update credits
[LibreOffice.git] / svx / source / sidebar / text / TextCharacterSpacingControl.cxx
blob96371cec632c412fbccf82f4e274a9640e346c96
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #include "TextCharacterSpacingControl.hxx"
19 #include "TextPropertyPanel.hrc"
20 #include <sfx2/sidebar/ResourceDefinitions.hrc>
21 #include <svx/dialogs.hrc>
22 #include <svx/dialmgr.hxx>
23 #include <unotools/viewoptions.hxx>
24 #include <editeng/kernitem.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/sidebar/Theme.hxx>
29 namespace svx { namespace sidebar {
31 TextCharacterSpacingControl::TextCharacterSpacingControl (
32 Window* pParent,
33 svx::sidebar::TextPropertyPanel& rPanel,
34 SfxBindings* pBindings)
35 : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_TEXTPAGE_SPACING))
36 , mrTextPropertyPanel(rPanel)
37 , mpBindings(pBindings)
38 , maVSSpacing (ValueSetWithTextControl::IMAGE_TEXT,this, SVX_RES(VS_SPACING))
39 , maLastCus (this, SVX_RES(FT_LASTCUSTOM))
40 //, maBorder (this, SVX_RES(CT_BORDER))
41 , maFTSpacing (this, SVX_RES(FT_SPACING))
42 , maLBKerning (this, SVX_RES(LB_KERNING))
43 , maFTBy (this, SVX_RES(FT_BY))
44 , maEditKerning (this, SVX_RES(ED_KERNING))
46 , mpImg (NULL)
47 , mpImgSel (NULL)
48 , mpStr (NULL)
49 , mpStrTip (NULL)
51 , maImgCus (SVX_RES(IMG_CUSTOM))
52 , maImgCusGrey (SVX_RES(IMG_CUSTOM_GRAY))
53 , maStrCus (SVX_RES(STR_CUSTOM))
54 , maStrCusE (SVX_RES(STR_CUSTOM_E_TIP)) //add
55 , maStrCusC (SVX_RES(STR_CUSTOM_C_TIP)) //add
56 , maStrCusN (SVX_RES(STR_NORMAL_TIP)) //add
57 , maStrUnit (SVX_RES(STR_PT)) //add
59 , mnCustomKern(0)
60 , mnLastCus ( SPACING_NOCUSTOM )
61 , mbCusEnable(false)
62 , mbVS(true)
64 initial();
65 FreeResource();
66 Link aLink = LINK(this, TextCharacterSpacingControl, KerningSelectHdl);
67 maLBKerning.SetSelectHdl(aLink);
68 aLink =LINK(this, TextCharacterSpacingControl, KerningModifyHdl);
69 maEditKerning.SetModifyHdl(aLink);
72 TextCharacterSpacingControl::~TextCharacterSpacingControl()
74 delete[] mpImg;
75 delete[] mpImgSel;
76 delete[] mpStr;
77 delete[] mpStrTip;
80 void TextCharacterSpacingControl::initial()
82 maVSSpacing.SetStyle( maVSSpacing.GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT );
84 maVSSpacing.SetControlBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
85 GetSettings().GetStyleSettings().GetMenuColor():
86 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
87 maVSSpacing.SetColor(GetSettings().GetStyleSettings().GetHighContrastMode()?
88 GetSettings().GetStyleSettings().GetMenuColor():
89 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
90 maVSSpacing.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
91 GetSettings().GetStyleSettings().GetMenuColor():
92 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
93 maFTSpacing.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
94 GetSettings().GetStyleSettings().GetMenuColor():
95 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
96 maFTBy.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
97 GetSettings().GetStyleSettings().GetMenuColor():
98 sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
100 mpImg = new Image[5];
101 mpImg[0] = Image(SVX_RES(IMG_VERY_TIGHT));
102 mpImg[1] = Image(SVX_RES(IMG_TIGHT));
103 mpImg[2] = Image(SVX_RES(IMG_NORMAL));
104 mpImg[3] = Image(SVX_RES(IMG_LOOSE));
105 mpImg[4] = Image(SVX_RES(IMG_VERY_LOOSE));
107 mpImgSel = new Image[5];
108 mpImgSel[0] = Image(SVX_RES(IMG_VERY_TIGHT_S));
109 mpImgSel[1] = Image(SVX_RES(IMG_TIGHT_S));
110 mpImgSel[2] = Image(SVX_RES(IMG_NORMAL_S));
111 mpImgSel[3] = Image(SVX_RES(IMG_LOOSE_S));
112 mpImgSel[4] = Image(SVX_RES(IMG_VERY_LOOSE_S));
114 mpStr = new XubString[5];
115 mpStr[0] = XubString(SVX_RES(STR_VERY_TIGHT));
116 mpStr[1] = XubString(SVX_RES(STR_TIGHT));
117 mpStr[2] = XubString(SVX_RES(STR_NORMAL));
118 mpStr[3] = XubString(SVX_RES(STR_LOOSE));
119 mpStr[4] = XubString(SVX_RES(STR_VERY_LOOSE));
122 mpStrTip = new XubString[5];
123 mpStrTip[0] = XubString(SVX_RES(STR_VERY_TIGHT_TIP));
124 mpStrTip[1] = XubString(SVX_RES(STR_TIGHT_TIP));
125 mpStrTip[2] = XubString(SVX_RES(STR_NORMAL_TIP));
126 mpStrTip[3] = XubString(SVX_RES(STR_LOOSE_TIP));
127 mpStrTip[4] = XubString(SVX_RES(STR_VERY_LOOSE_TIP));
129 for (int i=0;i<5;i++)
130 maVSSpacing.AddItem(mpImg[i], &mpImgSel[i],mpStr[i],&mpStrTip[i]);
132 maVSSpacing.AddItem( maImgCus, 0, maStrCus, 0 );
134 maVSSpacing.SetNoSelection();
135 Link aLink = LINK(this, TextCharacterSpacingControl,VSSelHdl );
136 maVSSpacing.SetSelectHdl(aLink);
137 maVSSpacing.StartSelection();
138 maVSSpacing.Show();
140 void TextCharacterSpacingControl::ToGetFocus()
142 if(!mbVS)
143 maLBKerning.GrabFocus();
144 else
145 maVSSpacing.GrabFocus();
148 void TextCharacterSpacingControl::Rearrange(bool bLBAvailable,bool bAvailable, long nKerning)
150 mbVS = true;
151 maVSSpacing.SetNoSelection();
152 SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_SPACING_GLOBAL_VALUE );
153 if ( aWinOpt.Exists() )
155 ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
156 ::rtl::OUString aTmp;
157 if ( aSeq.getLength())
158 aSeq[0].Value >>= aTmp;
160 String aWinData( aTmp );
161 mnCustomKern = aWinData.ToInt32();
162 mnLastCus = SPACING_CLOSE_BY_CUS_EDIT;
163 mbCusEnable = true;
165 else
167 mnLastCus = SPACING_NOCUSTOM;
168 mbCusEnable = false;
171 if( !mnLastCus )
173 maVSSpacing.ReplaceItemImages(6, maImgCusGrey,0);
175 else
177 //set custom tips
178 maVSSpacing.ReplaceItemImages(6, maImgCus,0);
179 if(mnCustomKern > 0)
181 String aStrTip( maStrCusE); //LAST CUSTOM no tip defect //add
182 aStrTip.Append( OUString::number( (double)mnCustomKern / 10));
183 aStrTip.Append(maStrUnit); // modify
184 maVSSpacing.SetItemText(6,aStrTip);
186 else if(mnCustomKern < 0)
188 String aStrTip(maStrCusC) ; //LAST CUSTOM no tip defect //add
189 aStrTip.Append( OUString::number( (double)-mnCustomKern / 10));
190 aStrTip.Append(maStrUnit); // modify
191 maVSSpacing.SetItemText( 6, aStrTip );
193 else
195 String aStrTip(maStrCusN) ; //LAST CUSTOM no tip defect //add
196 maVSSpacing.SetItemText( 6, aStrTip );
201 if(bLBAvailable && bAvailable)
203 maLBKerning.Enable();
204 maFTSpacing.Enable();
206 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric();
207 MapUnit eOrgUnit = (MapUnit)eUnit;
208 MapUnit ePntUnit( MAP_POINT );
209 long nBig = maEditKerning.Normalize(nKerning);
210 nKerning = LogicToLogic( nBig, eOrgUnit, ePntUnit );
212 if ( nKerning > 0 )
214 maFTBy.Enable();
215 maEditKerning.Enable();
216 maEditKerning.SetMax( 9999 );
217 maEditKerning.SetLast( 9999 );
218 maEditKerning.SetValue( nKerning );
219 maLBKerning.SelectEntryPos( SIDEBAR_SPACE_EXPAND );
220 if(nKerning == 30)
222 maVSSpacing.SelectItem(4);
224 else if(nKerning == 60)
226 maVSSpacing.SelectItem(5);
228 else
230 maVSSpacing.SetNoSelection();
231 maVSSpacing.SelectItem(0);
232 mbVS = false;
235 else if ( nKerning < 0 )
237 maFTBy.Enable();
238 maEditKerning.Enable();
239 maEditKerning.SetValue( -nKerning );
240 maLBKerning.SelectEntryPos( SIDEBAR_SPACE_CONDENSED );
241 long nMax = mrTextPropertyPanel.GetSelFontSize()/6;
242 maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_POINT );
243 maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) );
244 if( nKerning == -30 )
246 maVSSpacing.SelectItem(1);
248 else if( nKerning == -15 )
250 maVSSpacing.SelectItem(2);
252 else
254 maVSSpacing.SetNoSelection();
255 maVSSpacing.SelectItem(0);
256 mbVS = false;
259 else
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 );
270 else if(bLBAvailable && !bAvailable)
272 //modified
273 maVSSpacing.SetNoSelection();
274 maVSSpacing.SelectItem(0);
275 mbVS = false;
276 maLBKerning.Enable();
277 maFTSpacing.Enable();
278 maLBKerning.SetNoSelection();
279 maEditKerning.SetText(String());
280 maEditKerning.Disable();
281 maFTBy.Disable();
283 else
285 maVSSpacing.SetNoSelection();
286 maVSSpacing.SelectItem(0);
287 mbVS = false;
288 maEditKerning.SetText(String());
289 maLBKerning.SetNoSelection();
290 maLBKerning.Disable();
291 maFTSpacing.Disable();
292 maEditKerning.Disable();
293 maFTBy.Disable();
295 GetFocus();
296 maVSSpacing.Format();
297 maVSSpacing.StartSelection();
299 IMPL_LINK(TextCharacterSpacingControl, VSSelHdl, void *, pControl)
301 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
303 if(pControl == &maVSSpacing)
305 sal_uInt16 iPos = maVSSpacing.GetSelectItemId();
306 short nKern = 0;
307 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric();
308 long nVal = 0;
309 if(iPos == 1)
311 nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit);
312 nKern = (short)maEditKerning.Denormalize(nVal);
313 SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING);
314 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
315 mrTextPropertyPanel.SetSpacing(-nKern);
316 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
318 else if(iPos == 2)
320 nVal = LogicToLogic(15, MAP_POINT, (MapUnit)eUnit);
321 nKern = (short)maEditKerning.Denormalize(nVal);
322 SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING);
323 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
324 mrTextPropertyPanel.SetSpacing(-nKern);
325 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
327 else if(iPos == 3)
329 SvxKerningItem aKernItem(0, SID_ATTR_CHAR_KERNING);
330 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
331 mrTextPropertyPanel.SetSpacing(0);
332 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
334 else if(iPos == 4)
336 nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit);
337 nKern = (short)maEditKerning.Denormalize(nVal);
338 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING);
339 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
340 mrTextPropertyPanel.SetSpacing(nKern);
341 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
343 else if(iPos == 5)
345 nVal = LogicToLogic(60, MAP_POINT, (MapUnit)eUnit);
346 nKern = (short)maEditKerning.Denormalize(nVal);
347 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING);
348 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
349 mrTextPropertyPanel.SetSpacing(nKern);
350 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
352 else if(iPos == 6)
354 //modified
355 if(mbCusEnable)
357 nVal = LogicToLogic(mnCustomKern, MAP_POINT, (MapUnit)eUnit);
358 nKern = (short)maEditKerning.Denormalize(nVal);
359 SvxKerningItem aKernItem(nKern , SID_ATTR_CHAR_KERNING);
360 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
361 mrTextPropertyPanel.SetSpacing(nKern);
362 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
364 else
366 maVSSpacing.SetNoSelection(); //add , set no selection and keep the last select item
367 maVSSpacing.Format();
368 Invalidate();
369 maVSSpacing.StartSelection();
371 //modify end
374 if(iPos < 6 || (iPos == 6 && mbCusEnable)) //add
375 mrTextPropertyPanel.EndSpacingPopupMode();
380 return 0;
383 IMPL_LINK(TextCharacterSpacingControl, KerningSelectHdl, ListBox*, EMPTYARG)
385 if ( maLBKerning.GetSelectEntryPos() > 0 )
387 maFTBy.Enable();
388 maEditKerning.Enable();
390 else
392 maEditKerning.SetValue( 0 );
393 maFTBy.Disable();
394 maEditKerning.Disable();
397 if ( maVSSpacing.GetSelectItemId() > 0 )
399 maVSSpacing.SetNoSelection();
400 maVSSpacing.SelectItem(0);
401 maVSSpacing.Format();
402 Invalidate();
403 maVSSpacing.StartSelection();
405 KerningModifyHdl( NULL );
406 return 0;
408 IMPL_LINK(TextCharacterSpacingControl, KerningModifyHdl, MetricField*, EMPTYARG)
410 if ( maVSSpacing.GetSelectItemId() > 0 )
412 maVSSpacing.SetNoSelection();
413 maVSSpacing.SelectItem(0);
414 maVSSpacing.Format();
415 Invalidate();
416 maVSSpacing.StartSelection();
418 sal_uInt16 nPos = maLBKerning.GetSelectEntryPos();
419 short nKern = 0;
420 SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric();
421 mnLastCus = SPACING_CLOSE_BY_CUS_EDIT;
422 if ( nPos == SIDEBAR_SPACE_EXPAND || nPos == SIDEBAR_SPACE_CONDENSED )
424 long nTmp = static_cast<long>(maEditKerning.GetValue());
425 if ( nPos == SIDEBAR_SPACE_CONDENSED )
427 long nMax = mrTextPropertyPanel.GetSelFontSize()/6;
428 maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_TWIP );
429 maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) );
430 if(nTmp > maEditKerning.GetMax())
431 nTmp = maEditKerning.GetMax();
432 mnCustomKern = -nTmp;
433 long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit );
434 nKern = (short)maEditKerning.Denormalize( nVal );
435 nKern *= - 1;
437 else
439 maEditKerning.SetMax( 9999 );
440 maEditKerning.SetLast( 9999 );
441 if(nTmp > maEditKerning.GetMax(FUNIT_TWIP))
442 nTmp = maEditKerning.GetMax(FUNIT_TWIP);
443 mnCustomKern = nTmp;
444 long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit );
445 nKern = (short)maEditKerning.Denormalize( nVal );
448 else
450 mnCustomKern = 0;
452 SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING);
453 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
454 mrTextPropertyPanel.SetSpacing(nKern);
455 return 0;
457 short TextCharacterSpacingControl::GetLastCustomState()
459 return mnLastCus;
461 long TextCharacterSpacingControl::GetLastCustomValue()
463 return mnCustomKern;
466 }} // end of namespace sidebar