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