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
), wxFileDialog
*dialog
)
47 int style
= dialog
->GetStyle();
49 if ((style
&wxSAVE
)&&(style
&wxOVERWRITE_PROMPT
))
51 char *filename
= gtk_file_selection_get_filename(
52 GTK_FILE_SELECTION(dialog
->m_widget
) );
54 if (wxFileExists( filename
))
57 msg
.Printf( _("File '%s' already exists, do you really want to "
58 "overwrite it?"), filename
);
60 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
65 dialog
->SetPath( gtk_file_selection_get_filename( GTK_FILE_SELECTION(dialog
->m_widget
) ) );
67 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_OK
);
68 event
.SetEventObject( dialog
);
69 dialog
->GetEventHandler()->ProcessEvent( event
);
72 //-----------------------------------------------------------------------------
73 // "clicked" for Cancel-button
74 //-----------------------------------------------------------------------------
77 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFileDialog
*dialog
)
79 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
80 event
.SetEventObject( dialog
);
81 dialog
->GetEventHandler()->ProcessEvent( event
);
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
90 wxFileDialog::wxFileDialog( wxWindow
*parent
, const wxString
& message
,
91 const wxString
& defaultDir
, const wxString
& defaultFileName
,
92 const wxString
& wildCard
,
93 long style
, const wxPoint
& pos
)
97 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, "filedialog" );
100 m_fileName
= defaultFileName
;
102 m_wildCard
= wildCard
;
103 m_dialogStyle
= style
;
106 m_widget
= gtk_file_selection_new( m_message
);
108 int x
= (gdk_screen_width () - 400) / 2;
109 int y
= (gdk_screen_height () - 400) / 2;
110 gtk_widget_set_uposition( m_widget
, x
, y
);
112 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
113 gtk_file_selection_hide_fileop_buttons( sel
); // they don't work anyway
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 // strange way to internationalize
125 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->ok_button
)->child
), _("OK") );
127 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
128 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
130 // strange way to internationalize
131 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->cancel_button
)->child
), _("Cancel") );
133 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
134 GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback
), (gpointer
)this );
137 wxString
wxFileSelector( const char *title
,
138 const char *defaultDir
, const char *defaultFileName
,
139 const char *defaultExtension
, const char *filter
, int flags
,
140 wxWindow
*parent
, int x
, int y
)
142 wxString
filter2("");
143 if ( defaultExtension
&& !filter
)
144 filter2
= wxString("*.") + wxString(defaultExtension
) ;
148 wxString defaultDirString
;
150 defaultDirString
= defaultDir
;
152 defaultDirString
= "";
154 wxString defaultFilenameString
;
156 defaultFilenameString
= defaultFileName
;
158 defaultFilenameString
= "";
160 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
162 if ( fileDialog
.ShowModal() == wxID_OK
)
164 return fileDialog
.GetPath();
168 return wxEmptyString
;
172 wxString
wxLoadFileSelector( const char *what
, const char *extension
, const char *default_name
, wxWindow
*parent
)
174 char *ext
= (char *)extension
;
177 wxString str
= _("Load %s file");
178 sprintf(prompt
, str
, what
);
180 if (*ext
== '.') ext
++;
182 sprintf(wild
, "*.%s", ext
);
184 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);
187 wxString
wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
190 char *ext
= (char *)extension
;
193 wxString str
= _("Save %s file");
194 sprintf(prompt
, str
, what
);
196 if (*ext
== '.') ext
++;
198 sprintf(wild
, "*.%s", ext
);
200 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);