summaryrefslogtreecommitdiff
path: root/tipper/tipper.cpp
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2006-11-01 14:46:09 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2006-11-01 14:46:09 +0000
commita13e82647294da4add976a24335fec50d7bfe905 (patch)
tree087acc8d5085391fe71cde7299269c4d0f583c30 /tipper/tipper.cpp
parentbded3f3d452e097995cbb1e695aaec13a739d1af (diff)
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@15 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'tipper/tipper.cpp')
-rw-r--r--tipper/tipper.cpp295
1 files changed, 295 insertions, 0 deletions
diff --git a/tipper/tipper.cpp b/tipper/tipper.cpp
new file mode 100644
index 0000000..cd8085b
--- /dev/null
+++ b/tipper/tipper.cpp
@@ -0,0 +1,295 @@
+// popups2.cpp : Defines the entry point for the DLL application.
+//
+
+#include "common.h"
+#include "tipper.h"
+#include "version.h"
+#include "message_pump.h"
+#include "options.h"
+#include "popwin.h"
+
+HMODULE hInst = 0;
+HANDLE mainThread = 0;
+
+int code_page = CP_ACP;
+
+
+FontIDW font_id_title = {0}, font_id_labels = {0}, font_id_values = {0};
+ColourIDW colour_id_bg = {0}, colour_id_border = {0}, colour_id_divider = {0}, colour_id_sidebar = {0};
+HFONT hFontTitle = 0, hFontLabels = 0, hFontValues = 0;
+
+// hooked here so it's in the main thread
+HANDLE hAvChangeEvent = 0, hShowTipEvent = 0, hHideTipEvent = 0, hAckEvent = 0, hFramesSBShow = 0, hFramesSBHide;
+
+HANDLE hShowTipService = 0, hShowTipWService = 0, hHideTipService = 0;
+
+struct MM_INTERFACE memoryManagerInterface = {0};
+
+PLUGININFO pluginInfo={
+ sizeof(PLUGININFO),
+ __PLUGIN_NAME,
+ PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
+ __DESC,
+ __AUTHOR,
+ __AUTHOREMAIL,
+ __COPYRIGHT,
+ __AUTHORWEB,
+ 0, //not transient
+ 0 //doesn't replace anything built-in
+};
+
+PLUGINLINK *pluginLink = 0;
+
+extern "C" BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
+{
+ hInst = hModule;
+ DisableThreadLibraryCalls(hInst);
+ return TRUE;
+}
+
+extern "C" __declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+int ReloadFont(WPARAM wParam, LPARAM lParam) {
+ LOGFONT log_font;
+
+ if(hFontTitle) DeleteObject(hFontTitle);
+ options.title_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_title, (LPARAM)&log_font);
+ hFontTitle = CreateFontIndirect(&log_font);
+ if(hFontLabels) DeleteObject(hFontLabels);
+ options.label_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_labels, (LPARAM)&log_font);
+ hFontLabels = CreateFontIndirect(&log_font);
+ if(hFontValues) DeleteObject(hFontValues);
+ options.value_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_values, (LPARAM)&log_font);
+ hFontValues = CreateFontIndirect(&log_font);
+
+ options.bg_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_bg, 0);
+ options.border_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_border, 0);
+ options.sidebar_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_sidebar, 0);
+ options.div_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_divider, 0);
+
+ return 0;
+}
+
+int ModulesLoaded(WPARAM wParam, LPARAM lParam) {
+ if(ServiceExists(MS_UPDATE_REGISTER)) {
+ // register with updater
+ Update update = {0};
+ char szVersion[16];
+
+ update.cbSize = sizeof(Update);
+
+ update.szComponentName = pluginInfo.shortName;
+ update.pbVersion = (BYTE *)CreateVersionString(pluginInfo.version, szVersion);
+ update.cpbVersion = strlen((char *)update.pbVersion);
+
+ update.szUpdateURL = UPDATER_AUTOREGISTER;
+
+ // these are the three lines that matter - the archive, the page containing the version string, and the text (or data)
+ // before the version that we use to locate it on the page
+ // (note that if the update URL and the version URL point to standard file listing entries, the backend xml
+ // data will be used to check for updates rather than the actual web page - this is not true for beta urls)
+ update.szBetaUpdateURL = "http://www.scottellis.com.au/miranda_plugins/tipper.zip";
+ update.szBetaVersionURL = "http://www.scottellis.com.au/miranda_plugins/ver_tipper.html";
+ update.pbBetaVersionPrefix = (BYTE *)"Tipper version ";
+
+ update.cpbBetaVersionPrefix = strlen((char *)update.pbBetaVersionPrefix);
+
+ CallService(MS_UPDATE_REGISTER, 0, (WPARAM)&update);
+ }
+
+ if(ServiceExists(MS_FONT_REGISTERW)) {
+ font_id_title.cbSize = sizeof(FontIDW);
+ font_id_title.flags = FIDF_ALLOWEFFECTS;
+ wcscpy(font_id_title.group, TranslateT("Tooltips"));
+ wcscpy(font_id_title.name, TranslateT("Title"));
+ strcpy(font_id_title.dbSettingsGroup, MODULE);
+ strcpy(font_id_title.prefix, "FontFirst");
+ font_id_title.order = 0;
+
+ font_id_title.deffontsettings.charset = DEFAULT_CHARSET;
+ font_id_title.deffontsettings.size = -14;
+ font_id_title.deffontsettings.style = DBFONTF_BOLD;
+ font_id_title.deffontsettings.colour = RGB(255, 0, 0);
+ font_id_title.flags |= FIDF_DEFAULTVALID;
+
+ font_id_labels.cbSize = sizeof(FontIDW);
+ font_id_labels.flags = FIDF_ALLOWEFFECTS;
+ wcscpy(font_id_labels.group, TranslateT("Tooltips"));
+ wcscpy(font_id_labels.name, TranslateT("Labels"));
+ strcpy(font_id_labels.dbSettingsGroup, MODULE);
+ strcpy(font_id_labels.prefix, "FontLabels");
+ font_id_labels.order = 1;
+
+ font_id_labels.deffontsettings.charset = DEFAULT_CHARSET;
+ font_id_labels.deffontsettings.size = -12;
+ font_id_labels.deffontsettings.style = DBFONTF_ITALIC;
+ font_id_labels.deffontsettings.colour = RGB(128, 128, 128);
+ font_id_labels.flags |= FIDF_DEFAULTVALID;
+
+ font_id_values.cbSize = sizeof(FontIDW);
+ font_id_values.flags = FIDF_ALLOWEFFECTS;
+ wcscpy(font_id_values.group, TranslateT("Tooltips"));
+ wcscpy(font_id_values.name, TranslateT("Values"));
+ strcpy(font_id_values.dbSettingsGroup, MODULE);
+ strcpy(font_id_values.prefix, "FontValues");
+ font_id_values.order = 2;
+
+ font_id_values.deffontsettings.charset = DEFAULT_CHARSET;
+ font_id_values.deffontsettings.size = -12;
+ font_id_values.deffontsettings.style = 0;
+ font_id_values.deffontsettings.colour = RGB(0, 0, 0);
+ font_id_values.flags |= FIDF_DEFAULTVALID;
+
+ CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_title, 0);
+ CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_labels, 0);
+ CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_values, 0);
+
+ colour_id_bg.cbSize = sizeof(ColourIDW);
+ wcscpy(colour_id_bg.group, TranslateT("Tooltips"));
+ wcscpy(colour_id_bg.name, TranslateT("Background"));
+ strcpy(colour_id_bg.dbSettingsGroup, MODULE);
+ strcpy(colour_id_bg.setting, "ColourBg");
+ colour_id_bg.defcolour = RGB(219, 219, 219);
+ colour_id_bg.order = 0;
+
+ colour_id_border.cbSize = sizeof(ColourIDW);
+ wcscpy(colour_id_border.group, TranslateT("Tooltips"));
+ wcscpy(colour_id_border.name, TranslateT("Border"));
+ strcpy(colour_id_border.dbSettingsGroup, MODULE);
+ strcpy(colour_id_border.setting, "BorderCol");
+ colour_id_border.defcolour = 0;
+ colour_id_border.order = 0;
+
+ colour_id_divider.cbSize = sizeof(ColourIDW);
+ wcscpy(colour_id_divider.group, TranslateT("Tooltips"));
+ wcscpy(colour_id_divider.name, TranslateT("Dividers"));
+ strcpy(colour_id_divider.dbSettingsGroup, MODULE);
+ strcpy(colour_id_divider.setting, "DividerCol");
+ colour_id_divider.defcolour = 0;
+ colour_id_divider.order = 0;
+
+ colour_id_sidebar.cbSize = sizeof(ColourIDW);
+ wcscpy(colour_id_sidebar.group, TranslateT("Tooltips"));
+ wcscpy(colour_id_sidebar.name, TranslateT("Sidebar"));
+ strcpy(colour_id_sidebar.dbSettingsGroup, MODULE);
+ strcpy(colour_id_sidebar.setting, "SidebarCol");
+ colour_id_sidebar.defcolour = RGB(192, 192, 192);
+ colour_id_sidebar.order = 0;
+
+ CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_bg, 0);
+ CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_border, 0);
+ CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_divider, 0);
+ CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_sidebar, 0);
+
+ ReloadFont(0, 0);
+
+ HookEvent(ME_FONT_RELOAD, ReloadFont);
+ } else {
+ options.title_col = RGB(255, 0, 0); options.label_col = RGB(128, 128, 128), options.value_col = 0;
+ options.bg_col = RGB(219, 219, 219);
+ options.border_col = options.div_col = 0;
+ options.sidebar_col = RGB(192, 192, 192);
+
+ LOGFONT lf = {0};
+ lf.lfCharSet = DEFAULT_CHARSET;
+ lf.lfHeight = -14;
+ lf.lfWeight = FW_BOLD;
+ hFontTitle = CreateFontIndirect(&lf);
+
+ lf.lfHeight = -12;
+ lf.lfWeight = 0;
+ lf.lfItalic = TRUE;
+ hFontLabels = CreateFontIndirect(&lf);
+
+ lf.lfHeight = -12;
+ lf.lfWeight = 0;
+ lf.lfItalic = FALSE;
+ hFontValues = CreateFontIndirect(&lf);
+ }
+
+ hAvChangeEvent = HookEvent(ME_AV_AVATARCHANGED, AvatarChanged);
+ hShowTipEvent = HookEvent(ME_CLC_SHOWINFOTIP, ShowTip);
+ hHideTipEvent = HookEvent(ME_CLC_HIDEINFOTIP, HideTip);
+ hAckEvent = HookEvent(ME_PROTO_ACK, ProtoAck);
+
+ hFramesSBShow = HookEvent(ME_CLIST_FRAMES_SB_SHOW_TOOLTIP, FramesShowSBTip);
+ hFramesSBHide = HookEvent(ME_CLIST_FRAMES_SB_HIDE_TOOLTIP, FramesHideSBTip);
+
+ LoadOptions();
+
+ // set 'time-in'
+ CallService(MS_CLC_SETINFOTIPHOVERTIME, options.time_in, 0);
+
+ return 0;
+}
+
+int Shutdown(WPARAM wParam, LPARAM lParam) {
+ if(hFramesSBShow) UnhookEvent(hFramesSBShow);
+ if(hFramesSBHide) UnhookEvent(hFramesSBHide);
+ if(hAvChangeEvent) UnhookEvent(hAvChangeEvent);
+ if(hShowTipEvent) UnhookEvent(hShowTipEvent);
+ if(hHideTipEvent) UnhookEvent(hHideTipEvent);
+ if(hAckEvent) UnhookEvent(hAckEvent);
+
+ if(hShowTipService) DestroyServiceFunction(hShowTipService);
+ if(hShowTipWService) DestroyServiceFunction(hShowTipWService);
+ if(hHideTipService) DestroyServiceFunction(hHideTipService);
+
+ DeinitMessagePump();
+
+ return 0;
+}
+
+HANDLE hEventPreShutdown, hEventModulesLoaded;
+
+extern "C" int TIPPER_API Load(PLUGINLINK *link) {
+ pluginLink = link;
+ DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0);
+
+ // get the internal malloc/free()
+ memoryManagerInterface.cbSize = sizeof(memoryManagerInterface);
+ CallService(MS_SYSTEM_GET_MMI, 0, (LPARAM)&memoryManagerInterface);
+
+ // don't save status messages
+ CallService(MS_DB_SETSETTINGRESIDENT, (WPARAM)TRUE, (LPARAM)MODULE "/TempStatusMsg");
+
+ // Ensure that the common control DLL is loaded (for listview)
+ INITCOMMONCONTROLSEX icex;
+ icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ icex.dwICC = ICC_LISTVIEW_CLASSES;
+ InitCommonControlsEx(&icex);
+
+ if(ServiceExists(MS_LANGPACK_GETCODEPAGE))
+ code_page = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
+
+ InitTranslations();
+ InitMessagePump();
+ InitOptions();
+
+ // for compatibility with mToolTip status tooltips
+ hShowTipService = CreateServiceFunction("mToolTip/ShowTip", ShowTip);
+ hShowTipWService = CreateServiceFunction("mToolTip/ShowTipW", ShowTipW);
+ hHideTipService = CreateServiceFunction("mToolTip/HideTip", HideTip);
+
+ hEventPreShutdown = HookEvent(ME_SYSTEM_PRESHUTDOWN, Shutdown);
+ hEventModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
+
+ return 0;
+}
+
+extern "C" int TIPPER_API Unload() {
+ UnhookEvent(hEventPreShutdown);
+ UnhookEvent(hEventModulesLoaded);
+
+ DeinitOptions();
+ if(ServiceExists(MS_FONT_REGISTERW)) {
+ DeleteObject(hFontTitle);
+ DeleteObject(hFontLabels);
+ DeleteObject(hFontValues);
+ } // otherwise, no need to delete the handle
+ DeinitTranslations();
+ return 0;
+}