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

Generated by: LCOV version 1.10