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/XAccessibleText.hpp>
25 #include <com/sun/star/awt/Size.hpp>
26 #include <com/sun/star/geometry/RealPoint2D.hpp>
27 #include <com/sun/star/geometry/RealSize2D.hpp>
28 #include <com/sun/star/i18n/XBreakIterator.hpp>
29 #include <com/sun/star/i18n/XScriptTypeDetector.hpp>
30 #include <com/sun/star/rendering/XCanvas.hpp>
31 #include <com/sun/star/style/ParagraphAdjust.hpp>
32 #include <com/sun/star/text/XText.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <cppuhelper/basemutex.hxx>
38 namespace sdext
{ namespace presenter
{
40 class PresenterTextCaret
44 css::uno::Reference
<css::uno::XComponentContext
> const& xContext
,
45 const ::std::function
<css::awt::Rectangle (const sal_Int32
,const sal_Int32
)>&
46 rCharacterBoundsAccess
,
47 const ::std::function
<void (const css::awt::Rectangle
&)>&
49 ~PresenterTextCaret();
54 sal_Int32
GetParagraphIndex() const { return mnParagraphIndex
;}
55 sal_Int32
GetCharacterIndex() const { return mnCharacterIndex
;}
57 const sal_Int32 nParagraphIndex
,
58 const sal_Int32 nCharacterIndex
);
60 bool IsVisible() const { return mbIsCaretVisible
;}
62 /** Set a (possibly empty) functor that broadcasts changes of the caret
63 position. This is used when a PresenterTextView object is set at
64 the accessibility object so that accessibility events can be sent
65 when the caret changes position.
67 void SetCaretMotionBroadcaster (
68 const ::std::function
<void (sal_Int32
,sal_Int32
,sal_Int32
,sal_Int32
)>& rBroadcaster
);
70 const css::awt::Rectangle
& GetBounds() const;
73 css::uno::Reference
<css::uno::XComponentContext
> const& m_xContext
;
74 sal_Int32 mnParagraphIndex
;
75 sal_Int32 mnCharacterIndex
;
76 sal_Int32 mnCaretBlinkTaskId
;
77 bool mbIsCaretVisible
;
78 const ::std::function
<css::awt::Rectangle (const sal_Int32
,const sal_Int32
)> maCharacterBoundsAccess
;
79 const ::std::function
<void (const css::awt::Rectangle
&)> maInvalidator
;
80 ::std::function
<void (sal_Int32
,sal_Int32
,sal_Int32
,sal_Int32
)> maBroadcaster
;
81 css::awt::Rectangle maCaretBounds
;
85 typedef std::shared_ptr
<PresenterTextCaret
> SharedPresenterTextCaret
;
87 //===== PresenterTextParagraph ================================================
89 class PresenterTextParagraph
92 PresenterTextParagraph (
93 const sal_Int32 nParagraphIndex
,
94 const css::uno::Reference
<css::i18n::XBreakIterator
>& rxBreakIterator
,
95 const css::uno::Reference
<css::i18n::XScriptTypeDetector
>& rxScriptTypeDetector
,
96 const css::uno::Reference
<css::text::XTextRange
>& rxTextRange
,
97 const SharedPresenterTextCaret
& rpCaret
);
100 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
101 const css::geometry::RealSize2D
& rSize
,
102 const PresenterTheme::SharedFontDescriptor
& rpFont
,
103 const css::rendering::ViewState
& rViewState
,
104 css::rendering::RenderState
& rRenderState
,
105 const double nTopOffset
,
106 const double nClipTop
,
107 const double nClipBottom
);
109 double GetTotalTextHeight();
111 void SetCharacterOffset (const sal_Int32 nCharacterOffset
);
112 sal_Int32
GetCharacterCount() const;
113 sal_Unicode
GetCharacter (const sal_Int32 nGlobalCharacterIndex
) const;
114 const OUString
& GetText() const;
115 css::accessibility::TextSegment
GetTextSegment (
116 const sal_Int32 nOffset
,
117 const sal_Int32 nGlobalCharacterIndex
,
118 const sal_Int16 nTextType
) const;
119 css::accessibility::TextSegment
GetWordTextSegment (
120 const sal_Int32 nOffset
,
121 const sal_Int32 nIndex
) const;
122 css::accessibility::TextSegment
CreateTextSegment (
123 sal_Int32 nStartIndex
,
124 sal_Int32 nEndIndex
) const;
125 css::awt::Rectangle
GetCharacterBounds (
126 sal_Int32 nGlobalCharacterIndex
,
127 const bool bCaretBox
);
128 void SetupCellArray (
129 const PresenterTheme::SharedFontDescriptor
& rpFont
);
133 const PresenterTheme::SharedFontDescriptor
& rpFont
);
134 sal_Int32
GetWordBoundary(
135 const sal_Int32 nLocalCharacterIndex
,
136 const sal_Int32 nDistance
);
137 sal_Int32
GetCaretPosition() const;
138 void SetCaretPosition (const sal_Int32 nPosition
) const;
139 void SetOrigin (const double nXOrigin
, const double nYOrigin
);
140 css::awt::Point
GetRelativeLocation() const;
141 css::awt::Size
GetSize();
144 OUString msParagraphText
;
145 const sal_Int32 mnParagraphIndex
;
146 SharedPresenterTextCaret mpCaret
;
148 /** A portion of a string that encodes one unicode cell. It describes
149 number of characters in the unicode string that make up the cell and its
150 width in pixel (with respect to some configuration that is stored
151 externally or implicitly).
156 Cell (const sal_Int32 nCharacterIndex
, const sal_Int32 nCharacterCount
, const double nCellWidth
);
157 sal_Int32
const mnCharacterIndex
;
158 sal_Int32
const mnCharacterCount
;
159 double const mnCellWidth
;
165 Line (const sal_Int32 nLineStartCharacterIndex
, const sal_Int32 nLineEndCharacterIndex
);
166 sal_Int32
const mnLineStartCharacterIndex
;
167 sal_Int32
const mnLineEndCharacterIndex
;
168 sal_Int32 mnLineStartCellIndex
;
169 sal_Int32 mnLineEndCellIndex
;
170 css::uno::Reference
<css::rendering::XTextLayout
> mxLayoutedLine
;
173 css::uno::Sequence
<css::geometry::RealRectangle2D
> maCellBoxes
;
175 void ProvideLayoutedLine (
176 const OUString
& rsParagraphText
,
177 const PresenterTheme::SharedFontDescriptor
& rpFont
,
178 const sal_Int8 nTextDirection
);
179 void ProvideCellBoxes();
182 css::uno::Reference
<css::i18n::XBreakIterator
> mxBreakIterator
;
183 css::uno::Reference
<css::i18n::XScriptTypeDetector
> mxScriptTypeDetector
;
184 ::std::vector
<Line
> maLines
;
185 ::std::vector
<sal_Int32
> maWordBoundaries
;
186 // Offset of the top of the paragraph with respect to the origin of the
187 // whole text (specified by mnXOrigin and mnYOrigin).
188 double mnVerticalOffset
;
195 sal_Int8 mnWritingMode
;
196 /// The index of the first character in this paragraph with respect to
198 sal_Int32 mnCharacterOffset
;
199 ::std::vector
<Cell
> maCells
;
203 css::i18n::Boundary
& rCurrentLine
,
204 const sal_Int32 nWordBoundary
,
205 const PresenterTheme::SharedFontDescriptor
& rpFont
);
207 css::i18n::Boundary
& rCurrentLine
);
208 sal_Int8
GetTextDirection() const;
209 bool IsTextReferencePointLeft() const;
211 typedef std::shared_ptr
<PresenterTextParagraph
> SharedPresenterTextParagraph
;
213 /** A simple text view that paints text onto a given canvas.
215 class PresenterTextView
220 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
221 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
222 const ::std::function
<void (const css::awt::Rectangle
&)>& rInvalidator
);
223 void SetText (const css::uno::Reference
<css::text::XText
>& rxText
);
224 void SetTextChangeBroadcaster(const ::std::function
<void ()>& rBroadcaster
);
226 void SetLocation (const css::geometry::RealPoint2D
& rLocation
);
227 void SetSize (const css::geometry::RealSize2D
& rSize
);
228 double GetTotalTextHeight();
230 void SetFont (const PresenterTheme::SharedFontDescriptor
& rpFont
);
236 /** Move the caret forward or backward by character or by word.
238 Should be either -1 or +1 to move caret backwards or forwards,
242 css::accessibility::AccessibleTextType constants.
245 const sal_Int32 nDistance
,
246 const sal_Int16 nTextType
);
248 void Paint (const css::awt::Rectangle
& rUpdateBox
);
250 const SharedPresenterTextCaret
& GetCaret() const;
252 sal_Int32
GetParagraphCount() const;
253 SharedPresenterTextParagraph
GetParagraph (const sal_Int32 nParagraphIndex
) const;
256 css::uno::Reference
<css::rendering::XCanvas
> mxCanvas
;
257 css::uno::Reference
<css::i18n::XBreakIterator
> mxBreakIterator
;
258 css::uno::Reference
<css::i18n::XScriptTypeDetector
> mxScriptTypeDetector
;
259 css::geometry::RealPoint2D maLocation
;
260 css::geometry::RealSize2D maSize
;
261 PresenterTheme::SharedFontDescriptor mpFont
;
262 ::std::vector
<SharedPresenterTextParagraph
> maParagraphs
;
263 SharedPresenterTextCaret mpCaret
;
266 bool mbIsFormatPending
;
267 ::std::function
<void ()> maTextChangeBroadcaster
;
269 void RequestFormat();
271 css::awt::Rectangle
GetCaretBounds (
272 const sal_Int32 nParagraphIndex
,
273 const sal_Int32 nCharacterIndex
) const;
276 } } // end of namespace ::sdext::presenter
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */