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_sc.hxx"
23 
24 #include <sfx2/sidebar/propertypanel.hrc>
25 #include <sfx2/sidebar/Theme.hxx>
26 #include <sfx2/sidebar/ControlFactory.hxx>
27 #include <CellAppearancePropertyPanel.hxx>
28 #include <CellAppearancePropertyPanel.hrc>
29 #include "sc.hrc"
30 #include "scresid.hxx"
31 #include <sfx2/bindings.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <vcl/fixed.hxx>
34 #include <svx/tbxcolorupdate.hxx>
35 #include <svl/eitem.hxx>
36 #include <editeng/bolnitem.hxx>
37 #include <editeng/boxitem.hxx>
38 #include <editeng/colritem.hxx>
39 #include <vcl/svapp.hxx>
40 #include <svx/sidebar/ColorControl.hxx>
41 #include <boost/bind.hpp>
42 #include <svx/sidebar/PopupContainer.hxx>
43 #include <CellLineStyleControl.hxx>
44 #include <CellLineStylePopup.hxx>
45 #include <CellBorderUpdater.hxx>
46 #include <CellBorderStyleControl.hxx>
47 #include <CellBorderStylePopup.hxx>
48 
49 using namespace css;
50 using namespace cssu;
51 
52 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
53 
54 //////////////////////////////////////////////////////////////////////////////
55 // helpers
56 
57 namespace
58 {
59     Color GetTransparentColor(void)
60     {
61         return COL_TRANSPARENT;
62     }
63 } // end of anonymous namespace
64 
65 //////////////////////////////////////////////////////////////////////////////
66 // namespace open
67 
68 namespace sc { namespace sidebar {
69 
70 //////////////////////////////////////////////////////////////////////////////
71 
72 svx::sidebar::PopupControl* CellAppearancePropertyPanel::CreateFillColorPopupControl(svx::sidebar::PopupContainer* pParent)
73 {
74     const ScResId aResId(VS_NOFILLCOLOR);
75 
76     return new svx::sidebar::ColorControl(
77         pParent,
78         mpBindings,
79         ScResId(RID_POPUPPANEL_CELLAPPEARANCE_FILLCOLOR),
80         ScResId(VS_FILLCOLOR),
81         ::boost::bind(GetTransparentColor),
82         ::boost::bind(&CellAppearancePropertyPanel::SetFillColor, this, _1, _2),
83         pParent,
84         &aResId);
85 }
86 
87 void CellAppearancePropertyPanel::SetFillColor(
88     const String& /*rsColorName*/,
89     const Color aColor)
90 {
91     const SvxColorItem aColorItem(aColor, SID_BACKGROUND_COLOR);
92     mpBindings->GetDispatcher()->Execute(SID_BACKGROUND_COLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
93     maBackColor = aColor;
94 }
95 
96 //////////////////////////////////////////////////////////////////////////////
97 
98 svx::sidebar::PopupControl* CellAppearancePropertyPanel::CreateLineColorPopupControl(svx::sidebar::PopupContainer* pParent)
99 {
100     return new svx::sidebar::ColorControl(
101         pParent,
102         mpBindings,
103         ScResId(RID_POPUPPANEL_CELLAPPEARANCE_LINECOLOR),
104         ScResId(VS_LINECOLOR),
105         ::boost::bind(GetTransparentColor),
106         ::boost::bind(&CellAppearancePropertyPanel::SetLineColor, this, _1, _2),
107         pParent,
108         0);
109 }
110 
111 void CellAppearancePropertyPanel::SetLineColor(
112     const String& /*rsColorName*/,
113     const Color aColor)
114 {
115     const SvxColorItem aColorItem(aColor, SID_FRAME_LINECOLOR);
116     mpBindings->GetDispatcher()->Execute(SID_FRAME_LINECOLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
117     maLineColor = aColor;
118 }
119 
120 //////////////////////////////////////////////////////////////////////////////
121 
122 svx::sidebar::PopupControl* CellAppearancePropertyPanel::CreateCellLineStylePopupControl(svx::sidebar::PopupContainer* pParent)
123 {
124     return new CellLineStyleControl(pParent, *this);
125 }
126 
127 void CellAppearancePropertyPanel::EndCellLineStylePopupMode(void)
128 {
129     if(mpCellLineStylePopup.get())
130     {
131         mpCellLineStylePopup->Hide();
132     }
133 }
134 
135 //////////////////////////////////////////////////////////////////////////////
136 
137 svx::sidebar::PopupControl* CellAppearancePropertyPanel::CreateCellBorderStylePopupControl(svx::sidebar::PopupContainer* pParent)
138 {
139     return new CellBorderStyleControl(pParent, *this);
140 }
141 
142 void CellAppearancePropertyPanel::EndCellBorderStylePopupMode(void)
143 {
144     if(mpCellBorderStylePopup.get())
145     {
146         mpCellBorderStylePopup->Hide();
147     }
148 }
149 
150 //////////////////////////////////////////////////////////////////////////////
151 
152 CellAppearancePropertyPanel::CellAppearancePropertyPanel(
153     Window* pParent,
154     const cssu::Reference<css::frame::XFrame>& rxFrame,
155     SfxBindings* pBindings)
156 :   Control(
157         pParent,
158         ScResId(RID_PROPERTYPANEL_SC_APPEAR)),
159 
160     mpFTFillColor(new FixedText(this, ScResId(FT_BK_COLOR))),
161     mpTBFillColorBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
162     mpTBFillColor(sfx2::sidebar::ControlFactory::CreateToolBox(mpTBFillColorBackground.get(), ScResId(TB_BK_COLOR))),
163     mpFillColorUpdater(new ::svx::ToolboxButtonColorUpdater(SID_ATTR_BRUSH, TBI_BK_COLOR, mpTBFillColor.get(), TBX_UPDATER_MODE_CHAR_COLOR_NEW)),
164 
165     mpFTCellBorder(new FixedText(this, ScResId(FT_BORDER))),
166     mpTBCellBorderBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
167     mpTBCellBorder(sfx2::sidebar::ControlFactory::CreateToolBox(mpTBCellBorderBackground.get(), ScResId(TB_APP_BORDER))),
168     mpCellBorderUpdater(new CellBorderUpdater(TBI_BORDER, *mpTBCellBorder)),
169 
170     mpTBLineStyleBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
171     mpTBLineStyle(sfx2::sidebar::ControlFactory::CreateToolBox(mpTBLineStyleBackground.get(), ScResId(TB_BORDER_LINE_STYLE))),
172 
173     mpTBLineColorBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
174     mpTBLineColor(sfx2::sidebar::ControlFactory::CreateToolBox(mpTBLineColorBackground.get(), ScResId(TB_BORDER_LINE_COLOR))),
175     mpLineColorUpdater(new ::svx::ToolboxButtonColorUpdater(SID_FRAME_LINECOLOR, TBI_LINE_COLOR, mpTBLineColor.get(), TBX_UPDATER_MODE_CHAR_COLOR_NEW)),
176 
177     mpCBXShowGrid(new CheckBox(this, ScResId(CBX_SHOW_GRID))),
178 
179     maBackColorControl(SID_BACKGROUND_COLOR, *pBindings, *this),
180     maLineColorControl(SID_FRAME_LINECOLOR, *pBindings, *this),
181     maLineStyleControl(SID_FRAME_LINESTYLE, *pBindings, *this),
182     maBorderOuterControl(SID_ATTR_BORDER_OUTER, *pBindings, *this),
183     maBorderInnerControl(SID_ATTR_BORDER_INNER, *pBindings, *this),
184     maGridShowControl(SID_SCGRIDSHOW, *pBindings, *this),
185     maBorderTLBRControl(SID_ATTR_BORDER_DIAG_TLBR, *pBindings, *this),
186     maBorderBLTRControl(SID_ATTR_BORDER_DIAG_BLTR, *pBindings, *this),
187 
188     maIMGBKColor(ScResId(IMG_BK_COLOR)),
189     maIMGCellBorder(ScResId(IMG_CELL_BORDER)),
190     maIMGLineColor(ScResId(IMG_LINE_COLOR)),
191     maIMGLineStyle1(ScResId(IMG_LINE_STYLE1)),
192     maIMGLineStyle2(ScResId(IMG_LINE_STYLE2)),
193     maIMGLineStyle3(ScResId(IMG_LINE_STYLE3)),
194     maIMGLineStyle4(ScResId(IMG_LINE_STYLE4)),
195     maIMGLineStyle5(ScResId(IMG_LINE_STYLE5)),
196     maIMGLineStyle6(ScResId(IMG_LINE_STYLE6)),
197     maIMGLineStyle7(ScResId(IMG_LINE_STYLE7)),
198     maIMGLineStyle8(ScResId(IMG_LINE_STYLE8)),
199     maIMGLineStyle9(ScResId(IMG_LINE_STYLE9)),
200 
201     maIMGBKColorH(ScResId(IMG_BK_COLOR_H)),
202     maIMGLineStyle1H(ScResId(IMG_LINE_STYLE1_H)),
203     maIMGLineStyle2H(ScResId(IMG_LINE_STYLE2_H)),
204     maIMGLineStyle3H(ScResId(IMG_LINE_STYLE3_H)),
205     maIMGLineStyle4H(ScResId(IMG_LINE_STYLE4_H)),
206     maIMGLineStyle5H(ScResId(IMG_LINE_STYLE5_H)),
207     maIMGLineStyle6H(ScResId(IMG_LINE_STYLE6_H)),
208     maIMGLineStyle7H(ScResId(IMG_LINE_STYLE7_H)),
209     maIMGLineStyle8H(ScResId(IMG_LINE_STYLE8_H)),
210     maIMGLineStyle9H(ScResId(IMG_LINE_STYLE9_H)),
211 
212     maBackColor(COL_TRANSPARENT),
213     maLineColor(COL_BLACK),
214     maTLBRColor(COL_BLACK),
215     maBLTRColor(COL_BLACK),
216     mnIn(0),
217     mnOut(0),
218     mnDis(0),
219     mnTLBRIn(0),
220     mnTLBROut(0),
221     mnTLBRDis(0),
222     mnBLTRIn(0),
223     mnBLTROut(0),
224     mnBLTRDis(0),
225     mbBackColorAvailable(true),
226     mbLineColorAvailable(true),
227     mbBorderStyleAvailable(true),
228     mbLeft(false),
229     mbRight(false),
230     mbTop(false),
231     mbBottom(false),
232     mbVer(false),
233     mbHor(false),
234     mbOuterBorder(false),
235     mbInnerBorder(false),
236     mbTLBR(false),
237     mbBLTR(false),
238 
239     maFillColorPopup(this, ::boost::bind(&CellAppearancePropertyPanel::CreateFillColorPopupControl, this, _1)),
240     maLineColorPopup(this, ::boost::bind(&CellAppearancePropertyPanel::CreateLineColorPopupControl, this, _1)),
241     mpCellLineStylePopup(),
242     mpCellBorderStylePopup(),
243 
244     mxFrame(rxFrame),
245     maContext(),
246     mpBindings(pBindings)
247 {
248     Initialize();
249     FreeResource();
250 }
251 
252 //////////////////////////////////////////////////////////////////////////////
253 
254 CellAppearancePropertyPanel::~CellAppearancePropertyPanel()
255 {
256     // Destroy the toolboxes, then their background windows.
257     mpTBFillColor.reset();
258     mpTBCellBorder.reset();
259     mpTBLineStyle.reset();
260     mpTBLineColor.reset();
261 
262     mpTBFillColorBackground.reset();
263     mpTBCellBorderBackground.reset();
264     mpTBLineStyleBackground.reset();
265     mpTBLineColorBackground.reset();
266 }
267 
268 //////////////////////////////////////////////////////////////////////////////
269 
270 void CellAppearancePropertyPanel::Initialize()
271 {
272 	mpTBFillColor->SetItemImage(TBI_BK_COLOR, GetDisplayBackground().GetColor().IsDark() ? maIMGBKColorH : maIMGBKColor);
273 	mpTBFillColor->SetItemBits( TBI_BK_COLOR, mpTBFillColor->GetItemBits( TBI_BK_COLOR ) | TIB_DROPDOWNONLY );
274 	mpTBFillColor->SetQuickHelpText(TBI_BK_COLOR,String(ScResId(STR_QH_BK_COLOR)));	//Add
275 	Size aTbxSize1( mpTBFillColor->CalcWindowSizePixel() );
276 	mpTBFillColor->SetOutputSizePixel( aTbxSize1 );
277 	mpTBFillColor->SetBackground(Wallpaper());
278 	mpTBFillColor->SetPaintTransparent(true);
279 	Link aLink = LINK(this, CellAppearancePropertyPanel, TbxBKColorSelectHdl);
280 	mpTBFillColor->SetDropdownClickHdl ( aLink );
281 	mpTBFillColor->SetSelectHdl ( aLink );
282 
283 	mpTBCellBorder->SetItemImage(TBI_BORDER, maIMGCellBorder);
284 	mpTBCellBorder->SetItemBits( TBI_BORDER, mpTBCellBorder->GetItemBits( TBI_BORDER ) | TIB_DROPDOWNONLY );
285 	mpTBCellBorder->SetQuickHelpText(TBI_BORDER,String(ScResId(STR_QH_BORDER)));	//Add
286 	Size aTbxSize2( mpTBCellBorder->CalcWindowSizePixel() );
287 	mpTBCellBorder->SetOutputSizePixel( aTbxSize2 );
288 	mpTBCellBorder->SetBackground(Wallpaper());
289 	mpTBCellBorder->SetPaintTransparent(true);
290 	aLink = LINK(this, CellAppearancePropertyPanel, TbxCellBorderSelectHdl);
291 	mpTBCellBorder->SetDropdownClickHdl ( aLink );
292 	mpTBCellBorder->SetSelectHdl ( aLink );
293 
294 	mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, maIMGLineStyle1);
295 	mpTBLineStyle->SetItemBits( TBI_LINE_STYLE, mpTBLineStyle->GetItemBits( TBI_LINE_STYLE ) | TIB_DROPDOWNONLY );
296 	mpTBLineStyle->SetQuickHelpText(TBI_LINE_STYLE,String(ScResId(STR_QH_BORDER_LINE_STYLE)));	//Add
297 	Size aTbxSize3( mpTBLineStyle->CalcWindowSizePixel() );
298 	mpTBLineStyle->SetOutputSizePixel( aTbxSize3 );
299 	mpTBLineStyle->SetBackground(Wallpaper());
300 	mpTBLineStyle->SetPaintTransparent(true);
301 	aLink = LINK(this, CellAppearancePropertyPanel, TbxLineStyleSelectHdl);
302 	mpTBLineStyle->SetDropdownClickHdl ( aLink );
303 	mpTBLineStyle->SetSelectHdl ( aLink );
304 	mpTBLineStyle->Disable();
305 
306 	mpTBLineColor->SetItemImage(TBI_LINE_COLOR, maIMGLineColor);
307 	mpTBLineColor->SetItemBits( TBI_LINE_COLOR, mpTBLineColor->GetItemBits( TBI_LINE_COLOR ) | TIB_DROPDOWNONLY );
308 	mpTBLineColor->SetQuickHelpText(TBI_LINE_COLOR,String(ScResId(STR_QH_BORDER_LINE_COLOR)));	//Add
309 	Size aTbxSize4( mpTBLineColor->CalcWindowSizePixel() );
310 	mpTBLineColor->SetOutputSizePixel( aTbxSize4 );
311 	mpTBLineColor->SetBackground(Wallpaper());
312 	mpTBLineColor->SetPaintTransparent(true);
313 	aLink = LINK(this, CellAppearancePropertyPanel, TbxLineColorSelectHdl);
314 	mpTBLineColor->SetDropdownClickHdl ( aLink );
315 	mpTBLineColor->SetSelectHdl ( aLink );
316 	mpTBLineColor->Disable();
317 
318 	aLink = LINK(this, CellAppearancePropertyPanel, CBOXGridShowClkHdl);
319 	mpCBXShowGrid->SetClickHdl ( aLink );
320 
321 	mpTBFillColor->SetAccessibleRelationLabeledBy(mpFTFillColor.get());
322 	mpTBLineColor->SetAccessibleRelationLabeledBy(mpTBLineColor.get());
323 	mpTBCellBorder->SetAccessibleRelationLabeledBy(mpFTCellBorder.get());
324 	mpTBLineStyle->SetAccessibleRelationLabeledBy(mpTBLineStyle.get());
325 }
326 
327 //////////////////////////////////////////////////////////////////////////////
328 
329 IMPL_LINK(CellAppearancePropertyPanel, TbxBKColorSelectHdl, ToolBox*, pToolBox)
330 {
331 	sal_uInt16 nId = pToolBox->GetCurItemId();
332 	if(nId == TBI_BK_COLOR)
333 	{
334         maFillColorPopup.Show(*pToolBox);
335         maFillColorPopup.SetCurrentColor(maBackColor, mbBackColorAvailable);
336 	}
337 	return 0;
338 }
339 
340 //////////////////////////////////////////////////////////////////////////////
341 
342 IMPL_LINK(CellAppearancePropertyPanel, TbxLineColorSelectHdl, ToolBox*, pToolBox)
343 {
344 	sal_uInt16 nId = pToolBox->GetCurItemId();
345 	if(nId == TBI_LINE_COLOR)
346 	{
347         maLineColorPopup.Show(*pToolBox);
348         maLineColorPopup.SetCurrentColor(maLineColor, mbLineColorAvailable);
349 	}
350 	return 0;
351 }
352 
353 //////////////////////////////////////////////////////////////////////////////
354 
355 IMPL_LINK(CellAppearancePropertyPanel, TbxCellBorderSelectHdl, ToolBox*, pToolBox)
356 {
357 	sal_uInt16 nId = pToolBox->GetCurItemId();
358 
359     if(nId == TBI_BORDER)
360 	{
361         // create popup on demand
362         if(!mpCellBorderStylePopup.get())
363         {
364             mpCellBorderStylePopup.reset(
365                 new CellBorderStylePopup(
366                     this,
367                     ::boost::bind(&CellAppearancePropertyPanel::CreateCellBorderStylePopupControl, this, _1)));
368         }
369 
370         if(mpCellBorderStylePopup.get())
371         {
372             mpCellBorderStylePopup->Show(*pToolBox);
373         }
374 	}
375 	return 0;
376 }
377 
378 //////////////////////////////////////////////////////////////////////////////
379 
380 IMPL_LINK(CellAppearancePropertyPanel, TbxLineStyleSelectHdl, ToolBox*, pToolBox)
381 {
382 	sal_uInt16 nId = pToolBox->GetCurItemId();
383 	if(nId == TBI_LINE_STYLE)
384 	{
385         // create popup on demand
386         if(!mpCellLineStylePopup.get())
387         {
388             mpCellLineStylePopup.reset(
389                 new CellLineStylePopup(
390                     this,
391                     ::boost::bind(&CellAppearancePropertyPanel::CreateCellLineStylePopupControl, this, _1)));
392         }
393 
394         if(mpCellLineStylePopup.get())
395         {
396             mpCellLineStylePopup->SetLineStyleSelect(mnOut, mnIn, mnDis);
397             mpCellLineStylePopup->Show(*pToolBox);
398         }
399 	}
400 	return 0;
401 }
402 
403 //////////////////////////////////////////////////////////////////////////////
404 
405 IMPL_LINK(CellAppearancePropertyPanel, CBOXGridShowClkHdl, void*, EMPTYARG)
406 {
407 	bool bState = mpCBXShowGrid->IsChecked();
408 	SfxBoolItem aItem( SID_SCGRIDSHOW , bState);
409 	GetBindings()->GetDispatcher()->Execute(SID_SCGRIDSHOW, SFX_CALLMODE_RECORD, &aItem, false, 0L);
410 	return 0;
411 }
412 
413 //////////////////////////////////////////////////////////////////////////////
414 
415 CellAppearancePropertyPanel* CellAppearancePropertyPanel::Create (
416     Window* pParent,
417     const cssu::Reference<css::frame::XFrame>& rxFrame,
418     SfxBindings* pBindings)
419 {
420     if (pParent == NULL)
421         throw lang::IllegalArgumentException(A2S("no parent Window given to CellAppearancePropertyPanel::Create"), NULL, 0);
422     if ( ! rxFrame.is())
423         throw lang::IllegalArgumentException(A2S("no XFrame given to CellAppearancePropertyPanel::Create"), NULL, 1);
424     if (pBindings == NULL)
425         throw lang::IllegalArgumentException(A2S("no SfxBindings given to CellAppearancePropertyPanel::Create"), NULL, 2);
426 
427     return new CellAppearancePropertyPanel(
428         pParent,
429         rxFrame,
430         pBindings);
431 }
432 
433 //////////////////////////////////////////////////////////////////////////////
434 
435 void CellAppearancePropertyPanel::DataChanged(
436     const DataChangedEvent& rEvent)
437 {
438     (void)rEvent;
439 }
440 
441 //////////////////////////////////////////////////////////////////////////////
442 
443 void CellAppearancePropertyPanel::HandleContextChange(
444     const ::sfx2::sidebar::EnumContext aContext)
445 {
446     if(maContext == aContext)
447     {
448         // Nothing to do.
449         return;
450     }
451 
452     maContext = aContext;
453 
454 
455 
456     // todo
457 }
458 
459 //////////////////////////////////////////////////////////////////////////////
460 
461 void CellAppearancePropertyPanel::NotifyItemUpdate(
462     sal_uInt16 nSID,
463     SfxItemState eState,
464     const SfxPoolItem* pState,
465     const bool bIsEnabled)
466 {
467     (void)bIsEnabled;
468 
469 	switch(nSID)
470 	{
471 	case SID_BACKGROUND_COLOR:
472 		if(eState >= SFX_ITEM_DEFAULT)
473 		{
474             const SvxColorItem* pSvxColorItem = dynamic_cast< const SvxColorItem* >(pState);
475 
476             if(pSvxColorItem)
477             {
478 			    maBackColor = ((const SvxColorItem*)pState)->GetValue();
479 			    mbBackColorAvailable = true;
480 			    mpFillColorUpdater->Update(maBackColor);
481                 break;
482             }
483 		}
484 
485         mbBackColorAvailable = false;
486 		maBackColor.SetColor(COL_TRANSPARENT);
487 		mpFillColorUpdater->Update(COL_TRANSPARENT);
488         break;
489 	case SID_FRAME_LINECOLOR:
490 		if( eState == SFX_ITEM_DONTCARE)
491 		{
492 			mbLineColorAvailable = true;
493 			maLineColor.SetColor( COL_TRANSPARENT );
494     		UpdateControlState();
495             break;
496 		}
497 
498         if(eState >= SFX_ITEM_DEFAULT && pState && pState->ISA(SvxColorItem) )
499 		{
500             const SvxColorItem* pSvxColorItem = dynamic_cast< const SvxColorItem* >(pState);
501 
502             if(pSvxColorItem)
503             {
504 			    maLineColor = ((const SvxColorItem*)pState)->GetValue();
505 			    if(maLineColor == COL_AUTO)
506 				    mbLineColorAvailable = false;
507 			    else
508 			    {
509 				    mbLineColorAvailable = true;
510 			    //	mpLineColorUpdater->Update(maLineColor);
511 			    }
512 
513                 UpdateControlState();
514                 break;
515             }
516 		}
517 
518         mbLineColorAvailable = false;
519 		maLineColor.SetColor(COL_AUTO);
520 	    //	mpLineColorUpdater->Update(maLineColor);
521 		UpdateControlState();
522 		break;
523 	case SID_FRAME_LINESTYLE:
524 		if( eState == SFX_ITEM_DONTCARE )
525 		{
526 			mbBorderStyleAvailable = true;
527 			mnIn = 0;
528 			mnOut = 0;
529 			mnDis = 0;
530     		SetStyleIcon();
531             break;
532 		}
533 
534         if(eState >= SFX_ITEM_DEFAULT)
535 		{
536             const SvxLineItem* pSvxLineItem = dynamic_cast< const SvxLineItem* >(pState);
537 
538             if(pSvxLineItem)
539             {
540 			    const SvxBorderLine* mbLineItem = pSvxLineItem->GetLine();
541 			    mnIn = mbLineItem->GetInWidth();
542 			    mnOut = mbLineItem->GetOutWidth();
543 			    mnDis = mbLineItem->GetDistance();
544 
545                 if(mnIn == 0 && mnOut == 0 && mnDis == 0)
546 				    mbBorderStyleAvailable = false;
547 			    else
548 				    mbBorderStyleAvailable = true;
549 
550                 SetStyleIcon();
551                 break;
552             }
553 		}
554 
555 		mbBorderStyleAvailable = false;
556 		SetStyleIcon();
557 		break;
558 	case SID_ATTR_BORDER_OUTER:
559 		if(eState >= SFX_ITEM_DEFAULT)
560 		{
561 			const SvxBoxItem* pBoxItem = dynamic_cast< const SvxBoxItem* >(pState);
562 
563             if(pBoxItem)
564             {
565 			    mbLeft=false, mbRight=false, mbTop=false, mbBottom=false;
566 
567 			    if(pBoxItem->GetLeft())
568 				    mbLeft = true;
569 
570                 if(pBoxItem->GetRight())
571 				    mbRight = true;
572 
573                 if(pBoxItem->GetTop())
574 				    mbTop = true;
575 
576                 if(pBoxItem->GetBottom())
577 				    mbBottom = true;
578 
579                 if(!Application::GetSettings().GetLayoutRTL())
580 				    mpCellBorderUpdater->UpdateCellBorder(mbTop, mbBottom, mbLeft, mbRight, maIMGCellBorder, mbVer, mbHor);
581 			    else
582 				    mpCellBorderUpdater->UpdateCellBorder(mbTop, mbBottom, mbRight, mbLeft, maIMGCellBorder, mbVer, mbHor);
583 
584                 if(mbLeft || mbRight || mbTop || mbBottom)
585 				    mbOuterBorder = true;
586 			    else
587 				    mbOuterBorder = false;
588 
589                 UpdateControlState();
590             }
591 		}
592 		break;
593 	case SID_ATTR_BORDER_INNER:
594 		if(eState >= SFX_ITEM_DEFAULT)
595 		{
596 			const SvxBoxInfoItem* pBoxInfoItem = dynamic_cast< const SvxBoxInfoItem* >(pState);
597 
598             if(pBoxInfoItem)
599             {
600 			    bool bLeft(false), bRight(false), bTop(false), bBottom(false);
601 
602 			    mbVer = false, mbHor = false;
603 
604                 if(!pBoxInfoItem->IsValid( VALID_VERT )  || pBoxInfoItem->GetVert())
605 				    mbVer = true;
606 
607 			    if(!pBoxInfoItem->IsValid( VALID_HORI )  || pBoxInfoItem->GetHori())
608 				    mbHor = true;
609 
610 			    if(!pBoxInfoItem->IsValid( VALID_LEFT ) || mbLeft)
611 				    bLeft = true;
612 
613 			    if(!pBoxInfoItem->IsValid( VALID_RIGHT ) || mbRight)
614 				    bRight = true;
615 
616 			    if(!pBoxInfoItem->IsValid( VALID_TOP ) || mbTop)
617 				    bTop = true;
618 
619 			    if(!pBoxInfoItem->IsValid( VALID_BOTTOM ) || mbBottom)
620 				    bBottom = true;
621 
622                 if(!Application::GetSettings().GetLayoutRTL())
623 				    mpCellBorderUpdater->UpdateCellBorder(bTop, bBottom, bLeft, bRight, maIMGCellBorder, mbVer, mbHor);
624 			    else
625 				    mpCellBorderUpdater->UpdateCellBorder(bTop, bBottom, bRight, bLeft, maIMGCellBorder, mbVer, mbHor);
626 
627                 if(mbVer || mbHor || bLeft || bRight || bTop || bBottom)
628 				    mbInnerBorder = true;
629 			    else
630 				    mbInnerBorder = false;
631 
632                 UpdateControlState();
633             }
634 		}
635 		break;
636 	case SID_ATTR_BORDER_DIAG_TLBR:
637 		if( eState == SFX_ITEM_DONTCARE )
638 		{
639 			mbTLBR = true;
640 			maTLBRColor.SetColor(COL_TRANSPARENT);
641 			mnTLBRIn = mnTLBROut = mnTLBRDis = 0;
642     		UpdateControlState();
643             break;
644 		}
645 
646         if(eState >= SFX_ITEM_DEFAULT)
647 		{
648 			const SvxLineItem* pItem = dynamic_cast< const SvxLineItem* >(pState);
649 
650             if(pItem)
651             {
652 			    const SvxBorderLine* aLine = pItem->GetLine();
653 
654                 if(!aLine)
655                 {
656 				    mbTLBR = false;
657                 }
658 			    else
659 			    {
660 				    mbTLBR = true;
661 				    maTLBRColor = aLine->GetColor();
662 				    mnTLBRIn = aLine->GetInWidth();
663 				    mnTLBROut = aLine->GetOutWidth();
664 				    mnTLBRDis = aLine->GetDistance();
665 
666                     if(mnTLBRIn == 0 && mnTLBROut == 0 && mnTLBRDis == 0)
667 					    mbTLBR = false;
668 			    }
669 
670                 UpdateControlState();
671                 break;
672             }
673 		}
674 
675         mbTLBR = false;
676 		UpdateControlState();
677 		break;
678 	case SID_ATTR_BORDER_DIAG_BLTR:
679 		if( eState == SFX_ITEM_DONTCARE )
680 		{
681 			mbBLTR = true;
682 			maBLTRColor.SetColor( COL_TRANSPARENT );
683 			mnBLTRIn = mnBLTROut = mnBLTRDis = 0;
684     		UpdateControlState();
685             break;
686 		}
687 
688         if(eState >= SFX_ITEM_DEFAULT)
689 		{
690 			const SvxLineItem* pItem = dynamic_cast< const SvxLineItem* >(pState);
691 
692             if(pItem)
693             {
694 			    const SvxBorderLine* aLine = pItem->GetLine();
695 
696                 if(!aLine)
697                 {
698 				    mbBLTR = false;
699                 }
700 			    else
701 			    {
702 				    mbBLTR = true;
703 				    maBLTRColor = aLine->GetColor();
704 				    mnBLTRIn = aLine->GetInWidth();
705 				    mnBLTROut = aLine->GetOutWidth();
706 				    mnBLTRDis = aLine->GetDistance();
707 
708                     if(mnBLTRIn == 0 && mnBLTROut == 0 && mnBLTRDis == 0)
709 					    mbBLTR = false;
710 			    }
711 
712                 UpdateControlState();
713             }
714             break;
715 		}
716 
717         mbBLTR = false;
718 		UpdateControlState();
719 		break;
720 	case SID_SCGRIDSHOW:
721 		if(eState >= SFX_ITEM_DEFAULT)
722 		{
723 			const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
724 
725             if(pItem)
726             {
727 			    const bool bVal = pItem->GetValue();
728 
729 			    if(bVal)
730 				    mpCBXShowGrid->Check(true);
731 			    else
732 				    mpCBXShowGrid->Check(false);
733             }
734 		}
735 		break;
736 	}
737 }
738 
739 //////////////////////////////////////////////////////////////////////////////
740 
741 SfxBindings* CellAppearancePropertyPanel::GetBindings()
742 {
743     return mpBindings;
744 }
745 
746 //////////////////////////////////////////////////////////////////////////////
747 
748 void CellAppearancePropertyPanel::SetStyleIcon()
749 {
750 	if(mnOut == DEF_LINE_WIDTH_0 && mnIn == 0 && mnDis == 0)	//1
751 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle1H : maIMGLineStyle1);
752 	else if(mnOut == DEF_LINE_WIDTH_2 && mnIn == 0 && mnDis == 0) //2
753 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle2H :maIMGLineStyle2);
754 	else if(mnOut == DEF_LINE_WIDTH_3 && mnIn == 0 && mnDis == 0) //3
755 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle3H :maIMGLineStyle3);
756 	else if(mnOut == DEF_LINE_WIDTH_4 && mnIn == 0 && mnDis == 0) //4
757 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle4H :maIMGLineStyle4);
758 	else if(mnOut == DEF_DOUBLE_LINE0_OUT && mnIn == DEF_DOUBLE_LINE0_IN && mnDis == DEF_DOUBLE_LINE0_DIST) //5
759 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle5H :maIMGLineStyle5);
760 	else if(mnOut == DEF_DOUBLE_LINE7_OUT && mnIn == DEF_DOUBLE_LINE7_IN && mnDis == DEF_DOUBLE_LINE7_DIST) //6
761 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle6H :maIMGLineStyle6);
762 	else if(mnOut == DEF_DOUBLE_LINE4_OUT && mnIn == DEF_DOUBLE_LINE4_IN && mnDis == DEF_DOUBLE_LINE4_DIST) //7
763 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle7H :maIMGLineStyle7);
764 	else if(mnOut == DEF_DOUBLE_LINE9_OUT && mnIn == DEF_DOUBLE_LINE9_IN && mnDis == DEF_DOUBLE_LINE9_DIST) //8
765 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle8H :maIMGLineStyle8);
766 	else if(mnOut == DEF_DOUBLE_LINE2_OUT && mnIn == DEF_DOUBLE_LINE2_IN && mnDis == DEF_DOUBLE_LINE2_DIST) //9
767 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle9H :maIMGLineStyle9);
768 	else
769 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle1H :maIMGLineStyle1);
770 }
771 
772 //////////////////////////////////////////////////////////////////////////////
773 
774 void CellAppearancePropertyPanel::UpdateControlState()
775 {
776 	if(mbOuterBorder || mbInnerBorder || mbTLBR || mbBLTR)
777 	{
778 		mpTBLineColor->Enable();
779 		mpTBLineStyle->Enable();
780 
781 		//set line color state
782 		if( mbLineColorAvailable && !mbTLBR && !mbBLTR )
783 			mpLineColorUpdater->Update(maLineColor);
784 		else if( !mbLineColorAvailable && mbTLBR && !mbBLTR )
785 			mpLineColorUpdater->Update(maTLBRColor);
786 		else if ( !mbLineColorAvailable && !mbTLBR && mbBLTR )
787 			mpLineColorUpdater->Update(maBLTRColor);
788 		else if( !mbLineColorAvailable && mbTLBR && mbBLTR)
789 		{
790 			if( maTLBRColor == maBLTRColor)
791 				mpLineColorUpdater->Update(maBLTRColor);
792 			else
793 				mpLineColorUpdater->Update(COL_TRANSPARENT);
794 		}
795 		else if( mbLineColorAvailable && mbTLBR && !mbBLTR )
796 		{
797 			if( maTLBRColor == maLineColor)
798 				mpLineColorUpdater->Update(maLineColor);
799 			else
800 				mpLineColorUpdater->Update(COL_TRANSPARENT);
801 		}
802 		else if( mbLineColorAvailable && !mbTLBR && mbBLTR )
803 		{
804 			if( maBLTRColor == maLineColor)
805 				mpLineColorUpdater->Update(maLineColor);
806 			else
807 				mpLineColorUpdater->Update(COL_TRANSPARENT);
808 		}
809 		else
810 			mpLineColorUpdater->Update(COL_TRANSPARENT);
811 
812 		//set line style state
813 		if( mbBorderStyleAvailable && !mbTLBR && !mbBLTR )
814 		{
815 		}
816 		else if( !mbBorderStyleAvailable && mbTLBR && !mbBLTR )
817 		{
818 			mnIn = mnTLBRIn;
819 			mnOut = mnTLBROut;
820 			mnDis = mnTLBRDis;
821 		}
822 		else if ( !mbBorderStyleAvailable && !mbTLBR && mbBLTR )
823 		{
824 			mnIn = mnBLTRIn;
825 			mnOut = mnBLTROut;
826 			mnDis = mnBLTRDis;
827 		}
828 		else if( !mbBorderStyleAvailable && mbTLBR && mbBLTR)
829 		{
830 			if( mnTLBRIn == mnBLTRIn && mnTLBROut == mnBLTROut && mnTLBRDis == mnBLTRDis)
831 			{
832 				mnIn = mnTLBRIn;
833 				mnOut = mnTLBROut;
834 				mnDis = mnTLBRDis;
835 			}
836 			else
837 			{
838 				mnIn = 0;
839 				mnOut = 0;
840 				mnDis = 0;
841 			}
842 		}
843 		else if( mbBorderStyleAvailable && mbTLBR && !mbBLTR )
844 		{
845 			if( mnTLBRIn != mnIn || mnTLBROut != mnOut || mnTLBRDis != mnDis)
846 			{
847 				mnIn = 0;
848 				mnOut = 0;
849 				mnDis = 0;
850 			}
851 		}
852 		else if( mbBorderStyleAvailable && !mbTLBR && mbBLTR )
853 		{
854 			if(  mnBLTRIn != mnIn || mnBLTROut != mnOut || mnBLTRDis != mnDis )
855 			{
856 				mnIn = 0;
857 				mnOut = 0;
858 				mnDis = 0;
859 			}
860 		}
861 		else
862 		{
863 			mnIn = 0;
864 			mnOut = 0;
865 			mnDis = 0;
866 		}
867 		SetStyleIcon();
868 	}
869 	else
870 	{
871 		mpTBLineColor->Disable();
872 		mpTBLineStyle->Disable();
873 	}
874 }
875 
876 //////////////////////////////////////////////////////////////////////////////
877 // namespace close
878 
879 }} // end of namespace ::sc::sidebar
880 
881 //////////////////////////////////////////////////////////////////////////////
882 // eof
883