summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2009-04-23 04:31:27 +0000
committerpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2009-04-23 04:31:27 +0000
commit3892d0da37e70a6c0106e57dad835e9a67933b02 (patch)
tree4ae8600d4eb5acce08a42b68d1d218c4e47153cc
parentd27127d44576580e3a0000590b6179f06cc67b8e (diff)
extraicons: start of group code
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@168 c086bb3d-8645-0410-b8da-73a8550f86e7
-rw-r--r--Plugins/extraicons/.cproject6
-rw-r--r--Plugins/extraicons/BaseExtraIcon.cpp59
-rw-r--r--Plugins/extraicons/BaseExtraIcon.h29
-rw-r--r--Plugins/extraicons/CallbackExtraIcon.cpp21
-rw-r--r--Plugins/extraicons/CallbackExtraIcon.h8
-rw-r--r--Plugins/extraicons/DefaultExtraIcons.cpp9
-rw-r--r--Plugins/extraicons/ExtraIcon.cpp39
-rw-r--r--Plugins/extraicons/ExtraIcon.h24
-rw-r--r--Plugins/extraicons/ExtraIconGroup.cpp162
-rw-r--r--Plugins/extraicons/ExtraIconGroup.h54
-rw-r--r--Plugins/extraicons/IcolibExtraIcon.cpp44
-rw-r--r--Plugins/extraicons/IcolibExtraIcon.h8
-rw-r--r--Plugins/extraicons/commons.h3
-rw-r--r--Plugins/extraicons/extraicons.cpp41
-rw-r--r--Plugins/extraicons/extraicons.dsp16
-rw-r--r--Plugins/extraicons/options.cpp576
-rw-r--r--Plugins/extraicons/resource.h9
-rw-r--r--Plugins/extraicons/resource.rc20
18 files changed, 781 insertions, 347 deletions
diff --git a/Plugins/extraicons/.cproject b/Plugins/extraicons/.cproject
index d9cd872..39d4b46 100644
--- a/Plugins/extraicons/.cproject
+++ b/Plugins/extraicons/.cproject
@@ -47,7 +47,7 @@
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.so.debug.650923336" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.so.debug">
<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}&quot;${OUTPUT_PREFIX}${OUTPUT}&quot; ${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">
+<tool commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG}&quot;C:\Desenvolvimento\Miranda\bin\Debug Unicode\Plugins\${OUTPUT_PREFIX}${OUTPUT}&quot; ${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"/>
<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">
@@ -64,7 +64,7 @@
</toolChain>
</folderInfo>
<sourceEntries>
-<entry excluding="resource.aps|extraicons.plg|extraicons.opt|extraicons.ncb" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
+<entry excluding="multitree|resource.aps|extraicons.plg|extraicons.opt|extraicons.ncb" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
@@ -551,7 +551,7 @@
</toolChain>
</folderInfo>
<sourceEntries>
-<entry excluding="resource.aps|extraicons.plg|extraicons.opt|extraicons.ncb" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
+<entry excluding="multitree|resource.aps|extraicons.plg|extraicons.opt|extraicons.ncb" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
diff --git a/Plugins/extraicons/BaseExtraIcon.cpp b/Plugins/extraicons/BaseExtraIcon.cpp
new file mode 100644
index 0000000..54a8a2b
--- /dev/null
+++ b/Plugins/extraicons/BaseExtraIcon.cpp
@@ -0,0 +1,59 @@
+/*
+ Copyright (C) 2009 Ricardo Pescuma Domenecci
+
+ This is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this file; see the file license.txt. If
+ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+#include "commons.h"
+
+BaseExtraIcon::BaseExtraIcon(int id, const char *name, const char *description, const char *descIcon,
+ MIRANDAHOOKPARAM OnClick, LPARAM param) :
+ ExtraIcon(id, name), description(description), descIcon(descIcon), OnClick(OnClick), onClickParam(param)
+{
+}
+
+BaseExtraIcon::~BaseExtraIcon()
+{
+}
+
+const char *BaseExtraIcon::getDescription() const
+{
+ return description.c_str();
+}
+
+void BaseExtraIcon::setDescription(const char *desc)
+{
+ description = desc;
+}
+
+const char *BaseExtraIcon::getDescIcon() const
+{
+ return descIcon.c_str();
+}
+
+void BaseExtraIcon::setDescIcon(const char *icon)
+{
+ descIcon = icon;
+}
+
+void BaseExtraIcon::onClick(HANDLE hContact)
+{
+ if (OnClick == NULL)
+ return;
+
+ OnClick((WPARAM) hContact, (LPARAM) ConvertToClistSlot(slot), onClickParam);
+}
+
diff --git a/Plugins/extraicons/BaseExtraIcon.h b/Plugins/extraicons/BaseExtraIcon.h
new file mode 100644
index 0000000..7194e68
--- /dev/null
+++ b/Plugins/extraicons/BaseExtraIcon.h
@@ -0,0 +1,29 @@
+#ifndef __BASEEXTRAICON_H__
+#define __BASEEXTRAICON_H__
+
+#include "ExtraIcon.h"
+
+class BaseExtraIcon : public ExtraIcon
+{
+public:
+ BaseExtraIcon(int id, const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
+ LPARAM param);
+ virtual ~BaseExtraIcon();
+
+ virtual const char *getDescription() const;
+ virtual void setDescription(const char *desc);
+ virtual const char *getDescIcon() const;
+ virtual void setDescIcon(const char *icon);
+ virtual int getType() const =0;
+
+ virtual void onClick(HANDLE hContact);
+
+
+protected:
+ std::string description;
+ std::string descIcon;
+ MIRANDAHOOKPARAM OnClick;
+ LPARAM onClickParam;
+};
+
+#endif // __BASEEXTRAICON_H__
diff --git a/Plugins/extraicons/CallbackExtraIcon.cpp b/Plugins/extraicons/CallbackExtraIcon.cpp
index 4ea8574..b80675d 100644
--- a/Plugins/extraicons/CallbackExtraIcon.cpp
+++ b/Plugins/extraicons/CallbackExtraIcon.cpp
@@ -21,7 +21,7 @@
CallbackExtraIcon::CallbackExtraIcon(int id, const char *name, const char *description, const char *descIcon,
MIRANDAHOOK RebuildIcons, MIRANDAHOOK ApplyIcon, MIRANDAHOOKPARAM OnClick, LPARAM param) :
- ExtraIcon(id, name, description, descIcon, OnClick, param), RebuildIcons(RebuildIcons), ApplyIcon(ApplyIcon),
+ BaseExtraIcon(id, name, description, descIcon, OnClick, param), RebuildIcons(RebuildIcons), ApplyIcon(ApplyIcon),
needToRebuild(true)
{
}
@@ -35,11 +35,6 @@ int CallbackExtraIcon::getType() const
return EXTRAICON_TYPE_CALLBACK;
}
-bool CallbackExtraIcon::needToRebuildIcons()
-{
- return needToRebuild;
-}
-
void CallbackExtraIcon::rebuildIcons()
{
if (!isEnabled())
@@ -57,13 +52,21 @@ void CallbackExtraIcon::applyIcon(HANDLE hContact)
if (!isEnabled() || hContact == NULL)
return;
+ if (needToRebuild)
+ rebuildIcons();
+
ApplyIcon((WPARAM) hContact, 0);
}
-int CallbackExtraIcon::setIcon(HANDLE hContact, void *icon)
+int CallbackExtraIcon::setIcon(int id, HANDLE hContact, void *icon)
{
- if (!isEnabled() || hContact == NULL)
+ if (!isEnabled() || hContact == NULL || id != this->id)
return -1;
- return Clist_SetExtraIcon(hContact, slot, (HANDLE) icon);
+ return ClistSetExtraIcon(hContact, slot, (HANDLE) icon);
}
+
+void CallbackExtraIcon::storeIcon(HANDLE hContact, void *icon)
+{
+}
+
diff --git a/Plugins/extraicons/CallbackExtraIcon.h b/Plugins/extraicons/CallbackExtraIcon.h
index 0dc4c2b..7b46c88 100644
--- a/Plugins/extraicons/CallbackExtraIcon.h
+++ b/Plugins/extraicons/CallbackExtraIcon.h
@@ -20,9 +20,9 @@
#ifndef __CALLBACKEXTRAICON_H__
#define __CALLBACKEXTRAICON_H__
-#include "ExtraIcon.h"
+#include "BaseExtraIcon.h"
-class CallbackExtraIcon : public ExtraIcon
+class CallbackExtraIcon : public BaseExtraIcon
{
public:
CallbackExtraIcon(int id, const char *name, const char *description, const char *descIcon,
@@ -31,11 +31,11 @@ public:
virtual int getType() const;
- virtual bool needToRebuildIcons();
virtual void rebuildIcons();
virtual void applyIcon(HANDLE hContact);
- virtual int setIcon(HANDLE hContact, void *icon);
+ virtual int setIcon(int id, HANDLE hContact, void *icon);
+ virtual void storeIcon(HANDLE hContact, void *icon);
private:
int(*RebuildIcons)(WPARAM wParam, LPARAM lParam);
diff --git a/Plugins/extraicons/DefaultExtraIcons.cpp b/Plugins/extraicons/DefaultExtraIcons.cpp
index 7acc9e6..100f8e8 100644
--- a/Plugins/extraicons/DefaultExtraIcons.cpp
+++ b/Plugins/extraicons/DefaultExtraIcons.cpp
@@ -350,15 +350,14 @@ static ProtoInfo *FindProto(const char * proto)
static int ProtocolApplyIcon(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE) wParam;
- int slot = (int) lParam;
char *proto = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
if (IsEmpty(proto))
return 0;
- HANDLE hImage = NULL;
-
ProtoInfo *pi = FindProto(proto);
+
+ HANDLE hImage = NULL;
if (pi != NULL)
hImage = pi->hImage;
@@ -379,6 +378,6 @@ static int ProtocolOnClick(WPARAM wParam, LPARAM lParam, LPARAM param)
static void ProtocolInit()
{
- hExtraProto = ExtraIcon_Register("protocol", "Account", "core_main_34",
- &ProtocolRebuildIcons, &ProtocolApplyIcon, &ProtocolOnClick);
+ hExtraProto = ExtraIcon_Register("protocol", "Account", "core_main_34", &ProtocolRebuildIcons, &ProtocolApplyIcon,
+ &ProtocolOnClick);
}
diff --git a/Plugins/extraicons/ExtraIcon.cpp b/Plugins/extraicons/ExtraIcon.cpp
index 3e33f5b..696613b 100644
--- a/Plugins/extraicons/ExtraIcon.cpp
+++ b/Plugins/extraicons/ExtraIcon.cpp
@@ -19,10 +19,8 @@
#include "commons.h"
-ExtraIcon::ExtraIcon(int id, const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
- LPARAM param) :
- id(id), name(name), description(description), descIcon(descIcon), OnClick(OnClick), onClickParam(param), slot(-1),
- position(1000)
+ExtraIcon::ExtraIcon(int id, const char *name) :
+ id(id), name(name), slot(-1), position(1000)
{
}
@@ -35,26 +33,6 @@ const char *ExtraIcon::getName() const
return name.c_str();
}
-const char *ExtraIcon::getDescription() const
-{
- return description.c_str();
-}
-
-void ExtraIcon::setDescription(const char *desc)
-{
- description = desc;
-}
-
-const char *ExtraIcon::getDescIcon() const
-{
- return descIcon.c_str();
-}
-
-void ExtraIcon::setDescIcon(const char *icon)
-{
- descIcon = icon;
-}
-
int ExtraIcon::getSlot() const
{
return slot;
@@ -102,14 +80,6 @@ void ExtraIcon::applyIcons()
}
}
-void ExtraIcon::onClick(HANDLE hContact)
-{
- if (OnClick == NULL)
- return;
-
- OnClick((WPARAM) hContact, (LPARAM) ConvertToClistSlot(slot), onClickParam);
-}
-
int ExtraIcon::compare(const ExtraIcon *other) const
{
int ret = getPosition() - other->getPosition();
@@ -154,3 +124,8 @@ bool ExtraIcon::operator>=(const ExtraIcon & other) const
return c >= 0;
}
+int ExtraIcon::ClistSetExtraIcon(HANDLE hContact, int slot, HANDLE hImage)
+{
+ return Clist_SetExtraIcon(hContact, slot, hImage);
+}
+
diff --git a/Plugins/extraicons/ExtraIcon.h b/Plugins/extraicons/ExtraIcon.h
index b38a0cb..19cfb9e 100644
--- a/Plugins/extraicons/ExtraIcon.h
+++ b/Plugins/extraicons/ExtraIcon.h
@@ -22,27 +22,26 @@
#include <string>
+#define EXTRAICON_TYPE_GROUP -1
+
class ExtraIcon
{
public:
- ExtraIcon(int id, const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
- LPARAM param);
+ ExtraIcon(int id, const char *name);
virtual ~ExtraIcon();
- virtual bool needToRebuildIcons() =0;
virtual void rebuildIcons() =0;
virtual void applyIcons();
virtual void applyIcon(HANDLE hContact) =0;
- virtual void onClick(HANDLE hContact);
+ virtual void onClick(HANDLE hContact) =0;
- virtual int setIcon(HANDLE hContact, void *icon) =0;
+ virtual int setIcon(int id, HANDLE hContact, void *icon) =0;
+ virtual void storeIcon(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);
- virtual const char *getDescIcon() const;
- virtual void setDescIcon(const char *icon);
+ virtual const char *getDescription() const =0;
+ virtual const char *getDescIcon() const =0;
virtual int getType() const =0;
virtual int getSlot() const;
@@ -66,14 +65,11 @@ public:
protected:
int id;
std::string name;
- std::string description;
- std::string descIcon;
- MIRANDAHOOKPARAM OnClick;
- LPARAM onClickParam;
int slot;
int position;
-};
+ virtual int ClistSetExtraIcon(HANDLE hContact, int slot, HANDLE hImage);
+};
#endif // __EXTRAICON_H__
diff --git a/Plugins/extraicons/ExtraIconGroup.cpp b/Plugins/extraicons/ExtraIconGroup.cpp
new file mode 100644
index 0000000..48ff791
--- /dev/null
+++ b/Plugins/extraicons/ExtraIconGroup.cpp
@@ -0,0 +1,162 @@
+/*
+ Copyright (C) 2009void ExtraIconGroup::storeIcon(int id, HANDLE hContact, void *icon)
+ {
+ }
+
+ Ricardo Pescuma Domenecci
+
+ This is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this file; see the file license.txt. If
+ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+#include "commons.h"
+
+ExtraIconGroup::ExtraIconGroup(int id, const char *name) :
+ ExtraIcon(id, name), setValidExtraIcon(false)
+{
+ char setting[512];
+ mir_snprintf(setting, MAX_REGS(setting), "%s/%s", MODULE_NAME, name);
+ CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (WPARAM) setting);
+}
+
+ExtraIconGroup::~ExtraIconGroup()
+{
+ items.clear();
+}
+
+void ExtraIconGroup::addExtraIcon(ExtraIcon *extra)
+{
+ items.push_back(extra);
+
+ description = "";
+ for (unsigned int i = 0; i < items.size(); ++i)
+ {
+ if (i > 0)
+ description += " / ";
+ description += items[i]->getDescription();
+ }
+}
+
+void ExtraIconGroup::rebuildIcons()
+{
+ for (unsigned int i = 0; i < items.size(); ++i)
+ items[i]->rebuildIcons();
+}
+
+void ExtraIconGroup::applyIcon(HANDLE hContact)
+{
+ if (hContact == NULL)
+ return;
+
+ setValidExtraIcon = false;
+
+ unsigned int i;
+ for (i = 0; !setValidExtraIcon && i < items.size(); ++i)
+ items[i]->applyIcon(hContact);
+
+ DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), setValidExtraIcon ? items[i]->getID() : 0);
+}
+
+ExtraIcon * ExtraIconGroup::getCurrentItem(HANDLE hContact) const
+{
+ int id = (int) DBGetContactSettingDword(hContact, MODULE_NAME, name.c_str(), 0);
+ if (id < 1)
+ return NULL;
+
+ for (unsigned int i = 0; i < items.size(); ++i)
+ if (id == items[i]->getID())
+ return items[i];
+
+ return NULL;
+}
+
+void ExtraIconGroup::onClick(HANDLE hContact)
+{
+ ExtraIcon *extra = getCurrentItem(hContact);
+ if (extra != NULL)
+ extra->onClick(hContact);
+}
+
+int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon)
+{
+ ExtraIcon *current = getCurrentItem(hContact);
+ int currentPos = items.size();
+ ExtraIcon *store = NULL;
+ int storePos = items.size();
+ for (unsigned int i = 0; i < items.size(); ++i)
+ {
+ if (items[i]->getID() == id)
+ {
+ store = items[i];
+ storePos = i;
+ }
+
+ if (items[i] == current)
+ {
+ currentPos = i;
+ }
+ }
+
+ if (store == NULL)
+ {
+ return -1;
+ }
+ else if (storePos < currentPos)
+ {
+ DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), id);
+ return store->setIcon(id, hContact, icon);
+ }
+ else if (storePos == currentPos) // store == current
+ {
+ return store->setIcon(id, hContact, icon);
+ }
+ else // if (storePos > currentPos)
+ {
+ store->storeIcon(hContact, icon);
+ return 0;
+ }
+}
+
+void ExtraIconGroup::storeIcon(HANDLE hContact, void *icon)
+{
+}
+
+const char *ExtraIconGroup::getDescription() const
+{
+ return description.c_str();
+}
+
+const char *ExtraIconGroup::getDescIcon() const
+{
+ for (unsigned int i = 0; i < items.size(); ++i)
+ if (!IsEmpty(items[i]->getDescIcon()))
+ return items[i]->getDescIcon();
+
+ return "";
+}
+
+int ExtraIconGroup::getType() const
+{
+ return EXTRAICON_TYPE_GROUP;
+}
+
+int ExtraIconGroup::ClistSetExtraIcon(HANDLE hContact, int slot, HANDLE hImage)
+{
+ if (hImage != NULL && hImage != (HANDLE) -1)
+ setValidExtraIcon = true;
+
+ return ExtraIcon::ClistSetExtraIcon(hContact, slot, hImage);
+}
+
diff --git a/Plugins/extraicons/ExtraIconGroup.h b/Plugins/extraicons/ExtraIconGroup.h
new file mode 100644
index 0000000..90b7a46
--- /dev/null
+++ b/Plugins/extraicons/ExtraIconGroup.h
@@ -0,0 +1,54 @@
+/*
+ Copyright (C) 2009 Ricardo Pescuma Domenecci
+
+ This is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this file; see the file license.txt. If
+ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __EXTRAICONGROUP_H__
+#define __EXTRAICONGROUP_H__
+
+#include <vector>
+#include "ExtraIcon.h"
+
+class ExtraIconGroup : public ExtraIcon
+{
+public:
+ ExtraIconGroup(int id, const char *name);
+ virtual ~ExtraIconGroup();
+
+ virtual void addExtraIcon(ExtraIcon *extra);
+
+ virtual void rebuildIcons();
+ virtual void applyIcon(HANDLE hContact);
+ virtual void onClick(HANDLE hContact);
+
+ virtual int setIcon(int id, HANDLE hContact, void *icon);
+ virtual void storeIcon(HANDLE hContact, void *icon);
+
+ virtual const char *getDescription() const;
+ virtual const char *getDescIcon() const;
+ virtual int getType() const;
+
+protected:
+ std::string description;
+ std::vector<ExtraIcon*> items;
+ bool setValidExtraIcon;
+
+ virtual ExtraIcon * getCurrentItem(HANDLE hContact) const;
+ virtual int ClistSetExtraIcon(HANDLE hContact, int slot, HANDLE hImage);
+};
+
+#endif // __EXTRAICONGROUP_H__
diff --git a/Plugins/extraicons/IcolibExtraIcon.cpp b/Plugins/extraicons/IcolibExtraIcon.cpp
index a7d98c9..1e7cfbf 100644
--- a/Plugins/extraicons/IcolibExtraIcon.cpp
+++ b/Plugins/extraicons/IcolibExtraIcon.cpp
@@ -21,7 +21,7 @@
IcolibExtraIcon::IcolibExtraIcon(int id, const char *name, const char *description, const char *descIcon,
MIRANDAHOOKPARAM OnClick, LPARAM param) :
- ExtraIcon(id, name, description, descIcon, OnClick, param)
+ BaseExtraIcon(id, name, description, descIcon, OnClick, param)
{
char setting[512];
mir_snprintf(setting, MAX_REGS(setting), "%s/%s", MODULE_NAME, name);
@@ -37,11 +37,6 @@ int IcolibExtraIcon::getType() const
return EXTRAICON_TYPE_ICOLIB;
}
-bool IcolibExtraIcon::needToRebuildIcons()
-{
- return false;
-}
-
void IcolibExtraIcon::rebuildIcons()
{
}
@@ -51,9 +46,6 @@ void IcolibExtraIcon::applyIcon(HANDLE hContact)
if (!isEnabled() || hContact == NULL)
return;
- if (hContact == (HANDLE) 0x004a984c)
- OutputDebugString("t");
-
HANDLE hImage = NULL;
DBVARIANT dbv = { 0 };
@@ -68,13 +60,11 @@ void IcolibExtraIcon::applyIcon(HANDLE hContact)
Clist_SetExtraIcon(hContact, slot, hImage);
}
-int IcolibExtraIcon::setIcon(HANDLE hContact, void *icon)
+int IcolibExtraIcon::setIcon(int id, HANDLE hContact, void *icon)
{
- if (hContact == NULL)
+ if (hContact == NULL || id != this->id)
return -1;
- const char *icolibName = (const char *) icon;
-
if (isEnabled())
{
DBVARIANT dbv = { 0 };
@@ -87,21 +77,33 @@ int IcolibExtraIcon::setIcon(HANDLE hContact, void *icon)
}
}
- // Delete don't work and I don't know why
- if (IsEmpty(icolibName))
- icolibName = "";
-
- DBWriteContactSettingString(hContact, MODULE_NAME, name.c_str(), icolibName);
+ storeIcon(hContact, icon);
if (isEnabled())
{
- HANDLE hImage = NULL;
- if (!IsEmpty(icolibName))
+ const char *icolibName = (const char *) icon;
+
+ HANDLE hImage;
+ if (IsEmpty(icolibName))
+ hImage = NULL;
+ else
hImage = AddIcon(icolibName);
- return Clist_SetExtraIcon(hContact, slot, hImage);
+ return ClistSetExtraIcon(hContact, slot, hImage);
}
return 0;
}
+void IcolibExtraIcon::storeIcon(HANDLE hContact, void *icon)
+{
+ if (hContact == NULL)
+ return;
+
+ const char *icolibName = (const char *) icon;
+ if (IsEmpty(icolibName))
+ icolibName = ""; // Delete don't work and I don't know why
+
+ DBWriteContactSettingString(hContact, MODULE_NAME, name.c_str(), icolibName);
+}
+
diff --git a/Plugins/extraicons/IcolibExtraIcon.h b/Plugins/extraicons/IcolibExtraIcon.h
index 6d6c440..2f142f2 100644
--- a/Plugins/extraicons/IcolibExtraIcon.h
+++ b/Plugins/extraicons/IcolibExtraIcon.h
@@ -20,9 +20,9 @@
#ifndef __ICOLIBEXTRAICON_H__
#define __ICOLIBEXTRAICON_H__
-#include "ExtraIcon.h"
+#include "BaseExtraIcon.h"
-class IcolibExtraIcon : public ExtraIcon
+class IcolibExtraIcon : public BaseExtraIcon
{
public:
IcolibExtraIcon(int id, const char *name, const char *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
@@ -31,11 +31,11 @@ public:
virtual int getType() const;
- virtual bool needToRebuildIcons();
virtual void rebuildIcons();
virtual void applyIcon(HANDLE hContact);
- virtual int setIcon(HANDLE hContact, void *icon);
+ virtual int setIcon(int id, HANDLE hContact, void *icon);
+ virtual void storeIcon(HANDLE hContact, void *icon);
};
#endif // __ICOLIBEXTRAICON_H__
diff --git a/Plugins/extraicons/commons.h b/Plugins/extraicons/commons.h
index 19cce84..9ae6620 100644
--- a/Plugins/extraicons/commons.h
+++ b/Plugins/extraicons/commons.h
@@ -63,6 +63,7 @@ using namespace std;
#include "m_extraicons.h"
#include "ExtraIcon.h"
+#include "ExtraIconGroup.h"
#include "CallbackExtraIcon.h"
#include "IcolibExtraIcon.h"
#include "usedIcons.h"
@@ -83,7 +84,7 @@ extern PLUGINLINK *pluginLink;
extern vector<HANDLE> hHooks;
-extern vector<ExtraIcon*> extraIcons;
+extern vector<BaseExtraIcon*> registeredExtraIcons;
ExtraIcon * GetExtraIconBySlot(int slot);
int GetNumberOfSlots();
diff --git a/Plugins/extraicons/extraicons.cpp b/Plugins/extraicons/extraicons.cpp
index 6bbcff6..a3c7ed3 100644
--- a/Plugins/extraicons/extraicons.cpp
+++ b/Plugins/extraicons/extraicons.cpp
@@ -42,6 +42,8 @@ UTF8_INTERFACE utfi;
vector<HANDLE> hHooks;
vector<HANDLE> hServices;
+vector<BaseExtraIcon*> registeredExtraIcons;
+vector<BaseExtraIcon*> extraIconsByHandle;
vector<ExtraIcon*> extraIcons;
char *metacontacts_proto = NULL;
@@ -215,7 +217,6 @@ int PreShutdown(WPARAM wParam, LPARAM lParam)
int GetNumberOfSlots()
{
- // return MIN(clistSlotCount, extraIcons.size());
return clistSlotCount;
}
@@ -224,7 +225,7 @@ int ConvertToClistSlot(int slot)
if (slot < 0)
return slot;
- return clistSlotCount + clistFirstSlot - 1 - slot;
+ return clistFirstSlot + slot;
}
int Clist_SetExtraIcon(HANDLE hContact, int slot, HANDLE hImage)
@@ -241,10 +242,10 @@ ExtraIcon *GetExtraIcon(HANDLE id)
{
unsigned int i = (int) id;
- if (i < 1 || i > extraIcons.size())
+ if (i < 1 || i > extraIconsByHandle.size())
return NULL;
- return extraIcons[i - 1];
+ return extraIconsByHandle[i - 1];
}
ExtraIcon * GetExtraIconBySlot(int slot)
@@ -283,9 +284,9 @@ int ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
const char *desc = Translate(ei->description);
- for (unsigned int i = 0; i < extraIcons.size(); ++i)
+ for (unsigned int i = 0; i < registeredExtraIcons.size(); ++i)
{
- ExtraIcon *extra = extraIcons[i];
+ BaseExtraIcon *extra = registeredExtraIcons[i];
if (strcmp(ei->name, extra->getName()) != 0)
continue;
@@ -296,6 +297,7 @@ int ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
if (stricmp(extra->getDescription(), desc))
{
+ // TODO Handle group
string newDesc = extra->getDescription();
newDesc += " / ";
newDesc += desc;
@@ -308,9 +310,9 @@ int ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
return i + 1;
}
- int id = extraIcons.size() + 1;
+ int id = registeredExtraIcons.size() + 1;
- ExtraIcon *extra;
+ BaseExtraIcon *extra;
switch (ei->type)
{
case EXTRAICON_TYPE_CALLBACK:
@@ -335,12 +337,14 @@ int ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
slot = -1;
extra->setSlot(slot);
+ registeredExtraIcons.push_back(extra);
+ extraIconsByHandle.push_back(extra);
extraIcons.push_back(extra);
if (slot >= 0)
{
- vector<ExtraIcon *> tmp;
- tmp = extraIcons;
+ vector<BaseExtraIcon *> tmp;
+ tmp = registeredExtraIcons;
std::sort(tmp.begin(), tmp.end(), compareFunc());
if (clistRebuildAlreadyCalled)
@@ -361,7 +365,6 @@ int ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
}
}
-
return id;
}
@@ -380,7 +383,7 @@ int ExtraIcon_SetIcon(WPARAM wParam, LPARAM lParam)
if (extra == NULL)
return -1;
- return extra->setIcon(ei->hContact, ei->hImage);
+ return extra->setIcon((int) ei->hExtraIcon, ei->hContact, ei->hImage);
}
int ClistExtraListRebuild(WPARAM wParam, LPARAM lParam)
@@ -389,8 +392,8 @@ int ClistExtraListRebuild(WPARAM wParam, LPARAM lParam)
ResetIcons();
- for (unsigned int i = 0; i < extraIcons.size(); ++i)
- extraIcons[i]->rebuildIcons();
+ for (unsigned int i = 0; i < registeredExtraIcons.size(); ++i)
+ registeredExtraIcons[i]->rebuildIcons();
return 0;
}
@@ -403,8 +406,8 @@ int ClistExtraImageApply(WPARAM wParam, LPARAM lParam)
clistApplyAlreadyCalled = TRUE;
- for (unsigned int i = 0; i < extraIcons.size(); ++i)
- extraIcons[i]->applyIcon(hContact);
+ for (unsigned int i = 0; i < registeredExtraIcons.size(); ++i)
+ registeredExtraIcons[i]->applyIcon(hContact);
return 0;
}
@@ -417,11 +420,11 @@ int ClistExtraClick(WPARAM wParam, LPARAM lParam)
int extra = (int) lParam;
- for (unsigned int i = 0; i < extraIcons.size(); ++i)
+ for (unsigned int i = 0; i < registeredExtraIcons.size(); ++i)
{
- if (ConvertToClistSlot(extraIcons[i]->getSlot()) == extra)
+ if (ConvertToClistSlot(registeredExtraIcons[i]->getSlot()) == extra)
{
- extraIcons[i]->onClick(hContact);
+ registeredExtraIcons[i]->onClick(hContact);
break;
}
}
diff --git a/Plugins/extraicons/extraicons.dsp b/Plugins/extraicons/extraicons.dsp
index 0aae181..ba2d1e4 100644
--- a/Plugins/extraicons/extraicons.dsp
+++ b/Plugins/extraicons/extraicons.dsp
@@ -160,6 +160,10 @@ LINK32=link.exe
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
+SOURCE=.\BaseExtraIcon.h
+# End Source File
+# Begin Source File
+
SOURCE=.\CallbackExtraIcon.h
# End Source File
# Begin Source File
@@ -176,6 +180,10 @@ SOURCE=.\ExtraIcon.h
# End Source File
# Begin Source File
+SOURCE=.\ExtraIconGroup.h
+# End Source File
+# Begin Source File
+
SOURCE=.\IcolibExtraIcon.h
# End Source File
# Begin Source File
@@ -236,6 +244,10 @@ SOURCE=.\resource.rc
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
+SOURCE=.\BaseExtraIcon.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\CallbackExtraIcon.cpp
# End Source File
# Begin Source File
@@ -248,6 +260,10 @@ SOURCE=.\ExtraIcon.cpp
# End Source File
# Begin Source File
+SOURCE=.\ExtraIconGroup.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\extraicons.cpp
# End Source File
# Begin Source File
diff --git a/Plugins/extraicons/options.cpp b/Plugins/extraicons/options.cpp
index 6a4664d..bb9d09e 100644
--- a/Plugins/extraicons/options.cpp
+++ b/Plugins/extraicons/options.cpp
@@ -98,246 +98,321 @@ static void RemoveExtraIcons(int slot)
}
}
-static BOOL CALLBACK OptionsDlgProcOld(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- static int numSlots;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
+/*
+ static BOOL CALLBACK OptionsDlgProcOld(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ static int numSlots;
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
+
+ numSlots = GetNumberOfSlots();
+
+ RECT rcLabel;
+ GetWindowRect(GetDlgItem(hwndDlg, IDC_SLOT_L), &rcLabel);
+ ScreenToClient(hwndDlg, &rcLabel);
+
+ RECT rcCombo;
+ GetWindowRect(GetDlgItem(hwndDlg, IDC_SLOT), &rcCombo);
+ ScreenToClient(hwndDlg, &rcCombo);
+
+ HFONT hFont = (HFONT) SendMessage(hwndDlg, WM_GETFONT, 0, 0);
+
+ int height = MAX(rcLabel.bottom - rcLabel.top, rcCombo.bottom - rcCombo.top) + 3;
+
+ for (int i = 0; i < numSlots; ++i)
+ {
+ int id = IDC_SLOT + i * 2;
+
+
+ // Create controls
+ if (i > 0)
+ {
+ char desc[256];
+ mir_snprintf(desc, MAX_REGS(desc), "Slot %d:", i + 1);
+
+ HWND tmp = CreateWindow("STATIC", Translate(desc),
+ WS_CHILD | WS_VISIBLE,
+ rcLabel.left, rcLabel.top + i * height,
+ rcLabel.right - rcLabel.left, rcLabel.bottom - rcLabel.top,
+ hwndDlg, 0, hInst, NULL);
+ SendMessage(tmp, WM_SETFONT, (WPARAM) hFont, FALSE);
+
+ HWND combo = CreateWindow("COMBOBOX", "",
+ WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | WS_VSCROLL
+ | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS,
+ rcCombo.left, rcCombo.top + i * height,
+ rcCombo.right - rcCombo.left, rcCombo.bottom - rcCombo.top,
+ hwndDlg, (HMENU) id, hInst, NULL);
+ SendMessage(combo, WM_SETFONT, (WPARAM) hFont, FALSE);
+ }
+
+ // Fill combo
+ int sel = 0;
+ SendDlgItemMessage(hwndDlg, id, CB_ADDSTRING, 0, (LPARAM) Translate("<Empty>"));
+ for (int j = 0; j < (int) extraIcons.size(); ++j)
+ {
+ ExtraIcon *extra = extraIcons[j];
+
+ int pos = SendDlgItemMessage(hwndDlg, id, CB_ADDSTRING, 0, (LPARAM) extra->getDescription());
+ SendDlgItemMessage(hwndDlg, id, CB_SETITEMDATA, pos, (DWORD) extra);
+
+ if (extra->getSlot() == i)
+ sel = j + 1;
+ }
+ SendDlgItemMessage(hwndDlg, id, CB_SETCURSEL, sel, 0);
+ }
+
+ break;
+ }
+ case WM_COMMAND:
+ {
+ HWND cbl = (HWND) lParam;
+ if (HIWORD(wParam) != CBN_SELCHANGE || cbl != GetFocus())
+ return 0;
+
+ int sel = SendMessage(cbl, CB_GETCURSEL, 0, 0);
+ if (sel > 0)
+ {
+ for (int i = 0; i < numSlots; ++i)
+ {
+ int id = IDC_SLOT + i * 2;
+
+ if (GetDlgItem(hwndDlg, id) == cbl)
+ continue;
+
+ int sl = SendDlgItemMessage(hwndDlg, id, CB_GETCURSEL, 0, 0);
+ if (sl == sel)
+ SendDlgItemMessage(hwndDlg, id, CB_SETCURSEL, 0, 0);
+ }
+ }
+
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ }
+ case WM_NOTIFY:
+ {
+ LPNMHDR lpnmhdr = (LPNMHDR) lParam;
+
+ if (lpnmhdr->idFrom == 0 && lpnmhdr->code == (UINT) PSN_APPLY)
+ {
+ int * slots = new int[extraIcons.size()];
+
+ int i;
+ for (i = 0; i < (int) extraIcons.size(); ++i)
+ slots[i] = -1;
+
+ for (i = 0; i < (int) extraIcons.size(); ++i)
+ {
+ if (slots[i] != -1)
+ continue;
+
+ for (int j = 0; j < numSlots; ++j)
+ {
+ if (SendDlgItemMessage(hwndDlg, IDC_SLOT + j * 2, CB_GETCURSEL, 0, 0) == i + 1)
+ {
+ slots[i] = j;
+ break;
+ }
+ }
+ }
+
+ for (int j = 0; j < numSlots; ++j)
+ {
+ // Has icon?
+ bool found = false;
+ for (i = 0; !found && i < (int) extraIcons.size(); ++i)
+ found = (slots[i] == j);
+ if (found)
+ continue;
+
+ // Had icon?
+ if (GetExtraIconBySlot(j) == NULL)
+ continue;
+
+
+ // Had and icon and lost
+ RemoveExtraIcons(j);
+ }
+
+ for (i = 0; i < (int) extraIcons.size(); ++i)
+ {
+ ExtraIcon *extra = extraIcons[i];
+
+ int oldSlot = extra->getSlot();
+ if (oldSlot == slots[i])
+ continue;
+
+ extra->setSlot(slots[i]);
+
+ char setting[512];
+ mir_snprintf(setting, MAX_REGS(setting), "Slot_%s", extra->getName());
+ DBWriteContactSettingWord(NULL, MODULE_NAME, setting, extra->getSlot());
+
+ extra->applyIcons();
+ }
+
+ delete[] slots;
+ }
+
+ break;
+ }
+ case WM_DRAWITEM:
+ {
+ LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;
+ if ((lpdis->CtlID % 2) != 0)
+ break;
+ int slot = (lpdis->CtlID - IDC_SLOT) / 2;
+ if (slot < 0 || slot > numSlots * 2)
+ break;
+ if (lpdis->itemID == (UINT) -1)
+ break;
+
+ ExtraIcon *extra = (ExtraIcon *) lpdis->itemData;
+
+ TEXTMETRIC tm;
+ RECT rc;
+
+ GetTextMetrics(lpdis->hDC, &tm);
+
+ COLORREF clrfore = SetTextColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED
+ ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
+ COLORREF clrback = SetBkColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT
+ : COLOR_WINDOW));
+
+ FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT
+ : COLOR_WINDOW));
+
+ rc.left = lpdis->rcItem.left + 2;
+
+
+ // Draw icon
+ HICON hIcon = NULL;
+ if (extra != NULL && !IsEmpty(extra->getDescIcon()))
+ hIcon = (HICON) CallService(MS_SKIN2_GETICON, 0, (LPARAM) extra->getDescIcon());
+ if (hIcon != NULL)
+ {
+ rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - ICON_SIZE) / 2;
+ DrawIconEx(lpdis->hDC, rc.left, rc.top, hIcon, 16, 16, 0, NULL, DI_NORMAL);
+ CallService(MS_SKIN2_RELEASEICON, (WPARAM) hIcon, 0);
+ }
+
+ rc.left += ICON_SIZE + 4;
+
+
+ // Draw text
+ rc.right = lpdis->rcItem.right - 2;
+ rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - tm.tmHeight) / 2;
+ rc.bottom = rc.top + tm.tmHeight;
+ DrawText(lpdis->hDC, extra == NULL ? Translate("<Empty>") : extra->getDescription(), -1, &rc,
+ DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE);
+
+
+ // Restore old colors
+ SetTextColor(lpdis->hDC, clrfore);
+ SetBkColor(lpdis->hDC, clrback);
+
+ return TRUE;
+ }
- numSlots = GetNumberOfSlots();
+ case WM_MEASUREITEM:
+ {
+ LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
+ if ((lpmis->CtlID % 2) != 0)
+ break;
+ int slot = (lpmis->CtlID - IDC_SLOT) / 2;
+ if (slot < 0 || slot > numSlots * 2)
+ break;
- RECT rcLabel;
- GetWindowRect(GetDlgItem(hwndDlg, IDC_SLOT_L), &rcLabel);
- ScreenToClient(hwndDlg, &rcLabel);
+ TEXTMETRIC tm;
+ GetTextMetrics(GetDC(hwndDlg), &tm);
- RECT rcCombo;
- GetWindowRect(GetDlgItem(hwndDlg, IDC_SLOT), &rcCombo);
- ScreenToClient(hwndDlg, &rcCombo);
+ lpmis->itemHeight = MAX(ICON_SIZE, tm.tmHeight);
- HFONT hFont = (HFONT) SendMessage(hwndDlg, WM_GETFONT, 0, 0);
+ return TRUE;
+ }
+ }
- int height = MAX(rcLabel.bottom - rcLabel.top, rcCombo.bottom - rcCombo.top) + 3;
+ return 0;
+ }
+ */
- for (int i = 0; i < numSlots; ++i)
- {
- int id = IDC_SLOT + i * 2;
+#ifndef TVIS_FOCUSED
+#define TVIS_FOCUSED 1
+#endif
+WNDPROC origTreeProc;
- // Create controls
- if (i > 0)
- {
- char desc[256];
- mir_snprintf(desc, MAX_REGS(desc), "Slot %d:", i + 1);
-
- HWND tmp = CreateWindow("STATIC", Translate(desc),
- WS_CHILD | WS_VISIBLE,
- rcLabel.left, rcLabel.top + i * height,
- rcLabel.right - rcLabel.left, rcLabel.bottom - rcLabel.top,
- hwndDlg, 0, hInst, NULL);
- SendMessage(tmp, WM_SETFONT, (WPARAM) hFont, FALSE);
-
- HWND combo = CreateWindow("COMBOBOX", "",
- WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | WS_VSCROLL
- | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS,
- rcCombo.left, rcCombo.top + i * height,
- rcCombo.right - rcCombo.left, rcCombo.bottom - rcCombo.top,
- hwndDlg, (HMENU) id, hInst, NULL);
- SendMessage(combo, WM_SETFONT, (WPARAM) hFont, FALSE);
- }
+static bool IsSelected(HWND tree, HTREEITEM hItem)
+{
+ return (TVIS_SELECTED & TreeView_GetItemState(tree, hItem, TVIS_SELECTED)) == TVIS_SELECTED;
+}
- // Fill combo
- int sel = 0;
- SendDlgItemMessage(hwndDlg, id, CB_ADDSTRING, 0, (LPARAM) Translate("<Empty>"));
- for (int j = 0; j < (int) extraIcons.size(); ++j)
- {
- ExtraIcon *extra = extraIcons[j];
+static void UnselectAllExcept(HWND tree, HTREEITEM hIgnore)
+{
+ HTREEITEM hItem = TreeView_GetRoot(tree);
+ while (hItem)
+ {
+ if (hItem != hIgnore)
+ if (IsSelected(tree, hItem))
+ TreeView_SetItemState(tree, hItem, 0, TVIS_SELECTED);
+ hItem = TreeView_GetNextVisible(tree, hItem);
+ }
+}
- int pos = SendDlgItemMessage(hwndDlg, id, CB_ADDSTRING, 0, (LPARAM) extra->getDescription());
- SendDlgItemMessage(hwndDlg, id, CB_SETITEMDATA, pos, (DWORD) extra);
+static int GetNumSelected(HWND tree)
+{
+ int ret = 0;
+ HTREEITEM hItem = TreeView_GetRoot(tree);
+ while (hItem)
+ {
+ if (IsSelected(tree, hItem))
+ ret++;
+ hItem = TreeView_GetNextVisible(tree, hItem);
+ }
+ return ret;
+}
- if (extra->getSlot() == i)
- sel = j + 1;
- }
- SendDlgItemMessage(hwndDlg, id, CB_SETCURSEL, sel, 0);
- }
+static void Select(HWND tree, HTREEITEM hItem)
+{
+ TreeView_SetItemState(tree, hItem, TVIS_FOCUSED | TVIS_SELECTED, TVIS_FOCUSED | TVIS_SELECTED);
+}
- break;
- }
- case WM_COMMAND:
+LRESULT CALLBACK TreeProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_LBUTTONDOWN:
{
- HWND cbl = (HWND) lParam;
- if (HIWORD(wParam) != CBN_SELCHANGE || cbl != GetFocus())
- return 0;
+ DWORD pos = (DWORD) lParam;
- int sel = SendMessage(cbl, CB_GETCURSEL, 0, 0);
- if (sel > 0)
+ TVHITTESTINFO hti;
+ hti.pt.x = (short) LOWORD(pos);
+ hti.pt.y = (short) HIWORD(pos);
+ if (!TreeView_HitTest(hwndDlg, &hti))
{
- for (int i = 0; i < numSlots; ++i)
- {
- int id = IDC_SLOT + i * 2;
-
- if (GetDlgItem(hwndDlg, id) == cbl)
- continue;
-
- int sl = SendDlgItemMessage(hwndDlg, id, CB_GETCURSEL, 0, 0);
- if (sl == sel)
- SendDlgItemMessage(hwndDlg, id, CB_SETCURSEL, 0, 0);
- }
+ UnselectAllExcept(hwndDlg, NULL);
+ break;
}
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
- }
- case WM_NOTIFY:
- {
- LPNMHDR lpnmhdr = (LPNMHDR) lParam;
-
- if (lpnmhdr->idFrom == 0 && lpnmhdr->code == (UINT) PSN_APPLY)
+ if (!(wParam & MK_CONTROL) || !(hti.flags & (TVHT_ONITEMICON | TVHT_ONITEMLABEL | TVHT_ONITEMRIGHT)))
{
- int * slots = new int[extraIcons.size()];
-
- int i;
- for (i = 0; i < (int) extraIcons.size(); ++i)
- slots[i] = -1;
-
- for (i = 0; i < (int) extraIcons.size(); ++i)
- {
- if (slots[i] != -1)
- continue;
-
- for (int j = 0; j < numSlots; ++j)
- {
- if (SendDlgItemMessage(hwndDlg, IDC_SLOT + j * 2, CB_GETCURSEL, 0, 0) == i + 1)
- {
- slots[i] = j;
- break;
- }
- }
- }
-
- for (int j = 0; j < numSlots; ++j)
- {
- // Has icon?
- bool found = false;
- for (i = 0; !found && i < (int) extraIcons.size(); ++i)
- found = (slots[i] == j);
- if (found)
- continue;
-
- // Had icon?
- if (GetExtraIconBySlot(j) == NULL)
- continue;
-
-
- // Had and icon and lost
- RemoveExtraIcons(j);
- }
-
- for (i = 0; i < (int) extraIcons.size(); ++i)
- {
- ExtraIcon *extra = extraIcons[i];
-
- int oldSlot = extra->getSlot();
- if (oldSlot == slots[i])
- continue;
-
- extra->setSlot(slots[i]);
-
- char setting[512];
- mir_snprintf(setting, MAX_REGS(setting), "Slot_%s", extra->getName());
- DBWriteContactSettingWord(NULL, MODULE_NAME, setting, extra->getSlot());
-
- if (oldSlot < 0 && extra->needToRebuildIcons())
- extra->rebuildIcons();
- extra->applyIcons();
- }
-
- delete[] slots;
- }
-
- break;
- }
- case WM_DRAWITEM:
- {
- LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;
- if ((lpdis->CtlID % 2) != 0)
- break;
- int slot = (lpdis->CtlID - IDC_SLOT) / 2;
- if (slot < 0 || slot > numSlots * 2)
+ UnselectAllExcept(hwndDlg, hti.hItem);
break;
- if (lpdis->itemID == (UINT) -1)
- break;
-
- ExtraIcon *extra = (ExtraIcon *) lpdis->itemData;
-
- TEXTMETRIC tm;
- RECT rc;
-
- GetTextMetrics(lpdis->hDC, &tm);
-
- COLORREF clrfore = SetTextColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED
- ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
- COLORREF clrback = SetBkColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT
- : COLOR_WINDOW));
-
- FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT
- : COLOR_WINDOW));
-
- rc.left = lpdis->rcItem.left + 2;
-
-
- // Draw icon
- HICON hIcon = NULL;
- if (extra != NULL && !IsEmpty(extra->getDescIcon()))
- hIcon = (HICON) CallService(MS_SKIN2_GETICON, 0, (LPARAM) extra->getDescIcon());
- if (hIcon != NULL)
- {
- rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - ICON_SIZE) / 2;
- DrawIconEx(lpdis->hDC, rc.left, rc.top, hIcon, 16, 16, 0, NULL, DI_NORMAL);
- CallService(MS_SKIN2_RELEASEICON, (WPARAM) hIcon, 0);
}
- rc.left += ICON_SIZE + 4;
-
-
- // Draw text
- rc.right = lpdis->rcItem.right - 2;
- rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - tm.tmHeight) / 2;
- rc.bottom = rc.top + tm.tmHeight;
- DrawText(lpdis->hDC, extra == NULL ? Translate("<Empty>") : extra->getDescription(), -1, &rc,
- DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE);
-
-
- // Restore old colors
- SetTextColor(lpdis->hDC, clrfore);
- SetBkColor(lpdis->hDC, clrback);
-
- return TRUE;
- }
-
- case WM_MEASUREITEM:
- {
- LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
- if ((lpmis->CtlID % 2) != 0)
- break;
- int slot = (lpmis->CtlID - IDC_SLOT) / 2;
- if (slot < 0 || slot > numSlots * 2)
- break;
-
- TEXTMETRIC tm;
- GetTextMetrics(GetDC(hwndDlg), &tm);
-
- lpmis->itemHeight = MAX(ICON_SIZE, tm.tmHeight);
-
- return TRUE;
+ HTREEITEM hItem = TreeView_GetSelection(hwndDlg);
+ TreeView_SelectItem(hwndDlg, hti.hItem);
+ if (hItem != NULL)
+ Select(hwndDlg, hItem);
+ return 0;
}
}
- return 0;
+ return CallWindowProc(origTreeProc, hwndDlg, msg, wParam, lParam);
}
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
@@ -358,6 +433,17 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
{
TranslateDialogDefault(hwndDlg);
+ int numSlots = GetNumberOfSlots();
+ if (numSlots < (int) registeredExtraIcons.size())
+ {
+ char txt[512];
+ mir_snprintf(txt, MAX_REGS(txt), Translate("* only the first %d icons will be shown"), numSlots);
+
+ HWND label = GetDlgItem(hwndDlg, IDC_MAX_ICONS_L);
+ SetWindowText(label, txt);
+ ShowWindow(label, SW_SHOW);
+ }
+
HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_NOHSCROLL);
@@ -365,9 +451,9 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
HIMAGELIST hImageList = ImageList_Create(cx, cx, ILC_COLOR32 | ILC_MASK, 2, 2);
unsigned int i;
- for (i = 0; i < extraIcons.size(); ++i)
+ for (i = 0; i < registeredExtraIcons.size(); ++i)
{
- ExtraIcon *extra = extraIcons[i];
+ ExtraIcon *extra = registeredExtraIcons[i];
HICON hIcon = NULL;
if (!IsEmpty(extra->getDescIcon()))
@@ -393,9 +479,9 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
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)
+ for (i = 0; i < registeredExtraIcons.size(); ++i)
{
- ExtraIcon *extra = extraIcons[i];
+ ExtraIcon *extra = registeredExtraIcons[i];
tvis.item.lParam = (LPARAM) extra;
tvis.item.pszText = (char *) extra->getDescription();
@@ -410,6 +496,8 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
sort.lpfnCompare = CompareFunc;
TreeView_SortChildrenCB(tree, &sort, 0);
+ origTreeProc = (WNDPROC) SetWindowLong(tree, GWL_WNDPROC, (LONG) TreeProc);
+
return TRUE;
}
case WM_COMMAND:
@@ -424,10 +512,10 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
{
if (lpnmhdr->code == (UINT) PSN_APPLY)
{
- int *slots = new int[extraIcons.size()];
+ int *slots = new int[registeredExtraIcons.size()];
unsigned int i;
- for (i = 0; i < extraIcons.size(); ++i)
+ for (i = 0; i < registeredExtraIcons.size(); ++i)
slots[i] = -1;
HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER);
@@ -463,9 +551,9 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
}
// Apply icons to new slots
- for (i = 0; i < extraIcons.size(); ++i)
+ for (i = 0; i < registeredExtraIcons.size(); ++i)
{
- ExtraIcon *extra = extraIcons[i];
+ ExtraIcon *extra = registeredExtraIcons[i];
char setting[512];
mir_snprintf(setting, MAX_REGS(setting), "Position_%s", extra->getName());
@@ -483,8 +571,6 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
if (slots[i] < 0)
continue;
- if (oldSlot < 0 && extra->needToRebuildIcons())
- extra->rebuildIcons();
extra->applyIcons();
}
@@ -523,7 +609,6 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0);
}
}
-
break;
}
case TVN_KEYDOWN:
@@ -541,8 +626,41 @@ static BOOL CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
case NM_RCLICK:
{
HTREEITEM hSelected = (HTREEITEM) SendMessage(tree, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0);
- if (hSelected != NULL)
- TreeView_SelectItem(tree, hSelected);
+ if (hSelected != NULL && !IsSelected(tree, hSelected))
+ {
+// if (GetKeyState(VK_CONTROL) & 0xFF00)
+// {
+// HTREEITEM hItem = TreeView_GetSelection(tree);
+// TreeView_SelectItem(tree, hSelected);
+// Select(tree, hItem);
+// }
+// else
+// {
+ UnselectAllExcept(tree, hSelected);
+ TreeView_SelectItem(tree, hSelected);
+// }
+ }
+ if (GetNumSelected(tree) > 1)
+ {
+ HMENU menu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_OPT_POPUP));
+ HMENU submenu = GetSubMenu(menu, 0);
+ CallService(MS_LANGPACK_TRANSLATEMENU, (WPARAM) submenu, 0);
+
+ DWORD pos = GetMessagePos();
+ int ret = TrackPopupMenu(submenu, TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD
+ | TPM_LEFTALIGN, LOWORD(pos), HIWORD(pos), 0, hwndDlg, NULL);
+
+ DestroyMenu(menu);
+
+ switch (ret)
+ {
+ case ID_GROUP:
+ {
+ OutputDebugString("GROUP\n");
+ break;
+ }
+ }
+ }
break;
}
}
diff --git a/Plugins/extraicons/resource.h b/Plugins/extraicons/resource.h
index 9f905a3..34c5263 100644
--- a/Plugins/extraicons/resource.h
+++ b/Plugins/extraicons/resource.h
@@ -10,9 +10,12 @@
#define IDI_MALE 123
#define IDI_FEMALE 124
#define IDI_EMPTY 125
+#define IDR_OPT_POPUP 126
#define IDC_SLOT_L 1075
#define IDC_SLOT 1076
+#define IDC_MAX_ICONS_L 1077
#define IDC_EXTRAORDER 1889
+#define ID_GROUP 40006
#define IDC_STATIC -1
// Next default values for new objects
@@ -21,9 +24,9 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_3D_CONTROLS 1
-#define _APS_NEXT_RESOURCE_VALUE 126
-#define _APS_NEXT_COMMAND_VALUE 40005
-#define _APS_NEXT_CONTROL_VALUE 1077
+#define _APS_NEXT_RESOURCE_VALUE 127
+#define _APS_NEXT_COMMAND_VALUE 40007
+#define _APS_NEXT_CONTROL_VALUE 1078
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/Plugins/extraicons/resource.rc b/Plugins/extraicons/resource.rc
index e2d07c4..c64372e 100644
--- a/Plugins/extraicons/resource.rc
+++ b/Plugins/extraicons/resource.rc
@@ -43,15 +43,15 @@ 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
+FONT 8, "MS Shell Dlg"
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
+ LTEXT "* only the first %d icons will be shown",
+ IDC_MAX_ICONS_L,1,190,274,13,NOT WS_VISIBLE
END
@@ -95,6 +95,20 @@ 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"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDR_OPT_POPUP MENU DISCARDABLE
+BEGIN
+ POPUP "Group"
+ BEGIN
+ MENUITEM "Group", ID_GROUP
+ END
+END
+
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////