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 "precompiled_svx.hxx" 23 #include "TextCharacterSpacingControl.hxx" 24 #include "TextPropertyPanel.hrc" 25 #include <sfx2/sidebar/propertypanel.hrc> 26 #include <svx/dialogs.hrc> 27 #include <svx/dialmgr.hxx> 28 #include <unotools/viewoptions.hxx> 29 #include <editeng/kernitem.hxx> 30 #include <sfx2/bindings.hxx> 31 #include <sfx2/dispatch.hxx> 32 #include <sfx2/sidebar/Theme.hxx> 33 34 namespace svx { namespace sidebar { 35 TextCharacterSpacingControl::TextCharacterSpacingControl(Window* pParent, svx::sidebar::TextPropertyPanel& rPanel) 36 : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_TEXTPAGE_SPACING)) 37 , mrTextPropertyPanel(rPanel) 38 , mpBindings(NULL) 39 , maVSSpacing (ValueSetWithTextControl::IMAGE_TEXT,this, SVX_RES(VS_SPACING)) 40 , maLastCus (this, SVX_RES(FT_LASTCUSTOM)) 41 //, maBorder (this, SVX_RES(CT_BORDER)) 42 , maFTSpacing (this, SVX_RES(FT_SPACING)) 43 , maLBKerning (this, SVX_RES(LB_KERNING)) 44 , maFTBy (this, SVX_RES(FT_BY)) 45 , maEditKerning (this, SVX_RES(ED_KERNING)) 46 47 , mpImg (NULL) 48 , mpImgSel (NULL) 49 , mpStr (NULL) 50 , mpStrTip (NULL) 51 52 , maImgCus (SVX_RES(IMG_CUSTOM)) 53 , maImgCusGrey (SVX_RES(IMG_CUSTOM_GRAY)) 54 , maStrCus (SVX_RES(STR_CUSTOM)) 55 , maStrCusE (SVX_RES(STR_CUSTOM_E_TIP)) //add 56 , maStrCusC (SVX_RES(STR_CUSTOM_C_TIP)) //add 57 , maStrCusN (SVX_RES(STR_NORMAL_TIP)) //add 58 , maStrUnit (SVX_RES(STR_PT)) //add 59 60 , mnCustomKern(0) 61 , mnLastCus ( SPACING_NOCUSTOM ) 62 , mbCusEnable(false) 63 , mbVS(true) 64 { 65 initial(); 66 FreeResource(); 67 mpBindings = mrTextPropertyPanel.GetBindings(); 68 Link aLink = LINK(this, TextCharacterSpacingControl, KerningSelectHdl); 69 maLBKerning.SetSelectHdl(aLink); 70 aLink =LINK(this, TextCharacterSpacingControl, KerningModifyHdl); 71 maEditKerning.SetModifyHdl(aLink); 72 73 } 74 TextCharacterSpacingControl::~TextCharacterSpacingControl() 75 { 76 delete[] mpImg; 77 delete[] mpImgSel; 78 delete[] mpStr; 79 delete[] mpStrTip; 80 } 81 82 void TextCharacterSpacingControl::initial() 83 { 84 maVSSpacing.SetStyle( maVSSpacing.GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT ); 85 { 86 maVSSpacing.SetControlBackground(GetSettings().GetStyleSettings().GetHighContrastMode()? 87 GetSettings().GetStyleSettings().GetMenuColor(): 88 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground )); 89 maVSSpacing.SetColor(GetSettings().GetStyleSettings().GetHighContrastMode()? 90 GetSettings().GetStyleSettings().GetMenuColor(): 91 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground )); 92 maVSSpacing.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()? 93 GetSettings().GetStyleSettings().GetMenuColor(): 94 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground )); 95 maFTSpacing.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()? 96 GetSettings().GetStyleSettings().GetMenuColor(): 97 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground )); 98 maFTBy.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()? 99 GetSettings().GetStyleSettings().GetMenuColor(): 100 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground )); 101 } 102 mpImg = new Image[5]; 103 mpImg[0] = Image(SVX_RES(IMG_VERY_TIGHT)); 104 mpImg[1] = Image(SVX_RES(IMG_TIGHT)); 105 mpImg[2] = Image(SVX_RES(IMG_NORMAL)); 106 mpImg[3] = Image(SVX_RES(IMG_LOOSE)); 107 mpImg[4] = Image(SVX_RES(IMG_VERY_LOOSE)); 108 109 mpImgSel = new Image[5]; 110 mpImgSel[0] = Image(SVX_RES(IMG_VERY_TIGHT_S)); 111 mpImgSel[1] = Image(SVX_RES(IMG_TIGHT_S)); 112 mpImgSel[2] = Image(SVX_RES(IMG_NORMAL_S)); 113 mpImgSel[3] = Image(SVX_RES(IMG_LOOSE_S)); 114 mpImgSel[4] = Image(SVX_RES(IMG_VERY_LOOSE_S)); 115 116 mpStr = new XubString[5]; 117 mpStr[0] = XubString(SVX_RES(STR_VERY_TIGHT)); 118 mpStr[1] = XubString(SVX_RES(STR_TIGHT)); 119 mpStr[2] = XubString(SVX_RES(STR_NORMAL)); 120 mpStr[3] = XubString(SVX_RES(STR_LOOSE)); 121 mpStr[4] = XubString(SVX_RES(STR_VERY_LOOSE)); 122 123 124 mpStrTip = new XubString[5]; 125 mpStrTip[0] = XubString(SVX_RES(STR_VERY_TIGHT_TIP)); 126 mpStrTip[1] = XubString(SVX_RES(STR_TIGHT_TIP)); 127 mpStrTip[2] = XubString(SVX_RES(STR_NORMAL_TIP)); 128 mpStrTip[3] = XubString(SVX_RES(STR_LOOSE_TIP)); 129 mpStrTip[4] = XubString(SVX_RES(STR_VERY_LOOSE_TIP)); 130 131 for (int i=0;i<5;i++) 132 maVSSpacing.AddItem(mpImg[i], &mpImgSel[i],mpStr[i],&mpStrTip[i]); 133 134 maVSSpacing.AddItem( maImgCus, 0, maStrCus, 0 ); 135 136 maVSSpacing.SetNoSelection(); 137 Link aLink = LINK(this, TextCharacterSpacingControl,VSSelHdl ); 138 maVSSpacing.SetSelectHdl(aLink); 139 maVSSpacing.StartSelection(); 140 maVSSpacing.Show(); 141 } 142 void TextCharacterSpacingControl::ToGetFocus() 143 { 144 if(!mbVS) 145 maLBKerning.GrabFocus(); 146 else 147 maVSSpacing.GrabFocus(); 148 } 149 150 void TextCharacterSpacingControl::Rearrange(bool bLBAvailable,bool bAvailable, long nKerning) 151 { 152 mbVS = true; 153 maVSSpacing.SetNoSelection(); 154 SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_SPACING_GLOBAL_VALUE ); 155 if ( aWinOpt.Exists() ) 156 { 157 ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData(); 158 ::rtl::OUString aTmp; 159 if ( aSeq.getLength()) 160 aSeq[0].Value >>= aTmp; 161 162 String aWinData( aTmp ); 163 mnCustomKern = aWinData.ToInt32(); 164 mnLastCus = SPACING_CLOSE_BY_CUS_EDIT; 165 mbCusEnable = true; 166 } 167 else 168 { 169 mnLastCus = SPACING_NOCUSTOM; 170 mbCusEnable = false; 171 } 172 173 if( !mnLastCus ) 174 { 175 maVSSpacing.ReplaceItemImages(6, maImgCusGrey,0); 176 } 177 else 178 { 179 //set custom tips 180 maVSSpacing.ReplaceItemImages(6, maImgCus,0); 181 if(mnCustomKern > 0) 182 { 183 String aStrTip( maStrCusE); //LAST CUSTOM no tip defect //add 184 aStrTip.Append( String::CreateFromDouble( (double)mnCustomKern / 10)); 185 aStrTip.Append(maStrUnit); // modify 186 maVSSpacing.SetItemText(6,aStrTip); 187 } 188 else if(mnCustomKern < 0) 189 { 190 String aStrTip(maStrCusC) ; //LAST CUSTOM no tip defect //add 191 aStrTip.Append( String::CreateFromDouble( (double)-mnCustomKern / 10)); 192 aStrTip.Append(maStrUnit); // modify 193 maVSSpacing.SetItemText( 6, aStrTip ); 194 } 195 else 196 { 197 String aStrTip(maStrCusN) ; //LAST CUSTOM no tip defect //add 198 maVSSpacing.SetItemText( 6, aStrTip ); 199 } 200 201 } 202 203 if(bLBAvailable && bAvailable) 204 { 205 maLBKerning.Enable(); 206 maFTSpacing.Enable(); 207 208 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric(); 209 MapUnit eOrgUnit = (MapUnit)eUnit; 210 MapUnit ePntUnit( MAP_POINT ); 211 long nBig = maEditKerning.Normalize(nKerning); 212 nKerning = LogicToLogic( nBig, eOrgUnit, ePntUnit ); 213 214 if ( nKerning > 0 ) 215 { 216 maFTBy.Enable(); 217 maEditKerning.Enable(); 218 maEditKerning.SetMax( 9999 ); 219 maEditKerning.SetLast( 9999 ); 220 maEditKerning.SetValue( nKerning ); 221 maLBKerning.SelectEntryPos( SIDEBAR_SPACE_EXPAND ); 222 if(nKerning == 30) 223 { 224 maVSSpacing.SelectItem(4); 225 } 226 else if(nKerning == 60) 227 { 228 maVSSpacing.SelectItem(5); 229 } 230 else 231 { 232 maVSSpacing.SetNoSelection(); 233 maVSSpacing.SelectItem(0); 234 mbVS = false; 235 } 236 } 237 else if ( nKerning < 0 ) 238 { 239 maFTBy.Enable(); 240 maEditKerning.Enable(); 241 maEditKerning.SetValue( -nKerning ); 242 maLBKerning.SelectEntryPos( SIDEBAR_SPACE_CONDENSED ); 243 long nMax = mrTextPropertyPanel.GetSelFontSize()/6; 244 maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_POINT ); 245 maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) ); 246 if( nKerning == -30 ) 247 { 248 maVSSpacing.SelectItem(1); 249 } 250 else if( nKerning == -15 ) 251 { 252 maVSSpacing.SelectItem(2); 253 } 254 else 255 { 256 maVSSpacing.SetNoSelection(); 257 maVSSpacing.SelectItem(0); 258 mbVS = false; 259 } 260 } 261 else 262 { 263 maVSSpacing.SelectItem(3); 264 maLBKerning.SelectEntryPos( SIDEBAR_SPACE_NORMAL ); 265 maFTBy.Disable(); 266 maEditKerning.Disable(); 267 maEditKerning.SetValue( 0 ); 268 maEditKerning.SetMax( 9999 ); 269 maEditKerning.SetLast( 9999 ); 270 } 271 } 272 else if(bLBAvailable && !bAvailable) 273 { 274 //modified 275 maVSSpacing.SetNoSelection(); 276 maVSSpacing.SelectItem(0); 277 mbVS = false; 278 maLBKerning.Enable(); 279 maFTSpacing.Enable(); 280 maLBKerning.SetNoSelection(); 281 maEditKerning.SetText(String()); 282 maEditKerning.Disable(); 283 maFTBy.Disable(); 284 } 285 else 286 { 287 maVSSpacing.SetNoSelection(); 288 maVSSpacing.SelectItem(0); 289 mbVS = false; 290 maEditKerning.SetText(String()); 291 maLBKerning.SetNoSelection(); 292 maLBKerning.Disable(); 293 maFTSpacing.Disable(); 294 maEditKerning.Disable(); 295 maFTBy.Disable(); 296 } 297 GetFocus(); 298 maVSSpacing.Format(); 299 maVSSpacing.StartSelection(); 300 } 301 IMPL_LINK(TextCharacterSpacingControl, VSSelHdl, void *, pControl) 302 { 303 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 304 305 if(pControl == &maVSSpacing) 306 { 307 sal_uInt16 iPos = maVSSpacing.GetSelectItemId(); 308 short nKern = 0; 309 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric(); 310 long nVal = 0; 311 if(iPos == 1) 312 { 313 nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit); 314 nKern = (short)maEditKerning.Denormalize(nVal); 315 SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING); 316 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 317 mrTextPropertyPanel.SetSpacing(-nKern); 318 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 319 } 320 else if(iPos == 2) 321 { 322 nVal = LogicToLogic(15, MAP_POINT, (MapUnit)eUnit); 323 nKern = (short)maEditKerning.Denormalize(nVal); 324 SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING); 325 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 326 mrTextPropertyPanel.SetSpacing(-nKern); 327 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 328 } 329 else if(iPos == 3) 330 { 331 SvxKerningItem aKernItem(0, SID_ATTR_CHAR_KERNING); 332 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 333 mrTextPropertyPanel.SetSpacing(0); 334 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 335 } 336 else if(iPos == 4) 337 { 338 nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit); 339 nKern = (short)maEditKerning.Denormalize(nVal); 340 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING); 341 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 342 mrTextPropertyPanel.SetSpacing(nKern); 343 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 344 } 345 else if(iPos == 5) 346 { 347 nVal = LogicToLogic(60, MAP_POINT, (MapUnit)eUnit); 348 nKern = (short)maEditKerning.Denormalize(nVal); 349 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING); 350 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 351 mrTextPropertyPanel.SetSpacing(nKern); 352 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 353 } 354 else if(iPos == 6) 355 { 356 //modified 357 if(mbCusEnable) 358 { 359 nVal = LogicToLogic(mnCustomKern, MAP_POINT, (MapUnit)eUnit); 360 nKern = (short)maEditKerning.Denormalize(nVal); 361 SvxKerningItem aKernItem(nKern , SID_ATTR_CHAR_KERNING); 362 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 363 mrTextPropertyPanel.SetSpacing(nKern); 364 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 365 } 366 else 367 { 368 maVSSpacing.SetNoSelection(); //add , set no selection and keep the last select item 369 maVSSpacing.Format(); 370 Invalidate(); 371 maVSSpacing.StartSelection(); 372 } 373 //modify end 374 } 375 376 if(iPos < 6 || (iPos == 6 && mbCusEnable)) //add 377 mrTextPropertyPanel.EndSpacingPopupMode(); 378 } 379 380 381 382 return 0; 383 } 384 385 IMPL_LINK(TextCharacterSpacingControl, KerningSelectHdl, ListBox*, EMPTYARG) 386 { 387 if ( maLBKerning.GetSelectEntryPos() > 0 ) 388 { 389 maFTBy.Enable(); 390 maEditKerning.Enable(); 391 } 392 else 393 { 394 maEditKerning.SetValue( 0 ); 395 maFTBy.Disable(); 396 maEditKerning.Disable(); 397 } 398 399 if ( maVSSpacing.GetSelectItemId() > 0 ) 400 { 401 maVSSpacing.SetNoSelection(); 402 maVSSpacing.SelectItem(0); 403 maVSSpacing.Format(); 404 Invalidate(); 405 maVSSpacing.StartSelection(); 406 } 407 KerningModifyHdl( NULL ); 408 return 0; 409 } 410 IMPL_LINK(TextCharacterSpacingControl, KerningModifyHdl, MetricField*, EMPTYARG) 411 { 412 if ( maVSSpacing.GetSelectItemId() > 0 ) 413 { 414 maVSSpacing.SetNoSelection(); 415 maVSSpacing.SelectItem(0); 416 maVSSpacing.Format(); 417 Invalidate(); 418 maVSSpacing.StartSelection(); 419 } 420 sal_uInt16 nPos = maLBKerning.GetSelectEntryPos(); 421 short nKern = 0; 422 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric(); 423 mnLastCus = SPACING_CLOSE_BY_CUS_EDIT; 424 if ( nPos == SIDEBAR_SPACE_EXPAND || nPos == SIDEBAR_SPACE_CONDENSED ) 425 { 426 long nTmp = static_cast<long>(maEditKerning.GetValue()); 427 if ( nPos == SIDEBAR_SPACE_CONDENSED ) 428 { 429 long nMax = mrTextPropertyPanel.GetSelFontSize()/6; 430 maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_TWIP ); 431 maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) ); 432 if(nTmp > maEditKerning.GetMax()) 433 nTmp = maEditKerning.GetMax(); 434 mnCustomKern = -nTmp; 435 long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit ); 436 nKern = (short)maEditKerning.Denormalize( nVal ); 437 nKern *= - 1; 438 } 439 else 440 { 441 maEditKerning.SetMax( 9999 ); 442 maEditKerning.SetLast( 9999 ); 443 if(nTmp > maEditKerning.GetMax(FUNIT_TWIP)) 444 nTmp = maEditKerning.GetMax(FUNIT_TWIP); 445 mnCustomKern = nTmp; 446 long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit ); 447 nKern = (short)maEditKerning.Denormalize( nVal ); 448 } 449 } 450 else 451 { 452 mnCustomKern = 0; 453 } 454 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING); 455 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 456 mrTextPropertyPanel.SetSpacing(nKern); 457 return 0; 458 } 459 short TextCharacterSpacingControl::GetLastCustomState() 460 { 461 return mnLastCus; 462 } 463 long TextCharacterSpacingControl::GetLastCustomValue() 464 { 465 return mnCustomKern; 466 } 467 468 }} // end of namespace sidebar 469