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 //-----------------------------------------------------------------------------
26 bool gtk_filedialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
29 printf( "OnDelete from " );
30 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
31 printf( win->GetClassInfo()->GetClassName() );
40 //-----------------------------------------------------------------------------
41 // "clicked" for OK-button
42 //-----------------------------------------------------------------------------
45 void gtk_filedialog_ok_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
47 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
48 wxCommandEvent
event(wxEVT_NULL
);
51 style
= dialog
->GetStyle();
53 if( (style
& wxSAVE
) && ( style
&wxOVERWRITE_PROMPT
) )
55 char *filename
= gtk_file_selection_get_filename(
56 GTK_FILE_SELECTION(dialog
->m_widget
)
59 if(wxFileExists( filename
))
62 msg
.Printf(_("File '%s' already exists, do you really want to "
63 "overwrite it?"), filename
);
65 if( wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
70 dialog
->OnOK( event
);
73 //-----------------------------------------------------------------------------
74 // "clicked" for Cancel-button
75 //-----------------------------------------------------------------------------
78 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
80 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
81 wxCommandEvent
event(wxEVT_NULL
);
82 dialog
->OnCancel( event
);
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
89 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
91 wxFileDialog::wxFileDialog( wxWindow
*parent
, const wxString
& message
,
92 const wxString
& defaultDir
, const wxString
& defaultFileName
,
93 const wxString
& wildCard
,
94 long style
, const wxPoint
& pos
)
98 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, "filedialog" );
101 m_fileName
= defaultFileName
;
103 m_wildCard
= wildCard
;
104 m_dialogStyle
= style
;
107 m_widget
= gtk_file_selection_new( m_message
);
109 int x
= (gdk_screen_width () - 400) / 2;
110 int y
= (gdk_screen_height () - 400) / 2;
111 gtk_widget_set_uposition( m_widget
, x
, y
);
113 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
115 m_path
.Append(m_dir
);
116 if(! m_path
.IsEmpty() && m_path
.Last()!='/') m_path
.Append('/');
117 m_path
.Append(m_fileName
);
119 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
);
121 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
122 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
124 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
125 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
127 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
128 GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback
), (gpointer
)this );
132 int wxFileDialog::ShowModal(void)
134 int ret
= wxDialog::ShowModal();
138 m_fileName
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
139 m_path
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
145 wxString
wxFileSelector( const char *title
,
146 const char *defaultDir
, const char *defaultFileName
,
147 const char *defaultExtension
, const char *filter
, int flags
,
148 wxWindow
*parent
, int x
, int y
)
150 wxString
filter2("");
151 if ( defaultExtension
&& !filter
)
152 filter2
= wxString("*.") + wxString(defaultExtension
) ;
156 wxString defaultDirString
;
158 defaultDirString
= defaultDir
;
160 defaultDirString
= "";
162 wxString defaultFilenameString
;
164 defaultFilenameString
= defaultFileName
;
166 defaultFilenameString
= "";
168 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
170 if ( fileDialog
.ShowModal() == wxID_OK
)
172 return fileDialog
.GetPath();
176 return wxEmptyString
;
180 wxString
wxLoadFileSelector( const char *what
, const char *extension
, const char *default_name
, wxWindow
*parent
)
182 char *ext
= (char *)extension
;
185 wxString str
= _("Load %s file");
186 sprintf(prompt
, str
, what
);
188 if (*ext
== '.') ext
++;
190 sprintf(wild
, "*.%s", ext
);
192 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);
195 wxString
wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
198 char *ext
= (char *)extension
;
201 wxString str
= _("Save %s file");
202 sprintf(prompt
, str
, what
);
204 if (*ext
== '.') ext
++;
206 sprintf(wild
, "*.%s", ext
);
208 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);