]>
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 | |
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
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 VZ |
36 | #include "wx/dcclient.h" |
37 | #include "wx/palette.h" | |
574c939e KB |
38 | #endif // wxUSE_PALETTE |
39 | ||
88ac883a VZ |
40 | #if wxUSE_ACCEL |
41 | #include "wx/accel.h" | |
42 | #endif // wxUSE_ACCEL | |
f03fc89f | 43 | |
6522713c VZ |
44 | // when building wxUniv/Foo we don't want the code for native menu use to be |
45 | // compiled in - it should only be used when building real wxFoo | |
46 | #ifdef __WXUNIVERSAL__ | |
47 | #define wxUSE_MENUS_NATIVE 0 | |
48 | #else // __WXMSW__ | |
49 | #define wxUSE_MENUS_NATIVE wxUSE_MENUS | |
50 | #endif // __WXUNIVERSAL__/__WXMSW__ | |
51 | ||
f03fc89f VZ |
52 | // ---------------------------------------------------------------------------- |
53 | // forward declarations | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
789295bf | 56 | class WXDLLEXPORT wxCaret; |
f03fc89f VZ |
57 | class WXDLLEXPORT wxControl; |
58 | class WXDLLEXPORT wxCursor; | |
eb082a08 | 59 | class WXDLLEXPORT wxDC; |
f03fc89f VZ |
60 | class WXDLLEXPORT wxDropTarget; |
61 | class WXDLLEXPORT wxItemResource; | |
62 | class WXDLLEXPORT wxLayoutConstraints; | |
63 | class WXDLLEXPORT wxResourceTable; | |
64 | class WXDLLEXPORT wxSizer; | |
65 | class WXDLLEXPORT wxToolTip; | |
f03fc89f VZ |
66 | class WXDLLEXPORT wxWindowBase; |
67 | class WXDLLEXPORT wxWindow; | |
68 | ||
69 | // ---------------------------------------------------------------------------- | |
70 | // (pseudo)template list classes | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
f6bcfd97 | 73 | WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT); |
f03fc89f VZ |
74 | |
75 | // ---------------------------------------------------------------------------- | |
76 | // global variables | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
79 | WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows; | |
80 | ||
f03fc89f VZ |
81 | // ---------------------------------------------------------------------------- |
82 | // wxWindowBase is the base class for all GUI controls/widgets, this is the public | |
83 | // interface of this class. | |
84 | // | |
85 | // Event handler: windows have themselves as their event handlers by default, | |
86 | // but their event handlers could be set to another object entirely. This | |
87 | // separation can reduce the amount of derivation required, and allow | |
88 | // alteration of a window's functionality (e.g. by a resource editor that | |
89 | // temporarily switches event handlers). | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | class WXDLLEXPORT wxWindowBase : public wxEvtHandler | |
93 | { | |
f03fc89f VZ |
94 | public: |
95 | // creating the window | |
96 | // ------------------- | |
97 | ||
98 | // default ctor | |
99 | wxWindowBase() { InitBase(); } | |
100 | ||
101 | // pseudo ctor (can't be virtual, called from ctor) | |
102 | bool CreateBase(wxWindowBase *parent, | |
103 | wxWindowID id, | |
104 | const wxPoint& pos = wxDefaultPosition, | |
105 | const wxSize& size = wxDefaultSize, | |
106 | long style = 0, | |
8d99be5f | 107 | const wxValidator& validator = wxDefaultValidator, |
f03fc89f VZ |
108 | const wxString& name = wxPanelNameStr); |
109 | ||
110 | virtual ~wxWindowBase(); | |
111 | ||
112 | #if wxUSE_WX_RESOURCES | |
113 | // these functions are implemented in resource.cpp and resourc2.cpp | |
114 | virtual bool LoadFromResource(wxWindow *parent, | |
115 | const wxString& resourceName, | |
116 | const wxResourceTable *table = (const wxResourceTable *) NULL); | |
117 | virtual wxControl *CreateItem(const wxItemResource* childResource, | |
118 | const wxItemResource* parentResource, | |
119 | const wxResourceTable *table = (const wxResourceTable *) NULL); | |
120 | #endif // wxUSE_WX_RESOURCES | |
121 | ||
122 | // deleting the window | |
123 | // ------------------- | |
124 | ||
125 | // ask the window to close itself, return TRUE if the event handler | |
126 | // honoured our request | |
127 | bool Close( bool force = FALSE ); | |
128 | ||
129 | // the following functions delete the C++ objects (the window itself | |
130 | // or its children) as well as the GUI windows and normally should | |
131 | // never be used directly | |
132 | ||
133 | // delete window unconditionally (dangerous!), returns TRUE if ok | |
134 | virtual bool Destroy(); | |
135 | // delete all children of this window, returns TRUE if ok | |
136 | bool DestroyChildren(); | |
137 | ||
138 | // is the window being deleted? | |
139 | bool IsBeingDeleted() const { return m_isBeingDeleted; } | |
140 | ||
141 | // window attributes | |
142 | // ----------------- | |
143 | ||
456bc6d9 VZ |
144 | // NB: in future versions of wxWindows Set/GetTitle() will only work |
145 | // with the top level windows (such as dialogs and frames) and | |
146 | // Set/GetLabel() only with the other ones (i.e. all controls). | |
147 | ||
f03fc89f VZ |
148 | // the title (or label, see below) of the window: the text which the |
149 | // window shows | |
fe6b43a3 VS |
150 | virtual void SetTitle( const wxString& WXUNUSED(title) ) {} |
151 | virtual wxString GetTitle() const { return wxEmptyString; } | |
f03fc89f VZ |
152 | |
153 | // label is just the same as the title (but for, e.g., buttons it | |
154 | // makes more sense to speak about labels) | |
eba0e4d4 RR |
155 | virtual void SetLabel(const wxString& label) { SetTitle(label); } |
156 | virtual wxString GetLabel() const { return GetTitle(); } | |
f03fc89f VZ |
157 | |
158 | // the window name is used for ressource setting in X, it is not the | |
159 | // same as the window title/label | |
160 | virtual void SetName( const wxString &name ) { m_windowName = name; } | |
161 | virtual wxString GetName() const { return m_windowName; } | |
162 | ||
163 | // window id uniquely identifies the window among its siblings unless | |
164 | // it is -1 which means "don't care" | |
165 | void SetId( wxWindowID id ) { m_windowId = id; } | |
166 | wxWindowID GetId() const { return m_windowId; } | |
167 | ||
168 | // generate a control id for the controls which were not given one by | |
169 | // user | |
69418a8e | 170 | static int NewControlId() { return --ms_lastControlId; } |
c539ab55 VZ |
171 | // get the id of the control following the one with the given |
172 | // (autogenerated) id | |
173 | static int NextControlId(int id) { return id - 1; } | |
174 | // get the id of the control preceding the one with the given | |
175 | // (autogenerated) id | |
176 | static int PrevControlId(int id) { return id + 1; } | |
f03fc89f VZ |
177 | |
178 | // moving/resizing | |
179 | // --------------- | |
180 | ||
181 | // set the window size and/or position | |
182 | void SetSize( int x, int y, int width, int height, | |
183 | int sizeFlags = wxSIZE_AUTO ) | |
184 | { DoSetSize(x, y, width, height, sizeFlags); } | |
185 | ||
186 | void SetSize( int width, int height ) | |
187 | { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); } | |
188 | ||
189 | void SetSize( const wxSize& size ) | |
190 | { SetSize( size.x, size.y); } | |
191 | ||
192 | void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO) | |
193 | { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); } | |
194 | ||
1e6feb95 VZ |
195 | void Move(int x, int y, int flags = wxSIZE_USE_EXISTING) |
196 | { DoSetSize(x, y, -1, -1, flags); } | |
f03fc89f | 197 | |
1e6feb95 VZ |
198 | void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING) |
199 | { Move(pt.x, pt.y, flags); } | |
f03fc89f VZ |
200 | |
201 | // Z-order | |
202 | virtual void Raise() = 0; | |
203 | virtual void Lower() = 0; | |
204 | ||
205 | // client size is the size of area available for subwindows | |
206 | void SetClientSize( int width, int height ) | |
207 | { DoSetClientSize(width, height); } | |
208 | ||
209 | void SetClientSize( const wxSize& size ) | |
210 | { DoSetClientSize(size.x, size.y); } | |
211 | ||
212 | void SetClientSize(const wxRect& rect) | |
213 | { SetClientSize( rect.width, rect.height ); } | |
214 | ||
215 | // get the window position and/or size (pointers may be NULL) | |
216 | void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); } | |
217 | wxPoint GetPosition() const | |
218 | { | |
219 | int w, h; | |
220 | DoGetPosition(&w, &h); | |
221 | ||
222 | return wxPoint(w, h); | |
223 | } | |
224 | ||
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 | ||
362 | // returns TRUE if window was shown/hidden, FALSE if the nothing was | |
363 | // done (window was already shown/hidden) | |
364 | virtual bool Show( bool show = TRUE ); | |
365 | bool Hide() { return Show(FALSE); } | |
366 | ||
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); } | |
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) | |
392 | virtual void MakeModal(bool modal = TRUE); | |
393 | ||
a2d93e73 JS |
394 | virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; } |
395 | virtual bool GetThemeEnabled() const { return m_themeEnabled; } | |
396 | ||
456bc6d9 VZ |
397 | // focus and keyboard handling |
398 | // --------------------------- | |
f03fc89f VZ |
399 | |
400 | // set focus to this window | |
401 | virtual void SetFocus() = 0; | |
402 | ||
d577d610 VZ |
403 | // set focus to this window as the result of a keyboard action |
404 | virtual void SetFocusFromKbd() { SetFocus(); } | |
405 | ||
f03fc89f VZ |
406 | // return the window which currently has the focus or NULL |
407 | static wxWindow *FindFocus() /* = 0: implement in derived classes */; | |
408 | ||
409 | // can this window have focus? | |
410 | virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); } | |
411 | ||
1e6feb95 VZ |
412 | // can this window be given focus by keyboard navigation? if not, the |
413 | // only way to give it focus (provided it accepts it at all) is to | |
414 | // click it | |
415 | virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); } | |
416 | ||
456bc6d9 VZ |
417 | // NB: these methods really don't belong here but with the current |
418 | // class hierarchy there is no other place for them :-( | |
419 | ||
420 | // get the default child of this parent, i.e. the one which is | |
421 | // activated by pressing <Enter> | |
422 | virtual wxWindow *GetDefaultItem() const { return NULL; } | |
423 | ||
424 | // set this child as default, return the old default | |
425 | virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child)) | |
426 | { return NULL; } | |
427 | ||
036da5e3 VZ |
428 | // set this child as temporary default |
429 | virtual void SetTmpDefaultItem(wxWindow * WXUNUSED(win)) { } | |
430 | ||
f03fc89f VZ |
431 | // parent/children relations |
432 | // ------------------------- | |
433 | ||
434 | // get the list of children | |
435 | const wxWindowList& GetChildren() const { return m_children; } | |
436 | wxWindowList& GetChildren() { return m_children; } | |
437 | ||
438 | // get the parent or the parent of the parent | |
439 | wxWindow *GetParent() const { return m_parent; } | |
440 | inline wxWindow *GetGrandParent() const; | |
441 | ||
442 | // is this window a top level one? | |
8487f887 | 443 | virtual bool IsTopLevel() const; |
f03fc89f VZ |
444 | |
445 | // it doesn't really change parent, use ReParent() instead | |
446 | void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; } | |
447 | // change the real parent of this window, return TRUE if the parent | |
448 | // was changed, FALSE otherwise (error or newParent == oldParent) | |
449 | virtual bool Reparent( wxWindowBase *newParent ); | |
450 | ||
146ba0fe VZ |
451 | // implementation mostly |
452 | virtual void AddChild( wxWindowBase *child ); | |
453 | virtual void RemoveChild( wxWindowBase *child ); | |
454 | ||
455 | // looking for windows | |
456 | // ------------------- | |
457 | ||
f03fc89f VZ |
458 | // find window among the descendants of this one either by id or by |
459 | // name (return NULL if not found) | |
460 | wxWindow *FindWindow( long id ); | |
461 | wxWindow *FindWindow( const wxString& name ); | |
462 | ||
146ba0fe VZ |
463 | // Find a window among any window (all return NULL if not found) |
464 | static wxWindow *FindWindowById( long id, const wxWindow *parent = NULL ); | |
465 | static wxWindow *FindWindowByName( const wxString& name, | |
466 | const wxWindow *parent = NULL ); | |
467 | static wxWindow *FindWindowByLabel( const wxString& label, | |
468 | const wxWindow *parent = NULL ); | |
f03fc89f VZ |
469 | |
470 | // event handler stuff | |
471 | // ------------------- | |
472 | ||
473 | // get the current event handler | |
474 | wxEvtHandler *GetEventHandler() const { return m_eventHandler; } | |
475 | ||
476 | // replace the event handler (allows to completely subclass the | |
477 | // window) | |
478 | void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; } | |
479 | ||
480 | // push/pop event handler: allows to chain a custom event handler to | |
481 | // alreasy existing ones | |
482 | void PushEventHandler( wxEvtHandler *handler ); | |
483 | wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE ); | |
484 | ||
2e36d5cf VZ |
485 | // find the given handler in the event handler chain and remove (but |
486 | // not delete) it from the event handler chain, return TRUE if it was | |
487 | // found and FALSE otherwise (this also results in an assert failure so | |
488 | // this function should only be called when the handler is supposed to | |
489 | // be there) | |
490 | bool RemoveEventHandler(wxEvtHandler *handler); | |
491 | ||
1e6feb95 VZ |
492 | // validators |
493 | // ---------- | |
f03fc89f | 494 | |
88ac883a | 495 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
496 | // a window may have an associated validator which is used to control |
497 | // user input | |
498 | virtual void SetValidator( const wxValidator &validator ); | |
499 | virtual wxValidator *GetValidator() { return m_windowValidator; } | |
88ac883a | 500 | #endif // wxUSE_VALIDATORS |
f03fc89f | 501 | |
f03fc89f VZ |
502 | |
503 | // dialog oriented functions | |
504 | // ------------------------- | |
505 | ||
506 | // validate the correctness of input, return TRUE if ok | |
507 | virtual bool Validate(); | |
508 | ||
509 | // transfer data between internal and GUI representations | |
510 | virtual bool TransferDataToWindow(); | |
511 | virtual bool TransferDataFromWindow(); | |
512 | ||
513 | virtual void InitDialog(); | |
514 | ||
88ac883a | 515 | #if wxUSE_ACCEL |
f03fc89f VZ |
516 | // accelerators |
517 | // ------------ | |
518 | virtual void SetAcceleratorTable( const wxAcceleratorTable& accel ) | |
519 | { m_acceleratorTable = accel; } | |
520 | wxAcceleratorTable *GetAcceleratorTable() | |
521 | { return &m_acceleratorTable; } | |
88ac883a | 522 | #endif // wxUSE_ACCEL |
f03fc89f VZ |
523 | |
524 | // dialog units translations | |
525 | // ------------------------- | |
526 | ||
527 | wxPoint ConvertPixelsToDialog( const wxPoint& pt ); | |
528 | wxPoint ConvertDialogToPixels( const wxPoint& pt ); | |
529 | wxSize ConvertPixelsToDialog( const wxSize& sz ) | |
530 | { | |
531 | wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); | |
532 | ||
533 | return wxSize(pt.x, pt.y); | |
534 | } | |
535 | ||
536 | wxSize ConvertDialogToPixels( const wxSize& sz ) | |
537 | { | |
538 | wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); | |
539 | ||
540 | return wxSize(pt.x, pt.y); | |
541 | } | |
542 | ||
543 | // mouse functions | |
544 | // --------------- | |
545 | ||
546 | // move the mouse to the specified position | |
547 | virtual void WarpPointer(int x, int y) = 0; | |
548 | ||
94633ad9 VZ |
549 | // start or end mouse capture, these functions maintain the stack of |
550 | // windows having captured the mouse and after calling ReleaseMouse() | |
551 | // the mouse is not released but returns to the window which had had | |
552 | // captured it previously (if any) | |
553 | void CaptureMouse(); | |
554 | void ReleaseMouse(); | |
f03fc89f | 555 | |
1e6feb95 VZ |
556 | // get the window which currently captures the mouse or NULL |
557 | static wxWindow *GetCapture(); | |
558 | ||
559 | // does this window have the capture? | |
560 | virtual bool HasCapture() const | |
561 | { return (wxWindow *)this == GetCapture(); } | |
562 | ||
f03fc89f VZ |
563 | // painting the window |
564 | // ------------------- | |
565 | ||
566 | // mark the specified rectangle (or the whole window) as "dirty" so it | |
567 | // will be repainted | |
568 | virtual void Refresh( bool eraseBackground = TRUE, | |
569 | const wxRect *rect = (const wxRect *) NULL ) = 0; | |
1e6feb95 VZ |
570 | |
571 | // a less awkward wrapper for Refresh | |
572 | void RefreshRect(const wxRect& rect) { Refresh(TRUE, &rect); } | |
573 | ||
574 | // repaint all invalid areas of the window immediately | |
575 | virtual void Update() { } | |
576 | ||
f03fc89f VZ |
577 | // clear the window entirely |
578 | virtual void Clear() = 0; | |
579 | ||
0cc7251e VZ |
580 | // freeze the window: don't redraw it until it is thawed |
581 | virtual void Freeze() { } | |
582 | ||
583 | // thaw the window: redraw it after it had been frozen | |
584 | virtual void Thaw() { } | |
585 | ||
f03fc89f | 586 | // adjust DC for drawing on this window |
f6147cfc | 587 | virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { } |
f03fc89f VZ |
588 | |
589 | // the update region of the window contains the areas which must be | |
590 | // repainted by the program | |
591 | const wxRegion& GetUpdateRegion() const { return m_updateRegion; } | |
592 | wxRegion& GetUpdateRegion() { return m_updateRegion; } | |
593 | ||
1e6feb95 VZ |
594 | // get the update rectangleregion bounding box in client coords |
595 | wxRect GetUpdateClientRect() const; | |
596 | ||
f03fc89f VZ |
597 | // these functions verify whether the given point/rectangle belongs to |
598 | // (or at least intersects with) the update region | |
599 | bool IsExposed( int x, int y ) const; | |
600 | bool IsExposed( int x, int y, int w, int h ) const; | |
601 | ||
602 | bool IsExposed( const wxPoint& pt ) const | |
603 | { return IsExposed(pt.x, pt.y); } | |
604 | bool IsExposed( const wxRect& rect ) const | |
605 | { return IsExposed(rect.x, rect.y, rect.width, rect.height); } | |
606 | ||
607 | // colours, fonts and cursors | |
608 | // -------------------------- | |
609 | ||
610 | // set/retrieve the window colours (system defaults are used by | |
611 | // default): Set functions return TRUE if colour was changed | |
612 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
613 | virtual bool SetForegroundColour( const wxColour &colour ); | |
614 | ||
615 | wxColour GetBackgroundColour() const { return m_backgroundColour; } | |
616 | wxColour GetForegroundColour() const { return m_foregroundColour; } | |
617 | ||
618 | // set/retrieve the cursor for this window (SetCursor() returns TRUE | |
619 | // if the cursor was really changed) | |
620 | virtual bool SetCursor( const wxCursor &cursor ); | |
621 | const wxCursor& GetCursor() const { return m_cursor; } | |
622 | wxCursor& GetCursor() { return m_cursor; } | |
623 | ||
624 | // set/retrieve the font for the window (SetFont() returns TRUE if the | |
625 | // font really changed) | |
626 | virtual bool SetFont( const wxFont &font ) = 0; | |
627 | const wxFont& GetFont() const { return m_font; } | |
628 | wxFont& GetFont() { return m_font; } | |
629 | ||
789295bf VZ |
630 | #if wxUSE_CARET |
631 | // associate a caret with the window | |
632 | void SetCaret(wxCaret *caret); | |
633 | // get the current caret (may be NULL) | |
634 | wxCaret *GetCaret() const { return m_caret; } | |
635 | #endif // wxUSE_CARET | |
636 | ||
f03fc89f VZ |
637 | // get the (average) character size for the current font |
638 | virtual int GetCharHeight() const = 0; | |
639 | virtual int GetCharWidth() const = 0; | |
640 | ||
641 | // get the width/height/... of the text using current or specified | |
642 | // font | |
643 | virtual void GetTextExtent(const wxString& string, | |
644 | int *x, int *y, | |
645 | int *descent = (int *) NULL, | |
646 | int *externalLeading = (int *) NULL, | |
647 | const wxFont *theFont = (const wxFont *) NULL) | |
648 | const = 0; | |
649 | ||
1e6feb95 VZ |
650 | // client <-> screen coords |
651 | // ------------------------ | |
652 | ||
f03fc89f | 653 | // translate to/from screen/client coordinates (pointers may be NULL) |
dabc0cd5 VZ |
654 | void ClientToScreen( int *x, int *y ) const |
655 | { DoClientToScreen(x, y); } | |
656 | void ScreenToClient( int *x, int *y ) const | |
657 | { DoScreenToClient(x, y); } | |
1e6feb95 VZ |
658 | |
659 | // wxPoint interface to do the same thing | |
dabc0cd5 VZ |
660 | wxPoint ClientToScreen(const wxPoint& pt) const |
661 | { | |
662 | int x = pt.x, y = pt.y; | |
663 | DoClientToScreen(&x, &y); | |
664 | ||
665 | return wxPoint(x, y); | |
666 | } | |
667 | ||
668 | wxPoint ScreenToClient(const wxPoint& pt) const | |
669 | { | |
670 | int x = pt.x, y = pt.y; | |
671 | DoScreenToClient(&x, &y); | |
672 | ||
673 | return wxPoint(x, y); | |
674 | } | |
f03fc89f | 675 | |
1e6feb95 VZ |
676 | // test where the given (in client coords) point lies |
677 | wxHitTest HitTest(wxCoord x, wxCoord y) const | |
678 | { return DoHitTest(x, y); } | |
679 | ||
680 | wxHitTest HitTest(const wxPoint& pt) const | |
681 | { return DoHitTest(pt.x, pt.y); } | |
682 | ||
f03fc89f VZ |
683 | // misc |
684 | // ---- | |
685 | ||
1e6feb95 VZ |
686 | // get the window border style: uses the current style and falls back to |
687 | // the default style for this class otherwise (see GetDefaultBorder()) | |
688 | wxBorder GetBorder() const; | |
689 | ||
f03fc89f VZ |
690 | void UpdateWindowUI(); |
691 | ||
1e6feb95 | 692 | #if wxUSE_MENUS |
a1665b22 VZ |
693 | bool PopupMenu( wxMenu *menu, const wxPoint& pos ) |
694 | { return DoPopupMenu(menu, pos.x, pos.y); } | |
695 | bool PopupMenu( wxMenu *menu, int x, int y ) | |
696 | { return DoPopupMenu(menu, x, y); } | |
1e6feb95 | 697 | #endif // wxUSE_MENUS |
f03fc89f VZ |
698 | |
699 | // scrollbars | |
700 | // ---------- | |
701 | ||
1e6feb95 VZ |
702 | // does the window have the scrollbar for this orientation? |
703 | bool HasScrollbar(int orient) const | |
704 | { | |
705 | return (m_windowStyle & | |
706 | (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0; | |
707 | } | |
708 | ||
f03fc89f VZ |
709 | // configure the window scrollbars |
710 | virtual void SetScrollbar( int orient, | |
711 | int pos, | |
1e6feb95 | 712 | int thumbvisible, |
f03fc89f VZ |
713 | int range, |
714 | bool refresh = TRUE ) = 0; | |
715 | virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0; | |
716 | virtual int GetScrollPos( int orient ) const = 0; | |
717 | virtual int GetScrollThumb( int orient ) const = 0; | |
718 | virtual int GetScrollRange( int orient ) const = 0; | |
719 | ||
720 | // scroll window to the specified position | |
721 | virtual void ScrollWindow( int dx, int dy, | |
722 | const wxRect* rect = (wxRect *) NULL ) = 0; | |
723 | ||
b9b3393e | 724 | // scrolls window by line/page: note that not all controls support this |
9cd6d737 VZ |
725 | // |
726 | // return TRUE if the position changed, FALSE otherwise | |
727 | virtual bool ScrollLines(int WXUNUSED(lines)) { return FALSE; } | |
728 | virtual bool ScrollPages(int WXUNUSED(pages)) { return FALSE; } | |
729 | ||
730 | // convenient wrappers for ScrollLines/Pages | |
731 | bool LineUp() { return ScrollLines(-1); } | |
732 | bool LineDown() { return ScrollLines(1); } | |
733 | bool PageUp() { return ScrollPages(-1); } | |
734 | bool PageDown() { return ScrollPages(1); } | |
b9b3393e | 735 | |
bd83cb56 VZ |
736 | // context-sensitive help |
737 | // ---------------------- | |
738 | ||
739 | // these are the convenience functions wrapping wxHelpProvider methods | |
740 | ||
741 | #if wxUSE_HELP | |
742 | // associate this help text with this window | |
743 | void SetHelpText(const wxString& text); | |
744 | // associate this help text with all windows with the same id as this | |
745 | // one | |
746 | void SetHelpTextForId(const wxString& text); | |
747 | // get the help string associated with this window (may be empty) | |
748 | wxString GetHelpText() const; | |
749 | #endif // wxUSE_HELP | |
750 | ||
f03fc89f VZ |
751 | // tooltips |
752 | // -------- | |
bd83cb56 | 753 | |
f03fc89f VZ |
754 | #if wxUSE_TOOLTIPS |
755 | // the easiest way to set a tooltip for a window is to use this method | |
756 | void SetToolTip( const wxString &tip ); | |
757 | // attach a tooltip to the window | |
758 | void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); } | |
759 | // get the associated tooltip or NULL if none | |
760 | wxToolTip* GetToolTip() const { return m_tooltip; } | |
761 | #endif // wxUSE_TOOLTIPS | |
762 | ||
763 | // drag and drop | |
764 | // ------------- | |
765 | #if wxUSE_DRAG_AND_DROP | |
766 | // set/retrieve the drop target associated with this window (may be | |
767 | // NULL; it's owned by the window and will be deleted by it) | |
768 | virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0; | |
769 | virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; } | |
770 | #endif // wxUSE_DRAG_AND_DROP | |
771 | ||
772 | // constraints and sizers | |
773 | // ---------------------- | |
774 | #if wxUSE_CONSTRAINTS | |
775 | // set the constraints for this window or retrieve them (may be NULL) | |
776 | void SetConstraints( wxLayoutConstraints *constraints ); | |
777 | wxLayoutConstraints *GetConstraints() const { return m_constraints; } | |
778 | ||
f03fc89f VZ |
779 | // implementation only |
780 | void UnsetConstraints(wxLayoutConstraints *c); | |
781 | wxWindowList *GetConstraintsInvolvedIn() const | |
782 | { return m_constraintsInvolvedIn; } | |
783 | void AddConstraintReference(wxWindowBase *otherWin); | |
784 | void RemoveConstraintReference(wxWindowBase *otherWin); | |
785 | void DeleteRelatedConstraints(); | |
786 | void ResetConstraints(); | |
787 | ||
788 | // these methods may be overriden for special layout algorithms | |
789 | virtual void SetConstraintSizes(bool recurse = TRUE); | |
790 | virtual bool LayoutPhase1(int *noChanges); | |
791 | virtual bool LayoutPhase2(int *noChanges); | |
4b7f2165 | 792 | virtual bool DoPhase(int phase); |
f03fc89f VZ |
793 | |
794 | // these methods are virtual but normally won't be overridden | |
f03fc89f VZ |
795 | virtual void SetSizeConstraint(int x, int y, int w, int h); |
796 | virtual void MoveConstraint(int x, int y); | |
797 | virtual void GetSizeConstraint(int *w, int *h) const ; | |
798 | virtual void GetClientSizeConstraint(int *w, int *h) const ; | |
799 | virtual void GetPositionConstraint(int *x, int *y) const ; | |
800 | ||
461e93f9 JS |
801 | #endif // wxUSE_CONSTRAINTS |
802 | ||
803 | // when using constraints or sizers, it makes sense to update | |
804 | // children positions automatically whenever the window is resized | |
805 | // - this is done if autoLayout is on | |
806 | void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; } | |
807 | bool GetAutoLayout() const { return m_autoLayout; } | |
808 | ||
809 | // lay out the window and its children | |
810 | virtual bool Layout(); | |
811 | ||
f03fc89f | 812 | // sizers |
3aa5d532 | 813 | void SetSizer(wxSizer *sizer, bool deleteOld = TRUE ); |
566d84a7 RL |
814 | void SetSizerAndFit( wxSizer *sizer, bool deleteOld = TRUE ); |
815 | ||
f03fc89f | 816 | wxSizer *GetSizer() const { return m_windowSizer; } |
be90c029 RD |
817 | |
818 | // Track if this window is a member of a sizer | |
819 | void SetContainingSizer(wxSizer* sizer) { m_containingSizer = sizer; } | |
820 | wxSizer *GetContainingSizer() const { return m_containingSizer; } | |
821 | ||
f03fc89f VZ |
822 | // backward compatibility |
823 | // ---------------------- | |
824 | #if WXWIN_COMPATIBILITY | |
825 | bool Enabled() const { return IsEnabled(); } | |
826 | ||
827 | void SetButtonFont(const wxFont& font) { SetFont(font); } | |
828 | void SetLabelFont(const wxFont& font) { SetFont(font); } | |
829 | wxFont& GetLabelFont() { return GetFont(); }; | |
830 | wxFont& GetButtonFont() { return GetFont(); }; | |
831 | #endif // WXWIN_COMPATIBILITY | |
832 | ||
833 | // implementation | |
834 | // -------------- | |
835 | ||
836 | // event handlers | |
837 | void OnSysColourChanged( wxSysColourChangedEvent& event ); | |
838 | void OnInitDialog( wxInitDialogEvent &event ); | |
72fc5caf | 839 | void OnMiddleClick( wxMouseEvent& event ); |
bd83cb56 VZ |
840 | #if wxUSE_HELP |
841 | void OnHelp(wxHelpEvent& event); | |
842 | #endif // wxUSE_HELP | |
f03fc89f | 843 | |
d7c24517 VZ |
844 | // get the haqndle of the window for the underlying window system: this |
845 | // is only used for wxWin itself or for user code which wants to call | |
846 | // platform-specific APIs | |
d22699b5 | 847 | virtual WXWidget GetHandle() const = 0; |
cc2b7472 | 848 | |
574c939e KB |
849 | #if wxUSE_PALETTE |
850 | // Store the palette used by DCs in wxWindow so that the dcs can share | |
851 | // a palette. And we can respond to palette messages. | |
852 | wxPalette GetPalette() const { return m_palette; } | |
b95edd47 | 853 | |
574c939e KB |
854 | // When palette is changed tell the DC to set the system palette to the |
855 | // new one. | |
b95edd47 VZ |
856 | void SetPalette(const wxPalette& pal); |
857 | ||
858 | // return true if we have a specific palette | |
859 | bool HasCustomPalette() const { return m_hasCustomPalette; } | |
860 | ||
861 | // return the first parent window with a custom palette or NULL | |
862 | wxWindow *GetAncestorWithCustomPalette() const; | |
574c939e KB |
863 | #endif // wxUSE_PALETTE |
864 | ||
739730ca | 865 | protected: |
ec5bb70d VZ |
866 | #if wxUSE_CONSTRAINTS |
867 | // satisfy the constraints for the windows but don't set the window sizes | |
868 | void SatisfyConstraints(); | |
869 | #endif // wxUSE_CONSTRAINTS | |
566d84a7 | 870 | |
7af6f327 | 871 | // the window id - a number which uniquely identifies a window among |
d7c24517 | 872 | // its siblings unless it is -1 |
f03fc89f | 873 | wxWindowID m_windowId; |
456bc6d9 | 874 | |
f03fc89f VZ |
875 | // the parent window of this window (or NULL) and the list of the children |
876 | // of this window | |
877 | wxWindow *m_parent; | |
878 | wxWindowList m_children; | |
879 | ||
880 | // the minimal allowed size for the window (no minimal size if variable(s) | |
881 | // contain(s) -1) | |
ec5bb70d VZ |
882 | int m_minWidth, |
883 | m_minHeight, | |
884 | m_maxWidth, | |
885 | m_maxHeight; | |
f03fc89f VZ |
886 | |
887 | // event handler for this window: usually is just 'this' but may be | |
888 | // changed with SetEventHandler() | |
889 | wxEvtHandler *m_eventHandler; | |
890 | ||
88ac883a | 891 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
892 | // associated validator or NULL if none |
893 | wxValidator *m_windowValidator; | |
88ac883a | 894 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
895 | |
896 | #if wxUSE_DRAG_AND_DROP | |
897 | wxDropTarget *m_dropTarget; | |
898 | #endif // wxUSE_DRAG_AND_DROP | |
899 | ||
900 | // visual window attributes | |
901 | wxCursor m_cursor; | |
902 | wxFont m_font; | |
903 | wxColour m_backgroundColour, m_foregroundColour; | |
904 | ||
789295bf VZ |
905 | #if wxUSE_CARET |
906 | wxCaret *m_caret; | |
907 | #endif // wxUSE_CARET | |
908 | ||
f03fc89f VZ |
909 | // the region which should be repainted in response to paint event |
910 | wxRegion m_updateRegion; | |
911 | ||
88ac883a | 912 | #if wxUSE_ACCEL |
f03fc89f VZ |
913 | // the accelerator table for the window which translates key strokes into |
914 | // command events | |
915 | wxAcceleratorTable m_acceleratorTable; | |
88ac883a | 916 | #endif // wxUSE_ACCEL |
f03fc89f | 917 | |
f03fc89f VZ |
918 | // the tooltip for this window (may be NULL) |
919 | #if wxUSE_TOOLTIPS | |
920 | wxToolTip *m_tooltip; | |
921 | #endif // wxUSE_TOOLTIPS | |
922 | ||
923 | // constraints and sizers | |
924 | #if wxUSE_CONSTRAINTS | |
925 | // the constraints for this window or NULL | |
926 | wxLayoutConstraints *m_constraints; | |
927 | ||
928 | // constraints this window is involved in | |
929 | wxWindowList *m_constraintsInvolvedIn; | |
461e93f9 | 930 | #endif // wxUSE_CONSTRAINTS |
f03fc89f | 931 | |
be90c029 | 932 | // this window's sizer |
f03fc89f | 933 | wxSizer *m_windowSizer; |
be90c029 RD |
934 | |
935 | // The sizer this window is a member of, if any | |
936 | wxSizer *m_containingSizer; | |
f03fc89f VZ |
937 | |
938 | // Layout() window automatically when its size changes? | |
939 | bool m_autoLayout:1; | |
f03fc89f VZ |
940 | |
941 | // window state | |
942 | bool m_isShown:1; | |
943 | bool m_isEnabled:1; | |
944 | bool m_isBeingDeleted:1; | |
945 | ||
23895080 VZ |
946 | // was the window colours/font explicitly changed by user? |
947 | bool m_hasBgCol:1; | |
948 | bool m_hasFgCol:1; | |
949 | bool m_hasFont:1; | |
950 | ||
f03fc89f | 951 | // window attributes |
d80cd92a VZ |
952 | long m_windowStyle, |
953 | m_exStyle; | |
f03fc89f | 954 | wxString m_windowName; |
a2d93e73 | 955 | bool m_themeEnabled; |
f03fc89f | 956 | |
071e5fd9 | 957 | #if wxUSE_PALETTE |
574c939e | 958 | wxPalette m_palette; |
b95edd47 VZ |
959 | bool m_hasCustomPalette; |
960 | #endif // wxUSE_PALETTE | |
574c939e | 961 | |
566d84a7 RL |
962 | // Virtual size (scrolling) |
963 | wxSize m_virtualSize; | |
964 | ||
965 | int m_minVirtualWidth; // VirtualSizeHints | |
966 | int m_minVirtualHeight; | |
967 | int m_maxVirtualWidth; | |
968 | int m_maxVirtualHeight; | |
45e0dc94 | 969 | |
f03fc89f VZ |
970 | // common part of all ctors: it is not virtual because it is called from |
971 | // ctor | |
972 | void InitBase(); | |
973 | ||
1e6feb95 VZ |
974 | // override this to change the default (i.e. used when no style is |
975 | // specified) border for the window class | |
976 | virtual wxBorder GetDefaultBorder() const; | |
977 | ||
f03fc89f | 978 | // get the default size for the new window if no explicit size given |
1349f4f2 RR |
979 | // FIXME why 20 and not 30, 10 or ...? |
980 | static int WidthDefault(int w) { return w == -1 ? 20 : w; } | |
981 | static int HeightDefault(int h) { return h == -1 ? 20 : h; } | |
f03fc89f | 982 | |
1e6feb95 VZ |
983 | // set the best size for the control if the default size was given: |
984 | // replaces the fields of size == -1 with the best values for them and | |
985 | // calls SetSize() if needed | |
2b5f62a0 VZ |
986 | // |
987 | // This function is rather unfortunately named.. it's really just a | |
988 | // smarter SetSize / convenience function for expanding wxDefaultSize. | |
989 | // Note that it does not influence the value returned by GetBestSize | |
990 | // at all. | |
1e6feb95 | 991 | void SetBestSize(const wxSize& size) |
f68586e5 | 992 | { |
2b5f62a0 VZ |
993 | // the size only needs to be changed if the current size is incomplete, |
994 | // i.e. one of the components was specified as default -- so if both | |
995 | // were given, simply don't do anything | |
f68586e5 VZ |
996 | if ( size.x == -1 || size.y == -1 ) |
997 | { | |
1e6feb95 VZ |
998 | wxSize sizeBest = DoGetBestSize(); |
999 | if ( size.x != -1 ) | |
1000 | sizeBest.x = size.x; | |
1001 | if ( size.y != -1 ) | |
1002 | sizeBest.y = size.y; | |
1003 | ||
1004 | SetSize(sizeBest); | |
f68586e5 VZ |
1005 | } |
1006 | } | |
1007 | ||
f03fc89f VZ |
1008 | // more pure virtual functions |
1009 | // --------------------------- | |
1010 | ||
1011 | // NB: we must have DoSomething() function when Something() is an overloaded | |
1012 | // method: indeed, we can't just have "virtual Something()" in case when | |
1013 | // the function is overloaded because then we'd have to make virtual all | |
1014 | // the variants (otherwise only the virtual function may be called on a | |
1015 | // pointer to derived class according to C++ rules) which is, in | |
1016 | // general, absolutely not needed. So instead we implement all | |
1017 | // overloaded Something()s in terms of DoSomething() which will be the | |
1018 | // only one to be virtual. | |
1019 | ||
dabc0cd5 VZ |
1020 | // coordinates translation |
1021 | virtual void DoClientToScreen( int *x, int *y ) const = 0; | |
1022 | virtual void DoScreenToClient( int *x, int *y ) const = 0; | |
1023 | ||
1e6feb95 VZ |
1024 | virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const; |
1025 | ||
94633ad9 | 1026 | // capture/release the mouse, used by Capture/ReleaseMouse() |
a83e1475 VZ |
1027 | virtual void DoCaptureMouse() = 0; |
1028 | virtual void DoReleaseMouse() = 0; | |
be90c029 | 1029 | |
f03fc89f VZ |
1030 | // retrieve the position/size of the window |
1031 | virtual void DoGetPosition( int *x, int *y ) const = 0; | |
1032 | virtual void DoGetSize( int *width, int *height ) const = 0; | |
1033 | virtual void DoGetClientSize( int *width, int *height ) const = 0; | |
1034 | ||
f68586e5 VZ |
1035 | // get the size which best suits the window: for a control, it would be |
1036 | // the minimal size which doesn't truncate the control, for a panel - the | |
1037 | // same size as it would have after a call to Fit() | |
1038 | virtual wxSize DoGetBestSize() const; | |
1039 | ||
f03fc89f VZ |
1040 | // this is the virtual function to be overriden in any derived class which |
1041 | // wants to change how SetSize() or Move() works - it is called by all | |
1042 | // versions of these functions in the base class | |
1043 | virtual void DoSetSize(int x, int y, | |
1044 | int width, int height, | |
1045 | int sizeFlags = wxSIZE_AUTO) = 0; | |
1046 | ||
1047 | // same as DoSetSize() for the client size | |
1048 | virtual void DoSetClientSize(int width, int height) = 0; | |
1049 | ||
9d9b7755 VZ |
1050 | // move the window to the specified location and resize it: this is called |
1051 | // from both DoSetSize() and DoSetClientSize() and would usually just | |
1052 | // reposition this window except for composite controls which will want to | |
1053 | // arrange themselves inside the given rectangle | |
1054 | virtual void DoMoveWindow(int x, int y, int width, int height) = 0; | |
1055 | ||
f03fc89f VZ |
1056 | #if wxUSE_TOOLTIPS |
1057 | virtual void DoSetToolTip( wxToolTip *tip ); | |
1058 | #endif // wxUSE_TOOLTIPS | |
1059 | ||
1e6feb95 | 1060 | #if wxUSE_MENUS |
a1665b22 | 1061 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0; |
1e6feb95 | 1062 | #endif // wxUSE_MENUS |
a1665b22 | 1063 | |
a200c35e VS |
1064 | // Makes an adjustment to the window position (for example, a frame that has |
1065 | // a toolbar that it manages itself). | |
20a1eea1 | 1066 | virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const; |
8d99be5f | 1067 | |
45e0dc94 | 1068 | |
f03fc89f | 1069 | private: |
45e0dc94 | 1070 | |
f03fc89f VZ |
1071 | // contains the last id generated by NewControlId |
1072 | static int ms_lastControlId; | |
1073 | ||
a83e1475 VZ |
1074 | // the stack of windows which have captured the mouse |
1075 | static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext; | |
1076 | ||
1e6feb95 VZ |
1077 | DECLARE_ABSTRACT_CLASS(wxWindowBase) |
1078 | DECLARE_NO_COPY_CLASS(wxWindowBase) | |
f03fc89f VZ |
1079 | DECLARE_EVENT_TABLE() |
1080 | }; | |
1081 | ||
1082 | // ---------------------------------------------------------------------------- | |
1083 | // now include the declaration of wxWindow class | |
1084 | // ---------------------------------------------------------------------------- | |
1085 | ||
1e6feb95 | 1086 | // include the declaration of the platform-specific class |
2049ba38 | 1087 | #if defined(__WXMSW__) |
a5b3669d VZ |
1088 | #ifdef __WXUNIVERSAL__ |
1089 | #define wxWindowNative wxWindowMSW | |
1090 | #else // !wxUniv | |
1e6feb95 VZ |
1091 | #define wxWindowMSW wxWindow |
1092 | #define sm_classwxWindowMSW sm_classwxWindow | |
a5b3669d | 1093 | #endif // wxUniv/!wxUniv |
f03fc89f | 1094 | #include "wx/msw/window.h" |
2049ba38 | 1095 | #elif defined(__WXMOTIF__) |
f03fc89f | 1096 | #include "wx/motif/window.h" |
2049ba38 | 1097 | #elif defined(__WXGTK__) |
a5b3669d VZ |
1098 | #ifdef __WXUNIVERSAL__ |
1099 | #define wxWindowNative wxWindowGTK | |
1100 | #else // !wxUniv | |
1e6feb95 VZ |
1101 | #define wxWindowGTK wxWindow |
1102 | #define sm_classwxWindowGTK sm_classwxWindow | |
1103 | #endif // wxUniv | |
f03fc89f | 1104 | #include "wx/gtk/window.h" |
83df96d6 JS |
1105 | #elif defined(__WXX11__) |
1106 | #ifdef __WXUNIVERSAL__ | |
1107 | #define wxWindowNative wxWindowX11 | |
1108 | #else // !wxUniv | |
1109 | #define wxWindowX11 wxWindow | |
1110 | #define sm_classwxWindowX11 sm_classwxWindow | |
1111 | #endif // wxUniv | |
1112 | #include "wx/x11/window.h" | |
711c76db | 1113 | #elif defined(__WXMGL__) |
386c7058 VS |
1114 | #ifdef __WXUNIVERSAL__ |
1115 | #define wxWindowNative wxWindowMGL | |
1116 | #else // !wxUniv | |
1117 | #define wxWindowMGL wxWindow | |
1118 | #define sm_classwxWindowMGL sm_classwxWindow | |
1119 | #endif // wxUniv | |
1120 | #include "wx/mgl/window.h" | |
34138703 | 1121 | #elif defined(__WXMAC__) |
e766c8a9 SC |
1122 | #ifdef __WXUNIVERSAL__ |
1123 | #define wxWindowNative wxWindowMac | |
1124 | #else // !wxUniv | |
1125 | #define wxWindowMac wxWindow | |
1126 | #define sm_classwxWindowMac sm_classwxWindow | |
1127 | #endif // wxUniv | |
f03fc89f | 1128 | #include "wx/mac/window.h" |
1777b9bb | 1129 | #elif defined(__WXPM__) |
210a651b DW |
1130 | #ifdef __WXUNIVERSAL__ |
1131 | #define wxWindowNative wxWindowOS2 | |
1132 | #else // !wxUniv | |
1133 | #define wxWindowOS2 wxWindow | |
1134 | #define sm_classwxWindowOS2 sm_classwxWindow | |
1135 | #endif // wxUniv/!wxUniv | |
1777b9bb | 1136 | #include "wx/os2/window.h" |
c801d85f KB |
1137 | #endif |
1138 | ||
1e6feb95 VZ |
1139 | // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>, |
1140 | // for the native ports we already have defined it above | |
1141 | #if defined(__WXUNIVERSAL__) | |
a5b3669d VZ |
1142 | #ifndef wxWindowNative |
1143 | #error "wxWindowNative must be defined above!" | |
1144 | #endif | |
1145 | ||
1e6feb95 VZ |
1146 | #include "wx/univ/window.h" |
1147 | #endif // wxUniv | |
1148 | ||
f03fc89f VZ |
1149 | // ---------------------------------------------------------------------------- |
1150 | // inline functions which couldn't be declared in the class body because of | |
1151 | // forward dependencies | |
1152 | // ---------------------------------------------------------------------------- | |
1153 | ||
bacd69f9 | 1154 | inline wxWindow *wxWindowBase::GetGrandParent() const |
f03fc89f VZ |
1155 | { |
1156 | return m_parent ? m_parent->GetParent() : (wxWindow *)NULL; | |
1157 | } | |
1158 | ||
1159 | // ---------------------------------------------------------------------------- | |
3723b7b1 | 1160 | // global functions |
f03fc89f VZ |
1161 | // ---------------------------------------------------------------------------- |
1162 | ||
3723b7b1 JS |
1163 | // Find the wxWindow at the current mouse position, also returning the mouse |
1164 | // position. | |
1165 | WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt); | |
1166 | ||
1167 | // Get the current mouse position. | |
1168 | WXDLLEXPORT extern wxPoint wxGetMousePosition(); | |
1169 | ||
1e6feb95 VZ |
1170 | // get the currently active window of this application or NULL |
1171 | WXDLLEXPORT extern wxWindow *wxGetActiveWindow(); | |
1172 | ||
33b494d6 VZ |
1173 | // get the (first) top level parent window |
1174 | WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win); | |
1175 | ||
f68586e5 | 1176 | // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId() |
6d56eb5c | 1177 | inline int NewControlId() { return wxWindowBase::NewControlId(); } |
f03fc89f | 1178 | |
c801d85f | 1179 | #endif |
34138703 | 1180 | // _WX_WINDOW_H_BASE_ |
34c3ffca | 1181 |