]> git.saurik.com Git - wxWidgets.git/blob - include/wx/window.h
added wxUSE_COLOURDLG to the header too
[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 #include "wx/validate.h" // for wxDefaultValidator (always include it)
34
35 #if wxUSE_ACCEL
36 #include "wx/accel.h"
37 #endif // wxUSE_ACCEL
38
39 // ----------------------------------------------------------------------------
40 // forward declarations
41 // ----------------------------------------------------------------------------
42
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;
56
57 // ----------------------------------------------------------------------------
58 // (pseudo)template list classes
59 // ----------------------------------------------------------------------------
60
61 WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT);
62
63 // ----------------------------------------------------------------------------
64 // global variables
65 // ----------------------------------------------------------------------------
66
67 WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
68
69 // ----------------------------------------------------------------------------
70 // helper classes used by [SG]etClientObject/Data
71 //
72 // TODO move into a separate header?
73 // ----------------------------------------------------------------------------
74
75 // what kind of client data do we have?
76 enum wxClientDataType
77 {
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
81 };
82
83 class wxClientData
84 {
85 public:
86 wxClientData() { }
87 virtual ~wxClientData() { }
88 };
89
90 class wxStringClientData : public wxClientData
91 {
92 public:
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; }
97
98 private:
99 wxString m_data;
100 };
101
102 // ----------------------------------------------------------------------------
103 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
104 // interface of this class.
105 //
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 // ----------------------------------------------------------------------------
112
113 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
114 {
115 public:
116 // creating the window
117 // -------------------
118
119 // default ctor
120 wxWindowBase() { InitBase(); }
121
122 // pseudo ctor (can't be virtual, called from ctor)
123 bool CreateBase(wxWindowBase *parent,
124 wxWindowID id,
125 const wxPoint& pos = wxDefaultPosition,
126 const wxSize& size = wxDefaultSize,
127 long style = 0,
128 const wxValidator& validator = wxDefaultValidator,
129 const wxString& name = wxPanelNameStr);
130
131 virtual ~wxWindowBase();
132
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
142
143 // deleting the window
144 // -------------------
145
146 // ask the window to close itself, return TRUE if the event handler
147 // honoured our request
148 bool Close( bool force = FALSE );
149
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
153
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();
158
159 // is the window being deleted?
160 bool IsBeingDeleted() const { return m_isBeingDeleted; }
161
162 // window attributes
163 // -----------------
164
165 // the title (or label, see below) of the window: the text which the
166 // window shows
167 virtual void SetTitle( const wxString & WXUNUSED(title) ) { }
168 virtual wxString GetTitle() const { return ""; }
169
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(); }
174
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; }
179
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; }
184
185 // generate a control id for the controls which were not given one by
186 // user
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; }
194
195 // moving/resizing
196 // ---------------
197
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); }
202
203 void SetSize( int width, int height )
204 { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); }
205
206 void SetSize( const wxSize& size )
207 { SetSize( size.x, size.y); }
208
209 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
210 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
211
212 void Move(int x, int y, int flags = wxSIZE_USE_EXISTING)
213 { DoSetSize(x, y, -1, -1, flags); }
214
215 void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
216 { Move(pt.x, pt.y, flags); }
217
218 // Z-order
219 virtual void Raise() = 0;
220 virtual void Lower() = 0;
221
222 // client size is the size of area available for subwindows
223 void SetClientSize( int width, int height )
224 { DoSetClientSize(width, height); }
225
226 void SetClientSize( const wxSize& size )
227 { DoSetClientSize(size.x, size.y); }
228
229 void SetClientSize(const wxRect& rect)
230 { SetClientSize( rect.width, rect.height ); }
231
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
235 {
236 int w, h;
237 DoGetPosition(&w, &h);
238
239 return wxPoint(w, h);
240 }
241
242 void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
243 wxSize GetSize() const
244 {
245 int w, h;
246 DoGetSize(& w, & h);
247 return wxSize(w, h);
248 }
249
250 wxRect GetRect() const
251 {
252 int x, y, w, h;
253 GetPosition(& x, & y);
254 GetSize(& w, & h);
255
256 return wxRect(x, y, w, h);
257 }
258
259 void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
260 wxSize GetClientSize() const
261 {
262 int w, h;
263 DoGetClientSize(& w, & h);
264
265 return wxSize(w, h);
266 }
267
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;
272
273 // get the client rectangle in window (i.e. client) coordinates
274 wxRect GetClientRect() const
275 {
276 return wxRect(GetClientAreaOrigin(), GetClientSize());
277 }
278
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
283 {
284 wxSize s = DoGetBestSize();
285 if ( w )
286 *w = s.x;
287 if ( h )
288 *h = s.y;
289 }
290
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); }
296
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); }
300
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); }
304
305 // set window size to wrap around its children
306 virtual void Fit();
307
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 );
312
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; }
317
318 // window state
319 // ------------
320
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); }
325
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); }
329
330 bool IsShown() const { return m_isShown; }
331 bool IsEnabled() const { return m_isEnabled; }
332
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; }
337
338 // just some (somewhat shorter) synonims
339 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
340 long GetWindowStyle() const { return GetWindowStyleFlag(); }
341
342 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
343 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
344
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; }
349
350 // make the window modal (all other windows unresponsive)
351 virtual void MakeModal(bool modal = TRUE);
352
353 virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
354 virtual bool GetThemeEnabled() const { return m_themeEnabled; }
355
356 // focus handling
357 // --------------
358
359 // set focus to this window
360 virtual void SetFocus() = 0;
361
362 // return the window which currently has the focus or NULL
363 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
364
365 // can this window have focus?
366 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
367
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
370 // click it
371 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
372
373 // parent/children relations
374 // -------------------------
375
376 // get the list of children
377 const wxWindowList& GetChildren() const { return m_children; }
378 wxWindowList& GetChildren() { return m_children; }
379
380 // get the parent or the parent of the parent
381 wxWindow *GetParent() const { return m_parent; }
382 inline wxWindow *GetGrandParent() const;
383
384 // is this window a top level one?
385 virtual bool IsTopLevel() const;
386
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 );
392
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 );
397
398 // implementation mostly
399 virtual void AddChild( wxWindowBase *child );
400 virtual void RemoveChild( wxWindowBase *child );
401
402 // event handler stuff
403 // -------------------
404
405 // get the current event handler
406 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
407
408 // replace the event handler (allows to completely subclass the
409 // window)
410 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
411
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 );
416
417 // validators
418 // ----------
419
420 #if wxUSE_VALIDATORS
421 // a window may have an associated validator which is used to control
422 // user input
423 virtual void SetValidator( const wxValidator &validator );
424 virtual wxValidator *GetValidator() { return m_windowValidator; }
425 #endif // wxUSE_VALIDATORS
426
427 // client data
428 // -----------
429
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(); }
436
437 void SetClientData( void *data ) { DoSetClientData(data); }
438 void *GetClientData() const { return DoGetClientData(); }
439
440 // dialog oriented functions
441 // -------------------------
442
443 // validate the correctness of input, return TRUE if ok
444 virtual bool Validate();
445
446 // transfer data between internal and GUI representations
447 virtual bool TransferDataToWindow();
448 virtual bool TransferDataFromWindow();
449
450 virtual void InitDialog();
451
452 #if wxUSE_ACCEL
453 // accelerators
454 // ------------
455 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
456 { m_acceleratorTable = accel; }
457 wxAcceleratorTable *GetAcceleratorTable()
458 { return &m_acceleratorTable; }
459 #endif // wxUSE_ACCEL
460
461 // dialog units translations
462 // -------------------------
463
464 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
465 wxPoint ConvertDialogToPixels( const wxPoint& pt );
466 wxSize ConvertPixelsToDialog( const wxSize& sz )
467 {
468 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
469
470 return wxSize(pt.x, pt.y);
471 }
472
473 wxSize ConvertDialogToPixels( const wxSize& sz )
474 {
475 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
476
477 return wxSize(pt.x, pt.y);
478 }
479
480 // mouse functions
481 // ---------------
482
483 // move the mouse to the specified position
484 virtual void WarpPointer(int x, int y) = 0;
485
486 // start or end mouse capture
487 virtual void CaptureMouse() = 0;
488 virtual void ReleaseMouse() = 0;
489
490 // get the window which currently captures the mouse or NULL
491 static wxWindow *GetCapture();
492
493 // does this window have the capture?
494 virtual bool HasCapture() const
495 { return (wxWindow *)this == GetCapture(); }
496
497 // painting the window
498 // -------------------
499
500 // mark the specified rectangle (or the whole window) as "dirty" so it
501 // will be repainted
502 virtual void Refresh( bool eraseBackground = TRUE,
503 const wxRect *rect = (const wxRect *) NULL ) = 0;
504
505 // a less awkward wrapper for Refresh
506 void RefreshRect(const wxRect& rect) { Refresh(TRUE, &rect); }
507
508 // repaint all invalid areas of the window immediately
509 virtual void Update() { }
510
511 // clear the window entirely
512 virtual void Clear() = 0;
513
514 // adjust DC for drawing on this window
515 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
516
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; }
521
522 // get the update rectangleregion bounding box in client coords
523 wxRect GetUpdateClientRect() const;
524
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;
529
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); }
534
535 // colours, fonts and cursors
536 // --------------------------
537
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 );
542
543 wxColour GetBackgroundColour() const { return m_backgroundColour; }
544 wxColour GetForegroundColour() const { return m_foregroundColour; }
545
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; }
551
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; }
557
558 #if wxUSE_CARET
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
564
565 // get the (average) character size for the current font
566 virtual int GetCharHeight() const = 0;
567 virtual int GetCharWidth() const = 0;
568
569 // get the width/height/... of the text using current or specified
570 // font
571 virtual void GetTextExtent(const wxString& string,
572 int *x, int *y,
573 int *descent = (int *) NULL,
574 int *externalLeading = (int *) NULL,
575 const wxFont *theFont = (const wxFont *) NULL)
576 const = 0;
577
578 // client <-> screen coords
579 // ------------------------
580
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); }
586
587 // wxPoint interface to do the same thing
588 wxPoint ClientToScreen(const wxPoint& pt) const
589 {
590 int x = pt.x, y = pt.y;
591 DoClientToScreen(&x, &y);
592
593 return wxPoint(x, y);
594 }
595
596 wxPoint ScreenToClient(const wxPoint& pt) const
597 {
598 int x = pt.x, y = pt.y;
599 DoScreenToClient(&x, &y);
600
601 return wxPoint(x, y);
602 }
603
604 // test where the given (in client coords) point lies
605 wxHitTest HitTest(wxCoord x, wxCoord y) const
606 { return DoHitTest(x, y); }
607
608 wxHitTest HitTest(const wxPoint& pt) const
609 { return DoHitTest(pt.x, pt.y); }
610
611 // misc
612 // ----
613
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;
617
618 void UpdateWindowUI();
619
620 #if wxUSE_MENUS
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
626
627 // scrollbars
628 // ----------
629
630 // does the window have the scrollbar for this orientation?
631 bool HasScrollbar(int orient) const
632 {
633 return (m_windowStyle &
634 (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0;
635 }
636
637 // configure the window scrollbars
638 virtual void SetScrollbar( int orient,
639 int pos,
640 int thumbvisible,
641 int range,
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;
647
648 // scroll window to the specified position
649 virtual void ScrollWindow( int dx, int dy,
650 const wxRect* rect = (wxRect *) NULL ) = 0;
651
652 // context-sensitive help
653 // ----------------------
654
655 // these are the convenience functions wrapping wxHelpProvider methods
656
657 #if wxUSE_HELP
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
661 // one
662 void SetHelpTextForId(const wxString& text);
663 // get the help string associated with this window (may be empty)
664 wxString GetHelpText() const;
665 #endif // wxUSE_HELP
666
667 // tooltips
668 // --------
669
670 #if wxUSE_TOOLTIPS
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
678
679 // drag and drop
680 // -------------
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
687
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; }
694
695 // when using constraints, it makes sense to update children positions
696 // automatically whenever the window is resized - this is done if
697 // autoLayout is on
698 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
699 bool GetAutoLayout() const { return m_autoLayout; }
700
701 // do layout the window and its children
702 virtual bool Layout();
703
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();
712
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);
718
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 ;
725
726 // sizers
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
731
732 // backward compatibility
733 // ----------------------
734 #if WXWIN_COMPATIBILITY
735 bool Enabled() const { return IsEnabled(); }
736
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
742
743 // implementation
744 // --------------
745
746 // event handlers
747 void OnSysColourChanged( wxSysColourChangedEvent& event );
748 void OnInitDialog( wxInitDialogEvent &event );
749 void OnMiddleClick( wxMouseEvent& event );
750 #if wxUSE_HELP
751 void OnHelp(wxHelpEvent& event);
752 #endif // wxUSE_HELP
753
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;
758
759 protected:
760 // the window id - a number which uniquely identifies a window among
761 // its siblings unless it is -1
762 wxWindowID m_windowId;
763
764 // the parent window of this window (or NULL) and the list of the children
765 // of this window
766 wxWindow *m_parent;
767 wxWindowList m_children;
768
769 // the minimal allowed size for the window (no minimal size if variable(s)
770 // contain(s) -1)
771 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
772
773 // event handler for this window: usually is just 'this' but may be
774 // changed with SetEventHandler()
775 wxEvtHandler *m_eventHandler;
776
777 #if wxUSE_VALIDATORS
778 // associated validator or NULL if none
779 wxValidator *m_windowValidator;
780 #endif // wxUSE_VALIDATORS
781
782 #if wxUSE_DRAG_AND_DROP
783 wxDropTarget *m_dropTarget;
784 #endif // wxUSE_DRAG_AND_DROP
785
786 // visual window attributes
787 wxCursor m_cursor;
788 wxFont m_font;
789 wxColour m_backgroundColour, m_foregroundColour;
790
791 #if wxUSE_CARET
792 wxCaret *m_caret;
793 #endif // wxUSE_CARET
794
795 // the region which should be repainted in response to paint event
796 wxRegion m_updateRegion;
797
798 #if wxUSE_ACCEL
799 // the accelerator table for the window which translates key strokes into
800 // command events
801 wxAcceleratorTable m_acceleratorTable;
802 #endif // wxUSE_ACCEL
803
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)
809 union
810 {
811 wxClientData *m_clientObject;
812 void *m_clientData;
813 };
814
815 // the tooltip for this window (may be NULL)
816 #if wxUSE_TOOLTIPS
817 wxToolTip *m_tooltip;
818 #endif // wxUSE_TOOLTIPS
819
820 // constraints and sizers
821 #if wxUSE_CONSTRAINTS
822 // the constraints for this window or NULL
823 wxLayoutConstraints *m_constraints;
824
825 // constraints this window is involved in
826 wxWindowList *m_constraintsInvolvedIn;
827
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;
832
833 // Layout() window automatically when its size changes?
834 bool m_autoLayout:1;
835 #endif // wxUSE_CONSTRAINTS
836
837 // window state
838 bool m_isShown:1;
839 bool m_isEnabled:1;
840 bool m_isBeingDeleted:1;
841
842 // window attributes
843 long m_windowStyle,
844 m_exStyle;
845 wxString m_windowName;
846 bool m_themeEnabled;
847
848 protected:
849 // common part of all ctors: it is not virtual because it is called from
850 // ctor
851 void InitBase();
852
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;
856
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; }
861
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)
866 {
867 if ( size.x == -1 || size.y == -1 )
868 {
869 wxSize sizeBest = DoGetBestSize();
870 if ( size.x != -1 )
871 sizeBest.x = size.x;
872 if ( size.y != -1 )
873 sizeBest.y = size.y;
874
875 SetSize(sizeBest);
876 }
877 }
878
879 // more pure virtual functions
880 // ---------------------------
881
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.
890
891 // coordinates translation
892 virtual void DoClientToScreen( int *x, int *y ) const = 0;
893 virtual void DoScreenToClient( int *x, int *y ) const = 0;
894
895 virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
896
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;
901
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;
906
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;
913
914 // same as DoSetSize() for the client size
915 virtual void DoSetClientSize(int width, int height) = 0;
916
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;
922
923 #if wxUSE_TOOLTIPS
924 virtual void DoSetToolTip( wxToolTip *tip );
925 #endif // wxUSE_TOOLTIPS
926
927 #if wxUSE_MENUS
928 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
929 #endif // wxUSE_MENUS
930
931 // client data accessors
932 virtual void DoSetClientObject( wxClientData *data );
933 virtual wxClientData *DoGetClientObject() const;
934
935 virtual void DoSetClientData( void *data );
936 virtual void *DoGetClientData() const;
937
938 // what kind of data do we have?
939 wxClientDataType m_clientDataType;
940
941 private:
942 // contains the last id generated by NewControlId
943 static int ms_lastControlId;
944
945 DECLARE_ABSTRACT_CLASS(wxWindowBase)
946 DECLARE_NO_COPY_CLASS(wxWindowBase)
947 DECLARE_EVENT_TABLE()
948 };
949
950 // ----------------------------------------------------------------------------
951 // now include the declaration of wxWindow class
952 // ----------------------------------------------------------------------------
953
954 // include the declaration of the platform-specific class
955 #if defined(__WXMSW__)
956 #ifdef __WXUNIVERSAL__
957 #define wxWindowNative wxWindowMSW
958 #else // !wxUniv
959 #define wxWindowMSW wxWindow
960 #define sm_classwxWindowMSW sm_classwxWindow
961 #endif // wxUniv/!wxUniv
962 #include "wx/msw/window.h"
963 #elif defined(__WXMOTIF__)
964 #include "wx/motif/window.h"
965 #elif defined(__WXGTK__)
966 #ifdef __WXUNIVERSAL__
967 #define wxWindowNative wxWindowGTK
968 #else // !wxUniv
969 #define wxWindowGTK wxWindow
970 #define sm_classwxWindowGTK sm_classwxWindow
971 #endif // wxUniv
972 #include "wx/gtk/window.h"
973 #elif defined(__WXQT__)
974 #include "wx/qt/window.h"
975 #elif defined(__WXMAC__)
976 #ifdef __WXUNIVERSAL__
977 #define wxWindowNative wxWindowMac
978 #else // !wxUniv
979 #define wxWindowMac wxWindow
980 #define sm_classwxWindowMac sm_classwxWindow
981 #endif // wxUniv
982 #include "wx/mac/window.h"
983 #elif defined(__WXPM__)
984 #include "wx/os2/window.h"
985 #endif
986
987 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
988 // for the native ports we already have defined it above
989 #if defined(__WXUNIVERSAL__)
990 #ifndef wxWindowNative
991 #error "wxWindowNative must be defined above!"
992 #endif
993
994 #include "wx/univ/window.h"
995 #endif // wxUniv
996
997 // ----------------------------------------------------------------------------
998 // inline functions which couldn't be declared in the class body because of
999 // forward dependencies
1000 // ----------------------------------------------------------------------------
1001
1002 inline wxWindow *wxWindowBase::GetGrandParent() const
1003 {
1004 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
1005 }
1006
1007 // ----------------------------------------------------------------------------
1008 // global functions
1009 // ----------------------------------------------------------------------------
1010
1011 // Find the wxWindow at the current mouse position, also returning the mouse
1012 // position.
1013 WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt);
1014
1015 // Get the current mouse position.
1016 WXDLLEXPORT extern wxPoint wxGetMousePosition();
1017
1018 // get the currently active window of this application or NULL
1019 WXDLLEXPORT extern wxWindow *wxGetActiveWindow();
1020
1021 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1022 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1023
1024 #endif
1025 // _WX_WINDOW_H_BASE_