File Index Symbol Index

#include "GuiThemeStyleFactory.h"
namespace
vl
{
namespace
presentation
{
namespace
theme
{
using
namespace
collections
;
using
namespace
controls
;
using
namespace
templates
;
class
Theme
:
public
Object
,
public
virtual
theme
::
ITheme
{
public
:
Dictionary
<
WString
,
Ptr
<
ThemeTemplates
>>
templates
;
ThemeTemplates
*
first
=
nullptr
;
ThemeTemplates
*
last
=
nullptr
;
bool
RegisterTheme
(
const
WString
&
name
,
Ptr
<
ThemeTemplates
>
theme
) {
if
(
templates
.
Keys
().
Contains
(
name
)) {
return
false
; }
templates
.
Add
(
name
,
theme
);
if
(
last
) {
last
->
next
=
theme
.
Obj
(); }
theme
-
>
previous
=
last
;
last
=
theme
.
Obj
();
return
true
; }
Ptr
<
ThemeTemplates
>
UnregisterTheme
(
const
WString
&
name
) {
vint
index
=
templates
.
Keys
().
IndexOf
(
name
);
if
(
index
== -
1
) {
return
nullptr
; }
auto
themeTemplates
=
templates
.
Values
().
Get
(
index
);
if
(
themeTemplates
-
>
previous
) {
themeTemplates
-
>
previous
->
next
=
themeTemplates
-
>
next
; }
else
{
first
=
themeTemplates
-
>
next
; }
if
(
themeTemplates
-
>
next
) {
themeTemplates
-
>
next
->
previous
=
themeTemplates
-
>
previous
; }
else
{
last
=
themeTemplates
-
>
previous
; }
templates
.
Remove
(
name
);
return
themeTemplates
; }
TemplateProperty
<
GuiControlTemplate
>
CreateStyle
(
ThemeName
themeName
)
override
{
switch
(
themeName
) {
#define GUI_DEFINE_ITEM_PROPERTY(TEMPLATE, CONTROL) \
case ThemeName::CONTROL:\
{\
auto current = last;\
while (current) \
{\
if (current->CONTROL)\
{\
return current->CONTROL; \
}\
current = current->previous;\
}\
throw Exception(L"Control template for \"" L ## #CONTROL L"\" is not defined.");\
}\
#undef GUI_DEFINE_ITEM_PROPERTY
default
: } } };
controls
::
GuiControlHost
*
ThemeTemplates
::
GetControlHostForInstance
() {
return
nullptr
; }
ThemeTemplates
::
~
ThemeTemplates
() {
FinalizeAggregation
(); }
Theme
*
currentTheme
=
nullptr
;
ITheme
*
GetCurrentTheme
() {
return
currentTheme
; }
void
InitializeTheme
() {
currentTheme
=
new
Theme
; }
void
FinalizeTheme
() {
delete
currentTheme
;
currentTheme
=
nullptr
; }
bool
RegisterTheme
(
Ptr
<
ThemeTemplates
>
theme
) {
return
currentTheme
->
RegisterTheme
(
theme
-
>
Name
,
theme
); }
Ptr
<
ThemeTemplates
>
UnregisterTheme
(
const
WString
&
name
) {
return
currentTheme
->
UnregisterTheme
(
name
); } } } }