]>
Commit | Line | Data |
---|---|---|
7ec1983b | 1 | ///////////////////////////////////////////////////////////////////////////// |
f03fc89f | 2 | // Name: common/window.cpp |
7ec1983b VZ |
3 | // Purpose: common (to all ports) wxWindow functions |
4 | // Author: Julian Smart, Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 13/07/98 | |
7 | // RCS-ID: $Id$ | |
f03fc89f | 8 | // Copyright: (c) wxWindows team |
7ec1983b VZ |
9 | // Licence: wxWindows license |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
f03fc89f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
f701d7ab | 19 | |
58654ed0 VZ |
20 | #ifdef __GNUG__ |
21 | #pragma implementation "windowbase.h" | |
22 | #endif | |
23 | ||
341287bf JS |
24 | // For compilers that support precompilation, includes "wx.h". |
25 | #include "wx/wxprec.h" | |
26 | ||
f701d7ab | 27 | #ifdef __BORLANDC__ |
f03fc89f | 28 | #pragma hdrstop |
f701d7ab JS |
29 | #endif |
30 | ||
f03fc89f VZ |
31 | #ifndef WX_PRECOMP |
32 | #include "wx/string.h" | |
33 | #include "wx/log.h" | |
34 | #include "wx/intl.h" | |
35 | #include "wx/frame.h" | |
36 | #include "wx/defs.h" | |
37 | #include "wx/window.h" | |
1e6feb95 | 38 | #include "wx/control.h" |
f03fc89f VZ |
39 | #include "wx/checkbox.h" |
40 | #include "wx/radiobut.h" | |
106844da | 41 | #include "wx/statbox.h" |
26bf1ce0 | 42 | #include "wx/textctrl.h" |
f03fc89f VZ |
43 | #include "wx/settings.h" |
44 | #include "wx/dialog.h" | |
a02dc3e3 | 45 | #include "wx/msgdlg.h" |
a37a5a73 | 46 | #include "wx/statusbr.h" |
ed39ff57 | 47 | #include "wx/dcclient.h" |
f03fc89f VZ |
48 | #endif //WX_PRECOMP |
49 | ||
50 | #if wxUSE_CONSTRAINTS | |
51 | #include "wx/layout.h" | |
52 | #endif // wxUSE_CONSTRAINTS | |
53 | ||
461e93f9 JS |
54 | #include "wx/sizer.h" |
55 | ||
f03fc89f VZ |
56 | #if wxUSE_DRAG_AND_DROP |
57 | #include "wx/dnd.h" | |
58 | #endif // wxUSE_DRAG_AND_DROP | |
59 | ||
bd83cb56 VZ |
60 | #if wxUSE_HELP |
61 | #include "wx/cshelp.h" | |
62 | #endif // wxUSE_HELP | |
63 | ||
f03fc89f VZ |
64 | #if wxUSE_TOOLTIPS |
65 | #include "wx/tooltip.h" | |
66 | #endif // wxUSE_TOOLTIPS | |
67 | ||
789295bf VZ |
68 | #if wxUSE_CARET |
69 | #include "wx/caret.h" | |
70 | #endif // wxUSE_CARET | |
71 | ||
f03fc89f VZ |
72 | // ---------------------------------------------------------------------------- |
73 | // static data | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
edd802c6 DW |
76 | #if defined(__WXPM__) |
77 | int wxWindowBase::ms_lastControlId = 2000; | |
78 | #else | |
42e69d6b | 79 | int wxWindowBase::ms_lastControlId = -200; |
edd802c6 | 80 | #endif |
f03fc89f VZ |
81 | |
82 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // event table | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
89 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
90 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
a02dc3e3 | 91 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) |
bd83cb56 VZ |
92 | |
93 | #if wxUSE_HELP | |
94 | EVT_HELP(-1, wxWindowBase::OnHelp) | |
95 | #endif // wxUSE_HELP | |
96 | ||
f03fc89f VZ |
97 | END_EVENT_TABLE() |
98 | ||
99 | // ============================================================================ | |
100 | // implementation of the common functionality of the wxWindow class | |
101 | // ============================================================================ | |
102 | ||
103 | // ---------------------------------------------------------------------------- | |
104 | // initialization | |
105 | // ---------------------------------------------------------------------------- | |
106 | ||
107 | // the default initialization | |
108 | void wxWindowBase::InitBase() | |
109 | { | |
110 | // no window yet, no parent nor children | |
f03fc89f VZ |
111 | m_parent = (wxWindow *)NULL; |
112 | m_windowId = -1; | |
113 | m_children.DeleteContents( FALSE ); // don't auto delete node data | |
114 | ||
115 | // no constraints on the minimal window size | |
116 | m_minWidth = | |
117 | m_minHeight = | |
118 | m_maxWidth = | |
119 | m_maxHeight = -1; | |
120 | ||
121 | // window is created enabled but it's not visible yet | |
122 | m_isShown = FALSE; | |
123 | m_isEnabled = TRUE; | |
124 | ||
f03fc89f VZ |
125 | // the default event handler is just this window |
126 | m_eventHandler = this; | |
127 | ||
88ac883a | 128 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
129 | // no validator |
130 | m_windowValidator = (wxValidator *) NULL; | |
88ac883a | 131 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
132 | |
133 | // use the system default colours | |
a756f210 VS |
134 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); |
135 | m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
f6e4e9ea | 136 | |
8bf30fe9 VZ |
137 | // don't set the font here for wxMSW as we don't call WM_SETFONT here and |
138 | // so the font is *not* really set - but calls to SetFont() later won't do | |
139 | // anything because m_font appears to be already set! | |
140 | #ifndef __WXMSW__ | |
a756f210 | 141 | m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
8bf30fe9 | 142 | #endif // __WXMSW__ |
807a903e | 143 | |
08df3e44 VZ |
144 | // the colours/fonts are default for now |
145 | m_hasBgCol = | |
146 | m_hasFgCol = | |
147 | m_hasFont = FALSE; | |
148 | ||
f03fc89f | 149 | // no style bits |
d80cd92a | 150 | m_exStyle = |
f03fc89f VZ |
151 | m_windowStyle = 0; |
152 | ||
153 | // an optimization for the event processing: checking this flag is much | |
154 | // faster than using IsKindOf(CLASSINFO(wxWindow)) | |
155 | m_isWindow = TRUE; | |
156 | ||
157 | #if wxUSE_CONSTRAINTS | |
158 | // no constraints whatsoever | |
159 | m_constraints = (wxLayoutConstraints *) NULL; | |
160 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
461e93f9 JS |
161 | #endif // wxUSE_CONSTRAINTS |
162 | ||
f03fc89f | 163 | m_windowSizer = (wxSizer *) NULL; |
be90c029 | 164 | m_containingSizer = (wxSizer *) NULL; |
f03fc89f | 165 | m_autoLayout = FALSE; |
f03fc89f VZ |
166 | |
167 | #if wxUSE_DRAG_AND_DROP | |
168 | m_dropTarget = (wxDropTarget *)NULL; | |
169 | #endif // wxUSE_DRAG_AND_DROP | |
170 | ||
171 | #if wxUSE_TOOLTIPS | |
172 | m_tooltip = (wxToolTip *)NULL; | |
173 | #endif // wxUSE_TOOLTIPS | |
789295bf VZ |
174 | |
175 | #if wxUSE_CARET | |
176 | m_caret = (wxCaret *)NULL; | |
177 | #endif // wxUSE_CARET | |
a2d93e73 | 178 | |
574c939e | 179 | #if wxUSE_PALETTE |
b95edd47 | 180 | m_hasCustomPalette = FALSE; |
574c939e KB |
181 | #endif // wxUSE_PALETTE |
182 | ||
566d84a7 | 183 | m_virtualSize = wxDefaultSize; |
1e2a653b VZ |
184 | |
185 | m_minVirtualWidth = | |
186 | m_minVirtualHeight = | |
187 | m_maxVirtualWidth = | |
566d84a7 RL |
188 | m_maxVirtualHeight = -1; |
189 | ||
a2d93e73 JS |
190 | // Whether we're using the current theme for this window (wxGTK only for now) |
191 | m_themeEnabled = FALSE; | |
f03fc89f VZ |
192 | } |
193 | ||
194 | // common part of window creation process | |
195 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
196 | wxWindowID id, | |
74e3313b VZ |
197 | const wxPoint& WXUNUSED(pos), |
198 | const wxSize& WXUNUSED(size), | |
f03fc89f | 199 | long style, |
8d99be5f | 200 | const wxValidator& validator, |
f03fc89f VZ |
201 | const wxString& name) |
202 | { | |
203 | // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other | |
204 | // member variables - check that it has been called (will catch the case | |
205 | // when a new ctor is added which doesn't call InitWindow) | |
223d09f6 | 206 | wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") ); |
f03fc89f | 207 | |
106844da VZ |
208 | #if wxUSE_STATBOX |
209 | // wxGTK doesn't allow to create controls with static box as the parent so | |
210 | // this will result in a crash when the program is ported to wxGTK so warn | |
211 | // the user about it | |
212 | ||
213 | // if you get this assert, the correct solution is to create the controls | |
214 | // as siblings of the static box | |
215 | wxASSERT_MSG( !parent || !wxDynamicCast(parent, wxStaticBox), | |
216 | _T("wxStaticBox can't be used as a window parent!") ); | |
217 | #endif // wxUSE_STATBOX | |
218 | ||
f03fc89f | 219 | // generate a new id if the user doesn't care about it |
69418a8e | 220 | m_windowId = id == -1 ? NewControlId() : id; |
f03fc89f VZ |
221 | |
222 | SetName(name); | |
223 | SetWindowStyleFlag(style); | |
224 | SetParent(parent); | |
674ac8b9 VZ |
225 | |
226 | #if wxUSE_VALIDATORS | |
8d99be5f | 227 | SetValidator(validator); |
674ac8b9 | 228 | #endif // wxUSE_VALIDATORS |
f03fc89f | 229 | |
8ae6ce07 VZ |
230 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to |
231 | // have it too - like this it's possible to set it only in the top level | |
232 | // dialog/frame and all children will inherit it by defult | |
233 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
234 | { | |
9cb98d89 | 235 | SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY); |
8ae6ce07 VZ |
236 | } |
237 | ||
f03fc89f VZ |
238 | return TRUE; |
239 | } | |
240 | ||
241 | // ---------------------------------------------------------------------------- | |
242 | // destruction | |
243 | // ---------------------------------------------------------------------------- | |
244 | ||
245 | // common clean up | |
246 | wxWindowBase::~wxWindowBase() | |
247 | { | |
349d1942 VS |
248 | wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") ); |
249 | ||
f03fc89f VZ |
250 | // FIXME if these 2 cases result from programming errors in the user code |
251 | // we should probably assert here instead of silently fixing them | |
252 | ||
253 | // Just in case the window has been Closed, but we're then deleting | |
254 | // immediately: don't leave dangling pointers. | |
255 | wxPendingDelete.DeleteObject(this); | |
256 | ||
257 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
258 | // we weren't a dialog class | |
259 | wxTopLevelWindows.DeleteObject(this); | |
a23fd0e1 | 260 | |
223d09f6 | 261 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); |
f03fc89f | 262 | |
789295bf VZ |
263 | #if wxUSE_CARET |
264 | if ( m_caret ) | |
265 | delete m_caret; | |
266 | #endif // wxUSE_CARET | |
267 | ||
88ac883a | 268 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
269 | if ( m_windowValidator ) |
270 | delete m_windowValidator; | |
88ac883a | 271 | #endif // wxUSE_VALIDATORS |
f03fc89f | 272 | |
f03fc89f VZ |
273 | #if wxUSE_CONSTRAINTS |
274 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
275 | // at deleted windows as they delete themselves. | |
276 | DeleteRelatedConstraints(); | |
277 | ||
278 | if ( m_constraints ) | |
279 | { | |
280 | // This removes any dangling pointers to this window in other windows' | |
281 | // constraintsInvolvedIn lists. | |
282 | UnsetConstraints(m_constraints); | |
283 | delete m_constraints; | |
284 | m_constraints = NULL; | |
285 | } | |
286 | ||
461e93f9 JS |
287 | #endif // wxUSE_CONSTRAINTS |
288 | ||
be90c029 | 289 | if ( m_containingSizer ) |
12a3f227 | 290 | m_containingSizer->Detach( (wxWindow*)this ); |
be90c029 | 291 | |
f03fc89f VZ |
292 | if ( m_windowSizer ) |
293 | delete m_windowSizer; | |
294 | ||
f03fc89f VZ |
295 | #if wxUSE_DRAG_AND_DROP |
296 | if ( m_dropTarget ) | |
297 | delete m_dropTarget; | |
298 | #endif // wxUSE_DRAG_AND_DROP | |
299 | ||
300 | #if wxUSE_TOOLTIPS | |
301 | if ( m_tooltip ) | |
302 | delete m_tooltip; | |
303 | #endif // wxUSE_TOOLTIPS | |
b0ee47ff VZ |
304 | |
305 | // reset the dangling pointer our parent window may keep to us | |
306 | if ( m_parent && m_parent->GetDefaultItem() == this ) | |
307 | { | |
308 | m_parent->SetDefaultItem(NULL); | |
309 | } | |
f03fc89f VZ |
310 | } |
311 | ||
312 | bool wxWindowBase::Destroy() | |
313 | { | |
314 | delete this; | |
315 | ||
316 | return TRUE; | |
317 | } | |
318 | ||
319 | bool wxWindowBase::Close(bool force) | |
320 | { | |
321 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
322 | event.SetEventObject(this); | |
323 | #if WXWIN_COMPATIBILITY | |
324 | event.SetForce(force); | |
325 | #endif // WXWIN_COMPATIBILITY | |
326 | event.SetCanVeto(!force); | |
327 | ||
328 | // return FALSE if window wasn't closed because the application vetoed the | |
329 | // close event | |
330 | return GetEventHandler()->ProcessEvent(event) && !event.GetVeto(); | |
331 | } | |
332 | ||
333 | bool wxWindowBase::DestroyChildren() | |
334 | { | |
335 | wxWindowList::Node *node; | |
a23fd0e1 | 336 | for ( ;; ) |
f03fc89f | 337 | { |
a23fd0e1 VZ |
338 | // we iterate until the list becomes empty |
339 | node = GetChildren().GetFirst(); | |
340 | if ( !node ) | |
341 | break; | |
342 | ||
f03fc89f | 343 | wxWindow *child = node->GetData(); |
a23fd0e1 | 344 | |
223d09f6 | 345 | wxASSERT_MSG( child, wxT("children list contains empty nodes") ); |
a23fd0e1 | 346 | |
1a77875b | 347 | child->Show(FALSE); |
eb082a08 | 348 | delete child; |
a23fd0e1 VZ |
349 | |
350 | wxASSERT_MSG( !GetChildren().Find(child), | |
223d09f6 | 351 | wxT("child didn't remove itself using RemoveChild()") ); |
f03fc89f VZ |
352 | } |
353 | ||
354 | return TRUE; | |
355 | } | |
356 | ||
357 | // ---------------------------------------------------------------------------- | |
f68586e5 | 358 | // size/position related methods |
f03fc89f VZ |
359 | // ---------------------------------------------------------------------------- |
360 | ||
361 | // centre the window with respect to its parent in either (or both) directions | |
362 | void wxWindowBase::Centre(int direction) | |
363 | { | |
f6bcfd97 BP |
364 | // the position/size of the parent window or of the entire screen |
365 | wxPoint posParent; | |
f03fc89f VZ |
366 | int widthParent, heightParent; |
367 | ||
f6bcfd97 BP |
368 | wxWindow *parent = NULL; |
369 | ||
370 | if ( !(direction & wxCENTRE_ON_SCREEN) ) | |
f03fc89f | 371 | { |
f6bcfd97 BP |
372 | // find the parent to centre this window on: it should be the |
373 | // immediate parent for the controls but the top level parent for the | |
374 | // top level windows (like dialogs) | |
375 | parent = GetParent(); | |
376 | if ( IsTopLevel() ) | |
377 | { | |
378 | while ( parent && !parent->IsTopLevel() ) | |
379 | { | |
380 | parent = parent->GetParent(); | |
381 | } | |
382 | } | |
383 | ||
e28b0102 VZ |
384 | // there is no wxTopLevelWindow under wxMotif yet |
385 | #ifndef __WXMOTIF__ | |
085ad686 VZ |
386 | // we shouldn't center the dialog on the iconized window: under |
387 | // Windows, for example, this places it completely off the screen | |
388 | if ( parent ) | |
389 | { | |
390 | wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow); | |
391 | if ( winTop && winTop->IsIconized() ) | |
392 | { | |
393 | parent = NULL; | |
394 | } | |
395 | } | |
e28b0102 | 396 | #endif // __WXMOTIF__ |
085ad686 | 397 | |
f6bcfd97 BP |
398 | // did we find the parent? |
399 | if ( !parent ) | |
400 | { | |
401 | // no other choice | |
402 | direction |= wxCENTRE_ON_SCREEN; | |
403 | } | |
f03fc89f | 404 | } |
10fcf31a VZ |
405 | |
406 | if ( direction & wxCENTRE_ON_SCREEN ) | |
f03fc89f VZ |
407 | { |
408 | // centre with respect to the whole screen | |
409 | wxDisplaySize(&widthParent, &heightParent); | |
410 | } | |
10fcf31a VZ |
411 | else |
412 | { | |
f6bcfd97 BP |
413 | if ( IsTopLevel() ) |
414 | { | |
415 | // centre on the parent | |
416 | parent->GetSize(&widthParent, &heightParent); | |
417 | ||
418 | // adjust to the parents position | |
419 | posParent = parent->GetPosition(); | |
420 | } | |
421 | else | |
422 | { | |
423 | // centre inside the parents client rectangle | |
424 | parent->GetClientSize(&widthParent, &heightParent); | |
425 | } | |
10fcf31a | 426 | } |
f03fc89f VZ |
427 | |
428 | int width, height; | |
429 | GetSize(&width, &height); | |
430 | ||
c39eda94 VZ |
431 | int xNew = -1, |
432 | yNew = -1; | |
f03fc89f VZ |
433 | |
434 | if ( direction & wxHORIZONTAL ) | |
c39eda94 | 435 | xNew = (widthParent - width)/2; |
f03fc89f VZ |
436 | |
437 | if ( direction & wxVERTICAL ) | |
c39eda94 | 438 | yNew = (heightParent - height)/2; |
f03fc89f | 439 | |
f6bcfd97 BP |
440 | xNew += posParent.x; |
441 | yNew += posParent.y; | |
7631a292 | 442 | |
ef397583 GT |
443 | // Base size of the visible dimensions of the display |
444 | // to take into account the taskbar | |
445 | wxRect rect = wxGetClientDisplayRect(); | |
446 | wxSize size (rect.width,rect.height); | |
447 | ||
ede7020a VS |
448 | // NB: in wxMSW, negative position may not neccessary mean "out of screen", |
449 | // but it may mean that the window is placed on other than the main | |
450 | // display. Therefore we only make sure centered window is on the main display | |
451 | // if the parent is at least partially present here. | |
452 | if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display | |
ef397583 GT |
453 | { |
454 | if (xNew < 0) | |
455 | xNew = 0; | |
456 | else if (xNew+width > size.x) | |
457 | xNew = size.x-width-1; | |
458 | } | |
ede7020a | 459 | if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display |
ef397583 GT |
460 | { |
461 | if (yNew+height > size.y) | |
462 | yNew = size.y-height-1; | |
463 | ||
464 | // Make certain that the title bar is initially visible | |
465 | // always, even if this would push the bottom of the | |
466 | // dialog of the visible area of the display | |
467 | if (yNew < 0) | |
468 | yNew = 0; | |
469 | } | |
470 | ||
0fff366e VZ |
471 | // move the window to this position (keeping the old size but using |
472 | // SetSize() and not Move() to allow xNew and/or yNew to be -1) | |
db89aa76 | 473 | SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE); |
7631a292 RD |
474 | } |
475 | ||
f03fc89f VZ |
476 | // fits the window around the children |
477 | void wxWindowBase::Fit() | |
478 | { | |
f68586e5 VZ |
479 | if ( GetChildren().GetCount() > 0 ) |
480 | { | |
ec5bb70d | 481 | SetClientSize(DoGetBestSize()); |
f68586e5 VZ |
482 | } |
483 | //else: do nothing if we have no children | |
484 | } | |
f03fc89f | 485 | |
2b5f62a0 VZ |
486 | // fits virtual size (ie. scrolled area etc.) around children |
487 | void wxWindowBase::FitInside() | |
488 | { | |
489 | if ( GetChildren().GetCount() > 0 ) | |
490 | { | |
491 | SetVirtualSize( GetBestVirtualSize() ); | |
492 | } | |
493 | } | |
494 | ||
f68586e5 VZ |
495 | // return the size best suited for the current window |
496 | wxSize wxWindowBase::DoGetBestSize() const | |
497 | { | |
ec5bb70d VZ |
498 | if ( m_windowSizer ) |
499 | { | |
500 | return m_windowSizer->GetMinSize(); | |
501 | } | |
502 | #if wxUSE_CONSTRAINTS | |
503 | else if ( m_constraints ) | |
504 | { | |
505 | wxConstCast(this, wxWindowBase)->SatisfyConstraints(); | |
506 | ||
507 | // our minimal acceptable size is such that all our windows fit inside | |
508 | int maxX = 0, | |
509 | maxY = 0; | |
510 | ||
511 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
512 | node; | |
513 | node = node->GetNext() ) | |
514 | { | |
515 | wxLayoutConstraints *c = node->GetData()->GetConstraints(); | |
516 | if ( !c ) | |
517 | { | |
518 | // it's not normal that we have an unconstrained child, but | |
519 | // what can we do about it? | |
520 | continue; | |
521 | } | |
522 | ||
523 | int x = c->right.GetValue(), | |
524 | y = c->bottom.GetValue(); | |
525 | ||
526 | if ( x > maxX ) | |
527 | maxX = x; | |
528 | ||
529 | if ( y > maxY ) | |
530 | maxY = y; | |
531 | ||
532 | // TODO: we must calculate the overlaps somehow, otherwise we | |
533 | // will never return a size bigger than the current one :-( | |
534 | } | |
535 | ||
536 | return wxSize(maxX, maxY); | |
537 | } | |
538 | #endif // wxUSE_CONSTRAINTS | |
539 | else if ( GetChildren().GetCount() > 0 ) | |
f03fc89f | 540 | { |
f68586e5 VZ |
541 | // our minimal acceptable size is such that all our windows fit inside |
542 | int maxX = 0, | |
543 | maxY = 0; | |
544 | ||
545 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
546 | node; | |
547 | node = node->GetNext() ) | |
42e69d6b | 548 | { |
f68586e5 | 549 | wxWindow *win = node->GetData(); |
1e6feb95 VZ |
550 | if ( win->IsTopLevel() |
551 | #if wxUSE_STATUSBAR | |
552 | || wxDynamicCast(win, wxStatusBar) | |
553 | #endif // wxUSE_STATUSBAR | |
554 | ) | |
f68586e5 VZ |
555 | { |
556 | // dialogs and frames lie in different top level windows - | |
7d9fd004 VZ |
557 | // don't deal with them here; as for the status bars, they |
558 | // don't lie in the client area at all | |
f68586e5 VZ |
559 | continue; |
560 | } | |
561 | ||
562 | int wx, wy, ww, wh; | |
563 | win->GetPosition(&wx, &wy); | |
3f5513f5 VZ |
564 | |
565 | // if the window hadn't been positioned yet, assume that it is in | |
566 | // the origin | |
567 | if ( wx == -1 ) | |
568 | wx = 0; | |
569 | if ( wy == -1 ) | |
570 | wy = 0; | |
571 | ||
f68586e5 VZ |
572 | win->GetSize(&ww, &wh); |
573 | if ( wx + ww > maxX ) | |
574 | maxX = wx + ww; | |
575 | if ( wy + wh > maxY ) | |
576 | maxY = wy + wh; | |
42e69d6b VZ |
577 | } |
578 | ||
ec5bb70d VZ |
579 | // for compatibility with the old versions and because it really looks |
580 | // slightly more pretty like this, add a pad | |
581 | maxX += 7; | |
582 | maxY += 14; | |
583 | ||
ba81034d | 584 | return wxSize(maxX, maxY); |
f68586e5 VZ |
585 | } |
586 | else | |
587 | { | |
588 | // for a generic window there is no natural best size - just use the | |
589 | // current one | |
590 | return GetSize(); | |
f03fc89f | 591 | } |
f03fc89f VZ |
592 | } |
593 | ||
1e6feb95 VZ |
594 | // by default the origin is not shifted |
595 | wxPoint wxWindowBase::GetClientAreaOrigin() const | |
596 | { | |
597 | return wxPoint(0, 0); | |
598 | } | |
599 | ||
f03fc89f | 600 | // set the min/max size of the window |
f03fc89f VZ |
601 | void wxWindowBase::SetSizeHints(int minW, int minH, |
602 | int maxW, int maxH, | |
603 | int WXUNUSED(incW), int WXUNUSED(incH)) | |
604 | { | |
605 | m_minWidth = minW; | |
606 | m_maxWidth = maxW; | |
607 | m_minHeight = minH; | |
608 | m_maxHeight = maxH; | |
609 | } | |
610 | ||
566d84a7 RL |
611 | void wxWindowBase::SetVirtualSizeHints( int minW, int minH, |
612 | int maxW, int maxH ) | |
613 | { | |
614 | m_minVirtualWidth = minW; | |
615 | m_maxVirtualWidth = maxW; | |
616 | m_minVirtualHeight = minH; | |
617 | m_maxVirtualHeight = maxH; | |
566d84a7 RL |
618 | } |
619 | ||
620 | void wxWindowBase::DoSetVirtualSize( int x, int y ) | |
621 | { | |
1e2a653b VZ |
622 | if ( m_minVirtualWidth != -1 && m_minVirtualWidth > x ) |
623 | x = m_minVirtualWidth; | |
624 | if ( m_maxVirtualWidth != -1 && m_maxVirtualWidth < x ) | |
625 | x = m_maxVirtualWidth; | |
626 | if ( m_minVirtualHeight != -1 && m_minVirtualHeight > y ) | |
627 | y = m_minVirtualHeight; | |
628 | if ( m_maxVirtualHeight != -1 && m_maxVirtualHeight < y ) | |
629 | y = m_maxVirtualHeight; | |
630 | ||
631 | m_virtualSize = wxSize(x, y); | |
566d84a7 RL |
632 | } |
633 | ||
634 | wxSize wxWindowBase::DoGetVirtualSize() const | |
635 | { | |
636 | wxSize s( GetClientSize() ); | |
637 | ||
150c8d89 RL |
638 | return wxSize( wxMax( m_virtualSize.GetWidth(), s.GetWidth() ), |
639 | wxMax( m_virtualSize.GetHeight(), s.GetHeight() ) ); | |
566d84a7 RL |
640 | } |
641 | ||
f03fc89f VZ |
642 | // ---------------------------------------------------------------------------- |
643 | // show/hide/enable/disable the window | |
644 | // ---------------------------------------------------------------------------- | |
645 | ||
646 | bool wxWindowBase::Show(bool show) | |
647 | { | |
648 | if ( show != m_isShown ) | |
649 | { | |
650 | m_isShown = show; | |
651 | ||
652 | return TRUE; | |
653 | } | |
654 | else | |
655 | { | |
656 | return FALSE; | |
657 | } | |
658 | } | |
659 | ||
660 | bool wxWindowBase::Enable(bool enable) | |
661 | { | |
662 | if ( enable != m_isEnabled ) | |
663 | { | |
664 | m_isEnabled = enable; | |
665 | ||
666 | return TRUE; | |
667 | } | |
668 | else | |
669 | { | |
670 | return FALSE; | |
671 | } | |
672 | } | |
34636400 VZ |
673 | // ---------------------------------------------------------------------------- |
674 | // RTTI | |
675 | // ---------------------------------------------------------------------------- | |
676 | ||
677 | bool wxWindowBase::IsTopLevel() const | |
678 | { | |
8487f887 | 679 | return FALSE; |
34636400 | 680 | } |
f03fc89f VZ |
681 | |
682 | // ---------------------------------------------------------------------------- | |
683 | // reparenting the window | |
684 | // ---------------------------------------------------------------------------- | |
685 | ||
686 | void wxWindowBase::AddChild(wxWindowBase *child) | |
687 | { | |
223d09f6 | 688 | wxCHECK_RET( child, wxT("can't add a NULL child") ); |
f03fc89f | 689 | |
f6bcfd97 BP |
690 | // this should never happen and it will lead to a crash later if it does |
691 | // because RemoveChild() will remove only one node from the children list | |
692 | // and the other(s) one(s) will be left with dangling pointers in them | |
693 | wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") ); | |
694 | ||
f03fc89f VZ |
695 | GetChildren().Append(child); |
696 | child->SetParent(this); | |
697 | } | |
698 | ||
699 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
700 | { | |
223d09f6 | 701 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); |
f03fc89f VZ |
702 | |
703 | GetChildren().DeleteObject(child); | |
704 | child->SetParent((wxWindow *)NULL); | |
705 | } | |
439b3bf1 | 706 | |
f03fc89f VZ |
707 | bool wxWindowBase::Reparent(wxWindowBase *newParent) |
708 | { | |
709 | wxWindow *oldParent = GetParent(); | |
710 | if ( newParent == oldParent ) | |
711 | { | |
712 | // nothing done | |
713 | return FALSE; | |
714 | } | |
715 | ||
716 | // unlink this window from the existing parent. | |
717 | if ( oldParent ) | |
718 | { | |
719 | oldParent->RemoveChild(this); | |
720 | } | |
721 | else | |
722 | { | |
723 | wxTopLevelWindows.DeleteObject(this); | |
724 | } | |
725 | ||
726 | // add it to the new one | |
727 | if ( newParent ) | |
728 | { | |
729 | newParent->AddChild(this); | |
730 | } | |
731 | else | |
732 | { | |
733 | wxTopLevelWindows.Append(this); | |
734 | } | |
735 | ||
736 | return TRUE; | |
737 | } | |
738 | ||
739 | // ---------------------------------------------------------------------------- | |
740 | // event handler stuff | |
741 | // ---------------------------------------------------------------------------- | |
742 | ||
743 | void wxWindowBase::PushEventHandler(wxEvtHandler *handler) | |
744 | { | |
3a074ba8 VZ |
745 | wxEvtHandler *handlerOld = GetEventHandler(); |
746 | ||
747 | handler->SetNextHandler(handlerOld); | |
748 | ||
749 | if ( handlerOld ) | |
750 | GetEventHandler()->SetPreviousHandler(handler); | |
751 | ||
f03fc89f VZ |
752 | SetEventHandler(handler); |
753 | } | |
754 | ||
755 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
756 | { | |
757 | wxEvtHandler *handlerA = GetEventHandler(); | |
758 | if ( handlerA ) | |
759 | { | |
760 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
761 | handlerA->SetNextHandler((wxEvtHandler *)NULL); | |
3a074ba8 VZ |
762 | |
763 | if ( handlerB ) | |
764 | handlerB->SetPreviousHandler((wxEvtHandler *)NULL); | |
f03fc89f | 765 | SetEventHandler(handlerB); |
3a074ba8 | 766 | |
f03fc89f VZ |
767 | if ( deleteHandler ) |
768 | { | |
769 | delete handlerA; | |
770 | handlerA = (wxEvtHandler *)NULL; | |
771 | } | |
772 | } | |
773 | ||
774 | return handlerA; | |
775 | } | |
776 | ||
2e36d5cf VZ |
777 | bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler) |
778 | { | |
779 | wxCHECK_MSG( handler, FALSE, _T("RemoveEventHandler(NULL) called") ); | |
780 | ||
781 | wxEvtHandler *handlerPrev = NULL, | |
782 | *handlerCur = GetEventHandler(); | |
783 | while ( handlerCur ) | |
784 | { | |
785 | wxEvtHandler *handlerNext = handlerCur->GetNextHandler(); | |
786 | ||
787 | if ( handlerCur == handler ) | |
788 | { | |
789 | if ( handlerPrev ) | |
790 | { | |
791 | handlerPrev->SetNextHandler(handlerNext); | |
792 | } | |
793 | else | |
794 | { | |
795 | SetEventHandler(handlerNext); | |
796 | } | |
797 | ||
7a9c8d74 JS |
798 | if ( handlerNext ) |
799 | { | |
800 | handlerNext->SetPreviousHandler ( handlerPrev ); | |
801 | } | |
2e36d5cf VZ |
802 | handler->SetNextHandler(NULL); |
803 | ||
804 | return TRUE; | |
805 | } | |
806 | ||
807 | handlerPrev = handlerCur; | |
808 | handlerCur = handlerNext; | |
809 | } | |
810 | ||
811 | wxFAIL_MSG( _T("where has the event handler gone?") ); | |
812 | ||
813 | return FALSE; | |
814 | } | |
815 | ||
f03fc89f VZ |
816 | // ---------------------------------------------------------------------------- |
817 | // cursors, fonts &c | |
818 | // ---------------------------------------------------------------------------- | |
819 | ||
820 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) | |
821 | { | |
822 | if ( !colour.Ok() || (colour == m_backgroundColour) ) | |
823 | return FALSE; | |
824 | ||
825 | m_backgroundColour = colour; | |
826 | ||
23895080 VZ |
827 | m_hasBgCol = TRUE; |
828 | ||
f03fc89f VZ |
829 | return TRUE; |
830 | } | |
831 | ||
832 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
833 | { | |
834 | if ( !colour.Ok() || (colour == m_foregroundColour) ) | |
835 | return FALSE; | |
836 | ||
837 | m_foregroundColour = colour; | |
838 | ||
23895080 VZ |
839 | m_hasFgCol = TRUE; |
840 | ||
f03fc89f VZ |
841 | return TRUE; |
842 | } | |
843 | ||
844 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
845 | { | |
8a9c2246 VZ |
846 | // setting an invalid cursor is ok, it means that we don't have any special |
847 | // cursor | |
13588544 | 848 | if ( m_cursor == cursor ) |
f03fc89f VZ |
849 | { |
850 | // no change | |
851 | return FALSE; | |
852 | } | |
853 | ||
8a9c2246 | 854 | m_cursor = cursor; |
f03fc89f VZ |
855 | |
856 | return TRUE; | |
857 | } | |
858 | ||
859 | bool wxWindowBase::SetFont(const wxFont& font) | |
860 | { | |
861 | // don't try to set invalid font, always fall back to the default | |
862 | const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT; | |
863 | ||
8bf30fe9 | 864 | if ( fontOk == m_font ) |
f03fc89f VZ |
865 | { |
866 | // no change | |
867 | return FALSE; | |
868 | } | |
869 | ||
870 | m_font = fontOk; | |
871 | ||
23895080 VZ |
872 | m_hasFont = TRUE; |
873 | ||
f03fc89f VZ |
874 | return TRUE; |
875 | } | |
876 | ||
b95edd47 VZ |
877 | #if wxUSE_PALETTE |
878 | ||
879 | void wxWindowBase::SetPalette(const wxPalette& pal) | |
880 | { | |
881 | m_hasCustomPalette = TRUE; | |
882 | m_palette = pal; | |
883 | ||
884 | // VZ: can anyone explain me what do we do here? | |
885 | wxWindowDC d((wxWindow *) this); | |
886 | d.SetPalette(pal); | |
887 | } | |
888 | ||
889 | wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const | |
890 | { | |
891 | wxWindow *win = (wxWindow *)this; | |
892 | while ( win && !win->HasCustomPalette() ) | |
893 | { | |
894 | win = win->GetParent(); | |
895 | } | |
896 | ||
897 | return win; | |
898 | } | |
899 | ||
900 | #endif // wxUSE_PALETTE | |
901 | ||
789295bf VZ |
902 | #if wxUSE_CARET |
903 | void wxWindowBase::SetCaret(wxCaret *caret) | |
904 | { | |
905 | if ( m_caret ) | |
906 | { | |
907 | delete m_caret; | |
908 | } | |
909 | ||
910 | m_caret = caret; | |
911 | ||
912 | if ( m_caret ) | |
913 | { | |
914 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
223d09f6 | 915 | wxT("caret should be created associated to this window") ); |
789295bf VZ |
916 | } |
917 | } | |
918 | #endif // wxUSE_CARET | |
919 | ||
88ac883a | 920 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
921 | // ---------------------------------------------------------------------------- |
922 | // validators | |
923 | // ---------------------------------------------------------------------------- | |
924 | ||
925 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
926 | { | |
927 | if ( m_windowValidator ) | |
928 | delete m_windowValidator; | |
929 | ||
930 | m_windowValidator = (wxValidator *)validator.Clone(); | |
931 | ||
932 | if ( m_windowValidator ) | |
933 | m_windowValidator->SetWindow(this) ; | |
934 | } | |
88ac883a | 935 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
936 | |
937 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 938 | // update region stuff |
f03fc89f VZ |
939 | // ---------------------------------------------------------------------------- |
940 | ||
1e6feb95 VZ |
941 | wxRect wxWindowBase::GetUpdateClientRect() const |
942 | { | |
943 | wxRegion rgnUpdate = GetUpdateRegion(); | |
944 | rgnUpdate.Intersect(GetClientRect()); | |
945 | wxRect rectUpdate = rgnUpdate.GetBox(); | |
946 | wxPoint ptOrigin = GetClientAreaOrigin(); | |
947 | rectUpdate.x -= ptOrigin.x; | |
948 | rectUpdate.y -= ptOrigin.y; | |
949 | ||
950 | return rectUpdate; | |
951 | } | |
952 | ||
f03fc89f VZ |
953 | bool wxWindowBase::IsExposed(int x, int y) const |
954 | { | |
955 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
956 | } | |
957 | ||
958 | bool wxWindowBase::IsExposed(int x, int y, int w, int h) const | |
959 | { | |
960 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
961 | } | |
962 | ||
963 | // ---------------------------------------------------------------------------- | |
146ba0fe | 964 | // find child window by id or name |
f03fc89f VZ |
965 | // ---------------------------------------------------------------------------- |
966 | ||
967 | wxWindow *wxWindowBase::FindWindow( long id ) | |
968 | { | |
969 | if ( id == m_windowId ) | |
970 | return (wxWindow *)this; | |
971 | ||
972 | wxWindowBase *res = (wxWindow *)NULL; | |
973 | wxWindowList::Node *node; | |
974 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
975 | { | |
976 | wxWindowBase *child = node->GetData(); | |
977 | res = child->FindWindow( id ); | |
978 | } | |
979 | ||
980 | return (wxWindow *)res; | |
981 | } | |
982 | ||
983 | wxWindow *wxWindowBase::FindWindow( const wxString& name ) | |
984 | { | |
985 | if ( name == m_windowName ) | |
986 | return (wxWindow *)this; | |
987 | ||
988 | wxWindowBase *res = (wxWindow *)NULL; | |
989 | wxWindowList::Node *node; | |
990 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
991 | { | |
992 | wxWindow *child = node->GetData(); | |
993 | res = child->FindWindow(name); | |
994 | } | |
995 | ||
996 | return (wxWindow *)res; | |
997 | } | |
998 | ||
146ba0fe VZ |
999 | |
1000 | // find any window by id or name or label: If parent is non-NULL, look through | |
1001 | // children for a label or title matching the specified string. If NULL, look | |
1002 | // through all top-level windows. | |
1003 | // | |
1004 | // to avoid duplicating code we reuse the same helper function but with | |
1005 | // different comparators | |
1006 | ||
1007 | typedef bool (*wxFindWindowCmp)(const wxWindow *win, | |
1008 | const wxString& label, long id); | |
1009 | ||
1010 | static | |
1011 | bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label, | |
1012 | long WXUNUSED(id)) | |
1013 | { | |
1014 | return win->GetLabel() == label; | |
1015 | } | |
1016 | ||
1017 | static | |
1018 | bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label, | |
1019 | long WXUNUSED(id)) | |
1020 | { | |
1021 | return win->GetName() == label; | |
1022 | } | |
1023 | ||
1024 | static | |
1025 | bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label), | |
1026 | long id) | |
1027 | { | |
1028 | return win->GetId() == id; | |
1029 | } | |
1030 | ||
1031 | // recursive helper for the FindWindowByXXX() functions | |
1032 | static | |
1033 | wxWindow *wxFindWindowRecursively(const wxWindow *parent, | |
1034 | const wxString& label, | |
1035 | long id, | |
1036 | wxFindWindowCmp cmp) | |
1037 | { | |
1038 | if ( parent ) | |
1039 | { | |
1040 | // see if this is the one we're looking for | |
1041 | if ( (*cmp)(parent, label, id) ) | |
1042 | return (wxWindow *)parent; | |
1043 | ||
1044 | // It wasn't, so check all its children | |
1045 | for ( wxWindowList::Node * node = parent->GetChildren().GetFirst(); | |
1046 | node; | |
1047 | node = node->GetNext() ) | |
1048 | { | |
1049 | // recursively check each child | |
1050 | wxWindow *win = (wxWindow *)node->GetData(); | |
1051 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1052 | if (retwin) | |
1053 | return retwin; | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | // Not found | |
1058 | return NULL; | |
1059 | } | |
1060 | ||
1061 | // helper for FindWindowByXXX() | |
1062 | static | |
1063 | wxWindow *wxFindWindowHelper(const wxWindow *parent, | |
1064 | const wxString& label, | |
1065 | long id, | |
1066 | wxFindWindowCmp cmp) | |
1067 | { | |
1068 | if ( parent ) | |
1069 | { | |
1070 | // just check parent and all its children | |
1071 | return wxFindWindowRecursively(parent, label, id, cmp); | |
1072 | } | |
1073 | ||
1074 | // start at very top of wx's windows | |
1075 | for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst(); | |
1076 | node; | |
1077 | node = node->GetNext() ) | |
1078 | { | |
1079 | // recursively check each window & its children | |
1080 | wxWindow *win = node->GetData(); | |
1081 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1082 | if (retwin) | |
1083 | return retwin; | |
1084 | } | |
1085 | ||
1086 | return NULL; | |
1087 | } | |
1088 | ||
1089 | /* static */ | |
1090 | wxWindow * | |
1091 | wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent) | |
1092 | { | |
1093 | return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels); | |
1094 | } | |
1095 | ||
1096 | /* static */ | |
1097 | wxWindow * | |
1098 | wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent) | |
1099 | { | |
1100 | wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames); | |
1101 | ||
1102 | if ( !win ) | |
1103 | { | |
1104 | // fall back to the label | |
1105 | win = FindWindowByLabel(title, parent); | |
1106 | } | |
1107 | ||
1108 | return win; | |
1109 | } | |
1110 | ||
1111 | /* static */ | |
1112 | wxWindow * | |
1113 | wxWindowBase::FindWindowById( long id, const wxWindow* parent ) | |
1114 | { | |
1115 | return wxFindWindowHelper(parent, _T(""), id, wxFindWindowCmpIds); | |
1116 | } | |
1117 | ||
f03fc89f VZ |
1118 | // ---------------------------------------------------------------------------- |
1119 | // dialog oriented functions | |
1120 | // ---------------------------------------------------------------------------- | |
1121 | ||
34636400 | 1122 | void wxWindowBase::MakeModal(bool modal) |
f03fc89f | 1123 | { |
34636400 VZ |
1124 | // Disable all other windows |
1125 | if ( IsTopLevel() ) | |
1126 | { | |
1127 | wxWindowList::Node *node = wxTopLevelWindows.GetFirst(); | |
1128 | while (node) | |
1129 | { | |
1130 | wxWindow *win = node->GetData(); | |
1131 | if (win != this) | |
1132 | win->Enable(!modal); | |
1133 | ||
1134 | node = node->GetNext(); | |
1135 | } | |
1136 | } | |
f03fc89f VZ |
1137 | } |
1138 | ||
1139 | bool wxWindowBase::Validate() | |
1140 | { | |
88ac883a | 1141 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1142 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1143 | ||
f03fc89f VZ |
1144 | wxWindowList::Node *node; |
1145 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1146 | { | |
1147 | wxWindowBase *child = node->GetData(); | |
1148 | wxValidator *validator = child->GetValidator(); | |
dcd6b914 | 1149 | if ( validator && !validator->Validate((wxWindow *)this) ) |
f03fc89f VZ |
1150 | { |
1151 | return FALSE; | |
1152 | } | |
d80cd92a VZ |
1153 | |
1154 | if ( recurse && !child->Validate() ) | |
1155 | { | |
1156 | return FALSE; | |
1157 | } | |
f03fc89f | 1158 | } |
88ac883a | 1159 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1160 | |
1161 | return TRUE; | |
1162 | } | |
1163 | ||
1164 | bool wxWindowBase::TransferDataToWindow() | |
1165 | { | |
88ac883a | 1166 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1167 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1168 | ||
f03fc89f VZ |
1169 | wxWindowList::Node *node; |
1170 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1171 | { | |
1172 | wxWindowBase *child = node->GetData(); | |
1173 | wxValidator *validator = child->GetValidator(); | |
1174 | if ( validator && !validator->TransferToWindow() ) | |
1175 | { | |
d80cd92a | 1176 | wxLogWarning(_("Could not transfer data to window")); |
e30285ab | 1177 | #if wxUSE_LOG |
d80cd92a | 1178 | wxLog::FlushActive(); |
e30285ab | 1179 | #endif // wxUSE_LOG |
f03fc89f VZ |
1180 | |
1181 | return FALSE; | |
1182 | } | |
d80cd92a VZ |
1183 | |
1184 | if ( recurse ) | |
1185 | { | |
a58a12e9 | 1186 | if ( !child->TransferDataToWindow() ) |
d80cd92a VZ |
1187 | { |
1188 | // warning already given | |
1189 | return FALSE; | |
1190 | } | |
1191 | } | |
f03fc89f | 1192 | } |
88ac883a | 1193 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1194 | |
1195 | return TRUE; | |
1196 | } | |
1197 | ||
1198 | bool wxWindowBase::TransferDataFromWindow() | |
1199 | { | |
88ac883a | 1200 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1201 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1202 | ||
f03fc89f VZ |
1203 | wxWindowList::Node *node; |
1204 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1205 | { | |
1206 | wxWindow *child = node->GetData(); | |
d80cd92a VZ |
1207 | wxValidator *validator = child->GetValidator(); |
1208 | if ( validator && !validator->TransferFromWindow() ) | |
f03fc89f | 1209 | { |
d80cd92a VZ |
1210 | // nop warning here because the application is supposed to give |
1211 | // one itself - we don't know here what might have gone wrongly | |
1212 | ||
f03fc89f VZ |
1213 | return FALSE; |
1214 | } | |
d80cd92a VZ |
1215 | |
1216 | if ( recurse ) | |
1217 | { | |
a58a12e9 | 1218 | if ( !child->TransferDataFromWindow() ) |
d80cd92a VZ |
1219 | { |
1220 | // warning already given | |
1221 | return FALSE; | |
1222 | } | |
1223 | } | |
f03fc89f | 1224 | } |
88ac883a | 1225 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1226 | |
1227 | return TRUE; | |
1228 | } | |
1229 | ||
1230 | void wxWindowBase::InitDialog() | |
1231 | { | |
1232 | wxInitDialogEvent event(GetId()); | |
1233 | event.SetEventObject( this ); | |
1234 | GetEventHandler()->ProcessEvent(event); | |
1235 | } | |
1236 | ||
1237 | // ---------------------------------------------------------------------------- | |
bd83cb56 VZ |
1238 | // context-sensitive help support |
1239 | // ---------------------------------------------------------------------------- | |
1240 | ||
1241 | #if wxUSE_HELP | |
1242 | ||
1243 | // associate this help text with this window | |
1244 | void wxWindowBase::SetHelpText(const wxString& text) | |
1245 | { | |
1246 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1247 | if ( helpProvider ) | |
1248 | { | |
1249 | helpProvider->AddHelp(this, text); | |
1250 | } | |
1251 | } | |
1252 | ||
1253 | // associate this help text with all windows with the same id as this | |
1254 | // one | |
1255 | void wxWindowBase::SetHelpTextForId(const wxString& text) | |
1256 | { | |
1257 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1258 | if ( helpProvider ) | |
1259 | { | |
1260 | helpProvider->AddHelp(GetId(), text); | |
1261 | } | |
1262 | } | |
1263 | ||
1264 | // get the help string associated with this window (may be empty) | |
1265 | wxString wxWindowBase::GetHelpText() const | |
1266 | { | |
1267 | wxString text; | |
1268 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1269 | if ( helpProvider ) | |
1270 | { | |
1271 | text = helpProvider->GetHelp(this); | |
1272 | } | |
1273 | ||
1274 | return text; | |
1275 | } | |
1276 | ||
1277 | // show help for this window | |
1278 | void wxWindowBase::OnHelp(wxHelpEvent& event) | |
1279 | { | |
1280 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1281 | if ( helpProvider ) | |
1282 | { | |
1283 | if ( helpProvider->ShowHelp(this) ) | |
1284 | { | |
1285 | // skip the event.Skip() below | |
1286 | return; | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | event.Skip(); | |
1291 | } | |
1292 | ||
1293 | #endif // wxUSE_HELP | |
1294 | ||
1295 | // ---------------------------------------------------------------------------- | |
574c939e | 1296 | // tooltipsroot.Replace("\\", "/"); |
f03fc89f VZ |
1297 | // ---------------------------------------------------------------------------- |
1298 | ||
1299 | #if wxUSE_TOOLTIPS | |
1300 | ||
1301 | void wxWindowBase::SetToolTip( const wxString &tip ) | |
1302 | { | |
1303 | // don't create the new tooltip if we already have one | |
1304 | if ( m_tooltip ) | |
1305 | { | |
1306 | m_tooltip->SetTip( tip ); | |
1307 | } | |
1308 | else | |
1309 | { | |
1310 | SetToolTip( new wxToolTip( tip ) ); | |
1311 | } | |
1312 | ||
1313 | // setting empty tooltip text does not remove the tooltip any more - use | |
1314 | // SetToolTip((wxToolTip *)NULL) for this | |
1315 | } | |
1316 | ||
1317 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
1318 | { | |
1319 | if ( m_tooltip ) | |
1320 | delete m_tooltip; | |
1321 | ||
1322 | m_tooltip = tooltip; | |
1323 | } | |
1324 | ||
1325 | #endif // wxUSE_TOOLTIPS | |
1326 | ||
1327 | // ---------------------------------------------------------------------------- | |
1328 | // constraints and sizers | |
1329 | // ---------------------------------------------------------------------------- | |
1330 | ||
1331 | #if wxUSE_CONSTRAINTS | |
1332 | ||
1333 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
1334 | { | |
1335 | if ( m_constraints ) | |
1336 | { | |
1337 | UnsetConstraints(m_constraints); | |
1338 | delete m_constraints; | |
1339 | } | |
1340 | m_constraints = constraints; | |
1341 | if ( m_constraints ) | |
1342 | { | |
1343 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1344 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
1345 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
1346 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
1347 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
1348 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
1349 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
1350 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
1351 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
1352 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
1353 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
1354 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
1355 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
1356 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
1357 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
1358 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
1359 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
1360 | } | |
1361 | } | |
1362 | ||
1363 | // This removes any dangling pointers to this window in other windows' | |
1364 | // constraintsInvolvedIn lists. | |
1365 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
1366 | { | |
1367 | if ( c ) | |
1368 | { | |
1369 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1370 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
1371 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1372 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
1373 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
1374 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
1375 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
1376 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
1377 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
1378 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
1379 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
1380 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
1381 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
1382 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
1383 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
1384 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
1385 | } | |
1386 | } | |
1387 | ||
1388 | // Back-pointer to other windows we're involved with, so if we delete this | |
1389 | // window, we must delete any constraints we're involved with. | |
1390 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
1391 | { | |
1392 | if ( !m_constraintsInvolvedIn ) | |
1393 | m_constraintsInvolvedIn = new wxWindowList; | |
1394 | if ( !m_constraintsInvolvedIn->Find(otherWin) ) | |
1395 | m_constraintsInvolvedIn->Append(otherWin); | |
1396 | } | |
1397 | ||
1398 | // REMOVE back-pointer to other windows we're involved with. | |
1399 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
1400 | { | |
1401 | if ( m_constraintsInvolvedIn ) | |
1402 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
1403 | } | |
1404 | ||
1405 | // Reset any constraints that mention this window | |
1406 | void wxWindowBase::DeleteRelatedConstraints() | |
1407 | { | |
1408 | if ( m_constraintsInvolvedIn ) | |
1409 | { | |
1410 | wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst(); | |
1411 | while (node) | |
1412 | { | |
1413 | wxWindow *win = node->GetData(); | |
1414 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1415 | ||
1416 | // Reset any constraints involving this window | |
1417 | if ( constr ) | |
1418 | { | |
1419 | constr->left.ResetIfWin(this); | |
1420 | constr->top.ResetIfWin(this); | |
1421 | constr->right.ResetIfWin(this); | |
1422 | constr->bottom.ResetIfWin(this); | |
1423 | constr->width.ResetIfWin(this); | |
1424 | constr->height.ResetIfWin(this); | |
1425 | constr->centreX.ResetIfWin(this); | |
1426 | constr->centreY.ResetIfWin(this); | |
1427 | } | |
1428 | ||
1429 | wxWindowList::Node *next = node->GetNext(); | |
1430 | delete node; | |
1431 | node = next; | |
1432 | } | |
1433 | ||
1434 | delete m_constraintsInvolvedIn; | |
1435 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
1436 | } | |
1437 | } | |
ec5bb70d VZ |
1438 | |
1439 | #endif // wxUSE_CONSTRAINTS | |
f03fc89f | 1440 | |
3aa5d532 | 1441 | void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld) |
f03fc89f | 1442 | { |
ec5bb70d VZ |
1443 | if ( deleteOld ) |
1444 | delete m_windowSizer; | |
3417c2cd | 1445 | |
f03fc89f | 1446 | m_windowSizer = sizer; |
566d84a7 | 1447 | |
ec5bb70d | 1448 | SetAutoLayout( sizer != NULL ); |
566d84a7 RL |
1449 | } |
1450 | ||
1451 | void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) | |
1452 | { | |
1453 | SetSizer( sizer, deleteOld ); | |
1454 | sizer->SetSizeHints( (wxWindow*) this ); | |
f03fc89f VZ |
1455 | } |
1456 | ||
ec5bb70d VZ |
1457 | #if wxUSE_CONSTRAINTS |
1458 | ||
1459 | void wxWindowBase::SatisfyConstraints() | |
1460 | { | |
1461 | wxLayoutConstraints *constr = GetConstraints(); | |
1462 | bool wasOk = constr && constr->AreSatisfied(); | |
1463 | ||
1464 | ResetConstraints(); // Mark all constraints as unevaluated | |
1465 | ||
1466 | int noChanges = 1; | |
1467 | ||
1468 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
1469 | // own constraints will never be satisfied any more unless we do it | |
1470 | // here | |
1471 | if ( wasOk ) | |
1472 | { | |
1473 | while ( noChanges > 0 ) | |
1474 | { | |
1475 | LayoutPhase1(&noChanges); | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | LayoutPhase2(&noChanges); | |
1480 | } | |
1481 | ||
1482 | #endif // wxUSE_CONSTRAINTS | |
1483 | ||
f03fc89f VZ |
1484 | bool wxWindowBase::Layout() |
1485 | { | |
3417c2cd | 1486 | // If there is a sizer, use it instead of the constraints |
f03fc89f VZ |
1487 | if ( GetSizer() ) |
1488 | { | |
f1df0927 | 1489 | int w, h; |
566d84a7 | 1490 | GetVirtualSize(&w, &h); |
3417c2cd | 1491 | GetSizer()->SetDimension( 0, 0, w, h ); |
f03fc89f | 1492 | } |
461e93f9 | 1493 | #if wxUSE_CONSTRAINTS |
f1df0927 | 1494 | else |
f03fc89f | 1495 | { |
ec5bb70d | 1496 | SatisfyConstraints(); // Find the right constraints values |
f1df0927 | 1497 | SetConstraintSizes(); // Recursively set the real window sizes |
f03fc89f | 1498 | } |
461e93f9 | 1499 | #endif |
5d4b632b | 1500 | |
f03fc89f VZ |
1501 | return TRUE; |
1502 | } | |
1503 | ||
461e93f9 | 1504 | #if wxUSE_CONSTRAINTS |
ec5bb70d VZ |
1505 | |
1506 | // first phase of the constraints evaluation: set our own constraints | |
f03fc89f VZ |
1507 | bool wxWindowBase::LayoutPhase1(int *noChanges) |
1508 | { | |
1509 | wxLayoutConstraints *constr = GetConstraints(); | |
ec5bb70d VZ |
1510 | |
1511 | return !constr || constr->SatisfyConstraints(this, noChanges); | |
f03fc89f VZ |
1512 | } |
1513 | ||
ec5bb70d | 1514 | // second phase: set the constraints for our children |
f03fc89f VZ |
1515 | bool wxWindowBase::LayoutPhase2(int *noChanges) |
1516 | { | |
1517 | *noChanges = 0; | |
1518 | ||
1519 | // Layout children | |
1520 | DoPhase(1); | |
ec5bb70d VZ |
1521 | |
1522 | // Layout grand children | |
f03fc89f | 1523 | DoPhase(2); |
ec5bb70d | 1524 | |
f03fc89f VZ |
1525 | return TRUE; |
1526 | } | |
1527 | ||
1528 | // Do a phase of evaluating child constraints | |
1529 | bool wxWindowBase::DoPhase(int phase) | |
1530 | { | |
ec5bb70d VZ |
1531 | // the list containing the children for which the constraints are already |
1532 | // set correctly | |
f03fc89f | 1533 | wxWindowList succeeded; |
ec5bb70d VZ |
1534 | |
1535 | // the max number of iterations we loop before concluding that we can't set | |
1536 | // the constraints | |
1537 | static const int maxIterations = 500; | |
1538 | ||
1539 | for ( int noIterations = 0; noIterations < maxIterations; noIterations++ ) | |
f03fc89f | 1540 | { |
ec5bb70d VZ |
1541 | int noChanges = 0; |
1542 | ||
1543 | // loop over all children setting their constraints | |
1544 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
1545 | node; | |
1546 | node = node->GetNext() ) | |
f03fc89f VZ |
1547 | { |
1548 | wxWindow *child = node->GetData(); | |
ec5bb70d | 1549 | if ( child->IsTopLevel() ) |
f03fc89f | 1550 | { |
ec5bb70d VZ |
1551 | // top level children are not inside our client area |
1552 | continue; | |
1553 | } | |
1554 | ||
1555 | if ( !child->GetConstraints() || succeeded.Find(child) ) | |
1556 | { | |
1557 | // this one is either already ok or nothing we can do about it | |
1558 | continue; | |
1559 | } | |
1560 | ||
1561 | int tempNoChanges = 0; | |
1562 | bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges) | |
1563 | : child->LayoutPhase2(&tempNoChanges); | |
1564 | noChanges += tempNoChanges; | |
1565 | ||
1566 | if ( success ) | |
1567 | { | |
1568 | succeeded.Append(child); | |
f03fc89f | 1569 | } |
f03fc89f VZ |
1570 | } |
1571 | ||
ec5bb70d VZ |
1572 | if ( !noChanges ) |
1573 | { | |
1574 | // constraints are set | |
1575 | break; | |
1576 | } | |
f03fc89f VZ |
1577 | } |
1578 | ||
1579 | return TRUE; | |
1580 | } | |
1581 | ||
1582 | void wxWindowBase::ResetConstraints() | |
1583 | { | |
1584 | wxLayoutConstraints *constr = GetConstraints(); | |
1585 | if ( constr ) | |
1586 | { | |
1587 | constr->left.SetDone(FALSE); | |
1588 | constr->top.SetDone(FALSE); | |
1589 | constr->right.SetDone(FALSE); | |
1590 | constr->bottom.SetDone(FALSE); | |
1591 | constr->width.SetDone(FALSE); | |
1592 | constr->height.SetDone(FALSE); | |
1593 | constr->centreX.SetDone(FALSE); | |
1594 | constr->centreY.SetDone(FALSE); | |
1595 | } | |
f1df0927 | 1596 | |
f03fc89f VZ |
1597 | wxWindowList::Node *node = GetChildren().GetFirst(); |
1598 | while (node) | |
1599 | { | |
1600 | wxWindow *win = node->GetData(); | |
34636400 | 1601 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
1602 | win->ResetConstraints(); |
1603 | node = node->GetNext(); | |
1604 | } | |
1605 | } | |
1606 | ||
1607 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
1608 | // and setting the real values. | |
1609 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
1610 | { | |
1611 | wxLayoutConstraints *constr = GetConstraints(); | |
4b7f2165 | 1612 | if ( constr && constr->AreSatisfied() ) |
f03fc89f VZ |
1613 | { |
1614 | int x = constr->left.GetValue(); | |
1615 | int y = constr->top.GetValue(); | |
1616 | int w = constr->width.GetValue(); | |
1617 | int h = constr->height.GetValue(); | |
1618 | ||
f03fc89f | 1619 | if ( (constr->width.GetRelationship() != wxAsIs ) || |
3417c2cd | 1620 | (constr->height.GetRelationship() != wxAsIs) ) |
f03fc89f | 1621 | { |
3417c2cd | 1622 | SetSize(x, y, w, h); |
f03fc89f VZ |
1623 | } |
1624 | else | |
1625 | { | |
3417c2cd RR |
1626 | // If we don't want to resize this window, just move it... |
1627 | Move(x, y); | |
f03fc89f VZ |
1628 | } |
1629 | } | |
1630 | else if ( constr ) | |
1631 | { | |
4b7f2165 | 1632 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), |
f1df0927 | 1633 | GetClassInfo()->GetClassName(), |
4b7f2165 | 1634 | GetName().c_str()); |
f03fc89f VZ |
1635 | } |
1636 | ||
1637 | if ( recurse ) | |
1638 | { | |
1639 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1640 | while (node) | |
1641 | { | |
1642 | wxWindow *win = node->GetData(); | |
e2f9212c | 1643 | if ( !win->IsTopLevel() && win->GetConstraints() ) |
f03fc89f VZ |
1644 | win->SetConstraintSizes(); |
1645 | node = node->GetNext(); | |
1646 | } | |
1647 | } | |
1648 | } | |
1649 | ||
f03fc89f VZ |
1650 | // Only set the size/position of the constraint (if any) |
1651 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
1652 | { | |
1653 | wxLayoutConstraints *constr = GetConstraints(); | |
1654 | if ( constr ) | |
1655 | { | |
1656 | if ( x != -1 ) | |
1657 | { | |
1658 | constr->left.SetValue(x); | |
1659 | constr->left.SetDone(TRUE); | |
1660 | } | |
1661 | if ( y != -1 ) | |
1662 | { | |
1663 | constr->top.SetValue(y); | |
1664 | constr->top.SetDone(TRUE); | |
1665 | } | |
1666 | if ( w != -1 ) | |
1667 | { | |
1668 | constr->width.SetValue(w); | |
1669 | constr->width.SetDone(TRUE); | |
1670 | } | |
1671 | if ( h != -1 ) | |
1672 | { | |
1673 | constr->height.SetValue(h); | |
1674 | constr->height.SetDone(TRUE); | |
1675 | } | |
1676 | } | |
1677 | } | |
1678 | ||
1679 | void wxWindowBase::MoveConstraint(int x, int y) | |
1680 | { | |
1681 | wxLayoutConstraints *constr = GetConstraints(); | |
1682 | if ( constr ) | |
1683 | { | |
1684 | if ( x != -1 ) | |
1685 | { | |
1686 | constr->left.SetValue(x); | |
1687 | constr->left.SetDone(TRUE); | |
1688 | } | |
1689 | if ( y != -1 ) | |
1690 | { | |
1691 | constr->top.SetValue(y); | |
1692 | constr->top.SetDone(TRUE); | |
1693 | } | |
1694 | } | |
1695 | } | |
1696 | ||
1697 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
1698 | { | |
1699 | wxLayoutConstraints *constr = GetConstraints(); | |
1700 | if ( constr ) | |
1701 | { | |
1702 | *w = constr->width.GetValue(); | |
1703 | *h = constr->height.GetValue(); | |
1704 | } | |
1705 | else | |
1706 | GetSize(w, h); | |
1707 | } | |
1708 | ||
1709 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
1710 | { | |
1711 | wxLayoutConstraints *constr = GetConstraints(); | |
1712 | if ( constr ) | |
1713 | { | |
1714 | *w = constr->width.GetValue(); | |
1715 | *h = constr->height.GetValue(); | |
1716 | } | |
1717 | else | |
1718 | GetClientSize(w, h); | |
1719 | } | |
1720 | ||
461e93f9 JS |
1721 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const |
1722 | { | |
1723 | wxLayoutConstraints *constr = GetConstraints(); | |
1724 | if ( constr ) | |
1725 | { | |
1726 | *x = constr->left.GetValue(); | |
1727 | *y = constr->top.GetValue(); | |
1728 | } | |
1729 | else | |
1730 | GetPosition(x, y); | |
1731 | } | |
1732 | ||
1733 | #endif // wxUSE_CONSTRAINTS | |
1734 | ||
20a1eea1 | 1735 | void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const |
a200c35e VS |
1736 | { |
1737 | // don't do it for the dialogs/frames - they float independently of their | |
1738 | // parent | |
1739 | if ( !IsTopLevel() ) | |
1740 | { | |
1741 | wxWindow *parent = GetParent(); | |
1742 | if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent ) | |
1743 | { | |
1744 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1745 | x += pt.x; | |
1746 | y += pt.y; | |
1747 | } | |
1748 | } | |
1749 | } | |
1750 | ||
f03fc89f VZ |
1751 | // ---------------------------------------------------------------------------- |
1752 | // do Update UI processing for child controls | |
1753 | // ---------------------------------------------------------------------------- | |
7ec1983b VZ |
1754 | |
1755 | // TODO: should this be implemented for the child window rather | |
1756 | // than the parent? Then you can override it e.g. for wxCheckBox | |
1757 | // to do the Right Thing rather than having to assume a fixed number | |
1758 | // of control classes. | |
f03fc89f | 1759 | void wxWindowBase::UpdateWindowUI() |
7ec1983b | 1760 | { |
1e6feb95 | 1761 | #if wxUSE_CONTROLS |
26bf1ce0 VZ |
1762 | wxUpdateUIEvent event(GetId()); |
1763 | event.m_eventObject = this; | |
1764 | ||
1765 | if ( GetEventHandler()->ProcessEvent(event) ) | |
7ec1983b | 1766 | { |
26bf1ce0 VZ |
1767 | if ( event.GetSetEnabled() ) |
1768 | Enable(event.GetEnabled()); | |
7ec1983b | 1769 | |
26bf1ce0 | 1770 | if ( event.GetSetText() ) |
f03fc89f | 1771 | { |
f7637829 | 1772 | wxControl *control = wxDynamicCastThis(wxControl); |
26bf1ce0 | 1773 | if ( control ) |
34636400 | 1774 | { |
1e6feb95 | 1775 | #if wxUSE_TEXTCTRL |
26bf1ce0 VZ |
1776 | wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl); |
1777 | if ( text ) | |
2b5f62a0 VZ |
1778 | { |
1779 | if ( event.GetText() != text->GetValue() ) | |
1780 | text->SetValue(event.GetText()); | |
1781 | } | |
26bf1ce0 | 1782 | else |
1e6feb95 | 1783 | #endif // wxUSE_TEXTCTRL |
2b5f62a0 VZ |
1784 | { |
1785 | if ( event.GetText() != control->GetLabel() ) | |
1786 | control->SetLabel(event.GetText()); | |
1787 | } | |
34636400 | 1788 | } |
26bf1ce0 | 1789 | } |
f03fc89f | 1790 | |
88ac883a | 1791 | #if wxUSE_CHECKBOX |
f7637829 | 1792 | wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox); |
26bf1ce0 VZ |
1793 | if ( checkbox ) |
1794 | { | |
1795 | if ( event.GetSetChecked() ) | |
1796 | checkbox->SetValue(event.GetChecked()); | |
1797 | } | |
88ac883a VZ |
1798 | #endif // wxUSE_CHECKBOX |
1799 | ||
b3402d0d | 1800 | #if wxUSE_RADIOBTN |
f7637829 | 1801 | wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton); |
26bf1ce0 VZ |
1802 | if ( radiobtn ) |
1803 | { | |
1804 | if ( event.GetSetChecked() ) | |
1805 | radiobtn->SetValue(event.GetChecked()); | |
f03fc89f | 1806 | } |
b3402d0d | 1807 | #endif // wxUSE_RADIOBTN |
7ec1983b | 1808 | } |
1e6feb95 | 1809 | #endif // wxUSE_CONTROLS |
7ec1983b | 1810 | } |
fd71308f | 1811 | |
f03fc89f VZ |
1812 | // ---------------------------------------------------------------------------- |
1813 | // dialog units translations | |
1814 | // ---------------------------------------------------------------------------- | |
1815 | ||
1816 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) | |
fd71308f JS |
1817 | { |
1818 | int charWidth = GetCharWidth(); | |
1819 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1820 | wxPoint pt2(-1, -1); |
1821 | if (pt.x != -1) | |
1822 | pt2.x = (int) ((pt.x * 4) / charWidth) ; | |
1823 | if (pt.y != -1) | |
1824 | pt2.y = (int) ((pt.y * 8) / charHeight) ; | |
fd71308f JS |
1825 | |
1826 | return pt2; | |
1827 | } | |
1828 | ||
f03fc89f | 1829 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) |
fd71308f JS |
1830 | { |
1831 | int charWidth = GetCharWidth(); | |
1832 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1833 | wxPoint pt2(-1, -1); |
1834 | if (pt.x != -1) | |
1835 | pt2.x = (int) ((pt.x * charWidth) / 4) ; | |
1836 | if (pt.y != -1) | |
1837 | pt2.y = (int) ((pt.y * charHeight) / 8) ; | |
fd71308f JS |
1838 | |
1839 | return pt2; | |
1840 | } | |
1841 | ||
f03fc89f VZ |
1842 | // ---------------------------------------------------------------------------- |
1843 | // event handlers | |
1844 | // ---------------------------------------------------------------------------- | |
1845 | ||
1846 | // propagate the colour change event to the subwindows | |
1847 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1848 | { | |
1849 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1850 | while ( node ) | |
1851 | { | |
1852 | // Only propagate to non-top-level windows | |
1853 | wxWindow *win = node->GetData(); | |
1854 | if ( !win->IsTopLevel() ) | |
1855 | { | |
1856 | wxSysColourChangedEvent event2; | |
1857 | event.m_eventObject = win; | |
1858 | win->GetEventHandler()->ProcessEvent(event2); | |
1859 | } | |
1860 | ||
1861 | node = node->GetNext(); | |
1862 | } | |
1863 | } | |
1864 | ||
1865 | // the default action is to populate dialog with data when it's created | |
1866 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) | |
1867 | { | |
1868 | TransferDataToWindow(); | |
1869 | } | |
1870 | ||
a02dc3e3 VZ |
1871 | // process Ctrl-Alt-mclick |
1872 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) | |
1873 | { | |
1e6feb95 | 1874 | #if wxUSE_MSGDLG |
a02dc3e3 VZ |
1875 | if ( event.ControlDown() && event.AltDown() ) |
1876 | { | |
1877 | // don't translate these strings | |
1878 | wxString port; | |
af3062a8 VZ |
1879 | |
1880 | #ifdef __WXUNIVERSAL__ | |
1881 | port = _T("Univ/"); | |
1882 | #endif // __WXUNIVERSAL__ | |
1883 | ||
a02dc3e3 VZ |
1884 | switch ( wxGetOsVersion() ) |
1885 | { | |
ea8e90b7 | 1886 | case wxMOTIF_X: port += _T("Motif"); break; |
ff8fda36 | 1887 | case wxMAC: |
ea8e90b7 VZ |
1888 | case wxMAC_DARWIN: port += _T("Mac"); break; |
1889 | case wxBEOS: port += _T("BeOS"); break; | |
a02dc3e3 VZ |
1890 | case wxGTK: |
1891 | case wxGTK_WIN32: | |
1892 | case wxGTK_OS2: | |
ea8e90b7 | 1893 | case wxGTK_BEOS: port += _T("GTK"); break; |
a02dc3e3 VZ |
1894 | case wxWINDOWS: |
1895 | case wxPENWINDOWS: | |
1896 | case wxWINDOWS_NT: | |
1897 | case wxWIN32S: | |
1898 | case wxWIN95: | |
ea8e90b7 | 1899 | case wxWIN386: port += _T("MS Windows"); break; |
a02dc3e3 VZ |
1900 | case wxMGL_UNIX: |
1901 | case wxMGL_X: | |
1902 | case wxMGL_WIN32: | |
ea8e90b7 | 1903 | case wxMGL_OS2: port += _T("MGL"); break; |
a02dc3e3 | 1904 | case wxWINDOWS_OS2: |
ea8e90b7 VZ |
1905 | case wxOS2_PM: port += _T("OS/2"); break; |
1906 | default: port += _T("unknown"); break; | |
a02dc3e3 VZ |
1907 | } |
1908 | ||
1909 | wxMessageBox(wxString::Format( | |
1910 | _T( | |
af3062a8 | 1911 | " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team" |
a02dc3e3 VZ |
1912 | ), |
1913 | port.c_str(), | |
1914 | wxMAJOR_VERSION, | |
1915 | wxMINOR_VERSION, | |
1916 | wxRELEASE_NUMBER, | |
3f562374 VZ |
1917 | #if wxUSE_UNICODE |
1918 | L" (Unicode)", | |
1919 | #else | |
1920 | "", | |
1921 | #endif | |
1922 | __TDATE__, | |
1923 | __TTIME__ | |
a02dc3e3 VZ |
1924 | ), |
1925 | _T("wxWindows information"), | |
1926 | wxICON_INFORMATION | wxOK, | |
1927 | (wxWindow *)this); | |
1928 | } | |
1929 | else | |
1e6feb95 | 1930 | #endif // wxUSE_MSGDLG |
a02dc3e3 VZ |
1931 | { |
1932 | event.Skip(); | |
1933 | } | |
1934 | } | |
1935 | ||
f03fc89f VZ |
1936 | // ---------------------------------------------------------------------------- |
1937 | // list classes implementation | |
1938 | // ---------------------------------------------------------------------------- | |
1939 | ||
1940 | void wxWindowListNode::DeleteData() | |
1941 | { | |
1942 | delete (wxWindow *)GetData(); | |
1943 | } | |
1944 | ||
1e6feb95 VZ |
1945 | // ---------------------------------------------------------------------------- |
1946 | // borders | |
1947 | // ---------------------------------------------------------------------------- | |
1948 | ||
1949 | wxBorder wxWindowBase::GetBorder() const | |
1950 | { | |
1951 | wxBorder border = (wxBorder)(m_windowStyle & wxBORDER_MASK); | |
1952 | if ( border == wxBORDER_DEFAULT ) | |
1953 | { | |
1954 | border = GetDefaultBorder(); | |
1955 | } | |
1956 | ||
1957 | return border; | |
1958 | } | |
1959 | ||
1960 | wxBorder wxWindowBase::GetDefaultBorder() const | |
1961 | { | |
1962 | return wxBORDER_NONE; | |
1963 | } | |
1964 | ||
1965 | // ---------------------------------------------------------------------------- | |
1966 | // hit testing | |
1967 | // ---------------------------------------------------------------------------- | |
1968 | ||
1969 | wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const | |
1970 | { | |
1971 | // here we just check if the point is inside the window or not | |
1972 | ||
1973 | // check the top and left border first | |
1974 | bool outside = x < 0 || y < 0; | |
1975 | if ( !outside ) | |
1976 | { | |
1977 | // check the right and bottom borders too | |
1978 | wxSize size = GetSize(); | |
1979 | outside = x >= size.x || y >= size.y; | |
1980 | } | |
1981 | ||
1982 | return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE; | |
1983 | } | |
1984 | ||
94633ad9 VZ |
1985 | // ---------------------------------------------------------------------------- |
1986 | // mouse capture | |
1987 | // ---------------------------------------------------------------------------- | |
1988 | ||
1989 | struct WXDLLEXPORT wxWindowNext | |
1990 | { | |
1991 | wxWindow *win; | |
1992 | wxWindowNext *next; | |
786646f3 | 1993 | } *wxWindowBase::ms_winCaptureNext = NULL; |
94633ad9 | 1994 | |
a83e1475 | 1995 | void wxWindowBase::CaptureMouse() |
94633ad9 | 1996 | { |
7e555446 | 1997 | wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this); |
45e0dc94 | 1998 | |
94633ad9 VZ |
1999 | wxWindow *winOld = GetCapture(); |
2000 | if ( winOld ) | |
2001 | { | |
df2f507b | 2002 | ((wxWindowBase*) winOld)->DoReleaseMouse(); |
edd802c6 | 2003 | |
94633ad9 VZ |
2004 | // save it on stack |
2005 | wxWindowNext *item = new wxWindowNext; | |
2006 | item->win = winOld; | |
2007 | item->next = ms_winCaptureNext; | |
2008 | ms_winCaptureNext = item; | |
2009 | } | |
2010 | //else: no mouse capture to save | |
2011 | ||
2012 | DoCaptureMouse(); | |
2013 | } | |
2014 | ||
a83e1475 | 2015 | void wxWindowBase::ReleaseMouse() |
94633ad9 | 2016 | { |
7e555446 | 2017 | wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this); |
349d1942 | 2018 | |
63fd5f0b | 2019 | wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") ); |
a7b09001 | 2020 | |
94633ad9 VZ |
2021 | DoReleaseMouse(); |
2022 | ||
2023 | if ( ms_winCaptureNext ) | |
2024 | { | |
44f8caa7 | 2025 | ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse(); |
edd802c6 | 2026 | |
94633ad9 VZ |
2027 | wxWindowNext *item = ms_winCaptureNext; |
2028 | ms_winCaptureNext = item->next; | |
2029 | delete item; | |
2030 | } | |
2031 | //else: stack is empty, no previous capture | |
2032 | ||
2033 | wxLogTrace(_T("mousecapture"), | |
7e555446 | 2034 | _T("After ReleaseMouse() mouse is captured by %p"), |
94633ad9 VZ |
2035 | GetCapture()); |
2036 | } | |
2037 | ||
33b494d6 VZ |
2038 | // ---------------------------------------------------------------------------- |
2039 | // global functions | |
2040 | // ---------------------------------------------------------------------------- | |
2041 | ||
2042 | wxWindow* wxGetTopLevelParent(wxWindow *win) | |
2043 | { | |
2044 | while ( win && !win->IsTopLevel() ) | |
2045 | win = win->GetParent(); | |
2046 | ||
2047 | return win; | |
2048 | } | |
2049 | ||
7e555446 | 2050 | // vi:sts=4:sw=4:et |