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