summaryrefslogtreecommitdiff
path: root/src/modules/extraicons/options_ei.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/extraicons/options_ei.cpp')
-rw-r--r--src/modules/extraicons/options_ei.cpp344
1 files changed, 170 insertions, 174 deletions
diff --git a/src/modules/extraicons/options_ei.cpp b/src/modules/extraicons/options_ei.cpp
index 3bffe0c641..db7d74b0b1 100644
--- a/src/modules/extraicons/options_ei.cpp
+++ b/src/modules/extraicons/options_ei.cpp
@@ -25,6 +25,8 @@ Boston, MA 02111-1307, USA.
#define ICON_SIZE 16
+int SortFunc(const ExtraIcon *p1, const ExtraIcon *p2);
+
// Functions //////////////////////////////////////////////////////////////////////////////////////
BOOL ScreenToClient(HWND hWnd, LPRECT lpRect)
@@ -138,12 +140,10 @@ static void Tree_SelectRange(HWND tree, HTREEITEM hStart, HTREEITEM hEnd)
static int GetNumSelected(HWND tree)
{
int ret = 0;
- HTREEITEM hItem = TreeView_GetRoot(tree);
- while (hItem) {
- if (IsSelected(tree, hItem))
+ for (HTREEITEM hItem = TreeView_GetRoot(tree); hItem; hItem = TreeView_GetNextSibling(tree, hItem))
+ if ( IsSelected(tree, hItem))
ret++;
- hItem = TreeView_GetNextSibling(tree, hItem);
- }
+
return ret;
}
@@ -232,19 +232,18 @@ LRESULT CALLBACK TreeProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
return mir_callNextSubclass(hwndDlg, TreeProc, msg, wParam, lParam);
}
-static vector<int> * Tree_GetIDs(HWND tree, HTREEITEM hItem)
+static vector<int>* Tree_GetIDs(HWND tree, HTREEITEM hItem)
{
TVITEM tvi = { 0 };
tvi.mask = TVIF_HANDLE | TVIF_PARAM;
tvi.hItem = hItem;
TreeView_GetItem(tree, &tvi);
-
- return (vector<int> *) tvi.lParam;
+ return (vector<int>*) tvi.lParam;
}
static HTREEITEM Tree_AddExtraIcon(HWND tree, BaseExtraIcon *extra, bool selected, HTREEITEM hAfter = TVI_LAST)
{
- vector<int> *ids = new vector<int> ;
+ vector<int>*ids = new vector<int> ;
ids->push_back(extra->getID());
TVINSERTSTRUCT tvis = { 0 };
@@ -252,7 +251,7 @@ static HTREEITEM Tree_AddExtraIcon(HWND tree, BaseExtraIcon *extra, bool selecte
tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
tvis.item.stateMask = TVIS_STATEIMAGEMASK;
tvis.item.iSelectedImage = tvis.item.iImage = extra->getID();
- tvis.item.lParam = (LPARAM) ids;
+ tvis.item.lParam = (LPARAM)ids;
tvis.item.pszText = (LPTSTR)extra->getDescription();
tvis.item.state = INDEXTOSTATEIMAGEMASK(selected ? 2 : 1);
return TreeView_InsertItem(tree, &tvis);
@@ -260,8 +259,8 @@ static HTREEITEM Tree_AddExtraIcon(HWND tree, BaseExtraIcon *extra, bool selecte
static HTREEITEM Tree_AddExtraIconGroup(HWND tree, vector<int> &group, bool selected, HTREEITEM hAfter = TVI_LAST)
{
- vector<int> *ids = new vector<int> ;
- tstring desc;
+ vector<int>*ids = new vector<int> ;
+ CMString desc;
int img = 0;
for (unsigned int i = 0; i < group.size(); i++) {
BaseExtraIcon *extra = registeredExtraIcons[group[i] - 1];
@@ -280,8 +279,8 @@ static HTREEITEM Tree_AddExtraIconGroup(HWND tree, vector<int> &group, bool sele
tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
tvis.item.stateMask = TVIS_STATEIMAGEMASK;
tvis.item.iSelectedImage = tvis.item.iImage = img;
- tvis.item.lParam = (LPARAM) ids;
- tvis.item.pszText = (TCHAR*) desc.c_str();
+ tvis.item.lParam = (LPARAM)ids;
+ tvis.item.pszText = (TCHAR*)desc.c_str();
tvis.item.state = INDEXTOSTATEIMAGEMASK(selected ? 2 : 1);
return TreeView_InsertItem(tree, &tvis);
}
@@ -305,7 +304,7 @@ static void GroupSelectedItems(HWND tree)
tvi.hItem = hItem;
TreeView_GetItem(tree, &tvi);
- vector<int> *iids = (vector<int> *) tvi.lParam;
+ vector<int>*iids = (vector<int>*) tvi.lParam;
ids.insert(ids.end(), iids->begin(), iids->end());
if ((tvi.state & INDEXTOSTATEIMAGEMASK(3)) == INDEXTOSTATEIMAGEMASK(2))
@@ -342,14 +341,14 @@ static void UngroupSelectedItems(HWND tree)
if (hItem == NULL)
return;
- vector<int> *ids = Tree_GetIDs(tree, hItem);
+ vector<int>*ids = Tree_GetIDs(tree, hItem);
if (ids->size() < 2)
return;
bool selected = IsSelected(tree, hItem);
for (size_t i = ids->size(); i > 0; --i) {
- BaseExtraIcon *extra = registeredExtraIcons[ids->at(i - 1) - 1];
+ BaseExtraIcon *extra = registeredExtraIcons[ids->at(i-1) - 1];
Tree_AddExtraIcon(tree, extra, selected, hItem);
}
@@ -396,14 +395,15 @@ static int ShowPopup(HWND hwndDlg, int popup)
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
- vector<int> *a = (vector<int> *) lParam1;
- vector<int> *b = (vector<int> *) lParam2;
- return registeredExtraIcons[a->at(0) - 1]->compare(registeredExtraIcons[b->at(0) - 1]);
+ vector<int>*a = (vector<int>*) lParam1;
+ vector<int>*b = (vector<int>*) lParam2;
+ return SortFunc(registeredExtraIcons[a->at(0)-1], registeredExtraIcons[b->at(0)-1]);
}
static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
+ LPNMHDR lpnmhdr;
static int dragging = 0;
static HANDLE hDragItem = NULL;
@@ -444,7 +444,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
TreeView_SetImageList(tree, hImageList, TVSIL_NORMAL);
DestroyIcon(hBlankIcon);
- for (unsigned k = 0; k < extraIconsBySlot.size(); k++) {
+ for (int k = 0; k < extraIconsBySlot.getCount(); k++) {
ExtraIcon *extra = extraIconsBySlot[k];
if (extra->getType() == EXTRAICON_TYPE_GROUP) {
@@ -468,188 +468,184 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
return TRUE;
case WM_NOTIFY:
- {
- LPNMHDR lpnmhdr = (LPNMHDR) lParam;
- if (lpnmhdr->idFrom == 0) {
- if (lpnmhdr->code == (UINT) PSN_APPLY) {
- // Store old slots
- int *oldSlots = new int[registeredExtraIcons.getCount()];
- int lastUsedSlot = -1;
- for (int i = 0; i < registeredExtraIcons.getCount(); i++) {
- if (extraIconsByHandle[i] == registeredExtraIcons[i])
- oldSlots[i] = registeredExtraIcons[i]->getSlot();
- else
- // Remove old slot for groups to re-set images
- oldSlots[i] = -1;
- lastUsedSlot = MAX(lastUsedSlot, registeredExtraIcons[i]->getSlot());
- }
- lastUsedSlot = MIN(lastUsedSlot, GetNumberOfSlots());
-
- // Get user data and create new groups
- vector<ExtraIconGroup *> groups;
-
- BYTE pos = 0;
- int firstEmptySlot = 0;
- HTREEITEM ht = TreeView_GetRoot(tree);
- TVITEM tvi = { 0 };
- tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
- tvi.stateMask = TVIS_STATEIMAGEMASK;
- while (ht) {
- tvi.hItem = ht;
- TreeView_GetItem(tree, &tvi);
-
- vector<int> *ids = (vector<int> *) tvi.lParam;
- if (ids == NULL || ids->size() < 1)
- continue; // ???
-
- bool enabled = ((tvi.state & INDEXTOSTATEIMAGEMASK(3)) == INDEXTOSTATEIMAGEMASK(2));
- int slot = (enabled ? firstEmptySlot++ : -1);
- if (slot >= GetNumberOfSlots())
- slot = -1;
-
- if (ids->size() == 1) {
- BaseExtraIcon *extra = registeredExtraIcons[ids->at(0) - 1];
- extra->setPosition(pos++);
- extra->setSlot(slot);
- }
- else {
- char name[128];
- mir_snprintf(name, SIZEOF(name), "__group_%d", groups.size());
-
- ExtraIconGroup *group = new ExtraIconGroup(name);
-
- for (unsigned i = 0; i < ids->size(); i++) {
- BaseExtraIcon *extra = registeredExtraIcons[ids->at(i) - 1];
- extra->setPosition(pos++);
+ lpnmhdr = (LPNMHDR)lParam;
+ if (lpnmhdr->idFrom == 0 && lpnmhdr->code == (UINT) PSN_APPLY) {
+ // Store old slots
+ int *oldSlots = new int[registeredExtraIcons.getCount()];
+ int lastUsedSlot = -1;
+ for (int i = 0; i < registeredExtraIcons.getCount(); i++) {
+ if (extraIconsByHandle[i] == registeredExtraIcons[i])
+ oldSlots[i] = registeredExtraIcons[i]->getSlot();
+ else
+ // Remove old slot for groups to re-set images
+ oldSlots[i] = -1;
+ lastUsedSlot = MAX(lastUsedSlot, registeredExtraIcons[i]->getSlot());
+ }
+ lastUsedSlot = MIN(lastUsedSlot, GetNumberOfSlots());
+
+ // Get user data and create new groups
+ vector<ExtraIconGroup *> groups;
+
+ BYTE pos = 0;
+ int firstEmptySlot = 0;
+ HTREEITEM ht = TreeView_GetRoot(tree);
+ TVITEM tvi = { 0 };
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+ while (ht) {
+ tvi.hItem = ht;
+ TreeView_GetItem(tree, &tvi);
+
+ vector<int>*ids = (vector<int>*) tvi.lParam;
+ if (ids == NULL || ids->size() < 1)
+ continue; // ???
+
+ bool enabled = ((tvi.state & INDEXTOSTATEIMAGEMASK(3)) == INDEXTOSTATEIMAGEMASK(2));
+ int slot = (enabled ? firstEmptySlot++ : -1);
+ if (slot >= GetNumberOfSlots())
+ slot = -1;
+
+ if (ids->size() == 1) {
+ BaseExtraIcon *extra = registeredExtraIcons[ids->at(0) - 1];
+ extra->setPosition(pos++);
+ extra->setSlot(slot);
+ }
+ else {
+ char name[128];
+ mir_snprintf(name, SIZEOF(name), "__group_%d", groups.size());
- group->addExtraIcon(extra);
- }
+ ExtraIconGroup *group = new ExtraIconGroup(name);
- group->setSlot(slot);
- groups.push_back(group);
- }
+ for (unsigned i = 0; i < ids->size(); i++) {
+ BaseExtraIcon *extra = registeredExtraIcons[ids->at(i) - 1];
+ extra->setPosition(pos++);
- ht = TreeView_GetNextSibling(tree, ht);
+ group->addExtraIcon(extra);
}
- // Store data
- for (int i = 0; i < registeredExtraIcons.getCount(); i++) {
- BaseExtraIcon *extra = registeredExtraIcons[i];
+ group->setSlot(slot);
+ groups.push_back(group);
+ }
- char setting[512];
- mir_snprintf(setting, SIZEOF(setting), "Position_%s", extra->getName());
- db_set_w(NULL, MODULE_NAME, setting, extra->getPosition());
+ ht = TreeView_GetNextSibling(tree, ht);
+ }
- mir_snprintf(setting, SIZEOF(setting), "Slot_%s", extra->getName());
- db_set_w(NULL, MODULE_NAME, setting, extra->getSlot());
- }
+ // Store data
+ for (int i = 0; i < registeredExtraIcons.getCount(); i++) {
+ BaseExtraIcon *extra = registeredExtraIcons[i];
- CallService(MS_DB_MODULE_DELETE, 0, (LPARAM) MODULE_NAME "Groups");
- db_set_w(NULL, MODULE_NAME "Groups", "Count", (WORD)groups.size());
- for (unsigned k = 0; k < groups.size(); k++) {
- ExtraIconGroup *group = groups[k];
+ char setting[512];
+ mir_snprintf(setting, SIZEOF(setting), "Position_%s", extra->getName());
+ db_set_w(NULL, MODULE_NAME, setting, extra->getPosition());
- char setting[512];
- mir_snprintf(setting, SIZEOF(setting), "%d_count", k);
- db_set_w(NULL, MODULE_NAME "Groups", setting, (WORD)group->items.size());
+ mir_snprintf(setting, SIZEOF(setting), "Slot_%s", extra->getName());
+ db_set_w(NULL, MODULE_NAME, setting, extra->getSlot());
+ }
- for (unsigned j = 0; j < group->items.size(); j++) {
- BaseExtraIcon *extra = group->items[j];
+ CallService(MS_DB_MODULE_DELETE, 0, (LPARAM) MODULE_NAME "Groups");
+ db_set_w(NULL, MODULE_NAME "Groups", "Count", (WORD)groups.size());
+ for (unsigned k = 0; k < groups.size(); k++) {
+ ExtraIconGroup *group = groups[k];
- mir_snprintf(setting, SIZEOF(setting), "%d_%d", k, j);
- db_set_s(NULL, MODULE_NAME "Groups", setting, extra->getName());
- }
- }
+ char setting[512];
+ mir_snprintf(setting, SIZEOF(setting), "%d_count", k);
+ db_set_w(NULL, MODULE_NAME "Groups", setting, (WORD)group->items.size());
- // Clean removed slots
- for (int j = firstEmptySlot; j <= lastUsedSlot; j++)
- RemoveExtraIcons(j);
+ for (unsigned j = 0; j < group->items.size(); j++) {
+ BaseExtraIcon *extra = group->items[j];
- // Apply icons to new slots
- RebuildListsBasedOnGroups(groups);
- for (unsigned n = 0; n < extraIconsBySlot.size(); n++) {
- ExtraIcon *extra = extraIconsBySlot[n];
+ mir_snprintf(setting, SIZEOF(setting), "%d_%d", k, j);
+ db_set_s(NULL, MODULE_NAME "Groups", setting, extra->getName());
+ }
+ }
- if (extra->getType() != EXTRAICON_TYPE_GROUP)
- if (oldSlots[((BaseExtraIcon *) extra)->getID() - 1] == extra->getSlot())
- continue;
+ // Clean removed slots
+ for (int j = firstEmptySlot; j <= lastUsedSlot; j++)
+ RemoveExtraIcons(j);
- extra->applyIcons();
- }
+ // Apply icons to new slots
+ RebuildListsBasedOnGroups(groups);
+ for (int n = 0; n < extraIconsBySlot.getCount(); n++) {
+ ExtraIcon *extra = extraIconsBySlot[n];
+ if (extra->getType() != EXTRAICON_TYPE_GROUP)
+ if (oldSlots[((BaseExtraIcon *) extra)->getID() - 1] == extra->getSlot())
+ continue;
- delete[] oldSlots;
- return TRUE;
- }
+ extra->applyIcons();
}
- else if (lpnmhdr->idFrom == IDC_EXTRAORDER) {
- switch (lpnmhdr->code) {
- case TVN_BEGINDRAGW:
- case TVN_BEGINDRAGA:
- SetCapture(hwndDlg);
- dragging = 1;
- hDragItem = ((LPNMTREEVIEWA) lParam)->itemNew.hItem;
- TreeView_SelectItem(tree, hDragItem);
- break;
- case NM_CLICK:
- {
- DWORD pos = GetMessagePos();
-
- TVHITTESTINFO hti;
- hti.pt.x = (short) LOWORD(pos);
- hti.pt.y = (short) HIWORD(pos);
- ScreenToClient(lpnmhdr->hwndFrom, &hti.pt);
- if (TreeView_HitTest(lpnmhdr->hwndFrom, &hti)) {
- if (hti.flags & TVHT_ONITEMSTATEICON) {
- TreeView_SelectItem(tree, hti.hItem);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
- }
+ delete[] oldSlots;
+ return TRUE;
+ }
+
+ if (lpnmhdr->idFrom == IDC_EXTRAORDER) {
+ switch (lpnmhdr->code) {
+ case TVN_BEGINDRAGW:
+ case TVN_BEGINDRAGA:
+ SetCapture(hwndDlg);
+ dragging = 1;
+ hDragItem = ((LPNMTREEVIEWA) lParam)->itemNew.hItem;
+ TreeView_SelectItem(tree, hDragItem);
+ break;
+
+ case NM_CLICK:
+ {
+ DWORD pos = GetMessagePos();
+
+ TVHITTESTINFO hti;
+ hti.pt.x = (short) LOWORD(pos);
+ hti.pt.y = (short) HIWORD(pos);
+ ScreenToClient(lpnmhdr->hwndFrom, &hti.pt);
+ if (TreeView_HitTest(lpnmhdr->hwndFrom, &hti)) {
+ if (hti.flags & TVHT_ONITEMSTATEICON) {
+ TreeView_SelectItem(tree, hti.hItem);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
}
- break;
}
- case TVN_KEYDOWN:
- {
- TV_KEYDOWN *nmkd = (TV_KEYDOWN *) lpnmhdr;
- if (nmkd->wVKey == VK_SPACE) {
- // Determine the selected tree item.
- HTREEITEM hItem = TreeView_GetSelection(tree);
- if (hItem != NULL)
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
- }
- break;
+ break;
+ }
+ case TVN_KEYDOWN:
+ {
+ TV_KEYDOWN *nmkd = (TV_KEYDOWN *) lpnmhdr;
+ if (nmkd->wVKey == VK_SPACE) {
+ // Determine the selected tree item.
+ HTREEITEM hItem = TreeView_GetSelection(tree);
+ if (hItem != NULL)
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
+ }
+ break;
+ }
+ case NM_RCLICK:
+ {
+ HTREEITEM hSelected = (HTREEITEM) SendMessage(tree, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0);
+ if (hSelected != NULL && !IsSelected(tree, hSelected)) {
+ UnselectAll(tree);
+ TreeView_SelectItem(tree, hSelected);
}
- case NM_RCLICK:
- {
- HTREEITEM hSelected = (HTREEITEM) SendMessage(tree, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0);
- if (hSelected != NULL && !IsSelected(tree, hSelected)) {
- UnselectAll(tree);
- TreeView_SelectItem(tree, hSelected);
- }
- int sels = GetNumSelected(tree);
- if (sels > 1) {
- if (ShowPopup(hwndDlg, 0) == ID_GROUP) {
- GroupSelectedItems(tree);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
- }
+ int sels = GetNumSelected(tree);
+ if (sels > 1) {
+ if (ShowPopup(hwndDlg, 0) == ID_GROUP) {
+ GroupSelectedItems(tree);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
}
- else if (sels == 1) {
- HTREEITEM hItem = TreeView_GetSelection(tree);
- vector<int> *ids = Tree_GetIDs(tree, hItem);
- if (ids->size() > 1) {
- if (ShowPopup(hwndDlg, 1) == ID_UNGROUP) {
- UngroupSelectedItems(tree);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
- }
+ }
+ else if (sels == 1) {
+ HTREEITEM hItem = TreeView_GetSelection(tree);
+ vector<int>*ids = Tree_GetIDs(tree, hItem);
+ if (ids->size() > 1) {
+ if (ShowPopup(hwndDlg, 1) == ID_UNGROUP) {
+ UngroupSelectedItems(tree);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
}
}
- break;
}
+ break;
}
}
-
- break;
}
+ break;
+
case WM_MOUSEMOVE:
if (dragging) {
TVHITTESTINFO hti;