Skip to content

Commit

Permalink
[Win32] Fix status icon menu assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
milani committed Nov 6, 2012
1 parent 79038e3 commit fc21101
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/native_menu/native_menu_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ int NativeMenu::AddSubMenu(HMENU& menu,Settings* settings){
menuItemInfo.fMask = MIIM_DATA;
menuItemInfo.dwTypeData = label;
menuItemInfo.dwItemData =(ULONG_PTR) actionCb;
menuItemInfo.cch = wcslen(label);

if( wcslen(label) == 0 ) {
menuItemInfo.fType = MIIM_TYPE;
menuItemInfo.fMask |= MIIM_TYPE;
menuItemInfo.fType = MF_SEPARATOR;
} else {
menuItemInfo.fMask |= MIIM_STRING;
Expand Down
26 changes: 21 additions & 5 deletions src/native_status_icon/native_status_icon_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ LRESULT CALLBACK StatusIconProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l
menuItem.fMask = MIIM_DATA;
int idx = wParam;
GetMenuItemInfo(menu,idx,TRUE,&menuItem);

appjs::appjs_action_callback* actionCallback = (appjs::appjs_action_callback*) menuItem.dwItemData;
v8::Persistent<v8::Object> action = actionCallback->action;
appjs::NativeMenu* nativeMenu = actionCallback->menu;

if( actionCallback == NULL) {
return 0;
}

v8::Persistent<v8::Object> action = actionCallback->action;

if(action->IsCallable()) {
const int argc = 1;
v8::Handle<v8::Value> argv[argc] = {actionCallback->item};
Expand Down Expand Up @@ -72,10 +78,20 @@ LRESULT CALLBACK StatusIconProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l
HMENU popup = CreatePopupMenu();
int loop = GetMenuItemCount(hPop);
for(int i = 0; i < loop; i++) {
TCHAR* menuTitle = new TCHAR[1000];
GetMenuString(hPop,i,menuTitle,1000,MF_BYPOSITION);
AppendMenu(popup,MF_POPUP, (UINT)GetSubMenu(hPop,i), menuTitle);
// AppendMenu(popup,MF_POPUP, (UINT)GetMenuItemID(hPop,i), menuTitle);
TCHAR* menuTitle = new TCHAR[256];
GetMenuString(hPop,i,menuTitle,256,MF_BYPOSITION);
if(IsMenu(GetSubMenu(hPop,i))) {
AppendMenu(popup,MF_POPUP, (UINT)GetSubMenu(hPop,i), menuTitle);
} else {
MENUITEMINFO menuItem;
menuItem.cbSize = sizeof(MENUITEMINFO) - 4;
menuItem.fMask = MIIM_DATA | MIIM_STRING;
menuItem.dwItemData = NULL;
menuItem.dwTypeData = NULL;
GetMenuItemInfo(hPop,i,TRUE,&menuItem);
menuItem.dwTypeData = menuTitle;
InsertMenuItem(popup,i,TRUE,&menuItem);
}
}

MENUINFO menuInfo;
Expand Down

0 comments on commit fc21101

Please sign in to comment.