Permalink
Browse files

[Win32] Fix status icon bugs

  • Loading branch information...
1 parent 272b62c commit ad5a9facb25de4ee9ed22ad8f66b43989bf5100f @milani milani committed Nov 4, 2012
@@ -36,6 +36,7 @@ class NativeMenu {
#elif defined(__WIN__)
int AddSubMenu(HMENU&,Settings*);
bool Attach(HMENU&);
+ bool Detach(HMENU&);
#endif
private:
@@ -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 */
@@ -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){
@@ -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;
@@ -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;
@@ -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;
@@ -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");
}

0 comments on commit ad5a9fa

Please sign in to comment.