1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTEXTVIEW_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTEXTVIEW_HXX
23 #include "PresenterTheme.hxx"
24 #include <com/sun/star/accessibility/TextSegment.hpp>
25 #include <com/sun/star/awt/Point.hpp>
26 #include <com/sun/star/awt/Size.hpp>
27 #include <com/sun/star/geometry/RealPoint2D.hpp>
28 #include <com/sun/star/geometry/RealSize2D.hpp>
29 #include <com/sun/star/i18n/XBreakIterator.hpp>
30 #include <com/sun/star/i18n/XScriptTypeDetector.hpp>
31 #include <com/sun/star/rendering/XCanvas.hpp>
32 #include <com/sun/star/text/XText.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
37 namespace sdext::presenter
{
39 class PresenterTextCaret
43 css::uno::Reference
<css::uno::XComponentContext
> const& xContext
,
44 ::std::function
<css::awt::Rectangle (const sal_Int32
,const sal_Int32
)>
45 aCharacterBoundsAccess
,
46 ::std::function
<void (const css::awt::Rectangle
&)>
48 ~PresenterTextCaret();
53 sal_Int32
GetParagraphIndex() const { return mnParagraphIndex
;}
54 sal_Int32
GetCharacterIndex() const { return mnCharacterIndex
;}
56 const sal_Int32 nParagraphIndex
,
57 const sal_Int32 nCharacterIndex
);
59 bool IsVisible() const { return mbIsCaretVisible
;}
61 /** Set a (possibly empty) functor that broadcasts changes of the caret
62 position. This is used when a PresenterTextView object is set at
63 the accessibility object so that accessibility events can be sent
64 when the caret changes position.
66 void SetCaretMotionBroadcaster (
67 const ::std::function
<void (sal_Int32
,sal_Int32
,sal_Int32
,sal_Int32
)>& rBroadcaster
);
69 const css::awt::Rectangle
& GetBounds() const;
72 css::uno::Reference
<css::uno::XComponentContext
> const& m_xContext
;
73 sal_Int32 mnParagraphIndex
;
74 sal_Int32 mnCharacterIndex
;
75 sal_Int32 mnCaretBlinkTaskId
;
76 bool mbIsCaretVisible
;
77 const ::std::function
<css::awt::Rectangle (const sal_Int32
,const sal_Int32
)> maCharacterBoundsAccess
;
78 const ::std::function
<void (const css::awt::Rectangle
&)> maInvalidator
;
79 ::std::function
<void (sal_Int32
,sal_Int32
,sal_Int32
,sal_Int32
)> maBroadcaster
;
80 css::awt::Rectangle maCaretBounds
;
84 typedef std::shared_ptr
<PresenterTextCaret
> SharedPresenterTextCaret
;
86 //===== PresenterTextParagraph ================================================
88 class PresenterTextParagraph
91 PresenterTextParagraph (
92 const sal_Int32 nParagraphIndex
,
93 const css::uno::Reference
<css::i18n::XBreakIterator
>& rxBreakIterator
,
94 const css::uno::Reference
<css::i18n::XScriptTypeDetector
>& rxScriptTypeDetector
,
95 const css::uno::Reference
<css::text::XTextRange
>& rxTextRange
,
96 SharedPresenterTextCaret xCaret
);
99 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
100 const css::geometry::RealSize2D
& rSize
,
101 const PresenterTheme::SharedFontDescriptor
& rpFont
,
102 const css::rendering::ViewState
& rViewState
,
103 css::rendering::RenderState
& rRenderState
,
104 const double nTopOffset
,
105 const double nClipTop
,
106 const double nClipBottom
);
108 double GetTotalTextHeight() const;
110 void SetCharacterOffset (const sal_Int32 nCharacterOffset
);
111 sal_Int32
GetCharacterCount() const;
112 sal_Unicode
GetCharacter (const sal_Int32 nGlobalCharacterIndex
) const;
113 const OUString
& GetText() const;
114 css::accessibility::TextSegment
GetTextSegment (
115 const sal_Int32 nOffset
,
116 const sal_Int32 nGlobalCharacterIndex
,
117 const sal_Int16 nTextType
) const;
118 css::accessibility::TextSegment
GetWordTextSegment (
119 const sal_Int32 nOffset
,
120 const sal_Int32 nIndex
) const;
121 css::accessibility::TextSegment
CreateTextSegment (
122 sal_Int32 nStartIndex
,
123 sal_Int32 nEndIndex
) const;
124 css::awt::Rectangle
GetCharacterBounds (
125 sal_Int32 nGlobalCharacterIndex
,
126 const bool bCaretBox
);
127 void SetupCellArray (
128 const PresenterTheme::SharedFontDescriptor
& rpFont
);
132 const PresenterTheme::SharedFontDescriptor
& rpFont
);
133 sal_Int32
GetWordBoundary(
134 const sal_Int32 nLocalCharacterIndex
,
135 const sal_Int32 nDistance
);
136 sal_Int32
GetCaretPosition() const;
137 void SetCaretPosition (const sal_Int32 nPosition
) const;
138 void SetOrigin (const double nXOrigin
, const double nYOrigin
);
139 css::awt::Point
GetRelativeLocation() const;
140 css::awt::Size
GetSize() const;
143 OUString msParagraphText
;
144 const sal_Int32 mnParagraphIndex
;
145 SharedPresenterTextCaret mpCaret
;
147 /** A portion of a string that encodes one unicode cell. It describes
148 number of characters in the unicode string that make up the cell and its
149 width in pixel (with respect to some configuration that is stored
150 externally or implicitly).
155 Cell (const sal_Int32 nCharacterIndex
, const sal_Int32 nCharacterCount
, const double nCellWidth
);
156 sal_Int32 mnCharacterIndex
;
157 sal_Int32 mnCharacterCount
;
164 Line (const sal_Int32 nLineStartCharacterIndex
, const sal_Int32 nLineEndCharacterIndex
);
165 sal_Int32 mnLineStartCharacterIndex
;
166 sal_Int32 mnLineEndCharacterIndex
;
167 sal_Int32 mnLineStartCellIndex
;
168 sal_Int32 mnLineEndCellIndex
;
169 css::uno::Reference
<css::rendering::XTextLayout
> mxLayoutedLine
;
172 css::uno::Sequence
<css::geometry::RealRectangle2D
> maCellBoxes
;
174 void ProvideLayoutedLine (
175 const OUString
& rsParagraphText
,
176 const PresenterTheme::SharedFontDescriptor
& rpFont
,
177 const sal_Int8 nTextDirection
);
178 void ProvideCellBoxes();
181 css::uno::Reference
<css::i18n::XBreakIterator
> mxBreakIterator
;
182 css::uno::Reference
<css::i18n::XScriptTypeDetector
> mxScriptTypeDetector
;
183 ::std::vector
<Line
> maLines
;
184 ::std::vector
<sal_Int32
> maWordBoundaries
;
185 // Offset of the top of the paragraph with respect to the origin of the
186 // whole text (specified by mnXOrigin and mnYOrigin).
187 double mnVerticalOffset
;
194 sal_Int8 mnWritingMode
;
195 /// The index of the first character in this paragraph with respect to
197 sal_Int32 mnCharacterOffset
;
198 ::std::vector
<Cell
> maCells
;
202 css::i18n::Boundary
& rCurrentLine
,
203 const sal_Int32 nWordBoundary
,
204 const PresenterTheme::SharedFontDescriptor
& rpFont
);
206 css::i18n::Boundary
& rCurrentLine
);
207 sal_Int8
GetTextDirection() const;
208 bool IsTextReferencePointLeft() const;
210 typedef std::shared_ptr
<PresenterTextParagraph
> SharedPresenterTextParagraph
;
212 /** A simple text view that paints text onto a given canvas.
214 class PresenterTextView
219 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
220 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
221 const ::std::function
<void (const css::awt::Rectangle
&)>& rInvalidator
);
222 void SetText (const css::uno::Reference
<css::text::XText
>& rxText
);
223 void SetTextChangeBroadcaster(const ::std::function
<void ()>& rBroadcaster
);
225 void SetLocation (const css::geometry::RealPoint2D
& rLocation
);
226 void SetSize (const css::geometry::RealSize2D
& rSize
);
227 double GetTotalTextHeight();
229 void SetFont (const PresenterTheme::SharedFontDescriptor
& rpFont
);
235 /** Move the caret forward or backward by character or by word.
237 Should be either -1 or +1 to move caret backwards or forwards,
241 css::accessibility::AccessibleTextType constants.
244 const sal_Int32 nDistance
,
245 const sal_Int16 nTextType
);
247 void Paint (const css::awt::Rectangle
& rUpdateBox
);
249 const SharedPresenterTextCaret
& GetCaret() const;
251 sal_Int32
GetParagraphCount() const;
252 SharedPresenterTextParagraph
GetParagraph (const sal_Int32 nParagraphIndex
) const;
255 css::uno::Reference
<css::rendering::XCanvas
> mxCanvas
;
256 css::uno::Reference
<css::i18n::XBreakIterator
> mxBreakIterator
;
257 css::uno::Reference
<css::i18n::XScriptTypeDetector
> mxScriptTypeDetector
;
258 css::geometry::RealPoint2D maLocation
;
259 css::geometry::RealSize2D maSize
;
260 PresenterTheme::SharedFontDescriptor mpFont
;
261 ::std::vector
<SharedPresenterTextParagraph
> maParagraphs
;
262 SharedPresenterTextCaret mpCaret
;
265 bool mbIsFormatPending
;
266 ::std::function
<void ()> maTextChangeBroadcaster
;
268 void RequestFormat();
270 css::awt::Rectangle
GetCaretBounds (
271 const sal_Int32 nParagraphIndex
,
272 const sal_Int32 nCharacterIndex
) const;
275 } // end of namespace ::sdext::presenter
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */