#include "wx/window.h"
#include "wx/checkbox.h"
#include "wx/radiobut.h"
+ #include "wx/textctrl.h"
#include "wx/settings.h"
#include "wx/dialog.h"
#endif //WX_PRECOMP
m_backgroundColour = settings.GetSystemColour(wxSYS_COLOUR_BTNFACE);
m_foregroundColour = *wxBLACK; // TODO take this from sys settings too?
+#ifndef __WXMAC__
m_font = *wxSWISS_FONT; // and this?
-
+#else
+ m_font = settings.GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
+#endif
// no style bits
m_windowStyle = 0;
const wxPoint& WXUNUSED(pos),
const wxSize& WXUNUSED(size),
long style,
+#if wxUSE_VALIDATORS
const wxValidator& validator,
+#endif
const wxString& name)
{
// m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
}
// ----------------------------------------------------------------------------
-// centre/fit the window
+// size/position related methods
// ----------------------------------------------------------------------------
// centre the window with respect to its parent in either (or both) directions
yNew += posParent.y;
}
+ // move the centre of this window to this position
Move(xNew, yNew);
}
// fits the window around the children
void wxWindowBase::Fit()
{
- int maxX = 0,
- maxY = 0;
+ if ( GetChildren().GetCount() > 0 )
+ {
+ SetClientSize(DoGetBestSize());
+ }
+ //else: do nothing if we have no children
+}
- for ( wxWindowList::Node *node = GetChildren().GetFirst();
- node;
- node = node->GetNext() )
+// return the size best suited for the current window
+wxSize wxWindowBase::DoGetBestSize() const
+{
+ if ( GetChildren().GetCount() > 0 )
{
- wxWindow *win = node->GetData();
- if ( win->IsTopLevel() )
+ // our minimal acceptable size is such that all our windows fit inside
+ int maxX = 0,
+ maxY = 0;
+
+ for ( wxWindowList::Node *node = GetChildren().GetFirst();
+ node;
+ node = node->GetNext() )
{
- // dialogs and frames lie in different top level windows - don't
- // deal with them here
- continue;
+ wxWindow *win = node->GetData();
+ if ( win->IsTopLevel() )
+ {
+ // dialogs and frames lie in different top level windows -
+ // don't deal with them here
+ continue;
+ }
+
+ int wx, wy, ww, wh;
+ win->GetPosition(&wx, &wy);
+ win->GetSize(&ww, &wh);
+ if ( wx + ww > maxX )
+ maxX = wx + ww;
+ if ( wy + wh > maxY )
+ maxY = wy + wh;
}
- int wx, wy, ww, wh;
- win->GetPosition(&wx, &wy);
- win->GetSize(&ww, &wh);
- if ( wx + ww > maxX )
- maxX = wx + ww;
- if ( wy + wh > maxY )
- maxY = wy + wh;
+ // leave a margin
+ return wxSize(maxX + 7, maxY + 14);
+ }
+ else
+ {
+ // for a generic window there is no natural best size - just use the
+ // current one
+ return GetSize();
}
-
- // leave a margin
- SetClientSize(maxX + 7, maxY + 14);
}
// set the min/max size of the window
-
void wxWindowBase::SetSizeHints(int minW, int minH,
int maxW, int maxH,
int WXUNUSED(incW), int WXUNUSED(incH))
bool wxWindowBase::IsTopLevel() const
{
- return wxDynamicCast(this, wxFrame) || wxDynamicCast(this, wxDialog);
+ return FALSE;
}
// ----------------------------------------------------------------------------
{
int w, h;
GetClientSize(&w, &h);
-
+
// If there is a sizer, use it instead of the constraints
if ( GetSizer() )
{
GetSizer()->SetDimension( 0, 0, w, h );
return TRUE;
}
-
+
if ( GetConstraints() )
{
GetConstraints()->width.SetValue(w);
DoPhase(1); // Just one phase need if no sizers involved
DoPhase(2);
SetConstraintSizes(); // Recursively set the real window sizes
-
+
return TRUE;
}
// of control classes.
void wxWindowBase::UpdateWindowUI()
{
- wxWindowID id = GetId();
- if ( id > 0 )
+ wxUpdateUIEvent event(GetId());
+ event.m_eventObject = this;
+
+ if ( GetEventHandler()->ProcessEvent(event) )
{
- wxUpdateUIEvent event(id);
- event.m_eventObject = this;
+ if ( event.GetSetEnabled() )
+ Enable(event.GetEnabled());
- if ( GetEventHandler()->ProcessEvent(event) )
+ if ( event.GetSetText() )
{
- if ( event.GetSetEnabled() )
- Enable(event.GetEnabled());
-
- if ( event.GetSetText() )
+ wxControl *control = wxDynamicCast(this, wxControl);
+ if ( control )
{
- wxControl *control = wxDynamicCast(this, wxControl);
- if ( control )
+ wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl);
+ if ( text )
+ text->SetValue(event.GetText());
+ else
control->SetLabel(event.GetText());
}
+ }
#if wxUSE_CHECKBOX
- wxCheckBox *checkbox = wxDynamicCast(this, wxCheckBox);
- if ( checkbox )
- {
- if ( event.GetSetChecked() )
- checkbox->SetValue(event.GetChecked());
- }
+ wxCheckBox *checkbox = wxDynamicCast(this, wxCheckBox);
+ if ( checkbox )
+ {
+ if ( event.GetSetChecked() )
+ checkbox->SetValue(event.GetChecked());
+ }
#endif // wxUSE_CHECKBOX
#if wxUSE_RADIOBUTTON
- wxRadioButton *radiobtn = wxDynamicCast(this, wxRadioButton);
- if ( radiobtn )
- {
- if ( event.GetSetChecked() )
- radiobtn->SetValue(event.GetChecked());
- }
-#endif // wxUSE_RADIOBUTTON
+ wxRadioButton *radiobtn = wxDynamicCast(this, wxRadioButton);
+ if ( radiobtn )
+ {
+ if ( event.GetSetChecked() )
+ radiobtn->SetValue(event.GetChecked());
}
+#endif // wxUSE_RADIOBUTTON
}
}