summaryrefslogtreecommitdiff
path: root/plugins/Clist_mw/src/clisttray.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-07-16 16:31:53 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-07-16 16:31:53 +0000
commit5b0a53a6d3f1b8d70b34631d96d3815d0a334dd3 (patch)
tree9b38676d8ae565bac52063f5398dde110082a26f /plugins/Clist_mw/src/clisttray.cpp
parent1cf47d1eaff4d7d7242d0ab87dd540ae5b400833 (diff)
Clist_mw, Clist_nicer, CmdLine, Console: folder structure change
git-svn-id: http://svn.miranda-ng.org/main/trunk@988 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Clist_mw/src/clisttray.cpp')
-rw-r--r--plugins/Clist_mw/src/clisttray.cpp281
1 files changed, 281 insertions, 0 deletions
diff --git a/plugins/Clist_mw/src/clisttray.cpp b/plugins/Clist_mw/src/clisttray.cpp
new file mode 100644
index 0000000000..d0e6e3ae93
--- /dev/null
+++ b/plugins/Clist_mw/src/clisttray.cpp
@@ -0,0 +1,281 @@
+/*
+
+Miranda IM: the free IM client for Microsoft* Windows*
+
+Copyright 2000-2003 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "commonheaders.h"
+#include "m_clui.h"
+
+#define TIM_CALLBACK (WM_USER+1857)
+#define TIM_CREATE (WM_USER+1858)
+
+extern INT_PTR ( *saveTrayIconProcessMessage )(WPARAM wParam,LPARAM lParam);
+void DestroyTrayMenu(HMENU hMenu);
+
+INT_PTR TrayIconProcessMessage(WPARAM wParam,LPARAM lParam)
+{
+ MSG *msg = (MSG*)wParam;
+ switch(msg->message) {
+ case WM_DRAWITEM:
+ return CallService(MS_CLIST_MENUDRAWITEM,msg->wParam,msg->lParam);
+ break;
+ case WM_MEASUREITEM:
+ return CallService(MS_CLIST_MENUMEASUREITEM,msg->wParam,msg->lParam);
+ break;
+ case TIM_CALLBACK:
+ if (msg->lParam == WM_RBUTTONUP)
+ {
+ POINT pt;
+ HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDTRAY,(WPARAM)0,(LPARAM)0);
+
+ SetForegroundWindow(msg->hwnd);
+ SetFocus(msg->hwnd);
+ GetCursorPos(&pt);
+ TrackPopupMenu(hMenu, TPM_TOPALIGN | TPM_LEFTALIGN, pt.x, pt.y, 0, msg->hwnd, NULL);
+ DestroyTrayMenu(hMenu);
+ }
+ else break;
+
+ *((LRESULT*)lParam) = 0;
+ return TRUE;
+ }
+
+ return saveTrayIconProcessMessage( wParam, lParam );
+}
+
+//////////////////////////////TRAY MENU/////////////////////////
+HANDLE hTrayMenuObject;
+
+HANDLE hTrayMainMenuItemProxy;
+HANDLE hHideShowMainMenuItem;
+HANDLE hTrayStatusMenuItemProxy;
+HANDLE hPreBuildTrayMenuEvent;
+
+//traymenu exec param(ownerdata)
+typedef struct{
+char *szServiceName;
+INT_PTR Param1;
+}TrayMenuExecParam,*lpTrayMenuExecParam;
+
+/*
+wparam = handle to the menu item returned by MS_CLIST_ADDCONTACTMENUITEM
+return 0 on success.
+*/
+static INT_PTR RemoveTrayMenuItem(WPARAM wParam,LPARAM lParam)
+{
+ CallService(MO_REMOVEMENUITEM,wParam,0);
+ return 0;
+}
+
+static INT_PTR BuildTrayMenu(WPARAM wParam,LPARAM lParam)
+{
+ int tick;
+ HMENU hMenu;
+ ListParam param = { 0 };
+ param.MenuObjectHandle = hTrayMenuObject;
+
+ //hMenu = hMainMenu;
+ hMenu = CreatePopupMenu();
+ //hMenu = wParam;
+ tick = GetTickCount();
+
+ NotifyEventHooks(hPreBuildTrayMenuEvent,0,0);
+
+ CallService(MO_BUILDMENU,(WPARAM)hMenu,(LPARAM)&param);
+ //DrawMenuBar((HWND)CallService("CLUI/GetHwnd",0,0));
+ tick = GetTickCount()-tick;
+ return (INT_PTR)hMenu;
+}
+
+static INT_PTR AddTrayMenuItem(WPARAM wParam,LPARAM lParam)
+{
+ TMO_MenuItem tmi;
+ CLISTMENUITEM *mi = (CLISTMENUITEM*)lParam;
+ if ( !pcli->pfnConvertMenu(mi, &tmi))
+ return NULL;
+
+ lpTrayMenuExecParam mmep = (lpTrayMenuExecParam)mir_alloc(sizeof(TrayMenuExecParam));
+ if (mmep == NULL)
+ return 0;
+
+ mmep->szServiceName = mir_strdup(mi->pszService);
+ mmep->Param1 = mi->popupPosition;
+ tmi.ownerdata = mmep;
+
+ OptParam op;
+ op.Handle = (HANDLE)CallService(MO_ADDNEWMENUITEM,(WPARAM)hTrayMenuObject,(LPARAM)&tmi);
+ op.Setting = OPT_MENUITEMSETUNIQNAME;
+ op.Value = (INT_PTR)mi->pszService;
+ CallService(MO_SETOPTIONSMENUITEM,(WPARAM)0,(LPARAM)&op);
+ return (INT_PTR)op.Handle;
+}
+
+INT_PTR TrayMenuCheckService(WPARAM wParam,LPARAM lParam)
+{
+ return 0;
+}
+
+INT_PTR TrayMenuonAddService(WPARAM wParam,LPARAM lParam)
+{
+ MENUITEMINFO *mii = (MENUITEMINFO* )wParam;
+ if (mii == NULL) return 0;
+
+ if (hHideShowMainMenuItem == (HANDLE)lParam) {
+ mii->fMask |= MIIM_STATE;
+ mii->fState |= MFS_DEFAULT;
+ }
+
+ if (hTrayMainMenuItemProxy == (HANDLE)lParam) {
+ mii->fMask |= MIIM_SUBMENU;
+ mii->hSubMenu = (HMENU)CallService(MS_CLIST_MENUGETMAIN,0,0);
+ }
+
+ if (hTrayStatusMenuItemProxy == (HANDLE)lParam) {
+ mii->fMask |= MIIM_SUBMENU;
+ mii->hSubMenu = (HMENU)CallService(MS_CLIST_MENUGETSTATUS,0,0);
+ }
+
+ return(TRUE);
+}
+
+
+//called with:
+//wparam - ownerdata
+//lparam - lparam from winproc
+INT_PTR TrayMenuExecService(WPARAM wParam,LPARAM lParam) {
+ if (wParam != 0)
+ {
+ lpTrayMenuExecParam mmep = (lpTrayMenuExecParam)wParam;
+ if (!strcmp(mmep->szServiceName,"Help/AboutCommand"))
+ {
+ //bug in help.c,it used wparam as parent window handle without reason.
+ mmep->Param1 = 0;
+ }
+ CallService(mmep->szServiceName,mmep->Param1,lParam);
+ }
+ return(1);
+}
+
+INT_PTR FreeOwnerDataTrayMenu (WPARAM wParam,LPARAM lParam)
+{
+
+ lpTrayMenuExecParam mmep;
+ mmep = (lpTrayMenuExecParam)lParam;
+ if (mmep != NULL){
+ FreeAndNil((void**)&mmep->szServiceName);
+ FreeAndNil((void**)&mmep);
+ }
+
+ return 0;
+}
+
+void InitTrayMenus(void)
+{
+ TMenuParam tmp;
+ OptParam op;
+
+ //Tray menu
+ memset(&tmp,0,sizeof(tmp));
+ tmp.cbSize = sizeof(tmp);
+ tmp.CheckService = NULL;
+ tmp.ExecService = "CLISTMENUSTRAY/ExecService";
+ tmp.name = "TrayMenu";
+ hTrayMenuObject = (HANDLE)CallService(MO_CREATENEWMENUOBJECT,(WPARAM)0,(LPARAM)&tmp);
+
+ CreateServiceFunction("CLISTMENUSTRAY/ExecService",TrayMenuExecService);
+ CreateServiceFunction("CLISTMENUSTRAY/FreeOwnerDataTrayMenu",FreeOwnerDataTrayMenu);
+ CreateServiceFunction("CLISTMENUSTRAY/TrayMenuonAddService",TrayMenuonAddService);
+
+ CreateServiceFunction("CList/AddTrayMenuItem",AddTrayMenuItem);
+ CreateServiceFunction(MS_CLIST_REMOVETRAYMENUITEM,RemoveTrayMenuItem);
+ CreateServiceFunction(MS_CLIST_MENUBUILDTRAY,BuildTrayMenu);
+ hPreBuildTrayMenuEvent = CreateHookableEvent(ME_CLIST_PREBUILDTRAYMENU);
+
+ op.Handle = hTrayMenuObject;
+ op.Setting = OPT_USERDEFINEDITEMS;
+ op.Value = TRUE;
+ CallService(MO_SETOPTIONSMENUOBJECT,(WPARAM)0,(LPARAM)&op);
+
+ op.Handle = hTrayMenuObject;
+ op.Setting = OPT_MENUOBJECT_SET_FREE_SERVICE;
+ op.Value = (INT_PTR)"CLISTMENUSTRAY/FreeOwnerDataTrayMenu";
+ CallService(MO_SETOPTIONSMENUOBJECT,(WPARAM)0,(LPARAM)&op);
+
+ op.Handle = hTrayMenuObject;
+ op.Setting = OPT_MENUOBJECT_SET_ONADD_SERVICE;
+ op.Value = (INT_PTR)"CLISTMENUSTRAY/TrayMenuonAddService";
+ CallService(MO_SETOPTIONSMENUOBJECT,(WPARAM)0,(LPARAM)&op);
+
+ {
+ //add exit command to menu
+ CLISTMENUITEM mi;
+
+ memset(&mi,0,sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 900000;
+ mi.pszService = "CloseAction";
+ mi.pszName = LPGEN("E&xit");
+ AddTrayMenuItem((WPARAM)0,(LPARAM)&mi);
+
+ memset(&mi,0,sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 100000;
+ mi.pszService = MS_CLIST_SHOWHIDE;
+ mi.pszName = LPGEN("&Hide/Show");
+ hHideShowMainMenuItem = (HANDLE)AddTrayMenuItem((WPARAM)0,(LPARAM)&mi);
+
+ memset(&mi,0,sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 200000;
+ mi.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_FINDUSER));
+ mi.pszService = "FindAdd/FindAddCommand";
+ mi.pszName = LPGEN("&Find/Add Contacts...");
+ AddTrayMenuItem((WPARAM)0,(LPARAM)&mi);
+
+ memset(&mi,0,sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 300000;
+ mi.pszService = "";
+ mi.pszName = LPGEN("&Main Menu");
+ hTrayMainMenuItemProxy = (HANDLE)AddTrayMenuItem((WPARAM)0,(LPARAM)&mi);
+
+ memset(&mi,0,sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 300100;
+ mi.pszService = "";
+ mi.pszName = LPGEN("&Status");
+ hTrayStatusMenuItemProxy = (HANDLE)AddTrayMenuItem((WPARAM)0,(LPARAM)&mi);
+
+ memset(&mi,0,sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 400000;
+ mi.hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_OPTIONS));
+ mi.pszService = "Options/OptionsCommand";
+ mi.pszName = LPGEN("&Options...");
+ AddTrayMenuItem((WPARAM)0,(LPARAM)&mi);
+
+ memset(&mi,0,sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = 500000;
+ mi.hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_CLIENTMIRANDA));
+ mi.pszService = "Help/AboutCommand";
+ mi.pszName = LPGEN("&About");
+ AddTrayMenuItem((WPARAM)0,(LPARAM)&mi);
+} }