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