1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/sidebar/ResourceDefinitions.hrc>
21 #include <sfx2/sidebar/Theme.hxx>
22 #include <sfx2/sidebar/ControlFactory.hxx>
23 #include "CellAppearancePropertyPanel.hxx"
24 #include <CellAppearancePropertyPanel.hrc>
26 #include "scresid.hxx"
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <vcl/fixed.hxx>
30 #include <svl/eitem.hxx>
31 #include <editeng/borderline.hxx>
32 #include <editeng/boxitem.hxx>
33 #include <editeng/lineitem.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/settings.hxx>
36 #include <boost/bind.hpp>
37 #include <svx/sidebar/PopupContainer.hxx>
38 #include "CellLineStyleControl.hxx"
39 #include "CellLineStylePopup.hxx"
40 #include "CellBorderUpdater.hxx"
41 #include "CellBorderStyleControl.hxx"
42 #include "CellBorderStylePopup.hxx"
45 using namespace css::uno
;
47 const char UNO_SETBORDERSTYLE
[] = ".uno:SetBorderStyle";
48 const char UNO_LINESTYLE
[] = ".uno:LineStyle";
52 namespace sc
{ namespace sidebar
{
54 svx::sidebar::PopupControl
* CellAppearancePropertyPanel::CreateCellLineStylePopupControl(svx::sidebar::PopupContainer
* pParent
)
56 return VclPtr
<CellLineStyleControl
>::Create(pParent
, *this);
59 void CellAppearancePropertyPanel::EndCellLineStylePopupMode()
61 if(mpCellLineStylePopup
.get())
63 mpCellLineStylePopup
->Hide();
67 svx::sidebar::PopupControl
* CellAppearancePropertyPanel::CreateCellBorderStylePopupControl(svx::sidebar::PopupContainer
* pParent
)
69 return VclPtr
<CellBorderStyleControl
>::Create(pParent
, *this);
72 void CellAppearancePropertyPanel::EndCellBorderStylePopupMode()
74 if(mpCellBorderStylePopup
.get())
76 mpCellBorderStylePopup
->Hide();
80 CellAppearancePropertyPanel::CellAppearancePropertyPanel(
82 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
83 SfxBindings
* pBindings
)
84 : PanelLayout(pParent
, "CellAppearancePropertyPanel", "modules/scalc/ui/sidebarcellappearance.ui", rxFrame
),
86 maLineStyleControl(SID_FRAME_LINESTYLE
, *pBindings
, *this),
87 maBorderOuterControl(SID_ATTR_BORDER_OUTER
, *pBindings
, *this),
88 maBorderInnerControl(SID_ATTR_BORDER_INNER
, *pBindings
, *this),
89 maGridShowControl(FID_TAB_TOGGLE_GRID
, *pBindings
, *this),
90 maBorderTLBRControl(SID_ATTR_BORDER_DIAG_TLBR
, *pBindings
, *this),
91 maBorderBLTRControl(SID_ATTR_BORDER_DIAG_BLTR
, *pBindings
, *this),
93 maIMGCellBorder(ScResId(IMG_CELL_BORDER
)),
94 maIMGLineStyle1(ScResId(IMG_LINE_STYLE1
)),
95 maIMGLineStyle2(ScResId(IMG_LINE_STYLE2
)),
96 maIMGLineStyle3(ScResId(IMG_LINE_STYLE3
)),
97 maIMGLineStyle4(ScResId(IMG_LINE_STYLE4
)),
98 maIMGLineStyle5(ScResId(IMG_LINE_STYLE5
)),
99 maIMGLineStyle6(ScResId(IMG_LINE_STYLE6
)),
100 maIMGLineStyle7(ScResId(IMG_LINE_STYLE7
)),
101 maIMGLineStyle8(ScResId(IMG_LINE_STYLE8
)),
102 maIMGLineStyle9(ScResId(IMG_LINE_STYLE9
)),
113 mbBorderStyleAvailable(true),
120 mbOuterBorder(false),
121 mbInnerBorder(false),
125 mpCellLineStylePopup(),
126 mpCellBorderStylePopup(),
130 mpBindings(pBindings
)
132 get(mpTBCellBorder
, "cellbordertype");
133 get(mpTBLineStyle
, "borderlinestyle");
134 get(mpTBLineColor
, "borderlinecolor");
136 mpCellBorderUpdater
.reset( new CellBorderUpdater(
137 mpTBCellBorder
->GetItemId( UNO_SETBORDERSTYLE
), *mpTBCellBorder
) );
142 CellAppearancePropertyPanel::~CellAppearancePropertyPanel()
147 void CellAppearancePropertyPanel::dispose()
149 mpTBCellBorder
.clear();
150 mpTBLineStyle
.clear();
151 mpTBLineColor
.clear();
153 maLineStyleControl
.dispose();
154 maBorderOuterControl
.dispose();
155 maBorderInnerControl
.dispose();
156 maGridShowControl
.dispose();
157 maBorderTLBRControl
.dispose();
158 maBorderBLTRControl
.dispose();
160 PanelLayout::dispose();
163 void CellAppearancePropertyPanel::Initialize()
165 const sal_uInt16 nIdBorderType
= mpTBCellBorder
->GetItemId( UNO_SETBORDERSTYLE
);
166 mpTBCellBorder
->SetItemImage( nIdBorderType
, maIMGCellBorder
);
167 mpTBCellBorder
->SetItemBits( nIdBorderType
, mpTBCellBorder
->GetItemBits( nIdBorderType
) | ToolBoxItemBits::DROPDOWNONLY
);
168 Link
<ToolBox
*, void> aLink
= LINK(this, CellAppearancePropertyPanel
, TbxCellBorderSelectHdl
);
169 mpTBCellBorder
->SetDropdownClickHdl ( aLink
);
170 mpTBCellBorder
->SetSelectHdl ( aLink
);
172 const sal_uInt16 nIdBorderLineStyle
= mpTBLineStyle
->GetItemId( UNO_LINESTYLE
);
173 mpTBLineStyle
->SetItemImage( nIdBorderLineStyle
, maIMGLineStyle1
);
174 mpTBLineStyle
->SetItemBits( nIdBorderLineStyle
, mpTBLineStyle
->GetItemBits( nIdBorderLineStyle
) | ToolBoxItemBits::DROPDOWNONLY
);
175 aLink
= LINK(this, CellAppearancePropertyPanel
, TbxLineStyleSelectHdl
);
176 mpTBLineStyle
->SetDropdownClickHdl ( aLink
);
177 mpTBLineStyle
->SetSelectHdl ( aLink
);
178 mpTBLineStyle
->Disable();
180 mpTBLineColor
->Disable();
182 mpTBLineColor
->SetAccessibleRelationLabeledBy(mpTBLineColor
);
183 mpTBLineStyle
->SetAccessibleRelationLabeledBy(mpTBLineStyle
);
186 IMPL_LINK_TYPED(CellAppearancePropertyPanel
, TbxCellBorderSelectHdl
, ToolBox
*, pToolBox
, void)
188 const OUString
aCommand(pToolBox
->GetItemCommand(pToolBox
->GetCurItemId()));
190 if(aCommand
== UNO_SETBORDERSTYLE
)
192 // create popup on demand
193 if(!mpCellBorderStylePopup
.get())
195 mpCellBorderStylePopup
.reset(
196 new CellBorderStylePopup(
198 ::boost::bind(&CellAppearancePropertyPanel::CreateCellBorderStylePopupControl
, this, _1
)));
201 if(mpCellBorderStylePopup
.get())
203 mpCellBorderStylePopup
->Show(*pToolBox
);
208 IMPL_LINK_TYPED(CellAppearancePropertyPanel
, TbxLineStyleSelectHdl
, ToolBox
*, pToolBox
, void)
210 const OUString
aCommand(pToolBox
->GetItemCommand(pToolBox
->GetCurItemId()));
212 if(aCommand
== UNO_LINESTYLE
)
214 // create popup on demand
215 if(!mpCellLineStylePopup
.get())
217 mpCellLineStylePopup
.reset(
218 new CellLineStylePopup(
220 ::boost::bind(&CellAppearancePropertyPanel::CreateCellLineStylePopupControl
, this, _1
)));
223 if(mpCellLineStylePopup
.get())
225 mpCellLineStylePopup
->SetLineStyleSelect(mnOut
, mnIn
, mnDis
);
226 mpCellLineStylePopup
->Show(*pToolBox
);
231 VclPtr
<vcl::Window
> CellAppearancePropertyPanel::Create (
232 vcl::Window
* pParent
,
233 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
234 SfxBindings
* pBindings
)
237 throw lang::IllegalArgumentException("no parent Window given to CellAppearancePropertyPanel::Create", NULL
, 0);
239 throw lang::IllegalArgumentException("no XFrame given to CellAppearancePropertyPanel::Create", NULL
, 1);
240 if (pBindings
== NULL
)
241 throw lang::IllegalArgumentException("no SfxBindings given to CellAppearancePropertyPanel::Create", NULL
, 2);
243 return VclPtr
<CellAppearancePropertyPanel
>::Create(
244 pParent
, rxFrame
, pBindings
);
247 void CellAppearancePropertyPanel::DataChanged(
248 const DataChangedEvent
& rEvent
)
253 void CellAppearancePropertyPanel::HandleContextChange(const ::sfx2::sidebar::EnumContext
& rContext
)
255 if (maContext
== rContext
)
261 maContext
= rContext
;
264 void CellAppearancePropertyPanel::NotifyItemUpdate(
267 const SfxPoolItem
* pState
,
268 const bool bIsEnabled
)
274 case SID_FRAME_LINESTYLE
:
275 if( eState
== SfxItemState::DONTCARE
)
277 mbBorderStyleAvailable
= true;
285 if(eState
>= SfxItemState::DEFAULT
)
287 const SvxLineItem
* pSvxLineItem
= dynamic_cast< const SvxLineItem
* >(pState
);
291 const editeng::SvxBorderLine
* mbLineItem
= pSvxLineItem
->GetLine();
292 mnIn
= mbLineItem
->GetInWidth();
293 mnOut
= mbLineItem
->GetOutWidth();
294 mnDis
= mbLineItem
->GetDistance();
296 if(mnIn
== 0 && mnOut
== 0 && mnDis
== 0)
297 mbBorderStyleAvailable
= false;
299 mbBorderStyleAvailable
= true;
306 mbBorderStyleAvailable
= false;
309 case SID_ATTR_BORDER_OUTER
:
310 if(eState
>= SfxItemState::DEFAULT
)
312 const SvxBoxItem
* pBoxItem
= dynamic_cast< const SvxBoxItem
* >(pState
);
316 mbLeft
=false, mbRight
=false, mbTop
=false, mbBottom
=false;
318 if(pBoxItem
->GetLeft())
321 if(pBoxItem
->GetRight())
324 if(pBoxItem
->GetTop())
327 if(pBoxItem
->GetBottom())
330 if(!AllSettings::GetLayoutRTL())
331 mpCellBorderUpdater
->UpdateCellBorder(mbTop
, mbBottom
, mbLeft
, mbRight
, maIMGCellBorder
, mbVer
, mbHor
);
333 mpCellBorderUpdater
->UpdateCellBorder(mbTop
, mbBottom
, mbRight
, mbLeft
, maIMGCellBorder
, mbVer
, mbHor
);
335 if(mbLeft
|| mbRight
|| mbTop
|| mbBottom
)
336 mbOuterBorder
= true;
338 mbOuterBorder
= false;
340 UpdateControlState();
344 case SID_ATTR_BORDER_INNER
:
345 if(eState
>= SfxItemState::DEFAULT
)
347 const SvxBoxInfoItem
* pBoxInfoItem
= dynamic_cast< const SvxBoxInfoItem
* >(pState
);
351 bool bLeft(false), bRight(false), bTop(false), bBottom(false);
353 mbVer
= false, mbHor
= false;
355 if(!pBoxInfoItem
->IsValid( SvxBoxInfoItemValidFlags::VERT
) || pBoxInfoItem
->GetVert())
358 if(!pBoxInfoItem
->IsValid( SvxBoxInfoItemValidFlags::HORI
) || pBoxInfoItem
->GetHori())
361 if(!pBoxInfoItem
->IsValid( SvxBoxInfoItemValidFlags::LEFT
) || mbLeft
)
364 if(!pBoxInfoItem
->IsValid( SvxBoxInfoItemValidFlags::RIGHT
) || mbRight
)
367 if(!pBoxInfoItem
->IsValid( SvxBoxInfoItemValidFlags::TOP
) || mbTop
)
370 if(!pBoxInfoItem
->IsValid( SvxBoxInfoItemValidFlags::BOTTOM
) || mbBottom
)
373 if(!AllSettings::GetLayoutRTL())
374 mpCellBorderUpdater
->UpdateCellBorder(bTop
, bBottom
, bLeft
, bRight
, maIMGCellBorder
, mbVer
, mbHor
);
376 mpCellBorderUpdater
->UpdateCellBorder(bTop
, bBottom
, bRight
, bLeft
, maIMGCellBorder
, mbVer
, mbHor
);
378 if(mbVer
|| mbHor
|| bLeft
|| bRight
|| bTop
|| bBottom
)
379 mbInnerBorder
= true;
381 mbInnerBorder
= false;
383 UpdateControlState();
387 case SID_ATTR_BORDER_DIAG_TLBR
:
388 if( eState
== SfxItemState::DONTCARE
)
391 mnTLBRIn
= mnTLBROut
= mnTLBRDis
= 0;
392 UpdateControlState();
396 if(eState
>= SfxItemState::DEFAULT
)
398 const SvxLineItem
* pItem
= dynamic_cast< const SvxLineItem
* >(pState
);
402 const editeng::SvxBorderLine
* aLine
= pItem
->GetLine();
411 mnTLBRIn
= aLine
->GetInWidth();
412 mnTLBROut
= aLine
->GetOutWidth();
413 mnTLBRDis
= aLine
->GetDistance();
415 if(mnTLBRIn
== 0 && mnTLBROut
== 0 && mnTLBRDis
== 0)
419 UpdateControlState();
425 UpdateControlState();
427 case SID_ATTR_BORDER_DIAG_BLTR
:
428 if( eState
== SfxItemState::DONTCARE
)
431 mnBLTRIn
= mnBLTROut
= mnBLTRDis
= 0;
432 UpdateControlState();
436 if(eState
>= SfxItemState::DEFAULT
)
438 const SvxLineItem
* pItem
= dynamic_cast< const SvxLineItem
* >(pState
);
442 const editeng::SvxBorderLine
* aLine
= pItem
->GetLine();
451 mnBLTRIn
= aLine
->GetInWidth();
452 mnBLTROut
= aLine
->GetOutWidth();
453 mnBLTRDis
= aLine
->GetDistance();
455 if(mnBLTRIn
== 0 && mnBLTROut
== 0 && mnBLTRDis
== 0)
459 UpdateControlState();
465 UpdateControlState();
470 void CellAppearancePropertyPanel::SetStyleIcon()
472 const sal_uInt16 nIdBorderLineStyle
= mpTBLineStyle
->GetItemId( UNO_LINESTYLE
);
474 //FIXME: update for new line border possibilities
475 if(mnOut
== DEF_LINE_WIDTH_0
&& mnIn
== 0 && mnDis
== 0) //1
476 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle1
);
477 else if(mnOut
== DEF_LINE_WIDTH_2
&& mnIn
== 0 && mnDis
== 0) //2
478 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle2
);
479 else if(mnOut
== DEF_LINE_WIDTH_3
&& mnIn
== 0 && mnDis
== 0) //3
480 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle3
);
481 else if(mnOut
== DEF_LINE_WIDTH_4
&& mnIn
== 0 && mnDis
== 0) //4
482 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle4
);
483 else if(mnOut
== DEF_LINE_WIDTH_0
&& mnIn
== DEF_LINE_WIDTH_0
&& mnDis
== DEF_LINE_WIDTH_1
) //5
484 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle5
);
485 else if(mnOut
== DEF_LINE_WIDTH_0
&& mnIn
== DEF_LINE_WIDTH_0
&& mnDis
== DEF_LINE_WIDTH_2
) //6
486 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle6
);
487 else if(mnOut
== DEF_LINE_WIDTH_1
&& mnIn
== DEF_LINE_WIDTH_2
&& mnDis
== DEF_LINE_WIDTH_1
) //7
488 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle7
);
489 else if(mnOut
== DEF_LINE_WIDTH_2
&& mnIn
== DEF_LINE_WIDTH_0
&& mnDis
== DEF_LINE_WIDTH_2
) //8
490 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle8
);
491 else if(mnOut
== DEF_LINE_WIDTH_2
&& mnIn
== DEF_LINE_WIDTH_2
&& mnDis
== DEF_LINE_WIDTH_2
) //9
492 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle9
);
494 mpTBLineStyle
->SetItemImage(nIdBorderLineStyle
, maIMGLineStyle1
);
497 void CellAppearancePropertyPanel::UpdateControlState()
499 if(mbOuterBorder
|| mbInnerBorder
|| mbTLBR
|| mbBLTR
)
501 mpTBLineColor
->Enable();
502 mpTBLineStyle
->Enable();
504 //set line style state
505 if( mbBorderStyleAvailable
&& !mbTLBR
&& !mbBLTR
)
508 else if( !mbBorderStyleAvailable
&& mbTLBR
&& !mbBLTR
)
514 else if ( !mbBorderStyleAvailable
&& !mbTLBR
&& mbBLTR
)
520 else if( !mbBorderStyleAvailable
&& mbTLBR
&& mbBLTR
)
522 if( mnTLBRIn
== mnBLTRIn
&& mnTLBROut
== mnBLTROut
&& mnTLBRDis
== mnBLTRDis
)
535 else if( mbBorderStyleAvailable
&& mbTLBR
&& !mbBLTR
)
537 if( mnTLBRIn
!= mnIn
|| mnTLBROut
!= mnOut
|| mnTLBRDis
!= mnDis
)
544 else if( mbBorderStyleAvailable
&& !mbTLBR
&& mbBLTR
)
546 if( mnBLTRIn
!= mnIn
|| mnBLTROut
!= mnOut
|| mnBLTRDis
!= mnDis
)
563 mpTBLineColor
->Disable();
564 mpTBLineStyle
->Disable();
570 }} // end of namespace ::sc::sidebar
572 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */