]>
Commit | Line | Data |
---|---|---|
4bb6408c | 1 | ///////////////////////////////////////////////////////////////////////////// |
7520f3da | 2 | // Name: src/motif/filedlg.cpp |
4bb6408c JS |
3 | // Purpose: wxFileDialog |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
65571936 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
1248b41f MB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
4bb6408c | 15 | #include "wx/filedlg.h" |
88a7a4e1 WS |
16 | |
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/intl.h" | |
670f9935 | 19 | #include "wx/app.h" |
de6185e2 | 20 | #include "wx/utils.h" |
9eddec69 | 21 | #include "wx/settings.h" |
88a7a4e1 WS |
22 | #endif |
23 | ||
a4e64fb5 | 24 | #include "wx/tokenzr.h" |
aeb9a156 | 25 | #include "wx/stockitem.h" |
643e9cf9 | 26 | #include "wx/testing.h" |
4bb6408c | 27 | |
338dd992 JJ |
28 | #ifdef __VMS__ |
29 | #pragma message disable nosimpint | |
30 | #endif | |
f97c9854 | 31 | #include <Xm/Xm.h> |
dfad0599 JS |
32 | #include <Xm/MwmUtil.h> |
33 | #include <Xm/Label.h> | |
34 | #include <Xm/BulletinB.h> | |
35 | #include <Xm/Frame.h> | |
36 | #include <Xm/Text.h> | |
37 | #include <Xm/DialogS.h> | |
38 | #include <Xm/FileSB.h> | |
39 | #include <Xm/RowColumn.h> | |
40 | #include <Xm/LabelG.h> | |
338dd992 JJ |
41 | #ifdef __VMS__ |
42 | #pragma message enable nosimpint | |
43 | #endif | |
f97c9854 | 44 | |
ee1aaf99 JS |
45 | #include "wx/motif/private.h" |
46 | ||
f74172ab | 47 | IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase) |
4bb6408c | 48 | |
dfe1eee3 | 49 | #define DEFAULT_FILE_SELECTOR_SIZE 0 |
2d120f83 JS |
50 | // Let Motif defines the size of File |
51 | // Selector Box (if 1), or fix it to | |
52 | // wxFSB_WIDTH x wxFSB_HEIGHT (if 0) | |
dfe1eee3 | 53 | #define wxFSB_WIDTH 600 |
dfad0599 JS |
54 | #define wxFSB_HEIGHT 500 |
55 | ||
56 | ||
83498ef2 | 57 | wxString wxFileDialog::m_fileSelectorAnswer = wxEmptyString; |
96be256b | 58 | bool wxFileDialog::m_fileSelectorReturned = false; |
f97c9854 | 59 | |
a4e64fb5 MB |
60 | static void wxFileSelClose(Widget WXUNUSED(w), |
61 | void* WXUNUSED(client_data), | |
62 | XmAnyCallbackStruct *WXUNUSED(call_data)) | |
63 | { | |
83498ef2 | 64 | wxFileDialog::m_fileSelectorAnswer = wxEmptyString; |
96be256b | 65 | wxFileDialog::m_fileSelectorReturned = true; |
a4e64fb5 MB |
66 | } |
67 | ||
dfe1eee3 | 68 | void wxFileSelCancel( Widget WXUNUSED(fs), XtPointer WXUNUSED(client_data), |
2d120f83 | 69 | XmFileSelectionBoxCallbackStruct *WXUNUSED(cbs) ) |
f97c9854 | 70 | { |
83498ef2 | 71 | wxFileDialog::m_fileSelectorAnswer = wxEmptyString; |
96be256b | 72 | wxFileDialog::m_fileSelectorReturned = true; |
f97c9854 JS |
73 | } |
74 | ||
f9e02ac7 | 75 | void wxFileSelOk(Widget WXUNUSED(fs), XtPointer WXUNUSED(client_data), XmFileSelectionBoxCallbackStruct *cbs) |
f97c9854 | 76 | { |
2d120f83 JS |
77 | char *filename = NULL; |
78 | if (!XmStringGetLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET, &filename)) { | |
83498ef2 | 79 | wxFileDialog::m_fileSelectorAnswer = wxEmptyString; |
96be256b | 80 | wxFileDialog::m_fileSelectorReturned = true; |
2d120f83 JS |
81 | } else { |
82 | if (filename) { | |
83 | wxFileDialog::m_fileSelectorAnswer = filename; | |
84 | XtFree(filename); | |
85 | } | |
96be256b | 86 | wxFileDialog::m_fileSelectorReturned = true; |
f97c9854 | 87 | } |
f97c9854 JS |
88 | } |
89 | ||
a4e64fb5 MB |
90 | static wxString ParseWildCard( const wxString& wild ) |
91 | { | |
4b6a582b VZ |
92 | #if wxDEBUG_LEVEL |
93 | static const char *msg = | |
94 | "Motif file dialog does not understand this wildcard syntax"; | |
02a48e3b | 95 | #endif |
a4e64fb5 | 96 | |
0fcb9bef MB |
97 | wxArrayString wildDescriptions, wildFilters; |
98 | const size_t count = wxParseCommonDialogsFilter(wild, | |
99 | wildDescriptions, | |
100 | wildFilters); | |
9a83f860 VZ |
101 | wxCHECK_MSG( count, wxT("*.*"), wxT("wxFileDialog: bad wildcard string") ); |
102 | wxCHECK_MSG( count == 1, wxT("*.*"), msg ); | |
0fcb9bef MB |
103 | |
104 | // check for *.txt;*.rtf | |
9a83f860 | 105 | wxStringTokenizer tok2( wildFilters[0], wxT(";") ); |
0fcb9bef MB |
106 | wxString wildcard = tok2.GetNextToken(); |
107 | ||
108 | wxCHECK_MSG( tok2.CountTokens() <= 1, wildcard, msg ); | |
109 | return wildcard; | |
a4e64fb5 MB |
110 | } |
111 | ||
dfad0599 | 112 | wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, |
2d120f83 | 113 | const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, |
ff3e84ff VZ |
114 | long style, const wxPoint& pos, const wxSize& sz, const wxString& name) |
115 | :wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name) | |
dfad0599 | 116 | { |
dfad0599 | 117 | } |
f97c9854 | 118 | |
af111fc3 | 119 | static void wxChangeListBoxColours(wxWindow* WXUNUSED(win), Widget widget) |
a91b47e8 | 120 | { |
a8680e3e | 121 | wxDoChangeBackgroundColour((WXWidget) widget, *wxWHITE); |
a91b47e8 JS |
122 | |
123 | // Change colour of the scrolled areas of the listboxes | |
124 | Widget listParent = XtParent (widget); | |
d4d46b56 | 125 | #if 0 |
96be256b | 126 | wxDoChangeBackgroundColour((WXWidget) listParent, *wxWHITE, true); |
d4d46b56 | 127 | #endif |
a91b47e8 JS |
128 | |
129 | Widget hsb = (Widget) 0; | |
130 | Widget vsb = (Widget) 0; | |
131 | XtVaGetValues (listParent, | |
132 | XmNhorizontalScrollBar, &hsb, | |
133 | XmNverticalScrollBar, &vsb, | |
134 | NULL); | |
dfe1eee3 | 135 | |
a91b47e8 JS |
136 | /* TODO: should scrollbars be affected? Should probably have separate |
137 | * function to change them (by default, taken from wxSystemSettings) | |
138 | */ | |
a756f210 | 139 | wxColour backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
96be256b MB |
140 | wxDoChangeBackgroundColour((WXWidget) hsb, backgroundColour, true); |
141 | wxDoChangeBackgroundColour((WXWidget) vsb, backgroundColour, true); | |
a91b47e8 JS |
142 | |
143 | if (hsb) | |
144 | XtVaSetValues (hsb, | |
145 | XmNtroughColor, backgroundColour.AllocColour(XtDisplay(hsb)), | |
146 | NULL); | |
147 | if (vsb) | |
148 | XtVaSetValues (vsb, | |
149 | XmNtroughColor, backgroundColour.AllocColour(XtDisplay(vsb)), | |
150 | NULL); | |
151 | } | |
152 | ||
dfad0599 | 153 | int wxFileDialog::ShowModal() |
f97c9854 | 154 | { |
643e9cf9 VS |
155 | WX_TESTING_SHOW_MODAL_HOOK(); |
156 | ||
2d120f83 | 157 | wxBeginBusyCursor(); |
dfe1eee3 | 158 | |
2d120f83 JS |
159 | // static char fileBuf[512]; |
160 | Widget parentWidget = (Widget) 0; | |
161 | if (m_parent) | |
2d120f83 | 162 | parentWidget = (Widget) m_parent->GetTopWidget(); |
f97c9854 | 163 | else |
2d120f83 | 164 | parentWidget = (Widget) wxTheApp->GetTopLevelWidget(); |
ee1aaf99 | 165 | // prepare the arg list |
6ace5176 | 166 | Display* dpy = XtDisplay(parentWidget); |
ee1aaf99 JS |
167 | Arg args[10]; |
168 | int ac = 0; | |
169 | ||
a1b806b9 | 170 | if (m_backgroundColour.IsOk()) |
105fbe1f | 171 | { |
d3b9f782 | 172 | wxComputeColours (dpy, & m_backgroundColour, NULL); |
105fbe1f MB |
173 | |
174 | XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++; | |
175 | XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++; | |
176 | XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++; | |
177 | XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; | |
178 | } | |
ee1aaf99 | 179 | |
6ace5176 MB |
180 | wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
181 | ||
7398fb81 MB |
182 | #if __WXMOTIF20__ && !__WXLESSTIF__ |
183 | XtSetArg(args[ac], XmNbuttonRenderTable, font.GetFontTypeC(dpy)); ac++; | |
184 | XtSetArg(args[ac], XmNlabelRenderTable, font.GetFontTypeC(dpy)); ac++; | |
185 | XtSetArg(args[ac], XmNtextRenderTable, font.GetFontTypeC(dpy)); ac++; | |
186 | #else | |
187 | XtSetArg(args[ac], XmNbuttonFontList, font.GetFontTypeC(dpy)); ac++; | |
188 | XtSetArg(args[ac], XmNlabelFontList, font.GetFontTypeC(dpy)); ac++; | |
189 | XtSetArg(args[ac], XmNtextFontList, font.GetFontTypeC(dpy)); ac++; | |
190 | #endif | |
dfe1eee3 | 191 | |
aeb9a156 | 192 | Widget fileSel = XmCreateFileSelectionDialog(parentWidget, |
f1db433a VZ |
193 | wxMOTIF_STR("file_selector"), |
194 | args, ac); | |
aeb9a156 MB |
195 | #define wxFSChild( name ) \ |
196 | XmFileSelectionBoxGetChild(fileSel, name) | |
197 | ||
198 | XtUnmanageChild(wxFSChild(XmDIALOG_HELP_BUTTON)); | |
199 | ||
200 | Widget filterWidget = wxFSChild(XmDIALOG_FILTER_TEXT); | |
201 | Widget selectionWidget = wxFSChild(XmDIALOG_TEXT); | |
202 | Widget dirListWidget = wxFSChild(XmDIALOG_DIR_LIST); | |
203 | Widget fileListWidget = wxFSChild(XmDIALOG_LIST); | |
204 | ||
205 | // for changing labels | |
206 | Widget okWidget = wxFSChild(XmDIALOG_OK_BUTTON); | |
207 | Widget applyWidget = wxFSChild(XmDIALOG_APPLY_BUTTON); | |
208 | Widget cancelWidget = wxFSChild(XmDIALOG_CANCEL_BUTTON); | |
209 | Widget dirlistLabel = wxFSChild(XmDIALOG_DIR_LIST_LABEL); | |
210 | Widget filterLabel = wxFSChild(XmDIALOG_FILTER_LABEL); | |
211 | Widget listLabel = wxFSChild(XmDIALOG_LIST_LABEL); | |
212 | Widget selectionLabel = wxFSChild(XmDIALOG_SELECTION_LABEL); | |
213 | ||
214 | #undef wxFSChild | |
215 | ||
216 | // change labels | |
217 | wxXmString btnOK( wxGetStockLabel( wxID_OK, false ) ), | |
218 | btnCancel( wxGetStockLabel( wxID_CANCEL, false ) ), | |
219 | btnFilter( _("Filter") ), lblFilter( _("Filter") ), | |
220 | lblDirectories( _("Directories") ), | |
221 | lblFiles( _("Files" ) ), lblSelection( _("Selection") ); | |
222 | ||
223 | XtVaSetValues( okWidget, XmNlabelString, btnOK(), NULL ); | |
224 | XtVaSetValues( applyWidget, XmNlabelString, btnFilter(), NULL ); | |
225 | XtVaSetValues( cancelWidget, XmNlabelString, btnCancel(), NULL ); | |
226 | XtVaSetValues( dirlistLabel, XmNlabelString, lblDirectories(), NULL ); | |
227 | XtVaSetValues( filterLabel, XmNlabelString, lblFilter(), NULL ); | |
228 | XtVaSetValues( listLabel, XmNlabelString, lblFiles(), NULL ); | |
229 | XtVaSetValues( selectionLabel, XmNlabelString, lblSelection(), NULL ); | |
a91b47e8 | 230 | |
2d120f83 | 231 | Widget shell = XtParent(fileSel); |
dfe1eee3 | 232 | |
6636ef8d | 233 | if ( !m_message.empty() ) |
d3a80c92 | 234 | XtVaSetValues(shell, |
6991087b | 235 | XmNtitle, (const char*)m_message.mb_str(), |
d3a80c92 | 236 | NULL); |
dfe1eee3 | 237 | |
83498ef2 | 238 | if (!m_wildCard.empty()) |
2d120f83 | 239 | { |
a4e64fb5 MB |
240 | // return something understandable by Motif |
241 | wxString wildCard = ParseWildCard( m_wildCard ); | |
242 | wxString filter; | |
83498ef2 | 243 | if (!m_dir.empty()) |
a4e64fb5 | 244 | filter = m_dir + wxString("/") + wildCard; |
2d120f83 | 245 | else |
a4e64fb5 | 246 | filter = wildCard; |
dfe1eee3 | 247 | |
6991087b | 248 | XmTextSetString(filterWidget, filter.char_str()); |
2d120f83 JS |
249 | XmFileSelectionDoSearch(fileSel, NULL); |
250 | } | |
dfe1eee3 | 251 | |
2d120f83 JS |
252 | // Suggested by Terry Gitnick, 16/9/97, because of change in Motif |
253 | // file selector on Solaris 1.5.1. | |
83498ef2 | 254 | if ( !m_dir.empty() ) |
2d120f83 | 255 | { |
d4d46b56 | 256 | wxXmString thePath( m_dir ); |
dfe1eee3 | 257 | |
2d120f83 | 258 | XtVaSetValues (fileSel, |
d4d46b56 | 259 | XmNdirectory, thePath(), |
2d120f83 | 260 | NULL); |
d4d46b56 | 261 | } |
dfe1eee3 | 262 | |
83498ef2 | 263 | wxString entirePath; |
aeb9a156 | 264 | |
83498ef2 | 265 | if (!m_dir.empty()) |
aeb9a156 MB |
266 | { |
267 | entirePath = m_dir + wxString("/") + m_fileName; | |
268 | } | |
269 | else | |
270 | { | |
271 | entirePath = m_fileName; | |
272 | } | |
273 | ||
83498ef2 | 274 | if (!entirePath.empty()) |
d4d46b56 | 275 | { |
6991087b | 276 | XmTextSetString(selectionWidget, entirePath.char_str()); |
2d120f83 | 277 | } |
dfe1eee3 | 278 | |
aeb9a156 MB |
279 | XtAddCallback(fileSel, XmNcancelCallback, |
280 | (XtCallbackProc)wxFileSelCancel, (XtPointer)NULL); | |
281 | XtAddCallback(fileSel, XmNokCallback, | |
282 | (XtCallbackProc)wxFileSelOk, (XtPointer)NULL); | |
a4e64fb5 MB |
283 | XtAddCallback(fileSel, XmNunmapCallback, |
284 | (XtCallbackProc)wxFileSelClose, (XtPointer)this); | |
dfe1eee3 | 285 | |
2d120f83 JS |
286 | //#if XmVersion > 1000 |
287 | // I'm not sure about what you mean with XmVersion. | |
288 | // If this is for Motif1.1/Motif1.2, then check XmVersion>=1200 | |
289 | // (Motif1.1.4 ==> XmVersion 1100 ) | |
aeb9a156 | 290 | // Nevertheless, I put here a #define, so anyone can choose in (I)makefile. |
2d120f83 | 291 | // |
f97c9854 | 292 | #if !DEFAULT_FILE_SELECTOR_SIZE |
2d120f83 JS |
293 | int width = wxFSB_WIDTH; |
294 | int height = wxFSB_HEIGHT; | |
295 | XtVaSetValues(fileSel, | |
296 | XmNwidth, width, | |
297 | XmNheight, height, | |
298 | XmNresizePolicy, XmRESIZE_NONE, | |
299 | NULL); | |
f97c9854 | 300 | #endif |
a8680e3e MB |
301 | wxDoChangeBackgroundColour((WXWidget) filterWidget, *wxWHITE); |
302 | wxDoChangeBackgroundColour((WXWidget) selectionWidget, *wxWHITE); | |
a91b47e8 | 303 | |
a91b47e8 JS |
304 | wxChangeListBoxColours(this, dirListWidget); |
305 | wxChangeListBoxColours(this, fileListWidget); | |
dfe1eee3 | 306 | |
2d120f83 | 307 | XtManageChild(fileSel); |
a91b47e8 | 308 | |
83498ef2 | 309 | m_fileSelectorAnswer = wxEmptyString; |
96be256b | 310 | m_fileSelectorReturned = false; |
dfe1eee3 | 311 | |
2d120f83 | 312 | wxEndBusyCursor(); |
dfe1eee3 | 313 | |
96be256b | 314 | XtAddGrab(XtParent(fileSel), True, False); |
eb6fa4b4 | 315 | XtAppContext context = (XtAppContext) wxTheApp->GetAppContext(); |
2d120f83 JS |
316 | XEvent event; |
317 | while (!m_fileSelectorReturned) | |
318 | { | |
eb6fa4b4 MB |
319 | XtAppNextEvent(context, &event); |
320 | XtDispatchEvent(&event); | |
2d120f83 JS |
321 | } |
322 | XtRemoveGrab(XtParent(fileSel)); | |
dfe1eee3 | 323 | |
2d120f83 JS |
324 | XtUnmapWidget(XtParent(fileSel)); |
325 | XtDestroyWidget(XtParent(fileSel)); | |
dfe1eee3 | 326 | |
2d120f83 JS |
327 | // Now process all events, because otherwise |
328 | // this might remain on the screen | |
aeb9a156 | 329 | wxFlushEvents(XtDisplay(fileSel)); |
dfe1eee3 | 330 | |
2d120f83 JS |
331 | m_path = m_fileSelectorAnswer; |
332 | m_fileName = wxFileNameFromPath(m_fileSelectorAnswer); | |
333 | m_dir = wxPathOnly(m_path); | |
dfe1eee3 | 334 | |
83498ef2 | 335 | if (m_fileName.empty()) |
2d120f83 JS |
336 | return wxID_CANCEL; |
337 | else | |
338 | return wxID_OK; | |
4bb6408c | 339 | } |