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