1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "filedlg.h"
15 #include "wx/filedlg.h"
18 #include "wx/generic/msgdlgg.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 void gtk_filedialog_ok_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
26 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
27 wxCommandEvent
event(wxEVT_NULL
);
29 if(dialog
->GetStyle()&(wxSAVE
|wxOVERWRITE_PROMPT
))
30 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog
->m_widget
) ))) {
31 if(wxMessageBox("File exists. Overwrite?","Confirm",wxYES_NO
)!=wxYES
)
35 dialog
->OnOk( event
);
38 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
40 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
41 wxCommandEvent
event(wxEVT_NULL
);
42 dialog
->OnCancel( event
);
45 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
47 wxFileDialog::wxFileDialog(wxWindow
*parent
, const wxString
& message
,
48 const wxString
& defaultDir
, const wxString
& defaultFileName
,
49 const wxString
& wildCard
,
50 long style
, const wxPoint
& pos
)
54 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, "filedialog" );
57 m_fileName
= defaultFileName
;
59 m_wildCard
= wildCard
;
60 m_dialogStyle
= style
;
63 m_widget
= gtk_file_selection_new( "File selection" );
65 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
68 if(! m_path
.IsEmpty() && m_path
.Last()!='/') m_path
.Append('/');
69 m_path
.Append(m_fileName
);
71 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
);
73 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
74 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
76 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
77 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
80 int wxFileDialog::ShowModal(void)
82 int ret
= wxDialog::ShowModal();
86 m_fileName
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
87 m_path
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
93 char *wxFileSelector(const char *title
,
94 const char *defaultDir
, const char *defaultFileName
,
95 const char *defaultExtension
, const char *filter
, int flags
,
96 wxWindow
*parent
, int x
, int y
)
99 if ( defaultExtension
&& !filter
)
100 filter2
= wxString("*.") + wxString(defaultExtension
) ;
104 wxString defaultDirString
;
106 defaultDirString
= defaultDir
;
108 defaultDirString
= "";
110 wxString defaultFilenameString
;
112 defaultFilenameString
= defaultFileName
;
114 defaultFilenameString
= "";
116 wxFileDialog
fileDialog(parent
, title
, defaultDirString
, defaultFilenameString
,
117 filter2
, flags
, wxPoint(x
, y
));
119 if ( fileDialog
.ShowModal() == wxID_OK
)
121 strcpy(wxBuffer
, (const char *)fileDialog
.GetPath());
128 char* wxLoadFileSelector(const char *what
, const char *extension
, const char *default_name
,
131 char *ext
= (char *)extension
;
134 wxString str
= _("Load %s file");
135 sprintf(prompt
, str
, what
);
137 if (*ext
== '.') ext
++;
139 sprintf(wild
, "*.%s", ext
);
141 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);
144 char* wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
147 char *ext
= (char *)extension
;
150 wxString str
= _("Save %s file");
151 sprintf(prompt
, str
, what
);
153 if (*ext
== '.') ext
++;
155 sprintf(wild
, "*.%s", ext
);
157 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);