1*06b3ce53SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*06b3ce53SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*06b3ce53SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*06b3ce53SAndrew Rist  * distributed with this work for additional information
6*06b3ce53SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*06b3ce53SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*06b3ce53SAndrew Rist  * "License"); you may not use this file except in compliance
9*06b3ce53SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*06b3ce53SAndrew Rist  *
11*06b3ce53SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*06b3ce53SAndrew Rist  *
13*06b3ce53SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*06b3ce53SAndrew Rist  * software distributed under the License is distributed on an
15*06b3ce53SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*06b3ce53SAndrew Rist  * KIND, either express or implied.  See the License for the
17*06b3ce53SAndrew Rist  * specific language governing permissions and limitations
18*06b3ce53SAndrew Rist  * under the License.
19*06b3ce53SAndrew Rist  *
20*06b3ce53SAndrew Rist  *************************************************************/
21*06b3ce53SAndrew Rist 
22*06b3ce53SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "resourcemanager.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <vcl/fixed.hxx>
31cdf0e10cSrcweir #include <svtools/stdctrl.hxx>
32cdf0e10cSrcweir #include <svl/solar.hrc>
33cdf0e10cSrcweir #include <unotools/syslocale.hxx>
34cdf0e10cSrcweir #include <rtl/ustring.h>
35cdf0e10cSrcweir #include <rtl/ustrbuf.h>
36cdf0e10cSrcweir #include <vector>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using ::rtl::OUString;
39cdf0e10cSrcweir using namespace std;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace XmlSec
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	static ResMgr*			pResMgr = 0;
44cdf0e10cSrcweir     static SvtSysLocale*    pSysLocale = 0;
45cdf0e10cSrcweir 
GetResMgr(void)46cdf0e10cSrcweir 	ResMgr* GetResMgr( void )
47cdf0e10cSrcweir 	{
48cdf0e10cSrcweir 		if( !pResMgr )
49cdf0e10cSrcweir 		{
50cdf0e10cSrcweir 			ByteString	aName( "xmlsec" );
51cdf0e10cSrcweir //    		pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), Application::GetSettings().GetUILanguage() );
52cdf0e10cSrcweir //			LanguageType	aLang( LANGUAGE_ENGLISH_US );
53cdf0e10cSrcweir //			pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), aLang );
54cdf0e10cSrcweir // MT: Change to Locale
55cdf0e10cSrcweir 			pResMgr = ResMgr::CreateResMgr( aName.GetBuffer() );
56cdf0e10cSrcweir 		}
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	return pResMgr;
59cdf0e10cSrcweir 	}
60cdf0e10cSrcweir 
GetLocaleData(void)61cdf0e10cSrcweir 	const LocaleDataWrapper&    GetLocaleData( void )
62cdf0e10cSrcweir 	{
63cdf0e10cSrcweir         if (!pSysLocale)
64cdf0e10cSrcweir             pSysLocale = new SvtSysLocale;
65cdf0e10cSrcweir         return pSysLocale->GetLocaleData();
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 
GetDateTime(const::com::sun::star::util::DateTime & _rDT)68cdf0e10cSrcweir 	DateTime GetDateTime( const ::com::sun::star::util::DateTime& _rDT )
69cdf0e10cSrcweir 	{
70cdf0e10cSrcweir 		return DateTime(
71cdf0e10cSrcweir 			Date( _rDT.Day, _rDT.Month, _rDT.Year ),
72cdf0e10cSrcweir 			Time( _rDT.Hours, _rDT.Minutes, _rDT.Seconds, _rDT.HundredthSeconds ) );
73cdf0e10cSrcweir 	}
74cdf0e10cSrcweir 
GetDateTimeString(const::com::sun::star::util::DateTime & _rDT)75cdf0e10cSrcweir 	String GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT )
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir         // --> PB 2004-10-12 #i20172# String with date and time information
78cdf0e10cSrcweir         DateTime aDT( GetDateTime( _rDT ) );
79cdf0e10cSrcweir         const LocaleDataWrapper& rLoDa = GetLocaleData();
80cdf0e10cSrcweir         String sRet( rLoDa.getDate( aDT ) );
81cdf0e10cSrcweir         sRet += ' ';
82cdf0e10cSrcweir         sRet += rLoDa.getTime( aDT );
83cdf0e10cSrcweir         return sRet;
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 
GetDateTimeString(const rtl::OUString & _rDate,const rtl::OUString & _rTime)86cdf0e10cSrcweir 	String GetDateTimeString( const rtl::OUString& _rDate, const rtl::OUString& _rTime )
87cdf0e10cSrcweir 	{
88cdf0e10cSrcweir 		String sDay( _rDate, 6, 2 );
89cdf0e10cSrcweir 		String sMonth( _rDate, 4, 2 );
90cdf0e10cSrcweir 		String sYear( _rDate, 0, 4 );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		String sHour( _rTime, 0, 2 );
93cdf0e10cSrcweir 		String sMin( _rTime, 4, 2 );
94cdf0e10cSrcweir 		String sSec( _rTime, 6, 2 );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 		Date aDate( (sal_uInt16)sDay.ToInt32(), (sal_uInt16) sMonth.ToInt32(), (sal_uInt16)sYear.ToInt32() );
98cdf0e10cSrcweir 		Time aTime( sHour.ToInt32(), sMin.ToInt32(), sSec.ToInt32(), 0 );
99cdf0e10cSrcweir         const LocaleDataWrapper& rLoDa = GetLocaleData();
100cdf0e10cSrcweir 		String aStr( rLoDa.getDate( aDate ) );
101cdf0e10cSrcweir 		aStr.AppendAscii( " " );
102cdf0e10cSrcweir 		aStr += rLoDa.getTime( aTime );
103cdf0e10cSrcweir 		return aStr;
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
GetDateString(const::com::sun::star::util::DateTime & _rDT)106cdf0e10cSrcweir 	String GetDateString( const ::com::sun::star::util::DateTime& _rDT )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		return GetLocaleData().getDate( GetDateTime( _rDT ) );
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     /*
112cdf0e10cSrcweir         Creates two strings based on the distinguished name which are displayed in the
113cdf0e10cSrcweir         certificate details view. The first string contains only the values of the attribute
114cdf0e10cSrcweir         and valudes pairs, which are separated by commas. All escape characters ('"') are
115cdf0e10cSrcweir         removed.
116cdf0e10cSrcweir         The second string is for the details view at the bottom. It shows the attribute/value
117cdf0e10cSrcweir         pairs on different lines. All escape characters ('"') are removed.
118cdf0e10cSrcweir     */
GetDNForCertDetailsView(const OUString & rRawString)119cdf0e10cSrcweir     pair< OUString, OUString> GetDNForCertDetailsView( const OUString & rRawString)
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(rRawString);
122cdf0e10cSrcweir         ::rtl::OUStringBuffer s1, s2;
123cdf0e10cSrcweir         OUString sEqual(RTL_CONSTASCII_USTRINGPARAM(" = "));
124cdf0e10cSrcweir         typedef vector< pair < OUString, OUString > >::const_iterator CIT;
125cdf0e10cSrcweir         for (CIT i = vecAttrValueOfDN.begin(); i < vecAttrValueOfDN.end(); i ++)
126cdf0e10cSrcweir         {
127cdf0e10cSrcweir             if (i != vecAttrValueOfDN.begin())
128cdf0e10cSrcweir             {
129cdf0e10cSrcweir                 s1.append(static_cast<sal_Unicode>(','));
130cdf0e10cSrcweir                 s2.append(static_cast<sal_Unicode>('\n'));
131cdf0e10cSrcweir             }
132cdf0e10cSrcweir             s1.append(i->second);
133cdf0e10cSrcweir             s2.append(i->first);
134cdf0e10cSrcweir             s2.append(sEqual);
135cdf0e10cSrcweir             s2.append(i->second);
136cdf0e10cSrcweir         }
137cdf0e10cSrcweir         return make_pair(s1.makeStringAndClear(), s2.makeStringAndClear());
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir /*
141cdf0e10cSrcweir     Whenever the attribute value contains special characters, such as '"' or ',' (without '')
142cdf0e10cSrcweir     then the value will be enclosed in double quotes by the respective Windows or NSS function
143cdf0e10cSrcweir     which we use to retrieve, for example, the subject name. If double quotes appear in the value then
144cdf0e10cSrcweir     they are escaped with a double quote. This function removes the escape characters.
145cdf0e10cSrcweir */
146cdf0e10cSrcweir #ifdef WNT
parseDN(const OUString & rRawString)147cdf0e10cSrcweir vector< pair< OUString, OUString> > parseDN(const OUString& rRawString)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir         vector< pair<OUString, OUString> > retVal;
150cdf0e10cSrcweir         bool bInEscape = false;
151cdf0e10cSrcweir         bool bInValue = false;
152cdf0e10cSrcweir         bool bInType = true;
153cdf0e10cSrcweir         sal_Int32 nTypeNameStart = 0;
154cdf0e10cSrcweir         OUString sType;
155cdf0e10cSrcweir         ::rtl::OUStringBuffer sbufValue;
156cdf0e10cSrcweir         sal_Int32 length = rRawString.getLength();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         for (sal_Int32 i = 0; i < length; i++)
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             sal_Unicode c = rRawString[i];
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             if (c == '=')
163cdf0e10cSrcweir             {
164cdf0e10cSrcweir                 if (! bInValue)
165cdf0e10cSrcweir                 {
166cdf0e10cSrcweir                     sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart);
167cdf0e10cSrcweir                     sType = sType.trim();
168cdf0e10cSrcweir                     bInType = false;
169cdf0e10cSrcweir                 }
170cdf0e10cSrcweir                 else
171cdf0e10cSrcweir                 {
172cdf0e10cSrcweir                     sbufValue.append(c);
173cdf0e10cSrcweir                 }
174cdf0e10cSrcweir             }
175cdf0e10cSrcweir             else if (c == '"')
176cdf0e10cSrcweir             {
177cdf0e10cSrcweir                 if (!bInEscape)
178cdf0e10cSrcweir                 {
179cdf0e10cSrcweir                     //If this is the quote is the first of the couple which enclose the
180cdf0e10cSrcweir                     //whole value, because the value contains special characters
181cdf0e10cSrcweir                     //then we just drop it. That is, this character must be followed by
182cdf0e10cSrcweir                     //a character which is not '"'.
183cdf0e10cSrcweir                     if ( i + 1 < length && rRawString[i+1] == '"')
184cdf0e10cSrcweir                         bInEscape = true;
185cdf0e10cSrcweir                     else
186cdf0e10cSrcweir                         bInValue = !bInValue; //value is enclosed in " "
187cdf0e10cSrcweir                 }
188cdf0e10cSrcweir                 else
189cdf0e10cSrcweir                 {
190cdf0e10cSrcweir                     //This quote is escaped by a preceding quote and therefore is
191cdf0e10cSrcweir                     //part of the value
192cdf0e10cSrcweir                     sbufValue.append(c);
193cdf0e10cSrcweir                     bInEscape = false;
194cdf0e10cSrcweir                 }
195cdf0e10cSrcweir             }
196cdf0e10cSrcweir             else if (c == ',' || c == '+')
197cdf0e10cSrcweir             {
198cdf0e10cSrcweir                 //The comma separate the attribute value pairs.
199cdf0e10cSrcweir                 //If the comma is not part of a value (the value would then be enclosed in '"'),
200cdf0e10cSrcweir                 //then we have reached the end of the value
201cdf0e10cSrcweir                 if (!bInValue)
202cdf0e10cSrcweir                 {
203cdf0e10cSrcweir                     OSL_ASSERT(sType.getLength());
204cdf0e10cSrcweir                     retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
205cdf0e10cSrcweir                     sType = OUString();
206cdf0e10cSrcweir                     //The next char is the start of the new type
207cdf0e10cSrcweir                     nTypeNameStart = i + 1;
208cdf0e10cSrcweir                     bInType = true;
209cdf0e10cSrcweir                 }
210cdf0e10cSrcweir                 else
211cdf0e10cSrcweir                 {
212cdf0e10cSrcweir                     //The whole string is enclosed because it contains special characters.
213cdf0e10cSrcweir                     //The enclosing '"' are not part of certificate but will be added by
214cdf0e10cSrcweir                     //the function (Windows or NSS) which retrieves DN
215cdf0e10cSrcweir                     sbufValue.append(c);
216cdf0e10cSrcweir                 }
217cdf0e10cSrcweir             }
218cdf0e10cSrcweir             else
219cdf0e10cSrcweir             {
220cdf0e10cSrcweir                 if (!bInType)
221cdf0e10cSrcweir                     sbufValue.append(c);
222cdf0e10cSrcweir             }
223cdf0e10cSrcweir         }
224cdf0e10cSrcweir         if (sbufValue.getLength())
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             OSL_ASSERT(sType.getLength());
227cdf0e10cSrcweir             retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir         return retVal;
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir #else
parseDN(const OUString & rRawString)232cdf0e10cSrcweir vector< pair< OUString, OUString> > parseDN(const OUString& rRawString)
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         vector< pair<OUString, OUString> > retVal;
235cdf0e10cSrcweir         //bInEscape == true means that the preceding character is an escape character
236cdf0e10cSrcweir         bool bInEscape = false;
237cdf0e10cSrcweir         bool bInValue = false;
238cdf0e10cSrcweir         bool bInType = true;
239cdf0e10cSrcweir         sal_Int32 nTypeNameStart = 0;
240cdf0e10cSrcweir         OUString sType;
241cdf0e10cSrcweir         ::rtl::OUStringBuffer sbufValue;
242cdf0e10cSrcweir         sal_Int32 length = rRawString.getLength();
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         for (sal_Int32 i = 0; i < length; i++)
245cdf0e10cSrcweir         {
246cdf0e10cSrcweir             sal_Unicode c = rRawString[i];
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             if (c == '=')
249cdf0e10cSrcweir             {
250cdf0e10cSrcweir                 if (! bInValue)
251cdf0e10cSrcweir                 {
252cdf0e10cSrcweir                     sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart);
253cdf0e10cSrcweir                     sType = sType.trim();
254cdf0e10cSrcweir                     bInType = false;
255cdf0e10cSrcweir                 }
256cdf0e10cSrcweir                 else
257cdf0e10cSrcweir                 {
258cdf0e10cSrcweir                     sbufValue.append(c);
259cdf0e10cSrcweir                 }
260cdf0e10cSrcweir             }
261cdf0e10cSrcweir             else if (c == '\\')
262cdf0e10cSrcweir             {
263cdf0e10cSrcweir                 if (!bInEscape)
264cdf0e10cSrcweir                 {
265cdf0e10cSrcweir                     bInEscape = true;
266cdf0e10cSrcweir                 }
267cdf0e10cSrcweir                 else
268cdf0e10cSrcweir                 { // bInEscape is true
269cdf0e10cSrcweir                     sbufValue.append(c);
270cdf0e10cSrcweir                     bInEscape = false;
271cdf0e10cSrcweir                 }
272cdf0e10cSrcweir             }
273cdf0e10cSrcweir             else if (c == '"')
274cdf0e10cSrcweir             {
275cdf0e10cSrcweir                 //an unescaped '"' is either at the beginning or end of the value
276cdf0e10cSrcweir                 if (!bInEscape)
277cdf0e10cSrcweir                 {
278cdf0e10cSrcweir                     if ( !bInValue)
279cdf0e10cSrcweir                         bInValue = true;
280cdf0e10cSrcweir                     else if (bInValue)
281cdf0e10cSrcweir                         bInValue = false;
282cdf0e10cSrcweir                 }
283cdf0e10cSrcweir                 else
284cdf0e10cSrcweir                 {
285cdf0e10cSrcweir                     //This quote is escaped by a preceding quote and therefore is
286cdf0e10cSrcweir                     //part of the value
287cdf0e10cSrcweir                     sbufValue.append(c);
288cdf0e10cSrcweir                     bInEscape = false;
289cdf0e10cSrcweir                 }
290cdf0e10cSrcweir             }
291cdf0e10cSrcweir             else if (c == ',' || c == '+')
292cdf0e10cSrcweir             {
293cdf0e10cSrcweir                 //The comma separate the attribute value pairs.
294cdf0e10cSrcweir                 //If the comma is not part of a value (the value would then be enclosed in '"'),
295cdf0e10cSrcweir                 //then we have reached the end of the value
296cdf0e10cSrcweir                 if (!bInValue)
297cdf0e10cSrcweir                 {
298cdf0e10cSrcweir                     OSL_ASSERT(sType.getLength());
299cdf0e10cSrcweir                     retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
300cdf0e10cSrcweir                     sType = OUString();
301cdf0e10cSrcweir                     //The next char is the start of the new type
302cdf0e10cSrcweir                     nTypeNameStart = i + 1;
303cdf0e10cSrcweir                     bInType = true;
304cdf0e10cSrcweir                 }
305cdf0e10cSrcweir                 else
306cdf0e10cSrcweir                 {
307cdf0e10cSrcweir                     //The whole string is enclosed because it contains special characters.
308cdf0e10cSrcweir                     //The enclosing '"' are not part of certificate but will be added by
309cdf0e10cSrcweir                     //the function (Windows or NSS) which retrieves DN
310cdf0e10cSrcweir                     sbufValue.append(c);
311cdf0e10cSrcweir                 }
312cdf0e10cSrcweir             }
313cdf0e10cSrcweir             else
314cdf0e10cSrcweir             {
315cdf0e10cSrcweir                 if (!bInType)
316cdf0e10cSrcweir                 {
317cdf0e10cSrcweir                     sbufValue.append(c);
318cdf0e10cSrcweir                     bInEscape = false;
319cdf0e10cSrcweir                 }
320cdf0e10cSrcweir             }
321cdf0e10cSrcweir         }
322cdf0e10cSrcweir         if (sbufValue.getLength())
323cdf0e10cSrcweir         {
324cdf0e10cSrcweir             OSL_ASSERT(sType.getLength());
325cdf0e10cSrcweir             retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir         return retVal;
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir #endif
331cdf0e10cSrcweir 
GetContentPart(const String & _rRawString)332cdf0e10cSrcweir     String GetContentPart( const String& _rRawString )
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         char const * aIDs[] = { "CN", "OU", "O", "E", NULL };
335cdf0e10cSrcweir         OUString retVal;
336cdf0e10cSrcweir         int i = 0;
337cdf0e10cSrcweir         vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(_rRawString);
338cdf0e10cSrcweir         while ( aIDs[i] )
339cdf0e10cSrcweir         {
340cdf0e10cSrcweir             OUString sPartId = OUString::createFromAscii( aIDs[i++] );
341cdf0e10cSrcweir             typedef vector< pair < OUString, OUString > >::const_iterator CIT;
342cdf0e10cSrcweir             for (CIT idn = vecAttrValueOfDN.begin(); idn != vecAttrValueOfDN.end(); idn++)
343cdf0e10cSrcweir             {
344cdf0e10cSrcweir                 if (idn->first.equals(sPartId))
345cdf0e10cSrcweir                 {
346cdf0e10cSrcweir                     retVal = idn->second;
347cdf0e10cSrcweir                     break;
348cdf0e10cSrcweir                 }
349cdf0e10cSrcweir             }
350cdf0e10cSrcweir             if (retVal.getLength())
351cdf0e10cSrcweir                 break;
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir         return retVal;
354cdf0e10cSrcweir     }
355cdf0e10cSrcweir 
GetHexString(const::com::sun::star::uno::Sequence<sal_Int8> & _rSeq,const char * _pSep,sal_uInt16 _nLineBreak)356cdf0e10cSrcweir 	String GetHexString( const ::com::sun::star::uno::Sequence< sal_Int8 >& _rSeq, const char* _pSep, sal_uInt16 _nLineBreak )
357cdf0e10cSrcweir 	{
358cdf0e10cSrcweir 		const sal_Int8*			pSerNumSeq = _rSeq.getConstArray();
359cdf0e10cSrcweir 		int						nCnt = _rSeq.getLength();
360cdf0e10cSrcweir 		String					aStr;
361cdf0e10cSrcweir 		const char				pHexDigs[ 17 ] = "0123456789ABCDEF";
362cdf0e10cSrcweir 		char					pBuffer[ 3 ] = "  ";
363cdf0e10cSrcweir 		sal_uInt8					nNum;
364cdf0e10cSrcweir 		sal_uInt16					nBreakStart = _nLineBreak? _nLineBreak : 1;
365cdf0e10cSrcweir 		sal_uInt16					nBreak = nBreakStart;
366cdf0e10cSrcweir 		for( int i = 0 ; i < nCnt ; ++i )
367cdf0e10cSrcweir 		{
368cdf0e10cSrcweir 			nNum = sal_uInt8( pSerNumSeq[ i ] );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 			//MM : exchange the buffer[0] and buffer[1], which make it consistent with Mozilla and Windows
371cdf0e10cSrcweir 			pBuffer[ 1 ] = pHexDigs[ nNum & 0x0F ];
372cdf0e10cSrcweir 			nNum >>= 4;
373cdf0e10cSrcweir 			pBuffer[ 0 ] = pHexDigs[ nNum ];
374cdf0e10cSrcweir 			aStr.AppendAscii( pBuffer );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 			--nBreak;
377cdf0e10cSrcweir 			if( nBreak )
378cdf0e10cSrcweir 				aStr.AppendAscii( _pSep );
379cdf0e10cSrcweir 			else
380cdf0e10cSrcweir 			{
381cdf0e10cSrcweir 				nBreak = nBreakStart;
382cdf0e10cSrcweir 				aStr.AppendAscii( "\n" );
383cdf0e10cSrcweir 			}
384cdf0e10cSrcweir 		}
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 		return aStr;
387cdf0e10cSrcweir 	}
388cdf0e10cSrcweir 
ShrinkToFitWidth(Control & _rCtrl,long _nOffs)389cdf0e10cSrcweir 	long ShrinkToFitWidth( Control& _rCtrl, long _nOffs )
390cdf0e10cSrcweir 	{
391cdf0e10cSrcweir 		long	nWidth = _rCtrl.GetTextWidth( _rCtrl.GetText() );
392cdf0e10cSrcweir 		Size	aSize( _rCtrl.GetSizePixel() );
393cdf0e10cSrcweir 		nWidth += _nOffs;
394cdf0e10cSrcweir 		aSize.Width() = nWidth;
395cdf0e10cSrcweir 		_rCtrl.SetSizePixel( aSize );
396cdf0e10cSrcweir 		return nWidth;
397cdf0e10cSrcweir 	}
398cdf0e10cSrcweir 
AlignAfterImage(const FixedImage & _rImage,Control & _rCtrl,long _nXOffset)399cdf0e10cSrcweir 	void AlignAfterImage( const FixedImage& _rImage, Control& _rCtrl, long _nXOffset )
400cdf0e10cSrcweir 	{
401cdf0e10cSrcweir 		Point	aPos( _rImage.GetPosPixel() );
402cdf0e10cSrcweir 		Size	aSize( _rImage.GetSizePixel() );
403cdf0e10cSrcweir 		long	n = aPos.X();
404cdf0e10cSrcweir 		n += aSize.Width();
405cdf0e10cSrcweir 		n += _nXOffset;
406cdf0e10cSrcweir 		aPos.X() = n;
407cdf0e10cSrcweir 		n = aPos.Y();
408cdf0e10cSrcweir 		n += aSize.Height() / 2;					// y-position is in the middle of the image
409cdf0e10cSrcweir 		n -= _rCtrl.GetSizePixel().Height() / 2;	// center Control
410cdf0e10cSrcweir 		aPos.Y() = n;
411cdf0e10cSrcweir 		_rCtrl.SetPosPixel( aPos );
412cdf0e10cSrcweir 	}
413cdf0e10cSrcweir 
AlignAfterImage(const FixedImage & _rImage,FixedInfo & _rFI,long _nXOffset)414cdf0e10cSrcweir 	void AlignAfterImage( const FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset )
415cdf0e10cSrcweir 	{
416cdf0e10cSrcweir 		AlignAfterImage( _rImage, static_cast< Control& >( _rFI ), _nXOffset );
417cdf0e10cSrcweir 		ShrinkToFitWidth( _rFI );
418cdf0e10cSrcweir 	}
419cdf0e10cSrcweir 
AlignAndFitImageAndControl(FixedImage & _rImage,FixedInfo & _rFI,long _nXOffset)420cdf0e10cSrcweir 	void AlignAndFitImageAndControl( FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset )
421cdf0e10cSrcweir 	{
422cdf0e10cSrcweir 		_rImage.SetSizePixel( _rImage.GetImage().GetSizePixel() );
423cdf0e10cSrcweir 		AlignAfterImage( _rImage, _rFI, _nXOffset );
424cdf0e10cSrcweir 	}
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 
428