diff options
author | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2009-04-17 01:59:38 +0000 |
---|---|---|
committer | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2009-04-17 01:59:38 +0000 |
commit | d27127d44576580e3a0000590b6179f06cc67b8e (patch) | |
tree | f5643bfb5d73ec3e4089c9cc6dcf44e5740e8ac9 | |
parent | fc229f1f9ff3600a9708da57f5629e14673011b7 (diff) |
extraicons: new options dialog
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@167 c086bb3d-8645-0410-b8da-73a8550f86e7
-rw-r--r-- | Plugins/extraicons/.cproject | 3 | ||||
-rw-r--r-- | Plugins/extraicons/CallbackExtraIcon.cpp | 6 | ||||
-rw-r--r-- | Plugins/extraicons/CallbackExtraIcon.h | 4 | ||||
-rw-r--r-- | Plugins/extraicons/DefaultExtraIcons.cpp | 31 | ||||
-rw-r--r-- | Plugins/extraicons/ExtraIcon.cpp | 64 | ||||
-rw-r--r-- | Plugins/extraicons/ExtraIcon.h | 20 | ||||
-rw-r--r-- | Plugins/extraicons/IcolibExtraIcon.cpp | 14 | ||||
-rw-r--r-- | Plugins/extraicons/IcolibExtraIcon.h | 2 | ||||
-rw-r--r-- | Plugins/extraicons/commons.h | 3 | ||||
-rw-r--r-- | Plugins/extraicons/extraicons.cpp | 70 | ||||
-rw-r--r-- | Plugins/extraicons/extraicons.dsp | 6 | ||||
-rw-r--r-- | Plugins/extraicons/m_extraicons.h | 6 | ||||
-rw-r--r-- | Plugins/extraicons/options.cpp | 310 | ||||
-rw-r--r-- | Plugins/extraicons/resource.h | 7 | ||||
-rw-r--r-- | Plugins/extraicons/resource.rc | 27 | ||||
-rw-r--r-- | Plugins/extraicons/usedIcons.cpp | 14 |
16 files changed, 499 insertions, 88 deletions
diff --git a/Plugins/extraicons/.cproject b/Plugins/extraicons/.cproject index 334b143..d9cd872 100644 --- a/Plugins/extraicons/.cproject +++ b/Plugins/extraicons/.cproject @@ -48,10 +48,11 @@ <option defaultValue="true" id="gnu.c.link.mingw.so.debug.option.shared.1575843488" name="Shared (-shared)" superClass="gnu.c.link.mingw.so.debug.option.shared" valueType="boolean"/>
</tool>
<tool commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG}"${OUTPUT_PREFIX}${OUTPUT}" ${INPUTS}" id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.so.debug.836489507" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.so.debug">
-<option id="gnu.cpp.link.option.paths.1417684678" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths"/>
+<option id="gnu.cpp.link.option.paths.1417684678" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths"/>
<option defaultValue="true" id="gnu.cpp.link.mingw.so.debug.option.shared.1239249880" name="Shared (-shared)" superClass="gnu.cpp.link.mingw.so.debug.option.shared" valueType="boolean"/>
<option id="gnu.cpp.link.option.libs.1498281393" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="gdi32"/>
+<listOptionValue builtIn="false" value="comctl32"/>
</option>
<option id="gnu.cpp.link.option.flags.714506212" name="Linker flags" superClass="gnu.cpp.link.option.flags" value="" valueType="string"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.417851543" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
diff --git a/Plugins/extraicons/CallbackExtraIcon.cpp b/Plugins/extraicons/CallbackExtraIcon.cpp index 8ea2631..4ea8574 100644 --- a/Plugins/extraicons/CallbackExtraIcon.cpp +++ b/Plugins/extraicons/CallbackExtraIcon.cpp @@ -19,9 +19,9 @@ #include "commons.h"
-CallbackExtraIcon::CallbackExtraIcon(const char *name, const char *description, const char *descIcon,
+CallbackExtraIcon::CallbackExtraIcon(int id, const char *name, const char *description, const char *descIcon,
MIRANDAHOOK RebuildIcons, MIRANDAHOOK ApplyIcon, MIRANDAHOOKPARAM OnClick, LPARAM param) :
- ExtraIcon(name, description, descIcon, OnClick, param), RebuildIcons(RebuildIcons), ApplyIcon(ApplyIcon),
+ ExtraIcon(id, name, description, descIcon, OnClick, param), RebuildIcons(RebuildIcons), ApplyIcon(ApplyIcon),
needToRebuild(true)
{
}
@@ -57,7 +57,7 @@ void CallbackExtraIcon::applyIcon(HANDLE hContact) if (!isEnabled() || hContact == NULL)
return;
- ApplyIcon((WPARAM) hContact, (LPARAM) ConvertToClistSlot(slot));
+ ApplyIcon((WPARAM) hContact, 0);
}
int CallbackExtraIcon::setIcon(HANDLE hContact, void *icon)
diff --git a/Plugins/extraicons/CallbackExtraIcon.h b/Plugins/extraicons/CallbackExtraIcon.h index a51e0d4..0dc4c2b 100644 --- a/Plugins/extraicons/CallbackExtraIcon.h +++ b/Plugins/extraicons/CallbackExtraIcon.h @@ -25,8 +25,8 @@ class CallbackExtraIcon : public ExtraIcon
{
public:
- CallbackExtraIcon(const char *name, const char *description, const char *descIcon, MIRANDAHOOK RebuildIcons,
- MIRANDAHOOK ApplyIcon, MIRANDAHOOKPARAM OnClick, LPARAM param);
+ CallbackExtraIcon(int id, const char *name, const char *description, const char *descIcon,
+ MIRANDAHOOK RebuildIcons, MIRANDAHOOK ApplyIcon, MIRANDAHOOKPARAM OnClick, LPARAM param);
virtual ~CallbackExtraIcon();
virtual int getType() const;
diff --git a/Plugins/extraicons/DefaultExtraIcons.cpp b/Plugins/extraicons/DefaultExtraIcons.cpp index 270f26a..7acc9e6 100644 --- a/Plugins/extraicons/DefaultExtraIcons.cpp +++ b/Plugins/extraicons/DefaultExtraIcons.cpp @@ -129,16 +129,16 @@ struct Info void (*SetIcon)(HANDLE hContact, Info *info, const char *text);
void (*OnClick)(Info *info, const char *text);
HANDLE hExtraIcon;
-} infos[] = {
- { "email", "E-mail", "core_main_14", { NULL, "e-mail",
- "UserInfo", "e-mail",
- "UserInfo", "Mye-mail0" }, DefaultSetIcon, &EmailOnClick, NULL },
- { "sms", "Phone/SMS", "core_main_17", { NULL, "Cellular",
+} infos[] = {
+ { "email", "E-mail", "core_main_14", { NULL, "e-mail",
+ "UserInfo", "e-mail",
+ "UserInfo", "Mye-mail0" }, DefaultSetIcon, &EmailOnClick, NULL },
+ { "sms", "Phone/SMS", "core_main_17", { NULL, "Cellular",
"UserInfo", "Cellular",
- "UserInfo", "Phone",
- "UserInfo", "MyPhone0" }, DefaultSetIcon, NULL, NULL },
- { "homepage", "Homepage", "core_main_2", { NULL, "Homepage",
- "UserInfo", "Homepage" }, DefaultSetIcon, &HomepageOnClick, NULL },
+ "UserInfo", "Phone",
+ "UserInfo", "MyPhone0" }, DefaultSetIcon, NULL, NULL },
+ { "homepage", "Homepage", "core_main_2", { NULL, "Homepage",
+ "UserInfo", "Homepage" }, DefaultSetIcon, &HomepageOnClick, NULL },
};
static void EmailOnClick(Info *info, const char *text)
@@ -244,7 +244,8 @@ static int SettingChanged(WPARAM wParam, LPARAM lParam) static int DefaultOnClick(WPARAM wParam, LPARAM lParam, LPARAM param)
{
- if (param == NULL)
+ Info *info = (Info *) param;
+ if (info == NULL)
return 0;
HANDLE hContact = (HANDLE) wParam;
@@ -255,8 +256,6 @@ static int DefaultOnClick(WPARAM wParam, LPARAM lParam, LPARAM param) if (IsEmpty(proto))
return 0;
- Info *info = (Info *) param;
-
bool found = false;
for (unsigned int j = 0; !found && j < MAX_REGS(info->db); j += 2)
{
@@ -363,11 +362,7 @@ static int ProtocolApplyIcon(WPARAM wParam, LPARAM lParam) if (pi != NULL)
hImage = pi->hImage;
- IconExtraColumn iec = { 0 };
- iec.cbSize = sizeof(iec);
- iec.ColumnType = slot;
- iec.hImage = (hImage == NULL ? (HANDLE) -1 : hImage);
- CallService(MS_CLIST_EXTRA_SET_ICON, (WPARAM) hContact, (LPARAM) &iec);
+ ExtraIcon_SetIcon(hExtraProto, hContact, hImage);
return 0;
}
@@ -384,6 +379,6 @@ static int ProtocolOnClick(WPARAM wParam, LPARAM lParam, LPARAM param) static void ProtocolInit()
{
- hExtraProto = ExtraIcon_Register("protocol", "Account", "core_main_34",
+ hExtraProto = ExtraIcon_Register("protocol", "Account", "core_main_34",
&ProtocolRebuildIcons, &ProtocolApplyIcon, &ProtocolOnClick);
}
diff --git a/Plugins/extraicons/ExtraIcon.cpp b/Plugins/extraicons/ExtraIcon.cpp index 89775f1..3e33f5b 100644 --- a/Plugins/extraicons/ExtraIcon.cpp +++ b/Plugins/extraicons/ExtraIcon.cpp @@ -19,9 +19,10 @@ #include "commons.h"
-ExtraIcon::ExtraIcon(const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
+ExtraIcon::ExtraIcon(int id, const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
LPARAM param) :
- name(name), description(description), descIcon(descIcon), OnClick(OnClick), onClickParam(param), slot(-1)
+ id(id), name(name), description(description), descIcon(descIcon), OnClick(OnClick), onClickParam(param), slot(-1),
+ position(1000)
{
}
@@ -64,6 +65,21 @@ void ExtraIcon::setSlot(int slot) this->slot = slot;
}
+int ExtraIcon::getPosition() const
+{
+ return position;
+}
+
+void ExtraIcon::setPosition(int position)
+{
+ this->position = position;
+}
+
+int ExtraIcon::getID() const
+{
+ return id;
+}
+
bool ExtraIcon::isEnabled() const
{
return slot >= 0;
@@ -94,3 +110,47 @@ void ExtraIcon::onClick(HANDLE hContact) OnClick((WPARAM) hContact, (LPARAM) ConvertToClistSlot(slot), onClickParam);
}
+int ExtraIcon::compare(const ExtraIcon *other) const
+{
+ int ret = getPosition() - other->getPosition();
+ if (ret != 0)
+ return ret;
+ return getID() - other->getID();
+}
+
+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/Plugins/extraicons/ExtraIcon.h b/Plugins/extraicons/ExtraIcon.h index b1ada82..b38a0cb 100644 --- a/Plugins/extraicons/ExtraIcon.h +++ b/Plugins/extraicons/ExtraIcon.h @@ -25,7 +25,8 @@ class ExtraIcon
{
public:
- ExtraIcon(const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, LPARAM param);
+ ExtraIcon(int id, const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
+ LPARAM param);
virtual ~ExtraIcon();
virtual bool needToRebuildIcons() =0;
@@ -36,6 +37,7 @@ public: virtual int setIcon(HANDLE hContact, void *icon) =0;
+ virtual int getID() const;
virtual const char *getName() const;
virtual const char *getDescription() const;
virtual void setDescription(const char *desc);
@@ -46,9 +48,23 @@ public: virtual int getSlot() const;
virtual void setSlot(int slot);
+ virtual int getPosition() const;
+ virtual void setPosition(int position);
+
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;
+
protected:
+ int id;
std::string name;
std::string description;
std::string descIcon;
@@ -56,6 +72,8 @@ protected: LPARAM onClickParam;
int slot;
+ int position;
};
+
#endif // __EXTRAICON_H__
diff --git a/Plugins/extraicons/IcolibExtraIcon.cpp b/Plugins/extraicons/IcolibExtraIcon.cpp index 5531aae..a7d98c9 100644 --- a/Plugins/extraicons/IcolibExtraIcon.cpp +++ b/Plugins/extraicons/IcolibExtraIcon.cpp @@ -19,9 +19,9 @@ #include "commons.h"
-IcolibExtraIcon::IcolibExtraIcon(const char *name, const char *description, const char *descIcon,
+IcolibExtraIcon::IcolibExtraIcon(int id, const char *name, const char *description, const char *descIcon,
MIRANDAHOOKPARAM OnClick, LPARAM param) :
- ExtraIcon(name, description, descIcon, OnClick, param)
+ ExtraIcon(id, name, description, descIcon, OnClick, param)
{
char setting[512];
mir_snprintf(setting, MAX_REGS(setting), "%s/%s", MODULE_NAME, name);
@@ -51,6 +51,9 @@ void IcolibExtraIcon::applyIcon(HANDLE hContact) if (!isEnabled() || hContact == NULL)
return;
+ if (hContact == (HANDLE) 0x004a984c)
+ OutputDebugString("t");
+
HANDLE hImage = NULL;
DBVARIANT dbv = { 0 };
@@ -84,10 +87,11 @@ int IcolibExtraIcon::setIcon(HANDLE hContact, void *icon) }
}
+ // Delete don't work and I don't know why
if (IsEmpty(icolibName))
- DBDeleteContactSetting(hContact, MODULE_NAME, name.c_str());
- else
- DBWriteContactSettingString(hContact, MODULE_NAME, name.c_str(), icolibName);
+ icolibName = "";
+
+ DBWriteContactSettingString(hContact, MODULE_NAME, name.c_str(), icolibName);
if (isEnabled())
{
diff --git a/Plugins/extraicons/IcolibExtraIcon.h b/Plugins/extraicons/IcolibExtraIcon.h index b385294..6d6c440 100644 --- a/Plugins/extraicons/IcolibExtraIcon.h +++ b/Plugins/extraicons/IcolibExtraIcon.h @@ -25,7 +25,7 @@ class IcolibExtraIcon : public ExtraIcon
{
public:
- IcolibExtraIcon(const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
+ IcolibExtraIcon(int id, const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
LPARAM param);
virtual ~IcolibExtraIcon();
diff --git a/Plugins/extraicons/commons.h b/Plugins/extraicons/commons.h index 33835a3..19cce84 100644 --- a/Plugins/extraicons/commons.h +++ b/Plugins/extraicons/commons.h @@ -26,14 +26,17 @@ #endif
+#define _WIN32_IE 0x500
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
+#include <commctrl.h>
#include <map>
#include <vector>
#include <string>
+#include <algorithm>
using namespace std;
// Miranda headers
diff --git a/Plugins/extraicons/extraicons.cpp b/Plugins/extraicons/extraicons.cpp index 9edccd3..6bbcff6 100644 --- a/Plugins/extraicons/extraicons.cpp +++ b/Plugins/extraicons/extraicons.cpp @@ -46,6 +46,7 @@ vector<ExtraIcon*> extraIcons; char *metacontacts_proto = NULL;
BOOL clistRebuildAlreadyCalled = FALSE;
+BOOL clistApplyAlreadyCalled = FALSE;
int clistFirstSlot = 0;
int clistSlotCount = 0;
@@ -214,7 +215,8 @@ int PreShutdown(WPARAM wParam, LPARAM lParam) int GetNumberOfSlots()
{
- return MIN(clistSlotCount, extraIcons.size());
+ // return MIN(clistSlotCount, extraIcons.size());
+ return clistSlotCount;
}
int ConvertToClistSlot(int slot)
@@ -256,16 +258,13 @@ ExtraIcon * GetExtraIconBySlot(int slot) return NULL;
}
-int GetFirstEmptySlot()
+struct compareFunc : std::binary_function<const ExtraIcon *, const ExtraIcon *, bool>
{
- int slots = GetNumberOfSlots();
- for (int i = 0; i < slots; ++i)
+ bool operator()(const ExtraIcon * one, const ExtraIcon * two) const
{
- if (GetExtraIconBySlot(i) == NULL)
- return i;
+ return *one < *two;
}
- return -1;
-}
+};
int ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
{
@@ -309,15 +308,17 @@ int ExtraIcon_Register(WPARAM wParam, LPARAM lParam) return i + 1;
}
+ int id = extraIcons.size() + 1;
+
ExtraIcon *extra;
switch (ei->type)
{
case EXTRAICON_TYPE_CALLBACK:
- extra = new CallbackExtraIcon(ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon, ei->RebuildIcons,
- ei->ApplyIcon, ei->OnClick, ei->onClickParam);
+ extra = new CallbackExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon,
+ ei->RebuildIcons, ei->ApplyIcon, ei->OnClick, ei->onClickParam);
break;
case EXTRAICON_TYPE_ICOLIB:
- extra = new IcolibExtraIcon(ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon, ei->OnClick,
+ extra = new IcolibExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon, ei->OnClick,
ei->onClickParam);
break;
default:
@@ -325,38 +326,43 @@ int ExtraIcon_Register(WPARAM wParam, LPARAM lParam) }
char setting[512];
+ mir_snprintf(setting, MAX_REGS(setting), "Position_%s", ei->name);
+ extra->setPosition(DBGetContactSettingWord(NULL, MODULE_NAME, setting, 1000));
+
mir_snprintf(setting, MAX_REGS(setting), "Slot_%s", ei->name);
- int slot = DBGetContactSettingWord(NULL, MODULE_NAME, setting, -2);
+ int slot = DBGetContactSettingWord(NULL, MODULE_NAME, setting, 1);
if (slot == (WORD) -1)
slot = -1;
- else if (slot == (WORD) -2)
- slot = -2;
- else if (slot >= clistSlotCount)
- slot = -2;
+ extra->setSlot(slot);
- int origSlot = slot;
+ extraIcons.push_back(extra);
if (slot >= 0)
- if (GetExtraIconBySlot(slot) != NULL)
- slot = -2;
-
- extraIcons.push_back(extra);
+ {
+ vector<ExtraIcon *> tmp;
+ tmp = extraIcons;
+ std::sort(tmp.begin(), tmp.end(), compareFunc());
- if (slot == -2)
- slot = GetFirstEmptySlot();
+ if (clistRebuildAlreadyCalled)
+ extra->rebuildIcons();
- extra->setSlot(slot);
+ slot = 0;
+ for (unsigned int i = 0; i < tmp.size(); ++i)
+ {
+ ExtraIcon *ex = tmp[i];
+ if (ex->getSlot() < 0)
+ continue;
- if (origSlot != slot)
- DBWriteContactSettingWord(NULL, MODULE_NAME, setting, slot);
+ int oldSlot = ex->getSlot();
+ ex->setSlot(slot++);
- if (clistRebuildAlreadyCalled)
- {
- extra->rebuildIcons();
- extra->applyIcons();
+ if (clistApplyAlreadyCalled && (ex == extra || oldSlot != slot))
+ extra->applyIcons();
+ }
}
- return extraIcons.size();
+
+ return id;
}
int ExtraIcon_SetIcon(WPARAM wParam, LPARAM lParam)
@@ -395,6 +401,8 @@ int ClistExtraImageApply(WPARAM wParam, LPARAM lParam) if (hContact == NULL)
return 0;
+ clistApplyAlreadyCalled = TRUE;
+
for (unsigned int i = 0; i < extraIcons.size(); ++i)
extraIcons[i]->applyIcon(hContact);
diff --git a/Plugins/extraicons/extraicons.dsp b/Plugins/extraicons/extraicons.dsp index 9fe9872..0aae181 100644 --- a/Plugins/extraicons/extraicons.dsp +++ b/Plugins/extraicons/extraicons.dsp @@ -86,7 +86,7 @@ BSC32=bscmake.exe LINK32=link.exe
# ADD BASE LINK32 comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..bin\release\Plugins\extraicons.dll" /filealign:0x200 /ALIGN:4096 /ignore:4108
# SUBTRACT BASE LINK32 /profile /pdb:none
-# ADD LINK32 shell32.lib kernel32.lib user32.lib gdi32.lib /nologo /base:"0x3EC20000" /dll /incremental:yes /debug /machine:I386 /out:"..\..\bin\debug unicode\Plugins\extraicons.dll" /filealign:0x200 /ALIGN:4096 /ignore:4108
+# ADD LINK32 shell32.lib kernel32.lib user32.lib gdi32.lib comctl32.lib /nologo /base:"0x3EC20000" /dll /incremental:yes /debug /machine:I386 /out:"..\..\bin\debug unicode\Plugins\extraicons.dll" /filealign:0x200 /ALIGN:4096 /ignore:4108
# SUBTRACT LINK32 /profile /pdb:none
!ELSEIF "$(CFG)" == "extraicons - Win32 Unicode Debug"
@@ -212,6 +212,10 @@ SOURCE=.\res\Chatchannel.ico # End Source File
# Begin Source File
+SOURCE=.\res\empty.ico
+# End Source File
+# Begin Source File
+
SOURCE=.\res\female.ico
# End Source File
# Begin Source File
diff --git a/Plugins/extraicons/m_extraicons.h b/Plugins/extraicons/m_extraicons.h index 589d040..54cc395 100644 --- a/Plugins/extraicons/m_extraicons.h +++ b/Plugins/extraicons/m_extraicons.h @@ -46,7 +46,7 @@ typedef struct { // Callback to set the icon to clist, calling MS_CLIST_EXTRA_SET_ICON or MS_EXTRAICON_SET_ICON
// wParam = HANDLE hContact
- // lParam = int slot
+ // lParam = 0
MIRANDAHOOK ApplyIcon;
// Other optional callbacks
@@ -92,7 +92,7 @@ typedef struct { static HANDLE ExtraIcon_Register(const char *name, const char *description, const char *descIcon,
MIRANDAHOOK RebuildIcons,
MIRANDAHOOK ApplyIcon,
- MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = NULL)
+ MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = 0)
{
if (!ServiceExists(MS_EXTRAICON_REGISTER))
return NULL;
@@ -112,7 +112,7 @@ static HANDLE ExtraIcon_Register(const char *name, const char *description, cons }
static HANDLE ExtraIcon_Register(const char *name, const char *description, const char *descIcon = NULL,
- MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = NULL)
+ MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = 0)
{
if (!ServiceExists(MS_EXTRAICON_REGISTER))
return NULL;
diff --git a/Plugins/extraicons/options.cpp b/Plugins/extraicons/options.cpp index bc32b15..6a4664d 100644 --- a/Plugins/extraicons/options.cpp +++ b/Plugins/extraicons/options.cpp @@ -19,14 +19,6 @@ #include "commons.h"
-#ifndef PSM_CHANGED
-#define PSM_CHANGED (WM_USER + 104)
-#endif
-
-#ifndef PSN_APPLY
-#define PSN_APPLY ((0U-200U)-2)
-#endif
-
#define ICON_SIZE 16
// Prototypes /////////////////////////////////////////////////////////////////////////////////////
@@ -106,7 +98,7 @@ static void RemoveExtraIcons(int slot) }
}
-static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+static BOOL CALLBACK OptionsDlgProcOld(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static int numSlots;
@@ -204,7 +196,7 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA {
LPNMHDR lpnmhdr = (LPNMHDR) lParam;
- if (lpnmhdr->idFrom == 0 && lpnmhdr->code == PSN_APPLY)
+ if (lpnmhdr->idFrom == 0 && lpnmhdr->code == (UINT) PSN_APPLY)
{
int * slots = new int[extraIcons.size()];
@@ -277,7 +269,7 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA int slot = (lpdis->CtlID - IDC_SLOT) / 2;
if (slot < 0 || slot > numSlots * 2)
break;
- if (lpdis->itemID == -1)
+ if (lpdis->itemID == (UINT) -1)
break;
ExtraIcon *extra = (ExtraIcon *) lpdis->itemData;
@@ -347,3 +339,299 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA return 0;
}
+
+static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+{
+ ExtraIcon *a = (ExtraIcon *) lParam1;
+ ExtraIcon *b = (ExtraIcon *) lParam2;
+ return a->compare(b);
+}
+
+static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ static int dragging = 0;
+ static HANDLE hDragItem = NULL;
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
+
+ HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
+ SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_NOHSCROLL);
+
+ int cx = GetSystemMetrics(SM_CXSMICON);
+ HIMAGELIST hImageList = ImageList_Create(cx, cx, ILC_COLOR32 | ILC_MASK, 2, 2);
+
+ unsigned int i;
+ for (i = 0; i < extraIcons.size(); ++i)
+ {
+ ExtraIcon *extra = extraIcons[i];
+
+ HICON hIcon = NULL;
+ if (!IsEmpty(extra->getDescIcon()))
+ hIcon = (HICON) CallService(MS_SKIN2_GETICON, 0, (LPARAM) extra->getDescIcon());
+
+ if (hIcon == NULL)
+ {
+ HICON hDefaultIcon = (HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_EMPTY), IMAGE_ICON, cx, cx,
+ LR_DEFAULTCOLOR | LR_SHARED);
+ ImageList_AddIcon(hImageList, hDefaultIcon);
+ DestroyIcon(hDefaultIcon);
+ }
+ else
+ ImageList_AddIcon(hImageList, hIcon);
+
+ if (hIcon != NULL)
+ CallService(MS_SKIN2_RELEASEICON, (WPARAM) hIcon, 0);
+ }
+ TreeView_SetImageList(tree, hImageList, TVSIL_NORMAL);
+
+ TVINSERTSTRUCT tvis = { 0 };
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = TVI_LAST;
+ tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
+ tvis.item.stateMask = TVIS_STATEIMAGEMASK;
+ for (i = 0; i < extraIcons.size(); ++i)
+ {
+ ExtraIcon *extra = extraIcons[i];
+
+ tvis.item.lParam = (LPARAM) extra;
+ tvis.item.pszText = (char *) extra->getDescription();
+ tvis.item.iSelectedImage = tvis.item.iImage = i;
+ tvis.item.state = INDEXTOSTATEIMAGEMASK(extra->getSlot() < 0 ? 1 : 2);
+ TreeView_InsertItem(tree, &tvis);
+ }
+
+ TVSORTCB sort = { 0 };
+ sort.hParent = NULL;
+ sort.lParam = 0;
+ sort.lpfnCompare = CompareFunc;
+ TreeView_SortChildrenCB(tree, &sort, 0);
+
+ return TRUE;
+ }
+ case WM_COMMAND:
+ {
+ // SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
+ break;
+ }
+ case WM_NOTIFY:
+ {
+ LPNMHDR lpnmhdr = (LPNMHDR) lParam;
+ if (lpnmhdr->idFrom == 0)
+ {
+ if (lpnmhdr->code == (UINT) PSN_APPLY)
+ {
+ int *slots = new int[extraIcons.size()];
+
+ unsigned int i;
+ for (i = 0; i < extraIcons.size(); ++i)
+ slots[i] = -1;
+
+ HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
+
+
+ // Get positions and slots
+ HTREEITEM ht = TreeView_GetRoot(tree);
+ BYTE pos = 0;
+ unsigned int firstEmptySlot = 0;
+ TVITEM tvi = { 0 };
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+ while (ht)
+ {
+ tvi.hItem = ht;
+ TreeView_GetItem(tree, &tvi);
+
+ ExtraIcon *extra = (ExtraIcon *) tvi.lParam;
+ extra->setPosition(pos);
+ if ((tvi.state & INDEXTOSTATEIMAGEMASK(3)) == INDEXTOSTATEIMAGEMASK(2))
+ slots[extra->getID() - 1] = firstEmptySlot++;
+
+ ht = TreeView_GetNextSibling(tree, ht);
+ pos++;
+ }
+
+ // Clean removed slots
+ for (int j = firstEmptySlot; j < GetNumberOfSlots(); ++j)
+ {
+ if (GetExtraIconBySlot(j) != NULL)
+ // Had and icon and lost
+ RemoveExtraIcons(j);
+ }
+
+ // Apply icons to new slots
+ for (i = 0; i < extraIcons.size(); ++i)
+ {
+ ExtraIcon *extra = extraIcons[i];
+
+ char setting[512];
+ mir_snprintf(setting, MAX_REGS(setting), "Position_%s", extra->getName());
+ DBWriteContactSettingWord(NULL, MODULE_NAME, setting, extra->getPosition());
+
+ int oldSlot = extra->getSlot();
+ if (oldSlot == slots[i])
+ continue;
+
+ extra->setSlot(slots[i]);
+
+ mir_snprintf(setting, MAX_REGS(setting), "Slot_%s", extra->getName());
+ DBWriteContactSettingWord(NULL, MODULE_NAME, setting, extra->getSlot());
+
+ if (slots[i] < 0)
+ continue;
+
+ if (oldSlot < 0 && extra->needToRebuildIcons())
+ extra->rebuildIcons();
+ extra->applyIcons();
+ }
+
+ delete[] slots;
+
+ return TRUE;
+ }
+ }
+ else if (lpnmhdr->idFrom == IDC_EXTRAORDER)
+ {
+ HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
+
+ switch (lpnmhdr->code)
+ {
+ case TVN_BEGINDRAG:
+ {
+ 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 item = TreeView_GetSelection(tree);
+ if (item != 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)
+ TreeView_SelectItem(tree, hSelected);
+ break;
+ }
+ }
+ }
+
+ break;
+ }
+ case WM_MOUSEMOVE:
+ {
+ if (!dragging)
+ break;
+
+ HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
+
+ TVHITTESTINFO hti;
+ hti.pt.x = (short) LOWORD(lParam);
+ hti.pt.y = (short) HIWORD(lParam);
+ ClientToScreen(hwndDlg, &hti.pt);
+ ScreenToClient(tree, &hti.pt);
+ TreeView_HitTest(tree, &hti);
+ if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT))
+ {
+ HTREEITEM it = hti.hItem;
+ hti.pt.y -= TreeView_GetItemHeight(tree) / 2;
+ TreeView_HitTest(tree, &hti);
+ if (!(hti.flags & TVHT_ABOVE))
+ TreeView_SetInsertMark(tree, hti.hItem, 1);
+ else
+ TreeView_SetInsertMark(tree, it, 0);
+ }
+ else
+ {
+ if (hti.flags & TVHT_ABOVE)
+ SendDlgItemMessage(hwndDlg, IDC_EXTRAORDER, WM_VSCROLL, MAKEWPARAM(SB_LINEUP,0), 0);
+ if (hti.flags & TVHT_BELOW)
+ SendDlgItemMessage(hwndDlg, IDC_EXTRAORDER, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN,0), 0);
+ TreeView_SetInsertMark(tree, NULL, 0);
+ }
+ break;
+ }
+ case WM_LBUTTONUP:
+ {
+ if (!dragging)
+ break;
+
+ HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
+
+ TreeView_SetInsertMark(tree, NULL, 0);
+ dragging = 0;
+ ReleaseCapture();
+
+ TVHITTESTINFO hti;
+ hti.pt.x = (short) LOWORD(lParam);
+ hti.pt.y = (short) HIWORD(lParam);
+ ClientToScreen(hwndDlg, &hti.pt);
+ ScreenToClient(tree, &hti.pt);
+ hti.pt.y -= TreeView_GetItemHeight(tree) / 2;
+ TreeView_HitTest(tree,&hti);
+ if (hDragItem == hti.hItem)
+ break;
+
+ if (!(hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT | TVHT_ABOVE | TVHT_BELOW)))
+ break;
+
+ if (hti.flags & TVHT_ABOVE)
+ hti.hItem = TVI_FIRST;
+ else if (hti.flags & TVHT_BELOW)
+ hti.hItem = TVI_LAST;
+
+ TVINSERTSTRUCT tvis;
+ TCHAR name[128];
+ tvis.item.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
+ tvis.item.stateMask = 0xFFFFFFFF;
+ tvis.item.pszText = name;
+ tvis.item.cchTextMax = MAX_REGS(name);
+ tvis.item.hItem = (HTREEITEM) hDragItem;
+ TreeView_GetItem(tree, &tvis.item);
+
+ TreeView_DeleteItem(tree, hDragItem);
+
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = hti.hItem;
+ TreeView_SelectItem(tree, TreeView_InsertItem(tree, &tvis));
+
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
+
+ break;
+ }
+ }
+
+ return 0;
+}
diff --git a/Plugins/extraicons/resource.h b/Plugins/extraicons/resource.h index 7ede69e..9f905a3 100644 --- a/Plugins/extraicons/resource.h +++ b/Plugins/extraicons/resource.h @@ -2,14 +2,17 @@ // Microsoft Developer Studio generated include file.
// Used by resource.rc
//
-#define IDD_OPTIONS 119
+#define IDD_OPTIONS_OLD 119
#define IDI_ALWAYSVIS 120
+#define IDD_OPTIONS 120
#define IDI_NEVERVIS 121
#define IDI_CHAT 122
#define IDI_MALE 123
#define IDI_FEMALE 124
+#define IDI_EMPTY 125
#define IDC_SLOT_L 1075
#define IDC_SLOT 1076
+#define IDC_EXTRAORDER 1889
#define IDC_STATIC -1
// Next default values for new objects
@@ -18,7 +21,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_3D_CONTROLS 1
-#define _APS_NEXT_RESOURCE_VALUE 125
+#define _APS_NEXT_RESOURCE_VALUE 126
#define _APS_NEXT_COMMAND_VALUE 40005
#define _APS_NEXT_CONTROL_VALUE 1077
#define _APS_NEXT_SYMED_VALUE 101
diff --git a/Plugins/extraicons/resource.rc b/Plugins/extraicons/resource.rc index 0dfe3e6..e2d07c4 100644 --- a/Plugins/extraicons/resource.rc +++ b/Plugins/extraicons/resource.rc @@ -27,10 +27,10 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL // Dialog
//
-IDD_OPTIONS DIALOGEX 0, 0, 276, 229
+IDD_OPTIONS_OLD DIALOGEX 0, 0, 276, 229
STYLE DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
EXSTYLE WS_EX_CONTROLPARENT
-FONT 8, "MS Shell Dlg"
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
LTEXT "Select the extra icons to be shown in the contact list:",
IDC_STATIC,1,9,274,13
@@ -40,6 +40,20 @@ BEGIN WS_TABSTOP
END
+IDD_OPTIONS DIALOGEX 0, 0, 276, 229
+STYLE DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
+BEGIN
+ LTEXT "Select the extra icons to be shown in the contact list:",
+ IDC_STATIC,1,9,274,13
+ CONTROL "",IDC_EXTRAORDER,"SysTreeView32",TVS_NOTOOLTIPS |
+ TVS_CHECKBOXES | TVS_FULLROWSELECT | WS_BORDER |
+ WS_TABSTOP,1,24,274,160
+ LTEXT "* only the first 10 icons will be shown",IDC_STATIC,1,
+ 190,274,13
+END
+
/////////////////////////////////////////////////////////////////////////////
//
@@ -49,6 +63,14 @@ END #ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
+ IDD_OPTIONS_OLD, DIALOG
+ BEGIN
+ LEFTMARGIN, 1
+ RIGHTMARGIN, 275
+ TOPMARGIN, 1
+ BOTTOMMARGIN, 228
+ END
+
IDD_OPTIONS, DIALOG
BEGIN
LEFTMARGIN, 1
@@ -72,6 +94,7 @@ IDI_NEVERVIS ICON DISCARDABLE "res\\NeverVis.ico" IDI_CHAT ICON DISCARDABLE "res\\Chatchannel.ico"
IDI_MALE ICON DISCARDABLE "res\\male.ico"
IDI_FEMALE ICON DISCARDABLE "res\\female.ico"
+IDI_EMPTY ICON DISCARDABLE "res\\empty.ico"
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/Plugins/extraicons/usedIcons.cpp b/Plugins/extraicons/usedIcons.cpp index 0be3995..010f0d8 100644 --- a/Plugins/extraicons/usedIcons.cpp +++ b/Plugins/extraicons/usedIcons.cpp @@ -93,17 +93,21 @@ void RemoveIcon(const char *icolibName) icon->refCount--;
- if (icon->refCount <= 0)
- usedIcons.erase(it);
-
break;
}
}
void ResetIcons()
{
- for (unsigned int i = 0; i < usedIcons.size(); ++i)
- usedIcons[i].hImage = NULL;
+ for (vector<Icon>::iterator it = usedIcons.begin(); it != usedIcons.end(); it++)
+ {
+ Icon *icon = &*it;
+
+ if (icon->refCount <= 0)
+ usedIcons.erase(it);
+ else
+ icon->hImage = NULL;
+ }
}
|