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 <svx/sidebar/ColorControl.hxx>
24 
25 #include "ParaPropertyPanel.hxx"
26 #include "ParaPropertyPanel.hrc"
27 
28 #include "ParaLineSpacingPopup.hxx"
29 #include "ParaLineSpacingControl.hxx"
30 #include "ParaBulletsPopup.hxx"
31 #include "ParaBulletsControl.hxx"
32 #include "ParaNumberingPopup.hxx"
33 #include "ParaNumberingControl.hxx"
34 #include <sfx2/sidebar/Theme.hxx>
35 #include <sfx2/sidebar/propertypanel.hrc>
36 #include <sfx2/sidebar/ControlFactory.hxx>
37 #include <svx/sidebar/PopupContainer.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <editeng/colritem.hxx>
40 #include <editeng/brshitem.hxx>
41 #include <editeng/lrspitem.hxx>
42 #include <editeng/ulspitem.hxx>
43 #include <vcl/toolbox.hxx>
44 #include <vcl/fixed.hxx>
45 #include <vcl/svapp.hxx>
46 #include <svx/svxids.hrc>
47 #include <svl/intitem.hxx>
48 #include "svx/dialmgr.hxx"
49 #include <sfx2/objsh.hxx>
50 #include <svtools/unitconv.hxx>
51 #include <boost/bind.hpp>
52 using namespace css;
53 using namespace cssu;
54 using ::sfx2::sidebar::Theme;
55 using ::sfx2::sidebar::ControlFactory;
56 
57 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
58 
59 
60 namespace svx {namespace sidebar {
61 #define DEFAULT_VALUE          0
62 #define TOOLBOX_ITEM1          1
63 #define TOOLBOX_ITEM2          2
64 #define TOOLBOX_ITEM3          3
65 #define TOOLBOX_ITEM4          4
66 
67 #define MAX_DURCH             5670
68 
69 #define INDENT_INCREMENT       1
70 #define INDENT_DECREMENT       2
71 #define INDENT_STEP            706
72 #define UL_STEP                58
73 #define UL_INCREMENT           1
74 #define UL_DECREMENT           2
75 
76 #define NEGATIVE_MAX_VALUE              -9999
77 #define BEGIN_VALUE            28
78 #define MAX_SW                  1709400
79 #define MAX_SC_SD				116220200
80 #define NEGA_MAXVALUE          -10000000
81 
82 #define POS_FT_PARA_SPACE								Point(LogicToPixel(Point(FT_PARA_SPACE_X,FT_PARA_SPACE_Y), MAP_APPFONT))
83 #define POS_FT_PARA_SPACE2								Point(LogicToPixel(Point(FT_PARA_SPACE_X,FT_PARA_SPACE_Y2), MAP_APPFONT))
84 #define POS_TBX_PARA_SPACE_INC_DEC						Point(LogicToPixel(Point(TBX_PARA_SPACE_INC_DEC_X,TBX_PARA_SPACE_INC_DEC_Y), MAP_APPFONT))
85 #define POS_TBX_PARA_SPACE_INC_DEC2						Point(LogicToPixel(Point(TBX_PARA_SPACE_INC_DEC_X,TBX_PARA_SPACE_INC_DEC_Y2), MAP_APPFONT))
86 #define POS_FT_PARA_INDENT								Point(LogicToPixel(Point(FT_PARA_INDENT_X,FT_PARA_INDENT_Y), MAP_APPFONT))
87 #define POS_FT_PARA_INDENT2								Point(LogicToPixel(Point(FT_PARA_INDENT_X,FT_PARA_INDENT_Y2), MAP_APPFONT))
88 #define POS_TBX_PARA_INDENT_INC_DEC						Point(LogicToPixel(Point(TBX_PARA_INDENT_INC_DEC_X,TBX_PARA_INDENT_INC_DEC_Y), MAP_APPFONT))
89 #define POS_TBX_PARA_INDENT_INC_DEC2					Point(LogicToPixel(Point(TBX_PARA_INDENT_INC_DEC_X,TBX_PARA_INDENT_INC_DEC_Y2), MAP_APPFONT))
90 #define POS_MBX_TOP_DIST								Point(LogicToPixel(Point(MBX_TOP_DIST_X,MBX_TOP_DIST_Y), MAP_APPFONT))
91 #define POS_MBX_TOP_DIST2								Point(LogicToPixel(Point(MBX_TOP_DIST_X,MBX_TOP_DIST_Y2), MAP_APPFONT))
92 #define POS_MBX_BOT_DIST								Point(LogicToPixel(Point(MBX_BOT_DIST_X,MBX_BOT_DIST_Y), MAP_APPFONT))
93 #define POS_MBX_BOT_DIST2								Point(LogicToPixel(Point(MBX_BOT_DIST_X,MBX_BOT_DIST_Y2), MAP_APPFONT))
94 #define POS_MBX_LEFT_DIST								Point(LogicToPixel(Point(MBX_LEFT_DIST_X,MBX_LEFT_DIST_Y), MAP_APPFONT))
95 #define POS_MBX_LEFT_DIST2								Point(LogicToPixel(Point(MBX_LEFT_DIST_X,MBX_LEFT_DIST_Y2), MAP_APPFONT))
96 #define POS_MBX_RIGHT_DIST								Point(LogicToPixel(Point(MBX_RIGHT_DIST_X,MBX_RIGHT_DIST_Y), MAP_APPFONT))
97 #define POS_MBX_RIGHT_DIST2								Point(LogicToPixel(Point(MBX_RIGHT_DIST_X,MBX_RIGHT_DIST_Y2), MAP_APPFONT))
98 #define POS_MBX_FLINE_DIST								Point(LogicToPixel(Point(MBX_FLINE_DIST_X,MBX_FLINE_DIST_Y), MAP_APPFONT))
99 #define POS_MBX_FLINE_DIST2								Point(LogicToPixel(Point(MBX_FLINE_DIST_X,MBX_FLINE_DIST_Y2), MAP_APPFONT))
100 #define POS_IMG_SPACE1									Point(LogicToPixel(Point(IMG_SPACE_X,IMG_SPACE1_Y), MAP_APPFONT))
101 #define POS_IMG_SPACE12									Point(LogicToPixel(Point(IMG_SPACE_X,IMG_SPACE1_Y2), MAP_APPFONT))
102 #define POS_IMG_SPACE2									Point(LogicToPixel(Point(IMG_SPACE_X,IMG_SPACE2_Y), MAP_APPFONT))
103 #define POS_IMG_SPACE22									Point(LogicToPixel(Point(IMG_SPACE_X,IMG_SPACE2_Y2), MAP_APPFONT))
104 #define POS_IMG_INDENT1									Point(LogicToPixel(Point(IMG_INDENT_X,IMG_INDENT1_Y), MAP_APPFONT))
105 #define POS_IMG_INDENT12								Point(LogicToPixel(Point(IMG_INDENT_X,IMG_INDENT1_Y2), MAP_APPFONT))
106 #define POS_IMG_INDENT2									Point(LogicToPixel(Point(IMG_INDENT_X,IMG_INDENT2_Y), MAP_APPFONT))
107 #define POS_IMG_INDENT22								Point(LogicToPixel(Point(IMG_INDENT_X,IMG_INDENT2_Y2), MAP_APPFONT))
108 #define POS_IMG_INDENT3									Point(LogicToPixel(Point(IMG_INDENT_X,IMG_INDENT3_Y), MAP_APPFONT))
109 #define POS_IMG_INDENT32								Point(LogicToPixel(Point(IMG_INDENT_X,IMG_INDENT3_Y2), MAP_APPFONT))
110 #define TBX_LINE_SPACE									Point(LogicToPixel(Point(TBX_LINE_SPACE_X,TBX_LINE_SPACE_Y), MAP_APPFONT))
111 #define TBX_LINE_SPACE2									Point(LogicToPixel(Point(TBX_LINE_SPACE_X,TBX_LINE_SPACE_Y2), MAP_APPFONT))
112 
113 #define LINE_POINT1_WHITE								Point(LogicToPixel(Point(LINE_X_WHITE,LINE_TOP_Y), MAP_APPFONT))
114 #define LINE_POINT2_WHITE								Point(LogicToPixel(Point(LINE_X_WHITE,LINE_BOT_Y), MAP_APPFONT))
115 #define LINE_POINT3_WHITE								Point(LogicToPixel(Point(LINE_X_WHITE,LINE_TOP_Y2), MAP_APPFONT))
116 #define LINE_POINT4_WHITE								Point(LogicToPixel(Point(LINE_X_WHITE,LINE_BOT_Y2), MAP_APPFONT))
117 
118 ParaPropertyPanel* ParaPropertyPanel::Create (
119     Window* pParent,
120     const cssu::Reference<css::frame::XFrame>& rxFrame,
121     SfxBindings* pBindings,
122     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
123 {
124     if (pParent == NULL)
125         throw lang::IllegalArgumentException(A2S("no parent Window given to ParaPropertyPanel::Create"), NULL, 0);
126     if ( ! rxFrame.is())
127         throw lang::IllegalArgumentException(A2S("no XFrame given to ParaPropertyPanel::Create"), NULL, 1);
128     if (pBindings == NULL)
129         throw lang::IllegalArgumentException(A2S("no SfxBindings given to ParaPropertyPanel::Create"), NULL, 2);
130 
131     return new ParaPropertyPanel(
132         pParent,
133         rxFrame,
134         pBindings,
135         rxSidebar);
136 }
137 
138 void ParaPropertyPanel::HandleContextChange (
139     const ::sfx2::sidebar::EnumContext aContext)
140 {
141     if (maContext == aContext)
142     {
143         // Nothing to do.
144         return;
145     }
146 
147     maContext = aContext;
148     switch (maContext.GetCombinedContext_DI())
149     {
150         case CombinedEnumContext(Application_Calc, Context_DrawText):
151             maTBxVertAlign->Show();
152             maTBxVertAlignBackground->Show();
153             maTBxBackColor->Hide();
154             maTBxBackColorBackground->Hide();
155             maTBxNumBullet->Hide();
156             maTBxNumBulletBackground->Hide();
157             ReSize(false);
158             maTbxIndent_IncDec->Show();
159             maTbxIndent_IncDecBackground->Show();
160             maTbxProDemote->Hide();
161             maTbxProDemoteBackground->Hide();
162             break;
163 
164         case CombinedEnumContext(Application_DrawImpress, Context_Draw):
165         case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
166         case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
167             maTBxVertAlign->Hide();
168 		    maTBxVertAlignBackground->Hide();
169             maTBxBackColor->Hide();
170             maTBxBackColorBackground->Hide();
171             maTBxNumBullet->Show();
172             maTBxNumBulletBackground->Show();
173             ReSize(true);
174             maTbxIndent_IncDec->Hide();
175             maTbxIndent_IncDecBackground->Hide();
176             maTbxProDemote->Show();
177             maTbxProDemoteBackground->Show();
178             break;
179 
180         case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
181             maTBxVertAlign->Show();
182             maTBxVertAlignBackground->Show();
183             maTBxBackColor->Hide();
184             maTBxBackColorBackground->Hide();
185             maTBxNumBullet->Show();
186             maTBxNumBulletBackground->Show();
187             ReSize(true);
188             maTbxIndent_IncDec->Hide();
189             maTbxIndent_IncDecBackground->Hide();
190             maTbxProDemote->Show();
191             maTbxProDemoteBackground->Show();
192             break;
193 
194         case CombinedEnumContext(Application_DrawImpress, Context_Table):
195             maTBxVertAlign->Show();
196             maTBxVertAlignBackground->Show();
197             maTBxBackColor->Hide();
198             maTBxBackColorBackground->Hide();
199             maTBxNumBullet->Show();
200             maTBxNumBulletBackground->Show();
201             ReSize(true);
202             maTbxIndent_IncDec->Hide();
203             maTbxIndent_IncDecBackground->Hide();
204             maTbxProDemote->Show();
205             maTbxProDemoteBackground->Show();
206             break;
207 
208         case CombinedEnumContext(Application_WriterAndWeb, Context_Default):
209         case CombinedEnumContext(Application_WriterAndWeb, Context_Text):
210             maTBxVertAlign->Hide();
211             maTBxVertAlignBackground->Hide();
212             maTBxBackColor->Show();
213             maTBxBackColorBackground->Show();
214             maTBxNumBullet->Show();
215 
216             maTBxNumBulletBackground->Show();
217             ReSize(true);
218             maTbxIndent_IncDec->Show();
219             maTbxIndent_IncDecBackground->Show();
220             maTbxProDemote->Hide();
221             maTbxProDemoteBackground->Hide();
222             break;
223 
224         case CombinedEnumContext(Application_WriterAndWeb, Context_Table):
225             maTBxVertAlign->Show();
226             maTBxVertAlignBackground->Show();
227             maTBxBackColor->Show();
228             maTBxBackColorBackground->Show();
229             maTBxNumBullet->Show();
230             maTBxNumBulletBackground->Show();
231             ReSize(true);
232             maTbxIndent_IncDec->Show();
233             maTbxIndent_IncDecBackground->Show();
234             maTbxProDemote->Hide();
235             maTbxProDemoteBackground->Hide();
236             break;
237 
238         case CombinedEnumContext(Application_WriterAndWeb, Context_DrawText):
239             maTBxVertAlign->Show();
240             maTBxVertAlignBackground->Show();
241             maTBxBackColor->Hide();
242             maTBxBackColorBackground->Hide();
243             maTBxNumBullet->Hide();
244             maTBxNumBulletBackground->Hide();
245             ReSize(false);
246             maTbxIndent_IncDec->Show();
247             maTbxIndent_IncDecBackground->Show();
248             maTbxProDemote->Hide();
249             maTbxProDemoteBackground->Hide();
250             break;
251 
252         case CombinedEnumContext(Application_WriterAndWeb, Context_Annotation):
253             maTBxVertAlign->Hide();
254             maTBxVertAlignBackground->Hide();
255             maTBxBackColor->Hide();
256             maTBxBackColorBackground->Hide();
257             maTBxNumBullet->Hide();
258             maTBxNumBulletBackground->Hide();
259             ReSize(false);
260             maTbxIndent_IncDec->Show();
261             maTbxIndent_IncDecBackground->Show();
262             maTbxProDemote->Hide();
263             maTbxProDemoteBackground->Hide();
264             break;
265 
266         case CombinedEnumContext(Application_Calc, Context_EditCell):
267         case CombinedEnumContext(Application_Calc, Context_Cell):
268         case CombinedEnumContext(Application_Calc, Context_Pivot):
269         case CombinedEnumContext(Application_DrawImpress, Context_Text):
270         case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
271         /*{
272             mpToolBoxScriptSw->Hide();
273             mpToolBoxScript->Show();
274             mpToolBoxSpacing->Show();
275             mpToolBoxHighlight->Hide();
276 
277             Size aSize(PROPERTYPAGE_WIDTH,TEXT_SECTIONPAGE_HEIGHT);
278             aSize = LogicToPixel( aSize,MapMode(MAP_APPFONT) );
279             aSize.setWidth(GetOutputSizePixel().Width());
280             SetSizePixel(aSize);
281         }*/
282             break;
283 
284         default:
285             break;
286     }
287 }
288 
289 SfxBindings* ParaPropertyPanel::GetBindings()
290 {
291     return mpBindings;
292 }
293 
294 void ParaPropertyPanel::SetupIcons (void)
295 {
296     if (Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
297     {
298     }
299     else
300     {
301     }
302 }
303 
304 void ParaPropertyPanel::DataChanged (const DataChangedEvent& rEvent)
305 {
306     (void)rEvent;
307 
308     SetupIcons();
309 }
310 
311 ParaPropertyPanel::~ParaPropertyPanel()
312 {
313 	delete mpLnSPItem;
314 }
315 
316 void ParaPropertyPanel::ReSize(bool bSize)
317 {
318 	if(bSize)
319 	{
320 		//Paragraph spacing
321 		maFTUL->SetPosPixel(POS_FT_PARA_SPACE);
322 		maTbxUL_IncDec->SetPosPixel(POS_TBX_PARA_SPACE_INC_DEC);
323 		maTopDist->SetPosPixel(POS_MBX_TOP_DIST);
324 		maBottomDist->SetPosPixel(POS_MBX_BOT_DIST);
325 		//Indent
326 		maFTIndent->SetPosPixel(POS_FT_PARA_INDENT);
327 		maTbxIndent_IncDec->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC);
328 		maTbxProDemote->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC);
329 		maLeftIndent->SetPosPixel(POS_MBX_LEFT_DIST);
330 		maRightIndent->SetPosPixel(POS_MBX_RIGHT_DIST);
331 		maFLineIndent->SetPosPixel(POS_MBX_FLINE_DIST);
332 		//Line spacing
333 		maLineSPTbx->SetPosPixel(TBX_LINE_SPACE);
334 		//image
335 		maFISpace1.SetPosPixel(POS_IMG_SPACE1);
336 		maFISpace2.SetPosPixel(POS_IMG_SPACE2);
337 		maFIndent1.SetPosPixel(POS_IMG_INDENT1);
338 		maFIndent2.SetPosPixel(POS_IMG_INDENT2);
339 		maFIndent3.SetPosPixel(POS_IMG_INDENT3);
340 		Size aSize(GetOutputSizePixel().Width(),PARA_SECTIONPAGE_HEIGHT);
341 		aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
342 		aSize.setWidth(GetOutputSizePixel().Width());
343 		SetSizePixel(aSize);
344 	}
345 	else
346 	{
347 		//Paragraph spacing
348 		maFTUL->SetPosPixel(POS_FT_PARA_SPACE2);
349 		maTbxUL_IncDec->SetPosPixel(POS_TBX_PARA_SPACE_INC_DEC2);
350 		maTopDist->SetPosPixel(POS_MBX_TOP_DIST2);
351 		maBottomDist->SetPosPixel(POS_MBX_BOT_DIST2);
352 		//Indent
353 		maFTIndent->SetPosPixel(POS_FT_PARA_INDENT2);
354 		maTbxIndent_IncDec->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC2);
355 		maTbxProDemote->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC2);
356 		maLeftIndent->SetPosPixel(POS_MBX_LEFT_DIST2);
357 		maRightIndent->SetPosPixel(POS_MBX_RIGHT_DIST2);
358 		maFLineIndent->SetPosPixel(POS_MBX_FLINE_DIST2);
359 		//Line spacing
360 		maLineSPTbx->SetPosPixel(TBX_LINE_SPACE2);
361 		//image
362 		maFISpace1.SetPosPixel(POS_IMG_SPACE12);
363 		maFISpace2.SetPosPixel(POS_IMG_SPACE22);
364 		maFIndent1.SetPosPixel(POS_IMG_INDENT12);
365 		maFIndent2.SetPosPixel(POS_IMG_INDENT22);
366 		maFIndent3.SetPosPixel(POS_IMG_INDENT32);
367 		Size aSize(GetOutputSizePixel().Width(),PARA_SECTIONPAGE_HEIGHT_2);
368 		aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
369 		aSize.setWidth(GetOutputSizePixel().Width());
370 		SetSizePixel(aSize);
371 	}
372 
373     if (mxSidebar.is())
374         mxSidebar->requestLayout();
375 }
376 
377 void ParaPropertyPanel::EndSpacingPopupMode (void)
378 {
379     maLineSpacePopup.Hide();
380 }
381 
382 void ParaPropertyPanel::EndBulletsPopupMode (void)
383 {
384 	//maUnderlinePopup.Hide();
385 }
386 
387 void ParaPropertyPanel::EndNumberingPopupMode (void)
388 {
389 	//maUnderlinePopup.Hide();
390 }
391 
392 
393 void ParaPropertyPanel::InitToolBoxAlign()
394 {
395 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM1,maLeftPara);
396 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM2,maCentPara);
397 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM3,maRightPara);
398 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM4,maJusPara);
399 	Link aLink = LINK( this, ParaPropertyPanel, AlignStyleModifyHdl_Impl );
400 	maAlignToolBox->SetSelectHdl( aLink );
401 	Size aTbxSize (maAlignToolBox->CalcWindowSizePixel());
402 	maAlignToolBox->SetOutputSizePixel( aTbxSize );
403 }
404 
405 void ParaPropertyPanel::InitToolBoxVertAlign()
406 {
407 	InitImageList(maTBxVertAlign, maVertImageList, maVertImageListH);
408 	maTBxVertAlign->SetSelectHdl(LINK(this,ParaPropertyPanel,VertTbxSelectHandler));
409 	Size aTbxSize (maTBxVertAlign->CalcWindowSizePixel());
410 	maTBxVertAlign->SetOutputSizePixel( aTbxSize );
411 }
412 
413 
414 void ParaPropertyPanel::InitToolBoxIndent()
415 {
416 	Link aLink = LINK( this, ParaPropertyPanel, ModifyIndentHdl_Impl );
417 	maLeftIndent->SetModifyHdl( aLink );
418 	maRightIndent->SetModifyHdl( aLink );
419 	maFLineIndent->SetModifyHdl( aLink );
420 
421 	if( Application::GetSettings().GetLayoutRTL())
422 	{
423 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM1,maIndInc_BD);
424 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM2,maIndDec_BD);
425 	}
426 	else
427 	{
428 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM1,maIndInc);
429 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM2,maIndDec);
430 	}
431 	maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM3,maIndHang);
432 	aLink = LINK( this, ParaPropertyPanel, ClickIndent_IncDec_Hdl_Impl );
433 	maTbxIndent_IncDec->SetSelectHdl(aLink);
434 	m_eLRSpaceUnit = maLRSpaceControl.GetCoreMetric();
435 	Size aTbxSize = maTbxIndent_IncDec->CalcWindowSizePixel();
436 	maTbxIndent_IncDec->SetOutputSizePixel( aTbxSize );
437 
438 	if( Application::GetSettings().GetLayoutRTL())
439 	{
440 		maTbxProDemote->SetItemImage(TOOLBOX_ITEM1,maIndInc_BD);
441 		maTbxProDemote->SetItemImage(TOOLBOX_ITEM2,maIndDec_BD);
442 	}
443 	else
444 	{
445 		maTbxProDemote->SetItemImage(TOOLBOX_ITEM1,maIndInc);
446 		maTbxProDemote->SetItemImage(TOOLBOX_ITEM2,maIndDec);
447 	}
448 	maTbxProDemote->SetItemImage(TOOLBOX_ITEM3,maIndHang);
449 	aLink = LINK( this, ParaPropertyPanel, ClickProDemote_Hdl_Impl );
450 	maTbxProDemote->SetSelectHdl(aLink);
451 	m_eLRSpaceUnit = maLRSpaceControl.GetCoreMetric();
452 	aTbxSize = maTbxProDemote->CalcWindowSizePixel();
453 	maTbxProDemote->SetOutputSizePixel( aTbxSize );
454 }
455 
456 void ParaPropertyPanel::InitToolBoxBGColor()
457 {
458 	mpColorUpdater.reset(new ::svx::ToolboxButtonColorUpdater(SID_BACKGROUND_COLOR, TBI_BACK_COLOR, maTBxBackColor.get(), TBX_UPDATER_MODE_CHAR_COLOR_NEW ));
459 
460 	maTBxBackColor->SetItemImage(TBI_BACK_COLOR, GetDisplayBackground().GetColor().IsDark()? maImgBackColorHigh : maImgBackColor);
461 	maTBxBackColor->SetItemBits( TBI_BACK_COLOR, maTBxBackColor->GetItemBits( TBI_BACK_COLOR ) | TIB_DROPDOWNONLY );
462 
463 	Link aLink = LINK(this, ParaPropertyPanel, ToolBoxBackColorDDHandler);
464 	maTBxBackColor->SetDropdownClickHdl ( aLink );
465 	maTBxBackColor->SetSelectHdl ( aLink );
466 	Size aTbxSize (maTBxBackColor->CalcWindowSizePixel());
467 	maTBxBackColor->SetOutputSizePixel( aTbxSize );
468 }
469 
470 void ParaPropertyPanel::InitToolBoxBulletsNumbering()
471 {
472 	if( Application::GetSettings().GetLayoutRTL())
473 	{
474 		maTBxNumBullet->SetItemImage( IID_BULLET, maNumBImageListRTL.GetImage( IID_BULLET ) );
475 		maTBxNumBullet->SetItemImage( IID_NUMBER, maNumBImageListRTL.GetImage( IID_NUMBER ) );
476 	}
477 	else
478 		InitImageList(maTBxNumBullet, maNumBImageList, maNumBImageListH);
479 
480 	maTBxNumBullet->SetDropdownClickHdl(LINK(this,ParaPropertyPanel,NumBTbxDDHandler));
481 	maTBxNumBullet->SetSelectHdl(LINK(this,ParaPropertyPanel,NumBTbxSelectHandler));
482 	Size aTbxSize (maTBxNumBullet->CalcWindowSizePixel());
483 	maTBxNumBullet->SetOutputSizePixel( aTbxSize );
484 }
485 void ParaPropertyPanel::InitToolBoxSpacing()
486 {
487 	Link aLink = LINK( this, ParaPropertyPanel, ULSpaceHdl_Impl );
488 	maTopDist->SetModifyHdl(aLink);
489 	maBottomDist->SetModifyHdl( aLink );
490 
491 	maTbxUL_IncDec->SetItemImage(TOOLBOX_ITEM1,maParInc);
492 	maTbxUL_IncDec->SetItemImage(TOOLBOX_ITEM2,maParDec);
493 	aLink = LINK( this, ParaPropertyPanel, ClickUL_IncDec_Hdl_Impl );
494 	maTbxUL_IncDec->SetSelectHdl(aLink);
495 	m_eULSpaceUnit = maULSpaceControl.GetCoreMetric();
496 	Size aTbxSize = maTbxUL_IncDec->CalcWindowSizePixel();
497 	maTbxUL_IncDec->SetOutputSizePixel( aTbxSize );
498 }
499 void ParaPropertyPanel::InitToolBoxLineSpacing()
500 {
501 	Link aLink = LINK( this, ParaPropertyPanel, ClickLineSPDropDownHdl_Impl );
502 	maLineSPTbx->SetDropdownClickHdl( aLink );
503 	maLineSPTbx->SetSelectHdl( aLink );		//support keyinput "ENTER"
504 	maLineSPTbx->SetItemBits( TOOLBOX_ITEM1, maLineSPTbx->GetItemBits( TOOLBOX_ITEM1 ) | TIB_DROPDOWNONLY );
505 	maLineSPTbx->SetItemImage(TOOLBOX_ITEM1,maSpace3);
506 	Size aTbxSize = maLineSPTbx->CalcWindowSizePixel();
507 	maLineSPTbx->SetOutputSizePixel( aTbxSize );
508 }
509 
510 void ParaPropertyPanel::initial()
511 {
512     maFTUL->SetBackground(Wallpaper());
513     maFTIndent->SetBackground(Wallpaper());
514     maFISpace1.SetBackground(Wallpaper());
515     maFISpace2.SetBackground(Wallpaper());
516     maFIndent1.SetBackground(Wallpaper());
517     maFIndent2.SetBackground(Wallpaper());
518     maFIndent3.SetBackground(Wallpaper());
519 
520     maFISpace1.SetImage(maSpace1);
521 	maFISpace2.SetImage(maSpace2);
522 	maFIndent1.SetImage(maIndent3);
523 	maFIndent2.SetImage(maIndent2);
524 	maFIndent3.SetImage(maIndent1);
525 
526 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_LEFT,sal_True,sal_False);
527 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_CENTER,sal_True,sal_False);
528 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_RIGHT,sal_True,sal_False);
529 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_BLOCK,sal_True,sal_False);
530 
531 	//toolbox
532 	SetupIcons();
533 	InitToolBoxAlign();
534 	InitToolBoxVertAlign();
535 	InitToolBoxIndent();
536 	InitToolBoxBGColor();
537 	InitToolBoxBulletsNumbering();
538 	InitToolBoxSpacing();
539 	InitToolBoxLineSpacing();
540 
541 #ifdef HAS_IA2
542 	maAlignToolBox->SetAccRelationLabeledBy(&maAlignToolBox);
543 	maTBxVertAlign->SetMpSubEditAccLableBy(&maTBxVertAlign);
544 	maTBxNumBullet->SetAccRelationLabeledBy(&maTBxNumBullet);
545 	maTBxBackColor->SetMpSubEditAccLableBy(&maTBxBackColor);
546 	maFTUL->SetAccRelationLabeledBy(&maFTUL);
547 	maTbxUL_IncDec->SetAccRelationLabeledBy(&maTbxUL_IncDec);
548 	maTopDist->SetAccRelationLabeledBy(&maTopDist);
549 	maBottomDist->SetAccRelationLabeledBy(&maBottomDist);
550 	maLineSPTbx->SetAccRelationLabeledBy(&maLineSPTbx);
551 	maFTIndent->SetAccRelationLabeledBy(&maFTIndent);
552 	maTbxIndent_IncDec->SetAccRelationLabeledBy(&maTbxIndent_IncDec);
553 	maTbxProDemote->SetAccRelationLabeledBy(&maTbxProDemote);
554 	maLeftIndent->SetAccRelationLabeledBy(&maLeftIndent);
555 	maRightIndent->SetAccRelationLabeledBy(&maRightIndent);
556 	maFLineIndent->SetAccRelationLabeledBy(&maFLineIndent);
557 	mpColorUpdater->SetAccRelationLabeledBy(&mpColorUpdater);
558 #endif
559 }
560 
561 void ParaPropertyPanel::InitImageList(::boost::scoped_ptr<ToolBox>& rTbx, ImageList& rImglst, ImageList& rImgHlst)
562 {
563 	sal_Bool bHighContrast = GetDisplayBackground().GetColor().IsDark();
564 
565     ImageList& rImgLst = bHighContrast ? rImgHlst : rImglst;
566 
567 	sal_uInt16 nCount = rTbx->GetItemCount();
568     for (sal_uInt16 i = 0; i < nCount; i++)
569     {
570     	sal_uInt16 nId = rTbx->GetItemId(i);
571 		rTbx->SetItemImage( nId, rImgLst.GetImage( nId ) );
572     }
573 }
574 
575 //===========================for Numbering & Bullet================================================
576 
577 
578 
579 IMPL_LINK(ParaPropertyPanel, NumBTbxDDHandler, ToolBox*, pToolBox)
580 {
581 	sal_uInt16 nId = pToolBox->GetCurItemId();
582 
583 	EndTracking();
584 	pToolBox->SetItemDown( nId, sal_True );
585 
586 	if (nId == 1)
587     {
588 		maBulletsPopup.UpdateValueSet();
589 		maBulletsPopup.Show(*pToolBox);
590 	}
591 	else if (nId == 2)
592 	{
593 		maNumberingPopup.UpdateValueSet();
594 		maNumberingPopup.Show(*pToolBox);
595 	}
596 	pToolBox->SetItemDown( nId, sal_False );
597 	return 0;
598 }
599 
600 IMPL_LINK(ParaPropertyPanel, NumBTbxSelectHandler, ToolBox*, pToolBox)
601 {
602 	sal_uInt16 nId = pToolBox->GetCurItemId();
603 	sal_uInt16 nSID = SID_TABLE_VERT_NONE;
604 
605 	EndTracking();
606 	if (nId == 1)
607     {
608 		nSID = FN_NUM_BULLET_ON;
609 	}
610 	else if ( nId == 2)
611 	{
612 		nSID = FN_NUM_NUMBERING_ON;
613 	}
614 	SfxBoolItem aBoolItem(nSID, sal_True);
615 	GetBindings()->GetDispatcher()->Execute(nSID, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
616 
617 	return 0;
618 }
619 
620 
621 //================================for Vertical Alignment========================================
622 
623 
624 
625 IMPL_LINK(ParaPropertyPanel, VertTbxSelectHandler, ToolBox*, pToolBox)
626 {
627 	sal_uInt16 nId = pToolBox->GetCurItemId();
628 	sal_uInt16 nSID = SID_TABLE_VERT_NONE;
629 	EndTracking();
630 	if (nId == 1)
631     {
632         nSID = SID_TABLE_VERT_NONE;
633 		maTBxVertAlign->SetItemState(1, STATE_CHECK);
634 		maTBxVertAlign->SetItemState(2, STATE_NOCHECK);
635 		maTBxVertAlign->SetItemState(3, STATE_NOCHECK);
636 	}
637 	else if (nId == 2)
638 	{
639 		nSID = SID_TABLE_VERT_CENTER;
640 		maTBxVertAlign->SetItemState(1, STATE_NOCHECK);
641 		maTBxVertAlign->SetItemState(2, STATE_CHECK);
642 		maTBxVertAlign->SetItemState(3, STATE_NOCHECK);
643 	}
644 	else if (nId == 3)
645 	{
646 		nSID = SID_TABLE_VERT_BOTTOM;
647 		maTBxVertAlign->SetItemState(1, STATE_NOCHECK);
648 		maTBxVertAlign->SetItemState(2, STATE_NOCHECK);
649 		maTBxVertAlign->SetItemState(3, STATE_CHECK);
650 	}
651 	SfxBoolItem aBoolItem(nSID, sal_True);
652 	GetBindings()->GetDispatcher()->Execute(nSID, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
653 
654 	return 0;
655 }
656 
657 void ParaPropertyPanel::VertStateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
658 {
659 	if (eState < SFX_ITEM_DONTCARE)
660 	{
661 		maTBxVertAlign->SetItemState(1, STATE_NOCHECK);
662 		maTBxVertAlign->SetItemState(2, STATE_NOCHECK);
663 		maTBxVertAlign->SetItemState(3, STATE_NOCHECK);
664 		maTBxVertAlign->EnableItem(1, sal_False);
665 		maTBxVertAlign->EnableItem(2, sal_False);
666 		maTBxVertAlign->EnableItem(3, sal_False);
667 	}
668 	else
669 	{
670 		maTBxVertAlign->EnableItem(1, sal_True);
671 		maTBxVertAlign->EnableItem(2, sal_True);
672 		maTBxVertAlign->EnableItem(3, sal_True);
673 		if ( (eState >= SFX_ITEM_DEFAULT) && (pState->ISA(SfxBoolItem)))
674 		{
675 			const SfxBoolItem* pItem= (const SfxBoolItem*)pState;
676 			sal_Bool aBool = (sal_Bool)pItem->GetValue();
677 
678 			if (aBool)
679 			{
680 				if (nSID == SID_TABLE_VERT_NONE)
681 				{
682 					maTBxVertAlign->SetItemState(1, STATE_CHECK);
683 					maTBxVertAlign->SetItemState(2, STATE_NOCHECK);
684 					maTBxVertAlign->SetItemState(3, STATE_NOCHECK);
685 				}
686 				else if (nSID == SID_TABLE_VERT_CENTER)
687 				{
688 					maTBxVertAlign->SetItemState(1, STATE_NOCHECK);
689 					maTBxVertAlign->SetItemState(2, STATE_CHECK);
690 					maTBxVertAlign->SetItemState(3, STATE_NOCHECK);
691 				}
692 				else if (nSID == SID_TABLE_VERT_BOTTOM)
693 				{
694 					maTBxVertAlign->SetItemState(1, STATE_NOCHECK);
695 					maTBxVertAlign->SetItemState(2, STATE_NOCHECK);
696 					maTBxVertAlign->SetItemState(3, STATE_CHECK);
697 				}
698 			}
699 			else
700 			{
701 				if (nSID == SID_TABLE_VERT_NONE)
702 				{
703 					maTBxVertAlign->SetItemState(1, STATE_NOCHECK);
704 				}
705 				else if (nSID == SID_TABLE_VERT_CENTER)
706 				{
707 					maTBxVertAlign->SetItemState(2, STATE_NOCHECK);
708 				}
709 				else if (nSID == SID_TABLE_VERT_BOTTOM)
710 				{
711 					maTBxVertAlign->SetItemState(3, STATE_NOCHECK);
712 				}
713 			}
714 		}
715 		else
716 		{
717 			maTBxVertAlign->SetItemState(1, STATE_NOCHECK);
718 			maTBxVertAlign->SetItemState(2, STATE_NOCHECK);
719 			maTBxVertAlign->SetItemState(3, STATE_NOCHECK);
720 		}
721 	}
722 }
723 //==================================for Background color=====================
724 
725 IMPL_LINK(ParaPropertyPanel, ToolBoxBackColorDDHandler,ToolBox*, pToolBox)
726 {
727 	sal_uInt16 nId = pToolBox->GetCurItemId();
728 	OSL_ASSERT(nId == TBI_BACK_COLOR);
729 	if(nId == TBI_BACK_COLOR)
730 	{
731 		pToolBox->SetItemDown( nId, true );
732 		maBGColorPopup.Show(*pToolBox);
733 		maBGColorPopup.SetCurrentColor(maColor, mbColorAvailable);
734 	}
735 	return 0;
736 }
737 
738 IMPL_LINK( ParaPropertyPanel, ImplPopupModeEndHdl, FloatingWindow*, EMPTYARG )
739 {
740 	return 0;
741 }
742 
743 void ParaPropertyPanel::ShowMenu (void)
744 {
745     if (mpBindings != NULL)
746     {
747         SfxDispatcher* pDispatcher = mpBindings->GetDispatcher();
748         if (pDispatcher != NULL)
749             pDispatcher->Execute(SID_PARA_DLG, SFX_CALLMODE_ASYNCHRON);
750     }
751 }
752 
753 void ParaPropertyPanel::ParaBKGStateChanged(sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState)
754 {
755 	if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxColorItem))
756 	{
757 		const SvxColorItem* pItem =  (const SvxColorItem*)pState;
758 		maColor = pItem->GetValue();
759 		mbColorAvailable = sal_True;
760 		mpColorUpdater->Update(maColor);
761 	}
762 	else
763 	{
764 		mbColorAvailable = sal_False;
765 		maColor.SetColor(COL_AUTO);
766 		mpColorUpdater->Update(maColor);
767 	}
768 }
769 
770 Color ParaPropertyPanel::GetBGColor (void) const
771 {
772     return maColor;
773 }
774 
775 void ParaPropertyPanel::SetBGColor (
776     const String& /* rsColorName */,
777     const Color aColor)
778 {
779 	SvxColorItem aColorItem(aColor, SID_BACKGROUND_COLOR);
780 	mpBindings->GetDispatcher()->Execute(SID_BACKGROUND_COLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
781 	maColor = aColor;
782 }
783 
784 //==================================for Paragraph Alignment=====================
785 IMPL_LINK( ParaPropertyPanel, AlignStyleModifyHdl_Impl, ToolBox*, pBox )
786 {
787 	switch (pBox->GetCurItemId())
788 	{
789 	case BT_SUBSTLEFT:
790 		{
791 			pBox->SetItemState(BT_SUBSTLEFT,STATE_CHECK);
792 			pBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
793 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
794 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
795 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_LEFT,  sal_True );
796 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_LEFT, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
797 		}
798 		break;
799 	case BT_SUBSTCENTER:
800 		{
801 			pBox->SetItemState(BT_SUBSTCENTER,STATE_CHECK);
802 			pBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
803 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
804 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
805 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_CENTER, sal_True );
806 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_CENTER, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
807 		}
808 		break;
809 	case BT_SUBSTRIGHT:
810 		{
811 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_CHECK);
812 			pBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
813 			pBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
814 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
815 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_RIGHT, sal_True );
816 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_RIGHT, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
817 		}
818 		break;
819 	case BT_SUBSTJUSTIFY:
820 		{
821 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_CHECK);
822 			pBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
823 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
824 			pBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
825 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_BLOCK, sal_True );
826 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_BLOCK, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
827 		}
828 		break;
829 	}
830 
831 	return 0;
832 }
833 //==================================for Paragraph Indent=====================
834 IMPL_LINK( ParaPropertyPanel, ModifyIndentHdl_Impl, SvxRelativeField*, /* pBox */ )
835 {
836 	SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
837 	aMargin.SetTxtLeft( (const long)GetCoreValue( *maLeftIndent.get(), m_eLRSpaceUnit ) );
838 	aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
839 	aMargin.SetTxtFirstLineOfst( (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
840 
841 	GetBindings()->GetDispatcher()->Execute(
842 		SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
843 	return 0;
844 }
845 
846 IMPL_LINK(ParaPropertyPanel, ClickIndent_IncDec_Hdl_Impl, ToolBox *, pControl)
847 {
848 	switch (pControl->GetCurItemId())
849 	{
850 		case INDENT_INCREMENT:
851 		{
852 			switch (maContext.GetCombinedContext())
853 			{
854 				case CombinedEnumContext(Application_Writer, Context_Default):
855 				case CombinedEnumContext(Application_Writer, Context_Text):
856 				case CombinedEnumContext(Application_Writer, Context_Table):
857 				{
858 					SfxBoolItem aMargin( SID_INC_INDENT, sal_True );
859 					GetBindings()->GetDispatcher()->Execute(
860 						SID_INC_INDENT, SFX_CALLMODE_RECORD, &aMargin, 0L);
861 				}
862 				break;
863 				default:
864 				{
865 					SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
866 
867 					maTxtLeft += INDENT_STEP;
868 					sal_Int64 nVal = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
869 					nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
870 					aMargin.SetTxtLeft( (const long)nVal );
871 					aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
872 					aMargin.SetTxtFirstLineOfst( (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
873 
874 					GetBindings()->GetDispatcher()->Execute(
875 						SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
876 				}
877 			}
878 		}
879 		break;
880 		case INDENT_DECREMENT:
881 		{
882 			switch (maContext.GetCombinedContext())
883 			{
884 				case CombinedEnumContext(Application_Writer, Context_Default):
885 				case CombinedEnumContext(Application_Writer, Context_Text):
886 				case CombinedEnumContext(Application_Writer, Context_Table):
887 				{
888 					SfxBoolItem aMargin( SID_DEC_INDENT, sal_True );
889 					GetBindings()->GetDispatcher()->Execute(
890 						SID_DEC_INDENT, SFX_CALLMODE_RECORD, &aMargin, 0L);
891 				}
892 				break;
893 				default:
894 				{
895 					if((maTxtLeft - INDENT_STEP) < 0)
896 						maTxtLeft = DEFAULT_VALUE;
897 					else
898 						maTxtLeft -= INDENT_STEP;
899 
900 					SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
901 
902 					sal_Int64 nVal = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
903 					nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
904 
905 					aMargin.SetTxtLeft( (const long)nVal );
906 					aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
907 					aMargin.SetTxtFirstLineOfst( (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
908 
909 					GetBindings()->GetDispatcher()->Execute(
910 						SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
911 				}
912 			}
913 		}
914 		break;
915 		case ID_HANGING_INDENT:
916 		{
917 			SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
918 			aMargin.SetTxtLeft( (const long)GetCoreValue( *maLeftIndent.get(), m_eLRSpaceUnit ) + (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
919 			aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
920 			aMargin.SetTxtFirstLineOfst( ((const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ))*(-1) );
921 
922 			GetBindings()->GetDispatcher()->Execute(
923 				SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
924 		}
925 		break;
926 	}
927 	return( 0L );
928 }
929 
930 IMPL_LINK(ParaPropertyPanel, ClickProDemote_Hdl_Impl, ToolBox *, pControl)
931 {
932     switch (pControl->GetCurItemId())
933     {
934         case BT_TBX_INDENT_PROMOTE:
935         {
936             GetBindings()->GetDispatcher()->Execute( SID_OUTLINE_RIGHT, SFX_CALLMODE_RECORD );
937         }
938         break;
939         case BT_TBX_INDENT_DEMOTE:
940         {
941             GetBindings()->GetDispatcher()->Execute( SID_OUTLINE_LEFT, SFX_CALLMODE_RECORD );
942         }
943         break;
944         case SD_HANGING_INDENT:
945         {
946             SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
947             aMargin.SetTxtLeft( (const long)GetCoreValue( *maLeftIndent.get(), m_eLRSpaceUnit ) + (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
948             aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
949             aMargin.SetTxtFirstLineOfst( ((const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ))*(-1) );
950 
951             GetBindings()->GetDispatcher()->Execute( SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
952         }
953         break;
954     }
955     return( 0L );
956 }
957 //==================================for Paragraph Line Spacing=====================
958 
959 IMPL_LINK( ParaPropertyPanel, ClickLineSPDropDownHdl_Impl, ToolBox*, pBox )
960 {
961 
962 	const sal_uInt16 nId = pBox->GetCurItemId();
963 	OSL_ASSERT(nId == TOOLBOX_ITEM1);
964 	if(nId == TOOLBOX_ITEM1)
965 	{
966 		pBox->SetItemDown( nId, true );
967 		maLineSpacePopup.Rearrange(meLnSpState,m_eMetricUnit,mpLnSPItem,maContext);
968 		maLineSpacePopup.Show(*pBox);
969 
970 	}
971 	return (0L);
972 }
973 
974 //==================================for Paragraph Spacing=====================
975 IMPL_LINK( ParaPropertyPanel, ULSpaceHdl_Impl, SvxRelativeField*, /* pBox */)
976 {
977 	SvxULSpaceItem aMargin( SID_ATTR_PARA_ULSPACE );
978 	aMargin.SetUpper( (sal_uInt16)GetCoreValue( *maTopDist.get(), m_eULSpaceUnit ) );
979 	aMargin.SetLower( (sal_uInt16)GetCoreValue( *maBottomDist.get(), m_eULSpaceUnit ) );
980 
981 	GetBindings()->GetDispatcher()->Execute(
982 		SID_ATTR_PARA_ULSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
983 	return 0L;
984 }
985 
986 IMPL_LINK(ParaPropertyPanel, ClickUL_IncDec_Hdl_Impl, ToolBox *, pControl)
987 {
988 	switch (pControl->GetCurItemId())
989 		{
990 	    case UL_INCREMENT:
991 		     {
992 				 SvxULSpaceItem aMargin( SID_ATTR_PARA_ULSPACE );
993 
994 				 maUpper += UL_STEP;
995 				 sal_Int64 nVal = OutputDevice::LogicToLogic( maUpper, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
996 				 nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
997 				 aMargin.SetUpper( (const sal_uInt16)nVal );
998 
999 				 maLower += UL_STEP;
1000 				 nVal = OutputDevice::LogicToLogic( maLower, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1001 				 nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
1002 	             aMargin.SetLower( (const sal_uInt16)nVal );
1003 
1004 				 GetBindings()->GetDispatcher()->Execute(
1005 					 SID_ATTR_PARA_ULSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
1006 			 }
1007 			 break;
1008 		case UL_DECREMENT:
1009 			{
1010 				 SvxULSpaceItem aMargin( SID_ATTR_PARA_ULSPACE );
1011 
1012 				 if( maUpper >= UL_STEP )
1013 				 {
1014 					maUpper -= UL_STEP;
1015 					sal_Int64	nVal = OutputDevice::LogicToLogic( maUpper, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1016 					nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
1017 					aMargin.SetUpper( (const sal_uInt16)nVal );
1018 				 }
1019 				 else
1020 					aMargin.SetUpper( DEFAULT_VALUE );
1021 				 if( maLower >= UL_STEP )
1022 				 {
1023 					maLower -= UL_STEP;
1024 					sal_Int64	nVal = OutputDevice::LogicToLogic( maLower, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1025 					nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
1026 					aMargin.SetLower( (const sal_uInt16)nVal );
1027 				 }
1028 				 else
1029 					aMargin.SetLower( DEFAULT_VALUE );
1030 
1031 				 GetBindings()->GetDispatcher()->Execute(
1032 					 SID_ATTR_PARA_ULSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
1033 			}
1034 			break;
1035 		}
1036 	return( 0L );
1037 }
1038 
1039 //==================================for Paragraph State change=====================
1040 void ParaPropertyPanel::NotifyItemUpdate( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1041 {
1042 	if( nSID == SID_ATTR_METRIC )
1043 	{
1044 		m_eMetricUnit = GetCurrentUnit(eState,pState);
1045 		if( m_eMetricUnit!=m_last_eMetricUnit )
1046 		{
1047 			SetFieldUnit( *maLeftIndent.get(), m_eMetricUnit );
1048 			SetFieldUnit( *maRightIndent.get(), m_eMetricUnit );
1049 			SetFieldUnit( *maFLineIndent.get(), m_eMetricUnit );
1050 			SetFieldUnit( *maTopDist.get(), m_eMetricUnit );
1051 			SetFieldUnit( *maBottomDist.get(), m_eMetricUnit );
1052 		}
1053 		m_last_eMetricUnit = m_eMetricUnit;
1054 	}
1055 
1056 	if( nSID == SID_ATTR_PARA_LRSPACE )
1057 		StateChangedIndentImpl( nSID, eState, pState );
1058 
1059 	if( nSID == SID_ATTR_PARA_LINESPACE )
1060 		StateChangedLnSPImpl( nSID, eState, pState );
1061 
1062 	if( nSID == SID_ATTR_PARA_ULSPACE)
1063 		StateChangedULImpl( nSID, eState, pState );
1064 
1065 	if (nSID==SID_ATTR_PARA_ADJUST_LEFT || nSID==SID_ATTR_PARA_ADJUST_CENTER || nSID==SID_ATTR_PARA_ADJUST_RIGHT || nSID==SID_ATTR_PARA_ADJUST_BLOCK)
1066 		StateChangedAlignmentImpl( nSID, eState, pState );
1067 
1068 	if (nSID==SID_OUTLINE_LEFT || nSID==SID_OUTLINE_RIGHT)
1069 		StateChangeOutLineImpl( nSID, eState, pState );
1070 
1071 	if (nSID==SID_INC_INDENT || nSID==SID_DEC_INDENT)
1072 		StateChangeIncDecImpl( nSID, eState, pState );
1073 	// Add toggle state for numbering and bullet icons
1074 	if (nSID==FN_NUM_NUMBERING_ON || nSID==FN_NUM_BULLET_ON)
1075 		StateChangeBulletNumImpl( nSID, eState, pState );
1076 
1077 	//Get the num rule index data of the current selection
1078 	if ( nSID == FN_BUL_NUM_RULE_INDEX ||nSID == FN_NUM_NUM_RULE_INDEX)
1079 		StateChangeBulletNumRuleImpl( nSID, eState, pState );
1080 
1081 	if ((nSID == SID_TABLE_VERT_NONE)||(nSID == SID_TABLE_VERT_CENTER)||(nSID == SID_TABLE_VERT_BOTTOM))
1082 	{
1083 		VertStateChanged( nSID, eState, pState);
1084 	}
1085 	else if (nSID == SID_BACKGROUND_COLOR)
1086 	{
1087 		ParaBKGStateChanged(nSID, eState, pState);
1088 	}
1089 }
1090 
1091 void ParaPropertyPanel::StateChangedAlignmentImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1092 {
1093 	if( eState >= SFX_ITEM_AVAILABLE )
1094 	{
1095 		const SfxBoolItem* pItem = (const SfxBoolItem*)pState;
1096 		bool IsChecked = (bool)pItem->GetValue();
1097 		switch (nSID)
1098 		{
1099 		case SID_ATTR_PARA_ADJUST_LEFT:
1100 			{
1101 				if(IsChecked)
1102 				{
1103 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_CHECK);
1104 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1105 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1106 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1107 				}
1108 				else
1109 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1110 			}
1111 			break;
1112 		case SID_ATTR_PARA_ADJUST_CENTER:
1113 			{
1114 				if(IsChecked)
1115 				{
1116 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_CHECK);
1117 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1118 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1119 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1120 				}
1121 				else
1122 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1123 			}
1124 			break;
1125 		case SID_ATTR_PARA_ADJUST_RIGHT:
1126 			{
1127 				if(IsChecked)
1128 				{
1129 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_CHECK);
1130 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1131 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1132 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1133 				}
1134 				else
1135 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1136 			}
1137 			break;
1138 		case SID_ATTR_PARA_ADJUST_BLOCK:
1139 			{
1140 				if(IsChecked)
1141 				{
1142 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_CHECK);
1143 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1144 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1145 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1146 				}
1147 				else
1148 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1149 			}
1150 			break;
1151 		}
1152 	}
1153 	else if( eState == SFX_ITEM_DISABLED )
1154 	{
1155 	}
1156 	else if ( eState == SFX_ITEM_DONTCARE )
1157 	{
1158 		switch (nSID)
1159 		{
1160 		case SID_ATTR_PARA_ADJUST_LEFT:
1161 			maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1162 			break;
1163 		case SID_ATTR_PARA_ADJUST_CENTER:
1164 			maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1165 			break;
1166 		case SID_ATTR_PARA_ADJUST_RIGHT:
1167 			maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1168 			break;
1169 		case SID_ATTR_PARA_ADJUST_BLOCK:
1170 			maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1171 			break;
1172 		}
1173 	}
1174 }
1175 
1176 void ParaPropertyPanel::StateChangedIndentImpl( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
1177 {
1178 	switch (maContext.GetCombinedContext())
1179 	{
1180 
1181 		case CombinedEnumContext(Application_Writer, Context_DrawText):
1182 		case CombinedEnumContext(Application_Calc, Context_DrawText):
1183 		case CombinedEnumContext(Application_Writer, Context_Annotation):
1184 		{
1185 			maLeftIndent->SetMin( DEFAULT_VALUE );
1186 			maRightIndent->SetMin( DEFAULT_VALUE );
1187 			maFLineIndent->SetMin( DEFAULT_VALUE );
1188 			maTbxIndent_IncDec->Show();
1189 			maTbxProDemote->Hide();
1190 		}
1191 		break;
1192 		case CombinedEnumContext(Application_Draw, Context_DrawText):
1193         	case CombinedEnumContext(Application_Impress, Context_DrawText):
1194 		case CombinedEnumContext(Application_Draw, Context_Draw):
1195 		case CombinedEnumContext(Application_Draw, Context_TextObject):
1196 		case CombinedEnumContext(Application_Draw, Context_Graphic):
1197 		case CombinedEnumContext(Application_Impress, Context_Draw):
1198 		case CombinedEnumContext(Application_Impress, Context_TextObject):
1199 		case CombinedEnumContext(Application_Impress, Context_Graphic):
1200 		case CombinedEnumContext(Application_Impress, Context_Table):
1201         	case CombinedEnumContext(Application_Draw, Context_Table):
1202 		{
1203     		maLeftIndent->SetMin( DEFAULT_VALUE );
1204 			maRightIndent->SetMin( DEFAULT_VALUE );
1205 			maFLineIndent->SetMin( DEFAULT_VALUE );
1206 			maTbxIndent_IncDec->Hide();
1207 			maTbxProDemote->Show();
1208 		}
1209 		break;
1210 		case CombinedEnumContext(Application_Writer, Context_Default):
1211 		case CombinedEnumContext(Application_Writer, Context_Text):
1212 		case CombinedEnumContext(Application_Writer, Context_Table):
1213 		{
1214 			maLeftIndent->SetMin( NEGA_MAXVALUE, FUNIT_100TH_MM );
1215 			maRightIndent->SetMin( NEGA_MAXVALUE, FUNIT_100TH_MM );
1216 			maFLineIndent->SetMin( NEGA_MAXVALUE, FUNIT_100TH_MM );
1217 			maTbxIndent_IncDec->Show();
1218 			maTbxProDemote->Hide();
1219 		}
1220 		break;
1221 	}
1222 
1223 	if( pState && eState >= SFX_ITEM_AVAILABLE )
1224 	{
1225 		SvxLRSpaceItem* pSpace = ( SvxLRSpaceItem*)pState;
1226 		maTxtLeft = pSpace->GetTxtLeft();
1227 		maTxtLeft = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)m_eLRSpaceUnit, MAP_100TH_MM );
1228 		maTxtLeft = OutputDevice::LogicToLogic( maTxtLeft, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1229 
1230 		long aTxtRight = pSpace->GetRight();
1231 		aTxtRight = OutputDevice::LogicToLogic( aTxtRight, (MapUnit)m_eLRSpaceUnit, MAP_100TH_MM );
1232 		aTxtRight = OutputDevice::LogicToLogic( aTxtRight, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1233 
1234 		long aTxtFirstLineOfst = pSpace->GetTxtFirstLineOfst();
1235 		aTxtFirstLineOfst = OutputDevice::LogicToLogic( aTxtFirstLineOfst, (MapUnit)m_eLRSpaceUnit, MAP_100TH_MM );
1236 		aTxtFirstLineOfst = OutputDevice::LogicToLogic( aTxtFirstLineOfst, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1237 
1238 		long nVal = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1239 		nVal = (long)maLeftIndent->Normalize( (long)nVal );
1240 		maLeftIndent->SetValue( nVal, FUNIT_100TH_MM );
1241 
1242 		if(maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Text) &&
1243 			maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Default) &&
1244 			maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Table))
1245 		{
1246 			maFLineIndent->SetMin( nVal*(-1), FUNIT_100TH_MM );
1247 		}
1248 
1249 		long nrVal = OutputDevice::LogicToLogic( aTxtRight, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1250 		nrVal = (long)maRightIndent->Normalize( (long)nrVal );
1251 	    maRightIndent->SetValue( nrVal, FUNIT_100TH_MM );
1252 
1253 		long nfVal = OutputDevice::LogicToLogic( aTxtFirstLineOfst, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1254 		nfVal = (long)maFLineIndent->Normalize( (long)nfVal );
1255 		maFLineIndent->SetValue( nfVal, FUNIT_100TH_MM );
1256 
1257 		switch (maContext.GetCombinedContext())
1258 		{
1259 			case CombinedEnumContext(Application_Writer, Context_DrawText):
1260 			case CombinedEnumContext(Application_Writer, Context_Text):
1261 			case CombinedEnumContext(Application_Writer, Context_Default):
1262 			case CombinedEnumContext(Application_Writer, Context_Table):
1263 			case CombinedEnumContext(Application_Writer, Context_Annotation):
1264 			{
1265 				maLeftIndent->SetMax( MAX_SW - nrVal, FUNIT_100TH_MM );
1266 				maRightIndent->SetMax( MAX_SW - nVal, FUNIT_100TH_MM );
1267 				maFLineIndent->SetMax( MAX_SW - nVal - nrVal, FUNIT_100TH_MM );
1268 			}
1269 			break;
1270 			case CombinedEnumContext(Application_Draw, Context_DrawText):
1271 			case CombinedEnumContext(Application_Draw, Context_Draw):
1272         		case CombinedEnumContext(Application_Draw, Context_Table):
1273 			case CombinedEnumContext(Application_Draw, Context_TextObject):
1274 			case CombinedEnumContext(Application_Draw, Context_Graphic):
1275 			case CombinedEnumContext(Application_Impress, Context_TextObject):
1276         		case CombinedEnumContext(Application_Impress, Context_DrawText):
1277 			case CombinedEnumContext(Application_Impress, Context_Table):
1278 			case CombinedEnumContext(Application_Impress, Context_Draw):
1279 			case CombinedEnumContext(Application_Impress, Context_Graphic):
1280 			{
1281 				maLeftIndent->SetMax( MAX_SC_SD - nrVal, FUNIT_100TH_MM );
1282 				maRightIndent->SetMax( MAX_SC_SD - nVal, FUNIT_100TH_MM );
1283 				maFLineIndent->SetMax( MAX_SC_SD - nVal - nrVal, FUNIT_100TH_MM );
1284 			}
1285 		}
1286 
1287 		maTbxIndent_IncDec->Enable();
1288 		maTbxIndent_IncDec->EnableItem(ID_HANGING_INDENT, sal_True);
1289 		if(maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Text)
1290 			&& maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Default)
1291 			&& maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Table))
1292 		{
1293 			maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_INC, sal_True);
1294 			maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_DEC, sal_True);
1295 		}
1296 
1297 //		maTbxProDemote->Enable();
1298 //		if( !mbOutLineRight && !mbOutLineLeft )
1299 //			maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_True);
1300 		maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_True);
1301 	}
1302 	else if( eState == SFX_ITEM_DISABLED )
1303 	{
1304 		maLeftIndent-> Disable();
1305 		maRightIndent->Disable();
1306 		maFLineIndent->Disable();
1307 		maTbxIndent_IncDec->Disable();
1308 		if( maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Text)  &&
1309 			maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Default) &&
1310 			maContext.GetCombinedContext() !=  CombinedEnumContext(Application_Writer, Context_Table) )
1311 			maTbxIndent_IncDec->Disable();
1312 		else
1313 			maTbxIndent_IncDec->EnableItem(ID_HANGING_INDENT, sal_False);
1314 
1315 //		maTbxProDemote->Disable();
1316 		maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_False);
1317 	}
1318 	else
1319 	{
1320 		maLeftIndent->SetEmptyFieldValue();
1321 		maRightIndent->SetEmptyFieldValue();
1322 		maFLineIndent->SetEmptyFieldValue();
1323 		if( maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Text)  &&
1324 			maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Default) &&
1325 			maContext.GetCombinedContext() !=  CombinedEnumContext(Application_Writer, Context_Table) )
1326 			maTbxIndent_IncDec->Disable();
1327 		else
1328 			maTbxIndent_IncDec->EnableItem(ID_HANGING_INDENT, sal_False);
1329 //		maTbxProDemote->Disable();
1330 		maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_False);
1331 	}
1332 }
1333 
1334 void ParaPropertyPanel::StateChangedLnSPImpl( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
1335 {
1336 	meLnSpState = eState;
1337 
1338 	if( pState && eState >= SFX_ITEM_AVAILABLE )
1339 	{
1340 		if(mpLnSPItem)
1341 			delete mpLnSPItem;
1342 		mpLnSPItem = ( SvxLineSpacingItem *)pState->Clone();
1343 	}
1344 }
1345 
1346 void ParaPropertyPanel::StateChangedULImpl( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
1347 {
1348 	maTopDist->SetMax( maTopDist->Normalize( MAX_DURCH ), MapToFieldUnit(m_eULSpaceUnit) );
1349 	maBottomDist->SetMax( maBottomDist->Normalize( MAX_DURCH ), MapToFieldUnit(m_eULSpaceUnit) );
1350 
1351 	if( pState && eState >= SFX_ITEM_AVAILABLE )
1352 	{
1353 		SvxULSpaceItem* pOldItem = (SvxULSpaceItem*)pState;
1354 
1355 		maUpper = pOldItem->GetUpper();
1356 		maUpper = OutputDevice::LogicToLogic( maUpper, (MapUnit)m_eULSpaceUnit, MAP_100TH_MM );
1357 		maUpper = OutputDevice::LogicToLogic( maUpper, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1358 
1359 		maLower = pOldItem->GetLower();
1360 		maLower = OutputDevice::LogicToLogic( maLower, (MapUnit)m_eULSpaceUnit, MAP_100TH_MM );
1361 		maLower = OutputDevice::LogicToLogic( maLower, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1362 
1363 		sal_Int64 nVal = OutputDevice::LogicToLogic( maUpper, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1364 		nVal = maTopDist->Normalize( nVal );
1365 		maTopDist->SetValue( nVal, FUNIT_100TH_MM );
1366 
1367 		nVal = OutputDevice::LogicToLogic( maLower, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1368 		nVal = maBottomDist->Normalize( nVal );
1369 		maBottomDist->SetValue( nVal, FUNIT_100TH_MM );
1370 		maTbxUL_IncDec->Enable();
1371 	}
1372 	else if(eState == SFX_ITEM_DISABLED )
1373 	{
1374 		maTopDist->Disable();
1375 		maBottomDist->Disable();
1376 		maTbxUL_IncDec->Disable();
1377 	}
1378 	else
1379 	{
1380 		maTopDist->SetEmptyFieldValue();
1381 		maBottomDist->SetEmptyFieldValue();
1382 		maTbxUL_IncDec->Disable();
1383 	}
1384 }
1385 
1386 void ParaPropertyPanel::StateChangeOutLineImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1387 {
1388     if (nSID==SID_OUTLINE_LEFT)
1389 	{
1390 		if( pState && eState == SFX_ITEM_UNKNOWN )
1391 			mbOutLineLeft = 1;
1392 		else
1393 			mbOutLineLeft = 0;
1394 	}
1395 	if (nSID==SID_OUTLINE_RIGHT)
1396 	{
1397 		if( pState && eState == SFX_ITEM_UNKNOWN )
1398 			mbOutLineRight = 1;
1399 		else
1400 			mbOutLineRight = 0;
1401 	}
1402 	if(mbOutLineLeft)
1403 		maTbxProDemote->EnableItem(BT_TBX_INDENT_DEMOTE, sal_True);
1404 	else
1405 		maTbxProDemote->EnableItem(BT_TBX_INDENT_DEMOTE, sal_False);
1406 
1407 	if(mbOutLineRight)
1408 		maTbxProDemote->EnableItem(BT_TBX_INDENT_PROMOTE, sal_True);
1409 	else
1410 		maTbxProDemote->EnableItem(BT_TBX_INDENT_PROMOTE, sal_False);
1411 
1412 //	if( !mbOutLineRight && !mbOutLineLeft )
1413 //	{
1414 //		maTbxProDemote->EnableItem(BT_TBX_INDENT_PROMOTE, sal_True);
1415 //		maTbxProDemote->EnableItem(BT_TBX_INDENT_DEMOTE, sal_True);
1416 //		maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_True);
1417 //	}
1418 //	else
1419 //		maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_False);
1420 }
1421 
1422 void ParaPropertyPanel::StateChangeIncDecImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1423 {
1424 	if (nSID==SID_INC_INDENT)
1425 	{
1426 		if( pState && eState == SFX_ITEM_UNKNOWN )
1427 			maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_INC, sal_True);
1428 		else
1429 			if( maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Text)  &&
1430 				maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Default) &&
1431 			maContext.GetCombinedContext() !=  CombinedEnumContext(Application_Writer, Context_Table) )
1432 				maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_INC, sal_False);
1433 	}
1434 	if (nSID==SID_DEC_INDENT)
1435 	{
1436 		if( pState && eState == SFX_ITEM_UNKNOWN )
1437 			maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_DEC, sal_True);
1438 		else
1439 			if( maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Text)  &&
1440 				maContext.GetCombinedContext() != CombinedEnumContext(Application_Writer, Context_Default) &&
1441 			maContext.GetCombinedContext() !=  CombinedEnumContext(Application_Writer, Context_Table) )
1442 				maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_DEC, sal_False);
1443 	}
1444 }
1445 // Add toggle state for numbering and bullet icons
1446 void ParaPropertyPanel::StateChangeBulletNumImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1447 {
1448 	if (nSID==FN_NUM_NUMBERING_ON)
1449 	{
1450 		if ( (eState >= SFX_ITEM_DEFAULT) && (pState->ISA(SfxBoolItem)))
1451 		{
1452 			const SfxBoolItem* pItem= (const SfxBoolItem*)pState;
1453 			sal_Bool aBool = (sal_Bool)pItem->GetValue();
1454 			if (aBool) {
1455 				maTBxNumBullet->SetItemState(IID_NUMBER,	STATE_CHECK);
1456 			} else {
1457 				maTBxNumBullet->SetItemState(IID_NUMBER,	STATE_NOCHECK);
1458 			}
1459 		}
1460 	}
1461 	if (nSID==FN_NUM_BULLET_ON)
1462 	{
1463 		if ( (eState >= SFX_ITEM_DEFAULT) && (pState->ISA(SfxBoolItem)))
1464 		{
1465 			const SfxBoolItem* pItem= (const SfxBoolItem*)pState;
1466 			sal_Bool aBool = (sal_Bool)pItem->GetValue();
1467 			if (aBool) {
1468 				maTBxNumBullet->SetItemState(IID_BULLET,	STATE_CHECK);
1469 			} else {
1470 				maTBxNumBullet->SetItemState(IID_BULLET,	STATE_NOCHECK);
1471 			}
1472 		}
1473 	}
1474 }
1475 //Modified for Numbering&Bullets Dialog UX Enh(Story 992) by chengjh,2011.7.5
1476 //Handing the transferred the num rule index data of the current selection
1477 void ParaPropertyPanel::StateChangeBulletNumRuleImpl( sal_uInt16 nSID, SfxItemState /* eState */, const SfxPoolItem* pState )
1478 {
1479 
1480 	const SfxUInt16Item* pIt = (const SfxUInt16Item*)pState;
1481 	sal_uInt16 nValue = (sal_uInt16)0xFFFF;
1482 	if ( pIt )
1483 		nValue = pIt->GetValue();
1484 
1485 	if ( nSID == FN_BUL_NUM_RULE_INDEX )
1486 	{
1487 		mnBulletTypeIndex = nValue;
1488 	}else if ( nSID == FN_NUM_NUM_RULE_INDEX )
1489 	{
1490 		mnNumTypeIndex = nValue;
1491 	}
1492 }
1493 //End
1494 FieldUnit ParaPropertyPanel::GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState )
1495 {
1496 	FieldUnit eUnit = FUNIT_NONE;
1497 
1498 	if ( pState && eState >= SFX_ITEM_DEFAULT )
1499 		eUnit = (FieldUnit)( (const SfxUInt16Item*)pState )->GetValue();
1500 	else
1501 	{
1502 		SfxViewFrame* pFrame = SfxViewFrame::Current();
1503 		SfxObjectShell* pSh = NULL;
1504 		if ( pFrame )
1505 			pSh = pFrame->GetObjectShell();
1506 		if ( pSh )  //the object shell is not always available during reload
1507 		{
1508 			SfxModule* pModule = pSh->GetModule();
1509 			if ( pModule )
1510 			{
1511 				const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
1512 				if ( pItem )
1513 					eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
1514 			}
1515 			else
1516 			{
1517 				DBG_ERRORFILE( "GetModuleFieldUnit(): no module found" );
1518 			}
1519 		}
1520 	}
1521 
1522 	return eUnit;
1523 }
1524 //new FixedText(this, SVX_RES(FT_COLOR))
1525 
1526 PopupControl* ParaPropertyPanel::CreateLineSpacingControl (PopupContainer* pParent)
1527 {
1528 	return new ParaLineSpacingControl(pParent, *this);
1529 }
1530 
1531 PopupControl* ParaPropertyPanel::CreateBulletsPopupControl (PopupContainer* pParent)
1532 {
1533 	return new ParaBulletsControl(pParent, *this);
1534 }
1535 
1536 PopupControl* ParaPropertyPanel::CreateNumberingPopupControl (PopupContainer* pParent)
1537 {
1538 	return new ParaNumberingControl(pParent, *this);
1539 }
1540 
1541 PopupControl* ParaPropertyPanel::CreateBGColorPopupControl (PopupContainer* pParent)
1542 {
1543 	return new ColorControl(
1544         pParent,
1545         mpBindings,
1546         SVX_RES(RID_POPUPPANEL_TEXTPAGE_FONT_COLOR),
1547         SVX_RES(VS_FONT_COLOR),
1548         ::boost::bind(&ParaPropertyPanel::GetBGColor, this),
1549         ::boost::bind(&ParaPropertyPanel::SetBGColor, this, _1,_2),
1550         pParent,
1551         0);
1552 }
1553 
1554 
1555 ParaPropertyPanel::ParaPropertyPanel(Window* pParent,
1556     const cssu::Reference<css::frame::XFrame>& /* rxFrame */,
1557     SfxBindings* pBindings,
1558     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
1559     : Control(pParent, SVX_RES(RID_SIDEBAR_PARA_PANEL)),
1560       maAlignToolBoxBackground(ControlFactory::CreateToolBoxBackground(this)),
1561       maAlignToolBox (ControlFactory::CreateToolBox(maAlignToolBoxBackground.get(),SVX_RES(TBX_HORIZONTALALIGNMENT))),
1562       maTBxVertAlignBackground(ControlFactory::CreateToolBoxBackground(this)),
1563       maTBxVertAlign (ControlFactory::CreateToolBox(maTBxVertAlignBackground.get(),SVX_RES(TBX_VERT_ALIGN))),
1564       maTBxNumBulletBackground(ControlFactory::CreateToolBoxBackground(this)),
1565       maTBxNumBullet (ControlFactory::CreateToolBox(maTBxNumBulletBackground.get(),SVX_RES(TBX_NUM_BULLET))),
1566       maTBxBackColorBackground(ControlFactory::CreateToolBoxBackground(this)),
1567       maTBxBackColor (ControlFactory::CreateToolBox(maTBxBackColorBackground.get(),SVX_RES(TBX_BACK_COLOR))),
1568       maFTUL (new FixedText(this, SVX_RES(FT_SPACING))),
1569       maTbxUL_IncDecBackground(ControlFactory::CreateToolBoxBackground(this)),
1570       maTbxUL_IncDec (ControlFactory::CreateToolBox(maTbxUL_IncDecBackground.get(),SVX_RES(TBX_UL_INC_DEC))),
1571       maTopDist (new SvxRelativeField(this, SVX_RES(MF_ABOVE_PARASPACING))),
1572       maBottomDist (new SvxRelativeField(this, SVX_RES(MF_BELOW_PARASPACING))),
1573       maLineSPTbxBackground(ControlFactory::CreateToolBoxBackground(this)),
1574       maLineSPTbx (ControlFactory::CreateToolBox(maLineSPTbxBackground.get(),SVX_RES(TBX_LINESP))),
1575       maFTIndent (new FixedText(this, SVX_RES(FT_INDENT))),
1576       maTbxIndent_IncDecBackground(ControlFactory::CreateToolBoxBackground(this)),
1577       maTbxIndent_IncDec (ControlFactory::CreateToolBox(maTbxIndent_IncDecBackground.get(),SVX_RES(TBX_INDENT_INC_DEC))),
1578       maTbxProDemoteBackground(ControlFactory::CreateToolBoxBackground(this)),
1579       maTbxProDemote (ControlFactory::CreateToolBox(maTbxProDemoteBackground.get(),SVX_RES(TBX_INDENT_PRO_DEMOTE))),
1580       maLeftIndent (new SvxRelativeField(this, SVX_RES(MF_BEFORE_INDENT))),
1581       maRightIndent (new SvxRelativeField(this, SVX_RES(MF_AFTER_INDENT))),
1582       maFLineIndent (new SvxRelativeField(this, SVX_RES(MF_FL_INDENT))),
1583       mpColorUpdater (),
1584       maFISpace1 ( this, SVX_RES( FI_SPACE1)),
1585       maFISpace2 ( this, SVX_RES( FI_SPACE2)),
1586       maFIndent1 ( this, SVX_RES( FI_INDENT1)),
1587       maFIndent2 ( this, SVX_RES( FI_INDENT2)),
1588       maFIndent3 ( this, SVX_RES( FI_INDENT3)),
1589       maSpace1 (SVX_RES(IMG_SPACE1)),
1590       maSpace2 (SVX_RES(IMG_SPACE2)),
1591       maSpace3 (SVX_RES(IMG_SPACE3)),
1592       maIndent1 (SVX_RES(IMG_INDENT1)),
1593       maIndent2 (SVX_RES(IMG_INDENT2)),
1594       maIndent3 (SVX_RES(IMG_INDENT3)),
1595       maLeftPara (SVX_RES(IMG_LEFT_PARA)),
1596       maCentPara (SVX_RES(IMG_CENTER_PARA)),
1597       maRightPara (SVX_RES(IMG_RIGHT_PARA)),
1598       maJusPara (SVX_RES(IMG_JUSTIFY_PARA)),
1599       maIndInc (SVX_RES(IMG_INDENT_INC)),
1600       maIndDec (SVX_RES(IMG_INDENT_DEC)),
1601       maIndInc_BD (SVX_RES(IMG_INDENT_INC_BD)),
1602       maIndDec_BD (SVX_RES(IMG_INDENT_DEC_BD)),
1603       maIndHang (SVX_RES(IMG_INDENT_HANG)),
1604       maParInc (SVX_RES(IMG_PARA_INC)),
1605       maParDec (SVX_RES(IMG_PARA_DEC)),
1606       maVertImageList (SVX_RES(IL_VERT_ALIGN)),
1607       maVertImageListH (SVX_RES(IL_VERT_ALIGN)),
1608       maNumBImageList (SVX_RES(IL_NUM_BULLET)),
1609       maNumBImageListH (SVX_RES(ILH_NUM_BULLET)),
1610       maNumBImageListRTL (SVX_RES(IL_NUM_BULLET_RTL)),
1611       maImgBackColorHigh (SVX_RES(IMG_BACK_COLOR_H)),
1612       maImgBackColor (SVX_RES(IMG_BACK_COLOR)),
1613       maTxtLeft (0),
1614       mpLnSPItem (NULL),
1615       meLnSpState (SFX_ITEM_DONTCARE),
1616       mbOutLineLeft (false),
1617       mbOutLineRight (false),
1618       maUpper (0),
1619       maLower (0),
1620       mnBulletTypeIndex ((sal_uInt16)0xFFFF),
1621       mnNumTypeIndex ((sal_uInt16)0xFFFF),
1622       maColor (COL_AUTO),
1623       mbColorAvailable (true),
1624  //, m_eMetricUnit			  (FUNIT_INCH)
1625 //, m_last_eMetricUnit      (FUNIT_INCH)
1626       m_eLRSpaceUnit(),
1627       m_eULSpaceUnit(),
1628       maLeftAlignControl (SID_ATTR_PARA_ADJUST_LEFT, *pBindings,*this),
1629       maCenterAlignControl (SID_ATTR_PARA_ADJUST_CENTER, *pBindings,*this),
1630       maRightAlignControl (SID_ATTR_PARA_ADJUST_RIGHT, *pBindings,*this),
1631       maJustifyAlignControl (SID_ATTR_PARA_ADJUST_BLOCK, *pBindings,*this),
1632       maLRSpaceControl (SID_ATTR_PARA_LRSPACE,*pBindings,*this),
1633       maLNSpaceControl (SID_ATTR_PARA_LINESPACE, *pBindings,*this),
1634       maULSpaceControl (SID_ATTR_PARA_ULSPACE, *pBindings,*this),
1635       maOutLineLeftControl (SID_OUTLINE_LEFT, *pBindings,*this),
1636       maOutLineRightControl (SID_OUTLINE_RIGHT, *pBindings,*this),
1637       maDecIndentControl (SID_DEC_INDENT, *pBindings,*this),
1638       maIncIndentControl (SID_INC_INDENT, *pBindings,*this),
1639       maVertTop (SID_TABLE_VERT_NONE, *pBindings,*this),
1640       maVertCenter (SID_TABLE_VERT_CENTER, *pBindings,*this),
1641       maVertBottom (SID_TABLE_VERT_BOTTOM,*pBindings,*this),
1642       maBulletOnOff (FN_NUM_BULLET_ON, *pBindings,*this),
1643       maNumberOnOff (FN_NUM_NUMBERING_ON, *pBindings,*this),
1644       maBackColorControl (SID_BACKGROUND_COLOR,	*pBindings,*this),
1645       m_aMetricCtl (SID_ATTR_METRIC, *pBindings,*this),
1646       maBulletNumRuleIndex (FN_BUL_NUM_RULE_INDEX, *pBindings,*this),
1647       maNumNumRuleIndex (FN_NUM_NUM_RULE_INDEX, *pBindings,*this),
1648       maContext(),
1649       mpBindings(pBindings),
1650       maLineSpacePopup(this, ::boost::bind(&ParaPropertyPanel::CreateLineSpacingControl, this, _1)),
1651       maBulletsPopup(this, ::boost::bind(&ParaPropertyPanel::CreateBulletsPopupControl, this, _1)),
1652       maNumberingPopup(this, ::boost::bind(&ParaPropertyPanel::CreateNumberingPopupControl, this, _1)),
1653       maBGColorPopup(this, ::boost::bind(&ParaPropertyPanel::CreateBGColorPopupControl, this, _1)),
1654       mxSidebar(rxSidebar)
1655 {
1656 	initial();
1657 	FreeResource();
1658 }
1659 
1660 } } // end of namespace svx::sidebar
1661