Exemple #1
0
static int mh_deleteitem (lua_State* l) {
menu* m = lua_touserdata(l,1);
if (lua_isnoneornil(l,2)) {
const char* menuName = GetMenuName(m->parent, m->position);
if (menuName) free(menuName);
DeleteMenu(m->parent, m->command, MF_BYCOMMAND);
if (!m->sub) {
removeCustomCommand(m->command);
removeAccelerator(m->command);
} 
DrawMenuBar(win);
return 0;
}
else {
if (!m->sub) return 0;
menu* x = lua_touserdata(l,2);
const char* menuName = GetMenuName(m->menu, x->position);
if (menuName) free(menuName);
DeleteMenu(m->menu, x->command, MF_BYCOMMAND);
DrawMenuBar(win);
if (!x->sub) {
removeCustomCommand(x->command);
removeAccelerator(x->command);
}
lua_settop(l,1);
return 1;
}}
bool CollectionNavigationPane::ShowContextMenu(const OpPoint &point, BOOL center, OpTreeView* view, BOOL use_keyboard_context)
{
	const char* menu_name = GetMenuName();
	if (!menu_name)
		return true;

	NavigationItem* item = static_cast<NavigationItem*>(m_tree_view->GetOpWidget()->GetSelectedItem());

	OpPoint p(point.x+GetScreenRect().x, point.y+GetScreenRect().y);
	g_application->GetMenuHandler()->ShowPopupMenu(menu_name, PopupPlacement::AnchorAt(p, center), item->GetID(), use_keyboard_context);
	return true;
}
Exemple #3
0
static int mh_index (lua_State* l) {
menu* m = lua_touserdata(l,1);
if (lua_isnumber(l,2)) {
if (!m->sub) return 0;
int n = lua_tointeger(l,2);
if (n==0) n=-1;
if (n<0) n += GetMenuItemCount(m->menu);
else n--;
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID | MIIM_SUBMENU;
if (!GetMenuItemInfo(m->menu, n, TRUE, &mii)) return 0;
menu x;
x.sub = mii.hSubMenu!=0;
x.origin = m->origin;
x.parent = m->menu;
x.position = n;
if (mii.hSubMenu!=0) x.menu = mii.hSubMenu;
else x.command = mii.wID;
lua_settop(l,0);
lua_pushfulluserdata(l, &x, sizeof(x), "menuhandle");
return 1;
}
const char* nm = luaL_checkstring(l,2);
if (streq(nm, "checked")) {
if (m->sub) luaL_error(l, "unsupported operation");
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE | MIIM_FTYPE;
if (!GetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0;
lua_pushboolean(l, 0!=(mii.fState&MFS_CHECKED));
return 1;
}
else if (streq(nm, "radio")) {
if (m->sub) luaL_error(l, "unsupported operation");
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_FTYPE;
if (!GetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0;
lua_pushboolean(l, 0!=(mii.fType&MFT_RADIOCHECK));
return 1;
}
else if (streq(nm, "enabled")) {
if (m->sub) luaL_error(l, "unsupported operation");
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
if (!GetMenuItemInfo(m->parent, m->command, FALSE, &mii)) return 0;
lua_settop(l,0);
lua_pushboolean(l, 0==(mii.fState&MFS_DISABLED));
return 1;
}
else if (streq(nm, "text")) {
const wchar_t* wc = mh_getLabel(m);
const char* mbc = strcvt(wc, CP_UTF16, CP_UTF8, NULL);
lua_pushstring(l, mbc);
free(mbc); 
free(wc);
return 1;
}
else if (streq(nm, "name")) {
const char* menuName = GetMenuName(m->parent, m->position);
lua_settop(l,0);
lua_pushstring(l,menuName);
return 1;
}
else if (streq(nm, "accelerator")) {
int f, k;
if (!(m->sub) && findAccelerator(m->command, &f, &k)) {
const wchar_t* wkn = getKeyName(f,k,0);
const char* kn = strcvt(wkn, CP_UTF16, CP_UTF8, NULL);
lua_pushstring(l,kn);
free(kn);
free(wkn);
return 1;
}
return 0;
}
else if (streq(nm, "onAction")) {
if (m->sub) return 0;
if (m->command>=IDM_CUSTOMCOMMAND) lua_pushluafunction(l, *getCustomCommand(m->command - IDM_CUSTOMCOMMAND));
else {
lua_pushinteger(l, m->command);
lua_pushcclosure(l, mh_commandclosure, 1);
}
return 1;
}
else if (streq(nm, "builtIn")) {
if (m->sub) return 0;
lua_pushboolean(l, m->command<IDM_CUSTOMCOMMAND);
return 1;
}
else if (streq(nm, "parent")) {
menu x;
x.sub = TRUE;
x.parent = GetParentMenu(m->parent, m->origin, &(x.position));
x.menu = m->parent;
x.origin = m->origin;
if (!x.parent) return 0;
lua_settop(l,0);
lua_pushfulluserdata(l, &x, sizeof(x), "menuhandle");
return 1;
}
else if (streq(nm, "parentHandle")) {
lua_pushlightuserdata(l, m->parent);
return 1;
}
else if (streq(nm, "handle") || streq(nm, "command")) {
if (m->sub) lua_pushlightuserdata(l, m->command);
else lua_pushinteger(l, m->command);
return 1;
}
//SUITE
else if (luaL_getmetafield(l, 1, nm)) return 1;
else if (m->sub) {
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
for (int i=0, n=GetMenuItemCount(m->menu); i<n; i++) {
if (!GetMenuItemInfo(m->menu, i, TRUE, &mii)) continue;
if (mii.dwItemData && streq(nm, mii.dwItemData)) {
menu x;
x.sub = mii.hSubMenu!=0;
x.parent = m->menu;
x.origin = m->origin;
x.position = i;
if (mii.hSubMenu!=0) x.menu = mii.hSubMenu;
else x.command = mii.wID;
lua_settop(l,0);
lua_pushfulluserdata(l, &x, sizeof(x), "menuhandle");
return 1;
}}}
return 0;
}