LCOV - code coverage report
Current view: top level - libreoffice/cui/source/tabpages - backgrnd.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 892 0.1 %
Date: 2012-12-27 Functions: 2 57 3.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <unotools/pathoptions.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include <tools/urlobj.hxx>
      23             : #include <sfx2/objsh.hxx>
      24             : #include <sfx2/docfile.hxx>
      25             : #include <svtools/wallitem.hxx>
      26             : #include <svl/cntwall.hxx>
      27             : #include <sfx2/cntids.hrc>
      28             : #include <svx/dialogs.hrc>
      29             : 
      30             : #define _SVX_BACKGRND_CXX
      31             : 
      32             : #include <cuires.hrc>
      33             : #include "backgrnd.hrc"
      34             : #include <svx/dialmgr.hxx>
      35             : #include <editeng/memberids.hrc>
      36             : #include <editeng/editrids.hrc>
      37             : #include <editeng/eerdll.hxx>
      38             : 
      39             : // table background
      40             : #define TBL_DEST_CELL   0
      41             : #define TBL_DEST_ROW    1
      42             : #define TBL_DEST_TBL    2
      43             : 
      44             : #include <editeng/brshitem.hxx>
      45             : #include "backgrnd.hxx"
      46             : 
      47             : #include <svx/xtable.hxx>
      48             : #include <sfx2/opengrf.hxx>
      49             : #include <svx/svxerr.hxx>
      50             : #include <svx/drawitem.hxx>
      51             : #include <dialmgr.hxx>
      52             : #include <svx/htmlmode.hxx>
      53             : #include <svtools/controldims.hrc>
      54             : #include <svx/flagsdef.hxx>
      55             : #include <svl/intitem.hxx>
      56             : #include <sfx2/request.hxx>
      57             : using namespace ::com::sun::star;
      58             : // static ----------------------------------------------------------------
      59             : 
      60             : static sal_uInt16 pRanges[] =
      61             : {
      62             :     SID_VIEW_FLD_PIC, SID_VIEW_FLD_PIC,
      63             :     SID_ATTR_BRUSH, SID_ATTR_BRUSH,
      64             :     SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR,
      65             :     0
      66             : };
      67             : 
      68             : struct SvxBackgroundTable_Impl
      69             : {
      70             :     SvxBrushItem*   pCellBrush;
      71             :     SvxBrushItem*   pRowBrush;
      72             :     SvxBrushItem*   pTableBrush;
      73             :     sal_uInt16          nCellWhich;
      74             :     sal_uInt16          nRowWhich;
      75             :     sal_uInt16          nTableWhich;
      76             :     sal_uInt16          nActPos;
      77             : 
      78           0 :     SvxBackgroundTable_Impl() :
      79             :         pCellBrush(NULL), pRowBrush(NULL), pTableBrush(NULL),
      80           0 :         nCellWhich(0), nRowWhich(0), nTableWhich(0) {}
      81             : };
      82             : 
      83             : struct SvxBackgroundPara_Impl
      84             : {
      85             :     SvxBrushItem*   pParaBrush;
      86             :     SvxBrushItem*   pCharBrush;
      87             : 
      88             :     sal_uInt16          nActPos;
      89             : 
      90           0 :     SvxBackgroundPara_Impl() :
      91           0 :         pParaBrush(NULL), pCharBrush(NULL) {}
      92             : };
      93             : 
      94             : struct SvxBackgroundPage_Impl
      95             : {
      96             :     Timer*          pLoadTimer;
      97             :     sal_Bool            bIsImportDlgInExecute;
      98             : 
      99           0 :     SvxBackgroundPage_Impl() :
     100           0 :         pLoadTimer(NULL), bIsImportDlgInExecute(sal_False) {}
     101             : };
     102             : 
     103           0 : static inline sal_uInt8 lcl_PercentToTransparency(long nPercent)
     104             : {
     105             :     //0xff must not be returned!
     106           0 :     return sal_uInt8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
     107             : }
     108           0 : static inline sal_uInt8 lcl_TransparencyToPercent(sal_uInt8 nTrans)
     109             : {
     110           0 :     return (nTrans * 100 + 127) / 254;
     111             : }
     112           0 : static void lcl_SetTransparency(SvxBrushItem& rBrush, long nTransparency)
     113             : {
     114           0 :     uno::Any aTransparency;
     115           0 :     aTransparency <<= (sal_Int8)nTransparency;
     116           0 :     rBrush.PutValue(aTransparency, MID_GRAPHIC_TRANSPARENCY);
     117           0 : }
     118             : //-------------------------------------------------------------------------
     119             : 
     120           0 : sal_uInt16 GetItemId_Impl( ValueSet& rValueSet, const Color& rCol )
     121             : {
     122           0 :     sal_Bool    bFound = sal_False;
     123           0 :     sal_uInt16  nCount = rValueSet.GetItemCount();
     124           0 :     sal_uInt16  n      = 1;
     125             : 
     126           0 :     while ( !bFound && n <= nCount )
     127             :     {
     128           0 :         Color aValCol = rValueSet.GetItemColor(n);
     129             : 
     130           0 :         bFound = (   aValCol.GetRed()   == rCol.GetRed()
     131           0 :                   && aValCol.GetGreen() == rCol.GetGreen()
     132           0 :                   && aValCol.GetBlue()  == rCol.GetBlue() );
     133             : 
     134           0 :         if ( !bFound )
     135           0 :             n++;
     136             :     }
     137           0 :     return bFound ? n : 0;
     138             : }
     139             : 
     140             : // class BackgroundPreview -----------------------------------------------
     141             : 
     142             : /*  [Description]
     143             : 
     144             :     preview window for brush or bitmap
     145             : */
     146             : 
     147             : class BackgroundPreviewImpl : public Window
     148             : {
     149             : public:
     150             :     BackgroundPreviewImpl( Window* pParent,
     151             :                            const ResId& rResId, sal_Bool bIsBmpPreview );
     152             :     ~BackgroundPreviewImpl();
     153             : 
     154             :     void            NotifyChange( const Color&  rColor );
     155             :     void            NotifyChange( const Bitmap* pBitmap );
     156             : 
     157             : protected:
     158             :     virtual void    Paint( const Rectangle& rRect );
     159             :     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
     160             : 
     161             : private:
     162             :     const sal_Bool      bIsBmp;
     163             :     Bitmap*         pBitmap;
     164             :     Point           aDrawPos;
     165             :     Size            aDrawSize;
     166             :     Rectangle       aDrawRect;
     167             :     sal_uInt8            nTransparency;
     168             : };
     169             : 
     170             : //-----------------------------------------------------------------------
     171             : 
     172           0 : BackgroundPreviewImpl::BackgroundPreviewImpl
     173             : (
     174             :     Window* pParent,
     175             :     const ResId& rResId,
     176             :     sal_Bool bIsBmpPreview
     177             : ) :
     178             : 
     179             :     Window( pParent, rResId ),
     180             : 
     181             :     bIsBmp   ( bIsBmpPreview ),
     182             :     pBitmap  ( NULL ),
     183           0 :     aDrawRect( Point(0,0), GetOutputSizePixel() ),
     184           0 :     nTransparency(0)
     185             : 
     186             : {
     187           0 :     SetBorderStyle(WINDOW_BORDER_MONO);
     188           0 :     Paint( aDrawRect );
     189           0 : }
     190             : 
     191             : //-----------------------------------------------------------------------
     192             : 
     193           0 : BackgroundPreviewImpl::~BackgroundPreviewImpl()
     194             : {
     195           0 :     delete pBitmap;
     196           0 : }
     197             : 
     198             : //-----------------------------------------------------------------------
     199           0 : void BackgroundPreviewImpl::NotifyChange( const Color& rColor )
     200             : {
     201           0 :     if ( !bIsBmp )
     202             :     {
     203           0 :         const static Color aTranspCol( COL_TRANSPARENT );
     204             : 
     205           0 :         nTransparency = lcl_TransparencyToPercent( rColor.GetTransparency() );
     206             : 
     207           0 :         SetFillColor( rColor == aTranspCol ? GetSettings().GetStyleSettings().GetFieldColor() : (Color) rColor.GetRGBColor() );
     208           0 :         Paint( aDrawRect );
     209             :     }
     210           0 : }
     211             : 
     212             : //-----------------------------------------------------------------------
     213             : 
     214           0 : void BackgroundPreviewImpl::NotifyChange( const Bitmap* pNewBitmap )
     215             : {
     216           0 :     if ( bIsBmp && (pNewBitmap || pBitmap) )
     217             :     {
     218           0 :         if ( pNewBitmap && pBitmap )
     219           0 :             *pBitmap = *pNewBitmap;
     220           0 :         else if ( pNewBitmap && !pBitmap )
     221           0 :             pBitmap = new Bitmap( *pNewBitmap );
     222           0 :         else if ( !pNewBitmap )
     223           0 :             DELETEZ( pBitmap );
     224             : 
     225           0 :         if ( pBitmap )
     226             :         {
     227           0 :             Size aSize = GetOutputSizePixel();
     228             :             // InnerSize == Size without one pixel border
     229           0 :             Size aInnerSize = aSize;
     230           0 :             aInnerSize.Width() -= 2;
     231           0 :             aInnerSize.Height() -= 2;
     232           0 :             aDrawSize = pBitmap->GetSizePixel();
     233             : 
     234             :             // bitmap bigger than preview window?
     235           0 :             if ( aDrawSize.Width() > aInnerSize.Width() )
     236             :             {
     237           0 :                 aDrawSize.Height() = aDrawSize.Height() * aInnerSize.Width() / aDrawSize.Width();
     238           0 :                 if ( aDrawSize.Height() > aInnerSize.Height() )
     239             :                 {
     240           0 :                     aDrawSize.Width() = aDrawSize.Height();
     241           0 :                     aDrawSize.Height() = aInnerSize.Height();
     242             :                 }
     243             :                 else
     244           0 :                     aDrawSize.Width() = aInnerSize.Width();
     245             :             }
     246           0 :             else if ( aDrawSize.Height() > aInnerSize.Height() )
     247             :             {
     248           0 :                 aDrawSize.Width() = aDrawSize.Width() * aInnerSize.Height() / aDrawSize.Height();
     249           0 :                 if ( aDrawSize.Width() > aInnerSize.Width() )
     250             :                 {
     251           0 :                     aDrawSize.Height() = aDrawSize.Width();
     252           0 :                     aDrawSize.Width() = aInnerSize.Width();
     253             :                 }
     254             :                 else
     255           0 :                     aDrawSize.Height() = aInnerSize.Height();
     256             :             }
     257             : 
     258           0 :             aDrawPos.X() = (aSize.Width()  - aDrawSize.Width())  / 2;
     259           0 :             aDrawPos.Y() = (aSize.Height() - aDrawSize.Height()) / 2;
     260             :         }
     261           0 :         Invalidate( aDrawRect );
     262           0 :         Update();
     263             :     }
     264           0 : }
     265             : 
     266             : //-----------------------------------------------------------------------
     267             : 
     268           0 : void BackgroundPreviewImpl::Paint( const Rectangle& )
     269             : {
     270           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     271           0 :     SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
     272           0 :     SetLineColor();
     273           0 :     if(bIsBmp)
     274           0 :         SetFillColor( Color(COL_TRANSPARENT) );
     275           0 :     DrawRect( aDrawRect );
     276           0 :     if ( bIsBmp )
     277             :     {
     278           0 :         if ( pBitmap )
     279           0 :             DrawBitmap( aDrawPos, aDrawSize, *pBitmap );
     280             :         else
     281             :         {
     282           0 :             Size aSize = GetOutputSizePixel();
     283           0 :             DrawLine( Point(0,0),               Point(aSize.Width(),aSize.Height()) );
     284           0 :             DrawLine( Point(0,aSize.Height()),  Point(aSize.Width(),0) );
     285             :         }
     286             :     }
     287           0 : }
     288             : 
     289           0 : void BackgroundPreviewImpl::DataChanged( const DataChangedEvent& rDCEvt )
     290             : {
     291           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     292           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     293             :     {
     294           0 :         Invalidate();
     295             :     }
     296           0 :     Window::DataChanged( rDCEvt );
     297           0 : }
     298             : 
     299             : // class SvxBackgroundTabPage --------------------------------------------
     300             : 
     301             : #define HDL(hdl) LINK(this,SvxBackgroundTabPage,hdl)
     302             : 
     303           0 : SvxBackgroundTabPage::SvxBackgroundTabPage( Window* pParent,
     304             :                                             const SfxItemSet& rCoreSet ) :
     305             : 
     306           0 :     SvxTabPage( pParent, CUI_RES( RID_SVXPAGE_BACKGROUND ), rCoreSet ),
     307             : 
     308           0 :     aSelectTxt          ( this, CUI_RES( FT_SELECTOR ) ),
     309           0 :     aLbSelect           ( this, CUI_RES( LB_SELECTOR ) ),
     310           0 :     aStrBrowse          ( CUI_RES( STR_BROWSE ) ),
     311           0 :     aStrUnlinked        ( CUI_RES( STR_UNLINKED ) ),
     312           0 :     aTblDesc            ( this, CUI_RES( FT_TBL_DESC ) ),
     313           0 :     aTblLBox            ( this, CUI_RES( LB_TBL_BOX ) ),
     314           0 :     aParaLBox           ( this, CUI_RES( LB_PARA_BOX ) ),
     315             : 
     316           0 :     aBorderWin          ( this, CUI_RES(CT_BORDER) ),
     317           0 :     aBackgroundColorSet ( &aBorderWin, CUI_RES( SET_BGDCOLOR ) ),
     318           0 :     aBackgroundColorBox ( this, CUI_RES( GB_BGDCOLOR ) ),
     319           0 :     pPreviewWin1        ( new BackgroundPreviewImpl( this, CUI_RES( WIN_PREVIEW1 ), sal_False ) ),
     320             : 
     321           0 :     aColTransFT         ( this, CUI_RES( FT_COL_TRANS ) ),
     322           0 :     aColTransMF         ( this, CUI_RES( MF_COL_TRANS ) ),
     323           0 :     aBtnPreview         ( this, CUI_RES( BTN_PREVIEW ) ),
     324           0 :     aGbFile             ( this, CUI_RES( GB_FILE ) ),
     325           0 :     aBtnBrowse          ( this, CUI_RES( BTN_BROWSE ) ),
     326           0 :     aBtnLink            ( this, CUI_RES( BTN_LINK ) ),
     327           0 :     aGbPosition         ( this, CUI_RES( GB_POSITION ) ),
     328           0 :     aBtnPosition        ( this, CUI_RES( BTN_POSITION ) ),
     329           0 :     aBtnArea            ( this, CUI_RES( BTN_AREA ) ),
     330           0 :     aBtnTile            ( this, CUI_RES( BTN_TILE ) ),
     331           0 :     aWndPosition        ( this, CUI_RES( WND_POSITION ), RP_MM ),
     332           0 :     aFtFile             ( this, CUI_RES( FT_FILE ) ),
     333           0 :     aGraphTransFL       ( this, CUI_RES( FL_GRAPH_TRANS ) ),
     334           0 :     aGraphTransMF       ( this, CUI_RES( MF_GRAPH_TRANS ) ),
     335             :     pPreviewWin2        ( new BackgroundPreviewImpl(
     336           0 :                             this, CUI_RES( WIN_PREVIEW2 ), sal_True ) ),
     337             : 
     338             :     nHtmlMode           ( 0 ),
     339             :     bAllowShowSelector  ( sal_True ),
     340             :     bIsGraphicValid     ( sal_False ),
     341             :     bLinkOnly           ( sal_False ),
     342             :     bResized            ( sal_False ),
     343             :     bColTransparency    ( sal_False ),
     344             :     bGraphTransparency  ( sal_False ),
     345             : 
     346           0 :     pPageImpl           ( new SvxBackgroundPage_Impl ),
     347             :     pImportDlg          ( NULL ),
     348             :     pTableBck_Impl      ( NULL ),
     349           0 :     pParaBck_Impl       ( NULL )
     350             : 
     351             : {
     352             :     // this page needs ExchangeSupport
     353           0 :     SetExchangeSupport();
     354             : 
     355             :     const SfxPoolItem* pItem;
     356             :     SfxObjectShell* pShell;
     357             : 
     358           0 :     if ( SFX_ITEM_SET == rCoreSet.GetItemState( SID_HTML_MODE, sal_False, &pItem )
     359             :          || ( 0 != ( pShell = SfxObjectShell::Current()) &&
     360           0 :               0 != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
     361             :     {
     362           0 :         nHtmlMode = ((SfxUInt16Item*)pItem)->GetValue();
     363             :     }
     364             : 
     365           0 :     FillColorValueSets_Impl();
     366             : 
     367           0 :     aBackgroundColorSet.SetSelectHdl( HDL(BackgroundColorHdl_Impl) );
     368           0 :     FreeResource();
     369             : 
     370           0 :     aBtnBrowse.SetAccessibleRelationMemberOf(&aGbFile);
     371           0 :     aWndPosition.SetAccessibleRelationMemberOf(&aGbPosition);
     372           0 :     aWndPosition.SetAccessibleRelationLabeledBy(&aBtnPosition);
     373           0 :     aBackgroundColorSet.SetAccessibleRelationLabeledBy(&aBackgroundColorBox);
     374           0 : }
     375             : 
     376             : //------------------------------------------------------------------------
     377             : 
     378           0 : SvxBackgroundTabPage::~SvxBackgroundTabPage()
     379             : {
     380           0 :     delete pPreviewWin1;
     381           0 :     delete pPreviewWin2;
     382           0 :     delete pPageImpl->pLoadTimer;
     383           0 :     delete pPageImpl;
     384           0 :     delete pImportDlg;
     385             : 
     386           0 :     if( pTableBck_Impl)
     387             :     {
     388           0 :         delete pTableBck_Impl->pCellBrush;
     389           0 :         delete pTableBck_Impl->pRowBrush;
     390           0 :         delete pTableBck_Impl->pTableBrush;
     391           0 :         delete pTableBck_Impl;
     392             :     }
     393             : 
     394           0 :     if(pParaBck_Impl)
     395             :     {
     396           0 :         delete pParaBck_Impl->pParaBrush;
     397           0 :         delete pParaBck_Impl->pCharBrush;
     398           0 :         delete pParaBck_Impl;
     399             :     }
     400           0 : }
     401             : 
     402             : //------------------------------------------------------------------------
     403             : 
     404           0 : sal_uInt16* SvxBackgroundTabPage::GetRanges()
     405             : 
     406             : /*  [Description]
     407             : 
     408             :     returns the area of the which-values
     409             : */
     410             : 
     411             : {
     412           0 :     return pRanges;
     413             : }
     414             : 
     415             : //------------------------------------------------------------------------
     416             : 
     417           0 : SfxTabPage* SvxBackgroundTabPage::Create( Window* pParent,
     418             :                                           const SfxItemSet& rAttrSet )
     419             : 
     420             : /*  [Description]
     421             : 
     422             :     create method for the TabDialog
     423             : */
     424             : 
     425             : {
     426           0 :     return ( new SvxBackgroundTabPage( pParent, rAttrSet ) );
     427             : }
     428             : 
     429             : //------------------------------------------------------------------------
     430             : 
     431           0 : void SvxBackgroundTabPage::Reset( const SfxItemSet& rSet )
     432             : {
     433             : // os: Such a nonsense! One will always find such an item somewhere,
     434             : //     but it must be existing in the rSet!
     435             : //  const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
     436             : //  if( pX && pX->ISA(SfxWallpaperItem))
     437           0 :     if(SFX_ITEM_AVAILABLE <= rSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), sal_False))
     438             :     {
     439           0 :         ResetFromWallpaperItem( rSet );
     440           0 :         return;
     441             :     }
     442             : 
     443             :     // condition of the preview button is persistent due to UserData
     444           0 :     String aUserData = GetUserData();
     445           0 :     aBtnPreview.Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
     446             : 
     447             :     // don't be allowed to call ShowSelector() after reset anymore
     448           0 :     bAllowShowSelector = sal_False;
     449             : 
     450             : 
     451             :     // get and evaluate Input-BrushItem
     452           0 :     const SvxBrushItem* pBgdAttr = NULL;
     453           0 :     sal_uInt16 nSlot = SID_ATTR_BRUSH;
     454             :     const SfxPoolItem* pItem;
     455           0 :     sal_uInt16 nDestValue = USHRT_MAX;
     456             : 
     457           0 :     if ( SFX_ITEM_SET == rSet.GetItemState( SID_BACKGRND_DESTINATION,
     458           0 :                                             sal_False, &pItem ) )
     459             :     {
     460           0 :         nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
     461           0 :         aTblLBox.SelectEntryPos(nDestValue);
     462             : 
     463           0 :         switch ( nDestValue )
     464             :         {
     465             :             case TBL_DEST_CELL:
     466           0 :                 nSlot = SID_ATTR_BRUSH;
     467           0 :             break;
     468             :             case TBL_DEST_ROW:
     469           0 :                 nSlot = SID_ATTR_BRUSH_ROW;
     470           0 :             break;
     471             :             case TBL_DEST_TBL:
     472           0 :                 nSlot = SID_ATTR_BRUSH_TABLE;
     473           0 :             break;
     474             :         }
     475             :     }
     476           0 :     else if( SFX_ITEM_SET == rSet.GetItemState(
     477           0 :                 SID_PARA_BACKGRND_DESTINATION, sal_False, &pItem ) )
     478             :     {
     479           0 :         nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
     480             :         // character activated?
     481           0 :         sal_uInt16 nParaSel  = aParaLBox.GetSelectEntryPos();
     482           0 :         if(1 == nParaSel)
     483             :         {
     484             :             // then it was a "standard"-call
     485           0 :             nDestValue = nParaSel;
     486             :         }
     487           0 :         aParaLBox.SelectEntryPos(nDestValue);
     488             : 
     489           0 :         switch ( nDestValue )
     490             :         {
     491             :             case PARA_DEST_PARA:
     492           0 :                 nSlot = SID_ATTR_BRUSH;
     493           0 :             break;
     494             :             case PARA_DEST_CHAR:
     495           0 :                 nSlot = SID_ATTR_BRUSH_CHAR;
     496           0 :             break;
     497             :         }
     498             :     }
     499             :     //#111173# the destination item is missing when the parent style has been changed
     500           0 :     if(USHRT_MAX == nDestValue && (aParaLBox.IsVisible()||aTblLBox.IsVisible()))
     501           0 :         nDestValue = 0;
     502           0 :     sal_uInt16 nWhich = GetWhich( nSlot );
     503             : 
     504           0 :     if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
     505           0 :         pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
     506             : 
     507           0 :     aBtnTile.Check();
     508             : 
     509           0 :     if ( pBgdAttr )
     510             :     {
     511           0 :         FillControls_Impl(*pBgdAttr, aUserData);
     512           0 :         aBgdColor = ( (SvxBrushItem*)pBgdAttr )->GetColor();
     513             :     }
     514             :     else
     515             :     {
     516           0 :         aSelectTxt.Hide();
     517           0 :         aLbSelect.Hide();
     518           0 :         aLbSelect.SelectEntryPos( 0 );
     519           0 :         ShowColorUI_Impl();
     520             : 
     521           0 :         const SfxPoolItem* pOld = GetOldItem( rSet, SID_ATTR_BRUSH );
     522             : 
     523           0 :         if ( pOld )
     524           0 :             aBgdColor = ( (SvxBrushItem*)pOld )->GetColor();
     525             :     }
     526             : 
     527           0 :     if ( nDestValue != USHRT_MAX )
     528             :     {
     529           0 :         if(aTblLBox.IsVisible())
     530             :         {
     531           0 :             sal_uInt16 nValue = aTblLBox.GetSelectEntryPos();
     532             : 
     533           0 :             if ( pTableBck_Impl )
     534             :             {
     535           0 :                 DELETEZ( pTableBck_Impl->pCellBrush);
     536           0 :                 DELETEZ( pTableBck_Impl->pRowBrush);
     537           0 :                 DELETEZ( pTableBck_Impl->pTableBrush);
     538             :             }
     539             :             else
     540           0 :                 pTableBck_Impl = new SvxBackgroundTable_Impl();
     541             : 
     542           0 :             pTableBck_Impl->nActPos = nValue;
     543             : 
     544           0 :             nWhich = GetWhich( SID_ATTR_BRUSH );
     545           0 :             if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
     546             :             {
     547           0 :                 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
     548           0 :                 pTableBck_Impl->pCellBrush = new SvxBrushItem(*pBgdAttr);
     549             :             }
     550           0 :             pTableBck_Impl->nCellWhich = nWhich;
     551             : 
     552           0 :             if ( rSet.GetItemState( SID_ATTR_BRUSH_ROW, sal_False ) >= SFX_ITEM_AVAILABLE )
     553             :             {
     554           0 :                 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_ROW ) );
     555           0 :                 pTableBck_Impl->pRowBrush = new SvxBrushItem(*pBgdAttr);
     556             :             }
     557           0 :             pTableBck_Impl->nRowWhich = SID_ATTR_BRUSH_ROW;
     558             : 
     559           0 :             if ( rSet.GetItemState( SID_ATTR_BRUSH_TABLE, sal_False ) >= SFX_ITEM_AVAILABLE )
     560             :             {
     561           0 :                 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_TABLE ) );
     562           0 :                 pTableBck_Impl->pTableBrush = new SvxBrushItem(*pBgdAttr);
     563             :             }
     564           0 :             pTableBck_Impl->nTableWhich = SID_ATTR_BRUSH_TABLE;
     565             : 
     566           0 :             TblDestinationHdl_Impl(&aTblLBox);
     567           0 :             aTblLBox.SaveValue();
     568             :         }
     569             :         else
     570             :         {
     571           0 :             sal_uInt16 nValue = aParaLBox.GetSelectEntryPos();
     572             : 
     573           0 :             if ( pParaBck_Impl )
     574             :             {
     575           0 :                 delete pParaBck_Impl->pParaBrush;
     576           0 :                 delete pParaBck_Impl->pCharBrush;
     577             :             }
     578             :             else
     579           0 :                 pParaBck_Impl = new SvxBackgroundPara_Impl();
     580             : 
     581           0 :             pParaBck_Impl->nActPos = nValue;
     582             : 
     583           0 :             nWhich = GetWhich( SID_ATTR_BRUSH );
     584           0 :             if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
     585             :             {
     586           0 :                 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
     587           0 :                 pParaBck_Impl->pParaBrush = new SvxBrushItem(*pBgdAttr);
     588             :             }
     589             : 
     590           0 :             nWhich = GetWhich( SID_ATTR_BRUSH_CHAR );
     591           0 :             rSet.GetItemState( nWhich, sal_True );
     592           0 :             rSet.GetItemState( nWhich, sal_False );
     593           0 :             if ( rSet.GetItemState( nWhich, sal_True ) > SFX_ITEM_AVAILABLE )
     594             :             {
     595           0 :                 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
     596           0 :                 pParaBck_Impl->pCharBrush = new SvxBrushItem(*pBgdAttr);
     597             :             }
     598             :             else
     599           0 :                 pParaBck_Impl->pCharBrush = new SvxBrushItem(SID_ATTR_BRUSH_CHAR);
     600             : 
     601           0 :             ParaDestinationHdl_Impl(&aParaLBox);
     602           0 :             aParaLBox.SaveValue();
     603             :         }
     604             :     }
     605           0 :     if(!bResized)
     606             :     {
     607           0 :         if(!aLbSelect.IsVisible() && !aTblLBox.IsVisible() && !aParaLBox.IsVisible())
     608             :         {
     609           0 :             long nY(LogicToPixel(Point(11,14), MAP_APPFONT).X());
     610           0 :             long nX(LogicToPixel(Point(11,14), MAP_APPFONT).Y());
     611           0 :             Point aPos(aBorderWin.GetPosPixel());
     612           0 :             aPos.X() = nX;
     613           0 :             aPos.Y() = nY;
     614           0 :             aBorderWin.SetPosPixel(aPos);
     615           0 :             aPos = pPreviewWin1->GetPosPixel();
     616           0 :             aPos.Y()  = nY;
     617           0 :             pPreviewWin1->SetPosPixel(aPos);
     618           0 :             aBackgroundColorBox.Hide();
     619           0 :             aBackgroundColorSet.SetAccessibleRelationLabeledBy(&aBackgroundColorSet);
     620             :         }
     621           0 :     }
     622             : }
     623             : 
     624           0 : void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet& rSet )
     625             : {
     626           0 :     ShowSelector();
     627             : 
     628             :     // condition of the preview button is persistent due to UserData
     629           0 :     String aUserData = GetUserData();
     630           0 :     aBtnPreview.Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
     631             : 
     632             :     // get and evaluate Input-BrushItem
     633           0 :     const SvxBrushItem* pBgdAttr = NULL;
     634           0 :     sal_uInt16 nSlot = SID_VIEW_FLD_PIC;
     635           0 :     sal_uInt16 nWhich = GetWhich( nSlot );
     636           0 :     SvxBrushItem* pTemp = 0;
     637           0 :     const CntWallpaperItem* pItem = 0;
     638             : 
     639           0 :     if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
     640             :     {
     641           0 :         pItem = (const CntWallpaperItem*)&rSet.Get( nWhich );
     642           0 :         pTemp = new SvxBrushItem( *pItem, nWhich );
     643           0 :         pBgdAttr = pTemp;
     644             :     }
     645             : 
     646           0 :     aBtnTile.Check();
     647             : 
     648           0 :     if ( pBgdAttr )
     649             :     {
     650           0 :         FillControls_Impl(*pBgdAttr, aUserData);
     651             :         // brush shall be kept when showing the graphic, too
     652           0 :         if( aBgdColor != pBgdAttr->GetColor() )
     653             :         {
     654           0 :             aBgdColor = pBgdAttr->GetColor();
     655           0 :             sal_uInt16 nCol = GetItemId_Impl( aBackgroundColorSet, aBgdColor );
     656           0 :             aBackgroundColorSet.SelectItem( nCol );
     657           0 :             pPreviewWin1->NotifyChange( aBgdColor );
     658             :         }
     659             :     }
     660             :     else
     661             :     {
     662           0 :         aLbSelect.SelectEntryPos( 0 );
     663           0 :         ShowColorUI_Impl();
     664             : 
     665           0 :         const SfxPoolItem* pOld = GetOldItem( rSet, SID_VIEW_FLD_PIC );
     666           0 :         if ( pOld )
     667           0 :             aBgdColor = Color( ((CntWallpaperItem*)pOld)->GetColor() );
     668             :     }
     669             : 
     670             :     // We now have always a link to the background
     671           0 :     bLinkOnly = sal_True;
     672           0 :     aBtnLink.Check( sal_True );
     673           0 :     aBtnLink.Show( sal_False );
     674             : //  if( !pItem || !pItem->GetWallpaper(sal_False).IsBitmap() )
     675             : //      aBtnLink.Check();
     676             : 
     677           0 :     delete pTemp;
     678           0 : }
     679             : 
     680             : 
     681             : 
     682             : //------------------------------------------------------------------------
     683             : 
     684           0 : void SvxBackgroundTabPage::FillUserData()
     685             : 
     686             : /*  [Description]
     687             : 
     688             :     When destroying a SfxTabPage this virtual method is called,
     689             :     so that the TabPage can save internal information.
     690             : 
     691             :     In this case the condition of the preview button is saved.
     692             : */
     693             : 
     694             : {
     695           0 :     SetUserData( aBtnPreview.IsChecked() ? rtl::OUString('1') : rtl::OUString('0') );
     696           0 : }
     697             : 
     698             : //------------------------------------------------------------------------
     699             : 
     700           0 : sal_Bool SvxBackgroundTabPage::FillItemSet( SfxItemSet& rCoreSet )
     701             : {
     702           0 :     if ( pPageImpl->pLoadTimer && pPageImpl->pLoadTimer->IsActive() )
     703             :     {
     704           0 :         pPageImpl->pLoadTimer->Stop();
     705           0 :         LoadTimerHdl_Impl( pPageImpl->pLoadTimer );
     706             :     }
     707             : // os: Such a nonsense! One will always find such an item somewhere,
     708             : //     but it must be existing in the rSet!
     709             : 
     710             : //  const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
     711             : //  if( pX && pX->ISA(SfxWallpaperItem))
     712           0 :     if(SFX_ITEM_AVAILABLE <= rCoreSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), sal_False))
     713           0 :         return FillItemSetWithWallpaperItem( rCoreSet, SID_VIEW_FLD_PIC );
     714             : 
     715           0 :     sal_Bool bModified = sal_False;
     716           0 :     sal_uInt16 nSlot = SID_ATTR_BRUSH;
     717             : 
     718           0 :     if ( aTblLBox.IsVisible() )
     719             :     {
     720           0 :         switch( aTblLBox.GetSelectEntryPos() )
     721             :         {
     722             :             case TBL_DEST_CELL:
     723           0 :                 nSlot = SID_ATTR_BRUSH;
     724           0 :             break;
     725             :             case TBL_DEST_ROW:
     726           0 :                 nSlot = SID_ATTR_BRUSH_ROW;
     727           0 :             break;
     728             :             case TBL_DEST_TBL:
     729           0 :                 nSlot = SID_ATTR_BRUSH_TABLE;
     730           0 :             break;
     731             :         }
     732             :     }
     733           0 :     else if(aParaLBox.GetData() == &aParaLBox)
     734             :     {
     735           0 :         switch(aParaLBox.GetSelectEntryPos())
     736             :         {
     737             :             case PARA_DEST_PARA:
     738           0 :                 nSlot = SID_ATTR_BRUSH;
     739           0 :             break;
     740             :             case PARA_DEST_CHAR:
     741           0 :                 nSlot = SID_ATTR_BRUSH_CHAR;
     742           0 :             break;
     743             :         }
     744             :     }
     745           0 :     sal_uInt16 nWhich = GetWhich( nSlot );
     746             : 
     747           0 :     const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
     748           0 :     SfxItemState eOldItemState = rCoreSet.GetItemState(nSlot, sal_False);
     749           0 :     const SfxItemSet& rOldSet = GetItemSet();
     750             : 
     751           0 :     sal_Bool bGraphTransparencyChanged = bGraphTransparency && (aGraphTransMF.GetText() != aGraphTransMF.GetSavedValue());
     752           0 :     if ( pOld )
     753             :     {
     754           0 :         const SvxBrushItem& rOldItem    = (const SvxBrushItem&)*pOld;
     755           0 :         SvxGraphicPosition  eOldPos     = rOldItem.GetGraphicPos();
     756           0 :         const sal_Bool          bIsBrush    = ( 0 == aLbSelect.GetSelectEntryPos() );
     757             : 
     758             :         // transparency has to be set if enabled, the color not already set to "No fill" and
     759           0 :         if( bColTransparency &&
     760           0 :             aBgdColor.GetTransparency() < 0xff)
     761             :         {
     762           0 :             aBgdColor.SetTransparency(lcl_PercentToTransparency(static_cast<long>(aColTransMF.GetValue())));
     763             :         }
     764           0 :         if (   ( (GPOS_NONE == eOldPos) && bIsBrush  )
     765             :             || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
     766             :         {
     767             :             // background art hasn't been changed:
     768             : 
     769           0 :             if ( (GPOS_NONE == eOldPos) || !aLbSelect.IsVisible() )
     770             :             {
     771             :                 // Brush-treatment:
     772           0 :                 if ( rOldItem.GetColor() != aBgdColor ||
     773           0 :                         (SFX_ITEM_AVAILABLE >= eOldItemState && !aBackgroundColorSet.IsNoSelection()))
     774             :                 {
     775           0 :                     bModified = sal_True;
     776           0 :                     rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
     777             :                 }
     778           0 :                 else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
     779           0 :                     rCoreSet.ClearItem( nWhich );
     780             :             }
     781             :             else
     782             :             {
     783             :                 // Bitmap-treatment:
     784             : 
     785           0 :                 SvxGraphicPosition  eNewPos  = GetGraphicPosition_Impl();
     786           0 :                 const sal_Bool          bIsLink  = aBtnLink.IsChecked();
     787           0 :                 const sal_Bool          bWasLink = (NULL != rOldItem.GetGraphicLink() );
     788             : 
     789             : 
     790           0 :                 if ( !bIsLink && !bIsGraphicValid )
     791           0 :                     bIsGraphicValid = LoadLinkedGraphic_Impl();
     792             : 
     793           0 :                 if (    bGraphTransparencyChanged ||
     794             :                         eNewPos != eOldPos
     795             :                     || bIsLink != bWasLink
     796           0 :                     || ( bWasLink  &&    *rOldItem.GetGraphicLink()
     797           0 :                                       != aBgdGraphicPath )
     798             :                     || ( !bWasLink &&    rOldItem.GetGraphic()->GetBitmap()
     799           0 :                                       != aBgdGraphic.GetBitmap() )
     800             :                    )
     801             :                 {
     802           0 :                     bModified = sal_True;
     803             : 
     804           0 :                     SvxBrushItem aTmpBrush(nWhich);
     805           0 :                     if ( bIsLink )
     806             :                     {
     807             :                         aTmpBrush = SvxBrushItem( aBgdGraphicPath,
     808             :                                                 aBgdGraphicFilter,
     809             :                                                 eNewPos,
     810           0 :                                                 nWhich );
     811             :                     }
     812             :                     else
     813             :                         aTmpBrush = SvxBrushItem( aBgdGraphic,
     814             :                                         eNewPos,
     815           0 :                                         nWhich );
     816           0 :                     lcl_SetTransparency(aTmpBrush, static_cast<long>(aGraphTransMF.GetValue()));
     817             : 
     818           0 :                     rCoreSet.Put(aTmpBrush);
     819             :                 }
     820           0 :                 else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
     821           0 :                     rCoreSet.ClearItem( nWhich );
     822           0 :             }
     823             :         }
     824             :         else // Brush <-> Bitmap changed!
     825             :         {
     826           0 :             if ( bIsBrush )
     827           0 :                 rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
     828             :             else
     829             :             {
     830           0 :                 SvxBrushItem* pTmpBrush = 0;
     831           0 :                 if ( aBtnLink.IsChecked() )
     832             :                 {
     833             :                     pTmpBrush = new SvxBrushItem( aBgdGraphicPath,
     834             :                                                 aBgdGraphicFilter,
     835             :                                                 GetGraphicPosition_Impl(),
     836           0 :                                                 nWhich );
     837             :                 }
     838             :                 else
     839             :                 {
     840           0 :                     if ( !bIsGraphicValid )
     841           0 :                         bIsGraphicValid = LoadLinkedGraphic_Impl();
     842             : 
     843           0 :                     if ( bIsGraphicValid )
     844             :                         pTmpBrush = new SvxBrushItem( aBgdGraphic,
     845             :                                                     GetGraphicPosition_Impl(),
     846           0 :                                                     nWhich );
     847             :                 }
     848           0 :                 if(pTmpBrush)
     849             :                 {
     850           0 :                     lcl_SetTransparency(*pTmpBrush, static_cast<long>(aGraphTransMF.GetValue()));
     851           0 :                     rCoreSet.Put(*pTmpBrush);
     852           0 :                     delete pTmpBrush;
     853             :                 }
     854             :             }
     855           0 :             bModified = ( bIsBrush || aBtnLink.IsChecked() || bIsGraphicValid );
     856             :         }
     857             :     }
     858           0 :     else if ( SID_ATTR_BRUSH_CHAR == nSlot && aBgdColor != Color( COL_WHITE ) )
     859             :     {
     860           0 :         rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
     861           0 :         bModified = sal_True;
     862             :     }
     863             : 
     864           0 :     if( aTblLBox.IsVisible() )
     865             :     {
     866             :         // the current condition has already been put
     867           0 :         if( nSlot != SID_ATTR_BRUSH && pTableBck_Impl->pCellBrush)
     868             :         {
     869             :             const SfxPoolItem* pOldCell =
     870           0 :                 GetOldItem( rCoreSet, SID_ATTR_BRUSH );
     871             : 
     872           0 :             if ( *pTableBck_Impl->pCellBrush != *pOldCell )
     873             :             {
     874           0 :                 rCoreSet.Put( *pTableBck_Impl->pCellBrush );
     875           0 :                 bModified |= sal_True;
     876             :             }
     877             :         }
     878             : 
     879           0 :         if( nSlot != SID_ATTR_BRUSH_ROW && pTableBck_Impl->pRowBrush)
     880             :         {
     881             :             const SfxPoolItem* pOldRow =
     882           0 :                 GetOldItem( rCoreSet, SID_ATTR_BRUSH_ROW );
     883             : 
     884           0 :             if ( *pTableBck_Impl->pRowBrush != *pOldRow )
     885             :             {
     886           0 :                 rCoreSet.Put( *pTableBck_Impl->pRowBrush );
     887           0 :                 bModified |= sal_True;
     888             :             }
     889             :         }
     890             : 
     891           0 :         if( nSlot != SID_ATTR_BRUSH_TABLE && pTableBck_Impl->pTableBrush)
     892             :         {
     893             :             const SfxPoolItem* pOldTable =
     894           0 :                 GetOldItem( rCoreSet, SID_ATTR_BRUSH_TABLE );
     895             : 
     896           0 :             if ( *pTableBck_Impl->pTableBrush != *pOldTable )
     897             :             {
     898           0 :                 rCoreSet.Put( *pTableBck_Impl->pTableBrush );
     899           0 :                 bModified |= sal_True;
     900             :             }
     901             :         }
     902             : 
     903           0 :         if( aTblLBox.GetSavedValue() != aTblLBox.GetSelectEntryPos() )
     904             :         {
     905             :             rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
     906           0 :                                          aTblLBox.GetSelectEntryPos() ) );
     907           0 :             bModified |= sal_True;
     908             :         }
     909             :     }
     910           0 :     else if(aParaLBox.GetData() == &aParaLBox)
     911             :     {
     912             :         // the current condition has already been put
     913           0 :         if( nSlot != SID_ATTR_BRUSH && aParaLBox.IsVisible()) // not in search format dialog
     914             :         {
     915             :             const SfxPoolItem* pOldPara =
     916           0 :                 GetOldItem( rCoreSet, SID_ATTR_BRUSH );
     917             : 
     918           0 :             if ( *pParaBck_Impl->pParaBrush != *pOldPara )
     919             :             {
     920           0 :                 rCoreSet.Put( *pParaBck_Impl->pParaBrush );
     921           0 :                 bModified |= sal_True;
     922             :             }
     923             :         }
     924             : 
     925           0 :         if( nSlot != SID_ATTR_BRUSH_CHAR )
     926             :         {
     927             :             const SfxPoolItem* pOldChar =
     928           0 :                 GetOldItem( rCoreSet, SID_ATTR_BRUSH_CHAR );
     929             :             DBG_ASSERT(pParaBck_Impl, "pParaBck_Impl == NULL ?");
     930           0 :             if ( pOldChar &&
     931             :                     //#111173#  crash report shows that pParaBck_Impl can be NULL, the cause is unknown
     932             :                     pParaBck_Impl &&
     933           0 :                         (*pParaBck_Impl->pCharBrush != *pOldChar ||
     934           0 :                 *pParaBck_Impl->pCharBrush != SvxBrushItem(SID_ATTR_BRUSH_CHAR)))
     935             :             {
     936           0 :                 rCoreSet.Put( *pParaBck_Impl->pCharBrush );
     937           0 :                 bModified |= sal_True;
     938             :             }
     939             :         }
     940             : 
     941           0 :         if( aParaLBox.GetSavedValue() != aParaLBox.GetSelectEntryPos() )
     942             :         {
     943             :             rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
     944           0 :                                          aParaLBox.GetSelectEntryPos() ) );
     945           0 :             bModified |= sal_True;
     946             :         }
     947             :     }
     948           0 :     return bModified;
     949             : }
     950             : 
     951           0 : sal_Bool SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet& rCoreSet, sal_uInt16 nSlot)
     952             : {
     953           0 :     sal_uInt16 nWhich = GetWhich( nSlot );
     954           0 :     const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
     955           0 :     const SfxItemSet& rOldSet = GetItemSet();
     956             :     DBG_ASSERT(pOld,"FillItemSetWithWallpaperItem: Item not found");
     957             : 
     958           0 :     SvxBrushItem        rOldItem( (const CntWallpaperItem&)*pOld, nWhich );
     959           0 :     SvxGraphicPosition  eOldPos     = rOldItem.GetGraphicPos();
     960           0 :     const sal_Bool          bIsBrush    = ( 0 == aLbSelect.GetSelectEntryPos() );
     961           0 :     sal_Bool                bModified = sal_False;
     962             : 
     963           0 :     if (   ( (GPOS_NONE == eOldPos) && bIsBrush  )
     964             :         || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
     965             :     {
     966             :         // background art hasn't been changed
     967             : 
     968           0 :         if ( (GPOS_NONE == eOldPos) || !aLbSelect.IsVisible() )
     969             :         {
     970             :             // Brush-treatment:
     971           0 :             if ( rOldItem.GetColor() != aBgdColor )
     972             :             {
     973           0 :                 bModified = sal_True;
     974           0 :                 CntWallpaperItem aItem( nWhich );
     975           0 :                 aItem.SetColor( aBgdColor );
     976           0 :                 rCoreSet.Put( aItem );
     977             :             }
     978           0 :             else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
     979           0 :                 rCoreSet.ClearItem( nWhich );
     980             :         }
     981             :         else
     982             :         {
     983             :             // Bitmap-treatment:
     984           0 :             SvxGraphicPosition  eNewPos  = GetGraphicPosition_Impl();
     985             : 
     986             :             int bBitmapChanged = ( ( eNewPos != eOldPos ) ||
     987           0 :                                    ( *rOldItem.GetGraphicLink() != aBgdGraphicPath ) );
     988           0 :             int bBrushChanged = ( rOldItem.GetColor() != aBgdColor );
     989           0 :             if( bBitmapChanged || bBrushChanged )
     990             :             {
     991           0 :                 bModified = sal_True;
     992             : 
     993           0 :                 CntWallpaperItem aItem( nWhich );
     994           0 :                 WallpaperStyle eWallStyle = SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos);
     995           0 :                 aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
     996           0 :                 aItem.SetColor( aBgdColor );
     997           0 :                 aItem.SetBitmapURL( aBgdGraphicPath );
     998           0 :                 rCoreSet.Put( aItem );
     999             :             }
    1000           0 :             else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
    1001           0 :                 rCoreSet.ClearItem( nWhich );
    1002           0 :         }
    1003             :     }
    1004             :     else // Brush <-> Bitmap changed!
    1005             :     {
    1006           0 :         CntWallpaperItem aItem( nWhich );
    1007           0 :         if ( bIsBrush )
    1008             :         {
    1009           0 :             aItem.SetColor( aBgdColor );
    1010           0 :             rCoreSet.Put( aItem );
    1011             :         }
    1012             :         else
    1013             :         {
    1014             :             WallpaperStyle eWallStyle =
    1015           0 :                 SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
    1016           0 :             aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
    1017           0 :             aItem.SetColor( aBgdColor );
    1018           0 :             aItem.SetBitmapURL( aBgdGraphicPath );
    1019           0 :             rCoreSet.Put( aItem );
    1020             :         }
    1021             : 
    1022           0 :         bModified = sal_True;
    1023             :     }
    1024           0 :     return bModified;
    1025             : }
    1026             : 
    1027             : //-----------------------------------------------------------------------
    1028             : 
    1029           0 : int SvxBackgroundTabPage::DeactivatePage( SfxItemSet* _pSet )
    1030             : 
    1031             : /*  [Description]
    1032             : 
    1033             :     virtual method; is called on deactivation
    1034             : */
    1035             : 
    1036             : {
    1037           0 :     if ( pPageImpl->bIsImportDlgInExecute )
    1038           0 :         return KEEP_PAGE;
    1039             : 
    1040           0 :     if ( _pSet )
    1041           0 :         FillItemSet( *_pSet );
    1042             : 
    1043           0 :     return LEAVE_PAGE;
    1044             : }
    1045             : 
    1046             : //-----------------------------------------------------------------------
    1047             : 
    1048           0 : void SvxBackgroundTabPage::PointChanged( Window* , RECT_POINT  )
    1049             : {
    1050             :     // has to be implemented so that position control can work
    1051           0 : }
    1052             : 
    1053             : //-----------------------------------------------------------------------
    1054             : 
    1055           0 : void SvxBackgroundTabPage::ShowSelector()
    1056             : {
    1057           0 :     if( bAllowShowSelector)
    1058             :     {
    1059           0 :         aSelectTxt.Show();
    1060           0 :         aLbSelect.Show();
    1061           0 :         aLbSelect.SetSelectHdl( HDL(SelectHdl_Impl) );
    1062           0 :         aBtnLink.SetClickHdl( HDL(FileClickHdl_Impl) );
    1063           0 :         aBtnPreview.SetClickHdl( HDL(FileClickHdl_Impl) );
    1064           0 :         aBtnBrowse.SetClickHdl( HDL(BrowseHdl_Impl) );
    1065           0 :         aBtnArea.SetClickHdl( HDL(RadioClickHdl_Impl) );
    1066           0 :         aBtnTile.SetClickHdl( HDL(RadioClickHdl_Impl) );
    1067           0 :         aBtnPosition.SetClickHdl( HDL(RadioClickHdl_Impl) );
    1068             : 
    1069             :         // delayed loading via timer (because of UI-Update)
    1070           0 :         pPageImpl->pLoadTimer = new Timer;
    1071           0 :         pPageImpl->pLoadTimer->SetTimeout( 500 );
    1072             :         pPageImpl->pLoadTimer->SetTimeoutHdl(
    1073           0 :             LINK( this, SvxBackgroundTabPage, LoadTimerHdl_Impl ) );
    1074             : 
    1075           0 :         bAllowShowSelector = sal_False;
    1076             : 
    1077           0 :         if(nHtmlMode & HTMLMODE_ON)
    1078             :         {
    1079           0 :             aBtnArea.Enable(sal_False);
    1080             :         }
    1081             :     }
    1082           0 : }
    1083             : 
    1084             : //------------------------------------------------------------------------
    1085             : 
    1086             : 
    1087           0 : void SvxBackgroundTabPage::RaiseLoadError_Impl()
    1088             : {
    1089             :     SfxErrorContext aContext( ERRCTX_SVX_BACKGROUND,
    1090             :                               String(),
    1091             :                               this,
    1092             :                               RID_SVXERRCTX,
    1093           0 :                               &CUI_MGR() );
    1094             : 
    1095             :     ErrorHandler::HandleError(
    1096             :         *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE,
    1097           0 :                               aBgdGraphicPath ) );
    1098           0 : }
    1099             : 
    1100             : //------------------------------------------------------------------------
    1101             : 
    1102           0 : sal_Bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
    1103             : {
    1104           0 :     sal_Bool bResult = ( aBgdGraphicPath.Len() > 0 ) &&
    1105             :                    ( GRFILTER_OK == GraphicFilter::LoadGraphic( aBgdGraphicPath,
    1106             :                                                  aBgdGraphicFilter,
    1107           0 :                                                  aBgdGraphic ) );
    1108           0 :     return bResult;
    1109             : }
    1110             : 
    1111             : //------------------------------------------------------------------------
    1112             : 
    1113             : 
    1114           0 : void SvxBackgroundTabPage::FillColorValueSets_Impl()
    1115             : {
    1116           0 :     SfxObjectShell* pDocSh = SfxObjectShell::Current();
    1117           0 :     const SfxPoolItem* pItem = NULL;
    1118           0 :     XColorListRef pColorTable = NULL;
    1119           0 :     const Size aSize15x15 = Size( 15, 15 );
    1120             : 
    1121           0 :     if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) )
    1122           0 :         pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
    1123             : 
    1124           0 :     if ( !pColorTable.is() )
    1125           0 :         pColorTable = XColorList::CreateStdColorList();
    1126             : 
    1127           0 :     if ( pColorTable.is() )
    1128             :     {
    1129           0 :         short i = 0;
    1130           0 :         long nCount = pColorTable->Count();
    1131           0 :         XColorEntry* pEntry = NULL;
    1132           0 :         Color aColWhite( COL_WHITE );
    1133           0 :         String aStrWhite( EditResId( RID_SVXITEMS_COLOR_WHITE ) );
    1134           0 :         WinBits nBits = ( aBackgroundColorSet.GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD );
    1135           0 :         aBackgroundColorSet.SetText( SVX_RESSTR( RID_SVXSTR_TRANSPARENT ) );
    1136           0 :         aBackgroundColorSet.SetStyle( nBits );
    1137           0 :         aBackgroundColorSet.SetAccessibleName(aBackgroundColorBox.GetText());
    1138           0 :         for ( i = 0; i < nCount; i++ )
    1139             :         {
    1140           0 :             pEntry = pColorTable->GetColor(i);
    1141           0 :             aBackgroundColorSet.InsertItem( i + 1, pEntry->GetColor(), pEntry->GetName() );
    1142             :         }
    1143             : 
    1144           0 :         while ( i < 104 )
    1145             :         {
    1146           0 :             aBackgroundColorSet.InsertItem( i + 1, aColWhite, aStrWhite );
    1147           0 :             i++;
    1148             :         }
    1149             : 
    1150           0 :         if ( nCount > 104 )
    1151             :         {
    1152           0 :             aBackgroundColorSet.SetStyle( nBits | WB_VSCROLL );
    1153           0 :         }
    1154             :     }
    1155             : 
    1156           0 :     aBackgroundColorSet.SetColCount( 8 );
    1157           0 :     aBackgroundColorSet.SetLineCount( 13 );
    1158           0 :     aBackgroundColorSet.CalcWindowSizePixel( aSize15x15 );
    1159             : 
    1160           0 : }
    1161             : 
    1162             : //------------------------------------------------------------------------
    1163             : 
    1164             : 
    1165             : 
    1166             : //------------------------------------------------------------------------
    1167             : 
    1168           0 : void SvxBackgroundTabPage::ShowColorUI_Impl()
    1169             : 
    1170             : /*  [Description]
    1171             : 
    1172             :     Hide the controls for editing the bitmap
    1173             :     and show the controls for color settings instead.
    1174             : */
    1175             : 
    1176             : {
    1177           0 :     if( !aBackgroundColorSet.IsVisible() )
    1178             :     {
    1179           0 :         aBackgroundColorSet.Show();
    1180           0 :         aBackgroundColorBox.Show();
    1181           0 :         aBorderWin.Show();
    1182           0 :         pPreviewWin1->Show();
    1183           0 :         aBtnBrowse.Hide();
    1184           0 :         aFtFile.Hide();
    1185           0 :         aBtnLink.Hide();
    1186           0 :         aBtnPreview.Hide();
    1187           0 :         aGbFile.Hide();
    1188           0 :         aBtnPosition.Hide();
    1189           0 :         aBtnArea.Hide();
    1190           0 :         aBtnTile.Hide();
    1191           0 :         aWndPosition.Hide();
    1192           0 :         aGbPosition.Hide();
    1193           0 :         pPreviewWin2->Hide();
    1194           0 :         aGraphTransFL.Show(sal_False);
    1195           0 :         aGraphTransMF.Show(sal_False);
    1196           0 :         if(bColTransparency)
    1197             :         {
    1198           0 :             aColTransFT.Show();
    1199           0 :             aColTransMF.Show();
    1200             :         }
    1201             :     }
    1202           0 : }
    1203             : 
    1204             : //------------------------------------------------------------------------
    1205             : 
    1206           0 : void SvxBackgroundTabPage::ShowBitmapUI_Impl()
    1207             : 
    1208             : /*  [Description]
    1209             : 
    1210             :     Hide the the controls for color settings
    1211             :     and show controls for editing the bitmap instead.
    1212             : */
    1213             : 
    1214             : {
    1215           0 :     if ( aLbSelect.IsVisible() &&
    1216             :          (
    1217           0 :         aBackgroundColorSet.IsVisible()
    1218           0 :          || !aBtnBrowse.IsVisible() ) )
    1219             :     {
    1220           0 :         aBackgroundColorSet.Hide();
    1221           0 :         aBackgroundColorBox.Hide();
    1222           0 :         aBorderWin.Hide();
    1223           0 :         pPreviewWin1->Hide();
    1224           0 :         aBtnBrowse.Show();
    1225           0 :         aFtFile.Show();
    1226             : 
    1227           0 :         if ( !bLinkOnly && ! nHtmlMode & HTMLMODE_ON )
    1228           0 :             aBtnLink.Show();
    1229           0 :         aBtnPreview.Show();
    1230           0 :         aGbFile.Show();
    1231           0 :         aBtnPosition.Show();
    1232           0 :         aBtnArea.Show();
    1233           0 :         aBtnTile.Show();
    1234           0 :         aWndPosition.Show();
    1235           0 :         aGbPosition.Show();
    1236           0 :         pPreviewWin2->Show();
    1237           0 :         if(bGraphTransparency)
    1238             :         {
    1239           0 :             aGraphTransFL.Show();
    1240           0 :             aGraphTransMF.Show();
    1241             :         }
    1242           0 :         aColTransFT.Show(sal_False);
    1243           0 :         aColTransMF.Show(sal_False);
    1244             :     }
    1245           0 : }
    1246             : 
    1247             : //------------------------------------------------------------------------
    1248             : 
    1249           0 : void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos )
    1250             : {
    1251           0 :     switch ( ePos )
    1252             :     {
    1253             :         case GPOS_AREA:
    1254             :         {
    1255           0 :             aBtnArea.Check();
    1256           0 :             aWndPosition.Disable();
    1257             :         }
    1258           0 :         break;
    1259             : 
    1260             :         case GPOS_TILED:
    1261             :         {
    1262           0 :             aBtnTile.Check();
    1263           0 :             aWndPosition.Disable();
    1264             :         }
    1265           0 :         break;
    1266             : 
    1267             :         default:
    1268             :         {
    1269           0 :             aBtnPosition.Check();
    1270           0 :             aWndPosition.Enable();
    1271           0 :             RECT_POINT eNewPos = RP_MM;
    1272             : 
    1273           0 :             switch ( ePos )
    1274             :             {
    1275           0 :                 case GPOS_MM:   break;
    1276           0 :                 case GPOS_LT:   eNewPos = RP_LT; break;
    1277           0 :                 case GPOS_MT:   eNewPos = RP_MT; break;
    1278           0 :                 case GPOS_RT:   eNewPos = RP_RT; break;
    1279           0 :                 case GPOS_LM:   eNewPos = RP_LM; break;
    1280           0 :                 case GPOS_RM:   eNewPos = RP_RM; break;
    1281           0 :                 case GPOS_LB:   eNewPos = RP_LB; break;
    1282           0 :                 case GPOS_MB:   eNewPos = RP_MB; break;
    1283           0 :                 case GPOS_RB:   eNewPos = RP_RB; break;
    1284             :                 default: ;//prevent warning
    1285             :             }
    1286           0 :             aWndPosition.SetActualRP( eNewPos );
    1287             :         }
    1288           0 :         break;
    1289             :     }
    1290           0 :     aWndPosition.Invalidate();
    1291           0 : }
    1292             : 
    1293             : //------------------------------------------------------------------------
    1294             : 
    1295           0 : SvxGraphicPosition SvxBackgroundTabPage::GetGraphicPosition_Impl()
    1296             : {
    1297           0 :     if ( aBtnTile.IsChecked() )
    1298           0 :         return GPOS_TILED;
    1299           0 :     else if ( aBtnArea.IsChecked() )
    1300           0 :         return GPOS_AREA;
    1301             :     else
    1302             :     {
    1303           0 :         switch ( aWndPosition.GetActualRP() )
    1304             :         {
    1305           0 :             case RP_LT: return GPOS_LT;
    1306           0 :             case RP_MT: return GPOS_MT;
    1307           0 :             case RP_RT: return GPOS_RT;
    1308           0 :             case RP_LM: return GPOS_LM;
    1309           0 :             case RP_MM: return GPOS_MM;
    1310           0 :             case RP_RM: return GPOS_RM;
    1311           0 :             case RP_LB: return GPOS_LB;
    1312           0 :             case RP_MB: return GPOS_MB;
    1313           0 :             case RP_RB: return GPOS_RB;
    1314             :         }
    1315             :     }
    1316           0 :     return GPOS_MM;
    1317             : }
    1318             : 
    1319             : //-----------------------------------------------------------------------
    1320             : // Handler
    1321             : //-----------------------------------------------------------------------
    1322             : 
    1323           0 : IMPL_LINK_NOARG(SvxBackgroundTabPage, BackgroundColorHdl_Impl)
    1324             : /*
    1325             :     Handler, called when color selection is changed
    1326             : */
    1327             : {
    1328           0 :     sal_uInt16 nItemId = aBackgroundColorSet.GetSelectItemId();
    1329           0 :     Color aColor = nItemId ? ( aBackgroundColorSet.GetItemColor( nItemId ) ) : Color( COL_TRANSPARENT );
    1330           0 :     aBgdColor = aColor;
    1331           0 :     pPreviewWin1->NotifyChange( aBgdColor );
    1332           0 :     sal_Bool bEnableTransp = aBgdColor.GetTransparency() < 0xff;
    1333           0 :     aColTransFT.Enable(bEnableTransp);
    1334           0 :     aColTransMF.Enable(bEnableTransp);
    1335           0 :     return 0;
    1336             : }
    1337             : 
    1338             : //------------------------------------------------------------------------
    1339             : 
    1340           0 : IMPL_LINK_NOARG(SvxBackgroundTabPage, SelectHdl_Impl)
    1341             : {
    1342           0 :     if ( 0 == aLbSelect.GetSelectEntryPos() )
    1343             :     {
    1344           0 :         ShowColorUI_Impl();
    1345           0 :         aParaLBox.Enable(); // drawing background can't be a bitmap
    1346             :     }
    1347             :     else
    1348             :     {
    1349           0 :         ShowBitmapUI_Impl();
    1350           0 :         aParaLBox.Enable(sal_False); // drawing background can't be a bitmap
    1351             :     }
    1352           0 :     return 0;
    1353             : }
    1354             : 
    1355             : //------------------------------------------------------------------------
    1356             : 
    1357           0 : IMPL_LINK( SvxBackgroundTabPage, FileClickHdl_Impl, CheckBox*, pBox )
    1358             : {
    1359           0 :     if ( &aBtnLink == pBox )
    1360             :     {
    1361           0 :         if ( aBtnLink.IsChecked() )
    1362             :         {
    1363           0 :             INetURLObject aObj( aBgdGraphicPath );
    1364           0 :             String aFilePath;
    1365           0 :             if ( aObj.GetProtocol() == INET_PROT_FILE )
    1366           0 :                 aFilePath = aObj.getFSysPath( INetURLObject::FSYS_DETECT );
    1367             :             else
    1368           0 :                 aFilePath = aBgdGraphicPath;
    1369           0 :             aFtFile.SetText( aFilePath );
    1370             :         }
    1371             :         else
    1372           0 :             aFtFile.SetText( aStrUnlinked );
    1373             :     }
    1374           0 :     else if ( &aBtnPreview == pBox )
    1375             :     {
    1376           0 :         if ( aBtnPreview.IsChecked() )
    1377             :         {
    1378           0 :             if ( !bIsGraphicValid )
    1379           0 :                 bIsGraphicValid = LoadLinkedGraphic_Impl();
    1380             : 
    1381           0 :             if ( bIsGraphicValid )
    1382             :             {
    1383           0 :                 Bitmap aBmp = aBgdGraphic.GetBitmap();
    1384           0 :                 pPreviewWin2->NotifyChange( &aBmp );
    1385             :             }
    1386             :             else
    1387             :             {
    1388           0 :                 if ( aBgdGraphicPath.Len() > 0 ) // only for linked bitmap
    1389           0 :                     RaiseLoadError_Impl();
    1390           0 :                 pPreviewWin2->NotifyChange( NULL );
    1391             :             }
    1392             :         }
    1393             :         else
    1394           0 :             pPreviewWin2->NotifyChange( NULL );
    1395             :     }
    1396           0 :     return 0;
    1397             : }
    1398             : 
    1399             : //------------------------------------------------------------------------
    1400             : 
    1401           0 : IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
    1402             : {
    1403           0 :     if ( pBtn == &aBtnPosition )
    1404             :     {
    1405           0 :         if ( !aWndPosition.IsEnabled() )
    1406             :         {
    1407           0 :             aWndPosition.Enable();
    1408           0 :             aWndPosition.Invalidate();
    1409             :         }
    1410             :     }
    1411           0 :     else if ( aWndPosition.IsEnabled() )
    1412             :     {
    1413           0 :         aWndPosition.Disable();
    1414           0 :         aWndPosition.Invalidate();
    1415             :     }
    1416           0 :     return 0;
    1417             : }
    1418             : 
    1419             : //------------------------------------------------------------------------
    1420             : 
    1421           0 : IMPL_LINK_NOARG(SvxBackgroundTabPage, BrowseHdl_Impl)
    1422             : 
    1423             : /*  [Description]
    1424             : 
    1425             :     Handler, called by pressing the browse button.
    1426             :     Create graphic/insert dialog, set path and start.
    1427             : */
    1428             : 
    1429             : {
    1430           0 :     if ( pPageImpl->pLoadTimer->IsActive() )
    1431           0 :         return 0;
    1432           0 :     sal_Bool bHtml = 0 != ( nHtmlMode & HTMLMODE_ON );
    1433             : 
    1434           0 :     pImportDlg = new SvxOpenGraphicDialog( aStrBrowse );
    1435           0 :     if ( bHtml || bLinkOnly )
    1436           0 :         pImportDlg->EnableLink(sal_False);
    1437           0 :     pImportDlg->SetPath( aBgdGraphicPath, aBtnLink.IsChecked() );
    1438             : 
    1439           0 :     pPageImpl->bIsImportDlgInExecute = sal_True;
    1440           0 :     short nErr = pImportDlg->Execute();
    1441           0 :     pPageImpl->bIsImportDlgInExecute = sal_False;
    1442             : 
    1443           0 :     if( !nErr )
    1444             :     {
    1445           0 :         if ( bHtml )
    1446           0 :             aBtnLink.Check();
    1447             :         // if link isn't checked and preview isn't, either,
    1448             :         // activate preview, so that the user sees which
    1449             :         // graphic he has chosen
    1450           0 :         if ( !aBtnLink.IsChecked() && !aBtnPreview.IsChecked() )
    1451           0 :             aBtnPreview.Check( sal_True );
    1452             :         // timer-delayed loading of the graphic
    1453           0 :         pPageImpl->pLoadTimer->Start();
    1454             :     }
    1455             :     else
    1456           0 :         DELETEZ( pImportDlg );
    1457           0 :     return 0;
    1458             : }
    1459             : 
    1460             : //-----------------------------------------------------------------------
    1461             : 
    1462           0 : IMPL_LINK( SvxBackgroundTabPage, LoadTimerHdl_Impl, Timer* , pTimer )
    1463             : 
    1464             : /*  [Description]
    1465             : 
    1466             :     Delayed loading of the graphic.
    1467             :     Graphic is only loaded, if it's
    1468             :     different to the current graphic.
    1469             : */
    1470             : 
    1471             : {
    1472           0 :     if ( pTimer == pPageImpl->pLoadTimer )
    1473             :     {
    1474           0 :         pPageImpl->pLoadTimer->Stop();
    1475             : 
    1476           0 :         if ( pImportDlg )
    1477             :         {
    1478           0 :             INetURLObject aOld( aBgdGraphicPath );
    1479           0 :             INetURLObject aNew( pImportDlg->GetPath() );
    1480           0 :             if ( !aBgdGraphicPath.Len() || aNew != aOld )
    1481             :             {
    1482             :                 // new file chosen
    1483           0 :                 aBgdGraphicPath   = pImportDlg->GetPath();
    1484           0 :                 aBgdGraphicFilter = pImportDlg->GetCurrentFilter();
    1485           0 :                 sal_Bool bLink = ( nHtmlMode & HTMLMODE_ON ) || bLinkOnly ? sal_True : pImportDlg->IsAsLink();
    1486           0 :                 aBtnLink.Check( bLink );
    1487           0 :                 aBtnLink.Enable();
    1488             : 
    1489           0 :                 if ( aBtnPreview.IsChecked() )
    1490             :                 {
    1491           0 :                     if( !pImportDlg->GetGraphic(aBgdGraphic) )
    1492             :                     {
    1493           0 :                         bIsGraphicValid = sal_True;
    1494             :                     }
    1495             :                     else
    1496             :                     {
    1497           0 :                         aBgdGraphicFilter.Erase();
    1498           0 :                         aBgdGraphicPath.Erase();
    1499           0 :                         bIsGraphicValid = sal_False;
    1500             :                     }
    1501             :                 }
    1502             :                 else
    1503           0 :                     bIsGraphicValid = sal_False; // load graphic not until preview click
    1504             : 
    1505           0 :                 if ( aBtnPreview.IsChecked() && bIsGraphicValid )
    1506             :                 {
    1507           0 :                     Bitmap aBmp = aBgdGraphic.GetBitmap();
    1508           0 :                     pPreviewWin2->NotifyChange( &aBmp );
    1509             :                 }
    1510             :                 else
    1511           0 :                     pPreviewWin2->NotifyChange( NULL );
    1512             :             }
    1513             : 
    1514           0 :             FileClickHdl_Impl( &aBtnLink );
    1515           0 :             DELETEZ( pImportDlg );
    1516             :         }
    1517             :     }
    1518           0 :     return 0;
    1519             : }
    1520             : 
    1521             : //-----------------------------------------------------------------------
    1522             : 
    1523           0 : void SvxBackgroundTabPage::ShowTblControl()
    1524             : {
    1525           0 :     aTblLBox            .SetSelectHdl( HDL(TblDestinationHdl_Impl) );
    1526           0 :     aTblLBox            .SelectEntryPos(0);
    1527           0 :     aTblDesc.Show();
    1528           0 :     aTblLBox.Show();
    1529           0 : }
    1530             : 
    1531             : //-----------------------------------------------------------------------
    1532             : 
    1533           0 : void SvxBackgroundTabPage::ShowParaControl(sal_Bool bCharOnly)
    1534             : {
    1535           0 :     aParaLBox.SetSelectHdl(HDL(ParaDestinationHdl_Impl));
    1536           0 :     aParaLBox.SelectEntryPos(0);
    1537           0 :     if(!bCharOnly)
    1538             :     {
    1539           0 :         aTblDesc.Show();
    1540           0 :         aParaLBox.Show();
    1541             :     }
    1542           0 :     aParaLBox.SetData(&aParaLBox); // here it can be recognized that this mode is turned on
    1543           0 : }
    1544             : //-----------------------------------------------------------------------
    1545             : 
    1546           0 : IMPL_LINK( SvxBackgroundTabPage, TblDestinationHdl_Impl, ListBox*, pBox )
    1547             : {
    1548           0 :     sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
    1549           0 :     if( pTableBck_Impl && pTableBck_Impl->nActPos != nSelPos)
    1550             :     {
    1551           0 :         SvxBrushItem** pActItem = new (SvxBrushItem*);
    1552           0 :         sal_uInt16 nWhich = 0;
    1553           0 :         switch(pTableBck_Impl->nActPos)
    1554             :         {
    1555             :             case TBL_DEST_CELL:
    1556           0 :                 *pActItem = pTableBck_Impl->pCellBrush;
    1557           0 :                 nWhich = pTableBck_Impl->nCellWhich;
    1558           0 :             break;
    1559             :             case TBL_DEST_ROW:
    1560           0 :                 *pActItem = pTableBck_Impl->pRowBrush;
    1561           0 :                 nWhich = pTableBck_Impl->nRowWhich;
    1562           0 :             break;
    1563             :             case TBL_DEST_TBL:
    1564           0 :                 *pActItem = pTableBck_Impl->pTableBrush;
    1565           0 :                 nWhich = pTableBck_Impl->nTableWhich;
    1566           0 :             break;
    1567             :         }
    1568           0 :         pTableBck_Impl->nActPos = nSelPos;
    1569           0 :         if(!*pActItem)
    1570           0 :             *pActItem = new SvxBrushItem(nWhich);
    1571           0 :         if(0 == aLbSelect.GetSelectEntryPos())  // brush selected
    1572             :         {
    1573           0 :             **pActItem = SvxBrushItem( aBgdColor, nWhich );
    1574             :         }
    1575             :         else
    1576             :         {
    1577           0 :                 SvxGraphicPosition  eNewPos  = GetGraphicPosition_Impl();
    1578           0 :                 const sal_Bool          bIsLink  = aBtnLink.IsChecked();
    1579             : 
    1580           0 :                 if ( !bIsLink && !bIsGraphicValid )
    1581           0 :                     bIsGraphicValid = LoadLinkedGraphic_Impl();
    1582             : 
    1583           0 :                 if ( bIsLink )
    1584             :                     **pActItem = SvxBrushItem( aBgdGraphicPath,
    1585             :                                                 aBgdGraphicFilter,
    1586             :                                                 eNewPos,
    1587           0 :                                                 (*pActItem)->Which() );
    1588             :                 else
    1589             :                     **pActItem = SvxBrushItem( aBgdGraphic,
    1590             :                                                 eNewPos,
    1591           0 :                                                 (*pActItem)->Which() );
    1592             :         }
    1593           0 :         switch(nSelPos)
    1594             :         {
    1595             :             case TBL_DEST_CELL:
    1596           0 :                 *pActItem = pTableBck_Impl->pCellBrush;
    1597           0 :                 aLbSelect.Enable();
    1598           0 :                 nWhich = pTableBck_Impl->nCellWhich;
    1599           0 :             break;
    1600             :             case TBL_DEST_ROW:
    1601             :             {
    1602           0 :                 if((nHtmlMode & HTMLMODE_ON) && !(nHtmlMode & HTMLMODE_SOME_STYLES))
    1603           0 :                     aLbSelect.Disable();
    1604           0 :                 *pActItem = pTableBck_Impl->pRowBrush;
    1605           0 :                 nWhich = pTableBck_Impl->nRowWhich;
    1606             :             }
    1607           0 :             break;
    1608             :             case TBL_DEST_TBL:
    1609           0 :                 *pActItem = pTableBck_Impl->pTableBrush;
    1610           0 :                 aLbSelect.Enable();
    1611           0 :                 nWhich = pTableBck_Impl->nTableWhich;
    1612           0 :             break;
    1613             :         }
    1614           0 :         String aUserData = GetUserData();
    1615           0 :         if(!*pActItem)
    1616           0 :             *pActItem = new SvxBrushItem(nWhich);
    1617           0 :         FillControls_Impl(**pActItem, aUserData);
    1618           0 :         delete pActItem;
    1619             :     }
    1620           0 :     return 0;
    1621             : }
    1622             : 
    1623             : //-----------------------------------------------------------------------
    1624             : 
    1625           0 : IMPL_LINK( SvxBackgroundTabPage, ParaDestinationHdl_Impl, ListBox*, pBox )
    1626             : {
    1627           0 :     sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
    1628           0 :     if( pParaBck_Impl && pParaBck_Impl->nActPos != nSelPos)
    1629             :     {
    1630           0 :         SvxBrushItem** pActItem = new (SvxBrushItem*);
    1631           0 :         switch(pParaBck_Impl->nActPos)
    1632             :         {
    1633             :             case PARA_DEST_PARA:
    1634           0 :                 *pActItem = pParaBck_Impl->pParaBrush;
    1635           0 :             break;
    1636             :             case PARA_DEST_CHAR:
    1637           0 :                 *pActItem = pParaBck_Impl->pCharBrush;
    1638           0 :             break;
    1639             :         }
    1640           0 :         pParaBck_Impl->nActPos = nSelPos;
    1641           0 :         if(0 == aLbSelect.GetSelectEntryPos())  // brush selected
    1642             :         {
    1643           0 :             sal_uInt16 nWhich = (*pActItem)->Which();
    1644           0 :             **pActItem = SvxBrushItem( aBgdColor, nWhich );
    1645             :         }
    1646             :         else
    1647             :         {
    1648           0 :                 SvxGraphicPosition  eNewPos  = GetGraphicPosition_Impl();
    1649           0 :                 const sal_Bool          bIsLink  = aBtnLink.IsChecked();
    1650             : 
    1651           0 :                 if ( !bIsLink && !bIsGraphicValid )
    1652           0 :                     bIsGraphicValid = LoadLinkedGraphic_Impl();
    1653             : 
    1654           0 :                 if ( bIsLink )
    1655             :                     **pActItem = SvxBrushItem( aBgdGraphicPath,
    1656             :                                                 aBgdGraphicFilter,
    1657             :                                                 eNewPos,
    1658           0 :                                                 (*pActItem)->Which() );
    1659             :                 else
    1660             :                     **pActItem = SvxBrushItem( aBgdGraphic,
    1661             :                                                 eNewPos,
    1662           0 :                                                 (*pActItem)->Which() );
    1663             :         }
    1664           0 :         switch(nSelPos)
    1665             :         {
    1666             :             case PARA_DEST_PARA:
    1667           0 :                 *pActItem = pParaBck_Impl->pParaBrush;
    1668           0 :                 aLbSelect.Enable();
    1669           0 :             break;
    1670             :             case PARA_DEST_CHAR:
    1671             :             {
    1672           0 :                 *pActItem = pParaBck_Impl->pCharBrush;
    1673           0 :                 aLbSelect.Enable(sal_False);
    1674             :             }
    1675           0 :             break;
    1676             :         }
    1677           0 :         String aUserData = GetUserData();
    1678           0 :         FillControls_Impl(**pActItem, aUserData);
    1679           0 :         delete pActItem;
    1680             :     }
    1681           0 :     return 0;
    1682             : }
    1683             : 
    1684             : //-----------------------------------------------------------------------
    1685             : 
    1686           0 : void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
    1687             :                                               const String& rUserData )
    1688             : {
    1689           0 :     SvxGraphicPosition  ePos = rBgdAttr.GetGraphicPos();
    1690           0 :     const Color& rColor = rBgdAttr.GetColor();
    1691           0 :     if(bColTransparency)
    1692             :     {
    1693           0 :         aColTransMF.SetValue(lcl_TransparencyToPercent(rColor.GetTransparency()));
    1694           0 :         aColTransMF.SaveValue();
    1695           0 :         sal_Bool bEnableTransp = rColor.GetTransparency() < 0xff;
    1696           0 :         aColTransFT.Enable(bEnableTransp);
    1697           0 :         aColTransMF.Enable(bEnableTransp);
    1698             :         //the default setting should be "no transparency"
    1699           0 :         if(!bEnableTransp)
    1700           0 :             aColTransMF.SetValue(0);
    1701             :     }
    1702             : 
    1703           0 :     if ( GPOS_NONE == ePos || !aLbSelect.IsVisible() )
    1704             :     {
    1705           0 :         aLbSelect.SelectEntryPos( 0 );
    1706           0 :         ShowColorUI_Impl();
    1707           0 :         Color aTrColor( COL_TRANSPARENT );
    1708           0 :         aBgdColor = rColor;
    1709             : 
    1710           0 :         sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
    1711           0 :             GetItemId_Impl( aBackgroundColorSet, aBgdColor ) : 0;
    1712             : 
    1713           0 :         if( aTrColor != aBgdColor && nCol == 0)
    1714             :         {
    1715           0 :             aBackgroundColorSet.SetNoSelection();
    1716             :         }
    1717             :         else
    1718             :         {
    1719           0 :             aBackgroundColorSet.SelectItem( nCol );
    1720             :         }
    1721             : 
    1722           0 :         pPreviewWin1->NotifyChange( aBgdColor );
    1723           0 :         if ( aLbSelect.IsVisible() ) // initialize graphic part
    1724             :         {
    1725           0 :             aBgdGraphicFilter.Erase();
    1726           0 :             aBgdGraphicPath.Erase();
    1727             : 
    1728           0 :             if ( !rUserData.Len() )
    1729           0 :                 aBtnPreview.Check( sal_False );
    1730           0 :             aBtnLink.Check( sal_False );
    1731           0 :             aBtnLink.Disable();
    1732           0 :             pPreviewWin2->NotifyChange( NULL );
    1733           0 :             SetGraphicPosition_Impl( GPOS_TILED );  // tiles as default
    1734             :         }
    1735             :     }
    1736             :     else
    1737             :     {
    1738           0 :         const String*   pStrLink   = rBgdAttr.GetGraphicLink();
    1739           0 :         const String*   pStrFilter = rBgdAttr.GetGraphicFilter();
    1740             : 
    1741           0 :         aLbSelect.SelectEntryPos( 1 );
    1742           0 :         ShowBitmapUI_Impl();
    1743             : 
    1744           0 :         if ( pStrLink )
    1745             :         {
    1746             : #ifdef DBG_UTIL
    1747             :             INetURLObject aObj( *pStrLink );
    1748             :             DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
    1749             : #endif
    1750           0 :             aBgdGraphicPath = *pStrLink;
    1751           0 :             aBtnLink.Check( sal_True );
    1752           0 :             aBtnLink.Enable();
    1753             :         }
    1754             :         else
    1755             :         {
    1756           0 :             aBgdGraphicPath.Erase();
    1757           0 :             aBtnLink.Check( sal_False );
    1758           0 :             aBtnLink.Disable();
    1759             :         }
    1760             : 
    1761           0 :         if(bGraphTransparency)
    1762             :         {
    1763           0 :             const GraphicObject* pObject = rBgdAttr.GetGraphicObject();
    1764           0 :             if(pObject)
    1765           0 :                 aGraphTransMF.SetValue(lcl_TransparencyToPercent(pObject->GetAttr().GetTransparency()));
    1766             :             else
    1767           0 :                 aGraphTransMF.SetValue(0);
    1768           0 :             aGraphTransMF.SaveValue();
    1769             :         }
    1770             : 
    1771           0 :         FileClickHdl_Impl( &aBtnLink );
    1772             : 
    1773           0 :         if ( pStrFilter )
    1774           0 :             aBgdGraphicFilter = *pStrFilter;
    1775             :         else
    1776           0 :             aBgdGraphicFilter.Erase();
    1777             : 
    1778           0 :         if ( !pStrLink || aBtnPreview.IsChecked() )
    1779             :         {
    1780             :             // Graphic exists in the item and doesn't have
    1781             :             // to be loaded:
    1782             : 
    1783           0 :             const Graphic* pGraphic = rBgdAttr.GetGraphic();
    1784             : 
    1785           0 :             if ( !pGraphic && aBtnPreview.IsChecked() )
    1786           0 :                 bIsGraphicValid = LoadLinkedGraphic_Impl();
    1787           0 :             else if ( pGraphic )
    1788             :             {
    1789           0 :                 aBgdGraphic = *pGraphic;
    1790           0 :                 bIsGraphicValid = sal_True;
    1791             : 
    1792           0 :                 if ( !rUserData.Len() )
    1793           0 :                     aBtnPreview.Check();
    1794             :             }
    1795             :             else
    1796             :             {
    1797           0 :                 RaiseLoadError_Impl();
    1798           0 :                 bIsGraphicValid = sal_False;
    1799             : 
    1800           0 :                 if ( !rUserData.Len() )
    1801           0 :                     aBtnPreview.Check( sal_False );
    1802             :             }
    1803             :         }
    1804             : 
    1805           0 :         if ( aBtnPreview.IsChecked() && bIsGraphicValid )
    1806             :         {
    1807           0 :             Bitmap aBmp = aBgdGraphic.GetBitmap();
    1808           0 :             pPreviewWin2->NotifyChange( &aBmp );
    1809             :         }
    1810             :         else
    1811           0 :             pPreviewWin2->NotifyChange( NULL );
    1812             : 
    1813           0 :         SetGraphicPosition_Impl( ePos );
    1814             :     }
    1815           0 : }
    1816             : 
    1817           0 : void SvxBackgroundTabPage::EnableTransparency(sal_Bool bColor, sal_Bool bGraphic)
    1818             : {
    1819           0 :     bColTransparency  = bColor;
    1820           0 :     bGraphTransparency = bGraphic;
    1821           0 :     if(bColor)
    1822             :     {
    1823           0 :         aColTransFT.Show();
    1824           0 :         aColTransMF.Show();
    1825             :     }
    1826           0 :     if(bGraphic)
    1827             :     {
    1828           0 :         Size aRectSize(aWndPosition.GetSizePixel());
    1829           0 :         Point aRectPos(aWndPosition.GetPosPixel());
    1830           0 :         Point aFLPos(aGraphTransFL.GetPosPixel());
    1831           0 :         Size aTmp(LogicToPixel(Size(RSC_SP_FLGR_SPACE_Y, RSC_SP_FLGR_SPACE_Y), MAP_APPFONT));
    1832           0 :         long nRectHeight = aFLPos.Y() - aRectPos.Y() - aTmp.Height();
    1833           0 :         aRectSize.Height() = nRectHeight;
    1834           0 :         aWndPosition.SetSizePixel(aRectSize);
    1835           0 :         aWndPosition.Invalidate();
    1836             :     }
    1837           0 : }
    1838             : 
    1839           0 : void SvxBackgroundTabPage::PageCreated (SfxAllItemSet aSet)
    1840             : {
    1841           0 :     SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,sal_False);
    1842           0 :     if (pFlagItem)
    1843             :     {
    1844           0 :         sal_uInt32 nFlags=pFlagItem->GetValue();
    1845           0 :         if ( ( nFlags & SVX_SHOW_TBLCTL ) == SVX_SHOW_TBLCTL )
    1846           0 :             ShowTblControl();
    1847           0 :         if ( ( nFlags & SVX_SHOW_PARACTL ) == SVX_SHOW_PARACTL )
    1848           0 :             ShowParaControl();
    1849           0 :         if ( ( nFlags & SVX_SHOW_SELECTOR ) == SVX_SHOW_SELECTOR )
    1850           0 :             ShowSelector();
    1851           0 :         if ( ( nFlags & SVX_ENABLE_TRANSPARENCY ) == SVX_ENABLE_TRANSPARENCY )
    1852           0 :             EnableTransparency(sal_True, sal_True);
    1853             :     }
    1854           3 : }
    1855             : 
    1856             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10