added wxWindow::NavigateIn(); provide wxGTK implementation of DoNavigateIn() working...
[wxWidgets.git] / include / wx / window.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/window.h
3 // Purpose: wxWindowBase class - the interface of wxWindow
4 // Author: Vadim Zeitlin
5 // Modified by: Ron Lee
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers which we must include here
17 // ----------------------------------------------------------------------------
18
19 #include "wx/event.h" // the base class
20
21 #include "wx/list.h" // defines wxWindowList
22
23 #include "wx/cursor.h" // we have member variables of these classes
24 #include "wx/font.h" // so we can't do without them
25 #include "wx/colour.h"
26 #include "wx/region.h"
27 #include "wx/utils.h"
28 #include "wx/intl.h"
29
30 #include "wx/validate.h" // for wxDefaultValidator (always include it)
31
32 #if wxUSE_PALETTE
33 #include "wx/palette.h"
34 #endif // wxUSE_PALETTE
35
36 #if wxUSE_ACCEL
37 #include "wx/accel.h"
38 #endif // wxUSE_ACCEL
39
40 #if wxUSE_ACCESSIBILITY
41 #include "wx/access.h"
42 #endif
43
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 // !__WXUNIVERSAL__
49 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
50 #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__
51
52
53 // Define this macro if the corresponding operating system handles the state
54 // of children windows automatically when the parent is enabled/disabled.
55 // Otherwise wx itself must ensure that when the parent is disabled its
56 // children are disabled too, and their initial state is restored when the
57 // parent is enabled back.
58 #if defined(__WXMSW__) || defined(__WXPM__)
59 // must do everything ourselves
60 #undef wxHAS_NATIVE_ENABLED_MANAGEMENT
61 #else
62 #define wxHAS_NATIVE_ENABLED_MANAGEMENT
63 #endif
64
65 // This is defined when the underlying toolkit handles tab traversal natively
66 // (currently this only works under GTK+ 2)
67 #ifdef __WXGTK20__
68 #define wxHAS_NATIVE_TAB_TRAVERSAL
69 #endif
70
71 // ----------------------------------------------------------------------------
72 // forward declarations
73 // ----------------------------------------------------------------------------
74
75 class WXDLLEXPORT wxCaret;
76 class WXDLLEXPORT wxControl;
77 class WXDLLEXPORT wxCursor;
78 class WXDLLEXPORT wxDC;
79 class WXDLLEXPORT wxDropTarget;
80 class WXDLLEXPORT wxItemResource;
81 class WXDLLEXPORT wxLayoutConstraints;
82 class WXDLLEXPORT wxResourceTable;
83 class WXDLLEXPORT wxSizer;
84 class WXDLLEXPORT wxToolTip;
85 class WXDLLEXPORT wxWindowBase;
86 class WXDLLEXPORT wxWindow;
87 class WXDLLEXPORT wxScrollHelper;
88
89 #if wxUSE_ACCESSIBILITY
90 class WXDLLEXPORT wxAccessible;
91 #endif
92
93 // ----------------------------------------------------------------------------
94 // helper stuff used by wxWindow
95 // ----------------------------------------------------------------------------
96
97 // struct containing all the visual attributes of a control
98 struct WXDLLEXPORT wxVisualAttributes
99 {
100 // the font used for control label/text inside it
101 wxFont font;
102
103 // the foreground colour
104 wxColour colFg;
105
106 // the background colour, may be wxNullColour if the controls background
107 // colour is not solid
108 wxColour colBg;
109 };
110
111 // different window variants, on platforms like eg mac uses different
112 // rendering sizes
113 enum wxWindowVariant
114 {
115 wxWINDOW_VARIANT_NORMAL, // Normal size
116 wxWINDOW_VARIANT_SMALL, // Smaller size (about 25 % smaller than normal)
117 wxWINDOW_VARIANT_MINI, // Mini size (about 33 % smaller than normal)
118 wxWINDOW_VARIANT_LARGE, // Large size (about 25 % larger than normal)
119 wxWINDOW_VARIANT_MAX
120 };
121
122 #if wxUSE_SYSTEM_OPTIONS
123 #define wxWINDOW_DEFAULT_VARIANT wxT("window-default-variant")
124 #endif
125
126 // ----------------------------------------------------------------------------
127 // (pseudo)template list classes
128 // ----------------------------------------------------------------------------
129
130 WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT);
131
132 // ----------------------------------------------------------------------------
133 // global variables
134 // ----------------------------------------------------------------------------
135
136 extern WXDLLEXPORT_DATA(wxWindowList) wxTopLevelWindows;
137 extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete;
138
139 // ----------------------------------------------------------------------------
140 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
141 // interface of this class.
142 //
143 // Event handler: windows have themselves as their event handlers by default,
144 // but their event handlers could be set to another object entirely. This
145 // separation can reduce the amount of derivation required, and allow
146 // alteration of a window's functionality (e.g. by a resource editor that
147 // temporarily switches event handlers).
148 // ----------------------------------------------------------------------------
149
150 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
151 {
152 public:
153 // creating the window
154 // -------------------
155
156 // default ctor, initializes everything which can be initialized before
157 // Create()
158 wxWindowBase() ;
159
160 // pseudo ctor (can't be virtual, called from ctor)
161 bool CreateBase(wxWindowBase *parent,
162 wxWindowID winid,
163 const wxPoint& pos = wxDefaultPosition,
164 const wxSize& size = wxDefaultSize,
165 long style = 0,
166 const wxValidator& validator = wxDefaultValidator,
167 const wxString& name = wxPanelNameStr);
168
169 virtual ~wxWindowBase();
170
171 // deleting the window
172 // -------------------
173
174 // ask the window to close itself, return true if the event handler
175 // honoured our request
176 bool Close( bool force = false );
177
178 // the following functions delete the C++ objects (the window itself
179 // or its children) as well as the GUI windows and normally should
180 // never be used directly
181
182 // delete window unconditionally (dangerous!), returns true if ok
183 virtual bool Destroy();
184 // delete all children of this window, returns true if ok
185 bool DestroyChildren();
186
187 // is the window being deleted?
188 bool IsBeingDeleted() const { return m_isBeingDeleted; }
189
190 // window attributes
191 // -----------------
192
193 // label is just the same as the title (but for, e.g., buttons it
194 // makes more sense to speak about labels), title access
195 // is available from wxTLW classes only (frames, dialogs)
196 virtual void SetLabel(const wxString& label) = 0;
197 virtual wxString GetLabel() const = 0;
198
199 // the window name is used for ressource setting in X, it is not the
200 // same as the window title/label
201 virtual void SetName( const wxString &name ) { m_windowName = name; }
202 virtual wxString GetName() const { return m_windowName; }
203
204 // sets the window variant, calls internally DoSetVariant if variant
205 // has changed
206 void SetWindowVariant(wxWindowVariant variant);
207 wxWindowVariant GetWindowVariant() const { return m_windowVariant; }
208
209
210 // window id uniquely identifies the window among its siblings unless
211 // it is wxID_ANY which means "don't care"
212 void SetId( wxWindowID winid ) { m_windowId = winid; }
213 wxWindowID GetId() const { return m_windowId; }
214
215 // get or change the layout direction (LTR or RTL) for this window,
216 // wxLayout_Default is returned if layout direction is not supported
217 virtual wxLayoutDirection GetLayoutDirection() const
218 { return wxLayout_Default; }
219 virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir))
220 { }
221
222 // mirror coordinates for RTL layout if this window uses it and if the
223 // mirroring is not done automatically like Win32
224 virtual wxCoord AdjustForLayoutDirection(wxCoord x,
225 wxCoord width,
226 wxCoord widthTotal) const;
227
228 // generate a control id for the controls which were not given one by
229 // user
230 static int NewControlId() { return --ms_lastControlId; }
231 // get the id of the control following the one with the given
232 // (autogenerated) id
233 static int NextControlId(int winid) { return winid - 1; }
234 // get the id of the control preceding the one with the given
235 // (autogenerated) id
236 static int PrevControlId(int winid) { return winid + 1; }
237
238 // moving/resizing
239 // ---------------
240
241 // set the window size and/or position
242 void SetSize( int x, int y, int width, int height,
243 int sizeFlags = wxSIZE_AUTO )
244 { DoSetSize(x, y, width, height, sizeFlags); }
245
246 void SetSize( int width, int height )
247 { DoSetSize( wxDefaultCoord, wxDefaultCoord, width, height, wxSIZE_USE_EXISTING ); }
248
249 void SetSize( const wxSize& size )
250 { SetSize( size.x, size.y); }
251
252 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
253 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
254
255 void Move(int x, int y, int flags = wxSIZE_USE_EXISTING)
256 { DoSetSize(x, y, wxDefaultCoord, wxDefaultCoord, flags); }
257
258 void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
259 { Move(pt.x, pt.y, flags); }
260
261 void SetPosition(const wxPoint& pt) { Move(pt); }
262
263 // Z-order
264 virtual void Raise() = 0;
265 virtual void Lower() = 0;
266
267 // client size is the size of area available for subwindows
268 void SetClientSize( int width, int height )
269 { DoSetClientSize(width, height); }
270
271 void SetClientSize( const wxSize& size )
272 { DoSetClientSize(size.x, size.y); }
273
274 void SetClientSize(const wxRect& rect)
275 { SetClientSize( rect.width, rect.height ); }
276
277 // get the window position (pointers may be NULL): notice that it is in
278 // client coordinates for child windows and screen coordinates for the
279 // top level ones, use GetScreenPosition() if you need screen
280 // coordinates for all kinds of windows
281 void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); }
282 wxPoint GetPosition() const
283 {
284 int x, y;
285 DoGetPosition(&x, &y);
286
287 return wxPoint(x, y);
288 }
289
290 // get the window position in screen coordinates
291 void GetScreenPosition(int *x, int *y) const { DoGetScreenPosition(x, y); }
292 wxPoint GetScreenPosition() const
293 {
294 int x, y;
295 DoGetScreenPosition(&x, &y);
296
297 return wxPoint(x, y);
298 }
299
300 // get the window size (pointers may be NULL)
301 void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
302 wxSize GetSize() const
303 {
304 int w, h;
305 DoGetSize(& w, & h);
306 return wxSize(w, h);
307 }
308
309 void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
310 wxSize GetClientSize() const
311 {
312 int w, h;
313 DoGetClientSize(&w, &h);
314
315 return wxSize(w, h);
316 }
317
318 // get the position and size at once
319 wxRect GetRect() const
320 {
321 int x, y, w, h;
322 GetPosition(&x, &y);
323 GetSize(&w, &h);
324
325 return wxRect(x, y, w, h);
326 }
327
328 wxRect GetScreenRect() const
329 {
330 int x, y, w, h;
331 GetScreenPosition(&x, &y);
332 GetSize(&w, &h);
333
334 return wxRect(x, y, w, h);
335 }
336
337 // get the origin of the client area of the window relative to the
338 // window top left corner (the client area may be shifted because of
339 // the borders, scrollbars, other decorations...)
340 virtual wxPoint GetClientAreaOrigin() const;
341
342 // get the client rectangle in window (i.e. client) coordinates
343 wxRect GetClientRect() const
344 {
345 return wxRect(GetClientAreaOrigin(), GetClientSize());
346 }
347
348 // get the size best suited for the window (in fact, minimal
349 // acceptable size using which it will still look "nice" in
350 // most situations)
351 wxSize GetBestSize() const
352 {
353 if (m_bestSizeCache.IsFullySpecified())
354 return m_bestSizeCache;
355 return DoGetBestSize();
356 }
357 void GetBestSize(int *w, int *h) const
358 {
359 wxSize s = GetBestSize();
360 if ( w )
361 *w = s.x;
362 if ( h )
363 *h = s.y;
364 }
365
366 void SetScrollHelper( wxScrollHelper *sh ) { m_scrollHelper = sh; }
367 wxScrollHelper *GetScrollHelper() { return m_scrollHelper; }
368
369 // reset the cached best size value so it will be recalculated the
370 // next time it is needed.
371 void InvalidateBestSize();
372 void CacheBestSize(const wxSize& size) const
373 { wxConstCast(this, wxWindowBase)->m_bestSizeCache = size; }
374
375
376 // This function will merge the window's best size into the window's
377 // minimum size, giving priority to the min size components, and
378 // returns the results.
379 wxSize GetEffectiveMinSize() const;
380 wxDEPRECATED( wxSize GetBestFittingSize() const ); // replaced by GetEffectiveMinSize
381 wxDEPRECATED( wxSize GetAdjustedMinSize() const ); // replaced by GetEffectiveMinSize
382
383 // A 'Smart' SetSize that will fill in default size values with 'best'
384 // size. Sets the minsize to what was passed in.
385 void SetInitialSize(const wxSize& size=wxDefaultSize);
386 wxDEPRECATED( void SetBestFittingSize(const wxSize& size=wxDefaultSize) ); // replaced by SetInitialSize
387
388
389 // the generic centre function - centers the window on parent by`
390 // default or on screen if it doesn't have parent or
391 // wxCENTER_ON_SCREEN flag is given
392 void Centre(int dir = wxBOTH) { DoCentre(dir); }
393 void Center(int dir = wxBOTH) { DoCentre(dir); }
394
395 // centre with respect to the the parent window
396 void CentreOnParent(int dir = wxBOTH) { DoCentre(dir); }
397 void CenterOnParent(int dir = wxBOTH) { CentreOnParent(dir); }
398
399 // set window size to wrap around its children
400 virtual void Fit();
401
402 // set virtual size to satisfy children
403 virtual void FitInside();
404
405
406 // SetSizeHints is actually for setting the size hints
407 // for the wxTLW for a Window Manager - hence the name -
408 // and it is therefore overridden in wxTLW to do that.
409 // In wxWindow(Base), it has (unfortunately) been abused
410 // to mean the same as SetMinSize() and SetMaxSize().
411
412 virtual void SetSizeHints( int minW, int minH,
413 int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
414 int incW = wxDefaultCoord, int incH = wxDefaultCoord )
415 { DoSetSizeHints(minW, minH, maxW, maxH, incW, incH); }
416
417 void SetSizeHints( const wxSize& minSize,
418 const wxSize& maxSize=wxDefaultSize,
419 const wxSize& incSize=wxDefaultSize)
420 { DoSetSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y, incSize.x, incSize.y); }
421
422 virtual void DoSetSizeHints( int minW, int minH,
423 int maxW, int maxH,
424 int incW, int incH );
425
426 // Methods for setting virtual size hints
427 // FIXME: What are virtual size hints?
428
429 virtual void SetVirtualSizeHints( int minW, int minH,
430 int maxW = wxDefaultCoord, int maxH = wxDefaultCoord );
431 void SetVirtualSizeHints( const wxSize& minSize,
432 const wxSize& maxSize=wxDefaultSize)
433 {
434 SetVirtualSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y);
435 }
436
437
438 // Call these to override what GetBestSize() returns. This
439 // method is only virtual because it is overriden in wxTLW
440 // as a different API for SetSizeHints().
441 virtual void SetMinSize(const wxSize& minSize) { m_minWidth = minSize.x; m_minHeight = minSize.y; }
442 virtual void SetMaxSize(const wxSize& maxSize) { m_maxWidth = maxSize.x; m_maxHeight = maxSize.y; }
443
444 // Override these methods to impose restrictions on min/max size.
445 // The easier way is to call SetMinSize() and SetMaxSize() which
446 // will have the same effect. Doing both is non-sense.
447 virtual wxSize GetMinSize() const { return wxSize(m_minWidth, m_minHeight); }
448 virtual wxSize GetMaxSize() const { return wxSize(m_maxWidth, m_maxHeight); }
449
450 // Get the min and max values one by one
451 int GetMinWidth() const { return GetMinSize().x; }
452 int GetMinHeight() const { return GetMinSize().y; }
453 int GetMaxWidth() const { return GetMaxSize().x; }
454 int GetMaxHeight() const { return GetMaxSize().y; }
455
456
457 // Methods for accessing the virtual size of a window. For most
458 // windows this is just the client area of the window, but for
459 // some like scrolled windows it is more or less independent of
460 // the screen window size. You may override the DoXXXVirtual
461 // methods below for classes where that is is the case.
462
463 void SetVirtualSize( const wxSize &size ) { DoSetVirtualSize( size.x, size.y ); }
464 void SetVirtualSize( int x, int y ) { DoSetVirtualSize( x, y ); }
465
466 wxSize GetVirtualSize() const { return DoGetVirtualSize(); }
467 void GetVirtualSize( int *x, int *y ) const
468 {
469 wxSize s( DoGetVirtualSize() );
470
471 if( x )
472 *x = s.GetWidth();
473 if( y )
474 *y = s.GetHeight();
475 }
476
477 // Override these methods for windows that have a virtual size
478 // independent of their client size. eg. the virtual area of a
479 // wxScrolledWindow.
480
481 virtual void DoSetVirtualSize( int x, int y );
482 virtual wxSize DoGetVirtualSize() const;
483
484 // Return the largest of ClientSize and BestSize (as determined
485 // by a sizer, interior children, or other means)
486
487 virtual wxSize GetBestVirtualSize() const
488 {
489 wxSize client( GetClientSize() );
490 wxSize best( GetBestSize() );
491
492 return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) );
493 }
494
495 // return the size of the left/right and top/bottom borders in x and y
496 // components of the result respectively
497 virtual wxSize GetWindowBorderSize() const;
498
499
500 // window state
501 // ------------
502
503 // returns true if window was shown/hidden, false if the nothing was
504 // done (window was already shown/hidden)
505 virtual bool Show( bool show = true );
506 bool Hide() { return Show(false); }
507
508 // returns true if window was enabled/disabled, false if nothing done
509 virtual bool Enable( bool enable = true );
510 bool Disable() { return Enable(false); }
511
512 virtual bool IsShown() const { return m_isShown; }
513 // returns true if the window is really enabled and false otherwise,
514 // whether because it had been explicitly disabled itself or because
515 // its parent is currently disabled -- then this method returns false
516 // whatever is the intrinsic state of this window, use IsThisEnabled(0
517 // to retrieve it. In other words, this relation always holds:
518 //
519 // IsEnabled() == IsThisEnabled() && parent.IsEnabled()
520 //
521 bool IsEnabled() const;
522
523 // returns the internal window state independently of the parent(s)
524 // state, i.e. the state in which the window would be if all its
525 // parents were enabled (use IsEnabled() above to get the effective
526 // window state)
527 bool IsThisEnabled() const { return m_isEnabled; }
528
529 // returns true if the window is visible, i.e. IsShown() returns true
530 // if called on it and all its parents up to the first TLW
531 virtual bool IsShownOnScreen() const;
532
533 // get/set window style (setting style won't update the window and so
534 // is only useful for internal usage)
535 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
536 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
537
538 // just some (somewhat shorter) synonims
539 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
540 long GetWindowStyle() const { return GetWindowStyleFlag(); }
541
542 // check if the flag is set
543 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
544 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
545
546 // turn the flag on if it had been turned off before and vice versa,
547 // return true if the flag is currently turned on
548 bool ToggleWindowStyle(int flag);
549
550 // extra style: the less often used style bits which can't be set with
551 // SetWindowStyleFlag()
552 virtual void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
553 long GetExtraStyle() const { return m_exStyle; }
554
555 // make the window modal (all other windows unresponsive)
556 virtual void MakeModal(bool modal = true);
557
558
559 // (primitive) theming support
560 // ---------------------------
561
562 virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
563 virtual bool GetThemeEnabled() const { return m_themeEnabled; }
564
565
566 // focus and keyboard handling
567 // ---------------------------
568
569 // set focus to this window
570 virtual void SetFocus() = 0;
571
572 // set focus to this window as the result of a keyboard action
573 virtual void SetFocusFromKbd() { SetFocus(); }
574
575 // return the window which currently has the focus or NULL
576 static wxWindow *FindFocus();
577
578 static wxWindow *DoFindFocus() /* = 0: implement in derived classes */;
579
580 // can this window have focus in principle?
581 //
582 // the difference between AcceptsFocus[FromKeyboard]() and CanAcceptFocus
583 // [FromKeyboard]() is that the former functions are meant to be
584 // overridden in the derived classes to simply return false if the
585 // control can't have focus, while the latter are meant to be used by
586 // this class clients and take into account the current window state
587 virtual bool AcceptsFocus() const { return true; }
588
589 // can this window have focus right now?
590 bool CanAcceptFocus() const { return AcceptsFocus() && IsShown() && IsEnabled(); }
591
592 // can this window be given focus by keyboard navigation? if not, the
593 // only way to give it focus (provided it accepts it at all) is to
594 // click it
595 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
596
597 // can this window be assigned focus from keyboard right now?
598 bool CanAcceptFocusFromKeyboard() const
599 { return AcceptsFocusFromKeyboard() && CanAcceptFocus(); }
600
601 // navigates inside this window
602 bool NavigateIn(int flags = wxNavigationKeyEvent::IsForward)
603 { return DoNavigateIn(flags); }
604
605 // navigates in the specified direction from this window, this is
606 // equivalent to GetParent()->NavigateIn()
607 bool Navigate(int flags = wxNavigationKeyEvent::IsForward)
608 { return m_parent && ((wxWindowBase *)m_parent)->DoNavigateIn(flags); }
609
610 // move this window just before/after the specified one in tab order
611 // (the other window must be our sibling!)
612 void MoveBeforeInTabOrder(wxWindow *win)
613 { DoMoveInTabOrder(win, MoveBefore); }
614 void MoveAfterInTabOrder(wxWindow *win)
615 { DoMoveInTabOrder(win, MoveAfter); }
616
617
618 // parent/children relations
619 // -------------------------
620
621 // get the list of children
622 const wxWindowList& GetChildren() const { return m_children; }
623 wxWindowList& GetChildren() { return m_children; }
624
625 // needed just for extended runtime
626 const wxWindowList& GetWindowChildren() const { return GetChildren() ; }
627
628 // get the parent or the parent of the parent
629 wxWindow *GetParent() const { return m_parent; }
630 inline wxWindow *GetGrandParent() const;
631
632 // is this window a top level one?
633 virtual bool IsTopLevel() const;
634
635 // it doesn't really change parent, use Reparent() instead
636 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
637 // change the real parent of this window, return true if the parent
638 // was changed, false otherwise (error or newParent == oldParent)
639 virtual bool Reparent( wxWindowBase *newParent );
640
641 // implementation mostly
642 virtual void AddChild( wxWindowBase *child );
643 virtual void RemoveChild( wxWindowBase *child );
644
645 // looking for windows
646 // -------------------
647
648 // find window among the descendants of this one either by id or by
649 // name (return NULL if not found)
650 wxWindow *FindWindow(long winid) const;
651 wxWindow *FindWindow(const wxString& name) const;
652
653 // Find a window among any window (all return NULL if not found)
654 static wxWindow *FindWindowById( long winid, const wxWindow *parent = NULL );
655 static wxWindow *FindWindowByName( const wxString& name,
656 const wxWindow *parent = NULL );
657 static wxWindow *FindWindowByLabel( const wxString& label,
658 const wxWindow *parent = NULL );
659
660 // event handler stuff
661 // -------------------
662
663 // get the current event handler
664 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
665
666 // replace the event handler (allows to completely subclass the
667 // window)
668 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
669
670 // push/pop event handler: allows to chain a custom event handler to
671 // alreasy existing ones
672 void PushEventHandler( wxEvtHandler *handler );
673 wxEvtHandler *PopEventHandler( bool deleteHandler = false );
674
675 // find the given handler in the event handler chain and remove (but
676 // not delete) it from the event handler chain, return true if it was
677 // found and false otherwise (this also results in an assert failure so
678 // this function should only be called when the handler is supposed to
679 // be there)
680 bool RemoveEventHandler(wxEvtHandler *handler);
681
682 // validators
683 // ----------
684
685 #if wxUSE_VALIDATORS
686 // a window may have an associated validator which is used to control
687 // user input
688 virtual void SetValidator( const wxValidator &validator );
689 virtual wxValidator *GetValidator() { return m_windowValidator; }
690 #endif // wxUSE_VALIDATORS
691
692
693 // dialog oriented functions
694 // -------------------------
695
696 // validate the correctness of input, return true if ok
697 virtual bool Validate();
698
699 // transfer data between internal and GUI representations
700 virtual bool TransferDataToWindow();
701 virtual bool TransferDataFromWindow();
702
703 virtual void InitDialog();
704
705 #if wxUSE_ACCEL
706 // accelerators
707 // ------------
708 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
709 { m_acceleratorTable = accel; }
710 wxAcceleratorTable *GetAcceleratorTable()
711 { return &m_acceleratorTable; }
712
713 #endif // wxUSE_ACCEL
714
715 #if wxUSE_HOTKEY
716 // hot keys (system wide accelerators)
717 // -----------------------------------
718
719 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
720 virtual bool UnregisterHotKey(int hotkeyId);
721 #endif // wxUSE_HOTKEY
722
723
724 // dialog units translations
725 // -------------------------
726
727 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
728 wxPoint ConvertDialogToPixels( const wxPoint& pt );
729 wxSize ConvertPixelsToDialog( const wxSize& sz )
730 {
731 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
732
733 return wxSize(pt.x, pt.y);
734 }
735
736 wxSize ConvertDialogToPixels( const wxSize& sz )
737 {
738 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
739
740 return wxSize(pt.x, pt.y);
741 }
742
743 // mouse functions
744 // ---------------
745
746 // move the mouse to the specified position
747 virtual void WarpPointer(int x, int y) = 0;
748
749 // start or end mouse capture, these functions maintain the stack of
750 // windows having captured the mouse and after calling ReleaseMouse()
751 // the mouse is not released but returns to the window which had had
752 // captured it previously (if any)
753 void CaptureMouse();
754 void ReleaseMouse();
755
756 // get the window which currently captures the mouse or NULL
757 static wxWindow *GetCapture();
758
759 // does this window have the capture?
760 virtual bool HasCapture() const
761 { return (wxWindow *)this == GetCapture(); }
762
763 // painting the window
764 // -------------------
765
766 // mark the specified rectangle (or the whole window) as "dirty" so it
767 // will be repainted
768 virtual void Refresh( bool eraseBackground = true,
769 const wxRect *rect = (const wxRect *) NULL ) = 0;
770
771 // a less awkward wrapper for Refresh
772 void RefreshRect(const wxRect& rect, bool eraseBackground = true)
773 {
774 Refresh(eraseBackground, &rect);
775 }
776
777 // repaint all invalid areas of the window immediately
778 virtual void Update() { }
779
780 // clear the window background
781 virtual void ClearBackground();
782
783 // freeze the window: don't redraw it until it is thawed
784 virtual void Freeze() { }
785
786 // thaw the window: redraw it after it had been frozen
787 virtual void Thaw() { }
788
789 // return true if window had been frozen and not unthawed yet
790 virtual bool IsFrozen() const { return false; }
791
792 // adjust DC for drawing on this window
793 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
794
795 // return true if the window contents is double buffered by the system
796 virtual bool IsDoubleBuffered() const { return false; }
797
798 // the update region of the window contains the areas which must be
799 // repainted by the program
800 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
801 wxRegion& GetUpdateRegion() { return m_updateRegion; }
802
803 // get the update rectangleregion bounding box in client coords
804 wxRect GetUpdateClientRect() const;
805
806 // these functions verify whether the given point/rectangle belongs to
807 // (or at least intersects with) the update region
808 virtual bool DoIsExposed( int x, int y ) const;
809 virtual bool DoIsExposed( int x, int y, int w, int h ) const;
810
811 bool IsExposed( int x, int y ) const
812 { return DoIsExposed(x, y); }
813 bool IsExposed( int x, int y, int w, int h ) const
814 { return DoIsExposed(x, y, w, h); }
815 bool IsExposed( const wxPoint& pt ) const
816 { return DoIsExposed(pt.x, pt.y); }
817 bool IsExposed( const wxRect& rect ) const
818 { return DoIsExposed(rect.x, rect.y, rect.width, rect.height); }
819
820 // colours, fonts and cursors
821 // --------------------------
822
823 // get the default attributes for the controls of this class: we
824 // provide a virtual function which can be used to query the default
825 // attributes of an existing control and a static function which can
826 // be used even when no existing object of the given class is
827 // available, but which won't return any styles specific to this
828 // particular control, of course (e.g. "Ok" button might have
829 // different -- bold for example -- font)
830 virtual wxVisualAttributes GetDefaultAttributes() const
831 {
832 return GetClassDefaultAttributes(GetWindowVariant());
833 }
834
835 static wxVisualAttributes
836 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
837
838 // set/retrieve the window colours (system defaults are used by
839 // default): SetXXX() functions return true if colour was changed,
840 // SetDefaultXXX() reset the "m_inheritXXX" flag after setting the
841 // value to prevent it from being inherited by our children
842 virtual bool SetBackgroundColour(const wxColour& colour);
843 void SetOwnBackgroundColour(const wxColour& colour)
844 {
845 if ( SetBackgroundColour(colour) )
846 m_inheritBgCol = false;
847 }
848 wxColour GetBackgroundColour() const;
849 bool InheritsBackgroundColour() const
850 {
851 return m_inheritBgCol;
852 }
853 bool UseBgCol() const
854 {
855 return m_hasBgCol;
856 }
857
858 virtual bool SetForegroundColour(const wxColour& colour);
859 void SetOwnForegroundColour(const wxColour& colour)
860 {
861 if ( SetForegroundColour(colour) )
862 m_inheritFgCol = false;
863 }
864 wxColour GetForegroundColour() const;
865
866 // Set/get the background style.
867 // Pass one of wxBG_STYLE_SYSTEM, wxBG_STYLE_COLOUR, wxBG_STYLE_CUSTOM
868 virtual bool SetBackgroundStyle(wxBackgroundStyle style) { m_backgroundStyle = style; return true; }
869 virtual wxBackgroundStyle GetBackgroundStyle() const { return m_backgroundStyle; }
870
871 // returns true if the control has "transparent" areas such as a
872 // wxStaticText and wxCheckBox and the background should be adapted
873 // from a parent window
874 virtual bool HasTransparentBackground() { return false; }
875
876 // set/retrieve the font for the window (SetFont() returns true if the
877 // font really changed)
878 virtual bool SetFont(const wxFont& font) = 0;
879 void SetOwnFont(const wxFont& font)
880 {
881 if ( SetFont(font) )
882 m_inheritFont = false;
883 }
884 wxFont GetFont() const;
885
886 // set/retrieve the cursor for this window (SetCursor() returns true
887 // if the cursor was really changed)
888 virtual bool SetCursor( const wxCursor &cursor );
889 const wxCursor& GetCursor() const { return m_cursor; }
890
891 #if wxUSE_CARET
892 // associate a caret with the window
893 void SetCaret(wxCaret *caret);
894 // get the current caret (may be NULL)
895 wxCaret *GetCaret() const { return m_caret; }
896 #endif // wxUSE_CARET
897
898 // get the (average) character size for the current font
899 virtual int GetCharHeight() const = 0;
900 virtual int GetCharWidth() const = 0;
901
902 // get the width/height/... of the text using current or specified
903 // font
904 virtual void GetTextExtent(const wxString& string,
905 int *x, int *y,
906 int *descent = (int *) NULL,
907 int *externalLeading = (int *) NULL,
908 const wxFont *theFont = (const wxFont *) NULL)
909 const = 0;
910
911 wxSize GetTextExtent(const wxString& string) const
912 {
913 wxCoord w, h;
914 GetTextExtent(string, &w, &h);
915 return wxSize(w, h);
916 }
917
918 // client <-> screen coords
919 // ------------------------
920
921 // translate to/from screen/client coordinates (pointers may be NULL)
922 void ClientToScreen( int *x, int *y ) const
923 { DoClientToScreen(x, y); }
924 void ScreenToClient( int *x, int *y ) const
925 { DoScreenToClient(x, y); }
926
927 // wxPoint interface to do the same thing
928 wxPoint ClientToScreen(const wxPoint& pt) const
929 {
930 int x = pt.x, y = pt.y;
931 DoClientToScreen(&x, &y);
932
933 return wxPoint(x, y);
934 }
935
936 wxPoint ScreenToClient(const wxPoint& pt) const
937 {
938 int x = pt.x, y = pt.y;
939 DoScreenToClient(&x, &y);
940
941 return wxPoint(x, y);
942 }
943
944 // test where the given (in client coords) point lies
945 wxHitTest HitTest(wxCoord x, wxCoord y) const
946 { return DoHitTest(x, y); }
947
948 wxHitTest HitTest(const wxPoint& pt) const
949 { return DoHitTest(pt.x, pt.y); }
950
951 // misc
952 // ----
953
954 // get the window border style from the given flags: this is different from
955 // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to
956 // translate wxBORDER_DEFAULT to something reasonable
957 wxBorder GetBorder(long flags) const;
958
959 // get border for the flags of this window
960 wxBorder GetBorder() const { return GetBorder(GetWindowStyleFlag()); }
961
962 // send wxUpdateUIEvents to this window, and children if recurse is true
963 virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
964
965 // do the window-specific processing after processing the update event
966 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
967
968 #if wxUSE_MENUS
969 bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition)
970 { return DoPopupMenu(menu, pos.x, pos.y); }
971 bool PopupMenu(wxMenu *menu, int x, int y)
972 { return DoPopupMenu(menu, x, y); }
973 #endif // wxUSE_MENUS
974
975 // override this method to return true for controls having multiple pages
976 virtual bool HasMultiplePages() const { return false; }
977
978
979 // scrollbars
980 // ----------
981
982 // does the window have the scrollbar for this orientation?
983 bool HasScrollbar(int orient) const
984 {
985 return (m_windowStyle &
986 (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0;
987 }
988
989 // configure the window scrollbars
990 virtual void SetScrollbar( int orient,
991 int pos,
992 int thumbvisible,
993 int range,
994 bool refresh = true ) = 0;
995 virtual void SetScrollPos( int orient, int pos, bool refresh = true ) = 0;
996 virtual int GetScrollPos( int orient ) const = 0;
997 virtual int GetScrollThumb( int orient ) const = 0;
998 virtual int GetScrollRange( int orient ) const = 0;
999
1000 // scroll window to the specified position
1001 virtual void ScrollWindow( int dx, int dy,
1002 const wxRect* rect = (wxRect *) NULL ) = 0;
1003
1004 // scrolls window by line/page: note that not all controls support this
1005 //
1006 // return true if the position changed, false otherwise
1007 virtual bool ScrollLines(int WXUNUSED(lines)) { return false; }
1008 virtual bool ScrollPages(int WXUNUSED(pages)) { return false; }
1009
1010 // convenient wrappers for ScrollLines/Pages
1011 bool LineUp() { return ScrollLines(-1); }
1012 bool LineDown() { return ScrollLines(1); }
1013 bool PageUp() { return ScrollPages(-1); }
1014 bool PageDown() { return ScrollPages(1); }
1015
1016 // context-sensitive help
1017 // ----------------------
1018
1019 // these are the convenience functions wrapping wxHelpProvider methods
1020
1021 #if wxUSE_HELP
1022 // associate this help text with this window
1023 void SetHelpText(const wxString& text);
1024 // associate this help text with all windows with the same id as this
1025 // one
1026 void SetHelpTextForId(const wxString& text);
1027 // get the help string associated with the given position in this window
1028 //
1029 // notice that pt may be invalid if event origin is keyboard or unknown
1030 // and this method should return the global window help text then
1031 virtual wxString GetHelpTextAtPoint(const wxPoint& pt,
1032 wxHelpEvent::Origin origin) const;
1033 // returns the position-independent help text
1034 wxString GetHelpText() const
1035 {
1036 return GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Unknown);
1037 }
1038
1039 #else // !wxUSE_HELP
1040 // silently ignore SetHelpText() calls
1041 void SetHelpText(const wxString& WXUNUSED(text)) { }
1042 void SetHelpTextForId(const wxString& WXUNUSED(text)) { }
1043 #endif // wxUSE_HELP
1044
1045 // tooltips
1046 // --------
1047
1048 #if wxUSE_TOOLTIPS
1049 // the easiest way to set a tooltip for a window is to use this method
1050 void SetToolTip( const wxString &tip );
1051 // attach a tooltip to the window
1052 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
1053 // get the associated tooltip or NULL if none
1054 wxToolTip* GetToolTip() const { return m_tooltip; }
1055 wxString GetToolTipText() const ;
1056 #else
1057 // make it much easier to compile apps in an environment
1058 // that doesn't support tooltips, such as PocketPC
1059 inline void SetToolTip( const wxString & WXUNUSED(tip) ) {}
1060 #endif // wxUSE_TOOLTIPS
1061
1062 // drag and drop
1063 // -------------
1064 #if wxUSE_DRAG_AND_DROP
1065 // set/retrieve the drop target associated with this window (may be
1066 // NULL; it's owned by the window and will be deleted by it)
1067 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
1068 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
1069 #endif // wxUSE_DRAG_AND_DROP
1070
1071 // constraints and sizers
1072 // ----------------------
1073 #if wxUSE_CONSTRAINTS
1074 // set the constraints for this window or retrieve them (may be NULL)
1075 void SetConstraints( wxLayoutConstraints *constraints );
1076 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
1077
1078 // implementation only
1079 void UnsetConstraints(wxLayoutConstraints *c);
1080 wxWindowList *GetConstraintsInvolvedIn() const
1081 { return m_constraintsInvolvedIn; }
1082 void AddConstraintReference(wxWindowBase *otherWin);
1083 void RemoveConstraintReference(wxWindowBase *otherWin);
1084 void DeleteRelatedConstraints();
1085 void ResetConstraints();
1086
1087 // these methods may be overridden for special layout algorithms
1088 virtual void SetConstraintSizes(bool recurse = true);
1089 virtual bool LayoutPhase1(int *noChanges);
1090 virtual bool LayoutPhase2(int *noChanges);
1091 virtual bool DoPhase(int phase);
1092
1093 // these methods are virtual but normally won't be overridden
1094 virtual void SetSizeConstraint(int x, int y, int w, int h);
1095 virtual void MoveConstraint(int x, int y);
1096 virtual void GetSizeConstraint(int *w, int *h) const ;
1097 virtual void GetClientSizeConstraint(int *w, int *h) const ;
1098 virtual void GetPositionConstraint(int *x, int *y) const ;
1099
1100 #endif // wxUSE_CONSTRAINTS
1101
1102 // when using constraints or sizers, it makes sense to update
1103 // children positions automatically whenever the window is resized
1104 // - this is done if autoLayout is on
1105 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
1106 bool GetAutoLayout() const { return m_autoLayout; }
1107
1108 // lay out the window and its children
1109 virtual bool Layout();
1110
1111 // sizers
1112 void SetSizer(wxSizer *sizer, bool deleteOld = true );
1113 void SetSizerAndFit( wxSizer *sizer, bool deleteOld = true );
1114
1115 wxSizer *GetSizer() const { return m_windowSizer; }
1116
1117 // Track if this window is a member of a sizer
1118 void SetContainingSizer(wxSizer* sizer);
1119 wxSizer *GetContainingSizer() const { return m_containingSizer; }
1120
1121 // accessibility
1122 // ----------------------
1123 #if wxUSE_ACCESSIBILITY
1124 // Override to create a specific accessible object.
1125 virtual wxAccessible* CreateAccessible();
1126
1127 // Sets the accessible object.
1128 void SetAccessible(wxAccessible* accessible) ;
1129
1130 // Returns the accessible object.
1131 wxAccessible* GetAccessible() { return m_accessible; };
1132
1133 // Returns the accessible object, creating if necessary.
1134 wxAccessible* GetOrCreateAccessible() ;
1135 #endif
1136
1137
1138 // Set window transparency if the platform supports it
1139 virtual bool SetTransparent(wxByte WXUNUSED(alpha)) { return false; }
1140 virtual bool CanSetTransparent() { return false; }
1141
1142
1143 // implementation
1144 // --------------
1145
1146 // event handlers
1147 void OnSysColourChanged( wxSysColourChangedEvent& event );
1148 void OnInitDialog( wxInitDialogEvent &event );
1149 void OnMiddleClick( wxMouseEvent& event );
1150 #if wxUSE_HELP
1151 void OnHelp(wxHelpEvent& event);
1152 #endif // wxUSE_HELP
1153
1154 // virtual function for implementing internal idle
1155 // behaviour
1156 virtual void OnInternalIdle() {}
1157
1158 // call internal idle recursively
1159 // void ProcessInternalIdle() ;
1160
1161 // get the handle of the window for the underlying window system: this
1162 // is only used for wxWin itself or for user code which wants to call
1163 // platform-specific APIs
1164 virtual WXWidget GetHandle() const = 0;
1165 // associate the window with a new native handle
1166 virtual void AssociateHandle(WXWidget WXUNUSED(handle)) { }
1167 // dissociate the current native handle from the window
1168 virtual void DissociateHandle() { }
1169
1170 #if wxUSE_PALETTE
1171 // Store the palette used by DCs in wxWindow so that the dcs can share
1172 // a palette. And we can respond to palette messages.
1173 wxPalette GetPalette() const { return m_palette; }
1174
1175 // When palette is changed tell the DC to set the system palette to the
1176 // new one.
1177 void SetPalette(const wxPalette& pal);
1178
1179 // return true if we have a specific palette
1180 bool HasCustomPalette() const { return m_hasCustomPalette; }
1181
1182 // return the first parent window with a custom palette or NULL
1183 wxWindow *GetAncestorWithCustomPalette() const;
1184 #endif // wxUSE_PALETTE
1185
1186 // inherit the parents visual attributes if they had been explicitly set
1187 // by the user (i.e. we don't inherit default attributes) and if we don't
1188 // have our own explicitly set
1189 virtual void InheritAttributes();
1190
1191 // returns false from here if this window doesn't want to inherit the
1192 // parents colours even if InheritAttributes() would normally do it
1193 //
1194 // this just provides a simple way to customize InheritAttributes()
1195 // behaviour in the most common case
1196 virtual bool ShouldInheritColours() const { return false; }
1197
1198 // returns true if the window can be positioned outside of parent's client
1199 // area (normal windows can't, but e.g. menubar or statusbar can):
1200 virtual bool CanBeOutsideClientArea() const { return false; }
1201
1202 protected:
1203 // event handling specific to wxWindow
1204 virtual bool TryValidator(wxEvent& event);
1205 virtual bool TryParent(wxEvent& event);
1206
1207 // common part of MoveBefore/AfterInTabOrder()
1208 enum MoveKind
1209 {
1210 MoveBefore, // insert before the given window
1211 MoveAfter // insert after the given window
1212 };
1213 virtual void DoMoveInTabOrder(wxWindow *win, MoveKind move);
1214
1215 // implementation of Navigate() and NavigateIn()
1216 virtual bool DoNavigateIn(int flags);
1217
1218
1219 #if wxUSE_CONSTRAINTS
1220 // satisfy the constraints for the windows but don't set the window sizes
1221 void SatisfyConstraints();
1222 #endif // wxUSE_CONSTRAINTS
1223
1224 // Send the wxWindowDestroyEvent
1225 void SendDestroyEvent();
1226
1227 // returns the main window of composite control; this is the window
1228 // that FindFocus returns if the focus is in one of composite control's
1229 // windows
1230 virtual wxWindow *GetMainWindowOfCompositeControl()
1231 { return (wxWindow*)this; }
1232
1233 // this method should be implemented to use operating system specific code
1234 // to really enable/disable the widget, it will only be called when we
1235 // really need to enable/disable window and so no additional checks on the
1236 // widgets state are necessary
1237 virtual void DoEnable(bool WXUNUSED(enable)) { }
1238
1239 // called when the on-screen widget state changes and provides an
1240 // an opportunity for the widget to update its visual state (colours,
1241 // fonts, anything else) as necessary
1242 virtual void OnEnabled(bool WXUNUSED(enabled)) { }
1243
1244
1245 // the window id - a number which uniquely identifies a window among
1246 // its siblings unless it is wxID_ANY
1247 wxWindowID m_windowId;
1248
1249 // the parent window of this window (or NULL) and the list of the children
1250 // of this window
1251 wxWindow *m_parent;
1252 wxWindowList m_children;
1253
1254 // the minimal allowed size for the window (no minimal size if variable(s)
1255 // contain(s) wxDefaultCoord)
1256 int m_minWidth,
1257 m_minHeight,
1258 m_maxWidth,
1259 m_maxHeight;
1260
1261 // event handler for this window: usually is just 'this' but may be
1262 // changed with SetEventHandler()
1263 wxEvtHandler *m_eventHandler;
1264
1265 #if wxUSE_VALIDATORS
1266 // associated validator or NULL if none
1267 wxValidator *m_windowValidator;
1268 #endif // wxUSE_VALIDATORS
1269
1270 #if wxUSE_DRAG_AND_DROP
1271 wxDropTarget *m_dropTarget;
1272 #endif // wxUSE_DRAG_AND_DROP
1273
1274 // visual window attributes
1275 wxCursor m_cursor;
1276 wxFont m_font; // see m_hasFont
1277 wxColour m_backgroundColour, // m_hasBgCol
1278 m_foregroundColour; // m_hasFgCol
1279
1280 #if wxUSE_CARET
1281 wxCaret *m_caret;
1282 #endif // wxUSE_CARET
1283
1284 // the region which should be repainted in response to paint event
1285 wxRegion m_updateRegion;
1286
1287 #if wxUSE_ACCEL
1288 // the accelerator table for the window which translates key strokes into
1289 // command events
1290 wxAcceleratorTable m_acceleratorTable;
1291 #endif // wxUSE_ACCEL
1292
1293 // the tooltip for this window (may be NULL)
1294 #if wxUSE_TOOLTIPS
1295 wxToolTip *m_tooltip;
1296 #endif // wxUSE_TOOLTIPS
1297
1298 // constraints and sizers
1299 #if wxUSE_CONSTRAINTS
1300 // the constraints for this window or NULL
1301 wxLayoutConstraints *m_constraints;
1302
1303 // constraints this window is involved in
1304 wxWindowList *m_constraintsInvolvedIn;
1305 #endif // wxUSE_CONSTRAINTS
1306
1307 // this window's sizer
1308 wxSizer *m_windowSizer;
1309
1310 // The sizer this window is a member of, if any
1311 wxSizer *m_containingSizer;
1312
1313 // Layout() window automatically when its size changes?
1314 bool m_autoLayout:1;
1315
1316 // window state
1317 bool m_isShown:1;
1318 bool m_isEnabled:1;
1319 bool m_isBeingDeleted:1;
1320
1321 // was the window colours/font explicitly changed by user?
1322 bool m_hasBgCol:1;
1323 bool m_hasFgCol:1;
1324 bool m_hasFont:1;
1325
1326 // and should it be inherited by children?
1327 bool m_inheritBgCol:1;
1328 bool m_inheritFgCol:1;
1329 bool m_inheritFont:1;
1330
1331 // window attributes
1332 long m_windowStyle,
1333 m_exStyle;
1334 wxString m_windowName;
1335 bool m_themeEnabled;
1336 wxBackgroundStyle m_backgroundStyle;
1337 #if wxUSE_PALETTE
1338 wxPalette m_palette;
1339 bool m_hasCustomPalette;
1340 #endif // wxUSE_PALETTE
1341
1342 #if wxUSE_ACCESSIBILITY
1343 wxAccessible* m_accessible;
1344 #endif
1345
1346 // Virtual size (scrolling)
1347 wxSize m_virtualSize;
1348
1349 wxScrollHelper *m_scrollHelper;
1350
1351 int m_minVirtualWidth; // VirtualSizeHints
1352 int m_minVirtualHeight;
1353 int m_maxVirtualWidth;
1354 int m_maxVirtualHeight;
1355
1356 wxWindowVariant m_windowVariant ;
1357
1358 // override this to change the default (i.e. used when no style is
1359 // specified) border for the window class
1360 virtual wxBorder GetDefaultBorder() const;
1361
1362 // Get the default size for the new window if no explicit size given. TLWs
1363 // have their own default size so this is just for non top-level windows.
1364 static int WidthDefault(int w) { return w == wxDefaultCoord ? 20 : w; }
1365 static int HeightDefault(int h) { return h == wxDefaultCoord ? 20 : h; }
1366
1367
1368 // Used to save the results of DoGetBestSize so it doesn't need to be
1369 // recalculated each time the value is needed.
1370 wxSize m_bestSizeCache;
1371
1372 wxDEPRECATED( void SetBestSize(const wxSize& size) ); // use SetInitialSize
1373 wxDEPRECATED( virtual void SetInitialBestSize(const wxSize& size) ); // use SetInitialSize
1374
1375
1376
1377 // more pure virtual functions
1378 // ---------------------------
1379
1380 // NB: we must have DoSomething() function when Something() is an overloaded
1381 // method: indeed, we can't just have "virtual Something()" in case when
1382 // the function is overloaded because then we'd have to make virtual all
1383 // the variants (otherwise only the virtual function may be called on a
1384 // pointer to derived class according to C++ rules) which is, in
1385 // general, absolutely not needed. So instead we implement all
1386 // overloaded Something()s in terms of DoSomething() which will be the
1387 // only one to be virtual.
1388
1389 // coordinates translation
1390 virtual void DoClientToScreen( int *x, int *y ) const = 0;
1391 virtual void DoScreenToClient( int *x, int *y ) const = 0;
1392
1393 virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
1394
1395 // capture/release the mouse, used by Capture/ReleaseMouse()
1396 virtual void DoCaptureMouse() = 0;
1397 virtual void DoReleaseMouse() = 0;
1398
1399 // retrieve the position/size of the window
1400 virtual void DoGetPosition(int *x, int *y) const = 0;
1401 virtual void DoGetScreenPosition(int *x, int *y) const;
1402 virtual void DoGetSize(int *width, int *height) const = 0;
1403 virtual void DoGetClientSize(int *width, int *height) const = 0;
1404
1405 // get the size which best suits the window: for a control, it would be
1406 // the minimal size which doesn't truncate the control, for a panel - the
1407 // same size as it would have after a call to Fit()
1408 virtual wxSize DoGetBestSize() const;
1409
1410 // called from DoGetBestSize() to convert best virtual size (returned by
1411 // the window sizer) to the best size for the window itself; this is
1412 // overridden at wxScrolledWindow level to clump down virtual size to real
1413 virtual wxSize GetWindowSizeForVirtualSize(const wxSize& size) const
1414 {
1415 return size;
1416 }
1417
1418 // this is the virtual function to be overriden in any derived class which
1419 // wants to change how SetSize() or Move() works - it is called by all
1420 // versions of these functions in the base class
1421 virtual void DoSetSize(int x, int y,
1422 int width, int height,
1423 int sizeFlags = wxSIZE_AUTO) = 0;
1424
1425 // same as DoSetSize() for the client size
1426 virtual void DoSetClientSize(int width, int height) = 0;
1427
1428 // move the window to the specified location and resize it: this is called
1429 // from both DoSetSize() and DoSetClientSize() and would usually just
1430 // reposition this window except for composite controls which will want to
1431 // arrange themselves inside the given rectangle
1432 //
1433 // Important note: the coordinates passed to this method are in parent's
1434 // *window* coordinates and not parent's client coordinates (as the values
1435 // passed to DoSetSize and returned by DoGetPosition are)!
1436 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
1437
1438 // centre the window in the specified direction on parent, note that
1439 // wxCENTRE_ON_SCREEN shouldn't be specified here, it only makes sense for
1440 // TLWs
1441 virtual void DoCentre(int dir);
1442
1443 #if wxUSE_TOOLTIPS
1444 virtual void DoSetToolTip( wxToolTip *tip );
1445 #endif // wxUSE_TOOLTIPS
1446
1447 #if wxUSE_MENUS
1448 virtual bool DoPopupMenu(wxMenu *menu, int x, int y) = 0;
1449 #endif // wxUSE_MENUS
1450
1451 // Makes an adjustment to the window position to make it relative to the
1452 // parents client area, e.g. if the parent is a frame with a toolbar, its
1453 // (0, 0) is just below the toolbar
1454 virtual void AdjustForParentClientOrigin(int& x, int& y,
1455 int sizeFlags = 0) const;
1456
1457 // implements the window variants
1458 virtual void DoSetWindowVariant( wxWindowVariant variant ) ;
1459
1460 // Must be called when mouse capture is lost to send
1461 // wxMouseCaptureLostEvent to windows on capture stack.
1462 static void NotifyCaptureLost();
1463
1464 private:
1465 // recursively call our own and our children OnEnabled() when the
1466 // enabled/disabled status changed because a parent window had been
1467 // enabled/disabled
1468 void NotifyWindowOnEnableChange(bool enabled);
1469
1470
1471 // contains the last id generated by NewControlId
1472 static int ms_lastControlId;
1473
1474 // the stack of windows which have captured the mouse
1475 static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext;
1476 // the window that currently has mouse capture
1477 static wxWindow *ms_winCaptureCurrent;
1478 // indicates if execution is inside CaptureMouse/ReleaseMouse
1479 static bool ms_winCaptureChanging;
1480
1481 DECLARE_ABSTRACT_CLASS(wxWindowBase)
1482 DECLARE_NO_COPY_CLASS(wxWindowBase)
1483 DECLARE_EVENT_TABLE()
1484 };
1485
1486
1487
1488 // Inlines for some deprecated methods
1489 inline wxSize wxWindowBase::GetBestFittingSize() const
1490 {
1491 return GetEffectiveMinSize();
1492 }
1493
1494 inline void wxWindowBase::SetBestFittingSize(const wxSize& size)
1495 {
1496 SetInitialSize(size);
1497 }
1498
1499 inline void wxWindowBase::SetBestSize(const wxSize& size)
1500 {
1501 SetInitialSize(size);
1502 }
1503
1504 inline void wxWindowBase::SetInitialBestSize(const wxSize& size)
1505 {
1506 SetInitialSize(size);
1507 }
1508
1509
1510 // ----------------------------------------------------------------------------
1511 // now include the declaration of wxWindow class
1512 // ----------------------------------------------------------------------------
1513
1514 // include the declaration of the platform-specific class
1515 #if defined(__WXPALMOS__)
1516 #ifdef __WXUNIVERSAL__
1517 #define wxWindowNative wxWindowPalm
1518 #else // !wxUniv
1519 #define wxWindowPalm wxWindow
1520 #endif // wxUniv/!wxUniv
1521 #include "wx/palmos/window.h"
1522 #elif defined(__WXMSW__)
1523 #ifdef __WXUNIVERSAL__
1524 #define wxWindowNative wxWindowMSW
1525 #else // !wxUniv
1526 #define wxWindowMSW wxWindow
1527 #endif // wxUniv/!wxUniv
1528 #include "wx/msw/window.h"
1529 #elif defined(__WXMOTIF__)
1530 #include "wx/motif/window.h"
1531 #elif defined(__WXGTK20__)
1532 #ifdef __WXUNIVERSAL__
1533 #define wxWindowNative wxWindowGTK
1534 #else // !wxUniv
1535 #define wxWindowGTK wxWindow
1536 #endif // wxUniv
1537 #include "wx/gtk/window.h"
1538 #elif defined(__WXGTK__)
1539 #ifdef __WXUNIVERSAL__
1540 #define wxWindowNative wxWindowGTK
1541 #else // !wxUniv
1542 #define wxWindowGTK wxWindow
1543 #endif // wxUniv
1544 #include "wx/gtk1/window.h"
1545 #elif defined(__WXX11__)
1546 #ifdef __WXUNIVERSAL__
1547 #define wxWindowNative wxWindowX11
1548 #else // !wxUniv
1549 #define wxWindowX11 wxWindow
1550 #endif // wxUniv
1551 #include "wx/x11/window.h"
1552 #elif defined(__WXMGL__)
1553 #define wxWindowNative wxWindowMGL
1554 #include "wx/mgl/window.h"
1555 #elif defined(__WXDFB__)
1556 #define wxWindowNative wxWindowDFB
1557 #include "wx/dfb/window.h"
1558 #elif defined(__WXMAC__)
1559 #ifdef __WXUNIVERSAL__
1560 #define wxWindowNative wxWindowMac
1561 #else // !wxUniv
1562 #define wxWindowMac wxWindow
1563 #endif // wxUniv
1564 #include "wx/mac/window.h"
1565 #elif defined(__WXCOCOA__)
1566 #ifdef __WXUNIVERSAL__
1567 #define wxWindowNative wxWindowCocoa
1568 #else // !wxUniv
1569 #define wxWindowCocoa wxWindow
1570 #endif // wxUniv
1571 #include "wx/cocoa/window.h"
1572 #elif defined(__WXPM__)
1573 #ifdef __WXUNIVERSAL__
1574 #define wxWindowNative wxWindowOS2
1575 #else // !wxUniv
1576 #define wxWindowOS2 wxWindow
1577 #endif // wxUniv/!wxUniv
1578 #include "wx/os2/window.h"
1579 #endif
1580
1581 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1582 // for the native ports we already have defined it above
1583 #if defined(__WXUNIVERSAL__)
1584 #ifndef wxWindowNative
1585 #error "wxWindowNative must be defined above!"
1586 #endif
1587
1588 #include "wx/univ/window.h"
1589 #endif // wxUniv
1590
1591 // ----------------------------------------------------------------------------
1592 // inline functions which couldn't be declared in the class body because of
1593 // forward dependencies
1594 // ----------------------------------------------------------------------------
1595
1596 inline wxWindow *wxWindowBase::GetGrandParent() const
1597 {
1598 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
1599 }
1600
1601 // ----------------------------------------------------------------------------
1602 // global functions
1603 // ----------------------------------------------------------------------------
1604
1605 // Find the wxWindow at the current mouse position, also returning the mouse
1606 // position.
1607 extern WXDLLEXPORT wxWindow* wxFindWindowAtPointer(wxPoint& pt);
1608
1609 // Get the current mouse position.
1610 extern WXDLLEXPORT wxPoint wxGetMousePosition();
1611
1612 // get the currently active window of this application or NULL
1613 extern WXDLLEXPORT wxWindow *wxGetActiveWindow();
1614
1615 // get the (first) top level parent window
1616 WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win);
1617
1618 #if WXWIN_COMPATIBILITY_2_6
1619 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1620 wxDEPRECATED( int NewControlId() );
1621 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1622 #endif // WXWIN_COMPATIBILITY_2_6
1623
1624 #if wxUSE_ACCESSIBILITY
1625 // ----------------------------------------------------------------------------
1626 // accessible object for windows
1627 // ----------------------------------------------------------------------------
1628
1629 class WXDLLEXPORT wxWindowAccessible: public wxAccessible
1630 {
1631 public:
1632 wxWindowAccessible(wxWindow* win): wxAccessible(win) { if (win) win->SetAccessible(this); }
1633 virtual ~wxWindowAccessible() {}
1634
1635 // Overridables
1636
1637 // Can return either a child object, or an integer
1638 // representing the child element, starting from 1.
1639 virtual wxAccStatus HitTest(const wxPoint& pt, int* childId, wxAccessible** childObject);
1640
1641 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
1642 virtual wxAccStatus GetLocation(wxRect& rect, int elementId);
1643
1644 // Navigates from fromId to toId/toObject.
1645 virtual wxAccStatus Navigate(wxNavDir navDir, int fromId,
1646 int* toId, wxAccessible** toObject);
1647
1648 // Gets the name of the specified object.
1649 virtual wxAccStatus GetName(int childId, wxString* name);
1650
1651 // Gets the number of children.
1652 virtual wxAccStatus GetChildCount(int* childCount);
1653
1654 // Gets the specified child (starting from 1).
1655 // If *child is NULL and return value is wxACC_OK,
1656 // this means that the child is a simple element and
1657 // not an accessible object.
1658 virtual wxAccStatus GetChild(int childId, wxAccessible** child);
1659
1660 // Gets the parent, or NULL.
1661 virtual wxAccStatus GetParent(wxAccessible** parent);
1662
1663 // Performs the default action. childId is 0 (the action for this object)
1664 // or > 0 (the action for a child).
1665 // Return wxACC_NOT_SUPPORTED if there is no default action for this
1666 // window (e.g. an edit control).
1667 virtual wxAccStatus DoDefaultAction(int childId);
1668
1669 // Gets the default action for this object (0) or > 0 (the action for a child).
1670 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
1671 // string if there is no action.
1672 // The retrieved string describes the action that is performed on an object,
1673 // not what the object does as a result. For example, a toolbar button that prints
1674 // a document has a default action of "Press" rather than "Prints the current document."
1675 virtual wxAccStatus GetDefaultAction(int childId, wxString* actionName);
1676
1677 // Returns the description for this object or a child.
1678 virtual wxAccStatus GetDescription(int childId, wxString* description);
1679
1680 // Returns help text for this object or a child, similar to tooltip text.
1681 virtual wxAccStatus GetHelpText(int childId, wxString* helpText);
1682
1683 // Returns the keyboard shortcut for this object or child.
1684 // Return e.g. ALT+K
1685 virtual wxAccStatus GetKeyboardShortcut(int childId, wxString* shortcut);
1686
1687 // Returns a role constant.
1688 virtual wxAccStatus GetRole(int childId, wxAccRole* role);
1689
1690 // Returns a state constant.
1691 virtual wxAccStatus GetState(int childId, long* state);
1692
1693 // Returns a localized string representing the value for the object
1694 // or child.
1695 virtual wxAccStatus GetValue(int childId, wxString* strValue);
1696
1697 // Selects the object or child.
1698 virtual wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags);
1699
1700 // Gets the window with the keyboard focus.
1701 // If childId is 0 and child is NULL, no object in
1702 // this subhierarchy has the focus.
1703 // If this object has the focus, child should be 'this'.
1704 virtual wxAccStatus GetFocus(int* childId, wxAccessible** child);
1705
1706 #if wxUSE_VARIANT
1707 // Gets a variant representing the selected children
1708 // of this object.
1709 // Acceptable values:
1710 // - a null variant (IsNull() returns true)
1711 // - a list variant (GetType() == wxT("list")
1712 // - an integer representing the selected child element,
1713 // or 0 if this object is selected (GetType() == wxT("long")
1714 // - a "void*" pointer to a wxAccessible child object
1715 virtual wxAccStatus GetSelections(wxVariant* selections);
1716 #endif // wxUSE_VARIANT
1717 };
1718
1719 #endif // wxUSE_ACCESSIBILITY
1720
1721
1722 #endif // _WX_WINDOW_H_BASE_