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