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