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