summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2016-11-22 14:46:15 +0300
committerGeorge Hazan <ghazan@miranda.im>2016-11-22 14:56:24 +0300
commit0edfbcc3fd42701475505e6ac7cf6a153bc1e25a (patch)
treea10f8148266b5abc041fc5b7cce83ab215913447
parent5e7f1af9e78f7f7ae019a03ba34c9ae7ea72cdff (diff)
OnBuildMenu - new callback for handling rclicks
-rw-r--r--bin10/lib/mir_core.libbin318558 -> 312004 bytes
-rw-r--r--bin10/lib/mir_core64.libbin319858 -> 313002 bytes
-rw-r--r--bin12/lib/mir_core.libbin318558 -> 312004 bytes
-rw-r--r--bin12/lib/mir_core64.libbin319858 -> 313002 bytes
-rw-r--r--bin14/lib/mir_core.libbin318558 -> 312004 bytes
-rw-r--r--bin14/lib/mir_core64.libbin319858 -> 313002 bytes
-rw-r--r--include/m_gui.h6
-rw-r--r--src/mir_app/src/skin2opts.cpp248
-rw-r--r--src/mir_core/src/mir_core.def2
-rw-r--r--src/mir_core/src/mir_core64.def2
-rw-r--r--src/mir_core/src/ui_utils.cpp14
11 files changed, 143 insertions, 129 deletions
diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib
index 910d6845bb..33ef96afff 100644
--- a/bin10/lib/mir_core.lib
+++ b/bin10/lib/mir_core.lib
Binary files differ
diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib
index 69f091e557..6674239967 100644
--- a/bin10/lib/mir_core64.lib
+++ b/bin10/lib/mir_core64.lib
Binary files differ
diff --git a/bin12/lib/mir_core.lib b/bin12/lib/mir_core.lib
index 910d6845bb..33ef96afff 100644
--- a/bin12/lib/mir_core.lib
+++ b/bin12/lib/mir_core.lib
Binary files differ
diff --git a/bin12/lib/mir_core64.lib b/bin12/lib/mir_core64.lib
index 69f091e557..6674239967 100644
--- a/bin12/lib/mir_core64.lib
+++ b/bin12/lib/mir_core64.lib
Binary files differ
diff --git a/bin14/lib/mir_core.lib b/bin14/lib/mir_core.lib
index 910d6845bb..33ef96afff 100644
--- a/bin14/lib/mir_core.lib
+++ b/bin14/lib/mir_core.lib
Binary files differ
diff --git a/bin14/lib/mir_core64.lib b/bin14/lib/mir_core64.lib
index 69f091e557..6674239967 100644
--- a/bin14/lib/mir_core64.lib
+++ b/bin14/lib/mir_core64.lib
Binary files differ
diff --git a/include/m_gui.h b/include/m_gui.h
index 0f3f161b60..eabf1040a6 100644
--- a/include/m_gui.h
+++ b/include/m_gui.h
@@ -440,7 +440,8 @@ private:
LIST<CCtrlBase> m_controls;
void NotifyControls(void (CCtrlBase::*fn)());
- CCtrlBase *FindControl(int idCtrl);
+ CCtrlBase* FindControl(int idCtrl);
+ CCtrlBase* FindControl(HWND hwnd);
CTimer* FindTimer(int idEvent);
@@ -479,6 +480,8 @@ class MIR_CORE_EXPORT CCtrlBase
{
friend class CDlgBase;
+ __forceinline CCtrlBase(HWND hwnd) : m_hwnd(hwnd) {}
+
public:
CCtrlBase(CDlgBase *wnd, int idCtrl);
virtual ~CCtrlBase() { }
@@ -530,6 +533,7 @@ protected:
public:
CCallback<CCtrlBase> OnChange;
+ CCallback<CCtrlBase> OnBuildMenu;
protected:
virtual LRESULT CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/src/mir_app/src/skin2opts.cpp b/src/mir_app/src/skin2opts.cpp
index f3cb06356f..cf866a8743 100644
--- a/src/mir_app/src/skin2opts.cpp
+++ b/src/mir_app/src/skin2opts.cpp
@@ -294,18 +294,6 @@ static int CALLBACK DoSortIconsFuncByOrder(LPARAM lParam1, LPARAM lParam2, LPARA
return iconList[lParam1]->orderID - iconList[lParam2]->orderID;
}
-static int OpenPopupMenu(HWND hwndDlg)
-{
- POINT pt;
- GetCursorPos(&pt);
- HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_ICOLIB_CONTEXT));
- HMENU hPopup = GetSubMenu(hMenu, 0);
- TranslateMenu(hPopup);
- int cmd = TrackPopupMenu(hPopup, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL);
- DestroyMenu(hMenu);
- return cmd;
-}
-
static void LoadSectionIcons(wchar_t *filename, SectionItem* sectionActive)
{
wchar_t path[MAX_PATH];
@@ -333,26 +321,6 @@ static void LoadSectionIcons(wchar_t *filename, SectionItem* sectionActive)
}
}
-static void LoadSubIcons(HWND htv, wchar_t *filename, HTREEITEM hItem)
-{
- TVITEM tvi;
- tvi.mask = TVIF_HANDLE | TVIF_PARAM;
- tvi.hItem = hItem;
- TreeView_GetItem(htv, &tvi);
-
- TreeItem *treeItem = (TreeItem*)tvi.lParam;
- SectionItem* sectionActive = sectionList[SECTIONPARAM_INDEX(treeItem->value)];
-
- tvi.hItem = TreeView_GetChild(htv, tvi.hItem);
- while (tvi.hItem) {
- LoadSubIcons(htv, filename, tvi.hItem);
- tvi.hItem = TreeView_GetNextSibling(htv, tvi.hItem);
- }
-
- if (SECTIONPARAM_FLAGS(treeItem->value) & SECTIONPARAM_HAVEPAGE)
- LoadSectionIcons(filename, sectionActive);
-}
-
static void UndoChanges(int iconIndx, int cmd)
{
IcolibItem *item = iconList[iconIndx];
@@ -368,57 +336,6 @@ static void UndoChanges(int iconIndx, int cmd)
item->temp_reset = TRUE;
}
-static void UndoSubItemChanges(HWND htv, HTREEITEM hItem, int cmd)
-{
- TVITEM tvi = { 0 };
- tvi.mask = TVIF_HANDLE | TVIF_PARAM;
- tvi.hItem = hItem;
- TreeView_GetItem(htv, &tvi);
-
- TreeItem *treeItem = (TreeItem *)tvi.lParam;
- if (SECTIONPARAM_FLAGS(treeItem->value) & SECTIONPARAM_HAVEPAGE) {
- mir_cslock lck(csIconList);
-
- for (int indx = 0; indx < iconList.getCount(); indx++)
- if (iconList[indx]->section == sectionList[SECTIONPARAM_INDEX(treeItem->value)])
- UndoChanges(indx, cmd);
- }
-
- tvi.hItem = TreeView_GetChild(htv, tvi.hItem);
- while (tvi.hItem) {
- UndoSubItemChanges(htv, tvi.hItem, cmd);
- tvi.hItem = TreeView_GetNextSibling(htv, tvi.hItem);
- }
-}
-
-static HTREEITEM FindNamedTreeItemAt(HWND hwndTree, HTREEITEM hItem, const wchar_t *name)
-{
- TVITEM tvi = { 0 };
- wchar_t str[MAX_PATH];
-
- if (hItem)
- tvi.hItem = TreeView_GetChild(hwndTree, hItem);
- else
- tvi.hItem = TreeView_GetRoot(hwndTree);
-
- if (!name)
- return tvi.hItem;
-
- tvi.mask = TVIF_TEXT;
- tvi.pszText = str;
- tvi.cchTextMax = _countof(str);
-
- while (tvi.hItem) {
- TreeView_GetItem(hwndTree, &tvi);
-
- if (!mir_wstrcmp(tvi.pszText, name))
- return tvi.hItem;
-
- tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem);
- }
- return NULL;
-}
-
/////////////////////////////////////////////////////////////////////////////////////////
class CIcoLibOptsDlg : public CDlgBase
@@ -432,6 +349,33 @@ class CIcoLibOptsDlg : public CDlgBase
CCtrlListView m_preview;
CCtrlButton m_btnGetMore, m_btnImport, m_btnLoadIcons;
+ HTREEITEM FindNamedTreeItemAt(HTREEITEM hItem, const wchar_t *name)
+ {
+ TVITEMEX tvi = { 0 };
+ if (hItem)
+ tvi.hItem = m_categoryList.GetChild(hItem);
+ else
+ tvi.hItem = m_categoryList.GetRoot();
+
+ if (!name)
+ return tvi.hItem;
+
+ wchar_t str[MAX_PATH];
+ tvi.mask = TVIF_TEXT;
+ tvi.pszText = str;
+ tvi.cchTextMax = _countof(str);
+
+ while (tvi.hItem) {
+ m_categoryList.GetItem(&tvi);
+
+ if (!mir_wstrcmp(tvi.pszText, name))
+ return tvi.hItem;
+
+ tvi.hItem = m_categoryList.GetNextSibling(tvi.hItem);
+ }
+ return NULL;
+ }
+
void RebuildTree()
{
if (!m_categoryList.GetHwnd())
@@ -459,7 +403,7 @@ class CIcoLibOptsDlg : public CDlgBase
}
pItemName = TranslateW(pItemName);
- hItem = FindNamedTreeItemAt(m_categoryList.GetHwnd(), hSection, pItemName);
+ hItem = FindNamedTreeItemAt(hSection, pItemName);
if (!sectionName || !hItem) {
if (!hItem) {
TVINSERTSTRUCT tvis = { 0 };
@@ -497,7 +441,19 @@ class CIcoLibOptsDlg : public CDlgBase
ShowWindow(m_categoryList.GetHwnd(), SW_SHOW);
- m_categoryList.SelectItem(FindNamedTreeItemAt(m_categoryList.GetHwnd(), 0, NULL));
+ m_categoryList.SelectItem(FindNamedTreeItemAt(0, NULL));
+ }
+
+ int OpenPopupMenu()
+ {
+ POINT pt;
+ GetCursorPos(&pt);
+ HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_ICOLIB_CONTEXT));
+ HMENU hPopup = GetSubMenu(hMenu, 0);
+ TranslateMenu(hPopup);
+ int cmd = TrackPopupMenu(hPopup, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, m_hwnd, NULL);
+ DestroyMenu(hMenu);
+ return cmd;
}
void UpdateIconsPreview()
@@ -557,6 +513,46 @@ class CIcoLibOptsDlg : public CDlgBase
}
}
+ void LoadSubIcons(wchar_t *filename, HTREEITEM hItem)
+ {
+ TVITEMEX tvi;
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM;
+ tvi.hItem = hItem;
+ m_categoryList.GetItem(&tvi);
+
+ TreeItem *treeItem = (TreeItem*)tvi.lParam;
+ SectionItem *sectionActive = sectionList[SECTIONPARAM_INDEX(treeItem->value)];
+
+ tvi.hItem = m_categoryList.GetChild(tvi.hItem);
+ while (tvi.hItem) {
+ LoadSubIcons(filename, tvi.hItem);
+ tvi.hItem = m_categoryList.GetNextSibling(tvi.hItem);
+ }
+
+ if (SECTIONPARAM_FLAGS(treeItem->value) & SECTIONPARAM_HAVEPAGE)
+ LoadSectionIcons(filename, sectionActive);
+ }
+
+ void UndoSubItemChanges(HTREEITEM hItem, int cmd)
+ {
+ TVITEMEX tvi = { 0 };
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM;
+ tvi.hItem = hItem;
+ m_categoryList.GetItem(&tvi);
+
+ TreeItem *treeItem = (TreeItem *)tvi.lParam;
+ if (SECTIONPARAM_FLAGS(treeItem->value) & SECTIONPARAM_HAVEPAGE) {
+ mir_cslock lck(csIconList);
+
+ for (int indx = 0; indx < iconList.getCount(); indx++)
+ if (iconList[indx]->section == sectionList[SECTIONPARAM_INDEX(treeItem->value)])
+ UndoChanges(indx, cmd);
+ }
+
+ for (hItem = m_categoryList.GetChild(tvi.hItem); hItem; hItem = m_categoryList.GetNextSibling(hItem))
+ UndoSubItemChanges(hItem, cmd);
+ }
+
public:
CIcoLibOptsDlg() :
CDlgBase(g_hInst, IDD_OPT_ICOLIB),
@@ -573,8 +569,11 @@ public:
m_btnLoadIcons.OnClick = Callback(this, &CIcoLibOptsDlg::OnLoadIcons);
m_preview.OnGetInfoTip = Callback(this, &CIcoLibOptsDlg::OnGetInfoTip);
+ m_preview.OnBuildMenu = Callback(this, &CIcoLibOptsDlg::OnPreviewMenu);
+
m_categoryList.OnSelChanged = Callback(this, &CIcoLibOptsDlg::OnCategoryChanged);
m_categoryList.OnDeleteItem = Callback(this, &CIcoLibOptsDlg::OnCategoryDeleted);
+ m_categoryList.OnBuildMenu = Callback(this, &CIcoLibOptsDlg::OnTreeMenu);
}
virtual void OnInitDialog() override
@@ -609,48 +608,6 @@ public:
RebuildTree();
}
break;
-
- case WM_CONTEXTMENU:
- if ((HWND)wParam == m_preview.GetHwnd()) {
- UINT count = m_preview.GetSelectedCount();
-
- if (count > 0) {
- int cmd = OpenPopupMenu(m_hwnd);
- switch (cmd) {
- case ID_CANCELCHANGE:
- case ID_RESET:
- {
- LVITEM lvi = { 0 };
- int itemIndx = -1;
-
- while ((itemIndx = m_preview.GetNextItem(itemIndx, LVNI_SELECTED)) != -1) {
- lvi.mask = LVIF_PARAM;
- lvi.iItem = itemIndx; //lvhti.iItem;
- m_preview.GetItem(&lvi);
-
- UndoChanges(lvi.lParam, cmd);
- }
-
- DoOptionsChanged();
- break;
- }
- }
- }
- }
- else {
- if ((HWND)wParam == m_categoryList.GetHwnd()) {
- int cmd = OpenPopupMenu(m_hwnd);
-
- switch (cmd) {
- case ID_CANCELCHANGE:
- case ID_RESET:
- UndoSubItemChanges(m_categoryList.GetHwnd(), m_categoryList.GetSelection(), cmd);
- DoOptionsChanged();
- break;
- }
- }
- }
- break;
}
return CDlgBase::DlgProc(msg, wParam, lParam);
@@ -677,7 +634,7 @@ public:
mir_free(file);
MySetCursor(IDC_WAIT);
- LoadSubIcons(m_categoryList.GetHwnd(), filename, m_categoryList.GetSelection());
+ LoadSubIcons(filename, m_categoryList.GetSelection());
MySetCursor(IDC_ARROW);
DoOptionsChanged();
@@ -754,6 +711,41 @@ public:
}
}
+ void OnPreviewMenu(void*)
+ {
+ UINT count = m_preview.GetSelectedCount();
+ if (count <= 0)
+ return;
+
+ int cmd = OpenPopupMenu();
+ switch (cmd) {
+ case ID_CANCELCHANGE:
+ case ID_RESET:
+ int itemIndx = -1;
+ while ((itemIndx = m_preview.GetNextItem(itemIndx, LVNI_SELECTED)) != -1) {
+ LVITEM lvi;
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = itemIndx;
+ m_preview.GetItem(&lvi);
+
+ UndoChanges(lvi.lParam, cmd);
+ }
+
+ DoOptionsChanged();
+ }
+ }
+
+ void OnTreeMenu(void*)
+ {
+ int cmd = OpenPopupMenu();
+ switch (cmd) {
+ case ID_CANCELCHANGE:
+ case ID_RESET:
+ UndoSubItemChanges(m_categoryList.GetSelection(), cmd);
+ DoOptionsChanged();
+ }
+ }
+
void OnGetInfoTip(CCtrlListView::TEventInfo *evt)
{
NMLVGETINFOTIP *pInfoTip = evt->nmlvit;
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def
index 21a64dc25f..5415d0021a 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -1031,3 +1031,5 @@ CallFunctionSync @1170
?Start@CTimer@@QAEXH@Z @1188 NONAME
?Stop@CTimer@@QAEXXZ @1189 NONAME
?AddTimer@CDlgBase@@IAEXPAVCTimer@@@Z @1190 NONAME
+??0CCtrlBase@@AAE@PAUHWND__@@@Z @1191 NONAME
+?FindControl@CDlgBase@@AAEPAVCCtrlBase@@PAUHWND__@@@Z @1192 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index 50b1d8ed5d..1d24a768ff 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -1031,3 +1031,5 @@ CallFunctionSync @1170
?Start@CTimer@@QEAAXH@Z @1188 NONAME
?Stop@CTimer@@QEAAXXZ @1189 NONAME
?AddTimer@CDlgBase@@IEAAXPEAVCTimer@@@Z @1190 NONAME
+??0CCtrlBase@@AEAA@PEAUHWND__@@@Z @1191 NONAME
+?FindControl@CDlgBase@@AEAAPEAVCCtrlBase@@PEAUHWND__@@@Z @1192 NONAME
diff --git a/src/mir_core/src/ui_utils.cpp b/src/mir_core/src/ui_utils.cpp
index dc53f9dd71..ef726b6c49 100644
--- a/src/mir_core/src/ui_utils.cpp
+++ b/src/mir_core/src/ui_utils.cpp
@@ -210,6 +210,11 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
}
return FALSE;
+ case WM_CONTEXTMENU:
+ if (CCtrlBase *ctrl = FindControl(HWND(wParam)))
+ ctrl->OnBuildMenu(ctrl);
+ break;
+
case WM_SIZE:
if (m_forceResizable || (GetWindowLongPtr(m_hwnd, GWL_STYLE) & WS_SIZEBOX))
Utils_ResizeDialog(m_hwnd, m_hInst, MAKEINTRESOURCEA(m_idDialog), GlobalDlgResizer);
@@ -297,6 +302,15 @@ CCtrlBase* CDlgBase::FindControl(int idCtrl)
return m_controls.find(&search);
}
+CCtrlBase* CDlgBase::FindControl(HWND hwnd)
+{
+ for (int i = 0; i < m_controls.getCount(); i++)
+ if (m_controls[i]->GetHwnd() == hwnd)
+ return m_controls[i];
+
+ return NULL;
+}
+
void CDlgBase::AddTimer(CTimer *timer)
{
m_timers.insert(timer);