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