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: modeltoviewhelper.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 ************************************************************************/
31 #ifndef _MODELTOVIEWHELPER_HXX
32 #define _MODELTOVIEWHELPER_HXX
34 #include <sal/types.h>
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
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
70 ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
73 /** Converts a model position into a view position
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.
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.
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
91 sal_uInt32
ConvertToViewPosition( const ConversionMap
* pMap
, sal_uInt32 nModelPos
);
93 /** Converts a view position into a model position
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.
101 nPos denotes a position in the view string which should be
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
111 ModelPosition
ConvertToModelPosition( const ConversionMap
* pMap
, sal_uInt32 nViewPos
);