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 (
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
))
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
60 , mnLastCus ( SPACING_NOCUSTOM
)
66 Link aLink
= LINK(this, TextCharacterSpacingControl
, KerningSelectHdl
);
67 maLBKerning
.SetSelectHdl(aLink
);
68 aLink
=LINK(this, TextCharacterSpacingControl
, KerningModifyHdl
);
69 maEditKerning
.SetModifyHdl(aLink
);
72 TextCharacterSpacingControl::~TextCharacterSpacingControl()
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();
140 void TextCharacterSpacingControl::ToGetFocus()
143 maLBKerning
.GrabFocus();
145 maVSSpacing
.GrabFocus();
148 void TextCharacterSpacingControl::Rearrange(bool bLBAvailable
,bool bAvailable
, long nKerning
)
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
;
167 mnLastCus
= SPACING_NOCUSTOM
;
173 maVSSpacing
.ReplaceItemImages(6, maImgCusGrey
,0);
178 maVSSpacing
.ReplaceItemImages(6, maImgCus
,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
);
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
);
215 maEditKerning
.Enable();
216 maEditKerning
.SetMax( 9999 );
217 maEditKerning
.SetLast( 9999 );
218 maEditKerning
.SetValue( nKerning
);
219 maLBKerning
.SelectEntryPos( SIDEBAR_SPACE_EXPAND
);
222 maVSSpacing
.SelectItem(4);
224 else if(nKerning
== 60)
226 maVSSpacing
.SelectItem(5);
230 maVSSpacing
.SetNoSelection();
231 maVSSpacing
.SelectItem(0);
235 else if ( nKerning
< 0 )
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);
254 maVSSpacing
.SetNoSelection();
255 maVSSpacing
.SelectItem(0);
261 maVSSpacing
.SelectItem(3);
262 maLBKerning
.SelectEntryPos( SIDEBAR_SPACE_NORMAL
);
264 maEditKerning
.Disable();
265 maEditKerning
.SetValue( 0 );
266 maEditKerning
.SetMax( 9999 );
267 maEditKerning
.SetLast( 9999 );
270 else if(bLBAvailable
&& !bAvailable
)
273 maVSSpacing
.SetNoSelection();
274 maVSSpacing
.SelectItem(0);
276 maLBKerning
.Enable();
277 maFTSpacing
.Enable();
278 maLBKerning
.SetNoSelection();
279 maEditKerning
.SetText(String());
280 maEditKerning
.Disable();
285 maVSSpacing
.SetNoSelection();
286 maVSSpacing
.SelectItem(0);
288 maEditKerning
.SetText(String());
289 maLBKerning
.SetNoSelection();
290 maLBKerning
.Disable();
291 maFTSpacing
.Disable();
292 maEditKerning
.Disable();
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();
307 SfxMapUnit eUnit
= mrTextPropertyPanel
.GetSpaceController().GetCoreMetric();
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
;
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
;
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
;
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
;
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
;
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
;
366 maVSSpacing
.SetNoSelection(); //add , set no selection and keep the last select item
367 maVSSpacing
.Format();
369 maVSSpacing
.StartSelection();
374 if(iPos
< 6 || (iPos
== 6 && mbCusEnable
)) //add
375 mrTextPropertyPanel
.EndSpacingPopupMode();
383 IMPL_LINK(TextCharacterSpacingControl
, KerningSelectHdl
, ListBox
*, EMPTYARG
)
385 if ( maLBKerning
.GetSelectEntryPos() > 0 )
388 maEditKerning
.Enable();
392 maEditKerning
.SetValue( 0 );
394 maEditKerning
.Disable();
397 if ( maVSSpacing
.GetSelectItemId() > 0 )
399 maVSSpacing
.SetNoSelection();
400 maVSSpacing
.SelectItem(0);
401 maVSSpacing
.Format();
403 maVSSpacing
.StartSelection();
405 KerningModifyHdl( NULL
);
408 IMPL_LINK(TextCharacterSpacingControl
, KerningModifyHdl
, MetricField
*, EMPTYARG
)
410 if ( maVSSpacing
.GetSelectItemId() > 0 )
412 maVSSpacing
.SetNoSelection();
413 maVSSpacing
.SelectItem(0);
414 maVSSpacing
.Format();
416 maVSSpacing
.StartSelection();
418 sal_uInt16 nPos
= maLBKerning
.GetSelectEntryPos();
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
);
439 maEditKerning
.SetMax( 9999 );
440 maEditKerning
.SetLast( 9999 );
441 if(nTmp
> maEditKerning
.GetMax(FUNIT_TWIP
))
442 nTmp
= maEditKerning
.GetMax(FUNIT_TWIP
);
444 long nVal
= LogicToLogic( nTmp
, MAP_POINT
, (MapUnit
)eUnit
);
445 nKern
= (short)maEditKerning
.Denormalize( nVal
);
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
);
457 short TextCharacterSpacingControl::GetLastCustomState()
461 long TextCharacterSpacingControl::GetLastCustomValue()
466 }} // end of namespace sidebar