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 <svx/svxids.hrc>
21 #include <svx/xfillit0.hxx>
22 #include <svx/xflbckit.hxx>
23 #include <svx/drawitem.hxx>
24 #include <svx/xflclit.hxx>
25 #include <svx/xflgrit.hxx>
26 #include <svx/xflhtit.hxx>
27 #include <svx/xbtmpit.hxx>
28 #include <cuitabarea.hxx>
29 #include <sfx2/tabdlg.hxx>
31 using namespace com::sun::star
;
33 // static ----------------------------------------------------------------
45 const sal_uInt16
SvxAreaTabPage::pAreaRanges
[] =
47 XATTR_GRADIENTSTEPCOUNT
,
48 XATTR_GRADIENTSTEPCOUNT
,
57 void lclExtendSize(Size
& rSize
, const Size
& rInputSize
)
59 if (rSize
.Width() < rInputSize
.Width())
60 rSize
.setWidth( rInputSize
.Width() );
61 if (rSize
.Height() < rInputSize
.Height())
62 rSize
.setHeight( rInputSize
.Height() );
65 } // end anonymous namespace
67 /*************************************************************************
69 |* Dialog to modify fill-attributes
71 \************************************************************************/
73 SvxAreaTabPage::SvxAreaTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
74 : SfxTabPage(pPage
, pController
, "cui/ui/areatabpage.ui", "AreaTabPage", &rInAttrs
)
75 // local fixed not o be changed values for local pointers
76 , maFixed_ChangeType(ChangeType::NONE
)
77 // init with pointers to fixed ChangeType
78 , m_pnColorListState(&maFixed_ChangeType
)
79 , m_pnBitmapListState(&maFixed_ChangeType
)
80 , m_pnPatternListState(&maFixed_ChangeType
)
81 , m_pnGradientListState(&maFixed_ChangeType
)
82 , m_pnHatchingListState(&maFixed_ChangeType
)
83 , m_aXFillAttr(rInAttrs
.GetPool())
84 , m_rXFSet(m_aXFillAttr
.GetItemSet())
85 , m_xFillTab(m_xBuilder
->weld_container("fillstylebox"))
86 , m_xBtnNone(m_xBuilder
->weld_toggle_button("btnnone"))
87 , m_xBtnColor(m_xBuilder
->weld_toggle_button("btncolor"))
88 , m_xBtnGradient(m_xBuilder
->weld_toggle_button("btngradient"))
89 , m_xBtnHatch(m_xBuilder
->weld_toggle_button("btnhatch"))
90 , m_xBtnBitmap(m_xBuilder
->weld_toggle_button("btnbitmap"))
91 , m_xBtnPattern(m_xBuilder
->weld_toggle_button("btnpattern"))
93 maBox
.AddButton(m_xBtnNone
.get());
94 maBox
.AddButton(m_xBtnColor
.get());
95 maBox
.AddButton(m_xBtnGradient
.get());
96 maBox
.AddButton(m_xBtnHatch
.get());
97 maBox
.AddButton(m_xBtnBitmap
.get());
98 maBox
.AddButton(m_xBtnPattern
.get());
99 Link
<weld::ToggleButton
&, void> aLink
= LINK(this, SvxAreaTabPage
, SelectFillTypeHdl_Impl
);
100 m_xBtnNone
->connect_toggled(aLink
);
101 m_xBtnColor
->connect_toggled(aLink
);
102 m_xBtnGradient
->connect_toggled(aLink
);
103 m_xBtnHatch
->connect_toggled(aLink
);
104 m_xBtnBitmap
->connect_toggled(aLink
);
105 m_xBtnPattern
->connect_toggled(aLink
);
107 SetExchangeSupport();
110 void SvxAreaTabPage::SetOptimalSize(weld::DialogController
* pController
)
112 m_xFillTab
->set_size_request(-1, -1);
114 // Calculate optimal size of all pages...
115 m_xFillTabPage
= SvxColorTabPage::Create(m_xFillTab
.get(), pController
, &m_rXFSet
);
116 Size
aSize(m_xFillTab
->get_preferred_size());
118 if (m_xBtnGradient
->get_visible())
120 m_xFillTabPage
= SvxGradientTabPage::Create(m_xFillTab
.get(), pController
, &m_rXFSet
);
121 Size aGradientSize
= m_xFillTab
->get_preferred_size();
122 lclExtendSize(aSize
, aGradientSize
);
124 if (m_xBtnBitmap
->get_visible())
126 m_xFillTabPage
= SvxBitmapTabPage::Create(m_xFillTab
.get(), pController
, &m_rXFSet
);
127 Size aBitmapSize
= m_xFillTab
->get_preferred_size();
128 lclExtendSize(aSize
, aBitmapSize
);
130 if (m_xBtnHatch
->get_visible())
132 m_xFillTabPage
= SvxHatchTabPage::Create(m_xFillTab
.get(), pController
, &m_rXFSet
);
133 Size aHatchSize
= m_xFillTab
->get_preferred_size();
134 lclExtendSize(aSize
, aHatchSize
);
136 if (m_xBtnPattern
->get_visible())
138 m_xFillTabPage
= SvxPatternTabPage::Create(m_xFillTab
.get(), pController
, &m_rXFSet
);
139 Size aPatternSize
= m_xFillTab
->get_preferred_size();
140 lclExtendSize(aSize
, aPatternSize
);
142 m_xFillTabPage
.reset();
144 aSize
.extendBy(10, 10); // apply a bit of margin
146 m_xFillTab
->set_size_request(aSize
.Width(), aSize
.Height());
149 SvxAreaTabPage::~SvxAreaTabPage()
151 m_xFillTabPage
.reset();
154 void SvxAreaTabPage::ActivatePage( const SfxItemSet
& rSet
)
156 drawing::FillStyle eXFS
= drawing::FillStyle_NONE
;
157 if( rSet
.GetItemState( XATTR_FILLSTYLE
) != SfxItemState::DONTCARE
)
159 XFillStyleItem
aFillStyleItem( static_cast<const XFillStyleItem
&>( rSet
.Get( GetWhich( XATTR_FILLSTYLE
) ) ) );
160 eXFS
= aFillStyleItem
.GetValue();
161 m_rXFSet
.Put( aFillStyleItem
);
167 case drawing::FillStyle_NONE
:
169 SelectFillType(*m_xBtnNone
);
172 case drawing::FillStyle_SOLID
:
174 m_rXFSet
.Put( static_cast<const XFillColorItem
&>( rSet
.Get( GetWhich( XATTR_FILLCOLOR
) ) ) );
175 SelectFillType(*m_xBtnColor
);
178 case drawing::FillStyle_GRADIENT
:
180 m_rXFSet
.Put( static_cast<const XFillGradientItem
&>( rSet
.Get( GetWhich( XATTR_FILLGRADIENT
) ) ) );
181 SelectFillType(*m_xBtnGradient
);
184 case drawing::FillStyle_HATCH
:
186 m_rXFSet
.Put( rSet
.Get(XATTR_FILLHATCH
) );
187 m_rXFSet
.Put( rSet
.Get(XATTR_FILLBACKGROUND
) );
188 m_rXFSet
.Put( rSet
.Get(XATTR_FILLCOLOR
) );
189 SelectFillType(*m_xBtnHatch
);
192 case drawing::FillStyle_BITMAP
:
195 = rSet
.Get(TypedWhichId
<XFillBitmapItem
>(GetWhich(XATTR_FILLBITMAP
))).isPattern();
196 // pass full item set here, bitmap fill has many attributes (tiling, size, offset etc.)
197 m_rXFSet
.Put( rSet
);
199 SelectFillType(*m_xBtnBitmap
);
201 SelectFillType(*m_xBtnPattern
);
207 template< typename TTabPage
>
208 DeactivateRC
SvxAreaTabPage::DeactivatePage_Impl( SfxItemSet
* _pSet
)
210 return static_cast<TTabPage
&>(*m_xFillTabPage
).DeactivatePage(_pSet
);
213 DeactivateRC
SvxAreaTabPage::DeactivatePage( SfxItemSet
* _pSet
)
215 FillType eFillType
= static_cast<FillType
>(maBox
.GetCurrentButtonPos());
220 // Fill: None doesn't have its own tabpage and thus
221 // implementation of FillItemSet, so we supply it here
224 XFillStyleItem
aStyleItem( drawing::FillStyle_NONE
);
225 _pSet
->Put( aStyleItem
);
230 return DeactivatePage_Impl
<SvxColorTabPage
>(_pSet
);
232 return DeactivatePage_Impl
<SvxGradientTabPage
>(_pSet
);
234 return DeactivatePage_Impl
<SvxHatchTabPage
>(_pSet
);
236 return DeactivatePage_Impl
<SvxBitmapTabPage
&>(_pSet
);
238 return DeactivatePage_Impl
<SvxPatternTabPage
>(_pSet
);
242 return DeactivateRC::LeavePage
;
245 template< typename TTabPage
>
246 bool SvxAreaTabPage::FillItemSet_Impl( SfxItemSet
* rAttrs
)
248 return static_cast<TTabPage
&>( *m_xFillTabPage
).FillItemSet( rAttrs
);
251 bool SvxAreaTabPage::FillItemSet( SfxItemSet
* rAttrs
)
253 FillType eFillType
= static_cast<FillType
>(maBox
.GetCurrentButtonPos());
258 rAttrs
->Put( XFillStyleItem( drawing::FillStyle_NONE
) );
263 return FillItemSet_Impl
<SvxColorTabPage
>( rAttrs
);
267 return FillItemSet_Impl
<SvxGradientTabPage
>( rAttrs
);
271 return FillItemSet_Impl
<SvxHatchTabPage
>( rAttrs
);
275 return FillItemSet_Impl
<SvxBitmapTabPage
>( rAttrs
);
279 return FillItemSet_Impl
<SvxPatternTabPage
>( rAttrs
);
286 template< typename TTabPage
>
287 void SvxAreaTabPage::Reset_Impl( const SfxItemSet
* rAttrs
)
289 static_cast<TTabPage
&>( *m_xFillTabPage
).Reset( rAttrs
);
292 void SvxAreaTabPage::Reset( const SfxItemSet
* rAttrs
)
294 m_bBtnClicked
= false;
295 auto eFillType
= maBox
.GetCurrentButtonPos();
300 Reset_Impl
<SvxColorTabPage
>( rAttrs
);
305 Reset_Impl
<SvxGradientTabPage
>( rAttrs
);
310 Reset_Impl
<SvxHatchTabPage
>( rAttrs
);
315 Reset_Impl
<SvxBitmapTabPage
>( rAttrs
);
320 Reset_Impl
<SvxPatternTabPage
>( rAttrs
);
328 std::unique_ptr
<SfxTabPage
> SvxAreaTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrs
)
330 auto xRet
= std::make_unique
<SvxAreaTabPage
>(pPage
, pController
, *rAttrs
);
331 xRet
->SetOptimalSize(pController
);
337 std::unique_ptr
<SfxTabPage
> lcl_CreateFillStyleTabPage(sal_uInt16 nId
, weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
339 CreateTabPage fnCreate
= nullptr;
342 case TRANSPARENT
: fnCreate
= nullptr; break;
343 case SOLID
: fnCreate
= &SvxColorTabPage::Create
; break;
344 case GRADIENT
: fnCreate
= &SvxGradientTabPage::Create
; break;
345 case HATCH
: fnCreate
= &SvxHatchTabPage::Create
; break;
346 case BITMAP
: fnCreate
= &SvxBitmapTabPage::Create
; break;
347 case PATTERN
: fnCreate
= &SvxPatternTabPage::Create
; break;
349 return fnCreate
? (*fnCreate
)( pPage
, pController
, &rSet
) : nullptr;
354 IMPL_LINK(SvxAreaTabPage
, SelectFillTypeHdl_Impl
, weld::ToggleButton
&, rButton
, void)
356 //tdf#124549 - If the button is already active do not toggle it back.
357 if(!rButton
.get_active())
358 rButton
.set_active(true);
360 SelectFillType(rButton
);
361 m_bBtnClicked
= true;
364 void SvxAreaTabPage::SelectFillType(weld::ToggleButton
& rButton
, const SfxItemSet
* _pSet
)
367 m_rXFSet
.Set(*_pSet
);
369 sal_Int32 nPos
= maBox
.GetButtonPos(&rButton
);
370 if (nPos
!= -1 && (_pSet
|| nPos
!= maBox
.GetCurrentButtonPos()))
372 maBox
.SelectButton(&rButton
);
373 FillType eFillType
= static_cast<FillType
>(maBox
.GetCurrentButtonPos());
374 m_xFillTabPage
= lcl_CreateFillStyleTabPage(eFillType
, m_xFillTab
.get(), GetDialogController(), m_rXFSet
);
376 m_xFillTabPage
->SetDialogController(GetDialogController());
377 CreatePage(eFillType
, m_xFillTabPage
.get());
381 void SvxAreaTabPage::PageCreated(const SfxAllItemSet
& aSet
)
383 const SvxColorListItem
* pColorListItem
= aSet
.GetItem
<SvxColorListItem
>(SID_COLOR_TABLE
, false);
384 const SvxGradientListItem
* pGradientListItem
= aSet
.GetItem
<SvxGradientListItem
>(SID_GRADIENT_LIST
, false);
385 const SvxHatchListItem
* pHatchingListItem
= aSet
.GetItem
<SvxHatchListItem
>(SID_HATCH_LIST
, false);
386 const SvxBitmapListItem
* pBitmapListItem
= aSet
.GetItem
<SvxBitmapListItem
>(SID_BITMAP_LIST
, false);
387 const SvxPatternListItem
* pPatternListItem
= aSet
.GetItem
<SvxPatternListItem
>(SID_PATTERN_LIST
, false);
390 SetColorList(pColorListItem
->GetColorList());
391 if (pGradientListItem
)
392 SetGradientList(pGradientListItem
->GetGradientList());
393 if (pHatchingListItem
)
394 SetHatchingList(pHatchingListItem
->GetHatchList());
396 SetBitmapList(pBitmapListItem
->GetBitmapList());
397 if (pPatternListItem
)
398 SetPatternList(pPatternListItem
->GetPatternList());
401 void SvxAreaTabPage::CreatePage( sal_Int32 nId
, SfxTabPage
* pTab
)
405 auto* pColorTab
= static_cast<SvxColorTabPage
*>(pTab
);
406 pColorTab
->SetColorList(m_pColorList
);
407 pColorTab
->SetColorChgd(m_pnColorListState
);
408 pColorTab
->Construct();
409 pColorTab
->ActivatePage(m_rXFSet
);
410 pColorTab
->Reset(&m_rXFSet
);
411 pColorTab
->set_visible(true);
413 else if(nId
== GRADIENT
)
415 auto* pGradientTab
= static_cast<SvxGradientTabPage
*>(pTab
);
416 pGradientTab
->SetColorList(m_pColorList
);
417 pGradientTab
->SetGradientList(m_pGradientList
);
418 pGradientTab
->SetGrdChgd(m_pnGradientListState
);
419 pGradientTab
->SetColorChgd(m_pnColorListState
);
420 pGradientTab
->Construct();
421 pGradientTab
->ActivatePage(m_rXFSet
);
422 pGradientTab
->Reset(&m_rXFSet
);
423 pGradientTab
->set_visible(true);
425 else if(nId
== HATCH
)
427 auto* pHatchTab
= static_cast<SvxHatchTabPage
*>(pTab
);
428 pHatchTab
->SetColorList(m_pColorList
);
429 pHatchTab
->SetHatchingList(m_pHatchingList
);
430 pHatchTab
->SetHtchChgd(m_pnHatchingListState
);
431 pHatchTab
->SetColorChgd(m_pnColorListState
);
432 pHatchTab
->Construct();
433 pHatchTab
->ActivatePage(m_rXFSet
);
434 pHatchTab
->Reset(&m_rXFSet
);
435 pHatchTab
->set_visible(true);
437 else if(nId
== BITMAP
)
439 auto* pBitmapTab
= static_cast<SvxBitmapTabPage
*>(pTab
);
440 pBitmapTab
->SetBitmapList(m_pBitmapList
);
441 pBitmapTab
->SetBmpChgd(m_pnBitmapListState
);
442 pBitmapTab
->Construct();
443 pBitmapTab
->ActivatePage(m_rXFSet
);
444 pBitmapTab
->Reset(&m_rXFSet
);
445 pBitmapTab
->set_visible(true);
447 else if(nId
== PATTERN
)
449 auto* pPatternTab
= static_cast<SvxPatternTabPage
*>(pTab
);
450 pPatternTab
->SetColorList(m_pColorList
);
451 pPatternTab
->SetPatternList(m_pPatternList
);
452 pPatternTab
->SetPtrnChgd(m_pnPatternListState
);
453 pPatternTab
->SetColorChgd(m_pnColorListState
);
454 pPatternTab
->Construct();
455 pPatternTab
->ActivatePage(m_rXFSet
);
456 pPatternTab
->Reset(&m_rXFSet
);
457 pPatternTab
->set_visible(true);
461 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */