1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <vcl/wrkwin.hxx>
30 #include <tools/shl.hxx>
31 #include <vcl/metaact.hxx>
32 #include <svtools/valueset.hxx>
33 #include <svl/eitem.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <svtools/colrdlg.hxx>
37 #define BMPMASK_PRIVATE
39 #include <svx/dialmgr.hxx>
40 #include <svx/bmpmask.hxx>
41 #include <svx/dialogs.hrc>
42 #include <bmpmask.hrc>
43 #include <svx/svxids.hrc>
45 //-------------------------------------------------------------------------
47 #define BMP_RESID(nId) ResId(nId, DIALOG_MGR())
48 #define TRANSP_COL (Color( 252, 252, 252 ))
49 #define OWN_CALLMODE SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD
51 //-------------------------------------------------------------------------
55 nR = aCol.GetRed(); nG = aCol.GetGreen(); nB = aCol.GetBlue(); \
56 for( i = 0; i < nCount; i++ ) \
58 if ( ( pMinR[i] <= nR ) && ( pMaxR[i] >= nR ) && \
59 ( pMinG[i] <= nG ) && ( pMaxG[i] >= nG ) && \
60 ( pMinB[i] <= nB ) && ( pMaxB[i] >= nB ) ) \
62 aCol = pDstCols[i]; bReplace = sal_True; break; \
67 // -------------------------------------------------------------------------
69 SFX_IMPL_DOCKINGWINDOW( SvxBmpMaskChildWindow
, SID_BMPMASK
)
71 // -------------------------------------------------------------------------
73 class ColorWindow
: public Control
80 ColorWindow( Window
* pParent
, WinBits nWinStyle
) :
81 Control( pParent
, nWinStyle
),
82 aColor( COL_WHITE
) {};
84 ColorWindow( Window
* pParent
, const ResId
& rId
) :
85 Control( pParent
, rId
),
86 aColor( COL_WHITE
) {};
88 void SetColor( const Color
& rColor
)
94 virtual void Paint( const Rectangle
& rRect
);
97 //-------------------------------------------------------------------------
99 class MaskSet
: public ValueSet
101 SvxBmpMask
* pSvxBmpMask
;
105 MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
);
107 virtual void Select();
108 virtual void KeyInput( const KeyEvent
& rKEvt
);
109 virtual void GetFocus();
114 //-------------------------------------------------------------------------
116 MaskSet::MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
) :
117 ValueSet ( pParent
, rId
),
118 pSvxBmpMask ( pParent
)
122 //-------------------------------------------------------------------------
124 void MaskSet::Select()
128 pSvxBmpMask
->onSelect( this );
131 void MaskSet::GetFocus()
134 pSvxBmpMask
->onSelect( this );
137 void MaskSet::KeyInput( const KeyEvent
& rKEvt
)
139 KeyCode aCode
= rKEvt
.GetKeyCode();
141 // if the key has a modifier we don't care
142 if( aCode
.GetModifier() )
144 ValueSet::KeyInput( rKEvt
);
148 // check for keys that interests us
149 switch ( aCode
.GetCode() )
155 ValueSet::KeyInput( rKEvt
);
161 void MaskSet::onEditColor()
163 SvColorDialog
* pColorDlg
= new SvColorDialog( GetParent() );
165 pColorDlg
->SetColor(GetItemColor(1));
167 if( pColorDlg
->Execute() )
168 SetItemColor( 1, pColorDlg
->GetColor() );
173 //-------------------------------------------------------------------------
180 SfxBindings
& rBindings
;
183 MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
);
185 sal_Bool
IsCbxReady() const { return bIsReady
; }
186 void SetExecState( sal_Bool bState
) { bExecState
= bState
; }
187 sal_Bool
IsExecReady() const { return bExecState
; }
189 DECL_LINK( PipetteHdl
, ToolBox
* pTbx
);
190 DECL_LINK( CbxHdl
, CheckBox
* pCbx
);
191 DECL_LINK( CbxTransHdl
, CheckBox
* pCbx
);
192 DECL_LINK( FocusLbHdl
, ColorLB
* pLb
);
193 DECL_LINK(ExecHdl
, void *);
196 //-------------------------------------------------------------------------
198 MaskData::MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
) :
201 bIsReady ( sal_False
),
202 bExecState ( sal_False
),
208 //-------------------------------------------------------------------------
210 IMPL_LINK( MaskData
, PipetteHdl
, ToolBox
*, pTbx
)
212 SfxBoolItem
aBItem( SID_BMPMASK_PIPETTE
,
213 pTbx
->IsItemChecked( TBI_PIPETTE
) );
215 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aBItem
, 0L );
220 //-------------------------------------------------------------------------
222 IMPL_LINK( MaskData
, CbxHdl
, CheckBox
*, pCbx
)
224 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
225 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
227 if ( bIsReady
&& IsExecReady() )
228 pMask
->aBtnExec
.Enable();
230 pMask
->aBtnExec
.Disable();
232 // When a checkbox is checked, the pipette is enabled
233 if ( pCbx
->IsChecked() )
235 MaskSet
* pSet
= NULL
;
237 if ( pCbx
== &( pMask
->aCbx1
) )
238 pSet
= pMask
->pQSet1
;
239 else if ( pCbx
== &( pMask
->aCbx2
) )
240 pSet
= pMask
->pQSet2
;
241 else if ( pCbx
== &( pMask
->aCbx3
) )
242 pSet
= pMask
->pQSet3
;
243 else // if ( pCbx == &( pMask->aCbx4 ) )
244 pSet
= pMask
->pQSet4
;
246 pSet
->SelectItem( 1 );
249 pMask
->aTbxPipette
.CheckItem( TBI_PIPETTE
, sal_True
);
250 PipetteHdl( &( pMask
->aTbxPipette
) );
256 //-------------------------------------------------------------------------
258 IMPL_LINK( MaskData
, CbxTransHdl
, CheckBox
*, pCbx
)
260 bIsReady
= pCbx
->IsChecked();
263 pMask
->pQSet1
->Disable();
264 pMask
->pQSet2
->Disable();
265 pMask
->pQSet3
->Disable();
266 pMask
->pQSet4
->Disable();
267 pMask
->pCtlPipette
->Disable();
268 pMask
->aCbx1
.Disable();
269 pMask
->aSp1
.Disable();
270 pMask
->aCbx2
.Disable();
271 pMask
->aSp2
.Disable();
272 pMask
->aCbx3
.Disable();
273 pMask
->aSp3
.Disable();
274 pMask
->aCbx4
.Disable();
275 pMask
->aSp4
.Disable();
276 pMask
->aTbxPipette
.Disable();
278 pMask
->aLbColor1
.Disable();
279 pMask
->aLbColor2
.Disable();
280 pMask
->aLbColor3
.Disable();
281 pMask
->aLbColor4
.Disable();
282 pMask
->aLbColorTrans
.Enable();
286 pMask
->pQSet1
->Enable();
287 pMask
->pQSet2
->Enable();
288 pMask
->pQSet3
->Enable();
289 pMask
->pQSet4
->Enable();
290 pMask
->pCtlPipette
->Enable();
291 pMask
->aCbx1
.Enable();
292 pMask
->aSp1
.Enable();
293 pMask
->aCbx2
.Enable();
294 pMask
->aSp2
.Enable();
295 pMask
->aCbx3
.Enable();
296 pMask
->aSp3
.Enable();
297 pMask
->aCbx4
.Enable();
298 pMask
->aSp4
.Enable();
299 pMask
->aTbxPipette
.Enable();
301 pMask
->aLbColor1
.Enable();
302 pMask
->aLbColor2
.Enable();
303 pMask
->aLbColor3
.Enable();
304 pMask
->aLbColor4
.Enable();
305 pMask
->aLbColorTrans
.Disable();
307 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
308 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
311 if ( bIsReady
&& IsExecReady() )
312 pMask
->aBtnExec
.Enable();
314 pMask
->aBtnExec
.Disable();
319 //-------------------------------------------------------------------------
321 IMPL_LINK( MaskData
, FocusLbHdl
, ColorLB
*, pLb
)
323 pMask
->pQSet1
->SelectItem( pLb
== &( pMask
->aLbColor1
) ? 1 : 0 );
324 pMask
->pQSet2
->SelectItem( pLb
== &( pMask
->aLbColor2
) ? 1 : 0 );
325 pMask
->pQSet3
->SelectItem( pLb
== &( pMask
->aLbColor3
) ? 1 : 0 );
326 pMask
->pQSet4
->SelectItem( pLb
== &( pMask
->aLbColor4
) ? 1 : 0 );
331 //-------------------------------------------------------------------------
333 IMPL_LINK_NOARG(MaskData
, ExecHdl
)
335 SfxBoolItem
aBItem( SID_BMPMASK_EXEC
, sal_True
);
336 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_EXEC
, OWN_CALLMODE
, &aBItem
, 0L );
341 //-------------------------------------------------------------------------
343 void ColorWindow::Paint( const Rectangle
&/*Rect*/ )
345 const Color
& rOldLineColor
= GetLineColor();
346 const Color
& rOldFillColor
= GetFillColor();
348 SetLineColor( aColor
);
349 SetFillColor( aColor
);
351 DrawRect( Rectangle( Point(), GetSizePixel() ) );
353 SetLineColor( rOldLineColor
);
354 SetFillColor( rOldFillColor
);
357 //-------------------------------------------------------------------------
359 SvxBmpMaskSelectItem::SvxBmpMaskSelectItem( sal_uInt16 nId_
, SvxBmpMask
& rMask
,
360 SfxBindings
& rBindings
) :
361 SfxControllerItem ( nId_
, rBindings
),
366 //-------------------------------------------------------------------------
368 void SvxBmpMaskSelectItem::StateChanged( sal_uInt16 nSID
, SfxItemState
/*eState*/,
369 const SfxPoolItem
* pItem
)
371 if ( ( nSID
== SID_BMPMASK_EXEC
) && pItem
)
373 const SfxBoolItem
* pStateItem
= PTR_CAST( SfxBoolItem
, pItem
);
375 DBG_ASSERT( pStateItem
|| pItem
== 0, "SfxBoolItem erwartet");
377 rBmpMask
.SetExecState( pStateItem
->GetValue() );
381 //-------------------------------------------------------------------------
383 SvxBmpMaskChildWindow::SvxBmpMaskChildWindow( Window
* pParent_
, sal_uInt16 nId
,
384 SfxBindings
* pBindings
,
385 SfxChildWinInfo
* pInfo
) :
386 SfxChildWindow( pParent_
, nId
)
388 pWindow
= new SvxBmpMask( pBindings
, this, pParent_
,
389 BMP_RESID( RID_SVXDLG_BMPMASK
) );
390 SvxBmpMask
* pDlg
= (SvxBmpMask
*) pWindow
;
392 eChildAlignment
= SFX_ALIGN_NOALIGNMENT
;
394 pDlg
->Initialize( pInfo
);
397 //-------------------------------------------------------------------------
399 SvxBmpMask::SvxBmpMask( SfxBindings
*pBindinx
,
402 const ResId
& rResId
) :
403 SfxDockingWindow ( pBindinx
, pCW
, pParent
, rResId
),
404 aTbxPipette ( this, BMP_RESID( TBX_PIPETTE
) ),
405 pCtlPipette ( new ColorWindow( this, BMP_RESID( WND_PIPETTE
) ) ),
406 aBtnExec ( this, BMP_RESID( BTN_EXEC
) ),
407 aGrpQ ( this, BMP_RESID( GRP_Q
) ),
409 aFt1 ( this, BMP_RESID ( FT_1
) ),
410 aFt2 ( this, BMP_RESID ( FT_2
) ),
411 aFt3 ( this, BMP_RESID ( FT_3
) ),
413 aCbx1 ( this, BMP_RESID( CBX_1
) ),
414 pQSet1 ( new MaskSet( this, BMP_RESID( QCOL_1
) ) ),
415 aSp1 ( this, BMP_RESID( SP_1
) ),
416 aLbColor1 ( this, BMP_RESID ( LB_1
) ),
418 aCbx2 ( this, BMP_RESID( CBX_2
) ),
419 pQSet2 ( new MaskSet( this, BMP_RESID( QCOL_2
) ) ),
420 aSp2 ( this, BMP_RESID( SP_2
) ),
421 aLbColor2 ( this, BMP_RESID ( LB_2
) ),
423 aCbx3 ( this, BMP_RESID( CBX_3
) ),
424 pQSet3 ( new MaskSet( this, BMP_RESID( QCOL_3
) ) ),
425 aSp3 ( this, BMP_RESID( SP_3
) ),
426 aLbColor3 ( this, BMP_RESID ( LB_3
) ),
428 aCbx4 ( this, BMP_RESID( CBX_4
) ),
429 pQSet4 ( new MaskSet( this, BMP_RESID( QCOL_4
) ) ),
430 aSp4 ( this, BMP_RESID( SP_4
) ),
431 aLbColor4 ( this, BMP_RESID ( LB_4
) ),
433 pData ( new MaskData( this, *pBindinx
) ),
434 aCbxTrans ( this, BMP_RESID( CBX_TRANS
) ),
435 aLbColorTrans ( this, BMP_RESID ( LB_TRANS
) ),
436 aPipetteColor ( COL_WHITE
),
437 aSelItem ( SID_BMPMASK_EXEC
, *this, *pBindinx
),
438 maImgPipette ( BMP_RESID ( IMG_PIPETTE
) )
444 aTbxPipette
.SetSizePixel( aTbxPipette
.CalcWindowSizePixel() );
445 aTbxPipette
.SetSelectHdl( LINK( pData
, MaskData
, PipetteHdl
) );
446 aBtnExec
.SetClickHdl( LINK( pData
, MaskData
, ExecHdl
) );
448 aCbx1
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
449 aCbx2
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
450 aCbx3
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
451 aCbx4
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
452 aCbxTrans
.SetClickHdl( LINK( pData
, MaskData
, CbxTransHdl
) );
454 SetAccessibleNames ();
456 aLbColor1
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
457 aLbColor2
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
458 aLbColor3
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
459 aLbColor4
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
460 aLbColorTrans
.Disable();
467 pQSet1
->SetStyle( pQSet1
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
468 pQSet1
->SetColCount( 1 );
469 pQSet1
->SetLineCount( 1 );
470 pQSet1
->InsertItem( 1, aPipetteColor
);
471 pQSet1
->SelectItem( 1 );
473 pQSet2
->SetStyle( pQSet2
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
474 pQSet2
->SetColCount( 1 );
475 pQSet2
->SetLineCount( 1 );
476 pQSet2
->InsertItem( 1, aPipetteColor
);
477 pQSet2
->SelectItem( 0 );
479 pQSet3
->SetStyle( pQSet3
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
480 pQSet3
->SetColCount( 1 );
481 pQSet3
->SetLineCount( 1 );
482 pQSet3
->InsertItem( 1, aPipetteColor
);
483 pQSet3
->SelectItem( 0 );
485 pQSet4
->SetStyle( pQSet4
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
486 pQSet4
->SetColCount( 1 );
487 pQSet4
->SetLineCount( 1 );
488 pQSet4
->InsertItem( 1, aPipetteColor
);
489 pQSet4
->SelectItem( 0 );
496 aCbx1
.SetAccessibleRelationMemberOf( &aGrpQ
);
497 pQSet1
->SetAccessibleRelationMemberOf( &aGrpQ
);
498 aSp1
.SetAccessibleRelationMemberOf( &aGrpQ
);
499 aLbColor1
.SetAccessibleRelationMemberOf( &aGrpQ
);
500 aCbx1
.SetAccessibleRelationLabeledBy( &aFt1
);
501 pQSet1
->SetAccessibleRelationLabeledBy( &aFt1
);
502 aSp1
.SetAccessibleRelationLabeledBy( &aFt2
);
503 aLbColor1
.SetAccessibleRelationLabeledBy( &aFt3
);
504 aCbx2
.SetAccessibleRelationMemberOf( &aGrpQ
);
505 pQSet2
->SetAccessibleRelationMemberOf( &aGrpQ
);
506 aSp2
.SetAccessibleRelationMemberOf( &aGrpQ
);
507 aLbColor2
.SetAccessibleRelationMemberOf( &aGrpQ
);
508 aCbx2
.SetAccessibleRelationLabeledBy( &aFt1
);
509 pQSet2
->SetAccessibleRelationLabeledBy( &aFt1
);
510 aSp2
.SetAccessibleRelationLabeledBy( &aFt2
);
511 aLbColor2
.SetAccessibleRelationLabeledBy( &aFt3
);
512 aCbx3
.SetAccessibleRelationMemberOf( &aGrpQ
);
513 pQSet3
->SetAccessibleRelationMemberOf( &aGrpQ
);
514 aSp3
.SetAccessibleRelationMemberOf( &aGrpQ
);
515 aLbColor3
.SetAccessibleRelationMemberOf( &aGrpQ
);
516 aCbx3
.SetAccessibleRelationLabeledBy( &aFt1
);
517 pQSet3
->SetAccessibleRelationLabeledBy( &aFt1
);
518 aSp3
.SetAccessibleRelationLabeledBy( &aFt2
);
519 aLbColor3
.SetAccessibleRelationLabeledBy( &aFt3
);
520 aCbx4
.SetAccessibleRelationMemberOf( &aGrpQ
);
521 pQSet4
->SetAccessibleRelationMemberOf( &aGrpQ
);
522 aSp4
.SetAccessibleRelationMemberOf( &aGrpQ
);
523 aLbColor4
.SetAccessibleRelationMemberOf( &aGrpQ
);
524 aCbx4
.SetAccessibleRelationLabeledBy( &aFt1
);
525 pQSet4
->SetAccessibleRelationLabeledBy( &aFt1
);
526 aSp4
.SetAccessibleRelationLabeledBy( &aFt2
);
527 aLbColor4
.SetAccessibleRelationLabeledBy( &aFt3
);
528 aLbColorTrans
.SetAccessibleRelationLabeledBy( &aCbxTrans
);
529 aLbColorTrans
.SetAccessibleRelationMemberOf( &aGrpQ
);
530 aCbxTrans
.SetAccessibleRelationMemberOf( &aGrpQ
);
533 //-------------------------------------------------------------------------
535 SvxBmpMask::~SvxBmpMask()
545 //-------------------------------------------------------------------------
547 /** is called by a MaskSet when it is selected */
548 void SvxBmpMask::onSelect( MaskSet
* pSet
)
550 // now deselect all other value sets
552 pQSet1
->SelectItem( 0 );
555 pQSet2
->SelectItem( 0 );
558 pQSet3
->SelectItem( 0 );
561 pQSet4
->SelectItem( 0 );
564 //-------------------------------------------------------------------------
566 sal_Bool
SvxBmpMask::Close()
568 SfxBoolItem
aItem2( SID_BMPMASK_PIPETTE
, sal_False
);
569 GetBindings().GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aItem2
, 0L );
571 return SfxDockingWindow::Close();
574 //-------------------------------------------------------------------------
576 sal_Bool
SvxBmpMask::NeedsColorList() const
578 return ( aLbColor1
.GetEntryCount() == 0 );
581 //-------------------------------------------------------------------------
583 void SvxBmpMask::SetColorList( const XColorListRef
&pList
)
585 if ( pList
.is() && ( pList
!= pColLst
) )
587 const String
aTransp( BMP_RESID( RID_SVXDLG_BMPMASK_STR_TRANSP
) );
591 aLbColorTrans
.Fill( pColLst
);
592 aLbColorTrans
.SelectEntryPos( 0 );
594 aLbColor1
.Fill( pColLst
);
595 aLbColor1
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
596 aLbColor1
.SelectEntryPos( 0 );
598 aLbColor2
.Fill( pColLst
);
599 aLbColor2
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
600 aLbColor2
.SelectEntryPos( 0 );
602 aLbColor3
.Fill( pColLst
);
603 aLbColor3
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
604 aLbColor3
.SelectEntryPos( 0 );
606 aLbColor4
.Fill( pColLst
);
607 aLbColor4
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
608 aLbColor4
.SelectEntryPos( 0 );
612 //-------------------------------------------------------------------------
614 void SvxBmpMask::SetColor( const Color
& rColor
)
616 aPipetteColor
= rColor
;
617 pCtlPipette
->SetColor( aPipetteColor
);
620 //-------------------------------------------------------------------------
622 void SvxBmpMask::PipetteClicked()
624 if( pQSet1
->GetSelectItemId() == 1 )
626 aCbx1
.Check( sal_True
);
627 pData
->CbxHdl( &aCbx1
);
628 pQSet1
->SetItemColor( 1, aPipetteColor
);
630 else if( pQSet2
->GetSelectItemId() == 1 )
632 aCbx2
.Check( sal_True
);
633 pData
->CbxHdl( &aCbx2
);
634 pQSet2
->SetItemColor( 1, aPipetteColor
);
636 else if( pQSet3
->GetSelectItemId() == 1 )
638 aCbx3
.Check( sal_True
);
639 pData
->CbxHdl( &aCbx3
);
640 pQSet3
->SetItemColor( 1, aPipetteColor
);
642 else if( pQSet4
->GetSelectItemId() == 1 )
644 aCbx4
.Check( sal_True
);
645 pData
->CbxHdl( &aCbx4
);
646 pQSet4
->SetItemColor( 1, aPipetteColor
);
649 aTbxPipette
.CheckItem( TBI_PIPETTE
, sal_False
);
650 pData
->PipetteHdl( &aTbxPipette
);
653 //-------------------------------------------------------------------------
655 void SvxBmpMask::SetExecState( sal_Bool bEnable
)
657 pData
->SetExecState( bEnable
);
659 if ( pData
->IsExecReady() && pData
->IsCbxReady() )
665 //-------------------------------------------------------------------------
667 sal_uInt16
SvxBmpMask::InitColorArrays( Color
* pSrcCols
, Color
* pDstCols
, sal_uIntPtr
* pTols
)
669 sal_uInt16 nCount
= 0;
671 if ( aCbx1
.IsChecked() )
673 pSrcCols
[nCount
] = pQSet1
->GetItemColor( 1 );
674 pDstCols
[nCount
] = aLbColor1
.GetSelectEntryColor();
675 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp1
.GetValue());
678 if ( aCbx2
.IsChecked() )
680 pSrcCols
[nCount
] = pQSet2
->GetItemColor( 1 );
681 pDstCols
[nCount
] = aLbColor2
.GetSelectEntryColor();
682 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp2
.GetValue());
685 if ( aCbx3
.IsChecked() )
687 pSrcCols
[nCount
] = pQSet3
->GetItemColor( 1 );
688 pDstCols
[nCount
] = aLbColor3
.GetSelectEntryColor();
689 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp3
.GetValue());
692 if ( aCbx4
.IsChecked() )
694 pSrcCols
[nCount
] = pQSet4
->GetItemColor( 1 );
695 pDstCols
[nCount
] = aLbColor4
.GetSelectEntryColor();
696 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp4
.GetValue());
702 //-------------------------------------------------------------------------
704 Bitmap
SvxBmpMask::ImpMask( const Bitmap
& rBitmap
)
706 Bitmap
aBitmap( rBitmap
);
709 sal_uIntPtr pTols
[4];
710 const sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
713 aBitmap
.Replace( pSrcCols
, pDstCols
, nCount
, pTols
);
719 //-------------------------------------------------------------------------
721 BitmapEx
SvxBmpMask::ImpMaskTransparent( const BitmapEx
& rBitmapEx
, const Color
& rColor
, const long nTol
)
726 Bitmap
aMask( rBitmapEx
.GetBitmap().CreateMask( rColor
, nTol
) );
728 if( rBitmapEx
.IsTransparent() )
729 aMask
.CombineSimple( rBitmapEx
.GetMask(), BMP_COMBINE_OR
);
731 aBmpEx
= BitmapEx( rBitmapEx
.GetBitmap(), aMask
);
737 //-------------------------------------------------------------------------
739 Animation
SvxBmpMask::ImpMask( const Animation
& rAnimation
)
741 Animation
aAnimation( rAnimation
);
744 sal_uIntPtr pTols
[4];
745 InitColorArrays( pSrcCols
, pDstCols
, pTols
);
746 sal_uInt16 nAnimationCount
= aAnimation
.Count();
748 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
750 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
751 aAnimBmp
.aBmpEx
= Mask( aAnimBmp
.aBmpEx
).GetBitmapEx();
752 aAnimation
.Replace( aAnimBmp
, i
);
758 //-------------------------------------------------------------------------
760 GDIMetaFile
SvxBmpMask::ImpMask( const GDIMetaFile
& rMtf
)
765 sal_uIntPtr pTols
[4];
766 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
769 // If no color is selected, we copy only the Mtf
780 long* pMinR
= new long[nCount
];
781 long* pMaxR
= new long[nCount
];
782 long* pMinG
= new long[nCount
];
783 long* pMaxG
= new long[nCount
];
784 long* pMinB
= new long[nCount
];
785 long* pMaxB
= new long[nCount
];
789 aMtf
.SetPrefSize( rMtf
.GetPrefSize() );
790 aMtf
.SetPrefMapMode( rMtf
.GetPrefMapMode() );
792 // Prepare Color comparison array
793 for( i
= 0; i
< nCount
; i
++ )
795 nTol
= ( pTols
[i
] * 255L ) / 100L;
797 nVal
= ( (long) pSrcCols
[i
].GetRed() );
798 pMinR
[i
] = Max( nVal
- nTol
, 0L );
799 pMaxR
[i
] = Min( nVal
+ nTol
, 255L );
801 nVal
= ( (long) pSrcCols
[i
].GetGreen() );
802 pMinG
[i
] = Max( nVal
- nTol
, 0L );
803 pMaxG
[i
] = Min( nVal
+ nTol
, 255L );
805 nVal
= ( (long) pSrcCols
[i
].GetBlue() );
806 pMinB
[i
] = Max( nVal
- nTol
, 0L );
807 pMaxB
[i
] = Min( nVal
+ nTol
, 255L );
809 pTrans
[ i
] = ( pDstCols
[ i
] == TRANSP_COL
);
812 // Investigate actions and if necessary replace colors
813 for( size_t nAct
= 0, nActCount
= rMtf
.GetActionSize(); nAct
< nActCount
; nAct
++ )
815 MetaAction
* pAction
= rMtf
.GetAction( nAct
);
817 bReplace
= sal_False
;
819 switch( pAction
->GetType() )
821 case( META_PIXEL_ACTION
):
823 MetaPixelAction
* pAct
= (MetaPixelAction
*) pAction
;
825 aCol
= pAct
->GetColor();
829 pAct
= new MetaPixelAction( pAct
->GetPoint(), aCol
);
833 aMtf
.AddAction( pAct
);
837 case( META_LINECOLOR_ACTION
):
839 MetaLineColorAction
* pAct
= (MetaLineColorAction
*) pAction
;
841 aCol
= pAct
->GetColor();
845 pAct
= new MetaLineColorAction( aCol
, !pTrans
[ i
] );
849 aMtf
.AddAction( pAct
);
853 case( META_FILLCOLOR_ACTION
):
855 MetaFillColorAction
* pAct
= (MetaFillColorAction
*) pAction
;
857 aCol
= pAct
->GetColor();
861 pAct
= new MetaFillColorAction( aCol
, !pTrans
[ i
] );
865 aMtf
.AddAction( pAct
);
869 case( META_TEXTCOLOR_ACTION
):
871 MetaTextColorAction
* pAct
= (MetaTextColorAction
*) pAction
;
873 aCol
= pAct
->GetColor();
877 pAct
= new MetaTextColorAction( aCol
);
881 aMtf
.AddAction( pAct
);
885 case( META_TEXTFILLCOLOR_ACTION
):
887 MetaTextFillColorAction
* pAct
= (MetaTextFillColorAction
*) pAction
;
889 aCol
= pAct
->GetColor();
893 pAct
= new MetaTextFillColorAction( aCol
, !pTrans
[ i
] );
897 aMtf
.AddAction( pAct
);
901 case( META_FONT_ACTION
):
903 MetaFontAction
* pAct
= (MetaFontAction
*) pAction
;
904 Font
aFont( pAct
->GetFont() );
906 aCol
= aFont
.GetColor();
911 aFont
.SetColor( aCol
);
912 pAct
= new MetaFontAction( aFont
);
917 aMtf
.AddAction( pAct
);
921 case( META_WALLPAPER_ACTION
):
923 MetaWallpaperAction
* pAct
= (MetaWallpaperAction
*) pAction
;
924 Wallpaper
aWall( pAct
->GetWallpaper() );
926 aCol
= aWall
.GetColor();
931 aWall
.SetColor( aCol
);
932 pAct
= new MetaWallpaperAction( pAct
->GetRect(), aWall
);
937 aMtf
.AddAction( pAct
);
941 case( META_BMP_ACTION
):
943 MetaBmpAction
* pAct
= (MetaBmpAction
*) pAction
;
944 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
946 pAct
= new MetaBmpAction( pAct
->GetPoint(), aBmp
);
947 aMtf
.AddAction( pAct
);
951 case( META_BMPSCALE_ACTION
):
953 MetaBmpScaleAction
* pAct
= (MetaBmpScaleAction
*) pAction
;
954 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
956 pAct
= new MetaBmpScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmp
);
957 aMtf
.AddAction( pAct
);
961 case( META_BMPSCALEPART_ACTION
):
963 MetaBmpScalePartAction
* pAct
= (MetaBmpScalePartAction
*) pAction
;
964 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
966 pAct
= new MetaBmpScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
967 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmp
);
968 aMtf
.AddAction( pAct
);
972 case( META_BMPEX_ACTION
):
974 MetaBmpExAction
* pAct
= (MetaBmpExAction
*) pAction
;
975 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
977 pAct
= new MetaBmpExAction( pAct
->GetPoint(), aBmpEx
);
978 aMtf
.AddAction( pAct
);
982 case( META_BMPEXSCALE_ACTION
):
984 MetaBmpExScaleAction
* pAct
= (MetaBmpExScaleAction
*) pAction
;
985 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
987 pAct
= new MetaBmpExScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmpEx
);
988 aMtf
.AddAction( pAct
);
992 case( META_BMPEXSCALEPART_ACTION
):
994 MetaBmpExScalePartAction
* pAct
= (MetaBmpExScalePartAction
*) pAction
;
995 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
997 pAct
= new MetaBmpExScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
998 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmpEx
);
999 aMtf
.AddAction( pAct
);
1005 OSL_ENSURE( pAction
->GetType() != META_RENDERGRAPHIC_ACTION
,
1006 "META_RENDERGRAPHIC_ACTION currently not supported at masking" );
1008 pAction
->Duplicate();
1009 aMtf
.AddAction( pAction
);
1028 //-------------------------------------------------------------------------
1030 BitmapEx
SvxBmpMask::ImpReplaceTransparency( const BitmapEx
& rBmpEx
, const Color
& rColor
)
1032 if( rBmpEx
.IsTransparent() )
1034 Bitmap
aBmp( rBmpEx
.GetBitmap() );
1035 aBmp
.Replace( rBmpEx
.GetMask(), rColor
);
1042 //-------------------------------------------------------------------------
1044 Animation
SvxBmpMask::ImpReplaceTransparency( const Animation
& rAnim
, const Color
& rColor
)
1046 Animation
aAnimation( rAnim
);
1047 sal_uInt16 nAnimationCount
= aAnimation
.Count();
1049 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
1051 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
1052 aAnimBmp
.aBmpEx
= ImpReplaceTransparency( aAnimBmp
.aBmpEx
, rColor
);
1053 aAnimation
.Replace( aAnimBmp
, i
);
1059 //-------------------------------------------------------------------------
1061 GDIMetaFile
SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile
& rMtf
, const Color
& rColor
)
1063 VirtualDevice aVDev
;
1065 const MapMode
& rPrefMap
= rMtf
.GetPrefMapMode();
1066 const Size
& rPrefSize
= rMtf
.GetPrefSize();
1067 const size_t nActionCount
= rMtf
.GetActionSize();
1069 aVDev
.EnableOutput( sal_False
);
1070 aMtf
.Record( &aVDev
);
1071 aMtf
.SetPrefSize( rPrefSize
);
1072 aMtf
.SetPrefMapMode( rPrefMap
);
1073 aVDev
.SetLineColor( rColor
);
1074 aVDev
.SetFillColor( rColor
);
1076 // retrieve one action at the time; first
1077 // set the whole area to the replacement color.
1078 aVDev
.DrawRect( Rectangle( rPrefMap
.GetOrigin(), rPrefSize
) );
1079 for ( size_t i
= 0; i
< nActionCount
; i
++ )
1081 MetaAction
* pAct
= rMtf
.GetAction( i
);
1084 aMtf
.AddAction( pAct
);
1093 //-------------------------------------------------------------------------
1095 Graphic
SvxBmpMask::Mask( const Graphic
& rGraphic
)
1097 Graphic
aGraphic( rGraphic
);
1098 const Color
aReplColor( aLbColorTrans
.GetSelectEntryColor() );
1100 switch( rGraphic
.GetType() )
1102 case( GRAPHIC_BITMAP
):
1104 if( rGraphic
.IsAnimated() )
1106 // Replace transparency?
1107 if ( aCbxTrans
.IsChecked() )
1108 aGraphic
= ImpReplaceTransparency( rGraphic
.GetAnimation(), aReplColor
);
1110 aGraphic
= ImpMask( rGraphic
.GetAnimation() );
1114 // Replace transparency?
1115 if( aCbxTrans
.IsChecked() )
1117 if( aGraphic
.IsTransparent() )
1119 BitmapEx
aBmpEx( ImpReplaceTransparency( aGraphic
.GetBitmapEx(), aReplColor
) );
1120 const Size
aSize( aBmpEx
.GetSizePixel() );
1122 if( aSize
.Width() && aSize
.Height() )
1130 sal_uIntPtr pTols
[4];
1131 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
1135 // first set all transparent colors
1136 for( sal_uInt16 i
= 0; i
< nCount
; i
++ )
1138 // Do we have a transparent color?
1139 if( pDstCols
[i
] == TRANSP_COL
)
1141 BitmapEx
aBmpEx( ImpMaskTransparent( aGraphic
.GetBitmapEx(),
1142 pSrcCols
[ i
], pTols
[ i
] ) );
1143 const Size
aSize( aBmpEx
.GetSizePixel() );
1145 if( aSize
.Width() && aSize
.Height() )
1150 // now replace it again with the normal colors
1151 Bitmap
aBitmap( ImpMask( aGraphic
.GetBitmap() ) );
1152 Size
aSize( aBitmap
.GetSizePixel() );
1154 if ( aSize
.Width() && aSize
.Height() )
1156 if ( aGraphic
.IsTransparent() )
1157 aGraphic
= Graphic( BitmapEx( aBitmap
, aGraphic
.GetBitmapEx().GetMask() ) );
1167 case( GRAPHIC_GDIMETAFILE
):
1169 GDIMetaFile
aMtf( aGraphic
.GetGDIMetaFile() );
1171 // Replace transparency?
1172 if( aCbxTrans
.IsChecked() )
1173 aMtf
= ImpReplaceTransparency( aMtf
, aReplColor
);
1175 aMtf
= ImpMask( aMtf
);
1177 Size
aSize( aMtf
.GetPrefSize() );
1178 if ( aSize
.Width() && aSize
.Height() )
1179 aGraphic
= Graphic( aMtf
);
1181 aGraphic
= rGraphic
;
1186 aGraphic
= rGraphic
;
1190 if( aGraphic
!= rGraphic
)
1192 aGraphic
.SetPrefSize( rGraphic
.GetPrefSize() );
1193 aGraphic
.SetPrefMapMode( rGraphic
.GetPrefMapMode() );
1199 //-------------------------------------------------------------------------
1201 sal_Bool
SvxBmpMask::IsEyedropping() const
1203 return aTbxPipette
.IsItemChecked( TBI_PIPETTE
);
1206 void SvxBmpMask::DataChanged( const DataChangedEvent
& rDCEvt
)
1208 SfxDockingWindow::DataChanged( rDCEvt
);
1210 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
1214 void SvxBmpMask::ApplyStyle()
1216 aTbxPipette
.SetItemImage( TBI_PIPETTE
, maImgPipette
);
1220 /** Set an accessible name for the source color check boxes. Without this
1221 the lengthy description is read.
1223 void SvxBmpMask::SetAccessibleNames (void)
1225 String
sSourceColor (BMP_RESID( RID_SVXDLG_BMPMASK_STR_SOURCECOLOR
));
1226 String sSourceColorN
;
1228 sSourceColorN
= sSourceColor
;
1229 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 1"));
1230 aCbx1
.SetAccessibleName (sSourceColorN
);
1232 sSourceColorN
= sSourceColor
;
1233 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 2"));
1234 aCbx2
.SetAccessibleName (sSourceColorN
);
1236 sSourceColorN
= sSourceColor
;
1237 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 3"));
1238 aCbx3
.SetAccessibleName (sSourceColorN
);
1240 sSourceColorN
= sSourceColor
;
1241 sSourceColorN
.AppendAscii (RTL_CONSTASCII_STRINGPARAM (" 4"));
1242 aCbx4
.SetAccessibleName (sSourceColorN
);
1245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */