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