diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/commonheaders.h | 4 | ||||
-rw-r--r-- | src/modules/extraicons/BaseExtraIcon.cpp | 20 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIcon.cpp | 54 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIcon.h | 19 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIconGroup.cpp | 8 | ||||
-rw-r--r-- | src/modules/extraicons/extraicons.cpp | 75 | ||||
-rw-r--r-- | src/modules/extraicons/extraicons.h | 3 | ||||
-rw-r--r-- | src/modules/extraicons/options_ei.cpp | 344 | ||||
-rw-r--r-- | src/modules/extraicons/usedIcons.cpp | 54 |
9 files changed, 253 insertions, 328 deletions
diff --git a/src/core/commonheaders.h b/src/core/commonheaders.h index e37660c06f..e1e4ef2544 100644 --- a/src/core/commonheaders.h +++ b/src/core/commonheaders.h @@ -40,10 +40,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <vssym32.h>
#include <Shlwapi.h>
-#include <map>
#include <vector>
-#include <string>
-#include <algorithm>
using namespace std;
#include <stdio.h>
@@ -60,6 +57,7 @@ using namespace std; #include <m_system.h>
#include <m_system_cpp.h>
+#include <m_string.h>
#include <m_core.h>
#include <newpluginapi.h>
#include <m_database.h>
diff --git a/src/modules/extraicons/BaseExtraIcon.cpp b/src/modules/extraicons/BaseExtraIcon.cpp index 6810d0d832..d94ded904e 100644 --- a/src/modules/extraicons/BaseExtraIcon.cpp +++ b/src/modules/extraicons/BaseExtraIcon.cpp @@ -23,9 +23,10 @@ Boston, MA 02111-1307, USA. #include "extraicons.h"
-BaseExtraIcon::BaseExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon,
- MIRANDAHOOKPARAM OnClick, LPARAM param) :
- ExtraIcon(name), id(id), description(description), descIcon(descIcon), OnClick(OnClick), onClickParam(param)
+BaseExtraIcon::BaseExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, LPARAM param) :
+ ExtraIcon(name), id(id), OnClick(OnClick), onClickParam(param),
+ tszDescription( mir_tstrdup(description)),
+ szDescIcon( mir_strdup(descIcon))
{
}
@@ -44,24 +45,24 @@ int BaseExtraIcon::getID() const return id;
}
-const TCHAR *BaseExtraIcon::getDescription() const
+const TCHAR* BaseExtraIcon::getDescription() const
{
- return description.c_str();
+ return tszDescription;
}
void BaseExtraIcon::setDescription(const TCHAR *desc)
{
- description = desc;
+ tszDescription = mir_tstrdup(desc);
}
const char *BaseExtraIcon::getDescIcon() const
{
- return descIcon.c_str();
+ return szDescIcon;
}
void BaseExtraIcon::setDescIcon(const char *icon)
{
- descIcon = icon;
+ szDescIcon = mir_strdup(icon);
}
void BaseExtraIcon::onClick(HANDLE hContact)
@@ -77,6 +78,5 @@ int BaseExtraIcon::ClistSetExtraIcon(HANDLE hContact, HANDLE hImage) ExtraIcon *tmp = extraIconsByHandle[id - 1];
if (tmp != this)
return tmp->ClistSetExtraIcon(hContact, hImage);
- else
- return Clist_SetExtraIcon(hContact, slot, hImage);
+ return Clist_SetExtraIcon(hContact, slot, hImage);
}
diff --git a/src/modules/extraicons/ExtraIcon.cpp b/src/modules/extraicons/ExtraIcon.cpp index 379265e9ba..5298ea3a64 100644 --- a/src/modules/extraicons/ExtraIcon.cpp +++ b/src/modules/extraicons/ExtraIcon.cpp @@ -73,57 +73,3 @@ void ExtraIcon::applyIcons() applyIcon(hContact);
}
}
-
-int ExtraIcon::compare(const ExtraIcon *other) const
-{
- if (this == other)
- return 0;
-
- int ret = getPosition() - other->getPosition();
- if (ret != 0)
- return ret;
-
- int id = 0;
- if (getType() != EXTRAICON_TYPE_GROUP)
- id = ((BaseExtraIcon*) this)->getID();
- int otherId = 0;
- if (other->getType() != EXTRAICON_TYPE_GROUP)
- otherId = ((BaseExtraIcon*) other)->getID();
- return id - otherId;
-}
-
-bool ExtraIcon::operator==(const ExtraIcon & other) const
-{
- int c = compare(&other);
- return c == 0;
-}
-
-bool ExtraIcon::operator!=(const ExtraIcon & other) const
-{
- int c = compare(&other);
- return c != 0;
-}
-
-bool ExtraIcon::operator<(const ExtraIcon & other) const
-{
- int c = compare(&other);
- return c < 0;
-}
-
-bool ExtraIcon::operator<=(const ExtraIcon & other) const
-{
- int c = compare(&other);
- return c <= 0;
-}
-
-bool ExtraIcon::operator>(const ExtraIcon & other) const
-{
- int c = compare(&other);
- return c > 0;
-}
-
-bool ExtraIcon::operator>=(const ExtraIcon & other) const
-{
- int c = compare(&other);
- return c >= 0;
-}
diff --git a/src/modules/extraicons/ExtraIcon.h b/src/modules/extraicons/ExtraIcon.h index ca92cd659c..8b2a7a56ae 100644 --- a/src/modules/extraicons/ExtraIcon.h +++ b/src/modules/extraicons/ExtraIcon.h @@ -22,9 +22,6 @@ Boston, MA 02111-1307, USA. #ifndef __EXTRAICON_H__
#define __EXTRAICON_H__
-#include <string>
-#include <vector>
-
#define EXTRAICON_TYPE_GROUP -1
/////////////////////////////////////////////////////////////////////////////////////////
@@ -58,16 +55,6 @@ public: virtual bool isEnabled() const;
- /// @retun <0 if this < other, 0 if this == other, >0 if this > other
- virtual int compare(const ExtraIcon *other) const;
-
- bool operator==(const ExtraIcon &other) const;
- bool operator!=(const ExtraIcon &other) const;
- bool operator<(const ExtraIcon &other) const;
- bool operator<=(const ExtraIcon &other) const;
- bool operator>(const ExtraIcon &other) const;
- bool operator>=(const ExtraIcon &other) const;
-
virtual int ClistSetExtraIcon(HANDLE hContact, HANDLE hImage) = 0;
int hLangpack;
@@ -102,8 +89,8 @@ public: protected:
int id;
- std::tstring description;
- std::string descIcon;
+ ptrT tszDescription;
+ ptrA szDescIcon;
MIRANDAHOOKPARAM OnClick;
LPARAM onClickParam;
};
@@ -183,7 +170,7 @@ public: virtual int ClistSetExtraIcon(HANDLE hContact, HANDLE hImage);
protected:
- std::tstring description;
+ ptrT tszDescription;
bool setValidExtraIcon;
bool insideApply;
diff --git a/src/modules/extraicons/ExtraIconGroup.cpp b/src/modules/extraicons/ExtraIconGroup.cpp index 696728e4e2..dff2601695 100644 --- a/src/modules/extraicons/ExtraIconGroup.cpp +++ b/src/modules/extraicons/ExtraIconGroup.cpp @@ -38,13 +38,15 @@ void ExtraIconGroup::addExtraIcon(BaseExtraIcon *extra) {
items.push_back(extra);
- description.clear();
+ CMString description;
for (unsigned int i = 0; i < items.size(); i++)
{
if (i > 0)
description += _T(" / ");
description += items[i]->getDescription();
}
+
+ tszDescription = mir_tstrdup(description);
}
void ExtraIconGroup::rebuildIcons()
@@ -123,7 +125,7 @@ int ExtraIconGroup::setIconByName(int id, HANDLE hContact, const char *value) int ExtraIconGroup::internalSetIcon(int id, HANDLE hContact, void *value, bool bByName)
{
if (insideApply) {
- for (unsigned int i = 0; i < items.size(); i++)
+ for (unsigned int i=0; i < items.size(); i++)
if (items[i]->getID() == id) {
if (bByName)
return items[i]->setIconByName(id, hContact, (const char*)value);
@@ -190,7 +192,7 @@ int ExtraIconGroup::internalSetIcon(int id, HANDLE hContact, void *value, bool b const TCHAR *ExtraIconGroup::getDescription() const
{
- return description.c_str();
+ return tszDescription;
}
const char *ExtraIconGroup::getDescIcon() const
diff --git a/src/modules/extraicons/extraicons.cpp b/src/modules/extraicons/extraicons.cpp index c362115a0f..a599e7c916 100644 --- a/src/modules/extraicons/extraicons.cpp +++ b/src/modules/extraicons/extraicons.cpp @@ -31,9 +31,19 @@ Boston, MA 02111-1307, USA. typedef vector<ExtraIcon*>::iterator IconIter;
+int SortFunc(const ExtraIcon *p1, const ExtraIcon *p2)
+{
+ int ret = p1->getPosition() - p2->getPosition();
+ if (ret != 0)
+ return ret;
+
+ int id1 = (p1->getType() != EXTRAICON_TYPE_GROUP) ? ((BaseExtraIcon*) p1)->getID() : 0;
+ int id2 = (p2->getType() != EXTRAICON_TYPE_GROUP) ? ((BaseExtraIcon*) p2)->getID() : 0;
+ return id1 - id2;
+}
+
+LIST<ExtraIcon> extraIconsByHandle(10), extraIconsBySlot(10, SortFunc);
LIST<BaseExtraIcon> registeredExtraIcons(10);
-vector<ExtraIcon*> extraIconsByHandle;
-vector<ExtraIcon*> extraIconsBySlot;
BOOL clistRebuildAlreadyCalled = FALSE;
BOOL clistApplyAlreadyCalled = FALSE;
@@ -93,17 +103,16 @@ int Clist_SetExtraIcon(HANDLE hContact, int slot, HANDLE hImage) ExtraIcon* GetExtraIcon(HANDLE id)
{
- unsigned int i = (int)id;
-
- if (i < 1 || i > extraIconsByHandle.size())
+ int i = (int)id;
+ if (i < 1 || i > extraIconsByHandle.getCount())
return NULL;
- return extraIconsByHandle[i - 1];
+ return extraIconsByHandle[i-1];
}
ExtraIcon* GetExtraIconBySlot(int slot)
{
- for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) {
+ for (int i = 0; i < extraIconsBySlot.getCount(); i++) {
ExtraIcon *extra = extraIconsBySlot[i];
if (extra->getSlot() == slot)
return extra;
@@ -173,44 +182,35 @@ static ExtraIconGroup * IsInGroup(vector<ExtraIconGroup *> &groups, BaseExtraIco return NULL;
}
-struct compareFunc : std::binary_function<const ExtraIcon *, const ExtraIcon *, bool>
-{
- bool operator()(const ExtraIcon * one, const ExtraIcon * two) const
- {
- return *one < *two;
- }
-};
-
void RebuildListsBasedOnGroups(vector<ExtraIconGroup *> &groups)
{
- extraIconsByHandle.clear();
- for (int k = 0; k < registeredExtraIcons.getCount(); k++)
- extraIconsByHandle.push_back(registeredExtraIcons[k]);
+ extraIconsByHandle.destroy();
+ int k;
+ for (k=0; k < registeredExtraIcons.getCount(); k++)
+ extraIconsByHandle.insert(registeredExtraIcons[k]);
- unsigned int i;
- for (i = 0; i < extraIconsBySlot.size(); i++) {
- ExtraIcon *extra = extraIconsBySlot[i];
+ for (k=0; k < extraIconsBySlot.getCount(); k++) {
+ ExtraIcon *extra = extraIconsBySlot[k];
if (extra->getType() == EXTRAICON_TYPE_GROUP)
delete extra;
}
- extraIconsBySlot.clear();
+ extraIconsBySlot.destroy();
+ unsigned int i;
for (i = 0; i < groups.size(); i++) {
ExtraIconGroup *group = groups[i];
for (unsigned int j = 0; j < group->items.size(); j++)
- extraIconsByHandle[group->items[j]->getID() - 1] = group;
+ extraIconsByHandle.put(group->items[j]->getID()-1, group);
- extraIconsBySlot.push_back(group);
+ extraIconsBySlot.insert(group);
}
- for (i = 0; i < extraIconsByHandle.size(); i++) {
- ExtraIcon *extra = extraIconsByHandle[i];
+ for (k = 0; k < extraIconsByHandle.getCount(); k++) {
+ ExtraIcon *extra = extraIconsByHandle[k];
if (extra->getType() != EXTRAICON_TYPE_GROUP)
- extraIconsBySlot.push_back(extra);
+ extraIconsBySlot.insert(extra);
}
-
- std::sort(extraIconsBySlot.begin(), extraIconsBySlot.end(), compareFunc());
}
///////////////////////////////////////////////////////////////////////////////
@@ -247,7 +247,7 @@ int ClistExtraListRebuild(WPARAM wParam, LPARAM lParam) ResetIcons();
- for (unsigned int i = 0; i < extraIconsBySlot.size(); i++)
+ for (int i=0; i < extraIconsBySlot.getCount(); i++)
extraIconsBySlot[i]->rebuildIcons();
return 0;
@@ -261,7 +261,7 @@ int ClistExtraImageApply(WPARAM wParam, LPARAM lParam) clistApplyAlreadyCalled = TRUE;
- for (unsigned int i = 0; i < extraIconsBySlot.size(); i++)
+ for (int i=0; i < extraIconsBySlot.getCount(); i++)
extraIconsBySlot[i]->applyIcon(hContact);
return 0;
@@ -275,7 +275,7 @@ int ClistExtraClick(WPARAM wParam, LPARAM lParam) int clistSlot = (int)lParam;
- for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) {
+ for (int i=0; i < extraIconsBySlot.getCount(); i++) {
ExtraIcon *extra = extraIconsBySlot[i];
if (ConvertToClistSlot(extra->getSlot()) == clistSlot) {
extra->onClick(hContact);
@@ -379,7 +379,7 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) // Found one, now merge it
if ( _tcsicmp(extra->getDescription(), desc)) {
- tstring newDesc = extra->getDescription();
+ CMString newDesc = extra->getDescription();
newDesc += _T(" / ");
newDesc += desc;
extra->setDescription(newDesc.c_str());
@@ -429,7 +429,7 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) extra->hLangpack = (int)lParam;
registeredExtraIcons.insert(extra);
- extraIconsByHandle.push_back(extra);
+ extraIconsByHandle.insert(extra);
vector<ExtraIconGroup *> groups;
LoadGroups(groups);
@@ -441,8 +441,7 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) for (unsigned int i = 0; i < groups.size(); i++)
delete groups[i];
- extraIconsBySlot.push_back(extra);
- std::sort(extraIconsBySlot.begin(), extraIconsBySlot.end(), compareFunc());
+ extraIconsBySlot.insert(extra);
}
if (slot >= 0 || group != NULL) {
@@ -450,7 +449,7 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) extra->rebuildIcons();
slot = 0;
- for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) {
+ for (int i=0; i < extraIconsBySlot.getCount(); i++) {
ExtraIcon *ex = extraIconsBySlot[i];
if (ex->getSlot() < 0)
continue;
@@ -548,4 +547,6 @@ void UnloadExtraIconsModule(void) delete registeredExtraIcons[i];
registeredExtraIcons.destroy();
+ extraIconsByHandle.destroy();
+ extraIconsBySlot.destroy();
}
diff --git a/src/modules/extraicons/extraicons.h b/src/modules/extraicons/extraicons.h index ed2bdd20d4..b8c346b9f2 100644 --- a/src/modules/extraicons/extraicons.h +++ b/src/modules/extraicons/extraicons.h @@ -34,8 +34,7 @@ extern HINSTANCE hInst; #include "Extraicon.h"
extern LIST<BaseExtraIcon> registeredExtraIcons;
-extern vector<ExtraIcon*> extraIconsByHandle;
-extern vector<ExtraIcon*> extraIconsBySlot;
+extern LIST<ExtraIcon> extraIconsByHandle, extraIconsBySlot;
void RebuildListsBasedOnGroups(vector<ExtraIconGroup *> &groups);
ExtraIcon * GetExtraIconBySlot(int slot);
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;
diff --git a/src/modules/extraicons/usedIcons.cpp b/src/modules/extraicons/usedIcons.cpp index 00f4e3f3c1..374f4bfb1c 100644 --- a/src/modules/extraicons/usedIcons.cpp +++ b/src/modules/extraicons/usedIcons.cpp @@ -25,37 +25,35 @@ Boston, MA 02111-1307, USA. struct Icon
{
- string name;
+ char *name;
int refCount;
HANDLE hImage;
Icon(const char *icolibName) :
- name(icolibName), refCount(0), hImage(INVALID_HANDLE_VALUE)
+ name( mir_strdup(icolibName)), refCount(0), hImage(INVALID_HANDLE_VALUE)
{
}
-};
-static vector<Icon> usedIcons;
+ ~Icon()
+ { mir_free(name);
+ }
+};
-static Icon* FindIcon(const char *icolibName)
+static int SortFunc(const Icon *p1, const Icon *p2)
{
- Icon *icon = NULL;
+ return strcmp(p1->name, p2->name);
+}
- for (unsigned int i = 0; i < usedIcons.size(); i++) {
- Icon *tmp = &usedIcons[i];
- if (tmp->name == icolibName) {
- icon = tmp;
- break;
- }
- }
+static OBJLIST<Icon> usedIcons(50, SortFunc);
- if (icon == NULL) {
- usedIcons.push_back( Icon(icolibName));
- icon = &usedIcons[usedIcons.size() - 1];
- }
+static Icon* FindIcon(const char *icolibName)
+{
+ Icon *icon = usedIcons.find((Icon*)&icolibName);
+ if (icon == NULL)
+ usedIcons.insert(icon = new Icon(icolibName));
if (icon->hImage == INVALID_HANDLE_VALUE) {
- HICON hIcon = Skin_GetIcon(icon->name.c_str());
+ HICON hIcon = Skin_GetIcon(icon->name);
if (hIcon != NULL) {
icon->hImage = ExtraIcon_Add(hIcon);
Skin_ReleaseIcon(hIcon);
@@ -79,14 +77,9 @@ HANDLE AddIcon(const char *icolibName) void RemoveIcon(const char *icolibName)
{
- for (unsigned int i = 0; i < usedIcons.size(); i++) {
- Icon *icon = &usedIcons[i];
- if (icon->name != icolibName)
- continue;
-
+ Icon *icon = usedIcons.find((Icon*)&icolibName);
+ if (icon != NULL)
icon->refCount--;
- break;
- }
}
static bool NotUsedIcon(const Icon &icon)
@@ -96,8 +89,11 @@ static bool NotUsedIcon(const Icon &icon) void ResetIcons()
{
- usedIcons.erase(std::remove_if(usedIcons.begin(), usedIcons.end(), NotUsedIcon), usedIcons.end());
-
- for (unsigned int i = 0; i < usedIcons.size(); i++)
- usedIcons[i].hImage = INVALID_HANDLE_VALUE;
+ for (int i = usedIcons.getCount()-1; i >= 0; i--) {
+ Icon &p = usedIcons[i];
+ if (p.refCount <= 0)
+ usedIcons.remove(i);
+ else
+ p.hImage = INVALID_HANDLE_VALUE;
+ }
}
|