1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/wrkwin.hxx>
21 #include <tools/shl.hxx>
22 #include <vcl/metaact.hxx>
23 #include <vcl/settings.hxx>
24 #include <svtools/valueset.hxx>
25 #include <svl/eitem.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <svtools/colrdlg.hxx>
29 #define BMPMASK_PRIVATE
31 #include <svx/dialmgr.hxx>
32 #include <svx/bmpmask.hxx>
33 #include <svx/dialogs.hrc>
34 #include <bmpmask.hrc>
35 #include <svx/svxids.hrc>
39 #define BMP_RESID(nId) ResId(nId, DIALOG_MGR())
40 #define TRANSP_COL (Color( 252, 252, 252 ))
41 #define OWN_CALLMODE SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD
47 nR = aCol.GetRed(); nG = aCol.GetGreen(); nB = aCol.GetBlue(); \
48 for( i = 0; i < nCount; i++ ) \
50 if ( ( pMinR[i] <= nR ) && ( pMaxR[i] >= nR ) && \
51 ( pMinG[i] <= nG ) && ( pMaxG[i] >= nG ) && \
52 ( pMinB[i] <= nB ) && ( pMaxB[i] >= nB ) ) \
54 aCol = pDstCols[i]; bReplace = true; break; \
61 SFX_IMPL_DOCKINGWINDOW_WITHID( SvxBmpMaskChildWindow
, SID_BMPMASK
)
65 class ColorWindow
: public Control
71 ColorWindow( Window
* pParent
, const ResId
& rId
) :
72 Control( pParent
, rId
),
73 aColor( COL_WHITE
) {};
75 void SetColor( const Color
& rColor
)
81 virtual void Paint( const Rectangle
& rRect
) SAL_OVERRIDE
;
86 class MaskSet
: public ValueSet
88 SvxBmpMask
* pSvxBmpMask
;
92 MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
);
94 virtual void Select() SAL_OVERRIDE
;
95 virtual void KeyInput( const KeyEvent
& rKEvt
) SAL_OVERRIDE
;
96 virtual void GetFocus() SAL_OVERRIDE
;
103 MaskSet::MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
) :
104 ValueSet ( pParent
, rId
),
105 pSvxBmpMask ( pParent
)
111 void MaskSet::Select()
115 pSvxBmpMask
->onSelect( this );
118 void MaskSet::GetFocus()
120 ValueSet::GetFocus();
122 pSvxBmpMask
->onSelect( this );
125 void MaskSet::KeyInput( const KeyEvent
& rKEvt
)
127 KeyCode aCode
= rKEvt
.GetKeyCode();
129 // if the key has a modifier we don't care
130 if( aCode
.GetModifier() )
132 ValueSet::KeyInput( rKEvt
);
136 // check for keys that interests us
137 switch ( aCode
.GetCode() )
143 ValueSet::KeyInput( rKEvt
);
149 void MaskSet::onEditColor()
151 SvColorDialog
* pColorDlg
= new SvColorDialog( GetParent() );
153 pColorDlg
->SetColor(GetItemColor(1));
155 if( pColorDlg
->Execute() )
156 SetItemColor( 1, pColorDlg
->GetColor() );
168 SfxBindings
& rBindings
;
171 MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
);
173 bool IsCbxReady() const { return bIsReady
; }
174 void SetExecState( bool bState
) { bExecState
= bState
; }
175 bool IsExecReady() const { return bExecState
; }
177 DECL_LINK( PipetteHdl
, ToolBox
* pTbx
);
178 DECL_LINK( CbxHdl
, CheckBox
* pCbx
);
179 DECL_LINK( CbxTransHdl
, CheckBox
* pCbx
);
180 DECL_LINK( FocusLbHdl
, ColorLB
* pLb
);
181 DECL_LINK(ExecHdl
, void *);
186 MaskData::MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
) :
190 bExecState ( false ),
198 IMPL_LINK( MaskData
, PipetteHdl
, ToolBox
*, pTbx
)
200 SfxBoolItem
aBItem( SID_BMPMASK_PIPETTE
,
201 pTbx
->IsItemChecked( TBI_PIPETTE
) );
203 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aBItem
, 0L );
210 IMPL_LINK( MaskData
, CbxHdl
, CheckBox
*, pCbx
)
212 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
213 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
215 if ( bIsReady
&& IsExecReady() )
216 pMask
->aBtnExec
.Enable();
218 pMask
->aBtnExec
.Disable();
220 // When a checkbox is checked, the pipette is enabled
221 if ( pCbx
->IsChecked() )
223 MaskSet
* pSet
= NULL
;
225 if ( pCbx
== &( pMask
->aCbx1
) )
226 pSet
= pMask
->pQSet1
;
227 else if ( pCbx
== &( pMask
->aCbx2
) )
228 pSet
= pMask
->pQSet2
;
229 else if ( pCbx
== &( pMask
->aCbx3
) )
230 pSet
= pMask
->pQSet3
;
231 else // if ( pCbx == &( pMask->aCbx4 ) )
232 pSet
= pMask
->pQSet4
;
234 pSet
->SelectItem( 1 );
237 pMask
->aTbxPipette
.CheckItem( TBI_PIPETTE
, true );
238 PipetteHdl( &( pMask
->aTbxPipette
) );
246 IMPL_LINK( MaskData
, CbxTransHdl
, CheckBox
*, pCbx
)
248 bIsReady
= pCbx
->IsChecked();
251 pMask
->pQSet1
->Disable();
252 pMask
->pQSet2
->Disable();
253 pMask
->pQSet3
->Disable();
254 pMask
->pQSet4
->Disable();
255 pMask
->pCtlPipette
->Disable();
256 pMask
->aCbx1
.Disable();
257 pMask
->aSp1
.Disable();
258 pMask
->aCbx2
.Disable();
259 pMask
->aSp2
.Disable();
260 pMask
->aCbx3
.Disable();
261 pMask
->aSp3
.Disable();
262 pMask
->aCbx4
.Disable();
263 pMask
->aSp4
.Disable();
264 pMask
->aTbxPipette
.Disable();
266 pMask
->aLbColor1
.Disable();
267 pMask
->aLbColor2
.Disable();
268 pMask
->aLbColor3
.Disable();
269 pMask
->aLbColor4
.Disable();
270 pMask
->aLbColorTrans
.Enable();
274 pMask
->pQSet1
->Enable();
275 pMask
->pQSet2
->Enable();
276 pMask
->pQSet3
->Enable();
277 pMask
->pQSet4
->Enable();
278 pMask
->pCtlPipette
->Enable();
279 pMask
->aCbx1
.Enable();
280 pMask
->aSp1
.Enable();
281 pMask
->aCbx2
.Enable();
282 pMask
->aSp2
.Enable();
283 pMask
->aCbx3
.Enable();
284 pMask
->aSp3
.Enable();
285 pMask
->aCbx4
.Enable();
286 pMask
->aSp4
.Enable();
287 pMask
->aTbxPipette
.Enable();
289 pMask
->aLbColor1
.Enable();
290 pMask
->aLbColor2
.Enable();
291 pMask
->aLbColor3
.Enable();
292 pMask
->aLbColor4
.Enable();
293 pMask
->aLbColorTrans
.Disable();
295 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
296 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
299 if ( bIsReady
&& IsExecReady() )
300 pMask
->aBtnExec
.Enable();
302 pMask
->aBtnExec
.Disable();
309 IMPL_LINK( MaskData
, FocusLbHdl
, ColorLB
*, pLb
)
311 // MT: bFireFox as API parameter is ugly, find better solution????
312 pMask
->pQSet1
->SelectItem( pLb
== &( pMask
->aLbColor1
) ? 1 : 0 /* , false */ );
313 pMask
->pQSet2
->SelectItem( pLb
== &( pMask
->aLbColor2
) ? 1 : 0 /* , false */ );
314 pMask
->pQSet3
->SelectItem( pLb
== &( pMask
->aLbColor3
) ? 1 : 0 /* , false */ );
315 pMask
->pQSet4
->SelectItem( pLb
== &( pMask
->aLbColor4
) ? 1 : 0 /* , false */ );
322 IMPL_LINK_NOARG(MaskData
, ExecHdl
)
324 SfxBoolItem
aBItem( SID_BMPMASK_EXEC
, true );
325 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_EXEC
, OWN_CALLMODE
, &aBItem
, 0L );
332 void ColorWindow::Paint( const Rectangle
&/*Rect*/ )
334 const Color
& rOldLineColor
= GetLineColor();
335 const Color
& rOldFillColor
= GetFillColor();
337 SetLineColor( aColor
);
338 SetFillColor( aColor
);
340 DrawRect( Rectangle( Point(), GetSizePixel() ) );
342 SetLineColor( rOldLineColor
);
343 SetFillColor( rOldFillColor
);
348 SvxBmpMaskSelectItem::SvxBmpMaskSelectItem( sal_uInt16 nId_
, SvxBmpMask
& rMask
,
349 SfxBindings
& rBindings
) :
350 SfxControllerItem ( nId_
, rBindings
),
357 void SvxBmpMaskSelectItem::StateChanged( sal_uInt16 nSID
, SfxItemState
/*eState*/,
358 const SfxPoolItem
* pItem
)
360 if ( ( nSID
== SID_BMPMASK_EXEC
) && pItem
)
362 const SfxBoolItem
* pStateItem
= PTR_CAST( SfxBoolItem
, pItem
);
363 assert(pStateItem
); //SfxBoolItem erwartet
365 rBmpMask
.SetExecState( pStateItem
->GetValue() );
371 SvxBmpMaskChildWindow::SvxBmpMaskChildWindow( Window
* pParent_
, sal_uInt16 nId
,
372 SfxBindings
* pBindings
,
373 SfxChildWinInfo
* pInfo
) :
374 SfxChildWindow( pParent_
, nId
)
376 pWindow
= new SvxBmpMask( pBindings
, this, pParent_
,
377 BMP_RESID( RID_SVXDLG_BMPMASK
) );
378 SvxBmpMask
* pDlg
= (SvxBmpMask
*) pWindow
;
380 eChildAlignment
= SFX_ALIGN_NOALIGNMENT
;
382 pDlg
->Initialize( pInfo
);
387 SvxBmpMask::SvxBmpMask( SfxBindings
*pBindinx
,
390 const ResId
& rResId
) :
391 SfxDockingWindow ( pBindinx
, pCW
, pParent
, rResId
),
392 aTbxPipette ( this, BMP_RESID( TBX_PIPETTE
) ),
393 pCtlPipette ( new ColorWindow( this, BMP_RESID( WND_PIPETTE
) ) ),
394 aBtnExec ( this, BMP_RESID( BTN_EXEC
) ),
395 aGrpQ ( this, BMP_RESID( GRP_Q
) ),
397 aFt1 ( this, BMP_RESID ( FT_1
) ),
398 aFt2 ( this, BMP_RESID ( FT_2
) ),
399 aFt3 ( this, BMP_RESID ( FT_3
) ),
401 aCbx1 ( this, BMP_RESID( CBX_1
) ),
402 pQSet1 ( new MaskSet( this, BMP_RESID( QCOL_1
) ) ),
403 aSp1 ( this, BMP_RESID( SP_1
) ),
404 aLbColor1 ( this, BMP_RESID ( LB_1
) ),
406 aCbx2 ( this, BMP_RESID( CBX_2
) ),
407 pQSet2 ( new MaskSet( this, BMP_RESID( QCOL_2
) ) ),
408 aSp2 ( this, BMP_RESID( SP_2
) ),
409 aLbColor2 ( this, BMP_RESID ( LB_2
) ),
411 aCbx3 ( this, BMP_RESID( CBX_3
) ),
412 pQSet3 ( new MaskSet( this, BMP_RESID( QCOL_3
) ) ),
413 aSp3 ( this, BMP_RESID( SP_3
) ),
414 aLbColor3 ( this, BMP_RESID ( LB_3
) ),
416 aCbx4 ( this, BMP_RESID( CBX_4
) ),
417 pQSet4 ( new MaskSet( this, BMP_RESID( QCOL_4
) ) ),
418 aSp4 ( this, BMP_RESID( SP_4
) ),
419 aLbColor4 ( this, BMP_RESID ( LB_4
) ),
421 pData ( new MaskData( this, *pBindinx
) ),
422 aCbxTrans ( this, BMP_RESID( CBX_TRANS
) ),
423 aLbColorTrans ( this, BMP_RESID ( LB_TRANS
) ),
424 aPipetteColor ( COL_WHITE
),
425 aSelItem ( SID_BMPMASK_EXEC
, *this, *pBindinx
),
426 maImgPipette ( BMP_RESID ( IMG_PIPETTE
) )
432 aTbxPipette
.SetSizePixel( aTbxPipette
.CalcWindowSizePixel() );
433 aTbxPipette
.SetSelectHdl( LINK( pData
, MaskData
, PipetteHdl
) );
434 aBtnExec
.SetClickHdl( LINK( pData
, MaskData
, ExecHdl
) );
436 aCbx1
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
437 aCbx2
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
438 aCbx3
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
439 aCbx4
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
440 aCbxTrans
.SetClickHdl( LINK( pData
, MaskData
, CbxTransHdl
) );
442 SetAccessibleNames ();
444 aLbColor1
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
445 aLbColor2
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
446 aLbColor3
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
447 aLbColor4
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
448 aLbColorTrans
.Disable();
455 pQSet1
->SetStyle( pQSet1
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
456 pQSet1
->SetColCount( 1 );
457 pQSet1
->SetLineCount( 1 );
458 OUString
sColorPalette (BMP_RESID( RID_SVXDLG_BMPMASK_STR_PALETTE
));
459 OUString sColorPaletteN
;
460 sColorPaletteN
= sColorPalette
;
461 sColorPaletteN
+= " 1";
462 pQSet1
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
463 pQSet1
->SelectItem( 1 );
465 pQSet2
->SetStyle( pQSet2
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
466 pQSet2
->SetColCount( 1 );
467 pQSet2
->SetLineCount( 1 );
468 sColorPaletteN
= sColorPalette
;
469 sColorPaletteN
+= " 2";
470 pQSet2
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
471 pQSet2
->SelectItem( 0 );
473 pQSet3
->SetStyle( pQSet3
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
474 pQSet3
->SetColCount( 1 );
475 pQSet3
->SetLineCount( 1 );
476 sColorPaletteN
= sColorPalette
;
477 sColorPaletteN
+= " 3";
478 pQSet3
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
479 pQSet3
->SelectItem( 0 );
481 pQSet4
->SetStyle( pQSet4
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
482 pQSet4
->SetColCount( 1 );
483 pQSet4
->SetLineCount( 1 );
484 sColorPaletteN
= sColorPalette
;
485 sColorPaletteN
+= " 4";
486 pQSet4
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
487 pQSet4
->SelectItem( 0 );
494 aCbx1
.SetAccessibleRelationMemberOf( &aGrpQ
);
495 pQSet1
->SetAccessibleRelationMemberOf( &aGrpQ
);
496 aSp1
.SetAccessibleRelationMemberOf( &aGrpQ
);
497 aLbColor1
.SetAccessibleRelationMemberOf( &aGrpQ
);
498 aCbx1
.SetAccessibleRelationLabeledBy( &aFt1
);
499 pQSet1
->SetAccessibleRelationLabeledBy( &aFt1
);
500 aSp1
.SetAccessibleRelationLabeledBy( &aFt2
);
501 aLbColor1
.SetAccessibleRelationLabeledBy( &aFt3
);
502 aCbx2
.SetAccessibleRelationMemberOf( &aGrpQ
);
503 pQSet2
->SetAccessibleRelationMemberOf( &aGrpQ
);
504 aSp2
.SetAccessibleRelationMemberOf( &aGrpQ
);
505 aLbColor2
.SetAccessibleRelationMemberOf( &aGrpQ
);
506 aCbx2
.SetAccessibleRelationLabeledBy( &aFt1
);
507 pQSet2
->SetAccessibleRelationLabeledBy( &aFt1
);
508 aSp2
.SetAccessibleRelationLabeledBy( &aFt2
);
509 aLbColor2
.SetAccessibleRelationLabeledBy( &aFt3
);
510 aCbx3
.SetAccessibleRelationMemberOf( &aGrpQ
);
511 pQSet3
->SetAccessibleRelationMemberOf( &aGrpQ
);
512 aSp3
.SetAccessibleRelationMemberOf( &aGrpQ
);
513 aLbColor3
.SetAccessibleRelationMemberOf( &aGrpQ
);
514 aCbx3
.SetAccessibleRelationLabeledBy( &aFt1
);
515 pQSet3
->SetAccessibleRelationLabeledBy( &aFt1
);
516 aSp3
.SetAccessibleRelationLabeledBy( &aFt2
);
517 aLbColor3
.SetAccessibleRelationLabeledBy( &aFt3
);
518 aCbx4
.SetAccessibleRelationMemberOf( &aGrpQ
);
519 pQSet4
->SetAccessibleRelationMemberOf( &aGrpQ
);
520 aSp4
.SetAccessibleRelationMemberOf( &aGrpQ
);
521 aLbColor4
.SetAccessibleRelationMemberOf( &aGrpQ
);
522 aCbx4
.SetAccessibleRelationLabeledBy( &aFt1
);
523 pQSet4
->SetAccessibleRelationLabeledBy( &aFt1
);
524 aSp4
.SetAccessibleRelationLabeledBy( &aFt2
);
525 aLbColor4
.SetAccessibleRelationLabeledBy( &aFt3
);
526 aLbColorTrans
.SetAccessibleRelationLabeledBy( &aCbxTrans
);
527 aLbColorTrans
.SetAccessibleRelationMemberOf( &aGrpQ
);
528 aCbxTrans
.SetAccessibleRelationMemberOf( &aGrpQ
);
533 SvxBmpMask::~SvxBmpMask()
545 /** is called by a MaskSet when it is selected */
546 void SvxBmpMask::onSelect( MaskSet
* pSet
)
548 // now deselect all other value sets
550 pQSet1
->SelectItem( 0 );
553 pQSet2
->SelectItem( 0 );
556 pQSet3
->SelectItem( 0 );
559 pQSet4
->SelectItem( 0 );
564 bool SvxBmpMask::Close()
566 SfxBoolItem
aItem2( SID_BMPMASK_PIPETTE
, false );
567 GetBindings().GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aItem2
, 0L );
569 return SfxDockingWindow::Close();
574 bool SvxBmpMask::NeedsColorList() const
576 return ( aLbColor1
.GetEntryCount() == 0 );
581 void SvxBmpMask::SetColorList( const XColorListRef
&pList
)
583 if ( pList
.is() && ( pList
!= pColLst
) )
585 const OUString
aTransp(BMP_RESID(RID_SVXDLG_BMPMASK_STR_TRANSP
).toString());
589 aLbColorTrans
.Fill( pColLst
);
590 aLbColorTrans
.SelectEntryPos( 0 );
592 aLbColor1
.Fill( pColLst
);
593 aLbColor1
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
594 aLbColor1
.SelectEntryPos( 0 );
596 aLbColor2
.Fill( pColLst
);
597 aLbColor2
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
598 aLbColor2
.SelectEntryPos( 0 );
600 aLbColor3
.Fill( pColLst
);
601 aLbColor3
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
602 aLbColor3
.SelectEntryPos( 0 );
604 aLbColor4
.Fill( pColLst
);
605 aLbColor4
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
606 aLbColor4
.SelectEntryPos( 0 );
612 void SvxBmpMask::SetColor( const Color
& rColor
)
614 aPipetteColor
= rColor
;
615 pCtlPipette
->SetColor( aPipetteColor
);
620 void SvxBmpMask::PipetteClicked()
622 if( pQSet1
->GetSelectItemId() == 1 )
625 pData
->CbxHdl( &aCbx1
);
626 pQSet1
->SetItemColor( 1, aPipetteColor
);
628 else if( pQSet2
->GetSelectItemId() == 1 )
631 pData
->CbxHdl( &aCbx2
);
632 pQSet2
->SetItemColor( 1, aPipetteColor
);
634 else if( pQSet3
->GetSelectItemId() == 1 )
637 pData
->CbxHdl( &aCbx3
);
638 pQSet3
->SetItemColor( 1, aPipetteColor
);
640 else if( pQSet4
->GetSelectItemId() == 1 )
643 pData
->CbxHdl( &aCbx4
);
644 pQSet4
->SetItemColor( 1, aPipetteColor
);
647 aTbxPipette
.CheckItem( TBI_PIPETTE
, false );
648 pData
->PipetteHdl( &aTbxPipette
);
653 void SvxBmpMask::SetExecState( bool bEnable
)
655 pData
->SetExecState( bEnable
);
657 if ( pData
->IsExecReady() && pData
->IsCbxReady() )
665 sal_uInt16
SvxBmpMask::InitColorArrays( Color
* pSrcCols
, Color
* pDstCols
, sal_uIntPtr
* pTols
)
667 sal_uInt16 nCount
= 0;
669 if ( aCbx1
.IsChecked() )
671 pSrcCols
[nCount
] = pQSet1
->GetItemColor( 1 );
672 pDstCols
[nCount
] = aLbColor1
.GetSelectEntryColor();
673 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp1
.GetValue());
676 if ( aCbx2
.IsChecked() )
678 pSrcCols
[nCount
] = pQSet2
->GetItemColor( 1 );
679 pDstCols
[nCount
] = aLbColor2
.GetSelectEntryColor();
680 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp2
.GetValue());
683 if ( aCbx3
.IsChecked() )
685 pSrcCols
[nCount
] = pQSet3
->GetItemColor( 1 );
686 pDstCols
[nCount
] = aLbColor3
.GetSelectEntryColor();
687 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp3
.GetValue());
690 if ( aCbx4
.IsChecked() )
692 pSrcCols
[nCount
] = pQSet4
->GetItemColor( 1 );
693 pDstCols
[nCount
] = aLbColor4
.GetSelectEntryColor();
694 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp4
.GetValue());
702 Bitmap
SvxBmpMask::ImpMask( const Bitmap
& rBitmap
)
704 Bitmap
aBitmap( rBitmap
);
707 sal_uIntPtr pTols
[4];
708 const sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
711 aBitmap
.Replace( pSrcCols
, pDstCols
, nCount
, pTols
);
719 BitmapEx
SvxBmpMask::ImpMaskTransparent( const BitmapEx
& rBitmapEx
, const Color
& rColor
, const long nTol
)
724 Bitmap
aMask( rBitmapEx
.GetBitmap().CreateMask( rColor
, nTol
) );
726 if( rBitmapEx
.IsTransparent() )
727 aMask
.CombineSimple( rBitmapEx
.GetMask(), BMP_COMBINE_OR
);
729 aBmpEx
= BitmapEx( rBitmapEx
.GetBitmap(), aMask
);
737 Animation
SvxBmpMask::ImpMask( const Animation
& rAnimation
)
739 Animation
aAnimation( rAnimation
);
742 sal_uIntPtr pTols
[4];
743 InitColorArrays( pSrcCols
, pDstCols
, pTols
);
744 sal_uInt16 nAnimationCount
= aAnimation
.Count();
746 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
748 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
749 aAnimBmp
.aBmpEx
= Mask( aAnimBmp
.aBmpEx
).GetBitmapEx();
750 aAnimation
.Replace( aAnimBmp
, i
);
758 GDIMetaFile
SvxBmpMask::ImpMask( const GDIMetaFile
& rMtf
)
763 sal_uIntPtr pTols
[4];
764 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
767 // If no color is selected, we copy only the Mtf
778 long* pMinR
= new long[nCount
];
779 long* pMaxR
= new long[nCount
];
780 long* pMinG
= new long[nCount
];
781 long* pMaxG
= new long[nCount
];
782 long* pMinB
= new long[nCount
];
783 long* pMaxB
= new long[nCount
];
787 aMtf
.SetPrefSize( rMtf
.GetPrefSize() );
788 aMtf
.SetPrefMapMode( rMtf
.GetPrefMapMode() );
790 // Prepare Color comparison array
791 for( i
= 0; i
< nCount
; i
++ )
793 nTol
= ( pTols
[i
] * 255L ) / 100L;
795 nVal
= ( (long) pSrcCols
[i
].GetRed() );
796 pMinR
[i
] = std::max( nVal
- nTol
, 0L );
797 pMaxR
[i
] = std::min( nVal
+ nTol
, 255L );
799 nVal
= ( (long) pSrcCols
[i
].GetGreen() );
800 pMinG
[i
] = std::max( nVal
- nTol
, 0L );
801 pMaxG
[i
] = std::min( nVal
+ nTol
, 255L );
803 nVal
= ( (long) pSrcCols
[i
].GetBlue() );
804 pMinB
[i
] = std::max( nVal
- nTol
, 0L );
805 pMaxB
[i
] = std::min( nVal
+ nTol
, 255L );
807 pTrans
[ i
] = ( pDstCols
[ i
] == TRANSP_COL
);
810 // Investigate actions and if necessary replace colors
811 for( size_t nAct
= 0, nActCount
= rMtf
.GetActionSize(); nAct
< nActCount
; nAct
++ )
813 MetaAction
* pAction
= rMtf
.GetAction( nAct
);
817 switch( pAction
->GetType() )
819 case( META_PIXEL_ACTION
):
821 MetaPixelAction
* pAct
= (MetaPixelAction
*) pAction
;
823 aCol
= pAct
->GetColor();
827 pAct
= new MetaPixelAction( pAct
->GetPoint(), aCol
);
831 aMtf
.AddAction( pAct
);
835 case( META_LINECOLOR_ACTION
):
837 MetaLineColorAction
* pAct
= (MetaLineColorAction
*) pAction
;
839 aCol
= pAct
->GetColor();
843 pAct
= new MetaLineColorAction( aCol
, !pTrans
[ i
] );
847 aMtf
.AddAction( pAct
);
851 case( META_FILLCOLOR_ACTION
):
853 MetaFillColorAction
* pAct
= (MetaFillColorAction
*) pAction
;
855 aCol
= pAct
->GetColor();
859 pAct
= new MetaFillColorAction( aCol
, !pTrans
[ i
] );
863 aMtf
.AddAction( pAct
);
867 case( META_TEXTCOLOR_ACTION
):
869 MetaTextColorAction
* pAct
= (MetaTextColorAction
*) pAction
;
871 aCol
= pAct
->GetColor();
875 pAct
= new MetaTextColorAction( aCol
);
879 aMtf
.AddAction( pAct
);
883 case( META_TEXTFILLCOLOR_ACTION
):
885 MetaTextFillColorAction
* pAct
= (MetaTextFillColorAction
*) pAction
;
887 aCol
= pAct
->GetColor();
891 pAct
= new MetaTextFillColorAction( aCol
, !pTrans
[ i
] );
895 aMtf
.AddAction( pAct
);
899 case( META_FONT_ACTION
):
901 MetaFontAction
* pAct
= (MetaFontAction
*) pAction
;
902 Font
aFont( pAct
->GetFont() );
904 aCol
= aFont
.GetColor();
909 aFont
.SetColor( aCol
);
910 pAct
= new MetaFontAction( aFont
);
915 aMtf
.AddAction( pAct
);
919 case( META_WALLPAPER_ACTION
):
921 MetaWallpaperAction
* pAct
= (MetaWallpaperAction
*) pAction
;
922 Wallpaper
aWall( pAct
->GetWallpaper() );
924 aCol
= aWall
.GetColor();
929 aWall
.SetColor( aCol
);
930 pAct
= new MetaWallpaperAction( pAct
->GetRect(), aWall
);
935 aMtf
.AddAction( pAct
);
939 case( META_BMP_ACTION
):
941 MetaBmpAction
* pAct
= (MetaBmpAction
*) pAction
;
942 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
944 pAct
= new MetaBmpAction( pAct
->GetPoint(), aBmp
);
945 aMtf
.AddAction( pAct
);
949 case( META_BMPSCALE_ACTION
):
951 MetaBmpScaleAction
* pAct
= (MetaBmpScaleAction
*) pAction
;
952 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
954 pAct
= new MetaBmpScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmp
);
955 aMtf
.AddAction( pAct
);
959 case( META_BMPSCALEPART_ACTION
):
961 MetaBmpScalePartAction
* pAct
= (MetaBmpScalePartAction
*) pAction
;
962 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
964 pAct
= new MetaBmpScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
965 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmp
);
966 aMtf
.AddAction( pAct
);
970 case( META_BMPEX_ACTION
):
972 MetaBmpExAction
* pAct
= (MetaBmpExAction
*) pAction
;
973 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
975 pAct
= new MetaBmpExAction( pAct
->GetPoint(), aBmpEx
);
976 aMtf
.AddAction( pAct
);
980 case( META_BMPEXSCALE_ACTION
):
982 MetaBmpExScaleAction
* pAct
= (MetaBmpExScaleAction
*) pAction
;
983 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
985 pAct
= new MetaBmpExScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmpEx
);
986 aMtf
.AddAction( pAct
);
990 case( META_BMPEXSCALEPART_ACTION
):
992 MetaBmpExScalePartAction
* pAct
= (MetaBmpExScalePartAction
*) pAction
;
993 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
995 pAct
= new MetaBmpExScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
996 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmpEx
);
997 aMtf
.AddAction( pAct
);
1003 pAction
->Duplicate();
1004 aMtf
.AddAction( pAction
);
1025 BitmapEx
SvxBmpMask::ImpReplaceTransparency( const BitmapEx
& rBmpEx
, const Color
& rColor
)
1027 if( rBmpEx
.IsTransparent() )
1029 Bitmap
aBmp( rBmpEx
.GetBitmap() );
1030 aBmp
.Replace( rBmpEx
.GetMask(), rColor
);
1039 Animation
SvxBmpMask::ImpReplaceTransparency( const Animation
& rAnim
, const Color
& rColor
)
1041 Animation
aAnimation( rAnim
);
1042 sal_uInt16 nAnimationCount
= aAnimation
.Count();
1044 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
1046 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
1047 aAnimBmp
.aBmpEx
= ImpReplaceTransparency( aAnimBmp
.aBmpEx
, rColor
);
1048 aAnimation
.Replace( aAnimBmp
, i
);
1056 GDIMetaFile
SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile
& rMtf
, const Color
& rColor
)
1058 VirtualDevice aVDev
;
1060 const MapMode
& rPrefMap
= rMtf
.GetPrefMapMode();
1061 const Size
& rPrefSize
= rMtf
.GetPrefSize();
1062 const size_t nActionCount
= rMtf
.GetActionSize();
1064 aVDev
.EnableOutput( false );
1065 aMtf
.Record( &aVDev
);
1066 aMtf
.SetPrefSize( rPrefSize
);
1067 aMtf
.SetPrefMapMode( rPrefMap
);
1068 aVDev
.SetLineColor( rColor
);
1069 aVDev
.SetFillColor( rColor
);
1071 // retrieve one action at the time; first
1072 // set the whole area to the replacement color.
1073 aVDev
.DrawRect( Rectangle( rPrefMap
.GetOrigin(), rPrefSize
) );
1074 for ( size_t i
= 0; i
< nActionCount
; i
++ )
1076 MetaAction
* pAct
= rMtf
.GetAction( i
);
1079 aMtf
.AddAction( pAct
);
1090 Graphic
SvxBmpMask::Mask( const Graphic
& rGraphic
)
1092 Graphic
aGraphic( rGraphic
);
1093 const Color
aReplColor( aLbColorTrans
.GetSelectEntryColor() );
1095 switch( rGraphic
.GetType() )
1097 case( GRAPHIC_BITMAP
):
1099 if( rGraphic
.IsAnimated() )
1101 // Replace transparency?
1102 if ( aCbxTrans
.IsChecked() )
1103 aGraphic
= ImpReplaceTransparency( rGraphic
.GetAnimation(), aReplColor
);
1105 aGraphic
= ImpMask( rGraphic
.GetAnimation() );
1109 // Replace transparency?
1110 if( aCbxTrans
.IsChecked() )
1112 if( aGraphic
.IsTransparent() )
1114 BitmapEx
aBmpEx( ImpReplaceTransparency( aGraphic
.GetBitmapEx(), aReplColor
) );
1115 const Size
aSize( aBmpEx
.GetSizePixel() );
1117 if( aSize
.Width() && aSize
.Height() )
1125 sal_uIntPtr pTols
[4];
1126 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
1130 // first set all transparent colors
1131 for( sal_uInt16 i
= 0; i
< nCount
; i
++ )
1133 // Do we have a transparent color?
1134 if( pDstCols
[i
] == TRANSP_COL
)
1136 BitmapEx
aBmpEx( ImpMaskTransparent( aGraphic
.GetBitmapEx(),
1137 pSrcCols
[ i
], pTols
[ i
] ) );
1138 const Size
aSize( aBmpEx
.GetSizePixel() );
1140 if( aSize
.Width() && aSize
.Height() )
1145 // now replace it again with the normal colors
1146 Bitmap
aBitmap( ImpMask( aGraphic
.GetBitmap() ) );
1147 Size
aSize( aBitmap
.GetSizePixel() );
1149 if ( aSize
.Width() && aSize
.Height() )
1151 if ( aGraphic
.IsTransparent() )
1152 aGraphic
= Graphic( BitmapEx( aBitmap
, aGraphic
.GetBitmapEx().GetMask() ) );
1162 case( GRAPHIC_GDIMETAFILE
):
1164 GDIMetaFile
aMtf( aGraphic
.GetGDIMetaFile() );
1166 // Replace transparency?
1167 if( aCbxTrans
.IsChecked() )
1168 aMtf
= ImpReplaceTransparency( aMtf
, aReplColor
);
1170 aMtf
= ImpMask( aMtf
);
1172 Size
aSize( aMtf
.GetPrefSize() );
1173 if ( aSize
.Width() && aSize
.Height() )
1174 aGraphic
= Graphic( aMtf
);
1176 aGraphic
= rGraphic
;
1181 aGraphic
= rGraphic
;
1185 if( aGraphic
!= rGraphic
)
1187 aGraphic
.SetPrefSize( rGraphic
.GetPrefSize() );
1188 aGraphic
.SetPrefMapMode( rGraphic
.GetPrefMapMode() );
1196 bool SvxBmpMask::IsEyedropping() const
1198 return aTbxPipette
.IsItemChecked( TBI_PIPETTE
);
1201 void SvxBmpMask::DataChanged( const DataChangedEvent
& rDCEvt
)
1203 SfxDockingWindow::DataChanged( rDCEvt
);
1205 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
1209 void SvxBmpMask::ApplyStyle()
1211 aTbxPipette
.SetItemImage( TBI_PIPETTE
, maImgPipette
);
1215 /** Set an accessible name for the source color check boxes. Without this
1216 the lengthy description is read.
1218 void SvxBmpMask::SetAccessibleNames (void)
1220 OUString
sSourceColor(BMP_RESID(RID_SVXDLG_BMPMASK_STR_SOURCECOLOR
).toString());
1221 OUString sSourceColorN
;
1223 sSourceColorN
= sSourceColor
;
1224 sSourceColorN
+= " 1";
1225 aCbx1
.SetAccessibleName (sSourceColorN
);
1227 sSourceColorN
= sSourceColor
;
1228 sSourceColorN
+= " 2";
1229 aCbx2
.SetAccessibleName (sSourceColorN
);
1231 sSourceColorN
= sSourceColor
;
1232 sSourceColorN
+= " 3";
1233 aCbx3
.SetAccessibleName (sSourceColorN
);
1235 sSourceColorN
= sSourceColor
;
1236 sSourceColorN
+= " 4";
1237 aCbx4
.SetAccessibleName (sSourceColorN
);
1238 // set the accessible name for valueset
1239 OUString
sColorPalette (BMP_RESID( RID_SVXDLG_BMPMASK_STR_PALETTE
));
1240 OUString sColorPaletteN
;
1241 sColorPaletteN
= sColorPalette
;
1242 sColorPaletteN
+= " 1";
1243 pQSet1
->SetText (sColorPaletteN
);
1244 sColorPaletteN
= sColorPalette
;
1245 sColorPaletteN
+= " 2";
1246 pQSet2
->SetText (sColorPaletteN
);
1247 sColorPaletteN
= sColorPalette
;
1248 sColorPaletteN
+= " 3";
1249 pQSet3
->SetText (sColorPaletteN
);
1250 sColorPaletteN
= sColorPalette
;
1251 sColorPaletteN
+= " 4";
1252 pQSet4
->SetText (sColorPaletteN
);
1253 // set the accessible for replace with spin boxes.
1254 OUString
sTolerance(BMP_RESID( RID_SVXDLG_BMPMASK_STR_TOLERANCE
));
1255 OUString sToleranceN
;
1256 sToleranceN
= sTolerance
;
1257 sToleranceN
+= " 1";
1258 aSp1
.SetAccessibleName (sToleranceN
);
1259 sToleranceN
= sTolerance
;
1260 sToleranceN
+= " 2";
1261 aSp2
.SetAccessibleName (sToleranceN
);
1262 sToleranceN
= sTolerance
;
1263 sToleranceN
+= " 3";
1264 aSp3
.SetAccessibleName (sToleranceN
);
1265 sToleranceN
= sTolerance
;
1266 sToleranceN
+= " 4";
1267 aSp4
.SetAccessibleName (sToleranceN
);
1268 // set the accessible for replace with combo boxes.
1269 OUString
sReplaceWith(BMP_RESID( RID_SVXDLG_BMPMASK_STR_REPLACEWITH
));
1270 OUString sReplaceWithN
;
1271 sReplaceWithN
= sReplaceWith
;
1272 sReplaceWithN
+= " 1";
1273 aLbColor1
.SetAccessibleName (sReplaceWithN
);
1274 sReplaceWithN
= sReplaceWith
;
1275 sReplaceWithN
+= " 2";
1276 aLbColor2
.SetAccessibleName (sReplaceWithN
);
1277 sReplaceWithN
= sReplaceWith
;
1278 sReplaceWithN
+= " 3";
1279 aLbColor3
.SetAccessibleName (sReplaceWithN
);
1280 sReplaceWithN
= sReplaceWith
;
1281 sReplaceWithN
+= " 4";
1282 aLbColor4
.SetAccessibleName (sReplaceWithN
);
1285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */