xref: /aoo42x/main/sw/inc/modeltoviewhelper.hxx (revision 1d2dbeb0)
1*1d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1d2dbeb0SAndrew Rist  * distributed with this work for additional information
6*1d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
9*1d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1d2dbeb0SAndrew Rist  *
11*1d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1d2dbeb0SAndrew Rist  *
13*1d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
15*1d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
18*1d2dbeb0SAndrew Rist  * under the License.
19*1d2dbeb0SAndrew Rist  *
20*1d2dbeb0SAndrew Rist  *************************************************************/
21*1d2dbeb0SAndrew Rist 
22*1d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _MODELTOVIEWHELPER_HXX
25cdf0e10cSrcweir #define _MODELTOVIEWHELPER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sal/types.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vector>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** Some helpers for converting model strings to view strings.
32cdf0e10cSrcweir 
33cdf0e10cSrcweir     A paragraph string does not have its fields expanded, i.e., they are
34cdf0e10cSrcweir     represented by a special character inside the string with an additional
35cdf0e10cSrcweir     attribute assigned to it. For some tasks (e.g., SmartTags) it is required
36cdf0e10cSrcweir     to expand the fields to get the string as it appears in the view. Two
37cdf0e10cSrcweir     helper functions are provided to convert model positions to view positions
38cdf0e10cSrcweir     and vice versa.
39cdf0e10cSrcweir */
40cdf0e10cSrcweir namespace ModelToViewHelper
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     /** For each field in the model string, there is an entry in the conversion
43cdf0e10cSrcweir         map. The first value of the ConversionMapEntry points to the field
44cdf0e10cSrcweir         position in the model string, the second value points to the associated
45cdf0e10cSrcweir         position in the view string. The last entry in the conversion map
46cdf0e10cSrcweir         denotes the lengths of the model resp. view string.
47cdf0e10cSrcweir     */
48cdf0e10cSrcweir     typedef std::pair< sal_uInt32 , sal_uInt32 > ConversionMapEntry;
49cdf0e10cSrcweir     typedef std::vector< ConversionMapEntry > ConversionMap;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     /** This struct defines a position in the model string.
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         The 'main' position is given by mnPos. If there's a field located at
54cdf0e10cSrcweir         this position, mbIsField is set and mnSubPos denotes the position inside
55cdf0e10cSrcweir         that field.
56cdf0e10cSrcweir     */
57cdf0e10cSrcweir     struct ModelPosition
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         sal_uInt32 mnPos;
60cdf0e10cSrcweir         sal_uInt32 mnSubPos;
61cdf0e10cSrcweir         bool mbIsField;
62cdf0e10cSrcweir 
ModelPositionModelToViewHelper::ModelPosition63cdf0e10cSrcweir         ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
64cdf0e10cSrcweir     };
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /** Converts a model position into a view position
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         @param pMap
69cdf0e10cSrcweir             pMap is the conversion map required for the calculation. If pMap is
70cdf0e10cSrcweir             0, no conversion takes place, i.e., it is assumed that the model
71cdf0e10cSrcweir             string is identical to the view string.
72cdf0e10cSrcweir 
73cdf0e10cSrcweir         @param nPos
74cdf0e10cSrcweir             nPos denotes a position in the model string which should be
75cdf0e10cSrcweir             converted. Note that converting model positions inside fields is
76cdf0e10cSrcweir             not supported, therefore nPos is not of type ModelPosition.
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         @return
79cdf0e10cSrcweir             the position of nPos in the view string. In case the conversion
80cdf0e10cSrcweir             could not be performed (e.g., because there is not ConversionMap or
81cdf0e10cSrcweir             nPos is behind the last entry in the conversion map) nPos will
82cdf0e10cSrcweir             be returned.
83cdf0e10cSrcweir     */
84cdf0e10cSrcweir     sal_uInt32 ConvertToViewPosition( const ConversionMap* pMap, sal_uInt32 nModelPos );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     /** Converts a view position into a model position
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         @param pMap
89cdf0e10cSrcweir             pMap is the conversion map required for the calculation. If pMap is
90cdf0e10cSrcweir             0, no conversion takes place, i.e., it is assumed that the model
91cdf0e10cSrcweir             string is identical to the view string.
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         @param nPos
94cdf0e10cSrcweir             nPos denotes a position in the view string which should be
95cdf0e10cSrcweir             converted.
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         @return
98cdf0e10cSrcweir             the position of nPos in the model string. In case the conversion
99cdf0e10cSrcweir             could not be performed (e.g., because there is not ConversionMap or
100cdf0e10cSrcweir             nPos is behind the last entry in the conversion map) a model
101cdf0e10cSrcweir             model position with mnPos = nPos and mnIsField = false will be
102cdf0e10cSrcweir             returned.
103cdf0e10cSrcweir     */
104cdf0e10cSrcweir     ModelPosition ConvertToModelPosition( const ConversionMap* pMap, sal_uInt32 nViewPos );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir #endif
108