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 
24 #include "TextPropertyPanel.hrc"
25 #include "TextPropertyPanel.hxx"
26 #include "SvxSBFontNameBox.hxx"
27 
28 #include "svx/dialmgr.hxx"
29 
30 #include <editeng/brshitem.hxx>
31 #include <editeng/colritem.hxx>
32 #include <editeng/crsditem.hxx>
33 #include <editeng/escpitem.hxx>
34 #include <editeng/flstitem.hxx>
35 #include <editeng/fontitem.hxx>
36 #include <editeng/kernitem.hxx>
37 #include <editeng/postitem.hxx>
38 #include <editeng/shdditem.hxx>
39 #include <editeng/udlnitem.hxx>
40 #include <editeng/wghtitem.hxx>
41 #include <rtl/ref.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <sfx2/viewsh.hxx>
45 #include <sfx2/sidebar/propertypanel.hrc>
46 #include <sfx2/sidebar/ControlFactory.hxx>
47 #include <sfx2/sidebar/Theme.hxx>
48 #include "sfx2/imagemgr.hxx"
49 #include <svtools/ctrltool.hxx>
50 #include <svtools/unitconv.hxx>
51 
52 #include <vcl/gradient.hxx>
53 #include <vcl/svapp.hxx>
54 #include <vcl/toolbox.hxx>
55 #include "TextCharacterSpacingControl.hxx"
56 #include "TextCharacterSpacingPopup.hxx"
57 #include "TextUnderlineControl.hxx"
58 #include "TextUnderlinePopup.hxx"
59 #include <svx/sidebar/ColorControl.hxx>
60 #include <svx/sidebar/PopupContainer.hxx>
61 
62 #include <boost/bind.hpp>
63 
64 using namespace css;
65 using namespace cssu;
66 using ::sfx2::sidebar::Theme;
67 using ::sfx2::sidebar::ControlFactory;
68 
69 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
70 
71 namespace svx { namespace sidebar {
72 
73 #undef HAS_IA2
74 
75 
76 #define FONT_CONTROL_WIDTH 		160
77 #define SIZE_CONTROL_WIDTH 		80
78 #define CONTROL_COMBOX_HEIGHT	20
79 #define CONTROL_HEIGHT_5X  		120
80 
81 
82 #define TEXT_SECTIONPAGE_HEIGHT_S   SECTIONPAGE_MARGIN_VERTICAL_TOP + CBOX_HEIGHT  + ( TOOLBOX_ITEM_HEIGHT + 2 ) + CONTROL_SPACING_VERTICAL * 1 + SECTIONPAGE_MARGIN_VERTICAL_BOT
83 #define TEXT_SECTIONPAGE_HEIGHT		SECTIONPAGE_MARGIN_VERTICAL_TOP + CBOX_HEIGHT  + ( TOOLBOX_ITEM_HEIGHT + 2 ) * 2 + CONTROL_SPACING_VERTICAL * 2 + SECTIONPAGE_MARGIN_VERTICAL_BOT
84 
85 //
86 
87 //end
88 PopupControl* TextPropertyPanel::CreateCharacterSpacingControl (PopupContainer* pParent)
89 {
90     return new TextCharacterSpacingControl(pParent, *this, mpBindings);
91 }
92 
93 PopupControl* TextPropertyPanel::CreateUnderlinePopupControl (PopupContainer* pParent)
94 {
95 	return new TextUnderlineControl(pParent, *this, mpBindings);
96 }
97 
98 namespace
99 {
100     Color GetAutomaticColor(void)
101     {
102         return COL_AUTO;
103     }
104 } // end of anonymous namespace
105 
106 PopupControl* TextPropertyPanel::CreateFontColorPopupControl (PopupContainer* pParent)
107 {
108     const ResId aResId(SVX_RES(STR_AUTOMATICE));
109 
110     return new ColorControl(
111         pParent,
112         mpBindings,
113         SVX_RES(RID_POPUPPANEL_TEXTPAGE_FONT_COLOR),
114         SVX_RES(VS_FONT_COLOR),
115         ::boost::bind(GetAutomaticColor),
116         ::boost::bind(&TextPropertyPanel::SetFontColor, this, _1,_2),
117         pParent,
118         &aResId);
119 }
120 
121 PopupControl* TextPropertyPanel::CreateBrushColorPopupControl (PopupContainer* pParent)
122 {
123     const ResId aResId(SVX_RES(STR_AUTOMATICE));
124 
125     return new ColorControl(
126         pParent,
127         mpBindings,
128         SVX_RES(RID_POPUPPANEL_TEXTPAGE_FONT_COLOR),
129         SVX_RES(VS_FONT_COLOR),
130         ::boost::bind(GetAutomaticColor),
131         ::boost::bind(&TextPropertyPanel::SetBrushColor, this, _1,_2),
132         pParent,
133         &aResId);
134 }
135 
136 long TextPropertyPanel::GetSelFontSize()
137 {
138     long nH = 240;
139     SfxMapUnit eUnit = maSpacingControl.GetCoreMetric();
140     if (mpHeightItem)
141         nH = LogicToLogic(  mpHeightItem->GetHeight(), (MapUnit)eUnit, MAP_TWIP );
142     return nH;
143 }
144 
145 
146 TextPropertyPanel* TextPropertyPanel::Create (
147     Window* pParent,
148     const cssu::Reference<css::frame::XFrame>& rxFrame,
149     SfxBindings* pBindings,
150     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
151 {
152     if (pParent == NULL)
153         throw lang::IllegalArgumentException(A2S("no parent Window given to TextPropertyPanel::Create"), NULL, 0);
154     if ( ! rxFrame.is())
155         throw lang::IllegalArgumentException(A2S("no XFrame given to TextPropertyPanel::Create"), NULL, 1);
156     if (pBindings == NULL)
157         throw lang::IllegalArgumentException(A2S("no SfxBindings given to TextPropertyPanel::Create"), NULL, 2);
158 
159     return new TextPropertyPanel(
160         pParent,
161         rxFrame,
162         pBindings,
163         rxSidebar);
164 }
165 
166 
167 ::sfx2::sidebar::ControllerItem& TextPropertyPanel::GetSpaceController()
168 {
169 	return maSpacingControl;
170 }
171 
172 TextPropertyPanel::TextPropertyPanel (
173     Window* pParent,
174     const cssu::Reference<css::frame::XFrame>& rxFrame,
175     SfxBindings* pBindings,
176     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
177     :	Control(pParent, SVX_RES(RID_SIDEBAR_TEXT_PANEL)),
178         mpFontNameBox (new SvxSBFontNameBox(this, SVX_RES(CB_SBFONT_FONT))),
179     	maFontSizeBox		(this, SVX_RES(MB_SBFONT_FONTSIZE)),
180     	mpToolBoxIncDecBackground(ControlFactory::CreateToolBoxBackground(this)),
181     	mpToolBoxIncDec(ControlFactory::CreateToolBox(
182                 mpToolBoxIncDecBackground.get(),
183                 SVX_RES(TB_INCREASE_DECREASE))),
184         mpToolBoxFontBackground(ControlFactory::CreateToolBoxBackground(this)),
185         mpToolBoxFont(ControlFactory::CreateToolBox(
186                 mpToolBoxFontBackground.get(),
187                 SVX_RES(TB_FONT))),
188         mpToolBoxFontColorBackground(ControlFactory::CreateToolBoxBackground(this)),
189         mpToolBoxFontColor(ControlFactory::CreateToolBox(
190                 mpToolBoxFontColorBackground.get(),
191                 SVX_RES(TB_FONTCOLOR))),
192         mpToolBoxScriptBackground(ControlFactory::CreateToolBoxBackground(this)),
193         mpToolBoxScript(ControlFactory::CreateToolBox(
194                 mpToolBoxScriptBackground.get(),
195                 SVX_RES(TB_SCRIPT))),
196         mpToolBoxScriptSwBackground(ControlFactory::CreateToolBoxBackground(this)),
197         mpToolBoxScriptSw(ControlFactory::CreateToolBox(
198                 mpToolBoxScriptSwBackground.get(),
199                 SVX_RES(TB_SCRIPT_SW))),
200         mpToolBoxSpacingBackground(ControlFactory::CreateToolBoxBackground(this)),
201         mpToolBoxSpacing(ControlFactory::CreateToolBox(
202                 mpToolBoxSpacingBackground.get(),
203                 SVX_RES(TB_SPACING))),
204         mpToolBoxHighlightBackground(ControlFactory::CreateToolBoxBackground(this)),
205         mpToolBoxHighlight(ControlFactory::CreateToolBox(
206                 mpToolBoxHighlightBackground.get(),
207                 SVX_RES(TB_HIGHLIGHT))),
208         mpFontColorUpdater(),
209         mpHighlightUpdater(),
210 
211         maFontNameControl	(SID_ATTR_CHAR_FONT,		*pBindings, *this, A2S("CharFontName"), rxFrame),
212         maFontSizeControl	(SID_ATTR_CHAR_FONTHEIGHT,	*pBindings, *this, A2S("FontHeight"),   rxFrame),
213         maWeightControl		(SID_ATTR_CHAR_WEIGHT,		*pBindings, *this, A2S("Bold"),         rxFrame),
214         maItalicControl		(SID_ATTR_CHAR_POSTURE,		*pBindings, *this, A2S("Italic"),       rxFrame),
215         maUnderlineControl	(SID_ATTR_CHAR_UNDERLINE,	*pBindings, *this, A2S("Underline"),    rxFrame),
216         maStrikeControl		(SID_ATTR_CHAR_STRIKEOUT,	*pBindings, *this, A2S("Strikeout"),    rxFrame),
217         maShadowControl		(SID_ATTR_CHAR_SHADOWED,	*pBindings, *this, A2S("Shadowed"),     rxFrame),
218         maFontColorControl	(SID_ATTR_CHAR_COLOR,		*pBindings, *this, A2S("Color"),        rxFrame),
219         maScriptControlSw	(SID_ATTR_CHAR_ESCAPEMENT,	*pBindings, *this, A2S("Escapement"),   rxFrame),
220         maSuperScriptControl(SID_SET_SUPER_SCRIPT,		*pBindings, *this, A2S("SuperScript"),  rxFrame),
221         maSubScriptControl	(SID_SET_SUB_SCRIPT,		*pBindings, *this, A2S("SubScript"),    rxFrame),
222         maSpacingControl	(SID_ATTR_CHAR_KERNING,		*pBindings, *this, A2S("Spacing"),      rxFrame),
223         maHighlightControl	(SID_ATTR_BRUSH_CHAR, *pBindings, *this, A2S("CharacterBackgroundPattern"),rxFrame),
224         maSDFontGrow		(SID_GROW_FONT_SIZE,		*pBindings, *this, A2S("Grow"),         rxFrame),
225         maSDFontShrink		(SID_SHRINK_FONT_SIZE,		*pBindings, *this, A2S("Shrink"),       rxFrame),
226 
227         mpFontList			(NULL),
228         mbMustDelete		(false),
229         mbFocusOnFontSizeCtrl(false),
230         maCharSpacePopup(this, ::boost::bind(&TextPropertyPanel::CreateCharacterSpacingControl, this, _1)),
231         maUnderlinePopup(this, ::boost::bind(&TextPropertyPanel::CreateUnderlinePopupControl, this, _1)),
232         maFontColorPopup(this, ::boost::bind(&TextPropertyPanel::CreateFontColorPopupControl, this, _1)),
233         maBrushColorPopup(this, ::boost::bind(&TextPropertyPanel::CreateBrushColorPopupControl, this, _1)),
234         mxFrame(rxFrame),
235         maContext(),
236         mpBindings(pBindings),
237         mxSidebar(rxSidebar)
238 {
239 	Initialize();
240 	FreeResource();
241 }
242 
243 
244 
245 
246 TextPropertyPanel::~TextPropertyPanel (void)
247 {
248     if(mbMustDelete)
249         delete mpFontList;
250 
251     // Destroy the toolbox windows.
252     mpToolBoxIncDec.reset();
253     mpToolBoxFont.reset();
254     mpToolBoxFontColor.reset();
255     mpToolBoxScript.reset();
256     mpToolBoxScriptSw.reset();
257     mpToolBoxSpacing.reset();
258     mpToolBoxHighlight.reset();
259 
260     // Destroy the background windows of the toolboxes.
261     mpToolBoxIncDecBackground.reset();
262     mpToolBoxFontBackground.reset();
263     mpToolBoxFontColorBackground.reset();
264     mpToolBoxScriptBackground.reset();
265     mpToolBoxScriptSwBackground.reset();
266     mpToolBoxSpacingBackground.reset();
267     mpToolBoxHighlightBackground.reset();
268 }
269 
270 
271 
272 
273 void TextPropertyPanel::SetSpacing(long nKern)
274 {
275 	mlKerning = nKern;
276 }
277 
278 
279 void TextPropertyPanel::HandleContextChange (
280     const ::sfx2::sidebar::EnumContext aContext)
281 {
282     if (maContext == aContext)
283     {
284         // Nothing to do.
285         return;
286     }
287 
288     maContext = aContext;
289     switch (maContext.GetCombinedContext_DI()) //
290     {
291         case CombinedEnumContext(Application_Calc, Context_Cell):
292         case CombinedEnumContext(Application_Calc, Context_Pivot):
293         {
294             mpToolBoxScript->Hide();
295 		    mpToolBoxScriptSw->Hide();
296             mpToolBoxSpacing->Hide();
297             mpToolBoxHighlight->Hide();
298 
299             Size aSize(PROPERTYPAGE_WIDTH,TEXT_SECTIONPAGE_HEIGHT_S);
300             aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
301             aSize.setWidth(GetOutputSizePixel().Width());
302             SetSizePixel(aSize);
303             if (mxSidebar.is())
304                 mxSidebar->requestLayout();
305             break;
306         }
307 
308         case CombinedEnumContext(Application_WriterVariants, Context_Text):
309         case CombinedEnumContext(Application_WriterVariants, Context_Table):
310         {
311             mpToolBoxScriptSw->Show();
312             mpToolBoxScript->Hide();
313             mpToolBoxHighlight->Show();
314             mpToolBoxSpacing->Show();
315 
316             Size aSize(PROPERTYPAGE_WIDTH, TEXT_SECTIONPAGE_HEIGHT);
317             aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
318             aSize.setWidth(GetOutputSizePixel().Width());
319             SetSizePixel(aSize);
320             if (mxSidebar.is())
321                 mxSidebar->requestLayout();
322             break;
323         }
324 
325         case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
326         case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
327         {
328             mpToolBoxScriptSw->Show();
329             mpToolBoxScript->Hide();
330             mpToolBoxSpacing->Show();
331             mpToolBoxHighlight->Hide();
332 
333             Size aSize(PROPERTYPAGE_WIDTH,TEXT_SECTIONPAGE_HEIGHT);
334             aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
335             aSize.setWidth(GetOutputSizePixel().Width());
336             SetSizePixel(aSize);
337             if (mxSidebar.is())
338                 mxSidebar->requestLayout();
339             break;
340         }
341 
342         case CombinedEnumContext(Application_Calc, Context_EditCell):
343         case CombinedEnumContext(Application_Calc, Context_DrawText):
344         case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
345         case CombinedEnumContext(Application_DrawImpress, Context_Text):
346         case CombinedEnumContext(Application_DrawImpress, Context_Table):
347         case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
348         case CombinedEnumContext(Application_DrawImpress, Context_Draw):
349         case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
350         case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
351         {
352             mpToolBoxScriptSw->Hide();
353             mpToolBoxScript->Show();
354             mpToolBoxSpacing->Show();
355             mpToolBoxHighlight->Hide();
356 
357             Size aSize(PROPERTYPAGE_WIDTH,TEXT_SECTIONPAGE_HEIGHT);
358             aSize = LogicToPixel( aSize,MapMode(MAP_APPFONT) );
359             aSize.setWidth(GetOutputSizePixel().Width());
360             SetSizePixel(aSize);
361             if (mxSidebar.is())
362                 mxSidebar->requestLayout();
363             break;
364         }
365 
366         default:
367             break;
368     }
369 }
370 
371 
372 
373 
374 void TextPropertyPanel::DataChanged (const DataChangedEvent& rEvent)
375 {
376     (void)rEvent;
377 
378     SetupToolboxItems();
379 }
380 
381 
382 
383 void TextPropertyPanel::Initialize (void)
384 {
385     //<<modify fill font list
386     SfxObjectShell* pDocSh = SfxObjectShell::Current();
387     const SfxPoolItem* pItem = NULL;
388 
389     if (pDocSh != NULL)
390         pItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
391     if (pItem != NULL)
392         mpFontList = ( (SvxFontListItem*)pItem )->GetFontList();
393     else
394     {
395         mpFontList = new FontList( Application::GetDefaultDevice() );
396         mbMustDelete = true;
397     }
398 
399     mpFontNameBox->SetAccessibleName(mpFontNameBox->GetQuickHelpText());
400     const FontInfo aFontInfo (mpFontList->Get( String::CreateFromAscii( "" ), String::CreateFromAscii( "" )));
401     maFontSizeBox.Fill(&aFontInfo,mpFontList);
402     maFontSizeBox.SetAccessibleName(maFontSizeBox.GetQuickHelpText());
403 
404 	//toolbox
405     SetupToolboxItems();
406     InitToolBoxIncDec();
407     InitToolBoxFont();
408     InitToolBoxFontColor();
409     InitToolBoxScript();
410     InitToolBoxSpacing();
411     InitToolBoxHighlight();
412 
413 #ifdef HAS_IA2
414     mpFontNameBox->SetAccRelationLabeledBy(&mpFontNameBox);
415     mpFontNameBox->SetMpSubEditAccLableBy(&mpFontNameBox);
416     maFontSizeBox.SetAccRelationLabeledBy(&maFontSizeBox);
417     maFontSizeBox.SetMpSubEditAccLableBy(&maFontSizeBox);
418     mpToolBoxFont.SetAccRelationLabeledBy(&mpToolBoxFont);
419     mpToolBoxIncDec.SetAccRelationLabeledBy(&mpToolBoxIncDec);
420     mpToolBoxFontColor.SetAccRelationLabeledBy(&mpToolBoxFontColor);
421     mpToolBoxScript.SetAccRelationLabeledBy(&mpToolBoxScript);
422     mpToolBoxScriptSw.SetAccRelationLabeledBy(&mpToolBoxScriptSw);
423     mpToolBoxSpacing.SetAccRelationLabeledBy(&mpToolBoxSpacing);
424     mpToolBoxHighlight.SetAccRelationLabeledBy(&mpToolBoxHighlight);
425 #endif
426 
427     //init state
428     mpHeightItem = NULL;
429     meWeight = WEIGHT_NORMAL;
430     meItalic = ITALIC_NONE;
431     mbShadow = false;
432     meStrike = STRIKEOUT_NONE;
433     mbPostureAvailable = true;
434     mbWeightAvailable = true;
435     meUnderline = UNDERLINE_NONE;
436     meUnderlineColor = COL_AUTO;   //
437     maColor = COL_BLACK;
438     mbColorAvailable = true;
439     maBackColor = COL_AUTO;
440     mbBackColorAvailable = true;
441     meColorType = FONT_COLOR;
442     meEscape = SVX_ESCAPEMENT_OFF;
443     mbSuper = false;
444     mbSub = false;
445     mbKernAvailable = true;
446     mbKernLBAvailable = true;
447     mlKerning = 0;
448     mpFontColorUpdater.reset(new ToolboxButtonColorUpdater(
449             SID_ATTR_CHAR_COLOR,
450             TBI_FONTCOLOR,
451             mpToolBoxFontColor.get(),
452             TBX_UPDATER_MODE_CHAR_COLOR_NEW));
453     mpHighlightUpdater.reset(new ToolboxButtonColorUpdater(
454             SID_ATTR_BRUSH_CHAR,
455             TBI_HIGHLIGHT,
456             mpToolBoxHighlight.get(),
457             TBX_UPDATER_MODE_CHAR_COLOR_NEW));
458 
459     //set handler
460     mpFontNameBox->SetBindings(mpBindings);
461     //add
462     Link aLink = LINK(this, TextPropertyPanel, FontSelHdl);
463     mpFontNameBox->SetSelectHdl(aLink);
464     //add end
465 
466     aLink = LINK(this, TextPropertyPanel, FontSizeModifyHdl);
467     maFontSizeBox.SetModifyHdl(aLink);
468     //add
469     aLink = LINK(this, TextPropertyPanel, FontSizeSelHdl);
470     maFontSizeBox.SetSelectHdl(aLink);
471     //add end
472     aLink = LINK(this, TextPropertyPanel, FontSizeLoseFocus);
473     maFontSizeBox.SetLoseFocusHdl(aLink);
474 
475     // add
476     long aSizeBoxHeight = maFontSizeBox.GetSizePixel().getHeight();;
477     Point aPosFontSize = maFontSizeBox.GetPosPixel();
478     long aPosY = aPosFontSize.getY();
479     Point pTBIncDec = mpToolBoxIncDec->GetPosPixel();
480     long aIncDecHeight = mpToolBoxIncDec->GetSizePixel().getHeight();
481     pTBIncDec.setY(aPosY+aSizeBoxHeight/2-aIncDecHeight/2);
482     mpToolBoxIncDec->SetPosPixel(pTBIncDec);
483     //end
484 }
485 
486 void TextPropertyPanel::EndSpacingPopupMode (void)
487 {
488     maCharSpacePopup.Hide();
489 }
490 
491 void TextPropertyPanel::EndUnderlinePopupMode (void)
492 {
493 	maUnderlinePopup.Hide();
494 }
495 
496 
497 void TextPropertyPanel::InitToolBoxFont()
498 {
499 	mpToolBoxFont->SetBackground(Wallpaper());
500 	mpToolBoxFont->SetPaintTransparent(true);
501 
502 	Size aTbxSize( mpToolBoxFont->CalcWindowSizePixel() );
503 	mpToolBoxFont->SetOutputSizePixel( aTbxSize );
504 
505 	Link aLink  = LINK(this, TextPropertyPanel, ToolboxFontSelectHandler);
506 	mpToolBoxFont->SetSelectHdl ( aLink );
507 	aLink = LINK(this, TextPropertyPanel, ToolBoxUnderlineClickHdl);
508 	mpToolBoxFont->SetDropdownClickHdl(aLink);
509 }
510 
511 
512 
513 
514 void TextPropertyPanel::InitToolBoxIncDec()
515 {
516 	Size aTbxSize( mpToolBoxIncDec->CalcWindowSizePixel() );
517 	mpToolBoxIncDec->SetOutputSizePixel( aTbxSize );
518 
519 	Link aLink = LINK(this, TextPropertyPanel, ToolboxIncDecSelectHdl);
520     mpToolBoxIncDec->SetSelectHdl ( aLink );
521 }
522 
523 
524 
525 
526 void TextPropertyPanel::InitToolBoxFontColor()
527 {
528 	Size aTbxSize( mpToolBoxFontColor->CalcWindowSizePixel() );
529 	mpToolBoxFontColor->SetOutputSizePixel( aTbxSize );
530 	mpToolBoxFontColor->SetItemBits( TBI_FONTCOLOR, mpToolBoxFontColor->GetItemBits( TBI_FONTCOLOR ) | TIB_DROPDOWNONLY );
531 
532 	Link aLink = LINK(this, TextPropertyPanel, ToolBoxFontColorDropHdl);
533     mpToolBoxFontColor->SetDropdownClickHdl ( aLink );
534 	mpToolBoxFontColor->SetSelectHdl ( aLink );
535 
536 }
537 void TextPropertyPanel::InitToolBoxScript()
538 {
539 	Size aTbxSize( mpToolBoxScriptSw->CalcWindowSizePixel() );
540 	mpToolBoxScriptSw->SetOutputSizePixel( aTbxSize );
541 
542 	Link aLink = LINK(this, TextPropertyPanel, ToolBoxSwScriptSelectHdl);
543     mpToolBoxScriptSw->SetSelectHdl ( aLink );
544 
545 	aTbxSize = mpToolBoxScript->CalcWindowSizePixel() ;
546 	mpToolBoxScript->SetOutputSizePixel( aTbxSize );
547 
548 	aLink = LINK(this, TextPropertyPanel, ToolBoxScriptSelectHdl);
549     mpToolBoxScript->SetSelectHdl ( aLink );
550 }
551 void TextPropertyPanel::InitToolBoxSpacing()
552 {
553 	Size aTbxSize( mpToolBoxSpacing->CalcWindowSizePixel() );
554 	mpToolBoxSpacing->SetOutputSizePixel( aTbxSize );
555 	mpToolBoxSpacing->SetItemBits( TBI_SPACING, mpToolBoxSpacing->GetItemBits( TBI_SPACING ) | TIB_DROPDOWNONLY );
556 
557 	Link aLink = LINK(this, TextPropertyPanel, SpacingClickHdl);
558     mpToolBoxSpacing->SetDropdownClickHdl ( aLink );
559 	mpToolBoxSpacing->SetSelectHdl( aLink );
560 }
561 void TextPropertyPanel::InitToolBoxHighlight()
562 {
563 	Size aTbxSize( mpToolBoxHighlight->CalcWindowSizePixel() );
564 	mpToolBoxHighlight->SetOutputSizePixel( aTbxSize );
565 	mpToolBoxHighlight->SetItemBits( TBI_HIGHLIGHT, mpToolBoxHighlight->GetItemBits( TBI_HIGHLIGHT ) | TIB_DROPDOWNONLY );
566 
567 	Link aLink = LINK(this, TextPropertyPanel, ToolBoxHighlightDropHdl);
568     mpToolBoxHighlight->SetDropdownClickHdl ( aLink );
569 	mpToolBoxHighlight->SetSelectHdl( aLink );
570 }
571 
572 
573 
574 
575 void TextPropertyPanel::SetupToolboxItems (void)
576 {
577     maSDFontGrow.SetupToolBoxItem(*mpToolBoxIncDec, TBI_INCREASE);
578     maSDFontShrink.SetupToolBoxItem(*mpToolBoxIncDec, TBI_DECREASE);
579 
580     maWeightControl.SetupToolBoxItem(*mpToolBoxFont, TBI_BOLD);
581 	maItalicControl.SetupToolBoxItem(*mpToolBoxFont, TBI_ITALIC);
582 	maUnderlineControl.SetupToolBoxItem(*mpToolBoxFont, TBI_UNDERLINE);
583 	maStrikeControl.SetupToolBoxItem(*mpToolBoxFont, TBI_STRIKEOUT);
584 	maShadowControl.SetupToolBoxItem(*mpToolBoxFont, TBI_SHADOWED);
585 
586     maFontColorControl.SetupToolBoxItem(*mpToolBoxFontColor, TBI_FONTCOLOR);
587     //for sw
588     maSuperScriptControl.SetupToolBoxItem(*mpToolBoxScriptSw, TBI_SUPER_SW);
589     maSubScriptControl.SetupToolBoxItem(*mpToolBoxScriptSw, TBI_SUB_SW);
590     //for sc and sd
591     maSubScriptControl.SetupToolBoxItem(*mpToolBoxScript, TBI_SUPER);
592     maSubScriptControl.SetupToolBoxItem(*mpToolBoxScript, TBI_SUB);
593     maSpacingControl.SetupToolBoxItem(*mpToolBoxSpacing, TBI_SPACING);
594     maHighlightControl.SetupToolBoxItem(*mpToolBoxHighlight, TBI_HIGHLIGHT);
595 }
596 
597 
598 
599 
600 IMPL_LINK( TextPropertyPanel, FontSelHdl, FontNameBox*, pBox )
601 {
602 	if ( !pBox->IsTravelSelect() )
603 	{
604 		if( SfxViewShell::Current() )
605 		{
606 			Window* pShellWnd = SfxViewShell::Current()->GetWindow();
607 
608 			if ( pShellWnd )
609 				pShellWnd->GrabFocus();
610 		}
611 	}
612 	return 0;
613 }
614 //add end
615 IMPL_LINK( TextPropertyPanel, FontSizeModifyHdl, FontSizeBox*, pSizeBox )
616 {
617 	if (pSizeBox == &maFontSizeBox)
618 	{
619 		long nSize = pSizeBox->GetValue();
620 		mbFocusOnFontSizeCtrl = true;
621 
622 		float fSize = (float)nSize / 10;
623 		SfxMapUnit eUnit = maFontSizeControl.GetCoreMetric();
624 		SvxFontHeightItem aItem( CalcToUnit( fSize, eUnit ), 100, SID_ATTR_CHAR_FONTHEIGHT ) ;
625 
626 		mpBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_FONTHEIGHT, SFX_CALLMODE_RECORD, &aItem, 0L );
627 		mpBindings->Invalidate(SID_ATTR_CHAR_FONTHEIGHT,true,false);
628 	}
629 	return 0;
630 }
631 //add
632 IMPL_LINK( TextPropertyPanel, FontSizeSelHdl, FontSizeBox*, pSizeBox )
633 {
634 	if ( !pSizeBox->IsTravelSelect() )
635 	{
636 		if( SfxViewShell::Current() )
637 		{
638 			Window* pShellWnd = SfxViewShell::Current()->GetWindow();
639 
640 			if ( pShellWnd )
641 				pShellWnd->GrabFocus();
642 		}
643 	}
644 
645 	return 0;
646 }
647 //add end
648 IMPL_LINK(TextPropertyPanel, FontSizeLoseFocus, FontSizeBox*, pSizeBox)
649 {
650 	if(pSizeBox == &maFontSizeBox)
651 	{
652 		mbFocusOnFontSizeCtrl = false;
653 	}
654 	return 0;
655 }
656 
657 IMPL_LINK(TextPropertyPanel, ToolboxFontSelectHandler, ToolBox*, pToolBox)
658 {
659 	const sal_uInt16 nId = pToolBox->GetCurItemId();
660 
661 	switch (nId)
662     {
663         case TBI_BOLD:
664         {
665             EndTracking();
666             if(meWeight != WEIGHT_BOLD)
667                 meWeight = WEIGHT_BOLD;
668             else
669                 meWeight = WEIGHT_NORMAL;
670             SvxWeightItem aWeightItem(meWeight, SID_ATTR_CHAR_WEIGHT);
671             mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_WEIGHT, SFX_CALLMODE_RECORD, &aWeightItem, 0L);
672             UpdateItem(SID_ATTR_CHAR_WEIGHT);
673             break;
674         }
675         case TBI_ITALIC:
676         {
677             EndTracking();
678             if(meItalic != ITALIC_NORMAL)
679                 meItalic = ITALIC_NORMAL;
680             else
681                 meItalic = ITALIC_NONE;
682             SvxPostureItem aPostureItem(meItalic, SID_ATTR_CHAR_POSTURE);
683             mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_POSTURE, SFX_CALLMODE_RECORD, &aPostureItem, 0L);
684             UpdateItem(SID_ATTR_CHAR_POSTURE);
685             break;
686         }
687         case TBI_UNDERLINE:
688         {
689             EndTracking();
690             if(meUnderline == UNDERLINE_NONE)
691             {
692                 meUnderline = UNDERLINE_SINGLE;
693                 SvxUnderlineItem aLineItem(meUnderline, SID_ATTR_CHAR_UNDERLINE);
694                 aLineItem.SetColor(meUnderlineColor);
695                 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_UNDERLINE, SFX_CALLMODE_RECORD, &aLineItem, 0L);
696             }
697             else
698             {
699                 meUnderline = UNDERLINE_NONE;
700                 SvxUnderlineItem aLineItem(meUnderline, SID_ATTR_CHAR_UNDERLINE);
701                 mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_UNDERLINE, SFX_CALLMODE_RECORD, &aLineItem, 0L);
702             }
703             UpdateItem(SID_ATTR_CHAR_UNDERLINE);
704         }
705         case TBI_STRIKEOUT:
706         {
707             EndTracking();
708             if(meStrike !=  STRIKEOUT_NONE && meStrike != STRIKEOUT_DONTKNOW)
709                 meStrike = STRIKEOUT_NONE;
710             else
711                 meStrike = STRIKEOUT_SINGLE;
712             SvxCrossedOutItem aStrikeItem(meStrike,SID_ATTR_CHAR_STRIKEOUT);
713             mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_STRIKEOUT, SFX_CALLMODE_RECORD, &aStrikeItem, 0L);
714             UpdateItem(SID_ATTR_CHAR_STRIKEOUT);
715             break;
716         }
717         case TBI_SHADOWED:
718         {
719             EndTracking();
720             mbShadow = !mbShadow;
721             SvxShadowedItem aShadowItem(mbShadow, SID_ATTR_CHAR_SHADOWED);
722             mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_SHADOWED, SFX_CALLMODE_RECORD, &aShadowItem, 0L);
723             UpdateItem(SID_ATTR_CHAR_SHADOWED);
724             break;
725         }
726 	}
727 	return 0;
728 }
729 
730 
731 
732 
733 IMPL_LINK(TextPropertyPanel, ToolboxIncDecSelectHdl, ToolBox*, pToolBox)
734 {
735 	const sal_uInt16 nId = pToolBox->GetCurItemId();
736 
737 	// font size +/- enhancement in sd
738     switch (maContext.GetCombinedContext_DI())
739     {
740         case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
741         case CombinedEnumContext(Application_DrawImpress, Context_Text):
742         case CombinedEnumContext(Application_DrawImpress, Context_Table):
743         case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
744         case CombinedEnumContext(Application_DrawImpress, Context_Draw):
745         case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
746         case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
747             if(nId == TBI_INCREASE)
748             {
749                 EndTracking();
750                 SfxVoidItem aItem(SID_GROW_FONT_SIZE);
751                 mpBindings->GetDispatcher()->Execute( SID_GROW_FONT_SIZE, SFX_CALLMODE_RECORD, &aItem, 0L );
752             }
753             else if(nId == TBI_DECREASE)
754             {
755                 EndTracking();
756                 SfxVoidItem aItem(SID_SHRINK_FONT_SIZE);
757                 mpBindings->GetDispatcher()->Execute( SID_SHRINK_FONT_SIZE, SFX_CALLMODE_RECORD, &aItem, 0L );
758             }
759             break;
760 
761         default:
762             if(nId == TBI_INCREASE)
763             {
764                 EndTracking();
765                 mbFocusOnFontSizeCtrl = false;
766                 sal_Int64 iValue = maFontSizeBox.GetValue();
767                 int iPos = maFontSizeBox.GetValuePos(iValue, FUNIT_NONE);
768                 long nSize = iValue;
769                 if(iPos != LISTBOX_ENTRY_NOTFOUND)
770                     nSize = maFontSizeBox.GetValue(iPos+1 , FUNIT_NONE);
771                 else if(iValue >= 100 && iValue < 105)
772                     nSize = 105;
773                 else if(iValue >= 105 && iValue < 110)
774                     nSize = 110;
775                 else if(iValue < 960)
776                 {
777                     nSize = (nSize / 10) * 10 + 10;
778                     while(maFontSizeBox.GetValuePos(nSize, FUNIT_NONE) == LISTBOX_ENTRY_NOTFOUND)
779                         nSize += 10;
780                 }
781                 else
782                 {
783                     nSize = iValue;
784                 }
785 
786                 float fSize = (float)nSize / 10;
787 
788                 SfxMapUnit eUnit = maFontSizeControl.GetCoreMetric();
789                 SvxFontHeightItem aItem( CalcToUnit( fSize, eUnit ), 100, SID_ATTR_CHAR_FONTHEIGHT ) ;
790 
791                 mpBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_FONTHEIGHT, SFX_CALLMODE_RECORD, &aItem, 0L );
792                 mpBindings->Invalidate(SID_ATTR_CHAR_FONTHEIGHT,true,false);
793                 maFontSizeBox.SetValue( nSize );
794             }
795             else if(nId == TBI_DECREASE)
796             {
797                 EndTracking();
798                 mbFocusOnFontSizeCtrl = false;
799                 sal_Int64 iValue = maFontSizeBox.GetValue();
800                 int iPos = maFontSizeBox.GetValuePos(iValue, FUNIT_NONE);
801                 long nSize = iValue;
802                 if(iPos != LISTBOX_ENTRY_NOTFOUND)
803                     nSize = maFontSizeBox.GetValue(iPos-1 , FUNIT_NONE);
804                 else if(iValue > 100 && iValue <= 105)
805                     nSize = 100;
806                 else if(iValue > 105 && iValue <= 110)
807                     nSize = 105;
808                 else if(iValue > 960)
809                 {
810                     nSize = 960;
811                 }
812                 else if(iValue > 60)
813                 {
814                     nSize = (nSize / 10) * 10 ;
815                     while(maFontSizeBox.GetValuePos(nSize, FUNIT_NONE) == LISTBOX_ENTRY_NOTFOUND)
816                         nSize -= 10;
817                 }
818                 else
819                 {
820                     nSize = iValue;
821                 }
822 
823                 float fSize = (float)nSize / 10;
824 
825                 SfxMapUnit eUnit = maFontSizeControl.GetCoreMetric();
826                 SvxFontHeightItem aItem( CalcToUnit( fSize, eUnit ), 100, SID_ATTR_CHAR_FONTHEIGHT ) ;
827 
828                 mpBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_FONTHEIGHT, SFX_CALLMODE_RECORD, &aItem, 0L );
829                 mpBindings->Invalidate(SID_ATTR_CHAR_FONTHEIGHT,true,false);
830                 maFontSizeBox.SetValue( nSize );
831             }
832 	}
833     UpdateItem(SID_ATTR_CHAR_FONTHEIGHT);
834 
835 	return 0;
836 }
837 
838 
839 
840 IMPL_LINK(TextPropertyPanel, ToolBoxUnderlineClickHdl, ToolBox*, pToolBox)
841 {
842 	const sal_uInt16 nId = pToolBox->GetCurItemId();
843 	OSL_ASSERT(nId == TBI_UNDERLINE);
844 	if(nId == TBI_UNDERLINE)
845 	{
846 		pToolBox->SetItemDown( nId, true );
847 		maUnderlinePopup.Rearrange(meUnderline);
848 		maUnderlinePopup.Show(*pToolBox);
849 
850 	}
851 	return 0L;
852 }
853 
854 
855 
856 
857 IMPL_LINK(TextPropertyPanel, ToolBoxFontColorDropHdl,ToolBox*, pToolBox)
858 {
859 	const sal_uInt16 nId = pToolBox->GetCurItemId();
860 	if(nId == TBI_FONTCOLOR)
861 	{
862 		meColorType = FONT_COLOR;
863 
864 		pToolBox->SetItemDown( nId, true );
865 
866 		maFontColorPopup.Show(*pToolBox);
867 		maFontColorPopup.SetCurrentColor(maColor, mbColorAvailable);
868 	}
869 	return 0;
870 }
871 
872 
873 
874 
875 IMPL_LINK(TextPropertyPanel, ToolBoxSwScriptSelectHdl, ToolBox*, pToolBox)
876 {
877 	const sal_uInt16 nId = pToolBox->GetCurItemId();
878 	if( nId == TBI_SUPER_SW )
879 	{
880 		if(meEscape != SVX_ESCAPEMENT_SUPERSCRIPT)
881 		{
882 			meEscape = SVX_ESCAPEMENT_SUPERSCRIPT;
883 			SvxEscapementItem aSupItem(DFLT_ESC_SUPER, DFLT_ESC_PROP, SID_ATTR_CHAR_ESCAPEMENT);
884 			mpBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_ESCAPEMENT, SFX_CALLMODE_RECORD, &aSupItem, 0L );
885 		}
886 		else
887 		{
888 			meEscape = SVX_ESCAPEMENT_OFF;
889 			SvxEscapementItem aNoneItem(0, 100, SID_ATTR_CHAR_ESCAPEMENT);
890 			mpBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_ESCAPEMENT, SFX_CALLMODE_RECORD, &aNoneItem, 0L );
891 		}
892 	}
893 	else if(TBI_SUB_SW == nId)
894 	{
895 		if(meEscape != SVX_ESCAPEMENT_SUBSCRIPT)
896 		{
897 			meEscape = (SvxEscapement)SVX_ESCAPEMENT_SUBSCRIPT;
898 			SvxEscapementItem aSubItem(DFLT_ESC_SUB, DFLT_ESC_PROP, SID_ATTR_CHAR_ESCAPEMENT);
899 			mpBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_ESCAPEMENT, SFX_CALLMODE_RECORD, &aSubItem, 0L );
900 		}
901 		else
902 		{
903 			meEscape = SVX_ESCAPEMENT_OFF;
904 			SvxEscapementItem aNoneItem(0, 100, SID_ATTR_CHAR_ESCAPEMENT);
905 			mpBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_ESCAPEMENT, SFX_CALLMODE_RECORD, &aNoneItem, 0L );
906 		}
907 	}
908     UpdateItem(SID_ATTR_CHAR_ESCAPEMENT);
909 
910 	return 0;
911 }
912 
913 
914 
915 
916 IMPL_LINK(TextPropertyPanel, ToolBoxScriptSelectHdl, ToolBox*, pToolBox)
917 {
918 	const sal_uInt16 nId = pToolBox->GetCurItemId();
919 	if( nId == TBI_SUPER )
920 	{
921 		mbSuper = !mbSuper;
922 		SfxBoolItem aSupItem(SID_SET_SUPER_SCRIPT, mbSuper);
923 		mpBindings->GetDispatcher()->Execute( SID_SET_SUPER_SCRIPT, SFX_CALLMODE_RECORD, &aSupItem, 0L );
924         UpdateItem(SID_SET_SUPER_SCRIPT);
925 	}
926 	else if(TBI_SUB == nId)
927 	{
928 
929 		mbSub = !mbSub;
930 		SfxBoolItem aSubItem(SID_SET_SUB_SCRIPT, mbSub );
931 		mpBindings->GetDispatcher()->Execute( SID_SET_SUB_SCRIPT, SFX_CALLMODE_RECORD, &aSubItem, 0L );
932         UpdateItem(SID_SET_SUB_SCRIPT);
933 	}
934 	return 0;
935 }
936 
937 
938 
939 
940 IMPL_LINK(TextPropertyPanel, ToolBoxHighlightDropHdl, ToolBox*, pToolBox)
941 {
942 	const sal_uInt16 nId = pToolBox->GetCurItemId();
943 	if(nId == TBI_HIGHLIGHT)
944 	{
945 		meColorType = BACK_COLOR;
946 
947 		pToolBox->SetItemDown( nId, true );
948 		maBrushColorPopup.Show(*pToolBox);
949 		maBrushColorPopup.SetCurrentColor(maBackColor, mbBackColorAvailable);
950 
951 	}
952 	return 0;
953 }
954 
955 
956 
957 IMPL_LINK(TextPropertyPanel, SpacingClickHdl, ToolBox*, pToolBox)
958 {
959 	const sal_uInt16 nId = pToolBox->GetCurItemId();
960 	OSL_ASSERT(nId == TBI_SPACING);
961 	if(nId == TBI_SPACING)
962 	{
963 		pToolBox->SetItemDown( nId, true );
964 		maCharSpacePopup.Rearrange(mbKernLBAvailable,mbKernAvailable,mlKerning);
965 		maCharSpacePopup.Show(*pToolBox);
966 
967 	}
968 	return 0L;
969 }
970 
971 
972 
973 
974 IMPL_LINK( TextPropertyPanel, ImplPopupModeEndHdl, FloatingWindow*, EMPTYARG )
975 {
976 	return 0;
977 }
978 
979 
980 
981 
982 void TextPropertyPanel::NotifyItemUpdate (
983     const sal_uInt16 nSID,
984     const SfxItemState eState,
985     const SfxPoolItem* pState,
986     const bool bIsEnabled)
987 {
988 	switch(nSID)
989 	{
990         case SID_ATTR_CHAR_FONT:
991         {
992             bool bIsControlEnabled (bIsEnabled);
993             if (  eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxFontItem) )
994             {
995                 const SvxFontItem* pFontItem = (const SvxFontItem*)pState;
996                 mpFontNameBox->SetText( pFontItem->GetFamilyName() );
997             }
998             else
999             {
1000                 mpFontNameBox->SetText( String() );
1001                 if (SFX_ITEM_DISABLED == eState)
1002                     bIsControlEnabled = false;
1003             }
1004             mpFontNameBox->Enable(bIsControlEnabled);
1005             break;
1006         }
1007         case SID_ATTR_CHAR_FONTHEIGHT:
1008         {
1009             bool bIsControlEnabled (bIsEnabled);
1010             if (  eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxFontHeightItem) )
1011             {
1012                 mpHeightItem = (SvxFontHeightItem*)pState;//const SvxFontHeightItem*
1013                 SfxMapUnit eUnit = maFontSizeControl.GetCoreMetric();
1014                 long iValue = (long)CalcToPoint( mpHeightItem->GetHeight(), eUnit, 10 );
1015                 mpToolBoxIncDec->Enable();
1016 
1017                 mpToolBoxIncDec->SetItemState(TBI_INCREASE, STATE_NOCHECK);
1018                 mpToolBoxIncDec->SetItemState(TBI_DECREASE, STATE_NOCHECK);
1019 
1020                 if( mbFocusOnFontSizeCtrl )
1021                     return;
1022 
1023                 maFontSizeBox.SetValue( iValue );
1024                 maFontSizeBox.LoseFocus();
1025 
1026                 UpdateItem(SID_SHRINK_FONT_SIZE);
1027                 UpdateItem(SID_GROW_FONT_SIZE);
1028             }
1029             else
1030             {
1031                 mpHeightItem = NULL;
1032                 maFontSizeBox.SetText( String() );
1033                 //increase decrease diabled when multi-seletion have different font size
1034 
1035                 // font size +/- enhancement in sd
1036                 switch(maContext.GetCombinedContext_DI())
1037                 {
1038                     case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
1039                     case CombinedEnumContext(Application_DrawImpress, Context_Text):
1040                     case CombinedEnumContext(Application_DrawImpress, Context_Table):
1041                     case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
1042                     case CombinedEnumContext(Application_DrawImpress, Context_Draw):
1043                     case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
1044                     case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
1045                         break;
1046 
1047                     default:
1048                         mpToolBoxIncDec->Disable();
1049                 }
1050                 if ( eState <= SFX_ITEM_READONLY )
1051                     bIsControlEnabled = false;
1052             }
1053             maFontSizeBox.Enable(bIsControlEnabled);
1054             break;
1055         }
1056 
1057         case SID_ATTR_CHAR_WEIGHT:
1058             mbWeightAvailable = (eState >= SFX_ITEM_DONTCARE);
1059             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxWeightItem))
1060             {
1061                 const SvxWeightItem* pItem = (const SvxWeightItem*)pState;
1062                 meWeight = (FontWeight)pItem->GetValue();
1063             }
1064             else
1065             {
1066                 meWeight = WEIGHT_NORMAL;
1067             }
1068             mpToolBoxFont->EnableItem(TBI_BOLD, mbWeightAvailable && bIsEnabled);
1069             mpToolBoxFont->SetItemState(TBI_BOLD, meWeight==WEIGHT_BOLD ? STATE_CHECK : STATE_NOCHECK);
1070             break;
1071 
1072         case SID_ATTR_CHAR_POSTURE:
1073             mbPostureAvailable = (eState >= SFX_ITEM_DONTCARE);
1074             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxPostureItem))
1075             {
1076                 const SvxPostureItem* pItem = (const SvxPostureItem*)pState;
1077                 meItalic = (FontItalic)pItem->GetValue();
1078             }
1079             else
1080             {
1081                 meItalic = ITALIC_NONE;
1082             }
1083             mpToolBoxFont->EnableItem(TBI_ITALIC, mbPostureAvailable && bIsEnabled);
1084             mpToolBoxFont->SetItemState(TBI_ITALIC,	meItalic==ITALIC_NORMAL ? STATE_CHECK : STATE_NOCHECK);
1085             break;
1086 
1087         case SID_ATTR_CHAR_UNDERLINE:
1088             if( eState >= SFX_ITEM_DEFAULT)
1089             {
1090                 if(pState->ISA(SvxUnderlineItem))
1091                 {
1092                     const SvxUnderlineItem* pItem = (const SvxUnderlineItem*)pState;
1093                     meUnderline = (FontUnderline)pItem->GetValue();
1094                     meUnderlineColor = pItem->GetColor();
1095                 }
1096             }
1097             else
1098             {
1099                 meUnderline = UNDERLINE_NONE;
1100             }
1101             mpToolBoxFont->EnableItem(TBI_UNDERLINE, bIsEnabled);
1102             mpToolBoxFont->SetItemState(TBI_UNDERLINE, meUnderline==UNDERLINE_NONE ? STATE_NOCHECK : STATE_CHECK);
1103             break;
1104 
1105         case SID_ATTR_CHAR_SHADOWED:
1106             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxShadowedItem))
1107             {
1108                 const SvxShadowedItem* pItem = (const SvxShadowedItem*)pState;
1109                 mbShadow = pItem->GetValue();
1110             }
1111             else
1112             {
1113                 mbShadow = false;
1114             }
1115             mpToolBoxFont->EnableItem(TBI_SHADOWED, bIsEnabled);
1116             mpToolBoxFont->SetItemState(TBI_SHADOWED, mbShadow ? STATE_CHECK : STATE_NOCHECK);
1117             break;
1118 
1119         case SID_ATTR_CHAR_STRIKEOUT:
1120             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxCrossedOutItem))
1121             {
1122                 const SvxCrossedOutItem* pItem = (const SvxCrossedOutItem*)pState;
1123                 meStrike = (FontStrikeout)pItem->GetValue();
1124             }
1125             else
1126             {
1127                 meStrike = STRIKEOUT_NONE;
1128             }
1129             mpToolBoxFont->EnableItem(TBI_STRIKEOUT, bIsEnabled);
1130             mpToolBoxFont->SetItemState(TBI_STRIKEOUT,
1131                 meStrike!=STRIKEOUT_NONE && meStrike!=STRIKEOUT_DONTKNOW
1132                     ? STATE_CHECK
1133                     : STATE_NOCHECK);
1134             break;
1135 
1136         case SID_ATTR_CHAR_COLOR:
1137             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxColorItem))
1138             {
1139                 const SvxColorItem* pItem =  (const SvxColorItem*)pState;
1140                 maColor = pItem->GetValue();
1141                 mbColorAvailable = true;
1142 				if (mpFontColorUpdater)
1143 	                mpFontColorUpdater->Update(maColor);
1144             }
1145             else
1146             {
1147                 mbColorAvailable = false;
1148                 maColor.SetColor(COL_AUTO);
1149 				if (mpFontColorUpdater)
1150 					mpFontColorUpdater->Update(maColor);
1151             }
1152             mpToolBoxFontColor->EnableItem(TBI_FONTCOLOR, bIsEnabled);
1153             break;
1154 
1155         case SID_ATTR_BRUSH_CHAR:
1156             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxBrushItem))
1157             {
1158                 const SvxBrushItem* pItem =  (const SvxBrushItem*)pState;
1159                 maBackColor = pItem->GetColor();
1160                 mbBackColorAvailable = true;
1161                 if (mpHighlightUpdater)
1162                     mpHighlightUpdater->Update(maBackColor);
1163             }
1164             else
1165             {
1166                 mbBackColorAvailable = false;
1167                 maBackColor.SetColor(COL_AUTO);
1168                 if (mpHighlightUpdater)
1169                     mpHighlightUpdater->Update(maBackColor);
1170             }
1171             mpToolBoxHighlight->EnableItem(TBI_HIGHLIGHT, bIsEnabled);
1172             break;
1173 
1174         case SID_ATTR_CHAR_ESCAPEMENT:
1175         {
1176             bool bIsItemEnabled (true);
1177             if (eState == SFX_ITEM_AVAILABLE)
1178             {
1179                 if (pState->ISA(SvxEscapementItem))
1180                 {
1181                     const SvxEscapementItem* pItem = (const SvxEscapementItem *)pState;
1182                     short nEsc = pItem->GetEsc();
1183                     if(nEsc == 0)
1184                     {
1185                         meEscape = SVX_ESCAPEMENT_OFF;
1186                         mpToolBoxScriptSw->SetItemState(TBI_SUPER_SW, STATE_NOCHECK);
1187                         mpToolBoxScriptSw->SetItemState(TBI_SUB_SW, STATE_NOCHECK);
1188                     }
1189                     else if(nEsc > 0)
1190                     {
1191                         meEscape = SVX_ESCAPEMENT_SUPERSCRIPT;
1192                         mpToolBoxScriptSw->SetItemState(TBI_SUPER_SW, STATE_CHECK);
1193                         mpToolBoxScriptSw->SetItemState(TBI_SUB_SW,	STATE_NOCHECK);
1194                     }
1195                     else
1196                     {
1197                         meEscape = SVX_ESCAPEMENT_SUBSCRIPT;
1198                         mpToolBoxScriptSw->SetItemState(TBI_SUPER_SW, STATE_NOCHECK);
1199                         mpToolBoxScriptSw->SetItemState(TBI_SUB_SW, STATE_CHECK);
1200                     }
1201                 }
1202                 else
1203                 {
1204                     meEscape = SVX_ESCAPEMENT_OFF;
1205                     mpToolBoxScriptSw->SetItemState(TBI_SUPER_SW, STATE_NOCHECK);
1206                     mpToolBoxScriptSw->SetItemState(TBI_SUB_SW,	STATE_NOCHECK);
1207                 }
1208             }
1209             else if (eState == SFX_ITEM_DISABLED)
1210             {
1211                 bIsItemEnabled = false;
1212             }
1213             else
1214             {
1215                 meEscape = SVX_ESCAPEMENT_OFF;
1216             }
1217             mpToolBoxScriptSw->EnableItem(TBI_SUPER, bIsItemEnabled && bIsEnabled);
1218             mpToolBoxScriptSw->EnableItem(TBI_SUB, bIsItemEnabled && bIsEnabled);
1219             break;
1220         }
1221 
1222         case SID_SET_SUB_SCRIPT:
1223             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SfxBoolItem))
1224             {
1225                 const SfxBoolItem* pItem = (const SfxBoolItem*)pState;
1226                 mbSub = pItem->GetValue();
1227             }
1228             else
1229             {
1230                 mbSub = false;
1231             }
1232             mpToolBoxScript->EnableItem(TBI_SUB, bIsEnabled);
1233             mpToolBoxScript->SetItemState(TBI_SUB, mbSub ? STATE_CHECK : STATE_NOCHECK);
1234             break;
1235 
1236         case SID_SET_SUPER_SCRIPT:
1237             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SfxBoolItem))
1238             {
1239                 const SfxBoolItem* pItem = (const SfxBoolItem*)pState;
1240                 mbSuper = pItem->GetValue();
1241             }
1242             else
1243             {
1244                 mbSuper = false;
1245             }
1246             mpToolBoxScript->EnableItem(TBI_SUPER, bIsEnabled);
1247             mpToolBoxScript->SetItemState(TBI_SUPER, mbSuper ? STATE_CHECK : STATE_NOCHECK);
1248             break;
1249 
1250         case SID_ATTR_CHAR_KERNING:
1251             if ( SFX_ITEM_AVAILABLE == eState )
1252             {
1253                 mbKernLBAvailable = true;
1254 
1255                 if(pState->ISA(SvxKerningItem))
1256                 {
1257                     const SvxKerningItem* pKerningItem  = (const SvxKerningItem*)pState;
1258                     mlKerning = (long)pKerningItem->GetValue();
1259                     mbKernAvailable = true;
1260                 }
1261                 else
1262                 {
1263                     mlKerning = 0;
1264                     mbKernAvailable =false;
1265                 }
1266             }
1267             else if (SFX_ITEM_DISABLED == eState)
1268             {
1269                 mbKernLBAvailable = false;
1270                 mbKernAvailable = false;
1271                 mlKerning = 0;
1272             }
1273             else
1274             {
1275                 mbKernLBAvailable = true;
1276                 mbKernAvailable = false;
1277                 mlKerning = 0;
1278             }
1279             mpToolBoxSpacing->EnableItem(TBI_SPACING, bIsEnabled);
1280             break;
1281 
1282             // font size +/- enhancement in sd
1283         case SID_SHRINK_FONT_SIZE:
1284         case SID_GROW_FONT_SIZE:
1285             switch(maContext.GetCombinedContext_DI())
1286             {
1287                 case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
1288                 case CombinedEnumContext(Application_DrawImpress, Context_Text):
1289                 case CombinedEnumContext(Application_DrawImpress, Context_Table):
1290                 case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
1291                 case CombinedEnumContext(Application_DrawImpress, Context_Draw):
1292                 case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
1293                 case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
1294                     if(eState == SFX_ITEM_DISABLED)
1295                         mpToolBoxIncDec->Disable();
1296                     else
1297                         mpToolBoxIncDec->Enable();
1298                 break;
1299             }
1300             const sal_Int32 nSize (maFontSizeBox.GetValue());
1301             if (nSID == SID_GROW_FONT_SIZE)
1302                 mpToolBoxIncDec->EnableItem(TBI_INCREASE, bIsEnabled && nSize<960);
1303             else
1304                 mpToolBoxIncDec->EnableItem(TBI_DECREASE, bIsEnabled && nSize>60);
1305             break;
1306     }
1307 }
1308 
1309 
1310 
1311 
1312 void TextPropertyPanel::UpdateItem (const sal_uInt16 nSlotId)
1313 {
1314     switch (nSlotId)
1315     {
1316         case SID_ATTR_CHAR_FONT:
1317             maFontNameControl.RequestUpdate();
1318             break;
1319         case SID_ATTR_CHAR_FONTHEIGHT:
1320             maFontSizeControl.RequestUpdate();
1321             break;
1322         case SID_ATTR_CHAR_WEIGHT:
1323             maWeightControl.RequestUpdate();
1324             break;
1325         case SID_ATTR_CHAR_POSTURE:
1326             maItalicControl.RequestUpdate();
1327             break;
1328         case SID_ATTR_CHAR_UNDERLINE:
1329             maUnderlineControl.RequestUpdate();
1330             break;
1331         case SID_ATTR_CHAR_STRIKEOUT:
1332             maStrikeControl.RequestUpdate();
1333             break;
1334         case SID_ATTR_CHAR_SHADOWED:
1335             maShadowControl.RequestUpdate();
1336             break;
1337         case SID_ATTR_CHAR_COLOR:
1338             maFontColorControl.RequestUpdate();
1339             break;
1340         case SID_ATTR_CHAR_ESCAPEMENT:
1341             maScriptControlSw.RequestUpdate();
1342             break;
1343         case SID_SET_SUPER_SCRIPT:
1344             maSuperScriptControl.RequestUpdate();
1345             break;
1346         case SID_SET_SUB_SCRIPT:
1347             maSubScriptControl.RequestUpdate();
1348             break;
1349         case SID_ATTR_CHAR_KERNING:
1350             maSpacingControl.RequestUpdate();
1351             break;
1352         case SID_ATTR_BRUSH_CHAR:
1353             maHighlightControl.RequestUpdate();
1354             break;
1355         case SID_GROW_FONT_SIZE:
1356             maSDFontGrow.RequestUpdate();
1357             break;
1358         case SID_SHRINK_FONT_SIZE:
1359             maSDFontShrink.RequestUpdate();
1360             break;
1361     }
1362 }
1363 
1364 
1365 
1366 
1367 
1368 void TextPropertyPanel::SetFontColor (
1369     const String& /* rsColorName */,
1370     const Color aColor)
1371 {
1372 	SvxColorItem aColorItem(aColor, SID_ATTR_CHAR_COLOR);
1373 	mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_COLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
1374 	maColor = aColor;
1375 }
1376 
1377 void TextPropertyPanel::SetBrushColor (
1378     const String& /* rsColorName */,
1379     const Color aColor)
1380 {
1381 	SvxBrushItem aBrushItem(aColor, SID_ATTR_BRUSH_CHAR);
1382 	mpBindings->GetDispatcher()->Execute(SID_ATTR_BRUSH_CHAR, SFX_CALLMODE_RECORD, &aBrushItem, 0L);
1383 	maBackColor = aColor;
1384 }
1385 
1386 Color& TextPropertyPanel::GetUnderlineColor()
1387 {
1388 	return meUnderlineColor;
1389 }
1390 
1391 void TextPropertyPanel::SetUnderline(FontUnderline	eUnderline)
1392 {
1393 	meUnderline = eUnderline;
1394 }
1395 
1396 
1397 
1398 } } // end of namespace svx::sidebar
1399