add support for custom controls in file dialog in wxGTK and generic versions; also allow using generic dialogs in the sample with wxGTK2 (patch 1846837)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52252 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-03-02 14:33:47 +00:00
parent 77c950fdad
commit 8ce68f7fc0
13 changed files with 216 additions and 110 deletions

View File

@@ -229,6 +229,7 @@ All (GUI):
- Added wxNotificationMessage class for non-intrusive notifications - Added wxNotificationMessage class for non-intrusive notifications
- Added wxWindow::Show/HideWithEffect() - Added wxWindow::Show/HideWithEffect()
- Added wxWrapSizer - Added wxWrapSizer
- Added custom controls support to wxFileDialog (Diaa Sami and Marcin Wojdyr)
- Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron). - Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron).
- Added support for drop down toolbar buttons (Tim Kosse). - Added support for drop down toolbar buttons (Tim Kosse).
- Added support for labels for toolbar controls (Vince Harron). - Added support for labels for toolbar controls (Vince Harron).

View File

@@ -116,6 +116,15 @@ Destructor.
Returns the default directory. Returns the default directory.
\membersection{wxFileDialog::GetExtraControl}\label{wxfiledialoggetextracontrol}
\constfunc{wxWindow* }{GetExtraControl}{\void}
If functions
\helpref{SetExtraControlCreator}{wxfiledialogsetextracontrolcreator}
and \helpref{ShowModal}{wxfiledialogshowmodal} were called,
returns the extra window. Otherwise returns \NULL.
\membersection{wxFileDialog::GetFilename}\label{wxfiledialoggetfilename} \membersection{wxFileDialog::GetFilename}\label{wxfiledialoggetfilename}
\constfunc{wxString}{GetFilename}{\void} \constfunc{wxString}{GetFilename}{\void}
@@ -175,6 +184,26 @@ Returns the file dialog wildcard.
Sets the default directory. Sets the default directory.
\membersection{wxFileDialog::SetExtraControlCreator}\label{wxfiledialogsetextracontrolcreator}
\begin{verbatim}
typedef wxWindow* (*ExtraControlCreatorFunction)(wxWindow*);
\end{verbatim}
\func{bool}{SetExtraControlCreator}{\param{t\_extraControlCreator }{creator}}
Customize file dialog by adding extra window, which is typically placed
below the list of files and above the buttons.
SetExtraControlCreator can be called only once, before calling
\helpref{ShowModal}{wxfiledialogshowmodal}.
The {\tt creator} function should take pointer to parent window (file dialog)
and should return a window allocated with operator new.
Supported platforms: wxGTK, wxUniv.
\wxheading{Return value}
{\tt true} if adding extra controls is supported, {\tt false} otherwise.
\membersection{wxFileDialog::SetFilename}\label{wxfiledialogsetfilename} \membersection{wxFileDialog::SetFilename}\label{wxfiledialogsetfilename}
\func{void}{SetFilename}{\param{const wxString\& }{setfilename}} \func{void}{SetFilename}{\param{const wxString\& }{setfilename}}

View File

@@ -85,6 +85,9 @@ public:
Create(parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name); Create(parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name);
} }
virtual ~wxFileDialogBase() {}
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
const wxString& message = wxFileSelectorPromptStr, const wxString& message = wxFileSelectorPromptStr,
const wxString& defaultDir = wxEmptyString, const wxString& defaultDir = wxEmptyString,
@@ -113,6 +116,17 @@ public:
virtual wxString GetWildcard() const { return m_wildCard; } virtual wxString GetWildcard() const { return m_wildCard; }
virtual int GetFilterIndex() const { return m_filterIndex; } virtual int GetFilterIndex() const { return m_filterIndex; }
// this function is called with wxFileDialog as parameter and should
// create the window containing the extra controls we want to show in it
typedef wxWindow *(*ExtraControlCreatorFunction)(wxWindow*);
// extra controls are currently supported in GTK and generic versions
// only currently
virtual bool SupportsExtraControl() const { return false; }
bool SetExtraControlCreator(ExtraControlCreatorFunction WXUNUSED(c));
wxWindow *GetExtraControl() const { return m_extraControl; }
// Utility functions // Utility functions
#if WXWIN_COMPATIBILITY_2_6 #if WXWIN_COMPATIBILITY_2_6
@@ -137,13 +151,20 @@ protected:
wxString m_fileName; wxString m_fileName;
wxString m_wildCard; wxString m_wildCard;
int m_filterIndex; int m_filterIndex;
wxWindow* m_extraControl;
// returns true if control is created (if it already exists returns false)
bool CreateExtraControl();
private: private:
ExtraControlCreatorFunction m_extraControlCreator;
void Init(); void Init();
DECLARE_DYNAMIC_CLASS(wxFileDialogBase) DECLARE_DYNAMIC_CLASS(wxFileDialogBase)
DECLARE_NO_COPY_CLASS(wxFileDialogBase) DECLARE_NO_COPY_CLASS(wxFileDialogBase)
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxFileDialog convenience functions // wxFileDialog convenience functions
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@@ -82,6 +82,7 @@ public:
{ return m_filectrl->GetWildcard(); } { return m_filectrl->GetWildcard(); }
virtual int GetFilterIndex() const virtual int GetFilterIndex() const
{ return m_filectrl->GetFilterIndex(); } { return m_filectrl->GetFilterIndex(); }
virtual bool SupportsExtraControl() const { return true; }
// implementation only from now on // implementation only from now on
// ------------------------------- // -------------------------------
@@ -113,6 +114,8 @@ protected:
private: private:
void Init(); void Init();
wxBitmapButton* AddBitmapButton( wxWindowID winId, const wxArtID& artId,
const wxString& tip, wxSizer *sizer );
DECLARE_DYNAMIC_CLASS(wxGenericFileDialog) DECLARE_DYNAMIC_CLASS(wxGenericFileDialog)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@@ -30,8 +30,7 @@ public:
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& sz = wxDefaultSize, const wxSize& sz = wxDefaultSize,
const wxString& name = wxFileDialogNameStr); const wxString& name = wxFileDialogNameStr);
virtual ~wxFileDialog() { delete m_extraControl; }
virtual ~wxFileDialog() {}
virtual wxString GetPath() const; virtual wxString GetPath() const;
virtual void GetPaths(wxArrayString& paths) const; virtual void GetPaths(wxArrayString& paths) const;
@@ -48,8 +47,8 @@ public:
virtual void SetFilterIndex(int filterIndex); virtual void SetFilterIndex(int filterIndex);
virtual int ShowModal(); virtual int ShowModal();
virtual bool Show( bool show = true );
virtual bool SupportsExtraControl() const { return true; }
protected: protected:

View File

@@ -112,6 +112,8 @@ COND_PLATFORM_OS2_1___dialogs___os2_emxbindcmd = $(NM) dialogs$(EXEEXT) | if \
@COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@__GENERIC_DIALOGS_IN_NATIVE_BUILDS_OBJECTS \ @COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@__GENERIC_DIALOGS_IN_NATIVE_BUILDS_OBJECTS \
@COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@ = dialogs_colrdlgg.o dialogs_dirdlgg.o \ @COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@ = dialogs_colrdlgg.o dialogs_dirdlgg.o \
@COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@ dialogs_filedlgg.o @COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@ dialogs_filedlgg.o
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__GENERIC_DIALOGS_IN_NATIVE_BUILDS_OBJECTS \
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@ = dialogs_filedlgg.o
@COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@__GENERIC_DIALOGS_IN_NATIVE_BUILDS_OBJECTS \ @COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@__GENERIC_DIALOGS_IN_NATIVE_BUILDS_OBJECTS \
@COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@ = dialogs_fontdlgg.o dialogs_filedlgg.o @COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@ = dialogs_fontdlgg.o dialogs_filedlgg.o
COND_MONOLITHIC_0___WXLIB_ADV_p = \ COND_MONOLITHIC_0___WXLIB_ADV_p = \
@@ -237,6 +239,9 @@ dialogs_dialogs.o: $(srcdir)/dialogs.cpp
@COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@dialogs_filedlgg.o: $(srcdir)/../../src/generic/filedlgg.cpp @COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@dialogs_filedlgg.o: $(srcdir)/../../src/generic/filedlgg.cpp
@COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@ $(CXXC) -c -o $@ $(DIALOGS_CXXFLAGS) $(srcdir)/../../src/generic/filedlgg.cpp @COND_SHARED_0_TOOLKIT_MAC_WXUNIV_0@ $(CXXC) -c -o $@ $(DIALOGS_CXXFLAGS) $(srcdir)/../../src/generic/filedlgg.cpp
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@dialogs_filedlgg.o: $(srcdir)/../../src/generic/filedlgg.cpp
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@ $(CXXC) -c -o $@ $(DIALOGS_CXXFLAGS) $(srcdir)/../../src/generic/filedlgg.cpp
@COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@dialogs_filedlgg.o: $(srcdir)/../../src/generic/filedlgg.cpp @COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@dialogs_filedlgg.o: $(srcdir)/../../src/generic/filedlgg.cpp
@COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@ $(CXXC) -c -o $@ $(DIALOGS_CXXFLAGS) $(srcdir)/../../src/generic/filedlgg.cpp @COND_SHARED_0_TOOLKIT_PM_WXUNIV_0@ $(CXXC) -c -o $@ $(DIALOGS_CXXFLAGS) $(srcdir)/../../src/generic/filedlgg.cpp

View File

@@ -18,6 +18,9 @@
$(WXTOPDIR)src/generic/dirdlgg.cpp $(WXTOPDIR)src/generic/dirdlgg.cpp
$(WXTOPDIR)src/generic/filedlgg.cpp $(WXTOPDIR)src/generic/filedlgg.cpp
</if> </if>
<if cond="TOOLKIT=='GTK' and TOOLKIT_VERSION=='2'">
$(WXTOPDIR)src/generic/filedlgg.cpp
</if>
<if cond="TOOLKIT=='PM' and WXUNIV=='0' and SHARED=='0'"> <if cond="TOOLKIT=='PM' and WXUNIV=='0' and SHARED=='0'">
$(WXTOPDIR)src/generic/fontdlgg.cpp $(WXTOPDIR)src/generic/fontdlgg.cpp
$(WXTOPDIR)src/generic/filedlgg.cpp $(WXTOPDIR)src/generic/filedlgg.cpp

View File

@@ -337,12 +337,12 @@ bool MyApp::OnInit()
filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
#if USE_FILEDLG_GENERIC #if USE_FILEDLG_GENERIC
filedlg_menu->AppendSeparator(); filedlg_menu->AppendSeparator();
filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)")); filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)"));
filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)")); filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)"));
filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)")); filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)"));
#endif // USE_FILEDLG_GENERIC #endif // USE_FILEDLG_GENERIC
menuDlg->Append(wxID_ANY,_T("&File operations"),filedlg_menu); menuDlg->Append(wxID_ANY,_T("&File operations"),filedlg_menu);
@@ -799,6 +799,43 @@ void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
#endif // wxUSE_CHOICEDLG #endif // wxUSE_CHOICEDLG
#if wxUSE_FILEDLG #if wxUSE_FILEDLG
// panel with custom controls for file dialog
class MyExtraPanel : public wxPanel
{
public:
MyExtraPanel(wxWindow *parent);
void OnCheckBox(wxCommandEvent& event) { m_btn->Enable(event.IsChecked()); }
wxString GetInfo() const
{
return wxString::Format("checkbox value = %d", (int) m_cb->GetValue());
}
private:
wxButton *m_btn;
wxCheckBox *m_cb;
};
MyExtraPanel::MyExtraPanel(wxWindow *parent)
: wxPanel(parent)
{
m_btn = new wxButton(this, -1, _T("Custom Button"));
m_btn->Enable(false);
m_cb = new wxCheckBox(this, -1, _T("Enable Custom Button"));
m_cb->Connect(wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler(MyExtraPanel::OnCheckBox), NULL, this);
wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
sizerTop->Add(m_cb, wxSizerFlags().Centre().Border());
sizerTop->AddStretchSpacer();
sizerTop->Add(m_btn, wxSizerFlags().Right().Border());
SetSizerAndFit(sizerTop);
}
// a static method can be used instead of a function with most of compilers
static wxWindow* createMyExtraPanel(wxWindow *parent)
{
return new MyExtraPanel(parent);
}
void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
{ {
wxFileDialog dialog wxFileDialog dialog
@@ -814,18 +851,23 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
#endif #endif
); );
dialog.SetExtraControlCreator(&createMyExtraPanel);
dialog.CentreOnParent(); dialog.CentreOnParent();
dialog.SetDirectory(wxGetHomeDir()); dialog.SetDirectory(wxGetHomeDir());
if (dialog.ShowModal() == wxID_OK) if (dialog.ShowModal() == wxID_OK)
{ {
wxString info; wxString info;
MyExtraPanel *extra_panel
= static_cast<MyExtraPanel*>(dialog.GetExtraControl());
info.Printf(_T("Full file name: %s\n") info.Printf(_T("Full file name: %s\n")
_T("Path: %s\n") _T("Path: %s\n")
_T("Name: %s"), _T("Name: %s\n")
_T("Custom window: %s"),
dialog.GetPath().c_str(), dialog.GetPath().c_str(),
dialog.GetDirectory().c_str(), dialog.GetDirectory().c_str(),
dialog.GetFilename().c_str()); dialog.GetFilename().c_str(),
extra_panel->GetInfo().c_str());
wxMessageDialog dialog2(this, info, _T("Selected file")); wxMessageDialog dialog2(this, info, _T("Selected file"));
dialog2.ShowModal(); dialog2.ShowModal();
} }
@@ -933,6 +975,7 @@ void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
_T("C++ files (*.cpp;*.h)|*.cpp;*.h") _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
); );
dialog.SetExtraControlCreator(&createMyExtraPanel);
dialog.SetDirectory(wxGetHomeDir()); dialog.SetDirectory(wxGetHomeDir());
if (dialog.ShowModal() == wxID_OK) if (dialog.ShowModal() == wxID_OK)
@@ -1264,8 +1307,7 @@ TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
if (button_sizer) if (button_sizer)
main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 ); main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 );
SetSizer( main_sizer ); SetSizerAndFit( main_sizer );
main_sizer->Fit( this );
} }
void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event) void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
@@ -1651,10 +1693,7 @@ MyModelessDialog::MyModelessDialog(wxWindow *parent)
sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
SetSizer(sizerTop); SetSizerAndFit(sizerTop);
sizerTop->SetSizeHints(this);
sizerTop->Fit(this);
} }
void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
@@ -1694,10 +1733,7 @@ MyModalDialog::MyModalDialog(wxWindow *parent)
sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
SetSizer(sizerTop); SetSizerAndFit(sizerTop);
sizerTop->SetSizeHints(this);
sizerTop->Fit(this);
m_btnModal->SetFocus(); m_btnModal->SetFocus();
m_btnModal->SetDefault(); m_btnModal->SetDefault();
@@ -1800,9 +1836,8 @@ StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent)
EnableDisableControls(); EnableDisableControls();
SetSizer(sizerTop); SetSizerAndFit(sizerTop);
sizerTop->SetSizeHints(this);
wxCommandEvent ev; wxCommandEvent ev;
OnEvent(ev); OnEvent(ev);
} }
@@ -2015,8 +2050,7 @@ wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
panel->SetSizer(topSizer); panel->SetSizerAndFit(topSizer);
topSizer->Fit(panel);
return panel; return panel;
} }
@@ -2074,8 +2108,7 @@ wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
topSizer->AddSpacer(5); topSizer->AddSpacer(5);
panel->SetSizer(topSizer); panel->SetSizerAndFit(topSizer);
topSizer->Fit(panel);
return panel; return panel;
} }

View File

@@ -77,7 +77,8 @@ of MSW, MAC and OS2
#define USE_DIRDLG_GENERIC \ #define USE_DIRDLG_GENERIC \
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG) ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG)
#define USE_FILEDLG_GENERIC \ #define USE_FILEDLG_GENERIC \
((((USE_WXMSW || USE_WXMAC || USE_WXPM) && USE_GENERIC_DIALOGS) || USE_WXWINCE) && wxUSE_FILEDLG) ((((USE_WXMSW || USE_WXMAC || USE_WXPM || USE_WXGTK) \
&& USE_GENERIC_DIALOGS) || USE_WXWINCE) && wxUSE_FILEDLG)
#define USE_FONTDLG_GENERIC \ #define USE_FONTDLG_GENERIC \
((USE_WXMSW || USE_WXMACFONTDLG || USE_WXPM) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG) ((USE_WXMSW || USE_WXMACFONTDLG || USE_WXPM) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG)

View File

@@ -35,8 +35,10 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileDialogBase, wxDialog)
void wxFileDialogBase::Init() void wxFileDialogBase::Init()
{ {
m_filterIndex = m_filterIndex = 0;
m_windowStyle = 0; m_windowStyle = 0;
m_extraControl = NULL;
m_extraControlCreator = NULL;
} }
bool wxFileDialogBase::Create(wxWindow *parent, bool wxFileDialogBase::Create(wxWindow *parent,
@@ -149,6 +151,23 @@ wxString wxFileDialogBase::AppendExtension(const wxString &filePath,
return filePath + ext; return filePath + ext;
} }
bool wxFileDialogBase::SetExtraControlCreator(ExtraControlCreatorFunction c)
{
wxCHECK_MSG( !m_extraControlCreator, false,
"wxFileDialog::SetExtraControl() called second time" );
m_extraControlCreator = c;
return SupportsExtraControl();
}
bool wxFileDialogBase::CreateExtraControl()
{
if (!m_extraControlCreator || m_extraControl)
return false;
m_extraControl = (*m_extraControlCreator)(this);
return true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxFileDialog convenience functions // wxFileDialog convenience functions
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@@ -912,6 +912,7 @@ bool wxGenericFileCtrl::Create( wxWindow *parent,
this->m_style = style; this->m_style = style;
m_inSelected = false; m_inSelected = false;
m_noSelChgEvent = false; m_noSelChgEvent = false;
m_check = NULL;
// check that the styles are not contradictory // check that the styles are not contradictory
wxASSERT_MSG( !( ( m_style & wxFC_SAVE ) && ( m_style & wxFC_OPEN ) ), wxASSERT_MSG( !( ( m_style & wxFC_SAVE ) && ( m_style & wxFC_OPEN ) ),
@@ -947,10 +948,11 @@ bool wxGenericFileCtrl::Create( wxWindow *parent,
wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL );
if ( is_pda ) if ( is_pda )
staticsizer->Add( new wxStaticText( this, wxID_ANY, _( "Current directory:" ) ), 0, wxRIGHT, 10 ); staticsizer->Add( new wxStaticText( this, wxID_ANY, _( "Current directory:" ) ),
wxSizerFlags().DoubleBorder(wxRIGHT) );
m_static = new wxStaticText( this, wxID_ANY, m_dir ); m_static = new wxStaticText( this, wxID_ANY, m_dir );
staticsizer->Add( m_static, 1 ); staticsizer->Add( m_static, 1 );
mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10 ); mainsizer->Add( staticsizer, wxSizerFlags().Expand().Border());
long style2 = wxLC_LIST; long style2 = wxLC_LIST;
if ( !( m_style & wxFC_MULTIPLE ) ) if ( !( m_style & wxFC_MULTIPLE ) )
@@ -979,33 +981,25 @@ bool wxGenericFileCtrl::Create( wxWindow *parent,
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
textsizer->Add( m_text, wxSizerFlags( 1 ).Centre().Border() ); textsizer->Add( m_text, wxSizerFlags( 1 ).Centre().Border() );
textsizer->Add( m_choice, wxSizerFlags( 1 ).Centre().Border() );
mainsizer->Add( textsizer, wxSizerFlags().Expand() ); mainsizer->Add( textsizer, wxSizerFlags().Expand() );
m_check = NULL;
textsizer->Add( m_choice, wxSizerFlags( 1 ).Centre().Border() );
} }
else // !is_pda else // !is_pda
{ {
mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().DoubleHorzBorder() ); mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().Border() );
mainsizer->Add( m_text, wxSizerFlags().Expand().Border() );
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
textsizer->Add( m_text, wxSizerFlags( 1 ).Centre().
DoubleBorder( wxLEFT | wxRIGHT | wxTOP ) );
mainsizer->Add( textsizer, wxSizerFlags().Expand() );
wxSizerFlags flagsCentre;
flagsCentre.Centre().DoubleBorder();
wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
choicesizer->Add( m_choice, wxSizerFlags( flagsCentre ).Proportion( 1 ) ); choicesizer->Add( m_choice, wxSizerFlags( 1 ).Centre() );
if ( !( m_style & wxFC_NOSHOWHIDDEN ) ) if ( !( m_style & wxFC_NOSHOWHIDDEN ) )
{ {
m_check = new wxCheckBox( this, ID_CHECK, _( "Show &hidden files" ) ); m_check = new wxCheckBox( this, ID_CHECK, _( "Show &hidden files" ) );
choicesizer->Add( m_check, flagsCentre ); choicesizer->Add( m_check, wxSizerFlags().Centre().DoubleBorder(wxLEFT) );
} }
mainsizer->Add( choicesizer, wxSizerFlags().Expand() ); mainsizer->Add( choicesizer, wxSizerFlags().Expand().Border() );
} }
SetWildcard( wildCard ); SetWildcard( wildCard );

View File

@@ -103,7 +103,7 @@
#define ID_LIST_MODE (wxID_FILEDLGG ) #define ID_LIST_MODE (wxID_FILEDLGG )
#define ID_REPORT_MODE (wxID_FILEDLGG + 1) #define ID_REPORT_MODE (wxID_FILEDLGG + 1)
#define ID_UP_DIR (wxID_FILEDLGG + 2) #define ID_UP_DIR (wxID_FILEDLGG + 2)
#define ID_PARENT_DIR (wxID_FILEDLGG + 3) #define ID_HOME_DIR (wxID_FILEDLGG + 3)
#define ID_NEW_DIR (wxID_FILEDLGG + 4) #define ID_NEW_DIR (wxID_FILEDLGG + 4)
#define ID_FILE_CTRL (wxID_FILEDLGG + 5) #define ID_FILE_CTRL (wxID_FILEDLGG + 5)
@@ -113,7 +113,7 @@ BEGIN_EVENT_TABLE(wxGenericFileDialog,wxDialog)
EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList) EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList)
EVT_BUTTON(ID_REPORT_MODE, wxGenericFileDialog::OnReport) EVT_BUTTON(ID_REPORT_MODE, wxGenericFileDialog::OnReport)
EVT_BUTTON(ID_UP_DIR, wxGenericFileDialog::OnUp) EVT_BUTTON(ID_UP_DIR, wxGenericFileDialog::OnUp)
EVT_BUTTON(ID_PARENT_DIR, wxGenericFileDialog::OnHome) EVT_BUTTON(ID_HOME_DIR, wxGenericFileDialog::OnHome)
EVT_BUTTON(ID_NEW_DIR, wxGenericFileDialog::OnNew) EVT_BUTTON(ID_NEW_DIR, wxGenericFileDialog::OnNew)
EVT_BUTTON(wxID_OK, wxGenericFileDialog::OnOk) EVT_BUTTON(wxID_OK, wxGenericFileDialog::OnOk)
EVT_FILECTRL_FILEACTIVATED(ID_FILE_CTRL, wxGenericFileDialog::OnFileActivated) EVT_FILECTRL_FILEACTIVATED(ID_FILE_CTRL, wxGenericFileDialog::OnFileActivated)
@@ -212,54 +212,28 @@ bool wxGenericFileDialog::Create( wxWindow *parent,
wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
AddBitmapButton( ID_LIST_MODE, wxART_LIST_VIEW,
wxBitmapButton *but; _("View files as a list view"), buttonsizer );
AddBitmapButton( ID_REPORT_MODE, wxART_REPORT_VIEW,
but = new wxBitmapButton(this, ID_LIST_MODE, _("View files as a detailed view"), buttonsizer );
wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_BUTTON));
#if wxUSE_TOOLTIPS
but->SetToolTip( _("View files as a list view") );
#endif
buttonsizer->Add( but, 0, wxALL, 5 );
but = new wxBitmapButton(this, ID_REPORT_MODE,
wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_BUTTON));
#if wxUSE_TOOLTIPS
but->SetToolTip( _("View files as a detailed view") );
#endif
buttonsizer->Add( but, 0, wxALL, 5 );
buttonsizer->Add( 30, 5, 1 ); buttonsizer->Add( 30, 5, 1 );
m_upDirButton = AddBitmapButton( ID_UP_DIR, wxART_GO_DIR_UP,
m_upDirButton = new wxBitmapButton(this, ID_UP_DIR, _("Go to parent directory"), buttonsizer );
wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_BUTTON));
#if wxUSE_TOOLTIPS
m_upDirButton->SetToolTip( _("Go to parent directory") );
#endif
buttonsizer->Add( m_upDirButton, 0, wxALL, 5 );
#ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS... #ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS...
but = new wxBitmapButton(this, ID_PARENT_DIR, AddBitmapButton( ID_HOME_DIR, wxART_GO_HOME,
wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_BUTTON)); _("Go to home directory"), buttonsizer );
#if wxUSE_TOOLTIPS
but->SetToolTip( _("Go to home directory") );
#endif
buttonsizer->Add( but, 0, wxALL, 5);
buttonsizer->Add( 20, 20 ); buttonsizer->Add( 20, 20 );
#endif //!__DOS__ #endif //!__DOS__
m_newDirButton = new wxBitmapButton(this, ID_NEW_DIR, m_newDirButton = AddBitmapButton( ID_NEW_DIR, wxART_NEW_DIR,
wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_BUTTON)); _("Create new directory"), buttonsizer );
#if wxUSE_TOOLTIPS
m_newDirButton->SetToolTip( _("Create new directory") );
#endif
buttonsizer->Add( m_newDirButton, 0, wxALL, 5 );
if (is_pda) if (is_pda)
mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 0 ); mainsizer->Add( buttonsizer, wxSizerFlags().Expand() );
else else
mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 ); mainsizer->Add( buttonsizer, wxSizerFlags().Expand()
.Border( wxLEFT | wxRIGHT | wxTOP ) );
long style2 = 0; long style2 = 0;
if ( HasFdFlag(wxFD_MULTIPLE) ) if ( HasFdFlag(wxFD_MULTIPLE) )
@@ -283,31 +257,21 @@ bool wxGenericFileDialog::Create( wxWindow *parent,
m_filectrl->ChangeToReportMode(); m_filectrl->ChangeToReportMode();
} }
if (is_pda) mainsizer->Add(m_filectrl, wxSizerFlags(1).Expand().HorzBorder());
{
// PDAs have a different screen layout
mainsizer->Add(m_filectrl, wxSizerFlags(1).Expand().HorzBorder());
wxSizer *bsizer = CreateButtonSizer(wxOK | wxCANCEL); wxSizer *bsizer = CreateButtonSizer(wxOK | wxCANCEL);
if ( bsizer ) if ( bsizer )
{
if (is_pda)
mainsizer->Add(bsizer, wxSizerFlags().Expand().Border()); mainsizer->Add(bsizer, wxSizerFlags().Expand().Border());
else
mainsizer->Add(bsizer, wxSizerFlags().Expand().DoubleBorder());
} }
else // !is_pda
{
mainsizer->Add(m_filectrl, wxSizerFlags(1).Expand().DoubleHorzBorder());
wxBoxSizer *okcancelsizer = new wxBoxSizer( wxHORIZONTAL );
okcancelsizer->Add(new wxButton(this, wxID_OK), wxSizerFlags().DoubleBorder().Centre());
okcancelsizer->Add(new wxButton(this, wxID_CANCEL), wxSizerFlags().DoubleBorder().Centre());
mainsizer->Add(okcancelsizer, wxSizerFlags().Center());
}
SetAutoLayout( true );
SetSizer( mainsizer ); SetSizer( mainsizer );
if (!is_pda) if (!is_pda)
{ {
mainsizer->Fit( this );
mainsizer->SetSizeHints( this ); mainsizer->SetSizeHints( this );
Centre( wxBOTH ); Centre( wxBOTH );
@@ -332,8 +296,28 @@ wxGenericFileDialog::~wxGenericFileDialog()
} }
} }
wxBitmapButton* wxGenericFileDialog::AddBitmapButton( wxWindowID winId,
const wxArtID& artId,
const wxString& tip,
wxSizer *sizer)
{
wxBitmapButton *but = new wxBitmapButton(this, winId,
wxArtProvider::GetBitmap(artId, wxART_BUTTON));
but->SetToolTip(tip);
sizer->Add(but, wxSizerFlags().Border());
return but;
}
int wxGenericFileDialog::ShowModal() int wxGenericFileDialog::ShowModal()
{ {
if (CreateExtraControl())
{
wxSizer *sizer = GetSizer();
sizer->Insert(2 /* after m_filectrl */, m_extraControl,
wxSizerFlags().Expand().HorzBorder());
sizer->Fit(this);
}
m_filectrl->SetDirectory(m_dir); m_filectrl->SetDirectory(m_dir);
return wxDialog::ShowModal(); return wxDialog::ShowModal();

View File

@@ -131,6 +131,11 @@ static void gtk_filedialog_update_preview_callback(GtkFileChooser *chooser,
} // extern "C" } // extern "C"
static void wxInsertChildInFileDialog(wxWindow* WXUNUSED(parent),
wxWindow* WXUNUSED(child))
{
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxFileDialog // wxFileDialog
@@ -151,6 +156,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
const wxString& name) const wxString& name)
: wxFileDialogBase() : wxFileDialogBase()
{ {
m_insertCallback = wxInsertChildInFileDialog;
parent = GetParentForModalDialog(parent); parent = GetParentForModalDialog(parent);
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName, if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName,
@@ -276,6 +282,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
} }
} }
void wxFileDialog::OnFakeOk(wxCommandEvent& WXUNUSED(event)) void wxFileDialog::OnFakeOk(wxCommandEvent& WXUNUSED(event))
{ {
EndDialog(wxID_OK); EndDialog(wxID_OK);
@@ -283,12 +290,19 @@ void wxFileDialog::OnFakeOk(wxCommandEvent& WXUNUSED(event))
int wxFileDialog::ShowModal() int wxFileDialog::ShowModal()
{ {
return wxDialog::ShowModal(); if (CreateExtraControl())
} {
GtkWidget *control = m_extraControl->m_widget;
bool wxFileDialog::Show( bool show ) // see wxNotebook::InsertPage() for explaination
{ // why gtk_widget_unparent() is not used here
return wxDialog::Show( show ); control->parent = NULL;
gtk_widget_show(control);
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(m_widget), control);
}
return wxDialog::ShowModal();
} }
void wxFileDialog::DoSetSize(int WXUNUSED(x), int WXUNUSED(y), void wxFileDialog::DoSetSize(int WXUNUSED(x), int WXUNUSED(y),