27
static enum eFileDialogType {
32
ColorDialogOption::ColorDialogOption()
33
: m_ReturnColor(0, 0, 0, 0)
35
for(t_u32 i = 0; i < INL_COLOR_DIALOG_CUSTOM_COLOR; i++)
37
m_CustomColors[i] = (COLORREF) INL_RGB(255, 255, 255);
41
ColorDialogOption::~ColorDialogOption()
46
void ColorDialogOption::SetCustomColor(t_u32 index, t_u32 RGBColor)
48
nuxAssert(index < INL_COLOR_DIALOG_CUSTOM_COLOR);
49
m_CustomColors[index] = (COLORREF) RGBColor;
52
void ColorDialogOption::SetCustomColor(t_u32 index, BYTE R, BYTE G, BYTE B)
54
nuxAssert(index < INL_COLOR_DIALOG_CUSTOM_COLOR);
55
m_CustomColors[index] = (COLORREF) INL_RGB(R, G, B);
59
#define MAX_FILE_CHARACTERS 2*260
61
FileDialogOption::FileDialogOption()
65
DialogTitle = TEXT("\0");
66
InitialDirectory = TEXT("\0");
69
FileDialogOption::~FileDialogOption()
74
void FileDialogOption::AddFilter(const TCHAR* Description, const TCHAR* Filter)
76
nuxAssert(Description);
79
FilterDesc.push_back(NString(Description));
80
Filters.push_back(NString(Filter));
84
void FileDialogOption::RemoveFilter()
91
delete [] FormattedFilter;
96
TCHAR* FileDialogOption::GetFormatedFilter()
99
for(t_u32 i = 0; i < NumFilters; i++)
101
size += FilterDesc[i].Length() + Filters[i].Length() + 2; // + 2 for for the NULL char at the end of each string
103
size += 1; // + 1 for the final NULL char. The total string is terminated by two NULL char
106
delete [] FormattedFilter;
107
FormattedFilter = new TCHAR[size];
109
for(t_u32 i = 0; i < NumFilters; i++)
111
Memcpy((void*)(FormattedFilter + l), *FilterDesc[i], FilterDesc[i].Length());
112
l += FilterDesc[i].Length();
113
FormattedFilter[l] = 0;
115
Memcpy((void*)(FormattedFilter + l), *Filters[i], Filters[i].Length());
116
l += Filters[i].Length();
117
FormattedFilter[l] = 0;
120
FormattedFilter[l] = 0;
122
nuxAssert(size == l);
124
return FormattedFilter;
127
void FileDialogOption::SetDialogTitle(const TCHAR* Title)
131
void FileDialogOption::SetInitialDirectory(const TCHAR* Directory)
133
InitialDirectory = Directory;
136
bool Win32ColorDialog(HWND hWnd, ColorDialogOption& cdo)
138
CHOOSECOLOR ColorOptions;
140
Memset(&ColorOptions, 0, sizeof(CHOOSECOLOR));
141
ColorOptions.lStructSize = sizeof(CHOOSECOLOR);
142
ColorOptions.hwndOwner = hWnd;
143
ColorOptions.hInstance = 0;
144
ColorOptions.lpCustColors = cdo.m_CustomColors;
145
ColorOptions.Flags = CC_ANYCOLOR | CC_FULLOPEN;
147
if( ChooseColor(&ColorOptions) )
149
cdo.m_ReturnColor = Color(GetRValue(ColorOptions.rgbResult),GetGValue(ColorOptions.rgbResult),GetBValue(ColorOptions.rgbResult));
157
static bool _Win32FileDialog(HWND hWnd, eFileDialogType DialogType, FileDialogOption& fdo)
159
nuxAssert((DialogType == FILE_OPEN_DIALOG) || (DialogType == FILE_SAVE_DIALOG));
161
OPENFILENAME SaveFileOption;
163
TCHAR DrivePathFileName[MAX_FILE_CHARACTERS]; // buffer for OpenFileName.lpstrFile
164
TCHAR FileName[MAX_FILE_CHARACTERS]; // buffer for OpenFileName.lpstrFileTitle
166
DrivePathFileName[0] = 0;
167
Memset(&SaveFileOption, 0, sizeof(OPENFILENAME));
168
SaveFileOption.lStructSize = sizeof(OPENFILENAME);
169
// (See remark at the end of this file!)
170
SaveFileOption.hwndOwner = hWnd;
172
SaveFileOption.lpstrFilter = fdo.GetFormatedFilter();
173
SaveFileOption.nFilterIndex = 0;
175
// On return, this buffer contains the drive designator, path, file name, and extension of the selected file.
176
SaveFileOption.lpstrFile = DrivePathFileName;
177
SaveFileOption.nMaxFile = MAX_FILE_CHARACTERS;
179
// On return, this buffer receives the file name and extension (without path information) of the selected file.
180
SaveFileOption.lpstrFileTitle = FileName;
181
SaveFileOption.nMaxFileTitle = MAX_FILE_CHARACTERS;
183
SaveFileOption.lpstrInitialDir = fdo.GetInitialDirectory();
185
SaveFileOption.lpstrTitle = fdo.GetDialogTitle();
187
SaveFileOption.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR;
188
SaveFileOption.lpstrDefExt = TEXT("");
191
if(DialogType == FILE_OPEN_DIALOG)
193
if(::GetOpenFileName(&SaveFileOption))
195
fdo.ReturnFileName = NFileName(SaveFileOption.lpstrFile);
200
if(DialogType == FILE_SAVE_DIALOG)
202
if(::GetSaveFileName(&SaveFileOption))
204
fdo.ReturnFileName = NFileName(SaveFileOption.lpstrFile);
209
t_u32 error = ::CommDlgExtendedError();
213
bool Win32SaveFileDialog(HWND hWnd, FileDialogOption& fdo)
215
return (bool)_Win32FileDialog(hWnd, FILE_SAVE_DIALOG, fdo);
218
bool Win32OpenFileDialog(HWND hWnd, FileDialogOption& fdo)
220
return (bool)_Win32FileDialog(hWnd, FILE_OPEN_DIALOG, fdo);
27
static enum eFileDialogType {
32
ColorDialogOption::ColorDialogOption()
33
: m_ReturnColor(0, 0, 0, 0)
35
for(t_u32 i = 0; i < INL_COLOR_DIALOG_CUSTOM_COLOR; i++)
37
m_CustomColors[i] = (COLORREF) INL_RGB(255, 255, 255);
41
ColorDialogOption::~ColorDialogOption()
46
void ColorDialogOption::SetCustomColor(t_u32 index, t_u32 RGBColor)
48
nuxAssert(index < INL_COLOR_DIALOG_CUSTOM_COLOR);
49
m_CustomColors[index] = (COLORREF) RGBColor;
52
void ColorDialogOption::SetCustomColor(t_u32 index, BYTE R, BYTE G, BYTE B)
54
nuxAssert(index < INL_COLOR_DIALOG_CUSTOM_COLOR);
55
m_CustomColors[index] = (COLORREF) INL_RGB(R, G, B);
59
#define MAX_FILE_CHARACTERS 2*260
61
FileDialogOption::FileDialogOption()
65
DialogTitle = TEXT("\0");
66
InitialDirectory = TEXT("\0");
69
FileDialogOption::~FileDialogOption()
74
void FileDialogOption::AddFilter(const TCHAR* Description, const TCHAR* Filter)
76
nuxAssert(Description);
79
FilterDesc.push_back(NString(Description));
80
Filters.push_back(NString(Filter));
84
void FileDialogOption::RemoveFilter()
91
delete [] FormattedFilter;
96
TCHAR* FileDialogOption::GetFormatedFilter()
99
for(t_u32 i = 0; i < NumFilters; i++)
101
size += FilterDesc[i].Length() + Filters[i].Length() + 2; // + 2 for for the NULL char at the end of each string
103
size += 1; // + 1 for the final NULL char. The total string is terminated by two NULL char
106
delete [] FormattedFilter;
107
FormattedFilter = new TCHAR[size];
109
for(t_u32 i = 0; i < NumFilters; i++)
111
Memcpy((void*)(FormattedFilter + l), *FilterDesc[i], FilterDesc[i].Length());
112
l += FilterDesc[i].Length();
113
FormattedFilter[l] = 0;
115
Memcpy((void*)(FormattedFilter + l), *Filters[i], Filters[i].Length());
116
l += Filters[i].Length();
117
FormattedFilter[l] = 0;
120
FormattedFilter[l] = 0;
122
nuxAssert(size == l);
124
return FormattedFilter;
127
void FileDialogOption::SetDialogTitle(const TCHAR* Title)
131
void FileDialogOption::SetInitialDirectory(const TCHAR* Directory)
133
InitialDirectory = Directory;
136
bool Win32ColorDialog(HWND hWnd, ColorDialogOption& cdo)
138
CHOOSECOLOR ColorOptions;
140
Memset(&ColorOptions, 0, sizeof(CHOOSECOLOR));
141
ColorOptions.lStructSize = sizeof(CHOOSECOLOR);
142
ColorOptions.hwndOwner = hWnd;
143
ColorOptions.hInstance = 0;
144
ColorOptions.lpCustColors = cdo.m_CustomColors;
145
ColorOptions.Flags = CC_ANYCOLOR | CC_FULLOPEN;
147
if( ChooseColor(&ColorOptions) )
149
cdo.m_ReturnColor = Color(GetRValue(ColorOptions.rgbResult),GetGValue(ColorOptions.rgbResult),GetBValue(ColorOptions.rgbResult));
157
static bool _Win32FileDialog(HWND hWnd, eFileDialogType DialogType, FileDialogOption& fdo)
159
nuxAssert((DialogType == FILE_OPEN_DIALOG) || (DialogType == FILE_SAVE_DIALOG));
161
OPENFILENAME SaveFileOption;
163
TCHAR DrivePathFileName[MAX_FILE_CHARACTERS]; // buffer for OpenFileName.lpstrFile
164
TCHAR FileName[MAX_FILE_CHARACTERS]; // buffer for OpenFileName.lpstrFileTitle
166
DrivePathFileName[0] = 0;
167
Memset(&SaveFileOption, 0, sizeof(OPENFILENAME));
168
SaveFileOption.lStructSize = sizeof(OPENFILENAME);
169
// (See remark at the end of this file!)
170
SaveFileOption.hwndOwner = hWnd;
172
SaveFileOption.lpstrFilter = fdo.GetFormatedFilter();
173
SaveFileOption.nFilterIndex = 0;
175
// On return, this buffer contains the drive designator, path, file name, and extension of the selected file.
176
SaveFileOption.lpstrFile = DrivePathFileName;
177
SaveFileOption.nMaxFile = MAX_FILE_CHARACTERS;
179
// On return, this buffer receives the file name and extension (without path information) of the selected file.
180
SaveFileOption.lpstrFileTitle = FileName;
181
SaveFileOption.nMaxFileTitle = MAX_FILE_CHARACTERS;
183
SaveFileOption.lpstrInitialDir = fdo.GetInitialDirectory();
185
SaveFileOption.lpstrTitle = fdo.GetDialogTitle();
187
SaveFileOption.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR;
188
SaveFileOption.lpstrDefExt = TEXT("");
191
if(DialogType == FILE_OPEN_DIALOG)
193
if(::GetOpenFileName(&SaveFileOption))
195
fdo.ReturnFileName = NFileName(SaveFileOption.lpstrFile);
200
if(DialogType == FILE_SAVE_DIALOG)
202
if(::GetSaveFileName(&SaveFileOption))
204
fdo.ReturnFileName = NFileName(SaveFileOption.lpstrFile);
209
t_u32 error = ::CommDlgExtendedError();
213
bool Win32SaveFileDialog(HWND hWnd, FileDialogOption& fdo)
215
return (bool)_Win32FileDialog(hWnd, FILE_SAVE_DIALOG, fdo);
218
bool Win32OpenFileDialog(HWND hWnd, FileDialogOption& fdo)
220
return (bool)_Win32FileDialog(hWnd, FILE_OPEN_DIALOG, fdo);