]> git.saurik.com Git - wxWidgets.git/blob - src/qt/filedlg.cpp
-fpermissive is now returned by wx-config -cflags if the library was compiled
[wxWidgets.git] / src / qt / filedlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filedlg.cpp
3 // Purpose: wxFileDialog
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "filedlg.h"
14 #endif
15
16 #include "wx/defs.h"
17 #include "wx/utils.h"
18 #include "wx/dialog.h"
19 #include "wx/filedlg.h"
20
21 IMPLEMENT_CLASS(wxFileDialog, wxDialog)
22
23 char *wxFileSelector(const char *title,
24 const char *defaultDir, const char *defaultFileName,
25 const char *defaultExtension, const char *filter, int flags,
26 wxWindow *parent, int x, int y)
27 {
28 // If there's a default extension specified but no filter, we create a suitable
29 // filter.
30
31 wxString filter2("");
32 if ( defaultExtension && !filter )
33 filter2 = wxString("*.") + wxString(defaultExtension) ;
34 else if ( filter )
35 filter2 = filter;
36
37 wxString defaultDirString;
38 if (defaultDir)
39 defaultDirString = defaultDir;
40 else
41 defaultDirString = "";
42
43 wxString defaultFilenameString;
44 if (defaultFileName)
45 defaultFilenameString = defaultFileName;
46 else
47 defaultFilenameString = "";
48
49 wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y));
50
51 if ( fileDialog.ShowModal() == wxID_OK )
52 {
53 strcpy(wxBuffer, (const char *)fileDialog.GetPath());
54 return wxBuffer;
55 }
56 else
57 return NULL;
58 }
59
60 char *wxFileSelectorEx(const char *title,
61 const char *defaultDir,
62 const char *defaultFileName,
63 int* defaultFilterIndex,
64 const char *filter,
65 int flags,
66 wxWindow* parent,
67 int x,
68 int y)
69
70 {
71 wxFileDialog fileDialog(parent, title ? title : "", defaultDir ? defaultDir : "",
72 defaultFileName ? defaultFileName : "", filter ? filter : "", flags, wxPoint(x, y));
73
74 if ( fileDialog.ShowModal() == wxID_OK )
75 {
76 *defaultFilterIndex = fileDialog.GetFilterIndex();
77 strcpy(wxBuffer, (const char *)fileDialog.GetPath());
78 return wxBuffer;
79 }
80 else
81 return NULL;
82 }
83
84 wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
85 const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
86 long style, const wxPoint& pos)
87 {
88 m_message = message;
89 m_dialogStyle = style;
90 m_parent = parent;
91 m_path = "";
92 m_fileName = defaultFileName;
93 m_dir = defaultDir;
94 m_wildCard = wildCard;
95 m_filterIndex = 1;
96 }
97
98 int wxFileDialog::ShowModal()
99 {
100 // TODO
101 wxID_CANCEL;
102 }
103
104 // Generic file load/save dialog
105 static char *
106 wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent)
107 {
108 char *ext = (char *)extension;
109
110 char prompt[50];
111 wxString str;
112 if (load)
113 str = "Load %s file";
114 else
115 str = "Save %s file";
116 sprintf(prompt, wxGetTranslation(str), what);
117
118 if (*ext == '.') ext++;
119 char wild[60];
120 sprintf(wild, "*.%s", ext);
121
122 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
123 }
124
125 // Generic file load dialog
126 char *
127 wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
128 {
129 return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
130 }
131
132
133 // Generic file save dialog
134 char *
135 wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
136 {
137 return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
138 }
139
140