Skip to content

Commit

Permalink
[Win32] Fix status icon bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
milani committed Nov 4, 2012
1 parent 272b62c commit ad5a9fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/native_menu/native_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class NativeMenu {
#elif defined(__WIN__)
int AddSubMenu(HMENU&,Settings*);
bool Attach(HMENU&);
bool Detach(HMENU&);
#endif

private:
Expand Down
12 changes: 12 additions & 0 deletions src/native_menu/native_menu_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,16 @@ bool NativeMenu::Attach(HMENU& menuBar) {
}
}


bool NativeMenu::Detach(HMENU& menuBar) {
if(attached_) {
attached_ = false;
this->Emit("detached");
return true;
} else {
// already detached
return false;
}
}

} /* appjs */
3 changes: 3 additions & 0 deletions src/native_status_icon/native_status_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ NativeStatusIcon::NativeStatusIcon(Settings* settings){
}

NativeStatusIcon::~NativeStatusIcon(){
#ifdef __WIN__
Shell_NotifyIcon(NIM_DELETE, &statusIconHandle_);
#endif
}

void NativeStatusIcon::Emit(v8::Handle<Value>* args,int length){
Expand Down
38 changes: 26 additions & 12 deletions src/native_status_icon/native_status_icon_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "includes/util_win.h"
#include "includes/cef_handler.h"
#include "native_status_icon/native_status_icon.h"
#include "native_menu/native_menu.h"

extern CefRefPtr<ClientHandler> g_handler;

Expand All @@ -29,21 +30,33 @@ HWND hWnd;

LRESULT CALLBACK StatusIconProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch(message) {
case WM_MENUCOMMAND: {
HMENU menu = (HMENU)lParam;
MENUITEMINFO menuItem;
menuItem.cbSize = sizeof(MENUITEMINFO);
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(action->IsCallable()) {
const int argc = 1;
v8::Handle<v8::Value> argv[argc] = {actionCallback->item};
action->CallAsFunction(nativeMenu->GetV8Handle(),argc,argv);
}

nativeMenu->Emit("select",v8::Local<v8::Object>::New(actionCallback->item));
return 0;
}
case WM_USER:
switch(lParam) {
case WM_LBUTTONDBLCLK: {
appjs::NativeStatusIcon* nativeStatusIcon = (appjs::NativeStatusIcon*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
nativeStatusIcon->Emit("dblclick");
return true;
}
case WM_COMMAND: {
fprintf(stderr, "%s\n", "clicked2");
return 0;
}
case WM_MENUCOMMAND: {
fprintf(stderr, "%s\n", "clicked");
return 0;
}
case WM_RBUTTONUP: {

HMENU hPop;
Expand Down Expand Up @@ -77,12 +90,11 @@ LRESULT CALLBACK StatusIconProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l

SendMessage( hWnd, WM_INITMENUPOPUP, (WPARAM)popup, 0 );

cmd = TrackPopupMenu( popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON
| TPM_RETURNCMD | TPM_NONOTIFY,
TrackPopupMenu( popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON,
curpos->x, curpos->y, 0, hWnd, NULL );

SendMessage( hWnd, WM_COMMAND, cmd, 0 );
PostMessage(hWnd, WM_USER,0,0);
nativeMenu->Detach(hPop);
// SendMessage( hWnd, WM_MENUCOMMAND, cmd, (UINT)popup );

nativeStatusIcon->Emit("rightclick");
return true;
Expand Down Expand Up @@ -185,10 +197,12 @@ void NativeStatusIcon::Init(Settings* settings) {
}

void NativeStatusIcon::Show(){
Shell_NotifyIcon(NIM_ADD, &statusIconHandle_);
this->Emit("show");
}

void NativeStatusIcon::Hide(){
Shell_NotifyIcon(NIM_DELETE, &statusIconHandle_);
this->Emit("hide");
}

Expand Down

0 comments on commit ad5a9fa

Please sign in to comment.