void CTreeViewEx::vSetCheckParent(HTREEITEM hItem) { if(hItem == NULL) { return; } CTreeCtrl &omTreeCtrl = GetTreeCtrl(); HTREEITEM hParentItem = omTreeCtrl.GetParentItem(hItem); HTREEITEM hChildItem; BOOL bAllChecked = TRUE; if( omTreeCtrl.ItemHasChildren(hParentItem)) { hChildItem = omTreeCtrl.GetChildItem(hParentItem); while(hChildItem) { if(!bIsItemChecked(hChildItem)) { bAllChecked = FALSE; break; } hChildItem = omTreeCtrl.GetNextSiblingItem(hChildItem); } } vSetCheck(hParentItem, bAllChecked); vSetCheckParent(hParentItem); return; }
void CCheckBoxTree::vSetCheckParent(HTREEITEM hItem) { if(hItem == nullptr) { return; } HTREEITEM hParentItem = GetParentItem(hItem); HTREEITEM hChildItem; BOOL bAllChecked = TRUE; if( ItemHasChildren(hParentItem)) { hChildItem = GetChildItem(hParentItem); while(hChildItem) { if(!bIsItemChecked(hChildItem)) { bAllChecked = FALSE; break; } hChildItem = GetNextSiblingItem(hChildItem); } } BOOL fCheck=0; vSetCheck(hParentItem, bAllChecked); vSetCheckParent(hParentItem); vSetCheckChildren(hParentItem,!fCheck); }
void CTreeViewEx::OnLButtonDown(UINT nFlags, CPoint point) { UINT nHitTestFlags = 0; HTREEITEM hItem = GetTreeCtrl().HitTest(point, &nHitTestFlags); if((hItem != NULL) && (TVHT_ONITEMSTATEICON & nHitTestFlags)) { BOOL bCheck = bIsItemChecked(hItem); vSetCheck(hItem, !bCheck); return; } CTreeView::OnLButtonDown(nFlags, point); }
void CTreeViewEx::OnTvnKeyPress(NMHDR* pNMHDR, LRESULT* pResult) { TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR; CTreeCtrl& omTreeCtrl = GetTreeCtrl(); HTREEITEM hItem = omTreeCtrl.GetSelectedItem(); if((NULL != pTVKeyDown) && (NULL != hItem) && (pTVKeyDown->wVKey == VK_SPACE)) { BOOL bCheck = bIsItemChecked(hItem); bCheck = !bCheck ; GetExecutorWindow()->vEnableItem((DWORD)GetTreeCtrl().GetItemData(hItem), bCheck); } }
void CTreeViewEx::OnNMRclick(NMHDR* /*pNMHDR*/, LRESULT* pResult) { CPoint point; GetCursorPos(&point); CPoint omCurrentPoint(point); ScreenToClient(&omCurrentPoint); UINT flags; HTREEITEM hItem = GetTreeCtrl().HitTest(omCurrentPoint, &flags); CTreeCtrl& omTempTreeCtrl = GetTreeCtrl(); if(hItem && (flags & TVHT_ONITEM) && !(flags & TVHT_ONITEMRIGHT)) { omTempTreeCtrl.SelectItem(hItem); CMenu omContextMenu; VERIFY(omContextMenu.CreatePopupMenu()); if(omTempTreeCtrl.GetItemData(hItem) == def_ID_TESTSUITE) { VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_TESTSUITE_ADD, _("Add..."))); BOOL bCheck = bIsItemChecked(hItem); if(GetExecutorWindow()->bGetBusStatus() == TRUE && bCheck == TRUE ) { VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_TESTSUITE_EXECUTE, _("Execute"))); } else { VERIFY(omContextMenu.AppendMenu(MF_STRING|MF_GRAYED, IDM_TESTSUITE_EXECUTE, _("Execute"))); } } else { HTREEITEM hParentItem = omTempTreeCtrl.GetParentItem(hItem); if(omTempTreeCtrl.GetItemData(hParentItem) == def_ID_TESTSUITE) { VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_TESTSETUP_DELETE, _("Delete"))); VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_TESTSETUP_MODIFY, _("Reload File"))); } } omContextMenu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this); *pResult = 0; } else //On Tree View Create Collapse All and Expand All { CMenu omContextMenu; VERIFY(omContextMenu.CreatePopupMenu()); VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_COLLAPSE_ALL, _("Collapse All"))); VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_EXPAND_ALL, _("Expand All"))); omContextMenu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this); *pResult = 0; } }
/****************************************************************************** Function Name : OnLButtonDown Input(s) : UINT unFlag - Flags CPoint point - Mouse Pointer point Output : void Functionality : ON_WM_LBUTTON Handler used to toggle the check point Member of : CTreeViewEx Friend of : - Author(s) : Venkatanarayana Makam Date Created : 30/03/2011 Modifications : ******************************************************************************/ void CTreeViewEx::OnLButtonDown(UINT unFlag, CPoint point) { UINT unHitTestFlags = 0; HTREEITEM hItem = GetTreeCtrl().HitTest(point, &unHitTestFlags); if((hItem != nullptr) && (TVHT_ONITEMSTATEICON & unHitTestFlags)) { BOOL bCheck = bIsItemChecked(hItem); vSetCheck(hItem, !bCheck); vSetCheckChildren(hItem, !bCheck); vSetCheckParent(hItem); return; } CTreeView::OnLButtonDown(unFlag, point); }
//-------------------------------------------------------------------// // ExtractItemsToDragData() // //-------------------------------------------------------------------// // Dump the current selection into drag data array. //-------------------------------------------------------------------// void OleListCtrl::ExtractItemsToDragData( bool bSelectedOnly, int nUnderCursor ) { // Any previous drag contents should have been cleared at this time. // Remember, the drag data item array is only for temporary use, as // the clipboard is already handling the persistence of the drag data. ASSERT( Items.GetSize() == 0 ); // Loop through items. int nLoop = GetNextItem( -1, bSelectedOnly? LVNI_SELECTED : LVNI_ALL ); while ( nLoop != -1 ) { // Get a drag data object to add to the drag archive. OleDragItem Temp; // Get the item's lParam. Temp.m_lParam = GetItemData( nLoop ); // Get the item's checked status. Temp.m_bChecked = bIsItemChecked( nLoop ); // Add all the text from each column, separated by // the column separator. int nA; Temp.m_strName.Empty(); for ( nA = 0; nA < GetAbsoluteColCount(); nA++ ) { if ( nA != 0 ) Temp.m_strName += ctColumnSeparator; Temp.m_strName += GetItemText( nLoop, nA ); } // Currently we do not need any state data from the list control. // We may need state information at some point. // The flag variable can be used to hold this information. // There are states that are specific to tree controls, // list controls, etc.; we will add state flags only // as needed. For example, if, at some point in time, // we need to know whether an item was marked to be cut, // we can test the LVIS_CUT flag here in the list control, // and set the EM_STATE_MARKED_FOR_CUT flag accordingly. // UINT uListState = GetItemState( // nUnderCursor, // LVIS_CUT | LVIS_DROPHILITED | LVIS_FOCUSED | LVIS_SELECTED // ); // if ( uListState & LVIS_CUT ) uNodeState |= EM_STATE_MARKED_FOR_CUT; // etc. // No thanks to this functionality. /* // If we are on the item under the cursor, make sure it // is moved to the top of the list, as needed. if ( nLoop == nUnderCursor && pData->Items.GetSize() > 0 ) { // Swap our new item with item 0. OleDragItem Temp2 = pData->Items[0]; pData->Items[0] = Temp; Temp = Temp2; } */ // Add it to the list. Items.Add( Temp ); // Try for the next one. nLoop = GetNextItem( nLoop, bSelectedOnly? LVNI_SELECTED : LVNI_ALL ); } }
void CCheckBoxTree::OnLButtonDown(UINT nFlags, CPoint point) { UINT nHitTestFlags = 0; HTREEITEM hItem = HitTest(point, &nHitTestFlags); //MessageBox( "BEFORE IF", "IF1", MB_OK); if((hItem != nullptr) && (TVHT_ONITEMSTATEICON & nHitTestFlags)) { //MessageBox( "INSIDE IF", "IF1", MB_OK); //BOOL bCheck= GetCheck(hItem); BOOL bCheck = bIsItemChecked(hItem); //vSetCheck(hItem,!bCheck); vSetCheckChildren(hItem,!bCheck); if(!bCheck) { HTREEITEM root,parent; root=GetRootItem(); SetCheck(root); parent=GetParentItem(hItem); SetCheck(parent); } if(bCheck) { HTREEITEM root; HTREEITEM child; root=GetRootItem(); SetCheck(root,0); while(ItemHasChildren(root)) { //MessageBox("wHILE1", "WHILE1", MB_OK); HTREEITEM parent=GetChildItem(root); while(ItemHasChildren(parent)) { if(GetCheck(parent)) { SetCheck(parent,0); child=GetChildItem(parent); //MessageBox( "wHILE2", "WHILE2", MB_OK); while(child) { if(GetCheck(child)) { SetCheck(root); SetCheck(parent); } child=GetNextSiblingItem(child); if ( child == nullptr ) { break; } } } parent=GetNextSiblingItem(parent); if ( parent == nullptr ) { break; } } parent=GetNextSiblingItem(parent); if ( parent == nullptr ) { break; } } } } else { //MessageBox( "INSIDE ELSE", "ELSE", MB_OK); CTreeCtrl::OnLButtonDown(nFlags, point); } }