LibreOffice Module sdext (master)  1
PresenterTextView.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTEXTVIEW_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTEXTVIEW_HXX
22 
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>
34 
35 #include <functional>
36 
37 namespace sdext::presenter {
38 
40 {
41 public:
43  css::uno::Reference<css::uno::XComponentContext> const& xContext,
44  const ::std::function<css::awt::Rectangle (const sal_Int32,const sal_Int32)>&
45  rCharacterBoundsAccess,
46  const ::std::function<void (const css::awt::Rectangle&)>&
47  rInvalidator);
49 
50  void ShowCaret();
51  void HideCaret();
52 
53  sal_Int32 GetParagraphIndex() const { return mnParagraphIndex;}
54  sal_Int32 GetCharacterIndex() const { return mnCharacterIndex;}
55  void SetPosition (
56  const sal_Int32 nParagraphIndex,
57  const sal_Int32 nCharacterIndex);
58 
59  bool IsVisible() const { return mbIsCaretVisible;}
60 
67  const ::std::function<void (sal_Int32,sal_Int32,sal_Int32,sal_Int32)>& rBroadcaster);
68 
69  const css::awt::Rectangle& GetBounds() const;
70 
71 private:
72  css::uno::Reference<css::uno::XComponentContext> const& m_xContext;
73  sal_Int32 mnParagraphIndex;
74  sal_Int32 mnCharacterIndex;
75  sal_Int32 mnCaretBlinkTaskId;
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;
81 
82  void InvertCaret();
83 };
84 typedef std::shared_ptr<PresenterTextCaret> SharedPresenterTextCaret;
85 
86 //===== PresenterTextParagraph ================================================
87 
89 {
90 public:
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  const SharedPresenterTextCaret& rpCaret);
97 
98  void Paint (
99  const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
100  const css::geometry::RealSize2D& rSize,
102  const css::rendering::ViewState& rViewState,
103  css::rendering::RenderState& rRenderState,
104  const double nTopOffset,
105  const double nClipTop,
106  const double nClipBottom);
107 
108  double GetTotalTextHeight() const;
109 
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 (
129  void Format (
130  const double nY,
131  const double nWidth,
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;
141 
142 private:
143  OUString msParagraphText;
144  const sal_Int32 mnParagraphIndex;
145  SharedPresenterTextCaret mpCaret;
146 
152  class Cell
153  {
154  public:
155  Cell (const sal_Int32 nCharacterIndex, const sal_Int32 nCharacterCount, const double nCellWidth);
156  sal_Int32 mnCharacterIndex;
157  sal_Int32 mnCharacterCount;
158  double mnCellWidth;
159  };
160 
161  class Line
162  {
163  public:
164  Line (const sal_Int32 nLineStartCharacterIndex, const sal_Int32 nLineEndCharacterIndex);
169  css::uno::Reference<css::rendering::XTextLayout> mxLayoutedLine;
170  double mnBaseLine;
171  double mnWidth;
172  css::uno::Sequence<css::geometry::RealRectangle2D> maCellBoxes;
173 
174  void ProvideLayoutedLine (
175  const OUString& rsParagraphText,
177  const sal_Int8 nTextDirection);
178  void ProvideCellBoxes();
179  };
180 
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).
188  double mnXOrigin;
189  double mnYOrigin;
190  double mnWidth;
191  double mnAscent;
192  double mnDescent;
193  double mnLineHeight;
197  sal_Int32 mnCharacterOffset;
198  ::std::vector<Cell> maCells;
199 
200  void AddWord (
201  const double nWidth,
202  css::i18n::Boundary& rCurrentLine,
203  const sal_Int32 nWordBoundary,
205  void AddLine (
206  css::i18n::Boundary& rCurrentLine);
207  sal_Int8 GetTextDirection() const;
208  bool IsTextReferencePointLeft() const;
209 };
210 typedef std::shared_ptr<PresenterTextParagraph> SharedPresenterTextParagraph;
211 
215 {
216 public:
217 
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);
224 
225  void SetLocation (const css::geometry::RealPoint2D& rLocation);
226  void SetSize (const css::geometry::RealSize2D& rSize);
227  double GetTotalTextHeight();
228 
229  void SetFont (const PresenterTheme::SharedFontDescriptor& rpFont);
230 
231  void SetOffset (
232  const double nLeft,
233  const double nTop);
234 
243  void MoveCaret (
244  const sal_Int32 nDistance,
245  const sal_Int16 nTextType);
246 
247  void Paint (const css::awt::Rectangle& rUpdateBox);
248 
249  const SharedPresenterTextCaret& GetCaret() const;
250 
251  sal_Int32 GetParagraphCount() const;
252  SharedPresenterTextParagraph GetParagraph (const sal_Int32 nParagraphIndex) const;
253 
254 private:
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;
261  ::std::vector<SharedPresenterTextParagraph> maParagraphs;
262  SharedPresenterTextCaret mpCaret;
263  double mnLeftOffset;
264  double mnTopOffset;
266  ::std::function<void ()> maTextChangeBroadcaster;
267 
268  void RequestFormat();
269  void Format();
270  css::awt::Rectangle GetCaretBounds (
271  const sal_Int32 nParagraphIndex,
272  const sal_Int32 nCharacterIndex) const;
273 };
274 
275 } // end of namespace ::sdext::presenter
276 
277 #endif
278 
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::rendering::XCanvas > mxCanvas
css::accessibility::TextSegment GetTextSegment(const sal_Int32 nOffset, const sal_Int32 nGlobalCharacterIndex, const sal_Int16 nTextType) const
std::shared_ptr< FontDescriptor > SharedFontDescriptor
sal_Int32 nIndex
css::uno::Reference< css::uno::XComponentContext > const & m_xContext
::std::function< void()> maTextChangeBroadcaster
signed char sal_Int8
void SetCaretPosition(const sal_Int32 nPosition) const
PresenterTextCaret(css::uno::Reference< css::uno::XComponentContext > const &xContext, const ::std::function< css::awt::Rectangle(const sal_Int32, const sal_Int32)> &rCharacterBoundsAccess, const ::std::function< void(const css::awt::Rectangle &)> &rInvalidator)
void SetCaretMotionBroadcaster(const ::std::function< void(sal_Int32, sal_Int32, sal_Int32, sal_Int32)> &rBroadcaster)
Set a (possibly empty) functor that broadcasts changes of the caret position.
A portion of a string that encodes one unicode cell.
void ProvideLayoutedLine(const OUString &rsParagraphText, const PresenterTheme::SharedFontDescriptor &rpFont, const sal_Int8 nTextDirection)
css::awt::Rectangle GetCharacterBounds(sal_Int32 nGlobalCharacterIndex, const bool bCaretBox)
const css::awt::Rectangle & GetBounds() const
sal_uInt16 sal_Unicode
void SetText(const css::uno::Reference< css::text::XText > &rxText)
void SetOffset(const double nLeft, const double nTop)
css::uno::Reference< css::rendering::XTextLayout > mxLayoutedLine
Line(const sal_Int32 nLineStartCharacterIndex, const sal_Int32 nLineEndCharacterIndex)
const ::std::function< css::awt::Rectangle(const sal_Int32, const sal_Int32)> maCharacterBoundsAccess
PresenterTextParagraph(const sal_Int32 nParagraphIndex, const css::uno::Reference< css::i18n::XBreakIterator > &rxBreakIterator, const css::uno::Reference< css::i18n::XScriptTypeDetector > &rxScriptTypeDetector, const css::uno::Reference< css::text::XTextRange > &rxTextRange, const SharedPresenterTextCaret &rpCaret)
sal_Int32 GetWordBoundary(const sal_Int32 nLocalCharacterIndex, const sal_Int32 nDistance)
sal_Int32 mnCharacterOffset
The index of the first character in this paragraph with respect to the whole text.
css::uno::Reference< css::i18n::XScriptTypeDetector > mxScriptTypeDetector
const SharedPresenterTextCaret & GetCaret() const
css::uno::Sequence< css::geometry::RealRectangle2D > maCellBoxes
void SetupCellArray(const PresenterTheme::SharedFontDescriptor &rpFont)
const sal_Int32 nCellWidth
void Paint(const css::awt::Rectangle &rUpdateBox)
css::accessibility::TextSegment CreateTextSegment(sal_Int32 nStartIndex, sal_Int32 nEndIndex) const
Cell(const sal_Int32 nCharacterIndex, const sal_Int32 nCharacterCount, const double nCellWidth)
css::accessibility::TextSegment GetWordTextSegment(const sal_Int32 nOffset, const sal_Int32 nIndex) const
void Paint(const css::uno::Reference< css::rendering::XCanvas > &rxCanvas, const css::geometry::RealSize2D &rSize, const PresenterTheme::SharedFontDescriptor &rpFont, const css::rendering::ViewState &rViewState, css::rendering::RenderState &rRenderState, const double nTopOffset, const double nClipTop, const double nClipBottom)
void AddWord(const double nWidth, css::i18n::Boundary &rCurrentLine, const sal_Int32 nWordBoundary, const PresenterTheme::SharedFontDescriptor &rpFont)
css::uno::Reference< css::i18n::XScriptTypeDetector > mxScriptTypeDetector
void SetFont(const PresenterTheme::SharedFontDescriptor &rpFont)
SharedPresenterTextParagraph GetParagraph(const sal_Int32 nParagraphIndex) const
css::awt::Rectangle GetCaretBounds(const sal_Int32 nParagraphIndex, const sal_Int32 nCharacterIndex) const
void SetTextChangeBroadcaster(const ::std::function< void()> &rBroadcaster)
std::shared_ptr< PresenterTextCaret > SharedPresenterTextCaret
void SetPosition(const sal_Int32 nParagraphIndex, const sal_Int32 nCharacterIndex)
void AddLine(css::i18n::Boundary &rCurrentLine)
void SetLocation(const css::geometry::RealPoint2D &rLocation)
::std::function< void(sal_Int32, sal_Int32, sal_Int32, sal_Int32)> maBroadcaster
PresenterTheme::SharedFontDescriptor mpFont
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator
void Format(const double nY, const double nWidth, const PresenterTheme::SharedFontDescriptor &rpFont)
void MoveCaret(const sal_Int32 nDistance, const sal_Int16 nTextType)
Move the caret forward or backward by character or by word.
css::geometry::RealPoint2D maLocation
A simple text view that paints text onto a given canvas.
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator
const ::std::function< void(const css::awt::Rectangle &)> maInvalidator
void SetCharacterOffset(const sal_Int32 nCharacterOffset)
PresenterTextView(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::rendering::XCanvas > &rxCanvas, const ::std::function< void(const css::awt::Rectangle &)> &rInvalidator)
sal_Unicode GetCharacter(const sal_Int32 nGlobalCharacterIndex) const
std::shared_ptr< PresenterTextParagraph > SharedPresenterTextParagraph
void SetSize(const css::geometry::RealSize2D &rSize)
::std::vector< SharedPresenterTextParagraph > maParagraphs
void SetOrigin(const double nXOrigin, const double nYOrigin)