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