]> icculus.org git repositories - mikachu/openbox.git/blob - src/Toolbar.hh
make window menu behavior consistant. ignore !button1.
[mikachu/openbox.git] / src / Toolbar.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // Toolbar.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifndef   __Toolbar_hh
25 #define   __Toolbar_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29 }
30
31 #include "Screen.hh"
32 #include "Basemenu.hh"
33 #include "Timer.hh"
34
35 // forward declaration
36 class Toolbar;
37
38 class Toolbarmenu : public Basemenu {
39 private:
40   class Placementmenu : public Basemenu {
41   private:
42     Placementmenu(const Placementmenu&);
43     Placementmenu& operator=(const Placementmenu&);
44     Toolbar *toolbar;
45
46   protected:
47     virtual void itemSelected(int button, unsigned int index);
48     virtual void setValues(void);
49
50   public:
51     Placementmenu(Toolbarmenu *tm);
52     virtual void reconfigure(void);
53   };
54
55   Toolbar *toolbar;
56   Placementmenu *placementmenu;
57
58   friend class Placementmenu;
59   friend class Toolbar;
60
61   Toolbarmenu(const Toolbarmenu&);
62   Toolbarmenu& operator=(const Toolbarmenu&);
63
64 protected:
65   virtual void itemSelected(int button, unsigned int index);
66   virtual void internal_hide(void);
67   virtual void setValues(void);
68
69 public:
70   Toolbarmenu(Toolbar *tb);
71   ~Toolbarmenu(void);
72
73   inline Basemenu *getPlacementmenu(void) { return placementmenu; }
74
75   virtual void reconfigure(void);
76 };
77
78
79 class Toolbar : public TimeoutHandler {
80 private:
81   bool on_top, editing, hidden, do_auto_hide;
82   unsigned int width_percent;
83   int placement;
84   std::string toolbarstr;
85   Display *display;
86
87   struct ToolbarFrame {
88     unsigned long button_pixel, pbutton_pixel;
89     Pixmap base, label, wlabel, clk, button, pbutton;
90     Window window, workspace_label, window_label, clock, psbutton, nsbutton,
91       pwbutton, nwbutton;
92
93     int x_hidden, y_hidden, hour, minute, grab_x, grab_y;
94     unsigned int window_label_w, workspace_label_w, clock_w,
95       button_w, bevel_w, label_h;
96
97     Rect rect;
98   } frame;
99
100   class HideHandler : public TimeoutHandler {
101   public:
102     Toolbar *toolbar;
103
104     virtual void timeout(void);
105   } hide_handler;
106
107   Blackbox *blackbox;
108   BScreen *screen;
109   Configuration *config;
110   BTimer *clock_timer, *hide_timer;
111   Toolbarmenu *toolbarmenu;
112   Strut strut;
113
114   std::string new_workspace_name;
115   size_t new_name_pos;
116
117   friend class HideHandler;
118   friend class Toolbarmenu;
119   friend class Toolbarmenu::Placementmenu;
120
121   void redrawPrevWorkspaceButton(bool pressed = False, bool redraw = False);
122   void redrawNextWorkspaceButton(bool pressed = False, bool redraw = False);
123   void redrawPrevWindowButton(bool preseed = False, bool redraw = False);
124   void redrawNextWindowButton(bool preseed = False, bool redraw = False);
125
126   void updateStrut(void);
127
128 #ifdef    HAVE_STRFTIME
129   void checkClock(bool redraw = False);
130 #else //  HAVE_STRFTIME
131   void checkClock(bool redraw = False, bool date = False);
132 #endif // HAVE_STRFTIME
133
134   Toolbar(const Toolbar&);
135   Toolbar& operator=(const Toolbar&);
136
137 public:
138   Toolbar(BScreen *scrn);
139   virtual ~Toolbar(void);
140
141   inline Toolbarmenu *getMenu(void) { return toolbarmenu; }
142
143   inline bool isEditing(void) const { return editing; }
144   inline bool isOnTop(void) const { return on_top; }
145   inline bool isHidden(void) const { return hidden; }
146   inline bool doAutoHide(void) const { return do_auto_hide; }
147   inline unsigned int getWidthPercent(void) const { return width_percent; }
148   inline int getPlacement(void) const { return placement; }
149  
150   void saveOnTop(bool);
151   void saveAutoHide(bool);
152   void saveWidthPercent(unsigned int);
153   void savePlacement(int);
154
155   void save_rc(void);
156   void load_rc(void);
157
158   inline Window getWindowID(void) const { return frame.window; }
159
160   inline const Rect& getRect(void) const { return frame.rect; }
161   inline unsigned int getWidth(void) const { return frame.rect.width(); }
162   inline unsigned int getHeight(void) const { return frame.rect.height(); }
163   inline unsigned int getExposedHeight(void) const
164   { return ((do_auto_hide) ? frame.bevel_w : frame.rect.height()); }
165   inline int getX(void) const
166   { return ((hidden) ? frame.x_hidden : frame.rect.x()); }
167   inline int getY(void) const
168   { return ((hidden) ? frame.y_hidden : frame.rect.y()); }
169
170   void buttonPressEvent(XButtonEvent *be);
171   void buttonReleaseEvent(XButtonEvent *re);
172   void enterNotifyEvent(XCrossingEvent * /*unused*/);
173   void leaveNotifyEvent(XCrossingEvent * /*unused*/);
174   void exposeEvent(XExposeEvent *ee);
175   void keyPressEvent(XKeyEvent *ke);
176
177   void edit(void);
178   void reconfigure(void);
179   void toggleAutoHide(void);
180
181   void redrawWindowLabel(bool redraw = False);
182   void redrawWorkspaceLabel(bool redraw = False);
183
184   virtual void timeout(void);
185
186   enum { TopLeft = 1, BottomLeft, TopCenter,
187          BottomCenter, TopRight, BottomRight };
188 };
189
190
191 #endif // __Toolbar_hh