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 mbVS = false; 234 } 235 } 236 else if ( nKerning < 0 ) 237 { 238 maFTBy.Enable(); 239 maEditKerning.Enable(); 240 maEditKerning.SetValue( -nKerning ); 241 maLBKerning.SelectEntryPos( SIDEBAR_SPACE_CONDENSED ); 242 long nMax = mrTextPropertyPanel.GetSelFontSize()/6; 243 maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_POINT ); 244 maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) ); 245 if( nKerning == -30 ) 246 { 247 maVSSpacing.SelectItem(1); 248 } 249 else if( nKerning == -15 ) 250 { 251 maVSSpacing.SelectItem(2); 252 } 253 else 254 { 255 maVSSpacing.SetNoSelection(); 256 mbVS = false; 257 } 258 } 259 else 260 { 261 maVSSpacing.SelectItem(3); 262 maLBKerning.SelectEntryPos( SIDEBAR_SPACE_NORMAL ); 263 maFTBy.Disable(); 264 maEditKerning.Disable(); 265 maEditKerning.SetValue( 0 ); 266 maEditKerning.SetMax( 9999 ); 267 maEditKerning.SetLast( 9999 ); 268 } 269 } 270 else if(bLBAvailable && !bAvailable) 271 { 272 //modified 273 maVSSpacing.SetNoSelection(); 274 mbVS = false; 275 maLBKerning.Enable(); 276 maFTSpacing.Enable(); 277 maLBKerning.SetNoSelection(); 278 maEditKerning.SetText(String()); 279 maEditKerning.Disable(); 280 maFTBy.Disable(); 281 } 282 else 283 { 284 maVSSpacing.SetNoSelection(); 285 mbVS = false; 286 maEditKerning.SetText(String()); 287 maLBKerning.SetNoSelection(); 288 maLBKerning.Disable(); 289 maFTSpacing.Disable(); 290 maEditKerning.Disable(); 291 maFTBy.Disable(); 292 } 293 GetFocus(); 294 maVSSpacing.Format(); 295 maVSSpacing.StartSelection(); 296 } 297 IMPL_LINK(TextCharacterSpacingControl, VSSelHdl, void *, pControl) 298 { 299 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 300 301 if(pControl == &maVSSpacing) 302 { 303 sal_uInt16 iPos = maVSSpacing.GetSelectItemId(); 304 short nKern = 0; 305 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric(); 306 long nVal = 0; 307 if(iPos == 1) 308 { 309 nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit); 310 nKern = (short)maEditKerning.Denormalize(nVal); 311 SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING); 312 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 313 mrTextPropertyPanel.SetSpacing(-nKern); 314 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 315 } 316 else if(iPos == 2) 317 { 318 nVal = LogicToLogic(15, MAP_POINT, (MapUnit)eUnit); 319 nKern = (short)maEditKerning.Denormalize(nVal); 320 SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING); 321 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 322 mrTextPropertyPanel.SetSpacing(-nKern); 323 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 324 } 325 else if(iPos == 3) 326 { 327 SvxKerningItem aKernItem(0, SID_ATTR_CHAR_KERNING); 328 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 329 mrTextPropertyPanel.SetSpacing(0); 330 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 331 } 332 else if(iPos == 4) 333 { 334 nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit); 335 nKern = (short)maEditKerning.Denormalize(nVal); 336 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING); 337 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 338 mrTextPropertyPanel.SetSpacing(nKern); 339 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 340 } 341 else if(iPos == 5) 342 { 343 nVal = LogicToLogic(60, MAP_POINT, (MapUnit)eUnit); 344 nKern = (short)maEditKerning.Denormalize(nVal); 345 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING); 346 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 347 mrTextPropertyPanel.SetSpacing(nKern); 348 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 349 } 350 else if(iPos == 6) 351 { 352 //modified 353 if(mbCusEnable) 354 { 355 nVal = LogicToLogic(mnCustomKern, MAP_POINT, (MapUnit)eUnit); 356 nKern = (short)maEditKerning.Denormalize(nVal); 357 SvxKerningItem aKernItem(nKern , SID_ATTR_CHAR_KERNING); 358 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 359 mrTextPropertyPanel.SetSpacing(nKern); 360 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON; 361 } 362 else 363 { 364 maVSSpacing.SetNoSelection(); //add , set no selection and keep the last select item 365 maVSSpacing.Format(); 366 Invalidate(); 367 maVSSpacing.StartSelection(); 368 } 369 //modify end 370 } 371 372 if(iPos < 6 || (iPos == 6 && mbCusEnable)) //add 373 mrTextPropertyPanel.EndSpacingPopupMode(); 374 } 375 376 377 378 return 0; 379 } 380 381 IMPL_LINK(TextCharacterSpacingControl, KerningSelectHdl, ListBox*, EMPTYARG) 382 { 383 if ( maLBKerning.GetSelectEntryPos() > 0 ) 384 { 385 maFTBy.Enable(); 386 maEditKerning.Enable(); 387 } 388 else 389 { 390 maEditKerning.SetValue( 0 ); 391 maFTBy.Disable(); 392 maEditKerning.Disable(); 393 } 394 395 if ( maVSSpacing.GetSelectItemId() > 0 ) 396 { 397 maVSSpacing.SetNoSelection(); //modify 398 maVSSpacing.Format(); 399 Invalidate(); 400 maVSSpacing.StartSelection(); 401 } 402 KerningModifyHdl( NULL ); 403 return 0; 404 } 405 IMPL_LINK(TextCharacterSpacingControl, KerningModifyHdl, MetricField*, EMPTYARG) 406 { 407 if ( maVSSpacing.GetSelectItemId() > 0 ) 408 { 409 maVSSpacing.SetNoSelection(); //modify 410 maVSSpacing.Format(); 411 Invalidate(); 412 maVSSpacing.StartSelection(); 413 } 414 sal_uInt16 nPos = maLBKerning.GetSelectEntryPos(); 415 short nKern = 0; 416 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric(); 417 mnLastCus = SPACING_CLOSE_BY_CUS_EDIT; 418 if ( nPos == SIDEBAR_SPACE_EXPAND || nPos == SIDEBAR_SPACE_CONDENSED ) 419 { 420 long nTmp = static_cast<long>(maEditKerning.GetValue()); 421 if ( nPos == SIDEBAR_SPACE_CONDENSED ) 422 { 423 long nMax = mrTextPropertyPanel.GetSelFontSize()/6; 424 maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_TWIP ); 425 maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) ); 426 if(nTmp > maEditKerning.GetMax()) 427 nTmp = maEditKerning.GetMax(); 428 mnCustomKern = -nTmp; 429 long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit ); 430 nKern = (short)maEditKerning.Denormalize( nVal ); 431 nKern *= - 1; 432 } 433 else 434 { 435 maEditKerning.SetMax( 9999 ); 436 maEditKerning.SetLast( 9999 ); 437 if(nTmp > maEditKerning.GetMax(FUNIT_TWIP)) 438 nTmp = maEditKerning.GetMax(FUNIT_TWIP); 439 mnCustomKern = nTmp; 440 long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit ); 441 nKern = (short)maEditKerning.Denormalize( nVal ); 442 } 443 } 444 else 445 { 446 mnCustomKern = 0; 447 } 448 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING); 449 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L); 450 mrTextPropertyPanel.SetSpacing(nKern); 451 return 0; 452 } 453 short TextCharacterSpacingControl::GetLastCustomState() 454 { 455 return mnLastCus; 456 } 457 long TextCharacterSpacingControl::GetLastCustomValue() 458 { 459 return mnCustomKern; 460 } 461 462 }} // end of namespace sidebar 463