\func{void}{SetInternalMargin}{\param{int}{margin}}
Sets the margin (in pixel) between the picker and the text control.
+This function can be used only when \helpref{wxpickerbasehastextctrl}{HasTextCtrl} returns \true.
\membersection{wxPickerBase::GetInternalMargin}\label{wxpickerbasegetinternalmargin}
\constfunc{int}{GetInternalMargin}{}
Returns the margin (in pixel) between the picker and the text control.
+This function can be used only when \helpref{wxpickerbasehastextctrl}{HasTextCtrl} returns \true.
\membersection{wxPickerBase::SetTextCtrlProportion}\label{wxpickerbasesettextctrlproportion}
Sets the proportion between the text control and the picker.
Look at the overview of wxPickerBase for more details about this.
+This function can be used only when \helpref{wxpickerbasehastextctrl}{HasTextCtrl} returns \true.
-\membersection{wxPickerBase::GetTextCtrlProportion}\label{wxpickerbasesgettextctrlproportion}
+\membersection{wxPickerBase::GetTextCtrlProportion}\label{wxpickerbasegettextctrlproportion}
\constfunc{int}{GetTextCtrlProportion}{}
Returns the proportion between the text control and the picker.
+This function can be used only when \helpref{wxpickerbasehastextctrl}{HasTextCtrl} returns \true.
-\membersection{wxPickerBase::HasTextCtrl}\label{wxpickerbaseshastextctrl}
+
+\membersection{wxPickerBase::HasTextCtrl}\label{wxpickerbasehastextctrl}
\constfunc{bool}{HasTextCtrl}{}
-Returns true if this class has a valid text control (i.e. if the \windowstyle{wxPB\_USE\_TEXTCTRL} style was
+Returns true if this window has a valid text control (i.e. if the \windowstyle{wxPB\_USE\_TEXTCTRL} style was
given when creating this control).
-\membersection{wxPickerBase::GetTextCtrl}\label{wxpickerbasesgetextctrl}
+\membersection{wxPickerBase::GetTextCtrl}\label{wxpickerbasegetextctrl}
\func{wxTextCtrl *}{GetTextCtrl}{}
-Returns a pointer to the text control handled by this class or \texttt{NULL} if the \windowstyle{wxPB\_USE\_TEXTCTRL} style was not specified when this control was created.
+Returns a pointer to the text control handled by this window or \texttt{NULL} if the \windowstyle{wxPB\_USE\_TEXTCTRL} style was not specified when this control was created.
Very important: the contents of the text control could be containing an invalid representation of the entity which can be chosen through the picker (e.g. the user entered an invalid colour syntax because of a typo). Thus you should never parse the content of the textctrl to get the user's input; rather use the derived-class getter (e.g. \helpref{wxColourPickerCtrl::GetColour}{wxcolourpickerctrlgetcolour}, \helpref{wxFilePickerCtrl::GetPath}{wxfilepickerctrlgetpath}, etc).
+
+
+\membersection{wxPickerBase::IsTextCtrlGrowable}\label{wxpickerbaseistextctrlgrowable}
+
+\constfunc{bool}{IsTextCtrlGrowable}{}
+
+Returns \true if the text control is growable.
+This function can be used only when \helpref{wxpickerbasehastextctrl}{HasTextCtrl} returns \true.
+
+
+\membersection{wxPickerBase::SetTextCtrlGrowable}\label{wxpickerbasesettextctrlgrowable}
+
+\func{void}{SetTextCtrlGrowable}{\param{bool}{ grow = true}}
+
+Sets the text control as growable when {\tt grow} is \true.
+This function can be used only when \helpref{wxpickerbasehastextctrl}{HasTextCtrl} returns \true.
+
+
+
+\membersection{wxPickerBase::IsPickerCtrlGrowable}\label{wxpickerbaseispickerctrlgrowable}
+
+\constfunc{bool}{IsPickerCtrlGrowable}{}
+
+Returns \true if the picker control is growable.
+
+
+\membersection{wxPickerBase::SetPickerCtrlGrowable}\label{wxpickerbasesetpickerctrlgrowable}
+
+\func{void}{SetPickerCtrlGrowable}{\param{bool}{ grow = true}}
+
+Sets the picker control as growable when {\tt grow} is \true.
+This function has effects only when \helpref{wxpickerbasehastextctrl}{HasTextCtrl} returns \true.
+
void SetNativeFontInfo(const gchar *gtkdescription)
{ m_selectedFont.SetNativeFontInfo(wxString::FromAscii(gtkdescription)); }
- wxWindow *m_topParent;
-
private:
DECLARE_DYNAMIC_CLASS(wxFontButton)
};
{
public:
// ctor: text is the associated text control
- wxPickerBase() : m_text(NULL), m_picker(NULL),
- m_margin(5), m_textProportion(2) {}
- virtual ~wxPickerBase();
+ wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL)
+ { m_container.SetContainerWindow(this); }
+ virtual ~wxPickerBase() {}
// if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control
public: // public API
// margin between the text control and the picker
- void SetInternalMargin(int newmargin);
- int GetInternalMargin() const { return m_margin; }
+ void SetInternalMargin(int newmargin)
+ { GetTextCtrlItem()->SetBorder(newmargin); m_sizer->Layout(); }
+ int GetInternalMargin() const
+ { return GetTextCtrlItem()->GetBorder(); }
// proportion of the text control respect the picker
// (which has a fixed proportion value of 1)
- void SetTextCtrlProportion(int prop) { wxASSERT(prop>=1); m_textProportion=prop; }
- int GetTextCtrlProportion() const { return m_textProportion; }
+ void SetTextCtrlProportion(int prop)
+ { GetTextCtrlItem()->SetProportion(prop); m_sizer->Layout(); }
+ int GetTextCtrlProportion() const
+ { return GetTextCtrlItem()->GetProportion(); }
+
+ bool IsTextCtrlGrowable() const
+ { return GetTextCtrlItem()->GetFlag() & wxGROW; }
+ void SetTextCtrlGrowable(bool grow = true)
+ {
+ int f = GetDefaultTextCtrlFlag();
+ if (grow)
+ GetTextCtrlItem()->SetFlag(f | wxGROW);
+ else
+ GetTextCtrlItem()->SetFlag(f & ~wxGROW);
+ }
+
+ bool IsPickerCtrlGrowable() const
+ { return GetPickerCtrlItem()->GetFlag() & wxGROW; }
+ void SetPickerCtrlGrowable(bool grow = true)
+ {
+ int f = GetDefaultPickerCtrlFlag();
+ if (grow)
+ GetPickerCtrlItem()->SetFlag(f | wxGROW);
+ else
+ GetPickerCtrlItem()->SetFlag(f & ~wxGROW);
+ }
bool HasTextCtrl() const
{ return m_text != NULL; }
wxControl *GetPickerCtrl()
{ return m_picker; }
-public: // wxWindow overrides
-
- void DoSetSizeHints(int minW, int minH,
- int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
- int incW = wxDefaultCoord, int incH = wxDefaultCoord );
-
-protected:
- void DoSetSize(int x, int y,
- int width, int height,
- int sizeFlags = wxSIZE_AUTO);
-
- wxSize DoGetBestSize() const;
-
-
public: // methods that derived class must/may override
virtual void UpdatePickerFromTextCtrl() = 0;
protected: // utility functions
- inline int GetTextCtrlWidth(int given);
-
// event handlers
void OnTextCtrlDelete(wxWindowDestroyEvent &);
void OnTextCtrlUpdate(wxCommandEvent &);
void OnTextCtrlKillFocus(wxFocusEvent &);
+ void OnSize(wxSizeEvent &);
+
// returns the set of styles for the attached wxTextCtrl
// from given wxPickerBase's styles
virtual long GetTextCtrlStyle(long style) const
virtual long GetPickerStyle(long style) const
{ return (style & wxWINDOW_STYLE_MASK); }
+
+ wxSizerItem *GetPickerCtrlItem() const
+ {
+ if (this->HasTextCtrl())
+ return m_sizer->GetItem((size_t)1);
+ return m_sizer->GetItem((size_t)0);
+ }
+
+ wxSizerItem *GetTextCtrlItem() const
+ {
+ wxASSERT(this->HasTextCtrl());
+ return m_sizer->GetItem((size_t)0);
+ }
+
+ int GetDefaultPickerCtrlFlag() const
+ {
+ // on macintosh, without additional borders
+ // there's not enough space for focus rect
+ return wxALIGN_CENTER_VERTICAL|wxGROW
+#ifdef __WXMAC__
+ | wxTOP | wxRIGHT | wxBOTTOM
+#endif
+ ;
+ }
+
+ int GetDefaultTextCtrlFlag() const
+ {
+ // on macintosh, without wxALL there's not enough space for focus rect
+ return wxALIGN_CENTER_VERTICAL
+#ifdef __WXMAC__
+ | wxALL
+#else
+ | wxRIGHT
+#endif
+ ;
+ }
+
+ void PostCreation();
+
protected:
wxTextCtrl *m_text; // can be NULL
wxControl *m_picker;
-
- int m_margin; // distance between subcontrols
- int m_textProportion; // proportion between textctrl and other item
+ wxBoxSizer *m_sizer;
private:
DECLARE_ABSTRACT_CLASS(wxPickerBase)
+ DECLARE_EVENT_TABLE()
+
+ // This class must be something just like a panel...
+ WX_DECLARE_CONTROL_CONTAINER();
};
// to its "changed" event dynamically...
m_picker = new wxColourPickerWidget(this, wxID_ANY, col, wxPoint(40,0), wxSize(30,-1),
GetPickerStyle(style));
+
+ // complete sizer creation
+ wxPickerBase::PostCreation();
+
m_picker->Connect(wxEVT_COMMAND_COLOURPICKER_CHANGED,
wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange),
NULL, this);
// create a wxFilePickerWidget or a wxDirPickerWidget...
if (!CreatePicker(this, path, message, wildcard))
return false;
+
+ // complete sizer creation
+ wxPickerBase::PostCreation();
+
m_picker->Connect(GetEventType(),
wxFileDirPickerEventHandler(wxFileDirPickerCtrlBase::OnFileDirChange),
NULL, this);
long style, const wxValidator& validator,
const wxString &name )
{
- // by default, the textctrl is, if present, as big as the picker, for wxFontPickerCtrl
- SetTextCtrlProportion(1);
-
if (!wxPickerBase::CreateBase(parent, id, Font2String(initial),
pos, size, style, validator, name))
return false;
m_picker = new wxFontPickerWidget(this, wxID_ANY, initial,
wxDefaultPosition, wxDefaultSize,
GetPickerStyle(style));
+ // complete sizer creation
+ wxPickerBase::PostCreation();
+
m_picker->Connect(wxEVT_COMMAND_FONTPICKER_CHANGED,
wxFontPickerEventHandler(wxFontPickerCtrl::OnFontChange),
NULL, this);
IMPLEMENT_ABSTRACT_CLASS(wxPickerBase, wxWindow)
+BEGIN_EVENT_TABLE(wxPickerBase, wxControl)
+ EVT_SIZE(wxPickerBase::OnSize)
+ WX_EVENT_TABLE_CONTROL_CONTAINER(wxPickerBase)
+END_EVENT_TABLE()
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase)
+
+
// ----------------------------------------------------------------------------
// wxPickerBase
// ----------------------------------------------------------------------------
-wxPickerBase::~wxPickerBase()
-{
- // destroy the windows we are managing: these are not automatically
- // destroyed by wxWindow because they are not built as our children
- // but rather as children of the parent of the wxPickerBase class
- // (since wxPickerBase does not represent a real window)
- if (m_text) m_text->Destroy();
- if (m_picker) m_picker->Destroy();
-}
-
bool wxPickerBase::CreateBase(wxWindow *parent,
wxWindowID id,
const wxString &text,
// invisible (user styles must be set on the textctrl or the platform-dependent picker)
style &= ~wxBORDER_MASK;
if (!wxControl::Create(parent, id, pos, size, style | wxNO_BORDER | wxTAB_TRAVERSAL,
- validator, name))
+ validator, name))
return false;
+ m_sizer = new wxBoxSizer(wxHORIZONTAL);
+
if (HasFlag(wxPB_USE_TEXTCTRL))
{
// NOTE: the style of this class (wxPickerBase) and the style of the
// attached text control are different: GetTextCtrlStyle() extracts
// the styles related to the textctrl from the styles passed here
- m_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxPoint(0, 0),
- wxSize(40, size.GetHeight()), GetTextCtrlStyle(style));
+ m_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+ wxDefaultSize, GetTextCtrlStyle(style));
if (!m_text)
{
wxFAIL_MSG( wxT("wxPickerBase's textctrl creation failed") );
m_text->Connect(wxEVT_DESTROY,
wxWindowDestroyEventHandler(wxPickerBase::OnTextCtrlDelete),
NULL, this);
+
+ m_sizer->Add(m_text, 2, GetDefaultTextCtrlFlag(), 5);
}
return true;
}
+void wxPickerBase::PostCreation()
+{
+ // the picker's proportion value is fixed
+ m_sizer->Add(m_picker, 1, GetDefaultPickerCtrlFlag(), 5);
+
+ SetSizer(m_sizer);
+ m_sizer->SetSizeHints(this);
+}
+
void wxPickerBase::OnTextCtrlKillFocus(wxFocusEvent &)
{
wxASSERT(m_text);
UpdatePickerFromTextCtrl();
}
-int wxPickerBase::GetTextCtrlWidth(int given)
-{
- // compute the width of m_text like a wxBoxSizer(wxHORIZONTAL) would do
- // NOTE: the proportion of m_picker is fixed to 1
- return ((given - m_margin) / (m_textProportion + 1)) * m_textProportion;
-}
-
-void wxPickerBase::DoSetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
-{
- wxControl::DoSetSizeHints(minW, minH, maxW, maxH, incW, incH);
-
- if (m_text)
- {
- // compute minWidth and maxWidth of the ausiliary textctrl
- int textCtrlMinW = -1, textCtrlMaxW = -1;
- if (minW != -1)
- {
- textCtrlMinW = GetTextCtrlWidth(minW);
- minW -= textCtrlMinW + m_margin;
- }
-
- if (maxW != -1)
- {
- textCtrlMaxW = GetTextCtrlWidth(maxW);
- maxW -= textCtrlMaxW + m_margin;
- }
-
- m_text->SetSizeHints(textCtrlMinW, minH, textCtrlMaxW, maxH, incW, incH);
- }
-
- if (m_picker)
- m_picker->SetSizeHints(minW, minH, maxW, maxH, incW, incH);
-}
-
-void wxPickerBase::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
- wxControl::DoSetSize(x, y, width, height, sizeFlags);
-
- int pickerx = 0;
- if (m_text)
- {
- // compute width of the ausiliary textctrl
- int textCtrlW = GetTextCtrlWidth(width);
-
- // set the m_text's position relatively to this window
- m_text->SetSize(0, 0, textCtrlW, height, sizeFlags);
-
- // change position of the real picker
- pickerx += textCtrlW + m_margin;
- width -= textCtrlW + m_margin;
- }
-
- if (m_picker)
- m_picker->SetSize(pickerx, 0, width, height, sizeFlags);
-}
-
-wxSize wxPickerBase::DoGetBestSize() const
-{
- wxSize ret = m_picker->GetBestSize();
-
- if (m_text)
- {
- wxSize sz = m_text->GetBestSize();
-
- ret.SetWidth( ret.GetWidth() + sz.GetWidth() + m_margin );
- ret.SetHeight( wxMax(ret.GetHeight(), sz.GetHeight()) );
- }
-
- return ret;
-}
-
-void wxPickerBase::SetInternalMargin(int newmargin)
+void wxPickerBase::OnSize(wxSizeEvent &event)
{
- m_margin = newmargin;
+ if (GetAutoLayout())
+ Layout();
+ event.Skip();
}
#endif // Any picker in use
if (!gtk_check_version(2,4,0))
{
m_needParent = true;
+ m_acceptsFocus = true;
if (!PreCreation( parent, pos, size ) ||
!wxControl::CreateBase(parent, id, pos, size, style, validator, name))
{
if (!gtk_check_version(2,6,0))
{
- // VERY IMPORTANT: this code is identic to relative code in wxFileButton;
- // if you find a problem here, fix it also in wxFileButton !
+ // VERY IMPORTANT: this code is identic to relative code in wxDirButton;
+ // if you find a problem here, fix it also in wxDirButton !
m_needParent = true;
+ m_acceptsFocus = true;
if (!PreCreation( parent, pos, size ) ||
!wxControl::CreateBase(parent, id, pos, size, style & wxWINDOW_STYLE_MASK,
}
}
-
void wxFileButton::SetPath(const wxString &str)
{
m_path = str;
// if you find a problem here, fix it also in wxFileButton !
m_needParent = true;
+ m_acceptsFocus = true;
if (!PreCreation( parent, pos, size ) ||
!wxControl::CreateBase(parent, id, pos, size, style & wxWINDOW_STYLE_MASK,
if (!gtk_check_version(2,4,0))
{
m_needParent = true;
+ m_acceptsFocus = true;
if (!PreCreation( parent, pos, size ) ||
!wxControl::CreateBase(parent, id, pos, size, style, validator, name))