]> git.saurik.com Git - wxWidgets.git/commitdiff
use wxBoxSizer in wxPickerBase instead of doing the layout manually + other picker...
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 27 Jun 2006 14:07:45 +0000 (14:07 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 27 Jun 2006 14:07:45 +0000 (14:07 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39846 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/pickerbase.tex
include/wx/gtk/fontpicker.h
include/wx/pickerbase.h
src/common/clrpickercmn.cpp
src/common/filepickercmn.cpp
src/common/fontpickercmn.cpp
src/common/pickerbase.cpp
src/gtk/clrpicker.cpp
src/gtk/filepicker.cpp
src/gtk/fontpicker.cpp

index 123c7bcd502299410dfe46b02d82815ff5cf6d50..07f12bb15c4067714f9dfab9f30179a3880c369d 100644 (file)
@@ -47,6 +47,7 @@ class.}
 \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}
@@ -54,6 +55,7 @@ Sets the margin (in pixel) between the picker and the text control.
 \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}
@@ -62,26 +64,62 @@ Returns the margin (in pixel) between the picker and the text control.
 
 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.
+
index 06ba2ed99f47bcdf7e4d72b61ee72febf608ef38..200615fcff12eec0d7be91ca39aecb9aaeb95304 100644 (file)
@@ -60,8 +60,6 @@ public:     // used by the GTK callback only
     void SetNativeFontInfo(const gchar *gtkdescription)
         { m_selectedFont.SetNativeFontInfo(wxString::FromAscii(gtkdescription)); }
 
-    wxWindow *m_topParent;
-
 private:
     DECLARE_DYNAMIC_CLASS(wxFontButton)
 };
index 64714f4399487a1526f5a445d63298e7b13bdf81..705924b3621aefafb9079791e2fa772400a2099f 100644 (file)
@@ -33,9 +33,9 @@ class WXDLLIMPEXP_CORE wxPickerBase : public wxControl
 {
 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
@@ -51,13 +51,39 @@ public:
 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; }
@@ -66,20 +92,6 @@ public:     // public API
     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;
@@ -87,13 +99,13 @@ public:     // methods that derived class must/may override
 
 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
@@ -103,15 +115,56 @@ protected:        // utility functions
     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();
 };
 
 
index 6b7ea1c7687d1d218ba1cb216609d5c571b8c3c9..75295088d8db4670743eca1af90f609c52dcb3cc 100644 (file)
@@ -61,6 +61,10 @@ bool wxColourPickerCtrl::Create( wxWindow *parent, wxWindowID id,
     // 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);
index 27fb86a331e8367a1659f3f221def1010f63231c..06931b3b56cc4e20356c246f6465a0a9350d2d4e 100644 (file)
@@ -76,6 +76,10 @@ bool wxFileDirPickerCtrlBase::CreateBase( wxWindow *parent, wxWindowID id,
     // 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);
index 159b5403dfd9c3ae177badcdb5b278bdcf568010..92cf9898b69dbeeda5d1d0a16be99932afd88596 100644 (file)
@@ -55,9 +55,6 @@ bool wxFontPickerCtrl::Create( wxWindow *parent, wxWindowID id,
                         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;
@@ -66,6 +63,9 @@ bool wxFontPickerCtrl::Create( wxWindow *parent, wxWindowID id,
     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);
index ce5c4a2d5546ea4791b1e7bb8e3fb3bd9fc67f86..62a4429f5972f1525b5fa9849ee0b470b9c9d6cb 100644 (file)
 
 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,
@@ -68,16 +65,18 @@ bool wxPickerBase::CreateBase(wxWindow *parent,
     // 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") );
@@ -104,11 +103,22 @@ bool wxPickerBase::CreateBase(wxWindow *parent,
         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);
@@ -130,80 +140,11 @@ void wxPickerBase::OnTextCtrlUpdate(wxCommandEvent &)
     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
index 672a8593cb3afcbcd9afd91ffb2a42f1e8230db3..b88a8a37aa9659866698b302e0588c91e2fdae88 100644 (file)
@@ -62,6 +62,7 @@ bool wxColourButton::Create( wxWindow *parent, wxWindowID id,
     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))
index f5f6a0a97b62594a718b972c2163d1abbc7121a4..6779e751117164ef3de7ba3cc8aa2b5e703d253a 100644 (file)
@@ -45,10 +45,11 @@ bool wxFileButton::Create( wxWindow *parent, wxWindowID id,
 {
     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,
@@ -127,7 +128,6 @@ void wxFileButton::OnDialogOK(wxCommandEvent& ev)
     }
 }
 
-
 void wxFileButton::SetPath(const wxString &str)
 {
     m_path = str;
@@ -200,6 +200,7 @@ bool wxDirButton::Create( wxWindow *parent, wxWindowID id,
         //                 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,
index 27d8bb19bfc1a3ce19035eeed8b50f6c2710e9bb..88e2b93c7c5da116e22bacfe521203bc9dd29f72 100644 (file)
@@ -61,6 +61,7 @@ bool wxFontButton::Create( wxWindow *parent, wxWindowID id,
     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))