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