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
32using 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
44static 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{
118 if ( m_xTblLBox && m_xTblLBox->get_visible() )
119 {
120 m_nActPos = -1;
121 if ( const SfxUInt16Item* pDestItem = m_pResetSet->GetItemIfSet( SID_BACKGRND_DESTINATION, false ) )
122 {
123 sal_uInt16 nDestValue = pDestItem->GetValue();
124 m_xTblLBox->set_active( nDestValue );
125 TblDestinationHdl_Impl( *m_xTblLBox );
126 }
127 m_xTblLBox->save_value();
128 }
130}
131
133{
134 sal_uInt16 nSlot = SID_ATTR_BRUSH;
135 if (m_xTblLBox && m_xTblLBox->get_visible())
136 nSlot = lcl_GetTableDestSlot(m_xTblLBox->get_active());
137 else if ( bHighlighting )
138 nSlot = SID_ATTR_BRUSH_CHAR;
139 else if( bCharBackColor )
140 nSlot = SID_ATTR_CHAR_BACK_COLOR;
141
142 sal_uInt16 nWhich = GetWhich(nSlot);
143
144 drawing::FillStyle eFillType = maSet.Get( XATTR_FILLSTYLE ).GetValue();
145 switch( eFillType )
146 {
147 case drawing::FillStyle_NONE:
148 {
149 if ( IsBtnClicked() )
150 {
151 if ( SID_ATTR_CHAR_BACK_COLOR == nSlot )
152 {
154 rCoreSet->Put( SvxColorItem( COL_TRANSPARENT, nWhich ) );
155 }
156 else
157 {
159 rCoreSet->Put( SvxBrushItem( COL_TRANSPARENT, nWhich ) );
160 }
161 }
162 break;
163 }
164 case drawing::FillStyle_SOLID:
165 {
166 XFillColorItem aColorItem( maSet.Get( XATTR_FILLCOLOR ) );
167 if ( SID_ATTR_CHAR_BACK_COLOR == nSlot )
168 {
169 maSet.Put( SvxColorItem( aColorItem.GetColorValue(), nWhich ) );
170 rCoreSet->Put( SvxColorItem( aColorItem.GetColorValue(), nWhich ) );
171 }
172 else
173 {
174 maSet.Put( SvxBrushItem( aColorItem.GetColorValue(), nWhich ) );
175 rCoreSet->Put( SvxBrushItem( aColorItem.GetColorValue(), nWhich ) );
176 }
177 break;
178 }
179 case drawing::FillStyle_BITMAP:
180 {
181 std::unique_ptr<SvxBrushItem> aBrushItem( getSvxBrushItemFromSourceSet( maSet, nWhich ) );
182 if ( GraphicType::NONE != aBrushItem->GetGraphicObject()->GetType() )
183 rCoreSet->Put( std::move(aBrushItem) );
184 break;
185 }
186 default:
187 break;
188 }
189
190 if (!m_xTblLBox || !m_xTblLBox->get_visible())
191 return true;
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 if (SfxItemState::SET == maSet.GetItemState(SID_ATTR_BRUSH_ROW))
205 {
206 SvxBrushItem aBrushItem(maSet.Get(SID_ATTR_BRUSH_ROW));
207 rCoreSet->Put(aBrushItem);
208 }
209 }
210 if (nSlot != SID_ATTR_BRUSH_TABLE)
211 {
212 if (SfxItemState::SET == maSet.GetItemState(SID_ATTR_BRUSH_TABLE))
213 {
214 SvxBrushItem aBrushItem(maSet.Get(SID_ATTR_BRUSH_TABLE));
215 rCoreSet->Put(aBrushItem);
216 }
217 }
218
219 if (m_xTblLBox->get_value_changed_from_saved())
220 {
221 rCoreSet->Put(SfxUInt16Item(SID_BACKGRND_DESTINATION, m_xTblLBox->get_active()));
222 }
223
224 return true;
225}
226
227std::unique_ptr<SfxTabPage> SvxBkgTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
228{
229 auto xRet = std::make_unique<SvxBkgTabPage>(pPage, pController, *rAttrs);
230 xRet->SetOptimalSize(pController);
231 return xRet;
232}
233
235{
236 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_FLAG_TYPE, false);
237 if (pFlagItem)
238 {
239 SvxBackgroundTabFlags nFlags = static_cast<SvxBackgroundTabFlags>(pFlagItem->GetValue());
240 if ( nFlags & SvxBackgroundTabFlags::SHOW_TBLCTL )
241 {
242 m_xBtnBitmap->show();
243 m_xTblLBox = m_xBuilder->weld_combo_box("tablelb");
244 m_xTblLBox->connect_changed(LINK(this, SvxBkgTabPage, TblDestinationHdl_Impl));
245 m_xTblLBox->show();
246 }
247 if ((nFlags & SvxBackgroundTabFlags::SHOW_HIGHLIGHTING) ||
248 (nFlags & SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR))
249 {
250 bHighlighting = bool(nFlags & SvxBackgroundTabFlags::SHOW_HIGHLIGHTING);
251 bCharBackColor = bool(nFlags & SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR);
252 }
253 if (nFlags & SvxBackgroundTabFlags::SHOW_SELECTOR)
254 m_xBtnBitmap->show();
256 }
257
258 if ( bCharBackColor )
259 {
260 sal_uInt16 nWhich(maSet.GetPool()->GetWhich(SID_ATTR_CHAR_BACK_COLOR));
261 Color aBackColor(static_cast<const SvxColorItem&>(maSet.Get(nWhich)).GetValue());
262 SvxBrushItem aBrushItem(SvxBrushItem(aBackColor, SID_ATTR_BRUSH_CHAR));
264 }
265 else
266 {
267 sal_uInt16 nWhich(maSet.GetPool()->GetWhich(bHighlighting ? SID_ATTR_BRUSH_CHAR : SID_ATTR_BRUSH));
268 SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
270 }
271
273
275}
276
277IMPL_LINK(SvxBkgTabPage, TblDestinationHdl_Impl, weld::ComboBox&, rBox, void)
278{
279 if (m_nActPos > -1)
280 {
281 // fill local item set with XATTR_FILL settings gathered from tab page
282 // and convert to SvxBrushItem and store in table destination slot Which
284 maSet.Put(getSvxBrushItemFromSourceSet(maSet, maSet.GetPool()->GetWhich(lcl_GetTableDestSlot(m_nActPos))));
285 }
286
287 sal_Int32 nSelPos = rBox.get_active();
288 if (m_nActPos == nSelPos)
289 return;
290
291 m_nActPos = nSelPos;
292
293 // fill local item set with XATTR_FILL created from SvxBushItem for table destination slot Which
294 sal_uInt16 nWhich = maSet.GetPool()->GetWhich(lcl_GetTableDestSlot(nSelPos));
295 if (SfxItemState::SET == maSet.GetItemState(nWhich))
296 {
297 SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
299 }
300 else
301 {
302 SelectFillType(*m_xBtnNone, &maSet);
303 return;
304 }
305
306 // show tab page
307 drawing::FillStyle eXFS = drawing::FillStyle_NONE;
308 if (maSet.GetItemState(XATTR_FILLSTYLE) != SfxItemState::DONTCARE)
309 {
310 XFillStyleItem aFillStyleItem(maSet.Get(GetWhich( XATTR_FILLSTYLE)));
311 eXFS = aFillStyleItem.GetValue();
312 }
313 switch(eXFS)
314 {
315 default:
316 case drawing::FillStyle_NONE:
317 {
318 SelectFillType(*m_xBtnNone, &maSet);
319 break;
320 }
321 case drawing::FillStyle_SOLID:
322 {
323 SelectFillType(*m_xBtnColor, &maSet);
324 // color tab page Active and New preview controls are same after SelectFillType
325 // hack to restore color tab page Active preview
326 setSvxBrushItemAsFillAttributesToTargetSet(static_cast<const SvxBrushItem&>(m_pResetSet->Get(nWhich)), *m_pResetSet);
327 static_cast<SvxColorTabPage*>(GetFillTabPage())->SetCtlPreviewOld(*m_pResetSet);
328 break;
329 }
330 case drawing::FillStyle_BITMAP:
331 {
332 SelectFillType(*m_xBtnBitmap, &maSet);
333 break;
334 }
335 }
336}
337
338/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define TBL_DEST_CELL
Definition: backgrnd.cxx:35
#define TBL_DEST_TBL
Definition: backgrnd.cxx:37
#define TBL_DEST_ROW
Definition: backgrnd.cxx:36
IMPL_LINK(SvxBkgTabPage, TblDestinationHdl_Impl, weld::ComboBox &, rBox, void)
Definition: backgrnd.cxx:277
static sal_uInt16 lcl_GetTableDestSlot(sal_Int32 nTblDest)
Definition: backgrnd.cxx:44
#define GetWhich(nSlot)
sal_uInt32 GetValue() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
SfxItemPool * GetPool() const
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
bool Set(const SfxItemSet &, bool bDeep=true)
static SfxObjectShell * Current()
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
SfxOkDialogController * GetDialogController() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
std::unique_ptr< weld::Toggleable > m_xBtnPattern
Definition: cuitabarea.hxx:244
virtual bool FillItemSet(SfxItemSet *) override
Definition: tparea.cxx:282
std::unique_ptr< weld::Toggleable > m_xBtnBitmap
Definition: cuitabarea.hxx:243
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tparea.cxx:228
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tparea.cxx:166
std::unique_ptr< weld::Toggleable > m_xBtnHatch
Definition: cuitabarea.hxx:242
void SetBitmapList(XBitmapListRef const &pBmpLst)
Definition: cuitabarea.hxx:285
void SetColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:280
virtual void Reset(const SfxItemSet *) override
Definition: tparea.cxx:330
void SetOptimalSize(weld::DialogController *pController)
Definition: tparea.cxx:122
bool IsBtnClicked() const
Definition: cuitabarea.hxx:252
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: tparea.cxx:430
std::unique_ptr< weld::Toggleable > m_xBtnGradient
Definition: cuitabarea.hxx:241
class SvxBackgroundTabPage -----------------------------------------—
Definition: backgrnd.hxx:39
sal_Int32 m_nActPos
Definition: backgrnd.hxx:48
std::unique_ptr< SfxItemSet > m_pResetSet
Definition: backgrnd.hxx:46
bool bHighlighting
Definition: backgrnd.hxx:43
static const WhichRangesContainer pPageRanges
Definition: backgrnd.hxx:40
SfxItemSet maSet
Definition: backgrnd.hxx:45
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: backgrnd.cxx:234
std::unique_ptr< weld::ComboBox > m_xTblLBox
Definition: backgrnd.hxx:42
SvxBkgTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: backgrnd.cxx:64
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: backgrnd.cxx:104
virtual ~SvxBkgTabPage() override
Definition: backgrnd.cxx:94
virtual bool FillItemSet(SfxItemSet *) override
Definition: backgrnd.cxx:132
virtual void ActivatePage(const SfxItemSet &) override
Definition: backgrnd.cxx:99
bool bCharBackColor
Definition: backgrnd.hxx:44
virtual void Reset(const SfxItemSet *) override
Definition: backgrnd.cxx:115
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: backgrnd.cxx:227
const Color & GetValue() const
const Color & GetColorValue() const
static XColorListRef CreateStdColorList()
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
SvxBackgroundTabFlags
static constexpr auto Items
DeactivateRC
SVXCORE_DLLPUBLIC std::unique_ptr< SvxBrushItem > getSvxBrushItemFromSourceSet(const SfxItemSet &rSourceSet, sal_uInt16 nBackgroundID, bool bSearchInParents=true, bool bXMLImportHack=false)
SVXCORE_DLLPUBLIC void setSvxBrushItemAsFillAttributesToTargetSet(const SvxBrushItem &rBrush, SfxItemSet &rToSet)
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)