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