]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/filedlg.cpp
wxStream: wxInputStream and wxOutputStream don't inherit from wxObject anymore.
[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
19 //-----------------------------------------------------------------------------
20 // wxFileDialog
21 //-----------------------------------------------------------------------------
22
23 void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), gpointer data )
24 {
25 wxFileDialog *dialog = (wxFileDialog*)data;
26 wxCommandEvent event(wxEVT_NULL);
27 dialog->OnOk( event );
28 };
29
30 void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(widget), gpointer data )
31 {
32 wxFileDialog *dialog = (wxFileDialog*)data;
33 wxCommandEvent event(wxEVT_NULL);
34 dialog->OnCancel( event );
35 };
36
37 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
38
39 wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
40 const wxString& defaultDir, const wxString& defaultFileName,
41 const wxString& wildCard,
42 long style, const wxPoint& pos )
43 {
44 m_needParent = FALSE;
45
46 PreCreation( parent, -1, pos, wxDefaultSize, style, "filedialog" );
47 m_message = message;
48 m_path = "";
49 m_fileName = defaultFileName;
50 m_dir = defaultDir;
51 m_wildCard = wildCard;
52 m_filterIndex = 1;
53
54 m_widget = gtk_file_selection_new( "File selection" );
55
56 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
57
58 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
59 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
60
61 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
62 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
63 };
64
65 int wxFileDialog::ShowModal(void)
66 {
67 int ret = wxDialog::ShowModal();
68 if (ret == wxID_OK)
69 {
70 m_fileName = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
71 m_path = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
72 };
73 return ret;
74 };
75
76
77 char *wxFileSelector(const char *title,
78 const char *defaultDir, const char *defaultFileName,
79 const char *defaultExtension, const char *filter, int flags,
80 wxWindow *parent, int x, int y)
81 {
82 wxString filter2("");
83 if ( defaultExtension && !filter )
84 filter2 = wxString("*.") + wxString(defaultExtension) ;
85 else if ( filter )
86 filter2 = filter;
87
88 wxString defaultDirString;
89 if (defaultDir)
90 defaultDirString = defaultDir;
91 else
92 defaultDirString = "";
93
94 wxString defaultFilenameString;
95 if (defaultFileName)
96 defaultFilenameString = defaultFileName;
97 else
98 defaultFilenameString = "";
99
100 wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString,
101 filter2, flags, wxPoint(x, y));
102
103 if ( fileDialog.ShowModal() == wxID_OK )
104 {
105 strcpy(wxBuffer, (const char *)fileDialog.GetPath());
106 return wxBuffer;
107 }
108 else
109 return NULL;
110 };
111
112 char* wxLoadFileSelector(const char *what, const char *extension, const char *default_name,
113 wxWindow *parent )
114 {
115 char *ext = (char *)extension;
116
117 char prompt[50];
118 wxString str = _("Load %s file");
119 sprintf(prompt, str, what);
120
121 if (*ext == '.') ext++;
122 char wild[60];
123 sprintf(wild, "*.%s", ext);
124
125 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
126 };
127
128 char* wxSaveFileSelector(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 = _("Save %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
145
146