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