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(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 , bHighlighting(false)
362 , pPageImpl(new SvxBackgroundPage_Impl
)
364 , pTableBck_Impl(NULL
)
365 , pParaBck_Impl(NULL
)
366 , pHighlighting(nullptr)
368 get(m_pAsGrid
, "asgrid");
369 get(m_pSelectTxt
, "asft");
370 get(m_pLbSelect
, "selectlb");
371 get(m_pTblDesc
, "forft");
372 get(m_pTblLBox
, "tablelb");
373 get(m_pParaLBox
, "paralb");
375 get(m_pBackGroundColorLabelFT
, "background_label");
376 get(m_pBackGroundColorFrame
, "backgroundcolorframe");
377 get(m_pBackgroundColorSet
, "backgroundcolorset");
378 get(m_pPreviewWin1
, "preview1");
380 get(m_pColTransFT
, "transparencyft");
381 get(m_pColTransMF
, "transparencymf");
382 get(m_pBtnPreview
, "showpreview");
384 get(m_pBitmapContainer
, "graphicgrid");
385 get(m_pFileFrame
, "fileframe");
386 get(m_pBtnBrowse
, "browse");
387 get(m_pBtnLink
, "link");
388 get(m_pFtUnlinked
, "unlinkedft");
389 get(m_pFtFile
, "fileft");
391 get(m_pTypeFrame
, "typeframe");
392 get(m_pBtnPosition
, "positionrb");
393 get(m_pBtnArea
, "arearb");
394 get(m_pBtnTile
, "tilerb");
395 get(m_pWndPosition
, "windowpos");
397 get(m_pGraphTransFrame
, "graphtransframe");
398 get(m_pGraphTransMF
, "graphtransmf");
400 get(m_pPreviewWin2
, "preview2");
401 m_pPreviewWin2
->setBmp(true);
403 // this page needs ExchangeSupport
404 SetExchangeSupport();
406 const SfxPoolItem
* pItem
;
407 SfxObjectShell
* pShell
;
409 if ( SfxItemState::SET
== rCoreSet
.GetItemState( SID_HTML_MODE
, false, &pItem
)
410 || ( 0 != ( pShell
= SfxObjectShell::Current()) &&
411 0 != ( pItem
= pShell
->GetItem( SID_HTML_MODE
) ) ) )
413 nHtmlMode
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
416 FillColorValueSets_Impl();
418 m_pBackgroundColorSet
->SetSelectHdl( HDL(BackgroundColorHdl_Impl
) );
419 m_pBackgroundColorSet
->SetStyle(m_pBackgroundColorSet
->GetStyle() | WB_ITEMBORDER
| WB_NAMEFIELD
| WB_NONEFIELD
);
420 m_pBackgroundColorSet
->SetText(SVX_RESSTR(RID_SVXSTR_TRANSPARENT
));
423 SvxBackgroundTabPage::~SvxBackgroundTabPage()
428 void SvxBackgroundTabPage::dispose()
432 delete pPageImpl
->pLoadIdle
;
442 delete pTableBck_Impl
->pCellBrush
;
443 delete pTableBck_Impl
->pRowBrush
;
444 delete pTableBck_Impl
->pTableBrush
;
445 delete pTableBck_Impl
;
446 pTableBck_Impl
= NULL
;
451 delete pParaBck_Impl
->pParaBrush
;
452 delete pParaBck_Impl
->pCharBrush
;
453 delete pParaBck_Impl
;
454 pParaBck_Impl
= NULL
;
458 m_pSelectTxt
.clear();
463 m_pBackGroundColorFrame
.clear();
464 m_pBackgroundColorSet
.clear();
465 m_pPreviewWin1
.clear();
466 m_pColTransFT
.clear();
467 m_pColTransMF
.clear();
468 m_pBtnPreview
.clear();
469 m_pBitmapContainer
.clear();
470 m_pFileFrame
.clear();
471 m_pBtnBrowse
.clear();
473 m_pFtUnlinked
.clear();
475 m_pTypeFrame
.clear();
476 m_pBtnPosition
.clear();
479 m_pWndPosition
.clear();
480 m_pGraphTransFrame
.clear();
481 m_pGraphTransMF
.clear();
482 m_pPreviewWin2
.clear();
483 SvxTabPage::dispose();
486 VclPtr
<SfxTabPage
> SvxBackgroundTabPage::Create( vcl::Window
* pParent
, const SfxItemSet
* rAttrSet
)
488 return VclPtr
<SvxBackgroundTabPage
>::Create( pParent
, *rAttrSet
);
491 void SvxBackgroundTabPage::Reset( const SfxItemSet
* rSet
)
493 // os: Such a nonsense! One will always find such an item somewhere,
494 // but it must be existing in the rSet!
495 // const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
496 // if( pX && pX->ISA(SfxWallpaperItem))
497 if(SfxItemState::DEFAULT
<= rSet
->GetItemState(GetWhich(SID_VIEW_FLD_PIC
), false))
499 ResetFromWallpaperItem( *rSet
);
503 // condition of the preview button is persistent due to UserData
504 OUString aUserData
= GetUserData();
505 m_pBtnPreview
->Check( !aUserData
.isEmpty() && '1' == aUserData
[0] );
507 // don't be allowed to call ShowSelector() after reset anymore
508 bAllowShowSelector
= false;
511 // get and evaluate Input-BrushItem
512 const SvxBrushItem
* pBgdAttr
= NULL
;
513 sal_uInt16 nSlot
= SID_ATTR_BRUSH
;
514 const SfxPoolItem
* pItem
;
515 sal_uInt16 nDestValue
= USHRT_MAX
;
517 if ( SfxItemState::SET
== rSet
->GetItemState( SID_BACKGRND_DESTINATION
,
520 nDestValue
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
521 m_pTblLBox
->SelectEntryPos(nDestValue
);
523 switch ( nDestValue
)
526 nSlot
= SID_ATTR_BRUSH
;
529 nSlot
= SID_ATTR_BRUSH_ROW
;
532 nSlot
= SID_ATTR_BRUSH_TABLE
;
536 else if( SfxItemState::SET
== rSet
->GetItemState(
537 SID_PARA_BACKGRND_DESTINATION
, false, &pItem
) )
539 nDestValue
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
540 // character activated?
541 sal_Int32 nParaSel
= m_pParaLBox
->GetSelectEntryPos();
544 // then it was a "standard"-call
545 nDestValue
= nParaSel
;
547 m_pParaLBox
->SelectEntryPos(nDestValue
);
549 switch ( nDestValue
)
552 nSlot
= SID_ATTR_BRUSH
;
555 nSlot
= SID_ATTR_BRUSH_CHAR
;
559 else if( bHighlighting
)
561 nSlot
= SID_ATTR_BRUSH_CHAR
;
563 //#111173# the destination item is missing when the parent style has been changed
564 if(USHRT_MAX
== nDestValue
&& (m_pParaLBox
->IsVisible()||m_pTblLBox
->IsVisible()))
566 sal_uInt16 nWhich
= GetWhich( nSlot
);
568 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
569 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
575 FillControls_Impl(*pBgdAttr
, aUserData
);
576 aBgdColor
= const_cast<SvxBrushItem
*>(pBgdAttr
)->GetColor();
580 m_pSelectTxt
->Hide();
582 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_SOLID
);
585 const SfxPoolItem
* pOld
= GetOldItem( *rSet
, SID_ATTR_BRUSH
);
588 aBgdColor
= static_cast<const SvxBrushItem
*>(pOld
)->GetColor();
591 if ( nDestValue
!= USHRT_MAX
)
593 if(m_pTblLBox
->IsVisible())
595 sal_Int32 nValue
= m_pTblLBox
->GetSelectEntryPos();
597 if ( pTableBck_Impl
)
599 DELETEZ( pTableBck_Impl
->pCellBrush
);
600 DELETEZ( pTableBck_Impl
->pRowBrush
);
601 DELETEZ( pTableBck_Impl
->pTableBrush
);
604 pTableBck_Impl
= new SvxBackgroundTable_Impl();
606 pTableBck_Impl
->nActPos
= nValue
;
608 nWhich
= GetWhich( SID_ATTR_BRUSH
);
609 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
611 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
612 pTableBck_Impl
->pCellBrush
= new SvxBrushItem(*pBgdAttr
);
614 pTableBck_Impl
->nCellWhich
= nWhich
;
616 if ( rSet
->GetItemState( SID_ATTR_BRUSH_ROW
, false ) >= SfxItemState::DEFAULT
)
618 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( SID_ATTR_BRUSH_ROW
) ));
619 pTableBck_Impl
->pRowBrush
= new SvxBrushItem(*pBgdAttr
);
621 pTableBck_Impl
->nRowWhich
= SID_ATTR_BRUSH_ROW
;
623 if ( rSet
->GetItemState( SID_ATTR_BRUSH_TABLE
, false ) >= SfxItemState::DEFAULT
)
625 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( SID_ATTR_BRUSH_TABLE
) ));
626 pTableBck_Impl
->pTableBrush
= new SvxBrushItem(*pBgdAttr
);
628 pTableBck_Impl
->nTableWhich
= SID_ATTR_BRUSH_TABLE
;
630 TblDestinationHdl_Impl(m_pTblLBox
);
631 m_pTblLBox
->SaveValue();
633 else if (m_pParaLBox
->GetData() == m_pParaLBox
)
635 sal_Int32 nValue
= m_pParaLBox
->GetSelectEntryPos();
639 delete pParaBck_Impl
->pParaBrush
;
640 delete pParaBck_Impl
->pCharBrush
;
643 pParaBck_Impl
= new SvxBackgroundPara_Impl();
645 pParaBck_Impl
->nActPos
= nValue
;
647 nWhich
= GetWhich( SID_ATTR_BRUSH
);
648 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
650 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
651 pParaBck_Impl
->pParaBrush
= new SvxBrushItem(*pBgdAttr
);
654 nWhich
= GetWhich( SID_ATTR_BRUSH_CHAR
);
655 rSet
->GetItemState( nWhich
, true );
656 rSet
->GetItemState( nWhich
, false );
657 if ( rSet
->GetItemState( nWhich
, true ) > SfxItemState::DEFAULT
)
659 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
660 pParaBck_Impl
->pCharBrush
= new SvxBrushItem(*pBgdAttr
);
663 pParaBck_Impl
->pCharBrush
= new SvxBrushItem(SID_ATTR_BRUSH_CHAR
);
665 ParaDestinationHdl_Impl(m_pParaLBox
);
666 m_pParaLBox
->SaveValue();
668 else if( bHighlighting
)
670 nWhich
= GetWhich( SID_ATTR_BRUSH_CHAR
);
671 if ( rSet
->GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
673 pBgdAttr
= static_cast<const SvxBrushItem
*>(&( rSet
->Get( nWhich
) ));
674 pHighlighting
.reset(new SvxBrushItem(*pBgdAttr
));
680 void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet
& rSet
)
684 // condition of the preview button is persistent due to UserData
685 OUString aUserData
= GetUserData();
686 m_pBtnPreview
->Check( !aUserData
.isEmpty() && '1' == aUserData
[0] );
688 // get and evaluate Input-BrushItem
689 const SvxBrushItem
* pBgdAttr
= NULL
;
690 sal_uInt16 nSlot
= SID_VIEW_FLD_PIC
;
691 sal_uInt16 nWhich
= GetWhich( nSlot
);
692 boost::scoped_ptr
<SvxBrushItem
> pTemp
;
694 if ( rSet
.GetItemState( nWhich
, false ) >= SfxItemState::DEFAULT
)
696 const CntWallpaperItem
* pItem
= static_cast<const CntWallpaperItem
*>(&rSet
.Get( nWhich
));
697 pTemp
.reset(new SvxBrushItem( *pItem
, nWhich
));
698 pBgdAttr
= pTemp
.get();
705 FillControls_Impl(*pBgdAttr
, aUserData
);
706 // brush shall be kept when showing the graphic, too
707 if( aBgdColor
!= pBgdAttr
->GetColor() )
709 aBgdColor
= pBgdAttr
->GetColor();
710 sal_uInt16 nCol
= GetItemId_Impl(*m_pBackgroundColorSet
, aBgdColor
);
711 m_pBackgroundColorSet
->SelectItem( nCol
);
712 m_pPreviewWin1
->NotifyChange( aBgdColor
);
717 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_SOLID
);
720 const SfxPoolItem
* pOld
= GetOldItem( rSet
, SID_VIEW_FLD_PIC
);
722 aBgdColor
= Color( static_cast<const CntWallpaperItem
*>(pOld
)->GetColor() );
725 // We now have always a link to the background
727 m_pBtnLink
->Check( true );
728 m_pBtnLink
->Show( false );
731 /** When destroying a SfxTabPage this virtual method is called,
732 so that the TabPage can save internal information.
734 In this case the condition of the preview button is saved.
736 void SvxBackgroundTabPage::FillUserData()
740 SetUserData( m_pBtnPreview
->IsChecked() ? OUString('1') : OUString('0') );
743 bool SvxBackgroundTabPage::FillItemSet( SfxItemSet
* rCoreSet
)
745 if ( pPageImpl
->pLoadIdle
&& pPageImpl
->pLoadIdle
->IsActive() )
747 pPageImpl
->pLoadIdle
->Stop();
748 LoadIdleHdl_Impl( pPageImpl
->pLoadIdle
);
750 // os: Such a nonsense! One will always find such an item somewhere,
751 // but it must be existing in the rSet!
753 // const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
754 // if( pX && pX->ISA(SfxWallpaperItem))
755 if(SfxItemState::DEFAULT
<= rCoreSet
->GetItemState(GetWhich(SID_VIEW_FLD_PIC
), false))
756 return FillItemSetWithWallpaperItem( *rCoreSet
, SID_VIEW_FLD_PIC
);
758 bool bModified
= false;
759 sal_uInt16 nSlot
= SID_ATTR_BRUSH
;
761 if ( m_pTblLBox
->IsVisible() )
763 switch( m_pTblLBox
->GetSelectEntryPos() )
766 nSlot
= SID_ATTR_BRUSH
;
769 nSlot
= SID_ATTR_BRUSH_ROW
;
772 nSlot
= SID_ATTR_BRUSH_TABLE
;
776 else if (m_pParaLBox
->GetData() == m_pParaLBox
)
778 switch(m_pParaLBox
->GetSelectEntryPos())
781 nSlot
= SID_ATTR_BRUSH
;
784 nSlot
= SID_ATTR_BRUSH_CHAR
;
788 else if( bHighlighting
)
790 nSlot
= SID_ATTR_BRUSH_CHAR
;
792 sal_uInt16 nWhich
= GetWhich( nSlot
);
794 const SfxPoolItem
* pOld
= GetOldItem( *rCoreSet
, nSlot
);
795 SfxItemState eOldItemState
= rCoreSet
->GetItemState(nSlot
, false);
796 const SfxItemSet
& rOldSet
= GetItemSet();
798 bool bGraphTransparencyChanged
= bGraphTransparency
&& m_pGraphTransMF
->IsValueChangedFromSaved();
801 const SvxBrushItem
& rOldItem
= static_cast<const SvxBrushItem
&>(*pOld
);
802 SvxGraphicPosition eOldPos
= rOldItem
.GetGraphicPos();
803 const bool bIsBrush
= ( drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
) );
805 // transparency has to be set if enabled, the color not already set to "No fill" and
806 if( bColTransparency
&&
807 aBgdColor
.GetTransparency() < 0xff)
809 aBgdColor
.SetTransparency(lcl_PercentToTransparency(static_cast<long>(m_pColTransMF
->GetValue())));
811 if ( ( (GPOS_NONE
== eOldPos
) && bIsBrush
)
812 || ( (GPOS_NONE
!= eOldPos
) && !bIsBrush
) ) // Brush <-> Bitmap changed?
814 // background art hasn't been changed:
816 if ( (GPOS_NONE
== eOldPos
) || !m_pLbSelect
->IsVisible() )
819 if ( rOldItem
.GetColor() != aBgdColor
||
820 (SfxItemState::DEFAULT
>= eOldItemState
&& !m_pBackgroundColorSet
->IsNoSelection()))
823 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
825 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
826 rCoreSet
->ClearItem( nWhich
);
832 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
833 const bool bIsLink
= m_pBtnLink
->IsChecked();
834 const bool bWasLink
= (NULL
!= rOldItem
.GetGraphicLink() );
837 if ( !bIsLink
&& !bIsGraphicValid
)
838 bIsGraphicValid
= LoadLinkedGraphic_Impl();
840 bool bModifyBrush
= false;
841 if (bGraphTransparencyChanged
|| eNewPos
!= eOldPos
|| bIsLink
!= bWasLink
)
843 else if (bWasLink
&& rOldItem
.GetGraphicLink() != aBgdGraphicPath
)
847 const Graphic
* pGraphic
= rOldItem
.GetGraphic();
849 bModifyBrush
= pGraphic
->GetBitmap() != aBgdGraphic
.GetBitmap();
855 SvxBrushItem
aTmpBrush(nWhich
);
858 aTmpBrush
= SvxBrushItem( aBgdGraphicPath
,
864 aTmpBrush
= SvxBrushItem( aBgdGraphic
,
867 lcl_SetTransparency(aTmpBrush
, static_cast<long>(m_pGraphTransMF
->GetValue()));
869 rCoreSet
->Put(aTmpBrush
);
871 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
872 rCoreSet
->ClearItem( nWhich
);
875 else // Brush <-> Bitmap changed!
879 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
883 boost::scoped_ptr
<SvxBrushItem
> pTmpBrush
;
884 if ( m_pBtnLink
->IsChecked() )
886 pTmpBrush
.reset(new SvxBrushItem( aBgdGraphicPath
,
888 GetGraphicPosition_Impl(),
893 if ( !bIsGraphicValid
)
894 bIsGraphicValid
= LoadLinkedGraphic_Impl();
896 if ( bIsGraphicValid
)
897 pTmpBrush
.reset(new SvxBrushItem( aBgdGraphic
,
898 GetGraphicPosition_Impl(),
903 lcl_SetTransparency(*pTmpBrush
, static_cast<long>(m_pGraphTransMF
->GetValue()));
904 rCoreSet
->Put(*pTmpBrush
);
907 bModified
= ( bIsBrush
|| m_pBtnLink
->IsChecked() || bIsGraphicValid
);
910 else if ( SID_ATTR_BRUSH_CHAR
== nSlot
&& aBgdColor
!= Color( COL_WHITE
) )
912 rCoreSet
->Put( SvxBrushItem( aBgdColor
, nWhich
) );
916 if( m_pTblLBox
->IsVisible() )
918 // the current condition has already been put
919 if( nSlot
!= SID_ATTR_BRUSH
&& pTableBck_Impl
->pCellBrush
)
921 const SfxPoolItem
* pOldCell
=
922 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH
);
924 if ( *pTableBck_Impl
->pCellBrush
!= *pOldCell
)
926 rCoreSet
->Put( *pTableBck_Impl
->pCellBrush
);
931 if( nSlot
!= SID_ATTR_BRUSH_ROW
&& pTableBck_Impl
->pRowBrush
)
933 const SfxPoolItem
* pOldRow
=
934 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_ROW
);
936 if ( *pTableBck_Impl
->pRowBrush
!= *pOldRow
)
938 rCoreSet
->Put( *pTableBck_Impl
->pRowBrush
);
943 if( nSlot
!= SID_ATTR_BRUSH_TABLE
&& pTableBck_Impl
->pTableBrush
)
945 const SfxPoolItem
* pOldTable
=
946 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_TABLE
);
948 if ( *pTableBck_Impl
->pTableBrush
!= *pOldTable
)
950 rCoreSet
->Put( *pTableBck_Impl
->pTableBrush
);
955 if( m_pTblLBox
->IsValueChangedFromSaved() )
957 rCoreSet
->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION
,
958 m_pTblLBox
->GetSelectEntryPos() ) );
962 else if (m_pParaLBox
->GetData() == m_pParaLBox
)
964 // the current condition has already been put
965 if( nSlot
!= SID_ATTR_BRUSH
&& m_pParaLBox
->IsVisible()) // not in search format dialog
967 const SfxPoolItem
* pOldPara
=
968 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH
);
970 if ( *pParaBck_Impl
->pParaBrush
!= *pOldPara
)
972 rCoreSet
->Put( *pParaBck_Impl
->pParaBrush
);
977 if( nSlot
!= SID_ATTR_BRUSH_CHAR
)
979 const SfxPoolItem
* pOldChar
=
980 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_CHAR
);
981 DBG_ASSERT(pParaBck_Impl
, "pParaBck_Impl == NULL ?");
983 //#111173# crash report shows that pParaBck_Impl can be NULL, the cause is unknown
985 (*pParaBck_Impl
->pCharBrush
!= *pOldChar
||
986 *pParaBck_Impl
->pCharBrush
!= SvxBrushItem(SID_ATTR_BRUSH_CHAR
)))
988 rCoreSet
->Put( *pParaBck_Impl
->pCharBrush
);
993 if( m_pParaLBox
->IsValueChangedFromSaved() )
995 rCoreSet
->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION
,
996 m_pParaLBox
->GetSelectEntryPos() ) );
1000 else if( bHighlighting
)
1002 if( nSlot
!= SID_ATTR_BRUSH_CHAR
)
1004 const SfxPoolItem
* pOldChar
=
1005 GetOldItem( *rCoreSet
, SID_ATTR_BRUSH_CHAR
);
1006 if ( pOldChar
&& pHighlighting
&&
1007 (*pHighlighting
!= *pOldChar
|| *pHighlighting
!= SvxBrushItem(SID_ATTR_BRUSH_CHAR
)))
1009 rCoreSet
->Put( *pHighlighting
);
1017 bool SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet
& rCoreSet
, sal_uInt16 nSlot
)
1019 sal_uInt16 nWhich
= GetWhich( nSlot
);
1020 const SfxPoolItem
* pOld
= GetOldItem( rCoreSet
, nSlot
);
1021 DBG_ASSERT(pOld
,"FillItemSetWithWallpaperItem: Item not found");
1024 const SfxItemSet
& rOldSet
= GetItemSet();
1026 SvxBrushItem
rOldItem( static_cast<const CntWallpaperItem
&>(*pOld
), nWhich
);
1027 SvxGraphicPosition eOldPos
= rOldItem
.GetGraphicPos();
1028 const bool bIsBrush
= ( drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
) );
1029 bool bModified
= false;
1031 if ( ( (GPOS_NONE
== eOldPos
) && bIsBrush
)
1032 || ( (GPOS_NONE
!= eOldPos
) && !bIsBrush
) ) // Brush <-> Bitmap changed?
1034 // background art hasn't been changed
1036 if ( (GPOS_NONE
== eOldPos
) || !m_pLbSelect
->IsVisible() )
1039 if ( rOldItem
.GetColor() != aBgdColor
)
1042 CntWallpaperItem
aItem( nWhich
);
1043 aItem
.SetColor( aBgdColor
);
1044 rCoreSet
.Put( aItem
);
1046 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
1047 rCoreSet
.ClearItem( nWhich
);
1051 // Bitmap-treatment:
1052 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
1054 bool bBitmapChanged
= ( ( eNewPos
!= eOldPos
) ||
1055 ( rOldItem
.GetGraphicLink() != aBgdGraphicPath
) );
1056 bool bBrushChanged
= ( rOldItem
.GetColor() != aBgdColor
);
1057 if( bBitmapChanged
|| bBrushChanged
)
1061 CntWallpaperItem
aItem( nWhich
);
1062 WallpaperStyle eWallStyle
= SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos
);
1063 aItem
.SetStyle( sal::static_int_cast
< sal_uInt16
>( eWallStyle
) );
1064 aItem
.SetColor( aBgdColor
);
1065 aItem
.SetBitmapURL( aBgdGraphicPath
);
1066 rCoreSet
.Put( aItem
);
1068 else if ( SfxItemState::DEFAULT
== rOldSet
.GetItemState( nWhich
, false ) )
1069 rCoreSet
.ClearItem( nWhich
);
1072 else // Brush <-> Bitmap changed!
1074 CntWallpaperItem
aItem( nWhich
);
1077 aItem
.SetColor( aBgdColor
);
1078 rCoreSet
.Put( aItem
);
1082 WallpaperStyle eWallStyle
=
1083 SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
1084 aItem
.SetStyle( sal::static_int_cast
< sal_uInt16
>( eWallStyle
) );
1085 aItem
.SetColor( aBgdColor
);
1086 aItem
.SetBitmapURL( aBgdGraphicPath
);
1087 rCoreSet
.Put( aItem
);
1095 /** virtual method; is called on deactivation */
1096 SfxTabPage::sfxpg
SvxBackgroundTabPage::DeactivatePage( SfxItemSet
* _pSet
)
1098 if ( pPageImpl
->bIsImportDlgInExecute
)
1102 FillItemSet( _pSet
);
1107 void SvxBackgroundTabPage::PointChanged( vcl::Window
* , RECT_POINT
)
1109 // has to be implemented so that position control can work
1112 void SvxBackgroundTabPage::ShowSelector()
1114 if( bAllowShowSelector
)
1117 m_pSelectTxt
->Show();
1118 m_pLbSelect
->Show();
1119 m_pLbSelect
->SetSelectHdl( HDL(SelectHdl_Impl
) );
1120 m_pBtnLink
->SetClickHdl( HDL(FileClickHdl_Impl
) );
1121 m_pBtnPreview
->SetClickHdl( HDL(FileClickHdl_Impl
) );
1122 m_pBtnBrowse
->SetClickHdl( HDL(BrowseHdl_Impl
) );
1123 m_pBtnArea
->SetClickHdl( HDL(RadioClickHdl_Impl
) );
1124 m_pBtnTile
->SetClickHdl( HDL(RadioClickHdl_Impl
) );
1125 m_pBtnPosition
->SetClickHdl( HDL(RadioClickHdl_Impl
) );
1127 // delayed loading via timer (because of UI-Update)
1128 pPageImpl
->pLoadIdle
= new Idle
;
1129 pPageImpl
->pLoadIdle
->SetPriority( SchedulerPriority::LOWEST
);
1130 pPageImpl
->pLoadIdle
->SetIdleHdl(
1131 LINK( this, SvxBackgroundTabPage
, LoadIdleHdl_Impl
) );
1133 bAllowShowSelector
= false;
1135 if(nHtmlMode
& HTMLMODE_ON
)
1137 m_pBtnArea
->Enable(false);
1142 void SvxBackgroundTabPage::RaiseLoadError_Impl()
1144 SfxErrorContext
aContext( ERRCTX_SVX_BACKGROUND
,
1150 ErrorHandler::HandleError(
1151 *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE
,
1152 aBgdGraphicPath
) );
1155 bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
1157 bool bResult
= ( !aBgdGraphicPath
.isEmpty() ) &&
1158 ( GRFILTER_OK
== GraphicFilter::LoadGraphic( aBgdGraphicPath
,
1164 void SvxBackgroundTabPage::FillColorValueSets_Impl()
1166 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
1167 const SfxPoolItem
* pItem
= NULL
;
1168 XColorListRef pColorTable
= NULL
;
1169 if ( pDocSh
&& ( 0 != ( pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
) ) ) )
1171 pColorTable
= static_cast<const SvxColorListItem
*>(pItem
)->GetColorList();
1174 if ( !pColorTable
.is() )
1175 pColorTable
= XColorList::CreateStdColorList();
1177 if ( pColorTable
.is() )
1179 m_pBackgroundColorSet
->Clear();
1180 m_pBackgroundColorSet
->addEntriesForXColorList(*pColorTable
);
1183 const WinBits
nBits(m_pBackgroundColorSet
->GetStyle() | WB_ITEMBORDER
| WB_NAMEFIELD
| WB_NONEFIELD
);
1184 m_pBackgroundColorSet
->SetStyle(nBits
);
1185 m_pBackgroundColorSet
->SetColCount(SvxColorValueSet::getColumnCount());
1188 /** Hide the controls for editing the bitmap
1189 and show the controls for color settings instead.
1191 void SvxBackgroundTabPage::ShowColorUI_Impl()
1193 if (!m_pBackGroundColorFrame
->IsVisible())
1195 HideBitmapUI_Impl();
1196 m_pBackGroundColorFrame
->Show();
1198 if(bColTransparency
)
1200 m_pColTransFT
->Show();
1201 m_pColTransMF
->Show();
1206 void SvxBackgroundTabPage::HideColorUI_Impl()
1208 m_pBackGroundColorFrame
->Hide();
1211 /** Hide the controls for color settings
1212 and show controls for editing the bitmap instead.
1214 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1216 if (m_pLbSelect
->IsVisible() &&
1217 (m_pBackGroundColorFrame
->IsVisible() || !m_pFileFrame
->IsVisible()))
1222 m_pBitmapContainer
->Show();
1224 m_pFileFrame
->Show();
1225 m_pBtnLink
->Show(!bLinkOnly
&& !(nHtmlMode
& HTMLMODE_ON
));
1227 m_pTypeFrame
->Show();
1229 m_pPreviewWin2
->Show();
1230 m_pBtnPreview
->Show();
1232 m_pGraphTransFrame
->Show(bGraphTransparency
);
1233 m_pColTransFT
->Show(false);
1234 m_pColTransMF
->Show(false);
1238 void SvxBackgroundTabPage::HideBitmapUI_Impl()
1240 m_pBitmapContainer
->Hide();
1241 m_pFileFrame
->Hide();
1242 m_pTypeFrame
->Hide();
1243 m_pPreviewWin2
->Hide();
1244 m_pBtnPreview
->Hide();
1245 m_pGraphTransFrame
->Hide();
1248 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos
)
1254 m_pBtnArea
->Check();
1255 m_pWndPosition
->Disable();
1261 m_pBtnTile
->Check();
1262 m_pWndPosition
->Disable();
1268 m_pBtnPosition
->Check();
1269 m_pWndPosition
->Enable();
1270 RECT_POINT eNewPos
= RP_MM
;
1274 case GPOS_MM
: break;
1275 case GPOS_LT
: eNewPos
= RP_LT
; break;
1276 case GPOS_MT
: eNewPos
= RP_MT
; break;
1277 case GPOS_RT
: eNewPos
= RP_RT
; break;
1278 case GPOS_LM
: eNewPos
= RP_LM
; break;
1279 case GPOS_RM
: eNewPos
= RP_RM
; break;
1280 case GPOS_LB
: eNewPos
= RP_LB
; break;
1281 case GPOS_MB
: eNewPos
= RP_MB
; break;
1282 case GPOS_RB
: eNewPos
= RP_RB
; break;
1283 default: ;//prevent warning
1285 m_pWndPosition
->SetActualRP( eNewPos
);
1289 m_pWndPosition
->Invalidate();
1292 SvxGraphicPosition
SvxBackgroundTabPage::GetGraphicPosition_Impl()
1294 if ( m_pBtnTile
->IsChecked() )
1296 else if ( m_pBtnArea
->IsChecked() )
1300 switch ( m_pWndPosition
->GetActualRP() )
1302 case RP_LT
: return GPOS_LT
;
1303 case RP_MT
: return GPOS_MT
;
1304 case RP_RT
: return GPOS_RT
;
1305 case RP_LM
: return GPOS_LM
;
1306 case RP_MM
: return GPOS_MM
;
1307 case RP_RM
: return GPOS_RM
;
1308 case RP_LB
: return GPOS_LB
;
1309 case RP_MB
: return GPOS_MB
;
1310 case RP_RB
: return GPOS_RB
;
1319 /** Handler, called when color selection is changed */
1320 IMPL_LINK_NOARG(SvxBackgroundTabPage
, BackgroundColorHdl_Impl
)
1322 sal_uInt16 nItemId
= m_pBackgroundColorSet
->GetSelectItemId();
1323 Color aColor
= nItemId
? ( m_pBackgroundColorSet
->GetItemColor( nItemId
) ) : Color( COL_TRANSPARENT
);
1325 m_pPreviewWin1
->NotifyChange( aBgdColor
);
1326 bool bEnableTransp
= aBgdColor
.GetTransparency() < 0xff;
1327 m_pColTransFT
->Enable(bEnableTransp
);
1328 m_pColTransMF
->Enable(bEnableTransp
);
1332 IMPL_LINK_NOARG(SvxBackgroundTabPage
, SelectHdl_Impl
)
1334 if ( drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
) )
1337 m_pParaLBox
->Enable(); // drawing background can't be a bitmap
1341 ShowBitmapUI_Impl();
1342 m_pParaLBox
->Enable(false); // drawing background can't be a bitmap
1347 IMPL_LINK( SvxBackgroundTabPage
, FileClickHdl_Impl
, CheckBox
*, pBox
)
1349 if (m_pBtnLink
== pBox
)
1351 if ( m_pBtnLink
->IsChecked() )
1353 m_pFtUnlinked
->Hide();
1354 INetURLObject
aObj( aBgdGraphicPath
);
1356 if ( aObj
.GetProtocol() == INetProtocol::File
)
1357 aFilePath
= aObj
.getFSysPath( INetURLObject::FSYS_DETECT
);
1359 aFilePath
= aBgdGraphicPath
;
1360 m_pFtFile
->SetText( aFilePath
);
1365 m_pFtUnlinked
->Show();
1369 else if (m_pBtnPreview
== pBox
)
1371 if ( m_pBtnPreview
->IsChecked() )
1373 if ( !bIsGraphicValid
)
1374 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1376 if ( bIsGraphicValid
)
1378 Bitmap aBmp
= aBgdGraphic
.GetBitmap();
1379 m_pPreviewWin2
->NotifyChange( &aBmp
);
1383 if ( !aBgdGraphicPath
.isEmpty() ) // only for linked bitmap
1384 RaiseLoadError_Impl();
1385 m_pPreviewWin2
->NotifyChange( NULL
);
1389 m_pPreviewWin2
->NotifyChange( NULL
);
1394 IMPL_LINK( SvxBackgroundTabPage
, RadioClickHdl_Impl
, RadioButton
*, pBtn
)
1396 if (pBtn
== m_pBtnPosition
)
1398 if ( !m_pWndPosition
->IsEnabled() )
1400 m_pWndPosition
->Enable();
1401 m_pWndPosition
->Invalidate();
1404 else if ( m_pWndPosition
->IsEnabled() )
1406 m_pWndPosition
->Disable();
1407 m_pWndPosition
->Invalidate();
1412 /** Handler, called by pressing the browse button.
1413 Create graphic/insert dialog, set path and start.
1415 IMPL_LINK_NOARG(SvxBackgroundTabPage
, BrowseHdl_Impl
)
1417 if ( pPageImpl
->pLoadIdle
->IsActive() )
1419 bool bHtml
= 0 != ( nHtmlMode
& HTMLMODE_ON
);
1421 OUString
aStrBrowse(get
<vcl::Window
>("findgraphicsft")->GetText());
1422 pImportDlg
= new SvxOpenGraphicDialog( aStrBrowse
);
1423 if ( bHtml
|| bLinkOnly
)
1424 pImportDlg
->EnableLink(false);
1425 pImportDlg
->SetPath( aBgdGraphicPath
, m_pBtnLink
->IsChecked() );
1427 pPageImpl
->bIsImportDlgInExecute
= true;
1428 short nErr
= pImportDlg
->Execute();
1429 pPageImpl
->bIsImportDlgInExecute
= false;
1434 m_pBtnLink
->Check();
1435 // if link isn't checked and preview isn't, either,
1436 // activate preview, so that the user sees which
1437 // graphic he has chosen
1438 if ( !m_pBtnLink
->IsChecked() && !m_pBtnPreview
->IsChecked() )
1439 m_pBtnPreview
->Check( true );
1440 // timer-delayed loading of the graphic
1441 pPageImpl
->pLoadIdle
->Start();
1444 DELETEZ( pImportDlg
);
1448 /** Delayed loading of the graphic.
1449 Graphic is only loaded, if it's
1450 different to the current graphic.
1452 IMPL_LINK_TYPED( SvxBackgroundTabPage
, LoadIdleHdl_Impl
, Idle
* , pIdle
, void )
1454 if ( pIdle
== pPageImpl
->pLoadIdle
)
1456 pPageImpl
->pLoadIdle
->Stop();
1460 INetURLObject
aOld( aBgdGraphicPath
);
1461 INetURLObject
aNew( pImportDlg
->GetPath() );
1462 if ( aBgdGraphicPath
.isEmpty() || aNew
!= aOld
)
1465 aBgdGraphicPath
= pImportDlg
->GetPath();
1466 aBgdGraphicFilter
= pImportDlg
->GetCurrentFilter();
1467 bool bLink
= ( nHtmlMode
& HTMLMODE_ON
) || bLinkOnly
|| pImportDlg
->IsAsLink();
1468 m_pBtnLink
->Check( bLink
);
1469 m_pBtnLink
->Enable();
1471 if ( m_pBtnPreview
->IsChecked() )
1473 if( !pImportDlg
->GetGraphic(aBgdGraphic
) )
1475 bIsGraphicValid
= true;
1479 aBgdGraphicFilter
.clear();
1480 aBgdGraphicPath
.clear();
1481 bIsGraphicValid
= false;
1485 bIsGraphicValid
= false; // load graphic not until preview click
1487 if ( m_pBtnPreview
->IsChecked() && bIsGraphicValid
)
1489 Bitmap aBmp
= aBgdGraphic
.GetBitmap();
1490 m_pPreviewWin2
->NotifyChange( &aBmp
);
1493 m_pPreviewWin2
->NotifyChange( NULL
);
1496 FileClickHdl_Impl(m_pBtnLink
);
1497 DELETEZ( pImportDlg
);
1502 void SvxBackgroundTabPage::ShowTblControl()
1504 m_pTblLBox
->SetSelectHdl( HDL(TblDestinationHdl_Impl
) );
1505 m_pTblLBox
->SelectEntryPos(0);
1511 void SvxBackgroundTabPage::ShowParaControl(bool bCharOnly
)
1513 m_pParaLBox
->SetSelectHdl(HDL(ParaDestinationHdl_Impl
));
1514 m_pParaLBox
->SelectEntryPos(0);
1518 m_pParaLBox
->Show();
1521 m_pParaLBox
->SetData(m_pParaLBox
); // here it can be recognized that this mode is turned on
1524 IMPL_LINK( SvxBackgroundTabPage
, TblDestinationHdl_Impl
, ListBox
*, pBox
)
1526 sal_Int32 nSelPos
= pBox
->GetSelectEntryPos();
1527 if( pTableBck_Impl
&& pTableBck_Impl
->nActPos
!= nSelPos
)
1529 boost::scoped_ptr
<SvxBrushItem
> xItemHolder
;
1530 SvxBrushItem
* pActItem
= NULL
;
1531 sal_uInt16 nWhich
= 0;
1532 switch(pTableBck_Impl
->nActPos
)
1535 pActItem
= pTableBck_Impl
->pCellBrush
;
1536 nWhich
= pTableBck_Impl
->nCellWhich
;
1539 pActItem
= pTableBck_Impl
->pRowBrush
;
1540 nWhich
= pTableBck_Impl
->nRowWhich
;
1543 pActItem
= pTableBck_Impl
->pTableBrush
;
1544 nWhich
= pTableBck_Impl
->nTableWhich
;
1550 pTableBck_Impl
->nActPos
= nSelPos
;
1553 xItemHolder
.reset(new SvxBrushItem(nWhich
));
1554 pActItem
= xItemHolder
.get();
1556 if(drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
)) // brush selected
1558 *pActItem
= SvxBrushItem( aBgdColor
, nWhich
);
1562 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
1563 const bool bIsLink
= m_pBtnLink
->IsChecked();
1565 if ( !bIsLink
&& !bIsGraphicValid
)
1566 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1569 *pActItem
= SvxBrushItem( aBgdGraphicPath
,
1572 pActItem
->Which() );
1574 *pActItem
= SvxBrushItem( aBgdGraphic
,
1576 pActItem
->Which() );
1581 pActItem
= pTableBck_Impl
->pCellBrush
;
1582 m_pLbSelect
->Enable();
1583 nWhich
= pTableBck_Impl
->nCellWhich
;
1586 pActItem
= pTableBck_Impl
->pRowBrush
;
1587 nWhich
= pTableBck_Impl
->nRowWhich
;
1590 pActItem
= pTableBck_Impl
->pTableBrush
;
1591 m_pLbSelect
->Enable();
1592 nWhich
= pTableBck_Impl
->nTableWhich
;
1595 // The item will be new'ed again below, but that will be the
1596 // default item then, not an existing modified one.
1597 xItemHolder
.reset();
1601 OUString aUserData
= GetUserData();
1604 xItemHolder
.reset(new SvxBrushItem(nWhich
));
1605 pActItem
= xItemHolder
.get();
1607 FillControls_Impl(*pActItem
, aUserData
);
1612 IMPL_LINK( SvxBackgroundTabPage
, ParaDestinationHdl_Impl
, ListBox
*, pBox
)
1614 sal_Int32 nSelPos
= pBox
->GetSelectEntryPos();
1615 if( pParaBck_Impl
&& pParaBck_Impl
->nActPos
!= nSelPos
)
1617 SvxBrushItem
* pActItem
= NULL
;
1618 switch(pParaBck_Impl
->nActPos
)
1620 case PARA_DEST_PARA
:
1621 pActItem
= pParaBck_Impl
->pParaBrush
;
1623 case PARA_DEST_CHAR
:
1624 pActItem
= pParaBck_Impl
->pCharBrush
;
1627 /* we assert here because the rest of the code expect pActItem to be non NULL */
1631 pParaBck_Impl
->nActPos
= nSelPos
;
1632 if(drawing::FillStyle_SOLID
== lcl_getFillStyle(m_pLbSelect
)) // brush selected
1634 sal_uInt16 nWhich
= pActItem
->Which();
1635 *pActItem
= SvxBrushItem( aBgdColor
, nWhich
);
1639 SvxGraphicPosition eNewPos
= GetGraphicPosition_Impl();
1640 const bool bIsLink
= m_pBtnLink
->IsChecked();
1642 if ( !bIsLink
&& !bIsGraphicValid
)
1643 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1646 *pActItem
= SvxBrushItem( aBgdGraphicPath
,
1649 pActItem
->Which() );
1651 *pActItem
= SvxBrushItem( aBgdGraphic
,
1653 pActItem
->Which() );
1657 case PARA_DEST_PARA
:
1658 pActItem
= pParaBck_Impl
->pParaBrush
;
1659 m_pLbSelect
->Enable();
1661 case PARA_DEST_CHAR
:
1663 pActItem
= pParaBck_Impl
->pCharBrush
;
1664 m_pLbSelect
->Enable(false);
1668 OUString aUserData
= GetUserData();
1669 FillControls_Impl(*pActItem
, aUserData
);
1674 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem
& rBgdAttr
,
1675 const OUString
& rUserData
)
1677 SvxGraphicPosition ePos
= rBgdAttr
.GetGraphicPos();
1678 const Color
& rColor
= rBgdAttr
.GetColor();
1679 if(bColTransparency
)
1681 m_pColTransMF
->SetValue(lcl_TransparencyToPercent(rColor
.GetTransparency()));
1682 m_pColTransMF
->SaveValue();
1683 bool bEnableTransp
= rColor
.GetTransparency() < 0xff;
1684 m_pColTransFT
->Enable(bEnableTransp
);
1685 m_pColTransMF
->Enable(bEnableTransp
);
1686 //the default setting should be "no transparency"
1688 m_pColTransMF
->SetValue(0);
1691 if ( GPOS_NONE
== ePos
|| !m_pLbSelect
->IsVisible() )
1693 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_SOLID
);
1695 Color
aTrColor( COL_TRANSPARENT
);
1698 sal_uInt16 nCol
= ( aTrColor
!= aBgdColor
) ?
1699 GetItemId_Impl(*m_pBackgroundColorSet
, aBgdColor
) : 0;
1701 if( aTrColor
!= aBgdColor
&& nCol
== 0)
1703 m_pBackgroundColorSet
->SetNoSelection();
1707 m_pBackgroundColorSet
->SelectItem( nCol
);
1710 m_pPreviewWin1
->NotifyChange( aBgdColor
);
1712 if ( m_pLbSelect
->IsVisible() ) // initialize graphic part
1714 aBgdGraphicFilter
.clear();
1715 aBgdGraphicPath
.clear();
1717 if ( rUserData
.isEmpty() )
1718 m_pBtnPreview
->Check( false );
1719 m_pBtnLink
->Check( false );
1720 m_pBtnLink
->Disable();
1721 m_pPreviewWin2
->NotifyChange( NULL
);
1722 SetGraphicPosition_Impl( GPOS_TILED
); // tiles as default
1727 const OUString aStrLink
= rBgdAttr
.GetGraphicLink();
1728 const OUString aStrFilter
= rBgdAttr
.GetGraphicFilter();
1730 lcl_setFillStyle(m_pLbSelect
, drawing::FillStyle_BITMAP
);
1731 ShowBitmapUI_Impl();
1733 if ( !aStrLink
.isEmpty() )
1736 INetURLObject
aObj( aStrLink
);
1737 DBG_ASSERT( aObj
.GetProtocol() != INetProtocol::NotValid
, "Invalid URL!" );
1739 aBgdGraphicPath
= aStrLink
;
1740 m_pBtnLink
->Check( true );
1741 m_pBtnLink
->Enable();
1745 aBgdGraphicPath
.clear();
1746 m_pBtnLink
->Check( false );
1747 m_pBtnLink
->Disable();
1750 if (bGraphTransparency
)
1752 const GraphicObject
* pObject
= rBgdAttr
.GetGraphicObject();
1754 m_pGraphTransMF
->SetValue(lcl_TransparencyToPercent(pObject
->GetAttr().GetTransparency()));
1756 m_pGraphTransMF
->SetValue(0);
1757 m_pGraphTransMF
->SaveValue();
1760 FileClickHdl_Impl(m_pBtnLink
);
1762 aBgdGraphicFilter
= aStrFilter
;
1764 if ( aStrLink
.isEmpty() || m_pBtnPreview
->IsChecked() )
1766 // Graphic exists in the item and doesn't have
1769 const Graphic
* pGraphic
= rBgdAttr
.GetGraphic();
1771 if ( !pGraphic
&& m_pBtnPreview
->IsChecked() )
1772 bIsGraphicValid
= LoadLinkedGraphic_Impl();
1773 else if ( pGraphic
)
1775 aBgdGraphic
= *pGraphic
;
1776 bIsGraphicValid
= true;
1778 if ( rUserData
.isEmpty() )
1779 m_pBtnPreview
->Check();
1783 RaiseLoadError_Impl();
1784 bIsGraphicValid
= false;
1786 if ( rUserData
.isEmpty() )
1787 m_pBtnPreview
->Check( false );
1791 if ( m_pBtnPreview
->IsChecked() && bIsGraphicValid
)
1793 Bitmap aBmp
= aBgdGraphic
.GetBitmap();
1794 m_pPreviewWin2
->NotifyChange( &aBmp
);
1797 m_pPreviewWin2
->NotifyChange( NULL
);
1799 SetGraphicPosition_Impl( ePos
);
1803 void SvxBackgroundTabPage::EnableTransparency(bool bColor
, bool bGraphic
)
1805 bColTransparency
= bColor
;
1806 bGraphTransparency
= bGraphic
;
1807 m_pColTransFT
->Show(bColor
);
1808 m_pColTransMF
->Show(bColor
);
1811 void SvxBackgroundTabPage::PageCreated(const SfxAllItemSet
& aSet
)
1813 SFX_ITEMSET_ARG (&aSet
,pFlagItem
,SfxUInt32Item
,SID_FLAG_TYPE
,false);
1817 SvxBackgroundTabFlags nFlags
= static_cast<SvxBackgroundTabFlags
>(pFlagItem
->GetValue());
1818 if (nFlags
& SvxBackgroundTabFlags::SHOW_TBLCTL
)
1820 if ( nFlags
& SvxBackgroundTabFlags::SHOW_PARACTL
)
1822 if ( nFlags
& SvxBackgroundTabFlags::SHOW_SELECTOR
)
1824 if ( nFlags
& SvxBackgroundTabFlags::ENABLE_TRANSPARENCY
)
1825 EnableTransparency(true, true);
1826 if ( nFlags
& SvxBackgroundTabFlags::SHOW_HIGHLIGHTING
)
1828 m_pBackGroundColorLabelFT
->SetText(CUI_RES(RID_SVXSTR_CHARNAME_HIGHLIGHTING
));
1829 bHighlighting
= true;
1834 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */