]> git.saurik.com Git - wxWidgets.git/blob - include/wx/window.h
1. wxMSW seems to work (please test and send your bug reports!)
[wxWidgets.git] / include / wx / window.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindowBase class - the interface of wxWindowBase
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
14
15 #ifdef __GNUG__
16 #pragma interface "windowbase.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // headers which we must include here
21 // ----------------------------------------------------------------------------
22
23 #include "wx/event.h" // the base class
24
25 #include "wx/list.h" // defines wxWindowList
26
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"
31 #include "wx/accel.h"
32
33 // ----------------------------------------------------------------------------
34 // forward declarations
35 // ----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxClientData;
38 class WXDLLEXPORT wxControl;
39 class WXDLLEXPORT wxCursor;
40 class WXDLLEXPORT wxDC;
41 class WXDLLEXPORT wxDropTarget;
42 class WXDLLEXPORT wxItemResource;
43 class WXDLLEXPORT wxLayoutConstraints;
44 class WXDLLEXPORT wxResourceTable;
45 class WXDLLEXPORT wxSizer;
46 class WXDLLEXPORT wxToolTip;
47 class WXDLLEXPORT wxValidator;
48 class WXDLLEXPORT wxWindowBase;
49 class WXDLLEXPORT wxWindow;
50
51 // ----------------------------------------------------------------------------
52 // (pseudo)template list classes
53 // ----------------------------------------------------------------------------
54
55 WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode);
56
57 // ----------------------------------------------------------------------------
58 // global variables
59 // ----------------------------------------------------------------------------
60
61 WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
62
63 // ----------------------------------------------------------------------------
64 // helper classes used by [SG]etClientObject/Data
65 //
66 // TODO move into a separate header?
67 // ----------------------------------------------------------------------------
68
69 class wxClientData
70 {
71 public:
72 wxClientData() { }
73 virtual ~wxClientData() { }
74 };
75
76 class wxStringClientData : public wxClientData
77 {
78 public:
79 wxStringClientData() { }
80 wxStringClientData( const wxString &data ) : m_data(data) { }
81 void SetData( const wxString &data ) { m_data = data; }
82 const wxString& GetData() const { return m_data; }
83
84 private:
85 wxString m_data;
86 };
87
88 // ----------------------------------------------------------------------------
89 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
90 // interface of this class.
91 //
92 // Event handler: windows have themselves as their event handlers by default,
93 // but their event handlers could be set to another object entirely. This
94 // separation can reduce the amount of derivation required, and allow
95 // alteration of a window's functionality (e.g. by a resource editor that
96 // temporarily switches event handlers).
97 // ----------------------------------------------------------------------------
98
99 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
100 {
101 DECLARE_ABSTRACT_CLASS(wxWindowBase);
102
103 public:
104 // creating the window
105 // -------------------
106
107 // default ctor
108 wxWindowBase() { InitBase(); }
109
110 // pseudo ctor (can't be virtual, called from ctor)
111 bool CreateBase(wxWindowBase *parent,
112 wxWindowID id,
113 const wxPoint& pos = wxDefaultPosition,
114 const wxSize& size = wxDefaultSize,
115 long style = 0,
116 const wxString& name = wxPanelNameStr);
117
118 virtual ~wxWindowBase();
119
120 #if wxUSE_WX_RESOURCES
121 // these functions are implemented in resource.cpp and resourc2.cpp
122 virtual bool LoadFromResource(wxWindow *parent,
123 const wxString& resourceName,
124 const wxResourceTable *table = (const wxResourceTable *) NULL);
125 virtual wxControl *CreateItem(const wxItemResource* childResource,
126 const wxItemResource* parentResource,
127 const wxResourceTable *table = (const wxResourceTable *) NULL);
128 #endif // wxUSE_WX_RESOURCES
129
130 // deleting the window
131 // -------------------
132
133 // ask the window to close itself, return TRUE if the event handler
134 // honoured our request
135 bool Close( bool force = FALSE );
136
137 // the following functions delete the C++ objects (the window itself
138 // or its children) as well as the GUI windows and normally should
139 // never be used directly
140
141 // delete window unconditionally (dangerous!), returns TRUE if ok
142 virtual bool Destroy();
143 // delete all children of this window, returns TRUE if ok
144 bool DestroyChildren();
145
146 // is the window being deleted?
147 bool IsBeingDeleted() const { return m_isBeingDeleted; }
148
149 // window attributes
150 // -----------------
151
152 // the title (or label, see below) of the window: the text which the
153 // window shows
154 virtual void SetTitle( const wxString & WXUNUSED(title) ) { }
155 virtual wxString GetTitle() const { return ""; }
156
157 // label is just the same as the title (but for, e.g., buttons it
158 // makes more sense to speak about labels)
159 void SetLabel(const wxString& label) { SetTitle(label); }
160 wxString GetLabel() const { return GetTitle(); }
161
162 // the window name is used for ressource setting in X, it is not the
163 // same as the window title/label
164 virtual void SetName( const wxString &name ) { m_windowName = name; }
165 virtual wxString GetName() const { return m_windowName; }
166
167 // window id uniquely identifies the window among its siblings unless
168 // it is -1 which means "don't care"
169 void SetId( wxWindowID id ) { m_windowId = id; }
170 wxWindowID GetId() const { return m_windowId; }
171
172 // generate a control id for the controls which were not given one by
173 // user
174 static int NewControlId() { return --ms_lastControlId; }
175 // get the id of the control following the one with the given
176 // (autogenerated) id
177 static int NextControlId(int id) { return id - 1; }
178 // get the id of the control preceding the one with the given
179 // (autogenerated) id
180 static int PrevControlId(int id) { return id + 1; }
181
182 // moving/resizing
183 // ---------------
184
185 // set the window size and/or position
186 void SetSize( int x, int y, int width, int height,
187 int sizeFlags = wxSIZE_AUTO )
188 { DoSetSize(x, y, width, height, sizeFlags); }
189
190 void SetSize( int width, int height )
191 { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); }
192
193 void SetSize( const wxSize& size )
194 { SetSize( size.x, size.y); }
195
196 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
197 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
198
199 void Move( int x, int y )
200 { DoSetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); }
201
202 void Move(const wxPoint& pt)
203 { Move(pt.x, pt.y); }
204
205 // Z-order
206 virtual void Raise() = 0;
207 virtual void Lower() = 0;
208
209 // client size is the size of area available for subwindows
210 void SetClientSize( int width, int height )
211 { DoSetClientSize(width, height); }
212
213 void SetClientSize( const wxSize& size )
214 { DoSetClientSize(size.x, size.y); }
215
216 void SetClientSize(const wxRect& rect)
217 { SetClientSize( rect.width, rect.height ); }
218
219 // get the window position and/or size (pointers may be NULL)
220 void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); }
221 wxPoint GetPosition() const
222 {
223 int w, h;
224 DoGetPosition(&w, &h);
225
226 return wxPoint(w, h);
227 }
228
229 void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
230 wxSize GetSize() const
231 {
232 int w, h;
233 DoGetSize(& w, & h);
234 return wxSize(w, h);
235 }
236
237 wxRect GetRect() const
238 {
239 int x, y, w, h;
240 GetPosition(& x, & y);
241 GetSize(& w, & h);
242
243 return wxRect(x, y, w, h);
244 }
245
246 void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
247 wxSize GetClientSize() const
248 {
249 int w, h;
250 DoGetClientSize(& w, & h);
251
252 return wxSize(w, h);
253 }
254
255 // centre with respect to the the parent window
256 void Centre( int direction = wxHORIZONTAL );
257 void Center( int direction = wxHORIZONTAL ) { Centre(direction); }
258
259 // set window size to wrap around its children
260 virtual void Fit();
261
262 // set min/max size of the window
263 virtual void SetSizeHints( int minW, int minH,
264 int maxW = -1, int maxH = -1,
265 int incW = -1, int incH = -1 );
266
267 // window state
268 // ------------
269
270 // returns TRUE if window was shown/hidden, FALSE if the nothing was
271 // done (window was already shown/hidden)
272 virtual bool Show( bool show = TRUE );
273 bool Hide() { return Show(FALSE); }
274
275 // returns TRUE if window was enabled/disabled, FALSE if nothing done
276 virtual bool Enable( bool enable = TRUE );
277 bool Disable() { return Enable(FALSE); }
278
279 bool IsShown() const { return m_isShown; }
280 bool IsEnabled() const { return m_isEnabled; }
281
282 // get/set window style (setting style won't update the window and so
283 // is only useful for internal usage)
284 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
285 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
286
287 // just some (somewhat shorter) synonims
288 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
289 long GetWindowStyle() const { return GetWindowStyleFlag(); }
290
291 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
292
293 virtual bool IsRetained() const
294 { return (m_windowStyle & wxRETAINED) != 0; }
295
296 // make the window modal (all other windows unresponsive)
297 virtual void MakeModal(bool modal = TRUE);
298
299 // focus handling
300 // --------------
301
302 // set focus to this window
303 virtual void SetFocus() = 0;
304
305 // return the window which currently has the focus or NULL
306 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
307
308 // can this window have focus?
309 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
310
311 // parent/children relations
312 // -------------------------
313
314 // get the list of children
315 const wxWindowList& GetChildren() const { return m_children; }
316 wxWindowList& GetChildren() { return m_children; }
317
318 // get the parent or the parent of the parent
319 wxWindow *GetParent() const { return m_parent; }
320 inline wxWindow *GetGrandParent() const;
321
322 // is this window a top level one?
323 bool IsTopLevel() const { return m_parent != 0; }
324
325 // it doesn't really change parent, use ReParent() instead
326 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
327 // change the real parent of this window, return TRUE if the parent
328 // was changed, FALSE otherwise (error or newParent == oldParent)
329 virtual bool Reparent( wxWindowBase *newParent );
330
331 // find window among the descendants of this one either by id or by
332 // name (return NULL if not found)
333 wxWindow *FindWindow( long id );
334 wxWindow *FindWindow( const wxString& name );
335
336 // implementation mostly
337 virtual void AddChild( wxWindowBase *child );
338 virtual void RemoveChild( wxWindowBase *child );
339
340 // event handler stuff
341 // -------------------
342
343 // get the current event handler
344 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
345
346 // replace the event handler (allows to completely subclass the
347 // window)
348 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
349
350 // push/pop event handler: allows to chain a custom event handler to
351 // alreasy existing ones
352 void PushEventHandler( wxEvtHandler *handler );
353 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
354
355 // validators and client data
356 // --------------------------
357
358 // a window may have an associated validator which is used to control
359 // user input
360 virtual void SetValidator( const wxValidator &validator );
361 virtual wxValidator *GetValidator() { return m_windowValidator; }
362
363 // each window may have associated client data: either a pointer to
364 // wxClientData object in which case it is managed by the window (i.e.
365 // it will delete the data when it's destroyed) or an untyped pointer
366 // which won't be deleted by the window
367 virtual void SetClientObject( wxClientData *data )
368 {
369 if ( m_clientObject )
370 delete m_clientObject;
371
372 m_clientObject = data;
373 }
374 virtual wxClientData *GetClientObject() const { return m_clientObject; }
375
376 virtual void SetClientData( void *data ) { m_clientData = data; }
377 virtual void *GetClientData() const { return m_clientData; }
378
379 // dialog oriented functions
380 // -------------------------
381
382 // validate the correctness of input, return TRUE if ok
383 virtual bool Validate();
384
385 // transfer data between internal and GUI representations
386 virtual bool TransferDataToWindow();
387 virtual bool TransferDataFromWindow();
388
389 virtual void InitDialog();
390
391 // accelerators
392 // ------------
393 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
394 { m_acceleratorTable = accel; }
395 wxAcceleratorTable *GetAcceleratorTable()
396 { return &m_acceleratorTable; }
397
398 // dialog units translations
399 // -------------------------
400
401 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
402 wxPoint ConvertDialogToPixels( const wxPoint& pt );
403 wxSize ConvertPixelsToDialog( const wxSize& sz )
404 {
405 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
406
407 return wxSize(pt.x, pt.y);
408 }
409
410 wxSize ConvertDialogToPixels( const wxSize& sz )
411 {
412 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
413
414 return wxSize(pt.x, pt.y);
415 }
416
417 // mouse functions
418 // ---------------
419
420 // move the mouse to the specified position
421 virtual void WarpPointer(int x, int y) = 0;
422
423 // start or end mouse capture
424 virtual void CaptureMouse() = 0;
425 virtual void ReleaseMouse() = 0;
426
427 // painting the window
428 // -------------------
429
430 // mark the specified rectangle (or the whole window) as "dirty" so it
431 // will be repainted
432 virtual void Refresh( bool eraseBackground = TRUE,
433 const wxRect *rect = (const wxRect *) NULL ) = 0;
434 // clear the window entirely
435 virtual void Clear() = 0;
436
437 // adjust DC for drawing on this window
438 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
439
440 // the update region of the window contains the areas which must be
441 // repainted by the program
442 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
443 wxRegion& GetUpdateRegion() { return m_updateRegion; }
444
445 // these functions verify whether the given point/rectangle belongs to
446 // (or at least intersects with) the update region
447 bool IsExposed( int x, int y ) const;
448 bool IsExposed( int x, int y, int w, int h ) const;
449
450 bool IsExposed( const wxPoint& pt ) const
451 { return IsExposed(pt.x, pt.y); }
452 bool IsExposed( const wxRect& rect ) const
453 { return IsExposed(rect.x, rect.y, rect.width, rect.height); }
454
455 // colours, fonts and cursors
456 // --------------------------
457
458 // set/retrieve the window colours (system defaults are used by
459 // default): Set functions return TRUE if colour was changed
460 virtual bool SetBackgroundColour( const wxColour &colour );
461 virtual bool SetForegroundColour( const wxColour &colour );
462
463 wxColour GetBackgroundColour() const { return m_backgroundColour; }
464 wxColour GetForegroundColour() const { return m_foregroundColour; }
465
466 // set/retrieve the cursor for this window (SetCursor() returns TRUE
467 // if the cursor was really changed)
468 virtual bool SetCursor( const wxCursor &cursor );
469 const wxCursor& GetCursor() const { return m_cursor; }
470 wxCursor& GetCursor() { return m_cursor; }
471
472 // set/retrieve the font for the window (SetFont() returns TRUE if the
473 // font really changed)
474 virtual bool SetFont( const wxFont &font ) = 0;
475 const wxFont& GetFont() const { return m_font; }
476 wxFont& GetFont() { return m_font; }
477
478 // get the (average) character size for the current font
479 virtual int GetCharHeight() const = 0;
480 virtual int GetCharWidth() const = 0;
481
482 // get the width/height/... of the text using current or specified
483 // font
484 virtual void GetTextExtent(const wxString& string,
485 int *x, int *y,
486 int *descent = (int *) NULL,
487 int *externalLeading = (int *) NULL,
488 const wxFont *theFont = (const wxFont *) NULL)
489 const = 0;
490
491 // translate to/from screen/client coordinates (pointers may be NULL)
492 virtual void ClientToScreen( int *x, int *y ) const = 0;
493 virtual void ScreenToClient( int *x, int *y ) const = 0;
494
495 // misc
496 // ----
497
498 void UpdateWindowUI();
499
500 virtual bool PopupMenu( wxMenu *menu, int x, int y ) = 0;
501
502 // scrollbars
503 // ----------
504
505 // configure the window scrollbars
506 virtual void SetScrollbar( int orient,
507 int pos,
508 int thumbVisible,
509 int range,
510 bool refresh = TRUE ) = 0;
511 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0;
512 virtual int GetScrollPos( int orient ) const = 0;
513 virtual int GetScrollThumb( int orient ) const = 0;
514 virtual int GetScrollRange( int orient ) const = 0;
515
516 // scroll window to the specified position
517 virtual void ScrollWindow( int dx, int dy,
518 const wxRect* rect = (wxRect *) NULL ) = 0;
519
520 // tooltips
521 // --------
522 #if wxUSE_TOOLTIPS
523 // the easiest way to set a tooltip for a window is to use this method
524 void SetToolTip( const wxString &tip );
525 // attach a tooltip to the window
526 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
527 // get the associated tooltip or NULL if none
528 wxToolTip* GetToolTip() const { return m_tooltip; }
529 #endif // wxUSE_TOOLTIPS
530
531 // drag and drop
532 // -------------
533 #if wxUSE_DRAG_AND_DROP
534 // set/retrieve the drop target associated with this window (may be
535 // NULL; it's owned by the window and will be deleted by it)
536 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
537 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
538 #endif // wxUSE_DRAG_AND_DROP
539
540 // constraints and sizers
541 // ----------------------
542 #if wxUSE_CONSTRAINTS
543 // set the constraints for this window or retrieve them (may be NULL)
544 void SetConstraints( wxLayoutConstraints *constraints );
545 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
546
547 // when using constraints, it makes sense to update children positions
548 // automatically whenever the window is resized - this is done if
549 // autoLayout is on
550 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
551 bool GetAutoLayout() const { return m_autoLayout; }
552
553 // do layout the window and its children
554 virtual bool Layout();
555
556 // implementation only
557 void UnsetConstraints(wxLayoutConstraints *c);
558 wxWindowList *GetConstraintsInvolvedIn() const
559 { return m_constraintsInvolvedIn; }
560 void AddConstraintReference(wxWindowBase *otherWin);
561 void RemoveConstraintReference(wxWindowBase *otherWin);
562 void DeleteRelatedConstraints();
563 void ResetConstraints();
564
565 // these methods may be overriden for special layout algorithms
566 virtual void SetConstraintSizes(bool recurse = TRUE);
567 virtual bool LayoutPhase1(int *noChanges);
568 virtual bool LayoutPhase2(int *noChanges);
569 virtual bool DoPhase(int);
570
571 // these methods are virtual but normally won't be overridden
572 virtual void TransformSizerToActual(int *x, int *y) const ;
573 virtual void SetSizeConstraint(int x, int y, int w, int h);
574 virtual void MoveConstraint(int x, int y);
575 virtual void GetSizeConstraint(int *w, int *h) const ;
576 virtual void GetClientSizeConstraint(int *w, int *h) const ;
577 virtual void GetPositionConstraint(int *x, int *y) const ;
578
579 // sizers
580 // TODO: what are they and how do they work??
581 void SetSizer( wxSizer *sizer );
582 wxSizer *GetSizer() const { return m_windowSizer; }
583
584 void SetSizerParent( wxWindowBase *win ) { m_sizerParent = win; }
585 wxWindowBase *GetSizerParent() const { return m_sizerParent; }
586
587 virtual void SizerSetSize(int x, int y, int w, int h);
588 virtual void SizerMove(int x, int y);
589 #endif // wxUSE_CONSTRAINTS
590
591 // backward compatibility
592 // ----------------------
593 #if WXWIN_COMPATIBILITY
594 bool Enabled() const { return IsEnabled(); }
595
596 void SetButtonFont(const wxFont& font) { SetFont(font); }
597 void SetLabelFont(const wxFont& font) { SetFont(font); }
598 wxFont& GetLabelFont() { return GetFont(); };
599 wxFont& GetButtonFont() { return GetFont(); };
600 #endif // WXWIN_COMPATIBILITY
601
602 // implementation
603 // --------------
604
605 // event handlers
606 void OnSysColourChanged( wxSysColourChangedEvent& event );
607 void OnInitDialog( wxInitDialogEvent &event );
608
609 // get the haqndle of the window for the underlying window system: this
610 // is only used for wxWin itself or for user code which wants to call
611 // platform-specific APIs
612 virtual WXWidget GetHandle() const = 0;
613
614 protected:
615 // the window id - a number which uniquely identifies a window among
616 // its siblings unless it is -1
617 wxWindowID m_windowId;
618
619 // the parent window of this window (or NULL) and the list of the children
620 // of this window
621 wxWindow *m_parent;
622 wxWindowList m_children;
623
624 // the minimal allowed size for the window (no minimal size if variable(s)
625 // contain(s) -1)
626 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
627
628 // event handler for this window: usually is just 'this' but may be
629 // changed with SetEventHandler()
630 wxEvtHandler *m_eventHandler;
631
632 // associated validator or NULL if none
633 wxValidator *m_windowValidator;
634
635 #if wxUSE_DRAG_AND_DROP
636 wxDropTarget *m_dropTarget;
637 #endif // wxUSE_DRAG_AND_DROP
638
639 // visual window attributes
640 wxCursor m_cursor;
641 wxFont m_font;
642 wxColour m_backgroundColour, m_foregroundColour;
643
644 // the region which should be repainted in response to paint event
645 wxRegion m_updateRegion;
646
647 // the accelerator table for the window which translates key strokes into
648 // command events
649 wxAcceleratorTable m_acceleratorTable;
650
651 // user data associated with the window: either an object which will be
652 // deleted by the window when it's deleted or some raw pointer which we do
653 // nothing with
654 wxClientData *m_clientObject;
655 void *m_clientData;
656
657 // the tooltip for this window (may be NULL)
658 #if wxUSE_TOOLTIPS
659 wxToolTip *m_tooltip;
660 #endif // wxUSE_TOOLTIPS
661
662 // constraints and sizers
663 #if wxUSE_CONSTRAINTS
664 // the constraints for this window or NULL
665 wxLayoutConstraints *m_constraints;
666
667 // constraints this window is involved in
668 wxWindowList *m_constraintsInvolvedIn;
669
670 // top level and the parent sizers
671 // TODO what's this and how does it work?)
672 wxSizer *m_windowSizer;
673 wxWindowBase *m_sizerParent;
674
675 // Layout() window automatically when its size changes?
676 bool m_autoLayout:1;
677 #endif // wxUSE_CONSTRAINTS
678
679 // window state
680 bool m_isShown:1;
681 bool m_isEnabled:1;
682 bool m_isBeingDeleted:1;
683
684 // window attributes
685 long m_windowStyle;
686 wxString m_windowName;
687
688 protected:
689 // common part of all ctors: it is not virtual because it is called from
690 // ctor
691 void InitBase();
692
693 // get the default size for the new window if no explicit size given
694 // FIXME why 20 and not 30, 10 or ...?
695 static int WidthDefault(int w) { return w == -1 ? 20 : w; }
696 static int HeightDefault(int h) { return h == -1 ? 20 : h; }
697
698 // more pure virtual functions
699 // ---------------------------
700
701 // NB: we must have DoSomething() function when Something() is an overloaded
702 // method: indeed, we can't just have "virtual Something()" in case when
703 // the function is overloaded because then we'd have to make virtual all
704 // the variants (otherwise only the virtual function may be called on a
705 // pointer to derived class according to C++ rules) which is, in
706 // general, absolutely not needed. So instead we implement all
707 // overloaded Something()s in terms of DoSomething() which will be the
708 // only one to be virtual.
709
710 // retrieve the position/size of the window
711 virtual void DoGetPosition( int *x, int *y ) const = 0;
712 virtual void DoGetSize( int *width, int *height ) const = 0;
713 virtual void DoGetClientSize( int *width, int *height ) const = 0;
714
715 // this is the virtual function to be overriden in any derived class which
716 // wants to change how SetSize() or Move() works - it is called by all
717 // versions of these functions in the base class
718 virtual void DoSetSize(int x, int y,
719 int width, int height,
720 int sizeFlags = wxSIZE_AUTO) = 0;
721
722 // same as DoSetSize() for the client size
723 virtual void DoSetClientSize(int width, int height) = 0;
724
725 #if wxUSE_TOOLTIPS
726 virtual void DoSetToolTip( wxToolTip *tip );
727 #endif // wxUSE_TOOLTIPS
728
729 private:
730 // contains the last id generated by NewControlId
731 static int ms_lastControlId;
732
733 DECLARE_NO_COPY_CLASS(wxWindowBase);
734 DECLARE_EVENT_TABLE()
735 };
736
737 // ----------------------------------------------------------------------------
738 // now include the declaration of wxWindow class
739 // ----------------------------------------------------------------------------
740
741 #if defined(__WXMSW__)
742 #include "wx/msw/window.h"
743 #elif defined(__WXMOTIF__)
744 #include "wx/motif/window.h"
745 #elif defined(__WXGTK__)
746 #include "wx/gtk/window.h"
747 #elif defined(__WXQT__)
748 #include "wx/qt/window.h"
749 #elif defined(__WXMAC__)
750 #include "wx/mac/window.h"
751 #endif
752
753 // ----------------------------------------------------------------------------
754 // inline functions which couldn't be declared in the class body because of
755 // forward dependencies
756 // ----------------------------------------------------------------------------
757
758 inline wxWindow *wxWindowBase::GetGrandParent() const
759 {
760 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
761 }
762
763 // ----------------------------------------------------------------------------
764 // global function
765 // ----------------------------------------------------------------------------
766
767 WXDLLEXPORT extern wxWindow* wxGetActiveWindow();
768 inline WXDLLEXPORT int NewControlId() { return wxWindowBase::NewControlId(); }
769
770 #endif
771 // _WX_WINDOW_H_BASE_