1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include "svx/sidebar/ValueSetWithTextControl.hxx" 23 #include <svx/dialogs.hrc> 24 #include <svx/dialmgr.hxx> 25 #include <sfx2/sidebar/Theme.hxx> 26 27 #include <limits.h> 28 #include <com/sun/star/uno/Reference.h> 29 #include <com/sun/star/uno/Sequence.h> 30 #include <com/sun/star/lang/Locale.hpp> 31 #include <com/sun/star/style/NumberingType.hpp> 32 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 33 #include <com/sun/star/container/XIndexAccess.hpp> 34 #include <com/sun/star/text/XDefaultNumberingProvider.hpp> 35 #include <com/sun/star/text/XNumberingFormatter.hpp> 36 #include <com/sun/star/beans/PropertyValue.hpp> 37 #include <comphelper/processfactory.hxx> 38 #include <com/sun/star/text/XNumberingTypeInfo.hpp> 39 #include <i18npool/mslangid.hxx> 40 #include <svtools/valueset.hxx> 41 #include <editeng/brshitem.hxx> 42 #include <vcl/graph.hxx> 43 #include <svx/nbdtmg.hxx> 44 #include <svx/nbdtmgfact.hxx> 45 46 using namespace com::sun::star::uno; 47 using namespace com::sun::star::beans; 48 using namespace com::sun::star::lang; 49 using namespace com::sun::star::i18n; 50 using namespace com::sun::star::text; 51 using namespace com::sun::star::container; 52 using namespace com::sun::star::style; 53 using rtl::OUString; 54 55 #define C2U(cChar) OUString::createFromAscii(cChar) 56 57 namespace svx { namespace sidebar { 58 static const sal_Char cValue[] = "Value"; 59 60 static Font& lcl_GetDefaultBulletFont() 61 { 62 static sal_Bool bInit = 0; 63 static Font aDefBulletFont( UniString::CreateFromAscii( 64 RTL_CONSTASCII_STRINGPARAM( "StarSymbol" ) ), 65 String(), Size( 0, 14 ) ); 66 if(!bInit) 67 { 68 aDefBulletFont.SetCharSet( RTL_TEXTENCODING_SYMBOL ); 69 aDefBulletFont.SetFamily( FAMILY_DONTKNOW ); 70 aDefBulletFont.SetPitch( PITCH_DONTKNOW ); 71 aDefBulletFont.SetWeight( WEIGHT_DONTKNOW ); 72 aDefBulletFont.SetTransparent( sal_True ); 73 bInit = sal_True; 74 } 75 return aDefBulletFont; 76 } 77 78 ValueSetWithTextControl::ValueSetWithTextControl( 79 const tControlType eControlType, 80 Window* pParent, 81 const ResId& rResId) 82 : ValueSet( pParent, rResId ) 83 , meControlType( eControlType ) 84 , maItems() 85 { 86 SetColCount( 1 ); 87 } 88 89 ValueSetWithTextControl::~ValueSetWithTextControl(void) 90 { 91 } 92 93 void ValueSetWithTextControl::AddItem( 94 const Image& rItemImage, 95 const Image* pSelectedItemImage, 96 const XubString& rItemText, 97 const XubString* pItemHelpText ) 98 { 99 if ( meControlType != IMAGE_TEXT ) 100 { 101 return; 102 } 103 104 ValueSetWithTextItem aItem; 105 aItem.maItemImage = rItemImage; 106 aItem.maSelectedItemImage = (pSelectedItemImage != 0) 107 ? *pSelectedItemImage 108 : rItemImage; 109 aItem.maItemText = rItemText; 110 111 maItems.push_back( aItem ); 112 113 InsertItem( maItems.size() ); 114 SetItemText( maItems.size(), 115 (pItemHelpText != 0) ? *pItemHelpText : rItemText ); 116 } 117 118 119 void ValueSetWithTextControl::AddItem( 120 const XubString& rItemText, 121 const XubString& rItemText2, 122 const XubString* pItemHelpText ) 123 { 124 if ( meControlType != TEXT_TEXT ) 125 { 126 return; 127 } 128 129 ValueSetWithTextItem aItem; 130 aItem.maItemText = rItemText; 131 aItem.maItemText2 = rItemText2; 132 133 maItems.push_back( aItem ); 134 135 InsertItem( maItems.size() ); 136 SetItemText( maItems.size(), 137 (pItemHelpText != 0) ? *pItemHelpText : rItemText ); 138 } 139 140 141 void ValueSetWithTextControl::ReplaceItemImages( 142 const sal_uInt16 nItemId, 143 const Image& rItemImage, 144 const Image* pSelectedItemImage ) 145 { 146 if ( meControlType != IMAGE_TEXT ) 147 { 148 return; 149 } 150 151 if ( nItemId == 0 || 152 nItemId > maItems.size() ) 153 { 154 return; 155 } 156 157 maItems[nItemId-1].maItemImage = rItemImage; 158 maItems[nItemId-1].maSelectedItemImage = (pSelectedItemImage != 0) 159 ? *pSelectedItemImage 160 : rItemImage; 161 } 162 163 164 void ValueSetWithTextControl::UserDraw( const UserDrawEvent& rUDEvt ) 165 { 166 const Rectangle aRect = rUDEvt.GetRect(); 167 OutputDevice* pDev = rUDEvt.GetDevice(); 168 pDev->Push( PUSH_ALL ); 169 const sal_uInt16 nItemId = rUDEvt.GetItemId(); 170 171 const long nRectHeight = aRect.GetHeight(); 172 const Point aBLPos = aRect.TopLeft(); 173 174 Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 175 { 176 Size aSize = aFont.GetSize(); 177 aSize.Height() = (nRectHeight*4)/9; 178 aFont.SetSize( aSize ); 179 } 180 181 { 182 // draw background 183 if ( GetSelectItemId() == nItemId ) 184 { 185 Rectangle aBackRect = aRect; 186 aBackRect.Top() += 3; 187 aBackRect.Bottom() -= 2; 188 pDev->SetFillColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_Highlight ) ); 189 pDev->DrawRect(aBackRect); 190 } 191 else 192 { 193 pDev->SetFillColor( COL_TRANSPARENT ); 194 pDev->DrawRect(aRect); 195 } 196 197 // draw image + text resp. text + text 198 Image* pImage = 0; 199 if ( GetSelectItemId() == nItemId ) 200 { 201 aFont.SetColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_HighlightText ) ); 202 pImage = &maItems[nItemId-1].maSelectedItemImage; 203 } 204 else 205 { 206 aFont.SetColor( GetSettings().GetStyleSettings().GetFieldTextColor() ); 207 pImage = &maItems[nItemId-1].maItemImage; 208 } 209 210 Rectangle aStrRect = aRect; 211 aStrRect.Top() += nRectHeight/4; 212 aStrRect.Bottom() -= nRectHeight/4; 213 214 switch ( meControlType ) 215 { 216 case IMAGE_TEXT: 217 { 218 Point aImgStart( 219 aBLPos.X() + 4, 220 aBLPos.Y() + ( ( nRectHeight - pImage->GetSizePixel().Height() ) / 2 ) ); 221 pDev->DrawImage( aImgStart, *pImage ); 222 223 aStrRect.Left() += pImage->GetSizePixel().Width() + 12; 224 pDev->SetFont(aFont); 225 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS); 226 } 227 break; 228 case TEXT_TEXT: 229 { 230 const long nRectWidth = aRect.GetWidth(); 231 aStrRect.Left() += 8; 232 aStrRect.Right() -= (nRectWidth*2)/3; 233 pDev->SetFont(aFont); 234 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS); 235 aStrRect.Left() += nRectWidth/3; 236 aStrRect.Right() += (nRectWidth*2)/3; 237 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, TEXT_DRAW_ENDELLIPSIS); 238 } 239 break; 240 } 241 } 242 243 Invalidate( aRect ); 244 pDev->Pop(); 245 } 246 247 SvxNumValueSet2::SvxNumValueSet2( Window* pParent, const ResId& rResId) : 248 ValueSet( pParent, rResId ), 249 aLineColor ( COL_LIGHTGRAY ), 250 pVDev ( NULL ) 251 { 252 SetColCount( 3 ); 253 SetLineCount( 3 ); 254 SetStyle( GetStyle() | WB_ITEMBORDER ); 255 } 256 257 SvxNumValueSet2::~SvxNumValueSet2() 258 { 259 delete pVDev; 260 } 261 262 void SvxNumValueSet2::SetNumberingSettings( 263 const Sequence<Sequence<PropertyValue> >& aNum, 264 Reference<XNumberingFormatter>& xFormat, 265 const Locale& rLocale ) 266 { 267 aNumSettings = aNum; 268 xFormatter = xFormat; 269 aLocale = rLocale; 270 if(aNum.getLength() > 9) 271 SetStyle( GetStyle()|WB_VSCROLL); 272 InsertItem( DEFAULT_NONE, DEFAULT_NONE - 1 ); 273 SetItemText( DEFAULT_NONE, SVX_RESSTR( RID_SVXSTR_NUMBULLET_NONE )); 274 275 for ( sal_Int32 i = 0; i < aNum.getLength(); i++ ) 276 { 277 InsertItem( i + 1); 278 if( i < 8 ) 279 { 280 NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING); 281 if ( pNumbering ) 282 { 283 SetItemText( i + 1, pNumbering->GetDescription(i)); 284 } 285 } 286 } 287 } 288 289 void SvxNumValueSet2::UserDraw( const UserDrawEvent& rUDEvt ) 290 { 291 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 292 const Color aBackColor = rStyleSettings.GetFieldColor(); 293 const Color aTextColor = rStyleSettings.GetFieldTextColor(); 294 295 OutputDevice* pDev = rUDEvt.GetDevice(); 296 Rectangle aRect = rUDEvt.GetRect(); 297 sal_uInt32 nItemId = rUDEvt.GetItemId(); 298 long nRectWidth = aRect.GetWidth(); 299 long nRectHeight = aRect.GetHeight(); 300 Size aRectSize(nRectWidth, aRect.GetHeight()); 301 Point aBLPos = aRect.TopLeft(); 302 Font aOldFont = pDev->GetFont(); 303 Color aOldColor = pDev->GetLineColor(); 304 pDev->SetLineColor(aBackColor); 305 Font aFont(OutputDevice::GetDefaultFont( 306 DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 307 308 Size aSize = aFont.GetSize(); 309 aSize.Height() = nRectHeight/5; 310 aFont.SetColor(aTextColor); 311 aFont.SetFillColor(aBackColor); 312 aFont.SetSize( aSize ); 313 pDev->SetFont(aFont); 314 pDev->SetLineColor(aTextColor); 315 if(!pVDev) 316 { 317 // Die Linien werden nur einmalig in das VirtualDevice gepainted 318 // nur die Gliederungspage bekommt es aktuell 319 pVDev = new VirtualDevice(*pDev); 320 pVDev->SetMapMode(pDev->GetMapMode()); 321 pVDev->EnableRTL( IsRTLEnabled() ); 322 pVDev->SetOutputSize( aRectSize ); 323 aOrgRect = aRect; 324 325 pVDev->SetLineColor( aBackColor ); 326 pVDev->SetFillColor( aBackColor ); 327 pVDev->DrawRect(aOrgRect); 328 329 if(aBackColor == aLineColor) 330 aLineColor.Invert(); 331 if(GetSettings().GetStyleSettings().GetHighContrastMode()) 332 pVDev->SetLineColor(aTextColor); 333 else 334 pVDev->SetLineColor(aLineColor); 335 // Linien nur einmalig Zeichnen 336 Point aStart(aBLPos.X() + nRectWidth *30 / 100,0); 337 Point aEnd(aBLPos.X() + nRectWidth * 9 / 10,0); 338 for( sal_uInt32 i = 11; i < 100; i += 33) 339 { 340 aStart.Y() = aEnd.Y() = aBLPos.Y() + nRectHeight * i / 100; 341 pVDev->DrawLine(aStart, aEnd); 342 aStart.Y() = aEnd.Y() = aBLPos.Y() + nRectHeight * (i + 11) / 100; 343 pVDev->DrawLine(aStart, aEnd); 344 } 345 } 346 if ( nItemId != DEFAULT_NONE) 347 pDev->DrawOutDev( aRect.TopLeft(), aRectSize, 348 aOrgRect.TopLeft(), aRectSize, 349 *pVDev ); 350 const OUString sValue(C2U(cValue)); 351 352 Point aStart(aBLPos.X() + nRectWidth / 9,0); 353 if ( nItemId == DEFAULT_NONE) 354 { 355 String sText(SVX_RESSTR( RID_SVXSTR_NUMBULLET_NONE)); 356 Font aFont = pDev->GetFont(); 357 Size aSize = aFont.GetSize(); 358 aSize.Height() = nRectHeight/4; 359 aFont.SetSize( aSize ); 360 pDev->SetFont(aFont); 361 long nTextWidth = pDev->GetTextWidth(sText); 362 long nTextHeight = pDev->GetTextHeight(); 363 //GVT refine 364 while (nTextWidth>nRectWidth && aSize.Height()>4) { 365 aSize.Height() = aSize.Height()*0.9; 366 aFont.SetSize( aSize ); 367 pDev->SetFont(aFont); 368 nTextWidth = pDev->GetTextWidth(sText); 369 } 370 Point aSStart(aBLPos.X()+(nRectWidth-nTextWidth)/2, aBLPos.Y() +(nRectHeight-nTextHeight)/2); 371 pDev->DrawText(aSStart, sText); 372 pDev->SetFont(aOldFont); 373 } 374 else 375 { 376 NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING); 377 if ( pNumbering && nItemId <= DEFAULT_BULLET_TYPES ) 378 { 379 for( sal_uInt32 i = 0; i < 3; i++ ) 380 { 381 sal_uInt32 nY = 11 + i * 33; 382 aStart.Y() = aBLPos.Y() + nRectHeight * nY / 100; 383 String sText; 384 sal_uInt16 nLvl = 0; 385 SvxNumRule aTempRule( 0, 10, false ); 386 pNumbering->ApplyNumRule(aTempRule,nItemId -1,1<<nLvl); 387 SvxNumberFormat aNumFmt(aTempRule.GetLevel(nLvl)); 388 sText=aNumFmt.GetNumStr(i+1); 389 sText.Insert( aNumFmt.GetPrefix(), 0 ); 390 sText += aNumFmt.GetSuffix(); 391 aStart.X() = aBLPos.X() + 2; 392 aStart.Y() -= pDev->GetTextHeight()/2; 393 pDev->DrawText(aStart, sText); 394 } 395 } 396 pDev->SetFont(aOldFont); 397 pDev->SetLineColor(aOldColor); 398 } 399 //End 400 } 401 402 //=============================================================================================== 403 404 SvxNumValueSet3::SvxNumValueSet3( Window* pParent, const ResId& rResId) : 405 ValueSet( pParent, rResId ) 406 { 407 SetColCount( 3 ); 408 SetLineCount( 4 ); 409 SetStyle( GetStyle() | WB_ITEMBORDER ); 410 } 411 412 SvxNumValueSet3::~SvxNumValueSet3() 413 { 414 } 415 416 void SvxNumValueSet3::UserDraw( const UserDrawEvent& rUDEvt ) 417 { 418 Rectangle aRect = rUDEvt.GetRect(); 419 OutputDevice* pDev = rUDEvt.GetDevice(); 420 sal_uInt32 nItemId = rUDEvt.GetItemId(); 421 422 long nRectHeight = aRect.GetHeight(); 423 long nRectWidth = aRect.GetWidth(); 424 Point aBLPos = aRect.TopLeft(); 425 NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS); 426 if ( pBullets ) 427 { 428 if ( nItemId <= DEFAULT_BULLET_TYPES ) { 429 sal_uInt16 nLvl = 0; 430 SvxNumRule aTempRule( 0, 10, false ); 431 pBullets->ApplyNumRule(aTempRule,nItemId -1,1<<nLvl); 432 SvxNumberFormat aFmt(aTempRule.GetLevel(nLvl)); 433 sal_Int16 eNumType = aFmt.GetNumberingType(); 434 if( eNumType == SVX_NUM_CHAR_SPECIAL) 435 { 436 sal_Unicode cChar = aFmt.GetBulletChar(); 437 //End 438 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 439 const Color aBackColor = rStyleSettings.GetFieldColor(); 440 const Color aTextColor = rStyleSettings.GetFieldTextColor(); 441 442 Font aOldFont = pDev->GetFont(); 443 Font aFont( lcl_GetDefaultBulletFont() ); 444 445 Size aSize = aFont.GetSize(); 446 aSize.Height() = nRectHeight*3/6; 447 aFont.SetColor(aTextColor); 448 aFont.SetFillColor(aBackColor); 449 aFont.SetSize( aSize ); 450 pDev->SetFont(aFont); 451 pDev->SetFillColor( aBackColor ); //wj 452 453 String sText; 454 sText = cChar; 455 Font aOldBulletFont = pDev->GetFont(); 456 Font aBulletFnt(aFmt.GetBulletFont() ? *aFmt.GetBulletFont() : aOldBulletFont); 457 Size aBulSize = aOldBulletFont.GetSize(); 458 aBulletFnt.SetSize(aBulSize); 459 pDev->SetFont(aBulletFnt); 460 long nTextWidth = pDev->GetTextWidth(sText); 461 long nTextHeight = pDev->GetTextHeight(); 462 Point aStart(aBLPos.X()+(nRectWidth-nTextWidth)/2, aBLPos.Y() +(nRectHeight-nTextHeight)/2); 463 pDev->DrawText(aStart, sText); 464 pDev->SetFont(aOldFont); 465 }else if ( eNumType == SVX_NUM_BITMAP ) 466 { 467 const SvxBrushItem* pBrushItem = aFmt.GetBrush(); 468 if(pBrushItem) 469 { 470 const Graphic* pGrf = pBrushItem->GetGraphic(); 471 if(pGrf) 472 { 473 Size aSize(nRectHeight*6/20, nRectHeight*6/20); 474 Point aStart(aBLPos.X() + nRectWidth*7/20, aBLPos.Y() + nRectHeight*7/20); 475 476 pGrf->Draw( pDev, aStart, aSize ); 477 } 478 } 479 } 480 }else if ( nItemId == DEFAULT_NONE) 481 { 482 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 483 const Color aBackColor = rStyleSettings.GetFieldColor(); 484 const Color aTextColor = rStyleSettings.GetFieldTextColor(); 485 486 Font aOldFont = pDev->GetFont(); 487 Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 488 Size aSize = aFont.GetSize(); 489 //aSize.Height() = nRectHeight/5; 490 aSize.Height() = nRectHeight/4; 491 aFont.SetColor(aTextColor); 492 aFont.SetFillColor(aBackColor); 493 aFont.SetSize( aSize ); 494 pDev->SetFont(aFont); 495 pDev->SetFillColor( aBackColor ); 496 497 String sText(SVX_RESSTR( RID_SVXSTR_NUMBULLET_NONE)); 498 499 long nTextWidth = pDev->GetTextWidth(sText); 500 long nTextHeight = pDev->GetTextHeight(); 501 //GVT refine 502 while (nTextWidth>nRectWidth && aSize.Height()>4) { 503 aSize.Height() = aSize.Height()*0.9; 504 aFont.SetSize( aSize ); 505 pDev->SetFont(aFont); 506 nTextWidth = pDev->GetTextWidth(sText); 507 } 508 Point aStart(aBLPos.X()+(nRectWidth-nTextWidth)/2, aBLPos.Y() +(nRectHeight-nTextHeight)/2); 509 pDev->DrawText(aStart, sText); 510 511 pDev->SetFont(aOldFont); 512 } 513 } 514 515 } 516 517 } } // end of namespace svx::sidebar 518 519 /* vim: set noet sw=4 ts=4: */ 520