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 wxClientData
;
53 class WXDLLEXPORT wxControl
;
54 class WXDLLEXPORT wxCursor
;
55 class WXDLLEXPORT wxDC
;
56 class WXDLLEXPORT wxDropTarget
;
57 class WXDLLEXPORT wxItemResource
;
58 class WXDLLEXPORT wxLayoutConstraints
;
59 class WXDLLEXPORT wxResourceTable
;
60 class WXDLLEXPORT wxSizer
;
61 class WXDLLEXPORT wxToolTip
;
62 class WXDLLEXPORT wxWindowBase
;
63 class WXDLLEXPORT wxWindow
;
65 // ----------------------------------------------------------------------------
66 // (pseudo)template list classes
67 // ----------------------------------------------------------------------------
69 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
, class WXDLLEXPORT
);
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
77 // ----------------------------------------------------------------------------
78 // helper classes used by [SG]etClientObject/Data
80 // TODO move into a separate header?
81 // ----------------------------------------------------------------------------
83 // what kind of client data do we have?
86 wxClientData_None
, // we don't know yet because we don't have it at all
87 wxClientData_Object
, // our client data is typed and we own it
88 wxClientData_Void
// client data is untyped and we don't own it
95 virtual ~wxClientData() { }
98 class wxStringClientData
: public wxClientData
101 wxStringClientData() { }
102 wxStringClientData( const wxString
&data
) : m_data(data
) { }
103 void SetData( const wxString
&data
) { m_data
= data
; }
104 const wxString
& GetData() const { return m_data
; }
110 // ----------------------------------------------------------------------------
111 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
112 // interface of this class.
114 // Event handler: windows have themselves as their event handlers by default,
115 // but their event handlers could be set to another object entirely. This
116 // separation can reduce the amount of derivation required, and allow
117 // alteration of a window's functionality (e.g. by a resource editor that
118 // temporarily switches event handlers).
119 // ----------------------------------------------------------------------------
121 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
124 // creating the window
125 // -------------------
128 wxWindowBase() { InitBase(); }
130 // pseudo ctor (can't be virtual, called from ctor)
131 bool CreateBase(wxWindowBase
*parent
,
133 const wxPoint
& pos
= wxDefaultPosition
,
134 const wxSize
& size
= wxDefaultSize
,
136 const wxValidator
& validator
= wxDefaultValidator
,
137 const wxString
& name
= wxPanelNameStr
);
139 virtual ~wxWindowBase();
141 #if wxUSE_WX_RESOURCES
142 // these functions are implemented in resource.cpp and resourc2.cpp
143 virtual bool LoadFromResource(wxWindow
*parent
,
144 const wxString
& resourceName
,
145 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
146 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
147 const wxItemResource
* parentResource
,
148 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
149 #endif // wxUSE_WX_RESOURCES
151 // deleting the window
152 // -------------------
154 // ask the window to close itself, return TRUE if the event handler
155 // honoured our request
156 bool Close( bool force
= FALSE
);
158 // the following functions delete the C++ objects (the window itself
159 // or its children) as well as the GUI windows and normally should
160 // never be used directly
162 // delete window unconditionally (dangerous!), returns TRUE if ok
163 virtual bool Destroy();
164 // delete all children of this window, returns TRUE if ok
165 bool DestroyChildren();
167 // is the window being deleted?
168 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
173 // the title (or label, see below) of the window: the text which the
175 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) { }
176 virtual wxString
GetTitle() const { return ""; }
178 // label is just the same as the title (but for, e.g., buttons it
179 // makes more sense to speak about labels)
180 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
181 virtual wxString
GetLabel() const { return GetTitle(); }
183 // the window name is used for ressource setting in X, it is not the
184 // same as the window title/label
185 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
186 virtual wxString
GetName() const { return m_windowName
; }
188 // window id uniquely identifies the window among its siblings unless
189 // it is -1 which means "don't care"
190 void SetId( wxWindowID id
) { m_windowId
= id
; }
191 wxWindowID
GetId() const { return m_windowId
; }
193 // generate a control id for the controls which were not given one by
195 static int NewControlId() { return --ms_lastControlId
; }
196 // get the id of the control following the one with the given
197 // (autogenerated) id
198 static int NextControlId(int id
) { return id
- 1; }
199 // get the id of the control preceding the one with the given
200 // (autogenerated) id
201 static int PrevControlId(int id
) { return id
+ 1; }
206 // set the window size and/or position
207 void SetSize( int x
, int y
, int width
, int height
,
208 int sizeFlags
= wxSIZE_AUTO
)
209 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
211 void SetSize( int width
, int height
)
212 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
214 void SetSize( const wxSize
& size
)
215 { SetSize( size
.x
, size
.y
); }
217 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
218 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
220 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
221 { DoSetSize(x
, y
, -1, -1, flags
); }
223 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
224 { Move(pt
.x
, pt
.y
, flags
); }
227 virtual void Raise() = 0;
228 virtual void Lower() = 0;
230 // client size is the size of area available for subwindows
231 void SetClientSize( int width
, int height
)
232 { DoSetClientSize(width
, height
); }
234 void SetClientSize( const wxSize
& size
)
235 { DoSetClientSize(size
.x
, size
.y
); }
237 void SetClientSize(const wxRect
& rect
)
238 { SetClientSize( rect
.width
, rect
.height
); }
240 // get the window position and/or size (pointers may be NULL)
241 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
242 wxPoint
GetPosition() const
245 DoGetPosition(&w
, &h
);
247 return wxPoint(w
, h
);
250 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
251 wxSize
GetSize() const
258 wxRect
GetRect() const
261 GetPosition(& x
, & y
);
264 return wxRect(x
, y
, w
, h
);
267 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
268 wxSize
GetClientSize() const
271 DoGetClientSize(& w
, & h
);
276 // get the origin of the client area of the window relative to the
277 // window top left corner (the client area may be shifted because of
278 // the borders, scrollbars, other decorations...)
279 virtual wxPoint
GetClientAreaOrigin() const;
281 // get the client rectangle in window (i.e. client) coordinates
282 wxRect
GetClientRect() const
284 return wxRect(GetClientAreaOrigin(), GetClientSize());
287 // get the size best suited for the window (in fact, minimal
288 // acceptable size using which it will still look "nice")
289 wxSize
GetBestSize() const { return DoGetBestSize(); }
290 void GetBestSize(int *w
, int *h
) const
292 wxSize s
= DoGetBestSize();
299 // the generic centre function - centers the window on parent by
300 // default or on screen if it doesn't have parent or
301 // wxCENTER_ON_SCREEN flag is given
302 void Centre( int direction
= wxBOTH
);
303 void Center( int direction
= wxBOTH
) { Centre(direction
); }
305 // centre on screen (only works for top level windows)
306 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
307 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
309 // centre with respect to the the parent window
310 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
311 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
313 // set window size to wrap around its children
316 // set min/max size of the window
317 virtual void SetSizeHints( int minW
, int minH
,
318 int maxW
= -1, int maxH
= -1,
319 int incW
= -1, int incH
= -1 );
321 int GetMinWidth() const { return m_minWidth
; }
322 int GetMinHeight() const { return m_minHeight
; }
323 int GetMaxWidth() const { return m_maxWidth
; }
324 int GetMaxHeight() const { return m_maxHeight
; }
329 // returns TRUE if window was shown/hidden, FALSE if the nothing was
330 // done (window was already shown/hidden)
331 virtual bool Show( bool show
= TRUE
);
332 bool Hide() { return Show(FALSE
); }
334 // returns TRUE if window was enabled/disabled, FALSE if nothing done
335 virtual bool Enable( bool enable
= TRUE
);
336 bool Disable() { return Enable(FALSE
); }
338 bool IsShown() const { return m_isShown
; }
339 bool IsEnabled() const { return m_isEnabled
; }
341 // get/set window style (setting style won't update the window and so
342 // is only useful for internal usage)
343 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
344 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
346 // just some (somewhat shorter) synonims
347 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
348 long GetWindowStyle() const { return GetWindowStyleFlag(); }
350 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
351 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
353 // extra style: the less often used style bits which can't be set with
354 // SetWindowStyleFlag()
355 void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
356 long GetExtraStyle() const { return m_exStyle
; }
358 // make the window modal (all other windows unresponsive)
359 virtual void MakeModal(bool modal
= TRUE
);
361 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
362 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
367 // set focus to this window
368 virtual void SetFocus() = 0;
370 // return the window which currently has the focus or NULL
371 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
373 // can this window have focus?
374 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
376 // can this window be given focus by keyboard navigation? if not, the
377 // only way to give it focus (provided it accepts it at all) is to
379 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
381 // parent/children relations
382 // -------------------------
384 // get the list of children
385 const wxWindowList
& GetChildren() const { return m_children
; }
386 wxWindowList
& GetChildren() { return m_children
; }
388 // get the parent or the parent of the parent
389 wxWindow
*GetParent() const { return m_parent
; }
390 inline wxWindow
*GetGrandParent() const;
392 // is this window a top level one?
393 virtual bool IsTopLevel() const;
395 // it doesn't really change parent, use ReParent() instead
396 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
397 // change the real parent of this window, return TRUE if the parent
398 // was changed, FALSE otherwise (error or newParent == oldParent)
399 virtual bool Reparent( wxWindowBase
*newParent
);
401 // find window among the descendants of this one either by id or by
402 // name (return NULL if not found)
403 wxWindow
*FindWindow( long id
);
404 wxWindow
*FindWindow( const wxString
& name
);
406 // implementation mostly
407 virtual void AddChild( wxWindowBase
*child
);
408 virtual void RemoveChild( wxWindowBase
*child
);
410 // event handler stuff
411 // -------------------
413 // get the current event handler
414 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
416 // replace the event handler (allows to completely subclass the
418 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
420 // push/pop event handler: allows to chain a custom event handler to
421 // alreasy existing ones
422 void PushEventHandler( wxEvtHandler
*handler
);
423 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
429 // a window may have an associated validator which is used to control
431 virtual void SetValidator( const wxValidator
&validator
);
432 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
433 #endif // wxUSE_VALIDATORS
438 // each window may have associated client data: either a pointer to
439 // wxClientData object in which case it is managed by the window (i.e.
440 // it will delete the data when it's destroyed) or an untyped pointer
441 // which won't be deleted by the window - but not both of them
442 void SetClientObject( wxClientData
*data
) { DoSetClientObject(data
); }
443 wxClientData
*GetClientObject() const { return DoGetClientObject(); }
445 void SetClientData( void *data
) { DoSetClientData(data
); }
446 void *GetClientData() const { return DoGetClientData(); }
448 // dialog oriented functions
449 // -------------------------
451 // validate the correctness of input, return TRUE if ok
452 virtual bool Validate();
454 // transfer data between internal and GUI representations
455 virtual bool TransferDataToWindow();
456 virtual bool TransferDataFromWindow();
458 virtual void InitDialog();
463 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
464 { m_acceleratorTable
= accel
; }
465 wxAcceleratorTable
*GetAcceleratorTable()
466 { return &m_acceleratorTable
; }
467 #endif // wxUSE_ACCEL
469 // dialog units translations
470 // -------------------------
472 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
473 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
474 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
476 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
478 return wxSize(pt
.x
, pt
.y
);
481 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
483 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
485 return wxSize(pt
.x
, pt
.y
);
491 // move the mouse to the specified position
492 virtual void WarpPointer(int x
, int y
) = 0;
494 // start or end mouse capture
495 virtual void CaptureMouse() = 0;
496 virtual void ReleaseMouse() = 0;
498 // get the window which currently captures the mouse or NULL
499 static wxWindow
*GetCapture();
501 // does this window have the capture?
502 virtual bool HasCapture() const
503 { return (wxWindow
*)this == GetCapture(); }
505 // painting the window
506 // -------------------
508 // mark the specified rectangle (or the whole window) as "dirty" so it
510 virtual void Refresh( bool eraseBackground
= TRUE
,
511 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
513 // a less awkward wrapper for Refresh
514 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
516 // repaint all invalid areas of the window immediately
517 virtual void Update() { }
519 // clear the window entirely
520 virtual void Clear() = 0;
522 // adjust DC for drawing on this window
523 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
525 // the update region of the window contains the areas which must be
526 // repainted by the program
527 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
528 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
530 // get the update rectangleregion bounding box in client coords
531 wxRect
GetUpdateClientRect() const;
533 // these functions verify whether the given point/rectangle belongs to
534 // (or at least intersects with) the update region
535 bool IsExposed( int x
, int y
) const;
536 bool IsExposed( int x
, int y
, int w
, int h
) const;
538 bool IsExposed( const wxPoint
& pt
) const
539 { return IsExposed(pt
.x
, pt
.y
); }
540 bool IsExposed( const wxRect
& rect
) const
541 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
543 // colours, fonts and cursors
544 // --------------------------
546 // set/retrieve the window colours (system defaults are used by
547 // default): Set functions return TRUE if colour was changed
548 virtual bool SetBackgroundColour( const wxColour
&colour
);
549 virtual bool SetForegroundColour( const wxColour
&colour
);
551 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
552 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
554 // set/retrieve the cursor for this window (SetCursor() returns TRUE
555 // if the cursor was really changed)
556 virtual bool SetCursor( const wxCursor
&cursor
);
557 const wxCursor
& GetCursor() const { return m_cursor
; }
558 wxCursor
& GetCursor() { return m_cursor
; }
560 // set/retrieve the font for the window (SetFont() returns TRUE if the
561 // font really changed)
562 virtual bool SetFont( const wxFont
&font
) = 0;
563 const wxFont
& GetFont() const { return m_font
; }
564 wxFont
& GetFont() { return m_font
; }
567 // associate a caret with the window
568 void SetCaret(wxCaret
*caret
);
569 // get the current caret (may be NULL)
570 wxCaret
*GetCaret() const { return m_caret
; }
571 #endif // wxUSE_CARET
573 // get the (average) character size for the current font
574 virtual int GetCharHeight() const = 0;
575 virtual int GetCharWidth() const = 0;
577 // get the width/height/... of the text using current or specified
579 virtual void GetTextExtent(const wxString
& string
,
581 int *descent
= (int *) NULL
,
582 int *externalLeading
= (int *) NULL
,
583 const wxFont
*theFont
= (const wxFont
*) NULL
)
586 // client <-> screen coords
587 // ------------------------
589 // translate to/from screen/client coordinates (pointers may be NULL)
590 void ClientToScreen( int *x
, int *y
) const
591 { DoClientToScreen(x
, y
); }
592 void ScreenToClient( int *x
, int *y
) const
593 { DoScreenToClient(x
, y
); }
595 // wxPoint interface to do the same thing
596 wxPoint
ClientToScreen(const wxPoint
& pt
) const
598 int x
= pt
.x
, y
= pt
.y
;
599 DoClientToScreen(&x
, &y
);
601 return wxPoint(x
, y
);
604 wxPoint
ScreenToClient(const wxPoint
& pt
) const
606 int x
= pt
.x
, y
= pt
.y
;
607 DoScreenToClient(&x
, &y
);
609 return wxPoint(x
, y
);
612 // test where the given (in client coords) point lies
613 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
614 { return DoHitTest(x
, y
); }
616 wxHitTest
HitTest(const wxPoint
& pt
) const
617 { return DoHitTest(pt
.x
, pt
.y
); }
622 // get the window border style: uses the current style and falls back to
623 // the default style for this class otherwise (see GetDefaultBorder())
624 wxBorder
GetBorder() const;
626 void UpdateWindowUI();
629 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
630 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
631 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
632 { return DoPopupMenu(menu
, x
, y
); }
633 #endif // wxUSE_MENUS
638 // does the window have the scrollbar for this orientation?
639 bool HasScrollbar(int orient
) const
641 return (m_windowStyle
&
642 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
645 // configure the window scrollbars
646 virtual void SetScrollbar( int orient
,
650 bool refresh
= TRUE
) = 0;
651 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
652 virtual int GetScrollPos( int orient
) const = 0;
653 virtual int GetScrollThumb( int orient
) const = 0;
654 virtual int GetScrollRange( int orient
) const = 0;
656 // scroll window to the specified position
657 virtual void ScrollWindow( int dx
, int dy
,
658 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
660 // context-sensitive help
661 // ----------------------
663 // these are the convenience functions wrapping wxHelpProvider methods
666 // associate this help text with this window
667 void SetHelpText(const wxString
& text
);
668 // associate this help text with all windows with the same id as this
670 void SetHelpTextForId(const wxString
& text
);
671 // get the help string associated with this window (may be empty)
672 wxString
GetHelpText() const;
679 // the easiest way to set a tooltip for a window is to use this method
680 void SetToolTip( const wxString
&tip
);
681 // attach a tooltip to the window
682 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
683 // get the associated tooltip or NULL if none
684 wxToolTip
* GetToolTip() const { return m_tooltip
; }
685 #endif // wxUSE_TOOLTIPS
689 #if wxUSE_DRAG_AND_DROP
690 // set/retrieve the drop target associated with this window (may be
691 // NULL; it's owned by the window and will be deleted by it)
692 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
693 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
694 #endif // wxUSE_DRAG_AND_DROP
696 // constraints and sizers
697 // ----------------------
698 #if wxUSE_CONSTRAINTS
699 // set the constraints for this window or retrieve them (may be NULL)
700 void SetConstraints( wxLayoutConstraints
*constraints
);
701 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
703 // when using constraints, it makes sense to update children positions
704 // automatically whenever the window is resized - this is done if
706 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
707 bool GetAutoLayout() const { return m_autoLayout
; }
709 // do layout the window and its children
710 virtual bool Layout();
712 // implementation only
713 void UnsetConstraints(wxLayoutConstraints
*c
);
714 wxWindowList
*GetConstraintsInvolvedIn() const
715 { return m_constraintsInvolvedIn
; }
716 void AddConstraintReference(wxWindowBase
*otherWin
);
717 void RemoveConstraintReference(wxWindowBase
*otherWin
);
718 void DeleteRelatedConstraints();
719 void ResetConstraints();
721 // these methods may be overriden for special layout algorithms
722 virtual void SetConstraintSizes(bool recurse
= TRUE
);
723 virtual bool LayoutPhase1(int *noChanges
);
724 virtual bool LayoutPhase2(int *noChanges
);
725 virtual bool DoPhase(int phase
);
727 // these methods are virtual but normally won't be overridden
728 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
729 virtual void MoveConstraint(int x
, int y
);
730 virtual void GetSizeConstraint(int *w
, int *h
) const ;
731 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
732 virtual void GetPositionConstraint(int *x
, int *y
) const ;
735 // TODO: what are they and how do they work??
736 void SetSizer( wxSizer
*sizer
);
737 wxSizer
*GetSizer() const { return m_windowSizer
; }
738 #endif // wxUSE_CONSTRAINTS
740 // backward compatibility
741 // ----------------------
742 #if WXWIN_COMPATIBILITY
743 bool Enabled() const { return IsEnabled(); }
745 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
746 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
747 wxFont
& GetLabelFont() { return GetFont(); };
748 wxFont
& GetButtonFont() { return GetFont(); };
749 #endif // WXWIN_COMPATIBILITY
755 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
756 void OnInitDialog( wxInitDialogEvent
&event
);
757 void OnMiddleClick( wxMouseEvent
& event
);
759 void OnHelp(wxHelpEvent
& event
);
762 // get the haqndle of the window for the underlying window system: this
763 // is only used for wxWin itself or for user code which wants to call
764 // platform-specific APIs
765 virtual WXWidget
GetHandle() const = 0;
768 // the window id - a number which uniquely identifies a window among
769 // its siblings unless it is -1
770 wxWindowID m_windowId
;
772 // the parent window of this window (or NULL) and the list of the children
775 wxWindowList m_children
;
777 // the minimal allowed size for the window (no minimal size if variable(s)
779 int m_minWidth
, m_minHeight
, m_maxWidth
, m_maxHeight
;
781 // event handler for this window: usually is just 'this' but may be
782 // changed with SetEventHandler()
783 wxEvtHandler
*m_eventHandler
;
786 // associated validator or NULL if none
787 wxValidator
*m_windowValidator
;
788 #endif // wxUSE_VALIDATORS
790 #if wxUSE_DRAG_AND_DROP
791 wxDropTarget
*m_dropTarget
;
792 #endif // wxUSE_DRAG_AND_DROP
794 // visual window attributes
797 wxColour m_backgroundColour
, m_foregroundColour
;
801 #endif // wxUSE_CARET
803 // the region which should be repainted in response to paint event
804 wxRegion m_updateRegion
;
807 // the accelerator table for the window which translates key strokes into
809 wxAcceleratorTable m_acceleratorTable
;
810 #endif // wxUSE_ACCEL
812 // user data associated with the window: either an object which will be
813 // deleted by the window when it's deleted or some raw pointer which we do
814 // nothing with - only one type of data can be used with the given window
815 // (i.e. you cannot set the void data and then associate the window with
816 // wxClientData or vice versa)
819 wxClientData
*m_clientObject
;
823 // the tooltip for this window (may be NULL)
825 wxToolTip
*m_tooltip
;
826 #endif // wxUSE_TOOLTIPS
828 // constraints and sizers
829 #if wxUSE_CONSTRAINTS
830 // the constraints for this window or NULL
831 wxLayoutConstraints
*m_constraints
;
833 // constraints this window is involved in
834 wxWindowList
*m_constraintsInvolvedIn
;
836 // top level and the parent sizers
837 // TODO what's this and how does it work?)
838 wxSizer
*m_windowSizer
;
839 wxWindowBase
*m_sizerParent
;
841 // Layout() window automatically when its size changes?
843 #endif // wxUSE_CONSTRAINTS
848 bool m_isBeingDeleted
:1;
853 wxString m_windowName
;
857 // common part of all ctors: it is not virtual because it is called from
861 // override this to change the default (i.e. used when no style is
862 // specified) border for the window class
863 virtual wxBorder
GetDefaultBorder() const;
865 // get the default size for the new window if no explicit size given
866 // FIXME why 20 and not 30, 10 or ...?
867 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
868 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
870 // set the best size for the control if the default size was given:
871 // replaces the fields of size == -1 with the best values for them and
872 // calls SetSize() if needed
873 void SetBestSize(const wxSize
& size
)
875 if ( size
.x
== -1 || size
.y
== -1 )
877 wxSize sizeBest
= DoGetBestSize();
887 // more pure virtual functions
888 // ---------------------------
890 // NB: we must have DoSomething() function when Something() is an overloaded
891 // method: indeed, we can't just have "virtual Something()" in case when
892 // the function is overloaded because then we'd have to make virtual all
893 // the variants (otherwise only the virtual function may be called on a
894 // pointer to derived class according to C++ rules) which is, in
895 // general, absolutely not needed. So instead we implement all
896 // overloaded Something()s in terms of DoSomething() which will be the
897 // only one to be virtual.
899 // coordinates translation
900 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
901 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
903 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
905 // retrieve the position/size of the window
906 virtual void DoGetPosition( int *x
, int *y
) const = 0;
907 virtual void DoGetSize( int *width
, int *height
) const = 0;
908 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
910 // get the size which best suits the window: for a control, it would be
911 // the minimal size which doesn't truncate the control, for a panel - the
912 // same size as it would have after a call to Fit()
913 virtual wxSize
DoGetBestSize() const;
915 // this is the virtual function to be overriden in any derived class which
916 // wants to change how SetSize() or Move() works - it is called by all
917 // versions of these functions in the base class
918 virtual void DoSetSize(int x
, int y
,
919 int width
, int height
,
920 int sizeFlags
= wxSIZE_AUTO
) = 0;
922 // same as DoSetSize() for the client size
923 virtual void DoSetClientSize(int width
, int height
) = 0;
925 // move the window to the specified location and resize it: this is called
926 // from both DoSetSize() and DoSetClientSize() and would usually just
927 // reposition this window except for composite controls which will want to
928 // arrange themselves inside the given rectangle
929 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
932 virtual void DoSetToolTip( wxToolTip
*tip
);
933 #endif // wxUSE_TOOLTIPS
936 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
937 #endif // wxUSE_MENUS
939 // client data accessors
940 virtual void DoSetClientObject( wxClientData
*data
);
941 virtual wxClientData
*DoGetClientObject() const;
943 virtual void DoSetClientData( void *data
);
944 virtual void *DoGetClientData() const;
946 // what kind of data do we have?
947 wxClientDataType m_clientDataType
;
950 // contains the last id generated by NewControlId
951 static int ms_lastControlId
;
953 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
954 DECLARE_NO_COPY_CLASS(wxWindowBase
)
955 DECLARE_EVENT_TABLE()
958 // ----------------------------------------------------------------------------
959 // now include the declaration of wxWindow class
960 // ----------------------------------------------------------------------------
962 // include the declaration of the platform-specific class
963 #if defined(__WXMSW__)
964 #ifdef __WXUNIVERSAL__
965 #define wxWindowNative wxWindowMSW
967 #define wxWindowMSW wxWindow
968 #define sm_classwxWindowMSW sm_classwxWindow
969 #endif // wxUniv/!wxUniv
970 #include "wx/msw/window.h"
971 #elif defined(__WXMOTIF__)
972 #include "wx/motif/window.h"
973 #elif defined(__WXGTK__)
974 #ifdef __WXUNIVERSAL__
975 #define wxWindowNative wxWindowGTK
977 #define wxWindowGTK wxWindow
978 #define sm_classwxWindowGTK sm_classwxWindow
980 #include "wx/gtk/window.h"
981 #elif defined(__WXQT__)
982 #include "wx/qt/window.h"
983 #elif defined(__WXMAC__)
984 #ifdef __WXUNIVERSAL__
985 #define wxWindowNative wxWindowMac
987 #define wxWindowMac wxWindow
988 #define sm_classwxWindowMac sm_classwxWindow
990 #include "wx/mac/window.h"
991 #elif defined(__WXPM__)
992 #ifdef __WXUNIVERSAL__
993 #define wxWindowNative wxWindowOS2
995 #define wxWindowOS2 wxWindow
996 #define sm_classwxWindowOS2 sm_classwxWindow
997 #endif // wxUniv/!wxUniv
998 #include "wx/os2/window.h"
1001 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1002 // for the native ports we already have defined it above
1003 #if defined(__WXUNIVERSAL__)
1004 #ifndef wxWindowNative
1005 #error "wxWindowNative must be defined above!"
1008 #include "wx/univ/window.h"
1011 // ----------------------------------------------------------------------------
1012 // inline functions which couldn't be declared in the class body because of
1013 // forward dependencies
1014 // ----------------------------------------------------------------------------
1016 inline wxWindow
*wxWindowBase::GetGrandParent() const
1018 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1021 // ----------------------------------------------------------------------------
1023 // ----------------------------------------------------------------------------
1025 // Find the wxWindow at the current mouse position, also returning the mouse
1027 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1029 // Get the current mouse position.
1030 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1032 // get the currently active window of this application or NULL
1033 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1035 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1036 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1039 // _WX_WINDOW_H_BASE_