void CLineAdvDlg::OnBnClickedCheckAll() { if ( BST_CHECKED == m_AllCheck.GetCheck() ) { SetAllCheck(); } }
// // Used to select one or more targets. May or may not clear any previous // selection depending on the replace parameter. // void CPageNetwork::SelectRange( HTREEITEM hstart, HTREEITEM hend, BOOL replace, TargetSelType state ) { HTREEITEM hmgr, hifc; BOOL in_range; if ( !hstart || !hend ) { ErrorMessage( "Unexpectedly found start or end point of selection" " range equal NULL in CPageNetwork::SelectRange()." ); return; } // Clear all the check boxes if forced to or if a multiple selection occurs. if ( replace ) SetAllCheck( TargetUnChecked ); // The last selection is the start point. selected = hstart; highlighted = hend; // Note that if both endpoints are the same, other selections will be // unchecked depending on the value of the 'replace' variable. if ( hstart == hend ) { SetSelectionCheck( hstart, state ); return; } // Since we don't know the relationship between the clicked item // and the last selection (up or down), we do not know what // direction to select targets in. Do a linear seach of the target tree // until we find either the start or end point. From there, mark // all the targets the specified selection type until we reach the end or // start (whichever we didn't get before). in_range = FALSE; for ( hmgr = m_TTargets.GetRootItem(); hmgr; hmgr = m_TTargets.GetNextSiblingItem( hmgr ) ) { for ( hifc = m_TTargets.GetChildItem( hmgr ); hifc; hifc = m_TTargets.GetNextSiblingItem( hifc ) ) { // Do we have either the previously selected item or the // clicked item? if ( hifc == hstart || hifc == hend ) in_range = !in_range; // If we are between the start and end point, set the state. if ( in_range || hifc == hstart || hifc == hend ) SetSelectionCheck( hifc, state ); } } }
BOOL CLineAdvDlg::OnInitDialog() { CDialog::OnInitDialog(); // Rule m_strRuleName.LoadString(IDS_RuleName); // Object CString strTmp; m_strObject.LoadString(IDS_Object); strTmp.LoadString(IDS_Object_Person); m_PersonCheck.SetWindowText(strTmp); strTmp.LoadString(IDS_Object_Vehicle); m_VehicleCheck.SetWindowText(strTmp); strTmp.LoadString(IDS_Object_Other); m_OtherCheck.SetWindowText(strTmp); strTmp.LoadString(IDS_Object_All); m_AllCheck.SetWindowText(strTmp); do { unsigned int nTest = m_pRule->ruleDescription.targetClassification; if ( nTest == 7 ) { SetAllCheck(); break; } if ( nTest & TARGET_CLASSIFICATION_HUMAN ) { m_PersonCheck.SetCheck(BST_CHECKED); } if ( nTest & TARGET_CLASSIFICATION_VEHICLE ) { m_VehicleCheck.SetCheck(BST_CHECKED); } if ( nTest & TARGET_CLASSIFICATION_UNKNOWN ) { m_OtherCheck.SetCheck(BST_CHECKED); } } while (0); UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
// // Multi selection keyboard handler for the tree control. // void CPageDisk::KeyMultiSel( WORD wVKey ) { BOOL shift = GetKeyState( VK_SHIFT ) & 0x8000; BOOL control = GetKeyState( VK_CONTROL ) & 0x8000; // Make sure there are disks. if ( !highlighted ) return; switch ( wVKey ) { case VK_UP: if ( !selected && shift ) selected = highlighted; SetFocusUp(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_DOWN: if ( !selected && shift ) selected = highlighted; SetFocusDown(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_HOME: if ( !selected && shift ) selected = highlighted; SetFocusHome(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_END: if ( !selected && shift ) selected = highlighted; SetFocusEnd(); // Only select items if the shift key is pressed. if ( shift ) { SelectRange( selected, highlighted, !control, TargetChecked ); StoreTargetSelection(); } break; case VK_SPACE: if ( shift ) { // Extend the selection. Clear any other items if the control // key is not pressed. SelectRange( selected, highlighted, !control, TargetChecked ); } else if ( control ) // toggle. { // Toggle the selection, but do not clear any other items. if ( GetSelectionCheck( highlighted ) == TargetChecked ) { SelectRange( highlighted, highlighted, FALSE, TargetUnChecked ); } else { SelectRange( highlighted, highlighted, FALSE, TargetChecked ); } } else // normal { // Select only the highlighted item and clear any other. SelectRange( highlighted, highlighted, TRUE, TargetChecked ); } ShowFocus(); StoreTargetSelection(); break; case 'A': if ( control ) { SetAllCheck( TargetChecked ); StoreTargetSelection(); } } }
void CPageDisk::ShowTargetSelection() { Manager *manager; Worker *worker; HTREEITEM hiface; int w, i, expected_worker, iface_count, wkr_count; TargetSelType state; Target_Spec target_info; // Get the selected manager. manager = theApp.pView->m_pWorkerView->GetSelectedManager(); // Get the first disk item from the target tree. hiface = m_TTargets.GetRootItem(); switch ( theApp.pView->m_pWorkerView->GetSelectedType() ) { case WORKER: // A worker is selected, show its assigned targets. worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); // Loop through the manager's disks, and mark which ones are selected // for the worker. iface_count = manager->InterfaceCount( GenericDiskType ); for ( i = 0; i < iface_count; i++ ) { if ( worker->IsTargetAssigned( manager->GetInterface(i, GenericDiskType))) SetSelectionCheck( hiface, TargetChecked ); else SetSelectionCheck( hiface, TargetUnChecked ); hiface = m_TTargets.GetNextSiblingItem( hiface ); } break; case MANAGER: // Show the targets assigned to a manager's workers if possible. expected_worker = 0; // Loop through the manager's disks, and see if they are assigned // to the expected worker. If not, gray all of them and return. iface_count = manager->InterfaceCount( GenericDiskType ); wkr_count = manager->WorkerCount( GenericDiskType ); for ( i = 0; i < iface_count; i++ ) { memcpy( &target_info, manager->GetInterface( i, GenericDiskType ), sizeof( Target_Spec ) ); state = TargetUnChecked; for ( w = 0; w < wkr_count; w++ ) { // If the disk is selected by any other than expected // worker, all the disk check boxes are grayed. if ( manager->GetWorker(w, GenericDiskType)->IsTargetAssigned( &target_info ) ) { if ( w != expected_worker || state != TargetUnChecked ) { SetAllCheck( TargetGrayed ); return; } state = TargetChecked; if ( ++expected_worker == wkr_count ) { expected_worker = 0; } } } SetSelectionCheck( hiface, state ); hiface = m_TTargets.GetNextSiblingItem( hiface ); } break; default: SetAllCheck( TargetGrayed ); break; } }
void CPageNetwork::ShowTargetSelection() { Manager *manager, *partner_manager; Worker *worker, *partner_worker; char *remote_address; HTREEITEM hmgr; HTREEITEM hifc; int i, expected_worker; TargetSelType state; switch (theApp.pView->m_pWorkerView->GetSelectedType()) { case WORKER: worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); // Get the interface to check. if (IsType(worker->Type(), GenericServerType)) { if (!worker->net_partner) { partner_manager = NULL; } else { partner_manager = worker->net_partner->manager; if (IsType(worker->GetTarget(0)->spec.type, TCPClientType)) remote_address = worker->GetTarget(0)->spec.tcp_info.remote_address; else if (IsType(worker->GetTarget(0)->spec.type, VIClientType)) remote_address = worker->GetTarget(0)->spec.vi_info.remote_nic_name; else { ErrorMessage("Invalid client target type in CPageNetwork::" "ShowTargetSelection()."); return; } } } else if (IsType(worker->Type(), GenericClientType)) { partner_manager = worker->net_partner->manager; remote_address = worker->net_partner->spec.name; } else { return; } // Walk the target tree to find the correct partner manager. for (hmgr = m_TTargets.GetRootItem(); hmgr; hmgr = m_TTargets.GetNextSiblingItem(hmgr)) { if (m_TTargets.GetItemData(hmgr) == (DWORD_PTR) partner_manager) { // Check the appropriate interface on the partner manager. CheckInterface(hmgr, remote_address); } else { // Clear all check marks for this manager's interfaces. CheckInterface(hmgr, NULL); } } break; case MANAGER: // Get the selected manager. manager = theApp.pView->m_pWorkerView->GetSelectedManager(); expected_worker = 0; // Loop through all the target tree items. for (hmgr = m_TTargets.GetRootItem(); hmgr; hmgr = m_TTargets.GetNextSiblingItem(hmgr)) { // Get the possible partner manager from the tree. partner_manager = (Manager *) m_TTargets.GetItemData(hmgr); // Loop through that manager item's interfaces. for (hifc = m_TTargets.GetChildItem(hmgr); hifc; hifc = m_TTargets.GetNextSiblingItem(hifc)) { // Initialize the state. It may or may not be changed, // depending on whether we find it selected by a worker. state = TargetUnChecked; // Check the interface for selection by any of the manager's // workers for (i = 0; i < manager->WorkerCount(GenericServerType); i++) { // Get the net partner of the expected worker. partner_worker = manager->GetWorker(i, GenericServerType)->net_partner; // If the partner worker exists and it's manager is the // same as the manager in the target tree that we are // currently looking at and.. if (partner_worker && partner_worker->manager == partner_manager) { // if the net addresses match but.. if (m_TTargets.GetItemText(hifc) == partner_worker->GetLocalNetworkInterface()) { // the worker is not the expected worker.. if (i != expected_worker || state != TargetUnChecked) { // gray the selection SetAllCheck(TargetGrayed); return; } state = TargetChecked; expected_worker++; } } } SetSelectionCheck(hifc, state); } } break; default: SetAllCheck(TargetGrayed); break; } }