LCOV - code coverage report
Current view: top level - svx/source/dialog - _bmpmask.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 671 0.3 %
Date: 2014-04-11 Functions: 4 58 6.9 %
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 <vcl/wrkwin.hxx>
      21             : #include <tools/shl.hxx>
      22             : #include <vcl/metaact.hxx>
      23             : #include <vcl/settings.hxx>
      24             : #include <svtools/valueset.hxx>
      25             : #include <svl/eitem.hxx>
      26             : #include <sfx2/dispatch.hxx>
      27             : #include <svtools/colrdlg.hxx>
      28             : 
      29             : #define BMPMASK_PRIVATE
      30             : 
      31             : #include <svx/dialmgr.hxx>
      32             : #include <svx/bmpmask.hxx>
      33             : #include <svx/dialogs.hrc>
      34             : #include <bmpmask.hrc>
      35             : #include <svx/svxids.hrc>
      36             : 
      37             : 
      38             : 
      39             : #define BMP_RESID(nId)  ResId(nId, DIALOG_MGR())
      40             : #define TRANSP_COL      (Color( 252, 252, 252 ))
      41             : #define OWN_CALLMODE    SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD
      42             : 
      43             : 
      44             : 
      45             : #define TEST_COLS()                                                 \
      46             : {                                                                   \
      47             :     nR = aCol.GetRed(); nG = aCol.GetGreen(); nB = aCol.GetBlue();  \
      48             :     for( i = 0; i < nCount; i++ )                                   \
      49             :     {                                                               \
      50             :         if ( ( pMinR[i] <= nR ) && ( pMaxR[i] >= nR ) &&            \
      51             :              ( pMinG[i] <= nG ) && ( pMaxG[i] >= nG ) &&            \
      52             :              ( pMinB[i] <= nB ) && ( pMaxB[i] >= nB ) )             \
      53             :         {                                                           \
      54             :             aCol = pDstCols[i]; bReplace = sal_True; break;             \
      55             :         }                                                           \
      56             :     }                                                               \
      57             : }
      58             : 
      59             : 
      60             : 
      61         253 : SFX_IMPL_DOCKINGWINDOW_WITHID( SvxBmpMaskChildWindow, SID_BMPMASK )
      62             : 
      63             : 
      64             : 
      65           0 : class ColorWindow : public Control
      66             : {
      67             :     Color       aColor;
      68             : 
      69             : 
      70             : public:
      71           0 :                 ColorWindow( Window* pParent, const ResId& rId ) :
      72             :                     Control( pParent, rId ),
      73           0 :                     aColor( COL_WHITE ) {};
      74             : 
      75           0 :     void        SetColor( const Color& rColor )
      76             :                 {
      77           0 :                     aColor = rColor;
      78           0 :                     Invalidate();
      79           0 :                 }
      80             : 
      81             :     virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
      82             : };
      83             : 
      84             : 
      85             : 
      86           0 : class MaskSet : public ValueSet
      87             : {
      88             :     SvxBmpMask*     pSvxBmpMask;
      89             : 
      90             : 
      91             : public:
      92             :     MaskSet( SvxBmpMask* pParent, const ResId& rId );
      93             : 
      94             :     virtual void    Select() SAL_OVERRIDE;
      95             :     virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
      96             :     virtual void GetFocus() SAL_OVERRIDE;
      97             : 
      98             :     void onEditColor();
      99             : };
     100             : 
     101             : 
     102             : 
     103           0 : MaskSet::MaskSet( SvxBmpMask* pParent, const ResId& rId ) :
     104             :             ValueSet        ( pParent, rId ),
     105           0 :             pSvxBmpMask     ( pParent )
     106             : {
     107           0 : }
     108             : 
     109             : 
     110             : 
     111           0 : void MaskSet::Select()
     112             : {
     113           0 :     ValueSet::Select();
     114             : 
     115           0 :     pSvxBmpMask->onSelect( this );
     116           0 : }
     117             : 
     118           0 : void MaskSet::GetFocus()
     119             : {
     120           0 :     ValueSet::GetFocus();
     121           0 :     SelectItem( 1 );
     122           0 :     pSvxBmpMask->onSelect( this );
     123           0 : }
     124             : 
     125           0 : void MaskSet::KeyInput( const KeyEvent& rKEvt )
     126             : {
     127           0 :     KeyCode aCode = rKEvt.GetKeyCode();
     128             : 
     129             :     // if the key has a modifier we don't care
     130           0 :     if( aCode.GetModifier() )
     131             :     {
     132           0 :         ValueSet::KeyInput( rKEvt );
     133             :     }
     134             :     else
     135             :     {
     136             :         // check for keys that interests us
     137           0 :         switch ( aCode.GetCode() )
     138             :         {
     139             :             case KEY_SPACE:
     140           0 :                 onEditColor();
     141           0 :                 break;
     142             :             default:
     143           0 :                 ValueSet::KeyInput( rKEvt );
     144             :         }
     145             : 
     146             :     }
     147           0 : }
     148             : 
     149           0 : void MaskSet::onEditColor()
     150             : {
     151           0 :     SvColorDialog* pColorDlg = new SvColorDialog( GetParent() );
     152             : 
     153           0 :     pColorDlg->SetColor(GetItemColor(1));
     154             : 
     155           0 :     if( pColorDlg->Execute() )
     156           0 :         SetItemColor( 1, pColorDlg->GetColor() );
     157             : 
     158           0 :     delete pColorDlg;
     159           0 : }
     160             : 
     161             : 
     162             : 
     163             : class MaskData
     164             : {
     165             :     SvxBmpMask*     pMask;
     166             :     sal_Bool            bIsReady;
     167             :     sal_Bool            bExecState;
     168             :     SfxBindings&    rBindings;
     169             : 
     170             : public:
     171             :                 MaskData( SvxBmpMask* pBmpMask, SfxBindings& rBind );
     172             : 
     173           0 :     sal_Bool        IsCbxReady() const { return bIsReady; }
     174           0 :     void        SetExecState( sal_Bool bState ) { bExecState = bState; }
     175           0 :     sal_Bool        IsExecReady() const { return bExecState; }
     176             : 
     177             :                 DECL_LINK( PipetteHdl, ToolBox* pTbx );
     178             :                 DECL_LINK( CbxHdl, CheckBox* pCbx );
     179             :                 DECL_LINK( CbxTransHdl, CheckBox* pCbx );
     180             :                 DECL_LINK( FocusLbHdl, ColorLB* pLb );
     181             :                 DECL_LINK(ExecHdl, void *);
     182             : };
     183             : 
     184             : 
     185             : 
     186           0 : MaskData::MaskData( SvxBmpMask* pBmpMask, SfxBindings& rBind ) :
     187             : 
     188             :     pMask       ( pBmpMask ),
     189             :     bIsReady    ( sal_False ),
     190             :     bExecState  ( sal_False ),
     191           0 :     rBindings   ( rBind )
     192             : 
     193             : {
     194           0 : }
     195             : 
     196             : 
     197             : 
     198           0 : IMPL_LINK( MaskData, PipetteHdl, ToolBox*, pTbx )
     199             : {
     200             :     SfxBoolItem aBItem( SID_BMPMASK_PIPETTE,
     201           0 :                         pTbx->IsItemChecked( TBI_PIPETTE ) );
     202             : 
     203           0 :     rBindings.GetDispatcher()->Execute( SID_BMPMASK_PIPETTE, OWN_CALLMODE, &aBItem, 0L );
     204             : 
     205           0 :     return 0;
     206             : }
     207             : 
     208             : 
     209             : 
     210           0 : IMPL_LINK( MaskData, CbxHdl, CheckBox*, pCbx )
     211             : {
     212           0 :     bIsReady =  pMask->aCbx1.IsChecked() || pMask->aCbx2.IsChecked() ||
     213           0 :                 pMask->aCbx3.IsChecked() || pMask->aCbx4.IsChecked();
     214             : 
     215           0 :     if ( bIsReady && IsExecReady() )
     216           0 :         pMask->aBtnExec.Enable();
     217             :     else
     218           0 :         pMask->aBtnExec.Disable();
     219             : 
     220             :     // When a checkbox is checked, the pipette is enabled
     221           0 :     if ( pCbx->IsChecked() )
     222             :     {
     223           0 :         MaskSet* pSet = NULL;
     224             : 
     225           0 :         if ( pCbx == &( pMask->aCbx1 ) )
     226           0 :             pSet = pMask->pQSet1;
     227           0 :         else if ( pCbx == &( pMask->aCbx2 ) )
     228           0 :             pSet = pMask->pQSet2;
     229           0 :         else if ( pCbx == &( pMask->aCbx3 ) )
     230           0 :             pSet = pMask->pQSet3;
     231             :         else // if ( pCbx == &( pMask->aCbx4 ) )
     232           0 :             pSet = pMask->pQSet4;
     233             : 
     234           0 :         pSet->SelectItem( 1 );
     235           0 :         pSet->Select();
     236             : 
     237           0 :         pMask->aTbxPipette.CheckItem( TBI_PIPETTE, true );
     238           0 :         PipetteHdl( &( pMask->aTbxPipette ) );
     239             :     }
     240             : 
     241           0 :     return 0;
     242             : }
     243             : 
     244             : 
     245             : 
     246           0 : IMPL_LINK( MaskData, CbxTransHdl, CheckBox*, pCbx )
     247             : {
     248           0 :     bIsReady = pCbx->IsChecked();
     249           0 :     if ( bIsReady )
     250             :     {
     251           0 :         pMask->pQSet1->Disable();
     252           0 :         pMask->pQSet2->Disable();
     253           0 :         pMask->pQSet3->Disable();
     254           0 :         pMask->pQSet4->Disable();
     255           0 :         pMask->pCtlPipette->Disable();
     256           0 :         pMask->aCbx1.Disable();
     257           0 :         pMask->aSp1.Disable();
     258           0 :         pMask->aCbx2.Disable();
     259           0 :         pMask->aSp2.Disable();
     260           0 :         pMask->aCbx3.Disable();
     261           0 :         pMask->aSp3.Disable();
     262           0 :         pMask->aCbx4.Disable();
     263           0 :         pMask->aSp4.Disable();
     264           0 :         pMask->aTbxPipette.Disable();
     265             : 
     266           0 :         pMask->aLbColor1.Disable();
     267           0 :         pMask->aLbColor2.Disable();
     268           0 :         pMask->aLbColor3.Disable();
     269           0 :         pMask->aLbColor4.Disable();
     270           0 :         pMask->aLbColorTrans.Enable();
     271             :     }
     272             :     else
     273             :     {
     274           0 :         pMask->pQSet1->Enable();
     275           0 :         pMask->pQSet2->Enable();
     276           0 :         pMask->pQSet3->Enable();
     277           0 :         pMask->pQSet4->Enable();
     278           0 :         pMask->pCtlPipette->Enable();
     279           0 :         pMask->aCbx1.Enable();
     280           0 :         pMask->aSp1.Enable();
     281           0 :         pMask->aCbx2.Enable();
     282           0 :         pMask->aSp2.Enable();
     283           0 :         pMask->aCbx3.Enable();
     284           0 :         pMask->aSp3.Enable();
     285           0 :         pMask->aCbx4.Enable();
     286           0 :         pMask->aSp4.Enable();
     287           0 :         pMask->aTbxPipette.Enable();
     288             : 
     289           0 :         pMask->aLbColor1.Enable();
     290           0 :         pMask->aLbColor2.Enable();
     291           0 :         pMask->aLbColor3.Enable();
     292           0 :         pMask->aLbColor4.Enable();
     293           0 :         pMask->aLbColorTrans.Disable();
     294             : 
     295           0 :         bIsReady = pMask->aCbx1.IsChecked() || pMask->aCbx2.IsChecked() ||
     296           0 :                    pMask->aCbx3.IsChecked() || pMask->aCbx4.IsChecked();
     297             :     }
     298             : 
     299           0 :     if ( bIsReady && IsExecReady() )
     300           0 :         pMask->aBtnExec.Enable();
     301             :     else
     302           0 :         pMask->aBtnExec.Disable();
     303             : 
     304           0 :     return 0L;
     305             : }
     306             : 
     307             : 
     308             : 
     309           0 : IMPL_LINK( MaskData, FocusLbHdl, ColorLB*, pLb )
     310             : {
     311             :     // MT: bFireFox as API parameter is ugly, find better solution????
     312           0 :     pMask->pQSet1->SelectItem( pLb == &( pMask->aLbColor1 ) ? 1 : 0 /* , false */ );
     313           0 :     pMask->pQSet2->SelectItem( pLb == &( pMask->aLbColor2 ) ? 1 : 0 /* , false */ );
     314           0 :     pMask->pQSet3->SelectItem( pLb == &( pMask->aLbColor3 ) ? 1 : 0 /* , false */ );
     315           0 :     pMask->pQSet4->SelectItem( pLb == &( pMask->aLbColor4 ) ? 1 : 0 /* , false */ );
     316             : 
     317           0 :     return 0;
     318             : }
     319             : 
     320             : 
     321             : 
     322           0 : IMPL_LINK_NOARG(MaskData, ExecHdl)
     323             : {
     324           0 :     SfxBoolItem aBItem( SID_BMPMASK_EXEC, true );
     325           0 :     rBindings.GetDispatcher()->Execute( SID_BMPMASK_EXEC, OWN_CALLMODE, &aBItem, 0L );
     326             : 
     327           0 :     return 0L;
     328             : }
     329             : 
     330             : 
     331             : 
     332           0 : void ColorWindow::Paint( const Rectangle &/*Rect*/ )
     333             : {
     334           0 :     const Color& rOldLineColor = GetLineColor();
     335           0 :     const Color& rOldFillColor = GetFillColor();
     336             : 
     337           0 :     SetLineColor( aColor );
     338           0 :     SetFillColor( aColor );
     339             : 
     340           0 :     DrawRect( Rectangle( Point(), GetSizePixel() ) );
     341             : 
     342           0 :     SetLineColor( rOldLineColor );
     343           0 :     SetFillColor( rOldFillColor );
     344           0 : }
     345             : 
     346             : 
     347             : 
     348           0 : SvxBmpMaskSelectItem::SvxBmpMaskSelectItem( sal_uInt16 nId_, SvxBmpMask& rMask,
     349             :                                             SfxBindings& rBindings ) :
     350             :             SfxControllerItem   ( nId_, rBindings ),
     351           0 :             rBmpMask            ( rMask)
     352             : {
     353           0 : }
     354             : 
     355             : 
     356             : 
     357           0 : void SvxBmpMaskSelectItem::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/,
     358             :                                          const SfxPoolItem* pItem )
     359             : {
     360           0 :     if ( ( nSID == SID_BMPMASK_EXEC ) && pItem )
     361             :     {
     362           0 :         const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
     363             : 
     364             :         DBG_ASSERT( pStateItem || pItem == 0, "SfxBoolItem erwartet");
     365             : 
     366           0 :         rBmpMask.SetExecState( pStateItem->GetValue() );
     367             :     }
     368           0 : }
     369             : 
     370             : 
     371             : 
     372           0 : SvxBmpMaskChildWindow::SvxBmpMaskChildWindow( Window* pParent_, sal_uInt16 nId,
     373             :                                               SfxBindings* pBindings,
     374             :                                               SfxChildWinInfo* pInfo ) :
     375           0 :         SfxChildWindow( pParent_, nId )
     376             : {
     377             :     pWindow = new SvxBmpMask( pBindings, this, pParent_,
     378           0 :                               BMP_RESID( RID_SVXDLG_BMPMASK ) );
     379           0 :     SvxBmpMask* pDlg = (SvxBmpMask*) pWindow;
     380             : 
     381           0 :     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
     382             : 
     383           0 :     pDlg->Initialize( pInfo );
     384           0 : }
     385             : 
     386             : 
     387             : 
     388           0 : SvxBmpMask::SvxBmpMask( SfxBindings *pBindinx,
     389             :                         SfxChildWindow *pCW,
     390             :                         Window* pParent,
     391             :                         const ResId& rResId ) :
     392             :         SfxDockingWindow    ( pBindinx, pCW, pParent, rResId ),
     393           0 :         aTbxPipette         ( this, BMP_RESID( TBX_PIPETTE ) ),
     394           0 :         pCtlPipette         ( new ColorWindow( this, BMP_RESID( WND_PIPETTE ) ) ),
     395           0 :         aBtnExec            ( this, BMP_RESID( BTN_EXEC ) ),
     396           0 :         aGrpQ               ( this, BMP_RESID( GRP_Q ) ),
     397             : 
     398           0 :         aFt1                ( this, BMP_RESID ( FT_1 ) ),
     399           0 :         aFt2                ( this, BMP_RESID ( FT_2 ) ),
     400           0 :         aFt3                ( this, BMP_RESID ( FT_3 ) ),
     401             : 
     402           0 :         aCbx1               ( this, BMP_RESID( CBX_1 ) ),
     403           0 :         pQSet1              ( new MaskSet( this, BMP_RESID( QCOL_1 ) ) ),
     404           0 :         aSp1                ( this, BMP_RESID( SP_1 ) ),
     405           0 :         aLbColor1           ( this, BMP_RESID ( LB_1 ) ),
     406             : 
     407           0 :         aCbx2               ( this, BMP_RESID( CBX_2 ) ),
     408           0 :         pQSet2              ( new MaskSet( this, BMP_RESID( QCOL_2 ) ) ),
     409           0 :         aSp2                ( this, BMP_RESID( SP_2 ) ),
     410           0 :         aLbColor2           ( this, BMP_RESID ( LB_2 ) ),
     411             : 
     412           0 :         aCbx3               ( this, BMP_RESID( CBX_3 ) ),
     413           0 :         pQSet3              ( new MaskSet( this, BMP_RESID( QCOL_3 ) ) ),
     414           0 :         aSp3                ( this, BMP_RESID( SP_3 ) ),
     415           0 :         aLbColor3           ( this, BMP_RESID ( LB_3 ) ),
     416             : 
     417           0 :         aCbx4               ( this, BMP_RESID( CBX_4 ) ),
     418           0 :         pQSet4              ( new MaskSet( this, BMP_RESID( QCOL_4 ) ) ),
     419           0 :         aSp4                ( this, BMP_RESID( SP_4 ) ),
     420           0 :         aLbColor4           ( this, BMP_RESID ( LB_4 ) ),
     421             : 
     422           0 :         pData               ( new MaskData( this, *pBindinx ) ),
     423           0 :         aCbxTrans           ( this, BMP_RESID( CBX_TRANS ) ),
     424           0 :         aLbColorTrans       ( this, BMP_RESID ( LB_TRANS ) ),
     425             :         aPipetteColor       ( COL_WHITE ),
     426             :         aSelItem            ( SID_BMPMASK_EXEC, *this, *pBindinx ),
     427           0 :         maImgPipette        ( BMP_RESID ( IMG_PIPETTE ) )
     428             : {
     429           0 :     FreeResource();
     430             : 
     431           0 :     ApplyStyle();
     432             : 
     433           0 :     aTbxPipette.SetSizePixel( aTbxPipette.CalcWindowSizePixel() );
     434           0 :     aTbxPipette.SetSelectHdl( LINK( pData, MaskData, PipetteHdl ) );
     435           0 :     aBtnExec.SetClickHdl( LINK( pData, MaskData, ExecHdl ) );
     436             : 
     437           0 :     aCbx1.SetClickHdl( LINK( pData, MaskData, CbxHdl ) );
     438           0 :     aCbx2.SetClickHdl( LINK( pData, MaskData, CbxHdl ) );
     439           0 :     aCbx3.SetClickHdl( LINK( pData, MaskData, CbxHdl ) );
     440           0 :     aCbx4.SetClickHdl( LINK( pData, MaskData, CbxHdl ) );
     441           0 :     aCbxTrans.SetClickHdl( LINK( pData, MaskData, CbxTransHdl ) );
     442             : 
     443           0 :     SetAccessibleNames ();
     444             : 
     445           0 :     aLbColor1.SetGetFocusHdl( LINK( pData, MaskData, FocusLbHdl ) );
     446           0 :     aLbColor2.SetGetFocusHdl( LINK( pData, MaskData, FocusLbHdl ) );
     447           0 :     aLbColor3.SetGetFocusHdl( LINK( pData, MaskData, FocusLbHdl ) );
     448           0 :     aLbColor4.SetGetFocusHdl( LINK( pData, MaskData, FocusLbHdl ) );
     449           0 :     aLbColorTrans.Disable();
     450             : 
     451           0 :     aSp1.SetValue( 10 );
     452           0 :     aSp2.SetValue( 10 );
     453           0 :     aSp3.SetValue( 10 );
     454           0 :     aSp4.SetValue( 10 );
     455             : 
     456           0 :     pQSet1->SetStyle( pQSet1->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER );
     457           0 :     pQSet1->SetColCount( 1 );
     458           0 :     pQSet1->SetLineCount( 1 );
     459           0 :     OUString sColorPalette (BMP_RESID( RID_SVXDLG_BMPMASK_STR_PALETTE));
     460           0 :     OUString sColorPaletteN;
     461           0 :     sColorPaletteN = sColorPalette;
     462           0 :     sColorPaletteN += " 1";
     463           0 :     pQSet1->InsertItem( 1, aPipetteColor, sColorPaletteN);
     464           0 :     pQSet1->SelectItem( 1 );
     465             : 
     466           0 :     pQSet2->SetStyle( pQSet2->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER );
     467           0 :     pQSet2->SetColCount( 1 );
     468           0 :     pQSet2->SetLineCount( 1 );
     469           0 :     sColorPaletteN = sColorPalette;
     470           0 :     sColorPaletteN += " 2";
     471           0 :     pQSet2->InsertItem( 1, aPipetteColor, sColorPaletteN);
     472           0 :     pQSet2->SelectItem( 0 );
     473             : 
     474           0 :     pQSet3->SetStyle( pQSet3->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER );
     475           0 :     pQSet3->SetColCount( 1 );
     476           0 :     pQSet3->SetLineCount( 1 );
     477           0 :     sColorPaletteN = sColorPalette;
     478           0 :     sColorPaletteN += " 3";
     479           0 :     pQSet3->InsertItem( 1, aPipetteColor, sColorPaletteN);
     480           0 :     pQSet3->SelectItem( 0 );
     481             : 
     482           0 :     pQSet4->SetStyle( pQSet4->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER );
     483           0 :     pQSet4->SetColCount( 1 );
     484           0 :     pQSet4->SetLineCount( 1 );
     485           0 :     sColorPaletteN = sColorPalette;
     486           0 :     sColorPaletteN += " 4";
     487           0 :     pQSet4->InsertItem( 1, aPipetteColor, sColorPaletteN);
     488           0 :     pQSet4->SelectItem( 0 );
     489             : 
     490           0 :     pQSet1->Show();
     491           0 :     pQSet2->Show();
     492           0 :     pQSet3->Show();
     493           0 :     pQSet4->Show();
     494             : 
     495           0 :     aCbx1.SetAccessibleRelationMemberOf( &aGrpQ );
     496           0 :     pQSet1->SetAccessibleRelationMemberOf( &aGrpQ );
     497           0 :     aSp1.SetAccessibleRelationMemberOf( &aGrpQ );
     498           0 :     aLbColor1.SetAccessibleRelationMemberOf( &aGrpQ );
     499           0 :     aCbx1.SetAccessibleRelationLabeledBy( &aFt1 );
     500           0 :     pQSet1->SetAccessibleRelationLabeledBy( &aFt1 );
     501           0 :     aSp1.SetAccessibleRelationLabeledBy( &aFt2 );
     502           0 :     aLbColor1.SetAccessibleRelationLabeledBy( &aFt3 );
     503           0 :     aCbx2.SetAccessibleRelationMemberOf( &aGrpQ );
     504           0 :     pQSet2->SetAccessibleRelationMemberOf( &aGrpQ );
     505           0 :     aSp2.SetAccessibleRelationMemberOf( &aGrpQ );
     506           0 :     aLbColor2.SetAccessibleRelationMemberOf( &aGrpQ );
     507           0 :     aCbx2.SetAccessibleRelationLabeledBy( &aFt1 );
     508           0 :     pQSet2->SetAccessibleRelationLabeledBy( &aFt1 );
     509           0 :     aSp2.SetAccessibleRelationLabeledBy( &aFt2 );
     510           0 :     aLbColor2.SetAccessibleRelationLabeledBy( &aFt3 );
     511           0 :     aCbx3.SetAccessibleRelationMemberOf( &aGrpQ );
     512           0 :     pQSet3->SetAccessibleRelationMemberOf( &aGrpQ );
     513           0 :     aSp3.SetAccessibleRelationMemberOf( &aGrpQ );
     514           0 :     aLbColor3.SetAccessibleRelationMemberOf( &aGrpQ );
     515           0 :     aCbx3.SetAccessibleRelationLabeledBy( &aFt1 );
     516           0 :     pQSet3->SetAccessibleRelationLabeledBy( &aFt1 );
     517           0 :     aSp3.SetAccessibleRelationLabeledBy( &aFt2 );
     518           0 :     aLbColor3.SetAccessibleRelationLabeledBy( &aFt3 );
     519           0 :     aCbx4.SetAccessibleRelationMemberOf( &aGrpQ );
     520           0 :     pQSet4->SetAccessibleRelationMemberOf( &aGrpQ );
     521           0 :     aSp4.SetAccessibleRelationMemberOf( &aGrpQ );
     522           0 :     aLbColor4.SetAccessibleRelationMemberOf( &aGrpQ );
     523           0 :     aCbx4.SetAccessibleRelationLabeledBy( &aFt1 );
     524           0 :     pQSet4->SetAccessibleRelationLabeledBy( &aFt1 );
     525           0 :     aSp4.SetAccessibleRelationLabeledBy( &aFt2 );
     526           0 :     aLbColor4.SetAccessibleRelationLabeledBy( &aFt3 );
     527           0 :     aLbColorTrans.SetAccessibleRelationLabeledBy( &aCbxTrans );
     528           0 :     aLbColorTrans.SetAccessibleRelationMemberOf( &aGrpQ );
     529           0 :     aCbxTrans.SetAccessibleRelationMemberOf( &aGrpQ );
     530           0 : }
     531             : 
     532             : 
     533             : 
     534           0 : SvxBmpMask::~SvxBmpMask()
     535             : {
     536           0 :     delete pQSet1;
     537           0 :     delete pQSet2;
     538           0 :     delete pQSet3;
     539           0 :     delete pQSet4;
     540           0 :     delete pCtlPipette;
     541           0 :     delete pData;
     542           0 : }
     543             : 
     544             : 
     545             : 
     546             : /** is called by a MaskSet when it is selected */
     547           0 : void SvxBmpMask::onSelect( MaskSet* pSet )
     548             : {
     549             :     // now deselect all other value sets
     550           0 :     if( pSet != pQSet1 )
     551           0 :         pQSet1->SelectItem( 0 );
     552             : 
     553           0 :     if( pSet != pQSet2 )
     554           0 :         pQSet2->SelectItem( 0 );
     555             : 
     556           0 :     if( pSet != pQSet3 )
     557           0 :         pQSet3->SelectItem( 0 );
     558             : 
     559           0 :     if( pSet != pQSet4 )
     560           0 :         pQSet4->SelectItem( 0 );
     561           0 : }
     562             : 
     563             : 
     564             : 
     565           0 : bool SvxBmpMask::Close()
     566             : {
     567           0 :     SfxBoolItem aItem2( SID_BMPMASK_PIPETTE, false );
     568           0 :     GetBindings().GetDispatcher()->Execute( SID_BMPMASK_PIPETTE, OWN_CALLMODE, &aItem2, 0L );
     569             : 
     570           0 :     return SfxDockingWindow::Close();
     571             : }
     572             : 
     573             : 
     574             : 
     575           0 : bool SvxBmpMask::NeedsColorList() const
     576             : {
     577           0 :     return ( aLbColor1.GetEntryCount() == 0 );
     578             : }
     579             : 
     580             : 
     581             : 
     582           0 : void SvxBmpMask::SetColorList( const XColorListRef &pList )
     583             : {
     584           0 :     if ( pList.is() && ( pList != pColLst ) )
     585             :     {
     586           0 :         const OUString aTransp(BMP_RESID(RID_SVXDLG_BMPMASK_STR_TRANSP).toString());
     587             : 
     588           0 :         pColLst = pList;
     589             : 
     590           0 :         aLbColorTrans.Fill( pColLst );
     591           0 :         aLbColorTrans.SelectEntryPos( 0 );
     592             : 
     593           0 :         aLbColor1.Fill( pColLst );
     594           0 :         aLbColor1.InsertEntry( TRANSP_COL, aTransp, 0 );
     595           0 :         aLbColor1.SelectEntryPos( 0 );
     596             : 
     597           0 :         aLbColor2.Fill( pColLst );
     598           0 :         aLbColor2.InsertEntry( TRANSP_COL, aTransp, 0 );
     599           0 :         aLbColor2.SelectEntryPos( 0 );
     600             : 
     601           0 :         aLbColor3.Fill( pColLst );
     602           0 :         aLbColor3.InsertEntry( TRANSP_COL, aTransp, 0 );
     603           0 :         aLbColor3.SelectEntryPos( 0 );
     604             : 
     605           0 :         aLbColor4.Fill( pColLst );
     606           0 :         aLbColor4.InsertEntry( TRANSP_COL, aTransp, 0 );
     607           0 :         aLbColor4.SelectEntryPos( 0 );
     608             :     }
     609           0 : }
     610             : 
     611             : 
     612             : 
     613           0 : void SvxBmpMask::SetColor( const Color& rColor )
     614             : {
     615           0 :     aPipetteColor = rColor;
     616           0 :     pCtlPipette->SetColor( aPipetteColor );
     617           0 : }
     618             : 
     619             : 
     620             : 
     621           0 : void SvxBmpMask::PipetteClicked()
     622             : {
     623           0 :     if( pQSet1->GetSelectItemId() == 1 )
     624             :     {
     625           0 :         aCbx1.Check( true );
     626           0 :         pData->CbxHdl( &aCbx1 );
     627           0 :         pQSet1->SetItemColor( 1, aPipetteColor );
     628             :     }
     629           0 :     else if( pQSet2->GetSelectItemId() == 1 )
     630             :     {
     631           0 :         aCbx2.Check( true );
     632           0 :         pData->CbxHdl( &aCbx2 );
     633           0 :         pQSet2->SetItemColor( 1, aPipetteColor );
     634             :     }
     635           0 :     else if( pQSet3->GetSelectItemId() == 1 )
     636             :     {
     637           0 :         aCbx3.Check( true );
     638           0 :         pData->CbxHdl( &aCbx3 );
     639           0 :         pQSet3->SetItemColor( 1, aPipetteColor );
     640             :     }
     641           0 :     else if( pQSet4->GetSelectItemId() == 1 )
     642             :     {
     643           0 :         aCbx4.Check( true );
     644           0 :         pData->CbxHdl( &aCbx4 );
     645           0 :         pQSet4->SetItemColor( 1, aPipetteColor );
     646             :     }
     647             : 
     648           0 :     aTbxPipette.CheckItem( TBI_PIPETTE, false );
     649           0 :     pData->PipetteHdl( &aTbxPipette );
     650           0 : }
     651             : 
     652             : 
     653             : 
     654           0 : void SvxBmpMask::SetExecState( bool bEnable )
     655             : {
     656           0 :     pData->SetExecState( bEnable );
     657             : 
     658           0 :     if ( pData->IsExecReady() && pData->IsCbxReady() )
     659           0 :         aBtnExec.Enable();
     660             :     else
     661           0 :         aBtnExec.Disable();
     662           0 : }
     663             : 
     664             : 
     665             : 
     666           0 : sal_uInt16 SvxBmpMask::InitColorArrays( Color* pSrcCols, Color* pDstCols, sal_uIntPtr* pTols )
     667             : {
     668           0 :     sal_uInt16  nCount = 0;
     669             : 
     670           0 :     if ( aCbx1.IsChecked() )
     671             :     {
     672           0 :         pSrcCols[nCount] = pQSet1->GetItemColor( 1 );
     673           0 :         pDstCols[nCount] = aLbColor1.GetSelectEntryColor();
     674           0 :         pTols[nCount++] = static_cast<sal_uIntPtr>(aSp1.GetValue());
     675             :     }
     676             : 
     677           0 :     if ( aCbx2.IsChecked() )
     678             :     {
     679           0 :         pSrcCols[nCount] = pQSet2->GetItemColor( 1 );
     680           0 :         pDstCols[nCount] = aLbColor2.GetSelectEntryColor();
     681           0 :         pTols[nCount++] = static_cast<sal_uIntPtr>(aSp2.GetValue());
     682             :     }
     683             : 
     684           0 :     if ( aCbx3.IsChecked() )
     685             :     {
     686           0 :         pSrcCols[nCount] = pQSet3->GetItemColor( 1 );
     687           0 :         pDstCols[nCount] = aLbColor3.GetSelectEntryColor();
     688           0 :         pTols[nCount++] = static_cast<sal_uIntPtr>(aSp3.GetValue());
     689             :     }
     690             : 
     691           0 :     if ( aCbx4.IsChecked() )
     692             :     {
     693           0 :         pSrcCols[nCount] = pQSet4->GetItemColor( 1 );
     694           0 :         pDstCols[nCount] = aLbColor4.GetSelectEntryColor();
     695           0 :         pTols[nCount++] = static_cast<sal_uIntPtr>(aSp4.GetValue());
     696             :     }
     697             : 
     698           0 :     return nCount;
     699             : }
     700             : 
     701             : 
     702             : 
     703           0 : Bitmap SvxBmpMask::ImpMask( const Bitmap& rBitmap )
     704             : {
     705           0 :     Bitmap          aBitmap( rBitmap );
     706           0 :     Color           pSrcCols[4];
     707           0 :     Color           pDstCols[4];
     708             :     sal_uIntPtr         pTols[4];
     709           0 :     const sal_uInt16    nCount = InitColorArrays( pSrcCols, pDstCols, pTols );
     710             : 
     711           0 :     EnterWait();
     712           0 :     aBitmap.Replace( pSrcCols, pDstCols, nCount, pTols );
     713           0 :     LeaveWait();
     714             : 
     715           0 :     return aBitmap;
     716             : }
     717             : 
     718             : 
     719             : 
     720           0 : BitmapEx SvxBmpMask::ImpMaskTransparent( const BitmapEx& rBitmapEx, const Color& rColor, const long nTol )
     721             : {
     722           0 :     EnterWait();
     723             : 
     724           0 :     BitmapEx    aBmpEx;
     725           0 :     Bitmap      aMask( rBitmapEx.GetBitmap().CreateMask( rColor, nTol ) );
     726             : 
     727           0 :     if( rBitmapEx.IsTransparent() )
     728           0 :         aMask.CombineSimple( rBitmapEx.GetMask(), BMP_COMBINE_OR );
     729             : 
     730           0 :     aBmpEx = BitmapEx( rBitmapEx.GetBitmap(), aMask );
     731           0 :     LeaveWait();
     732             : 
     733           0 :     return aBmpEx;
     734             : }
     735             : 
     736             : 
     737             : 
     738           0 : Animation SvxBmpMask::ImpMask( const Animation& rAnimation )
     739             : {
     740           0 :     Animation   aAnimation( rAnimation );
     741           0 :     Color       pSrcCols[4];
     742           0 :     Color       pDstCols[4];
     743             :     sal_uIntPtr     pTols[4];
     744           0 :     InitColorArrays( pSrcCols, pDstCols, pTols );
     745           0 :     sal_uInt16      nAnimationCount = aAnimation.Count();
     746             : 
     747           0 :     for( sal_uInt16 i = 0; i < nAnimationCount; i++ )
     748             :     {
     749           0 :         AnimationBitmap aAnimBmp( aAnimation.Get( i ) );
     750           0 :         aAnimBmp.aBmpEx = Mask( aAnimBmp.aBmpEx ).GetBitmapEx();
     751           0 :         aAnimation.Replace( aAnimBmp, i );
     752           0 :     }
     753             : 
     754           0 :     return aAnimation;
     755             : }
     756             : 
     757             : 
     758             : 
     759           0 : GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
     760             : {
     761           0 :     GDIMetaFile aMtf;
     762           0 :     Color       pSrcCols[4];
     763           0 :     Color       pDstCols[4];
     764             :     sal_uIntPtr     pTols[4];
     765           0 :     sal_uInt16      nCount = InitColorArrays( pSrcCols, pDstCols, pTols );
     766             :     sal_Bool        pTrans[4];
     767             : 
     768             :     // If no color is selected, we copy only the Mtf
     769           0 :     if( !nCount )
     770           0 :         aMtf = rMtf;
     771             :     else
     772             :     {
     773           0 :         Color       aCol;
     774             :         long        nVal;
     775             :         long        nTol;
     776             :         long        nR;
     777             :         long        nG;
     778             :         long        nB;
     779           0 :         long*       pMinR = new long[nCount];
     780           0 :         long*       pMaxR = new long[nCount];
     781           0 :         long*       pMinG = new long[nCount];
     782           0 :         long*       pMaxG = new long[nCount];
     783           0 :         long*       pMinB = new long[nCount];
     784           0 :         long*       pMaxB = new long[nCount];
     785             :         sal_uInt16      i;
     786             :         sal_Bool        bReplace;
     787             : 
     788           0 :         aMtf.SetPrefSize( rMtf.GetPrefSize() );
     789           0 :         aMtf.SetPrefMapMode( rMtf.GetPrefMapMode() );
     790             : 
     791             :         // Prepare Color comparison array
     792           0 :         for( i = 0; i < nCount; i++ )
     793             :         {
     794           0 :             nTol = ( pTols[i] * 255L ) / 100L;
     795             : 
     796           0 :             nVal = ( (long) pSrcCols[i].GetRed() );
     797           0 :             pMinR[i] = std::max( nVal - nTol, 0L );
     798           0 :             pMaxR[i] = std::min( nVal + nTol, 255L );
     799             : 
     800           0 :             nVal = ( (long) pSrcCols[i].GetGreen() );
     801           0 :             pMinG[i] = std::max( nVal - nTol, 0L );
     802           0 :             pMaxG[i] = std::min( nVal + nTol, 255L );
     803             : 
     804           0 :             nVal = ( (long) pSrcCols[i].GetBlue() );
     805           0 :             pMinB[i] = std::max( nVal - nTol, 0L );
     806           0 :             pMaxB[i] = std::min( nVal + nTol, 255L );
     807             : 
     808           0 :             pTrans[ i ] = ( pDstCols[ i ] == TRANSP_COL );
     809             :         }
     810             : 
     811             :         // Investigate actions and if necessary replace colors
     812           0 :         for( size_t nAct = 0, nActCount = rMtf.GetActionSize(); nAct < nActCount; nAct++ )
     813             :         {
     814           0 :             MetaAction* pAction = rMtf.GetAction( nAct );
     815             : 
     816           0 :             bReplace = sal_False;
     817             : 
     818           0 :             switch( pAction->GetType() )
     819             :             {
     820             :                 case( META_PIXEL_ACTION ):
     821             :                 {
     822           0 :                     MetaPixelAction* pAct = (MetaPixelAction*) pAction;
     823             : 
     824           0 :                     aCol = pAct->GetColor();
     825           0 :                     TEST_COLS();
     826             : 
     827           0 :                     if( bReplace )
     828           0 :                         pAct = new MetaPixelAction( pAct->GetPoint(), aCol );
     829             :                     else
     830           0 :                         pAct->Duplicate();
     831             : 
     832           0 :                     aMtf.AddAction( pAct );
     833             :                 }
     834           0 :                 break;
     835             : 
     836             :                 case( META_LINECOLOR_ACTION ):
     837             :                 {
     838           0 :                     MetaLineColorAction* pAct = (MetaLineColorAction*) pAction;
     839             : 
     840           0 :                     aCol = pAct->GetColor();
     841           0 :                     TEST_COLS();
     842             : 
     843           0 :                     if( bReplace )
     844           0 :                         pAct = new MetaLineColorAction( aCol, !pTrans[ i ] );
     845             :                     else
     846           0 :                         pAct->Duplicate();
     847             : 
     848           0 :                     aMtf.AddAction( pAct );
     849             :                 }
     850           0 :                 break;
     851             : 
     852             :                 case( META_FILLCOLOR_ACTION ):
     853             :                 {
     854           0 :                     MetaFillColorAction* pAct = (MetaFillColorAction*) pAction;
     855             : 
     856           0 :                     aCol = pAct->GetColor();
     857           0 :                     TEST_COLS();
     858             : 
     859           0 :                     if( bReplace )
     860           0 :                         pAct = new MetaFillColorAction( aCol, !pTrans[ i ] );
     861             :                     else
     862           0 :                         pAct->Duplicate();
     863             : 
     864           0 :                     aMtf.AddAction( pAct );
     865             :                 }
     866           0 :                 break;
     867             : 
     868             :                 case( META_TEXTCOLOR_ACTION ):
     869             :                 {
     870           0 :                     MetaTextColorAction* pAct = (MetaTextColorAction*) pAction;
     871             : 
     872           0 :                     aCol = pAct->GetColor();
     873           0 :                     TEST_COLS();
     874             : 
     875           0 :                     if( bReplace )
     876           0 :                         pAct = new MetaTextColorAction( aCol );
     877             :                     else
     878           0 :                         pAct->Duplicate();
     879             : 
     880           0 :                     aMtf.AddAction( pAct );
     881             :                 }
     882           0 :                 break;
     883             : 
     884             :                 case( META_TEXTFILLCOLOR_ACTION ):
     885             :                 {
     886           0 :                     MetaTextFillColorAction* pAct = (MetaTextFillColorAction*) pAction;
     887             : 
     888           0 :                     aCol = pAct->GetColor();
     889           0 :                     TEST_COLS();
     890             : 
     891           0 :                     if( bReplace )
     892           0 :                         pAct = new MetaTextFillColorAction( aCol, !pTrans[ i ] );
     893             :                     else
     894           0 :                         pAct->Duplicate();
     895             : 
     896           0 :                     aMtf.AddAction( pAct );
     897             :                 }
     898           0 :                 break;
     899             : 
     900             :                 case( META_FONT_ACTION ):
     901             :                 {
     902           0 :                     MetaFontAction* pAct = (MetaFontAction*) pAction;
     903           0 :                     Font            aFont( pAct->GetFont() );
     904             : 
     905           0 :                     aCol = aFont.GetColor();
     906           0 :                     TEST_COLS();
     907             : 
     908           0 :                     if( bReplace )
     909             :                     {
     910           0 :                         aFont.SetColor( aCol );
     911           0 :                         pAct = new MetaFontAction( aFont );
     912             :                     }
     913             :                     else
     914           0 :                         pAct->Duplicate();
     915             : 
     916           0 :                     aMtf.AddAction( pAct );
     917             :                 }
     918           0 :                 break;
     919             : 
     920             :                 case( META_WALLPAPER_ACTION ):
     921             :                 {
     922           0 :                     MetaWallpaperAction*    pAct = (MetaWallpaperAction*) pAction;
     923           0 :                     Wallpaper               aWall( pAct->GetWallpaper() );
     924             : 
     925           0 :                     aCol = aWall.GetColor();
     926           0 :                     TEST_COLS();
     927             : 
     928           0 :                     if( bReplace )
     929             :                     {
     930           0 :                         aWall.SetColor( aCol );
     931           0 :                         pAct = new MetaWallpaperAction( pAct->GetRect(), aWall );
     932             :                     }
     933             :                     else
     934           0 :                         pAct->Duplicate();
     935             : 
     936           0 :                     aMtf.AddAction( pAct );
     937             :                 }
     938           0 :                 break;
     939             : 
     940             :                 case( META_BMP_ACTION ):
     941             :                 {
     942           0 :                     MetaBmpAction*  pAct = (MetaBmpAction*) pAction;
     943           0 :                     const Bitmap    aBmp( Mask( pAct->GetBitmap() ).GetBitmap() );
     944             : 
     945           0 :                     pAct = new MetaBmpAction( pAct->GetPoint(), aBmp );
     946           0 :                     aMtf.AddAction( pAct );
     947             :                 }
     948           0 :                 break;
     949             : 
     950             :                 case( META_BMPSCALE_ACTION ):
     951             :                 {
     952           0 :                     MetaBmpScaleAction* pAct = (MetaBmpScaleAction*) pAction;
     953           0 :                     const Bitmap        aBmp( Mask( pAct->GetBitmap() ).GetBitmap() );
     954             : 
     955           0 :                     pAct = new MetaBmpScaleAction( pAct->GetPoint(), pAct->GetSize(), aBmp );
     956           0 :                     aMtf.AddAction( pAct );
     957             :                 }
     958           0 :                 break;
     959             : 
     960             :                 case( META_BMPSCALEPART_ACTION ):
     961             :                 {
     962           0 :                     MetaBmpScalePartAction* pAct = (MetaBmpScalePartAction*) pAction;
     963           0 :                     const Bitmap            aBmp( Mask( pAct->GetBitmap() ).GetBitmap() );
     964             : 
     965             :                     pAct = new MetaBmpScalePartAction( pAct->GetDestPoint(), pAct->GetDestSize(),
     966           0 :                                                        pAct->GetSrcPoint(), pAct->GetSrcSize(), aBmp );
     967           0 :                     aMtf.AddAction( pAct );
     968             :                 }
     969           0 :                 break;
     970             : 
     971             :                 case( META_BMPEX_ACTION ):
     972             :                 {
     973           0 :                     MetaBmpExAction*    pAct = (MetaBmpExAction*) pAction;
     974           0 :                     const BitmapEx      aBmpEx( Mask( pAct->GetBitmapEx() ).GetBitmapEx() );
     975             : 
     976           0 :                     pAct = new MetaBmpExAction( pAct->GetPoint(), aBmpEx );
     977           0 :                     aMtf.AddAction( pAct );
     978             :                 }
     979           0 :                 break;
     980             : 
     981             :                 case( META_BMPEXSCALE_ACTION ):
     982             :                 {
     983           0 :                     MetaBmpExScaleAction*   pAct = (MetaBmpExScaleAction*) pAction;
     984           0 :                     const BitmapEx          aBmpEx( Mask( pAct->GetBitmapEx() ).GetBitmapEx() );
     985             : 
     986           0 :                     pAct = new MetaBmpExScaleAction( pAct->GetPoint(), pAct->GetSize(), aBmpEx );
     987           0 :                     aMtf.AddAction( pAct );
     988             :                 }
     989           0 :                 break;
     990             : 
     991             :                 case( META_BMPEXSCALEPART_ACTION ):
     992             :                 {
     993           0 :                     MetaBmpExScalePartAction*   pAct = (MetaBmpExScalePartAction*) pAction;
     994           0 :                     const BitmapEx              aBmpEx( Mask( pAct->GetBitmapEx() ).GetBitmapEx() );
     995             : 
     996             :                     pAct = new MetaBmpExScalePartAction( pAct->GetDestPoint(), pAct->GetDestSize(),
     997           0 :                                                          pAct->GetSrcPoint(), pAct->GetSrcSize(), aBmpEx );
     998           0 :                     aMtf.AddAction( pAct );
     999             :                 }
    1000           0 :                 break;
    1001             : 
    1002             :                 default:
    1003             :                 {
    1004           0 :                     pAction->Duplicate();
    1005           0 :                     aMtf.AddAction( pAction );
    1006             :                 }
    1007           0 :                 break;
    1008             :             }
    1009             :         }
    1010             : 
    1011           0 :         delete[] pMinR;
    1012           0 :         delete[] pMaxR;
    1013           0 :         delete[] pMinG;
    1014           0 :         delete[] pMaxG;
    1015           0 :         delete[] pMinB;
    1016           0 :         delete[] pMaxB;
    1017             :     }
    1018             : 
    1019           0 :     LeaveWait();
    1020             : 
    1021           0 :     return aMtf;
    1022             : }
    1023             : 
    1024             : 
    1025             : 
    1026           0 : BitmapEx SvxBmpMask::ImpReplaceTransparency( const BitmapEx& rBmpEx, const Color& rColor )
    1027             : {
    1028           0 :     if( rBmpEx.IsTransparent() )
    1029             :     {
    1030           0 :         Bitmap aBmp( rBmpEx.GetBitmap() );
    1031           0 :         aBmp.Replace( rBmpEx.GetMask(), rColor );
    1032           0 :         return aBmp;
    1033             :     }
    1034             :     else
    1035           0 :         return rBmpEx;
    1036             : }
    1037             : 
    1038             : 
    1039             : 
    1040           0 : Animation SvxBmpMask::ImpReplaceTransparency( const Animation& rAnim, const Color& rColor )
    1041             : {
    1042           0 :     Animation   aAnimation( rAnim );
    1043           0 :     sal_uInt16      nAnimationCount = aAnimation.Count();
    1044             : 
    1045           0 :     for( sal_uInt16 i = 0; i < nAnimationCount; i++ )
    1046             :     {
    1047           0 :         AnimationBitmap aAnimBmp( aAnimation.Get( i ) );
    1048           0 :         aAnimBmp.aBmpEx = ImpReplaceTransparency( aAnimBmp.aBmpEx, rColor );
    1049           0 :         aAnimation.Replace( aAnimBmp, i );
    1050           0 :     }
    1051             : 
    1052           0 :     return aAnimation;
    1053             : }
    1054             : 
    1055             : 
    1056             : 
    1057           0 : GDIMetaFile SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile& rMtf, const Color& rColor )
    1058             : {
    1059           0 :     VirtualDevice   aVDev;
    1060           0 :     GDIMetaFile     aMtf;
    1061           0 :     const MapMode&  rPrefMap = rMtf.GetPrefMapMode();
    1062           0 :     const Size&     rPrefSize = rMtf.GetPrefSize();
    1063           0 :     const size_t    nActionCount = rMtf.GetActionSize();
    1064             : 
    1065           0 :     aVDev.EnableOutput( false );
    1066           0 :     aMtf.Record( &aVDev );
    1067           0 :     aMtf.SetPrefSize( rPrefSize );
    1068           0 :     aMtf.SetPrefMapMode( rPrefMap );
    1069           0 :     aVDev.SetLineColor( rColor );
    1070           0 :     aVDev.SetFillColor( rColor );
    1071             : 
    1072             :     // retrieve one action at the time; first
    1073             :     // set the whole area to the replacement color.
    1074           0 :     aVDev.DrawRect( Rectangle( rPrefMap.GetOrigin(), rPrefSize ) );
    1075           0 :     for ( size_t i = 0; i < nActionCount; i++ )
    1076             :     {
    1077           0 :         MetaAction* pAct = rMtf.GetAction( i );
    1078             : 
    1079           0 :         pAct->Duplicate();
    1080           0 :         aMtf.AddAction( pAct );
    1081             :     }
    1082             : 
    1083           0 :     aMtf.Stop();
    1084           0 :     aMtf.WindStart();
    1085             : 
    1086           0 :     return aMtf;
    1087             : }
    1088             : 
    1089             : 
    1090             : 
    1091           0 : Graphic SvxBmpMask::Mask( const Graphic& rGraphic )
    1092             : {
    1093           0 :     Graphic     aGraphic( rGraphic );
    1094           0 :     const Color aReplColor( aLbColorTrans.GetSelectEntryColor() );
    1095             : 
    1096           0 :     switch( rGraphic.GetType() )
    1097             :     {
    1098             :         case( GRAPHIC_BITMAP ):
    1099             :         {
    1100           0 :             if( rGraphic.IsAnimated() )
    1101             :             {
    1102             :                 // Replace transparency?
    1103           0 :                 if ( aCbxTrans.IsChecked() )
    1104           0 :                     aGraphic = ImpReplaceTransparency( rGraphic.GetAnimation(), aReplColor );
    1105             :                 else
    1106           0 :                     aGraphic = ImpMask( rGraphic.GetAnimation() );
    1107             :             }
    1108             :             else
    1109             :             {
    1110             :                 // Replace transparency?
    1111           0 :                 if( aCbxTrans.IsChecked() )
    1112             :                 {
    1113           0 :                     if( aGraphic.IsTransparent() )
    1114             :                     {
    1115           0 :                         BitmapEx    aBmpEx( ImpReplaceTransparency( aGraphic.GetBitmapEx(), aReplColor ) );
    1116           0 :                         const Size  aSize( aBmpEx.GetSizePixel() );
    1117             : 
    1118           0 :                         if( aSize.Width() && aSize.Height() )
    1119           0 :                             aGraphic = aBmpEx;
    1120             :                     }
    1121             :                 }
    1122             :                 else
    1123             :                 {
    1124           0 :                     Color   pSrcCols[4];
    1125           0 :                     Color   pDstCols[4];
    1126             :                     sal_uIntPtr pTols[4];
    1127           0 :                     sal_uInt16  nCount = InitColorArrays( pSrcCols, pDstCols, pTols );
    1128             : 
    1129           0 :                     if( nCount )
    1130             :                     {
    1131             :                         // first set all transparent colors
    1132           0 :                         for( sal_uInt16 i = 0; i < nCount; i++ )
    1133             :                         {
    1134             :                             // Do we have a transparent color?
    1135           0 :                             if( pDstCols[i] == TRANSP_COL )
    1136             :                             {
    1137             :                                 BitmapEx    aBmpEx( ImpMaskTransparent( aGraphic.GetBitmapEx(),
    1138           0 :                                                                         pSrcCols[ i ], pTols[ i ] ) );
    1139           0 :                                 const Size  aSize( aBmpEx.GetSizePixel() );
    1140             : 
    1141           0 :                                 if( aSize.Width() && aSize.Height() )
    1142           0 :                                     aGraphic = aBmpEx;
    1143             :                             }
    1144             :                         }
    1145             : 
    1146             :                         // now replace it again with the normal colors
    1147           0 :                         Bitmap  aBitmap( ImpMask( aGraphic.GetBitmap() ) );
    1148           0 :                         Size    aSize( aBitmap.GetSizePixel() );
    1149             : 
    1150           0 :                         if ( aSize.Width() && aSize.Height() )
    1151             :                         {
    1152           0 :                             if ( aGraphic.IsTransparent() )
    1153           0 :                                 aGraphic = Graphic( BitmapEx( aBitmap, aGraphic.GetBitmapEx().GetMask() ) );
    1154             :                             else
    1155           0 :                                 aGraphic = aBitmap;
    1156           0 :                         }
    1157             :                     }
    1158             :                 }
    1159             :             }
    1160             :         }
    1161           0 :         break;
    1162             : 
    1163             :         case( GRAPHIC_GDIMETAFILE ):
    1164             :         {
    1165           0 :             GDIMetaFile aMtf( aGraphic.GetGDIMetaFile() );
    1166             : 
    1167             :             // Replace transparency?
    1168           0 :             if( aCbxTrans.IsChecked() )
    1169           0 :                 aMtf = ImpReplaceTransparency( aMtf, aReplColor );
    1170             :             else
    1171           0 :                 aMtf = ImpMask( aMtf );
    1172             : 
    1173           0 :             Size aSize( aMtf.GetPrefSize() );
    1174           0 :             if ( aSize.Width() && aSize.Height() )
    1175           0 :                 aGraphic = Graphic( aMtf );
    1176             :             else
    1177           0 :                 aGraphic = rGraphic;
    1178             :         }
    1179           0 :         break;
    1180             : 
    1181             :         default:
    1182           0 :             aGraphic = rGraphic;
    1183           0 :         break;
    1184             :     }
    1185             : 
    1186           0 :     if( aGraphic != rGraphic )
    1187             :     {
    1188           0 :         aGraphic.SetPrefSize( rGraphic.GetPrefSize() );
    1189           0 :         aGraphic.SetPrefMapMode( rGraphic.GetPrefMapMode() );
    1190             :     }
    1191             : 
    1192           0 :     return aGraphic;
    1193             : }
    1194             : 
    1195             : 
    1196             : 
    1197           0 : bool SvxBmpMask::IsEyedropping() const
    1198             : {
    1199           0 :     return aTbxPipette.IsItemChecked( TBI_PIPETTE );
    1200             : }
    1201             : 
    1202           0 : void SvxBmpMask::DataChanged( const DataChangedEvent& rDCEvt )
    1203             : {
    1204           0 :     SfxDockingWindow::DataChanged( rDCEvt );
    1205             : 
    1206           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
    1207           0 :             ApplyStyle();
    1208           0 : }
    1209             : 
    1210           0 : void SvxBmpMask::ApplyStyle()
    1211             : {
    1212           0 :     aTbxPipette.SetItemImage( TBI_PIPETTE, maImgPipette );
    1213           0 : }
    1214             : 
    1215             : 
    1216             : /** Set an accessible name for the source color check boxes.  Without this
    1217             :     the lengthy description is read.
    1218             : */
    1219           0 : void SvxBmpMask::SetAccessibleNames (void)
    1220             : {
    1221           0 :     OUString sSourceColor(BMP_RESID(RID_SVXDLG_BMPMASK_STR_SOURCECOLOR).toString());
    1222           0 :     OUString sSourceColorN;
    1223             : 
    1224           0 :     sSourceColorN = sSourceColor;
    1225           0 :     sSourceColorN += " 1";
    1226           0 :     aCbx1.SetAccessibleName (sSourceColorN);
    1227             : 
    1228           0 :     sSourceColorN = sSourceColor;
    1229           0 :     sSourceColorN += " 2";
    1230           0 :     aCbx2.SetAccessibleName (sSourceColorN);
    1231             : 
    1232           0 :     sSourceColorN = sSourceColor;
    1233           0 :     sSourceColorN += " 3";
    1234           0 :     aCbx3.SetAccessibleName (sSourceColorN);
    1235             : 
    1236           0 :     sSourceColorN = sSourceColor;
    1237           0 :     sSourceColorN += " 4";
    1238           0 :     aCbx4.SetAccessibleName (sSourceColorN);
    1239             :     // set the accessible name for valueset
    1240           0 :     OUString sColorPalette (BMP_RESID( RID_SVXDLG_BMPMASK_STR_PALETTE));
    1241           0 :     OUString sColorPaletteN;
    1242           0 :     sColorPaletteN = sColorPalette;
    1243           0 :     sColorPaletteN += " 1";
    1244           0 :     pQSet1->SetText (sColorPaletteN);
    1245           0 :     sColorPaletteN = sColorPalette;
    1246           0 :     sColorPaletteN += " 2";
    1247           0 :     pQSet2->SetText (sColorPaletteN);
    1248           0 :     sColorPaletteN = sColorPalette;
    1249           0 :     sColorPaletteN += " 3";
    1250           0 :     pQSet3->SetText (sColorPaletteN);
    1251           0 :     sColorPaletteN = sColorPalette;
    1252           0 :     sColorPaletteN += " 4";
    1253           0 :     pQSet4->SetText (sColorPaletteN);
    1254             :     // set the accessible for replace with spin boxes.
    1255           0 :     OUString sTolerance(BMP_RESID( RID_SVXDLG_BMPMASK_STR_TOLERANCE));
    1256           0 :     OUString sToleranceN;
    1257           0 :     sToleranceN = sTolerance;
    1258           0 :     sToleranceN += " 1";
    1259           0 :     aSp1.SetAccessibleName (sToleranceN);
    1260           0 :     sToleranceN = sTolerance;
    1261           0 :     sToleranceN += " 2";
    1262           0 :     aSp2.SetAccessibleName (sToleranceN);
    1263           0 :     sToleranceN = sTolerance;
    1264           0 :     sToleranceN += " 3";
    1265           0 :     aSp3.SetAccessibleName (sToleranceN);
    1266           0 :     sToleranceN = sTolerance;
    1267           0 :     sToleranceN += " 4";
    1268           0 :     aSp4.SetAccessibleName (sToleranceN);
    1269             :     // set the accessible for replace with combo boxes.
    1270           0 :     OUString sReplaceWith(BMP_RESID( RID_SVXDLG_BMPMASK_STR_REPLACEWITH));
    1271           0 :     OUString sReplaceWithN;
    1272           0 :     sReplaceWithN = sReplaceWith;
    1273           0 :     sReplaceWithN += " 1";
    1274           0 :     aLbColor1.SetAccessibleName (sReplaceWithN);
    1275           0 :     sReplaceWithN = sReplaceWith;
    1276           0 :     sReplaceWithN += " 2";
    1277           0 :     aLbColor2.SetAccessibleName (sReplaceWithN);
    1278           0 :     sReplaceWithN = sReplaceWith;
    1279           0 :     sReplaceWithN += " 3";
    1280           0 :     aLbColor3.SetAccessibleName (sReplaceWithN);
    1281           0 :     sReplaceWithN = sReplaceWith;
    1282           0 :     sReplaceWithN += " 4";
    1283           0 :     aLbColor4.SetAccessibleName (sReplaceWithN);
    1284         255 : }
    1285             : 
    1286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10