]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxFLP_SMALL and wxDIRP_SMALL styles for wx{File,Dir}PickerCtrl.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 27 Aug 2011 14:11:25 +0000 (14:11 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 27 Aug 2011 14:11:25 +0000 (14:11 +0000)
These styles allow to use a smaller browse button as the standard one takes
too much space, often leaving too little of it for the more important text
control part.

Notice that both styles are, in fact, equal to wxPB_SMALL but only file and
directory pickers currently use it as it doesn't make sense for the colour and
font pickers.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68921 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/filepicker.h
include/wx/pickerbase.h
interface/wx/filepicker.h
samples/widgets/dirpicker.cpp
samples/widgets/filepicker.cpp
src/common/pickerbase.cpp
src/generic/filepickerg.cpp
src/xrc/xh_dirpicker.cpp
src/xrc/xh_filepicker.cpp

index 2789e3526c7e26ee55965289e4cb3f6575caead0..6fb7429ec8bf6b43c9fae612a616df6949840c0e 100644 (file)
@@ -465,6 +465,7 @@ All (GUI):
 - Fix stock labels when not using mnemonics for Chinese (cw.ahbong).
 - Added wxComboBox::IsListEmpty() and IsTextEmpty().
 - Added wxDataViewCtrl::GetSelectedItemsCount() and HasSelection().
 - Fix stock labels when not using mnemonics for Chinese (cw.ahbong).
 - Added wxComboBox::IsListEmpty() and IsTextEmpty().
 - Added wxDataViewCtrl::GetSelectedItemsCount() and HasSelection().
+- Added wxFLP_SMALL and wxDIRP_SMALL styles.
 
 OSX:
 
 
 OSX:
 
index 4ddb53f381cc2281c992157d684bdbbb05f925f5..3b471b7aca3c81d5975109a6961331f617ad99f4 100644 (file)
@@ -109,12 +109,14 @@ protected:
 #define wxFLP_OVERWRITE_PROMPT        0x1000
 #define wxFLP_FILE_MUST_EXIST         0x2000
 #define wxFLP_CHANGE_DIR              0x4000
 #define wxFLP_OVERWRITE_PROMPT        0x1000
 #define wxFLP_FILE_MUST_EXIST         0x2000
 #define wxFLP_CHANGE_DIR              0x4000
+#define wxFLP_SMALL                   wxPB_SMALL
 
 // NOTE: wxMULTIPLE is not supported !
 
 
 #define wxDIRP_DIR_MUST_EXIST         0x0008
 #define wxDIRP_CHANGE_DIR             0x0010
 
 // NOTE: wxMULTIPLE is not supported !
 
 
 #define wxDIRP_DIR_MUST_EXIST         0x0008
 #define wxDIRP_CHANGE_DIR             0x0010
+#define wxDIRP_SMALL                  wxPB_SMALL
 
 
 // map platform-dependent controls which implement the wxFileDirPickerWidgetBase
 
 
 // map platform-dependent controls which implement the wxFileDirPickerWidgetBase
@@ -300,8 +302,13 @@ protected:
     // extracts the style for our picker from wxFileDirPickerCtrlBase's style
     long GetPickerStyle(long style) const
     {
     // extracts the style for our picker from wxFileDirPickerCtrlBase's style
     long GetPickerStyle(long style) const
     {
-        return (style & (wxFLP_OPEN|wxFLP_SAVE|wxFLP_OVERWRITE_PROMPT|
-                            wxFLP_FILE_MUST_EXIST|wxFLP_CHANGE_DIR|wxFLP_USE_TEXTCTRL));
+        return style & (wxFLP_OPEN |
+                        wxFLP_SAVE |
+                        wxFLP_OVERWRITE_PROMPT |
+                        wxFLP_FILE_MUST_EXIST |
+                        wxFLP_CHANGE_DIR |
+                        wxFLP_USE_TEXTCTRL |
+                        wxFLP_SMALL);
     }
 
 private:
     }
 
 private:
@@ -396,7 +403,12 @@ protected:
 
     // extracts the style for our picker from wxFileDirPickerCtrlBase's style
     long GetPickerStyle(long style) const
 
     // extracts the style for our picker from wxFileDirPickerCtrlBase's style
     long GetPickerStyle(long style) const
-        { return (style & (wxDIRP_DIR_MUST_EXIST|wxDIRP_CHANGE_DIR|wxDIRP_USE_TEXTCTRL)); }
+    {
+        return style & (wxDIRP_DIR_MUST_EXIST |
+                        wxDIRP_CHANGE_DIR |
+                        wxDIRP_USE_TEXTCTRL |
+                        wxDIRP_SMALL);
+    }
 
 private:
     DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl)
 
 private:
     DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl)
index 56a30d087387234a2263ef308bcd185088957701..16afd715f084699cb548cc5cb88b5a2410fa8833 100644 (file)
@@ -31,6 +31,7 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
 // ----------------------------------------------------------------------------
 
 #define wxPB_USE_TEXTCTRL           0x0002
 // ----------------------------------------------------------------------------
 
 #define wxPB_USE_TEXTCTRL           0x0002
+#define wxPB_SMALL                  0x8000
 
 class WXDLLIMPEXP_CORE wxPickerBase : public wxNavigationEnabled<wxControl>
 {
 
 class WXDLLIMPEXP_CORE wxPickerBase : public wxNavigationEnabled<wxControl>
 {
index 95155a17dd428e3bbefd0f2d542b12606b46b23d..89466aaf095b435fc692793778aa90114abb3405 100644 (file)
@@ -37,6 +37,9 @@
            existing file.
     @style{wxFLP_CHANGE_DIR}
            Change current working directory on each user file selection change.
            existing file.
     @style{wxFLP_CHANGE_DIR}
            Change current working directory on each user file selection change.
+    @style{wxFLP_SMALL}
+           Use smaller version of the control with a small "..." button instead
+           of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
     @endStyleTable
 
 
     @endStyleTable
 
 
@@ -161,6 +164,9 @@ public:
            support its absence.
     @style{wxDIRP_CHANGE_DIR}
            Change current working directory on each user directory selection change.
            support its absence.
     @style{wxDIRP_CHANGE_DIR}
            Change current working directory on each user directory selection change.
+    @style{wxDIRP_SMALL}
+           Use smaller version of the control with a small "..." button instead
+           of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
     @endStyleTable
 
     @beginEventEmissionTable{wxFileDirPickerEvent}
     @endStyleTable
 
     @beginEventEmissionTable{wxFileDirPickerEvent}
index 1d0044bc4c0ddb498fd3c6f40ec226e65a1e028a..7bdfc69d34b58fe561b91430c0f9dcbaed9d0ead 100644 (file)
@@ -100,7 +100,8 @@ protected:
 
     wxCheckBox *m_chkDirTextCtrl,
                *m_chkDirChangeDir,
 
     wxCheckBox *m_chkDirTextCtrl,
                *m_chkDirChangeDir,
-               *m_chkDirMustExist;
+               *m_chkDirMustExist,
+               *m_chkSmall;
     wxBoxSizer *m_sizer;
 
 private:
     wxBoxSizer *m_sizer;
 
 private:
@@ -148,6 +149,7 @@ void DirPickerWidgetsPage::CreateContent()
     m_chkDirTextCtrl = CreateCheckBoxAndAddToSizer(dirbox, wxT("With textctrl"), false);
     m_chkDirMustExist = CreateCheckBoxAndAddToSizer(dirbox, wxT("Dir must exist"), false);
     m_chkDirChangeDir = CreateCheckBoxAndAddToSizer(dirbox, wxT("Change working dir"), false);
     m_chkDirTextCtrl = CreateCheckBoxAndAddToSizer(dirbox, wxT("With textctrl"), false);
     m_chkDirMustExist = CreateCheckBoxAndAddToSizer(dirbox, wxT("Dir must exist"), false);
     m_chkDirChangeDir = CreateCheckBoxAndAddToSizer(dirbox, wxT("Change working dir"), false);
+    m_chkSmall = CreateCheckBoxAndAddToSizer(dirbox, "&Small version", false);
     boxleft->Add(dirbox, 0, wxALL|wxGROW, 5);
 
     boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")),
     boxleft->Add(dirbox, 0, wxALL|wxGROW, 5);
 
     boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")),
@@ -196,6 +198,9 @@ long DirPickerWidgetsPage::GetPickerStyle()
     if ( m_chkDirChangeDir->GetValue() )
         style |= wxDIRP_CHANGE_DIR;
 
     if ( m_chkDirChangeDir->GetValue() )
         style |= wxDIRP_CHANGE_DIR;
 
+    if ( m_chkSmall->GetValue() )
+        style |= wxDIRP_SMALL;
+
     return style;
 }
 
     return style;
 }
 
@@ -213,6 +218,7 @@ void DirPickerWidgetsPage::Reset()
     m_chkDirTextCtrl->SetValue((wxDIRP_DEFAULT_STYLE & wxDIRP_USE_TEXTCTRL) != 0);
     m_chkDirMustExist->SetValue((wxDIRP_DEFAULT_STYLE & wxDIRP_DIR_MUST_EXIST) != 0);
     m_chkDirChangeDir->SetValue((wxDIRP_DEFAULT_STYLE & wxDIRP_CHANGE_DIR) != 0);
     m_chkDirTextCtrl->SetValue((wxDIRP_DEFAULT_STYLE & wxDIRP_USE_TEXTCTRL) != 0);
     m_chkDirMustExist->SetValue((wxDIRP_DEFAULT_STYLE & wxDIRP_DIR_MUST_EXIST) != 0);
     m_chkDirChangeDir->SetValue((wxDIRP_DEFAULT_STYLE & wxDIRP_CHANGE_DIR) != 0);
+    m_chkSmall->SetValue((wxFLP_DEFAULT_STYLE & wxDIRP_SMALL) != 0);
 }
 
 
 }
 
 
@@ -236,7 +242,8 @@ void DirPickerWidgetsPage::OnCheckBox(wxCommandEvent &event)
 {
     if (event.GetEventObject() == m_chkDirTextCtrl ||
         event.GetEventObject() == m_chkDirChangeDir ||
 {
     if (event.GetEventObject() == m_chkDirTextCtrl ||
         event.GetEventObject() == m_chkDirChangeDir ||
-        event.GetEventObject() == m_chkDirMustExist)
+        event.GetEventObject() == m_chkDirMustExist ||
+        event.GetEventObject() == m_chkSmall)
         RecreatePicker();
 }
 
         RecreatePicker();
 }
 
index 55cfe98c06f6881a99c14658e0334f3f576e565e..8e3957815857717eaa7480270fe0f0a95867e03b 100644 (file)
@@ -111,7 +111,8 @@ protected:
     wxCheckBox *m_chkFileTextCtrl,
                *m_chkFileOverwritePrompt,
                *m_chkFileMustExist,
     wxCheckBox *m_chkFileTextCtrl,
                *m_chkFileOverwritePrompt,
                *m_chkFileMustExist,
-               *m_chkFileChangeDir;
+               *m_chkFileChangeDir,
+               *m_chkSmall;
     wxRadioBox *m_radioFilePickerMode;
 
     wxBoxSizer *m_sizer;
     wxRadioBox *m_radioFilePickerMode;
 
     wxBoxSizer *m_sizer;
@@ -169,6 +170,8 @@ void FilePickerWidgetsPage::CreateContent()
     m_chkFileOverwritePrompt = CreateCheckBoxAndAddToSizer(filebox, wxT("Overwrite prompt"), false);
     m_chkFileMustExist = CreateCheckBoxAndAddToSizer(filebox, wxT("File must exist"), false);
     m_chkFileChangeDir = CreateCheckBoxAndAddToSizer(filebox, wxT("Change working dir"), false);
     m_chkFileOverwritePrompt = CreateCheckBoxAndAddToSizer(filebox, wxT("Overwrite prompt"), false);
     m_chkFileMustExist = CreateCheckBoxAndAddToSizer(filebox, wxT("File must exist"), false);
     m_chkFileChangeDir = CreateCheckBoxAndAddToSizer(filebox, wxT("Change working dir"), false);
