]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/filedlg.cpp
Added ODBC database classes and sample from RemStar (sample needs work for wxWin 2)
[wxWidgets.git] / src / gtk1 / 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
29 if(dialog->GetStyle()&(wxSAVE|wxOVERWRITE_PROMPT))
30 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog->m_widget) ))) {
31 if(wxMessageBox("File exists. Overwrite?","Confirm",wxYES_NO)!=wxYES)
32 return;
33 }
34
35 dialog->OnOk( event );
36 };
37
38 void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(widget), gpointer data )
39 {
40 wxFileDialog *dialog = (wxFileDialog*)data;
41 wxCommandEvent event(wxEVT_NULL);
42 dialog->OnCancel( event );
43 };
44
45 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
46
47 wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
48 const wxString& defaultDir, const wxString& defaultFileName,
49 const wxString& wildCard,
50 long style, const wxPoint& pos )
51 {
52 m_needParent = FALSE;
53
54 PreCreation( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, "filedialog" );
55 m_message = message;
56 m_path = "";
57 m_fileName = defaultFileName;
58 m_dir = defaultDir;
59 m_wildCard = wildCard;
60 m_dialogStyle = style;
61 m_filterIndex = 1;
62
63 m_widget = gtk_file_selection_new( "File selection" );
64
65 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
66
67 m_path.Append(m_dir);
68 if(! m_path.IsEmpty() && m_path.Last()!='/') m_path.Append('/');
69 m_path.Append(m_fileName);
70
71 if(m_path.Length()>1) gtk_file_selection_set_filename(sel,m_path);
72
73 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
74 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
75
76 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
77 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
78 };
79
80 int wxFileDialog::ShowModal(void)
81 {
82 int ret = wxDialog::ShowModal();
83
84 if (ret == wxID_OK)
85 {
86 m_fileName = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
87 m_path = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
88 };
89 return ret;
90 };
91
92
93 char *wxFileSelector(const char *title,
94 const char *defaultDir, const char *defaultFileName,
95 const char *defaultExtension, const char *filter, int flags,
96 wxWindow *parent, int x, int y)
97 {
98 wxString filter2("");
99 if ( defaultExtension && !filter )
100 filter2 = wxString("*.") + wxString(defaultExtension) ;
101 else if ( filter )
102 filter2 = filter;
103
104 wxString defaultDirString;
105 if (defaultDir)
106 defaultDirString = defaultDir;
107 else
108 defaultDirString = "";
109
110 wxString defaultFilenameString;
111 if (defaultFileName)
112 defaultFilenameString = defaultFileName;
113 else
114 defaultFilenameString = "";
115
116 wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString,
117 filter2, flags, wxPoint(x, y));
118
119 if ( fileDialog.ShowModal() == wxID_OK )
120 {
121 strcpy(wxBuffer, (const char *)fileDialog.GetPath());
122 return wxBuffer;
123 }
124 else
125 return NULL;
126 };
127
128 char* wxLoadFileSelector(const char *what, const char *extension, const char *default_name,
129 wxWindow *parent )
130 {
131 char *ext = (char *)extension;
132
133 char prompt[50];
134 wxString str = _("Load %s file");
135 sprintf(prompt, str, what);
136
137 if (*ext == '.') ext++;
138 char wild[60];
139 sprintf(wild, "*.%s", ext);
140
141 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
142 };
143
144 char* wxSaveFileSelector(const char *what, const char *extension, const char *default_name,
145 wxWindow *parent )
146 {
147 char *ext = (char *)extension;
148
149 char prompt[50];
150 wxString str = _("Save %s file");
151 sprintf(prompt, str, what);
152
153 if (*ext == '.') ext++;
154 char wild[60];
155 sprintf(wild, "*.%s", ext);
156
157 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
158 };
159
160
161
162