summaryrefslogtreecommitdiff
path: root/MySpace/srmm_icon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MySpace/srmm_icon.cpp')
-rw-r--r--MySpace/srmm_icon.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/MySpace/srmm_icon.cpp b/MySpace/srmm_icon.cpp
new file mode 100644
index 0000000..23251e0
--- /dev/null
+++ b/MySpace/srmm_icon.cpp
@@ -0,0 +1,78 @@
+#include "common.h"
+#include "srmm_icon.h"
+#include "resource.h"
+#include "notifications.h"
+#include "server_con.h"
+
+#include <ctime>
+
+int WindowEvent(WPARAM wParam, LPARAM lParam) {
+ MessageWindowEventData *wd = (MessageWindowEventData *)lParam;
+ if(wd->uType != MSG_WINDOW_EVT_OPEN) return 0;
+
+ HANDLE hContact = wd->hContact, hTemp;
+ if(ServiceExists(MS_MC_GETMOSTONLINECONTACT) && (hTemp = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0)
+ hContact = hTemp;
+
+ bool hide = false;
+ if(!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULE))
+ hide = true;
+
+ StatusIconData sid = {0};
+ sid.cbSize = sizeof(sid);
+ sid.szModule = MODULE;
+ sid.flags = (hide ? MBF_HIDDEN : 0);
+ CallService(MS_MSG_MODIFYICON, (WPARAM)wd->hContact, (LPARAM)&sid);
+
+ return 0;
+}
+
+int IconPressed(WPARAM wParam, LPARAM lParam) {
+ StatusIconClickData *cd = (StatusIconClickData *)lParam;
+ if(strcmp(cd->szModule, MODULE) != 0) return 0;
+
+ HANDLE hContact = (HANDLE)wParam, hTemp;
+ if(ServiceExists(MS_MC_GETMOSTONLINECONTACT) && (hTemp = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0)
+ hContact = hTemp;
+
+ if(!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULE))
+ return 0;
+
+ HMENU hMenu = CreatePopupMenu();
+ for(int i = 0; zap_array[i]; i++) {
+ AppendMenuA(hMenu,MF_STRING,i+1, Translate(zap_array[i]));
+ }
+ BOOL cmd = TrackPopupMenu(hMenu, TPM_NONOTIFY | TPM_RETURNCMD, cd->clickLocation.x, cd->clickLocation.y, 0, (HWND)CallService(MS_CLUI_GETHWND, 0, 0), 0);
+ DestroyMenu(hMenu);
+
+ if(cmd) {
+ int zap_num = cmd - 1;
+ NotifyZapSend(hContact, zap_num);
+ }
+ return 0;
+}
+
+HICON hZapIcon = 0;
+HANDLE hEventIconPressed = 0, hEventWindow = 0;
+void InitSRMMIcon() {
+ // add icon to srmm status icons
+ if(ServiceExists(MS_MSG_ADDICON)) {
+ hZapIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ZAPS));
+ StatusIconData sid = {0};
+ sid.cbSize = sizeof(sid);
+ sid.szModule = MODULE;
+ sid.hIcon = hZapIcon;
+ sid.szTooltip = Translate("Send ZAP");
+ CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid);
+
+ // hook the window events so that we can can change the status of the icon
+ hEventWindow = HookEvent(ME_MSG_WINDOWEVENT, WindowEvent);
+ hEventIconPressed = HookEvent(ME_MSG_ICONPRESSED, IconPressed);
+ }
+}
+
+void DeinitSRMMIcon() {
+ if(hZapIcon) DestroyIcon(hZapIcon);
+ if(hEventIconPressed) UnhookEvent(hEventIconPressed);
+ if(hEventWindow) UnhookEvent(hEventWindow);
+}