#include "GuiGraphicsDocumentElement.h"
namespace
{
using
namespace
collections
;
namespace
{
namespace
{
namespace
{
class
:
public
,
public
::
{
typedef
::
GuiDocumentElementRenderer
;
typedef
::
;
public
:
;
;
;
;
<
>
;
*
;
*
;
<
::
>
;
*
;
(
*
,
*
,
<
::
>
,
,
)
:start(
0
)
,length(
0
)
,model(
)
,renderer(
)
,cache(
)
,paragraph(
.
())
,selectionBegin(
)
,selectionEnd(
)
{
;
style
->
(
::
,
style
);
.
(
style
);
}
void
(
*
)
{
FOREACH(Ptr<DocumentRun>, subRun, run->runs)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
subRun
);)
{
subRun
(
this
);
}
}
void
(
,
,
const
&
)
{
->
(
,
,
.
.
);
->
(
,
,
.
.
);
->
(
,
,
(
::
)
( (
.
.
?
::
:
0
)
| (
.
.
?
::
:
0
)
| (
.
.
?
::
:
0
)
| (
.
.
?
::
:
0
)
));
}
void
(
,
,
const
&
)
{
->
(
,
,
.
);
->
(
,
,
.
);
}
void
(
*
)
override
{
=
->
().
();
if
(
>
0
)
{
=
.
()-
1
];
(
,
,
style
);
(
,
,
style
);
=
;
=
styleStart
+
;
if
(
styleStart
<
&&
<
styleEnd
)
{
=
styleStart
>
?
styleStart
:
;
=
<
styleEnd
?
:
styleEnd
;
if
(
s2
<
s3
)
{
=
->
(
::
,
style
);
(
s2
,
s3
-
s2
,
selectionStyle
);
}
}
}
+=
;
}
void
(
DocumentStylePropertiesRun
*
)
override
{
=
.
()-
1
];
style
->
(
->
,
style
);
.
(
style
);
(
);
.
(
.
()-
1
);
}
void
(
DocumentStyleApplicationRun
*
)
override
{
=
.
()-
1
];
style
->
(
->
,
style
);
.
(
style
);
(
);
.
(
.
()-
1
);
}
void
(
*
)
override
{
=
.
()-
1
];
style
->
(
->
,
style
);
.
(
style
);
(
);
.
(
.
()-
1
);
}
void
(
*
)
override
{
=
->
().
();
<
>
=
::
();
element
(
->
,
->
);
element
(
true
);
::
;
properties
.
->
;
properties
.
=
->
;
properties
.
=
::
;
properties
.
element
;
->
(
,
,
properties
);
if
(
<
&&
<
+
)
{
=
.
()-
1
];
=
->
(
::
,
style
);
(
,
,
selectionStyle
);
}
+=
;
}
void
(
DocumentEmbeddedObjectRun
*
)
override
{
=
->
().
();
::
;
properties
.
=
::
;
if
(
->
!=
L""
)
{
=
->
.
().
(
->
);
if
(
index
!= -
1
)
{
auto
=
->
.
()
index
];
index
=
.
().
(
id
);
if
(
index
!= -
1
)
{
auto
=
.
()
index
];
if
(
eo
==
)
{
properties
.
eo
;
properties
.
=
id
;
}
}
}
else
{
auto
=
<
::
>();
eo
->
;
eo
(
0
,
0
);
eo
=
;
= -
1
;
=
->
.
();
if
(
count
>
0
)
{
id
=
->
count
-
1
];
->
.
(
count
-
1
);
}
else
{
id
=
->
++;
}
->
.
(
eo
,
id
);
.
(
id
,
eo
);
properties
.
=
id
;
}
}
->
(
,
,
properties
);
if
(
<
&&
<
+
)
{
=
.
()-
1
];
=
->
(
::
,
style
);
(
,
,
selectionStyle
);
}
+=
;
}
void
(
*
)
override
{
(
);
}
static
(
*
,
*
,
<
::
>
,
<
>
,
,
)
{
(
,
,
,
,
);
(&
visitor
);
return
visitor
.
;
}
};
}
using
namespace
visitors
;
::
GuiDocumentElementRenderer
::
(
,
)
{
if
(
->
)
{
auto
=
];
auto
=
(
(
.
+
.
,
.
+
.
),
.
());
auto
=
cache
];
auto
=
->
->
(
eo
,
relativeLocation
);
eo
=
eo
size
;
eo
size
;
return
eo
;
}
else
{
return
();
}
}
void
::
GuiDocumentElementRenderer
::
()
{
}
void
::
GuiDocumentElementRenderer
::
()
{
}
void
::
GuiDocumentElementRenderer
::
RenderTargetChangedInternal
(
*
,
*
)
{
for
(
=
0
;
i
<
.
();
i
++)
{
*
=
i
].
();
if
(
cache
)
{
cache
->
0
;
}
}
}
<
::
GuiDocumentElementRenderer
::
>
::
GuiDocumentElementRenderer
::
(
,
bool
)
{
if
(
<
0
||
>=
.
())
return
0
;
<
>
=
->
];
<
>
=
];
if
(!
cache
)
{
cache
new
;
cache
paragraph
(
false
);
]
cache
;
}
if
(
)
{
if
(!
cache
)
{
cache
->
(
cache
,
,
this
);
cache
(
paragraph
?
paragraph
.
() :
::
);
::
(
->
.
(),
this
,
cache
,
paragraph
,
cache
,
cache
);
}
if
(
cache
()!=
)
{
cache
(
);
}
=
];
=
cache
();
if
(
paragraphHeight
!=
height
)
{
+=
height
-
paragraphHeight
;
paragraphHeight
=
height
;
]=
paragraphHeight
;
(
0
,
);
}
}
return
cache
;
}
bool
::
GuiDocumentElementRenderer
::
GetParagraphIndexFromPoint
(
,
&
,
&
)
{
=
0
;
for
(
=
0
;
i
<
.
();
i
++)
{
=
i
];
=
y
+
paragraphHeight
+
;
=
y
;
=
i
;
if
(
nextY
<=
.
)
{
y
=
nextY
;
continue
;
}
else
{
break
;
}
}
return
true
;
}
::
GuiDocumentElementRenderer
::
GuiDocumentElementRenderer
()
:paragraphDistance(
0
)
,lastMaxWidth(-
1
)
,cachedTotalHeight(
0
)
,layoutProvider(
GetGuiGraphicsResourceManager
()->
())
,lastCaret(-
1
, -
1
)
,lastCaretFrontSide(
false
)
{
}
void
::
GuiDocumentElementRenderer
::
(
)
{
if
(
->
)
{
->
->
();
}
->
(
);
if
(!
->
IsClipperCoverWholeTarget
())
{
=
.
();
=
->
();
=
.
();
=
.
();
=
clipper
.
()-
.
();
=
y1
+
clipper
.
();
=
0
;
=
maxWidth
;
for
(
=
0
;
i
<
.
();
i
++)
{
=
i
];
if
(
y
+
paragraphHeight
<=
y1
)
{
y
+=
paragraphHeight
+
;
continue
;
}
else
if
(
y
>=
y2
)
{
break
;
}
else
{
<
>
=
->
i
];
<
>
=
i
];
bool
=
cache
&&
cache
;
cache
(
i
,
true
);
if
(!
created
&&
i
==
.
&&
->
)
{
cache
(
.
,
,
);
}
paragraphHeight
=
cache
();
=
i
;
(
cx
-
.
,
cy
+
y
-
.
);
cache
(
(
(
cx
,
cy
+
y
),
(
maxWidth
,
paragraphHeight
)));
= -
1
;
bool
=
false
;
for
(
=
0
;
j
<
cache
.
();
j
++)
{
auto
=
cache
.
()
j
];
if
(
eo
)
{
eo
=
false
;
resized
=
true
;
}
}
if
(
resized
)
{
cache
0
;
}
}
y
+=
paragraphHeight
+
;
}
}
->
();
if
(
->
)
{
->
->
();
}
}
void
::
GuiDocumentElementRenderer
::
()
{
if
(
->
&&
->
.
() >
0
)
{
=
()->
()->
().
;
=
defaultSize
;
=
defaultSize
;
.
(
->
.
());
.
(
->
.
());
for
(
=
0
;
i
<
.
();
i
++)
{
i
]
0
;
}
for
(
=
0
;
i
<
.
();
i
++)
{
i
] =
defaultHeight
;
}
=
.
() * (
defaultHeight
+
);
if
(
.
()>
0
)
{
-=
;
}
(
0
,
);
}
else
{
.
(
0
);
.
(
0
);
=
0
;
(
0
,
0
);
}
.
();
.
();
=
0
;
}
void
::
GuiDocumentElementRenderer
::
(
,
,
,
bool
)
{
if
(
0
<=
&&
<
.
() &&
0
<=
&&
+
<=
.
() &&
0
<=
)
{
=
->
.
();
CHECK_ERROR(updatedText || oldCount == newCount, L"GuiDocumentlement::GuiDocumentElementRenderer::NotifyParagraphUpdated(vint, vint, vint, bool)#Illegal values of oldCount and newCount.");
do
{
if
(!(
||
==
))
throw
(
L"GuiDocumentlement::GuiDocumentElementRenderer::NotifyParagraphUpdated(vint, vint, vint, bool)#Illegal values of oldCount and newCount."
);}
while
(
0
);
CHECK_ERROR(paragraphCount - paragraphCaches.Count() == newCount - oldCount, L"GuiDocumentElement::GuiDocumentElementRenderer::NotifyParagraphUpdated(vint, vint, vint, bool)#Illegal values of oldCount and newCount.");
do
{
if
(!(
paragraphCount
-
.
() ==
-
))
throw
(
L"GuiDocumentElement::GuiDocumentElementRenderer::NotifyParagraphUpdated(vint, vint, vint, bool)#Illegal values of oldCount and newCount."
);}
while
(
0
);
;
(
oldCaches
,
);
.
(
paragraphCount
);
;
(
oldHeights
,
);
.
(
paragraphCount
);
=
()->
()->
().
;
=
0
;
for
(
=
0
;
i
<
paragraphCount
;
i
++)
{
if
(
i
<
)
{
i
]
oldCaches
i
];
i
] =
oldHeights
i
];
}
else
if
(
i
<
+
)
{
i
]
0
;
i
] =
defaultHeight
;
if
(!
&&
i
<
+
)
{
auto
=
oldCaches
i
];
if
(
cache
)
{
cache
0
;
}
i
]
cache
;
i
] =
oldHeights
i
];
}
}
else
{
i
]
oldCaches
i
- (
-
)];
i
] =
oldHeights
i
- (
-
)];
}
+=
i
] +
;
}
if
(
paragraphCount
>
0
)
{
-=
;
}
if
(
)
{
=
<
?
:
;
for
(
=
0
;
i
<
count
;
i
++)
{
if
(
auto
=
oldCaches
+
i
])
{
for
(
=
0
;
j
<
cache
.
();
j
++)
{
auto
=
cache
.
()
j
];
auto
=
cache
.
()
j
]
;
.
(
name
);
.
(
id
);
}
}
}
}
}
}
<
::
>
::
GuiDocumentElementRenderer
::
(
)
{
if
(!
)
return
nullptr
;
=
0
;
=-
1
;
if
(
GetParagraphIndexFromPoint
(
,
top
,
index
))
{
<
>
=
(
index
,
true
);
(
.
,
.
-
top
);
=-
1
;
=
0
;
if
(
cache
(
paragraphPoint
,
start
,
length
))
{
return
->
(
index
,
start
,
start
+
length
);
}
=
cache
(
paragraphPoint
);
return
->
(
index
,
caret
,
caret
);
}
return
nullptr
;
}
void
::
GuiDocumentElementRenderer
::
(
,
,
bool
)
{
(
);
;
;
=
;
<
>
=
.
];
if
(
cache
&&
cache
)
{
cache
(
.
,
,
);
}
}
void
::
GuiDocumentElementRenderer
::
(
)
{
if
(
(-
1
, -
1
))
{
if
(
0
<=
.
&&
.
<
.
())
{
<
>
=
.
];
if
(
cache
&&
cache
)
{
cache
();
}
}
}
;
}
void
::
GuiDocumentElementRenderer
::
(
,
)
{
if
(
)
{
=
;
;
t
;
}
if
(
)
{
(-
1
, -
1
);
(-
1
, -
1
);
}
if
(!
)
return
;
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
.
<=
i
&&
i
<=
.
)
{
<
>
=
(
i
,
false
);
=
i
==
.
?
.
:
0
;
=
i
==
.
?
.
:
cache
.
();
if
(
cache
!=
newBegin
||
cache
!=
newEnd
)
{
cache
=
newBegin
;
cache
=
newEnd
;
(
i
,
1
,
1
,
false
);
}
}
else
{
<
>
=
i
];
if
(
cache
)
{
if
(
cache
!=-
1
||
cache
!=-
1
)
{
cache
=-
1
;
cache
=-
1
;
(
i
,
1
,
1
,
false
);
}
}
}
}
}
::
GuiDocumentElementRenderer
::
(
,
::
,
bool
&
)
{
if
(!
)
return
;
<
>
=
(
.
,
true
);
if
(
cache
)
{
switch
(
)
{
case
::
:
{
=
false
;
=
cache
(
0
,
::
,
);
return
(
.
,
caret
);
}
case
::
:
{
=
true
;
=
cache
(
0
,
::
,
);
return
(
.
,
caret
);
}
case
::
:
{
=
false
;
=
cache
(
.
,
::
,
);
return
(
.
,
caret
);
}
case
::
:
{
=
true
;
=
cache
(
.
,
::
,
);
return
(
.
,
caret
);
}
case
::
:
{
=
cache
(
.
,
::
,
);
if
(
caret
==
.
&&
.
>
0
)
{
=
cache
(
.
,
);
<
>
=
(
.
-
1
,
true
);
=
anotherCache
();
caret
=
anotherCache
(
(
caretBounds
.
,
height
));
return
(
.
-
1
,
caret
);
}
else
{
return
(
.
,
caret
);
}
}
case
::
:
{
=
cache
(
.
,
::
,
);
if
(
caret
==
.
&&
.
<
.
()-
1
)
{
=
cache
(
.
,
);
<
>
=
(
.
+
1
,
true
);
caret
=
anotherCache
(
(
caretBounds
.
,
0
));
return
(
.
+
1
,
caret
);
}
else
{
return
(
.
,
caret
);
}
}
case
::
:
{
=
false
;
=
cache
(
.
,
::
,
);
if
(
caret
==
.
&&
.
>
0
)
{
<
>
=
(
.
-
1
,
true
);
caret
=
anotherCache
(
0
,
::
,
);
return
(
.
-
1
,
caret
);
}
else
{
return
(
.
,
caret
);
}
}
case
::
:
{
=
true
;
=
cache
(
.
,
::
,
);
if
(
caret
==
.
&&
.
<
.
()-
1
)
{
<
>
=
(
.
+
1
,
true
);
caret
=
anotherCache
(
0
,
::
,
);
return
(
.
+
1
,
caret
);
}
else
{
return
(
.
,
caret
);
}
}
}
}
return
;
}
::
GuiDocumentElementRenderer
::
(
)
{
if
(!
)
return
(-
1
, -
1
);
=
0
;
=-
1
;
if
(
GetParagraphIndexFromPoint
(
,
top
,
index
))
{
<
>
=
(
index
,
true
);
(
.
,
.
-
top
);
=
cache
(
paragraphPoint
);
return
(
index
,
caret
);
}
return
(-
1
, -
1
);
}
::
GuiDocumentElementRenderer
::
(
,
bool
)
{
if
(!
)
return
();
<
>
=
(
.
,
true
);
if
(
cache
)
{
=
cache
(
.
,
);
if
(
bounds
())
{
=
0
;
for
(
=
0
;
i
<
.
;
i
++)
{
(
i
,
true
);
y
+=
i
]+
;
}
bounds
.
+=
y
;
bounds
.
+=
y
;
return
bounds
;
}
}
return
();
}
void
::
()
{
auto
=
.
<
GuiDocumentElementRenderer
>();
if
(
elementRenderer
)
{
elementRenderer
(
,
);
if
(
)
{
elementRenderer
(
,
,
);
}
else
{
elementRenderer
(
);
}
InvokeOnCompositionStateChanged
();
}
}
::
()
:caretVisible(
false
)
,caretFrontSide(
false
)
{
}
::
*
::
()
{
return
;
}
void
::
(
*
)
{
=
;
}
<
>
::
()
{
return
;
}
void
::
(
<
>
)
{
;
InvokeOnElementStateChanged
();
(
(),
(),
false
);
}
::
()
{
return
;
}
::
()
{
return
;
}
bool
::
IsCaretEndPreferFrontSide
()
{
return
;
}
void
::
(
,
,
bool
)
{
;
;
if
(
)
{
=
true
;
}
else
if
(
)
{
=
false
;
}
else
{
=
;
}
();
}
bool
::
()
{
return
;
}
void
::
(
bool
)
{
=
;
();
}
::
()
{
return
;
}
void
::
(
)
{
;
();
}
::
(
,
::
,
bool
&
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
=
elementRenderer
(
,
,
);
return
caret
.
==-
1
?
:
caret
;
}
else
{
return
;
}
}
::
(
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
return
elementRenderer
(
);
}
else
{
return
(
0
,
0
);
}
}
::
(
,
bool
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
return
elementRenderer
(
,
);
}
else
{
return
();
}
}
void
::
(
,
,
,
bool
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
elementRenderer
(
,
,
,
);
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
,
<
>
,
bool
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
=
(
,
,
,
);
if
(
newRows
!= -
1
)
{
elementRenderer
(
.
,
.
-
.
+
1
,
newRows
,
true
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
,
bool
,
const
collections
::
<
>&
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
=
(
,
,
,
);
if
(
newRows
!= -
1
)
{
elementRenderer
(
.
,
.
-
.
+
1
,
newRows
,
true
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
,
<
>
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
if
(
(
,
,
))
{
elementRenderer
(
.
,
.
-
.
+
1
,
.
-
.
+
1
,
false
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
,
<
>
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
if
(
(
,
,
))
{
elementRenderer
(
.
,
.
-
.
+
1
,
1
,
true
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
,
,
const
&
,
const
&
,
const
&
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
>
)
{
=
;
=
;
=
temp
;
}
if
(
(
,
,
,
,
,
))
{
elementRenderer
(
,
1
,
1
,
false
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
,
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
>
)
{
=
;
=
;
=
temp
;
}
if
(
(
,
,
))
{
elementRenderer
(
,
1
,
1
,
false
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
,
const
&
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
if
(
(
,
,
))
{
elementRenderer
(
.
,
.
-
.
+
1
,
.
-
.
+
1
,
false
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
,
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
if
(
(
,
))
{
elementRenderer
(
.
,
.
-
.
+
1
,
.
-
.
+
1
,
false
);
}
InvokeOnCompositionStateChanged
();
}
}
void
::
(
const
&
,
const
&
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
(
,
);
}
}
void
::
(
,
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
if
(
(
,
))
{
elementRenderer
(
.
,
.
-
.
+
1
,
.
-
.
+
1
,
false
);
}
InvokeOnCompositionStateChanged
();
}
}
<
>
::
(
,
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
return
(
,
);
}
return
nullptr
;
}
<
>
::
(
,
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
return
(
,
);
}
return
{};
}
void
::
(
,
,
const
collections
::
<
<
>>&
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
=
.
;
=
.
;
if
(
first
>
last
)
{
=
first
;
first
=
last
;
last
=
temp
;
}
if
(
0
<=
first
&&
first
<
.
() &&
0
<=
last
&&
last
<
.
() &&
last
-
first
+
1
==
.
())
{
for
(
=
first
;
i
<=
last
;
i
++)
{
i
]
i
-
first
];
}
elementRenderer
(
first
,
.
(),
.
(),
false
);
}
InvokeOnCompositionStateChanged
();
}
}
<
>
::
SummarizeParagraphAlignment
(
,
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
if
(
)
{
=
;
;
temp
;
}
return
SummarizeParagraphAlignment
(
,
);
}
return
{};
}
<
::
>
::
(
)
{
if
(
auto
=
.
<
GuiDocumentElementRenderer
>())
{
return
elementRenderer
(
);
}
return
nullptr
;
}
}
}
}