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"
34 #if wxUSE_DRAG_AND_DROP
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_KEY_DOWN(wxWindow::OnKeyDown
)
48 EVT_KEY_UP(wxWindow::OnKeyUp
)
49 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
50 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
51 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
52 EVT_IDLE(wxWindow::OnIdle
)
62 m_isWindow
= TRUE
; // An optimization
65 m_windowParent
= NULL
;
66 m_windowEventHandler
= this;
68 m_windowCursor
= *wxSTANDARD_CURSOR
;
69 m_children
= new wxList
;
71 m_constraintsInvolvedIn
= NULL
;
75 m_windowValidator
= NULL
;
78 m_caretWidth
= 0; m_caretHeight
= 0;
79 m_caretEnabled
= FALSE
;
81 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
82 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
83 m_foregroundColour
= *wxBLACK
;
85 #if wxUSE_DRAG_AND_DROP
93 // Have to delete constraints/sizer FIRST otherwise
94 // sizers may try to look at deleted windows as they
97 DeleteRelatedConstraints();
100 // This removes any dangling pointers to this window
101 // in other windows' constraintsInvolvedIn lists.
102 UnsetConstraints(m_constraints
);
103 delete m_constraints
;
104 m_constraints
= NULL
;
108 delete m_windowSizer
;
109 m_windowSizer
= NULL
;
111 // If this is a child of a sizer, remove self from parent
113 m_sizerParent
->RemoveChild((wxWindow
*)this);
117 m_windowParent
->RemoveChild(this);
121 // TODO: destroy the window
126 // Just in case the window has been Closed, but
127 // we're then deleting immediately: don't leave
128 // dangling pointers.
129 wxPendingDelete
.DeleteObject(this);
131 if ( m_windowValidator
)
132 delete m_windowValidator
;
135 // Destroy the window (delayed, if a managed window)
136 bool wxWindow::Destroy()
143 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
147 const wxString
& name
)
150 m_isWindow
= TRUE
; // An optimization
153 m_windowParent
= NULL
;
154 m_windowEventHandler
= this;
156 m_windowCursor
= *wxSTANDARD_CURSOR
;
157 m_constraints
= NULL
;
158 m_constraintsInvolvedIn
= NULL
;
159 m_windowSizer
= NULL
;
160 m_sizerParent
= NULL
;
161 m_autoLayout
= FALSE
;
162 m_windowValidator
= NULL
;
164 #if wxUSE_DRAG_AND_DROP
165 m_pDropTarget
= NULL
;
168 m_caretWidth
= 0; m_caretHeight
= 0;
169 m_caretEnabled
= FALSE
;
170 m_caretShown
= FALSE
;
175 m_defaultItem
= NULL
;
176 m_windowParent
= NULL
;
180 if (parent
) parent
->AddChild(this);
187 m_windowId
= (int)NewControlId();
191 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
192 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
193 m_foregroundColour
= *wxBLACK
;
195 m_windowStyle
= style
;
198 m_windowId
= (int)NewControlId();
202 // TODO: create the window
207 void wxWindow::SetFocus()
212 void wxWindow::Enable(bool enable
)
217 void wxWindow::CaptureMouse()
222 void wxWindow::ReleaseMouse()
227 // Push/pop event handler (i.e. allow a chain of event handlers
229 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
231 handler
->SetNextHandler(GetEventHandler());
232 SetEventHandler(handler
);
235 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
237 if ( GetEventHandler() )
239 wxEvtHandler
*handlerA
= GetEventHandler();
240 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
241 handlerA
->SetNextHandler(NULL
);
242 SetEventHandler(handlerB
);
255 #if wxUSE_DRAG_AND_DROP
257 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
259 if ( m_pDropTarget
!= 0 ) {
260 delete m_pDropTarget
;
263 m_pDropTarget
= pDropTarget
;
264 if ( m_pDropTarget
!= 0 )
272 // Old style file-manager drag&drop
273 void wxWindow::DragAcceptFiles(bool accept
)
279 void wxWindow::GetSize(int *x
, int *y
) const
284 void wxWindow::GetPosition(int *x
, int *y
) const
289 void wxWindow::ScreenToClient(int *x
, int *y
) const
294 void wxWindow::ClientToScreen(int *x
, int *y
) const
299 void wxWindow::SetCursor(const wxCursor
& cursor
)
301 m_windowCursor
= cursor
;
302 if (m_windowCursor
.Ok())
309 // Get size *available for subwindows* i.e. excluding menu bar etc.
310 void wxWindow::GetClientSize(int *x
, int *y
) const
315 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
320 void wxWindow::SetClientSize(int width
, int height
)
325 // For implementation purposes - sometimes decorations make the client area
327 wxPoint
wxWindow::GetClientAreaOrigin() const
329 return wxPoint(0, 0);
332 // Makes an adjustment to the window position (for example, a frame that has
333 // a toolbar that it manages itself).
334 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
336 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
338 wxPoint
pt(GetParent()->GetClientAreaOrigin());
339 x
+= pt
.x
; y
+= pt
.y
;
343 bool wxWindow::Show(bool show
)
349 bool wxWindow::IsShown() const
355 int wxWindow::GetCharHeight() const
361 int wxWindow::GetCharWidth() const
367 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
368 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
370 wxFont
*fontToUse
= (wxFont
*)theFont
;
372 fontToUse
= (wxFont
*) & m_windowFont
;
377 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
382 // Responds to colour changes: passes event on to children.
383 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
385 wxNode
*node
= GetChildren().First();
388 // Only propagate to non-top-level windows
389 wxWindow
*win
= (wxWindow
*)node
->Data();
390 if ( win
->GetParent() )
392 wxSysColourChangedEvent event2
;
393 event
.m_eventObject
= win
;
394 win
->GetEventHandler()->ProcessEvent(event2
);
401 // This can be called by the app (or wxWindows) to do default processing for the current
402 // event. Save message/event info in wxWindow so they can be used in this function.
403 long wxWindow::Default()
409 void wxWindow::InitDialog()
411 wxInitDialogEvent
event(GetId());
412 event
.SetEventObject( this );
413 GetEventHandler()->ProcessEvent(event
);
416 // Default init dialog behaviour is to transfer data to window
417 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
419 TransferDataToWindow();
422 // Caret manipulation
423 void wxWindow::CreateCaret(int w
, int h
)
427 m_caretEnabled
= TRUE
;
430 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
435 void wxWindow::ShowCaret(bool show
)
440 void wxWindow::DestroyCaret()
443 m_caretEnabled
= FALSE
;
446 void wxWindow::SetCaretPos(int x
, int y
)
451 void wxWindow::GetCaretPos(int *x
, int *y
) const
456 wxWindow
*wxGetActiveWindow()
462 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
470 void wxWindow::Centre(int direction
)
472 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
474 wxWindow
*father
= (wxWindow
*)GetParent();
478 father
->GetClientSize(&panel_width
, &panel_height
);
479 GetSize(&width
, &height
);
485 if (direction
& wxHORIZONTAL
)
486 new_x
= (int)((panel_width
- width
)/2);
488 if (direction
& wxVERTICAL
)
489 new_y
= (int)((panel_height
- height
)/2);
491 SetSize(new_x
, new_y
, -1, -1);
495 // Coordinates relative to the window
496 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
501 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
507 int wxWindow::GetScrollPos(int orient
) const
513 // This now returns the whole range, not just the number
514 // of positions that we can scroll.
515 int wxWindow::GetScrollRange(int orient
) const
521 int wxWindow::GetScrollThumb(int orient
) const
527 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
533 // New function that will replace some of the above.
534 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
535 int range
, bool refresh
)
540 // Does a physical scroll
541 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
547 void wxWindow::SetFont(const wxFont
& font
)
551 if (!m_windowFont
.Ok())
556 void wxWindow::OnChar(wxKeyEvent
& event
)
559 if ( event.KeyCode() == WXK_TAB ) {
560 // propagate the TABs to the parent - it's up to it to decide what
563 if ( GetParent()->ProcessEvent(event) )
571 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
576 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
581 void wxWindow::OnPaint(wxPaintEvent
& event
)
586 bool wxWindow::IsEnabled() const
592 // Dialog support: override these and call
593 // base class members to add functionality
594 // that can't be done using validators.
595 // NOTE: these functions assume that controls
596 // are direct children of this window, not grandchildren
597 // or other levels of descendant.
599 // Transfer values to controls. If returns FALSE,
600 // it's an application error (pops up a dialog)
601 bool wxWindow::TransferDataToWindow()
603 wxNode
*node
= GetChildren().First();
606 wxWindow
*child
= (wxWindow
*)node
->Data();
607 if ( child
->GetValidator() &&
608 !child
->GetValidator()->TransferToWindow() )
610 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
619 // Transfer values from controls. If returns FALSE,
620 // validation failed: don't quit
621 bool wxWindow::TransferDataFromWindow()
623 wxNode
*node
= GetChildren().First();
626 wxWindow
*child
= (wxWindow
*)node
->Data();
627 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
637 bool wxWindow::Validate()
639 wxNode
*node
= GetChildren().First();
642 wxWindow
*child
= (wxWindow
*)node
->Data();
643 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
653 // Get the window with the focus
654 wxWindow
*wxWindow::FindFocus()
660 void wxWindow::AddChild(wxWindow
*child
)
662 GetChildren().Append(child
);
663 child
->m_windowParent
= this;
666 void wxWindow::RemoveChild(wxWindow
*child
)
668 GetChildren().DeleteObject(child
);
669 child
->m_windowParent
= NULL
;
672 void wxWindow::DestroyChildren()
675 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
677 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
679 if ( GetChildren().Member(child
) )
685 void wxWindow::MakeModal(bool modal
)
687 // Disable all other windows
688 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
690 wxNode
*node
= wxTopLevelWindows
.First();
693 wxWindow
*win
= (wxWindow
*)node
->Data();
702 // If nothing defined for this, try the parent.
703 // E.g. we may be a button loaded from a resource, with no callback function
705 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
707 if (GetEventHandler()->ProcessEvent(event
) )
710 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
713 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
717 UnsetConstraints(m_constraints
);
718 delete m_constraints
;
723 // Make sure other windows know they're part of a 'meaningful relationship'
724 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
725 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
726 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
727 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
728 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
729 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
730 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
731 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
732 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
733 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
734 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
735 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
736 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
737 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
738 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
739 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
743 // This removes any dangling pointers to this window
744 // in other windows' constraintsInvolvedIn lists.
745 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
749 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
750 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
751 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
752 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
753 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
754 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
755 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
756 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
757 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
758 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
759 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
760 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
761 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
762 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
763 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
764 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
768 // Back-pointer to other windows we're involved with, so if we delete
769 // this window, we must delete any constraints we're involved with.
770 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
772 if (!m_constraintsInvolvedIn
)
773 m_constraintsInvolvedIn
= new wxList
;
774 if (!m_constraintsInvolvedIn
->Member(otherWin
))
775 m_constraintsInvolvedIn
->Append(otherWin
);
778 // REMOVE back-pointer to other windows we're involved with.
779 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
781 if (m_constraintsInvolvedIn
)
782 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
785 // Reset any constraints that mention this window
786 void wxWindow::DeleteRelatedConstraints()
788 if (m_constraintsInvolvedIn
)
790 wxNode
*node
= m_constraintsInvolvedIn
->First();
793 wxWindow
*win
= (wxWindow
*)node
->Data();
794 wxNode
*next
= node
->Next();
795 wxLayoutConstraints
*constr
= win
->GetConstraints();
797 // Reset any constraints involving this window
800 constr
->left
.ResetIfWin((wxWindow
*)this);
801 constr
->top
.ResetIfWin((wxWindow
*)this);
802 constr
->right
.ResetIfWin((wxWindow
*)this);
803 constr
->bottom
.ResetIfWin((wxWindow
*)this);
804 constr
->width
.ResetIfWin((wxWindow
*)this);
805 constr
->height
.ResetIfWin((wxWindow
*)this);
806 constr
->centreX
.ResetIfWin((wxWindow
*)this);
807 constr
->centreY
.ResetIfWin((wxWindow
*)this);
812 delete m_constraintsInvolvedIn
;
813 m_constraintsInvolvedIn
= NULL
;
817 void wxWindow::SetSizer(wxSizer
*sizer
)
819 m_windowSizer
= sizer
;
821 sizer
->SetSizerParent((wxWindow
*)this);
828 bool wxWindow::Layout()
830 if (GetConstraints())
833 GetClientSize(&w
, &h
);
834 GetConstraints()->width
.SetValue(w
);
835 GetConstraints()->height
.SetValue(h
);
838 // If top level (one sizer), evaluate the sizer's constraints.
842 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
843 GetSizer()->LayoutPhase1(&noChanges
);
844 GetSizer()->LayoutPhase2(&noChanges
);
845 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
850 // Otherwise, evaluate child constraints
851 ResetConstraints(); // Mark all constraints as unevaluated
852 DoPhase(1); // Just one phase need if no sizers involved
854 SetConstraintSizes(); // Recursively set the real window sizes
860 // Do a phase of evaluating constraints:
861 // the default behaviour. wxSizers may do a similar
862 // thing, but also impose their own 'constraints'
863 // and order the evaluation differently.
864 bool wxWindow::LayoutPhase1(int *noChanges
)
866 wxLayoutConstraints
*constr
= GetConstraints();
869 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
875 bool wxWindow::LayoutPhase2(int *noChanges
)
885 // Do a phase of evaluating child constraints
886 bool wxWindow::DoPhase(int phase
)
888 int noIterations
= 0;
889 int maxIterations
= 500;
893 while ((noChanges
> 0) && (noIterations
< maxIterations
))
897 wxNode
*node
= GetChildren().First();
900 wxWindow
*child
= (wxWindow
*)node
->Data();
901 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
903 wxLayoutConstraints
*constr
= child
->GetConstraints();
906 if (succeeded
.Member(child
))
911 int tempNoChanges
= 0;
912 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
913 noChanges
+= tempNoChanges
;
916 succeeded
.Append(child
);
928 void wxWindow::ResetConstraints()
930 wxLayoutConstraints
*constr
= GetConstraints();
933 constr
->left
.SetDone(FALSE
);
934 constr
->top
.SetDone(FALSE
);
935 constr
->right
.SetDone(FALSE
);
936 constr
->bottom
.SetDone(FALSE
);
937 constr
->width
.SetDone(FALSE
);
938 constr
->height
.SetDone(FALSE
);
939 constr
->centreX
.SetDone(FALSE
);
940 constr
->centreY
.SetDone(FALSE
);
942 wxNode
*node
= GetChildren().First();
945 wxWindow
*win
= (wxWindow
*)node
->Data();
946 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
947 win
->ResetConstraints();
952 // Need to distinguish between setting the 'fake' size for
953 // windows and sizers, and setting the real values.
954 void wxWindow::SetConstraintSizes(bool recurse
)
956 wxLayoutConstraints
*constr
= GetConstraints();
957 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
958 constr
->width
.GetDone() && constr
->height
.GetDone())
960 int x
= constr
->left
.GetValue();
961 int y
= constr
->top
.GetValue();
962 int w
= constr
->width
.GetValue();
963 int h
= constr
->height
.GetValue();
965 // If we don't want to resize this window, just move it...
966 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
967 (constr
->height
.GetRelationship() != wxAsIs
))
969 // Calls Layout() recursively. AAAGH. How can we stop that.
970 // Simply take Layout() out of non-top level OnSizes.
971 SizerSetSize(x
, y
, w
, h
);
980 char *windowClass
= this->GetClassInfo()->GetClassName();
987 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
988 if (!constr
->left
.GetDone())
989 wxDebugMsg(" unsatisfied 'left' constraint.\n");
990 if (!constr
->right
.GetDone())
991 wxDebugMsg(" unsatisfied 'right' constraint.\n");
992 if (!constr
->width
.GetDone())
993 wxDebugMsg(" unsatisfied 'width' constraint.\n");
994 if (!constr
->height
.GetDone())
995 wxDebugMsg(" unsatisfied 'height' constraint.\n");
996 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1001 wxNode
*node
= GetChildren().First();
1004 wxWindow
*win
= (wxWindow
*)node
->Data();
1005 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1006 win
->SetConstraintSizes();
1007 node
= node
->Next();
1012 // This assumes that all sizers are 'on' the same
1013 // window, i.e. the parent of this window.
1014 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1016 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1017 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1021 m_sizerParent
->GetPosition(&xp
, &yp
);
1022 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1027 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1031 TransformSizerToActual(&xx
, &yy
);
1032 SetSize(xx
, yy
, w
, h
);
1035 void wxWindow::SizerMove(int x
, int y
)
1039 TransformSizerToActual(&xx
, &yy
);
1043 // Only set the size/position of the constraint (if any)
1044 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1046 wxLayoutConstraints
*constr
= GetConstraints();
1051 constr
->left
.SetValue(x
);
1052 constr
->left
.SetDone(TRUE
);
1056 constr
->top
.SetValue(y
);
1057 constr
->top
.SetDone(TRUE
);
1061 constr
->width
.SetValue(w
);
1062 constr
->width
.SetDone(TRUE
);
1066 constr
->height
.SetValue(h
);
1067 constr
->height
.SetDone(TRUE
);
1072 void wxWindow::MoveConstraint(int x
, int y
)
1074 wxLayoutConstraints
*constr
= GetConstraints();
1079 constr
->left
.SetValue(x
);
1080 constr
->left
.SetDone(TRUE
);
1084 constr
->top
.SetValue(y
);
1085 constr
->top
.SetDone(TRUE
);
1090 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1092 wxLayoutConstraints
*constr
= GetConstraints();
1095 *w
= constr
->width
.GetValue();
1096 *h
= constr
->height
.GetValue();
1102 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1104 wxLayoutConstraints
*constr
= GetConstraints();
1107 *w
= constr
->width
.GetValue();
1108 *h
= constr
->height
.GetValue();
1111 GetClientSize(w
, h
);
1114 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1116 wxLayoutConstraints
*constr
= GetConstraints();
1119 *x
= constr
->left
.GetValue();
1120 *y
= constr
->top
.GetValue();
1126 bool wxWindow::Close(bool force
)
1128 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1129 event
.SetEventObject(this);
1130 #if WXWIN_COMPATIBILITY
1131 event
.SetForce(force
);
1133 event
.SetCanVeto(!force
);
1135 return GetEventHandler()->ProcessEvent(event
);
1138 wxObject
* wxWindow::GetChild(int number
) const
1140 // Return a pointer to the Nth object in the window
1141 wxNode
*node
= GetChildren().First();
1144 node
= node
->Next() ;
1147 wxObject
*obj
= (wxObject
*)node
->Data();
1154 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1156 // Obsolete function
1159 void wxWindow::Clear()
1161 wxClientDC
dc(this);
1162 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1163 dc
.SetBackground(brush
);
1167 // Fits the panel around the items
1168 void wxWindow::Fit()
1172 wxNode
*node
= GetChildren().First();
1175 wxWindow
*win
= (wxWindow
*)node
->Data();
1177 win
->GetPosition(&wx
, &wy
);
1178 win
->GetSize(&ww
, &wh
);
1179 if ( wx
+ ww
> maxX
)
1181 if ( wy
+ wh
> maxY
)
1184 node
= node
->Next();
1186 SetClientSize(maxX
+ 5, maxY
+ 5);
1189 void wxWindow::SetValidator(const wxValidator
& validator
)
1191 if ( m_windowValidator
)
1192 delete m_windowValidator
;
1193 m_windowValidator
= validator
.Clone();
1195 if ( m_windowValidator
)
1196 m_windowValidator
->SetWindow(this) ;
1199 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1201 m_acceleratorTable
= accel
;
1204 // Find a window by id or name
1205 wxWindow
*wxWindow::FindWindow(long id
)
1210 wxNode
*node
= GetChildren().First();
1213 wxWindow
*child
= (wxWindow
*)node
->Data();
1214 wxWindow
*found
= child
->FindWindow(id
);
1217 node
= node
->Next();
1222 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1224 if ( GetName() == name
)
1227 wxNode
*node
= GetChildren().First();
1230 wxWindow
*child
= (wxWindow
*)node
->Data();
1231 wxWindow
*found
= child
->FindWindow(name
);
1234 node
= node
->Next();
1239 void wxWindow::OnIdle(wxIdleEvent
& event
)
1241 /* TODO: you may need to do something like this
1242 * if your GUI doesn't generate enter/leave events
1244 // Check if we need to send a LEAVE event
1245 if (m_mouseInWindow)
1248 ::GetCursorPos(&pt);
1249 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1251 // Generate a LEAVE event
1252 m_mouseInWindow = FALSE;
1253 MSWOnMouseLeave(pt.x, pt.y, 0);
1258 // This calls the UI-update mechanism (querying windows for
1259 // menu/toolbar/control state information)
1263 // Raise the window to the top of the Z order
1264 void wxWindow::Raise()
1269 // Lower the window to the bottom of the Z order
1270 void wxWindow::Lower()
1275 bool wxWindow::AcceptsFocus() const
1277 return IsShown() && IsEnabled();
1280 // Update region access
1281 wxRegion
wxWindow::GetUpdateRegion() const
1283 return m_updateRegion
;
1286 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1288 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1291 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1293 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1296 bool wxWindow::IsExposed(const wxRect
& rect
) const
1298 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1301 void wxWindow::SetToolTip(const wxString
& tooltip
)
1307 * Allocates control IDs
1310 int wxWindow::NewControlId()
1312 static int s_controlId
= 0;