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