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