void mxTreeView::scrollTo( mxTreeViewItem *item ) { if (!d_this) return; TreeView_EnsureVisible( d_this->d_hwnd, item ); }
INT CALLBACK FolderBrowserDialog::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM pData) { static BOOL bProcessEnsureVisible = FALSE; switch(uMsg) { case BFFM_INITIALIZED: { //In case of Windows 7 and later //INFO: Correction for the Microsoft bug that doesn't // scroll the tree-view to the selected item... OSVERSIONINFOEX osi; DWORDLONG dwlConditionMask = 0; ::SecureZeroMemory(&osi, sizeof(OSVERSIONINFOEX)); osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osi.dwMajorVersion = 6; osi.dwMinorVersion = 1; VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); //if (GetVersionEx(&osi) && osi.dwMajorVersion >= 6 && osi.dwMinorVersion >= 1) if (VerifyVersionInfo(&osi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask)) bProcessEnsureVisible = TRUE; FolderBrowserDialog* bfd = FolderBrowserDialog::GetInstance(); if (!bfd) break; if (bfd->Title[0]) SetWindowTextW(hwnd,bfd->Title); if(bfd->curdir[0]) ::SendMessageW(hwnd, BFFM_SETSELECTIONW, TRUE, (LPARAM)bfd->curdir); else if (bfd->root) ::SendMessageW(hwnd, BFFM_SETSELECTIONW, FALSE, (LPARAM)bfd->root); return 1; } case BFFM_SELCHANGED: if (bProcessEnsureVisible) { bProcessEnsureVisible = FALSE; HWND hTreeView = 0; ::EnumChildWindows(hwnd, FolderBrowserDialog::FindTreeViewCallback, (LPARAM)&hTreeView); if (hTreeView) { HTREEITEM hItm = TreeView_GetSelection(hTreeView); if (hItm) { TreeView_EnsureVisible(hTreeView, hItm); TreeView_Expand(hTreeView, hItm, TVE_EXPAND); } } } break; } return 0; }
BOOLEAN FilterListOnDelete( IN HWND hWnd, IN UINT uMsg, IN WPARAM wp, IN LPARAM lp ) { int Index; int Count; HTREEITEM hTreeItem; HWND hWndTree; HWND hWndParent; Index = ListViewGetFirstSelected(hWnd); if (Index != -1) { ListViewGetParam(hWnd, Index, (LPARAM *)&hTreeItem); if (hTreeItem != NULL) { ListView_DeleteItem(hWnd, Index); hWndParent = GetParent(hWnd); hWndTree = GetDlgItem(hWndParent, IDC_TREE_FILTER); TreeView_EnsureVisible(hWndTree, hTreeItem); if (BspIsVistaAbove()) { TreeView_SetCheckState(hWndTree, hTreeItem, FALSE); } else { PostMessage(hWndParent, WM_TVN_UNCHECKITEM, (WPARAM)hTreeItem, 0); } Count = ListView_GetItemCount(hWnd); // // If the last item is deleted, start from 0 // if (Count > Index) { ListViewSelectSingle(hWnd, Index); } else { ListViewSelectSingle(hWnd, 0); } return TRUE; } } return FALSE; }
bool EnsureNodeVisible(_Ty Key) { HTREEITEM hItem = KeyToHandle(Key); if (NULL != hItem) { return WND_TRUE(TreeView_EnsureVisible(m_hWnd, hItem)); } return false; }
static LRESULT CALLBACK WndProcTocTree(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WindowInfo *win = FindWindowInfoByHwnd(hwnd); if (!win) return CallWindowProc(DefWndProcTocTree, hwnd, message, wParam, lParam); switch (message) { case WM_ERASEBKGND: return FALSE; case WM_CHAR: if (VK_ESCAPE == wParam && gGlobalPrefs->escToExit && MayCloseWindow(win)) CloseWindow(win, true); break; case WM_KEYDOWN: // consistently expand/collapse whole (sub)trees if (VK_MULTIPLY == wParam && IsShiftPressed()) TreeView_ExpandRecursively(hwnd, TreeView_GetRoot(hwnd), TVE_EXPAND); else if (VK_MULTIPLY == wParam) TreeView_ExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_EXPAND, true); else if (VK_DIVIDE == wParam && IsShiftPressed()) { HTREEITEM root = TreeView_GetRoot(hwnd); if (!TreeView_GetNextSibling(hwnd, root)) root = TreeView_GetChild(hwnd, root); TreeView_ExpandRecursively(hwnd, root, TVE_COLLAPSE); } else if (VK_DIVIDE == wParam) TreeView_ExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_COLLAPSE, true); else break; TreeView_EnsureVisible(hwnd, TreeView_GetSelection(hwnd)); return 0; case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL: // scroll the canvas if the cursor isn't over the ToC tree if (!IsCursorOverWindow(win->hwndTocTree)) return SendMessage(win->hwndCanvas, message, wParam, lParam); break; #ifdef DISPLAY_TOC_PAGE_NUMBERS case WM_SIZE: case WM_HSCROLL: // Repaint the ToC so that RelayoutTocItem is called for all items PostMessage(hwnd, WM_APP_REPAINT_TOC, 0, 0); break; case WM_APP_REPAINT_TOC: InvalidateRect(hwnd, nullptr, TRUE); UpdateWindow(hwnd); break; #endif } return CallWindowProc(DefWndProcTocTree, hwnd, message, wParam, lParam); }
void TffdshowPageBase::treeSelectItem(int uniqueId, int prevVisId) { for (HTREEITEM hti = TreeView_GetRoot(htv); hti; hti = TreeView_GetNextVisible(htv, hti)) { TconfPageBase *page = hti2page(hti); if (page->uniqueID() == uniqueId) { TreeView_SelectItem(htv, hti); if (prevVisId) for (HTREEITEM htivis = TreeView_GetRoot(htv); htivis; htivis = TreeView_GetNextVisible(htv, htivis)) { TconfPageBase *pagevis = hti2page(htivis); if (pagevis->uniqueID() == prevVisId) { TreeView_EnsureVisible(htv, htivis); } } return; } } }
int CALLBACK BrowseForFolderCallbackProc(HWND wnd_handle,UINT message,LPARAM lparam,LPARAM data){ static HWND edit_handle,tree_handle; switch(message){ case BFFM_INITIALIZED:{ if(data){ //初期ディレクトリ設定 SendMessage(wnd_handle,BFFM_SETSELECTION,(WPARAM)true,(LPARAM)data); edit_handle=::FindWindowEx(wnd_handle,NULL,WC_EDIT,NULL); if(edit_handle){ //エディットコントロールにオートコンプリート機能を実装 ::SHAutoComplete(edit_handle,SHACF_FILESYSTEM|SHACF_URLALL|SHACF_FILESYS_ONLY|SHACF_USETAB); } ::EnumChildWindows(wnd_handle,EnumChildCallbackProc,(LPARAM)&tree_handle); ::SetFocus(tree_handle); } break; } case BFFM_SELCHANGED:{ LPITEMIDLIST item_id_list=(LPITEMIDLIST)lparam; TCHAR directory[MAX_PATHW]={}; //TODO:マイコンピュータを素通りしてしまう if(SHGetPathFromIDList(item_id_list,directory)){ if(edit_handle){ SendMessage(edit_handle,WM_SETTEXT,(WPARAM)0,(LPARAM)path::addTailSlash(directory).c_str()); } } TreeView_Expand(tree_handle,TreeView_GetSelection(tree_handle),TVE_EXPAND); TreeView_EnsureVisible(tree_handle,TreeView_GetSelection(tree_handle)); ::SetFocus(tree_handle); break; } //無効なディレクトリ名であった場合 case BFFM_VALIDATEFAILED: return 1; default: break; } return 0; }
static bool HandleKey(HWND hwnd, WPARAM wp) { // consistently expand/collapse whole (sub)trees if (VK_MULTIPLY == wp && IsShiftPressed()) { TreeViewExpandRecursively(hwnd, TreeView_GetRoot(hwnd), TVE_EXPAND, false); } else if (VK_MULTIPLY == wp) { TreeViewExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_EXPAND, true); } else if (VK_DIVIDE == wp && IsShiftPressed()) { HTREEITEM root = TreeView_GetRoot(hwnd); if (!TreeView_GetNextSibling(hwnd, root)) root = TreeView_GetChild(hwnd, root); TreeViewExpandRecursively(hwnd, root, TVE_COLLAPSE, false); } else if (VK_DIVIDE == wp) { TreeViewExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_COLLAPSE, true); } else { return false; } TreeView_EnsureVisible(hwnd, TreeView_GetSelection(hwnd)); return true; }
//---------------------------------------------------// // TreeView_StartProc //---------------------------------------------------// BOOL TreeView_StartProc(HWND hWndActive) { GetmHpVarStruct()->hWndCurCtrl=NULL; /*if(*GetmHpVarStruct()->CourantTask->GetmHpCtrlName()!=0) { if(mHpPak_IsDotNetHwnd(hWndActive)) { int iState=0,iStyle=0; GetmHpVarStruct()->hWndCurCtrl=mHpPak_GetDotNetCtrlHandle(hWndActive,GetmHpVarStruct()->CourantTask->GetmHpCtrlName(),iStyle,iState); } }*/ if(!GetmHpVarStruct()->hWndCurCtrl) GetmHpVarStruct()->hWndCurCtrl=GetCtrlWnd(hWndActive,GetmHpVarStruct()->CourantTask->GetmHpCtrlID()); if(!IsCtrlReady(hWndActive,GetmHpVarStruct()->hWndCurCtrl)) return FALSE; RECT CtrlRct; GetWindowRect(GetmHpVarStruct()->hWndCurCtrl,&CtrlRct); GetmHpVarStruct()->SelItemListe->EmptyGroupListe(); GetTVitemSelList(GetmHpVarStruct()->hWndCurCtrl,TreeView_GetRoot(GetmHpVarStruct()->hWndCurCtrl),0); GetmHpVarStruct()->SelItemListe->ReplaceCurrent(); hCurSelItm=GetNexthTreeItemToSel(GetmHpVarStruct()->hWndCurCtrl,TreeView_GetRoot(GetmHpVarStruct()->hWndCurCtrl)); if(hCurSelItm==NULL) { bFindItm=FALSE; GetmHpVarStruct()->CourantTask->SetmHpStep(13); GetmHpVarStruct()->YnextPos=(int)(((CtrlRct.bottom-CtrlRct.top)/2)+CtrlRct.top); GetmHpVarStruct()->XnextPos=(int)(((CtrlRct.right-CtrlRct.left)/2)+CtrlRct.left); } else { bFindItm=TRUE; if(GetmHpVarStruct()->imHpMode==1) TreeView_EnsureVisible(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); RECT itmRct; TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&itmRct,TRUE); ListTreeStatusPos(hWndActive,itmRct); if(!GetmHpVarStruct()->AscensSens) { GetmHpVarStruct()->YnextPos=(int)(CtrlRct.top+((itmRct.bottom-itmRct.top)/2)+itmRct.top); GetmHpVarStruct()->XnextPos=(int)(CtrlRct.left+((itmRct.right-itmRct.left)/2)+itmRct.left); // Click | DoubleClick if(!GetmHpVarStruct()->SelItemListe->IsNextIndexExist()) GetmHpVarStruct()->CourantTask->SetmHpStep(10); } else // Not visible { GetmHpVarStruct()->CourantTask->SetmHpStep(10); MoveOnScrollBar(GetmHpVarStruct()->hWndCurCtrl,CtrlRct); } } return TRUE; }
LRESULT CALLBACK ContactListSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { TVITEM tvi; CCList *dat = CWndUserData(GetParent(hWnd)).GetCList(); switch (Msg) { case INTM_CONTACTDELETED: // wParam = (HANDLE)hContact { HTREEITEM hItem = dat->FindContact(wParam); if (hItem) TreeView_DeleteItem(hWnd, hItem); } break; case INTM_ICONCHANGED: // wParam = (HANDLE)hContact, lParam = IconID tvi.hItem = dat->FindContact(wParam); if (tvi.hItem) { tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.iImage = tvi.iSelectedImage = lParam; TreeView_SetItem(hWnd, &tvi); dat->SortContacts(); InvalidateRect(hWnd, nullptr, false); } break; case INTM_INVALIDATE: InvalidateRect(hWnd, nullptr, true); break; case WM_RBUTTONDOWN: SetFocus(hWnd); { TVHITTESTINFO hitTest; hitTest.pt.x = (short)LOWORD(lParam); hitTest.pt.y = (short)HIWORD(lParam); TreeView_HitTest(hWnd, &hitTest); if (hitTest.hItem && hitTest.flags & TVHT_ONITEM) TreeView_SelectItem(hWnd, hitTest.hItem); } return DefWindowProc(hWnd, Msg, wParam, lParam); case WM_LBUTTONDOWN: { POINT pt = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DWORD hitFlags; HTREEITEM hItem = dat->HitTest(&pt, &hitFlags); if (!hItem) break; if (hitFlags & MCLCHT_ONITEMICON) { if (TreeView_GetChild(hWnd, hItem)) { // if it's a group, then toggle its state NMTREEVIEW nmtv; nmtv.hdr.hwndFrom = hWnd; nmtv.hdr.idFrom = GetDlgCtrlID(hWnd); nmtv.hdr.code = TVN_ITEMEXPANDING; nmtv.action = TVE_TOGGLE; nmtv.itemNew.hItem = hItem; nmtv.itemNew.mask = TVIF_HANDLE | TVIF_STATE | TVIF_PARAM; TreeView_GetItem(hWnd, &nmtv.itemNew); nmtv.ptDrag = pt; if (SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nmtv)) return 0; HTREEITEM hOldSelItem = TreeView_GetSelection(hWnd); TreeView_Expand(hWnd, hItem, TVE_TOGGLE); HTREEITEM hNewSelItem = TreeView_GetSelection(hWnd); if (hNewSelItem != hOldSelItem) { TreeView_SetItemState(hWnd, hOldSelItem, (dat->SelectedItems.Find(hOldSelItem) == -1) ? 0 : TVIS_SELECTED, TVIS_SELECTED); TreeView_SetItemState(hWnd, hNewSelItem, (dat->SelectedItems.Find(hNewSelItem) == -1) ? 0 : TVIS_SELECTED, TVIS_SELECTED); } nmtv.hdr.code = TVN_ITEMEXPANDED; TreeView_GetItem(hWnd, &nmtv.itemNew); SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nmtv); return 0; } } if (hitFlags & MCLCHT_ONITEM) { if (wParam & MK_CONTROL) { SetFocus(hWnd); TREEITEMARRAY OldSelection = dat->SelectedItems; int nIndex = dat->SelectedItems.Find(hItem); if (nIndex == -1) { TreeView_SetItemState(hWnd, hItem, TVIS_SELECTED, TVIS_SELECTED); dat->SelectedItems.AddElem(hItem); } else { TreeView_SetItemState(hWnd, hItem, 0, TVIS_SELECTED); dat->SelectedItems.RemoveElem(nIndex); } dat->SelectGroups(hItem, nIndex == -1); NMCLIST nm; nm.hdr.code = MCLN_SELCHANGED; nm.hdr.hwndFrom = hWnd; nm.hdr.idFrom = GetDlgCtrlID(hWnd); nm.OldSelection = &OldSelection; nm.NewSelection = &dat->SelectedItems; SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nm); return 0; } // if it was a click on the selected item and there's need to do something in this case, then send SELCHANGED notification by ourselves, as the tree control doesn't do anything if (hItem == TreeView_GetSelection(hWnd) && (dat->SelectedItems.GetSize() != 1 || (dat->SelectedItems.GetSize() == 1 && dat->SelectedItems[0] != hItem))) { TreeView_SetItemState(hWnd, hItem, TVIS_SELECTED, TVIS_SELECTED); NMTREEVIEW nm = {}; nm.hdr.code = TVN_SELCHANGED; nm.hdr.hwndFrom = hWnd; nm.hdr.idFrom = GetDlgCtrlID(hWnd); nm.itemOld.hItem = TreeView_GetSelection(hWnd); nm.itemOld.mask = TVIF_HANDLE | TVIF_STATE | TVIF_PARAM; TreeView_GetItem(hWnd, &nm.itemOld); nm.itemNew = nm.itemOld; SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nm); } } } break; case WM_SETFOCUS: case WM_KILLFOCUS: for (int i = 0; i < dat->SelectedItems.GetSize(); i++) { RECT rc; if (TreeView_GetItemRect(hWnd, dat->SelectedItems[i], &rc, false)) InvalidateRect(hWnd, &rc, false); } break; case WM_SIZE: case WM_HSCROLL: InvalidateRect(hWnd, nullptr, false); break; case WM_MEASUREITEM: if (!wParam) // if the message was sent by a menu return Menu_MeasureItem(lParam); break; case WM_DRAWITEM: if (!wParam) // if the message was sent by a menu return Menu_DrawItem(lParam); break; case WM_CONTEXTMENU: { POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; HTREEITEM hItem = nullptr; if (pt.x == -1 && pt.y == -1) { if (dat->SelectedItems.GetSize() == 1) { hItem = dat->SelectedItems[0]; TreeView_EnsureVisible(hWnd, hItem); RECT rc; TreeView_GetItemRect(hWnd, hItem, &rc, true); pt.x = rc.left; pt.y = rc.bottom; } } else { DWORD hitFlags; ScreenToClient(hWnd, &pt); hItem = dat->HitTest(&pt, &hitFlags); if (!(hitFlags & MCLCHT_ONITEM)) hItem = nullptr; } if (hItem) { MCONTACT hContact = dat->GetItemData(hItem).hContact; if (IsHContactContact(hContact)) { HMENU hMenu = Menu_BuildContactMenu(hContact); if (hMenu) { ClientToScreen(hWnd, &pt); Clist_MenuProcessCommand(TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, nullptr), MPCF_CONTACTMENU, hContact); DestroyMenu(hMenu); return 0; } } } } break; case WM_DESTROY: if (dat->ExtraImageList) ImageList_Destroy(dat->ExtraImageList); dat->SelectedItems.RemoveAll(); dat->Items.RemoveAll(); break; } return CallWindowProc(dat->OrigTreeViewProc, hWnd, Msg, wParam, lParam); }
/** * Makes sure the item is visible */ void CTreeControl::ensureVisible(CTreeItem* _item) { TreeView_EnsureVisible(hwnd, _item->handle); }
static LRESULT CALLBACK MsgTreeSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { CMsgTree *dat = CWndUserData(GetParent(hWnd)).GetMsgTree(); switch (Msg) { case UM_MSGTREE_UPDATE: // returns TRUE if updated { bool Modified = dat->MsgTreePage.GetModified(); TCString WndTitle; if (Modified) { WndTitle.GetBuffer(256); HWND hCurWnd = hWnd; do { hCurWnd = GetParent(hCurWnd); } while (hCurWnd && !GetWindowText(hCurWnd, WndTitle, 256)); WndTitle.ReleaseBuffer(); } if (!Modified || MessageBox(GetParent(hWnd), TCString(TranslateT("You've made changes to multiple message trees at a time.\r\nDo you want to leave changes in \"")) + WndTitle + TranslateT("\" dialog?\r\nPress Yes to leave changes in this dialog, or No to discard its changes and save changes of the other message tree instead."), WndTitle + _T(" - ") + TranslateT("New Away System"), MB_ICONQUESTION | MB_YESNO) == IDNO) { COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); TCString OldTitle, OldMsg, NewTitle, NewMsg; int OldOrder = TreeCtrl->IDToOrder(TreeCtrl->GetSelectedItemID(GetParent(hWnd))); if (OldOrder != -1) { CBaseTreeItem* ItemOld = (OldOrder <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(OldOrder)] : (CBaseTreeItem*)&TreeCtrl->Value[OldOrder]; OldTitle = ItemOld->Title; if (!(ItemOld->Flags & TIF_ROOTITEM)) OldMsg = ((CTreeItem*)ItemOld)->User_Str1; } dat->UpdateLock++; dat->MsgTreePage.DBToMemToPage(); dat->UpdateLock--; NMMSGTREE nm = { 0 }; int Order = TreeCtrl->IDToOrder(TreeCtrl->GetSelectedItemID(GetParent(hWnd))); if (Order != -1) { nm.ItemNew = (Order <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(Order)] : (CBaseTreeItem*)&TreeCtrl->Value[Order]; NewTitle = nm.ItemNew->Title; if (!(nm.ItemNew->Flags & TIF_ROOTITEM)) NewMsg = ((CTreeItem*)nm.ItemNew)->User_Str1; } if (OldTitle.IsEmpty()) OldTitle = _T(""); // to be sure that NULL will be equal to "" in the latter comparisons if (OldMsg.IsEmpty()) OldMsg = _T(""); if (NewTitle.IsEmpty()) NewTitle = _T(""); if (NewMsg.IsEmpty()) NewMsg = _T(""); if (OldTitle != (const TCHAR*)NewTitle || OldMsg != (const TCHAR*)NewMsg) { // probably it's better to leave nm.ItemOld = NULL, to prevent accidental rewriting of it with old data from an edit control etc. nm.hdr.code = MTN_SELCHANGED; nm.hdr.hwndFrom = hWnd; nm.hdr.idFrom = GetDlgCtrlID(hWnd); SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nm); } return true; } } return false; case WM_KEYDOWN: switch (wParam) { case VK_DELETE: dat->DeleteSelectedItem(); break; case VK_INSERT: dat->AddMessage(); break; } break; case WM_RBUTTONDOWN: SetFocus(hWnd); { TVHITTESTINFO hitTest; hitTest.pt.x = (short)LOWORD(lParam); hitTest.pt.y = (short)HIWORD(lParam); TreeView_HitTest(hWnd, &hitTest); if (hitTest.hItem && hitTest.flags & TVHT_ONITEM) TreeView_SelectItem(hWnd, hitTest.hItem); return DefWindowProc(hWnd, Msg, wParam, lParam); } break; case WM_CONTEXTMENU: { TVHITTESTINFO ht; ht.pt.x = GET_X_LPARAM(lParam); ht.pt.y = GET_Y_LPARAM(lParam); TVITEM tvi = { 0 }; if (ht.pt.x == -1 && ht.pt.y == -1) { // use selected item if (tvi.hItem = TreeView_GetSelection(hWnd)) { TreeView_EnsureVisible(hWnd, tvi.hItem); RECT rc; TreeView_GetItemRect(hWnd, tvi.hItem, &rc, true); ht.pt.x = rc.left; ht.pt.y = rc.bottom; } } else { ScreenToClient(hWnd, &ht.pt); TreeView_HitTest(hWnd, &ht); if (ht.hItem && ht.flags & TVHT_ONITEM) { tvi.hItem = ht.hItem; } } if (tvi.hItem) { COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(hWnd, &tvi); int Order = TreeCtrl->IDToOrder(tvi.lParam); if (Order >= 0) { HMENU hMenu; if (TreeCtrl->Value[Order].Flags & TIF_GROUP) hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MSGTREE_CATEGORYMENU)); else hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MSGTREE_MESSAGEMENU)); _ASSERT(hMenu); HMENU hPopupMenu = GetSubMenu(hMenu, 0); TranslateMenu(hPopupMenu); ClientToScreen(hWnd, &ht.pt); struct { int ItemID, IconID; } MenuItems[] = { IDM_MSGTREEMENU_NEWMESSAGE, IMGLIST_NEWMESSAGE, IDM_MSGTREEMENU_NEWCATEGORY, IMGLIST_NEWCATEGORY, IDM_MSGTREEMENU_DELETE, IMGLIST_DELETE }; MENUITEMINFO mii = { 0 }; mii.cbSize = sizeof(mii); mii.fMask = MIIM_BITMAP | MIIM_DATA | MIIM_STATE | MIIM_CHECKMARKS; mii.hbmpItem = HBMMENU_CALLBACK; int i; for (i = 0; i < _countof(MenuItems); i++) { // set icons mii.dwItemData = MenuItems[i].IconID; SetMenuItemInfo(hPopupMenu, MenuItems[i].ItemID, false, &mii); } mii.fMask = MIIM_STATE; mii.fState = MFS_CHECKED; for (i = 0; i < _countof(SettingsList); i++) // set checkmarks if (TreeCtrl->Value[Order].ID == dat->MsgTreePage.GetValue(SettingsList[i].DBSetting)) SetMenuItemInfo(hPopupMenu, SettingsList[i].MenuItemID, false, &mii); int MenuResult = TrackPopupMenu(hPopupMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, ht.pt.x, ht.pt.y, 0, hWnd, NULL); switch (MenuResult) { case IDM_MSGTREEMENU_NEWMESSAGE: dat->AddMessage(); break; case IDM_MSGTREEMENU_NEWCATEGORY: dat->AddCategory(); break; case IDM_MSGTREEMENU_RENAME: TreeView_EditLabel(hWnd, tvi.hItem); break; case IDM_MSGTREEMENU_DELETE: dat->DeleteSelectedItem(); break; case IDR_MSGTREEMENU_DEF_ONL: case IDR_MSGTREEMENU_DEF_AWAY: case IDR_MSGTREEMENU_DEF_NA: case IDR_MSGTREEMENU_DEF_OCC: case IDR_MSGTREEMENU_DEF_DND: case IDR_MSGTREEMENU_DEF_FFC: case IDR_MSGTREEMENU_DEF_INV: case IDR_MSGTREEMENU_DEF_OTP: case IDR_MSGTREEMENU_DEF_OTL: for (int i = 0; i < _countof(SettingsList); i++) { if (SettingsList[i].MenuItemID == MenuResult) { dat->SetDefMsg(SettingsList[i].Status, tvi.lParam); break; } } } DestroyMenu(hMenu); return 0; } } } break; case WM_MEASUREITEM: { LPMEASUREITEMSTRUCT lpmi = (LPMEASUREITEMSTRUCT)lParam; if (lpmi->CtlType == ODT_MENU) { lpmi->itemWidth = max(0, GetSystemMetrics(SM_CXSMICON) - GetSystemMetrics(SM_CXMENUCHECK) + 4); lpmi->itemHeight = GetSystemMetrics(SM_CYSMICON) + 2; return true; } } break; case WM_DRAWITEM: { LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; if (dis->CtlType == ODT_MENU) { ImageList_DrawEx(dat->hImageList, dis->itemData, dis->hDC, 2, (dis->rcItem.bottom + dis->rcItem.top - GetSystemMetrics(SM_CYSMICON)) / 2 + 1, 0, 0, GetSysColor(COLOR_WINDOW), CLR_NONE, ILD_NORMAL); return true; } } break; } return CallWindowProc(dat->OrigTreeViewProc, hWnd, Msg, wParam, lParam); }
void TrayNotifyDlg::Refresh() { ///@todo refresh incrementally HiddenWindow hide(_tree_ctrl); TreeView_DeleteAllItems(_tree_ctrl); TV_INSERTSTRUCT tvi; tvi.hParent = 0; tvi.hInsertAfter = TVI_LAST; TV_ITEM& tv = tvi.item; tv.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE; ResString str_cur(IDS_ITEMS_CUR); tv.pszText = str_cur.str(); tv.iSelectedImage = tv.iImage = 0; // IDI_DOT _hitemCurrent = TreeView_InsertItem(_tree_ctrl, &tvi); ResString str_conf(IDS_ITEMS_CONFIGURED); tv.pszText = str_conf.str(); tv.iSelectedImage = tv.iImage = 2; // IDI_DOT_RED _hitemConfig = TreeView_InsertItem(_tree_ctrl, &tvi); tvi.hParent = _hitemCurrent; ResString str_visible(IDS_ITEMS_VISIBLE); tv.pszText = str_visible.str(); tv.iSelectedImage = tv.iImage = 0; // IDI_DOT _hitemCurrent_visible = TreeView_InsertItem(_tree_ctrl, &tvi); ResString str_hidden(IDS_ITEMS_HIDDEN); tv.pszText = str_hidden.str(); tv.iSelectedImage = tv.iImage = 1; // IDI_DOT_TRANS _hitemCurrent_hidden = TreeView_InsertItem(_tree_ctrl, &tvi); if (_pNotifyArea) { _info.clear(); tv.mask |= TVIF_PARAM; WindowCanvas canvas(_hwnd); // insert current (visible and hidden) items for(NotifyIconMap::const_iterator it=_pNotifyArea->_icon_map.begin(); it!=_pNotifyArea->_icon_map.end(); ++it) { const NotifyInfo& entry = it->second; InsertItem(entry._dwState&NIS_HIDDEN? _hitemCurrent_hidden: _hitemCurrent_visible, TVI_LAST, entry, canvas); } // insert configured items in tree view const NotifyIconCfgList& cfg = _pNotifyArea->_cfg; for(NotifyIconCfgList::const_iterator it=cfg.begin(); it!=cfg.end(); ++it) { const NotifyIconConfig& cfg_entry = *it; HICON hicon = 0; if (!cfg_entry._modulePath.empty()) { if ((int)ExtractIconEx(cfg_entry._modulePath, 0, NULL, &hicon, 1) <= 0) hicon = 0; if (!hicon) { SHFILEINFO sfi; if (SHGetFileInfo(cfg_entry._modulePath, 0, &sfi, sizeof(sfi), SHGFI_ICON|SHGFI_SMALLICON)) hicon = sfi.hIcon; } } InsertItem(_hitemConfig, TVI_SORT, cfg_entry, canvas, hicon, cfg_entry._mode); if (hicon) DestroyIcon(hicon); } CheckDlgButton(_hwnd, ID_SHOW_HIDDEN_ICONS, _pNotifyArea->_show_hidden? BST_CHECKED: BST_UNCHECKED); } TreeView_Expand(_tree_ctrl, _hitemCurrent_visible, TVE_EXPAND); TreeView_Expand(_tree_ctrl, _hitemCurrent_hidden, TVE_EXPAND); TreeView_Expand(_tree_ctrl, _hitemCurrent, TVE_EXPAND); TreeView_Expand(_tree_ctrl, _hitemConfig, TVE_EXPAND); TreeView_EnsureVisible(_tree_ctrl, _hitemCurrent_visible); }
//---------------------------------------------------// // TreeView_mHpProcess //---------------------------------------------------// void TreeView_mHpProcess(HWND hWndActive,BOOL &bChangeWnd,int iCurrentWnd,int iCountWnd) { switch(GetmHpVarStruct()->CourantTask->GetmHpStep()) { case 2: // 1° CLICK { EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,7); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 3: // DELAY { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_PRESS)); SetTimer(hWndActive,ID_TIMER_DELAI,50,(TIMERPROC)mHpTimerProc); break; } case 4: // UNCLICK + Selection { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); if(GetFocus()!=GetmHpVarStruct()->hWndCurCtrl) SetFocus(GetmHpVarStruct()->hWndCurCtrl); TreeView_SelectItem(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 5: // DELAY { SetTimer(hWndActive,ID_TIMER_DELAI,1,(TIMERPROC)mHpTimerProc); break; } case 6: // 2° CLICK { EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,8); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 7: // DELAY { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_PRESS)); SetTimer(hWndActive,ID_TIMER_DELAI,50,(TIMERPROC)mHpTimerProc); break; } case 8: // UNCLICK + Expand { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); TreeView_Expand(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,TVE_EXPAND); EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 9: // DELAY { SetTimer(hWndActive,ID_TIMER_DELAI,400,(TIMERPROC)mHpTimerProc); break; } case 10: // NEXT SELECTION { GetmHpVarStruct()->SelItemListe->ItemIndexSuivant(); hCurSelItm=GetNexthTreeItemToSel(GetmHpVarStruct()->hWndCurCtrl,TreeView_GetChild(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm)); if(hCurSelItm!=NULL) { RECT CtlRct; GetWindowRect(GetmHpVarStruct()->hWndCurCtrl,&CtlRct); GetmHpVarStruct()->bRefreshDDraw=TRUE; GetmHpVarStruct()->bNewDepl=TRUE; RECT ItmRct; TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&ItmRct,TRUE); ListTreeStatusPos(hWndActive,ItmRct); if(!GetmHpVarStruct()->AscensSens) { // When the last visible item is selected, that launch an auto-scroll TreeView_EnsureVisible(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&ItmRct,TRUE); // GetmHpVarStruct()->YnextPos=(int)(CtlRct.top+((ItmRct.bottom-ItmRct.top)/2)+ItmRct.top); GetmHpVarStruct()->XnextPos=(int)(CtlRct.left+((ItmRct.right-ItmRct.left)/2)+ItmRct.left); // DoubleClick | Click if(GetmHpVarStruct()->SelItemListe->IsNextIndexExist()) GetmHpVarStruct()->CourantTask->SetmHpStep(1); } else MoveOnScrollBar(GetmHpVarStruct()->hWndCurCtrl,CtlRct); // Not visible SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else // END { GetmHpVarStruct()->CourantTask->SetmHpStep(14); SetTimer(hWndActive,ID_TIMER_DELAI,1,(TIMERPROC)mHpTimerProc); } break; } case 11: // CLICK { GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); GetmHpVarStruct()->CursorType=1; SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 12: // DELAY { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_PRESS)); SetTimer(hWndActive,ID_TIMER_DELAI,150,(TIMERPROC)mHpTimerProc); break; } case 13: // LAST SELECTION { RECT ctlRct; RECT itmRct; int iLastAscens; if(!GetmHpVarStruct()->AscensSens) { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); if(GetFocus()!=GetmHpVarStruct()->hWndCurCtrl) SetFocus(GetmHpVarStruct()->hWndCurCtrl); TreeView_SelectItem(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); GetmHpVarStruct()->CourantTask->SetmHpStep(14); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else { switch(GetmHpVarStruct()->AscensSens) { case 1: // UP { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_VERT)-1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } case 2: // DOWN { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_VERT)+1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } case 3: // RIGHT { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_HORZ)+1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } case 4: // LEFT { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_HORZ)-1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } } iLastAscens=GetmHpVarStruct()->AscensSens; GetWindowRect(GetmHpVarStruct()->hWndCurCtrl,&ctlRct); TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&itmRct,TRUE); ListTreeStatusPos(hWndActive,itmRct); if(!GetmHpVarStruct()->AscensSens) { // When the last visible item is selected, that launch an auto-scroll TreeView_EnsureVisible(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&itmRct,TRUE); // GetmHpVarStruct()->YnextPos=(int)(ctlRct.top+((itmRct.bottom-itmRct.top)/2)+itmRct.top); GetmHpVarStruct()->XnextPos=(int)(ctlRct.left+((itmRct.right-itmRct.left)/2)+itmRct.left); // DoubleClick | Click if(GetmHpVarStruct()->SelItemListe->IsNextIndexExist()) GetmHpVarStruct()->CourantTask->SetmHpStep(1); else GetmHpVarStruct()->CourantTask->SetmHpStep(10); PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; GetmHpVarStruct()->bNewDepl=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else // Not visible { if(iLastAscens!=GetmHpVarStruct()->AscensSens) { MoveOnScrollBar(GetmHpVarStruct()->hWndCurCtrl,ctlRct); GetmHpVarStruct()->CourantTask->SetmHpStep(10); PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; GetmHpVarStruct()->bNewDepl=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else { GetmHpVarStruct()->CourantTask->SetmHpStep(12); SetTimer(hWndActive,ID_TIMER_DELAI,200,(TIMERPROC)mHpTimerProc); } } } break; } case 14: { if((!bFindItm)&&(GetmHpVarStruct()->CourantTask->GetmHpOption()>=10)) ViewCtrlNotReadyMsg(hWndActive,4); else SetTimer(hWndActive,ID_TIMER_DELAI,300,(TIMERPROC)mHpTimerProc); break; } case 15: { if(GetmHpVarStruct()->TaskList->NextCellule()) { GetmHpVarStruct()->bNewDepl=TRUE; SetDDrawObj(hWndActive,0); GetmHpVarStruct()->CourantTask=GetmHpVarStruct()->TaskList->GetCurrentTask(); GetNextPos(hWndActive); } else NextRepeatAssistProc(hWndActive); break; } default: NULL; } }
BOOL plComponentDlg::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: fhDlg = hDlg; IAddComponentsRecur(GetDlgItem(hDlg, IDC_TREE), (plMaxNode*)GetCOREInterface()->GetRootNode()); ICreateMenu(); ICreateRightClickMenu(); return TRUE; case WM_SIZING: IPositionControls((RECT*)lParam, wParam); return TRUE; case WM_ACTIVATE: if (LOWORD(wParam) == WA_INACTIVE) plMaxAccelerators::Enable(); else plMaxAccelerators::Disable(); return TRUE; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDCANCEL) { ShowWindow(hDlg, SW_HIDE); fInterface->UnRegisterDlgWnd(hDlg); return TRUE; } else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_ATTACH) { IAttachTreeSelection(); return TRUE; } else if (HIWORD(wParam) == EN_KILLFOCUS && LOWORD(wParam) == IDC_COMMENTS) { IGetComment(); return TRUE; } // "Refresh" menu item else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == ID_REFRESH) { IRefreshTree(); return TRUE; } // "Remove unused components" menu item else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == ID_REMOVE_UNUSED) { IRemoveUnusedComps(); return TRUE; } // Item selected from 'New' menu else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) >= MENU_ID_START) { ClassDesc *desc = plComponentMgr::Inst().Get(LOWORD(wParam)-MENU_ID_START); // If this is a component type (not a category) if (desc) { // Create an object of that type and a node to reference it Object *obj = (Object*)GetCOREInterface()->CreateInstance(desc->SuperClassID(), desc->ClassID()); INode *node = GetCOREInterface()->CreateObjectNode(obj); plComponentBase *comp = (plComponentBase*)obj; node->Hide(!comp->AllowUnhide()); node->Freeze(TRUE); // Add the new component to the tree HWND hTree = GetDlgItem(hDlg, IDC_TREE); HTREEITEM item = IAddComponent(hTree, (plMaxNode*)node); TreeView_SelectItem(hTree, item); TreeView_EnsureVisible(hTree, item); } } break; case WM_NOTIFY: NMHDR *nmhdr = (NMHDR*)lParam; if (nmhdr->idFrom == IDC_TREE) { switch (nmhdr->code) { case TVN_SELCHANGED: { NMTREEVIEW *tv = (NMTREEVIEW*)lParam; IGetComment(); bool isComponent = IIsComponent(tv->itemNew.lParam); // If the new selection is a component, enable the attach button and comment field EnableWindow(GetDlgItem(hDlg, IDC_ATTACH), isComponent); SendDlgItemMessage(hDlg, IDC_COMMENTS, EM_SETREADONLY, !isComponent, 0); if (isComponent) { fCommentNode = (plMaxNode*)tv->itemNew.lParam; TSTR buf; fCommentNode->GetUserPropBuffer(buf); SetDlgItemText(hDlg, IDC_COMMENTS, buf); } else { fCommentNode = nil; SetDlgItemText(hDlg, IDC_COMMENTS, ""); } return TRUE; } break; case TVN_BEGINLABELEDIT: // If this isn't a component, don't allow the edit if (!IIsComponent(((NMTVDISPINFO*)lParam)->item.lParam)) { SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); return TRUE; } // The edit box this creates kills the focus on our window, causing // accelerators to be enabled. Add an extra disable to counteract that. plMaxAccelerators::Disable(); return TRUE; // Finishing changing the name of a component case TVN_ENDLABELEDIT: { NMTVDISPINFO *di = (NMTVDISPINFO*)lParam; char* text = di->item.pszText; // If the name was changed... if (text && *text != '\0') { // Update the name of the node plMaxNode *node = IGetTreeSelection(); node->SetName(text); // Update the name in the panel too if (plComponentUtil::Instance().IsOpen()) plComponentUtil::Instance().IUpdateNodeName(node); // Make sure Max knows the file was changed SetSaveRequiredFlag(); // Return true to keep the changes SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); } plMaxAccelerators::Enable(); } return TRUE; // User double-clicked. Select the objects the selected component is attached to. case NM_DBLCLK: ISelectTreeSelection(); return TRUE; case NM_RCLICK: IOpenRightClickMenu(); return TRUE; case TVN_KEYDOWN: // User pressed delete if (((NMTVKEYDOWN*)lParam)->wVKey == VK_DELETE) { IDeleteComponent(IGetTreeSelection()); return TRUE; } break; } } break; } return FALSE; }
static void RebuildPageTree(HWND hdlg, OptionsDlgData *dat) { BOOL bRemoveFocusFromFilter = FALSE; HINSTANCE FilterInst = NULL; LPARAM oldSel = SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, CB_GETEDITSEL, 0, 0); GetDlgItemText(hdlg, IDC_KEYWORD_FILTER, dat->szFilterString, SIZEOF(dat->szFilterString)); //if filter string is set to all modules then make the filter string empty (this will return all modules) if (_tcscmp(dat->szFilterString, TranslateT(ALL_MODULES_FILTER)) == 0) { dat->szFilterString[0] = 0; bRemoveFocusFromFilter = TRUE; } //if filter string is set to core modules replace it with the name of the executable (this will return all core modules) else if (_tcscmp(dat->szFilterString, TranslateT(CORE_MODULES_FILTER)) == 0) { //replace string with process name - that will show core settings TCHAR szFileName[300]; GetModuleFileName(NULL, szFileName, SIZEOF(szFileName)); TCHAR *pos = _tcsrchr(szFileName, _T('\\')); if (pos) pos++; else pos = szFileName; _tcsncpy(dat->szFilterString, pos, SIZEOF(dat->szFilterString)); } else { int sel = SendMessage(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), (UINT)CB_GETCURSEL, 0, 0); if (sel != -1) { HINSTANCE hinst = (HINSTANCE)SendMessage(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), (UINT)CB_GETITEMDATA, sel, 0); TCHAR szFileName[300]; GetModuleFileName(hinst, szFileName, SIZEOF(szFileName)); TCHAR *pos = _tcsrchr(szFileName, _T('\\')); if (pos) pos++; else pos = szFileName; _tcsncpy(dat->szFilterString, pos, SIZEOF(dat->szFilterString)); } } _tcslwr_locale(dat->szFilterString); //all strings are stored as lowercase ... make sure filter string is lowercase too HWND hwndTree = GetDlgItem(hdlg, IDC_PAGETREE); SendMessage(hwndTree, WM_SETREDRAW, FALSE, 0); HWND oldWnd = NULL; HWND oldTab = NULL; OptionsPageData *opd = dat->getCurrent(); if (opd != NULL) { oldWnd = opd->hwnd; if (opd->insideTab) oldTab = GetDlgItem(hdlg, IDC_TAB); } dat->hCurrentPage = NULL; TreeView_SelectItem(hwndTree, NULL); TreeView_DeleteAllItems(hwndTree); TVINSERTSTRUCT tvis; tvis.hParent = NULL; tvis.hInsertAfter = TVI_SORT; tvis.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM; tvis.item.state = tvis.item.stateMask = TVIS_EXPANDED; for (int i = 0; i < dat->arOpd.getCount(); i++) { static TCHAR *fullTitle = NULL; mir_free(fullTitle); fullTitle = NULL; if (!CheckPageShow(hdlg, dat, i)) continue; opd = dat->arOpd[i]; TCHAR *ptszGroup = TranslateTH(opd->hLangpack, opd->ptszGroup); TCHAR *ptszTitle = opd->getString(opd->ptszTitle); TCHAR *ptszTab = TranslateTH(opd->hLangpack, opd->ptszTab); tvis.hParent = NULL; if (FilterInst != NULL) { size_t sz = ptszGroup ? _tcslen(ptszGroup) + 1 : 0; if (sz) sz += 3; sz += ptszTitle ? _tcslen(ptszTitle) + 1 : 0; fullTitle = (TCHAR*)mir_alloc(sz*sizeof(TCHAR)); mir_sntprintf(fullTitle, sz, (ptszGroup && ptszTitle) ? _T("%s - %s") : _T("%s%s"), ptszGroup ? ptszGroup : _T(""), ptszTitle ? ptszTitle : _T("")); } TCHAR *useTitle = fullTitle ? fullTitle : ptszTitle; if (ptszGroup != NULL && FilterInst == NULL) { tvis.hParent = FindNamedTreeItemAtRoot(hwndTree, ptszGroup); if (tvis.hParent == NULL) { tvis.item.lParam = -1; tvis.item.pszText = ptszGroup; tvis.hParent = TreeView_InsertItem(hwndTree, &tvis); } } else { TVITEM tvi; tvi.hItem = FindNamedTreeItemAtRoot(hwndTree, useTitle); if (tvi.hItem != NULL) { if (i == dat->currentPage) dat->hCurrentPage = tvi.hItem; tvi.mask = TVIF_PARAM; TreeView_GetItem(hwndTree, &tvi); if (tvi.lParam == -1) { tvi.lParam = i; TreeView_SetItem(hwndTree, &tvi); continue; } } } if (ptszTab != NULL) { HTREEITEM hItem; if (tvis.hParent == NULL) hItem = FindNamedTreeItemAtRoot(hwndTree, useTitle); else hItem = FindNamedTreeItemAtChildren(hwndTree, tvis.hParent, useTitle); if (hItem != NULL) { if (i == dat->currentPage) { TVITEM tvi; tvi.hItem = hItem; tvi.mask = TVIF_PARAM; tvi.lParam = dat->currentPage; TreeView_SetItem(hwndTree, &tvi); dat->hCurrentPage = hItem; } continue; } } tvis.item.pszText = useTitle; tvis.item.lParam = i; opd->hTreeItem = TreeView_InsertItem(hwndTree, &tvis); if (i == dat->currentPage) dat->hCurrentPage = opd->hTreeItem; if (fullTitle) mir_free(fullTitle); fullTitle = NULL; } char str[128]; TVITEMA tvi; tvi.mask = TVIF_TEXT | TVIF_STATE; tvi.pszText = str; tvi.cchTextMax = SIZEOF(str); tvi.hItem = TreeView_GetRoot(hwndTree); while (tvi.hItem != NULL) { if (SendMessageA(hwndTree, TVM_GETITEMA, 0, (LPARAM)&tvi)) { char buf[130]; mir_snprintf(buf, SIZEOF(buf), "%s%s", OPTSTATE_PREFIX, str); if (!db_get_b(NULL, "Options", buf, 1)) TreeView_Expand(hwndTree, tvi.hItem, TVE_COLLAPSE); } tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); } if (dat->hCurrentPage == NULL) { dat->hCurrentPage = TreeView_GetRoot(hwndTree); dat->currentPage = -1; } TreeView_SelectItem(hwndTree, dat->hCurrentPage); if (oldWnd) { opd = dat->getCurrent(); if (opd && oldWnd != opd->hwnd) { ShowWindow(oldWnd, SW_HIDE); if (oldTab && (opd == NULL || !opd->insideTab)) ShowWindow(oldTab, SW_HIDE); } } if (dat->szFilterString[0] == 0) // Clear the keyword combo box SetWindowText(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), _T("")); if (!bRemoveFocusFromFilter) SetFocus(GetDlgItem(hdlg, IDC_KEYWORD_FILTER)); //set the focus back to the combo box SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, CB_SETEDITSEL, 0, oldSel); //but don't select any of the text SendMessage(hwndTree, WM_SETREDRAW, TRUE, 0); TreeView_EnsureVisible(hwndTree, dat->hCurrentPage); }
void TreeNode::EnsureVisible() { TreeView_EnsureVisible(mTreeView->GetHandle(), mHandle); }