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"
34 #include "wx/validate.h" // defines wxDefaultValidator
35 #endif // wxUSE_VALIDATORS
41 // ----------------------------------------------------------------------------
42 // forward declarations
43 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxCaret
;
46 class WXDLLEXPORT wxClientData
;
47 class WXDLLEXPORT wxControl
;
48 class WXDLLEXPORT wxCursor
;
49 class WXDLLEXPORT wxDC
;
50 class WXDLLEXPORT wxDropTarget
;
51 class WXDLLEXPORT wxItemResource
;
52 class WXDLLEXPORT wxLayoutConstraints
;
53 class WXDLLEXPORT wxResourceTable
;
54 class WXDLLEXPORT wxSizer
;
55 class WXDLLEXPORT wxToolTip
;
56 class WXDLLEXPORT wxWindowBase
;
57 class WXDLLEXPORT wxWindow
;
59 // ----------------------------------------------------------------------------
60 // (pseudo)template list classes
61 // ----------------------------------------------------------------------------
63 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
);
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
71 // ----------------------------------------------------------------------------
72 // helper classes used by [SG]etClientObject/Data
74 // TODO move into a separate header?
75 // ----------------------------------------------------------------------------
81 virtual ~wxClientData() { }
84 class wxStringClientData
: public wxClientData
87 wxStringClientData() { }
88 wxStringClientData( const wxString
&data
) : m_data(data
) { }
89 void SetData( const wxString
&data
) { m_data
= data
; }
90 const wxString
& GetData() const { return m_data
; }
96 // ----------------------------------------------------------------------------
97 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
98 // interface of this class.
100 // Event handler: windows have themselves as their event handlers by default,
101 // but their event handlers could be set to another object entirely. This
102 // separation can reduce the amount of derivation required, and allow
103 // alteration of a window's functionality (e.g. by a resource editor that
104 // temporarily switches event handlers).
105 // ----------------------------------------------------------------------------
107 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
109 DECLARE_ABSTRACT_CLASS(wxWindowBase
);
112 // creating the window
113 // -------------------
116 wxWindowBase() { InitBase(); }
118 // pseudo ctor (can't be virtual, called from ctor)
119 bool CreateBase(wxWindowBase
*parent
,
121 const wxPoint
& pos
= wxDefaultPosition
,
122 const wxSize
& size
= wxDefaultSize
,
126 const wxValidator
& validator
= wxDefaultValidator
,
127 #endif // wxUSE_VALIDATORS
128 const wxString
& name
= wxPanelNameStr
);
130 virtual ~wxWindowBase();
132 #if wxUSE_WX_RESOURCES
133 // these functions are implemented in resource.cpp and resourc2.cpp
134 virtual bool LoadFromResource(wxWindow
*parent
,
135 const wxString
& resourceName
,
136 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
137 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
138 const wxItemResource
* parentResource
,
139 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
140 #endif // wxUSE_WX_RESOURCES
142 // deleting the window
143 // -------------------
145 // ask the window to close itself, return TRUE if the event handler
146 // honoured our request
147 bool Close( bool force
= FALSE
);
149 // the following functions delete the C++ objects (the window itself
150 // or its children) as well as the GUI windows and normally should
151 // never be used directly
153 // delete window unconditionally (dangerous!), returns TRUE if ok
154 virtual bool Destroy();
155 // delete all children of this window, returns TRUE if ok
156 bool DestroyChildren();
158 // is the window being deleted?
159 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
164 // the title (or label, see below) of the window: the text which the
166 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) { }
167 virtual wxString
GetTitle() const { return ""; }
169 // label is just the same as the title (but for, e.g., buttons it
170 // makes more sense to speak about labels)
171 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
172 virtual wxString
GetLabel() const { return GetTitle(); }
174 // the window name is used for ressource setting in X, it is not the
175 // same as the window title/label
176 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
177 virtual wxString
GetName() const { return m_windowName
; }
179 // window id uniquely identifies the window among its siblings unless
180 // it is -1 which means "don't care"
181 void SetId( wxWindowID id
) { m_windowId
= id
; }
182 wxWindowID
GetId() const { return m_windowId
; }
184 // generate a control id for the controls which were not given one by
186 static int NewControlId() { return --ms_lastControlId
; }
187 // get the id of the control following the one with the given
188 // (autogenerated) id
189 static int NextControlId(int id
) { return id
- 1; }
190 // get the id of the control preceding the one with the given
191 // (autogenerated) id
192 static int PrevControlId(int id
) { return id
+ 1; }
197 // set the window size and/or position
198 void SetSize( int x
, int y
, int width
, int height
,
199 int sizeFlags
= wxSIZE_AUTO
)
200 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
202 void SetSize( int width
, int height
)
203 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
205 void SetSize( const wxSize
& size
)
206 { SetSize( size
.x
, size
.y
); }
208 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
209 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
211 void Move( int x
, int y
)
212 { DoSetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
); }
214 void Move(const wxPoint
& pt
)
215 { Move(pt
.x
, pt
.y
); }
218 virtual void Raise() = 0;
219 virtual void Lower() = 0;
221 // client size is the size of area available for subwindows
222 void SetClientSize( int width
, int height
)
223 { DoSetClientSize(width
, height
); }
225 void SetClientSize( const wxSize
& size
)
226 { DoSetClientSize(size
.x
, size
.y
); }
228 void SetClientSize(const wxRect
& rect
)
229 { SetClientSize( rect
.width
, rect
.height
); }
231 // get the window position and/or size (pointers may be NULL)
232 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
233 wxPoint
GetPosition() const
236 DoGetPosition(&w
, &h
);
238 return wxPoint(w
, h
);
241 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
242 wxSize
GetSize() const
249 wxRect
GetRect() const
252 GetPosition(& x
, & y
);
255 return wxRect(x
, y
, w
, h
);
258 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
259 wxSize
GetClientSize() const
262 DoGetClientSize(& w
, & h
);
267 // get the size best suited for the window (in fact, minimal
268 // acceptable size using which it will still look "nice")
269 wxSize
GetBestSize() const { return DoGetBestSize(); }
270 void GetBestSize(int *w
, int *h
) const
272 wxSize s
= DoGetBestSize();
279 // centre with respect to the the parent window
280 void Centre( int direction
= wxBOTH
);
281 void Center( int direction
= wxBOTH
) { Centre(direction
); }
282 void CentreOnParent( int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
283 void CenterOnParent( int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
285 // set window size to wrap around its children
288 // set min/max size of the window
289 virtual void SetSizeHints( int minW
, int minH
,
290 int maxW
= -1, int maxH
= -1,
291 int incW
= -1, int incH
= -1 );
293 int GetMinWidth() const { return m_minWidth
; }
294 int GetMinHeight() const { return m_minHeight
; }
295 int GetMaxWidth() const { return m_maxWidth
; }
296 int GetMaxHeight() const { return m_maxHeight
; }
301 // returns TRUE if window was shown/hidden, FALSE if the nothing was
302 // done (window was already shown/hidden)
303 virtual bool Show( bool show
= TRUE
);
304 bool Hide() { return Show(FALSE
); }
306 // returns TRUE if window was enabled/disabled, FALSE if nothing done
307 virtual bool Enable( bool enable
= TRUE
);
308 bool Disable() { return Enable(FALSE
); }
310 bool IsShown() const { return m_isShown
; }
311 bool IsEnabled() const { return m_isEnabled
; }
313 // get/set window style (setting style won't update the window and so
314 // is only useful for internal usage)
315 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
316 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
318 // just some (somewhat shorter) synonims
319 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
320 long GetWindowStyle() const { return GetWindowStyleFlag(); }
322 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
324 virtual bool IsRetained() const
325 { return (m_windowStyle
& wxRETAINED
) != 0; }
327 // make the window modal (all other windows unresponsive)
328 virtual void MakeModal(bool modal
= TRUE
);
333 // set focus to this window
334 virtual void SetFocus() = 0;
336 // return the window which currently has the focus or NULL
337 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
339 // can this window have focus?
340 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
342 // parent/children relations
343 // -------------------------
345 // get the list of children
346 const wxWindowList
& GetChildren() const { return m_children
; }
347 wxWindowList
& GetChildren() { return m_children
; }
349 // get the parent or the parent of the parent
350 wxWindow
*GetParent() const { return m_parent
; }
351 inline wxWindow
*GetGrandParent() const;
353 // is this window a top level one?
354 virtual bool IsTopLevel() const;
356 // it doesn't really change parent, use ReParent() instead
357 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
358 // change the real parent of this window, return TRUE if the parent
359 // was changed, FALSE otherwise (error or newParent == oldParent)
360 virtual bool Reparent( wxWindowBase
*newParent
);
362 // find window among the descendants of this one either by id or by
363 // name (return NULL if not found)
364 wxWindow
*FindWindow( long id
);
365 wxWindow
*FindWindow( const wxString
& name
);
367 // implementation mostly
368 virtual void AddChild( wxWindowBase
*child
);
369 virtual void RemoveChild( wxWindowBase
*child
);
371 // event handler stuff
372 // -------------------
374 // get the current event handler
375 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
377 // replace the event handler (allows to completely subclass the
379 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
381 // push/pop event handler: allows to chain a custom event handler to
382 // alreasy existing ones
383 void PushEventHandler( wxEvtHandler
*handler
);
384 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
386 // validators and client data
387 // --------------------------
390 // a window may have an associated validator which is used to control
392 virtual void SetValidator( const wxValidator
&validator
);
393 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
394 #endif // wxUSE_VALIDATORS
396 // each window may have associated client data: either a pointer to
397 // wxClientData object in which case it is managed by the window (i.e.
398 // it will delete the data when it's destroyed) or an untyped pointer
399 // which won't be deleted by the window - but not both of them
400 void SetClientObject( wxClientData
*data
) { DoSetClientObject(data
); }
401 wxClientData
*GetClientObject() const { return DoGetClientObject(); }
403 void SetClientData( void *data
) { DoSetClientData(data
); }
404 void *GetClientData() const { return DoGetClientData(); }
406 // dialog oriented functions
407 // -------------------------
409 // validate the correctness of input, return TRUE if ok
410 virtual bool Validate();
412 // transfer data between internal and GUI representations
413 virtual bool TransferDataToWindow();
414 virtual bool TransferDataFromWindow();
416 virtual void InitDialog();
421 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
422 { m_acceleratorTable
= accel
; }
423 wxAcceleratorTable
*GetAcceleratorTable()
424 { return &m_acceleratorTable
; }
425 #endif // wxUSE_ACCEL
427 // dialog units translations
428 // -------------------------
430 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
431 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
432 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
434 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
436 return wxSize(pt
.x
, pt
.y
);
439 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
441 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
443 return wxSize(pt
.x
, pt
.y
);
449 // move the mouse to the specified position
450 virtual void WarpPointer(int x
, int y
) = 0;
452 // start or end mouse capture
453 virtual void CaptureMouse() = 0;
454 virtual void ReleaseMouse() = 0;
456 // painting the window
457 // -------------------
459 // mark the specified rectangle (or the whole window) as "dirty" so it
461 virtual void Refresh( bool eraseBackground
= TRUE
,
462 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
463 // clear the window entirely
464 virtual void Clear() = 0;
466 // adjust DC for drawing on this window
467 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
469 // the update region of the window contains the areas which must be
470 // repainted by the program
471 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
472 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
474 // these functions verify whether the given point/rectangle belongs to
475 // (or at least intersects with) the update region
476 bool IsExposed( int x
, int y
) const;
477 bool IsExposed( int x
, int y
, int w
, int h
) const;
479 bool IsExposed( const wxPoint
& pt
) const
480 { return IsExposed(pt
.x
, pt
.y
); }
481 bool IsExposed( const wxRect
& rect
) const
482 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
484 // colours, fonts and cursors
485 // --------------------------
487 // set/retrieve the window colours (system defaults are used by
488 // default): Set functions return TRUE if colour was changed
489 virtual bool SetBackgroundColour( const wxColour
&colour
);
490 virtual bool SetForegroundColour( const wxColour
&colour
);
492 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
493 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
495 // set/retrieve the cursor for this window (SetCursor() returns TRUE
496 // if the cursor was really changed)
497 virtual bool SetCursor( const wxCursor
&cursor
);
498 const wxCursor
& GetCursor() const { return m_cursor
; }
499 wxCursor
& GetCursor() { return m_cursor
; }
501 // set/retrieve the font for the window (SetFont() returns TRUE if the
502 // font really changed)
503 virtual bool SetFont( const wxFont
&font
) = 0;
504 const wxFont
& GetFont() const { return m_font
; }
505 wxFont
& GetFont() { return m_font
; }
508 // associate a caret with the window
509 void SetCaret(wxCaret
*caret
);
510 // get the current caret (may be NULL)
511 wxCaret
*GetCaret() const { return m_caret
; }
512 #endif // wxUSE_CARET
514 // get the (average) character size for the current font
515 virtual int GetCharHeight() const = 0;
516 virtual int GetCharWidth() const = 0;
518 // get the width/height/... of the text using current or specified
520 virtual void GetTextExtent(const wxString
& string
,
522 int *descent
= (int *) NULL
,
523 int *externalLeading
= (int *) NULL
,
524 const wxFont
*theFont
= (const wxFont
*) NULL
)
527 // translate to/from screen/client coordinates (pointers may be NULL)
528 void ClientToScreen( int *x
, int *y
) const
529 { DoClientToScreen(x
, y
); }
530 void ScreenToClient( int *x
, int *y
) const
531 { DoScreenToClient(x
, y
); }
532 wxPoint
ClientToScreen(const wxPoint
& pt
) const
534 int x
= pt
.x
, y
= pt
.y
;
535 DoClientToScreen(&x
, &y
);
537 return wxPoint(x
, y
);
540 wxPoint
ScreenToClient(const wxPoint
& pt
) const
542 int x
= pt
.x
, y
= pt
.y
;
543 DoScreenToClient(&x
, &y
);
545 return wxPoint(x
, y
);
551 void UpdateWindowUI();
553 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
554 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
555 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
556 { return DoPopupMenu(menu
, x
, y
); }
561 // configure the window scrollbars
562 virtual void SetScrollbar( int orient
,
566 bool refresh
= TRUE
) = 0;
567 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
568 virtual int GetScrollPos( int orient
) const = 0;
569 virtual int GetScrollThumb( int orient
) const = 0;
570 virtual int GetScrollRange( int orient
) const = 0;
572 // scroll window to the specified position
573 virtual void ScrollWindow( int dx
, int dy
,
574 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
579 // the easiest way to set a tooltip for a window is to use this method
580 void SetToolTip( const wxString
&tip
);
581 // attach a tooltip to the window
582 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
583 // get the associated tooltip or NULL if none
584 wxToolTip
* GetToolTip() const { return m_tooltip
; }
585 #endif // wxUSE_TOOLTIPS
589 #if wxUSE_DRAG_AND_DROP
590 // set/retrieve the drop target associated with this window (may be
591 // NULL; it's owned by the window and will be deleted by it)
592 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
593 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
594 #endif // wxUSE_DRAG_AND_DROP
596 // constraints and sizers
597 // ----------------------
598 #if wxUSE_CONSTRAINTS
599 // set the constraints for this window or retrieve them (may be NULL)
600 void SetConstraints( wxLayoutConstraints
*constraints
);
601 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
603 // when using constraints, it makes sense to update children positions
604 // automatically whenever the window is resized - this is done if
606 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
607 bool GetAutoLayout() const { return m_autoLayout
; }
609 // do layout the window and its children
610 virtual bool Layout();
612 // implementation only
613 void UnsetConstraints(wxLayoutConstraints
*c
);
614 wxWindowList
*GetConstraintsInvolvedIn() const
615 { return m_constraintsInvolvedIn
; }
616 void AddConstraintReference(wxWindowBase
*otherWin
);
617 void RemoveConstraintReference(wxWindowBase
*otherWin
);
618 void DeleteRelatedConstraints();
619 void ResetConstraints();
621 // these methods may be overriden for special layout algorithms
622 virtual void SetConstraintSizes(bool recurse
= TRUE
);
623 virtual bool LayoutPhase1(int *noChanges
);
624 virtual bool LayoutPhase2(int *noChanges
);
625 virtual bool DoPhase(int);
627 // these methods are virtual but normally won't be overridden
628 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
629 virtual void MoveConstraint(int x
, int y
);
630 virtual void GetSizeConstraint(int *w
, int *h
) const ;
631 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
632 virtual void GetPositionConstraint(int *x
, int *y
) const ;
635 // TODO: what are they and how do they work??
636 void SetSizer( wxSizer
*sizer
);
637 wxSizer
*GetSizer() const { return m_windowSizer
; }
638 #endif // wxUSE_CONSTRAINTS
640 // backward compatibility
641 // ----------------------
642 #if WXWIN_COMPATIBILITY
643 bool Enabled() const { return IsEnabled(); }
645 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
646 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
647 wxFont
& GetLabelFont() { return GetFont(); };
648 wxFont
& GetButtonFont() { return GetFont(); };
649 #endif // WXWIN_COMPATIBILITY
655 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
656 void OnInitDialog( wxInitDialogEvent
&event
);
658 // get the haqndle of the window for the underlying window system: this
659 // is only used for wxWin itself or for user code which wants to call
660 // platform-specific APIs
661 virtual WXWidget
GetHandle() const = 0;
664 // the window id - a number which uniquely identifies a window among
665 // its siblings unless it is -1
666 wxWindowID m_windowId
;
668 // the parent window of this window (or NULL) and the list of the children
671 wxWindowList m_children
;
673 // the minimal allowed size for the window (no minimal size if variable(s)
675 int m_minWidth
, m_minHeight
, m_maxWidth
, m_maxHeight
;
677 // event handler for this window: usually is just 'this' but may be
678 // changed with SetEventHandler()
679 wxEvtHandler
*m_eventHandler
;
682 // associated validator or NULL if none
683 wxValidator
*m_windowValidator
;
684 #endif // wxUSE_VALIDATORS
686 #if wxUSE_DRAG_AND_DROP
687 wxDropTarget
*m_dropTarget
;
688 #endif // wxUSE_DRAG_AND_DROP
690 // visual window attributes
693 wxColour m_backgroundColour
, m_foregroundColour
;
697 #endif // wxUSE_CARET
699 // the region which should be repainted in response to paint event
700 wxRegion m_updateRegion
;
703 // the accelerator table for the window which translates key strokes into
705 wxAcceleratorTable m_acceleratorTable
;
706 #endif // wxUSE_ACCEL
708 // user data associated with the window: either an object which will be
709 // deleted by the window when it's deleted or some raw pointer which we do
710 // nothing with - only one type of data can be used with the given window
711 // (i.e. you cannot set the void data and then associate the window with
712 // wxClientData or vice versa)
715 wxClientData
*m_clientObject
;
719 // the tooltip for this window (may be NULL)
721 wxToolTip
*m_tooltip
;
722 #endif // wxUSE_TOOLTIPS
724 // constraints and sizers
725 #if wxUSE_CONSTRAINTS
726 // the constraints for this window or NULL
727 wxLayoutConstraints
*m_constraints
;
729 // constraints this window is involved in
730 wxWindowList
*m_constraintsInvolvedIn
;
732 // top level and the parent sizers
733 // TODO what's this and how does it work?)
734 wxSizer
*m_windowSizer
;
735 wxWindowBase
*m_sizerParent
;
737 // Layout() window automatically when its size changes?
739 #endif // wxUSE_CONSTRAINTS
744 bool m_isBeingDeleted
:1;
748 wxString m_windowName
;
751 // common part of all ctors: it is not virtual because it is called from
755 // get the default size for the new window if no explicit size given
756 // FIXME why 20 and not 30, 10 or ...?
757 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
758 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
760 // sets the size to be size but take width and/or height from
761 // DoGetBestSize() if width/height of size is -1
763 // NB: when calling this function from the ctor, the DoGetBestSize() of
764 // the class with the same name as the ctor, not the real (most
765 // derived) one - but this is what we usually want
766 void SetSizeOrDefault(const wxSize
& size
= wxDefaultSize
)
768 if ( size
.x
== -1 || size
.y
== -1 )
770 wxSize sizeDef
= GetBestSize();
771 SetSize( size
.x
== -1 ? sizeDef
.x
: size
.x
,
772 size
.y
== -1 ? sizeDef
.y
: size
.y
);
780 // more pure virtual functions
781 // ---------------------------
783 // NB: we must have DoSomething() function when Something() is an overloaded
784 // method: indeed, we can't just have "virtual Something()" in case when
785 // the function is overloaded because then we'd have to make virtual all
786 // the variants (otherwise only the virtual function may be called on a
787 // pointer to derived class according to C++ rules) which is, in
788 // general, absolutely not needed. So instead we implement all
789 // overloaded Something()s in terms of DoSomething() which will be the
790 // only one to be virtual.
792 // coordinates translation
793 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
794 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
796 // retrieve the position/size of the window
797 virtual void DoGetPosition( int *x
, int *y
) const = 0;
798 virtual void DoGetSize( int *width
, int *height
) const = 0;
799 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
801 // get the size which best suits the window: for a control, it would be
802 // the minimal size which doesn't truncate the control, for a panel - the
803 // same size as it would have after a call to Fit()
804 virtual wxSize
DoGetBestSize() const;
806 // this is the virtual function to be overriden in any derived class which
807 // wants to change how SetSize() or Move() works - it is called by all
808 // versions of these functions in the base class
809 virtual void DoSetSize(int x
, int y
,
810 int width
, int height
,
811 int sizeFlags
= wxSIZE_AUTO
) = 0;
813 // same as DoSetSize() for the client size
814 virtual void DoSetClientSize(int width
, int height
) = 0;
817 virtual void DoSetToolTip( wxToolTip
*tip
);
818 #endif // wxUSE_TOOLTIPS
820 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
822 // client data accessors
823 virtual void DoSetClientObject( wxClientData
*data
);
824 virtual wxClientData
*DoGetClientObject() const;
826 virtual void DoSetClientData( void *data
);
827 virtual void *DoGetClientData() const;
829 // what kind of data do we have?
830 enum wxClientDataType
832 ClientData_None
, // we don't know yet because we don't have it at all
833 ClientData_Object
, // our client data is typed and we own it
834 ClientData_Void
// client data is untyped and we don't own it
838 // contains the last id generated by NewControlId
839 static int ms_lastControlId
;
841 DECLARE_NO_COPY_CLASS(wxWindowBase
);
842 DECLARE_EVENT_TABLE()
845 // ----------------------------------------------------------------------------
846 // now include the declaration of wxWindow class
847 // ----------------------------------------------------------------------------
849 #if defined(__WXMSW__)
850 #include "wx/msw/window.h"
851 #elif defined(__WXMOTIF__)
852 #include "wx/motif/window.h"
853 #elif defined(__WXGTK__)
854 #include "wx/gtk/window.h"
855 #elif defined(__WXQT__)
856 #include "wx/qt/window.h"
857 #elif defined(__WXMAC__)
858 #include "wx/mac/window.h"
859 #elif defined(__WXPM__)
860 #include "wx/os2/window.h"
863 // ----------------------------------------------------------------------------
864 // inline functions which couldn't be declared in the class body because of
865 // forward dependencies
866 // ----------------------------------------------------------------------------
868 inline wxWindow
*wxWindowBase::GetGrandParent() const
870 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
873 // ----------------------------------------------------------------------------
875 // ----------------------------------------------------------------------------
877 WXDLLEXPORT
extern wxWindow
* wxGetActiveWindow();
879 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
880 inline WXDLLEXPORT
int NewControlId() { return wxWindowBase::NewControlId(); }
883 // _WX_WINDOW_H_BASE_