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