summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-05-30 22:46:56 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-05-30 22:46:56 +0300
commitac830cb53dedc1428f196f62304eed354a812a13 (patch)
treea6c521985e4765f0f2482335251f84607df4f5ee /src
parenta43c82a16bf29951cc7913cbff1808098e648d96 (diff)
EI options: code cleaning
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/ei_options.cpp152
-rw-r--r--src/mir_app/src/ei_services.cpp4
-rw-r--r--src/mir_app/src/extraicons.h2
3 files changed, 93 insertions, 65 deletions
diff --git a/src/mir_app/src/ei_options.cpp b/src/mir_app/src/ei_options.cpp
index 54c1d627d2..50cdcc1ce3 100644
--- a/src/mir_app/src/ei_options.cpp
+++ b/src/mir_app/src/ei_options.cpp
@@ -23,7 +23,7 @@ Boston, MA 02111-1307, USA.
#include "extraicons.h"
-#define ICON_SIZE 16
+static class CExtraIconOptsDlg *pGlgOptions;
int SortFunc(const ExtraIcon *p1, const ExtraIcon *p2);
@@ -240,17 +240,24 @@ class CExtraIconOptsDlg : public CDlgBase
}
CCtrlTreeView m_tree;
+ CTimer m_timer;
public:
CExtraIconOptsDlg() :
CDlgBase(g_plugin, IDD_EI_OPTIONS),
- m_tree(this, IDC_EXTRAORDER)
+ m_tree(this, IDC_EXTRAORDER),
+ m_timer(this, 1)
{
m_tree.SetFlags(MTREE_DND | MTREE_MULTISELECT);
+ m_tree.OnRightClick = Callback(this, &CExtraIconOptsDlg::onRClick);
+
+ m_timer.OnEvent = Callback(this, &CExtraIconOptsDlg::onTimer);
}
virtual void OnInitDialog()
{
+ pGlgOptions = this;
+
int numSlots = EXTRA_ICON_COUNT;
if (numSlots < (int)registeredExtraIcons.getCount()) {
HWND label = GetDlgItem(m_hwnd, IDC_MAX_ICONS_L);
@@ -258,42 +265,7 @@ public:
ShowWindow(label, SW_SHOW);
}
- int cx = g_iIconSX;
- HIMAGELIST hImageList = ImageList_Create(cx, cx, ILC_COLOR32 | ILC_MASK, 2, 2);
-
- HICON hBlankIcon = (HICON)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_BLANK), IMAGE_ICON, cx, cx, 0);
- ImageList_AddIcon(hImageList, hBlankIcon);
-
- for (auto &extra : registeredExtraIcons) {
- extra->setID(registeredExtraIcons.indexOf(&extra) + 1);
-
- HICON hIcon = IcoLib_GetIcon(extra->getDescIcon());
- if (hIcon == nullptr)
- ImageList_AddIcon(hImageList, hBlankIcon);
- else {
- ImageList_AddIcon(hImageList, hIcon);
- IcoLib_ReleaseIcon(hIcon);
- }
- }
- m_tree.SetImageList(hImageList, TVSIL_NORMAL);
- DestroyIcon(hBlankIcon);
-
- for (auto &extra : extraIconsBySlot) {
- if (extra->getType() == EXTRAICON_TYPE_GROUP) {
- ExtraIconGroup *group = (ExtraIconGroup *)extra;
- intlist ids;
- for (auto &p : group->m_items)
- ids.add(p->getID());
- Tree_AddExtraIconGroup(ids, extra->isEnabled());
- }
- else Tree_AddExtraIcon((BaseExtraIcon *)extra, extra->isEnabled());
- }
-
- TVSORTCB sort = {};
- sort.hParent = nullptr;
- sort.lParam = 0;
- sort.lpfnCompare = CompareFunc;
- m_tree.SortChildrenCB(&sort, 0);
+ BuildIconList();
}
virtual void OnApply()
@@ -399,6 +371,8 @@ public:
virtual void OnDestroy()
{
+ pGlgOptions = nullptr;
+
HTREEITEM hItem = m_tree.GetRoot();
while (hItem) {
delete Tree_GetIDs(hItem);
@@ -408,41 +382,91 @@ public:
ImageList_Destroy(m_tree.GetImageList(TVSIL_NORMAL));
}
- virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+ void onRClick(CCtrlTreeView::TEventInfo*)
{
- if (msg == WM_NOTIFY) {
- LPNMHDR lpnmhdr = (LPNMHDR)lParam;
- if (lpnmhdr->idFrom == IDC_EXTRAORDER && lpnmhdr->code == NM_RCLICK) {
- HTREEITEM hSelected = m_tree.GetDropHilight();
- if (hSelected != nullptr && !m_tree.IsSelected(hSelected)) {
- m_tree.UnselectAll();
- m_tree.SelectItem(hSelected);
- }
+ HTREEITEM hSelected = m_tree.GetDropHilight();
+ if (hSelected != nullptr && !m_tree.IsSelected(hSelected)) {
+ m_tree.UnselectAll();
+ m_tree.SelectItem(hSelected);
+ }
- int sels = m_tree.GetNumSelected();
- if (sels > 1) {
- if (ShowPopup(0) == ID_GROUP) {
- GroupSelectedItems();
- NotifyChange();
- }
- }
- else if (sels == 1) {
- HTREEITEM hItem = m_tree.GetSelection();
- intlist *ids = Tree_GetIDs(hItem);
- if (ids->count > 1) {
- if (ShowPopup(1) == ID_UNGROUP) {
- UngroupSelectedItems();
- NotifyChange();
- }
- }
+ int sels = m_tree.GetNumSelected();
+ if (sels > 1) {
+ if (ShowPopup(0) == ID_GROUP) {
+ GroupSelectedItems();
+ NotifyChange();
+ }
+ }
+ else if (sels == 1) {
+ HTREEITEM hItem = m_tree.GetSelection();
+ intlist *ids = Tree_GetIDs(hItem);
+ if (ids->count > 1) {
+ if (ShowPopup(1) == ID_UNGROUP) {
+ UngroupSelectedItems();
+ NotifyChange();
}
}
}
+ }
- return CDlgBase::DlgProc(msg, wParam, lParam);
+ void BuildIconList()
+ {
+ HIMAGELIST hImageList = ImageList_Create(g_iIconSX, g_iIconSX, ILC_COLOR32 | ILC_MASK, 2, 2);
+
+ HICON hBlankIcon = (HICON)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_BLANK), IMAGE_ICON, g_iIconSX, g_iIconSX, 0);
+ ImageList_AddIcon(hImageList, hBlankIcon);
+
+ for (auto &extra : registeredExtraIcons) {
+ extra->setID(registeredExtraIcons.indexOf(&extra)+1);
+
+ HICON hIcon = IcoLib_GetIcon(extra->getDescIcon());
+ if (hIcon == nullptr)
+ ImageList_AddIcon(hImageList, hBlankIcon);
+ else {
+ ImageList_AddIcon(hImageList, hIcon);
+ IcoLib_ReleaseIcon(hIcon);
+ }
+ }
+ m_tree.SetImageList(hImageList, TVSIL_NORMAL);
+ DestroyIcon(hBlankIcon);
+
+ for (auto &extra : extraIconsBySlot) {
+ if (extra->getType() == EXTRAICON_TYPE_GROUP) {
+ ExtraIconGroup *group = (ExtraIconGroup *)extra;
+ intlist ids;
+ for (auto &p : group->m_items)
+ ids.add(p->getID());
+ Tree_AddExtraIconGroup(ids, extra->isEnabled());
+ }
+ else Tree_AddExtraIcon((BaseExtraIcon*)extra, extra->isEnabled());
+ }
+
+ TVSORTCB sort = {};
+ sort.hParent = nullptr;
+ sort.lParam = 0;
+ sort.lpfnCompare = CompareFunc;
+ m_tree.SortChildrenCB(&sort, 0);
+ }
+
+ void onTimer(CTimer*)
+ {
+ m_timer.Stop();
+ m_tree.DeleteAllItems();
+ BuildIconList();
+ }
+
+ void ResetIconList()
+ {
+ m_timer.Start(100);
}
};
+void eiOptionsRefresh()
+{
+ if (pGlgOptions)
+ pGlgOptions->ResetIconList();
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
int InitOptionsCallback(WPARAM wParam, LPARAM)
diff --git a/src/mir_app/src/ei_services.cpp b/src/mir_app/src/ei_services.cpp
index 60cb0e7567..52017494e7 100644
--- a/src/mir_app/src/ei_services.cpp
+++ b/src/mir_app/src/ei_services.cpp
@@ -187,8 +187,10 @@ static void ResetSlots(BaseExtraIcon *extra, ExtraIconGroup *group)
for (auto &hContact : Contacts())
Clist_SetExtraIcon(hContact, i, INVALID_HANDLE_VALUE);
- if (!g_bMirandaTerminated)
+ if (!g_bMirandaTerminated) {
Clist_InitAutoRebuild(g_clistApi.hwndContactTree);
+ eiOptionsRefresh();
+ }
}
MIR_APP_DLL(void) KillModuleExtraIcons(int _hLang)
diff --git a/src/mir_app/src/extraicons.h b/src/mir_app/src/extraicons.h
index 5c6a6b7a46..5a0c1560d3 100644
--- a/src/mir_app/src/extraicons.h
+++ b/src/mir_app/src/extraicons.h
@@ -201,6 +201,8 @@ extern LIST<BaseExtraIcon> registeredExtraIcons;
void RebuildListsBasedOnGroups(LIST<ExtraIconGroup> &groups);
extern LIST<ExtraIcon> extraIconsBySlot;
+void eiOptionsRefresh(void);
+
int ConvertToClistSlot(int slot);
int Clist_SetExtraIcon(MCONTACT hContact, int slot, HANDLE hImage);