1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_svx.hxx"
23 #include "ParaLineSpacingControl.hxx"
24 #include "ParaPropertyPanel.hrc"
25 #include <sfx2/sidebar/propertypanel.hrc>
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <unotools/viewoptions.hxx>
29 #include <editeng/kernitem.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/sidebar/Theme.hxx>
33 #include <svtools/unitconv.hxx>
34 
35 #define _DEFAULT_LINE_SPACING  200
36 #define FIX_DIST_DEF           283
37 #define LINESPACE_1            100
38 #define LINESPACE_15           150
39 #define LINESPACE_2            200
40 #define LINESPACE_115          115
41 
42 #define LLINESPACE_1          0
43 #define LLINESPACE_15         1
44 #define LLINESPACE_2          2
45 #define LLINESPACE_PROP       3
46 #define LLINESPACE_MIN        4
47 #define LLINESPACE_DURCH      5
48 #define LLINESPACE_FIX        6
49 
50 #define DO_NOT_CUSTOM          0
51 #define USE_CUSTOM             1
52 
53 namespace svx { namespace sidebar {
54 
55 
56 ParaLineSpacingControl::ParaLineSpacingControl(Window* pParent, svx::sidebar::ParaPropertyPanel& rPanel)
57 :	PopupControl( pParent,SVX_RES(RID_POPUPPANEL_PARAPAGE_LINESPACING))
58 ,	mrParaPropertyPanel(rPanel)
59 ,	mpBindings(NULL)
60 ,aLineDist				( this, SVX_RES( LB_LINE_SPACING )),
61 aLineDistAtPercentBox	( this, SVX_RES( ED_SBINDE_LINEDISTPERCENT ) ),
62 aLineDistAtMetricBox	( this, SVX_RES( ED_SBINDE_LINEDISTPOINT ) ),
63 maCustomFT        ( this, SVX_RES( FT_CUSTOM ) ),
64 maLSpacingFT      ( this, SVX_RES( FT_LINE_SPACING ) ),
65 maOfFT            ( this, SVX_RES( FT_OF ) ),
66 maSpacing1       (SVX_RES(IMG_SPACING1)),
67 maSpacing115     (SVX_RES(IMG_SPACING115)),
68 maSpacing15      (SVX_RES(IMG_SPACING15)),
69 maSpacing2       (SVX_RES(IMG_SPACING2)),
70 maLPCustom       (SVX_RES(IMG_SPACINGLCUSTOM)),
71 maSelSpacing1    (SVX_RES(IMG_SEL_SPACING1)),
72 maSelSpacing115  (SVX_RES(IMG_SEL_SPACING115)),
73 maSelSpacing15   (SVX_RES(IMG_SEL_SPACING15)),
74 maSelSpacing2    (SVX_RES(IMG_SEL_SPACING2)),
75 maImgCusGrey	 (SVX_RES(IMG_CUSTOM_GRAY)),
76 maImgCus		 (SVX_RES(IMG_CUSTOM)),
77 maStrCus		 (SVX_RES(STR_LCVALUE)),
78 pActLineDistFld 		( &aLineDistAtPercentBox ),
79 nMinFixDist			    ( BEGIN_VALUE ),
80 maValue                 ( 0 ),
81 maPos                   ( 0 ),
82 maLineSpacing		(ValueSetWithTextControl::IMAGE_TEXT,this, SVX_RES( LINE_SPACING ) ),
83 mpImg			(NULL),
84 mpImgSel		(NULL),
85 mpStr			(NULL),
86 mpStrTip		(NULL),
87 maLine			(SVX_RES(STR_LSPACING)),
88 maOf			(SVX_RES(STR_LS_OF))
89 , mbUseLineSPCustom             (0)
90 , mbLineSPDisable               (0)
91 {
92 	initial();
93 	FreeResource();
94 	mpBindings = mrParaPropertyPanel.GetBindings();
95 //	m_eLNSpaceUnit = mrParaPropertyPanel.maLNSpaceControl.GetCoreMetric();
96 	m_eLNSpaceUnit = SFX_MAPUNIT_100TH_MM;
97 }
98 ParaLineSpacingControl::~ParaLineSpacingControl()
99 {
100 	delete[] mpImg;
101 	delete[] mpImgSel;
102 	delete[] mpStr;
103 	delete[] mpStrTip;
104 }
105 /*void TextCharacterSpacingControl::Paint(const Rectangle& rect)
106 {
107 	svx::sidebar::PopupControl::Paint(rect);
108 	Color aOldLineColor = GetLineColor();
109 	Color aOldFillColor = GetFillColor();
110 
111 	//Point aPos = maBorder.GetPosPixel();
112 	//Size aSize = maBorder.GetSizePixel();
113 	Point aPos( LogicToPixel( Point( CUSTOM_X, CUSTOM_Y), MAP_APPFONT ));
114 	Size aSize( LogicToPixel( Size(  CUSTOM_WIDTH, CUSTOM_HEIGHT ), MAP_APPFONT ));
115 	Rectangle aRect( aPos, aSize );
116 	aRect.Left() -= 1;
117 	aRect.Top() -= 1;
118 	aRect.Right() += 1;
119 	aRect.Bottom() += 1;
120 
121 
122 	Color aLineColor(189,201,219);
123 	if(!GetSettings().GetStyleSettings().GetHighContrastMode())
124 		SetLineColor(aLineColor);
125 	else
126 		SetLineColor(GetSettings().GetStyleSettings().GetShadowColor());
127 	SetFillColor(COL_TRANSPARENT);
128 	//add  for high contract
129 	//if(GetSettings().GetStyleSettings().GetHighContrastMode())
130 	//{
131 	//	maBorder.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
132 	//	maFTSpacing.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
133 	//	maFTBy.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
134 	//}
135 	DrawRect(aRect);
136 
137 
138 	SetLineColor(aOldLineColor);
139 	SetFillColor(aOldFillColor);
140 }*/
141 void ParaLineSpacingControl::initial()
142 {
143 	maLineSpacing.SetStyle( maLineSpacing.GetStyle()| WB_3DLOOK |  WB_NO_DIRECTSELECT  );
144 	maLineSpacing.SetControlBackground(GetSettings().GetStyleSettings().GetMenuColor());
145 	maLineSpacing.SetColor(GetSettings().GetStyleSettings().GetMenuColor());
146 	//maLineSpacing.SetMinFont();
147 
148 	mpImg = new Image[4];
149 	mpImg[0] = maSpacing1;
150 	mpImg[1] = maSpacing115;
151 	mpImg[2] = maSpacing15;
152 	mpImg[3] = maSpacing2;
153 
154 	mpImgSel = new Image[4];
155 	mpImgSel[0] = maSelSpacing1;
156 	mpImgSel[1] = maSelSpacing115;
157 	mpImgSel[2] = maSelSpacing15;
158 	mpImgSel[3] = maSelSpacing2;
159 
160 	mpStr = new XubString[4];
161 	mpStr[0] = XubString(SVX_RES(STR_SPACING1));
162 	mpStr[1] = XubString(SVX_RES(STR_SPACING115));
163 	mpStr[2] = XubString(SVX_RES(STR_SPACING15));
164 	mpStr[3] = XubString(SVX_RES(STR_SPACING2));
165 
166 	mpStrTip = new XubString[4];
167 	mpStrTip[0] = XubString(SVX_RES(STR_LS_SINGLE));
168 	mpStrTip[1] = XubString(SVX_RES(STR_LS_115));
169 	mpStrTip[2] = XubString(SVX_RES(STR_LS_15));
170 	mpStrTip[3] = XubString(SVX_RES(STR_LS_DOUBLE));
171 	for (int i=0;i<4;i++)
172 		maLineSpacing.AddItem(mpImg[i], &mpImgSel[i],mpStr[i],&mpStrTip[i]);
173 
174 	maLineSpacing.InsertCustom(maImgCus, maImgCusGrey, maStrCus);
175 	maLineSpacing.SetCustomTip(maStrCus); //Add
176 
177 	SetAllNoSel();
178 	Link aLink = LINK(this, ParaLineSpacingControl,VSSelHdl );
179 	maLineSpacing.SetSelectHdl(aLink);
180 	maLineSpacing.StartSelection();
181 	maLineSpacing.Show();
182 
183 	aLink = LINK( this, ParaLineSpacingControl, LineSPDistHdl_Impl );
184 	aLineDist.SetSelectHdl(aLink);
185 	aLineDist.SelectEntryPos( LLINESPACE_1 ) ;
186 	aLink = LINK( this, ParaLineSpacingControl, LineSPDistAtHdl_Impl );
187 	aLineDistAtPercentBox.SetModifyHdl( aLink );
188 	aLineDistAtMetricBox.SetModifyHdl( aLink );
189 }
190 void ParaLineSpacingControl::ToGetFocus(bool bType)
191 {
192 	if(!bType)
193 		aLineDist.GrabFocus();
194 	else
195 		maLineSpacing.GrabFocus();	//wj
196 }
197 
198 void ParaLineSpacingControl::Rearrange(SfxItemState currSPState,FieldUnit currMetricUnit,SvxLineSpacingItem* currSPItem,const ::sfx2::sidebar::EnumContext currentContext)
199 {
200 	SvtViewOptions aWinOpt( E_WINDOW, LSP_POS_GLOBAL_VALUE );
201     if ( aWinOpt.Exists() )
202 	{
203 		::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
204 		::rtl::OUString aTmp;
205 		if ( aSeq.getLength())
206 			aSeq[0].Value >>= aTmp;
207 
208 		String aWinData( aTmp );
209 		maPos = (sal_uInt16)aWinData.ToInt32();
210 	}
211 
212 	SvtViewOptions aWinOpt2( E_WINDOW, LSP_LV_GLOBAL_VALUE );
213     if ( aWinOpt2.Exists() )
214 	{
215 		::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt2.GetUserData();
216 		::rtl::OUString aTmp;
217 		if ( aSeq.getLength())
218 			aSeq[0].Value >>= aTmp;
219 
220 		String aWinData( aTmp );
221 		maValue = (sal_uInt16)aWinData.ToInt32();
222 	}
223 	String sHelpText;
224 	switch(maPos)
225 	{
226 		case LLINESPACE_1:
227 			sHelpText += mpStrTip[0];
228 			break;
229 		case LLINESPACE_15:
230 			sHelpText += mpStrTip[2];
231 			break;
232 		case LLINESPACE_2:
233 			sHelpText += mpStrTip[3];
234 			break;
235 		case LLINESPACE_PROP:
236 			sHelpText +=maLine;
237 			sHelpText.Append(String("Proportion: ", 12, RTL_TEXTENCODING_ASCII_US));
238 			sHelpText += maOf;
239 			sHelpText.Append( String::CreateFromInt64( maValue ));
240 			break;
241 		case LLINESPACE_MIN:
242 			sHelpText += maLine;
243 			sHelpText.Append(String("At Least: ", 10, RTL_TEXTENCODING_ASCII_US));
244 			sHelpText += maOf;
245 			sHelpText.Append( String::CreateFromInt64( maValue ));
246 			break;
247 		case LLINESPACE_DURCH:
248 			sHelpText += maLine;
249 			sHelpText.Append(String("Leading: ", 9, RTL_TEXTENCODING_ASCII_US));
250 			sHelpText += maOf;
251 			sHelpText.Append( String::CreateFromInt64( maValue ));
252 			break;
253 		case LLINESPACE_FIX:
254 			sHelpText += maLine;
255 			sHelpText.Append(String("Fixed: ", 7, RTL_TEXTENCODING_ASCII_US));
256 			sHelpText += maOf;
257 			sHelpText.Append( String::CreateFromInt64( maValue ));
258 			break;
259 	}
260 	if( !aWinOpt.Exists() && !aWinOpt2.Exists() )
261 		mbLineSPDisable = sal_True;
262 	else
263 		mbLineSPDisable = sal_False;
264 
265 	if( mbLineSPDisable )
266 		maLineSpacing.SetCusEnable(0);
267 	else
268 	{
269 		maLineSpacing.SetCusEnable(1);
270 		maLineSpacing.SetCustomTip(sHelpText,sal_True);//Modify for Sym2_7266
271 	}
272 
273 	SfxItemState eState = currSPState;
274 
275 	SetFieldUnit( aLineDistAtMetricBox, currMetricUnit );
276 
277 //	mpLineSPPage->SetAllNoSel();
278 	aLineDist.Enable();
279 	pActLineDistFld->Enable();
280 	pActLineDistFld->SetText( String() );
281 	bool bValueSetFocus = sal_False;		//wj
282 
283 	if( eState >= SFX_ITEM_AVAILABLE )
284 	{
285 	//	SfxMapUnit eUnit = maLNSpaceControl.GetCoreMetric();
286 		SfxMapUnit eUnit = SFX_MAPUNIT_100TH_MM;
287 		m_eLNSpaceUnit = eUnit;
288 
289 		switch( currSPItem->GetLineSpaceRule() )
290 		{
291 		case SVX_LINE_SPACE_AUTO:
292 			{
293 				SvxInterLineSpace eInter = currSPItem->GetInterLineSpaceRule();
294 
295 				switch( eInter )
296 				{
297 				case SVX_INTER_LINE_SPACE_OFF:
298 					{
299 						aLineDist.SelectEntryPos( LLINESPACE_1 );
300 						pActLineDistFld->Disable();
301 						pActLineDistFld->SetText( String() );
302 						mbUseLineSPCustom = DO_NOT_CUSTOM;
303 						if ( LINESPACE_1 == currSPItem->GetPropLineSpace() )
304 						{
305 							maLineSpacing.SetSelItem(1);
306 							bValueSetFocus = sal_True;	//wj
307 						}
308 					}
309 					break;
310 
311 				case SVX_INTER_LINE_SPACE_PROP:
312 					{
313 						if ( LINESPACE_1 == currSPItem->GetPropLineSpace() )
314 						{
315 							aLineDist.SelectEntryPos( LLINESPACE_1 );
316 							pActLineDistFld->Disable();
317 							pActLineDistFld->SetText( String() );
318 							mbUseLineSPCustom = DO_NOT_CUSTOM;
319 							maLineSpacing.SetSelItem(1);
320 							bValueSetFocus = sal_True;	//wj
321 							break;
322 						}
323 						if ( LINESPACE_15 == currSPItem->GetPropLineSpace() )
324 						{
325 							aLineDist.SelectEntryPos( LLINESPACE_15 );
326 							pActLineDistFld->Disable();
327 							pActLineDistFld->SetText( String() );
328 
329 							mbUseLineSPCustom = DO_NOT_CUSTOM;
330 							maLineSpacing.SetSelItem(3);
331 							bValueSetFocus = sal_True;	//wj
332 							break;
333 						}
334 						if ( LINESPACE_2 == currSPItem->GetPropLineSpace() )
335 						{
336 							aLineDist.SelectEntryPos( LLINESPACE_2 );
337 							pActLineDistFld->Disable();
338 							pActLineDistFld->SetText( String() );
339 
340 							mbUseLineSPCustom = DO_NOT_CUSTOM;
341 							maLineSpacing.SetSelItem(4);
342 							bValueSetFocus = sal_True;	//wj
343 							break;
344 						}
345 
346 						aLineDist.SelectEntryPos( LLINESPACE_PROP );
347 						if(pActLineDistFld != &(aLineDistAtPercentBox))
348 						{
349 							pActLineDistFld->Disable();
350 							pActLineDistFld->Hide();
351 							pActLineDistFld = &(aLineDistAtPercentBox);
352 						}
353 						else
354 						{
355 							pActLineDistFld = &(aLineDistAtMetricBox);
356 							pActLineDistFld->Disable();
357 							pActLineDistFld->Hide();
358 							pActLineDistFld = &(aLineDistAtPercentBox);
359 						}
360 						pActLineDistFld->Enable();
361 						pActLineDistFld->Show();
362 						aLineDistAtPercentBox.
363 							SetValue( aLineDistAtPercentBox.Normalize(
364 							currSPItem->GetPropLineSpace() ) );
365 
366 						if( currSPItem->GetPropLineSpace() == LINESPACE_115 )
367 						{
368 							mbUseLineSPCustom = DO_NOT_CUSTOM;
369 							maLineSpacing.SetSelItem(2);
370 							bValueSetFocus = sal_True;	//wj
371 						}
372 						else
373 						{
374 							mbUseLineSPCustom = USE_CUSTOM;
375 							maLineSpacing.SetSelItem(0);
376 						}
377 					}
378 					break;
379 
380 				case SVX_INTER_LINE_SPACE_FIX:
381 					{
382 						if(pActLineDistFld != &(aLineDistAtMetricBox))
383 						{
384 							pActLineDistFld->Disable();
385 							pActLineDistFld->Hide();
386 							pActLineDistFld = &(aLineDistAtMetricBox);
387 						}
388 						else
389 						{
390 							pActLineDistFld = &(aLineDistAtPercentBox);
391 							pActLineDistFld->Disable();
392 							pActLineDistFld->Hide();
393 							pActLineDistFld = &(aLineDistAtMetricBox);
394 						}
395 						pActLineDistFld->Enable();
396 						pActLineDistFld->Show();
397 						maLineSpacing.SetSelItem(0);
398 
399 						SetMetricValue( aLineDistAtMetricBox,
400 							currSPItem->GetInterLineSpace(), eUnit );
401 						aLineDist.SelectEntryPos( LLINESPACE_DURCH );
402 
403 						mbUseLineSPCustom = USE_CUSTOM;
404 					}
405 					break;
406 				}
407 			}
408 			break;
409 		case SVX_LINE_SPACE_FIX:
410 			{
411 				if(pActLineDistFld != &(aLineDistAtMetricBox))
412 				{
413 					pActLineDistFld->Disable();
414 					pActLineDistFld->Hide();
415 					pActLineDistFld = &(aLineDistAtMetricBox);
416 				}
417 				else
418 				{
419 					pActLineDistFld = &(aLineDistAtPercentBox);
420 					pActLineDistFld->Disable();
421 					pActLineDistFld->Hide();
422 					pActLineDistFld = &(aLineDistAtMetricBox);
423 				}
424 				pActLineDistFld->Enable();
425 				pActLineDistFld->Show();
426 				maLineSpacing.SetSelItem(0);
427 
428 				SetMetricValue(aLineDistAtMetricBox, currSPItem->GetLineHeight(), eUnit);
429 				aLineDist.SelectEntryPos( LLINESPACE_FIX );
430 
431 				mbUseLineSPCustom = USE_CUSTOM;
432 			}
433 			break;
434 
435 		case SVX_LINE_SPACE_MIN:
436 			{
437 				if(pActLineDistFld != &(aLineDistAtMetricBox))
438 				{
439 					pActLineDistFld->Disable();
440 					pActLineDistFld->Hide();
441 					pActLineDistFld = &(aLineDistAtMetricBox);
442 				}
443 				else
444 				{
445 					pActLineDistFld = &(aLineDistAtPercentBox);
446 					pActLineDistFld->Disable();
447 					pActLineDistFld->Hide();
448 					pActLineDistFld = &(aLineDistAtMetricBox);
449 				}
450 				pActLineDistFld->Enable();
451 				pActLineDistFld->Show();
452 				maLineSpacing.SetSelItem(0);
453 
454 				SetMetricValue(aLineDistAtMetricBox, currSPItem->GetLineHeight(), eUnit);
455 				aLineDist.SelectEntryPos( LLINESPACE_MIN );
456 				mbUseLineSPCustom = USE_CUSTOM;
457 			}
458 			break;
459 		}
460 	}
461 	else if( eState == SFX_ITEM_DISABLED )
462 	{
463 		aLineDist.Disable();
464 		pActLineDistFld->Enable(sal_False);
465 		pActLineDistFld->SetText( String() );
466 		maLineSpacing.SetSelItem(0);
467 
468 	    mbUseLineSPCustom = DO_NOT_CUSTOM;
469 	}
470 	else
471 	{
472 		pActLineDistFld->Enable(sal_False);
473 		pActLineDistFld->SetText( String() );
474 		aLineDist.SetNoSelection();
475 		maLineSpacing.SetSelItem(0);
476 		mbUseLineSPCustom = DO_NOT_CUSTOM;
477 	}
478 
479 	aLineDist.SaveValue();
480 
481 	/*sal_uInt16 nID = pBox->GetCurItemId();
482 	pBox->SetItemDown(nID, sal_True);
483 
484 	Size aFloatSz = GetOutputSizePixel();
485 
486 	GetLineSPFloatWin()->SetSizePixel( aFloatSz );
487 
488 	Point aPos=maLineSPTbx->GetPosPixel();
489 	aPos.setX(aPos.getX());
490 	aPos = OutputToScreenPixel( aPos );
491 	Size aSize = maLineSPTbx->GetSizePixel();
492 	Rectangle aRect( aPos, aSize );
493 
494 	GetLineSPFloatWin()->StartPopupMode( aRect, FLOATWIN_POPUPMODE_DOWN | FLOATWIN_POPUPMODE_NOFOCUSCLOSE);
495 	GetLineSPFloatWin()->SetPopupModeFlags(GetLineSPFloatWin()->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
496 
497 	pLineSPPage->ToGetFocus(bValueSetFocus);
498 	*/
499 	sal_uInt16 uCount = aLineDist.GetEntryCount();
500 	if( uCount == LLINESPACE_FIX + 1 )
501 	{
502 		switch (currentContext.GetCombinedContext())
503 		{
504 			case CombinedEnumContext(Application_Impress, Context_Table):
505         		case CombinedEnumContext(Application_Draw, Context_Table):
506 			case CombinedEnumContext(Application_Writer, Context_DrawText):
507 			case CombinedEnumContext(Application_Calc, Context_DrawText):
508 			case CombinedEnumContext(Application_Draw, Context_DrawText):
509         		case CombinedEnumContext(Application_Impress, Context_DrawText):
510 			case CombinedEnumContext(Application_Writer, Context_Annotation):
511 			case CombinedEnumContext(Application_Draw, Context_Draw):
512 		        case CombinedEnumContext(Application_Draw, Context_TextObject):
513 		        case CombinedEnumContext(Application_Draw, Context_Graphic):
514 		        case CombinedEnumContext(Application_Impress, Context_Draw):
515 		        case CombinedEnumContext(Application_Impress, Context_TextObject):
516 		        case CombinedEnumContext(Application_Impress, Context_Graphic):
517 			{
518 				aLineDist.RemoveEntry(LLINESPACE_FIX);
519 			}
520 		}
521 	}
522 	else if( uCount == LLINESPACE_FIX)
523 	{
524 		switch (currentContext.GetCombinedContext())
525 		{
526 			case CombinedEnumContext(Application_Writer, Context_Default):
527 			case CombinedEnumContext(Application_Writer, Context_Text):
528 			case CombinedEnumContext(Application_Writer, Context_Table):
529 			{
530 				aLineDist.InsertEntry(String::CreateFromAscii("Fixed"), LLINESPACE_FIX);
531 			}
532 		}
533 	}
534 	maLineSpacing.Format();
535 	maLineSpacing.StartSelection();
536 }
537 
538 void ParaLineSpacingControl::SetAllNoSel()
539 {
540 	maLineSpacing.SelectItem(1);	//modified by wj for sym2_5397
541 	maLineSpacing.SetNoSelection();
542 }
543 
544 IMPL_LINK( ParaLineSpacingControl, LineSPDistHdl_Impl, ListBox*, pBox )
545 {
546 	maLineSpacing.SetNoSelection();
547 	maLineSpacing.SetSelItem(0);
548 	maLineSpacing.Format();
549 	maLineSpacing.StartSelection();
550 
551 	switch( pBox->GetSelectEntryPos() )
552 	{
553 		case LLINESPACE_1:
554 		case LLINESPACE_15:
555 		case LLINESPACE_2:
556 			pActLineDistFld->Enable(sal_False);
557 			pActLineDistFld->SetText( String() );
558 			break;
559 
560 		case LLINESPACE_DURCH:
561 			aLineDistAtPercentBox.Hide();
562 			pActLineDistFld = &aLineDistAtMetricBox;
563 			aLineDistAtMetricBox.SetMin(0);
564 
565 
566 			if ( !aLineDistAtMetricBox.GetText().Len() )
567 				aLineDistAtMetricBox.SetValue(
568 					aLineDistAtMetricBox.Normalize( 0 ) );
569 			aLineDistAtPercentBox.Hide();
570 			pActLineDistFld->Show();
571 			pActLineDistFld->Enable();
572 			break;
573 
574 		case LLINESPACE_MIN:
575 			aLineDistAtPercentBox.Hide();
576 			pActLineDistFld = &aLineDistAtMetricBox;
577 			aLineDistAtMetricBox.SetMin(0);
578 
579 			if ( !aLineDistAtMetricBox.GetText().Len() )
580 				aLineDistAtMetricBox.SetValue(
581 					aLineDistAtMetricBox.Normalize( 0 ), FUNIT_TWIP );
582 			aLineDistAtPercentBox.Hide();
583 			pActLineDistFld->Show();
584 			pActLineDistFld->Enable();
585 			break;
586 
587 		case LLINESPACE_PROP:
588 			aLineDistAtMetricBox.Hide();
589 			pActLineDistFld = &aLineDistAtPercentBox;
590 
591 			if ( !aLineDistAtPercentBox.GetText().Len() )
592 				aLineDistAtPercentBox.SetValue(
593 					aLineDistAtPercentBox.Normalize( 100 ), FUNIT_TWIP );
594 			aLineDistAtMetricBox.Hide();
595 			pActLineDistFld->Show();
596 			pActLineDistFld->Enable();
597 			break;
598 		case LLINESPACE_FIX:
599 		{
600 			aLineDistAtPercentBox.Hide();
601 			pActLineDistFld = &aLineDistAtMetricBox;
602 			sal_Int64 nTemp = aLineDistAtMetricBox.GetValue();
603 			aLineDistAtMetricBox.SetMin(aLineDistAtMetricBox.Normalize(nMinFixDist), FUNIT_TWIP);
604 
605 			if ( aLineDistAtMetricBox.GetValue() != nTemp )
606 				SetMetricValue( aLineDistAtMetricBox,
607 									FIX_DIST_DEF, SFX_MAPUNIT_TWIP );
608 			aLineDistAtPercentBox.Hide();
609 			pActLineDistFld->Show();
610 			pActLineDistFld->Enable();
611 		}
612 		break;
613 	}
614 	ExecuteLineSpace();
615 	return 0;
616 }
617 
618 IMPL_LINK( ParaLineSpacingControl, LineSPDistAtHdl_Impl, MetricField*, pBox )
619 {
620 	ExecuteLineSpace();
621 	return (0L);
622 }
623 
624 void ParaLineSpacingControl::ExecuteLineSpace()
625 {
626 	aLineDist.SaveValue();
627 	maLineSpacing.SetNoSelection();
628 
629 	SvxLineSpacingItem aSpacing(_DEFAULT_LINE_SPACING, SID_ATTR_PARA_LINESPACE);
630 	sal_uInt16 nPos = aLineDist.GetSelectEntryPos();
631 
632 	switch ( nPos )
633 	{
634 		case LLINESPACE_1:
635 		case LLINESPACE_15:
636 		case LLINESPACE_2:
637 			{
638 				SetLineSpace( aSpacing, nPos );
639 				maPos = nPos;
640 			}
641 			break;
642 
643 		case LLINESPACE_PROP:
644 			{
645 				SetLineSpace( aSpacing, nPos,
646 					aLineDistAtPercentBox.Denormalize(
647 					(long)aLineDistAtPercentBox.GetValue() ) );
648 				maPos = nPos;
649 				maValue =aLineDistAtPercentBox.GetValue();
650 			}
651 			break;
652 
653 		case LLINESPACE_MIN:
654 		case LLINESPACE_DURCH:
655 		case LLINESPACE_FIX:
656 			{
657 				SetLineSpace( aSpacing, nPos,
658 					GetCoreValue( aLineDistAtMetricBox, m_eLNSpaceUnit ) );
659 				maPos = nPos;
660 				maValue = GetCoreValue( aLineDistAtMetricBox, m_eLNSpaceUnit );
661 			}
662 		break;
663 
664 		default:
665 			DBG_ERROR( "error!!" );
666 			break;
667 	}
668 
669 	mpBindings->GetDispatcher()->Execute(
670 			SID_ATTR_PARA_LINESPACE, SFX_CALLMODE_RECORD, &aSpacing, 0L);
671 
672 	mbUseLineSPCustom = USE_CUSTOM;
673 }
674 
675 void ParaLineSpacingControl::SetLineSpace( SvxLineSpacingItem& rLineSpace,
676 						int eSpace, long lValue )
677 {
678 	switch ( eSpace )
679 	{
680 		case LLINESPACE_1:
681 			rLineSpace.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
682 			rLineSpace.GetInterLineSpaceRule() = SVX_INTER_LINE_SPACE_OFF;
683 			break;
684 
685 		case LLINESPACE_15:
686 			rLineSpace.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
687 			rLineSpace.SetPropLineSpace( LINESPACE_15 );
688 			break;
689 
690 		case LLINESPACE_2:
691 			rLineSpace.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
692 			rLineSpace.SetPropLineSpace( LINESPACE_2 );
693 			break;
694 
695 		case LLINESPACE_PROP:
696 			rLineSpace.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
697 			rLineSpace.SetPropLineSpace( (sal_uInt8)lValue );
698 			break;
699 
700 		case LLINESPACE_MIN:
701 			rLineSpace.SetLineHeight( (sal_uInt16)lValue );
702 			rLineSpace.GetInterLineSpaceRule() = SVX_INTER_LINE_SPACE_OFF;
703 			break;
704 
705 		case LLINESPACE_DURCH:
706 			rLineSpace.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
707 			rLineSpace.SetInterLineSpace( (sal_uInt16)lValue );
708 			break;
709 
710 		case LLINESPACE_FIX:
711 			rLineSpace.SetLineHeight((sal_uInt16)lValue);
712 			rLineSpace.GetLineSpaceRule() = SVX_LINE_SPACE_FIX;
713 			rLineSpace.GetInterLineSpaceRule() = SVX_INTER_LINE_SPACE_OFF;
714 		break;
715 	}
716 }
717 
718 IMPL_LINK(ParaLineSpacingControl, VSSelHdl, void *, pControl)
719 {
720 	maLineSpacing.SetNoSelection();
721 	bool bClosePop = true;
722 	if(pControl == &maLineSpacing)
723 	{
724 		sal_uInt16 iPos = maLineSpacing.GetSelectItemId();
725 		short nKern = 0;
726 		long nVal = 0;
727 		switch ( iPos )
728 		{
729 			case 1:
730 				ExecuteLineSpacing( 0, 0 );
731 				break;
732 			case 2:
733 				ExecuteLineSpacing( 0, 3 );
734 				break;
735 			case 3:
736 				ExecuteLineSpacing( 0, 1 );
737 				break;
738 			case 4:
739 				ExecuteLineSpacing( 0, 2 );
740 				break;
741 			case 5:
742 				{
743 					if(!(mbLineSPDisable))
744 					{
745 						//maPos = mrParaPropertyPanel.maLinePos;
746 						aLineDist.SelectEntryPos( maPos ) ;
747 						aLineDist.SaveValue();
748 						//maValue = mrParaPropertyPanel.maLineValue;
749 
750 						SvxLineSpacingItem aSpacing(_DEFAULT_LINE_SPACING, SID_ATTR_PARA_LINESPACE);
751 						switch(maPos)
752 						{
753 						case LLINESPACE_1:
754 						case LLINESPACE_15:
755 						case LLINESPACE_2:
756 							SetLineSpace( aSpacing, maPos );
757 							break;
758 
759 						case LLINESPACE_PROP:
760 							SetLineSpace( aSpacing, maPos,
761 								aLineDistAtPercentBox.Denormalize( (long)maValue ) );
762 							break;
763 
764 						case LLINESPACE_MIN:
765 						case LLINESPACE_DURCH:
766 						case LLINESPACE_FIX:
767 							SetLineSpace( aSpacing, maPos, (long)maValue );
768 							break;
769 						}
770 
771 						mpBindings->GetDispatcher()->Execute(
772 							SID_ATTR_PARA_LINESPACE, SFX_CALLMODE_RECORD, &aSpacing, 0L);
773 
774 						ExecuteLineSpacing( USE_CUSTOM, 0 );
775 					}
776 					else
777 						bClosePop = sal_False;
778 				}
779 				break;
780 		}
781 	}
782 	if(bClosePop)
783 		mrParaPropertyPanel.EndSpacingPopupMode();
784 	return 0;
785 }
786 
787 void ParaLineSpacingControl::ExecuteLineSpacing( sal_uInt16 aIsCustom, sal_uInt16 aEntry )
788 {
789 	if( !aIsCustom )
790 	{
791 		aLineDist.SelectEntryPos( aEntry ) ;
792 		aLineDist.SaveValue();
793 		SvxLineSpacingItem aSpacing(_DEFAULT_LINE_SPACING, SID_ATTR_PARA_LINESPACE);
794 		sal_uInt16 nPos = aEntry;
795 		if( aEntry == LLINESPACE_PROP )
796 			SetLineSpace( aSpacing, nPos, aLineDistAtPercentBox.Denormalize( (long)115 ) );
797 		else
798 			SetLineSpace( aSpacing, nPos );
799 
800 		mpBindings->GetDispatcher()->Execute(
801 			SID_ATTR_PARA_LINESPACE, SFX_CALLMODE_RECORD, &aSpacing, 0L);
802 	}
803 
804 	if( !aIsCustom )
805 	{
806 		mbUseLineSPCustom = DO_NOT_CUSTOM;
807 		mrParaPropertyPanel.EndSpacingPopupMode();
808 	}
809 	maLineSpacing.SetNoSelection();
810 }
811 
812 }} // end of namespace sidebar
813 
814