void CreateTree(HuffmanTree *ht,int n,int *w) { int i,m=2*n-1; int bt1,bt2; if(n<=1) return ; for(i=1;i<=n;++i) { ht[i].weight = w[i-1]; ht[i].parent = 0; ht[i].left = 0; ht[i].right = 0; } for(;i<=m;++i) { ht[i].weight = 0; ht[i].parent = 0; ht[i].left = 0; ht[i].right = 0; } for(i=n+1;i<=m;++i) { SelectNode(ht,i-1,&bt1,&bt2); ht[bt1].parent = i; ht[bt2].parent = i; ht[i].left = bt1; ht[i].right = bt2; ht[i].weight = ht[bt1].weight+ht[bt2].weight; } }
/** * 创建赫夫曼树 * @param ht [description] * @param n 结点总数量 * @param w [description] */ void Create(HuffmanTree *ht, int n, int *w) { printf("创建赫夫曼树!\n"); int i, m =2*n-1; int bt1, bt2; if(n<=1) return; //只有一个结点时,无法创建 //初始化叶结点 for(i=1;i<=n;++i) { printf("初始化叶结点!权重为:%d\n",w[i-1]); ht[i].weight = w[i-1]; ht[i].parent = 0; ht[i].left = 0; ht[i].right = 0; } //初始化后续结点 for(;i<=m;++i) { ht[i].weight = 0; ht[i].parent = 0; ht[i].left = 0; ht[i].right = 0; } //逐个计算非叶结点,创建赫夫曼树 for(i=n+1;i<=m;++i) { SelectNode(ht, i-1, &bt1, &bt2); //得到权重最小的两个结点 ht[bt1].parent = i; ht[bt2].parent = i; ht[i].left = bt1; ht[i].right = bt2; ht[i].weight = ht[bt1].weight+ht[bt2].weight; //保存权值 printf("两个结点:bt1:%d,bt2:%d,父结点:%d,权重:%d\n", bt1,bt2,i,ht[i].weight); } }
// // Sets the view type // void KeyView::SetView(ViewByType type) { int index = LineToIndex(GetSelection()); // Handle an existing selection if (index != wxNOT_FOUND) { // Cache the currently selected node KeyNode & node = mNodes[index]; // Expand branches if switching to Tree view and a line // is currently selected if (type == ViewByTree) { // Cache the node's depth int depth = node.depth; // Search for its parents, setting each one as open for (int i = node.index - 1; i >= 0 && depth > 1; i--) { if (mNodes[i].depth < depth) { mNodes[i].isopen = true; depth = mNodes[i].depth; } } } } // Unselect any currently selected line...do even if none selected SelectNode(-1); // Save new type mViewType = type; // Refresh the view lines RefreshLines(); // Reselect old node (if possible) if (index != wxNOT_FOUND) { SelectNode(index); } return; }
BOOL W_EXPORT SelectBrowserObjectCB(OBJECTID idObj, BOOL bOn, BOOL bMult, BOOL bQuery) { BRDATA lpBrData = (BRDATA) GLOBALLOCK(hClBrData); LPBRTABLE lpBrowser = (LPBRTABLE) GLOBALLOCK(lpBrData->hBrowser); BOOL bFound = FALSE; LPBRTABLE lpItem; LEVEL_TYPE level = lpBrData->lFocusedLevel; while (level <= lpBrData->lDepth && FindLevel_BrTable(lpBrowser, level, &lpItem, FALSE)) { WORD wCount = LEVELCOUNT((lpItem - SIZE_BRLEVEL)); while (wCount-- && !bFound) { if (ITEMID_BRITEM(lpItem) == idObj) bFound = TRUE; else lpItem = MOVE_TO_NEXT_ITEM(lpItem, lpBrData->sItemSize); } if (bFound) break; level++; } if (bFound && !bQuery) { HDC hDC = GetDC(hWndBrowser); MapWinToView(hWndBrowser, lpBrData, hDC); if (bOn && !(BRITEM_FLAGS(lpItem) & SELECTED_ITEM) || !bOn && BRITEM_FLAGS(lpItem) & SELECTED_ITEM) { OBJECTID idOldSel = NULLID; if (!bOn && idObj != BrSelection.idObj) { idOldSel = BrSelection.idObj; BrSelection.idObj = idObj; } SelectNode((CLBRITEM) lpItem, bMult, hDC, level); if (idOldSel) BrSelection.idObj = idOldSel; } ReleaseDC(hWndBrowser, hDC); } else if (bFound) bOn = BRITEM_FLAGS(lpItem) & SELECTED_ITEM; GLOBALUNLOCK(lpBrData->hBrowser); GLOBALUNLOCK(hClBrData); return bOn && bFound; }
// // Sets the filter // void KeyView::SetFilter(const wxString & filter) { int index = LineToIndex(GetSelection()); // Unselect any currently selected line...do even if none selected SelectNode(-1); // Save the filter mFilter = filter.Lower(); // Refresh the view lines RefreshLines(); // Reselect old node (if possible) if (index != wxNOT_FOUND) { SelectNode(index); } }
nsresult FilteredContentIterator::Init(nsINode* aRoot) { NS_ENSURE_ARG_POINTER(aRoot); mIsOutOfRange = false; mDirection = eForward; mCurrentIterator = &mPreIterator; mRange = new nsRange(aRoot); mRange->SelectNode(*aRoot, IgnoreErrors()); nsresult rv = mPreIterator.Init(mRange); NS_ENSURE_SUCCESS(rv, rv); return mPostIterator.Init(mRange); }
// // Handle the wxEVT_LEFT_DOWN event // void KeyView::OnLeftDown(wxMouseEvent & event) { // Only check if for tree view if (mViewType != ViewByTree) { // Allow further processing (important for focus handling) event.Skip(); return; } // Get the mouse position when the button was pressed wxPoint pos = event.GetPosition(); // And see if it was on a line within the view int line = HitTest(pos); // It was on a line if (line != wxNOT_FOUND) { KeyNode *node = mLines[line]; // Toggle the open state if this is a parent node if (node->isparent) { // Toggle state node->isopen = !node->isopen; // Don't want the view to scroll vertically, so remember the current // top line. size_t topline = GetVisibleBegin(); // Refresh the view now that the number of lines have changed RefreshLines(); // Reset the original top line ScrollToLine(topline); // And make sure current line is still selected SelectNode(LineToIndex(line)); } } // Allow further processing (important for focus handling) event.Skip(); }
void wxSpinTreeCtrl::removeNode(const char *id) { // if the node to be removed is currently selected, then select NULL (root) spin::ReferencedNode* n = GetSelectedNode(); if (n && strcmp(n->id->s_name,id)==0) { SelectNode(NULL); } // We need to find the node based on the string id provided: wxTreeItemId nodeInTree = GetTreeItem(id); if (nodeInTree) { Freeze(); Delete(nodeInTree); Thaw(); } }
//------------------------------------------------------------ nsresult nsFilteredContentIterator::Init(nsINode* aRoot) { NS_ENSURE_TRUE(mPreIterator, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE); mIsOutOfRange = false; mDirection = eForward; mCurrentIterator = mPreIterator; mRange = new nsRange(); nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(aRoot)); if (domNode) { mRange->SelectNode(domNode); } nsresult rv = mPreIterator->Init(mRange); NS_ENSURE_SUCCESS(rv, rv); return mIterator->Init(mRange); }
LRESULT CALLBACK AddressBarProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldwndproc; static WCHAR s_szNode[256]; oldwndproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(hwnd, GWLP_USERDATA); switch (uMsg) { case WM_KEYUP: if (wParam == VK_RETURN) { GetWindowTextW(hwnd, s_szNode, COUNT_OF(s_szNode)); SelectNode(g_pChildWnd->hTreeWnd, s_szNode); } break; default: break; } return CallWindowProcW(oldwndproc, hwnd, uMsg, wParam, lParam); }
static void ChooseFavorite(LPCTSTR pszFavorite) { HKEY hKey = NULL; TCHAR szFavoritePath[512]; DWORD cbData, dwType; if (RegOpenKeyEx(HKEY_CURRENT_USER, s_szFavoritesRegKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) goto done; cbData = (sizeof(szFavoritePath) / sizeof(szFavoritePath[0])) - 1; memset(szFavoritePath, 0, sizeof(szFavoritePath)); if (RegQueryValueEx(hKey, pszFavorite, NULL, &dwType, (LPBYTE) szFavoritePath, &cbData) != ERROR_SUCCESS) goto done; if (dwType == REG_SZ) SelectNode(g_pChildWnd->hTreeWnd, szFavoritePath); done: if (hKey) RegCloseKey(hKey); }
bool canFinish(int numCourses, vector<pair<int, int>>& prerequisites) { vector<int> CoursesRequire(numCourses,0); map<int, vector<int>> NodeEdges; vector<int> EdgesElement; int node; for(int i = 0; i<prerequisites.size();i++){ CoursesRequire[prerequisites[i].first]++; NodeEdges[prerequisites[i].second].push_back(prerequisites[i].first); } for(int i = 0; i < numCourses; i++){ node = SelectNode(CoursesRequire); if (node == -1) return false; for (int j = 0 ;j < NodeEdges[node].size();j++) CoursesRequire[NodeEdges[node][j]]--; CoursesRequire[node] = -2; } return true; }
void SceneEditor3D::HandleNodeRemoved(StringHash eventType, VariantMap& eventData) { Node* node = (Node*) (eventData[NodeRemoved::P_NODE].GetPtr()); if (node == selectedNode_) SelectNode(0); }
void SceneEditor3D::HandleEditorActiveNodeChange(StringHash eventType, VariantMap& eventData) { Node* node = (Node*) (eventData[EditorActiveNodeChange::P_NODE].GetPtr()); SelectNode(node); }
// // Handle the wxEVT_KEY_DOWN event // void KeyView::OnKeyDown(wxKeyEvent & event) { int line = GetSelection(); int keycode = event.GetKeyCode(); switch (keycode) { // The LEFT key moves selection to parent or collapses selected // node if it is expanded. case WXK_LEFT: { // Nothing selected...nothing to do if (line == wxNOT_FOUND) { // Allow further processing event.Skip(); break; } KeyNode *node = mLines[line]; // Collapse the node if it is open if (node->isopen) { // No longer open node->isopen = false; // Don't want the view to scroll vertically, so remember the current // top line. size_t topline = GetVisibleBegin(); // Refresh the view now that the number of lines have changed RefreshLines(); // Reset the original top line ScrollToLine(topline); // And make sure current line is still selected SelectNode(LineToIndex(line)); } else { // Move selection to the parent of this node for (int i = line - 1; i >= 0; i--) { // Found the parent if (mLines[i]->depth < node->depth) { // So select it SelectNode(LineToIndex(i)); break; } } } // Further processing of the event is not wanted // (we didn't call event.Skip() } break; // The RIGHT key moves the selection to the first child or expands // the node if it is a parent. case WXK_RIGHT: { // Nothing selected...nothing to do if (line == wxNOT_FOUND) { // Allow further processing event.Skip(); break; } KeyNode *node = mLines[line]; // Only want parent nodes if (node->isparent) { // It is open so move select to first child if (node->isopen) { // But only if there is one if (line < (int) mLines.GetCount() - 1) { SelectNode(LineToIndex(line + 1)); } } else { // Node is now open node->isopen = true; // Don't want the view to scroll vertically, so remember the current // top line. size_t topline = GetVisibleBegin(); // Refresh the view now that the number of lines have changed RefreshLines(); // Reset the original top line ScrollToLine(topline); // And make sure current line is still selected SelectNode(LineToIndex(line)); } } // Further processing of the event is not wanted // (we didn't call event.Skip() } break; // Move selection to next node whose 1st character matches // the keycode default: { int cnt = (int) mLines.GetCount(); bool found = false; // Search the entire list if not is currently selected if (line == wxNOT_FOUND) { line = cnt; } else { // Search from the node following the current one for (int i = line + 1; i < cnt; i++) { wxString label; // Get the string to search based on view type if (mViewType == ViewByTree) { label = GetLabel(LineToIndex(i)); } else if (mViewType == ViewByName) { label = GetFullLabel(LineToIndex(i)); } else if (mViewType == ViewByKey) { label = GetKey(LineToIndex(i)); } // Move selection if they match if (label.Left(1).IsSameAs(keycode, false)) { SelectNode(LineToIndex(i)); found = true; break; } } } // A match wasn't found if (!found) { // So scan from the start of the list to the current node for (int i = 0; i < line; i++) { wxString label; // Get the string to search based on view type if (mViewType == ViewByTree) { label = GetLabel(LineToIndex(i)); } else if (mViewType == ViewByName) { label = GetFullLabel(LineToIndex(i)); } else if (mViewType == ViewByKey) { label = GetKey(LineToIndex(i)); } // Move selection if they match if (label.Left(1).IsSameAs(keycode, false)) { SelectNode(LineToIndex(i)); found = true; break; } } } // A node wasn't found so allow further processing if (!found) { event.Skip(); } // Otherwise, further processing of the event is not wanted // (we didn't call event.Skip() } } }
nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, nsISelectionController *aSelectionController, bool aIsFirstVisiblePreferred, bool aFindPrev, nsIPresShell **aPresShell, nsPresContext **aPresContext) { NS_ENSURE_ARG_POINTER(aContainer); NS_ENSURE_ARG_POINTER(aPresShell); NS_ENSURE_ARG_POINTER(aPresContext); *aPresShell = nullptr; *aPresContext = nullptr; nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); if (!docShell) return NS_ERROR_FAILURE; nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell(); nsRefPtr<nsPresContext> presContext; docShell->GetPresContext(getter_AddRefs(presContext)); if (!presShell || !presContext) return NS_ERROR_FAILURE; nsIDocument* doc = presShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; nsCOMPtr<nsIContent> rootContent; nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc)); if (htmlDoc) { nsCOMPtr<nsIDOMHTMLElement> bodyEl; htmlDoc->GetBody(getter_AddRefs(bodyEl)); rootContent = do_QueryInterface(bodyEl); } if (!rootContent) rootContent = doc->GetRootElement(); nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootContent)); if (!rootNode) return NS_ERROR_FAILURE; if (!mSearchRange) { mSearchRange = new nsRange(doc); } nsCOMPtr<nsIDOMNode> searchRootNode = rootNode; // Hack for XMLPrettyPrinter. nsFind can't handle complex anonymous content. // If the root node has an XBL binding then there's not much we can do in // in general, but we can try searching the binding's first child, which // in the case of XMLPrettyPrinter contains the visible pretty-printed // content. nsXBLBinding* binding = rootContent->GetXBLBinding(); if (binding) { nsIContent* anonContent = binding->GetAnonymousContent(); if (anonContent) { searchRootNode = do_QueryInterface(anonContent->GetFirstChild()); } } mSearchRange->SelectNodeContents(searchRootNode); if (!mStartPointRange) { mStartPointRange = new nsRange(doc); } mStartPointRange->SetStart(searchRootNode, 0); mStartPointRange->Collapse(true); // collapse to start if (!mEndPointRange) { mEndPointRange = new nsRange(doc); } nsCOMPtr<nsINode> searchRootTmp = do_QueryInterface(searchRootNode); mEndPointRange->SetEnd(searchRootNode, searchRootTmp->Length()); mEndPointRange->Collapse(false); // collapse to end // Consider current selection as null if // it's not in the currently focused document nsCOMPtr<nsIDOMRange> currentSelectionRange; nsCOMPtr<nsIPresShell> selectionPresShell = GetPresShell(); if (aSelectionController && selectionPresShell && selectionPresShell == presShell) { nsCOMPtr<nsISelection> selection; aSelectionController->GetSelection( nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (selection) selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange)); } if (!currentSelectionRange) { // Ensure visible range, move forward if necessary // This uses ignores the return value, but usese the side effect of // IsRangeVisible. It returns the first visible range after searchRange IsRangeVisible(presShell, presContext, mSearchRange, aIsFirstVisiblePreferred, true, getter_AddRefs(mStartPointRange), nullptr); } else { int32_t startOffset; nsCOMPtr<nsIDOMNode> startNode; if (aFindPrev) { currentSelectionRange->GetStartContainer(getter_AddRefs(startNode)); currentSelectionRange->GetStartOffset(&startOffset); } else { currentSelectionRange->GetEndContainer(getter_AddRefs(startNode)); currentSelectionRange->GetEndOffset(&startOffset); } if (!startNode) startNode = rootNode; // We need to set the start point this way, other methods haven't worked mStartPointRange->SelectNode(startNode); mStartPointRange->SetStart(startNode, startOffset); } mStartPointRange->Collapse(true); // collapse to start presShell.forget(aPresShell); presContext.forget(aPresContext); return NS_OK; }
BOOL MoveAroundBrowser(HWND hWnd, WORD wKey, WORD wFlags, OBJECTID idParent) { BRDATA lpBrData = (BRDATA) GLOBALLOCK(hClBrData); CLBRITEM lpLevel, lpNode = NULL; LPBRTABLE lpBrowser; LEVEL_TYPE level; if (!lpBrData->hBrowser) return FALSE; lpBrowser = (LPBRTABLE) GLOBALLOCK(lpBrData->hBrowser); level = (LEVEL_TYPE) ((float) (lpBrData->fLeftColumn * sNodeWidth + BrSelection.rect.left + 2) / sNodeWidth); if (wKey == VK_HOME) { lpNode = FindFocusedNode(lpBrowser, lpBrData); level = lpBrData->fLeftColumn; } else if (BrSelection.idObj) { switch (wKey) { case VK_RIGHT: if (OBJECT_TYPE(BrSelection.idObj) == CLASS && FindLevel_BrTable(lpBrowser, level + 1, (LPLPBRTABLE) &lpLevel, FALSE)) { CLBRITEM lpParent = FindNodeInLevel(BrSelection.idObj, level, lpBrData->sItemSize, lpBrowser); if (lpParent) { BOOL bInstVisible = ARE_INSTANCES_VISIBLE(BRITEM_FLAGS(lpParent)); BOOL bClassVisible = ARE_SUBCLASSES_VISIBLE(BRITEM_FLAGS(lpParent)); level += 1; lpNode = FindTopInLevel(BrSelection.idObj, (LPBRTABLE) lpLevel, lpBrData->sItemSize, bInstVisible, bClassVisible, lpBrData->fTopRow, lpBrData->fBottomRow, lpBrData, level); } } break; case VK_LEFT: if (BrSelection.idObj != lpIDs->idRootClass) { OBJECTID idObj = BrSelection.idObj; WORD wType = OBJECT_TYPE(idObj); if (!idParent) idParent = Kpp_Get_Super(wType, idObj); if (BrSelection.idObj == lpBrData->idFocusedItem) { SetClBrowserFocusCB(CLASS, idParent); SendMessage(hWnd, WM_PAINT, 0, 0L); } if (FindLevel_BrTable(lpBrowser, --level, (LPBRTABLE *) &lpLevel, FALSE)) lpNode = FindParentInLevel(BrSelection.idObj, (LPBRTABLE) lpLevel, lpBrData->sItemSize, lpBrData->fTopRow, lpBrData->fBottomRow, idParent); } break; case VK_UP: case VK_DOWN: if (BrSelection.idObj != lpIDs->idRootClass && FindLevel_BrTable(lpBrowser, level, (LPLPBRTABLE) &lpLevel, FALSE)) { LPBRTABLE lpParentLevel; if (FindLevel_BrTable(lpBrowser, level - 1, (LPLPBRTABLE) &lpParentLevel, FALSE)) lpNode = FindNextInLevel(BrSelection.fRow, (LPBRTABLE) lpLevel, lpBrData->sItemSize, wKey == VK_UP, lpParentLevel, lpBrData->fTopRow, lpBrData->fBottomRow, lpBrData->idFocusedItem, lpBrData, level); } break; case VK_PRIOR: case VK_NEXT: SendMessage(hWnd, WM_VSCROLL, wKey == VK_PRIOR ? SB_PAGEUP : SB_PAGEDOWN, 0L); break; case VK_CANCEL: case VK_CLEAR: ClearSelections(hWnd, lpBrData); break; } } if (lpNode) { HDC hDC = GetDC(hWnd); float fItemRow = GET_Y_REL(lpNode); float fItemColumn = (float) (level - 1); RECT rect, wrect; int sbw = GetSystemMetrics(SM_CXVSCROLL); MapWinToView(hWnd, lpBrData, hDC); GetClientRect(hWnd, &wrect); wrect.right -= sbw; wrect.left = sbw; GetItemRect(lpBrData, (LPBRTABLE) lpNode, level, &rect); DPtoLP(hDC, (LPPOINT) &wrect, 2); SelectNode(lpNode, wFlags & SHIFT_FLAG, hDC, level); ReleaseDC(hWnd, hDC); if (wFlags & ONCE_NO_DELETE) BRITEM_FLAGS(lpNode) |= ONCE_NO_DELETE; if (!(fItemRow - lpBrData->fTopRow > (float) -1.0)) SendMessage(hWnd, WM_VSCROLL, SB_LINEUP, 0L); else if (!(lpBrData->fBottomRow - fItemRow > (float) 0.0)) SendMessage(hWnd, WM_VSCROLL, SB_LINEDOWN, 0L); if (fItemColumn > lpBrData->fRightColumn || rect.left > wrect.right) SendMessage(hWnd, WM_HSCROLL, SB_PAGEDOWN, 0L); else if (fItemColumn < lpBrData->fLeftColumn - 1) SendMessage(hWnd, WM_HSCROLL, SB_PAGEUP, 0L); } GLOBALUNLOCK(lpBrData->hBrowser); GLOBALUNLOCK(hClBrData); return TRUE; }
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { BOOL AclUiAvailable; HMENU hEditMenu; TCHAR szBuffer[256]; WNDCLASSEX wcFrame; WNDCLASSEX wcChild; ATOM hFrameWndClass; ZeroMemory(&wcFrame, sizeof(WNDCLASSEX)); wcFrame.cbSize = sizeof(WNDCLASSEX); wcFrame.lpfnWndProc = FrameWndProc; wcFrame.hInstance = hInstance; wcFrame.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)); wcFrame.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); wcFrame.hCursor = LoadCursor(0, IDC_ARROW); wcFrame.lpszClassName = szFrameClass; hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */ ZeroMemory(&wcChild, sizeof(WNDCLASSEX)); wcChild.cbSize = sizeof(WNDCLASSEX); wcChild.lpfnWndProc = ChildWndProc; wcChild.cbWndExtra = sizeof(HANDLE); wcChild.hInstance = hInstance; wcChild.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)); wcChild.hCursor = LoadCursor(0, IDC_ARROW), wcChild.lpszClassName = szChildClass, wcChild.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); RegisterClassEx(&wcChild); /* register child windows class */ RegisterHexEditorClass(hInstance); hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU)); hPopupMenus = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_POPUP_MENUS)); /* Initialize the Windows Common Controls DLL */ InitCommonControls(); hEditMenu = GetSubMenu(hMenuFrame, 1); AclUiAvailable = InitializeAclUiDll(); if(!AclUiAvailable) { /* hide the Edit/Permissions... menu entry */ if(hEditMenu != NULL) { RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND); /* remove the separator after the menu item */ RemoveMenu(hEditMenu, 4, MF_BYPOSITION); } } if(hEditMenu != NULL) SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND); nClipboardFormat = RegisterClipboardFormat(strClipboardFormat); /* if (nClipboardFormat == 0) { DWORD dwError = GetLastError(); } */ hFrameWnd = CreateWindowEx(WS_EX_WINDOWEDGE, (LPCTSTR)(UlongToPtr(hFrameWndClass)), szTitle, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenuFrame, hInstance, NULL/*lpParam*/); if (!hFrameWnd) { return FALSE; } /* Create the status bar */ hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|SBT_NOBORDERS, _T(""), hFrameWnd, STATUS_WINDOW); if (hStatusBar) { /* Create the status bar panes */ SetupStatusBar(hFrameWnd, FALSE); CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED); } /* Restore position */ if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("LastKey"), szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS) { SelectNode(g_pChildWnd->hTreeWnd, szBuffer); } ShowWindow(hFrameWnd, nCmdShow); UpdateWindow(hFrameWnd); return TRUE; }
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HTREEITEM hSelection; HKEY hRootKey; LPCWSTR keyPath, s; WORD wID = LOWORD(wParam); UNREFERENCED_PARAMETER(message); switch (wID) { /* Parse the menu selections: */ case ID_REGISTRY_EXIT: DestroyWindow(hWnd); break; case ID_VIEW_REFRESH: /* TODO */ break; case ID_TREE_EXPANDBRANCH: (void)TreeView_Expand(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd), TVE_EXPAND); break; case ID_TREE_COLLAPSEBRANCH: (void)TreeView_Expand(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd), TVE_COLLAPSE); break; case ID_TREE_RENAME: SetFocus(g_pChildWnd->hTreeWnd); (void)TreeView_EditLabel(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd)); break; case ID_TREE_DELETE: hSelection = TreeView_GetSelection(g_pChildWnd->hTreeWnd); keyPath = GetItemPath(g_pChildWnd->hTreeWnd, hSelection, &hRootKey); if (keyPath == 0 || *keyPath == 0) { MessageBeep(MB_ICONHAND); } else if (DeleteKey(hWnd, hRootKey, keyPath)) DeleteNode(g_pChildWnd->hTreeWnd, 0); break; case ID_TREE_EXPORT: ExportRegistryFile(g_pChildWnd->hTreeWnd); break; case ID_EDIT_FIND: FindDialog(hWnd); break; case ID_EDIT_COPYKEYNAME: hSelection = TreeView_GetSelection(g_pChildWnd->hTreeWnd); keyPath = GetItemPath(g_pChildWnd->hTreeWnd, hSelection, &hRootKey); CopyKeyName(hWnd, hRootKey, keyPath); break; case ID_EDIT_NEW_KEY: CreateNewKey(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd)); break; case ID_EDIT_NEW_STRINGVALUE: case ID_EDIT_NEW_BINARYVALUE: case ID_EDIT_NEW_DWORDVALUE: SendMessageW(hFrameWnd, WM_COMMAND, wParam, lParam); break; case ID_SWITCH_PANELS: g_pChildWnd->nFocusPanel = !g_pChildWnd->nFocusPanel; SetFocus(g_pChildWnd->nFocusPanel? g_pChildWnd->hListWnd: g_pChildWnd->hTreeWnd); break; default: if ((wID >= ID_TREE_SUGGESTION_MIN) && (wID <= ID_TREE_SUGGESTION_MAX)) { s = Suggestions; while(wID > ID_TREE_SUGGESTION_MIN) { if (*s) s += wcslen(s) + 1; wID--; } SelectNode(g_pChildWnd->hTreeWnd, s); break; } return FALSE; } return TRUE; }
void CTreeWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // Let the selection do its stuff with this keypress // m_selection.NotifyKeyPress(nChar); if (m_selection.empty()) return; CTreeNode* pLastSel = m_selection.lastSelected(); switch (nChar) { case VK_LEFT: if (pLastSel && pLastSel->IsExpanded()) { pLastSel->ToggleExpanded(); ForceLayout(); Invalidate(); } break; case VK_RIGHT: if (pLastSel && (!pLastSel->IsExpanded())) { if (m_style & MTS_EXPANDRECURSIVE) pLastSel->Expand(true); else pLastSel->ToggleExpanded(); ForceLayout(); Invalidate(); } break; case VK_UP: { //InvalidateNode(pLastSel); //pLastSel = pLastSel->PrevNode(); //m_selection.SelectItem(pLastSel); // GetParent()->SendMessage(WM_MTREE_ITEM_SELECTED,(WPARAM)pLastSel,0); // Force scroll up if node is not in view. // CRect a; GetClientRect(a); CShape* pShape = ShapeFromNode(pLastSel); if (!pShape || pShape->bottom < a.top) { SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),NULL); } ForceLayout(); InvalidateNode(pLastSel); } break; case VK_DOWN: { //InvalidateNode(pLastSel); //pLastSel = pLastSel->NextNode(); //m_selection.SelectItem(pLastSel); // GetParent()->SendMessage(WM_MTREE_ITEM_SELECTED,(WPARAM)pLastSel,0); // Force scroll down if node is not in view. // CRect a; GetClientRect(a); CShape* pShape = ShapeFromNode(pLastSel); if (!pShape || pShape->bottom > a.bottom) { SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),NULL); } InvalidateNode(pLastSel); ForceLayout(); } break; case VK_RETURN: if (pLastSel) OnNodeDoubleClicked(pLastSel); break; case VK_DELETE: if (pLastSel && CanDeleteNode(pLastSel)) { OnNodeDeleted(pLastSel); if (pLastSel->PrevSibling() == NULL) m_firstVisible = NULL; pLastSel->getmtNode()->deleteNode(); m_selection.Clear(); delete pLastSel; ForceLayout(); Invalidate(); } break; case VK_HOME: SendMessage(WM_VSCROLL,MAKEWPARAM(SB_TOP,0),NULL); SelectNode(m_firstVisible); break; case VK_END: { SendMessage(WM_VSCROLL,MAKEWPARAM(SB_BOTTOM,0),NULL); CTreeNode* pNode = GetLastVisibleNode(); if (pNode) SelectNode(GetLastVisibleNode()); } break; case VK_PRIOR: if (m_selection.lastSelected() && m_selection.lastSelected() == m_firstVisible) { // Already selected first vis. node, so page up. SendMessage(WM_VSCROLL,MAKEWPARAM(SB_PAGEUP,0),NULL); } else { SelectNode(m_firstVisible); } break; case VK_NEXT: if (m_selection.lastSelected() && m_selection.lastSelected() == GetLastVisibleNode()) { // Already selected last visible, so scroll down. SendMessage(WM_VSCROLL,MAKEWPARAM(SB_PAGEDOWN,0),NULL); } SelectNode(GetLastVisibleNode()); break; } CFrame::OnKeyDown(nChar, nRepCnt, nFlags); }
nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, nsISelectionController *aSelectionController, bool aIsFirstVisiblePreferred, bool aFindPrev, nsIPresShell **aPresShell, nsPresContext **aPresContext) { NS_ENSURE_ARG_POINTER(aContainer); NS_ENSURE_ARG_POINTER(aPresShell); NS_ENSURE_ARG_POINTER(aPresContext); *aPresShell = nullptr; *aPresContext = nullptr; nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); if (!docShell) return NS_ERROR_FAILURE; nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell(); nsRefPtr<nsPresContext> presContext; docShell->GetPresContext(getter_AddRefs(presContext)); if (!presShell || !presContext) return NS_ERROR_FAILURE; nsIDocument* doc = presShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; nsCOMPtr<nsIContent> rootContent; nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc)); if (htmlDoc) { nsCOMPtr<nsIDOMHTMLElement> bodyEl; htmlDoc->GetBody(getter_AddRefs(bodyEl)); rootContent = do_QueryInterface(bodyEl); } if (!rootContent) rootContent = doc->GetRootElement(); nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootContent)); if (!rootNode) return NS_ERROR_FAILURE; uint32_t childCount = rootContent->GetChildCount(); if (!mSearchRange) { mSearchRange = new nsRange(rootContent); } if (!mEndPointRange) { mEndPointRange = new nsRange(rootContent); } mSearchRange->SelectNodeContents(rootNode); mEndPointRange->SetEnd(rootNode, childCount); mEndPointRange->Collapse(false); // collapse to end // Consider current selection as null if // it's not in the currently focused document nsCOMPtr<nsIDOMRange> currentSelectionRange; nsCOMPtr<nsIPresShell> selectionPresShell = GetPresShell(); if (aSelectionController && selectionPresShell && selectionPresShell == presShell) { nsCOMPtr<nsISelection> selection; aSelectionController->GetSelection( nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (selection) selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange)); } if (!mStartPointRange) { mStartPointRange = new nsRange(doc); } if (!currentSelectionRange) { // Ensure visible range, move forward if necessary // This uses ignores the return value, but usese the side effect of // IsRangeVisible. It returns the first visible range after searchRange IsRangeVisible(presShell, presContext, mSearchRange, aIsFirstVisiblePreferred, true, getter_AddRefs(mStartPointRange), nullptr); } else { int32_t startOffset; nsCOMPtr<nsIDOMNode> startNode; if (aFindPrev) { currentSelectionRange->GetStartContainer(getter_AddRefs(startNode)); currentSelectionRange->GetStartOffset(&startOffset); } else { currentSelectionRange->GetEndContainer(getter_AddRefs(startNode)); currentSelectionRange->GetEndOffset(&startOffset); } if (!startNode) startNode = rootNode; // We need to set the start point this way, other methods haven't worked mStartPointRange->SelectNode(startNode); mStartPointRange->SetStart(startNode, startOffset); } mStartPointRange->Collapse(true); // collapse to start *aPresShell = presShell; NS_ADDREF(*aPresShell); *aPresContext = presContext; NS_ADDREF(*aPresContext); return NS_OK; }
//HOWTO: Search nodeptr that have a specific item and subitems also shows you how to select the node and delete it void CMySuperGrid::HowToSearch_I_am_using_hardcoded_values_here_cause_I_am_tired_now(void) { //one Item and two Subitems CTreeItem *pNode = Search(__T("Hello World"),_T("Happy"),_T("Programming"),NULL); if(pNode!=NULL) { CItemInfo *pInfo = GetData(pNode); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); } else AfxMessageBox(_T("not found")); //one Item and one Subitem CTreeItem *pNode1 = Search(_T("Mission: Impossible"),_T("Allan Nielsen"),NULL); if(pNode1!=NULL) { CItemInfo *pInfo = GetData(pNode1); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); } else AfxMessageBox(_T("not found")); //one Item and one Subitem CTreeItem *pNode2 = Search(_T("Training Agent"),_T("Mr. Bean"),NULL); if(pNode2!=NULL) { CItemInfo *pInfo = GetData(pNode2); AfxMessageBox(_T("Found Item") + pInfo->GetItemText()); } else AfxMessageBox(_T("not found")); CTreeItem *pNode3 = Search(_T("BC"),NULL); if(pNode3!=NULL) { CItemInfo *pInfo = GetData(pNode3); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); int nIndex = SelectNode(pNode3); if(nIndex!=-1) if(AfxMessageBox(_T("Do you want to delete it"),MB_OKCANCEL)==IDOK) DeleteItemEx(pNode3, nIndex); } else AfxMessageBox(_T("not found")); CTreeItem *pItem = NULL; POSITION pos = GetRootHeadPosition(); while(pos != NULL) { CTreeItem * pRoot = (CTreeItem*)GetNextRoot(pos); pItem = SearchEx(pRoot, "AB"); if(pItem!=NULL) { CItemInfo *pInfo = GetData(pItem); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); int nIndex = SelectNode(pItem); if(nIndex!=-1) if(AfxMessageBox(_T("Do you want to delete it"),MB_OKCANCEL)==IDOK) DeleteItemEx(pItem, nIndex); } } if( pItem == NULL ) AfxMessageBox(_T("not found")); }
bool EditorBodyControl::ProcessMouse(UIEvent *event) { Entity * selection = scene->GetProxy(); //selection with second mouse button if (event->tid == UIEvent::BUTTON_1) { if (event->phase == UIEvent::PHASE_BEGAN) { isDrag = false; inTouch = true; touchStart = event->point; if (selection) { modifiedNode = selection; transformBeforeModification = selection->GetLocalTransform(); } } else if (event->phase == UIEvent::PHASE_DRAG) { if (!isDrag) { Vector2 d = event->point - touchStart; if (selection && d.Length() > 5 && InModificationMode()) { ArrowsNode* arrowsNode = GetArrowsNode(false); if (arrowsNode && arrowsNode->GetModAxis() != ArrowsNode::AXIS_NONE) { isDrag = true; if (InputSystem::Instance()->GetKeyboard()->IsKeyPressed(DVKEY_SHIFT)) { originalNode = scene->GetProxy(); //create temporary node to calculate transform modifiedNode = originalNode->Clone(); originalNode->GetParent()->AddNode(modifiedNode); SelectNode(modifiedNode); selection = modifiedNode; //store original transform transformBeforeModification = modifiedNode->GetLocalTransform(); } if (selection) { scene->SetBulletUpdate(selection, false); inTouch = true; touchStart = event->point; startTransform = selection->GetLocalTransform(); InitMoving(event->point); translate1.CreateTranslation(-rotationCenter); translate2.CreateTranslation(rotationCenter); //calculate koefficient for moving Camera * cam = scene->GetCurrentCamera(); const Vector3 & camPos = cam->GetPosition(); const Matrix4 & wt = selection->GetWorldTransform(); Vector3 objPos = Vector3(0,0,0) * wt; Vector3 dir = objPos - camPos; moveKf = (dir.Length() - cam->GetZNear()) * 0.003; } } } } else { if (selection && InModificationMode()) { Landscape *landscape = dynamic_cast<Landscape *>(selection); if(!landscape) { PrepareModMatrix(event->point); if (IsLandscapeRelative()) { currTransform = currTransform * GetLandscapeOffset(currTransform); } selection->SetLocalTransform(currTransform); if(currentGraph) { currentGraph->UpdateMatricesForCurrentNode(); } } } } } else if (event->phase == UIEvent::PHASE_ENDED) { inTouch = false; if (isDrag) { // originalNode should be non-zero only when clone node if (originalNode) { // Get final transform from temporary node Matrix4 transform = modifiedNode->GetLocalTransform(); // Remove temporary node RemoveSelectedSGNode(); SafeRelease(modifiedNode); CommandCloneAndTransform* cmd = new CommandCloneAndTransform(originalNode, transform, this, scene->collisionWorld); CommandsManager::Instance()->ExecuteAndRelease(cmd, scene); originalNode = NULL; // update selection to newly created node selection = scene->GetProxy(); } else { CommandsManager::Instance()->ExecuteAndRelease(new CommandTransformObject(modifiedNode, transformBeforeModification, modifiedNode->GetLocalTransform()), scene); } if (selection) { scene->SetBulletUpdate(selection, true); } } else { Vector3 from, dir; GetCursorVectors(&from, &dir, event->point); Vector3 to = from + dir * 1000.0f; scene->TrySelection(from, to); selection = scene->GetProxy(); SelectNodeAtTree(selection); } } } else { cameraController->SetSelection(selection); if (event->phase == UIEvent::PHASE_KEYCHAR) { UITextField *tf = dynamic_cast<UITextField *>(UIControlSystem::Instance()->GetFocusedControl()); if(!tf) { cameraController->Input(event); } } else { cameraController->Input(event); } } ArrowsNode* arrowsNode = GetArrowsNode(false); if (arrowsNode && arrowsNode->GetVisible() && !inTouch && event->phase != UIEvent::PHASE_KEYCHAR) { Vector3 from, dir; GetCursorVectors(&from, &dir, event->point); Vector3 to = from + dir * 1000.0f; arrowsNode->ProcessMouse(event, from, dir); } return true; }