+    m_chkSmall = CreateCheckBoxAndAddToSizer(filebox, "&Small version", false);
+
     boxleft->Add(filebox, 0, wxALL|wxGROW, 5);
 
     boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")),
     boxleft->Add(filebox, 0, wxALL|wxGROW, 5);
 
     boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")),
@@ -222,6 +225,9 @@ long FilePickerWidgetsPage::GetPickerStyle()
     if ( m_chkFileChangeDir->GetValue() )
         style |= wxFLP_CHANGE_DIR;
 
     if ( m_chkFileChangeDir->GetValue() )
         style |= wxFLP_CHANGE_DIR;
 
+    if ( m_chkSmall->GetValue() )
+        style |= wxFLP_SMALL;
+
     if (m_radioFilePickerMode->GetSelection() == FilePickerMode_Open)
         style |= wxFLP_OPEN;
     else
     if (m_radioFilePickerMode->GetSelection() == FilePickerMode_Open)
         style |= wxFLP_OPEN;
     else
@@ -247,6 +253,7 @@ void FilePickerWidgetsPage::Reset()
     m_chkFileOverwritePrompt->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_OVERWRITE_PROMPT) != 0);
     m_chkFileMustExist->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_FILE_MUST_EXIST) != 0);
     m_chkFileChangeDir->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_CHANGE_DIR) != 0);
     m_chkFileOverwritePrompt->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_OVERWRITE_PROMPT) != 0);
     m_chkFileMustExist->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_FILE_MUST_EXIST) != 0);
     m_chkFileChangeDir->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_CHANGE_DIR) != 0);
+    m_chkSmall->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_SMALL) != 0);
 
     UpdateFilePickerMode();
 }
 
     UpdateFilePickerMode();
 }
@@ -291,7 +298,8 @@ void FilePickerWidgetsPage::OnCheckBox(wxCommandEvent &event)
     if (event.GetEventObject() == m_chkFileTextCtrl ||
         event.GetEventObject() == m_chkFileOverwritePrompt ||
         event.GetEventObject() == m_chkFileMustExist ||
     if (event.GetEventObject() == m_chkFileTextCtrl ||
         event.GetEventObject() == m_chkFileOverwritePrompt ||
         event.GetEventObject() == m_chkFileMustExist ||
-        event.GetEventObject() == m_chkFileChangeDir)
+        event.GetEventObject() == m_chkFileChangeDir ||
+        event.GetEventObject() == m_chkSmall)
         RecreatePicker();
 
     if (event.GetEventObject() == m_radioFilePickerMode)
         RecreatePicker();
 
     if (event.GetEventObject() == m_radioFilePickerMode)
index 797c946876f5849f88ccf4dfc99c5d74b19fdeb4..da1a4ad59d95a484b76a7e2a4d437c7453a98c4f 100644 (file)
@@ -117,14 +117,19 @@ void wxPickerBase::PostCreation()
     m_sizer->Add(m_picker, HasTextCtrl() ? 0 : 1, GetDefaultPickerCtrlFlag(), 5);
 
     // For aesthetic reasons, make sure the picker is at least as high as the
     m_sizer->Add(m_picker, HasTextCtrl() ? 0 : 1, GetDefaultPickerCtrlFlag(), 5);
 
     // For aesthetic reasons, make sure the picker is at least as high as the
-    // associated text control and is always at least square.
-    const wxSize pickerBestSize(m_picker->GetBestSize());
-    const wxSize textBestSize( HasTextCtrl() ? m_text->GetBestSize() : wxSize());
-    wxSize pickerMinSize;
-    pickerMinSize.y = wxMax(pickerBestSize.y, textBestSize.y);
-    pickerMinSize.x = wxMax(pickerBestSize.x, pickerMinSize.y);
-    if ( pickerMinSize != pickerBestSize )
-        m_picker->SetMinSize(pickerMinSize);
+    // associated text control and is always at least square, unless we are
+    // explicitly using wxPB_SMALL style to force it to take as little space as
+    // possible.
+    if ( !HasFlag(wxPB_SMALL) )
+    {
+        const wxSize pickerBestSize(m_picker->GetBestSize());
+        const wxSize textBestSize( HasTextCtrl() ? m_text->GetBestSize() : wxSize());
+        wxSize pickerMinSize;
+        pickerMinSize.y = wxMax(pickerBestSize.y, textBestSize.y);
+        pickerMinSize.x = wxMax(pickerBestSize.x, pickerMinSize.y);
+        if ( pickerMinSize != pickerBestSize )
+            m_picker->SetMinSize(pickerMinSize);
+    }
 
     SetSizer(m_sizer);
 
 
     SetSizer(m_sizer);
 
index 1aaf01a42044c46c5d45211e7bbdd9bb538cb5de..2b1c6d271d2e86bfb4d36354cc8934459ddc3b8b 100644 (file)
@@ -54,8 +54,24 @@ bool wxGenericFileDirButton::Create(wxWindow *parent,
 {
     m_pickerStyle = style;
 
 {
     m_pickerStyle = style;
 
+    // If the special wxPB_SMALL flag is used, ignore the provided label and
+    // use the shortest possible label and the smallest possible button fitting
+    // it.
+    long styleButton = 0;
+    wxString labelButton;
+    if ( m_pickerStyle & wxPB_SMALL )
+    {
+        labelButton = _("...");
+        styleButton = wxBU_EXACTFIT;
+    }
+    else
+    {
+        labelButton = label;
+    }
+
     // create this button
     // create this button
-    if ( !wxButton::Create(parent, id, label, pos, size, 0, validator, name) )
+    if ( !wxButton::Create(parent, id, labelButton,
+                           pos, size, styleButton, validator, name) )
     {
         wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
         return false;
     {
         wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
         return false;
index e70c44e14ab8861dd62c60c2d45f163d01a864bb..ff750e15d185c434d01430f7a207de1cac3d3723 100644 (file)
@@ -27,6 +27,7 @@ wxDirPickerCtrlXmlHandler::wxDirPickerCtrlXmlHandler() : wxXmlResourceHandler()
     XRC_ADD_STYLE(wxDIRP_USE_TEXTCTRL);
     XRC_ADD_STYLE(wxDIRP_DIR_MUST_EXIST);
     XRC_ADD_STYLE(wxDIRP_CHANGE_DIR);
     XRC_ADD_STYLE(wxDIRP_USE_TEXTCTRL);
     XRC_ADD_STYLE(wxDIRP_DIR_MUST_EXIST);
     XRC_ADD_STYLE(wxDIRP_CHANGE_DIR);
+    XRC_ADD_STYLE(wxDIRP_SMALL);
     XRC_ADD_STYLE(wxDIRP_DEFAULT_STYLE);
     AddWindowStyles();
 }
     XRC_ADD_STYLE(wxDIRP_DEFAULT_STYLE);
     AddWindowStyles();
 }
index df544fa0f58476fa657d64617a351999ddf95172..90965a34ca087e7270e6bee4711447caad2a9535 100644 (file)
@@ -29,6 +29,7 @@ wxFilePickerCtrlXmlHandler::wxFilePickerCtrlXmlHandler() : wxXmlResourceHandler(
     XRC_ADD_STYLE(wxFLP_OVERWRITE_PROMPT);
     XRC_ADD_STYLE(wxFLP_FILE_MUST_EXIST);
     XRC_ADD_STYLE(wxFLP_CHANGE_DIR);
     XRC_ADD_STYLE(wxFLP_OVERWRITE_PROMPT);
     XRC_ADD_STYLE(wxFLP_FILE_MUST_EXIST);
     XRC_ADD_STYLE(wxFLP_CHANGE_DIR);
+    XRC_ADD_STYLE(wxFLP_SMALL);
     XRC_ADD_STYLE(wxFLP_DEFAULT_STYLE);
     XRC_ADD_STYLE(wxFLP_USE_TEXTCTRL);
     AddWindowStyles();
     XRC_ADD_STYLE(wxFLP_DEFAULT_STYLE);
     XRC_ADD_STYLE(wxFLP_USE_TEXTCTRL);
     AddWindowStyles();