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 <com/sun/star/drawing/FillStyle.hpp>
22 #include <vcl/settings.hxx>
23 #include <vcl/graphicfilter.hxx>
24 #include <vcl/idle.hxx>
25 #include <vcl/svapp.hxx>
26 #include <tools/urlobj.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <svx/svxids.hrc>
29 #include <svx/strings.hrc>
31 #include <strings.hrc>
32 #include <svx/dialmgr.hxx>
34 #include <editeng/brushitem.hxx>
35 #include <editeng/colritem.hxx>
36 #include <backgrnd.hxx>
38 #include <svx/xtable.hxx>
39 #include <sfx2/opengrf.hxx>
40 #include <svx/svxerr.hxx>
41 #include <svx/drawitem.hxx>
42 #include <svx/xfillit0.hxx>
43 #include <svx/xflclit.hxx>
44 #include <dialmgr.hxx>
45 #include <sfx2/htmlmode.hxx>
46 #include <svx/flagsdef.hxx>
47 #include <svl/intitem.hxx>
48 #include <vcl/GraphicObject.hxx>
50 #include <svx/unobrushitemhelper.hxx>
55 #define TBL_DEST_CELL 0
56 #define TBL_DEST_ROW 1
57 #define TBL_DEST_TBL 2
59 const sal_uInt16
SvxBackgroundTabPage::pPageRanges
[] =
61 SID_ATTR_BRUSH
, SID_ATTR_BRUSH
,
62 SID_ATTR_BRUSH_CHAR
, SID_ATTR_BRUSH_CHAR
,
66 /// Returns the fill style of the currently selected entry.
67 static drawing::FillStyle
lcl_getFillStyle(const weld::ComboBox
& rLbSelect
)
69 return static_cast<drawing::FillStyle
>(rLbSelect
.get_active_id().toUInt32());
72 // Selects the entry matching the specified fill style.
73 static void lcl_setFillStyle(weld::ComboBox
& rLbSelect
, drawing::FillStyle eStyle
)
75 OUString sStyle
= OUString::number(static_cast<sal_uInt32
>(eStyle
));
76 for (int i
= 0; i
< rLbSelect
.get_count(); ++i
)
78 if (rLbSelect
.get_id(i
) == sStyle
)
80 rLbSelect
.set_active(i
);
86 static sal_uInt16
GetItemId_Impl(const SvtValueSet
& rValueSet
, const Color
& rCol
)
89 sal_uInt16 nCount
= rValueSet
.GetItemCount();
92 while ( !bFound
&& n
<= nCount
)
94 Color aValCol
= rValueSet
.GetItemColor(n
);
96 bFound
= ( aValCol
.GetRed() == rCol
.GetRed()
97 && aValCol
.GetGreen() == rCol
.GetGreen()
98 && aValCol
.GetBlue() == rCol
.GetBlue() );
103 return bFound
? n
: 0;
106 /** Preview window for brush or bitmap */
107 class BackgroundPreviewImpl
: public weld::CustomWidgetController
110 explicit BackgroundPreviewImpl();
111 void setBmp(bool bBmp
);
113 void NotifyChange(const Color
& rColor
);
114 void NotifyChange(const BitmapEx
* pBitmap
);
115 void SetFillColor(const Color
& rColor
) { aColor
= rColor
; }
118 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const ::tools::Rectangle
& rRect
) override
;
119 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
120 virtual void Resize() override
;
124 void recalcDrawPos();
127 std::unique_ptr
<BitmapEx
> pBitmap
;
130 ::tools::Rectangle aDrawRect
;
134 BackgroundPreviewImpl::BackgroundPreviewImpl()
136 , aColor(Application::GetSettings().GetStyleSettings().GetFieldColor())
140 void BackgroundPreviewImpl::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
142 CustomWidgetController::SetDrawingArea(pDrawingArea
);
143 Size
aSize(pDrawingArea
->get_ref_device().LogicToPixel(Size(300, 77)));
144 pDrawingArea
->set_size_request(aSize
.Width(), aSize
.Height());
145 aDrawRect
= tools::Rectangle(Point(0,0), aSize
);
146 Invalidate(aDrawRect
);
149 void BackgroundPreviewImpl::setBmp(bool bBmp
)
155 void BackgroundPreviewImpl::NotifyChange( const Color
& rColor
)
159 const static Color
aTranspCol(COL_TRANSPARENT
);
160 SetFillColor(rColor
== aTranspCol
? Application::GetSettings().GetStyleSettings().GetFieldColor() : rColor
.GetRGBColor());
161 Invalidate(aDrawRect
);
165 void BackgroundPreviewImpl::NotifyChange( const BitmapEx
* pNewBitmap
)
167 if (bIsBmp
&& (pNewBitmap
|| pBitmap
))
169 if (pNewBitmap
&& pBitmap
)
170 *pBitmap
= *pNewBitmap
;
171 else if (pNewBitmap
&& !pBitmap
)
172 pBitmap
.reset( new BitmapEx(*pNewBitmap
) );
173 else if (!pNewBitmap
)
178 Invalidate(aDrawRect
);
182 void BackgroundPreviewImpl::recalcDrawPos()
186 Size aSize
= GetOutputSizePixel();
187 // InnerSize == Size without one pixel border
188 Size aInnerSize
= aSize
;
189 aInnerSize
.AdjustWidth( -2 );
190 aInnerSize
.AdjustHeight( -2 );
191 aDrawSize
= pBitmap
->GetSizePixel();
193 // bitmap bigger than preview window?
194 if (aDrawSize
.Width() > aInnerSize
.Width())
196 aDrawSize
.setHeight( aDrawSize
.Height() * aInnerSize
.Width() / aDrawSize
.Width() );
197 if (aDrawSize
.Height() > aInnerSize
.Height())
199 aDrawSize
.setWidth( aDrawSize
.Height() );
200 aDrawSize
.setHeight( aInnerSize
.Height() );
203 aDrawSize
.setWidth( aInnerSize
.Width() );
205 else if (aDrawSize
.Height() > aInnerSize
.Height())
207 aDrawSize
.setWidth( aDrawSize
.Width() * aInnerSize
.Height() / aDrawSize
.Height() );
208 if (aDrawSize
.Width() > aInnerSize
.Width())
210 aDrawSize
.setHeight( aDrawSize
.Width() );
211 aDrawSize
.setWidth( aInnerSize
.Width() );
214 aDrawSize
.setHeight( aInnerSize
.Height() );
217 aDrawPos
.setX( (aSize
.Width() - aDrawSize
.Width()) / 2 );
218 aDrawPos
.setY( (aSize
.Height() - aDrawSize
.Height()) / 2 );
222 void BackgroundPreviewImpl::Resize()
224 CustomWidgetController::Resize();
225 aDrawRect
= tools::Rectangle(Point(0,0), GetOutputSizePixel());
229 void BackgroundPreviewImpl::Paint(vcl::RenderContext
& rRenderContext
, const ::tools::Rectangle
&)
231 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
232 rRenderContext
.SetBackground(Wallpaper(rStyleSettings
.GetWindowColor()));
233 rRenderContext
.SetLineColor();
236 rRenderContext
.SetFillColor(COL_TRANSPARENT
);
238 rRenderContext
.SetFillColor(aColor
);
240 rRenderContext
.DrawRect(aDrawRect
);
245 rRenderContext
.DrawBitmapEx(aDrawPos
, aDrawSize
, *pBitmap
);
248 Size
aSize(GetOutputSizePixel());
249 rRenderContext
.DrawLine(Point(0, 0), Point(aSize
.Width(), aSize
.Height()));
250 rRenderContext
.DrawLine(Point(0, aSize
.Height()), Point(aSize
.Width(), 0));
255 #define HDL(hdl) LINK(this,SvxBackgroundTabPage,hdl)
257 SvxBackgroundTabPage::SvxBackgroundTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rCoreSet
)
258 : SvxTabPage(pPage
, pController
, "cui/ui/backgroundpage.ui", "BackgroundPage", rCoreSet
)
260 , bAllowShowSelector(true)
261 , bIsGraphicValid(false)
262 , bHighlighting(false)
263 , bCharBackColor(false)
264 , m_bColorSelected(false)
265 , m_xWndPosition(new SvxRectCtl(this))
266 , m_xBackgroundColorSet(new ColorValueSet(m_xBuilder
->weld_scrolled_window("backgroundcolorsetwin")))
267 , m_xPreview1(new BackgroundPreviewImpl
)
268 , m_xPreview2(new BackgroundPreviewImpl
)
269 , m_xFindGraphicsFt(m_xBuilder
->weld_label("findgraphicsft"))
270 , m_xAsGrid(m_xBuilder
->weld_widget("asgrid"))
271 , m_xSelectTxt(m_xBuilder
->weld_label("asft"))
272 , m_xLbSelect(m_xBuilder
->weld_combo_box("selectlb"))
273 , m_xTblDesc(m_xBuilder
->weld_label("forft"))
274 , m_xTblLBox(m_xBuilder
->weld_combo_box("tablelb"))
275 , m_xBackGroundColorLabelFT(m_xBuilder
->weld_label("background_label"))
276 , m_xBackGroundColorFrame(m_xBuilder
->weld_widget("backgroundcolorframe"))
277 , m_xBtnPreview(m_xBuilder
->weld_check_button("showpreview"))
278 , m_xBitmapContainer(m_xBuilder
->weld_widget("graphicgrid"))
279 , m_xFileFrame(m_xBuilder
->weld_widget("fileframe"))
280 , m_xBtnBrowse(m_xBuilder
->weld_button("browse"))
281 , m_xBtnLink(m_xBuilder
->weld_check_button("link"))
282 , m_xFtUnlinked(m_xBuilder
->weld_label("unlinkedft"))
283 , m_xFtFile(m_xBuilder
->weld_label("fileft"))
284 , m_xTypeFrame(m_xBuilder
->weld_widget("typeframe"))
285 , m_xBtnPosition(m_xBuilder
->weld_radio_button("positionrb"))
286 , m_xBtnArea(m_xBuilder
->weld_radio_button("arearb"))
287 , m_xBtnTile(m_xBuilder
->weld_radio_button("tilerb"))
288 , m_xWndPositionWin(new weld::CustomWeld(*m_xBuilder
, "windowpos", *m_xWndPosition
))
289 , m_xBackgroundColorSetWin(new weld::CustomWeld(*m_xBuilder
, "backgroundcolorset", *m_xBackgroundColorSet
))
290 , m_xPreviewWin1(new weld::CustomWeld(*m_xBuilder
, "preview1", *m_xPreview1
))
291 , m_xPreviewWin2(new weld::CustomWeld(*m_xBuilder
, "preview2", *m_xPreview2
))
294 m_xPreview2
->setBmp(true);
296 // this page needs ExchangeSupport
297 SetExchangeSupport();
299 const SfxPoolItem
* pItem
;
300 SfxObjectShell
* pShell
;
302 if ( SfxItemState::SET
== rCoreSet
.GetItemState( SID_HTML_MODE
, false, &pItem
)
303 || ( nullptr != ( pShell
= SfxObjectShell::Current()) &&
304 nullptr != ( pItem
= pShell
->GetItem( SID_HTML_MODE
) ) ) )
306 nHtmlMode
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
309 FillColorValueSets_Impl();
311 m_xBackgroundColorSet
->SetSelectHdl(HDL(BackgroundColorHdl_Impl
));
312 m_xBackgroundColorSet
->SetStyle(m_xBackgroundColorSet
->GetStyle() | WB_ITEMBORDER
| WB_NAMEFIELD
| WB_NONEFIELD
);
313 m_xBackgroundColorSet
->SetText(SvxResId(RID_SVXSTR_NOFILL
));
316 SvxBackgroundTabPage::~SvxBackgroundTabPage()
320 m_pCellBrush
.reset();
322 m_pTableBrush
.reset();
323 m_xPreviewWin2
.reset();
324 m_xPreviewWin1
.reset();
325 m_xBackgroundColorSetWin
.reset();
326 m_xWndPositionWin
.reset();
329 m_xBackgroundColorSet
.reset();
330 m_xWndPosition
.reset();
333 std::unique_ptr
<SfxTabPage
> SvxBackgroundTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrSet
)
335 return std::make_unique
<SvxBackgroundTabPage
>(pPage
, pController
, *rAttrSet
);
338 void SvxBackgroundTabPage::Reset( const SfxItemSet
* rSet
)
340 m_bColorSelected
= false;
342 // condition of the preview button is persistent due to UserData
343 OUString aUserData
= GetUserData();
344 m_xBtnPreview
->set_active(!aUserData
.isEmpty() && '1' == aUserData
[0]);
346 // don't be allowed to call ShowSelector() after reset anymore
347 bAllowShowSelector
= false;
350 // get and evaluate Input-BrushItem
351 bool bBrushItemSet
= false;
352 sal_uInt16 nSlot
= SID_ATTR_BRUSH
;
353 const SfxPoolItem
* pItem
;
354 sal_uInt16 nDestValue
= USHRT_MAX
;
356 if ( SfxItemState::SET
== rSet
->GetItemState( SID_BACKGRND_DESTINATION
,
359 nDestValue
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
360 m_xTblLBox
->set_active(nDestValue
);
362 switch ( nDestValue
)
365 nSlot
= SID_ATTR_BRUSH
;
368 nSlot
= SID_ATTR_BRUSH_ROW
;
371 nSlot
= SID_ATTR_BRUSH_TABLE
;
375 else if( bHighlighting
)
377 nSlot
= SID_ATTR_BRUSH_CHAR
;
379 else if( bCharBackColor
)
381 nSlot
= SID_ATTR_CHAR_BACK_COLOR
;
384 //#111173# the destination item is missing when the parent style has been changed
385 if (USHRT_MAX
== nDestValue
&& m_xTblLBox
->get_visible())
387 sal_uInt16 nWhich
= GetWhich(nSlot
);
388 std::shared_ptr
<SvxBrushItem
> aBgdAttr(std::make_shared
<SvxBrushItem
>(nWhich
));
390 if (rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
394 aBgdAttr
.reset(static_cast<SvxBrushItem
*>(rSet
->Get(nWhich
).Clone()));
398 // EE_CHAR_BKGCOLOR is SvxBackgroundColorItem, but char background tabpage
399 // can only work with SvxBrushItems
400 // extract Color out of SvxBackColorItem
401 Color aBackColor
= static_cast<const SvxBackgroundColorItem
&>(rSet
->Get(nWhich
)).GetValue();
402 // make new SvxBrushItem with this Color
403 aBgdAttr
= std::make_shared
<SvxBrushItem
>(aBackColor
, SID_ATTR_BRUSH_CHAR
);
405 bBrushItemSet
= true;
408 m_xBtnTile
->set_active(true);
412 FillControls_Impl(*aBgdAttr
, aUserData
);
413 aBgdColor
= aBgdAttr
->GetColor();
417 m_xSelectTxt
->hide();
419 lcl_setFillStyle(*m_xLbSelect
, drawing::FillStyle_SOLID
);
422 const SfxPoolItem
* pOld
= GetOldItem( *rSet
, SID_ATTR_BRUSH
);
425 aBgdColor
= static_cast<const SvxBrushItem
*>(pOld
)->GetColor();
428 if ( nDestValue
!= USHRT_MAX
)
430 if (m_xTblLBox
->get_visible())
432 m_pCellBrush
.reset();
434 m_pTableBrush
.reset();
435 m_nActPos
= m_xTblLBox
->get_active();
437 nWhich
= GetWhich( SID_ATTR_BRUSH
);
438 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
440 m_pCellBrush
.reset(static_cast<SvxBrushItem
*>(rSet
->Get(nWhich
).Clone()));
442 m_nCellWhich
= nWhich
;
444 if ( rSet
->GetItemState( SID_ATTR_BRUSH_ROW
, false ) >= SfxItemState::DEFAULT
)
446 m_pRowBrush
.reset(static_cast<SvxBrushItem
*>(rSet
->Get(SID_ATTR_BRUSH_ROW
).Clone()));
448 m_nRowWhich
= SID_ATTR_BRUSH_ROW
;
450 if ( rSet
->GetItemState( SID_ATTR_BRUSH_TABLE
, false ) >= SfxItemState::DEFAULT
)
452 m_pTableBrush
.reset(static_cast<SvxBrushItem
*>(rSet
->Get(SID_ATTR_BRUSH_TABLE
).Clone()));
454 m_nTableWhich
= SID_ATTR_BRUSH_TABLE
;
456 TblDestinationHdl_Impl(*m_xTblLBox
);
457 m_xTblLBox
->save_value();
459 else if( bHighlighting
)
461 nWhich
= GetWhich( SID_ATTR_BRUSH_CHAR
);
462 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
464 pHighlighting
.reset(static_cast<SvxBrushItem
*>(rSet
->Get(nWhich
).Clone()));
467 else if( bCharBackColor
)
469 nWhich
= GetWhich(SID_ATTR_CHAR_BACK_COLOR
);
470 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
472 // EE_CHAR_BKGCOLOR is SvxBackgroundColorItem, but char background tabpage
473 // can only work with SvxBrushItems
474 // extract Color out of SvxBackColorItem
475 Color aBackColor
= static_cast<const SvxBackgroundColorItem
&>(rSet
->Get(nWhich
)).GetValue();
476 // make new SvxBrushItem with this Color
477 pHighlighting
= std::make_unique
<SvxBrushItem
>(aBackColor
, SID_ATTR_BRUSH_CHAR
);
483 /** When destroying a SfxTabPage this virtual method is called,
484 so that the TabPage can save internal information.
486 In this case the condition of the preview button is saved.
488 void SvxBackgroundTabPage::FillUserData()
490 SetUserData(m_xBtnPreview
->get_active() ? OUString('1') : OUString('0'));
493 bool SvxBackgroundTabPage::FillItemSet( SfxItemSet
* rCoreSet
)
495 if ( m_pLoadIdle
&& m_pLoadIdle
->IsActive() )
498 LoadIdleHdl_Impl( m_pLoadIdle
.get() );
501 bool bModified
= false;
502 bool bCompareOldBrush
= true;
503 sal_uInt16 nSlot
= SID_ATTR_BRUSH
;
505 if (m_xTblLBox
->get_visible())
507 switch (m_xTblLBox
->get_active())
510 nSlot
= SID_ATTR_BRUSH
;
513 nSlot
= SID_ATTR_BRUSH_ROW
;
516 nSlot
= SID_ATTR_BRUSH_TABLE
;
520 else if( bHighlighting
)
522 nSlot
= SID_ATTR_BRUSH_CHAR
;
524 else if( bCharBackColor
)
526 nSlot
= SID_ATTR_CHAR_BACK_COLOR
;
527 bCompareOldBrush
= false;
530 sal_uInt16 nWhich
= GetWhich( nSlot
);
532 const SfxPoolItem
* pOld
= GetOldItem(*rCoreSet
, nSlot
);
533 if (pOld
&& bCompareOldBrush
)
535 SfxItemState eOldItemState
= rCoreSet
->GetItemState(nSlot
, false);
536 const SfxItemSet
& rOldSet
= GetItemSet();
537 const SvxBrushItem
& rOldItem
= static_cast<const SvxBrushItem
&>(*pOld
);
539 SvxGraphicPosition eOldPos
= rOldItem
.GetGraphicPos();
540 const bool bIsBrush
= ( drawing::FillStyle_SOLID
== lcl_getFillStyle(*m_xLbSelect
) );
542 if ( ( (GPOS_NONE
== eOldPos
) && bIsBrush
)
543 || ( (GPOS_NONE
!= eOldPos
) && !bIsBrush
) ) // Brush <-> Bitmap changed?
545 // background art hasn't been changed:
547 if (GPOS_NONE
== eOldPos
|| !m_xLbSelect
->get_visible())
550 if ( rOldItem
.GetColor() != aBgdColor
||
551 (SfxItemState::DEFAULT
>= eOldItemState
&& m_bColorSelected
))
554 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
556 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
557 rCoreSet
->ClearItem( nWhich
);
563 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
564 const bool bIsLink
= m_xBtnLink
->get_active();
565 const bool bWasLink
= !rOldItem
.GetGraphicLink().isEmpty();
568 if ( !bIsLink
&& !bIsGraphicValid
)
569 bIsGraphicValid
= LoadLinkedGraphic_Impl();
571 bool bModifyBrush
= false;
572 if (eNewPos
!= eOldPos
|| bIsLink
!= bWasLink
)
574 else if (bWasLink
&& rOldItem
.GetGraphicLink() != aBgdGraphicPath
)
578 const Graphic
* pGraphic
= rOldItem
.GetGraphic();
580 bModifyBrush
= pGraphic
->GetBitmapEx() != aBgdGraphic
.GetBitmapEx();
585 std::unique_ptr
<SvxBrushItem
> aTmpBrush
;
589 aTmpBrush
.reset(new SvxBrushItem( aBgdGraphicPath
,
596 aTmpBrush
.reset(new SvxBrushItem( aBgdGraphic
,
601 rCoreSet
->Put(*aTmpBrush
);
603 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
604 rCoreSet
->ClearItem( nWhich
);
607 else // Brush <-> Bitmap changed!
611 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
615 std::unique_ptr
<SvxBrushItem
> pTmpBrush
;
616 if ( m_xBtnLink
->get_active() )
618 pTmpBrush
.reset(new SvxBrushItem( aBgdGraphicPath
,
620 GetGraphicPosition_Impl(),
625 if ( !bIsGraphicValid
)
626 bIsGraphicValid
= LoadLinkedGraphic_Impl();
628 if ( bIsGraphicValid
)
629 pTmpBrush
.reset(new SvxBrushItem( aBgdGraphic
,
630 GetGraphicPosition_Impl(),
635 rCoreSet
->Put(*pTmpBrush
);
638 bModified
= ( bIsBrush
|| m_xBtnLink
->get_active() || bIsGraphicValid
);
641 else if (pOld
&& SID_ATTR_CHAR_BACK_COLOR
== nSlot
)
643 SfxItemState eOldItemState
= rCoreSet
->GetItemState(nSlot
, false);
644 const SfxItemSet
& rOldSet
= GetItemSet();
645 const SvxBackgroundColorItem
& rOldItem
= static_cast<const SvxBackgroundColorItem
&>(*pOld
);
648 if ( rOldItem
.GetValue() != aBgdColor
||
649 (SfxItemState::DEFAULT
>= eOldItemState
&& m_bColorSelected
))
652 rCoreSet
->Put(SvxBackgroundColorItem(aBgdColor
, nWhich
));
654 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
655 rCoreSet
->ClearItem( nWhich
);
657 else if ( SID_ATTR_BRUSH_CHAR
== nSlot
&& aBgdColor
!= COL_WHITE
)
659 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
663 if (m_xTblLBox
->get_visible())
665 // the current condition has already been put
666 if( nSlot
!= SID_ATTR_BRUSH
&& m_pCellBrush
)
668 const SfxPoolItem
* pOldCell
=
669 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH
);
671 if ( *m_pCellBrush
!= *pOldCell
)
673 rCoreSet
->Put( *m_pCellBrush
);
678 if( nSlot
!= SID_ATTR_BRUSH_ROW
&& m_pRowBrush
)
680 const SfxPoolItem
* pOldRow
=
681 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_ROW
);
683 if ( *m_pRowBrush
!= *pOldRow
)
685 rCoreSet
->Put( *m_pRowBrush
);
690 if( nSlot
!= SID_ATTR_BRUSH_TABLE
&& m_pTableBrush
)
692 const SfxPoolItem
* pOldTable
=
693 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_TABLE
);
695 if ( *m_pTableBrush
!= *pOldTable
)
697 rCoreSet
->Put( *m_pTableBrush
);
702 if (m_xTblLBox
->get_value_changed_from_saved())
704 rCoreSet
->Put(SfxUInt16Item(SID_BACKGRND_DESTINATION
,
705 m_xTblLBox
->get_active()));
709 else if( bHighlighting
)
711 if( nSlot
!= SID_ATTR_BRUSH_CHAR
)
713 const SfxPoolItem
* pOldChar
=
714 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_CHAR
);
715 if ( pOldChar
&& pHighlighting
&&
716 (*pHighlighting
!= *pOldChar
|| *pHighlighting
!= SvxBrushItem(SID_ATTR_BRUSH_CHAR
)))
718 rCoreSet
->Put( *pHighlighting
);
726 /** virtual method; is called on deactivation */
727 DeactivateRC
SvxBackgroundTabPage::DeactivatePage( SfxItemSet
* _pSet
)
729 if ( m_bIsImportDlgInExecute
)
730 return DeactivateRC::KeepPage
;
733 FillItemSet( _pSet
);
735 return DeactivateRC::LeavePage
;
738 void SvxBackgroundTabPage::PointChanged( weld::DrawingArea
*, RectPoint
)
740 // has to be implemented so that position control can work
743 void SvxBackgroundTabPage::ShowSelector()
745 if( bAllowShowSelector
)
748 m_xSelectTxt
->show();
750 m_xLbSelect
->connect_changed(HDL(SelectHdl_Impl
));
751 m_xBtnLink
->connect_toggled(HDL(FileClickHdl_Impl
));
752 m_xBtnPreview
->connect_toggled(HDL(FileClickHdl_Impl
));
753 m_xBtnBrowse
->connect_clicked(HDL(BrowseHdl_Impl
));
754 m_xBtnArea
->connect_toggled(HDL(RadioClickHdl_Impl
));
755 m_xBtnTile
->connect_toggled(HDL(RadioClickHdl_Impl
));
756 m_xBtnPosition
->connect_toggled(HDL(RadioClickHdl_Impl
));
758 // delayed loading via timer (because of UI-Update)
759 m_pLoadIdle
.reset( new Idle("DelayedLoad") );
760 m_pLoadIdle
->SetPriority( TaskPriority::LOWEST
);
761 m_pLoadIdle
->SetInvokeHandler(
762 LINK( this, SvxBackgroundTabPage
, LoadIdleHdl_Impl
) );
764 bAllowShowSelector
= false;
766 if (nHtmlMode
& HTMLMODE_ON
)
768 m_xBtnArea
->set_sensitive(false);
773 void SvxBackgroundTabPage::RaiseLoadError_Impl()
775 SfxErrorContext
aContext( ERRCTX_SVX_BACKGROUND
,
781 ErrorHandler::HandleError(
782 *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE
,
786 bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
788 bool bResult
= ( !aBgdGraphicPath
.isEmpty() ) &&
789 ( ERRCODE_NONE
== GraphicFilter::LoadGraphic( aBgdGraphicPath
,
795 void SvxBackgroundTabPage::FillColorValueSets_Impl()
797 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
798 const SfxPoolItem
* pItem
= nullptr;
799 XColorListRef pColorTable
;
800 if ( pDocSh
&& ( nullptr != ( pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
) ) ) )
802 pColorTable
= static_cast<const SvxColorListItem
*>(pItem
)->GetColorList();
805 if ( !pColorTable
.is() )
806 pColorTable
= XColorList::CreateStdColorList();
808 if ( pColorTable
.is() )
810 m_xBackgroundColorSet
->Clear();
811 m_xBackgroundColorSet
->addEntriesForXColorList(*pColorTable
);
814 const WinBits
nBits(m_xBackgroundColorSet
->GetStyle() | WB_ITEMBORDER
| WB_NAMEFIELD
| WB_NONEFIELD
);
815 m_xBackgroundColorSet
->SetStyle(nBits
);
816 m_xBackgroundColorSet
->SetColCount(SvxColorValueSet::getColumnCount());
819 /** Hide the controls for editing the bitmap
820 and show the controls for color settings instead.
822 void SvxBackgroundTabPage::ShowColorUI_Impl()
824 if (!m_xBackGroundColorFrame
->get_visible())
827 m_xBackGroundColorFrame
->show();
831 void SvxBackgroundTabPage::HideColorUI_Impl()
833 m_xBackGroundColorFrame
->hide();
836 /** Hide the controls for color settings
837 and show controls for editing the bitmap instead.
839 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
841 if (m_xLbSelect
->get_visible() &&
842 (m_xBackGroundColorFrame
->get_visible() || !m_xFileFrame
->get_visible()))
846 m_xBitmapContainer
->show();
847 m_xFileFrame
->show();
848 m_xBtnLink
->set_visible(!(nHtmlMode
& HTMLMODE_ON
));
849 m_xTypeFrame
->show();
850 m_xPreviewWin2
->show();
851 m_xBtnPreview
->show();
855 void SvxBackgroundTabPage::HideBitmapUI_Impl()
857 m_xBitmapContainer
->hide();
858 m_xFileFrame
->hide();
859 m_xTypeFrame
->hide();
860 m_xPreviewWin2
->hide();
861 m_xBtnPreview
->hide();
864 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos
)
870 m_xBtnArea
->set_active(true);
871 m_xWndPositionWin
->set_sensitive(false);
877 m_xBtnTile
->set_active(true);
878 m_xWndPositionWin
->set_sensitive(false);
884 m_xBtnPosition
->set_active(true);
885 m_xWndPositionWin
->set_sensitive(true);
886 RectPoint eNewPos
= RectPoint::MM
;
891 case GPOS_LT
: eNewPos
= RectPoint::LT
; break;
892 case GPOS_MT
: eNewPos
= RectPoint::MT
; break;
893 case GPOS_RT
: eNewPos
= RectPoint::RT
; break;
894 case GPOS_LM
: eNewPos
= RectPoint::LM
; break;
895 case GPOS_RM
: eNewPos
= RectPoint::RM
; break;
896 case GPOS_LB
: eNewPos
= RectPoint::LB
; break;
897 case GPOS_MB
: eNewPos
= RectPoint::MB
; break;
898 case GPOS_RB
: eNewPos
= RectPoint::RB
; break;
899 default: ;//prevent warning
901 m_xWndPosition
->SetActualRP( eNewPos
);
905 m_xWndPosition
->Invalidate();
908 SvxGraphicPosition
SvxBackgroundTabPage::GetGraphicPosition_Impl() const
910 if (m_xBtnTile
->get_active())
912 else if (m_xBtnArea
->get_active())
916 switch (m_xWndPosition
->GetActualRP())
918 case RectPoint::LT
: return GPOS_LT
;
919 case RectPoint::MT
: return GPOS_MT
;
920 case RectPoint::RT
: return GPOS_RT
;
921 case RectPoint::LM
: return GPOS_LM
;
922 case RectPoint::MM
: return GPOS_MM
;
923 case RectPoint::RM
: return GPOS_RM
;
924 case RectPoint::LB
: return GPOS_LB
;
925 case RectPoint::MB
: return GPOS_MB
;
926 case RectPoint::RB
: return GPOS_RB
;
935 /** Handler, called when color selection is changed */
936 IMPL_LINK_NOARG(SvxBackgroundTabPage
, BackgroundColorHdl_Impl
, SvtValueSet
*, void)
938 sal_uInt16 nItemId
= m_xBackgroundColorSet
->GetSelectedItemId();
939 Color aColor
= nItemId
? ( m_xBackgroundColorSet
->GetItemColor( nItemId
) ) : COL_TRANSPARENT
;
941 m_bColorSelected
= true;
942 m_xPreview1
->NotifyChange( aBgdColor
);
945 IMPL_LINK_NOARG(SvxBackgroundTabPage
, SelectHdl_Impl
, weld::ComboBox
&, void)
947 if ( drawing::FillStyle_SOLID
== lcl_getFillStyle(*m_xLbSelect
) )
957 IMPL_LINK(SvxBackgroundTabPage
, FileClickHdl_Impl
, weld::ToggleButton
&, rBox
, void)
959 if (m_xBtnLink
.get() == &rBox
)
961 if (m_xBtnLink
->get_active())
963 m_xFtUnlinked
->hide();
964 INetURLObject
aObj( aBgdGraphicPath
);
966 if ( aObj
.GetProtocol() == INetProtocol::File
)
967 aFilePath
= aObj
.getFSysPath( FSysStyle::Detect
);
969 aFilePath
= aBgdGraphicPath
;
970 m_xFtFile
->set_label(aFilePath
);
975 m_xFtUnlinked
->show();
979 else if (m_xBtnPreview
.get() == &rBox
)
981 if (m_xBtnPreview
->get_active())
983 if ( !bIsGraphicValid
)
984 bIsGraphicValid
= LoadLinkedGraphic_Impl();
986 if ( bIsGraphicValid
)
988 BitmapEx aBmp
= aBgdGraphic
.GetBitmapEx();
989 m_xPreview2
->NotifyChange( &aBmp
);
993 if ( !aBgdGraphicPath
.isEmpty() ) // only for linked bitmap
994 RaiseLoadError_Impl();
995 m_xPreview2
->NotifyChange( nullptr );
999 m_xPreview2
->NotifyChange( nullptr );
1003 IMPL_LINK(SvxBackgroundTabPage
, RadioClickHdl_Impl
, weld::ToggleButton
&, rBtn
, void)
1005 if (&rBtn
== m_xBtnPosition
.get())
1007 if (!m_xWndPositionWin
->get_sensitive())
1009 m_xWndPositionWin
->set_sensitive(true);
1010 m_xWndPositionWin
->queue_draw();
1013 else if (m_xWndPositionWin
->get_sensitive())
1015 m_xWndPositionWin
->set_sensitive(false);
1016 m_xWndPositionWin
->queue_draw();
1020 /** Handler, called by pressing the browse button.
1021 Create graphic/insert dialog, set path and start.
1023 IMPL_LINK_NOARG(SvxBackgroundTabPage
, BrowseHdl_Impl
, weld::Button
&, void)
1025 if ( m_pLoadIdle
->IsActive() )
1027 bool bHtml
= 0 != ( nHtmlMode
& HTMLMODE_ON
);
1029 OUString
aStrBrowse(m_xFindGraphicsFt
->get_label());
1030 pImportDlg
.reset(new SvxOpenGraphicDialog(aStrBrowse
, GetFrameWeld()));
1032 pImportDlg
->EnableLink(false);
1033 pImportDlg
->SetPath(aBgdGraphicPath
, m_xBtnLink
->get_active());
1035 m_bIsImportDlgInExecute
= true;
1036 ErrCode nErr
= pImportDlg
->Execute();
1037 m_bIsImportDlgInExecute
= false;
1042 m_xBtnLink
->set_active(true);
1043 // if link isn't checked and preview isn't, either,
1044 // activate preview, so that the user sees which
1045 // graphic he has chosen
1046 if (!m_xBtnLink
->get_active() && !m_xBtnPreview
->get_active())
1047 m_xBtnPreview
->set_active(true);
1048 // timer-delayed loading of the graphic
1049 m_pLoadIdle
->Start();
1055 /** Delayed loading of the graphic.
1056 Graphic is only loaded, if it's
1057 different to the current graphic.
1059 IMPL_LINK( SvxBackgroundTabPage
, LoadIdleHdl_Impl
, Timer
*, pIdle
, void )
1061 if ( pIdle
== m_pLoadIdle
.get() )
1063 m_pLoadIdle
->Stop();
1067 INetURLObject
aOld( aBgdGraphicPath
);
1068 INetURLObject
aNew( pImportDlg
->GetPath() );
1069 if ( aBgdGraphicPath
.isEmpty() || aNew
!= aOld
)
1072 aBgdGraphicPath
= pImportDlg
->GetPath();
1073 aBgdGraphicFilter
= pImportDlg
->GetDetectedFilter();
1074 bool bLink
= ( nHtmlMode
& HTMLMODE_ON
) || pImportDlg
->IsAsLink();
1075 m_xBtnLink
->set_active(bLink
);
1076 m_xBtnLink
->set_sensitive(true);
1078 if (m_xBtnPreview
->get_active())
1080 if( !pImportDlg
->GetGraphic(aBgdGraphic
) )
1082 bIsGraphicValid
= true;
1086 aBgdGraphicFilter
.clear();
1087 aBgdGraphicPath
.clear();
1088 bIsGraphicValid
= false;
1092 bIsGraphicValid
= false; // load graphic not until preview click
1094 if (m_xBtnPreview
->get_active() && bIsGraphicValid
)
1096 BitmapEx aBmp
= aBgdGraphic
.GetBitmapEx();
1097 m_xPreview2
->NotifyChange( &aBmp
);
1100 m_xPreview2
->NotifyChange( nullptr );
1103 FileClickHdl_Impl(*m_xBtnLink
);
1109 void SvxBackgroundTabPage::ShowTblControl()
1111 m_xTblLBox
->connect_changed(HDL(TblDestinationHdl_Impl
));
1112 m_xTblLBox
->set_active(0);
1118 IMPL_LINK(SvxBackgroundTabPage
, TblDestinationHdl_Impl
, weld::ComboBox
&, rBox
, void)
1120 int nSelPos
= rBox
.get_active();
1121 if( m_nActPos
!= nSelPos
)
1123 std::unique_ptr
<SvxBrushItem
> xItemHolder
;
1124 std::unique_ptr
<SvxBrushItem
>* pActItem
= nullptr;
1125 sal_uInt16 nWhich
= 0;
1129 pActItem
= &m_pCellBrush
;
1130 nWhich
= m_nCellWhich
;
1133 pActItem
= &m_pRowBrush
;
1134 nWhich
= m_nRowWhich
;
1137 pActItem
= &m_pTableBrush
;
1138 nWhich
= m_nTableWhich
;
1144 m_nActPos
= nSelPos
;
1147 xItemHolder
.reset(new SvxBrushItem(nWhich
));
1148 pActItem
= &xItemHolder
;
1150 if(drawing::FillStyle_SOLID
== lcl_getFillStyle(*m_xLbSelect
)) // brush selected
1152 *pActItem
= std::make_unique
<SvxBrushItem
>(aBgdColor
, nWhich
);
1156 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
1157 const bool bIsLink
= m_xBtnLink
->get_active();
1159 if ( !bIsLink
&& !bIsGraphicValid
)
1160 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1164 *pActItem
= std::make_unique
<SvxBrushItem
>( aBgdGraphicPath
,
1167 (*pActItem
)->Which() );
1171 *pActItem
= std::make_unique
<SvxBrushItem
>( aBgdGraphic
,
1173 (*pActItem
)->Which() );
1179 pActItem
= &m_pCellBrush
;
1180 m_xLbSelect
->set_sensitive(true);
1181 nWhich
= m_nCellWhich
;
1184 pActItem
= &m_pRowBrush
;
1185 nWhich
= m_nRowWhich
;
1188 pActItem
= &m_pTableBrush
;
1189 m_xLbSelect
->set_sensitive(true);
1190 nWhich
= m_nTableWhich
;
1193 // The item will be new'ed again below, but that will be the
1194 // default item then, not an existing modified one.
1195 xItemHolder
.reset();
1199 OUString aUserData
= GetUserData();
1202 xItemHolder
.reset(new SvxBrushItem(nWhich
));
1203 pActItem
= &xItemHolder
;
1205 FillControls_Impl(**pActItem
, aUserData
);
1209 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem
& rBgdAttr
,
1210 const OUString
& rUserData
)
1212 SvxGraphicPosition ePos
= rBgdAttr
.GetGraphicPos();
1213 const Color
& rColor
= rBgdAttr
.GetColor();
1215 if (GPOS_NONE
== ePos
|| !m_xLbSelect
->get_visible())
1217 lcl_setFillStyle(*m_xLbSelect
, drawing::FillStyle_SOLID
);
1219 Color
aTrColor( COL_TRANSPARENT
);
1222 sal_uInt16 nCol
= ( aTrColor
!= aBgdColor
) ?
1223 GetItemId_Impl(*m_xBackgroundColorSet
, aBgdColor
) : 0;
1225 if( aTrColor
!= aBgdColor
&& nCol
== 0)
1227 m_xBackgroundColorSet
->SetNoSelection();
1231 m_xBackgroundColorSet
->SelectItem( nCol
);
1234 m_xPreview1
->NotifyChange( aBgdColor
);
1236 if (m_xLbSelect
->get_visible()) // initialize graphic part
1238 aBgdGraphicFilter
.clear();
1239 aBgdGraphicPath
.clear();
1241 if ( rUserData
.isEmpty() )
1242 m_xBtnPreview
->set_active(false);
1243 m_xBtnLink
->set_active(false);
1244 m_xBtnLink
->set_sensitive(false);
1245 m_xPreview2
->NotifyChange(nullptr);
1246 SetGraphicPosition_Impl( GPOS_TILED
); // tiles as default
1251 const OUString
& aStrLink
= rBgdAttr
.GetGraphicLink();
1252 const OUString
& aStrFilter
= rBgdAttr
.GetGraphicFilter();
1254 lcl_setFillStyle(*m_xLbSelect
, drawing::FillStyle_BITMAP
);
1255 ShowBitmapUI_Impl();
1257 if ( !aStrLink
.isEmpty() )
1260 INetURLObject
aObj( aStrLink
);
1261 DBG_ASSERT( aObj
.GetProtocol() != INetProtocol::NotValid
, "Invalid URL!" );
1263 aBgdGraphicPath
= aStrLink
;
1264 m_xBtnLink
->set_active(true);
1265 m_xBtnLink
->set_sensitive(true);
1269 aBgdGraphicPath
.clear();
1270 m_xBtnLink
->set_active(false);
1271 m_xBtnLink
->set_sensitive(false);
1274 FileClickHdl_Impl(*m_xBtnLink
);
1276 aBgdGraphicFilter
= aStrFilter
;
1278 if (aStrLink
.isEmpty() || m_xBtnPreview
->get_active())
1280 // Graphic exists in the item and doesn't have
1283 const Graphic
* pGraphic
= rBgdAttr
.GetGraphic();
1285 if (!pGraphic
&& m_xBtnPreview
->get_active())
1286 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1287 else if ( pGraphic
)
1289 aBgdGraphic
= *pGraphic
;
1290 bIsGraphicValid
= true;
1292 if (rUserData
.isEmpty())
1293 m_xBtnPreview
->set_active(true);
1297 RaiseLoadError_Impl();
1298 bIsGraphicValid
= false;
1300 if ( rUserData
.isEmpty() )
1301 m_xBtnPreview
->set_active(false);
1305 if (m_xBtnPreview
->get_active() && bIsGraphicValid
)
1307 BitmapEx aBmp
= aBgdGraphic
.GetBitmapEx();
1308 m_xPreview2
->NotifyChange( &aBmp
);
1311 m_xPreview2
->NotifyChange( nullptr );
1313 SetGraphicPosition_Impl( ePos
);
1317 void SvxBackgroundTabPage::PageCreated(const SfxAllItemSet
& aSet
)
1319 const SfxUInt32Item
* pFlagItem
= aSet
.GetItem
<SfxUInt32Item
>(SID_FLAG_TYPE
, false);
1323 SvxBackgroundTabFlags nFlags
= static_cast<SvxBackgroundTabFlags
>(pFlagItem
->GetValue());
1324 if (nFlags
& SvxBackgroundTabFlags::SHOW_TBLCTL
)
1326 if ( nFlags
& SvxBackgroundTabFlags::SHOW_SELECTOR
)
1330 if ((nFlags
& SvxBackgroundTabFlags::SHOW_HIGHLIGHTING
) ||
1331 (nFlags
& SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR
))
1333 m_xBackGroundColorLabelFT
->set_label(CuiResId(RID_SVXSTR_CHARNAME_HIGHLIGHTING
));
1334 bHighlighting
= bool(nFlags
& SvxBackgroundTabFlags::SHOW_HIGHLIGHTING
);
1335 bCharBackColor
= bool(nFlags
& SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR
);
1340 static sal_uInt16
lcl_GetTableDestSlot(sal_Int32 nTblDest
)
1347 return SID_ATTR_BRUSH
;
1351 return SID_ATTR_BRUSH_ROW
;
1355 return SID_ATTR_BRUSH_TABLE
;
1360 SvxBkgTabPage::SvxBkgTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
1361 : SvxAreaTabPage(pPage
, pController
, rInAttrs
),
1362 bHighlighting(false),
1363 bCharBackColor(false),
1366 m_xBtnGradient
->hide();
1367 m_xBtnHatch
->hide();
1368 m_xBtnBitmap
->hide();
1369 m_xBtnPattern
->hide();
1371 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
1372 const SfxPoolItem
* pItem
= nullptr;
1374 XColorListRef pColorTable
;
1375 if ( pDocSh
&& ( nullptr != ( pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
) ) ) )
1377 pColorTable
= static_cast<const SvxColorListItem
*>(pItem
)->GetColorList();
1380 if ( !pColorTable
.is() )
1381 pColorTable
= XColorList::CreateStdColorList();
1383 XBitmapListRef pBitmapList
;
1384 if ( pDocSh
&& ( nullptr != ( pItem
= pDocSh
->GetItem( SID_BITMAP_LIST
) ) ) )
1386 pBitmapList
= static_cast<const SvxBitmapListItem
*>(pItem
)->GetBitmapList();
1389 SetColorList(pColorTable
);
1390 SetBitmapList(pBitmapList
);
1393 SvxBkgTabPage::~SvxBkgTabPage()
1398 void SvxBkgTabPage::ActivatePage( const SfxItemSet
& )
1400 SvxAreaTabPage::ActivatePage( maSet
);
1403 DeactivateRC
SvxBkgTabPage::DeactivatePage( SfxItemSet
* _pSet
)
1405 if ( DeactivateRC::KeepPage
== SvxAreaTabPage::DeactivatePage( &maSet
) )
1406 return DeactivateRC::KeepPage
;
1409 FillItemSet( _pSet
);
1411 return DeactivateRC::LeavePage
;
1414 void SvxBkgTabPage::Reset( const SfxItemSet
* )
1416 maSet
.Set( *m_pResetSet
);
1417 if ( m_xTblLBox
&& m_xTblLBox
->get_visible() )
1420 const SfxPoolItem
* pItem
;
1421 if ( SfxItemState::SET
== m_pResetSet
->GetItemState( SID_BACKGRND_DESTINATION
, false, &pItem
) )
1423 sal_uInt16 nDestValue
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
1424 m_xTblLBox
->set_active( nDestValue
);
1425 TblDestinationHdl_Impl( *m_xTblLBox
);
1427 m_xTblLBox
->save_value();
1429 SvxAreaTabPage::Reset( &maSet
);
1432 bool SvxBkgTabPage::FillItemSet( SfxItemSet
* rCoreSet
)
1434 sal_uInt16 nSlot
= SID_ATTR_BRUSH
;
1435 if (m_xTblLBox
&& m_xTblLBox
->get_visible())
1436 nSlot
= lcl_GetTableDestSlot(m_xTblLBox
->get_active());
1437 else if ( bHighlighting
)
1438 nSlot
= SID_ATTR_BRUSH_CHAR
;
1439 else if( bCharBackColor
)
1440 nSlot
= SID_ATTR_CHAR_BACK_COLOR
;
1442 sal_uInt16 nWhich
= GetWhich(nSlot
);
1444 drawing::FillStyle eFillType
= maSet
.Get( XATTR_FILLSTYLE
).GetValue();
1447 case drawing::FillStyle_NONE
:
1449 if ( IsBtnClicked() )
1451 if ( SID_ATTR_CHAR_BACK_COLOR
== nSlot
)
1453 maSet
.Put( SvxBackgroundColorItem( COL_TRANSPARENT
, nWhich
) );
1454 rCoreSet
->Put( SvxBackgroundColorItem( COL_TRANSPARENT
, nWhich
) );
1458 maSet
.Put( SvxBrushItem( COL_TRANSPARENT
, nWhich
) );
1459 rCoreSet
->Put( SvxBrushItem( COL_TRANSPARENT
, nWhich
) );
1464 case drawing::FillStyle_SOLID
:
1466 XFillColorItem
aColorItem( maSet
.Get( XATTR_FILLCOLOR
) );
1467 if ( SID_ATTR_CHAR_BACK_COLOR
== nSlot
)
1469 maSet
.Put( SvxBackgroundColorItem( aColorItem
.GetColorValue(), nWhich
) );
1470 rCoreSet
->Put( SvxBackgroundColorItem( aColorItem
.GetColorValue(), nWhich
) );
1474 maSet
.Put( SvxBrushItem( aColorItem
.GetColorValue(), nWhich
) );
1475 rCoreSet
->Put( SvxBrushItem( aColorItem
.GetColorValue(), nWhich
) );
1479 case drawing::FillStyle_BITMAP
:
1481 std::shared_ptr
<SvxBrushItem
> aBrushItem( getSvxBrushItemFromSourceSet( maSet
, nWhich
) );
1482 if ( GraphicType::NONE
!= aBrushItem
->GetGraphicObject()->GetType() )
1483 rCoreSet
->Put( *aBrushItem
);
1490 if (m_xTblLBox
&& m_xTblLBox
->get_visible())
1492 if (nSlot
!= SID_ATTR_BRUSH
)
1494 nWhich
= maSet
.GetPool()->GetWhich(SID_ATTR_BRUSH
);
1495 if (SfxItemState::SET
== maSet
.GetItemState(nWhich
))
1497 SvxBrushItem
aBrushItem(static_cast<const SvxBrushItem
&>(maSet
.Get(nWhich
)));
1498 rCoreSet
->Put(aBrushItem
);
1501 if (nSlot
!= SID_ATTR_BRUSH_ROW
)
1503 nWhich
= maSet
.GetPool()->GetWhich(SID_ATTR_BRUSH_ROW
);
1504 if (SfxItemState::SET
== maSet
.GetItemState(nWhich
))
1506 SvxBrushItem
aBrushItem(static_cast<const SvxBrushItem
&>(maSet
.Get(nWhich
)));
1507 rCoreSet
->Put(aBrushItem
);
1510 if (nSlot
!= SID_ATTR_BRUSH_TABLE
)
1512 nWhich
= maSet
.GetPool()->GetWhich(SID_ATTR_BRUSH_TABLE
);
1513 if (SfxItemState::SET
== maSet
.GetItemState(nWhich
))
1515 SvxBrushItem
aBrushItem(static_cast<const SvxBrushItem
&>(maSet
.Get(nWhich
)));
1516 rCoreSet
->Put(aBrushItem
);
1520 if (m_xTblLBox
->get_value_changed_from_saved())
1522 rCoreSet
->Put(SfxUInt16Item(SID_BACKGRND_DESTINATION
, m_xTblLBox
->get_active()));
1529 std::unique_ptr
<SfxTabPage
> SvxBkgTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrs
)
1531 auto xRet
= std::make_unique
<SvxBkgTabPage
>(pPage
, pController
, *rAttrs
);
1532 xRet
->SetOptimalSize(pController
);
1536 void SvxBkgTabPage::PageCreated(const SfxAllItemSet
& aSet
)
1538 const SfxUInt32Item
* pFlagItem
= aSet
.GetItem
<SfxUInt32Item
>(SID_FLAG_TYPE
, false);
1541 SvxBackgroundTabFlags nFlags
= static_cast<SvxBackgroundTabFlags
>(pFlagItem
->GetValue());
1542 if ( nFlags
& SvxBackgroundTabFlags::SHOW_TBLCTL
)
1544 m_xBtnBitmap
->show();
1545 m_xTblLBox
= m_xBuilder
->weld_combo_box("tablelb");
1546 m_xTblLBox
->connect_changed(LINK(this, SvxBkgTabPage
, TblDestinationHdl_Impl
));
1549 if ((nFlags
& SvxBackgroundTabFlags::SHOW_HIGHLIGHTING
) ||
1550 (nFlags
& SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR
))
1552 bHighlighting
= bool(nFlags
& SvxBackgroundTabFlags::SHOW_HIGHLIGHTING
);
1553 bCharBackColor
= bool(nFlags
& SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR
);
1555 if (nFlags
& SvxBackgroundTabFlags::SHOW_SELECTOR
)
1556 m_xBtnBitmap
->show();
1557 SetOptimalSize(GetDialogController());
1560 if ( bCharBackColor
)
1562 sal_uInt16
nWhich(maSet
.GetPool()->GetWhich(SID_ATTR_CHAR_BACK_COLOR
));
1563 Color
aBackColor(static_cast<const SvxBackgroundColorItem
&>(maSet
.Get(nWhich
)).GetValue());
1564 SvxBrushItem
aBrushItem(SvxBrushItem(aBackColor
, SID_ATTR_BRUSH_CHAR
));
1565 setSvxBrushItemAsFillAttributesToTargetSet(aBrushItem
, maSet
);
1569 sal_uInt16
nWhich(maSet
.GetPool()->GetWhich(bHighlighting
? SID_ATTR_BRUSH_CHAR
: SID_ATTR_BRUSH
));
1570 SvxBrushItem
aBrushItem(static_cast<const SvxBrushItem
&>(maSet
.Get(nWhich
)));
1571 setSvxBrushItemAsFillAttributesToTargetSet(aBrushItem
, maSet
);
1574 m_pResetSet
= maSet
.Clone();
1576 SvxAreaTabPage::PageCreated(aSet
);
1579 IMPL_LINK(SvxBkgTabPage
, TblDestinationHdl_Impl
, weld::ComboBox
&, rBox
, void)
1583 // fill local item set with XATTR_FILL settings gathered from tab page
1584 // and convert to SvxBrushItem and store in table destination slot Which
1585 SvxAreaTabPage::FillItemSet(&maSet
);
1586 maSet
.Put(*getSvxBrushItemFromSourceSet(maSet
, maSet
.GetPool()->GetWhich(lcl_GetTableDestSlot(m_nActPos
))));
1589 sal_Int32 nSelPos
= rBox
.get_active();
1590 if (m_nActPos
!= nSelPos
)
1592 m_nActPos
= nSelPos
;
1594 // fill local item set with XATTR_FILL created from SvxBushItem for table destination slot Which
1595 sal_uInt16 nWhich
= maSet
.GetPool()->GetWhich(lcl_GetTableDestSlot(nSelPos
));
1596 if (SfxItemState::SET
== maSet
.GetItemState(nWhich
))
1598 SvxBrushItem
aBrushItem(static_cast<const SvxBrushItem
&>(maSet
.Get(nWhich
)));
1599 setSvxBrushItemAsFillAttributesToTargetSet(aBrushItem
, maSet
);
1603 SelectFillType(*m_xBtnNone
, &maSet
);
1608 drawing::FillStyle eXFS
= drawing::FillStyle_NONE
;
1609 if (maSet
.GetItemState(XATTR_FILLSTYLE
) != SfxItemState::DONTCARE
)
1611 XFillStyleItem
aFillStyleItem(static_cast<const XFillStyleItem
&>(maSet
.Get(GetWhich( XATTR_FILLSTYLE
))));
1612 eXFS
= aFillStyleItem
.GetValue();
1617 case drawing::FillStyle_NONE
:
1619 SelectFillType(*m_xBtnNone
, &maSet
);
1622 case drawing::FillStyle_SOLID
:
1624 SelectFillType(*m_xBtnColor
, &maSet
);
1625 // color tab page Active and New preview controls are same after SelectFillType
1626 // hack to restore color tab page Active preview
1627 setSvxBrushItemAsFillAttributesToTargetSet(static_cast<const SvxBrushItem
&>(m_pResetSet
->Get(nWhich
)), *m_pResetSet
);
1628 static_cast<SvxColorTabPage
*>(GetFillTabPage())->SetCtlPreviewOld(*m_pResetSet
);
1631 case drawing::FillStyle_BITMAP
:
1633 SelectFillType(*m_xBtnBitmap
, &maSet
);
1640 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */