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