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