1 ///////////////////////////////////////////////////////////////////////////// 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "window.h" 
  19 #include "wx/dcclient.h" 
  23 #include "wx/layout.h" 
  24 #include "wx/dialog.h" 
  25 #include "wx/listbox.h" 
  26 #include "wx/button.h" 
  27 #include "wx/settings.h" 
  28 #include "wx/msgdlg.h" 
  30 #include "wx/menuitem.h" 
  33 #if  wxUSE_DRAG_AND_DROP 
  39 extern wxList wxPendingDelete
; 
  41 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
) 
  43 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
) 
  44   EVT_CHAR(wxWindow::OnChar
) 
  45   EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
) 
  46   EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
) 
  47   EVT_INIT_DIALOG(wxWindow::OnInitDialog
) 
  48   EVT_IDLE(wxWindow::OnIdle
) 
  59     m_windowParent 
= NULL
; 
  60     m_windowEventHandler 
= this; 
  62     m_windowCursor 
= *wxSTANDARD_CURSOR
; 
  63     m_children 
= new wxList
; 
  65     m_constraintsInvolvedIn 
= NULL
; 
  69     m_windowValidator 
= NULL
; 
  72     m_caretWidth 
= 0; m_caretHeight 
= 0; 
  73     m_caretEnabled 
= FALSE
; 
  75     m_backgroundColour 
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ; 
  76     m_foregroundColour 
= *wxBLACK
; 
  77     m_defaultForegroundColour 
= *wxBLACK 
; 
  78     m_defaultBackgroundColour 
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ; 
  80 #if  wxUSE_DRAG_AND_DROP 
  88         // Have to delete constraints/sizer FIRST otherwise 
  89         // sizers may try to look at deleted windows as they 
  92     DeleteRelatedConstraints(); 
  95         // This removes any dangling pointers to this window 
  96         // in other windows' constraintsInvolvedIn lists. 
  97         UnsetConstraints(m_constraints
); 
 103         delete m_windowSizer
; 
 104         m_windowSizer 
= NULL
; 
 106     // If this is a child of a sizer, remove self from parent 
 108         m_sizerParent
->RemoveChild((wxWindow 
*)this); 
 112         m_windowParent
->RemoveChild(this); 
 116     // TODO: destroy the window 
 121     // Just in case the window has been Closed, but 
 122     // we're then deleting immediately: don't leave 
 123     // dangling pointers. 
 124     wxPendingDelete
.DeleteObject(this); 
 126     if ( m_windowValidator 
) 
 127             delete m_windowValidator
; 
 130 // Destroy the window (delayed, if a managed window) 
 131 bool wxWindow::Destroy() 
 138 bool wxWindow::Create(wxWindow 
*parent
, wxWindowID id
, 
 142            const wxString
& name
) 
 147     m_windowParent 
= NULL
; 
 148     m_windowEventHandler 
= this; 
 150     m_windowCursor 
= *wxSTANDARD_CURSOR
; 
 151     m_constraints 
= NULL
; 
 152     m_constraintsInvolvedIn 
= NULL
; 
 153     m_windowSizer 
= NULL
; 
 154     m_sizerParent 
= NULL
; 
 155     m_autoLayout 
= FALSE
; 
 156     m_windowValidator 
= NULL
; 
 158 #if wxUSE_DRAG_AND_DROP 
 159     m_pDropTarget 
= NULL
; 
 162     m_caretWidth 
= 0; m_caretHeight 
= 0; 
 163     m_caretEnabled 
= FALSE
; 
 164     m_caretShown 
= FALSE
; 
 169     m_defaultItem 
= NULL
; 
 170     m_windowParent 
= NULL
; 
 174     if (parent
) parent
->AddChild(this); 
 181         m_windowId 
= (int)NewControlId(); 
 185     m_backgroundColour 
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ; 
 186     m_foregroundColour 
= *wxBLACK
; 
 187     m_defaultForegroundColour 
= *wxBLACK 
; 
 188     m_defaultBackgroundColour 
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ; 
 190     m_windowStyle 
= style
; 
 193         m_windowId 
= (int)NewControlId(); 
 197     // TODO: create the window 
 202 void wxWindow::SetFocus() 
 207 void wxWindow::Enable(bool enable
) 
 212 void wxWindow::CaptureMouse() 
 217 void wxWindow::ReleaseMouse() 
 222 // Push/pop event handler (i.e. allow a chain of event handlers 
 224 void wxWindow::PushEventHandler(wxEvtHandler 
*handler
) 
 226         handler
->SetNextHandler(GetEventHandler()); 
 227         SetEventHandler(handler
); 
 230 wxEvtHandler 
*wxWindow::PopEventHandler(bool deleteHandler
) 
 232         if ( GetEventHandler() ) 
 234                 wxEvtHandler 
*handlerA 
= GetEventHandler(); 
 235                 wxEvtHandler 
*handlerB 
= handlerA
->GetNextHandler(); 
 236                 handlerA
->SetNextHandler(NULL
); 
 237                 SetEventHandler(handlerB
); 
 250 #if    wxUSE_DRAG_AND_DROP 
 252 void wxWindow::SetDropTarget(wxDropTarget 
*pDropTarget
) 
 254   if ( m_pDropTarget 
!= 0 ) { 
 255     m_pDropTarget
->Revoke(m_hWnd
); 
 256     delete m_pDropTarget
; 
 259   m_pDropTarget 
= pDropTarget
; 
 260   if ( m_pDropTarget 
!= 0 ) 
 261     m_pDropTarget
->Register(m_hWnd
); 
 266 // Old style file-manager drag&drop 
 267 void wxWindow::DragAcceptFiles(bool accept
) 
 273 void wxWindow::GetSize(int *x
, int *y
) const 
 278 void wxWindow::GetPosition(int *x
, int *y
) const 
 283 void wxWindow::ScreenToClient(int *x
, int *y
) const 
 288 void wxWindow::ClientToScreen(int *x
, int *y
) const 
 293 void wxWindow::SetCursor(const wxCursor
& cursor
) 
 295   m_windowCursor 
= cursor
; 
 296   if (m_windowCursor
.Ok()) 
 303 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 304 void wxWindow::GetClientSize(int *x
, int *y
) const 
 309 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 314 void wxWindow::SetClientSize(int width
, int height
) 
 319 // For implementation purposes - sometimes decorations make the client area 
 321 wxPoint 
wxWindow::GetClientAreaOrigin() const 
 323     return wxPoint(0, 0); 
 326 // Makes an adjustment to the window position (for example, a frame that has 
 327 // a toolbar that it manages itself). 
 328 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) 
 330     if (((sizeFlags 
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent()) 
 332         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 333         x 
+= pt
.x
; y 
+= pt
.y
; 
 337 bool wxWindow::Show(bool show
) 
 343 bool wxWindow::IsShown() const 
 349 int wxWindow::GetCharHeight() const 
 355 int wxWindow::GetCharWidth() const 
 361 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
 362                            int *descent
, int *externalLeading
, const wxFont 
*theFont
, bool) const 
 364   wxFont 
*fontToUse 
= (wxFont 
*)theFont
; 
 366     fontToUse 
= (wxFont 
*) & m_windowFont
; 
 371 void wxWindow::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 376 // Responds to colour changes: passes event on to children. 
 377 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
) 
 379     wxNode 
*node 
= GetChildren()->First(); 
 382         // Only propagate to non-top-level windows 
 383         wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
 384         if ( win
->GetParent() ) 
 386             wxSysColourChangedEvent event2
; 
 387             event
.m_eventObject 
= win
; 
 388             win
->GetEventHandler()->ProcessEvent(event2
); 
 395 // This can be called by the app (or wxWindows) to do default processing for the current 
 396 // event. Save message/event info in wxWindow so they can be used in this function. 
 397 long wxWindow::Default() 
 403 void wxWindow::InitDialog() 
 405   wxInitDialogEvent 
event(GetId()); 
 406   event
.SetEventObject( this ); 
 407   GetEventHandler()->ProcessEvent(event
); 
 410 // Default init dialog behaviour is to transfer data to window 
 411 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
) 
 413   TransferDataToWindow(); 
 416 // Caret manipulation 
 417 void wxWindow::CreateCaret(int w
, int h
) 
 421   m_caretEnabled 
= TRUE
; 
 424 void wxWindow::CreateCaret(const wxBitmap 
*WXUNUSED(bitmap
)) 
 429 void wxWindow::ShowCaret(bool show
) 
 434 void wxWindow::DestroyCaret() 
 437     m_caretEnabled 
= FALSE
; 
 440 void wxWindow::SetCaretPos(int x
, int y
) 
 445 void wxWindow::GetCaretPos(int *x
, int *y
) const 
 450 wxWindow 
*wxGetActiveWindow() 
 456 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
)) 
 464 void wxWindow::Centre(int direction
) 
 466   int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
; 
 468   wxWindow 
*father 
= (wxWindow 
*)GetParent(); 
 472   father
->GetClientSize(&panel_width
, &panel_height
); 
 473   GetSize(&width
, &height
); 
 479   if (direction 
& wxHORIZONTAL
) 
 480     new_x 
= (int)((panel_width 
- width
)/2); 
 482   if (direction 
& wxVERTICAL
) 
 483     new_y 
= (int)((panel_height 
- height
)/2); 
 485   SetSize(new_x
, new_y
, -1, -1); 
 489 // Coordinates relative to the window 
 490 void wxWindow::WarpPointer (int x_pos
, int y_pos
) 
 495 void wxWindow::OnEraseBackground(wxEraseEvent
& event
) 
 501 int wxWindow::GetScrollPos(int orient
) const 
 507 // This now returns the whole range, not just the number 
 508 // of positions that we can scroll. 
 509 int wxWindow::GetScrollRange(int orient
) const 
 515 int wxWindow::GetScrollThumb(int orient
) const 
 521 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
) 
 527 // New function that will replace some of the above. 
 528 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
 529     int range
, bool refresh
) 
 534 // Does a physical scroll 
 535 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
 541 void wxWindow::SetFont(const wxFont
& font
) 
 545     if (!m_windowFont
.Ok()) 
 550 void wxWindow::OnChar(wxKeyEvent
& event
) 
 552     if ( event
.KeyCode() == WXK_TAB 
) { 
 553         // propagate the TABs to the parent - it's up to it to decide what 
 556             if ( GetParent()->ProcessEvent(event
) ) 
 562 void wxWindow::OnPaint(wxPaintEvent
& event
) 
 567 bool wxWindow::IsEnabled() const 
 573 // Dialog support: override these and call 
 574 // base class members to add functionality 
 575 // that can't be done using validators. 
 576 // NOTE: these functions assume that controls 
 577 // are direct children of this window, not grandchildren 
 578 // or other levels of descendant. 
 580 // Transfer values to controls. If returns FALSE, 
 581 // it's an application error (pops up a dialog) 
 582 bool wxWindow::TransferDataToWindow() 
 584         wxNode 
*node 
= GetChildren()->First(); 
 587                 wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
 588                 if ( child
->GetValidator() && 
 589                      !child
->GetValidator()->TransferToWindow() ) 
 591                         wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
); 
 600 // Transfer values from controls. If returns FALSE, 
 601 // validation failed: don't quit 
 602 bool wxWindow::TransferDataFromWindow() 
 604         wxNode 
*node 
= GetChildren()->First(); 
 607                 wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
 608                 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() ) 
 618 bool wxWindow::Validate() 
 620         wxNode 
*node 
= GetChildren()->First(); 
 623                 wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
 624                 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) ) 
 634 // Get the window with the focus 
 635 wxWindow 
*wxWindow::FindFocus() 
 641 void wxWindow::AddChild(wxWindow 
*child
) 
 643     GetChildren()->Append(child
); 
 644     child
->m_windowParent 
= this; 
 647 void wxWindow::RemoveChild(wxWindow 
*child
) 
 650         GetChildren()->DeleteObject(child
); 
 651     child
->m_windowParent 
= NULL
; 
 654 void wxWindow::DestroyChildren() 
 658     while ((node 
= GetChildren()->First()) != (wxNode 
*)NULL
) { 
 660       if ((child 
= (wxWindow 
*)node
->Data()) != (wxWindow 
*)NULL
) { 
 662                 if ( GetChildren()->Member(child
) ) 
 669 void wxWindow::MakeModal(bool modal
) 
 671   // Disable all other windows 
 672   if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
))) 
 674     wxNode 
*node 
= wxTopLevelWindows
.First(); 
 677       wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
 686 // If nothing defined for this, try the parent. 
 687 // E.g. we may be a button loaded from a resource, with no callback function 
 689 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
) 
 691   if (GetEventHandler()->ProcessEvent(event
) ) 
 694     m_windowParent
->GetEventHandler()->OnCommand(win
, event
); 
 697 void wxWindow::SetConstraints(wxLayoutConstraints 
*c
) 
 701     UnsetConstraints(m_constraints
); 
 702     delete m_constraints
; 
 707     // Make sure other windows know they're part of a 'meaningful relationship' 
 708     if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this)) 
 709       m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 710     if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this)) 
 711       m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 712     if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this)) 
 713       m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 714     if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this)) 
 715       m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 716     if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this)) 
 717       m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 718     if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this)) 
 719       m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 720     if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this)) 
 721       m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 722     if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this)) 
 723       m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
 727 // This removes any dangling pointers to this window 
 728 // in other windows' constraintsInvolvedIn lists. 
 729 void wxWindow::UnsetConstraints(wxLayoutConstraints 
*c
) 
 733     if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this)) 
 734       c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 735     if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this)) 
 736       c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 737     if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this)) 
 738       c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 739     if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this)) 
 740       c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 741     if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this)) 
 742       c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 743     if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this)) 
 744       c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 745     if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this)) 
 746       c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 747     if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this)) 
 748       c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
 752 // Back-pointer to other windows we're involved with, so if we delete 
 753 // this window, we must delete any constraints we're involved with. 
 754 void wxWindow::AddConstraintReference(wxWindow 
*otherWin
) 
 756   if (!m_constraintsInvolvedIn
) 
 757     m_constraintsInvolvedIn 
= new wxList
; 
 758   if (!m_constraintsInvolvedIn
->Member(otherWin
)) 
 759     m_constraintsInvolvedIn
->Append(otherWin
); 
 762 // REMOVE back-pointer to other windows we're involved with. 
 763 void wxWindow::RemoveConstraintReference(wxWindow 
*otherWin
) 
 765   if (m_constraintsInvolvedIn
) 
 766     m_constraintsInvolvedIn
->DeleteObject(otherWin
); 
 769 // Reset any constraints that mention this window 
 770 void wxWindow::DeleteRelatedConstraints() 
 772   if (m_constraintsInvolvedIn
) 
 774     wxNode 
*node 
= m_constraintsInvolvedIn
->First(); 
 777       wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
 778       wxNode 
*next 
= node
->Next(); 
 779       wxLayoutConstraints 
*constr 
= win
->GetConstraints(); 
 781       // Reset any constraints involving this window 
 784         constr
->left
.ResetIfWin((wxWindow 
*)this); 
 785         constr
->top
.ResetIfWin((wxWindow 
*)this); 
 786         constr
->right
.ResetIfWin((wxWindow 
*)this); 
 787         constr
->bottom
.ResetIfWin((wxWindow 
*)this); 
 788         constr
->width
.ResetIfWin((wxWindow 
*)this); 
 789         constr
->height
.ResetIfWin((wxWindow 
*)this); 
 790         constr
->centreX
.ResetIfWin((wxWindow 
*)this); 
 791         constr
->centreY
.ResetIfWin((wxWindow 
*)this); 
 796     delete m_constraintsInvolvedIn
; 
 797     m_constraintsInvolvedIn 
= NULL
; 
 801 void wxWindow::SetSizer(wxSizer 
*sizer
) 
 803   m_windowSizer 
= sizer
; 
 805     sizer
->SetSizerParent((wxWindow 
*)this); 
 812 bool wxWindow::Layout() 
 814   if (GetConstraints()) 
 817     GetClientSize(&w
, &h
); 
 818     GetConstraints()->width
.SetValue(w
); 
 819     GetConstraints()->height
.SetValue(h
); 
 822   // If top level (one sizer), evaluate the sizer's constraints. 
 826     GetSizer()->ResetConstraints();   // Mark all constraints as unevaluated 
 827     GetSizer()->LayoutPhase1(&noChanges
); 
 828     GetSizer()->LayoutPhase2(&noChanges
); 
 829     GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes 
 834     // Otherwise, evaluate child constraints 
 835     ResetConstraints();   // Mark all constraints as unevaluated 
 836     DoPhase(1);           // Just one phase need if no sizers involved 
 838     SetConstraintSizes(); // Recursively set the real window sizes 
 844 // Do a phase of evaluating constraints: 
 845 // the default behaviour. wxSizers may do a similar 
 846 // thing, but also impose their own 'constraints' 
 847 // and order the evaluation differently. 
 848 bool wxWindow::LayoutPhase1(int *noChanges
) 
 850   wxLayoutConstraints 
*constr 
= GetConstraints(); 
 853     return constr
->SatisfyConstraints((wxWindow 
*)this, noChanges
); 
 859 bool wxWindow::LayoutPhase2(int *noChanges
) 
 869 // Do a phase of evaluating child constraints 
 870 bool wxWindow::DoPhase(int phase
) 
 872   int noIterations 
= 0; 
 873   int maxIterations 
= 500; 
 877   while ((noChanges 
> 0) && (noIterations 
< maxIterations
)) 
 881     wxNode 
*node 
= GetChildren()->First(); 
 884       wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
 885       if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
))) 
 887         wxLayoutConstraints 
*constr 
= child
->GetConstraints(); 
 890           if (succeeded
.Member(child
)) 
 895             int tempNoChanges 
= 0; 
 896             bool success 
= ( (phase 
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ; 
 897             noChanges 
+= tempNoChanges
; 
 900               succeeded
.Append(child
); 
 912 void wxWindow::ResetConstraints() 
 914   wxLayoutConstraints 
*constr 
= GetConstraints(); 
 917     constr
->left
.SetDone(FALSE
); 
 918     constr
->top
.SetDone(FALSE
); 
 919     constr
->right
.SetDone(FALSE
); 
 920     constr
->bottom
.SetDone(FALSE
); 
 921     constr
->width
.SetDone(FALSE
); 
 922     constr
->height
.SetDone(FALSE
); 
 923     constr
->centreX
.SetDone(FALSE
); 
 924     constr
->centreY
.SetDone(FALSE
); 
 926   wxNode 
*node 
= GetChildren()->First(); 
 929     wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
 930     if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
))) 
 931       win
->ResetConstraints(); 
 936 // Need to distinguish between setting the 'fake' size for 
 937 // windows and sizers, and setting the real values. 
 938 void wxWindow::SetConstraintSizes(bool recurse
) 
 940   wxLayoutConstraints 
*constr 
= GetConstraints(); 
 941   if (constr 
&& constr
->left
.GetDone() && constr
->right
.GetDone() && 
 942                 constr
->width
.GetDone() && constr
->height
.GetDone()) 
 944     int x 
= constr
->left
.GetValue(); 
 945     int y 
= constr
->top
.GetValue(); 
 946     int w 
= constr
->width
.GetValue(); 
 947     int h 
= constr
->height
.GetValue(); 
 949     // If we don't want to resize this window, just move it... 
 950     if ((constr
->width
.GetRelationship() != wxAsIs
) || 
 951         (constr
->height
.GetRelationship() != wxAsIs
)) 
 953       // Calls Layout() recursively. AAAGH. How can we stop that. 
 954       // Simply take Layout() out of non-top level OnSizes. 
 955       SizerSetSize(x
, y
, w
, h
); 
 964     char *windowClass 
= this->GetClassInfo()->GetClassName(); 
 971     wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
); 
 972     if (!constr
->left
.GetDone()) 
 973       wxDebugMsg("  unsatisfied 'left' constraint.\n"); 
 974     if (!constr
->right
.GetDone()) 
 975       wxDebugMsg("  unsatisfied 'right' constraint.\n"); 
 976     if (!constr
->width
.GetDone()) 
 977       wxDebugMsg("  unsatisfied 'width' constraint.\n"); 
 978     if (!constr
->height
.GetDone()) 
 979       wxDebugMsg("  unsatisfied 'height' constraint.\n"); 
 980     wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n"); 
 985     wxNode 
*node 
= GetChildren()->First(); 
 988       wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
 989       if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
))) 
 990         win
->SetConstraintSizes(); 
 996 // This assumes that all sizers are 'on' the same 
 997 // window, i.e. the parent of this window. 
 998 void wxWindow::TransformSizerToActual(int *x
, int *y
) const 
1000   if (!m_sizerParent 
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) || 
1001                          m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) ) 
1005   m_sizerParent
->GetPosition(&xp
, &yp
); 
1006   m_sizerParent
->TransformSizerToActual(&xp
, &yp
); 
1011 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
) 
1015   TransformSizerToActual(&xx
, &yy
); 
1016   SetSize(xx
, yy
, w
, h
); 
1019 void wxWindow::SizerMove(int x
, int y
) 
1023   TransformSizerToActual(&xx
, &yy
); 
1027 // Only set the size/position of the constraint (if any) 
1028 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
) 
1030   wxLayoutConstraints 
*constr 
= GetConstraints(); 
1035       constr
->left
.SetValue(x
); 
1036       constr
->left
.SetDone(TRUE
); 
1040       constr
->top
.SetValue(y
); 
1041       constr
->top
.SetDone(TRUE
); 
1045       constr
->width
.SetValue(w
); 
1046       constr
->width
.SetDone(TRUE
); 
1050       constr
->height
.SetValue(h
); 
1051       constr
->height
.SetDone(TRUE
); 
1056 void wxWindow::MoveConstraint(int x
, int y
) 
1058   wxLayoutConstraints 
*constr 
= GetConstraints(); 
1063       constr
->left
.SetValue(x
); 
1064       constr
->left
.SetDone(TRUE
); 
1068       constr
->top
.SetValue(y
); 
1069       constr
->top
.SetDone(TRUE
); 
1074 void wxWindow::GetSizeConstraint(int *w
, int *h
) const 
1076   wxLayoutConstraints 
*constr 
= GetConstraints(); 
1079     *w 
= constr
->width
.GetValue(); 
1080     *h 
= constr
->height
.GetValue(); 
1086 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const 
1088   wxLayoutConstraints 
*constr 
= GetConstraints(); 
1091     *w 
= constr
->width
.GetValue(); 
1092     *h 
= constr
->height
.GetValue(); 
1095     GetClientSize(w
, h
); 
1098 void wxWindow::GetPositionConstraint(int *x
, int *y
) const 
1100   wxLayoutConstraints 
*constr 
= GetConstraints(); 
1103     *x 
= constr
->left
.GetValue(); 
1104     *y 
= constr
->top
.GetValue(); 
1110 bool wxWindow::Close(bool force
) 
1112   wxCloseEvent 
event(wxEVT_CLOSE_WINDOW
, m_windowId
); 
1113   event
.SetEventObject(this); 
1114 #if WXWIN_COMPATIBILITY 
1115   event
.SetForce(force
); 
1117   event
.SetCanVeto(!force
); 
1119   return GetEventHandler()->ProcessEvent(event
); 
1122 wxObject
* wxWindow::GetChild(int number
) const 
1124   // Return a pointer to the Nth object in the window 
1127   wxNode 
*node 
= GetChildren()->First(); 
1130     node 
= node
->Next() ; 
1133     wxObject 
*obj 
= (wxObject 
*)node
->Data(); 
1140 void wxWindow::OnDefaultAction(wxControl 
*initiatingItem
) 
1142     // Obsolete function 
1145 void wxWindow::Clear() 
1147         wxClientDC 
dc(this); 
1148     wxBrush 
brush(GetBackgroundColour(), wxSOLID
); 
1149     dc
.SetBackground(brush
); 
1153 // Fits the panel around the items 
1154 void wxWindow::Fit() 
1158         wxNode 
*node 
= GetChildren()->First(); 
1161                 wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
1163                 win
->GetPosition(&wx
, &wy
); 
1164                 win
->GetSize(&ww
, &wh
); 
1165                 if ( wx 
+ ww 
> maxX 
) 
1167                 if ( wy 
+ wh 
> maxY 
) 
1170                 node 
= node
->Next(); 
1172         SetClientSize(maxX 
+ 5, maxY 
+ 5); 
1175 void wxWindow::SetValidator(const wxValidator
& validator
) 
1177         if ( m_windowValidator 
) 
1178                 delete m_windowValidator
; 
1179         m_windowValidator 
= validator
.Clone(); 
1181         if ( m_windowValidator 
) 
1182                 m_windowValidator
->SetWindow(this) ; 
1185 // Find a window by id or name 
1186 wxWindow 
*wxWindow::FindWindow(long id
) 
1191         wxNode 
*node 
= GetChildren()->First(); 
1194                 wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
1195                 wxWindow 
*found 
= child
->FindWindow(id
); 
1198                 node 
= node
->Next(); 
1203 wxWindow 
*wxWindow::FindWindow(const wxString
& name
) 
1205         if ( GetName() == name
) 
1208         wxNode 
*node 
= GetChildren()->First(); 
1211                 wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
1212                 wxWindow 
*found 
= child
->FindWindow(name
); 
1215                 node 
= node
->Next(); 
1220 void wxWindow::OnIdle(wxIdleEvent
& event
) 
1222 /* TODO: you may need to do something like this 
1223  * if your GUI doesn't generate enter/leave events 
1225     // Check if we need to send a LEAVE event 
1226     if (m_mouseInWindow) 
1229         ::GetCursorPos(&pt); 
1230         if (::WindowFromPoint(pt) != (HWND) GetHWND()) 
1232             // Generate a LEAVE event 
1233             m_mouseInWindow = FALSE; 
1234             MSWOnMouseLeave(pt.x, pt.y, 0); 
1239     // This calls the UI-update mechanism (querying windows for 
1240     // menu/toolbar/control state information) 
1244 // Raise the window to the top of the Z order 
1245 void wxWindow::Raise() 
1250 // Lower the window to the bottom of the Z order 
1251 void wxWindow::Lower() 
1256 bool wxWindow::AcceptsFocus() const 
1258   return IsShown() && IsEnabled(); 
1261 // Update region access 
1262 wxRegion 
wxWindow::GetUpdateRegion() const 
1264     return m_updateRegion
; 
1267 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const 
1269     return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
); 
1272 bool wxWindow::IsExposed(const wxPoint
& pt
) const 
1274     return (m_updateRegion
.Contains(pt
) != wxOutRegion
); 
1277 bool wxWindow::IsExposed(const wxRect
& rect
) const 
1279     return (m_updateRegion
.Contains(rect
) != wxOutRegion
);