merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / modeltoviewhelper.hxx
blobedc27ed16767cc1cb883fb92cb57994abb1afaf9
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: modeltoviewhelper.hxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 #ifndef _MODELTOVIEWHELPER_HXX
32 #define _MODELTOVIEWHELPER_HXX
34 #include <sal/types.h>
36 #include <vector>
38 /** Some helpers for converting model strings to view strings.
40 A paragraph string does not have its fields expanded, i.e., they are
41 represented by a special character inside the string with an additional
42 attribute assigned to it. For some tasks (e.g., SmartTags) it is required
43 to expand the fields to get the string as it appears in the view. Two
44 helper functions are provided to convert model positions to view positions
45 and vice versa.
47 namespace ModelToViewHelper
49 /** For each field in the model string, there is an entry in the conversion
50 map. The first value of the ConversionMapEntry points to the field
51 position in the model string, the second value points to the associated
52 position in the view string. The last entry in the conversion map
53 denotes the lengths of the model resp. view string.
55 typedef std::pair< sal_uInt32 , sal_uInt32 > ConversionMapEntry;
56 typedef std::vector< ConversionMapEntry > ConversionMap;
58 /** This struct defines a position in the model string.
60 The 'main' position is given by mnPos. If there's a field located at
61 this position, mbIsField is set and mnSubPos denotes the position inside
62 that field.
64 struct ModelPosition
66 sal_uInt32 mnPos;
67 sal_uInt32 mnSubPos;
68 bool mbIsField;
70 ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
73 /** Converts a model position into a view position
75 @param pMap
76 pMap is the conversion map required for the calculation. If pMap is
77 0, no conversion takes place, i.e., it is assumed that the model
78 string is identical to the view string.
80 @param nPos
81 nPos denotes a position in the model string which should be
82 converted. Note that converting model positions inside fields is
83 not supported, therefore nPos is not of type ModelPosition.
85 @return
86 the position of nPos in the view string. In case the conversion
87 could not be performed (e.g., because there is not ConversionMap or
88 nPos is behind the last entry in the conversion map) nPos will
89 be returned.
91 sal_uInt32 ConvertToViewPosition( const ConversionMap* pMap, sal_uInt32 nModelPos );
93 /** Converts a view position into a model position
95 @param pMap
96 pMap is the conversion map required for the calculation. If pMap is
97 0, no conversion takes place, i.e., it is assumed that the model
98 string is identical to the view string.
100 @param nPos
101 nPos denotes a position in the view string which should be
102 converted.
104 @return
105 the position of nPos in the model string. In case the conversion
106 could not be performed (e.g., because there is not ConversionMap or
107 nPos is behind the last entry in the conversion map) a model
108 model position with mnPos = nPos and mnIsField = false will be
109 returned.
111 ModelPosition ConvertToModelPosition( const ConversionMap* pMap, sal_uInt32 nViewPos );
114 #endif