1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
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
44 static sal_uInt16
lcl_GetTableDestSlot(sal_Int32 nTblDest
)
51 return SID_ATTR_BRUSH
;
55 return SID_ATTR_BRUSH_ROW
;
59 return SID_ATTR_BRUSH_TABLE
;
64 SvxBkgTabPage::SvxBkgTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
65 : SvxAreaTabPage(pPage
, pController
, rInAttrs
),
67 bCharBackColor(false),
70 m_xBtnGradient
->hide();
73 m_xBtnPattern
->hide();
75 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
77 XColorListRef pColorTable
;
79 if (auto pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
))
80 pColorTable
= pItem
->GetColorList();
82 if ( !pColorTable
.is() )
83 pColorTable
= XColorList::CreateStdColorList();
85 XBitmapListRef pBitmapList
;
87 if (auto pItem
= pDocSh
->GetItem( SID_BITMAP_LIST
) )
88 pBitmapList
= pItem
->GetBitmapList();
90 SetColorList(pColorTable
);
91 SetBitmapList(pBitmapList
);
94 SvxBkgTabPage::~SvxBkgTabPage()
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
;
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() )
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();
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
) );
158 maSet
.Put( SvxBrushItem( COL_TRANSPARENT
, nWhich
) );
159 rCoreSet
->Put( SvxBrushItem( COL_TRANSPARENT
, nWhich
) );
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
) );
174 maSet
.Put( SvxBrushItem( aColorItem
.GetColorValue(), aColorItem
.getComplexColor(), nWhich
) );
175 rCoreSet
->Put( SvxBrushItem( aColorItem
.GetColorValue(), aColorItem
.getComplexColor(), nWhich
) );
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
) );
190 if (!m_xTblLBox
|| !m_xTblLBox
->get_visible())
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()));
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
);
234 void SvxBkgTabPage::PageCreated(const SfxAllItemSet
& aSet
)
236 const SfxUInt32Item
* pFlagItem
= aSet
.GetItem
<SfxUInt32Item
>(SID_FLAG_TYPE
, false);
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
));
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
);
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)
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
)
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
);
302 SelectFillType(*m_xBtnNone
, &maSet
);
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();
316 case drawing::FillStyle_NONE
:
318 SelectFillType(*m_xBtnNone
, &maSet
);
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
);
330 case drawing::FillStyle_BITMAP
:
332 SelectFillType(*m_xBtnBitmap
, &maSet
);
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */