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