1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _bmpmask.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <vcl/wrkwin.hxx>
34 #include <tools/shl.hxx>
35 #include <vcl/metaact.hxx>
36 #include <svtools/valueset.hxx>
37 #include <svtools/eitem.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <svtools/colrdlg.hxx>
41 #define BMPMASK_PRIVATE
43 #include <svx/dialmgr.hxx>
44 #include <svx/bmpmask.hxx>
45 #include <svx/dialogs.hrc>
46 #include <bmpmask.hrc>
47 #include <svx/svxids.hrc>
49 //-------------------------------------------------------------------------
51 #define BMP_RESID(nId) ResId(nId, DIALOG_MGR())
52 #define TRANSP_STRING "Transparent"
53 #define TRANSP_COL (Color( 252, 252, 252 ))
54 #define OWN_CALLMODE SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD
56 //-------------------------------------------------------------------------
60 nR = aCol.GetRed(); nG = aCol.GetGreen(); nB = aCol.GetBlue(); \
61 for( i = 0; i < nCount; i++ ) \
63 if ( ( pMinR[i] <= nR ) && ( pMaxR[i] >= nR ) && \
64 ( pMinG[i] <= nG ) && ( pMaxG[i] >= nG ) && \
65 ( pMinB[i] <= nB ) && ( pMaxB[i] >= nB ) ) \
67 aCol = pDstCols[i]; bReplace = TRUE; break; \
72 // -------------------------------------------------------------------------
74 SFX_IMPL_DOCKINGWINDOW( SvxBmpMaskChildWindow
, SID_BMPMASK
)
76 // -------------------------------------------------------------------------
78 class ColorWindow
: public Control
85 ColorWindow( Window
* pParent
, WinBits nWinStyle
) :
86 Control( pParent
, nWinStyle
),
87 aColor( COL_WHITE
) {};
89 ColorWindow( Window
* pParent
, const ResId
& rId
) :
90 Control( pParent
, rId
),
91 aColor( COL_WHITE
) {};
93 void SetColor( const Color
& rColor
)
99 virtual void Paint( const Rectangle
& rRect
);
102 //-------------------------------------------------------------------------
104 class MaskSet
: public ValueSet
106 SvxBmpMask
* pSvxBmpMask
;
110 MaskSet( SvxBmpMask
* pParent
, WinBits nWinStyle
);
111 MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
);
113 virtual void Select();
114 virtual void KeyInput( const KeyEvent
& rKEvt
);
115 virtual void GetFocus();
120 //-------------------------------------------------------------------------
122 MaskSet::MaskSet( SvxBmpMask
* pParent
, WinBits nWinStyle
) :
123 ValueSet ( pParent
, nWinStyle
),
124 pSvxBmpMask ( pParent
)
128 //-------------------------------------------------------------------------
130 MaskSet::MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
) :
131 ValueSet ( pParent
, rId
),
132 pSvxBmpMask ( pParent
)
136 //-------------------------------------------------------------------------
138 void MaskSet::Select()
142 pSvxBmpMask
->onSelect( this );
145 void MaskSet::GetFocus()
148 pSvxBmpMask
->onSelect( this );
151 void MaskSet::KeyInput( const KeyEvent
& rKEvt
)
153 KeyCode aCode
= rKEvt
.GetKeyCode();
155 // if the key has a modifier we don't care
156 if( aCode
.GetModifier() )
158 ValueSet::KeyInput( rKEvt
);
162 // check for keys that interests us
163 switch ( aCode
.GetCode() )
169 ValueSet::KeyInput( rKEvt
);
175 void MaskSet::onEditColor()
177 SvColorDialog
* pColorDlg
= new SvColorDialog( GetParent() );
179 pColorDlg
->SetColor(GetItemColor(1));
181 if( pColorDlg
->Execute() )
182 SetItemColor( 1, pColorDlg
->GetColor() );
187 //-------------------------------------------------------------------------
194 SfxBindings
& rBindings
;
197 MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
);
199 BOOL
IsCbxReady() const { return bIsReady
; }
200 void SetExecState( BOOL bState
) { bExecState
= bState
; }
201 BOOL
IsExecReady() const { return bExecState
; }
203 DECL_LINK( PipetteHdl
, ToolBox
* pTbx
);
204 DECL_LINK( CbxHdl
, CheckBox
* pCbx
);
205 DECL_LINK( CbxTransHdl
, CheckBox
* pCbx
);
206 DECL_LINK( FocusLbHdl
, ColorLB
* pLb
);
207 DECL_LINK( ExecHdl
, PushButton
* pBtn
);
210 //-------------------------------------------------------------------------
212 MaskData::MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
) :
216 bExecState ( FALSE
),
222 //-------------------------------------------------------------------------
224 IMPL_LINK( MaskData
, PipetteHdl
, ToolBox
*, pTbx
)
226 SfxBoolItem
aBItem( SID_BMPMASK_PIPETTE
,
227 pTbx
->IsItemChecked( TBI_PIPETTE
) );
229 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aBItem
, 0L );
234 //-------------------------------------------------------------------------
236 IMPL_LINK( MaskData
, CbxHdl
, CheckBox
*, pCbx
)
238 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
239 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
241 if ( bIsReady
&& IsExecReady() )
242 pMask
->aBtnExec
.Enable();
244 pMask
->aBtnExec
.Disable();
246 // Wenn eine Checkbox gecheckt wurde, wird die Pipette enabled
247 if ( pCbx
->IsChecked() )
249 MaskSet
* pSet
= NULL
;
251 if ( pCbx
== &( pMask
->aCbx1
) )
252 pSet
= pMask
->pQSet1
;
253 else if ( pCbx
== &( pMask
->aCbx2
) )
254 pSet
= pMask
->pQSet2
;
255 else if ( pCbx
== &( pMask
->aCbx3
) )
256 pSet
= pMask
->pQSet3
;
257 else // if ( pCbx == &( pMask->aCbx4 ) )
258 pSet
= pMask
->pQSet4
;
260 pSet
->SelectItem( 1 );
263 pMask
->aTbxPipette
.CheckItem( TBI_PIPETTE
, TRUE
);
264 PipetteHdl( &( pMask
->aTbxPipette
) );
270 //-------------------------------------------------------------------------
272 IMPL_LINK( MaskData
, CbxTransHdl
, CheckBox
*, pCbx
)
274 bIsReady
= pCbx
->IsChecked();
277 pMask
->pQSet1
->Disable();
278 pMask
->pQSet2
->Disable();
279 pMask
->pQSet3
->Disable();
280 pMask
->pQSet4
->Disable();
281 pMask
->pCtlPipette
->Disable();
282 pMask
->aCbx1
.Disable();
283 pMask
->aSp1
.Disable();
284 pMask
->aCbx2
.Disable();
285 pMask
->aSp2
.Disable();
286 pMask
->aCbx3
.Disable();
287 pMask
->aSp3
.Disable();
288 pMask
->aCbx4
.Disable();
289 pMask
->aSp4
.Disable();
290 pMask
->aTbxPipette
.Disable();
292 pMask
->aLbColor1
.Disable();
293 pMask
->aLbColor2
.Disable();
294 pMask
->aLbColor3
.Disable();
295 pMask
->aLbColor4
.Disable();
296 pMask
->aLbColorTrans
.Enable();
300 pMask
->pQSet1
->Enable();
301 pMask
->pQSet2
->Enable();
302 pMask
->pQSet3
->Enable();
303 pMask
->pQSet4
->Enable();
304 pMask
->pCtlPipette
->Enable();
305 pMask
->aCbx1
.Enable();
306 pMask
->aSp1
.Enable();
307 pMask
->aCbx2
.Enable();
308 pMask
->aSp2
.Enable();
309 pMask
->aCbx3
.Enable();
310 pMask
->aSp3
.Enable();
311 pMask
->aCbx4
.Enable();
312 pMask
->aSp4
.Enable();
313 pMask
->aTbxPipette
.Enable();
315 pMask
->aLbColor1
.Enable();
316 pMask
->aLbColor2
.Enable();
317 pMask
->aLbColor3
.Enable();
318 pMask
->aLbColor4
.Enable();
319 pMask
->aLbColorTrans
.Disable();
321 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
322 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
325 if ( bIsReady
&& IsExecReady() )
326 pMask
->aBtnExec
.Enable();
328 pMask
->aBtnExec
.Disable();
333 //-------------------------------------------------------------------------
335 IMPL_LINK( MaskData
, FocusLbHdl
, ColorLB
*, pLb
)
337 pMask
->pQSet1
->SelectItem( pLb
== &( pMask
->aLbColor1
) ? 1 : 0 );
338 pMask
->pQSet2
->SelectItem( pLb
== &( pMask
->aLbColor2
) ? 1 : 0 );
339 pMask
->pQSet3
->SelectItem( pLb
== &( pMask
->aLbColor3
) ? 1 : 0 );
340 pMask
->pQSet4
->SelectItem( pLb
== &( pMask
->aLbColor4
) ? 1 : 0 );
345 //-------------------------------------------------------------------------
347 IMPL_LINK( MaskData
, ExecHdl
, PushButton
*, EMPTYARG
)
349 SfxBoolItem
aBItem( SID_BMPMASK_EXEC
, TRUE
);
350 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_EXEC
, OWN_CALLMODE
, &aBItem
, 0L );
355 //-------------------------------------------------------------------------
357 void ColorWindow::Paint( const Rectangle
&/*Rect*/ )
359 const Color
& rOldLineColor
= GetLineColor();
360 const Color
& rOldFillColor
= GetFillColor();
362 SetLineColor( aColor
);
363 SetFillColor( aColor
);
365 DrawRect( Rectangle( Point(), GetSizePixel() ) );
367 SetLineColor( rOldLineColor
);
368 SetFillColor( rOldFillColor
);
371 //-------------------------------------------------------------------------
373 SvxBmpMaskSelectItem::SvxBmpMaskSelectItem( USHORT nId_
, SvxBmpMask
& rMask
,
374 SfxBindings
& rBindings
) :
375 SfxControllerItem ( nId_
, rBindings
),
380 //-------------------------------------------------------------------------
382 void SvxBmpMaskSelectItem::StateChanged( USHORT nSID
, SfxItemState
/*eState*/,
383 const SfxPoolItem
* pItem
)
385 if ( ( nSID
== SID_BMPMASK_EXEC
) && pItem
)
387 const SfxBoolItem
* pStateItem
= PTR_CAST( SfxBoolItem
, pItem
);
389 DBG_ASSERT( pStateItem
|| pItem
== 0, "SfxBoolItem erwartet");
391 rBmpMask
.SetExecState( pStateItem
->GetValue() );
395 //-------------------------------------------------------------------------
397 SvxBmpMaskChildWindow::SvxBmpMaskChildWindow( Window
* pParent_
, USHORT nId
,
398 SfxBindings
* pBindings
,
399 SfxChildWinInfo
* pInfo
) :
400 SfxChildWindow( pParent_
, nId
)
402 pWindow
= new SvxBmpMask( pBindings
, this, pParent_
,
403 BMP_RESID( RID_SVXDLG_BMPMASK
) );
404 SvxBmpMask
* pDlg
= (SvxBmpMask
*) pWindow
;
406 eChildAlignment
= SFX_ALIGN_NOALIGNMENT
;
408 pDlg
->Initialize( pInfo
);
411 //-------------------------------------------------------------------------
413 SvxBmpMask::SvxBmpMask( SfxBindings
*pBindinx
,
416 const ResId
& rResId
) :
417 SfxDockingWindow ( pBindinx
, pCW
, pParent
, rResId
),
418 aTbxPipette ( this, BMP_RESID( TBX_PIPETTE
) ),
419 pCtlPipette ( new ColorWindow( this, BMP_RESID( WND_PIPETTE
) ) ),
420 aBtnExec ( this, BMP_RESID( BTN_EXEC
) ),
421 aGrpQ ( this, BMP_RESID( GRP_Q
) ),
423 aCbx1 ( this, BMP_RESID( CBX_1
) ),
424 pQSet1 ( new MaskSet( this, BMP_RESID( QCOL_1
) ) ),
425 aSp1 ( this, BMP_RESID( SP_1
) ),
426 aLbColor1 ( this, BMP_RESID ( LB_1
) ),
428 aCbx2 ( this, BMP_RESID( CBX_2
) ),
429 pQSet2 ( new MaskSet( this, BMP_RESID( QCOL_2
) ) ),
430 aSp2 ( this, BMP_RESID( SP_2
) ),
431 aLbColor2 ( this, BMP_RESID ( LB_2
) ),
433 aCbx3 ( this, BMP_RESID( CBX_3
) ),
434 pQSet3 ( new MaskSet( this, BMP_RESID( QCOL_3
) ) ),
435 aSp3 ( this, BMP_RESID( SP_3
) ),
436 aLbColor3 ( this, BMP_RESID ( LB_3
) ),
438 aCbx4 ( this, BMP_RESID( CBX_4
) ),
439 pQSet4 ( new MaskSet( this, BMP_RESID( QCOL_4
) ) ),
440 aSp4 ( this, BMP_RESID( SP_4
) ),
441 aLbColor4 ( this, BMP_RESID ( LB_4
) ),
443 pData ( new MaskData( this, *pBindinx
) ),
444 aCbxTrans ( this, BMP_RESID( CBX_TRANS
) ),
445 aLbColorTrans ( this, BMP_RESID ( LB_TRANS
) ),
446 aFt1 ( this, BMP_RESID ( FT_1
) ),
447 aFt2 ( this, BMP_RESID ( FT_2
) ),
448 aFt3 ( this, BMP_RESID ( FT_3
) ),
450 aPipetteColor ( COL_WHITE
),
451 aSelItem ( SID_BMPMASK_EXEC
, *this, *pBindinx
),
452 maImgPipette ( BMP_RESID ( IMG_PIPETTE
) ),
453 maImgPipetteH ( BMP_RESID ( IMG_PIPETTE_H
) )
459 aTbxPipette
.SetSizePixel( aTbxPipette
.CalcWindowSizePixel() );
460 aTbxPipette
.SetSelectHdl( LINK( pData
, MaskData
, PipetteHdl
) );
461 aBtnExec
.SetClickHdl( LINK( pData
, MaskData
, ExecHdl
) );
463 aCbx1
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
464 aCbx2
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
465 aCbx3
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
466 aCbx4
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
467 aCbxTrans
.SetClickHdl( LINK( pData
, MaskData
, CbxTransHdl
) );
469 SetAccessibleNames ();
471 aLbColor1
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
472 aLbColor2
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
473 aLbColor3
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
474 aLbColor4
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
475 aLbColorTrans
.Disable();
482 pQSet1
->SetStyle( pQSet1
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
483 pQSet1
->SetColCount( 1 );
484 pQSet1
->SetLineCount( 1 );
485 // pQSet1->SetExtraSpacing( 1 );
486 pQSet1
->InsertItem( 1, aPipetteColor
);
487 pQSet1
->SelectItem( 1 );
489 pQSet2
->SetStyle( pQSet2
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
490 pQSet2
->SetColCount( 1 );
491 pQSet2
->SetLineCount( 1 );
492 // pQSet2->SetExtraSpacing( 1 );
493 pQSet2
->InsertItem( 1, aPipetteColor
);
494 pQSet2
->SelectItem( 0 );
496 pQSet3
->SetStyle( pQSet3
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
497 pQSet3
->SetColCount( 1 );
498 pQSet3
->SetLineCount( 1 );
499 // pQSet3->SetExtraSpacing( 1 );
500 pQSet3
->InsertItem( 1, aPipetteColor
);
501 pQSet3
->SelectItem( 0 );
503 pQSet4
->SetStyle( pQSet4
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
504 pQSet4
->SetColCount( 1 );
505 pQSet4
->SetLineCount( 1 );
506 // pQSet4->SetExtraSpacing( 1 );
507 pQSet4
->InsertItem( 1, aPipetteColor
);
508 pQSet4
->SelectItem( 0 );
516 //-------------------------------------------------------------------------
518 SvxBmpMask::~SvxBmpMask()
528 //-------------------------------------------------------------------------
530 /** is called by a MaskSet when it is selected */
531 void SvxBmpMask::onSelect( MaskSet
* pSet
)
533 // automaticaly set focus to the corresponding listbox
536 aLbColor1.GrabFocus();
537 else if( pSet == pQSet2 )
538 aLbColor2.GrabFocus();
539 else if( pSet == pQSet2 )
540 aLbColor3.GrabFocus();
541 else if( pSet == pQSet2 )
542 aLbColor4.GrabFocus();
545 // now deselect all other value sets
547 pQSet1
->SelectItem( 0 );
550 pQSet2
->SelectItem( 0 );
553 pQSet3
->SelectItem( 0 );
556 pQSet4
->SelectItem( 0 );
559 //-------------------------------------------------------------------------
561 BOOL
SvxBmpMask::Close()
563 SfxBoolItem
aItem2( SID_BMPMASK_PIPETTE
, FALSE
);
564 GetBindings().GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aItem2
, 0L );
566 return SfxDockingWindow::Close();
569 //-------------------------------------------------------------------------
571 BOOL
SvxBmpMask::NeedsColorTable() const
573 return ( aLbColor1
.GetEntryCount() == 0 );
576 //-------------------------------------------------------------------------
578 void SvxBmpMask::SetColorTable( const XColorTable
* pTable
)
580 if ( pTable
&& ( pTable
!= pColTab
) )
582 const String
aTransp( BMP_RESID( RID_SVXDLG_BMPMASK_STR_TRANSP
) );
586 aLbColorTrans
.Fill( pColTab
);
587 aLbColorTrans
.SelectEntryPos( 0 );
589 aLbColor1
.Fill( pColTab
);
590 aLbColor1
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
591 aLbColor1
.SelectEntryPos( 0 );
593 aLbColor2
.Fill( pColTab
);
594 aLbColor2
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
595 aLbColor2
.SelectEntryPos( 0 );
597 aLbColor3
.Fill( pColTab
);
598 aLbColor3
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
599 aLbColor3
.SelectEntryPos( 0 );
601 aLbColor4
.Fill( pColTab
);
602 aLbColor4
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
603 aLbColor4
.SelectEntryPos( 0 );
607 //-------------------------------------------------------------------------
609 void SvxBmpMask::SetColor( const Color
& rColor
)
611 aPipetteColor
= rColor
;
612 pCtlPipette
->SetColor( aPipetteColor
);
615 //-------------------------------------------------------------------------
617 void SvxBmpMask::PipetteClicked()
619 if( pQSet1
->GetSelectItemId() == 1 )
622 pData
->CbxHdl( &aCbx1
);
623 pQSet1
->SetItemColor( 1, aPipetteColor
);
625 else if( pQSet2
->GetSelectItemId() == 1 )
628 pData
->CbxHdl( &aCbx2
);
629 pQSet2
->SetItemColor( 1, aPipetteColor
);
631 else if( pQSet3
->GetSelectItemId() == 1 )
634 pData
->CbxHdl( &aCbx3
);
635 pQSet3
->SetItemColor( 1, aPipetteColor
);
637 else if( pQSet4
->GetSelectItemId() == 1 )
640 pData
->CbxHdl( &aCbx4
);
641 pQSet4
->SetItemColor( 1, aPipetteColor
);
644 aTbxPipette
.CheckItem( TBI_PIPETTE
, FALSE
);
645 pData
->PipetteHdl( &aTbxPipette
);
648 //-------------------------------------------------------------------------
650 void SvxBmpMask::SetExecState( BOOL bEnable
)
652 pData
->SetExecState( bEnable
);
654 if ( pData
->IsExecReady() && pData
->IsCbxReady() )
660 //-------------------------------------------------------------------------
662 USHORT
SvxBmpMask::InitColorArrays( Color
* pSrcCols
, Color
* pDstCols
, ULONG
* pTols
)
666 if ( aCbx1
.IsChecked() )
668 pSrcCols
[nCount
] = pQSet1
->GetItemColor( 1 );
669 pDstCols
[nCount
] = aLbColor1
.GetSelectEntryColor();
670 pTols
[nCount
++] = static_cast<ULONG
>(aSp1
.GetValue());
673 if ( aCbx2
.IsChecked() )
675 pSrcCols
[nCount
] = pQSet2
->GetItemColor( 1 );
676 pDstCols
[nCount
] = aLbColor2
.GetSelectEntryColor();
677 pTols
[nCount
++] = static_cast<ULONG
>(aSp2
.GetValue());
680 if ( aCbx3
.IsChecked() )
682 pSrcCols
[nCount
] = pQSet3
->GetItemColor( 1 );
683 pDstCols
[nCount
] = aLbColor3
.GetSelectEntryColor();
684 pTols
[nCount
++] = static_cast<ULONG
>(aSp3
.GetValue());
687 if ( aCbx4
.IsChecked() )
689 pSrcCols
[nCount
] = pQSet4
->GetItemColor( 1 );
690 pDstCols
[nCount
] = aLbColor4
.GetSelectEntryColor();
691 pTols
[nCount
++] = static_cast<ULONG
>(aSp4
.GetValue());
697 //-------------------------------------------------------------------------
699 Bitmap
SvxBmpMask::ImpMask( const Bitmap
& rBitmap
)
701 Bitmap
aBitmap( rBitmap
);
705 const USHORT nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
708 aBitmap
.Replace( pSrcCols
, pDstCols
, nCount
, pTols
);
714 //-------------------------------------------------------------------------
716 BitmapEx
SvxBmpMask::ImpMask( const BitmapEx
& rBitmapEx
)
718 return BitmapEx( ImpMask( rBitmapEx
.GetBitmap() ), rBitmapEx
.GetMask() );
721 //-------------------------------------------------------------------------
723 BitmapEx
SvxBmpMask::ImpMaskTransparent( const BitmapEx
& rBitmapEx
, const Color
& rColor
, const long nTol
)
728 Bitmap
aMask( rBitmapEx
.GetBitmap().CreateMask( rColor
, nTol
) );
730 if( rBitmapEx
.IsTransparent() )
731 aMask
.CombineSimple( rBitmapEx
.GetMask(), BMP_COMBINE_OR
);
733 aBmpEx
= BitmapEx( rBitmapEx
.GetBitmap(), aMask
);
739 //-------------------------------------------------------------------------
741 Animation
SvxBmpMask::ImpMask( const Animation
& rAnimation
)
743 Animation
aAnimation( rAnimation
);
747 InitColorArrays( pSrcCols
, pDstCols
, pTols
);
748 USHORT nAnimationCount
= aAnimation
.Count();
750 for( USHORT i
= 0; i
< nAnimationCount
; i
++ )
752 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
753 aAnimBmp
.aBmpEx
= Mask( aAnimBmp
.aBmpEx
).GetBitmapEx();
754 aAnimation
.Replace( aAnimBmp
, i
);
760 //-------------------------------------------------------------------------
762 GDIMetaFile
SvxBmpMask::ImpMask( const GDIMetaFile
& rMtf
)
768 USHORT nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
771 // Falls keine Farben ausgewaehlt, kopieren wir nur das Mtf
782 long* pMinR
= new long[nCount
];
783 long* pMaxR
= new long[nCount
];
784 long* pMinG
= new long[nCount
];
785 long* pMaxG
= new long[nCount
];
786 long* pMinB
= new long[nCount
];
787 long* pMaxB
= new long[nCount
];
791 aMtf
.SetPrefSize( rMtf
.GetPrefSize() );
792 aMtf
.SetPrefMapMode( rMtf
.GetPrefMapMode() );
794 // Farbvergleichsarrays vorbereiten
795 for( i
= 0; i
< nCount
; i
++ )
797 nTol
= ( pTols
[i
] * 255L ) / 100L;
799 nVal
= ( (long) pSrcCols
[i
].GetRed() );
800 pMinR
[i
] = Max( nVal
- nTol
, 0L );
801 pMaxR
[i
] = Min( nVal
+ nTol
, 255L );
803 nVal
= ( (long) pSrcCols
[i
].GetGreen() );
804 pMinG
[i
] = Max( nVal
- nTol
, 0L );
805 pMaxG
[i
] = Min( nVal
+ nTol
, 255L );
807 nVal
= ( (long) pSrcCols
[i
].GetBlue() );
808 pMinB
[i
] = Max( nVal
- nTol
, 0L );
809 pMaxB
[i
] = Min( nVal
+ nTol
, 255L );
811 pTrans
[ i
] = ( pDstCols
[ i
] == TRANSP_COL
);
814 // Actions untersuchen und Farben ggf. ersetzen
815 for( ULONG nAct
= 0UL, nActCount
= rMtf
.GetActionCount(); nAct
< nActCount
; nAct
++ )
817 MetaAction
* pAction
= rMtf
.GetAction( nAct
);
821 switch( pAction
->GetType() )
823 case( META_PIXEL_ACTION
):
825 MetaPixelAction
* pAct
= (MetaPixelAction
*) pAction
;
827 aCol
= pAct
->GetColor();
831 pAct
= new MetaPixelAction( pAct
->GetPoint(), aCol
);
835 aMtf
.AddAction( pAct
);
839 case( META_LINECOLOR_ACTION
):
841 MetaLineColorAction
* pAct
= (MetaLineColorAction
*) pAction
;
843 aCol
= pAct
->GetColor();
847 pAct
= new MetaLineColorAction( aCol
, !pTrans
[ i
] );
851 aMtf
.AddAction( pAct
);
855 case( META_FILLCOLOR_ACTION
):
857 MetaFillColorAction
* pAct
= (MetaFillColorAction
*) pAction
;
859 aCol
= pAct
->GetColor();
863 pAct
= new MetaFillColorAction( aCol
, !pTrans
[ i
] );
867 aMtf
.AddAction( pAct
);
871 case( META_TEXTCOLOR_ACTION
):
873 MetaTextColorAction
* pAct
= (MetaTextColorAction
*) pAction
;
875 aCol
= pAct
->GetColor();
879 pAct
= new MetaTextColorAction( aCol
);
883 aMtf
.AddAction( pAct
);
887 case( META_TEXTFILLCOLOR_ACTION
):
889 MetaTextFillColorAction
* pAct
= (MetaTextFillColorAction
*) pAction
;
891 aCol
= pAct
->GetColor();
895 pAct
= new MetaTextFillColorAction( aCol
, !pTrans
[ i
] );
899 aMtf
.AddAction( pAct
);
903 case( META_FONT_ACTION
):
905 MetaFontAction
* pAct
= (MetaFontAction
*) pAction
;
906 Font
aFont( pAct
->GetFont() );
908 aCol
= aFont
.GetColor();
913 aFont
.SetColor( aCol
);
914 pAct
= new MetaFontAction( aFont
);
919 aMtf
.AddAction( pAct
);
923 case( META_WALLPAPER_ACTION
):
925 MetaWallpaperAction
* pAct
= (MetaWallpaperAction
*) pAction
;
926 Wallpaper
aWall( pAct
->GetWallpaper() );
928 aCol
= aWall
.GetColor();
933 aWall
.SetColor( aCol
);
934 pAct
= new MetaWallpaperAction( pAct
->GetRect(), aWall
);
939 aMtf
.AddAction( pAct
);
943 case( META_BMP_ACTION
):
945 MetaBmpAction
* pAct
= (MetaBmpAction
*) pAction
;
946 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
948 pAct
= new MetaBmpAction( pAct
->GetPoint(), aBmp
);
949 aMtf
.AddAction( pAct
);
953 case( META_BMPSCALE_ACTION
):
955 MetaBmpScaleAction
* pAct
= (MetaBmpScaleAction
*) pAction
;
956 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
958 pAct
= new MetaBmpScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmp
);
959 aMtf
.AddAction( pAct
);
963 case( META_BMPSCALEPART_ACTION
):
965 MetaBmpScalePartAction
* pAct
= (MetaBmpScalePartAction
*) pAction
;
966 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
968 pAct
= new MetaBmpScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
969 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmp
);
970 aMtf
.AddAction( pAct
);
974 case( META_BMPEX_ACTION
):
976 MetaBmpExAction
* pAct
= (MetaBmpExAction
*) pAction
;
977 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
979 pAct
= new MetaBmpExAction( pAct
->GetPoint(), aBmpEx
);
980 aMtf
.AddAction( pAct
);
984 case( META_BMPEXSCALE_ACTION
):
986 MetaBmpExScaleAction
* pAct
= (MetaBmpExScaleAction
*) pAction
;
987 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
989 pAct
= new MetaBmpExScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmpEx
);
990 aMtf
.AddAction( pAct
);
994 case( META_BMPEXSCALEPART_ACTION
):
996 MetaBmpExScalePartAction
* pAct
= (MetaBmpExScalePartAction
*) pAction
;
997 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
999 pAct
= new MetaBmpExScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
1000 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmpEx
);
1001 aMtf
.AddAction( pAct
);
1007 pAction
->Duplicate();
1008 aMtf
.AddAction( pAction
);
1027 //-------------------------------------------------------------------------
1029 BitmapEx
SvxBmpMask::ImpReplaceTransparency( const BitmapEx
& rBmpEx
, const Color
& rColor
)
1031 if( rBmpEx
.IsTransparent() )
1033 Bitmap
aBmp( rBmpEx
.GetBitmap() );
1034 aBmp
.Replace( rBmpEx
.GetMask(), rColor
);
1041 //-------------------------------------------------------------------------
1043 Animation
SvxBmpMask::ImpReplaceTransparency( const Animation
& rAnim
, const Color
& rColor
)
1045 Animation
aAnimation( rAnim
);
1046 USHORT nAnimationCount
= aAnimation
.Count();
1048 for( USHORT i
= 0; i
< nAnimationCount
; i
++ )
1050 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
1051 aAnimBmp
.aBmpEx
= ImpReplaceTransparency( aAnimBmp
.aBmpEx
, rColor
);
1052 aAnimation
.Replace( aAnimBmp
, i
);
1058 //-------------------------------------------------------------------------
1060 GDIMetaFile
SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile
& rMtf
, const Color
& rColor
)
1062 VirtualDevice aVDev
;
1064 const MapMode
& rPrefMap
= rMtf
.GetPrefMapMode();
1065 const Size
& rPrefSize
= rMtf
.GetPrefSize();
1066 const ULONG nActionCount
= rMtf
.GetActionCount();
1068 aVDev
.EnableOutput( FALSE
);
1069 aMtf
.Record( &aVDev
);
1070 aMtf
.SetPrefSize( rPrefSize
);
1071 aMtf
.SetPrefMapMode( rPrefMap
);
1072 aVDev
.SetLineColor( rColor
);
1073 aVDev
.SetFillColor( rColor
);
1075 // Actions nacheinander abspielen; zuerst
1076 // den gesamten Bereich auf die Ersatzfarbe setzen
1077 aVDev
.DrawRect( Rectangle( rPrefMap
.GetOrigin(), rPrefSize
) );
1078 for ( ULONG i
= 0; i
< nActionCount
; i
++ )
1080 MetaAction
* pAct
= rMtf
.GetAction( i
);
1083 aMtf
.AddAction( pAct
);
1092 //-------------------------------------------------------------------------
1094 Graphic
SvxBmpMask::Mask( const Graphic
& rGraphic
)
1096 Graphic
aGraphic( rGraphic
);
1097 const Color
aReplColor( aLbColorTrans
.GetSelectEntryColor() );
1099 switch( rGraphic
.GetType() )
1101 case( GRAPHIC_BITMAP
):
1103 if( rGraphic
.IsAnimated() )
1105 // Transparenz ersetzen?
1106 if ( aCbxTrans
.IsChecked() )
1107 aGraphic
= ImpReplaceTransparency( rGraphic
.GetAnimation(), aReplColor
);
1109 aGraphic
= ImpMask( rGraphic
.GetAnimation() );
1113 // Transparenz ersetzen?
1114 if( aCbxTrans
.IsChecked() )
1116 if( aGraphic
.IsTransparent() )
1118 BitmapEx
aBmpEx( ImpReplaceTransparency( aGraphic
.GetBitmapEx(), aReplColor
) );
1119 const Size
aSize( aBmpEx
.GetSizePixel() );
1121 if( aSize
.Width() && aSize
.Height() )
1130 USHORT nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
1134 // erstmal alle Transparent-Farben setzen
1135 for( USHORT i
= 0; i
< nCount
; i
++ )
1137 // Haben wir eine Transparenzfarbe?
1138 if( pDstCols
[i
] == TRANSP_COL
)
1140 BitmapEx
aBmpEx( ImpMaskTransparent( aGraphic
.GetBitmapEx(),
1141 pSrcCols
[ i
], pTols
[ i
] ) );
1142 const Size
aSize( aBmpEx
.GetSizePixel() );
1144 if( aSize
.Width() && aSize
.Height() )
1149 // jetzt noch einmal mit den normalen Farben ersetzen
1150 Bitmap
aBitmap( ImpMask( aGraphic
.GetBitmap() ) );
1151 Size
aSize( aBitmap
.GetSizePixel() );
1153 if ( aSize
.Width() && aSize
.Height() )
1155 if ( aGraphic
.IsTransparent() )
1156 aGraphic
= Graphic( BitmapEx( aBitmap
, aGraphic
.GetBitmapEx().GetMask() ) );
1166 case( GRAPHIC_GDIMETAFILE
):
1168 GDIMetaFile
aMtf( aGraphic
.GetGDIMetaFile() );
1170 // Transparenz ersetzen?
1171 if( aCbxTrans
.IsChecked() )
1172 aMtf
= ImpReplaceTransparency( aMtf
, aReplColor
);
1174 aMtf
= ImpMask( aMtf
);
1176 Size
aSize( aMtf
.GetPrefSize() );
1177 if ( aSize
.Width() && aSize
.Height() )
1178 aGraphic
= Graphic( aMtf
);
1180 aGraphic
= rGraphic
;
1185 aGraphic
= rGraphic
;
1189 if( aGraphic
!= rGraphic
)
1191 aGraphic
.SetPrefSize( rGraphic
.GetPrefSize() );
1192 aGraphic
.SetPrefMapMode( rGraphic
.GetPrefMapMode() );
1198 //-------------------------------------------------------------------------
1200 BOOL
SvxBmpMask::IsEyedropping() const
1202 return aTbxPipette
.IsItemChecked( TBI_PIPETTE
);
1205 void SvxBmpMask::DataChanged( const DataChangedEvent
& rDCEvt
)
1207 SfxDockingWindow::DataChanged( rDCEvt
);
1209 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
1213 void SvxBmpMask::ApplyStyle()
1215 bool bHighContrast
= GetDisplayBackground().GetColor().IsDark() != 0;
1217 aTbxPipette
.SetItemImage( TBI_PIPETTE
, bHighContrast
? maImgPipetteH
: maImgPipette
);
1221 /** Set an accessible name for the source color check boxes. Without this
1222 the lengthy description is read.
1224 void SvxBmpMask::SetAccessibleNames (void)
1226 String
sSourceColor (BMP_RESID( RID_SVXDLG_BMPMASK_STR_SOURCECOLOR
));
1227 String sSourceColorN
;
1229 sSourceColorN
= sSourceColor
;
1230 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 1"));
1231 aCbx1
.SetAccessibleName (sSourceColorN
);
1233 sSourceColorN
= sSourceColor
;
1234 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 2"));
1235 aCbx2
.SetAccessibleName (sSourceColorN
);
1237 sSourceColorN
= sSourceColor
;
1238 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 3"));
1239 aCbx3
.SetAccessibleName (sSourceColorN
);
1241 sSourceColorN
= sSourceColor
;
1242 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 4"));
1243 aCbx4
.SetAccessibleName (sSourceColorN
);