1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowBase class - the interface of wxWindow
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
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)
39 // when building wxUniv/Foo we don't want the code for native menu use to be
40 // compiled in - it should only be used when building real wxFoo
41 #ifdef __WXUNIVERSAL__
42 #define wxUSE_MENUS_NATIVE 0
44 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
45 #endif // __WXUNIVERSAL__/__WXMSW__
47 // ----------------------------------------------------------------------------
48 // forward declarations
49 // ----------------------------------------------------------------------------
51 class WXDLLEXPORT wxCaret
;
52 class WXDLLEXPORT wxControl
;
53 class WXDLLEXPORT wxCursor
;
54 class WXDLLEXPORT wxDC
;
55 class WXDLLEXPORT wxDropTarget
;
56 class WXDLLEXPORT wxItemResource
;
57 class WXDLLEXPORT wxLayoutConstraints
;
58 class WXDLLEXPORT wxResourceTable
;
59 class WXDLLEXPORT wxSizer
;
60 class WXDLLEXPORT wxToolTip
;
61 class WXDLLEXPORT wxWindowBase
;
62 class WXDLLEXPORT wxWindow
;
64 // ----------------------------------------------------------------------------
65 // (pseudo)template list classes
66 // ----------------------------------------------------------------------------
68 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
, class WXDLLEXPORT
);
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
76 // ----------------------------------------------------------------------------
77 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
78 // interface of this class.
80 // Event handler: windows have themselves as their event handlers by default,
81 // but their event handlers could be set to another object entirely. This
82 // separation can reduce the amount of derivation required, and allow
83 // alteration of a window's functionality (e.g. by a resource editor that
84 // temporarily switches event handlers).
85 // ----------------------------------------------------------------------------
87 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
90 // creating the window
91 // -------------------
94 wxWindowBase() { InitBase(); }
96 // pseudo ctor (can't be virtual, called from ctor)
97 bool CreateBase(wxWindowBase
*parent
,
99 const wxPoint
& pos
= wxDefaultPosition
,
100 const wxSize
& size
= wxDefaultSize
,
102 const wxValidator
& validator
= wxDefaultValidator
,
103 const wxString
& name
= wxPanelNameStr
);
105 virtual ~wxWindowBase();
107 #if wxUSE_WX_RESOURCES
108 // these functions are implemented in resource.cpp and resourc2.cpp
109 virtual bool LoadFromResource(wxWindow
*parent
,
110 const wxString
& resourceName
,
111 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
112 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
113 const wxItemResource
* parentResource
,
114 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
115 #endif // wxUSE_WX_RESOURCES
117 // deleting the window
118 // -------------------
120 // ask the window to close itself, return TRUE if the event handler
121 // honoured our request
122 bool Close( bool force
= FALSE
);
124 // the following functions delete the C++ objects (the window itself
125 // or its children) as well as the GUI windows and normally should
126 // never be used directly
128 // delete window unconditionally (dangerous!), returns TRUE if ok
129 virtual bool Destroy();
130 // delete all children of this window, returns TRUE if ok
131 bool DestroyChildren();
133 // is the window being deleted?
134 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
139 // NB: in future versions of wxWindows Set/GetTitle() will only work
140 // with the top level windows (such as dialogs and frames) and
141 // Set/GetLabel() only with the other ones (i.e. all controls).
143 // the title (or label, see below) of the window: the text which the
145 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) {}
146 virtual wxString
GetTitle() const { return wxEmptyString
; }
148 // label is just the same as the title (but for, e.g., buttons it
149 // makes more sense to speak about labels)
150 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
151 virtual wxString
GetLabel() const { return GetTitle(); }
153 // the window name is used for ressource setting in X, it is not the
154 // same as the window title/label
155 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
156 virtual wxString
GetName() const { return m_windowName
; }
158 // window id uniquely identifies the window among its siblings unless
159 // it is -1 which means "don't care"
160 void SetId( wxWindowID id
) { m_windowId
= id
; }
161 wxWindowID
GetId() const { return m_windowId
; }
163 // generate a control id for the controls which were not given one by
165 static int NewControlId() { return --ms_lastControlId
; }
166 // get the id of the control following the one with the given
167 // (autogenerated) id
168 static int NextControlId(int id
) { return id
- 1; }
169 // get the id of the control preceding the one with the given
170 // (autogenerated) id
171 static int PrevControlId(int id
) { return id
+ 1; }
176 // set the window size and/or position
177 void SetSize( int x
, int y
, int width
, int height
,
178 int sizeFlags
= wxSIZE_AUTO
)
179 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
181 void SetSize( int width
, int height
)
182 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
184 void SetSize( const wxSize
& size
)
185 { SetSize( size
.x
, size
.y
); }
187 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
188 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
190 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
191 { DoSetSize(x
, y
, -1, -1, flags
); }
193 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
194 { Move(pt
.x
, pt
.y
, flags
); }
197 virtual void Raise() = 0;
198 virtual void Lower() = 0;
200 // client size is the size of area available for subwindows
201 void SetClientSize( int width
, int height
)
202 { DoSetClientSize(width
, height
); }
204 void SetClientSize( const wxSize
& size
)
205 { DoSetClientSize(size
.x
, size
.y
); }
207 void SetClientSize(const wxRect
& rect
)
208 { SetClientSize( rect
.width
, rect
.height
); }
210 // get the window position and/or size (pointers may be NULL)
211 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
212 wxPoint
GetPosition() const
215 DoGetPosition(&w
, &h
);
217 return wxPoint(w
, h
);
220 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
221 wxSize
GetSize() const
228 wxRect
GetRect() const
231 GetPosition(& x
, & y
);
234 return wxRect(x
, y
, w
, h
);
237 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
238 wxSize
GetClientSize() const
241 DoGetClientSize(& w
, & h
);
246 // get the origin of the client area of the window relative to the
247 // window top left corner (the client area may be shifted because of
248 // the borders, scrollbars, other decorations...)
249 virtual wxPoint
GetClientAreaOrigin() const;
251 // get the client rectangle in window (i.e. client) coordinates
252 wxRect
GetClientRect() const
254 return wxRect(GetClientAreaOrigin(), GetClientSize());
257 // get the size best suited for the window (in fact, minimal
258 // acceptable size using which it will still look "nice")
259 wxSize
GetBestSize() const { return DoGetBestSize(); }
260 void GetBestSize(int *w
, int *h
) const
262 wxSize s
= DoGetBestSize();
269 // the generic centre function - centers the window on parent by
270 // default or on screen if it doesn't have parent or
271 // wxCENTER_ON_SCREEN flag is given
272 void Centre( int direction
= wxBOTH
);
273 void Center( int direction
= wxBOTH
) { Centre(direction
); }
275 // centre on screen (only works for top level windows)
276 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
277 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
279 // centre with respect to the the parent window
280 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
281 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
283 // set window size to wrap around its children
286 // set min/max size of the window
287 virtual void SetSizeHints( int minW
, int minH
,
288 int maxW
= -1, int maxH
= -1,
289 int incW
= -1, int incH
= -1 );
291 int GetMinWidth() const { return m_minWidth
; }
292 int GetMinHeight() const { return m_minHeight
; }
293 int GetMaxWidth() const { return m_maxWidth
; }
294 int GetMaxHeight() const { return m_maxHeight
; }
299 // returns TRUE if window was shown/hidden, FALSE if the nothing was
300 // done (window was already shown/hidden)
301 virtual bool Show( bool show
= TRUE
);
302 bool Hide() { return Show(FALSE
); }
304 // returns TRUE if window was enabled/disabled, FALSE if nothing done
305 virtual bool Enable( bool enable
= TRUE
);
306 bool Disable() { return Enable(FALSE
); }
308 bool IsShown() const { return m_isShown
; }
309 bool IsEnabled() const { return m_isEnabled
; }
311 // get/set window style (setting style won't update the window and so
312 // is only useful for internal usage)
313 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
314 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
316 // just some (somewhat shorter) synonims
317 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
318 long GetWindowStyle() const { return GetWindowStyleFlag(); }
320 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
321 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
323 // extra style: the less often used style bits which can't be set with
324 // SetWindowStyleFlag()
325 void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
326 long GetExtraStyle() const { return m_exStyle
; }
328 // make the window modal (all other windows unresponsive)
329 virtual void MakeModal(bool modal
= TRUE
);
331 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
332 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
334 // focus and keyboard handling
335 // ---------------------------
337 // set focus to this window
338 virtual void SetFocus() = 0;
340 // return the window which currently has the focus or NULL
341 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
343 // can this window have focus?
344 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
346 // can this window be given focus by keyboard navigation? if not, the
347 // only way to give it focus (provided it accepts it at all) is to
349 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
351 // NB: these methods really don't belong here but with the current
352 // class hierarchy there is no other place for them :-(
354 // get the default child of this parent, i.e. the one which is
355 // activated by pressing <Enter>
356 virtual wxWindow
*GetDefaultItem() const { return NULL
; }
358 // set this child as default, return the old default
359 virtual wxWindow
*SetDefaultItem(wxWindow
* WXUNUSED(child
))
362 // parent/children relations
363 // -------------------------
365 // get the list of children
366 const wxWindowList
& GetChildren() const { return m_children
; }
367 wxWindowList
& GetChildren() { return m_children
; }
369 // get the parent or the parent of the parent
370 wxWindow
*GetParent() const { return m_parent
; }
371 inline wxWindow
*GetGrandParent() const;
373 // is this window a top level one?
374 virtual bool IsTopLevel() const;
376 // it doesn't really change parent, use ReParent() instead
377 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
378 // change the real parent of this window, return TRUE if the parent
379 // was changed, FALSE otherwise (error or newParent == oldParent)
380 virtual bool Reparent( wxWindowBase
*newParent
);
382 // find window among the descendants of this one either by id or by
383 // name (return NULL if not found)
384 wxWindow
*FindWindow( long id
);
385 wxWindow
*FindWindow( const wxString
& name
);
387 // implementation mostly
388 virtual void AddChild( wxWindowBase
*child
);
389 virtual void RemoveChild( wxWindowBase
*child
);
391 // event handler stuff
392 // -------------------
394 // get the current event handler
395 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
397 // replace the event handler (allows to completely subclass the
399 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
401 // push/pop event handler: allows to chain a custom event handler to
402 // alreasy existing ones
403 void PushEventHandler( wxEvtHandler
*handler
);
404 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
410 // a window may have an associated validator which is used to control
412 virtual void SetValidator( const wxValidator
&validator
);
413 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
414 #endif // wxUSE_VALIDATORS
417 // dialog oriented functions
418 // -------------------------
420 // validate the correctness of input, return TRUE if ok
421 virtual bool Validate();
423 // transfer data between internal and GUI representations
424 virtual bool TransferDataToWindow();
425 virtual bool TransferDataFromWindow();
427 virtual void InitDialog();
432 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
433 { m_acceleratorTable
= accel
; }
434 wxAcceleratorTable
*GetAcceleratorTable()
435 { return &m_acceleratorTable
; }
436 #endif // wxUSE_ACCEL
438 // dialog units translations
439 // -------------------------
441 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
442 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
443 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
445 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
447 return wxSize(pt
.x
, pt
.y
);
450 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
452 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
454 return wxSize(pt
.x
, pt
.y
);
460 // move the mouse to the specified position
461 virtual void WarpPointer(int x
, int y
) = 0;
463 // start or end mouse capture
464 virtual void CaptureMouse() = 0;
465 virtual void ReleaseMouse() = 0;
467 // get the window which currently captures the mouse or NULL
468 static wxWindow
*GetCapture();
470 // does this window have the capture?
471 virtual bool HasCapture() const
472 { return (wxWindow
*)this == GetCapture(); }
474 // painting the window
475 // -------------------
477 // mark the specified rectangle (or the whole window) as "dirty" so it
479 virtual void Refresh( bool eraseBackground
= TRUE
,
480 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
482 // a less awkward wrapper for Refresh
483 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
485 // repaint all invalid areas of the window immediately
486 virtual void Update() { }
488 // clear the window entirely
489 virtual void Clear() = 0;
491 // freeze the window: don't redraw it until it is thawed
492 virtual void Freeze() { }
494 // thaw the window: redraw it after it had been frozen
495 virtual void Thaw() { }
497 // adjust DC for drawing on this window
498 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
500 // the update region of the window contains the areas which must be
501 // repainted by the program
502 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
503 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
505 // get the update rectangleregion bounding box in client coords
506 wxRect
GetUpdateClientRect() const;
508 // these functions verify whether the given point/rectangle belongs to
509 // (or at least intersects with) the update region
510 bool IsExposed( int x
, int y
) const;
511 bool IsExposed( int x
, int y
, int w
, int h
) const;
513 bool IsExposed( const wxPoint
& pt
) const
514 { return IsExposed(pt
.x
, pt
.y
); }
515 bool IsExposed( const wxRect
& rect
) const
516 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
518 // colours, fonts and cursors
519 // --------------------------
521 // set/retrieve the window colours (system defaults are used by
522 // default): Set functions return TRUE if colour was changed
523 virtual bool SetBackgroundColour( const wxColour
&colour
);
524 virtual bool SetForegroundColour( const wxColour
&colour
);
526 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
527 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
529 // set/retrieve the cursor for this window (SetCursor() returns TRUE
530 // if the cursor was really changed)
531 virtual bool SetCursor( const wxCursor
&cursor
);
532 const wxCursor
& GetCursor() const { return m_cursor
; }
533 wxCursor
& GetCursor() { return m_cursor
; }
535 // set/retrieve the font for the window (SetFont() returns TRUE if the
536 // font really changed)
537 virtual bool SetFont( const wxFont
&font
) = 0;
538 const wxFont
& GetFont() const { return m_font
; }
539 wxFont
& GetFont() { return m_font
; }
542 // associate a caret with the window
543 void SetCaret(wxCaret
*caret
);
544 // get the current caret (may be NULL)
545 wxCaret
*GetCaret() const { return m_caret
; }
546 #endif // wxUSE_CARET
548 // get the (average) character size for the current font
549 virtual int GetCharHeight() const = 0;
550 virtual int GetCharWidth() const = 0;
552 // get the width/height/... of the text using current or specified
554 virtual void GetTextExtent(const wxString
& string
,
556 int *descent
= (int *) NULL
,
557 int *externalLeading
= (int *) NULL
,
558 const wxFont
*theFont
= (const wxFont
*) NULL
)
561 // client <-> screen coords
562 // ------------------------
564 // translate to/from screen/client coordinates (pointers may be NULL)
565 void ClientToScreen( int *x
, int *y
) const
566 { DoClientToScreen(x
, y
); }
567 void ScreenToClient( int *x
, int *y
) const
568 { DoScreenToClient(x
, y
); }
570 // wxPoint interface to do the same thing
571 wxPoint
ClientToScreen(const wxPoint
& pt
) const
573 int x
= pt
.x
, y
= pt
.y
;
574 DoClientToScreen(&x
, &y
);
576 return wxPoint(x
, y
);
579 wxPoint
ScreenToClient(const wxPoint
& pt
) const
581 int x
= pt
.x
, y
= pt
.y
;
582 DoScreenToClient(&x
, &y
);
584 return wxPoint(x
, y
);
587 // test where the given (in client coords) point lies
588 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
589 { return DoHitTest(x
, y
); }
591 wxHitTest
HitTest(const wxPoint
& pt
) const
592 { return DoHitTest(pt
.x
, pt
.y
); }
597 // get the window border style: uses the current style and falls back to
598 // the default style for this class otherwise (see GetDefaultBorder())
599 wxBorder
GetBorder() const;
601 void UpdateWindowUI();
604 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
605 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
606 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
607 { return DoPopupMenu(menu
, x
, y
); }
608 #endif // wxUSE_MENUS
613 // does the window have the scrollbar for this orientation?
614 bool HasScrollbar(int orient
) const
616 return (m_windowStyle
&
617 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
620 // configure the window scrollbars
621 virtual void SetScrollbar( int orient
,
625 bool refresh
= TRUE
) = 0;
626 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
627 virtual int GetScrollPos( int orient
) const = 0;
628 virtual int GetScrollThumb( int orient
) const = 0;
629 virtual int GetScrollRange( int orient
) const = 0;
631 // scroll window to the specified position
632 virtual void ScrollWindow( int dx
, int dy
,
633 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
635 // scrolls window by line/page: note that not all controls support this
637 // return TRUE if the position changed, FALSE otherwise
638 virtual bool ScrollLines(int WXUNUSED(lines
)) { return FALSE
; }
639 virtual bool ScrollPages(int WXUNUSED(pages
)) { return FALSE
; }
641 // convenient wrappers for ScrollLines/Pages
642 bool LineUp() { return ScrollLines(-1); }
643 bool LineDown() { return ScrollLines(1); }
644 bool PageUp() { return ScrollPages(-1); }
645 bool PageDown() { return ScrollPages(1); }
647 // context-sensitive help
648 // ----------------------
650 // these are the convenience functions wrapping wxHelpProvider methods
653 // associate this help text with this window
654 void SetHelpText(const wxString
& text
);
655 // associate this help text with all windows with the same id as this
657 void SetHelpTextForId(const wxString
& text
);
658 // get the help string associated with this window (may be empty)
659 wxString
GetHelpText() const;
666 // the easiest way to set a tooltip for a window is to use this method
667 void SetToolTip( const wxString
&tip
);
668 // attach a tooltip to the window
669 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
670 // get the associated tooltip or NULL if none
671 wxToolTip
* GetToolTip() const { return m_tooltip
; }
672 #endif // wxUSE_TOOLTIPS
676 #if wxUSE_DRAG_AND_DROP
677 // set/retrieve the drop target associated with this window (may be
678 // NULL; it's owned by the window and will be deleted by it)
679 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
680 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
681 #endif // wxUSE_DRAG_AND_DROP
683 // constraints and sizers
684 // ----------------------
685 #if wxUSE_CONSTRAINTS
686 // set the constraints for this window or retrieve them (may be NULL)
687 void SetConstraints( wxLayoutConstraints
*constraints
);
688 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
690 // when using constraints, it makes sense to update children positions
691 // automatically whenever the window is resized - this is done if
693 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
694 bool GetAutoLayout() const { return m_autoLayout
; }
696 // do layout the window and its children
697 virtual bool Layout();
699 // implementation only
700 void UnsetConstraints(wxLayoutConstraints
*c
);
701 wxWindowList
*GetConstraintsInvolvedIn() const
702 { return m_constraintsInvolvedIn
; }
703 void AddConstraintReference(wxWindowBase
*otherWin
);
704 void RemoveConstraintReference(wxWindowBase
*otherWin
);
705 void DeleteRelatedConstraints();
706 void ResetConstraints();
708 // these methods may be overriden for special layout algorithms
709 virtual void SetConstraintSizes(bool recurse
= TRUE
);
710 virtual bool LayoutPhase1(int *noChanges
);
711 virtual bool LayoutPhase2(int *noChanges
);
712 virtual bool DoPhase(int phase
);
714 // these methods are virtual but normally won't be overridden
715 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
716 virtual void MoveConstraint(int x
, int y
);
717 virtual void GetSizeConstraint(int *w
, int *h
) const ;
718 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
719 virtual void GetPositionConstraint(int *x
, int *y
) const ;
722 // TODO: what are they and how do they work??
723 void SetSizer( wxSizer
*sizer
);
724 wxSizer
*GetSizer() const { return m_windowSizer
; }
725 #endif // wxUSE_CONSTRAINTS
727 // backward compatibility
728 // ----------------------
729 #if WXWIN_COMPATIBILITY
730 bool Enabled() const { return IsEnabled(); }
732 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
733 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
734 wxFont
& GetLabelFont() { return GetFont(); };
735 wxFont
& GetButtonFont() { return GetFont(); };
736 #endif // WXWIN_COMPATIBILITY
742 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
743 void OnInitDialog( wxInitDialogEvent
&event
);
744 void OnMiddleClick( wxMouseEvent
& event
);
746 void OnHelp(wxHelpEvent
& event
);
749 // get the haqndle of the window for the underlying window system: this
750 // is only used for wxWin itself or for user code which wants to call
751 // platform-specific APIs
752 virtual WXWidget
GetHandle() const = 0;
755 // the window id - a number which uniquely identifies a window among
756 // its siblings unless it is -1
757 wxWindowID m_windowId
;
759 // the parent window of this window (or NULL) and the list of the children
762 wxWindowList m_children
;
764 // the minimal allowed size for the window (no minimal size if variable(s)
766 int m_minWidth
, m_minHeight
, m_maxWidth
, m_maxHeight
;
768 // event handler for this window: usually is just 'this' but may be
769 // changed with SetEventHandler()
770 wxEvtHandler
*m_eventHandler
;
773 // associated validator or NULL if none
774 wxValidator
*m_windowValidator
;
775 #endif // wxUSE_VALIDATORS
777 #if wxUSE_DRAG_AND_DROP
778 wxDropTarget
*m_dropTarget
;
779 #endif // wxUSE_DRAG_AND_DROP
781 // visual window attributes
784 wxColour m_backgroundColour
, m_foregroundColour
;
788 #endif // wxUSE_CARET
790 // the region which should be repainted in response to paint event
791 wxRegion m_updateRegion
;
794 // the accelerator table for the window which translates key strokes into
796 wxAcceleratorTable m_acceleratorTable
;
797 #endif // wxUSE_ACCEL
799 // the tooltip for this window (may be NULL)
801 wxToolTip
*m_tooltip
;
802 #endif // wxUSE_TOOLTIPS
804 // constraints and sizers
805 #if wxUSE_CONSTRAINTS
806 // the constraints for this window or NULL
807 wxLayoutConstraints
*m_constraints
;
809 // constraints this window is involved in
810 wxWindowList
*m_constraintsInvolvedIn
;
812 // top level and the parent sizers
813 // TODO what's this and how does it work?)
814 wxSizer
*m_windowSizer
;
815 wxWindowBase
*m_sizerParent
;
817 // Layout() window automatically when its size changes?
819 #endif // wxUSE_CONSTRAINTS
824 bool m_isBeingDeleted
:1;
826 // was the window colours/font explicitly changed by user?
834 wxString m_windowName
;
838 // common part of all ctors: it is not virtual because it is called from
842 // override this to change the default (i.e. used when no style is
843 // specified) border for the window class
844 virtual wxBorder
GetDefaultBorder() const;
846 // get the default size for the new window if no explicit size given
847 // FIXME why 20 and not 30, 10 or ...?
848 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
849 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
851 // set the best size for the control if the default size was given:
852 // replaces the fields of size == -1 with the best values for them and
853 // calls SetSize() if needed
854 void SetBestSize(const wxSize
& size
)
856 if ( size
.x
== -1 || size
.y
== -1 )
858 wxSize sizeBest
= DoGetBestSize();
868 // more pure virtual functions
869 // ---------------------------
871 // NB: we must have DoSomething() function when Something() is an overloaded
872 // method: indeed, we can't just have "virtual Something()" in case when
873 // the function is overloaded because then we'd have to make virtual all
874 // the variants (otherwise only the virtual function may be called on a
875 // pointer to derived class according to C++ rules) which is, in
876 // general, absolutely not needed. So instead we implement all
877 // overloaded Something()s in terms of DoSomething() which will be the
878 // only one to be virtual.
880 // coordinates translation
881 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
882 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
884 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
886 // retrieve the position/size of the window
887 virtual void DoGetPosition( int *x
, int *y
) const = 0;
888 virtual void DoGetSize( int *width
, int *height
) const = 0;
889 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
891 // get the size which best suits the window: for a control, it would be
892 // the minimal size which doesn't truncate the control, for a panel - the
893 // same size as it would have after a call to Fit()
894 virtual wxSize
DoGetBestSize() const;
896 // this is the virtual function to be overriden in any derived class which
897 // wants to change how SetSize() or Move() works - it is called by all
898 // versions of these functions in the base class
899 virtual void DoSetSize(int x
, int y
,
900 int width
, int height
,
901 int sizeFlags
= wxSIZE_AUTO
) = 0;
903 // same as DoSetSize() for the client size
904 virtual void DoSetClientSize(int width
, int height
) = 0;
906 // move the window to the specified location and resize it: this is called
907 // from both DoSetSize() and DoSetClientSize() and would usually just
908 // reposition this window except for composite controls which will want to
909 // arrange themselves inside the given rectangle
910 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
913 virtual void DoSetToolTip( wxToolTip
*tip
);
914 #endif // wxUSE_TOOLTIPS
917 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
918 #endif // wxUSE_MENUS
920 // Makes an adjustment to the window position (for example, a frame that has
921 // a toolbar that it manages itself).
922 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
925 // contains the last id generated by NewControlId
926 static int ms_lastControlId
;
928 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
929 DECLARE_NO_COPY_CLASS(wxWindowBase
)
930 DECLARE_EVENT_TABLE()
933 // ----------------------------------------------------------------------------
934 // now include the declaration of wxWindow class
935 // ----------------------------------------------------------------------------
937 // include the declaration of the platform-specific class
938 #if defined(__WXMSW__)
939 #ifdef __WXUNIVERSAL__
940 #define wxWindowNative wxWindowMSW
942 #define wxWindowMSW wxWindow
943 #define sm_classwxWindowMSW sm_classwxWindow
944 #endif // wxUniv/!wxUniv
945 #include "wx/msw/window.h"
946 #elif defined(__WXMOTIF__)
947 #include "wx/motif/window.h"
948 #elif defined(__WXGTK__)
949 #ifdef __WXUNIVERSAL__
950 #define wxWindowNative wxWindowGTK
952 #define wxWindowGTK wxWindow
953 #define sm_classwxWindowGTK sm_classwxWindow
955 #include "wx/gtk/window.h"
956 #elif defined(__WXMGL__)
957 #ifdef __WXUNIVERSAL__
958 #define wxWindowNative wxWindowMGL
960 #define wxWindowMGL wxWindow
961 #define sm_classwxWindowMGL sm_classwxWindow
963 #include "wx/mgl/window.h"
964 #elif defined(__WXMAC__)
965 #ifdef __WXUNIVERSAL__
966 #define wxWindowNative wxWindowMac
968 #define wxWindowMac wxWindow
969 #define sm_classwxWindowMac sm_classwxWindow
971 #include "wx/mac/window.h"
972 #elif defined(__WXPM__)
973 #ifdef __WXUNIVERSAL__
974 #define wxWindowNative wxWindowOS2
976 #define wxWindowOS2 wxWindow
977 #define sm_classwxWindowOS2 sm_classwxWindow
978 #endif // wxUniv/!wxUniv
979 #include "wx/os2/window.h"
982 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
983 // for the native ports we already have defined it above
984 #if defined(__WXUNIVERSAL__)
985 #ifndef wxWindowNative
986 #error "wxWindowNative must be defined above!"
989 #include "wx/univ/window.h"
992 // ----------------------------------------------------------------------------
993 // inline functions which couldn't be declared in the class body because of
994 // forward dependencies
995 // ----------------------------------------------------------------------------
997 inline wxWindow
*wxWindowBase::GetGrandParent() const
999 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1002 // ----------------------------------------------------------------------------
1004 // ----------------------------------------------------------------------------
1006 // Find the wxWindow at the current mouse position, also returning the mouse
1008 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1010 // Get the current mouse position.
1011 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1013 // get the currently active window of this application or NULL
1014 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1016 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1017 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1020 // _WX_WINDOW_H_BASE_