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