]>
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" | |
38 | #include "wx/checkbox.h" | |
39 | #include "wx/radiobut.h" | |
26bf1ce0 | 40 | #include "wx/textctrl.h" |
f03fc89f VZ |
41 | #include "wx/settings.h" |
42 | #include "wx/dialog.h" | |
a02dc3e3 | 43 | #include "wx/msgdlg.h" |
f03fc89f VZ |
44 | #endif //WX_PRECOMP |
45 | ||
46 | #if wxUSE_CONSTRAINTS | |
47 | #include "wx/layout.h" | |
3417c2cd | 48 | #include "wx/sizer.h" |
f03fc89f VZ |
49 | #endif // wxUSE_CONSTRAINTS |
50 | ||
51 | #if wxUSE_DRAG_AND_DROP | |
52 | #include "wx/dnd.h" | |
53 | #endif // wxUSE_DRAG_AND_DROP | |
54 | ||
55 | #if wxUSE_TOOLTIPS | |
56 | #include "wx/tooltip.h" | |
57 | #endif // wxUSE_TOOLTIPS | |
58 | ||
789295bf VZ |
59 | #if wxUSE_CARET |
60 | #include "wx/caret.h" | |
61 | #endif // wxUSE_CARET | |
62 | ||
f03fc89f VZ |
63 | // ---------------------------------------------------------------------------- |
64 | // static data | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
42e69d6b | 67 | int wxWindowBase::ms_lastControlId = -200; |
f03fc89f VZ |
68 | |
69 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
70 | ||
71 | // ---------------------------------------------------------------------------- | |
72 | // event table | |
73 | // ---------------------------------------------------------------------------- | |
74 | ||
75 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
76 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
77 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
a02dc3e3 | 78 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) |
f03fc89f VZ |
79 | END_EVENT_TABLE() |
80 | ||
81 | // ============================================================================ | |
82 | // implementation of the common functionality of the wxWindow class | |
83 | // ============================================================================ | |
84 | ||
85 | // ---------------------------------------------------------------------------- | |
86 | // initialization | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | // the default initialization | |
90 | void wxWindowBase::InitBase() | |
91 | { | |
92 | // no window yet, no parent nor children | |
f03fc89f VZ |
93 | m_parent = (wxWindow *)NULL; |
94 | m_windowId = -1; | |
95 | m_children.DeleteContents( FALSE ); // don't auto delete node data | |
96 | ||
97 | // no constraints on the minimal window size | |
98 | m_minWidth = | |
99 | m_minHeight = | |
100 | m_maxWidth = | |
101 | m_maxHeight = -1; | |
102 | ||
103 | // window is created enabled but it's not visible yet | |
104 | m_isShown = FALSE; | |
105 | m_isEnabled = TRUE; | |
106 | ||
8d99be5f | 107 | // no client data (yet) |
f03fc89f | 108 | m_clientData = NULL; |
8d99be5f | 109 | m_clientDataType = ClientData_None; |
f03fc89f VZ |
110 | |
111 | // the default event handler is just this window | |
112 | m_eventHandler = this; | |
113 | ||
88ac883a | 114 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
115 | // no validator |
116 | m_windowValidator = (wxValidator *) NULL; | |
88ac883a | 117 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
118 | |
119 | // use the system default colours | |
120 | wxSystemSettings settings; | |
121 | ||
122 | m_backgroundColour = settings.GetSystemColour(wxSYS_COLOUR_BTNFACE); | |
f6e4e9ea JS |
123 | // m_foregroundColour = *wxBLACK; // TODO take this from sys settings too? |
124 | m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); | |
125 | ||
db434467 | 126 | #if !defined(__WXMAC__) && !defined(__WXGTK__) |
f03fc89f | 127 | m_font = *wxSWISS_FONT; // and this? |
7c74e7fe | 128 | #else |
f855d4cb | 129 | m_font = settings.GetSystemFont(wxSYS_DEFAULT_GUI_FONT); |
7c74e7fe | 130 | #endif |
d80cd92a | 131 | |
f03fc89f | 132 | // no style bits |
d80cd92a | 133 | m_exStyle = |
f03fc89f VZ |
134 | m_windowStyle = 0; |
135 | ||
136 | // an optimization for the event processing: checking this flag is much | |
137 | // faster than using IsKindOf(CLASSINFO(wxWindow)) | |
138 | m_isWindow = TRUE; | |
139 | ||
140 | #if wxUSE_CONSTRAINTS | |
141 | // no constraints whatsoever | |
142 | m_constraints = (wxLayoutConstraints *) NULL; | |
143 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
144 | m_windowSizer = (wxSizer *) NULL; | |
f03fc89f VZ |
145 | m_autoLayout = FALSE; |
146 | #endif // wxUSE_CONSTRAINTS | |
147 | ||
148 | #if wxUSE_DRAG_AND_DROP | |
149 | m_dropTarget = (wxDropTarget *)NULL; | |
150 | #endif // wxUSE_DRAG_AND_DROP | |
151 | ||
152 | #if wxUSE_TOOLTIPS | |
153 | m_tooltip = (wxToolTip *)NULL; | |
154 | #endif // wxUSE_TOOLTIPS | |
789295bf VZ |
155 | |
156 | #if wxUSE_CARET | |
157 | m_caret = (wxCaret *)NULL; | |
158 | #endif // wxUSE_CARET | |
f03fc89f VZ |
159 | } |
160 | ||
161 | // common part of window creation process | |
162 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
163 | wxWindowID id, | |
74e3313b VZ |
164 | const wxPoint& WXUNUSED(pos), |
165 | const wxSize& WXUNUSED(size), | |
f03fc89f | 166 | long style, |
8d99be5f | 167 | const wxValidator& validator, |
f03fc89f VZ |
168 | const wxString& name) |
169 | { | |
170 | // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other | |
171 | // member variables - check that it has been called (will catch the case | |
172 | // when a new ctor is added which doesn't call InitWindow) | |
223d09f6 | 173 | wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") ); |
f03fc89f VZ |
174 | |
175 | // generate a new id if the user doesn't care about it | |
69418a8e | 176 | m_windowId = id == -1 ? NewControlId() : id; |
f03fc89f VZ |
177 | |
178 | SetName(name); | |
179 | SetWindowStyleFlag(style); | |
180 | SetParent(parent); | |
674ac8b9 VZ |
181 | |
182 | #if wxUSE_VALIDATORS | |
8d99be5f | 183 | SetValidator(validator); |
674ac8b9 | 184 | #endif // wxUSE_VALIDATORS |
f03fc89f | 185 | |
8ae6ce07 VZ |
186 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to |
187 | // have it too - like this it's possible to set it only in the top level | |
188 | // dialog/frame and all children will inherit it by defult | |
189 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
190 | { | |
191 | SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY); | |
192 | } | |
193 | ||
f03fc89f VZ |
194 | return TRUE; |
195 | } | |
196 | ||
197 | // ---------------------------------------------------------------------------- | |
198 | // destruction | |
199 | // ---------------------------------------------------------------------------- | |
200 | ||
201 | // common clean up | |
202 | wxWindowBase::~wxWindowBase() | |
203 | { | |
204 | // FIXME if these 2 cases result from programming errors in the user code | |
205 | // we should probably assert here instead of silently fixing them | |
206 | ||
207 | // Just in case the window has been Closed, but we're then deleting | |
208 | // immediately: don't leave dangling pointers. | |
209 | wxPendingDelete.DeleteObject(this); | |
210 | ||
211 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
212 | // we weren't a dialog class | |
213 | wxTopLevelWindows.DeleteObject(this); | |
a23fd0e1 | 214 | |
223d09f6 | 215 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); |
f03fc89f | 216 | |
319fefa9 VZ |
217 | // make sure that there are no dangling pointers left pointing to us |
218 | wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); | |
219 | if ( panel ) | |
220 | { | |
221 | if ( panel->GetLastFocus() == this ) | |
222 | { | |
223 | panel->SetLastFocus((wxWindow *)NULL); | |
224 | } | |
225 | } | |
226 | ||
789295bf VZ |
227 | #if wxUSE_CARET |
228 | if ( m_caret ) | |
229 | delete m_caret; | |
230 | #endif // wxUSE_CARET | |
231 | ||
88ac883a | 232 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
233 | if ( m_windowValidator ) |
234 | delete m_windowValidator; | |
88ac883a | 235 | #endif // wxUSE_VALIDATORS |
f03fc89f | 236 | |
6ccec5fc VZ |
237 | // we only delete object data, not untyped |
238 | if ( m_clientDataType == ClientData_Object ) | |
f03fc89f VZ |
239 | delete m_clientObject; |
240 | ||
241 | #if wxUSE_CONSTRAINTS | |
242 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
243 | // at deleted windows as they delete themselves. | |
244 | DeleteRelatedConstraints(); | |
245 | ||
246 | if ( m_constraints ) | |
247 | { | |
248 | // This removes any dangling pointers to this window in other windows' | |
249 | // constraintsInvolvedIn lists. | |
250 | UnsetConstraints(m_constraints); | |
251 | delete m_constraints; | |
252 | m_constraints = NULL; | |
253 | } | |
254 | ||
255 | if ( m_windowSizer ) | |
256 | delete m_windowSizer; | |
257 | ||
f03fc89f VZ |
258 | #endif // wxUSE_CONSTRAINTS |
259 | ||
260 | #if wxUSE_DRAG_AND_DROP | |
261 | if ( m_dropTarget ) | |
262 | delete m_dropTarget; | |
263 | #endif // wxUSE_DRAG_AND_DROP | |
264 | ||
265 | #if wxUSE_TOOLTIPS | |
266 | if ( m_tooltip ) | |
267 | delete m_tooltip; | |
268 | #endif // wxUSE_TOOLTIPS | |
269 | } | |
270 | ||
271 | bool wxWindowBase::Destroy() | |
272 | { | |
273 | delete this; | |
274 | ||
275 | return TRUE; | |
276 | } | |
277 | ||
278 | bool wxWindowBase::Close(bool force) | |
279 | { | |
280 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
281 | event.SetEventObject(this); | |
282 | #if WXWIN_COMPATIBILITY | |
283 | event.SetForce(force); | |
284 | #endif // WXWIN_COMPATIBILITY | |
285 | event.SetCanVeto(!force); | |
286 | ||
287 | // return FALSE if window wasn't closed because the application vetoed the | |
288 | // close event | |
289 | return GetEventHandler()->ProcessEvent(event) && !event.GetVeto(); | |
290 | } | |
291 | ||
292 | bool wxWindowBase::DestroyChildren() | |
293 | { | |
294 | wxWindowList::Node *node; | |
a23fd0e1 | 295 | for ( ;; ) |
f03fc89f | 296 | { |
a23fd0e1 VZ |
297 | // we iterate until the list becomes empty |
298 | node = GetChildren().GetFirst(); | |
299 | if ( !node ) | |
300 | break; | |
301 | ||
f03fc89f | 302 | wxWindow *child = node->GetData(); |
a23fd0e1 | 303 | |
223d09f6 | 304 | wxASSERT_MSG( child, wxT("children list contains empty nodes") ); |
a23fd0e1 | 305 | |
eb082a08 | 306 | delete child; |
a23fd0e1 VZ |
307 | |
308 | wxASSERT_MSG( !GetChildren().Find(child), | |
223d09f6 | 309 | wxT("child didn't remove itself using RemoveChild()") ); |
f03fc89f VZ |
310 | } |
311 | ||
312 | return TRUE; | |
313 | } | |
314 | ||
315 | // ---------------------------------------------------------------------------- | |
f68586e5 | 316 | // size/position related methods |
f03fc89f VZ |
317 | // ---------------------------------------------------------------------------- |
318 | ||
319 | // centre the window with respect to its parent in either (or both) directions | |
320 | void wxWindowBase::Centre(int direction) | |
321 | { | |
322 | int widthParent, heightParent; | |
323 | ||
324 | wxWindow *parent = GetParent(); | |
10fcf31a | 325 | if ( !parent ) |
f03fc89f | 326 | { |
10fcf31a VZ |
327 | // no other choice |
328 | direction |= wxCENTRE_ON_SCREEN; | |
f03fc89f | 329 | } |
10fcf31a VZ |
330 | |
331 | if ( direction & wxCENTRE_ON_SCREEN ) | |
f03fc89f VZ |
332 | { |
333 | // centre with respect to the whole screen | |
334 | wxDisplaySize(&widthParent, &heightParent); | |
335 | } | |
10fcf31a VZ |
336 | else |
337 | { | |
338 | // centre inside the parents rectangle | |
339 | parent->GetClientSize(&widthParent, &heightParent); | |
340 | } | |
f03fc89f VZ |
341 | |
342 | int width, height; | |
343 | GetSize(&width, &height); | |
344 | ||
c39eda94 VZ |
345 | int xNew = -1, |
346 | yNew = -1; | |
f03fc89f VZ |
347 | |
348 | if ( direction & wxHORIZONTAL ) | |
c39eda94 | 349 | xNew = (widthParent - width)/2; |
f03fc89f VZ |
350 | |
351 | if ( direction & wxVERTICAL ) | |
c39eda94 | 352 | yNew = (heightParent - height)/2; |
f03fc89f | 353 | |
c39eda94 VZ |
354 | // controls are always centered on their parent because it doesn't make |
355 | // sense to centre them on the screen | |
7eb4e9cc | 356 | if ( !(direction & wxCENTRE_ON_SCREEN) || !IsTopLevel() ) |
c39eda94 | 357 | { |
7eb4e9cc VZ |
358 | // the only chance to get this is to have a not top level window |
359 | // without parent which shouldn't happen | |
360 | wxCHECK_RET( parent, wxT("this window must have a parent") ); | |
10fcf31a | 361 | |
c39eda94 VZ |
362 | // adjust to the parents client area origin |
363 | wxPoint posParent = parent->ClientToScreen(wxPoint(0, 0)); | |
f03fc89f | 364 | |
c39eda94 VZ |
365 | xNew += posParent.x; |
366 | yNew += posParent.y; | |
7631a292 RD |
367 | } |
368 | ||
07cf98cb VZ |
369 | // move the centre of this window to this position |
370 | Move(xNew, yNew); | |
7631a292 RD |
371 | } |
372 | ||
f03fc89f VZ |
373 | // fits the window around the children |
374 | void wxWindowBase::Fit() | |
375 | { | |
f68586e5 VZ |
376 | if ( GetChildren().GetCount() > 0 ) |
377 | { | |
378 | SetClientSize(DoGetBestSize()); | |
379 | } | |
380 | //else: do nothing if we have no children | |
381 | } | |
f03fc89f | 382 | |
f68586e5 VZ |
383 | // return the size best suited for the current window |
384 | wxSize wxWindowBase::DoGetBestSize() const | |
385 | { | |
386 | if ( GetChildren().GetCount() > 0 ) | |
f03fc89f | 387 | { |
f68586e5 VZ |
388 | // our minimal acceptable size is such that all our windows fit inside |
389 | int maxX = 0, | |
390 | maxY = 0; | |
391 | ||
392 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
393 | node; | |
394 | node = node->GetNext() ) | |
42e69d6b | 395 | { |
f68586e5 VZ |
396 | wxWindow *win = node->GetData(); |
397 | if ( win->IsTopLevel() ) | |
398 | { | |
399 | // dialogs and frames lie in different top level windows - | |
400 | // don't deal with them here | |
401 | continue; | |
402 | } | |
403 | ||
404 | int wx, wy, ww, wh; | |
405 | win->GetPosition(&wx, &wy); | |
3f5513f5 VZ |
406 | |
407 | // if the window hadn't been positioned yet, assume that it is in | |
408 | // the origin | |
409 | if ( wx == -1 ) | |
410 | wx = 0; | |
411 | if ( wy == -1 ) | |
412 | wy = 0; | |
413 | ||
f68586e5 VZ |
414 | win->GetSize(&ww, &wh); |
415 | if ( wx + ww > maxX ) | |
416 | maxX = wx + ww; | |
417 | if ( wy + wh > maxY ) | |
418 | maxY = wy + wh; | |
42e69d6b VZ |
419 | } |
420 | ||
f68586e5 VZ |
421 | // leave a margin |
422 | return wxSize(maxX + 7, maxY + 14); | |
423 | } | |
424 | else | |
425 | { | |
426 | // for a generic window there is no natural best size - just use the | |
427 | // current one | |
428 | return GetSize(); | |
f03fc89f | 429 | } |
f03fc89f VZ |
430 | } |
431 | ||
432 | // set the min/max size of the window | |
f03fc89f VZ |
433 | void wxWindowBase::SetSizeHints(int minW, int minH, |
434 | int maxW, int maxH, | |
435 | int WXUNUSED(incW), int WXUNUSED(incH)) | |
436 | { | |
437 | m_minWidth = minW; | |
438 | m_maxWidth = maxW; | |
439 | m_minHeight = minH; | |
440 | m_maxHeight = maxH; | |
441 | } | |
442 | ||
443 | // ---------------------------------------------------------------------------- | |
444 | // show/hide/enable/disable the window | |
445 | // ---------------------------------------------------------------------------- | |
446 | ||
447 | bool wxWindowBase::Show(bool show) | |
448 | { | |
449 | if ( show != m_isShown ) | |
450 | { | |
451 | m_isShown = show; | |
452 | ||
453 | return TRUE; | |
454 | } | |
455 | else | |
456 | { | |
457 | return FALSE; | |
458 | } | |
459 | } | |
460 | ||
461 | bool wxWindowBase::Enable(bool enable) | |
462 | { | |
463 | if ( enable != m_isEnabled ) | |
464 | { | |
465 | m_isEnabled = enable; | |
466 | ||
467 | return TRUE; | |
468 | } | |
469 | else | |
470 | { | |
471 | return FALSE; | |
472 | } | |
473 | } | |
34636400 VZ |
474 | // ---------------------------------------------------------------------------- |
475 | // RTTI | |
476 | // ---------------------------------------------------------------------------- | |
477 | ||
478 | bool wxWindowBase::IsTopLevel() const | |
479 | { | |
8487f887 | 480 | return FALSE; |
34636400 | 481 | } |
f03fc89f VZ |
482 | |
483 | // ---------------------------------------------------------------------------- | |
484 | // reparenting the window | |
485 | // ---------------------------------------------------------------------------- | |
486 | ||
487 | void wxWindowBase::AddChild(wxWindowBase *child) | |
488 | { | |
223d09f6 | 489 | wxCHECK_RET( child, wxT("can't add a NULL child") ); |
f03fc89f VZ |
490 | |
491 | GetChildren().Append(child); | |
492 | child->SetParent(this); | |
493 | } | |
494 | ||
495 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
496 | { | |
223d09f6 | 497 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); |
f03fc89f VZ |
498 | |
499 | GetChildren().DeleteObject(child); | |
500 | child->SetParent((wxWindow *)NULL); | |
501 | } | |
439b3bf1 | 502 | |
f03fc89f VZ |
503 | bool wxWindowBase::Reparent(wxWindowBase *newParent) |
504 | { | |
505 | wxWindow *oldParent = GetParent(); | |
506 | if ( newParent == oldParent ) | |
507 | { | |
508 | // nothing done | |
509 | return FALSE; | |
510 | } | |
511 | ||
512 | // unlink this window from the existing parent. | |
513 | if ( oldParent ) | |
514 | { | |
515 | oldParent->RemoveChild(this); | |
516 | } | |
517 | else | |
518 | { | |
519 | wxTopLevelWindows.DeleteObject(this); | |
520 | } | |
521 | ||
522 | // add it to the new one | |
523 | if ( newParent ) | |
524 | { | |
525 | newParent->AddChild(this); | |
526 | } | |
527 | else | |
528 | { | |
529 | wxTopLevelWindows.Append(this); | |
530 | } | |
531 | ||
532 | return TRUE; | |
533 | } | |
534 | ||
535 | // ---------------------------------------------------------------------------- | |
536 | // event handler stuff | |
537 | // ---------------------------------------------------------------------------- | |
538 | ||
539 | void wxWindowBase::PushEventHandler(wxEvtHandler *handler) | |
540 | { | |
541 | handler->SetNextHandler(GetEventHandler()); | |
542 | SetEventHandler(handler); | |
543 | } | |
544 | ||
545 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
546 | { | |
547 | wxEvtHandler *handlerA = GetEventHandler(); | |
548 | if ( handlerA ) | |
549 | { | |
550 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
551 | handlerA->SetNextHandler((wxEvtHandler *)NULL); | |
552 | SetEventHandler(handlerB); | |
553 | if ( deleteHandler ) | |
554 | { | |
555 | delete handlerA; | |
556 | handlerA = (wxEvtHandler *)NULL; | |
557 | } | |
558 | } | |
559 | ||
560 | return handlerA; | |
561 | } | |
562 | ||
563 | // ---------------------------------------------------------------------------- | |
564 | // cursors, fonts &c | |
565 | // ---------------------------------------------------------------------------- | |
566 | ||
567 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) | |
568 | { | |
569 | if ( !colour.Ok() || (colour == m_backgroundColour) ) | |
570 | return FALSE; | |
571 | ||
572 | m_backgroundColour = colour; | |
573 | ||
574 | return TRUE; | |
575 | } | |
576 | ||
577 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
578 | { | |
579 | if ( !colour.Ok() || (colour == m_foregroundColour) ) | |
580 | return FALSE; | |
581 | ||
582 | m_foregroundColour = colour; | |
583 | ||
584 | return TRUE; | |
585 | } | |
586 | ||
587 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
588 | { | |
589 | // don't try to set invalid cursor, always fall back to the default | |
590 | const wxCursor& cursorOk = cursor.Ok() ? cursor : *wxSTANDARD_CURSOR; | |
591 | ||
913df6f2 | 592 | if ( (wxCursor&)cursorOk == m_cursor ) |
f03fc89f VZ |
593 | { |
594 | // no change | |
595 | return FALSE; | |
596 | } | |
597 | ||
598 | m_cursor = cursorOk; | |
599 | ||
600 | return TRUE; | |
601 | } | |
602 | ||
603 | bool wxWindowBase::SetFont(const wxFont& font) | |
604 | { | |
605 | // don't try to set invalid font, always fall back to the default | |
606 | const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT; | |
607 | ||
913df6f2 | 608 | if ( (wxFont&)fontOk == m_font ) |
f03fc89f VZ |
609 | { |
610 | // no change | |
611 | return FALSE; | |
612 | } | |
613 | ||
614 | m_font = fontOk; | |
615 | ||
616 | return TRUE; | |
617 | } | |
618 | ||
789295bf VZ |
619 | #if wxUSE_CARET |
620 | void wxWindowBase::SetCaret(wxCaret *caret) | |
621 | { | |
622 | if ( m_caret ) | |
623 | { | |
624 | delete m_caret; | |
625 | } | |
626 | ||
627 | m_caret = caret; | |
628 | ||
629 | if ( m_caret ) | |
630 | { | |
631 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
223d09f6 | 632 | wxT("caret should be created associated to this window") ); |
789295bf VZ |
633 | } |
634 | } | |
635 | #endif // wxUSE_CARET | |
636 | ||
88ac883a | 637 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
638 | // ---------------------------------------------------------------------------- |
639 | // validators | |
640 | // ---------------------------------------------------------------------------- | |
641 | ||
642 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
643 | { | |
644 | if ( m_windowValidator ) | |
645 | delete m_windowValidator; | |
646 | ||
647 | m_windowValidator = (wxValidator *)validator.Clone(); | |
648 | ||
649 | if ( m_windowValidator ) | |
650 | m_windowValidator->SetWindow(this) ; | |
651 | } | |
88ac883a | 652 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
653 | |
654 | // ---------------------------------------------------------------------------- | |
655 | // update region testing | |
656 | // ---------------------------------------------------------------------------- | |
657 | ||
658 | bool wxWindowBase::IsExposed(int x, int y) const | |
659 | { | |
660 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
661 | } | |
662 | ||
663 | bool wxWindowBase::IsExposed(int x, int y, int w, int h) const | |
664 | { | |
665 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
666 | } | |
667 | ||
668 | // ---------------------------------------------------------------------------- | |
669 | // find window by id or name | |
670 | // ---------------------------------------------------------------------------- | |
671 | ||
672 | wxWindow *wxWindowBase::FindWindow( long id ) | |
673 | { | |
674 | if ( id == m_windowId ) | |
675 | return (wxWindow *)this; | |
676 | ||
677 | wxWindowBase *res = (wxWindow *)NULL; | |
678 | wxWindowList::Node *node; | |
679 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
680 | { | |
681 | wxWindowBase *child = node->GetData(); | |
682 | res = child->FindWindow( id ); | |
683 | } | |
684 | ||
685 | return (wxWindow *)res; | |
686 | } | |
687 | ||
688 | wxWindow *wxWindowBase::FindWindow( const wxString& name ) | |
689 | { | |
690 | if ( name == m_windowName ) | |
691 | return (wxWindow *)this; | |
692 | ||
693 | wxWindowBase *res = (wxWindow *)NULL; | |
694 | wxWindowList::Node *node; | |
695 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
696 | { | |
697 | wxWindow *child = node->GetData(); | |
698 | res = child->FindWindow(name); | |
699 | } | |
700 | ||
701 | return (wxWindow *)res; | |
702 | } | |
703 | ||
704 | // ---------------------------------------------------------------------------- | |
705 | // dialog oriented functions | |
706 | // ---------------------------------------------------------------------------- | |
707 | ||
34636400 | 708 | void wxWindowBase::MakeModal(bool modal) |
f03fc89f | 709 | { |
34636400 VZ |
710 | // Disable all other windows |
711 | if ( IsTopLevel() ) | |
712 | { | |
713 | wxWindowList::Node *node = wxTopLevelWindows.GetFirst(); | |
714 | while (node) | |
715 | { | |
716 | wxWindow *win = node->GetData(); | |
717 | if (win != this) | |
718 | win->Enable(!modal); | |
719 | ||
720 | node = node->GetNext(); | |
721 | } | |
722 | } | |
f03fc89f VZ |
723 | } |
724 | ||
725 | bool wxWindowBase::Validate() | |
726 | { | |
88ac883a | 727 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
728 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
729 | ||
f03fc89f VZ |
730 | wxWindowList::Node *node; |
731 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
732 | { | |
733 | wxWindowBase *child = node->GetData(); | |
734 | wxValidator *validator = child->GetValidator(); | |
dcd6b914 | 735 | if ( validator && !validator->Validate((wxWindow *)this) ) |
f03fc89f VZ |
736 | { |
737 | return FALSE; | |
738 | } | |
d80cd92a VZ |
739 | |
740 | if ( recurse && !child->Validate() ) | |
741 | { | |
742 | return FALSE; | |
743 | } | |
f03fc89f | 744 | } |
88ac883a | 745 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
746 | |
747 | return TRUE; | |
748 | } | |
749 | ||
750 | bool wxWindowBase::TransferDataToWindow() | |
751 | { | |
88ac883a | 752 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
753 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
754 | ||
f03fc89f VZ |
755 | wxWindowList::Node *node; |
756 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
757 | { | |
758 | wxWindowBase *child = node->GetData(); | |
759 | wxValidator *validator = child->GetValidator(); | |
760 | if ( validator && !validator->TransferToWindow() ) | |
761 | { | |
d80cd92a VZ |
762 | wxLogWarning(_("Could not transfer data to window")); |
763 | wxLog::FlushActive(); | |
f03fc89f VZ |
764 | |
765 | return FALSE; | |
766 | } | |
d80cd92a VZ |
767 | |
768 | if ( recurse ) | |
769 | { | |
a58a12e9 | 770 | if ( !child->TransferDataToWindow() ) |
d80cd92a VZ |
771 | { |
772 | // warning already given | |
773 | return FALSE; | |
774 | } | |
775 | } | |
f03fc89f | 776 | } |
88ac883a | 777 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
778 | |
779 | return TRUE; | |
780 | } | |
781 | ||
782 | bool wxWindowBase::TransferDataFromWindow() | |
783 | { | |
88ac883a | 784 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
785 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
786 | ||
f03fc89f VZ |
787 | wxWindowList::Node *node; |
788 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
789 | { | |
790 | wxWindow *child = node->GetData(); | |
d80cd92a VZ |
791 | wxValidator *validator = child->GetValidator(); |
792 | if ( validator && !validator->TransferFromWindow() ) | |
f03fc89f | 793 | { |
d80cd92a VZ |
794 | // nop warning here because the application is supposed to give |
795 | // one itself - we don't know here what might have gone wrongly | |
796 | ||
f03fc89f VZ |
797 | return FALSE; |
798 | } | |
d80cd92a VZ |
799 | |
800 | if ( recurse ) | |
801 | { | |
a58a12e9 | 802 | if ( !child->TransferDataFromWindow() ) |
d80cd92a VZ |
803 | { |
804 | // warning already given | |
805 | return FALSE; | |
806 | } | |
807 | } | |
f03fc89f | 808 | } |
88ac883a | 809 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
810 | |
811 | return TRUE; | |
812 | } | |
813 | ||
814 | void wxWindowBase::InitDialog() | |
815 | { | |
816 | wxInitDialogEvent event(GetId()); | |
817 | event.SetEventObject( this ); | |
818 | GetEventHandler()->ProcessEvent(event); | |
819 | } | |
820 | ||
821 | // ---------------------------------------------------------------------------- | |
822 | // tooltips | |
823 | // ---------------------------------------------------------------------------- | |
824 | ||
825 | #if wxUSE_TOOLTIPS | |
826 | ||
827 | void wxWindowBase::SetToolTip( const wxString &tip ) | |
828 | { | |
829 | // don't create the new tooltip if we already have one | |
830 | if ( m_tooltip ) | |
831 | { | |
832 | m_tooltip->SetTip( tip ); | |
833 | } | |
834 | else | |
835 | { | |
836 | SetToolTip( new wxToolTip( tip ) ); | |
837 | } | |
838 | ||
839 | // setting empty tooltip text does not remove the tooltip any more - use | |
840 | // SetToolTip((wxToolTip *)NULL) for this | |
841 | } | |
842 | ||
843 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
844 | { | |
845 | if ( m_tooltip ) | |
846 | delete m_tooltip; | |
847 | ||
848 | m_tooltip = tooltip; | |
849 | } | |
850 | ||
851 | #endif // wxUSE_TOOLTIPS | |
852 | ||
853 | // ---------------------------------------------------------------------------- | |
854 | // constraints and sizers | |
855 | // ---------------------------------------------------------------------------- | |
856 | ||
857 | #if wxUSE_CONSTRAINTS | |
858 | ||
859 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
860 | { | |
861 | if ( m_constraints ) | |
862 | { | |
863 | UnsetConstraints(m_constraints); | |
864 | delete m_constraints; | |
865 | } | |
866 | m_constraints = constraints; | |
867 | if ( m_constraints ) | |
868 | { | |
869 | // Make sure other windows know they're part of a 'meaningful relationship' | |
870 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
871 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
872 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
873 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
874 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
875 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
876 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
877 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
878 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
879 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
880 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
881 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
882 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
883 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
884 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
885 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
886 | } | |
887 | } | |
888 | ||
889 | // This removes any dangling pointers to this window in other windows' | |
890 | // constraintsInvolvedIn lists. | |
891 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
892 | { | |
893 | if ( c ) | |
894 | { | |
895 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
896 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
897 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
898 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
899 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
900 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
901 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
902 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
903 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
904 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
905 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
906 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
907 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
908 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
909 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
910 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
911 | } | |
912 | } | |
913 | ||
914 | // Back-pointer to other windows we're involved with, so if we delete this | |
915 | // window, we must delete any constraints we're involved with. | |
916 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
917 | { | |
918 | if ( !m_constraintsInvolvedIn ) | |
919 | m_constraintsInvolvedIn = new wxWindowList; | |
920 | if ( !m_constraintsInvolvedIn->Find(otherWin) ) | |
921 | m_constraintsInvolvedIn->Append(otherWin); | |
922 | } | |
923 | ||
924 | // REMOVE back-pointer to other windows we're involved with. | |
925 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
926 | { | |
927 | if ( m_constraintsInvolvedIn ) | |
928 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
929 | } | |
930 | ||
931 | // Reset any constraints that mention this window | |
932 | void wxWindowBase::DeleteRelatedConstraints() | |
933 | { | |
934 | if ( m_constraintsInvolvedIn ) | |
935 | { | |
936 | wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst(); | |
937 | while (node) | |
938 | { | |
939 | wxWindow *win = node->GetData(); | |
940 | wxLayoutConstraints *constr = win->GetConstraints(); | |
941 | ||
942 | // Reset any constraints involving this window | |
943 | if ( constr ) | |
944 | { | |
945 | constr->left.ResetIfWin(this); | |
946 | constr->top.ResetIfWin(this); | |
947 | constr->right.ResetIfWin(this); | |
948 | constr->bottom.ResetIfWin(this); | |
949 | constr->width.ResetIfWin(this); | |
950 | constr->height.ResetIfWin(this); | |
951 | constr->centreX.ResetIfWin(this); | |
952 | constr->centreY.ResetIfWin(this); | |
953 | } | |
954 | ||
955 | wxWindowList::Node *next = node->GetNext(); | |
956 | delete node; | |
957 | node = next; | |
958 | } | |
959 | ||
960 | delete m_constraintsInvolvedIn; | |
961 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
962 | } | |
963 | } | |
964 | ||
965 | void wxWindowBase::SetSizer(wxSizer *sizer) | |
966 | { | |
3417c2cd RR |
967 | if (m_windowSizer) delete m_windowSizer; |
968 | ||
f03fc89f | 969 | m_windowSizer = sizer; |
f03fc89f VZ |
970 | } |
971 | ||
972 | bool wxWindowBase::Layout() | |
973 | { | |
3417c2cd | 974 | // If there is a sizer, use it instead of the constraints |
f03fc89f VZ |
975 | if ( GetSizer() ) |
976 | { | |
f1df0927 VZ |
977 | int w, h; |
978 | GetClientSize(&w, &h); | |
979 | ||
3417c2cd | 980 | GetSizer()->SetDimension( 0, 0, w, h ); |
f03fc89f | 981 | } |
f1df0927 | 982 | else |
f03fc89f | 983 | { |
4b7f2165 VZ |
984 | wxLayoutConstraints *constr = GetConstraints(); |
985 | bool wasOk = constr && constr->AreSatisfied(); | |
986 | ||
f1df0927 | 987 | ResetConstraints(); // Mark all constraints as unevaluated |
4b7f2165 VZ |
988 | |
989 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
990 | // own constraints will never be satisfied any more unless we do it | |
991 | // here | |
992 | if ( wasOk ) | |
993 | { | |
994 | int noChanges = 1; | |
995 | while ( noChanges > 0 ) | |
996 | { | |
997 | constr->SatisfyConstraints(this, &noChanges); | |
998 | } | |
999 | } | |
1000 | ||
1001 | DoPhase(1); // Layout children | |
1002 | DoPhase(2); // Layout grand children | |
f1df0927 | 1003 | SetConstraintSizes(); // Recursively set the real window sizes |
f03fc89f | 1004 | } |
5d4b632b | 1005 | |
f03fc89f VZ |
1006 | return TRUE; |
1007 | } | |
1008 | ||
1009 | ||
1010 | // Do a phase of evaluating constraints: the default behaviour. wxSizers may | |
1011 | // do a similar thing, but also impose their own 'constraints' and order the | |
1012 | // evaluation differently. | |
1013 | bool wxWindowBase::LayoutPhase1(int *noChanges) | |
1014 | { | |
1015 | wxLayoutConstraints *constr = GetConstraints(); | |
1016 | if ( constr ) | |
1017 | { | |
1018 | return constr->SatisfyConstraints(this, noChanges); | |
1019 | } | |
1020 | else | |
1021 | return TRUE; | |
1022 | } | |
1023 | ||
1024 | bool wxWindowBase::LayoutPhase2(int *noChanges) | |
1025 | { | |
1026 | *noChanges = 0; | |
1027 | ||
1028 | // Layout children | |
1029 | DoPhase(1); | |
1030 | DoPhase(2); | |
1031 | return TRUE; | |
1032 | } | |
1033 | ||
1034 | // Do a phase of evaluating child constraints | |
1035 | bool wxWindowBase::DoPhase(int phase) | |
1036 | { | |
1037 | int noIterations = 0; | |
1038 | int maxIterations = 500; | |
1039 | int noChanges = 1; | |
1040 | int noFailures = 0; | |
1041 | wxWindowList succeeded; | |
1042 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
1043 | { | |
1044 | noChanges = 0; | |
1045 | noFailures = 0; | |
1046 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1047 | while (node) | |
1048 | { | |
1049 | wxWindow *child = node->GetData(); | |
34636400 | 1050 | if ( !child->IsTopLevel() ) |
f03fc89f VZ |
1051 | { |
1052 | wxLayoutConstraints *constr = child->GetConstraints(); | |
1053 | if ( constr ) | |
1054 | { | |
1055 | if ( !succeeded.Find(child) ) | |
1056 | { | |
1057 | int tempNoChanges = 0; | |
1058 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
1059 | noChanges += tempNoChanges; | |
1060 | if ( success ) | |
1061 | { | |
1062 | succeeded.Append(child); | |
1063 | } | |
1064 | } | |
1065 | } | |
1066 | } | |
1067 | node = node->GetNext(); | |
1068 | } | |
1069 | ||
1070 | noIterations++; | |
1071 | } | |
1072 | ||
1073 | return TRUE; | |
1074 | } | |
1075 | ||
1076 | void wxWindowBase::ResetConstraints() | |
1077 | { | |
1078 | wxLayoutConstraints *constr = GetConstraints(); | |
1079 | if ( constr ) | |
1080 | { | |
1081 | constr->left.SetDone(FALSE); | |
1082 | constr->top.SetDone(FALSE); | |
1083 | constr->right.SetDone(FALSE); | |
1084 | constr->bottom.SetDone(FALSE); | |
1085 | constr->width.SetDone(FALSE); | |
1086 | constr->height.SetDone(FALSE); | |
1087 | constr->centreX.SetDone(FALSE); | |
1088 | constr->centreY.SetDone(FALSE); | |
1089 | } | |
f1df0927 | 1090 | |
f03fc89f VZ |
1091 | wxWindowList::Node *node = GetChildren().GetFirst(); |
1092 | while (node) | |
1093 | { | |
1094 | wxWindow *win = node->GetData(); | |
34636400 | 1095 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
1096 | win->ResetConstraints(); |
1097 | node = node->GetNext(); | |
1098 | } | |
1099 | } | |
1100 | ||
1101 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
1102 | // and setting the real values. | |
1103 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
1104 | { | |
1105 | wxLayoutConstraints *constr = GetConstraints(); | |
4b7f2165 | 1106 | if ( constr && constr->AreSatisfied() ) |
f03fc89f VZ |
1107 | { |
1108 | int x = constr->left.GetValue(); | |
1109 | int y = constr->top.GetValue(); | |
1110 | int w = constr->width.GetValue(); | |
1111 | int h = constr->height.GetValue(); | |
1112 | ||
f03fc89f | 1113 | if ( (constr->width.GetRelationship() != wxAsIs ) || |
3417c2cd | 1114 | (constr->height.GetRelationship() != wxAsIs) ) |
f03fc89f | 1115 | { |
3417c2cd | 1116 | SetSize(x, y, w, h); |
f03fc89f VZ |
1117 | } |
1118 | else | |
1119 | { | |
3417c2cd RR |
1120 | // If we don't want to resize this window, just move it... |
1121 | Move(x, y); | |
f03fc89f VZ |
1122 | } |
1123 | } | |
1124 | else if ( constr ) | |
1125 | { | |
4b7f2165 | 1126 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), |
f1df0927 | 1127 | GetClassInfo()->GetClassName(), |
4b7f2165 | 1128 | GetName().c_str()); |
f03fc89f VZ |
1129 | } |
1130 | ||
1131 | if ( recurse ) | |
1132 | { | |
1133 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1134 | while (node) | |
1135 | { | |
1136 | wxWindow *win = node->GetData(); | |
34636400 | 1137 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
1138 | win->SetConstraintSizes(); |
1139 | node = node->GetNext(); | |
1140 | } | |
1141 | } | |
1142 | } | |
1143 | ||
f03fc89f VZ |
1144 | // Only set the size/position of the constraint (if any) |
1145 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
1146 | { | |
1147 | wxLayoutConstraints *constr = GetConstraints(); | |
1148 | if ( constr ) | |
1149 | { | |
1150 | if ( x != -1 ) | |
1151 | { | |
1152 | constr->left.SetValue(x); | |
1153 | constr->left.SetDone(TRUE); | |
1154 | } | |
1155 | if ( y != -1 ) | |
1156 | { | |
1157 | constr->top.SetValue(y); | |
1158 | constr->top.SetDone(TRUE); | |
1159 | } | |
1160 | if ( w != -1 ) | |
1161 | { | |
1162 | constr->width.SetValue(w); | |
1163 | constr->width.SetDone(TRUE); | |
1164 | } | |
1165 | if ( h != -1 ) | |
1166 | { | |
1167 | constr->height.SetValue(h); | |
1168 | constr->height.SetDone(TRUE); | |
1169 | } | |
1170 | } | |
1171 | } | |
1172 | ||
1173 | void wxWindowBase::MoveConstraint(int x, int y) | |
1174 | { | |
1175 | wxLayoutConstraints *constr = GetConstraints(); | |
1176 | if ( constr ) | |
1177 | { | |
1178 | if ( x != -1 ) | |
1179 | { | |
1180 | constr->left.SetValue(x); | |
1181 | constr->left.SetDone(TRUE); | |
1182 | } | |
1183 | if ( y != -1 ) | |
1184 | { | |
1185 | constr->top.SetValue(y); | |
1186 | constr->top.SetDone(TRUE); | |
1187 | } | |
1188 | } | |
1189 | } | |
1190 | ||
1191 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
1192 | { | |
1193 | wxLayoutConstraints *constr = GetConstraints(); | |
1194 | if ( constr ) | |
1195 | { | |
1196 | *w = constr->width.GetValue(); | |
1197 | *h = constr->height.GetValue(); | |
1198 | } | |
1199 | else | |
1200 | GetSize(w, h); | |
1201 | } | |
1202 | ||
1203 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
1204 | { | |
1205 | wxLayoutConstraints *constr = GetConstraints(); | |
1206 | if ( constr ) | |
1207 | { | |
1208 | *w = constr->width.GetValue(); | |
1209 | *h = constr->height.GetValue(); | |
1210 | } | |
1211 | else | |
1212 | GetClientSize(w, h); | |
1213 | } | |
1214 | ||
1215 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const | |
1216 | { | |
1217 | wxLayoutConstraints *constr = GetConstraints(); | |
1218 | if ( constr ) | |
1219 | { | |
1220 | *x = constr->left.GetValue(); | |
1221 | *y = constr->top.GetValue(); | |
1222 | } | |
1223 | else | |
1224 | GetPosition(x, y); | |
1225 | } | |
1226 | ||
1227 | #endif // wxUSE_CONSTRAINTS | |
1228 | ||
1229 | // ---------------------------------------------------------------------------- | |
1230 | // do Update UI processing for child controls | |
1231 | // ---------------------------------------------------------------------------- | |
7ec1983b VZ |
1232 | |
1233 | // TODO: should this be implemented for the child window rather | |
1234 | // than the parent? Then you can override it e.g. for wxCheckBox | |
1235 | // to do the Right Thing rather than having to assume a fixed number | |
1236 | // of control classes. | |
f03fc89f | 1237 | void wxWindowBase::UpdateWindowUI() |
7ec1983b | 1238 | { |
26bf1ce0 VZ |
1239 | wxUpdateUIEvent event(GetId()); |
1240 | event.m_eventObject = this; | |
1241 | ||
1242 | if ( GetEventHandler()->ProcessEvent(event) ) | |
7ec1983b | 1243 | { |
26bf1ce0 VZ |
1244 | if ( event.GetSetEnabled() ) |
1245 | Enable(event.GetEnabled()); | |
7ec1983b | 1246 | |
26bf1ce0 | 1247 | if ( event.GetSetText() ) |
f03fc89f | 1248 | { |
26bf1ce0 VZ |
1249 | wxControl *control = wxDynamicCast(this, wxControl); |
1250 | if ( control ) | |
34636400 | 1251 | { |
26bf1ce0 VZ |
1252 | wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl); |
1253 | if ( text ) | |
1254 | text->SetValue(event.GetText()); | |
1255 | else | |
34636400 VZ |
1256 | control->SetLabel(event.GetText()); |
1257 | } | |
26bf1ce0 | 1258 | } |
f03fc89f | 1259 | |
88ac883a | 1260 | #if wxUSE_CHECKBOX |
26bf1ce0 VZ |
1261 | wxCheckBox *checkbox = wxDynamicCast(this, wxCheckBox); |
1262 | if ( checkbox ) | |
1263 | { | |
1264 | if ( event.GetSetChecked() ) | |
1265 | checkbox->SetValue(event.GetChecked()); | |
1266 | } | |
88ac883a VZ |
1267 | #endif // wxUSE_CHECKBOX |
1268 | ||
b3402d0d | 1269 | #if wxUSE_RADIOBTN |
26bf1ce0 VZ |
1270 | wxRadioButton *radiobtn = wxDynamicCast(this, wxRadioButton); |
1271 | if ( radiobtn ) | |
1272 | { | |
1273 | if ( event.GetSetChecked() ) | |
1274 | radiobtn->SetValue(event.GetChecked()); | |
f03fc89f | 1275 | } |
b3402d0d | 1276 | #endif // wxUSE_RADIOBTN |
7ec1983b | 1277 | } |
7ec1983b | 1278 | } |
fd71308f | 1279 | |
f03fc89f VZ |
1280 | // ---------------------------------------------------------------------------- |
1281 | // dialog units translations | |
1282 | // ---------------------------------------------------------------------------- | |
1283 | ||
1284 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) | |
fd71308f JS |
1285 | { |
1286 | int charWidth = GetCharWidth(); | |
1287 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1288 | wxPoint pt2(-1, -1); |
1289 | if (pt.x != -1) | |
1290 | pt2.x = (int) ((pt.x * 4) / charWidth) ; | |
1291 | if (pt.y != -1) | |
1292 | pt2.y = (int) ((pt.y * 8) / charHeight) ; | |
fd71308f JS |
1293 | |
1294 | return pt2; | |
1295 | } | |
1296 | ||
f03fc89f | 1297 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) |
fd71308f JS |
1298 | { |
1299 | int charWidth = GetCharWidth(); | |
1300 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1301 | wxPoint pt2(-1, -1); |
1302 | if (pt.x != -1) | |
1303 | pt2.x = (int) ((pt.x * charWidth) / 4) ; | |
1304 | if (pt.y != -1) | |
1305 | pt2.y = (int) ((pt.y * charHeight) / 8) ; | |
fd71308f JS |
1306 | |
1307 | return pt2; | |
1308 | } | |
1309 | ||
8d99be5f VZ |
1310 | // ---------------------------------------------------------------------------- |
1311 | // client data | |
1312 | // ---------------------------------------------------------------------------- | |
1313 | ||
1314 | void wxWindowBase::DoSetClientObject( wxClientData *data ) | |
1315 | { | |
1316 | wxASSERT_MSG( m_clientDataType != ClientData_Void, | |
223d09f6 | 1317 | wxT("can't have both object and void client data") ); |
8d99be5f VZ |
1318 | |
1319 | if ( m_clientObject ) | |
1320 | delete m_clientObject; | |
1321 | ||
1322 | m_clientObject = data; | |
1323 | m_clientDataType = ClientData_Object; | |
1324 | } | |
1325 | ||
1326 | wxClientData *wxWindowBase::DoGetClientObject() const | |
1327 | { | |
0d7ea902 VZ |
1328 | // it's not an error to call GetClientObject() on a window which doesn't |
1329 | // have client data at all - NULL will be returned | |
1330 | wxASSERT_MSG( m_clientDataType != ClientData_Void, | |
223d09f6 | 1331 | wxT("this window doesn't have object client data") ); |
8d99be5f VZ |
1332 | |
1333 | return m_clientObject; | |
1334 | } | |
1335 | ||
1336 | void wxWindowBase::DoSetClientData( void *data ) | |
1337 | { | |
1338 | wxASSERT_MSG( m_clientDataType != ClientData_Object, | |
223d09f6 | 1339 | wxT("can't have both object and void client data") ); |
8d99be5f VZ |
1340 | |
1341 | m_clientData = data; | |
1342 | m_clientDataType = ClientData_Void; | |
1343 | } | |
1344 | ||
1345 | void *wxWindowBase::DoGetClientData() const | |
1346 | { | |
0d7ea902 VZ |
1347 | // it's not an error to call GetClientData() on a window which doesn't have |
1348 | // client data at all - NULL will be returned | |
1349 | wxASSERT_MSG( m_clientDataType != ClientData_Object, | |
223d09f6 | 1350 | wxT("this window doesn't have void client data") ); |
8d99be5f VZ |
1351 | |
1352 | return m_clientData; | |
1353 | } | |
1354 | ||
f03fc89f VZ |
1355 | // ---------------------------------------------------------------------------- |
1356 | // event handlers | |
1357 | // ---------------------------------------------------------------------------- | |
1358 | ||
1359 | // propagate the colour change event to the subwindows | |
1360 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1361 | { | |
1362 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1363 | while ( node ) | |
1364 | { | |
1365 | // Only propagate to non-top-level windows | |
1366 | wxWindow *win = node->GetData(); | |
1367 | if ( !win->IsTopLevel() ) | |
1368 | { | |
1369 | wxSysColourChangedEvent event2; | |
1370 | event.m_eventObject = win; | |
1371 | win->GetEventHandler()->ProcessEvent(event2); | |
1372 | } | |
1373 | ||
1374 | node = node->GetNext(); | |
1375 | } | |
1376 | } | |
1377 | ||
1378 | // the default action is to populate dialog with data when it's created | |
1379 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) | |
1380 | { | |
1381 | TransferDataToWindow(); | |
1382 | } | |
1383 | ||
a02dc3e3 VZ |
1384 | // process Ctrl-Alt-mclick |
1385 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) | |
1386 | { | |
1387 | if ( event.ControlDown() && event.AltDown() ) | |
1388 | { | |
1389 | // don't translate these strings | |
1390 | wxString port; | |
1391 | switch ( wxGetOsVersion() ) | |
1392 | { | |
1393 | case wxMOTIF_X: port = _T("Motif"); break; | |
1394 | case wxMACINTOSH: port = _T("Mac"); break; | |
1395 | case wxBEOS: port = _T("BeOS"); break; | |
1396 | case wxGTK: | |
1397 | case wxGTK_WIN32: | |
1398 | case wxGTK_OS2: | |
1399 | case wxGTK_BEOS: port = _T("GTK"); break; | |
1400 | case wxWINDOWS: | |
1401 | case wxPENWINDOWS: | |
1402 | case wxWINDOWS_NT: | |
1403 | case wxWIN32S: | |
1404 | case wxWIN95: | |
1405 | case wxWIN386: port = _T("MS Windows"); break; | |
1406 | case wxMGL_UNIX: | |
1407 | case wxMGL_X: | |
1408 | case wxMGL_WIN32: | |
1409 | case wxMGL_OS2: port = _T("MGL"); break; | |
1410 | case wxWINDOWS_OS2: | |
1411 | case wxOS2_PM: port = _T("OS/2"); break; | |
1412 | default: port = _T("unknown"); break; | |
1413 | } | |
1414 | ||
1415 | wxMessageBox(wxString::Format( | |
1416 | _T( | |
1417 | " wxWindows Library (%s port)\n" | |
1418 | "Version %u.%u.%u, compiled at %s %s\n" | |
1419 | " Copyright (c) 1995-2000 wxWindows team" | |
1420 | ), | |
1421 | port.c_str(), | |
1422 | wxMAJOR_VERSION, | |
1423 | wxMINOR_VERSION, | |
1424 | wxRELEASE_NUMBER, | |
1425 | __DATE__, | |
1426 | __TIME__ | |
1427 | ), | |
1428 | _T("wxWindows information"), | |
1429 | wxICON_INFORMATION | wxOK, | |
1430 | (wxWindow *)this); | |
1431 | } | |
1432 | else | |
1433 | { | |
1434 | event.Skip(); | |
1435 | } | |
1436 | } | |
1437 | ||
f03fc89f VZ |
1438 | // ---------------------------------------------------------------------------- |
1439 | // list classes implementation | |
1440 | // ---------------------------------------------------------------------------- | |
1441 | ||
1442 | void wxWindowListNode::DeleteData() | |
1443 | { | |
1444 | delete (wxWindow *)GetData(); | |
1445 | } | |
1446 |