tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / fpicker / source / win32 / WinImplHelper.cxx
blob9f81f6b60ffccf437c2a6af282a8e6f63cbb6615
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 const sal_Unicode TILDE_SIGN = L'~';
28 const sal_Unicode AMPERSAND_SIGN = L'&';
30 // OS NAME Platform Major Minor
32 // Windows NT 3.51 VER_PLATFORM_WIN32_NT 3 51
33 // Windows NT 4.0 VER_PLATFORM_WIN32_NT 4 0
34 // Windows 2000 VER_PLATFORM_WIN32_NT 5 0
35 // Windows XP VER_PLATFORM_WIN32_NT 5 1
36 // Windows Vista VER_PLATFORM_WIN32_NT 6 0
37 // Windows 7 VER_PLATFORM_WIN32_NT 6 1
38 // Windows 95 VER_PLATFORM_WIN32_WINDOWS 4 0
39 // Windows 98 VER_PLATFORM_WIN32_WINDOWS 4 10
40 // Windows ME VER_PLATFORM_WIN32_WINDOWS 4 90
43 static void Replace( const OUString& aLabel, sal_Unicode OldChar, sal_Unicode NewChar, OUStringBuffer& aBuffer )
45 OSL_ASSERT( aLabel.getLength( ) );
46 OSL_ASSERT( aBuffer.getCapacity( ) >= (aLabel.getLength( )) );
48 sal_Int32 i = 0;
49 const sal_Unicode* pCurrent = aLabel.getStr( );
50 const sal_Unicode* pNext = aLabel.getStr( ) + 1;
51 const sal_Unicode* pEnd = aLabel.getStr( ) + aLabel.getLength( );
53 while( pCurrent < pEnd )
55 OSL_ASSERT( pNext <= pEnd );
56 OSL_ASSERT( (i >= 0) && (i < aBuffer.getCapacity( )) );
58 if ( OldChar == *pCurrent )
60 if ( OldChar == *pNext )
62 // two OldChars in line will
63 // be replaced by one
64 // e.g. ~~ -> ~
65 aBuffer.insert( i, *pCurrent );
67 // skip the next one
68 pCurrent++;
69 pNext++;
71 else
73 // one OldChar will be replace
74 // by NexChar
75 aBuffer.insert( i, NewChar );
78 else if ( *pCurrent == NewChar )
80 // a NewChar will be replaced by
81 // two NewChars
82 // e.g. & -> &&
83 aBuffer.insert( i++, *pCurrent );
84 aBuffer.insert( i, *pCurrent );
86 else
88 aBuffer.insert( i, *pCurrent );
91 pCurrent++;
92 pNext++;
93 i++;
97 // converts a soffice label to a windows label
98 // the following rules for character replacements
99 // will be done:
100 // '~' -> '&'
101 // '~~' -> '~'
102 // '&' -> '&&'
104 OUString SOfficeToWindowsLabel( const OUString& aSOLabel )
106 OUString aWinLabel = aSOLabel;
108 if ( (aWinLabel.indexOf( TILDE_SIGN ) > -1) || (aWinLabel.indexOf( AMPERSAND_SIGN ) > -1) )
110 sal_Int32 nStrLen = aWinLabel.getLength( );
112 // in the worst case the new string is
113 // doubled in length, maybe some waste
114 // of memory but how long is a label
115 // normally(?)
116 OUStringBuffer aBuffer( nStrLen * 2 );
118 Replace( aWinLabel, TILDE_SIGN, AMPERSAND_SIGN, aBuffer );
120 aWinLabel = aBuffer.makeStringAndClear( );
123 return aWinLabel;
126 // converts a windows label to a soffice label
127 // the following rules for character replacements
128 // will be done:
129 // '&' -> '~'
130 // '&&' -> '&'
131 // '~' -> '~~'
133 OUString WindowsToSOfficeLabel( const OUString& aWinLabel )
135 OUString aSOLabel = aWinLabel;
137 if ( (aSOLabel.indexOf( TILDE_SIGN ) > -1) || (aSOLabel.indexOf( AMPERSAND_SIGN ) > -1) )
139 sal_Int32 nStrLen = aSOLabel.getLength( );
141 // in the worst case the new string is
142 // doubled in length, maybe some waste
143 // of memory but how long is a label
144 // normally(?)
145 OUStringBuffer aBuffer( nStrLen * 2 );
147 Replace( aSOLabel, AMPERSAND_SIGN, TILDE_SIGN, aBuffer );
149 aSOLabel = aBuffer.makeStringAndClear( );
152 return aSOLabel;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */