]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: common/window.cpp | |
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$ | |
8 | // Copyright: (c) wxWidgets team | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
21 | #pragma implementation "windowbase.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
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" | |
38 | #include "wx/control.h" | |
39 | #include "wx/checkbox.h" | |
40 | #include "wx/radiobut.h" | |
41 | #include "wx/statbox.h" | |
42 | #include "wx/textctrl.h" | |
43 | #include "wx/settings.h" | |
44 | #include "wx/dialog.h" | |
45 | #include "wx/msgdlg.h" | |
46 | #include "wx/statusbr.h" | |
47 | #include "wx/dcclient.h" | |
48 | #endif //WX_PRECOMP | |
49 | ||
50 | #if defined(__WXMAC__) && wxUSE_SCROLLBAR | |
51 | #include "wx/scrolbar.h" | |
52 | #endif | |
53 | ||
54 | #if wxUSE_CONSTRAINTS | |
55 | #include "wx/layout.h" | |
56 | #endif // wxUSE_CONSTRAINTS | |
57 | ||
58 | #include "wx/sizer.h" | |
59 | ||
60 | #if wxUSE_DRAG_AND_DROP | |
61 | #include "wx/dnd.h" | |
62 | #endif // wxUSE_DRAG_AND_DROP | |
63 | ||
64 | #if wxUSE_ACCESSIBILITY | |
65 | #include "wx/access.h" | |
66 | #endif | |
67 | ||
68 | #if wxUSE_HELP | |
69 | #include "wx/cshelp.h" | |
70 | #endif // wxUSE_HELP | |
71 | ||
72 | #if wxUSE_TOOLTIPS | |
73 | #include "wx/tooltip.h" | |
74 | #endif // wxUSE_TOOLTIPS | |
75 | ||
76 | #if wxUSE_CARET | |
77 | #include "wx/caret.h" | |
78 | #endif // wxUSE_CARET | |
79 | ||
80 | #if wxUSE_SYSTEM_OPTIONS | |
81 | #include "wx/sysopt.h" | |
82 | #endif | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // static data | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | #if defined(__WXPALMOS__) | |
89 | int wxWindowBase::ms_lastControlId = 32767; | |
90 | #elif defined(__WXPM__) | |
91 | int wxWindowBase::ms_lastControlId = 2000; | |
92 | #else | |
93 | int wxWindowBase::ms_lastControlId = -200; | |
94 | #endif | |
95 | ||
96 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | // event table | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
102 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
103 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
104 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
105 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) | |
106 | ||
107 | #if wxUSE_HELP | |
108 | EVT_HELP(wxID_ANY, wxWindowBase::OnHelp) | |
109 | #endif // wxUSE_HELP | |
110 | ||
111 | END_EVENT_TABLE() | |
112 | ||
113 | // ============================================================================ | |
114 | // implementation of the common functionality of the wxWindow class | |
115 | // ============================================================================ | |
116 | ||
117 | // ---------------------------------------------------------------------------- | |
118 | // initialization | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
121 | // the default initialization | |
122 | wxWindowBase::wxWindowBase() | |
123 | { | |
124 | // no window yet, no parent nor children | |
125 | m_parent = (wxWindow *)NULL; | |
126 | m_windowId = wxID_ANY; | |
127 | ||
128 | // no constraints on the minimal window size | |
129 | m_minWidth = | |
130 | m_maxWidth = wxDefaultCoord; | |
131 | m_minHeight = | |
132 | m_maxHeight = wxDefaultCoord; | |
133 | ||
134 | // invalidiated cache value | |
135 | m_bestSizeCache = wxDefaultSize; | |
136 | ||
137 | // window are created enabled and visible by default | |
138 | m_isShown = | |
139 | m_isEnabled = true; | |
140 | ||
141 | // the default event handler is just this window | |
142 | m_eventHandler = this; | |
143 | ||
144 | #if wxUSE_VALIDATORS | |
145 | // no validator | |
146 | m_windowValidator = (wxValidator *) NULL; | |
147 | #endif // wxUSE_VALIDATORS | |
148 | ||
149 | // the colours/fonts are default for now, so leave m_font, | |
150 | // m_backgroundColour and m_foregroundColour uninitialized and set those | |
151 | m_hasBgCol = | |
152 | m_hasFgCol = | |
153 | m_hasFont = false; | |
154 | m_inheritBgCol = | |
155 | m_inheritFgCol = | |
156 | m_inheritFont = false; | |
157 | ||
158 | // no style bits | |
159 | m_exStyle = | |
160 | m_windowStyle = 0; | |
161 | ||
162 | m_backgroundStyle = wxBG_STYLE_SYSTEM; | |
163 | ||
164 | #if wxUSE_CONSTRAINTS | |
165 | // no constraints whatsoever | |
166 | m_constraints = (wxLayoutConstraints *) NULL; | |
167 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
168 | #endif // wxUSE_CONSTRAINTS | |
169 | ||
170 | m_windowSizer = (wxSizer *) NULL; | |
171 | m_containingSizer = (wxSizer *) NULL; | |
172 | m_autoLayout = false; | |
173 | ||
174 | #if wxUSE_DRAG_AND_DROP | |
175 | m_dropTarget = (wxDropTarget *)NULL; | |
176 | #endif // wxUSE_DRAG_AND_DROP | |
177 | ||
178 | #if wxUSE_TOOLTIPS | |
179 | m_tooltip = (wxToolTip *)NULL; | |
180 | #endif // wxUSE_TOOLTIPS | |
181 | ||
182 | #if wxUSE_CARET | |
183 | m_caret = (wxCaret *)NULL; | |
184 | #endif // wxUSE_CARET | |
185 | ||
186 | #if wxUSE_PALETTE | |
187 | m_hasCustomPalette = false; | |
188 | #endif // wxUSE_PALETTE | |
189 | ||
190 | #if wxUSE_ACCESSIBILITY | |
191 | m_accessible = NULL; | |
192 | #endif | |
193 | ||
194 | m_virtualSize = wxDefaultSize; | |
195 | ||
196 | m_minVirtualWidth = | |
197 | m_maxVirtualWidth = wxDefaultCoord; | |
198 | m_minVirtualHeight = | |
199 | m_maxVirtualHeight = wxDefaultCoord; | |
200 | ||
201 | m_windowVariant = wxWINDOW_VARIANT_NORMAL; | |
202 | #if wxUSE_SYSTEM_OPTIONS | |
203 | if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT) ) | |
204 | { | |
205 | m_windowVariant = (wxWindowVariant) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT ) ; | |
206 | } | |
207 | #endif | |
208 | ||
209 | // Whether we're using the current theme for this window (wxGTK only for now) | |
210 | m_themeEnabled = false; | |
211 | ||
212 | // VZ: this one shouldn't exist... | |
213 | m_isBeingDeleted = false; | |
214 | } | |
215 | ||
216 | // common part of window creation process | |
217 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
218 | wxWindowID id, | |
219 | const wxPoint& WXUNUSED(pos), | |
220 | const wxSize& WXUNUSED(size), | |
221 | long style, | |
222 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
223 | const wxString& name) | |
224 | { | |
225 | #if wxUSE_STATBOX | |
226 | // wxGTK doesn't allow to create controls with static box as the parent so | |
227 | // this will result in a crash when the program is ported to wxGTK so warn | |
228 | // the user about it | |
229 | ||
230 | // if you get this assert, the correct solution is to create the controls | |
231 | // as siblings of the static box | |
232 | wxASSERT_MSG( !parent || !wxDynamicCast(parent, wxStaticBox), | |
233 | _T("wxStaticBox can't be used as a window parent!") ); | |
234 | #endif // wxUSE_STATBOX | |
235 | ||
236 | // ids are limited to 16 bits under MSW so if you care about portability, | |
237 | // it's not a good idea to use ids out of this range (and negative ids are | |
238 | // reserved for wxWidgets own usage) | |
239 | wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767), | |
240 | _T("invalid id value") ); | |
241 | ||
242 | // generate a new id if the user doesn't care about it | |
243 | m_windowId = id == wxID_ANY ? NewControlId() : id; | |
244 | ||
245 | SetName(name); | |
246 | SetWindowStyleFlag(style); | |
247 | SetParent(parent); | |
248 | ||
249 | #if wxUSE_VALIDATORS | |
250 | SetValidator(validator); | |
251 | #endif // wxUSE_VALIDATORS | |
252 | ||
253 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to | |
254 | // have it too - like this it's possible to set it only in the top level | |
255 | // dialog/frame and all children will inherit it by defult | |
256 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
257 | { | |
258 | SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY); | |
259 | } | |
260 | ||
261 | return true; | |
262 | } | |
263 | ||
264 | // ---------------------------------------------------------------------------- | |
265 | // destruction | |
266 | // ---------------------------------------------------------------------------- | |
267 | ||
268 | // common clean up | |
269 | wxWindowBase::~wxWindowBase() | |
270 | { | |
271 | wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") ); | |
272 | ||
273 | // FIXME if these 2 cases result from programming errors in the user code | |
274 | // we should probably assert here instead of silently fixing them | |
275 | ||
276 | // Just in case the window has been Closed, but we're then deleting | |
277 | // immediately: don't leave dangling pointers. | |
278 | wxPendingDelete.DeleteObject(this); | |
279 | ||
280 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
281 | // we weren't a dialog class | |
282 | wxTopLevelWindows.DeleteObject((wxWindow*)this); | |
283 | ||
284 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); | |
285 | ||
286 | // reset the dangling pointer our parent window may keep to us | |
287 | if ( m_parent ) | |
288 | { | |
289 | if ( m_parent->GetDefaultItem() == this ) | |
290 | { | |
291 | m_parent->SetDefaultItem(NULL); | |
292 | } | |
293 | ||
294 | m_parent->RemoveChild(this); | |
295 | } | |
296 | ||
297 | #if wxUSE_CARET | |
298 | delete m_caret; | |
299 | #endif // wxUSE_CARET | |
300 | ||
301 | #if wxUSE_VALIDATORS | |
302 | delete m_windowValidator; | |
303 | #endif // wxUSE_VALIDATORS | |
304 | ||
305 | #if wxUSE_CONSTRAINTS | |
306 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
307 | // at deleted windows as they delete themselves. | |
308 | DeleteRelatedConstraints(); | |
309 | ||
310 | if ( m_constraints ) | |
311 | { | |
312 | // This removes any dangling pointers to this window in other windows' | |
313 | // constraintsInvolvedIn lists. | |
314 | UnsetConstraints(m_constraints); | |
315 | delete m_constraints; | |
316 | m_constraints = NULL; | |
317 | } | |
318 | #endif // wxUSE_CONSTRAINTS | |
319 | ||
320 | if ( m_containingSizer ) | |
321 | m_containingSizer->Detach( (wxWindow*)this ); | |
322 | ||
323 | delete m_windowSizer; | |
324 | ||
325 | #if wxUSE_DRAG_AND_DROP | |
326 | delete m_dropTarget; | |
327 | #endif // wxUSE_DRAG_AND_DROP | |
328 | ||
329 | #if wxUSE_TOOLTIPS | |
330 | delete m_tooltip; | |
331 | #endif // wxUSE_TOOLTIPS | |
332 | ||
333 | #if wxUSE_ACCESSIBILITY | |
334 | delete m_accessible; | |
335 | #endif | |
336 | } | |
337 | ||
338 | bool wxWindowBase::Destroy() | |
339 | { | |
340 | delete this; | |
341 | ||
342 | return true; | |
343 | } | |
344 | ||
345 | bool wxWindowBase::Close(bool force) | |
346 | { | |
347 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
348 | event.SetEventObject(this); | |
349 | event.SetCanVeto(!force); | |
350 | ||
351 | // return false if window wasn't closed because the application vetoed the | |
352 | // close event | |
353 | return GetEventHandler()->ProcessEvent(event) && !event.GetVeto(); | |
354 | } | |
355 | ||
356 | bool wxWindowBase::DestroyChildren() | |
357 | { | |
358 | wxWindowList::compatibility_iterator node; | |
359 | for ( ;; ) | |
360 | { | |
361 | // we iterate until the list becomes empty | |
362 | node = GetChildren().GetFirst(); | |
363 | if ( !node ) | |
364 | break; | |
365 | ||
366 | wxWindow *child = node->GetData(); | |
367 | ||
368 | // note that we really want to call delete and not ->Destroy() here | |
369 | // because we want to delete the child immediately, before we are | |
370 | // deleted, and delayed deletion would result in problems as our (top | |
371 | // level) child could outlive its parent | |
372 | delete child; | |
373 | ||
374 | wxASSERT_MSG( !GetChildren().Find(child), | |
375 | wxT("child didn't remove itself using RemoveChild()") ); | |
376 | } | |
377 | ||
378 | return true; | |
379 | } | |
380 | ||
381 | // ---------------------------------------------------------------------------- | |
382 | // size/position related methods | |
383 | // ---------------------------------------------------------------------------- | |
384 | ||
385 | // centre the window with respect to its parent in either (or both) directions | |
386 | void wxWindowBase::Centre(int direction) | |
387 | { | |
388 | // the position/size of the parent window or of the entire screen | |
389 | wxPoint posParent; | |
390 | int widthParent, heightParent; | |
391 | ||
392 | wxWindow *parent = NULL; | |
393 | wxTopLevelWindow *winTop = NULL; | |
394 | ||
395 | if ( !(direction & wxCENTRE_ON_SCREEN) ) | |
396 | { | |
397 | // find the parent to centre this window on: it should be the | |
398 | // immediate parent for the controls but the top level parent for the | |
399 | // top level windows (like dialogs) | |
400 | parent = GetParent(); | |
401 | if ( IsTopLevel() ) | |
402 | { | |
403 | while ( parent && !parent->IsTopLevel() ) | |
404 | { | |
405 | parent = parent->GetParent(); | |
406 | } | |
407 | } | |
408 | ||
409 | // there is no wxTopLevelWindow under wxMotif yet | |
410 | #ifndef __WXMOTIF__ | |
411 | // we shouldn't center the dialog on the iconized window: under | |
412 | // Windows, for example, this places it completely off the screen | |
413 | if ( parent ) | |
414 | { | |
415 | winTop = wxDynamicCast(parent, wxTopLevelWindow); | |
416 | if ( winTop && winTop->IsIconized() ) | |
417 | { | |
418 | winTop = NULL; | |
419 | parent = NULL; | |
420 | } | |
421 | } | |
422 | #endif // __WXMOTIF__ | |
423 | ||
424 | // did we find the parent? | |
425 | if ( !parent ) | |
426 | { | |
427 | // no other choice | |
428 | direction |= wxCENTRE_ON_SCREEN; | |
429 | } | |
430 | } | |
431 | ||
432 | if ( direction & wxCENTRE_ON_SCREEN ) | |
433 | { | |
434 | // centre with respect to the whole screen | |
435 | wxDisplaySize(&widthParent, &heightParent); | |
436 | } | |
437 | else | |
438 | { | |
439 | if ( IsTopLevel() ) | |
440 | { | |
441 | if(winTop) | |
442 | winTop->GetRectForTopLevelChildren(&posParent.x, &posParent.y, &widthParent, &heightParent); | |
443 | else | |
444 | { | |
445 | // centre on the parent | |
446 | parent->GetSize(&widthParent, &heightParent); | |
447 | ||
448 | // adjust to the parents position | |
449 | posParent = parent->GetPosition(); | |
450 | } | |
451 | } | |
452 | else | |
453 | { | |
454 | // centre inside the parents client rectangle | |
455 | parent->GetClientSize(&widthParent, &heightParent); | |
456 | } | |
457 | } | |
458 | ||
459 | int width, height; | |
460 | GetSize(&width, &height); | |
461 | ||
462 | int xNew = wxDefaultCoord, | |
463 | yNew = wxDefaultCoord; | |
464 | ||
465 | if ( direction & wxHORIZONTAL ) | |
466 | xNew = (widthParent - width)/2; | |
467 | ||
468 | if ( direction & wxVERTICAL ) | |
469 | yNew = (heightParent - height)/2; | |
470 | ||
471 | xNew += posParent.x; | |
472 | yNew += posParent.y; | |
473 | ||
474 | // Base size of the visible dimensions of the display | |
475 | // to take into account the taskbar. And the Mac menu bar at top. | |
476 | wxRect clientrect = wxGetClientDisplayRect(); | |
477 | ||
478 | // NB: in wxMSW, negative position may not neccessary mean "out of screen", | |
479 | // but it may mean that the window is placed on other than the main | |
480 | // display. Therefore we only make sure centered window is on the main display | |
481 | // if the parent is at least partially present here. | |
482 | if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display | |
483 | { | |
484 | if (xNew < clientrect.GetLeft()) | |
485 | xNew = clientrect.GetLeft(); | |
486 | else if (xNew + width > clientrect.GetRight()) | |
487 | xNew = clientrect.GetRight() - width; | |
488 | } | |
489 | if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display | |
490 | { | |
491 | if (yNew + height > clientrect.GetBottom()) | |
492 | yNew = clientrect.GetBottom() - height; | |
493 | ||
494 | // Make certain that the title bar is initially visible | |
495 | // always, even if this would push the bottom of the | |
496 | // dialog off the visible area of the display | |
497 | if (yNew < clientrect.GetTop()) | |
498 | yNew = clientrect.GetTop(); | |
499 | } | |
500 | ||
501 | // move the window to this position (keeping the old size but using | |
502 | // SetSize() and not Move() to allow xNew and/or yNew to be wxDefaultCoord) | |
503 | SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE); | |
504 | } | |
505 | ||
506 | // fits the window around the children | |
507 | void wxWindowBase::Fit() | |
508 | { | |
509 | if ( GetChildren().GetCount() > 0 ) | |
510 | { | |
511 | SetSize(GetBestSize()); | |
512 | } | |
513 | //else: do nothing if we have no children | |
514 | } | |
515 | ||
516 | // fits virtual size (ie. scrolled area etc.) around children | |
517 | void wxWindowBase::FitInside() | |
518 | { | |
519 | if ( GetChildren().GetCount() > 0 ) | |
520 | { | |
521 | SetVirtualSize( GetBestVirtualSize() ); | |
522 | } | |
523 | } | |
524 | ||
525 | // On Mac, scrollbars are explicitly children. | |
526 | #ifdef __WXMAC__ | |
527 | static bool wxHasRealChildren(const wxWindowBase* win) | |
528 | { | |
529 | int realChildCount = 0; | |
530 | ||
531 | for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); | |
532 | node; | |
533 | node = node->GetNext() ) | |
534 | { | |
535 | wxWindow *win = node->GetData(); | |
536 | if ( !win->IsTopLevel() && win->IsShown() && !win->IsKindOf(CLASSINFO(wxScrollBar))) | |
537 | realChildCount ++; | |
538 | } | |
539 | return (realChildCount > 0); | |
540 | } | |
541 | #endif | |
542 | ||
543 | void wxWindowBase::InvalidateBestSize() | |
544 | { | |
545 | m_bestSizeCache = wxDefaultSize; | |
546 | ||
547 | // parent's best size calculation may depend on its children's | |
548 | // best sizes, so let's invalidate it as well to be safe: | |
549 | if (m_parent) | |
550 | m_parent->InvalidateBestSize(); | |
551 | } | |
552 | ||
553 | // return the size best suited for the current window | |
554 | wxSize wxWindowBase::DoGetBestSize() const | |
555 | { | |
556 | wxSize best; | |
557 | ||
558 | if ( m_windowSizer ) | |
559 | { | |
560 | best = m_windowSizer->GetMinSize(); | |
561 | } | |
562 | #if wxUSE_CONSTRAINTS | |
563 | else if ( m_constraints ) | |
564 | { | |
565 | wxConstCast(this, wxWindowBase)->SatisfyConstraints(); | |
566 | ||
567 | // our minimal acceptable size is such that all our windows fit inside | |
568 | int maxX = 0, | |
569 | maxY = 0; | |
570 | ||
571 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
572 | node; | |
573 | node = node->GetNext() ) | |
574 | { | |
575 | wxLayoutConstraints *c = node->GetData()->GetConstraints(); | |
576 | if ( !c ) | |
577 | { | |
578 | // it's not normal that we have an unconstrained child, but | |
579 | // what can we do about it? | |
580 | continue; | |
581 | } | |
582 | ||
583 | int x = c->right.GetValue(), | |
584 | y = c->bottom.GetValue(); | |
585 | ||
586 | if ( x > maxX ) | |
587 | maxX = x; | |
588 | ||
589 | if ( y > maxY ) | |
590 | maxY = y; | |
591 | ||
592 | // TODO: we must calculate the overlaps somehow, otherwise we | |
593 | // will never return a size bigger than the current one :-( | |
594 | } | |
595 | ||
596 | best = wxSize(maxX, maxY); | |
597 | } | |
598 | #endif // wxUSE_CONSTRAINTS | |
599 | else if ( !GetChildren().empty() | |
600 | #ifdef __WXMAC__ | |
601 | && wxHasRealChildren(this) | |
602 | #endif | |
603 | ) | |
604 | { | |
605 | // our minimal acceptable size is such that all our visible child windows fit inside | |
606 | int maxX = 0, | |
607 | maxY = 0; | |
608 | ||
609 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
610 | node; | |
611 | node = node->GetNext() ) | |
612 | { | |
613 | wxWindow *win = node->GetData(); | |
614 | if ( win->IsTopLevel() || ( ! win->IsShown() ) | |
615 | #if wxUSE_STATUSBAR | |
616 | || wxDynamicCast(win, wxStatusBar) | |
617 | #endif // wxUSE_STATUSBAR | |
618 | ) | |
619 | { | |
620 | // dialogs and frames lie in different top level windows - | |
621 | // don't deal with them here; as for the status bars, they | |
622 | // don't lie in the client area at all | |
623 | continue; | |
624 | } | |
625 | ||
626 | int wx, wy, ww, wh; | |
627 | win->GetPosition(&wx, &wy); | |
628 | ||
629 | // if the window hadn't been positioned yet, assume that it is in | |
630 | // the origin | |
631 | if ( wx == wxDefaultCoord ) | |
632 | wx = 0; | |
633 | if ( wy == wxDefaultCoord ) | |
634 | wy = 0; | |
635 | ||
636 | win->GetSize(&ww, &wh); | |
637 | if ( wx + ww > maxX ) | |
638 | maxX = wx + ww; | |
639 | if ( wy + wh > maxY ) | |
640 | maxY = wy + wh; | |
641 | } | |
642 | ||
643 | // for compatibility with the old versions and because it really looks | |
644 | // slightly more pretty like this, add a pad | |
645 | maxX += 7; | |
646 | maxY += 14; | |
647 | ||
648 | best = wxSize(maxX, maxY); | |
649 | } | |
650 | else // ! has children | |
651 | { | |
652 | // For a generic window there is no natural best size - just use | |
653 | // either the minimum size if there is one, or the current size. | |
654 | // These are returned as-is, unadjusted by the client size difference. | |
655 | if ( GetMinSize().IsFullySpecified() ) | |
656 | return GetMinSize(); | |
657 | else | |
658 | return GetSize(); | |
659 | } | |
660 | ||
661 | // Add any difference between size and client size | |
662 | wxSize diff = GetSize() - GetClientSize(); | |
663 | best.x += wxMax(0, diff.x); | |
664 | best.y += wxMax(0, diff.y); | |
665 | ||
666 | return best; | |
667 | } | |
668 | ||
669 | ||
670 | wxSize wxWindowBase::GetBestFittingSize() const | |
671 | { | |
672 | // merge the best size with the min size, giving priority to the min size | |
673 | wxSize min = GetMinSize(); | |
674 | if (min.x == wxDefaultCoord || min.y == wxDefaultCoord) | |
675 | { | |
676 | wxSize best = GetBestSize(); | |
677 | if (min.x == wxDefaultCoord) min.x = best.x; | |
678 | if (min.y == wxDefaultCoord) min.y = best.y; | |
679 | } | |
680 | return min; | |
681 | } | |
682 | ||
683 | ||
684 | void wxWindowBase::SetBestFittingSize(const wxSize& size) | |
685 | { | |
686 | // Set the min size to the size passed in. This will usually either be | |
687 | // wxDefaultSize or the size passed to this window's ctor/Create function. | |
688 | SetMinSize(size); | |
689 | ||
690 | // Merge the size with the best size if needed | |
691 | wxSize best = GetBestFittingSize(); | |
692 | ||
693 | // If the current size doesn't match then change it | |
694 | if (GetSize() != best) | |
695 | SetSize(best); | |
696 | } | |
697 | ||
698 | ||
699 | // by default the origin is not shifted | |
700 | wxPoint wxWindowBase::GetClientAreaOrigin() const | |
701 | { | |
702 | return wxPoint(0, 0); | |
703 | } | |
704 | ||
705 | // set the min/max size of the window | |
706 | void wxWindowBase::DoSetSizeHints(int minW, int minH, | |
707 | int maxW, int maxH, | |
708 | int WXUNUSED(incW), int WXUNUSED(incH)) | |
709 | { | |
710 | // setting min width greater than max width leads to infinite loops under | |
711 | // X11 and generally doesn't make any sense, so don't allow it | |
712 | wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) && | |
713 | (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH), | |
714 | _T("min width/height must be less than max width/height!") ); | |
715 | ||
716 | m_minWidth = minW; | |
717 | m_maxWidth = maxW; | |
718 | m_minHeight = minH; | |
719 | m_maxHeight = maxH; | |
720 | } | |
721 | ||
722 | void wxWindowBase::SetWindowVariant( wxWindowVariant variant ) | |
723 | { | |
724 | if ( m_windowVariant != variant ) | |
725 | { | |
726 | m_windowVariant = variant; | |
727 | ||
728 | DoSetWindowVariant(variant); | |
729 | } | |
730 | } | |
731 | ||
732 | void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant ) | |
733 | { | |
734 | // adjust the font height to correspond to our new variant (notice that | |
735 | // we're only called if something really changed) | |
736 | wxFont font = GetFont(); | |
737 | int size = font.GetPointSize(); | |
738 | switch ( variant ) | |
739 | { | |
740 | case wxWINDOW_VARIANT_NORMAL: | |
741 | break; | |
742 | ||
743 | case wxWINDOW_VARIANT_SMALL: | |
744 | size *= 3; | |
745 | size /= 4; | |
746 | break; | |
747 | ||
748 | case wxWINDOW_VARIANT_MINI: | |
749 | size *= 2; | |
750 | size /= 3; | |
751 | break; | |
752 | ||
753 | case wxWINDOW_VARIANT_LARGE: | |
754 | size *= 5; | |
755 | size /= 4; | |
756 | break; | |
757 | ||
758 | default: | |
759 | wxFAIL_MSG(_T("unexpected window variant")); | |
760 | break; | |
761 | } | |
762 | ||
763 | font.SetPointSize(size); | |
764 | SetFont(font); | |
765 | } | |
766 | ||
767 | void wxWindowBase::SetVirtualSizeHints( int minW, int minH, | |
768 | int maxW, int maxH ) | |
769 | { | |
770 | m_minVirtualWidth = minW; | |
771 | m_maxVirtualWidth = maxW; | |
772 | m_minVirtualHeight = minH; | |
773 | m_maxVirtualHeight = maxH; | |
774 | } | |
775 | ||
776 | void wxWindowBase::DoSetVirtualSize( int x, int y ) | |
777 | { | |
778 | if ( m_minVirtualWidth != wxDefaultCoord && m_minVirtualWidth > x ) | |
779 | x = m_minVirtualWidth; | |
780 | if ( m_maxVirtualWidth != wxDefaultCoord && m_maxVirtualWidth < x ) | |
781 | x = m_maxVirtualWidth; | |
782 | if ( m_minVirtualHeight != wxDefaultCoord && m_minVirtualHeight > y ) | |
783 | y = m_minVirtualHeight; | |
784 | if ( m_maxVirtualHeight != wxDefaultCoord && m_maxVirtualHeight < y ) | |
785 | y = m_maxVirtualHeight; | |
786 | ||
787 | m_virtualSize = wxSize(x, y); | |
788 | } | |
789 | ||
790 | wxSize wxWindowBase::DoGetVirtualSize() const | |
791 | { | |
792 | wxSize s( GetClientSize() ); | |
793 | ||
794 | return wxSize( wxMax( m_virtualSize.GetWidth(), s.GetWidth() ), | |
795 | wxMax( m_virtualSize.GetHeight(), s.GetHeight() ) ); | |
796 | } | |
797 | ||
798 | // ---------------------------------------------------------------------------- | |
799 | // show/hide/enable/disable the window | |
800 | // ---------------------------------------------------------------------------- | |
801 | ||
802 | bool wxWindowBase::Show(bool show) | |
803 | { | |
804 | if ( show != m_isShown ) | |
805 | { | |
806 | m_isShown = show; | |
807 | ||
808 | return true; | |
809 | } | |
810 | else | |
811 | { | |
812 | return false; | |
813 | } | |
814 | } | |
815 | ||
816 | bool wxWindowBase::Enable(bool enable) | |
817 | { | |
818 | if ( enable != m_isEnabled ) | |
819 | { | |
820 | m_isEnabled = enable; | |
821 | ||
822 | return true; | |
823 | } | |
824 | else | |
825 | { | |
826 | return false; | |
827 | } | |
828 | } | |
829 | // ---------------------------------------------------------------------------- | |
830 | // RTTI | |
831 | // ---------------------------------------------------------------------------- | |
832 | ||
833 | bool wxWindowBase::IsTopLevel() const | |
834 | { | |
835 | return false; | |
836 | } | |
837 | ||
838 | // ---------------------------------------------------------------------------- | |
839 | // reparenting the window | |
840 | // ---------------------------------------------------------------------------- | |
841 | ||
842 | void wxWindowBase::AddChild(wxWindowBase *child) | |
843 | { | |
844 | wxCHECK_RET( child, wxT("can't add a NULL child") ); | |
845 | ||
846 | // this should never happen and it will lead to a crash later if it does | |
847 | // because RemoveChild() will remove only one node from the children list | |
848 | // and the other(s) one(s) will be left with dangling pointers in them | |
849 | wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") ); | |
850 | ||
851 | GetChildren().Append((wxWindow*)child); | |
852 | child->SetParent(this); | |
853 | } | |
854 | ||
855 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
856 | { | |
857 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); | |
858 | ||
859 | GetChildren().DeleteObject((wxWindow *)child); | |
860 | child->SetParent(NULL); | |
861 | } | |
862 | ||
863 | bool wxWindowBase::Reparent(wxWindowBase *newParent) | |
864 | { | |
865 | wxWindow *oldParent = GetParent(); | |
866 | if ( newParent == oldParent ) | |
867 | { | |
868 | // nothing done | |
869 | return false; | |
870 | } | |
871 | ||
872 | // unlink this window from the existing parent. | |
873 | if ( oldParent ) | |
874 | { | |
875 | oldParent->RemoveChild(this); | |
876 | } | |
877 | else | |
878 | { | |
879 | wxTopLevelWindows.DeleteObject((wxWindow *)this); | |
880 | } | |
881 | ||
882 | // add it to the new one | |
883 | if ( newParent ) | |
884 | { | |
885 | newParent->AddChild(this); | |
886 | } | |
887 | else | |
888 | { | |
889 | wxTopLevelWindows.Append((wxWindow *)this); | |
890 | } | |
891 | ||
892 | return true; | |
893 | } | |
894 | ||
895 | // ---------------------------------------------------------------------------- | |
896 | // event handler stuff | |
897 | // ---------------------------------------------------------------------------- | |
898 | ||
899 | void wxWindowBase::PushEventHandler(wxEvtHandler *handler) | |
900 | { | |
901 | wxEvtHandler *handlerOld = GetEventHandler(); | |
902 | ||
903 | handler->SetNextHandler(handlerOld); | |
904 | ||
905 | if ( handlerOld ) | |
906 | GetEventHandler()->SetPreviousHandler(handler); | |
907 | ||
908 | SetEventHandler(handler); | |
909 | } | |
910 | ||
911 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
912 | { | |
913 | wxEvtHandler *handlerA = GetEventHandler(); | |
914 | if ( handlerA ) | |
915 | { | |
916 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
917 | handlerA->SetNextHandler((wxEvtHandler *)NULL); | |
918 | ||
919 | if ( handlerB ) | |
920 | handlerB->SetPreviousHandler((wxEvtHandler *)NULL); | |
921 | SetEventHandler(handlerB); | |
922 | ||
923 | if ( deleteHandler ) | |
924 | { | |
925 | delete handlerA; | |
926 | handlerA = (wxEvtHandler *)NULL; | |
927 | } | |
928 | } | |
929 | ||
930 | return handlerA; | |
931 | } | |
932 | ||
933 | bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler) | |
934 | { | |
935 | wxCHECK_MSG( handler, false, _T("RemoveEventHandler(NULL) called") ); | |
936 | ||
937 | wxEvtHandler *handlerPrev = NULL, | |
938 | *handlerCur = GetEventHandler(); | |
939 | while ( handlerCur ) | |
940 | { | |
941 | wxEvtHandler *handlerNext = handlerCur->GetNextHandler(); | |
942 | ||
943 | if ( handlerCur == handler ) | |
944 | { | |
945 | if ( handlerPrev ) | |
946 | { | |
947 | handlerPrev->SetNextHandler(handlerNext); | |
948 | } | |
949 | else | |
950 | { | |
951 | SetEventHandler(handlerNext); | |
952 | } | |
953 | ||
954 | if ( handlerNext ) | |
955 | { | |
956 | handlerNext->SetPreviousHandler ( handlerPrev ); | |
957 | } | |
958 | ||
959 | handler->SetNextHandler(NULL); | |
960 | handler->SetPreviousHandler(NULL); | |
961 | ||
962 | return true; | |
963 | } | |
964 | ||
965 | handlerPrev = handlerCur; | |
966 | handlerCur = handlerNext; | |
967 | } | |
968 | ||
969 | wxFAIL_MSG( _T("where has the event handler gone?") ); | |
970 | ||
971 | return false; | |
972 | } | |
973 | ||
974 | // ---------------------------------------------------------------------------- | |
975 | // colours, fonts &c | |
976 | // ---------------------------------------------------------------------------- | |
977 | ||
978 | void wxWindowBase::InheritAttributes() | |
979 | { | |
980 | const wxWindowBase * const parent = GetParent(); | |
981 | if ( !parent ) | |
982 | return; | |
983 | ||
984 | // we only inherit attributes which had been explicitly set for the parent | |
985 | // which ensures that this only happens if the user really wants it and | |
986 | // not by default which wouldn't make any sense in modern GUIs where the | |
987 | // controls don't all use the same fonts (nor colours) | |
988 | if ( parent->m_inheritFont && !m_hasFont ) | |
989 | SetFont(parent->GetFont()); | |
990 | ||
991 | // in addition, there is a possibility to explicitly forbid inheriting | |
992 | // colours at each class level by overriding ShouldInheritColours() | |
993 | if ( ShouldInheritColours() ) | |
994 | { | |
995 | if ( parent->m_inheritFgCol && !m_hasFgCol ) | |
996 | SetForegroundColour(parent->GetForegroundColour()); | |
997 | ||
998 | // inheriting (solid) background colour is wrong as it totally breaks | |
999 | // any kind of themed backgrounds | |
1000 | // | |
1001 | // instead, the controls should use the same background as their parent | |
1002 | // (ideally by not drawing it at all) | |
1003 | #if 0 | |
1004 | if ( parent->m_inheritBgCol && !m_hasBgCol ) | |
1005 | SetBackgroundColour(parent->GetBackgroundColour()); | |
1006 | #endif // 0 | |
1007 | } | |
1008 | } | |
1009 | ||
1010 | /* static */ wxVisualAttributes | |
1011 | wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
1012 | { | |
1013 | // it is important to return valid values for all attributes from here, | |
1014 | // GetXXX() below rely on this | |
1015 | wxVisualAttributes attrs; | |
1016 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
1017 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
1018 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
1019 | ||
1020 | return attrs; | |
1021 | } | |
1022 | ||
1023 | wxColour wxWindowBase::GetBackgroundColour() const | |
1024 | { | |
1025 | if ( !m_backgroundColour.Ok() ) | |
1026 | { | |
1027 | wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") ); | |
1028 | ||
1029 | // get our default background colour | |
1030 | wxColour colBg = GetDefaultAttributes().colBg; | |
1031 | ||
1032 | // we must return some valid colour to avoid redoing this every time | |
1033 | // and also to avoid surprizing the applications written for older | |
1034 | // wxWidgets versions where GetBackgroundColour() always returned | |
1035 | // something -- so give them something even if it doesn't make sense | |
1036 | // for this window (e.g. it has a themed background) | |
1037 | if ( !colBg.Ok() ) | |
1038 | colBg = GetClassDefaultAttributes().colBg; | |
1039 | ||
1040 | return colBg; | |
1041 | } | |
1042 | else | |
1043 | return m_backgroundColour; | |
1044 | } | |
1045 | ||
1046 | wxColour wxWindowBase::GetForegroundColour() const | |
1047 | { | |
1048 | // logic is the same as above | |
1049 | if ( !m_hasFgCol && !m_foregroundColour.Ok() ) | |
1050 | { | |
1051 | wxASSERT_MSG( !m_hasFgCol, _T("we have invalid explicit fg colour?") ); | |
1052 | ||
1053 | wxColour colFg = GetDefaultAttributes().colFg; | |
1054 | ||
1055 | if ( !colFg.Ok() ) | |
1056 | colFg = GetClassDefaultAttributes().colFg; | |
1057 | ||
1058 | return colFg; | |
1059 | } | |
1060 | else | |
1061 | return m_foregroundColour; | |
1062 | } | |
1063 | ||
1064 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) | |
1065 | { | |
1066 | if ( colour == m_backgroundColour ) | |
1067 | return false; | |
1068 | ||
1069 | m_hasBgCol = colour.Ok(); | |
1070 | if ( m_backgroundStyle != wxBG_STYLE_CUSTOM ) | |
1071 | m_backgroundStyle = m_hasBgCol ? wxBG_STYLE_COLOUR : wxBG_STYLE_SYSTEM; | |
1072 | ||
1073 | m_inheritBgCol = m_hasBgCol; | |
1074 | m_backgroundColour = colour; | |
1075 | SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() ); | |
1076 | return true; | |
1077 | } | |
1078 | ||
1079 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
1080 | { | |
1081 | if (colour == m_foregroundColour ) | |
1082 | return false; | |
1083 | ||
1084 | m_hasFgCol = colour.Ok(); | |
1085 | m_inheritFgCol = m_hasFgCol; | |
1086 | m_foregroundColour = colour; | |
1087 | SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() ); | |
1088 | return true; | |
1089 | } | |
1090 | ||
1091 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
1092 | { | |
1093 | // setting an invalid cursor is ok, it means that we don't have any special | |
1094 | // cursor | |
1095 | if ( m_cursor == cursor ) | |
1096 | { | |
1097 | // no change | |
1098 | return false; | |
1099 | } | |
1100 | ||
1101 | m_cursor = cursor; | |
1102 | ||
1103 | return true; | |
1104 | } | |
1105 | ||
1106 | wxFont wxWindowBase::GetFont() const | |
1107 | { | |
1108 | // logic is the same as in GetBackgroundColour() | |
1109 | if ( !m_font.Ok() ) | |
1110 | { | |
1111 | wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") ); | |
1112 | ||
1113 | wxFont font = GetDefaultAttributes().font; | |
1114 | if ( !font.Ok() ) | |
1115 | font = GetClassDefaultAttributes().font; | |
1116 | ||
1117 | return font; | |
1118 | } | |
1119 | else | |
1120 | return m_font; | |
1121 | } | |
1122 | ||
1123 | bool wxWindowBase::SetFont(const wxFont& font) | |
1124 | { | |
1125 | if ( font == m_font ) | |
1126 | { | |
1127 | // no change | |
1128 | return false; | |
1129 | } | |
1130 | ||
1131 | m_font = font; | |
1132 | m_hasFont = font.Ok(); | |
1133 | m_inheritFont = m_hasFont; | |
1134 | ||
1135 | InvalidateBestSize(); | |
1136 | ||
1137 | return true; | |
1138 | } | |
1139 | ||
1140 | #if wxUSE_PALETTE | |
1141 | ||
1142 | void wxWindowBase::SetPalette(const wxPalette& pal) | |
1143 | { | |
1144 | m_hasCustomPalette = true; | |
1145 | m_palette = pal; | |
1146 | ||
1147 | // VZ: can anyone explain me what do we do here? | |
1148 | wxWindowDC d((wxWindow *) this); | |
1149 | d.SetPalette(pal); | |
1150 | } | |
1151 | ||
1152 | wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const | |
1153 | { | |
1154 | wxWindow *win = (wxWindow *)this; | |
1155 | while ( win && !win->HasCustomPalette() ) | |
1156 | { | |
1157 | win = win->GetParent(); | |
1158 | } | |
1159 | ||
1160 | return win; | |
1161 | } | |
1162 | ||
1163 | #endif // wxUSE_PALETTE | |
1164 | ||
1165 | #if wxUSE_CARET | |
1166 | void wxWindowBase::SetCaret(wxCaret *caret) | |
1167 | { | |
1168 | if ( m_caret ) | |
1169 | { | |
1170 | delete m_caret; | |
1171 | } | |
1172 | ||
1173 | m_caret = caret; | |
1174 | ||
1175 | if ( m_caret ) | |
1176 | { | |
1177 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
1178 | wxT("caret should be created associated to this window") ); | |
1179 | } | |
1180 | } | |
1181 | #endif // wxUSE_CARET | |
1182 | ||
1183 | #if wxUSE_VALIDATORS | |
1184 | // ---------------------------------------------------------------------------- | |
1185 | // validators | |
1186 | // ---------------------------------------------------------------------------- | |
1187 | ||
1188 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
1189 | { | |
1190 | if ( m_windowValidator ) | |
1191 | delete m_windowValidator; | |
1192 | ||
1193 | m_windowValidator = (wxValidator *)validator.Clone(); | |
1194 | ||
1195 | if ( m_windowValidator ) | |
1196 | m_windowValidator->SetWindow(this); | |
1197 | } | |
1198 | #endif // wxUSE_VALIDATORS | |
1199 | ||
1200 | // ---------------------------------------------------------------------------- | |
1201 | // update region stuff | |
1202 | // ---------------------------------------------------------------------------- | |
1203 | ||
1204 | wxRect wxWindowBase::GetUpdateClientRect() const | |
1205 | { | |
1206 | wxRegion rgnUpdate = GetUpdateRegion(); | |
1207 | rgnUpdate.Intersect(GetClientRect()); | |
1208 | wxRect rectUpdate = rgnUpdate.GetBox(); | |
1209 | wxPoint ptOrigin = GetClientAreaOrigin(); | |
1210 | rectUpdate.x -= ptOrigin.x; | |
1211 | rectUpdate.y -= ptOrigin.y; | |
1212 | ||
1213 | return rectUpdate; | |
1214 | } | |
1215 | ||
1216 | bool wxWindowBase::IsExposed(int x, int y) const | |
1217 | { | |
1218 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
1219 | } | |
1220 | ||
1221 | bool wxWindowBase::IsExposed(int x, int y, int w, int h) const | |
1222 | { | |
1223 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
1224 | } | |
1225 | ||
1226 | void wxWindowBase::ClearBackground() | |
1227 | { | |
1228 | // wxGTK uses its own version, no need to add never used code | |
1229 | #ifndef __WXGTK__ | |
1230 | wxClientDC dc((wxWindow *)this); | |
1231 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1232 | dc.SetBackground(brush); | |
1233 | dc.Clear(); | |
1234 | #endif // __WXGTK__ | |
1235 | } | |
1236 | ||
1237 | // ---------------------------------------------------------------------------- | |
1238 | // find child window by id or name | |
1239 | // ---------------------------------------------------------------------------- | |
1240 | ||
1241 | wxWindow *wxWindowBase::FindWindow(long id) const | |
1242 | { | |
1243 | if ( id == m_windowId ) | |
1244 | return (wxWindow *)this; | |
1245 | ||
1246 | wxWindowBase *res = (wxWindow *)NULL; | |
1247 | wxWindowList::compatibility_iterator node; | |
1248 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
1249 | { | |
1250 | wxWindowBase *child = node->GetData(); | |
1251 | res = child->FindWindow( id ); | |
1252 | } | |
1253 | ||
1254 | return (wxWindow *)res; | |
1255 | } | |
1256 | ||
1257 | wxWindow *wxWindowBase::FindWindow(const wxString& name) const | |
1258 | { | |
1259 | if ( name == m_windowName ) | |
1260 | return (wxWindow *)this; | |
1261 | ||
1262 | wxWindowBase *res = (wxWindow *)NULL; | |
1263 | wxWindowList::compatibility_iterator node; | |
1264 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
1265 | { | |
1266 | wxWindow *child = node->GetData(); | |
1267 | res = child->FindWindow(name); | |
1268 | } | |
1269 | ||
1270 | return (wxWindow *)res; | |
1271 | } | |
1272 | ||
1273 | ||
1274 | // find any window by id or name or label: If parent is non-NULL, look through | |
1275 | // children for a label or title matching the specified string. If NULL, look | |
1276 | // through all top-level windows. | |
1277 | // | |
1278 | // to avoid duplicating code we reuse the same helper function but with | |
1279 | // different comparators | |
1280 | ||
1281 | typedef bool (*wxFindWindowCmp)(const wxWindow *win, | |
1282 | const wxString& label, long id); | |
1283 | ||
1284 | static | |
1285 | bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label, | |
1286 | long WXUNUSED(id)) | |
1287 | { | |
1288 | return win->GetLabel() == label; | |
1289 | } | |
1290 | ||
1291 | static | |
1292 | bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label, | |
1293 | long WXUNUSED(id)) | |
1294 | { | |
1295 | return win->GetName() == label; | |
1296 | } | |
1297 | ||
1298 | static | |
1299 | bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label), | |
1300 | long id) | |
1301 | { | |
1302 | return win->GetId() == id; | |
1303 | } | |
1304 | ||
1305 | // recursive helper for the FindWindowByXXX() functions | |
1306 | static | |
1307 | wxWindow *wxFindWindowRecursively(const wxWindow *parent, | |
1308 | const wxString& label, | |
1309 | long id, | |
1310 | wxFindWindowCmp cmp) | |
1311 | { | |
1312 | if ( parent ) | |
1313 | { | |
1314 | // see if this is the one we're looking for | |
1315 | if ( (*cmp)(parent, label, id) ) | |
1316 | return (wxWindow *)parent; | |
1317 | ||
1318 | // It wasn't, so check all its children | |
1319 | for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst(); | |
1320 | node; | |
1321 | node = node->GetNext() ) | |
1322 | { | |
1323 | // recursively check each child | |
1324 | wxWindow *win = (wxWindow *)node->GetData(); | |
1325 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1326 | if (retwin) | |
1327 | return retwin; | |
1328 | } | |
1329 | } | |
1330 | ||
1331 | // Not found | |
1332 | return NULL; | |
1333 | } | |
1334 | ||
1335 | // helper for FindWindowByXXX() | |
1336 | static | |
1337 | wxWindow *wxFindWindowHelper(const wxWindow *parent, | |
1338 | const wxString& label, | |
1339 | long id, | |
1340 | wxFindWindowCmp cmp) | |
1341 | { | |
1342 | if ( parent ) | |
1343 | { | |
1344 | // just check parent and all its children | |
1345 | return wxFindWindowRecursively(parent, label, id, cmp); | |
1346 | } | |
1347 | ||
1348 | // start at very top of wx's windows | |
1349 | for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); | |
1350 | node; | |
1351 | node = node->GetNext() ) | |
1352 | { | |
1353 | // recursively check each window & its children | |
1354 | wxWindow *win = node->GetData(); | |
1355 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1356 | if (retwin) | |
1357 | return retwin; | |
1358 | } | |
1359 | ||
1360 | return NULL; | |
1361 | } | |
1362 | ||
1363 | /* static */ | |
1364 | wxWindow * | |
1365 | wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent) | |
1366 | { | |
1367 | return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels); | |
1368 | } | |
1369 | ||
1370 | /* static */ | |
1371 | wxWindow * | |
1372 | wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent) | |
1373 | { | |
1374 | wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames); | |
1375 | ||
1376 | if ( !win ) | |
1377 | { | |
1378 | // fall back to the label | |
1379 | win = FindWindowByLabel(title, parent); | |
1380 | } | |
1381 | ||
1382 | return win; | |
1383 | } | |
1384 | ||
1385 | /* static */ | |
1386 | wxWindow * | |
1387 | wxWindowBase::FindWindowById( long id, const wxWindow* parent ) | |
1388 | { | |
1389 | return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds); | |
1390 | } | |
1391 | ||
1392 | // ---------------------------------------------------------------------------- | |
1393 | // dialog oriented functions | |
1394 | // ---------------------------------------------------------------------------- | |
1395 | ||
1396 | void wxWindowBase::MakeModal(bool modal) | |
1397 | { | |
1398 | // Disable all other windows | |
1399 | if ( IsTopLevel() ) | |
1400 | { | |
1401 | wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); | |
1402 | while (node) | |
1403 | { | |
1404 | wxWindow *win = node->GetData(); | |
1405 | if (win != this) | |
1406 | win->Enable(!modal); | |
1407 | ||
1408 | node = node->GetNext(); | |
1409 | } | |
1410 | } | |
1411 | } | |
1412 | ||
1413 | bool wxWindowBase::Validate() | |
1414 | { | |
1415 | #if wxUSE_VALIDATORS | |
1416 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; | |
1417 | ||
1418 | wxWindowList::compatibility_iterator node; | |
1419 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1420 | { | |
1421 | wxWindowBase *child = node->GetData(); | |
1422 | wxValidator *validator = child->GetValidator(); | |
1423 | if ( validator && !validator->Validate((wxWindow *)this) ) | |
1424 | { | |
1425 | return false; | |
1426 | } | |
1427 | ||
1428 | if ( recurse && !child->Validate() ) | |
1429 | { | |
1430 | return false; | |
1431 | } | |
1432 | } | |
1433 | #endif // wxUSE_VALIDATORS | |
1434 | ||
1435 | return true; | |
1436 | } | |
1437 | ||
1438 | bool wxWindowBase::TransferDataToWindow() | |
1439 | { | |
1440 | #if wxUSE_VALIDATORS | |
1441 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; | |
1442 | ||
1443 | wxWindowList::compatibility_iterator node; | |
1444 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1445 | { | |
1446 | wxWindowBase *child = node->GetData(); | |
1447 | wxValidator *validator = child->GetValidator(); | |
1448 | if ( validator && !validator->TransferToWindow() ) | |
1449 | { | |
1450 | wxLogWarning(_("Could not transfer data to window")); | |
1451 | #if wxUSE_LOG | |
1452 | wxLog::FlushActive(); | |
1453 | #endif // wxUSE_LOG | |
1454 | ||
1455 | return false; | |
1456 | } | |
1457 | ||
1458 | if ( recurse ) | |
1459 | { | |
1460 | if ( !child->TransferDataToWindow() ) | |
1461 | { | |
1462 | // warning already given | |
1463 | return false; | |
1464 | } | |
1465 | } | |
1466 | } | |
1467 | #endif // wxUSE_VALIDATORS | |
1468 | ||
1469 | return true; | |
1470 | } | |
1471 | ||
1472 | bool wxWindowBase::TransferDataFromWindow() | |
1473 | { | |
1474 | #if wxUSE_VALIDATORS | |
1475 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; | |
1476 | ||
1477 | wxWindowList::compatibility_iterator node; | |
1478 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1479 | { | |
1480 | wxWindow *child = node->GetData(); | |
1481 | wxValidator *validator = child->GetValidator(); | |
1482 | if ( validator && !validator->TransferFromWindow() ) | |
1483 | { | |
1484 | // nop warning here because the application is supposed to give | |
1485 | // one itself - we don't know here what might have gone wrongly | |
1486 | ||
1487 | return false; | |
1488 | } | |
1489 | ||
1490 | if ( recurse ) | |
1491 | { | |
1492 | if ( !child->TransferDataFromWindow() ) | |
1493 | { | |
1494 | // warning already given | |
1495 | return false; | |
1496 | } | |
1497 | } | |
1498 | } | |
1499 | #endif // wxUSE_VALIDATORS | |
1500 | ||
1501 | return true; | |
1502 | } | |
1503 | ||
1504 | void wxWindowBase::InitDialog() | |
1505 | { | |
1506 | wxInitDialogEvent event(GetId()); | |
1507 | event.SetEventObject( this ); | |
1508 | GetEventHandler()->ProcessEvent(event); | |
1509 | } | |
1510 | ||
1511 | // ---------------------------------------------------------------------------- | |
1512 | // context-sensitive help support | |
1513 | // ---------------------------------------------------------------------------- | |
1514 | ||
1515 | #if wxUSE_HELP | |
1516 | ||
1517 | // associate this help text with this window | |
1518 | void wxWindowBase::SetHelpText(const wxString& text) | |
1519 | { | |
1520 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1521 | if ( helpProvider ) | |
1522 | { | |
1523 | helpProvider->AddHelp(this, text); | |
1524 | } | |
1525 | } | |
1526 | ||
1527 | // associate this help text with all windows with the same id as this | |
1528 | // one | |
1529 | void wxWindowBase::SetHelpTextForId(const wxString& text) | |
1530 | { | |
1531 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1532 | if ( helpProvider ) | |
1533 | { | |
1534 | helpProvider->AddHelp(GetId(), text); | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | // get the help string associated with this window (may be empty) | |
1539 | wxString wxWindowBase::GetHelpText() const | |
1540 | { | |
1541 | wxString text; | |
1542 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1543 | if ( helpProvider ) | |
1544 | { | |
1545 | text = helpProvider->GetHelp(this); | |
1546 | } | |
1547 | ||
1548 | return text; | |
1549 | } | |
1550 | ||
1551 | // show help for this window | |
1552 | void wxWindowBase::OnHelp(wxHelpEvent& event) | |
1553 | { | |
1554 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1555 | if ( helpProvider ) | |
1556 | { | |
1557 | if ( helpProvider->ShowHelp(this) ) | |
1558 | { | |
1559 | // skip the event.Skip() below | |
1560 | return; | |
1561 | } | |
1562 | } | |
1563 | ||
1564 | event.Skip(); | |
1565 | } | |
1566 | ||
1567 | #endif // wxUSE_HELP | |
1568 | ||
1569 | // ---------------------------------------------------------------------------- | |
1570 | // tooltipsroot.Replace("\\", "/"); | |
1571 | // ---------------------------------------------------------------------------- | |
1572 | ||
1573 | #if wxUSE_TOOLTIPS | |
1574 | ||
1575 | void wxWindowBase::SetToolTip( const wxString &tip ) | |
1576 | { | |
1577 | // don't create the new tooltip if we already have one | |
1578 | if ( m_tooltip ) | |
1579 | { | |
1580 | m_tooltip->SetTip( tip ); | |
1581 | } | |
1582 | else | |
1583 | { | |
1584 | SetToolTip( new wxToolTip( tip ) ); | |
1585 | } | |
1586 | ||
1587 | // setting empty tooltip text does not remove the tooltip any more - use | |
1588 | // SetToolTip((wxToolTip *)NULL) for this | |
1589 | } | |
1590 | ||
1591 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
1592 | { | |
1593 | if ( m_tooltip ) | |
1594 | delete m_tooltip; | |
1595 | ||
1596 | m_tooltip = tooltip; | |
1597 | } | |
1598 | ||
1599 | #endif // wxUSE_TOOLTIPS | |
1600 | ||
1601 | // ---------------------------------------------------------------------------- | |
1602 | // constraints and sizers | |
1603 | // ---------------------------------------------------------------------------- | |
1604 | ||
1605 | #if wxUSE_CONSTRAINTS | |
1606 | ||
1607 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
1608 | { | |
1609 | if ( m_constraints ) | |
1610 | { | |
1611 | UnsetConstraints(m_constraints); | |
1612 | delete m_constraints; | |
1613 | } | |
1614 | m_constraints = constraints; | |
1615 | if ( m_constraints ) | |
1616 | { | |
1617 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1618 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
1619 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
1620 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
1621 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
1622 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
1623 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
1624 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
1625 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
1626 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
1627 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
1628 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
1629 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
1630 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
1631 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
1632 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
1633 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
1634 | } | |
1635 | } | |
1636 | ||
1637 | // This removes any dangling pointers to this window in other windows' | |
1638 | // constraintsInvolvedIn lists. | |
1639 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
1640 | { | |
1641 | if ( c ) | |
1642 | { | |
1643 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1644 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
1645 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1646 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
1647 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
1648 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
1649 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
1650 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
1651 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
1652 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
1653 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
1654 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
1655 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
1656 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
1657 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
1658 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
1659 | } | |
1660 | } | |
1661 | ||
1662 | // Back-pointer to other windows we're involved with, so if we delete this | |
1663 | // window, we must delete any constraints we're involved with. | |
1664 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
1665 | { | |
1666 | if ( !m_constraintsInvolvedIn ) | |
1667 | m_constraintsInvolvedIn = new wxWindowList; | |
1668 | if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) ) | |
1669 | m_constraintsInvolvedIn->Append((wxWindow *)otherWin); | |
1670 | } | |
1671 | ||
1672 | // REMOVE back-pointer to other windows we're involved with. | |
1673 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
1674 | { | |
1675 | if ( m_constraintsInvolvedIn ) | |
1676 | m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin); | |
1677 | } | |
1678 | ||
1679 | // Reset any constraints that mention this window | |
1680 | void wxWindowBase::DeleteRelatedConstraints() | |
1681 | { | |
1682 | if ( m_constraintsInvolvedIn ) | |
1683 | { | |
1684 | wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst(); | |
1685 | while (node) | |
1686 | { | |
1687 | wxWindow *win = node->GetData(); | |
1688 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1689 | ||
1690 | // Reset any constraints involving this window | |
1691 | if ( constr ) | |
1692 | { | |
1693 | constr->left.ResetIfWin(this); | |
1694 | constr->top.ResetIfWin(this); | |
1695 | constr->right.ResetIfWin(this); | |
1696 | constr->bottom.ResetIfWin(this); | |
1697 | constr->width.ResetIfWin(this); | |
1698 | constr->height.ResetIfWin(this); | |
1699 | constr->centreX.ResetIfWin(this); | |
1700 | constr->centreY.ResetIfWin(this); | |
1701 | } | |
1702 | ||
1703 | wxWindowList::compatibility_iterator next = node->GetNext(); | |
1704 | m_constraintsInvolvedIn->Erase(node); | |
1705 | node = next; | |
1706 | } | |
1707 | ||
1708 | delete m_constraintsInvolvedIn; | |
1709 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
1710 | } | |
1711 | } | |
1712 | ||
1713 | #endif // wxUSE_CONSTRAINTS | |
1714 | ||
1715 | void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld) | |
1716 | { | |
1717 | if ( sizer == m_windowSizer) | |
1718 | return; | |
1719 | ||
1720 | if ( deleteOld ) | |
1721 | delete m_windowSizer; | |
1722 | ||
1723 | m_windowSizer = sizer; | |
1724 | ||
1725 | SetAutoLayout( sizer != NULL ); | |
1726 | } | |
1727 | ||
1728 | void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) | |
1729 | { | |
1730 | SetSizer( sizer, deleteOld ); | |
1731 | sizer->SetSizeHints( (wxWindow*) this ); | |
1732 | } | |
1733 | ||
1734 | ||
1735 | void wxWindowBase::SetContainingSizer(wxSizer* sizer) | |
1736 | { | |
1737 | // adding a window to a sizer twice is going to result in fatal and | |
1738 | // hard to debug problems later because when deleting the second | |
1739 | // associated wxSizerItem we're going to dereference a dangling | |
1740 | // pointer; so try to detect this as early as possible | |
1741 | wxASSERT_MSG( !sizer || m_containingSizer != sizer, | |
1742 | _T("Adding a window to the same sizer twice?") ); | |
1743 | ||
1744 | m_containingSizer = sizer; | |
1745 | } | |
1746 | ||
1747 | #if wxUSE_CONSTRAINTS | |
1748 | ||
1749 | void wxWindowBase::SatisfyConstraints() | |
1750 | { | |
1751 | wxLayoutConstraints *constr = GetConstraints(); | |
1752 | bool wasOk = constr && constr->AreSatisfied(); | |
1753 | ||
1754 | ResetConstraints(); // Mark all constraints as unevaluated | |
1755 | ||
1756 | int noChanges = 1; | |
1757 | ||
1758 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
1759 | // own constraints will never be satisfied any more unless we do it | |
1760 | // here | |
1761 | if ( wasOk ) | |
1762 | { | |
1763 | while ( noChanges > 0 ) | |
1764 | { | |
1765 | LayoutPhase1(&noChanges); | |
1766 | } | |
1767 | } | |
1768 | ||
1769 | LayoutPhase2(&noChanges); | |
1770 | } | |
1771 | ||
1772 | #endif // wxUSE_CONSTRAINTS | |
1773 | ||
1774 | bool wxWindowBase::Layout() | |
1775 | { | |
1776 | // If there is a sizer, use it instead of the constraints | |
1777 | if ( GetSizer() ) | |
1778 | { | |
1779 | int w, h; | |
1780 | GetVirtualSize(&w, &h); | |
1781 | GetSizer()->SetDimension( 0, 0, w, h ); | |
1782 | } | |
1783 | #if wxUSE_CONSTRAINTS | |
1784 | else | |
1785 | { | |
1786 | SatisfyConstraints(); // Find the right constraints values | |
1787 | SetConstraintSizes(); // Recursively set the real window sizes | |
1788 | } | |
1789 | #endif | |
1790 | ||
1791 | return true; | |
1792 | } | |
1793 | ||
1794 | #if wxUSE_CONSTRAINTS | |
1795 | ||
1796 | // first phase of the constraints evaluation: set our own constraints | |
1797 | bool wxWindowBase::LayoutPhase1(int *noChanges) | |
1798 | { | |
1799 | wxLayoutConstraints *constr = GetConstraints(); | |
1800 | ||
1801 | return !constr || constr->SatisfyConstraints(this, noChanges); | |
1802 | } | |
1803 | ||
1804 | // second phase: set the constraints for our children | |
1805 | bool wxWindowBase::LayoutPhase2(int *noChanges) | |
1806 | { | |
1807 | *noChanges = 0; | |
1808 | ||
1809 | // Layout children | |
1810 | DoPhase(1); | |
1811 | ||
1812 | // Layout grand children | |
1813 | DoPhase(2); | |
1814 | ||
1815 | return true; | |
1816 | } | |
1817 | ||
1818 | // Do a phase of evaluating child constraints | |
1819 | bool wxWindowBase::DoPhase(int phase) | |
1820 | { | |
1821 | // the list containing the children for which the constraints are already | |
1822 | // set correctly | |
1823 | wxWindowList succeeded; | |
1824 | ||
1825 | // the max number of iterations we loop before concluding that we can't set | |
1826 | // the constraints | |
1827 | static const int maxIterations = 500; | |
1828 | ||
1829 | for ( int noIterations = 0; noIterations < maxIterations; noIterations++ ) | |
1830 | { | |
1831 | int noChanges = 0; | |
1832 | ||
1833 | // loop over all children setting their constraints | |
1834 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
1835 | node; | |
1836 | node = node->GetNext() ) | |
1837 | { | |
1838 | wxWindow *child = node->GetData(); | |
1839 | if ( child->IsTopLevel() ) | |
1840 | { | |
1841 | // top level children are not inside our client area | |
1842 | continue; | |
1843 | } | |
1844 | ||
1845 | if ( !child->GetConstraints() || succeeded.Find(child) ) | |
1846 | { | |
1847 | // this one is either already ok or nothing we can do about it | |
1848 | continue; | |
1849 | } | |
1850 | ||
1851 | int tempNoChanges = 0; | |
1852 | bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges) | |
1853 | : child->LayoutPhase2(&tempNoChanges); | |
1854 | noChanges += tempNoChanges; | |
1855 | ||
1856 | if ( success ) | |
1857 | { | |
1858 | succeeded.Append(child); | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | if ( !noChanges ) | |
1863 | { | |
1864 | // constraints are set | |
1865 | break; | |
1866 | } | |
1867 | } | |
1868 | ||
1869 | return true; | |
1870 | } | |
1871 | ||
1872 | void wxWindowBase::ResetConstraints() | |
1873 | { | |
1874 | wxLayoutConstraints *constr = GetConstraints(); | |
1875 | if ( constr ) | |
1876 | { | |
1877 | constr->left.SetDone(false); | |
1878 | constr->top.SetDone(false); | |
1879 | constr->right.SetDone(false); | |
1880 | constr->bottom.SetDone(false); | |
1881 | constr->width.SetDone(false); | |
1882 | constr->height.SetDone(false); | |
1883 | constr->centreX.SetDone(false); | |
1884 | constr->centreY.SetDone(false); | |
1885 | } | |
1886 | ||
1887 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
1888 | while (node) | |
1889 | { | |
1890 | wxWindow *win = node->GetData(); | |
1891 | if ( !win->IsTopLevel() ) | |
1892 | win->ResetConstraints(); | |
1893 | node = node->GetNext(); | |
1894 | } | |
1895 | } | |
1896 | ||
1897 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
1898 | // and setting the real values. | |
1899 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
1900 | { | |
1901 | wxLayoutConstraints *constr = GetConstraints(); | |
1902 | if ( constr && constr->AreSatisfied() ) | |
1903 | { | |
1904 | int x = constr->left.GetValue(); | |
1905 | int y = constr->top.GetValue(); | |
1906 | int w = constr->width.GetValue(); | |
1907 | int h = constr->height.GetValue(); | |
1908 | ||
1909 | if ( (constr->width.GetRelationship() != wxAsIs ) || | |
1910 | (constr->height.GetRelationship() != wxAsIs) ) | |
1911 | { | |
1912 | SetSize(x, y, w, h); | |
1913 | } | |
1914 | else | |
1915 | { | |
1916 | // If we don't want to resize this window, just move it... | |
1917 | Move(x, y); | |
1918 | } | |
1919 | } | |
1920 | else if ( constr ) | |
1921 | { | |
1922 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), | |
1923 | GetClassInfo()->GetClassName(), | |
1924 | GetName().c_str()); | |
1925 | } | |
1926 | ||
1927 | if ( recurse ) | |
1928 | { | |
1929 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
1930 | while (node) | |
1931 | { | |
1932 | wxWindow *win = node->GetData(); | |
1933 | if ( !win->IsTopLevel() && win->GetConstraints() ) | |
1934 | win->SetConstraintSizes(); | |
1935 | node = node->GetNext(); | |
1936 | } | |
1937 | } | |
1938 | } | |
1939 | ||
1940 | // Only set the size/position of the constraint (if any) | |
1941 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
1942 | { | |
1943 | wxLayoutConstraints *constr = GetConstraints(); | |
1944 | if ( constr ) | |
1945 | { | |
1946 | if ( x != wxDefaultCoord ) | |
1947 | { | |
1948 | constr->left.SetValue(x); | |
1949 | constr->left.SetDone(true); | |
1950 | } | |
1951 | if ( y != wxDefaultCoord ) | |
1952 | { | |
1953 | constr->top.SetValue(y); | |
1954 | constr->top.SetDone(true); | |
1955 | } | |
1956 | if ( w != wxDefaultCoord ) | |
1957 | { | |
1958 | constr->width.SetValue(w); | |
1959 | constr->width.SetDone(true); | |
1960 | } | |
1961 | if ( h != wxDefaultCoord ) | |
1962 | { | |
1963 | constr->height.SetValue(h); | |
1964 | constr->height.SetDone(true); | |
1965 | } | |
1966 | } | |
1967 | } | |
1968 | ||
1969 | void wxWindowBase::MoveConstraint(int x, int y) | |
1970 | { | |
1971 | wxLayoutConstraints *constr = GetConstraints(); | |
1972 | if ( constr ) | |
1973 | { | |
1974 | if ( x != wxDefaultCoord ) | |
1975 | { | |
1976 | constr->left.SetValue(x); | |
1977 | constr->left.SetDone(true); | |
1978 | } | |
1979 | if ( y != wxDefaultCoord ) | |
1980 | { | |
1981 | constr->top.SetValue(y); | |
1982 | constr->top.SetDone(true); | |
1983 | } | |
1984 | } | |
1985 | } | |
1986 | ||
1987 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
1988 | { | |
1989 | wxLayoutConstraints *constr = GetConstraints(); | |
1990 | if ( constr ) | |
1991 | { | |
1992 | *w = constr->width.GetValue(); | |
1993 | *h = constr->height.GetValue(); | |
1994 | } | |
1995 | else | |
1996 | GetSize(w, h); | |
1997 | } | |
1998 | ||
1999 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
2000 | { | |
2001 | wxLayoutConstraints *constr = GetConstraints(); | |
2002 | if ( constr ) | |
2003 | { | |
2004 | *w = constr->width.GetValue(); | |
2005 | *h = constr->height.GetValue(); | |
2006 | } | |
2007 | else | |
2008 | GetClientSize(w, h); | |
2009 | } | |
2010 | ||
2011 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const | |
2012 | { | |
2013 | wxLayoutConstraints *constr = GetConstraints(); | |
2014 | if ( constr ) | |
2015 | { | |
2016 | *x = constr->left.GetValue(); | |
2017 | *y = constr->top.GetValue(); | |
2018 | } | |
2019 | else | |
2020 | GetPosition(x, y); | |
2021 | } | |
2022 | ||
2023 | #endif // wxUSE_CONSTRAINTS | |
2024 | ||
2025 | void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const | |
2026 | { | |
2027 | // don't do it for the dialogs/frames - they float independently of their | |
2028 | // parent | |
2029 | if ( !IsTopLevel() ) | |
2030 | { | |
2031 | wxWindow *parent = GetParent(); | |
2032 | if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent ) | |
2033 | { | |
2034 | wxPoint pt(parent->GetClientAreaOrigin()); | |
2035 | x += pt.x; | |
2036 | y += pt.y; | |
2037 | } | |
2038 | } | |
2039 | } | |
2040 | ||
2041 | // ---------------------------------------------------------------------------- | |
2042 | // do Update UI processing for child controls | |
2043 | // ---------------------------------------------------------------------------- | |
2044 | ||
2045 | void wxWindowBase::UpdateWindowUI(long flags) | |
2046 | { | |
2047 | wxUpdateUIEvent event(GetId()); | |
2048 | event.SetEventObject(this); | |
2049 | ||
2050 | if ( GetEventHandler()->ProcessEvent(event) ) | |
2051 | { | |
2052 | DoUpdateWindowUI(event); | |
2053 | } | |
2054 | ||
2055 | if (flags & wxUPDATE_UI_RECURSE) | |
2056 | { | |
2057 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2058 | while (node) | |
2059 | { | |
2060 | wxWindow* child = (wxWindow*) node->GetData(); | |
2061 | child->UpdateWindowUI(flags); | |
2062 | node = node->GetNext(); | |
2063 | } | |
2064 | } | |
2065 | } | |
2066 | ||
2067 | // do the window-specific processing after processing the update event | |
2068 | // TODO: take specific knowledge out of this function and | |
2069 | // put in each control's base class. Unfortunately we don't | |
2070 | // yet have base implementation files for wxCheckBox and wxRadioButton. | |
2071 | void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event) | |
2072 | { | |
2073 | if ( event.GetSetEnabled() ) | |
2074 | Enable(event.GetEnabled()); | |
2075 | ||
2076 | #if wxUSE_CONTROLS | |
2077 | if ( event.GetSetText() ) | |
2078 | { | |
2079 | wxControl *control = wxDynamicCastThis(wxControl); | |
2080 | if ( control ) | |
2081 | { | |
2082 | if ( event.GetText() != control->GetLabel() ) | |
2083 | control->SetLabel(event.GetText()); | |
2084 | } | |
2085 | } | |
2086 | #endif // wxUSE_CONTROLS | |
2087 | ||
2088 | if ( event.GetSetChecked() ) | |
2089 | { | |
2090 | #if wxUSE_CHECKBOX | |
2091 | wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox); | |
2092 | if ( checkbox ) | |
2093 | { | |
2094 | checkbox->SetValue(event.GetChecked()); | |
2095 | } | |
2096 | #endif // wxUSE_CHECKBOX | |
2097 | ||
2098 | #if wxUSE_RADIOBTN | |
2099 | wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton); | |
2100 | if ( radiobtn ) | |
2101 | { | |
2102 | radiobtn->SetValue(event.GetChecked()); | |
2103 | } | |
2104 | #endif // wxUSE_RADIOBTN | |
2105 | } | |
2106 | } | |
2107 | ||
2108 | #if 0 | |
2109 | // call internal idle recursively | |
2110 | // may be obsolete (wait until OnIdle scheme stabilises) | |
2111 | void wxWindowBase::ProcessInternalIdle() | |
2112 | { | |
2113 | OnInternalIdle(); | |
2114 | ||
2115 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2116 | while (node) | |
2117 | { | |
2118 | wxWindow *child = node->GetData(); | |
2119 | child->ProcessInternalIdle(); | |
2120 | node = node->GetNext(); | |
2121 | } | |
2122 | } | |
2123 | #endif | |
2124 | ||
2125 | // ---------------------------------------------------------------------------- | |
2126 | // dialog units translations | |
2127 | // ---------------------------------------------------------------------------- | |
2128 | ||
2129 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) | |
2130 | { | |
2131 | int charWidth = GetCharWidth(); | |
2132 | int charHeight = GetCharHeight(); | |
2133 | wxPoint pt2 = wxDefaultPosition; | |
2134 | if (pt.x != wxDefaultCoord) | |
2135 | pt2.x = (int) ((pt.x * 4) / charWidth); | |
2136 | if (pt.y != wxDefaultCoord) | |
2137 | pt2.y = (int) ((pt.y * 8) / charHeight); | |
2138 | ||
2139 | return pt2; | |
2140 | } | |
2141 | ||
2142 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) | |
2143 | { | |
2144 | int charWidth = GetCharWidth(); | |
2145 | int charHeight = GetCharHeight(); | |
2146 | wxPoint pt2 = wxDefaultPosition; | |
2147 | if (pt.x != wxDefaultCoord) | |
2148 | pt2.x = (int) ((pt.x * charWidth) / 4); | |
2149 | if (pt.y != wxDefaultCoord) | |
2150 | pt2.y = (int) ((pt.y * charHeight) / 8); | |
2151 | ||
2152 | return pt2; | |
2153 | } | |
2154 | ||
2155 | // ---------------------------------------------------------------------------- | |
2156 | // event handlers | |
2157 | // ---------------------------------------------------------------------------- | |
2158 | ||
2159 | // propagate the colour change event to the subwindows | |
2160 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) | |
2161 | { | |
2162 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2163 | while ( node ) | |
2164 | { | |
2165 | // Only propagate to non-top-level windows | |
2166 | wxWindow *win = node->GetData(); | |
2167 | if ( !win->IsTopLevel() ) | |
2168 | { | |
2169 | wxSysColourChangedEvent event2; | |
2170 | event.SetEventObject(win); | |
2171 | win->GetEventHandler()->ProcessEvent(event2); | |
2172 | } | |
2173 | ||
2174 | node = node->GetNext(); | |
2175 | } | |
2176 | ||
2177 | Refresh(); | |
2178 | } | |
2179 | ||
2180 | // the default action is to populate dialog with data when it's created, | |
2181 | // and nudge the UI into displaying itself correctly in case | |
2182 | // we've turned the wxUpdateUIEvents frequency down low. | |
2183 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) | |
2184 | { | |
2185 | TransferDataToWindow(); | |
2186 | ||
2187 | // Update the UI at this point | |
2188 | UpdateWindowUI(wxUPDATE_UI_RECURSE); | |
2189 | } | |
2190 | ||
2191 | // process Ctrl-Alt-mclick | |
2192 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) | |
2193 | { | |
2194 | #if wxUSE_MSGDLG | |
2195 | if ( event.ControlDown() && event.AltDown() ) | |
2196 | { | |
2197 | // don't translate these strings | |
2198 | wxString port; | |
2199 | ||
2200 | #ifdef __WXUNIVERSAL__ | |
2201 | port = _T("Univ/"); | |
2202 | #endif // __WXUNIVERSAL__ | |
2203 | ||
2204 | switch ( wxGetOsVersion() ) | |
2205 | { | |
2206 | case wxMOTIF_X: port += _T("Motif"); break; | |
2207 | case wxMAC: | |
2208 | case wxMAC_DARWIN: port += _T("Mac"); break; | |
2209 | case wxBEOS: port += _T("BeOS"); break; | |
2210 | case wxGTK: | |
2211 | case wxGTK_WIN32: | |
2212 | case wxGTK_OS2: | |
2213 | case wxGTK_BEOS: port += _T("GTK"); break; | |
2214 | case wxWINDOWS: | |
2215 | case wxPENWINDOWS: | |
2216 | case wxWINDOWS_NT: | |
2217 | case wxWIN32S: | |
2218 | case wxWIN95: | |
2219 | case wxWIN386: port += _T("MS Windows"); break; | |
2220 | case wxMGL_UNIX: | |
2221 | case wxMGL_X: | |
2222 | case wxMGL_WIN32: | |
2223 | case wxMGL_OS2: port += _T("MGL"); break; | |
2224 | case wxWINDOWS_OS2: | |
2225 | case wxOS2_PM: port += _T("OS/2"); break; | |
2226 | default: port += _T("unknown"); break; | |
2227 | } | |
2228 | ||
2229 | wxMessageBox(wxString::Format( | |
2230 | _T( | |
2231 | " wxWidgets Library (%s port)\nVersion %u.%u.%u%s%s, compiled at %s %s\n Copyright (c) 1995-2004 wxWidgets team" | |
2232 | ), | |
2233 | port.c_str(), | |
2234 | wxMAJOR_VERSION, | |
2235 | wxMINOR_VERSION, | |
2236 | wxRELEASE_NUMBER, | |
2237 | #if wxUSE_UNICODE | |
2238 | L" (Unicode)", | |
2239 | #else | |
2240 | "", | |
2241 | #endif | |
2242 | #ifdef __WXDEBUG__ | |
2243 | _T(" Debug build"), | |
2244 | #else | |
2245 | wxEmptyString, | |
2246 | #endif | |
2247 | __TDATE__, | |
2248 | __TTIME__ | |
2249 | ), | |
2250 | _T("wxWidgets information"), | |
2251 | wxICON_INFORMATION | wxOK, | |
2252 | (wxWindow *)this); | |
2253 | } | |
2254 | else | |
2255 | #endif // wxUSE_MSGDLG | |
2256 | { | |
2257 | event.Skip(); | |
2258 | } | |
2259 | } | |
2260 | ||
2261 | // ---------------------------------------------------------------------------- | |
2262 | // accessibility | |
2263 | // ---------------------------------------------------------------------------- | |
2264 | ||
2265 | #if wxUSE_ACCESSIBILITY | |
2266 | void wxWindowBase::SetAccessible(wxAccessible* accessible) | |
2267 | { | |
2268 | if (m_accessible && (accessible != m_accessible)) | |
2269 | delete m_accessible; | |
2270 | m_accessible = accessible; | |
2271 | if (m_accessible) | |
2272 | m_accessible->SetWindow((wxWindow*) this); | |
2273 | } | |
2274 | ||
2275 | // Returns the accessible object, creating if necessary. | |
2276 | wxAccessible* wxWindowBase::GetOrCreateAccessible() | |
2277 | { | |
2278 | if (!m_accessible) | |
2279 | m_accessible = CreateAccessible(); | |
2280 | return m_accessible; | |
2281 | } | |
2282 | ||
2283 | // Override to create a specific accessible object. | |
2284 | wxAccessible* wxWindowBase::CreateAccessible() | |
2285 | { | |
2286 | return new wxWindowAccessible((wxWindow*) this); | |
2287 | } | |
2288 | ||
2289 | #endif | |
2290 | ||
2291 | #if !wxUSE_STL | |
2292 | // ---------------------------------------------------------------------------- | |
2293 | // list classes implementation | |
2294 | // ---------------------------------------------------------------------------- | |
2295 | ||
2296 | void wxWindowListNode::DeleteData() | |
2297 | { | |
2298 | delete (wxWindow *)GetData(); | |
2299 | } | |
2300 | #endif | |
2301 | ||
2302 | // ---------------------------------------------------------------------------- | |
2303 | // borders | |
2304 | // ---------------------------------------------------------------------------- | |
2305 | ||
2306 | wxBorder wxWindowBase::GetBorder(long flags) const | |
2307 | { | |
2308 | wxBorder border = (wxBorder)(flags & wxBORDER_MASK); | |
2309 | if ( border == wxBORDER_DEFAULT ) | |
2310 | { | |
2311 | border = GetDefaultBorder(); | |
2312 | } | |
2313 | ||
2314 | return border; | |
2315 | } | |
2316 | ||
2317 | wxBorder wxWindowBase::GetDefaultBorder() const | |
2318 | { | |
2319 | return wxBORDER_NONE; | |
2320 | } | |
2321 | ||
2322 | // ---------------------------------------------------------------------------- | |
2323 | // hit testing | |
2324 | // ---------------------------------------------------------------------------- | |
2325 | ||
2326 | wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const | |
2327 | { | |
2328 | // here we just check if the point is inside the window or not | |
2329 | ||
2330 | // check the top and left border first | |
2331 | bool outside = x < 0 || y < 0; | |
2332 | if ( !outside ) | |
2333 | { | |
2334 | // check the right and bottom borders too | |
2335 | wxSize size = GetSize(); | |
2336 | outside = x >= size.x || y >= size.y; | |
2337 | } | |
2338 | ||
2339 | return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE; | |
2340 | } | |
2341 | ||
2342 | // ---------------------------------------------------------------------------- | |
2343 | // mouse capture | |
2344 | // ---------------------------------------------------------------------------- | |
2345 | ||
2346 | struct WXDLLEXPORT wxWindowNext | |
2347 | { | |
2348 | wxWindow *win; | |
2349 | wxWindowNext *next; | |
2350 | } *wxWindowBase::ms_winCaptureNext = NULL; | |
2351 | ||
2352 | void wxWindowBase::CaptureMouse() | |
2353 | { | |
2354 | wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this); | |
2355 | ||
2356 | wxWindow *winOld = GetCapture(); | |
2357 | if ( winOld ) | |
2358 | { | |
2359 | ((wxWindowBase*) winOld)->DoReleaseMouse(); | |
2360 | ||
2361 | // save it on stack | |
2362 | wxWindowNext *item = new wxWindowNext; | |
2363 | item->win = winOld; | |
2364 | item->next = ms_winCaptureNext; | |
2365 | ms_winCaptureNext = item; | |
2366 | } | |
2367 | //else: no mouse capture to save | |
2368 | ||
2369 | DoCaptureMouse(); | |
2370 | } | |
2371 | ||
2372 | void wxWindowBase::ReleaseMouse() | |
2373 | { | |
2374 | wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this); | |
2375 | ||
2376 | wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") ); | |
2377 | ||
2378 | DoReleaseMouse(); | |
2379 | ||
2380 | if ( ms_winCaptureNext ) | |
2381 | { | |
2382 | ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse(); | |
2383 | ||
2384 | wxWindowNext *item = ms_winCaptureNext; | |
2385 | ms_winCaptureNext = item->next; | |
2386 | delete item; | |
2387 | } | |
2388 | //else: stack is empty, no previous capture | |
2389 | ||
2390 | wxLogTrace(_T("mousecapture"), | |
2391 | (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"), | |
2392 | GetCapture()); | |
2393 | } | |
2394 | ||
2395 | #if wxUSE_HOTKEY | |
2396 | ||
2397 | bool | |
2398 | wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId), | |
2399 | int WXUNUSED(modifiers), | |
2400 | int WXUNUSED(keycode)) | |
2401 | { | |
2402 | // not implemented | |
2403 | return false; | |
2404 | } | |
2405 | ||
2406 | bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId)) | |
2407 | { | |
2408 | // not implemented | |
2409 | return false; | |
2410 | } | |
2411 | ||
2412 | #endif // wxUSE_HOTKEY | |
2413 | ||
2414 | void wxWindowBase::SendDestroyEvent() | |
2415 | { | |
2416 | wxWindowDestroyEvent event; | |
2417 | event.SetEventObject(this); | |
2418 | event.SetId(GetId()); | |
2419 | GetEventHandler()->ProcessEvent(event); | |
2420 | } | |
2421 | ||
2422 | // ---------------------------------------------------------------------------- | |
2423 | // event processing | |
2424 | // ---------------------------------------------------------------------------- | |
2425 | ||
2426 | bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event)) | |
2427 | { | |
2428 | #if wxUSE_VALIDATORS | |
2429 | // Can only use the validator of the window which | |
2430 | // is receiving the event | |
2431 | if ( event.GetEventObject() == this ) | |
2432 | { | |
2433 | wxValidator *validator = GetValidator(); | |
2434 | if ( validator && validator->ProcessEvent(event) ) | |
2435 | { | |
2436 | return true; | |
2437 | } | |
2438 | } | |
2439 | #endif // wxUSE_VALIDATORS | |
2440 | ||
2441 | return false; | |
2442 | } | |
2443 | ||
2444 | bool wxWindowBase::TryParent(wxEvent& event) | |
2445 | { | |
2446 | // carry on up the parent-child hierarchy if the propgation count hasn't | |
2447 | // reached zero yet | |
2448 | if ( event.ShouldPropagate() ) | |
2449 | { | |
2450 | // honour the requests to stop propagation at this window: this is | |
2451 | // used by the dialogs, for example, to prevent processing the events | |
2452 | // from the dialog controls in the parent frame which rarely, if ever, | |
2453 | // makes sense | |
2454 | if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) ) | |
2455 | { | |
2456 | wxWindow *parent = GetParent(); | |
2457 | if ( parent && !parent->IsBeingDeleted() ) | |
2458 | { | |
2459 | wxPropagateOnce propagateOnce(event); | |
2460 | ||
2461 | return parent->GetEventHandler()->ProcessEvent(event); | |
2462 | } | |
2463 | } | |
2464 | } | |
2465 | ||
2466 | return wxEvtHandler::TryParent(event); | |
2467 | } | |
2468 | ||
2469 | // ---------------------------------------------------------------------------- | |
2470 | // keyboard navigation | |
2471 | // ---------------------------------------------------------------------------- | |
2472 | ||
2473 | // Navigates in the specified direction. | |
2474 | bool wxWindowBase::Navigate(int flags) | |
2475 | { | |
2476 | wxNavigationKeyEvent eventNav; | |
2477 | eventNav.SetFlags(flags); | |
2478 | eventNav.SetEventObject(this); | |
2479 | if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) | |
2480 | { | |
2481 | return true; | |
2482 | } | |
2483 | return false; | |
2484 | } | |
2485 | ||
2486 | void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move) | |
2487 | { | |
2488 | // check that we're not a top level window | |
2489 | wxCHECK_RET( GetParent(), | |
2490 | _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") ); | |
2491 | ||
2492 | // detect the special case when we have nothing to do anyhow and when the | |
2493 | // code below wouldn't work | |
2494 | if ( win == this ) | |
2495 | return; | |
2496 | ||
2497 | // find the target window in the siblings list | |
2498 | wxWindowList& siblings = GetParent()->GetChildren(); | |
2499 | wxWindowList::compatibility_iterator i = siblings.Find(win); | |
2500 | wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") ); | |
2501 | ||
2502 | // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we | |
2503 | // can't just move the node around | |
2504 | wxWindow *self = (wxWindow *)this; | |
2505 | siblings.DeleteObject(self); | |
2506 | if ( move == MoveAfter ) | |
2507 | { | |
2508 | i = i->GetNext(); | |
2509 | } | |
2510 | ||
2511 | if ( i ) | |
2512 | { | |
2513 | siblings.Insert(i, self); | |
2514 | } | |
2515 | else // MoveAfter and win was the last sibling | |
2516 | { | |
2517 | siblings.Append(self); | |
2518 | } | |
2519 | } | |
2520 | ||
2521 | // ---------------------------------------------------------------------------- | |
2522 | // focus handling | |
2523 | // ---------------------------------------------------------------------------- | |
2524 | ||
2525 | /*static*/ wxWindow* wxWindowBase::FindFocus() | |
2526 | { | |
2527 | wxWindowBase *win = DoFindFocus(); | |
2528 | return win ? win->GetMainWindowOfCompositeControl() : NULL; | |
2529 | } | |
2530 | ||
2531 | // ---------------------------------------------------------------------------- | |
2532 | // global functions | |
2533 | // ---------------------------------------------------------------------------- | |
2534 | ||
2535 | wxWindow* wxGetTopLevelParent(wxWindow *win) | |
2536 | { | |
2537 | while ( win && !win->IsTopLevel() ) | |
2538 | win = win->GetParent(); | |
2539 | ||
2540 | return win; | |
2541 | } | |
2542 | ||
2543 | #if wxUSE_ACCESSIBILITY | |
2544 | // ---------------------------------------------------------------------------- | |
2545 | // accessible object for windows | |
2546 | // ---------------------------------------------------------------------------- | |
2547 | ||
2548 | // Can return either a child object, or an integer | |
2549 | // representing the child element, starting from 1. | |
2550 | wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject)) | |
2551 | { | |
2552 | wxASSERT( GetWindow() != NULL ); | |
2553 | if (!GetWindow()) | |
2554 | return wxACC_FAIL; | |
2555 | ||
2556 | return wxACC_NOT_IMPLEMENTED; | |
2557 | } | |
2558 | ||
2559 | // Returns the rectangle for this object (id = 0) or a child element (id > 0). | |
2560 | wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId) | |
2561 | { | |
2562 | wxASSERT( GetWindow() != NULL ); | |
2563 | if (!GetWindow()) | |
2564 | return wxACC_FAIL; | |
2565 | ||
2566 | wxWindow* win = NULL; | |
2567 | if (elementId == 0) | |
2568 | { | |
2569 | win = GetWindow(); | |
2570 | } | |
2571 | else | |
2572 | { | |
2573 | if (elementId <= (int) GetWindow()->GetChildren().GetCount()) | |
2574 | { | |
2575 | win = GetWindow()->GetChildren().Item(elementId-1)->GetData(); | |
2576 | } | |
2577 | else | |
2578 | return wxACC_FAIL; | |
2579 | } | |
2580 | if (win) | |
2581 | { | |
2582 | rect = win->GetRect(); | |
2583 | if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow))) | |
2584 | rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition())); | |
2585 | return wxACC_OK; | |
2586 | } | |
2587 | ||
2588 | return wxACC_NOT_IMPLEMENTED; | |
2589 | } | |
2590 | ||
2591 | // Navigates from fromId to toId/toObject. | |
2592 | wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId, | |
2593 | int* WXUNUSED(toId), wxAccessible** toObject) | |
2594 | { | |
2595 | wxASSERT( GetWindow() != NULL ); | |
2596 | if (!GetWindow()) | |
2597 | return wxACC_FAIL; | |
2598 | ||
2599 | switch (navDir) | |
2600 | { | |
2601 | case wxNAVDIR_FIRSTCHILD: | |
2602 | { | |
2603 | if (GetWindow()->GetChildren().GetCount() == 0) | |
2604 | return wxACC_FALSE; | |
2605 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData(); | |
2606 | *toObject = childWindow->GetOrCreateAccessible(); | |
2607 | ||
2608 | return wxACC_OK; | |
2609 | } | |
2610 | case wxNAVDIR_LASTCHILD: | |
2611 | { | |
2612 | if (GetWindow()->GetChildren().GetCount() == 0) | |
2613 | return wxACC_FALSE; | |
2614 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData(); | |
2615 | *toObject = childWindow->GetOrCreateAccessible(); | |
2616 | ||
2617 | return wxACC_OK; | |
2618 | } | |
2619 | case wxNAVDIR_RIGHT: | |
2620 | case wxNAVDIR_DOWN: | |
2621 | case wxNAVDIR_NEXT: | |
2622 | { | |
2623 | wxWindowList::compatibility_iterator node = | |
2624 | wxWindowList::compatibility_iterator(); | |
2625 | if (fromId == 0) | |
2626 | { | |
2627 | // Can't navigate to sibling of this window | |
2628 | // if we're a top-level window. | |
2629 | if (!GetWindow()->GetParent()) | |
2630 | return wxACC_NOT_IMPLEMENTED; | |
2631 | ||
2632 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
2633 | } | |
2634 | else | |
2635 | { | |
2636 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
2637 | node = GetWindow()->GetChildren().Item(fromId-1); | |
2638 | } | |
2639 | ||
2640 | if (node && node->GetNext()) | |
2641 | { | |
2642 | wxWindow* nextWindow = node->GetNext()->GetData(); | |
2643 | *toObject = nextWindow->GetOrCreateAccessible(); | |
2644 | return wxACC_OK; | |
2645 | } | |
2646 | else | |
2647 | return wxACC_FALSE; | |
2648 | } | |
2649 | case wxNAVDIR_LEFT: | |
2650 | case wxNAVDIR_UP: | |
2651 | case wxNAVDIR_PREVIOUS: | |
2652 | { | |
2653 | wxWindowList::compatibility_iterator node = | |
2654 | wxWindowList::compatibility_iterator(); | |
2655 | if (fromId == 0) | |
2656 | { | |
2657 | // Can't navigate to sibling of this window | |
2658 | // if we're a top-level window. | |
2659 | if (!GetWindow()->GetParent()) | |
2660 | return wxACC_NOT_IMPLEMENTED; | |
2661 | ||
2662 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
2663 | } | |
2664 | else | |
2665 | { | |
2666 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
2667 | node = GetWindow()->GetChildren().Item(fromId-1); | |
2668 | } | |
2669 | ||
2670 | if (node && node->GetPrevious()) | |
2671 | { | |
2672 | wxWindow* previousWindow = node->GetPrevious()->GetData(); | |
2673 | *toObject = previousWindow->GetOrCreateAccessible(); | |
2674 | return wxACC_OK; | |
2675 | } | |
2676 | else | |
2677 | return wxACC_FALSE; | |
2678 | } | |
2679 | } | |
2680 | ||
2681 | return wxACC_NOT_IMPLEMENTED; | |
2682 | } | |
2683 | ||
2684 | // Gets the name of the specified object. | |
2685 | wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name) | |
2686 | { | |
2687 | wxASSERT( GetWindow() != NULL ); | |
2688 | if (!GetWindow()) | |
2689 | return wxACC_FAIL; | |
2690 | ||
2691 | wxString title; | |
2692 | ||
2693 | // If a child, leave wxWidgets to call the function on the actual | |
2694 | // child object. | |
2695 | if (childId > 0) | |
2696 | return wxACC_NOT_IMPLEMENTED; | |
2697 | ||
2698 | // This will eventually be replaced by specialised | |
2699 | // accessible classes, one for each kind of wxWidgets | |
2700 | // control or window. | |
2701 | #if wxUSE_BUTTON | |
2702 | if (GetWindow()->IsKindOf(CLASSINFO(wxButton))) | |
2703 | title = ((wxButton*) GetWindow())->GetLabel(); | |
2704 | else | |
2705 | #endif | |
2706 | title = GetWindow()->GetName(); | |
2707 | ||
2708 | if (!title.empty()) | |
2709 | { | |
2710 | *name = title; | |
2711 | return wxACC_OK; | |
2712 | } | |
2713 | else | |
2714 | return wxACC_NOT_IMPLEMENTED; | |
2715 | } | |
2716 | ||
2717 | // Gets the number of children. | |
2718 | wxAccStatus wxWindowAccessible::GetChildCount(int* childId) | |
2719 | { | |
2720 | wxASSERT( GetWindow() != NULL ); | |
2721 | if (!GetWindow()) | |
2722 | return wxACC_FAIL; | |
2723 | ||
2724 | *childId = (int) GetWindow()->GetChildren().GetCount(); | |
2725 | return wxACC_OK; | |
2726 | } | |
2727 | ||
2728 | // Gets the specified child (starting from 1). | |
2729 | // If *child is NULL and return value is wxACC_OK, | |
2730 | // this means that the child is a simple element and | |
2731 | // not an accessible object. | |
2732 | wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child) | |
2733 | { | |
2734 | wxASSERT( GetWindow() != NULL ); | |
2735 | if (!GetWindow()) | |
2736 | return wxACC_FAIL; | |
2737 | ||
2738 | if (childId == 0) | |
2739 | { | |
2740 | *child = this; | |
2741 | return wxACC_OK; | |
2742 | } | |
2743 | ||
2744 | if (childId > (int) GetWindow()->GetChildren().GetCount()) | |
2745 | return wxACC_FAIL; | |
2746 | ||
2747 | wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData(); | |
2748 | *child = childWindow->GetOrCreateAccessible(); | |
2749 | if (*child) | |
2750 | return wxACC_OK; | |
2751 | else | |
2752 | return wxACC_FAIL; | |
2753 | } | |
2754 | ||
2755 | // Gets the parent, or NULL. | |
2756 | wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent) | |
2757 | { | |
2758 | wxASSERT( GetWindow() != NULL ); | |
2759 | if (!GetWindow()) | |
2760 | return wxACC_FAIL; | |
2761 | ||
2762 | wxWindow* parentWindow = GetWindow()->GetParent(); | |
2763 | if (!parentWindow) | |
2764 | { | |
2765 | *parent = NULL; | |
2766 | return wxACC_OK; | |
2767 | } | |
2768 | else | |
2769 | { | |
2770 | *parent = parentWindow->GetOrCreateAccessible(); | |
2771 | if (*parent) | |
2772 | return wxACC_OK; | |
2773 | else | |
2774 | return wxACC_FAIL; | |
2775 | } | |
2776 | } | |
2777 | ||
2778 | // Performs the default action. childId is 0 (the action for this object) | |
2779 | // or > 0 (the action for a child). | |
2780 | // Return wxACC_NOT_SUPPORTED if there is no default action for this | |
2781 | // window (e.g. an edit control). | |
2782 | wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId)) | |
2783 | { | |
2784 | wxASSERT( GetWindow() != NULL ); | |
2785 | if (!GetWindow()) | |
2786 | return wxACC_FAIL; | |
2787 | ||
2788 | return wxACC_NOT_IMPLEMENTED; | |
2789 | } | |
2790 | ||
2791 | // Gets the default action for this object (0) or > 0 (the action for a child). | |
2792 | // Return wxACC_OK even if there is no action. actionName is the action, or the empty | |
2793 | // string if there is no action. | |
2794 | // The retrieved string describes the action that is performed on an object, | |
2795 | // not what the object does as a result. For example, a toolbar button that prints | |
2796 | // a document has a default action of "Press" rather than "Prints the current document." | |
2797 | wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName)) | |
2798 | { | |
2799 | wxASSERT( GetWindow() != NULL ); | |
2800 | if (!GetWindow()) | |
2801 | return wxACC_FAIL; | |
2802 | ||
2803 | return wxACC_NOT_IMPLEMENTED; | |
2804 | } | |
2805 | ||
2806 | // Returns the description for this object or a child. | |
2807 | wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description) | |
2808 | { | |
2809 | wxASSERT( GetWindow() != NULL ); | |
2810 | if (!GetWindow()) | |
2811 | return wxACC_FAIL; | |
2812 | ||
2813 | wxString ht(GetWindow()->GetHelpText()); | |
2814 | if (!ht.empty()) | |
2815 | { | |
2816 | *description = ht; | |
2817 | return wxACC_OK; | |
2818 | } | |
2819 | return wxACC_NOT_IMPLEMENTED; | |
2820 | } | |
2821 | ||
2822 | // Returns help text for this object or a child, similar to tooltip text. | |
2823 | wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText) | |
2824 | { | |
2825 | wxASSERT( GetWindow() != NULL ); | |
2826 | if (!GetWindow()) | |
2827 | return wxACC_FAIL; | |
2828 | ||
2829 | wxString ht(GetWindow()->GetHelpText()); | |
2830 | if (!ht.empty()) | |
2831 | { | |
2832 | *helpText = ht; | |
2833 | return wxACC_OK; | |
2834 | } | |
2835 | return wxACC_NOT_IMPLEMENTED; | |
2836 | } | |
2837 | ||
2838 | // Returns the keyboard shortcut for this object or child. | |
2839 | // Return e.g. ALT+K | |
2840 | wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut)) | |
2841 | { | |
2842 | wxASSERT( GetWindow() != NULL ); | |
2843 | if (!GetWindow()) | |
2844 | return wxACC_FAIL; | |
2845 | ||
2846 | return wxACC_NOT_IMPLEMENTED; | |
2847 | } | |
2848 | ||
2849 | // Returns a role constant. | |
2850 | wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role) | |
2851 | { | |
2852 | wxASSERT( GetWindow() != NULL ); | |
2853 | if (!GetWindow()) | |
2854 | return wxACC_FAIL; | |
2855 | ||
2856 | // If a child, leave wxWidgets to call the function on the actual | |
2857 | // child object. | |
2858 | if (childId > 0) | |
2859 | return wxACC_NOT_IMPLEMENTED; | |
2860 | ||
2861 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
2862 | return wxACC_NOT_IMPLEMENTED; | |
2863 | #if wxUSE_STATUSBAR | |
2864 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
2865 | return wxACC_NOT_IMPLEMENTED; | |
2866 | #endif | |
2867 | #if wxUSE_TOOLBAR | |
2868 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
2869 | return wxACC_NOT_IMPLEMENTED; | |
2870 | #endif | |
2871 | ||
2872 | //*role = wxROLE_SYSTEM_CLIENT; | |
2873 | *role = wxROLE_SYSTEM_CLIENT; | |
2874 | return wxACC_OK; | |
2875 | ||
2876 | #if 0 | |
2877 | return wxACC_NOT_IMPLEMENTED; | |
2878 | #endif | |
2879 | } | |
2880 | ||
2881 | // Returns a state constant. | |
2882 | wxAccStatus wxWindowAccessible::GetState(int childId, long* state) | |
2883 | { | |
2884 | wxASSERT( GetWindow() != NULL ); | |
2885 | if (!GetWindow()) | |
2886 | return wxACC_FAIL; | |
2887 | ||
2888 | // If a child, leave wxWidgets to call the function on the actual | |
2889 | // child object. | |
2890 | if (childId > 0) | |
2891 | return wxACC_NOT_IMPLEMENTED; | |
2892 | ||
2893 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
2894 | return wxACC_NOT_IMPLEMENTED; | |
2895 | ||
2896 | #if wxUSE_STATUSBAR | |
2897 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
2898 | return wxACC_NOT_IMPLEMENTED; | |
2899 | #endif | |
2900 | #if wxUSE_TOOLBAR | |
2901 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
2902 | return wxACC_NOT_IMPLEMENTED; | |
2903 | #endif | |
2904 | ||
2905 | *state = 0; | |
2906 | return wxACC_OK; | |
2907 | ||
2908 | #if 0 | |
2909 | return wxACC_NOT_IMPLEMENTED; | |
2910 | #endif | |
2911 | } | |
2912 | ||
2913 | // Returns a localized string representing the value for the object | |
2914 | // or child. | |
2915 | wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue)) | |
2916 | { | |
2917 | wxASSERT( GetWindow() != NULL ); | |
2918 | if (!GetWindow()) | |
2919 | return wxACC_FAIL; | |
2920 | ||
2921 | return wxACC_NOT_IMPLEMENTED; | |
2922 | } | |
2923 | ||
2924 | // Selects the object or child. | |
2925 | wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags)) | |
2926 | { | |
2927 | wxASSERT( GetWindow() != NULL ); | |
2928 | if (!GetWindow()) | |
2929 | return wxACC_FAIL; | |
2930 | ||
2931 | return wxACC_NOT_IMPLEMENTED; | |
2932 | } | |
2933 | ||
2934 | // Gets the window with the keyboard focus. | |
2935 | // If childId is 0 and child is NULL, no object in | |
2936 | // this subhierarchy has the focus. | |
2937 | // If this object has the focus, child should be 'this'. | |
2938 | wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child)) | |
2939 | { | |
2940 | wxASSERT( GetWindow() != NULL ); | |
2941 | if (!GetWindow()) | |
2942 | return wxACC_FAIL; | |
2943 | ||
2944 | return wxACC_NOT_IMPLEMENTED; | |
2945 | } | |
2946 | ||
2947 | // Gets a variant representing the selected children | |
2948 | // of this object. | |
2949 | // Acceptable values: | |
2950 | // - a null variant (IsNull() returns true) | |
2951 | // - a list variant (GetType() == wxT("list") | |
2952 | // - an integer representing the selected child element, | |
2953 | // or 0 if this object is selected (GetType() == wxT("long") | |
2954 | // - a "void*" pointer to a wxAccessible child object | |
2955 | wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections)) | |
2956 | { | |
2957 | wxASSERT( GetWindow() != NULL ); | |
2958 | if (!GetWindow()) | |
2959 | return wxACC_FAIL; | |
2960 | ||
2961 | return wxACC_NOT_IMPLEMENTED; | |
2962 | } | |
2963 | ||
2964 | #endif // wxUSE_ACCESSIBILITY |