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