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 .
20 #include <com/sun/star/drawing/FillStyle.hpp>
21 #include <unotools/pathoptions.hxx>
22 #include <vcl/builderfactory.hxx>
23 #include <vcl/msgbox.hxx>
24 #include <vcl/settings.hxx>
25 #include <vcl/idle.hxx>
26 #include <tools/urlobj.hxx>
27 #include <sfx2/dialoghelper.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <sfx2/docfile.hxx>
30 #include <svl/cntwall.hxx>
31 #include <sfx2/cntids.hrc>
32 #include <svx/dialogs.hrc>
35 #include <svx/dialmgr.hxx>
36 #include <editeng/memberids.hrc>
37 #include <editeng/editrids.hrc>
38 #include <editeng/eerdll.hxx>
40 #include <editeng/brushitem.hxx>
41 #include "backgrnd.hxx"
43 #include <svx/xtable.hxx>
44 #include <sfx2/opengrf.hxx>
45 #include <svx/svxerr.hxx>
46 #include <svx/drawitem.hxx>
47 #include <dialmgr.hxx>
48 #include <sfx2/htmlmode.hxx>
49 #include <svtools/controldims.hrc>
50 #include <svx/flagsdef.hxx>
51 #include <svl/intitem.hxx>
52 #include <sfx2/request.hxx>
53 #include <svtools/grfmgr.hxx>
54 #include <boost/scoped_ptr.hpp>
59 #define TBL_DEST_CELL 0
60 #define TBL_DEST_ROW 1
61 #define TBL_DEST_TBL 2
63 const sal_uInt16
SvxBackgroundTabPage::pPageRanges
[] =
65 SID_VIEW_FLD_PIC
, SID_VIEW_FLD_PIC
,
66 SID_ATTR_BRUSH
, SID_ATTR_BRUSH
,
67 SID_ATTR_BRUSH_CHAR
, SID_ATTR_BRUSH_CHAR
,
71 struct SvxBackgroundTable_Impl
73 SvxBrushItem
* pCellBrush
;
74 SvxBrushItem
* pRowBrush
;
75 SvxBrushItem
* pTableBrush
;
76 sal_uInt16 nCellWhich
;
78 sal_uInt16 nTableWhich
;
81 SvxBackgroundTable_Impl()
92 struct SvxBackgroundPara_Impl
94 SvxBrushItem
* pParaBrush
;
95 SvxBrushItem
* pCharBrush
;
99 SvxBackgroundPara_Impl()
102 , nActPos(LISTBOX_ENTRY_NOTFOUND
)
107 struct SvxBackgroundPage_Impl
110 bool bIsImportDlgInExecute
;
112 SvxBackgroundPage_Impl()
114 , bIsImportDlgInExecute(false)
118 static inline sal_uInt8
lcl_PercentToTransparency(long nPercent
)
120 //0xff must not be returned!
121 return sal_uInt8(nPercent
? (50 + 0xfe * nPercent
) / 100 : 0);
123 static inline sal_uInt8
lcl_TransparencyToPercent(sal_uInt8 nTrans
)
125 return (nTrans
* 100 + 127) / 254;
127 static void lcl_SetTransparency(SvxBrushItem
& rBrush
, long nTransparency
)
129 uno::Any aTransparency
;
130 aTransparency
<<= (sal_Int8
)nTransparency
;
131 rBrush
.PutValue(aTransparency
, MID_GRAPHIC_TRANSPARENCY
);
134 /// Returns the fill style of the currently selected entry.
135 static drawing::FillStyle
lcl_getFillStyle(ListBox
* pLbSelect
)
137 return (drawing::FillStyle
)reinterpret_cast<sal_uLong
>(pLbSelect
->GetSelectEntryData());
140 // Selects the entry matching the specified fill style.
141 static void lcl_setFillStyle(ListBox
* pLbSelect
, drawing::FillStyle eStyle
)
143 for (int i
= 0; i
< pLbSelect
->GetEntryCount(); ++i
)
145 if ((drawing::FillStyle
)reinterpret_cast<sal_uLong
>(pLbSelect
->GetEntryData(i
)) == eStyle
)
147 pLbSelect
->SelectEntryPos(i
);
153 sal_uInt16
GetItemId_Impl( ValueSet
& rValueSet
, const Color
& rCol
)
156 sal_uInt16 nCount
= rValueSet
.GetItemCount();
159 while ( !bFound
&& n
<= nCount
)
161 Color aValCol
= rValueSet
.GetItemColor(n
);
163 bFound
= ( aValCol
.GetRed() == rCol
.GetRed()
164 && aValCol
.GetGreen() == rCol
.GetGreen()
165 && aValCol
.GetBlue() == rCol
.GetBlue() );
170 return bFound
? n
: 0;
174 /** Preview window for brush or bitmap */
175 class BackgroundPreviewImpl
: public vcl::Window
178 BackgroundPreviewImpl(vcl::Window
* pParent
);
179 void setBmp(bool bBmp
);
180 virtual ~BackgroundPreviewImpl();
181 virtual void dispose() SAL_OVERRIDE
;
183 void NotifyChange( const Color
& rColor
);
184 void NotifyChange( const Bitmap
* pBitmap
);
187 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const Rectangle
& rRect
) SAL_OVERRIDE
;
188 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) SAL_OVERRIDE
;
189 virtual void Resize() SAL_OVERRIDE
;
193 void recalcDrawPos();
200 sal_uInt8 nTransparency
;
203 BackgroundPreviewImpl::BackgroundPreviewImpl(vcl::Window
* pParent
)
204 : Window(pParent
, WB_BORDER
)
207 , aDrawRect(Point(0,0), GetOutputSizePixel())
210 SetBorderStyle(WindowBorderStyle::MONO
);
211 Invalidate(aDrawRect
);
214 VCL_BUILDER_DECL_FACTORY(BackgroundPreview
)
217 rRet
= VclPtr
<BackgroundPreviewImpl
>::Create(pParent
);
220 void BackgroundPreviewImpl::setBmp(bool bBmp
)
226 BackgroundPreviewImpl::~BackgroundPreviewImpl()
231 void BackgroundPreviewImpl::dispose()
235 vcl::Window::dispose();
238 void BackgroundPreviewImpl::NotifyChange( const Color
& rColor
)
242 const static Color
aTranspCol( COL_TRANSPARENT
);
244 nTransparency
= lcl_TransparencyToPercent( rColor
.GetTransparency() );
246 SetFillColor( rColor
== aTranspCol
? GetSettings().GetStyleSettings().GetFieldColor() : Color(rColor
.GetRGBColor()) );
247 Invalidate(aDrawRect
);
251 void BackgroundPreviewImpl::NotifyChange( const Bitmap
* pNewBitmap
)
253 if (bIsBmp
&& (pNewBitmap
|| pBitmap
))
255 if (pNewBitmap
&& pBitmap
)
256 *pBitmap
= *pNewBitmap
;
257 else if (pNewBitmap
&& !pBitmap
)
258 pBitmap
= new Bitmap(*pNewBitmap
);
259 else if (!pNewBitmap
)
264 Invalidate(aDrawRect
);
269 void BackgroundPreviewImpl::recalcDrawPos()
273 Size aSize
= GetOutputSizePixel();
274 // InnerSize == Size without one pixel border
275 Size aInnerSize
= aSize
;
276 aInnerSize
.Width() -= 2;
277 aInnerSize
.Height() -= 2;
278 aDrawSize
= pBitmap
->GetSizePixel();
280 // bitmap bigger than preview window?
281 if (aDrawSize
.Width() > aInnerSize
.Width())
283 aDrawSize
.Height() = aDrawSize
.Height() * aInnerSize
.Width() / aDrawSize
.Width();
284 if (aDrawSize
.Height() > aInnerSize
.Height())
286 aDrawSize
.Width() = aDrawSize
.Height();
287 aDrawSize
.Height() = aInnerSize
.Height();
290 aDrawSize
.Width() = aInnerSize
.Width();
292 else if (aDrawSize
.Height() > aInnerSize
.Height())
294 aDrawSize
.Width() = aDrawSize
.Width() * aInnerSize
.Height() / aDrawSize
.Height();
295 if (aDrawSize
.Width() > aInnerSize
.Width())
297 aDrawSize
.Height() = aDrawSize
.Width();
298 aDrawSize
.Width() = aInnerSize
.Width();
301 aDrawSize
.Height() = aInnerSize
.Height();
304 aDrawPos
.X() = (aSize
.Width() - aDrawSize
.Width()) / 2;
305 aDrawPos
.Y() = (aSize
.Height() - aDrawSize
.Height()) / 2;
309 void BackgroundPreviewImpl::Resize()
312 aDrawRect
= Rectangle(Point(0,0), GetOutputSizePixel());
316 void BackgroundPreviewImpl::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
&)
318 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
319 rRenderContext
.SetBackground(Wallpaper(rStyleSettings
.GetWindowColor()));
320 rRenderContext
.SetLineColor();
324 rRenderContext
.SetFillColor(Color(COL_TRANSPARENT
));
326 rRenderContext
.DrawRect(aDrawRect
);
331 rRenderContext
.DrawBitmap(aDrawPos
, aDrawSize
, *pBitmap
);
334 Size aSize
= rRenderContext
.GetOutputSizePixel();
335 rRenderContext
.DrawLine(Point(0, 0), Point(aSize
.Width(), aSize
.Height()));
336 rRenderContext
.DrawLine(Point(0, aSize
.Height()), Point(aSize
.Width(), 0));
341 void BackgroundPreviewImpl::DataChanged( const DataChangedEvent
& rDCEvt
)
343 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
344 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
348 Window::DataChanged( rDCEvt
);
351 #define HDL(hdl) LINK(this,SvxBackgroundTabPage,hdl)
353 SvxBackgroundTabPage::SvxBackgroundTabPage(vcl::Window
* pParent
, const SfxItemSet
& rCoreSet
)
354 : SvxTabPage(pParent
, "BackgroundPage", "cui/ui/backgroundpage.ui", rCoreSet
)
356 , bAllowShowSelector(true)
357 , bIsGraphicValid(false)
359 , bColTransparency(false)
360 , bGraphTransparency(false)
361 , pPageImpl(new SvxBackgroundPage_Impl
)
363 , pTableBck_Impl(NULL
)
364 , pParaBck_Impl(NULL
)
366 get(m_pAsGrid
, "asgrid");
367 get(m_pSelectTxt
, "asft");
368 get(m_pLbSelect
, "selectlb");
369 get(m_pTblDesc
, "forft");
370 get(m_pTblLBox
, "tablelb");
371 get(m_pParaLBox
, "paralb");
373 get(m_pBackGroundColorFrame
, "backgroundcolorframe");
374 get(m_pBackgroundColorSet
, "backgroundcolorset");
375 get(m_pPreviewWin1
, "preview1");
377 get(m_pColTransFT
, "transparencyft");
378 get(m_pColTransMF
, "transparencymf");
379 get(m_pBtnPreview
, "showpreview");
381 get(m_pBitmapContainer
, "graphicgrid");
382 get(m_pFileFrame
, "fileframe");
383 get(m_pBtnBrowse
, "browse");
384 get(m_pBtnLink
, "link");
385 get(m_pFtUnlinked
, "unlinkedft");
386 get(m_pFtFile
, "fileft");
388 get(m_pTypeFrame
, "typeframe");
389 get(m_pBtnPosition
, "positionrb");
390 get(m_pBtnArea
, "arearb");
391 get(m_pBtnTile
, "tilerb");
392 get(m_pWndPosition
, "windowpos");
394 get(m_pGraphTransFrame
, "graphtransframe");
395 get(m_pGraphTransMF
, "graphtransmf");
397 get(m_pPreviewWin2
, "preview2");
398 m_pPreviewWin2
->setBmp(true);
400 // this page needs ExchangeSupport
401 SetExchangeSupport();
403 const SfxPoolItem
* pItem
;
404 SfxObjectShell
* pShell
;
406 if ( SfxItemState::SET
== rCoreSet
.GetItemState( SID_HTML_MODE
, false, &pItem
)
407 || ( 0 != ( pShell
= SfxObjectShell::Current()) &&
408 0 != ( pItem
= pShell
->GetItem( SID_HTML_MODE
) ) ) )
410 nHtmlMode
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
413 FillColorValueSets_Impl();
415 m_pBackgroundColorSet
->SetSelectHdl( HDL(BackgroundColorHdl_Impl
) );
416 m_pBackgroundColorSet
->SetStyle(m_pBackgroundColorSet
->GetStyle() | WB_ITEMBORDER
| WB_NAMEFIELD
| WB_NONEFIELD
);
417 m_pBackgroundColorSet
->SetText(SVX_RESSTR(RID_SVXSTR_TRANSPARENT
));
420 SvxBackgroundTabPage::~SvxBackgroundTabPage()
425 void SvxBackgroundTabPage::dispose()
429 delete pPageImpl
->pLoadIdle
;
439 delete pTableBck_Impl
->pCellBrush
;
440 delete pTableBck_Impl
->pRowBrush
;
441 delete pTableBck_Impl
->pTableBrush
;
442 delete pTableBck_Impl
;
443 pTableBck_Impl
= NULL
;
448 delete pParaBck_Impl
->pParaBrush
;
449 delete pParaBck_Impl
->pCharBrush
;
450 delete pParaBck_Impl
;
451 pParaBck_Impl
= NULL
;
455 m_pSelectTxt
.clear();
460 m_pBackGroundColorFrame
.clear();
461 m_pBackgroundColorSet
.clear();
462 m_pPreviewWin1
.clear();
463 m_pColTransFT
.clear();
464 m_pColTransMF
.clear();
465 m_pBtnPreview
.clear();
466 m_pBitmapContainer
.clear();
467 m_pFileFrame
.clear();
468 m_pBtnBrowse
.clear();
470 m_pFtUnlinked
.clear();
472 m_pTypeFrame
.clear();
473 m_pBtnPosition
.clear();
476 m_pWndPosition
.clear();
477 m_pGraphTransFrame
.clear();
478 m_pGraphTransMF
.clear();
479 m_pPreviewWin2
.clear();
480 SvxTabPage::dispose();
483 VclPtr
<SfxTabPage
> SvxBackgroundTabPage::Create( vcl::Window
* pParent
, const SfxItemSet
* rAttrSet
)
485 return VclPtr
<SfxTabPage
>( new SvxBackgroundTabPage( pParent
, *rAttrSet
), SAL_NO_ACQUIRE
);
488 void SvxBackgroundTabPage::Reset( const SfxItemSet
* rSet
)
490 // os: Such a nonsense! One will always find such an item somewhere,
491 // but it must be existing in the rSet!
492 // const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
493 // if( pX && pX->ISA(SfxWallpaperItem))
494 if(SfxItemState::DEFAULT
<= rSet
->GetItemState(GetWhich(SID_VIEW_FLD_PIC
), false))
496 ResetFromWallpaperItem( *rSet
);
500 // condition of the preview button is persistent due to UserData
501 OUString aUserData
= GetUserData();
502 m_pBtnPreview
->Check( !aUserData
.isEmpty() && '1' == aUserData
[0] );
504 // don't be allowed to call ShowSelector() after reset anymore
505 bAllowShowSelector
= false;
508 // get and evaluate Input-BrushItem
509 const SvxBrushItem
* pBgdAttr
= NULL
;
510 sal_uInt16 nSlot
= SID_ATTR_BRUSH
;
511 const SfxPoolItem
* pItem
;
512 sal_uInt16 nDestValue
= USHRT_MAX
;
514 if ( SfxItemState::SET
== rSet
->GetItemState( SID_BACKGRND_DESTINATION
,
517 nDestValue
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
518 m_pTblLBox
->SelectEntryPos(nDestValue
);
520 switch ( nDestValue
)
523 nSlot
= SID_ATTR_BRUSH
;
526 nSlot
= SID_ATTR_BRUSH_ROW
;
529 nSlot
= SID_ATTR_BRUSH_TABLE
;
533 else if( SfxItemState::SET
== rSet
->GetItemState(
534 SID_PARA_BACKGRND_DESTINATION
, false, &pItem
) )
536 nDestValue
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
537 // character activated?
538 sal_Int32 nParaSel
= m_pParaLBox
->GetSelectEntryPos();
541 // then it was a "standard"-call
542 nDestValue
= nParaSel
;
544 m_pParaLBox
->SelectEntryPos(nDestValue
);
546 switch ( nDestValue
)
549 nSlot
= SID_ATTR_BRUSH
;
552 nSlot
= SID_ATTR_BRUSH_CHAR
;
556 //#111173# the destination item is missing when the parent style has been changed
557 if(USHRT_MAX
== nDestValue
&& (m_pParaLBox
->IsVisible()||m_pTblLBox
->IsVisible()))
559 sal_uInt16 nWhich
= GetWhich( nSlot
);
561 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
562 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
568 FillControls_Impl(*pBgdAttr
, aUserData
);
569 aBgdColor
= const_cast<SvxBrushItem
*>(pBgdAttr
)->GetColor();
573 m_pSelectTxt
->Hide();
575 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_SOLID
);
578 const SfxPoolItem
* pOld
= GetOldItem( *rSet
, SID_ATTR_BRUSH
);
581 aBgdColor
= static_cast<const SvxBrushItem
*>(pOld
)->GetColor();
584 if ( nDestValue
!= USHRT_MAX
)
586 if(m_pTblLBox
->IsVisible())
588 sal_Int32 nValue
= m_pTblLBox
->GetSelectEntryPos();
590 if ( pTableBck_Impl
)
592 DELETEZ( pTableBck_Impl
->pCellBrush
);
593 DELETEZ( pTableBck_Impl
->pRowBrush
);
594 DELETEZ( pTableBck_Impl
->pTableBrush
);
597 pTableBck_Impl
= new SvxBackgroundTable_Impl();
599 pTableBck_Impl
->nActPos
= nValue
;
601 nWhich
= GetWhich( SID_ATTR_BRUSH
);
602 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
604 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
605 pTableBck_Impl
->pCellBrush
= new SvxBrushItem(*pBgdAttr
);
607 pTableBck_Impl
->nCellWhich
= nWhich
;
609 if ( rSet
->GetItemState( SID_ATTR_BRUSH_ROW
, false ) >= SfxItemState::DEFAULT
)
611 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( SID_ATTR_BRUSH_ROW
) ));
612 pTableBck_Impl
->pRowBrush
= new SvxBrushItem(*pBgdAttr
);
614 pTableBck_Impl
->nRowWhich
= SID_ATTR_BRUSH_ROW
;
616 if ( rSet
->GetItemState( SID_ATTR_BRUSH_TABLE
, false ) >= SfxItemState::DEFAULT
)
618 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( SID_ATTR_BRUSH_TABLE
) ));
619 pTableBck_Impl
->pTableBrush
= new SvxBrushItem(*pBgdAttr
);
621 pTableBck_Impl
->nTableWhich
= SID_ATTR_BRUSH_TABLE
;
623 TblDestinationHdl_Impl(m_pTblLBox
);
624 m_pTblLBox
->SaveValue();
628 sal_Int32 nValue
= m_pParaLBox
->GetSelectEntryPos();
632 delete pParaBck_Impl
->pParaBrush
;
633 delete pParaBck_Impl
->pCharBrush
;
636 pParaBck_Impl
= new SvxBackgroundPara_Impl();
638 pParaBck_Impl
->nActPos
= nValue
;
640 nWhich
= GetWhich( SID_ATTR_BRUSH
);
641 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
643 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
644 pParaBck_Impl
->pParaBrush
= new SvxBrushItem(*pBgdAttr
);
647 nWhich
= GetWhich( SID_ATTR_BRUSH_CHAR
);
648 rSet
->GetItemState( nWhich
, true );
649 rSet
->GetItemState( nWhich
, false );
650 if ( rSet
->GetItemState( nWhich
, true ) > SfxItemState::DEFAULT
)
652 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
653 pParaBck_Impl
->pCharBrush
= new SvxBrushItem(*pBgdAttr
);
656 pParaBck_Impl
->pCharBrush
= new SvxBrushItem(SID_ATTR_BRUSH_CHAR
);
658 ParaDestinationHdl_Impl(m_pParaLBox
);
659 m_pParaLBox
->SaveValue();
664 void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet
& rSet
)
668 // condition of the preview button is persistent due to UserData
669 OUString aUserData
= GetUserData();
670 m_pBtnPreview
->Check( !aUserData
.isEmpty() && '1' == aUserData
[0] );
672 // get and evaluate Input-BrushItem
673 const SvxBrushItem
* pBgdAttr
= NULL
;
674 sal_uInt16 nSlot
= SID_VIEW_FLD_PIC
;
675 sal_uInt16 nWhich
= GetWhich( nSlot
);
676 boost::scoped_ptr
<SvxBrushItem
> pTemp
;
678 if ( rSet
.GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
680 const CntWallpaperItem
* pItem
= static_cast<const CntWallpaperItem
*>(&rSet
.Get( nWhich
));
681 pTemp
.reset(new SvxBrushItem( *pItem
, nWhich
));
682 pBgdAttr
= pTemp
.get();
689 FillControls_Impl(*pBgdAttr
, aUserData
);
690 // brush shall be kept when showing the graphic, too
691 if( aBgdColor
!= pBgdAttr
->GetColor() )
693 aBgdColor
= pBgdAttr
->GetColor();
694 sal_uInt16 nCol
= GetItemId_Impl(*m_pBackgroundColorSet
, aBgdColor
);
695 m_pBackgroundColorSet
->SelectItem( nCol
);
696 m_pPreviewWin1
->NotifyChange( aBgdColor
);
701 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_SOLID
);
704 const SfxPoolItem
* pOld
= GetOldItem( rSet
, SID_VIEW_FLD_PIC
);
706 aBgdColor
= Color( static_cast<const CntWallpaperItem
*>(pOld
)->GetColor() );
709 // We now have always a link to the background
711 m_pBtnLink
->Check( true );
712 m_pBtnLink
->Show( false );
715 /** When destroying a SfxTabPage this virtual method is called,
716 so that the TabPage can save internal information.
718 In this case the condition of the preview button is saved.
720 void SvxBackgroundTabPage::FillUserData()
724 SetUserData( m_pBtnPreview
->IsChecked() ? OUString('1') : OUString('0') );
727 bool SvxBackgroundTabPage::FillItemSet( SfxItemSet
* rCoreSet
)
729 if ( pPageImpl
->pLoadIdle
&& pPageImpl
->pLoadIdle
->IsActive() )
731 pPageImpl
->pLoadIdle
->Stop();
732 LoadIdleHdl_Impl( pPageImpl
->pLoadIdle
);
734 // os: Such a nonsense! One will always find such an item somewhere,
735 // but it must be existing in the rSet!
737 // const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
738 // if( pX && pX->ISA(SfxWallpaperItem))
739 if(SfxItemState::DEFAULT
<= rCoreSet
->GetItemState(GetWhich(SID_VIEW_FLD_PIC
), false))
740 return FillItemSetWithWallpaperItem( *rCoreSet
, SID_VIEW_FLD_PIC
);
742 bool bModified
= false;
743 sal_uInt16 nSlot
= SID_ATTR_BRUSH
;
745 if ( m_pTblLBox
->IsVisible() )
747 switch( m_pTblLBox
->GetSelectEntryPos() )
750 nSlot
= SID_ATTR_BRUSH
;
753 nSlot
= SID_ATTR_BRUSH_ROW
;
756 nSlot
= SID_ATTR_BRUSH_TABLE
;
760 else if (m_pParaLBox
->GetData() == m_pParaLBox
)
762 switch(m_pParaLBox
->GetSelectEntryPos())
765 nSlot
= SID_ATTR_BRUSH
;
768 nSlot
= SID_ATTR_BRUSH_CHAR
;
772 sal_uInt16 nWhich
= GetWhich( nSlot
);
774 const SfxPoolItem
* pOld
= GetOldItem( *rCoreSet
, nSlot
);
775 SfxItemState eOldItemState
= rCoreSet
->GetItemState(nSlot
, false);
776 const SfxItemSet
& rOldSet
= GetItemSet();
778 bool bGraphTransparencyChanged
= bGraphTransparency
&& m_pGraphTransMF
->IsValueChangedFromSaved();
781 const SvxBrushItem
& rOldItem
= static_cast<const SvxBrushItem
&>(*pOld
);
782 SvxGraphicPosition eOldPos
= rOldItem
.GetGraphicPos();
783 const bool bIsBrush
= ( drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
) );
785 // transparency has to be set if enabled, the color not already set to "No fill" and
786 if( bColTransparency
&&
787 aBgdColor
.GetTransparency() < 0xff)
789 aBgdColor
.SetTransparency(lcl_PercentToTransparency(static_cast<long>(m_pColTransMF
->GetValue())));
791 if ( ( (GPOS_NONE
== eOldPos
) && bIsBrush
)
792 || ( (GPOS_NONE
!= eOldPos
) && !bIsBrush
) ) // Brush <-> Bitmap changed?
794 // background art hasn't been changed:
796 if ( (GPOS_NONE
== eOldPos
) || !m_pLbSelect
->IsVisible() )
799 if ( rOldItem
.GetColor() != aBgdColor
||
800 (SfxItemState::DEFAULT
>= eOldItemState
&& !m_pBackgroundColorSet
->IsNoSelection()))
803 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
805 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
806 rCoreSet
->ClearItem( nWhich
);
812 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
813 const bool bIsLink
= m_pBtnLink
->IsChecked();
814 const bool bWasLink
= (NULL
!= rOldItem
.GetGraphicLink() );
817 if ( !bIsLink
&& !bIsGraphicValid
)
818 bIsGraphicValid
= LoadLinkedGraphic_Impl();
820 if ( bGraphTransparencyChanged
||
822 || bIsLink
!= bWasLink
823 || ( bWasLink
&& rOldItem
.GetGraphicLink()
825 || ( !bWasLink
&& rOldItem
.GetGraphic()->GetBitmap()
826 != aBgdGraphic
.GetBitmap() )
831 SvxBrushItem
aTmpBrush(nWhich
);
834 aTmpBrush
= SvxBrushItem( aBgdGraphicPath
,
840 aTmpBrush
= SvxBrushItem( aBgdGraphic
,
843 lcl_SetTransparency(aTmpBrush
, static_cast<long>(m_pGraphTransMF
->GetValue()));
845 rCoreSet
->Put(aTmpBrush
);
847 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
848 rCoreSet
->ClearItem( nWhich
);
851 else // Brush <-> Bitmap changed!
855 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
859 boost::scoped_ptr
<SvxBrushItem
> pTmpBrush
;
860 if ( m_pBtnLink
->IsChecked() )
862 pTmpBrush
.reset(new SvxBrushItem( aBgdGraphicPath
,
864 GetGraphicPosition_Impl(),
869 if ( !bIsGraphicValid
)
870 bIsGraphicValid
= LoadLinkedGraphic_Impl();
872 if ( bIsGraphicValid
)
873 pTmpBrush
.reset(new SvxBrushItem( aBgdGraphic
,
874 GetGraphicPosition_Impl(),
879 lcl_SetTransparency(*pTmpBrush
, static_cast<long>(m_pGraphTransMF
->GetValue()));
880 rCoreSet
->Put(*pTmpBrush
);
883 bModified
= ( bIsBrush
|| m_pBtnLink
->IsChecked() || bIsGraphicValid
);
886 else if ( SID_ATTR_BRUSH_CHAR
== nSlot
&& aBgdColor
!= Color( COL_WHITE
) )
888 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
892 if( m_pTblLBox
->IsVisible() )
894 // the current condition has already been put
895 if( nSlot
!= SID_ATTR_BRUSH
&& pTableBck_Impl
->pCellBrush
)
897 const SfxPoolItem
* pOldCell
=
898 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH
);
900 if ( *pTableBck_Impl
->pCellBrush
!= *pOldCell
)
902 rCoreSet
->Put( *pTableBck_Impl
->pCellBrush
);
907 if( nSlot
!= SID_ATTR_BRUSH_ROW
&& pTableBck_Impl
->pRowBrush
)
909 const SfxPoolItem
* pOldRow
=
910 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_ROW
);
912 if ( *pTableBck_Impl
->pRowBrush
!= *pOldRow
)
914 rCoreSet
->Put( *pTableBck_Impl
->pRowBrush
);
919 if( nSlot
!= SID_ATTR_BRUSH_TABLE
&& pTableBck_Impl
->pTableBrush
)
921 const SfxPoolItem
* pOldTable
=
922 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_TABLE
);
924 if ( *pTableBck_Impl
->pTableBrush
!= *pOldTable
)
926 rCoreSet
->Put( *pTableBck_Impl
->pTableBrush
);
931 if( m_pTblLBox
->IsValueChangedFromSaved() )
933 rCoreSet
->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION
,
934 m_pTblLBox
->GetSelectEntryPos() ) );
938 else if (m_pParaLBox
->GetData() == m_pParaLBox
)
940 // the current condition has already been put
941 if( nSlot
!= SID_ATTR_BRUSH
&& m_pParaLBox
->IsVisible()) // not in search format dialog
943 const SfxPoolItem
* pOldPara
=
944 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH
);
946 if ( *pParaBck_Impl
->pParaBrush
!= *pOldPara
)
948 rCoreSet
->Put( *pParaBck_Impl
->pParaBrush
);
953 if( nSlot
!= SID_ATTR_BRUSH_CHAR
)
955 const SfxPoolItem
* pOldChar
=
956 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_CHAR
);
957 DBG_ASSERT(pParaBck_Impl
, "pParaBck_Impl == NULL ?");
959 //#111173# crash report shows that pParaBck_Impl can be NULL, the cause is unknown
961 (*pParaBck_Impl
->pCharBrush
!= *pOldChar
||
962 *pParaBck_Impl
->pCharBrush
!= SvxBrushItem(SID_ATTR_BRUSH_CHAR
)))
964 rCoreSet
->Put( *pParaBck_Impl
->pCharBrush
);
969 if( m_pParaLBox
->IsValueChangedFromSaved() )
971 rCoreSet
->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION
,
972 m_pParaLBox
->GetSelectEntryPos() ) );
979 bool SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet
& rCoreSet
, sal_uInt16 nSlot
)
981 sal_uInt16 nWhich
= GetWhich( nSlot
);
982 const SfxPoolItem
* pOld
= GetOldItem( rCoreSet
, nSlot
);
983 DBG_ASSERT(pOld
,"FillItemSetWithWallpaperItem: Item not found");
986 const SfxItemSet
& rOldSet
= GetItemSet();
988 SvxBrushItem
rOldItem( static_cast<const CntWallpaperItem
&>(*pOld
), nWhich
);
989 SvxGraphicPosition eOldPos
= rOldItem
.GetGraphicPos();
990 const bool bIsBrush
= ( drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
) );
991 bool bModified
= false;
993 if ( ( (GPOS_NONE
== eOldPos
) && bIsBrush
)
994 || ( (GPOS_NONE
!= eOldPos
) && !bIsBrush
) ) // Brush <-> Bitmap changed?
996 // background art hasn't been changed
998 if ( (GPOS_NONE
== eOldPos
) || !m_pLbSelect
->IsVisible() )
1001 if ( rOldItem
.GetColor() != aBgdColor
)
1004 CntWallpaperItem
aItem( nWhich
);
1005 aItem
.SetColor( aBgdColor
);
1006 rCoreSet
.Put( aItem
);
1008 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
1009 rCoreSet
.ClearItem( nWhich
);
1013 // Bitmap-treatment:
1014 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
1016 bool bBitmapChanged
= ( ( eNewPos
!= eOldPos
) ||
1017 ( rOldItem
.GetGraphicLink() != aBgdGraphicPath
) );
1018 bool bBrushChanged
= ( rOldItem
.GetColor() != aBgdColor
);
1019 if( bBitmapChanged
|| bBrushChanged
)
1023 CntWallpaperItem
aItem( nWhich
);
1024 WallpaperStyle eWallStyle
= SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos
);
1025 aItem
.SetStyle( sal::static_int_cast
< sal_uInt16
>( eWallStyle
) );
1026 aItem
.SetColor( aBgdColor
);
1027 aItem
.SetBitmapURL( aBgdGraphicPath
);
1028 rCoreSet
.Put( aItem
);
1030 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
1031 rCoreSet
.ClearItem( nWhich
);
1034 else // Brush <-> Bitmap changed!
1036 CntWallpaperItem
aItem( nWhich
);
1039 aItem
.SetColor( aBgdColor
);
1040 rCoreSet
.Put( aItem
);
1044 WallpaperStyle eWallStyle
=
1045 SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
1046 aItem
.SetStyle( sal::static_int_cast
< sal_uInt16
>( eWallStyle
) );
1047 aItem
.SetColor( aBgdColor
);
1048 aItem
.SetBitmapURL( aBgdGraphicPath
);
1049 rCoreSet
.Put( aItem
);
1057 /** virtual method; is called on deactivation */
1058 SfxTabPage::sfxpg
SvxBackgroundTabPage::DeactivatePage( SfxItemSet
* _pSet
)
1060 if ( pPageImpl
->bIsImportDlgInExecute
)
1064 FillItemSet( _pSet
);
1069 void SvxBackgroundTabPage::PointChanged( vcl::Window
* , RECT_POINT
)
1071 // has to be implemented so that position control can work
1074 void SvxBackgroundTabPage::ShowSelector()
1076 if( bAllowShowSelector
)
1079 m_pSelectTxt
->Show();
1080 m_pLbSelect
->Show();
1081 m_pLbSelect
->SetSelectHdl( HDL(SelectHdl_Impl
) );
1082 m_pBtnLink
->SetClickHdl( HDL(FileClickHdl_Impl
) );
1083 m_pBtnPreview
->SetClickHdl( HDL(FileClickHdl_Impl
) );
1084 m_pBtnBrowse
->SetClickHdl( HDL(BrowseHdl_Impl
) );
1085 m_pBtnArea
->SetClickHdl( HDL(RadioClickHdl_Impl
) );
1086 m_pBtnTile
->SetClickHdl( HDL(RadioClickHdl_Impl
) );
1087 m_pBtnPosition
->SetClickHdl( HDL(RadioClickHdl_Impl
) );
1089 // delayed loading via timer (because of UI-Update)
1090 pPageImpl
->pLoadIdle
= new Idle
;
1091 pPageImpl
->pLoadIdle
->SetPriority( SchedulerPriority::LOWEST
);
1092 pPageImpl
->pLoadIdle
->SetIdleHdl(
1093 LINK( this, SvxBackgroundTabPage
, LoadIdleHdl_Impl
) );
1095 bAllowShowSelector
= false;
1097 if(nHtmlMode
& HTMLMODE_ON
)
1099 m_pBtnArea
->Enable(false);
1104 void SvxBackgroundTabPage::RaiseLoadError_Impl()
1106 SfxErrorContext
aContext( ERRCTX_SVX_BACKGROUND
,
1112 ErrorHandler::HandleError(
1113 *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE
,
1114 aBgdGraphicPath
) );
1117 bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
1119 bool bResult
= ( !aBgdGraphicPath
.isEmpty() ) &&
1120 ( GRFILTER_OK
== GraphicFilter::LoadGraphic( aBgdGraphicPath
,
1126 void SvxBackgroundTabPage::FillColorValueSets_Impl()
1128 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
1129 const SfxPoolItem
* pItem
= NULL
;
1130 XColorListRef pColorTable
= NULL
;
1131 if ( pDocSh
&& ( 0 != ( pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
) ) ) )
1133 pColorTable
= static_cast<const SvxColorListItem
*>(pItem
)->GetColorList();
1136 if ( !pColorTable
.is() )
1137 pColorTable
= XColorList::CreateStdColorList();
1139 if ( pColorTable
.is() )
1141 m_pBackgroundColorSet
->Clear();
1142 m_pBackgroundColorSet
->addEntriesForXColorList(*pColorTable
);
1145 const WinBits
nBits(m_pBackgroundColorSet
->GetStyle() | WB_ITEMBORDER
| WB_NAMEFIELD
| WB_NONEFIELD
);
1146 m_pBackgroundColorSet
->SetStyle(nBits
);
1147 m_pBackgroundColorSet
->SetColCount(SvxColorValueSet::getColumnCount());
1150 /** Hide the controls for editing the bitmap
1151 and show the controls for color settings instead.
1153 void SvxBackgroundTabPage::ShowColorUI_Impl()
1155 if (!m_pBackGroundColorFrame
->IsVisible())
1157 HideBitmapUI_Impl();
1158 m_pBackGroundColorFrame
->Show();
1160 if(bColTransparency
)
1162 m_pColTransFT
->Show();
1163 m_pColTransMF
->Show();
1168 void SvxBackgroundTabPage::HideColorUI_Impl()
1170 m_pBackGroundColorFrame
->Hide();
1173 /** Hide the controls for color settings
1174 and show controls for editing the bitmap instead.
1176 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1178 if (m_pLbSelect
->IsVisible() &&
1179 (m_pBackGroundColorFrame
->IsVisible() || !m_pFileFrame
->IsVisible()))
1184 m_pBitmapContainer
->Show();
1186 m_pFileFrame
->Show();
1187 m_pBtnLink
->Show(!bLinkOnly
&& !(nHtmlMode
& HTMLMODE_ON
));
1189 m_pTypeFrame
->Show();
1191 m_pPreviewWin2
->Show();
1192 m_pBtnPreview
->Show();
1194 m_pGraphTransFrame
->Show(bGraphTransparency
);
1195 m_pColTransFT
->Show(false);
1196 m_pColTransMF
->Show(false);
1200 void SvxBackgroundTabPage::HideBitmapUI_Impl()
1202 m_pBitmapContainer
->Hide();
1203 m_pFileFrame
->Hide();
1204 m_pTypeFrame
->Hide();
1205 m_pPreviewWin2
->Hide();
1206 m_pBtnPreview
->Hide();
1207 m_pGraphTransFrame
->Hide();
1210 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos
)
1216 m_pBtnArea
->Check();
1217 m_pWndPosition
->Disable();
1223 m_pBtnTile
->Check();
1224 m_pWndPosition
->Disable();
1230 m_pBtnPosition
->Check();
1231 m_pWndPosition
->Enable();
1232 RECT_POINT eNewPos
= RP_MM
;
1236 case GPOS_MM
: break;
1237 case GPOS_LT
: eNewPos
= RP_LT
; break;
1238 case GPOS_MT
: eNewPos
= RP_MT
; break;
1239 case GPOS_RT
: eNewPos
= RP_RT
; break;
1240 case GPOS_LM
: eNewPos
= RP_LM
; break;
1241 case GPOS_RM
: eNewPos
= RP_RM
; break;
1242 case GPOS_LB
: eNewPos
= RP_LB
; break;
1243 case GPOS_MB
: eNewPos
= RP_MB
; break;
1244 case GPOS_RB
: eNewPos
= RP_RB
; break;
1245 default: ;//prevent warning
1247 m_pWndPosition
->SetActualRP( eNewPos
);
1251 m_pWndPosition
->Invalidate();
1254 SvxGraphicPosition
SvxBackgroundTabPage::GetGraphicPosition_Impl()
1256 if ( m_pBtnTile
->IsChecked() )
1258 else if ( m_pBtnArea
->IsChecked() )
1262 switch ( m_pWndPosition
->GetActualRP() )
1264 case RP_LT
: return GPOS_LT
;
1265 case RP_MT
: return GPOS_MT
;
1266 case RP_RT
: return GPOS_RT
;
1267 case RP_LM
: return GPOS_LM
;
1268 case RP_MM
: return GPOS_MM
;
1269 case RP_RM
: return GPOS_RM
;
1270 case RP_LB
: return GPOS_LB
;
1271 case RP_MB
: return GPOS_MB
;
1272 case RP_RB
: return GPOS_RB
;
1281 /** Handler, called when color selection is changed */
1282 IMPL_LINK_NOARG(SvxBackgroundTabPage
, BackgroundColorHdl_Impl
)
1284 sal_uInt16 nItemId
= m_pBackgroundColorSet
->GetSelectItemId();
1285 Color aColor
= nItemId
? ( m_pBackgroundColorSet
->GetItemColor( nItemId
) ) : Color( COL_TRANSPARENT
);
1287 m_pPreviewWin1
->NotifyChange( aBgdColor
);
1288 bool bEnableTransp
= aBgdColor
.GetTransparency() < 0xff;
1289 m_pColTransFT
->Enable(bEnableTransp
);
1290 m_pColTransMF
->Enable(bEnableTransp
);
1294 IMPL_LINK_NOARG(SvxBackgroundTabPage
, SelectHdl_Impl
)
1296 if ( drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
) )
1299 m_pParaLBox
->Enable(); // drawing background can't be a bitmap
1303 ShowBitmapUI_Impl();
1304 m_pParaLBox
->Enable(false); // drawing background can't be a bitmap
1309 IMPL_LINK( SvxBackgroundTabPage
, FileClickHdl_Impl
, CheckBox
*, pBox
)
1311 if (m_pBtnLink
== pBox
)
1313 if ( m_pBtnLink
->IsChecked() )
1315 m_pFtUnlinked
->Hide();
1316 INetURLObject
aObj( aBgdGraphicPath
);
1318 if ( aObj
.GetProtocol() == INetProtocol::File
)
1319 aFilePath
= aObj
.getFSysPath( INetURLObject::FSYS_DETECT
);
1321 aFilePath
= aBgdGraphicPath
;
1322 m_pFtFile
->SetText( aFilePath
);
1327 m_pFtUnlinked
->Show();
1331 else if (m_pBtnPreview
== pBox
)
1333 if ( m_pBtnPreview
->IsChecked() )
1335 if ( !bIsGraphicValid
)
1336 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1338 if ( bIsGraphicValid
)
1340 Bitmap aBmp
= aBgdGraphic
.GetBitmap();
1341 m_pPreviewWin2
->NotifyChange( &aBmp
);
1345 if ( !aBgdGraphicPath
.isEmpty() ) // only for linked bitmap
1346 RaiseLoadError_Impl();
1347 m_pPreviewWin2
->NotifyChange( NULL
);
1351 m_pPreviewWin2
->NotifyChange( NULL
);
1356 IMPL_LINK( SvxBackgroundTabPage
, RadioClickHdl_Impl
, RadioButton
*, pBtn
)
1358 if (pBtn
== m_pBtnPosition
)
1360 if ( !m_pWndPosition
->IsEnabled() )
1362 m_pWndPosition
->Enable();
1363 m_pWndPosition
->Invalidate();
1366 else if ( m_pWndPosition
->IsEnabled() )
1368 m_pWndPosition
->Disable();
1369 m_pWndPosition
->Invalidate();
1374 /** Handler, called by pressing the browse button.
1375 Create graphic/insert dialog, set path and start.
1377 IMPL_LINK_NOARG(SvxBackgroundTabPage
, BrowseHdl_Impl
)
1379 if ( pPageImpl
->pLoadIdle
->IsActive() )
1381 bool bHtml
= 0 != ( nHtmlMode
& HTMLMODE_ON
);
1383 OUString
aStrBrowse(get
<vcl::Window
>("findgraphicsft")->GetText());
1384 pImportDlg
= new SvxOpenGraphicDialog( aStrBrowse
);
1385 if ( bHtml
|| bLinkOnly
)
1386 pImportDlg
->EnableLink(false);
1387 pImportDlg
->SetPath( aBgdGraphicPath
, m_pBtnLink
->IsChecked() );
1389 pPageImpl
->bIsImportDlgInExecute
= true;
1390 short nErr
= pImportDlg
->Execute();
1391 pPageImpl
->bIsImportDlgInExecute
= false;
1396 m_pBtnLink
->Check();
1397 // if link isn't checked and preview isn't, either,
1398 // activate preview, so that the user sees which
1399 // graphic he has chosen
1400 if ( !m_pBtnLink
->IsChecked() && !m_pBtnPreview
->IsChecked() )
1401 m_pBtnPreview
->Check( true );
1402 // timer-delayed loading of the graphic
1403 pPageImpl
->pLoadIdle
->Start();
1406 DELETEZ( pImportDlg
);
1410 /** Delayed loading of the graphic.
1411 Graphic is only loaded, if it's
1412 different to the current graphic.
1414 IMPL_LINK_TYPED( SvxBackgroundTabPage
, LoadIdleHdl_Impl
, Idle
* , pIdle
, void )
1416 if ( pIdle
== pPageImpl
->pLoadIdle
)
1418 pPageImpl
->pLoadIdle
->Stop();
1422 INetURLObject
aOld( aBgdGraphicPath
);
1423 INetURLObject
aNew( pImportDlg
->GetPath() );
1424 if ( aBgdGraphicPath
.isEmpty() || aNew
!= aOld
)
1427 aBgdGraphicPath
= pImportDlg
->GetPath();
1428 aBgdGraphicFilter
= pImportDlg
->GetCurrentFilter();
1429 bool bLink
= ( nHtmlMode
& HTMLMODE_ON
) || bLinkOnly
|| pImportDlg
->IsAsLink();
1430 m_pBtnLink
->Check( bLink
);
1431 m_pBtnLink
->Enable();
1433 if ( m_pBtnPreview
->IsChecked() )
1435 if( !pImportDlg
->GetGraphic(aBgdGraphic
) )
1437 bIsGraphicValid
= true;
1441 aBgdGraphicFilter
.clear();
1442 aBgdGraphicPath
.clear();
1443 bIsGraphicValid
= false;
1447 bIsGraphicValid
= false; // load graphic not until preview click
1449 if ( m_pBtnPreview
->IsChecked() && bIsGraphicValid
)
1451 Bitmap aBmp
= aBgdGraphic
.GetBitmap();
1452 m_pPreviewWin2
->NotifyChange( &aBmp
);
1455 m_pPreviewWin2
->NotifyChange( NULL
);
1458 FileClickHdl_Impl(m_pBtnLink
);
1459 DELETEZ( pImportDlg
);
1464 void SvxBackgroundTabPage::ShowTblControl()
1466 m_pTblLBox
->SetSelectHdl( HDL(TblDestinationHdl_Impl
) );
1467 m_pTblLBox
->SelectEntryPos(0);
1473 void SvxBackgroundTabPage::ShowParaControl(bool bCharOnly
)
1475 m_pParaLBox
->SetSelectHdl(HDL(ParaDestinationHdl_Impl
));
1476 m_pParaLBox
->SelectEntryPos(0);
1480 m_pParaLBox
->Show();
1483 m_pParaLBox
->SetData(m_pParaLBox
); // here it can be recognized that this mode is turned on
1486 IMPL_LINK( SvxBackgroundTabPage
, TblDestinationHdl_Impl
, ListBox
*, pBox
)
1488 sal_Int32 nSelPos
= pBox
->GetSelectEntryPos();
1489 if( pTableBck_Impl
&& pTableBck_Impl
->nActPos
!= nSelPos
)
1491 boost::scoped_ptr
<SvxBrushItem
> xItemHolder
;
1492 SvxBrushItem
* pActItem
= NULL
;
1493 sal_uInt16 nWhich
= 0;
1494 switch(pTableBck_Impl
->nActPos
)
1497 pActItem
= pTableBck_Impl
->pCellBrush
;
1498 nWhich
= pTableBck_Impl
->nCellWhich
;
1501 pActItem
= pTableBck_Impl
->pRowBrush
;
1502 nWhich
= pTableBck_Impl
->nRowWhich
;
1505 pActItem
= pTableBck_Impl
->pTableBrush
;
1506 nWhich
= pTableBck_Impl
->nTableWhich
;
1512 pTableBck_Impl
->nActPos
= nSelPos
;
1515 xItemHolder
.reset(new SvxBrushItem(nWhich
));
1516 pActItem
= xItemHolder
.get();
1518 if(drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
)) // brush selected
1520 *pActItem
= SvxBrushItem( aBgdColor
, nWhich
);
1524 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
1525 const bool bIsLink
= m_pBtnLink
->IsChecked();
1527 if ( !bIsLink
&& !bIsGraphicValid
)
1528 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1531 *pActItem
= SvxBrushItem( aBgdGraphicPath
,
1534 pActItem
->Which() );
1536 *pActItem
= SvxBrushItem( aBgdGraphic
,
1538 pActItem
->Which() );
1543 pActItem
= pTableBck_Impl
->pCellBrush
;
1544 m_pLbSelect
->Enable();
1545 nWhich
= pTableBck_Impl
->nCellWhich
;
1548 pActItem
= pTableBck_Impl
->pRowBrush
;
1549 nWhich
= pTableBck_Impl
->nRowWhich
;
1552 pActItem
= pTableBck_Impl
->pTableBrush
;
1553 m_pLbSelect
->Enable();
1554 nWhich
= pTableBck_Impl
->nTableWhich
;
1557 // The item will be new'ed again below, but that will be the
1558 // default item then, not an existing modified one.
1559 xItemHolder
.reset();
1563 OUString aUserData
= GetUserData();
1566 xItemHolder
.reset(new SvxBrushItem(nWhich
));
1567 pActItem
= xItemHolder
.get();
1569 FillControls_Impl(*pActItem
, aUserData
);
1574 IMPL_LINK( SvxBackgroundTabPage
, ParaDestinationHdl_Impl
, ListBox
*, pBox
)
1576 sal_Int32 nSelPos
= pBox
->GetSelectEntryPos();
1577 if( pParaBck_Impl
&& pParaBck_Impl
->nActPos
!= nSelPos
)
1579 SvxBrushItem
* pActItem
= NULL
;
1580 switch(pParaBck_Impl
->nActPos
)
1582 case PARA_DEST_PARA
:
1583 pActItem
= pParaBck_Impl
->pParaBrush
;
1585 case PARA_DEST_CHAR
:
1586 pActItem
= pParaBck_Impl
->pCharBrush
;
1589 /* we assert here because the rest of the code expect pActItem to be non NULL */
1593 pParaBck_Impl
->nActPos
= nSelPos
;
1594 if(drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
)) // brush selected
1596 sal_uInt16 nWhich
= pActItem
->Which();
1597 *pActItem
= SvxBrushItem( aBgdColor
, nWhich
);
1601 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
1602 const bool bIsLink
= m_pBtnLink
->IsChecked();
1604 if ( !bIsLink
&& !bIsGraphicValid
)
1605 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1608 *pActItem
= SvxBrushItem( aBgdGraphicPath
,
1611 pActItem
->Which() );
1613 *pActItem
= SvxBrushItem( aBgdGraphic
,
1615 pActItem
->Which() );
1619 case PARA_DEST_PARA
:
1620 pActItem
= pParaBck_Impl
->pParaBrush
;
1621 m_pLbSelect
->Enable();
1623 case PARA_DEST_CHAR
:
1625 pActItem
= pParaBck_Impl
->pCharBrush
;
1626 m_pLbSelect
->Enable(false);
1630 OUString aUserData
= GetUserData();
1631 FillControls_Impl(*pActItem
, aUserData
);
1636 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem
& rBgdAttr
,
1637 const OUString
& rUserData
)
1639 SvxGraphicPosition ePos
= rBgdAttr
.GetGraphicPos();
1640 const Color
& rColor
= rBgdAttr
.GetColor();
1641 if(bColTransparency
)
1643 m_pColTransMF
->SetValue(lcl_TransparencyToPercent(rColor
.GetTransparency()));
1644 m_pColTransMF
->SaveValue();
1645 bool bEnableTransp
= rColor
.GetTransparency() < 0xff;
1646 m_pColTransFT
->Enable(bEnableTransp
);
1647 m_pColTransMF
->Enable(bEnableTransp
);
1648 //the default setting should be "no transparency"
1650 m_pColTransMF
->SetValue(0);
1653 if ( GPOS_NONE
== ePos
|| !m_pLbSelect
->IsVisible() )
1655 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_SOLID
);
1657 Color
aTrColor( COL_TRANSPARENT
);
1660 sal_uInt16 nCol
= ( aTrColor
!= aBgdColor
) ?
1661 GetItemId_Impl(*m_pBackgroundColorSet
, aBgdColor
) : 0;
1663 if( aTrColor
!= aBgdColor
&& nCol
== 0)
1665 m_pBackgroundColorSet
->SetNoSelection();
1669 m_pBackgroundColorSet
->SelectItem( nCol
);
1672 m_pPreviewWin1
->NotifyChange( aBgdColor
);
1674 if ( m_pLbSelect
->IsVisible() ) // initialize graphic part
1676 aBgdGraphicFilter
.clear();
1677 aBgdGraphicPath
.clear();
1679 if ( rUserData
.isEmpty() )
1680 m_pBtnPreview
->Check( false );
1681 m_pBtnLink
->Check( false );
1682 m_pBtnLink
->Disable();
1683 m_pPreviewWin2
->NotifyChange( NULL
);
1684 SetGraphicPosition_Impl( GPOS_TILED
); // tiles as default
1689 const OUString aStrLink
= rBgdAttr
.GetGraphicLink();
1690 const OUString aStrFilter
= rBgdAttr
.GetGraphicFilter();
1692 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_BITMAP
);
1693 ShowBitmapUI_Impl();
1695 if ( !aStrLink
.isEmpty() )
1698 INetURLObject
aObj( aStrLink
);
1699 DBG_ASSERT( aObj
.GetProtocol() != INetProtocol::NotValid
, "Invalid URL!" );
1701 aBgdGraphicPath
= aStrLink
;
1702 m_pBtnLink
->Check( true );
1703 m_pBtnLink
->Enable();
1707 aBgdGraphicPath
.clear();
1708 m_pBtnLink
->Check( false );
1709 m_pBtnLink
->Disable();
1712 if (bGraphTransparency
)
1714 const GraphicObject
* pObject
= rBgdAttr
.GetGraphicObject();
1716 m_pGraphTransMF
->SetValue(lcl_TransparencyToPercent(pObject
->GetAttr().GetTransparency()));
1718 m_pGraphTransMF
->SetValue(0);
1719 m_pGraphTransMF
->SaveValue();
1722 FileClickHdl_Impl(m_pBtnLink
);
1724 aBgdGraphicFilter
= aStrFilter
;
1726 if ( aStrLink
.isEmpty() || m_pBtnPreview
->IsChecked() )
1728 // Graphic exists in the item and doesn't have
1731 const Graphic
* pGraphic
= rBgdAttr
.GetGraphic();
1733 if ( !pGraphic
&& m_pBtnPreview
->IsChecked() )
1734 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1735 else if ( pGraphic
)
1737 aBgdGraphic
= *pGraphic
;
1738 bIsGraphicValid
= true;
1740 if ( rUserData
.isEmpty() )
1741 m_pBtnPreview
->Check();
1745 RaiseLoadError_Impl();
1746 bIsGraphicValid
= false;
1748 if ( rUserData
.isEmpty() )
1749 m_pBtnPreview
->Check( false );
1753 if ( m_pBtnPreview
->IsChecked() && bIsGraphicValid
)
1755 Bitmap aBmp
= aBgdGraphic
.GetBitmap();
1756 m_pPreviewWin2
->NotifyChange( &aBmp
);
1759 m_pPreviewWin2
->NotifyChange( NULL
);
1761 SetGraphicPosition_Impl( ePos
);
1765 void SvxBackgroundTabPage::EnableTransparency(bool bColor
, bool bGraphic
)
1767 bColTransparency
= bColor
;
1768 bGraphTransparency
= bGraphic
;
1769 m_pColTransFT
->Show(bColor
);
1770 m_pColTransMF
->Show(bColor
);
1773 void SvxBackgroundTabPage::PageCreated(const SfxAllItemSet
& aSet
)
1775 SFX_ITEMSET_ARG (&aSet
,pFlagItem
,SfxUInt32Item
,SID_FLAG_TYPE
,false);
1779 SvxBackgroundTabFlags nFlags
= static_cast<SvxBackgroundTabFlags
>(pFlagItem
->GetValue());
1780 if (nFlags
& SvxBackgroundTabFlags::SHOW_TBLCTL
)
1782 if ( nFlags
& SvxBackgroundTabFlags::SHOW_PARACTL
)
1784 if ( nFlags
& SvxBackgroundTabFlags::SHOW_SELECTOR
)
1786 if ( nFlags
& SvxBackgroundTabFlags::ENABLE_TRANSPARENCY
)
1787 EnableTransparency(true, true);
1791 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */