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 <svtools/valueset.hxx>
24 #include <svl/eitem.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <svtools/colrdlg.hxx>
28 #define BMPMASK_PRIVATE
30 #include <svx/dialmgr.hxx>
31 #include <svx/bmpmask.hxx>
32 #include <svx/dialogs.hrc>
33 #include <bmpmask.hrc>
34 #include <svx/svxids.hrc>
36 //-------------------------------------------------------------------------
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
42 //-------------------------------------------------------------------------
46 nR = aCol.GetRed(); nG = aCol.GetGreen(); nB = aCol.GetBlue(); \
47 for( i = 0; i < nCount; i++ ) \
49 if ( ( pMinR[i] <= nR ) && ( pMaxR[i] >= nR ) && \
50 ( pMinG[i] <= nG ) && ( pMaxG[i] >= nG ) && \
51 ( pMinB[i] <= nB ) && ( pMaxB[i] >= nB ) ) \
53 aCol = pDstCols[i]; bReplace = sal_True; break; \
58 // -------------------------------------------------------------------------
60 SFX_IMPL_DOCKINGWINDOW_WITHID( SvxBmpMaskChildWindow
, SID_BMPMASK
)
62 // -------------------------------------------------------------------------
64 class ColorWindow
: public Control
71 ColorWindow( Window
* pParent
, WinBits nWinStyle
) :
72 Control( pParent
, nWinStyle
),
73 aColor( COL_WHITE
) {};
75 ColorWindow( Window
* pParent
, const ResId
& rId
) :
76 Control( pParent
, rId
),
77 aColor( COL_WHITE
) {};
79 void SetColor( const Color
& rColor
)
85 virtual void Paint( const Rectangle
& rRect
);
88 //-------------------------------------------------------------------------
90 class MaskSet
: public ValueSet
92 SvxBmpMask
* pSvxBmpMask
;
96 MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
);
98 virtual void Select();
99 virtual void KeyInput( const KeyEvent
& rKEvt
);
100 virtual void GetFocus();
105 //-------------------------------------------------------------------------
107 MaskSet::MaskSet( SvxBmpMask
* pParent
, const ResId
& rId
) :
108 ValueSet ( pParent
, rId
),
109 pSvxBmpMask ( pParent
)
113 //-------------------------------------------------------------------------
115 void MaskSet::Select()
119 pSvxBmpMask
->onSelect( this );
122 void MaskSet::GetFocus()
125 pSvxBmpMask
->onSelect( this );
128 void MaskSet::KeyInput( const KeyEvent
& rKEvt
)
130 KeyCode aCode
= rKEvt
.GetKeyCode();
132 // if the key has a modifier we don't care
133 if( aCode
.GetModifier() )
135 ValueSet::KeyInput( rKEvt
);
139 // check for keys that interests us
140 switch ( aCode
.GetCode() )
146 ValueSet::KeyInput( rKEvt
);
152 void MaskSet::onEditColor()
154 SvColorDialog
* pColorDlg
= new SvColorDialog( GetParent() );
156 pColorDlg
->SetColor(GetItemColor(1));
158 if( pColorDlg
->Execute() )
159 SetItemColor( 1, pColorDlg
->GetColor() );
164 //-------------------------------------------------------------------------
171 SfxBindings
& rBindings
;
174 MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
);
176 sal_Bool
IsCbxReady() const { return bIsReady
; }
177 void SetExecState( sal_Bool bState
) { bExecState
= bState
; }
178 sal_Bool
IsExecReady() const { return bExecState
; }
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 *);
187 //-------------------------------------------------------------------------
189 MaskData::MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
) :
192 bIsReady ( sal_False
),
193 bExecState ( sal_False
),
199 //-------------------------------------------------------------------------
201 IMPL_LINK( MaskData
, PipetteHdl
, ToolBox
*, pTbx
)
203 SfxBoolItem
aBItem( SID_BMPMASK_PIPETTE
,
204 pTbx
->IsItemChecked( TBI_PIPETTE
) );
206 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aBItem
, 0L );
211 //-------------------------------------------------------------------------
213 IMPL_LINK( MaskData
, CbxHdl
, CheckBox
*, pCbx
)
215 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
216 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
218 if ( bIsReady
&& IsExecReady() )
219 pMask
->aBtnExec
.Enable();
221 pMask
->aBtnExec
.Disable();
223 // When a checkbox is checked, the pipette is enabled
224 if ( pCbx
->IsChecked() )
226 MaskSet
* pSet
= NULL
;
228 if ( pCbx
== &( pMask
->aCbx1
) )
229 pSet
= pMask
->pQSet1
;
230 else if ( pCbx
== &( pMask
->aCbx2
) )
231 pSet
= pMask
->pQSet2
;
232 else if ( pCbx
== &( pMask
->aCbx3
) )
233 pSet
= pMask
->pQSet3
;
234 else // if ( pCbx == &( pMask->aCbx4 ) )
235 pSet
= pMask
->pQSet4
;
237 pSet
->SelectItem( 1 );
240 pMask
->aTbxPipette
.CheckItem( TBI_PIPETTE
, sal_True
);
241 PipetteHdl( &( pMask
->aTbxPipette
) );
247 //-------------------------------------------------------------------------
249 IMPL_LINK( MaskData
, CbxTransHdl
, CheckBox
*, pCbx
)
251 bIsReady
= pCbx
->IsChecked();
254 pMask
->pQSet1
->Disable();
255 pMask
->pQSet2
->Disable();
256 pMask
->pQSet3
->Disable();
257 pMask
->pQSet4
->Disable();
258 pMask
->pCtlPipette
->Disable();
259 pMask
->aCbx1
.Disable();
260 pMask
->aSp1
.Disable();
261 pMask
->aCbx2
.Disable();
262 pMask
->aSp2
.Disable();
263 pMask
->aCbx3
.Disable();
264 pMask
->aSp3
.Disable();
265 pMask
->aCbx4
.Disable();
266 pMask
->aSp4
.Disable();
267 pMask
->aTbxPipette
.Disable();
269 pMask
->aLbColor1
.Disable();
270 pMask
->aLbColor2
.Disable();
271 pMask
->aLbColor3
.Disable();
272 pMask
->aLbColor4
.Disable();
273 pMask
->aLbColorTrans
.Enable();
277 pMask
->pQSet1
->Enable();
278 pMask
->pQSet2
->Enable();
279 pMask
->pQSet3
->Enable();
280 pMask
->pQSet4
->Enable();
281 pMask
->pCtlPipette
->Enable();
282 pMask
->aCbx1
.Enable();
283 pMask
->aSp1
.Enable();
284 pMask
->aCbx2
.Enable();
285 pMask
->aSp2
.Enable();
286 pMask
->aCbx3
.Enable();
287 pMask
->aSp3
.Enable();
288 pMask
->aCbx4
.Enable();
289 pMask
->aSp4
.Enable();
290 pMask
->aTbxPipette
.Enable();
292 pMask
->aLbColor1
.Enable();
293 pMask
->aLbColor2
.Enable();
294 pMask
->aLbColor3
.Enable();
295 pMask
->aLbColor4
.Enable();
296 pMask
->aLbColorTrans
.Disable();
298 bIsReady
= pMask
->aCbx1
.IsChecked() || pMask
->aCbx2
.IsChecked() ||
299 pMask
->aCbx3
.IsChecked() || pMask
->aCbx4
.IsChecked();
302 if ( bIsReady
&& IsExecReady() )
303 pMask
->aBtnExec
.Enable();
305 pMask
->aBtnExec
.Disable();
310 //-------------------------------------------------------------------------
312 IMPL_LINK( MaskData
, FocusLbHdl
, ColorLB
*, pLb
)
314 pMask
->pQSet1
->SelectItem( pLb
== &( pMask
->aLbColor1
) ? 1 : 0 );
315 pMask
->pQSet2
->SelectItem( pLb
== &( pMask
->aLbColor2
) ? 1 : 0 );
316 pMask
->pQSet3
->SelectItem( pLb
== &( pMask
->aLbColor3
) ? 1 : 0 );
317 pMask
->pQSet4
->SelectItem( pLb
== &( pMask
->aLbColor4
) ? 1 : 0 );
322 //-------------------------------------------------------------------------
324 IMPL_LINK_NOARG(MaskData
, ExecHdl
)
326 SfxBoolItem
aBItem( SID_BMPMASK_EXEC
, sal_True
);
327 rBindings
.GetDispatcher()->Execute( SID_BMPMASK_EXEC
, OWN_CALLMODE
, &aBItem
, 0L );
332 //-------------------------------------------------------------------------
334 void ColorWindow::Paint( const Rectangle
&/*Rect*/ )
336 const Color
& rOldLineColor
= GetLineColor();
337 const Color
& rOldFillColor
= GetFillColor();
339 SetLineColor( aColor
);
340 SetFillColor( aColor
);
342 DrawRect( Rectangle( Point(), GetSizePixel() ) );
344 SetLineColor( rOldLineColor
);
345 SetFillColor( rOldFillColor
);
348 //-------------------------------------------------------------------------
350 SvxBmpMaskSelectItem::SvxBmpMaskSelectItem( sal_uInt16 nId_
, SvxBmpMask
& rMask
,
351 SfxBindings
& rBindings
) :
352 SfxControllerItem ( nId_
, rBindings
),
357 //-------------------------------------------------------------------------
359 void SvxBmpMaskSelectItem::StateChanged( sal_uInt16 nSID
, SfxItemState
/*eState*/,
360 const SfxPoolItem
* pItem
)
362 if ( ( nSID
== SID_BMPMASK_EXEC
) && pItem
)
364 const SfxBoolItem
* pStateItem
= PTR_CAST( SfxBoolItem
, pItem
);
366 DBG_ASSERT( pStateItem
|| pItem
== 0, "SfxBoolItem erwartet");
368 rBmpMask
.SetExecState( pStateItem
->GetValue() );
372 //-------------------------------------------------------------------------
374 SvxBmpMaskChildWindow::SvxBmpMaskChildWindow( Window
* pParent_
, sal_uInt16 nId
,
375 SfxBindings
* pBindings
,
376 SfxChildWinInfo
* pInfo
) :
377 SfxChildWindow( pParent_
, nId
)
379 pWindow
= new SvxBmpMask( pBindings
, this, pParent_
,
380 BMP_RESID( RID_SVXDLG_BMPMASK
) );
381 SvxBmpMask
* pDlg
= (SvxBmpMask
*) pWindow
;
383 eChildAlignment
= SFX_ALIGN_NOALIGNMENT
;
385 pDlg
->Initialize( pInfo
);
388 //-------------------------------------------------------------------------
390 SvxBmpMask::SvxBmpMask( SfxBindings
*pBindinx
,
393 const ResId
& rResId
) :
394 SfxDockingWindow ( pBindinx
, pCW
, pParent
, rResId
),
395 aTbxPipette ( this, BMP_RESID( TBX_PIPETTE
) ),
396 pCtlPipette ( new ColorWindow( this, BMP_RESID( WND_PIPETTE
) ) ),
397 aBtnExec ( this, BMP_RESID( BTN_EXEC
) ),
398 aGrpQ ( this, BMP_RESID( GRP_Q
) ),
400 aFt1 ( this, BMP_RESID ( FT_1
) ),
401 aFt2 ( this, BMP_RESID ( FT_2
) ),
402 aFt3 ( this, BMP_RESID ( FT_3
) ),
404 aCbx1 ( this, BMP_RESID( CBX_1
) ),
405 pQSet1 ( new MaskSet( this, BMP_RESID( QCOL_1
) ) ),
406 aSp1 ( this, BMP_RESID( SP_1
) ),
407 aLbColor1 ( this, BMP_RESID ( LB_1
) ),
409 aCbx2 ( this, BMP_RESID( CBX_2
) ),
410 pQSet2 ( new MaskSet( this, BMP_RESID( QCOL_2
) ) ),
411 aSp2 ( this, BMP_RESID( SP_2
) ),
412 aLbColor2 ( this, BMP_RESID ( LB_2
) ),
414 aCbx3 ( this, BMP_RESID( CBX_3
) ),
415 pQSet3 ( new MaskSet( this, BMP_RESID( QCOL_3
) ) ),
416 aSp3 ( this, BMP_RESID( SP_3
) ),
417 aLbColor3 ( this, BMP_RESID ( LB_3
) ),
419 aCbx4 ( this, BMP_RESID( CBX_4
) ),
420 pQSet4 ( new MaskSet( this, BMP_RESID( QCOL_4
) ) ),
421 aSp4 ( this, BMP_RESID( SP_4
) ),
422 aLbColor4 ( this, BMP_RESID ( LB_4
) ),
424 pData ( new MaskData( this, *pBindinx
) ),
425 aCbxTrans ( this, BMP_RESID( CBX_TRANS
) ),
426 aLbColorTrans ( this, BMP_RESID ( LB_TRANS
) ),
427 aPipetteColor ( COL_WHITE
),
428 aSelItem ( SID_BMPMASK_EXEC
, *this, *pBindinx
),
429 maImgPipette ( BMP_RESID ( IMG_PIPETTE
) )
435 aTbxPipette
.SetSizePixel( aTbxPipette
.CalcWindowSizePixel() );
436 aTbxPipette
.SetSelectHdl( LINK( pData
, MaskData
, PipetteHdl
) );
437 aBtnExec
.SetClickHdl( LINK( pData
, MaskData
, ExecHdl
) );
439 aCbx1
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
440 aCbx2
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
441 aCbx3
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
442 aCbx4
.SetClickHdl( LINK( pData
, MaskData
, CbxHdl
) );
443 aCbxTrans
.SetClickHdl( LINK( pData
, MaskData
, CbxTransHdl
) );
445 SetAccessibleNames ();
447 aLbColor1
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
448 aLbColor2
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
449 aLbColor3
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
450 aLbColor4
.SetGetFocusHdl( LINK( pData
, MaskData
, FocusLbHdl
) );
451 aLbColorTrans
.Disable();
458 pQSet1
->SetStyle( pQSet1
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
459 pQSet1
->SetColCount( 1 );
460 pQSet1
->SetLineCount( 1 );
461 pQSet1
->InsertItem( 1, aPipetteColor
);
462 pQSet1
->SelectItem( 1 );
464 pQSet2
->SetStyle( pQSet2
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
465 pQSet2
->SetColCount( 1 );
466 pQSet2
->SetLineCount( 1 );
467 pQSet2
->InsertItem( 1, aPipetteColor
);
468 pQSet2
->SelectItem( 0 );
470 pQSet3
->SetStyle( pQSet3
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
471 pQSet3
->SetColCount( 1 );
472 pQSet3
->SetLineCount( 1 );
473 pQSet3
->InsertItem( 1, aPipetteColor
);
474 pQSet3
->SelectItem( 0 );
476 pQSet4
->SetStyle( pQSet4
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
477 pQSet4
->SetColCount( 1 );
478 pQSet4
->SetLineCount( 1 );
479 pQSet4
->InsertItem( 1, aPipetteColor
);
480 pQSet4
->SelectItem( 0 );
487 aCbx1
.SetAccessibleRelationMemberOf( &aGrpQ
);
488 pQSet1
->SetAccessibleRelationMemberOf( &aGrpQ
);
489 aSp1
.SetAccessibleRelationMemberOf( &aGrpQ
);
490 aLbColor1
.SetAccessibleRelationMemberOf( &aGrpQ
);
491 aCbx1
.SetAccessibleRelationLabeledBy( &aFt1
);
492 pQSet1
->SetAccessibleRelationLabeledBy( &aFt1
);
493 aSp1
.SetAccessibleRelationLabeledBy( &aFt2
);
494 aLbColor1
.SetAccessibleRelationLabeledBy( &aFt3
);
495 aCbx2
.SetAccessibleRelationMemberOf( &aGrpQ
);
496 pQSet2
->SetAccessibleRelationMemberOf( &aGrpQ
);
497 aSp2
.SetAccessibleRelationMemberOf( &aGrpQ
);
498 aLbColor2
.SetAccessibleRelationMemberOf( &aGrpQ
);
499 aCbx2
.SetAccessibleRelationLabeledBy( &aFt1
);
500 pQSet2
->SetAccessibleRelationLabeledBy( &aFt1
);
501 aSp2
.SetAccessibleRelationLabeledBy( &aFt2
);
502 aLbColor2
.SetAccessibleRelationLabeledBy( &aFt3
);
503 aCbx3
.SetAccessibleRelationMemberOf( &aGrpQ
);
504 pQSet3
->SetAccessibleRelationMemberOf( &aGrpQ
);
505 aSp3
.SetAccessibleRelationMemberOf( &aGrpQ
);
506 aLbColor3
.SetAccessibleRelationMemberOf( &aGrpQ
);
507 aCbx3
.SetAccessibleRelationLabeledBy( &aFt1
);
508 pQSet3
->SetAccessibleRelationLabeledBy( &aFt1
);
509 aSp3
.SetAccessibleRelationLabeledBy( &aFt2
);
510 aLbColor3
.SetAccessibleRelationLabeledBy( &aFt3
);
511 aCbx4
.SetAccessibleRelationMemberOf( &aGrpQ
);
512 pQSet4
->SetAccessibleRelationMemberOf( &aGrpQ
);
513 aSp4
.SetAccessibleRelationMemberOf( &aGrpQ
);
514 aLbColor4
.SetAccessibleRelationMemberOf( &aGrpQ
);
515 aCbx4
.SetAccessibleRelationLabeledBy( &aFt1
);
516 pQSet4
->SetAccessibleRelationLabeledBy( &aFt1
);
517 aSp4
.SetAccessibleRelationLabeledBy( &aFt2
);
518 aLbColor4
.SetAccessibleRelationLabeledBy( &aFt3
);
519 aLbColorTrans
.SetAccessibleRelationLabeledBy( &aCbxTrans
);
520 aLbColorTrans
.SetAccessibleRelationMemberOf( &aGrpQ
);
521 aCbxTrans
.SetAccessibleRelationMemberOf( &aGrpQ
);
524 //-------------------------------------------------------------------------
526 SvxBmpMask::~SvxBmpMask()
536 //-------------------------------------------------------------------------
538 /** is called by a MaskSet when it is selected */
539 void SvxBmpMask::onSelect( MaskSet
* pSet
)
541 // now deselect all other value sets
543 pQSet1
->SelectItem( 0 );
546 pQSet2
->SelectItem( 0 );
549 pQSet3
->SelectItem( 0 );
552 pQSet4
->SelectItem( 0 );
555 //-------------------------------------------------------------------------
557 sal_Bool
SvxBmpMask::Close()
559 SfxBoolItem
aItem2( SID_BMPMASK_PIPETTE
, sal_False
);
560 GetBindings().GetDispatcher()->Execute( SID_BMPMASK_PIPETTE
, OWN_CALLMODE
, &aItem2
, 0L );
562 return SfxDockingWindow::Close();
565 //-------------------------------------------------------------------------
567 sal_Bool
SvxBmpMask::NeedsColorList() const
569 return ( aLbColor1
.GetEntryCount() == 0 );
572 //-------------------------------------------------------------------------
574 void SvxBmpMask::SetColorList( const XColorListRef
&pList
)
576 if ( pList
.is() && ( pList
!= pColLst
) )
578 const String
aTransp( BMP_RESID( RID_SVXDLG_BMPMASK_STR_TRANSP
) );
582 aLbColorTrans
.Fill( pColLst
);
583 aLbColorTrans
.SelectEntryPos( 0 );
585 aLbColor1
.Fill( pColLst
);
586 aLbColor1
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
587 aLbColor1
.SelectEntryPos( 0 );
589 aLbColor2
.Fill( pColLst
);
590 aLbColor2
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
591 aLbColor2
.SelectEntryPos( 0 );
593 aLbColor3
.Fill( pColLst
);
594 aLbColor3
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
595 aLbColor3
.SelectEntryPos( 0 );
597 aLbColor4
.Fill( pColLst
);
598 aLbColor4
.InsertEntry( TRANSP_COL
, aTransp
, 0 );
599 aLbColor4
.SelectEntryPos( 0 );
603 //-------------------------------------------------------------------------
605 void SvxBmpMask::SetColor( const Color
& rColor
)
607 aPipetteColor
= rColor
;
608 pCtlPipette
->SetColor( aPipetteColor
);
611 //-------------------------------------------------------------------------
613 void SvxBmpMask::PipetteClicked()
615 if( pQSet1
->GetSelectItemId() == 1 )
617 aCbx1
.Check( sal_True
);
618 pData
->CbxHdl( &aCbx1
);
619 pQSet1
->SetItemColor( 1, aPipetteColor
);
621 else if( pQSet2
->GetSelectItemId() == 1 )
623 aCbx2
.Check( sal_True
);
624 pData
->CbxHdl( &aCbx2
);
625 pQSet2
->SetItemColor( 1, aPipetteColor
);
627 else if( pQSet3
->GetSelectItemId() == 1 )
629 aCbx3
.Check( sal_True
);
630 pData
->CbxHdl( &aCbx3
);
631 pQSet3
->SetItemColor( 1, aPipetteColor
);
633 else if( pQSet4
->GetSelectItemId() == 1 )
635 aCbx4
.Check( sal_True
);
636 pData
->CbxHdl( &aCbx4
);
637 pQSet4
->SetItemColor( 1, aPipetteColor
);
640 aTbxPipette
.CheckItem( TBI_PIPETTE
, sal_False
);
641 pData
->PipetteHdl( &aTbxPipette
);
644 //-------------------------------------------------------------------------
646 void SvxBmpMask::SetExecState( sal_Bool bEnable
)
648 pData
->SetExecState( bEnable
);
650 if ( pData
->IsExecReady() && pData
->IsCbxReady() )
656 //-------------------------------------------------------------------------
658 sal_uInt16
SvxBmpMask::InitColorArrays( Color
* pSrcCols
, Color
* pDstCols
, sal_uIntPtr
* pTols
)
660 sal_uInt16 nCount
= 0;
662 if ( aCbx1
.IsChecked() )
664 pSrcCols
[nCount
] = pQSet1
->GetItemColor( 1 );
665 pDstCols
[nCount
] = aLbColor1
.GetSelectEntryColor();
666 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp1
.GetValue());
669 if ( aCbx2
.IsChecked() )
671 pSrcCols
[nCount
] = pQSet2
->GetItemColor( 1 );
672 pDstCols
[nCount
] = aLbColor2
.GetSelectEntryColor();
673 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp2
.GetValue());
676 if ( aCbx3
.IsChecked() )
678 pSrcCols
[nCount
] = pQSet3
->GetItemColor( 1 );
679 pDstCols
[nCount
] = aLbColor3
.GetSelectEntryColor();
680 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp3
.GetValue());
683 if ( aCbx4
.IsChecked() )
685 pSrcCols
[nCount
] = pQSet4
->GetItemColor( 1 );
686 pDstCols
[nCount
] = aLbColor4
.GetSelectEntryColor();
687 pTols
[nCount
++] = static_cast<sal_uIntPtr
>(aSp4
.GetValue());
693 //-------------------------------------------------------------------------
695 Bitmap
SvxBmpMask::ImpMask( const Bitmap
& rBitmap
)
697 Bitmap
aBitmap( rBitmap
);
700 sal_uIntPtr pTols
[4];
701 const sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
704 aBitmap
.Replace( pSrcCols
, pDstCols
, nCount
, pTols
);
710 //-------------------------------------------------------------------------
712 BitmapEx
SvxBmpMask::ImpMaskTransparent( const BitmapEx
& rBitmapEx
, const Color
& rColor
, const long nTol
)
717 Bitmap
aMask( rBitmapEx
.GetBitmap().CreateMask( rColor
, nTol
) );
719 if( rBitmapEx
.IsTransparent() )
720 aMask
.CombineSimple( rBitmapEx
.GetMask(), BMP_COMBINE_OR
);
722 aBmpEx
= BitmapEx( rBitmapEx
.GetBitmap(), aMask
);
728 //-------------------------------------------------------------------------
730 Animation
SvxBmpMask::ImpMask( const Animation
& rAnimation
)
732 Animation
aAnimation( rAnimation
);
735 sal_uIntPtr pTols
[4];
736 InitColorArrays( pSrcCols
, pDstCols
, pTols
);
737 sal_uInt16 nAnimationCount
= aAnimation
.Count();
739 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
741 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
742 aAnimBmp
.aBmpEx
= Mask( aAnimBmp
.aBmpEx
).GetBitmapEx();
743 aAnimation
.Replace( aAnimBmp
, i
);
749 //-------------------------------------------------------------------------
751 GDIMetaFile
SvxBmpMask::ImpMask( const GDIMetaFile
& rMtf
)
756 sal_uIntPtr pTols
[4];
757 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
760 // If no color is selected, we copy only the Mtf
771 long* pMinR
= new long[nCount
];
772 long* pMaxR
= new long[nCount
];
773 long* pMinG
= new long[nCount
];
774 long* pMaxG
= new long[nCount
];
775 long* pMinB
= new long[nCount
];
776 long* pMaxB
= new long[nCount
];
780 aMtf
.SetPrefSize( rMtf
.GetPrefSize() );
781 aMtf
.SetPrefMapMode( rMtf
.GetPrefMapMode() );
783 // Prepare Color comparison array
784 for( i
= 0; i
< nCount
; i
++ )
786 nTol
= ( pTols
[i
] * 255L ) / 100L;
788 nVal
= ( (long) pSrcCols
[i
].GetRed() );
789 pMinR
[i
] = std::max( nVal
- nTol
, 0L );
790 pMaxR
[i
] = std::min( nVal
+ nTol
, 255L );
792 nVal
= ( (long) pSrcCols
[i
].GetGreen() );
793 pMinG
[i
] = std::max( nVal
- nTol
, 0L );
794 pMaxG
[i
] = std::min( nVal
+ nTol
, 255L );
796 nVal
= ( (long) pSrcCols
[i
].GetBlue() );
797 pMinB
[i
] = std::max( nVal
- nTol
, 0L );
798 pMaxB
[i
] = std::min( nVal
+ nTol
, 255L );
800 pTrans
[ i
] = ( pDstCols
[ i
] == TRANSP_COL
);
803 // Investigate actions and if necessary replace colors
804 for( size_t nAct
= 0, nActCount
= rMtf
.GetActionSize(); nAct
< nActCount
; nAct
++ )
806 MetaAction
* pAction
= rMtf
.GetAction( nAct
);
808 bReplace
= sal_False
;
810 switch( pAction
->GetType() )
812 case( META_PIXEL_ACTION
):
814 MetaPixelAction
* pAct
= (MetaPixelAction
*) pAction
;
816 aCol
= pAct
->GetColor();
820 pAct
= new MetaPixelAction( pAct
->GetPoint(), aCol
);
824 aMtf
.AddAction( pAct
);
828 case( META_LINECOLOR_ACTION
):
830 MetaLineColorAction
* pAct
= (MetaLineColorAction
*) pAction
;
832 aCol
= pAct
->GetColor();
836 pAct
= new MetaLineColorAction( aCol
, !pTrans
[ i
] );
840 aMtf
.AddAction( pAct
);
844 case( META_FILLCOLOR_ACTION
):
846 MetaFillColorAction
* pAct
= (MetaFillColorAction
*) pAction
;
848 aCol
= pAct
->GetColor();
852 pAct
= new MetaFillColorAction( aCol
, !pTrans
[ i
] );
856 aMtf
.AddAction( pAct
);
860 case( META_TEXTCOLOR_ACTION
):
862 MetaTextColorAction
* pAct
= (MetaTextColorAction
*) pAction
;
864 aCol
= pAct
->GetColor();
868 pAct
= new MetaTextColorAction( aCol
);
872 aMtf
.AddAction( pAct
);
876 case( META_TEXTFILLCOLOR_ACTION
):
878 MetaTextFillColorAction
* pAct
= (MetaTextFillColorAction
*) pAction
;
880 aCol
= pAct
->GetColor();
884 pAct
= new MetaTextFillColorAction( aCol
, !pTrans
[ i
] );
888 aMtf
.AddAction( pAct
);
892 case( META_FONT_ACTION
):
894 MetaFontAction
* pAct
= (MetaFontAction
*) pAction
;
895 Font
aFont( pAct
->GetFont() );
897 aCol
= aFont
.GetColor();
902 aFont
.SetColor( aCol
);
903 pAct
= new MetaFontAction( aFont
);
908 aMtf
.AddAction( pAct
);
912 case( META_WALLPAPER_ACTION
):
914 MetaWallpaperAction
* pAct
= (MetaWallpaperAction
*) pAction
;
915 Wallpaper
aWall( pAct
->GetWallpaper() );
917 aCol
= aWall
.GetColor();
922 aWall
.SetColor( aCol
);
923 pAct
= new MetaWallpaperAction( pAct
->GetRect(), aWall
);
928 aMtf
.AddAction( pAct
);
932 case( META_BMP_ACTION
):
934 MetaBmpAction
* pAct
= (MetaBmpAction
*) pAction
;
935 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
937 pAct
= new MetaBmpAction( pAct
->GetPoint(), aBmp
);
938 aMtf
.AddAction( pAct
);
942 case( META_BMPSCALE_ACTION
):
944 MetaBmpScaleAction
* pAct
= (MetaBmpScaleAction
*) pAction
;
945 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
947 pAct
= new MetaBmpScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmp
);
948 aMtf
.AddAction( pAct
);
952 case( META_BMPSCALEPART_ACTION
):
954 MetaBmpScalePartAction
* pAct
= (MetaBmpScalePartAction
*) pAction
;
955 const Bitmap
aBmp( Mask( pAct
->GetBitmap() ).GetBitmap() );
957 pAct
= new MetaBmpScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
958 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmp
);
959 aMtf
.AddAction( pAct
);
963 case( META_BMPEX_ACTION
):
965 MetaBmpExAction
* pAct
= (MetaBmpExAction
*) pAction
;
966 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
968 pAct
= new MetaBmpExAction( pAct
->GetPoint(), aBmpEx
);
969 aMtf
.AddAction( pAct
);
973 case( META_BMPEXSCALE_ACTION
):
975 MetaBmpExScaleAction
* pAct
= (MetaBmpExScaleAction
*) pAction
;
976 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
978 pAct
= new MetaBmpExScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmpEx
);
979 aMtf
.AddAction( pAct
);
983 case( META_BMPEXSCALEPART_ACTION
):
985 MetaBmpExScalePartAction
* pAct
= (MetaBmpExScalePartAction
*) pAction
;
986 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
988 pAct
= new MetaBmpExScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
989 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmpEx
);
990 aMtf
.AddAction( pAct
);
996 pAction
->Duplicate();
997 aMtf
.AddAction( pAction
);
1016 //-------------------------------------------------------------------------
1018 BitmapEx
SvxBmpMask::ImpReplaceTransparency( const BitmapEx
& rBmpEx
, const Color
& rColor
)
1020 if( rBmpEx
.IsTransparent() )
1022 Bitmap
aBmp( rBmpEx
.GetBitmap() );
1023 aBmp
.Replace( rBmpEx
.GetMask(), rColor
);
1030 //-------------------------------------------------------------------------
1032 Animation
SvxBmpMask::ImpReplaceTransparency( const Animation
& rAnim
, const Color
& rColor
)
1034 Animation
aAnimation( rAnim
);
1035 sal_uInt16 nAnimationCount
= aAnimation
.Count();
1037 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
1039 AnimationBitmap
aAnimBmp( aAnimation
.Get( i
) );
1040 aAnimBmp
.aBmpEx
= ImpReplaceTransparency( aAnimBmp
.aBmpEx
, rColor
);
1041 aAnimation
.Replace( aAnimBmp
, i
);
1047 //-------------------------------------------------------------------------
1049 GDIMetaFile
SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile
& rMtf
, const Color
& rColor
)
1051 VirtualDevice aVDev
;
1053 const MapMode
& rPrefMap
= rMtf
.GetPrefMapMode();
1054 const Size
& rPrefSize
= rMtf
.GetPrefSize();
1055 const size_t nActionCount
= rMtf
.GetActionSize();
1057 aVDev
.EnableOutput( sal_False
);
1058 aMtf
.Record( &aVDev
);
1059 aMtf
.SetPrefSize( rPrefSize
);
1060 aMtf
.SetPrefMapMode( rPrefMap
);
1061 aVDev
.SetLineColor( rColor
);
1062 aVDev
.SetFillColor( rColor
);
1064 // retrieve one action at the time; first
1065 // set the whole area to the replacement color.
1066 aVDev
.DrawRect( Rectangle( rPrefMap
.GetOrigin(), rPrefSize
) );
1067 for ( size_t i
= 0; i
< nActionCount
; i
++ )
1069 MetaAction
* pAct
= rMtf
.GetAction( i
);
1072 aMtf
.AddAction( pAct
);
1081 //-------------------------------------------------------------------------
1083 Graphic
SvxBmpMask::Mask( const Graphic
& rGraphic
)
1085 Graphic
aGraphic( rGraphic
);
1086 const Color
aReplColor( aLbColorTrans
.GetSelectEntryColor() );
1088 switch( rGraphic
.GetType() )
1090 case( GRAPHIC_BITMAP
):
1092 if( rGraphic
.IsAnimated() )
1094 // Replace transparency?
1095 if ( aCbxTrans
.IsChecked() )
1096 aGraphic
= ImpReplaceTransparency( rGraphic
.GetAnimation(), aReplColor
);
1098 aGraphic
= ImpMask( rGraphic
.GetAnimation() );
1102 // Replace transparency?
1103 if( aCbxTrans
.IsChecked() )
1105 if( aGraphic
.IsTransparent() )
1107 BitmapEx
aBmpEx( ImpReplaceTransparency( aGraphic
.GetBitmapEx(), aReplColor
) );
1108 const Size
aSize( aBmpEx
.GetSizePixel() );
1110 if( aSize
.Width() && aSize
.Height() )
1118 sal_uIntPtr pTols
[4];
1119 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
1123 // first set all transparent colors
1124 for( sal_uInt16 i
= 0; i
< nCount
; i
++ )
1126 // Do we have a transparent color?
1127 if( pDstCols
[i
] == TRANSP_COL
)
1129 BitmapEx
aBmpEx( ImpMaskTransparent( aGraphic
.GetBitmapEx(),
1130 pSrcCols
[ i
], pTols
[ i
] ) );
1131 const Size
aSize( aBmpEx
.GetSizePixel() );
1133 if( aSize
.Width() && aSize
.Height() )
1138 // now replace it again with the normal colors
1139 Bitmap
aBitmap( ImpMask( aGraphic
.GetBitmap() ) );
1140 Size
aSize( aBitmap
.GetSizePixel() );
1142 if ( aSize
.Width() && aSize
.Height() )
1144 if ( aGraphic
.IsTransparent() )
1145 aGraphic
= Graphic( BitmapEx( aBitmap
, aGraphic
.GetBitmapEx().GetMask() ) );
1155 case( GRAPHIC_GDIMETAFILE
):
1157 GDIMetaFile
aMtf( aGraphic
.GetGDIMetaFile() );
1159 // Replace transparency?
1160 if( aCbxTrans
.IsChecked() )
1161 aMtf
= ImpReplaceTransparency( aMtf
, aReplColor
);
1163 aMtf
= ImpMask( aMtf
);
1165 Size
aSize( aMtf
.GetPrefSize() );
1166 if ( aSize
.Width() && aSize
.Height() )
1167 aGraphic
= Graphic( aMtf
);
1169 aGraphic
= rGraphic
;
1174 aGraphic
= rGraphic
;
1178 if( aGraphic
!= rGraphic
)
1180 aGraphic
.SetPrefSize( rGraphic
.GetPrefSize() );
1181 aGraphic
.SetPrefMapMode( rGraphic
.GetPrefMapMode() );
1187 //-------------------------------------------------------------------------
1189 sal_Bool
SvxBmpMask::IsEyedropping() const
1191 return aTbxPipette
.IsItemChecked( TBI_PIPETTE
);
1194 void SvxBmpMask::DataChanged( const DataChangedEvent
& rDCEvt
)
1196 SfxDockingWindow::DataChanged( rDCEvt
);
1198 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
1202 void SvxBmpMask::ApplyStyle()
1204 aTbxPipette
.SetItemImage( TBI_PIPETTE
, maImgPipette
);
1208 /** Set an accessible name for the source color check boxes. Without this
1209 the lengthy description is read.
1211 void SvxBmpMask::SetAccessibleNames (void)
1213 String
sSourceColor (BMP_RESID( RID_SVXDLG_BMPMASK_STR_SOURCECOLOR
));
1214 String sSourceColorN
;
1216 sSourceColorN
= sSourceColor
;
1217 sSourceColorN
.AppendAscii (" 1");
1218 aCbx1
.SetAccessibleName (sSourceColorN
);
1220 sSourceColorN
= sSourceColor
;
1221 sSourceColorN
.AppendAscii (" 2");
1222 aCbx2
.SetAccessibleName (sSourceColorN
);
1224 sSourceColorN
= sSourceColor
;
1225 sSourceColorN
.AppendAscii (" 3");
1226 aCbx3
.SetAccessibleName (sSourceColorN
);
1228 sSourceColorN
= sSourceColor
;
1229 sSourceColorN
.AppendAscii (" 4");
1230 aCbx4
.SetAccessibleName (sSourceColorN
);
1233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */