Moved the implemtation of the generic and the

native GTK 2.4 file dialogs into one place
   by making wxFileDialog derive from the
   generic variant and by then choosing which
   implementation to use. Later, we'll add
   run-time checks.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30868 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2004-12-05 20:30:18 +00:00
parent 822cf31c27
commit 4e1901b70e
7 changed files with 321 additions and 119 deletions

View File

@ -159,11 +159,7 @@ wxSaveFileSelector(const wxChar *what,
#elif defined(__WXMOTIF__) #elif defined(__WXMOTIF__)
#include "wx/motif/filedlg.h" #include "wx/motif/filedlg.h"
#elif defined(__WXGTK__) #elif defined(__WXGTK__)
#ifdef __WXGTK24__
#include "wx/gtk/filedlg.h" #include "wx/gtk/filedlg.h"
#else
#include "wx/generic/filedlgg.h"
#endif
#elif defined(__WXX11__) #elif defined(__WXX11__)
#include "wx/generic/filedlgg.h" #include "wx/generic/filedlgg.h"
#elif defined(__WXMGL__) #elif defined(__WXMGL__)

View File

@ -34,7 +34,7 @@ class WXDLLEXPORT wxListItem;
class WXDLLEXPORT wxStaticText; class WXDLLEXPORT wxStaticText;
class WXDLLEXPORT wxTextCtrl; class WXDLLEXPORT wxTextCtrl;
#if defined(__WXUNIVERSAL__)||defined(__WXGTK__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__) #if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__)
#define USE_GENERIC_FILEDIALOG #define USE_GENERIC_FILEDIALOG
#endif #endif
@ -53,7 +53,15 @@ public:
const wxString& defaultFile = wxEmptyString, const wxString& defaultFile = wxEmptyString,
const wxString& wildCard = wxFileSelectorDefaultWildcardStr, const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
long style = 0, long style = 0,
const wxPoint& pos = wxDefaultPosition); const wxPoint& pos = wxDefaultPosition,
bool bypassGenericImpl = false );
bool Create( wxWindow *parent,
const wxString& message = wxFileSelectorPromptStr,
const wxString& defaultDir = wxEmptyString,
const wxString& defaultFile = wxEmptyString,
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
long style = 0,
const wxPoint& pos = wxDefaultPosition );
virtual ~wxGenericFileDialog(); virtual ~wxGenericFileDialog();
virtual void SetMessage(const wxString& message) { SetTitle(message); } virtual void SetMessage(const wxString& message) { SetTitle(message); }
@ -87,6 +95,10 @@ public:
virtual void HandleAction( const wxString &fn ); virtual void HandleAction( const wxString &fn );
virtual void UpdateControls(); virtual void UpdateControls();
private:
// Don't use this implementation at all :-)
bool m_bypassGenericImpl;
protected: protected:
// use the filter with the given index // use the filter with the given index
@ -114,8 +126,6 @@ private:
class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog
{ {
DECLARE_DYNAMIC_CLASS(wxFileDialog)
public: public:
wxFileDialog() {} wxFileDialog() {}
@ -129,6 +139,9 @@ public:
:wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos) :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos)
{ {
} }
private:
DECLARE_DYNAMIC_CLASS(wxFileDialog)
}; };
#endif // USE_GENERIC_FILEDIALOG #endif // USE_GENERIC_FILEDIALOG

View File

@ -15,11 +15,13 @@
#pragma interface #pragma interface
#endif #endif
#include "wx/generic/filedlgg.h"
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxFileDialog // wxFileDialog
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxFileDialog: public wxFileDialogBase class wxFileDialog: public wxGenericFileDialog
{ {
public: public:
wxFileDialog() { } wxFileDialog() { }
@ -44,13 +46,20 @@ public:
virtual void SetWildcard(const wxString& wildCard); virtual void SetWildcard(const wxString& wildCard);
virtual void SetFilterIndex(int filterIndex); virtual void SetFilterIndex(int filterIndex);
virtual int ShowModal();
virtual bool Show( bool show = true );
void OnFakeOk( wxCommandEvent &event );
//private: //private:
bool m_destroyed_by_delete; bool m_destroyed_by_delete;
void UpdateFromDialog(); void UpdateFromDialog();
void UpdateDialog(); void UpdateDialog();
private:
DECLARE_DYNAMIC_CLASS(wxFileDialog) DECLARE_DYNAMIC_CLASS(wxFileDialog)
DECLARE_EVENT_TABLE()
}; };
#endif // __GTKFILEDLGH__ #endif // __GTKFILEDLGH__

View File

@ -15,11 +15,13 @@
#pragma interface #pragma interface
#endif #endif
#include "wx/generic/filedlgg.h"
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxFileDialog // wxFileDialog
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxFileDialog: public wxFileDialogBase class wxFileDialog: public wxGenericFileDialog
{ {
public: public:
wxFileDialog() { } wxFileDialog() { }
@ -44,13 +46,20 @@ public:
virtual void SetWildcard(const wxString& wildCard); virtual void SetWildcard(const wxString& wildCard);
virtual void SetFilterIndex(int filterIndex); virtual void SetFilterIndex(int filterIndex);
virtual int ShowModal();
virtual bool Show( bool show = true );
void OnFakeOk( wxCommandEvent &event );
//private: //private:
bool m_destroyed_by_delete; bool m_destroyed_by_delete;
void UpdateFromDialog(); void UpdateFromDialog();
void UpdateDialog(); void UpdateDialog();
private:
DECLARE_DYNAMIC_CLASS(wxFileDialog) DECLARE_DYNAMIC_CLASS(wxFileDialog)
DECLARE_EVENT_TABLE()
}; };
#endif // __GTKFILEDLGH__ #endif // __GTKFILEDLGH__

View File

@ -20,7 +20,7 @@
#pragma hdrstop #pragma hdrstop
#endif #endif
#if wxUSE_FILEDLG && !defined(__WXGTK24__) #if wxUSE_FILEDLG
// NOTE : it probably also supports MAC, untested // NOTE : it probably also supports MAC, untested
#if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__) && !defined(__OS2__) #if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__) && !defined(__OS2__)
@ -876,11 +876,29 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
const wxString& defaultFile, const wxString& defaultFile,
const wxString& wildCard, const wxString& wildCard,
long style, long style,
const wxPoint& pos ) const wxPoint& pos,
bool bypassGenericImpl )
:wxFileDialogBase(parent, message, defaultDir, defaultFile, wildCard, style, pos) :wxFileDialogBase(parent, message, defaultDir, defaultFile, wildCard, style, pos)
{ {
wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize, m_bypassGenericImpl = bypassGenericImpl;
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
if (!m_bypassGenericImpl)
Create( parent, message, defaultDir, defaultFile, wildCard, style, pos );
}
bool wxGenericFileDialog::Create( wxWindow *parent,
const wxString& message,
const wxString& defaultDir,
const wxString& defaultFile,
const wxString& wildCard,
long style,
const wxPoint& pos )
{
if (!wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ))
{
return false;
}
if (wxConfig::Get(false)) if (wxConfig::Get(false))
{ {
@ -1031,22 +1049,27 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
Centre( wxBOTH ); Centre( wxBOTH );
m_text->SetFocus(); m_text->SetFocus();
return true;
} }
wxGenericFileDialog::~wxGenericFileDialog() wxGenericFileDialog::~wxGenericFileDialog()
{ {
if (wxConfig::Get(false)) if (!m_bypassGenericImpl)
{ {
wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"), if (wxConfig::Get(false))
ms_lastViewStyle); {
wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"), wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"),
ms_lastShowHidden); ms_lastViewStyle);
} wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"),
ms_lastShowHidden);
}
const int count = m_choice->GetCount(); const int count = m_choice->GetCount();
for ( int i = 0; i < count; i++ ) for ( int i = 0; i < count; i++ )
{ {
delete (wxString *)m_choice->GetClientData(i); delete (wxString *)m_choice->GetClientData(i);
}
} }
} }
@ -1416,5 +1439,5 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog);
#endif // USE_GENERIC_FILEDIALOG #endif // USE_GENERIC_FILEDIALOG
#endif // wxUSE_FILEDLG && !defined(__WXGTK24__) #endif // wxUSE_FILEDLG

View File

@ -14,7 +14,7 @@
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if wxUSE_FILEDLG && defined(__WXGTK24__) #if wxUSE_FILEDLG
#include "wx/filedlg.h" #include "wx/filedlg.h"
#include "wx/utils.h" #include "wx/utils.h"
@ -23,6 +23,8 @@
#include "wx/msgdlg.h" #include "wx/msgdlg.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#ifdef __WXGTK24__
#include "wx/gtk/private.h" #include "wx/gtk/private.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -118,21 +120,27 @@ static void gtk_filedialog_response_callback(GtkWidget *w,
dialog->m_destroyed_by_delete = TRUE; dialog->m_destroyed_by_delete = TRUE;
} }
} }
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxFileDialog // wxFileDialog
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxFileDialogBase) IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxGenericFileDialog)
BEGIN_EVENT_TABLE(wxFileDialog,wxGenericFileDialog)
EVT_BUTTON(wxID_OK, wxFileDialog::OnFakeOk)
END_EVENT_TABLE()
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
const wxString& defaultDir, const wxString& defaultDir,
const wxString& defaultFileName, const wxString& defaultFileName,
const wxString& wildCard, const wxString& wildCard,
long style, const wxPoint& pos) long style, const wxPoint& pos)
: wxFileDialogBase(parent, message, defaultDir, defaultFileName, : wxGenericFileDialog(parent, message, defaultDir, defaultFileName,
wildCard, style, pos) wildCard, style, pos, true )
{ {
#ifdef __WXGTK24__
m_needParent = FALSE; m_needParent = FALSE;
m_destroyed_by_delete = FALSE; m_destroyed_by_delete = FALSE;
@ -184,16 +192,49 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
SetWildcard(wildCard); SetWildcard(wildCard);
SetFilterIndex(0); SetFilterIndex(0);
#else
wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos );
#endif
} }
wxFileDialog::~wxFileDialog() wxFileDialog::~wxFileDialog()
{ {
#ifdef __WXGTK24__
if (m_destroyed_by_delete) if (m_destroyed_by_delete)
m_widget = NULL; m_widget = NULL;
#endif
}
void wxFileDialog::OnFakeOk( wxCommandEvent &event )
{
#ifdef __WXGTK24__
wxDialog::OnOK( event );
#else
wxGenericFileDialog::OnListOk( event );
#endif
}
int wxFileDialog::ShowModal()
{
#ifdef __WXGTK24__
return wxDialog::ShowModal();
#else
return wxGenericFileDialog::ShowModal();
#endif
}
bool wxFileDialog::Show( bool show )
{
#ifdef __WXGTK24__
return wxDialog::Show( show );
#else
return wxGenericFileDialog::Show( show );
#endif
} }
void wxFileDialog::GetFilenames(wxArrayString& files) const void wxFileDialog::GetFilenames(wxArrayString& files) const
{ {
#ifdef __WXGTK24__
GetPaths(files); GetPaths(files);
for (size_t n = 0; n < files.GetCount(); n++ ) for (size_t n = 0; n < files.GetCount(); n++ )
{ {
@ -206,10 +247,14 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const
} }
files[n] = name; files[n] = name;
} }
#else
wxGenericFileDialog::GetFilenames( files );
#endif
} }
void wxFileDialog::GetPaths(wxArrayString& paths) const void wxFileDialog::GetPaths(wxArrayString& paths) const
{ {
#ifdef __WXGTK24__
paths.Empty(); paths.Empty();
if (GetWindowStyle() & wxMULTIPLE) if (GetWindowStyle() & wxMULTIPLE)
{ {
@ -230,16 +275,24 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const
{ {
paths.Add(m_fileName); paths.Add(m_fileName);
} }
#else
wxGenericFileDialog::GetPaths( paths );
#endif
} }
void wxFileDialog::SetMessage(const wxString& message) void wxFileDialog::SetMessage(const wxString& message)
{ {
#ifdef __WXGTK24__
m_message = message; m_message = message;
SetTitle(message); SetTitle(message);
#else
wxGenericFileDialog::SetMessage( message );
#endif
} }
void wxFileDialog::SetPath(const wxString& path) void wxFileDialog::SetPath(const wxString& path)
{ {
#ifdef __WXGTK24__
if (path.empty()) return; if (path.empty()) return;
wxFileName fn(path); wxFileName fn(path);
@ -247,68 +300,39 @@ void wxFileDialog::SetPath(const wxString& path)
m_dir = fn.GetPath(); m_dir = fn.GetPath();
m_fileName = fn.GetFullName(); m_fileName = fn.GetFullName();
UpdateDialog(); UpdateDialog();
#else
wxGenericFileDialog::SetPath( path );
#endif
} }
void wxFileDialog::SetDirectory(const wxString& dir) void wxFileDialog::SetDirectory(const wxString& dir)
{ {
#ifdef __WXGTK24__
if (wxDirExists(dir)) if (wxDirExists(dir))
{ {
m_dir = dir; m_dir = dir;
m_path = wxFileName(m_dir, m_fileName).GetFullPath(); m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog(); UpdateDialog();
} }
#else
wxGenericFileDialog::SetDirectory( dir );
#endif
} }
void wxFileDialog::SetFilename(const wxString& name) void wxFileDialog::SetFilename(const wxString& name)
{ {
#ifdef __WXGTK24__
m_fileName = name; m_fileName = name;
m_path = wxFileName(m_dir, m_fileName).GetFullPath(); m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog(); UpdateDialog();
} #else
wxGenericFileDialog::SetFilename( name );
void wxFileDialog::UpdateDialog() #endif
{
// set currently selected directory to match the path:
if (!m_dir.empty() && wxDirExists(m_dir))
{
// NB: This is important -- if we set directory only and not the path,
// then dialog will still remember old path set using previous
// call to gtk_chooser_set_filename. If the previous directory
// was a subdirectory of the directory we want to select now,
// the dialog would still contain directory selector controls
// for the subdirectory (with the parent directory selected),
// instead of showing only the parent directory as expected.
// This way, we force GtkFileChooser to really change the
// directory. Finally, it doesn't have to be done if filename
// is not empty because of the code that sets the filename below.
if (m_fileName.empty())
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
}
// if the user set only the directory (e.g. by calling SetDirectory)
// and not the default filename, then we don't want to set the filename:
if (!m_fileName.empty())
{
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_path));
// pre-fill the filename when saving, too (there's no text entry
// control when opening a file, so it doesn't make sense to
// do this when opening files):
if (GetWindowStyle() & wxSAVE)
{
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_fileName));
}
}
} }
void wxFileDialog::SetWildcard(const wxString& wildCard) void wxFileDialog::SetWildcard(const wxString& wildCard)
{ {
#ifdef __WXGTK24__
m_wildCard = wildCard; m_wildCard = wildCard;
GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget); GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget);
@ -350,10 +374,14 @@ void wxFileDialog::SetWildcard(const wxString& wildCard)
gtk_file_chooser_add_filter(chooser, filter); gtk_file_chooser_add_filter(chooser, filter);
} }
} }
#else
wxGenericFileDialog::SetWildcard( wildCard );
#endif
} }
void wxFileDialog::SetFilterIndex(int filterIndex) void wxFileDialog::SetFilterIndex(int filterIndex)
{ {
#ifdef __WXGTK24__
m_filterIndex = filterIndex; m_filterIndex = filterIndex;
GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget); GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget);
@ -372,10 +400,57 @@ void wxFileDialog::SetFilterIndex(int filterIndex)
fnode = fnode->next; fnode = fnode->next;
} }
g_slist_free(filters); g_slist_free(filters);
#else
wxGenericFileDialog::SetFilterIndex( filterIndex );
#endif
}
void wxFileDialog::UpdateDialog()
{
#ifdef __WXGTK24__
// set currently selected directory to match the path:
if (!m_dir.empty() && wxDirExists(m_dir))
{
// NB: This is important -- if we set directory only and not the path,
// then dialog will still remember old path set using previous
// call to gtk_chooser_set_filename. If the previous directory
// was a subdirectory of the directory we want to select now,
// the dialog would still contain directory selector controls
// for the subdirectory (with the parent directory selected),
// instead of showing only the parent directory as expected.
// This way, we force GtkFileChooser to really change the
// directory. Finally, it doesn't have to be done if filename
// is not empty because of the code that sets the filename below.
if (m_fileName.empty())
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
}
// if the user set only the directory (e.g. by calling SetDirectory)
// and not the default filename, then we don't want to set the filename:
if (!m_fileName.empty())
{
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_path));
// pre-fill the filename when saving, too (there's no text entry
// control when opening a file, so it doesn't make sense to
// do this when opening files):
if (GetWindowStyle() & wxSAVE)
{
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_fileName));
}
}
#endif
} }
void wxFileDialog::UpdateFromDialog() void wxFileDialog::UpdateFromDialog()
{ {
#ifdef __WXGTK24__
// update filterIndex // update filterIndex
GSList *fnode = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(m_widget)); GSList *fnode = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(m_widget));
GSList *filters = fnode; GSList *filters = fnode;
@ -395,6 +470,7 @@ void wxFileDialog::UpdateFromDialog()
fnode = fnode->next; fnode = fnode->next;
} }
g_slist_free(filters); g_slist_free(filters);
#endif
} }
#endif // wxUSE_FILEDLG && defined(__WXGTK24__) #endif // wxUSE_FILEDLG

View File

@ -14,7 +14,7 @@
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if wxUSE_FILEDLG && defined(__WXGTK24__) #if wxUSE_FILEDLG
#include "wx/filedlg.h" #include "wx/filedlg.h"
#include "wx/utils.h" #include "wx/utils.h"
@ -23,6 +23,8 @@
#include "wx/msgdlg.h" #include "wx/msgdlg.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#ifdef __WXGTK24__
#include "wx/gtk/private.h" #include "wx/gtk/private.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -118,21 +120,27 @@ static void gtk_filedialog_response_callback(GtkWidget *w,
dialog->m_destroyed_by_delete = TRUE; dialog->m_destroyed_by_delete = TRUE;
} }
} }
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxFileDialog // wxFileDialog
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxFileDialogBase) IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxGenericFileDialog)
BEGIN_EVENT_TABLE(wxFileDialog,wxGenericFileDialog)
EVT_BUTTON(wxID_OK, wxFileDialog::OnFakeOk)
END_EVENT_TABLE()
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
const wxString& defaultDir, const wxString& defaultDir,
const wxString& defaultFileName, const wxString& defaultFileName,
const wxString& wildCard, const wxString& wildCard,
long style, const wxPoint& pos) long style, const wxPoint& pos)
: wxFileDialogBase(parent, message, defaultDir, defaultFileName, : wxGenericFileDialog(parent, message, defaultDir, defaultFileName,
wildCard, style, pos) wildCard, style, pos, true )
{ {
#ifdef __WXGTK24__
m_needParent = FALSE; m_needParent = FALSE;
m_destroyed_by_delete = FALSE; m_destroyed_by_delete = FALSE;
@ -184,16 +192,49 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
SetWildcard(wildCard); SetWildcard(wildCard);
SetFilterIndex(0); SetFilterIndex(0);
#else
wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos );
#endif
} }
wxFileDialog::~wxFileDialog() wxFileDialog::~wxFileDialog()
{ {
#ifdef __WXGTK24__
if (m_destroyed_by_delete) if (m_destroyed_by_delete)
m_widget = NULL; m_widget = NULL;
#endif
}
void wxFileDialog::OnFakeOk( wxCommandEvent &event )
{
#ifdef __WXGTK24__
wxDialog::OnOK( event );
#else
wxGenericFileDialog::OnListOk( event );
#endif
}
int wxFileDialog::ShowModal()
{
#ifdef __WXGTK24__
return wxDialog::ShowModal();
#else
return wxGenericFileDialog::ShowModal();
#endif
}
bool wxFileDialog::Show( bool show )
{
#ifdef __WXGTK24__
return wxDialog::Show( show );
#else
return wxGenericFileDialog::Show( show );
#endif
} }
void wxFileDialog::GetFilenames(wxArrayString& files) const void wxFileDialog::GetFilenames(wxArrayString& files) const
{ {
#ifdef __WXGTK24__
GetPaths(files); GetPaths(files);
for (size_t n = 0; n < files.GetCount(); n++ ) for (size_t n = 0; n < files.GetCount(); n++ )
{ {
@ -206,10 +247,14 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const
} }
files[n] = name; files[n] = name;
} }
#else
wxGenericFileDialog::GetFilenames( files );
#endif
} }
void wxFileDialog::GetPaths(wxArrayString& paths) const void wxFileDialog::GetPaths(wxArrayString& paths) const
{ {
#ifdef __WXGTK24__
paths.Empty(); paths.Empty();
if (GetWindowStyle() & wxMULTIPLE) if (GetWindowStyle() & wxMULTIPLE)
{ {
@ -230,16 +275,24 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const
{ {
paths.Add(m_fileName); paths.Add(m_fileName);
} }
#else
wxGenericFileDialog::GetPaths( paths );
#endif
} }
void wxFileDialog::SetMessage(const wxString& message) void wxFileDialog::SetMessage(const wxString& message)
{ {
#ifdef __WXGTK24__
m_message = message; m_message = message;
SetTitle(message); SetTitle(message);
#else
wxGenericFileDialog::SetMessage( message );
#endif
} }
void wxFileDialog::SetPath(const wxString& path) void wxFileDialog::SetPath(const wxString& path)
{ {
#ifdef __WXGTK24__
if (path.empty()) return; if (path.empty()) return;
wxFileName fn(path); wxFileName fn(path);
@ -247,68 +300,39 @@ void wxFileDialog::SetPath(const wxString& path)
m_dir = fn.GetPath(); m_dir = fn.GetPath();
m_fileName = fn.GetFullName(); m_fileName = fn.GetFullName();
UpdateDialog(); UpdateDialog();
#else
wxGenericFileDialog::SetPath( path );
#endif
} }
void wxFileDialog::SetDirectory(const wxString& dir) void wxFileDialog::SetDirectory(const wxString& dir)
{ {
#ifdef __WXGTK24__
if (wxDirExists(dir)) if (wxDirExists(dir))
{ {
m_dir = dir; m_dir = dir;
m_path = wxFileName(m_dir, m_fileName).GetFullPath(); m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog(); UpdateDialog();
} }
#else
wxGenericFileDialog::SetDirectory( dir );
#endif
} }
void wxFileDialog::SetFilename(const wxString& name) void wxFileDialog::SetFilename(const wxString& name)
{ {
#ifdef __WXGTK24__
m_fileName = name; m_fileName = name;
m_path = wxFileName(m_dir, m_fileName).GetFullPath(); m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog(); UpdateDialog();
} #else
wxGenericFileDialog::SetFilename( name );
void wxFileDialog::UpdateDialog() #endif
{
// set currently selected directory to match the path:
if (!m_dir.empty() && wxDirExists(m_dir))
{
// NB: This is important -- if we set directory only and not the path,
// then dialog will still remember old path set using previous
// call to gtk_chooser_set_filename. If the previous directory
// was a subdirectory of the directory we want to select now,
// the dialog would still contain directory selector controls
// for the subdirectory (with the parent directory selected),
// instead of showing only the parent directory as expected.
// This way, we force GtkFileChooser to really change the
// directory. Finally, it doesn't have to be done if filename
// is not empty because of the code that sets the filename below.
if (m_fileName.empty())
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
}
// if the user set only the directory (e.g. by calling SetDirectory)
// and not the default filename, then we don't want to set the filename:
if (!m_fileName.empty())
{
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_path));
// pre-fill the filename when saving, too (there's no text entry
// control when opening a file, so it doesn't make sense to
// do this when opening files):
if (GetWindowStyle() & wxSAVE)
{
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_fileName));
}
}
} }
void wxFileDialog::SetWildcard(const wxString& wildCard) void wxFileDialog::SetWildcard(const wxString& wildCard)
{ {
#ifdef __WXGTK24__
m_wildCard = wildCard; m_wildCard = wildCard;
GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget); GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget);
@ -350,10 +374,14 @@ void wxFileDialog::SetWildcard(const wxString& wildCard)
gtk_file_chooser_add_filter(chooser, filter); gtk_file_chooser_add_filter(chooser, filter);
} }
} }
#else
wxGenericFileDialog::SetWildcard( wildCard );
#endif
} }
void wxFileDialog::SetFilterIndex(int filterIndex) void wxFileDialog::SetFilterIndex(int filterIndex)
{ {
#ifdef __WXGTK24__
m_filterIndex = filterIndex; m_filterIndex = filterIndex;
GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget); GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget);
@ -372,10 +400,57 @@ void wxFileDialog::SetFilterIndex(int filterIndex)
fnode = fnode->next; fnode = fnode->next;
} }
g_slist_free(filters); g_slist_free(filters);
#else
wxGenericFileDialog::SetFilterIndex( filterIndex );
#endif
}
void wxFileDialog::UpdateDialog()
{
#ifdef __WXGTK24__
// set currently selected directory to match the path:
if (!m_dir.empty() && wxDirExists(m_dir))
{
// NB: This is important -- if we set directory only and not the path,
// then dialog will still remember old path set using previous
// call to gtk_chooser_set_filename. If the previous directory
// was a subdirectory of the directory we want to select now,
// the dialog would still contain directory selector controls
// for the subdirectory (with the parent directory selected),
// instead of showing only the parent directory as expected.
// This way, we force GtkFileChooser to really change the
// directory. Finally, it doesn't have to be done if filename
// is not empty because of the code that sets the filename below.
if (m_fileName.empty())
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_dir));
}
// if the user set only the directory (e.g. by calling SetDirectory)
// and not the default filename, then we don't want to set the filename:
if (!m_fileName.empty())
{
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_path));
// pre-fill the filename when saving, too (there's no text entry
// control when opening a file, so it doesn't make sense to
// do this when opening files):
if (GetWindowStyle() & wxSAVE)
{
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(m_fileName));
}
}
#endif
} }
void wxFileDialog::UpdateFromDialog() void wxFileDialog::UpdateFromDialog()
{ {
#ifdef __WXGTK24__
// update filterIndex // update filterIndex
GSList *fnode = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(m_widget)); GSList *fnode = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(m_widget));
GSList *filters = fnode; GSList *filters = fnode;
@ -395,6 +470,7 @@ void wxFileDialog::UpdateFromDialog()
fnode = fnode->next; fnode = fnode->next;
} }
g_slist_free(filters); g_slist_free(filters);
#endif
} }
#endif // wxUSE_FILEDLG && defined(__WXGTK24__) #endif // wxUSE_FILEDLG