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 {
466 	switch(nSID)
467 	{
468 	case SID_BACKGROUND_COLOR:
469 		if(eState >= SFX_ITEM_DEFAULT)
470 		{
471             const SvxColorItem* pSvxColorItem = dynamic_cast< const SvxColorItem* >(pState);
472 
473             if(pSvxColorItem)
474             {
475 			    maBackColor = ((const SvxColorItem*)pState)->GetValue();
476 			    mbBackColorAvailable = true;
477 			    mpFillColorUpdater->Update(maBackColor);
478                 break;
479             }
480 		}
481 
482         mbBackColorAvailable = false;
483 		maBackColor.SetColor(COL_TRANSPARENT);
484 		mpFillColorUpdater->Update(COL_TRANSPARENT);
485         break;
486 	case SID_FRAME_LINECOLOR:
487 		if( eState == SFX_ITEM_DONTCARE)
488 		{
489 			mbLineColorAvailable = true;
490 			maLineColor.SetColor( COL_TRANSPARENT );
491     		UpdateControlState();
492             break;
493 		}
494 
495         if(eState >= SFX_ITEM_DEFAULT && pState && pState->ISA(SvxColorItem) )
496 		{
497             const SvxColorItem* pSvxColorItem = dynamic_cast< const SvxColorItem* >(pState);
498 
499             if(pSvxColorItem)
500             {
501 			    maLineColor = ((const SvxColorItem*)pState)->GetValue();
502 			    if(maLineColor == COL_AUTO)
503 				    mbLineColorAvailable = false;
504 			    else
505 			    {
506 				    mbLineColorAvailable = true;
507 			    //	mpLineColorUpdater->Update(maLineColor);
508 			    }
509 
510                 UpdateControlState();
511                 break;
512             }
513 		}
514 
515         mbLineColorAvailable = false;
516 		maLineColor.SetColor(COL_AUTO);
517 	    //	mpLineColorUpdater->Update(maLineColor);
518 		UpdateControlState();
519 		break;
520 	case SID_FRAME_LINESTYLE:
521 		if( eState == SFX_ITEM_DONTCARE )
522 		{
523 			mbBorderStyleAvailable = true;
524 			mnIn = 0;
525 			mnOut = 0;
526 			mnDis = 0;
527     		SetStyleIcon();
528             break;
529 		}
530 
531         if(eState >= SFX_ITEM_DEFAULT)
532 		{
533             const SvxLineItem* pSvxLineItem = dynamic_cast< const SvxLineItem* >(pState);
534 
535             if(pSvxLineItem)
536             {
537 			    const SvxBorderLine* mbLineItem = pSvxLineItem->GetLine();
538 			    mnIn = mbLineItem->GetInWidth();
539 			    mnOut = mbLineItem->GetOutWidth();
540 			    mnDis = mbLineItem->GetDistance();
541 
542                 if(mnIn == 0 && mnOut == 0 && mnDis == 0)
543 				    mbBorderStyleAvailable = false;
544 			    else
545 				    mbBorderStyleAvailable = true;
546 
547                 SetStyleIcon();
548                 break;
549             }
550 		}
551 
552 		mbBorderStyleAvailable = false;
553 		SetStyleIcon();
554 		break;
555 	case SID_ATTR_BORDER_OUTER:
556 		if(eState >= SFX_ITEM_DEFAULT)
557 		{
558 			const SvxBoxItem* pBoxItem = dynamic_cast< const SvxBoxItem* >(pState);
559 
560             if(pBoxItem)
561             {
562 			    mbLeft=false, mbRight=false, mbTop=false, mbBottom=false;
563 
564 			    if(pBoxItem->GetLeft())
565 				    mbLeft = true;
566 
567                 if(pBoxItem->GetRight())
568 				    mbRight = true;
569 
570                 if(pBoxItem->GetTop())
571 				    mbTop = true;
572 
573                 if(pBoxItem->GetBottom())
574 				    mbBottom = true;
575 
576                 if(!Application::GetSettings().GetLayoutRTL())
577 				    mpCellBorderUpdater->UpdateCellBorder(mbTop, mbBottom, mbLeft, mbRight, maIMGCellBorder, mbVer, mbHor);
578 			    else
579 				    mpCellBorderUpdater->UpdateCellBorder(mbTop, mbBottom, mbRight, mbLeft, maIMGCellBorder, mbVer, mbHor);
580 
581                 if(mbLeft || mbRight || mbTop || mbBottom)
582 				    mbOuterBorder = true;
583 			    else
584 				    mbOuterBorder = false;
585 
586                 UpdateControlState();
587             }
588 		}
589 		break;
590 	case SID_ATTR_BORDER_INNER:
591 		if(eState >= SFX_ITEM_DEFAULT)
592 		{
593 			const SvxBoxInfoItem* pBoxInfoItem = dynamic_cast< const SvxBoxInfoItem* >(pState);
594 
595             if(pBoxInfoItem)
596             {
597 			    bool bLeft(false), bRight(false), bTop(false), bBottom(false);
598 
599 			    mbVer = false, mbHor = false;
600 
601                 if(!pBoxInfoItem->IsValid( VALID_VERT )  || pBoxInfoItem->GetVert())
602 				    mbVer = true;
603 
604 			    if(!pBoxInfoItem->IsValid( VALID_HORI )  || pBoxInfoItem->GetHori())
605 				    mbHor = true;
606 
607 			    if(!pBoxInfoItem->IsValid( VALID_LEFT ) || mbLeft)
608 				    bLeft = true;
609 
610 			    if(!pBoxInfoItem->IsValid( VALID_RIGHT ) || mbRight)
611 				    bRight = true;
612 
613 			    if(!pBoxInfoItem->IsValid( VALID_TOP ) || mbTop)
614 				    bTop = true;
615 
616 			    if(!pBoxInfoItem->IsValid( VALID_BOTTOM ) || mbBottom)
617 				    bBottom = true;
618 
619                 if(!Application::GetSettings().GetLayoutRTL())
620 				    mpCellBorderUpdater->UpdateCellBorder(bTop, bBottom, bLeft, bRight, maIMGCellBorder, mbVer, mbHor);
621 			    else
622 				    mpCellBorderUpdater->UpdateCellBorder(bTop, bBottom, bRight, bLeft, maIMGCellBorder, mbVer, mbHor);
623 
624                 if(mbVer || mbHor || bLeft || bRight || bTop || bBottom)
625 				    mbInnerBorder = true;
626 			    else
627 				    mbInnerBorder = false;
628 
629                 UpdateControlState();
630             }
631 		}
632 		break;
633 	case SID_ATTR_BORDER_DIAG_TLBR:
634 		if( eState == SFX_ITEM_DONTCARE )
635 		{
636 			mbTLBR = true;
637 			maTLBRColor.SetColor(COL_TRANSPARENT);
638 			mnTLBRIn = mnTLBROut = mnTLBRDis = 0;
639     		UpdateControlState();
640             break;
641 		}
642 
643         if(eState >= SFX_ITEM_DEFAULT)
644 		{
645 			const SvxLineItem* pItem = dynamic_cast< const SvxLineItem* >(pState);
646 
647             if(pItem)
648             {
649 			    const SvxBorderLine* aLine = pItem->GetLine();
650 
651                 if(!aLine)
652                 {
653 				    mbTLBR = false;
654                 }
655 			    else
656 			    {
657 				    mbTLBR = true;
658 				    maTLBRColor = aLine->GetColor();
659 				    mnTLBRIn = aLine->GetInWidth();
660 				    mnTLBROut = aLine->GetOutWidth();
661 				    mnTLBRDis = aLine->GetDistance();
662 
663                     if(mnTLBRIn == 0 && mnTLBROut == 0 && mnTLBRDis == 0)
664 					    mbTLBR = false;
665 			    }
666 
667                 UpdateControlState();
668                 break;
669             }
670 		}
671 
672         mbTLBR = false;
673 		UpdateControlState();
674 		break;
675 	case SID_ATTR_BORDER_DIAG_BLTR:
676 		if( eState == SFX_ITEM_DONTCARE )
677 		{
678 			mbBLTR = true;
679 			maBLTRColor.SetColor( COL_TRANSPARENT );
680 			mnBLTRIn = mnBLTROut = mnBLTRDis = 0;
681     		UpdateControlState();
682             break;
683 		}
684 
685         if(eState >= SFX_ITEM_DEFAULT)
686 		{
687 			const SvxLineItem* pItem = dynamic_cast< const SvxLineItem* >(pState);
688 
689             if(pItem)
690             {
691 			    const SvxBorderLine* aLine = pItem->GetLine();
692 
693                 if(!aLine)
694                 {
695 				    mbBLTR = false;
696                 }
697 			    else
698 			    {
699 				    mbBLTR = true;
700 				    maBLTRColor = aLine->GetColor();
701 				    mnBLTRIn = aLine->GetInWidth();
702 				    mnBLTROut = aLine->GetOutWidth();
703 				    mnBLTRDis = aLine->GetDistance();
704 
705                     if(mnBLTRIn == 0 && mnBLTROut == 0 && mnBLTRDis == 0)
706 					    mbBLTR = false;
707 			    }
708 
709                 UpdateControlState();
710             }
711             break;
712 		}
713 
714         mbBLTR = false;
715 		UpdateControlState();
716 		break;
717 	case SID_SCGRIDSHOW:
718 		if(eState >= SFX_ITEM_DEFAULT)
719 		{
720 			const SfxBoolItem* pItem = dynamic_cast< const SfxBoolItem* >(pState);
721 
722             if(pItem)
723             {
724 			    const bool bVal = pItem->GetValue();
725 
726 			    if(bVal)
727 				    mpCBXShowGrid->Check(true);
728 			    else
729 				    mpCBXShowGrid->Check(false);
730             }
731 		}
732 		break;
733 	}
734 }
735 
736 //////////////////////////////////////////////////////////////////////////////
737 
738 SfxBindings* CellAppearancePropertyPanel::GetBindings()
739 {
740     return mpBindings;
741 }
742 
743 //////////////////////////////////////////////////////////////////////////////
744 
745 void CellAppearancePropertyPanel::SetStyleIcon()
746 {
747 	if(mnOut == DEF_LINE_WIDTH_0 && mnIn == 0 && mnDis == 0)	//1
748 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle1H : maIMGLineStyle1);
749 	else if(mnOut == DEF_LINE_WIDTH_2 && mnIn == 0 && mnDis == 0) //2
750 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle2H :maIMGLineStyle2);
751 	else if(mnOut == DEF_LINE_WIDTH_3 && mnIn == 0 && mnDis == 0) //3
752 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle3H :maIMGLineStyle3);
753 	else if(mnOut == DEF_LINE_WIDTH_4 && mnIn == 0 && mnDis == 0) //4
754 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle4H :maIMGLineStyle4);
755 	else if(mnOut == DEF_DOUBLE_LINE0_OUT && mnIn == DEF_DOUBLE_LINE0_IN && mnDis == DEF_DOUBLE_LINE0_DIST) //5
756 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle5H :maIMGLineStyle5);
757 	else if(mnOut == DEF_DOUBLE_LINE7_OUT && mnIn == DEF_DOUBLE_LINE7_IN && mnDis == DEF_DOUBLE_LINE7_DIST) //6
758 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle6H :maIMGLineStyle6);
759 	else if(mnOut == DEF_DOUBLE_LINE4_OUT && mnIn == DEF_DOUBLE_LINE4_IN && mnDis == DEF_DOUBLE_LINE4_DIST) //7
760 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle7H :maIMGLineStyle7);
761 	else if(mnOut == DEF_DOUBLE_LINE9_OUT && mnIn == DEF_DOUBLE_LINE9_IN && mnDis == DEF_DOUBLE_LINE9_DIST) //8
762 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle8H :maIMGLineStyle8);
763 	else if(mnOut == DEF_DOUBLE_LINE2_OUT && mnIn == DEF_DOUBLE_LINE2_IN && mnDis == DEF_DOUBLE_LINE2_DIST) //9
764 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle9H :maIMGLineStyle9);
765 	else
766 		mpTBLineStyle->SetItemImage(TBI_LINE_STYLE, GetDisplayBackground().GetColor().IsDark() ? maIMGLineStyle1H :maIMGLineStyle1);
767 }
768 
769 //////////////////////////////////////////////////////////////////////////////
770 
771 void CellAppearancePropertyPanel::UpdateControlState()
772 {
773 	if(mbOuterBorder || mbInnerBorder || mbTLBR || mbBLTR)
774 	{
775 		mpTBLineColor->Enable();
776 		mpTBLineStyle->Enable();
777 
778 		//set line color state
779 		if( mbLineColorAvailable && !mbTLBR && !mbBLTR )
780 			mpLineColorUpdater->Update(maLineColor);
781 		else if( !mbLineColorAvailable && mbTLBR && !mbBLTR )
782 			mpLineColorUpdater->Update(maTLBRColor);
783 		else if ( !mbLineColorAvailable && !mbTLBR && mbBLTR )
784 			mpLineColorUpdater->Update(maBLTRColor);
785 		else if( !mbLineColorAvailable && mbTLBR && mbBLTR)
786 		{
787 			if( maTLBRColor == maBLTRColor)
788 				mpLineColorUpdater->Update(maBLTRColor);
789 			else
790 				mpLineColorUpdater->Update(COL_TRANSPARENT);
791 		}
792 		else if( mbLineColorAvailable && mbTLBR && !mbBLTR )
793 		{
794 			if( maTLBRColor == maLineColor)
795 				mpLineColorUpdater->Update(maLineColor);
796 			else
797 				mpLineColorUpdater->Update(COL_TRANSPARENT);
798 		}
799 		else if( mbLineColorAvailable && !mbTLBR && mbBLTR )
800 		{
801 			if( maBLTRColor == maLineColor)
802 				mpLineColorUpdater->Update(maLineColor);
803 			else
804 				mpLineColorUpdater->Update(COL_TRANSPARENT);
805 		}
806 		else
807 			mpLineColorUpdater->Update(COL_TRANSPARENT);
808 
809 		//set line style state
810 		if( mbBorderStyleAvailable && !mbTLBR && !mbBLTR )
811 		{
812 		}
813 		else if( !mbBorderStyleAvailable && mbTLBR && !mbBLTR )
814 		{
815 			mnIn = mnTLBRIn;
816 			mnOut = mnTLBROut;
817 			mnDis = mnTLBRDis;
818 		}
819 		else if ( !mbBorderStyleAvailable && !mbTLBR && mbBLTR )
820 		{
821 			mnIn = mnBLTRIn;
822 			mnOut = mnBLTROut;
823 			mnDis = mnBLTRDis;
824 		}
825 		else if( !mbBorderStyleAvailable && mbTLBR && mbBLTR)
826 		{
827 			if( mnTLBRIn == mnBLTRIn && mnTLBROut == mnBLTROut && mnTLBRDis == mnBLTRDis)
828 			{
829 				mnIn = mnTLBRIn;
830 				mnOut = mnTLBROut;
831 				mnDis = mnTLBRDis;
832 			}
833 			else
834 			{
835 				mnIn = 0;
836 				mnOut = 0;
837 				mnDis = 0;
838 			}
839 		}
840 		else if( mbBorderStyleAvailable && mbTLBR && !mbBLTR )
841 		{
842 			if( mnTLBRIn != mnIn || mnTLBROut != mnOut || mnTLBRDis != mnDis)
843 			{
844 				mnIn = 0;
845 				mnOut = 0;
846 				mnDis = 0;
847 			}
848 		}
849 		else if( mbBorderStyleAvailable && !mbTLBR && mbBLTR )
850 		{
851 			if(  mnBLTRIn != mnIn || mnBLTROut != mnOut || mnBLTRDis != mnDis )
852 			{
853 				mnIn = 0;
854 				mnOut = 0;
855 				mnDis = 0;
856 			}
857 		}
858 		else
859 		{
860 			mnIn = 0;
861 			mnOut = 0;
862 			mnDis = 0;
863 		}
864 		SetStyleIcon();
865 	}
866 	else
867 	{
868 		mpTBLineColor->Disable();
869 		mpTBLineStyle->Disable();
870 	}
871 }
872 
873 //////////////////////////////////////////////////////////////////////////////
874 // namespace close
875 
876 }} // end of namespace ::sc::sidebar
877 
878 //////////////////////////////////////////////////////////////////////////////
879 // eof
880