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?","Confirm",wxYES_NO
)!=wxYES
)
38 dialog
->OnOk( event
);
41 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
43 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
44 wxCommandEvent
event(wxEVT_NULL
);
45 dialog
->OnCancel( event
);
48 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
50 wxFileDialog::wxFileDialog(wxWindow
*parent
, const wxString
& message
,
51 const wxString
& defaultDir
, const wxString
& defaultFileName
,
52 const wxString
& wildCard
,
53 long style
, const wxPoint
& pos
)
57 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, "filedialog" );
60 m_fileName
= defaultFileName
;
62 m_wildCard
= wildCard
;
63 m_dialogStyle
= style
;
66 m_widget
= gtk_file_selection_new( "File selection" );
68 int x
= (gdk_screen_width () - 400) / 2;
69 int y
= (gdk_screen_height () - 400) / 2;
70 gtk_widget_set_uposition( m_widget
, x
, y
);
72 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
75 if(! m_path
.IsEmpty() && m_path
.Last()!='/') m_path
.Append('/');
76 m_path
.Append(m_fileName
);
78 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
);
80 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
81 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
83 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
84 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
87 int wxFileDialog::ShowModal(void)
89 int ret
= wxDialog::ShowModal();
93 m_fileName
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
94 m_path
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
100 char *wxFileSelector(const char *title
,
101 const char *defaultDir
, const char *defaultFileName
,
102 const char *defaultExtension
, const char *filter
, int flags
,
103 wxWindow
*parent
, int x
, int y
)
105 wxString
filter2("");
106 if ( defaultExtension
&& !filter
)
107 filter2
= wxString("*.") + wxString(defaultExtension
) ;
111 wxString defaultDirString
;
113 defaultDirString
= defaultDir
;
115 defaultDirString
= "";
117 wxString defaultFilenameString
;
119 defaultFilenameString
= defaultFileName
;
121 defaultFilenameString
= "";
123 wxFileDialog
fileDialog(parent
, title
, defaultDirString
, defaultFilenameString
,
124 filter2
, flags
, wxPoint(x
, y
));
126 if ( fileDialog
.ShowModal() == wxID_OK
)
128 strcpy(wxBuffer
, (const char *)fileDialog
.GetPath());
135 char* wxLoadFileSelector(const char *what
, const char *extension
, const char *default_name
,
138 char *ext
= (char *)extension
;
141 wxString str
= _("Load %s file");
142 sprintf(prompt
, str
, what
);
144 if (*ext
== '.') ext
++;
146 sprintf(wild
, "*.%s", ext
);
148 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);
151 char* wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
154 char *ext
= (char *)extension
;
157 wxString str
= _("Save %s file");
158 sprintf(prompt
, str
, what
);
160 if (*ext
== '.') ext
++;
162 sprintf(wild
, "*.%s", ext
);
164 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);