]>
Commit | Line | Data |
---|---|---|
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 | |
8d99be5f VZ |
33 | #if wxUSE_VALIDATORS |
34 | #include "wx/validate.h" // defines wxDefaultValidator | |
35 | #endif // wxUSE_VALIDATORS | |
36 | ||
88ac883a VZ |
37 | #if wxUSE_ACCEL |
38 | #include "wx/accel.h" | |
39 | #endif // wxUSE_ACCEL | |
f03fc89f VZ |
40 | |
41 | // ---------------------------------------------------------------------------- | |
42 | // forward declarations | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
789295bf | 45 | class WXDLLEXPORT wxCaret; |
f03fc89f VZ |
46 | class WXDLLEXPORT wxClientData; |
47 | class WXDLLEXPORT wxControl; | |
48 | class WXDLLEXPORT wxCursor; | |
eb082a08 | 49 | class WXDLLEXPORT wxDC; |
f03fc89f VZ |
50 | class WXDLLEXPORT wxDropTarget; |
51 | class WXDLLEXPORT wxItemResource; | |
52 | class WXDLLEXPORT wxLayoutConstraints; | |
53 | class WXDLLEXPORT wxResourceTable; | |
54 | class WXDLLEXPORT wxSizer; | |
55 | class WXDLLEXPORT wxToolTip; | |
f03fc89f VZ |
56 | class WXDLLEXPORT wxWindowBase; |
57 | class WXDLLEXPORT wxWindow; | |
58 | ||
59 | // ---------------------------------------------------------------------------- | |
60 | // (pseudo)template list classes | |
61 | // ---------------------------------------------------------------------------- | |
62 | ||
63 | WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode); | |
64 | ||
65 | // ---------------------------------------------------------------------------- | |
66 | // global variables | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
69 | WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows; | |
70 | ||
71 | // ---------------------------------------------------------------------------- | |
72 | // helper classes used by [SG]etClientObject/Data | |
73 | // | |
74 | // TODO move into a separate header? | |
75 | // ---------------------------------------------------------------------------- | |
76 | ||
77 | class wxClientData | |
78 | { | |
79 | public: | |
80 | wxClientData() { } | |
81 | virtual ~wxClientData() { } | |
82 | }; | |
83 | ||
84 | class wxStringClientData : public wxClientData | |
85 | { | |
86 | public: | |
87 | wxStringClientData() { } | |
88 | wxStringClientData( const wxString &data ) : m_data(data) { } | |
89 | void SetData( const wxString &data ) { m_data = data; } | |
90 | const wxString& GetData() const { return m_data; } | |
91 | ||
92 | private: | |
93 | wxString m_data; | |
94 | }; | |
95 | ||
96 | // ---------------------------------------------------------------------------- | |
97 | // wxWindowBase is the base class for all GUI controls/widgets, this is the public | |
98 | // interface of this class. | |
99 | // | |
100 | // Event handler: windows have themselves as their event handlers by default, | |
101 | // but their event handlers could be set to another object entirely. This | |
102 | // separation can reduce the amount of derivation required, and allow | |
103 | // alteration of a window's functionality (e.g. by a resource editor that | |
104 | // temporarily switches event handlers). | |
105 | // ---------------------------------------------------------------------------- | |
106 | ||
107 | class WXDLLEXPORT wxWindowBase : public wxEvtHandler | |
108 | { | |
109 | DECLARE_ABSTRACT_CLASS(wxWindowBase); | |
110 | ||
111 | public: | |
112 | // creating the window | |
113 | // ------------------- | |
114 | ||
115 | // default ctor | |
116 | wxWindowBase() { InitBase(); } | |
117 | ||
118 | // pseudo ctor (can't be virtual, called from ctor) | |
119 | bool CreateBase(wxWindowBase *parent, | |
120 | wxWindowID id, | |
121 | const wxPoint& pos = wxDefaultPosition, | |
122 | const wxSize& size = wxDefaultSize, | |
123 | long style = 0, | |
8d99be5f | 124 | #if wxUSE_VALIDATORS |
57c4d796 DW |
125 | # if defined(__VISAGECPP__) |
126 | const wxValidator* validator = wxDefaultValidator, | |
127 | # else | |
8d99be5f | 128 | const wxValidator& validator = wxDefaultValidator, |
57c4d796 | 129 | # endif |
8d99be5f | 130 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
131 | const wxString& name = wxPanelNameStr); |
132 | ||
133 | virtual ~wxWindowBase(); | |
134 | ||
135 | #if wxUSE_WX_RESOURCES | |
136 | // these functions are implemented in resource.cpp and resourc2.cpp | |
137 | virtual bool LoadFromResource(wxWindow *parent, | |
138 | const wxString& resourceName, | |
139 | const wxResourceTable *table = (const wxResourceTable *) NULL); | |
140 | virtual wxControl *CreateItem(const wxItemResource* childResource, | |
141 | const wxItemResource* parentResource, | |
142 | const wxResourceTable *table = (const wxResourceTable *) NULL); | |
143 | #endif // wxUSE_WX_RESOURCES | |
144 | ||
145 | // deleting the window | |
146 | // ------------------- | |
147 | ||
148 | // ask the window to close itself, return TRUE if the event handler | |
149 | // honoured our request | |
150 | bool Close( bool force = FALSE ); | |
151 | ||
152 | // the following functions delete the C++ objects (the window itself | |
153 | // or its children) as well as the GUI windows and normally should | |
154 | // never be used directly | |
155 | ||
156 | // delete window unconditionally (dangerous!), returns TRUE if ok | |
157 | virtual bool Destroy(); | |
158 | // delete all children of this window, returns TRUE if ok | |
159 | bool DestroyChildren(); | |
160 | ||
161 | // is the window being deleted? | |
162 | bool IsBeingDeleted() const { return m_isBeingDeleted; } | |
163 | ||
164 | // window attributes | |
165 | // ----------------- | |
166 | ||
167 | // the title (or label, see below) of the window: the text which the | |
168 | // window shows | |
169 | virtual void SetTitle( const wxString & WXUNUSED(title) ) { } | |
170 | virtual wxString GetTitle() const { return ""; } | |
171 | ||
172 | // label is just the same as the title (but for, e.g., buttons it | |
173 | // makes more sense to speak about labels) | |
eba0e4d4 RR |
174 | virtual void SetLabel(const wxString& label) { SetTitle(label); } |
175 | virtual wxString GetLabel() const { return GetTitle(); } | |
f03fc89f VZ |
176 | |
177 | // the window name is used for ressource setting in X, it is not the | |
178 | // same as the window title/label | |
179 | virtual void SetName( const wxString &name ) { m_windowName = name; } | |
180 | virtual wxString GetName() const { return m_windowName; } | |
181 | ||
182 | // window id uniquely identifies the window among its siblings unless | |
183 | // it is -1 which means "don't care" | |
184 | void SetId( wxWindowID id ) { m_windowId = id; } | |
185 | wxWindowID GetId() const { return m_windowId; } | |
186 | ||
187 | // generate a control id for the controls which were not given one by | |
188 | // user | |
69418a8e | 189 | static int NewControlId() { return --ms_lastControlId; } |
c539ab55 VZ |
190 | // get the id of the control following the one with the given |
191 | // (autogenerated) id | |
192 | static int NextControlId(int id) { return id - 1; } | |
193 | // get the id of the control preceding the one with the given | |
194 | // (autogenerated) id | |
195 | static int PrevControlId(int id) { return id + 1; } | |
f03fc89f VZ |
196 | |
197 | // moving/resizing | |
198 | // --------------- | |
199 | ||
200 | // set the window size and/or position | |
201 | void SetSize( int x, int y, int width, int height, | |
202 | int sizeFlags = wxSIZE_AUTO ) | |
203 | { DoSetSize(x, y, width, height, sizeFlags); } | |
204 | ||
205 | void SetSize( int width, int height ) | |
206 | { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); } | |
207 | ||
208 | void SetSize( const wxSize& size ) | |
209 | { SetSize( size.x, size.y); } | |
210 | ||
211 | void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO) | |
212 | { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); } | |
213 | ||
214 | void Move( int x, int y ) | |
215 | { DoSetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); } | |
216 | ||
217 | void Move(const wxPoint& pt) | |
218 | { Move(pt.x, pt.y); } | |
219 | ||
220 | // Z-order | |
221 | virtual void Raise() = 0; | |
222 | virtual void Lower() = 0; | |
223 | ||
224 | // client size is the size of area available for subwindows | |
225 | void SetClientSize( int width, int height ) | |
226 | { DoSetClientSize(width, height); } | |
227 | ||
228 | void SetClientSize( const wxSize& size ) | |
229 | { DoSetClientSize(size.x, size.y); } | |
230 | ||
231 | void SetClientSize(const wxRect& rect) | |
232 | { SetClientSize( rect.width, rect.height ); } | |
233 | ||
234 | // get the window position and/or size (pointers may be NULL) | |
235 | void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); } | |
236 | wxPoint GetPosition() const | |
237 | { | |
238 | int w, h; | |
239 | DoGetPosition(&w, &h); | |
240 | ||
241 | return wxPoint(w, h); | |
242 | } | |
243 | ||
244 | void GetSize( int *w, int *h ) const { DoGetSize(w, h); } | |
245 | wxSize GetSize() const | |
246 | { | |
247 | int w, h; | |
248 | DoGetSize(& w, & h); | |
249 | return wxSize(w, h); | |
250 | } | |
251 | ||
252 | wxRect GetRect() const | |
253 | { | |
254 | int x, y, w, h; | |
255 | GetPosition(& x, & y); | |
256 | GetSize(& w, & h); | |
257 | ||
258 | return wxRect(x, y, w, h); | |
259 | } | |
260 | ||
261 | void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); } | |
262 | wxSize GetClientSize() const | |
263 | { | |
264 | int w, h; | |
265 | DoGetClientSize(& w, & h); | |
266 | ||
267 | return wxSize(w, h); | |
268 | } | |
269 | ||
270 | // centre with respect to the the parent window | |
c39eda94 VZ |
271 | void Centre( int direction = wxBOTH ); |
272 | void Center( int direction = wxBOTH ) { Centre(direction); } | |
273 | void CentreOnParent( int dir = wxBOTH ) { Centre(dir | wxCENTER_FRAME); } | |
274 | void CenterOnParent( int dir = wxBOTH ) { Centre(dir | wxCENTER_FRAME); } | |
f03fc89f VZ |
275 | |
276 | // set window size to wrap around its children | |
277 | virtual void Fit(); | |
278 | ||
279 | // set min/max size of the window | |
280 | virtual void SetSizeHints( int minW, int minH, | |
281 | int maxW = -1, int maxH = -1, | |
282 | int incW = -1, int incH = -1 ); | |
283 | ||
738f9e5a RR |
284 | int GetMinWidth() const { return m_minWidth; } |
285 | int GetMinHeight() const { return m_minHeight; } | |
286 | int GetMaxWidth() const { return m_maxWidth; } | |
287 | int GetMaxHeight() const { return m_maxHeight; } | |
57c4d796 | 288 | |
f03fc89f VZ |
289 | // window state |
290 | // ------------ | |
291 | ||
292 | // returns TRUE if window was shown/hidden, FALSE if the nothing was | |
293 | // done (window was already shown/hidden) | |
294 | virtual bool Show( bool show = TRUE ); | |
295 | bool Hide() { return Show(FALSE); } | |
296 | ||
297 | // returns TRUE if window was enabled/disabled, FALSE if nothing done | |
298 | virtual bool Enable( bool enable = TRUE ); | |
299 | bool Disable() { return Enable(FALSE); } | |
300 | ||
301 | bool IsShown() const { return m_isShown; } | |
302 | bool IsEnabled() const { return m_isEnabled; } | |
303 | ||
304 | // get/set window style (setting style won't update the window and so | |
305 | // is only useful for internal usage) | |
306 | virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; } | |
307 | virtual long GetWindowStyleFlag() const { return m_windowStyle; } | |
308 | ||
309 | // just some (somewhat shorter) synonims | |
310 | void SetWindowStyle( long style ) { SetWindowStyleFlag(style); } | |
311 | long GetWindowStyle() const { return GetWindowStyleFlag(); } | |
312 | ||
313 | bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; } | |
314 | ||
315 | virtual bool IsRetained() const | |
316 | { return (m_windowStyle & wxRETAINED) != 0; } | |
317 | ||
318 | // make the window modal (all other windows unresponsive) | |
319 | virtual void MakeModal(bool modal = TRUE); | |
320 | ||
321 | // focus handling | |
322 | // -------------- | |
323 | ||
324 | // set focus to this window | |
325 | virtual void SetFocus() = 0; | |
326 | ||
327 | // return the window which currently has the focus or NULL | |
328 | static wxWindow *FindFocus() /* = 0: implement in derived classes */; | |
329 | ||
330 | // can this window have focus? | |
331 | virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); } | |
332 | ||
333 | // parent/children relations | |
334 | // ------------------------- | |
335 | ||
336 | // get the list of children | |
337 | const wxWindowList& GetChildren() const { return m_children; } | |
338 | wxWindowList& GetChildren() { return m_children; } | |
339 | ||
340 | // get the parent or the parent of the parent | |
341 | wxWindow *GetParent() const { return m_parent; } | |
342 | inline wxWindow *GetGrandParent() const; | |
343 | ||
344 | // is this window a top level one? | |
8487f887 | 345 | virtual bool IsTopLevel() const; |
f03fc89f VZ |
346 | |
347 | // it doesn't really change parent, use ReParent() instead | |
348 | void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; } | |
349 | // change the real parent of this window, return TRUE if the parent | |
350 | // was changed, FALSE otherwise (error or newParent == oldParent) | |
351 | virtual bool Reparent( wxWindowBase *newParent ); | |
352 | ||
353 | // find window among the descendants of this one either by id or by | |
354 | // name (return NULL if not found) | |
355 | wxWindow *FindWindow( long id ); | |
356 | wxWindow *FindWindow( const wxString& name ); | |
357 | ||
358 | // implementation mostly | |
359 | virtual void AddChild( wxWindowBase *child ); | |
360 | virtual void RemoveChild( wxWindowBase *child ); | |
361 | ||
362 | // event handler stuff | |
363 | // ------------------- | |
364 | ||
365 | // get the current event handler | |
366 | wxEvtHandler *GetEventHandler() const { return m_eventHandler; } | |
367 | ||
368 | // replace the event handler (allows to completely subclass the | |
369 | // window) | |
370 | void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; } | |
371 | ||
372 | // push/pop event handler: allows to chain a custom event handler to | |
373 | // alreasy existing ones | |
374 | void PushEventHandler( wxEvtHandler *handler ); | |
375 | wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE ); | |
376 | ||
377 | // validators and client data | |
378 | // -------------------------- | |
379 | ||
88ac883a | 380 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
381 | // a window may have an associated validator which is used to control |
382 | // user input | |
57c4d796 DW |
383 | # if defined(__VISAGECPP__) |
384 | virtual void SetValidator( const wxValidator *validator ); | |
385 | # else | |
f03fc89f | 386 | virtual void SetValidator( const wxValidator &validator ); |
57c4d796 | 387 | # endif |
f03fc89f | 388 | virtual wxValidator *GetValidator() { return m_windowValidator; } |
88ac883a | 389 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
390 | |
391 | // each window may have associated client data: either a pointer to | |
392 | // wxClientData object in which case it is managed by the window (i.e. | |
393 | // it will delete the data when it's destroyed) or an untyped pointer | |
8d99be5f VZ |
394 | // which won't be deleted by the window - but not both of them |
395 | void SetClientObject( wxClientData *data ) { DoSetClientObject(data); } | |
396 | wxClientData *GetClientObject() const { return DoGetClientObject(); } | |
f03fc89f | 397 | |
8d99be5f VZ |
398 | void SetClientData( void *data ) { DoSetClientData(data); } |
399 | void *GetClientData() const { return DoGetClientData(); } | |
f03fc89f VZ |
400 | |
401 | // dialog oriented functions | |
402 | // ------------------------- | |
403 | ||
404 | // validate the correctness of input, return TRUE if ok | |
405 | virtual bool Validate(); | |
406 | ||
407 | // transfer data between internal and GUI representations | |
408 | virtual bool TransferDataToWindow(); | |
409 | virtual bool TransferDataFromWindow(); | |
410 | ||
411 | virtual void InitDialog(); | |
412 | ||
88ac883a | 413 | #if wxUSE_ACCEL |
f03fc89f VZ |
414 | // accelerators |
415 | // ------------ | |
416 | virtual void SetAcceleratorTable( const wxAcceleratorTable& accel ) | |
417 | { m_acceleratorTable = accel; } | |
418 | wxAcceleratorTable *GetAcceleratorTable() | |
419 | { return &m_acceleratorTable; } | |
88ac883a | 420 | #endif // wxUSE_ACCEL |
f03fc89f VZ |
421 | |
422 | // dialog units translations | |
423 | // ------------------------- | |
424 | ||
425 | wxPoint ConvertPixelsToDialog( const wxPoint& pt ); | |
426 | wxPoint ConvertDialogToPixels( const wxPoint& pt ); | |
427 | wxSize ConvertPixelsToDialog( const wxSize& sz ) | |
428 | { | |
429 | wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); | |
430 | ||
431 | return wxSize(pt.x, pt.y); | |
432 | } | |
433 | ||
434 | wxSize ConvertDialogToPixels( const wxSize& sz ) | |
435 | { | |
436 | wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); | |
437 | ||
438 | return wxSize(pt.x, pt.y); | |
439 | } | |
440 | ||
441 | // mouse functions | |
442 | // --------------- | |
443 | ||
444 | // move the mouse to the specified position | |
445 | virtual void WarpPointer(int x, int y) = 0; | |
446 | ||
447 | // start or end mouse capture | |
448 | virtual void CaptureMouse() = 0; | |
449 | virtual void ReleaseMouse() = 0; | |
450 | ||
451 | // painting the window | |
452 | // ------------------- | |
453 | ||
454 | // mark the specified rectangle (or the whole window) as "dirty" so it | |
455 | // will be repainted | |
456 | virtual void Refresh( bool eraseBackground = TRUE, | |
457 | const wxRect *rect = (const wxRect *) NULL ) = 0; | |
458 | // clear the window entirely | |
459 | virtual void Clear() = 0; | |
460 | ||
461 | // adjust DC for drawing on this window | |
f6147cfc | 462 | virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { } |
f03fc89f VZ |
463 | |
464 | // the update region of the window contains the areas which must be | |
465 | // repainted by the program | |
466 | const wxRegion& GetUpdateRegion() const { return m_updateRegion; } | |
467 | wxRegion& GetUpdateRegion() { return m_updateRegion; } | |
468 | ||
469 | // these functions verify whether the given point/rectangle belongs to | |
470 | // (or at least intersects with) the update region | |
471 | bool IsExposed( int x, int y ) const; | |
472 | bool IsExposed( int x, int y, int w, int h ) const; | |
473 | ||
474 | bool IsExposed( const wxPoint& pt ) const | |
475 | { return IsExposed(pt.x, pt.y); } | |
476 | bool IsExposed( const wxRect& rect ) const | |
477 | { return IsExposed(rect.x, rect.y, rect.width, rect.height); } | |
478 | ||
479 | // colours, fonts and cursors | |
480 | // -------------------------- | |
481 | ||
482 | // set/retrieve the window colours (system defaults are used by | |
483 | // default): Set functions return TRUE if colour was changed | |
484 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
485 | virtual bool SetForegroundColour( const wxColour &colour ); | |
486 | ||
487 | wxColour GetBackgroundColour() const { return m_backgroundColour; } | |
488 | wxColour GetForegroundColour() const { return m_foregroundColour; } | |
489 | ||
490 | // set/retrieve the cursor for this window (SetCursor() returns TRUE | |
491 | // if the cursor was really changed) | |
492 | virtual bool SetCursor( const wxCursor &cursor ); | |
493 | const wxCursor& GetCursor() const { return m_cursor; } | |
494 | wxCursor& GetCursor() { return m_cursor; } | |
495 | ||
496 | // set/retrieve the font for the window (SetFont() returns TRUE if the | |
497 | // font really changed) | |
498 | virtual bool SetFont( const wxFont &font ) = 0; | |
499 | const wxFont& GetFont() const { return m_font; } | |
500 | wxFont& GetFont() { return m_font; } | |
501 | ||
789295bf VZ |
502 | #if wxUSE_CARET |
503 | // associate a caret with the window | |
504 | void SetCaret(wxCaret *caret); | |
505 | // get the current caret (may be NULL) | |
506 | wxCaret *GetCaret() const { return m_caret; } | |
507 | #endif // wxUSE_CARET | |
508 | ||
f03fc89f VZ |
509 | // get the (average) character size for the current font |
510 | virtual int GetCharHeight() const = 0; | |
511 | virtual int GetCharWidth() const = 0; | |
512 | ||
513 | // get the width/height/... of the text using current or specified | |
514 | // font | |
515 | virtual void GetTextExtent(const wxString& string, | |
516 | int *x, int *y, | |
517 | int *descent = (int *) NULL, | |
518 | int *externalLeading = (int *) NULL, | |
519 | const wxFont *theFont = (const wxFont *) NULL) | |
520 | const = 0; | |
521 | ||
522 | // translate to/from screen/client coordinates (pointers may be NULL) | |
dabc0cd5 VZ |
523 | void ClientToScreen( int *x, int *y ) const |
524 | { DoClientToScreen(x, y); } | |
525 | void ScreenToClient( int *x, int *y ) const | |
526 | { DoScreenToClient(x, y); } | |
527 | wxPoint ClientToScreen(const wxPoint& pt) const | |
528 | { | |
529 | int x = pt.x, y = pt.y; | |
530 | DoClientToScreen(&x, &y); | |
531 | ||
532 | return wxPoint(x, y); | |
533 | } | |
534 | ||
535 | wxPoint ScreenToClient(const wxPoint& pt) const | |
536 | { | |
537 | int x = pt.x, y = pt.y; | |
538 | DoScreenToClient(&x, &y); | |
539 | ||
540 | return wxPoint(x, y); | |
541 | } | |
f03fc89f VZ |
542 | |
543 | // misc | |
544 | // ---- | |
545 | ||
546 | void UpdateWindowUI(); | |
547 | ||
a1665b22 VZ |
548 | bool PopupMenu( wxMenu *menu, const wxPoint& pos ) |
549 | { return DoPopupMenu(menu, pos.x, pos.y); } | |
550 | bool PopupMenu( wxMenu *menu, int x, int y ) | |
551 | { return DoPopupMenu(menu, x, y); } | |
f03fc89f VZ |
552 | |
553 | // scrollbars | |
554 | // ---------- | |
555 | ||
556 | // configure the window scrollbars | |
557 | virtual void SetScrollbar( int orient, | |
558 | int pos, | |
559 | int thumbVisible, | |
560 | int range, | |
561 | bool refresh = TRUE ) = 0; | |
562 | virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0; | |
563 | virtual int GetScrollPos( int orient ) const = 0; | |
564 | virtual int GetScrollThumb( int orient ) const = 0; | |
565 | virtual int GetScrollRange( int orient ) const = 0; | |
566 | ||
567 | // scroll window to the specified position | |
568 | virtual void ScrollWindow( int dx, int dy, | |
569 | const wxRect* rect = (wxRect *) NULL ) = 0; | |
570 | ||
571 | // tooltips | |
572 | // -------- | |
573 | #if wxUSE_TOOLTIPS | |
574 | // the easiest way to set a tooltip for a window is to use this method | |
575 | void SetToolTip( const wxString &tip ); | |
576 | // attach a tooltip to the window | |
577 | void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); } | |
578 | // get the associated tooltip or NULL if none | |
579 | wxToolTip* GetToolTip() const { return m_tooltip; } | |
580 | #endif // wxUSE_TOOLTIPS | |
581 | ||
582 | // drag and drop | |
583 | // ------------- | |
584 | #if wxUSE_DRAG_AND_DROP | |
585 | // set/retrieve the drop target associated with this window (may be | |
586 | // NULL; it's owned by the window and will be deleted by it) | |
587 | virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0; | |
588 | virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; } | |
589 | #endif // wxUSE_DRAG_AND_DROP | |
590 | ||
591 | // constraints and sizers | |
592 | // ---------------------- | |
593 | #if wxUSE_CONSTRAINTS | |
594 | // set the constraints for this window or retrieve them (may be NULL) | |
595 | void SetConstraints( wxLayoutConstraints *constraints ); | |
596 | wxLayoutConstraints *GetConstraints() const { return m_constraints; } | |
597 | ||
598 | // when using constraints, it makes sense to update children positions | |
599 | // automatically whenever the window is resized - this is done if | |
600 | // autoLayout is on | |
601 | void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; } | |
602 | bool GetAutoLayout() const { return m_autoLayout; } | |
603 | ||
604 | // do layout the window and its children | |
605 | virtual bool Layout(); | |
606 | ||
607 | // implementation only | |
608 | void UnsetConstraints(wxLayoutConstraints *c); | |
609 | wxWindowList *GetConstraintsInvolvedIn() const | |
610 | { return m_constraintsInvolvedIn; } | |
611 | void AddConstraintReference(wxWindowBase *otherWin); | |
612 | void RemoveConstraintReference(wxWindowBase *otherWin); | |
613 | void DeleteRelatedConstraints(); | |
614 | void ResetConstraints(); | |
615 | ||
616 | // these methods may be overriden for special layout algorithms | |
617 | virtual void SetConstraintSizes(bool recurse = TRUE); | |
618 | virtual bool LayoutPhase1(int *noChanges); | |
619 | virtual bool LayoutPhase2(int *noChanges); | |
620 | virtual bool DoPhase(int); | |
621 | ||
622 | // these methods are virtual but normally won't be overridden | |
f03fc89f VZ |
623 | virtual void SetSizeConstraint(int x, int y, int w, int h); |
624 | virtual void MoveConstraint(int x, int y); | |
625 | virtual void GetSizeConstraint(int *w, int *h) const ; | |
626 | virtual void GetClientSizeConstraint(int *w, int *h) const ; | |
627 | virtual void GetPositionConstraint(int *x, int *y) const ; | |
628 | ||
629 | // sizers | |
630 | // TODO: what are they and how do they work?? | |
631 | void SetSizer( wxSizer *sizer ); | |
632 | wxSizer *GetSizer() const { return m_windowSizer; } | |
f03fc89f VZ |
633 | #endif // wxUSE_CONSTRAINTS |
634 | ||
635 | // backward compatibility | |
636 | // ---------------------- | |
637 | #if WXWIN_COMPATIBILITY | |
638 | bool Enabled() const { return IsEnabled(); } | |
639 | ||
640 | void SetButtonFont(const wxFont& font) { SetFont(font); } | |
641 | void SetLabelFont(const wxFont& font) { SetFont(font); } | |
642 | wxFont& GetLabelFont() { return GetFont(); }; | |
643 | wxFont& GetButtonFont() { return GetFont(); }; | |
644 | #endif // WXWIN_COMPATIBILITY | |
645 | ||
646 | // implementation | |
647 | // -------------- | |
648 | ||
649 | // event handlers | |
650 | void OnSysColourChanged( wxSysColourChangedEvent& event ); | |
651 | void OnInitDialog( wxInitDialogEvent &event ); | |
652 | ||
d7c24517 VZ |
653 | // get the haqndle of the window for the underlying window system: this |
654 | // is only used for wxWin itself or for user code which wants to call | |
655 | // platform-specific APIs | |
d22699b5 | 656 | virtual WXWidget GetHandle() const = 0; |
cc2b7472 | 657 | |
739730ca | 658 | protected: |
7af6f327 | 659 | // the window id - a number which uniquely identifies a window among |
d7c24517 | 660 | // its siblings unless it is -1 |
f03fc89f VZ |
661 | wxWindowID m_windowId; |
662 | ||
663 | // the parent window of this window (or NULL) and the list of the children | |
664 | // of this window | |
665 | wxWindow *m_parent; | |
666 | wxWindowList m_children; | |
667 | ||
668 | // the minimal allowed size for the window (no minimal size if variable(s) | |
669 | // contain(s) -1) | |
670 | int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight; | |
671 | ||
672 | // event handler for this window: usually is just 'this' but may be | |
673 | // changed with SetEventHandler() | |
674 | wxEvtHandler *m_eventHandler; | |
675 | ||
88ac883a | 676 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
677 | // associated validator or NULL if none |
678 | wxValidator *m_windowValidator; | |
88ac883a | 679 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
680 | |
681 | #if wxUSE_DRAG_AND_DROP | |
682 | wxDropTarget *m_dropTarget; | |
683 | #endif // wxUSE_DRAG_AND_DROP | |
684 | ||
685 | // visual window attributes | |
686 | wxCursor m_cursor; | |
687 | wxFont m_font; | |
688 | wxColour m_backgroundColour, m_foregroundColour; | |
689 | ||
789295bf VZ |
690 | #if wxUSE_CARET |
691 | wxCaret *m_caret; | |
692 | #endif // wxUSE_CARET | |
693 | ||
f03fc89f VZ |
694 | // the region which should be repainted in response to paint event |
695 | wxRegion m_updateRegion; | |
696 | ||
88ac883a | 697 | #if wxUSE_ACCEL |
f03fc89f VZ |
698 | // the accelerator table for the window which translates key strokes into |
699 | // command events | |
700 | wxAcceleratorTable m_acceleratorTable; | |
88ac883a | 701 | #endif // wxUSE_ACCEL |
f03fc89f VZ |
702 | |
703 | // user data associated with the window: either an object which will be | |
704 | // deleted by the window when it's deleted or some raw pointer which we do | |
8d99be5f VZ |
705 | // nothing with - only one type of data can be used with the given window |
706 | // (i.e. you cannot set the void data and then associate the window with | |
707 | // wxClientData or vice versa) | |
708 | union | |
709 | { | |
710 | wxClientData *m_clientObject; | |
711 | void *m_clientData; | |
712 | }; | |
f03fc89f VZ |
713 | |
714 | // the tooltip for this window (may be NULL) | |
715 | #if wxUSE_TOOLTIPS | |
716 | wxToolTip *m_tooltip; | |
717 | #endif // wxUSE_TOOLTIPS | |
718 | ||
719 | // constraints and sizers | |
720 | #if wxUSE_CONSTRAINTS | |
721 | // the constraints for this window or NULL | |
722 | wxLayoutConstraints *m_constraints; | |
723 | ||
724 | // constraints this window is involved in | |
725 | wxWindowList *m_constraintsInvolvedIn; | |
726 | ||
727 | // top level and the parent sizers | |
728 | // TODO what's this and how does it work?) | |
729 | wxSizer *m_windowSizer; | |
730 | wxWindowBase *m_sizerParent; | |
731 | ||
732 | // Layout() window automatically when its size changes? | |
733 | bool m_autoLayout:1; | |
734 | #endif // wxUSE_CONSTRAINTS | |
735 | ||
736 | // window state | |
737 | bool m_isShown:1; | |
738 | bool m_isEnabled:1; | |
739 | bool m_isBeingDeleted:1; | |
740 | ||
741 | // window attributes | |
742 | long m_windowStyle; | |
743 | wxString m_windowName; | |
744 | ||
745 | protected: | |
746 | // common part of all ctors: it is not virtual because it is called from | |
747 | // ctor | |
748 | void InitBase(); | |
749 | ||
750 | // get the default size for the new window if no explicit size given | |
751 | // FIXME why 20 and not 30, 10 or ...? | |
752 | static int WidthDefault(int w) { return w == -1 ? 20 : w; } | |
753 | static int HeightDefault(int h) { return h == -1 ? 20 : h; } | |
754 | ||
755 | // more pure virtual functions | |
756 | // --------------------------- | |
757 | ||
758 | // NB: we must have DoSomething() function when Something() is an overloaded | |
759 | // method: indeed, we can't just have "virtual Something()" in case when | |
760 | // the function is overloaded because then we'd have to make virtual all | |
761 | // the variants (otherwise only the virtual function may be called on a | |
762 | // pointer to derived class according to C++ rules) which is, in | |
763 | // general, absolutely not needed. So instead we implement all | |
764 | // overloaded Something()s in terms of DoSomething() which will be the | |
765 | // only one to be virtual. | |
766 | ||
dabc0cd5 VZ |
767 | // coordinates translation |
768 | virtual void DoClientToScreen( int *x, int *y ) const = 0; | |
769 | virtual void DoScreenToClient( int *x, int *y ) const = 0; | |
770 | ||
f03fc89f VZ |
771 | // retrieve the position/size of the window |
772 | virtual void DoGetPosition( int *x, int *y ) const = 0; | |
773 | virtual void DoGetSize( int *width, int *height ) const = 0; | |
774 | virtual void DoGetClientSize( int *width, int *height ) const = 0; | |
775 | ||
776 | // this is the virtual function to be overriden in any derived class which | |
777 | // wants to change how SetSize() or Move() works - it is called by all | |
778 | // versions of these functions in the base class | |
779 | virtual void DoSetSize(int x, int y, | |
780 | int width, int height, | |
781 | int sizeFlags = wxSIZE_AUTO) = 0; | |
782 | ||
783 | // same as DoSetSize() for the client size | |
784 | virtual void DoSetClientSize(int width, int height) = 0; | |
785 | ||
786 | #if wxUSE_TOOLTIPS | |
787 | virtual void DoSetToolTip( wxToolTip *tip ); | |
788 | #endif // wxUSE_TOOLTIPS | |
789 | ||
a1665b22 VZ |
790 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0; |
791 | ||
8d99be5f VZ |
792 | // client data accessors |
793 | virtual void DoSetClientObject( wxClientData *data ); | |
794 | virtual wxClientData *DoGetClientObject() const; | |
795 | ||
796 | virtual void DoSetClientData( void *data ); | |
797 | virtual void *DoGetClientData() const; | |
798 | ||
799 | // what kind of data do we have? | |
800 | enum wxClientDataType | |
801 | { | |
802 | ClientData_None, // we don't know yet because we don't have it at all | |
803 | ClientData_Object, // our client data is typed and we own it | |
804 | ClientData_Void // client data is untyped and we don't own it | |
805 | } m_clientDataType; | |
806 | ||
f03fc89f VZ |
807 | private: |
808 | // contains the last id generated by NewControlId | |
809 | static int ms_lastControlId; | |
810 | ||
a23fd0e1 | 811 | DECLARE_NO_COPY_CLASS(wxWindowBase); |
f03fc89f VZ |
812 | DECLARE_EVENT_TABLE() |
813 | }; | |
814 | ||
815 | // ---------------------------------------------------------------------------- | |
816 | // now include the declaration of wxWindow class | |
817 | // ---------------------------------------------------------------------------- | |
818 | ||
2049ba38 | 819 | #if defined(__WXMSW__) |
f03fc89f | 820 | #include "wx/msw/window.h" |
2049ba38 | 821 | #elif defined(__WXMOTIF__) |
f03fc89f | 822 | #include "wx/motif/window.h" |
2049ba38 | 823 | #elif defined(__WXGTK__) |
f03fc89f | 824 | #include "wx/gtk/window.h" |
b4e76e0d | 825 | #elif defined(__WXQT__) |
f03fc89f | 826 | #include "wx/qt/window.h" |
34138703 | 827 | #elif defined(__WXMAC__) |
f03fc89f | 828 | #include "wx/mac/window.h" |
1777b9bb DW |
829 | #elif defined(__WXPM__) |
830 | #include "wx/os2/window.h" | |
c801d85f KB |
831 | #endif |
832 | ||
f03fc89f VZ |
833 | // ---------------------------------------------------------------------------- |
834 | // inline functions which couldn't be declared in the class body because of | |
835 | // forward dependencies | |
836 | // ---------------------------------------------------------------------------- | |
837 | ||
bacd69f9 | 838 | inline wxWindow *wxWindowBase::GetGrandParent() const |
f03fc89f VZ |
839 | { |
840 | return m_parent ? m_parent->GetParent() : (wxWindow *)NULL; | |
841 | } | |
842 | ||
843 | // ---------------------------------------------------------------------------- | |
844 | // global function | |
845 | // ---------------------------------------------------------------------------- | |
846 | ||
7af6f327 RD |
847 | WXDLLEXPORT extern wxWindow* wxGetActiveWindow(); |
848 | inline WXDLLEXPORT int NewControlId() { return wxWindowBase::NewControlId(); } | |
f03fc89f | 849 | |
c801d85f | 850 | #endif |
34138703 | 851 | // _WX_WINDOW_H_BASE_ |