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
);
30 style
=dialog
->GetStyle();
32 if((style
&wxSAVE
)&&(style
&wxOVERWRITE_PROMPT
))
33 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog
->m_widget
) ))) {
34 if(wxMessageBox(_("File exists. Overwrite?"),
35 _("Confirm"), wxYES_NO
) != wxYES
)
39 dialog
->OnOk( event
);
42 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
44 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
45 wxCommandEvent
event(wxEVT_NULL
);
46 dialog
->OnCancel( event
);
49 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
51 wxFileDialog::wxFileDialog(wxWindow
*parent
, const wxString
& message
,
52 const wxString
& defaultDir
, const wxString
& defaultFileName
,
53 const wxString
& wildCard
,
54 long style
, const wxPoint
& pos
)
58 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, "filedialog" );
61 m_fileName
= defaultFileName
;
63 m_wildCard
= wildCard
;
64 m_dialogStyle
= style
;
67 m_widget
= gtk_file_selection_new(_("File selection"));
69 int x
= (gdk_screen_width () - 400) / 2;
70 int y
= (gdk_screen_height () - 400) / 2;
71 gtk_widget_set_uposition( m_widget
, x
, y
);
73 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
76 if(! m_path
.IsEmpty() && m_path
.Last()!='/') m_path
.Append('/');
77 m_path
.Append(m_fileName
);
79 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
);
81 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
82 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
84 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
85 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
88 int wxFileDialog::ShowModal(void)
90 int ret
= wxDialog::ShowModal();
94 m_fileName
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
95 m_path
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
101 char *wxFileSelector(const char *title
,
102 const char *defaultDir
, const char *defaultFileName
,
103 const char *defaultExtension
, const char *filter
, int flags
,
104 wxWindow
*parent
, int x
, int y
)
106 wxString
filter2("");
107 if ( defaultExtension
&& !filter
)
108 filter2
= wxString("*.") + wxString(defaultExtension
) ;
112 wxString defaultDirString
;
114 defaultDirString
= defaultDir
;
116 defaultDirString
= "";
118 wxString defaultFilenameString
;
120 defaultFilenameString
= defaultFileName
;
122 defaultFilenameString
= "";
124 wxFileDialog
fileDialog(parent
, title
, defaultDirString
, defaultFilenameString
,
125 filter2
, flags
, wxPoint(x
, y
));
127 if ( fileDialog
.ShowModal() == wxID_OK
)
129 strcpy(wxBuffer
, (const char *)fileDialog
.GetPath());
136 char* wxLoadFileSelector(const char *what
, const char *extension
, const char *default_name
,
139 char *ext
= (char *)extension
;
142 wxString str
= _("Load %s file");
143 sprintf(prompt
, str
, what
);
145 if (*ext
== '.') ext
++;
147 sprintf(wild
, "*.%s", ext
);
149 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);
152 char* wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
155 char *ext
= (char *)extension
;
158 wxString str
= _("Save %s file");
159 sprintf(prompt
, str
, what
);
161 if (*ext
== '.') ext
++;
163 sprintf(wild
, "*.%s", ext
);
165 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);