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