merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / presenter / PresenterTextView.hxx
blob3ef67dc4fe6da765779a406a2d75ff651c69ff3a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterNotesView.hxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef SDEXT_PRESENTER_TEXT_VIEW_HXX
33 #define SDEXT_PRESENTER_TEXT_VIEW_HXX
35 #include "PresenterTheme.hxx"
36 #include <com/sun/star/accessibility/XAccessibleText.hpp>
37 #include <com/sun/star/awt/Size.hpp>
38 #include <com/sun/star/geometry/RealPoint2D.hpp>
39 #include <com/sun/star/geometry/RealSize2D.hpp>
40 #include <com/sun/star/i18n/XBreakIterator.hpp>
41 #include <com/sun/star/i18n/XScriptTypeDetector.hpp>
42 #include <com/sun/star/rendering/XCanvas.hpp>
43 #include <com/sun/star/style/ParagraphAdjust.hpp>
44 #include <com/sun/star/text/XText.hpp>
45 #include <com/sun/star/uno/XComponentContext.hpp>
46 #include <cppuhelper/compbase1.hxx>
47 #include <cppuhelper/basemutex.hxx>
49 namespace css = ::com::sun::star;
50 namespace cssu = ::com::sun::star::uno;
51 namespace cssa = ::com::sun::star::accessibility;
53 namespace sdext { namespace presenter {
55 class PresenterTextCaret
57 public:
58 PresenterTextCaret (
59 const ::boost::function<css::awt::Rectangle(const sal_Int32,const sal_Int32)>&
60 rCharacterBoundsAccess,
61 const ::boost::function<void(const css::awt::Rectangle&)>&
62 rInvalidator);
63 ~PresenterTextCaret (void);
65 void ShowCaret (void);
66 void HideCaret (void);
68 sal_Int32 GetParagraphIndex (void) const;
69 sal_Int32 GetCharacterIndex (void) const;
70 void SetPosition (
71 const sal_Int32 nParagraphIndex,
72 const sal_Int32 nCharacterIndex);
74 bool IsVisible (void) const;
76 /** Set a (possibly empty) functor that broadcasts changes of the caret
77 position. This is used when a PresenterTextView object is set at
78 the accessibility object so that accessibility events can be sent
79 when the caret changes position.
81 void SetCaretMotionBroadcaster (
82 const ::boost::function<void(sal_Int32,sal_Int32,sal_Int32,sal_Int32)>& rBroadcaster);
84 css::awt::Rectangle GetBounds (void) const;
86 private:
87 sal_Int32 mnParagraphIndex;
88 sal_Int32 mnCharacterIndex;
89 sal_Int32 mnCaretBlinkTaskId;
90 bool mbIsCaretVisible;
91 const ::boost::function<css::awt::Rectangle(const sal_Int32,const sal_Int32)> maCharacterBoundsAccess;
92 const ::boost::function<void(const css::awt::Rectangle&)> maInvalidator;
93 ::boost::function<void(sal_Int32,sal_Int32,sal_Int32,sal_Int32)> maBroadcaster;
94 css::awt::Rectangle maCaretBounds;
96 void InvertCaret (void);
98 typedef ::boost::shared_ptr<PresenterTextCaret> SharedPresenterTextCaret;
103 //===== PresenterTextParagraph ================================================
105 class PresenterTextParagraph
107 public:
108 PresenterTextParagraph (
109 const sal_Int32 nParagraphIndex,
110 const cssu::Reference<css::i18n::XBreakIterator>& rxBreakIterator,
111 const cssu::Reference<css::i18n::XScriptTypeDetector>& rxScriptTypeDetector,
112 const cssu::Reference<css::text::XTextRange>& rxTextRange,
113 const SharedPresenterTextCaret& rpCaret);
114 PresenterTextParagraph (
115 const sal_Int32 nParagraphIndex,
116 const cssu::Reference<css::i18n::XBreakIterator>& rxBreakIterator,
117 const cssu::Reference<css::i18n::XScriptTypeDetector>& rxScriptTypeDetector,
118 const ::rtl::OUString& rsText,
119 const SharedPresenterTextCaret& rpCaret);
121 void Paint (
122 const cssu::Reference<css::rendering::XCanvas>& rxCanvas,
123 const css::geometry::RealSize2D& rSize,
124 const PresenterTheme::SharedFontDescriptor& rpFont,
125 const css::rendering::ViewState& rViewState,
126 css::rendering::RenderState& rRenderState,
127 const double nTopOffset,
128 const double nClipTop,
129 const double nClipBottom);
131 sal_Int32 GetParagraphIndex (void) const;
132 double GetTotalTextHeight (void);
134 sal_Int32 GetCharacterOffset (void) const;
135 void SetCharacterOffset (const sal_Int32 nCharacterOffset);
136 sal_Int32 GetCharacterCount (void) const;
137 sal_Unicode GetCharacter (const sal_Int32 nGlobalCharacterIndex) const;
138 ::rtl::OUString GetText (void) const;
139 cssa::TextSegment GetTextSegment (
140 const sal_Int32 nOffset,
141 const sal_Int32 nGlobalCharacterIndex,
142 const sal_Int16 nTextType) const;
143 cssa::TextSegment GetWordTextSegment (
144 const sal_Int32 nOffset,
145 const sal_Int32 nIndex) const;
146 cssa::TextSegment CreateTextSegment (
147 sal_Int32 nStartIndex,
148 sal_Int32 nEndIndex) const;
149 css::awt::Rectangle GetCharacterBounds (
150 sal_Int32 nGlobalCharacterIndex,
151 const bool bCaretBox);
152 sal_Int32 GetIndexAtPoint (const css::awt::Point& rPoint) const;
153 void SetupCellArray (
154 const PresenterTheme::SharedFontDescriptor& rpFont);
155 void Format (
156 const double nY,
157 const double nWidth,
158 const PresenterTheme::SharedFontDescriptor& rpFont);
159 sal_Int32 GetWordBoundary(
160 const sal_Int32 nLocalCharacterIndex,
161 const sal_Int32 nDistance);
162 sal_Int32 GetCaretPosition (void) const;
163 void SetCaretPosition (const sal_Int32 nPosition) const;
164 void SetOrigin (const double nXOrigin, const double nYOrigin);
165 css::awt::Point GetRelativeLocation (void) const;
166 css::awt::Size GetSize (void);
168 private:
169 ::rtl::OUString msParagraphText;
170 const sal_Int32 mnParagraphIndex;
171 SharedPresenterTextCaret mpCaret;
173 /** A portion of a string that encodes one unicode cell. It describes
174 number of characters in the unicode string that make up the cell and its
175 width in pixel (with respect to some configuration that is stored
176 externally or implicitly).
178 class Cell
180 public:
181 Cell (const sal_Int32 nCharacterIndex, const sal_Int32 nCharacterCount, const double nCellWidth);
182 sal_Int32 mnCharacterIndex;
183 sal_Int32 mnCharacterCount;
184 double mnCellWidth;
187 class Line
189 public:
190 Line (const sal_Int32 nLineStartCharacterIndex, const sal_Int32 nLineEndCharacterIndex);
191 sal_Int32 mnLineStartCharacterIndex;
192 sal_Int32 mnLineEndCharacterIndex;
193 sal_Int32 mnLineStartCellIndex;
194 sal_Int32 mnLineEndCellIndex;
195 cssu::Reference<css::rendering::XTextLayout> mxLayoutedLine;
196 double mnBaseLine;
197 double mnWidth;
198 cssu::Sequence<css::geometry::RealRectangle2D> maCellBoxes;
200 sal_Int32 GetLength (void) const;
201 void ProvideLayoutedLine (
202 const ::rtl::OUString& rsParagraphText,
203 const PresenterTheme::SharedFontDescriptor& rpFont,
204 const sal_Int8 nTextDirection);
205 void ProvideCellBoxes (void);
206 bool IsEmpty (void) const;
210 cssu::Reference<css::i18n::XBreakIterator> mxBreakIterator;
211 cssu::Reference<css::i18n::XScriptTypeDetector> mxScriptTypeDetector;
212 ::std::vector<Line> maLines;
213 ::std::vector<sal_Int32> maWordBoundaries;
214 // Offset of the top of the paragraph with respect to the origin of the
215 // whole text (specified by mnXOrigin and mnYOrigin).
216 double mnVerticalOffset;
217 double mnXOrigin;
218 double mnYOrigin;
219 double mnWidth;
220 double mnAscent;
221 double mnDescent;
222 double mnLineHeight;
223 css::style::ParagraphAdjust meAdjust;
224 sal_Int8 mnWritingMode;
225 /// The index of the first character in this paragraph with respect to
226 /// the whole text.
227 sal_Int32 mnCharacterOffset;
228 ::std::vector<Cell> maCells;
230 void AddWord (
231 const double nWidth,
232 css::i18n::Boundary& rCurrentLine,
233 const sal_Int32 nWordBoundary,
234 const PresenterTheme::SharedFontDescriptor& rpFont);
235 void AddLine (
236 css::i18n::Boundary& rCurrentLine);
237 sal_Int8 GetTextDirection (void) const;
238 bool IsTextReferencePointLeft (void) const;
240 typedef ::boost::shared_ptr<PresenterTextParagraph> SharedPresenterTextParagraph;
245 /** A simple text view that paints text onto a given canvas.
247 class PresenterTextView
249 public:
251 PresenterTextView (
252 const css::uno::Reference<css::uno::XComponentContext>& rxContext,
253 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
254 const ::boost::function<void(const ::css::awt::Rectangle&)>& rInvalidator);
255 /** Create a new instance that does no output but only provides
256 geometric information to an accessibility object.
258 PresenterTextView (
259 const css::uno::Reference<css::uno::XComponentContext>& rxContext,
260 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
262 void SetText (const css::uno::Reference<css::text::XText>& rxText);
263 void SetText (const ::rtl::OUString& rsText);
264 void SetTextChangeBroadcaster (const ::boost::function<void(void)>& rBroadcaster);
266 void SetLocation (const css::geometry::RealPoint2D& rLocation);
267 void SetSize (const css::geometry::RealSize2D& rSize);
268 double GetTotalTextHeight (void);
270 void SetFont (const PresenterTheme::SharedFontDescriptor& rpFont);
272 void SetOffset (
273 const double nLeft,
274 const double nTop);
276 /** Move the caret forward or backward by character or by word.
277 @param nDistance
278 Should be either -1 or +1 to move caret backwards or forwards,
279 respectively.
280 @param nTextType
281 Valid values are the
282 com::sun::star::accessibility::AccessibleTextType constants.
284 void MoveCaret (
285 const sal_Int32 nDistance,
286 const sal_Int16 nTextType);
288 void Paint (const css::awt::Rectangle& rUpdateBox);
290 SharedPresenterTextCaret GetCaret (void) const;
292 sal_Int32 GetParagraphCount (void) const;
293 SharedPresenterTextParagraph GetParagraph (const sal_Int32 nParagraphIndex) const;
295 private:
296 css::uno::Reference<css::rendering::XCanvas> mxCanvas;
297 bool mbDoOuput;
298 css::uno::Reference<css::i18n::XBreakIterator> mxBreakIterator;
299 css::uno::Reference<css::i18n::XScriptTypeDetector> mxScriptTypeDetector;
300 css::geometry::RealPoint2D maLocation;
301 css::geometry::RealSize2D maSize;
302 PresenterTheme::SharedFontDescriptor mpFont;
303 ::std::vector<SharedPresenterTextParagraph> maParagraphs;
304 SharedPresenterTextCaret mpCaret;
305 double mnLeftOffset;
306 double mnTopOffset;
307 const ::boost::function<void(const ::css::awt::Rectangle&)> maInvalidator;
308 bool mbIsFormatPending;
309 sal_Int32 mnCharacterCount;
310 ::boost::function<void(void)> maTextChangeBroadcaster;
312 void RequestFormat (void);
313 void Format (void);
314 SharedPresenterTextParagraph GetParagraphForCharacterIndex (const sal_Int32 nCharacterIndex) const;
315 sal_Int32 GetCharacterOffset (const sal_Int32 nParagraphIndex) const;
316 css::awt::Rectangle GetCaretBounds (
317 const sal_Int32 nParagraphIndex,
318 const sal_Int32 nCharacterIndex) const;
321 } } // end of namespace ::sdext::presenter
323 #endif