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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
#include "main.h"
#include "./local_menu.h"
#include "./wasabi.h"
#include "./resource.h"
#include "./navigation.h"
#include "./import.h"
#include "../../General/gen_ml/ml_ipc_0313.h"
#include "../nu/menuHelpers.h"
#include "./ombrowser/browserView.h"
#include "./ombrowser/toolbar.h"
#include "./serviceHelper.h"
#include <ifc_omservice.h>
#define SUBMENU_VIEW 0
#define SUBMENU_SERVICEMNGR 1
#define SUBMENU_NAVIGATION 2
#define SUBMENU_PLUGIN 3
static INT Menu_AddViewContext(HMENU destMenu, HMENU baseMenu, BOOL viewActive)
{
if (NULL == destMenu) return 0;
HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_VIEW);
if (NULL == sorceMenu) return 0;
INT c = GetMenuItemCount(destMenu);
c = MenuHelper_CopyMenu(destMenu, c, sorceMenu);
if (FALSE != viewActive)
{
EnableMenuItem(destMenu, ID_VIEW_OPEN, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);
}
else
{
EnableMenuItem(destMenu, ID_VIEW_OPEN, MF_BYCOMMAND | MF_ENABLED);
SetMenuDefaultItem(destMenu, ID_VIEW_OPEN, FALSE);
}
return c;
}
typedef struct __NAVITEMPAIR
{
INT wId;
LPCSTR toolItem;
} NAVITEMPAIR;
static INT Menu_AddNavigationContext(HMENU destMenu, HMENU baseMenu)
{
if (NULL == destMenu) return 0;
HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_NAVIGATION);
if (NULL == sorceMenu) return 0;
INT c = GetMenuItemCount(destMenu);
c = MenuHelper_CopyMenu(destMenu, c, sorceMenu);
if (0 == c) return c;
HWND hView = NULL;
Navigation *navigation;
if (SUCCEEDED(Plugin_GetNavigation(&navigation)))
{
hView = navigation->GetActiveView(NULL);
navigation->Release();
}
HWND hToolbar = (NULL != hView) ? BrowserView_GetToolbar(hView) : NULL;
if (NULL != hToolbar)
{
NAVITEMPAIR szItems[] =
{
{ID_NAVIGATION_BACK, TOOLITEM_BUTTON_BACK},
{ID_NAVIGATION_FORWARD, TOOLITEM_BUTTON_FORWARD},
{ID_NAVIGATION_HOME, TOOLITEM_BUTTON_HOME},
{ID_NAVIGATION_STOP, TOOLITEM_BUTTON_STOP},
{ID_NAVIGATION_REFRESH, TOOLITEM_BUTTON_REFRESH},
};
for (INT i = 0; i < ARRAYSIZE(szItems); i++)
{
INT index = Toolbar_FindItem(hToolbar, szItems[i].toolItem);
if (-1 != index)
{
BOOL fDisabled = Toolbar_GetItemStyle(hToolbar, MAKEINTRESOURCE(index), TBIS_DISABLED);
EnableMenuItem(destMenu, szItems[i].wId, MF_BYCOMMAND | (fDisabled) ? (MF_DISABLED | MF_GRAYED) : (MF_ENABLED));
}
}
}
return c;
}
static INT Menu_AddServiceContext(HMENU destMenu, HMENU baseMenu, ifc_omservice *service)
{
if (NULL == destMenu || NULL == service) return 0;
HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_SERVICEMNGR);
if (NULL == sorceMenu) return 0;
INT origCount = GetMenuItemCount(destMenu);
INT c = MenuHelper_CopyMenu(destMenu, origCount, sorceMenu);
UINT serviceFlags;
if (FAILED(service->GetFlags(&serviceFlags))) serviceFlags = 0;
if (0 != ((WDSVCF_ROOT | WDSVCF_SPECIAL) & serviceFlags))
{
UINT szDisabled[] = {ID_SERVICE_EDIT, ID_SERVICE_DELETE, ID_SERVICE_RELOAD,
ID_SERVICE_LOCATE, ID_SERVICE_EDITEXTERNAL };
for (INT i = 0; i < ARRAYSIZE(szDisabled); i++)
EnableMenuItem(destMenu, szDisabled[i], MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
}
UINT uEnable;
uEnable = (S_OK == ImportService_GetFileSupported()) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED);
EnableMenuItem(destMenu, ID_SERVICE_IMPORT_FILE, MF_BYCOMMAND | uEnable);
uEnable = (S_OK == ImportService_GetUrlSupported()) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED);
EnableMenuItem(destMenu, ID_SERVICE_IMPORT_URL, MF_BYCOMMAND | uEnable);
return c;
}
static INT Menu_AddPluginContext(HMENU destMenu, HMENU baseMenu, ifc_omservice *service)
{
UINT serviceFlags;
if (NULL == service || FAILED(service->GetFlags(&serviceFlags)))
serviceFlags = 0;
if (NULL == destMenu || NULL == service ||
0 == (WDSVCF_ROOT & serviceFlags))
{
return 0;
}
HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_PLUGIN);
if (NULL == sorceMenu) return 0;
INT origCount = GetMenuItemCount(destMenu);
INT c = MenuHelper_CopyMenu(destMenu, origCount, sorceMenu);
return c;
}
static HMENU Menu_GetServiceContext(HMENU baseMenu, ifc_omservice *service)
{
HMENU hMenu = CreatePopupMenu();
if(NULL == hMenu) return NULL;
ifc_omservice *activeService = NULL;
Navigation *navigation;
if (SUCCEEDED(Plugin_GetNavigation(&navigation)))
{
navigation->GetActive(&activeService);
navigation->Release();
}
BOOL fActive = (NULL != service && activeService == service);
INT c, total;
total = Menu_AddViewContext(hMenu, baseMenu, fActive);
if (FALSE != fActive)
{
c = Menu_AddNavigationContext(hMenu, baseMenu);
if (0 != c && total > 0 && 0 != MenuHelper_InsertSeparator(hMenu, total))
total++;
total += c;
}
if (NULL != service)
{
c = Menu_AddServiceContext(hMenu, baseMenu, service);
if (0 != c && total > 0 && 0 != MenuHelper_InsertSeparator(hMenu, total))
total++;
total += c;
c = Menu_AddPluginContext(hMenu, baseMenu, service);
if (0 != c && total > 0 && 0 != MenuHelper_InsertSeparator(hMenu, total))
total++;
total += c;
}
if (NULL != activeService)
activeService->Release();
return hMenu;
}
HMENU Menu_GetMenu(UINT menuKind, ifc_omservice *service)
{
HMENU baseMenu = WASABI_API_LOADMENUW(IDR_CONTEXTMENU);
if (NULL == baseMenu)
return NULL;
switch(menuKind)
{
case MENU_SERVICECONTEXT:
return Menu_GetServiceContext(baseMenu, service);
}
return NULL;
}
BOOL Menu_ReleaseMenu(HMENU hMenu, UINT menuKind)
{
if (NULL == hMenu) return FALSE;
switch(menuKind)
{
case MENU_SERVICECONTEXT:
return DestroyMenu(hMenu);
}
return FALSE;
}
|