]>
Commit | Line | Data |
---|---|---|
7ec1983b | 1 | ///////////////////////////////////////////////////////////////////////////// |
7ec69821 | 2 | // Name: src/common/window.cpp |
7ec1983b VZ |
3 | // Purpose: common (to all ports) wxWindow functions |
4 | // Author: Julian Smart, Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 13/07/98 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
7ec1983b VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
f03fc89f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
f701d7ab | 19 | |
341287bf JS |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
f701d7ab | 23 | #ifdef __BORLANDC__ |
f03fc89f | 24 | #pragma hdrstop |
f701d7ab JS |
25 | #endif |
26 | ||
f03fc89f VZ |
27 | #ifndef WX_PRECOMP |
28 | #include "wx/string.h" | |
29 | #include "wx/log.h" | |
30 | #include "wx/intl.h" | |
31 | #include "wx/frame.h" | |
f03fc89f | 32 | #include "wx/window.h" |
1e6feb95 | 33 | #include "wx/control.h" |
f03fc89f VZ |
34 | #include "wx/checkbox.h" |
35 | #include "wx/radiobut.h" | |
106844da | 36 | #include "wx/statbox.h" |
26bf1ce0 | 37 | #include "wx/textctrl.h" |
f03fc89f VZ |
38 | #include "wx/settings.h" |
39 | #include "wx/dialog.h" | |
a02dc3e3 | 40 | #include "wx/msgdlg.h" |
1b942d5f | 41 | #include "wx/msgout.h" |
a37a5a73 | 42 | #include "wx/statusbr.h" |
e0cf3745 | 43 | #include "wx/toolbar.h" |
ed39ff57 | 44 | #include "wx/dcclient.h" |
7d59475e | 45 | #include "wx/scrolbar.h" |
f03fc89f | 46 | #include "wx/layout.h" |
ed2fbeb8 | 47 | #include "wx/sizer.h" |
8515098c | 48 | #include "wx/menu.h" |
ed2fbeb8 | 49 | #endif //WX_PRECOMP |
461e93f9 | 50 | |
f03fc89f VZ |
51 | #if wxUSE_DRAG_AND_DROP |
52 | #include "wx/dnd.h" | |
53 | #endif // wxUSE_DRAG_AND_DROP | |
54 | ||
ed5317e5 | 55 | #if wxUSE_ACCESSIBILITY |
7de59551 | 56 | #include "wx/access.h" |
ed5317e5 JS |
57 | #endif |
58 | ||
bd83cb56 VZ |
59 | #if wxUSE_HELP |
60 | #include "wx/cshelp.h" | |
61 | #endif // wxUSE_HELP | |
62 | ||
f03fc89f VZ |
63 | #if wxUSE_TOOLTIPS |
64 | #include "wx/tooltip.h" | |
65 | #endif // wxUSE_TOOLTIPS | |
66 | ||
789295bf VZ |
67 | #if wxUSE_CARET |
68 | #include "wx/caret.h" | |
69 | #endif // wxUSE_CARET | |
70 | ||
ff9f7a12 | 71 | #if wxUSE_SYSTEM_OPTIONS |
cab1a605 | 72 | #include "wx/sysopt.h" |
ff9f7a12 SC |
73 | #endif |
74 | ||
8bb6b2c0 VZ |
75 | #include "wx/platinfo.h" |
76 | ||
e7445ff8 PC |
77 | // Windows List |
78 | WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows; | |
79 | ||
eeb0bee1 | 80 | // globals |
8bb08801 | 81 | #if wxUSE_MENUS |
eeb0bee1 | 82 | wxMenu *wxCurrentPopupMenu = NULL; |
8bb08801 | 83 | #endif // wxUSE_MENUS |
eeb0bee1 | 84 | |
f03fc89f VZ |
85 | // ---------------------------------------------------------------------------- |
86 | // static data | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
f03fc89f VZ |
89 | |
90 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
91 | ||
92 | // ---------------------------------------------------------------------------- | |
93 | // event table | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
97 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
98 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
a02dc3e3 | 99 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) |
bd83cb56 VZ |
100 | |
101 | #if wxUSE_HELP | |
e11f4636 | 102 | EVT_HELP(wxID_ANY, wxWindowBase::OnHelp) |
bd83cb56 VZ |
103 | #endif // wxUSE_HELP |
104 | ||
6528a7f1 | 105 | EVT_SIZE(wxWindowBase::InternalOnSize) |
f03fc89f VZ |
106 | END_EVENT_TABLE() |
107 | ||
108 | // ============================================================================ | |
109 | // implementation of the common functionality of the wxWindow class | |
110 | // ============================================================================ | |
111 | ||
112 | // ---------------------------------------------------------------------------- | |
113 | // initialization | |
114 | // ---------------------------------------------------------------------------- | |
115 | ||
116 | // the default initialization | |
72795335 | 117 | wxWindowBase::wxWindowBase() |
f03fc89f VZ |
118 | { |
119 | // no window yet, no parent nor children | |
d3b9f782 | 120 | m_parent = NULL; |
e11f4636 | 121 | m_windowId = wxID_ANY; |
f03fc89f VZ |
122 | |
123 | // no constraints on the minimal window size | |
124 | m_minWidth = | |
422d0ff0 | 125 | m_maxWidth = wxDefaultCoord; |
f03fc89f | 126 | m_minHeight = |
422d0ff0 | 127 | m_maxHeight = wxDefaultCoord; |
f03fc89f | 128 | |
9f884528 RD |
129 | // invalidiated cache value |
130 | m_bestSizeCache = wxDefaultSize; | |
131 | ||
eefe6d4b VZ |
132 | // window are created enabled and visible by default |
133 | m_isShown = | |
e11f4636 | 134 | m_isEnabled = true; |
f03fc89f | 135 | |
f03fc89f VZ |
136 | // the default event handler is just this window |
137 | m_eventHandler = this; | |
138 | ||
88ac883a | 139 | #if wxUSE_VALIDATORS |
f03fc89f | 140 | // no validator |
d3b9f782 | 141 | m_windowValidator = NULL; |
88ac883a | 142 | #endif // wxUSE_VALIDATORS |
f03fc89f | 143 | |
1b69c815 VZ |
144 | // the colours/fonts are default for now, so leave m_font, |
145 | // m_backgroundColour and m_foregroundColour uninitialized and set those | |
08df3e44 VZ |
146 | m_hasBgCol = |
147 | m_hasFgCol = | |
e11f4636 | 148 | m_hasFont = false; |
f8ff87ed VS |
149 | m_inheritBgCol = |
150 | m_inheritFgCol = | |
151 | m_inheritFont = false; | |
e11f4636 | 152 | |
f03fc89f | 153 | // no style bits |
d80cd92a | 154 | m_exStyle = |
f03fc89f | 155 | m_windowStyle = 0; |
cab1a605 | 156 | |
9c61c5b0 | 157 | m_backgroundStyle = wxBG_STYLE_ERASE; |
f03fc89f | 158 | |
f03fc89f VZ |
159 | #if wxUSE_CONSTRAINTS |
160 | // no constraints whatsoever | |
d3b9f782 VZ |
161 | m_constraints = NULL; |
162 | m_constraintsInvolvedIn = NULL; | |
461e93f9 JS |
163 | #endif // wxUSE_CONSTRAINTS |
164 | ||
d3b9f782 VZ |
165 | m_windowSizer = NULL; |
166 | m_containingSizer = NULL; | |
e11f4636 | 167 | m_autoLayout = false; |
f03fc89f VZ |
168 | |
169 | #if wxUSE_DRAG_AND_DROP | |
d3b9f782 | 170 | m_dropTarget = NULL; |
f03fc89f VZ |
171 | #endif // wxUSE_DRAG_AND_DROP |
172 | ||
173 | #if wxUSE_TOOLTIPS | |
d3b9f782 | 174 | m_tooltip = NULL; |
f03fc89f | 175 | #endif // wxUSE_TOOLTIPS |
789295bf VZ |
176 | |
177 | #if wxUSE_CARET | |
d3b9f782 | 178 | m_caret = NULL; |
789295bf | 179 | #endif // wxUSE_CARET |
a2d93e73 | 180 | |
574c939e | 181 | #if wxUSE_PALETTE |
e11f4636 | 182 | m_hasCustomPalette = false; |
574c939e KB |
183 | #endif // wxUSE_PALETTE |
184 | ||
ed5317e5 JS |
185 | #if wxUSE_ACCESSIBILITY |
186 | m_accessible = NULL; | |
187 | #endif | |
188 | ||
566d84a7 | 189 | m_virtualSize = wxDefaultSize; |
1b69c815 | 190 | |
d3b9f782 | 191 | m_scrollHelper = NULL; |
f4fe2f20 | 192 | |
1b69c815 | 193 | m_windowVariant = wxWINDOW_VARIANT_NORMAL; |
ff9f7a12 SC |
194 | #if wxUSE_SYSTEM_OPTIONS |
195 | if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT) ) | |
196 | { | |
197 | m_windowVariant = (wxWindowVariant) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT ) ; | |
198 | } | |
199 | #endif | |
69d90995 | 200 | |
a2d93e73 | 201 | // Whether we're using the current theme for this window (wxGTK only for now) |
e11f4636 | 202 | m_themeEnabled = false; |
1b69c815 | 203 | |
c6212a0c VZ |
204 | // This is set to true by SendDestroyEvent() which should be called by the |
205 | // most derived class to ensure that the destruction event is sent as soon | |
206 | // as possible to allow its handlers to still see the undestroyed window | |
1b69c815 | 207 | m_isBeingDeleted = false; |
17808a75 VZ |
208 | |
209 | m_freezeCount = 0; | |
f03fc89f VZ |
210 | } |
211 | ||
212 | // common part of window creation process | |
213 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
214 | wxWindowID id, | |
74e3313b | 215 | const wxPoint& WXUNUSED(pos), |
400a9e41 | 216 | const wxSize& WXUNUSED(size), |
f03fc89f | 217 | long style, |
ac8d0c11 | 218 | const wxValidator& wxVALIDATOR_PARAM(validator), |
f03fc89f VZ |
219 | const wxString& name) |
220 | { | |
925f154d VZ |
221 | // ids are limited to 16 bits under MSW so if you care about portability, |
222 | // it's not a good idea to use ids out of this range (and negative ids are | |
77ffb593 | 223 | // reserved for wxWidgets own usage) |
f35fdf7e VZ |
224 | wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767) || |
225 | (id >= wxID_AUTO_LOWEST && id <= wxID_AUTO_HIGHEST), | |
925f154d VZ |
226 | _T("invalid id value") ); |
227 | ||
f03fc89f | 228 | // generate a new id if the user doesn't care about it |
f35fdf7e VZ |
229 | if ( id == wxID_ANY ) |
230 | { | |
231 | m_windowId = NewControlId(); | |
f35fdf7e VZ |
232 | } |
233 | else // valid id specified | |
234 | { | |
235 | m_windowId = id; | |
236 | } | |
f03fc89f | 237 | |
e96248c4 VZ |
238 | // don't use SetWindowStyleFlag() here, this function should only be called |
239 | // to change the flag after creation as it tries to reflect the changes in | |
240 | // flags by updating the window dynamically and we don't need this here | |
241 | m_windowStyle = style; | |
242 | ||
f03fc89f | 243 | SetName(name); |
f03fc89f | 244 | SetParent(parent); |
674ac8b9 VZ |
245 | |
246 | #if wxUSE_VALIDATORS | |
8d99be5f | 247 | SetValidator(validator); |
674ac8b9 | 248 | #endif // wxUSE_VALIDATORS |
f03fc89f | 249 | |
8ae6ce07 VZ |
250 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to |
251 | // have it too - like this it's possible to set it only in the top level | |
252 | // dialog/frame and all children will inherit it by defult | |
253 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
254 | { | |
9cb98d89 | 255 | SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY); |
8ae6ce07 VZ |
256 | } |
257 | ||
e11f4636 | 258 | return true; |
f03fc89f VZ |
259 | } |
260 | ||
d63312a9 VZ |
261 | bool wxWindowBase::ToggleWindowStyle(int flag) |
262 | { | |
263 | wxASSERT_MSG( flag, _T("flags with 0 value can't be toggled") ); | |
264 | ||
265 | bool rc; | |
266 | long style = GetWindowStyleFlag(); | |
267 | if ( style & flag ) | |
268 | { | |
269 | style &= ~flag; | |
270 | rc = false; | |
271 | } | |
272 | else // currently off | |
273 | { | |
274 | style |= flag; | |
275 | rc = true; | |
276 | } | |
277 | ||
278 | SetWindowStyleFlag(style); | |
279 | ||
280 | return rc; | |
281 | } | |
282 | ||
f03fc89f VZ |
283 | // ---------------------------------------------------------------------------- |
284 | // destruction | |
285 | // ---------------------------------------------------------------------------- | |
286 | ||
287 | // common clean up | |
288 | wxWindowBase::~wxWindowBase() | |
289 | { | |
349d1942 VS |
290 | wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") ); |
291 | ||
f03fc89f VZ |
292 | // FIXME if these 2 cases result from programming errors in the user code |
293 | // we should probably assert here instead of silently fixing them | |
294 | ||
295 | // Just in case the window has been Closed, but we're then deleting | |
296 | // immediately: don't leave dangling pointers. | |
297 | wxPendingDelete.DeleteObject(this); | |
298 | ||
299 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
300 | // we weren't a dialog class | |
222ed1d6 | 301 | wxTopLevelWindows.DeleteObject((wxWindow*)this); |
a23fd0e1 | 302 | |
3bc9aac0 | 303 | #if wxUSE_MENUS |
eeb0bee1 VZ |
304 | // The associated popup menu can still be alive, disassociate from it in |
305 | // this case | |
306 | if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetInvokingWindow() == this ) | |
307 | wxCurrentPopupMenu->SetInvokingWindow(NULL); | |
3bc9aac0 | 308 | #endif // wxUSE_MENUS |
eeb0bee1 | 309 | |
223d09f6 | 310 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); |
f03fc89f | 311 | |
f8ab85ae | 312 | // notify the parent about this window destruction |
f09df8b2 | 313 | if ( m_parent ) |
8e35ab96 | 314 | m_parent->RemoveChild(this); |
8e35ab96 | 315 | |
789295bf | 316 | #if wxUSE_CARET |
a2b436fb | 317 | delete m_caret; |
789295bf VZ |
318 | #endif // wxUSE_CARET |
319 | ||
88ac883a | 320 | #if wxUSE_VALIDATORS |
a2b436fb | 321 | delete m_windowValidator; |
88ac883a | 322 | #endif // wxUSE_VALIDATORS |
f03fc89f | 323 | |
f03fc89f VZ |
324 | #if wxUSE_CONSTRAINTS |
325 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
326 | // at deleted windows as they delete themselves. | |
327 | DeleteRelatedConstraints(); | |
328 | ||
329 | if ( m_constraints ) | |
330 | { | |
331 | // This removes any dangling pointers to this window in other windows' | |
332 | // constraintsInvolvedIn lists. | |
333 | UnsetConstraints(m_constraints); | |
334 | delete m_constraints; | |
335 | m_constraints = NULL; | |
336 | } | |
461e93f9 JS |
337 | #endif // wxUSE_CONSTRAINTS |
338 | ||
be90c029 | 339 | if ( m_containingSizer ) |
12a3f227 | 340 | m_containingSizer->Detach( (wxWindow*)this ); |
be90c029 | 341 | |
a2b436fb | 342 | delete m_windowSizer; |
f03fc89f | 343 | |
f03fc89f | 344 | #if wxUSE_DRAG_AND_DROP |
a2b436fb | 345 | delete m_dropTarget; |
f03fc89f VZ |
346 | #endif // wxUSE_DRAG_AND_DROP |
347 | ||
348 | #if wxUSE_TOOLTIPS | |
a2b436fb | 349 | delete m_tooltip; |
f03fc89f | 350 | #endif // wxUSE_TOOLTIPS |
b0ee47ff | 351 | |
ed5317e5 | 352 | #if wxUSE_ACCESSIBILITY |
a2b436fb | 353 | delete m_accessible; |
ed5317e5 | 354 | #endif |
d18d8bda VS |
355 | |
356 | #if wxUSE_HELP | |
357 | // NB: this has to be called unconditionally, because we don't know | |
358 | // whether this window has associated help text or not | |
359 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
360 | if ( helpProvider ) | |
361 | helpProvider->RemoveHelp(this); | |
362 | #endif | |
f03fc89f VZ |
363 | } |
364 | ||
a3ac93e3 VZ |
365 | bool wxWindowBase::IsBeingDeleted() const |
366 | { | |
367 | return m_isBeingDeleted || | |
368 | (!IsTopLevel() && m_parent && m_parent->IsBeingDeleted()); | |
369 | } | |
370 | ||
602a2e02 VZ |
371 | void wxWindowBase::SendDestroyEvent() |
372 | { | |
c6212a0c VZ |
373 | if ( m_isBeingDeleted ) |
374 | { | |
375 | // we could have been already called from a more derived class dtor, | |
376 | // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call | |
377 | // should be simply ignored | |
378 | return; | |
379 | } | |
380 | ||
381 | m_isBeingDeleted = true; | |
382 | ||
602a2e02 VZ |
383 | wxWindowDestroyEvent event; |
384 | event.SetEventObject(this); | |
385 | event.SetId(GetId()); | |
386 | GetEventHandler()->ProcessEvent(event); | |
387 | } | |
388 | ||
f03fc89f VZ |
389 | bool wxWindowBase::Destroy() |
390 | { | |
a79a6671 VZ |
391 | SendDestroyEvent(); |
392 | ||
f03fc89f VZ |
393 | delete this; |
394 | ||
e11f4636 | 395 | return true; |
f03fc89f VZ |
396 | } |
397 | ||
398 | bool wxWindowBase::Close(bool force) | |
399 | { | |
400 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
401 | event.SetEventObject(this); | |
f03fc89f VZ |
402 | event.SetCanVeto(!force); |
403 | ||
e11f4636 | 404 | // return false if window wasn't closed because the application vetoed the |
f03fc89f | 405 | // close event |
a50c5fcc | 406 | return HandleWindowEvent(event) && !event.GetVeto(); |
f03fc89f VZ |
407 | } |
408 | ||
409 | bool wxWindowBase::DestroyChildren() | |
410 | { | |
222ed1d6 | 411 | wxWindowList::compatibility_iterator node; |
a23fd0e1 | 412 | for ( ;; ) |
f03fc89f | 413 | { |
a23fd0e1 VZ |
414 | // we iterate until the list becomes empty |
415 | node = GetChildren().GetFirst(); | |
416 | if ( !node ) | |
417 | break; | |
418 | ||
f03fc89f | 419 | wxWindow *child = node->GetData(); |
a23fd0e1 | 420 | |
a79a6671 VZ |
421 | // note that we really want to delete it immediately so don't call the |
422 | // possible overridden Destroy() version which might not delete the | |
423 | // child immediately resulting in problems with our (top level) child | |
424 | // outliving its parent | |
425 | child->wxWindowBase::Destroy(); | |
a23fd0e1 VZ |
426 | |
427 | wxASSERT_MSG( !GetChildren().Find(child), | |
223d09f6 | 428 | wxT("child didn't remove itself using RemoveChild()") ); |
f03fc89f VZ |
429 | } |
430 | ||
e11f4636 | 431 | return true; |
f03fc89f VZ |
432 | } |
433 | ||
434 | // ---------------------------------------------------------------------------- | |
f68586e5 | 435 | // size/position related methods |
f03fc89f VZ |
436 | // ---------------------------------------------------------------------------- |
437 | ||
438 | // centre the window with respect to its parent in either (or both) directions | |
1f464296 | 439 | void wxWindowBase::DoCentre(int dir) |
f03fc89f | 440 | { |
1f464296 VZ |
441 | wxCHECK_RET( !(dir & wxCENTRE_ON_SCREEN) && GetParent(), |
442 | _T("this method only implements centering child windows") ); | |
ef397583 | 443 | |
1f464296 | 444 | SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir)); |
7631a292 RD |
445 | } |
446 | ||
f03fc89f VZ |
447 | // fits the window around the children |
448 | void wxWindowBase::Fit() | |
449 | { | |
74205969 | 450 | if ( !GetChildren().empty() ) |
f68586e5 | 451 | { |
1736f021 | 452 | SetSize(GetBestSize()); |
f68586e5 VZ |
453 | } |
454 | //else: do nothing if we have no children | |
455 | } | |
f03fc89f | 456 | |
2b5f62a0 VZ |
457 | // fits virtual size (ie. scrolled area etc.) around children |
458 | void wxWindowBase::FitInside() | |
459 | { | |
460 | if ( GetChildren().GetCount() > 0 ) | |
461 | { | |
462 | SetVirtualSize( GetBestVirtualSize() ); | |
463 | } | |
464 | } | |
465 | ||
7d59475e | 466 | // On Mac, scrollbars are explicitly children. |
d7928233 | 467 | #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) |
7d59475e JS |
468 | static bool wxHasRealChildren(const wxWindowBase* win) |
469 | { | |
470 | int realChildCount = 0; | |
cab1a605 | 471 | |
7d59475e JS |
472 | for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); |
473 | node; | |
474 | node = node->GetNext() ) | |
475 | { | |
476 | wxWindow *win = node->GetData(); | |
477 | if ( !win->IsTopLevel() && win->IsShown() && !win->IsKindOf(CLASSINFO(wxScrollBar))) | |
478 | realChildCount ++; | |
479 | } | |
480 | return (realChildCount > 0); | |
481 | } | |
482 | #endif | |
ba889513 | 483 | |
992b2ec4 VS |
484 | void wxWindowBase::InvalidateBestSize() |
485 | { | |
486 | m_bestSizeCache = wxDefaultSize; | |
487 | ||
488 | // parent's best size calculation may depend on its children's | |
5b7df27e WS |
489 | // as long as child window we are in is not top level window itself |
490 | // (because the TLW size is never resized automatically) | |
491 | // so let's invalidate it as well to be safe: | |
5ff84587 | 492 | if (m_parent && !IsTopLevel()) |
992b2ec4 VS |
493 | m_parent->InvalidateBestSize(); |
494 | } | |
7d59475e | 495 | |
f68586e5 VZ |
496 | // return the size best suited for the current window |
497 | wxSize wxWindowBase::DoGetBestSize() const | |
498 | { | |
08a19f64 | 499 | wxSize best; |
2997ca30 | 500 | |
ec5bb70d VZ |
501 | if ( m_windowSizer ) |
502 | { | |
7e0f7539 | 503 | best = m_windowSizer->GetMinSize(); |
ec5bb70d VZ |
504 | } |
505 | #if wxUSE_CONSTRAINTS | |
506 | else if ( m_constraints ) | |
507 | { | |
508 | wxConstCast(this, wxWindowBase)->SatisfyConstraints(); | |
509 | ||
510 | // our minimal acceptable size is such that all our windows fit inside | |
511 | int maxX = 0, | |
512 | maxY = 0; | |
513 | ||
222ed1d6 | 514 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
ec5bb70d VZ |
515 | node; |
516 | node = node->GetNext() ) | |
517 | { | |
518 | wxLayoutConstraints *c = node->GetData()->GetConstraints(); | |
519 | if ( !c ) | |
520 | { | |
521 | // it's not normal that we have an unconstrained child, but | |
522 | // what can we do about it? | |
523 | continue; | |
524 | } | |
525 | ||
526 | int x = c->right.GetValue(), | |
527 | y = c->bottom.GetValue(); | |
528 | ||
529 | if ( x > maxX ) | |
530 | maxX = x; | |
531 | ||
532 | if ( y > maxY ) | |
533 | maxY = y; | |
534 | ||
535 | // TODO: we must calculate the overlaps somehow, otherwise we | |
536 | // will never return a size bigger than the current one :-( | |
537 | } | |
538 | ||
08a19f64 | 539 | best = wxSize(maxX, maxY); |
ec5bb70d VZ |
540 | } |
541 | #endif // wxUSE_CONSTRAINTS | |
7d59475e | 542 | else if ( !GetChildren().empty() |
d7928233 | 543 | #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) |
7d59475e JS |
544 | && wxHasRealChildren(this) |
545 | #endif | |
546 | ) | |
f03fc89f | 547 | { |
54af2461 VZ |
548 | // our minimal acceptable size is such that all our visible child |
549 | // windows fit inside | |
f68586e5 VZ |
550 | int maxX = 0, |
551 | maxY = 0; | |
552 | ||
222ed1d6 | 553 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f68586e5 VZ |
554 | node; |
555 | node = node->GetNext() ) | |
42e69d6b | 556 | { |
f68586e5 | 557 | wxWindow *win = node->GetData(); |
54af2461 VZ |
558 | if ( win->IsTopLevel() |
559 | || !win->IsShown() | |
1e6feb95 | 560 | #if wxUSE_STATUSBAR |
54af2461 | 561 | || wxDynamicCast(win, wxStatusBar) |
1e6feb95 VZ |
562 | #endif // wxUSE_STATUSBAR |
563 | ) | |
f68586e5 VZ |
564 | { |
565 | // dialogs and frames lie in different top level windows - | |
7d9fd004 VZ |
566 | // don't deal with them here; as for the status bars, they |
567 | // don't lie in the client area at all | |
f68586e5 VZ |
568 | continue; |
569 | } | |
570 | ||
571 | int wx, wy, ww, wh; | |
572 | win->GetPosition(&wx, &wy); | |
3f5513f5 VZ |
573 | |
574 | // if the window hadn't been positioned yet, assume that it is in | |
575 | // the origin | |
422d0ff0 | 576 | if ( wx == wxDefaultCoord ) |
3f5513f5 | 577 | wx = 0; |
422d0ff0 | 578 | if ( wy == wxDefaultCoord ) |
3f5513f5 VZ |
579 | wy = 0; |
580 | ||
f68586e5 VZ |
581 | win->GetSize(&ww, &wh); |
582 | if ( wx + ww > maxX ) | |
583 | maxX = wx + ww; | |
584 | if ( wy + wh > maxY ) | |
585 | maxY = wy + wh; | |
42e69d6b VZ |
586 | } |
587 | ||
08a19f64 | 588 | best = wxSize(maxX, maxY); |
f68586e5 | 589 | } |
997c7280 | 590 | else // ! has children |
f68586e5 | 591 | { |
c0bb586f VZ |
592 | // for a generic window there is no natural best size so, if the |
593 | // minimal size is not set, use the current size but take care to | |
594 | // remember it as minimal size for the next time because our best size | |
595 | // should be constant: otherwise we could get into a situation when the | |
596 | // window is initially at some size, then expanded to a larger size and | |
597 | // then, when the containing window is shrunk back (because our initial | |
598 | // best size had been used for computing the parent min size), we can't | |
599 | // be shrunk back any more because our best size is now bigger | |
9240613a VZ |
600 | wxSize size = GetMinSize(); |
601 | if ( !size.IsFullySpecified() ) | |
602 | { | |
603 | size.SetDefaults(GetSize()); | |
604 | wxConstCast(this, wxWindowBase)->SetMinSize(size); | |
605 | } | |
c0bb586f VZ |
606 | |
607 | // return as-is, unadjusted by the client size difference. | |
9240613a | 608 | return size; |
f03fc89f | 609 | } |
08a19f64 RD |
610 | |
611 | // Add any difference between size and client size | |
612 | wxSize diff = GetSize() - GetClientSize(); | |
613 | best.x += wxMax(0, diff.x); | |
614 | best.y += wxMax(0, diff.y); | |
615 | ||
616 | return best; | |
f03fc89f VZ |
617 | } |
618 | ||
333d7052 VZ |
619 | // helper of GetWindowBorderSize(): as many ports don't implement support for |
620 | // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded | |
621 | // fallbacks in this case | |
d45a01e0 | 622 | static int wxGetMetricOrDefault(wxSystemMetric what, const wxWindowBase* win) |
333d7052 | 623 | { |
d45a01e0 PC |
624 | int rc = wxSystemSettings::GetMetric( |
625 | what, static_cast<wxWindow*>(const_cast<wxWindowBase*>(win))); | |
333d7052 VZ |
626 | if ( rc == -1 ) |
627 | { | |
628 | switch ( what ) | |
629 | { | |
630 | case wxSYS_BORDER_X: | |
631 | case wxSYS_BORDER_Y: | |
632 | // 2D border is by default 1 pixel wide | |
633 | rc = 1; | |
634 | break; | |
635 | ||
636 | case wxSYS_EDGE_X: | |
637 | case wxSYS_EDGE_Y: | |
638 | // 3D borders are by default 2 pixels | |
639 | rc = 2; | |
640 | break; | |
641 | ||
642 | default: | |
643 | wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") ); | |
644 | rc = 0; | |
645 | } | |
646 | } | |
647 | ||
648 | return rc; | |
649 | } | |
650 | ||
651 | wxSize wxWindowBase::GetWindowBorderSize() const | |
652 | { | |
653 | wxSize size; | |
654 | ||
655 | switch ( GetBorder() ) | |
656 | { | |
657 | case wxBORDER_NONE: | |
658 | // nothing to do, size is already (0, 0) | |
659 | break; | |
660 | ||
661 | case wxBORDER_SIMPLE: | |
662 | case wxBORDER_STATIC: | |
d45a01e0 PC |
663 | size.x = wxGetMetricOrDefault(wxSYS_BORDER_X, this); |
664 | size.y = wxGetMetricOrDefault(wxSYS_BORDER_Y, this); | |
333d7052 VZ |
665 | break; |
666 | ||
667 | case wxBORDER_SUNKEN: | |
668 | case wxBORDER_RAISED: | |
d45a01e0 PC |
669 | size.x = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X, this), |
670 | wxGetMetricOrDefault(wxSYS_BORDER_X, this)); | |
671 | size.y = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y, this), | |
672 | wxGetMetricOrDefault(wxSYS_BORDER_Y, this)); | |
333d7052 VZ |
673 | break; |
674 | ||
675 | case wxBORDER_DOUBLE: | |
d45a01e0 PC |
676 | size.x = wxGetMetricOrDefault(wxSYS_EDGE_X, this) + |
677 | wxGetMetricOrDefault(wxSYS_BORDER_X, this); | |
678 | size.y = wxGetMetricOrDefault(wxSYS_EDGE_Y, this) + | |
679 | wxGetMetricOrDefault(wxSYS_BORDER_Y, this); | |
333d7052 VZ |
680 | break; |
681 | ||
682 | default: | |
683 | wxFAIL_MSG(_T("Unknown border style.")); | |
684 | break; | |
685 | } | |
686 | ||
687 | // we have borders on both sides | |
688 | return size*2; | |
689 | } | |
9f884528 | 690 | |
170acdc9 | 691 | wxSize wxWindowBase::GetEffectiveMinSize() const |
400a9e41 | 692 | { |
9f884528 RD |
693 | // merge the best size with the min size, giving priority to the min size |
694 | wxSize min = GetMinSize(); | |
1b942d5f | 695 | |
9f884528 | 696 | if (min.x == wxDefaultCoord || min.y == wxDefaultCoord) |
400a9e41 | 697 | { |
9f884528 RD |
698 | wxSize best = GetBestSize(); |
699 | if (min.x == wxDefaultCoord) min.x = best.x; | |
700 | if (min.y == wxDefaultCoord) min.y = best.y; | |
17c48da8 | 701 | } |
1b942d5f | 702 | |
9f884528 RD |
703 | return min; |
704 | } | |
17c48da8 | 705 | |
26f7724c RR |
706 | wxSize wxWindowBase::GetBestSize() const |
707 | { | |
708 | if ((!m_windowSizer) && (m_bestSizeCache.IsFullySpecified())) | |
709 | return m_bestSizeCache; | |
1b942d5f | 710 | |
26f7724c RR |
711 | return DoGetBestSize(); |
712 | } | |
42cfa184 | 713 | |
e81c7155 | 714 | void wxWindowBase::SetMinSize(const wxSize& minSize) |
1b942d5f FM |
715 | { |
716 | m_minWidth = minSize.x; | |
717 | m_minHeight = minSize.y; | |
e81c7155 RR |
718 | } |
719 | ||
720 | void wxWindowBase::SetMaxSize(const wxSize& maxSize) | |
1b942d5f FM |
721 | { |
722 | m_maxWidth = maxSize.x; | |
e81c7155 RR |
723 | m_maxHeight = maxSize.y; |
724 | } | |
725 | ||
170acdc9 | 726 | void wxWindowBase::SetInitialSize(const wxSize& size) |
9f884528 RD |
727 | { |
728 | // Set the min size to the size passed in. This will usually either be | |
729 | // wxDefaultSize or the size passed to this window's ctor/Create function. | |
730 | SetMinSize(size); | |
731 | ||
732 | // Merge the size with the best size if needed | |
170acdc9 | 733 | wxSize best = GetEffectiveMinSize(); |
cab1a605 | 734 | |
9f884528 RD |
735 | // If the current size doesn't match then change it |
736 | if (GetSize() != best) | |
737 | SetSize(best); | |
400a9e41 VZ |
738 | } |
739 | ||
9f884528 | 740 | |
1e6feb95 VZ |
741 | // by default the origin is not shifted |
742 | wxPoint wxWindowBase::GetClientAreaOrigin() const | |
743 | { | |
c47addef | 744 | return wxPoint(0,0); |
1e6feb95 VZ |
745 | } |
746 | ||
301d7a0d VS |
747 | wxSize wxWindowBase::ClientToWindowSize(const wxSize& size) const |
748 | { | |
749 | const wxSize diff(GetSize() - GetClientSize()); | |
750 | ||
751 | return wxSize(size.x == -1 ? -1 : size.x + diff.x, | |
752 | size.y == -1 ? -1 : size.y + diff.y); | |
753 | } | |
754 | ||
755 | wxSize wxWindowBase::WindowToClientSize(const wxSize& size) const | |
756 | { | |
757 | const wxSize diff(GetSize() - GetClientSize()); | |
758 | ||
759 | return wxSize(size.x == -1 ? -1 : size.x - diff.x, | |
760 | size.y == -1 ? -1 : size.y - diff.y); | |
761 | } | |
762 | ||
69d90995 SC |
763 | void wxWindowBase::SetWindowVariant( wxWindowVariant variant ) |
764 | { | |
1b69c815 VZ |
765 | if ( m_windowVariant != variant ) |
766 | { | |
767 | m_windowVariant = variant; | |
69d90995 | 768 | |
1b69c815 VZ |
769 | DoSetWindowVariant(variant); |
770 | } | |
69d90995 SC |
771 | } |
772 | ||
773 | void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant ) | |
774 | { | |
1b69c815 VZ |
775 | // adjust the font height to correspond to our new variant (notice that |
776 | // we're only called if something really changed) | |
777 | wxFont font = GetFont(); | |
778 | int size = font.GetPointSize(); | |
69d90995 SC |
779 | switch ( variant ) |
780 | { | |
1b69c815 VZ |
781 | case wxWINDOW_VARIANT_NORMAL: |
782 | break; | |
783 | ||
784 | case wxWINDOW_VARIANT_SMALL: | |
785 | size *= 3; | |
786 | size /= 4; | |
787 | break; | |
788 | ||
789 | case wxWINDOW_VARIANT_MINI: | |
790 | size *= 2; | |
791 | size /= 3; | |
792 | break; | |
793 | ||
794 | case wxWINDOW_VARIANT_LARGE: | |
795 | size *= 5; | |
796 | size /= 4; | |
797 | break; | |
798 | ||
69d90995 SC |
799 | default: |
800 | wxFAIL_MSG(_T("unexpected window variant")); | |
1b69c815 | 801 | break; |
69d90995 | 802 | } |
1b69c815 VZ |
803 | |
804 | font.SetPointSize(size); | |
805 | SetFont(font); | |
69d90995 SC |
806 | } |
807 | ||
b21f4960 RR |
808 | void wxWindowBase::DoSetSizeHints( int minW, int minH, |
809 | int maxW, int maxH, | |
f36978ba | 810 | int WXUNUSED(incW), int WXUNUSED(incH) ) |
b21f4960 RR |
811 | { |
812 | wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) && | |
813 | (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH), | |
814 | _T("min width/height must be less than max width/height!") ); | |
815 | ||
816 | m_minWidth = minW; | |
817 | m_maxWidth = maxW; | |
818 | m_minHeight = minH; | |
819 | m_maxHeight = maxH; | |
820 | } | |
821 | ||
822 | ||
f944aec0 VS |
823 | #if WXWIN_COMPATIBILITY_2_8 |
824 | void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW), int WXUNUSED(minH), | |
825 | int WXUNUSED(maxW), int WXUNUSED(maxH)) | |
566d84a7 | 826 | { |
566d84a7 RL |
827 | } |
828 | ||
f944aec0 VS |
829 | void wxWindowBase::SetVirtualSizeHints(const wxSize& WXUNUSED(minsize), |
830 | const wxSize& WXUNUSED(maxsize)) | |
566d84a7 | 831 | { |
f944aec0 VS |
832 | } |
833 | #endif // WXWIN_COMPATIBILITY_2_8 | |
1e2a653b | 834 | |
f944aec0 VS |
835 | void wxWindowBase::DoSetVirtualSize( int x, int y ) |
836 | { | |
1e2a653b | 837 | m_virtualSize = wxSize(x, y); |
566d84a7 RL |
838 | } |
839 | ||
840 | wxSize wxWindowBase::DoGetVirtualSize() const | |
841 | { | |
143e2719 VZ |
842 | // we should use the entire client area so if it is greater than our |
843 | // virtual size, expand it to fit (otherwise if the window is big enough we | |
844 | // wouldn't be using parts of it) | |
c20ab85b | 845 | wxSize size = GetClientSize(); |
143e2719 | 846 | if ( m_virtualSize.x > size.x ) |
c20ab85b VZ |
847 | size.x = m_virtualSize.x; |
848 | ||
143e2719 | 849 | if ( m_virtualSize.y >= size.y ) |
c20ab85b VZ |
850 | size.y = m_virtualSize.y; |
851 | ||
852 | return size; | |
566d84a7 RL |
853 | } |
854 | ||
3c81c9aa VZ |
855 | void wxWindowBase::DoGetScreenPosition(int *x, int *y) const |
856 | { | |
857 | // screen position is the same as (0, 0) in client coords for non TLWs (and | |
858 | // TLWs override this method) | |
859 | if ( x ) | |
860 | *x = 0; | |
861 | if ( y ) | |
862 | *y = 0; | |
863 | ||
aa738eb8 | 864 | ClientToScreen(x, y); |
3c81c9aa VZ |
865 | } |
866 | ||
ecdc1183 | 867 | void wxWindowBase::SendSizeEvent(int flags) |
0dba08dd VZ |
868 | { |
869 | wxSizeEvent event(GetSize(), GetId()); | |
870 | event.SetEventObject(this); | |
ecdc1183 VZ |
871 | if ( flags & wxSEND_EVENT_POST ) |
872 | wxPostEvent(this, event); | |
873 | else | |
874 | HandleWindowEvent(event); | |
0dba08dd VZ |
875 | } |
876 | ||
ecdc1183 | 877 | void wxWindowBase::SendSizeEventToParent(int flags) |
0dba08dd VZ |
878 | { |
879 | wxWindow * const parent = GetParent(); | |
880 | if ( parent && !parent->IsBeingDeleted() ) | |
ecdc1183 | 881 | parent->SendSizeEvent(flags); |
0dba08dd VZ |
882 | } |
883 | ||
f03fc89f VZ |
884 | // ---------------------------------------------------------------------------- |
885 | // show/hide/enable/disable the window | |
886 | // ---------------------------------------------------------------------------- | |
887 | ||
888 | bool wxWindowBase::Show(bool show) | |
889 | { | |
890 | if ( show != m_isShown ) | |
891 | { | |
892 | m_isShown = show; | |
893 | ||
e11f4636 | 894 | return true; |
f03fc89f VZ |
895 | } |
896 | else | |
897 | { | |
e11f4636 | 898 | return false; |
f03fc89f VZ |
899 | } |
900 | } | |
901 | ||
47a8a4d5 | 902 | bool wxWindowBase::IsEnabled() const |
f03fc89f | 903 | { |
47a8a4d5 VZ |
904 | return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled()); |
905 | } | |
f03fc89f | 906 | |
47a8a4d5 VZ |
907 | void wxWindowBase::NotifyWindowOnEnableChange(bool enabled) |
908 | { | |
909 | #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT | |
910 | DoEnable(enabled); | |
911 | #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT) | |
912 | ||
913 | OnEnabled(enabled); | |
914 | ||
915 | // If we are top-level then the logic doesn't apply - otherwise | |
916 | // showing a modal dialog would result in total greying out (and ungreying | |
917 | // out later) of everything which would be really ugly | |
918 | if ( IsTopLevel() ) | |
919 | return; | |
920 | ||
921 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
922 | node; | |
923 | node = node->GetNext() ) | |
f03fc89f | 924 | { |
47a8a4d5 VZ |
925 | wxWindowBase * const child = node->GetData(); |
926 | if ( !child->IsTopLevel() && child->IsThisEnabled() ) | |
927 | child->NotifyWindowOnEnableChange(enabled); | |
928 | } | |
929 | } | |
930 | ||
931 | bool wxWindowBase::Enable(bool enable) | |
932 | { | |
933 | if ( enable == IsThisEnabled() ) | |
e11f4636 | 934 | return false; |
47a8a4d5 VZ |
935 | |
936 | m_isEnabled = enable; | |
937 | ||
938 | #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT | |
939 | DoEnable(enable); | |
940 | #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT) | |
941 | wxWindowBase * const parent = GetParent(); | |
942 | if( !IsTopLevel() && parent && !parent->IsEnabled() ) | |
943 | { | |
944 | return true; | |
f03fc89f | 945 | } |
47a8a4d5 VZ |
946 | #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT) |
947 | ||
948 | NotifyWindowOnEnableChange(enable); | |
949 | ||
950 | return true; | |
f03fc89f | 951 | } |
9c72cf76 | 952 | |
865a74c7 | 953 | bool wxWindowBase::IsShownOnScreen() const |
9c72cf76 | 954 | { |
8a6a997f VS |
955 | // A window is shown on screen if it itself is shown and so are all its |
956 | // parents. But if a window is toplevel one, then its always visible on | |
957 | // screen if IsShown() returns true, even if it has a hidden parent. | |
865a74c7 | 958 | return IsShown() && |
8a6a997f | 959 | (IsTopLevel() || GetParent() == NULL || GetParent()->IsShownOnScreen()); |
9c72cf76 VS |
960 | } |
961 | ||
34636400 VZ |
962 | // ---------------------------------------------------------------------------- |
963 | // RTTI | |
964 | // ---------------------------------------------------------------------------- | |
965 | ||
966 | bool wxWindowBase::IsTopLevel() const | |
967 | { | |
e11f4636 | 968 | return false; |
34636400 | 969 | } |
f03fc89f | 970 | |
1c8e5c51 VS |
971 | // ---------------------------------------------------------------------------- |
972 | // Freeze/Thaw | |
973 | // ---------------------------------------------------------------------------- | |
974 | ||
975 | void wxWindowBase::Freeze() | |
976 | { | |
977 | if ( !m_freezeCount++ ) | |
978 | { | |
979 | // physically freeze this window: | |
980 | DoFreeze(); | |
981 | ||
982 | // and recursively freeze all children: | |
983 | for ( wxWindowList::iterator i = GetChildren().begin(); | |
984 | i != GetChildren().end(); ++i ) | |
985 | { | |
986 | wxWindow *child = *i; | |
987 | if ( child->IsTopLevel() ) | |
988 | continue; | |
989 | ||
990 | child->Freeze(); | |
991 | } | |
992 | } | |
993 | } | |
994 | ||
995 | void wxWindowBase::Thaw() | |
996 | { | |
997 | wxASSERT_MSG( m_freezeCount, "Thaw() without matching Freeze()" ); | |
998 | ||
999 | if ( !--m_freezeCount ) | |
1000 | { | |
1001 | // recursively thaw all children: | |
1002 | for ( wxWindowList::iterator i = GetChildren().begin(); | |
1003 | i != GetChildren().end(); ++i ) | |
1004 | { | |
1005 | wxWindow *child = *i; | |
1006 | if ( child->IsTopLevel() ) | |
1007 | continue; | |
1008 | ||
1009 | child->Thaw(); | |
1010 | } | |
1011 | ||
1012 | // physically thaw this window: | |
1013 | DoThaw(); | |
1014 | } | |
1015 | } | |
1016 | ||
f03fc89f VZ |
1017 | // ---------------------------------------------------------------------------- |
1018 | // reparenting the window | |
1019 | // ---------------------------------------------------------------------------- | |
1020 | ||
1021 | void wxWindowBase::AddChild(wxWindowBase *child) | |
1022 | { | |
223d09f6 | 1023 | wxCHECK_RET( child, wxT("can't add a NULL child") ); |
f03fc89f | 1024 | |
f6bcfd97 BP |
1025 | // this should never happen and it will lead to a crash later if it does |
1026 | // because RemoveChild() will remove only one node from the children list | |
1027 | // and the other(s) one(s) will be left with dangling pointers in them | |
222ed1d6 | 1028 | wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") ); |
f6bcfd97 | 1029 | |
222ed1d6 | 1030 | GetChildren().Append((wxWindow*)child); |
f03fc89f | 1031 | child->SetParent(this); |
1c8e5c51 | 1032 | |
76be36e4 | 1033 | // adding a child while frozen will assert when thawed, so freeze it as if |
1c8e5c51 VS |
1034 | // it had been already present when we were frozen |
1035 | if ( IsFrozen() && !child->IsTopLevel() ) | |
1036 | child->Freeze(); | |
f03fc89f VZ |
1037 | } |
1038 | ||
1039 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
1040 | { | |
223d09f6 | 1041 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); |
f03fc89f | 1042 | |
1c8e5c51 VS |
1043 | // removing a child while frozen may result in permanently frozen window |
1044 | // if used e.g. from Reparent(), so thaw it | |
76be36e4 VZ |
1045 | // |
1046 | // NB: IsTopLevel() doesn't return true any more when a TLW child is being | |
1047 | // removed from its ~wxWindowBase, so check for IsBeingDeleted() too | |
1048 | if ( IsFrozen() && !child->IsBeingDeleted() && !child->IsTopLevel() ) | |
1c8e5c51 VS |
1049 | child->Thaw(); |
1050 | ||
222ed1d6 MB |
1051 | GetChildren().DeleteObject((wxWindow *)child); |
1052 | child->SetParent(NULL); | |
f03fc89f | 1053 | } |
439b3bf1 | 1054 | |
f03fc89f VZ |
1055 | bool wxWindowBase::Reparent(wxWindowBase *newParent) |
1056 | { | |
1057 | wxWindow *oldParent = GetParent(); | |
1058 | if ( newParent == oldParent ) | |
1059 | { | |
1060 | // nothing done | |
e11f4636 | 1061 | return false; |
f03fc89f VZ |
1062 | } |
1063 | ||
47a8a4d5 VZ |
1064 | const bool oldEnabledState = IsEnabled(); |
1065 | ||
f03fc89f VZ |
1066 | // unlink this window from the existing parent. |
1067 | if ( oldParent ) | |
1068 | { | |
1069 | oldParent->RemoveChild(this); | |
1070 | } | |
1071 | else | |
1072 | { | |
222ed1d6 | 1073 | wxTopLevelWindows.DeleteObject((wxWindow *)this); |
f03fc89f VZ |
1074 | } |
1075 | ||
1076 | // add it to the new one | |
1077 | if ( newParent ) | |
1078 | { | |
1079 | newParent->AddChild(this); | |
1080 | } | |
1081 | else | |
1082 | { | |
222ed1d6 | 1083 | wxTopLevelWindows.Append((wxWindow *)this); |
f03fc89f VZ |
1084 | } |
1085 | ||
47a8a4d5 VZ |
1086 | // We need to notify window (and its subwindows) if by changing the parent |
1087 | // we also change our enabled/disabled status. | |
1088 | const bool newEnabledState = IsEnabled(); | |
1089 | if ( newEnabledState != oldEnabledState ) | |
1090 | { | |
1091 | NotifyWindowOnEnableChange(newEnabledState); | |
1092 | } | |
1093 | ||
e11f4636 | 1094 | return true; |
f03fc89f VZ |
1095 | } |
1096 | ||
1097 | // ---------------------------------------------------------------------------- | |
1098 | // event handler stuff | |
1099 | // ---------------------------------------------------------------------------- | |
1100 | ||
7f853dd0 | 1101 | void wxWindowBase::SetEventHandler(wxEvtHandler *handler) |
f03fc89f | 1102 | { |
7f853dd0 FM |
1103 | wxCHECK_RET(handler != NULL, "SetEventHandler(NULL) called"); |
1104 | ||
1105 | m_eventHandler = handler; | |
1106 | } | |
1107 | ||
1108 | void wxWindowBase::SetNextHandler(wxEvtHandler *WXUNUSED(handler)) | |
1109 | { | |
1110 | // disable wxEvtHandler chain mechanism for wxWindows: | |
1111 | // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one | |
1112 | ||
1113 | wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain"); | |
1114 | } | |
1115 | void wxWindowBase::SetPreviousHandler(wxEvtHandler *WXUNUSED(handler)) | |
1116 | { | |
1117 | // we can't simply wxFAIL here as in SetNextHandler: in fact the last | |
1118 | // handler of our stack when is destroyed will be Unlink()ed and thus | |
1119 | // will call this function to update the pointer of this window... | |
1120 | ||
1121 | //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain"); | |
1122 | } | |
1123 | ||
1124 | void wxWindowBase::PushEventHandler(wxEvtHandler *handlerToPush) | |
1125 | { | |
1126 | wxCHECK_RET( handlerToPush != NULL, "PushEventHandler(NULL) called" ); | |
1127 | ||
1128 | // the new handler is going to be part of the wxWindow stack of event handlers: | |
1129 | // it can't be part also of an event handler double-linked chain: | |
1130 | wxASSERT_MSG(handlerToPush->IsUnlinked(), | |
1131 | "The handler being pushed in the wxWindow stack shouldn't be part of " | |
1132 | "a wxEvtHandler chain; call Unlink() on it first"); | |
1133 | ||
3a074ba8 | 1134 | wxEvtHandler *handlerOld = GetEventHandler(); |
7f853dd0 FM |
1135 | wxCHECK_RET( handlerOld, "an old event handler is NULL?" ); |
1136 | ||
1137 | // now use wxEvtHandler double-linked list to implement a stack: | |
1138 | handlerToPush->SetNextHandler(handlerOld); | |
3a074ba8 | 1139 | |
7f853dd0 FM |
1140 | if (handlerOld != this) |
1141 | handlerOld->SetPreviousHandler(handlerToPush); | |
3a074ba8 | 1142 | |
7f853dd0 | 1143 | SetEventHandler(handlerToPush); |
3a074ba8 | 1144 | |
4b6a582b | 1145 | #if wxDEBUG_LEVEL |
7f853dd0 FM |
1146 | // final checks of the operations done above: |
1147 | wxASSERT_MSG( handlerToPush->GetPreviousHandler() == NULL, | |
4b6a582b VZ |
1148 | "the first handler of the wxWindow stack should " |
1149 | "have no previous handlers set" ); | |
7f853dd0 | 1150 | wxASSERT_MSG( handlerToPush->GetNextHandler() != NULL, |
4b6a582b VZ |
1151 | "the first handler of the wxWindow stack should " |
1152 | "have non-NULL next handler" ); | |
7f853dd0 FM |
1153 | |
1154 | wxEvtHandler* pLast = handlerToPush; | |
4b6a582b | 1155 | while ( pLast && pLast != this ) |
7f853dd0 FM |
1156 | pLast = pLast->GetNextHandler(); |
1157 | wxASSERT_MSG( pLast->GetNextHandler() == NULL, | |
4b6a582b VZ |
1158 | "the last handler of the wxWindow stack should " |
1159 | "have this window as next handler" ); | |
1160 | #endif // wxDEBUG_LEVEL | |
f03fc89f VZ |
1161 | } |
1162 | ||
1163 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
1164 | { | |
7f853dd0 | 1165 | // we need to pop the wxWindow stack, i.e. we need to remove the first handler |
3a074ba8 | 1166 | |
7f853dd0 FM |
1167 | wxEvtHandler *firstHandler = GetEventHandler(); |
1168 | wxCHECK_MSG( firstHandler != NULL, NULL, "wxWindow cannot have a NULL event handler" ); | |
1169 | wxCHECK_MSG( firstHandler != this, NULL, "cannot pop the wxWindow itself" ); | |
1170 | wxCHECK_MSG( firstHandler->GetPreviousHandler() == NULL, NULL, | |
1171 | "the first handler of the wxWindow stack should have no previous handlers set" ); | |
3a074ba8 | 1172 | |
7f853dd0 FM |
1173 | wxEvtHandler *secondHandler = firstHandler->GetNextHandler(); |
1174 | wxCHECK_MSG( secondHandler != NULL, NULL, | |
1175 | "the first handler of the wxWindow stack should have non-NULL next handler" ); | |
1176 | ||
1177 | firstHandler->SetNextHandler(NULL); | |
1178 | secondHandler->SetPreviousHandler(NULL); | |
1179 | ||
1180 | // now firstHandler is completely unlinked; set secondHandler as the new window event handler | |
1181 | SetEventHandler(secondHandler); | |
1182 | ||
1183 | if ( deleteHandler ) | |
1184 | { | |
1185 | delete firstHandler; | |
1186 | firstHandler = NULL; | |
f03fc89f VZ |
1187 | } |
1188 | ||
7f853dd0 | 1189 | return firstHandler; |
f03fc89f VZ |
1190 | } |
1191 | ||
7f853dd0 | 1192 | bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handlerToRemove) |
2e36d5cf | 1193 | { |
7f853dd0 FM |
1194 | wxCHECK_MSG( handlerToRemove != NULL, false, "RemoveEventHandler(NULL) called" ); |
1195 | wxCHECK_MSG( handlerToRemove != this, false, "Cannot remove the window itself" ); | |
1196 | ||
1197 | if (handlerToRemove == GetEventHandler()) | |
1198 | { | |
1199 | // removing the first event handler is equivalent to "popping" the stack | |
1200 | PopEventHandler(false); | |
1201 | return true; | |
1202 | } | |
2e36d5cf | 1203 | |
7f853dd0 FM |
1204 | // NOTE: the wxWindow event handler list is always terminated with "this" handler |
1205 | wxEvtHandler *handlerCur = GetEventHandler()->GetNextHandler(); | |
1206 | while ( handlerCur != this ) | |
2e36d5cf VZ |
1207 | { |
1208 | wxEvtHandler *handlerNext = handlerCur->GetNextHandler(); | |
1209 | ||
7f853dd0 | 1210 | if ( handlerCur == handlerToRemove ) |
2e36d5cf | 1211 | { |
7f853dd0 | 1212 | handlerCur->Unlink(); |
2e36d5cf | 1213 | |
7f853dd0 FM |
1214 | wxASSERT_MSG( handlerCur != GetEventHandler(), |
1215 | "the case Remove == Pop should was already handled" ); | |
e11f4636 | 1216 | return true; |
2e36d5cf VZ |
1217 | } |
1218 | ||
2e36d5cf VZ |
1219 | handlerCur = handlerNext; |
1220 | } | |
1221 | ||
1222 | wxFAIL_MSG( _T("where has the event handler gone?") ); | |
1223 | ||
e11f4636 | 1224 | return false; |
2e36d5cf VZ |
1225 | } |
1226 | ||
937013e0 VS |
1227 | bool wxWindowBase::HandleWindowEvent(wxEvent& event) const |
1228 | { | |
7f853dd0 | 1229 | // SafelyProcessEvent() will handle exceptions nicely |
937013e0 VS |
1230 | return GetEventHandler()->SafelyProcessEvent(event); |
1231 | } | |
1232 | ||
f03fc89f | 1233 | // ---------------------------------------------------------------------------- |
1b69c815 | 1234 | // colours, fonts &c |
f03fc89f VZ |
1235 | // ---------------------------------------------------------------------------- |
1236 | ||
b8e7b673 VZ |
1237 | void wxWindowBase::InheritAttributes() |
1238 | { | |
8afef133 | 1239 | const wxWindowBase * const parent = GetParent(); |
b8e7b673 VZ |
1240 | if ( !parent ) |
1241 | return; | |
1242 | ||
1243 | // we only inherit attributes which had been explicitly set for the parent | |
1244 | // which ensures that this only happens if the user really wants it and | |
1245 | // not by default which wouldn't make any sense in modern GUIs where the | |
1246 | // controls don't all use the same fonts (nor colours) | |
f8ff87ed | 1247 | if ( parent->m_inheritFont && !m_hasFont ) |
b8e7b673 VZ |
1248 | SetFont(parent->GetFont()); |
1249 | ||
1250 | // in addition, there is a possibility to explicitly forbid inheriting | |
1251 | // colours at each class level by overriding ShouldInheritColours() | |
1252 | if ( ShouldInheritColours() ) | |
1253 | { | |
f8ff87ed | 1254 | if ( parent->m_inheritFgCol && !m_hasFgCol ) |
b8e7b673 VZ |
1255 | SetForegroundColour(parent->GetForegroundColour()); |
1256 | ||
eb96212b VZ |
1257 | // inheriting (solid) background colour is wrong as it totally breaks |
1258 | // any kind of themed backgrounds | |
1259 | // | |
1260 | // instead, the controls should use the same background as their parent | |
1261 | // (ideally by not drawing it at all) | |
1262 | #if 0 | |
f8ff87ed | 1263 | if ( parent->m_inheritBgCol && !m_hasBgCol ) |
b8e7b673 | 1264 | SetBackgroundColour(parent->GetBackgroundColour()); |
eb96212b | 1265 | #endif // 0 |
b8e7b673 VZ |
1266 | } |
1267 | } | |
1268 | ||
1b69c815 VZ |
1269 | /* static */ wxVisualAttributes |
1270 | wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
1271 | { | |
1272 | // it is important to return valid values for all attributes from here, | |
1273 | // GetXXX() below rely on this | |
1274 | wxVisualAttributes attrs; | |
1275 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
1276 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
1b69c815 | 1277 | |
0477a857 JS |
1278 | // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of |
1279 | // the usual background colour than wxSYS_COLOUR_BTNFACE. | |
1280 | // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background | |
1281 | // colour on other platforms. | |
1282 | ||
1283 | #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__)) | |
1284 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
1285 | #else | |
1286 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
1287 | #endif | |
1b69c815 VZ |
1288 | return attrs; |
1289 | } | |
1290 | ||
1291 | wxColour wxWindowBase::GetBackgroundColour() const | |
1292 | { | |
1117d56f | 1293 | if ( !m_backgroundColour.IsOk() ) |
1b69c815 VZ |
1294 | { |
1295 | wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") ); | |
1296 | ||
1297 | // get our default background colour | |
1298 | wxColour colBg = GetDefaultAttributes().colBg; | |
1299 | ||
1300 | // we must return some valid colour to avoid redoing this every time | |
1301 | // and also to avoid surprizing the applications written for older | |
77ffb593 | 1302 | // wxWidgets versions where GetBackgroundColour() always returned |
1b69c815 VZ |
1303 | // something -- so give them something even if it doesn't make sense |
1304 | // for this window (e.g. it has a themed background) | |
1305 | if ( !colBg.Ok() ) | |
1306 | colBg = GetClassDefaultAttributes().colBg; | |
1307 | ||
f604c658 | 1308 | return colBg; |
1b69c815 | 1309 | } |
f604c658 VS |
1310 | else |
1311 | return m_backgroundColour; | |
1b69c815 VZ |
1312 | } |
1313 | ||
1314 | wxColour wxWindowBase::GetForegroundColour() const | |
1315 | { | |
1316 | // logic is the same as above | |
1317 | if ( !m_hasFgCol && !m_foregroundColour.Ok() ) | |
1318 | { | |
1b69c815 VZ |
1319 | wxColour colFg = GetDefaultAttributes().colFg; |
1320 | ||
1117d56f | 1321 | if ( !colFg.IsOk() ) |
1b69c815 VZ |
1322 | colFg = GetClassDefaultAttributes().colFg; |
1323 | ||
f604c658 | 1324 | return colFg; |
1b69c815 | 1325 | } |
f604c658 VS |
1326 | else |
1327 | return m_foregroundColour; | |
1b69c815 VZ |
1328 | } |
1329 | ||
f03fc89f VZ |
1330 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) |
1331 | { | |
cab1a605 | 1332 | if ( colour == m_backgroundColour ) |
e11f4636 | 1333 | return false; |
f03fc89f | 1334 | |
1117d56f | 1335 | m_hasBgCol = colour.IsOk(); |
17bcd9a6 | 1336 | |
f8ff87ed | 1337 | m_inheritBgCol = m_hasBgCol; |
f03fc89f | 1338 | m_backgroundColour = colour; |
44dfb5ce | 1339 | SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() ); |
e11f4636 | 1340 | return true; |
f03fc89f VZ |
1341 | } |
1342 | ||
1343 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
1344 | { | |
44dfb5ce | 1345 | if (colour == m_foregroundColour ) |
e11f4636 | 1346 | return false; |
f03fc89f | 1347 | |
1117d56f | 1348 | m_hasFgCol = colour.IsOk(); |
f8ff87ed | 1349 | m_inheritFgCol = m_hasFgCol; |
f03fc89f | 1350 | m_foregroundColour = colour; |
44dfb5ce | 1351 | SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() ); |
e11f4636 | 1352 | return true; |
f03fc89f VZ |
1353 | } |
1354 | ||
1355 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
1356 | { | |
8a9c2246 VZ |
1357 | // setting an invalid cursor is ok, it means that we don't have any special |
1358 | // cursor | |
a3ab1c18 | 1359 | if ( m_cursor.IsSameAs(cursor) ) |
f03fc89f VZ |
1360 | { |
1361 | // no change | |
e11f4636 | 1362 | return false; |
f03fc89f VZ |
1363 | } |
1364 | ||
8a9c2246 | 1365 | m_cursor = cursor; |
f03fc89f | 1366 | |
e11f4636 | 1367 | return true; |
f03fc89f VZ |
1368 | } |
1369 | ||
f604c658 | 1370 | wxFont wxWindowBase::GetFont() const |
1b69c815 VZ |
1371 | { |
1372 | // logic is the same as in GetBackgroundColour() | |
1117d56f | 1373 | if ( !m_font.IsOk() ) |
1b69c815 VZ |
1374 | { |
1375 | wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") ); | |
1376 | ||
1377 | wxFont font = GetDefaultAttributes().font; | |
1117d56f | 1378 | if ( !font.IsOk() ) |
1b69c815 VZ |
1379 | font = GetClassDefaultAttributes().font; |
1380 | ||
f604c658 | 1381 | return font; |
1b69c815 | 1382 | } |
f604c658 VS |
1383 | else |
1384 | return m_font; | |
1b69c815 VZ |
1385 | } |
1386 | ||
f03fc89f VZ |
1387 | bool wxWindowBase::SetFont(const wxFont& font) |
1388 | { | |
1b69c815 | 1389 | if ( font == m_font ) |
f03fc89f VZ |
1390 | { |
1391 | // no change | |
e11f4636 | 1392 | return false; |
f03fc89f VZ |
1393 | } |
1394 | ||
1b69c815 | 1395 | m_font = font; |
1117d56f | 1396 | m_hasFont = font.IsOk(); |
f8ff87ed | 1397 | m_inheritFont = m_hasFont; |
23895080 | 1398 | |
583d7e55 VS |
1399 | InvalidateBestSize(); |
1400 | ||
e11f4636 | 1401 | return true; |
f03fc89f VZ |
1402 | } |
1403 | ||
b95edd47 VZ |
1404 | #if wxUSE_PALETTE |
1405 | ||
1406 | void wxWindowBase::SetPalette(const wxPalette& pal) | |
1407 | { | |
e11f4636 | 1408 | m_hasCustomPalette = true; |
b95edd47 VZ |
1409 | m_palette = pal; |
1410 | ||
1411 | // VZ: can anyone explain me what do we do here? | |
1412 | wxWindowDC d((wxWindow *) this); | |
1413 | d.SetPalette(pal); | |
1414 | } | |
1415 | ||
1416 | wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const | |
1417 | { | |
1418 | wxWindow *win = (wxWindow *)this; | |
1419 | while ( win && !win->HasCustomPalette() ) | |
1420 | { | |
1421 | win = win->GetParent(); | |
1422 | } | |
1423 | ||
1424 | return win; | |
1425 | } | |
1426 | ||
1427 | #endif // wxUSE_PALETTE | |
1428 | ||
789295bf VZ |
1429 | #if wxUSE_CARET |
1430 | void wxWindowBase::SetCaret(wxCaret *caret) | |
1431 | { | |
1432 | if ( m_caret ) | |
1433 | { | |
1434 | delete m_caret; | |
1435 | } | |
1436 | ||
1437 | m_caret = caret; | |
1438 | ||
1439 | if ( m_caret ) | |
1440 | { | |
1441 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
223d09f6 | 1442 | wxT("caret should be created associated to this window") ); |
789295bf VZ |
1443 | } |
1444 | } | |
1445 | #endif // wxUSE_CARET | |
1446 | ||
88ac883a | 1447 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
1448 | // ---------------------------------------------------------------------------- |
1449 | // validators | |
1450 | // ---------------------------------------------------------------------------- | |
1451 | ||
1452 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
1453 | { | |
1454 | if ( m_windowValidator ) | |
1455 | delete m_windowValidator; | |
1456 | ||
1457 | m_windowValidator = (wxValidator *)validator.Clone(); | |
1458 | ||
1459 | if ( m_windowValidator ) | |
1b69c815 | 1460 | m_windowValidator->SetWindow(this); |
f03fc89f | 1461 | } |
88ac883a | 1462 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1463 | |
1464 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 1465 | // update region stuff |
f03fc89f VZ |
1466 | // ---------------------------------------------------------------------------- |
1467 | ||
1e6feb95 VZ |
1468 | wxRect wxWindowBase::GetUpdateClientRect() const |
1469 | { | |
1470 | wxRegion rgnUpdate = GetUpdateRegion(); | |
1471 | rgnUpdate.Intersect(GetClientRect()); | |
1472 | wxRect rectUpdate = rgnUpdate.GetBox(); | |
1473 | wxPoint ptOrigin = GetClientAreaOrigin(); | |
1474 | rectUpdate.x -= ptOrigin.x; | |
1475 | rectUpdate.y -= ptOrigin.y; | |
1476 | ||
1477 | return rectUpdate; | |
1478 | } | |
1479 | ||
657b4fd4 | 1480 | bool wxWindowBase::DoIsExposed(int x, int y) const |
f03fc89f VZ |
1481 | { |
1482 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
1483 | } | |
1484 | ||
657b4fd4 | 1485 | bool wxWindowBase::DoIsExposed(int x, int y, int w, int h) const |
f03fc89f VZ |
1486 | { |
1487 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
1488 | } | |
1489 | ||
5da0803c VZ |
1490 | void wxWindowBase::ClearBackground() |
1491 | { | |
1492 | // wxGTK uses its own version, no need to add never used code | |
1493 | #ifndef __WXGTK__ | |
1494 | wxClientDC dc((wxWindow *)this); | |
cb129171 | 1495 | wxBrush brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID); |
5da0803c VZ |
1496 | dc.SetBackground(brush); |
1497 | dc.Clear(); | |
1498 | #endif // __WXGTK__ | |
1499 | } | |
1500 | ||
f03fc89f | 1501 | // ---------------------------------------------------------------------------- |
146ba0fe | 1502 | // find child window by id or name |
f03fc89f VZ |
1503 | // ---------------------------------------------------------------------------- |
1504 | ||
6b73af79 | 1505 | wxWindow *wxWindowBase::FindWindow(long id) const |
f03fc89f VZ |
1506 | { |
1507 | if ( id == m_windowId ) | |
1508 | return (wxWindow *)this; | |
1509 | ||
d3b9f782 | 1510 | wxWindowBase *res = NULL; |
222ed1d6 | 1511 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1512 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) |
1513 | { | |
1514 | wxWindowBase *child = node->GetData(); | |
1515 | res = child->FindWindow( id ); | |
1516 | } | |
1517 | ||
1518 | return (wxWindow *)res; | |
1519 | } | |
1520 | ||
6b73af79 | 1521 | wxWindow *wxWindowBase::FindWindow(const wxString& name) const |
f03fc89f VZ |
1522 | { |
1523 | if ( name == m_windowName ) | |
1524 | return (wxWindow *)this; | |
1525 | ||
d3b9f782 | 1526 | wxWindowBase *res = NULL; |
222ed1d6 | 1527 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1528 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) |
1529 | { | |
1530 | wxWindow *child = node->GetData(); | |
1531 | res = child->FindWindow(name); | |
1532 | } | |
1533 | ||
1534 | return (wxWindow *)res; | |
1535 | } | |
1536 | ||
146ba0fe VZ |
1537 | |
1538 | // find any window by id or name or label: If parent is non-NULL, look through | |
1539 | // children for a label or title matching the specified string. If NULL, look | |
1540 | // through all top-level windows. | |
1541 | // | |
1542 | // to avoid duplicating code we reuse the same helper function but with | |
1543 | // different comparators | |
1544 | ||
1545 | typedef bool (*wxFindWindowCmp)(const wxWindow *win, | |
1546 | const wxString& label, long id); | |
1547 | ||
1548 | static | |
1549 | bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label, | |
1550 | long WXUNUSED(id)) | |
1551 | { | |
1552 | return win->GetLabel() == label; | |
1553 | } | |
1554 | ||
1555 | static | |
1556 | bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label, | |
1557 | long WXUNUSED(id)) | |
1558 | { | |
1559 | return win->GetName() == label; | |
1560 | } | |
1561 | ||
1562 | static | |
1563 | bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label), | |
1564 | long id) | |
1565 | { | |
1566 | return win->GetId() == id; | |
1567 | } | |
1568 | ||
1569 | // recursive helper for the FindWindowByXXX() functions | |
1570 | static | |
1571 | wxWindow *wxFindWindowRecursively(const wxWindow *parent, | |
1572 | const wxString& label, | |
1573 | long id, | |
1574 | wxFindWindowCmp cmp) | |
1575 | { | |
1576 | if ( parent ) | |
1577 | { | |
1578 | // see if this is the one we're looking for | |
1579 | if ( (*cmp)(parent, label, id) ) | |
1580 | return (wxWindow *)parent; | |
1581 | ||
1582 | // It wasn't, so check all its children | |
222ed1d6 | 1583 | for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst(); |
146ba0fe VZ |
1584 | node; |
1585 | node = node->GetNext() ) | |
1586 | { | |
1587 | // recursively check each child | |
1588 | wxWindow *win = (wxWindow *)node->GetData(); | |
1589 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1590 | if (retwin) | |
1591 | return retwin; | |
1592 | } | |
1593 | } | |
1594 | ||
1595 | // Not found | |
1596 | return NULL; | |
1597 | } | |
1598 | ||
1599 | // helper for FindWindowByXXX() | |
1600 | static | |
1601 | wxWindow *wxFindWindowHelper(const wxWindow *parent, | |
1602 | const wxString& label, | |
1603 | long id, | |
1604 | wxFindWindowCmp cmp) | |
1605 | { | |
1606 | if ( parent ) | |
1607 | { | |
1608 | // just check parent and all its children | |
1609 | return wxFindWindowRecursively(parent, label, id, cmp); | |
1610 | } | |
1611 | ||
1612 | // start at very top of wx's windows | |
222ed1d6 | 1613 | for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); |
146ba0fe VZ |
1614 | node; |
1615 | node = node->GetNext() ) | |
1616 | { | |
1617 | // recursively check each window & its children | |
1618 | wxWindow *win = node->GetData(); | |
1619 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1620 | if (retwin) | |
1621 | return retwin; | |
1622 | } | |
1623 | ||
1624 | return NULL; | |
1625 | } | |
1626 | ||
1627 | /* static */ | |
1628 | wxWindow * | |
1629 | wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent) | |
1630 | { | |
1631 | return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels); | |
1632 | } | |
1633 | ||
1634 | /* static */ | |
1635 | wxWindow * | |
1636 | wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent) | |
1637 | { | |
1638 | wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames); | |
1639 | ||
1640 | if ( !win ) | |
1641 | { | |
1642 | // fall back to the label | |
1643 | win = FindWindowByLabel(title, parent); | |
1644 | } | |
1645 | ||
1646 | return win; | |
1647 | } | |
1648 | ||
1649 | /* static */ | |
1650 | wxWindow * | |
1651 | wxWindowBase::FindWindowById( long id, const wxWindow* parent ) | |
1652 | { | |
525d8583 | 1653 | return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds); |
146ba0fe VZ |
1654 | } |
1655 | ||
f03fc89f VZ |
1656 | // ---------------------------------------------------------------------------- |
1657 | // dialog oriented functions | |
1658 | // ---------------------------------------------------------------------------- | |
1659 | ||
34636400 | 1660 | void wxWindowBase::MakeModal(bool modal) |
f03fc89f | 1661 | { |
34636400 VZ |
1662 | // Disable all other windows |
1663 | if ( IsTopLevel() ) | |
1664 | { | |
222ed1d6 | 1665 | wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); |
34636400 VZ |
1666 | while (node) |
1667 | { | |
1668 | wxWindow *win = node->GetData(); | |
1669 | if (win != this) | |
1670 | win->Enable(!modal); | |
1671 | ||
1672 | node = node->GetNext(); | |
1673 | } | |
1674 | } | |
f03fc89f VZ |
1675 | } |
1676 | ||
1677 | bool wxWindowBase::Validate() | |
1678 | { | |
88ac883a | 1679 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1680 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1681 | ||
222ed1d6 | 1682 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1683 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1684 | { | |
1685 | wxWindowBase *child = node->GetData(); | |
1686 | wxValidator *validator = child->GetValidator(); | |
dcd6b914 | 1687 | if ( validator && !validator->Validate((wxWindow *)this) ) |
f03fc89f | 1688 | { |
e11f4636 | 1689 | return false; |
f03fc89f | 1690 | } |
d80cd92a VZ |
1691 | |
1692 | if ( recurse && !child->Validate() ) | |
1693 | { | |
e11f4636 | 1694 | return false; |
d80cd92a | 1695 | } |
f03fc89f | 1696 | } |
88ac883a | 1697 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1698 | |
e11f4636 | 1699 | return true; |
f03fc89f VZ |
1700 | } |
1701 | ||
1702 | bool wxWindowBase::TransferDataToWindow() | |
1703 | { | |
88ac883a | 1704 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1705 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1706 | ||
222ed1d6 | 1707 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1708 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1709 | { | |
1710 | wxWindowBase *child = node->GetData(); | |
1711 | wxValidator *validator = child->GetValidator(); | |
1712 | if ( validator && !validator->TransferToWindow() ) | |
1713 | { | |
d80cd92a | 1714 | wxLogWarning(_("Could not transfer data to window")); |
e30285ab | 1715 | #if wxUSE_LOG |
d80cd92a | 1716 | wxLog::FlushActive(); |
e30285ab | 1717 | #endif // wxUSE_LOG |
f03fc89f | 1718 | |
e11f4636 | 1719 | return false; |
f03fc89f | 1720 | } |
d80cd92a VZ |
1721 | |
1722 | if ( recurse ) | |
1723 | { | |
a58a12e9 | 1724 | if ( !child->TransferDataToWindow() ) |
d80cd92a VZ |
1725 | { |
1726 | // warning already given | |
e11f4636 | 1727 | return false; |
d80cd92a VZ |
1728 | } |
1729 | } | |
f03fc89f | 1730 | } |
88ac883a | 1731 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1732 | |
e11f4636 | 1733 | return true; |
f03fc89f VZ |
1734 | } |
1735 | ||
1736 | bool wxWindowBase::TransferDataFromWindow() | |
1737 | { | |
88ac883a | 1738 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1739 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1740 | ||
222ed1d6 | 1741 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1742 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1743 | { | |
1744 | wxWindow *child = node->GetData(); | |
d80cd92a VZ |
1745 | wxValidator *validator = child->GetValidator(); |
1746 | if ( validator && !validator->TransferFromWindow() ) | |
f03fc89f | 1747 | { |
d80cd92a VZ |
1748 | // nop warning here because the application is supposed to give |
1749 | // one itself - we don't know here what might have gone wrongly | |
1750 | ||
e11f4636 | 1751 | return false; |
f03fc89f | 1752 | } |
d80cd92a VZ |
1753 | |
1754 | if ( recurse ) | |
1755 | { | |
a58a12e9 | 1756 | if ( !child->TransferDataFromWindow() ) |
d80cd92a VZ |
1757 | { |
1758 | // warning already given | |
e11f4636 | 1759 | return false; |
d80cd92a VZ |
1760 | } |
1761 | } | |
f03fc89f | 1762 | } |
88ac883a | 1763 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1764 | |
e11f4636 | 1765 | return true; |
f03fc89f VZ |
1766 | } |
1767 | ||
1768 | void wxWindowBase::InitDialog() | |
1769 | { | |
1770 | wxInitDialogEvent event(GetId()); | |
1771 | event.SetEventObject( this ); | |
1772 | GetEventHandler()->ProcessEvent(event); | |
1773 | } | |
1774 | ||
1775 | // ---------------------------------------------------------------------------- | |
bd83cb56 VZ |
1776 | // context-sensitive help support |
1777 | // ---------------------------------------------------------------------------- | |
1778 | ||
1779 | #if wxUSE_HELP | |
1780 | ||
1781 | // associate this help text with this window | |
1782 | void wxWindowBase::SetHelpText(const wxString& text) | |
1783 | { | |
1784 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1785 | if ( helpProvider ) | |
1786 | { | |
1787 | helpProvider->AddHelp(this, text); | |
1788 | } | |
1789 | } | |
1790 | ||
520746ac | 1791 | #if WXWIN_COMPATIBILITY_2_8 |
bd83cb56 VZ |
1792 | // associate this help text with all windows with the same id as this |
1793 | // one | |
1794 | void wxWindowBase::SetHelpTextForId(const wxString& text) | |
1795 | { | |
1796 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1797 | if ( helpProvider ) | |
1798 | { | |
1799 | helpProvider->AddHelp(GetId(), text); | |
1800 | } | |
1801 | } | |
520746ac | 1802 | #endif // WXWIN_COMPATIBILITY_2_8 |
bd83cb56 VZ |
1803 | |
1804 | // get the help string associated with this window (may be empty) | |
dc6588e7 VZ |
1805 | // default implementation forwards calls to the help provider |
1806 | wxString | |
1807 | wxWindowBase::GetHelpTextAtPoint(const wxPoint & WXUNUSED(pt), | |
1808 | wxHelpEvent::Origin WXUNUSED(origin)) const | |
bd83cb56 VZ |
1809 | { |
1810 | wxString text; | |
1811 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1812 | if ( helpProvider ) | |
1813 | { | |
1814 | text = helpProvider->GetHelp(this); | |
1815 | } | |
1816 | ||
1817 | return text; | |
1818 | } | |
1819 | ||
1820 | // show help for this window | |
1821 | void wxWindowBase::OnHelp(wxHelpEvent& event) | |
1822 | { | |
1823 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1824 | if ( helpProvider ) | |
1825 | { | |
95d3881f VZ |
1826 | wxPoint pos = event.GetPosition(); |
1827 | const wxHelpEvent::Origin origin = event.GetOrigin(); | |
1828 | if ( origin == wxHelpEvent::Origin_Keyboard ) | |
1829 | { | |
1830 | // if the help event was generated from keyboard it shouldn't | |
1831 | // appear at the mouse position (which is still the only position | |
1832 | // associated with help event) if the mouse is far away, although | |
1833 | // we still do use the mouse position if it's over the window | |
1834 | // because we suppose the user looks approximately at the mouse | |
1835 | // already and so it would be more convenient than showing tooltip | |
1836 | // at some arbitrary position which can be quite far from it | |
1837 | const wxRect rectClient = GetClientRect(); | |
1838 | if ( !rectClient.Contains(ScreenToClient(pos)) ) | |
1839 | { | |
1840 | // position help slightly under and to the right of this window | |
1841 | pos = ClientToScreen(wxPoint( | |
1842 | 2*GetCharWidth(), | |
1843 | rectClient.height + GetCharHeight() | |
1844 | )); | |
1845 | } | |
1846 | } | |
1847 | ||
1848 | if ( helpProvider->ShowHelpAtPoint(this, pos, origin) ) | |
bd83cb56 VZ |
1849 | { |
1850 | // skip the event.Skip() below | |
1851 | return; | |
1852 | } | |
1853 | } | |
1854 | ||
1855 | event.Skip(); | |
1856 | } | |
1857 | ||
1858 | #endif // wxUSE_HELP | |
1859 | ||
1860 | // ---------------------------------------------------------------------------- | |
602a2e02 | 1861 | // tooltips |
f03fc89f VZ |
1862 | // ---------------------------------------------------------------------------- |
1863 | ||
1864 | #if wxUSE_TOOLTIPS | |
1865 | ||
1866 | void wxWindowBase::SetToolTip( const wxString &tip ) | |
1867 | { | |
1868 | // don't create the new tooltip if we already have one | |
1869 | if ( m_tooltip ) | |
1870 | { | |
1871 | m_tooltip->SetTip( tip ); | |
1872 | } | |
1873 | else | |
1874 | { | |
1875 | SetToolTip( new wxToolTip( tip ) ); | |
1876 | } | |
1877 | ||
1878 | // setting empty tooltip text does not remove the tooltip any more - use | |
d3b9f782 | 1879 | // SetToolTip(NULL) for this |
f03fc89f VZ |
1880 | } |
1881 | ||
1882 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
1883 | { | |
0cb57187 VZ |
1884 | if ( m_tooltip != tooltip ) |
1885 | { | |
1886 | if ( m_tooltip ) | |
1887 | delete m_tooltip; | |
f03fc89f | 1888 | |
0cb57187 VZ |
1889 | m_tooltip = tooltip; |
1890 | } | |
f03fc89f VZ |
1891 | } |
1892 | ||
1893 | #endif // wxUSE_TOOLTIPS | |
1894 | ||
1895 | // ---------------------------------------------------------------------------- | |
1896 | // constraints and sizers | |
1897 | // ---------------------------------------------------------------------------- | |
1898 | ||
1899 | #if wxUSE_CONSTRAINTS | |
1900 | ||
1901 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
1902 | { | |
1903 | if ( m_constraints ) | |
1904 | { | |
1905 | UnsetConstraints(m_constraints); | |
1906 | delete m_constraints; | |
1907 | } | |
1908 | m_constraints = constraints; | |
1909 | if ( m_constraints ) | |
1910 | { | |
1911 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1912 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
1913 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
1914 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
1915 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
1916 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
1917 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
1918 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
1919 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
1920 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
1921 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
1922 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
1923 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
1924 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
1925 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
1926 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
1927 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
1928 | } | |
1929 | } | |
1930 | ||
1931 | // This removes any dangling pointers to this window in other windows' | |
1932 | // constraintsInvolvedIn lists. | |
1933 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
1934 | { | |
1935 | if ( c ) | |
1936 | { | |
1937 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1938 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
1939 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1940 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
1941 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
1942 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
1943 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
1944 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
1945 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
1946 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
1947 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
1948 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
1949 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
1950 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
1951 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
1952 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
1953 | } | |
1954 | } | |
1955 | ||
1956 | // Back-pointer to other windows we're involved with, so if we delete this | |
1957 | // window, we must delete any constraints we're involved with. | |
1958 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
1959 | { | |
1960 | if ( !m_constraintsInvolvedIn ) | |
1961 | m_constraintsInvolvedIn = new wxWindowList; | |
222ed1d6 MB |
1962 | if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) ) |
1963 | m_constraintsInvolvedIn->Append((wxWindow *)otherWin); | |
f03fc89f VZ |
1964 | } |
1965 | ||
1966 | // REMOVE back-pointer to other windows we're involved with. | |
1967 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
1968 | { | |
1969 | if ( m_constraintsInvolvedIn ) | |
222ed1d6 | 1970 | m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin); |
f03fc89f VZ |
1971 | } |
1972 | ||
1973 | // Reset any constraints that mention this window | |
1974 | void wxWindowBase::DeleteRelatedConstraints() | |
1975 | { | |
1976 | if ( m_constraintsInvolvedIn ) | |
1977 | { | |
222ed1d6 | 1978 | wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst(); |
f03fc89f VZ |
1979 | while (node) |
1980 | { | |
1981 | wxWindow *win = node->GetData(); | |
1982 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1983 | ||
1984 | // Reset any constraints involving this window | |
1985 | if ( constr ) | |
1986 | { | |
1987 | constr->left.ResetIfWin(this); | |
1988 | constr->top.ResetIfWin(this); | |
1989 | constr->right.ResetIfWin(this); | |
1990 | constr->bottom.ResetIfWin(this); | |
1991 | constr->width.ResetIfWin(this); | |
1992 | constr->height.ResetIfWin(this); | |
1993 | constr->centreX.ResetIfWin(this); | |
1994 | constr->centreY.ResetIfWin(this); | |
1995 | } | |
1996 | ||
222ed1d6 MB |
1997 | wxWindowList::compatibility_iterator next = node->GetNext(); |
1998 | m_constraintsInvolvedIn->Erase(node); | |
f03fc89f VZ |
1999 | node = next; |
2000 | } | |
2001 | ||
2002 | delete m_constraintsInvolvedIn; | |
d3b9f782 | 2003 | m_constraintsInvolvedIn = NULL; |
f03fc89f VZ |
2004 | } |
2005 | } | |
ec5bb70d VZ |
2006 | |
2007 | #endif // wxUSE_CONSTRAINTS | |
f03fc89f | 2008 | |
3aa5d532 | 2009 | void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld) |
f03fc89f | 2010 | { |
fb89cfc5 RD |
2011 | if ( sizer == m_windowSizer) |
2012 | return; | |
1b69c815 | 2013 | |
e8cfff87 VZ |
2014 | if ( m_windowSizer ) |
2015 | { | |
2016 | m_windowSizer->SetContainingWindow(NULL); | |
2017 | ||
2018 | if ( deleteOld ) | |
2019 | delete m_windowSizer; | |
2020 | } | |
3417c2cd | 2021 | |
f03fc89f | 2022 | m_windowSizer = sizer; |
e8cfff87 VZ |
2023 | if ( m_windowSizer ) |
2024 | { | |
2025 | m_windowSizer->SetContainingWindow((wxWindow *)this); | |
2026 | } | |
566d84a7 | 2027 | |
e8cfff87 | 2028 | SetAutoLayout(m_windowSizer != NULL); |
566d84a7 RL |
2029 | } |
2030 | ||
2031 | void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) | |
2032 | { | |
2033 | SetSizer( sizer, deleteOld ); | |
2034 | sizer->SetSizeHints( (wxWindow*) this ); | |
f03fc89f VZ |
2035 | } |
2036 | ||
400a9e41 | 2037 | |
1ebfafde RD |
2038 | void wxWindowBase::SetContainingSizer(wxSizer* sizer) |
2039 | { | |
2040 | // adding a window to a sizer twice is going to result in fatal and | |
2041 | // hard to debug problems later because when deleting the second | |
2042 | // associated wxSizerItem we're going to dereference a dangling | |
2043 | // pointer; so try to detect this as early as possible | |
2044 | wxASSERT_MSG( !sizer || m_containingSizer != sizer, | |
2045 | _T("Adding a window to the same sizer twice?") ); | |
1ebfafde | 2046 | |
400a9e41 | 2047 | m_containingSizer = sizer; |
1ebfafde | 2048 | } |
400a9e41 | 2049 | |
ec5bb70d VZ |
2050 | #if wxUSE_CONSTRAINTS |
2051 | ||
2052 | void wxWindowBase::SatisfyConstraints() | |
2053 | { | |
2054 | wxLayoutConstraints *constr = GetConstraints(); | |
2055 | bool wasOk = constr && constr->AreSatisfied(); | |
2056 | ||
2057 | ResetConstraints(); // Mark all constraints as unevaluated | |
2058 | ||
2059 | int noChanges = 1; | |
2060 | ||
2061 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
2062 | // own constraints will never be satisfied any more unless we do it | |
2063 | // here | |
2064 | if ( wasOk ) | |
2065 | { | |
2066 | while ( noChanges > 0 ) | |
2067 | { | |
2068 | LayoutPhase1(&noChanges); | |
2069 | } | |
2070 | } | |
2071 | ||
2072 | LayoutPhase2(&noChanges); | |
2073 | } | |
2074 | ||
2075 | #endif // wxUSE_CONSTRAINTS | |
2076 | ||
f03fc89f VZ |
2077 | bool wxWindowBase::Layout() |
2078 | { | |
3417c2cd | 2079 | // If there is a sizer, use it instead of the constraints |
f03fc89f VZ |
2080 | if ( GetSizer() ) |
2081 | { | |
8d7eaf91 | 2082 | int w = 0, h = 0; |
566d84a7 | 2083 | GetVirtualSize(&w, &h); |
3417c2cd | 2084 | GetSizer()->SetDimension( 0, 0, w, h ); |
f03fc89f | 2085 | } |
461e93f9 | 2086 | #if wxUSE_CONSTRAINTS |
f1df0927 | 2087 | else |
f03fc89f | 2088 | { |
ec5bb70d | 2089 | SatisfyConstraints(); // Find the right constraints values |
f1df0927 | 2090 | SetConstraintSizes(); // Recursively set the real window sizes |
f03fc89f | 2091 | } |
461e93f9 | 2092 | #endif |
5d4b632b | 2093 | |
e11f4636 | 2094 | return true; |
f03fc89f VZ |
2095 | } |
2096 | ||
6528a7f1 VZ |
2097 | void wxWindowBase::InternalOnSize(wxSizeEvent& event) |
2098 | { | |
2099 | if ( GetAutoLayout() ) | |
2100 | Layout(); | |
2101 | ||
2102 | event.Skip(); | |
2103 | } | |
2104 | ||
461e93f9 | 2105 | #if wxUSE_CONSTRAINTS |
ec5bb70d VZ |
2106 | |
2107 | // first phase of the constraints evaluation: set our own constraints | |
f03fc89f VZ |
2108 | bool wxWindowBase::LayoutPhase1(int *noChanges) |
2109 | { | |
2110 | wxLayoutConstraints *constr = GetConstraints(); | |
ec5bb70d VZ |
2111 | |
2112 | return !constr || constr->SatisfyConstraints(this, noChanges); | |
f03fc89f VZ |
2113 | } |
2114 | ||
ec5bb70d | 2115 | // second phase: set the constraints for our children |
f03fc89f VZ |
2116 | bool wxWindowBase::LayoutPhase2(int *noChanges) |
2117 | { | |
2118 | *noChanges = 0; | |
2119 | ||
2120 | // Layout children | |
2121 | DoPhase(1); | |
ec5bb70d VZ |
2122 | |
2123 | // Layout grand children | |
f03fc89f | 2124 | DoPhase(2); |
ec5bb70d | 2125 | |
e11f4636 | 2126 | return true; |
f03fc89f VZ |
2127 | } |
2128 | ||
2129 | // Do a phase of evaluating child constraints | |
2130 | bool wxWindowBase::DoPhase(int phase) | |
2131 | { | |
ec5bb70d VZ |
2132 | // the list containing the children for which the constraints are already |
2133 | // set correctly | |
f03fc89f | 2134 | wxWindowList succeeded; |
ec5bb70d VZ |
2135 | |
2136 | // the max number of iterations we loop before concluding that we can't set | |
2137 | // the constraints | |
2138 | static const int maxIterations = 500; | |
2139 | ||
2140 | for ( int noIterations = 0; noIterations < maxIterations; noIterations++ ) | |
f03fc89f | 2141 | { |
ec5bb70d VZ |
2142 | int noChanges = 0; |
2143 | ||
2144 | // loop over all children setting their constraints | |
222ed1d6 | 2145 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
ec5bb70d VZ |
2146 | node; |
2147 | node = node->GetNext() ) | |
f03fc89f VZ |
2148 | { |
2149 | wxWindow *child = node->GetData(); | |
ec5bb70d | 2150 | if ( child->IsTopLevel() ) |
f03fc89f | 2151 | { |
ec5bb70d VZ |
2152 | // top level children are not inside our client area |
2153 | continue; | |
2154 | } | |
2155 | ||
2156 | if ( !child->GetConstraints() || succeeded.Find(child) ) | |
2157 | { | |
2158 | // this one is either already ok or nothing we can do about it | |
2159 | continue; | |
2160 | } | |
2161 | ||
2162 | int tempNoChanges = 0; | |
2163 | bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges) | |
2164 | : child->LayoutPhase2(&tempNoChanges); | |
2165 | noChanges += tempNoChanges; | |
2166 | ||
2167 | if ( success ) | |
2168 | { | |
2169 | succeeded.Append(child); | |
f03fc89f | 2170 | } |
f03fc89f VZ |
2171 | } |
2172 | ||
ec5bb70d VZ |
2173 | if ( !noChanges ) |
2174 | { | |
2175 | // constraints are set | |
2176 | break; | |
2177 | } | |
f03fc89f VZ |
2178 | } |
2179 | ||
e11f4636 | 2180 | return true; |
f03fc89f VZ |
2181 | } |
2182 | ||
2183 | void wxWindowBase::ResetConstraints() | |
2184 | { | |
2185 | wxLayoutConstraints *constr = GetConstraints(); | |
2186 | if ( constr ) | |
2187 | { | |
e11f4636 DS |
2188 | constr->left.SetDone(false); |
2189 | constr->top.SetDone(false); | |
2190 | constr->right.SetDone(false); | |
2191 | constr->bottom.SetDone(false); | |
2192 | constr->width.SetDone(false); | |
2193 | constr->height.SetDone(false); | |
2194 | constr->centreX.SetDone(false); | |
2195 | constr->centreY.SetDone(false); | |
f03fc89f | 2196 | } |
f1df0927 | 2197 | |
222ed1d6 | 2198 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
2199 | while (node) |
2200 | { | |
2201 | wxWindow *win = node->GetData(); | |
34636400 | 2202 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
2203 | win->ResetConstraints(); |
2204 | node = node->GetNext(); | |
2205 | } | |
2206 | } | |
2207 | ||
2208 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
2209 | // and setting the real values. | |
2210 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
2211 | { | |
2212 | wxLayoutConstraints *constr = GetConstraints(); | |
4b7f2165 | 2213 | if ( constr && constr->AreSatisfied() ) |
f03fc89f VZ |
2214 | { |
2215 | int x = constr->left.GetValue(); | |
2216 | int y = constr->top.GetValue(); | |
2217 | int w = constr->width.GetValue(); | |
2218 | int h = constr->height.GetValue(); | |
2219 | ||
f03fc89f | 2220 | if ( (constr->width.GetRelationship() != wxAsIs ) || |
3417c2cd | 2221 | (constr->height.GetRelationship() != wxAsIs) ) |
f03fc89f | 2222 | { |
3417c2cd | 2223 | SetSize(x, y, w, h); |
f03fc89f VZ |
2224 | } |
2225 | else | |
2226 | { | |
3417c2cd RR |
2227 | // If we don't want to resize this window, just move it... |
2228 | Move(x, y); | |
f03fc89f VZ |
2229 | } |
2230 | } | |
2231 | else if ( constr ) | |
2232 | { | |
4b7f2165 | 2233 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), |
f1df0927 | 2234 | GetClassInfo()->GetClassName(), |
4b7f2165 | 2235 | GetName().c_str()); |
f03fc89f VZ |
2236 | } |
2237 | ||
2238 | if ( recurse ) | |
2239 | { | |
222ed1d6 | 2240 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
2241 | while (node) |
2242 | { | |
2243 | wxWindow *win = node->GetData(); | |
e2f9212c | 2244 | if ( !win->IsTopLevel() && win->GetConstraints() ) |
f03fc89f VZ |
2245 | win->SetConstraintSizes(); |
2246 | node = node->GetNext(); | |
2247 | } | |
2248 | } | |
2249 | } | |
2250 | ||
f03fc89f VZ |
2251 | // Only set the size/position of the constraint (if any) |
2252 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
2253 | { | |
2254 | wxLayoutConstraints *constr = GetConstraints(); | |
2255 | if ( constr ) | |
2256 | { | |
422d0ff0 | 2257 | if ( x != wxDefaultCoord ) |
f03fc89f VZ |
2258 | { |
2259 | constr->left.SetValue(x); | |
e11f4636 | 2260 | constr->left.SetDone(true); |
f03fc89f | 2261 | } |
422d0ff0 | 2262 | if ( y != wxDefaultCoord ) |
f03fc89f VZ |
2263 | { |
2264 | constr->top.SetValue(y); | |
e11f4636 | 2265 | constr->top.SetDone(true); |
f03fc89f | 2266 | } |
422d0ff0 | 2267 | if ( w != wxDefaultCoord ) |
f03fc89f VZ |
2268 | { |
2269 | constr->width.SetValue(w); | |
e11f4636 | 2270 | constr->width.SetDone(true); |
f03fc89f | 2271 | } |
422d0ff0 | 2272 | if ( h != wxDefaultCoord ) |
f03fc89f VZ |
2273 | { |
2274 | constr->height.SetValue(h); | |
e11f4636 | 2275 | constr->height.SetDone(true); |
f03fc89f VZ |
2276 | } |
2277 | } | |
2278 | } | |
2279 | ||
2280 | void wxWindowBase::MoveConstraint(int x, int y) | |
2281 | { | |
2282 | wxLayoutConstraints *constr = GetConstraints(); | |
2283 | if ( constr ) | |
2284 | { | |
422d0ff0 | 2285 | if ( x != wxDefaultCoord ) |
f03fc89f VZ |
2286 | { |
2287 | constr->left.SetValue(x); | |
e11f4636 | 2288 | constr->left.SetDone(true); |
f03fc89f | 2289 | } |
422d0ff0 | 2290 | if ( y != wxDefaultCoord ) |
f03fc89f VZ |
2291 | { |
2292 | constr->top.SetValue(y); | |
e11f4636 | 2293 | constr->top.SetDone(true); |
f03fc89f VZ |
2294 | } |
2295 | } | |
2296 | } | |
2297 | ||
2298 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
2299 | { | |
2300 | wxLayoutConstraints *constr = GetConstraints(); | |
2301 | if ( constr ) | |
2302 | { | |
2303 | *w = constr->width.GetValue(); | |
2304 | *h = constr->height.GetValue(); | |
2305 | } | |
2306 | else | |
2307 | GetSize(w, h); | |
2308 | } | |
2309 | ||
2310 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
2311 | { | |
2312 | wxLayoutConstraints *constr = GetConstraints(); | |
2313 | if ( constr ) | |
2314 | { | |
2315 | *w = constr->width.GetValue(); | |
2316 | *h = constr->height.GetValue(); | |
2317 | } | |
2318 | else | |
2319 | GetClientSize(w, h); | |
2320 | } | |
2321 | ||
461e93f9 JS |
2322 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const |
2323 | { | |
2324 | wxLayoutConstraints *constr = GetConstraints(); | |
2325 | if ( constr ) | |
2326 | { | |
2327 | *x = constr->left.GetValue(); | |
2328 | *y = constr->top.GetValue(); | |
2329 | } | |
2330 | else | |
2331 | GetPosition(x, y); | |
2332 | } | |
2333 | ||
2334 | #endif // wxUSE_CONSTRAINTS | |
2335 | ||
20a1eea1 | 2336 | void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const |
a200c35e VS |
2337 | { |
2338 | // don't do it for the dialogs/frames - they float independently of their | |
2339 | // parent | |
2340 | if ( !IsTopLevel() ) | |
2341 | { | |
2342 | wxWindow *parent = GetParent(); | |
2343 | if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent ) | |
2344 | { | |
2345 | wxPoint pt(parent->GetClientAreaOrigin()); | |
2346 | x += pt.x; | |
2347 | y += pt.y; | |
2348 | } | |
2349 | } | |
2350 | } | |
2351 | ||
f03fc89f | 2352 | // ---------------------------------------------------------------------------- |
602a2e02 | 2353 | // Update UI processing |
f03fc89f | 2354 | // ---------------------------------------------------------------------------- |
7ec1983b | 2355 | |
e39af974 | 2356 | void wxWindowBase::UpdateWindowUI(long flags) |
7ec1983b | 2357 | { |
26bf1ce0 | 2358 | wxUpdateUIEvent event(GetId()); |
687706f5 | 2359 | event.SetEventObject(this); |
26bf1ce0 VZ |
2360 | |
2361 | if ( GetEventHandler()->ProcessEvent(event) ) | |
7ec1983b | 2362 | { |
e39af974 JS |
2363 | DoUpdateWindowUI(event); |
2364 | } | |
7ec1983b | 2365 | |
e39af974 JS |
2366 | if (flags & wxUPDATE_UI_RECURSE) |
2367 | { | |
222ed1d6 | 2368 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
e39af974 | 2369 | while (node) |
f03fc89f | 2370 | { |
e39af974 JS |
2371 | wxWindow* child = (wxWindow*) node->GetData(); |
2372 | child->UpdateWindowUI(flags); | |
2373 | node = node->GetNext(); | |
26bf1ce0 | 2374 | } |
e39af974 JS |
2375 | } |
2376 | } | |
f03fc89f | 2377 | |
e39af974 | 2378 | // do the window-specific processing after processing the update event |
e39af974 JS |
2379 | void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event) |
2380 | { | |
2381 | if ( event.GetSetEnabled() ) | |
2382 | Enable(event.GetEnabled()); | |
e11f4636 | 2383 | |
a3a4105d VZ |
2384 | if ( event.GetSetShown() ) |
2385 | Show(event.GetShown()); | |
e39af974 JS |
2386 | } |
2387 | ||
f03fc89f VZ |
2388 | // ---------------------------------------------------------------------------- |
2389 | // dialog units translations | |
2390 | // ---------------------------------------------------------------------------- | |
2391 | ||
2392 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) | |
fd71308f JS |
2393 | { |
2394 | int charWidth = GetCharWidth(); | |
2395 | int charHeight = GetCharHeight(); | |
cab1a605 WS |
2396 | wxPoint pt2 = wxDefaultPosition; |
2397 | if (pt.x != wxDefaultCoord) | |
1b69c815 | 2398 | pt2.x = (int) ((pt.x * 4) / charWidth); |
cab1a605 | 2399 | if (pt.y != wxDefaultCoord) |
1b69c815 | 2400 | pt2.y = (int) ((pt.y * 8) / charHeight); |
fd71308f JS |
2401 | |
2402 | return pt2; | |
2403 | } | |
2404 | ||
f03fc89f | 2405 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) |
fd71308f JS |
2406 | { |
2407 | int charWidth = GetCharWidth(); | |
2408 | int charHeight = GetCharHeight(); | |
cab1a605 WS |
2409 | wxPoint pt2 = wxDefaultPosition; |
2410 | if (pt.x != wxDefaultCoord) | |
1b69c815 | 2411 | pt2.x = (int) ((pt.x * charWidth) / 4); |
cab1a605 | 2412 | if (pt.y != wxDefaultCoord) |
1b69c815 | 2413 | pt2.y = (int) ((pt.y * charHeight) / 8); |
fd71308f JS |
2414 | |
2415 | return pt2; | |
2416 | } | |
2417 | ||
f03fc89f VZ |
2418 | // ---------------------------------------------------------------------------- |
2419 | // event handlers | |
2420 | // ---------------------------------------------------------------------------- | |
2421 | ||
2422 | // propagate the colour change event to the subwindows | |
2423 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) | |
2424 | { | |
222ed1d6 | 2425 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
2426 | while ( node ) |
2427 | { | |
2428 | // Only propagate to non-top-level windows | |
2429 | wxWindow *win = node->GetData(); | |
2430 | if ( !win->IsTopLevel() ) | |
2431 | { | |
2432 | wxSysColourChangedEvent event2; | |
687706f5 | 2433 | event.SetEventObject(win); |
f03fc89f VZ |
2434 | win->GetEventHandler()->ProcessEvent(event2); |
2435 | } | |
2436 | ||
2437 | node = node->GetNext(); | |
2438 | } | |
9a8477e1 VS |
2439 | |
2440 | Refresh(); | |
f03fc89f VZ |
2441 | } |
2442 | ||
e39af974 JS |
2443 | // the default action is to populate dialog with data when it's created, |
2444 | // and nudge the UI into displaying itself correctly in case | |
2445 | // we've turned the wxUpdateUIEvents frequency down low. | |
f03fc89f VZ |
2446 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) |
2447 | { | |
2448 | TransferDataToWindow(); | |
e11f4636 | 2449 | |
e39af974 JS |
2450 | // Update the UI at this point |
2451 | UpdateWindowUI(wxUPDATE_UI_RECURSE); | |
f03fc89f VZ |
2452 | } |
2453 | ||
00a77b7c VZ |
2454 | // ---------------------------------------------------------------------------- |
2455 | // menu-related functions | |
2456 | // ---------------------------------------------------------------------------- | |
2457 | ||
2458 | #if wxUSE_MENUS | |
2459 | ||
eeb0bee1 VZ |
2460 | bool wxWindowBase::PopupMenu(wxMenu *menu, int x, int y) |
2461 | { | |
2462 | wxCHECK_MSG( menu, false, "can't popup NULL menu" ); | |
2463 | ||
2464 | wxCurrentPopupMenu = menu; | |
2465 | const bool rc = DoPopupMenu(menu, x, y); | |
2466 | wxCurrentPopupMenu = NULL; | |
2467 | ||
2468 | return rc; | |
2469 | } | |
2470 | ||
00a77b7c VZ |
2471 | // this is used to pass the id of the selected item from the menu event handler |
2472 | // to the main function itself | |
2473 | // | |
2474 | // it's ok to use a global here as there can be at most one popup menu shown at | |
2475 | // any time | |
2476 | static int gs_popupMenuSelection = wxID_NONE; | |
2477 | ||
2478 | void wxWindowBase::InternalOnPopupMenu(wxCommandEvent& event) | |
2479 | { | |
2480 | // store the id in a global variable where we'll retrieve it from later | |
2481 | gs_popupMenuSelection = event.GetId(); | |
2482 | } | |
2483 | ||
565382de VZ |
2484 | void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent& WXUNUSED(event)) |
2485 | { | |
2486 | // nothing to do but do not skip it | |
2487 | } | |
2488 | ||
00a77b7c VZ |
2489 | int |
2490 | wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y) | |
2491 | { | |
2492 | gs_popupMenuSelection = wxID_NONE; | |
2493 | ||
2494 | Connect(wxEVT_COMMAND_MENU_SELECTED, | |
2495 | wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu), | |
2496 | NULL, | |
2497 | this); | |
2498 | ||
565382de VZ |
2499 | // it is common to construct the menu passed to this function dynamically |
2500 | // using some fixed range of ids which could clash with the ids used | |
2501 | // elsewhere in the program, which could result in some menu items being | |
2502 | // unintentionally disabled or otherwise modified by update UI handlers | |
2503 | // elsewhere in the program code and this is difficult to avoid in the | |
2504 | // program itself, so instead we just temporarily suspend UI updating while | |
2505 | // this menu is shown | |
2506 | Connect(wxEVT_UPDATE_UI, | |
2507 | wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate), | |
2508 | NULL, | |
2509 | this); | |
2510 | ||
00a77b7c VZ |
2511 | PopupMenu(&menu, x, y); |
2512 | ||
565382de VZ |
2513 | Disconnect(wxEVT_UPDATE_UI, |
2514 | wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate), | |
2515 | NULL, | |
2516 | this); | |
00a77b7c VZ |
2517 | Disconnect(wxEVT_COMMAND_MENU_SELECTED, |
2518 | wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu), | |
2519 | NULL, | |
2520 | this); | |
2521 | ||
2522 | return gs_popupMenuSelection; | |
2523 | } | |
2524 | ||
2525 | #endif // wxUSE_MENUS | |
2526 | ||
dddd1f21 VZ |
2527 | // methods for drawing the sizers in a visible way |
2528 | #ifdef __WXDEBUG__ | |
2529 | ||
2530 | static void DrawSizers(wxWindowBase *win); | |
2531 | ||
a721fd82 | 2532 | static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill, const wxPen* pen) |
dddd1f21 VZ |
2533 | { |
2534 | wxClientDC dc((wxWindow *)win); | |
a721fd82 | 2535 | dc.SetPen(*pen); |
1b942d5f | 2536 | dc.SetBrush(fill ? wxBrush(pen->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH) : |
a721fd82 | 2537 | *wxTRANSPARENT_BRUSH); |
dddd1f21 VZ |
2538 | dc.DrawRectangle(rect.Deflate(1, 1)); |
2539 | } | |
2540 | ||
2541 | static void DrawSizer(wxWindowBase *win, wxSizer *sizer) | |
2542 | { | |
2543 | const wxSizerItemList& items = sizer->GetChildren(); | |
2544 | for ( wxSizerItemList::const_iterator i = items.begin(), | |
2545 | end = items.end(); | |
2546 | i != end; | |
2547 | ++i ) | |
2548 | { | |
2549 | wxSizerItem *item = *i; | |
2550 | if ( item->IsSizer() ) | |
2551 | { | |
a721fd82 | 2552 | DrawBorder(win, item->GetRect().Deflate(2), false, wxRED_PEN); |
dddd1f21 VZ |
2553 | DrawSizer(win, item->GetSizer()); |
2554 | } | |
2555 | else if ( item->IsSpacer() ) | |
2556 | { | |
a721fd82 | 2557 | DrawBorder(win, item->GetRect().Deflate(2), true, wxBLUE_PEN); |
dddd1f21 VZ |
2558 | } |
2559 | else if ( item->IsWindow() ) | |
2560 | { | |
2561 | DrawSizers(item->GetWindow()); | |
2562 | } | |
1b942d5f FM |
2563 | else |
2564 | wxFAIL_MSG("inconsistent wxSizerItem status!"); | |
dddd1f21 VZ |
2565 | } |
2566 | } | |
2567 | ||
2568 | static void DrawSizers(wxWindowBase *win) | |
2569 | { | |
a721fd82 FM |
2570 | DrawBorder(win, win->GetClientSize(), false, wxGREEN_PEN); |
2571 | ||
dddd1f21 VZ |
2572 | wxSizer *sizer = win->GetSizer(); |
2573 | if ( sizer ) | |
2574 | { | |
dddd1f21 VZ |
2575 | DrawSizer(win, sizer); |
2576 | } | |
2577 | else // no sizer, still recurse into the children | |
2578 | { | |
2579 | const wxWindowList& children = win->GetChildren(); | |
2580 | for ( wxWindowList::const_iterator i = children.begin(), | |
2581 | end = children.end(); | |
2582 | i != end; | |
2583 | ++i ) | |
2584 | { | |
2585 | DrawSizers(*i); | |
2586 | } | |
1b942d5f FM |
2587 | |
2588 | // show all kind of sizes of this window; see the "window sizing" topic | |
2589 | // overview for more info about the various differences: | |
2590 | wxSize fullSz = win->GetSize(); | |
2591 | wxSize clientSz = win->GetClientSize(); | |
2592 | wxSize bestSz = win->GetBestSize(); | |
2593 | wxSize minSz = win->GetMinSize(); | |
2594 | wxSize maxSz = win->GetMaxSize(); | |
2595 | wxSize virtualSz = win->GetVirtualSize(); | |
2596 | ||
2597 | wxMessageOutputDebug dbgout; | |
2598 | dbgout.Printf( | |
2599 | "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n", | |
79cb759d | 2600 | win->GetName(), |
1b942d5f FM |
2601 | fullSz.x, fullSz.y, |
2602 | clientSz.x, clientSz.y, | |
2603 | bestSz.x, bestSz.y, | |
2604 | minSz.x, minSz.y, | |
2605 | maxSz.x, maxSz.y, | |
2606 | virtualSz.x, virtualSz.y); | |
dddd1f21 VZ |
2607 | } |
2608 | } | |
2609 | ||
2610 | #endif // __WXDEBUG__ | |
2611 | ||
2612 | // process special middle clicks | |
a02dc3e3 VZ |
2613 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) |
2614 | { | |
2615 | if ( event.ControlDown() && event.AltDown() ) | |
2616 | { | |
dddd1f21 VZ |
2617 | #ifdef __WXDEBUG__ |
2618 | // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds | |
2619 | if ( event.ShiftDown() ) | |
2620 | { | |
2621 | DrawSizers(this); | |
2622 | return; | |
2623 | } | |
2624 | #endif // __WXDEBUG__ | |
8cf304f8 | 2625 | ::wxInfoMessageBox((wxWindow*)this); |
a02dc3e3 VZ |
2626 | } |
2627 | else | |
2628 | { | |
2629 | event.Skip(); | |
2630 | } | |
2631 | } | |
2632 | ||
ed5317e5 JS |
2633 | // ---------------------------------------------------------------------------- |
2634 | // accessibility | |
2635 | // ---------------------------------------------------------------------------- | |
2636 | ||
2637 | #if wxUSE_ACCESSIBILITY | |
2638 | void wxWindowBase::SetAccessible(wxAccessible* accessible) | |
2639 | { | |
2aefc528 | 2640 | if (m_accessible && (accessible != m_accessible)) |
ed5317e5 JS |
2641 | delete m_accessible; |
2642 | m_accessible = accessible; | |
2643 | if (m_accessible) | |
2644 | m_accessible->SetWindow((wxWindow*) this); | |
2645 | } | |
2646 | ||
2647 | // Returns the accessible object, creating if necessary. | |
2648 | wxAccessible* wxWindowBase::GetOrCreateAccessible() | |
2649 | { | |
2650 | if (!m_accessible) | |
2651 | m_accessible = CreateAccessible(); | |
2652 | return m_accessible; | |
2653 | } | |
2654 | ||
2655 | // Override to create a specific accessible object. | |
2656 | wxAccessible* wxWindowBase::CreateAccessible() | |
2657 | { | |
2658 | return new wxWindowAccessible((wxWindow*) this); | |
2659 | } | |
2660 | ||
2661 | #endif | |
2662 | ||
f03fc89f VZ |
2663 | // ---------------------------------------------------------------------------- |
2664 | // list classes implementation | |
2665 | // ---------------------------------------------------------------------------- | |
2666 | ||
ed1288c1 VZ |
2667 | #if wxUSE_STL |
2668 | ||
7ec69821 | 2669 | #include "wx/listimpl.cpp" |
412e0d47 | 2670 | WX_DEFINE_LIST(wxWindowList) |
ed1288c1 | 2671 | |
602a2e02 | 2672 | #else // !wxUSE_STL |
ed1288c1 | 2673 | |
f03fc89f VZ |
2674 | void wxWindowListNode::DeleteData() |
2675 | { | |
2676 | delete (wxWindow *)GetData(); | |
2677 | } | |
ed1288c1 | 2678 | |
602a2e02 | 2679 | #endif // wxUSE_STL/!wxUSE_STL |
f03fc89f | 2680 | |
1e6feb95 VZ |
2681 | // ---------------------------------------------------------------------------- |
2682 | // borders | |
2683 | // ---------------------------------------------------------------------------- | |
2684 | ||
aede4ebb | 2685 | wxBorder wxWindowBase::GetBorder(long flags) const |
1e6feb95 | 2686 | { |
aede4ebb | 2687 | wxBorder border = (wxBorder)(flags & wxBORDER_MASK); |
1e6feb95 VZ |
2688 | if ( border == wxBORDER_DEFAULT ) |
2689 | { | |
2690 | border = GetDefaultBorder(); | |
2691 | } | |
78cd9c69 JS |
2692 | else if ( border == wxBORDER_THEME ) |
2693 | { | |
2694 | border = GetDefaultBorderForControl(); | |
2695 | } | |
1e6feb95 VZ |
2696 | |
2697 | return border; | |
2698 | } | |
2699 | ||
2700 | wxBorder wxWindowBase::GetDefaultBorder() const | |
2701 | { | |
2702 | return wxBORDER_NONE; | |
2703 | } | |
2704 | ||
2705 | // ---------------------------------------------------------------------------- | |
2706 | // hit testing | |
2707 | // ---------------------------------------------------------------------------- | |
2708 | ||
2709 | wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const | |
2710 | { | |
2711 | // here we just check if the point is inside the window or not | |
2712 | ||
2713 | // check the top and left border first | |
2714 | bool outside = x < 0 || y < 0; | |
2715 | if ( !outside ) | |
2716 | { | |
2717 | // check the right and bottom borders too | |
2718 | wxSize size = GetSize(); | |
2719 | outside = x >= size.x || y >= size.y; | |
2720 | } | |
2721 | ||
2722 | return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE; | |
2723 | } | |
2724 | ||
94633ad9 VZ |
2725 | // ---------------------------------------------------------------------------- |
2726 | // mouse capture | |
2727 | // ---------------------------------------------------------------------------- | |
2728 | ||
2729 | struct WXDLLEXPORT wxWindowNext | |
2730 | { | |
2731 | wxWindow *win; | |
2732 | wxWindowNext *next; | |
786646f3 | 2733 | } *wxWindowBase::ms_winCaptureNext = NULL; |
63e819f2 VS |
2734 | wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL; |
2735 | bool wxWindowBase::ms_winCaptureChanging = false; | |
94633ad9 | 2736 | |
a83e1475 | 2737 | void wxWindowBase::CaptureMouse() |
94633ad9 | 2738 | { |
5c33522f | 2739 | wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), static_cast<void*>(this)); |
45e0dc94 | 2740 | |
63e819f2 VS |
2741 | wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive CaptureMouse call?") ); |
2742 | ||
2743 | ms_winCaptureChanging = true; | |
2744 | ||
94633ad9 VZ |
2745 | wxWindow *winOld = GetCapture(); |
2746 | if ( winOld ) | |
2747 | { | |
df2f507b | 2748 | ((wxWindowBase*) winOld)->DoReleaseMouse(); |
edd802c6 | 2749 | |
94633ad9 VZ |
2750 | // save it on stack |
2751 | wxWindowNext *item = new wxWindowNext; | |
2752 | item->win = winOld; | |
2753 | item->next = ms_winCaptureNext; | |
2754 | ms_winCaptureNext = item; | |
2755 | } | |
2756 | //else: no mouse capture to save | |
2757 | ||
2758 | DoCaptureMouse(); | |
63e819f2 VS |
2759 | ms_winCaptureCurrent = (wxWindow*)this; |
2760 | ||
2761 | ms_winCaptureChanging = false; | |
94633ad9 VZ |
2762 | } |
2763 | ||
a83e1475 | 2764 | void wxWindowBase::ReleaseMouse() |
94633ad9 | 2765 | { |
5c33522f | 2766 | wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), static_cast<void*>(this)); |
349d1942 | 2767 | |
63e819f2 VS |
2768 | wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive ReleaseMouse call?") ); |
2769 | ||
31b9d29f VS |
2770 | wxASSERT_MSG( GetCapture() == this, |
2771 | "attempt to release mouse, but this window hasn't captured it" ); | |
2772 | wxASSERT_MSG( ms_winCaptureCurrent == this, | |
2773 | "attempt to release mouse, but this window hasn't captured it" ); | |
a7b09001 | 2774 | |
63e819f2 VS |
2775 | ms_winCaptureChanging = true; |
2776 | ||
94633ad9 | 2777 | DoReleaseMouse(); |
63e819f2 | 2778 | ms_winCaptureCurrent = NULL; |
94633ad9 VZ |
2779 | |
2780 | if ( ms_winCaptureNext ) | |
2781 | { | |
44f8caa7 | 2782 | ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse(); |
63e819f2 | 2783 | ms_winCaptureCurrent = ms_winCaptureNext->win; |
edd802c6 | 2784 | |
94633ad9 VZ |
2785 | wxWindowNext *item = ms_winCaptureNext; |
2786 | ms_winCaptureNext = item->next; | |
2787 | delete item; | |
2788 | } | |
2789 | //else: stack is empty, no previous capture | |
2790 | ||
63e819f2 VS |
2791 | ms_winCaptureChanging = false; |
2792 | ||
94633ad9 | 2793 | wxLogTrace(_T("mousecapture"), |
e11f4636 | 2794 | (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"), |
5c33522f | 2795 | static_cast<void*>(GetCapture())); |
94633ad9 VZ |
2796 | } |
2797 | ||
63e819f2 VS |
2798 | static void DoNotifyWindowAboutCaptureLost(wxWindow *win) |
2799 | { | |
2800 | wxMouseCaptureLostEvent event(win->GetId()); | |
2801 | event.SetEventObject(win); | |
40bdc5d6 VZ |
2802 | if ( !win->GetEventHandler()->ProcessEvent(event) ) |
2803 | { | |
44038f9a VS |
2804 | // windows must handle this event, otherwise the app wouldn't behave |
2805 | // correctly if it loses capture unexpectedly; see the discussion here: | |
2806 | // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863 | |
2807 | // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376 | |
40bdc5d6 VZ |
2808 | wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") ); |
2809 | } | |
63e819f2 VS |
2810 | } |
2811 | ||
2812 | /* static */ | |
72f8c792 | 2813 | void wxWindowBase::NotifyCaptureLost() |
63e819f2 VS |
2814 | { |
2815 | // don't do anything if capture lost was expected, i.e. resulted from | |
2816 | // a wx call to ReleaseMouse or CaptureMouse: | |
2817 | if ( ms_winCaptureChanging ) | |
2818 | return; | |
2819 | ||
2820 | // if the capture was lost unexpectedly, notify every window that has | |
2821 | // capture (on stack or current) about it and clear the stack: | |
2822 | ||
2823 | if ( ms_winCaptureCurrent ) | |
2824 | { | |
2825 | DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent); | |
2826 | ms_winCaptureCurrent = NULL; | |
2827 | } | |
2828 | ||
2829 | while ( ms_winCaptureNext ) | |
2830 | { | |
2831 | wxWindowNext *item = ms_winCaptureNext; | |
2832 | ms_winCaptureNext = item->next; | |
2833 | ||
2834 | DoNotifyWindowAboutCaptureLost(item->win); | |
2835 | ||
2836 | delete item; | |
2837 | } | |
2838 | } | |
2839 | ||
5048c832 | 2840 | #if wxUSE_HOTKEY |
540b6b09 VZ |
2841 | |
2842 | bool | |
2843 | wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId), | |
2844 | int WXUNUSED(modifiers), | |
2845 | int WXUNUSED(keycode)) | |
5048c832 JS |
2846 | { |
2847 | // not implemented | |
2848 | return false; | |
2849 | } | |
2850 | ||
540b6b09 | 2851 | bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId)) |
5048c832 JS |
2852 | { |
2853 | // not implemented | |
2854 | return false; | |
2855 | } | |
540b6b09 VZ |
2856 | |
2857 | #endif // wxUSE_HOTKEY | |
7de59551 | 2858 | |
4caf847c VZ |
2859 | // ---------------------------------------------------------------------------- |
2860 | // event processing | |
2861 | // ---------------------------------------------------------------------------- | |
2862 | ||
8cc208e3 | 2863 | bool wxWindowBase::TryBefore(wxEvent& event) |
4caf847c | 2864 | { |
6eabf58c | 2865 | #if wxUSE_VALIDATORS |
4caf847c VZ |
2866 | // Can only use the validator of the window which |
2867 | // is receiving the event | |
2868 | if ( event.GetEventObject() == this ) | |
2869 | { | |
92089d00 VZ |
2870 | wxValidator * const validator = GetValidator(); |
2871 | if ( validator && validator->ProcessEventHere(event) ) | |
4caf847c | 2872 | { |
6eabf58c | 2873 | return true; |
4caf847c VZ |
2874 | } |
2875 | } | |
6eabf58c | 2876 | #endif // wxUSE_VALIDATORS |
4caf847c | 2877 | |
8cc208e3 | 2878 | return wxEvtHandler::TryBefore(event); |
4caf847c VZ |
2879 | } |
2880 | ||
8cc208e3 | 2881 | bool wxWindowBase::TryAfter(wxEvent& event) |
4caf847c | 2882 | { |
90e572f1 | 2883 | // carry on up the parent-child hierarchy if the propagation count hasn't |
040e234d VZ |
2884 | // reached zero yet |
2885 | if ( event.ShouldPropagate() ) | |
4caf847c VZ |
2886 | { |
2887 | // honour the requests to stop propagation at this window: this is | |
2888 | // used by the dialogs, for example, to prevent processing the events | |
2889 | // from the dialog controls in the parent frame which rarely, if ever, | |
2890 | // makes sense | |
2891 | if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) ) | |
2892 | { | |
2893 | wxWindow *parent = GetParent(); | |
2894 | if ( parent && !parent->IsBeingDeleted() ) | |
040e234d VZ |
2895 | { |
2896 | wxPropagateOnce propagateOnce(event); | |
2897 | ||
4caf847c | 2898 | return parent->GetEventHandler()->ProcessEvent(event); |
040e234d | 2899 | } |
4caf847c VZ |
2900 | } |
2901 | } | |
2902 | ||
8cc208e3 | 2903 | return wxEvtHandler::TryAfter(event); |
4caf847c VZ |
2904 | } |
2905 | ||
c944775f VZ |
2906 | // ---------------------------------------------------------------------------- |
2907 | // window relationships | |
2908 | // ---------------------------------------------------------------------------- | |
2909 | ||
2910 | wxWindow *wxWindowBase::DoGetSibling(WindowOrder order) const | |
2911 | { | |
2912 | wxCHECK_MSG( GetParent(), NULL, | |
2913 | _T("GetPrev/NextSibling() don't work for TLWs!") ); | |
2914 | ||
2915 | wxWindowList& siblings = GetParent()->GetChildren(); | |
c52b9635 | 2916 | wxWindowList::compatibility_iterator i = siblings.Find((wxWindow *)this); |
c944775f VZ |
2917 | wxCHECK_MSG( i, NULL, _T("window not a child of its parent?") ); |
2918 | ||
2919 | if ( order == OrderBefore ) | |
2920 | i = i->GetPrevious(); | |
2921 | else // OrderAfter | |
2922 | i = i->GetNext(); | |
2923 | ||
2924 | return i ? i->GetData() : NULL; | |
2925 | } | |
2926 | ||
5f6cfda7 | 2927 | // ---------------------------------------------------------------------------- |
a24de76b | 2928 | // keyboard navigation |
5f6cfda7 JS |
2929 | // ---------------------------------------------------------------------------- |
2930 | ||
5644933f | 2931 | // Navigates in the specified direction inside this window |
553d2d7d | 2932 | bool wxWindowBase::DoNavigateIn(int flags) |
5f6cfda7 | 2933 | { |
5644933f VZ |
2934 | #ifdef wxHAS_NATIVE_TAB_TRAVERSAL |
2935 | // native code doesn't process our wxNavigationKeyEvents anyhow | |
553d2d7d | 2936 | wxUnusedVar(flags); |
5644933f VZ |
2937 | return false; |
2938 | #else // !wxHAS_NATIVE_TAB_TRAVERSAL | |
5f6cfda7 | 2939 | wxNavigationKeyEvent eventNav; |
f029f1d1 VS |
2940 | wxWindow *focused = FindFocus(); |
2941 | eventNav.SetCurrentFocus(focused); | |
2942 | eventNav.SetEventObject(focused); | |
eedc82f4 | 2943 | eventNav.SetFlags(flags); |
5644933f VZ |
2944 | return GetEventHandler()->ProcessEvent(eventNav); |
2945 | #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL | |
5f6cfda7 JS |
2946 | } |
2947 | ||
f029f1d1 VS |
2948 | bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent& event) |
2949 | { | |
2950 | if ( event.GetKeyCode() != WXK_TAB ) | |
2951 | return false; | |
2952 | ||
2953 | int flags = wxNavigationKeyEvent::FromTab; | |
2954 | ||
2955 | if ( event.ShiftDown() ) | |
2956 | flags |= wxNavigationKeyEvent::IsBackward; | |
2957 | else | |
2958 | flags |= wxNavigationKeyEvent::IsForward; | |
2959 | ||
2960 | if ( event.ControlDown() ) | |
2961 | flags |= wxNavigationKeyEvent::WinChange; | |
2962 | ||
2963 | Navigate(flags); | |
2964 | return true; | |
2965 | } | |
2966 | ||
c944775f | 2967 | void wxWindowBase::DoMoveInTabOrder(wxWindow *win, WindowOrder move) |
a24de76b VZ |
2968 | { |
2969 | // check that we're not a top level window | |
2970 | wxCHECK_RET( GetParent(), | |
2971 | _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") ); | |
2972 | ||
ef6816ef VZ |
2973 | // detect the special case when we have nothing to do anyhow and when the |
2974 | // code below wouldn't work | |
2975 | if ( win == this ) | |
2976 | return; | |
2977 | ||
a24de76b VZ |
2978 | // find the target window in the siblings list |
2979 | wxWindowList& siblings = GetParent()->GetChildren(); | |
2980 | wxWindowList::compatibility_iterator i = siblings.Find(win); | |
2981 | wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") ); | |
2982 | ||
2983 | // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we | |
2984 | // can't just move the node around | |
feef1ecf VZ |
2985 | wxWindow *self = (wxWindow *)this; |
2986 | siblings.DeleteObject(self); | |
c944775f | 2987 | if ( move == OrderAfter ) |
9e9300c4 VZ |
2988 | { |
2989 | i = i->GetNext(); | |
2990 | } | |
2991 | ||
2992 | if ( i ) | |
a24de76b | 2993 | { |
feef1ecf | 2994 | siblings.Insert(i, self); |
a24de76b | 2995 | } |
c944775f | 2996 | else // OrderAfter and win was the last sibling |
a24de76b | 2997 | { |
feef1ecf | 2998 | siblings.Append(self); |
a24de76b VZ |
2999 | } |
3000 | } | |
3001 | ||
0fe02759 VS |
3002 | // ---------------------------------------------------------------------------- |
3003 | // focus handling | |
3004 | // ---------------------------------------------------------------------------- | |
3005 | ||
3006 | /*static*/ wxWindow* wxWindowBase::FindFocus() | |
3007 | { | |
9c52a429 | 3008 | wxWindowBase *win = DoFindFocus(); |
0fe02759 VS |
3009 | return win ? win->GetMainWindowOfCompositeControl() : NULL; |
3010 | } | |
3011 | ||
3358af0f VS |
3012 | bool wxWindowBase::HasFocus() const |
3013 | { | |
3014 | wxWindowBase *win = DoFindFocus(); | |
3015 | return win == this || | |
3016 | win == wxConstCast(this, wxWindowBase)->GetMainWindowOfCompositeControl(); | |
3017 | } | |
3018 | ||
4f24cbbd VS |
3019 | // ---------------------------------------------------------------------------- |
3020 | // drag and drop | |
3021 | // ---------------------------------------------------------------------------- | |
3022 | ||
3023 | #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__) | |
3024 | ||
3025 | namespace | |
3026 | { | |
3027 | ||
3028 | class DragAcceptFilesTarget : public wxFileDropTarget | |
3029 | { | |
3030 | public: | |
3031 | DragAcceptFilesTarget(wxWindowBase *win) : m_win(win) {} | |
3032 | ||
3033 | virtual bool OnDropFiles(wxCoord x, wxCoord y, | |
3034 | const wxArrayString& filenames) | |
3035 | { | |
3036 | wxDropFilesEvent event(wxEVT_DROP_FILES, | |
3037 | filenames.size(), | |
3038 | wxCArrayString(filenames).Release()); | |
3039 | event.SetEventObject(m_win); | |
3040 | event.m_pos.x = x; | |
3041 | event.m_pos.y = y; | |
3042 | ||
3043 | return m_win->HandleWindowEvent(event); | |
3044 | } | |
3045 | ||
3046 | private: | |
3047 | wxWindowBase * const m_win; | |
3048 | ||
c0c133e1 | 3049 | wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget); |
4f24cbbd VS |
3050 | }; |
3051 | ||
3052 | ||
3053 | } // anonymous namespace | |
3054 | ||
3055 | // Generic version of DragAcceptFiles(). It works by installing a simple | |
3056 | // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used | |
3057 | // together with explicit SetDropTarget() calls. | |
3058 | void wxWindowBase::DragAcceptFiles(bool accept) | |
3059 | { | |
3060 | if ( accept ) | |
3061 | { | |
3062 | wxASSERT_MSG( !GetDropTarget(), | |
3063 | "cannot use DragAcceptFiles() and SetDropTarget() together" ); | |
3064 | SetDropTarget(new DragAcceptFilesTarget(this)); | |
3065 | } | |
3066 | else | |
3067 | { | |
3068 | SetDropTarget(NULL); | |
3069 | } | |
3070 | } | |
3071 | ||
3072 | #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__) | |
3073 | ||
33b494d6 VZ |
3074 | // ---------------------------------------------------------------------------- |
3075 | // global functions | |
3076 | // ---------------------------------------------------------------------------- | |
3077 | ||
3078 | wxWindow* wxGetTopLevelParent(wxWindow *win) | |
3079 | { | |
3080 | while ( win && !win->IsTopLevel() ) | |
3081 | win = win->GetParent(); | |
3082 | ||
3083 | return win; | |
3084 | } | |
3085 | ||
ed5317e5 JS |
3086 | #if wxUSE_ACCESSIBILITY |
3087 | // ---------------------------------------------------------------------------- | |
3088 | // accessible object for windows | |
3089 | // ---------------------------------------------------------------------------- | |
3090 | ||
3091 | // Can return either a child object, or an integer | |
3092 | // representing the child element, starting from 1. | |
66b9ec3d | 3093 | wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject)) |
ed5317e5 JS |
3094 | { |
3095 | wxASSERT( GetWindow() != NULL ); | |
3096 | if (!GetWindow()) | |
3097 | return wxACC_FAIL; | |
3098 | ||
3099 | return wxACC_NOT_IMPLEMENTED; | |
3100 | } | |
3101 | ||
3102 | // Returns the rectangle for this object (id = 0) or a child element (id > 0). | |
3103 | wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId) | |
3104 | { | |
3105 | wxASSERT( GetWindow() != NULL ); | |
3106 | if (!GetWindow()) | |
3107 | return wxACC_FAIL; | |
3108 | ||
c6e2af45 JS |
3109 | wxWindow* win = NULL; |
3110 | if (elementId == 0) | |
3111 | { | |
3112 | win = GetWindow(); | |
3113 | } | |
3114 | else | |
3115 | { | |
3116 | if (elementId <= (int) GetWindow()->GetChildren().GetCount()) | |
3117 | { | |
ee6eb8d8 | 3118 | win = GetWindow()->GetChildren().Item(elementId-1)->GetData(); |
c6e2af45 JS |
3119 | } |
3120 | else | |
3121 | return wxACC_FAIL; | |
3122 | } | |
3123 | if (win) | |
3124 | { | |
3125 | rect = win->GetRect(); | |
3126 | if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow))) | |
3127 | rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition())); | |
3128 | return wxACC_OK; | |
3129 | } | |
3130 | ||
ed5317e5 JS |
3131 | return wxACC_NOT_IMPLEMENTED; |
3132 | } | |
3133 | ||
3134 | // Navigates from fromId to toId/toObject. | |
3135 | wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId, | |
66b9ec3d | 3136 | int* WXUNUSED(toId), wxAccessible** toObject) |
ed5317e5 JS |
3137 | { |
3138 | wxASSERT( GetWindow() != NULL ); | |
3139 | if (!GetWindow()) | |
3140 | return wxACC_FAIL; | |
3141 | ||
c6e2af45 JS |
3142 | switch (navDir) |
3143 | { | |
3144 | case wxNAVDIR_FIRSTCHILD: | |
3145 | { | |
3146 | if (GetWindow()->GetChildren().GetCount() == 0) | |
3147 | return wxACC_FALSE; | |
3148 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData(); | |
3149 | *toObject = childWindow->GetOrCreateAccessible(); | |
3150 | ||
3151 | return wxACC_OK; | |
3152 | } | |
3153 | case wxNAVDIR_LASTCHILD: | |
3154 | { | |
3155 | if (GetWindow()->GetChildren().GetCount() == 0) | |
3156 | return wxACC_FALSE; | |
3157 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData(); | |
3158 | *toObject = childWindow->GetOrCreateAccessible(); | |
3159 | ||
3160 | return wxACC_OK; | |
3161 | } | |
3162 | case wxNAVDIR_RIGHT: | |
3163 | case wxNAVDIR_DOWN: | |
3164 | case wxNAVDIR_NEXT: | |
3165 | { | |
ee6eb8d8 MB |
3166 | wxWindowList::compatibility_iterator node = |
3167 | wxWindowList::compatibility_iterator(); | |
c6e2af45 JS |
3168 | if (fromId == 0) |
3169 | { | |
3170 | // Can't navigate to sibling of this window | |
3171 | // if we're a top-level window. | |
3172 | if (!GetWindow()->GetParent()) | |
3173 | return wxACC_NOT_IMPLEMENTED; | |
3174 | ||
3175 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
3176 | } | |
3177 | else | |
3178 | { | |
3179 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
33b3f7c3 | 3180 | node = GetWindow()->GetChildren().Item(fromId-1); |
c6e2af45 JS |
3181 | } |
3182 | ||
3183 | if (node && node->GetNext()) | |
3184 | { | |
ee6eb8d8 | 3185 | wxWindow* nextWindow = node->GetNext()->GetData(); |
c6e2af45 JS |
3186 | *toObject = nextWindow->GetOrCreateAccessible(); |
3187 | return wxACC_OK; | |
3188 | } | |
3189 | else | |
3190 | return wxACC_FALSE; | |
3191 | } | |
3192 | case wxNAVDIR_LEFT: | |
3193 | case wxNAVDIR_UP: | |
3194 | case wxNAVDIR_PREVIOUS: | |
3195 | { | |
ee6eb8d8 MB |
3196 | wxWindowList::compatibility_iterator node = |
3197 | wxWindowList::compatibility_iterator(); | |
c6e2af45 JS |
3198 | if (fromId == 0) |
3199 | { | |
3200 | // Can't navigate to sibling of this window | |
3201 | // if we're a top-level window. | |
3202 | if (!GetWindow()->GetParent()) | |
3203 | return wxACC_NOT_IMPLEMENTED; | |
3204 | ||
3205 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
3206 | } | |
3207 | else | |
3208 | { | |
3209 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
33b3f7c3 | 3210 | node = GetWindow()->GetChildren().Item(fromId-1); |
c6e2af45 JS |
3211 | } |
3212 | ||
3213 | if (node && node->GetPrevious()) | |
3214 | { | |
ee6eb8d8 | 3215 | wxWindow* previousWindow = node->GetPrevious()->GetData(); |
c6e2af45 JS |
3216 | *toObject = previousWindow->GetOrCreateAccessible(); |
3217 | return wxACC_OK; | |
3218 | } | |
3219 | else | |
3220 | return wxACC_FALSE; | |
3221 | } | |
3222 | } | |
3223 | ||
ed5317e5 JS |
3224 | return wxACC_NOT_IMPLEMENTED; |
3225 | } | |
3226 | ||
3227 | // Gets the name of the specified object. | |
3228 | wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name) | |
3229 | { | |
3230 | wxASSERT( GetWindow() != NULL ); | |
3231 | if (!GetWindow()) | |
3232 | return wxACC_FAIL; | |
3233 | ||
2aefc528 JS |
3234 | wxString title; |
3235 | ||
77ffb593 | 3236 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
3237 | // child object. |
3238 | if (childId > 0) | |
3239 | return wxACC_NOT_IMPLEMENTED; | |
3240 | ||
3241 | // This will eventually be replaced by specialised | |
77ffb593 | 3242 | // accessible classes, one for each kind of wxWidgets |
2aefc528 | 3243 | // control or window. |
0b4f47a3 | 3244 | #if wxUSE_BUTTON |
2aefc528 JS |
3245 | if (GetWindow()->IsKindOf(CLASSINFO(wxButton))) |
3246 | title = ((wxButton*) GetWindow())->GetLabel(); | |
3247 | else | |
0b4f47a3 | 3248 | #endif |
2aefc528 | 3249 | title = GetWindow()->GetName(); |
e11f4636 | 3250 | |
ba889513 | 3251 | if (!title.empty()) |
ed5317e5 JS |
3252 | { |
3253 | *name = title; | |
3254 | return wxACC_OK; | |
3255 | } | |
3256 | else | |
3257 | return wxACC_NOT_IMPLEMENTED; | |
3258 | } | |
3259 | ||
3260 | // Gets the number of children. | |
3261 | wxAccStatus wxWindowAccessible::GetChildCount(int* childId) | |
3262 | { | |
3263 | wxASSERT( GetWindow() != NULL ); | |
3264 | if (!GetWindow()) | |
3265 | return wxACC_FAIL; | |
3266 | ||
3267 | *childId = (int) GetWindow()->GetChildren().GetCount(); | |
3268 | return wxACC_OK; | |
3269 | } | |
3270 | ||
3271 | // Gets the specified child (starting from 1). | |
3272 | // If *child is NULL and return value is wxACC_OK, | |
3273 | // this means that the child is a simple element and | |
3274 | // not an accessible object. | |
3275 | wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child) | |
3276 | { | |
3277 | wxASSERT( GetWindow() != NULL ); | |
3278 | if (!GetWindow()) | |
3279 | return wxACC_FAIL; | |
3280 | ||
3281 | if (childId == 0) | |
3282 | { | |
3283 | *child = this; | |
3284 | return wxACC_OK; | |
3285 | } | |
3286 | ||
3287 | if (childId > (int) GetWindow()->GetChildren().GetCount()) | |
3288 | return wxACC_FAIL; | |
3289 | ||
ee6eb8d8 | 3290 | wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData(); |
ed5317e5 JS |
3291 | *child = childWindow->GetOrCreateAccessible(); |
3292 | if (*child) | |
3293 | return wxACC_OK; | |
3294 | else | |
3295 | return wxACC_FAIL; | |
3296 | } | |
3297 | ||
3298 | // Gets the parent, or NULL. | |
3299 | wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent) | |
3300 | { | |
3301 | wxASSERT( GetWindow() != NULL ); | |
3302 | if (!GetWindow()) | |
3303 | return wxACC_FAIL; | |
3304 | ||
3305 | wxWindow* parentWindow = GetWindow()->GetParent(); | |
c6e2af45 | 3306 | if (!parentWindow) |
ed5317e5 JS |
3307 | { |
3308 | *parent = NULL; | |
3309 | return wxACC_OK; | |
3310 | } | |
3311 | else | |
3312 | { | |
3313 | *parent = parentWindow->GetOrCreateAccessible(); | |
3314 | if (*parent) | |
3315 | return wxACC_OK; | |
3316 | else | |
3317 | return wxACC_FAIL; | |
3318 | } | |
3319 | } | |
3320 | ||
3321 | // Performs the default action. childId is 0 (the action for this object) | |
3322 | // or > 0 (the action for a child). | |
3323 | // Return wxACC_NOT_SUPPORTED if there is no default action for this | |
3324 | // window (e.g. an edit control). | |
66b9ec3d | 3325 | wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId)) |
ed5317e5 JS |
3326 | { |
3327 | wxASSERT( GetWindow() != NULL ); | |
3328 | if (!GetWindow()) | |
3329 | return wxACC_FAIL; | |
3330 | ||
3331 | return wxACC_NOT_IMPLEMENTED; | |
3332 | } | |
3333 | ||
3334 | // Gets the default action for this object (0) or > 0 (the action for a child). | |
3335 | // Return wxACC_OK even if there is no action. actionName is the action, or the empty | |
3336 | // string if there is no action. | |
3337 | // The retrieved string describes the action that is performed on an object, | |
3338 | // not what the object does as a result. For example, a toolbar button that prints | |
3339 | // a document has a default action of "Press" rather than "Prints the current document." | |
66b9ec3d | 3340 | wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName)) |
ed5317e5 JS |
3341 | { |
3342 | wxASSERT( GetWindow() != NULL ); | |
3343 | if (!GetWindow()) | |
3344 | return wxACC_FAIL; | |
3345 | ||
3346 | return wxACC_NOT_IMPLEMENTED; | |
3347 | } | |
3348 | ||
3349 | // Returns the description for this object or a child. | |
66b9ec3d | 3350 | wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description) |
ed5317e5 JS |
3351 | { |
3352 | wxASSERT( GetWindow() != NULL ); | |
3353 | if (!GetWindow()) | |
3354 | return wxACC_FAIL; | |
3355 | ||
dc6588e7 | 3356 | wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard)); |
ba889513 | 3357 | if (!ht.empty()) |
2aefc528 JS |
3358 | { |
3359 | *description = ht; | |
3360 | return wxACC_OK; | |
3361 | } | |
ed5317e5 JS |
3362 | return wxACC_NOT_IMPLEMENTED; |
3363 | } | |
3364 | ||
3365 | // Returns help text for this object or a child, similar to tooltip text. | |
66b9ec3d | 3366 | wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText) |
ed5317e5 JS |
3367 | { |
3368 | wxASSERT( GetWindow() != NULL ); | |
3369 | if (!GetWindow()) | |
3370 | return wxACC_FAIL; | |
3371 | ||
dc6588e7 | 3372 | wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard)); |
ba889513 | 3373 | if (!ht.empty()) |
ed5317e5 JS |
3374 | { |
3375 | *helpText = ht; | |
3376 | return wxACC_OK; | |
3377 | } | |
3378 | return wxACC_NOT_IMPLEMENTED; | |
3379 | } | |
3380 | ||
3381 | // Returns the keyboard shortcut for this object or child. | |
3382 | // Return e.g. ALT+K | |
66b9ec3d | 3383 | wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut)) |
ed5317e5 JS |
3384 | { |
3385 | wxASSERT( GetWindow() != NULL ); | |
3386 | if (!GetWindow()) | |
3387 | return wxACC_FAIL; | |
3388 | ||
3389 | return wxACC_NOT_IMPLEMENTED; | |
3390 | } | |
3391 | ||
3392 | // Returns a role constant. | |
3393 | wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role) | |
3394 | { | |
3395 | wxASSERT( GetWindow() != NULL ); | |
3396 | if (!GetWindow()) | |
3397 | return wxACC_FAIL; | |
3398 | ||
77ffb593 | 3399 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
3400 | // child object. |
3401 | if (childId > 0) | |
3402 | return wxACC_NOT_IMPLEMENTED; | |
3403 | ||
3404 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
3405 | return wxACC_NOT_IMPLEMENTED; | |
3406 | #if wxUSE_STATUSBAR | |
3407 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
3408 | return wxACC_NOT_IMPLEMENTED; | |
3409 | #endif | |
3410 | #if wxUSE_TOOLBAR | |
3411 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
3412 | return wxACC_NOT_IMPLEMENTED; | |
3413 | #endif | |
3414 | ||
3415 | //*role = wxROLE_SYSTEM_CLIENT; | |
3416 | *role = wxROLE_SYSTEM_CLIENT; | |
3417 | return wxACC_OK; | |
3418 | ||
66b9ec3d | 3419 | #if 0 |
ed5317e5 | 3420 | return wxACC_NOT_IMPLEMENTED; |
66b9ec3d | 3421 | #endif |
ed5317e5 JS |
3422 | } |
3423 | ||
3424 | // Returns a state constant. | |
3425 | wxAccStatus wxWindowAccessible::GetState(int childId, long* state) | |
3426 | { | |
3427 | wxASSERT( GetWindow() != NULL ); | |
3428 | if (!GetWindow()) | |
3429 | return wxACC_FAIL; | |
3430 | ||
77ffb593 | 3431 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
3432 | // child object. |
3433 | if (childId > 0) | |
3434 | return wxACC_NOT_IMPLEMENTED; | |
3435 | ||
3436 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
3437 | return wxACC_NOT_IMPLEMENTED; | |
3438 | ||
3439 | #if wxUSE_STATUSBAR | |
3440 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
3441 | return wxACC_NOT_IMPLEMENTED; | |
3442 | #endif | |
3443 | #if wxUSE_TOOLBAR | |
3444 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
3445 | return wxACC_NOT_IMPLEMENTED; | |
3446 | #endif | |
3447 | ||
3448 | *state = 0; | |
3449 | return wxACC_OK; | |
3450 | ||
66b9ec3d | 3451 | #if 0 |
ed5317e5 | 3452 | return wxACC_NOT_IMPLEMENTED; |
66b9ec3d | 3453 | #endif |
ed5317e5 JS |
3454 | } |
3455 | ||
3456 | // Returns a localized string representing the value for the object | |
3457 | // or child. | |
66b9ec3d | 3458 | wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue)) |
ed5317e5 JS |
3459 | { |
3460 | wxASSERT( GetWindow() != NULL ); | |
3461 | if (!GetWindow()) | |
3462 | return wxACC_FAIL; | |
3463 | ||
3464 | return wxACC_NOT_IMPLEMENTED; | |
3465 | } | |
3466 | ||
3467 | // Selects the object or child. | |
66b9ec3d | 3468 | wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags)) |
ed5317e5 JS |
3469 | { |
3470 | wxASSERT( GetWindow() != NULL ); | |
3471 | if (!GetWindow()) | |
3472 | return wxACC_FAIL; | |
3473 | ||
3474 | return wxACC_NOT_IMPLEMENTED; | |
3475 | } | |
3476 | ||
3477 | // Gets the window with the keyboard focus. | |
3478 | // If childId is 0 and child is NULL, no object in | |
3479 | // this subhierarchy has the focus. | |
3480 | // If this object has the focus, child should be 'this'. | |
66b9ec3d | 3481 | wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child)) |
ed5317e5 JS |
3482 | { |
3483 | wxASSERT( GetWindow() != NULL ); | |
3484 | if (!GetWindow()) | |
3485 | return wxACC_FAIL; | |
3486 | ||
3487 | return wxACC_NOT_IMPLEMENTED; | |
3488 | } | |
3489 | ||
ca5c6ac3 | 3490 | #if wxUSE_VARIANT |
ed5317e5 JS |
3491 | // Gets a variant representing the selected children |
3492 | // of this object. | |
3493 | // Acceptable values: | |
cab1a605 | 3494 | // - a null variant (IsNull() returns true) |
ed5317e5 JS |
3495 | // - a list variant (GetType() == wxT("list") |
3496 | // - an integer representing the selected child element, | |
3497 | // or 0 if this object is selected (GetType() == wxT("long") | |
3498 | // - a "void*" pointer to a wxAccessible child object | |
66b9ec3d | 3499 | wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections)) |
ed5317e5 JS |
3500 | { |
3501 | wxASSERT( GetWindow() != NULL ); | |
3502 | if (!GetWindow()) | |
3503 | return wxACC_FAIL; | |
3504 | ||
3505 | return wxACC_NOT_IMPLEMENTED; | |
3506 | } | |
ca5c6ac3 | 3507 | #endif // wxUSE_VARIANT |
ed5317e5 JS |
3508 | |
3509 | #endif // wxUSE_ACCESSIBILITY | |
978af864 VZ |
3510 | |
3511 | // ---------------------------------------------------------------------------- | |
3512 | // RTL support | |
3513 | // ---------------------------------------------------------------------------- | |
3514 | ||
3515 | wxCoord | |
3516 | wxWindowBase::AdjustForLayoutDirection(wxCoord x, | |
3517 | wxCoord width, | |
3518 | wxCoord widthTotal) const | |
3519 | { | |
3520 | if ( GetLayoutDirection() == wxLayout_RightToLeft ) | |
3521 | { | |
3522 | x = widthTotal - x - width; | |
3523 | } | |
3524 | ||
3525 | return x; | |
3526 | } | |
3527 | ||
f35fdf7e | 3528 |