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 .
21 #include <sfx2/app.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/viewsh.hxx>
25 #include <sfx2/sidebar/SidebarToolBox.hxx>
26 #include <rtl/ustring.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/toolbox.hxx>
29 #include <svx/strings.hrc>
30 #include <svx/svxids.hrc>
32 #define TMP_STR_BEGIN "["
33 #define TMP_STR_END "]"
35 #include <svx/drawitem.hxx>
36 #include <svx/xattr.hxx>
37 #include <svx/xtable.hxx>
38 #include <svx/fillctrl.hxx>
39 #include <svx/itemwin.hxx>
40 #include <svx/dialmgr.hxx>
43 #include <o3tl/make_unique.hxx>
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::util
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::lang
;
52 SFX_IMPL_TOOLBOX_CONTROL( SvxFillToolBoxControl
, XFillStyleItem
);
54 SvxFillToolBoxControl::SvxFillToolBoxControl(
58 : SfxToolBoxControl( nSlotId
, nId
, rTbx
)
61 , mpFillGradientItem()
64 , mpFillControl(nullptr)
65 , mpLbFillType(nullptr)
66 , mpLbFillAttr(nullptr)
67 , meLastXFS(static_cast<drawing::FillStyle
>(-1))
68 , mnLastPosGradient(0)
72 addStatusListener( ".uno:FillColor");
73 addStatusListener( ".uno:FillGradient");
74 addStatusListener( ".uno:FillHatch");
75 addStatusListener( ".uno:FillBitmap");
76 addStatusListener( ".uno:ColorTableState");
77 addStatusListener( ".uno:GradientListState");
78 addStatusListener( ".uno:HatchListState");
79 addStatusListener( ".uno:BitmapListState");
82 SvxFillToolBoxControl::~SvxFillToolBoxControl()
86 void SvxFillToolBoxControl::StateChanged(
89 const SfxPoolItem
* pState
)
91 const bool bDisabled(SfxItemState::DISABLED
== eState
);
95 case SID_ATTR_FILL_STYLE
:
99 mpLbFillType
->Disable();
100 mpLbFillType
->SetNoSelection();
101 mpLbFillAttr
->Show();
102 mpLbFillAttr
->Disable();
103 mpLbFillAttr
->SetNoSelection();
104 mpToolBoxColor
->Hide();
105 meLastXFS
= static_cast<drawing::FillStyle
>(-1);
109 if(eState
>= SfxItemState::DEFAULT
)
111 const XFillStyleItem
* pItem
= dynamic_cast< const XFillStyleItem
* >(pState
);
115 mpStyleItem
.reset(dynamic_cast< XFillStyleItem
* >(pItem
->Clone()));
116 mpLbFillType
->Enable();
117 drawing::FillStyle eXFS
= (drawing::FillStyle
)mpStyleItem
->GetValue();
119 mpLbFillType
->SelectEntryPos(sal::static_int_cast
< sal_Int32
>(eXFS
));
121 if(drawing::FillStyle_NONE
== eXFS
)
123 mpLbFillAttr
->SetNoSelection();
124 mpLbFillAttr
->Disable();
132 mpLbFillType
->SetNoSelection();
133 mpLbFillAttr
->Show();
134 mpLbFillAttr
->Disable();
135 mpLbFillAttr
->SetNoSelection();
136 mpToolBoxColor
->Hide();
137 meLastXFS
= static_cast<drawing::FillStyle
>(-1);
141 case SID_ATTR_FILL_COLOR
:
143 if(SfxItemState::DEFAULT
== eState
)
145 mpColorItem
.reset(pState
? static_cast<XFillColorItem
*>(pState
->Clone()) : nullptr);
148 if(mpStyleItem
&& drawing::FillStyle_SOLID
== (drawing::FillStyle
)mpStyleItem
->GetValue())
150 mpLbFillAttr
->Hide();
151 mpToolBoxColor
->Show();
157 case SID_ATTR_FILL_GRADIENT
:
159 if(SfxItemState::DEFAULT
== eState
)
161 mpFillGradientItem
.reset(pState
? static_cast<XFillGradientItem
*>(pState
->Clone()) : nullptr);
164 if(mpStyleItem
&& drawing::FillStyle_GRADIENT
== (drawing::FillStyle
)mpStyleItem
->GetValue())
166 mpLbFillAttr
->Show();
167 mpToolBoxColor
->Hide();
169 if(SfxItemState::DEFAULT
== eState
)
171 mpLbFillAttr
->Enable();
174 else if(SfxItemState::DISABLED
== eState
)
176 mpLbFillAttr
->Disable();
177 mpLbFillAttr
->SetNoSelection();
181 mpLbFillAttr
->SetNoSelection();
186 case SID_ATTR_FILL_HATCH
:
188 if(SfxItemState::DEFAULT
== eState
)
190 mpHatchItem
.reset(pState
? static_cast<XFillHatchItem
*>(pState
->Clone()) : nullptr);
193 if(mpStyleItem
&& drawing::FillStyle_HATCH
== (drawing::FillStyle
)mpStyleItem
->GetValue())
195 mpLbFillAttr
->Show();
196 mpToolBoxColor
->Hide();
198 if(SfxItemState::DEFAULT
== eState
)
200 mpLbFillAttr
->Enable();
203 else if(SfxItemState::DISABLED
== eState
)
205 mpLbFillAttr
->Disable();
206 mpLbFillAttr
->SetNoSelection();
210 mpLbFillAttr
->SetNoSelection();
215 case SID_ATTR_FILL_BITMAP
:
217 if(SfxItemState::DEFAULT
== eState
)
219 mpBitmapItem
.reset(pState
? static_cast<XFillBitmapItem
*>(pState
->Clone()) : nullptr);
222 if(mpStyleItem
&& drawing::FillStyle_BITMAP
== (drawing::FillStyle
)mpStyleItem
->GetValue())
224 mpLbFillAttr
->Show();
225 mpToolBoxColor
->Hide();
227 if(SfxItemState::DEFAULT
== eState
)
229 mpLbFillAttr
->Enable();
232 else if(SfxItemState::DISABLED
== eState
)
234 mpLbFillAttr
->Disable();
235 mpLbFillAttr
->SetNoSelection();
239 mpLbFillAttr
->SetNoSelection();
244 case SID_GRADIENT_LIST
:
246 if(SfxItemState::DEFAULT
== eState
)
248 if(mpStyleItem
&& drawing::FillStyle_GRADIENT
== (drawing::FillStyle
)mpStyleItem
->GetValue())
250 if(mpFillGradientItem
)
252 const OUString
aString( mpFillGradientItem
->GetName() );
253 const SfxObjectShell
* pSh
= SfxObjectShell::Current();
254 const SvxGradientListItem
aItem( *static_cast<const SvxGradientListItem
*>(pSh
->GetItem(SID_GRADIENT_LIST
)));
256 mpLbFillAttr
->Clear();
257 mpLbFillAttr
->Enable();
258 mpLbFillAttr
->Fill(aItem
.GetGradientList());
259 mpLbFillAttr
->SelectEntry(aString
);
263 mpLbFillAttr
->SetNoSelection();
271 if(SfxItemState::DEFAULT
== eState
)
273 if(mpStyleItem
&& drawing::FillStyle_HATCH
== (drawing::FillStyle
)mpStyleItem
->GetValue())
277 const OUString
aString( mpHatchItem
->GetName() );
278 const SfxObjectShell
* pSh
= SfxObjectShell::Current();
279 const SvxHatchListItem
aItem(*static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
281 mpLbFillAttr
->Clear();
282 mpLbFillAttr
->Enable();
283 mpLbFillAttr
->Fill(aItem
.GetHatchList());
284 mpLbFillAttr
->SelectEntry(aString
);
288 mpLbFillAttr
->SetNoSelection();
294 case SID_BITMAP_LIST
:
296 if(SfxItemState::DEFAULT
== eState
)
298 if(mpStyleItem
&& drawing::FillStyle_BITMAP
== (drawing::FillStyle
)mpStyleItem
->GetValue())
302 const OUString
aString( mpBitmapItem
->GetName() );
303 const SfxObjectShell
* pSh
= SfxObjectShell::Current();
304 const SvxBitmapListItem
aItem(*static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
306 mpLbFillAttr
->Clear();
307 mpLbFillAttr
->Enable();
308 mpLbFillAttr
->Fill(aItem
.GetBitmapList());
309 mpLbFillAttr
->SelectEntry(aString
);
313 mpLbFillAttr
->SetNoSelection();
322 void SvxFillToolBoxControl::Update()
326 const drawing::FillStyle eXFS
= (drawing::FillStyle
)mpStyleItem
->GetValue();
327 SfxObjectShell
* pSh
= SfxObjectShell::Current();
331 case drawing::FillStyle_NONE
:
333 mpLbFillAttr
->Show();
334 mpToolBoxColor
->Hide();
337 case drawing::FillStyle_SOLID
:
341 mpLbFillAttr
->Hide();
342 mpToolBoxColor
->Show();
346 case drawing::FillStyle_GRADIENT
:
348 mpLbFillAttr
->Show();
349 mpToolBoxColor
->Hide();
351 if(pSh
&& pSh
->GetItem(SID_GRADIENT_LIST
))
353 const SvxGradientListItem
aItem(*static_cast<const SvxGradientListItem
*>(pSh
->GetItem(SID_GRADIENT_LIST
)));
354 mpLbFillAttr
->Enable();
355 mpLbFillAttr
->Clear();
356 mpLbFillAttr
->Fill(aItem
.GetGradientList());
358 if(mpFillGradientItem
)
360 const OUString
aString(mpFillGradientItem
->GetName());
362 mpLbFillAttr
->SelectEntry(aString
);
364 // Check if the entry is not in the list
365 if (mpLbFillAttr
->GetSelectedEntry() != aString
)
367 sal_Int32 nCount
= mpLbFillAttr
->GetEntryCount();
371 // Last entry gets tested against temporary entry
372 aTmpStr
= mpLbFillAttr
->GetEntry( nCount
- 1 );
373 if( aTmpStr
.startsWith(TMP_STR_BEGIN
) &&
374 aTmpStr
.endsWith(TMP_STR_END
) )
376 mpLbFillAttr
->RemoveEntry(nCount
- 1);
379 aTmpStr
= TMP_STR_BEGIN
+ aString
+ TMP_STR_END
;
381 XGradientList
aGradientList( "", ""/*TODO?*/ );
382 aGradientList
.Insert(o3tl::make_unique
<XGradientEntry
>(mpFillGradientItem
->GetGradientValue(), aTmpStr
));
383 aGradientList
.SetDirty( false );
384 const Bitmap aBmp
= aGradientList
.GetUiBitmap( 0 );
388 mpLbFillAttr
->InsertEntry(aGradientList
.Get(0)->GetName(), Image(aBmp
));
389 mpLbFillAttr
->SelectEntryPos(mpLbFillAttr
->GetEntryCount() - 1);
396 mpLbFillAttr
->SetNoSelection();
401 mpLbFillAttr
->SetNoSelection();
405 case drawing::FillStyle_HATCH
:
407 mpLbFillAttr
->Show();
408 mpToolBoxColor
->Hide();
410 if(pSh
&& pSh
->GetItem(SID_HATCH_LIST
))
412 const SvxHatchListItem
aItem(*static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
413 mpLbFillAttr
->Enable();
414 mpLbFillAttr
->Clear();
415 mpLbFillAttr
->Fill(aItem
.GetHatchList());
419 const OUString
aString(mpHatchItem
->GetName());
421 mpLbFillAttr
->SelectEntry( aString
);
423 // Check if the entry is not in the list
424 if( mpLbFillAttr
->GetSelectedEntry() != aString
)
426 const sal_Int32 nCount
= mpLbFillAttr
->GetEntryCount();
430 // Last entry gets tested against temporary entry
431 aTmpStr
= mpLbFillAttr
->GetEntry( nCount
- 1 );
432 if( aTmpStr
.startsWith(TMP_STR_BEGIN
) &&
433 aTmpStr
.endsWith(TMP_STR_END
) )
435 mpLbFillAttr
->RemoveEntry( nCount
- 1 );
438 aTmpStr
= TMP_STR_BEGIN
+ aString
+ TMP_STR_END
;
440 XHatchList
aHatchList( "", ""/*TODO?*/ );
441 aHatchList
.Insert(o3tl::make_unique
<XHatchEntry
>(mpHatchItem
->GetHatchValue(), aTmpStr
));
442 aHatchList
.SetDirty( false );
443 const Bitmap aBmp
= aHatchList
.GetUiBitmap( 0 );
445 if( !aBmp
.IsEmpty() )
447 mpLbFillAttr
->InsertEntry(aHatchList
.GetHatch(0)->GetName(), Image(aBmp
));
448 mpLbFillAttr
->SelectEntryPos( mpLbFillAttr
->GetEntryCount() - 1 );
455 mpLbFillAttr
->SetNoSelection();
460 mpLbFillAttr
->SetNoSelection();
464 case drawing::FillStyle_BITMAP
:
466 mpLbFillAttr
->Show();
467 mpToolBoxColor
->Hide();
469 if(pSh
&& pSh
->GetItem(SID_BITMAP_LIST
))
471 const SvxBitmapListItem
aItem(*static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
472 mpLbFillAttr
->Enable();
473 mpLbFillAttr
->Clear();
474 mpLbFillAttr
->Fill(aItem
.GetBitmapList());
478 const OUString
aString(mpBitmapItem
->GetName());
480 mpLbFillAttr
->SelectEntry(aString
);
482 // Check if the entry is not in the list
483 if (mpLbFillAttr
->GetSelectedEntry() != aString
)
485 sal_Int32 nCount
= mpLbFillAttr
->GetEntryCount();
489 // Last entry gets tested against temporary entry
490 aTmpStr
= mpLbFillAttr
->GetEntry(nCount
- 1);
491 if( aTmpStr
.startsWith(TMP_STR_BEGIN
) &&
492 aTmpStr
.endsWith(TMP_STR_END
) )
494 mpLbFillAttr
->RemoveEntry(nCount
- 1);
497 aTmpStr
= TMP_STR_BEGIN
+ aString
+ TMP_STR_END
;
499 XBitmapListRef xBitmapList
=
500 XPropertyList::AsBitmapList(
501 XPropertyList::CreatePropertyList(
502 XPropertyListType::Bitmap
, "TmpList", ""/*TODO?*/));
503 xBitmapList
->Insert(o3tl::make_unique
<XBitmapEntry
>(mpBitmapItem
->GetGraphicObject(), aTmpStr
));
504 xBitmapList
->SetDirty( false );
505 mpLbFillAttr
->Fill( xBitmapList
);
506 mpLbFillAttr
->SelectEntryPos(mpLbFillAttr
->GetEntryCount() - 1);
512 mpLbFillAttr
->SetNoSelection();
517 mpLbFillAttr
->SetNoSelection();
522 OSL_ENSURE(false, "Non supported FillType (!)");
529 VclPtr
<vcl::Window
> SvxFillToolBoxControl::CreateItemWindow(vcl::Window
*pParent
)
531 if(GetSlotId() == SID_ATTR_FILL_STYLE
)
533 mpFillControl
.reset(VclPtr
<FillControl
>::Create(pParent
));
535 mpLbFillType
= mpFillControl
->mpLbFillType
;
536 mpLbFillAttr
= mpFillControl
->mpLbFillAttr
;
537 mpToolBoxColor
= mpFillControl
->mpToolBoxColor
;
538 mpFillControl
->Resize();
539 mpToolBoxColor
->InsertItem(".uno:FillColor", m_xFrame
, ToolBoxItemBits::DROPDOWNONLY
, Size(mpToolBoxColor
->GetSizePixel().Width(), 0));
541 mpLbFillType
->SetSelectHdl(LINK(this,SvxFillToolBoxControl
,SelectFillTypeHdl
));
542 mpLbFillAttr
->SetSelectHdl(LINK(this,SvxFillToolBoxControl
,SelectFillAttrHdl
));
544 return mpFillControl
.get();
546 return VclPtr
<vcl::Window
>();
549 FillControl::FillControl(vcl::Window
* pParent
)
550 : Window(pParent
, WB_DIALOGCONTROL
)
551 , mpLbFillType(VclPtr
<SvxFillTypeBox
>::Create(this))
552 , mpToolBoxColor(VclPtr
<sfx2::sidebar::SidebarToolBox
>::Create(this))
553 , mpLbFillAttr(VclPtr
<SvxFillAttrBox
>::Create(this))
558 FillControl::~FillControl()
563 void FillControl::dispose()
565 mpLbFillType
.disposeAndClear();
566 mpToolBoxColor
.disposeAndClear();
567 mpLbFillAttr
.disposeAndClear();
568 vcl::Window::dispose();
571 IMPL_LINK_NOARG(SvxFillToolBoxControl
, SelectFillTypeHdl
, ListBox
&, void)
573 const drawing::FillStyle eXFS
= (drawing::FillStyle
)mpLbFillType
->GetSelectedEntryPos();
575 if((drawing::FillStyle
)meLastXFS
!= eXFS
)
577 mpLbFillAttr
->Clear();
578 SfxObjectShell
* pSh
= SfxObjectShell::Current();
579 const XFillStyleItem
aXFillStyleItem(eXFS
);
581 // #i122676# Do no longer trigger two Execute calls, one for SID_ATTR_FILL_STYLE
582 // and one for setting the fill attribute itself, but add two SfxPoolItems to the
583 // call to get just one action at the SdrObject and to create only one Undo action, too.
584 // Checked that this works in all apps.
588 case drawing::FillStyle_NONE
:
590 mpLbFillAttr
->Show();
591 mpToolBoxColor
->Hide();
592 mpLbFillType
->Selected();
593 mpLbFillAttr
->Disable();
595 // #i122676# need to call a single SID_ATTR_FILL_STYLE change
596 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
597 SID_ATTR_FILL_STYLE
, SfxCallMode::RECORD
,
598 { &aXFillStyleItem
});
601 case drawing::FillStyle_SOLID
:
603 mpLbFillAttr
->Hide();
604 mpToolBoxColor
->Show();
605 const OUString aTmpStr
;
606 const ::Color aColor
= mpColorItem
->GetColorValue();
607 const XFillColorItem
aXFillColorItem( aTmpStr
, aColor
);
609 // #i122676# change FillStyle and Color in one call
610 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
611 SID_ATTR_FILL_COLOR
, SfxCallMode::RECORD
,
612 { &aXFillColorItem
, &aXFillStyleItem
});
615 case drawing::FillStyle_GRADIENT
:
617 mpLbFillAttr
->Show();
618 mpToolBoxColor
->Hide();
620 if(pSh
&& pSh
->GetItem(SID_GRADIENT_LIST
))
622 if(!mpLbFillAttr
->GetEntryCount())
624 const SvxGradientListItem
aItem(*static_cast<const SvxGradientListItem
*>(pSh
->GetItem(SID_GRADIENT_LIST
)));
625 mpLbFillAttr
->Enable();
626 mpLbFillAttr
->Clear();
627 mpLbFillAttr
->Fill(aItem
.GetGradientList());
630 mpLbFillAttr
->AdaptDropDownLineCountToMaximum();
632 if(LISTBOX_ENTRY_NOTFOUND
!= mnLastPosGradient
)
634 const SvxGradientListItem
aItem(*static_cast<const SvxGradientListItem
*>(pSh
->GetItem(SID_GRADIENT_LIST
)));
636 if(mnLastPosGradient
< aItem
.GetGradientList()->Count())
638 const XGradient aGradient
= aItem
.GetGradientList()->GetGradient(mnLastPosGradient
)->GetGradient();
639 const XFillGradientItem
aXFillGradientItem(mpLbFillAttr
->GetEntry(mnLastPosGradient
), aGradient
);
641 // #i122676# change FillStyle and Gradient in one call
642 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
643 SID_ATTR_FILL_GRADIENT
, SfxCallMode::RECORD
,
644 { &aXFillGradientItem
, &aXFillStyleItem
});
645 mpLbFillAttr
->SelectEntryPos(mnLastPosGradient
);
651 mpLbFillAttr
->Disable();
655 case drawing::FillStyle_HATCH
:
657 mpLbFillAttr
->Show();
658 mpToolBoxColor
->Hide();
660 if(pSh
&& pSh
->GetItem(SID_HATCH_LIST
))
662 if(!mpLbFillAttr
->GetEntryCount())
664 const SvxHatchListItem
aItem( *static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
665 mpLbFillAttr
->Enable();
666 mpLbFillAttr
->Clear();
667 mpLbFillAttr
->Fill(aItem
.GetHatchList());
670 mpLbFillAttr
->AdaptDropDownLineCountToMaximum();
672 if(LISTBOX_ENTRY_NOTFOUND
!= mnLastPosHatch
)
674 const SvxHatchListItem
aItem(*static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
676 if(mnLastPosHatch
< aItem
.GetHatchList()->Count())
678 const XHatch aHatch
= aItem
.GetHatchList()->GetHatch(mnLastPosHatch
)->GetHatch();
679 const XFillHatchItem
aXFillHatchItem(mpLbFillAttr
->GetSelectedEntry(), aHatch
);
681 // #i122676# change FillStyle and Hatch in one call
682 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
683 SID_ATTR_FILL_HATCH
, SfxCallMode::RECORD
,
684 { &aXFillHatchItem
, &aXFillStyleItem
});
685 mpLbFillAttr
->SelectEntryPos(mnLastPosHatch
);
691 mpLbFillAttr
->Disable();
695 case drawing::FillStyle_BITMAP
:
697 mpLbFillAttr
->Show();
698 mpToolBoxColor
->Hide();
700 if(pSh
&& pSh
->GetItem(SID_BITMAP_LIST
))
702 if(!mpLbFillAttr
->GetEntryCount())
704 const SvxBitmapListItem
aItem( *static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
705 mpLbFillAttr
->Enable();
706 mpLbFillAttr
->Clear();
707 mpLbFillAttr
->Fill(aItem
.GetBitmapList());
710 mpLbFillAttr
->AdaptDropDownLineCountToMaximum();
712 if(LISTBOX_ENTRY_NOTFOUND
!= mnLastPosBitmap
)
714 const SvxBitmapListItem
aItem(*static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
716 if(mnLastPosBitmap
< aItem
.GetBitmapList()->Count())
718 const XBitmapEntry
* pXBitmapEntry
= aItem
.GetBitmapList()->GetBitmap(mnLastPosBitmap
);
719 const XFillBitmapItem
aXFillBitmapItem(mpLbFillAttr
->GetSelectedEntry(), pXBitmapEntry
->GetGraphicObject());
721 // #i122676# change FillStyle and Bitmap in one call
722 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
723 SID_ATTR_FILL_BITMAP
, SfxCallMode::RECORD
,
724 { &aXFillBitmapItem
, &aXFillStyleItem
});
725 mpLbFillAttr
->SelectEntryPos(mnLastPosBitmap
);
731 mpLbFillAttr
->Disable();
739 if(drawing::FillStyle_NONE
!= eXFS
)
741 mpLbFillType
->Selected();
746 IMPL_LINK_NOARG(SvxFillToolBoxControl
, SelectFillAttrHdl
, ListBox
&, void)
748 const drawing::FillStyle eXFS
= (drawing::FillStyle
)mpLbFillType
->GetSelectedEntryPos();
749 const XFillStyleItem
aXFillStyleItem(eXFS
);
750 SfxObjectShell
* pSh
= SfxObjectShell::Current();
752 // #i122676# dependent from bFillStyleChange, do execute a single or two
753 // changes in one Execute call
754 const bool bFillStyleChange((drawing::FillStyle
) meLastXFS
!= eXFS
);
758 case drawing::FillStyle_SOLID
:
762 // #i122676# Single FillStyle change call needed here
763 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
764 SID_ATTR_FILL_STYLE
, SfxCallMode::RECORD
,
765 { &aXFillStyleItem
});
769 case drawing::FillStyle_GRADIENT
:
771 sal_Int32 nPos
= mpLbFillAttr
->GetSelectedEntryPos();
773 if(LISTBOX_ENTRY_NOTFOUND
== nPos
)
775 nPos
= mnLastPosGradient
;
778 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
&& pSh
&& pSh
->GetItem(SID_GRADIENT_LIST
))
780 const SvxGradientListItem
aItem(*static_cast<const SvxGradientListItem
*>(pSh
->GetItem(SID_GRADIENT_LIST
)));
782 if(nPos
< aItem
.GetGradientList()->Count())
784 const XGradient aGradient
= aItem
.GetGradientList()->GetGradient(nPos
)->GetGradient();
785 const XFillGradientItem
aXFillGradientItem(mpLbFillAttr
->GetSelectedEntry(), aGradient
);
787 // #i122676# Change FillStyle and Gradinet in one call
788 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
789 SID_ATTR_FILL_GRADIENT
, SfxCallMode::RECORD
,
791 ? std::initializer_list
<SfxPoolItem
const*>{ &aXFillGradientItem
, &aXFillStyleItem
}
792 : std::initializer_list
<SfxPoolItem
const*>{ &aXFillGradientItem
});
796 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
)
798 mnLastPosGradient
= nPos
;
802 case drawing::FillStyle_HATCH
:
804 sal_Int32 nPos
= mpLbFillAttr
->GetSelectedEntryPos();
806 if(LISTBOX_ENTRY_NOTFOUND
== nPos
)
808 nPos
= mnLastPosHatch
;
811 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
&& pSh
&& pSh
->GetItem(SID_HATCH_LIST
))
813 const SvxHatchListItem
aItem(*static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
815 if(nPos
< aItem
.GetHatchList()->Count())
817 const XHatch aHatch
= aItem
.GetHatchList()->GetHatch(nPos
)->GetHatch();
818 const XFillHatchItem
aXFillHatchItem( mpLbFillAttr
->GetSelectedEntry(), aHatch
);
820 // #i122676# Change FillStyle and Hatch in one call
821 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
822 SID_ATTR_FILL_HATCH
, SfxCallMode::RECORD
,
824 ? std::initializer_list
<SfxPoolItem
const*>{ &aXFillHatchItem
, &aXFillStyleItem
}
825 : std::initializer_list
<SfxPoolItem
const*>{ &aXFillHatchItem
});
829 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
)
831 mnLastPosHatch
= nPos
;
835 case drawing::FillStyle_BITMAP
:
837 sal_Int32 nPos
= mpLbFillAttr
->GetSelectedEntryPos();
839 if(LISTBOX_ENTRY_NOTFOUND
== nPos
)
841 nPos
= mnLastPosBitmap
;
844 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
&& pSh
&& pSh
->GetItem(SID_BITMAP_LIST
))
846 const SvxBitmapListItem
aItem(*static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
848 if(nPos
< aItem
.GetBitmapList()->Count())
850 const XBitmapEntry
* pXBitmapEntry
= aItem
.GetBitmapList()->GetBitmap(nPos
);
851 const XFillBitmapItem
aXFillBitmapItem(mpLbFillAttr
->GetSelectedEntry(), pXBitmapEntry
->GetGraphicObject());
853 // #i122676# Change FillStyle and Bitmap in one call
854 SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
855 SID_ATTR_FILL_BITMAP
, SfxCallMode::RECORD
,
857 ? std::initializer_list
<SfxPoolItem
const*>{ &aXFillBitmapItem
, &aXFillStyleItem
}
858 : std::initializer_list
<SfxPoolItem
const*>{ &aXFillBitmapItem
});
862 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
)
864 mnLastPosBitmap
= nPos
;
872 void FillControl::Resize()
874 // Relative width of the two list boxes is 2/5 : 3/5
875 Size
aSize(GetOutputSizePixel());
876 long nW
= aSize
.Width() / 5;
877 long nH
= aSize
.Height();
879 long nPrefHeight
= mpLbFillType
->get_preferred_size().Height();
880 long nOffset
= (nH
- nPrefHeight
)/2;
881 mpLbFillType
->SetPosSizePixel(Point(0, nOffset
), Size(nW
* 2, nPrefHeight
));
882 nPrefHeight
= mpToolBoxColor
->get_preferred_size().Height();
883 nOffset
= (nH
- nPrefHeight
)/2;
884 mpToolBoxColor
->SetPosSizePixel(Point(nW
* 2, nOffset
),Size(nW
* 3, nPrefHeight
));
885 nPrefHeight
= mpLbFillType
->get_preferred_size().Height();
886 nOffset
= (nH
- nPrefHeight
)/2;
887 mpLbFillAttr
->SetPosSizePixel(Point(nW
* 2, nOffset
),Size(nW
* 3, nPrefHeight
));
890 void FillControl::SetOptimalSize()
892 const Size
aLogicalAttrSize(50,0);
893 Size
aSize(LogicToPixel(aLogicalAttrSize
, MapMode(MapUnit::MapAppFont
)));
895 Point aAttrPnt
= mpLbFillAttr
->GetPosPixel();
897 aSize
.Height() = std::max(aSize
.Height(), mpLbFillType
->get_preferred_size().Height());
898 aSize
.Height() = std::max(aSize
.Height(), mpToolBoxColor
->get_preferred_size().Height());
899 aSize
.Height() = std::max(aSize
.Height(), mpLbFillAttr
->get_preferred_size().Height());
901 aSize
.Width() = aAttrPnt
.X() + aSize
.Width();
906 void FillControl::DataChanged(const DataChangedEvent
& rDCEvt
)
908 if((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
909 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
))
913 Window::DataChanged(rDCEvt
);
916 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */