summaryrefslogtreecommitdiff
path: root/plugins/Clist_modern/src/CLUIFrames/framesmenu.cpp
blob: 80ba3433c0c63fb15d739923b9c2c86d06dafb1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "../hdr/modern_commonheaders.h"
#include "../hdr/modern_commonprototypes.h"

//========================== Frames
HANDLE hFrameMenuObject;
static HANDLE hPreBuildFrameMenuEvent;

//contactmenu exec param(ownerdata)
//also used in checkservice
typedef struct{
	char *szServiceName;
	int Frameid;
	INT_PTR param1;
}FrameMenuExecParam,*lpFrameMenuExecParam;

INT_PTR FreeOwnerDataFrameMenu(WPARAM wParam, LPARAM lParam)
{
	lpFrameMenuExecParam cmep = (lpFrameMenuExecParam)lParam;
	if (cmep != NULL){
		mir_free(cmep->szServiceName);
		mir_free(cmep);
	}
	return 0;
}

static INT_PTR AddContextFrameMenuItem(WPARAM wParam, LPARAM lParam)
{
	CLISTMENUITEM *mi = (CLISTMENUITEM*)lParam;

	TMO_MenuItem tmi;
	if ( !pcli->pfnConvertMenu(mi, &tmi))
		return NULL;

	tmi.root = (mi->flags & CMIF_ROOTHANDLE) ? mi->hParentMenu : NULL;

	lpFrameMenuExecParam fmep = (lpFrameMenuExecParam)mir_alloc(sizeof(FrameMenuExecParam));
	if (fmep == NULL)
		return 0;

	fmep->szServiceName = mir_strdup(mi->pszService);
	fmep->Frameid = mi->popupPosition;
	fmep->param1 = (INT_PTR)mi->pszContactOwner;
	tmi.ownerdata = fmep;

	return CallService(MO_ADDNEWMENUITEM, (WPARAM)hFrameMenuObject, (LPARAM)&tmi);
}

static INT_PTR RemoveContextFrameMenuItem(WPARAM wParam, LPARAM lParam)
{
	if (lParam != 1)
		CallService(MO_REMOVEMENUITEM, wParam, 0);

	return 0;
}

//called with:
//wparam - ownerdata
//lparam - lparam from winproc
INT_PTR FrameMenuExecService(WPARAM wParam, LPARAM lParam)
{
	lpFrameMenuExecParam fmep = (lpFrameMenuExecParam)wParam;
	if (fmep == NULL)
		return -1;

	CallService(fmep->szServiceName, lParam, fmep->param1);
	return 0;
}

//true - ok,false ignore
INT_PTR FrameMenuCheckService(WPARAM wParam, LPARAM lParam)
{
	PCheckProcParam pcpp = (PCheckProcParam)wParam;
	if (pcpp == NULL)
		return FALSE;

	TMO_MenuItem mi;
	if (CallService(MO_GETMENUITEM, (WPARAM)pcpp->MenuItemHandle, (LPARAM)&mi) == 0) {
		lpFrameMenuExecParam fmep = (lpFrameMenuExecParam)mi.ownerdata;
		if (fmep != NULL) {
			//pcpp->wParam  -  frameid
			if (((WPARAM)fmep->Frameid == pcpp->wParam) || fmep->Frameid == -1)
				return TRUE;
		}
	}
	return FALSE;
}

static INT_PTR ContextFrameMenuNotify(WPARAM wParam, LPARAM lParam)
{
	NotifyEventHooks(hPreBuildFrameMenuEvent,wParam,lParam);
	return 0;
}

static INT_PTR BuildContextFrameMenu(WPARAM wParam,LPARAM lParam)
{
	ListParam param = { 0 };
	param.MenuObjectHandle = hFrameMenuObject;
	param.wParam = wParam;
	param.lParam = lParam;

	HMENU hMenu = CreatePopupMenu();
	ContextFrameMenuNotify(wParam, -1);
	CallService(MO_BUILDMENU, (WPARAM)hMenu, (LPARAM)&param);
	return (INT_PTR)hMenu;
}

//========================== Frames end

int InitFramesMenus(void)
{
	CreateServiceFunction("FrameMenuExecService", FrameMenuExecService);
	CreateServiceFunction("FrameMenuCheckService", FrameMenuCheckService);
	CreateServiceFunction("FrameMenuFreeService", FreeOwnerDataFrameMenu);

	CreateServiceFunction(MS_CLIST_REMOVECONTEXTFRAMEMENUITEM, RemoveContextFrameMenuItem);
	CreateServiceFunction("CList/AddContextFrameMenuItem", AddContextFrameMenuItem);
	CreateServiceFunction(MS_CLIST_MENUBUILDFRAMECONTEXT, BuildContextFrameMenu);
	CreateServiceFunction(MS_CLIST_FRAMEMENUNOTIFY, ContextFrameMenuNotify);
	hPreBuildFrameMenuEvent = CreateHookableEvent(ME_CLIST_PREBUILDFRAMEMENU);

	// frame menu object
	hFrameMenuObject = MO_CreateMenuObject("FrameMenu", LPGEN("Frame menu"), "FrameMenuCheckService", "FrameMenuExecService");
	MO_SetMenuObjectParam(hFrameMenuObject, OPT_MENUOBJECT_SET_FREE_SERVICE, "FrameMenuFreeService");
	return 0;
}