]> git.saurik.com Git - wxWidgets.git/blame - src/motif/filedlg.cpp
Added buttons to allow a dump of DB DATATYPES and DB DIAGNOSTIC info via wxLogMessage...
[wxWidgets.git] / src / motif / filedlg.cpp
CommitLineData
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"
4bb6408c 29
338dd992
JJ
30#ifdef __VMS__
31#pragma message disable nosimpint
32#endif
f97c9854 33#include <Xm/Xm.h>
dfad0599
JS
34#include <Xm/MwmUtil.h>
35#include <Xm/Label.h>
36#include <Xm/BulletinB.h>
37#include <Xm/Frame.h>
38#include <Xm/Text.h>
39#include <Xm/DialogS.h>
40#include <Xm/FileSB.h>
41#include <Xm/RowColumn.h>
42#include <Xm/LabelG.h>
338dd992
JJ
43#ifdef __VMS__
44#pragma message enable nosimpint
45#endif
f97c9854 46
ee1aaf99
JS
47#include "wx/motif/private.h"
48
4bb6408c 49IMPLEMENT_CLASS(wxFileDialog, wxDialog)
4bb6408c 50
dfe1eee3 51#define DEFAULT_FILE_SELECTOR_SIZE 0
2d120f83
JS
52// Let Motif defines the size of File
53// Selector Box (if 1), or fix it to
54// wxFSB_WIDTH x wxFSB_HEIGHT (if 0)
dfe1eee3 55#define wxFSB_WIDTH 600
dfad0599
JS
56#define wxFSB_HEIGHT 500
57
58
7482b220 59wxString wxFileSelector(const char *title,
4bb6408c
JS
60 const char *defaultDir, const char *defaultFileName,
61 const char *defaultExtension, const char *filter, int flags,
62 wxWindow *parent, int x, int y)
63{
64 // If there's a default extension specified but no filter, we create a suitable
65 // filter.
dfe1eee3 66
4bb6408c
JS
67 wxString filter2("");
68 if ( defaultExtension && !filter )
69 filter2 = wxString("*.") + wxString(defaultExtension) ;
70 else if ( filter )
71 filter2 = filter;
dfe1eee3 72
4bb6408c
JS
73 wxString defaultDirString;
74 if (defaultDir)
75 defaultDirString = defaultDir;
76 else
77 defaultDirString = "";
dfe1eee3 78
4bb6408c
JS
79 wxString defaultFilenameString;
80 if (defaultFileName)
81 defaultFilenameString = defaultFileName;
82 else
83 defaultFilenameString = "";
dfe1eee3 84
4bb6408c 85 wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y));
dfe1eee3 86
4bb6408c
JS
87 if ( fileDialog.ShowModal() == wxID_OK )
88 {
7482b220 89 return fileDialog.GetPath();
4bb6408c
JS
90 }
91 else
7482b220 92 return wxEmptyString;
4bb6408c
JS
93}
94
7482b220 95wxString wxFileSelectorEx(const char *title,
4bb6408c
JS
96 const char *defaultDir,
97 const char *defaultFileName,
98 int* defaultFilterIndex,
99 const char *filter,
100 int flags,
101 wxWindow* parent,
102 int x,
103 int y)
dfe1eee3 104
4bb6408c
JS
105{
106 wxFileDialog fileDialog(parent, title ? title : "", defaultDir ? defaultDir : "",
107 defaultFileName ? defaultFileName : "", filter ? filter : "", flags, wxPoint(x, y));
dfe1eee3 108
4bb6408c
JS
109 if ( fileDialog.ShowModal() == wxID_OK )
110 {
111 *defaultFilterIndex = fileDialog.GetFilterIndex();
c330a2cf 112 return fileDialog.GetPath();
4bb6408c
JS
113 }
114 else
7482b220 115 return wxEmptyString;
4bb6408c
JS
116}
117
dfad0599
JS
118wxString wxFileDialog::m_fileSelectorAnswer = "";
119bool wxFileDialog::m_fileSelectorReturned = FALSE;
f97c9854 120
dfe1eee3 121void wxFileSelCancel( Widget WXUNUSED(fs), XtPointer WXUNUSED(client_data),
2d120f83 122 XmFileSelectionBoxCallbackStruct *WXUNUSED(cbs) )
f97c9854 123{
2d120f83
JS
124 wxFileDialog::m_fileSelectorAnswer = "";
125 wxFileDialog::m_fileSelectorReturned = TRUE;
f97c9854
JS
126}
127
f9e02ac7 128void wxFileSelOk(Widget WXUNUSED(fs), XtPointer WXUNUSED(client_data), XmFileSelectionBoxCallbackStruct *cbs)
f97c9854 129{
2d120f83
JS
130 char *filename = NULL;
131 if (!XmStringGetLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET, &filename)) {
132 wxFileDialog::m_fileSelectorAnswer = "";
133 wxFileDialog::m_fileSelectorReturned = TRUE;
134 } else {
135 if (filename) {
136 wxFileDialog::m_fileSelectorAnswer = filename;
137 XtFree(filename);
138 }
139 wxFileDialog::m_fileSelectorReturned = TRUE;
f97c9854 140 }
f97c9854
JS
141}
142
dfad0599 143wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
2d120f83
JS
144 const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
145 long style, const wxPoint& pos)
dfad0599
JS
146{
147 m_message = message;
148 m_dialogStyle = style;
149 m_parent = parent;
150 m_path = "";
151 m_fileName = defaultFileName;
152 m_dir = defaultDir;
153 m_wildCard = wildCard;
154 m_filterIndex = 1;
155 m_pos = pos;
156}
f97c9854 157
af111fc3 158static void wxChangeListBoxColours(wxWindow* WXUNUSED(win), Widget widget)
a91b47e8 159{
dfe1eee3 160 wxWindow::DoChangeBackgroundColour((WXWidget) widget, *wxWHITE);
a91b47e8
JS
161
162 // Change colour of the scrolled areas of the listboxes
163 Widget listParent = XtParent (widget);
dfe1eee3 164 wxWindow::DoChangeBackgroundColour((WXWidget) listParent, *wxWHITE, TRUE);
a91b47e8
JS
165
166 Widget hsb = (Widget) 0;
167 Widget vsb = (Widget) 0;
168 XtVaGetValues (listParent,
169 XmNhorizontalScrollBar, &hsb,
170 XmNverticalScrollBar, &vsb,
171 NULL);
dfe1eee3 172
a91b47e8
JS
173 /* TODO: should scrollbars be affected? Should probably have separate
174 * function to change them (by default, taken from wxSystemSettings)
175 */
176 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
dfe1eee3
VZ
177 wxWindow::DoChangeBackgroundColour((WXWidget) hsb, backgroundColour, TRUE);
178 wxWindow::DoChangeBackgroundColour((WXWidget) vsb, backgroundColour, TRUE);
a91b47e8
JS
179
180 if (hsb)
181 XtVaSetValues (hsb,
182 XmNtroughColor, backgroundColour.AllocColour(XtDisplay(hsb)),
183 NULL);
184 if (vsb)
185 XtVaSetValues (vsb,
186 XmNtroughColor, backgroundColour.AllocColour(XtDisplay(vsb)),
187 NULL);
188}
189
dfad0599 190int wxFileDialog::ShowModal()
f97c9854 191{
2d120f83 192 wxBeginBusyCursor();
dfe1eee3 193
2d120f83
JS
194 // static char fileBuf[512];
195 Widget parentWidget = (Widget) 0;
196 if (m_parent)
197 {
198 parentWidget = (Widget) m_parent->GetTopWidget();
199 }
f97c9854 200 else
2d120f83 201 parentWidget = (Widget) wxTheApp->GetTopLevelWidget();
ee1aaf99
JS
202 // prepare the arg list
203 Arg args[10];
204 int ac = 0;
205
206 wxComputeColours (XtDisplay(parentWidget), & m_backgroundColour,
207 (wxColour*) NULL);
208
209 XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++;
210 XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++;
211 XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++;
212 XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++;
213
dfe1eee3 214
ee1aaf99 215 Widget fileSel = XmCreateFileSelectionDialog(parentWidget, "file_selector", args, ac);
2d120f83 216 XtUnmanageChild(XmFileSelectionBoxGetChild(fileSel, XmDIALOG_HELP_BUTTON));
a91b47e8
JS
217
218 Widget filterWidget = XmFileSelectionBoxGetChild(fileSel, XmDIALOG_FILTER_TEXT);
219 Widget selectionWidget = XmFileSelectionBoxGetChild(fileSel, XmDIALOG_TEXT);
220 Widget dirListWidget = XmFileSelectionBoxGetChild(fileSel, XmDIALOG_DIR_LIST);
221 Widget fileListWidget = XmFileSelectionBoxGetChild(fileSel, XmDIALOG_LIST);
dfe1eee3
VZ
222
223 // code using these vars disabled
224#if 0
a91b47e8
JS
225 Widget okWidget = XmFileSelectionBoxGetChild(fileSel, XmDIALOG_OK_BUTTON);
226 Widget applyWidget = XmFileSelectionBoxGetChild(fileSel, XmDIALOG_APPLY_BUTTON);
227 Widget cancelWidget = XmFileSelectionBoxGetChild(fileSel, XmDIALOG_CANCEL_BUTTON);
dfe1eee3
VZ
228#endif
229
a91b47e8 230
2d120f83 231 Widget shell = XtParent(fileSel);
dfe1eee3 232
2d120f83
JS
233 if (!m_message.IsNull())
234 XtVaSetValues(shell, XmNtitle, (char*) (const char*) m_message, NULL);
dfe1eee3 235
2d120f83 236 wxString entirePath("");
dfe1eee3 237
2d120f83
JS
238 if ((m_dir != "") && (m_fileName != ""))
239 {
240 entirePath = m_dir + wxString("/") + m_fileName;
241 }
242 else if ((m_dir != "") && (m_fileName == ""))
243 {
244 entirePath = m_dir + wxString("/");
245 }
246 else if ((m_dir == "") && (m_fileName != ""))
247 {
248 entirePath = m_fileName;
249 }
dfe1eee3 250
2d120f83
JS
251 if (entirePath != "")
252 {
2d120f83
JS
253 XmTextSetString(selectionWidget, (char*) (const char*) entirePath);
254 }
dfe1eee3 255
2d120f83
JS
256 if (m_wildCard != "")
257 {
258 wxString filter("");
259 if (m_dir != "")
260 filter = m_dir + wxString("/") + m_wildCard;
261 else
262 filter = m_wildCard;
dfe1eee3 263
2d120f83
JS
264 XmTextSetString(filterWidget, (char*) (const char*) filter);
265 XmFileSelectionDoSearch(fileSel, NULL);
266 }
dfe1eee3 267
2d120f83
JS
268 // Suggested by Terry Gitnick, 16/9/97, because of change in Motif
269 // file selector on Solaris 1.5.1.
270 if ( m_dir != "" )
271 {
272 XmString thePath = XmStringCreateLtoR ((char*) (const char*) m_dir,
273 XmSTRING_DEFAULT_CHARSET);
dfe1eee3 274
2d120f83
JS
275 XtVaSetValues (fileSel,
276 XmNdirectory, thePath,
277 NULL);
dfe1eee3 278
2d120f83
JS
279 XmStringFree(thePath);
280 }
dfe1eee3 281
2d120f83
JS
282 XtAddCallback(fileSel, XmNcancelCallback, (XtCallbackProc)wxFileSelCancel, (XtPointer)NULL);
283 XtAddCallback(fileSel, XmNokCallback, (XtCallbackProc)wxFileSelOk, (XtPointer)NULL);
dfe1eee3 284
2d120f83
JS
285 //#if XmVersion > 1000
286 // I'm not sure about what you mean with XmVersion.
287 // If this is for Motif1.1/Motif1.2, then check XmVersion>=1200
288 // (Motif1.1.4 ==> XmVersion 1100 )
289 // Nevertheless, I put here a #define, so anyone can choose in (I)makefile...
290 //
f97c9854 291#if !DEFAULT_FILE_SELECTOR_SIZE
2d120f83
JS
292 int width = wxFSB_WIDTH;
293 int height = wxFSB_HEIGHT;
294 XtVaSetValues(fileSel,
295 XmNwidth, width,
296 XmNheight, height,
297 XmNresizePolicy, XmRESIZE_NONE,
298 NULL);
f97c9854 299#endif
ee1aaf99 300 // DoChangeBackgroundColour((WXWidget) fileSel, m_backgroundColour);
a91b47e8
JS
301 DoChangeBackgroundColour((WXWidget) filterWidget, *wxWHITE);
302 DoChangeBackgroundColour((WXWidget) selectionWidget, *wxWHITE);
303
a91b47e8
JS
304 wxChangeListBoxColours(this, dirListWidget);
305 wxChangeListBoxColours(this, fileListWidget);
dfe1eee3 306
2d120f83 307 XtManageChild(fileSel);
a91b47e8 308
2d120f83
JS
309 m_fileSelectorAnswer = "";
310 m_fileSelectorReturned = FALSE;
dfe1eee3 311
2d120f83 312 wxEndBusyCursor();
dfe1eee3 313
2d120f83
JS
314 XtAddGrab(XtParent(fileSel), TRUE, FALSE);
315 XEvent event;
316 while (!m_fileSelectorReturned)
317 {
318 XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll);
319 }
320 XtRemoveGrab(XtParent(fileSel));
dfe1eee3 321
2d120f83 322 XmUpdateDisplay((Widget) wxTheApp->GetTopLevelWidget()); // Experimental
dfe1eee3 323
2d120f83
JS
324 // XtDestroyWidget(fileSel);
325 XtUnmapWidget(XtParent(fileSel));
326 XtDestroyWidget(XtParent(fileSel));
dfe1eee3 327
2d120f83
JS
328 // Now process all events, because otherwise
329 // this might remain on the screen
330 XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE);
331 while (XtAppPending((XtAppContext) wxTheApp->GetAppContext()))
332 {
333 XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
334 XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event);
335 XtDispatchEvent(&event);
336 }
dfe1eee3 337
2d120f83
JS
338 m_path = m_fileSelectorAnswer;
339 m_fileName = wxFileNameFromPath(m_fileSelectorAnswer);
340 m_dir = wxPathOnly(m_path);
dfe1eee3 341
2d120f83
JS
342 if (m_fileName == "")
343 return wxID_CANCEL;
344 else
345 return wxID_OK;
4bb6408c
JS
346}
347
348// Generic file load/save dialog
7482b220 349static wxString
4bb6408c
JS
350wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent)
351{
2d120f83 352 char *ext = (char *)extension;
dfe1eee3
VZ
353
354 wxString prompt;
2d120f83
JS
355 wxString str;
356 if (load)
dfe1eee3 357 str = _("Load %s file");
2d120f83 358 else
dfe1eee3
VZ
359 str = _("Save %s file");
360 prompt.Printf(str, what);
361
362 if (*ext == '.')
363 ext++;
364 wxString wild;
365 wild.Printf("*.%s", ext);
366
2d120f83 367 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
4bb6408c
JS
368}
369
370// Generic file load dialog
7482b220 371wxString wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
4bb6408c 372{
2d120f83 373 return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
4bb6408c
JS
374}
375
376
377// Generic file save dialog
7482b220 378wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
4bb6408c 379{
2d120f83 380 return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
4bb6408c
JS
381}
382
383