// // Stores the targets that have been selected by the user with the appropriate // worker. // void CPageDisk::StoreTargetSelection() { HTREEITEM hdisk; Manager *manager; Worker *worker; int target = 0; int next_worker; // Get the selected manager and worker. manager = theApp.pView->m_pWorkerView->GetSelectedManager(); worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); // Make sure we have a selected manager (or worker). if (!manager) { ErrorMessage("Unexpectedly found no selected manager in " "CPageDisk::StoreTargetSelection."); return; } if (worker) { // Assign the targets to the selected worker in the order that they // appear in the GUI. worker->RemoveTargets(GenericDiskType); for (hdisk = m_TTargets.GetRootItem(); hdisk; hdisk = m_TTargets.GetNextSiblingItem(hdisk)) { if (GetSelectionCheck(hdisk) == TargetChecked) worker->AddTarget(manager->GetInterface(target, GenericDiskType)); target++; } } else { // Clear the assigned targets from all the manager's workers. manager->RemoveTargets(GenericDiskType); // Set the first worker to receive targets. worker = manager->GetWorker(0, GenericDiskType); next_worker = 0; // Assign the targets to the workers of the selected manager. for (hdisk = m_TTargets.GetRootItem(); hdisk; hdisk = m_TTargets.GetNextSiblingItem(hdisk)) { // If the disk is selected in the GUI, assign it to the expected // worker. if (GetSelectionCheck(hdisk) == TargetChecked) { worker->AddTarget(manager->GetInterface(target, GenericDiskType)); // Update who the next worker to receive a target is. if (++next_worker >= manager->WorkerCount(GenericDiskType)) next_worker = 0; worker = manager->GetWorker(next_worker, GenericDiskType); } target++; } } ShowTargetSelection(); }
// // Mouse click handler for target tree. // void CPageDisk::OnClickTTargets(NMHDR * pNMHDR, LRESULT * pResult) { CPoint point; TV_HITTESTINFO test_info; TargetSelType state; // Get the cursor position. GetCursorPos(&point); test_info.pt = point; m_TTargets.ScreenToClient(&(test_info.pt)); // Check to see whether the cursor is on an item. m_TTargets.HitTest(&test_info); // Check that we have an disk item. if (!test_info.hItem) return; // A new target assignment is being made. Clear the results since they are // for a configuration we no longer have. theApp.pView->ResetDisplayforNewTest(); // Toggle the selection if the control key is pressed. if (GetKeyState(VK_CONTROL) & 0x8000 && GetSelectionCheck(test_info.hItem) == TargetChecked) { state = TargetUnChecked; } else { state = TargetChecked; } switch (theApp.pView->m_pWorkerView->GetSelectedType()) { case WORKER: case MANAGER: // A shift click extends the selection from the last selected item // to the currently focused item. When the control key is also // pressed, any previous selection is not cleared. if ((GetKeyState(VK_SHIFT) & 0x8000) && selected) { // We have a previous item (not the first click) and the shift // key is down. SelectRange(selected, test_info.hItem, !(GetKeyState(VK_CONTROL) & 0x8000)); } else if (GetKeyState(VK_CONTROL) & 0x8000) { // The control key is down. SelectRange(test_info.hItem, test_info.hItem, FALSE, state); } else { SelectRange(test_info.hItem, test_info.hItem, TRUE, state); } break; default: ErrorMessage("Unexpected selection type in CPageNetwork::" "OnClickTTargets()."); return; } // immediately refresh the display (create/delete NetClients as needed) StoreTargetSelection(); *pResult = 0; }
// // 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 CPageNetwork::StoreTargetSelection() { HTREEITEM hmgr, hifc; Manager *manager; Worker *worker; Target_Spec new_target; int local_interface_no; int interface_no; int target_count = 0; int expected_worker = 0; // Make sure we have a selected manager (or worker). manager = theApp.pView->m_pWorkerView->GetSelectedManager(); if (!manager) { ErrorMessage("Unexpectedly found no selected manager in " "CPageNetwork::StoreTargetSelection."); return; } // Count the number of assigned targets. for (hmgr = m_TTargets.GetRootItem(); hmgr; hmgr = m_TTargets.GetNextSiblingItem(hmgr)) { for (hifc = m_TTargets.GetChildItem(hmgr); hifc; hifc = m_TTargets.GetNextSiblingItem(hifc)) { if (GetSelectionCheck(hifc) == TargetChecked) target_count++; } } // Make sure we are not assigning more targets than we have workers. if (target_count > manager->WorkerCount(GenericServerType)) { ErrorMessage("You do not have enough network workers to assign all " "the selected targets."); // Restore the last selection. ShowTargetSelection(); // Set the focus to the target list. ::SetFocus(m_TTargets); return; } // The selection will succeed. Remove current network clients. if (worker = theApp.pView->m_pWorkerView->GetSelectedWorker()) worker->RemoveTargets(GenericNetType); else manager->RemoveTargets(GenericNetType); // Get the assigned local interface to use for the connection. local_interface_no = m_DInterface.GetCurSel(); // Assign the targets. // Loop through all managers. for (hmgr = m_TTargets.GetRootItem(); hmgr; hmgr = m_TTargets.GetNextSiblingItem(hmgr)) { // Loop through all interfaces of a manager. interface_no = 0; for (hifc = m_TTargets.GetChildItem(hmgr); hifc; hifc = m_TTargets.GetNextSiblingItem(hifc)) { if (GetSelectionCheck(hifc) == TargetChecked) { // Are we dealing with a worker or a manager? if (!worker) { // A manager is selected. Get the next available // network server worker. worker = manager->GetWorker(expected_worker++, GenericServerType); } // Get the interface of the selected target from the manager // whose interface is selected. memcpy(&new_target, ((Manager *) m_TTargets.GetItemData(hmgr))->GetInterface(interface_no, GenericNetType), sizeof(Target_Spec)); // Set the local and remote addresses of the connection. // The remote address used by the server is stored as the local // address for some manager's interface. if (IsType(new_target.type, TCPClientType)) { strcpy(new_target.tcp_info.remote_address, new_target.name); // Verify that the locally assigned interface matches the // selected target's interface. if (local_interface_no >= manager->InterfaceCount(GenericTCPType)) { // Use the first TCP interface. local_interface_no = 0; m_DInterface.SetCurSel(local_interface_no); } } else if (IsType(new_target.type, VIClientType)) { strcpy(new_target.vi_info.remote_nic_name, new_target.name); memcpy(&new_target.vi_info.remote_address, &new_target.vi_info.local_address, VI_ADDRESS_SIZE); // Verify that the locally assigned interface matches the // selected target's interface. if (local_interface_no <= manager->InterfaceCount(GenericTCPType)) { // Use the first VI interface. local_interface_no = manager->InterfaceCount(GenericTCPType); m_DInterface.SetCurSel(local_interface_no); } } else { ErrorMessage("Invalid target type for new target in " "CPageNetwork::StoreTargetSelection()."); } worker->AddTarget(&new_target); // Record information about what local interface the server // should use. worker->SetLocalNetworkInterface(local_interface_no); // Create the corresponding network client. worker->CreateNetClient((Manager *) m_TTargets.GetItemData(hmgr), new_target.type); // Clear the worker pointer so that the next iteration // through the loop (for a manager with multiple selected // interfaces) will get the next available network server. worker = NULL; } interface_no++; } } }
// // Single selection keyboard handler for the tree control. // void CPageNetwork::KeySingleSel(WORD wVKey) { BOOL shift = GetKeyState(VK_SHIFT) & 0x8000; BOOL control = GetKeyState(VK_CONTROL) & 0x8000; // Make sure there are interfaces. if (!highlighted) return; switch (wVKey) { case VK_UP: SetFocusUp(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_DOWN: SetFocusDown(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_HOME: SetFocusHome(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_END: SetFocusEnd(); // Only select items if the shift key is pressed. if (shift) { SelectRange(highlighted, highlighted, TRUE, TargetChecked); StoreTargetSelection(); } break; case VK_SPACE: 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 selection. { // Extend the selection and clear any other items. SelectRange(highlighted, highlighted, TRUE, TargetChecked); } ShowFocus(); StoreTargetSelection(); break; } ShowSettings(); EnableWindow(); }