1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowBase class - the interface of wxWindow
4 // Author: Vadim Zeitlin
5 // Modified by: Ron Lee
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "windowbase.h"
19 // ----------------------------------------------------------------------------
20 // headers which we must include here
21 // ----------------------------------------------------------------------------
23 #include "wx/event.h" // the base class
25 #include "wx/list.h" // defines wxWindowList
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"
33 #include "wx/validate.h" // for wxDefaultValidator (always include it)
36 #include "wx/palette.h"
37 #endif // wxUSE_PALETTE
43 #if wxUSE_ACCESSIBILITY
44 #include "wx/access.h"
47 // when building wxUniv/Foo we don't want the code for native menu use to be
48 // compiled in - it should only be used when building real wxFoo
49 #ifdef __WXUNIVERSAL__
50 #define wxUSE_MENUS_NATIVE 0
52 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
53 #endif // __WXUNIVERSAL__/__WXMSW__
55 // ----------------------------------------------------------------------------
56 // forward declarations
57 // ----------------------------------------------------------------------------
59 class WXDLLEXPORT wxCaret
;
60 class WXDLLEXPORT wxControl
;
61 class WXDLLEXPORT wxCursor
;
62 class WXDLLEXPORT wxDC
;
63 class WXDLLEXPORT wxDropTarget
;
64 class WXDLLEXPORT wxItemResource
;
65 class WXDLLEXPORT wxLayoutConstraints
;
66 class WXDLLEXPORT wxResourceTable
;
67 class WXDLLEXPORT wxSizer
;
68 class WXDLLEXPORT wxToolTip
;
69 class WXDLLEXPORT wxWindowBase
;
70 class WXDLLEXPORT wxWindow
;
72 #if wxUSE_ACCESSIBILITY
73 class WXDLLEXPORT wxAccessible
;
76 // ----------------------------------------------------------------------------
77 // (pseudo)template list classes
78 // ----------------------------------------------------------------------------
80 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
, class WXDLLEXPORT
);
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
88 // ----------------------------------------------------------------------------
89 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
90 // interface of this class.
92 // Event handler: windows have themselves as their event handlers by default,
93 // but their event handlers could be set to another object entirely. This
94 // separation can reduce the amount of derivation required, and allow
95 // alteration of a window's functionality (e.g. by a resource editor that
96 // temporarily switches event handlers).
97 // ----------------------------------------------------------------------------
99 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
102 // creating the window
103 // -------------------
106 wxWindowBase() { InitBase(); }
108 // pseudo ctor (can't be virtual, called from ctor)
109 bool CreateBase(wxWindowBase
*parent
,
111 const wxPoint
& pos
= wxDefaultPosition
,
112 const wxSize
& size
= wxDefaultSize
,
114 const wxValidator
& validator
= wxDefaultValidator
,
115 const wxString
& name
= wxPanelNameStr
);
117 virtual ~wxWindowBase();
119 // deleting the window
120 // -------------------
122 // ask the window to close itself, return TRUE if the event handler
123 // honoured our request
124 bool Close( bool force
= FALSE
);
126 // the following functions delete the C++ objects (the window itself
127 // or its children) as well as the GUI windows and normally should
128 // never be used directly
130 // delete window unconditionally (dangerous!), returns TRUE if ok
131 virtual bool Destroy();
132 // delete all children of this window, returns TRUE if ok
133 bool DestroyChildren();
135 // is the window being deleted?
136 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
141 // NB: in future versions of wxWindows Set/GetTitle() will only work
142 // with the top level windows (such as dialogs and frames) and
143 // Set/GetLabel() only with the other ones (i.e. all controls).
145 // the title (or label, see below) of the window: the text which the
147 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) {}
148 virtual wxString
GetTitle() const { return wxEmptyString
; }
150 // label is just the same as the title (but for, e.g., buttons it
151 // makes more sense to speak about labels)
152 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
153 virtual wxString
GetLabel() const { return GetTitle(); }
155 // the window name is used for ressource setting in X, it is not the
156 // same as the window title/label
157 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
158 virtual wxString
GetName() const { return m_windowName
; }
160 // window id uniquely identifies the window among its siblings unless
161 // it is -1 which means "don't care"
162 void SetId( wxWindowID winid
) { m_windowId
= winid
; }
163 wxWindowID
GetId() const { return m_windowId
; }
165 // generate a control id for the controls which were not given one by
167 static int NewControlId() { return --ms_lastControlId
; }
168 // get the id of the control following the one with the given
169 // (autogenerated) id
170 static int NextControlId(int winid
) { return winid
- 1; }
171 // get the id of the control preceding the one with the given
172 // (autogenerated) id
173 static int PrevControlId(int winid
) { return winid
+ 1; }
178 // set the window size and/or position
179 void SetSize( int x
, int y
, int width
, int height
,
180 int sizeFlags
= wxSIZE_AUTO
)
181 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
183 void SetSize( int width
, int height
)
184 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
186 void SetSize( const wxSize
& size
)
187 { SetSize( size
.x
, size
.y
); }
189 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
190 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
192 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
193 { DoSetSize(x
, y
, -1, -1, flags
); }
195 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
196 { Move(pt
.x
, pt
.y
, flags
); }
199 virtual void Raise() = 0;
200 virtual void Lower() = 0;
202 // client size is the size of area available for subwindows
203 void SetClientSize( int width
, int height
)
204 { DoSetClientSize(width
, height
); }
206 void SetClientSize( const wxSize
& size
)
207 { DoSetClientSize(size
.x
, size
.y
); }
209 void SetClientSize(const wxRect
& rect
)
210 { SetClientSize( rect
.width
, rect
.height
); }
212 // get the window position and/or size (pointers may be NULL)
213 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
214 wxPoint
GetPosition() const
217 DoGetPosition(&w
, &h
);
219 return wxPoint(w
, h
);
222 void SetPosition( const wxPoint
& pt
) { Move( pt
) ; }
224 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
225 wxSize
GetSize() const
232 wxRect
GetRect() const
235 GetPosition(& x
, & y
);
238 return wxRect(x
, y
, w
, h
);
241 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
242 wxSize
GetClientSize() const
245 DoGetClientSize(& w
, & h
);
250 // get the origin of the client area of the window relative to the
251 // window top left corner (the client area may be shifted because of
252 // the borders, scrollbars, other decorations...)
253 virtual wxPoint
GetClientAreaOrigin() const;
255 // get the client rectangle in window (i.e. client) coordinates
256 wxRect
GetClientRect() const
258 return wxRect(GetClientAreaOrigin(), GetClientSize());
261 // get the size best suited for the window (in fact, minimal
262 // acceptable size using which it will still look "nice")
263 wxSize
GetBestSize() const { return DoGetBestSize(); }
264 void GetBestSize(int *w
, int *h
) const
266 wxSize s
= DoGetBestSize();
273 // There are times (and windows) where 'Best' size and 'Min' size
274 // are vastly out of sync. This should be remedied somehow, but in
275 // the meantime, this method will return the larger of BestSize
276 // (the window's smallest legible size), and any user specified
278 wxSize
GetAdjustedBestSize() const
280 wxSize
s( DoGetBestSize() );
281 return wxSize( wxMax( s
.x
, GetMinWidth() ), wxMax( s
.y
, GetMinHeight() ) );
284 // the generic centre function - centers the window on parent by`
285 // default or on screen if it doesn't have parent or
286 // wxCENTER_ON_SCREEN flag is given
287 void Centre( int direction
= wxBOTH
);
288 void Center( int direction
= wxBOTH
) { Centre(direction
); }
290 // centre on screen (only works for top level windows)
291 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
292 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
294 // centre with respect to the the parent window
295 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
296 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
298 // set window size to wrap around its children
301 // set virtual size to satisfy children
302 virtual void FitInside();
304 // set min/max size of the window
305 virtual void SetSizeHints( int minW
, int minH
,
306 int maxW
= -1, int maxH
= -1,
307 int incW
= -1, int incH
= -1 );
309 virtual void SetVirtualSizeHints( int minW
, int minH
,
310 int maxW
= -1, int maxH
= -1 );
312 virtual int GetMinWidth() const { return m_minWidth
; }
313 virtual int GetMinHeight() const { return m_minHeight
; }
314 int GetMaxWidth() const { return m_maxWidth
; }
315 int GetMaxHeight() const { return m_maxHeight
; }
317 // Override this method to control the values given to Sizers etc.
318 virtual wxSize
GetMaxSize() const { return wxSize( m_maxWidth
, m_maxHeight
); }
320 // Methods for accessing the virtual size of a window. For most
321 // windows this is just the client area of the window, but for
322 // some like scrolled windows it is more or less independent of
323 // the screen window size. You may override the DoXXXVirtual
324 // methods below for classes where that is is the case.
326 void SetVirtualSize( const wxSize
&size
) { DoSetVirtualSize( size
.x
, size
.y
); }
327 void SetVirtualSize( int x
, int y
) { DoSetVirtualSize( x
, y
); }
329 wxSize
GetVirtualSize() const { return DoGetVirtualSize(); }
330 void GetVirtualSize( int *x
, int *y
) const
332 wxSize
s( DoGetVirtualSize() );
340 // Override these methods for windows that have a virtual size
341 // independent of their client size. eg. the virtual area of a
342 // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
344 virtual void DoSetVirtualSize( int x
, int y
);
345 virtual wxSize
DoGetVirtualSize() const; // { return m_virtualSize; }
347 // Return the largest of ClientSize and BestSize (as determined
348 // by a sizer, interior children, or other means)
350 virtual wxSize
GetBestVirtualSize() const
352 wxSize
client( GetClientSize() );
353 wxSize
best( GetBestSize() );
355 return wxSize( wxMax( client
.x
, best
.x
), wxMax( client
.y
, best
.y
) );
361 // returns TRUE if window was shown/hidden, FALSE if the nothing was
362 // done (window was already shown/hidden)
363 virtual bool Show( bool show
= TRUE
);
364 bool Hide() { return Show(FALSE
); }
366 // returns TRUE if window was enabled/disabled, FALSE if nothing done
367 virtual bool Enable( bool enable
= TRUE
);
368 bool Disable() { return Enable(FALSE
); }
370 bool IsShown() const { return m_isShown
; }
371 bool IsEnabled() const { return m_isEnabled
; }
373 // get/set window style (setting style won't update the window and so
374 // is only useful for internal usage)
375 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
376 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
378 // just some (somewhat shorter) synonims
379 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
380 long GetWindowStyle() const { return GetWindowStyleFlag(); }
382 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
383 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
385 // extra style: the less often used style bits which can't be set with
386 // SetWindowStyleFlag()
387 virtual void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
388 long GetExtraStyle() const { return m_exStyle
; }
390 // make the window modal (all other windows unresponsive)
391 virtual void MakeModal(bool modal
= TRUE
);
393 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
394 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
396 // focus and keyboard handling
397 // ---------------------------
399 // set focus to this window
400 virtual void SetFocus() = 0;
402 // set focus to this window as the result of a keyboard action
403 virtual void SetFocusFromKbd() { SetFocus(); }
405 // return the window which currently has the focus or NULL
406 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
408 // can this window have focus?
409 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
411 // can this window be given focus by keyboard navigation? if not, the
412 // only way to give it focus (provided it accepts it at all) is to
414 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
416 // NB: these methods really don't belong here but with the current
417 // class hierarchy there is no other place for them :-(
419 // get the default child of this parent, i.e. the one which is
420 // activated by pressing <Enter>
421 virtual wxWindow
*GetDefaultItem() const { return NULL
; }
423 // set this child as default, return the old default
424 virtual wxWindow
*SetDefaultItem(wxWindow
* WXUNUSED(child
))
427 // set this child as temporary default
428 virtual void SetTmpDefaultItem(wxWindow
* WXUNUSED(win
)) { }
430 // parent/children relations
431 // -------------------------
433 // get the list of children
434 const wxWindowList
& GetChildren() const { return m_children
; }
435 wxWindowList
& GetChildren() { return m_children
; }
437 // needed just for extended runtime
438 const wxWindowList
& GetWindowChildren() const { return GetChildren() ; }
440 // get the parent or the parent of the parent
441 wxWindow
*GetParent() const { return m_parent
; }
442 inline wxWindow
*GetGrandParent() const;
444 // is this window a top level one?
445 virtual bool IsTopLevel() const;
447 // it doesn't really change parent, use ReParent() instead
448 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
449 // change the real parent of this window, return TRUE if the parent
450 // was changed, FALSE otherwise (error or newParent == oldParent)
451 virtual bool Reparent( wxWindowBase
*newParent
);
453 // implementation mostly
454 virtual void AddChild( wxWindowBase
*child
);
455 virtual void RemoveChild( wxWindowBase
*child
);
457 // looking for windows
458 // -------------------
460 // find window among the descendants of this one either by id or by
461 // name (return NULL if not found)
462 wxWindow
*FindWindow( long winid
);
463 wxWindow
*FindWindow( const wxString
& name
);
465 // Find a window among any window (all return NULL if not found)
466 static wxWindow
*FindWindowById( long winid
, const wxWindow
*parent
= NULL
);
467 static wxWindow
*FindWindowByName( const wxString
& name
,
468 const wxWindow
*parent
= NULL
);
469 static wxWindow
*FindWindowByLabel( const wxString
& label
,
470 const wxWindow
*parent
= NULL
);
472 // event handler stuff
473 // -------------------
475 // get the current event handler
476 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
478 // replace the event handler (allows to completely subclass the
480 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
482 // push/pop event handler: allows to chain a custom event handler to
483 // alreasy existing ones
484 void PushEventHandler( wxEvtHandler
*handler
);
485 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
487 // find the given handler in the event handler chain and remove (but
488 // not delete) it from the event handler chain, return TRUE if it was
489 // found and FALSE otherwise (this also results in an assert failure so
490 // this function should only be called when the handler is supposed to
492 bool RemoveEventHandler(wxEvtHandler
*handler
);
498 // a window may have an associated validator which is used to control
500 virtual void SetValidator( const wxValidator
&validator
);
501 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
502 #endif // wxUSE_VALIDATORS
505 // dialog oriented functions
506 // -------------------------
508 // validate the correctness of input, return TRUE if ok
509 virtual bool Validate();
511 // transfer data between internal and GUI representations
512 virtual bool TransferDataToWindow();
513 virtual bool TransferDataFromWindow();
515 virtual void InitDialog();
520 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
521 { m_acceleratorTable
= accel
; }
522 wxAcceleratorTable
*GetAcceleratorTable()
523 { return &m_acceleratorTable
; }
525 #endif // wxUSE_ACCEL
528 // hot keys (system wide accelerators)
529 // -----------------------------------
531 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
532 virtual bool UnregisterHotKey(int hotkeyId
);
533 #endif // wxUSE_HOTKEY
536 // dialog units translations
537 // -------------------------
539 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
540 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
541 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
543 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
545 return wxSize(pt
.x
, pt
.y
);
548 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
550 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
552 return wxSize(pt
.x
, pt
.y
);
558 // move the mouse to the specified position
559 virtual void WarpPointer(int x
, int y
) = 0;
561 // start or end mouse capture, these functions maintain the stack of
562 // windows having captured the mouse and after calling ReleaseMouse()
563 // the mouse is not released but returns to the window which had had
564 // captured it previously (if any)
568 // get the window which currently captures the mouse or NULL
569 static wxWindow
*GetCapture();
571 // does this window have the capture?
572 virtual bool HasCapture() const
573 { return (wxWindow
*)this == GetCapture(); }
575 // painting the window
576 // -------------------
578 // mark the specified rectangle (or the whole window) as "dirty" so it
580 virtual void Refresh( bool eraseBackground
= TRUE
,
581 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
583 // a less awkward wrapper for Refresh
584 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
586 // repaint all invalid areas of the window immediately
587 virtual void Update() { }
589 // clear the window background
590 virtual void ClearBackground();
592 // freeze the window: don't redraw it until it is thawed
593 virtual void Freeze() { }
595 // thaw the window: redraw it after it had been frozen
596 virtual void Thaw() { }
598 // adjust DC for drawing on this window
599 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
601 // the update region of the window contains the areas which must be
602 // repainted by the program
603 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
604 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
606 // get the update rectangleregion bounding box in client coords
607 wxRect
GetUpdateClientRect() const;
609 // these functions verify whether the given point/rectangle belongs to
610 // (or at least intersects with) the update region
611 bool IsExposed( int x
, int y
) const;
612 bool IsExposed( int x
, int y
, int w
, int h
) const;
614 bool IsExposed( const wxPoint
& pt
) const
615 { return IsExposed(pt
.x
, pt
.y
); }
616 bool IsExposed( const wxRect
& rect
) const
617 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
619 // colours, fonts and cursors
620 // --------------------------
622 // set/retrieve the window colours (system defaults are used by
623 // default): Set functions return TRUE if colour was changed
624 virtual bool SetBackgroundColour( const wxColour
&colour
);
625 virtual bool SetForegroundColour( const wxColour
&colour
);
627 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
628 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
630 // set/retrieve the cursor for this window (SetCursor() returns TRUE
631 // if the cursor was really changed)
632 virtual bool SetCursor( const wxCursor
&cursor
);
633 const wxCursor
& GetCursor() const { return m_cursor
; }
634 wxCursor
& GetCursor() { return m_cursor
; }
636 // set/retrieve the font for the window (SetFont() returns TRUE if the
637 // font really changed)
638 virtual bool SetFont( const wxFont
&font
) = 0;
639 const wxFont
& GetFont() const { return m_font
; }
640 wxFont
& GetFont() { return m_font
; }
643 // associate a caret with the window
644 void SetCaret(wxCaret
*caret
);
645 // get the current caret (may be NULL)
646 wxCaret
*GetCaret() const { return m_caret
; }
647 #endif // wxUSE_CARET
649 // get the (average) character size for the current font
650 virtual int GetCharHeight() const = 0;
651 virtual int GetCharWidth() const = 0;
653 // get the width/height/... of the text using current or specified
655 virtual void GetTextExtent(const wxString
& string
,
657 int *descent
= (int *) NULL
,
658 int *externalLeading
= (int *) NULL
,
659 const wxFont
*theFont
= (const wxFont
*) NULL
)
662 // client <-> screen coords
663 // ------------------------
665 // translate to/from screen/client coordinates (pointers may be NULL)
666 void ClientToScreen( int *x
, int *y
) const
667 { DoClientToScreen(x
, y
); }
668 void ScreenToClient( int *x
, int *y
) const
669 { DoScreenToClient(x
, y
); }
671 // wxPoint interface to do the same thing
672 wxPoint
ClientToScreen(const wxPoint
& pt
) const
674 int x
= pt
.x
, y
= pt
.y
;
675 DoClientToScreen(&x
, &y
);
677 return wxPoint(x
, y
);
680 wxPoint
ScreenToClient(const wxPoint
& pt
) const
682 int x
= pt
.x
, y
= pt
.y
;
683 DoScreenToClient(&x
, &y
);
685 return wxPoint(x
, y
);
688 // test where the given (in client coords) point lies
689 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
690 { return DoHitTest(x
, y
); }
692 wxHitTest
HitTest(const wxPoint
& pt
) const
693 { return DoHitTest(pt
.x
, pt
.y
); }
698 // get the window border style from the given flags: this is different from
699 // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to
700 // translate wxBORDER_DEFAULT to something reasonable
701 wxBorder
GetBorder(long flags
) const;
703 // get border for the flags of this window
704 wxBorder
GetBorder() const { return GetBorder(GetWindowStyleFlag()); }
706 // send wxUpdateUIEvents to this window, and children if recurse is TRUE
707 virtual void UpdateWindowUI(long flags
= wxUPDATE_UI_NONE
);
709 // do the window-specific processing after processing the update event
710 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
) ;
713 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
714 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
715 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
716 { return DoPopupMenu(menu
, x
, y
); }
717 #endif // wxUSE_MENUS
722 // does the window have the scrollbar for this orientation?
723 bool HasScrollbar(int orient
) const
725 return (m_windowStyle
&
726 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
729 // configure the window scrollbars
730 virtual void SetScrollbar( int orient
,
734 bool refresh
= TRUE
) = 0;
735 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
736 virtual int GetScrollPos( int orient
) const = 0;
737 virtual int GetScrollThumb( int orient
) const = 0;
738 virtual int GetScrollRange( int orient
) const = 0;
740 // scroll window to the specified position
741 virtual void ScrollWindow( int dx
, int dy
,
742 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
744 // scrolls window by line/page: note that not all controls support this
746 // return TRUE if the position changed, FALSE otherwise
747 virtual bool ScrollLines(int WXUNUSED(lines
)) { return FALSE
; }
748 virtual bool ScrollPages(int WXUNUSED(pages
)) { return FALSE
; }
750 // convenient wrappers for ScrollLines/Pages
751 bool LineUp() { return ScrollLines(-1); }
752 bool LineDown() { return ScrollLines(1); }
753 bool PageUp() { return ScrollPages(-1); }
754 bool PageDown() { return ScrollPages(1); }
756 // context-sensitive help
757 // ----------------------
759 // these are the convenience functions wrapping wxHelpProvider methods
762 // associate this help text with this window
763 void SetHelpText(const wxString
& text
);
764 // associate this help text with all windows with the same id as this
766 void SetHelpTextForId(const wxString
& text
);
767 // get the help string associated with this window (may be empty)
768 wxString
GetHelpText() const;
775 // the easiest way to set a tooltip for a window is to use this method
776 void SetToolTip( const wxString
&tip
);
777 // attach a tooltip to the window
778 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
779 // get the associated tooltip or NULL if none
780 wxToolTip
* GetToolTip() const { return m_tooltip
; }
781 wxString
GetToolTipText() const ;
782 #endif // wxUSE_TOOLTIPS
786 #if wxUSE_DRAG_AND_DROP
787 // set/retrieve the drop target associated with this window (may be
788 // NULL; it's owned by the window and will be deleted by it)
789 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
790 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
791 #endif // wxUSE_DRAG_AND_DROP
793 // constraints and sizers
794 // ----------------------
795 #if wxUSE_CONSTRAINTS
796 // set the constraints for this window or retrieve them (may be NULL)
797 void SetConstraints( wxLayoutConstraints
*constraints
);
798 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
800 // implementation only
801 void UnsetConstraints(wxLayoutConstraints
*c
);
802 wxWindowList
*GetConstraintsInvolvedIn() const
803 { return m_constraintsInvolvedIn
; }
804 void AddConstraintReference(wxWindowBase
*otherWin
);
805 void RemoveConstraintReference(wxWindowBase
*otherWin
);
806 void DeleteRelatedConstraints();
807 void ResetConstraints();
809 // these methods may be overriden for special layout algorithms
810 virtual void SetConstraintSizes(bool recurse
= TRUE
);
811 virtual bool LayoutPhase1(int *noChanges
);
812 virtual bool LayoutPhase2(int *noChanges
);
813 virtual bool DoPhase(int phase
);
815 // these methods are virtual but normally won't be overridden
816 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
817 virtual void MoveConstraint(int x
, int y
);
818 virtual void GetSizeConstraint(int *w
, int *h
) const ;
819 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
820 virtual void GetPositionConstraint(int *x
, int *y
) const ;
822 #endif // wxUSE_CONSTRAINTS
824 // when using constraints or sizers, it makes sense to update
825 // children positions automatically whenever the window is resized
826 // - this is done if autoLayout is on
827 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
828 bool GetAutoLayout() const { return m_autoLayout
; }
830 // lay out the window and its children
831 virtual bool Layout();
834 void SetSizer(wxSizer
*sizer
, bool deleteOld
= TRUE
);
835 void SetSizerAndFit( wxSizer
*sizer
, bool deleteOld
= TRUE
);
837 wxSizer
*GetSizer() const { return m_windowSizer
; }
839 // Track if this window is a member of a sizer
840 void SetContainingSizer(wxSizer
* sizer
)
842 // adding a window to a sizer twice is going to result in fatal and
843 // hard to debug problems later because when deleting the second
844 // associated wxSizerItem we're going to dereference a dangling
845 // pointer; so try to detect this as early as possible
846 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
847 _T("Adding a window to the same sizer twice?") );
849 m_containingSizer
= sizer
;
851 wxSizer
*GetContainingSizer() const { return m_containingSizer
; }
854 // ----------------------
855 #if wxUSE_ACCESSIBILITY
856 // Override to create a specific accessible object.
857 virtual wxAccessible
* CreateAccessible();
859 // Sets the accessible object.
860 void SetAccessible(wxAccessible
* accessible
) ;
862 // Returns the accessible object.
863 wxAccessible
* GetAccessible() { return m_accessible
; };
865 // Returns the accessible object, creating if necessary.
866 wxAccessible
* GetOrCreateAccessible() ;
873 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
874 void OnInitDialog( wxInitDialogEvent
&event
);
875 void OnMiddleClick( wxMouseEvent
& event
);
877 void OnHelp(wxHelpEvent
& event
);
880 // virtual function for implementing internal idle
882 virtual void OnInternalIdle() {}
884 // call internal idle recursively
885 // void ProcessInternalIdle() ;
887 // get the handle of the window for the underlying window system: this
888 // is only used for wxWin itself or for user code which wants to call
889 // platform-specific APIs
890 virtual WXWidget
GetHandle() const = 0;
893 // Store the palette used by DCs in wxWindow so that the dcs can share
894 // a palette. And we can respond to palette messages.
895 wxPalette
GetPalette() const { return m_palette
; }
897 // When palette is changed tell the DC to set the system palette to the
899 void SetPalette(const wxPalette
& pal
);
901 // return true if we have a specific palette
902 bool HasCustomPalette() const { return m_hasCustomPalette
; }
904 // return the first parent window with a custom palette or NULL
905 wxWindow
*GetAncestorWithCustomPalette() const;
906 #endif // wxUSE_PALETTE
909 // event handling specific to wxWindow
910 virtual bool TryValidator(wxEvent
& event
);
911 virtual bool TryParent(wxEvent
& event
);
914 #if wxUSE_CONSTRAINTS
915 // satisfy the constraints for the windows but don't set the window sizes
916 void SatisfyConstraints();
917 #endif // wxUSE_CONSTRAINTS
919 // Send the wxWindowDestroyEvent
920 void SendDestroyEvent();
922 // the window id - a number which uniquely identifies a window among
923 // its siblings unless it is -1
924 wxWindowID m_windowId
;
926 // the parent window of this window (or NULL) and the list of the children
929 wxWindowList m_children
;
931 // the minimal allowed size for the window (no minimal size if variable(s)
938 // event handler for this window: usually is just 'this' but may be
939 // changed with SetEventHandler()
940 wxEvtHandler
*m_eventHandler
;
943 // associated validator or NULL if none
944 wxValidator
*m_windowValidator
;
945 #endif // wxUSE_VALIDATORS
947 #if wxUSE_DRAG_AND_DROP
948 wxDropTarget
*m_dropTarget
;
949 #endif // wxUSE_DRAG_AND_DROP
951 // visual window attributes
954 wxColour m_backgroundColour
, m_foregroundColour
;
958 #endif // wxUSE_CARET
960 // the region which should be repainted in response to paint event
961 wxRegion m_updateRegion
;
964 // the accelerator table for the window which translates key strokes into
966 wxAcceleratorTable m_acceleratorTable
;
967 #endif // wxUSE_ACCEL
969 // the tooltip for this window (may be NULL)
971 wxToolTip
*m_tooltip
;
972 #endif // wxUSE_TOOLTIPS
974 // constraints and sizers
975 #if wxUSE_CONSTRAINTS
976 // the constraints for this window or NULL
977 wxLayoutConstraints
*m_constraints
;
979 // constraints this window is involved in
980 wxWindowList
*m_constraintsInvolvedIn
;
981 #endif // wxUSE_CONSTRAINTS
983 // this window's sizer
984 wxSizer
*m_windowSizer
;
986 // The sizer this window is a member of, if any
987 wxSizer
*m_containingSizer
;
989 // Layout() window automatically when its size changes?
995 bool m_isBeingDeleted
:1;
997 // was the window colours/font explicitly changed by user?
1002 // window attributes
1005 wxString m_windowName
;
1006 bool m_themeEnabled
;
1009 wxPalette m_palette
;
1010 bool m_hasCustomPalette
;
1011 #endif // wxUSE_PALETTE
1013 #if wxUSE_ACCESSIBILITY
1014 wxAccessible
* m_accessible
;
1016 // Virtual size (scrolling)
1017 wxSize m_virtualSize
;
1019 int m_minVirtualWidth
; // VirtualSizeHints
1020 int m_minVirtualHeight
;
1021 int m_maxVirtualWidth
;
1022 int m_maxVirtualHeight
;
1024 // common part of all ctors: it is not virtual because it is called from
1028 // override this to change the default (i.e. used when no style is
1029 // specified) border for the window class
1030 virtual wxBorder
GetDefaultBorder() const;
1032 // get the default size for the new window if no explicit size given
1033 // FIXME why 20 and not 30, 10 or ...?
1034 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
1035 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
1037 // set the best size for the control if the default size was given:
1038 // replaces the fields of size == -1 with the best values for them and
1039 // calls SetSize() if needed
1041 // This function is rather unfortunately named.. it's really just a
1042 // smarter SetSize / convenience function for expanding wxDefaultSize.
1043 // Note that it does not influence the value returned by GetBestSize
1045 void SetBestSize(const wxSize
& size
)
1047 // the size only needs to be changed if the current size is incomplete,
1048 // i.e. one of the components was specified as default -- so if both
1049 // were given, simply don't do anything
1050 if ( size
.x
== -1 || size
.y
== -1 )
1052 wxSize sizeBest
= DoGetBestSize();
1054 sizeBest
.x
= size
.x
;
1056 sizeBest
.y
= size
.y
;
1062 // more pure virtual functions
1063 // ---------------------------
1065 // NB: we must have DoSomething() function when Something() is an overloaded
1066 // method: indeed, we can't just have "virtual Something()" in case when
1067 // the function is overloaded because then we'd have to make virtual all
1068 // the variants (otherwise only the virtual function may be called on a
1069 // pointer to derived class according to C++ rules) which is, in
1070 // general, absolutely not needed. So instead we implement all
1071 // overloaded Something()s in terms of DoSomething() which will be the
1072 // only one to be virtual.
1074 // coordinates translation
1075 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
1076 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
1078 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
1080 // capture/release the mouse, used by Capture/ReleaseMouse()
1081 virtual void DoCaptureMouse() = 0;
1082 virtual void DoReleaseMouse() = 0;
1084 // retrieve the position/size of the window
1085 virtual void DoGetPosition( int *x
, int *y
) const = 0;
1086 virtual void DoGetSize( int *width
, int *height
) const = 0;
1087 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
1089 // get the size which best suits the window: for a control, it would be
1090 // the minimal size which doesn't truncate the control, for a panel - the
1091 // same size as it would have after a call to Fit()
1092 virtual wxSize
DoGetBestSize() const;
1094 // this is the virtual function to be overriden in any derived class which
1095 // wants to change how SetSize() or Move() works - it is called by all
1096 // versions of these functions in the base class
1097 virtual void DoSetSize(int x
, int y
,
1098 int width
, int height
,
1099 int sizeFlags
= wxSIZE_AUTO
) = 0;
1101 // same as DoSetSize() for the client size
1102 virtual void DoSetClientSize(int width
, int height
) = 0;
1104 // move the window to the specified location and resize it: this is called
1105 // from both DoSetSize() and DoSetClientSize() and would usually just
1106 // reposition this window except for composite controls which will want to
1107 // arrange themselves inside the given rectangle
1108 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
1111 virtual void DoSetToolTip( wxToolTip
*tip
);
1112 #endif // wxUSE_TOOLTIPS
1115 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
1116 #endif // wxUSE_MENUS
1118 // Makes an adjustment to the window position (for example, a frame that has
1119 // a toolbar that it manages itself).
1120 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const;
1125 // contains the last id generated by NewControlId
1126 static int ms_lastControlId
;
1128 // the stack of windows which have captured the mouse
1129 static struct WXDLLEXPORT wxWindowNext
*ms_winCaptureNext
;
1131 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
1132 DECLARE_NO_COPY_CLASS(wxWindowBase
)
1133 DECLARE_EVENT_TABLE()
1136 // ----------------------------------------------------------------------------
1137 // now include the declaration of wxWindow class
1138 // ----------------------------------------------------------------------------
1140 // include the declaration of the platform-specific class
1141 #if defined(__WXMSW__)
1142 #ifdef __WXUNIVERSAL__
1143 #define wxWindowNative wxWindowMSW
1145 #define wxWindowMSW wxWindow
1146 #define sm_classwxWindowMSW sm_classwxWindow
1147 #define sm_constructorPropertiesCountwxWindowMSW sm_constructorPropertiesCountwxWindow
1148 #define sm_constructorPropertieswxWindowMSW sm_constructorPropertieswxWindow
1149 #define sm_constructorwxWindowMSW sm_constructorwxWindow
1150 #endif // wxUniv/!wxUniv
1151 #include "wx/msw/window.h"
1152 #elif defined(__WXMOTIF__)
1153 #include "wx/motif/window.h"
1154 #elif defined(__WXGTK__)
1155 #ifdef __WXUNIVERSAL__
1156 #define wxWindowNative wxWindowGTK
1158 #define wxWindowGTK wxWindow
1159 #define sm_classwxWindowGTK sm_classwxWindow
1161 #include "wx/gtk/window.h"
1162 #elif defined(__WXX11__)
1163 #ifdef __WXUNIVERSAL__
1164 #define wxWindowNative wxWindowX11
1166 #define wxWindowX11 wxWindow
1167 #define sm_classwxWindowX11 sm_classwxWindow
1169 #include "wx/x11/window.h"
1170 #elif defined(__WXMGL__)
1171 #ifdef __WXUNIVERSAL__
1172 #define wxWindowNative wxWindowMGL
1174 #define wxWindowMGL wxWindow
1175 #define sm_classwxWindowMGL sm_classwxWindow
1177 #include "wx/mgl/window.h"
1178 #elif defined(__WXMAC__)
1179 #ifdef __WXUNIVERSAL__
1180 #define wxWindowNative wxWindowMac
1182 #define wxWindowMac wxWindow
1183 #define sm_classwxWindowMac sm_classwxWindow
1185 #include "wx/mac/window.h"
1186 #elif defined(__WXCOCOA__)
1187 #ifdef __WXUNIVERSAL__
1188 #define wxWindowNative wxWindowCocoa
1190 #define wxWindowCocoa wxWindow
1191 #define sm_classwxWindowCocoa sm_classwxWindow
1193 #include "wx/cocoa/window.h"
1194 #elif defined(__WXPM__)
1195 #ifdef __WXUNIVERSAL__
1196 #define wxWindowNative wxWindowOS2
1198 #define wxWindowOS2 wxWindow
1199 #define sm_classwxWindowOS2 sm_classwxWindow
1200 #endif // wxUniv/!wxUniv
1201 #include "wx/os2/window.h"
1204 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1205 // for the native ports we already have defined it above
1206 #if defined(__WXUNIVERSAL__)
1207 #ifndef wxWindowNative
1208 #error "wxWindowNative must be defined above!"
1211 #include "wx/univ/window.h"
1214 // ----------------------------------------------------------------------------
1215 // inline functions which couldn't be declared in the class body because of
1216 // forward dependencies
1217 // ----------------------------------------------------------------------------
1219 inline wxWindow
*wxWindowBase::GetGrandParent() const
1221 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1224 // ----------------------------------------------------------------------------
1226 // ----------------------------------------------------------------------------
1228 // Find the wxWindow at the current mouse position, also returning the mouse
1230 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1232 // Get the current mouse position.
1233 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1235 // get the currently active window of this application or NULL
1236 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1238 // get the (first) top level parent window
1239 WXDLLEXPORT wxWindow
* wxGetTopLevelParent(wxWindow
*win
);
1241 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1242 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1244 #if wxUSE_ACCESSIBILITY
1245 // ----------------------------------------------------------------------------
1246 // accessible object for windows
1247 // ----------------------------------------------------------------------------
1249 class WXDLLEXPORT wxWindowAccessible
: public wxAccessible
1252 wxWindowAccessible(wxWindow
* win
): wxAccessible(win
) { if (win
) win
->SetAccessible(this); }
1253 virtual ~wxWindowAccessible() {};
1257 // Can return either a child object, or an integer
1258 // representing the child element, starting from 1.
1259 virtual wxAccStatus
HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
);
1261 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
1262 virtual wxAccStatus
GetLocation(wxRect
& rect
, int elementId
);
1264 // Navigates from fromId to toId/toObject.
1265 virtual wxAccStatus
Navigate(wxNavDir navDir
, int fromId
,
1266 int* toId
, wxAccessible
** toObject
);
1268 // Gets the name of the specified object.
1269 virtual wxAccStatus
GetName(int childId
, wxString
* name
);
1271 // Gets the number of children.
1272 virtual wxAccStatus
GetChildCount(int* childCount
);
1274 // Gets the specified child (starting from 1).
1275 // If *child is NULL and return value is wxACC_OK,
1276 // this means that the child is a simple element and
1277 // not an accessible object.
1278 virtual wxAccStatus
GetChild(int childId
, wxAccessible
** child
);
1280 // Gets the parent, or NULL.
1281 virtual wxAccStatus
GetParent(wxAccessible
** parent
);
1283 // Performs the default action. childId is 0 (the action for this object)
1284 // or > 0 (the action for a child).
1285 // Return wxACC_NOT_SUPPORTED if there is no default action for this
1286 // window (e.g. an edit control).
1287 virtual wxAccStatus
DoDefaultAction(int childId
);
1289 // Gets the default action for this object (0) or > 0 (the action for a child).
1290 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
1291 // string if there is no action.
1292 // The retrieved string describes the action that is performed on an object,
1293 // not what the object does as a result. For example, a toolbar button that prints
1294 // a document has a default action of "Press" rather than "Prints the current document."
1295 virtual wxAccStatus
GetDefaultAction(int childId
, wxString
* actionName
);
1297 // Returns the description for this object or a child.
1298 virtual wxAccStatus
GetDescription(int childId
, wxString
* description
);
1300 // Returns help text for this object or a child, similar to tooltip text.
1301 virtual wxAccStatus
GetHelpText(int childId
, wxString
* helpText
);
1303 // Returns the keyboard shortcut for this object or child.
1304 // Return e.g. ALT+K
1305 virtual wxAccStatus
GetKeyboardShortcut(int childId
, wxString
* shortcut
);
1307 // Returns a role constant.
1308 virtual wxAccStatus
GetRole(int childId
, wxAccRole
* role
);
1310 // Returns a state constant.
1311 virtual wxAccStatus
GetState(int childId
, long* state
);
1313 // Returns a localized string representing the value for the object
1315 virtual wxAccStatus
GetValue(int childId
, wxString
* strValue
);
1317 // Selects the object or child.
1318 virtual wxAccStatus
Select(int childId
, wxAccSelectionFlags selectFlags
);
1320 // Gets the window with the keyboard focus.
1321 // If childId is 0 and child is NULL, no object in
1322 // this subhierarchy has the focus.
1323 // If this object has the focus, child should be 'this'.
1324 virtual wxAccStatus
GetFocus(int* childId
, wxAccessible
** child
);
1326 // Gets a variant representing the selected children
1328 // Acceptable values:
1329 // - a null variant (IsNull() returns TRUE)
1330 // - a list variant (GetType() == wxT("list")
1331 // - an integer representing the selected child element,
1332 // or 0 if this object is selected (GetType() == wxT("long")
1333 // - a "void*" pointer to a wxAccessible child object
1334 virtual wxAccStatus
GetSelections(wxVariant
* selections
);
1337 #endif // wxUSE_ACCESSIBILITY
1341 // _WX_WINDOW_H_BASE_