Line data Source code
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/wrkwin.hxx>
21 : #include <sot/factory.hxx>
22 : #include <tools/shl.hxx>
23 : #include <tools/helpers.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <svl/eitem.hxx>
26 : #include <sfx2/dispatch.hxx>
27 : #include <sfx2/viewfrm.hxx>
28 : #include <svtools/miscopt.hxx>
29 : #include <unotools/localedatawrapper.hxx>
30 : #include <comphelper/processfactory.hxx>
31 :
32 : #include <svx/dialmgr.hxx>
33 : #include "svx/xoutbmp.hxx"
34 : #include <svx/dialogs.hrc>
35 : #include <svx/svxids.hrc>
36 : #include <svx/contdlg.hxx>
37 : #include "contimp.hxx"
38 : #include "contdlg.hrc"
39 : #include "contwnd.hxx"
40 : #include <svx/svdtrans.hxx>
41 : #include <svx/svdopath.hxx>
42 : #include "svx/dlgutil.hxx"
43 : #include <vcl/svapp.hxx>
44 : #include <vcl/virdev.hxx>
45 : #include "dlgunit.hxx"
46 :
47 66 : SFX_IMPL_FLOATINGWINDOW_WITHID( SvxContourDlgChildWindow, SID_CONTOUR_DLG );
48 :
49 :
50 : /******************************************************************************/
51 :
52 0 : SvxContourDlgItem::SvxContourDlgItem( sal_uInt16 _nId, SvxSuperContourDlg& rContourDlg, SfxBindings& rBindings ) :
53 : SfxControllerItem ( _nId, rBindings ),
54 0 : rDlg ( rContourDlg )
55 : {
56 0 : }
57 :
58 0 : void SvxContourDlgItem::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/, const SfxPoolItem* pItem )
59 : {
60 0 : if ( pItem && ( SID_CONTOUR_EXEC == nSID ) )
61 : {
62 0 : const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
63 :
64 : DBG_ASSERT( pStateItem || pItem == 0, "SfxBoolItem expected ");
65 :
66 0 : rDlg.SetExecState( !pStateItem->GetValue() );
67 : }
68 0 : }
69 :
70 :
71 : /******************************************************************************/
72 :
73 0 : SvxContourDlgChildWindow::SvxContourDlgChildWindow( Window* _pParent, sal_uInt16 nId,
74 : SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
75 0 : SfxChildWindow( _pParent, nId )
76 : {
77 0 : SvxSuperContourDlg* pDlg = new SvxSuperContourDlg( pBindings, this, _pParent, CONT_RESID( RID_SVXDLG_CONTOUR ) );
78 0 : pWindow = pDlg;
79 :
80 0 : if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
81 0 : pDlg->RollUp();
82 :
83 0 : eChildAlignment = SFX_ALIGN_NOALIGNMENT;
84 :
85 0 : pDlg->Initialize( pInfo );
86 0 : }
87 :
88 0 : SvxContourDlg::SvxContourDlg( SfxBindings* _pBindings, SfxChildWindow* pCW,
89 : Window* _pParent, const ResId& rResId ) :
90 :
91 0 : SfxFloatingWindow ( _pBindings, pCW, _pParent, rResId )
92 :
93 : {
94 0 : }
95 :
96 0 : SvxContourDlg::~SvxContourDlg()
97 : {
98 0 : }
99 :
100 0 : PolyPolygon SvxContourDlg::CreateAutoContour( const Graphic& rGraphic,
101 : const Rectangle* pRect,
102 : const sal_uIntPtr nFlags )
103 : {
104 0 : Bitmap aBmp;
105 0 : sal_uIntPtr nContourFlags = XOUTBMP_CONTOUR_HORZ;
106 :
107 0 : if ( rGraphic.GetType() == GRAPHIC_BITMAP )
108 : {
109 0 : if( rGraphic.IsAnimated() )
110 : {
111 0 : VirtualDevice aVDev;
112 0 : MapMode aTransMap;
113 0 : const Animation aAnim( rGraphic.GetAnimation() );
114 0 : const Size& rSizePix = aAnim.GetDisplaySizePixel();
115 0 : const sal_uInt16 nCount = aAnim.Count();
116 :
117 0 : if ( aVDev.SetOutputSizePixel( rSizePix ) )
118 : {
119 0 : aVDev.SetLineColor( Color( COL_BLACK ) );
120 0 : aVDev.SetFillColor( Color( COL_BLACK ) );
121 :
122 0 : for( sal_uInt16 i = 0; i < nCount; i++ )
123 : {
124 0 : const AnimationBitmap& rStepBmp = aAnim.Get( i );
125 :
126 : // Push Polygon output to the right place; this is the
127 : // offset of the sub-image within the total animation
128 0 : aTransMap.SetOrigin( Point( rStepBmp.aPosPix.X(), rStepBmp.aPosPix.Y() ) );
129 0 : aVDev.SetMapMode( aTransMap );
130 0 : aVDev.DrawPolyPolygon( CreateAutoContour( rStepBmp.aBmpEx, pRect, nFlags ) );
131 : }
132 :
133 0 : aTransMap.SetOrigin( Point() );
134 0 : aVDev.SetMapMode( aTransMap );
135 0 : aBmp = aVDev.GetBitmap( Point(), rSizePix );
136 0 : aBmp.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
137 0 : }
138 : }
139 0 : else if( rGraphic.IsTransparent() )
140 0 : aBmp = rGraphic.GetBitmapEx().GetMask();
141 : else
142 : {
143 0 : aBmp = rGraphic.GetBitmap();
144 0 : nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
145 : }
146 : }
147 0 : else if( rGraphic.GetType() != GRAPHIC_NONE )
148 : {
149 0 : const Graphic aTmpGrf( rGraphic.GetGDIMetaFile().GetMonochromeMtf( Color( COL_BLACK ) ) );
150 0 : VirtualDevice aVDev;
151 0 : Size aSizePix( aVDev.LogicToPixel( aTmpGrf.GetPrefSize(), aTmpGrf.GetPrefMapMode() ) );
152 :
153 0 : if( aSizePix.Width() && aSizePix.Height() && ( aSizePix.Width() > 512 || aSizePix.Height() > 512 ) )
154 : {
155 0 : double fWH = (double) aSizePix.Width() / aSizePix.Height();
156 :
157 0 : if( fWH <= 1.0 )
158 0 : aSizePix.Width() = FRound( ( aSizePix.Height() = 512 ) * fWH );
159 : else
160 0 : aSizePix.Height() = FRound( ( aSizePix.Width() = 512 ) / fWH );
161 : }
162 :
163 0 : if( aVDev.SetOutputSizePixel( aSizePix ) )
164 : {
165 0 : const Point aPt;
166 0 : aTmpGrf.Draw( &aVDev, aPt, aSizePix );
167 0 : aBmp = aVDev.GetBitmap( aPt, aSizePix );
168 : }
169 :
170 0 : nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
171 : }
172 :
173 0 : aBmp.SetPrefSize( rGraphic.GetPrefSize() );
174 0 : aBmp.SetPrefMapMode( rGraphic.GetPrefMapMode() );
175 :
176 0 : return PolyPolygon( XOutBitmap::GetCountour( aBmp, nContourFlags, 128, pRect ) );
177 : }
178 :
179 : // Loop through to super class, no virtual Methods to not become incompatible
180 : // due to IF changes
181 :
182 0 : const Graphic& SvxContourDlg::GetGraphic() const
183 : {
184 0 : return pSuperClass->GetGraphic();
185 : }
186 :
187 0 : sal_Bool SvxContourDlg::IsGraphicChanged() const
188 : {
189 0 : return pSuperClass->IsGraphicChanged();
190 : }
191 :
192 0 : PolyPolygon SvxContourDlg::GetPolyPolygon()
193 : {
194 0 : return pSuperClass->GetPolyPolygon( true );
195 : }
196 :
197 0 : const void* SvxContourDlg::GetEditingObject() const
198 : {
199 0 : return pSuperClass->GetEditingObject();
200 : }
201 :
202 0 : void SvxContourDlg::Update( const Graphic& rGraphic, sal_Bool bGraphicLinked,
203 : const PolyPolygon* pPolyPoly, void* pEditingObj )
204 : {
205 0 : pSuperClass->UpdateGraphic( rGraphic, bGraphicLinked, pPolyPoly, pEditingObj );
206 0 : }
207 :
208 0 : SvxSuperContourDlg::SvxSuperContourDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
209 : Window* _pParent, const ResId& rResId ) :
210 : SvxContourDlg ( _pBindings, pCW, _pParent, rResId ),
211 : pCheckObj ( NULL ),
212 : aContourItem ( SID_CONTOUR_EXEC, *this, *_pBindings ),
213 0 : aTbx1 ( this, ResId( TBX1, *rResId.GetResMgr() ) ),
214 0 : aMtfTolerance ( this, ResId( MTF_TOLERANCE, *rResId.GetResMgr() ) ),
215 0 : aContourWnd ( this, ResId( CTL_CONTOUR, *rResId.GetResMgr() ) ),
216 : aStbStatus ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
217 : nGrfChanged ( 0UL ),
218 : bExecState ( sal_False ),
219 : bGraphicLinked ( sal_False ),
220 0 : maImageList ( SVX_RES( CD_IMAPDLG ) )
221 : {
222 0 : ApplyImageList();
223 :
224 0 : FreeResource();
225 :
226 0 : SvxContourDlg::SetSuperClass( *this );
227 :
228 0 : aContourWnd.SetMousePosLink( LINK( this, SvxSuperContourDlg, MousePosHdl ) );
229 0 : aContourWnd.SetGraphSizeLink( LINK( this, SvxSuperContourDlg, GraphSizeHdl ) );
230 0 : aContourWnd.SetUpdateLink( LINK( this, SvxSuperContourDlg, StateHdl ) );
231 0 : aContourWnd.SetPipetteHdl( LINK( this, SvxSuperContourDlg, PipetteHdl ) );
232 0 : aContourWnd.SetPipetteClickHdl( LINK( this, SvxSuperContourDlg, PipetteClickHdl ) );
233 0 : aContourWnd.SetWorkplaceClickHdl( LINK( this, SvxSuperContourDlg, WorkplaceClickHdl ) );
234 :
235 0 : const Size aTbxSize( aTbx1.CalcWindowSizePixel() );
236 0 : Point aPos( aTbx1.GetPosPixel() );
237 0 : SvtMiscOptions aMiscOptions;
238 :
239 0 : aMiscOptions.AddListenerLink( LINK( this, SvxSuperContourDlg, MiscHdl ) );
240 :
241 0 : aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
242 0 : aTbx1.SetSizePixel( aTbxSize );
243 0 : aTbx1.SetSelectHdl( LINK( this, SvxSuperContourDlg, Tbx1ClickHdl ) );
244 :
245 0 : aPos.X() += aTbxSize.Width() + LogicToPixel( Size( 3, 0 ), MapMode( MAP_APPFONT ) ).Width();
246 0 : aMtfTolerance.SetPosPixel( aPos );
247 0 : aMtfTolerance.SetValue( 10L );
248 :
249 0 : SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
250 :
251 0 : aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
252 0 : aStbStatus.InsertItem( 2, 10 + GetTextWidth( OUString(" 9999,99 cm / 9999,99 cm ") ), SIB_CENTER | SIB_IN );
253 0 : aStbStatus.InsertItem( 3, 10 + GetTextWidth( OUString(" 9999,99 cm x 9999,99 cm ") ), SIB_CENTER | SIB_IN );
254 0 : aStbStatus.InsertItem( 4, 20, SIB_CENTER | SIB_IN );
255 :
256 0 : Resize();
257 :
258 0 : aUpdateTimer.SetTimeout( 100 );
259 0 : aUpdateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, UpdateHdl ) );
260 :
261 0 : aCreateTimer.SetTimeout( 50 );
262 0 : aCreateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, CreateHdl ) );
263 0 : }
264 :
265 0 : SvxSuperContourDlg::~SvxSuperContourDlg()
266 : {
267 0 : SvtMiscOptions aMiscOptions;
268 0 : aMiscOptions.RemoveListenerLink( LINK(this, SvxSuperContourDlg, MiscHdl) );
269 0 : }
270 :
271 : // Resize methods
272 :
273 0 : void SvxSuperContourDlg::Resize()
274 : {
275 0 : SfxFloatingWindow::Resize();
276 :
277 0 : Size aMinSize( GetMinOutputSizePixel() );
278 0 : Size aNewSize( GetOutputSizePixel() );
279 :
280 0 : if ( aNewSize.Height() >= aMinSize.Height() )
281 : {
282 0 : Size _aSize( aStbStatus.GetSizePixel() );
283 0 : Point aPoint( 0, aNewSize.Height() - _aSize.Height() );
284 :
285 : // Position the StatusBar
286 0 : aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
287 0 : aStbStatus.Show();
288 :
289 : // Position the EditWindow
290 0 : _aSize.Width() = aNewSize.Width() - 18;
291 0 : _aSize.Height() = aPoint.Y() - aContourWnd.GetPosPixel().Y() - 6;
292 0 : aContourWnd.SetSizePixel( _aSize );
293 :
294 0 : aLastSize = aNewSize;
295 : }
296 0 : }
297 :
298 : // Close methods
299 :
300 0 : sal_Bool SvxSuperContourDlg::Close()
301 : {
302 0 : sal_Bool bRet = sal_True;
303 :
304 0 : if ( aTbx1.IsItemEnabled( TBI_APPLY ) )
305 : {
306 : QueryBox aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
307 0 : String( CONT_RESID( STR_CONTOURDLG_MODIFY ) ) );
308 0 : const long nRet = aQBox.Execute();
309 :
310 0 : if ( nRet == RET_YES )
311 : {
312 0 : SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, sal_True );
313 0 : GetBindings().GetDispatcher()->Execute(
314 0 : SID_CONTOUR_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
315 : }
316 0 : else if ( nRet == RET_CANCEL )
317 0 : bRet = sal_False;
318 : }
319 :
320 0 : return( bRet ? SfxFloatingWindow::Close() : sal_False );
321 : }
322 :
323 : // Enabled or disabled all Controls
324 :
325 0 : void SvxSuperContourDlg::SetExecState( sal_Bool bEnable )
326 : {
327 0 : bExecState = bEnable;
328 0 : }
329 :
330 0 : void SvxSuperContourDlg::SetGraphic( const Graphic& rGraphic )
331 : {
332 0 : aUndoGraphic = aRedoGraphic = Graphic();
333 0 : aGraphic = rGraphic;
334 0 : nGrfChanged = 0UL;
335 0 : aContourWnd.SetGraphic( aGraphic );
336 0 : }
337 :
338 0 : void SvxSuperContourDlg::SetPolyPolygon( const PolyPolygon& rPolyPoly )
339 : {
340 : DBG_ASSERT( aContourWnd.GetGraphic().GetType() != GRAPHIC_NONE, "Graphic must've been set first!" );
341 :
342 0 : PolyPolygon aPolyPoly( rPolyPoly );
343 0 : const MapMode aMap100( MAP_100TH_MM );
344 0 : const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
345 0 : OutputDevice* pOutDev = Application::GetDefaultDevice();
346 0 : sal_Bool bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
347 :
348 0 : for ( sal_uInt16 j = 0, nPolyCount = aPolyPoly.Count(); j < nPolyCount; j++ )
349 : {
350 0 : Polygon& rPoly = aPolyPoly[ j ];
351 :
352 0 : for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
353 : {
354 0 : Point& rPt = rPoly[ i ];
355 :
356 0 : if ( !bPixelMap )
357 0 : rPt = pOutDev->LogicToPixel( rPt, aGrfMap );
358 :
359 0 : rPt = pOutDev->PixelToLogic( rPt, aMap100 );
360 : }
361 : }
362 :
363 0 : aContourWnd.SetPolyPolygon( aPolyPoly );
364 0 : aContourWnd.GetSdrModel()->SetChanged( sal_True );
365 0 : }
366 :
367 0 : PolyPolygon SvxSuperContourDlg::GetPolyPolygon( bool bRescaleToGraphic )
368 : {
369 0 : PolyPolygon aRetPolyPoly( aContourWnd.GetPolyPolygon() );
370 :
371 0 : if ( bRescaleToGraphic )
372 : {
373 0 : const MapMode aMap100( MAP_100TH_MM );
374 0 : const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
375 0 : OutputDevice* pOutDev = Application::GetDefaultDevice();
376 0 : sal_Bool bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
377 :
378 0 : for ( sal_uInt16 j = 0, nPolyCount = aRetPolyPoly.Count(); j < nPolyCount; j++ )
379 : {
380 0 : Polygon& rPoly = aRetPolyPoly[ j ];
381 :
382 0 : for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
383 : {
384 0 : Point& rPt = rPoly[ i ];
385 :
386 0 : rPt = pOutDev->LogicToPixel( rPt, aMap100 );
387 :
388 0 : if ( !bPixelMap )
389 0 : rPt = pOutDev->PixelToLogic( rPt, aGrfMap );
390 : }
391 0 : }
392 : }
393 :
394 0 : return aRetPolyPoly;
395 : }
396 :
397 0 : void SvxSuperContourDlg::UpdateGraphic( const Graphic& rGraphic, sal_Bool _bGraphicLinked,
398 : const PolyPolygon* pPolyPoly, void* pEditingObj )
399 : {
400 0 : aUpdateGraphic = rGraphic;
401 0 : bUpdateGraphicLinked = _bGraphicLinked;
402 0 : pUpdateEditingObject = pEditingObj;
403 :
404 0 : if ( pPolyPoly )
405 0 : aUpdatePolyPoly = *pPolyPoly;
406 : else
407 0 : aUpdatePolyPoly = PolyPolygon();
408 :
409 0 : aUpdateTimer.Start();
410 0 : }
411 :
412 0 : bool SvxSuperContourDlg::IsUndoPossible() const
413 : {
414 0 : return aUndoGraphic.GetType() != GRAPHIC_NONE;
415 : }
416 :
417 0 : bool SvxSuperContourDlg::IsRedoPossible() const
418 : {
419 0 : return aRedoGraphic.GetType() != GRAPHIC_NONE;
420 : }
421 :
422 : // Click handler for ToolBox
423 :
424 0 : IMPL_LINK( SvxSuperContourDlg, Tbx1ClickHdl, ToolBox*, pTbx )
425 : {
426 0 : sal_uInt16 nNewItemId = pTbx->GetCurItemId();
427 :
428 0 : switch( pTbx->GetCurItemId() )
429 : {
430 : case( TBI_APPLY ):
431 : {
432 0 : SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, sal_True );
433 0 : GetBindings().GetDispatcher()->Execute(
434 0 : SID_CONTOUR_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
435 : }
436 0 : break;
437 :
438 : case( TBI_WORKPLACE ):
439 : {
440 0 : if ( aTbx1.IsItemChecked( TBI_WORKPLACE ) )
441 : {
442 0 : QueryBox aQBox( this, WB_YES_NO | WB_DEF_NO, String( CONT_RESID( STR_CONTOURDLG_WORKPLACE ) ) );
443 :
444 0 : if ( !aContourWnd.IsContourChanged() || ( aQBox.Execute() == RET_YES ) )
445 0 : aContourWnd.SetWorkplaceMode( sal_True );
446 : else
447 0 : aTbx1.CheckItem( TBI_WORKPLACE, sal_False );
448 : }
449 : else
450 0 : aContourWnd.SetWorkplaceMode( sal_False );
451 : }
452 0 : break;
453 :
454 : case( TBI_SELECT ):
455 : {
456 0 : pTbx->CheckItem( nNewItemId, sal_True );
457 0 : aContourWnd.SetEditMode( sal_True );
458 : }
459 0 : break;
460 :
461 : case( TBI_RECT ):
462 : {
463 0 : pTbx->CheckItem( nNewItemId, sal_True );
464 0 : aContourWnd.SetObjKind( OBJ_RECT );
465 : }
466 0 : break;
467 :
468 : case( TBI_CIRCLE ):
469 : {
470 0 : pTbx->CheckItem( nNewItemId, sal_True );
471 0 : aContourWnd.SetObjKind( OBJ_CIRC );
472 :
473 : }
474 0 : break;
475 :
476 : case( TBI_POLY ):
477 : {
478 0 : pTbx->CheckItem( nNewItemId, sal_True );
479 0 : aContourWnd.SetObjKind( OBJ_POLY );
480 : }
481 0 : break;
482 :
483 : case( TBI_FREEPOLY ):
484 : {
485 0 : pTbx->CheckItem( nNewItemId, sal_True );
486 0 : aContourWnd.SetObjKind( OBJ_FREEFILL );
487 : }
488 0 : break;
489 :
490 : case( TBI_POLYEDIT ):
491 0 : aContourWnd.SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
492 0 : break;
493 :
494 : case( TBI_POLYMOVE ):
495 0 : aContourWnd.SetPolyEditMode( SID_BEZIER_MOVE );
496 0 : break;
497 :
498 : case( TBI_POLYINSERT ):
499 0 : aContourWnd.SetPolyEditMode( SID_BEZIER_INSERT );
500 0 : break;
501 :
502 : case( TBI_POLYDELETE ):
503 0 : aContourWnd.GetSdrView()->DeleteMarkedPoints();
504 0 : break;
505 :
506 : case( TBI_UNDO ):
507 : {
508 0 : nGrfChanged = nGrfChanged ? nGrfChanged - 1 : 0UL;
509 0 : aRedoGraphic = aGraphic;
510 0 : aGraphic = aUndoGraphic;
511 0 : aUndoGraphic = Graphic();
512 0 : aContourWnd.SetGraphic( aGraphic, sal_False );
513 : }
514 0 : break;
515 :
516 : case( TBI_REDO ):
517 : {
518 0 : nGrfChanged++;
519 0 : aUndoGraphic = aGraphic;
520 0 : aGraphic = aRedoGraphic;
521 0 : aRedoGraphic = Graphic();
522 0 : aContourWnd.SetGraphic( aGraphic, sal_False );
523 : }
524 0 : break;
525 :
526 : case( TBI_AUTOCONTOUR ):
527 0 : aCreateTimer.Start();
528 0 : break;
529 :
530 : case( TBI_PIPETTE ):
531 : {
532 0 : sal_Bool bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
533 :
534 0 : if ( !bPipette )
535 0 : aStbStatus.Invalidate();
536 0 : else if ( bGraphicLinked )
537 : {
538 0 : QueryBox aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_LINKED ) ) );
539 :
540 0 : if ( aQBox.Execute() != RET_YES )
541 : {
542 0 : aTbx1.CheckItem( TBI_PIPETTE, bPipette = sal_False );
543 0 : aStbStatus.Invalidate();
544 0 : }
545 : }
546 :
547 0 : aContourWnd.SetPipetteMode( bPipette );
548 : }
549 0 : break;
550 :
551 : default:
552 0 : break;
553 : }
554 :
555 0 : return 0L;
556 : }
557 :
558 0 : IMPL_LINK( SvxSuperContourDlg, MousePosHdl, ContourWindow*, pWnd )
559 : {
560 0 : String aStr;
561 0 : const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
562 0 : const Point& rMousePos = pWnd->GetMousePos();
563 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
564 0 : const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
565 :
566 0 : aStr.Assign( GetUnitString( rMousePos.X(), eFieldUnit, cSep ) );
567 0 : aStr.Append( OUString(" / ") );
568 0 : aStr.Append( GetUnitString( rMousePos.Y(), eFieldUnit, cSep ) );
569 :
570 0 : aStbStatus.SetItemText( 2, aStr );
571 :
572 0 : return 0L;
573 : }
574 :
575 0 : IMPL_LINK( SvxSuperContourDlg, GraphSizeHdl, ContourWindow*, pWnd )
576 : {
577 0 : String aStr;
578 0 : const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
579 0 : const Size& rSize = pWnd->GetGraphicSize();
580 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
581 0 : const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
582 :
583 0 : aStr.Assign( GetUnitString( rSize.Width(), eFieldUnit, cSep ) );
584 0 : aStr.Append( OUString(" x ") );
585 0 : aStr.Append( GetUnitString( rSize.Height(), eFieldUnit, cSep ) );
586 :
587 0 : aStbStatus.SetItemText( 3, aStr );
588 :
589 0 : return 0L;
590 : }
591 :
592 0 : IMPL_LINK_NOARG(SvxSuperContourDlg, UpdateHdl)
593 : {
594 0 : aUpdateTimer.Stop();
595 :
596 0 : if ( pUpdateEditingObject != pCheckObj )
597 : {
598 0 : if( !GetEditingObject() )
599 0 : aContourWnd.GrabFocus();
600 :
601 0 : SetGraphic( aUpdateGraphic );
602 0 : SetPolyPolygon( aUpdatePolyPoly );
603 0 : SetEditingObject( pUpdateEditingObject );
604 0 : bGraphicLinked = bUpdateGraphicLinked;
605 :
606 0 : aUpdateGraphic = Graphic();
607 0 : aUpdatePolyPoly = PolyPolygon();
608 0 : bUpdateGraphicLinked = sal_False;
609 :
610 0 : aContourWnd.GetSdrModel()->SetChanged( sal_False );
611 : }
612 :
613 0 : GetBindings().Invalidate( SID_CONTOUR_EXEC );
614 :
615 0 : return 0L;
616 : }
617 :
618 0 : IMPL_LINK_NOARG(SvxSuperContourDlg, CreateHdl)
619 : {
620 0 : aCreateTimer.Stop();
621 :
622 0 : const Rectangle aWorkRect = aContourWnd.LogicToPixel( aContourWnd.GetWorkRect(), MapMode( MAP_100TH_MM ) );
623 0 : const Graphic& rGraphic = aContourWnd.GetGraphic();
624 0 : const sal_Bool bValid = aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom();
625 :
626 0 : EnterWait();
627 0 : SetPolyPolygon( CreateAutoContour( rGraphic, bValid ? &aWorkRect : NULL ) );
628 0 : LeaveWait();
629 :
630 0 : return 0L;
631 : }
632 :
633 0 : IMPL_LINK( SvxSuperContourDlg, StateHdl, ContourWindow*, pWnd )
634 : {
635 0 : const SdrObject* pObj = pWnd->GetSelectedSdrObject();
636 0 : const SdrView* pView = pWnd->GetSdrView();
637 0 : const sal_Bool bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
638 0 : const sal_Bool bDrawEnabled = !( bPolyEdit && aTbx1.IsItemChecked( TBI_POLYEDIT ) );
639 0 : const sal_Bool bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
640 0 : const sal_Bool bWorkplace = aTbx1.IsItemChecked( TBI_WORKPLACE );
641 0 : const sal_Bool bDontHide = !( bPipette || bWorkplace );
642 0 : const sal_Bool bBitmap = pWnd->GetGraphic().GetType() == GRAPHIC_BITMAP;
643 :
644 0 : aTbx1.EnableItem( TBI_APPLY, bDontHide && bExecState && pWnd->IsChanged() );
645 :
646 0 : aTbx1.EnableItem( TBI_WORKPLACE, !bPipette && bDrawEnabled );
647 :
648 0 : aTbx1.EnableItem( TBI_SELECT, bDontHide && bDrawEnabled );
649 0 : aTbx1.EnableItem( TBI_RECT, bDontHide && bDrawEnabled );
650 0 : aTbx1.EnableItem( TBI_CIRCLE, bDontHide && bDrawEnabled );
651 0 : aTbx1.EnableItem( TBI_POLY, bDontHide && bDrawEnabled );
652 0 : aTbx1.EnableItem( TBI_FREEPOLY, bDontHide && bDrawEnabled );
653 :
654 0 : aTbx1.EnableItem( TBI_POLYEDIT, bDontHide && bPolyEdit );
655 0 : aTbx1.EnableItem( TBI_POLYMOVE, bDontHide && !bDrawEnabled );
656 0 : aTbx1.EnableItem( TBI_POLYINSERT, bDontHide && !bDrawEnabled );
657 0 : aTbx1.EnableItem( TBI_POLYDELETE, bDontHide && !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
658 :
659 0 : aTbx1.EnableItem( TBI_AUTOCONTOUR, bDontHide && bDrawEnabled );
660 0 : aTbx1.EnableItem( TBI_PIPETTE, !bWorkplace && bDrawEnabled && bBitmap );
661 :
662 0 : aTbx1.EnableItem( TBI_UNDO, bDontHide && IsUndoPossible() );
663 0 : aTbx1.EnableItem( TBI_REDO, bDontHide && IsRedoPossible() );
664 :
665 0 : if ( bPolyEdit )
666 : {
667 0 : sal_uInt16 nId = 0;
668 :
669 0 : switch( pWnd->GetPolyEditMode() )
670 : {
671 0 : case( SID_BEZIER_MOVE ): nId = TBI_POLYMOVE; break;
672 0 : case( SID_BEZIER_INSERT ): nId = TBI_POLYINSERT; break;
673 :
674 : default:
675 0 : break;
676 : }
677 :
678 0 : aTbx1.CheckItem( nId, sal_True );
679 : }
680 : else
681 : {
682 0 : aTbx1.CheckItem( TBI_POLYEDIT, sal_False );
683 0 : aTbx1.CheckItem( TBI_POLYMOVE, sal_True );
684 0 : aTbx1.CheckItem( TBI_POLYINSERT, sal_False );
685 0 : pWnd->SetPolyEditMode( 0 );
686 : }
687 :
688 0 : return 0L;
689 : }
690 :
691 0 : IMPL_LINK( SvxSuperContourDlg, PipetteHdl, ContourWindow*, pWnd )
692 : {
693 0 : const Color& rOldLineColor = aStbStatus.GetLineColor();
694 0 : const Color& rOldFillColor = aStbStatus.GetFillColor();
695 :
696 0 : Rectangle aRect( aStbStatus.GetItemRect( 4 ) );
697 0 : const Color& rColor = pWnd->GetPipetteColor();
698 :
699 0 : aStbStatus.SetLineColor( rColor );
700 0 : aStbStatus.SetFillColor( rColor );
701 :
702 0 : aRect.Left() += 4;
703 0 : aRect.Top() += 4;
704 0 : aRect.Right() -= 4;
705 0 : aRect.Bottom() -= 4;
706 :
707 0 : aStbStatus.DrawRect( aRect );
708 :
709 0 : aStbStatus.SetLineColor( rOldLineColor );
710 0 : aStbStatus.SetFillColor( rOldFillColor );
711 :
712 0 : return 0L;
713 : }
714 :
715 0 : IMPL_LINK( SvxSuperContourDlg, PipetteClickHdl, ContourWindow*, pWnd )
716 : {
717 0 : if ( pWnd->IsClickValid() )
718 : {
719 0 : Bitmap aMask;
720 0 : const Color& rColor = pWnd->GetPipetteColor();
721 :
722 0 : EnterWait();
723 :
724 0 : if( aGraphic.GetType() == GRAPHIC_BITMAP )
725 : {
726 0 : Bitmap aBmp( aGraphic.GetBitmap() );
727 0 : const long nTol = static_cast<long>(aMtfTolerance.GetValue() * 255L / 100L);
728 :
729 0 : aMask = aBmp.CreateMask( rColor, nTol );
730 :
731 0 : if( aGraphic.IsTransparent() )
732 0 : aMask.CombineSimple( aGraphic.GetBitmapEx().GetMask(), BMP_COMBINE_OR );
733 :
734 0 : if( !!aMask )
735 : {
736 0 : QueryBox aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_NEWPIPETTE ) ) );
737 : sal_Bool bNewContour;
738 :
739 0 : aRedoGraphic = Graphic();
740 0 : aUndoGraphic = aGraphic;
741 0 : aGraphic = Graphic( BitmapEx( aBmp, aMask ) );
742 0 : nGrfChanged++;
743 :
744 0 : bNewContour = ( aQBox.Execute() == RET_YES );
745 0 : pWnd->SetGraphic( aGraphic, bNewContour );
746 :
747 0 : if( bNewContour )
748 0 : aCreateTimer.Start();
749 0 : }
750 : }
751 :
752 0 : LeaveWait();
753 : }
754 :
755 0 : aTbx1.CheckItem( TBI_PIPETTE, sal_False );
756 0 : pWnd->SetPipetteMode( sal_False );
757 0 : aStbStatus.Invalidate();
758 :
759 0 : return 0L;
760 : }
761 :
762 0 : IMPL_LINK( SvxSuperContourDlg, WorkplaceClickHdl, ContourWindow*, pWnd )
763 : {
764 0 : aTbx1.CheckItem( TBI_WORKPLACE, sal_False );
765 0 : aTbx1.CheckItem( TBI_SELECT, sal_True );
766 0 : pWnd->SetWorkplaceMode( sal_False );
767 :
768 0 : return 0L;
769 : }
770 :
771 0 : void SvxSuperContourDlg::ApplyImageList()
772 : {
773 0 : ImageList& rImgLst = maImageList;
774 :
775 0 : aTbx1.SetImageList( rImgLst );
776 0 : }
777 :
778 0 : void SvxSuperContourDlg::DataChanged( const DataChangedEvent& rDCEvt )
779 : {
780 0 : SfxFloatingWindow::DataChanged( rDCEvt );
781 :
782 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
783 0 : ApplyImageList();
784 0 : }
785 :
786 0 : IMPL_LINK_NOARG(SvxSuperContourDlg, MiscHdl)
787 : {
788 0 : SvtMiscOptions aMiscOptions;
789 0 : aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
790 :
791 0 : return 0L;
792 216 : }
793 :
794 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|