]>
Commit | Line | Data |
---|---|---|
7ec1983b | 1 | ///////////////////////////////////////////////////////////////////////////// |
f03fc89f | 2 | // Name: 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$ | |
f03fc89f | 8 | // Copyright: (c) wxWindows team |
7ec1983b VZ |
9 | // Licence: wxWindows license |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
f03fc89f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
f701d7ab | 19 | |
58654ed0 VZ |
20 | #ifdef __GNUG__ |
21 | #pragma implementation "windowbase.h" | |
22 | #endif | |
23 | ||
341287bf JS |
24 | // For compilers that support precompilation, includes "wx.h". |
25 | #include "wx/wxprec.h" | |
26 | ||
f701d7ab | 27 | #ifdef __BORLANDC__ |
f03fc89f | 28 | #pragma hdrstop |
f701d7ab JS |
29 | #endif |
30 | ||
f03fc89f VZ |
31 | #ifndef WX_PRECOMP |
32 | #include "wx/string.h" | |
33 | #include "wx/log.h" | |
34 | #include "wx/intl.h" | |
35 | #include "wx/frame.h" | |
36 | #include "wx/defs.h" | |
37 | #include "wx/window.h" | |
1e6feb95 | 38 | #include "wx/control.h" |
f03fc89f VZ |
39 | #include "wx/checkbox.h" |
40 | #include "wx/radiobut.h" | |
26bf1ce0 | 41 | #include "wx/textctrl.h" |
f03fc89f VZ |
42 | #include "wx/settings.h" |
43 | #include "wx/dialog.h" | |
a02dc3e3 | 44 | #include "wx/msgdlg.h" |
a37a5a73 | 45 | #include "wx/statusbr.h" |
f03fc89f VZ |
46 | #endif //WX_PRECOMP |
47 | ||
48 | #if wxUSE_CONSTRAINTS | |
49 | #include "wx/layout.h" | |
50 | #endif // wxUSE_CONSTRAINTS | |
51 | ||
461e93f9 JS |
52 | #include "wx/sizer.h" |
53 | ||
f03fc89f VZ |
54 | #if wxUSE_DRAG_AND_DROP |
55 | #include "wx/dnd.h" | |
56 | #endif // wxUSE_DRAG_AND_DROP | |
57 | ||
bd83cb56 VZ |
58 | #if wxUSE_HELP |
59 | #include "wx/cshelp.h" | |
60 | #endif // wxUSE_HELP | |
61 | ||
f03fc89f VZ |
62 | #if wxUSE_TOOLTIPS |
63 | #include "wx/tooltip.h" | |
64 | #endif // wxUSE_TOOLTIPS | |
65 | ||
789295bf VZ |
66 | #if wxUSE_CARET |
67 | #include "wx/caret.h" | |
68 | #endif // wxUSE_CARET | |
69 | ||
f03fc89f VZ |
70 | // ---------------------------------------------------------------------------- |
71 | // static data | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
42e69d6b | 74 | int wxWindowBase::ms_lastControlId = -200; |
f03fc89f VZ |
75 | |
76 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
77 | ||
78 | // ---------------------------------------------------------------------------- | |
79 | // event table | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
82 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
83 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
84 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
a02dc3e3 | 85 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) |
bd83cb56 VZ |
86 | |
87 | #if wxUSE_HELP | |
88 | EVT_HELP(-1, wxWindowBase::OnHelp) | |
89 | #endif // wxUSE_HELP | |
90 | ||
f03fc89f VZ |
91 | END_EVENT_TABLE() |
92 | ||
93 | // ============================================================================ | |
94 | // implementation of the common functionality of the wxWindow class | |
95 | // ============================================================================ | |
96 | ||
97 | // ---------------------------------------------------------------------------- | |
98 | // initialization | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | // the default initialization | |
102 | void wxWindowBase::InitBase() | |
103 | { | |
104 | // no window yet, no parent nor children | |
f03fc89f VZ |
105 | m_parent = (wxWindow *)NULL; |
106 | m_windowId = -1; | |
107 | m_children.DeleteContents( FALSE ); // don't auto delete node data | |
108 | ||
109 | // no constraints on the minimal window size | |
110 | m_minWidth = | |
111 | m_minHeight = | |
112 | m_maxWidth = | |
113 | m_maxHeight = -1; | |
114 | ||
115 | // window is created enabled but it's not visible yet | |
116 | m_isShown = FALSE; | |
117 | m_isEnabled = TRUE; | |
118 | ||
f03fc89f VZ |
119 | // the default event handler is just this window |
120 | m_eventHandler = this; | |
121 | ||
88ac883a | 122 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
123 | // no validator |
124 | m_windowValidator = (wxValidator *) NULL; | |
88ac883a | 125 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
126 | |
127 | // use the system default colours | |
a756f210 VS |
128 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); |
129 | m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
f6e4e9ea | 130 | |
8bf30fe9 VZ |
131 | // don't set the font here for wxMSW as we don't call WM_SETFONT here and |
132 | // so the font is *not* really set - but calls to SetFont() later won't do | |
133 | // anything because m_font appears to be already set! | |
134 | #ifndef __WXMSW__ | |
a756f210 | 135 | m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
8bf30fe9 | 136 | #endif // __WXMSW__ |
807a903e | 137 | |
08df3e44 VZ |
138 | // the colours/fonts are default for now |
139 | m_hasBgCol = | |
140 | m_hasFgCol = | |
141 | m_hasFont = FALSE; | |
142 | ||
f03fc89f | 143 | // no style bits |
d80cd92a | 144 | m_exStyle = |
f03fc89f VZ |
145 | m_windowStyle = 0; |
146 | ||
147 | // an optimization for the event processing: checking this flag is much | |
148 | // faster than using IsKindOf(CLASSINFO(wxWindow)) | |
149 | m_isWindow = TRUE; | |
150 | ||
151 | #if wxUSE_CONSTRAINTS | |
152 | // no constraints whatsoever | |
153 | m_constraints = (wxLayoutConstraints *) NULL; | |
154 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
461e93f9 JS |
155 | #endif // wxUSE_CONSTRAINTS |
156 | ||
f03fc89f | 157 | m_windowSizer = (wxSizer *) NULL; |
be90c029 | 158 | m_containingSizer = (wxSizer *) NULL; |
f03fc89f | 159 | m_autoLayout = FALSE; |
f03fc89f VZ |
160 | |
161 | #if wxUSE_DRAG_AND_DROP | |
162 | m_dropTarget = (wxDropTarget *)NULL; | |
163 | #endif // wxUSE_DRAG_AND_DROP | |
164 | ||
165 | #if wxUSE_TOOLTIPS | |
166 | m_tooltip = (wxToolTip *)NULL; | |
167 | #endif // wxUSE_TOOLTIPS | |
789295bf VZ |
168 | |
169 | #if wxUSE_CARET | |
170 | m_caret = (wxCaret *)NULL; | |
171 | #endif // wxUSE_CARET | |
a2d93e73 | 172 | |
574c939e | 173 | #if wxUSE_PALETTE |
b95edd47 | 174 | m_hasCustomPalette = FALSE; |
574c939e KB |
175 | #endif // wxUSE_PALETTE |
176 | ||
566d84a7 RL |
177 | m_virtualSize = wxDefaultSize; |
178 | m_minVirtualWidth = -1; | |
179 | m_minVirtualHeight = -1; | |
180 | m_maxVirtualWidth = -1; | |
181 | m_maxVirtualHeight = -1; | |
182 | ||
a2d93e73 JS |
183 | // Whether we're using the current theme for this window (wxGTK only for now) |
184 | m_themeEnabled = FALSE; | |
f03fc89f VZ |
185 | } |
186 | ||
187 | // common part of window creation process | |
188 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
189 | wxWindowID id, | |
74e3313b VZ |
190 | const wxPoint& WXUNUSED(pos), |
191 | const wxSize& WXUNUSED(size), | |
f03fc89f | 192 | long style, |
8d99be5f | 193 | const wxValidator& validator, |
f03fc89f VZ |
194 | const wxString& name) |
195 | { | |
196 | // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other | |
197 | // member variables - check that it has been called (will catch the case | |
198 | // when a new ctor is added which doesn't call InitWindow) | |
223d09f6 | 199 | wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") ); |
f03fc89f VZ |
200 | |
201 | // generate a new id if the user doesn't care about it | |
69418a8e | 202 | m_windowId = id == -1 ? NewControlId() : id; |
f03fc89f VZ |
203 | |
204 | SetName(name); | |
205 | SetWindowStyleFlag(style); | |
206 | SetParent(parent); | |
674ac8b9 VZ |
207 | |
208 | #if wxUSE_VALIDATORS | |
8d99be5f | 209 | SetValidator(validator); |
674ac8b9 | 210 | #endif // wxUSE_VALIDATORS |
f03fc89f | 211 | |
8ae6ce07 VZ |
212 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to |
213 | // have it too - like this it's possible to set it only in the top level | |
214 | // dialog/frame and all children will inherit it by defult | |
215 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
216 | { | |
217 | SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY); | |
218 | } | |
219 | ||
f03fc89f VZ |
220 | return TRUE; |
221 | } | |
222 | ||
223 | // ---------------------------------------------------------------------------- | |
224 | // destruction | |
225 | // ---------------------------------------------------------------------------- | |
226 | ||
227 | // common clean up | |
228 | wxWindowBase::~wxWindowBase() | |
229 | { | |
349d1942 VS |
230 | wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") ); |
231 | ||
f03fc89f VZ |
232 | // FIXME if these 2 cases result from programming errors in the user code |
233 | // we should probably assert here instead of silently fixing them | |
234 | ||
235 | // Just in case the window has been Closed, but we're then deleting | |
236 | // immediately: don't leave dangling pointers. | |
237 | wxPendingDelete.DeleteObject(this); | |
238 | ||
239 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
240 | // we weren't a dialog class | |
241 | wxTopLevelWindows.DeleteObject(this); | |
a23fd0e1 | 242 | |
223d09f6 | 243 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); |
f03fc89f | 244 | |
789295bf VZ |
245 | #if wxUSE_CARET |
246 | if ( m_caret ) | |
247 | delete m_caret; | |
248 | #endif // wxUSE_CARET | |
249 | ||
88ac883a | 250 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
251 | if ( m_windowValidator ) |
252 | delete m_windowValidator; | |
88ac883a | 253 | #endif // wxUSE_VALIDATORS |
f03fc89f | 254 | |
f03fc89f VZ |
255 | #if wxUSE_CONSTRAINTS |
256 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
257 | // at deleted windows as they delete themselves. | |
258 | DeleteRelatedConstraints(); | |
259 | ||
260 | if ( m_constraints ) | |
261 | { | |
262 | // This removes any dangling pointers to this window in other windows' | |
263 | // constraintsInvolvedIn lists. | |
264 | UnsetConstraints(m_constraints); | |
265 | delete m_constraints; | |
266 | m_constraints = NULL; | |
267 | } | |
268 | ||
461e93f9 JS |
269 | #endif // wxUSE_CONSTRAINTS |
270 | ||
be90c029 RD |
271 | if ( m_containingSizer ) |
272 | m_containingSizer->Remove((wxWindow*)this); | |
273 | ||
f03fc89f VZ |
274 | if ( m_windowSizer ) |
275 | delete m_windowSizer; | |
276 | ||
f03fc89f VZ |
277 | #if wxUSE_DRAG_AND_DROP |
278 | if ( m_dropTarget ) | |
279 | delete m_dropTarget; | |
280 | #endif // wxUSE_DRAG_AND_DROP | |
281 | ||
282 | #if wxUSE_TOOLTIPS | |
283 | if ( m_tooltip ) | |
284 | delete m_tooltip; | |
285 | #endif // wxUSE_TOOLTIPS | |
b0ee47ff VZ |
286 | |
287 | // reset the dangling pointer our parent window may keep to us | |
288 | if ( m_parent && m_parent->GetDefaultItem() == this ) | |
289 | { | |
290 | m_parent->SetDefaultItem(NULL); | |
291 | } | |
f03fc89f VZ |
292 | } |
293 | ||
294 | bool wxWindowBase::Destroy() | |
295 | { | |
296 | delete this; | |
297 | ||
298 | return TRUE; | |
299 | } | |
300 | ||
301 | bool wxWindowBase::Close(bool force) | |
302 | { | |
303 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
304 | event.SetEventObject(this); | |
305 | #if WXWIN_COMPATIBILITY | |
306 | event.SetForce(force); | |
307 | #endif // WXWIN_COMPATIBILITY | |
308 | event.SetCanVeto(!force); | |
309 | ||
310 | // return FALSE if window wasn't closed because the application vetoed the | |
311 | // close event | |
312 | return GetEventHandler()->ProcessEvent(event) && !event.GetVeto(); | |
313 | } | |
314 | ||
315 | bool wxWindowBase::DestroyChildren() | |
316 | { | |
317 | wxWindowList::Node *node; | |
a23fd0e1 | 318 | for ( ;; ) |
f03fc89f | 319 | { |
a23fd0e1 VZ |
320 | // we iterate until the list becomes empty |
321 | node = GetChildren().GetFirst(); | |
322 | if ( !node ) | |
323 | break; | |
324 | ||
f03fc89f | 325 | wxWindow *child = node->GetData(); |
a23fd0e1 | 326 | |
223d09f6 | 327 | wxASSERT_MSG( child, wxT("children list contains empty nodes") ); |
a23fd0e1 | 328 | |
1a77875b | 329 | child->Show(FALSE); |
eb082a08 | 330 | delete child; |
a23fd0e1 VZ |
331 | |
332 | wxASSERT_MSG( !GetChildren().Find(child), | |
223d09f6 | 333 | wxT("child didn't remove itself using RemoveChild()") ); |
f03fc89f VZ |
334 | } |
335 | ||
336 | return TRUE; | |
337 | } | |
338 | ||
339 | // ---------------------------------------------------------------------------- | |
f68586e5 | 340 | // size/position related methods |
f03fc89f VZ |
341 | // ---------------------------------------------------------------------------- |
342 | ||
343 | // centre the window with respect to its parent in either (or both) directions | |
344 | void wxWindowBase::Centre(int direction) | |
345 | { | |
f6bcfd97 BP |
346 | // the position/size of the parent window or of the entire screen |
347 | wxPoint posParent; | |
f03fc89f VZ |
348 | int widthParent, heightParent; |
349 | ||
f6bcfd97 BP |
350 | wxWindow *parent = NULL; |
351 | ||
352 | if ( !(direction & wxCENTRE_ON_SCREEN) ) | |
f03fc89f | 353 | { |
f6bcfd97 BP |
354 | // find the parent to centre this window on: it should be the |
355 | // immediate parent for the controls but the top level parent for the | |
356 | // top level windows (like dialogs) | |
357 | parent = GetParent(); | |
358 | if ( IsTopLevel() ) | |
359 | { | |
360 | while ( parent && !parent->IsTopLevel() ) | |
361 | { | |
362 | parent = parent->GetParent(); | |
363 | } | |
364 | } | |
365 | ||
366 | // did we find the parent? | |
367 | if ( !parent ) | |
368 | { | |
369 | // no other choice | |
370 | direction |= wxCENTRE_ON_SCREEN; | |
371 | } | |
f03fc89f | 372 | } |
10fcf31a VZ |
373 | |
374 | if ( direction & wxCENTRE_ON_SCREEN ) | |
f03fc89f VZ |
375 | { |
376 | // centre with respect to the whole screen | |
377 | wxDisplaySize(&widthParent, &heightParent); | |
378 | } | |
10fcf31a VZ |
379 | else |
380 | { | |
f6bcfd97 BP |
381 | if ( IsTopLevel() ) |
382 | { | |
383 | // centre on the parent | |
384 | parent->GetSize(&widthParent, &heightParent); | |
385 | ||
386 | // adjust to the parents position | |
387 | posParent = parent->GetPosition(); | |
388 | } | |
389 | else | |
390 | { | |
391 | // centre inside the parents client rectangle | |
392 | parent->GetClientSize(&widthParent, &heightParent); | |
393 | } | |
10fcf31a | 394 | } |
f03fc89f VZ |
395 | |
396 | int width, height; | |
397 | GetSize(&width, &height); | |
398 | ||
c39eda94 VZ |
399 | int xNew = -1, |
400 | yNew = -1; | |
f03fc89f VZ |
401 | |
402 | if ( direction & wxHORIZONTAL ) | |
c39eda94 | 403 | xNew = (widthParent - width)/2; |
f03fc89f VZ |
404 | |
405 | if ( direction & wxVERTICAL ) | |
c39eda94 | 406 | yNew = (heightParent - height)/2; |
f03fc89f | 407 | |
f6bcfd97 BP |
408 | xNew += posParent.x; |
409 | yNew += posParent.y; | |
7631a292 | 410 | |
ef397583 GT |
411 | // Base size of the visible dimensions of the display |
412 | // to take into account the taskbar | |
413 | wxRect rect = wxGetClientDisplayRect(); | |
414 | wxSize size (rect.width,rect.height); | |
415 | ||
ede7020a VS |
416 | // NB: in wxMSW, negative position may not neccessary mean "out of screen", |
417 | // but it may mean that the window is placed on other than the main | |
418 | // display. Therefore we only make sure centered window is on the main display | |
419 | // if the parent is at least partially present here. | |
420 | if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display | |
ef397583 GT |
421 | { |
422 | if (xNew < 0) | |
423 | xNew = 0; | |
424 | else if (xNew+width > size.x) | |
425 | xNew = size.x-width-1; | |
426 | } | |
ede7020a | 427 | if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display |
ef397583 GT |
428 | { |
429 | if (yNew+height > size.y) | |
430 | yNew = size.y-height-1; | |
431 | ||
432 | // Make certain that the title bar is initially visible | |
433 | // always, even if this would push the bottom of the | |
434 | // dialog of the visible area of the display | |
435 | if (yNew < 0) | |
436 | yNew = 0; | |
437 | } | |
438 | ||
0fff366e VZ |
439 | // move the window to this position (keeping the old size but using |
440 | // SetSize() and not Move() to allow xNew and/or yNew to be -1) | |
db89aa76 | 441 | SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE); |
7631a292 RD |
442 | } |
443 | ||
f03fc89f VZ |
444 | // fits the window around the children |
445 | void wxWindowBase::Fit() | |
446 | { | |
f68586e5 VZ |
447 | if ( GetChildren().GetCount() > 0 ) |
448 | { | |
ba81034d VZ |
449 | wxSize size = DoGetBestSize(); |
450 | ||
451 | // for compatibility with the old versions and because it really looks | |
452 | // slightly more pretty like this, add a pad | |
453 | size.x += 7; | |
454 | size.y += 14; | |
455 | ||
456 | SetClientSize(size); | |
f68586e5 VZ |
457 | } |
458 | //else: do nothing if we have no children | |
459 | } | |
f03fc89f | 460 | |
f68586e5 VZ |
461 | // return the size best suited for the current window |
462 | wxSize wxWindowBase::DoGetBestSize() const | |
463 | { | |
464 | if ( GetChildren().GetCount() > 0 ) | |
f03fc89f | 465 | { |
f68586e5 VZ |
466 | // our minimal acceptable size is such that all our windows fit inside |
467 | int maxX = 0, | |
468 | maxY = 0; | |
469 | ||
470 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
471 | node; | |
472 | node = node->GetNext() ) | |
42e69d6b | 473 | { |
f68586e5 | 474 | wxWindow *win = node->GetData(); |
1e6feb95 VZ |
475 | if ( win->IsTopLevel() |
476 | #if wxUSE_STATUSBAR | |
477 | || wxDynamicCast(win, wxStatusBar) | |
478 | #endif // wxUSE_STATUSBAR | |
479 | ) | |
f68586e5 VZ |
480 | { |
481 | // dialogs and frames lie in different top level windows - | |
7d9fd004 VZ |
482 | // don't deal with them here; as for the status bars, they |
483 | // don't lie in the client area at all | |
f68586e5 VZ |
484 | continue; |
485 | } | |
486 | ||
487 | int wx, wy, ww, wh; | |
488 | win->GetPosition(&wx, &wy); | |
3f5513f5 VZ |
489 | |
490 | // if the window hadn't been positioned yet, assume that it is in | |
491 | // the origin | |
492 | if ( wx == -1 ) | |
493 | wx = 0; | |
494 | if ( wy == -1 ) | |
495 | wy = 0; | |
496 | ||
f68586e5 VZ |
497 | win->GetSize(&ww, &wh); |
498 | if ( wx + ww > maxX ) | |
499 | maxX = wx + ww; | |
500 | if ( wy + wh > maxY ) | |
501 | maxY = wy + wh; | |
42e69d6b VZ |
502 | } |
503 | ||
ba81034d | 504 | return wxSize(maxX, maxY); |
f68586e5 VZ |
505 | } |
506 | else | |
507 | { | |
508 | // for a generic window there is no natural best size - just use the | |
509 | // current one | |
510 | return GetSize(); | |
f03fc89f | 511 | } |
f03fc89f VZ |
512 | } |
513 | ||
1e6feb95 VZ |
514 | // by default the origin is not shifted |
515 | wxPoint wxWindowBase::GetClientAreaOrigin() const | |
516 | { | |
517 | return wxPoint(0, 0); | |
518 | } | |
519 | ||
f03fc89f | 520 | // set the min/max size of the window |
f03fc89f VZ |
521 | void wxWindowBase::SetSizeHints(int minW, int minH, |
522 | int maxW, int maxH, | |
523 | int WXUNUSED(incW), int WXUNUSED(incH)) | |
524 | { | |
525 | m_minWidth = minW; | |
526 | m_maxWidth = maxW; | |
527 | m_minHeight = minH; | |
528 | m_maxHeight = maxH; | |
529 | } | |
530 | ||
566d84a7 RL |
531 | void wxWindowBase::SetVirtualSizeHints( int minW, int minH, |
532 | int maxW, int maxH ) | |
533 | { | |
534 | m_minVirtualWidth = minW; | |
535 | m_maxVirtualWidth = maxW; | |
536 | m_minVirtualHeight = minH; | |
537 | m_maxVirtualHeight = maxH; | |
538 | ||
539 | SetVirtualSize( GetClientSize() ); | |
540 | } | |
541 | ||
542 | void wxWindowBase::DoSetVirtualSize( int x, int y ) | |
543 | { | |
544 | if( m_minVirtualWidth != -1 && m_minVirtualWidth > x ) x = m_minVirtualWidth; | |
545 | if( m_maxVirtualWidth != -1 && m_maxVirtualWidth < x ) x = m_maxVirtualWidth; | |
546 | if( m_minVirtualHeight != -1 && m_minVirtualHeight > y ) y = m_minVirtualHeight; | |
547 | if( m_maxVirtualHeight != -1 && m_maxVirtualHeight < y ) y = m_maxVirtualHeight; | |
548 | ||
549 | m_virtualSize.SetWidth( x ); | |
550 | m_virtualSize.SetHeight( y ); | |
551 | } | |
552 | ||
553 | wxSize wxWindowBase::DoGetVirtualSize() const | |
554 | { | |
555 | wxSize s( GetClientSize() ); | |
556 | ||
557 | if( m_virtualSize.GetWidth() != -1 ) | |
558 | s.SetWidth( m_virtualSize.GetWidth() ); | |
559 | if( m_virtualSize.GetHeight() != -1 ) | |
560 | s.SetHeight( m_virtualSize.GetHeight() ); | |
561 | ||
562 | return s; | |
563 | } | |
564 | ||
f03fc89f VZ |
565 | // ---------------------------------------------------------------------------- |
566 | // show/hide/enable/disable the window | |
567 | // ---------------------------------------------------------------------------- | |
568 | ||
569 | bool wxWindowBase::Show(bool show) | |
570 | { | |
571 | if ( show != m_isShown ) | |
572 | { | |
573 | m_isShown = show; | |
574 | ||
575 | return TRUE; | |
576 | } | |
577 | else | |
578 | { | |
579 | return FALSE; | |
580 | } | |
581 | } | |
582 | ||
583 | bool wxWindowBase::Enable(bool enable) | |
584 | { | |
585 | if ( enable != m_isEnabled ) | |
586 | { | |
587 | m_isEnabled = enable; | |
588 | ||
589 | return TRUE; | |
590 | } | |
591 | else | |
592 | { | |
593 | return FALSE; | |
594 | } | |
595 | } | |
34636400 VZ |
596 | // ---------------------------------------------------------------------------- |
597 | // RTTI | |
598 | // ---------------------------------------------------------------------------- | |
599 | ||
600 | bool wxWindowBase::IsTopLevel() const | |
601 | { | |
8487f887 | 602 | return FALSE; |
34636400 | 603 | } |
f03fc89f VZ |
604 | |
605 | // ---------------------------------------------------------------------------- | |
606 | // reparenting the window | |
607 | // ---------------------------------------------------------------------------- | |
608 | ||
609 | void wxWindowBase::AddChild(wxWindowBase *child) | |
610 | { | |
223d09f6 | 611 | wxCHECK_RET( child, wxT("can't add a NULL child") ); |
f03fc89f | 612 | |
f6bcfd97 BP |
613 | // this should never happen and it will lead to a crash later if it does |
614 | // because RemoveChild() will remove only one node from the children list | |
615 | // and the other(s) one(s) will be left with dangling pointers in them | |
616 | wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") ); | |
617 | ||
f03fc89f VZ |
618 | GetChildren().Append(child); |
619 | child->SetParent(this); | |
620 | } | |
621 | ||
622 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
623 | { | |
223d09f6 | 624 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); |
f03fc89f VZ |
625 | |
626 | GetChildren().DeleteObject(child); | |
627 | child->SetParent((wxWindow *)NULL); | |
628 | } | |
439b3bf1 | 629 | |
f03fc89f VZ |
630 | bool wxWindowBase::Reparent(wxWindowBase *newParent) |
631 | { | |
632 | wxWindow *oldParent = GetParent(); | |
633 | if ( newParent == oldParent ) | |
634 | { | |
635 | // nothing done | |
636 | return FALSE; | |
637 | } | |
638 | ||
639 | // unlink this window from the existing parent. | |
640 | if ( oldParent ) | |
641 | { | |
642 | oldParent->RemoveChild(this); | |
643 | } | |
644 | else | |
645 | { | |
646 | wxTopLevelWindows.DeleteObject(this); | |
647 | } | |
648 | ||
649 | // add it to the new one | |
650 | if ( newParent ) | |
651 | { | |
652 | newParent->AddChild(this); | |
653 | } | |
654 | else | |
655 | { | |
656 | wxTopLevelWindows.Append(this); | |
657 | } | |
658 | ||
659 | return TRUE; | |
660 | } | |
661 | ||
662 | // ---------------------------------------------------------------------------- | |
663 | // event handler stuff | |
664 | // ---------------------------------------------------------------------------- | |
665 | ||
666 | void wxWindowBase::PushEventHandler(wxEvtHandler *handler) | |
667 | { | |
668 | handler->SetNextHandler(GetEventHandler()); | |
669 | SetEventHandler(handler); | |
670 | } | |
671 | ||
672 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
673 | { | |
674 | wxEvtHandler *handlerA = GetEventHandler(); | |
675 | if ( handlerA ) | |
676 | { | |
677 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
678 | handlerA->SetNextHandler((wxEvtHandler *)NULL); | |
679 | SetEventHandler(handlerB); | |
680 | if ( deleteHandler ) | |
681 | { | |
682 | delete handlerA; | |
683 | handlerA = (wxEvtHandler *)NULL; | |
684 | } | |
685 | } | |
686 | ||
687 | return handlerA; | |
688 | } | |
689 | ||
2e36d5cf VZ |
690 | bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler) |
691 | { | |
692 | wxCHECK_MSG( handler, FALSE, _T("RemoveEventHandler(NULL) called") ); | |
693 | ||
694 | wxEvtHandler *handlerPrev = NULL, | |
695 | *handlerCur = GetEventHandler(); | |
696 | while ( handlerCur ) | |
697 | { | |
698 | wxEvtHandler *handlerNext = handlerCur->GetNextHandler(); | |
699 | ||
700 | if ( handlerCur == handler ) | |
701 | { | |
702 | if ( handlerPrev ) | |
703 | { | |
704 | handlerPrev->SetNextHandler(handlerNext); | |
705 | } | |
706 | else | |
707 | { | |
708 | SetEventHandler(handlerNext); | |
709 | } | |
710 | ||
711 | handler->SetNextHandler(NULL); | |
712 | ||
713 | return TRUE; | |
714 | } | |
715 | ||
716 | handlerPrev = handlerCur; | |
717 | handlerCur = handlerNext; | |
718 | } | |
719 | ||
720 | wxFAIL_MSG( _T("where has the event handler gone?") ); | |
721 | ||
722 | return FALSE; | |
723 | } | |
724 | ||
f03fc89f VZ |
725 | // ---------------------------------------------------------------------------- |
726 | // cursors, fonts &c | |
727 | // ---------------------------------------------------------------------------- | |
728 | ||
729 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) | |
730 | { | |
731 | if ( !colour.Ok() || (colour == m_backgroundColour) ) | |
732 | return FALSE; | |
733 | ||
734 | m_backgroundColour = colour; | |
735 | ||
23895080 VZ |
736 | m_hasBgCol = TRUE; |
737 | ||
f03fc89f VZ |
738 | return TRUE; |
739 | } | |
740 | ||
741 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
742 | { | |
743 | if ( !colour.Ok() || (colour == m_foregroundColour) ) | |
744 | return FALSE; | |
745 | ||
746 | m_foregroundColour = colour; | |
747 | ||
23895080 VZ |
748 | m_hasFgCol = TRUE; |
749 | ||
f03fc89f VZ |
750 | return TRUE; |
751 | } | |
752 | ||
753 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
754 | { | |
8a9c2246 VZ |
755 | // setting an invalid cursor is ok, it means that we don't have any special |
756 | // cursor | |
13588544 | 757 | if ( m_cursor == cursor ) |
f03fc89f VZ |
758 | { |
759 | // no change | |
760 | return FALSE; | |
761 | } | |
762 | ||
8a9c2246 | 763 | m_cursor = cursor; |
f03fc89f VZ |
764 | |
765 | return TRUE; | |
766 | } | |
767 | ||
768 | bool wxWindowBase::SetFont(const wxFont& font) | |
769 | { | |
770 | // don't try to set invalid font, always fall back to the default | |
771 | const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT; | |
772 | ||
8bf30fe9 | 773 | if ( fontOk == m_font ) |
f03fc89f VZ |
774 | { |
775 | // no change | |
776 | return FALSE; | |
777 | } | |
778 | ||
779 | m_font = fontOk; | |
780 | ||
23895080 VZ |
781 | m_hasFont = TRUE; |
782 | ||
f03fc89f VZ |
783 | return TRUE; |
784 | } | |
785 | ||
b95edd47 VZ |
786 | #if wxUSE_PALETTE |
787 | ||
788 | void wxWindowBase::SetPalette(const wxPalette& pal) | |
789 | { | |
790 | m_hasCustomPalette = TRUE; | |
791 | m_palette = pal; | |
792 | ||
793 | // VZ: can anyone explain me what do we do here? | |
794 | wxWindowDC d((wxWindow *) this); | |
795 | d.SetPalette(pal); | |
796 | } | |
797 | ||
798 | wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const | |
799 | { | |
800 | wxWindow *win = (wxWindow *)this; | |
801 | while ( win && !win->HasCustomPalette() ) | |
802 | { | |
803 | win = win->GetParent(); | |
804 | } | |
805 | ||
806 | return win; | |
807 | } | |
808 | ||
809 | #endif // wxUSE_PALETTE | |
810 | ||
789295bf VZ |
811 | #if wxUSE_CARET |
812 | void wxWindowBase::SetCaret(wxCaret *caret) | |
813 | { | |
814 | if ( m_caret ) | |
815 | { | |
816 | delete m_caret; | |
817 | } | |
818 | ||
819 | m_caret = caret; | |
820 | ||
821 | if ( m_caret ) | |
822 | { | |
823 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
223d09f6 | 824 | wxT("caret should be created associated to this window") ); |
789295bf VZ |
825 | } |
826 | } | |
827 | #endif // wxUSE_CARET | |
828 | ||
88ac883a | 829 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
830 | // ---------------------------------------------------------------------------- |
831 | // validators | |
832 | // ---------------------------------------------------------------------------- | |
833 | ||
834 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
835 | { | |
836 | if ( m_windowValidator ) | |
837 | delete m_windowValidator; | |
838 | ||
839 | m_windowValidator = (wxValidator *)validator.Clone(); | |
840 | ||
841 | if ( m_windowValidator ) | |
842 | m_windowValidator->SetWindow(this) ; | |
843 | } | |
88ac883a | 844 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
845 | |
846 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 847 | // update region stuff |
f03fc89f VZ |
848 | // ---------------------------------------------------------------------------- |
849 | ||
1e6feb95 VZ |
850 | wxRect wxWindowBase::GetUpdateClientRect() const |
851 | { | |
852 | wxRegion rgnUpdate = GetUpdateRegion(); | |
853 | rgnUpdate.Intersect(GetClientRect()); | |
854 | wxRect rectUpdate = rgnUpdate.GetBox(); | |
855 | wxPoint ptOrigin = GetClientAreaOrigin(); | |
856 | rectUpdate.x -= ptOrigin.x; | |
857 | rectUpdate.y -= ptOrigin.y; | |
858 | ||
859 | return rectUpdate; | |
860 | } | |
861 | ||
f03fc89f VZ |
862 | bool wxWindowBase::IsExposed(int x, int y) const |
863 | { | |
864 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
865 | } | |
866 | ||
867 | bool wxWindowBase::IsExposed(int x, int y, int w, int h) const | |
868 | { | |
869 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
870 | } | |
871 | ||
872 | // ---------------------------------------------------------------------------- | |
146ba0fe | 873 | // find child window by id or name |
f03fc89f VZ |
874 | // ---------------------------------------------------------------------------- |
875 | ||
876 | wxWindow *wxWindowBase::FindWindow( long id ) | |
877 | { | |
878 | if ( id == m_windowId ) | |
879 | return (wxWindow *)this; | |
880 | ||
881 | wxWindowBase *res = (wxWindow *)NULL; | |
882 | wxWindowList::Node *node; | |
883 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
884 | { | |
885 | wxWindowBase *child = node->GetData(); | |
886 | res = child->FindWindow( id ); | |
887 | } | |
888 | ||
889 | return (wxWindow *)res; | |
890 | } | |
891 | ||
892 | wxWindow *wxWindowBase::FindWindow( const wxString& name ) | |
893 | { | |
894 | if ( name == m_windowName ) | |
895 | return (wxWindow *)this; | |
896 | ||
897 | wxWindowBase *res = (wxWindow *)NULL; | |
898 | wxWindowList::Node *node; | |
899 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
900 | { | |
901 | wxWindow *child = node->GetData(); | |
902 | res = child->FindWindow(name); | |
903 | } | |
904 | ||
905 | return (wxWindow *)res; | |
906 | } | |
907 | ||
146ba0fe VZ |
908 | |
909 | // find any window by id or name or label: If parent is non-NULL, look through | |
910 | // children for a label or title matching the specified string. If NULL, look | |
911 | // through all top-level windows. | |
912 | // | |
913 | // to avoid duplicating code we reuse the same helper function but with | |
914 | // different comparators | |
915 | ||
916 | typedef bool (*wxFindWindowCmp)(const wxWindow *win, | |
917 | const wxString& label, long id); | |
918 | ||
919 | static | |
920 | bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label, | |
921 | long WXUNUSED(id)) | |
922 | { | |
923 | return win->GetLabel() == label; | |
924 | } | |
925 | ||
926 | static | |
927 | bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label, | |
928 | long WXUNUSED(id)) | |
929 | { | |
930 | return win->GetName() == label; | |
931 | } | |
932 | ||
933 | static | |
934 | bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label), | |
935 | long id) | |
936 | { | |
937 | return win->GetId() == id; | |
938 | } | |
939 | ||
940 | // recursive helper for the FindWindowByXXX() functions | |
941 | static | |
942 | wxWindow *wxFindWindowRecursively(const wxWindow *parent, | |
943 | const wxString& label, | |
944 | long id, | |
945 | wxFindWindowCmp cmp) | |
946 | { | |
947 | if ( parent ) | |
948 | { | |
949 | // see if this is the one we're looking for | |
950 | if ( (*cmp)(parent, label, id) ) | |
951 | return (wxWindow *)parent; | |
952 | ||
953 | // It wasn't, so check all its children | |
954 | for ( wxWindowList::Node * node = parent->GetChildren().GetFirst(); | |
955 | node; | |
956 | node = node->GetNext() ) | |
957 | { | |
958 | // recursively check each child | |
959 | wxWindow *win = (wxWindow *)node->GetData(); | |
960 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
961 | if (retwin) | |
962 | return retwin; | |
963 | } | |
964 | } | |
965 | ||
966 | // Not found | |
967 | return NULL; | |
968 | } | |
969 | ||
970 | // helper for FindWindowByXXX() | |
971 | static | |
972 | wxWindow *wxFindWindowHelper(const wxWindow *parent, | |
973 | const wxString& label, | |
974 | long id, | |
975 | wxFindWindowCmp cmp) | |
976 | { | |
977 | if ( parent ) | |
978 | { | |
979 | // just check parent and all its children | |
980 | return wxFindWindowRecursively(parent, label, id, cmp); | |
981 | } | |
982 | ||
983 | // start at very top of wx's windows | |
984 | for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst(); | |
985 | node; | |
986 | node = node->GetNext() ) | |
987 | { | |
988 | // recursively check each window & its children | |
989 | wxWindow *win = node->GetData(); | |
990 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
991 | if (retwin) | |
992 | return retwin; | |
993 | } | |
994 | ||
995 | return NULL; | |
996 | } | |
997 | ||
998 | /* static */ | |
999 | wxWindow * | |
1000 | wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent) | |
1001 | { | |
1002 | return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels); | |
1003 | } | |
1004 | ||
1005 | /* static */ | |
1006 | wxWindow * | |
1007 | wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent) | |
1008 | { | |
1009 | wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames); | |
1010 | ||
1011 | if ( !win ) | |
1012 | { | |
1013 | // fall back to the label | |
1014 | win = FindWindowByLabel(title, parent); | |
1015 | } | |
1016 | ||
1017 | return win; | |
1018 | } | |
1019 | ||
1020 | /* static */ | |
1021 | wxWindow * | |
1022 | wxWindowBase::FindWindowById( long id, const wxWindow* parent ) | |
1023 | { | |
1024 | return wxFindWindowHelper(parent, _T(""), id, wxFindWindowCmpIds); | |
1025 | } | |
1026 | ||
f03fc89f VZ |
1027 | // ---------------------------------------------------------------------------- |
1028 | // dialog oriented functions | |
1029 | // ---------------------------------------------------------------------------- | |
1030 | ||
34636400 | 1031 | void wxWindowBase::MakeModal(bool modal) |
f03fc89f | 1032 | { |
34636400 VZ |
1033 | // Disable all other windows |
1034 | if ( IsTopLevel() ) | |
1035 | { | |
1036 | wxWindowList::Node *node = wxTopLevelWindows.GetFirst(); | |
1037 | while (node) | |
1038 | { | |
1039 | wxWindow *win = node->GetData(); | |
1040 | if (win != this) | |
1041 | win->Enable(!modal); | |
1042 | ||
1043 | node = node->GetNext(); | |
1044 | } | |
1045 | } | |
f03fc89f VZ |
1046 | } |
1047 | ||
1048 | bool wxWindowBase::Validate() | |
1049 | { | |
88ac883a | 1050 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1051 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1052 | ||
f03fc89f VZ |
1053 | wxWindowList::Node *node; |
1054 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1055 | { | |
1056 | wxWindowBase *child = node->GetData(); | |
1057 | wxValidator *validator = child->GetValidator(); | |
dcd6b914 | 1058 | if ( validator && !validator->Validate((wxWindow *)this) ) |
f03fc89f VZ |
1059 | { |
1060 | return FALSE; | |
1061 | } | |
d80cd92a VZ |
1062 | |
1063 | if ( recurse && !child->Validate() ) | |
1064 | { | |
1065 | return FALSE; | |
1066 | } | |
f03fc89f | 1067 | } |
88ac883a | 1068 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1069 | |
1070 | return TRUE; | |
1071 | } | |
1072 | ||
1073 | bool wxWindowBase::TransferDataToWindow() | |
1074 | { | |
88ac883a | 1075 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1076 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1077 | ||
f03fc89f VZ |
1078 | wxWindowList::Node *node; |
1079 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1080 | { | |
1081 | wxWindowBase *child = node->GetData(); | |
1082 | wxValidator *validator = child->GetValidator(); | |
1083 | if ( validator && !validator->TransferToWindow() ) | |
1084 | { | |
d80cd92a VZ |
1085 | wxLogWarning(_("Could not transfer data to window")); |
1086 | wxLog::FlushActive(); | |
f03fc89f VZ |
1087 | |
1088 | return FALSE; | |
1089 | } | |
d80cd92a VZ |
1090 | |
1091 | if ( recurse ) | |
1092 | { | |
a58a12e9 | 1093 | if ( !child->TransferDataToWindow() ) |
d80cd92a VZ |
1094 | { |
1095 | // warning already given | |
1096 | return FALSE; | |
1097 | } | |
1098 | } | |
f03fc89f | 1099 | } |
88ac883a | 1100 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1101 | |
1102 | return TRUE; | |
1103 | } | |
1104 | ||
1105 | bool wxWindowBase::TransferDataFromWindow() | |
1106 | { | |
88ac883a | 1107 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1108 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1109 | ||
f03fc89f VZ |
1110 | wxWindowList::Node *node; |
1111 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
1112 | { | |
1113 | wxWindow *child = node->GetData(); | |
d80cd92a VZ |
1114 | wxValidator *validator = child->GetValidator(); |
1115 | if ( validator && !validator->TransferFromWindow() ) | |
f03fc89f | 1116 | { |
d80cd92a VZ |
1117 | // nop warning here because the application is supposed to give |
1118 | // one itself - we don't know here what might have gone wrongly | |
1119 | ||
f03fc89f VZ |
1120 | return FALSE; |
1121 | } | |
d80cd92a VZ |
1122 | |
1123 | if ( recurse ) | |
1124 | { | |
a58a12e9 | 1125 | if ( !child->TransferDataFromWindow() ) |
d80cd92a VZ |
1126 | { |
1127 | // warning already given | |
1128 | return FALSE; | |
1129 | } | |
1130 | } | |
f03fc89f | 1131 | } |
88ac883a | 1132 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1133 | |
1134 | return TRUE; | |
1135 | } | |
1136 | ||
1137 | void wxWindowBase::InitDialog() | |
1138 | { | |
1139 | wxInitDialogEvent event(GetId()); | |
1140 | event.SetEventObject( this ); | |
1141 | GetEventHandler()->ProcessEvent(event); | |
1142 | } | |
1143 | ||
1144 | // ---------------------------------------------------------------------------- | |
bd83cb56 VZ |
1145 | // context-sensitive help support |
1146 | // ---------------------------------------------------------------------------- | |
1147 | ||
1148 | #if wxUSE_HELP | |
1149 | ||
1150 | // associate this help text with this window | |
1151 | void wxWindowBase::SetHelpText(const wxString& text) | |
1152 | { | |
1153 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1154 | if ( helpProvider ) | |
1155 | { | |
1156 | helpProvider->AddHelp(this, text); | |
1157 | } | |
1158 | } | |
1159 | ||
1160 | // associate this help text with all windows with the same id as this | |
1161 | // one | |
1162 | void wxWindowBase::SetHelpTextForId(const wxString& text) | |
1163 | { | |
1164 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1165 | if ( helpProvider ) | |
1166 | { | |
1167 | helpProvider->AddHelp(GetId(), text); | |
1168 | } | |
1169 | } | |
1170 | ||
1171 | // get the help string associated with this window (may be empty) | |
1172 | wxString wxWindowBase::GetHelpText() const | |
1173 | { | |
1174 | wxString text; | |
1175 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1176 | if ( helpProvider ) | |
1177 | { | |
1178 | text = helpProvider->GetHelp(this); | |
1179 | } | |
1180 | ||
1181 | return text; | |
1182 | } | |
1183 | ||
1184 | // show help for this window | |
1185 | void wxWindowBase::OnHelp(wxHelpEvent& event) | |
1186 | { | |
1187 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1188 | if ( helpProvider ) | |
1189 | { | |
1190 | if ( helpProvider->ShowHelp(this) ) | |
1191 | { | |
1192 | // skip the event.Skip() below | |
1193 | return; | |
1194 | } | |
1195 | } | |
1196 | ||
1197 | event.Skip(); | |
1198 | } | |
1199 | ||
1200 | #endif // wxUSE_HELP | |
1201 | ||
1202 | // ---------------------------------------------------------------------------- | |
574c939e | 1203 | // tooltipsroot.Replace("\\", "/"); |
f03fc89f VZ |
1204 | // ---------------------------------------------------------------------------- |
1205 | ||
1206 | #if wxUSE_TOOLTIPS | |
1207 | ||
1208 | void wxWindowBase::SetToolTip( const wxString &tip ) | |
1209 | { | |
1210 | // don't create the new tooltip if we already have one | |
1211 | if ( m_tooltip ) | |
1212 | { | |
1213 | m_tooltip->SetTip( tip ); | |
1214 | } | |
1215 | else | |
1216 | { | |
1217 | SetToolTip( new wxToolTip( tip ) ); | |
1218 | } | |
1219 | ||
1220 | // setting empty tooltip text does not remove the tooltip any more - use | |
1221 | // SetToolTip((wxToolTip *)NULL) for this | |
1222 | } | |
1223 | ||
1224 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
1225 | { | |
1226 | if ( m_tooltip ) | |
1227 | delete m_tooltip; | |
1228 | ||
1229 | m_tooltip = tooltip; | |
1230 | } | |
1231 | ||
1232 | #endif // wxUSE_TOOLTIPS | |
1233 | ||
1234 | // ---------------------------------------------------------------------------- | |
1235 | // constraints and sizers | |
1236 | // ---------------------------------------------------------------------------- | |
1237 | ||
1238 | #if wxUSE_CONSTRAINTS | |
1239 | ||
1240 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
1241 | { | |
1242 | if ( m_constraints ) | |
1243 | { | |
1244 | UnsetConstraints(m_constraints); | |
1245 | delete m_constraints; | |
1246 | } | |
1247 | m_constraints = constraints; | |
1248 | if ( m_constraints ) | |
1249 | { | |
1250 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1251 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
1252 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
1253 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
1254 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
1255 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
1256 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
1257 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
1258 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
1259 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
1260 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
1261 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
1262 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
1263 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
1264 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
1265 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
1266 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | // This removes any dangling pointers to this window in other windows' | |
1271 | // constraintsInvolvedIn lists. | |
1272 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
1273 | { | |
1274 | if ( c ) | |
1275 | { | |
1276 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1277 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
1278 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1279 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
1280 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
1281 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
1282 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
1283 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
1284 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
1285 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
1286 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
1287 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
1288 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
1289 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
1290 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
1291 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
1292 | } | |
1293 | } | |
1294 | ||
1295 | // Back-pointer to other windows we're involved with, so if we delete this | |
1296 | // window, we must delete any constraints we're involved with. | |
1297 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
1298 | { | |
1299 | if ( !m_constraintsInvolvedIn ) | |
1300 | m_constraintsInvolvedIn = new wxWindowList; | |
1301 | if ( !m_constraintsInvolvedIn->Find(otherWin) ) | |
1302 | m_constraintsInvolvedIn->Append(otherWin); | |
1303 | } | |
1304 | ||
1305 | // REMOVE back-pointer to other windows we're involved with. | |
1306 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
1307 | { | |
1308 | if ( m_constraintsInvolvedIn ) | |
1309 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
1310 | } | |
1311 | ||
1312 | // Reset any constraints that mention this window | |
1313 | void wxWindowBase::DeleteRelatedConstraints() | |
1314 | { | |
1315 | if ( m_constraintsInvolvedIn ) | |
1316 | { | |
1317 | wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst(); | |
1318 | while (node) | |
1319 | { | |
1320 | wxWindow *win = node->GetData(); | |
1321 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1322 | ||
1323 | // Reset any constraints involving this window | |
1324 | if ( constr ) | |
1325 | { | |
1326 | constr->left.ResetIfWin(this); | |
1327 | constr->top.ResetIfWin(this); | |
1328 | constr->right.ResetIfWin(this); | |
1329 | constr->bottom.ResetIfWin(this); | |
1330 | constr->width.ResetIfWin(this); | |
1331 | constr->height.ResetIfWin(this); | |
1332 | constr->centreX.ResetIfWin(this); | |
1333 | constr->centreY.ResetIfWin(this); | |
1334 | } | |
1335 | ||
1336 | wxWindowList::Node *next = node->GetNext(); | |
1337 | delete node; | |
1338 | node = next; | |
1339 | } | |
1340 | ||
1341 | delete m_constraintsInvolvedIn; | |
1342 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
1343 | } | |
1344 | } | |
461e93f9 | 1345 | #endif |
f03fc89f | 1346 | |
3aa5d532 | 1347 | void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld) |
f03fc89f | 1348 | { |
3aa5d532 | 1349 | if (m_windowSizer && deleteOld) delete m_windowSizer; |
3417c2cd | 1350 | |
f03fc89f | 1351 | m_windowSizer = sizer; |
566d84a7 RL |
1352 | |
1353 | SetAutoLayout( sizer != 0 ); | |
1354 | } | |
1355 | ||
1356 | void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) | |
1357 | { | |
1358 | SetSizer( sizer, deleteOld ); | |
1359 | sizer->SetSizeHints( (wxWindow*) this ); | |
f03fc89f VZ |
1360 | } |
1361 | ||
1362 | bool wxWindowBase::Layout() | |
1363 | { | |
3417c2cd | 1364 | // If there is a sizer, use it instead of the constraints |
f03fc89f VZ |
1365 | if ( GetSizer() ) |
1366 | { | |
f1df0927 | 1367 | int w, h; |
566d84a7 | 1368 | GetVirtualSize(&w, &h); |
3417c2cd | 1369 | GetSizer()->SetDimension( 0, 0, w, h ); |
f03fc89f | 1370 | } |
461e93f9 | 1371 | #if wxUSE_CONSTRAINTS |
f1df0927 | 1372 | else |
f03fc89f | 1373 | { |
4b7f2165 VZ |
1374 | wxLayoutConstraints *constr = GetConstraints(); |
1375 | bool wasOk = constr && constr->AreSatisfied(); | |
1376 | ||
f1df0927 | 1377 | ResetConstraints(); // Mark all constraints as unevaluated |
4b7f2165 VZ |
1378 | |
1379 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
1380 | // own constraints will never be satisfied any more unless we do it | |
1381 | // here | |
1382 | if ( wasOk ) | |
1383 | { | |
1384 | int noChanges = 1; | |
1385 | while ( noChanges > 0 ) | |
1386 | { | |
1387 | constr->SatisfyConstraints(this, &noChanges); | |
1388 | } | |
1389 | } | |
1390 | ||
1391 | DoPhase(1); // Layout children | |
1392 | DoPhase(2); // Layout grand children | |
f1df0927 | 1393 | SetConstraintSizes(); // Recursively set the real window sizes |
f03fc89f | 1394 | } |
461e93f9 | 1395 | #endif |
5d4b632b | 1396 | |
f03fc89f VZ |
1397 | return TRUE; |
1398 | } | |
1399 | ||
461e93f9 | 1400 | #if wxUSE_CONSTRAINTS |
f03fc89f VZ |
1401 | // Do a phase of evaluating constraints: the default behaviour. wxSizers may |
1402 | // do a similar thing, but also impose their own 'constraints' and order the | |
1403 | // evaluation differently. | |
1404 | bool wxWindowBase::LayoutPhase1(int *noChanges) | |
1405 | { | |
1406 | wxLayoutConstraints *constr = GetConstraints(); | |
1407 | if ( constr ) | |
1408 | { | |
1409 | return constr->SatisfyConstraints(this, noChanges); | |
1410 | } | |
1411 | else | |
1412 | return TRUE; | |
1413 | } | |
1414 | ||
1415 | bool wxWindowBase::LayoutPhase2(int *noChanges) | |
1416 | { | |
1417 | *noChanges = 0; | |
1418 | ||
1419 | // Layout children | |
1420 | DoPhase(1); | |
1421 | DoPhase(2); | |
1422 | return TRUE; | |
1423 | } | |
1424 | ||
1425 | // Do a phase of evaluating child constraints | |
1426 | bool wxWindowBase::DoPhase(int phase) | |
1427 | { | |
1428 | int noIterations = 0; | |
1429 | int maxIterations = 500; | |
1430 | int noChanges = 1; | |
1431 | int noFailures = 0; | |
1432 | wxWindowList succeeded; | |
1433 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
1434 | { | |
1435 | noChanges = 0; | |
1436 | noFailures = 0; | |
1437 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1438 | while (node) | |
1439 | { | |
1440 | wxWindow *child = node->GetData(); | |
34636400 | 1441 | if ( !child->IsTopLevel() ) |
f03fc89f VZ |
1442 | { |
1443 | wxLayoutConstraints *constr = child->GetConstraints(); | |
1444 | if ( constr ) | |
1445 | { | |
1446 | if ( !succeeded.Find(child) ) | |
1447 | { | |
1448 | int tempNoChanges = 0; | |
1449 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
1450 | noChanges += tempNoChanges; | |
1451 | if ( success ) | |
1452 | { | |
1453 | succeeded.Append(child); | |
1454 | } | |
1455 | } | |
1456 | } | |
1457 | } | |
1458 | node = node->GetNext(); | |
1459 | } | |
1460 | ||
1461 | noIterations++; | |
1462 | } | |
1463 | ||
1464 | return TRUE; | |
1465 | } | |
1466 | ||
1467 | void wxWindowBase::ResetConstraints() | |
1468 | { | |
1469 | wxLayoutConstraints *constr = GetConstraints(); | |
1470 | if ( constr ) | |
1471 | { | |
1472 | constr->left.SetDone(FALSE); | |
1473 | constr->top.SetDone(FALSE); | |
1474 | constr->right.SetDone(FALSE); | |
1475 | constr->bottom.SetDone(FALSE); | |
1476 | constr->width.SetDone(FALSE); | |
1477 | constr->height.SetDone(FALSE); | |
1478 | constr->centreX.SetDone(FALSE); | |
1479 | constr->centreY.SetDone(FALSE); | |
1480 | } | |
f1df0927 | 1481 | |
f03fc89f VZ |
1482 | wxWindowList::Node *node = GetChildren().GetFirst(); |
1483 | while (node) | |
1484 | { | |
1485 | wxWindow *win = node->GetData(); | |
34636400 | 1486 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
1487 | win->ResetConstraints(); |
1488 | node = node->GetNext(); | |
1489 | } | |
1490 | } | |
1491 | ||
1492 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
1493 | // and setting the real values. | |
1494 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
1495 | { | |
1496 | wxLayoutConstraints *constr = GetConstraints(); | |
4b7f2165 | 1497 | if ( constr && constr->AreSatisfied() ) |
f03fc89f VZ |
1498 | { |
1499 | int x = constr->left.GetValue(); | |
1500 | int y = constr->top.GetValue(); | |
1501 | int w = constr->width.GetValue(); | |
1502 | int h = constr->height.GetValue(); | |
1503 | ||
f03fc89f | 1504 | if ( (constr->width.GetRelationship() != wxAsIs ) || |
3417c2cd | 1505 | (constr->height.GetRelationship() != wxAsIs) ) |
f03fc89f | 1506 | { |
3417c2cd | 1507 | SetSize(x, y, w, h); |
f03fc89f VZ |
1508 | } |
1509 | else | |
1510 | { | |
3417c2cd RR |
1511 | // If we don't want to resize this window, just move it... |
1512 | Move(x, y); | |
f03fc89f VZ |
1513 | } |
1514 | } | |
1515 | else if ( constr ) | |
1516 | { | |
4b7f2165 | 1517 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), |
f1df0927 | 1518 | GetClassInfo()->GetClassName(), |
4b7f2165 | 1519 | GetName().c_str()); |
f03fc89f VZ |
1520 | } |
1521 | ||
1522 | if ( recurse ) | |
1523 | { | |
1524 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1525 | while (node) | |
1526 | { | |
1527 | wxWindow *win = node->GetData(); | |
e2f9212c | 1528 | if ( !win->IsTopLevel() && win->GetConstraints() ) |
f03fc89f VZ |
1529 | win->SetConstraintSizes(); |
1530 | node = node->GetNext(); | |
1531 | } | |
1532 | } | |
1533 | } | |
1534 | ||
f03fc89f VZ |
1535 | // Only set the size/position of the constraint (if any) |
1536 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
1537 | { | |
1538 | wxLayoutConstraints *constr = GetConstraints(); | |
1539 | if ( constr ) | |
1540 | { | |
1541 | if ( x != -1 ) | |
1542 | { | |
1543 | constr->left.SetValue(x); | |
1544 | constr->left.SetDone(TRUE); | |
1545 | } | |
1546 | if ( y != -1 ) | |
1547 | { | |
1548 | constr->top.SetValue(y); | |
1549 | constr->top.SetDone(TRUE); | |
1550 | } | |
1551 | if ( w != -1 ) | |
1552 | { | |
1553 | constr->width.SetValue(w); | |
1554 | constr->width.SetDone(TRUE); | |
1555 | } | |
1556 | if ( h != -1 ) | |
1557 | { | |
1558 | constr->height.SetValue(h); | |
1559 | constr->height.SetDone(TRUE); | |
1560 | } | |
1561 | } | |
1562 | } | |
1563 | ||
1564 | void wxWindowBase::MoveConstraint(int x, int y) | |
1565 | { | |
1566 | wxLayoutConstraints *constr = GetConstraints(); | |
1567 | if ( constr ) | |
1568 | { | |
1569 | if ( x != -1 ) | |
1570 | { | |
1571 | constr->left.SetValue(x); | |
1572 | constr->left.SetDone(TRUE); | |
1573 | } | |
1574 | if ( y != -1 ) | |
1575 | { | |
1576 | constr->top.SetValue(y); | |
1577 | constr->top.SetDone(TRUE); | |
1578 | } | |
1579 | } | |
1580 | } | |
1581 | ||
1582 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
1583 | { | |
1584 | wxLayoutConstraints *constr = GetConstraints(); | |
1585 | if ( constr ) | |
1586 | { | |
1587 | *w = constr->width.GetValue(); | |
1588 | *h = constr->height.GetValue(); | |
1589 | } | |
1590 | else | |
1591 | GetSize(w, h); | |
1592 | } | |
1593 | ||
1594 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
1595 | { | |
1596 | wxLayoutConstraints *constr = GetConstraints(); | |
1597 | if ( constr ) | |
1598 | { | |
1599 | *w = constr->width.GetValue(); | |
1600 | *h = constr->height.GetValue(); | |
1601 | } | |
1602 | else | |
1603 | GetClientSize(w, h); | |
1604 | } | |
1605 | ||
461e93f9 JS |
1606 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const |
1607 | { | |
1608 | wxLayoutConstraints *constr = GetConstraints(); | |
1609 | if ( constr ) | |
1610 | { | |
1611 | *x = constr->left.GetValue(); | |
1612 | *y = constr->top.GetValue(); | |
1613 | } | |
1614 | else | |
1615 | GetPosition(x, y); | |
1616 | } | |
1617 | ||
1618 | #endif // wxUSE_CONSTRAINTS | |
1619 | ||
20a1eea1 | 1620 | void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const |
a200c35e VS |
1621 | { |
1622 | // don't do it for the dialogs/frames - they float independently of their | |
1623 | // parent | |
1624 | if ( !IsTopLevel() ) | |
1625 | { | |
1626 | wxWindow *parent = GetParent(); | |
1627 | if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent ) | |
1628 | { | |
1629 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1630 | x += pt.x; | |
1631 | y += pt.y; | |
1632 | } | |
1633 | } | |
1634 | } | |
1635 | ||
f03fc89f VZ |
1636 | // ---------------------------------------------------------------------------- |
1637 | // do Update UI processing for child controls | |
1638 | // ---------------------------------------------------------------------------- | |
7ec1983b VZ |
1639 | |
1640 | // TODO: should this be implemented for the child window rather | |
1641 | // than the parent? Then you can override it e.g. for wxCheckBox | |
1642 | // to do the Right Thing rather than having to assume a fixed number | |
1643 | // of control classes. | |
f03fc89f | 1644 | void wxWindowBase::UpdateWindowUI() |
7ec1983b | 1645 | { |
1e6feb95 | 1646 | #if wxUSE_CONTROLS |
26bf1ce0 VZ |
1647 | wxUpdateUIEvent event(GetId()); |
1648 | event.m_eventObject = this; | |
1649 | ||
1650 | if ( GetEventHandler()->ProcessEvent(event) ) | |
7ec1983b | 1651 | { |
26bf1ce0 VZ |
1652 | if ( event.GetSetEnabled() ) |
1653 | Enable(event.GetEnabled()); | |
7ec1983b | 1654 | |
26bf1ce0 | 1655 | if ( event.GetSetText() ) |
f03fc89f | 1656 | { |
f7637829 | 1657 | wxControl *control = wxDynamicCastThis(wxControl); |
26bf1ce0 | 1658 | if ( control ) |
34636400 | 1659 | { |
1e6feb95 | 1660 | #if wxUSE_TEXTCTRL |
26bf1ce0 VZ |
1661 | wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl); |
1662 | if ( text ) | |
1663 | text->SetValue(event.GetText()); | |
1664 | else | |
1e6feb95 | 1665 | #endif // wxUSE_TEXTCTRL |
34636400 VZ |
1666 | control->SetLabel(event.GetText()); |
1667 | } | |
26bf1ce0 | 1668 | } |
f03fc89f | 1669 | |
88ac883a | 1670 | #if wxUSE_CHECKBOX |
f7637829 | 1671 | wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox); |
26bf1ce0 VZ |
1672 | if ( checkbox ) |
1673 | { | |
1674 | if ( event.GetSetChecked() ) | |
1675 | checkbox->SetValue(event.GetChecked()); | |
1676 | } | |
88ac883a VZ |
1677 | #endif // wxUSE_CHECKBOX |
1678 | ||
b3402d0d | 1679 | #if wxUSE_RADIOBTN |
f7637829 | 1680 | wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton); |
26bf1ce0 VZ |
1681 | if ( radiobtn ) |
1682 | { | |
1683 | if ( event.GetSetChecked() ) | |
1684 | radiobtn->SetValue(event.GetChecked()); | |
f03fc89f | 1685 | } |
b3402d0d | 1686 | #endif // wxUSE_RADIOBTN |
7ec1983b | 1687 | } |
1e6feb95 | 1688 | #endif // wxUSE_CONTROLS |
7ec1983b | 1689 | } |
fd71308f | 1690 | |
f03fc89f VZ |
1691 | // ---------------------------------------------------------------------------- |
1692 | // dialog units translations | |
1693 | // ---------------------------------------------------------------------------- | |
1694 | ||
1695 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) | |
fd71308f JS |
1696 | { |
1697 | int charWidth = GetCharWidth(); | |
1698 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1699 | wxPoint pt2(-1, -1); |
1700 | if (pt.x != -1) | |
1701 | pt2.x = (int) ((pt.x * 4) / charWidth) ; | |
1702 | if (pt.y != -1) | |
1703 | pt2.y = (int) ((pt.y * 8) / charHeight) ; | |
fd71308f JS |
1704 | |
1705 | return pt2; | |
1706 | } | |
1707 | ||
f03fc89f | 1708 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) |
fd71308f JS |
1709 | { |
1710 | int charWidth = GetCharWidth(); | |
1711 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1712 | wxPoint pt2(-1, -1); |
1713 | if (pt.x != -1) | |
1714 | pt2.x = (int) ((pt.x * charWidth) / 4) ; | |
1715 | if (pt.y != -1) | |
1716 | pt2.y = (int) ((pt.y * charHeight) / 8) ; | |
fd71308f JS |
1717 | |
1718 | return pt2; | |
1719 | } | |
1720 | ||
f03fc89f VZ |
1721 | // ---------------------------------------------------------------------------- |
1722 | // event handlers | |
1723 | // ---------------------------------------------------------------------------- | |
1724 | ||
1725 | // propagate the colour change event to the subwindows | |
1726 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1727 | { | |
1728 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1729 | while ( node ) | |
1730 | { | |
1731 | // Only propagate to non-top-level windows | |
1732 | wxWindow *win = node->GetData(); | |
1733 | if ( !win->IsTopLevel() ) | |
1734 | { | |
1735 | wxSysColourChangedEvent event2; | |
1736 | event.m_eventObject = win; | |
1737 | win->GetEventHandler()->ProcessEvent(event2); | |
1738 | } | |
1739 | ||
1740 | node = node->GetNext(); | |
1741 | } | |
1742 | } | |
1743 | ||
1744 | // the default action is to populate dialog with data when it's created | |
1745 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) | |
1746 | { | |
1747 | TransferDataToWindow(); | |
1748 | } | |
1749 | ||
a02dc3e3 VZ |
1750 | // process Ctrl-Alt-mclick |
1751 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) | |
1752 | { | |
1e6feb95 | 1753 | #if wxUSE_MSGDLG |
a02dc3e3 VZ |
1754 | if ( event.ControlDown() && event.AltDown() ) |
1755 | { | |
1756 | // don't translate these strings | |
1757 | wxString port; | |
af3062a8 VZ |
1758 | |
1759 | #ifdef __WXUNIVERSAL__ | |
1760 | port = _T("Univ/"); | |
1761 | #endif // __WXUNIVERSAL__ | |
1762 | ||
a02dc3e3 VZ |
1763 | switch ( wxGetOsVersion() ) |
1764 | { | |
1765 | case wxMOTIF_X: port = _T("Motif"); break; | |
ff8fda36 GD |
1766 | case wxMAC: |
1767 | case wxMAC_DARWIN: port = _T("Mac"); break; | |
a02dc3e3 VZ |
1768 | case wxBEOS: port = _T("BeOS"); break; |
1769 | case wxGTK: | |
1770 | case wxGTK_WIN32: | |
1771 | case wxGTK_OS2: | |
1772 | case wxGTK_BEOS: port = _T("GTK"); break; | |
1773 | case wxWINDOWS: | |
1774 | case wxPENWINDOWS: | |
1775 | case wxWINDOWS_NT: | |
1776 | case wxWIN32S: | |
1777 | case wxWIN95: | |
1778 | case wxWIN386: port = _T("MS Windows"); break; | |
1779 | case wxMGL_UNIX: | |
1780 | case wxMGL_X: | |
1781 | case wxMGL_WIN32: | |
1782 | case wxMGL_OS2: port = _T("MGL"); break; | |
1783 | case wxWINDOWS_OS2: | |
1784 | case wxOS2_PM: port = _T("OS/2"); break; | |
1785 | default: port = _T("unknown"); break; | |
1786 | } | |
1787 | ||
1788 | wxMessageBox(wxString::Format( | |
1789 | _T( | |
af3062a8 | 1790 | " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team" |
a02dc3e3 VZ |
1791 | ), |
1792 | port.c_str(), | |
1793 | wxMAJOR_VERSION, | |
1794 | wxMINOR_VERSION, | |
1795 | wxRELEASE_NUMBER, | |
3f562374 VZ |
1796 | #if wxUSE_UNICODE |
1797 | L" (Unicode)", | |
1798 | #else | |
1799 | "", | |
1800 | #endif | |
1801 | __TDATE__, | |
1802 | __TTIME__ | |
a02dc3e3 VZ |
1803 | ), |
1804 | _T("wxWindows information"), | |
1805 | wxICON_INFORMATION | wxOK, | |
1806 | (wxWindow *)this); | |
1807 | } | |
1808 | else | |
1e6feb95 | 1809 | #endif // wxUSE_MSGDLG |
a02dc3e3 VZ |
1810 | { |
1811 | event.Skip(); | |
1812 | } | |
1813 | } | |
1814 | ||
f03fc89f VZ |
1815 | // ---------------------------------------------------------------------------- |
1816 | // list classes implementation | |
1817 | // ---------------------------------------------------------------------------- | |
1818 | ||
1819 | void wxWindowListNode::DeleteData() | |
1820 | { | |
1821 | delete (wxWindow *)GetData(); | |
1822 | } | |
1823 | ||
1e6feb95 VZ |
1824 | // ---------------------------------------------------------------------------- |
1825 | // borders | |
1826 | // ---------------------------------------------------------------------------- | |
1827 | ||
1828 | wxBorder wxWindowBase::GetBorder() const | |
1829 | { | |
1830 | wxBorder border = (wxBorder)(m_windowStyle & wxBORDER_MASK); | |
1831 | if ( border == wxBORDER_DEFAULT ) | |
1832 | { | |
1833 | border = GetDefaultBorder(); | |
1834 | } | |
1835 | ||
1836 | return border; | |
1837 | } | |
1838 | ||
1839 | wxBorder wxWindowBase::GetDefaultBorder() const | |
1840 | { | |
1841 | return wxBORDER_NONE; | |
1842 | } | |
1843 | ||
1844 | // ---------------------------------------------------------------------------- | |
1845 | // hit testing | |
1846 | // ---------------------------------------------------------------------------- | |
1847 | ||
1848 | wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const | |
1849 | { | |
1850 | // here we just check if the point is inside the window or not | |
1851 | ||
1852 | // check the top and left border first | |
1853 | bool outside = x < 0 || y < 0; | |
1854 | if ( !outside ) | |
1855 | { | |
1856 | // check the right and bottom borders too | |
1857 | wxSize size = GetSize(); | |
1858 | outside = x >= size.x || y >= size.y; | |
1859 | } | |
1860 | ||
1861 | return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE; | |
1862 | } | |
1863 | ||
94633ad9 VZ |
1864 | // ---------------------------------------------------------------------------- |
1865 | // mouse capture | |
1866 | // ---------------------------------------------------------------------------- | |
1867 | ||
1868 | struct WXDLLEXPORT wxWindowNext | |
1869 | { | |
1870 | wxWindow *win; | |
1871 | wxWindowNext *next; | |
786646f3 | 1872 | } *wxWindowBase::ms_winCaptureNext = NULL; |
94633ad9 | 1873 | |
a83e1475 | 1874 | void wxWindowBase::CaptureMouse() |
94633ad9 VZ |
1875 | { |
1876 | wxLogTrace(_T("mousecapture"), _T("CaptureMouse(0x%08x)"), this); | |
45e0dc94 | 1877 | |
94633ad9 VZ |
1878 | wxWindow *winOld = GetCapture(); |
1879 | if ( winOld ) | |
1880 | { | |
df2f507b | 1881 | ((wxWindowBase*) winOld)->DoReleaseMouse(); |
3edb5d30 | 1882 | |
94633ad9 VZ |
1883 | // save it on stack |
1884 | wxWindowNext *item = new wxWindowNext; | |
1885 | item->win = winOld; | |
1886 | item->next = ms_winCaptureNext; | |
1887 | ms_winCaptureNext = item; | |
1888 | } | |
1889 | //else: no mouse capture to save | |
1890 | ||
1891 | DoCaptureMouse(); | |
1892 | } | |
1893 | ||
a83e1475 | 1894 | void wxWindowBase::ReleaseMouse() |
94633ad9 | 1895 | { |
349d1942 VS |
1896 | wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(0x%08x)"), this); |
1897 | ||
a7b09001 VS |
1898 | wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") ) |
1899 | ||
94633ad9 VZ |
1900 | DoReleaseMouse(); |
1901 | ||
1902 | if ( ms_winCaptureNext ) | |
1903 | { | |
44f8caa7 | 1904 | ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse(); |
3edb5d30 | 1905 | |
94633ad9 VZ |
1906 | wxWindowNext *item = ms_winCaptureNext; |
1907 | ms_winCaptureNext = item->next; | |
1908 | delete item; | |
1909 | } | |
1910 | //else: stack is empty, no previous capture | |
1911 | ||
1912 | wxLogTrace(_T("mousecapture"), | |
1913 | _T("After ReleaseMouse() mouse is captured by 0x%08x"), | |
1914 | GetCapture()); | |
1915 | } | |
1916 | ||
33b494d6 VZ |
1917 | // ---------------------------------------------------------------------------- |
1918 | // global functions | |
1919 | // ---------------------------------------------------------------------------- | |
1920 | ||
1921 | wxWindow* wxGetTopLevelParent(wxWindow *win) | |
1922 | { | |
1923 | while ( win && !win->IsTopLevel() ) | |
1924 | win = win->GetParent(); | |
1925 | ||
1926 | return win; | |
1927 | } | |
1928 |