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