calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / fpicker / source / win32 / WinImplHelper.cxx
blob5d6e20d923199354231e414c797351b746feb13a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WinImplHelper.hxx"
22 #include <vector>
23 #include <osl/diagnose.h>
24 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
27 using ::com::sun::star::lang::IllegalArgumentException;
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::XInterface;
30 using ::com::sun::star::uno::Any;
31 using ::com::sun::star::uno::Sequence;
33 const sal_Unicode TILDE_SIGN = L'~';
34 const sal_Unicode AMPERSAND_SIGN = L'&';
36 // OS NAME Platform Major Minor
38 // Windows NT 3.51 VER_PLATFORM_WIN32_NT 3 51
39 // Windows NT 4.0 VER_PLATFORM_WIN32_NT 4 0
40 // Windows 2000 VER_PLATFORM_WIN32_NT 5 0
41 // Windows XP VER_PLATFORM_WIN32_NT 5 1
42 // Windows Vista VER_PLATFORM_WIN32_NT 6 0
43 // Windows 7 VER_PLATFORM_WIN32_NT 6 1
44 // Windows 95 VER_PLATFORM_WIN32_WINDOWS 4 0
45 // Windows 98 VER_PLATFORM_WIN32_WINDOWS 4 10
46 // Windows ME VER_PLATFORM_WIN32_WINDOWS 4 90
49 static void Replace( const OUString& aLabel, sal_Unicode OldChar, sal_Unicode NewChar, OUStringBuffer& aBuffer )
51 OSL_ASSERT( aLabel.getLength( ) );
52 OSL_ASSERT( aBuffer.getCapacity( ) >= (aLabel.getLength( )) );
54 sal_Int32 i = 0;
55 const sal_Unicode* pCurrent = aLabel.getStr( );
56 const sal_Unicode* pNext = aLabel.getStr( ) + 1;
57 const sal_Unicode* pEnd = aLabel.getStr( ) + aLabel.getLength( );
59 while( pCurrent < pEnd )
61 OSL_ASSERT( pNext <= pEnd );
62 OSL_ASSERT( (i >= 0) && (i < aBuffer.getCapacity( )) );
64 if ( OldChar == *pCurrent )
66 if ( OldChar == *pNext )
68 // two OldChars in line will
69 // be replaced by one
70 // e.g. ~~ -> ~
71 aBuffer.insert( i, *pCurrent );
73 // skip the next one
74 pCurrent++;
75 pNext++;
77 else
79 // one OldChar will be replace
80 // by NexChar
81 aBuffer.insert( i, NewChar );
84 else if ( *pCurrent == NewChar )
86 // a NewChar will be replaced by
87 // two NewChars
88 // e.g. & -> &&
89 aBuffer.insert( i++, *pCurrent );
90 aBuffer.insert( i, *pCurrent );
92 else
94 aBuffer.insert( i, *pCurrent );
97 pCurrent++;
98 pNext++;
99 i++;
103 // converts a soffice label to a windows label
104 // the following rules for character replacements
105 // will be done:
106 // '~' -> '&'
107 // '~~' -> '~'
108 // '&' -> '&&'
110 OUString SOfficeToWindowsLabel( const OUString& aSOLabel )
112 OUString aWinLabel = aSOLabel;
114 if ( (aWinLabel.indexOf( TILDE_SIGN ) > -1) || (aWinLabel.indexOf( AMPERSAND_SIGN ) > -1) )
116 sal_Int32 nStrLen = aWinLabel.getLength( );
118 // in the worst case the new string is
119 // doubled in length, maybe some waste
120 // of memory but how long is a label
121 // normally(?)
122 OUStringBuffer aBuffer( nStrLen * 2 );
124 Replace( aWinLabel, TILDE_SIGN, AMPERSAND_SIGN, aBuffer );
126 aWinLabel = aBuffer.makeStringAndClear( );
129 return aWinLabel;
132 // converts a windows label to a soffice label
133 // the following rules for character replacements
134 // will be done:
135 // '&' -> '~'
136 // '&&' -> '&'
137 // '~' -> '~~'
139 OUString WindowsToSOfficeLabel( const OUString& aWinLabel )
141 OUString aSOLabel = aWinLabel;
143 if ( (aSOLabel.indexOf( TILDE_SIGN ) > -1) || (aSOLabel.indexOf( AMPERSAND_SIGN ) > -1) )
145 sal_Int32 nStrLen = aSOLabel.getLength( );
147 // in the worst case the new string is
148 // doubled in length, maybe some waste
149 // of memory but how long is a label
150 // normally(?)
151 OUStringBuffer aBuffer( nStrLen * 2 );
153 Replace( aSOLabel, AMPERSAND_SIGN, TILDE_SIGN, aBuffer );
155 aSOLabel = aBuffer.makeStringAndClear( );
158 return aSOLabel;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */