1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "filedlg.h"
17 #define XtDisplay XTDISPLAY
18 #define XtParent XTPARENT
19 #define XtWindow XTWINDOW
24 #include "wx/filedlg.h"
27 #include "wx/settings.h"
28 #include "wx/tokenzr.h"
31 #pragma message disable nosimpint
34 #include <Xm/MwmUtil.h>
36 #include <Xm/BulletinB.h>
39 #include <Xm/DialogS.h>
40 #include <Xm/FileSB.h>
41 #include <Xm/RowColumn.h>
42 #include <Xm/LabelG.h>
44 #pragma message enable nosimpint
47 #include "wx/motif/private.h"
49 IMPLEMENT_CLASS(wxFileDialog
, wxFileDialogBase
)
51 #define DEFAULT_FILE_SELECTOR_SIZE 0
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)
55 #define wxFSB_WIDTH 600
56 #define wxFSB_HEIGHT 500
59 wxString
wxFileDialog::m_fileSelectorAnswer
= "";
60 bool wxFileDialog::m_fileSelectorReturned
= FALSE
;
62 static void wxFileSelClose(Widget
WXUNUSED(w
),
63 void* WXUNUSED(client_data
),
64 XmAnyCallbackStruct
*WXUNUSED(call_data
))
66 wxFileDialog::m_fileSelectorAnswer
= "";
67 wxFileDialog::m_fileSelectorReturned
= TRUE
;
70 void wxFileSelCancel( Widget
WXUNUSED(fs
), XtPointer
WXUNUSED(client_data
),
71 XmFileSelectionBoxCallbackStruct
*WXUNUSED(cbs
) )
73 wxFileDialog::m_fileSelectorAnswer
= "";
74 wxFileDialog::m_fileSelectorReturned
= TRUE
;
77 void wxFileSelOk(Widget
WXUNUSED(fs
), XtPointer
WXUNUSED(client_data
), XmFileSelectionBoxCallbackStruct
*cbs
)
79 char *filename
= NULL
;
80 if (!XmStringGetLtoR(cbs
->value
, XmSTRING_DEFAULT_CHARSET
, &filename
)) {
81 wxFileDialog::m_fileSelectorAnswer
= "";
82 wxFileDialog::m_fileSelectorReturned
= TRUE
;
85 wxFileDialog::m_fileSelectorAnswer
= filename
;
88 wxFileDialog::m_fileSelectorReturned
= TRUE
;
92 static wxString
ParseWildCard( const wxString
& wild
)
95 static const wxChar
* msg
=
96 _T("Motif file dialog does not understand this ")
97 _T("wildcard syntax");
100 wxStringTokenizer
tok( wild
, _T("|") );
102 wxCHECK_MSG( tok
.CountTokens() <= 2, _T("*.*"), msg
);
104 if( tok
.CountTokens() == 1 ) return wild
;
108 wxStringTokenizer
tok2( tok
.GetNextToken(), _T(";") );
110 wxCHECK_MSG( tok2
.CountTokens() == 1, tok2
.GetNextToken(), msg
);
111 return tok2
.GetNextToken();
114 wxFileDialog::wxFileDialog(wxWindow
*parent
, const wxString
& message
,
115 const wxString
& defaultDir
, const wxString
& defaultFileName
, const wxString
& wildCard
,
116 long style
, const wxPoint
& pos
)
117 :wxFileDialogBase(parent
, message
, defaultDir
, defaultFileName
, wildCard
, style
, pos
)
122 static void wxChangeListBoxColours(wxWindow
* WXUNUSED(win
), Widget widget
)
124 wxDoChangeBackgroundColour((WXWidget
) widget
, *wxWHITE
);
126 // Change colour of the scrolled areas of the listboxes
127 Widget listParent
= XtParent (widget
);
129 wxDoChangeBackgroundColour((WXWidget
) listParent
, *wxWHITE
, TRUE
);
132 Widget hsb
= (Widget
) 0;
133 Widget vsb
= (Widget
) 0;
134 XtVaGetValues (listParent
,
135 XmNhorizontalScrollBar
, &hsb
,
136 XmNverticalScrollBar
, &vsb
,
139 /* TODO: should scrollbars be affected? Should probably have separate
140 * function to change them (by default, taken from wxSystemSettings)
142 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
143 wxDoChangeBackgroundColour((WXWidget
) hsb
, backgroundColour
, TRUE
);
144 wxDoChangeBackgroundColour((WXWidget
) vsb
, backgroundColour
, TRUE
);
148 XmNtroughColor
, backgroundColour
.AllocColour(XtDisplay(hsb
)),
152 XmNtroughColor
, backgroundColour
.AllocColour(XtDisplay(vsb
)),
156 int wxFileDialog::ShowModal()
160 // static char fileBuf[512];
161 Widget parentWidget
= (Widget
) 0;
163 parentWidget
= (Widget
) m_parent
->GetTopWidget();
165 parentWidget
= (Widget
) wxTheApp
->GetTopLevelWidget();
166 // prepare the arg list
170 wxComputeColours (XtDisplay(parentWidget
), & m_backgroundColour
,
173 XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++;
174 XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++;
175 XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++;
176 XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++;
179 Widget fileSel
= XmCreateFileSelectionDialog(parentWidget
, "file_selector", args
, ac
);
180 XtUnmanageChild(XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_HELP_BUTTON
));
182 Widget filterWidget
= XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_FILTER_TEXT
);
183 Widget selectionWidget
= XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_TEXT
);
184 Widget dirListWidget
= XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_DIR_LIST
);
185 Widget fileListWidget
= XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_LIST
);
187 // code using these vars disabled
189 Widget okWidget
= XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_OK_BUTTON
);
190 Widget applyWidget
= XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_APPLY_BUTTON
);
191 Widget cancelWidget
= XmFileSelectionBoxGetChild(fileSel
, XmDIALOG_CANCEL_BUTTON
);
195 Widget shell
= XtParent(fileSel
);
197 if (!m_message
.IsNull())
199 XmNtitle
, wxConstCast(m_message
.c_str(), char),
202 wxString
entirePath("");
204 if ((m_dir
!= "") && (m_fileName
!= ""))
206 entirePath
= m_dir
+ wxString("/") + m_fileName
;
208 else if ((m_dir
!= "") && (m_fileName
== ""))
210 entirePath
= m_dir
+ wxString("/");
212 else if ((m_dir
== "") && (m_fileName
!= ""))
214 entirePath
= m_fileName
;
217 if (m_wildCard
!= "")
219 // return something understandable by Motif
220 wxString wildCard
= ParseWildCard( m_wildCard
);
223 filter
= m_dir
+ wxString("/") + wildCard
;
227 XmTextSetString(filterWidget
, wxConstCast(filter
.c_str(), char));
228 XmFileSelectionDoSearch(fileSel
, NULL
);
231 // Suggested by Terry Gitnick, 16/9/97, because of change in Motif
232 // file selector on Solaris 1.5.1.
235 wxXmString
thePath( m_dir
);
237 XtVaSetValues (fileSel
,
238 XmNdirectory
, thePath(),
242 if (entirePath
!= "")
244 XmTextSetString(selectionWidget
,
245 wxConstCast(entirePath
.c_str(), char));
248 XtAddCallback(fileSel
, XmNcancelCallback
, (XtCallbackProc
)wxFileSelCancel
, (XtPointer
)NULL
);
249 XtAddCallback(fileSel
, XmNokCallback
, (XtCallbackProc
)wxFileSelOk
, (XtPointer
)NULL
);
250 XtAddCallback(fileSel
, XmNunmapCallback
,
251 (XtCallbackProc
)wxFileSelClose
, (XtPointer
)this);
253 //#if XmVersion > 1000
254 // I'm not sure about what you mean with XmVersion.
255 // If this is for Motif1.1/Motif1.2, then check XmVersion>=1200
256 // (Motif1.1.4 ==> XmVersion 1100 )
257 // Nevertheless, I put here a #define, so anyone can choose in (I)makefile...
259 #if !DEFAULT_FILE_SELECTOR_SIZE
260 int width
= wxFSB_WIDTH
;
261 int height
= wxFSB_HEIGHT
;
262 XtVaSetValues(fileSel
,
265 XmNresizePolicy
, XmRESIZE_NONE
,
268 // wxDoChangeBackgroundColour((WXWidget) fileSel, m_backgroundColour);
269 wxDoChangeBackgroundColour((WXWidget
) filterWidget
, *wxWHITE
);
270 wxDoChangeBackgroundColour((WXWidget
) selectionWidget
, *wxWHITE
);
272 wxChangeListBoxColours(this, dirListWidget
);
273 wxChangeListBoxColours(this, fileListWidget
);
275 XtManageChild(fileSel
);
277 m_fileSelectorAnswer
= "";
278 m_fileSelectorReturned
= FALSE
;
282 XtAddGrab(XtParent(fileSel
), TRUE
, FALSE
);
283 XtAppContext context
= (XtAppContext
) wxTheApp
->GetAppContext();
285 while (!m_fileSelectorReturned
)
287 XtAppNextEvent(context
, &event
);
288 XtDispatchEvent(&event
);
290 XtRemoveGrab(XtParent(fileSel
));
292 // XmUpdateDisplay((Widget) wxTheApp->GetTopLevelWidget()); // Experimental
294 Display
* display
= XtDisplay(fileSel
);
296 XtUnmapWidget(XtParent(fileSel
));
297 XtDestroyWidget(XtParent(fileSel
));
299 // Now process all events, because otherwise
300 // this might remain on the screen
301 wxFlushEvents(display
);
303 m_path
= m_fileSelectorAnswer
;
304 m_fileName
= wxFileNameFromPath(m_fileSelectorAnswer
);
305 m_dir
= wxPathOnly(m_path
);
307 if (m_fileName
== "")