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 <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_WriterVariants, Context_Default):
209         case CombinedEnumContext(Application_WriterVariants, 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_WriterVariants, 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_WriterVariants, 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_WriterVariants, 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 
295 
296 
297 void ParaPropertyPanel::DataChanged (const DataChangedEvent& rEvent)
298 {
299     (void)rEvent;
300 }
301 
302 ParaPropertyPanel::~ParaPropertyPanel()
303 {
304 	delete mpLnSPItem;
305 }
306 
307 void ParaPropertyPanel::ReSize(bool bSize)
308 {
309 	if(bSize)
310 	{
311 		//Paragraph spacing
312 		maFTUL->SetPosPixel(POS_FT_PARA_SPACE);
313 		maTbxUL_IncDec->SetPosPixel(POS_TBX_PARA_SPACE_INC_DEC);
314 		maTopDist->SetPosPixel(POS_MBX_TOP_DIST);
315 		maBottomDist->SetPosPixel(POS_MBX_BOT_DIST);
316 		//Indent
317 		maFTIndent->SetPosPixel(POS_FT_PARA_INDENT);
318 		maTbxIndent_IncDec->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC);
319 		maTbxProDemote->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC);
320 		maLeftIndent->SetPosPixel(POS_MBX_LEFT_DIST);
321 		maRightIndent->SetPosPixel(POS_MBX_RIGHT_DIST);
322 		maFLineIndent->SetPosPixel(POS_MBX_FLINE_DIST);
323 		//Line spacing
324 		maLineSPTbx->SetPosPixel(TBX_LINE_SPACE);
325 		//image
326 		maFISpace1.SetPosPixel(POS_IMG_SPACE1);
327 		maFISpace2.SetPosPixel(POS_IMG_SPACE2);
328 		maFIndent1.SetPosPixel(POS_IMG_INDENT1);
329 		maFIndent2.SetPosPixel(POS_IMG_INDENT2);
330 		maFIndent3.SetPosPixel(POS_IMG_INDENT3);
331 		Size aSize(GetOutputSizePixel().Width(),PARA_SECTIONPAGE_HEIGHT);
332 		aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
333 		aSize.setWidth(GetOutputSizePixel().Width());
334 		SetSizePixel(aSize);
335 	}
336 	else
337 	{
338 		//Paragraph spacing
339 		maFTUL->SetPosPixel(POS_FT_PARA_SPACE2);
340 		maTbxUL_IncDec->SetPosPixel(POS_TBX_PARA_SPACE_INC_DEC2);
341 		maTopDist->SetPosPixel(POS_MBX_TOP_DIST2);
342 		maBottomDist->SetPosPixel(POS_MBX_BOT_DIST2);
343 		//Indent
344 		maFTIndent->SetPosPixel(POS_FT_PARA_INDENT2);
345 		maTbxIndent_IncDec->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC2);
346 		maTbxProDemote->SetPosPixel(POS_TBX_PARA_INDENT_INC_DEC2);
347 		maLeftIndent->SetPosPixel(POS_MBX_LEFT_DIST2);
348 		maRightIndent->SetPosPixel(POS_MBX_RIGHT_DIST2);
349 		maFLineIndent->SetPosPixel(POS_MBX_FLINE_DIST2);
350 		//Line spacing
351 		maLineSPTbx->SetPosPixel(TBX_LINE_SPACE2);
352 		//image
353 		maFISpace1.SetPosPixel(POS_IMG_SPACE12);
354 		maFISpace2.SetPosPixel(POS_IMG_SPACE22);
355 		maFIndent1.SetPosPixel(POS_IMG_INDENT12);
356 		maFIndent2.SetPosPixel(POS_IMG_INDENT22);
357 		maFIndent3.SetPosPixel(POS_IMG_INDENT32);
358 		Size aSize(GetOutputSizePixel().Width(),PARA_SECTIONPAGE_HEIGHT_2);
359 		aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
360 		aSize.setWidth(GetOutputSizePixel().Width());
361 		SetSizePixel(aSize);
362 	}
363 
364     if (mxSidebar.is())
365         mxSidebar->requestLayout();
366 }
367 
368 void ParaPropertyPanel::EndSpacingPopupMode (void)
369 {
370     maLineSpacePopup.Hide();
371 }
372 
373 void ParaPropertyPanel::EndBulletsPopupMode (void)
374 {
375 	//i122054, Missed following line, for collapse the bullets popup
376 	maBulletsPopup.Hide();
377 }
378 
379 void ParaPropertyPanel::EndNumberingPopupMode (void)
380 {
381 	//i122054, Missed following line, for collapse the numbering popup
382 	maNumberingPopup.Hide();
383 }
384 
385 
386 void ParaPropertyPanel::InitToolBoxAlign()
387 {
388     const bool bIsHighContrastModeActive (Theme::IsHighContrastMode());
389 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM1, maLeftAlignControl.GetIcon(bIsHighContrastModeActive));
390 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM2, maCenterAlignControl.GetIcon(bIsHighContrastModeActive));
391 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM3, maRightAlignControl.GetIcon(bIsHighContrastModeActive));
392 	maAlignToolBox->SetItemImage(TOOLBOX_ITEM4, maJustifyAlignControl.GetIcon(bIsHighContrastModeActive));
393 
394 	Link aLink = LINK( this, ParaPropertyPanel, AlignStyleModifyHdl_Impl );
395 	maAlignToolBox->SetSelectHdl( aLink );
396 	Size aTbxSize (maAlignToolBox->CalcWindowSizePixel());
397 	maAlignToolBox->SetOutputSizePixel( aTbxSize );
398 }
399 
400 void ParaPropertyPanel::InitToolBoxVertAlign()
401 {
402     const bool bIsHighContrastModeActive (Theme::IsHighContrastMode());
403     maTBxVertAlign->SetItemImage(IID_VERT_TOP, maVertTop.GetIcon(bIsHighContrastModeActive));
404     maTBxVertAlign->SetItemImage(IID_VERT_CENTER, maVertCenter.GetIcon(bIsHighContrastModeActive));
405     maTBxVertAlign->SetItemImage(IID_VERT_BOTTOM, maVertBottom.GetIcon(bIsHighContrastModeActive));
406 	maTBxVertAlign->SetSelectHdl(LINK(this,ParaPropertyPanel,VertTbxSelectHandler));
407 	Size aTbxSize (maTBxVertAlign->CalcWindowSizePixel());
408 	maTBxVertAlign->SetOutputSizePixel( aTbxSize );
409 }
410 
411 
412 void ParaPropertyPanel::InitToolBoxIndent()
413 {
414 	Link aLink = LINK( this, ParaPropertyPanel, ModifyIndentHdl_Impl );
415 	maLeftIndent->SetModifyHdl( aLink );
416 	maRightIndent->SetModifyHdl( aLink );
417 	maFLineIndent->SetModifyHdl( aLink );
418 
419     const bool bIsHighContrastModeActive (Theme::IsHighContrastMode());
420 
421 	if( Application::GetSettings().GetLayoutRTL())
422 	{
423 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM1, maIncIndentControl.GetIcon(bIsHighContrastModeActive));
424 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM2, maDecIndentControl.GetIcon(bIsHighContrastModeActive));
425 	}
426 	else
427 	{
428 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM1, maIncIndentControl.GetIcon(bIsHighContrastModeActive));
429 		maTbxIndent_IncDec->SetItemImage(TOOLBOX_ITEM2, maDecIndentControl.GetIcon(bIsHighContrastModeActive));
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, maOutLineLeftControl.GetIcon(bIsHighContrastModeActive));
441 		maTbxProDemote->SetItemImage(TOOLBOX_ITEM2, maOutLineRightControl.GetIcon(bIsHighContrastModeActive));
442 	}
443 	else
444 	{
445 		maTbxProDemote->SetItemImage(TOOLBOX_ITEM1, maOutLineLeftControl.GetIcon(bIsHighContrastModeActive));
446 		maTbxProDemote->SetItemImage(TOOLBOX_ITEM2, maOutLineRightControl.GetIcon(bIsHighContrastModeActive));
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     const bool bIsHighContrastModeActive (Theme::IsHighContrastMode());
473     maTBxNumBullet->SetItemImage(IID_BULLET, maBulletOnOff.GetIcon(bIsHighContrastModeActive));
474     maTBxNumBullet->SetItemImage(IID_NUMBER, maNumberOnOff.GetIcon(bIsHighContrastModeActive));
475 
476 	maTBxNumBullet->SetDropdownClickHdl(LINK(this,ParaPropertyPanel,NumBTbxDDHandler));
477 	maTBxNumBullet->SetSelectHdl(LINK(this,ParaPropertyPanel,NumBTbxSelectHandler));
478 	Size aTbxSize (maTBxNumBullet->CalcWindowSizePixel());
479 	maTBxNumBullet->SetOutputSizePixel( aTbxSize );
480 }
481 void ParaPropertyPanel::InitToolBoxSpacing()
482 {
483 	Link aLink = LINK( this, ParaPropertyPanel, ULSpaceHdl_Impl );
484 	maTopDist->SetModifyHdl(aLink);
485 	maBottomDist->SetModifyHdl( aLink );
486 
487 	maTbxUL_IncDec->SetItemImage(TOOLBOX_ITEM1, maParInc);
488 	maTbxUL_IncDec->SetItemImage(TOOLBOX_ITEM2, maParDec);
489 	aLink = LINK( this, ParaPropertyPanel, ClickUL_IncDec_Hdl_Impl );
490 	maTbxUL_IncDec->SetSelectHdl(aLink);
491 	m_eULSpaceUnit = maULSpaceControl.GetCoreMetric();
492 	Size aTbxSize = maTbxUL_IncDec->CalcWindowSizePixel();
493 	maTbxUL_IncDec->SetOutputSizePixel( aTbxSize );
494 }
495 void ParaPropertyPanel::InitToolBoxLineSpacing()
496 {
497 	Link aLink = LINK( this, ParaPropertyPanel, ClickLineSPDropDownHdl_Impl );
498 	maLineSPTbx->SetDropdownClickHdl( aLink );
499 	maLineSPTbx->SetSelectHdl( aLink );		//support keyinput "ENTER"
500 	maLineSPTbx->SetItemBits( TOOLBOX_ITEM1, maLineSPTbx->GetItemBits( TOOLBOX_ITEM1 ) | TIB_DROPDOWNONLY );
501 	maLineSPTbx->SetItemImage(TOOLBOX_ITEM1,maSpace3);
502 	Size aTbxSize = maLineSPTbx->CalcWindowSizePixel();
503 	maLineSPTbx->SetOutputSizePixel( aTbxSize );
504 }
505 
506 void ParaPropertyPanel::initial()
507 {
508     maFTUL->SetBackground(Wallpaper());
509     maFTIndent->SetBackground(Wallpaper());
510     maFISpace1.SetBackground(Wallpaper());
511     maFISpace2.SetBackground(Wallpaper());
512     maFIndent1.SetBackground(Wallpaper());
513     maFIndent2.SetBackground(Wallpaper());
514     maFIndent3.SetBackground(Wallpaper());
515 
516     maFISpace1.SetImage(maSpace1);
517 	maFISpace2.SetImage(maSpace2);
518 	maFIndent1.SetImage(maIndent3);
519 	maFIndent2.SetImage(maIndent2);
520 	maFIndent3.SetImage(maIndent1);
521 
522 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_LEFT,sal_True,sal_False);
523 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_CENTER,sal_True,sal_False);
524 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_RIGHT,sal_True,sal_False);
525 	GetBindings()->Invalidate(SID_ATTR_PARA_ADJUST_BLOCK,sal_True,sal_False);
526 
527 	//toolbox
528 	InitToolBoxAlign();
529 	InitToolBoxVertAlign();
530 	InitToolBoxIndent();
531 	InitToolBoxBGColor();
532 	InitToolBoxBulletsNumbering();
533 	InitToolBoxSpacing();
534 	InitToolBoxLineSpacing();
535 
536 #ifdef HAS_IA2
537 	maAlignToolBox->SetAccRelationLabeledBy(&maAlignToolBox);
538 	maTBxVertAlign->SetMpSubEditAccLableBy(&maTBxVertAlign);
539 	maTBxNumBullet->SetAccRelationLabeledBy(&maTBxNumBullet);
540 	maTBxBackColor->SetMpSubEditAccLableBy(&maTBxBackColor);
541 	maFTUL->SetAccRelationLabeledBy(&maFTUL);
542 	maTbxUL_IncDec->SetAccRelationLabeledBy(&maTbxUL_IncDec);
543 	maTopDist->SetAccRelationLabeledBy(&maTopDist);
544 	maBottomDist->SetAccRelationLabeledBy(&maBottomDist);
545 	maLineSPTbx->SetAccRelationLabeledBy(&maLineSPTbx);
546 	maFTIndent->SetAccRelationLabeledBy(&maFTIndent);
547 	maTbxIndent_IncDec->SetAccRelationLabeledBy(&maTbxIndent_IncDec);
548 	maTbxProDemote->SetAccRelationLabeledBy(&maTbxProDemote);
549 	maLeftIndent->SetAccRelationLabeledBy(&maLeftIndent);
550 	maRightIndent->SetAccRelationLabeledBy(&maRightIndent);
551 	maFLineIndent->SetAccRelationLabeledBy(&maFLineIndent);
552 	mpColorUpdater->SetAccRelationLabeledBy(&mpColorUpdater);
553 #endif
554 }
555 
556 void ParaPropertyPanel::InitImageList(::boost::scoped_ptr<ToolBox>& rTbx, ImageList& rImglst, ImageList& rImgHlst)
557 {
558 	sal_Bool bHighContrast = GetDisplayBackground().GetColor().IsDark();
559 
560     ImageList& rImgLst = bHighContrast ? rImgHlst : rImglst;
561 
562 	sal_uInt16 nCount = rTbx->GetItemCount();
563     for (sal_uInt16 i = 0; i < nCount; i++)
564     {
565     	sal_uInt16 nId = rTbx->GetItemId(i);
566 		rTbx->SetItemImage( nId, rImgLst.GetImage( nId ) );
567     }
568 }
569 
570 //===========================for Numbering & Bullet================================================
571 
572 
573 
574 IMPL_LINK(ParaPropertyPanel, NumBTbxDDHandler, ToolBox*, pToolBox)
575 {
576 	sal_uInt16 nId = pToolBox->GetCurItemId();
577 
578 	EndTracking();
579 	pToolBox->SetItemDown( nId, sal_True );
580 
581 	if (nId == 1)
582     {
583 		maBulletsPopup.UpdateValueSet();
584 		maBulletsPopup.Show(*pToolBox);
585 	}
586 	else if (nId == 2)
587 	{
588 		maNumberingPopup.UpdateValueSet();
589 		maNumberingPopup.Show(*pToolBox);
590 	}
591 	pToolBox->SetItemDown( nId, sal_False );
592 	return 0;
593 }
594 
595 IMPL_LINK(ParaPropertyPanel, NumBTbxSelectHandler, ToolBox*, pToolBox)
596 {
597 	sal_uInt16 nId = pToolBox->GetCurItemId();
598 	sal_uInt16 nSID = SID_TABLE_VERT_NONE;
599 
600 	EndTracking();
601 	if (nId == 1)
602     {
603 		nSID = FN_NUM_BULLET_ON;
604 	}
605 	else if ( nId == 2)
606 	{
607 		nSID = FN_NUM_NUMBERING_ON;
608 	}
609 	SfxBoolItem aBoolItem(nSID, sal_True);
610 	GetBindings()->GetDispatcher()->Execute(nSID, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
611 
612 	return 0;
613 }
614 
615 
616 //================================for Vertical Alignment========================================
617 
618 
619 
620 IMPL_LINK(ParaPropertyPanel, VertTbxSelectHandler, ToolBox*, pToolBox)
621 {
622 	sal_uInt16 nId = pToolBox->GetCurItemId();
623 	sal_uInt16 nSID = SID_TABLE_VERT_NONE;
624 	EndTracking();
625 	if (nId == 1)
626     {
627         nSID = SID_TABLE_VERT_NONE;
628 		maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_CHECK);
629 		maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_NOCHECK);
630 		maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_NOCHECK);
631 	}
632 	else if (nId == 2)
633 	{
634 		nSID = SID_TABLE_VERT_CENTER;
635 		maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_NOCHECK);
636 		maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_CHECK);
637 		maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_NOCHECK);
638 	}
639 	else if (nId == 3)
640 	{
641 		nSID = SID_TABLE_VERT_BOTTOM;
642 		maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_NOCHECK);
643 		maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_NOCHECK);
644 		maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_CHECK);
645 	}
646 	SfxBoolItem aBoolItem(nSID, sal_True);
647 	GetBindings()->GetDispatcher()->Execute(nSID, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
648 
649 	return 0;
650 }
651 
652 void ParaPropertyPanel::VertStateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
653 {
654 	if (eState < SFX_ITEM_DONTCARE)
655 	{
656 		maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_NOCHECK);
657 		maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_NOCHECK);
658 		maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_NOCHECK);
659 		maTBxVertAlign->EnableItem(IID_VERT_TOP, sal_False);
660 		maTBxVertAlign->EnableItem(IID_VERT_CENTER, sal_False);
661 		maTBxVertAlign->EnableItem(IID_VERT_BOTTOM, sal_False);
662 	}
663 	else
664 	{
665 		maTBxVertAlign->EnableItem(IID_VERT_TOP, sal_True);
666 		maTBxVertAlign->EnableItem(IID_VERT_CENTER, sal_True);
667 		maTBxVertAlign->EnableItem(IID_VERT_BOTTOM, sal_True);
668 		if ( (eState >= SFX_ITEM_DEFAULT) && (pState->ISA(SfxBoolItem)))
669 		{
670 			const SfxBoolItem* pItem= (const SfxBoolItem*)pState;
671 			sal_Bool aBool = (sal_Bool)pItem->GetValue();
672 
673 			if (aBool)
674 			{
675 				if (nSID == SID_TABLE_VERT_NONE)
676 				{
677 					maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_CHECK);
678 					maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_NOCHECK);
679 					maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_NOCHECK);
680 				}
681 				else if (nSID == SID_TABLE_VERT_CENTER)
682 				{
683 					maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_NOCHECK);
684 					maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_CHECK);
685 					maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_NOCHECK);
686 				}
687 				else if (nSID == SID_TABLE_VERT_BOTTOM)
688 				{
689 					maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_NOCHECK);
690 					maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_NOCHECK);
691 					maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_CHECK);
692 				}
693 			}
694 			else
695 			{
696 				if (nSID == SID_TABLE_VERT_NONE)
697 				{
698 					maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_NOCHECK);
699 				}
700 				else if (nSID == SID_TABLE_VERT_CENTER)
701 				{
702 					maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_NOCHECK);
703 				}
704 				else if (nSID == SID_TABLE_VERT_BOTTOM)
705 				{
706 					maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_NOCHECK);
707 				}
708 			}
709 		}
710 		else
711 		{
712 			maTBxVertAlign->SetItemState(IID_VERT_TOP, STATE_NOCHECK);
713 			maTBxVertAlign->SetItemState(IID_VERT_CENTER, STATE_NOCHECK);
714 			maTBxVertAlign->SetItemState(IID_VERT_BOTTOM, STATE_NOCHECK);
715 		}
716 	}
717 }
718 //==================================for Background color=====================
719 
720 IMPL_LINK(ParaPropertyPanel, ToolBoxBackColorDDHandler,ToolBox*, pToolBox)
721 {
722 	sal_uInt16 nId = pToolBox->GetCurItemId();
723 	OSL_ASSERT(nId == TBI_BACK_COLOR);
724 	if(nId == TBI_BACK_COLOR)
725 	{
726 		pToolBox->SetItemDown( nId, true );
727 		maBGColorPopup.Show(*pToolBox);
728 		maBGColorPopup.SetCurrentColor(maColor, mbColorAvailable);
729 	}
730 	return 0;
731 }
732 
733 IMPL_LINK( ParaPropertyPanel, ImplPopupModeEndHdl, FloatingWindow*, EMPTYARG )
734 {
735 	return 0;
736 }
737 
738 void ParaPropertyPanel::ShowMenu (void)
739 {
740     if (mpBindings != NULL)
741     {
742         SfxDispatcher* pDispatcher = mpBindings->GetDispatcher();
743         if (pDispatcher != NULL)
744             pDispatcher->Execute(SID_PARA_DLG, SFX_CALLMODE_ASYNCHRON);
745     }
746 }
747 
748 void ParaPropertyPanel::ParaBKGStateChanged(sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState)
749 {
750 	if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxColorItem))
751 	{
752 		const SvxColorItem* pItem =  (const SvxColorItem*)pState;
753 		maColor = pItem->GetValue();
754 		mbColorAvailable = sal_True;
755 		mpColorUpdater->Update(maColor);
756 	}
757 	else
758 	{
759 		mbColorAvailable = sal_False;
760 		maColor.SetColor(COL_AUTO);
761 		mpColorUpdater->Update(maColor);
762 	}
763 }
764 
765 void ParaPropertyPanel::SetBGColor (
766     const String& /* rsColorName */,
767     const Color aColor)
768 {
769 	SvxColorItem aColorItem(aColor, SID_BACKGROUND_COLOR);
770 	mpBindings->GetDispatcher()->Execute(SID_BACKGROUND_COLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
771 	maColor = aColor;
772 }
773 
774 //==================================for Paragraph Alignment=====================
775 IMPL_LINK( ParaPropertyPanel, AlignStyleModifyHdl_Impl, ToolBox*, pBox )
776 {
777 	switch (pBox->GetCurItemId())
778 	{
779 	case BT_SUBSTLEFT:
780 		{
781 			pBox->SetItemState(BT_SUBSTLEFT,STATE_CHECK);
782 			pBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
783 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
784 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
785 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_LEFT,  sal_True );
786 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_LEFT, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
787 		}
788 		break;
789 	case BT_SUBSTCENTER:
790 		{
791 			pBox->SetItemState(BT_SUBSTCENTER,STATE_CHECK);
792 			pBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
793 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
794 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
795 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_CENTER, sal_True );
796 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_CENTER, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
797 		}
798 		break;
799 	case BT_SUBSTRIGHT:
800 		{
801 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_CHECK);
802 			pBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
803 			pBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
804 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
805 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_RIGHT, sal_True );
806 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_RIGHT, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
807 		}
808 		break;
809 	case BT_SUBSTJUSTIFY:
810 		{
811 			pBox->SetItemState(BT_SUBSTJUSTIFY,STATE_CHECK);
812 			pBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
813 			pBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
814 			pBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
815 			SfxBoolItem aBoolItem( SID_ATTR_PARA_ADJUST_BLOCK, sal_True );
816 			GetBindings()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_BLOCK, SFX_CALLMODE_RECORD, &aBoolItem, 0L);
817 		}
818 		break;
819 	}
820 
821 	return 0;
822 }
823 //==================================for Paragraph Indent=====================
824 IMPL_LINK( ParaPropertyPanel, ModifyIndentHdl_Impl, SvxRelativeField*, /* pBox */ )
825 {
826 	SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
827 	aMargin.SetTxtLeft( (const long)GetCoreValue( *maLeftIndent.get(), m_eLRSpaceUnit ) );
828 	aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
829 	aMargin.SetTxtFirstLineOfst( (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
830 
831 	GetBindings()->GetDispatcher()->Execute(
832 		SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
833 	return 0;
834 }
835 
836 IMPL_LINK(ParaPropertyPanel, ClickIndent_IncDec_Hdl_Impl, ToolBox *, pControl)
837 {
838     switch (pControl->GetCurItemId())
839     {
840     case INDENT_INCREMENT:
841         {
842             switch (maContext.GetCombinedContext_DI())
843             {
844             case CombinedEnumContext(Application_WriterVariants, Context_Default):
845             case CombinedEnumContext(Application_WriterVariants, Context_Text):
846             case CombinedEnumContext(Application_WriterVariants, Context_Table):
847                 {
848                     SfxBoolItem aMargin( SID_INC_INDENT, sal_True );
849                     GetBindings()->GetDispatcher()->Execute(
850                         SID_INC_INDENT, SFX_CALLMODE_RECORD, &aMargin, 0L);
851                 }
852                 break;
853             default:
854                 {
855                     SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
856 
857                     maTxtLeft += INDENT_STEP;
858                     sal_Int64 nVal = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
859                     nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
860                     aMargin.SetTxtLeft( (const long)nVal );
861                     aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
862                     aMargin.SetTxtFirstLineOfst( (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
863 
864                     GetBindings()->GetDispatcher()->Execute(
865                         SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
866                 }
867             }
868         }
869         break;
870     case INDENT_DECREMENT:
871         {
872             switch (maContext.GetCombinedContext_DI())
873             {
874             case CombinedEnumContext(Application_WriterVariants, Context_Default):
875             case CombinedEnumContext(Application_WriterVariants, Context_Text):
876             case CombinedEnumContext(Application_WriterVariants, Context_Table):
877                 {
878                     SfxBoolItem aMargin( SID_DEC_INDENT, sal_True );
879                     GetBindings()->GetDispatcher()->Execute(
880                         SID_DEC_INDENT, SFX_CALLMODE_RECORD, &aMargin, 0L);
881                 }
882                 break;
883             default:
884                 {
885                     if((maTxtLeft - INDENT_STEP) < 0)
886                         maTxtLeft = DEFAULT_VALUE;
887                     else
888                         maTxtLeft -= INDENT_STEP;
889 
890                     SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
891 
892                     sal_Int64 nVal = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
893                     nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
894 
895                     aMargin.SetTxtLeft( (const long)nVal );
896                     aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
897                     aMargin.SetTxtFirstLineOfst( (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
898 
899                     GetBindings()->GetDispatcher()->Execute(
900                         SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
901                 }
902             }
903         }
904         break;
905     case ID_HANGING_INDENT:
906         {
907             SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
908             aMargin.SetTxtLeft( (const long)GetCoreValue( *maLeftIndent.get(), m_eLRSpaceUnit ) + (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
909             aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
910             aMargin.SetTxtFirstLineOfst( ((const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ))*(-1) );
911 
912             GetBindings()->GetDispatcher()->Execute(
913                 SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
914         }
915         break;
916     }
917     return( 0L );
918 }
919 
920 IMPL_LINK(ParaPropertyPanel, ClickProDemote_Hdl_Impl, ToolBox *, pControl)
921 {
922     switch (pControl->GetCurItemId())
923     {
924         case BT_TBX_INDENT_PROMOTE:
925         {
926             GetBindings()->GetDispatcher()->Execute( SID_OUTLINE_RIGHT, SFX_CALLMODE_RECORD );
927         }
928         break;
929         case BT_TBX_INDENT_DEMOTE:
930         {
931             GetBindings()->GetDispatcher()->Execute( SID_OUTLINE_LEFT, SFX_CALLMODE_RECORD );
932         }
933         break;
934         case SD_HANGING_INDENT:
935         {
936             SvxLRSpaceItem aMargin( SID_ATTR_PARA_LRSPACE );
937             aMargin.SetTxtLeft( (const long)GetCoreValue( *maLeftIndent.get(), m_eLRSpaceUnit ) + (const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ) );
938             aMargin.SetRight( (const long)GetCoreValue( *maRightIndent.get(), m_eLRSpaceUnit ) );
939             aMargin.SetTxtFirstLineOfst( ((const short)GetCoreValue( *maFLineIndent.get(), m_eLRSpaceUnit ))*(-1) );
940 
941             GetBindings()->GetDispatcher()->Execute( SID_ATTR_PARA_LRSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
942         }
943         break;
944     }
945     return( 0L );
946 }
947 //==================================for Paragraph Line Spacing=====================
948 
949 IMPL_LINK( ParaPropertyPanel, ClickLineSPDropDownHdl_Impl, ToolBox*, pBox )
950 {
951 
952 	const sal_uInt16 nId = pBox->GetCurItemId();
953 	OSL_ASSERT(nId == TOOLBOX_ITEM1);
954 	if(nId == TOOLBOX_ITEM1)
955 	{
956 		pBox->SetItemDown( nId, true );
957 		maLineSpacePopup.Rearrange(meLnSpState,m_eMetricUnit,mpLnSPItem,maContext);
958 		maLineSpacePopup.Show(*pBox);
959 
960 	}
961 	return (0L);
962 }
963 
964 //==================================for Paragraph Spacing=====================
965 IMPL_LINK( ParaPropertyPanel, ULSpaceHdl_Impl, SvxRelativeField*, /* pBox */)
966 {
967 	SvxULSpaceItem aMargin( SID_ATTR_PARA_ULSPACE );
968 	aMargin.SetUpper( (sal_uInt16)GetCoreValue( *maTopDist.get(), m_eULSpaceUnit ) );
969 	aMargin.SetLower( (sal_uInt16)GetCoreValue( *maBottomDist.get(), m_eULSpaceUnit ) );
970 
971 	GetBindings()->GetDispatcher()->Execute(
972 		SID_ATTR_PARA_ULSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
973 	return 0L;
974 }
975 
976 IMPL_LINK(ParaPropertyPanel, ClickUL_IncDec_Hdl_Impl, ToolBox *, pControl)
977 {
978 	switch (pControl->GetCurItemId())
979 		{
980 	    case UL_INCREMENT:
981 		     {
982 				 SvxULSpaceItem aMargin( SID_ATTR_PARA_ULSPACE );
983 
984 				 maUpper += UL_STEP;
985 				 sal_Int64 nVal = OutputDevice::LogicToLogic( maUpper, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
986 				 nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
987 				 aMargin.SetUpper( (const sal_uInt16)nVal );
988 
989 				 maLower += UL_STEP;
990 				 nVal = OutputDevice::LogicToLogic( maLower, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
991 				 nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
992 	             aMargin.SetLower( (const sal_uInt16)nVal );
993 
994 				 GetBindings()->GetDispatcher()->Execute(
995 					 SID_ATTR_PARA_ULSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
996 			 }
997 			 break;
998 		case UL_DECREMENT:
999 			{
1000 				 SvxULSpaceItem aMargin( SID_ATTR_PARA_ULSPACE );
1001 
1002 				 if( maUpper >= UL_STEP )
1003 				 {
1004 					maUpper -= UL_STEP;
1005 					sal_Int64	nVal = OutputDevice::LogicToLogic( maUpper, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1006 					nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
1007 					aMargin.SetUpper( (const sal_uInt16)nVal );
1008 				 }
1009 				 else
1010 					aMargin.SetUpper( DEFAULT_VALUE );
1011 				 if( maLower >= UL_STEP )
1012 				 {
1013 					maLower -= UL_STEP;
1014 					sal_Int64	nVal = OutputDevice::LogicToLogic( maLower, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1015 					nVal = OutputDevice::LogicToLogic( (long)nVal, MAP_100TH_MM, (MapUnit)m_eLRSpaceUnit );
1016 					aMargin.SetLower( (const sal_uInt16)nVal );
1017 				 }
1018 				 else
1019 					aMargin.SetLower( DEFAULT_VALUE );
1020 
1021 				 GetBindings()->GetDispatcher()->Execute(
1022 					 SID_ATTR_PARA_ULSPACE, SFX_CALLMODE_RECORD, &aMargin, 0L);
1023 			}
1024 			break;
1025 		}
1026 	return( 0L );
1027 }
1028 
1029 //==================================for Paragraph State change=====================
1030 void ParaPropertyPanel::NotifyItemUpdate(
1031     sal_uInt16 nSID,
1032     SfxItemState eState,
1033     const SfxPoolItem* pState,
1034     const bool bIsEnabled)
1035 {
1036     (void)bIsEnabled;
1037 
1038     switch (nSID)
1039     {
1040     case SID_ATTR_METRIC:
1041         {
1042             m_eMetricUnit = GetCurrentUnit(eState,pState);
1043             if( m_eMetricUnit!=m_last_eMetricUnit )
1044             {
1045                 SetFieldUnit( *maLeftIndent.get(), m_eMetricUnit );
1046                 SetFieldUnit( *maRightIndent.get(), m_eMetricUnit );
1047                 SetFieldUnit( *maFLineIndent.get(), m_eMetricUnit );
1048                 SetFieldUnit( *maTopDist.get(), m_eMetricUnit );
1049                 SetFieldUnit( *maBottomDist.get(), m_eMetricUnit );
1050             }
1051             m_last_eMetricUnit = m_eMetricUnit;
1052         }
1053         break;
1054 
1055     case SID_ATTR_PARA_LRSPACE:
1056         StateChangedIndentImpl( nSID, eState, pState );
1057         break;
1058 
1059     case SID_ATTR_PARA_LINESPACE:
1060         StateChangedLnSPImpl( nSID, eState, pState );
1061         break;
1062 
1063     case SID_ATTR_PARA_ULSPACE:
1064         StateChangedULImpl( nSID, eState, pState );
1065         break;
1066 
1067     case SID_ATTR_PARA_ADJUST_LEFT:
1068     case SID_ATTR_PARA_ADJUST_CENTER:
1069     case SID_ATTR_PARA_ADJUST_RIGHT:
1070     case SID_ATTR_PARA_ADJUST_BLOCK:
1071         StateChangedAlignmentImpl( nSID, eState, pState );
1072         break;
1073 
1074     case SID_OUTLINE_LEFT:
1075     case SID_OUTLINE_RIGHT:
1076         StateChangeOutLineImpl( nSID, eState, pState );
1077         break;
1078 
1079     case SID_INC_INDENT:
1080     case SID_DEC_INDENT:
1081         StateChangeIncDecImpl( nSID, eState, pState );
1082         break;
1083 
1084     case FN_NUM_NUMBERING_ON:
1085     case FN_NUM_BULLET_ON:
1086         StateChangeBulletNumImpl( nSID, eState, pState );
1087         break;
1088 
1089     case FN_BUL_NUM_RULE_INDEX:
1090     case FN_NUM_NUM_RULE_INDEX:
1091         StateChangeBulletNumRuleImpl( nSID, eState, pState );
1092         break;
1093 
1094     case SID_TABLE_VERT_NONE:
1095     case SID_TABLE_VERT_CENTER:
1096     case SID_TABLE_VERT_BOTTOM:
1097         VertStateChanged( nSID, eState, pState);
1098         break;
1099 
1100     case SID_BACKGROUND_COLOR:
1101         ParaBKGStateChanged(nSID, eState, pState);
1102         break;
1103     }
1104 }
1105 
1106 
1107 
1108 
1109 void ParaPropertyPanel::StateChangedAlignmentImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1110 {
1111 	if( eState >= SFX_ITEM_AVAILABLE )
1112 	{
1113 		const SfxBoolItem* pItem = (const SfxBoolItem*)pState;
1114 		bool IsChecked = (bool)pItem->GetValue();
1115 		switch (nSID)
1116 		{
1117 		case SID_ATTR_PARA_ADJUST_LEFT:
1118 			{
1119 				if(IsChecked)
1120 				{
1121 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_CHECK);
1122 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1123 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1124 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1125 				}
1126 				else
1127 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1128 			}
1129 			break;
1130 		case SID_ATTR_PARA_ADJUST_CENTER:
1131 			{
1132 				if(IsChecked)
1133 				{
1134 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_CHECK);
1135 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1136 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1137 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1138 				}
1139 				else
1140 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1141 			}
1142 			break;
1143 		case SID_ATTR_PARA_ADJUST_RIGHT:
1144 			{
1145 				if(IsChecked)
1146 				{
1147 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_CHECK);
1148 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1149 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1150 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1151 				}
1152 				else
1153 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1154 			}
1155 			break;
1156 		case SID_ATTR_PARA_ADJUST_BLOCK:
1157 			{
1158 				if(IsChecked)
1159 				{
1160 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_CHECK);
1161 					maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1162 					maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1163 					maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1164 				}
1165 				else
1166 					maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1167 			}
1168 			break;
1169 		}
1170 	}
1171 	else if( eState == SFX_ITEM_DISABLED )
1172 	{
1173 	}
1174 	else if ( eState == SFX_ITEM_DONTCARE )
1175 	{
1176 		switch (nSID)
1177 		{
1178 		case SID_ATTR_PARA_ADJUST_LEFT:
1179 			maAlignToolBox->SetItemState(BT_SUBSTLEFT,STATE_NOCHECK);
1180 			break;
1181 		case SID_ATTR_PARA_ADJUST_CENTER:
1182 			maAlignToolBox->SetItemState(BT_SUBSTCENTER,STATE_NOCHECK);
1183 			break;
1184 		case SID_ATTR_PARA_ADJUST_RIGHT:
1185 			maAlignToolBox->SetItemState(BT_SUBSTRIGHT,STATE_NOCHECK);
1186 			break;
1187 		case SID_ATTR_PARA_ADJUST_BLOCK:
1188 			maAlignToolBox->SetItemState(BT_SUBSTJUSTIFY,STATE_NOCHECK);
1189 			break;
1190 		}
1191 	}
1192 }
1193 
1194 void ParaPropertyPanel::StateChangedIndentImpl( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
1195 {
1196     switch (maContext.GetCombinedContext_DI())
1197     {
1198 
1199     case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
1200     case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
1201     case CombinedEnumContext(Application_Calc, Context_DrawText):
1202         {
1203             maLeftIndent->SetMin( DEFAULT_VALUE );
1204             maRightIndent->SetMin( DEFAULT_VALUE );
1205             maFLineIndent->SetMin( DEFAULT_VALUE );
1206             maTbxIndent_IncDec->Show();
1207             maTbxProDemote->Hide();
1208         }
1209         break;
1210     case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
1211     case CombinedEnumContext(Application_DrawImpress, Context_Draw):
1212     case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
1213     case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
1214     case CombinedEnumContext(Application_DrawImpress, Context_Table):
1215         {
1216             maLeftIndent->SetMin( DEFAULT_VALUE );
1217             maRightIndent->SetMin( DEFAULT_VALUE );
1218             maFLineIndent->SetMin( DEFAULT_VALUE );
1219             maTbxIndent_IncDec->Hide();
1220             maTbxProDemote->Show();
1221         }
1222         break;
1223     case CombinedEnumContext(Application_WriterVariants, Context_Default):
1224     case CombinedEnumContext(Application_WriterVariants, Context_Text):
1225     case CombinedEnumContext(Application_WriterVariants, Context_Table):
1226         {
1227             maLeftIndent->SetMin( NEGA_MAXVALUE, FUNIT_100TH_MM );
1228             maRightIndent->SetMin( NEGA_MAXVALUE, FUNIT_100TH_MM );
1229             maFLineIndent->SetMin( NEGA_MAXVALUE, FUNIT_100TH_MM );
1230             maTbxIndent_IncDec->Show();
1231             maTbxProDemote->Hide();
1232         }
1233         break;
1234     }
1235 
1236     if( pState && eState >= SFX_ITEM_AVAILABLE )
1237     {
1238         SvxLRSpaceItem* pSpace = ( SvxLRSpaceItem*)pState;
1239         maTxtLeft = pSpace->GetTxtLeft();
1240         maTxtLeft = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)m_eLRSpaceUnit, MAP_100TH_MM );
1241         maTxtLeft = OutputDevice::LogicToLogic( maTxtLeft, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1242 
1243         long aTxtRight = pSpace->GetRight();
1244         aTxtRight = OutputDevice::LogicToLogic( aTxtRight, (MapUnit)m_eLRSpaceUnit, MAP_100TH_MM );
1245         aTxtRight = OutputDevice::LogicToLogic( aTxtRight, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1246 
1247         long aTxtFirstLineOfst = pSpace->GetTxtFirstLineOfst();
1248         aTxtFirstLineOfst = OutputDevice::LogicToLogic( aTxtFirstLineOfst, (MapUnit)m_eLRSpaceUnit, MAP_100TH_MM );
1249         aTxtFirstLineOfst = OutputDevice::LogicToLogic( aTxtFirstLineOfst, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1250 
1251         long nVal = OutputDevice::LogicToLogic( maTxtLeft, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1252         nVal = (long)maLeftIndent->Normalize( (long)nVal );
1253         maLeftIndent->SetValue( nVal, FUNIT_100TH_MM );
1254 
1255         if ( maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Text)
1256              && maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Default)
1257              && maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Table))
1258         {
1259             maFLineIndent->SetMin( nVal*(-1), FUNIT_100TH_MM );
1260         }
1261 
1262         long nrVal = OutputDevice::LogicToLogic( aTxtRight, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1263         nrVal = (long)maRightIndent->Normalize( (long)nrVal );
1264         maRightIndent->SetValue( nrVal, FUNIT_100TH_MM );
1265 
1266         long nfVal = OutputDevice::LogicToLogic( aTxtFirstLineOfst, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1267         nfVal = (long)maFLineIndent->Normalize( (long)nfVal );
1268         maFLineIndent->SetValue( nfVal, FUNIT_100TH_MM );
1269 
1270         switch (maContext.GetCombinedContext_DI())
1271         {
1272         case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
1273         case CombinedEnumContext(Application_WriterVariants, Context_Text):
1274         case CombinedEnumContext(Application_WriterVariants, Context_Default):
1275         case CombinedEnumContext(Application_WriterVariants, Context_Table):
1276         case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
1277             {
1278                 maLeftIndent->SetMax( MAX_SW - nrVal, FUNIT_100TH_MM );
1279                 maRightIndent->SetMax( MAX_SW - nVal, FUNIT_100TH_MM );
1280                 maFLineIndent->SetMax( MAX_SW - nVal - nrVal, FUNIT_100TH_MM );
1281             }
1282             break;
1283         case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
1284         case CombinedEnumContext(Application_DrawImpress, Context_Draw):
1285         case CombinedEnumContext(Application_DrawImpress, Context_Table):
1286         case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
1287         case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
1288             {
1289                 maLeftIndent->SetMax( MAX_SC_SD - nrVal, FUNIT_100TH_MM );
1290                 maRightIndent->SetMax( MAX_SC_SD - nVal, FUNIT_100TH_MM );
1291                 maFLineIndent->SetMax( MAX_SC_SD - nVal - nrVal, FUNIT_100TH_MM );
1292             }
1293         }
1294 
1295         maTbxIndent_IncDec->Enable();
1296         maTbxIndent_IncDec->EnableItem(ID_HANGING_INDENT, sal_True);
1297         if ( maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Text)
1298              && maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Default)
1299              && maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Table) )
1300         {
1301             maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_INC, sal_True);
1302             maTbxIndent_IncDec->EnableItem(BT_TBX_INDENT_DEC, sal_True);
1303         }
1304 
1305         maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_True);
1306     }
1307     else if( eState == SFX_ITEM_DISABLED )
1308     {
1309         maLeftIndent-> Disable();
1310         maRightIndent->Disable();
1311         maFLineIndent->Disable();
1312         maTbxIndent_IncDec->Disable();
1313         if( maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Text)  &&
1314             maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Default) &&
1315             maContext.GetCombinedContext_DI() !=  CombinedEnumContext(Application_WriterVariants, Context_Table) )
1316             maTbxIndent_IncDec->Disable();
1317         else
1318             maTbxIndent_IncDec->EnableItem(ID_HANGING_INDENT, sal_False);
1319 
1320         //		maTbxProDemote->Disable();
1321         maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_False);
1322     }
1323     else
1324     {
1325         maLeftIndent->SetEmptyFieldValue();
1326         maRightIndent->SetEmptyFieldValue();
1327         maFLineIndent->SetEmptyFieldValue();
1328         if( maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Text)  &&
1329             maContext.GetCombinedContext_DI() != CombinedEnumContext(Application_WriterVariants, Context_Default) &&
1330             maContext.GetCombinedContext_DI() !=  CombinedEnumContext(Application_WriterVariants, Context_Table) )
1331             maTbxIndent_IncDec->Disable();
1332         else
1333             maTbxIndent_IncDec->EnableItem(ID_HANGING_INDENT, sal_False);
1334         maTbxProDemote->EnableItem(SD_HANGING_INDENT, sal_False);
1335     }
1336 }
1337 
1338 void ParaPropertyPanel::StateChangedLnSPImpl( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
1339 {
1340 	meLnSpState = eState;
1341 
1342 	if( pState && eState >= SFX_ITEM_AVAILABLE )
1343 	{
1344 		if(mpLnSPItem)
1345 			delete mpLnSPItem;
1346 		mpLnSPItem = ( SvxLineSpacingItem *)pState->Clone();
1347 	}
1348 }
1349 
1350 void ParaPropertyPanel::StateChangedULImpl( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
1351 {
1352 	maTopDist->SetMax( maTopDist->Normalize( MAX_DURCH ), MapToFieldUnit(m_eULSpaceUnit) );
1353 	maBottomDist->SetMax( maBottomDist->Normalize( MAX_DURCH ), MapToFieldUnit(m_eULSpaceUnit) );
1354 
1355 	if( pState && eState >= SFX_ITEM_AVAILABLE )
1356 	{
1357 		SvxULSpaceItem* pOldItem = (SvxULSpaceItem*)pState;
1358 
1359 		maUpper = pOldItem->GetUpper();
1360 		maUpper = OutputDevice::LogicToLogic( maUpper, (MapUnit)m_eULSpaceUnit, MAP_100TH_MM );
1361 		maUpper = OutputDevice::LogicToLogic( maUpper, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1362 
1363 		maLower = pOldItem->GetLower();
1364 		maLower = OutputDevice::LogicToLogic( maLower, (MapUnit)m_eULSpaceUnit, MAP_100TH_MM );
1365 		maLower = OutputDevice::LogicToLogic( maLower, MAP_100TH_MM, (MapUnit)(SFX_MAPUNIT_TWIP) );
1366 
1367 		sal_Int64 nVal = OutputDevice::LogicToLogic( maUpper, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1368 		nVal = maTopDist->Normalize( nVal );
1369 		maTopDist->SetValue( nVal, FUNIT_100TH_MM );
1370 
1371 		nVal = OutputDevice::LogicToLogic( maLower, (MapUnit)(SFX_MAPUNIT_TWIP), MAP_100TH_MM );
1372 		nVal = maBottomDist->Normalize( nVal );
1373 		maBottomDist->SetValue( nVal, FUNIT_100TH_MM );
1374 		maTbxUL_IncDec->Enable();
1375 	}
1376 	else if(eState == SFX_ITEM_DISABLED )
1377 	{
1378 		maTopDist->Disable();
1379 		maBottomDist->Disable();
1380 		maTbxUL_IncDec->Disable();
1381 	}
1382 	else
1383 	{
1384 		maTopDist->SetEmptyFieldValue();
1385 		maBottomDist->SetEmptyFieldValue();
1386 		maTbxUL_IncDec->Disable();
1387 	}
1388 }
1389 
1390 void ParaPropertyPanel::StateChangeOutLineImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1391 {
1392     if (nSID==SID_OUTLINE_LEFT)
1393 	{
1394 		if( pState && eState == SFX_ITEM_UNKNOWN )
1395 			mbOutLineLeft = 1;
1396 		else
1397 			mbOutLineLeft = 0;
1398 	}
1399 	if (nSID==SID_OUTLINE_RIGHT)
1400 	{
1401 		if( pState && eState == SFX_ITEM_UNKNOWN )
1402 			mbOutLineRight = 1;
1403 		else
1404 			mbOutLineRight = 0;
1405 	}
1406 	if(mbOutLineLeft)
1407 		maTbxProDemote->EnableItem(BT_TBX_INDENT_DEMOTE, sal_True);
1408 	else
1409 		maTbxProDemote->EnableItem(BT_TBX_INDENT_DEMOTE, sal_False);
1410 
1411 	if(mbOutLineRight)
1412 		maTbxProDemote->EnableItem(BT_TBX_INDENT_PROMOTE, sal_True);
1413 	else
1414 		maTbxProDemote->EnableItem(BT_TBX_INDENT_PROMOTE, sal_False);
1415 
1416 }
1417 
1418 void ParaPropertyPanel::StateChangeIncDecImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1419 {
1420     if ( ( maContext.GetCombinedContext_DI() == CombinedEnumContext(Application_WriterVariants, Context_Text)
1421            || maContext.GetCombinedContext_DI() == CombinedEnumContext(Application_WriterVariants, Context_Default)
1422            || maContext.GetCombinedContext_DI() ==  CombinedEnumContext(Application_WriterVariants, Context_Table) )
1423          && ( nSID == SID_INC_INDENT || nSID == SID_DEC_INDENT ) )
1424     {
1425         // Writer's text shell is the only one which provides reasonable states for Slots SID_INC_INDENT and SID_DEC_INDENT
1426         // - namely SFX_ITEM_UNKNOWN and SFX_ITEM_DISABLED
1427         maTbxIndent_IncDec->EnableItem(
1428             nSID == SID_INC_INDENT ? BT_TBX_INDENT_INC : BT_TBX_INDENT_DEC,
1429             ( pState && eState == SFX_ITEM_UNKNOWN ) ? sal_True : sal_False );
1430     }
1431 }
1432 
1433 
1434 // Add toggle state for numbering and bullet icons
1435 void ParaPropertyPanel::StateChangeBulletNumImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1436 {
1437     if ( (eState >= SFX_ITEM_DEFAULT) && (pState->ISA(SfxBoolItem)) )
1438     {
1439         const SfxBoolItem* pItem= (const SfxBoolItem*)pState;
1440         const sal_Bool aBool = (sal_Bool)pItem->GetValue();
1441         if (nSID==FN_NUM_NUMBERING_ON)
1442         {
1443             maTBxNumBullet->SetItemState(
1444                 IID_NUMBER,
1445                 aBool ? STATE_CHECK : STATE_NOCHECK );
1446         }
1447         else if (nSID==FN_NUM_BULLET_ON)
1448         {
1449             maTBxNumBullet->SetItemState(
1450                 IID_BULLET,
1451                 aBool ? STATE_CHECK : STATE_NOCHECK );
1452         }
1453     }
1454 }
1455 
1456 
1457 void ParaPropertyPanel::StateChangeBulletNumRuleImpl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1458 {
1459     if ( eState >= SFX_ITEM_DEFAULT && pState->ISA(SfxUInt16Item) )
1460     {
1461         sal_uInt16 nValue = (sal_uInt16)0xFFFF;
1462         {
1463             const SfxUInt16Item* pIt = (const SfxUInt16Item*)pState;
1464             if ( pIt )
1465                 nValue = pIt->GetValue();
1466         }
1467 
1468         if ( nSID == FN_BUL_NUM_RULE_INDEX )
1469         {
1470             mnBulletTypeIndex = nValue;
1471         }
1472         else if ( nSID == FN_NUM_NUM_RULE_INDEX )
1473         {
1474             mnNumTypeIndex = nValue;
1475         }
1476     }
1477 }
1478 
1479 
1480 FieldUnit ParaPropertyPanel::GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState )
1481 {
1482 	FieldUnit eUnit = FUNIT_NONE;
1483 
1484 	if ( pState && eState >= SFX_ITEM_DEFAULT )
1485 		eUnit = (FieldUnit)( (const SfxUInt16Item*)pState )->GetValue();
1486 	else
1487 	{
1488 		SfxViewFrame* pFrame = SfxViewFrame::Current();
1489 		SfxObjectShell* pSh = NULL;
1490 		if ( pFrame )
1491 			pSh = pFrame->GetObjectShell();
1492 		if ( pSh )  //the object shell is not always available during reload
1493 		{
1494 			SfxModule* pModule = pSh->GetModule();
1495 			if ( pModule )
1496 			{
1497 				const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
1498 				if ( pItem )
1499 					eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
1500 			}
1501 			else
1502 			{
1503 				DBG_ERRORFILE( "GetModuleFieldUnit(): no module found" );
1504 			}
1505 		}
1506 	}
1507 
1508 	return eUnit;
1509 }
1510 
1511 
1512 PopupControl* ParaPropertyPanel::CreateLineSpacingControl (PopupContainer* pParent)
1513 {
1514 	return new ParaLineSpacingControl(pParent, *this);
1515 }
1516 
1517 PopupControl* ParaPropertyPanel::CreateBulletsPopupControl (PopupContainer* pParent)
1518 {
1519 	return new ParaBulletsControl(pParent, *this);
1520 }
1521 
1522 PopupControl* ParaPropertyPanel::CreateNumberingPopupControl (PopupContainer* pParent)
1523 {
1524 	return new ParaNumberingControl(pParent, *this);
1525 }
1526 
1527 namespace
1528 {
1529     Color GetNoBackgroundColor(void)
1530     {
1531         return COL_TRANSPARENT;
1532     }
1533 } // end of anonymous namespace
1534 
1535 PopupControl* ParaPropertyPanel::CreateBGColorPopupControl (PopupContainer* pParent)
1536 {
1537     const ResId aResId(SVX_RES(STR_NOFILL));
1538 
1539     return new ColorControl(
1540         pParent,
1541         mpBindings,
1542         SVX_RES(RID_POPUPPANEL_PARAPAGE_BACK_COLOR),
1543         SVX_RES(VS_FONT_COLOR),
1544         ::boost::bind(GetNoBackgroundColor),
1545         ::boost::bind(&ParaPropertyPanel::SetBGColor, this, _1,_2),
1546         pParent,
1547         &aResId);
1548 }
1549 
1550 
1551 ParaPropertyPanel::ParaPropertyPanel(Window* pParent,
1552     const cssu::Reference<css::frame::XFrame>& rxFrame,
1553     SfxBindings* pBindings,
1554     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
1555     : Control(pParent, SVX_RES(RID_SIDEBAR_PARA_PANEL)),
1556       maAlignToolBoxBackground(ControlFactory::CreateToolBoxBackground(this)),
1557       maAlignToolBox (ControlFactory::CreateToolBox(maAlignToolBoxBackground.get(),SVX_RES(TBX_HORIZONTALALIGNMENT))),
1558       maTBxVertAlignBackground(ControlFactory::CreateToolBoxBackground(this)),
1559       maTBxVertAlign (ControlFactory::CreateToolBox(maTBxVertAlignBackground.get(),SVX_RES(TBX_VERT_ALIGN))),
1560       maTBxNumBulletBackground(ControlFactory::CreateToolBoxBackground(this)),
1561       maTBxNumBullet (ControlFactory::CreateToolBox(maTBxNumBulletBackground.get(),SVX_RES(TBX_NUM_BULLET))),
1562       maTBxBackColorBackground(ControlFactory::CreateToolBoxBackground(this)),
1563       maTBxBackColor (ControlFactory::CreateToolBox(maTBxBackColorBackground.get(),SVX_RES(TBX_BACK_COLOR))),
1564       maFTUL (new FixedText(this, SVX_RES(FT_SPACING))),
1565       maTbxUL_IncDecBackground(ControlFactory::CreateToolBoxBackground(this)),
1566       maTbxUL_IncDec (ControlFactory::CreateToolBox(maTbxUL_IncDecBackground.get(),SVX_RES(TBX_UL_INC_DEC))),
1567       maFTIndent (new FixedText(this, SVX_RES(FT_INDENT))),
1568       maTbxIndent_IncDecBackground(ControlFactory::CreateToolBoxBackground(this)),
1569       maTbxIndent_IncDec (ControlFactory::CreateToolBox(maTbxIndent_IncDecBackground.get(),SVX_RES(TBX_INDENT_INC_DEC))),
1570 
1571       maTopDist (new SvxRelativeField(this, SVX_RES(MF_ABOVE_PARASPACING))),
1572       maLeftIndent (new SvxRelativeField(this, SVX_RES(MF_BEFORE_INDENT))),
1573 
1574       maBottomDist (new SvxRelativeField(this, SVX_RES(MF_BELOW_PARASPACING))),
1575       maRightIndent (new SvxRelativeField(this, SVX_RES(MF_AFTER_INDENT))),
1576 
1577       maLineSPTbxBackground(ControlFactory::CreateToolBoxBackground(this)),
1578       maLineSPTbx (ControlFactory::CreateToolBox(maLineSPTbxBackground.get(),SVX_RES(TBX_LINESP))),
1579       maFLineIndent (new SvxRelativeField(this, SVX_RES(MF_FL_INDENT))),
1580 
1581       maTbxProDemoteBackground(ControlFactory::CreateToolBoxBackground(this)),
1582       maTbxProDemote (ControlFactory::CreateToolBox(maTbxProDemoteBackground.get(),SVX_RES(TBX_INDENT_PRO_DEMOTE))),
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       maIndHang (SVX_RES(IMG_INDENT_HANG)),
1596       maParInc (SVX_RES(IMG_PARA_INC)),
1597       maParDec (SVX_RES(IMG_PARA_DEC)),
1598       maNumBImageList (SVX_RES(IL_NUM_BULLET)),
1599       maNumBImageListH (SVX_RES(ILH_NUM_BULLET)),
1600       maNumBImageListRTL (SVX_RES(IL_NUM_BULLET_RTL)),
1601       maImgBackColorHigh (SVX_RES(IMG_BACK_COLOR_H)),
1602       maImgBackColor (SVX_RES(IMG_BACK_COLOR)),
1603       maTxtLeft (0),
1604       mpLnSPItem (NULL),
1605       meLnSpState (SFX_ITEM_DONTCARE),
1606       mbOutLineLeft (false),
1607       mbOutLineRight (false),
1608       maUpper (0),
1609       maLower (0),
1610       mnBulletTypeIndex ((sal_uInt16)0xFFFF),
1611       mnNumTypeIndex ((sal_uInt16)0xFFFF),
1612       maColor (COL_AUTO),
1613       mbColorAvailable (true),
1614       m_eLRSpaceUnit(),
1615       m_eULSpaceUnit(),
1616       maLeftAlignControl(SID_ATTR_PARA_ADJUST_LEFT, *pBindings, *this, A2S("LeftPara"), rxFrame),
1617       maCenterAlignControl(SID_ATTR_PARA_ADJUST_CENTER, *pBindings, *this, A2S("CenterPara"), rxFrame),
1618       maRightAlignControl(SID_ATTR_PARA_ADJUST_RIGHT, *pBindings, *this, A2S("RightPara"), rxFrame),
1619       maJustifyAlignControl(SID_ATTR_PARA_ADJUST_BLOCK, *pBindings, *this, A2S("JustifyPara"), rxFrame),
1620       maLRSpaceControl (SID_ATTR_PARA_LRSPACE,*pBindings,*this),
1621       maLNSpaceControl (SID_ATTR_PARA_LINESPACE, *pBindings,*this),
1622       maULSpaceControl (SID_ATTR_PARA_ULSPACE, *pBindings,*this),
1623       maOutLineLeftControl(SID_OUTLINE_LEFT, *pBindings, *this, A2S("OutlineRight"), rxFrame),
1624       maOutLineRightControl(SID_OUTLINE_RIGHT, *pBindings, *this, A2S("OutlineLeft"), rxFrame),
1625       maDecIndentControl(SID_DEC_INDENT, *pBindings,*this, A2S("DecrementIndent"), rxFrame),
1626       maIncIndentControl(SID_INC_INDENT, *pBindings,*this, A2S("IncrementIndent"), rxFrame),
1627       maVertTop (SID_TABLE_VERT_NONE, *pBindings, *this, A2S("CellVertTop"), rxFrame),
1628       maVertCenter (SID_TABLE_VERT_CENTER, *pBindings,*this, A2S("CellVertCenter"), rxFrame),
1629       maVertBottom (SID_TABLE_VERT_BOTTOM,*pBindings,*this, A2S("CellVertBottom"), rxFrame),
1630       maBulletOnOff(FN_NUM_BULLET_ON, *pBindings, *this, A2S("DefaultBullet"), rxFrame),
1631       maNumberOnOff(FN_NUM_NUMBERING_ON, *pBindings, *this, A2S("DefaultNumbering"), rxFrame),
1632       maBackColorControl (SID_BACKGROUND_COLOR,	*pBindings,*this),
1633       m_aMetricCtl (SID_ATTR_METRIC, *pBindings,*this),
1634       maBulletNumRuleIndex (FN_BUL_NUM_RULE_INDEX, *pBindings,*this),
1635       maNumNumRuleIndex (FN_NUM_NUM_RULE_INDEX, *pBindings,*this),
1636       mxFrame(rxFrame),
1637       maContext(),
1638       mpBindings(pBindings),
1639       maLineSpacePopup(this, ::boost::bind(&ParaPropertyPanel::CreateLineSpacingControl, this, _1)),
1640       maBulletsPopup(this, ::boost::bind(&ParaPropertyPanel::CreateBulletsPopupControl, this, _1)),
1641       maNumberingPopup(this, ::boost::bind(&ParaPropertyPanel::CreateNumberingPopupControl, this, _1)),
1642       maBGColorPopup(this, ::boost::bind(&ParaPropertyPanel::CreateBGColorPopupControl, this, _1)),
1643       mxSidebar(rxSidebar)
1644 {
1645 	initial();
1646 	FreeResource();
1647 }
1648 
1649 } } // end of namespace svx::sidebar
1650