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_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_3DFACE
) ;
79 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
80 m_foregroundColour
= *wxBLACK
;
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_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
189 m_foregroundColour
= *wxBLACK
;
191 m_windowStyle
= style
;
194 m_windowId
= (int)NewControlId();
198 // TODO: create the window
203 void wxWindow::SetFocus()
208 void wxWindow::Enable(bool enable
)
213 void wxWindow::CaptureMouse()
218 void wxWindow::ReleaseMouse()
223 // Push/pop event handler (i.e. allow a chain of event handlers
225 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
227 handler
->SetNextHandler(GetEventHandler());
228 SetEventHandler(handler
);
231 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
233 if ( GetEventHandler() )
235 wxEvtHandler
*handlerA
= GetEventHandler();
236 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
237 handlerA
->SetNextHandler(NULL
);
238 SetEventHandler(handlerB
);
251 #if wxUSE_DRAG_AND_DROP
253 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
255 if ( m_pDropTarget
!= 0 ) {
256 delete m_pDropTarget
;
259 m_pDropTarget
= pDropTarget
;
260 if ( m_pDropTarget
!= 0 )
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
)
651 GetChildren().DeleteObject(child
);
652 child
->m_windowParent
= NULL
;
655 void wxWindow::DestroyChildren()
658 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
660 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
662 if ( GetChildren().Member(child
) )
668 void wxWindow::MakeModal(bool modal
)
670 // Disable all other windows
671 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
673 wxNode
*node
= wxTopLevelWindows
.First();
676 wxWindow
*win
= (wxWindow
*)node
->Data();
685 // If nothing defined for this, try the parent.
686 // E.g. we may be a button loaded from a resource, with no callback function
688 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
690 if (GetEventHandler()->ProcessEvent(event
) )
693 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
696 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
700 UnsetConstraints(m_constraints
);
701 delete m_constraints
;
706 // Make sure other windows know they're part of a 'meaningful relationship'
707 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
708 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
709 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
710 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
711 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
712 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
713 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
714 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
715 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
716 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
717 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
718 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
719 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
720 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
721 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
722 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
726 // This removes any dangling pointers to this window
727 // in other windows' constraintsInvolvedIn lists.
728 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
732 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
733 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
734 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
735 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
736 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
737 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
738 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
739 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
740 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
741 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
742 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
743 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
744 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
745 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
746 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
747 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
751 // Back-pointer to other windows we're involved with, so if we delete
752 // this window, we must delete any constraints we're involved with.
753 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
755 if (!m_constraintsInvolvedIn
)
756 m_constraintsInvolvedIn
= new wxList
;
757 if (!m_constraintsInvolvedIn
->Member(otherWin
))
758 m_constraintsInvolvedIn
->Append(otherWin
);
761 // REMOVE back-pointer to other windows we're involved with.
762 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
764 if (m_constraintsInvolvedIn
)
765 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
768 // Reset any constraints that mention this window
769 void wxWindow::DeleteRelatedConstraints()
771 if (m_constraintsInvolvedIn
)
773 wxNode
*node
= m_constraintsInvolvedIn
->First();
776 wxWindow
*win
= (wxWindow
*)node
->Data();
777 wxNode
*next
= node
->Next();
778 wxLayoutConstraints
*constr
= win
->GetConstraints();
780 // Reset any constraints involving this window
783 constr
->left
.ResetIfWin((wxWindow
*)this);
784 constr
->top
.ResetIfWin((wxWindow
*)this);
785 constr
->right
.ResetIfWin((wxWindow
*)this);
786 constr
->bottom
.ResetIfWin((wxWindow
*)this);
787 constr
->width
.ResetIfWin((wxWindow
*)this);
788 constr
->height
.ResetIfWin((wxWindow
*)this);
789 constr
->centreX
.ResetIfWin((wxWindow
*)this);
790 constr
->centreY
.ResetIfWin((wxWindow
*)this);
795 delete m_constraintsInvolvedIn
;
796 m_constraintsInvolvedIn
= NULL
;
800 void wxWindow::SetSizer(wxSizer
*sizer
)
802 m_windowSizer
= sizer
;
804 sizer
->SetSizerParent((wxWindow
*)this);
811 bool wxWindow::Layout()
813 if (GetConstraints())
816 GetClientSize(&w
, &h
);
817 GetConstraints()->width
.SetValue(w
);
818 GetConstraints()->height
.SetValue(h
);
821 // If top level (one sizer), evaluate the sizer's constraints.
825 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
826 GetSizer()->LayoutPhase1(&noChanges
);
827 GetSizer()->LayoutPhase2(&noChanges
);
828 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
833 // Otherwise, evaluate child constraints
834 ResetConstraints(); // Mark all constraints as unevaluated
835 DoPhase(1); // Just one phase need if no sizers involved
837 SetConstraintSizes(); // Recursively set the real window sizes
843 // Do a phase of evaluating constraints:
844 // the default behaviour. wxSizers may do a similar
845 // thing, but also impose their own 'constraints'
846 // and order the evaluation differently.
847 bool wxWindow::LayoutPhase1(int *noChanges
)
849 wxLayoutConstraints
*constr
= GetConstraints();
852 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
858 bool wxWindow::LayoutPhase2(int *noChanges
)
868 // Do a phase of evaluating child constraints
869 bool wxWindow::DoPhase(int phase
)
871 int noIterations
= 0;
872 int maxIterations
= 500;
876 while ((noChanges
> 0) && (noIterations
< maxIterations
))
880 wxNode
*node
= GetChildren().First();
883 wxWindow
*child
= (wxWindow
*)node
->Data();
884 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
886 wxLayoutConstraints
*constr
= child
->GetConstraints();
889 if (succeeded
.Member(child
))
894 int tempNoChanges
= 0;
895 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
896 noChanges
+= tempNoChanges
;
899 succeeded
.Append(child
);
911 void wxWindow::ResetConstraints()
913 wxLayoutConstraints
*constr
= GetConstraints();
916 constr
->left
.SetDone(FALSE
);
917 constr
->top
.SetDone(FALSE
);
918 constr
->right
.SetDone(FALSE
);
919 constr
->bottom
.SetDone(FALSE
);
920 constr
->width
.SetDone(FALSE
);
921 constr
->height
.SetDone(FALSE
);
922 constr
->centreX
.SetDone(FALSE
);
923 constr
->centreY
.SetDone(FALSE
);
925 wxNode
*node
= GetChildren().First();
928 wxWindow
*win
= (wxWindow
*)node
->Data();
929 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
930 win
->ResetConstraints();
935 // Need to distinguish between setting the 'fake' size for
936 // windows and sizers, and setting the real values.
937 void wxWindow::SetConstraintSizes(bool recurse
)
939 wxLayoutConstraints
*constr
= GetConstraints();
940 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
941 constr
->width
.GetDone() && constr
->height
.GetDone())
943 int x
= constr
->left
.GetValue();
944 int y
= constr
->top
.GetValue();
945 int w
= constr
->width
.GetValue();
946 int h
= constr
->height
.GetValue();
948 // If we don't want to resize this window, just move it...
949 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
950 (constr
->height
.GetRelationship() != wxAsIs
))
952 // Calls Layout() recursively. AAAGH. How can we stop that.
953 // Simply take Layout() out of non-top level OnSizes.
954 SizerSetSize(x
, y
, w
, h
);
963 char *windowClass
= this->GetClassInfo()->GetClassName();
970 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
971 if (!constr
->left
.GetDone())
972 wxDebugMsg(" unsatisfied 'left' constraint.\n");
973 if (!constr
->right
.GetDone())
974 wxDebugMsg(" unsatisfied 'right' constraint.\n");
975 if (!constr
->width
.GetDone())
976 wxDebugMsg(" unsatisfied 'width' constraint.\n");
977 if (!constr
->height
.GetDone())
978 wxDebugMsg(" unsatisfied 'height' constraint.\n");
979 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
984 wxNode
*node
= GetChildren().First();
987 wxWindow
*win
= (wxWindow
*)node
->Data();
988 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
989 win
->SetConstraintSizes();
995 // This assumes that all sizers are 'on' the same
996 // window, i.e. the parent of this window.
997 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
999 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1000 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1004 m_sizerParent
->GetPosition(&xp
, &yp
);
1005 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1010 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1014 TransformSizerToActual(&xx
, &yy
);
1015 SetSize(xx
, yy
, w
, h
);
1018 void wxWindow::SizerMove(int x
, int y
)
1022 TransformSizerToActual(&xx
, &yy
);
1026 // Only set the size/position of the constraint (if any)
1027 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1029 wxLayoutConstraints
*constr
= GetConstraints();
1034 constr
->left
.SetValue(x
);
1035 constr
->left
.SetDone(TRUE
);
1039 constr
->top
.SetValue(y
);
1040 constr
->top
.SetDone(TRUE
);
1044 constr
->width
.SetValue(w
);
1045 constr
->width
.SetDone(TRUE
);
1049 constr
->height
.SetValue(h
);
1050 constr
->height
.SetDone(TRUE
);
1055 void wxWindow::MoveConstraint(int x
, int y
)
1057 wxLayoutConstraints
*constr
= GetConstraints();
1062 constr
->left
.SetValue(x
);
1063 constr
->left
.SetDone(TRUE
);
1067 constr
->top
.SetValue(y
);
1068 constr
->top
.SetDone(TRUE
);
1073 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1075 wxLayoutConstraints
*constr
= GetConstraints();
1078 *w
= constr
->width
.GetValue();
1079 *h
= constr
->height
.GetValue();
1085 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1087 wxLayoutConstraints
*constr
= GetConstraints();
1090 *w
= constr
->width
.GetValue();
1091 *h
= constr
->height
.GetValue();
1094 GetClientSize(w
, h
);
1097 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1099 wxLayoutConstraints
*constr
= GetConstraints();
1102 *x
= constr
->left
.GetValue();
1103 *y
= constr
->top
.GetValue();
1109 bool wxWindow::Close(bool force
)
1111 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1112 event
.SetEventObject(this);
1113 event
.SetForce(force
);
1115 return GetEventHandler()->ProcessEvent(event
);
1118 wxObject
* wxWindow::GetChild(int number
) const
1120 // Return a pointer to the Nth object in the window
1121 wxNode
*node
= GetChildren().First();
1124 node
= node
->Next() ;
1127 wxObject
*obj
= (wxObject
*)node
->Data();
1134 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1136 // Obsolete function
1139 void wxWindow::Clear()
1141 wxClientDC
dc(this);
1142 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1143 dc
.SetBackground(brush
);
1147 // Fits the panel around the items
1148 void wxWindow::Fit()
1152 wxNode
*node
= GetChildren().First();
1155 wxWindow
*win
= (wxWindow
*)node
->Data();
1157 win
->GetPosition(&wx
, &wy
);
1158 win
->GetSize(&ww
, &wh
);
1159 if ( wx
+ ww
> maxX
)
1161 if ( wy
+ wh
> maxY
)
1164 node
= node
->Next();
1166 SetClientSize(maxX
+ 5, maxY
+ 5);
1169 void wxWindow::SetValidator(const wxValidator
& validator
)
1171 if ( m_windowValidator
)
1172 delete m_windowValidator
;
1173 m_windowValidator
= validator
.Clone();
1175 if ( m_windowValidator
)
1176 m_windowValidator
->SetWindow(this) ;
1179 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1181 m_acceleratorTable
= accel
;
1184 // Find a window by id or name
1185 wxWindow
*wxWindow::FindWindow(long id
)
1190 wxNode
*node
= GetChildren().First();
1193 wxWindow
*child
= (wxWindow
*)node
->Data();
1194 wxWindow
*found
= child
->FindWindow(id
);
1197 node
= node
->Next();
1202 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1204 if ( GetName() == name
)
1207 wxNode
*node
= GetChildren().First();
1210 wxWindow
*child
= (wxWindow
*)node
->Data();
1211 wxWindow
*found
= child
->FindWindow(name
);
1214 node
= node
->Next();
1219 void wxWindow::OnIdle(wxIdleEvent
& event
)
1221 /* TODO: you may need to do something like this
1222 * if your GUI doesn't generate enter/leave events
1224 // Check if we need to send a LEAVE event
1225 if (m_mouseInWindow)
1228 ::GetCursorPos(&pt);
1229 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1231 // Generate a LEAVE event
1232 m_mouseInWindow = FALSE;
1233 MSWOnMouseLeave(pt.x, pt.y, 0);
1238 // This calls the UI-update mechanism (querying windows for
1239 // menu/toolbar/control state information)
1243 // Raise the window to the top of the Z order
1244 void wxWindow::Raise()
1249 // Lower the window to the bottom of the Z order
1250 void wxWindow::Lower()
1255 bool wxWindow::AcceptsFocus() const
1257 return IsShown() && IsEnabled();
1260 // Update region access
1261 wxRegion
wxWindow::GetUpdateRegion() const
1263 return m_updateRegion
;
1266 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1268 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1271 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1273 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1276 bool wxWindow::IsExposed(const wxRect
& rect
) const
1278 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1282 * Allocates control IDs
1285 int wxWindow::NewControlId()
1287 static int s_controlId
= 0;