1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/event.hxx>
21 #include <vcl/metaact.hxx>
22 #include <vcl/virdev.hxx>
23 #include <svtools/valueset.hxx>
24 #include <svl/eitem.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <svtools/colrdlg.hxx>
28 #include <svx/colorbox.hxx>
29 #include <svx/dialmgr.hxx>
30 #include <svx/bmpmask.hxx>
31 #include <svx/strings.hrc>
32 #include <svx/svxids.hrc>
36 #define OWN_CALLMODE SfxCallMode::ASYNCHRON | SfxCallMode::RECORD
41 nR = aCol.GetRed(); nG = aCol.GetGreen(); nB = aCol.GetBlue(); \
42 for( i = 0; i < nCount; i++ ) \
44 if ( ( pMinR[i] <= nR ) && ( pMaxR[i] >= nR ) && \
45 ( pMinG[i] <= nG ) && ( pMaxG[i] >= nG ) && \
46 ( pMinB[i] <= nB ) && ( pMaxB[i] >= nB ) ) \
48 aCol = pDstCols[i]; bReplace = true; break; \
53 SFX_IMPL_DOCKINGWINDOW_WITHID( SvxBmpMaskChildWindow
, SID_BMPMASK
)
55 class BmpColorWindow
: public weld::CustomWidgetController
61 explicit BmpColorWindow()
66 void SetColor( const Color
& rColor
)
72 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
74 virtual void SetDrawingArea(weld::DrawingArea
* pArea
) override
76 Size
aSize(pArea
->get_ref_device().LogicToPixel(Size(43, 14), MapMode(MapUnit::MapAppFont
)));
77 CustomWidgetController::SetDrawingArea(pArea
);
78 pArea
->set_size_request(aSize
.Width(), aSize
.Height());
79 SetOutputSizePixel(aSize
);
83 class MaskSet
: public ValueSet
85 VclPtr
<SvxBmpMask
> pSvxBmpMask
;
88 MaskSet(SvxBmpMask
* pMask
);
89 virtual void Select() override
;
90 virtual bool KeyInput( const KeyEvent
& rKEvt
) override
;
91 virtual void GetFocus() override
;
92 virtual void SetDrawingArea(weld::DrawingArea
* pArea
) override
94 Size
aSize(pArea
->get_ref_device().LogicToPixel(Size(24, 12), MapMode(MapUnit::MapAppFont
)));
95 ValueSet::SetDrawingArea(pArea
);
96 pArea
->set_size_request(aSize
.Width(), aSize
.Height());
97 SetOutputSizePixel(aSize
);
98 SetHelpId(HID_BMPMASK_CTL_QCOL_1
);
103 MaskSet::MaskSet(SvxBmpMask
* pMask
)
109 void MaskSet::Select()
113 pSvxBmpMask
->onSelect( this );
116 void MaskSet::GetFocus()
118 ValueSet::GetFocus();
120 pSvxBmpMask
->onSelect( this );
123 bool MaskSet::KeyInput( const KeyEvent
& rKEvt
)
127 vcl::KeyCode aCode
= rKEvt
.GetKeyCode();
129 // if the key has a modifier we don't care
130 if( aCode
.GetModifier() )
132 bRet
= ValueSet::KeyInput( rKEvt
);
136 // check for keys that interests us
137 switch ( aCode
.GetCode() )
144 bRet
= ValueSet::KeyInput( rKEvt
);
150 void MaskSet::onEditColor()
152 SvColorDialog aColorDlg
;
154 aColorDlg
.SetColor(GetItemColor(1));
156 if (aColorDlg
.Execute(pSvxBmpMask
->GetFrameWeld()))
157 SetItemColor(1, aColorDlg
.GetColor());
162 VclPtr
<SvxBmpMask
> pMask
;
165 SfxBindings
& rBindings
;
168 MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
);
170 bool IsCbxReady() const { return bIsReady
; }
171 void SetExecState( bool bState
) { bExecState
= bState
; }
172 bool IsExecReady() const { return bExecState
; }
174 DECL_LINK( PipetteHdl
, const OUString
&, void );
175 DECL_LINK( CbxHdl
, weld::Toggleable
&, void);
176 DECL_LINK( CbxTransHdl
, weld::Toggleable
&, void );
177 DECL_LINK( FocusLbHdl
, weld::Widget
&, void );
178 DECL_LINK(ExecHdl
, weld::Button
&, void);
182 MaskData::MaskData( SvxBmpMask
* pBmpMask
, SfxBindings
& rBind
) :
186 bExecState ( false ),
192 IMPL_LINK( MaskData
, PipetteHdl
, const OUString
&, rId
, void )
194 SfxBoolItem
aBItem( SID_BMPMASK_PIPETTE
,
195 pMask
->m_xTbxPipette
->get_item_active(rId
) );
197 rBindings
.GetDispatcher()->ExecuteList(SID_BMPMASK_PIPETTE
, OWN_CALLMODE
,
201 IMPL_LINK( MaskData
, CbxHdl
, weld::Toggleable
&, rCbx
, void )
203 bIsReady
= pMask
->m_xCbx1
->get_active() || pMask
->m_xCbx2
->get_active() ||
204 pMask
->m_xCbx3
->get_active() || pMask
->m_xCbx4
->get_active();
206 if ( bIsReady
&& IsExecReady() )
207 pMask
->m_xBtnExec
->set_sensitive(true);
209 pMask
->m_xBtnExec
->set_sensitive(false);
211 // When a checkbox is checked, the pipette is enabled
212 if ( !rCbx
.get_active() )
215 MaskSet
* pSet
= nullptr;
217 if (&rCbx
== pMask
->m_xCbx1
.get())
218 pSet
= pMask
->m_xQSet1
.get();
219 else if (&rCbx
== pMask
->m_xCbx2
.get())
220 pSet
= pMask
->m_xQSet2
.get();
221 else if (&rCbx
== pMask
->m_xCbx3
.get())
222 pSet
= pMask
->m_xQSet3
.get();
223 else // if ( &rCbx == pMask->m_xCbx4 )
224 pSet
= pMask
->m_xQSet4
.get();
226 pSet
->SelectItem( 1 );
229 pMask
->m_xTbxPipette
->set_item_active("pipette", true);
230 PipetteHdl("pipette");
233 IMPL_LINK( MaskData
, CbxTransHdl
, weld::Toggleable
&, rCbx
, void )
235 bIsReady
= rCbx
.get_active();
238 pMask
->m_xQSet1
->Disable();
239 pMask
->m_xQSet2
->Disable();
240 pMask
->m_xQSet3
->Disable();
241 pMask
->m_xQSet4
->Disable();
242 pMask
->m_xCtlPipette
->Disable();
243 pMask
->m_xCbx1
->set_sensitive(false);
244 pMask
->m_xSp1
->set_sensitive(false);
245 pMask
->m_xCbx2
->set_sensitive(false);
246 pMask
->m_xSp2
->set_sensitive(false);
247 pMask
->m_xCbx3
->set_sensitive(false);
248 pMask
->m_xSp3
->set_sensitive(false);
249 pMask
->m_xCbx4
->set_sensitive(false);
250 pMask
->m_xSp4
->set_sensitive(false);
251 pMask
->m_xTbxPipette
->set_sensitive(false);
253 pMask
->m_xLbColor1
->set_sensitive(false);
254 pMask
->m_xLbColor2
->set_sensitive(false);
255 pMask
->m_xLbColor3
->set_sensitive(false);
256 pMask
->m_xLbColor4
->set_sensitive(false);
257 pMask
->m_xLbColorTrans
->set_sensitive(true);
261 pMask
->m_xQSet1
->Enable();
262 pMask
->m_xQSet2
->Enable();
263 pMask
->m_xQSet3
->Enable();
264 pMask
->m_xQSet4
->Enable();
265 pMask
->m_xCtlPipette
->Enable();
266 pMask
->m_xCbx1
->set_sensitive(true);
267 pMask
->m_xSp1
->set_sensitive(true);
268 pMask
->m_xCbx2
->set_sensitive(true);
269 pMask
->m_xSp2
->set_sensitive(true);
270 pMask
->m_xCbx3
->set_sensitive(true);
271 pMask
->m_xSp3
->set_sensitive(true);
272 pMask
->m_xCbx4
->set_sensitive(true);
273 pMask
->m_xSp4
->set_sensitive(true);
274 pMask
->m_xTbxPipette
->set_sensitive(true);
276 pMask
->m_xLbColor1
->set_sensitive(true);
277 pMask
->m_xLbColor2
->set_sensitive(true);
278 pMask
->m_xLbColor3
->set_sensitive(true);
279 pMask
->m_xLbColor4
->set_sensitive(true);
280 pMask
->m_xLbColorTrans
->set_sensitive(false);
282 bIsReady
= pMask
->m_xCbx1
->get_active() || pMask
->m_xCbx2
->get_active() ||
283 pMask
->m_xCbx3
->get_active() || pMask
->m_xCbx4
->get_active();
286 if ( bIsReady
&& IsExecReady() )
287 pMask
->m_xBtnExec
->set_sensitive(true);
289 pMask
->m_xBtnExec
->set_sensitive(false);
292 IMPL_LINK( MaskData
, FocusLbHdl
, weld::Widget
&, rLb
, void )
294 pMask
->m_xQSet1
->SelectItem( &rLb
== &pMask
->m_xLbColor1
->get_widget() ? 1 : 0 /* , false */ );
295 pMask
->m_xQSet2
->SelectItem( &rLb
== &pMask
->m_xLbColor2
->get_widget() ? 1 : 0 /* , false */ );
296 pMask
->m_xQSet3
->SelectItem( &rLb
== &pMask
->m_xLbColor3
->get_widget() ? 1 : 0 /* , false */ );
297 pMask
->m_xQSet4
->SelectItem( &rLb
== &pMask
->m_xLbColor4
->get_widget() ? 1 : 0 /* , false */ );
300 IMPL_LINK_NOARG(MaskData
, ExecHdl
, weld::Button
&, void)
302 SfxBoolItem
aBItem( SID_BMPMASK_EXEC
, true );
303 rBindings
.GetDispatcher()->ExecuteList(SID_BMPMASK_EXEC
, OWN_CALLMODE
,
307 void BmpColorWindow::Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*Rect*/)
309 rRenderContext
.Push(vcl::PushFlags::LINECOLOR
| vcl::PushFlags::FILLCOLOR
);
310 rRenderContext
.SetLineColor(aColor
);
311 rRenderContext
.SetFillColor(aColor
);
312 rRenderContext
.DrawRect(tools::Rectangle(Point(), GetOutputSizePixel()));
313 rRenderContext
.Pop();
316 SvxBmpMaskSelectItem::SvxBmpMaskSelectItem( SvxBmpMask
& rMask
,
317 SfxBindings
& rBindings
) :
318 SfxControllerItem ( SID_BMPMASK_EXEC
, rBindings
),
323 void SvxBmpMaskSelectItem::StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState
/*eState*/,
324 const SfxPoolItem
* pItem
)
326 if ( ( nSID
== SID_BMPMASK_EXEC
) && pItem
)
328 const SfxBoolItem
* pStateItem
= dynamic_cast<const SfxBoolItem
*>( pItem
);
329 assert(pStateItem
); // SfxBoolItem expected
331 rBmpMask
.SetExecState( pStateItem
->GetValue() );
335 SvxBmpMaskChildWindow::SvxBmpMaskChildWindow(vcl::Window
* pParent_
, sal_uInt16 nId
,
336 SfxBindings
* pBindings
,
337 SfxChildWinInfo
* pInfo
)
338 : SfxChildWindow(pParent_
, nId
)
340 VclPtr
<SvxBmpMask
> pDlg
= VclPtr
<SvxBmpMask
>::Create(pBindings
, this, pParent_
);
344 pDlg
->Initialize( pInfo
);
347 SvxBmpMask::SvxBmpMask(SfxBindings
*pBindinx
, SfxChildWindow
*pCW
, vcl::Window
* pParent
)
348 : SfxDockingWindow(pBindinx
, pCW
, pParent
, "DockingColorReplace",
349 "svx/ui/dockingcolorreplace.ui")
350 , m_xTbxPipette(m_xBuilder
->weld_toolbar("toolbar"))
351 , m_xCtlPipette(new BmpColorWindow
)
352 , m_xCtlPipetteWin(new weld::CustomWeld(*m_xBuilder
, "toolcolor", *m_xCtlPipette
))
353 , m_xBtnExec(m_xBuilder
->weld_button("replace"))
354 , m_xCbx1(m_xBuilder
->weld_check_button("cbx1"))
355 , m_xQSet1(new MaskSet(this))
356 , m_xQSetWin1(new weld::CustomWeld(*m_xBuilder
, "qset1", *m_xQSet1
))
357 , m_xSp1(m_xBuilder
->weld_metric_spin_button("tol1", FieldUnit::PERCENT
))
358 , m_xLbColor1(new ColorListBox(m_xBuilder
->weld_menu_button("color1"), [this]{ return GetFrameWeld(); }))
359 , m_xCbx2(m_xBuilder
->weld_check_button("cbx2"))
360 , m_xQSet2(new MaskSet(this))
361 , m_xQSetWin2(new weld::CustomWeld(*m_xBuilder
, "qset2", *m_xQSet2
))
362 , m_xSp2(m_xBuilder
->weld_metric_spin_button("tol2", FieldUnit::PERCENT
))
363 , m_xLbColor2(new ColorListBox(m_xBuilder
->weld_menu_button("color2"), [this]{ return GetFrameWeld(); }))
364 , m_xCbx3(m_xBuilder
->weld_check_button("cbx3"))
365 , m_xQSet3(new MaskSet(this))
366 , m_xQSetWin3(new weld::CustomWeld(*m_xBuilder
, "qset3", *m_xQSet3
))
367 , m_xSp3(m_xBuilder
->weld_metric_spin_button("tol3", FieldUnit::PERCENT
))
368 , m_xLbColor3(new ColorListBox(m_xBuilder
->weld_menu_button("color3"), [this]{ return GetFrameWeld(); }))
369 , m_xCbx4(m_xBuilder
->weld_check_button("cbx4"))
370 , m_xQSet4(new MaskSet(this))
371 , m_xQSetWin4(new weld::CustomWeld(*m_xBuilder
, "qset4", *m_xQSet4
))
372 , m_xSp4(m_xBuilder
->weld_metric_spin_button("tol4", FieldUnit::PERCENT
))
373 , m_xLbColor4(new ColorListBox(m_xBuilder
->weld_menu_button("color4"), [this]{ return GetFrameWeld(); }))
374 , m_xCbxTrans(m_xBuilder
->weld_check_button("cbx5"))
375 , m_xLbColorTrans(new ColorListBox(m_xBuilder
->weld_menu_button("color5"), [this]{ return GetFrameWeld(); }))
376 , m_xData(new MaskData(this, *pBindinx
))
377 , aPipetteColor(COL_WHITE
)
378 , aSelItem(*this, *pBindinx
)
380 SetText(SvxResId(RID_SVXDLG_BMPMASK_STR_TITLE
));
382 m_xLbColor1
->SetSlotId(SID_BMPMASK_COLOR
);
383 m_xLbColor2
->SetSlotId(SID_BMPMASK_COLOR
);
384 m_xLbColor3
->SetSlotId(SID_BMPMASK_COLOR
);
385 m_xLbColor4
->SetSlotId(SID_BMPMASK_COLOR
);
387 m_xLbColorTrans
->SelectEntry(COL_BLACK
);
388 m_xLbColor1
->SelectEntry(COL_TRANSPARENT
);
389 m_xLbColor2
->SelectEntry(COL_TRANSPARENT
);
390 m_xLbColor3
->SelectEntry(COL_TRANSPARENT
);
391 m_xLbColor4
->SelectEntry(COL_TRANSPARENT
);
393 m_xTbxPipette
->connect_clicked( LINK( m_xData
.get(), MaskData
, PipetteHdl
) );
394 m_xBtnExec
->connect_clicked( LINK( m_xData
.get(), MaskData
, ExecHdl
) );
396 m_xCbx1
->connect_toggled( LINK( m_xData
.get(), MaskData
, CbxHdl
) );
397 m_xCbx2
->connect_toggled( LINK( m_xData
.get(), MaskData
, CbxHdl
) );
398 m_xCbx3
->connect_toggled( LINK( m_xData
.get(), MaskData
, CbxHdl
) );
399 m_xCbx4
->connect_toggled( LINK( m_xData
.get(), MaskData
, CbxHdl
) );
400 m_xCbxTrans
->connect_toggled( LINK( m_xData
.get(), MaskData
, CbxTransHdl
) );
402 SetAccessibleNames ();
404 m_xLbColor1
->connect_focus_in( LINK( m_xData
.get(), MaskData
, FocusLbHdl
) );
405 m_xLbColor2
->connect_focus_in( LINK( m_xData
.get(), MaskData
, FocusLbHdl
) );
406 m_xLbColor3
->connect_focus_in( LINK( m_xData
.get(), MaskData
, FocusLbHdl
) );
407 m_xLbColor4
->connect_focus_in( LINK( m_xData
.get(), MaskData
, FocusLbHdl
) );
408 m_xLbColorTrans
->set_sensitive(false);
410 OUString
sColorPalette (SvxResId( RID_SVXDLG_BMPMASK_STR_PALETTE
));
411 OUString sColorPaletteN
;
413 m_xQSet1
->SetStyle( m_xQSet1
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
414 m_xQSet1
->SetColCount();
415 m_xQSet1
->SetLineCount( 1 );
416 sColorPaletteN
= sColorPalette
+ " 1";
417 m_xQSet1
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
418 m_xQSet1
->SelectItem( 1 );
420 m_xQSet2
->SetStyle( m_xQSet2
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
421 m_xQSet2
->SetColCount();
422 m_xQSet2
->SetLineCount( 1 );
423 sColorPaletteN
= sColorPalette
+ " 2";
424 m_xQSet2
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
425 m_xQSet2
->SelectItem( 0 );
427 m_xQSet3
->SetStyle( m_xQSet3
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
428 m_xQSet3
->SetColCount();
429 m_xQSet3
->SetLineCount( 1 );
430 sColorPaletteN
= sColorPalette
+ " 3";
431 m_xQSet3
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
432 m_xQSet3
->SelectItem( 0 );
434 m_xQSet4
->SetStyle( m_xQSet4
->GetStyle() | WB_DOUBLEBORDER
| WB_ITEMBORDER
);
435 m_xQSet4
->SetColCount();
436 m_xQSet4
->SetLineCount( 1 );
437 sColorPaletteN
= sColorPalette
+ " 4";
438 m_xQSet4
->InsertItem( 1, aPipetteColor
, sColorPaletteN
);
439 m_xQSet4
->SelectItem( 0 );
447 SvxBmpMask::~SvxBmpMask()
452 void SvxBmpMask::dispose()
462 m_xCtlPipetteWin
.reset();
463 m_xCtlPipette
.reset();
465 m_xTbxPipette
.reset();
480 m_xLbColorTrans
.reset();
482 SfxDockingWindow::dispose();
485 /** is called by a MaskSet when it is selected */
486 void SvxBmpMask::onSelect( const MaskSet
* pSet
)
488 // now deselect all other value sets
489 if( pSet
!= m_xQSet1
.get() )
490 m_xQSet1
->SelectItem( 0 );
492 if( pSet
!= m_xQSet2
.get() )
493 m_xQSet2
->SelectItem( 0 );
495 if( pSet
!= m_xQSet3
.get() )
496 m_xQSet3
->SelectItem( 0 );
498 if( pSet
!= m_xQSet4
.get() )
499 m_xQSet4
->SelectItem( 0 );
502 bool SvxBmpMask::Close()
504 SfxBoolItem
aItem2( SID_BMPMASK_PIPETTE
, false );
505 GetBindings().GetDispatcher()->ExecuteList(SID_BMPMASK_PIPETTE
,
506 OWN_CALLMODE
, { &aItem2
});
508 return SfxDockingWindow::Close();
511 void SvxBmpMask::SetColor( const Color
& rColor
)
513 aPipetteColor
= rColor
;
514 m_xCtlPipette
->SetColor( aPipetteColor
);
517 void SvxBmpMask::PipetteClicked()
519 if( m_xQSet1
->GetSelectedItemId() == 1 )
521 m_xCbx1
->set_active(true);
522 m_xData
->CbxHdl(*m_xCbx1
);
523 m_xQSet1
->SetItemColor( 1, aPipetteColor
);
524 m_xQSet1
->SetFormat();
526 else if( m_xQSet2
->GetSelectedItemId() == 1 )
528 m_xCbx2
->set_active(true);
529 m_xData
->CbxHdl(*m_xCbx2
);
530 m_xQSet2
->SetItemColor( 1, aPipetteColor
);
531 m_xQSet2
->SetFormat();
533 else if( m_xQSet3
->GetSelectedItemId() == 1 )
535 m_xCbx3
->set_active(true);
536 m_xData
->CbxHdl(*m_xCbx3
);
537 m_xQSet3
->SetItemColor( 1, aPipetteColor
);
538 m_xQSet3
->SetFormat();
540 else if( m_xQSet4
->GetSelectedItemId() == 1 )
542 m_xCbx4
->set_active(true);
543 m_xData
->CbxHdl(*m_xCbx4
);
544 m_xQSet4
->SetItemColor( 1, aPipetteColor
);
545 m_xQSet4
->SetFormat();
548 m_xTbxPipette
->set_item_active("pipette", false);
549 m_xData
->PipetteHdl("pipette");
552 void SvxBmpMask::SetExecState( bool bEnable
)
554 m_xData
->SetExecState( bEnable
);
556 if ( m_xData
->IsExecReady() && m_xData
->IsCbxReady() )
557 m_xBtnExec
->set_sensitive(true);
559 m_xBtnExec
->set_sensitive(false);
563 sal_uInt16
SvxBmpMask::InitColorArrays( Color
* pSrcCols
, Color
* pDstCols
, sal_uInt8
* pTols
)
565 sal_uInt16 nCount
= 0;
567 if ( m_xCbx1
->get_active() )
569 pSrcCols
[nCount
] = m_xQSet1
->GetItemColor( 1 );
570 pDstCols
[nCount
] = m_xLbColor1
->GetSelectEntryColor();
571 pTols
[nCount
++] = static_cast<sal_uInt8
>(m_xSp1
->get_value(FieldUnit::PERCENT
));
574 if ( m_xCbx2
->get_active() )
576 pSrcCols
[nCount
] = m_xQSet2
->GetItemColor( 1 );
577 pDstCols
[nCount
] = m_xLbColor2
->GetSelectEntryColor();
578 pTols
[nCount
++] = static_cast<sal_uInt8
>(m_xSp2
->get_value(FieldUnit::PERCENT
));
581 if ( m_xCbx3
->get_active() )
583 pSrcCols
[nCount
] = m_xQSet3
->GetItemColor( 1 );
584 pDstCols
[nCount
] = m_xLbColor3
->GetSelectEntryColor();
585 pTols
[nCount
++] = static_cast<sal_uInt8
>(m_xSp3
->get_value(FieldUnit::PERCENT
));
588 if ( m_xCbx4
->get_active() )
590 pSrcCols
[nCount
] = m_xQSet4
->GetItemColor( 1 );
591 pDstCols
[nCount
] = m_xLbColor4
->GetSelectEntryColor();
592 pTols
[nCount
++] = static_cast<sal_uInt8
>(m_xSp4
->get_value(FieldUnit::PERCENT
));
598 void SvxBmpMask::ImpMask( BitmapEx
& rBitmap
)
603 const sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
606 rBitmap
.Replace( pSrcCols
, pDstCols
, nCount
, pTols
);
610 BitmapEx
SvxBmpMask::ImpMaskTransparent( const BitmapEx
& rBitmapEx
, const Color
& rColor
, const sal_uInt8 nTol
)
615 Bitmap
aMask( rBitmapEx
.GetBitmap().CreateMask( rColor
, nTol
) );
617 if( rBitmapEx
.IsAlpha() )
618 aMask
.CombineOr( rBitmapEx
.GetAlphaMask() );
620 aBmpEx
= BitmapEx( rBitmapEx
.GetBitmap(), aMask
);
627 Animation
SvxBmpMask::ImpMask( const Animation
& rAnimation
)
629 Animation
aAnimation( rAnimation
);
633 InitColorArrays( pSrcCols
, pDstCols
, pTols
);
634 sal_uInt16 nAnimationCount
= aAnimation
.Count();
636 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
638 AnimationFrame
aAnimationFrame( aAnimation
.Get( i
) );
639 aAnimationFrame
.maBitmapEx
= Mask(aAnimationFrame
.maBitmapEx
).GetBitmapEx();
640 aAnimation
.Replace(aAnimationFrame
, i
);
647 GDIMetaFile
SvxBmpMask::ImpMask( const GDIMetaFile
& rMtf
)
653 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
655 // If no color is selected, we copy only the Mtf
665 std::unique_ptr
<tools::Long
[]> pMinR(new tools::Long
[nCount
]);
666 std::unique_ptr
<tools::Long
[]> pMaxR(new tools::Long
[nCount
]);
667 std::unique_ptr
<tools::Long
[]> pMinG(new tools::Long
[nCount
]);
668 std::unique_ptr
<tools::Long
[]> pMaxG(new tools::Long
[nCount
]);
669 std::unique_ptr
<tools::Long
[]> pMinB(new tools::Long
[nCount
]);
670 std::unique_ptr
<tools::Long
[]> pMaxB(new tools::Long
[nCount
]);
673 aMtf
.SetPrefSize( rMtf
.GetPrefSize() );
674 aMtf
.SetPrefMapMode( rMtf
.GetPrefMapMode() );
676 // Prepare Color comparison array
677 for( i
= 0; i
< nCount
; i
++ )
679 tools::Long nTol
= ( pTols
[i
] * 255 ) / 100;
681 tools::Long nVal
= static_cast<tools::Long
>(pSrcCols
[i
].GetRed());
682 pMinR
[i
] = std::max( nVal
- nTol
, tools::Long(0) );
683 pMaxR
[i
] = std::min( nVal
+ nTol
, tools::Long(255) );
685 nVal
= static_cast<tools::Long
>(pSrcCols
[i
].GetGreen());
686 pMinG
[i
] = std::max( nVal
- nTol
, tools::Long(0) );
687 pMaxG
[i
] = std::min( nVal
+ nTol
, tools::Long(255) );
689 nVal
= static_cast<tools::Long
>(pSrcCols
[i
].GetBlue());
690 pMinB
[i
] = std::max( nVal
- nTol
, tools::Long(0) );
691 pMaxB
[i
] = std::min( nVal
+ nTol
, tools::Long(255) );
693 pTrans
[ i
] = (pDstCols
[ i
] == COL_TRANSPARENT
);
696 // Investigate actions and if necessary replace colors
697 for( size_t nAct
= 0, nActCount
= rMtf
.GetActionSize(); nAct
< nActCount
; nAct
++ )
699 MetaAction
* pAction
= rMtf
.GetAction( nAct
);
701 bool bReplace
= false;
703 switch( pAction
->GetType() )
705 case MetaActionType::PIXEL
:
707 MetaPixelAction
* pAct
= static_cast<MetaPixelAction
*>(pAction
);
709 aCol
= pAct
->GetColor();
713 pAct
= new MetaPixelAction( pAct
->GetPoint(), aCol
);
715 aMtf
.AddAction( pAct
);
719 case MetaActionType::LINECOLOR
:
721 MetaLineColorAction
* pAct
= static_cast<MetaLineColorAction
*>(pAction
);
723 aCol
= pAct
->GetColor();
727 pAct
= new MetaLineColorAction( aCol
, !pTrans
[ i
] );
729 aMtf
.AddAction( pAct
);
733 case MetaActionType::FILLCOLOR
:
735 MetaFillColorAction
* pAct
= static_cast<MetaFillColorAction
*>(pAction
);
737 aCol
= pAct
->GetColor();
741 pAct
= new MetaFillColorAction( aCol
, !pTrans
[ i
] );
743 aMtf
.AddAction( pAct
);
747 case MetaActionType::TEXTCOLOR
:
749 MetaTextColorAction
* pAct
= static_cast<MetaTextColorAction
*>(pAction
);
751 aCol
= pAct
->GetColor();
755 pAct
= new MetaTextColorAction( aCol
);
757 aMtf
.AddAction( pAct
);
761 case MetaActionType::TEXTFILLCOLOR
:
763 MetaTextFillColorAction
* pAct
= static_cast<MetaTextFillColorAction
*>(pAction
);
765 aCol
= pAct
->GetColor();
769 pAct
= new MetaTextFillColorAction( aCol
, !pTrans
[ i
] );
771 aMtf
.AddAction( pAct
);
775 case MetaActionType::FONT
:
777 MetaFontAction
* pAct
= static_cast<MetaFontAction
*>(pAction
);
778 vcl::Font
aFont( pAct
->GetFont() );
780 aCol
= aFont
.GetColor();
785 aFont
.SetColor( aCol
);
786 pAct
= new MetaFontAction( std::move(aFont
) );
789 aMtf
.AddAction( pAct
);
793 case MetaActionType::WALLPAPER
:
795 MetaWallpaperAction
* pAct
= static_cast<MetaWallpaperAction
*>(pAction
);
796 Wallpaper
aWall( pAct
->GetWallpaper() );
798 aCol
= aWall
.GetColor();
803 aWall
.SetColor( aCol
);
804 pAct
= new MetaWallpaperAction( pAct
->GetRect(), std::move(aWall
) );
807 aMtf
.AddAction( pAct
);
811 case MetaActionType::BMP
:
813 MetaBmpAction
* pAct
= static_cast<MetaBmpAction
*>(pAction
);
814 const Bitmap
aBmp( Mask(BitmapEx(pAct
->GetBitmap())).GetBitmapEx().GetBitmap() );
816 pAct
= new MetaBmpAction( pAct
->GetPoint(), aBmp
);
817 aMtf
.AddAction( pAct
);
821 case MetaActionType::BMPSCALE
:
823 MetaBmpScaleAction
* pAct
= static_cast<MetaBmpScaleAction
*>(pAction
);
824 const Bitmap
aBmp( Mask(BitmapEx(pAct
->GetBitmap())).GetBitmapEx().GetBitmap() );
826 pAct
= new MetaBmpScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmp
);
827 aMtf
.AddAction( pAct
);
831 case MetaActionType::BMPSCALEPART
:
833 MetaBmpScalePartAction
* pAct
= static_cast<MetaBmpScalePartAction
*>(pAction
);
834 const Bitmap
aBmp( Mask(BitmapEx(pAct
->GetBitmap())).GetBitmapEx().GetBitmap() );
836 pAct
= new MetaBmpScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
837 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmp
);
838 aMtf
.AddAction( pAct
);
842 case MetaActionType::BMPEX
:
844 MetaBmpExAction
* pAct
= static_cast<MetaBmpExAction
*>(pAction
);
845 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
847 pAct
= new MetaBmpExAction( pAct
->GetPoint(), aBmpEx
);
848 aMtf
.AddAction( pAct
);
852 case MetaActionType::BMPEXSCALE
:
854 MetaBmpExScaleAction
* pAct
= static_cast<MetaBmpExScaleAction
*>(pAction
);
855 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
857 pAct
= new MetaBmpExScaleAction( pAct
->GetPoint(), pAct
->GetSize(), aBmpEx
);
858 aMtf
.AddAction( pAct
);
862 case MetaActionType::BMPEXSCALEPART
:
864 MetaBmpExScalePartAction
* pAct
= static_cast<MetaBmpExScalePartAction
*>(pAction
);
865 const BitmapEx
aBmpEx( Mask( pAct
->GetBitmapEx() ).GetBitmapEx() );
867 pAct
= new MetaBmpExScalePartAction( pAct
->GetDestPoint(), pAct
->GetDestSize(),
868 pAct
->GetSrcPoint(), pAct
->GetSrcSize(), aBmpEx
);
869 aMtf
.AddAction( pAct
);
875 aMtf
.AddAction( pAction
);
888 Animation
SvxBmpMask::ImpReplaceTransparency( const Animation
& rAnim
, const Color
& rColor
)
890 Animation
aAnimation( rAnim
);
891 sal_uInt16 nAnimationCount
= aAnimation
.Count();
893 for( sal_uInt16 i
= 0; i
< nAnimationCount
; i
++ )
895 AnimationFrame
aAnimationFrame(aAnimation
.Get(i
));
896 aAnimationFrame
.maBitmapEx
.ReplaceTransparency(rColor
);
897 aAnimation
.Replace(aAnimationFrame
, i
);
904 GDIMetaFile
SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile
& rMtf
, const Color
& rColor
)
906 ScopedVclPtrInstance
< VirtualDevice
> pVDev
;
908 const MapMode
& rPrefMap
= rMtf
.GetPrefMapMode();
909 const Size
& rPrefSize
= rMtf
.GetPrefSize();
910 const size_t nActionCount
= rMtf
.GetActionSize();
912 pVDev
->EnableOutput( false );
913 aMtf
.Record( pVDev
);
914 aMtf
.SetPrefSize( rPrefSize
);
915 aMtf
.SetPrefMapMode( rPrefMap
);
916 pVDev
->SetLineColor( rColor
);
917 pVDev
->SetFillColor( rColor
);
919 // retrieve one action at the time; first
920 // set the whole area to the replacement color.
921 pVDev
->DrawRect( tools::Rectangle( rPrefMap
.GetOrigin(), rPrefSize
) );
922 for ( size_t i
= 0; i
< nActionCount
; i
++ )
924 MetaAction
* pAct
= rMtf
.GetAction( i
);
925 aMtf
.AddAction( pAct
);
934 GDIMetaFile
SvxBmpMask::GetMetaFile(const Graphic
& rGraphic
)
936 // Replace transparency?
937 if (m_xCbxTrans
->get_active())
938 return ImpReplaceTransparency(rGraphic
.GetGDIMetaFile(), m_xLbColorTrans
->GetSelectEntryColor());
939 return ImpMask(rGraphic
.GetGDIMetaFile());
942 Graphic
SvxBmpMask::Mask( const Graphic
& rGraphic
)
944 Graphic
aGraphic( rGraphic
);
945 const Color
aReplColor( m_xLbColorTrans
->GetSelectEntryColor() );
947 switch( rGraphic
.GetType() )
949 case GraphicType::Bitmap
:
951 if( rGraphic
.IsAnimated() )
953 // Replace transparency?
954 if ( m_xCbxTrans
->get_active() )
955 aGraphic
= ImpReplaceTransparency( rGraphic
.GetAnimation(), aReplColor
);
957 aGraphic
= ImpMask( rGraphic
.GetAnimation() );
961 // Replace transparency?
962 if( m_xCbxTrans
->get_active() )
964 BitmapEx aBmpEx
= aGraphic
.GetBitmapEx();
965 aBmpEx
.ReplaceTransparency(aReplColor
);
973 sal_uInt16 nCount
= InitColorArrays( pSrcCols
, pDstCols
, pTols
);
977 // first set all transparent colors
978 for( sal_uInt16 i
= 0; i
< nCount
; i
++ )
980 // Do we have a transparent color?
981 if (pDstCols
[i
] == COL_TRANSPARENT
)
983 BitmapEx
aBmpEx( ImpMaskTransparent( aGraphic
.GetBitmapEx(),
984 pSrcCols
[ i
], pTols
[ i
] ) );
985 const Size
aSize( aBmpEx
.GetSizePixel() );
987 if( aSize
.Width() && aSize
.Height() )
992 // now replace it again with the normal colors
993 BitmapEx
aBitmapEx( aGraphic
.GetBitmapEx() );
994 if ( aBitmapEx
.GetSizePixel().Width() && aBitmapEx
.GetSizePixel().Height() )
996 ImpMask( aBitmapEx
);
997 if ( aGraphic
.IsTransparent() )
998 aGraphic
= Graphic( BitmapEx( aBitmapEx
.GetBitmap(), aBitmapEx
.GetAlphaMask() ) );
1000 aGraphic
= aBitmapEx
;
1008 case GraphicType::GdiMetafile
:
1010 GDIMetaFile
aMtf(GetMetaFile(rGraphic
));
1011 Size
aSize( aMtf
.GetPrefSize() );
1012 if ( aSize
.Width() && aSize
.Height() )
1013 aGraphic
= Graphic( aMtf
);
1015 aGraphic
= rGraphic
;
1020 aGraphic
= rGraphic
;
1024 if( aGraphic
!= rGraphic
)
1026 aGraphic
.SetPrefSize( rGraphic
.GetPrefSize() );
1027 aGraphic
.SetPrefMapMode( rGraphic
.GetPrefMapMode() );
1033 bool SvxBmpMask::IsEyedropping() const
1035 return m_xTbxPipette
->get_item_active("pipette");
1038 /** Set an accessible name for the source color check boxes. Without this
1039 the lengthy description is read.
1041 void SvxBmpMask::SetAccessibleNames()
1043 // set the accessible name for valueset
1044 OUString
sColorPalette (SvxResId( RID_SVXDLG_BMPMASK_STR_PALETTE
));
1045 OUString sColorPaletteN
;
1047 sColorPaletteN
= sColorPalette
+ " 1";
1048 m_xQSet1
->SetText (sColorPaletteN
);
1049 sColorPaletteN
= sColorPalette
+ " 2";
1050 m_xQSet2
->SetText (sColorPaletteN
);
1051 sColorPaletteN
= sColorPalette
+ " 3";
1052 m_xQSet3
->SetText (sColorPaletteN
);
1053 sColorPaletteN
= sColorPalette
+ " 4";
1054 m_xQSet4
->SetText (sColorPaletteN
);
1057 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */