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
)
64 m_windowParent
= NULL
;
65 m_windowEventHandler
= this;
67 m_windowCursor
= *wxSTANDARD_CURSOR
;
68 m_children
= new wxList
;
70 m_constraintsInvolvedIn
= NULL
;
74 m_windowValidator
= NULL
;
77 m_caretWidth
= 0; m_caretHeight
= 0;
78 m_caretEnabled
= FALSE
;
80 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
81 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
82 m_foregroundColour
= *wxBLACK
;
84 #if wxUSE_DRAG_AND_DROP
92 // Have to delete constraints/sizer FIRST otherwise
93 // sizers may try to look at deleted windows as they
96 DeleteRelatedConstraints();
99 // This removes any dangling pointers to this window
100 // in other windows' constraintsInvolvedIn lists.
101 UnsetConstraints(m_constraints
);
102 delete m_constraints
;
103 m_constraints
= NULL
;
107 delete m_windowSizer
;
108 m_windowSizer
= NULL
;
110 // If this is a child of a sizer, remove self from parent
112 m_sizerParent
->RemoveChild((wxWindow
*)this);
116 m_windowParent
->RemoveChild(this);
120 // TODO: destroy the window
125 // Just in case the window has been Closed, but
126 // we're then deleting immediately: don't leave
127 // dangling pointers.
128 wxPendingDelete
.DeleteObject(this);
130 if ( m_windowValidator
)
131 delete m_windowValidator
;
134 // Destroy the window (delayed, if a managed window)
135 bool wxWindow::Destroy()
142 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
146 const wxString
& name
)
151 m_windowParent
= NULL
;
152 m_windowEventHandler
= this;
154 m_windowCursor
= *wxSTANDARD_CURSOR
;
155 m_constraints
= NULL
;
156 m_constraintsInvolvedIn
= NULL
;
157 m_windowSizer
= NULL
;
158 m_sizerParent
= NULL
;
159 m_autoLayout
= FALSE
;
160 m_windowValidator
= NULL
;
162 #if wxUSE_DRAG_AND_DROP
163 m_pDropTarget
= NULL
;
166 m_caretWidth
= 0; m_caretHeight
= 0;
167 m_caretEnabled
= FALSE
;
168 m_caretShown
= FALSE
;
173 m_defaultItem
= NULL
;
174 m_windowParent
= NULL
;
178 if (parent
) parent
->AddChild(this);
185 m_windowId
= (int)NewControlId();
189 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
190 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
191 m_foregroundColour
= *wxBLACK
;
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 wxUSE_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 wxRect
*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 wxRect
*rect
)
545 void wxWindow::SetFont(const wxFont
& font
)
549 if (!m_windowFont
.Ok())
554 void wxWindow::OnChar(wxKeyEvent
& event
)
557 if ( event.KeyCode() == WXK_TAB ) {
558 // propagate the TABs to the parent - it's up to it to decide what
561 if ( GetParent()->ProcessEvent(event) )
569 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
574 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
579 void wxWindow::OnPaint(wxPaintEvent
& event
)
584 bool wxWindow::IsEnabled() const
590 // Dialog support: override these and call
591 // base class members to add functionality
592 // that can't be done using validators.
593 // NOTE: these functions assume that controls
594 // are direct children of this window, not grandchildren
595 // or other levels of descendant.
597 // Transfer values to controls. If returns FALSE,
598 // it's an application error (pops up a dialog)
599 bool wxWindow::TransferDataToWindow()
601 wxNode
*node
= GetChildren().First();
604 wxWindow
*child
= (wxWindow
*)node
->Data();
605 if ( child
->GetValidator() &&
606 !child
->GetValidator()->TransferToWindow() )
608 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
617 // Transfer values from controls. If returns FALSE,
618 // validation failed: don't quit
619 bool wxWindow::TransferDataFromWindow()
621 wxNode
*node
= GetChildren().First();
624 wxWindow
*child
= (wxWindow
*)node
->Data();
625 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
635 bool wxWindow::Validate()
637 wxNode
*node
= GetChildren().First();
640 wxWindow
*child
= (wxWindow
*)node
->Data();
641 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
651 // Get the window with the focus
652 wxWindow
*wxWindow::FindFocus()
658 void wxWindow::AddChild(wxWindow
*child
)
660 GetChildren().Append(child
);
661 child
->m_windowParent
= this;
664 void wxWindow::RemoveChild(wxWindow
*child
)
666 GetChildren().DeleteObject(child
);
667 child
->m_windowParent
= NULL
;
670 void wxWindow::DestroyChildren()
673 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
675 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
677 if ( GetChildren().Member(child
) )
683 void wxWindow::MakeModal(bool modal
)
685 // Disable all other windows
686 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
688 wxNode
*node
= wxTopLevelWindows
.First();
691 wxWindow
*win
= (wxWindow
*)node
->Data();
700 // If nothing defined for this, try the parent.
701 // E.g. we may be a button loaded from a resource, with no callback function
703 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
705 if (GetEventHandler()->ProcessEvent(event
) )
708 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
711 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
715 UnsetConstraints(m_constraints
);
716 delete m_constraints
;
721 // Make sure other windows know they're part of a 'meaningful relationship'
722 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
723 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
724 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
725 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
726 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
727 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
728 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
729 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
730 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
731 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
732 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
733 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
734 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
735 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
736 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
737 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
741 // This removes any dangling pointers to this window
742 // in other windows' constraintsInvolvedIn lists.
743 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
747 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
748 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
749 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
750 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
751 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
752 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
753 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
754 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
755 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
756 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
757 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
758 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
759 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
760 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
761 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
762 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
766 // Back-pointer to other windows we're involved with, so if we delete
767 // this window, we must delete any constraints we're involved with.
768 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
770 if (!m_constraintsInvolvedIn
)
771 m_constraintsInvolvedIn
= new wxList
;
772 if (!m_constraintsInvolvedIn
->Member(otherWin
))
773 m_constraintsInvolvedIn
->Append(otherWin
);
776 // REMOVE back-pointer to other windows we're involved with.
777 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
779 if (m_constraintsInvolvedIn
)
780 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
783 // Reset any constraints that mention this window
784 void wxWindow::DeleteRelatedConstraints()
786 if (m_constraintsInvolvedIn
)
788 wxNode
*node
= m_constraintsInvolvedIn
->First();
791 wxWindow
*win
= (wxWindow
*)node
->Data();
792 wxNode
*next
= node
->Next();
793 wxLayoutConstraints
*constr
= win
->GetConstraints();
795 // Reset any constraints involving this window
798 constr
->left
.ResetIfWin((wxWindow
*)this);
799 constr
->top
.ResetIfWin((wxWindow
*)this);
800 constr
->right
.ResetIfWin((wxWindow
*)this);
801 constr
->bottom
.ResetIfWin((wxWindow
*)this);
802 constr
->width
.ResetIfWin((wxWindow
*)this);
803 constr
->height
.ResetIfWin((wxWindow
*)this);
804 constr
->centreX
.ResetIfWin((wxWindow
*)this);
805 constr
->centreY
.ResetIfWin((wxWindow
*)this);
810 delete m_constraintsInvolvedIn
;
811 m_constraintsInvolvedIn
= NULL
;
815 void wxWindow::SetSizer(wxSizer
*sizer
)
817 m_windowSizer
= sizer
;
819 sizer
->SetSizerParent((wxWindow
*)this);
826 bool wxWindow::Layout()
828 if (GetConstraints())
831 GetClientSize(&w
, &h
);
832 GetConstraints()->width
.SetValue(w
);
833 GetConstraints()->height
.SetValue(h
);
836 // If top level (one sizer), evaluate the sizer's constraints.
840 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
841 GetSizer()->LayoutPhase1(&noChanges
);
842 GetSizer()->LayoutPhase2(&noChanges
);
843 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
848 // Otherwise, evaluate child constraints
849 ResetConstraints(); // Mark all constraints as unevaluated
850 DoPhase(1); // Just one phase need if no sizers involved
852 SetConstraintSizes(); // Recursively set the real window sizes
858 // Do a phase of evaluating constraints:
859 // the default behaviour. wxSizers may do a similar
860 // thing, but also impose their own 'constraints'
861 // and order the evaluation differently.
862 bool wxWindow::LayoutPhase1(int *noChanges
)
864 wxLayoutConstraints
*constr
= GetConstraints();
867 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
873 bool wxWindow::LayoutPhase2(int *noChanges
)
883 // Do a phase of evaluating child constraints
884 bool wxWindow::DoPhase(int phase
)
886 int noIterations
= 0;
887 int maxIterations
= 500;
891 while ((noChanges
> 0) && (noIterations
< maxIterations
))
895 wxNode
*node
= GetChildren().First();
898 wxWindow
*child
= (wxWindow
*)node
->Data();
899 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
901 wxLayoutConstraints
*constr
= child
->GetConstraints();
904 if (succeeded
.Member(child
))
909 int tempNoChanges
= 0;
910 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
911 noChanges
+= tempNoChanges
;
914 succeeded
.Append(child
);
926 void wxWindow::ResetConstraints()
928 wxLayoutConstraints
*constr
= GetConstraints();
931 constr
->left
.SetDone(FALSE
);
932 constr
->top
.SetDone(FALSE
);
933 constr
->right
.SetDone(FALSE
);
934 constr
->bottom
.SetDone(FALSE
);
935 constr
->width
.SetDone(FALSE
);
936 constr
->height
.SetDone(FALSE
);
937 constr
->centreX
.SetDone(FALSE
);
938 constr
->centreY
.SetDone(FALSE
);
940 wxNode
*node
= GetChildren().First();
943 wxWindow
*win
= (wxWindow
*)node
->Data();
944 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
945 win
->ResetConstraints();
950 // Need to distinguish between setting the 'fake' size for
951 // windows and sizers, and setting the real values.
952 void wxWindow::SetConstraintSizes(bool recurse
)
954 wxLayoutConstraints
*constr
= GetConstraints();
955 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
956 constr
->width
.GetDone() && constr
->height
.GetDone())
958 int x
= constr
->left
.GetValue();
959 int y
= constr
->top
.GetValue();
960 int w
= constr
->width
.GetValue();
961 int h
= constr
->height
.GetValue();
963 // If we don't want to resize this window, just move it...
964 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
965 (constr
->height
.GetRelationship() != wxAsIs
))
967 // Calls Layout() recursively. AAAGH. How can we stop that.
968 // Simply take Layout() out of non-top level OnSizes.
969 SizerSetSize(x
, y
, w
, h
);
978 char *windowClass
= this->GetClassInfo()->GetClassName();
985 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
986 if (!constr
->left
.GetDone())
987 wxDebugMsg(" unsatisfied 'left' constraint.\n");
988 if (!constr
->right
.GetDone())
989 wxDebugMsg(" unsatisfied 'right' constraint.\n");
990 if (!constr
->width
.GetDone())
991 wxDebugMsg(" unsatisfied 'width' constraint.\n");
992 if (!constr
->height
.GetDone())
993 wxDebugMsg(" unsatisfied 'height' constraint.\n");
994 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
999 wxNode
*node
= GetChildren().First();
1002 wxWindow
*win
= (wxWindow
*)node
->Data();
1003 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1004 win
->SetConstraintSizes();
1005 node
= node
->Next();
1010 // This assumes that all sizers are 'on' the same
1011 // window, i.e. the parent of this window.
1012 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1014 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1015 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1019 m_sizerParent
->GetPosition(&xp
, &yp
);
1020 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1025 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1029 TransformSizerToActual(&xx
, &yy
);
1030 SetSize(xx
, yy
, w
, h
);
1033 void wxWindow::SizerMove(int x
, int y
)
1037 TransformSizerToActual(&xx
, &yy
);
1041 // Only set the size/position of the constraint (if any)
1042 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1044 wxLayoutConstraints
*constr
= GetConstraints();
1049 constr
->left
.SetValue(x
);
1050 constr
->left
.SetDone(TRUE
);
1054 constr
->top
.SetValue(y
);
1055 constr
->top
.SetDone(TRUE
);
1059 constr
->width
.SetValue(w
);
1060 constr
->width
.SetDone(TRUE
);
1064 constr
->height
.SetValue(h
);
1065 constr
->height
.SetDone(TRUE
);
1070 void wxWindow::MoveConstraint(int x
, int y
)
1072 wxLayoutConstraints
*constr
= GetConstraints();
1077 constr
->left
.SetValue(x
);
1078 constr
->left
.SetDone(TRUE
);
1082 constr
->top
.SetValue(y
);
1083 constr
->top
.SetDone(TRUE
);
1088 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1090 wxLayoutConstraints
*constr
= GetConstraints();
1093 *w
= constr
->width
.GetValue();
1094 *h
= constr
->height
.GetValue();
1100 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1102 wxLayoutConstraints
*constr
= GetConstraints();
1105 *w
= constr
->width
.GetValue();
1106 *h
= constr
->height
.GetValue();
1109 GetClientSize(w
, h
);
1112 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1114 wxLayoutConstraints
*constr
= GetConstraints();
1117 *x
= constr
->left
.GetValue();
1118 *y
= constr
->top
.GetValue();
1124 bool wxWindow::Close(bool force
)
1126 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1127 event
.SetEventObject(this);
1128 event
.SetForce(force
);
1130 return GetEventHandler()->ProcessEvent(event
);
1133 wxObject
* wxWindow::GetChild(int number
) const
1135 // Return a pointer to the Nth object in the window
1136 wxNode
*node
= GetChildren().First();
1139 node
= node
->Next() ;
1142 wxObject
*obj
= (wxObject
*)node
->Data();
1149 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1151 // Obsolete function
1154 void wxWindow::Clear()
1156 wxClientDC
dc(this);
1157 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1158 dc
.SetBackground(brush
);
1162 // Fits the panel around the items
1163 void wxWindow::Fit()
1167 wxNode
*node
= GetChildren().First();
1170 wxWindow
*win
= (wxWindow
*)node
->Data();
1172 win
->GetPosition(&wx
, &wy
);
1173 win
->GetSize(&ww
, &wh
);
1174 if ( wx
+ ww
> maxX
)
1176 if ( wy
+ wh
> maxY
)
1179 node
= node
->Next();
1181 SetClientSize(maxX
+ 5, maxY
+ 5);
1184 void wxWindow::SetValidator(const wxValidator
& validator
)
1186 if ( m_windowValidator
)
1187 delete m_windowValidator
;
1188 m_windowValidator
= validator
.Clone();
1190 if ( m_windowValidator
)
1191 m_windowValidator
->SetWindow(this) ;
1194 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1196 m_acceleratorTable
= accel
;
1199 // Find a window by id or name
1200 wxWindow
*wxWindow::FindWindow(long id
)
1205 wxNode
*node
= GetChildren().First();
1208 wxWindow
*child
= (wxWindow
*)node
->Data();
1209 wxWindow
*found
= child
->FindWindow(id
);
1212 node
= node
->Next();
1217 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1219 if ( GetName() == name
)
1222 wxNode
*node
= GetChildren().First();
1225 wxWindow
*child
= (wxWindow
*)node
->Data();
1226 wxWindow
*found
= child
->FindWindow(name
);
1229 node
= node
->Next();
1234 void wxWindow::OnIdle(wxIdleEvent
& event
)
1236 /* TODO: you may need to do something like this
1237 * if your GUI doesn't generate enter/leave events
1239 // Check if we need to send a LEAVE event
1240 if (m_mouseInWindow)
1243 ::GetCursorPos(&pt);
1244 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1246 // Generate a LEAVE event
1247 m_mouseInWindow = FALSE;
1248 MSWOnMouseLeave(pt.x, pt.y, 0);
1253 // This calls the UI-update mechanism (querying windows for
1254 // menu/toolbar/control state information)
1258 // Raise the window to the top of the Z order
1259 void wxWindow::Raise()
1264 // Lower the window to the bottom of the Z order
1265 void wxWindow::Lower()
1270 bool wxWindow::AcceptsFocus() const
1272 return IsShown() && IsEnabled();
1275 // Update region access
1276 wxRegion
wxWindow::GetUpdateRegion() const
1278 return m_updateRegion
;
1281 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1283 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1286 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1288 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1291 bool wxWindow::IsExposed(const wxRect
& rect
) const
1293 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1296 void wxWindow::SetToolTip(const wxString
& tooltip
)
1302 * Allocates control IDs
1305 int wxWindow::NewControlId()
1307 static int s_controlId
= 0;