/src/libreoffice/svx/source/dialog/_bmpmask.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <vcl/ColorDialog.hxx> |
21 | | #include <vcl/alpha.hxx> |
22 | | #include <vcl/event.hxx> |
23 | | #include <vcl/metaact.hxx> |
24 | | #include <vcl/virdev.hxx> |
25 | | #include <svtools/valueset.hxx> |
26 | | #include <svl/eitem.hxx> |
27 | | #include <svl/itemset.hxx> |
28 | | #include <sfx2/dispatch.hxx> |
29 | | |
30 | | #include <svx/colorbox.hxx> |
31 | | #include <svx/dialmgr.hxx> |
32 | | #include <svx/bmpmask.hxx> |
33 | | #include <svx/strings.hrc> |
34 | | #include <svx/svxids.hrc> |
35 | | #include <memory> |
36 | | #include <helpids.h> |
37 | | |
38 | 0 | #define OWN_CALLMODE SfxCallMode::ASYNCHRON | SfxCallMode::RECORD |
39 | | |
40 | | |
41 | 0 | #define TEST_COLS() \ |
42 | 0 | { \ |
43 | 0 | nR = aCol.GetRed(); nG = aCol.GetGreen(); nB = aCol.GetBlue(); \ |
44 | 0 | for( i = 0; i < nCount; i++ ) \ |
45 | 0 | { \ |
46 | 0 | if ( ( pMinR[i] <= nR ) && ( pMaxR[i] >= nR ) && \ |
47 | 0 | ( pMinG[i] <= nG ) && ( pMaxG[i] >= nG ) && \ |
48 | 0 | ( pMinB[i] <= nB ) && ( pMaxB[i] >= nB ) ) \ |
49 | 0 | { \ |
50 | 0 | aCol = pDstCols[i]; bReplace = true; break; \ |
51 | 0 | } \ |
52 | 0 | } \ |
53 | 0 | } |
54 | | |
55 | | SFX_IMPL_DOCKINGWINDOW_WITHID( SvxBmpMaskChildWindow, SID_BMPMASK ) |
56 | | |
57 | | class BmpColorWindow : public weld::CustomWidgetController |
58 | | { |
59 | | Color aColor; |
60 | | |
61 | | |
62 | | public: |
63 | | explicit BmpColorWindow() |
64 | 0 | : aColor( COL_WHITE ) |
65 | 0 | { |
66 | 0 | } |
67 | | |
68 | | void SetColor( const Color& rColor ) |
69 | 0 | { |
70 | 0 | aColor = rColor; |
71 | 0 | Invalidate(); |
72 | 0 | } |
73 | | |
74 | | virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; |
75 | | |
76 | | virtual void SetDrawingArea(weld::DrawingArea* pArea) override |
77 | 0 | { |
78 | 0 | Size aSize(pArea->get_ref_device().LogicToPixel(Size(43, 14), MapMode(MapUnit::MapAppFont))); |
79 | 0 | CustomWidgetController::SetDrawingArea(pArea); |
80 | 0 | pArea->set_size_request(aSize.Width(), aSize.Height()); |
81 | 0 | SetOutputSizePixel(aSize); |
82 | 0 | } |
83 | | }; |
84 | | |
85 | | class MaskSet : public ValueSet |
86 | | { |
87 | | VclPtr<SvxBmpMask> pSvxBmpMask; |
88 | | |
89 | | public: |
90 | | MaskSet(SvxBmpMask* pMask); |
91 | | virtual void Select() override; |
92 | | virtual bool KeyInput( const KeyEvent& rKEvt ) override; |
93 | | virtual void GetFocus() override; |
94 | | virtual void SetDrawingArea(weld::DrawingArea* pArea) override |
95 | 0 | { |
96 | 0 | Size aSize(pArea->get_ref_device().LogicToPixel(Size(24, 12), MapMode(MapUnit::MapAppFont))); |
97 | 0 | ValueSet::SetDrawingArea(pArea); |
98 | 0 | pArea->set_size_request(aSize.Width(), aSize.Height()); |
99 | 0 | SetOutputSizePixel(aSize); |
100 | 0 | SetHelpId(HID_BMPMASK_CTL_QCOL_1); |
101 | 0 | } |
102 | | void onEditColor(); |
103 | | }; |
104 | | |
105 | | MaskSet::MaskSet(SvxBmpMask* pMask) |
106 | 0 | : ValueSet(nullptr) |
107 | 0 | , pSvxBmpMask(pMask) |
108 | 0 | { |
109 | 0 | } |
110 | | |
111 | | void MaskSet::Select() |
112 | 0 | { |
113 | 0 | ValueSet::Select(); |
114 | |
|
115 | 0 | pSvxBmpMask->onSelect( this ); |
116 | 0 | } |
117 | | |
118 | | void MaskSet::GetFocus() |
119 | 0 | { |
120 | 0 | ValueSet::GetFocus(); |
121 | 0 | SelectItem( 1 ); |
122 | 0 | pSvxBmpMask->onSelect( this ); |
123 | 0 | } |
124 | | |
125 | | bool MaskSet::KeyInput( const KeyEvent& rKEvt ) |
126 | 0 | { |
127 | 0 | bool bRet = false; |
128 | |
|
129 | 0 | vcl::KeyCode aCode = rKEvt.GetKeyCode(); |
130 | | |
131 | | // if the key has a modifier we don't care |
132 | 0 | if( aCode.GetModifier() ) |
133 | 0 | { |
134 | 0 | bRet = ValueSet::KeyInput( rKEvt ); |
135 | 0 | } |
136 | 0 | else |
137 | 0 | { |
138 | | // check for keys that interests us |
139 | 0 | switch ( aCode.GetCode() ) |
140 | 0 | { |
141 | 0 | case KEY_SPACE: |
142 | 0 | onEditColor(); |
143 | 0 | bRet = true; |
144 | 0 | break; |
145 | 0 | default: |
146 | 0 | bRet = ValueSet::KeyInput( rKEvt ); |
147 | 0 | } |
148 | 0 | } |
149 | 0 | return bRet; |
150 | 0 | } |
151 | | |
152 | | void MaskSet::onEditColor() |
153 | 0 | { |
154 | 0 | ColorDialog aColorDlg(pSvxBmpMask->GetFrameWeld()); |
155 | |
|
156 | 0 | aColorDlg.SetColor(GetItemColor(1)); |
157 | |
|
158 | 0 | if (aColorDlg.Execute()) |
159 | 0 | SetItemColor(1, aColorDlg.GetColor()); |
160 | 0 | } |
161 | | |
162 | | class MaskData |
163 | | { |
164 | | VclPtr<SvxBmpMask> pMask; |
165 | | bool bIsReady; |
166 | | bool bExecState; |
167 | | SfxBindings& rBindings; |
168 | | |
169 | | public: |
170 | | MaskData( SvxBmpMask* pBmpMask, SfxBindings& rBind ); |
171 | | |
172 | 0 | bool IsCbxReady() const { return bIsReady; } |
173 | 0 | void SetExecState( bool bState ) { bExecState = bState; } |
174 | 0 | bool IsExecReady() const { return bExecState; } |
175 | | |
176 | | DECL_LINK( PipetteHdl, const OUString&, void ); |
177 | | DECL_LINK( CbxHdl, weld::Toggleable&, void); |
178 | | DECL_LINK( CbxTransHdl, weld::Toggleable&, void ); |
179 | | DECL_LINK( FocusLbHdl, weld::Widget&, void ); |
180 | | DECL_LINK(ExecHdl, weld::Button&, void); |
181 | | }; |
182 | | |
183 | | |
184 | | MaskData::MaskData( SvxBmpMask* pBmpMask, SfxBindings& rBind ) : |
185 | | |
186 | 0 | pMask ( pBmpMask ), |
187 | 0 | bIsReady ( false ), |
188 | 0 | bExecState ( false ), |
189 | 0 | rBindings ( rBind ) |
190 | | |
191 | 0 | { |
192 | 0 | } |
193 | | |
194 | | IMPL_LINK( MaskData, PipetteHdl, const OUString&, rId, void ) |
195 | 0 | { |
196 | 0 | SfxBoolItem aBItem( SID_BMPMASK_PIPETTE, |
197 | 0 | pMask->m_xTbxPipette->get_item_active(rId) ); |
198 | |
|
199 | 0 | rBindings.GetDispatcher()->ExecuteList(SID_BMPMASK_PIPETTE, OWN_CALLMODE, |
200 | 0 | { &aBItem }); |
201 | 0 | } |
202 | | |
203 | | IMPL_LINK( MaskData, CbxHdl, weld::Toggleable&, rCbx, void ) |
204 | 0 | { |
205 | 0 | bIsReady = pMask->m_xCbx1->get_active() || pMask->m_xCbx2->get_active() || |
206 | 0 | pMask->m_xCbx3->get_active() || pMask->m_xCbx4->get_active(); |
207 | |
|
208 | 0 | if ( bIsReady && IsExecReady() ) |
209 | 0 | pMask->m_xBtnExec->set_sensitive(true); |
210 | 0 | else |
211 | 0 | pMask->m_xBtnExec->set_sensitive(false); |
212 | | |
213 | | // When a checkbox is checked, the pipette is enabled |
214 | 0 | if ( !rCbx.get_active() ) |
215 | 0 | return; |
216 | | |
217 | 0 | MaskSet* pSet = nullptr; |
218 | |
|
219 | 0 | if (&rCbx == pMask->m_xCbx1.get()) |
220 | 0 | pSet = pMask->m_xQSet1.get(); |
221 | 0 | else if (&rCbx == pMask->m_xCbx2.get()) |
222 | 0 | pSet = pMask->m_xQSet2.get(); |
223 | 0 | else if (&rCbx == pMask->m_xCbx3.get()) |
224 | 0 | pSet = pMask->m_xQSet3.get(); |
225 | 0 | else // if ( &rCbx == pMask->m_xCbx4 ) |
226 | 0 | pSet = pMask->m_xQSet4.get(); |
227 | |
|
228 | 0 | pSet->SelectItem( 1 ); |
229 | 0 | pSet->Select(); |
230 | |
|
231 | 0 | pMask->m_xTbxPipette->set_item_active(u"pipette"_ustr, true); |
232 | 0 | PipetteHdl(u"pipette"_ustr); |
233 | 0 | } |
234 | | |
235 | | IMPL_LINK( MaskData, CbxTransHdl, weld::Toggleable&, rCbx, void ) |
236 | 0 | { |
237 | 0 | bIsReady = rCbx.get_active(); |
238 | 0 | if ( bIsReady ) |
239 | 0 | { |
240 | 0 | pMask->m_xQSet1->Disable(); |
241 | 0 | pMask->m_xQSet2->Disable(); |
242 | 0 | pMask->m_xQSet3->Disable(); |
243 | 0 | pMask->m_xQSet4->Disable(); |
244 | 0 | pMask->m_xCtlPipette->Disable(); |
245 | 0 | pMask->m_xCbx1->set_sensitive(false); |
246 | 0 | pMask->m_xSp1->set_sensitive(false); |
247 | 0 | pMask->m_xCbx2->set_sensitive(false); |
248 | 0 | pMask->m_xSp2->set_sensitive(false); |
249 | 0 | pMask->m_xCbx3->set_sensitive(false); |
250 | 0 | pMask->m_xSp3->set_sensitive(false); |
251 | 0 | pMask->m_xCbx4->set_sensitive(false); |
252 | 0 | pMask->m_xSp4->set_sensitive(false); |
253 | 0 | pMask->m_xTbxPipette->set_sensitive(false); |
254 | |
|
255 | 0 | pMask->m_xLbColor1->set_sensitive(false); |
256 | 0 | pMask->m_xLbColor2->set_sensitive(false); |
257 | 0 | pMask->m_xLbColor3->set_sensitive(false); |
258 | 0 | pMask->m_xLbColor4->set_sensitive(false); |
259 | 0 | pMask->m_xLbColorTrans->set_sensitive(true); |
260 | 0 | } |
261 | 0 | else |
262 | 0 | { |
263 | 0 | pMask->m_xQSet1->Enable(); |
264 | 0 | pMask->m_xQSet2->Enable(); |
265 | 0 | pMask->m_xQSet3->Enable(); |
266 | 0 | pMask->m_xQSet4->Enable(); |
267 | 0 | pMask->m_xCtlPipette->Enable(); |
268 | 0 | pMask->m_xCbx1->set_sensitive(true); |
269 | 0 | pMask->m_xSp1->set_sensitive(true); |
270 | 0 | pMask->m_xCbx2->set_sensitive(true); |
271 | 0 | pMask->m_xSp2->set_sensitive(true); |
272 | 0 | pMask->m_xCbx3->set_sensitive(true); |
273 | 0 | pMask->m_xSp3->set_sensitive(true); |
274 | 0 | pMask->m_xCbx4->set_sensitive(true); |
275 | 0 | pMask->m_xSp4->set_sensitive(true); |
276 | 0 | pMask->m_xTbxPipette->set_sensitive(true); |
277 | |
|
278 | 0 | pMask->m_xLbColor1->set_sensitive(true); |
279 | 0 | pMask->m_xLbColor2->set_sensitive(true); |
280 | 0 | pMask->m_xLbColor3->set_sensitive(true); |
281 | 0 | pMask->m_xLbColor4->set_sensitive(true); |
282 | 0 | pMask->m_xLbColorTrans->set_sensitive(false); |
283 | |
|
284 | 0 | bIsReady = pMask->m_xCbx1->get_active() || pMask->m_xCbx2->get_active() || |
285 | 0 | pMask->m_xCbx3->get_active() || pMask->m_xCbx4->get_active(); |
286 | 0 | } |
287 | |
|
288 | 0 | if ( bIsReady && IsExecReady() ) |
289 | 0 | pMask->m_xBtnExec->set_sensitive(true); |
290 | 0 | else |
291 | 0 | pMask->m_xBtnExec->set_sensitive(false); |
292 | 0 | } |
293 | | |
294 | | IMPL_LINK( MaskData, FocusLbHdl, weld::Widget&, rLb, void ) |
295 | 0 | { |
296 | 0 | pMask->m_xQSet1->SelectItem( &rLb == &pMask->m_xLbColor1->get_widget() ? 1 : 0 /* , false */ ); |
297 | 0 | pMask->m_xQSet2->SelectItem( &rLb == &pMask->m_xLbColor2->get_widget() ? 1 : 0 /* , false */ ); |
298 | 0 | pMask->m_xQSet3->SelectItem( &rLb == &pMask->m_xLbColor3->get_widget() ? 1 : 0 /* , false */ ); |
299 | 0 | pMask->m_xQSet4->SelectItem( &rLb == &pMask->m_xLbColor4->get_widget() ? 1 : 0 /* , false */ ); |
300 | 0 | } |
301 | | |
302 | | IMPL_LINK_NOARG(MaskData, ExecHdl, weld::Button&, void) |
303 | 0 | { |
304 | 0 | SfxBoolItem aBItem( SID_BMPMASK_EXEC, true ); |
305 | 0 | rBindings.GetDispatcher()->ExecuteList(SID_BMPMASK_EXEC, OWN_CALLMODE, |
306 | 0 | { &aBItem }); |
307 | 0 | } |
308 | | |
309 | | void BmpColorWindow::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& /*Rect*/) |
310 | 0 | { |
311 | 0 | auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR); |
312 | 0 | rRenderContext.SetLineColor(aColor); |
313 | 0 | rRenderContext.SetFillColor(aColor); |
314 | 0 | rRenderContext.DrawRect(tools::Rectangle(Point(), GetOutputSizePixel())); |
315 | 0 | } |
316 | | |
317 | | SvxBmpMaskSelectItem::SvxBmpMaskSelectItem( SvxBmpMask& rMask, |
318 | | SfxBindings& rBindings ) : |
319 | 0 | SfxControllerItem ( SID_BMPMASK_EXEC, rBindings ), |
320 | 0 | m_rBmpMask ( rMask) |
321 | 0 | { |
322 | 0 | } |
323 | | |
324 | | void SvxBmpMaskSelectItem::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState /*eState*/, |
325 | | const SfxPoolItem* pItem ) |
326 | 0 | { |
327 | 0 | if ( ( nSID == SID_BMPMASK_EXEC ) && pItem ) |
328 | 0 | { |
329 | 0 | const SfxBoolItem* pStateItem = dynamic_cast<const SfxBoolItem*>( pItem ); |
330 | 0 | assert(pStateItem); // SfxBoolItem expected |
331 | 0 | if (pStateItem) |
332 | 0 | m_rBmpMask.SetExecState( pStateItem->GetValue() ); |
333 | 0 | } |
334 | 0 | } |
335 | | |
336 | | SvxBmpMaskChildWindow::SvxBmpMaskChildWindow(vcl::Window* pParent_, sal_uInt16 nId, |
337 | | SfxBindings* pBindings, |
338 | | SfxChildWinInfo* pInfo) |
339 | 0 | : SfxChildWindow(pParent_, nId) |
340 | 0 | { |
341 | 0 | VclPtr<SvxBmpMask> pDlg = VclPtr<SvxBmpMask>::Create(pBindings, this, pParent_); |
342 | |
|
343 | 0 | SetWindow( pDlg ); |
344 | |
|
345 | 0 | pDlg->Initialize( pInfo ); |
346 | 0 | } |
347 | | |
348 | | SvxBmpMask::SvxBmpMask(SfxBindings *pBindinx, SfxChildWindow *pCW, vcl::Window* pParent) |
349 | 0 | : SfxDockingWindow(pBindinx, pCW, pParent, u"DockingColorReplace"_ustr, |
350 | 0 | u"svx/ui/dockingcolorreplace.ui"_ustr) |
351 | 0 | , m_xTbxPipette(m_xBuilder->weld_toolbar(u"toolbar"_ustr)) |
352 | 0 | , m_xCtlPipette(new BmpColorWindow) |
353 | 0 | , m_xCtlPipetteWin(new weld::CustomWeld(*m_xBuilder, u"toolcolor"_ustr, *m_xCtlPipette)) |
354 | 0 | , m_xBtnExec(m_xBuilder->weld_button(u"replace"_ustr)) |
355 | 0 | , m_xCbx1(m_xBuilder->weld_check_button(u"cbx1"_ustr)) |
356 | 0 | , m_xQSet1(new MaskSet(this)) |
357 | 0 | , m_xQSetWin1(new weld::CustomWeld(*m_xBuilder, u"qset1"_ustr, *m_xQSet1)) |
358 | 0 | , m_xSp1(m_xBuilder->weld_metric_spin_button(u"tol1"_ustr, FieldUnit::PERCENT)) |
359 | 0 | , m_xLbColor1(new ColorListBox(m_xBuilder->weld_menu_button(u"color1"_ustr), [this]{ return GetFrameWeld(); })) |
360 | 0 | , m_xCbx2(m_xBuilder->weld_check_button(u"cbx2"_ustr)) |
361 | 0 | , m_xQSet2(new MaskSet(this)) |
362 | 0 | , m_xQSetWin2(new weld::CustomWeld(*m_xBuilder, u"qset2"_ustr, *m_xQSet2)) |
363 | 0 | , m_xSp2(m_xBuilder->weld_metric_spin_button(u"tol2"_ustr, FieldUnit::PERCENT)) |
364 | 0 | , m_xLbColor2(new ColorListBox(m_xBuilder->weld_menu_button(u"color2"_ustr), [this]{ return GetFrameWeld(); })) |
365 | 0 | , m_xCbx3(m_xBuilder->weld_check_button(u"cbx3"_ustr)) |
366 | 0 | , m_xQSet3(new MaskSet(this)) |
367 | 0 | , m_xQSetWin3(new weld::CustomWeld(*m_xBuilder, u"qset3"_ustr, *m_xQSet3)) |
368 | 0 | , m_xSp3(m_xBuilder->weld_metric_spin_button(u"tol3"_ustr, FieldUnit::PERCENT)) |
369 | 0 | , m_xLbColor3(new ColorListBox(m_xBuilder->weld_menu_button(u"color3"_ustr), [this]{ return GetFrameWeld(); })) |
370 | 0 | , m_xCbx4(m_xBuilder->weld_check_button(u"cbx4"_ustr)) |
371 | 0 | , m_xQSet4(new MaskSet(this)) |
372 | 0 | , m_xQSetWin4(new weld::CustomWeld(*m_xBuilder, u"qset4"_ustr, *m_xQSet4)) |
373 | 0 | , m_xSp4(m_xBuilder->weld_metric_spin_button(u"tol4"_ustr, FieldUnit::PERCENT)) |
374 | 0 | , m_xLbColor4(new ColorListBox(m_xBuilder->weld_menu_button(u"color4"_ustr), [this]{ return GetFrameWeld(); })) |
375 | 0 | , m_xCbxTrans(m_xBuilder->weld_check_button(u"cbx5"_ustr)) |
376 | 0 | , m_xLbColorTrans(new ColorListBox(m_xBuilder->weld_menu_button(u"color5"_ustr), [this]{ return GetFrameWeld(); })) |
377 | 0 | , m_xData(new MaskData(this, *pBindinx)) |
378 | 0 | , m_aPipetteColor(COL_WHITE) |
379 | 0 | , m_aSelItem(*this, *pBindinx) |
380 | 0 | { |
381 | 0 | SetText(SvxResId(RID_SVXDLG_BMPMASK_STR_TITLE)); |
382 | |
|
383 | 0 | m_xLbColor1->SetSlotId(SID_BMPMASK_COLOR); |
384 | 0 | m_xLbColor2->SetSlotId(SID_BMPMASK_COLOR); |
385 | 0 | m_xLbColor3->SetSlotId(SID_BMPMASK_COLOR); |
386 | 0 | m_xLbColor4->SetSlotId(SID_BMPMASK_COLOR); |
387 | |
|
388 | 0 | m_xLbColorTrans->SelectEntry(COL_BLACK); |
389 | 0 | m_xLbColor1->SelectEntry(COL_TRANSPARENT); |
390 | 0 | m_xLbColor2->SelectEntry(COL_TRANSPARENT); |
391 | 0 | m_xLbColor3->SelectEntry(COL_TRANSPARENT); |
392 | 0 | m_xLbColor4->SelectEntry(COL_TRANSPARENT); |
393 | |
|
394 | 0 | m_xTbxPipette->connect_clicked( LINK( m_xData.get(), MaskData, PipetteHdl ) ); |
395 | 0 | m_xBtnExec->connect_clicked( LINK( m_xData.get(), MaskData, ExecHdl ) ); |
396 | |
|
397 | 0 | m_xCbx1->connect_toggled( LINK( m_xData.get(), MaskData, CbxHdl ) ); |
398 | 0 | m_xCbx2->connect_toggled( LINK( m_xData.get(), MaskData, CbxHdl ) ); |
399 | 0 | m_xCbx3->connect_toggled( LINK( m_xData.get(), MaskData, CbxHdl ) ); |
400 | 0 | m_xCbx4->connect_toggled( LINK( m_xData.get(), MaskData, CbxHdl ) ); |
401 | 0 | m_xCbxTrans->connect_toggled( LINK( m_xData.get(), MaskData, CbxTransHdl ) ); |
402 | |
|
403 | 0 | SetAccessibleNames (); |
404 | |
|
405 | 0 | m_xLbColor1->connect_focus_in( LINK( m_xData.get(), MaskData, FocusLbHdl ) ); |
406 | 0 | m_xLbColor2->connect_focus_in( LINK( m_xData.get(), MaskData, FocusLbHdl ) ); |
407 | 0 | m_xLbColor3->connect_focus_in( LINK( m_xData.get(), MaskData, FocusLbHdl ) ); |
408 | 0 | m_xLbColor4->connect_focus_in( LINK( m_xData.get(), MaskData, FocusLbHdl ) ); |
409 | 0 | m_xLbColorTrans->set_sensitive(false); |
410 | |
|
411 | 0 | OUString sColorPalette (SvxResId( RID_SVXDLG_BMPMASK_STR_PALETTE)); |
412 | 0 | OUString sColorPaletteN; |
413 | |
|
414 | 0 | m_xQSet1->SetStyle( m_xQSet1->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER ); |
415 | 0 | m_xQSet1->SetColCount(); |
416 | 0 | m_xQSet1->SetLineCount( 1 ); |
417 | 0 | sColorPaletteN = sColorPalette + " 1"; |
418 | 0 | m_xQSet1->InsertItem( 1, m_aPipetteColor, sColorPaletteN); |
419 | 0 | m_xQSet1->SelectItem( 1 ); |
420 | |
|
421 | 0 | m_xQSet2->SetStyle( m_xQSet2->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER ); |
422 | 0 | m_xQSet2->SetColCount(); |
423 | 0 | m_xQSet2->SetLineCount( 1 ); |
424 | 0 | sColorPaletteN = sColorPalette + " 2"; |
425 | 0 | m_xQSet2->InsertItem( 1, m_aPipetteColor, sColorPaletteN); |
426 | 0 | m_xQSet2->SelectItem( 0 ); |
427 | |
|
428 | 0 | m_xQSet3->SetStyle( m_xQSet3->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER ); |
429 | 0 | m_xQSet3->SetColCount(); |
430 | 0 | m_xQSet3->SetLineCount( 1 ); |
431 | 0 | sColorPaletteN = sColorPalette + " 3"; |
432 | 0 | m_xQSet3->InsertItem( 1, m_aPipetteColor, sColorPaletteN); |
433 | 0 | m_xQSet3->SelectItem( 0 ); |
434 | |
|
435 | 0 | m_xQSet4->SetStyle( m_xQSet4->GetStyle() | WB_DOUBLEBORDER | WB_ITEMBORDER ); |
436 | 0 | m_xQSet4->SetColCount(); |
437 | 0 | m_xQSet4->SetLineCount( 1 ); |
438 | 0 | sColorPaletteN = sColorPalette + " 4"; |
439 | 0 | m_xQSet4->InsertItem( 1, m_aPipetteColor, sColorPaletteN); |
440 | 0 | m_xQSet4->SelectItem( 0 ); |
441 | |
|
442 | 0 | m_xQSet1->Show(); |
443 | 0 | m_xQSet2->Show(); |
444 | 0 | m_xQSet3->Show(); |
445 | 0 | m_xQSet4->Show(); |
446 | 0 | } Unexecuted instantiation: SvxBmpMask::SvxBmpMask(SfxBindings*, SfxChildWindow*, vcl::Window*) Unexecuted instantiation: SvxBmpMask::SvxBmpMask(SfxBindings*, SfxChildWindow*, vcl::Window*) |
447 | | |
448 | | SvxBmpMask::~SvxBmpMask() |
449 | 0 | { |
450 | 0 | disposeOnce(); |
451 | 0 | } |
452 | | |
453 | | void SvxBmpMask::dispose() |
454 | 0 | { |
455 | 0 | m_xQSetWin1.reset(); |
456 | 0 | m_xQSet1.reset(); |
457 | 0 | m_xQSetWin2.reset(); |
458 | 0 | m_xQSet2.reset(); |
459 | 0 | m_xQSetWin3.reset(); |
460 | 0 | m_xQSet3.reset(); |
461 | 0 | m_xQSetWin4.reset(); |
462 | 0 | m_xQSet4.reset(); |
463 | 0 | m_xCtlPipetteWin.reset(); |
464 | 0 | m_xCtlPipette.reset(); |
465 | 0 | m_xData.reset(); |
466 | 0 | m_xTbxPipette.reset(); |
467 | 0 | m_xBtnExec.reset(); |
468 | 0 | m_xCbx1.reset(); |
469 | 0 | m_xSp1.reset(); |
470 | 0 | m_xLbColor1.reset(); |
471 | 0 | m_xCbx2.reset(); |
472 | 0 | m_xSp2.reset(); |
473 | 0 | m_xLbColor2.reset(); |
474 | 0 | m_xCbx3.reset(); |
475 | 0 | m_xSp3.reset(); |
476 | 0 | m_xLbColor3.reset(); |
477 | 0 | m_xCbx4.reset(); |
478 | 0 | m_xSp4.reset(); |
479 | 0 | m_xLbColor4.reset(); |
480 | 0 | m_xCbxTrans.reset(); |
481 | 0 | m_xLbColorTrans.reset(); |
482 | 0 | m_aSelItem.dispose(); |
483 | 0 | SfxDockingWindow::dispose(); |
484 | 0 | } |
485 | | |
486 | | /** is called by a MaskSet when it is selected */ |
487 | | void SvxBmpMask::onSelect( const MaskSet* pSet ) |
488 | 0 | { |
489 | | // now deselect all other value sets |
490 | 0 | if( pSet != m_xQSet1.get() ) |
491 | 0 | m_xQSet1->SelectItem( 0 ); |
492 | |
|
493 | 0 | if( pSet != m_xQSet2.get() ) |
494 | 0 | m_xQSet2->SelectItem( 0 ); |
495 | |
|
496 | 0 | if( pSet != m_xQSet3.get() ) |
497 | 0 | m_xQSet3->SelectItem( 0 ); |
498 | |
|
499 | 0 | if( pSet != m_xQSet4.get() ) |
500 | 0 | m_xQSet4->SelectItem( 0 ); |
501 | 0 | } |
502 | | |
503 | | bool SvxBmpMask::Close() |
504 | 0 | { |
505 | 0 | SfxBoolItem aItem2( SID_BMPMASK_PIPETTE, false ); |
506 | 0 | GetBindings().GetDispatcher()->ExecuteList(SID_BMPMASK_PIPETTE, |
507 | 0 | OWN_CALLMODE, { &aItem2 }); |
508 | |
|
509 | 0 | return SfxDockingWindow::Close(); |
510 | 0 | } |
511 | | |
512 | | void SvxBmpMask::SetColor( const Color& rColor ) |
513 | 0 | { |
514 | 0 | m_aPipetteColor = rColor; |
515 | 0 | m_xCtlPipette->SetColor( m_aPipetteColor ); |
516 | 0 | } |
517 | | |
518 | | void SvxBmpMask::PipetteClicked() |
519 | 0 | { |
520 | 0 | if( m_xQSet1->GetSelectedItemId() == 1 ) |
521 | 0 | { |
522 | 0 | m_xCbx1->set_active(true); |
523 | 0 | m_xData->CbxHdl(*m_xCbx1); |
524 | 0 | m_xQSet1->SetItemColor( 1, m_aPipetteColor ); |
525 | 0 | m_xQSet1->SetFormat(); |
526 | 0 | } |
527 | 0 | else if( m_xQSet2->GetSelectedItemId() == 1 ) |
528 | 0 | { |
529 | 0 | m_xCbx2->set_active(true); |
530 | 0 | m_xData->CbxHdl(*m_xCbx2); |
531 | 0 | m_xQSet2->SetItemColor( 1, m_aPipetteColor ); |
532 | 0 | m_xQSet2->SetFormat(); |
533 | 0 | } |
534 | 0 | else if( m_xQSet3->GetSelectedItemId() == 1 ) |
535 | 0 | { |
536 | 0 | m_xCbx3->set_active(true); |
537 | 0 | m_xData->CbxHdl(*m_xCbx3); |
538 | 0 | m_xQSet3->SetItemColor( 1, m_aPipetteColor ); |
539 | 0 | m_xQSet3->SetFormat(); |
540 | 0 | } |
541 | 0 | else if( m_xQSet4->GetSelectedItemId() == 1 ) |
542 | 0 | { |
543 | 0 | m_xCbx4->set_active(true); |
544 | 0 | m_xData->CbxHdl(*m_xCbx4); |
545 | 0 | m_xQSet4->SetItemColor( 1, m_aPipetteColor ); |
546 | 0 | m_xQSet4->SetFormat(); |
547 | 0 | } |
548 | |
|
549 | 0 | m_xTbxPipette->set_item_active(u"pipette"_ustr, false); |
550 | 0 | m_xData->PipetteHdl(u"pipette"_ustr); |
551 | 0 | } |
552 | | |
553 | | void SvxBmpMask::SetExecState( bool bEnable ) |
554 | 0 | { |
555 | 0 | m_xData->SetExecState( bEnable ); |
556 | |
|
557 | 0 | if ( m_xData->IsExecReady() && m_xData->IsCbxReady() ) |
558 | 0 | m_xBtnExec->set_sensitive(true); |
559 | 0 | else |
560 | 0 | m_xBtnExec->set_sensitive(false); |
561 | 0 | } |
562 | | |
563 | | |
564 | | sal_uInt16 SvxBmpMask::InitColorArrays( Color* pSrcCols, Color* pDstCols, sal_uInt8* pTols ) |
565 | 0 | { |
566 | 0 | sal_uInt16 nCount = 0; |
567 | |
|
568 | 0 | if ( m_xCbx1->get_active() ) |
569 | 0 | { |
570 | 0 | pSrcCols[nCount] = m_xQSet1->GetItemColor( 1 ); |
571 | 0 | pDstCols[nCount] = m_xLbColor1->GetSelectEntryColor(); |
572 | 0 | pTols[nCount++] = static_cast<sal_uInt8>(m_xSp1->get_value(FieldUnit::PERCENT)); |
573 | 0 | } |
574 | |
|
575 | 0 | if ( m_xCbx2->get_active() ) |
576 | 0 | { |
577 | 0 | pSrcCols[nCount] = m_xQSet2->GetItemColor( 1 ); |
578 | 0 | pDstCols[nCount] = m_xLbColor2->GetSelectEntryColor(); |
579 | 0 | pTols[nCount++] = static_cast<sal_uInt8>(m_xSp2->get_value(FieldUnit::PERCENT)); |
580 | 0 | } |
581 | |
|
582 | 0 | if ( m_xCbx3->get_active() ) |
583 | 0 | { |
584 | 0 | pSrcCols[nCount] = m_xQSet3->GetItemColor( 1 ); |
585 | 0 | pDstCols[nCount] = m_xLbColor3->GetSelectEntryColor(); |
586 | 0 | pTols[nCount++] = static_cast<sal_uInt8>(m_xSp3->get_value(FieldUnit::PERCENT)); |
587 | 0 | } |
588 | |
|
589 | 0 | if ( m_xCbx4->get_active() ) |
590 | 0 | { |
591 | 0 | pSrcCols[nCount] = m_xQSet4->GetItemColor( 1 ); |
592 | 0 | pDstCols[nCount] = m_xLbColor4->GetSelectEntryColor(); |
593 | 0 | pTols[nCount++] = static_cast<sal_uInt8>(m_xSp4->get_value(FieldUnit::PERCENT)); |
594 | 0 | } |
595 | |
|
596 | 0 | return nCount; |
597 | 0 | } |
598 | | |
599 | | void SvxBmpMask::ImpMask( Bitmap& rBitmap ) |
600 | 0 | { |
601 | 0 | Color pSrcCols[4]; |
602 | 0 | Color pDstCols[4]; |
603 | 0 | sal_uInt8 pTols[4]; |
604 | 0 | const sal_uInt16 nCount = InitColorArrays( pSrcCols, pDstCols, pTols ); |
605 | |
|
606 | 0 | EnterWait(); |
607 | 0 | rBitmap.Replace( pSrcCols, pDstCols, nCount, pTols ); |
608 | 0 | LeaveWait(); |
609 | 0 | } |
610 | | |
611 | | Bitmap SvxBmpMask::ImpMaskTransparent( const Bitmap& rBitmap, const Color& rColor, const sal_uInt8 nTol ) |
612 | 0 | { |
613 | 0 | EnterWait(); |
614 | |
|
615 | 0 | AlphaMask aMask( rBitmap.CreateColorBitmap().CreateAlphaMask( rColor, nTol ) ); |
616 | |
|
617 | 0 | if( rBitmap.HasAlpha() ) |
618 | 0 | aMask.AlphaCombineOr( rBitmap.CreateAlphaMask() ); |
619 | |
|
620 | 0 | Bitmap aBmp( rBitmap.CreateColorBitmap(), aMask ); |
621 | 0 | LeaveWait(); |
622 | |
|
623 | 0 | return aBmp; |
624 | 0 | } |
625 | | |
626 | | |
627 | | Animation SvxBmpMask::ImpMask( const Animation& rAnimation ) |
628 | 0 | { |
629 | 0 | Animation aAnimation( rAnimation ); |
630 | 0 | Color pSrcCols[4]; |
631 | 0 | Color pDstCols[4]; |
632 | 0 | sal_uInt8 pTols[4]; |
633 | 0 | InitColorArrays( pSrcCols, pDstCols, pTols ); |
634 | 0 | sal_uInt16 nAnimationCount = aAnimation.Count(); |
635 | |
|
636 | 0 | for( sal_uInt16 i = 0; i < nAnimationCount; i++ ) |
637 | 0 | { |
638 | 0 | AnimationFrame aAnimationFrame( aAnimation.Get( i ) ); |
639 | 0 | aAnimationFrame.maBitmap = Mask(aAnimationFrame.maBitmap).GetBitmap(); |
640 | 0 | aAnimation.Replace(aAnimationFrame, i); |
641 | 0 | } |
642 | |
|
643 | 0 | return aAnimation; |
644 | 0 | } |
645 | | |
646 | | |
647 | | GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf ) |
648 | 0 | { |
649 | 0 | GDIMetaFile aMtf; |
650 | 0 | Color pSrcCols[4]; |
651 | 0 | Color pDstCols[4]; |
652 | 0 | sal_uInt8 pTols[4]; |
653 | 0 | sal_uInt16 nCount = InitColorArrays( pSrcCols, pDstCols, pTols ); |
654 | | |
655 | | // If no color is selected, we copy only the Mtf |
656 | 0 | if( !nCount ) |
657 | 0 | aMtf = rMtf; |
658 | 0 | else |
659 | 0 | { |
660 | 0 | bool pTrans[4]; |
661 | 0 | Color aCol; |
662 | 0 | tools::Long nR; |
663 | 0 | tools::Long nG; |
664 | 0 | tools::Long nB; |
665 | 0 | std::unique_ptr<tools::Long[]> pMinR(new tools::Long[nCount]); |
666 | 0 | std::unique_ptr<tools::Long[]> pMaxR(new tools::Long[nCount]); |
667 | 0 | std::unique_ptr<tools::Long[]> pMinG(new tools::Long[nCount]); |
668 | 0 | std::unique_ptr<tools::Long[]> pMaxG(new tools::Long[nCount]); |
669 | 0 | std::unique_ptr<tools::Long[]> pMinB(new tools::Long[nCount]); |
670 | 0 | std::unique_ptr<tools::Long[]> pMaxB(new tools::Long[nCount]); |
671 | 0 | sal_uInt16 i; |
672 | |
|
673 | 0 | aMtf.SetPrefSize( rMtf.GetPrefSize() ); |
674 | 0 | aMtf.SetPrefMapMode( rMtf.GetPrefMapMode() ); |
675 | | |
676 | | // Prepare Color comparison array |
677 | 0 | for( i = 0; i < nCount; i++ ) |
678 | 0 | { |
679 | 0 | tools::Long nTol = ( pTols[i] * 255 ) / 100; |
680 | |
|
681 | 0 | tools::Long nVal = static_cast<tools::Long>(pSrcCols[i].GetRed()); |
682 | 0 | pMinR[i] = std::max( nVal - nTol, tools::Long(0) ); |
683 | 0 | pMaxR[i] = std::min( nVal + nTol, tools::Long(255) ); |
684 | |
|
685 | 0 | nVal = static_cast<tools::Long>(pSrcCols[i].GetGreen()); |
686 | 0 | pMinG[i] = std::max( nVal - nTol, tools::Long(0) ); |
687 | 0 | pMaxG[i] = std::min( nVal + nTol, tools::Long(255) ); |
688 | |
|
689 | 0 | nVal = static_cast<tools::Long>(pSrcCols[i].GetBlue()); |
690 | 0 | pMinB[i] = std::max( nVal - nTol, tools::Long(0) ); |
691 | 0 | pMaxB[i] = std::min( nVal + nTol, tools::Long(255) ); |
692 | |
|
693 | 0 | pTrans[ i ] = (pDstCols[ i ] == COL_TRANSPARENT); |
694 | 0 | } |
695 | | |
696 | | // Investigate actions and if necessary replace colors |
697 | 0 | for( size_t nAct = 0, nActCount = rMtf.GetActionSize(); nAct < nActCount; nAct++ ) |
698 | 0 | { |
699 | 0 | MetaAction* pAction = rMtf.GetAction( nAct ); |
700 | |
|
701 | 0 | bool bReplace = false; |
702 | |
|
703 | 0 | switch( pAction->GetType() ) |
704 | 0 | { |
705 | 0 | case MetaActionType::PIXEL: |
706 | 0 | { |
707 | 0 | MetaPixelAction* pAct = static_cast<MetaPixelAction*>(pAction); |
708 | |
|
709 | 0 | aCol = pAct->GetColor(); |
710 | 0 | TEST_COLS(); |
711 | |
|
712 | 0 | if( bReplace ) |
713 | 0 | pAct = new MetaPixelAction( pAct->GetPoint(), aCol ); |
714 | |
|
715 | 0 | aMtf.AddAction( pAct ); |
716 | 0 | } |
717 | 0 | break; |
718 | | |
719 | 0 | case MetaActionType::LINECOLOR: |
720 | 0 | { |
721 | 0 | MetaLineColorAction* pAct = static_cast<MetaLineColorAction*>(pAction); |
722 | |
|
723 | 0 | aCol = pAct->GetColor(); |
724 | 0 | TEST_COLS(); |
725 | |
|
726 | 0 | if( bReplace ) |
727 | 0 | pAct = new MetaLineColorAction( aCol, !pTrans[ i ] ); |
728 | |
|
729 | 0 | aMtf.AddAction( pAct ); |
730 | 0 | } |
731 | 0 | break; |
732 | | |
733 | 0 | case MetaActionType::FILLCOLOR: |
734 | 0 | { |
735 | 0 | MetaFillColorAction* pAct = static_cast<MetaFillColorAction*>(pAction); |
736 | |
|
737 | 0 | aCol = pAct->GetColor(); |
738 | 0 | TEST_COLS(); |
739 | |
|
740 | 0 | if( bReplace ) |
741 | 0 | pAct = new MetaFillColorAction( aCol, !pTrans[ i ] ); |
742 | |
|
743 | 0 | aMtf.AddAction( pAct ); |
744 | 0 | } |
745 | 0 | break; |
746 | | |
747 | 0 | case MetaActionType::TEXTCOLOR: |
748 | 0 | { |
749 | 0 | MetaTextColorAction* pAct = static_cast<MetaTextColorAction*>(pAction); |
750 | |
|
751 | 0 | aCol = pAct->GetColor(); |
752 | 0 | TEST_COLS(); |
753 | |
|
754 | 0 | if( bReplace ) |
755 | 0 | pAct = new MetaTextColorAction( aCol ); |
756 | |
|
757 | 0 | aMtf.AddAction( pAct ); |
758 | 0 | } |
759 | 0 | break; |
760 | | |
761 | 0 | case MetaActionType::TEXTFILLCOLOR: |
762 | 0 | { |
763 | 0 | MetaTextFillColorAction* pAct = static_cast<MetaTextFillColorAction*>(pAction); |
764 | |
|
765 | 0 | aCol = pAct->GetColor(); |
766 | 0 | TEST_COLS(); |
767 | |
|
768 | 0 | if( bReplace ) |
769 | 0 | pAct = new MetaTextFillColorAction( aCol, !pTrans[ i ] ); |
770 | |
|
771 | 0 | aMtf.AddAction( pAct ); |
772 | 0 | } |
773 | 0 | break; |
774 | | |
775 | 0 | case MetaActionType::FONT: |
776 | 0 | { |
777 | 0 | MetaFontAction* pAct = static_cast<MetaFontAction*>(pAction); |
778 | 0 | vcl::Font aFont( pAct->GetFont() ); |
779 | |
|
780 | 0 | aCol = aFont.GetColor(); |
781 | 0 | TEST_COLS(); |
782 | |
|
783 | 0 | if( bReplace ) |
784 | 0 | { |
785 | 0 | aFont.SetColor( aCol ); |
786 | 0 | pAct = new MetaFontAction( std::move(aFont) ); |
787 | 0 | } |
788 | |
|
789 | 0 | aMtf.AddAction( pAct ); |
790 | 0 | } |
791 | 0 | break; |
792 | | |
793 | 0 | case MetaActionType::WALLPAPER: |
794 | 0 | { |
795 | 0 | MetaWallpaperAction* pAct = static_cast<MetaWallpaperAction*>(pAction); |
796 | 0 | Wallpaper aWall( pAct->GetWallpaper() ); |
797 | |
|
798 | 0 | aCol = aWall.GetColor(); |
799 | 0 | TEST_COLS(); |
800 | |
|
801 | 0 | if( bReplace ) |
802 | 0 | { |
803 | 0 | aWall.SetColor( aCol ); |
804 | 0 | pAct = new MetaWallpaperAction( pAct->GetRect(), std::move(aWall) ); |
805 | 0 | } |
806 | |
|
807 | 0 | aMtf.AddAction( pAct ); |
808 | 0 | } |
809 | 0 | break; |
810 | | |
811 | 0 | case MetaActionType::BMP: |
812 | 0 | { |
813 | 0 | MetaBmpAction* pAct = static_cast<MetaBmpAction*>(pAction); |
814 | 0 | const Bitmap aBmp( Mask(pAct->GetBitmap()).GetBitmap().CreateColorBitmap() ); |
815 | |
|
816 | 0 | pAct = new MetaBmpAction( pAct->GetPoint(), aBmp ); |
817 | 0 | aMtf.AddAction( pAct ); |
818 | 0 | } |
819 | 0 | break; |
820 | | |
821 | 0 | case MetaActionType::BMPSCALE: |
822 | 0 | { |
823 | 0 | MetaBmpScaleAction* pAct = static_cast<MetaBmpScaleAction*>(pAction); |
824 | 0 | const Bitmap aBmp( Mask(pAct->GetBitmap()).GetBitmap().CreateColorBitmap() ); |
825 | |
|
826 | 0 | pAct = new MetaBmpScaleAction( pAct->GetPoint(), pAct->GetSize(), aBmp ); |
827 | 0 | aMtf.AddAction( pAct ); |
828 | 0 | } |
829 | 0 | break; |
830 | | |
831 | 0 | case MetaActionType::BMPSCALEPART: |
832 | 0 | { |
833 | 0 | MetaBmpScalePartAction* pAct = static_cast<MetaBmpScalePartAction*>(pAction); |
834 | 0 | const Bitmap aBmp( Mask(pAct->GetBitmap()).GetBitmap().CreateColorBitmap() ); |
835 | |
|
836 | 0 | pAct = new MetaBmpScalePartAction( pAct->GetDestPoint(), pAct->GetDestSize(), |
837 | 0 | pAct->GetSrcPoint(), pAct->GetSrcSize(), aBmp ); |
838 | 0 | aMtf.AddAction( pAct ); |
839 | 0 | } |
840 | 0 | break; |
841 | | |
842 | 0 | case MetaActionType::BMPEX: |
843 | 0 | { |
844 | 0 | MetaBmpExAction* pAct = static_cast<MetaBmpExAction*>(pAction); |
845 | 0 | const Bitmap aBmp( Mask( pAct->GetBitmap() ).GetBitmap() ); |
846 | |
|
847 | 0 | pAct = new MetaBmpExAction( pAct->GetPoint(), aBmp ); |
848 | 0 | aMtf.AddAction( pAct ); |
849 | 0 | } |
850 | 0 | break; |
851 | | |
852 | 0 | case MetaActionType::BMPEXSCALE: |
853 | 0 | { |
854 | 0 | MetaBmpExScaleAction* pAct = static_cast<MetaBmpExScaleAction*>(pAction); |
855 | 0 | const Bitmap aBmp( Mask( pAct->GetBitmap() ).GetBitmap() ); |
856 | |
|
857 | 0 | pAct = new MetaBmpExScaleAction( pAct->GetPoint(), pAct->GetSize(), aBmp ); |
858 | 0 | aMtf.AddAction( pAct ); |
859 | 0 | } |
860 | 0 | break; |
861 | | |
862 | 0 | case MetaActionType::BMPEXSCALEPART: |
863 | 0 | { |
864 | 0 | MetaBmpExScalePartAction* pAct = static_cast<MetaBmpExScalePartAction*>(pAction); |
865 | 0 | const Bitmap aBmp( Mask( pAct->GetBitmap() ).GetBitmap() ); |
866 | |
|
867 | 0 | pAct = new MetaBmpExScalePartAction( pAct->GetDestPoint(), pAct->GetDestSize(), |
868 | 0 | pAct->GetSrcPoint(), pAct->GetSrcSize(), aBmp ); |
869 | 0 | aMtf.AddAction( pAct ); |
870 | 0 | } |
871 | 0 | break; |
872 | | |
873 | 0 | default: |
874 | 0 | { |
875 | 0 | aMtf.AddAction( pAction ); |
876 | 0 | } |
877 | 0 | break; |
878 | 0 | } |
879 | 0 | } |
880 | 0 | } |
881 | | |
882 | 0 | LeaveWait(); |
883 | |
|
884 | 0 | return aMtf; |
885 | 0 | } |
886 | | |
887 | | |
888 | | Animation SvxBmpMask::ImpReplaceTransparency( const Animation& rAnim, const Color& rColor ) |
889 | 0 | { |
890 | 0 | Animation aAnimation( rAnim ); |
891 | 0 | sal_uInt16 nAnimationCount = aAnimation.Count(); |
892 | |
|
893 | 0 | for( sal_uInt16 i = 0; i < nAnimationCount; i++ ) |
894 | 0 | { |
895 | 0 | AnimationFrame aAnimationFrame(aAnimation.Get(i)); |
896 | 0 | aAnimationFrame.maBitmap.ReplaceTransparency(rColor); |
897 | 0 | aAnimation.Replace(aAnimationFrame, i); |
898 | 0 | } |
899 | |
|
900 | 0 | return aAnimation; |
901 | 0 | } |
902 | | |
903 | | |
904 | | GDIMetaFile SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile& rMtf, const Color& rColor ) |
905 | 0 | { |
906 | 0 | ScopedVclPtrInstance< VirtualDevice > pVDev; |
907 | 0 | GDIMetaFile aMtf; |
908 | 0 | const MapMode& rPrefMap = rMtf.GetPrefMapMode(); |
909 | 0 | const Size& rPrefSize = rMtf.GetPrefSize(); |
910 | 0 | const size_t nActionCount = rMtf.GetActionSize(); |
911 | |
|
912 | 0 | pVDev->EnableOutput( false ); |
913 | 0 | aMtf.Record( pVDev ); |
914 | 0 | aMtf.SetPrefSize( rPrefSize ); |
915 | 0 | aMtf.SetPrefMapMode( rPrefMap ); |
916 | 0 | pVDev->SetLineColor( rColor ); |
917 | 0 | pVDev->SetFillColor( rColor ); |
918 | | |
919 | | // retrieve one action at the time; first |
920 | | // set the whole area to the replacement color. |
921 | 0 | pVDev->DrawRect( tools::Rectangle( rPrefMap.GetOrigin(), rPrefSize ) ); |
922 | 0 | for ( size_t i = 0; i < nActionCount; i++ ) |
923 | 0 | { |
924 | 0 | MetaAction* pAct = rMtf.GetAction( i ); |
925 | 0 | aMtf.AddAction( pAct ); |
926 | 0 | } |
927 | |
|
928 | 0 | aMtf.Stop(); |
929 | 0 | aMtf.WindStart(); |
930 | |
|
931 | 0 | return aMtf; |
932 | 0 | } |
933 | | |
934 | | GDIMetaFile SvxBmpMask::GetMetaFile(const Graphic& rGraphic) |
935 | 0 | { |
936 | | // Replace transparency? |
937 | 0 | if (m_xCbxTrans->get_active()) |
938 | 0 | return ImpReplaceTransparency(rGraphic.GetGDIMetaFile(), m_xLbColorTrans->GetSelectEntryColor()); |
939 | 0 | return ImpMask(rGraphic.GetGDIMetaFile()); |
940 | 0 | } |
941 | | |
942 | | Graphic SvxBmpMask::Mask( const Graphic& rGraphic ) |
943 | 0 | { |
944 | 0 | Graphic aGraphic( rGraphic ); |
945 | 0 | const Color aReplColor( m_xLbColorTrans->GetSelectEntryColor() ); |
946 | |
|
947 | 0 | switch( rGraphic.GetType() ) |
948 | 0 | { |
949 | 0 | case GraphicType::Bitmap: |
950 | 0 | { |
951 | 0 | if( rGraphic.IsAnimated() ) |
952 | 0 | { |
953 | | // Replace transparency? |
954 | 0 | if ( m_xCbxTrans->get_active() ) |
955 | 0 | aGraphic = ImpReplaceTransparency( rGraphic.GetAnimation(), aReplColor ); |
956 | 0 | else |
957 | 0 | aGraphic = ImpMask( rGraphic.GetAnimation() ); |
958 | 0 | } |
959 | 0 | else |
960 | 0 | { |
961 | | // Replace transparency? |
962 | 0 | if( m_xCbxTrans->get_active() ) |
963 | 0 | { |
964 | 0 | Bitmap aBmp = aGraphic.GetBitmap(); |
965 | 0 | aBmp.ReplaceTransparency(aReplColor); |
966 | 0 | aGraphic = aBmp; |
967 | 0 | } |
968 | 0 | else |
969 | 0 | { |
970 | 0 | Color pSrcCols[4]; |
971 | 0 | Color pDstCols[4]; |
972 | 0 | sal_uInt8 pTols[4]; |
973 | 0 | sal_uInt16 nCount = InitColorArrays( pSrcCols, pDstCols, pTols ); |
974 | |
|
975 | 0 | if( nCount ) |
976 | 0 | { |
977 | | // first set all transparent colors |
978 | 0 | for( sal_uInt16 i = 0; i < nCount; i++ ) |
979 | 0 | { |
980 | | // Do we have a transparent color? |
981 | 0 | if (pDstCols[i] == COL_TRANSPARENT) |
982 | 0 | { |
983 | 0 | Bitmap aBmp( ImpMaskTransparent( aGraphic.GetBitmap(), |
984 | 0 | pSrcCols[ i ], pTols[ i ] ) ); |
985 | 0 | const Size aSize( aBmp.GetSizePixel() ); |
986 | |
|
987 | 0 | if( aSize.Width() && aSize.Height() ) |
988 | 0 | aGraphic = aBmp; |
989 | 0 | } |
990 | 0 | } |
991 | | |
992 | | // now replace it again with the normal colors |
993 | 0 | Bitmap aBitmap( aGraphic.GetBitmap() ); |
994 | 0 | if ( aBitmap.GetSizePixel().Width() && aBitmap.GetSizePixel().Height() ) |
995 | 0 | { |
996 | 0 | ImpMask( aBitmap ); |
997 | 0 | aGraphic = Graphic( aBitmap ); |
998 | 0 | } |
999 | 0 | } |
1000 | 0 | } |
1001 | 0 | } |
1002 | 0 | } |
1003 | 0 | break; |
1004 | | |
1005 | 0 | case GraphicType::GdiMetafile: |
1006 | 0 | { |
1007 | 0 | GDIMetaFile aMtf(GetMetaFile(rGraphic)); |
1008 | 0 | Size aSize( aMtf.GetPrefSize() ); |
1009 | 0 | if ( aSize.Width() && aSize.Height() ) |
1010 | 0 | aGraphic = Graphic( aMtf ); |
1011 | 0 | else |
1012 | 0 | aGraphic = rGraphic; |
1013 | 0 | } |
1014 | 0 | break; |
1015 | | |
1016 | 0 | default: |
1017 | 0 | aGraphic = rGraphic; |
1018 | 0 | break; |
1019 | 0 | } |
1020 | | |
1021 | 0 | if( aGraphic != rGraphic ) |
1022 | 0 | { |
1023 | 0 | aGraphic.SetPrefSize( rGraphic.GetPrefSize() ); |
1024 | 0 | aGraphic.SetPrefMapMode( rGraphic.GetPrefMapMode() ); |
1025 | 0 | } |
1026 | |
|
1027 | 0 | return aGraphic; |
1028 | 0 | } |
1029 | | |
1030 | | bool SvxBmpMask::IsEyedropping() const |
1031 | 0 | { |
1032 | 0 | return m_xTbxPipette->get_item_active(u"pipette"_ustr); |
1033 | 0 | } |
1034 | | |
1035 | | /** Set an accessible name for the source color check boxes. Without this |
1036 | | the lengthy description is read. |
1037 | | */ |
1038 | | void SvxBmpMask::SetAccessibleNames() |
1039 | 0 | { |
1040 | | // set the accessible name for valueset |
1041 | 0 | OUString sColorPalette (SvxResId( RID_SVXDLG_BMPMASK_STR_PALETTE)); |
1042 | 0 | OUString sColorPaletteN; |
1043 | |
|
1044 | 0 | sColorPaletteN = sColorPalette + " 1"; |
1045 | 0 | m_xQSet1->SetText (sColorPaletteN); |
1046 | 0 | sColorPaletteN = sColorPalette + " 2"; |
1047 | 0 | m_xQSet2->SetText (sColorPaletteN); |
1048 | 0 | sColorPaletteN = sColorPalette + " 3"; |
1049 | 0 | m_xQSet3->SetText (sColorPaletteN); |
1050 | 0 | sColorPaletteN = sColorPalette + " 4"; |
1051 | 0 | m_xQSet4->SetText (sColorPaletteN); |
1052 | 0 | } |
1053 | | |
1054 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |