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