xref: /AOO41X/main/svx/source/sidebar/text/TextCharacterSpacingControl.cxx (revision ae2dc0fa19335fe713e6dbbf20d81f8e1d5c6ee5)
1d4aefcaeSZheng Fan /**************************************************************
2d4aefcaeSZheng Fan  *
3d4aefcaeSZheng Fan  * Licensed to the Apache Software Foundation (ASF) under one
4d4aefcaeSZheng Fan  * or more contributor license agreements.  See the NOTICE file
5d4aefcaeSZheng Fan  * distributed with this work for additional information
6d4aefcaeSZheng Fan  * regarding copyright ownership.  The ASF licenses this file
7d4aefcaeSZheng Fan  * to you under the Apache License, Version 2.0 (the
8d4aefcaeSZheng Fan  * "License"); you may not use this file except in compliance
9d4aefcaeSZheng Fan  * with the License.  You may obtain a copy of the License at
10d4aefcaeSZheng Fan  *
11d4aefcaeSZheng Fan  *   http://www.apache.org/licenses/LICENSE-2.0
12d4aefcaeSZheng Fan  *
13d4aefcaeSZheng Fan  * Unless required by applicable law or agreed to in writing,
14d4aefcaeSZheng Fan  * software distributed under the License is distributed on an
15d4aefcaeSZheng Fan  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d4aefcaeSZheng Fan  * KIND, either express or implied.  See the License for the
17d4aefcaeSZheng Fan  * specific language governing permissions and limitations
18d4aefcaeSZheng Fan  * under the License.
19d4aefcaeSZheng Fan  *
20d4aefcaeSZheng Fan  *************************************************************/
21d4aefcaeSZheng Fan 
22d4aefcaeSZheng Fan #include "precompiled_svx.hxx"
23d4aefcaeSZheng Fan #include "TextCharacterSpacingControl.hxx"
24d4aefcaeSZheng Fan #include "TextPropertyPanel.hrc"
25d29c2fc2SAndre Fischer #include <sfx2/sidebar/ResourceDefinitions.hrc>
26d4aefcaeSZheng Fan #include <svx/dialogs.hrc>
27d4aefcaeSZheng Fan #include <svx/dialmgr.hxx>
28d4aefcaeSZheng Fan #include <unotools/viewoptions.hxx>
29d4aefcaeSZheng Fan #include <editeng/kernitem.hxx>
30d4aefcaeSZheng Fan #include <sfx2/bindings.hxx>
31d4aefcaeSZheng Fan #include <sfx2/dispatch.hxx>
32d4aefcaeSZheng Fan #include <sfx2/sidebar/Theme.hxx>
33d4aefcaeSZheng Fan 
34d4aefcaeSZheng Fan namespace svx { namespace sidebar {
3545da7d5eSAndre Fischer 
TextCharacterSpacingControl(Window * pParent,svx::sidebar::TextPropertyPanel & rPanel,SfxBindings * pBindings)3645da7d5eSAndre Fischer TextCharacterSpacingControl::TextCharacterSpacingControl (
3745da7d5eSAndre Fischer     Window* pParent,
3845da7d5eSAndre Fischer     svx::sidebar::TextPropertyPanel& rPanel,
3945da7d5eSAndre Fischer     SfxBindings* pBindings)
40d4aefcaeSZheng Fan :	PopupControl( pParent,SVX_RES(RID_POPUPPANEL_TEXTPAGE_SPACING))
41d4aefcaeSZheng Fan ,	mrTextPropertyPanel(rPanel)
4245da7d5eSAndre Fischer ,	mpBindings(pBindings)
43d4aefcaeSZheng Fan ,	maVSSpacing		(ValueSetWithTextControl::IMAGE_TEXT,this, SVX_RES(VS_SPACING))
44d4aefcaeSZheng Fan ,	maLastCus		(this, SVX_RES(FT_LASTCUSTOM))
45d4aefcaeSZheng Fan //,	maBorder		(this, SVX_RES(CT_BORDER))
46d4aefcaeSZheng Fan ,	maFTSpacing		(this, SVX_RES(FT_SPACING))
47d4aefcaeSZheng Fan ,	maLBKerning		(this, SVX_RES(LB_KERNING))
48d4aefcaeSZheng Fan ,	maFTBy			(this, SVX_RES(FT_BY))
49d4aefcaeSZheng Fan ,	maEditKerning	(this, SVX_RES(ED_KERNING))
50d4aefcaeSZheng Fan 
51d4aefcaeSZheng Fan ,	mpImg			(NULL)
52d4aefcaeSZheng Fan ,	mpImgSel		(NULL)
53d4aefcaeSZheng Fan ,	mpStr			(NULL)
54d4aefcaeSZheng Fan ,	mpStrTip		(NULL)
55d4aefcaeSZheng Fan 
56d4aefcaeSZheng Fan ,	maImgCus		(SVX_RES(IMG_CUSTOM))
57d4aefcaeSZheng Fan ,	maImgCusGrey	(SVX_RES(IMG_CUSTOM_GRAY))
58d4aefcaeSZheng Fan ,	maStrCus		(SVX_RES(STR_CUSTOM))
59d4aefcaeSZheng Fan ,	maStrCusE		(SVX_RES(STR_CUSTOM_E_TIP))	//add
60d4aefcaeSZheng Fan ,	maStrCusC		(SVX_RES(STR_CUSTOM_C_TIP))	//add
61d4aefcaeSZheng Fan ,	maStrCusN		(SVX_RES(STR_NORMAL_TIP))	//add
62d4aefcaeSZheng Fan ,	maStrUnit		(SVX_RES(STR_PT))			//add
63d4aefcaeSZheng Fan 
64d4aefcaeSZheng Fan ,	mnCustomKern(0)
65d4aefcaeSZheng Fan ,	mnLastCus ( SPACING_NOCUSTOM )
66d4aefcaeSZheng Fan ,	mbCusEnable(false)
67d4aefcaeSZheng Fan ,	mbVS(true)
68d4aefcaeSZheng Fan {
69d4aefcaeSZheng Fan 	initial();
70d4aefcaeSZheng Fan 	FreeResource();
71d4aefcaeSZheng Fan 	Link aLink = LINK(this, TextCharacterSpacingControl, KerningSelectHdl);
72d4aefcaeSZheng Fan 	maLBKerning.SetSelectHdl(aLink);
73d4aefcaeSZheng Fan 	aLink =LINK(this, TextCharacterSpacingControl, KerningModifyHdl);
74d4aefcaeSZheng Fan 	maEditKerning.SetModifyHdl(aLink);
75d4aefcaeSZheng Fan 
76d4aefcaeSZheng Fan }
~TextCharacterSpacingControl()77d4aefcaeSZheng Fan TextCharacterSpacingControl::~TextCharacterSpacingControl()
78d4aefcaeSZheng Fan {
79d4aefcaeSZheng Fan 	delete[] mpImg;
80d4aefcaeSZheng Fan 	delete[] mpImgSel;
81d4aefcaeSZheng Fan 	delete[] mpStr;
82d4aefcaeSZheng Fan 	delete[] mpStrTip;
83d4aefcaeSZheng Fan }
84d4aefcaeSZheng Fan 
initial()85d4aefcaeSZheng Fan void TextCharacterSpacingControl::initial()
86d4aefcaeSZheng Fan {
87d4aefcaeSZheng Fan 	maVSSpacing.SetStyle( maVSSpacing.GetStyle()| WB_3DLOOK |  WB_NO_DIRECTSELECT  );
88d4aefcaeSZheng Fan 	{
89d4aefcaeSZheng Fan 		maVSSpacing.SetControlBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
90d4aefcaeSZheng Fan 		GetSettings().GetStyleSettings().GetMenuColor():
91d4aefcaeSZheng Fan 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
92d4aefcaeSZheng Fan 		maVSSpacing.SetColor(GetSettings().GetStyleSettings().GetHighContrastMode()?
93d4aefcaeSZheng Fan 		GetSettings().GetStyleSettings().GetMenuColor():
94d4aefcaeSZheng Fan 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
95d4aefcaeSZheng Fan 		maVSSpacing.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
96d4aefcaeSZheng Fan 		GetSettings().GetStyleSettings().GetMenuColor():
97d4aefcaeSZheng Fan 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
98d4aefcaeSZheng Fan 		maFTSpacing.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
99d4aefcaeSZheng Fan 		GetSettings().GetStyleSettings().GetMenuColor():
100d4aefcaeSZheng Fan 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
101d4aefcaeSZheng Fan 		maFTBy.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
102d4aefcaeSZheng Fan 		GetSettings().GetStyleSettings().GetMenuColor():
103d4aefcaeSZheng Fan 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
104d4aefcaeSZheng Fan 	}
105d4aefcaeSZheng Fan 	mpImg = new Image[5];
106d4aefcaeSZheng Fan 	mpImg[0] = Image(SVX_RES(IMG_VERY_TIGHT));
107d4aefcaeSZheng Fan 	mpImg[1] = Image(SVX_RES(IMG_TIGHT));
108d4aefcaeSZheng Fan 	mpImg[2] = Image(SVX_RES(IMG_NORMAL));
109d4aefcaeSZheng Fan 	mpImg[3] = Image(SVX_RES(IMG_LOOSE));
110d4aefcaeSZheng Fan 	mpImg[4] = Image(SVX_RES(IMG_VERY_LOOSE));
111d4aefcaeSZheng Fan 
112d4aefcaeSZheng Fan 	mpImgSel = new Image[5];
113d4aefcaeSZheng Fan 	mpImgSel[0] = Image(SVX_RES(IMG_VERY_TIGHT_S));
114d4aefcaeSZheng Fan 	mpImgSel[1] = Image(SVX_RES(IMG_TIGHT_S));
115d4aefcaeSZheng Fan 	mpImgSel[2] = Image(SVX_RES(IMG_NORMAL_S));
116d4aefcaeSZheng Fan 	mpImgSel[3] = Image(SVX_RES(IMG_LOOSE_S));
117d4aefcaeSZheng Fan 	mpImgSel[4] = Image(SVX_RES(IMG_VERY_LOOSE_S));
118d4aefcaeSZheng Fan 
119d4aefcaeSZheng Fan 	mpStr = new XubString[5];
120d4aefcaeSZheng Fan 	mpStr[0] = XubString(SVX_RES(STR_VERY_TIGHT));
121d4aefcaeSZheng Fan 	mpStr[1] = XubString(SVX_RES(STR_TIGHT));
122d4aefcaeSZheng Fan 	mpStr[2] = XubString(SVX_RES(STR_NORMAL));
123d4aefcaeSZheng Fan 	mpStr[3] = XubString(SVX_RES(STR_LOOSE));
124d4aefcaeSZheng Fan 	mpStr[4] = XubString(SVX_RES(STR_VERY_LOOSE));
125d4aefcaeSZheng Fan 
126d4aefcaeSZheng Fan 
127d4aefcaeSZheng Fan 	mpStrTip = new XubString[5];
128d4aefcaeSZheng Fan 	mpStrTip[0] = XubString(SVX_RES(STR_VERY_TIGHT_TIP));
129d4aefcaeSZheng Fan 	mpStrTip[1] = XubString(SVX_RES(STR_TIGHT_TIP));
130d4aefcaeSZheng Fan 	mpStrTip[2] = XubString(SVX_RES(STR_NORMAL_TIP));
131d4aefcaeSZheng Fan 	mpStrTip[3] = XubString(SVX_RES(STR_LOOSE_TIP));
132d4aefcaeSZheng Fan 	mpStrTip[4] = XubString(SVX_RES(STR_VERY_LOOSE_TIP));
133d4aefcaeSZheng Fan 
134d4aefcaeSZheng Fan 	for (int i=0;i<5;i++)
135d4aefcaeSZheng Fan 		maVSSpacing.AddItem(mpImg[i], &mpImgSel[i],mpStr[i],&mpStrTip[i]);
136d4aefcaeSZheng Fan 
1370a759ee0SZheng Fan     maVSSpacing.AddItem( maImgCus, 0, maStrCus, 0 );
138d4aefcaeSZheng Fan 
1390a759ee0SZheng Fan     maVSSpacing.SetNoSelection();
140d4aefcaeSZheng Fan 	Link aLink = LINK(this, TextCharacterSpacingControl,VSSelHdl );
141d4aefcaeSZheng Fan 	maVSSpacing.SetSelectHdl(aLink);
142d4aefcaeSZheng Fan 	maVSSpacing.StartSelection();
143d4aefcaeSZheng Fan 	maVSSpacing.Show();
144d4aefcaeSZheng Fan }
ToGetFocus()145d4aefcaeSZheng Fan void TextCharacterSpacingControl::ToGetFocus()
146d4aefcaeSZheng Fan {
147d4aefcaeSZheng Fan 	if(!mbVS)
148d4aefcaeSZheng Fan 		maLBKerning.GrabFocus();
149d4aefcaeSZheng Fan 	else
150d4aefcaeSZheng Fan 		maVSSpacing.GrabFocus();
151d4aefcaeSZheng Fan }
152d4aefcaeSZheng Fan 
Rearrange(bool bLBAvailable,bool bAvailable,long nKerning)153d4aefcaeSZheng Fan void TextCharacterSpacingControl::Rearrange(bool bLBAvailable,bool bAvailable, long nKerning)
154d4aefcaeSZheng Fan {
155d4aefcaeSZheng Fan 	mbVS = true;
1560a759ee0SZheng Fan     maVSSpacing.SetNoSelection();
157d4aefcaeSZheng Fan 	SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_SPACING_GLOBAL_VALUE );
158d4aefcaeSZheng Fan     if ( aWinOpt.Exists() )
159d4aefcaeSZheng Fan 	{
160d4aefcaeSZheng Fan 		::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
161d4aefcaeSZheng Fan 		::rtl::OUString aTmp;
162d4aefcaeSZheng Fan 		if ( aSeq.getLength())
163d4aefcaeSZheng Fan 			aSeq[0].Value >>= aTmp;
164d4aefcaeSZheng Fan 
165d4aefcaeSZheng Fan 		String aWinData( aTmp );
166d4aefcaeSZheng Fan 		mnCustomKern = aWinData.ToInt32();
167d4aefcaeSZheng Fan 		mnLastCus = SPACING_CLOSE_BY_CUS_EDIT;
168d4aefcaeSZheng Fan 		mbCusEnable = true;
169d4aefcaeSZheng Fan 	}
170d4aefcaeSZheng Fan 	else
171d4aefcaeSZheng Fan 	{
172d4aefcaeSZheng Fan 		mnLastCus = SPACING_NOCUSTOM;
173d4aefcaeSZheng Fan 		mbCusEnable = false;
174d4aefcaeSZheng Fan 	}
175d4aefcaeSZheng Fan 
176d4aefcaeSZheng Fan 	if( !mnLastCus )
177d4aefcaeSZheng Fan 	{
1780a759ee0SZheng Fan 		maVSSpacing.ReplaceItemImages(6, maImgCusGrey,0);
179d4aefcaeSZheng Fan 	}
180d4aefcaeSZheng Fan 	else
181d4aefcaeSZheng Fan 	{
182d4aefcaeSZheng Fan 		//set custom tips
1830a759ee0SZheng Fan 		maVSSpacing.ReplaceItemImages(6, maImgCus,0);
184d4aefcaeSZheng Fan 		if(mnCustomKern > 0)
185d4aefcaeSZheng Fan 		{
186d4aefcaeSZheng Fan 			String aStrTip( maStrCusE);   //LAST CUSTOM no tip defect //add
187d4aefcaeSZheng Fan 			aStrTip.Append( String::CreateFromDouble( (double)mnCustomKern / 10));
188*ae2dc0faSTsutomu Uchino 			aStrTip.Append( xub_Unicode(' ') );
189d4aefcaeSZheng Fan 			aStrTip.Append(maStrUnit);		// modify
1900a759ee0SZheng Fan 			maVSSpacing.SetItemText(6,aStrTip);
191d4aefcaeSZheng Fan 		}
192d4aefcaeSZheng Fan 		else if(mnCustomKern < 0)
193d4aefcaeSZheng Fan 		{
194d4aefcaeSZheng Fan 			String aStrTip(maStrCusC) ;		//LAST CUSTOM no tip defect //add
195d4aefcaeSZheng Fan 			aStrTip.Append( String::CreateFromDouble( (double)-mnCustomKern / 10));
196*ae2dc0faSTsutomu Uchino 			aStrTip.Append( xub_Unicode( ' ' ) );
197d4aefcaeSZheng Fan 			aStrTip.Append(maStrUnit);		// modify
1980a759ee0SZheng Fan 			maVSSpacing.SetItemText( 6, aStrTip );
199d4aefcaeSZheng Fan 		}
200d4aefcaeSZheng Fan 		else
201d4aefcaeSZheng Fan 		{
202d4aefcaeSZheng Fan 			String aStrTip(maStrCusN) ;		//LAST CUSTOM no tip defect //add
2030a759ee0SZheng Fan 			maVSSpacing.SetItemText( 6, aStrTip );
204d4aefcaeSZheng Fan 		}
205d4aefcaeSZheng Fan 
206d4aefcaeSZheng Fan 	}
207d4aefcaeSZheng Fan 
208d4aefcaeSZheng Fan 	if(bLBAvailable && bAvailable)
209d4aefcaeSZheng Fan 	{
210d4aefcaeSZheng Fan 		maLBKerning.Enable();
211d4aefcaeSZheng Fan 		maFTSpacing.Enable();
212d4aefcaeSZheng Fan 
213d4aefcaeSZheng Fan 		SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric();
214d4aefcaeSZheng Fan         MapUnit eOrgUnit = (MapUnit)eUnit;
215d4aefcaeSZheng Fan         MapUnit ePntUnit( MAP_POINT );
216d4aefcaeSZheng Fan         long nBig = maEditKerning.Normalize(nKerning);
217d4aefcaeSZheng Fan         nKerning = LogicToLogic( nBig, eOrgUnit, ePntUnit );
218d4aefcaeSZheng Fan 
219d4aefcaeSZheng Fan         if ( nKerning > 0 )
220d4aefcaeSZheng Fan         {
221d4aefcaeSZheng Fan             maFTBy.Enable();
222d4aefcaeSZheng Fan             maEditKerning.Enable();
223d4aefcaeSZheng Fan             maEditKerning.SetMax( 9999 );
224d4aefcaeSZheng Fan             maEditKerning.SetLast( 9999 );
225d4aefcaeSZheng Fan             maEditKerning.SetValue( nKerning );
226d4aefcaeSZheng Fan             maLBKerning.SelectEntryPos( SIDEBAR_SPACE_EXPAND );
227d4aefcaeSZheng Fan 			if(nKerning == 30)
228d4aefcaeSZheng Fan 			{
2290a759ee0SZheng Fan 				maVSSpacing.SelectItem(4);
230d4aefcaeSZheng Fan 			}
231d4aefcaeSZheng Fan 			else if(nKerning == 60)
232d4aefcaeSZheng Fan 			{
2330a759ee0SZheng Fan 				maVSSpacing.SelectItem(5);
234d4aefcaeSZheng Fan 			}
235d4aefcaeSZheng Fan 			else
236d4aefcaeSZheng Fan 			{
2370a759ee0SZheng Fan                 maVSSpacing.SetNoSelection();
23861a625e4SOliver-Rainer Wittmann                 maVSSpacing.SelectItem(0);
239d4aefcaeSZheng Fan 				mbVS = false;
240d4aefcaeSZheng Fan 			}
241d4aefcaeSZheng Fan         }
242d4aefcaeSZheng Fan         else if ( nKerning < 0 )
243d4aefcaeSZheng Fan         {
244d4aefcaeSZheng Fan 			maFTBy.Enable();
245d4aefcaeSZheng Fan             maEditKerning.Enable();
246d4aefcaeSZheng Fan             maEditKerning.SetValue( -nKerning );
247d4aefcaeSZheng Fan             maLBKerning.SelectEntryPos( SIDEBAR_SPACE_CONDENSED );
248d4aefcaeSZheng Fan             long nMax = mrTextPropertyPanel.GetSelFontSize()/6;
249d4aefcaeSZheng Fan             maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_POINT );
250d4aefcaeSZheng Fan             maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) );
251d4aefcaeSZheng Fan 			if( nKerning == -30 )
252d4aefcaeSZheng Fan 			{
2530a759ee0SZheng Fan 				maVSSpacing.SelectItem(1);
254d4aefcaeSZheng Fan 			}
255d4aefcaeSZheng Fan 			else if( nKerning == -15 )
256d4aefcaeSZheng Fan 			{
2570a759ee0SZheng Fan 				maVSSpacing.SelectItem(2);
258d4aefcaeSZheng Fan 			}
259d4aefcaeSZheng Fan 			else
260d4aefcaeSZheng Fan 			{
2610a759ee0SZheng Fan                 maVSSpacing.SetNoSelection();
26261a625e4SOliver-Rainer Wittmann                 maVSSpacing.SelectItem(0);
263d4aefcaeSZheng Fan 				mbVS = false;
264d4aefcaeSZheng Fan 			}
265d4aefcaeSZheng Fan         }
266d4aefcaeSZheng Fan         else
267d4aefcaeSZheng Fan         {
2680a759ee0SZheng Fan 			maVSSpacing.SelectItem(3);
269d4aefcaeSZheng Fan 			maLBKerning.SelectEntryPos( SIDEBAR_SPACE_NORMAL );
270d4aefcaeSZheng Fan 			maFTBy.Disable();
271d4aefcaeSZheng Fan             maEditKerning.Disable();
272d4aefcaeSZheng Fan             maEditKerning.SetValue( 0 );
273d4aefcaeSZheng Fan             maEditKerning.SetMax( 9999 );
274d4aefcaeSZheng Fan             maEditKerning.SetLast( 9999 );
275d4aefcaeSZheng Fan         }
276d4aefcaeSZheng Fan 	}
277d4aefcaeSZheng Fan 	else if(bLBAvailable && !bAvailable)
278d4aefcaeSZheng Fan 	{
279d4aefcaeSZheng Fan 		//modified
2800a759ee0SZheng Fan         maVSSpacing.SetNoSelection();
28161a625e4SOliver-Rainer Wittmann         maVSSpacing.SelectItem(0);
282d4aefcaeSZheng Fan 		mbVS = false;
283d4aefcaeSZheng Fan 		maLBKerning.Enable();
284d4aefcaeSZheng Fan 		maFTSpacing.Enable();
285d4aefcaeSZheng Fan 		maLBKerning.SetNoSelection();
286d4aefcaeSZheng Fan 		maEditKerning.SetText(String());
287d4aefcaeSZheng Fan 		maEditKerning.Disable();
288d4aefcaeSZheng Fan 		maFTBy.Disable();
289d4aefcaeSZheng Fan 	}
290d4aefcaeSZheng Fan 	else
291d4aefcaeSZheng Fan 	{
2920a759ee0SZheng Fan         maVSSpacing.SetNoSelection();
29361a625e4SOliver-Rainer Wittmann         maVSSpacing.SelectItem(0);
294d4aefcaeSZheng Fan 		mbVS = false;
295d4aefcaeSZheng Fan 		maEditKerning.SetText(String());
296d4aefcaeSZheng Fan         maLBKerning.SetNoSelection();
297d4aefcaeSZheng Fan 		maLBKerning.Disable();
298d4aefcaeSZheng Fan 		maFTSpacing.Disable();
299d4aefcaeSZheng Fan         maEditKerning.Disable();
300d4aefcaeSZheng Fan 		maFTBy.Disable();
301d4aefcaeSZheng Fan 	}
302d4aefcaeSZheng Fan 	GetFocus();
303d4aefcaeSZheng Fan 	maVSSpacing.Format();
304d4aefcaeSZheng Fan 	maVSSpacing.StartSelection();
305d4aefcaeSZheng Fan }
IMPL_LINK(TextCharacterSpacingControl,VSSelHdl,void *,pControl)306d4aefcaeSZheng Fan IMPL_LINK(TextCharacterSpacingControl, VSSelHdl, void *, pControl)
307d4aefcaeSZheng Fan {
308d4aefcaeSZheng Fan 	mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
309d4aefcaeSZheng Fan 
310d4aefcaeSZheng Fan 	if(pControl == &maVSSpacing)
311d4aefcaeSZheng Fan 	{
312d4aefcaeSZheng Fan 		sal_uInt16 iPos = maVSSpacing.GetSelectItemId();
313d4aefcaeSZheng Fan 		short nKern = 0;
314d4aefcaeSZheng Fan 		SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric();
315d4aefcaeSZheng Fan 		long nVal = 0;
316d4aefcaeSZheng Fan 		if(iPos == 1)
317d4aefcaeSZheng Fan 		{
318d4aefcaeSZheng Fan 			nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit);
319d4aefcaeSZheng Fan 			nKern = (short)maEditKerning.Denormalize(nVal);
320d4aefcaeSZheng Fan 			SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING);
321d4aefcaeSZheng Fan 			mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
322d4aefcaeSZheng Fan 			mrTextPropertyPanel.SetSpacing(-nKern);
323d4aefcaeSZheng Fan 			mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
324d4aefcaeSZheng Fan 		}
325d4aefcaeSZheng Fan 		else if(iPos == 2)
326d4aefcaeSZheng Fan 		{
327d4aefcaeSZheng Fan 			nVal = LogicToLogic(15, MAP_POINT, (MapUnit)eUnit);
328d4aefcaeSZheng Fan 			nKern = (short)maEditKerning.Denormalize(nVal);
329d4aefcaeSZheng Fan 			SvxKerningItem aKernItem(-nKern, SID_ATTR_CHAR_KERNING);
330d4aefcaeSZheng Fan 			mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
331d4aefcaeSZheng Fan 			mrTextPropertyPanel.SetSpacing(-nKern);
332d4aefcaeSZheng Fan 			mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
333d4aefcaeSZheng Fan 		}
334d4aefcaeSZheng Fan 		else if(iPos == 3)
335d4aefcaeSZheng Fan 		{
336d4aefcaeSZheng Fan 			SvxKerningItem aKernItem(0, SID_ATTR_CHAR_KERNING);
337d4aefcaeSZheng Fan 			mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
338d4aefcaeSZheng Fan 			mrTextPropertyPanel.SetSpacing(0);
339d4aefcaeSZheng Fan 			mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
340d4aefcaeSZheng Fan 		}
341d4aefcaeSZheng Fan 		else if(iPos == 4)
342d4aefcaeSZheng Fan 		{
343d4aefcaeSZheng Fan 			nVal = LogicToLogic(30, MAP_POINT, (MapUnit)eUnit);
344d4aefcaeSZheng Fan 			nKern = (short)maEditKerning.Denormalize(nVal);
345d4aefcaeSZheng Fan 			SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING);
346d4aefcaeSZheng Fan 			mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
347d4aefcaeSZheng Fan 			mrTextPropertyPanel.SetSpacing(nKern);
348d4aefcaeSZheng Fan 			mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
349d4aefcaeSZheng Fan 		}
350d4aefcaeSZheng Fan 		else if(iPos == 5)
351d4aefcaeSZheng Fan 		{
352d4aefcaeSZheng Fan 			nVal = LogicToLogic(60, MAP_POINT, (MapUnit)eUnit);
353d4aefcaeSZheng Fan 			nKern = (short)maEditKerning.Denormalize(nVal);
354d4aefcaeSZheng Fan 			SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING);
355d4aefcaeSZheng Fan 			mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
356d4aefcaeSZheng Fan 			mrTextPropertyPanel.SetSpacing(nKern);
357d4aefcaeSZheng Fan 			mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
358d4aefcaeSZheng Fan 		}
359d4aefcaeSZheng Fan 		else if(iPos == 6)
360d4aefcaeSZheng Fan 		{
361d4aefcaeSZheng Fan 			//modified
362d4aefcaeSZheng Fan 			if(mbCusEnable)
363d4aefcaeSZheng Fan 			{
364d4aefcaeSZheng Fan 				nVal = LogicToLogic(mnCustomKern, MAP_POINT, (MapUnit)eUnit);
365d4aefcaeSZheng Fan 				nKern = (short)maEditKerning.Denormalize(nVal);
366d4aefcaeSZheng Fan 				SvxKerningItem aKernItem(nKern , SID_ATTR_CHAR_KERNING);
367d4aefcaeSZheng Fan 				mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
368d4aefcaeSZheng Fan 				mrTextPropertyPanel.SetSpacing(nKern);
369d4aefcaeSZheng Fan 				mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
370d4aefcaeSZheng Fan 			}
371d4aefcaeSZheng Fan 			else
372d4aefcaeSZheng Fan 			{
373d4aefcaeSZheng Fan 				maVSSpacing.SetNoSelection();		//add , set no selection and keep the last select item
374d4aefcaeSZheng Fan 				maVSSpacing.Format();
375d4aefcaeSZheng Fan 				Invalidate();
376d4aefcaeSZheng Fan 				maVSSpacing.StartSelection();
377d4aefcaeSZheng Fan 			}
378d4aefcaeSZheng Fan 			//modify end
379d4aefcaeSZheng Fan 		}
380d4aefcaeSZheng Fan 
381d4aefcaeSZheng Fan 		if(iPos < 6 || (iPos == 6 && mbCusEnable)) //add
382d4aefcaeSZheng Fan 			mrTextPropertyPanel.EndSpacingPopupMode();
383d4aefcaeSZheng Fan 	}
384d4aefcaeSZheng Fan 
385d4aefcaeSZheng Fan 
386d4aefcaeSZheng Fan 
387d4aefcaeSZheng Fan 	return 0;
388d4aefcaeSZheng Fan }
389d4aefcaeSZheng Fan 
IMPL_LINK(TextCharacterSpacingControl,KerningSelectHdl,ListBox *,EMPTYARG)390d4aefcaeSZheng Fan IMPL_LINK(TextCharacterSpacingControl, KerningSelectHdl, ListBox*, EMPTYARG)
391d4aefcaeSZheng Fan {
392d4aefcaeSZheng Fan 	if ( maLBKerning.GetSelectEntryPos() > 0 )
393d4aefcaeSZheng Fan 	{
394d4aefcaeSZheng Fan 		maFTBy.Enable();
395d4aefcaeSZheng Fan 		maEditKerning.Enable();
396d4aefcaeSZheng Fan 	}
397d4aefcaeSZheng Fan 	else
398d4aefcaeSZheng Fan 	{
399d4aefcaeSZheng Fan 		maEditKerning.SetValue( 0 );
400d4aefcaeSZheng Fan 		maFTBy.Disable();
401d4aefcaeSZheng Fan 		maEditKerning.Disable();
402d4aefcaeSZheng Fan 	}
403d4aefcaeSZheng Fan 
4040a759ee0SZheng Fan     if ( maVSSpacing.GetSelectItemId() > 0 )
405d4aefcaeSZheng Fan 	{
40661a625e4SOliver-Rainer Wittmann         maVSSpacing.SetNoSelection();
40761a625e4SOliver-Rainer Wittmann         maVSSpacing.SelectItem(0);
408d4aefcaeSZheng Fan 		maVSSpacing.Format();
409d4aefcaeSZheng Fan 		Invalidate();
410d4aefcaeSZheng Fan 		maVSSpacing.StartSelection();
411d4aefcaeSZheng Fan 	}
412d4aefcaeSZheng Fan 	KerningModifyHdl( NULL );
413d4aefcaeSZheng Fan 	return 0;
414d4aefcaeSZheng Fan }
IMPL_LINK(TextCharacterSpacingControl,KerningModifyHdl,MetricField *,EMPTYARG)415d4aefcaeSZheng Fan IMPL_LINK(TextCharacterSpacingControl, KerningModifyHdl, MetricField*, EMPTYARG)
416d4aefcaeSZheng Fan {
4170a759ee0SZheng Fan     if ( maVSSpacing.GetSelectItemId() > 0 )
418d4aefcaeSZheng Fan 	{
41961a625e4SOliver-Rainer Wittmann         maVSSpacing.SetNoSelection();
42061a625e4SOliver-Rainer Wittmann         maVSSpacing.SelectItem(0);
421d4aefcaeSZheng Fan 		maVSSpacing.Format();
422d4aefcaeSZheng Fan 		Invalidate();
423d4aefcaeSZheng Fan 		maVSSpacing.StartSelection();
424d4aefcaeSZheng Fan 	}
425d4aefcaeSZheng Fan 	sal_uInt16 nPos = maLBKerning.GetSelectEntryPos();
426d4aefcaeSZheng Fan     short nKern = 0;
427d4aefcaeSZheng Fan     SfxMapUnit eUnit = mrTextPropertyPanel.GetSpaceController().GetCoreMetric();
428d4aefcaeSZheng Fan 	mnLastCus = SPACING_CLOSE_BY_CUS_EDIT;
429d4aefcaeSZheng Fan 	if ( nPos == SIDEBAR_SPACE_EXPAND || nPos == SIDEBAR_SPACE_CONDENSED )
430d4aefcaeSZheng Fan     {
431d4aefcaeSZheng Fan         long nTmp = static_cast<long>(maEditKerning.GetValue());
432d4aefcaeSZheng Fan         if ( nPos == SIDEBAR_SPACE_CONDENSED )
433d4aefcaeSZheng Fan 		{
434d4aefcaeSZheng Fan 			long nMax =  mrTextPropertyPanel.GetSelFontSize()/6;
435d4aefcaeSZheng Fan 			maEditKerning.SetMax( maEditKerning.Normalize( nMax ), FUNIT_TWIP );
436d4aefcaeSZheng Fan 			maEditKerning.SetLast( maEditKerning.GetMax( maEditKerning.GetUnit() ) );
437d4aefcaeSZheng Fan 			if(nTmp > maEditKerning.GetMax())
438d4aefcaeSZheng Fan 				nTmp = maEditKerning.GetMax();
439d4aefcaeSZheng Fan 			mnCustomKern = -nTmp;
440d4aefcaeSZheng Fan 			long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit );
441d4aefcaeSZheng Fan 			nKern = (short)maEditKerning.Denormalize( nVal );
442d4aefcaeSZheng Fan             nKern *= - 1;
443d4aefcaeSZheng Fan 		}
444d4aefcaeSZheng Fan 		else
445d4aefcaeSZheng Fan 		{
446d4aefcaeSZheng Fan 			maEditKerning.SetMax( 9999 );
447d4aefcaeSZheng Fan 			maEditKerning.SetLast( 9999 );
448d4aefcaeSZheng Fan 			if(nTmp > maEditKerning.GetMax(FUNIT_TWIP))
449d4aefcaeSZheng Fan 				nTmp = maEditKerning.GetMax(FUNIT_TWIP);
450d4aefcaeSZheng Fan 			mnCustomKern = nTmp;
451d4aefcaeSZheng Fan 			long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)eUnit );
452d4aefcaeSZheng Fan 			nKern = (short)maEditKerning.Denormalize( nVal );
453d4aefcaeSZheng Fan 		}
454d4aefcaeSZheng Fan     }
455d4aefcaeSZheng Fan 	else
456d4aefcaeSZheng Fan 	{
457d4aefcaeSZheng Fan 		mnCustomKern = 0;
458d4aefcaeSZheng Fan 	}
459d4aefcaeSZheng Fan 	SvxKerningItem aKernItem(nKern, SID_ATTR_CHAR_KERNING);
460d4aefcaeSZheng Fan 	mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_KERNING, SFX_CALLMODE_RECORD, &aKernItem, 0L);
461d4aefcaeSZheng Fan 	mrTextPropertyPanel.SetSpacing(nKern);
462d4aefcaeSZheng Fan 	return 0;
463d4aefcaeSZheng Fan }
GetLastCustomState()464d4aefcaeSZheng Fan short  TextCharacterSpacingControl::GetLastCustomState()
465d4aefcaeSZheng Fan {
466d4aefcaeSZheng Fan 	return mnLastCus;
467d4aefcaeSZheng Fan }
GetLastCustomValue()468d4aefcaeSZheng Fan long  TextCharacterSpacingControl::GetLastCustomValue()
469d4aefcaeSZheng Fan {
470d4aefcaeSZheng Fan 	return mnCustomKern;
471d4aefcaeSZheng Fan }
472d4aefcaeSZheng Fan 
473d4aefcaeSZheng Fan }} // end of namespace sidebar
474