]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/filedlg.cpp
distrin corrections files
[wxWidgets.git] / src / gtk1 / filedlg.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: filedlg.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
a3622daa 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "filedlg.h"
12#endif
13
14#include "wx/filedlg.h"
15#include "wx/utils.h"
16#include "wx/intl.h"
035b704a 17#include "wx/generic/msgdlgg.h"
c801d85f 18
83624f79
RR
19#include "gtk/gtk.h"
20
c801d85f 21//-----------------------------------------------------------------------------
291a8f20
RR
22// "delete_event"
23//-----------------------------------------------------------------------------
24
0e1399b3 25static
291a8f20 26bool gtk_filedialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
0e1399b3 27{
291a8f20
RR
28/*
29 printf( "OnDelete from " );
30 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
31 printf( win->GetClassInfo()->GetClassName() );
32 printf( ".\n" );
33*/
0e1399b3 34
291a8f20
RR
35 win->Close();
36
37 return TRUE;
38}
39
40//-----------------------------------------------------------------------------
41// "clicked" for OK-button
c801d85f
KB
42//-----------------------------------------------------------------------------
43
0e1399b3 44static
2748d251 45void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dialog )
c801d85f 46{
2748d251 47 int style = dialog->GetStyle();
035b704a 48
2748d251 49 if ((style&wxSAVE)&&(style&wxOVERWRITE_PROMPT))
83624f79 50 {
0e1399b3 51 char *filename = gtk_file_selection_get_filename(
2748d251 52 GTK_FILE_SELECTION(dialog->m_widget) );
0e1399b3 53
2748d251 54 if (wxFileExists( filename ))
0e1399b3
VZ
55 {
56 wxString msg;
2748d251 57 msg.Printf( _("File '%s' already exists, do you really want to "
0e1399b3
VZ
58 "overwrite it?"), filename);
59
2748d251 60 if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
0e1399b3
VZ
61 return;
62 }
83624f79 63 }
035b704a 64
2748d251 65 dialog->SetPath( gtk_file_selection_get_filename( GTK_FILE_SELECTION(dialog->m_widget) ) );
b7f4714a 66
2748d251
RR
67 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_OK);
68 event.SetEventObject( dialog );
69 dialog->GetEventHandler()->ProcessEvent( event );
ff7b1510 70}
c801d85f 71
291a8f20
RR
72//-----------------------------------------------------------------------------
73// "clicked" for Cancel-button
74//-----------------------------------------------------------------------------
75
0e1399b3 76static
b7f4714a 77void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFileDialog *dialog )
c801d85f 78{
2748d251
RR
79 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
80 event.SetEventObject( dialog );
81 dialog->GetEventHandler()->ProcessEvent( event );
ff7b1510 82}
c801d85f 83
291a8f20
RR
84//-----------------------------------------------------------------------------
85// wxFileDialog
86//-----------------------------------------------------------------------------
87
c801d85f
KB
88IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
89
83624f79
RR
90wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
91 const wxString& defaultDir, const wxString& defaultFileName,
92 const wxString& wildCard,
93 long style, const wxPoint& pos )
c801d85f 94{
83624f79
RR
95 m_needParent = FALSE;
96
97 PreCreation( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, "filedialog" );
98 m_message = message;
99 m_path = "";
100 m_fileName = defaultFileName;
101 m_dir = defaultDir;
102 m_wildCard = wildCard;
103 m_dialogStyle = style;
104 m_filterIndex = 1;
105
106 m_widget = gtk_file_selection_new( m_message );
0e1399b3 107
83624f79
RR
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 );
0e1399b3 111
83624f79 112 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
3502e687 113 gtk_file_selection_hide_fileop_buttons( sel ); // they don't work anyway
035b704a 114
83624f79
RR
115 m_path.Append(m_dir);
116 if(! m_path.IsEmpty() && m_path.Last()!='/') m_path.Append('/');
117 m_path.Append(m_fileName);
035b704a 118
83624f79 119 if(m_path.Length()>1) gtk_file_selection_set_filename(sel,m_path);
a3622daa 120
83624f79
RR
121 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
122 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
c801d85f 123
3502e687
RR
124 // strange way to internationalize
125 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->ok_button)->child ), _("OK") );
126
83624f79
RR
127 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
128 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
3502e687
RR
129
130 // strange way to internationalize
131 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), _("Cancel") );
132
0e1399b3 133 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
291a8f20 134 GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
ff7b1510 135}
c801d85f 136
7482b220 137wxString wxFileSelector( const char *title,
83624f79
RR
138 const char *defaultDir, const char *defaultFileName,
139 const char *defaultExtension, const char *filter, int flags,
140 wxWindow *parent, int x, int y )
c801d85f 141{
83624f79
RR
142 wxString filter2("");
143 if ( defaultExtension && !filter )
144 filter2 = wxString("*.") + wxString(defaultExtension) ;
145 else if ( filter )
146 filter2 = filter;
147
148 wxString defaultDirString;
149 if (defaultDir)
150 defaultDirString = defaultDir;
151 else
152 defaultDirString = "";
153
154 wxString defaultFilenameString;
155 if (defaultFileName)
156 defaultFilenameString = defaultFileName;
157 else
158 defaultFilenameString = "";
0e1399b3 159
83624f79
RR
160 wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) );
161
162 if ( fileDialog.ShowModal() == wxID_OK )
163 {
7482b220 164 return fileDialog.GetPath();
83624f79
RR
165 }
166 else
167 {
7482b220 168 return wxEmptyString;
83624f79 169 }
ff7b1510 170}
c801d85f 171
7482b220 172wxString wxLoadFileSelector( const char *what, const char *extension, const char *default_name, wxWindow *parent )
c801d85f 173{
83624f79 174 char *ext = (char *)extension;
a3622daa 175
83624f79
RR
176 char prompt[50];
177 wxString str = _("Load %s file");
178 sprintf(prompt, str, what);
c801d85f 179
83624f79
RR
180 if (*ext == '.') ext++;
181 char wild[60];
182 sprintf(wild, "*.%s", ext);
c801d85f 183
83624f79 184 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
ff7b1510 185}
c801d85f 186
7482b220 187wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name,
c801d85f
KB
188 wxWindow *parent )
189{
83624f79 190 char *ext = (char *)extension;
a3622daa 191
83624f79
RR
192 char prompt[50];
193 wxString str = _("Save %s file");
194 sprintf(prompt, str, what);
c801d85f 195
83624f79
RR
196 if (*ext == '.') ext++;
197 char wild[60];
198 sprintf(wild, "*.%s", ext);
c801d85f 199
83624f79 200 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
ff7b1510 201}
c801d85f 202