Add m_fsStyle next to m_windowStyle

Add HasFdFlag()
  Use it for all tests in all variants of
    wxFileDialogs. That way it will be easier
    to change again centrally, if required.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42399 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-10-25 13:26:47 +00:00
parent 14d8546a75
commit b014db05bb
6 changed files with 26 additions and 23 deletions

View File

@@ -88,6 +88,8 @@ public:
const wxSize& sz = wxDefaultSize, const wxSize& sz = wxDefaultSize,
const wxString& name = wxFileDialogNameStr); const wxString& name = wxFileDialogNameStr);
bool HasFdFlag(int flag) const { return (m_fdStyle & flag) != 0; }
virtual void SetMessage(const wxString& message) { m_message = message; } virtual void SetMessage(const wxString& message) { m_message = message; }
virtual void SetPath(const wxString& path) { m_path = path; } virtual void SetPath(const wxString& path) { m_path = path; }
virtual void SetDirectory(const wxString& dir) { m_dir = dir; } virtual void SetDirectory(const wxString& dir) { m_dir = dir; }
@@ -131,6 +133,7 @@ protected:
wxString m_fileName; wxString m_fileName;
wxString m_wildCard; wxString m_wildCard;
int m_filterIndex; int m_filterIndex;
int m_fdStyle;
private: private:
void Init(); void Init();

View File

@@ -54,21 +54,21 @@ bool wxFileDialogBase::Create(wxWindow *parent,
m_wildCard = wildCard; m_wildCard = wildCard;
m_parent = parent; m_parent = parent;
m_windowStyle = style; m_fdStyle = style;
m_filterIndex = 0; m_filterIndex = 0;
if (!HasFlag(wxFD_OPEN) && !HasFlag(wxFD_SAVE)) if (!HasFdFlag(wxFD_OPEN) && !HasFdFlag(wxFD_SAVE))
m_windowStyle |= wxFD_OPEN; // wxFD_OPEN is the default m_fdStyle |= wxFD_OPEN; // wxFD_OPEN is the default
// check that the styles are not contradictory // check that the styles are not contradictory
wxASSERT_MSG( !(HasFlag(wxFD_SAVE) && HasFlag(wxFD_OPEN)), wxASSERT_MSG( !(HasFdFlag(wxFD_SAVE) && HasFdFlag(wxFD_OPEN)),
_T("can't specify both wxFD_SAVE and wxFD_OPEN at once") ); _T("can't specify both wxFD_SAVE and wxFD_OPEN at once") );
wxASSERT_MSG( !HasFlag(wxFD_SAVE) || wxASSERT_MSG( !HasFdFlag(wxFD_SAVE) ||
(!HasFlag(wxFD_MULTIPLE) && !HasFlag(wxFD_FILE_MUST_EXIST)), (!HasFdFlag(wxFD_MULTIPLE) && !HasFdFlag(wxFD_FILE_MUST_EXIST)),
_T("wxFD_MULTIPLE or wxFD_FILE_MUST_EXIST can't be used with wxFD_SAVE" ) ); _T("wxFD_MULTIPLE or wxFD_FILE_MUST_EXIST can't be used with wxFD_SAVE" ) );
wxASSERT_MSG( !HasFlag(wxFD_OPEN) || !HasFlag(wxFD_OVERWRITE_PROMPT), wxASSERT_MSG( !HasFdFlag(wxFD_OPEN) || !HasFdFlag(wxFD_OVERWRITE_PROMPT),
_T("wxFD_OVERWRITE_PROMPT can't be used with wxFD_OPEN") ); _T("wxFD_OVERWRITE_PROMPT can't be used with wxFD_OPEN") );
if ( wildCard.empty() || wildCard == wxFileSelectorDefaultWildcardStr ) if ( wildCard.empty() || wildCard == wxFileSelectorDefaultWildcardStr )

View File

@@ -1102,7 +1102,7 @@ bool wxGenericFileDialog::Create( wxWindow *parent,
mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 ); mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 );
long style2 = ms_lastViewStyle; long style2 = ms_lastViewStyle;
if ( style & wxFD_MULTIPLE == 0 ) if ( !HasFdFlag(wxFD_MULTIPLE) )
style2 |= wxLC_SINGLE_SEL; style2 |= wxLC_SINGLE_SEL;
#ifdef __WXWINCE__ #ifdef __WXWINCE__
@@ -1406,7 +1406,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
} }
#endif // __UNIX__ #endif // __UNIX__
if (!HasFlag(wxFD_SAVE)) if (!HasFdFlag(wxFD_SAVE))
{ {
if ((filename.Find(wxT('*')) != wxNOT_FOUND) || if ((filename.Find(wxT('*')) != wxNOT_FOUND) ||
(filename.Find(wxT('?')) != wxNOT_FOUND)) (filename.Find(wxT('?')) != wxNOT_FOUND))
@@ -1451,13 +1451,13 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
// VZ: the logic of testing for !wxFileExists() only for the open file // VZ: the logic of testing for !wxFileExists() only for the open file
// dialog is not entirely clear to me, why don't we allow saving to a // dialog is not entirely clear to me, why don't we allow saving to a
// file without extension as well? // file without extension as well?
if ( !HasFlag(wxFD_OPEN) || !wxFileExists(filename) ) if ( !HasFdFlag(wxFD_OPEN) || !wxFileExists(filename) )
{ {
filename = AppendExtension(filename, m_filterExtension); filename = AppendExtension(filename, m_filterExtension);
} }
// check that the file [doesn't] exist if necessary // check that the file [doesn't] exist if necessary
if ( HasFlag(wxFD_SAVE) && HasFlag(wxFD_OVERWRITE_PROMPT) && if ( HasFdFlag(wxFD_SAVE) && HasFdFlag(wxFD_OVERWRITE_PROMPT) &&
wxFileExists( filename ) ) wxFileExists( filename ) )
{ {
wxString msg; wxString msg;
@@ -1466,7 +1466,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES) if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
return; return;
} }
else if ( HasFlag(wxFD_OPEN) && HasFlag(wxFD_FILE_MUST_EXIST) && else if ( HasFdFlag(wxFD_OPEN) && HasFdFlag(wxFD_FILE_MUST_EXIST) &&
!wxFileExists(filename) ) !wxFileExists(filename) )
{ {
wxMessageBox(_("Please choose an existing file."), _("Error"), wxMessageBox(_("Please choose an existing file."), _("Error"),
@@ -1476,7 +1476,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
SetPath( filename ); SetPath( filename );
// change to the directory where the user went if asked // change to the directory where the user went if asked
if ( HasFlag(wxFD_CHANGE_DIR) ) if ( HasFdFlag(wxFD_CHANGE_DIR) )
{ {
wxString cwd; wxString cwd;
wxSplitPath(filename, &cwd, NULL, NULL); wxSplitPath(filename, &cwd, NULL, NULL);

View File

@@ -404,7 +404,7 @@ void wxFileDialog::SetFilename(const wxString& name)
{ {
if (!gtk_check_version(2,4,0)) if (!gtk_check_version(2,4,0))
{ {
if (HasFlag(wxFD_SAVE)) if (HasFdFlag(wxFD_SAVE))
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), wxGTK_CONV(name)); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), wxGTK_CONV(name));
else else
SetPath(wxFileName(GetDirectory(), name).GetFullPath()); SetPath(wxFileName(GetDirectory(), name).GetFullPath());

View File

@@ -330,7 +330,7 @@ int wxFileDialog::ShowModal()
} }
} }
if (HasFlag(wxFD_SAVE)) if (HasFdFlag(wxFD_SAVE))
{ {
myData.saveMode = true; myData.saveMode = true;
@@ -403,7 +403,7 @@ int wxFileDialog::ShowModal()
if (err != noErr) if (err != noErr)
break; break;
if (HasFlag(wxFD_SAVE)) if (HasFdFlag(wxFD_SAVE))
thePath = wxMacFSRefToPath( &theFSRef, navReply.saveFileName ); thePath = wxMacFSRefToPath( &theFSRef, navReply.saveFileName );
else else
thePath = wxMacFSRefToPath( &theFSRef ); thePath = wxMacFSRefToPath( &theFSRef );

View File

@@ -278,13 +278,13 @@ int wxFileDialog::ShowModal()
#if WXWIN_COMPATIBILITY_2_4 #if WXWIN_COMPATIBILITY_2_4
long msw_flags = 0; long msw_flags = 0;
if ( (m_windowStyle & wxHIDE_READONLY) || (m_windowStyle & wxFD_SAVE) ) if ( HasFdFlag(wxHIDE_READONLY) || HasFdFlag(wxFD_SAVE) )
msw_flags |= OFN_HIDEREADONLY; msw_flags |= OFN_HIDEREADONLY;
#else #else
long msw_flags = OFN_HIDEREADONLY; long msw_flags = OFN_HIDEREADONLY;
#endif #endif
if ( m_windowStyle & wxFD_FILE_MUST_EXIST ) if ( HasFdFlag(wxFD_FILE_MUST_EXIST) )
msw_flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; msw_flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
/* /*
If the window has been moved the programmer is probably If the window has been moved the programmer is probably
@@ -302,7 +302,7 @@ int wxFileDialog::ShowModal()
#endif #endif
} }
if (m_windowStyle & wxFD_MULTIPLE ) if ( HasFdFlag(wxFD_MULTIPLE) )
{ {
// OFN_EXPLORER must always be specified with OFN_ALLOWMULTISELECT // OFN_EXPLORER must always be specified with OFN_ALLOWMULTISELECT
msw_flags |= OFN_EXPLORER | OFN_ALLOWMULTISELECT; msw_flags |= OFN_EXPLORER | OFN_ALLOWMULTISELECT;
@@ -311,12 +311,12 @@ int wxFileDialog::ShowModal()
// if wxFD_CHANGE_DIR flag is not given we shouldn't change the CWD which the // if wxFD_CHANGE_DIR flag is not given we shouldn't change the CWD which the
// standard dialog does by default (notice that under NT it does it anyhow, // standard dialog does by default (notice that under NT it does it anyhow,
// OFN_NOCHANGEDIR or not, see below) // OFN_NOCHANGEDIR or not, see below)
if ( !(m_windowStyle & wxFD_CHANGE_DIR) ) if ( !HasFdFlag(wxFD_CHANGE_DIR) )
{ {
msw_flags |= OFN_NOCHANGEDIR; msw_flags |= OFN_NOCHANGEDIR;
} }
if ( m_windowStyle & wxFD_OVERWRITE_PROMPT ) if ( HasFdFlag(wxFD_OVERWRITE_PROMPT) )
{ {
msw_flags |= OFN_OVERWRITEPROMPT; msw_flags |= OFN_OVERWRITEPROMPT;
} }
@@ -413,7 +413,7 @@ int wxFileDialog::ShowModal()
// user types "foo" and the default extension is ".bar" we should force it // user types "foo" and the default extension is ".bar" we should force it
// to check for "foo.bar" existence and not "foo") // to check for "foo.bar" existence and not "foo")
wxString defextBuffer; // we need it to be alive until GetSaveFileName()! wxString defextBuffer; // we need it to be alive until GetSaveFileName()!
if (m_windowStyle & wxFD_SAVE) if (HasFdFlag(wxFD_SAVE))
{ {
const wxChar* extension = filterBuffer; const wxChar* extension = filterBuffer;
int maxFilter = (int)(of.nFilterIndex*2L) - 1; int maxFilter = (int)(of.nFilterIndex*2L) - 1;
@@ -470,7 +470,7 @@ int wxFileDialog::ShowModal()
m_fileNames.Empty(); m_fileNames.Empty();
if ( ( m_windowStyle & wxFD_MULTIPLE ) && if ( ( HasFdFlag(wxFD_MULTIPLE) ) &&
#if defined(OFN_EXPLORER) #if defined(OFN_EXPLORER)
( fileNameBuffer[of.nFileOffset-1] == wxT('\0') ) ( fileNameBuffer[of.nFileOffset-1] == wxT('\0') )
#else #else