1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "filedlg.h"
14 #include "wx/filedlg.h"
17 #include "wx/generic/msgdlgg.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 void gtk_filedialog_ok_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
27 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
28 wxCommandEvent
event(wxEVT_NULL
);
31 style
= dialog
->GetStyle();
33 if((style
&wxSAVE
)&&(style
&wxOVERWRITE_PROMPT
))
35 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog
->m_widget
) )))
37 if(wxMessageBox(_("File exists. Overwrite?"),
38 _("Confirm"), wxYES_NO
) != wxYES
)
43 dialog
->OnOK( event
);
46 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
48 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
49 wxCommandEvent
event(wxEVT_NULL
);
50 dialog
->OnCancel( event
);
53 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
55 wxFileDialog::wxFileDialog( wxWindow
*parent
, const wxString
& message
,
56 const wxString
& defaultDir
, const wxString
& defaultFileName
,
57 const wxString
& wildCard
,
58 long style
, const wxPoint
& pos
)
62 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, "filedialog" );
65 m_fileName
= defaultFileName
;
67 m_wildCard
= wildCard
;
68 m_dialogStyle
= style
;
71 m_widget
= gtk_file_selection_new( m_message
);
73 int x
= (gdk_screen_width () - 400) / 2;
74 int y
= (gdk_screen_height () - 400) / 2;
75 gtk_widget_set_uposition( m_widget
, x
, y
);
77 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
80 if(! m_path
.IsEmpty() && m_path
.Last()!='/') m_path
.Append('/');
81 m_path
.Append(m_fileName
);
83 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
);
85 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
86 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
88 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
89 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
92 int wxFileDialog::ShowModal(void)
94 int ret
= wxDialog::ShowModal();
98 m_fileName
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
99 m_path
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
105 char *wxFileSelector( const char *title
,
106 const char *defaultDir
, const char *defaultFileName
,
107 const char *defaultExtension
, const char *filter
, int flags
,
108 wxWindow
*parent
, int x
, int y
)
110 wxString
filter2("");
111 if ( defaultExtension
&& !filter
)
112 filter2
= wxString("*.") + wxString(defaultExtension
) ;
116 wxString defaultDirString
;
118 defaultDirString
= defaultDir
;
120 defaultDirString
= "";
122 wxString defaultFilenameString
;
124 defaultFilenameString
= defaultFileName
;
126 defaultFilenameString
= "";
128 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
130 if ( fileDialog
.ShowModal() == wxID_OK
)
132 strcpy(wxBuffer
, (const char *)fileDialog
.GetPath());
137 return (char *) NULL
;
141 char* wxLoadFileSelector( const char *what
, const char *extension
, const char *default_name
, wxWindow
*parent
)
143 char *ext
= (char *)extension
;
146 wxString str
= _("Load %s file");
147 sprintf(prompt
, str
, what
);
149 if (*ext
== '.') ext
++;
151 sprintf(wild
, "*.%s", ext
);
153 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);
156 char* wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
159 char *ext
= (char *)extension
;
162 wxString str
= _("Save %s file");
163 sprintf(prompt
, str
, what
);
165 if (*ext
== '.') ext
++;
167 sprintf(wild
, "*.%s", ext
);
169 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);