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