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: accportions.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _ACCPORTIONS_HXX
31 #define _ACCPORTIONS_HXX
32 #include <SwPortionHandler.hxx>
33 #include <sal/types.h>
34 #include <rtl/ustrbuf.hxx>
41 namespace com
{ namespace sun
{ namespace star
{
42 namespace i18n
{ struct Boundary
; }
46 * collect text portion data from the layout through SwPortionHandler interface
48 class SwAccessiblePortionData
: public SwPortionHandler
50 // the node this portion is referring to
51 const SwTxtNode
* pTxtNode
;
53 // variables used while collecting the data
54 rtl::OUStringBuffer aBuffer
;
55 sal_Int32 nModelPosition
;
57 const SwViewOption
* pViewOptions
;
59 // the accessible string
60 rtl::OUString sAccessibleString
;
63 // instances of Position_t must always include the minimum and
64 // maximum positions as first/last elements (to simplify the
66 typedef std::vector
<sal_Int32
> Positions_t
;
68 Positions_t aLineBreaks
; /// position of line breaks
69 Positions_t aModelPositions
; /// position of portion breaks in the model
70 Positions_t aAccessiblePositions
; /// portion breaks in sAccessibleString
72 typedef std::vector
<sal_uInt8
> PortionAttrs_t
;
73 PortionAttrs_t aPortionAttrs
; /// additional portion attributes
75 Positions_t
* pSentences
; /// positions of sentence breaks
77 size_t nBeforePortions
; /// # of portions before first model character
78 sal_Bool bLastIsSpecial
; /// set if last portion was 'Special()'
80 /// returns the index of the first position whose value is smaller
81 /// or equal, and whose following value is equal or larger
82 size_t FindBreak( const Positions_t
& rPositions
, sal_Int32 nValue
) const;
84 /// like FindBreak, but finds the last equal or larger position
85 size_t FindLastBreak( const Positions_t
& rPositions
, sal_Int32 nValue
) const;
87 /// fill the boundary with the values from rPositions[nPos]
88 void FillBoundary(com::sun::star::i18n::Boundary
& rBound
,
89 const Positions_t
& rPositions
,
92 /// Access to portion attributes
93 sal_Bool
IsPortionAttrSet( size_t nPortionNo
, sal_uInt8 nAttr
) const;
94 sal_Bool
IsSpecialPortion( size_t nPortionNo
) const;
95 sal_Bool
IsReadOnlyPortion( size_t nPortionNo
) const;
96 sal_Bool
IsGrayPortion( size_t nPortionNo
) const;
97 sal_Bool
IsGrayPortionType( USHORT nType
) const;
99 // helper method for GetEditableRange(...):
100 void AdjustAndCheck( sal_Int32 nPos
, size_t& nPortionNo
,
101 USHORT
& nCorePos
, sal_Bool
& bEdit
) const;
104 SwAccessiblePortionData( const SwTxtNode
* pTxtNd
,
105 const SwViewOption
* pViewOpt
= NULL
);
106 virtual ~SwAccessiblePortionData();
108 // SwPortionHandler methods
109 virtual void Text(USHORT nLength
, USHORT nType
);
110 virtual void Special(USHORT nLength
, const String
& rText
, USHORT nType
);
111 virtual void LineBreak();
112 virtual void Skip(USHORT nLength
);
113 virtual void Finish();
116 // access to the portion data
118 /// get the text string, as presented by the layout
119 const rtl::OUString
& GetAccessibleString() const;
121 /// get the start & end positions of the sentence
122 void GetLineBoundary( com::sun::star::i18n::Boundary
& rBound
,
123 sal_Int32 nPos
) const;
125 // get start and end position of the last line
126 void GetLastLineBoundary( com::sun::star::i18n::Boundary
& rBound
) const;
128 // --> OD 2008-05-30 #i89175#
129 sal_Int32
GetLineCount() const;
130 sal_Int32
GetLineNo( const sal_Int32 nPos
) const;
131 void GetBoundaryOfLine( const sal_Int32 nLineNo
,
132 com::sun::star::i18n::Boundary
& rLineBound
);
135 /// get the position in the model string for a given
136 /// (accessibility) position
137 USHORT
GetModelPosition( sal_Int32 nPos
) const;
139 /// get the position in the accessibility string for a given model position
140 sal_Int32
GetAccessiblePosition( USHORT nPos
) const;
142 /// fill a SwSpecialPos structure, suitable for calling
143 /// SwTxtFrm->GetCharRect
144 /// Returns the core position, and fills thr rpPos either with NULL or
145 /// with the &rPos, after putting the appropriate data into it.
146 USHORT
FillSpecialPos( sal_Int32 nPos
,
148 SwSpecialPos
*& rpPos
) const;
151 // get boundaries of words/sentences. The data structures are
152 // created on-demand.
153 void GetSentenceBoundary( com::sun::star::i18n::Boundary
& rBound
,
156 // get (a) boundary for attribut change
157 void GetAttributeBoundary( com::sun::star::i18n::Boundary
& rBound
,
158 sal_Int32 nPos
) const;
160 /// Convert start and end positions into core positions.
161 /// @returns true if 'special' portions are included either completely
162 /// or not at all. This can be used to test whether editing
163 /// that range would be legal
164 sal_Bool
GetEditableRange( sal_Int32 nStart
, sal_Int32 nEnd
,
165 USHORT
& nCoreStart
, USHORT
& nCoreEnd
) const;
167 /// Determine whether this core position is valid for these portions.
168 /// (A paragraph may be split into several frames, e.g. at page
169 /// boundaries. In this case, only part of a paragraph is represented
170 /// through this object. This method determines whether one particular
171 /// position is valid for this object or not.)
172 sal_Bool
IsValidCorePosition( USHORT nPos
) const;
173 USHORT
GetFirstValidCorePosition() const;
174 USHORT
GetLastValidCorePosition() const;