]> git.saurik.com Git - wxWidgets.git/blame - src/generic/filedlgg.cpp
* rename maxOnOverflow parameter to CoordToRowOrCol() to clipToMinMax
[wxWidgets.git] / src / generic / filedlgg.cpp
CommitLineData
8b17ba72
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: filedlgg.cpp
23254b13 3// Purpose: wxGenericFileDialog
8b17ba72
RR
4// Author: Robert Roebling
5// Modified by:
6// Created: 12/12/98
7// RCS-ID: $Id$
8// Copyright: (c) Robert Roebling
c8c0e54c 9// Licence: wxWindows licence
8b17ba72
RR
10/////////////////////////////////////////////////////////////////////////////
11
9cedab37
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
8b17ba72
RR
20#ifdef __GNUG__
21#pragma implementation "filedlgg.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28#pragma hdrstop
29#endif
30
1e6feb95
VZ
31#if wxUSE_FILEDLG
32
099d4217 33#if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__)
23254b13 34#error wxGenericFileDialog currently only supports Unix, win32 and DOS
8b17ba72
RR
35#endif
36
04dbb646
VZ
37#include "wx/checkbox.h"
38#include "wx/textctrl.h"
39#include "wx/choice.h"
40#include "wx/checkbox.h"
41#include "wx/stattext.h"
8b17ba72
RR
42#include "wx/debug.h"
43#include "wx/log.h"
44#include "wx/intl.h"
45#include "wx/msgdlg.h"
46#include "wx/sizer.h"
0b855868 47#include "wx/bmpbuttn.h"
cae5359f 48#include "wx/tokenzr.h"
655cf310
VS
49#include "wx/mimetype.h"
50#include "wx/image.h"
51#include "wx/module.h"
eaf40b23 52#include "wx/config.h"
48fe8374 53#include "wx/imaglist.h"
5e673a6a 54#include "wx/dir.h"
60d2cc25 55#include "wx/artprov.h"
ed39ff57 56#include "wx/hash.h"
1265e13d 57#include "wx/file.h" // for wxS_IXXX constants only
23254b13
JS
58#include "wx/filedlg.h" // wxOPEN, wxSAVE...
59#include "wx/generic/filedlgg.h"
8b17ba72 60
e6daf794
RR
61#if wxUSE_TOOLTIPS
62 #include "wx/tooltip.h"
63#endif
64
ac2def68
RR
65#include <sys/types.h>
66#include <sys/stat.h>
4894ae18
VS
67
68#ifdef __UNIX__
69 #include <dirent.h>
70 #include <pwd.h>
71 #ifndef __VMS
72 # include <grp.h>
73 #endif
74#endif
75
76#ifdef __WATCOMC__
77 #include <direct.h>
27df579a 78#endif
4894ae18 79
7a82dabc 80#include <time.h>
099d4217 81#if defined(__UNIX__) || defined(__DOS__)
ac2def68 82#include <unistd.h>
099d4217 83#endif
8b17ba72 84
655cf310
VS
85// ----------------------------------------------------------------------------
86// private classes - icons list management
87// ----------------------------------------------------------------------------
88
89class wxFileIconEntry : public wxObject
90{
473d087e
RR
91public:
92 wxFileIconEntry(int i) { id = i; }
48fe8374 93
473d087e 94 int id;
655cf310
VS
95};
96
97
98class wxFileIconsTable
99{
473d087e
RR
100public:
101 wxFileIconsTable();
655cf310 102
473d087e
RR
103 int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
104 wxImageList *GetImageList() { return &m_ImageList; }
48fe8374 105
473d087e
RR
106protected:
107 wxImageList m_ImageList;
108 wxHashTable m_HashTable;
655cf310
VS
109};
110
111static wxFileIconsTable *g_IconsTable = NULL;
112
b0c5c421
VS
113#define FI_FOLDER 0
114#define FI_UNKNOWN 1
115#define FI_EXECUTABLE 2
655cf310
VS
116
117wxFileIconsTable::wxFileIconsTable() :
118 m_ImageList(16, 16),
73725567 119 m_HashTable(wxKEY_STRING)
655cf310
VS
120{
121 m_HashTable.DeleteContents(TRUE);
60d2cc25
VS
122 // FI_FOLDER:
123 m_ImageList.Add(wxArtProvider::GetBitmap(wxART_FOLDER, wxART_CMN_DIALOG));
124 // FI_UNKNOWN:
7a82dabc 125 m_ImageList.Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_CMN_DIALOG));
60d2cc25 126 // FI_EXECUTABLE:
48fe8374 127 if (GetIconID(wxEmptyString, _T("application/x-executable")) == FI_UNKNOWN)
60d2cc25
VS
128 {
129 m_ImageList.Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE, wxART_CMN_DIALOG));
b0c5c421
VS
130 m_HashTable.Delete(_T("exe"));
131 m_HashTable.Put(_T("exe"), new wxFileIconEntry(FI_EXECUTABLE));
132 }
133 /* else put into list by GetIconID
134 (KDE defines application/x-executable for *.exe and has nice icon)
135 */
655cf310
VS
136}
137
138
139
75ec8bd4
VS
140#if wxUSE_MIMETYPE
141// VS: we don't need this function w/o wxMimeTypesManager because we'll only have
142// one icon and we won't resize it
143
655cf310
VS
144static wxBitmap CreateAntialiasedBitmap(const wxImage& img)
145{
a2638e74 146 wxImage smallimg (16, 16);
655cf310 147 unsigned char *p1, *p2, *ps;
48fe8374
VZ
148 unsigned char mr = img.GetMaskRed(),
149 mg = img.GetMaskGreen(),
b0c5c421 150 mb = img.GetMaskBlue();
48fe8374 151
655cf310
VS
152 unsigned x, y;
153 unsigned sr, sg, sb, smask;
48fe8374 154
a2638e74
CE
155 p1 = img.GetData(), p2 = img.GetData() + 3 * 32, ps = smallimg.GetData();
156 smallimg.SetMaskColour(mr, mr, mr);
48fe8374 157
655cf310
VS
158 for (y = 0; y < 16; y++)
159 {
160 for (x = 0; x < 16; x++)
161 {
162 sr = sg = sb = smask = 0;
163 if (p1[0] != mr || p1[1] != mg || p1[2] != mb)
164 sr += p1[0], sg += p1[1], sb += p1[2];
165 else smask++;
166 p1 += 3;
167 if (p1[0] != mr || p1[1] != mg || p1[2] != mb)
168 sr += p1[0], sg += p1[1], sb += p1[2];
169 else smask++;
170 p1 += 3;
171 if (p2[0] != mr || p2[1] != mg || p2[2] != mb)
172 sr += p2[0], sg += p2[1], sb += p2[2];
173 else smask++;
174 p2 += 3;
175 if (p2[0] != mr || p2[1] != mg || p2[2] != mb)
176 sr += p2[0], sg += p2[1], sb += p2[2];
177 else smask++;
178 p2 += 3;
48fe8374
VZ
179
180 if (smask > 2)
655cf310
VS
181 ps[0] = ps[1] = ps[2] = mr;
182 else
183 ps[0] = sr >> 2, ps[1] = sg >> 2, ps[2] = sb >> 2;
184 ps += 3;
185 }
186 p1 += 32 * 3, p2 += 32 * 3;
187 }
78316bbe 188
a2638e74 189 return wxBitmap(smallimg);
655cf310
VS
190}
191
78316bbe
VS
192// finds empty borders and return non-empty area of image:
193static wxImage CutEmptyBorders(const wxImage& img)
194{
48fe8374
VZ
195 unsigned char mr = img.GetMaskRed(),
196 mg = img.GetMaskGreen(),
78316bbe
VS
197 mb = img.GetMaskBlue();
198 unsigned char *dt = img.GetData(), *dttmp;
199 unsigned w = img.GetWidth(), h = img.GetHeight();
48fe8374 200
78316bbe
VS
201 unsigned top, bottom, left, right, i;
202 bool empt;
203
204#define MK_DTTMP(x,y) dttmp = dt + ((x + y * w) * 3)
205#define NOEMPTY_PIX(empt) if (dttmp[0] != mr || dttmp[1] != mg || dttmp[2] != mb) {empt = FALSE; break;}
48fe8374 206
78316bbe
VS
207 for (empt = TRUE, top = 0; empt && top < h; top++)
208 {
209 MK_DTTMP(0, top);
210 for (i = 0; i < w; i++, dttmp+=3)
211 NOEMPTY_PIX(empt)
212 }
213 for (empt = TRUE, bottom = h-1; empt && bottom > top; bottom--)
214 {
215 MK_DTTMP(0, bottom);
216 for (i = 0; i < w; i++, dttmp+=3)
217 NOEMPTY_PIX(empt)
218 }
219 for (empt = TRUE, left = 0; empt && left < w; left++)
220 {
221 MK_DTTMP(left, 0);
222 for (i = 0; i < h; i++, dttmp+=3*w)
223 NOEMPTY_PIX(empt)
224 }
225 for (empt = TRUE, right = w-1; empt && right > left; right--)
226 {
227 MK_DTTMP(right, 0);
228 for (i = 0; i < h; i++, dttmp+=3*w)
229 NOEMPTY_PIX(empt)
230 }
231 top--, left--, bottom++, right++;
232
233 return img.GetSubImage(wxRect(left, top, right - left + 1, bottom - top + 1));
234}
75ec8bd4 235#endif // wxUSE_MIMETYPE
78316bbe
VS
236
237
238
b0c5c421 239int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
655cf310 240{
4894ae18 241#if wxUSE_MIMETYPE
b0c5c421
VS
242 if (!extension.IsEmpty())
243 {
244 wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable.Get(extension);
245 if (entry) return (entry -> id);
246 }
247
48fe8374 248 wxFileType *ft = (mime.IsEmpty()) ?
73725567
VS
249 wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) :
250 wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime);
655cf310 251 wxIcon ic;
26065a88 252 if (ft == NULL || (!ft -> GetIcon(&ic)) || (!ic.Ok()))
655cf310 253 {
b0c5c421 254 int newid = FI_UNKNOWN;
655cf310
VS
255 m_HashTable.Put(extension, new wxFileIconEntry(newid));
256 return newid;
257 }
5eac771d
VS
258
259 wxBitmap tmpBmp;
260 tmpBmp.CopyFromIcon(ic);
261 wxImage img = tmpBmp.ConvertToImage();
262
655cf310 263 delete ft;
48fe8374 264
655cf310
VS
265 int id = m_ImageList.GetImageCount();
266 if (img.GetWidth() == 16 && img.GetHeight() == 16)
368d59f0 267 m_ImageList.Add(wxBitmap(img));
655cf310 268 else
b4b58c41
VS
269 {
270 if (img.GetWidth() != 32 || img.GetHeight() != 32)
78316bbe
VS
271 m_ImageList.Add(CreateAntialiasedBitmap(CutEmptyBorders(img).Rescale(32, 32)));
272 else
273 m_ImageList.Add(CreateAntialiasedBitmap(img));
b4b58c41 274 }
655cf310
VS
275 m_HashTable.Put(extension, new wxFileIconEntry(id));
276 return id;
4894ae18
VS
277
278#else // !wxUSE_MIMETYPE
279
280 if (extension == wxT("exe"))
281 return FI_EXECUTABLE;
282 else
283 return FI_UNKNOWN;
284#endif // wxUSE_MIMETYPE/!wxUSE_MIMETYPE
655cf310
VS
285}
286
287
288
c8c0e54c
VZ
289// ----------------------------------------------------------------------------
290// private functions
291// ----------------------------------------------------------------------------
292
293static
23254b13
JS
294int wxFileDataNameCompare( long data1, long data2, long data)
295{
296 wxFileData *fd1 = (wxFileData*)data1;
297 wxFileData *fd2 = (wxFileData*)data2;
298 if (fd1->GetName() == wxT("..")) return -data;
299 if (fd2->GetName() == wxT("..")) return data;
300 if (fd1->IsDir() && !fd2->IsDir()) return -data;
301 if (fd2->IsDir() && !fd1->IsDir()) return data;
302 return data*wxStrcmp( fd1->GetName(), fd2->GetName() );
303}
304
305static
306int wxFileDataTypeCompare( long data1, long data2, long data)
307{
308 wxFileData *fd1 = (wxFileData*)data1;
309 wxFileData *fd2 = (wxFileData*)data2;
310 if (fd1->GetName() == wxT("..")) return -data;
311 if (fd2->GetName() == wxT("..")) return data;
312 if (fd1->IsDir() && !fd2->IsDir()) return -data;
313 if (fd2->IsDir() && !fd1->IsDir()) return data;
314 if (fd1->IsLink() && !fd2->IsLink()) return -data;
315 if (fd2->IsLink() && !fd1->IsLink()) return data;
316 return data*(fd1->GetSize() - fd2->GetSize());
317}
318
319static
320int wxFileDataTimeCompare( long data1, long data2, long data)
321{
322 wxFileData *fd1 = (wxFileData*)data1;
323 wxFileData *fd2 = (wxFileData*)data2;
324 if (fd1->GetName() == wxT("..")) return -data;
325 if (fd2->GetName() == wxT("..")) return data;
326 if (fd1->IsDir() && !fd2->IsDir()) return -data;
327 if (fd2->IsDir() && !fd1->IsDir()) return data;
328
329 int val = fd1->GetYear() - fd2->GetYear();
330 if (val) return data*val;
331 val = fd1->GetMonth() - fd2->GetMonth();
332 if (val) return data*val;
333 val = fd1->GetDay() - fd2->GetDay();
334 if (val) return data*val;
335 val = fd1->GetHour() - fd2->GetHour();
336 if (val) return data*val;
337 val = fd1->GetMinute() - fd2->GetMinute();
338 return data*val;
c8c0e54c
VZ
339}
340
5e673a6a
VS
341#ifdef __UNIX__
342#define IsTopMostDir(dir) (dir == wxT("/"))
343#endif
344
345#if defined(__DOS__) || defined(__WINDOWS__)
346#define IsTopMostDir(dir) (dir.IsEmpty())
347#endif
348
37fd1c97
VS
349#if defined(__DOS__) || defined(__WINDOWS__)
350extern bool wxIsDriveAvailable(const wxString& dirName);
351#endif
352
8b17ba72
RR
353//-----------------------------------------------------------------------------
354// wxFileData
355//-----------------------------------------------------------------------------
356
23254b13 357wxFileData::wxFileData( const wxString &name, const wxString &fname, fileType type )
8b17ba72
RR
358{
359 m_name = name;
360 m_fileName = fname;
23254b13 361 m_type = type;
7a82dabc 362
37fd1c97
VS
363#if defined(__DOS__) || defined(__WINDOWS__)
364 // VS: In case the file is root directory of a volume (e.g. "C:"),
365 // we don't want it stat()ed, since the drive may not be in:
366 if (name.length() == 2 && name[1u] == wxT(':'))
367 {
23254b13
JS
368 m_type = is_drive;
369 m_size = 0;
370 return;
371 }
372
373 // This is a drive, even if MSW thinks c:\.. is a file
374 if ((name == wxT("..")) && (fname.length() <= 5))
375 {
376 m_type = is_drive;
37fd1c97
VS
377 m_size = 0;
378 return;
379 }
7f04165e 380#endif // __DOS__ || __WINDOWS__
c8c0e54c 381
8115f9e7 382 wxStructStat buff;
479cd5de 383
4894ae18 384#if defined(__UNIX__) && (!defined( __EMX__ ) && !defined(__VMS))
7f04165e 385 lstat( m_fileName.fn_str(), &buff );
23254b13 386 m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0;
7f04165e
VZ
387#else // no lstat()
388 wxStat( m_fileName, &buff );
9f2d09aa
RR
389#endif
390
23254b13
JS
391 m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0;
392 m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0;
8b17ba72
RR
393
394 m_size = buff.st_size;
395
7f04165e 396 const struct tm * const t = localtime( &buff.st_mtime );
8b17ba72
RR
397 m_hour = t->tm_hour;
398 m_minute = t->tm_min;
399 m_month = t->tm_mon+1;
400 m_day = t->tm_mday;
401 m_year = t->tm_year;
d3e90957 402 m_year += 1900;
8b17ba72 403
7f04165e
VZ
404 m_permissions.Printf(_T("%c%c%c"),
405 buff.st_mode & wxS_IRUSR ? _T('r') : _T('-'),
406 buff.st_mode & wxS_IWUSR ? _T('w') : _T('-'),
407 buff.st_mode & wxS_IXUSR ? _T('x') : _T('-'));
8b17ba72
RR
408}
409
410wxString wxFileData::GetName() const
411{
412 return m_name;
413}
414
415wxString wxFileData::GetFullName() const
416{
417 return m_fileName;
418}
419
23254b13
JS
420bool wxFileData::IsDir() const
421{
422 return (m_type & is_dir) != 0;
423}
424bool wxFileData::IsLink() const
425{
426 return (m_type & is_link) != 0;
427}
428bool wxFileData::IsExe() const
429{
430 return (m_type & is_exe) != 0;
431}
432bool wxFileData::IsDrive() const
433{
434 return (m_type & is_drive) != 0;
435}
436
8b17ba72
RR
437wxString wxFileData::GetHint() const
438{
439 wxString s = m_fileName;
2b5f62a0 440 s += wxT(" ");
23254b13
JS
441 if (IsDir())
442 s += wxT("<DIR> ");
443 else if (IsLink())
444 s += wxT("<LINK> ");
445 else if (IsDrive())
446 {
447 s += wxT("<DRIVE> ");
448 return s;
449 }
8b17ba72
RR
450 else
451 {
452 s += LongToString( m_size );
2b5f62a0 453 s += wxT(" bytes ");
8b17ba72 454 }
23254b13 455
8b17ba72 456 s += IntToString( m_day );
223d09f6 457 s += wxT(".");
8b17ba72 458 s += IntToString( m_month );
223d09f6 459 s += wxT(".");
8b17ba72 460 s += IntToString( m_year );
223d09f6 461 s += wxT(" ");
8b17ba72 462 s += IntToString( m_hour );
223d09f6 463 s += wxT(":");
8b17ba72 464 s += IntToString( m_minute );
223d09f6 465 s += wxT(" ");
8b17ba72
RR
466 s += m_permissions;
467 return s;
468};
469
23254b13 470wxString wxFileData::GetEntry( fileListFieldType num ) const
8b17ba72
RR
471{
472 wxString s;
9cedab37 473 switch ( num )
8b17ba72 474 {
9cedab37 475 case FileList_Name:
8b17ba72 476 s = m_name;
8b17ba72 477 break;
9cedab37
VZ
478
479 case FileList_Type:
23254b13 480 if (IsDir())
9cedab37 481 s = _("<DIR>");
23254b13 482 else if (IsLink())
9cedab37 483 s = _("<LINK>");
23254b13
JS
484 else if (IsDrive())
485 s = _("<DRIVE>");
9cedab37
VZ
486 else
487 s.Printf(_T("%ld"), m_size);
8b17ba72 488 break;
9cedab37
VZ
489
490 case FileList_Date:
23254b13 491 if (!IsDrive())
9cedab37 492 s.Printf(_T("%02d.%02d.%d"), m_day, m_month, m_year);
8b17ba72 493 break;
8b17ba72 494
9cedab37 495 case FileList_Time:
23254b13 496 if (!IsDrive())
9cedab37
VZ
497 s.Printf(_T("%02d:%02d"), m_hour, m_minute);
498 break;
8b17ba72 499
9cedab37
VZ
500#ifdef __UNIX__
501 case FileList_Perm:
502 s = m_permissions;
503 break;
504#endif // __UNIX__
8b17ba72 505
9cedab37
VZ
506 default:
507 wxFAIL_MSG( _T("unexpected field in wxFileData::GetEntry()") );
508 }
8b17ba72 509
9cedab37 510 return s;
8b17ba72
RR
511}
512
0b855868 513void wxFileData::SetNewName( const wxString &name, const wxString &fname )
8b17ba72 514{
0b855868
RR
515 m_name = name;
516 m_fileName = fname;
8b17ba72
RR
517}
518
519void wxFileData::MakeItem( wxListItem &item )
520{
521 item.m_text = m_name;
9b00bb16 522 item.ClearAttributes();
9cedab37
VZ
523 if (IsExe())
524 item.SetTextColour(*wxRED);
525 if (IsDir())
526 item.SetTextColour(*wxBLUE);
48fe8374 527
655cf310 528 if (IsDir())
b0c5c421 529 item.m_image = FI_FOLDER;
23254b13
JS
530 if (IsDrive()) // FIXME - add icons for drives, see wxDirCtrl
531 item.m_image = FI_FOLDER;
48fe8374 532 else if (IsExe())
b0c5c421 533 item.m_image = FI_EXECUTABLE;
655cf310 534 else if (m_name.Find(wxT('.')) != wxNOT_FOUND)
37fd1c97 535 item.m_image = g_IconsTable->GetIconID(m_name.AfterLast(wxT('.')));
655cf310 536 else
b0c5c421 537 item.m_image = FI_UNKNOWN;
655cf310 538
8b17ba72
RR
539 if (IsLink())
540 {
9cedab37 541 wxColour *dg = wxTheColourDatabase->FindColour( _T("MEDIUM GREY") );
aaa37c0d 542 item.SetTextColour(*dg);
8b17ba72
RR
543 }
544 item.m_data = (long)this;
545}
c8c0e54c 546
8b17ba72
RR
547//-----------------------------------------------------------------------------
548// wxFileCtrl
549//-----------------------------------------------------------------------------
550
d84afea9 551IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl)
8b17ba72
RR
552
553BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
0b855868
RR
554 EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
555 EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
23254b13 556 EVT_LIST_COL_CLICK(-1, wxFileCtrl::OnListColClick)
8b17ba72
RR
557END_EVENT_TABLE()
558
655cf310 559
8b17ba72
RR
560wxFileCtrl::wxFileCtrl()
561{
8b17ba72 562 m_showHidden = FALSE;
23254b13
JS
563 m_goToParentControl = NULL;
564 m_newDirControl = NULL;
565 m_sort_foward = 1;
566 m_sort_field = wxFileData::FileList_Name;
8b17ba72
RR
567}
568
9cedab37
VZ
569wxFileCtrl::wxFileCtrl(wxWindow *win,
570 wxWindowID id,
571 const wxString& wild,
572 bool showHidden,
573 const wxPoint& pos,
574 const wxSize& size,
575 long style,
576 const wxValidator &validator,
5e673a6a 577 const wxString &name)
9cedab37
VZ
578 : wxListCtrl(win, id, pos, size, style, validator, name),
579 m_wild(wild)
8b17ba72 580{
7a82dabc 581 if (! g_IconsTable)
5e673a6a 582 g_IconsTable = new wxFileIconsTable;
37fd1c97 583 wxImageList *imageList = g_IconsTable->GetImageList();
655cf310 584
0b855868 585 SetImageList( imageList, wxIMAGE_LIST_SMALL );
c8c0e54c 586
9cedab37
VZ
587 m_goToParentControl =
588 m_newDirControl = NULL;
37fd1c97 589
9cedab37 590 m_showHidden = showHidden;
23254b13
JS
591
592 m_sort_foward = 1;
593 m_sort_field = wxFileData::FileList_Name;
594
595 m_dirName = wxT("*");
596
597 if (style & wxLC_REPORT)
598 ChangeToReportMode();
8b17ba72
RR
599}
600
601void wxFileCtrl::ChangeToListMode()
602{
23254b13 603 ClearAll();
8b17ba72 604 SetSingleStyle( wxLC_LIST );
8f4fcc4e 605 UpdateFiles();
8b17ba72
RR
606}
607
608void wxFileCtrl::ChangeToReportMode()
609{
23254b13 610 ClearAll();
8b17ba72 611 SetSingleStyle( wxLC_REPORT );
23254b13
JS
612
613 int w, h;
614 GetTextExtent(wxT("CCCCCCCCC"), &w, &h);
615
616 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT, w*2 );
617 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, w );
618 InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT, w );
619 InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT, w/2 );
620#ifdef __UNIX__
621 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, (w*12)/9 );
622#endif
623
8f4fcc4e 624 UpdateFiles();
8b17ba72
RR
625}
626
627void wxFileCtrl::ChangeToIconMode()
628{
23254b13 629 ClearAll();
8b17ba72 630 SetSingleStyle( wxLC_ICON );
8f4fcc4e 631 UpdateFiles();
8b17ba72
RR
632}
633
634void wxFileCtrl::ShowHidden( bool show )
635{
636 m_showHidden = show;
8f4fcc4e 637 UpdateFiles();
8b17ba72
RR
638}
639
0b855868
RR
640long wxFileCtrl::Add( wxFileData *fd, wxListItem &item )
641{
642 long ret = -1;
643 item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE;
644 fd->MakeItem( item );
645 long my_style = GetWindowStyleFlag();
646 if (my_style & wxLC_REPORT)
647 {
648 ret = InsertItem( item );
23254b13
JS
649 for (int i = 1; i < wxFileData::FileList_Max; i++)
650 SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) );
0b855868
RR
651 }
652 else if (my_style & wxLC_LIST)
653 {
654 ret = InsertItem( item );
c8c0e54c 655 }
0b855868
RR
656 return ret;
657}
658
8f4fcc4e 659void wxFileCtrl::UpdateFiles()
c8c0e54c 660{
2b5f62a0 661 // don't do anything before ShowModal() call which sets m_dirName
23254b13 662 if ( m_dirName == wxT("*") )
2b5f62a0
VZ
663 return;
664
37fd1c97 665 wxBusyCursor bcur; // this may take a while...
7a82dabc 666
7a82dabc 667 FreeAllItemsData();
23254b13 668 DeleteAllItems();
7a82dabc 669
8b17ba72
RR
670 wxFileData *fd = (wxFileData *) NULL;
671 wxListItem item;
8b17ba72
RR
672 item.m_itemId = 0;
673 item.m_col = 0;
0b855868 674
5e673a6a 675#if defined(__DOS__) || defined(__WINDOWS__)
37fd1c97 676 if ( IsTopMostDir(m_dirName) )
7a82dabc 677 {
5e673a6a 678 // Pseudo-directory with all available drives listed...
37fd1c97
VS
679 for (int drive = 1; drive <= 26; drive++)
680 {
681 wxString path;
682 path.Printf(wxT("%c:\\"), (char)(drive + 'A' - 1));
683 if ( wxIsDriveAvailable(path) )
684 {
685 path.RemoveLast();
23254b13 686 fd = new wxFileData(path, path, wxFileData::is_drive);
37fd1c97
VS
687 Add(fd, item);
688 item.m_itemId++;
689 }
690 }
0b855868 691 }
5e673a6a 692 else
75ec8bd4 693#endif
8b17ba72 694 {
5e673a6a
VS
695 // Real directory...
696 if ( !IsTopMostDir(m_dirName) )
8b17ba72 697 {
5e673a6a
VS
698 wxString p(wxPathOnly(m_dirName));
699#ifdef __UNIX__
700 if (p.IsEmpty()) p = wxT("/");
701#endif
23254b13 702 fd = new wxFileData( wxT(".."), p, wxFileData::is_dir );
5e673a6a 703 Add(fd, item);
8b17ba72
RR
704 item.m_itemId++;
705 }
c8c0e54c 706
5e673a6a
VS
707 wxString dirname(m_dirName);
708#if defined(__DOS__) || defined(__WINDOWS__)
709 if (dirname.length() == 2 && dirname[1u] == wxT(':'))
710 dirname << wxT('\\');
711#endif
712 wxDir dir(dirname);
713
714 if ( dir.IsOpened() )
cae5359f 715 {
23254b13
JS
716 wxString dirPrefix(dirname);
717 if (dirPrefix.Last() != wxFILE_SEP_PATH)
718 dirPrefix += wxFILE_SEP_PATH;
719
5e673a6a 720 int hiddenFlag = m_showHidden ? wxDIR_HIDDEN : 0;
7a82dabc 721
5e673a6a
VS
722 bool cont;
723 wxString f;
724
725 // Get the directories first (not matched against wildcards):
726 cont = dir.GetFirst(&f, wxEmptyString, wxDIR_DIRS | hiddenFlag);
727 while (cont)
551adc4b 728 {
23254b13 729 fd = new wxFileData(f, dirPrefix + f, wxFileData::is_dir);
5e673a6a 730 Add(fd, item);
551adc4b 731 item.m_itemId++;
5e673a6a
VS
732 cont = dir.GetNext(&f);
733 }
734
7a82dabc 735 // Tokenize the wildcard string, so we can handle more than 1
5e673a6a
VS
736 // search pattern in a wildcard.
737 wxStringTokenizer tokenWild(m_wild, wxT(";"));
738 while ( tokenWild.HasMoreTokens() )
739 {
7a82dabc 740 cont = dir.GetFirst(&f, tokenWild.GetNextToken(),
5e673a6a
VS
741 wxDIR_FILES | hiddenFlag);
742 while (cont)
743 {
23254b13 744 fd = new wxFileData(f, dirPrefix + f, wxFileData::is_file);
5e673a6a
VS
745 Add(fd, item);
746 item.m_itemId++;
747 cont = dir.GetNext(&f);
748 }
551adc4b 749 }
cae5359f 750 }
cae5359f 751 }
c8c0e54c 752
23254b13 753 SortItems(m_sort_field, m_sort_foward > 0);
7a82dabc 754
37fd1c97
VS
755 // Finally, enable/disable context-dependent controls:
756 if ( m_goToParentControl )
757 m_goToParentControl->Enable(!IsTopMostDir(m_dirName));
758#if defined(__DOS__) || defined(__WINDOWS__)
759 if ( m_newDirControl )
760 m_newDirControl->Enable(!IsTopMostDir(m_dirName));
761#endif
8b17ba72
RR
762}
763
0b855868 764void wxFileCtrl::SetWild( const wxString &wild )
8b17ba72 765{
0b855868 766 m_wild = wild;
8f4fcc4e 767 UpdateFiles();
0b855868
RR
768}
769
770void wxFileCtrl::MakeDir()
771{
5e673a6a 772 wxString new_name( _("NewName") );
0b855868 773 wxString path( m_dirName );
75ec8bd4 774 path += wxFILE_SEP_PATH;
0b855868
RR
775 path += new_name;
776 if (wxFileExists(path))
8b17ba72 777 {
0b855868
RR
778 // try NewName0, NewName1 etc.
779 int i = 0;
c8c0e54c 780 do {
0b855868 781 new_name = _("NewName");
c8c0e54c 782 wxString num;
223d09f6 783 num.Printf( wxT("%d"), i );
c8c0e54c
VZ
784 new_name += num;
785
0b855868 786 path = m_dirName;
75ec8bd4 787 path += wxFILE_SEP_PATH;
0b855868 788 path += new_name;
c8c0e54c
VZ
789 i++;
790 } while (wxFileExists(path));
8b17ba72 791 }
c8c0e54c 792
0b855868 793 wxLogNull log;
c8c0e54c 794 if (!wxMkdir(path))
8b17ba72 795 {
0b855868 796 wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
c8c0e54c 797 dialog.ShowModal();
0b855868 798 return;
8b17ba72 799 }
8b17ba72 800
23254b13 801 wxFileData *fd = new wxFileData( new_name, path, wxFileData::is_dir );
0b855868
RR
802 wxListItem item;
803 item.m_itemId = 0;
804 item.m_col = 0;
13111b2a 805 long id = Add( fd, item );
c8c0e54c 806
0b855868
RR
807 if (id != -1)
808 {
23254b13 809 SortItems(m_sort_field, m_sort_foward > 0);
c8c0e54c 810 id = FindItem( 0, (long)fd );
0b855868
RR
811 EnsureVisible( id );
812 EditLabel( id );
813 }
8b17ba72
RR
814}
815
816void wxFileCtrl::GoToParentDir()
817{
5e673a6a 818 if (!IsTopMostDir(m_dirName))
8b17ba72 819 {
353f41cb 820 size_t len = m_dirName.Len();
083f7497 821 if (wxEndsWithPathSeparator(m_dirName))
353f41cb 822 m_dirName.Remove( len-1, 1 );
c8c0e54c 823 wxString fname( wxFileNameFromPath(m_dirName) );
0b855868 824 m_dirName = wxPathOnly( m_dirName );
23254b13
JS
825#if defined(__DOS__) || defined(__WINDOWS__)
826 if (!m_dirName.IsEmpty())
827 {
828 if (m_dirName.Last() == wxT('.'))
829 m_dirName = wxT("");
830 }
831#elif defined(__UNIX__)
7a82dabc 832 if (m_dirName.IsEmpty())
5e673a6a
VS
833 m_dirName = wxT("/");
834#endif
8f4fcc4e 835 UpdateFiles();
13111b2a 836 long id = FindItem( 0, fname );
c8c0e54c
VZ
837 if (id != -1)
838 {
839 SetItemState( id, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
840 EnsureVisible( id );
841 }
8b17ba72
RR
842 }
843}
844
845void wxFileCtrl::GoToHomeDir()
846{
847 wxString s = wxGetUserHome( wxString() );
5e673a6a 848 GoToDir(s);
8b17ba72
RR
849}
850
851void wxFileCtrl::GoToDir( const wxString &dir )
852{
853 m_dirName = dir;
8f4fcc4e 854 UpdateFiles();
e6daf794
RR
855 SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
856 EnsureVisible( 0 );
8b17ba72
RR
857}
858
859void wxFileCtrl::GetDir( wxString &dir )
860{
861 dir = m_dirName;
862}
863
7a82dabc 864void wxFileCtrl::FreeItemData(const wxListItem& item)
8b17ba72 865{
7a82dabc 866 wxFileData *fd = (wxFileData*)item.m_data;
8b17ba72
RR
867 delete fd;
868}
869
7a82dabc
VZ
870void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
871{
872 FreeItemData(event.m_item);
873}
874
875void wxFileCtrl::FreeAllItemsData()
12c1b46a
RR
876{
877 wxListItem item;
878 item.m_mask = wxLIST_MASK_DATA;
879
880 item.m_itemId = GetNextItem( -1, wxLIST_NEXT_ALL );
92da8bde 881 while ( item.m_itemId != -1 )
12c1b46a
RR
882 {
883 GetItem( item );
7a82dabc 884 FreeItemData(item);
12c1b46a
RR
885 item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL );
886 }
887}
888
0b855868 889void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event )
8b17ba72
RR
890{
891 wxFileData *fd = (wxFileData*)event.m_item.m_data;
0b855868 892 wxASSERT( fd );
c8c0e54c 893
0b855868
RR
894 if ((event.GetLabel().IsEmpty()) ||
895 (event.GetLabel() == _(".")) ||
896 (event.GetLabel() == _("..")) ||
75ec8bd4 897 (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND))
8b17ba72 898 {
0b855868 899 wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
c8c0e54c 900 dialog.ShowModal();
0b855868 901 event.Veto();
c8c0e54c 902 return;
8b17ba72 903 }
c8c0e54c 904
0b855868 905 wxString new_name( wxPathOnly( fd->GetFullName() ) );
75ec8bd4 906 new_name += wxFILE_SEP_PATH;
0b855868 907 new_name += event.GetLabel();
c8c0e54c 908
0b855868 909 wxLogNull log;
c8c0e54c 910
0b855868 911 if (wxFileExists(new_name))
8b17ba72 912 {
0b855868 913 wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
c8c0e54c 914 dialog.ShowModal();
0b855868 915 event.Veto();
8b17ba72 916 }
c8c0e54c 917
0b855868 918 if (wxRenameFile(fd->GetFullName(),new_name))
8b17ba72 919 {
0b855868 920 fd->SetNewName( new_name, event.GetLabel() );
c8c0e54c 921 SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
0b855868 922 EnsureVisible( event.GetItem() );
8b17ba72
RR
923 }
924 else
925 {
0b855868 926 wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
c8c0e54c 927 dialog.ShowModal();
0b855868 928 event.Veto();
8b17ba72 929 }
8b17ba72
RR
930}
931
23254b13
JS
932void wxFileCtrl::OnListColClick( wxListEvent &event )
933{
934 int col = event.GetColumn();
935
936 switch (col)
937 {
938 case wxFileData::FileList_Name :
939 case wxFileData::FileList_Type :
940 case wxFileData::FileList_Date :
941 case wxFileData::FileList_Time : break;
942 default : return;
943 }
944
945 if ((wxFileData::fileListFieldType)col == m_sort_field)
946 m_sort_foward = -m_sort_foward;
947 else
948 m_sort_field = (wxFileData::fileListFieldType)col;
949
950 SortItems(m_sort_field, m_sort_foward > 0);
951}
952
953void wxFileCtrl::SortItems(wxFileData::fileListFieldType field, bool foward)
954{
955 m_sort_field = field;
956 m_sort_foward = foward ? 1 : -1;
957
958 switch (m_sort_field)
959 {
960 case wxFileData::FileList_Name :
961 {
962 wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataNameCompare, m_sort_foward);
963 break;
964 }
965 case wxFileData::FileList_Type :
966 {
967 wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTypeCompare, m_sort_foward);
968 break;
969 }
970 case wxFileData::FileList_Date :
971 case wxFileData::FileList_Time :
972 {
973 wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTimeCompare, m_sort_foward);
974 break;
975 }
976 default : break;
977 }
978}
979
7a82dabc
VZ
980wxFileCtrl::~wxFileCtrl()
981{
982 FreeAllItemsData();
983}
984
8b17ba72 985//-----------------------------------------------------------------------------
23254b13 986// wxGenericFileDialog
8b17ba72
RR
987//-----------------------------------------------------------------------------
988
5e673a6a
VS
989#define ID_LIST_MODE (wxID_FILEDLGG )
990#define ID_REPORT_MODE (wxID_FILEDLGG + 1)
991#define ID_UP_DIR (wxID_FILEDLGG + 5)
992#define ID_PARENT_DIR (wxID_FILEDLGG + 6)
993#define ID_NEW_DIR (wxID_FILEDLGG + 7)
994#define ID_CHOICE (wxID_FILEDLGG + 8)
995#define ID_TEXT (wxID_FILEDLGG + 9)
996#define ID_LIST_CTRL (wxID_FILEDLGG + 10)
997#define ID_ACTIVATED (wxID_FILEDLGG + 11)
998#define ID_CHECK (wxID_FILEDLGG + 12)
8b17ba72 999
23254b13
JS
1000IMPLEMENT_DYNAMIC_CLASS(wxGenericFileDialog,wxDialog)
1001
1002BEGIN_EVENT_TABLE(wxGenericFileDialog,wxDialog)
1003 EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList)
1004 EVT_BUTTON(ID_REPORT_MODE, wxGenericFileDialog::OnReport)
1005 EVT_BUTTON(ID_UP_DIR, wxGenericFileDialog::OnUp)
1006 EVT_BUTTON(ID_PARENT_DIR, wxGenericFileDialog::OnHome)
1007 EVT_BUTTON(ID_NEW_DIR, wxGenericFileDialog::OnNew)
1008 EVT_BUTTON(wxID_OK, wxGenericFileDialog::OnListOk)
1009 EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxGenericFileDialog::OnSelected)
1010 EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxGenericFileDialog::OnActivated)
1011 EVT_CHOICE(ID_CHOICE,wxGenericFileDialog::OnChoiceFilter)
1012 EVT_TEXT_ENTER(ID_TEXT,wxGenericFileDialog::OnTextEnter)
1013 EVT_TEXT(ID_TEXT,wxGenericFileDialog::OnTextChange)
1014 EVT_CHECKBOX(ID_CHECK,wxGenericFileDialog::OnCheck)
8b17ba72
RR
1015END_EVENT_TABLE()
1016
23254b13
JS
1017long wxGenericFileDialog::ms_lastViewStyle = wxLC_LIST;
1018bool wxGenericFileDialog::ms_lastShowHidden = FALSE;
655cf310 1019
23254b13 1020wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
9cedab37
VZ
1021 const wxString& message,
1022 const wxString& defaultDir,
1023 const wxString& defaultFile,
1024 const wxString& wildCard,
1025 long style,
1026 const wxPoint& pos )
1027 : wxDialog( parent, -1, message, pos, wxDefaultSize,
1028 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
8b17ba72 1029{
eaf40b23
VS
1030 if (wxConfig::Get(FALSE))
1031 {
7a82dabc 1032 wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"),
9cedab37 1033 &ms_lastViewStyle);
7a82dabc 1034 wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ShowHidden"),
9cedab37 1035 &ms_lastShowHidden);
eaf40b23
VS
1036 }
1037
8b17ba72
RR
1038 m_message = message;
1039 m_dialogStyle = style;
479cd5de 1040
9cedab37
VZ
1041 if (m_dialogStyle == 0)
1042 m_dialogStyle = wxOPEN;
7941ba11 1043 if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN))
9b00bb16 1044 m_dialogStyle |= wxOPEN;
479cd5de 1045
8b17ba72 1046 m_dir = defaultDir;
353f41cb 1047 if ((m_dir.empty()) || (m_dir == wxT(".")))
ac2def68 1048 {
75ec8bd4 1049 m_dir = wxGetCwd();
ac2def68 1050 }
7a82dabc 1051
353f41cb 1052 size_t len = m_dir.Len();
083f7497 1053 if ((len > 1) && (wxEndsWithPathSeparator(m_dir)))
353f41cb
RR
1054 m_dir.Remove( len-1, 1 );
1055
1056 m_path = m_dir;
75ec8bd4 1057 m_path += wxFILE_SEP_PATH;
8b17ba72
RR
1058 m_path += defaultFile;
1059 m_fileName = defaultFile;
1060 m_wildCard = wildCard;
1061 m_filterIndex = 0;
655cf310 1062 m_filterExtension = wxEmptyString;
c8c0e54c 1063
cae5359f 1064 // interpret wildcards
c8c0e54c 1065
cae5359f
RR
1066 if (m_wildCard.IsEmpty())
1067 m_wildCard = _("All files (*)|*");
c8c0e54c 1068
223d09f6 1069 wxStringTokenizer tokens( m_wildCard, wxT("|") );
cae5359f
RR
1070 wxString firstWild;
1071 wxString firstWildText;
1072 if (tokens.CountTokens() == 1)
1073 {
1074 firstWildText = tokens.GetNextToken();
1075 firstWild = firstWildText;
1076 }
1077 else
1078 {
223d09f6 1079 wxASSERT_MSG( tokens.CountTokens() % 2 == 0, wxT("Wrong file type descripition") );
cae5359f
RR
1080 firstWildText = tokens.GetNextToken();
1081 firstWild = tokens.GetNextToken();
1082 }
655cf310
VS
1083 if ( firstWild.Left( 2 ) == wxT("*.") )
1084 m_filterExtension = firstWild.Mid( 1 );
2b5f62a0
VZ
1085 if ( m_filterExtension == wxT(".*") )
1086 m_filterExtension = wxEmptyString;
cae5359f
RR
1087
1088 // layout
2b5f62a0
VZ
1089
1090 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
c8c0e54c 1091
8b17ba72 1092 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
c8c0e54c 1093
8b17ba72 1094 wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
c8c0e54c 1095
e6daf794 1096 wxBitmapButton *but;
c8c0e54c 1097
7a82dabc 1098 but = new wxBitmapButton(this, ID_LIST_MODE,
60d2cc25 1099 wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_CMN_DIALOG));
e6daf794
RR
1100#if wxUSE_TOOLTIPS
1101 but->SetToolTip( _("View files as a list view") );
1102#endif
1103 buttonsizer->Add( but, 0, wxALL, 5 );
c8c0e54c 1104
60d2cc25
VS
1105 but = new wxBitmapButton(this, ID_REPORT_MODE,
1106 wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_CMN_DIALOG));
e6daf794
RR
1107#if wxUSE_TOOLTIPS
1108 but->SetToolTip( _("View files as a detailed view") );
1109#endif
1110 buttonsizer->Add( but, 0, wxALL, 5 );
c8c0e54c 1111
0b855868 1112 buttonsizer->Add( 30, 5, 1 );
e6daf794 1113
7a82dabc 1114 wxWindow *butDirUp =
60d2cc25
VS
1115 new wxBitmapButton(this, ID_UP_DIR,
1116 wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_CMN_DIALOG));
e6daf794 1117#if wxUSE_TOOLTIPS
37fd1c97 1118 butDirUp->SetToolTip( _("Go to parent directory") );
e6daf794 1119#endif
37fd1c97 1120 buttonsizer->Add( butDirUp, 0, wxALL, 5 );
c8c0e54c 1121
37fd1c97 1122#ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS...
60d2cc25
VS
1123 but = new wxBitmapButton(this, ID_PARENT_DIR,
1124 wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_CMN_DIALOG));
e6daf794
RR
1125#if wxUSE_TOOLTIPS
1126 but->SetToolTip( _("Go to home directory") );
1127#endif
1128 buttonsizer->Add( but, 0, wxALL, 5);
c8c0e54c 1129
e6daf794 1130 buttonsizer->Add( 20, 20 );
75ec8bd4 1131#endif //!__DOS__
c8c0e54c 1132
7a82dabc 1133 wxWindow *butNewDir =
60d2cc25
VS
1134 new wxBitmapButton(this, ID_NEW_DIR,
1135 wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_CMN_DIALOG));
e6daf794 1136#if wxUSE_TOOLTIPS
37fd1c97 1137 butNewDir->SetToolTip( _("Create new directory") );
e6daf794 1138#endif
37fd1c97 1139 buttonsizer->Add( butNewDir, 0, wxALL, 5 );
c8c0e54c 1140
2b5f62a0 1141 if (is_pda)
c15521c6
RR
1142 mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 0 );
1143 else
1144 mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 );
c8c0e54c 1145
9c884972 1146 wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL );
2b5f62a0 1147 if (is_pda)
c15521c6 1148 staticsizer->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT, 10 );
9c884972
RR
1149 m_static = new wxStaticText( this, -1, m_dir );
1150 staticsizer->Add( m_static, 1 );
1151 mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 );
1152
cd6b752b 1153 long style2 = ms_lastViewStyle | wxSUNKEN_BORDER;
9cedab37 1154 if ( !(m_dialogStyle & wxMULTIPLE) )
cd6b752b 1155 style2 |= wxLC_SINGLE_SEL;
9cedab37 1156
23254b13 1157 m_list = new wxFileCtrl( this, ID_LIST_CTRL,
2b5f62a0 1158 firstWild, ms_lastShowHidden,
9cedab37 1159 wxDefaultPosition, wxSize(540,200),
cd6b752b 1160 style2);
9cedab37 1161
37fd1c97
VS
1162 m_list->SetNewDirControl(butNewDir);
1163 m_list->SetGoToParentControl(butDirUp);
24f932d2 1164
2b5f62a0 1165 if (is_pda)
c15521c6 1166 {
41fecb44
VS
1167 // PDAs have a different screen layout
1168 mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 );
1169
1170 wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
1171 m_choice = new wxChoice( this, ID_CHOICE );
1172 choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 5 );
1173 mainsizer->Add( choicesizer, 0, wxEXPAND );
1174
1175 wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
1176 m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER );
1177 textsizer->Add( m_text, 1, wxCENTER | wxALL, 5 );
1178 mainsizer->Add( textsizer, 0, wxEXPAND );
1179
1180 m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") );
9cedab37 1181 m_check->SetValue( ms_lastShowHidden );
41fecb44
VS
1182 textsizer->Add( m_check, 0, wxCENTER|wxALL, 5 );
1183
1184 buttonsizer = new wxBoxSizer( wxHORIZONTAL );
1185 buttonsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxCENTER | wxALL, 5 );
1186 buttonsizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxCENTER | wxALL, 5 );
1187 mainsizer->Add( buttonsizer, 0, wxALIGN_RIGHT );
c15521c6
RR
1188 }
1189 else
1190 {
41fecb44
VS
1191 mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 );
1192
1193 wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
1194 m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER );
1195 textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
1196 textsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
1197 mainsizer->Add( textsizer, 0, wxEXPAND );
1198
1199 wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
1200 m_choice = new wxChoice( this, ID_CHOICE );
1201 choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 );
1202 m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") );
9cedab37 1203 m_check->SetValue( ms_lastShowHidden );
41fecb44
VS
1204 choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 );
1205 choicesizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxCENTER | wxALL, 10 );
1206 mainsizer->Add( choicesizer, 0, wxEXPAND );
c15521c6 1207 }
24f932d2 1208
cae5359f
RR
1209 m_choice->Append( firstWildText, (void*) new wxString( firstWild ) );
1210 while (tokens.HasMoreTokens())
1211 {
1212 firstWildText = tokens.GetNextToken();
1213 firstWild = tokens.GetNextToken();
1214 m_choice->Append( firstWildText, (void*) new wxString( firstWild ) );
1215 }
1216 m_choice->SetSelection( 0 );
8b17ba72
RR
1217
1218 SetAutoLayout( TRUE );
1219 SetSizer( mainsizer );
c8c0e54c 1220
8b17ba72
RR
1221 mainsizer->Fit( this );
1222 mainsizer->SetSizeHints( this );
48fe8374 1223
8b17ba72 1224 Centre( wxBOTH );
ed58dbea 1225
9cedab37 1226 m_text->SetFocus();
8b17ba72
RR
1227}
1228
23254b13 1229wxGenericFileDialog::~wxGenericFileDialog()
cae5359f 1230{
eaf40b23
VS
1231 if (wxConfig::Get(FALSE))
1232 {
5e673a6a 1233 wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"),
9cedab37 1234 ms_lastViewStyle);
5e673a6a 1235 wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"),
9cedab37 1236 ms_lastShowHidden);
eaf40b23 1237 }
c5ef41d3
VZ
1238
1239 const int count = m_choice->GetCount();
1240 for ( int i = 0; i < count; i++ )
1241 {
1242 delete (wxString *)m_choice->GetClientData(i);
1243 }
cae5359f
RR
1244}
1245
23254b13 1246int wxGenericFileDialog::ShowModal()
9cedab37
VZ
1247{
1248 m_list->GoToDir(m_dir);
23254b13 1249 m_static->SetLabel(m_list->GetDir());
2b5f62a0 1250 m_text->SetValue(m_fileName);
9cedab37
VZ
1251
1252 return wxDialog::ShowModal();
1253}
1254
23254b13 1255void wxGenericFileDialog::DoSetFilterIndex(int filterindex)
2b5f62a0
VZ
1256{
1257 wxString *str = (wxString*) m_choice->GetClientData( filterindex );
1258 m_list->SetWild( *str );
1259 m_filterIndex = filterindex;
1260 if ( str->Left(2) == wxT("*.") )
1261 {
787d22ec
JS
1262 m_filterExtension = str->Mid(1);
1263 if (m_filterExtension == _T(".*"))
2b5f62a0
VZ
1264 m_filterExtension.clear();
1265 }
1266 else
1267 {
1268 m_filterExtension.clear();
1269 }
1270}
1271
23254b13 1272void wxGenericFileDialog::SetFilterIndex( int filterindex )
04ea7f93
RR
1273{
1274 m_choice->SetSelection( filterindex );
2b5f62a0
VZ
1275
1276 DoSetFilterIndex(filterindex);
04ea7f93
RR
1277}
1278
23254b13 1279void wxGenericFileDialog::OnChoiceFilter( wxCommandEvent &event )
cae5359f 1280{
2b5f62a0 1281 DoSetFilterIndex((int)event.GetInt());
cae5359f
RR
1282}
1283
23254b13 1284void wxGenericFileDialog::OnCheck( wxCommandEvent &event )
bf9e3e73 1285{
9cedab37 1286 m_list->ShowHidden( (ms_lastShowHidden = event.GetInt() != 0) );
bf9e3e73
RR
1287}
1288
23254b13 1289void wxGenericFileDialog::OnActivated( wxListEvent &event )
8b17ba72 1290{
e1811a01 1291 HandleAction( event.m_item.m_text );
8b17ba72
RR
1292}
1293
23254b13 1294void wxGenericFileDialog::OnTextEnter( wxCommandEvent &WXUNUSED(event) )
cae5359f
RR
1295{
1296 wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
1297 cevent.SetEventObject( this );
1298 GetEventHandler()->ProcessEvent( cevent );
1299}
1300
df413171
JS
1301static bool ignoreChanges = FALSE;
1302
23254b13 1303void wxGenericFileDialog::OnTextChange( wxCommandEvent &WXUNUSED(event) )
df413171
JS
1304{
1305 if (!ignoreChanges)
1306 {
1307 // Clear selections. Otherwise when the user types in a value they may
1308 // not get the file whose name they typed.
1309 if (m_list->GetSelectedItemCount() > 0)
1310 {
7f04165e 1311 long item = m_list->GetNextItem(-1, wxLIST_NEXT_ALL,
df413171
JS
1312 wxLIST_STATE_SELECTED);
1313 while ( item != -1 )
7f04165e 1314 {
df413171
JS
1315 m_list->SetItemState(item,0, wxLIST_STATE_SELECTED);
1316 item = m_list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
7f04165e 1317 }
df413171
JS
1318 }
1319 }
1320}
1321
23254b13 1322void wxGenericFileDialog::OnSelected( wxListEvent &event )
8b17ba72 1323{
e1811a01 1324 wxString filename( event.m_item.m_text );
223d09f6 1325 if (filename == wxT("..")) return;
479cd5de 1326
e1811a01
RR
1327 wxString dir;
1328 m_list->GetDir( dir );
5e673a6a
VS
1329 if (!IsTopMostDir(dir))
1330 dir += wxFILE_SEP_PATH;
e1811a01
RR
1331 dir += filename;
1332 if (wxDirExists(dir)) return;
479cd5de 1333
df413171 1334 ignoreChanges = TRUE;
e1811a01 1335 m_text->SetValue( filename );
df413171 1336 ignoreChanges = FALSE;
8b17ba72
RR
1337}
1338
23254b13 1339void wxGenericFileDialog::HandleAction( const wxString &fn )
8b17ba72 1340{
e1811a01 1341 wxString filename( fn );
8b17ba72
RR
1342 wxString dir;
1343 m_list->GetDir( dir );
1344 if (filename.IsEmpty()) return;
223d09f6 1345 if (filename == wxT(".")) return;
c8c0e54c 1346
223d09f6 1347 if (filename == wxT(".."))
0b855868
RR
1348 {
1349 m_list->GoToParentDir();
1350 m_list->SetFocus();
23254b13 1351 m_static->SetLabel(m_list->GetDir());
c8c0e54c 1352 return;
0b855868
RR
1353 }
1354
75ec8bd4 1355#ifdef __UNIX__
223d09f6 1356 if (filename == wxT("~"))
ed58dbea
RR
1357 {
1358 m_list->GoToHomeDir();
1359 m_list->SetFocus();
23254b13 1360 m_static->SetLabel(m_list->GetDir());
c8c0e54c 1361 return;
ed58dbea 1362 }
c8c0e54c 1363
f6bcfd97 1364 if (filename[0u] == wxT('~'))
ed58dbea
RR
1365 {
1366 filename.Remove( 0, 1 );
c8c0e54c 1367 wxString tmp( wxGetUserHome() );
223d09f6 1368 tmp += wxT('/');
c8c0e54c
VZ
1369 tmp += filename;
1370 filename = tmp;
ed58dbea 1371 }
75ec8bd4 1372#endif // __UNIX__
ed58dbea 1373
223d09f6
KB
1374 if ((filename.Find(wxT('*')) != wxNOT_FOUND) ||
1375 (filename.Find(wxT('?')) != wxNOT_FOUND))
cae5359f 1376 {
75ec8bd4 1377 if (filename.Find(wxFILE_SEP_PATH) != wxNOT_FOUND)
c8c0e54c
VZ
1378 {
1379 wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR );
1380 return;
1381 }
1382 m_list->SetWild( filename );
1383 return;
cae5359f
RR
1384 }
1385
5e673a6a
VS
1386 if (!IsTopMostDir(dir))
1387 dir += wxFILE_SEP_PATH;
1388 if (!wxIsAbsolutePath(filename))
ed58dbea
RR
1389 {
1390 dir += filename;
1391 filename = dir;
1392 }
c8c0e54c 1393
8b17ba72
RR
1394 if (wxDirExists(filename))
1395 {
1396 m_list->GoToDir( filename );
23254b13 1397 m_static->SetLabel(m_list->GetDir());
c8c0e54c 1398 return;
8b17ba72 1399 }
c8c0e54c 1400
2b5f62a0
VZ
1401 // append the default extension to the filename if it doesn't have any
1402 //
1403 // VZ: the logic of testing for !wxFileExists() only for the open file
1404 // dialog is not entirely clear to me, why don't we allow saving to a
1405 // file without extension as well?
1406 if ( !(m_dialogStyle & wxOPEN) || !wxFileExists(filename) )
8b17ba72 1407 {
2b5f62a0
VZ
1408 wxString ext;
1409 wxSplitPath(filename, NULL, NULL, &ext);
1410 if ( ext.empty() )
8b17ba72 1411 {
2b5f62a0
VZ
1412 // append the first extension of the filter string
1413 filename += m_filterExtension.BeforeFirst(_T(';'));
8b17ba72
RR
1414 }
1415 }
2b5f62a0
VZ
1416
1417 // check that the file [doesn't] exist if necessary
1418 if ( (m_dialogStyle & wxSAVE) &&
1419 (m_dialogStyle & wxOVERWRITE_PROMPT) &&
1420 wxFileExists( filename ) )
8b17ba72 1421 {
2b5f62a0
VZ
1422 wxString msg;
1423 msg.Printf( _("File '%s' already exists, do you really want to "
1424 "overwrite it?"), filename.c_str() );
655cf310 1425
2b5f62a0
VZ
1426 if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
1427 return;
1428 }
1429 else if ( (m_dialogStyle & wxOPEN) &&
1430 (m_dialogStyle & wxFILE_MUST_EXIST) &&
1431 !wxFileExists(filename) )
1432 {
1433 wxMessageBox(_("Please choose an existing file."), _("Error"),
1434 wxOK | wxICON_ERROR );
8b17ba72
RR
1435 }
1436
1437 SetPath( filename );
479cd5de 1438
3f6638b8 1439 // change to the directory where the user went if asked
fda09b3f 1440 if ( m_dialogStyle & wxCHANGE_DIR )
3f6638b8
VZ
1441 {
1442 wxString cwd;
1443 wxSplitPath(filename, &cwd, NULL, NULL);
1444
1445 if ( cwd != wxGetWorkingDirectory() )
1446 {
1447 wxSetWorkingDirectory(cwd);
1448 }
1449 }
1450
9b7e522a
RR
1451 wxCommandEvent event;
1452 wxDialog::OnOK(event);
e1811a01
RR
1453}
1454
23254b13 1455void wxGenericFileDialog::OnListOk( wxCommandEvent &WXUNUSED(event) )
e1811a01
RR
1456{
1457 HandleAction( m_text->GetValue() );
8b17ba72
RR
1458}
1459
23254b13 1460void wxGenericFileDialog::OnList( wxCommandEvent &WXUNUSED(event) )
8b17ba72
RR
1461{
1462 m_list->ChangeToListMode();
9cedab37 1463 ms_lastViewStyle = wxLC_LIST;
0b855868 1464 m_list->SetFocus();
8b17ba72
RR
1465}
1466
23254b13 1467void wxGenericFileDialog::OnReport( wxCommandEvent &WXUNUSED(event) )
8b17ba72
RR
1468{
1469 m_list->ChangeToReportMode();
9cedab37 1470 ms_lastViewStyle = wxLC_REPORT;
0b855868 1471 m_list->SetFocus();
8b17ba72
RR
1472}
1473
23254b13 1474void wxGenericFileDialog::OnUp( wxCommandEvent &WXUNUSED(event) )
8b17ba72
RR
1475{
1476 m_list->GoToParentDir();
0b855868 1477 m_list->SetFocus();
23254b13 1478 m_static->SetLabel(m_list->GetDir());
8b17ba72
RR
1479}
1480
23254b13 1481void wxGenericFileDialog::OnHome( wxCommandEvent &WXUNUSED(event) )
8b17ba72
RR
1482{
1483 m_list->GoToHomeDir();
0b855868 1484 m_list->SetFocus();
23254b13 1485 m_static->SetLabel(m_list->GetDir());
0b855868
RR
1486}
1487
23254b13 1488void wxGenericFileDialog::OnNew( wxCommandEvent &WXUNUSED(event) )
0b855868
RR
1489{
1490 m_list->MakeDir();
8b17ba72
RR
1491}
1492
23254b13 1493void wxGenericFileDialog::SetPath( const wxString& path )
8b17ba72
RR
1494{
1495 // not only set the full path but also update filename and dir
1496 m_path = path;
9cedab37 1497 if ( !path.empty() )
8b17ba72
RR
1498 {
1499 wxString ext;
1500 wxSplitPath(path, &m_dir, &m_fileName, &ext);
9cedab37 1501 if (!ext.empty())
c8c0e54c 1502 {
223d09f6 1503 m_fileName += wxT(".");
8b17ba72 1504 m_fileName += ext;
c8c0e54c 1505 }
8b17ba72
RR
1506 }
1507}
c8c0e54c 1508
23254b13 1509void wxGenericFileDialog::GetPaths( wxArrayString& paths ) const
7941ba11
RR
1510{
1511 paths.Empty();
28c9c76e
RR
1512 if (m_list->GetSelectedItemCount() == 0)
1513 {
1514 paths.Add( GetPath() );
1515 return;
1516 }
479cd5de 1517
7941ba11
RR
1518 paths.Alloc( m_list->GetSelectedItemCount() );
1519
1520 wxString dir;
1521 m_list->GetDir( dir );
5e673a6a 1522#ifdef __UNIX__
7a82dabc 1523 if (dir != wxT("/"))
5e673a6a
VS
1524#endif
1525 dir += wxFILE_SEP_PATH;
7941ba11
RR
1526
1527 wxListItem item;
1528 item.m_mask = wxLIST_MASK_TEXT;
1529
1530 item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
92da8bde 1531 while ( item.m_itemId != -1 )
68df5777 1532 {
7941ba11
RR
1533 m_list->GetItem( item );
1534 paths.Add( dir + item.m_text );
68df5777 1535 item.m_itemId = m_list->GetNextItem( item.m_itemId,
7941ba11
RR
1536 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
1537 }
1538}
1539
23254b13 1540void wxGenericFileDialog::GetFilenames(wxArrayString& files) const
7941ba11
RR
1541{
1542 files.Empty();
28c9c76e
RR
1543 if (m_list->GetSelectedItemCount() == 0)
1544 {
1545 files.Add( GetFilename() );
1546 return;
1547 }
7941ba11
RR
1548 files.Alloc( m_list->GetSelectedItemCount() );
1549
1550 wxListItem item;
1551 item.m_mask = wxLIST_MASK_TEXT;
1552
1553 item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
92da8bde 1554 while ( item.m_itemId != -1 )
68df5777 1555 {
7941ba11
RR
1556 m_list->GetItem( item );
1557 files.Add( item.m_text );
68df5777 1558 item.m_itemId = m_list->GetNextItem( item.m_itemId,
7941ba11
RR
1559 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
1560 }
1561}
1562
23254b13 1563#ifdef USE_GENERIC_FILEDIALOG
655cf310 1564
23254b13 1565IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog);
655cf310 1566
8b17ba72
RR
1567// ----------------------------------------------------------------------------
1568// global functions
1569// ----------------------------------------------------------------------------
1570
ce9462d2
VZ
1571// common part of both wxFileSelectorEx() and wxFileSelector()
1572static wxString
1573DoSelectFile(const wxChar *title,
1574 const wxChar *defaultDir,
1575 const wxChar *defaultFileName,
1576 const wxChar *defaultExtension,
1577 int *indexDefaultExtension,
1578 const wxChar *filter,
1579 int flags,
1580 wxWindow *parent,
1581 int x,
1582 int y)
1583{
1584 // the filter may be either given explicitly or created automatically from
1585 // the default extension
1586 wxString filterReal;
1587 if ( filter )
1588 {
1589 // the user has specified the filter explicitly, use it
1590 filterReal = filter;
1591 }
1592 else if ( !wxIsEmpty(defaultExtension) )
1593 {
1594 // create the filter to match the given extension
1595 filterReal << wxT("*.") << defaultExtension;
1596 }
1597
1598 wxFileDialog fileDialog(parent,
1599 title,
1600 defaultDir,
1601 defaultFileName,
1602 filterReal,
1603 flags,
1604 wxPoint(x, y));
1605
1606 wxString path;
1607 if ( fileDialog.ShowModal() == wxID_OK )
1608 {
1609 path = fileDialog.GetPath();
1610 if ( indexDefaultExtension )
1611 {
1612 *indexDefaultExtension = fileDialog.GetFilterIndex();
1613 }
1614 }
1615
1616 return path;
1617}
1618
8b17ba72 1619wxString
ce9462d2
VZ
1620wxFileSelectorEx(const wxChar *title,
1621 const wxChar *defaultDir,
1622 const wxChar *defaultFileName,
1623 int *indexDefaultExtension,
1624 const wxChar *filter,
8b17ba72
RR
1625 int flags,
1626 wxWindow *parent,
ce9462d2
VZ
1627 int x,
1628 int y)
8b17ba72 1629{
ce9462d2
VZ
1630 return DoSelectFile(title,
1631 defaultDir,
1632 defaultFileName,
1633 wxT(""), // def ext determined by index
1634 indexDefaultExtension,
1635 filter,
1636 flags,
1637 parent,
1638 x,
1639 y);
8b17ba72
RR
1640}
1641
ce9462d2
VZ
1642wxString
1643wxFileSelector(const wxChar *title,
1644 const wxChar *defaultDir,
1645 const wxChar *defaultFileName,
1646 const wxChar *defaultExtension,
1647 const wxChar *filter,
1648 int flags,
1649 wxWindow *parent,
1650 int x,
1651 int y)
8b17ba72 1652{
ce9462d2
VZ
1653 return DoSelectFile(title,
1654 defaultDir,
1655 defaultFileName,
1656 defaultExtension,
1657 NULL, // not interested in filter index
1658 filter,
1659 flags,
1660 parent,
1661 x,
1662 y);
8b17ba72
RR
1663}
1664
2645b45a 1665static wxString GetWildcardString(const wxChar *ext)
8b17ba72 1666{
2645b45a
VZ
1667 wxString wild;
1668 if ( ext )
1669 {
1670 if ( *ext == wxT('.') )
1671 ext++;
8b17ba72 1672
2645b45a
VZ
1673 wild << _T("*.") << ext;
1674 }
1675 else // no extension specified
1676 {
1677 wild = wxFileSelectorDefaultWildcardStr;
1678 }
8b17ba72 1679
2645b45a 1680 return wild;
8b17ba72
RR
1681}
1682
2645b45a
VZ
1683wxString wxLoadFileSelector(const wxChar *what,
1684 const wxChar *ext,
1685 const wxChar *nameDef,
1686 wxWindow *parent)
8b17ba72 1687{
2645b45a
VZ
1688 wxString prompt;
1689 if ( what && *what )
1690 prompt = wxString::Format(_("Load %s file"), what);
1691 else
1692 prompt = _("Load file");
8b17ba72 1693
2645b45a
VZ
1694 return wxFileSelector(prompt, NULL, nameDef, ext,
1695 GetWildcardString(ext), 0, parent);
8b17ba72
RR
1696}
1697
2645b45a
VZ
1698wxString wxSaveFileSelector(const wxChar *what,
1699 const wxChar *ext,
1700 const wxChar *nameDef,
1701 wxWindow *parent)
1702{
1703 wxString prompt;
1704 if ( what && *what )
1705 prompt = wxString::Format(_("Save %s file"), what);
1706 else
1707 prompt = _("Save file");
655cf310 1708
2645b45a
VZ
1709 return wxFileSelector(prompt, NULL, nameDef, ext,
1710 GetWildcardString(ext), 0, parent);
1711}
655cf310
VS
1712
1713// A module to allow icons table cleanup
1714
1715class wxFileDialogGenericModule: public wxModule
1716{
1717DECLARE_DYNAMIC_CLASS(wxFileDialogGenericModule)
1718public:
1719 wxFileDialogGenericModule() {}
1720 bool OnInit() { return TRUE; }
1721 void OnExit() { if (g_IconsTable) {delete g_IconsTable; g_IconsTable = NULL;} }
1722};
1723
1724IMPLEMENT_DYNAMIC_CLASS(wxFileDialogGenericModule, wxModule)
1e6feb95 1725
23254b13
JS
1726#endif // USE_GENERIC_FILEDIALOG
1727
1e6feb95 1728#endif // wxUSE_FILEDLG
9cedab37 1729