1 // AppletWindow.hh --- Applet window
2 //
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012 Rob Caelers & Raymond Penners
4 // All rights reserved.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #ifndef W32APPLETWINDOW_HH
21 #define W32APPLETWINDOW_HH
22 
23 #include "preinclude.h"
24 #include <windows.h>
25 #include <process.h>
26 #include <string>
27 #include <gdk/gdkwin32.h>
28 
29 #include "TimerBoxViewBase.hh"
30 #include "ITimeBar.hh"
31 #include "Applet.hh"
32 #include "AppletWindow.hh"
33 
34 class W32AppletWindow : public AppletWindow, public TimerBoxViewBase
35 {
36 public:
37   W32AppletWindow();
38   virtual ~W32AppletWindow();
39 
40   virtual AppletState activate_applet();
41   virtual void deactivate_applet();
42 
43   void set_slot(BreakId  id, int slot);
44   void set_time_bar(BreakId id,
45                     std::string text,
46                     ITimeBar::ColorId primary_color,
47                     int primary_value, int primary_max,
48                     ITimeBar::ColorId secondary_color,
49                     int secondary_value, int secondary_max);
50   void update_view();
51   void update_time_bars();
52   void update_menu();
53   void set_enabled(bool enabled);
54   void set_geometry(Orientation orientation, int size);
55 
56   void init_menu(HWND dest);
57   void add_menu(const char *text, short cmd, int flags);
58 
59   GdkFilterReturn win32_filter_func (void *xevent, GdkEvent *event);
60   bool on_applet_command(int command);
61 
62   enum MenuFlag
63   {
64     MENU_FLAG_TOGGLE = APPLET_MENU_FLAG_TOGGLE,
65     MENU_FLAG_SELECTED = APPLET_MENU_FLAG_SELECTED,
66     MENU_FLAG_POPUP = APPLET_MENU_FLAG_POPUP
67   };
68 
69 private:
70   void update_applet_window();
71 
72   static unsigned __stdcall run_event_pipe_static( void * );
73 
74 private:
75   void run_event_pipe();
76 
77   HWND applet_window;
78   bool menu_sent;
79 
80   bool local_menu_ready;
81   AppletHeartbeatData local_heartbeat_data;
82   AppletMenuData local_menu_data;
83   HWND local_applet_window;
84 
85   AppletHeartbeatData heartbeat_data;
86   AppletMenuData menu_data;
87   CRITICAL_SECTION heartbeat_data_lock;
88   HANDLE heartbeat_data_event;
89   HANDLE thread_abort_event;
90   HANDLE thread_handle;
91   volatile unsigned thread_id;
92 };
93 
94 #endif // W32APPLETWINDOW_HH
95