Line data Source code
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/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/compbase1.hxx>
35 : #include <cppuhelper/basemutex.hxx>
36 :
37 :
38 : namespace sdext { namespace presenter {
39 :
40 : class PresenterTextCaret
41 : {
42 : public:
43 : PresenterTextCaret (
44 : const ::boost::function<css::awt::Rectangle(const sal_Int32,const sal_Int32)>&
45 : rCharacterBoundsAccess,
46 : const ::boost::function<void(const css::awt::Rectangle&)>&
47 : rInvalidator);
48 : ~PresenterTextCaret();
49 :
50 : void ShowCaret();
51 : void HideCaret();
52 :
53 0 : sal_Int32 GetParagraphIndex() const { return mnParagraphIndex;}
54 0 : sal_Int32 GetCharacterIndex() const { return mnCharacterIndex;}
55 : void SetPosition (
56 : const sal_Int32 nParagraphIndex,
57 : const sal_Int32 nCharacterIndex);
58 :
59 0 : bool IsVisible() const { return mbIsCaretVisible;}
60 :
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.
65 : */
66 : void SetCaretMotionBroadcaster (
67 : const ::boost::function<void(sal_Int32,sal_Int32,sal_Int32,sal_Int32)>& rBroadcaster);
68 :
69 : css::awt::Rectangle GetBounds() const;
70 :
71 : private:
72 : sal_Int32 mnParagraphIndex;
73 : sal_Int32 mnCharacterIndex;
74 : sal_Int32 mnCaretBlinkTaskId;
75 : bool mbIsCaretVisible;
76 : const ::boost::function<css::awt::Rectangle(const sal_Int32,const sal_Int32)> maCharacterBoundsAccess;
77 : const ::boost::function<void(const css::awt::Rectangle&)> maInvalidator;
78 : ::boost::function<void(sal_Int32,sal_Int32,sal_Int32,sal_Int32)> maBroadcaster;
79 : css::awt::Rectangle maCaretBounds;
80 :
81 : void InvertCaret();
82 : };
83 : typedef ::boost::shared_ptr<PresenterTextCaret> SharedPresenterTextCaret;
84 :
85 : //===== PresenterTextParagraph ================================================
86 :
87 0 : class PresenterTextParagraph
88 : {
89 : public:
90 : PresenterTextParagraph (
91 : const sal_Int32 nParagraphIndex,
92 : const css::uno::Reference<css::i18n::XBreakIterator>& rxBreakIterator,
93 : const css::uno::Reference<css::i18n::XScriptTypeDetector>& rxScriptTypeDetector,
94 : const css::uno::Reference<css::text::XTextRange>& rxTextRange,
95 : const SharedPresenterTextCaret& rpCaret);
96 :
97 : void Paint (
98 : const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
99 : const css::geometry::RealSize2D& rSize,
100 : const PresenterTheme::SharedFontDescriptor& rpFont,
101 : const css::rendering::ViewState& rViewState,
102 : css::rendering::RenderState& rRenderState,
103 : const double nTopOffset,
104 : const double nClipTop,
105 : const double nClipBottom);
106 :
107 : double GetTotalTextHeight();
108 :
109 : void SetCharacterOffset (const sal_Int32 nCharacterOffset);
110 : sal_Int32 GetCharacterCount() const;
111 : sal_Unicode GetCharacter (const sal_Int32 nGlobalCharacterIndex) const;
112 : OUString GetText() const;
113 : css::accessibility::TextSegment GetTextSegment (
114 : const sal_Int32 nOffset,
115 : const sal_Int32 nGlobalCharacterIndex,
116 : const sal_Int16 nTextType) const;
117 : css::accessibility::TextSegment GetWordTextSegment (
118 : const sal_Int32 nOffset,
119 : const sal_Int32 nIndex) const;
120 : css::accessibility::TextSegment CreateTextSegment (
121 : sal_Int32 nStartIndex,
122 : sal_Int32 nEndIndex) const;
123 : css::awt::Rectangle GetCharacterBounds (
124 : sal_Int32 nGlobalCharacterIndex,
125 : const bool bCaretBox);
126 : void SetupCellArray (
127 : const PresenterTheme::SharedFontDescriptor& rpFont);
128 : void Format (
129 : const double nY,
130 : const double nWidth,
131 : const PresenterTheme::SharedFontDescriptor& rpFont);
132 : sal_Int32 GetWordBoundary(
133 : const sal_Int32 nLocalCharacterIndex,
134 : const sal_Int32 nDistance);
135 : sal_Int32 GetCaretPosition() const;
136 : void SetCaretPosition (const sal_Int32 nPosition) const;
137 : void SetOrigin (const double nXOrigin, const double nYOrigin);
138 : css::awt::Point GetRelativeLocation() const;
139 : css::awt::Size GetSize();
140 :
141 : private:
142 : OUString msParagraphText;
143 : const sal_Int32 mnParagraphIndex;
144 : SharedPresenterTextCaret mpCaret;
145 :
146 : /** A portion of a string that encodes one unicode cell. It describes
147 : number of characters in the unicode string that make up the cell and its
148 : width in pixel (with respect to some configuration that is stored
149 : externally or implicitly).
150 : */
151 : class Cell
152 : {
153 : public:
154 : Cell (const sal_Int32 nCharacterIndex, const sal_Int32 nCharacterCount, const double nCellWidth);
155 : sal_Int32 mnCharacterIndex;
156 : sal_Int32 mnCharacterCount;
157 : double mnCellWidth;
158 : };
159 :
160 0 : class Line
161 : {
162 : public:
163 : Line (const sal_Int32 nLineStartCharacterIndex, const sal_Int32 nLineEndCharacterIndex);
164 : sal_Int32 mnLineStartCharacterIndex;
165 : sal_Int32 mnLineEndCharacterIndex;
166 : sal_Int32 mnLineStartCellIndex;
167 : sal_Int32 mnLineEndCellIndex;
168 : css::uno::Reference<css::rendering::XTextLayout> mxLayoutedLine;
169 : double mnBaseLine;
170 : double mnWidth;
171 : css::uno::Sequence<css::geometry::RealRectangle2D> maCellBoxes;
172 :
173 : void ProvideLayoutedLine (
174 : const OUString& rsParagraphText,
175 : const PresenterTheme::SharedFontDescriptor& rpFont,
176 : const sal_Int8 nTextDirection);
177 : void ProvideCellBoxes();
178 : bool IsEmpty() const;
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).
187 : double mnVerticalOffset;
188 : double mnXOrigin;
189 : double mnYOrigin;
190 : double mnWidth;
191 : double mnAscent;
192 : double mnDescent;
193 : double mnLineHeight;
194 : css::style::ParagraphAdjust meAdjust;
195 : sal_Int8 mnWritingMode;
196 : /// The index of the first character in this paragraph with respect to
197 : /// the whole text.
198 : sal_Int32 mnCharacterOffset;
199 : ::std::vector<Cell> maCells;
200 :
201 : void AddWord (
202 : const double nWidth,
203 : css::i18n::Boundary& rCurrentLine,
204 : const sal_Int32 nWordBoundary,
205 : const PresenterTheme::SharedFontDescriptor& rpFont);
206 : void AddLine (
207 : css::i18n::Boundary& rCurrentLine);
208 : sal_Int8 GetTextDirection() const;
209 : bool IsTextReferencePointLeft() const;
210 : };
211 : typedef ::boost::shared_ptr<PresenterTextParagraph> SharedPresenterTextParagraph;
212 :
213 : /** A simple text view that paints text onto a given canvas.
214 : */
215 0 : class PresenterTextView
216 : {
217 : public:
218 :
219 : PresenterTextView (
220 : const css::uno::Reference<css::uno::XComponentContext>& rxContext,
221 : const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
222 : const ::boost::function<void(const css::awt::Rectangle&)>& rInvalidator);
223 : void SetText (const css::uno::Reference<css::text::XText>& rxText);
224 : void SetTextChangeBroadcaster (const ::boost::function<void()>& rBroadcaster);
225 :
226 : void SetLocation (const css::geometry::RealPoint2D& rLocation);
227 : void SetSize (const css::geometry::RealSize2D& rSize);
228 : double GetTotalTextHeight();
229 :
230 : void SetFont (const PresenterTheme::SharedFontDescriptor& rpFont);
231 :
232 : void SetOffset (
233 : const double nLeft,
234 : const double nTop);
235 :
236 : /** Move the caret forward or backward by character or by word.
237 : @param nDistance
238 : Should be either -1 or +1 to move caret backwards or forwards,
239 : respectively.
240 : @param nTextType
241 : Valid values are the
242 : css::accessibility::AccessibleTextType constants.
243 : */
244 : void MoveCaret (
245 : const sal_Int32 nDistance,
246 : const sal_Int16 nTextType);
247 :
248 : void Paint (const css::awt::Rectangle& rUpdateBox);
249 :
250 : SharedPresenterTextCaret GetCaret() const;
251 :
252 : sal_Int32 GetParagraphCount() const;
253 : SharedPresenterTextParagraph GetParagraph (const sal_Int32 nParagraphIndex) const;
254 :
255 : private:
256 : css::uno::Reference<css::rendering::XCanvas> mxCanvas;
257 : bool mbDoOuput;
258 : css::uno::Reference<css::i18n::XBreakIterator> mxBreakIterator;
259 : css::uno::Reference<css::i18n::XScriptTypeDetector> mxScriptTypeDetector;
260 : css::geometry::RealPoint2D maLocation;
261 : css::geometry::RealSize2D maSize;
262 : PresenterTheme::SharedFontDescriptor mpFont;
263 : ::std::vector<SharedPresenterTextParagraph> maParagraphs;
264 : SharedPresenterTextCaret mpCaret;
265 : double mnLeftOffset;
266 : double mnTopOffset;
267 : const ::boost::function<void(const css::awt::Rectangle&)> maInvalidator;
268 : bool mbIsFormatPending;
269 : sal_Int32 mnCharacterCount;
270 : ::boost::function<void()> maTextChangeBroadcaster;
271 :
272 : void RequestFormat();
273 : void Format();
274 : SharedPresenterTextParagraph GetParagraphForCharacterIndex (const sal_Int32 nCharacterIndex) const;
275 : css::awt::Rectangle GetCaretBounds (
276 : const sal_Int32 nParagraphIndex,
277 : const sal_Int32 nCharacterIndex) const;
278 : };
279 :
280 : } } // end of namespace ::sdext::presenter
281 :
282 : #endif
283 :
284 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|