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