]> git.saurik.com Git - wxWidgets.git/blob - include/wx/window.h
moved AdjustToClientAreaOrigin to wxWindowBase, needed worldwide for wxUniv
[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 // when building wxUniv/Foo we don't want the code for native menu use to be
40 // compiled in - it should only be used when building real wxFoo
41 #ifdef __WXUNIVERSAL__
42 #define wxUSE_MENUS_NATIVE 0
43 #else // __WXMSW__
44 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
45 #endif // __WXUNIVERSAL__/__WXMSW__
46
47 // ----------------------------------------------------------------------------
48 // forward declarations
49 // ----------------------------------------------------------------------------
50
51 class WXDLLEXPORT wxCaret;
52 class WXDLLEXPORT wxClientData;
53 class WXDLLEXPORT wxControl;
54 class WXDLLEXPORT wxCursor;
55 class WXDLLEXPORT wxDC;
56 class WXDLLEXPORT wxDropTarget;
57 class WXDLLEXPORT wxItemResource;
58 class WXDLLEXPORT wxLayoutConstraints;
59 class WXDLLEXPORT wxResourceTable;
60 class WXDLLEXPORT wxSizer;
61 class WXDLLEXPORT wxToolTip;
62 class WXDLLEXPORT wxWindowBase;
63 class WXDLLEXPORT wxWindow;
64
65 // ----------------------------------------------------------------------------
66 // (pseudo)template list classes
67 // ----------------------------------------------------------------------------
68
69 WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT);
70
71 // ----------------------------------------------------------------------------
72 // global variables
73 // ----------------------------------------------------------------------------
74
75 WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
76
77 // ----------------------------------------------------------------------------
78 // helper classes used by [SG]etClientObject/Data
79 //
80 // TODO move into a separate header?
81 // ----------------------------------------------------------------------------
82
83 // what kind of client data do we have?
84 enum wxClientDataType
85 {
86 wxClientData_None, // we don't know yet because we don't have it at all
87 wxClientData_Object, // our client data is typed and we own it
88 wxClientData_Void // client data is untyped and we don't own it
89 };
90
91 class wxClientData
92 {
93 public:
94 wxClientData() { }
95 virtual ~wxClientData() { }
96 };
97
98 class wxStringClientData : public wxClientData
99 {
100 public:
101 wxStringClientData() { }
102 wxStringClientData( const wxString &data ) : m_data(data) { }
103 void SetData( const wxString &data ) { m_data = data; }
104 const wxString& GetData() const { return m_data; }
105
106 private:
107 wxString m_data;
108 };
109
110 // ----------------------------------------------------------------------------
111 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
112 // interface of this class.
113 //
114 // Event handler: windows have themselves as their event handlers by default,
115 // but their event handlers could be set to another object entirely. This
116 // separation can reduce the amount of derivation required, and allow
117 // alteration of a window's functionality (e.g. by a resource editor that
118 // temporarily switches event handlers).
119 // ----------------------------------------------------------------------------
120
121 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
122 {
123 public:
124 // creating the window
125 // -------------------
126
127 // default ctor
128 wxWindowBase() { InitBase(); }
129
130 // pseudo ctor (can't be virtual, called from ctor)
131 bool CreateBase(wxWindowBase *parent,
132 wxWindowID id,
133 const wxPoint& pos = wxDefaultPosition,
134 const wxSize& size = wxDefaultSize,
135 long style = 0,
136 const wxValidator& validator = wxDefaultValidator,
137 const wxString& name = wxPanelNameStr);
138
139 virtual ~wxWindowBase();
140
141 #if wxUSE_WX_RESOURCES
142 // these functions are implemented in resource.cpp and resourc2.cpp
143 virtual bool LoadFromResource(wxWindow *parent,
144 const wxString& resourceName,
145 const wxResourceTable *table = (const wxResourceTable *) NULL);
146 virtual wxControl *CreateItem(const wxItemResource* childResource,
147 const wxItemResource* parentResource,
148 const wxResourceTable *table = (const wxResourceTable *) NULL);
149 #endif // wxUSE_WX_RESOURCES
150
151 // deleting the window
152 // -------------------
153
154 // ask the window to close itself, return TRUE if the event handler
155 // honoured our request
156 bool Close( bool force = FALSE );
157
158 // the following functions delete the C++ objects (the window itself
159 // or its children) as well as the GUI windows and normally should
160 // never be used directly
161
162 // delete window unconditionally (dangerous!), returns TRUE if ok
163 virtual bool Destroy();
164 // delete all children of this window, returns TRUE if ok
165 bool DestroyChildren();
166
167 // is the window being deleted?
168 bool IsBeingDeleted() const { return m_isBeingDeleted; }
169
170 // window attributes
171 // -----------------
172
173 // NB: in future versions of wxWindows Set/GetTitle() will only work
174 // with the top level windows (such as dialogs and frames) and
175 // Set/GetLabel() only with the other ones (i.e. all controls).
176
177 // the title (or label, see below) of the window: the text which the
178 // window shows
179 virtual void SetTitle( const wxString& WXUNUSED(title) ) {}
180 virtual wxString GetTitle() const { return wxEmptyString; }
181
182 // label is just the same as the title (but for, e.g., buttons it
183 // makes more sense to speak about labels)
184 virtual void SetLabel(const wxString& label) { SetTitle(label); }
185 virtual wxString GetLabel() const { return GetTitle(); }
186
187 // the window name is used for ressource setting in X, it is not the
188 // same as the window title/label
189 virtual void SetName( const wxString &name ) { m_windowName = name; }
190 virtual wxString GetName() const { return m_windowName; }
191
192 // window id uniquely identifies the window among its siblings unless
193 // it is -1 which means "don't care"
194 void SetId( wxWindowID id ) { m_windowId = id; }
195 wxWindowID GetId() const { return m_windowId; }
196
197 // generate a control id for the controls which were not given one by
198 // user
199 static int NewControlId() { return --ms_lastControlId; }
200 // get the id of the control following the one with the given
201 // (autogenerated) id
202 static int NextControlId(int id) { return id - 1; }
203 // get the id of the control preceding the one with the given
204 // (autogenerated) id
205 static int PrevControlId(int id) { return id + 1; }
206
207 // moving/resizing
208 // ---------------
209
210 // set the window size and/or position
211 void SetSize( int x, int y, int width, int height,
212 int sizeFlags = wxSIZE_AUTO )
213 { DoSetSize(x, y, width, height, sizeFlags); }
214
215 void SetSize( int width, int height )
216 { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); }
217
218 void SetSize( const wxSize& size )
219 { SetSize( size.x, size.y); }
220
221 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
222 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
223
224 void Move(int x, int y, int flags = wxSIZE_USE_EXISTING)
225 { DoSetSize(x, y, -1, -1, flags); }
226
227 void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
228 { Move(pt.x, pt.y, flags); }
229
230 // Z-order
231 virtual void Raise() = 0;
232 virtual void Lower() = 0;
233
234 // client size is the size of area available for subwindows
235 void SetClientSize( int width, int height )
236 { DoSetClientSize(width, height); }
237
238 void SetClientSize( const wxSize& size )
239 { DoSetClientSize(size.x, size.y); }
240
241 void SetClientSize(const wxRect& rect)
242 { SetClientSize( rect.width, rect.height ); }
243
244 // get the window position and/or size (pointers may be NULL)
245 void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); }
246 wxPoint GetPosition() const
247 {
248 int w, h;
249 DoGetPosition(&w, &h);
250
251 return wxPoint(w, h);
252 }
253
254 void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
255 wxSize GetSize() const
256 {
257 int w, h;
258 DoGetSize(& w, & h);
259 return wxSize(w, h);
260 }
261
262 wxRect GetRect() const
263 {
264 int x, y, w, h;
265 GetPosition(& x, & y);
266 GetSize(& w, & h);
267
268 return wxRect(x, y, w, h);
269 }
270
271 void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
272 wxSize GetClientSize() const
273 {
274 int w, h;
275 DoGetClientSize(& w, & h);
276
277 return wxSize(w, h);
278 }
279
280 // get the origin of the client area of the window relative to the
281 // window top left corner (the client area may be shifted because of
282 // the borders, scrollbars, other decorations...)
283 virtual wxPoint GetClientAreaOrigin() const;
284
285 // get the client rectangle in window (i.e. client) coordinates
286 wxRect GetClientRect() const
287 {
288 return wxRect(GetClientAreaOrigin(), GetClientSize());
289 }
290
291 // get the size best suited for the window (in fact, minimal
292 // acceptable size using which it will still look "nice")
293 wxSize GetBestSize() const { return DoGetBestSize(); }
294 void GetBestSize(int *w, int *h) const
295 {
296 wxSize s = DoGetBestSize();
297 if ( w )
298 *w = s.x;
299 if ( h )
300 *h = s.y;
301 }
302
303 // the generic centre function - centers the window on parent by
304 // default or on screen if it doesn't have parent or
305 // wxCENTER_ON_SCREEN flag is given
306 void Centre( int direction = wxBOTH );
307 void Center( int direction = wxBOTH ) { Centre(direction); }
308
309 // centre on screen (only works for top level windows)
310 void CentreOnScreen(int dir = wxBOTH) { Centre(dir | wxCENTER_ON_SCREEN); }
311 void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); }
312
313 // centre with respect to the the parent window
314 void CentreOnParent(int dir = wxBOTH) { Centre(dir | wxCENTER_FRAME); }
315 void CenterOnParent(int dir = wxBOTH) { CentreOnParent(dir); }
316
317 // set window size to wrap around its children
318 virtual void Fit();
319
320 // set min/max size of the window
321 virtual void SetSizeHints( int minW, int minH,
322 int maxW = -1, int maxH = -1,
323 int incW = -1, int incH = -1 );
324
325 int GetMinWidth() const { return m_minWidth; }
326 int GetMinHeight() const { return m_minHeight; }
327 int GetMaxWidth() const { return m_maxWidth; }
328 int GetMaxHeight() const { return m_maxHeight; }
329
330 // window state
331 // ------------
332
333 // returns TRUE if window was shown/hidden, FALSE if the nothing was
334 // done (window was already shown/hidden)
335 virtual bool Show( bool show = TRUE );
336 bool Hide() { return Show(FALSE); }
337
338 // returns TRUE if window was enabled/disabled, FALSE if nothing done
339 virtual bool Enable( bool enable = TRUE );
340 bool Disable() { return Enable(FALSE); }
341
342 bool IsShown() const { return m_isShown; }
343 bool IsEnabled() const { return m_isEnabled; }
344
345 // get/set window style (setting style won't update the window and so
346 // is only useful for internal usage)
347 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
348 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
349
350 // just some (somewhat shorter) synonims
351 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
352 long GetWindowStyle() const { return GetWindowStyleFlag(); }
353
354 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
355 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
356
357 // extra style: the less often used style bits which can't be set with
358 // SetWindowStyleFlag()
359 void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
360 long GetExtraStyle() const { return m_exStyle; }
361
362 // make the window modal (all other windows unresponsive)
363 virtual void MakeModal(bool modal = TRUE);
364
365 virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
366 virtual bool GetThemeEnabled() const { return m_themeEnabled; }
367
368 // focus and keyboard handling
369 // ---------------------------
370
371 // set focus to this window
372 virtual void SetFocus() = 0;
373
374 // return the window which currently has the focus or NULL
375 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
376
377 // can this window have focus?
378 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
379
380 // can this window be given focus by keyboard navigation? if not, the
381 // only way to give it focus (provided it accepts it at all) is to
382 // click it
383 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
384
385 // NB: these methods really don't belong here but with the current
386 // class hierarchy there is no other place for them :-(
387
388 // get the default child of this parent, i.e. the one which is
389 // activated by pressing <Enter>
390 virtual wxWindow *GetDefaultItem() const { return NULL; }
391
392 // set this child as default, return the old default
393 virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child))
394 { return NULL; }
395
396 // parent/children relations
397 // -------------------------
398
399 // get the list of children
400 const wxWindowList& GetChildren() const { return m_children; }
401 wxWindowList& GetChildren() { return m_children; }
402
403 // get the parent or the parent of the parent
404 wxWindow *GetParent() const { return m_parent; }
405 inline wxWindow *GetGrandParent() const;
406
407 // is this window a top level one?
408 virtual bool IsTopLevel() const;
409
410 // it doesn't really change parent, use ReParent() instead
411 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
412 // change the real parent of this window, return TRUE if the parent
413 // was changed, FALSE otherwise (error or newParent == oldParent)
414 virtual bool Reparent( wxWindowBase *newParent );
415
416 // find window among the descendants of this one either by id or by
417 // name (return NULL if not found)
418 wxWindow *FindWindow( long id );
419 wxWindow *FindWindow( const wxString& name );
420
421 // implementation mostly
422 virtual void AddChild( wxWindowBase *child );
423 virtual void RemoveChild( wxWindowBase *child );
424
425 // event handler stuff
426 // -------------------
427
428 // get the current event handler
429 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
430
431 // replace the event handler (allows to completely subclass the
432 // window)
433 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
434
435 // push/pop event handler: allows to chain a custom event handler to
436 // alreasy existing ones
437 void PushEventHandler( wxEvtHandler *handler );
438 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
439
440 // validators
441 // ----------
442
443 #if wxUSE_VALIDATORS
444 // a window may have an associated validator which is used to control
445 // user input
446 virtual void SetValidator( const wxValidator &validator );
447 virtual wxValidator *GetValidator() { return m_windowValidator; }
448 #endif // wxUSE_VALIDATORS
449
450 // client data
451 // -----------
452
453 // each window may have associated client data: either a pointer to
454 // wxClientData object in which case it is managed by the window (i.e.
455 // it will delete the data when it's destroyed) or an untyped pointer
456 // which won't be deleted by the window - but not both of them
457 void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
458 wxClientData *GetClientObject() const { return DoGetClientObject(); }
459
460 void SetClientData( void *data ) { DoSetClientData(data); }
461 void *GetClientData() const { return DoGetClientData(); }
462
463 // dialog oriented functions
464 // -------------------------
465
466 // validate the correctness of input, return TRUE if ok
467 virtual bool Validate();
468
469 // transfer data between internal and GUI representations
470 virtual bool TransferDataToWindow();
471 virtual bool TransferDataFromWindow();
472
473 virtual void InitDialog();
474
475 #if wxUSE_ACCEL
476 // accelerators
477 // ------------
478 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
479 { m_acceleratorTable = accel; }
480 wxAcceleratorTable *GetAcceleratorTable()
481 { return &m_acceleratorTable; }
482 #endif // wxUSE_ACCEL
483
484 // dialog units translations
485 // -------------------------
486
487 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
488 wxPoint ConvertDialogToPixels( const wxPoint& pt );
489 wxSize ConvertPixelsToDialog( const wxSize& sz )
490 {
491 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
492
493 return wxSize(pt.x, pt.y);
494 }
495
496 wxSize ConvertDialogToPixels( const wxSize& sz )
497 {
498 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
499
500 return wxSize(pt.x, pt.y);
501 }
502
503 // mouse functions
504 // ---------------
505
506 // move the mouse to the specified position
507 virtual void WarpPointer(int x, int y) = 0;
508
509 // start or end mouse capture
510 virtual void CaptureMouse() = 0;
511 virtual void ReleaseMouse() = 0;
512
513 // get the window which currently captures the mouse or NULL
514 static wxWindow *GetCapture();
515
516 // does this window have the capture?
517 virtual bool HasCapture() const
518 { return (wxWindow *)this == GetCapture(); }
519
520 // painting the window
521 // -------------------
522
523 // mark the specified rectangle (or the whole window) as "dirty" so it
524 // will be repainted
525 virtual void Refresh( bool eraseBackground = TRUE,
526 const wxRect *rect = (const wxRect *) NULL ) = 0;
527
528 // a less awkward wrapper for Refresh
529 void RefreshRect(const wxRect& rect) { Refresh(TRUE, &rect); }
530
531 // repaint all invalid areas of the window immediately
532 virtual void Update() { }
533
534 // clear the window entirely
535 virtual void Clear() = 0;
536
537 // freeze the window: don't redraw it until it is thawed
538 virtual void Freeze() { }
539
540 // thaw the window: redraw it after it had been frozen
541 virtual void Thaw() { }
542
543 // adjust DC for drawing on this window
544 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
545
546 // the update region of the window contains the areas which must be
547 // repainted by the program
548 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
549 wxRegion& GetUpdateRegion() { return m_updateRegion; }
550
551 // get the update rectangleregion bounding box in client coords
552 wxRect GetUpdateClientRect() const;
553
554 // these functions verify whether the given point/rectangle belongs to
555 // (or at least intersects with) the update region
556 bool IsExposed( int x, int y ) const;
557 bool IsExposed( int x, int y, int w, int h ) const;
558
559 bool IsExposed( const wxPoint& pt ) const
560 { return IsExposed(pt.x, pt.y); }
561 bool IsExposed( const wxRect& rect ) const
562 { return IsExposed(rect.x, rect.y, rect.width, rect.height); }
563
564 // colours, fonts and cursors
565 // --------------------------
566
567 // set/retrieve the window colours (system defaults are used by
568 // default): Set functions return TRUE if colour was changed
569 virtual bool SetBackgroundColour( const wxColour &colour );
570 virtual bool SetForegroundColour( const wxColour &colour );
571
572 wxColour GetBackgroundColour() const { return m_backgroundColour; }
573 wxColour GetForegroundColour() const { return m_foregroundColour; }
574
575 // set/retrieve the cursor for this window (SetCursor() returns TRUE
576 // if the cursor was really changed)
577 virtual bool SetCursor( const wxCursor &cursor );
578 const wxCursor& GetCursor() const { return m_cursor; }
579 wxCursor& GetCursor() { return m_cursor; }
580
581 // set/retrieve the font for the window (SetFont() returns TRUE if the
582 // font really changed)
583 virtual bool SetFont( const wxFont &font ) = 0;
584 const wxFont& GetFont() const { return m_font; }
585 wxFont& GetFont() { return m_font; }
586
587 #if wxUSE_CARET
588 // associate a caret with the window
589 void SetCaret(wxCaret *caret);
590 // get the current caret (may be NULL)
591 wxCaret *GetCaret() const { return m_caret; }
592 #endif // wxUSE_CARET
593
594 // get the (average) character size for the current font
595 virtual int GetCharHeight() const = 0;
596 virtual int GetCharWidth() const = 0;
597
598 // get the width/height/... of the text using current or specified
599 // font
600 virtual void GetTextExtent(const wxString& string,
601 int *x, int *y,
602 int *descent = (int *) NULL,
603 int *externalLeading = (int *) NULL,
604 const wxFont *theFont = (const wxFont *) NULL)
605 const = 0;
606
607 // client <-> screen coords
608 // ------------------------
609
610 // translate to/from screen/client coordinates (pointers may be NULL)
611 void ClientToScreen( int *x, int *y ) const
612 { DoClientToScreen(x, y); }
613 void ScreenToClient( int *x, int *y ) const
614 { DoScreenToClient(x, y); }
615
616 // wxPoint interface to do the same thing
617 wxPoint ClientToScreen(const wxPoint& pt) const
618 {
619 int x = pt.x, y = pt.y;
620 DoClientToScreen(&x, &y);
621
622 return wxPoint(x, y);
623 }
624
625 wxPoint ScreenToClient(const wxPoint& pt) const
626 {
627 int x = pt.x, y = pt.y;
628 DoScreenToClient(&x, &y);
629
630 return wxPoint(x, y);
631 }
632
633 // test where the given (in client coords) point lies
634 wxHitTest HitTest(wxCoord x, wxCoord y) const
635 { return DoHitTest(x, y); }
636
637 wxHitTest HitTest(const wxPoint& pt) const
638 { return DoHitTest(pt.x, pt.y); }
639
640 // misc
641 // ----
642
643 // get the window border style: uses the current style and falls back to
644 // the default style for this class otherwise (see GetDefaultBorder())
645 wxBorder GetBorder() const;
646
647 void UpdateWindowUI();
648
649 #if wxUSE_MENUS
650 bool PopupMenu( wxMenu *menu, const wxPoint& pos )
651 { return DoPopupMenu(menu, pos.x, pos.y); }
652 bool PopupMenu( wxMenu *menu, int x, int y )
653 { return DoPopupMenu(menu, x, y); }
654 #endif // wxUSE_MENUS
655
656 // scrollbars
657 // ----------
658
659 // does the window have the scrollbar for this orientation?
660 bool HasScrollbar(int orient) const
661 {
662 return (m_windowStyle &
663 (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0;
664 }
665
666 // configure the window scrollbars
667 virtual void SetScrollbar( int orient,
668 int pos,
669 int thumbvisible,
670 int range,
671 bool refresh = TRUE ) = 0;
672 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0;
673 virtual int GetScrollPos( int orient ) const = 0;
674 virtual int GetScrollThumb( int orient ) const = 0;
675 virtual int GetScrollRange( int orient ) const = 0;
676
677 // scroll window to the specified position
678 virtual void ScrollWindow( int dx, int dy,
679 const wxRect* rect = (wxRect *) NULL ) = 0;
680
681 // scrolls window by line/page: note that not all controls support this
682 //
683 // return TRUE if the position changed, FALSE otherwise
684 virtual bool ScrollLines(int WXUNUSED(lines)) { return FALSE; }
685 virtual bool ScrollPages(int WXUNUSED(pages)) { return FALSE; }
686
687 // convenient wrappers for ScrollLines/Pages
688 bool LineUp() { return ScrollLines(-1); }
689 bool LineDown() { return ScrollLines(1); }
690 bool PageUp() { return ScrollPages(-1); }
691 bool PageDown() { return ScrollPages(1); }
692
693 // context-sensitive help
694 // ----------------------
695
696 // these are the convenience functions wrapping wxHelpProvider methods
697
698 #if wxUSE_HELP
699 // associate this help text with this window
700 void SetHelpText(const wxString& text);
701 // associate this help text with all windows with the same id as this
702 // one
703 void SetHelpTextForId(const wxString& text);
704 // get the help string associated with this window (may be empty)
705 wxString GetHelpText() const;
706 #endif // wxUSE_HELP
707
708 // tooltips
709 // --------
710
711 #if wxUSE_TOOLTIPS
712 // the easiest way to set a tooltip for a window is to use this method
713 void SetToolTip( const wxString &tip );
714 // attach a tooltip to the window
715 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
716 // get the associated tooltip or NULL if none
717 wxToolTip* GetToolTip() const { return m_tooltip; }
718 #endif // wxUSE_TOOLTIPS
719
720 // drag and drop
721 // -------------
722 #if wxUSE_DRAG_AND_DROP
723 // set/retrieve the drop target associated with this window (may be
724 // NULL; it's owned by the window and will be deleted by it)
725 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
726 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
727 #endif // wxUSE_DRAG_AND_DROP
728
729 // constraints and sizers
730 // ----------------------
731 #if wxUSE_CONSTRAINTS
732 // set the constraints for this window or retrieve them (may be NULL)
733 void SetConstraints( wxLayoutConstraints *constraints );
734 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
735
736 // when using constraints, it makes sense to update children positions
737 // automatically whenever the window is resized - this is done if
738 // autoLayout is on
739 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
740 bool GetAutoLayout() const { return m_autoLayout; }
741
742 // do layout the window and its children
743 virtual bool Layout();
744
745 // implementation only
746 void UnsetConstraints(wxLayoutConstraints *c);
747 wxWindowList *GetConstraintsInvolvedIn() const
748 { return m_constraintsInvolvedIn; }
749 void AddConstraintReference(wxWindowBase *otherWin);
750 void RemoveConstraintReference(wxWindowBase *otherWin);
751 void DeleteRelatedConstraints();
752 void ResetConstraints();
753
754 // these methods may be overriden for special layout algorithms
755 virtual void SetConstraintSizes(bool recurse = TRUE);
756 virtual bool LayoutPhase1(int *noChanges);
757 virtual bool LayoutPhase2(int *noChanges);
758 virtual bool DoPhase(int phase);
759
760 // these methods are virtual but normally won't be overridden
761 virtual void SetSizeConstraint(int x, int y, int w, int h);
762 virtual void MoveConstraint(int x, int y);
763 virtual void GetSizeConstraint(int *w, int *h) const ;
764 virtual void GetClientSizeConstraint(int *w, int *h) const ;
765 virtual void GetPositionConstraint(int *x, int *y) const ;
766
767 // sizers
768 // TODO: what are they and how do they work??
769 void SetSizer( wxSizer *sizer );
770 wxSizer *GetSizer() const { return m_windowSizer; }
771 #endif // wxUSE_CONSTRAINTS
772
773 // backward compatibility
774 // ----------------------
775 #if WXWIN_COMPATIBILITY
776 bool Enabled() const { return IsEnabled(); }
777
778 void SetButtonFont(const wxFont& font) { SetFont(font); }
779 void SetLabelFont(const wxFont& font) { SetFont(font); }
780 wxFont& GetLabelFont() { return GetFont(); };
781 wxFont& GetButtonFont() { return GetFont(); };
782 #endif // WXWIN_COMPATIBILITY
783
784 // implementation
785 // --------------
786
787 // event handlers
788 void OnSysColourChanged( wxSysColourChangedEvent& event );
789 void OnInitDialog( wxInitDialogEvent &event );
790 void OnMiddleClick( wxMouseEvent& event );
791 #if wxUSE_HELP
792 void OnHelp(wxHelpEvent& event);
793 #endif // wxUSE_HELP
794
795 // get the haqndle of the window for the underlying window system: this
796 // is only used for wxWin itself or for user code which wants to call
797 // platform-specific APIs
798 virtual WXWidget GetHandle() const = 0;
799
800 protected:
801 // the window id - a number which uniquely identifies a window among
802 // its siblings unless it is -1
803 wxWindowID m_windowId;
804
805 // the parent window of this window (or NULL) and the list of the children
806 // of this window
807 wxWindow *m_parent;
808 wxWindowList m_children;
809
810 // the minimal allowed size for the window (no minimal size if variable(s)
811 // contain(s) -1)
812 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
813
814 // event handler for this window: usually is just 'this' but may be
815 // changed with SetEventHandler()
816 wxEvtHandler *m_eventHandler;
817
818 #if wxUSE_VALIDATORS
819 // associated validator or NULL if none
820 wxValidator *m_windowValidator;
821 #endif // wxUSE_VALIDATORS
822
823 #if wxUSE_DRAG_AND_DROP
824 wxDropTarget *m_dropTarget;
825 #endif // wxUSE_DRAG_AND_DROP
826
827 // visual window attributes
828 wxCursor m_cursor;
829 wxFont m_font;
830 wxColour m_backgroundColour, m_foregroundColour;
831
832 #if wxUSE_CARET
833 wxCaret *m_caret;
834 #endif // wxUSE_CARET
835
836 // the region which should be repainted in response to paint event
837 wxRegion m_updateRegion;
838
839 #if wxUSE_ACCEL
840 // the accelerator table for the window which translates key strokes into
841 // command events
842 wxAcceleratorTable m_acceleratorTable;
843 #endif // wxUSE_ACCEL
844
845 // user data associated with the window: either an object which will be
846 // deleted by the window when it's deleted or some raw pointer which we do
847 // nothing with - only one type of data can be used with the given window
848 // (i.e. you cannot set the void data and then associate the window with
849 // wxClientData or vice versa)
850 union
851 {
852 wxClientData *m_clientObject;
853 void *m_clientData;
854 };
855
856 // the tooltip for this window (may be NULL)
857 #if wxUSE_TOOLTIPS
858 wxToolTip *m_tooltip;
859 #endif // wxUSE_TOOLTIPS
860
861 // constraints and sizers
862 #if wxUSE_CONSTRAINTS
863 // the constraints for this window or NULL
864 wxLayoutConstraints *m_constraints;
865
866 // constraints this window is involved in
867 wxWindowList *m_constraintsInvolvedIn;
868
869 // top level and the parent sizers
870 // TODO what's this and how does it work?)
871 wxSizer *m_windowSizer;
872 wxWindowBase *m_sizerParent;
873
874 // Layout() window automatically when its size changes?
875 bool m_autoLayout:1;
876 #endif // wxUSE_CONSTRAINTS
877
878 // window state
879 bool m_isShown:1;
880 bool m_isEnabled:1;
881 bool m_isBeingDeleted:1;
882
883 // window attributes
884 long m_windowStyle,
885 m_exStyle;
886 wxString m_windowName;
887 bool m_themeEnabled;
888
889 protected:
890 // common part of all ctors: it is not virtual because it is called from
891 // ctor
892 void InitBase();
893
894 // override this to change the default (i.e. used when no style is
895 // specified) border for the window class
896 virtual wxBorder GetDefaultBorder() const;
897
898 // get the default size for the new window if no explicit size given
899 // FIXME why 20 and not 30, 10 or ...?
900 static int WidthDefault(int w) { return w == -1 ? 20 : w; }
901 static int HeightDefault(int h) { return h == -1 ? 20 : h; }
902
903 // set the best size for the control if the default size was given:
904 // replaces the fields of size == -1 with the best values for them and
905 // calls SetSize() if needed
906 void SetBestSize(const wxSize& size)
907 {
908 if ( size.x == -1 || size.y == -1 )
909 {
910 wxSize sizeBest = DoGetBestSize();
911 if ( size.x != -1 )
912 sizeBest.x = size.x;
913 if ( size.y != -1 )
914 sizeBest.y = size.y;
915
916 SetSize(sizeBest);
917 }
918 }
919
920 // more pure virtual functions
921 // ---------------------------
922
923 // NB: we must have DoSomething() function when Something() is an overloaded
924 // method: indeed, we can't just have "virtual Something()" in case when
925 // the function is overloaded because then we'd have to make virtual all
926 // the variants (otherwise only the virtual function may be called on a
927 // pointer to derived class according to C++ rules) which is, in
928 // general, absolutely not needed. So instead we implement all
929 // overloaded Something()s in terms of DoSomething() which will be the
930 // only one to be virtual.
931
932 // coordinates translation
933 virtual void DoClientToScreen( int *x, int *y ) const = 0;
934 virtual void DoScreenToClient( int *x, int *y ) const = 0;
935
936 virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
937
938 // retrieve the position/size of the window
939 virtual void DoGetPosition( int *x, int *y ) const = 0;
940 virtual void DoGetSize( int *width, int *height ) const = 0;
941 virtual void DoGetClientSize( int *width, int *height ) const = 0;
942
943 // get the size which best suits the window: for a control, it would be
944 // the minimal size which doesn't truncate the control, for a panel - the
945 // same size as it would have after a call to Fit()
946 virtual wxSize DoGetBestSize() const;
947
948 // this is the virtual function to be overriden in any derived class which
949 // wants to change how SetSize() or Move() works - it is called by all
950 // versions of these functions in the base class
951 virtual void DoSetSize(int x, int y,
952 int width, int height,
953 int sizeFlags = wxSIZE_AUTO) = 0;
954
955 // same as DoSetSize() for the client size
956 virtual void DoSetClientSize(int width, int height) = 0;
957
958 // move the window to the specified location and resize it: this is called
959 // from both DoSetSize() and DoSetClientSize() and would usually just
960 // reposition this window except for composite controls which will want to
961 // arrange themselves inside the given rectangle
962 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
963
964 #if wxUSE_TOOLTIPS
965 virtual void DoSetToolTip( wxToolTip *tip );
966 #endif // wxUSE_TOOLTIPS
967
968 #if wxUSE_MENUS
969 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
970 #endif // wxUSE_MENUS
971
972 // client data accessors
973 virtual void DoSetClientObject( wxClientData *data );
974 virtual wxClientData *DoGetClientObject() const;
975
976 virtual void DoSetClientData( void *data );
977 virtual void *DoGetClientData() const;
978
979 // Makes an adjustment to the window position (for example, a frame that has
980 // a toolbar that it manages itself).
981 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
982
983 // what kind of data do we have?
984 wxClientDataType m_clientDataType;
985
986 private:
987 // contains the last id generated by NewControlId
988 static int ms_lastControlId;
989
990 DECLARE_ABSTRACT_CLASS(wxWindowBase)
991 DECLARE_NO_COPY_CLASS(wxWindowBase)
992 DECLARE_EVENT_TABLE()
993 };
994
995 // ----------------------------------------------------------------------------
996 // now include the declaration of wxWindow class
997 // ----------------------------------------------------------------------------
998
999 // include the declaration of the platform-specific class
1000 #if defined(__WXMSW__)
1001 #ifdef __WXUNIVERSAL__
1002 #define wxWindowNative wxWindowMSW
1003 #else // !wxUniv
1004 #define wxWindowMSW wxWindow
1005 #define sm_classwxWindowMSW sm_classwxWindow
1006 #endif // wxUniv/!wxUniv
1007 #include "wx/msw/window.h"
1008 #elif defined(__WXMOTIF__)
1009 #include "wx/motif/window.h"
1010 #elif defined(__WXGTK__)
1011 #ifdef __WXUNIVERSAL__
1012 #define wxWindowNative wxWindowGTK
1013 #else // !wxUniv
1014 #define wxWindowGTK wxWindow
1015 #define sm_classwxWindowGTK sm_classwxWindow
1016 #endif // wxUniv
1017 #include "wx/gtk/window.h"
1018 #elif defined(__WXMGL__)
1019 #ifdef __WXUNIVERSAL__
1020 #define wxWindowNative wxWindowMGL
1021 #else // !wxUniv
1022 #define wxWindowMGL wxWindow
1023 #define sm_classwxWindowMGL sm_classwxWindow
1024 #endif // wxUniv
1025 #include "wx/mgl/window.h"
1026 #elif defined(__WXMAC__)
1027 #ifdef __WXUNIVERSAL__
1028 #define wxWindowNative wxWindowMac
1029 #else // !wxUniv
1030 #define wxWindowMac wxWindow
1031 #define sm_classwxWindowMac sm_classwxWindow
1032 #endif // wxUniv
1033 #include "wx/mac/window.h"
1034 #elif defined(__WXPM__)
1035 #ifdef __WXUNIVERSAL__
1036 #define wxWindowNative wxWindowOS2
1037 #else // !wxUniv
1038 #define wxWindowOS2 wxWindow
1039 #define sm_classwxWindowOS2 sm_classwxWindow
1040 #endif // wxUniv/!wxUniv
1041 #include "wx/os2/window.h"
1042 #endif
1043
1044 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1045 // for the native ports we already have defined it above
1046 #if defined(__WXUNIVERSAL__)
1047 #ifndef wxWindowNative
1048 #error "wxWindowNative must be defined above!"
1049 #endif
1050
1051 #include "wx/univ/window.h"
1052 #endif // wxUniv
1053
1054 // ----------------------------------------------------------------------------
1055 // inline functions which couldn't be declared in the class body because of
1056 // forward dependencies
1057 // ----------------------------------------------------------------------------
1058
1059 inline wxWindow *wxWindowBase::GetGrandParent() const
1060 {
1061 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
1062 }
1063
1064 // ----------------------------------------------------------------------------
1065 // global functions
1066 // ----------------------------------------------------------------------------
1067
1068 // Find the wxWindow at the current mouse position, also returning the mouse
1069 // position.
1070 WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt);
1071
1072 // Get the current mouse position.
1073 WXDLLEXPORT extern wxPoint wxGetMousePosition();
1074
1075 // get the currently active window of this application or NULL
1076 WXDLLEXPORT extern wxWindow *wxGetActiveWindow();
1077
1078 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1079 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1080
1081 #endif
1082 // _WX_WINDOW_H_BASE_