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