1
// FbWinFrame.hh for Fluxbox Window Manager
2
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
// DEALINGS IN THE SOFTWARE.
22
// $Id: FbWinFrame.hh 4058 2005-06-19 12:12:54Z simonb $
27
#include "FbTk/FbWindow.hh"
28
#include "FbTk/EventHandler.hh"
29
#include "FbTk/RefCount.hh"
30
#include "FbTk/Observer.hh"
31
#include "FbTk/Color.hh"
32
#include "FbTk/FbPixmap.hh"
33
#include "Container.hh"
41
class FbWinFrameTheme;
51
/// holds a window frame with a client window
52
/// (see: <a href="fluxbox_fbwinframe.png">image</a>)
53
class FbWinFrame:public FbTk::EventHandler {
55
enum TabMode { INTERNAL = 1, EXTERNAL };
57
typedef FbTk::TextButton *ButtonId; ///< defines a button id
59
/// create a top level window
60
FbWinFrame(FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl,
62
unsigned int width, unsigned int height);
64
/// create a frame window inside another FbWindow, NOT IMPLEMENTED!
65
FbWinFrame(FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl,
66
const FbTk::FbWindow &parent,
68
unsigned int width, unsigned int height);
73
/// setup actions for titlebar
74
bool setOnClickTitlebar(FbTk::RefCount<FbTk::Command> &cmd, int button_num,
75
bool double_click=false, bool pressed=false);
79
inline bool isVisible() const { return m_visible; }
80
/// shade frame (ie resize to titlebar size)
82
void move(int x, int y, int win_gravity=ForgetGravity);
83
void resize(unsigned int width, unsigned int height, int win_gravity=ForgetGravity);
84
/// resize client to specified size and resize frame to it
85
void resizeForClient(unsigned int width, unsigned int height, int win_gravity=ForgetGravity);
87
// for when there needs to be an atomic move+resize operation
88
void moveResizeForClient(int x, int y,
89
unsigned int width, unsigned int height,
90
bool move = true, bool resize = true, int win_gravity=ForgetGravity);
92
// can elect to ignore move or resize (mainly for use of move/resize individual functions
93
void moveResize(int x, int y,
94
unsigned int width, unsigned int height,
95
bool move = true, bool resize = true, int win_gravity=ForgetGravity);
97
/// some outside move/resize happened, and we need to notify all of our windows
98
/// in case of transparency
99
void notifyMoved(bool clear);
102
/// set focus/unfocus style
103
void setFocus(bool newvalue);
104
void setDoubleClickTime(unsigned int time);
106
/// add a button to the left of the label
107
void addLeftButton(FbTk::Button *btn);
108
/// add a button to the right of the label
109
void addRightButton(FbTk::Button *btn);
110
/// remove all buttons from titlebar
111
void removeAllButtons();
112
/// adds a button to label window with specified title and command
113
ButtonId createTab(const std::string &title, FbTk::Command *cmd);
114
// void addLabelButton(FbTk::TextButton &btn);
115
/// removes a specific button from label window
116
void removeTab(ButtonId id);
117
/// move label button to the left
118
void moveLabelButtonLeft(FbTk::TextButton &btn);
119
/// move label button to the right
120
void moveLabelButtonRight(FbTk::TextButton &btn);
121
/// move label button to the given location( x and y are relative to the root window)
122
void moveLabelButtonTo(FbTk::TextButton &btn, int x, int y);
123
/// move the first label button to the left of the second
124
void moveLabelButtonLeftOf(FbTk::TextButton &btn, const FbTk::TextButton &dest);
125
//move the first label button to the right of the second
126
void moveLabelButtonRightOf(FbTk::TextButton &btn, const FbTk::TextButton &dest);
127
/// which button is to be rendered focused
128
void setLabelButtonFocus(FbTk::TextButton &btn);
129
/// attach a client window for client area
130
void setClientWindow(FbTk::FbWindow &win);
131
/// remove attached client window
133
/// redirect events to another eventhandler
134
void setEventHandler(FbTk::EventHandler &evh);
135
/// remove any handler for the windows
136
void removeEventHandler();
138
// these return true/false for if something changed
143
bool hideAllDecorations();
144
bool showAllDecorations();
146
// this function translates its arguments according to win_gravity
147
// if win_gravity is negative, it does an inverse translation
148
void gravityTranslate(int &x, int &y, int win_gravity, bool move_frame = false);
149
//use width and height given instead of the real values, allows figuring out where to place a window before doing a moveResize
150
void gravityTranslate(int &x, int &y, unsigned int width, unsigned int height, int win_gravity, bool move_frame = false);
151
void setBorderWidth(unsigned int borderW);
157
void buttonPressEvent(XButtonEvent &event);
158
void buttonReleaseEvent(XButtonEvent &event);
159
void exposeEvent(XExposeEvent &event);
160
void configureNotifyEvent(XConfigureEvent &event);
161
void handleEvent(XEvent &event);
165
void setUseShape(bool value);
171
inline int x() const { return m_window.x(); }
172
inline int y() const { return m_window.y(); }
173
inline unsigned int width() const { return m_window.width(); }
174
inline unsigned int height() const { return m_window.height(); }
175
inline const FbTk::FbWindow &window() const { return m_window; }
176
inline FbTk::FbWindow &window() { return m_window; }
177
/// @return titlebar window
178
inline const FbTk::FbWindow &titlebar() const { return m_titlebar; }
179
inline FbTk::FbWindow &titlebar() { return m_titlebar; }
180
inline const FbTk::FbWindow &label() const { return m_label; }
181
inline FbTk::FbWindow &label() { return m_label; }
182
/// @return clientarea window
183
inline const FbTk::FbWindow &clientArea() const { return m_clientarea; }
184
inline FbTk::FbWindow &clientArea() { return m_clientarea; }
185
/// @return handle window
186
inline const FbTk::FbWindow &handle() const { return m_handle; }
187
inline FbTk::FbWindow &handle() { return m_handle; }
188
inline const FbTk::FbWindow &gripLeft() const { return m_grip_left; }
189
inline FbTk::FbWindow &gripLeft() { return m_grip_left; }
190
inline const FbTk::FbWindow &gripRight() const { return m_grip_right; }
191
inline FbTk::FbWindow &gripRight() { return m_grip_right; }
192
inline const FbTk::TextButton *currentLabel() const { return m_current_label; }
193
inline bool focused() const { return m_focused; }
194
inline bool isShaded() const { return m_shaded; }
195
inline const FbWinFrameTheme &theme() const { return m_theme; }
196
/// @return titlebar height
197
unsigned int titlebarHeight() const { return m_titlebar.height(); }
198
/// @return size of button
199
unsigned int buttonHeight() const;
204
void redrawTitlebar();
206
/// reposition titlebar items
207
void reconfigureTitlebar();
209
@name render helper functions
213
void renderTitlebar();
214
void renderHandles();
215
void renderLabelButtons();
217
void renderButtons(); // subset of renderTitlebar - don't call directly
219
/// renders to pixmap or sets color
220
void render(const FbTk::Texture &tex, FbTk::Color &col, Pixmap &pm,
221
unsigned int width, unsigned int height);
226
@name apply pixmaps depending on focus
230
void applyTitlebar();
232
void applyLabelButtons();
233
void applyFocusLabel(FbTk::TextButton &button);
234
void applyUnfocusLabel(FbTk::TextButton &button);
235
void applyActiveLabel(FbTk::TextButton &button);
236
void applyButtons(); // only called within applyTitlebar
238
void getActiveLabelPixmap(Pixmap &label_pm, Pixmap &title_pm,
239
FbTk::Color &label_color, FbTk::Color &title_color);
240
void getCurrentFocusPixmap(Pixmap &label_pm, Pixmap &title_pm,
241
FbTk::Color &label_color, FbTk::Color &title_color);
243
/// initiate inserted button for current theme
244
void applyButton(FbTk::Button &btn);
247
/// initiate some commont variables
250
FbWinFrameTheme &m_theme; ///< theme to be used
251
FbTk::ImageControl &m_imagectrl; ///< Image control for rendering
256
FbTk::FbWindow m_window; ///< base window that holds each decorations (ie titlebar, handles)
257
FbTk::FbWindow m_titlebar; ///< titlebar window
258
Container m_tab_container; ///< Holds tabs
259
FbTk::FbWindow m_label; ///< holds title
260
FbTk::FbWindow m_handle; ///< handle between grips
261
FbTk::FbWindow m_grip_right, ///< rightgrip
262
m_grip_left; ///< left grip
263
FbTk::FbWindow m_clientarea; ///< window that sits behind client window to fill gaps @see setClientWindow
265
typedef std::vector<FbTk::Button *> ButtonList;
266
ButtonList m_buttons_left, ///< buttons to the left
267
m_buttons_right; ///< buttons to the right
268
typedef std::list<FbTk::TextButton *> LabelList;
269
FbTk::TextButton *m_current_label; ///< which client button is focused at the moment
270
std::string m_titletext; ///< text to be displayed int m_label
271
int m_bevel; ///< bevel between titlebar items and titlebar
272
bool m_use_titlebar; ///< if we should use titlebar
273
bool m_use_handle; ///< if we should use handle
274
bool m_focused; ///< focused/unfocused mode
275
bool m_visible; ///< if we are currently showing
278
@name pixmaps and colors for rendering
281
Pixmap m_title_focused_pm; ///< pixmap for focused title
282
FbTk::Color m_title_focused_color; ///< color for focused title
283
Pixmap m_title_unfocused_pm; ///< pixmap for unfocused title
284
FbTk::Color m_title_unfocused_color; ///< color for unfocued title
286
Pixmap m_label_focused_pm; ///< pixmap for focused label
287
FbTk::Color m_label_focused_color; ///< color for focused label
288
Pixmap m_label_unfocused_pm; ///< pixmap for unfocused label
289
FbTk::Color m_label_unfocused_color; ///< color for unfocued label
291
Pixmap m_labelbutton_focused_pm; ///< pixmap for focused label
292
FbTk::Color m_labelbutton_focused_color; ///< color for focused label
293
Pixmap m_labelbutton_unfocused_pm; ///< pixmap for unfocused label
294
FbTk::Color m_labelbutton_unfocused_color; ///< color for unfocued label
295
Pixmap m_labelbutton_active_pm; ///< pixmap for active label
296
FbTk::Color m_labelbutton_active_color; ///< color for active label
298
FbTk::Color m_handle_focused_color, m_handle_unfocused_color;
299
Pixmap m_handle_focused_pm, m_handle_unfocused_pm;
302
Pixmap m_button_pm; ///< normal button
303
FbTk::Color m_button_color; ///< normal color button
304
Pixmap m_button_unfocused_pm; ///< unfocused button
305
FbTk::Color m_button_unfocused_color; ///< unfocused color button
306
Pixmap m_button_pressed_pm; ///< pressed button
307
FbTk::Color m_button_pressed_color; ///< pressed button color
309
Pixmap m_grip_focused_pm;
310
FbTk::Color m_grip_focused_color; ///< if no pixmap is given for grip, use this color
311
Pixmap m_grip_unfocused_pm; ///< unfocused pixmap for grip
312
FbTk::Color m_grip_unfocused_color; ///< unfocused color for grip if no pixmap is given
318
int m_button_size; ///< size for all titlebar buttons
319
unsigned int m_width_before_shade, ///< width before shade, so we can restore it when we unshade
320
m_height_before_shade; ///< height before shade, so we can restore it when we unshade
321
bool m_shaded; ///< wheter we're shaded or not
322
unsigned int m_double_click_time; ///< the time period that's considerd to be a double click
323
struct MouseButtonAction {
324
FbTk::RefCount<FbTk::Command> click; ///< what to do when we release mouse button
325
FbTk::RefCount<FbTk::Command> click_pressed; ///< what to do when we press mouse button
326
FbTk::RefCount<FbTk::Command> double_click; ///< what to do when we double click
328
MouseButtonAction m_commands[5]; ///< hardcoded to five ... //!! TODO, change this
330
class ThemeListener: public FbTk::Observer {
332
ThemeListener(FbWinFrame &frame):m_frame(frame) { }
333
void update(FbTk::Subject *) {
334
m_frame.reconfigure();
339
ThemeListener m_themelistener;
340
std::auto_ptr<Shape> m_shape;
341
bool m_disable_shape;
345
#endif // FBWINFRAME_HH