File Index Symbol Index

#include "WindowsDialogService.h" #include <Vfw.h>
#pragma comment(lib,
"Vfw32.lib"
)
namespace
vl
{
namespace
presentation
{
namespace
windows
{
using
namespace
collections
;
/*********************************************************************** WindowsDialogService ***********************************************************************/
WindowsDialogService
::
WindowsDialogService
(
HandleRetriver
_handleRetriver
) :handleRetriver(
_handleRetriver
) { }
INativeDialogService
::
MessageBoxButtonsOutput
WindowsDialogService
::
ShowMessageBox
(
INativeWindow
*
window
,
const
WString
&
text
,
const
WString
&
title
,
MessageBoxButtonsInput
buttons
,
MessageBoxDefaultButton
defaultButton
,
MessageBoxIcons
icon
,
MessageBoxModalOptions
modal
) {
WString
realTitle
=
title
;
if
(
title
=
=
L""
&&
window
!=
0
) {
realTitle
=
window
->
GetTitle
(); }
HWND
hWnd
=
handleRetriver
(
window
);
LPCTSTR
lpText
=
text
.
Buffer
();
LPCTSTR
lpCaption
=
realTitle
.
Buffer
();
UINT
uType
=
0
;
#define MAP(A, B) case A: uType|=(B); break
switch
(
buttons
) { }
switch
(
defaultButton
) { }
switch
(
icon
) { }
switch
(
modal
) { }
#undef MAP
switch
(
result
) {
default
:
return
SelectOK
; } }
bool
WindowsDialogService
::
ShowColorDialog
(
INativeWindow
*
window
,
Color
&
selection
,
bool
selected
,
ColorDialogCustomColorOptions
customColorOptions
,
Color
*
customColors
) {
CHOOSECOLOR
chooseColor
;
COLORREF
customColorsBuffer
[
16
]={
0
};
if
(
customColors
) {
for
(
vint
i
=
0
;
i
<
sizeof
(
customColorsBuffer
)/
sizeof
(*
customColorsBuffer
);
i
++) { } }
chooseColor
.
lStructSize
=
sizeof
(
chooseColor
);
chooseColor
.
hwndOwner
=
handleRetriver
(
window
);
chooseColor
.
lpCustColors
=
customColorsBuffer
;
#define MAP(A, B) case A: chooseColor.Flags|=(B); break
switch
(
customColorOptions
) { }
#undef MAP
if
(
selected
) { }
if
(
result
) {
if
(
customColors
) {
for
(
vint
i
=
0
;
i
<
sizeof
(
customColorsBuffer
)/
sizeof
(*
customColorsBuffer
);
i
++) {
COLORREF
color
=
customColorsBuffer
[
i
]; } } } }
bool
WindowsDialogService
::
ShowFontDialog
(
INativeWindow
*
window
,
FontProperties
&
selectionFont
,
Color
&
selectionColor
,
bool
selected
,
bool
showEffect
,
bool
forceFontExist
) {
LOGFONT
logFont
;
logFont
.
lfHeight
=-(
int
)
selectionFont
.
size
;
wcscpy_s
(
logFont
.
lfFaceName
,
selectionFont
.
fontFamily
.
Buffer
());
CHOOSEFONT
chooseFont
;
chooseFont
.
lStructSize
=
sizeof
(
chooseFont
);
chooseFont
.
hwndOwner
=
handleRetriver
(
window
);
chooseFont
.
lpLogFont
=&
logFont
;
chooseFont
.
iPointSize
=
0
;
if
(
result
) {
selectionFont
.
fontFamily
=
logFont
.
lfFaceName
;
selectionFont
.
size
=-
logFont
.
lfHeight
; } }
bool
WindowsDialogService
::
ShowFileDialog
(
INativeWindow
*
window
,
collections
::
List
<
WString
>&
selectionFileNames
,
vint
&
selectionFilterIndex
,
FileDialogTypes
dialogType
,
const
WString
&
title
,
const
WString
&
initialFileName
,
const
WString
&
initialDirectory
,
const
WString
&
defaultExtension
,
const
WString
&
filter
,
FileDialogOptions
options
) {
Array
<
wchar_t
>
fileNamesBuffer
(
65536
>
initialFileName
.
Length
()+
1
?
65536
:
initialFileName
.
Length
()+
1
);
wcscpy_s
(&
fileNamesBuffer
[
0
],
fileNamesBuffer
.
Count
(),
initialFileName
.
Buffer
());
OPENFILENAME
ofn
;
ofn
.
lStructSize
=
sizeof
(
ofn
);
ofn
.
hwndOwner
=
handleRetriver
(
window
);
ofn
.
nMaxCustFilter
=
0
;
ofn
.
nFilterIndex
=(
int
)
selectionFilterIndex
+
1
;
ofn
.
lpstrFile
=&
fileNamesBuffer
[
0
];
ofn
.
nMaxFile
=(
int
)
fileNamesBuffer
.
Count
();
ofn
.
nMaxFileTitle
=
0
;
List
<
vint
>
filterSeparators
;
for
(
vint
i
=
0
;
i
<
filter
.
Length
();
i
++) {
if
(
filter
[
i
]==
L'|'
) {
filterSeparators
.
Add
(
i
); } }
if
(
filterSeparators
.
Count
()%
2
==
1
) {
filterSeparators
.
Add
(
filter
.
Length
()); }
Array
<
wchar_t
>
filterBuffer
(
filter
.
Length
()+
2
);
vint
index
=
0
;
for
(
vint
i
=
0
;
i
<
filterSeparators
.
Count
();
i
++) {
vint
end
=
filterSeparators
[
i
];
wcsncpy_s
(&
filterBuffer
[
index
],
filterBuffer
.
Count
()-
index
,
filter
.
Buffer
()+
index
,
end
-
index
);
filterBuffer
[
end
]=
0
;
index
=
end
+
1
; }
filterBuffer
[
index
]=
0
;
ofn
.
lpstrFilter
=&
filterBuffer
[
0
];
switch
(
dialogType
) {
case
FileDialogOpen
:
break
;
case
FileDialogOpenPreview
:
break
;
case
FileDialogSave
:
break
;
case
FileDialogSavePreview
:
break
; }
if
(
result
) {
selectionFilterIndex
=
ofn
.
nFilterIndex
-
1
;
selectionFileNames
.
Clear
();
if
(
options
&
FileDialogAllowMultipleSelection
) {
const
wchar_t
*
reading
=&
fileNamesBuffer
[
0
];
WString
directory
=
reading
;
reading
+=
directory
.
Length
()+
1
;
while
(*
reading
) {
WString
fileName
=
reading
;
reading
+=
fileName
.
Length
()+
1
;
selectionFileNames
.
Add
(
directory
+
L"\\"
+
fileName
); }
if
(
selectionFileNames
.
Count
()==
0
) {
selectionFileNames
.
Add
(
directory
); } }
else
{
selectionFileNames
.
Add
(&
fileNamesBuffer
[
0
]); } } } } } }