]>
Commit | Line | Data |
---|---|---|
f03fc89f | 1 | /////////////////////////////////////////////////////////////////////////////// |
23895080 | 2 | // Name: wx/window.h |
789295bf | 3 | // Purpose: wxWindowBase class - the interface of wxWindow |
f03fc89f | 4 | // Author: Vadim Zeitlin |
566d84a7 | 5 | // Modified by: Ron Lee |
f03fc89f VZ |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWindows team | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_WINDOW_H_BASE_ |
13 | #define _WX_WINDOW_H_BASE_ | |
c801d85f | 14 | |
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
58654ed0 VZ |
16 | #pragma interface "windowbase.h" |
17 | #endif | |
18 | ||
f03fc89f VZ |
19 | // ---------------------------------------------------------------------------- |
20 | // headers which we must include here | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | #include "wx/event.h" // the base class | |
24 | ||
25 | #include "wx/list.h" // defines wxWindowList | |
26 | ||
27 | #include "wx/cursor.h" // we have member variables of these classes | |
28 | #include "wx/font.h" // so we can't do without them | |
29 | #include "wx/colour.h" | |
30 | #include "wx/region.h" | |
5e4ff78a | 31 | #include "wx/utils.h" |
88ac883a | 32 | |
674ac8b9 | 33 | #include "wx/validate.h" // for wxDefaultValidator (always include it) |
8d99be5f | 34 | |
574c939e | 35 | #if wxUSE_PALETTE |
d577d610 | 36 | #include "wx/palette.h" |
574c939e KB |
37 | #endif // wxUSE_PALETTE |
38 | ||
88ac883a VZ |
39 | #if wxUSE_ACCEL |
40 | #include "wx/accel.h" | |
41 | #endif // wxUSE_ACCEL | |
f03fc89f | 42 | |
45a959a3 JS |
43 | #if wxUSE_ACCESSIBILITY |
44 | #include "wx/access.h" | |
45 | #endif | |
46 | ||
6522713c VZ |
47 | // when building wxUniv/Foo we don't want the code for native menu use to be |
48 | // compiled in - it should only be used when building real wxFoo | |
49 | #ifdef __WXUNIVERSAL__ | |
50 | #define wxUSE_MENUS_NATIVE 0 | |
51 | #else // __WXMSW__ | |
52 | #define wxUSE_MENUS_NATIVE wxUSE_MENUS | |
53 | #endif // __WXUNIVERSAL__/__WXMSW__ | |
54 | ||
f03fc89f VZ |
55 | // ---------------------------------------------------------------------------- |
56 | // forward declarations | |
57 | // ---------------------------------------------------------------------------- | |
58 | ||
789295bf | 59 | class WXDLLEXPORT wxCaret; |
f03fc89f VZ |
60 | class WXDLLEXPORT wxControl; |
61 | class WXDLLEXPORT wxCursor; | |
eb082a08 | 62 | class WXDLLEXPORT wxDC; |
f03fc89f VZ |
63 | class WXDLLEXPORT wxDropTarget; |
64 | class WXDLLEXPORT wxItemResource; | |
65 | class WXDLLEXPORT wxLayoutConstraints; | |
66 | class WXDLLEXPORT wxResourceTable; | |
67 | class WXDLLEXPORT wxSizer; | |
68 | class WXDLLEXPORT wxToolTip; | |
f03fc89f VZ |
69 | class WXDLLEXPORT wxWindowBase; |
70 | class WXDLLEXPORT wxWindow; | |
71 | ||
45a959a3 JS |
72 | #if wxUSE_ACCESSIBILITY |
73 | class WXDLLEXPORT wxAccessible; | |
74 | #endif | |
75 | ||
f03fc89f VZ |
76 | // ---------------------------------------------------------------------------- |
77 | // (pseudo)template list classes | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
f6bcfd97 | 80 | WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT); |
f03fc89f VZ |
81 | |
82 | // ---------------------------------------------------------------------------- | |
83 | // global variables | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows; | |
87 | ||
f03fc89f VZ |
88 | // ---------------------------------------------------------------------------- |
89 | // wxWindowBase is the base class for all GUI controls/widgets, this is the public | |
90 | // interface of this class. | |
91 | // | |
92 | // Event handler: windows have themselves as their event handlers by default, | |
93 | // but their event handlers could be set to another object entirely. This | |
94 | // separation can reduce the amount of derivation required, and allow | |
95 | // alteration of a window's functionality (e.g. by a resource editor that | |
96 | // temporarily switches event handlers). | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
99 | class WXDLLEXPORT wxWindowBase : public wxEvtHandler | |
100 | { | |
f03fc89f VZ |
101 | public: |
102 | // creating the window | |
103 | // ------------------- | |
104 | ||
06f6df7d VZ |
105 | // default ctor, initializes everything which can be initialized before |
106 | // Create() | |
6463b9f5 | 107 | wxWindowBase() ; |
f03fc89f VZ |
108 | |
109 | // pseudo ctor (can't be virtual, called from ctor) | |
110 | bool CreateBase(wxWindowBase *parent, | |
d9e2e4c2 | 111 | wxWindowID winid, |
f03fc89f VZ |
112 | const wxPoint& pos = wxDefaultPosition, |
113 | const wxSize& size = wxDefaultSize, | |
114 | long style = 0, | |
8d99be5f | 115 | const wxValidator& validator = wxDefaultValidator, |
f03fc89f VZ |
116 | const wxString& name = wxPanelNameStr); |
117 | ||
118 | virtual ~wxWindowBase(); | |
119 | ||
f03fc89f VZ |
120 | // deleting the window |
121 | // ------------------- | |
122 | ||
d4864e97 | 123 | // ask the window to close itself, return true if the event handler |
f03fc89f | 124 | // honoured our request |
d4864e97 | 125 | bool Close( bool force = false ); |
f03fc89f VZ |
126 | |
127 | // the following functions delete the C++ objects (the window itself | |
128 | // or its children) as well as the GUI windows and normally should | |
129 | // never be used directly | |
130 | ||
d4864e97 | 131 | // delete window unconditionally (dangerous!), returns true if ok |
f03fc89f | 132 | virtual bool Destroy(); |
d4864e97 | 133 | // delete all children of this window, returns true if ok |
f03fc89f VZ |
134 | bool DestroyChildren(); |
135 | ||
136 | // is the window being deleted? | |
137 | bool IsBeingDeleted() const { return m_isBeingDeleted; } | |
138 | ||
139 | // window attributes | |
140 | // ----------------- | |
141 | ||
456bc6d9 VZ |
142 | // NB: in future versions of wxWindows Set/GetTitle() will only work |
143 | // with the top level windows (such as dialogs and frames) and | |
144 | // Set/GetLabel() only with the other ones (i.e. all controls). | |
145 | ||
f03fc89f VZ |
146 | // the title (or label, see below) of the window: the text which the |
147 | // window shows | |
fe6b43a3 VS |
148 | virtual void SetTitle( const wxString& WXUNUSED(title) ) {} |
149 | virtual wxString GetTitle() const { return wxEmptyString; } | |
f03fc89f VZ |
150 | |
151 | // label is just the same as the title (but for, e.g., buttons it | |
152 | // makes more sense to speak about labels) | |
eba0e4d4 RR |
153 | virtual void SetLabel(const wxString& label) { SetTitle(label); } |
154 | virtual wxString GetLabel() const { return GetTitle(); } | |
f03fc89f VZ |
155 | |
156 | // the window name is used for ressource setting in X, it is not the | |
157 | // same as the window title/label | |
158 | virtual void SetName( const wxString &name ) { m_windowName = name; } | |
159 | virtual wxString GetName() const { return m_windowName; } | |
160 | ||
161 | // window id uniquely identifies the window among its siblings unless | |
162 | // it is -1 which means "don't care" | |
d9e2e4c2 | 163 | void SetId( wxWindowID winid ) { m_windowId = winid; } |
f03fc89f VZ |
164 | wxWindowID GetId() const { return m_windowId; } |
165 | ||
166 | // generate a control id for the controls which were not given one by | |
167 | // user | |
69418a8e | 168 | static int NewControlId() { return --ms_lastControlId; } |
c539ab55 VZ |
169 | // get the id of the control following the one with the given |
170 | // (autogenerated) id | |
d9e2e4c2 | 171 | static int NextControlId(int winid) { return winid - 1; } |
c539ab55 VZ |
172 | // get the id of the control preceding the one with the given |
173 | // (autogenerated) id | |
d9e2e4c2 | 174 | static int PrevControlId(int winid) { return winid + 1; } |
f03fc89f VZ |
175 | |
176 | // moving/resizing | |
177 | // --------------- | |
178 | ||
179 | // set the window size and/or position | |
180 | void SetSize( int x, int y, int width, int height, | |
181 | int sizeFlags = wxSIZE_AUTO ) | |
182 | { DoSetSize(x, y, width, height, sizeFlags); } | |
183 | ||
184 | void SetSize( int width, int height ) | |
185 | { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); } | |
186 | ||
187 | void SetSize( const wxSize& size ) | |
188 | { SetSize( size.x, size.y); } | |
189 | ||
190 | void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO) | |
191 | { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); } | |
192 | ||
1e6feb95 VZ |
193 | void Move(int x, int y, int flags = wxSIZE_USE_EXISTING) |
194 | { DoSetSize(x, y, -1, -1, flags); } | |
f03fc89f | 195 | |
1e6feb95 VZ |
196 | void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING) |
197 | { Move(pt.x, pt.y, flags); } | |
f03fc89f VZ |
198 | |
199 | // Z-order | |
200 | virtual void Raise() = 0; | |
201 | virtual void Lower() = 0; | |
202 | ||
203 | // client size is the size of area available for subwindows | |
204 | void SetClientSize( int width, int height ) | |
205 | { DoSetClientSize(width, height); } | |
206 | ||
207 | void SetClientSize( const wxSize& size ) | |
208 | { DoSetClientSize(size.x, size.y); } | |
209 | ||
210 | void SetClientSize(const wxRect& rect) | |
211 | { SetClientSize( rect.width, rect.height ); } | |
212 | ||
213 | // get the window position and/or size (pointers may be NULL) | |
214 | void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); } | |
215 | wxPoint GetPosition() const | |
216 | { | |
217 | int w, h; | |
218 | DoGetPosition(&w, &h); | |
219 | ||
220 | return wxPoint(w, h); | |
221 | } | |
222 | ||
311a173b | 223 | void SetPosition( const wxPoint& pt ) { Move( pt ) ; } |
38759b67 | 224 | |
f03fc89f VZ |
225 | void GetSize( int *w, int *h ) const { DoGetSize(w, h); } |
226 | wxSize GetSize() const | |
227 | { | |
228 | int w, h; | |
229 | DoGetSize(& w, & h); | |
230 | return wxSize(w, h); | |
231 | } | |
232 | ||
233 | wxRect GetRect() const | |
234 | { | |
235 | int x, y, w, h; | |
236 | GetPosition(& x, & y); | |
237 | GetSize(& w, & h); | |
238 | ||
239 | return wxRect(x, y, w, h); | |
240 | } | |
241 | ||
242 | void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); } | |
243 | wxSize GetClientSize() const | |
244 | { | |
245 | int w, h; | |
246 | DoGetClientSize(& w, & h); | |
247 | ||
248 | return wxSize(w, h); | |
249 | } | |
250 | ||
1e6feb95 VZ |
251 | // get the origin of the client area of the window relative to the |
252 | // window top left corner (the client area may be shifted because of | |
253 | // the borders, scrollbars, other decorations...) | |
254 | virtual wxPoint GetClientAreaOrigin() const; | |
255 | ||
256 | // get the client rectangle in window (i.e. client) coordinates | |
257 | wxRect GetClientRect() const | |
258 | { | |
259 | return wxRect(GetClientAreaOrigin(), GetClientSize()); | |
260 | } | |
261 | ||
f68586e5 VZ |
262 | // get the size best suited for the window (in fact, minimal |
263 | // acceptable size using which it will still look "nice") | |
264 | wxSize GetBestSize() const { return DoGetBestSize(); } | |
265 | void GetBestSize(int *w, int *h) const | |
266 | { | |
267 | wxSize s = DoGetBestSize(); | |
268 | if ( w ) | |
269 | *w = s.x; | |
270 | if ( h ) | |
271 | *h = s.y; | |
272 | } | |
273 | ||
2b5f62a0 VZ |
274 | // There are times (and windows) where 'Best' size and 'Min' size |
275 | // are vastly out of sync. This should be remedied somehow, but in | |
276 | // the meantime, this method will return the larger of BestSize | |
277 | // (the window's smallest legible size), and any user specified | |
278 | // MinSize hint. | |
279 | wxSize GetAdjustedBestSize() const | |
280 | { | |
281 | wxSize s( DoGetBestSize() ); | |
282 | return wxSize( wxMax( s.x, GetMinWidth() ), wxMax( s.y, GetMinHeight() ) ); | |
283 | } | |
284 | ||
285 | // the generic centre function - centers the window on parent by` | |
7eb4e9cc VZ |
286 | // default or on screen if it doesn't have parent or |
287 | // wxCENTER_ON_SCREEN flag is given | |
c39eda94 VZ |
288 | void Centre( int direction = wxBOTH ); |
289 | void Center( int direction = wxBOTH ) { Centre(direction); } | |
7eb4e9cc VZ |
290 | |
291 | // centre on screen (only works for top level windows) | |
292 | void CentreOnScreen(int dir = wxBOTH) { Centre(dir | wxCENTER_ON_SCREEN); } | |
293 | void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); } | |
294 | ||
295 | // centre with respect to the the parent window | |
296 | void CentreOnParent(int dir = wxBOTH) { Centre(dir | wxCENTER_FRAME); } | |
297 | void CenterOnParent(int dir = wxBOTH) { CentreOnParent(dir); } | |
f03fc89f VZ |
298 | |
299 | // set window size to wrap around its children | |
300 | virtual void Fit(); | |
301 | ||
2b5f62a0 VZ |
302 | // set virtual size to satisfy children |
303 | virtual void FitInside(); | |
304 | ||
f03fc89f VZ |
305 | // set min/max size of the window |
306 | virtual void SetSizeHints( int minW, int minH, | |
307 | int maxW = -1, int maxH = -1, | |
308 | int incW = -1, int incH = -1 ); | |
309 | ||
566d84a7 RL |
310 | virtual void SetVirtualSizeHints( int minW, int minH, |
311 | int maxW = -1, int maxH = -1 ); | |
312 | ||
e7dda1ff VS |
313 | virtual int GetMinWidth() const { return m_minWidth; } |
314 | virtual int GetMinHeight() const { return m_minHeight; } | |
738f9e5a RR |
315 | int GetMaxWidth() const { return m_maxWidth; } |
316 | int GetMaxHeight() const { return m_maxHeight; } | |
57c4d796 | 317 | |
34c3ffca RL |
318 | // Override this method to control the values given to Sizers etc. |
319 | virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); } | |
320 | ||
566d84a7 RL |
321 | // Methods for accessing the virtual size of a window. For most |
322 | // windows this is just the client area of the window, but for | |
323 | // some like scrolled windows it is more or less independent of | |
324 | // the screen window size. You may override the DoXXXVirtual | |
325 | // methods below for classes where that is is the case. | |
326 | ||
327 | void SetVirtualSize( const wxSize &size ) { DoSetVirtualSize( size.x, size.y ); } | |
328 | void SetVirtualSize( int x, int y ) { DoSetVirtualSize( x, y ); } | |
329 | ||
330 | wxSize GetVirtualSize() const { return DoGetVirtualSize(); } | |
331 | void GetVirtualSize( int *x, int *y ) const | |
332 | { | |
333 | wxSize s( DoGetVirtualSize() ); | |
334 | ||
335 | if( x ) | |
336 | *x = s.GetWidth(); | |
337 | if( y ) | |
338 | *y = s.GetHeight(); | |
339 | } | |
340 | ||
341 | // Override these methods for windows that have a virtual size | |
342 | // independent of their client size. eg. the virtual area of a | |
343 | // wxScrolledWindow. Default is to alias VirtualSize to ClientSize. | |
344 | ||
345 | virtual void DoSetVirtualSize( int x, int y ); | |
346 | virtual wxSize DoGetVirtualSize() const; // { return m_virtualSize; } | |
347 | ||
2b5f62a0 VZ |
348 | // Return the largest of ClientSize and BestSize (as determined |
349 | // by a sizer, interior children, or other means) | |
350 | ||
351 | virtual wxSize GetBestVirtualSize() const | |
352 | { | |
353 | wxSize client( GetClientSize() ); | |
354 | wxSize best( GetBestSize() ); | |
355 | ||
356 | return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) ); | |
357 | } | |
358 | ||
f03fc89f VZ |
359 | // window state |
360 | // ------------ | |
361 | ||
d4864e97 | 362 | // returns true if window was shown/hidden, false if the nothing was |
f03fc89f | 363 | // done (window was already shown/hidden) |
d4864e97 VZ |
364 | virtual bool Show( bool show = true ); |
365 | bool Hide() { return Show(false); } | |
f03fc89f | 366 | |
d4864e97 VZ |
367 | // returns true if window was enabled/disabled, false if nothing done |
368 | virtual bool Enable( bool enable = true ); | |
369 | bool Disable() { return Enable(false); } | |
f03fc89f VZ |
370 | |
371 | bool IsShown() const { return m_isShown; } | |
372 | bool IsEnabled() const { return m_isEnabled; } | |
373 | ||
374 | // get/set window style (setting style won't update the window and so | |
375 | // is only useful for internal usage) | |
376 | virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; } | |
377 | virtual long GetWindowStyleFlag() const { return m_windowStyle; } | |
378 | ||
379 | // just some (somewhat shorter) synonims | |
380 | void SetWindowStyle( long style ) { SetWindowStyleFlag(style); } | |
381 | long GetWindowStyle() const { return GetWindowStyleFlag(); } | |
382 | ||
383 | bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; } | |
d80cd92a | 384 | virtual bool IsRetained() const { return HasFlag(wxRETAINED); } |
f03fc89f | 385 | |
d80cd92a VZ |
386 | // extra style: the less often used style bits which can't be set with |
387 | // SetWindowStyleFlag() | |
b2d5a7ee | 388 | virtual void SetExtraStyle(long exStyle) { m_exStyle = exStyle; } |
d80cd92a | 389 | long GetExtraStyle() const { return m_exStyle; } |
f03fc89f VZ |
390 | |
391 | // make the window modal (all other windows unresponsive) | |
d4864e97 | 392 | virtual void MakeModal(bool modal = true); |
f03fc89f | 393 | |
a2d93e73 JS |
394 | virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; } |
395 | virtual bool GetThemeEnabled() const { return m_themeEnabled; } | |
396 | ||
bd507486 RD |
397 | // Returns true if this class should have the background colour |
398 | // changed to match the parent window's theme. For example when a | |
399 | // page is added to a notebook it and it's children may need to have | |
400 | // the colours adjusted depending on the current theme settings, but | |
401 | // not all windows/controls can do this without looking wrong. | |
cc0bffac RD |
402 | virtual void ApplyParentThemeBackground(const wxColour& WXUNUSED(bg)) |
403 | { /* do nothing */ } | |
bd507486 | 404 | |
d4864e97 VZ |
405 | // returns true if this window should inherit its parent colours on |
406 | // creation | |
407 | virtual bool ShouldInheritColours() const { return false; } | |
408 | ||
409 | ||
456bc6d9 VZ |
410 | // focus and keyboard handling |
411 | // --------------------------- | |
f03fc89f VZ |
412 | |
413 | // set focus to this window | |
414 | virtual void SetFocus() = 0; | |
415 | ||
d577d610 VZ |
416 | // set focus to this window as the result of a keyboard action |
417 | virtual void SetFocusFromKbd() { SetFocus(); } | |
418 | ||
f03fc89f VZ |
419 | // return the window which currently has the focus or NULL |
420 | static wxWindow *FindFocus() /* = 0: implement in derived classes */; | |
421 | ||
422 | // can this window have focus? | |
423 | virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); } | |
424 | ||
1e6feb95 VZ |
425 | // can this window be given focus by keyboard navigation? if not, the |
426 | // only way to give it focus (provided it accepts it at all) is to | |
427 | // click it | |
428 | virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); } | |
429 | ||
456bc6d9 VZ |
430 | // NB: these methods really don't belong here but with the current |
431 | // class hierarchy there is no other place for them :-( | |
432 | ||
433 | // get the default child of this parent, i.e. the one which is | |
434 | // activated by pressing <Enter> | |
435 | virtual wxWindow *GetDefaultItem() const { return NULL; } | |
436 | ||
437 | // set this child as default, return the old default | |
438 | virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child)) | |
439 | { return NULL; } | |
440 | ||
036da5e3 VZ |
441 | // set this child as temporary default |
442 | virtual void SetTmpDefaultItem(wxWindow * WXUNUSED(win)) { } | |
443 | ||
f03fc89f VZ |
444 | // parent/children relations |
445 | // ------------------------- | |
446 | ||
447 | // get the list of children | |
448 | const wxWindowList& GetChildren() const { return m_children; } | |
449 | wxWindowList& GetChildren() { return m_children; } | |
450 | ||
1978421a SC |
451 | // needed just for extended runtime |
452 | const wxWindowList& GetWindowChildren() const { return GetChildren() ; } | |
453 | ||
f03fc89f VZ |
454 | // get the parent or the parent of the parent |
455 | wxWindow *GetParent() const { return m_parent; } | |
456 | inline wxWindow *GetGrandParent() const; | |
457 | ||
458 | // is this window a top level one? | |
8487f887 | 459 | virtual bool IsTopLevel() const; |
f03fc89f VZ |
460 | |
461 | // it doesn't really change parent, use ReParent() instead | |
462 | void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; } | |
d4864e97 VZ |
463 | // change the real parent of this window, return true if the parent |
464 | // was changed, false otherwise (error or newParent == oldParent) | |
f03fc89f VZ |
465 | virtual bool Reparent( wxWindowBase *newParent ); |
466 | ||
146ba0fe VZ |
467 | // implementation mostly |
468 | virtual void AddChild( wxWindowBase *child ); | |
469 | virtual void RemoveChild( wxWindowBase *child ); | |
470 | ||
471 | // looking for windows | |
472 | // ------------------- | |
473 | ||
f03fc89f VZ |
474 | // find window among the descendants of this one either by id or by |
475 | // name (return NULL if not found) | |
d9e2e4c2 | 476 | wxWindow *FindWindow( long winid ); |
f03fc89f VZ |
477 | wxWindow *FindWindow( const wxString& name ); |
478 | ||
146ba0fe | 479 | // Find a window among any window (all return NULL if not found) |
d9e2e4c2 | 480 | static wxWindow *FindWindowById( long winid, const wxWindow *parent = NULL ); |
146ba0fe VZ |
481 | static wxWindow *FindWindowByName( const wxString& name, |
482 | const wxWindow *parent = NULL ); | |
483 | static wxWindow *FindWindowByLabel( const wxString& label, | |
484 | const wxWindow *parent = NULL ); | |
f03fc89f VZ |
485 | |
486 | // event handler stuff | |
487 | // ------------------- | |
488 | ||
489 | // get the current event handler | |
490 | wxEvtHandler *GetEventHandler() const { return m_eventHandler; } | |
491 | ||
492 | // replace the event handler (allows to completely subclass the | |
493 | // window) | |
494 | void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; } | |
495 | ||
496 | // push/pop event handler: allows to chain a custom event handler to | |
497 | // alreasy existing ones | |
498 | void PushEventHandler( wxEvtHandler *handler ); | |
d4864e97 | 499 | wxEvtHandler *PopEventHandler( bool deleteHandler = false ); |
f03fc89f | 500 | |
2e36d5cf | 501 | // find the given handler in the event handler chain and remove (but |
d4864e97 VZ |
502 | // not delete) it from the event handler chain, return true if it was |
503 | // found and false otherwise (this also results in an assert failure so | |
2e36d5cf VZ |
504 | // this function should only be called when the handler is supposed to |
505 | // be there) | |
506 | bool RemoveEventHandler(wxEvtHandler *handler); | |
507 | ||
1e6feb95 VZ |
508 | // validators |
509 | // ---------- | |
f03fc89f | 510 | |
88ac883a | 511 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
512 | // a window may have an associated validator which is used to control |
513 | // user input | |
514 | virtual void SetValidator( const wxValidator &validator ); | |
515 | virtual wxValidator *GetValidator() { return m_windowValidator; } | |
88ac883a | 516 | #endif // wxUSE_VALIDATORS |
f03fc89f | 517 | |
f03fc89f VZ |
518 | |
519 | // dialog oriented functions | |
520 | // ------------------------- | |
521 | ||
d4864e97 | 522 | // validate the correctness of input, return true if ok |
f03fc89f VZ |
523 | virtual bool Validate(); |
524 | ||
525 | // transfer data between internal and GUI representations | |
526 | virtual bool TransferDataToWindow(); | |
527 | virtual bool TransferDataFromWindow(); | |
528 | ||
529 | virtual void InitDialog(); | |
530 | ||
88ac883a | 531 | #if wxUSE_ACCEL |
f03fc89f VZ |
532 | // accelerators |
533 | // ------------ | |
534 | virtual void SetAcceleratorTable( const wxAcceleratorTable& accel ) | |
535 | { m_acceleratorTable = accel; } | |
536 | wxAcceleratorTable *GetAcceleratorTable() | |
537 | { return &m_acceleratorTable; } | |
5048c832 | 538 | |
540b6b09 VZ |
539 | #endif // wxUSE_ACCEL |
540 | ||
541 | #if wxUSE_HOTKEY | |
542 | // hot keys (system wide accelerators) | |
543 | // ----------------------------------- | |
544 | ||
545 | virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode); | |
5048c832 | 546 | virtual bool UnregisterHotKey(int hotkeyId); |
540b6b09 | 547 | #endif // wxUSE_HOTKEY |
5048c832 | 548 | |
f03fc89f VZ |
549 | |
550 | // dialog units translations | |
551 | // ------------------------- | |
552 | ||
553 | wxPoint ConvertPixelsToDialog( const wxPoint& pt ); | |
554 | wxPoint ConvertDialogToPixels( const wxPoint& pt ); | |
555 | wxSize ConvertPixelsToDialog( const wxSize& sz ) | |
556 | { | |
557 | wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); | |
558 | ||
559 | return wxSize(pt.x, pt.y); | |
560 | } | |
561 | ||
562 | wxSize ConvertDialogToPixels( const wxSize& sz ) | |
563 | { | |
564 | wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); | |
565 | ||
566 | return wxSize(pt.x, pt.y); | |
567 | } | |
568 | ||
569 | // mouse functions | |
570 | // --------------- | |
571 | ||
572 | // move the mouse to the specified position | |
573 | virtual void WarpPointer(int x, int y) = 0; | |
574 | ||
94633ad9 VZ |
575 | // start or end mouse capture, these functions maintain the stack of |
576 | // windows having captured the mouse and after calling ReleaseMouse() | |
577 | // the mouse is not released but returns to the window which had had | |
578 | // captured it previously (if any) | |
579 | void CaptureMouse(); | |
580 | void ReleaseMouse(); | |
f03fc89f | 581 | |
1e6feb95 VZ |
582 | // get the window which currently captures the mouse or NULL |
583 | static wxWindow *GetCapture(); | |
584 | ||
585 | // does this window have the capture? | |
586 | virtual bool HasCapture() const | |
587 | { return (wxWindow *)this == GetCapture(); } | |
588 | ||
f03fc89f VZ |
589 | // painting the window |
590 | // ------------------- | |
591 | ||
592 | // mark the specified rectangle (or the whole window) as "dirty" so it | |
593 | // will be repainted | |
d4864e97 | 594 | virtual void Refresh( bool eraseBackground = true, |
f03fc89f | 595 | const wxRect *rect = (const wxRect *) NULL ) = 0; |
1e6feb95 VZ |
596 | |
597 | // a less awkward wrapper for Refresh | |
d4864e97 | 598 | void RefreshRect(const wxRect& rect) { Refresh(true, &rect); } |
1e6feb95 VZ |
599 | |
600 | // repaint all invalid areas of the window immediately | |
601 | virtual void Update() { } | |
602 | ||
5da0803c VZ |
603 | // clear the window background |
604 | virtual void ClearBackground(); | |
f03fc89f | 605 | |
0cc7251e VZ |
606 | // freeze the window: don't redraw it until it is thawed |
607 | virtual void Freeze() { } | |
608 | ||
609 | // thaw the window: redraw it after it had been frozen | |
610 | virtual void Thaw() { } | |
611 | ||
f03fc89f | 612 | // adjust DC for drawing on this window |
f6147cfc | 613 | virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { } |
f03fc89f VZ |
614 | |
615 | // the update region of the window contains the areas which must be | |
616 | // repainted by the program | |
617 | const wxRegion& GetUpdateRegion() const { return m_updateRegion; } | |
618 | wxRegion& GetUpdateRegion() { return m_updateRegion; } | |
619 | ||
1e6feb95 VZ |
620 | // get the update rectangleregion bounding box in client coords |
621 | wxRect GetUpdateClientRect() const; | |
622 | ||
f03fc89f VZ |
623 | // these functions verify whether the given point/rectangle belongs to |
624 | // (or at least intersects with) the update region | |
625 | bool IsExposed( int x, int y ) const; | |
626 | bool IsExposed( int x, int y, int w, int h ) const; | |
627 | ||
628 | bool IsExposed( const wxPoint& pt ) const | |
629 | { return IsExposed(pt.x, pt.y); } | |
630 | bool IsExposed( const wxRect& rect ) const | |
631 | { return IsExposed(rect.x, rect.y, rect.width, rect.height); } | |
632 | ||
633 | // colours, fonts and cursors | |
634 | // -------------------------- | |
635 | ||
636 | // set/retrieve the window colours (system defaults are used by | |
d4864e97 | 637 | // default): Set functions return true if colour was changed |
f03fc89f VZ |
638 | virtual bool SetBackgroundColour( const wxColour &colour ); |
639 | virtual bool SetForegroundColour( const wxColour &colour ); | |
640 | ||
641 | wxColour GetBackgroundColour() const { return m_backgroundColour; } | |
642 | wxColour GetForegroundColour() const { return m_foregroundColour; } | |
643 | ||
d4864e97 | 644 | // set/retrieve the cursor for this window (SetCursor() returns true |
f03fc89f VZ |
645 | // if the cursor was really changed) |
646 | virtual bool SetCursor( const wxCursor &cursor ); | |
647 | const wxCursor& GetCursor() const { return m_cursor; } | |
648 | wxCursor& GetCursor() { return m_cursor; } | |
649 | ||
d4864e97 | 650 | // set/retrieve the font for the window (SetFont() returns true if the |
f03fc89f VZ |
651 | // font really changed) |
652 | virtual bool SetFont( const wxFont &font ) = 0; | |
653 | const wxFont& GetFont() const { return m_font; } | |
654 | wxFont& GetFont() { return m_font; } | |
655 | ||
789295bf VZ |
656 | #if wxUSE_CARET |
657 | // associate a caret with the window | |
658 | void SetCaret(wxCaret *caret); | |
659 | // get the current caret (may be NULL) | |
660 | wxCaret *GetCaret() const { return m_caret; } | |
661 | #endif // wxUSE_CARET | |
662 | ||
f03fc89f VZ |
663 | // get the (average) character size for the current font |
664 | virtual int GetCharHeight() const = 0; | |
665 | virtual int GetCharWidth() const = 0; | |
666 | ||
667 | // get the width/height/... of the text using current or specified | |
668 | // font | |
669 | virtual void GetTextExtent(const wxString& string, | |
670 | int *x, int *y, | |
671 | int *descent = (int *) NULL, | |
672 | int *externalLeading = (int *) NULL, | |
673 | const wxFont *theFont = (const wxFont *) NULL) | |
674 | const = 0; | |
675 | ||
1e6feb95 VZ |
676 | // client <-> screen coords |
677 | // ------------------------ | |
678 | ||
f03fc89f | 679 | // translate to/from screen/client coordinates (pointers may be NULL) |
dabc0cd5 VZ |
680 | void ClientToScreen( int *x, int *y ) const |
681 | { DoClientToScreen(x, y); } | |
682 | void ScreenToClient( int *x, int *y ) const | |
683 | { DoScreenToClient(x, y); } | |
1e6feb95 VZ |
684 | |
685 | // wxPoint interface to do the same thing | |
dabc0cd5 VZ |
686 | wxPoint ClientToScreen(const wxPoint& pt) const |
687 | { | |
688 | int x = pt.x, y = pt.y; | |
689 | DoClientToScreen(&x, &y); | |
690 | ||
691 | return wxPoint(x, y); | |
692 | } | |
693 | ||
694 | wxPoint ScreenToClient(const wxPoint& pt) const | |
695 | { | |
696 | int x = pt.x, y = pt.y; | |
697 | DoScreenToClient(&x, &y); | |
698 | ||
699 | return wxPoint(x, y); | |
700 | } | |
f03fc89f | 701 | |
1e6feb95 VZ |
702 | // test where the given (in client coords) point lies |
703 | wxHitTest HitTest(wxCoord x, wxCoord y) const | |
704 | { return DoHitTest(x, y); } | |
705 | ||
706 | wxHitTest HitTest(const wxPoint& pt) const | |
707 | { return DoHitTest(pt.x, pt.y); } | |
708 | ||
f03fc89f VZ |
709 | // misc |
710 | // ---- | |
711 | ||
aede4ebb VZ |
712 | // get the window border style from the given flags: this is different from |
713 | // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to | |
714 | // translate wxBORDER_DEFAULT to something reasonable | |
715 | wxBorder GetBorder(long flags) const; | |
716 | ||
717 | // get border for the flags of this window | |
718 | wxBorder GetBorder() const { return GetBorder(GetWindowStyleFlag()); } | |
1e6feb95 | 719 | |
d4864e97 | 720 | // send wxUpdateUIEvents to this window, and children if recurse is true |
e39af974 JS |
721 | virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE); |
722 | ||
723 | // do the window-specific processing after processing the update event | |
724 | virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ; | |
f03fc89f | 725 | |
1e6feb95 | 726 | #if wxUSE_MENUS |
a1665b22 VZ |
727 | bool PopupMenu( wxMenu *menu, const wxPoint& pos ) |
728 | { return DoPopupMenu(menu, pos.x, pos.y); } | |
729 | bool PopupMenu( wxMenu *menu, int x, int y ) | |
730 | { return DoPopupMenu(menu, x, y); } | |
1e6feb95 | 731 | #endif // wxUSE_MENUS |
f03fc89f VZ |
732 | |
733 | // scrollbars | |
734 | // ---------- | |
735 | ||
1e6feb95 VZ |
736 | // does the window have the scrollbar for this orientation? |
737 | bool HasScrollbar(int orient) const | |
738 | { | |
739 | return (m_windowStyle & | |
740 | (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0; | |
741 | } | |
742 | ||
f03fc89f VZ |
743 | // configure the window scrollbars |
744 | virtual void SetScrollbar( int orient, | |
745 | int pos, | |
1e6feb95 | 746 | int thumbvisible, |
f03fc89f | 747 | int range, |
d4864e97 VZ |
748 | bool refresh = true ) = 0; |
749 | virtual void SetScrollPos( int orient, int pos, bool refresh = true ) = 0; | |
f03fc89f VZ |
750 | virtual int GetScrollPos( int orient ) const = 0; |
751 | virtual int GetScrollThumb( int orient ) const = 0; | |
752 | virtual int GetScrollRange( int orient ) const = 0; | |
753 | ||
754 | // scroll window to the specified position | |
755 | virtual void ScrollWindow( int dx, int dy, | |
756 | const wxRect* rect = (wxRect *) NULL ) = 0; | |
757 | ||
b9b3393e | 758 | // scrolls window by line/page: note that not all controls support this |
9cd6d737 | 759 | // |
d4864e97 VZ |
760 | // return true if the position changed, false otherwise |
761 | virtual bool ScrollLines(int WXUNUSED(lines)) { return false; } | |
762 | virtual bool ScrollPages(int WXUNUSED(pages)) { return false; } | |
9cd6d737 VZ |
763 | |
764 | // convenient wrappers for ScrollLines/Pages | |
765 | bool LineUp() { return ScrollLines(-1); } | |
766 | bool LineDown() { return ScrollLines(1); } | |
767 | bool PageUp() { return ScrollPages(-1); } | |
768 | bool PageDown() { return ScrollPages(1); } | |
b9b3393e | 769 | |
bd83cb56 VZ |
770 | // context-sensitive help |
771 | // ---------------------- | |
772 | ||
773 | // these are the convenience functions wrapping wxHelpProvider methods | |
774 | ||
775 | #if wxUSE_HELP | |
776 | // associate this help text with this window | |
777 | void SetHelpText(const wxString& text); | |
778 | // associate this help text with all windows with the same id as this | |
779 | // one | |
780 | void SetHelpTextForId(const wxString& text); | |
781 | // get the help string associated with this window (may be empty) | |
782 | wxString GetHelpText() const; | |
783 | #endif // wxUSE_HELP | |
784 | ||
f03fc89f VZ |
785 | // tooltips |
786 | // -------- | |
bd83cb56 | 787 | |
f03fc89f VZ |
788 | #if wxUSE_TOOLTIPS |
789 | // the easiest way to set a tooltip for a window is to use this method | |
790 | void SetToolTip( const wxString &tip ); | |
791 | // attach a tooltip to the window | |
792 | void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); } | |
793 | // get the associated tooltip or NULL if none | |
794 | wxToolTip* GetToolTip() const { return m_tooltip; } | |
311a173b | 795 | wxString GetToolTipText() const ; |
f03fc89f VZ |
796 | #endif // wxUSE_TOOLTIPS |
797 | ||
798 | // drag and drop | |
799 | // ------------- | |
800 | #if wxUSE_DRAG_AND_DROP | |
801 | // set/retrieve the drop target associated with this window (may be | |
802 | // NULL; it's owned by the window and will be deleted by it) | |
803 | virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0; | |
804 | virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; } | |
805 | #endif // wxUSE_DRAG_AND_DROP | |
806 | ||
807 | // constraints and sizers | |
808 | // ---------------------- | |
809 | #if wxUSE_CONSTRAINTS | |
810 | // set the constraints for this window or retrieve them (may be NULL) | |
811 | void SetConstraints( wxLayoutConstraints *constraints ); | |
812 | wxLayoutConstraints *GetConstraints() const { return m_constraints; } | |
813 | ||
f03fc89f VZ |
814 | // implementation only |
815 | void UnsetConstraints(wxLayoutConstraints *c); | |
816 | wxWindowList *GetConstraintsInvolvedIn() const | |
817 | { return m_constraintsInvolvedIn; } | |
818 | void AddConstraintReference(wxWindowBase *otherWin); | |
819 | void RemoveConstraintReference(wxWindowBase *otherWin); | |
820 | void DeleteRelatedConstraints(); | |
821 | void ResetConstraints(); | |
822 | ||
823 | // these methods may be overriden for special layout algorithms | |
d4864e97 | 824 | virtual void SetConstraintSizes(bool recurse = true); |
f03fc89f VZ |
825 | virtual bool LayoutPhase1(int *noChanges); |
826 | virtual bool LayoutPhase2(int *noChanges); | |
4b7f2165 | 827 | virtual bool DoPhase(int phase); |
f03fc89f VZ |
828 | |
829 | // these methods are virtual but normally won't be overridden | |
f03fc89f VZ |
830 | virtual void SetSizeConstraint(int x, int y, int w, int h); |
831 | virtual void MoveConstraint(int x, int y); | |
832 | virtual void GetSizeConstraint(int *w, int *h) const ; | |
833 | virtual void GetClientSizeConstraint(int *w, int *h) const ; | |
834 | virtual void GetPositionConstraint(int *x, int *y) const ; | |
835 | ||
461e93f9 JS |
836 | #endif // wxUSE_CONSTRAINTS |
837 | ||
838 | // when using constraints or sizers, it makes sense to update | |
839 | // children positions automatically whenever the window is resized | |
840 | // - this is done if autoLayout is on | |
841 | void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; } | |
842 | bool GetAutoLayout() const { return m_autoLayout; } | |
843 | ||
844 | // lay out the window and its children | |
845 | virtual bool Layout(); | |
846 | ||
f03fc89f | 847 | // sizers |
d4864e97 VZ |
848 | void SetSizer(wxSizer *sizer, bool deleteOld = true ); |
849 | void SetSizerAndFit( wxSizer *sizer, bool deleteOld = true ); | |
566d84a7 | 850 | |
f03fc89f | 851 | wxSizer *GetSizer() const { return m_windowSizer; } |
be90c029 RD |
852 | |
853 | // Track if this window is a member of a sizer | |
f0244295 VZ |
854 | void SetContainingSizer(wxSizer* sizer) |
855 | { | |
856 | // adding a window to a sizer twice is going to result in fatal and | |
857 | // hard to debug problems later because when deleting the second | |
858 | // associated wxSizerItem we're going to dereference a dangling | |
859 | // pointer; so try to detect this as early as possible | |
860 | wxASSERT_MSG( !sizer || m_containingSizer != sizer, | |
861 | _T("Adding a window to the same sizer twice?") ); | |
862 | ||
863 | m_containingSizer = sizer; | |
864 | } | |
be90c029 RD |
865 | wxSizer *GetContainingSizer() const { return m_containingSizer; } |
866 | ||
45a959a3 JS |
867 | // accessibility |
868 | // ---------------------- | |
869 | #if wxUSE_ACCESSIBILITY | |
870 | // Override to create a specific accessible object. | |
871 | virtual wxAccessible* CreateAccessible(); | |
872 | ||
873 | // Sets the accessible object. | |
874 | void SetAccessible(wxAccessible* accessible) ; | |
875 | ||
876 | // Returns the accessible object. | |
877 | wxAccessible* GetAccessible() { return m_accessible; }; | |
878 | ||
879 | // Returns the accessible object, creating if necessary. | |
880 | wxAccessible* GetOrCreateAccessible() ; | |
881 | #endif | |
882 | ||
f03fc89f VZ |
883 | // implementation |
884 | // -------------- | |
885 | ||
886 | // event handlers | |
887 | void OnSysColourChanged( wxSysColourChangedEvent& event ); | |
888 | void OnInitDialog( wxInitDialogEvent &event ); | |
72fc5caf | 889 | void OnMiddleClick( wxMouseEvent& event ); |
bd83cb56 VZ |
890 | #if wxUSE_HELP |
891 | void OnHelp(wxHelpEvent& event); | |
892 | #endif // wxUSE_HELP | |
f03fc89f | 893 | |
e39af974 JS |
894 | // virtual function for implementing internal idle |
895 | // behaviour | |
896 | virtual void OnInternalIdle() {} | |
897 | ||
898 | // call internal idle recursively | |
5109ae5d | 899 | // void ProcessInternalIdle() ; |
e39af974 JS |
900 | |
901 | // get the handle of the window for the underlying window system: this | |
d7c24517 VZ |
902 | // is only used for wxWin itself or for user code which wants to call |
903 | // platform-specific APIs | |
d22699b5 | 904 | virtual WXWidget GetHandle() const = 0; |
cc2b7472 | 905 | |
574c939e KB |
906 | #if wxUSE_PALETTE |
907 | // Store the palette used by DCs in wxWindow so that the dcs can share | |
908 | // a palette. And we can respond to palette messages. | |
909 | wxPalette GetPalette() const { return m_palette; } | |
b95edd47 | 910 | |
574c939e KB |
911 | // When palette is changed tell the DC to set the system palette to the |
912 | // new one. | |
b95edd47 VZ |
913 | void SetPalette(const wxPalette& pal); |
914 | ||
915 | // return true if we have a specific palette | |
916 | bool HasCustomPalette() const { return m_hasCustomPalette; } | |
917 | ||
918 | // return the first parent window with a custom palette or NULL | |
919 | wxWindow *GetAncestorWithCustomPalette() const; | |
574c939e KB |
920 | #endif // wxUSE_PALETTE |
921 | ||
739730ca | 922 | protected: |
4caf847c | 923 | // event handling specific to wxWindow |
4caf847c | 924 | virtual bool TryValidator(wxEvent& event); |
4caf847c VZ |
925 | virtual bool TryParent(wxEvent& event); |
926 | ||
927 | ||
ec5bb70d VZ |
928 | #if wxUSE_CONSTRAINTS |
929 | // satisfy the constraints for the windows but don't set the window sizes | |
930 | void SatisfyConstraints(); | |
931 | #endif // wxUSE_CONSTRAINTS | |
566d84a7 | 932 | |
7de59551 RD |
933 | // Send the wxWindowDestroyEvent |
934 | void SendDestroyEvent(); | |
935 | ||
7af6f327 | 936 | // the window id - a number which uniquely identifies a window among |
d7c24517 | 937 | // its siblings unless it is -1 |
f03fc89f | 938 | wxWindowID m_windowId; |
456bc6d9 | 939 | |
f03fc89f VZ |
940 | // the parent window of this window (or NULL) and the list of the children |
941 | // of this window | |
942 | wxWindow *m_parent; | |
943 | wxWindowList m_children; | |
944 | ||
945 | // the minimal allowed size for the window (no minimal size if variable(s) | |
946 | // contain(s) -1) | |
ec5bb70d VZ |
947 | int m_minWidth, |
948 | m_minHeight, | |
949 | m_maxWidth, | |
950 | m_maxHeight; | |
f03fc89f VZ |
951 | |
952 | // event handler for this window: usually is just 'this' but may be | |
953 | // changed with SetEventHandler() | |
954 | wxEvtHandler *m_eventHandler; | |
955 | ||
88ac883a | 956 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
957 | // associated validator or NULL if none |
958 | wxValidator *m_windowValidator; | |
88ac883a | 959 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
960 | |
961 | #if wxUSE_DRAG_AND_DROP | |
962 | wxDropTarget *m_dropTarget; | |
963 | #endif // wxUSE_DRAG_AND_DROP | |
964 | ||
965 | // visual window attributes | |
966 | wxCursor m_cursor; | |
967 | wxFont m_font; | |
968 | wxColour m_backgroundColour, m_foregroundColour; | |
969 | ||
789295bf VZ |
970 | #if wxUSE_CARET |
971 | wxCaret *m_caret; | |
972 | #endif // wxUSE_CARET | |
973 | ||
f03fc89f VZ |
974 | // the region which should be repainted in response to paint event |
975 | wxRegion m_updateRegion; | |
976 | ||
88ac883a | 977 | #if wxUSE_ACCEL |
f03fc89f VZ |
978 | // the accelerator table for the window which translates key strokes into |
979 | // command events | |
980 | wxAcceleratorTable m_acceleratorTable; | |
88ac883a | 981 | #endif // wxUSE_ACCEL |
f03fc89f | 982 | |
f03fc89f VZ |
983 | // the tooltip for this window (may be NULL) |
984 | #if wxUSE_TOOLTIPS | |
985 | wxToolTip *m_tooltip; | |
986 | #endif // wxUSE_TOOLTIPS | |
987 | ||
988 | // constraints and sizers | |
989 | #if wxUSE_CONSTRAINTS | |
990 | // the constraints for this window or NULL | |
991 | wxLayoutConstraints *m_constraints; | |
992 | ||
993 | // constraints this window is involved in | |
994 | wxWindowList *m_constraintsInvolvedIn; | |
461e93f9 | 995 | #endif // wxUSE_CONSTRAINTS |
f03fc89f | 996 | |
be90c029 | 997 | // this window's sizer |
f03fc89f | 998 | wxSizer *m_windowSizer; |
be90c029 RD |
999 | |
1000 | // The sizer this window is a member of, if any | |
1001 | wxSizer *m_containingSizer; | |
f03fc89f VZ |
1002 | |
1003 | // Layout() window automatically when its size changes? | |
1004 | bool m_autoLayout:1; | |
f03fc89f VZ |
1005 | |
1006 | // window state | |
1007 | bool m_isShown:1; | |
1008 | bool m_isEnabled:1; | |
1009 | bool m_isBeingDeleted:1; | |
1010 | ||
23895080 VZ |
1011 | // was the window colours/font explicitly changed by user? |
1012 | bool m_hasBgCol:1; | |
1013 | bool m_hasFgCol:1; | |
1014 | bool m_hasFont:1; | |
1015 | ||
f03fc89f | 1016 | // window attributes |
d80cd92a VZ |
1017 | long m_windowStyle, |
1018 | m_exStyle; | |
f03fc89f | 1019 | wxString m_windowName; |
a2d93e73 | 1020 | bool m_themeEnabled; |
f03fc89f | 1021 | |
071e5fd9 | 1022 | #if wxUSE_PALETTE |
574c939e | 1023 | wxPalette m_palette; |
b95edd47 VZ |
1024 | bool m_hasCustomPalette; |
1025 | #endif // wxUSE_PALETTE | |
574c939e | 1026 | |
45a959a3 JS |
1027 | #if wxUSE_ACCESSIBILITY |
1028 | wxAccessible* m_accessible; | |
1029 | #endif | |
566d84a7 RL |
1030 | // Virtual size (scrolling) |
1031 | wxSize m_virtualSize; | |
1032 | ||
1033 | int m_minVirtualWidth; // VirtualSizeHints | |
1034 | int m_minVirtualHeight; | |
1035 | int m_maxVirtualWidth; | |
1036 | int m_maxVirtualHeight; | |
45e0dc94 | 1037 | |
1e6feb95 VZ |
1038 | // override this to change the default (i.e. used when no style is |
1039 | // specified) border for the window class | |
1040 | virtual wxBorder GetDefaultBorder() const; | |
1041 | ||
723f8e3a RD |
1042 | // Get the default size for the new window if no explicit size given If |
1043 | // there are better default sizes then these can be changed, just as long | |
1044 | // as they are not too small for TLWs. | |
a7c26d10 RD |
1045 | static int WidthDefault(int w) { return w == -1 ? 400 : w; } |
1046 | static int HeightDefault(int h) { return h == -1 ? 250 : h; } | |
f03fc89f | 1047 | |
1e6feb95 VZ |
1048 | // set the best size for the control if the default size was given: |
1049 | // replaces the fields of size == -1 with the best values for them and | |
1050 | // calls SetSize() if needed | |
2b5f62a0 VZ |
1051 | // |
1052 | // This function is rather unfortunately named.. it's really just a | |
1053 | // smarter SetSize / convenience function for expanding wxDefaultSize. | |
1054 | // Note that it does not influence the value returned by GetBestSize | |
1055 | // at all. | |
1e6feb95 | 1056 | void SetBestSize(const wxSize& size) |
f68586e5 | 1057 | { |
2b5f62a0 VZ |
1058 | // the size only needs to be changed if the current size is incomplete, |
1059 | // i.e. one of the components was specified as default -- so if both | |
1060 | // were given, simply don't do anything | |
f68586e5 VZ |
1061 | if ( size.x == -1 || size.y == -1 ) |
1062 | { | |
1e6feb95 VZ |
1063 | wxSize sizeBest = DoGetBestSize(); |
1064 | if ( size.x != -1 ) | |
1065 | sizeBest.x = size.x; | |
1066 | if ( size.y != -1 ) | |
1067 | sizeBest.y = size.y; | |
1068 | ||
1069 | SetSize(sizeBest); | |
f68586e5 VZ |
1070 | } |
1071 | } | |
1072 | ||
f03fc89f VZ |
1073 | // more pure virtual functions |
1074 | // --------------------------- | |
1075 | ||
1076 | // NB: we must have DoSomething() function when Something() is an overloaded | |
1077 | // method: indeed, we can't just have "virtual Something()" in case when | |
1078 | // the function is overloaded because then we'd have to make virtual all | |
1079 | // the variants (otherwise only the virtual function may be called on a | |
1080 | // pointer to derived class according to C++ rules) which is, in | |
1081 | // general, absolutely not needed. So instead we implement all | |
1082 | // overloaded Something()s in terms of DoSomething() which will be the | |
1083 | // only one to be virtual. | |
1084 | ||
dabc0cd5 VZ |
1085 | // coordinates translation |
1086 | virtual void DoClientToScreen( int *x, int *y ) const = 0; | |
1087 | virtual void DoScreenToClient( int *x, int *y ) const = 0; | |
1088 | ||
1e6feb95 VZ |
1089 | virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const; |
1090 | ||
94633ad9 | 1091 | // capture/release the mouse, used by Capture/ReleaseMouse() |
a83e1475 VZ |
1092 | virtual void DoCaptureMouse() = 0; |
1093 | virtual void DoReleaseMouse() = 0; | |
be90c029 | 1094 | |
f03fc89f VZ |
1095 | // retrieve the position/size of the window |
1096 | virtual void DoGetPosition( int *x, int *y ) const = 0; | |
1097 | virtual void DoGetSize( int *width, int *height ) const = 0; | |
1098 | virtual void DoGetClientSize( int *width, int *height ) const = 0; | |
1099 | ||
f68586e5 VZ |
1100 | // get the size which best suits the window: for a control, it would be |
1101 | // the minimal size which doesn't truncate the control, for a panel - the | |
1102 | // same size as it would have after a call to Fit() | |
1103 | virtual wxSize DoGetBestSize() const; | |
1104 | ||
f03fc89f VZ |
1105 | // this is the virtual function to be overriden in any derived class which |
1106 | // wants to change how SetSize() or Move() works - it is called by all | |
1107 | // versions of these functions in the base class | |
1108 | virtual void DoSetSize(int x, int y, | |
1109 | int width, int height, | |
1110 | int sizeFlags = wxSIZE_AUTO) = 0; | |
1111 | ||
1112 | // same as DoSetSize() for the client size | |
1113 | virtual void DoSetClientSize(int width, int height) = 0; | |
1114 | ||
9d9b7755 VZ |
1115 | // move the window to the specified location and resize it: this is called |
1116 | // from both DoSetSize() and DoSetClientSize() and would usually just | |
1117 | // reposition this window except for composite controls which will want to | |
1118 | // arrange themselves inside the given rectangle | |
1119 | virtual void DoMoveWindow(int x, int y, int width, int height) = 0; | |
1120 | ||
f03fc89f VZ |
1121 | #if wxUSE_TOOLTIPS |
1122 | virtual void DoSetToolTip( wxToolTip *tip ); | |
1123 | #endif // wxUSE_TOOLTIPS | |
1124 | ||
1e6feb95 | 1125 | #if wxUSE_MENUS |
a1665b22 | 1126 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0; |
1e6feb95 | 1127 | #endif // wxUSE_MENUS |
a1665b22 | 1128 | |
716e96df VZ |
1129 | // Makes an adjustment to the window position to make it relative to the |
1130 | // parents client area, e.g. if the parent is a frame with a toolbar, its | |
1131 | // (0, 0) is just below the toolbar | |
1132 | virtual void AdjustForParentClientOrigin(int& x, int& y, | |
1133 | int sizeFlags = 0) const; | |
8d99be5f | 1134 | |
45e0dc94 | 1135 | |
f03fc89f | 1136 | private: |
45e0dc94 | 1137 | |
f03fc89f VZ |
1138 | // contains the last id generated by NewControlId |
1139 | static int ms_lastControlId; | |
1140 | ||
a83e1475 VZ |
1141 | // the stack of windows which have captured the mouse |
1142 | static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext; | |
1143 | ||
1e6feb95 VZ |
1144 | DECLARE_ABSTRACT_CLASS(wxWindowBase) |
1145 | DECLARE_NO_COPY_CLASS(wxWindowBase) | |
f03fc89f VZ |
1146 | DECLARE_EVENT_TABLE() |
1147 | }; | |
1148 | ||
1149 | // ---------------------------------------------------------------------------- | |
1150 | // now include the declaration of wxWindow class | |
1151 | // ---------------------------------------------------------------------------- | |
1152 | ||
1e6feb95 | 1153 | // include the declaration of the platform-specific class |
2049ba38 | 1154 | #if defined(__WXMSW__) |
a5b3669d VZ |
1155 | #ifdef __WXUNIVERSAL__ |
1156 | #define wxWindowNative wxWindowMSW | |
1157 | #else // !wxUniv | |
1e6feb95 | 1158 | #define wxWindowMSW wxWindow |
a5b3669d | 1159 | #endif // wxUniv/!wxUniv |
f03fc89f | 1160 | #include "wx/msw/window.h" |
2049ba38 | 1161 | #elif defined(__WXMOTIF__) |
f03fc89f | 1162 | #include "wx/motif/window.h" |
2049ba38 | 1163 | #elif defined(__WXGTK__) |
a5b3669d VZ |
1164 | #ifdef __WXUNIVERSAL__ |
1165 | #define wxWindowNative wxWindowGTK | |
1166 | #else // !wxUniv | |
1e6feb95 | 1167 | #define wxWindowGTK wxWindow |
1e6feb95 | 1168 | #endif // wxUniv |
f03fc89f | 1169 | #include "wx/gtk/window.h" |
83df96d6 JS |
1170 | #elif defined(__WXX11__) |
1171 | #ifdef __WXUNIVERSAL__ | |
1172 | #define wxWindowNative wxWindowX11 | |
1173 | #else // !wxUniv | |
1174 | #define wxWindowX11 wxWindow | |
83df96d6 JS |
1175 | #endif // wxUniv |
1176 | #include "wx/x11/window.h" | |
711c76db | 1177 | #elif defined(__WXMGL__) |
386c7058 VS |
1178 | #ifdef __WXUNIVERSAL__ |
1179 | #define wxWindowNative wxWindowMGL | |
1180 | #else // !wxUniv | |
1181 | #define wxWindowMGL wxWindow | |
386c7058 VS |
1182 | #endif // wxUniv |
1183 | #include "wx/mgl/window.h" | |
34138703 | 1184 | #elif defined(__WXMAC__) |
e766c8a9 SC |
1185 | #ifdef __WXUNIVERSAL__ |
1186 | #define wxWindowNative wxWindowMac | |
1187 | #else // !wxUniv | |
1188 | #define wxWindowMac wxWindow | |
e766c8a9 | 1189 | #endif // wxUniv |
f03fc89f | 1190 | #include "wx/mac/window.h" |
e64df9bc DE |
1191 | #elif defined(__WXCOCOA__) |
1192 | #ifdef __WXUNIVERSAL__ | |
1193 | #define wxWindowNative wxWindowCocoa | |
1194 | #else // !wxUniv | |
1195 | #define wxWindowCocoa wxWindow | |
e64df9bc DE |
1196 | #endif // wxUniv |
1197 | #include "wx/cocoa/window.h" | |
1777b9bb | 1198 | #elif defined(__WXPM__) |
210a651b DW |
1199 | #ifdef __WXUNIVERSAL__ |
1200 | #define wxWindowNative wxWindowOS2 | |
1201 | #else // !wxUniv | |
1202 | #define wxWindowOS2 wxWindow | |
210a651b | 1203 | #endif // wxUniv/!wxUniv |
1777b9bb | 1204 | #include "wx/os2/window.h" |
c801d85f KB |
1205 | #endif |
1206 | ||
1e6feb95 VZ |
1207 | // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>, |
1208 | // for the native ports we already have defined it above | |
1209 | #if defined(__WXUNIVERSAL__) | |
a5b3669d VZ |
1210 | #ifndef wxWindowNative |
1211 | #error "wxWindowNative must be defined above!" | |
1212 | #endif | |
1213 | ||
1e6feb95 VZ |
1214 | #include "wx/univ/window.h" |
1215 | #endif // wxUniv | |
1216 | ||
f03fc89f VZ |
1217 | // ---------------------------------------------------------------------------- |
1218 | // inline functions which couldn't be declared in the class body because of | |
1219 | // forward dependencies | |
1220 | // ---------------------------------------------------------------------------- | |
1221 | ||
bacd69f9 | 1222 | inline wxWindow *wxWindowBase::GetGrandParent() const |
f03fc89f VZ |
1223 | { |
1224 | return m_parent ? m_parent->GetParent() : (wxWindow *)NULL; | |
1225 | } | |
1226 | ||
1227 | // ---------------------------------------------------------------------------- | |
3723b7b1 | 1228 | // global functions |
f03fc89f VZ |
1229 | // ---------------------------------------------------------------------------- |
1230 | ||
3723b7b1 JS |
1231 | // Find the wxWindow at the current mouse position, also returning the mouse |
1232 | // position. | |
1233 | WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt); | |
1234 | ||
1235 | // Get the current mouse position. | |
1236 | WXDLLEXPORT extern wxPoint wxGetMousePosition(); | |
1237 | ||
1e6feb95 VZ |
1238 | // get the currently active window of this application or NULL |
1239 | WXDLLEXPORT extern wxWindow *wxGetActiveWindow(); | |
1240 | ||
33b494d6 VZ |
1241 | // get the (first) top level parent window |
1242 | WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win); | |
1243 | ||
f68586e5 | 1244 | // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId() |
6d56eb5c | 1245 | inline int NewControlId() { return wxWindowBase::NewControlId(); } |
f03fc89f | 1246 | |
45a959a3 JS |
1247 | #if wxUSE_ACCESSIBILITY |
1248 | // ---------------------------------------------------------------------------- | |
1249 | // accessible object for windows | |
1250 | // ---------------------------------------------------------------------------- | |
1251 | ||
1252 | class WXDLLEXPORT wxWindowAccessible: public wxAccessible | |
1253 | { | |
1254 | public: | |
f81387bd | 1255 | wxWindowAccessible(wxWindow* win): wxAccessible(win) { if (win) win->SetAccessible(this); } |
45a959a3 JS |
1256 | virtual ~wxWindowAccessible() {}; |
1257 | ||
1258 | // Overridables | |
1259 | ||
1260 | // Can return either a child object, or an integer | |
1261 | // representing the child element, starting from 1. | |
1262 | virtual wxAccStatus HitTest(const wxPoint& pt, int* childId, wxAccessible** childObject); | |
1263 | ||
1264 | // Returns the rectangle for this object (id = 0) or a child element (id > 0). | |
1265 | virtual wxAccStatus GetLocation(wxRect& rect, int elementId); | |
1266 | ||
1267 | // Navigates from fromId to toId/toObject. | |
1268 | virtual wxAccStatus Navigate(wxNavDir navDir, int fromId, | |
1269 | int* toId, wxAccessible** toObject); | |
1270 | ||
1271 | // Gets the name of the specified object. | |
1272 | virtual wxAccStatus GetName(int childId, wxString* name); | |
1273 | ||
1274 | // Gets the number of children. | |
a37e4a07 | 1275 | virtual wxAccStatus GetChildCount(int* childCount); |
45a959a3 JS |
1276 | |
1277 | // Gets the specified child (starting from 1). | |
1278 | // If *child is NULL and return value is wxACC_OK, | |
1279 | // this means that the child is a simple element and | |
1280 | // not an accessible object. | |
1281 | virtual wxAccStatus GetChild(int childId, wxAccessible** child); | |
1282 | ||
1283 | // Gets the parent, or NULL. | |
1284 | virtual wxAccStatus GetParent(wxAccessible** parent); | |
1285 | ||
1286 | // Performs the default action. childId is 0 (the action for this object) | |
1287 | // or > 0 (the action for a child). | |
1288 | // Return wxACC_NOT_SUPPORTED if there is no default action for this | |
1289 | // window (e.g. an edit control). | |
1290 | virtual wxAccStatus DoDefaultAction(int childId); | |
1291 | ||
1292 | // Gets the default action for this object (0) or > 0 (the action for a child). | |
1293 | // Return wxACC_OK even if there is no action. actionName is the action, or the empty | |
1294 | // string if there is no action. | |
1295 | // The retrieved string describes the action that is performed on an object, | |
1296 | // not what the object does as a result. For example, a toolbar button that prints | |
1297 | // a document has a default action of "Press" rather than "Prints the current document." | |
1298 | virtual wxAccStatus GetDefaultAction(int childId, wxString* actionName); | |
1299 | ||
1300 | // Returns the description for this object or a child. | |
1301 | virtual wxAccStatus GetDescription(int childId, wxString* description); | |
1302 | ||
1303 | // Returns help text for this object or a child, similar to tooltip text. | |
1304 | virtual wxAccStatus GetHelpText(int childId, wxString* helpText); | |
1305 | ||
1306 | // Returns the keyboard shortcut for this object or child. | |
1307 | // Return e.g. ALT+K | |
1308 | virtual wxAccStatus GetKeyboardShortcut(int childId, wxString* shortcut); | |
1309 | ||
1310 | // Returns a role constant. | |
1311 | virtual wxAccStatus GetRole(int childId, wxAccRole* role); | |
1312 | ||
1313 | // Returns a state constant. | |
1314 | virtual wxAccStatus GetState(int childId, long* state); | |
1315 | ||
1316 | // Returns a localized string representing the value for the object | |
1317 | // or child. | |
1318 | virtual wxAccStatus GetValue(int childId, wxString* strValue); | |
1319 | ||
1320 | // Selects the object or child. | |
1321 | virtual wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags); | |
1322 | ||
1323 | // Gets the window with the keyboard focus. | |
1324 | // If childId is 0 and child is NULL, no object in | |
1325 | // this subhierarchy has the focus. | |
1326 | // If this object has the focus, child should be 'this'. | |
1327 | virtual wxAccStatus GetFocus(int* childId, wxAccessible** child); | |
1328 | ||
1329 | // Gets a variant representing the selected children | |
1330 | // of this object. | |
1331 | // Acceptable values: | |
d4864e97 | 1332 | // - a null variant (IsNull() returns true) |
45a959a3 JS |
1333 | // - a list variant (GetType() == wxT("list") |
1334 | // - an integer representing the selected child element, | |
1335 | // or 0 if this object is selected (GetType() == wxT("long") | |
1336 | // - a "void*" pointer to a wxAccessible child object | |
1337 | virtual wxAccStatus GetSelections(wxVariant* selections); | |
1338 | }; | |
1339 | ||
1340 | #endif // wxUSE_ACCESSIBILITY | |
1341 | ||
1342 | ||
c801d85f | 1343 | #endif |
34138703 | 1344 | // _WX_WINDOW_H_BASE_ |
34c3ffca | 1345 |