From 75bc8b3454bd2adda5bf3dc0e60984a275ea7ac3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Aug 2011 14:11:25 +0000 Subject: [PATCH] Added wxFLP_SMALL and wxDIRP_SMALL styles for wx{File,Dir}PickerCtrl. 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 | 1 + include/wx/filepicker.h | 18 +++++++++++++++--- include/wx/pickerbase.h | 1 + interface/wx/filepicker.h | 6 ++++++ samples/widgets/dirpicker.cpp | 11 +++++++++-- samples/widgets/filepicker.cpp | 12 ++++++++++-- src/common/pickerbase.cpp | 21 +++++++++++++-------- src/generic/filepickerg.cpp | 18 +++++++++++++++++- src/xrc/xh_dirpicker.cpp | 1 + src/xrc/xh_filepicker.cpp | 1 + 10 files changed, 74 insertions(+), 16 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 2789e3526c..6fb7429ec8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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(). +- Added wxFLP_SMALL and wxDIRP_SMALL styles. OSX: diff --git a/include/wx/filepicker.h b/include/wx/filepicker.h index 4ddb53f381..3b471b7aca 100644 --- a/include/wx/filepicker.h +++ b/include/wx/filepicker.h @@ -109,12 +109,14 @@ protected: #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 +#define wxDIRP_SMALL wxPB_SMALL // 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 { - 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: @@ -396,7 +403,12 @@ protected: // 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) diff --git a/include/wx/pickerbase.h b/include/wx/pickerbase.h index 56a30d0873..16afd715f0 100644 --- a/include/wx/pickerbase.h +++ b/include/wx/pickerbase.h @@ -31,6 +31,7 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[]; // ---------------------------------------------------------------------------- #define wxPB_USE_TEXTCTRL 0x0002 +#define wxPB_SMALL 0x8000 class WXDLLIMPEXP_CORE wxPickerBase : public wxNavigationEnabled { diff --git a/interface/wx/filepicker.h b/interface/wx/filepicker.h index 95155a17dd..89466aaf09 100644 --- a/interface/wx/filepicker.h +++ b/interface/wx/filepicker.h @@ -37,6 +37,9 @@ 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 @@ -161,6 +164,9 @@ public: 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} diff --git a/samples/widgets/dirpicker.cpp b/samples/widgets/dirpicker.cpp index 1d0044bc4c..7bdfc69d34 100644 --- a/samples/widgets/dirpicker.cpp +++ b/samples/widgets/dirpicker.cpp @@ -100,7 +100,8 @@ protected: wxCheckBox *m_chkDirTextCtrl, *m_chkDirChangeDir, - *m_chkDirMustExist; + *m_chkDirMustExist, + *m_chkSmall; 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_chkSmall = CreateCheckBoxAndAddToSizer(dirbox, "&Small version", false); 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_chkSmall->GetValue() ) + style |= wxDIRP_SMALL; + 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_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 || - event.GetEventObject() == m_chkDirMustExist) + event.GetEventObject() == m_chkDirMustExist || + event.GetEventObject() == m_chkSmall) RecreatePicker(); } diff --git a/samples/widgets/filepicker.cpp b/samples/widgets/filepicker.cpp index 55cfe98c06..8e39578158 100644 --- a/samples/widgets/filepicker.cpp +++ b/samples/widgets/filepicker.cpp @@ -111,7 +111,8 @@ protected: wxCheckBox *m_chkFileTextCtrl, *m_chkFileOverwritePrompt, *m_chkFileMustExist, - *m_chkFileChangeDir; + *m_chkFileChangeDir, + *m_chkSmall; 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_chkSmall = CreateCheckBoxAndAddToSizer(filebox, "&Small version", false); + 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_chkSmall->GetValue() ) + style |= wxFLP_SMALL; + 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_chkSmall->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_SMALL) != 0); UpdateFilePickerMode(); } @@ -291,7 +298,8 @@ void FilePickerWidgetsPage::OnCheckBox(wxCommandEvent &event) 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) diff --git a/src/common/pickerbase.cpp b/src/common/pickerbase.cpp index 797c946876..da1a4ad59d 100644 --- a/src/common/pickerbase.cpp +++ b/src/common/pickerbase.cpp @@ -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 - // 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); diff --git a/src/generic/filepickerg.cpp b/src/generic/filepickerg.cpp index 1aaf01a420..2b1c6d271d 100644 --- a/src/generic/filepickerg.cpp +++ b/src/generic/filepickerg.cpp @@ -54,8 +54,24 @@ bool wxGenericFileDirButton::Create(wxWindow *parent, { 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 - 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; diff --git a/src/xrc/xh_dirpicker.cpp b/src/xrc/xh_dirpicker.cpp index e70c44e14a..ff750e15d1 100644 --- a/src/xrc/xh_dirpicker.cpp +++ b/src/xrc/xh_dirpicker.cpp @@ -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_SMALL); XRC_ADD_STYLE(wxDIRP_DEFAULT_STYLE); AddWindowStyles(); } diff --git a/src/xrc/xh_filepicker.cpp b/src/xrc/xh_filepicker.cpp index df544fa0f5..90965a34ca 100644 --- a/src/xrc/xh_filepicker.cpp +++ b/src/xrc/xh_filepicker.cpp @@ -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_SMALL); XRC_ADD_STYLE(wxFLP_DEFAULT_STYLE); XRC_ADD_STYLE(wxFLP_USE_TEXTCTRL); AddWindowStyles(); -- 2.45.2