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 
49 const sal_uInt16 SvxAreaTabPage::pAreaRanges[] =
50 {
53  SID_ATTR_FILL_STYLE,
54  SID_ATTR_FILL_BITMAP,
55  0
56 };
57 
58 namespace
59 {
60 
61 void lclExtendSize(Size& rSize, const Size& rInputSize)
62 {
63  if (rSize.Width() < rInputSize.Width())
64  rSize.setWidth( rInputSize.Width() );
65  if (rSize.Height() < rInputSize.Height())
66  rSize.setHeight( rInputSize.Height() );
67 }
68 
69 } // end anonymous namespace
70 
71 /*************************************************************************
72 |*
73 |* Dialog to modify fill-attributes
74 |*
75 \************************************************************************/
76 
78  : SfxTabPage(pPage, pController, "cui/ui/areatabpage.ui", "AreaTabPage", &rInAttrs)
79  // local fixed not o be changed values for local pointers
80  , maFixed_ChangeType(ChangeType::NONE)
81  // init with pointers to fixed ChangeType
82  , m_pnColorListState(&maFixed_ChangeType)
83  , m_pnBitmapListState(&maFixed_ChangeType)
84  , m_pnPatternListState(&maFixed_ChangeType)
85  , m_pnGradientListState(&maFixed_ChangeType)
86  , m_pnHatchingListState(&maFixed_ChangeType)
87  , m_aXFillAttr(rInAttrs.GetPool())
88  , m_rXFSet(m_aXFillAttr.GetItemSet())
89  , m_xFillTab(m_xBuilder->weld_container("fillstylebox"))
90  , m_xBtnNone(m_xBuilder->weld_toggle_button("btnnone"))
91  , m_xBtnColor(m_xBuilder->weld_toggle_button("btncolor"))
92  , m_xBtnGradient(m_xBuilder->weld_toggle_button("btngradient"))
93  , m_xBtnHatch(m_xBuilder->weld_toggle_button("btnhatch"))
94  , m_xBtnBitmap(m_xBuilder->weld_toggle_button("btnbitmap"))
95  , m_xBtnPattern(m_xBuilder->weld_toggle_button("btnpattern"))
96 {
97  maBox.AddButton(m_xBtnNone.get());
100  maBox.AddButton(m_xBtnHatch.get());
103  Link<weld::ToggleButton&, void> aLink = LINK(this, SvxAreaTabPage, SelectFillTypeHdl_Impl);
104  m_xBtnNone->connect_toggled(aLink);
105  m_xBtnColor->connect_toggled(aLink);
106  m_xBtnGradient->connect_toggled(aLink);
107  m_xBtnHatch->connect_toggled(aLink);
108  m_xBtnBitmap->connect_toggled(aLink);
109  m_xBtnPattern->connect_toggled(aLink);
110 
112 }
113 
115 {
116  m_xFillTab->set_size_request(-1, -1);
117 
118  // Calculate optimal size of all pages...
120  Size aSize(m_xFillTab->get_preferred_size());
121 
122  if (m_xBtnGradient->get_visible())
123  {
125  Size aGradientSize = m_xFillTab->get_preferred_size();
126  lclExtendSize(aSize, aGradientSize);
127  }
128  if (m_xBtnBitmap->get_visible())
129  {
131  Size aBitmapSize = m_xFillTab->get_preferred_size();
132  lclExtendSize(aSize, aBitmapSize);
133  }
134  if (m_xBtnHatch->get_visible())
135  {
137  Size aHatchSize = m_xFillTab->get_preferred_size();
138  lclExtendSize(aSize, aHatchSize);
139  }
140  if (m_xBtnPattern->get_visible())
141  {
143  Size aPatternSize = m_xFillTab->get_preferred_size();
144  lclExtendSize(aSize, aPatternSize);
145  }
146  m_xFillTabPage.reset();
147 
148  aSize.extendBy(10, 10); // apply a bit of margin
149 
150  m_xFillTab->set_size_request(aSize.Width(), aSize.Height());
151 }
152 
154 {
155  m_xFillTabPage.reset();
156 }
157 
159 {
160  drawing::FillStyle eXFS = drawing::FillStyle_NONE;
161  if( rSet.GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE )
162  {
163  XFillStyleItem aFillStyleItem( static_cast<const XFillStyleItem&>( rSet.Get( GetWhich( XATTR_FILLSTYLE ) ) ) );
164  eXFS = aFillStyleItem.GetValue();
165  m_rXFSet.Put( aFillStyleItem );
166  }
167 
168  switch(eXFS)
169  {
170  default:
171  case drawing::FillStyle_NONE:
172  {
174  break;
175  }
176  case drawing::FillStyle_SOLID:
177  {
178  m_rXFSet.Put( static_cast<const XFillColorItem&>( rSet.Get( GetWhich( XATTR_FILLCOLOR ) ) ) );
180  break;
181  }
182  case drawing::FillStyle_GRADIENT:
183  {
184  m_rXFSet.Put( static_cast<const XFillGradientItem&>( rSet.Get( GetWhich( XATTR_FILLGRADIENT ) ) ) );
186  break;
187  }
188  case drawing::FillStyle_HATCH:
189  {
190  m_rXFSet.Put( rSet.Get(XATTR_FILLHATCH) );
192  m_rXFSet.Put( rSet.Get(XATTR_FILLCOLOR) );
194  break;
195  }
196  case drawing::FillStyle_BITMAP:
197  {
198  const bool bPattern
200  // pass full item set here, bitmap fill has many attributes (tiling, size, offset etc.)
201  m_rXFSet.Put( rSet );
202  if (!bPattern)
204  else
206  break;
207  }
208  }
209 }
210 
211 template< typename TTabPage >
213 {
214  return static_cast<TTabPage&>(*m_xFillTabPage).DeactivatePage(_pSet);
215 }
216 
218 {
219  FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
220  switch( eFillType )
221  {
222  case TRANSPARENT:
223  {
224  // Fill: None doesn't have its own tabpage and thus
225  // implementation of FillItemSet, so we supply it here
226  if ( m_bBtnClicked )
227  {
228  XFillStyleItem aStyleItem( drawing::FillStyle_NONE );
229  _pSet->Put( aStyleItem );
230  }
231  break;
232  }
233  case SOLID:
234  return DeactivatePage_Impl<SvxColorTabPage>(_pSet);
235  case GRADIENT:
236  return DeactivatePage_Impl<SvxGradientTabPage>(_pSet);
237  case HATCH:
238  return DeactivatePage_Impl<SvxHatchTabPage>(_pSet);
239  case BITMAP:
240  return DeactivatePage_Impl<SvxBitmapTabPage&>(_pSet);
241  case PATTERN:
242  return DeactivatePage_Impl<SvxPatternTabPage>(_pSet);
243  default:
244  break;
245  }
246  return DeactivateRC::LeavePage;
247 }
248 
249 template< typename TTabPage >
251 {
252  return static_cast<TTabPage&>( *m_xFillTabPage ).FillItemSet( rAttrs );
253 }
254 
256 {
257  FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
258  switch( eFillType )
259  {
260  case TRANSPARENT:
261  {
262  rAttrs->Put( XFillStyleItem( drawing::FillStyle_NONE ) );
263  return true;
264  }
265  case SOLID:
266  {
267  return FillItemSet_Impl<SvxColorTabPage>( rAttrs );
268  }
269  case GRADIENT:
270  {
271  return FillItemSet_Impl<SvxGradientTabPage>( rAttrs );
272  }
273  case HATCH:
274  {
275  return FillItemSet_Impl<SvxHatchTabPage>( rAttrs );
276  }
277  case BITMAP:
278  {
279  return FillItemSet_Impl<SvxBitmapTabPage>( rAttrs );
280  }
281  case PATTERN:
282  {
283  return FillItemSet_Impl<SvxPatternTabPage>( rAttrs );
284  }
285  default:
286  return false;
287  }
288 }
289 
290 template< typename TTabPage >
292 {
293  static_cast<TTabPage&>( *m_xFillTabPage ).Reset( rAttrs );
294 }
295 
296 void SvxAreaTabPage::Reset( const SfxItemSet* rAttrs )
297 {
298  m_bBtnClicked = false;
299  auto eFillType = maBox.GetCurrentButtonPos();
300  switch(eFillType)
301  {
302  case SOLID:
303  {
304  Reset_Impl<SvxColorTabPage>( rAttrs );
305  break;
306  }
307  case GRADIENT:
308  {
309  Reset_Impl<SvxGradientTabPage>( rAttrs );
310  break;
311  }
312  case HATCH:
313  {
314  Reset_Impl<SvxHatchTabPage>( rAttrs );
315  break;
316  }
317  case BITMAP:
318  {
319  Reset_Impl<SvxBitmapTabPage>( rAttrs );
320  break;
321  }
322  case PATTERN:
323  {
324  Reset_Impl<SvxPatternTabPage>( rAttrs );
325  break;
326  }
327  default:
328  break;
329  }
330 }
331 
332 std::unique_ptr<SfxTabPage> SvxAreaTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
333 {
334  auto xRet = std::make_unique<SvxAreaTabPage>(pPage, pController, *rAttrs);
335  xRet->SetOptimalSize(pController);
336  return xRet;
337 }
338 
339 namespace {
340 
341 std::unique_ptr<SfxTabPage> lcl_CreateFillStyleTabPage(sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
342 {
343  CreateTabPage fnCreate = nullptr;
344  switch(nId)
345  {
346  case TRANSPARENT: fnCreate = nullptr; break;
347  case SOLID: fnCreate = &SvxColorTabPage::Create; break;
348  case GRADIENT: fnCreate = &SvxGradientTabPage::Create; break;
349  case HATCH: fnCreate = &SvxHatchTabPage::Create; break;
350  case BITMAP: fnCreate = &SvxBitmapTabPage::Create; break;
351  case PATTERN: fnCreate = &SvxPatternTabPage::Create; break;
352  }
353  return fnCreate ? (*fnCreate)( pPage, pController, &rSet ) : nullptr;
354 }
355 
356 }
357 
358 IMPL_LINK(SvxAreaTabPage, SelectFillTypeHdl_Impl, weld::ToggleButton&, rButton, void)
359 {
360  //tdf#124549 - If the button is already active do not toggle it back.
361  if(!rButton.get_active())
362  rButton.set_active(true);
363 
364  SelectFillType(rButton);
365  m_bBtnClicked = true;
366 }
367 
369 {
370  if (_pSet)
371  m_rXFSet.Set(*_pSet);
372 
373  sal_Int32 nPos = maBox.GetButtonPos(&rButton);
374  if (nPos != -1 && (_pSet || nPos != maBox.GetCurrentButtonPos()))
375  {
376  maBox.SelectButton(&rButton);
377  FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
378  m_xFillTabPage = lcl_CreateFillStyleTabPage(eFillType, m_xFillTab.get(), GetDialogController(), m_rXFSet);
379  if (m_xFillTabPage)
380  m_xFillTabPage->SetDialogController(GetDialogController());
381  CreatePage(eFillType, m_xFillTabPage.get());
382  }
383 }
384 
386 {
387  const SvxColorListItem* pColorListItem = aSet.GetItem<SvxColorListItem>(SID_COLOR_TABLE, false);
388  const SvxGradientListItem* pGradientListItem = aSet.GetItem<SvxGradientListItem>(SID_GRADIENT_LIST, false);
389  const SvxHatchListItem* pHatchingListItem = aSet.GetItem<SvxHatchListItem>(SID_HATCH_LIST, false);
390  const SvxBitmapListItem* pBitmapListItem = aSet.GetItem<SvxBitmapListItem>(SID_BITMAP_LIST, false);
391  const SvxPatternListItem* pPatternListItem = aSet.GetItem<SvxPatternListItem>(SID_PATTERN_LIST, false);
392 
393  if (pColorListItem)
394  SetColorList(pColorListItem->GetColorList());
395  if (pGradientListItem)
396  SetGradientList(pGradientListItem->GetGradientList());
397  if (pHatchingListItem)
398  SetHatchingList(pHatchingListItem->GetHatchList());
399  if (pBitmapListItem)
400  SetBitmapList(pBitmapListItem->GetBitmapList());
401  if (pPatternListItem)
402  SetPatternList(pPatternListItem->GetPatternList());
403 }
404 
405 void SvxAreaTabPage::CreatePage( sal_Int32 nId, SfxTabPage* pTab )
406 {
407  if(nId == SOLID )
408  {
409  auto* pColorTab = static_cast<SvxColorTabPage*>(pTab);
410  pColorTab->SetColorList(m_pColorList);
411  pColorTab->SetColorChgd(m_pnColorListState);
412  pColorTab->Construct();
413  pColorTab->ActivatePage(m_rXFSet);
414  pColorTab->Reset(&m_rXFSet);
415  pColorTab->set_visible(true);
416  }
417  else if(nId == GRADIENT)
418  {
419  auto* pGradientTab = static_cast<SvxGradientTabPage*>(pTab);
420  pGradientTab->SetColorList(m_pColorList);
421  pGradientTab->SetGradientList(m_pGradientList);
422  pGradientTab->SetGrdChgd(m_pnGradientListState);
423  pGradientTab->SetColorChgd(m_pnColorListState);
424  pGradientTab->Construct();
425  pGradientTab->ActivatePage(m_rXFSet);
426  pGradientTab->Reset(&m_rXFSet);
427  pGradientTab->set_visible(true);
428  }
429  else if(nId == HATCH)
430  {
431  auto* pHatchTab = static_cast<SvxHatchTabPage*>(pTab);
432  pHatchTab->SetColorList(m_pColorList);
433  pHatchTab->SetHatchingList(m_pHatchingList);
434  pHatchTab->SetHtchChgd(m_pnHatchingListState);
435  pHatchTab->SetColorChgd(m_pnColorListState);
436  pHatchTab->Construct();
437  pHatchTab->ActivatePage(m_rXFSet);
438  pHatchTab->Reset(&m_rXFSet);
439  pHatchTab->set_visible(true);
440  }
441  else if(nId == BITMAP)
442  {
443  auto* pBitmapTab = static_cast<SvxBitmapTabPage*>(pTab);
444  pBitmapTab->SetBitmapList(m_pBitmapList);
445  pBitmapTab->SetBmpChgd(m_pnBitmapListState);
446  pBitmapTab->Construct();
447  pBitmapTab->ActivatePage(m_rXFSet);
448  pBitmapTab->Reset(&m_rXFSet);
449  pBitmapTab->set_visible(true);
450  }
451  else if(nId == PATTERN)
452  {
453  auto* pPatternTab = static_cast<SvxPatternTabPage*>(pTab);
454  pPatternTab->SetColorList(m_pColorList);
455  pPatternTab->SetPatternList(m_pPatternList);
456  pPatternTab->SetPtrnChgd(m_pnPatternListState);
457  pPatternTab->SetColorChgd(m_pnColorListState);
458  pPatternTab->Construct();
459  pPatternTab->ActivatePage(m_rXFSet);
460  pPatternTab->Reset(&m_rXFSet);
461  pPatternTab->set_visible(true);
462  }
463 }
464 
465 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DeactivateRC DeactivatePage_Impl(SfxItemSet *pSet)
Definition: tparea.cxx:212
void SetBitmapList(const XBitmapListRef &pBmpLst)
Definition: cuitabarea.hxx:559
long Width() const
SOLID
#define XATTR_FILLHATCH
virtual bool FillItemSet(SfxItemSet *) override
Definition: tparea.cxx:255
sal_Int32 GetButtonPos(weld::ToggleButton *pButton)
Definition: cuitabarea.hxx:66
static const sal_uInt16 pAreaRanges[]
Definition: cuitabarea.hxx:210
void Reset_Impl(const SfxItemSet *)
Definition: tparea.cxx:291
void SetGradientList(XGradientListRef const &pGrdLst)
Definition: cuitabarea.hxx:277
bool Set(const SfxItemSet &, bool bDeep=true)
ButtonBox maBox
Definition: cuitabarea.hxx:213
long Height() const
std::unique_ptr< SfxTabPage > m_xFillTabPage
Definition: cuitabarea.hxx:212
std::unique_ptr< weld::ToggleButton > m_xBtnHatch
Definition: cuitabarea.hxx:243
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tparea.cxx:158
#define XATTR_FILLGRADIENT
virtual void Reset(const SfxItemSet *) override
Definition: tparea.cxx:296
XGradientListRef m_pGradientList
Definition: cuitabarea.hxx:216
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:276
#define XATTR_FILLCOLOR
NONE
XBitmapListRef m_pBitmapList
Definition: cuitabarea.hxx:218
void SetExchangeSupport()
IMPL_LINK(SvxAreaTabPage, SelectFillTypeHdl_Impl, weld::ToggleButton &, rButton, void)
Definition: tparea.cxx:358
std::unique_ptr< weld::Container > m_xFillTab
Definition: cuitabarea.hxx:239
GRADIENT
FillType
Definition: tparea.cxx:37
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: tparea.cxx:385
std::unique_ptr< weld::ToggleButton > m_xBtnColor
Definition: cuitabarea.hxx:241
void SetPatternList(XPatternListRef const &pPtrnLst)
Definition: cuitabarea.hxx:282
std::unique_ptr< weld::ToggleButton > m_xBtnGradient
Definition: cuitabarea.hxx:242
ChangeType * m_pnGradientListState
Definition: cuitabarea.hxx:230
ChangeType
void SetColorList(const XColorListRef &pColList)
Definition: tpcolor.cxx:729
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void SetHatchingList(XHatchListRef const &pHtchLst)
Definition: cuitabarea.hxx:279
void SelectButton(weld::ToggleButton *pButton)
Definition: cuitabarea.hxx:74
ChangeType * m_pnBitmapListState
Definition: cuitabarea.hxx:228
void SelectFillType(weld::ToggleButton &rButton, const SfxItemSet *_pSet=nullptr)
Definition: tparea.cxx:368
virtual ~SvxAreaTabPage() override
Definition: tparea.cxx:153
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tparea.cxx:217
XHatchListRef m_pHatchingList
Definition: cuitabarea.hxx:217
#define XATTR_GRADIENTSTEPCOUNT
std::unique_ptr< weld::ToggleButton > m_xBtnNone
Definition: cuitabarea.hxx:240
const XColorListRef & GetColorList() const
std::unique_ptr< weld::ToggleButton > m_xBtnBitmap
Definition: cuitabarea.hxx:244
#define XATTR_FILLSTYLE
void CreatePage(sal_Int32 nId, SfxTabPage *pTab)
Definition: tparea.cxx:405
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpcolor.cxx:265
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpbitmap.cxx:423
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tphatch.cxx:268
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tparea.cxx:332
ChangeType * m_pnPatternListState
Definition: cuitabarea.hxx:229
sal_Int32 GetCurrentButtonPos() const
Definition: cuitabarea.hxx:65
std::unique_ptr< SfxTabPage >(* CreateTabPage)(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:411
SfxOkDialogController * GetDialogController() const
ChangeType * m_pnHatchingListState
Definition: cuitabarea.hxx:231
DeactivateRC
SvxAreaTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tparea.cxx:77
#define XATTR_FILLBITMAP
void AddButton(weld::ToggleButton *pButton)
Definition: cuitabarea.hxx:60
std::unique_ptr< weld::ToggleButton > m_xBtnPattern
Definition: cuitabarea.hxx:245
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tppattern.cxx:235
bool FillItemSet_Impl(SfxItemSet *)
Definition: tparea.cxx:250
void SetBitmapList(XBitmapListRef const &pBmpLst)
Definition: cuitabarea.hxx:281
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
sal_Int32 nPos
XPatternListRef m_pPatternList
Definition: cuitabarea.hxx:219
XColorListRef m_pColorList
Definition: cuitabarea.hxx:215
void setWidth(long nWidth)
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:615
void SetOptimalSize(weld::DialogController *pController)
Definition: tparea.cxx:114
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:479
#define XATTR_FILLBACKGROUND
ChangeType * m_pnColorListState
Definition: cuitabarea.hxx:227
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpgradnt.cxx:229
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:234
void setHeight(long nHeight)