summaryrefslogtreecommitdiff
path: root/plugins/Popup
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-06-13 15:09:41 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-06-13 15:09:41 +0300
commit346ae348ae7ee5a594c9fcd17114ae949c1ce201 (patch)
tree1e42c52d59515646d603a9593ce23d094a5fde20 /plugins/Popup
parent7524e8b875b924bb3cee484e90f6cc6bc01515a4 (diff)
Popup+: fix for a madness with default popup class values
Diffstat (limited to 'plugins/Popup')
-rw-r--r--plugins/Popup/src/font.cpp36
-rw-r--r--plugins/Popup/src/font.h2
-rw-r--r--plugins/Popup/src/main.cpp11
-rw-r--r--plugins/Popup/src/notifications.cpp2
-rw-r--r--plugins/Popup/src/notifications.h8
-rw-r--r--plugins/Popup/src/opt_class.cpp4
-rw-r--r--plugins/Popup/src/services.cpp62
-rw-r--r--plugins/Popup/src/version.h4
8 files changed, 60 insertions, 69 deletions
diff --git a/plugins/Popup/src/font.cpp b/plugins/Popup/src/font.cpp
index 349dccd1e2..3346cf046c 100644
--- a/plugins/Popup/src/font.cpp
+++ b/plugins/Popup/src/font.cpp
@@ -81,43 +81,41 @@ void InitFonts()
ReloadFonts();
}
+///////////////////////////////////////////////////////////////////////////////
-void ReloadFonts()
+static void ReplaceFont(HFONT &hFont, LOGFONTW &lf)
{
- if (fonts.title) DeleteObject(fonts.title);
- if (fonts.clock) DeleteObject(fonts.clock);
- if (fonts.text) DeleteObject(fonts.text);
- if (fonts.action) DeleteObject(fonts.action);
- if (fonts.actionHover) DeleteObject(fonts.actionHover);
+ if (hFont)
+ DeleteObject(hFont);
+ hFont = CreateFontIndirectW(&lf);
+}
- LOGFONT lf = { 0 };
+void CALLBACK ReloadFonts()
+{
+ LOGFONT lf;
fonts.clTitle = Font_GetW(_A2W(PU_FNT_AND_COLOR), _A2W(PU_FNT_NAME_TITLE), &lf);
- fonts.title = CreateFontIndirect(&lf);
+ ReplaceFont(fonts.title, lf);
fonts.clClock = Font_GetW(_A2W(PU_FNT_AND_COLOR), _A2W(PU_FNT_NAME_CLOCK), &lf);
- fonts.clock = CreateFontIndirect(&lf);
+ ReplaceFont(fonts.clock, lf);
fonts.clText = Font_GetW(_A2W(PU_FNT_AND_COLOR), _A2W(PU_FNT_NAME_TEXT), &lf);
- fonts.text = CreateFontIndirect(&lf);
+ ReplaceFont(fonts.text, lf);
fonts.clAction = Font_GetW(_A2W(PU_FNT_AND_COLOR), _A2W(PU_FNT_NAME_ACTION), &lf);
- fonts.action = CreateFontIndirect(&lf);
+ ReplaceFont(fonts.action, lf);
fonts.clActionHover = Font_GetW(_A2W(PU_FNT_AND_COLOR), _A2W(PU_FNT_NAME_HOVERED_ACTION), &lf);
- fonts.actionHover = CreateFontIndirect(&lf);
+ ReplaceFont(fonts.actionHover, lf);
fonts.clBack = Colour_GetW(_A2W(PU_FNT_AND_COLOR), PU_COL_BACK_NAME);
fonts.clAvatarBorder = Colour_GetW(_A2W(PU_FNT_AND_COLOR), PU_COL_AVAT_NAME);
- // update class popups (only temp at this point, must rework)
- char setting[256];
+ // update class popups
for (auto &it : gTreeData) {
if (it->typ == 2) {
- mir_snprintf(setting, "%s/TextCol", it->pupClass.pszName);
- it->colorText = it->pupClass.colorText = (COLORREF)db_get_dw(0, PU_MODULCLASS, setting, (uint32_t)fonts.clText);
-
- mir_snprintf(setting, "%s/BgCol", it->pupClass.pszName);
- it->colorBack = it->pupClass.colorBack = (COLORREF)db_get_dw(0, PU_MODULCLASS, setting, (uint32_t)fonts.clBack/*pc->colorBack*/);
+ it->pupClass.colorText = Font_GetW(it->fid, &lf);
+ it->pupClass.colorBack = Colour_GetW(it->cid);
}
}
}
diff --git a/plugins/Popup/src/font.h b/plugins/Popup/src/font.h
index 6b2b473499..19b9c3a559 100644
--- a/plugins/Popup/src/font.h
+++ b/plugins/Popup/src/font.h
@@ -69,7 +69,7 @@ extern PopupFonts fonts;
void InitFonts();
-void ReloadFonts();
+void CALLBACK ReloadFonts();
#endif // __font_h__
diff --git a/plugins/Popup/src/main.cpp b/plugins/Popup/src/main.cpp
index 879018c8a1..affb110364 100644
--- a/plugins/Popup/src/main.cpp
+++ b/plugins/Popup/src/main.cpp
@@ -233,10 +233,6 @@ static int ModulesLoaded(WPARAM, LPARAM)
if (ServiceExists("PluginSweeper/Add"))
CallService("PluginSweeper/Add", (WPARAM)Translate(MODULENAME), (LPARAM)MODULENAME);
- // load fonts / create hook
- InitFonts();
- HookEvent(ME_FONT_RELOAD, FontsChanged);
-
// load actions and notifications
LoadActions();
LoadNotifications();
@@ -377,12 +373,17 @@ int CMPlugin::Load()
CreateServiceFunction("Popup/LoadSkin", Popup_LoadSkin);
+ // load fonts / create hook
+ InitFonts();
+ HookEvent(ME_FONT_RELOAD, FontsChanged);
+ Miranda_WaitOnHandle(ReloadFonts);
+
// load icons / create hook
InitIcons();
HookEvent(ME_SKIN_ICONSCHANGED, IconsChanged);
+
// add menu items
InitMenuItems();
-
return 0;
}
diff --git a/plugins/Popup/src/notifications.cpp b/plugins/Popup/src/notifications.cpp
index 96158a2890..6884a735d9 100644
--- a/plugins/Popup/src/notifications.cpp
+++ b/plugins/Popup/src/notifications.cpp
@@ -25,8 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
HANDLE g_hntfError, g_hntfWarning, g_hntfNotification;
-#define PopupNotificationData_SIGNATURE 0x11BEDA1A
-
int TreeDataSortFunc(const POPUPTREEDATA *p1, const POPUPTREEDATA *p2)
{
if (int cmp = mir_wstrcmp(p1->pszTreeRoot, p2->pszTreeRoot))
diff --git a/plugins/Popup/src/notifications.h b/plugins/Popup/src/notifications.h
index b9a6baa709..4512a47002 100644
--- a/plugins/Popup/src/notifications.h
+++ b/plugins/Popup/src/notifications.h
@@ -24,9 +24,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __notifications_h__
#define __notifications_h__
+#define PopupNotificationData_SIGNATURE 0x11BEDA1A
+
struct POPUPTREEDATA
{
- int cbSize;
uint32_t signature;
LPTSTR pszTreeRoot;
LPTSTR pszDescription;
@@ -41,8 +42,9 @@ struct POPUPTREEDATA
char leftAction[MAXMODULELABELLENGTH];
char rightAction[MAXMODULELABELLENGTH];
HANDLE hIcoLib;
- COLORREF colorBack; //really needed ??
- COLORREF colorText; //really needed ??
+
+ FontIDW fid;
+ ColourIDW cid;
};
extern LIST<POPUPTREEDATA> gTreeData;
diff --git a/plugins/Popup/src/opt_class.cpp b/plugins/Popup/src/opt_class.cpp
index d6d28f42d8..b63768da97 100644
--- a/plugins/Popup/src/opt_class.cpp
+++ b/plugins/Popup/src/opt_class.cpp
@@ -333,8 +333,8 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
ppd.szTitle.w = ptd->pszDescription;
ppd.szText.w = TranslateT("Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!");
ppd.iSeconds = ptd->timeoutValue;
- ppd.colorBack = ptd->colorBack;
- ppd.colorText = ptd->colorText;
+ ppd.colorBack = ptd->pupClass.colorBack;
+ ppd.colorText = ptd->pupClass.colorText;
POPUPTREEDATA *ptdPrev = nullptr;
if (ptd->typ == 1) {
// we work with a copy for preview
diff --git a/plugins/Popup/src/services.cpp b/plugins/Popup/src/services.cpp
index eb8107d2fe..527e9c0c64 100644
--- a/plugins/Popup/src/services.cpp
+++ b/plugins/Popup/src/services.cpp
@@ -285,7 +285,7 @@ INT_PTR Popup_RegisterActions(WPARAM wParam, LPARAM lParam)
INT_PTR Popup_RegisterNotification(WPARAM wParam, LPARAM)
{
- return (INT_PTR)RegisterNotification((LPPOPUPNOTIFICATION)wParam);
+ return (INT_PTR)RegisterNotification((POPUPNOTIFICATION*)wParam);
}
@@ -324,13 +324,15 @@ INT_PTR Popup_RegisterVfx(WPARAM, LPARAM lParam)
//===== Popup/RegisterClass (for core class api support)
INT_PTR Popup_RegisterPopupClass(WPARAM, LPARAM lParam)
{
- char setting[256];
POPUPCLASS *pc = (POPUPCLASS *)lParam;
POPUPTREEDATA *ptd = (POPUPTREEDATA *)mir_calloc(sizeof(POPUPTREEDATA));
- ptd->cbSize = sizeof(POPUPTREEDATA);
- ptd->signature = 0/*PopupNotificationData_SIGNATURE*/;
+ ptd->signature = PopupNotificationData_SIGNATURE;
ptd->typ = 2;
memcpy(&ptd->pupClass, pc, sizeof(POPUPCLASS));
+ if (pc->colorText == 0) // default text color
+ ptd->pupClass.colorText = fonts.clText;
+ if (pc->colorBack == 0) // default back color
+ ptd->pupClass.colorBack = fonts.clBack;
ptd->pszTreeRoot = mir_a2u(pc->pszName);
ptd->pupClass.pszName = mir_strdup(pc->pszName);
if (pc->flags & PCF_UNICODE) {
@@ -343,35 +345,25 @@ INT_PTR Popup_RegisterPopupClass(WPARAM, LPARAM lParam)
}
LoadClassSettings(ptd, PU_MODULCLASS);
- // we ignore pc->colorText and use fonts.text as default (if no setting found in DB)
- mir_snprintf(setting, "%s/TextCol", ptd->pupClass.pszName);
- ptd->pupClass.colorText = (COLORREF)db_get_dw(0, PU_MODULCLASS, setting, fonts.clText/*pc->colorText*/);
-
- FontIDW fid = {};
- mir_snwprintf(fid.group, L"%S/%s", PU_FNT_AND_COLOR, ptd->pszDescription);
- strncpy_s(fid.dbSettingsGroup, PU_MODULCLASS, _TRUNCATE);
- fid.flags = FIDF_DEFAULTVALID;
- fid.deffontsettings.charset = DEFAULT_CHARSET;
- fid.deffontsettings.size = -11;
- wcsncpy_s(fid.deffontsettings.szFace, L"Verdana", _TRUNCATE);
- wcsncpy_s(fid.name, _A2W(PU_FNT_NAME_TEXT), _TRUNCATE);
- strncpy_s(fid.setting, setting, _TRUNCATE);
- mir_snprintf(fid.setting, "%s/Text", ptd->pupClass.pszName); // result is "%s/TextCol"
- fid.deffontsettings.style = 0;
- fid.deffontsettings.colour = fonts.clText;
- g_plugin.addFont(&fid);
-
- // we ignore pc->colorBack and use fonts.clBack as default (if no setting found in DB)
- mir_snprintf(setting, "%s/BgCol", ptd->pupClass.pszName);
- ptd->pupClass.colorBack = (COLORREF)db_get_dw(0, PU_MODULCLASS, setting, (uint32_t)fonts.clBack/*pc->colorBack*/);
-
- ColourIDW cid = {};
- mir_snwprintf(cid.group, L"%S/%s", PU_FNT_AND_COLOR, ptd->pszDescription);
- wcsncpy_s(cid.name, PU_COL_BACK_NAME, _TRUNCATE);
- strncpy_s(cid.dbSettingsGroup, PU_MODULCLASS, _TRUNCATE);
- mir_snprintf(cid.setting, "%s/BgCol", ptd->pupClass.pszName);
- cid.defcolour = fonts.clBack;
- g_plugin.addColor(&cid);
+ // text & back colors
+ mir_snwprintf(ptd->fid.group, L"%S/%s", PU_FNT_AND_COLOR, ptd->pszDescription);
+ strncpy_s(ptd->fid.dbSettingsGroup, PU_MODULCLASS, _TRUNCATE);
+ ptd->fid.flags = FIDF_DEFAULTVALID;
+ ptd->fid.deffontsettings.charset = DEFAULT_CHARSET;
+ ptd->fid.deffontsettings.size = -11;
+ wcsncpy_s(ptd->fid.deffontsettings.szFace, L"Verdana", _TRUNCATE);
+ wcsncpy_s(ptd->fid.name, _A2W(PU_FNT_NAME_TEXT), _TRUNCATE);
+ mir_snprintf(ptd->fid.setting, "%s/TextCol", ptd->pupClass.pszName); // result is "%s/TextCol"
+ ptd->fid.deffontsettings.style = 0;
+ ptd->fid.deffontsettings.colour = ptd->pupClass.colorText;
+ g_plugin.addFont(&ptd->fid);
+
+ mir_snwprintf(ptd->cid.group, L"%S/%s", PU_FNT_AND_COLOR, ptd->pszDescription);
+ wcsncpy_s(ptd->cid.name, PU_COL_BACK_NAME, _TRUNCATE);
+ strncpy_s(ptd->cid.dbSettingsGroup, PU_MODULCLASS, _TRUNCATE);
+ mir_snprintf(ptd->cid.setting, "%s/BgCol", ptd->pupClass.pszName);
+ ptd->cid.defcolour = ptd->pupClass.colorBack;
+ g_plugin.addColor(&ptd->cid);
gTreeData.insert(ptd);
num_classes++;
@@ -398,7 +390,7 @@ INT_PTR Popup_UnregisterPopupClass(WPARAM, LPARAM lParam)
INT_PTR Popup_CreateClassPopup(WPARAM wParam, LPARAM lParam)
{
POPUPDATACLASS *pdc = (POPUPDATACLASS *)lParam;
- if (!pdc || (pdc->cbSize != sizeof(POPUPDATACLASS)))
+ if (!pdc)
return 1;
POPUPCLASS *pc;
@@ -458,4 +450,4 @@ INT_PTR Popup_LoadSkin(WPARAM, LPARAM lParam)
}
return 1;
-} \ No newline at end of file
+}
diff --git a/plugins/Popup/src/version.h b/plugins/Popup/src/version.h
index 450918c248..f957f9ade0 100644
--- a/plugins/Popup/src/version.h
+++ b/plugins/Popup/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 2
#define __MINOR_VERSION 1
-#define __RELEASE_NUM 1
-#define __BUILD_NUM 17
+#define __RELEASE_NUM 2
+#define __BUILD_NUM 0
#include <stdver.h>