xref: /aoo41x/main/svtools/source/control/ctrlbox.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #define _CTRLBOX_CXX
32*cdf0e10cSrcweir #include <tools/debug.hxx>
33*cdf0e10cSrcweir #include <vcl/svapp.hxx>
34*cdf0e10cSrcweir #include <vcl/field.hxx>
35*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
36*cdf0e10cSrcweir #include <unotools/charclass.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <svtools/svtdata.hxx>
39*cdf0e10cSrcweir #include <svtools/svtools.hrc>
40*cdf0e10cSrcweir #include <svtools/ctrlbox.hxx>
41*cdf0e10cSrcweir #include <svtools/ctrltool.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <vcl/i18nhelp.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #define IMGTEXTSPACE    2
46*cdf0e10cSrcweir #define EXTRAFONTSIZE   5
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir static sal_Unicode aImplSymbolFontText[] = {0xF021,0xF032,0xF043,0xF054,0xF065,0xF076,0xF0B7,0xF0C8,0};
49*cdf0e10cSrcweir static sal_Unicode aImplStarSymbolText[] = {0x2706,0x2704,0x270D,0xE033,0x2211,0x2288,0};
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir // ========================================================================
52*cdf0e10cSrcweir // ColorListBox
53*cdf0e10cSrcweir // ========================================================================
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir // --------------------
56*cdf0e10cSrcweir // - ImplColorListData -
57*cdf0e10cSrcweir // --------------------
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir struct ImplColorListData
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     Color       aColor;
62*cdf0e10cSrcweir     sal_Bool        bColor;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir                 ImplColorListData() : aColor( COL_BLACK ) { bColor = sal_False; }
65*cdf0e10cSrcweir                 ImplColorListData( const Color& rColor ) : aColor( rColor ) { bColor = sal_True; }
66*cdf0e10cSrcweir };
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir DECLARE_LIST( ImpColorList, ImplColorListData* )
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // -----------------------------------------------------------------------
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir void ColorListBox::ImplInit()
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     pColorList = new ImpColorList( 256, 64 );
75*cdf0e10cSrcweir     aImageSize.Width()  = GetTextWidth( XubString( RTL_CONSTASCII_USTRINGPARAM( "xxx" ) ) );
76*cdf0e10cSrcweir     aImageSize.Height() = GetTextHeight();
77*cdf0e10cSrcweir     aImageSize.Height() -= 2;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     EnableUserDraw( sal_True );
80*cdf0e10cSrcweir     SetUserItemSize( aImageSize );
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir // -----------------------------------------------------------------------
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir void ColorListBox::ImplDestroyColorEntries()
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     for ( sal_uInt16 n = (sal_uInt16) pColorList->Count(); n; )
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir         ImplColorListData* pData = pColorList->GetObject( --n );
90*cdf0e10cSrcweir         delete pData;
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir     pColorList->Clear();
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir // -----------------------------------------------------------------------
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir ColorListBox::ColorListBox( Window* pParent, WinBits nWinStyle ) :
98*cdf0e10cSrcweir     ListBox( pParent, nWinStyle )
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     ImplInit();
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir // -----------------------------------------------------------------------
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir ColorListBox::ColorListBox( Window* pParent, const ResId& rResId ) :
106*cdf0e10cSrcweir     ListBox( pParent, rResId )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir     ImplInit();
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir // -----------------------------------------------------------------------
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir ColorListBox::~ColorListBox()
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     ImplDestroyColorEntries();
116*cdf0e10cSrcweir     delete pColorList;
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir // -----------------------------------------------------------------------
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir sal_uInt16 ColorListBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     nPos = ListBox::InsertEntry( rStr, nPos );
124*cdf0e10cSrcweir     if ( nPos != LISTBOX_ERROR )
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         ImplColorListData* pData = new ImplColorListData;
127*cdf0e10cSrcweir         pColorList->Insert( pData, nPos );
128*cdf0e10cSrcweir     }
129*cdf0e10cSrcweir     return nPos;
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir // -----------------------------------------------------------------------
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir sal_uInt16 ColorListBox::InsertEntry( const Color& rColor, const XubString& rStr,
135*cdf0e10cSrcweir                                 sal_uInt16 nPos )
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir     nPos = ListBox::InsertEntry( rStr, nPos );
138*cdf0e10cSrcweir     if ( nPos != LISTBOX_ERROR )
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         ImplColorListData* pData = new ImplColorListData( rColor );
141*cdf0e10cSrcweir         pColorList->Insert( pData, nPos );
142*cdf0e10cSrcweir     }
143*cdf0e10cSrcweir     return nPos;
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir // -----------------------------------------------------------------------
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir void ColorListBox::InsertAutomaticEntry()
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     // insert the "Automatic"-entry always on the first position
151*cdf0e10cSrcweir     InsertEntry( Color( COL_AUTO ), SvtResId( STR_SVT_AUTOMATIC_COLOR ), 0 );
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir // -----------------------------------------------------------------------
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir void ColorListBox::RemoveEntry( sal_uInt16 nPos )
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir     ListBox::RemoveEntry( nPos );
159*cdf0e10cSrcweir     delete pColorList->Remove( nPos );
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir // -----------------------------------------------------------------------
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir void ColorListBox::Clear()
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir     ImplDestroyColorEntries();
167*cdf0e10cSrcweir     ListBox::Clear();
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir // -----------------------------------------------------------------------
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void ColorListBox::CopyEntries( const ColorListBox& rBox )
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     // Liste leeren
175*cdf0e10cSrcweir     ImplDestroyColorEntries();
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     // Daten kopieren
178*cdf0e10cSrcweir     sal_uInt16 nCount = (sal_uInt16) rBox.pColorList->Count();
179*cdf0e10cSrcweir     for ( sal_uInt16 n = 0; n < nCount; n++ )
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir         ImplColorListData* pData = rBox.pColorList->GetObject( n );
182*cdf0e10cSrcweir         sal_uInt16 nPos = InsertEntry( rBox.GetEntry( n ), LISTBOX_APPEND );
183*cdf0e10cSrcweir         if ( nPos != LISTBOX_ERROR )
184*cdf0e10cSrcweir             pColorList->Insert( new ImplColorListData( *pData ), nPos );
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir // -----------------------------------------------------------------------
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir sal_uInt16 ColorListBox::GetEntryPos( const Color& rColor ) const
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     for( sal_uInt16 n = (sal_uInt16) pColorList->Count(); n; )
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         ImplColorListData* pData = pColorList->GetObject( --n );
195*cdf0e10cSrcweir         if ( pData->bColor && ( pData->aColor == rColor ) )
196*cdf0e10cSrcweir             return n;
197*cdf0e10cSrcweir     }
198*cdf0e10cSrcweir     return LISTBOX_ENTRY_NOTFOUND;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir // -----------------------------------------------------------------------
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir Color ColorListBox::GetEntryColor( sal_uInt16 nPos ) const
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir     Color aColor;
206*cdf0e10cSrcweir     ImplColorListData* pData = pColorList->GetObject( nPos );
207*cdf0e10cSrcweir     if ( pData && pData->bColor )
208*cdf0e10cSrcweir         aColor = pData->aColor;
209*cdf0e10cSrcweir     return aColor;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir // -----------------------------------------------------------------------
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir void ColorListBox::UserDraw( const UserDrawEvent& rUDEvt )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     ImplColorListData* pData = pColorList->GetObject( rUDEvt.GetItemId() );
217*cdf0e10cSrcweir     if ( pData )
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         if ( pData->bColor )
220*cdf0e10cSrcweir         {
221*cdf0e10cSrcweir             Point aPos( rUDEvt.GetRect().TopLeft() );
222*cdf0e10cSrcweir             aPos.X() += 2;
223*cdf0e10cSrcweir             aPos.Y() += ( rUDEvt.GetRect().GetHeight() - aImageSize.Height() ) / 2;
224*cdf0e10cSrcweir             rUDEvt.GetDevice()->Push();
225*cdf0e10cSrcweir             rUDEvt.GetDevice()->SetFillColor( pData->aColor );
226*cdf0e10cSrcweir             rUDEvt.GetDevice()->SetLineColor( rUDEvt.GetDevice()->GetTextColor() );
227*cdf0e10cSrcweir             rUDEvt.GetDevice()->DrawRect( Rectangle( aPos, aImageSize ) );
228*cdf0e10cSrcweir             rUDEvt.GetDevice()->Pop();
229*cdf0e10cSrcweir             ListBox::DrawEntry( rUDEvt, sal_False, sal_True, sal_False );
230*cdf0e10cSrcweir         }
231*cdf0e10cSrcweir         else
232*cdf0e10cSrcweir             ListBox::DrawEntry( rUDEvt, sal_False, sal_True, sal_True );
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir     else
235*cdf0e10cSrcweir         ListBox::DrawEntry( rUDEvt, sal_True, sal_True, sal_False );
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir // =======================================================================
239*cdf0e10cSrcweir // LineListBox
240*cdf0e10cSrcweir // =======================================================================
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir // -------------------
243*cdf0e10cSrcweir // - ImpListListData -
244*cdf0e10cSrcweir // -------------------
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir struct ImpLineListData
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     long    nLine1;
249*cdf0e10cSrcweir     long    nLine2;
250*cdf0e10cSrcweir     long    nDistance;
251*cdf0e10cSrcweir };
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir DECLARE_LIST( ImpLineList, ImpLineListData* )
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir // -----------------------------------------------------------------------
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir inline const Color& LineListBox::GetPaintColor( void ) const
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir 	return maPaintCol;
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir // -----------------------------------------------------------------------
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
265*cdf0e10cSrcweir                             Bitmap& rBmp, XubString& rStr )
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     Size aSize = GetOutputSizePixel();
268*cdf0e10cSrcweir     aSize.Width() -= 20;
269*cdf0e10cSrcweir     aSize.Width() -= aTxtSize.Width();
270*cdf0e10cSrcweir     aSize.Height() = aTxtSize.Height();
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     // SourceUnit nach Twips
273*cdf0e10cSrcweir     if ( eSourceUnit == FUNIT_POINT )
274*cdf0e10cSrcweir     {
275*cdf0e10cSrcweir         nLine1      *= 20;
276*cdf0e10cSrcweir         nLine2      *= 20;
277*cdf0e10cSrcweir         nDistance   *= 20;
278*cdf0e10cSrcweir     }
279*cdf0e10cSrcweir     else if ( eSourceUnit == FUNIT_MM )
280*cdf0e10cSrcweir     {
281*cdf0e10cSrcweir         nLine1      *= 14440;
282*cdf0e10cSrcweir         nLine1      /= 254;
283*cdf0e10cSrcweir         nLine2      *= 14440;
284*cdf0e10cSrcweir         nLine2      /= 254;
285*cdf0e10cSrcweir         nDistance   *= 14440;
286*cdf0e10cSrcweir         nDistance   /= 254;
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     // Linien malen
290*cdf0e10cSrcweir     aSize = aVirDev.PixelToLogic( aSize );
291*cdf0e10cSrcweir     long nPix = aVirDev.PixelToLogic( Size( 0, 1 ) ).Height();
292*cdf0e10cSrcweir     long n1 = nLine1 / 100;
293*cdf0e10cSrcweir     long n2 = nLine2 / 100;
294*cdf0e10cSrcweir     long nDist  = nDistance / 100;
295*cdf0e10cSrcweir     n1 += nPix-1;
296*cdf0e10cSrcweir     n1 -= n1%nPix;
297*cdf0e10cSrcweir     if ( n2 )
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         nDist += nPix-1;
300*cdf0e10cSrcweir         nDist -= nDist%nPix;
301*cdf0e10cSrcweir         n2    += nPix-1;
302*cdf0e10cSrcweir         n2    -= n2%nPix;
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir     long nVirHeight = n1+nDist+n2;
305*cdf0e10cSrcweir     if ( nVirHeight > aSize.Height() )
306*cdf0e10cSrcweir         aSize.Height() = nVirHeight;
307*cdf0e10cSrcweir     // negative Breiten muss und darf man nicht painten
308*cdf0e10cSrcweir     if ( aSize.Width() > 0 )
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         Size aVirSize = aVirDev.LogicToPixel( aSize );
311*cdf0e10cSrcweir         if ( aVirDev.GetOutputSizePixel() != aVirSize )
312*cdf0e10cSrcweir             aVirDev.SetOutputSizePixel( aVirSize );
313*cdf0e10cSrcweir         aVirDev.SetFillColor( GetSettings().GetStyleSettings().GetFieldColor() );
314*cdf0e10cSrcweir         aVirDev.DrawRect( Rectangle( Point(), aSize ) );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir         aVirDev.SetFillColor( GetPaintColor() );
317*cdf0e10cSrcweir         aVirDev.DrawRect( Rectangle( 0, 0, aSize.Width(), n1-nPix ) );
318*cdf0e10cSrcweir         if ( n2 )
319*cdf0e10cSrcweir         {
320*cdf0e10cSrcweir             aVirDev.DrawRect( Rectangle( 0, n1+nDist,
321*cdf0e10cSrcweir                                          aSize.Width(), n1+nDist+n2-nPix ) );
322*cdf0e10cSrcweir         }
323*cdf0e10cSrcweir         rBmp = aVirDev.GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
324*cdf0e10cSrcweir     }
325*cdf0e10cSrcweir     // Twips nach Unit
326*cdf0e10cSrcweir     if ( eUnit == FUNIT_POINT )
327*cdf0e10cSrcweir     {
328*cdf0e10cSrcweir         nLine1      /= 20;
329*cdf0e10cSrcweir         nLine2      /= 20;
330*cdf0e10cSrcweir         nDistance   /= 20;
331*cdf0e10cSrcweir         rStr.AssignAscii( " pt" );
332*cdf0e10cSrcweir     }
333*cdf0e10cSrcweir     else if ( eUnit == FUNIT_MM )
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         nLine1      *= 254;
336*cdf0e10cSrcweir         nLine1      /= 14400;
337*cdf0e10cSrcweir         nLine2      *= 254;
338*cdf0e10cSrcweir         nLine2      /= 14400;
339*cdf0e10cSrcweir         nDistance   *= 254;
340*cdf0e10cSrcweir         nDistance   /= 14400;
341*cdf0e10cSrcweir         rStr.AssignAscii( " mm" );
342*cdf0e10cSrcweir     }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir     String aNum( GetSettings().GetLocaleI18nHelper().GetNum( nLine1+nLine2+nDistance, 2 ) );
345*cdf0e10cSrcweir     rStr.Insert( aNum, 0 );
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir // -----------------------------------------------------------------------
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir void LineListBox::ImplInit()
351*cdf0e10cSrcweir {
352*cdf0e10cSrcweir     aTxtSize.Width()  = GetTextWidth( XubString( RTL_CONSTASCII_USTRINGPARAM( "99,99 mm" ) ) );
353*cdf0e10cSrcweir     aTxtSize.Height() = GetTextHeight();
354*cdf0e10cSrcweir     pLineList   = new ImpLineList;
355*cdf0e10cSrcweir     eUnit       = FUNIT_POINT;
356*cdf0e10cSrcweir     eSourceUnit = FUNIT_POINT;
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir     aVirDev.SetLineColor();
359*cdf0e10cSrcweir     aVirDev.SetMapMode( MapMode( MAP_TWIP ) );
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 	UpdatePaintLineColor();
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir // -----------------------------------------------------------------------
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir LineListBox::LineListBox( Window* pParent, WinBits nWinStyle ) :
367*cdf0e10cSrcweir     ListBox( pParent, nWinStyle ),
368*cdf0e10cSrcweir     aColor( COL_BLACK ),
369*cdf0e10cSrcweir 	maPaintCol( COL_BLACK )
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir     ImplInit();
372*cdf0e10cSrcweir }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir // -----------------------------------------------------------------------
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir LineListBox::LineListBox( Window* pParent, const ResId& rResId ) :
377*cdf0e10cSrcweir     ListBox( pParent, rResId ),
378*cdf0e10cSrcweir     aColor( COL_BLACK ),
379*cdf0e10cSrcweir 	maPaintCol( COL_BLACK )
380*cdf0e10cSrcweir {
381*cdf0e10cSrcweir     ImplInit();
382*cdf0e10cSrcweir }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir // -----------------------------------------------------------------------
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir LineListBox::~LineListBox()
387*cdf0e10cSrcweir {
388*cdf0e10cSrcweir     sal_uLong n = 0;
389*cdf0e10cSrcweir     sal_uLong nCount = pLineList->Count();
390*cdf0e10cSrcweir     while ( n < nCount )
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         ImpLineListData* pData = pLineList->GetObject( n );
393*cdf0e10cSrcweir         if ( pData )
394*cdf0e10cSrcweir             delete pData;
395*cdf0e10cSrcweir         n++;
396*cdf0e10cSrcweir     }
397*cdf0e10cSrcweir     delete pLineList;
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir // -----------------------------------------------------------------------
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir sal_uInt16 LineListBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos )
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir     nPos = ListBox::InsertEntry( rStr, nPos );
405*cdf0e10cSrcweir     if ( nPos != LISTBOX_ERROR )
406*cdf0e10cSrcweir         pLineList->Insert( NULL, nPos );
407*cdf0e10cSrcweir     return nPos;
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir // -----------------------------------------------------------------------
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir sal_uInt16 LineListBox::InsertEntry( long nLine1, long nLine2, long nDistance,
413*cdf0e10cSrcweir                                 sal_uInt16 nPos )
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir     XubString   aStr;
416*cdf0e10cSrcweir     Bitmap      aBmp;
417*cdf0e10cSrcweir     ImpGetLine( nLine1, nLine2, nDistance, aBmp, aStr );
418*cdf0e10cSrcweir     nPos = ListBox::InsertEntry( aStr, aBmp, nPos );
419*cdf0e10cSrcweir     if ( nPos != LISTBOX_ERROR )
420*cdf0e10cSrcweir     {
421*cdf0e10cSrcweir         ImpLineListData* pData = new ImpLineListData;
422*cdf0e10cSrcweir         pData->nLine1    = nLine1;
423*cdf0e10cSrcweir         pData->nLine2    = nLine2;
424*cdf0e10cSrcweir         pData->nDistance = nDistance;
425*cdf0e10cSrcweir         pLineList->Insert( pData, nPos );
426*cdf0e10cSrcweir     }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir     return nPos;
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir // -----------------------------------------------------------------------
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir void LineListBox::RemoveEntry( sal_uInt16 nPos )
434*cdf0e10cSrcweir {
435*cdf0e10cSrcweir     ListBox::RemoveEntry( nPos );
436*cdf0e10cSrcweir     ImpLineListData* pData = pLineList->Remove( nPos );
437*cdf0e10cSrcweir     if ( pData )
438*cdf0e10cSrcweir         delete pData;
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir // -----------------------------------------------------------------------
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir void LineListBox::Clear()
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir     sal_uLong n = 0;
446*cdf0e10cSrcweir     sal_uLong nCount = pLineList->Count();
447*cdf0e10cSrcweir     while ( n < nCount )
448*cdf0e10cSrcweir     {
449*cdf0e10cSrcweir         ImpLineListData* pData = pLineList->GetObject( n );
450*cdf0e10cSrcweir         if ( pData )
451*cdf0e10cSrcweir             delete pData;
452*cdf0e10cSrcweir         n++;
453*cdf0e10cSrcweir     }
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir     pLineList->Clear();
456*cdf0e10cSrcweir     ListBox::Clear();
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir // -----------------------------------------------------------------------
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir sal_uInt16 LineListBox::GetEntryPos( long nLine1, long nLine2,
462*cdf0e10cSrcweir                                 long nDistance ) const
463*cdf0e10cSrcweir {
464*cdf0e10cSrcweir     sal_uLong n = 0;
465*cdf0e10cSrcweir     sal_uLong nCount = pLineList->Count();
466*cdf0e10cSrcweir     while ( n < nCount )
467*cdf0e10cSrcweir     {
468*cdf0e10cSrcweir         ImpLineListData* pData = pLineList->GetObject( n );
469*cdf0e10cSrcweir         if ( pData )
470*cdf0e10cSrcweir         {
471*cdf0e10cSrcweir             if ( (pData->nLine1    == nLine1) &&
472*cdf0e10cSrcweir                 (pData->nLine2    == nLine2) &&
473*cdf0e10cSrcweir                 (pData->nDistance == nDistance) )
474*cdf0e10cSrcweir             return (sal_uInt16)n;
475*cdf0e10cSrcweir         }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir         n++;
478*cdf0e10cSrcweir     }
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     return LISTBOX_ENTRY_NOTFOUND;
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir // -----------------------------------------------------------------------
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir long LineListBox::GetEntryLine1( sal_uInt16 nPos ) const
486*cdf0e10cSrcweir {
487*cdf0e10cSrcweir     ImpLineListData* pData = pLineList->GetObject( nPos );
488*cdf0e10cSrcweir     if ( pData )
489*cdf0e10cSrcweir         return pData->nLine1;
490*cdf0e10cSrcweir     else
491*cdf0e10cSrcweir         return 0;
492*cdf0e10cSrcweir }
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir // -----------------------------------------------------------------------
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir long LineListBox::GetEntryLine2( sal_uInt16 nPos ) const
497*cdf0e10cSrcweir {
498*cdf0e10cSrcweir     ImpLineListData* pData = pLineList->GetObject( nPos );
499*cdf0e10cSrcweir     if ( pData )
500*cdf0e10cSrcweir         return pData->nLine2;
501*cdf0e10cSrcweir     else
502*cdf0e10cSrcweir         return 0;
503*cdf0e10cSrcweir }
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir // -----------------------------------------------------------------------
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir long LineListBox::GetEntryDistance( sal_uInt16 nPos ) const
508*cdf0e10cSrcweir {
509*cdf0e10cSrcweir     ImpLineListData* pData = pLineList->GetObject( nPos );
510*cdf0e10cSrcweir     if ( pData )
511*cdf0e10cSrcweir         return pData->nDistance;
512*cdf0e10cSrcweir     else
513*cdf0e10cSrcweir         return 0;
514*cdf0e10cSrcweir }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir // -----------------------------------------------------------------------
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir void LineListBox::UpdateLineColors( void )
519*cdf0e10cSrcweir {
520*cdf0e10cSrcweir 	if( UpdatePaintLineColor() )
521*cdf0e10cSrcweir 	{
522*cdf0e10cSrcweir 		sal_uLong		nCount = pLineList->Count();
523*cdf0e10cSrcweir 		if( !nCount )
524*cdf0e10cSrcweir 			return;
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 		XubString	aStr;
527*cdf0e10cSrcweir 		Bitmap		aBmp;
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 		// exchange entries which containing lines
530*cdf0e10cSrcweir 		SetUpdateMode( sal_False );
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 		sal_uInt16		nSelEntry = GetSelectEntryPos();
533*cdf0e10cSrcweir 		for( sal_uLong n = 0 ; n < nCount ; ++n )
534*cdf0e10cSrcweir 		{
535*cdf0e10cSrcweir 			ImpLineListData*	pData = pLineList->GetObject( n );
536*cdf0e10cSrcweir 			if( pData )
537*cdf0e10cSrcweir 			{
538*cdf0e10cSrcweir 				// exchange listbox data
539*cdf0e10cSrcweir 				ListBox::RemoveEntry( sal_uInt16( n ) );
540*cdf0e10cSrcweir 				ImpGetLine( pData->nLine1, pData->nLine2, pData->nDistance, aBmp, aStr );
541*cdf0e10cSrcweir 				ListBox::InsertEntry( aStr, aBmp, sal_uInt16( n ) );
542*cdf0e10cSrcweir 			}
543*cdf0e10cSrcweir 		}
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 		if( nSelEntry != LISTBOX_ENTRY_NOTFOUND )
546*cdf0e10cSrcweir 			SelectEntryPos( nSelEntry );
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 		SetUpdateMode( sal_True );
549*cdf0e10cSrcweir 		Invalidate();
550*cdf0e10cSrcweir 	}
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir // -----------------------------------------------------------------------
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir sal_Bool LineListBox::UpdatePaintLineColor( void )
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir 	sal_Bool					bRet = sal_True;
558*cdf0e10cSrcweir 	const StyleSettings&	rSettings = GetSettings().GetStyleSettings();
559*cdf0e10cSrcweir 	Color					aNewCol( rSettings.GetWindowColor().IsDark()? rSettings.GetLabelTextColor() : aColor );
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir 	bRet = aNewCol != maPaintCol;
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 	if( bRet )
564*cdf0e10cSrcweir 		maPaintCol = aNewCol;
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 	return bRet;
567*cdf0e10cSrcweir }
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir // -----------------------------------------------------------------------
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
572*cdf0e10cSrcweir {
573*cdf0e10cSrcweir 	ListBox::DataChanged( rDCEvt );
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 	if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
576*cdf0e10cSrcweir 		UpdateLineColors();
577*cdf0e10cSrcweir }
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir // ===================================================================
580*cdf0e10cSrcweir // FontNameBox
581*cdf0e10cSrcweir // ===================================================================
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir struct ImplFontNameListData
584*cdf0e10cSrcweir {
585*cdf0e10cSrcweir     FontInfo    maInfo;
586*cdf0e10cSrcweir     sal_uInt16      mnType;
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir                 ImplFontNameListData( const FontInfo& rInfo,
589*cdf0e10cSrcweir                                     sal_uInt16 nType ) :
590*cdf0e10cSrcweir                     maInfo( rInfo ),
591*cdf0e10cSrcweir                     mnType( nType )
592*cdf0e10cSrcweir                 {}
593*cdf0e10cSrcweir };
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir DECLARE_LIST( ImplFontList, ImplFontNameListData* )
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir // -------------------------------------------------------------------
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir FontNameBox::FontNameBox( Window* pParent, WinBits nWinStyle ) :
600*cdf0e10cSrcweir     ComboBox( pParent, nWinStyle )
601*cdf0e10cSrcweir {
602*cdf0e10cSrcweir     InitBitmaps();
603*cdf0e10cSrcweir     mpFontList = NULL;
604*cdf0e10cSrcweir     mbWYSIWYG = sal_False;
605*cdf0e10cSrcweir     mbSymbols = sal_False;
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir // -------------------------------------------------------------------
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir FontNameBox::FontNameBox( Window* pParent, const ResId& rResId ) :
611*cdf0e10cSrcweir     ComboBox( pParent, rResId )
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir     InitBitmaps();
614*cdf0e10cSrcweir     mpFontList = NULL;
615*cdf0e10cSrcweir     mbWYSIWYG = sal_False;
616*cdf0e10cSrcweir     mbSymbols = sal_False;
617*cdf0e10cSrcweir }
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir // -------------------------------------------------------------------
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir FontNameBox::~FontNameBox()
622*cdf0e10cSrcweir {
623*cdf0e10cSrcweir     ImplDestroyFontList();
624*cdf0e10cSrcweir }
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir // -------------------------------------------------------------------
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir void FontNameBox::DataChanged( const DataChangedEvent& rDCEvt )
629*cdf0e10cSrcweir {
630*cdf0e10cSrcweir 	ComboBox::DataChanged( rDCEvt );
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 	if( rDCEvt.GetType() == DATACHANGED_SETTINGS && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
633*cdf0e10cSrcweir 		InitBitmaps();
634*cdf0e10cSrcweir }
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir // -------------------------------------------------------------------
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir void FontNameBox::InitBitmaps( void )
639*cdf0e10cSrcweir {
640*cdf0e10cSrcweir 	sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 	maImagePrinterFont = Image( SvtResId( bHC? RID_IMG_PRINTERFONT_HC : RID_IMG_PRINTERFONT ) );
643*cdf0e10cSrcweir 	maImageBitmapFont = Image( SvtResId( bHC? RID_IMG_BITMAPFONT_HC : RID_IMG_BITMAPFONT ) );
644*cdf0e10cSrcweir 	maImageScalableFont = Image( SvtResId( bHC? RID_IMG_SCALABLEFONT_HC : RID_IMG_SCALABLEFONT ) );
645*cdf0e10cSrcweir }
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir // -------------------------------------------------------------------
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir void FontNameBox::ImplDestroyFontList()
650*cdf0e10cSrcweir {
651*cdf0e10cSrcweir     if ( mpFontList )
652*cdf0e10cSrcweir     {
653*cdf0e10cSrcweir         ImplFontNameListData* pInfo = mpFontList->First();
654*cdf0e10cSrcweir         while ( pInfo )
655*cdf0e10cSrcweir         {
656*cdf0e10cSrcweir             delete pInfo;
657*cdf0e10cSrcweir             pInfo = mpFontList->Next();
658*cdf0e10cSrcweir         }
659*cdf0e10cSrcweir         delete mpFontList;
660*cdf0e10cSrcweir     }
661*cdf0e10cSrcweir }
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir // -------------------------------------------------------------------
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir void FontNameBox::Fill( const FontList* pList )
666*cdf0e10cSrcweir {
667*cdf0e10cSrcweir     // store old text and clear box
668*cdf0e10cSrcweir     XubString aOldText = GetText();
669*cdf0e10cSrcweir     Clear();
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir     ImplDestroyFontList();
672*cdf0e10cSrcweir     mpFontList = new ImplFontList;
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir     // insert fonts
675*cdf0e10cSrcweir     sal_uInt16 nFontCount = pList->GetFontNameCount();
676*cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < nFontCount; i++ )
677*cdf0e10cSrcweir     {
678*cdf0e10cSrcweir         const FontInfo& rFontInfo = pList->GetFontName( i );
679*cdf0e10cSrcweir         sal_uLong nIndex = InsertEntry( rFontInfo.GetName() );
680*cdf0e10cSrcweir         if ( nIndex != LISTBOX_ERROR )
681*cdf0e10cSrcweir         {
682*cdf0e10cSrcweir             sal_uInt16 nType = pList->GetFontNameType( i );
683*cdf0e10cSrcweir             ImplFontNameListData* pData = new ImplFontNameListData( rFontInfo, nType );
684*cdf0e10cSrcweir             mpFontList->Insert( pData, nIndex );
685*cdf0e10cSrcweir         }
686*cdf0e10cSrcweir     }
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir     ImplCalcUserItemSize();
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir     // restore text
691*cdf0e10cSrcweir     if ( aOldText.Len() )
692*cdf0e10cSrcweir         SetText( aOldText );
693*cdf0e10cSrcweir }
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir // -------------------------------------------------------------------
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir void FontNameBox::EnableWYSIWYG( sal_Bool bEnable )
698*cdf0e10cSrcweir {
699*cdf0e10cSrcweir     if ( bEnable != mbWYSIWYG )
700*cdf0e10cSrcweir     {
701*cdf0e10cSrcweir         mbWYSIWYG = bEnable;
702*cdf0e10cSrcweir         EnableUserDraw( mbWYSIWYG | mbSymbols );
703*cdf0e10cSrcweir         ImplCalcUserItemSize();
704*cdf0e10cSrcweir     }
705*cdf0e10cSrcweir }
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir // -------------------------------------------------------------------
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir void FontNameBox::EnableSymbols( sal_Bool bEnable )
710*cdf0e10cSrcweir {
711*cdf0e10cSrcweir     if ( bEnable != mbSymbols )
712*cdf0e10cSrcweir     {
713*cdf0e10cSrcweir         mbSymbols = bEnable;
714*cdf0e10cSrcweir         EnableUserDraw( mbWYSIWYG | mbSymbols );
715*cdf0e10cSrcweir         ImplCalcUserItemSize();
716*cdf0e10cSrcweir     }
717*cdf0e10cSrcweir }
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir // -------------------------------------------------------------------
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir void FontNameBox::ImplCalcUserItemSize()
722*cdf0e10cSrcweir {
723*cdf0e10cSrcweir     Size aUserItemSz;
724*cdf0e10cSrcweir     if ( mbWYSIWYG && mpFontList )
725*cdf0e10cSrcweir     {
726*cdf0e10cSrcweir         sal_uInt16 nMaxLen = 0;
727*cdf0e10cSrcweir         sal_Bool bSymbolFont = sal_False;
728*cdf0e10cSrcweir         sal_Bool bStarSymbol = sal_False;
729*cdf0e10cSrcweir         for ( sal_uInt16 n = GetEntryCount(); n; )
730*cdf0e10cSrcweir         {
731*cdf0e10cSrcweir             ImplFontNameListData* pData = mpFontList->GetObject( --n );
732*cdf0e10cSrcweir             XubString aFontName = pData->maInfo.GetName();
733*cdf0e10cSrcweir             if ( aFontName.Len() > nMaxLen )
734*cdf0e10cSrcweir                 nMaxLen = aFontName.Len();
735*cdf0e10cSrcweir             if ( pData->maInfo.GetCharSet() == RTL_TEXTENCODING_SYMBOL )
736*cdf0e10cSrcweir                 bSymbolFont = sal_True;
737*cdf0e10cSrcweir             // starsymbol is a unicode font, but gets WYSIWIG symbols
738*cdf0e10cSrcweir             if( aFontName.EqualsIgnoreCaseAscii( "starsymbol" )
739*cdf0e10cSrcweir             ||  aFontName.EqualsIgnoreCaseAscii( "opensymbol" ) )
740*cdf0e10cSrcweir                 bSymbolFont = bStarSymbol = sal_True;
741*cdf0e10cSrcweir         }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir         // guess maximimum width
744*cdf0e10cSrcweir         Size aOneCharSz( GetTextWidth( String( 'X' ) ), GetTextHeight() );
745*cdf0e10cSrcweir         Size aSz( aOneCharSz );
746*cdf0e10cSrcweir         aSz.Width() *= nMaxLen;
747*cdf0e10cSrcweir         // only XX% of width, because ListBox calculates the normal width...
748*cdf0e10cSrcweir         aSz.Width() *= 1;
749*cdf0e10cSrcweir         aSz.Width() /= 10;
750*cdf0e10cSrcweir         if ( bSymbolFont )
751*cdf0e10cSrcweir         {
752*cdf0e10cSrcweir             int nLength = sizeof(aImplSymbolFontText)/sizeof(aImplSymbolFontText[0]) - 1;
753*cdf0e10cSrcweir             int nLength2 = sizeof(aImplStarSymbolText)/sizeof(aImplStarSymbolText[0]) - 1;
754*cdf0e10cSrcweir             if( bStarSymbol && (nLength < nLength2) )
755*cdf0e10cSrcweir                 nLength = nLength2;
756*cdf0e10cSrcweir             aSz.Width() += aOneCharSz.Width() * nLength;
757*cdf0e10cSrcweir         }
758*cdf0e10cSrcweir         aSz.Height() *= 14;
759*cdf0e10cSrcweir         aSz.Height() /= 10;
760*cdf0e10cSrcweir         aUserItemSz = aSz;
761*cdf0e10cSrcweir     }
762*cdf0e10cSrcweir     if ( mbSymbols )
763*cdf0e10cSrcweir     {
764*cdf0e10cSrcweir         Size aSz = maImageScalableFont.GetSizePixel();
765*cdf0e10cSrcweir         aUserItemSz.Width() += aSz.Width() + IMGTEXTSPACE;
766*cdf0e10cSrcweir         if ( aSz.Height() > aUserItemSz.Height() )
767*cdf0e10cSrcweir             aUserItemSz.Height() = aSz.Height();
768*cdf0e10cSrcweir     }
769*cdf0e10cSrcweir     SetUserItemSize( aUserItemSz );
770*cdf0e10cSrcweir }
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir // -------------------------------------------------------------------
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir void FontNameBox::UserDraw( const UserDrawEvent& rUDEvt )
775*cdf0e10cSrcweir {
776*cdf0e10cSrcweir     ImplFontNameListData*   pData = mpFontList->GetObject( rUDEvt.GetItemId() );
777*cdf0e10cSrcweir     const FontInfo&         rInfo = pData->maInfo;
778*cdf0e10cSrcweir     sal_uInt16                  nType = pData->mnType;
779*cdf0e10cSrcweir     Point                   aTopLeft = rUDEvt.GetRect().TopLeft();
780*cdf0e10cSrcweir     long                    nX = aTopLeft.X();
781*cdf0e10cSrcweir     long                    nH = rUDEvt.GetRect().GetHeight();
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir     if ( mbSymbols )
784*cdf0e10cSrcweir     {
785*cdf0e10cSrcweir         nX += IMGTEXTSPACE;
786*cdf0e10cSrcweir         Image* pImg = NULL;
787*cdf0e10cSrcweir         if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_PRINTER )
788*cdf0e10cSrcweir             pImg = &maImagePrinterFont;
789*cdf0e10cSrcweir         else if ( nType & FONTLIST_FONTNAMETYPE_SCALABLE )
790*cdf0e10cSrcweir             pImg = &maImageScalableFont;
791*cdf0e10cSrcweir         else
792*cdf0e10cSrcweir             pImg = &maImageBitmapFont;
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir         if ( pImg )
795*cdf0e10cSrcweir         {
796*cdf0e10cSrcweir             Point aPos( nX, aTopLeft.Y() + (nH-pImg->GetSizePixel().Height())/2 );
797*cdf0e10cSrcweir             rUDEvt.GetDevice()->DrawImage( aPos, *pImg );
798*cdf0e10cSrcweir         }
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir         // X immer um gleiche Breite aendern, auch wenn kein Image ausgegeben.
801*cdf0e10cSrcweir         nX += maImagePrinterFont.GetSizePixel().Width();
802*cdf0e10cSrcweir     }
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir     if ( mbWYSIWYG && mpFontList )
805*cdf0e10cSrcweir     {
806*cdf0e10cSrcweir         nX += IMGTEXTSPACE;
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir         bool bSymbolFont = (rInfo.GetCharSet() == RTL_TEXTENCODING_SYMBOL);
809*cdf0e10cSrcweir         // starsymbol is a unicode font, but cannot display its own name
810*cdf0e10cSrcweir         const bool bOpenSymbol = rInfo.GetName().EqualsIgnoreCaseAscii( "starsymbol" )
811*cdf0e10cSrcweir                               || rInfo.GetName().EqualsIgnoreCaseAscii( "opensymbol" );
812*cdf0e10cSrcweir         bSymbolFont |= bOpenSymbol;
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir         if( bSymbolFont )
815*cdf0e10cSrcweir         {
816*cdf0e10cSrcweir             String aText( rInfo.GetName() );
817*cdf0e10cSrcweir             aText.AppendAscii( "  " );
818*cdf0e10cSrcweir             Point aPos( nX, aTopLeft.Y() + (nH-rUDEvt.GetDevice()->GetTextHeight())/2 );
819*cdf0e10cSrcweir             rUDEvt.GetDevice()->DrawText( aPos, aText );
820*cdf0e10cSrcweir             nX += rUDEvt.GetDevice()->GetTextWidth( aText );
821*cdf0e10cSrcweir         }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir         Color aTextColor = rUDEvt.GetDevice()->GetTextColor();
824*cdf0e10cSrcweir         Font aOldFont( rUDEvt.GetDevice()->GetFont() );
825*cdf0e10cSrcweir         Size aSize( aOldFont.GetSize() );
826*cdf0e10cSrcweir         aSize.Height() += EXTRAFONTSIZE;
827*cdf0e10cSrcweir         Font aFont( rInfo );
828*cdf0e10cSrcweir         aFont.SetSize( aSize );
829*cdf0e10cSrcweir         rUDEvt.GetDevice()->SetFont( aFont );
830*cdf0e10cSrcweir         rUDEvt.GetDevice()->SetTextColor( aTextColor );
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir         FontCharMap aFontCharMap;
833*cdf0e10cSrcweir         bool bHasCharMap = rUDEvt.GetDevice()->GetFontCharMap( aFontCharMap );
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir         String aString;
836*cdf0e10cSrcweir         if( !bSymbolFont )
837*cdf0e10cSrcweir         {
838*cdf0e10cSrcweir   	        // preview the font name
839*cdf0e10cSrcweir             aString = rInfo.GetName();
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir             // reset font if the name cannot be display in the preview font
842*cdf0e10cSrcweir             if( STRING_LEN != rUDEvt.GetDevice()->HasGlyphs( aFont, aString ) )
843*cdf0e10cSrcweir                 rUDEvt.GetDevice()->SetFont( aOldFont );
844*cdf0e10cSrcweir         }
845*cdf0e10cSrcweir         else if( bHasCharMap )
846*cdf0e10cSrcweir         {
847*cdf0e10cSrcweir             // use some sample characters available in the font
848*cdf0e10cSrcweir             sal_Unicode aText[8];
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir             // start just above the PUA used by most symbol fonts
851*cdf0e10cSrcweir             sal_uInt32 cNewChar = 0xFF00;
852*cdf0e10cSrcweir #ifdef QUARTZ
853*cdf0e10cSrcweir             // on MacOSX there are too many non-presentable symbols above the codepoint 0x0192
854*cdf0e10cSrcweir             if( !bOpenSymbol )
855*cdf0e10cSrcweir                 cNewChar = 0x0192;
856*cdf0e10cSrcweir #endif
857*cdf0e10cSrcweir             const int nMaxCount = sizeof(aText)/sizeof(*aText) - 1;
858*cdf0e10cSrcweir             int nSkip = aFontCharMap.GetCharCount() / nMaxCount;
859*cdf0e10cSrcweir             if( nSkip > 10 )
860*cdf0e10cSrcweir                 nSkip = 10;
861*cdf0e10cSrcweir             else if( nSkip <= 0 )
862*cdf0e10cSrcweir                 nSkip = 1;
863*cdf0e10cSrcweir             for( int i = 0; i < nMaxCount; ++i )
864*cdf0e10cSrcweir             {
865*cdf0e10cSrcweir                 sal_uInt32 cOldChar = cNewChar;
866*cdf0e10cSrcweir                 for( int j = nSkip; --j >= 0; )
867*cdf0e10cSrcweir                     cNewChar = aFontCharMap.GetPrevChar( cNewChar );
868*cdf0e10cSrcweir                 if( cOldChar == cNewChar )
869*cdf0e10cSrcweir                     break;
870*cdf0e10cSrcweir                 aText[ i ] = static_cast<sal_Unicode>(cNewChar); // TODO: support UCS4 samples
871*cdf0e10cSrcweir                 aText[ i+1 ] = 0;
872*cdf0e10cSrcweir             }
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir             aString = String( aText );
875*cdf0e10cSrcweir         }
876*cdf0e10cSrcweir         else
877*cdf0e10cSrcweir         {
878*cdf0e10cSrcweir             const sal_Unicode* pText = aImplSymbolFontText;
879*cdf0e10cSrcweir             if( bOpenSymbol )
880*cdf0e10cSrcweir                 pText = aImplStarSymbolText;
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir             aString = String( pText );
883*cdf0e10cSrcweir         }
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir         long nTextHeight = rUDEvt.GetDevice()->GetTextHeight();
886*cdf0e10cSrcweir         Point aPos( nX, aTopLeft.Y() + (nH-nTextHeight)/2 );
887*cdf0e10cSrcweir         rUDEvt.GetDevice()->DrawText( aPos, aString );
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir         rUDEvt.GetDevice()->SetFont( aOldFont );
890*cdf0e10cSrcweir         DrawEntry( rUDEvt, sal_False, sal_False);   // draw seperator
891*cdf0e10cSrcweir     }
892*cdf0e10cSrcweir     else
893*cdf0e10cSrcweir     {
894*cdf0e10cSrcweir         DrawEntry( rUDEvt, sal_True, sal_True );
895*cdf0e10cSrcweir     }
896*cdf0e10cSrcweir }
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir // ===================================================================
899*cdf0e10cSrcweir // FontStyleBox
900*cdf0e10cSrcweir // ===================================================================
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir FontStyleBox::FontStyleBox( Window* pParent, WinBits nWinStyle ) :
903*cdf0e10cSrcweir     ComboBox( pParent, nWinStyle )
904*cdf0e10cSrcweir {
905*cdf0e10cSrcweir }
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir // -------------------------------------------------------------------
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir FontStyleBox::FontStyleBox( Window* pParent, const ResId& rResId ) :
910*cdf0e10cSrcweir     ComboBox( pParent, rResId )
911*cdf0e10cSrcweir {
912*cdf0e10cSrcweir     aLastStyle = GetText();
913*cdf0e10cSrcweir }
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir // -------------------------------------------------------------------
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir FontStyleBox::~FontStyleBox()
918*cdf0e10cSrcweir {
919*cdf0e10cSrcweir }
920*cdf0e10cSrcweir 
921*cdf0e10cSrcweir // -------------------------------------------------------------------
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir void FontStyleBox::Select()
924*cdf0e10cSrcweir {
925*cdf0e10cSrcweir     // keep text over fill operation
926*cdf0e10cSrcweir     aLastStyle = GetText();
927*cdf0e10cSrcweir     ComboBox::Select();
928*cdf0e10cSrcweir }
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir // -------------------------------------------------------------------
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir void FontStyleBox::LoseFocus()
933*cdf0e10cSrcweir {
934*cdf0e10cSrcweir     // keep text over fill operation
935*cdf0e10cSrcweir     aLastStyle = GetText();
936*cdf0e10cSrcweir     ComboBox::LoseFocus();
937*cdf0e10cSrcweir }
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir // -------------------------------------------------------------------
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir void FontStyleBox::Modify()
942*cdf0e10cSrcweir {
943*cdf0e10cSrcweir     CharClass   aChrCls( ::comphelper::getProcessServiceFactory(),
944*cdf0e10cSrcweir                         GetSettings().GetLocale() );
945*cdf0e10cSrcweir     XubString   aStr = GetText();
946*cdf0e10cSrcweir     sal_uInt16      nEntryCount = GetEntryCount();
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir     if ( GetEntryPos( aStr ) == COMBOBOX_ENTRY_NOTFOUND )
949*cdf0e10cSrcweir     {
950*cdf0e10cSrcweir         aChrCls.toUpper( aStr );
951*cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < nEntryCount; i++ )
952*cdf0e10cSrcweir         {
953*cdf0e10cSrcweir             XubString aEntryText = GetEntry( i );
954*cdf0e10cSrcweir             aChrCls.toUpper( aEntryText );
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir             if ( aStr == aEntryText )
957*cdf0e10cSrcweir             {
958*cdf0e10cSrcweir                 SetText( GetEntry( i ) );
959*cdf0e10cSrcweir                 break;
960*cdf0e10cSrcweir             }
961*cdf0e10cSrcweir         }
962*cdf0e10cSrcweir     }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir     ComboBox::Modify();
965*cdf0e10cSrcweir }
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir // -------------------------------------------------------------------
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir void FontStyleBox::Fill( const XubString& rName, const FontList* pList )
970*cdf0e10cSrcweir {
971*cdf0e10cSrcweir     // note: this method must call ComboBox::SetText(),
972*cdf0e10cSrcweir     //   else aLastStyle will overwritten
973*cdf0e10cSrcweir     // store prior selection position and clear box
974*cdf0e10cSrcweir     XubString aOldText = GetText();
975*cdf0e10cSrcweir     sal_uInt16 nPos = GetEntryPos( aOldText );
976*cdf0e10cSrcweir     Clear();
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir     // does a font with this name already exist?
979*cdf0e10cSrcweir     sal_Handle hFontInfo = pList->GetFirstFontInfo( rName );
980*cdf0e10cSrcweir     if ( hFontInfo )
981*cdf0e10cSrcweir     {
982*cdf0e10cSrcweir         XubString   aStyleText;
983*cdf0e10cSrcweir         FontWeight  eLastWeight = WEIGHT_DONTKNOW;
984*cdf0e10cSrcweir         FontItalic  eLastItalic = ITALIC_NONE;
985*cdf0e10cSrcweir         FontWidth   eLastWidth = WIDTH_DONTKNOW;
986*cdf0e10cSrcweir         sal_Bool        bNormal = sal_False;
987*cdf0e10cSrcweir         sal_Bool        bItalic = sal_False;
988*cdf0e10cSrcweir         sal_Bool        bBold = sal_False;
989*cdf0e10cSrcweir         sal_Bool        bBoldItalic = sal_False;
990*cdf0e10cSrcweir         sal_Bool        bInsert = sal_False;
991*cdf0e10cSrcweir         FontInfo    aInfo;
992*cdf0e10cSrcweir         while ( hFontInfo )
993*cdf0e10cSrcweir         {
994*cdf0e10cSrcweir             aInfo = pList->GetFontInfo( hFontInfo );
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir             FontWeight  eWeight = aInfo.GetWeight();
997*cdf0e10cSrcweir             FontItalic  eItalic = aInfo.GetItalic();
998*cdf0e10cSrcweir             FontWidth   eWidth = aInfo.GetWidthType();
999*cdf0e10cSrcweir             // Only if the attributes are different, we insert the
1000*cdf0e10cSrcweir             // Font to avoid double Entries in different languages
1001*cdf0e10cSrcweir             if ( (eWeight != eLastWeight) || (eItalic != eLastItalic) ||
1002*cdf0e10cSrcweir                  (eWidth != eLastWidth) )
1003*cdf0e10cSrcweir             {
1004*cdf0e10cSrcweir                 if ( bInsert )
1005*cdf0e10cSrcweir                     InsertEntry( aStyleText );
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir                 if ( eWeight <= WEIGHT_NORMAL )
1008*cdf0e10cSrcweir                 {
1009*cdf0e10cSrcweir                     if ( eItalic != ITALIC_NONE )
1010*cdf0e10cSrcweir                         bItalic = sal_True;
1011*cdf0e10cSrcweir                     else
1012*cdf0e10cSrcweir                         bNormal = sal_True;
1013*cdf0e10cSrcweir                 }
1014*cdf0e10cSrcweir                 else
1015*cdf0e10cSrcweir                 {
1016*cdf0e10cSrcweir                     if ( eItalic != ITALIC_NONE )
1017*cdf0e10cSrcweir                         bBoldItalic = sal_True;
1018*cdf0e10cSrcweir                     else
1019*cdf0e10cSrcweir                         bBold = sal_True;
1020*cdf0e10cSrcweir                 }
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir                 // For wrong StyleNames we replace this with the correct once
1023*cdf0e10cSrcweir                 aStyleText = pList->GetStyleName( aInfo );
1024*cdf0e10cSrcweir                 bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
1025*cdf0e10cSrcweir                 if ( !bInsert )
1026*cdf0e10cSrcweir                 {
1027*cdf0e10cSrcweir                     aStyleText = pList->GetStyleName( eWeight, eItalic );
1028*cdf0e10cSrcweir                     bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
1029*cdf0e10cSrcweir                 }
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir                 eLastWeight = eWeight;
1032*cdf0e10cSrcweir                 eLastItalic = eItalic;
1033*cdf0e10cSrcweir                 eLastWidth = eWidth;
1034*cdf0e10cSrcweir             }
1035*cdf0e10cSrcweir             else
1036*cdf0e10cSrcweir             {
1037*cdf0e10cSrcweir                 if ( bInsert )
1038*cdf0e10cSrcweir                 {
1039*cdf0e10cSrcweir                     // If we have two names for the same attributes
1040*cdf0e10cSrcweir                     // we prefer the translated standard names
1041*cdf0e10cSrcweir                     const XubString& rAttrStyleText = pList->GetStyleName( eWeight, eItalic );
1042*cdf0e10cSrcweir                     if ( rAttrStyleText != aStyleText )
1043*cdf0e10cSrcweir                     {
1044*cdf0e10cSrcweir                         XubString aTempStyleText = pList->GetStyleName( aInfo );
1045*cdf0e10cSrcweir                         if ( rAttrStyleText == aTempStyleText )
1046*cdf0e10cSrcweir                             aStyleText = rAttrStyleText;
1047*cdf0e10cSrcweir                         bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
1048*cdf0e10cSrcweir                     }
1049*cdf0e10cSrcweir                 }
1050*cdf0e10cSrcweir             }
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir             if ( !bItalic && (aStyleText == pList->GetItalicStr()) )
1053*cdf0e10cSrcweir                 bItalic = sal_True;
1054*cdf0e10cSrcweir             else if ( !bBold && (aStyleText == pList->GetBoldStr()) )
1055*cdf0e10cSrcweir                 bBold = sal_True;
1056*cdf0e10cSrcweir             else if ( !bBoldItalic && (aStyleText == pList->GetBoldItalicStr()) )
1057*cdf0e10cSrcweir                 bBoldItalic = sal_True;
1058*cdf0e10cSrcweir 
1059*cdf0e10cSrcweir             hFontInfo = pList->GetNextFontInfo( hFontInfo );
1060*cdf0e10cSrcweir         }
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir         if ( bInsert )
1063*cdf0e10cSrcweir             InsertEntry( aStyleText );
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir         // Bestimmte Styles als Nachbildung
1066*cdf0e10cSrcweir         if ( bNormal )
1067*cdf0e10cSrcweir         {
1068*cdf0e10cSrcweir             if ( !bItalic )
1069*cdf0e10cSrcweir                 InsertEntry( pList->GetItalicStr() );
1070*cdf0e10cSrcweir             if ( !bBold )
1071*cdf0e10cSrcweir                 InsertEntry( pList->GetBoldStr() );
1072*cdf0e10cSrcweir         }
1073*cdf0e10cSrcweir         if ( !bBoldItalic )
1074*cdf0e10cSrcweir         {
1075*cdf0e10cSrcweir             if ( bNormal || bItalic || bBold )
1076*cdf0e10cSrcweir                 InsertEntry( pList->GetBoldItalicStr() );
1077*cdf0e10cSrcweir         }
1078*cdf0e10cSrcweir         if ( aOldText.Len() )
1079*cdf0e10cSrcweir         {
1080*cdf0e10cSrcweir             if ( GetEntryPos( aLastStyle ) != LISTBOX_ENTRY_NOTFOUND )
1081*cdf0e10cSrcweir                 ComboBox::SetText( aLastStyle );
1082*cdf0e10cSrcweir             else
1083*cdf0e10cSrcweir             {
1084*cdf0e10cSrcweir                 if ( nPos >= GetEntryCount() )
1085*cdf0e10cSrcweir                     ComboBox::SetText( GetEntry( 0 ) );
1086*cdf0e10cSrcweir                 else
1087*cdf0e10cSrcweir                     ComboBox::SetText( GetEntry( nPos ) );
1088*cdf0e10cSrcweir             }
1089*cdf0e10cSrcweir         }
1090*cdf0e10cSrcweir     }
1091*cdf0e10cSrcweir     else
1092*cdf0e10cSrcweir     {
1093*cdf0e10cSrcweir         // Wenn Font nicht, dann Standard-Styles einfuegen
1094*cdf0e10cSrcweir         InsertEntry( pList->GetNormalStr() );
1095*cdf0e10cSrcweir         InsertEntry( pList->GetItalicStr() );
1096*cdf0e10cSrcweir         InsertEntry( pList->GetBoldStr() );
1097*cdf0e10cSrcweir         InsertEntry( pList->GetBoldItalicStr() );
1098*cdf0e10cSrcweir         if ( aOldText.Len() )
1099*cdf0e10cSrcweir         {
1100*cdf0e10cSrcweir             if ( nPos > GetEntryCount() )
1101*cdf0e10cSrcweir                 ComboBox::SetText( GetEntry( 0 ) );
1102*cdf0e10cSrcweir             else
1103*cdf0e10cSrcweir                 ComboBox::SetText( GetEntry( nPos ) );
1104*cdf0e10cSrcweir         }
1105*cdf0e10cSrcweir     }
1106*cdf0e10cSrcweir }
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir // ===================================================================
1109*cdf0e10cSrcweir // FontSizeBox
1110*cdf0e10cSrcweir // ===================================================================
1111*cdf0e10cSrcweir 
1112*cdf0e10cSrcweir FontSizeBox::FontSizeBox( Window* pParent, WinBits nWinSize ) :
1113*cdf0e10cSrcweir     MetricBox( pParent, nWinSize )
1114*cdf0e10cSrcweir {
1115*cdf0e10cSrcweir     ImplInit();
1116*cdf0e10cSrcweir }
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir // -----------------------------------------------------------------------
1119*cdf0e10cSrcweir 
1120*cdf0e10cSrcweir FontSizeBox::FontSizeBox( Window* pParent, const ResId& rResId ) :
1121*cdf0e10cSrcweir     MetricBox( pParent, rResId )
1122*cdf0e10cSrcweir {
1123*cdf0e10cSrcweir     ImplInit();
1124*cdf0e10cSrcweir }
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir // -----------------------------------------------------------------------
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir FontSizeBox::~FontSizeBox()
1129*cdf0e10cSrcweir {
1130*cdf0e10cSrcweir }
1131*cdf0e10cSrcweir 
1132*cdf0e10cSrcweir // -----------------------------------------------------------------------
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir void FontSizeBox::ImplInit()
1135*cdf0e10cSrcweir {
1136*cdf0e10cSrcweir     EnableAutocomplete( sal_False );
1137*cdf0e10cSrcweir 
1138*cdf0e10cSrcweir     bRelativeMode   = sal_False;
1139*cdf0e10cSrcweir     bPtRelative     = sal_False;
1140*cdf0e10cSrcweir     bRelative       = sal_False;
1141*cdf0e10cSrcweir     bStdSize        = sal_False;
1142*cdf0e10cSrcweir     pFontList       = NULL;
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir     SetShowTrailingZeros( sal_False );
1145*cdf0e10cSrcweir     SetDecimalDigits( 1 );
1146*cdf0e10cSrcweir     SetMin( 20 );
1147*cdf0e10cSrcweir     SetMax( 9999 );
1148*cdf0e10cSrcweir     SetProminentEntryType( PROMINENT_MIDDLE );
1149*cdf0e10cSrcweir }
1150*cdf0e10cSrcweir 
1151*cdf0e10cSrcweir // -----------------------------------------------------------------------
1152*cdf0e10cSrcweir 
1153*cdf0e10cSrcweir void FontSizeBox::Reformat()
1154*cdf0e10cSrcweir {
1155*cdf0e10cSrcweir     FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
1156*cdf0e10cSrcweir     if ( !bRelativeMode || !aFontSizeNames.IsEmpty() )
1157*cdf0e10cSrcweir     {
1158*cdf0e10cSrcweir         long nNewValue = aFontSizeNames.Name2Size( GetText() );
1159*cdf0e10cSrcweir         if ( nNewValue)
1160*cdf0e10cSrcweir         {
1161*cdf0e10cSrcweir             mnLastValue = nNewValue;
1162*cdf0e10cSrcweir             return;
1163*cdf0e10cSrcweir         }
1164*cdf0e10cSrcweir     }
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir     MetricBox::Reformat();
1167*cdf0e10cSrcweir }
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir // -----------------------------------------------------------------------
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir void FontSizeBox::Modify()
1172*cdf0e10cSrcweir {
1173*cdf0e10cSrcweir     MetricBox::Modify();
1174*cdf0e10cSrcweir 
1175*cdf0e10cSrcweir     if ( bRelativeMode )
1176*cdf0e10cSrcweir     {
1177*cdf0e10cSrcweir         XubString aStr = GetText();
1178*cdf0e10cSrcweir         aStr.EraseLeadingChars();
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir         sal_Bool bNewMode = bRelative;
1181*cdf0e10cSrcweir         sal_Bool bOldPtRelMode = bPtRelative;
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir         if ( bRelative )
1184*cdf0e10cSrcweir         {
1185*cdf0e10cSrcweir             bPtRelative = sal_False;
1186*cdf0e10cSrcweir             const xub_Unicode* pStr = aStr.GetBuffer();
1187*cdf0e10cSrcweir             while ( *pStr )
1188*cdf0e10cSrcweir             {
1189*cdf0e10cSrcweir                 if ( ((*pStr < '0') || (*pStr > '9')) && (*pStr != '%') )
1190*cdf0e10cSrcweir                 {
1191*cdf0e10cSrcweir                     if ( ('-' == *pStr || '+' == *pStr) && !bPtRelative )
1192*cdf0e10cSrcweir                         bPtRelative = sal_True;
1193*cdf0e10cSrcweir                     else if ( bPtRelative && 'p' == *pStr && 't' == *++pStr )
1194*cdf0e10cSrcweir                         ;
1195*cdf0e10cSrcweir                     else
1196*cdf0e10cSrcweir                     {
1197*cdf0e10cSrcweir                         bNewMode = sal_False;
1198*cdf0e10cSrcweir                         break;
1199*cdf0e10cSrcweir                     }
1200*cdf0e10cSrcweir                 }
1201*cdf0e10cSrcweir                 pStr++;
1202*cdf0e10cSrcweir             }
1203*cdf0e10cSrcweir         }
1204*cdf0e10cSrcweir         else
1205*cdf0e10cSrcweir         {
1206*cdf0e10cSrcweir             if ( STRING_NOTFOUND != aStr.Search( '%' ) )
1207*cdf0e10cSrcweir             {
1208*cdf0e10cSrcweir                 bNewMode = sal_True;
1209*cdf0e10cSrcweir                 bPtRelative = sal_False;
1210*cdf0e10cSrcweir             }
1211*cdf0e10cSrcweir 
1212*cdf0e10cSrcweir             if ( '-' == aStr.GetChar( 0 ) || '+' == aStr.GetChar( 0 ) )
1213*cdf0e10cSrcweir             {
1214*cdf0e10cSrcweir                 bNewMode = sal_True;
1215*cdf0e10cSrcweir                 bPtRelative = sal_True;
1216*cdf0e10cSrcweir             }
1217*cdf0e10cSrcweir         }
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir         if ( bNewMode != bRelative || bPtRelative != bOldPtRelMode )
1220*cdf0e10cSrcweir             SetRelative( bNewMode );
1221*cdf0e10cSrcweir     }
1222*cdf0e10cSrcweir }
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir // -----------------------------------------------------------------------
1225*cdf0e10cSrcweir 
1226*cdf0e10cSrcweir void FontSizeBox::Fill( const FontInfo* pInfo, const FontList* pList )
1227*cdf0e10cSrcweir {
1228*cdf0e10cSrcweir     // remember for relative mode
1229*cdf0e10cSrcweir     pFontList = pList;
1230*cdf0e10cSrcweir 
1231*cdf0e10cSrcweir     // no font sizes need to be set for relative mode
1232*cdf0e10cSrcweir     if ( bRelative )
1233*cdf0e10cSrcweir         return;
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir     // query font sizes
1236*cdf0e10cSrcweir     const long* pTempAry;
1237*cdf0e10cSrcweir     const long* pAry = 0;
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir 	if( pInfo )
1240*cdf0e10cSrcweir 	{
1241*cdf0e10cSrcweir 		aFontInfo = *pInfo;
1242*cdf0e10cSrcweir 		pAry = pList->GetSizeAry( *pInfo );
1243*cdf0e10cSrcweir 	}
1244*cdf0e10cSrcweir 	else
1245*cdf0e10cSrcweir 	{
1246*cdf0e10cSrcweir 		pAry = pList->GetStdSizeAry();
1247*cdf0e10cSrcweir 	}
1248*cdf0e10cSrcweir 
1249*cdf0e10cSrcweir     // first insert font size names (for simplified/traditional chinese)
1250*cdf0e10cSrcweir     FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
1251*cdf0e10cSrcweir     if ( pAry == pList->GetStdSizeAry() )
1252*cdf0e10cSrcweir     {
1253*cdf0e10cSrcweir         // for standard sizes we don't need to bother
1254*cdf0e10cSrcweir         if ( bStdSize && GetEntryCount() && aFontSizeNames.IsEmpty() )
1255*cdf0e10cSrcweir             return;
1256*cdf0e10cSrcweir         bStdSize = sal_True;
1257*cdf0e10cSrcweir     }
1258*cdf0e10cSrcweir     else
1259*cdf0e10cSrcweir         bStdSize = sal_False;
1260*cdf0e10cSrcweir 
1261*cdf0e10cSrcweir     Selection aSelection = GetSelection();
1262*cdf0e10cSrcweir     XubString aStr = GetText();
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir     Clear();
1265*cdf0e10cSrcweir     sal_uInt16 nPos = 0;
1266*cdf0e10cSrcweir 
1267*cdf0e10cSrcweir     if ( !aFontSizeNames.IsEmpty() )
1268*cdf0e10cSrcweir     {
1269*cdf0e10cSrcweir         if ( pAry == pList->GetStdSizeAry() )
1270*cdf0e10cSrcweir         {
1271*cdf0e10cSrcweir             // for scalable fonts all font size names
1272*cdf0e10cSrcweir             sal_uLong nCount = aFontSizeNames.Count();
1273*cdf0e10cSrcweir             for( sal_uLong i = 0; i < nCount; i++ )
1274*cdf0e10cSrcweir             {
1275*cdf0e10cSrcweir                 String  aSizeName = aFontSizeNames.GetIndexName( i );
1276*cdf0e10cSrcweir                 long    nSize = aFontSizeNames.GetIndexSize( i );
1277*cdf0e10cSrcweir                 ComboBox::InsertEntry( aSizeName, nPos );
1278*cdf0e10cSrcweir                 ComboBox::SetEntryData( nPos, (void*)(-nSize) ); // mark as special
1279*cdf0e10cSrcweir                 nPos++;
1280*cdf0e10cSrcweir             }
1281*cdf0e10cSrcweir         }
1282*cdf0e10cSrcweir         else
1283*cdf0e10cSrcweir         {
1284*cdf0e10cSrcweir             // for fixed size fonts only selectable font size names
1285*cdf0e10cSrcweir             pTempAry = pAry;
1286*cdf0e10cSrcweir             while ( *pTempAry )
1287*cdf0e10cSrcweir             {
1288*cdf0e10cSrcweir                 String aSizeName = aFontSizeNames.Size2Name( *pTempAry );
1289*cdf0e10cSrcweir                 if ( aSizeName.Len() )
1290*cdf0e10cSrcweir                 {
1291*cdf0e10cSrcweir                     ComboBox::InsertEntry( aSizeName, nPos );
1292*cdf0e10cSrcweir                     ComboBox::SetEntryData( nPos, (void*)(-(*pTempAry)) ); // mark as special
1293*cdf0e10cSrcweir                     nPos++;
1294*cdf0e10cSrcweir                 }
1295*cdf0e10cSrcweir                 pTempAry++;
1296*cdf0e10cSrcweir             }
1297*cdf0e10cSrcweir         }
1298*cdf0e10cSrcweir     }
1299*cdf0e10cSrcweir 
1300*cdf0e10cSrcweir     // then insert numerical font size values
1301*cdf0e10cSrcweir     pTempAry = pAry;
1302*cdf0e10cSrcweir     while ( *pTempAry )
1303*cdf0e10cSrcweir     {
1304*cdf0e10cSrcweir         InsertValue( *pTempAry, FUNIT_NONE, nPos );
1305*cdf0e10cSrcweir         ComboBox::SetEntryData( nPos, (void*)(*pTempAry) );
1306*cdf0e10cSrcweir         nPos++;
1307*cdf0e10cSrcweir         pTempAry++;
1308*cdf0e10cSrcweir     }
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir     SetText( aStr );
1311*cdf0e10cSrcweir     SetSelection( aSelection );
1312*cdf0e10cSrcweir }
1313*cdf0e10cSrcweir 
1314*cdf0e10cSrcweir // -----------------------------------------------------------------------
1315*cdf0e10cSrcweir 
1316*cdf0e10cSrcweir void FontSizeBox::EnableRelativeMode( sal_uInt16 nMin, sal_uInt16 nMax, sal_uInt16 nStep )
1317*cdf0e10cSrcweir {
1318*cdf0e10cSrcweir     bRelativeMode = sal_True;
1319*cdf0e10cSrcweir     nRelMin       = nMin;
1320*cdf0e10cSrcweir     nRelMax       = nMax;
1321*cdf0e10cSrcweir     nRelStep      = nStep;
1322*cdf0e10cSrcweir     SetUnit( FUNIT_POINT );
1323*cdf0e10cSrcweir }
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir // -----------------------------------------------------------------------
1326*cdf0e10cSrcweir 
1327*cdf0e10cSrcweir void FontSizeBox::EnablePtRelativeMode( short nMin, short nMax, short nStep )
1328*cdf0e10cSrcweir {
1329*cdf0e10cSrcweir     bRelativeMode = sal_True;
1330*cdf0e10cSrcweir     nPtRelMin     = nMin;
1331*cdf0e10cSrcweir     nPtRelMax     = nMax;
1332*cdf0e10cSrcweir     nPtRelStep    = nStep;
1333*cdf0e10cSrcweir     SetUnit( FUNIT_POINT );
1334*cdf0e10cSrcweir }
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir // -----------------------------------------------------------------------
1337*cdf0e10cSrcweir 
1338*cdf0e10cSrcweir void FontSizeBox::SetRelative( sal_Bool bNewRelative )
1339*cdf0e10cSrcweir {
1340*cdf0e10cSrcweir     if ( bRelativeMode )
1341*cdf0e10cSrcweir     {
1342*cdf0e10cSrcweir         Selection aSelection = GetSelection();
1343*cdf0e10cSrcweir         XubString  aStr = GetText();
1344*cdf0e10cSrcweir         aStr.EraseLeadingChars();
1345*cdf0e10cSrcweir 
1346*cdf0e10cSrcweir         if ( bNewRelative )
1347*cdf0e10cSrcweir         {
1348*cdf0e10cSrcweir             bRelative = sal_True;
1349*cdf0e10cSrcweir             bStdSize = sal_False;
1350*cdf0e10cSrcweir 
1351*cdf0e10cSrcweir             if ( bPtRelative )
1352*cdf0e10cSrcweir             {
1353*cdf0e10cSrcweir                 SetDecimalDigits( 1 );
1354*cdf0e10cSrcweir                 SetMin( nPtRelMin );
1355*cdf0e10cSrcweir                 SetMax( nPtRelMax );
1356*cdf0e10cSrcweir                 SetUnit( FUNIT_POINT );
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir                 Clear();
1359*cdf0e10cSrcweir 
1360*cdf0e10cSrcweir                 short i = nPtRelMin, n = 0;
1361*cdf0e10cSrcweir                 // JP 30.06.98: more than 100 values are not useful
1362*cdf0e10cSrcweir                 while ( i <= nPtRelMax && n++ < 100 )
1363*cdf0e10cSrcweir                 {
1364*cdf0e10cSrcweir                     InsertValue( i );
1365*cdf0e10cSrcweir                     i = i + nPtRelStep;
1366*cdf0e10cSrcweir                 }
1367*cdf0e10cSrcweir             }
1368*cdf0e10cSrcweir             else
1369*cdf0e10cSrcweir             {
1370*cdf0e10cSrcweir                 SetDecimalDigits( 0 );
1371*cdf0e10cSrcweir                 SetMin( nRelMin );
1372*cdf0e10cSrcweir                 SetMax( nRelMax );
1373*cdf0e10cSrcweir                 SetCustomUnitText( '%' );
1374*cdf0e10cSrcweir                 SetUnit( FUNIT_CUSTOM );
1375*cdf0e10cSrcweir 
1376*cdf0e10cSrcweir                 Clear();
1377*cdf0e10cSrcweir                 sal_uInt16 i = nRelMin;
1378*cdf0e10cSrcweir                 while ( i <= nRelMax )
1379*cdf0e10cSrcweir                 {
1380*cdf0e10cSrcweir                     InsertValue( i );
1381*cdf0e10cSrcweir                     i = i + nRelStep;
1382*cdf0e10cSrcweir                 }
1383*cdf0e10cSrcweir             }
1384*cdf0e10cSrcweir         }
1385*cdf0e10cSrcweir         else
1386*cdf0e10cSrcweir         {
1387*cdf0e10cSrcweir             bRelative = bPtRelative = sal_False;
1388*cdf0e10cSrcweir             SetDecimalDigits( 1 );
1389*cdf0e10cSrcweir             SetMin( 20 );
1390*cdf0e10cSrcweir             SetMax( 9999 );
1391*cdf0e10cSrcweir             SetUnit( FUNIT_POINT );
1392*cdf0e10cSrcweir             if ( pFontList )
1393*cdf0e10cSrcweir                 Fill( &aFontInfo, pFontList );
1394*cdf0e10cSrcweir         }
1395*cdf0e10cSrcweir 
1396*cdf0e10cSrcweir         SetText( aStr );
1397*cdf0e10cSrcweir         SetSelection( aSelection );
1398*cdf0e10cSrcweir     }
1399*cdf0e10cSrcweir }
1400*cdf0e10cSrcweir 
1401*cdf0e10cSrcweir // -----------------------------------------------------------------------
1402*cdf0e10cSrcweir 
1403*cdf0e10cSrcweir XubString FontSizeBox::CreateFieldText( sal_Int64 nValue ) const
1404*cdf0e10cSrcweir {
1405*cdf0e10cSrcweir     XubString sRet( MetricBox::CreateFieldText( nValue ) );
1406*cdf0e10cSrcweir     if ( bRelativeMode && bPtRelative && (0 <= nValue) && sRet.Len() )
1407*cdf0e10cSrcweir         sRet.Insert( '+', 0 );
1408*cdf0e10cSrcweir     return sRet;
1409*cdf0e10cSrcweir }
1410*cdf0e10cSrcweir 
1411*cdf0e10cSrcweir // -----------------------------------------------------------------------
1412*cdf0e10cSrcweir 
1413*cdf0e10cSrcweir void FontSizeBox::SetValue( sal_Int64 nNewValue, FieldUnit eInUnit )
1414*cdf0e10cSrcweir {
1415*cdf0e10cSrcweir     if ( !bRelative )
1416*cdf0e10cSrcweir     {
1417*cdf0e10cSrcweir         sal_Int64 nTempValue = MetricField::ConvertValue( nNewValue, GetBaseValue(), GetDecimalDigits(), eInUnit, GetUnit() );
1418*cdf0e10cSrcweir         FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
1419*cdf0e10cSrcweir         // conversion loses precision; however font sizes should
1420*cdf0e10cSrcweir         // never have a problem with that
1421*cdf0e10cSrcweir         String aName = aFontSizeNames.Size2Name( static_cast<long>(nTempValue) );
1422*cdf0e10cSrcweir         if ( aName.Len() && (GetEntryPos( aName ) != LISTBOX_ENTRY_NOTFOUND) )
1423*cdf0e10cSrcweir         {
1424*cdf0e10cSrcweir             mnLastValue = nTempValue;
1425*cdf0e10cSrcweir             SetText( aName );
1426*cdf0e10cSrcweir             mnFieldValue = mnLastValue;
1427*cdf0e10cSrcweir             SetEmptyFieldValueData( sal_False );
1428*cdf0e10cSrcweir 			return;
1429*cdf0e10cSrcweir         }
1430*cdf0e10cSrcweir     }
1431*cdf0e10cSrcweir 
1432*cdf0e10cSrcweir     MetricBox::SetValue( nNewValue, eInUnit );
1433*cdf0e10cSrcweir }
1434*cdf0e10cSrcweir 
1435*cdf0e10cSrcweir // -----------------------------------------------------------------------
1436*cdf0e10cSrcweir 
1437*cdf0e10cSrcweir void FontSizeBox::SetValue( sal_Int64 nNewValue )
1438*cdf0e10cSrcweir {
1439*cdf0e10cSrcweir     SetValue( nNewValue, FUNIT_NONE );
1440*cdf0e10cSrcweir }
1441*cdf0e10cSrcweir 
1442*cdf0e10cSrcweir // -----------------------------------------------------------------------
1443*cdf0e10cSrcweir 
1444*cdf0e10cSrcweir sal_Int64 FontSizeBox::GetValue( sal_uInt16 nPos, FieldUnit eOutUnit ) const
1445*cdf0e10cSrcweir {
1446*cdf0e10cSrcweir     if ( !bRelative )
1447*cdf0e10cSrcweir     {
1448*cdf0e10cSrcweir         sal_Int64 nComboVal = static_cast<sal_Int64>(reinterpret_cast<long>(ComboBox::GetEntryData( nPos )));
1449*cdf0e10cSrcweir         if ( nComboVal < 0 )     // marked as special?
1450*cdf0e10cSrcweir         {
1451*cdf0e10cSrcweir             return MetricField::ConvertValue( -nComboVal, mnBaseValue, GetDecimalDigits(),
1452*cdf0e10cSrcweir                                               meUnit, eOutUnit );
1453*cdf0e10cSrcweir         }
1454*cdf0e10cSrcweir     }
1455*cdf0e10cSrcweir 
1456*cdf0e10cSrcweir     // do normal font size processing
1457*cdf0e10cSrcweir     sal_Int64 nRetValue = MetricBox::GetValue( nPos, eOutUnit );
1458*cdf0e10cSrcweir     return nRetValue;
1459*cdf0e10cSrcweir }
1460*cdf0e10cSrcweir 
1461*cdf0e10cSrcweir // -----------------------------------------------------------------------
1462*cdf0e10cSrcweir 
1463*cdf0e10cSrcweir sal_Int64 FontSizeBox::GetValue( FieldUnit eOutUnit ) const
1464*cdf0e10cSrcweir {
1465*cdf0e10cSrcweir     if ( !bRelative )
1466*cdf0e10cSrcweir     {
1467*cdf0e10cSrcweir         FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
1468*cdf0e10cSrcweir         sal_Int64 nValue = aFontSizeNames.Name2Size( GetText() );
1469*cdf0e10cSrcweir         if ( nValue)
1470*cdf0e10cSrcweir             return MetricField::ConvertValue( nValue, GetBaseValue(), GetDecimalDigits(), GetUnit(), eOutUnit );
1471*cdf0e10cSrcweir     }
1472*cdf0e10cSrcweir 
1473*cdf0e10cSrcweir     return MetricBox::GetValue( eOutUnit );
1474*cdf0e10cSrcweir }
1475*cdf0e10cSrcweir 
1476*cdf0e10cSrcweir // -----------------------------------------------------------------------
1477*cdf0e10cSrcweir 
1478*cdf0e10cSrcweir sal_Int64 FontSizeBox::GetValue() const
1479*cdf0e10cSrcweir {
1480*cdf0e10cSrcweir     // implementation not inline, because it is a virtual function
1481*cdf0e10cSrcweir     return GetValue( FUNIT_NONE );
1482*cdf0e10cSrcweir }
1483*cdf0e10cSrcweir 
1484*cdf0e10cSrcweir // -----------------------------------------------------------------------
1485*cdf0e10cSrcweir 
1486*cdf0e10cSrcweir void FontSizeBox::SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit )
1487*cdf0e10cSrcweir {
1488*cdf0e10cSrcweir     if ( !bRelative )
1489*cdf0e10cSrcweir     {
1490*cdf0e10cSrcweir         sal_Int64 nTempValue = MetricField::ConvertValue( nNewValue, GetBaseValue(), GetDecimalDigits(), eInUnit, GetUnit() );
1491*cdf0e10cSrcweir         FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
1492*cdf0e10cSrcweir         // conversion loses precision
1493*cdf0e10cSrcweir         // however font sizes should never have a problem with that
1494*cdf0e10cSrcweir         String aName = aFontSizeNames.Size2Name( static_cast<long>(nTempValue) );
1495*cdf0e10cSrcweir         if ( aName.Len() && (GetEntryPos( aName ) != LISTBOX_ENTRY_NOTFOUND) )
1496*cdf0e10cSrcweir         {
1497*cdf0e10cSrcweir             mnLastValue = nTempValue;
1498*cdf0e10cSrcweir             SetText( aName );
1499*cdf0e10cSrcweir             return;
1500*cdf0e10cSrcweir         }
1501*cdf0e10cSrcweir     }
1502*cdf0e10cSrcweir 
1503*cdf0e10cSrcweir     MetricBox::SetUserValue( nNewValue, eInUnit );
1504*cdf0e10cSrcweir }
1505*cdf0e10cSrcweir 
1506