Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / sidebar / area / AreaPropertyPanel.cxx
blob0b0a2f8bd8e3a7683a6f524046957b62913cb66e
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 .
19 #include "svx/sidebar/PopupContainer.hxx"
20 #include "AreaTransparencyGradientControl.hxx"
22 #include <sfx2/sidebar/ResourceDefinitions.hrc>
23 #include <sfx2/sidebar/Theme.hxx>
24 #include <sfx2/sidebar/ControlFactory.hxx>
25 #include <AreaPropertyPanel.hxx>
26 #include <AreaPropertyPanel.hrc>
27 #include <svx/dialogs.hrc>
28 #include <svx/dialmgr.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <svx/xfltrit.hxx>
31 #include <svx/xflftrit.hxx>
32 #include <svx/xtable.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <helpid.hrc>
36 #include <svtools/valueset.hxx>
37 #include <unotools/pathoptions.hxx>
38 #include <svx/svxitems.hrc>
39 #include <vcl/toolbox.hxx>
40 #include <svtools/toolbarmenu.hxx>
41 #include <svx/sidebar/ColorControl.hxx>
43 #include <boost/bind.hpp>
45 using namespace css;
46 using namespace cssu;
47 using ::sfx2::sidebar::Theme;
49 const char UNO_SIDEBARCOLOR[] = ".uno:sidebarcolor";
50 const char UNO_SIDEBARGRADIENT[] = ".uno:sidebargradient";
52 namespace svx { namespace sidebar {
54 const sal_Int32 AreaPropertyPanel::DEFAULT_CENTERX = 50;
55 const sal_Int32 AreaPropertyPanel::DEFAULT_CENTERY = 50;
56 const sal_Int32 AreaPropertyPanel::DEFAULT_ANGLE = 0;
57 const sal_Int32 AreaPropertyPanel::DEFAULT_STARTVALUE = 0;
58 const sal_Int32 AreaPropertyPanel::DEFAULT_ENDVALUE = 16777215;
59 const sal_Int32 AreaPropertyPanel::DEFAULT_BORDER = 0;
62 AreaPropertyPanel::AreaPropertyPanel(
63 Window* pParent,
64 const cssu::Reference<css::frame::XFrame>& rxFrame,
65 SfxBindings* pBindings)
66 : PanelLayout(pParent, "AreaPropertyPanel", "svx/ui/sidebararea.ui", rxFrame),
67 meLastXFS(-1),
68 maLastColor(Color(COL_DEFAULT_SHAPE_FILLING)),
69 mnLastPosGradient(0),
70 mnLastPosHatch(0),
71 mnLastPosBitmap(0),
72 mnLastTransSolid(50),
73 maGradientLinear(),
74 maGradientAxial(),
75 maGradientRadial(),
76 maGradientElliptical(),
77 maGradientSquare(),
78 maGradientRect(),
79 mpStyleItem(),
80 mpColorItem(),
81 mpFillGradientItem(),
82 mpHatchItem(),
83 mpBitmapItem(),
84 maStyleControl(SID_ATTR_FILL_STYLE, *pBindings, *this),
85 maColorControl(SID_ATTR_FILL_COLOR, *pBindings, *this),
86 maGradientControl(SID_ATTR_FILL_GRADIENT, *pBindings, *this),
87 maHatchControl(SID_ATTR_FILL_HATCH, *pBindings, *this),
88 maBitmapControl(SID_ATTR_FILL_BITMAP, *pBindings, *this),
89 maColorTableControl(SID_COLOR_TABLE, *pBindings, *this),
90 maGradientListControl(SID_GRADIENT_LIST, *pBindings, *this),
91 maHatchListControl(SID_HATCH_LIST, *pBindings, *this),
92 maBitmapListControl(SID_BITMAP_LIST, *pBindings, *this),
93 maFillTransparenceController(SID_ATTR_FILL_TRANSPARENCE, *pBindings, *this),
94 maFillFloatTransparenceController(SID_ATTR_FILL_FLOATTRANSPARENCE, *pBindings, *this),
95 maImgAxial(SVX_RES(IMG_AXIAL)),
96 maImgElli(SVX_RES(IMG_ELLI)),
97 maImgQuad(SVX_RES(IMG_QUAD)),
98 maImgRadial(SVX_RES(IMG_RADIAL)),
99 maImgSquare(SVX_RES(IMG_SQUARE)),
100 maImgLinear(SVX_RES(IMG_LINEAR)),
101 maImgColor(SVX_RES(IMG_COLOR)),
102 maTrGrPopup(this, ::boost::bind(&AreaPropertyPanel::CreateTransparencyGradientControl, this, _1)),
103 maColorPopup(this, ::boost::bind(&AreaPropertyPanel::CreateColorPopupControl, this, _1)),
104 mpFloatTransparenceItem(),
105 mpTransparanceItem(),
106 mxFrame(rxFrame),
107 mpBindings(pBindings),
108 mbColorAvail(true)
110 get(mpColorTextFT, "filllabel");
111 get(mpLbFillType, "fillstyle");
112 get(mpLbFillAttr, "fillattr");
113 get(mpTrspTextFT, "transparencylabel");
114 get(mpToolBoxColor, "selectcolor");
115 get(mpLBTransType, "transtype");
116 get(mpMTRTransparent, "settransparency");
117 get(mpBTNGradient, "selectgradient");
119 const sal_uInt16 nIdColor = mpToolBoxColor->GetItemId(UNO_SIDEBARCOLOR);
120 mpColorUpdater.reset(new ::svx::ToolboxButtonColorUpdater(SID_ATTR_FILL_COLOR, nIdColor, mpToolBoxColor)),
122 Initialize();
127 AreaPropertyPanel::~AreaPropertyPanel()
133 void AreaPropertyPanel::Initialize()
135 maGradientLinear.SetXOffset(DEFAULT_CENTERX);
136 maGradientLinear.SetYOffset(DEFAULT_CENTERY);
137 maGradientLinear.SetAngle(DEFAULT_ANGLE);
138 maGradientLinear.SetStartColor(Color(DEFAULT_STARTVALUE));
139 maGradientLinear.SetEndColor(Color(DEFAULT_ENDVALUE));
140 maGradientLinear.SetBorder(DEFAULT_BORDER);
141 maGradientLinear.SetGradientStyle(XGRAD_LINEAR);
143 maGradientAxial = maGradientLinear;
144 maGradientAxial.SetGradientStyle(XGRAD_AXIAL);
146 maGradientRadial = maGradientLinear;
147 maGradientRadial.SetGradientStyle(XGRAD_RADIAL);
149 maGradientElliptical = maGradientLinear;
150 maGradientElliptical.SetGradientStyle(XGRAD_ELLIPTICAL);
152 maGradientSquare = maGradientLinear;
153 maGradientSquare.SetGradientStyle(XGRAD_SQUARE);
155 maGradientRect = maGradientLinear;
156 maGradientRect.SetGradientStyle(XGRAD_RECT);
158 mpLbFillType->SetAccessibleName(OUString( "Fill")); //wj acc
159 mpLbFillAttr->SetAccessibleName(OUString( "Fill")); //wj acc
161 Link aLink = LINK( this, AreaPropertyPanel, SelectFillTypeHdl );
162 mpLbFillType->SetSelectHdl( aLink );
164 aLink = LINK( this, AreaPropertyPanel, SelectFillAttrHdl );
165 mpLbFillAttr->SetSelectHdl( aLink );
167 //add for new color picker
168 mpLbFillAttr->Hide();
169 const sal_uInt16 nIdColor = mpToolBoxColor->GetItemId(UNO_SIDEBARCOLOR);
170 mpToolBoxColor->SetItemImage(nIdColor, maImgColor);
171 mpToolBoxColor->SetItemBits( nIdColor, mpToolBoxColor->GetItemBits( nIdColor ) | TIB_DROPDOWNONLY );
172 mpToolBoxColor->SetItemText(nIdColor, msHelpFillAttr);
174 aLink = LINK(this, AreaPropertyPanel, ToolBoxColorDropHdl);
175 mpToolBoxColor->SetDropdownClickHdl ( aLink );
176 mpToolBoxColor->SetSelectHdl ( aLink );
178 //add end
179 mpLBTransType->SetSelectHdl(LINK(this, AreaPropertyPanel, ChangeTrgrTypeHdl_Impl));
180 mpLBTransType->SetAccessibleName(OUString( "Transparency")); //wj acc
182 mpMTRTransparent->SetValue( 50 );
183 mpMTRTransparent->SetModifyHdl(LINK(this, AreaPropertyPanel, ModifyTransparentHdl_Impl));
184 mpMTRTransparent->SetAccessibleName(OUString( "Transparency")); //wj acc
186 const sal_uInt16 nIdGradient = mpBTNGradient->GetItemId(UNO_SIDEBARGRADIENT);
187 mpBTNGradient->SetItemBits( nIdGradient, mpBTNGradient->GetItemBits( nIdGradient ) | TIB_DROPDOWNONLY );
188 aLink = LINK( this, AreaPropertyPanel, ClickTrGrHdl_Impl );
189 mpBTNGradient->SetDropdownClickHdl( aLink );
190 mpBTNGradient->SetSelectHdl( aLink );
191 mpBTNGradient->SetItemImage(nIdGradient,maImgLinear);
192 mpBTNGradient->Hide();
194 mpLbFillType->SetAccessibleRelationLabeledBy(mpColorTextFT);
195 mpLbFillAttr->SetAccessibleRelationLabeledBy(mpLbFillAttr);
196 mpToolBoxColor->SetAccessibleRelationLabeledBy(mpToolBoxColor);
197 mpLBTransType->SetAccessibleRelationLabeledBy(mpTrspTextFT);
198 mpMTRTransparent->SetAccessibleRelationLabeledBy(mpMTRTransparent);
199 mpBTNGradient->SetAccessibleRelationLabeledBy(mpBTNGradient);
201 SetupIcons();
206 IMPL_LINK( AreaPropertyPanel, SelectFillTypeHdl, ListBox *, pToolBox )
208 const XFillStyle eXFS = (XFillStyle)mpLbFillType->GetSelectEntryPos();
210 if((XFillStyle)meLastXFS != eXFS)
212 mpLbFillAttr->Clear();
213 SfxObjectShell* pSh = SfxObjectShell::Current();
214 const XFillStyleItem aXFillStyleItem(eXFS);
216 // #i122676# Do no longer trigger two Execute calls, one for SID_ATTR_FILL_STYLE
217 // and one for setting the fill attribute itself, but add two SfxPoolItems to the
218 // call to get just one action at the SdrObject and to create only one Undo action, too.
219 // Checked that this works in all apps.
220 switch( eXFS )
222 case XFILL_NONE:
224 mpLbFillAttr->Show();
225 mpToolBoxColor->Hide();
226 mpLbFillType->Selected();
227 mpLbFillAttr->Disable();
229 // #i122676# need to call a single SID_ATTR_FILL_STYLE change
230 GetBindings()->GetDispatcher()->Execute(
231 SID_ATTR_FILL_STYLE, SFX_CALLMODE_RECORD, &aXFillStyleItem, 0L);
232 break;
234 case XFILL_SOLID:
236 mpLbFillAttr->Hide();
237 mpToolBoxColor->Show();
238 const OUString aTmpStr;
239 const Color aColor = maLastColor;
240 const XFillColorItem aXFillColorItem( aTmpStr, aColor );
242 // #i122676# change FillStyle and Color in one call
243 GetBindings()->GetDispatcher()->Execute(
244 SID_ATTR_FILL_COLOR, SFX_CALLMODE_RECORD, &aXFillColorItem, &aXFillStyleItem, 0L);
245 break;
247 case XFILL_GRADIENT:
249 mpLbFillAttr->Show();
250 mpToolBoxColor->Hide();
252 if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
254 if(!mpLbFillAttr->GetEntryCount())
256 const SvxGradientListItem aItem(*(const SvxGradientListItem*)(pSh->GetItem(SID_GRADIENT_LIST)));
257 mpLbFillAttr->Enable();
258 mpLbFillAttr->Clear();
259 mpLbFillAttr->Fill(aItem.GetGradientList());
262 mpLbFillAttr->AdaptDropDownLineCountToMaximum();
264 if(LISTBOX_ENTRY_NOTFOUND != mnLastPosGradient)
266 const SvxGradientListItem aItem(*(const SvxGradientListItem*)(pSh->GetItem(SID_GRADIENT_LIST)));
268 if(mnLastPosGradient < aItem.GetGradientList()->Count())
270 const XGradient aGradient = aItem.GetGradientList()->GetGradient(mnLastPosGradient)->GetGradient();
271 const XFillGradientItem aXFillGradientItem(mpLbFillAttr->GetEntry(mnLastPosGradient), aGradient);
273 // #i122676# change FillStyle and Gradient in one call
274 GetBindings()->GetDispatcher()->Execute(
275 SID_ATTR_FILL_GRADIENT, SFX_CALLMODE_RECORD, &aXFillGradientItem, &aXFillStyleItem, 0L);
276 mpLbFillAttr->SelectEntryPos(mnLastPosGradient);
280 else
282 mpLbFillAttr->Disable();
284 break;
286 case XFILL_HATCH:
288 mpLbFillAttr->Show();
289 mpToolBoxColor->Hide();
291 if(pSh && pSh->GetItem(SID_HATCH_LIST))
293 if(!mpLbFillAttr->GetEntryCount())
295 const SvxHatchListItem aItem( *(const SvxHatchListItem*)(pSh->GetItem(SID_HATCH_LIST)));
296 mpLbFillAttr->Enable();
297 mpLbFillAttr->Clear();
298 mpLbFillAttr->Fill(aItem.GetHatchList());
301 mpLbFillAttr->AdaptDropDownLineCountToMaximum();
303 if(LISTBOX_ENTRY_NOTFOUND != mnLastPosHatch)
305 const SvxHatchListItem aItem(*(const SvxHatchListItem*)(pSh->GetItem(SID_HATCH_LIST)));
307 if(mnLastPosHatch < aItem.GetHatchList()->Count())
309 const XHatch aHatch = aItem.GetHatchList()->GetHatch(mnLastPosHatch)->GetHatch();
310 const XFillHatchItem aXFillHatchItem(mpLbFillAttr->GetSelectEntry(), aHatch);
312 // #i122676# change FillStyle and Hatch in one call
313 GetBindings()->GetDispatcher()->Execute(
314 SID_ATTR_FILL_HATCH, SFX_CALLMODE_RECORD, &aXFillHatchItem, &aXFillStyleItem, 0L);
315 mpLbFillAttr->SelectEntryPos(mnLastPosHatch);
319 else
321 mpLbFillAttr->Disable();
323 break;
325 case XFILL_BITMAP:
327 mpLbFillAttr->Show();
328 mpToolBoxColor->Hide();
330 if(pSh && pSh->GetItem(SID_BITMAP_LIST))
332 if(!mpLbFillAttr->GetEntryCount())
334 const SvxBitmapListItem aItem( *(const SvxBitmapListItem*)(pSh->GetItem(SID_BITMAP_LIST)));
335 mpLbFillAttr->Enable();
336 mpLbFillAttr->Clear();
337 mpLbFillAttr->Fill(aItem.GetBitmapList());
340 mpLbFillAttr->AdaptDropDownLineCountToMaximum();
342 if(LISTBOX_ENTRY_NOTFOUND != mnLastPosBitmap)
344 const SvxBitmapListItem aItem(*(const SvxBitmapListItem*)(pSh->GetItem(SID_BITMAP_LIST)));
346 if(mnLastPosBitmap < aItem.GetBitmapList()->Count())
348 const XBitmapEntry* pXBitmapEntry = aItem.GetBitmapList()->GetBitmap(mnLastPosBitmap);
349 const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->GetSelectEntry(), pXBitmapEntry->GetGraphicObject());
351 // #i122676# change FillStyle and Bitmap in one call
352 GetBindings()->GetDispatcher()->Execute(
353 SID_ATTR_FILL_BITMAP, SFX_CALLMODE_RECORD, &aXFillBitmapItem, &aXFillStyleItem, 0L);
354 mpLbFillAttr->SelectEntryPos(mnLastPosBitmap);
358 else
360 mpLbFillAttr->Disable();
362 break;
366 meLastXFS = (sal_uInt16)eXFS;
368 if(XFILL_NONE != eXFS)
370 if(pToolBox)
372 mpLbFillType->Selected();
377 return 0;
382 IMPL_LINK( AreaPropertyPanel, SelectFillAttrHdl, ListBox*, pToolBox )
384 const XFillStyle eXFS = (XFillStyle)mpLbFillType->GetSelectEntryPos();
385 const XFillStyleItem aXFillStyleItem(eXFS);
386 SfxObjectShell* pSh = SfxObjectShell::Current();
388 if(pToolBox)
390 // #i122676# dependent from bFillStyleChange, do execute a single or two
391 // changes in one Execute call
392 const bool bFillStyleChange((XFillStyle) meLastXFS != eXFS);
394 switch(eXFS)
396 case XFILL_SOLID:
398 if(bFillStyleChange)
400 // #i122676# Single FillStyle change call needed here
401 GetBindings()->GetDispatcher()->Execute(SID_ATTR_FILL_STYLE, SFX_CALLMODE_RECORD, &aXFillStyleItem, 0L);
403 break;
405 case XFILL_GRADIENT:
407 sal_Int32 nPos = mpLbFillAttr->GetSelectEntryPos();
409 if(LISTBOX_ENTRY_NOTFOUND == nPos)
411 nPos = mnLastPosGradient;
414 if(LISTBOX_ENTRY_NOTFOUND != nPos && pSh && pSh->GetItem(SID_GRADIENT_LIST))
416 const SvxGradientListItem aItem(*(const SvxGradientListItem*)(pSh->GetItem(SID_GRADIENT_LIST)));
418 if(nPos < aItem.GetGradientList()->Count())
420 const XGradient aGradient = aItem.GetGradientList()->GetGradient(nPos)->GetGradient();
421 const XFillGradientItem aXFillGradientItem(mpLbFillAttr->GetSelectEntry(), aGradient);
423 // #i122676# Change FillStale and Gradinet in one call
424 GetBindings()->GetDispatcher()->Execute(
425 SID_ATTR_FILL_GRADIENT, SFX_CALLMODE_RECORD, &aXFillGradientItem,
426 bFillStyleChange ? &aXFillStyleItem : 0L, 0L);
430 if(LISTBOX_ENTRY_NOTFOUND != nPos)
432 mnLastPosGradient = nPos;
434 break;
436 case XFILL_HATCH:
438 sal_Int32 nPos = mpLbFillAttr->GetSelectEntryPos();
440 if(LISTBOX_ENTRY_NOTFOUND == nPos)
442 nPos = mnLastPosHatch;
445 if(LISTBOX_ENTRY_NOTFOUND != nPos && pSh && pSh->GetItem(SID_HATCH_LIST))
447 const SvxHatchListItem aItem(*(const SvxHatchListItem*)(pSh->GetItem(SID_HATCH_LIST)));
449 if(nPos < aItem.GetHatchList()->Count())
451 const XHatch aHatch = aItem.GetHatchList()->GetHatch(nPos)->GetHatch();
452 const XFillHatchItem aXFillHatchItem( mpLbFillAttr->GetSelectEntry(), aHatch);
454 // #i122676# Change FillStale and Hatch in one call
455 GetBindings()->GetDispatcher()->Execute(
456 SID_ATTR_FILL_HATCH, SFX_CALLMODE_RECORD, &aXFillHatchItem,
457 bFillStyleChange ? &aXFillStyleItem : 0L, 0L);
461 if(LISTBOX_ENTRY_NOTFOUND != nPos)
463 mnLastPosHatch = nPos;
465 break;
467 case XFILL_BITMAP:
469 sal_Int32 nPos = mpLbFillAttr->GetSelectEntryPos();
471 if(LISTBOX_ENTRY_NOTFOUND == nPos)
473 nPos = mnLastPosBitmap;
476 if(LISTBOX_ENTRY_NOTFOUND != nPos && pSh && pSh->GetItem(SID_BITMAP_LIST))
478 const SvxBitmapListItem aItem(*(const SvxBitmapListItem*)(pSh->GetItem(SID_BITMAP_LIST)));
480 if(nPos < aItem.GetBitmapList()->Count())
482 const XBitmapEntry* pXBitmapEntry = aItem.GetBitmapList()->GetBitmap(nPos);
483 const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->GetSelectEntry(), pXBitmapEntry->GetGraphicObject());
485 // #i122676# Change FillStale and Bitmap in one call
486 GetBindings()->GetDispatcher()->Execute(
487 SID_ATTR_FILL_BITMAP, SFX_CALLMODE_RECORD, &aXFillBitmapItem,
488 bFillStyleChange ? &aXFillStyleItem : 0L, 0L);
492 if(LISTBOX_ENTRY_NOTFOUND != nPos)
494 mnLastPosBitmap = nPos;
496 break;
498 default: break;
502 return 0;
506 IMPL_LINK(AreaPropertyPanel, ToolBoxColorDropHdl, ToolBox*, pToolBox)
508 const OUString aCommand(pToolBox->GetItemCommand(pToolBox->GetCurItemId()));
510 if(UNO_SIDEBARCOLOR == aCommand)
512 maColorPopup.Show(*pToolBox);
514 if (mpColorItem)
516 maColorPopup.SetCurrentColor(mpColorItem->GetColorValue(), mbColorAvail);
518 else
520 maColorPopup.SetCurrentColor(COL_WHITE, false);
524 return 0;
529 void AreaPropertyPanel::SetColor (
530 const OUString& rsColorName,
531 const Color aColor)
533 const XFillColorItem aXFillColorItem(rsColorName, aColor);
534 mpBindings->GetDispatcher()->Execute(SID_ATTR_FILL_COLOR, SFX_CALLMODE_RECORD, &aXFillColorItem, 0L);
535 maLastColor = aColor;
541 PopupControl* AreaPropertyPanel::CreateTransparencyGradientControl (PopupContainer* pParent)
543 return new AreaTransparencyGradientControl(pParent, *this);
549 PopupControl* AreaPropertyPanel::CreateColorPopupControl (PopupContainer* pParent)
551 return new ColorControl(
552 pParent,
553 mpBindings,
554 SVX_RES(RID_POPUPPANEL_AERAPAGE_COLOR),
555 SVX_RES(VS_COLOR),
556 ::boost::bind(&AreaPropertyPanel::GetLastColor, this),
557 ::boost::bind(&AreaPropertyPanel::SetColor, this, _1,_2),
558 pParent,
565 void AreaPropertyPanel::SetupIcons(void)
567 if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
569 // todo
571 else
573 // todo
579 AreaPropertyPanel* AreaPropertyPanel::Create (
580 Window* pParent,
581 const cssu::Reference<css::frame::XFrame>& rxFrame,
582 SfxBindings* pBindings)
584 if (pParent == NULL)
585 throw lang::IllegalArgumentException("no parent Window given to AreaPropertyPanel::Create", NULL, 0);
586 if ( ! rxFrame.is())
587 throw lang::IllegalArgumentException("no XFrame given to AreaPropertyPanel::Create", NULL, 1);
588 if (pBindings == NULL)
589 throw lang::IllegalArgumentException("no SfxBindings given to AreaPropertyPanel::Create", NULL, 2);
591 return new AreaPropertyPanel(
592 pParent,
593 rxFrame,
594 pBindings);
599 void AreaPropertyPanel::DataChanged(
600 const DataChangedEvent& rEvent)
602 (void)rEvent;
604 SetupIcons();
609 void AreaPropertyPanel::ImpUpdateTransparencies()
611 if(mpTransparanceItem.get() && mpFloatTransparenceItem.get())
613 bool bZeroValue(false);
615 if(mpTransparanceItem.get())
617 const sal_uInt16 nValue(mpTransparanceItem->GetValue());
619 if(!nValue)
621 bZeroValue = true;
623 else if(nValue <= 100)
625 mpLBTransType->Enable();
626 mpTrspTextFT->Enable();
627 mpLBTransType->SelectEntryPos(1);
628 mpBTNGradient->Hide();
629 mpMTRTransparent->Show();
630 mpMTRTransparent->Enable();
631 mpMTRTransparent->SetValue(nValue);
634 if(!bZeroValue)
636 maTrGrPopup.Hide();
640 if(bZeroValue && mpFloatTransparenceItem.get())
642 if(mpFloatTransparenceItem->IsEnabled())
644 const XGradient& rGradient = mpFloatTransparenceItem->GetGradientValue();
645 sal_Int32 nEntryPos(0);
646 Image* pImage = 0;
648 mpLBTransType->Enable();
649 mpTrspTextFT->Enable();
650 mpMTRTransparent->Hide();
651 mpBTNGradient->Enable();
652 mpBTNGradient->Show();
654 switch(rGradient.GetGradientStyle())
656 case XGRAD_LINEAR:
658 nEntryPos = 2;
659 pImage = &maImgLinear;
660 break;
662 case XGRAD_AXIAL:
664 nEntryPos = 3;
665 pImage = &maImgAxial;
666 break;
668 case XGRAD_RADIAL:
670 nEntryPos = 4;
671 pImage = &maImgRadial;
672 break;
674 case XGRAD_ELLIPTICAL:
676 nEntryPos = 5;
677 pImage = &maImgElli;
678 break;
680 case XGRAD_SQUARE:
682 nEntryPos = 6;
683 pImage = &maImgQuad;
684 break;
686 case XGRAD_RECT:
688 nEntryPos = 7;
689 pImage = &maImgSquare;
690 break;
694 const sal_uInt16 nIdGradient = mpBTNGradient->GetItemId(UNO_SIDEBARGRADIENT);
695 mpLBTransType->SelectEntryPos(nEntryPos);
696 mpBTNGradient->SetItemImage(nIdGradient, *pImage);
697 bZeroValue = false;
699 else
701 bZeroValue = true;
705 if(bZeroValue)
707 mpLBTransType->Enable();
708 mpTrspTextFT->Enable();
709 mpLBTransType->SelectEntryPos(0);
710 mpBTNGradient->Hide();
711 mpMTRTransparent->Enable();
712 mpMTRTransparent->Show();
713 mpMTRTransparent->SetValue(0);
716 else
718 // no transparency at all
719 mpLBTransType->SetNoSelection();
720 mpLBTransType->Disable();
721 mpTrspTextFT->Disable();
722 mpMTRTransparent->Disable();
723 mpMTRTransparent->Show();
724 mpBTNGradient->Disable();
725 mpBTNGradient->Hide();
731 void AreaPropertyPanel::NotifyItemUpdate(
732 sal_uInt16 nSID,
733 SfxItemState eState,
734 const SfxPoolItem* pState,
735 const bool bIsEnabled)
737 (void)bIsEnabled;
738 const bool bDisabled(SFX_ITEM_DISABLED == eState);
740 switch(nSID)
742 case SID_ATTR_FILL_TRANSPARENCE:
743 case SID_ATTR_FILL_FLOATTRANSPARENCE:
745 bool bFillTransparenceChanged(false);
747 if(SID_ATTR_FILL_TRANSPARENCE == nSID)
749 bFillTransparenceChanged = true;
751 if(eState >= SFX_ITEM_AVAILABLE)
753 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
755 if(pItem && (!mpTransparanceItem || *pItem != *mpTransparanceItem))
757 mpTransparanceItem.reset((SfxUInt16Item*)pItem->Clone());
759 else
761 mpTransparanceItem.reset();
764 else
766 mpTransparanceItem.reset();
769 else // if(SID_ATTR_FILL_FLOATTRANSPARENCE == nSID)
771 bFillTransparenceChanged = true;
773 if(eState >= SFX_ITEM_AVAILABLE)
775 const XFillFloatTransparenceItem* pItem = dynamic_cast< const XFillFloatTransparenceItem* >(pState);
777 if(pItem && (!mpFloatTransparenceItem || *pItem != *mpFloatTransparenceItem))
779 mpFloatTransparenceItem.reset((XFillFloatTransparenceItem*)pItem->Clone());
781 else
783 mpFloatTransparenceItem.reset();
786 else
788 mpFloatTransparenceItem.reset();
792 if(bFillTransparenceChanged)
794 // update transparency settings dependent of mpTransparanceItem and mpFloatTransparenceItem
795 ImpUpdateTransparencies();
797 break;
799 case SID_ATTR_FILL_STYLE:
801 if(bDisabled)
803 mpLbFillType->Disable();
804 mpColorTextFT->Disable();
805 mpLbFillType->SetNoSelection();
806 mpLbFillAttr->Show();
807 mpLbFillAttr->Disable();
808 mpLbFillAttr->SetNoSelection();
809 mpToolBoxColor->Hide();
810 meLastXFS = -1;
811 mpStyleItem.reset();
814 if(eState >= SFX_ITEM_AVAILABLE)
816 const XFillStyleItem* pItem = dynamic_cast< const XFillStyleItem* >(pState);
818 if(pItem)
820 mpStyleItem.reset(dynamic_cast< XFillStyleItem* >(pItem->Clone()));
821 mpLbFillType->Enable();
822 mpColorTextFT->Enable();
823 XFillStyle eXFS = (XFillStyle)mpStyleItem->GetValue();
824 meLastXFS = eXFS;
825 mpLbFillType->SelectEntryPos(sal::static_int_cast< sal_Int32 >(eXFS));
827 if(XFILL_NONE == eXFS)
829 mpLbFillAttr->SetNoSelection();
830 mpLbFillAttr->Disable();
833 Update();
834 break;
838 mpLbFillType->SetNoSelection();
839 mpLbFillAttr->Show();
840 mpLbFillAttr->Disable();
841 mpLbFillAttr->SetNoSelection();
842 mpToolBoxColor->Hide();
843 meLastXFS = -1;
844 mpStyleItem.reset();
845 break;
847 case SID_ATTR_FILL_COLOR:
849 if(SFX_ITEM_AVAILABLE == eState)
851 mpColorItem.reset(pState ? (XFillColorItem*)pState->Clone() : 0);
854 if(mpStyleItem && XFILL_SOLID == (XFillStyle)mpStyleItem->GetValue())
856 mpLbFillAttr->Hide();
857 mpToolBoxColor->Show();
859 if(SFX_ITEM_AVAILABLE == eState)
861 mpToolBoxColor->Enable();
862 mbColorAvail = true;
863 // maLastColor = mpColorItem->GetColorValue();
864 Update();
866 else if(SFX_ITEM_DISABLED == eState)
868 mpToolBoxColor->Disable();
869 mbColorAvail = false;
870 mpColorUpdater->Update(COL_WHITE);
872 else
874 mbColorAvail = false;
875 mpColorUpdater->Update(COL_WHITE);
878 break;
880 case SID_ATTR_FILL_GRADIENT:
882 if(SFX_ITEM_AVAILABLE == eState)
884 mpFillGradientItem.reset(pState ? (XFillGradientItem*)pState->Clone() : 0);
887 if(mpStyleItem && XFILL_GRADIENT == (XFillStyle)mpStyleItem->GetValue())
889 mpLbFillAttr->Show();
890 mpToolBoxColor->Hide();
892 if(SFX_ITEM_AVAILABLE == eState)
894 mpLbFillAttr->Enable();
895 Update();
897 else if(SFX_ITEM_DISABLED == eState )
899 mpLbFillAttr->Disable();
900 mpLbFillAttr->SetNoSelection();
902 else
904 mpLbFillAttr->SetNoSelection();
907 break;
909 case SID_ATTR_FILL_HATCH:
911 if(SFX_ITEM_AVAILABLE == eState)
913 mpHatchItem.reset(pState ? (XFillHatchItem*)pState->Clone() : 0);
916 if(mpStyleItem && XFILL_HATCH == (XFillStyle)mpStyleItem->GetValue())
918 mpLbFillAttr->Show();
919 mpToolBoxColor->Hide();
921 if(SFX_ITEM_AVAILABLE == eState)
923 mpLbFillAttr->Enable();
924 Update();
926 else if(SFX_ITEM_DISABLED == eState )
928 mpLbFillAttr->Disable();
929 mpLbFillAttr->SetNoSelection();
931 else
933 mpLbFillAttr->SetNoSelection();
936 break;
938 case SID_ATTR_FILL_BITMAP:
940 if(SFX_ITEM_AVAILABLE == eState)
942 mpBitmapItem.reset(pState ? (XFillBitmapItem*)pState->Clone() : 0);
945 if(mpStyleItem && XFILL_BITMAP == (XFillStyle)mpStyleItem->GetValue())
947 mpLbFillAttr->Show();
948 mpToolBoxColor->Hide();
950 if(SFX_ITEM_AVAILABLE == eState)
952 mpLbFillAttr->Enable();
953 Update();
955 else if(SFX_ITEM_DISABLED == eState )
957 mpLbFillAttr->Disable();
958 mpLbFillAttr->SetNoSelection();
960 else
962 mpLbFillAttr->SetNoSelection();
965 break;
967 case SID_COLOR_TABLE:
969 if(SFX_ITEM_AVAILABLE == eState)
971 if(mpStyleItem && XFILL_SOLID == (XFillStyle)mpStyleItem->GetValue())
973 if(mpColorItem)
975 const Color aColor = mpColorItem->GetColorValue();
976 const SfxObjectShell* pSh = SfxObjectShell::Current();
977 const SvxColorListItem aItem(*(const SvxColorListItem*)(pSh->GetItem(SID_COLOR_TABLE)));
979 mpLbFillAttr->Clear();
980 mpLbFillAttr->Enable();
981 mpLbFillAttr->Fill(aItem.GetColorList());
982 mpLbFillAttr->SelectEntry(aColor);
984 else
986 mpLbFillAttr->SetNoSelection();
990 break;
992 case SID_GRADIENT_LIST:
994 if(SFX_ITEM_AVAILABLE == eState)
996 if(mpStyleItem && XFILL_GRADIENT == (XFillStyle)mpStyleItem->GetValue())
998 if(mpFillGradientItem)
1000 const OUString aString( mpFillGradientItem->GetName() );
1001 const SfxObjectShell* pSh = SfxObjectShell::Current();
1002 const SvxGradientListItem aItem( *(const SvxGradientListItem*)(pSh->GetItem(SID_GRADIENT_LIST)));
1004 mpLbFillAttr->Clear();
1005 mpLbFillAttr->Enable();
1006 mpLbFillAttr->Fill(aItem.GetGradientList());
1007 mpLbFillAttr->SelectEntry(aString);
1009 else
1011 mpLbFillAttr->SetNoSelection();
1015 break;
1017 case SID_HATCH_LIST:
1019 if(SFX_ITEM_AVAILABLE == eState)
1021 if(mpStyleItem && XFILL_HATCH == (XFillStyle)mpStyleItem->GetValue())
1023 if(mpHatchItem)
1025 const OUString aString( mpHatchItem->GetName() );
1026 const SfxObjectShell* pSh = SfxObjectShell::Current();
1027 const SvxHatchListItem aItem(*(const SvxHatchListItem*)(pSh->GetItem(SID_HATCH_LIST)));
1029 mpLbFillAttr->Clear();
1030 mpLbFillAttr->Enable();
1031 mpLbFillAttr->Fill(aItem.GetHatchList());
1032 mpLbFillAttr->SelectEntry(aString);
1034 else
1036 mpLbFillAttr->SetNoSelection();
1040 break;
1042 case SID_BITMAP_LIST:
1044 if(SFX_ITEM_AVAILABLE == eState)
1046 if(mpStyleItem && XFILL_BITMAP == (XFillStyle)mpStyleItem->GetValue())
1048 if(mpBitmapItem)
1050 const OUString aString( mpBitmapItem->GetName() );
1051 const SfxObjectShell* pSh = SfxObjectShell::Current();
1052 const SvxBitmapListItem aItem(*(const SvxBitmapListItem*)(pSh->GetItem(SID_BITMAP_LIST)));
1054 mpLbFillAttr->Clear();
1055 mpLbFillAttr->Enable();
1056 mpLbFillAttr->Fill(aItem.GetBitmapList());
1057 mpLbFillAttr->SelectEntry(aString);
1059 else
1061 mpLbFillAttr->SetNoSelection();
1065 break;
1072 SfxBindings* AreaPropertyPanel::GetBindings()
1074 return mpBindings;
1079 void AreaPropertyPanel::Update()
1081 if(mpStyleItem)
1083 const XFillStyle eXFS = (XFillStyle)mpStyleItem->GetValue();
1084 SfxObjectShell* pSh = SfxObjectShell::Current();
1086 switch( eXFS )
1088 case XFILL_NONE:
1090 mpLbFillAttr->Show();
1091 mpToolBoxColor->Hide();
1092 break;
1094 case XFILL_SOLID:
1096 if(mpColorItem)
1098 mpLbFillAttr->Hide();
1099 mpToolBoxColor->Show();
1100 mpColorUpdater->Update(mpColorItem->GetColorValue());
1102 else
1104 mpColorUpdater->Update(COL_WHITE);
1106 break;
1108 case XFILL_GRADIENT:
1110 mpLbFillAttr->Show();
1111 mpToolBoxColor->Hide();
1113 if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
1115 const SvxGradientListItem aItem(*(const SvxGradientListItem*)(pSh->GetItem(SID_GRADIENT_LIST)));
1116 mpLbFillAttr->Enable();
1117 mpLbFillAttr->Clear();
1118 mpLbFillAttr->Fill(aItem.GetGradientList());
1120 if(mpFillGradientItem)
1122 const OUString aString(mpFillGradientItem->GetName());
1124 mpLbFillAttr->SelectEntry(aString);
1126 else
1128 mpLbFillAttr->SetNoSelection();
1131 else
1133 mpLbFillAttr->SetNoSelection();
1135 break;
1137 case XFILL_HATCH:
1139 mpLbFillAttr->Show();
1140 mpToolBoxColor->Hide();
1142 if(pSh && pSh->GetItem(SID_HATCH_LIST))
1144 const SvxHatchListItem aItem(*(const SvxHatchListItem*)(pSh->GetItem(SID_HATCH_LIST)));
1145 mpLbFillAttr->Enable();
1146 mpLbFillAttr->Clear();
1147 mpLbFillAttr->Fill(aItem.GetHatchList());
1149 if(mpHatchItem)
1151 const OUString aString(mpHatchItem->GetName());
1153 mpLbFillAttr->SelectEntry( aString );
1155 else
1157 mpLbFillAttr->SetNoSelection();
1160 else
1162 mpLbFillAttr->SetNoSelection();
1164 break;
1166 case XFILL_BITMAP:
1168 mpLbFillAttr->Show();
1169 mpToolBoxColor->Hide();
1171 if(pSh && pSh->GetItem(SID_BITMAP_LIST))
1173 const SvxBitmapListItem aItem(*(const SvxBitmapListItem*)(pSh->GetItem(SID_BITMAP_LIST)));
1174 mpLbFillAttr->Enable();
1175 mpLbFillAttr->Clear();
1176 mpLbFillAttr->Fill(aItem.GetBitmapList());
1178 if(mpBitmapItem)
1180 const OUString aString(mpBitmapItem->GetName());
1182 mpLbFillAttr->SelectEntry(aString);
1184 else
1186 mpLbFillAttr->SetNoSelection();
1189 else
1191 mpLbFillAttr->SetNoSelection();
1193 break;
1195 default:
1196 OSL_ENSURE(false, "Non supported FillType (!)");
1197 break;
1204 IMPL_LINK( AreaPropertyPanel, ClickTrGrHdl_Impl, ToolBox*, pToolBox )
1206 maTrGrPopup.Rearrange(mpFloatTransparenceItem.get());
1207 OSL_ASSERT( pToolBox->GetItemCommand(pToolBox->GetCurItemId()) == UNO_SIDEBARGRADIENT);
1208 maTrGrPopup.Show(*pToolBox);
1210 return (0L);
1215 IMPL_LINK(AreaPropertyPanel, ChangeTrgrTypeHdl_Impl, void *, EMPTYARG)
1217 sal_Int32 nSelectType = mpLBTransType->GetSelectEntryPos();
1218 bool bGradient = false;
1219 sal_uInt16 nTrans = 0;
1221 if(!nSelectType)
1223 mpBTNGradient->Hide();
1224 mpMTRTransparent->Show();
1225 mpMTRTransparent->Enable();
1226 mpMTRTransparent->SetValue(0);
1228 else if(1 == nSelectType)
1230 mpBTNGradient->Hide();
1231 mpMTRTransparent->Show();
1232 nTrans = mnLastTransSolid;
1233 mpMTRTransparent->SetValue(nTrans);
1234 mpLBTransType->SelectEntryPos(1);
1235 mpMTRTransparent->Enable();
1237 else
1239 mpBTNGradient->Show();
1241 const sal_uInt16 nIdGradient = mpBTNGradient->GetItemId(UNO_SIDEBARGRADIENT);
1242 switch (nSelectType)
1244 case 2:
1245 mpBTNGradient->SetItemImage(nIdGradient, maImgLinear);
1246 break;
1247 case 3:
1248 mpBTNGradient->SetItemImage(nIdGradient, maImgAxial);
1249 break;
1250 case 4:
1251 mpBTNGradient->SetItemImage(nIdGradient, maImgRadial);
1252 break;
1253 case 5:
1254 mpBTNGradient->SetItemImage(nIdGradient, maImgElli );
1255 break;
1256 case 6:
1257 mpBTNGradient->SetItemImage(nIdGradient, maImgQuad );
1258 break;
1259 case 7:
1260 mpBTNGradient->SetItemImage(nIdGradient, maImgSquare);
1261 break;
1264 mpMTRTransparent->Hide();
1265 mpBTNGradient->Enable();
1266 bGradient = true;
1269 const XFillTransparenceItem aLinearItem(nTrans);
1270 GetBindings()->GetDispatcher()->Execute( SID_ATTR_FILL_TRANSPARENCE, SFX_CALLMODE_RECORD, &aLinearItem, 0L );
1272 if(nSelectType > 1)
1274 nSelectType -= 2;
1277 XGradient aTmpGradient;
1279 switch(nSelectType)
1281 case XGRAD_LINEAR:
1282 aTmpGradient = maGradientLinear;
1283 break;
1284 case XGRAD_AXIAL:
1285 aTmpGradient = maGradientAxial;
1286 break;
1287 case XGRAD_RADIAL:
1288 aTmpGradient = maGradientRadial;
1289 break;
1290 case XGRAD_ELLIPTICAL:
1291 aTmpGradient = maGradientElliptical;
1292 break;
1293 case XGRAD_SQUARE:
1294 aTmpGradient = maGradientSquare;
1295 break;
1296 case XGRAD_RECT:
1297 aTmpGradient = maGradientRect;
1298 break;
1301 SfxItemPool* pPool = 0;
1302 const XFillFloatTransparenceItem aGradientItem(pPool, aTmpGradient, bGradient);
1303 GetBindings()->GetDispatcher()->Execute( SID_ATTR_FILL_FLOATTRANSPARENCE, SFX_CALLMODE_RECORD, &aGradientItem, 0L );
1305 return( 0L );
1310 IMPL_LINK(AreaPropertyPanel, ModifyTransparentHdl_Impl, void*, EMPTYARG)
1312 const sal_uInt16 nTrans = (sal_uInt16)mpMTRTransparent->GetValue();
1313 mnLastTransSolid = nTrans;
1314 const sal_Int32 nSelectType = mpLBTransType->GetSelectEntryPos();
1316 if(nTrans && !nSelectType)
1318 mpLBTransType->SelectEntryPos(1);
1321 const XFillTransparenceItem aLinearItem(nTrans);
1322 GetBindings()->GetDispatcher()->Execute( SID_ATTR_FILL_TRANSPARENCE, SFX_CALLMODE_RECORD, &aLinearItem, 0L );
1324 return 0L;
1328 Color AreaPropertyPanel::GetLastColor (void) const
1330 return maLastColor;
1336 XGradient AreaPropertyPanel::GetGradient (const XGradientStyle eStyle) const
1338 switch (eStyle)
1340 default:
1341 case XGRAD_LINEAR:
1342 return maGradientLinear;
1343 case XGRAD_AXIAL:
1344 return maGradientAxial;
1345 case XGRAD_RADIAL:
1346 return maGradientRadial;
1347 case XGRAD_ELLIPTICAL:
1348 return maGradientElliptical;
1349 case XGRAD_SQUARE:
1350 return maGradientSquare;
1351 case XGRAD_RECT:
1352 return maGradientRect;
1359 void AreaPropertyPanel::SetGradient (const XGradient& rGradient)
1361 switch (rGradient.GetGradientStyle())
1363 case XGRAD_LINEAR:
1364 maGradientLinear = rGradient;
1365 break;
1366 case XGRAD_AXIAL:
1367 maGradientAxial = rGradient;
1368 break;
1369 case XGRAD_RADIAL:
1370 maGradientRadial = rGradient;
1371 break;
1372 case XGRAD_ELLIPTICAL:
1373 maGradientElliptical = rGradient;
1374 break;
1375 case XGRAD_SQUARE:
1376 maGradientSquare = rGradient;
1377 break;
1378 case XGRAD_RECT:
1379 maGradientRect = rGradient;
1380 break;
1387 sal_Int32 AreaPropertyPanel::GetSelectedTransparencyTypeIndex (void) const
1389 return mpLBTransType->GetSelectEntryPos();
1392 } } // end of namespace svx::sidebar
1394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */