1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterNotesView.hxx,v $
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
59 const ::boost::function
<css::awt::Rectangle(const sal_Int32
,const sal_Int32
)>&
60 rCharacterBoundsAccess
,
61 const ::boost::function
<void(const css::awt::Rectangle
&)>&
63 ~PresenterTextCaret (void);
65 void ShowCaret (void);
66 void HideCaret (void);
68 sal_Int32
GetParagraphIndex (void) const;
69 sal_Int32
GetCharacterIndex (void) const;
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;
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
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
);
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
);
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);
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).
181 Cell (const sal_Int32 nCharacterIndex
, const sal_Int32 nCharacterCount
, const double nCellWidth
);
182 sal_Int32 mnCharacterIndex
;
183 sal_Int32 mnCharacterCount
;
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
;
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
;
223 css::style::ParagraphAdjust meAdjust
;
224 sal_Int8 mnWritingMode
;
225 /// The index of the first character in this paragraph with respect to
227 sal_Int32 mnCharacterOffset
;
228 ::std::vector
<Cell
> maCells
;
232 css::i18n::Boundary
& rCurrentLine
,
233 const sal_Int32 nWordBoundary
,
234 const PresenterTheme::SharedFontDescriptor
& rpFont
);
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
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.
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
);
276 /** Move the caret forward or backward by character or by word.
278 Should be either -1 or +1 to move caret backwards or forwards,
282 com::sun::star::accessibility::AccessibleTextType constants.
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;
296 css::uno::Reference
<css::rendering::XCanvas
> mxCanvas
;
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
;
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);
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