LibreOffice Module sd (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
37namespace sdext::presenter {
38
40{
41public:
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&)>
47 aInvalidator);
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
71private:
72 css::uno::Reference<css::uno::XComponentContext> const& m_xContext;
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};
84typedef std::shared_ptr<PresenterTextCaret> SharedPresenterTextCaret;
85
86//===== PresenterTextParagraph ================================================
87
89{
90public:
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,
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
142private:
144 const sal_Int32 mnParagraphIndex;
146
152 class Cell
153 {
154 public:
155 Cell (const sal_Int32 nCharacterIndex, const sal_Int32 nCharacterCount, const double nCellWidth);
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;
171 double mnWidth;
172 css::uno::Sequence<css::geometry::RealRectangle2D> maCellBoxes;
173
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;
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);
208 bool IsTextReferencePointLeft() const;
209};
210typedef std::shared_ptr<PresenterTextParagraph> SharedPresenterTextParagraph;
211
215{
216public:
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
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
254private:
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;
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: */
const css::awt::Rectangle & GetBounds() const
css::uno::Reference< css::uno::XComponentContext > const & m_xContext
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.
const ::std::function< css::awt::Rectangle(const sal_Int32, const sal_Int32)> maCharacterBoundsAccess
void SetPosition(const sal_Int32 nParagraphIndex, const sal_Int32 nCharacterIndex)
PresenterTextCaret(css::uno::Reference< css::uno::XComponentContext > const &xContext, ::std::function< css::awt::Rectangle(const sal_Int32, const sal_Int32)> aCharacterBoundsAccess, ::std::function< void(const css::awt::Rectangle &)> aInvalidator)
::std::function< void(sal_Int32, sal_Int32, sal_Int32, sal_Int32)> maBroadcaster
const ::std::function< void(const css::awt::Rectangle &)> maInvalidator
A portion of a string that encodes one unicode cell.
Cell(const sal_Int32 nCharacterIndex, const sal_Int32 nCharacterCount, const double nCellWidth)
Line(const sal_Int32 nLineStartCharacterIndex, const sal_Int32 nLineEndCharacterIndex)
css::uno::Sequence< css::geometry::RealRectangle2D > maCellBoxes
css::uno::Reference< css::rendering::XTextLayout > mxLayoutedLine
void ProvideLayoutedLine(const OUString &rsParagraphText, const PresenterTheme::SharedFontDescriptor &rpFont, const sal_Int8 nTextDirection)
sal_Unicode GetCharacter(const sal_Int32 nGlobalCharacterIndex) const
void SetCaretPosition(const sal_Int32 nPosition) const
css::accessibility::TextSegment GetTextSegment(const sal_Int32 nOffset, const sal_Int32 nGlobalCharacterIndex, const sal_Int16 nTextType) const
css::uno::Reference< css::i18n::XScriptTypeDetector > mxScriptTypeDetector
void AddLine(css::i18n::Boundary &rCurrentLine)
void SetupCellArray(const PresenterTheme::SharedFontDescriptor &rpFont)
sal_Int32 mnCharacterOffset
The index of the first character in this paragraph with respect to the whole text.
sal_Int32 GetWordBoundary(const sal_Int32 nLocalCharacterIndex, const sal_Int32 nDistance)
css::accessibility::TextSegment CreateTextSegment(sal_Int32 nStartIndex, sal_Int32 nEndIndex) const
void SetCharacterOffset(const sal_Int32 nCharacterOffset)
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, SharedPresenterTextCaret xCaret)
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator
void AddWord(const double nWidth, css::i18n::Boundary &rCurrentLine, const sal_Int32 nWordBoundary, const PresenterTheme::SharedFontDescriptor &rpFont)
css::awt::Rectangle GetCharacterBounds(sal_Int32 nGlobalCharacterIndex, const bool bCaretBox)
css::accessibility::TextSegment GetWordTextSegment(const sal_Int32 nOffset, const sal_Int32 nIndex) const
void SetOrigin(const double nXOrigin, const double nYOrigin)
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 Format(const double nY, const double nWidth, const PresenterTheme::SharedFontDescriptor &rpFont)
A simple text view that paints text onto a given canvas.
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
void SetSize(const css::geometry::RealSize2D &rSize)
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator
css::uno::Reference< css::i18n::XScriptTypeDetector > mxScriptTypeDetector
::std::vector< SharedPresenterTextParagraph > maParagraphs
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)
::std::function< void()> maTextChangeBroadcaster
void SetText(const css::uno::Reference< css::text::XText > &rxText)
const SharedPresenterTextCaret & GetCaret() const
void SetLocation(const css::geometry::RealPoint2D &rLocation)
void Paint(const css::awt::Rectangle &rUpdateBox)
SharedPresenterTextParagraph GetParagraph(const sal_Int32 nParagraphIndex) const
PresenterTheme::SharedFontDescriptor mpFont
void SetOffset(const double nLeft, const double nTop)
void SetFont(const PresenterTheme::SharedFontDescriptor &rpFont)
css::awt::Rectangle GetCaretBounds(const sal_Int32 nParagraphIndex, const sal_Int32 nCharacterIndex) const
css::uno::Reference< css::rendering::XCanvas > mxCanvas
void SetTextChangeBroadcaster(const ::std::function< void()> &rBroadcaster)
std::shared_ptr< FontDescriptor > SharedFontDescriptor
sal_Int32 nIndex
const sal_Int32 nCellWidth
std::shared_ptr< PresenterTextParagraph > SharedPresenterTextParagraph
std::shared_ptr< PresenterTextCaret > SharedPresenterTextCaret
sal_uInt16 sal_Unicode
signed char sal_Int8