LibreOffice Module cui (master)  1
tparea.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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>
30 
31 using namespace com::sun::star;
32 
33 // static ----------------------------------------------------------------
34 
35 namespace {
36 
38 {
39  TRANSPARENT,
40  SOLID,
41  GRADIENT,
42  HATCH,
43  BITMAP,
44  PATTERN
45 };
46 
47 }
48 
50  svl::Items<
51  XATTR_GRADIENTSTEPCOUNT, XATTR_GRADIENTSTEPCOUNT,
52  SID_ATTR_FILL_STYLE, SID_ATTR_FILL_BITMAP>);
53 
54 namespace
55 {
56 
57 void lclExtendSize(Size& rSize, const Size& rInputSize)
58 {
59  if (rSize.Width() < rInputSize.Width())
60  rSize.setWidth( rInputSize.Width() );
61  if (rSize.Height() < rInputSize.Height())
62  rSize.setHeight( rInputSize.Height() );
63 }
64 
65 } // end anonymous namespace
66 
67 /*************************************************************************
68 |*
69 |* Dialog to modify fill-attributes
70 |*
71 \************************************************************************/
72 
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"))
92 {
93  maBox.AddButton(m_xBtnNone.get());
99  Link<weld::Toggleable&, 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);
106 
108 }
109 
111 {
112  m_xFillTab->set_size_request(-1, -1);
113 
114  // Calculate optimal size of all pages...
116  Size aSize(m_xFillTab->get_preferred_size());
117 
118  if (m_xBtnGradient->get_visible())
119  {
121  Size aGradientSize = m_xFillTab->get_preferred_size();
122  lclExtendSize(aSize, aGradientSize);
123  }
124  if (m_xBtnBitmap->get_visible())
125  {
127  Size aBitmapSize = m_xFillTab->get_preferred_size();
128  lclExtendSize(aSize, aBitmapSize);
129  }
130  if (m_xBtnHatch->get_visible())
131  {
133  Size aHatchSize = m_xFillTab->get_preferred_size();
134  lclExtendSize(aSize, aHatchSize);
135  }
136  if (m_xBtnPattern->get_visible())
137  {
139  Size aPatternSize = m_xFillTab->get_preferred_size();
140  lclExtendSize(aSize, aPatternSize);
141  }
142  m_xFillTabPage.reset();
143 
144  aSize.extendBy(10, 10); // apply a bit of margin
145 
146  m_xFillTab->set_size_request(aSize.Width(), aSize.Height());
147 }
148 
150 {
151  m_xFillTabPage.reset();
152 }
153 
155 {
156  drawing::FillStyle eXFS = drawing::FillStyle_NONE;
157  if( rSet.GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE )
158  {
159  XFillStyleItem aFillStyleItem( rSet.Get( GetWhich( XATTR_FILLSTYLE ) ) );
160  eXFS = aFillStyleItem.GetValue();
161  m_rXFSet.Put( aFillStyleItem );
162  }
163 
164  switch(eXFS)
165  {
166  default:
167  case drawing::FillStyle_NONE:
168  {
170  break;
171  }
172  case drawing::FillStyle_SOLID:
173  {
174  m_rXFSet.Put( rSet.Get( GetWhich( XATTR_FILLCOLOR ) ) );
176  break;
177  }
178  case drawing::FillStyle_GRADIENT:
179  {
182  break;
183  }
184  case drawing::FillStyle_HATCH:
185  {
186  m_rXFSet.Put( rSet.Get(XATTR_FILLHATCH) );
188  m_rXFSet.Put( rSet.Get(XATTR_FILLCOLOR) );
190  break;
191  }
192  case drawing::FillStyle_BITMAP:
193  {
194  const bool bPattern = rSet.Get(GetWhich(XATTR_FILLBITMAP)).isPattern();
195  // pass full item set here, bitmap fill has many attributes (tiling, size, offset etc.)
196  m_rXFSet.Put( rSet );
197  if (!bPattern)
199  else
201  break;
202  }
203  }
204 }
205 
206 template< typename TTabPage >
208 {
209  return static_cast<TTabPage&>(*m_xFillTabPage).DeactivatePage(_pSet);
210 }
211 
213 {
214  FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
215  switch( eFillType )
216  {
217  case TRANSPARENT:
218  {
219  // Fill: None doesn't have its own tabpage and thus
220  // implementation of FillItemSet, so we supply it here
221  if ( m_bBtnClicked )
222  {
223  XFillStyleItem aStyleItem( drawing::FillStyle_NONE );
224  _pSet->Put( aStyleItem );
225  }
226  break;
227  }
228  case SOLID:
229  return DeactivatePage_Impl<SvxColorTabPage>(_pSet);
230  case GRADIENT:
231  return DeactivatePage_Impl<SvxGradientTabPage>(_pSet);
232  case HATCH:
233  return DeactivatePage_Impl<SvxHatchTabPage>(_pSet);
234  case BITMAP:
235  return DeactivatePage_Impl<SvxBitmapTabPage&>(_pSet);
236  case PATTERN:
237  return DeactivatePage_Impl<SvxPatternTabPage>(_pSet);
238  default:
239  break;
240  }
241  return DeactivateRC::LeavePage;
242 }
243 
244 template< typename TTabPage >
246 {
247  return static_cast<TTabPage&>( *m_xFillTabPage ).FillItemSet( rAttrs );
248 }
249 
251 {
252  FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
253  switch( eFillType )
254  {
255  case TRANSPARENT:
256  {
257  rAttrs->Put( XFillStyleItem( drawing::FillStyle_NONE ) );
258  return true;
259  }
260  case SOLID:
261  {
262  return FillItemSet_Impl<SvxColorTabPage>( rAttrs );
263  }
264  case GRADIENT:
265  {
266  return FillItemSet_Impl<SvxGradientTabPage>( rAttrs );
267  }
268  case HATCH:
269  {
270  return FillItemSet_Impl<SvxHatchTabPage>( rAttrs );
271  }
272  case BITMAP:
273  {
274  return FillItemSet_Impl<SvxBitmapTabPage>( rAttrs );
275  }
276  case PATTERN:
277  {
278  return FillItemSet_Impl<SvxPatternTabPage>( rAttrs );
279  }
280  default:
281  return false;
282  }
283 }
284 
285 template< typename TTabPage >
287 {
288  static_cast<TTabPage&>( *m_xFillTabPage ).Reset( rAttrs );
289 }
290 
291 void SvxAreaTabPage::Reset( const SfxItemSet* rAttrs )
292 {
293  m_bBtnClicked = false;
294  auto eFillType = maBox.GetCurrentButtonPos();
295  switch(eFillType)
296  {
297  case SOLID:
298  {
299  Reset_Impl<SvxColorTabPage>( rAttrs );
300  break;
301  }
302  case GRADIENT:
303  {
304  Reset_Impl<SvxGradientTabPage>( rAttrs );
305  break;
306  }
307  case HATCH:
308  {
309  Reset_Impl<SvxHatchTabPage>( rAttrs );
310  break;
311  }
312  case BITMAP:
313  {
314  Reset_Impl<SvxBitmapTabPage>( rAttrs );
315  break;
316  }
317  case PATTERN:
318  {
319  Reset_Impl<SvxPatternTabPage>( rAttrs );
320  break;
321  }
322  default:
323  break;
324  }
325 }
326 
327 std::unique_ptr<SfxTabPage> SvxAreaTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
328 {
329  auto xRet = std::make_unique<SvxAreaTabPage>(pPage, pController, *rAttrs);
330  xRet->SetOptimalSize(pController);
331  return xRet;
332 }
333 
334 namespace {
335 
336 std::unique_ptr<SfxTabPage> lcl_CreateFillStyleTabPage(sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
337 {
338  CreateTabPage fnCreate = nullptr;
339  switch(nId)
340  {
341  case TRANSPARENT: fnCreate = nullptr; break;
342  case SOLID: fnCreate = &SvxColorTabPage::Create; break;
343  case GRADIENT: fnCreate = &SvxGradientTabPage::Create; break;
344  case HATCH: fnCreate = &SvxHatchTabPage::Create; break;
345  case BITMAP: fnCreate = &SvxBitmapTabPage::Create; break;
346  case PATTERN: fnCreate = &SvxPatternTabPage::Create; break;
347  }
348  return fnCreate ? (*fnCreate)( pPage, pController, &rSet ) : nullptr;
349 }
350 
351 }
352 
353 IMPL_LINK(SvxAreaTabPage, SelectFillTypeHdl_Impl, weld::Toggleable&, rButton, void)
354 {
355  //tdf#124549 - If the button is already active do not toggle it back.
356  if(!rButton.get_active())
357  rButton.set_active(true);
358 
359  SelectFillType(rButton);
360  m_bBtnClicked = true;
361 }
362 
364 {
365  if (_pSet)
366  m_rXFSet.Set(*_pSet);
367 
368  sal_Int32 nPos = maBox.GetButtonPos(&rButton);
369  if (nPos != -1 && (_pSet || nPos != maBox.GetCurrentButtonPos()))
370  {
371  maBox.SelectButton(&rButton);
372  FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
373  m_xFillTabPage = lcl_CreateFillStyleTabPage(eFillType, m_xFillTab.get(), GetDialogController(), m_rXFSet);
374  if (m_xFillTabPage)
375  {
376  m_xFillTabPage->SetDialogController(GetDialogController());
377  CreatePage(eFillType, *m_xFillTabPage);
378  }
379  }
380 }
381 
383 {
384  const SvxColorListItem* pColorListItem = aSet.GetItem<SvxColorListItem>(SID_COLOR_TABLE, false);
385  const SvxGradientListItem* pGradientListItem = aSet.GetItem<SvxGradientListItem>(SID_GRADIENT_LIST, false);
386  const SvxHatchListItem* pHatchingListItem = aSet.GetItem<SvxHatchListItem>(SID_HATCH_LIST, false);
387  const SvxBitmapListItem* pBitmapListItem = aSet.GetItem<SvxBitmapListItem>(SID_BITMAP_LIST, false);
388  const SvxPatternListItem* pPatternListItem = aSet.GetItem<SvxPatternListItem>(SID_PATTERN_LIST, false);
389 
390  if (pColorListItem)
391  SetColorList(pColorListItem->GetColorList());
392  if (pGradientListItem)
393  SetGradientList(pGradientListItem->GetGradientList());
394  if (pHatchingListItem)
395  SetHatchingList(pHatchingListItem->GetHatchList());
396  if (pBitmapListItem)
397  SetBitmapList(pBitmapListItem->GetBitmapList());
398  if (pPatternListItem)
399  SetPatternList(pPatternListItem->GetPatternList());
400 }
401 
402 void SvxAreaTabPage::CreatePage(sal_Int32 nId, SfxTabPage& rTab)
403 {
404  if(nId == SOLID )
405  {
406  auto& rColorTab = static_cast<SvxColorTabPage&>(rTab);
407  rColorTab.SetColorList(m_pColorList);
408  rColorTab.SetColorChgd(m_pnColorListState);
409  rColorTab.Construct();
410  rColorTab.ActivatePage(m_rXFSet);
411  rColorTab.Reset(&m_rXFSet);
412  rColorTab.set_visible(true);
413  }
414  else if(nId == GRADIENT)
415  {
416  auto& rGradientTab = static_cast<SvxGradientTabPage&>(rTab);
417  rGradientTab.SetColorList(m_pColorList);
418  rGradientTab.SetGradientList(m_pGradientList);
419  rGradientTab.SetGrdChgd(m_pnGradientListState);
420  rGradientTab.SetColorChgd(m_pnColorListState);
421  rGradientTab.Construct();
422  rGradientTab.ActivatePage(m_rXFSet);
423  rGradientTab.Reset(&m_rXFSet);
424  rGradientTab.set_visible(true);
425  }
426  else if(nId == HATCH)
427  {
428  auto& rHatchTab = static_cast<SvxHatchTabPage&>(rTab);
429  rHatchTab.SetColorList(m_pColorList);
430  rHatchTab.SetHatchingList(m_pHatchingList);
431  rHatchTab.SetHtchChgd(m_pnHatchingListState);
432  rHatchTab.SetColorChgd(m_pnColorListState);
433  rHatchTab.Construct();
434  rHatchTab.ActivatePage(m_rXFSet);
435  rHatchTab.Reset(&m_rXFSet);
436  rHatchTab.set_visible(true);
437  }
438  else if(nId == BITMAP)
439  {
440  auto& rBitmapTab = static_cast<SvxBitmapTabPage&>(rTab);
441  rBitmapTab.SetBitmapList(m_pBitmapList);
442  rBitmapTab.SetBmpChgd(m_pnBitmapListState);
443  rBitmapTab.Construct();
444  rBitmapTab.ActivatePage(m_rXFSet);
445  rBitmapTab.Reset(&m_rXFSet);
446  rBitmapTab.set_visible(true);
447  }
448  else if(nId == PATTERN)
449  {
450  auto& rPatternTab = static_cast<SvxPatternTabPage&>(rTab);
451  rPatternTab.SetColorList(m_pColorList);
452  rPatternTab.SetPatternList(m_pPatternList);
453  rPatternTab.SetPtrnChgd(m_pnPatternListState);
454  rPatternTab.SetColorChgd(m_pnColorListState);
455  rPatternTab.Construct();
456  rPatternTab.ActivatePage(m_rXFSet);
457  rPatternTab.Reset(&m_rXFSet);
458  rPatternTab.set_visible(true);
459  }
460 }
461 
462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DeactivateRC DeactivatePage_Impl(SfxItemSet *pSet)
Definition: tparea.cxx:207
void SetBitmapList(const XBitmapListRef &pBmpLst)
Definition: cuitabarea.hxx:557
void AddButton(weld::Toggleable *pButton)
Definition: cuitabarea.hxx:58
virtual bool FillItemSet(SfxItemSet *) override
Definition: tparea.cxx:250
void SelectFillType(weld::Toggleable &rButton, const SfxItemSet *_pSet=nullptr)
Definition: tparea.cxx:363
void Reset_Impl(const SfxItemSet *)
Definition: tparea.cxx:286
void setWidth(tools::Long nWidth)
void SetGradientList(XGradientListRef const &pGrdLst)
Definition: cuitabarea.hxx:275
bool Set(const SfxItemSet &, bool bDeep=true)
static constexpr auto Items
ButtonBox maBox
Definition: cuitabarea.hxx:211
std::unique_ptr< SfxTabPage > m_xFillTabPage
Definition: cuitabarea.hxx:210
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tparea.cxx:154
virtual void Reset(const SfxItemSet *) override
Definition: tparea.cxx:291
std::unique_ptr< weld::Toggleable > m_xBtnColor
Definition: cuitabarea.hxx:239
XGradientListRef m_pGradientList
Definition: cuitabarea.hxx:214
constexpr TypedWhichId< XFillHatchItem > XATTR_FILLHATCH(XATTR_FILL_FIRST+3)
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:274
constexpr TypedWhichId< XFillBackgroundItem > XATTR_FILLBACKGROUND(XATTR_FILL_FIRST+19)
IMPL_LINK(SvxAreaTabPage, SelectFillTypeHdl_Impl, weld::Toggleable &, rButton, void)
Definition: tparea.cxx:353
NONE
XBitmapListRef m_pBitmapList
Definition: cuitabarea.hxx:216
constexpr tools::Long Width() const
std::unique_ptr< weld::Toggleable > m_xBtnHatch
Definition: cuitabarea.hxx:241
void SetExchangeSupport()
void SelectButton(weld::Toggleable *pButton)
Definition: cuitabarea.hxx:72
std::unique_ptr< weld::Container > m_xFillTab
Definition: cuitabarea.hxx:237
std::unique_ptr< weld::Toggleable > m_xBtnBitmap
Definition: cuitabarea.hxx:242
FillType
Definition: tparea.cxx:37
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: tparea.cxx:382
void SetPatternList(XPatternListRef const &pPtrnLst)
Definition: cuitabarea.hxx:280
ChangeType * m_pnGradientListState
Definition: cuitabarea.hxx:228
ChangeType
std::unique_ptr< weld::Toggleable > m_xBtnGradient
Definition: cuitabarea.hxx:240
void SetColorList(const XColorListRef &pColList)
Definition: tpcolor.cxx:789
constexpr TypedWhichId< XFillGradientItem > XATTR_FILLGRADIENT(XATTR_FILL_FIRST+2)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void SetHatchingList(XHatchListRef const &pHtchLst)
Definition: cuitabarea.hxx:277
constexpr OUStringLiteral PATTERN
constexpr TypedWhichId< XFillBitmapItem > XATTR_FILLBITMAP(XATTR_FILL_FIRST+4)
void CreatePage(sal_Int32 nId, SfxTabPage &rTab)
Definition: tparea.cxx:402
ChangeType * m_pnBitmapListState
Definition: cuitabarea.hxx:226
std::unique_ptr< weld::Toggleable > m_xBtnNone
Definition: cuitabarea.hxx:238
virtual ~SvxAreaTabPage() override
Definition: tparea.cxx:149
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tparea.cxx:212
XHatchListRef m_pHatchingList
Definition: cuitabarea.hxx:215
const XColorListRef & GetColorList() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpcolor.cxx:290
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpbitmap.cxx:419
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::Toggleable > m_xBtnPattern
Definition: cuitabarea.hxx:243
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr tools::Long Height() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tphatch.cxx:272
sal_Int32 GetButtonPos(weld::Toggleable *pButton)
Definition: cuitabarea.hxx:64
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tparea.cxx:327
ChangeType * m_pnPatternListState
Definition: cuitabarea.hxx:227
sal_Int32 GetCurrentButtonPos() const
Definition: cuitabarea.hxx:63
std::unique_ptr< SfxTabPage >(* CreateTabPage)(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:410
SfxOkDialogController * GetDialogController() const
ChangeType * m_pnHatchingListState
Definition: cuitabarea.hxx:229
DeactivateRC
void setHeight(tools::Long nHeight)
static const WhichRangesContainer pAreaRanges
Definition: cuitabarea.hxx:208
SvxAreaTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tparea.cxx:73
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tppattern.cxx:239
bool FillItemSet_Impl(SfxItemSet *)
Definition: tparea.cxx:245
void SetBitmapList(XBitmapListRef const &pBmpLst)
Definition: cuitabarea.hxx:279
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
XPatternListRef m_pPatternList
Definition: cuitabarea.hxx:217
XColorListRef m_pColorList
Definition: cuitabarea.hxx:213
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:613
void SetOptimalSize(weld::DialogController *pController)
Definition: tparea.cxx:110
sal_uInt16 nPos
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:478
ChangeType * m_pnColorListState
Definition: cuitabarea.hxx:225
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpgradnt.cxx:232
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:232