16#if defined(BI_MULTI_THREAD_RTL)
31 auto StreamedStringToTString_(
const char* s) ->
tstring
46 auto InternStreamedString_(
const char* s) -> LPCTSTR
48 if (!s)
return nullptr;
49 static std::set<tstring> pool;
50#if defined(BI_MULTI_THREAD_RTL)
54 return pool.insert(StreamedStringToTString_(s)).first->c_str();
61 auto GetFilterSpecification_(LPCTSTR filter) ->
tstring
64 for (
auto p = filter; p && *p; p +=
::_tcslen(p) + 1)
65 s.append(p).append(1,
_T(
'|'));
102 Flags |= OFN_EXPLORER | OFN_LONGNAMES;
132 Flags |= OFN_EXPLORER | OFN_LONGNAMES;
221 if (*i.Current() ==
_T(
'|'))
233const uint TOpenSaveDialog::ShareViMsgId = ::RegisterWindowMessage(SHAREVISTRING);
242 memset(&ofn, 0,
sizeof(OPENFILENAME));
243#if defined(OPENFILENAME_SIZE_VERSION_400)
245 OPENFILENAME_SIZE_VERSION_400 :
sizeof(OPENFILENAME);
247 ofn.lStructSize =
sizeof(OPENFILENAME);
251 ofn.Flags = OFN_ENABLEHOOK | Data.Flags;
253 ofn.lpTemplateName = templateId;
254 ofn.Flags |= OFN_ENABLETEMPLATE;
257 ofn.Flags &= ~OFN_ENABLETEMPLATE;
258#if WINVER >= 0x500 && !defined(WINELIB)
259 ofn.FlagsEx = Data.FlagsEx;
261 ofn.lpfnHook =
nullptr;
263 ofn.lpstrFilter = Data.Filter;
264 ofn.nFilterIndex = Data.FilterIndex;
265 ofn.lpstrFile = Data.FileName;
266 ofn.nMaxFile = Data.MaxPath;
267 ofn.lpstrInitialDir = Data.InitialDir;
268 ofn.lpstrDefExt = Data.DefExt;
293 Title(title ? title :
_T(
""))
296 ofn.lpstrTitle = title ? &Title[0] :
nullptr;
314 ofn.lpstrTitle = &Title[0];
324 const bool explorerStyle = ofn.Flags & OFN_EXPLORER;
328 TNotify* n = (msg == WM_NOTIFY) ?
reinterpret_cast<TNotify*
>(param2) :
nullptr;
329 if (n && n->code == CDN_SHAREVIOLATION)
331 WARN(!explorerStyle,
_T(
"CDN_SHAREVIOLATION was sent to old-style dialog."));
339 if (r == OFN_SHAREWARN)
342 CHECK(!
OWL_STRICT || r == OFN_SHAREFALLTHROUGH || r == OFN_SHARENOWARN);
343 WARN(r != OFN_SHAREFALLTHROUGH && r != OFN_SHARENOWARN,
_T(
"ShareViolation returned undefined value: ") << r);
349 else if (msg == TOpenSaveDialog::ShareViMsgId)
359 WARN(r != OFN_SHAREWARN,
_T(
"ShareViolation returned unexpected value in Explorer-style dialog:") << r);
363 CHECK(!
OWL_STRICT || r == OFN_SHAREFALLTHROUGH || r == OFN_SHARENOWARN || r == OFN_SHAREWARN);
364 WARN(r != OFN_SHAREFALLTHROUGH && r != OFN_SHARENOWARN && r != OFN_SHAREWARN,
365 _T(
"ShareViolation returned undefined value: ") << r);
392 return OFN_SHAREWARN;
421 int ret = GetOpenFileName(&ofn);
422 Data.Error = CommDlgExtendedError();
424 Data.Flags = ofn.Flags;
425 Data.FilterIndex =
static_cast<int>(ofn.nFilterIndex);
427 return ret ? IDOK : IDCANCEL;
455 int ret = GetSaveFileName(&ofn);
456 Data.Error = CommDlgExtendedError();
458 Data.Flags = ofn.Flags;
459 Data.FilterIndex = ofn.nFilterIndex;
461 return ret ? IDOK : IDCANCEL;
482 using TStreamedString = std::unique_ptr<char[]>;
486 const auto fileName = TStreamedString{is.
readString()};
487 const auto filter = TStreamedString{is.
freadString()};
488 const auto customFilter = TStreamedString{is.
freadString()};
491 const auto initialDir = TStreamedString{is.
freadString()};
492 const auto defExt = TStreamedString{is.
freadString()};
495 if (!is.
good())
return;
499 const auto f = StreamedStringToTString_(fileName.get());
500 const auto n = std::min(f.size(),
static_cast<size_t>(
MaxPath - 1));
501 WARN(n < f.size(),
_T(
"TOpenSaveDialog::TData::Read: File name truncated to MaxPath: ") << f);
503 f.copy(fileNameBuffer, n);
504 fileNameBuffer[n] =
_T(
'\0');
508 if (!filter || !*filter.get())
513 else if (strchr(filter.get(),
'|'))
514 SetFilter(StreamedStringToTString_(filter.get()));
518 InitialDir = InternStreamedString_(initialDir.get());
519 DefExt = InternStreamedString_(defExt.get());
536 const auto customFilter =
nullptr;
587 auto v = std::vector<tstring>{};
606 while (*p !=
_T(
'\0'))
609 const auto f = d +
_T(
'\\') + n;
#define WARN(condition, message)
#define PRECONDITION(condition)
TCommonDialog(TWindow *parent, LPCTSTR title=nullptr, TModule *module=nullptr)
Invokes a TWindow constructor, passing the parent window parent, and constructs a common dialog box t...
This nested class handles locking and unlocking critical sections.
Lightweight intra-process thread synchronization.
bool SetMsgResult(TResult result)
Sets the dialog procedure message result (DWLP_MSGRESULT) and returns true.
virtual INT_PTR DialogFunction(TMsgId, TParam1, TParam2)
Override this to process messages within the dialog function.
static INT_PTR CALLBACK StdDlgProc(HWND, UINT, WPARAM, LPARAM) noexcept
Callback procs for hooking TDialog to native window.
int DoExecute()
Creates the TFileOpenDialog object.
TFileOpenDialog(TWindow *parent, TData &data, TResId templateId=0, LPCTSTR title=nullptr, TModule *module=nullptr)
Constructs and initializes the TFileOpen object based on information in the TOpenSaveDialog::TData da...
int DoExecute()
Creates the TFileSaveDialog object.
TFileSaveDialog(TWindow *parent, TData &data, TResId templateId=0, LPCTSTR title=nullptr, TModule *module=nullptr)
Constructs and initializes the TFileOpen object based on the TOpenSaveDialog::TData structure,...
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
TNotify is a thin wrapper around the NMHDR structure.
TOpenSaveDialog structure contains information about the user's file open or save selection.
TData & operator=(const TData &src)
TCHAR * FileName
Holds the name of the file to be saved or opened.
TData(uint32 flags=0, LPCTSTR filter=nullptr, TCHAR *customFilter=nullptr, LPCTSTR initialDir=nullptr, LPCTSTR defExt=nullptr, int maxPath=0, int filterIndex=0, uint32 flagsEx=0)
Constructs a TOpenSaveDialog::TData structure.
int FilterIndex
FilterIndex indicates which filter to use initially when displaying file names.
void Read(ipstream &is)
Reads the data from the given persistent stream.
LPCTSTR InitialDir
Directory to use initially when displaying file names.
~TData()
Destructs a TOpenSaveDialog::TData structure.
uint32 Flags
Flag contains one or more of the following constants:
void Write(opstream &os)
Writes the data to the given persistent stream.
TCHAR * Filter
Filter holds the filter to use initially when displaying file names.
uint32 Error
This is the return value from calling CommDlgExtendedError after executing the dialog in the implemen...
LPCTSTR DefExt
Default extension to use when saving file names.
auto GetFileNames() const -> std::vector< tstring >
Returns a vector containing the full paths of every file entry in member FileName.
void SetFilter(LPCTSTR filter=nullptr)
Makes a copy of the filter list used to display the file names.
TOpenSaveDialog(TWindow *parent, TData &data, TResId templateId=0, LPCTSTR title=nullptr, TModule *module=nullptr)
auto DialogFunction(TMsgId, TParam1, TParam2) -> INT_PTR override
Handles CDN_SHAREVIOLATION and the older SHAREVISTRING registered message.
virtual int ShareViolation()
If a sharing violation occurs when a file is opened or saved, ShareViolation is called to obtain a re...
void Init(TResId templateId)
Initializes a TOpenSaveDialog object with the current resource ID.
static uint GetMajorVersion()
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
TWindow * GetParentO() const
Return the OWL's parent for this window.
TModule * GetModule() const
Returns a pointer to the module object.
HWND GetHandle() const
Returns the handle of the window.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
LPSTR readString()
Allocates a buffer large enough to contain the string at the current stream position and reads the st...
char * freadString()
Reads a string from the stream.
Base class for writing streamable objects.
void writeString(const char *)
Writes str to the stream.
void fwriteString(const char *str)
Writes the specified far character string (str) to the stream.
Definition of classes for CommonControl encapsulation.
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
int good() const
Returns nonzero if no error states have been recorded for the stream (that is, no errors have occurre...
char * strnewdup(const char *s, size_t minAllocSize=0)
Object Windows Library (OWLNext Core).
UINT TMsgId
Message ID type.
LPARAM TParam2
Second parameter type.
WPARAM TParam1
First parameter type.
Definition of TOpenSave abstract, TFileOpen, TFileSave common Dialog classes.