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 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
44 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
45 EVT_CHAR(wxWindow::OnChar
)
46 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
47 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
48 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
49 EVT_IDLE(wxWindow::OnIdle
)
61 m_windowParent
= NULL
;
62 m_windowEventHandler
= this;
64 m_windowCursor
= *wxSTANDARD_CURSOR
;
65 m_children
= new wxList
;
67 m_constraintsInvolvedIn
= NULL
;
71 m_windowValidator
= NULL
;
74 m_caretWidth
= 0; m_caretHeight
= 0;
75 m_caretEnabled
= FALSE
;
77 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
78 m_foregroundColour
= *wxBLACK
;
79 m_defaultForegroundColour
= *wxBLACK
;
80 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
82 #if wxUSE_DRAG_AND_DROP
90 // Have to delete constraints/sizer FIRST otherwise
91 // sizers may try to look at deleted windows as they
94 DeleteRelatedConstraints();
97 // This removes any dangling pointers to this window
98 // in other windows' constraintsInvolvedIn lists.
99 UnsetConstraints(m_constraints
);
100 delete m_constraints
;
101 m_constraints
= NULL
;
105 delete m_windowSizer
;
106 m_windowSizer
= NULL
;
108 // If this is a child of a sizer, remove self from parent
110 m_sizerParent
->RemoveChild((wxWindow
*)this);
114 m_windowParent
->RemoveChild(this);
118 // TODO: destroy the window
123 // Just in case the window has been Closed, but
124 // we're then deleting immediately: don't leave
125 // dangling pointers.
126 wxPendingDelete
.DeleteObject(this);
128 if ( m_windowValidator
)
129 delete m_windowValidator
;
132 // Destroy the window (delayed, if a managed window)
133 bool wxWindow::Destroy()
140 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
144 const wxString
& name
)
149 m_windowParent
= NULL
;
150 m_windowEventHandler
= this;
152 m_windowCursor
= *wxSTANDARD_CURSOR
;
153 m_constraints
= NULL
;
154 m_constraintsInvolvedIn
= NULL
;
155 m_windowSizer
= NULL
;
156 m_sizerParent
= NULL
;
157 m_autoLayout
= FALSE
;
158 m_windowValidator
= NULL
;
160 #if wxUSE_DRAG_AND_DROP
161 m_pDropTarget
= NULL
;
164 m_caretWidth
= 0; m_caretHeight
= 0;
165 m_caretEnabled
= FALSE
;
166 m_caretShown
= FALSE
;
171 m_defaultItem
= NULL
;
172 m_windowParent
= NULL
;
176 if (parent
) parent
->AddChild(this);
183 m_windowId
= (int)NewControlId();
187 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
188 m_foregroundColour
= *wxBLACK
;
189 m_defaultForegroundColour
= *wxBLACK
;
190 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
192 m_windowStyle
= style
;
195 m_windowId
= (int)NewControlId();
199 // TODO: create the window
204 void wxWindow::SetFocus()
209 void wxWindow::Enable(bool enable
)
214 void wxWindow::CaptureMouse()
219 void wxWindow::ReleaseMouse()
224 // Push/pop event handler (i.e. allow a chain of event handlers
226 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
228 handler
->SetNextHandler(GetEventHandler());
229 SetEventHandler(handler
);
232 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
234 if ( GetEventHandler() )
236 wxEvtHandler
*handlerA
= GetEventHandler();
237 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
238 handlerA
->SetNextHandler(NULL
);
239 SetEventHandler(handlerB
);
252 #if wxUSE_DRAG_AND_DROP
254 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
256 if ( m_pDropTarget
!= 0 ) {
257 m_pDropTarget
->Revoke(m_hWnd
);
258 delete m_pDropTarget
;
261 m_pDropTarget
= pDropTarget
;
262 if ( m_pDropTarget
!= 0 )
263 m_pDropTarget
->Register(m_hWnd
);
268 // Old style file-manager drag&drop
269 void wxWindow::DragAcceptFiles(bool accept
)
275 void wxWindow::GetSize(int *x
, int *y
) const
280 void wxWindow::GetPosition(int *x
, int *y
) const
285 void wxWindow::ScreenToClient(int *x
, int *y
) const
290 void wxWindow::ClientToScreen(int *x
, int *y
) const
295 void wxWindow::SetCursor(const wxCursor
& cursor
)
297 m_windowCursor
= cursor
;
298 if (m_windowCursor
.Ok())
305 // Get size *available for subwindows* i.e. excluding menu bar etc.
306 void wxWindow::GetClientSize(int *x
, int *y
) const
311 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
316 void wxWindow::SetClientSize(int width
, int height
)
321 // For implementation purposes - sometimes decorations make the client area
323 wxPoint
wxWindow::GetClientAreaOrigin() const
325 return wxPoint(0, 0);
328 // Makes an adjustment to the window position (for example, a frame that has
329 // a toolbar that it manages itself).
330 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
332 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
334 wxPoint
pt(GetParent()->GetClientAreaOrigin());
335 x
+= pt
.x
; y
+= pt
.y
;
339 bool wxWindow::Show(bool show
)
345 bool wxWindow::IsShown() const
351 int wxWindow::GetCharHeight() const
357 int wxWindow::GetCharWidth() const
363 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
364 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
366 wxFont
*fontToUse
= (wxFont
*)theFont
;
368 fontToUse
= (wxFont
*) & m_windowFont
;
373 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
378 // Responds to colour changes: passes event on to children.
379 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
381 wxNode
*node
= GetChildren()->First();
384 // Only propagate to non-top-level windows
385 wxWindow
*win
= (wxWindow
*)node
->Data();
386 if ( win
->GetParent() )
388 wxSysColourChangedEvent event2
;
389 event
.m_eventObject
= win
;
390 win
->GetEventHandler()->ProcessEvent(event2
);
397 // This can be called by the app (or wxWindows) to do default processing for the current
398 // event. Save message/event info in wxWindow so they can be used in this function.
399 long wxWindow::Default()
405 void wxWindow::InitDialog()
407 wxInitDialogEvent
event(GetId());
408 event
.SetEventObject( this );
409 GetEventHandler()->ProcessEvent(event
);
412 // Default init dialog behaviour is to transfer data to window
413 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
415 TransferDataToWindow();
418 // Caret manipulation
419 void wxWindow::CreateCaret(int w
, int h
)
423 m_caretEnabled
= TRUE
;
426 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
431 void wxWindow::ShowCaret(bool show
)
436 void wxWindow::DestroyCaret()
439 m_caretEnabled
= FALSE
;
442 void wxWindow::SetCaretPos(int x
, int y
)
447 void wxWindow::GetCaretPos(int *x
, int *y
) const
452 wxWindow
*wxGetActiveWindow()
458 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
466 void wxWindow::Centre(int direction
)
468 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
470 wxWindow
*father
= (wxWindow
*)GetParent();
474 father
->GetClientSize(&panel_width
, &panel_height
);
475 GetSize(&width
, &height
);
481 if (direction
& wxHORIZONTAL
)
482 new_x
= (int)((panel_width
- width
)/2);
484 if (direction
& wxVERTICAL
)
485 new_y
= (int)((panel_height
- height
)/2);
487 SetSize(new_x
, new_y
, -1, -1);
491 // Coordinates relative to the window
492 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
497 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
503 int wxWindow::GetScrollPos(int orient
) const
509 // This now returns the whole range, not just the number
510 // of positions that we can scroll.
511 int wxWindow::GetScrollRange(int orient
) const
517 int wxWindow::GetScrollThumb(int orient
) const
523 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
529 // New function that will replace some of the above.
530 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
531 int range
, bool refresh
)
536 // Does a physical scroll
537 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
543 void wxWindow::SetFont(const wxFont
& font
)
547 if (!m_windowFont
.Ok())
552 void wxWindow::OnChar(wxKeyEvent
& event
)
554 if ( event
.KeyCode() == WXK_TAB
) {
555 // propagate the TABs to the parent - it's up to it to decide what
558 if ( GetParent()->ProcessEvent(event
) )
564 void wxWindow::OnPaint(wxPaintEvent
& event
)
569 bool wxWindow::IsEnabled() const
575 // Dialog support: override these and call
576 // base class members to add functionality
577 // that can't be done using validators.
578 // NOTE: these functions assume that controls
579 // are direct children of this window, not grandchildren
580 // or other levels of descendant.
582 // Transfer values to controls. If returns FALSE,
583 // it's an application error (pops up a dialog)
584 bool wxWindow::TransferDataToWindow()
586 wxNode
*node
= GetChildren()->First();
589 wxWindow
*child
= (wxWindow
*)node
->Data();
590 if ( child
->GetValidator() &&
591 !child
->GetValidator()->TransferToWindow() )
593 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
602 // Transfer values from controls. If returns FALSE,
603 // validation failed: don't quit
604 bool wxWindow::TransferDataFromWindow()
606 wxNode
*node
= GetChildren()->First();
609 wxWindow
*child
= (wxWindow
*)node
->Data();
610 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
620 bool wxWindow::Validate()
622 wxNode
*node
= GetChildren()->First();
625 wxWindow
*child
= (wxWindow
*)node
->Data();
626 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
636 // Get the window with the focus
637 wxWindow
*wxWindow::FindFocus()
643 void wxWindow::AddChild(wxWindow
*child
)
645 GetChildren()->Append(child
);
646 child
->m_windowParent
= this;
649 void wxWindow::RemoveChild(wxWindow
*child
)
652 GetChildren()->DeleteObject(child
);
653 child
->m_windowParent
= NULL
;
656 void wxWindow::DestroyChildren()
660 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
662 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
664 if ( GetChildren()->Member(child
) )
671 void wxWindow::MakeModal(bool modal
)
673 // Disable all other windows
674 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
676 wxNode
*node
= wxTopLevelWindows
.First();
679 wxWindow
*win
= (wxWindow
*)node
->Data();
688 // If nothing defined for this, try the parent.
689 // E.g. we may be a button loaded from a resource, with no callback function
691 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
693 if (GetEventHandler()->ProcessEvent(event
) )
696 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
699 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
703 UnsetConstraints(m_constraints
);
704 delete m_constraints
;
709 // Make sure other windows know they're part of a 'meaningful relationship'
710 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
711 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
712 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
713 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
714 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
715 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
716 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
717 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
718 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
719 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
720 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
721 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
722 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
723 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
724 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
725 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
729 // This removes any dangling pointers to this window
730 // in other windows' constraintsInvolvedIn lists.
731 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
735 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
736 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
737 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
738 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
739 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
740 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
741 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
742 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
743 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
744 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
745 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
746 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
747 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
748 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
749 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
750 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
754 // Back-pointer to other windows we're involved with, so if we delete
755 // this window, we must delete any constraints we're involved with.
756 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
758 if (!m_constraintsInvolvedIn
)
759 m_constraintsInvolvedIn
= new wxList
;
760 if (!m_constraintsInvolvedIn
->Member(otherWin
))
761 m_constraintsInvolvedIn
->Append(otherWin
);
764 // REMOVE back-pointer to other windows we're involved with.
765 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
767 if (m_constraintsInvolvedIn
)
768 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
771 // Reset any constraints that mention this window
772 void wxWindow::DeleteRelatedConstraints()
774 if (m_constraintsInvolvedIn
)
776 wxNode
*node
= m_constraintsInvolvedIn
->First();
779 wxWindow
*win
= (wxWindow
*)node
->Data();
780 wxNode
*next
= node
->Next();
781 wxLayoutConstraints
*constr
= win
->GetConstraints();
783 // Reset any constraints involving this window
786 constr
->left
.ResetIfWin((wxWindow
*)this);
787 constr
->top
.ResetIfWin((wxWindow
*)this);
788 constr
->right
.ResetIfWin((wxWindow
*)this);
789 constr
->bottom
.ResetIfWin((wxWindow
*)this);
790 constr
->width
.ResetIfWin((wxWindow
*)this);
791 constr
->height
.ResetIfWin((wxWindow
*)this);
792 constr
->centreX
.ResetIfWin((wxWindow
*)this);
793 constr
->centreY
.ResetIfWin((wxWindow
*)this);
798 delete m_constraintsInvolvedIn
;
799 m_constraintsInvolvedIn
= NULL
;
803 void wxWindow::SetSizer(wxSizer
*sizer
)
805 m_windowSizer
= sizer
;
807 sizer
->SetSizerParent((wxWindow
*)this);
814 bool wxWindow::Layout()
816 if (GetConstraints())
819 GetClientSize(&w
, &h
);
820 GetConstraints()->width
.SetValue(w
);
821 GetConstraints()->height
.SetValue(h
);
824 // If top level (one sizer), evaluate the sizer's constraints.
828 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
829 GetSizer()->LayoutPhase1(&noChanges
);
830 GetSizer()->LayoutPhase2(&noChanges
);
831 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
836 // Otherwise, evaluate child constraints
837 ResetConstraints(); // Mark all constraints as unevaluated
838 DoPhase(1); // Just one phase need if no sizers involved
840 SetConstraintSizes(); // Recursively set the real window sizes
846 // Do a phase of evaluating constraints:
847 // the default behaviour. wxSizers may do a similar
848 // thing, but also impose their own 'constraints'
849 // and order the evaluation differently.
850 bool wxWindow::LayoutPhase1(int *noChanges
)
852 wxLayoutConstraints
*constr
= GetConstraints();
855 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
861 bool wxWindow::LayoutPhase2(int *noChanges
)
871 // Do a phase of evaluating child constraints
872 bool wxWindow::DoPhase(int phase
)
874 int noIterations
= 0;
875 int maxIterations
= 500;
879 while ((noChanges
> 0) && (noIterations
< maxIterations
))
883 wxNode
*node
= GetChildren()->First();
886 wxWindow
*child
= (wxWindow
*)node
->Data();
887 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
889 wxLayoutConstraints
*constr
= child
->GetConstraints();
892 if (succeeded
.Member(child
))
897 int tempNoChanges
= 0;
898 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
899 noChanges
+= tempNoChanges
;
902 succeeded
.Append(child
);
914 void wxWindow::ResetConstraints()
916 wxLayoutConstraints
*constr
= GetConstraints();
919 constr
->left
.SetDone(FALSE
);
920 constr
->top
.SetDone(FALSE
);
921 constr
->right
.SetDone(FALSE
);
922 constr
->bottom
.SetDone(FALSE
);
923 constr
->width
.SetDone(FALSE
);
924 constr
->height
.SetDone(FALSE
);
925 constr
->centreX
.SetDone(FALSE
);
926 constr
->centreY
.SetDone(FALSE
);
928 wxNode
*node
= GetChildren()->First();
931 wxWindow
*win
= (wxWindow
*)node
->Data();
932 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
933 win
->ResetConstraints();
938 // Need to distinguish between setting the 'fake' size for
939 // windows and sizers, and setting the real values.
940 void wxWindow::SetConstraintSizes(bool recurse
)
942 wxLayoutConstraints
*constr
= GetConstraints();
943 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
944 constr
->width
.GetDone() && constr
->height
.GetDone())
946 int x
= constr
->left
.GetValue();
947 int y
= constr
->top
.GetValue();
948 int w
= constr
->width
.GetValue();
949 int h
= constr
->height
.GetValue();
951 // If we don't want to resize this window, just move it...
952 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
953 (constr
->height
.GetRelationship() != wxAsIs
))
955 // Calls Layout() recursively. AAAGH. How can we stop that.
956 // Simply take Layout() out of non-top level OnSizes.
957 SizerSetSize(x
, y
, w
, h
);
966 char *windowClass
= this->GetClassInfo()->GetClassName();
973 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
974 if (!constr
->left
.GetDone())
975 wxDebugMsg(" unsatisfied 'left' constraint.\n");
976 if (!constr
->right
.GetDone())
977 wxDebugMsg(" unsatisfied 'right' constraint.\n");
978 if (!constr
->width
.GetDone())
979 wxDebugMsg(" unsatisfied 'width' constraint.\n");
980 if (!constr
->height
.GetDone())
981 wxDebugMsg(" unsatisfied 'height' constraint.\n");
982 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
987 wxNode
*node
= GetChildren()->First();
990 wxWindow
*win
= (wxWindow
*)node
->Data();
991 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
992 win
->SetConstraintSizes();
998 // This assumes that all sizers are 'on' the same
999 // window, i.e. the parent of this window.
1000 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1002 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1003 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1007 m_sizerParent
->GetPosition(&xp
, &yp
);
1008 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1013 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1017 TransformSizerToActual(&xx
, &yy
);
1018 SetSize(xx
, yy
, w
, h
);
1021 void wxWindow::SizerMove(int x
, int y
)
1025 TransformSizerToActual(&xx
, &yy
);
1029 // Only set the size/position of the constraint (if any)
1030 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1032 wxLayoutConstraints
*constr
= GetConstraints();
1037 constr
->left
.SetValue(x
);
1038 constr
->left
.SetDone(TRUE
);
1042 constr
->top
.SetValue(y
);
1043 constr
->top
.SetDone(TRUE
);
1047 constr
->width
.SetValue(w
);
1048 constr
->width
.SetDone(TRUE
);
1052 constr
->height
.SetValue(h
);
1053 constr
->height
.SetDone(TRUE
);
1058 void wxWindow::MoveConstraint(int x
, int y
)
1060 wxLayoutConstraints
*constr
= GetConstraints();
1065 constr
->left
.SetValue(x
);
1066 constr
->left
.SetDone(TRUE
);
1070 constr
->top
.SetValue(y
);
1071 constr
->top
.SetDone(TRUE
);
1076 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1078 wxLayoutConstraints
*constr
= GetConstraints();
1081 *w
= constr
->width
.GetValue();
1082 *h
= constr
->height
.GetValue();
1088 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1090 wxLayoutConstraints
*constr
= GetConstraints();
1093 *w
= constr
->width
.GetValue();
1094 *h
= constr
->height
.GetValue();
1097 GetClientSize(w
, h
);
1100 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1102 wxLayoutConstraints
*constr
= GetConstraints();
1105 *x
= constr
->left
.GetValue();
1106 *y
= constr
->top
.GetValue();
1112 bool wxWindow::Close(bool force
)
1114 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1115 event
.SetEventObject(this);
1116 #if WXWIN_COMPATIBILITY
1117 event
.SetForce(force
);
1119 event
.SetCanVeto(!force
);
1121 return GetEventHandler()->ProcessEvent(event
);
1124 wxObject
* wxWindow::GetChild(int number
) const
1126 // Return a pointer to the Nth object in the window
1129 wxNode
*node
= GetChildren()->First();
1132 node
= node
->Next() ;
1135 wxObject
*obj
= (wxObject
*)node
->Data();
1142 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1144 // Obsolete function
1147 void wxWindow::Clear()
1149 wxClientDC
dc(this);
1150 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1151 dc
.SetBackground(brush
);
1155 // Fits the panel around the items
1156 void wxWindow::Fit()
1160 wxNode
*node
= GetChildren()->First();
1163 wxWindow
*win
= (wxWindow
*)node
->Data();
1165 win
->GetPosition(&wx
, &wy
);
1166 win
->GetSize(&ww
, &wh
);
1167 if ( wx
+ ww
> maxX
)
1169 if ( wy
+ wh
> maxY
)
1172 node
= node
->Next();
1174 SetClientSize(maxX
+ 5, maxY
+ 5);
1177 void wxWindow::SetValidator(const wxValidator
& validator
)
1179 if ( m_windowValidator
)
1180 delete m_windowValidator
;
1181 m_windowValidator
= validator
.Clone();
1183 if ( m_windowValidator
)
1184 m_windowValidator
->SetWindow(this) ;
1187 // Find a window by id or name
1188 wxWindow
*wxWindow::FindWindow(long id
)
1193 wxNode
*node
= GetChildren()->First();
1196 wxWindow
*child
= (wxWindow
*)node
->Data();
1197 wxWindow
*found
= child
->FindWindow(id
);
1200 node
= node
->Next();
1205 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1207 if ( GetName() == name
)
1210 wxNode
*node
= GetChildren()->First();
1213 wxWindow
*child
= (wxWindow
*)node
->Data();
1214 wxWindow
*found
= child
->FindWindow(name
);
1217 node
= node
->Next();
1222 void wxWindow::OnIdle(wxIdleEvent
& event
)
1224 /* TODO: you may need to do something like this
1225 * if your GUI doesn't generate enter/leave events
1227 // Check if we need to send a LEAVE event
1228 if (m_mouseInWindow)
1231 ::GetCursorPos(&pt);
1232 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1234 // Generate a LEAVE event
1235 m_mouseInWindow = FALSE;
1236 MSWOnMouseLeave(pt.x, pt.y, 0);
1241 // This calls the UI-update mechanism (querying windows for
1242 // menu/toolbar/control state information)
1246 // Raise the window to the top of the Z order
1247 void wxWindow::Raise()
1252 // Lower the window to the bottom of the Z order
1253 void wxWindow::Lower()
1258 bool wxWindow::AcceptsFocus() const
1260 return IsShown() && IsEnabled();
1263 // Update region access
1264 wxRegion
wxWindow::GetUpdateRegion() const
1266 return m_updateRegion
;
1269 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1271 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1274 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1276 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1279 bool wxWindow::IsExposed(const wxRect
& rect
) const
1281 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);