1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
13 #include "backgroundwidget.hh"
14 #include "labelwidget.hh"
15 #include "buttonwidget.hh"
16 #include "otk/strut.hh"
17 #include "otk/rect.hh"
18 #include "otk/screeninfo.hh"
19 #include "otk/style.hh"
20 #include "otk/widget.hh"
26 //! Holds and decorates a frame around an OBClient (client window)
28 The frame is responsible for calling XSelectInput on the client window's new
29 parent with the SubstructureRedirectMask so that structure events for the
30 client are sent to the window manager.
32 class OBFrame
: public otk::OtkWidget
, public OBWidget
{
35 //! The event mask to grab on frame windows
36 static const long event_mask
= EnterWindowMask
| LeaveWindowMask
|
37 ButtonPressMask
| ButtonReleaseMask
|
42 const otk::ScreenInfo
*_screen
;
44 //! The style to use for size and display the decorations
47 //! The size of the frame on each side of the client window
50 //! The size of the frame on each side of the client window inside the border
51 otk::Strut _innersize
;
54 OBBackgroundWidget _plate
; // sits entirely under the client window
55 OBBackgroundWidget _titlebar
;
56 OBButtonWidget _button_close
;
57 OBButtonWidget _button_iconify
;
58 OBButtonWidget _button_max
;
59 OBButtonWidget _button_stick
;
61 OBBackgroundWidget _handle
;
62 OBButtonWidget _grip_left
;
63 OBButtonWidget _grip_right
;
65 //! The decorations to display on the window.
67 This is by default the same value as in the OBClient::decorations, but it
68 is duplicated here so that it can be overridden per-window by the user.
70 OBClient::DecorationFlags _decorations
;
72 //! Reparents the client window from the root window onto the frame
74 //! Reparents the client window back to the root window
76 @param remap Re-map the client window when we're done reparenting?
78 void releaseClient(bool remap
);
80 //! Shape the frame window to the client window
83 //! Grabs or ungrabs buttons on the frame
84 void grabButtons(bool grab
);
87 //! Constructs an OBFrame object, and reparents the client to itself
89 @param client The client window which will be decorated by the new OBFrame
90 @param style The style to use to decorate the frame
92 OBFrame(OBClient
*client
, otk::Style
*style
);
93 //! Destroys the OBFrame object
96 //! Set the style to decorate the frame with
97 virtual void setStyle(otk::Style
*style
);
99 //! Empty overridden method to prevent automatic alignment of children
100 virtual void adjust();
102 //! Displays focused decorations
103 virtual void focus();
104 //! Displays unfocused decorations
105 virtual void unfocus();
107 void setTitle(const std::string
&text
);
109 //! Update the frame's size to match the client
111 //! Update the frame's position to match the client
112 void adjustPosition();
114 //! Applies gravity to the client's position to find where the frame should
117 @return The proper coordinates for the frame, based on the client.
119 void clientGravity(int &x
, int &y
);
121 //! Reversly applies gravity to the frame's position to find where the client
122 //! should be positioned.
124 @return The proper coordinates for the client, based on the frame.
126 void frameGravity(int &x
, int &y
);
128 //! Gets the window id of the frame's "plate" subelement
129 inline Window
plate() const { return _plate
.window(); }
130 //! Gets the window id of the frame's "titlebar" subelement
131 inline Window
titlebar() const { return _titlebar
.window(); }
132 //! Gets the window id of the frame's "label" subelement
133 inline Window
label() const { return _label
.window(); }
134 //! Gets the window id of the frame's "close button" subelement
135 inline Window
button_close() const { return _button_close
.window(); }
136 //! Gets the window id of the frame's "iconify button" subelement
137 inline Window
button_iconify() const { return _button_iconify
.window(); }
138 //! Gets the window id of the frame's "maximize button" subelement
139 inline Window
button_max() const { return _button_max
.window(); }
140 //! Gets the window id of the frame's "sticky button" subelement
141 inline Window
button_stick() const { return _button_stick
.window(); }
142 //! Gets the window id of the frame's "handle" subelement
143 inline Window
handle() const { return _handle
.window(); }
144 //! Gets the window id of the frame's "left grip" subelement
145 inline Window
grip_left() const { return _grip_left
.window(); }
146 //! Gets the window id of the frame's "right grip" subelement
147 inline Window
grip_right() const { return _grip_right
.window(); }