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