LibreOffice Module cui (master)  1
backgrnd.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 <memory>
21 #include <sfx2/objsh.hxx>
22 #include <svx/svxids.hrc>
23 #include <editeng/colritem.hxx>
24 #include <backgrnd.hxx>
25 #include <svx/drawitem.hxx>
26 #include <svx/xfillit0.hxx>
27 #include <svx/xflclit.hxx>
28 #include <svx/flagsdef.hxx>
29 #include <svl/intitem.hxx>
31 
32 using namespace css;
33 
34 // table background
35 #define TBL_DEST_CELL 0
36 #define TBL_DEST_ROW 1
37 #define TBL_DEST_TBL 2
38 
39 const sal_uInt16 SvxBkgTabPage::pPageRanges[] =
40 {
41  SID_ATTR_BRUSH, SID_ATTR_BRUSH,
42  SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR,
43  0
44 };
45 
46 static sal_uInt16 lcl_GetTableDestSlot(sal_Int32 nTblDest)
47 {
48  switch (nTblDest)
49  {
50  default:
51  case TBL_DEST_CELL:
52  {
53  return SID_ATTR_BRUSH;
54  }
55  case TBL_DEST_ROW:
56  {
57  return SID_ATTR_BRUSH_ROW;
58  }
59  case TBL_DEST_TBL:
60  {
61  return SID_ATTR_BRUSH_TABLE;
62  }
63  }
64 }
65 
67  : SvxAreaTabPage(pPage, pController, rInAttrs),
68  bHighlighting(false),
69  bCharBackColor(false),
70  maSet(rInAttrs)
71 {
72  m_xBtnGradient->hide();
73  m_xBtnHatch->hide();
74  m_xBtnBitmap->hide();
75  m_xBtnPattern->hide();
76 
78 
79  XColorListRef pColorTable;
80  if ( pDocSh )
81  if (auto pItem = pDocSh->GetItem( SID_COLOR_TABLE ))
82  pColorTable = pItem->GetColorList();
83 
84  if ( !pColorTable.is() )
85  pColorTable = XColorList::CreateStdColorList();
86 
87  XBitmapListRef pBitmapList;
88  if ( pDocSh )
89  if (auto pItem = pDocSh->GetItem( SID_BITMAP_LIST ) )
90  pBitmapList = pItem->GetBitmapList();
91 
92  SetColorList(pColorTable);
93  SetBitmapList(pBitmapList);
94 }
95 
97 {
98  m_xTblLBox.reset();
99 }
100 
102 {
104 }
105 
107 {
108  if ( DeactivateRC::KeepPage == SvxAreaTabPage::DeactivatePage( &maSet ) )
109  return DeactivateRC::KeepPage;
110 
111  if ( _pSet )
112  FillItemSet( _pSet );
113 
114  return DeactivateRC::LeavePage;
115 }
116 
118 {
119  maSet.Set( *m_pResetSet );
120  if ( m_xTblLBox && m_xTblLBox->get_visible() )
121  {
122  m_nActPos = -1;
123  const SfxPoolItem* pItem;
124  if ( SfxItemState::SET == m_pResetSet->GetItemState( SID_BACKGRND_DESTINATION, false, &pItem ) )
125  {
126  sal_uInt16 nDestValue = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
127  m_xTblLBox->set_active( nDestValue );
128  TblDestinationHdl_Impl( *m_xTblLBox );
129  }
130  m_xTblLBox->save_value();
131  }
133 }
134 
136 {
137  sal_uInt16 nSlot = SID_ATTR_BRUSH;
138  if (m_xTblLBox && m_xTblLBox->get_visible())
139  nSlot = lcl_GetTableDestSlot(m_xTblLBox->get_active());
140  else if ( bHighlighting )
141  nSlot = SID_ATTR_BRUSH_CHAR;
142  else if( bCharBackColor )
143  nSlot = SID_ATTR_CHAR_BACK_COLOR;
144 
145  sal_uInt16 nWhich = GetWhich(nSlot);
146 
147  drawing::FillStyle eFillType = maSet.Get( XATTR_FILLSTYLE ).GetValue();
148  switch( eFillType )
149  {
150  case drawing::FillStyle_NONE:
151  {
152  if ( IsBtnClicked() )
153  {
154  if ( SID_ATTR_CHAR_BACK_COLOR == nSlot )
155  {
157  rCoreSet->Put( SvxBackgroundColorItem( COL_TRANSPARENT, nWhich ) );
158  }
159  else
160  {
161  maSet.Put( SvxBrushItem( COL_TRANSPARENT, nWhich ) );
162  rCoreSet->Put( SvxBrushItem( COL_TRANSPARENT, nWhich ) );
163  }
164  }
165  break;
166  }
167  case drawing::FillStyle_SOLID:
168  {
169  XFillColorItem aColorItem( maSet.Get( XATTR_FILLCOLOR ) );
170  if ( SID_ATTR_CHAR_BACK_COLOR == nSlot )
171  {
172  maSet.Put( SvxBackgroundColorItem( aColorItem.GetColorValue(), nWhich ) );
173  rCoreSet->Put( SvxBackgroundColorItem( aColorItem.GetColorValue(), nWhich ) );
174  }
175  else
176  {
177  maSet.Put( SvxBrushItem( aColorItem.GetColorValue(), nWhich ) );
178  rCoreSet->Put( SvxBrushItem( aColorItem.GetColorValue(), nWhich ) );
179  }
180  break;
181  }
182  case drawing::FillStyle_BITMAP:
183  {
184  std::unique_ptr<SvxBrushItem> aBrushItem( getSvxBrushItemFromSourceSet( maSet, nWhich ) );
185  if ( GraphicType::NONE != aBrushItem->GetGraphicObject()->GetType() )
186  rCoreSet->Put( *aBrushItem );
187  break;
188  }
189  default:
190  break;
191  }
192 
193  if (m_xTblLBox && m_xTblLBox->get_visible())
194  {
195  if (nSlot != SID_ATTR_BRUSH)
196  {
197  nWhich = maSet.GetPool()->GetWhich(SID_ATTR_BRUSH);
198  if (SfxItemState::SET == maSet.GetItemState(nWhich))
199  {
200  SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
201  rCoreSet->Put(aBrushItem);
202  }
203  }
204  if (nSlot != SID_ATTR_BRUSH_ROW)
205  {
206  nWhich = maSet.GetPool()->GetWhich(SID_ATTR_BRUSH_ROW);
207  if (SfxItemState::SET == maSet.GetItemState(nWhich))
208  {
209  SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
210  rCoreSet->Put(aBrushItem);
211  }
212  }
213  if (nSlot != SID_ATTR_BRUSH_TABLE)
214  {
215  nWhich = maSet.GetPool()->GetWhich(SID_ATTR_BRUSH_TABLE);
216  if (SfxItemState::SET == maSet.GetItemState(nWhich))
217  {
218  SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
219  rCoreSet->Put(aBrushItem);
220  }
221  }
222 
223  if (m_xTblLBox->get_value_changed_from_saved())
224  {
225  rCoreSet->Put(SfxUInt16Item(SID_BACKGRND_DESTINATION, m_xTblLBox->get_active()));
226  }
227  }
228 
229  return true;
230 }
231 
232 std::unique_ptr<SfxTabPage> SvxBkgTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
233 {
234  auto xRet = std::make_unique<SvxBkgTabPage>(pPage, pController, *rAttrs);
235  xRet->SetOptimalSize(pController);
236  return xRet;
237 }
238 
240 {
241  const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_FLAG_TYPE, false);
242  if (pFlagItem)
243  {
244  SvxBackgroundTabFlags nFlags = static_cast<SvxBackgroundTabFlags>(pFlagItem->GetValue());
245  if ( nFlags & SvxBackgroundTabFlags::SHOW_TBLCTL )
246  {
247  m_xBtnBitmap->show();
248  m_xTblLBox = m_xBuilder->weld_combo_box("tablelb");
249  m_xTblLBox->connect_changed(LINK(this, SvxBkgTabPage, TblDestinationHdl_Impl));
250  m_xTblLBox->show();
251  }
252  if ((nFlags & SvxBackgroundTabFlags::SHOW_HIGHLIGHTING) ||
253  (nFlags & SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR))
254  {
255  bHighlighting = bool(nFlags & SvxBackgroundTabFlags::SHOW_HIGHLIGHTING);
256  bCharBackColor = bool(nFlags & SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR);
257  }
258  if (nFlags & SvxBackgroundTabFlags::SHOW_SELECTOR)
259  m_xBtnBitmap->show();
261  }
262 
263  if ( bCharBackColor )
264  {
265  sal_uInt16 nWhich(maSet.GetPool()->GetWhich(SID_ATTR_CHAR_BACK_COLOR));
266  Color aBackColor(static_cast<const SvxBackgroundColorItem&>(maSet.Get(nWhich)).GetValue());
267  SvxBrushItem aBrushItem(SvxBrushItem(aBackColor, SID_ATTR_BRUSH_CHAR));
269  }
270  else
271  {
272  sal_uInt16 nWhich(maSet.GetPool()->GetWhich(bHighlighting ? SID_ATTR_BRUSH_CHAR : SID_ATTR_BRUSH));
273  SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
275  }
276 
277  m_pResetSet = maSet.Clone();
278 
280 }
281 
282 IMPL_LINK(SvxBkgTabPage, TblDestinationHdl_Impl, weld::ComboBox&, rBox, void)
283 {
284  if (m_nActPos > -1)
285  {
286  // fill local item set with XATTR_FILL settings gathered from tab page
287  // and convert to SvxBrushItem and store in table destination slot Which
289  maSet.Put(*getSvxBrushItemFromSourceSet(maSet, maSet.GetPool()->GetWhich(lcl_GetTableDestSlot(m_nActPos))));
290  }
291 
292  sal_Int32 nSelPos = rBox.get_active();
293  if (m_nActPos == nSelPos)
294  return;
295 
296  m_nActPos = nSelPos;
297 
298  // fill local item set with XATTR_FILL created from SvxBushItem for table destination slot Which
299  sal_uInt16 nWhich = maSet.GetPool()->GetWhich(lcl_GetTableDestSlot(nSelPos));
300  if (SfxItemState::SET == maSet.GetItemState(nWhich))
301  {
302  SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
304  }
305  else
306  {
307  SelectFillType(*m_xBtnNone, &maSet);
308  return;
309  }
310 
311  // show tab page
312  drawing::FillStyle eXFS = drawing::FillStyle_NONE;
313  if (maSet.GetItemState(XATTR_FILLSTYLE) != SfxItemState::DONTCARE)
314  {
315  XFillStyleItem aFillStyleItem(static_cast<const XFillStyleItem&>(maSet.Get(GetWhich( XATTR_FILLSTYLE))));
316  eXFS = aFillStyleItem.GetValue();
317  }
318  switch(eXFS)
319  {
320  default:
321  case drawing::FillStyle_NONE:
322  {
323  SelectFillType(*m_xBtnNone, &maSet);
324  break;
325  }
326  case drawing::FillStyle_SOLID:
327  {
328  SelectFillType(*m_xBtnColor, &maSet);
329  // color tab page Active and New preview controls are same after SelectFillType
330  // hack to restore color tab page Active preview
331  setSvxBrushItemAsFillAttributesToTargetSet(static_cast<const SvxBrushItem&>(m_pResetSet->Get(nWhich)), *m_pResetSet);
332  static_cast<SvxColorTabPage*>(GetFillTabPage())->SetCtlPreviewOld(*m_pResetSet);
333  break;
334  }
335  case drawing::FillStyle_BITMAP:
336  {
337  SelectFillType(*m_xBtnBitmap, &maSet);
338  break;
339  }
340  }
341 }
342 
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: backgrnd.cxx:106
std::unique_ptr< weld::ComboBox > m_xTblLBox
Definition: backgrnd.hxx:42
sal_Int32 m_nActPos
Definition: backgrnd.hxx:48
virtual bool FillItemSet(SfxItemSet *) override
Definition: tparea.cxx:255
bool Set(const SfxItemSet &, bool bDeep=true)
bool bCharBackColor
Definition: backgrnd.hxx:44
std::string GetValue
std::unique_ptr< SvxBrushItem > getSvxBrushItemFromSourceSet(const SfxItemSet &rSourceSet, sal_uInt16 nBackgroundID, bool bSearchInParents, bool bXMLImportHack)
static XColorListRef CreateStdColorList()
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
std::unique_ptr< weld::ToggleButton > m_xBtnHatch
Definition: cuitabarea.hxx:241
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tparea.cxx:158
virtual void Reset(const SfxItemSet *) override
Definition: tparea.cxx:296
static SfxObjectShell * Current()
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:274
IMPL_LINK(SvxBkgTabPage, TblDestinationHdl_Impl, weld::ComboBox &, rBox, void)
Definition: backgrnd.cxx:282
bool bHighlighting
Definition: backgrnd.hxx:43
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: backgrnd.cxx:239
SvxBackgroundTabFlags
SvxBkgTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: backgrnd.cxx:66
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: tparea.cxx:385
bool IsBtnClicked() const
Definition: cuitabarea.hxx:250
std::unique_ptr< weld::ToggleButton > m_xBtnGradient
Definition: cuitabarea.hxx:240
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
virtual bool FillItemSet(SfxItemSet *) override
Definition: backgrnd.cxx:135
SfxItemSet maSet
Definition: backgrnd.hxx:45
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tparea.cxx:217
void setSvxBrushItemAsFillAttributesToTargetSet(const SvxBrushItem &rBrush, SfxItemSet &rToSet)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: backgrnd.cxx:232
std::unique_ptr< weld::ToggleButton > m_xBtnBitmap
Definition: cuitabarea.hxx:242
SfxItemPool * GetPool() const
#define TBL_DEST_ROW
Definition: backgrnd.cxx:36
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
#define TBL_DEST_CELL
Definition: backgrnd.cxx:35
virtual void ActivatePage(const SfxItemSet &) override
Definition: backgrnd.cxx:101
class SvxBackgroundTabPage -----------------------------------------—
Definition: backgrnd.hxx:38
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
#define GetWhich(nSlot)
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
virtual ~SvxBkgTabPage() override
Definition: backgrnd.cxx:96
virtual void Reset(const SfxItemSet *) override
Definition: backgrnd.cxx:117
SfxOkDialogController * GetDialogController() const
DeactivateRC
sal_uInt32 GetValue() const
static const sal_uInt16 pPageRanges[]
Definition: backgrnd.hxx:40
std::unique_ptr< weld::ToggleButton > m_xBtnPattern
Definition: cuitabarea.hxx:243
static sal_uInt16 lcl_GetTableDestSlot(sal_Int32 nTblDest)
Definition: backgrnd.cxx:46
std::unique_ptr< SfxItemSet > m_pResetSet
Definition: backgrnd.hxx:46
void SetBitmapList(XBitmapListRef const &pBmpLst)
Definition: cuitabarea.hxx:279
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
#define TBL_DEST_TBL
Definition: backgrnd.cxx:37
void SetOptimalSize(weld::DialogController *pController)
Definition: tparea.cxx:114
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const