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"
31 #include "wx/menuitem.h"
40 extern wxList wxPendingDelete
;
42 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
45 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
46 EVT_CHAR(wxWindow::OnChar
)
47 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
48 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
49 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
50 EVT_IDLE(wxWindow::OnIdle
)
62 m_windowParent
= NULL
;
63 m_windowEventHandler
= this;
65 m_windowCursor
= *wxSTANDARD_CURSOR
;
66 m_children
= new wxList
;
68 m_constraintsInvolvedIn
= NULL
;
72 m_windowValidator
= NULL
;
75 m_caretWidth
= 0; m_caretHeight
= 0;
76 m_caretEnabled
= FALSE
;
78 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
79 m_foregroundColour
= *wxBLACK
;
80 m_defaultForegroundColour
= *wxBLACK
;
81 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
91 // Have to delete constraints/sizer FIRST otherwise
92 // sizers may try to look at deleted windows as they
95 DeleteRelatedConstraints();
98 // This removes any dangling pointers to this window
99 // in other windows' constraintsInvolvedIn lists.
100 UnsetConstraints(m_constraints
);
101 delete m_constraints
;
102 m_constraints
= NULL
;
106 delete m_windowSizer
;
107 m_windowSizer
= NULL
;
109 // If this is a child of a sizer, remove self from parent
111 m_sizerParent
->RemoveChild((wxWindow
*)this);
115 m_windowParent
->RemoveChild(this);
119 // TODO: destroy the window
124 // Just in case the window has been Closed, but
125 // we're then deleting immediately: don't leave
126 // dangling pointers.
127 wxPendingDelete
.DeleteObject(this);
129 if ( m_windowValidator
)
130 delete m_windowValidator
;
133 // Destroy the window (delayed, if a managed window)
134 bool wxWindow::Destroy()
141 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
145 const wxString
& name
)
150 m_windowParent
= NULL
;
151 m_windowEventHandler
= this;
153 m_windowCursor
= *wxSTANDARD_CURSOR
;
154 m_constraints
= NULL
;
155 m_constraintsInvolvedIn
= NULL
;
156 m_windowSizer
= NULL
;
157 m_sizerParent
= NULL
;
158 m_autoLayout
= FALSE
;
159 m_windowValidator
= NULL
;
161 #if USE_DRAG_AND_DROP
162 m_pDropTarget
= NULL
;
165 m_caretWidth
= 0; m_caretHeight
= 0;
166 m_caretEnabled
= FALSE
;
167 m_caretShown
= FALSE
;
172 m_defaultItem
= NULL
;
173 m_windowParent
= NULL
;
177 if (parent
) parent
->AddChild(this);
184 m_windowId
= (int)NewControlId();
188 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
189 m_foregroundColour
= *wxBLACK
;
190 m_defaultForegroundColour
= *wxBLACK
;
191 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
193 m_windowStyle
= style
;
196 m_windowId
= (int)NewControlId();
200 // TODO: create the window
205 void wxWindow::SetFocus()
210 void wxWindow::Enable(bool enable
)
215 void wxWindow::CaptureMouse()
220 void wxWindow::ReleaseMouse()
225 // Push/pop event handler (i.e. allow a chain of event handlers
227 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
229 handler
->SetNextHandler(GetEventHandler());
230 SetEventHandler(handler
);
233 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
235 if ( GetEventHandler() )
237 wxEvtHandler
*handlerA
= GetEventHandler();
238 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
239 handlerA
->SetNextHandler(NULL
);
240 SetEventHandler(handlerB
);
253 #if USE_DRAG_AND_DROP
255 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
257 if ( m_pDropTarget
!= 0 ) {
258 delete m_pDropTarget
;
261 m_pDropTarget
= pDropTarget
;
262 if ( m_pDropTarget
!= 0 )
270 // Old style file-manager drag&drop
271 void wxWindow::DragAcceptFiles(bool accept
)
277 void wxWindow::GetSize(int *x
, int *y
) const
282 void wxWindow::GetPosition(int *x
, int *y
) const
287 void wxWindow::ScreenToClient(int *x
, int *y
) const
292 void wxWindow::ClientToScreen(int *x
, int *y
) const
297 void wxWindow::SetCursor(const wxCursor
& cursor
)
299 m_windowCursor
= cursor
;
300 if (m_windowCursor
.Ok())
307 // Get size *available for subwindows* i.e. excluding menu bar etc.
308 void wxWindow::GetClientSize(int *x
, int *y
) const
313 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
318 void wxWindow::SetClientSize(int width
, int height
)
323 // For implementation purposes - sometimes decorations make the client area
325 wxPoint
wxWindow::GetClientAreaOrigin() const
327 return wxPoint(0, 0);
330 // Makes an adjustment to the window position (for example, a frame that has
331 // a toolbar that it manages itself).
332 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
334 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
336 wxPoint
pt(GetParent()->GetClientAreaOrigin());
337 x
+= pt
.x
; y
+= pt
.y
;
341 bool wxWindow::Show(bool show
)
347 bool wxWindow::IsShown() const
353 int wxWindow::GetCharHeight() const
359 int wxWindow::GetCharWidth() const
365 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
366 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
368 wxFont
*fontToUse
= (wxFont
*)theFont
;
370 fontToUse
= (wxFont
*) & m_windowFont
;
375 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
380 // Responds to colour changes: passes event on to children.
381 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
383 wxNode
*node
= GetChildren()->First();
386 // Only propagate to non-top-level windows
387 wxWindow
*win
= (wxWindow
*)node
->Data();
388 if ( win
->GetParent() )
390 wxSysColourChangedEvent event2
;
391 event
.m_eventObject
= win
;
392 win
->GetEventHandler()->ProcessEvent(event2
);
399 // This can be called by the app (or wxWindows) to do default processing for the current
400 // event. Save message/event info in wxWindow so they can be used in this function.
401 long wxWindow::Default()
407 void wxWindow::InitDialog()
409 wxInitDialogEvent
event(GetId());
410 event
.SetEventObject( this );
411 GetEventHandler()->ProcessEvent(event
);
414 // Default init dialog behaviour is to transfer data to window
415 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
417 TransferDataToWindow();
420 // Caret manipulation
421 void wxWindow::CreateCaret(int w
, int h
)
425 m_caretEnabled
= TRUE
;
428 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
433 void wxWindow::ShowCaret(bool show
)
438 void wxWindow::DestroyCaret()
441 m_caretEnabled
= FALSE
;
444 void wxWindow::SetCaretPos(int x
, int y
)
449 void wxWindow::GetCaretPos(int *x
, int *y
) const
454 wxWindow
*wxGetActiveWindow()
460 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
468 void wxWindow::Centre(int direction
)
470 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
472 wxWindow
*father
= (wxWindow
*)GetParent();
476 father
->GetClientSize(&panel_width
, &panel_height
);
477 GetSize(&width
, &height
);
483 if (direction
& wxHORIZONTAL
)
484 new_x
= (int)((panel_width
- width
)/2);
486 if (direction
& wxVERTICAL
)
487 new_y
= (int)((panel_height
- height
)/2);
489 SetSize(new_x
, new_y
, -1, -1);
493 // Coordinates relative to the window
494 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
499 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
505 int wxWindow::GetScrollPos(int orient
) const
511 // This now returns the whole range, not just the number
512 // of positions that we can scroll.
513 int wxWindow::GetScrollRange(int orient
) const
519 int wxWindow::GetScrollThumb(int orient
) const
525 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
531 // New function that will replace some of the above.
532 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
533 int range
, bool refresh
)
538 // Does a physical scroll
539 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
545 void wxWindow::SetFont(const wxFont
& font
)
549 if (!m_windowFont
.Ok())
554 void wxWindow::OnChar(wxKeyEvent
& event
)
556 if ( event
.KeyCode() == WXK_TAB
) {
557 // propagate the TABs to the parent - it's up to it to decide what
560 if ( GetParent()->ProcessEvent(event
) )
566 void wxWindow::OnPaint(wxPaintEvent
& event
)
571 bool wxWindow::IsEnabled() const
577 // Dialog support: override these and call
578 // base class members to add functionality
579 // that can't be done using validators.
580 // NOTE: these functions assume that controls
581 // are direct children of this window, not grandchildren
582 // or other levels of descendant.
584 // Transfer values to controls. If returns FALSE,
585 // it's an application error (pops up a dialog)
586 bool wxWindow::TransferDataToWindow()
588 wxNode
*node
= GetChildren()->First();
591 wxWindow
*child
= (wxWindow
*)node
->Data();
592 if ( child
->GetValidator() &&
593 !child
->GetValidator()->TransferToWindow() )
595 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
604 // Transfer values from controls. If returns FALSE,
605 // validation failed: don't quit
606 bool wxWindow::TransferDataFromWindow()
608 wxNode
*node
= GetChildren()->First();
611 wxWindow
*child
= (wxWindow
*)node
->Data();
612 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
622 bool wxWindow::Validate()
624 wxNode
*node
= GetChildren()->First();
627 wxWindow
*child
= (wxWindow
*)node
->Data();
628 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
638 // Get the window with the focus
639 wxWindow
*wxWindow::FindFocus()
645 void wxWindow::AddChild(wxWindow
*child
)
647 GetChildren()->Append(child
);
648 child
->m_windowParent
= this;
651 void wxWindow::RemoveChild(wxWindow
*child
)
654 GetChildren()->DeleteObject(child
);
655 child
->m_windowParent
= NULL
;
658 void wxWindow::DestroyChildren()
662 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
664 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
666 if ( GetChildren()->Member(child
) )
673 void wxWindow::MakeModal(bool modal
)
675 // Disable all other windows
676 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
678 wxNode
*node
= wxTopLevelWindows
.First();
681 wxWindow
*win
= (wxWindow
*)node
->Data();
690 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
694 UnsetConstraints(m_constraints
);
695 delete m_constraints
;
700 // Make sure other windows know they're part of a 'meaningful relationship'
701 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
702 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
703 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
704 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
705 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
706 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
707 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
708 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
709 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
710 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
711 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
712 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
713 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
714 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
715 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
716 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
720 // This removes any dangling pointers to this window
721 // in other windows' constraintsInvolvedIn lists.
722 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
726 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
727 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
728 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
729 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
730 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
731 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
732 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
733 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
734 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
735 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
736 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
737 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
738 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
739 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
740 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
741 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
745 // Back-pointer to other windows we're involved with, so if we delete
746 // this window, we must delete any constraints we're involved with.
747 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
749 if (!m_constraintsInvolvedIn
)
750 m_constraintsInvolvedIn
= new wxList
;
751 if (!m_constraintsInvolvedIn
->Member(otherWin
))
752 m_constraintsInvolvedIn
->Append(otherWin
);
755 // REMOVE back-pointer to other windows we're involved with.
756 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
758 if (m_constraintsInvolvedIn
)
759 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
762 // Reset any constraints that mention this window
763 void wxWindow::DeleteRelatedConstraints()
765 if (m_constraintsInvolvedIn
)
767 wxNode
*node
= m_constraintsInvolvedIn
->First();
770 wxWindow
*win
= (wxWindow
*)node
->Data();
771 wxNode
*next
= node
->Next();
772 wxLayoutConstraints
*constr
= win
->GetConstraints();
774 // Reset any constraints involving this window
777 constr
->left
.ResetIfWin((wxWindow
*)this);
778 constr
->top
.ResetIfWin((wxWindow
*)this);
779 constr
->right
.ResetIfWin((wxWindow
*)this);
780 constr
->bottom
.ResetIfWin((wxWindow
*)this);
781 constr
->width
.ResetIfWin((wxWindow
*)this);
782 constr
->height
.ResetIfWin((wxWindow
*)this);
783 constr
->centreX
.ResetIfWin((wxWindow
*)this);
784 constr
->centreY
.ResetIfWin((wxWindow
*)this);
789 delete m_constraintsInvolvedIn
;
790 m_constraintsInvolvedIn
= NULL
;
794 void wxWindow::SetSizer(wxSizer
*sizer
)
796 m_windowSizer
= sizer
;
798 sizer
->SetSizerParent((wxWindow
*)this);
805 bool wxWindow::Layout()
807 if (GetConstraints())
810 GetClientSize(&w
, &h
);
811 GetConstraints()->width
.SetValue(w
);
812 GetConstraints()->height
.SetValue(h
);
815 // If top level (one sizer), evaluate the sizer's constraints.
819 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
820 GetSizer()->LayoutPhase1(&noChanges
);
821 GetSizer()->LayoutPhase2(&noChanges
);
822 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
827 // Otherwise, evaluate child constraints
828 ResetConstraints(); // Mark all constraints as unevaluated
829 DoPhase(1); // Just one phase need if no sizers involved
831 SetConstraintSizes(); // Recursively set the real window sizes
837 // Do a phase of evaluating constraints:
838 // the default behaviour. wxSizers may do a similar
839 // thing, but also impose their own 'constraints'
840 // and order the evaluation differently.
841 bool wxWindow::LayoutPhase1(int *noChanges
)
843 wxLayoutConstraints
*constr
= GetConstraints();
846 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
852 bool wxWindow::LayoutPhase2(int *noChanges
)
862 // Do a phase of evaluating child constraints
863 bool wxWindow::DoPhase(int phase
)
865 int noIterations
= 0;
866 int maxIterations
= 500;
870 while ((noChanges
> 0) && (noIterations
< maxIterations
))
874 wxNode
*node
= GetChildren()->First();
877 wxWindow
*child
= (wxWindow
*)node
->Data();
878 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
880 wxLayoutConstraints
*constr
= child
->GetConstraints();
883 if (succeeded
.Member(child
))
888 int tempNoChanges
= 0;
889 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
890 noChanges
+= tempNoChanges
;
893 succeeded
.Append(child
);
905 void wxWindow::ResetConstraints()
907 wxLayoutConstraints
*constr
= GetConstraints();
910 constr
->left
.SetDone(FALSE
);
911 constr
->top
.SetDone(FALSE
);
912 constr
->right
.SetDone(FALSE
);
913 constr
->bottom
.SetDone(FALSE
);
914 constr
->width
.SetDone(FALSE
);
915 constr
->height
.SetDone(FALSE
);
916 constr
->centreX
.SetDone(FALSE
);
917 constr
->centreY
.SetDone(FALSE
);
919 wxNode
*node
= GetChildren()->First();
922 wxWindow
*win
= (wxWindow
*)node
->Data();
923 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
924 win
->ResetConstraints();
929 // Need to distinguish between setting the 'fake' size for
930 // windows and sizers, and setting the real values.
931 void wxWindow::SetConstraintSizes(bool recurse
)
933 wxLayoutConstraints
*constr
= GetConstraints();
934 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
935 constr
->width
.GetDone() && constr
->height
.GetDone())
937 int x
= constr
->left
.GetValue();
938 int y
= constr
->top
.GetValue();
939 int w
= constr
->width
.GetValue();
940 int h
= constr
->height
.GetValue();
942 // If we don't want to resize this window, just move it...
943 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
944 (constr
->height
.GetRelationship() != wxAsIs
))
946 // Calls Layout() recursively. AAAGH. How can we stop that.
947 // Simply take Layout() out of non-top level OnSizes.
948 SizerSetSize(x
, y
, w
, h
);
957 char *windowClass
= this->GetClassInfo()->GetClassName();
964 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
965 if (!constr
->left
.GetDone())
966 wxDebugMsg(" unsatisfied 'left' constraint.\n");
967 if (!constr
->right
.GetDone())
968 wxDebugMsg(" unsatisfied 'right' constraint.\n");
969 if (!constr
->width
.GetDone())
970 wxDebugMsg(" unsatisfied 'width' constraint.\n");
971 if (!constr
->height
.GetDone())
972 wxDebugMsg(" unsatisfied 'height' constraint.\n");
973 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
978 wxNode
*node
= GetChildren()->First();
981 wxWindow
*win
= (wxWindow
*)node
->Data();
982 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
983 win
->SetConstraintSizes();
989 // This assumes that all sizers are 'on' the same
990 // window, i.e. the parent of this window.
991 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
993 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
994 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
998 m_sizerParent
->GetPosition(&xp
, &yp
);
999 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1004 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1008 TransformSizerToActual(&xx
, &yy
);
1009 SetSize(xx
, yy
, w
, h
);
1012 void wxWindow::SizerMove(int x
, int y
)
1016 TransformSizerToActual(&xx
, &yy
);
1020 // Only set the size/position of the constraint (if any)
1021 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1023 wxLayoutConstraints
*constr
= GetConstraints();
1028 constr
->left
.SetValue(x
);
1029 constr
->left
.SetDone(TRUE
);
1033 constr
->top
.SetValue(y
);
1034 constr
->top
.SetDone(TRUE
);
1038 constr
->width
.SetValue(w
);
1039 constr
->width
.SetDone(TRUE
);
1043 constr
->height
.SetValue(h
);
1044 constr
->height
.SetDone(TRUE
);
1049 void wxWindow::MoveConstraint(int x
, int y
)
1051 wxLayoutConstraints
*constr
= GetConstraints();
1056 constr
->left
.SetValue(x
);
1057 constr
->left
.SetDone(TRUE
);
1061 constr
->top
.SetValue(y
);
1062 constr
->top
.SetDone(TRUE
);
1067 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1069 wxLayoutConstraints
*constr
= GetConstraints();
1072 *w
= constr
->width
.GetValue();
1073 *h
= constr
->height
.GetValue();
1079 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1081 wxLayoutConstraints
*constr
= GetConstraints();
1084 *w
= constr
->width
.GetValue();
1085 *h
= constr
->height
.GetValue();
1088 GetClientSize(w
, h
);
1091 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1093 wxLayoutConstraints
*constr
= GetConstraints();
1096 *x
= constr
->left
.GetValue();
1097 *y
= constr
->top
.GetValue();
1103 bool wxWindow::Close(bool force
)
1105 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1106 event
.SetEventObject(this);
1107 event
.SetForce(force
);
1109 return GetEventHandler()->ProcessEvent(event
);
1112 wxObject
* wxWindow::GetChild(int number
) const
1114 // Return a pointer to the Nth object in the window
1117 wxNode
*node
= GetChildren()->First();
1120 node
= node
->Next() ;
1123 wxObject
*obj
= (wxObject
*)node
->Data();
1130 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1132 // Obsolete function
1135 void wxWindow::Clear()
1137 wxClientDC
dc(this);
1138 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1139 dc
.SetBackground(brush
);
1143 // Fits the panel around the items
1144 void wxWindow::Fit()
1148 wxNode
*node
= GetChildren()->First();
1151 wxWindow
*win
= (wxWindow
*)node
->Data();
1153 win
->GetPosition(&wx
, &wy
);
1154 win
->GetSize(&ww
, &wh
);
1155 if ( wx
+ ww
> maxX
)
1157 if ( wy
+ wh
> maxY
)
1160 node
= node
->Next();
1162 SetClientSize(maxX
+ 5, maxY
+ 5);
1165 void wxWindow::SetValidator(const wxValidator
& validator
)
1167 if ( m_windowValidator
)
1168 delete m_windowValidator
;
1169 m_windowValidator
= validator
.Clone();
1171 if ( m_windowValidator
)
1172 m_windowValidator
->SetWindow(this) ;
1175 // Find a window by id or name
1176 wxWindow
*wxWindow::FindWindow(long id
)
1181 wxNode
*node
= GetChildren()->First();
1184 wxWindow
*child
= (wxWindow
*)node
->Data();
1185 wxWindow
*found
= child
->FindWindow(id
);
1188 node
= node
->Next();
1193 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1195 if ( GetName() == name
)
1198 wxNode
*node
= GetChildren()->First();
1201 wxWindow
*child
= (wxWindow
*)node
->Data();
1202 wxWindow
*found
= child
->FindWindow(name
);
1205 node
= node
->Next();
1210 void wxWindow::OnIdle(wxIdleEvent
& event
)
1212 /* TODO: you may need to do something like this
1213 * if your GUI doesn't generate enter/leave events
1215 // Check if we need to send a LEAVE event
1216 if (m_mouseInWindow)
1219 ::GetCursorPos(&pt);
1220 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1222 // Generate a LEAVE event
1223 m_mouseInWindow = FALSE;
1224 MSWOnMouseLeave(pt.x, pt.y, 0);
1229 // This calls the UI-update mechanism (querying windows for
1230 // menu/toolbar/control state information)
1234 // Raise the window to the top of the Z order
1235 void wxWindow::Raise()
1240 // Lower the window to the bottom of the Z order
1241 void wxWindow::Lower()
1246 bool wxWindow::AcceptsFocus() const
1248 return IsShown() && IsEnabled();
1251 // Update region access
1252 wxRegion
wxWindow::GetUpdateRegion() const
1254 return m_updateRegion
;
1257 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1259 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1262 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1264 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1267 bool wxWindow::IsExposed(const wxRect
& rect
) const
1269 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1273 * Allocates control IDs
1276 int wxWindow::NewControlId()
1278 static int s_controlId
= 0;