~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/FbWinFrame.hh

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// FbWinFrame.hh for Fluxbox Window Manager
2
 
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
 
//
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:
10
 
//
11
 
// The above copyright notice and this permission notice shall be included in
12
 
// all copies or substantial portions of the Software.
13
 
//
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.
21
 
 
22
 
// $Id: FbWinFrame.hh 4058 2005-06-19 12:12:54Z simonb $
23
 
 
24
 
#ifndef FBWINFRAME_HH
25
 
#define FBWINFRAME_HH
26
 
 
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"
34
 
 
35
 
#include <vector>
36
 
#include <list>
37
 
#include <string>
38
 
#include <memory>
39
 
 
40
 
class Shape;
41
 
class FbWinFrameTheme;
42
 
 
43
 
namespace FbTk {
44
 
class TextButton;
45
 
class ImageControl;
46
 
class Command;
47
 
class Button;
48
 
class Texture;
49
 
}
50
 
 
51
 
/// holds a window frame with a client window
52
 
/// (see: <a href="fluxbox_fbwinframe.png">image</a>)
53
 
class FbWinFrame:public FbTk::EventHandler {
54
 
public:
55
 
    enum TabMode { INTERNAL = 1, EXTERNAL };
56
 
 
57
 
    typedef FbTk::TextButton *ButtonId; ///< defines a button id 
58
 
 
59
 
    /// create a top level window
60
 
    FbWinFrame(FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl,
61
 
               int x, int y,
62
 
               unsigned int width, unsigned int height);
63
 
 
64
 
    /// create a frame window inside another FbWindow, NOT IMPLEMENTED!
65
 
    FbWinFrame(FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl, 
66
 
               const FbTk::FbWindow &parent,
67
 
               int x, int y, 
68
 
               unsigned int width, unsigned int height);
69
 
 
70
 
    /// destroy frame
71
 
    ~FbWinFrame();
72
 
 
73
 
    /// setup actions for titlebar
74
 
    bool setOnClickTitlebar(FbTk::RefCount<FbTk::Command> &cmd, int button_num,
75
 
                            bool double_click=false, bool pressed=false);
76
 
 
77
 
    void hide();
78
 
    void show();
79
 
    inline bool isVisible() const { return m_visible; }
80
 
    /// shade frame (ie resize to titlebar size)
81
 
    void shade();
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);
86
 
 
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);
91
 
 
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);
96
 
 
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);
100
 
    void clearAll();
101
 
 
102
 
    /// set focus/unfocus style
103
 
    void setFocus(bool newvalue);
104
 
    void setDoubleClickTime(unsigned int time);
105
 
 
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
132
 
    void removeClient();
133
 
    /// redirect events to another eventhandler
134
 
    void setEventHandler(FbTk::EventHandler &evh);
135
 
    /// remove any handler for the windows
136
 
    void removeEventHandler();
137
 
 
138
 
    // these return true/false for if something changed
139
 
    bool hideTitlebar();
140
 
    bool showTitlebar();
141
 
    bool hideHandle();
142
 
    bool showHandle();
143
 
    bool hideAllDecorations();
144
 
    bool showAllDecorations();
145
 
 
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);
152
 
 
153
 
    /**
154
 
       @name Event handlers
155
 
    */
156
 
    //@{
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);
162
 
    //@}
163
 
 
164
 
    void reconfigure();
165
 
    void setUseShape(bool value);
166
 
 
167
 
    /**
168
 
       @name accessors
169
 
    */
170
 
    //@{
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;
200
 
 
201
 
    //@}
202
 
 
203
 
private:
204
 
    void redrawTitlebar();
205
 
 
206
 
    /// reposition titlebar items
207
 
    void reconfigureTitlebar();
208
 
    /**
209
 
       @name render helper functions
210
 
    */
211
 
    //@{
212
 
    void renderAll();
213
 
    void renderTitlebar();
214
 
    void renderHandles();
215
 
    void renderLabelButtons();
216
 
 
217
 
    void renderButtons(); // subset of renderTitlebar - don't call directly
218
 
 
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);
222
 
 
223
 
    //@}
224
 
 
225
 
    /**
226
 
       @name apply pixmaps depending on focus
227
 
    */
228
 
    //@{
229
 
    void applyAll();
230
 
    void applyTitlebar();
231
 
    void applyHandles();
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
237
 
 
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);
242
 
 
243
 
    /// initiate inserted button for current theme
244
 
    void applyButton(FbTk::Button &btn);
245
 
    //@}
246
 
 
247
 
    /// initiate some commont variables
248
 
    void init();
249
 
 
250
 
    FbWinFrameTheme &m_theme; ///< theme to be used 
251
 
    FbTk::ImageControl &m_imagectrl; ///< Image control for rendering
252
 
    /**
253
 
       @name windows
254
 
    */
255
 
    //@{
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
264
 
    //@}
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
276
 
 
277
 
    /**
278
 
       @name pixmaps and colors for rendering
279
 
    */
280
 
    //@{
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
285
 
 
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
290
 
 
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
297
 
    
298
 
    FbTk::Color m_handle_focused_color, m_handle_unfocused_color;
299
 
    Pixmap m_handle_focused_pm, m_handle_unfocused_pm;
300
 
    
301
 
 
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
308
 
 
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
313
 
    //@}
314
 
 
315
 
    TabMode m_tabmode;
316
 
 
317
 
    bool m_need_render;
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
327
 
    };
328
 
    MouseButtonAction m_commands[5]; ///< hardcoded to five ... //!! TODO, change this
329
 
 
330
 
    class ThemeListener: public FbTk::Observer {
331
 
    public:
332
 
        ThemeListener(FbWinFrame &frame):m_frame(frame) { }
333
 
        void update(FbTk::Subject *) {
334
 
            m_frame.reconfigure();
335
 
        }
336
 
    private:
337
 
        FbWinFrame &m_frame;
338
 
    };
339
 
    ThemeListener m_themelistener;
340
 
    std::auto_ptr<Shape> m_shape;
341
 
    bool m_disable_shape;
342
 
 
343
 
};
344
 
 
345
 
#endif // FBWINFRAME_HH