fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / sidebar / CellAppearancePropertyPanel.cxx
blobe3b77fdb8fc43ea45a02f92923b1e2a2751da453
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include "sc.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"
44 using namespace css;
45 using namespace css::uno;
47 const char UNO_SETBORDERSTYLE[] = ".uno:SetBorderStyle";
48 const char UNO_LINESTYLE[] = ".uno:LineStyle";
50 // namespace open
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(
81 vcl::Window* pParent,
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)),
104 mnIn(0),
105 mnOut(0),
106 mnDis(0),
107 mnTLBRIn(0),
108 mnTLBROut(0),
109 mnTLBRDis(0),
110 mnBLTRIn(0),
111 mnBLTROut(0),
112 mnBLTRDis(0),
113 mbBorderStyleAvailable(true),
114 mbLeft(false),
115 mbRight(false),
116 mbTop(false),
117 mbBottom(false),
118 mbVer(false),
119 mbHor(false),
120 mbOuterBorder(false),
121 mbInnerBorder(false),
122 mbTLBR(false),
123 mbBLTR(false),
125 mpCellLineStylePopup(),
126 mpCellBorderStylePopup(),
128 mxFrame(rxFrame),
129 maContext(),
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) );
139 Initialize();
142 CellAppearancePropertyPanel::~CellAppearancePropertyPanel()
144 disposeOnce();
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(
197 this,
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(
219 this,
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)
236 if (pParent == NULL)
237 throw lang::IllegalArgumentException("no parent Window given to CellAppearancePropertyPanel::Create", NULL, 0);
238 if ( ! rxFrame.is())
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)
250 (void)rEvent;
253 void CellAppearancePropertyPanel::HandleContextChange(const ::sfx2::sidebar::EnumContext& rContext)
255 if (maContext == rContext)
257 // Nothing to do.
258 return;
261 maContext = rContext;
264 void CellAppearancePropertyPanel::NotifyItemUpdate(
265 sal_uInt16 nSID,
266 SfxItemState eState,
267 const SfxPoolItem* pState,
268 const bool bIsEnabled)
270 (void)bIsEnabled;
272 switch(nSID)
274 case SID_FRAME_LINESTYLE:
275 if( eState == SfxItemState::DONTCARE )
277 mbBorderStyleAvailable = true;
278 mnIn = 0;
279 mnOut = 0;
280 mnDis = 0;
281 SetStyleIcon();
282 break;
285 if(eState >= SfxItemState::DEFAULT)
287 const SvxLineItem* pSvxLineItem = dynamic_cast< const SvxLineItem* >(pState);
289 if(pSvxLineItem)
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;
298 else
299 mbBorderStyleAvailable = true;
301 SetStyleIcon();
302 break;
306 mbBorderStyleAvailable = false;
307 SetStyleIcon();
308 break;
309 case SID_ATTR_BORDER_OUTER:
310 if(eState >= SfxItemState::DEFAULT)
312 const SvxBoxItem* pBoxItem = dynamic_cast< const SvxBoxItem* >(pState);
314 if(pBoxItem)
316 mbLeft=false, mbRight=false, mbTop=false, mbBottom=false;
318 if(pBoxItem->GetLeft())
319 mbLeft = true;
321 if(pBoxItem->GetRight())
322 mbRight = true;
324 if(pBoxItem->GetTop())
325 mbTop = true;
327 if(pBoxItem->GetBottom())
328 mbBottom = true;
330 if(!AllSettings::GetLayoutRTL())
331 mpCellBorderUpdater->UpdateCellBorder(mbTop, mbBottom, mbLeft, mbRight, maIMGCellBorder, mbVer, mbHor);
332 else
333 mpCellBorderUpdater->UpdateCellBorder(mbTop, mbBottom, mbRight, mbLeft, maIMGCellBorder, mbVer, mbHor);
335 if(mbLeft || mbRight || mbTop || mbBottom)
336 mbOuterBorder = true;
337 else
338 mbOuterBorder = false;
340 UpdateControlState();
343 break;
344 case SID_ATTR_BORDER_INNER:
345 if(eState >= SfxItemState::DEFAULT)
347 const SvxBoxInfoItem* pBoxInfoItem = dynamic_cast< const SvxBoxInfoItem* >(pState);
349 if(pBoxInfoItem)
351 bool bLeft(false), bRight(false), bTop(false), bBottom(false);
353 mbVer = false, mbHor = false;
355 if(!pBoxInfoItem->IsValid( SvxBoxInfoItemValidFlags::VERT ) || pBoxInfoItem->GetVert())
356 mbVer = true;
358 if(!pBoxInfoItem->IsValid( SvxBoxInfoItemValidFlags::HORI ) || pBoxInfoItem->GetHori())
359 mbHor = true;
361 if(!pBoxInfoItem->IsValid( SvxBoxInfoItemValidFlags::LEFT ) || mbLeft)
362 bLeft = true;
364 if(!pBoxInfoItem->IsValid( SvxBoxInfoItemValidFlags::RIGHT ) || mbRight)
365 bRight = true;
367 if(!pBoxInfoItem->IsValid( SvxBoxInfoItemValidFlags::TOP ) || mbTop)
368 bTop = true;
370 if(!pBoxInfoItem->IsValid( SvxBoxInfoItemValidFlags::BOTTOM ) || mbBottom)
371 bBottom = true;
373 if(!AllSettings::GetLayoutRTL())
374 mpCellBorderUpdater->UpdateCellBorder(bTop, bBottom, bLeft, bRight, maIMGCellBorder, mbVer, mbHor);
375 else
376 mpCellBorderUpdater->UpdateCellBorder(bTop, bBottom, bRight, bLeft, maIMGCellBorder, mbVer, mbHor);
378 if(mbVer || mbHor || bLeft || bRight || bTop || bBottom)
379 mbInnerBorder = true;
380 else
381 mbInnerBorder = false;
383 UpdateControlState();
386 break;
387 case SID_ATTR_BORDER_DIAG_TLBR:
388 if( eState == SfxItemState::DONTCARE )
390 mbTLBR = true;
391 mnTLBRIn = mnTLBROut = mnTLBRDis = 0;
392 UpdateControlState();
393 break;
396 if(eState >= SfxItemState::DEFAULT)
398 const SvxLineItem* pItem = dynamic_cast< const SvxLineItem* >(pState);
400 if(pItem)
402 const editeng::SvxBorderLine* aLine = pItem->GetLine();
404 if(!aLine)
406 mbTLBR = false;
408 else
410 mbTLBR = true;
411 mnTLBRIn = aLine->GetInWidth();
412 mnTLBROut = aLine->GetOutWidth();
413 mnTLBRDis = aLine->GetDistance();
415 if(mnTLBRIn == 0 && mnTLBROut == 0 && mnTLBRDis == 0)
416 mbTLBR = false;
419 UpdateControlState();
420 break;
424 mbTLBR = false;
425 UpdateControlState();
426 break;
427 case SID_ATTR_BORDER_DIAG_BLTR:
428 if( eState == SfxItemState::DONTCARE )
430 mbBLTR = true;
431 mnBLTRIn = mnBLTROut = mnBLTRDis = 0;
432 UpdateControlState();
433 break;
436 if(eState >= SfxItemState::DEFAULT)
438 const SvxLineItem* pItem = dynamic_cast< const SvxLineItem* >(pState);
440 if(pItem)
442 const editeng::SvxBorderLine* aLine = pItem->GetLine();
444 if(!aLine)
446 mbBLTR = false;
448 else
450 mbBLTR = true;
451 mnBLTRIn = aLine->GetInWidth();
452 mnBLTROut = aLine->GetOutWidth();
453 mnBLTRDis = aLine->GetDistance();
455 if(mnBLTRIn == 0 && mnBLTROut == 0 && mnBLTRDis == 0)
456 mbBLTR = false;
459 UpdateControlState();
461 break;
464 mbBLTR = false;
465 UpdateControlState();
466 break;
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);
493 else
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 )
510 mnIn = mnTLBRIn;
511 mnOut = mnTLBROut;
512 mnDis = mnTLBRDis;
514 else if ( !mbBorderStyleAvailable && !mbTLBR && mbBLTR )
516 mnIn = mnBLTRIn;
517 mnOut = mnBLTROut;
518 mnDis = mnBLTRDis;
520 else if( !mbBorderStyleAvailable && mbTLBR && mbBLTR)
522 if( mnTLBRIn == mnBLTRIn && mnTLBROut == mnBLTROut && mnTLBRDis == mnBLTRDis)
524 mnIn = mnTLBRIn;
525 mnOut = mnTLBROut;
526 mnDis = mnTLBRDis;
528 else
530 mnIn = 0;
531 mnOut = 0;
532 mnDis = 0;
535 else if( mbBorderStyleAvailable && mbTLBR && !mbBLTR )
537 if( mnTLBRIn != mnIn || mnTLBROut != mnOut || mnTLBRDis != mnDis)
539 mnIn = 0;
540 mnOut = 0;
541 mnDis = 0;
544 else if( mbBorderStyleAvailable && !mbTLBR && mbBLTR )
546 if( mnBLTRIn != mnIn || mnBLTROut != mnOut || mnBLTRDis != mnDis )
548 mnIn = 0;
549 mnOut = 0;
550 mnDis = 0;
553 else
555 mnIn = 0;
556 mnOut = 0;
557 mnDis = 0;
559 SetStyleIcon();
561 else
563 mpTBLineColor->Disable();
564 mpTBLineStyle->Disable();
568 // namespace close
570 }} // end of namespace ::sc::sidebar
572 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */