android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / tabpages / backgrnd.cxx
blob5706f98c310a2e734de3239895ab0c0b075c163f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
30 #include <svx/unobrushitemhelper.hxx>
32 using namespace css;
34 // table background
35 #define TBL_DEST_CELL 0
36 #define TBL_DEST_ROW 1
37 #define TBL_DEST_TBL 2
39 const WhichRangesContainer SvxBkgTabPage::pPageRanges(svl::Items<
40 SID_ATTR_BRUSH, SID_ATTR_BRUSH,
41 SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR
42 >);
44 static sal_uInt16 lcl_GetTableDestSlot(sal_Int32 nTblDest)
46 switch (nTblDest)
48 default:
49 case TBL_DEST_CELL:
51 return SID_ATTR_BRUSH;
53 case TBL_DEST_ROW:
55 return SID_ATTR_BRUSH_ROW;
57 case TBL_DEST_TBL:
59 return SID_ATTR_BRUSH_TABLE;
64 SvxBkgTabPage::SvxBkgTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
65 : SvxAreaTabPage(pPage, pController, rInAttrs),
66 bHighlighting(false),
67 bCharBackColor(false),
68 maSet(rInAttrs)
70 m_xBtnGradient->hide();
71 m_xBtnHatch->hide();
72 m_xBtnBitmap->hide();
73 m_xBtnPattern->hide();
75 SfxObjectShell* pDocSh = SfxObjectShell::Current();
77 XColorListRef pColorTable;
78 if ( pDocSh )
79 if (auto pItem = pDocSh->GetItem( SID_COLOR_TABLE ))
80 pColorTable = pItem->GetColorList();
82 if ( !pColorTable.is() )
83 pColorTable = XColorList::CreateStdColorList();
85 XBitmapListRef pBitmapList;
86 if ( pDocSh )
87 if (auto pItem = pDocSh->GetItem( SID_BITMAP_LIST ) )
88 pBitmapList = pItem->GetBitmapList();
90 SetColorList(pColorTable);
91 SetBitmapList(pBitmapList);
94 SvxBkgTabPage::~SvxBkgTabPage()
96 m_xTblLBox.reset();
99 void SvxBkgTabPage::ActivatePage( const SfxItemSet& )
101 SvxAreaTabPage::ActivatePage( maSet );
104 DeactivateRC SvxBkgTabPage::DeactivatePage( SfxItemSet* _pSet )
106 if ( DeactivateRC::KeepPage == SvxAreaTabPage::DeactivatePage( &maSet ) )
107 return DeactivateRC::KeepPage;
109 if ( _pSet )
110 FillItemSet( _pSet );
112 return DeactivateRC::LeavePage;
115 void SvxBkgTabPage::Reset( const SfxItemSet* )
117 maSet.Set( *m_pResetSet );
118 if ( m_xTblLBox && m_xTblLBox->get_visible() )
120 m_nActPos = -1;
121 if ( const SfxUInt16Item* pDestItem = m_pResetSet->GetItemIfSet( SID_BACKGRND_DESTINATION, false ) )
123 sal_uInt16 nDestValue = pDestItem->GetValue();
124 m_xTblLBox->set_active( nDestValue );
125 TblDestinationHdl_Impl( *m_xTblLBox );
127 m_xTblLBox->save_value();
129 SvxAreaTabPage::Reset( &maSet );
132 bool SvxBkgTabPage::FillItemSet( SfxItemSet* rCoreSet )
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;
142 sal_uInt16 nWhich = GetWhich(nSlot);
144 drawing::FillStyle eFillType = maSet.Get( XATTR_FILLSTYLE ).GetValue();
145 switch( eFillType )
147 case drawing::FillStyle_NONE:
149 if ( IsBtnClicked() )
151 if ( SID_ATTR_CHAR_BACK_COLOR == nSlot )
153 maSet.Put( SvxColorItem( COL_TRANSPARENT, nWhich ) );
154 rCoreSet->Put( SvxColorItem( COL_TRANSPARENT, nWhich ) );
156 else
158 maSet.Put( SvxBrushItem( COL_TRANSPARENT, nWhich ) );
159 rCoreSet->Put( SvxBrushItem( COL_TRANSPARENT, nWhich ) );
162 break;
164 case drawing::FillStyle_SOLID:
166 XFillColorItem aColorItem( maSet.Get( XATTR_FILLCOLOR ) );
167 if ( SID_ATTR_CHAR_BACK_COLOR == nSlot )
169 maSet.Put( SvxColorItem( aColorItem.GetColorValue(), aColorItem.getComplexColor(), nWhich ) );
170 rCoreSet->Put( SvxColorItem( aColorItem.GetColorValue(), aColorItem.getComplexColor(), nWhich ) );
172 else
174 maSet.Put( SvxBrushItem( aColorItem.GetColorValue(), aColorItem.getComplexColor(), nWhich ) );
175 rCoreSet->Put( SvxBrushItem( aColorItem.GetColorValue(), aColorItem.getComplexColor(), nWhich ) );
177 break;
179 case drawing::FillStyle_BITMAP:
181 std::unique_ptr<SvxBrushItem> aBrushItem( getSvxBrushItemFromSourceSet( maSet, nWhich ) );
182 if ( GraphicType::NONE != aBrushItem->GetGraphicObject()->GetType() )
183 rCoreSet->Put( std::move(aBrushItem) );
184 break;
186 default:
187 break;
190 if (!m_xTblLBox || !m_xTblLBox->get_visible())
191 return true;
193 if (nSlot != SID_ATTR_BRUSH)
195 nWhich = maSet.GetPool()->GetWhich(SID_ATTR_BRUSH);
196 if (SfxItemState::SET == maSet.GetItemState(nWhich))
198 SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
199 rCoreSet->Put(aBrushItem);
202 if (nSlot != SID_ATTR_BRUSH_ROW)
204 if (SfxItemState::SET == maSet.GetItemState(SID_ATTR_BRUSH_ROW))
206 SvxBrushItem aBrushItem(maSet.Get(SID_ATTR_BRUSH_ROW));
207 rCoreSet->Put(aBrushItem);
210 if (nSlot != SID_ATTR_BRUSH_TABLE)
212 if (SfxItemState::SET == maSet.GetItemState(SID_ATTR_BRUSH_TABLE))
214 SvxBrushItem aBrushItem(maSet.Get(SID_ATTR_BRUSH_TABLE));
215 rCoreSet->Put(aBrushItem);
219 if (m_xTblLBox->get_value_changed_from_saved())
221 rCoreSet->Put(SfxUInt16Item(SID_BACKGRND_DESTINATION, m_xTblLBox->get_active()));
224 return true;
227 std::unique_ptr<SfxTabPage> SvxBkgTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
229 auto xRet = std::make_unique<SvxBkgTabPage>(pPage, pController, *rAttrs);
230 xRet->SetOptimalSize(pController);
231 return xRet;
234 void SvxBkgTabPage::PageCreated(const SfxAllItemSet& aSet)
236 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_FLAG_TYPE, false);
237 if (pFlagItem)
239 SvxBackgroundTabFlags nFlags = static_cast<SvxBackgroundTabFlags>(pFlagItem->GetValue());
240 if ( nFlags & SvxBackgroundTabFlags::SHOW_TBLCTL )
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();
247 if ((nFlags & SvxBackgroundTabFlags::SHOW_HIGHLIGHTING) ||
248 (nFlags & SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR))
250 bHighlighting = bool(nFlags & SvxBackgroundTabFlags::SHOW_HIGHLIGHTING);
251 bCharBackColor = bool(nFlags & SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR);
253 if (nFlags & SvxBackgroundTabFlags::SHOW_SELECTOR)
254 m_xBtnBitmap->show();
255 SetOptimalSize(GetDialogController());
258 if ( bCharBackColor )
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));
263 setSvxBrushItemAsFillAttributesToTargetSet(aBrushItem, maSet);
265 else
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)));
269 setSvxBrushItemAsFillAttributesToTargetSet(aBrushItem, maSet);
272 m_pResetSet = maSet.Clone();
274 SvxAreaTabPage::PageCreated(aSet);
277 IMPL_LINK(SvxBkgTabPage, TblDestinationHdl_Impl, weld::ComboBox&, rBox, void)
279 if (m_nActPos > -1)
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
283 SvxAreaTabPage::FillItemSet(&maSet);
284 maSet.Put(getSvxBrushItemFromSourceSet(maSet, maSet.GetPool()->GetWhich(lcl_GetTableDestSlot(m_nActPos))));
287 sal_Int32 nSelPos = rBox.get_active();
288 if (m_nActPos == nSelPos)
289 return;
291 m_nActPos = nSelPos;
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))
297 SvxBrushItem aBrushItem(static_cast<const SvxBrushItem&>(maSet.Get(nWhich)));
298 setSvxBrushItemAsFillAttributesToTargetSet(aBrushItem, maSet);
300 else
302 SelectFillType(*m_xBtnNone, &maSet);
303 return;
306 // show tab page
307 drawing::FillStyle eXFS = drawing::FillStyle_NONE;
308 if (maSet.GetItemState(XATTR_FILLSTYLE) != SfxItemState::DONTCARE)
310 XFillStyleItem aFillStyleItem(maSet.Get(GetWhich( XATTR_FILLSTYLE)));
311 eXFS = aFillStyleItem.GetValue();
313 switch(eXFS)
315 default:
316 case drawing::FillStyle_NONE:
318 SelectFillType(*m_xBtnNone, &maSet);
319 break;
321 case drawing::FillStyle_SOLID:
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;
330 case drawing::FillStyle_BITMAP:
332 SelectFillType(*m_xBtnBitmap, &maSet);
333 break;
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */