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 90 ValueSetWithTextControl::~ValueSetWithTextControl(void) 91 { 92 } 93 94 95 void ValueSetWithTextControl::AddItem( 96 const Image& rItemImage, 97 const Image* pSelectedItemImage, 98 const XubString& rItemText, 99 const XubString* pItemHelpText ) 100 { 101 if ( meControlType != IMAGE_TEXT ) 102 { 103 return; 104 } 105 106 ValueSetWithTextItem aItem; 107 aItem.maItemImage = rItemImage; 108 aItem.maSelectedItemImage = (pSelectedItemImage != 0) 109 ? *pSelectedItemImage 110 : rItemImage; 111 aItem.maItemText = rItemText; 112 113 maItems.push_back( aItem ); 114 115 InsertItem( maItems.size() ); 116 SetItemText( maItems.size(), 117 (pItemHelpText != 0) ? *pItemHelpText : rItemText ); 118 } 119 120 121 void ValueSetWithTextControl::AddItem( 122 const XubString& rItemText, 123 const XubString& rItemText2, 124 const XubString* pItemHelpText ) 125 { 126 if ( meControlType != TEXT_TEXT ) 127 { 128 return; 129 } 130 131 ValueSetWithTextItem aItem; 132 aItem.maItemText = rItemText; 133 aItem.maItemText2 = rItemText2; 134 135 maItems.push_back( aItem ); 136 137 InsertItem( maItems.size() ); 138 SetItemText( maItems.size(), 139 (pItemHelpText != 0) ? *pItemHelpText : rItemText ); 140 } 141 142 143 void ValueSetWithTextControl::ReplaceItemImages( 144 const sal_uInt16 nItemId, 145 const Image& rItemImage, 146 const Image* pSelectedItemImage ) 147 { 148 if ( meControlType != IMAGE_TEXT ) 149 { 150 return; 151 } 152 153 if ( nItemId == 0 || 154 nItemId > maItems.size() ) 155 { 156 return; 157 } 158 159 maItems[nItemId-1].maItemImage = rItemImage; 160 maItems[nItemId-1].maSelectedItemImage = (pSelectedItemImage != 0) 161 ? *pSelectedItemImage 162 : rItemImage; 163 } 164 165 166 void ValueSetWithTextControl::UserDraw( const UserDrawEvent& rUDEvt ) 167 { 168 const Rectangle aRect = rUDEvt.GetRect(); 169 OutputDevice* pDev = rUDEvt.GetDevice(); 170 pDev->Push( PUSH_ALL ); 171 const sal_uInt16 nItemId = rUDEvt.GetItemId(); 172 173 const long nRectHeight = aRect.GetHeight(); 174 const Point aBLPos = aRect.TopLeft(); 175 176 Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 177 { 178 Size aSize = aFont.GetSize(); 179 aSize.Height() = (nRectHeight*4)/9; 180 aFont.SetSize( aSize ); 181 } 182 183 { 184 //draw backgroud 185 if ( GetSelectItemId() == nItemId ) 186 { 187 Rectangle aBackRect = aRect; 188 aBackRect.Top() += 3; 189 aBackRect.Bottom() -= 2; 190 pDev->SetFillColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_Highlight ) ); 191 pDev->DrawRect(aBackRect); 192 } 193 else 194 { 195 pDev->SetFillColor( COL_TRANSPARENT ); 196 pDev->DrawRect(aRect); 197 } 198 199 //draw image + text resp. text + text 200 Image* pImage = 0; 201 if ( GetSelectItemId() == nItemId ) 202 { 203 aFont.SetColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_HighlightText ) ); 204 pImage = &maItems[nItemId-1].maSelectedItemImage; 205 } 206 else 207 { 208 aFont.SetColor( GetSettings().GetStyleSettings().GetFieldTextColor() ); 209 pImage = &maItems[nItemId-1].maItemImage; 210 } 211 212 Rectangle aStrRect = aRect; 213 aStrRect.Top() += nRectHeight/4; 214 aStrRect.Bottom() -= nRectHeight/4; 215 216 switch ( meControlType ) 217 { 218 case IMAGE_TEXT: 219 { 220 Point aImgStart( 221 aBLPos.X() + 4, 222 aBLPos.Y() + ( ( nRectHeight - pImage->GetSizePixel().Height() ) / 2 ) ); 223 pDev->DrawImage( aImgStart, *pImage ); 224 225 aStrRect.Left() += pImage->GetSizePixel().Width() + 12; 226 pDev->SetFont(aFont); 227 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS); 228 } 229 break; 230 case TEXT_TEXT: 231 { 232 const long nRectWidth = aRect.GetWidth(); 233 aStrRect.Left() += 8; 234 aStrRect.Right() -= (nRectWidth*2)/3; 235 pDev->SetFont(aFont); 236 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS); 237 aStrRect.Left() += nRectWidth/3; 238 aStrRect.Right() += (nRectWidth*2)/3; 239 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, TEXT_DRAW_ENDELLIPSIS); 240 } 241 break; 242 } 243 } 244 245 Invalidate( aRect ); 246 pDev->Pop(); 247 } 248 249 SvxNumValueSet2::SvxNumValueSet2( Window* pParent, const ResId& rResId) : 250 ValueSet( pParent, rResId ), 251 aLineColor ( COL_LIGHTGRAY ), 252 pVDev ( NULL ) 253 { 254 SetColCount( 3 ); 255 SetLineCount( 3 ); 256 SetStyle( GetStyle() | WB_ITEMBORDER ); 257 } 258 259 SvxNumValueSet2::~SvxNumValueSet2() 260 { 261 delete pVDev; 262 } 263 264 void SvxNumValueSet2::SetNumberingSettings( 265 const Sequence<Sequence<PropertyValue> >& aNum, 266 Reference<XNumberingFormatter>& xFormat, 267 const Locale& rLocale ) 268 { 269 aNumSettings = aNum; 270 xFormatter = xFormat; 271 aLocale = rLocale; 272 if(aNum.getLength() > 9) 273 SetStyle( GetStyle()|WB_VSCROLL); 274 InsertItem( DEFAULT_NONE, DEFAULT_NONE - 1 ); 275 SetItemText( DEFAULT_NONE, SVX_RESSTR( RID_SVXSTR_NUMBULLET_NONE )); 276 277 for ( sal_uInt32 i = 0; i < aNum.getLength(); i++ ) 278 { 279 InsertItem( i + 1); 280 if( i < 8 ) 281 { 282 NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING); 283 if ( pNumbering ) 284 { 285 SetItemText( i + 1, pNumbering->GetDescription(i)); 286 } 287 } 288 } 289 } 290 291 void SvxNumValueSet2::UserDraw( const UserDrawEvent& rUDEvt ) 292 { 293 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 294 const Color aBackColor = rStyleSettings.GetFieldColor(); 295 const Color aTextColor = rStyleSettings.GetFieldTextColor(); 296 297 OutputDevice* pDev = rUDEvt.GetDevice(); 298 Rectangle aRect = rUDEvt.GetRect(); 299 sal_uInt32 nItemId = rUDEvt.GetItemId(); 300 long nRectWidth = aRect.GetWidth(); 301 long nRectHeight = aRect.GetHeight(); 302 Size aRectSize(nRectWidth, aRect.GetHeight()); 303 Point aBLPos = aRect.TopLeft(); 304 Font aOldFont = pDev->GetFont(); 305 Color aOldColor = pDev->GetLineColor(); 306 pDev->SetLineColor(aBackColor); 307 Font aFont(OutputDevice::GetDefaultFont( 308 DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 309 310 Size aSize = aFont.GetSize(); 311 aSize.Height() = nRectHeight/5; 312 aFont.SetColor(aTextColor); 313 aFont.SetFillColor(aBackColor); 314 aFont.SetSize( aSize ); 315 pDev->SetFont(aFont); 316 pDev->SetLineColor(aTextColor); 317 if(!pVDev) 318 { 319 // Die Linien werden nur einmalig in das VirtualDevice gepainted 320 // nur die Gliederungspage bekommt es aktuell 321 pVDev = new VirtualDevice(*pDev); 322 pVDev->SetMapMode(pDev->GetMapMode()); 323 pVDev->EnableRTL( IsRTLEnabled() ); 324 pVDev->SetOutputSize( aRectSize ); 325 aOrgRect = aRect; 326 327 pVDev->SetLineColor( aBackColor ); 328 pVDev->SetFillColor( aBackColor ); 329 pVDev->DrawRect(aOrgRect); 330 331 if(aBackColor == aLineColor) 332 aLineColor.Invert(); 333 if(GetSettings().GetStyleSettings().GetHighContrastMode()) 334 pVDev->SetLineColor(aTextColor); 335 else 336 pVDev->SetLineColor(aLineColor); 337 // Linien nur einmalig Zeichnen 338 Point aStart(aBLPos.X() + nRectWidth *30 / 100,0); 339 Point aEnd(aBLPos.X() + nRectWidth * 9 / 10,0); 340 for( sal_uInt32 i = 11; i < 100; i += 33) 341 { 342 aStart.Y() = aEnd.Y() = aBLPos.Y() + nRectHeight * i / 100; 343 pVDev->DrawLine(aStart, aEnd); 344 aStart.Y() = aEnd.Y() = aBLPos.Y() + nRectHeight * (i + 11) / 100; 345 pVDev->DrawLine(aStart, aEnd); 346 } 347 } 348 if ( nItemId != DEFAULT_NONE) 349 pDev->DrawOutDev( aRect.TopLeft(), aRectSize, 350 aOrgRect.TopLeft(), aRectSize, 351 *pVDev ); 352 const OUString sValue(C2U(cValue)); 353 354 Point aStart(aBLPos.X() + nRectWidth / 9,0); 355 if ( nItemId == DEFAULT_NONE) 356 { 357 String sText(SVX_RESSTR( RID_SVXSTR_NUMBULLET_NONE)); 358 Font aFont = pDev->GetFont(); 359 Size aSize = aFont.GetSize(); 360 aSize.Height() = nRectHeight/4; 361 aFont.SetSize( aSize ); 362 pDev->SetFont(aFont); 363 long nTextWidth = pDev->GetTextWidth(sText); 364 long nTextHeight = pDev->GetTextHeight(); 365 //GVT refine 366 while (nTextWidth>nRectWidth && aSize.Height()>4) { 367 aSize.Height() = aSize.Height()*0.9; 368 aFont.SetSize( aSize ); 369 pDev->SetFont(aFont); 370 nTextWidth = pDev->GetTextWidth(sText); 371 } 372 Point aSStart(aBLPos.X()+(nRectWidth-nTextWidth)/2, aBLPos.Y() +(nRectHeight-nTextHeight)/2); 373 pDev->DrawText(aSStart, sText); 374 pDev->SetFont(aOldFont); 375 } 376 else 377 { 378 NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING); 379 if ( pNumbering && nItemId <= DEFAULT_BULLET_TYPES ) 380 { 381 for( sal_uInt32 i = 0; i < 3; i++ ) 382 { 383 sal_uInt32 nY = 11 + i * 33; 384 aStart.Y() = aBLPos.Y() + nRectHeight * nY / 100; 385 String sText; 386 sal_uInt16 nLvl = 0; 387 SvxNumRule aTempRule( 0, 10, false ); 388 pNumbering->ApplyNumRule(aTempRule,nItemId -1,1<<nLvl); 389 SvxNumberFormat aNumFmt(aTempRule.GetLevel(nLvl)); 390 sText=aNumFmt.GetNumStr(i+1); 391 sText.Insert( aNumFmt.GetPrefix(), 0 ); 392 sText += aNumFmt.GetSuffix(); 393 aStart.X() = aBLPos.X() + 2; 394 aStart.Y() -= pDev->GetTextHeight()/2; 395 pDev->DrawText(aStart, sText); 396 } 397 } 398 pDev->SetFont(aOldFont); 399 pDev->SetLineColor(aOldColor); 400 } 401 //End 402 } 403 404 //=============================================================================================== 405 406 static const long aOffsetX[] = 407 { 408 -1,//1, 409 3,//4, 410 4,//5, 411 -3,//0, 412 -1,//0, 413 3 414 }; 415 416 SvxNumValueSet3::SvxNumValueSet3( Window* pParent, const ResId& rResId) : 417 ValueSet( pParent, rResId ) 418 { 419 SetColCount( 3 ); 420 SetLineCount( 4 ); 421 SetStyle( GetStyle() | WB_ITEMBORDER ); 422 } 423 424 SvxNumValueSet3::~SvxNumValueSet3() 425 { 426 } 427 428 void SvxNumValueSet3::UserDraw( const UserDrawEvent& rUDEvt ) 429 { 430 Rectangle aRect = rUDEvt.GetRect(); 431 OutputDevice* pDev = rUDEvt.GetDevice(); 432 sal_uInt32 nItemId = rUDEvt.GetItemId(); 433 434 long nRectHeight = aRect.GetHeight(); 435 long nRectWidth = aRect.GetWidth(); 436 Point aBLPos = aRect.TopLeft(); 437 NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS); 438 if ( pBullets ) 439 { 440 if ( nItemId <= DEFAULT_BULLET_TYPES ) { 441 sal_uInt16 nLvl = 0; 442 SvxNumRule aTempRule( 0, 10, false ); 443 pBullets->ApplyNumRule(aTempRule,nItemId -1,1<<nLvl); 444 SvxNumberFormat aFmt(aTempRule.GetLevel(nLvl)); 445 sal_Int16 eNumType = aFmt.GetNumberingType(); 446 if( eNumType == SVX_NUM_CHAR_SPECIAL) 447 { 448 sal_Unicode cChar = aFmt.GetBulletChar(); 449 //End 450 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 451 const Color aBackColor = rStyleSettings.GetFieldColor(); 452 const Color aTextColor = rStyleSettings.GetFieldTextColor(); 453 454 Font aOldFont = pDev->GetFont(); 455 Font aFont( lcl_GetDefaultBulletFont() ); 456 457 Size aSize = aFont.GetSize(); 458 aSize.Height() = nRectHeight*3/6; 459 aFont.SetColor(aTextColor); 460 aFont.SetFillColor(aBackColor); 461 aFont.SetSize( aSize ); 462 pDev->SetFont(aFont); 463 pDev->SetFillColor( aBackColor ); //wj 464 465 String sText; 466 sText = cChar; 467 Font aOldBulletFont = pDev->GetFont(); 468 Font aBulletFnt(aFmt.GetBulletFont() ? *aFmt.GetBulletFont() : aOldBulletFont); 469 Size aBulSize = aOldBulletFont.GetSize(); 470 aBulletFnt.SetSize(aBulSize); 471 pDev->SetFont(aBulletFnt); 472 long nTextWidth = pDev->GetTextWidth(sText); 473 long nTextHeight = pDev->GetTextHeight(); 474 Point aStart(aBLPos.X()+(nRectWidth-nTextWidth)/2, aBLPos.Y() +(nRectHeight-nTextHeight)/2); 475 pDev->DrawText(aStart, sText); 476 pDev->SetFont(aOldFont); 477 }else if ( eNumType == SVX_NUM_BITMAP ) 478 { 479 const SvxBrushItem* pBrushItem = aFmt.GetBrush(); 480 if(pBrushItem) 481 { 482 const Graphic* pGrf = pBrushItem->GetGraphic(); 483 if(pGrf) 484 { 485 Size aSize(nRectHeight*6/20, nRectHeight*6/20); 486 Point aStart(aBLPos.X() + nRectWidth*7/20, aBLPos.Y() + nRectHeight*7/20); 487 488 pGrf->Draw( pDev, aStart, aSize ); 489 } 490 } 491 } 492 }else if ( nItemId == DEFAULT_NONE) 493 { 494 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 495 const Color aBackColor = rStyleSettings.GetFieldColor(); 496 const Color aTextColor = rStyleSettings.GetFieldTextColor(); 497 498 Font aOldFont = pDev->GetFont(); 499 Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 500 Size aSize = aFont.GetSize(); 501 //aSize.Height() = nRectHeight/5; 502 aSize.Height() = nRectHeight/4; 503 aFont.SetColor(aTextColor); 504 aFont.SetFillColor(aBackColor); 505 aFont.SetSize( aSize ); 506 pDev->SetFont(aFont); 507 pDev->SetFillColor( aBackColor ); 508 509 String sText(SVX_RESSTR( RID_SVXSTR_NUMBULLET_NONE)); 510 511 long nTextWidth = pDev->GetTextWidth(sText); 512 long nTextHeight = pDev->GetTextHeight(); 513 //GVT refine 514 while (nTextWidth>nRectWidth && aSize.Height()>4) { 515 aSize.Height() = aSize.Height()*0.9; 516 aFont.SetSize( aSize ); 517 pDev->SetFont(aFont); 518 nTextWidth = pDev->GetTextWidth(sText); 519 } 520 Point aStart(aBLPos.X()+(nRectWidth-nTextWidth)/2, aBLPos.Y() +(nRectHeight-nTextHeight)/2); 521 pDev->DrawText(aStart, sText); 522 523 pDev->SetFont(aOldFont); 524 } 525 } 526 527 } 528 529 } } // end of namespace svx::sidebar 530