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 // ----------------------------------------------------------------------------
40 // forward declarations
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxCaret
;
44 class WXDLLEXPORT wxClientData
;
45 class WXDLLEXPORT wxControl
;
46 class WXDLLEXPORT wxCursor
;
47 class WXDLLEXPORT wxDC
;
48 class WXDLLEXPORT wxDropTarget
;
49 class WXDLLEXPORT wxItemResource
;
50 class WXDLLEXPORT wxLayoutConstraints
;
51 class WXDLLEXPORT wxResourceTable
;
52 class WXDLLEXPORT wxSizer
;
53 class WXDLLEXPORT wxToolTip
;
54 class WXDLLEXPORT wxWindowBase
;
55 class WXDLLEXPORT wxWindow
;
57 // ----------------------------------------------------------------------------
58 // (pseudo)template list classes
59 // ----------------------------------------------------------------------------
61 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
, class WXDLLEXPORT
);
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
69 // ----------------------------------------------------------------------------
70 // helper classes used by [SG]etClientObject/Data
72 // TODO move into a separate header?
73 // ----------------------------------------------------------------------------
75 // what kind of client data do we have?
78 wxClientData_None
, // we don't know yet because we don't have it at all
79 wxClientData_Object
, // our client data is typed and we own it
80 wxClientData_Void
// client data is untyped and we don't own it
87 virtual ~wxClientData() { }
90 class wxStringClientData
: public wxClientData
93 wxStringClientData() { }
94 wxStringClientData( const wxString
&data
) : m_data(data
) { }
95 void SetData( const wxString
&data
) { m_data
= data
; }
96 const wxString
& GetData() const { return m_data
; }
102 // ----------------------------------------------------------------------------
103 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
104 // interface of this class.
106 // Event handler: windows have themselves as their event handlers by default,
107 // but their event handlers could be set to another object entirely. This
108 // separation can reduce the amount of derivation required, and allow
109 // alteration of a window's functionality (e.g. by a resource editor that
110 // temporarily switches event handlers).
111 // ----------------------------------------------------------------------------
113 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
116 // creating the window
117 // -------------------
120 wxWindowBase() { InitBase(); }
122 // pseudo ctor (can't be virtual, called from ctor)
123 bool CreateBase(wxWindowBase
*parent
,
125 const wxPoint
& pos
= wxDefaultPosition
,
126 const wxSize
& size
= wxDefaultSize
,
128 const wxValidator
& validator
= wxDefaultValidator
,
129 const wxString
& name
= wxPanelNameStr
);
131 virtual ~wxWindowBase();
133 #if wxUSE_WX_RESOURCES
134 // these functions are implemented in resource.cpp and resourc2.cpp
135 virtual bool LoadFromResource(wxWindow
*parent
,
136 const wxString
& resourceName
,
137 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
138 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
139 const wxItemResource
* parentResource
,
140 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
141 #endif // wxUSE_WX_RESOURCES
143 // deleting the window
144 // -------------------
146 // ask the window to close itself, return TRUE if the event handler
147 // honoured our request
148 bool Close( bool force
= FALSE
);
150 // the following functions delete the C++ objects (the window itself
151 // or its children) as well as the GUI windows and normally should
152 // never be used directly
154 // delete window unconditionally (dangerous!), returns TRUE if ok
155 virtual bool Destroy();
156 // delete all children of this window, returns TRUE if ok
157 bool DestroyChildren();
159 // is the window being deleted?
160 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
165 // the title (or label, see below) of the window: the text which the
167 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) { }
168 virtual wxString
GetTitle() const { return ""; }
170 // label is just the same as the title (but for, e.g., buttons it
171 // makes more sense to speak about labels)
172 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
173 virtual wxString
GetLabel() const { return GetTitle(); }
175 // the window name is used for ressource setting in X, it is not the
176 // same as the window title/label
177 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
178 virtual wxString
GetName() const { return m_windowName
; }
180 // window id uniquely identifies the window among its siblings unless
181 // it is -1 which means "don't care"
182 void SetId( wxWindowID id
) { m_windowId
= id
; }
183 wxWindowID
GetId() const { return m_windowId
; }
185 // generate a control id for the controls which were not given one by
187 static int NewControlId() { return --ms_lastControlId
; }
188 // get the id of the control following the one with the given
189 // (autogenerated) id
190 static int NextControlId(int id
) { return id
- 1; }
191 // get the id of the control preceding the one with the given
192 // (autogenerated) id
193 static int PrevControlId(int id
) { return id
+ 1; }
198 // set the window size and/or position
199 void SetSize( int x
, int y
, int width
, int height
,
200 int sizeFlags
= wxSIZE_AUTO
)
201 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
203 void SetSize( int width
, int height
)
204 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
206 void SetSize( const wxSize
& size
)
207 { SetSize( size
.x
, size
.y
); }
209 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
210 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
212 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
213 { DoSetSize(x
, y
, -1, -1, flags
); }
215 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
216 { Move(pt
.x
, pt
.y
, flags
); }
219 virtual void Raise() = 0;
220 virtual void Lower() = 0;
222 // client size is the size of area available for subwindows
223 void SetClientSize( int width
, int height
)
224 { DoSetClientSize(width
, height
); }
226 void SetClientSize( const wxSize
& size
)
227 { DoSetClientSize(size
.x
, size
.y
); }
229 void SetClientSize(const wxRect
& rect
)
230 { SetClientSize( rect
.width
, rect
.height
); }
232 // get the window position and/or size (pointers may be NULL)
233 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
234 wxPoint
GetPosition() const
237 DoGetPosition(&w
, &h
);
239 return wxPoint(w
, h
);
242 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
243 wxSize
GetSize() const
250 wxRect
GetRect() const
253 GetPosition(& x
, & y
);
256 return wxRect(x
, y
, w
, h
);
259 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
260 wxSize
GetClientSize() const
263 DoGetClientSize(& w
, & h
);
268 // get the origin of the client area of the window relative to the
269 // window top left corner (the client area may be shifted because of
270 // the borders, scrollbars, other decorations...)
271 virtual wxPoint
GetClientAreaOrigin() const;
273 // get the client rectangle in window (i.e. client) coordinates
274 wxRect
GetClientRect() const
276 return wxRect(GetClientAreaOrigin(), GetClientSize());
279 // get the size best suited for the window (in fact, minimal
280 // acceptable size using which it will still look "nice")
281 wxSize
GetBestSize() const { return DoGetBestSize(); }
282 void GetBestSize(int *w
, int *h
) const
284 wxSize s
= DoGetBestSize();
291 // the generic centre function - centers the window on parent by
292 // default or on screen if it doesn't have parent or
293 // wxCENTER_ON_SCREEN flag is given
294 void Centre( int direction
= wxBOTH
);
295 void Center( int direction
= wxBOTH
) { Centre(direction
); }
297 // centre on screen (only works for top level windows)
298 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
299 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
301 // centre with respect to the the parent window
302 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
303 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
305 // set window size to wrap around its children
308 // set min/max size of the window
309 virtual void SetSizeHints( int minW
, int minH
,
310 int maxW
= -1, int maxH
= -1,
311 int incW
= -1, int incH
= -1 );
313 int GetMinWidth() const { return m_minWidth
; }
314 int GetMinHeight() const { return m_minHeight
; }
315 int GetMaxWidth() const { return m_maxWidth
; }
316 int GetMaxHeight() const { return m_maxHeight
; }
321 // returns TRUE if window was shown/hidden, FALSE if the nothing was
322 // done (window was already shown/hidden)
323 virtual bool Show( bool show
= TRUE
);
324 bool Hide() { return Show(FALSE
); }
326 // returns TRUE if window was enabled/disabled, FALSE if nothing done
327 virtual bool Enable( bool enable
= TRUE
);
328 bool Disable() { return Enable(FALSE
); }
330 bool IsShown() const { return m_isShown
; }
331 bool IsEnabled() const { return m_isEnabled
; }
333 // get/set window style (setting style won't update the window and so
334 // is only useful for internal usage)
335 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
336 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
338 // just some (somewhat shorter) synonims
339 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
340 long GetWindowStyle() const { return GetWindowStyleFlag(); }
342 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
343 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
345 // extra style: the less often used style bits which can't be set with
346 // SetWindowStyleFlag()
347 void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
348 long GetExtraStyle() const { return m_exStyle
; }
350 // make the window modal (all other windows unresponsive)
351 virtual void MakeModal(bool modal
= TRUE
);
353 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
354 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
359 // set focus to this window
360 virtual void SetFocus() = 0;
362 // return the window which currently has the focus or NULL
363 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
365 // can this window have focus?
366 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
368 // can this window be given focus by keyboard navigation? if not, the
369 // only way to give it focus (provided it accepts it at all) is to
371 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
373 // parent/children relations
374 // -------------------------
376 // get the list of children
377 const wxWindowList
& GetChildren() const { return m_children
; }
378 wxWindowList
& GetChildren() { return m_children
; }
380 // get the parent or the parent of the parent
381 wxWindow
*GetParent() const { return m_parent
; }
382 inline wxWindow
*GetGrandParent() const;
384 // is this window a top level one?
385 virtual bool IsTopLevel() const;
387 // it doesn't really change parent, use ReParent() instead
388 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
389 // change the real parent of this window, return TRUE if the parent
390 // was changed, FALSE otherwise (error or newParent == oldParent)
391 virtual bool Reparent( wxWindowBase
*newParent
);
393 // find window among the descendants of this one either by id or by
394 // name (return NULL if not found)
395 wxWindow
*FindWindow( long id
);
396 wxWindow
*FindWindow( const wxString
& name
);
398 // implementation mostly
399 virtual void AddChild( wxWindowBase
*child
);
400 virtual void RemoveChild( wxWindowBase
*child
);
402 // event handler stuff
403 // -------------------
405 // get the current event handler
406 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
408 // replace the event handler (allows to completely subclass the
410 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
412 // push/pop event handler: allows to chain a custom event handler to
413 // alreasy existing ones
414 void PushEventHandler( wxEvtHandler
*handler
);
415 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
421 // a window may have an associated validator which is used to control
423 virtual void SetValidator( const wxValidator
&validator
);
424 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
425 #endif // wxUSE_VALIDATORS
430 // each window may have associated client data: either a pointer to
431 // wxClientData object in which case it is managed by the window (i.e.
432 // it will delete the data when it's destroyed) or an untyped pointer
433 // which won't be deleted by the window - but not both of them
434 void SetClientObject( wxClientData
*data
) { DoSetClientObject(data
); }
435 wxClientData
*GetClientObject() const { return DoGetClientObject(); }
437 void SetClientData( void *data
) { DoSetClientData(data
); }
438 void *GetClientData() const { return DoGetClientData(); }
440 // dialog oriented functions
441 // -------------------------
443 // validate the correctness of input, return TRUE if ok
444 virtual bool Validate();
446 // transfer data between internal and GUI representations
447 virtual bool TransferDataToWindow();
448 virtual bool TransferDataFromWindow();
450 virtual void InitDialog();
455 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
456 { m_acceleratorTable
= accel
; }
457 wxAcceleratorTable
*GetAcceleratorTable()
458 { return &m_acceleratorTable
; }
459 #endif // wxUSE_ACCEL
461 // dialog units translations
462 // -------------------------
464 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
465 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
466 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
468 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
470 return wxSize(pt
.x
, pt
.y
);
473 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
475 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
477 return wxSize(pt
.x
, pt
.y
);
483 // move the mouse to the specified position
484 virtual void WarpPointer(int x
, int y
) = 0;
486 // start or end mouse capture
487 virtual void CaptureMouse() = 0;
488 virtual void ReleaseMouse() = 0;
490 // get the window which currently captures the mouse or NULL
491 static wxWindow
*GetCapture();
493 // does this window have the capture?
494 virtual bool HasCapture() const
495 { return (wxWindow
*)this == GetCapture(); }
497 // painting the window
498 // -------------------
500 // mark the specified rectangle (or the whole window) as "dirty" so it
502 virtual void Refresh( bool eraseBackground
= TRUE
,
503 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
505 // a less awkward wrapper for Refresh
506 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
508 // repaint all invalid areas of the window immediately
509 virtual void Update() { }
511 // clear the window entirely
512 virtual void Clear() = 0;
514 // adjust DC for drawing on this window
515 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
517 // the update region of the window contains the areas which must be
518 // repainted by the program
519 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
520 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
522 // get the update rectangleregion bounding box in client coords
523 wxRect
GetUpdateClientRect() const;
525 // these functions verify whether the given point/rectangle belongs to
526 // (or at least intersects with) the update region
527 bool IsExposed( int x
, int y
) const;
528 bool IsExposed( int x
, int y
, int w
, int h
) const;
530 bool IsExposed( const wxPoint
& pt
) const
531 { return IsExposed(pt
.x
, pt
.y
); }
532 bool IsExposed( const wxRect
& rect
) const
533 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
535 // colours, fonts and cursors
536 // --------------------------
538 // set/retrieve the window colours (system defaults are used by
539 // default): Set functions return TRUE if colour was changed
540 virtual bool SetBackgroundColour( const wxColour
&colour
);
541 virtual bool SetForegroundColour( const wxColour
&colour
);
543 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
544 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
546 // set/retrieve the cursor for this window (SetCursor() returns TRUE
547 // if the cursor was really changed)
548 virtual bool SetCursor( const wxCursor
&cursor
);
549 const wxCursor
& GetCursor() const { return m_cursor
; }
550 wxCursor
& GetCursor() { return m_cursor
; }
552 // set/retrieve the font for the window (SetFont() returns TRUE if the
553 // font really changed)
554 virtual bool SetFont( const wxFont
&font
) = 0;
555 const wxFont
& GetFont() const { return m_font
; }
556 wxFont
& GetFont() { return m_font
; }
559 // associate a caret with the window
560 void SetCaret(wxCaret
*caret
);
561 // get the current caret (may be NULL)
562 wxCaret
*GetCaret() const { return m_caret
; }
563 #endif // wxUSE_CARET
565 // get the (average) character size for the current font
566 virtual int GetCharHeight() const = 0;
567 virtual int GetCharWidth() const = 0;
569 // get the width/height/... of the text using current or specified
571 virtual void GetTextExtent(const wxString
& string
,
573 int *descent
= (int *) NULL
,
574 int *externalLeading
= (int *) NULL
,
575 const wxFont
*theFont
= (const wxFont
*) NULL
)
578 // client <-> screen coords
579 // ------------------------
581 // translate to/from screen/client coordinates (pointers may be NULL)
582 void ClientToScreen( int *x
, int *y
) const
583 { DoClientToScreen(x
, y
); }
584 void ScreenToClient( int *x
, int *y
) const
585 { DoScreenToClient(x
, y
); }
587 // wxPoint interface to do the same thing
588 wxPoint
ClientToScreen(const wxPoint
& pt
) const
590 int x
= pt
.x
, y
= pt
.y
;
591 DoClientToScreen(&x
, &y
);
593 return wxPoint(x
, y
);
596 wxPoint
ScreenToClient(const wxPoint
& pt
) const
598 int x
= pt
.x
, y
= pt
.y
;
599 DoScreenToClient(&x
, &y
);
601 return wxPoint(x
, y
);
604 // test where the given (in client coords) point lies
605 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
606 { return DoHitTest(x
, y
); }
608 wxHitTest
HitTest(const wxPoint
& pt
) const
609 { return DoHitTest(pt
.x
, pt
.y
); }
614 // get the window border style: uses the current style and falls back to
615 // the default style for this class otherwise (see GetDefaultBorder())
616 wxBorder
GetBorder() const;
618 void UpdateWindowUI();
621 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
622 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
623 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
624 { return DoPopupMenu(menu
, x
, y
); }
625 #endif // wxUSE_MENUS
630 // does the window have the scrollbar for this orientation?
631 bool HasScrollbar(int orient
) const
633 return (m_windowStyle
&
634 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
637 // configure the window scrollbars
638 virtual void SetScrollbar( int orient
,
642 bool refresh
= TRUE
) = 0;
643 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
644 virtual int GetScrollPos( int orient
) const = 0;
645 virtual int GetScrollThumb( int orient
) const = 0;
646 virtual int GetScrollRange( int orient
) const = 0;
648 // scroll window to the specified position
649 virtual void ScrollWindow( int dx
, int dy
,
650 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
652 // context-sensitive help
653 // ----------------------
655 // these are the convenience functions wrapping wxHelpProvider methods
658 // associate this help text with this window
659 void SetHelpText(const wxString
& text
);
660 // associate this help text with all windows with the same id as this
662 void SetHelpTextForId(const wxString
& text
);
663 // get the help string associated with this window (may be empty)
664 wxString
GetHelpText() const;
671 // the easiest way to set a tooltip for a window is to use this method
672 void SetToolTip( const wxString
&tip
);
673 // attach a tooltip to the window
674 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
675 // get the associated tooltip or NULL if none
676 wxToolTip
* GetToolTip() const { return m_tooltip
; }
677 #endif // wxUSE_TOOLTIPS
681 #if wxUSE_DRAG_AND_DROP
682 // set/retrieve the drop target associated with this window (may be
683 // NULL; it's owned by the window and will be deleted by it)
684 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
685 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
686 #endif // wxUSE_DRAG_AND_DROP
688 // constraints and sizers
689 // ----------------------
690 #if wxUSE_CONSTRAINTS
691 // set the constraints for this window or retrieve them (may be NULL)
692 void SetConstraints( wxLayoutConstraints
*constraints
);
693 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
695 // when using constraints, it makes sense to update children positions
696 // automatically whenever the window is resized - this is done if
698 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
699 bool GetAutoLayout() const { return m_autoLayout
; }
701 // do layout the window and its children
702 virtual bool Layout();
704 // implementation only
705 void UnsetConstraints(wxLayoutConstraints
*c
);
706 wxWindowList
*GetConstraintsInvolvedIn() const
707 { return m_constraintsInvolvedIn
; }
708 void AddConstraintReference(wxWindowBase
*otherWin
);
709 void RemoveConstraintReference(wxWindowBase
*otherWin
);
710 void DeleteRelatedConstraints();
711 void ResetConstraints();
713 // these methods may be overriden for special layout algorithms
714 virtual void SetConstraintSizes(bool recurse
= TRUE
);
715 virtual bool LayoutPhase1(int *noChanges
);
716 virtual bool LayoutPhase2(int *noChanges
);
717 virtual bool DoPhase(int phase
);
719 // these methods are virtual but normally won't be overridden
720 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
721 virtual void MoveConstraint(int x
, int y
);
722 virtual void GetSizeConstraint(int *w
, int *h
) const ;
723 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
724 virtual void GetPositionConstraint(int *x
, int *y
) const ;
727 // TODO: what are they and how do they work??
728 void SetSizer( wxSizer
*sizer
);
729 wxSizer
*GetSizer() const { return m_windowSizer
; }
730 #endif // wxUSE_CONSTRAINTS
732 // backward compatibility
733 // ----------------------
734 #if WXWIN_COMPATIBILITY
735 bool Enabled() const { return IsEnabled(); }
737 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
738 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
739 wxFont
& GetLabelFont() { return GetFont(); };
740 wxFont
& GetButtonFont() { return GetFont(); };
741 #endif // WXWIN_COMPATIBILITY
747 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
748 void OnInitDialog( wxInitDialogEvent
&event
);
749 void OnMiddleClick( wxMouseEvent
& event
);
751 void OnHelp(wxHelpEvent
& event
);
754 // get the haqndle of the window for the underlying window system: this
755 // is only used for wxWin itself or for user code which wants to call
756 // platform-specific APIs
757 virtual WXWidget
GetHandle() const = 0;
760 // the window id - a number which uniquely identifies a window among
761 // its siblings unless it is -1
762 wxWindowID m_windowId
;
764 // the parent window of this window (or NULL) and the list of the children
767 wxWindowList m_children
;
769 // the minimal allowed size for the window (no minimal size if variable(s)
771 int m_minWidth
, m_minHeight
, m_maxWidth
, m_maxHeight
;
773 // event handler for this window: usually is just 'this' but may be
774 // changed with SetEventHandler()
775 wxEvtHandler
*m_eventHandler
;
778 // associated validator or NULL if none
779 wxValidator
*m_windowValidator
;
780 #endif // wxUSE_VALIDATORS
782 #if wxUSE_DRAG_AND_DROP
783 wxDropTarget
*m_dropTarget
;
784 #endif // wxUSE_DRAG_AND_DROP
786 // visual window attributes
789 wxColour m_backgroundColour
, m_foregroundColour
;
793 #endif // wxUSE_CARET
795 // the region which should be repainted in response to paint event
796 wxRegion m_updateRegion
;
799 // the accelerator table for the window which translates key strokes into
801 wxAcceleratorTable m_acceleratorTable
;
802 #endif // wxUSE_ACCEL
804 // user data associated with the window: either an object which will be
805 // deleted by the window when it's deleted or some raw pointer which we do
806 // nothing with - only one type of data can be used with the given window
807 // (i.e. you cannot set the void data and then associate the window with
808 // wxClientData or vice versa)
811 wxClientData
*m_clientObject
;
815 // the tooltip for this window (may be NULL)
817 wxToolTip
*m_tooltip
;
818 #endif // wxUSE_TOOLTIPS
820 // constraints and sizers
821 #if wxUSE_CONSTRAINTS
822 // the constraints for this window or NULL
823 wxLayoutConstraints
*m_constraints
;
825 // constraints this window is involved in
826 wxWindowList
*m_constraintsInvolvedIn
;
828 // top level and the parent sizers
829 // TODO what's this and how does it work?)
830 wxSizer
*m_windowSizer
;
831 wxWindowBase
*m_sizerParent
;
833 // Layout() window automatically when its size changes?
835 #endif // wxUSE_CONSTRAINTS
840 bool m_isBeingDeleted
:1;
845 wxString m_windowName
;
849 // common part of all ctors: it is not virtual because it is called from
853 // override this to change the default (i.e. used when no style is
854 // specified) border for the window class
855 virtual wxBorder
GetDefaultBorder() const;
857 // get the default size for the new window if no explicit size given
858 // FIXME why 20 and not 30, 10 or ...?
859 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
860 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
862 // set the best size for the control if the default size was given:
863 // replaces the fields of size == -1 with the best values for them and
864 // calls SetSize() if needed
865 void SetBestSize(const wxSize
& size
)
867 if ( size
.x
== -1 || size
.y
== -1 )
869 wxSize sizeBest
= DoGetBestSize();
879 // more pure virtual functions
880 // ---------------------------
882 // NB: we must have DoSomething() function when Something() is an overloaded
883 // method: indeed, we can't just have "virtual Something()" in case when
884 // the function is overloaded because then we'd have to make virtual all
885 // the variants (otherwise only the virtual function may be called on a
886 // pointer to derived class according to C++ rules) which is, in
887 // general, absolutely not needed. So instead we implement all
888 // overloaded Something()s in terms of DoSomething() which will be the
889 // only one to be virtual.
891 // coordinates translation
892 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
893 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
895 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
897 // retrieve the position/size of the window
898 virtual void DoGetPosition( int *x
, int *y
) const = 0;
899 virtual void DoGetSize( int *width
, int *height
) const = 0;
900 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
902 // get the size which best suits the window: for a control, it would be
903 // the minimal size which doesn't truncate the control, for a panel - the
904 // same size as it would have after a call to Fit()
905 virtual wxSize
DoGetBestSize() const;
907 // this is the virtual function to be overriden in any derived class which
908 // wants to change how SetSize() or Move() works - it is called by all
909 // versions of these functions in the base class
910 virtual void DoSetSize(int x
, int y
,
911 int width
, int height
,
912 int sizeFlags
= wxSIZE_AUTO
) = 0;
914 // same as DoSetSize() for the client size
915 virtual void DoSetClientSize(int width
, int height
) = 0;
917 // move the window to the specified location and resize it: this is called
918 // from both DoSetSize() and DoSetClientSize() and would usually just
919 // reposition this window except for composite controls which will want to
920 // arrange themselves inside the given rectangle
921 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
924 virtual void DoSetToolTip( wxToolTip
*tip
);
925 #endif // wxUSE_TOOLTIPS
928 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
929 #endif // wxUSE_MENUS
931 // client data accessors
932 virtual void DoSetClientObject( wxClientData
*data
);
933 virtual wxClientData
*DoGetClientObject() const;
935 virtual void DoSetClientData( void *data
);
936 virtual void *DoGetClientData() const;
938 // what kind of data do we have?
939 wxClientDataType m_clientDataType
;
942 // contains the last id generated by NewControlId
943 static int ms_lastControlId
;
945 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
946 DECLARE_NO_COPY_CLASS(wxWindowBase
)
947 DECLARE_EVENT_TABLE()
950 // ----------------------------------------------------------------------------
951 // now include the declaration of wxWindow class
952 // ----------------------------------------------------------------------------
954 // include the declaration of the platform-specific class
955 #if defined(__WXMSW__)
956 #if !defined(__WXUNIVERSAL__)
957 #define wxWindowMSW wxWindow
958 #define sm_classwxWindowMSW sm_classwxWindow
960 #include "wx/msw/window.h"
961 #elif defined(__WXMOTIF__)
962 #include "wx/motif/window.h"
963 #elif defined(__WXGTK__)
964 #if !defined(__WXUNIVERSAL__)
965 #define wxWindowGTK wxWindow
966 #define sm_classwxWindowGTK sm_classwxWindow
968 #include "wx/gtk/window.h"
969 #elif defined(__WXQT__)
970 #include "wx/qt/window.h"
971 #elif defined(__WXMAC__)
972 #include "wx/mac/window.h"
973 #elif defined(__WXPM__)
974 #include "wx/os2/window.h"
977 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
978 // for the native ports we already have defined it above
979 #if defined(__WXUNIVERSAL__)
980 #include "wx/univ/window.h"
983 // ----------------------------------------------------------------------------
984 // inline functions which couldn't be declared in the class body because of
985 // forward dependencies
986 // ----------------------------------------------------------------------------
988 inline wxWindow
*wxWindowBase::GetGrandParent() const
990 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
993 // ----------------------------------------------------------------------------
995 // ----------------------------------------------------------------------------
997 WXDLLEXPORT
extern wxWindow
* wxGetActiveWindow();
999 // Find the wxWindow at the current mouse position, also returning the mouse
1001 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1003 // Get the current mouse position.
1004 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1006 // get the currently active window of this application or NULL
1007 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1009 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1010 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1013 // _WX_WINDOW_H_BASE_