]>
Commit | Line | Data |
---|---|---|
8e08b761 | 1 | ///////////////////////////////////////////////////////////////////////////// |
4cbc57f0 JS |
2 | // Name: toolwnd.h |
3 | // Purpose: wxToolWindow, cbMiniButton, cbCloseBox, cbCollapseBox, | |
4 | // cbDockBox, cbFloatedBarWindow class declarations. | |
8e08b761 JS |
5 | // Author: Aleksandras Gluchovas |
6 | // Modified by: | |
7 | // Created: 06/09/98 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) Aleksandras Gluchovas | |
4cbc57f0 | 10 | // Licence: wxWindows licence |
8e08b761 JS |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | #ifndef __TOOLWND_G__ | |
14 | #define __TOOLWND_G__ | |
15 | ||
16 | #ifdef __GNUG__ | |
17 | #pragma interface "toolwnd.h" | |
18 | #endif | |
19 | ||
20 | #include "wx/frame.h" | |
21 | #include "wx/dynarray.h" | |
22 | ||
23 | // fixed settings | |
24 | ||
25 | #define BTN_BOX_HEIGHT 12 | |
26 | #define BTN_BOX_WIDTH 12 | |
27 | #define BTN_X_WIEGHT 2 | |
28 | ||
29 | class cbMiniButton; | |
30 | ||
31 | typedef cbMiniButton* cbMinitButtonPtrT; | |
32 | ||
33 | WX_DEFINE_ARRAY( cbMinitButtonPtrT, cbMiniButtonArrayT ); | |
34 | ||
4cbc57f0 JS |
35 | /* |
36 | A tool window is a special kind of frame that paints its own title, and | |
37 | can be used to implement small floating windows. | |
38 | */ | |
39 | ||
8e08b761 JS |
40 | class wxToolWindow : public wxFrame |
41 | { | |
4cbc57f0 | 42 | DECLARE_DYNAMIC_CLASS( wxToolWindow ) |
8e08b761 | 43 | |
4cbc57f0 | 44 | public: /** protected really, accessed only by serializers **/ |
8e08b761 | 45 | |
4cbc57f0 JS |
46 | cbMiniButtonArrayT mButtons; |
47 | wxWindow* mpClientWnd; | |
8e08b761 | 48 | |
4cbc57f0 | 49 | wxFont mTitleFont; |
8e08b761 | 50 | |
4cbc57f0 JS |
51 | int mTitleHeight; |
52 | int mClntHorizGap; | |
53 | int mClntVertGap; | |
54 | int mWndVertGap; | |
55 | int mWndHorizGap; | |
56 | int mButtonGap; | |
57 | int mInTitleMargin; | |
58 | int mHintBorder; | |
8e08b761 | 59 | |
4cbc57f0 JS |
60 | bool mResizeStarted; |
61 | bool mRealTimeUpdatesOn; | |
8e08b761 | 62 | |
4cbc57f0 | 63 | int mMTolerance; |
8e08b761 | 64 | |
4cbc57f0 JS |
65 | int mCursorType; |
66 | bool mMouseCaptured; | |
8e08b761 | 67 | |
4cbc57f0 | 68 | // drag&drop state variables |
8e08b761 | 69 | |
4cbc57f0 JS |
70 | wxPoint mDragOrigin; |
71 | wxRect mInitialRect; | |
72 | wxRect mPrevHintRect; | |
73 | wxScreenDC* mpScrDc; | |
8e08b761 JS |
74 | |
75 | protected: | |
4cbc57f0 JS |
76 | // Maps client coordinates to screen coordinates. |
77 | void GetScrWindowRect( wxRect& r ); | |
78 | ||
79 | // Gets the mouse position in screen coordinates. | |
80 | void GetScrMousePos ( wxMouseEvent& event, wxPoint& pos ); | |
81 | ||
82 | // Sets the hint cursor. | |
83 | void SetHintCursor ( int type ); | |
8e08b761 | 84 | |
4cbc57f0 JS |
85 | // Calculate resized rectangle. |
86 | void CalcResizedRect( wxRect& rect, wxPoint& delta, const wxSize& minDim ); | |
8e08b761 | 87 | |
4cbc57f0 JS |
88 | // Helper function. |
89 | void AdjustRectPos( const wxRect& original, const wxSize& newDim, wxRect& newRect ); | |
8e08b761 | 90 | |
4cbc57f0 JS |
91 | // Helper function. |
92 | wxSize GetMinimalWndDim(); | |
8e08b761 | 93 | |
4cbc57f0 JS |
94 | // Draws the hint rectangle. |
95 | void DrawHintRect( const wxRect& r ); | |
96 | ||
97 | // Tests if the mouse position is in this window. | |
98 | int HitTestWindow( wxMouseEvent& event ); | |
99 | ||
100 | // Lays out the buttons. | |
101 | void LayoutMiniButtons(); | |
8e08b761 JS |
102 | |
103 | public: | |
8e08b761 | 104 | |
4cbc57f0 JS |
105 | // Default constructor. |
106 | wxToolWindow(); | |
107 | ||
108 | // Destructor. | |
109 | ~wxToolWindow(); | |
110 | ||
111 | // Sets the client for this tool window. | |
112 | void SetClient( wxWindow* pWnd ); | |
113 | ||
114 | // Returns the client window. | |
115 | wxWindow* GetClient(); | |
116 | ||
117 | // Sets the title font. | |
118 | void SetTitleFont( wxFont& font ); | |
119 | ||
120 | // Adds a button. Buttons are added in right-to-left order. | |
121 | void AddMiniButton( cbMiniButton* pBtn ); | |
122 | ||
123 | // Responds to a paint event. | |
124 | void OnPaint( wxPaintEvent& event ); | |
125 | ||
126 | // Responds to a mouse move event. | |
127 | void OnMotion( wxMouseEvent& event ); | |
8e08b761 | 128 | |
4cbc57f0 JS |
129 | // Responds to a mouse left down event. |
130 | void OnLeftDown( wxMouseEvent& event ); | |
8e08b761 | 131 | |
4cbc57f0 JS |
132 | // Responds to a mouse left up event. |
133 | void OnLeftUp( wxMouseEvent& event ); | |
8e08b761 | 134 | |
4cbc57f0 JS |
135 | // Responds to a size event. |
136 | void OnSize( wxSizeEvent& event ); | |
8e08b761 | 137 | |
4cbc57f0 JS |
138 | // Responds to an erase background event. |
139 | void OnEraseBackground( wxEraseEvent& event ); | |
8e08b761 | 140 | |
4cbc57f0 JS |
141 | // Returns the preferred size for the window. |
142 | virtual wxSize GetPreferredSize( const wxSize& given ); | |
8e08b761 | 143 | |
4cbc57f0 JS |
144 | // Called when a mini button is clicked. |
145 | // By default, does nothing. | |
146 | virtual void OnMiniButtonClicked( int btnIdx ) {} | |
8e08b761 | 147 | |
4cbc57f0 JS |
148 | // Handles clicking on the title. By default, does nothing. |
149 | virtual bool HandleTitleClick( wxMouseEvent& event ) { return FALSE; } | |
8e08b761 | 150 | |
4cbc57f0 | 151 | DECLARE_EVENT_TABLE() |
8e08b761 JS |
152 | }; |
153 | ||
154 | // FIXME:: the code below should be moved to a separate file | |
155 | ||
156 | #include "wx/fl/controlbar.h" | |
157 | ||
4cbc57f0 JS |
158 | /* |
159 | cbMiniButton is the base class for a small button that can be placed in a wxToolWindow | |
160 | titlebar. | |
161 | */ | |
162 | ||
8e08b761 JS |
163 | class cbMiniButton : public wxObject |
164 | { | |
165 | public: | |
4cbc57f0 JS |
166 | wxPoint mPos; |
167 | wxSize mDim; | |
168 | bool mVisible; | |
169 | bool mEnabled; | |
8e08b761 | 170 | |
4cbc57f0 JS |
171 | wxFrameLayout* mpLayout; |
172 | cbDockPane* mpPane; | |
173 | cbPluginBase* mpPlugin; | |
8e08b761 | 174 | |
4cbc57f0 | 175 | wxWindow* mpWnd; |
8e08b761 | 176 | |
4cbc57f0 JS |
177 | bool mWasClicked; |
178 | bool mDragStarted; | |
8e08b761 | 179 | |
4cbc57f0 | 180 | bool mPressed; |
8e08b761 | 181 | public: |
4cbc57f0 JS |
182 | // Default constructor. |
183 | cbMiniButton(); | |
184 | ||
185 | // Set the position of the button. | |
186 | void SetPos( const wxPoint& pos ); | |
187 | ||
188 | // Returns TRUE if the given position was over the button. | |
189 | bool HitTest( const wxPoint& pos ); | |
190 | ||
191 | // Responds to a left down event. | |
192 | void OnLeftDown( const wxPoint& pos ); | |
193 | ||
194 | // Responds to a left up event. | |
195 | void OnLeftUp( const wxPoint& pos ); | |
196 | ||
197 | // Responds to a mouse move event. | |
198 | void OnMotion( const wxPoint& pos ); | |
8e08b761 | 199 | |
4cbc57f0 JS |
200 | // Refreshes the button. |
201 | void Refresh(); | |
8e08b761 | 202 | |
4cbc57f0 JS |
203 | // Draws the button. Override this to implement |
204 | // the desired appearance. | |
205 | virtual void Draw( wxDC& dc ); | |
8e08b761 | 206 | |
4cbc57f0 JS |
207 | // Returns TRUE if the button was clicked. |
208 | bool WasClicked(); | |
8e08b761 | 209 | |
4cbc57f0 JS |
210 | // Reset the button. |
211 | void Reset(); | |
8e08b761 | 212 | |
4cbc57f0 JS |
213 | // Enable or disable the button. |
214 | void Enable( bool enable ) { mEnabled = enable; } | |
8e08b761 | 215 | |
4cbc57f0 JS |
216 | // Returns TRUE if this button is pressed. |
217 | bool IsPressed() { return mPressed; } | |
8e08b761 JS |
218 | }; |
219 | ||
4cbc57f0 JS |
220 | /* |
221 | cbCloseBox is a window close button, used in a wxToolWindow titlebar. | |
222 | */ | |
8e08b761 JS |
223 | |
224 | class cbCloseBox : public cbMiniButton | |
225 | { | |
226 | public: | |
4cbc57f0 JS |
227 | // Draws the close button appearance. |
228 | virtual void Draw( wxDC& dc ); | |
8e08b761 JS |
229 | }; |
230 | ||
4cbc57f0 JS |
231 | /* |
232 | cbCollapseBox is a window collapse button, used in a wxToolWindow titlebar. | |
233 | */ | |
234 | ||
8e08b761 JS |
235 | class cbCollapseBox : public cbMiniButton |
236 | { | |
237 | public: | |
4cbc57f0 | 238 | bool mIsAtLeft; |
8e08b761 | 239 | |
4cbc57f0 JS |
240 | // Draws the collapse button appearance. |
241 | virtual void Draw( wxDC& dc ); | |
8e08b761 JS |
242 | }; |
243 | ||
4cbc57f0 JS |
244 | /* |
245 | cbDockBox is a window dock button, used in a wxToolWindow titlebar. | |
246 | */ | |
247 | ||
8e08b761 JS |
248 | class cbDockBox : public cbMiniButton |
249 | { | |
250 | public: | |
4cbc57f0 JS |
251 | // Draws the dock button appearance. |
252 | virtual void Draw( wxDC& dc ); | |
8e08b761 JS |
253 | }; |
254 | ||
4cbc57f0 JS |
255 | /* |
256 | cbFloatedBarWindow is a kind of wxToolWindow, | |
257 | implementing floating toolbars. | |
258 | */ | |
259 | ||
8e08b761 JS |
260 | class cbFloatedBarWindow : public wxToolWindow |
261 | { | |
4cbc57f0 | 262 | DECLARE_DYNAMIC_CLASS( cbFloatedBarWindow ) |
8e08b761 | 263 | protected: |
4cbc57f0 JS |
264 | cbBarInfo* mpBar; |
265 | wxFrameLayout* mpLayout; | |
8e08b761 | 266 | |
4cbc57f0 | 267 | friend class cbFloatedBarWindowSerializer; |
8e08b761 JS |
268 | |
269 | public: | |
4cbc57f0 JS |
270 | // Default constructor. |
271 | cbFloatedBarWindow(); | |
272 | ||
273 | // Sets the bar information for this window. | |
274 | void SetBar( cbBarInfo* pBar ); | |
275 | ||
276 | // Sets the layout for this window. | |
277 | void SetLayout( wxFrameLayout* pLayout ); | |
8e08b761 | 278 | |
4cbc57f0 JS |
279 | // Returns the bar information for this window. |
280 | cbBarInfo* GetBar(); | |
8e08b761 | 281 | |
4cbc57f0 JS |
282 | // Position the floating window. The given coordinates |
283 | // are those of the bar itself; the floated container window's | |
284 | // position and size are ajusted accordingly. | |
285 | void PositionFloatedWnd( int scrX, int scrY, | |
286 | int width, int height ); | |
8e08b761 | 287 | |
4cbc57f0 JS |
288 | // Overridden function returning the preferred size. |
289 | virtual wxSize GetPreferredSize( const wxSize& given ); | |
8e08b761 | 290 | |
4cbc57f0 JS |
291 | // Overridden function responding to mouse clicks on mini-buttons. |
292 | virtual void OnMiniButtonClicked( int btnIdx ); | |
8e08b761 | 293 | |
4cbc57f0 JS |
294 | // Overridden function responding to mouse button clicks on the titlebar. |
295 | virtual bool HandleTitleClick( wxMouseEvent& event ); | |
8e08b761 | 296 | |
4cbc57f0 JS |
297 | // Responds to double-click mouse events. |
298 | void OnDblClick( wxMouseEvent& event ); | |
8e08b761 | 299 | |
4cbc57f0 | 300 | DECLARE_EVENT_TABLE() |
8e08b761 JS |
301 | }; |
302 | ||
303 | #endif /* __TOOLWND_G__ */ | |
304 | ||
305 |