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