]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/filedlg.cpp
Another solaris fix. :-<
[wxWidgets.git] / src / gtk1 / filedlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filedlg.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
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"
17 #include "wx/generic/msgdlgg.h"
18
19 #include "gtk/gtk.h"
20
21 //-----------------------------------------------------------------------------
22 // wxFileDialog
23 //-----------------------------------------------------------------------------
24
25 void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), gpointer data )
26 {
27 wxFileDialog *dialog = (wxFileDialog*)data;
28 wxCommandEvent event(wxEVT_NULL);
29 int style;
30
31 style = dialog->GetStyle();
32
33 if((style&wxSAVE)&&(style&wxOVERWRITE_PROMPT))
34 {
35 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog->m_widget) )))
36 {
37 if(wxMessageBox(_("File exists. Overwrite?"),
38 _("Confirm"), wxYES_NO) != wxYES)
39 return;
40 }
41 }
42
43 dialog->OnOK( event );
44 }
45
46 void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(widget), gpointer data )
47 {
48 wxFileDialog *dialog = (wxFileDialog*)data;
49 wxCommandEvent event(wxEVT_NULL);
50 dialog->OnCancel( event );
51 }
52
53 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
54
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 )
59 {
60 m_needParent = FALSE;
61
62 PreCreation( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, "filedialog" );
63 m_message = message;
64 m_path = "";
65 m_fileName = defaultFileName;
66 m_dir = defaultDir;
67 m_wildCard = wildCard;
68 m_dialogStyle = style;
69 m_filterIndex = 1;
70
71 m_widget = gtk_file_selection_new( m_message );
72
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 );
76
77 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
78
79 m_path.Append(m_dir);
80 if(! m_path.IsEmpty() && m_path.Last()!='/') m_path.Append('/');
81 m_path.Append(m_fileName);
82
83 if(m_path.Length()>1) gtk_file_selection_set_filename(sel,m_path);
84
85 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
86 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
87
88 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
89 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
90 }
91
92 int wxFileDialog::ShowModal(void)
93 {
94 int ret = wxDialog::ShowModal();
95
96 if (ret == wxID_OK)
97 {
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) );
100 }
101 return ret;
102 }
103
104
105 wxString 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 )
109 {
110 wxString filter2("");
111 if ( defaultExtension && !filter )
112 filter2 = wxString("*.") + wxString(defaultExtension) ;
113 else if ( filter )
114 filter2 = filter;
115
116 wxString defaultDirString;
117 if (defaultDir)
118 defaultDirString = defaultDir;
119 else
120 defaultDirString = "";
121
122 wxString defaultFilenameString;
123 if (defaultFileName)
124 defaultFilenameString = defaultFileName;
125 else
126 defaultFilenameString = "";
127
128 wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) );
129
130 if ( fileDialog.ShowModal() == wxID_OK )
131 {
132 return fileDialog.GetPath();
133 }
134 else
135 {
136 return wxEmptyString;
137 }
138 }
139
140 wxString wxLoadFileSelector( const char *what, const char *extension, const char *default_name, wxWindow *parent )
141 {
142 char *ext = (char *)extension;
143
144 char prompt[50];
145 wxString str = _("Load %s file");
146 sprintf(prompt, str, what);
147
148 if (*ext == '.') ext++;
149 char wild[60];
150 sprintf(wild, "*.%s", ext);
151
152 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
153 }
154
155 wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name,
156 wxWindow *parent )
157 {
158 char *ext = (char *)extension;
159
160 char prompt[50];
161 wxString str = _("Save %s file");
162 sprintf(prompt, str, what);
163
164 if (*ext == '.') ext++;
165 char wild[60];
166 sprintf(wild, "*.%s", ext);
167
168 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
169 }
170