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