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 <tools/shl.hxx>
21 #include <svl/eitem.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/module.hxx>
24 #include <sfx2/sfxsids.hrc>
25 #include <dialmgr.hxx>
26 #include <svx/dlgutil.hxx>
27 #include <editeng/sizeitem.hxx>
28 #include <editeng/brushitem.hxx>
29 #include <grfpage.hxx>
30 #include <svx/grfcrop.hxx>
31 #include <grfpage.hrc>
32 #include <rtl/ustring.hxx>
34 #include <svx/dialogs.hrc> // for RID_SVXPAGE_GRFCROP
36 #define CM_1_TO_TWIP 567
37 #define TWIP_TO_INCH 1440
40 static inline long lcl_GetValue( MetricField
& rMetric
, FieldUnit eUnit
)
42 return static_cast<long>(rMetric
.Denormalize( rMetric
.GetValue( eUnit
)));
45 /*--------------------------------------------------------------------
46 description: crop graphic
47 --------------------------------------------------------------------*/
49 SvxGrfCropPage::SvxGrfCropPage ( Window
*pParent
, const SfxItemSet
&rSet
)
50 : SfxTabPage( pParent
, CUI_RES( RID_SVXPAGE_GRFCROP
), rSet
),
51 aCropFL( this, CUI_RES( FL_CROP
)),
52 aZoomConstRB( this, CUI_RES( RB_ZOOMCONST
)),
53 aSizeConstRB( this, CUI_RES( RB_SIZECONST
)),
54 aLeftFT( this, CUI_RES( FT_LEFT
)),
55 aLeftMF( this, CUI_RES( MF_LEFT
)),
56 aRightFT( this, CUI_RES( FT_RIGHT
)),
57 aRightMF( this, CUI_RES( MF_RIGHT
)),
58 aTopFT( this, CUI_RES( FT_TOP
)),
59 aTopMF( this, CUI_RES( MF_TOP
)),
60 aBottomFT( this, CUI_RES( FT_BOTTOM
)),
61 aBottomMF( this, CUI_RES( MF_BOTTOM
)),
62 aZoomFL( this, CUI_RES( FL_ZOOM
)),
63 aWidthZoomFT( this, CUI_RES( FT_WIDTHZOOM
)),
64 aWidthZoomMF( this, CUI_RES( MF_WIDTHZOOM
)),
65 aHeightZoomFT( this, CUI_RES( FT_HEIGHTZOOM
)),
66 aHeightZoomMF( this, CUI_RES( MF_HEIGHTZOOM
)),
67 aSizeFL( this, CUI_RES( FL_SIZE
)),
68 aWidthFT( this, CUI_RES( FT_WIDTH
)),
69 aWidthMF( this, CUI_RES( MF_WIDTH
)),
70 aHeightFT( this, CUI_RES( FT_HEIGHT
)),
71 aHeightMF( this, CUI_RES( MF_HEIGHT
)),
72 aOrigSizeFT( this, CUI_RES(FT_ORIG_SIZE
)),
73 aOrigSizePB( this, CUI_RES( PB_ORGSIZE
)),
74 aExampleWN( this, CUI_RES( WN_BSP
)),
76 bInitialized(sal_False
),
77 bSetOrigSize(sal_False
)
83 // set the correct metric
84 const FieldUnit eMetric
= GetModuleFieldUnit( rSet
);
86 SetFieldUnit( aWidthMF
, eMetric
);
87 SetFieldUnit( aHeightMF
, eMetric
);
88 SetFieldUnit( aLeftMF
, eMetric
);
89 SetFieldUnit( aRightMF
, eMetric
);
90 SetFieldUnit( aTopMF
, eMetric
);
91 SetFieldUnit( aBottomMF
, eMetric
);
93 Link aLk
= LINK(this, SvxGrfCropPage
, SizeHdl
);
94 aWidthMF
.SetModifyHdl( aLk
);
95 aHeightMF
.SetModifyHdl( aLk
);
97 aLk
= LINK(this, SvxGrfCropPage
, ZoomHdl
);
98 aWidthZoomMF
.SetModifyHdl( aLk
);
99 aHeightZoomMF
.SetModifyHdl( aLk
);
101 aLk
= LINK(this, SvxGrfCropPage
, CropHdl
);
102 aLeftMF
.SetDownHdl( aLk
);
103 aRightMF
.SetDownHdl( aLk
);
104 aTopMF
.SetDownHdl( aLk
);
105 aBottomMF
.SetDownHdl( aLk
);
106 aLeftMF
.SetUpHdl( aLk
);
107 aRightMF
.SetUpHdl( aLk
);
108 aTopMF
.SetUpHdl( aLk
);
109 aBottomMF
.SetUpHdl( aLk
);
111 aLk
= LINK(this, SvxGrfCropPage
, CropModifyHdl
);
112 aLeftMF
.SetModifyHdl( aLk
);
113 aRightMF
.SetModifyHdl( aLk
);
114 aTopMF
.SetModifyHdl( aLk
);
115 aBottomMF
.SetModifyHdl( aLk
);
117 aLk
= LINK(this, SvxGrfCropPage
, CropLoseFocusHdl
);
118 aLeftMF
.SetLoseFocusHdl( aLk
);
119 aRightMF
.SetLoseFocusHdl( aLk
);
120 aTopMF
.SetLoseFocusHdl( aLk
);
121 aBottomMF
.SetLoseFocusHdl( aLk
);
123 aLk
= LINK(this, SvxGrfCropPage
, OrigSizeHdl
);
124 aOrigSizePB
.SetClickHdl( aLk
);
126 aTimer
.SetTimeoutHdl(LINK(this, SvxGrfCropPage
, Timeout
));
127 aTimer
.SetTimeout( 1500 );
129 aOrigSizePB
.SetAccessibleRelationLabeledBy( &aOrigSizeFT
);
132 SvxGrfCropPage::~SvxGrfCropPage()
137 SfxTabPage
* SvxGrfCropPage::Create(Window
*pParent
, const SfxItemSet
&rSet
)
139 return new SvxGrfCropPage( pParent
, rSet
);
142 void SvxGrfCropPage::Reset( const SfxItemSet
&rSet
)
144 const SfxPoolItem
* pItem
;
145 const SfxItemPool
& rPool
= *rSet
.GetPool();
147 if(SFX_ITEM_SET
== rSet
.GetItemState( rPool
.GetWhich(
148 SID_ATTR_GRAF_KEEP_ZOOM
), sal_True
, &pItem
))
150 if( ((const SfxBoolItem
*)pItem
)->GetValue() )
151 aZoomConstRB
.Check();
153 aSizeConstRB
.Check();
154 aZoomConstRB
.SaveValue();
157 sal_uInt16 nW
= rPool
.GetWhich( SID_ATTR_GRAF_CROP
);
158 if( SFX_ITEM_SET
== rSet
.GetItemState( nW
, sal_True
, &pItem
))
160 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
162 SvxGrfCrop
* pCrop
= (SvxGrfCrop
*)pItem
;
164 aExampleWN
.SetLeft( pCrop
->GetLeft());
165 aExampleWN
.SetRight( pCrop
->GetRight());
166 aExampleWN
.SetTop( pCrop
->GetTop());
167 aExampleWN
.SetBottom( pCrop
->GetBottom());
169 aLeftMF
.SetValue( aLeftMF
.Normalize( pCrop
->GetLeft()), eUnit
);
170 aRightMF
.SetValue( aRightMF
.Normalize( pCrop
->GetRight()), eUnit
);
171 aTopMF
.SetValue( aTopMF
.Normalize( pCrop
->GetTop()), eUnit
);
172 aBottomMF
.SetValue( aBottomMF
.Normalize( pCrop
->GetBottom()), eUnit
);
176 aLeftMF
.SetValue( 0 );
177 aRightMF
.SetValue( 0 );
178 aTopMF
.SetValue( 0 );
179 aBottomMF
.SetValue( 0 );
182 nW
= rPool
.GetWhich( SID_ATTR_PAGE_SIZE
);
183 if ( SFX_ITEM_SET
== rSet
.GetItemState( nW
, sal_False
, &pItem
) )
185 // orientation and size from the PageItem
186 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
188 aPageSize
= ((const SvxSizeItem
*)pItem
)->GetSize();
190 sal_Int64 nTmp
= aHeightMF
.Normalize(aPageSize
.Height());
191 aHeightMF
.SetMax( nTmp
, eUnit
);
192 nTmp
= aWidthMF
.Normalize(aPageSize
.Width());
193 aWidthMF
.SetMax( nTmp
, eUnit
);
194 nTmp
= aWidthMF
.Normalize( 23 );
195 aHeightMF
.SetMin( nTmp
, eUnit
);
196 aWidthMF
.SetMin( nTmp
, eUnit
);
200 aPageSize
= OutputDevice::LogicToLogic(
201 Size( CM_1_TO_TWIP
, CM_1_TO_TWIP
),
203 MapMode( (MapUnit
)rSet
.GetPool()->GetMetric( nW
) ) );
206 sal_Bool bFound
= sal_False
;
207 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_GRAPHIC
, sal_False
, &pItem
) )
209 const Graphic
* pGrf
= ((SvxBrushItem
*)pItem
)->GetGraphic();
211 aOrigSize
= GetGrfOrigSize( *pGrf
);
212 if (pGrf
->GetType() == GRAPHIC_BITMAP
&& aOrigSize
.Width() && aOrigSize
.Height()) {
213 Bitmap aBitmap
= pGrf
->GetBitmap();
214 aOrigPixelSize
= aBitmap
.GetSizePixel();
218 if( aOrigSize
.Width() && aOrigSize
.Height() )
221 aExampleWN
.SetGraphic( *pGrf
);
222 aExampleWN
.SetFrameSize( aOrigSize
);
225 if( ((SvxBrushItem
*)pItem
)->GetGraphicLink() )
226 aGraphicName
= *((SvxBrushItem
*)pItem
)->GetGraphicLink();
230 GraphicHasChanged( bFound
);
232 ActivatePage( rSet
);
236 sal_Bool
SvxGrfCropPage::FillItemSet(SfxItemSet
&rSet
)
238 const SfxItemPool
& rPool
= *rSet
.GetPool();
239 sal_Bool bModified
= sal_False
;
240 if( aWidthMF
.GetSavedValue() != aWidthMF
.GetText() ||
241 aHeightMF
.GetSavedValue() != aHeightMF
.GetText() )
243 sal_uInt16 nW
= rPool
.GetWhich( SID_ATTR_GRAF_FRMSIZE
);
244 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
246 SvxSizeItem
aSz( nW
);
248 // size could already have been set from another page
250 const SfxItemSet
* pExSet
= GetTabDialog() ? GetTabDialog()->GetExampleSet() : NULL
;
251 const SfxPoolItem
* pItem
= 0;
252 if( pExSet
&& SFX_ITEM_SET
==
253 pExSet
->GetItemState( nW
, sal_False
, &pItem
) )
254 aSz
= *(const SvxSizeItem
*)pItem
;
256 aSz
= (const SvxSizeItem
&)GetItemSet().Get( nW
);
258 Size
aTmpSz( aSz
.GetSize() );
259 if( aWidthMF
.GetText() != aWidthMF
.GetSavedValue() )
260 aTmpSz
.Width() = lcl_GetValue( aWidthMF
, eUnit
);
261 if( aHeightMF
.GetText() != aHeightMF
.GetSavedValue() )
262 aTmpSz
.Height() = lcl_GetValue( aHeightMF
, eUnit
);
263 aSz
.SetSize( aTmpSz
);
264 aWidthMF
.SaveValue();
265 aHeightMF
.SaveValue();
267 bModified
|= 0 != rSet
.Put( aSz
);
271 bModified
|= 0 != rSet
.Put( SvxSizeItem( rPool
.GetWhich(
272 SID_ATTR_GRAF_FRMSIZE_PERCENT
), Size( 0, 0 )) );
275 if( aLeftMF
.IsModified() || aRightMF
.IsModified() ||
276 aTopMF
.IsModified() || aBottomMF
.IsModified() )
278 sal_uInt16 nW
= rPool
.GetWhich( SID_ATTR_GRAF_CROP
);
279 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
280 SvxGrfCrop
* pNew
= (SvxGrfCrop
*)rSet
.Get( nW
).Clone();
282 pNew
->SetLeft( lcl_GetValue( aLeftMF
, eUnit
) );
283 pNew
->SetRight( lcl_GetValue( aRightMF
, eUnit
) );
284 pNew
->SetTop( lcl_GetValue( aTopMF
, eUnit
) );
285 pNew
->SetBottom( lcl_GetValue( aBottomMF
, eUnit
) );
286 bModified
|= 0 != rSet
.Put( *pNew
);
290 if( aZoomConstRB
.GetSavedValue() != aZoomConstRB
.IsChecked() )
292 bModified
|= 0 != rSet
.Put( SfxBoolItem( rPool
.GetWhich(
293 SID_ATTR_GRAF_KEEP_ZOOM
), aZoomConstRB
.IsChecked() ) );
296 bInitialized
= sal_False
;
301 void SvxGrfCropPage::ActivatePage(const SfxItemSet
& rSet
)
304 SfxItemPool
* pPool
= GetItemSet().GetPool();
305 DBG_ASSERT( pPool
, "Wo ist der Pool" );
308 bSetOrigSize
= sal_False
;
312 const SfxPoolItem
* pItem
;
313 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_FRMSIZE
, sal_False
, &pItem
) )
314 aSize
= ((const SvxSizeItem
*)pItem
)->GetSize();
316 nOldWidth
= aSize
.Width();
317 nOldHeight
= aSize
.Height();
319 sal_Int64 nWidth
= aWidthMF
.Normalize(nOldWidth
);
320 sal_Int64 nHeight
= aHeightMF
.Normalize(nOldHeight
);
322 if (nWidth
!= aWidthMF
.GetValue(FUNIT_TWIP
))
326 // value was changed by wrap-tabpage and has to
327 // be set with modify-flag
328 aWidthMF
.SetUserValue(nWidth
, FUNIT_TWIP
);
331 aWidthMF
.SetValue(nWidth
, FUNIT_TWIP
);
333 aWidthMF
.SaveValue();
335 if (nHeight
!= aHeightMF
.GetValue(FUNIT_TWIP
))
339 // value was changed by wrap-tabpage and has to
340 // be set with modify-flag
341 aHeightMF
.SetUserValue(nHeight
, FUNIT_TWIP
);
344 aHeightMF
.SetValue(nHeight
, FUNIT_TWIP
);
346 aHeightMF
.SaveValue();
347 bInitialized
= sal_True
;
349 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_GRAPHIC
, sal_False
, &pItem
) )
351 const SvxBrushItem
& rBrush
= *(SvxBrushItem
*)pItem
;
352 if( rBrush
.GetGraphicLink() &&
353 aGraphicName
!= *rBrush
.GetGraphicLink() )
354 aGraphicName
= *rBrush
.GetGraphicLink();
356 const Graphic
* pGrf
= rBrush
.GetGraphic();
359 aExampleWN
.SetGraphic( *pGrf
);
360 aOrigSize
= GetGrfOrigSize( *pGrf
);
361 if (pGrf
->GetType() == GRAPHIC_BITMAP
&& aOrigSize
.Width() > 1 && aOrigSize
.Height() > 1) {
362 Bitmap aBitmap
= pGrf
->GetBitmap();
363 aOrigPixelSize
= aBitmap
.GetSizePixel();
365 aExampleWN
.SetFrameSize(aOrigSize
);
366 GraphicHasChanged( aOrigSize
.Width() && aOrigSize
.Height() );
370 GraphicHasChanged( sal_False
);
376 int SvxGrfCropPage::DeactivatePage(SfxItemSet
*_pSet
)
379 FillItemSet( *_pSet
);
383 /*--------------------------------------------------------------------
384 description: scale changed, adjust size
385 --------------------------------------------------------------------*/
387 IMPL_LINK( SvxGrfCropPage
, ZoomHdl
, MetricField
*, pField
)
389 SfxItemPool
* pPool
= GetItemSet().GetPool();
390 DBG_ASSERT( pPool
, "Wo ist der Pool" );
391 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
392 SID_ATTR_GRAF_CROP
) ) );
394 if( pField
== &aWidthZoomMF
)
396 long nLRBorders
= lcl_GetValue(aLeftMF
, eUnit
)
397 +lcl_GetValue(aRightMF
, eUnit
);
398 aWidthMF
.SetValue( aWidthMF
.Normalize(
399 ((aOrigSize
.Width() - nLRBorders
) * pField
->GetValue())/100L),
404 long nULBorders
= lcl_GetValue(aTopMF
, eUnit
)
405 +lcl_GetValue(aBottomMF
, eUnit
);
406 aHeightMF
.SetValue( aHeightMF
.Normalize(
407 ((aOrigSize
.Height() - nULBorders
) * pField
->GetValue())/100L) ,
414 /*--------------------------------------------------------------------
415 description: change size, adjust scale
416 --------------------------------------------------------------------*/
418 IMPL_LINK( SvxGrfCropPage
, SizeHdl
, MetricField
*, pField
)
420 SfxItemPool
* pPool
= GetItemSet().GetPool();
421 DBG_ASSERT( pPool
, "Wo ist der Pool" );
422 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
423 SID_ATTR_GRAF_CROP
) ) );
425 Size
aSize( lcl_GetValue(aWidthMF
, eUnit
),
426 lcl_GetValue(aHeightMF
, eUnit
) );
428 if(pField
== &aWidthMF
)
430 long nWidth
= aOrigSize
.Width() -
431 ( lcl_GetValue(aLeftMF
, eUnit
) +
432 lcl_GetValue(aRightMF
, eUnit
) );
435 sal_uInt16 nZoom
= (sal_uInt16
)( aSize
.Width() * 100L / nWidth
);
436 aWidthZoomMF
.SetValue(nZoom
);
440 long nHeight
= aOrigSize
.Height() -
441 ( lcl_GetValue(aTopMF
, eUnit
) +
442 lcl_GetValue(aBottomMF
, eUnit
));
445 sal_uInt16 nZoom
= (sal_uInt16
)( aSize
.Height() * 100L/ nHeight
);
446 aHeightZoomMF
.SetValue(nZoom
);
452 /*--------------------------------------------------------------------
453 description: evaluate border
454 --------------------------------------------------------------------*/
456 IMPL_LINK( SvxGrfCropPage
, CropHdl
, const MetricField
*, pField
)
458 SfxItemPool
* pPool
= GetItemSet().GetPool();
459 DBG_ASSERT( pPool
, "Wo ist der Pool" );
460 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
461 SID_ATTR_GRAF_CROP
) ) );
463 sal_Bool bZoom
= aZoomConstRB
.IsChecked();
464 if( pField
== &aLeftMF
|| pField
== &aRightMF
)
466 long nLeft
= lcl_GetValue( aLeftMF
, eUnit
);
467 long nRight
= lcl_GetValue( aRightMF
, eUnit
);
468 long nWidthZoom
= static_cast<long>(aWidthZoomMF
.GetValue());
469 if(bZoom
&& ( ( ( aOrigSize
.Width() - (nLeft
+ nRight
)) * nWidthZoom
)
470 / 100 >= aPageSize
.Width() ) )
472 if(pField
== &aLeftMF
)
474 nLeft
= aOrigSize
.Width() -
475 ( aPageSize
.Width() * 100 / nWidthZoom
+ nRight
);
476 aLeftMF
.SetValue( aLeftMF
.Normalize( nLeft
), eUnit
);
480 nRight
= aOrigSize
.Width() -
481 ( aPageSize
.Width() * 100 / nWidthZoom
+ nLeft
);
482 aRightMF
.SetValue( aRightMF
.Normalize( nRight
), eUnit
);
485 aExampleWN
.SetLeft(nLeft
);
486 aExampleWN
.SetRight(nRight
);
489 // scale stays, recompute width
490 ZoomHdl(&aWidthZoomMF
);
495 long nTop
= lcl_GetValue( aTopMF
, eUnit
);
496 long nBottom
= lcl_GetValue( aBottomMF
, eUnit
);
497 long nHeightZoom
= static_cast<long>(aHeightZoomMF
.GetValue());
498 if(bZoom
&& ( ( ( aOrigSize
.Height() - (nTop
+ nBottom
)) * nHeightZoom
)
499 / 100 >= aPageSize
.Height()))
501 if(pField
== &aTopMF
)
503 nTop
= aOrigSize
.Height() -
504 ( aPageSize
.Height() * 100 / nHeightZoom
+ nBottom
);
505 aTopMF
.SetValue( aWidthMF
.Normalize( nTop
), eUnit
);
509 nBottom
= aOrigSize
.Height() -
510 ( aPageSize
.Height() * 100 / nHeightZoom
+ nTop
);
511 aBottomMF
.SetValue( aWidthMF
.Normalize( nBottom
), eUnit
);
514 aExampleWN
.SetTop( nTop
);
515 aExampleWN
.SetBottom( nBottom
);
518 // scale stays, recompute height
519 ZoomHdl(&aHeightZoomMF
);
522 aExampleWN
.Invalidate();
523 // size and border changed -> recompute scale
529 /*--------------------------------------------------------------------
530 description: set original size
531 --------------------------------------------------------------------*/
533 IMPL_LINK_NOARG(SvxGrfCropPage
, OrigSizeHdl
)
535 SfxItemPool
* pPool
= GetItemSet().GetPool();
536 DBG_ASSERT( pPool
, "Wo ist der Pool" );
537 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
538 SID_ATTR_GRAF_CROP
) ) );
540 long nWidth
= aOrigSize
.Width() -
541 lcl_GetValue( aLeftMF
, eUnit
) -
542 lcl_GetValue( aRightMF
, eUnit
);
543 aWidthMF
.SetValue( aWidthMF
.Normalize( nWidth
), eUnit
);
544 long nHeight
= aOrigSize
.Height() -
545 lcl_GetValue( aTopMF
, eUnit
) -
546 lcl_GetValue( aBottomMF
, eUnit
);
547 aHeightMF
.SetValue( aHeightMF
.Normalize( nHeight
), eUnit
);
548 aWidthZoomMF
.SetValue(100);
549 aHeightZoomMF
.SetValue(100);
550 bSetOrigSize
= sal_True
;
553 /*--------------------------------------------------------------------
554 description: compute scale
555 --------------------------------------------------------------------*/
557 void SvxGrfCropPage::CalcZoom()
559 SfxItemPool
* pPool
= GetItemSet().GetPool();
560 DBG_ASSERT( pPool
, "Wo ist der Pool" );
561 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
562 SID_ATTR_GRAF_CROP
) ) );
564 long nWidth
= lcl_GetValue( aWidthMF
, eUnit
);
565 long nHeight
= lcl_GetValue( aHeightMF
, eUnit
);
566 long nLRBorders
= lcl_GetValue( aLeftMF
, eUnit
) +
567 lcl_GetValue( aRightMF
, eUnit
);
568 long nULBorders
= lcl_GetValue( aTopMF
, eUnit
) +
569 lcl_GetValue( aBottomMF
, eUnit
);
570 sal_uInt16 nZoom
= 0;
572 if( (nDen
= aOrigSize
.Width() - nLRBorders
) > 0)
573 nZoom
= (sal_uInt16
)((( nWidth
* 1000L / nDen
)+5)/10);
574 aWidthZoomMF
.SetValue(nZoom
);
575 if( (nDen
= aOrigSize
.Height() - nULBorders
) > 0)
576 nZoom
= (sal_uInt16
)((( nHeight
* 1000L / nDen
)+5)/10);
579 aHeightZoomMF
.SetValue(nZoom
);
582 /*--------------------------------------------------------------------
583 description: set minimum/maximum values for the margins
584 --------------------------------------------------------------------*/
586 void SvxGrfCropPage::CalcMinMaxBorder()
588 SfxItemPool
* pPool
= GetItemSet().GetPool();
589 DBG_ASSERT( pPool
, "Wo ist der Pool" );
590 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
591 SID_ATTR_GRAF_CROP
) ) );
592 long nR
= lcl_GetValue(aRightMF
, eUnit
);
593 long nMinWidth
= (aOrigSize
.Width() * 10) /11;
594 long nMin
= nMinWidth
- (nR
>= 0 ? nR
: 0);
595 aLeftMF
.SetMax( aLeftMF
.Normalize(nMin
), eUnit
);
597 long nL
= lcl_GetValue(aLeftMF
, eUnit
);
598 nMin
= nMinWidth
- (nL
>= 0 ? nL
: 0);
599 aRightMF
.SetMax( aRightMF
.Normalize(nMin
), eUnit
);
601 long nUp
= lcl_GetValue( aTopMF
, eUnit
);
602 long nMinHeight
= (aOrigSize
.Height() * 10) /11;
603 nMin
= nMinHeight
- (nUp
>= 0 ? nUp
: 0);
604 aBottomMF
.SetMax( aBottomMF
.Normalize(nMin
), eUnit
);
606 long nLow
= lcl_GetValue(aBottomMF
, eUnit
);
607 nMin
= nMinHeight
- (nLow
>= 0 ? nLow
: 0);
608 aTopMF
.SetMax( aTopMF
.Normalize(nMin
), eUnit
);
610 /*--------------------------------------------------------------------
611 description: set spinsize to 1/20 of the original size,
612 fill FixedText with the original size
613 --------------------------------------------------------------------*/
615 void SvxGrfCropPage::GraphicHasChanged( sal_Bool bFound
)
619 SfxItemPool
* pPool
= GetItemSet().GetPool();
620 DBG_ASSERT( pPool
, "Wo ist der Pool" );
621 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
622 SID_ATTR_GRAF_CROP
) ));
624 sal_Int64 nSpin
= aLeftMF
.Normalize(aOrigSize
.Width()) / 20;
625 nSpin
= MetricField::ConvertValue( nSpin
, aOrigSize
.Width(), 0,
626 eUnit
, aLeftMF
.GetUnit());
628 // if the margin is too big, it is set to 1/3 on both pages
629 long nR
= lcl_GetValue( aRightMF
, eUnit
);
630 long nL
= lcl_GetValue( aLeftMF
, eUnit
);
631 if((nL
+ nR
) < - aOrigSize
.Width())
633 long nVal
= aOrigSize
.Width() / -3;
634 aRightMF
.SetValue( aRightMF
.Normalize( nVal
), eUnit
);
635 aLeftMF
.SetValue( aLeftMF
.Normalize( nVal
), eUnit
);
636 aExampleWN
.SetLeft(nVal
);
637 aExampleWN
.SetRight(nVal
);
639 long nUp
= lcl_GetValue(aTopMF
, eUnit
);
640 long nLow
= lcl_GetValue(aBottomMF
, eUnit
);
641 if((nUp
+ nLow
) < - aOrigSize
.Height())
643 long nVal
= aOrigSize
.Height() / -3;
644 aTopMF
.SetValue( aTopMF
.Normalize( nVal
), eUnit
);
645 aBottomMF
.SetValue( aBottomMF
.Normalize( nVal
), eUnit
);
646 aExampleWN
.SetTop(nVal
);
647 aExampleWN
.SetBottom(nVal
);
650 aLeftMF
.SetSpinSize(nSpin
);
651 aRightMF
.SetSpinSize(nSpin
);
652 nSpin
= aTopMF
.Normalize(aOrigSize
.Height()) / 20;
653 nSpin
= MetricField::ConvertValue( nSpin
, aOrigSize
.Width(), 0,
654 eUnit
, aLeftMF
.GetUnit() );
655 aTopMF
.SetSpinSize(nSpin
);
656 aBottomMF
.SetSpinSize(nSpin
);
658 // display original size
659 const FieldUnit eMetric
= GetModuleFieldUnit( GetItemSet() );
661 MetricField
aFld(this, WB_HIDE
);
662 SetFieldUnit( aFld
, eMetric
);
663 aFld
.SetDecimalDigits( aWidthMF
.GetDecimalDigits() );
664 aFld
.SetMax( LONG_MAX
- 1 );
666 aFld
.SetValue( aFld
.Normalize( aOrigSize
.Width() ), eUnit
);
667 OUString sTemp
= aFld
.GetText();
668 aFld
.SetValue( aFld
.Normalize( aOrigSize
.Height() ), eUnit
);
669 // multiplication sign (U+00D7)
670 sTemp
+= OUString( sal_Unicode (0x00D7) );
671 sTemp
+= aFld
.GetText();
673 if ( aOrigPixelSize
.Width() && aOrigPixelSize
.Height() ) {
674 sal_Int32 ax
= sal_Int32(floor((float)aOrigPixelSize
.Width() /
675 ((float)aOrigSize
.Width()/TWIP_TO_INCH
)+0.5));
676 sal_Int32 ay
= sal_Int32(floor((float)aOrigPixelSize
.Height() /
677 ((float)aOrigSize
.Height()/TWIP_TO_INCH
)+0.5));
679 sTemp
+= CUI_RESSTR( STR_PPI
);
680 OUString sPPI
= OUString::valueOf(ax
);
681 if (abs(ax
- ay
) > 1) {
682 sPPI
+= OUString( sal_Unicode (0x00D7) );
683 sPPI
+= OUString::valueOf(ay
);
685 sTemp
= sTemp
.replaceAll("%1", sPPI
);
687 aOrigSizeFT
.SetText( sTemp
);
689 aLeftFT
.Enable(bFound
);
690 aLeftMF
.Enable(bFound
);
691 aRightFT
.Enable(bFound
);
692 aRightMF
.Enable(bFound
);
693 aTopFT
.Enable(bFound
);
694 aTopMF
.Enable(bFound
);
695 aBottomFT
.Enable(bFound
);
696 aBottomMF
.Enable(bFound
);
697 aSizeConstRB
.Enable(bFound
);
698 aZoomConstRB
.Enable(bFound
);
699 aWidthFT
.Enable(bFound
);
700 aWidthMF
.Enable(bFound
);
701 aHeightFT
.Enable(bFound
);
702 aHeightMF
.Enable(bFound
);
703 aWidthZoomFT
.Enable(bFound
);
704 aWidthZoomMF
.Enable(bFound
);
705 aHeightZoomFT
.Enable(bFound
);
706 aHeightZoomMF
.Enable(bFound
);
707 aExampleWN
.Enable(bFound
);
708 aOrigSizePB
.Enable(bFound
);
709 aOrigSizeFT
.Enable(bFound
);
712 IMPL_LINK_NOARG(SvxGrfCropPage
, Timeout
)
714 DBG_ASSERT(pLastCropField
,"Timeout ohne Feld?");
715 CropHdl(pLastCropField
);
721 IMPL_LINK( SvxGrfCropPage
, CropLoseFocusHdl
, MetricField
*, pField
)
730 IMPL_LINK( SvxGrfCropPage
, CropModifyHdl
, MetricField
*, pField
)
733 pLastCropField
= pField
;
737 Size
SvxGrfCropPage::GetGrfOrigSize( const Graphic
& rGrf
) const
739 const MapMode
aMapTwip( MAP_TWIP
);
740 Size
aSize( rGrf
.GetPrefSize() );
741 if( MAP_PIXEL
== rGrf
.GetPrefMapMode().GetMapUnit() )
742 aSize
= PixelToLogic( aSize
, aMapTwip
);
744 aSize
= OutputDevice::LogicToLogic( aSize
,
745 rGrf
.GetPrefMapMode(), aMapTwip
);
749 /*****************************************************************/
751 SvxGrfCropPage::SvxCropExample::SvxCropExample( Window
* pPar
,
752 const ResId
& rResId
)
753 : Window( pPar
, rResId
),
754 aFrameSize( OutputDevice::LogicToLogic(
755 Size( CM_1_TO_TWIP
/ 2, CM_1_TO_TWIP
/ 2 ),
756 MapMode( MAP_TWIP
), GetMapMode() )),
757 aTopLeft(0,0), aBottomRight(0,0)
759 SetBorderStyle( WINDOW_BORDER_MONO
);
762 void SvxGrfCropPage::SvxCropExample::Paint( const Rectangle
& )
764 Size
aWinSize( PixelToLogic(GetOutputSizePixel() ));
766 SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
767 SetRasterOp( ROP_OVERPAINT
);
768 DrawRect( Rectangle( Point(), aWinSize
) );
770 SetLineColor( Color( COL_WHITE
) );
771 Rectangle
aRect(Point((aWinSize
.Width() - aFrameSize
.Width())/2,
772 (aWinSize
.Height() - aFrameSize
.Height())/2),
774 aGrf
.Draw( this, aRect
.TopLeft(), aRect
.GetSize() );
777 aSz
= PixelToLogic( aSz
);
778 SetFillColor( Color( COL_TRANSPARENT
) );
779 SetRasterOp( ROP_INVERT
);
780 aRect
.Left() += aTopLeft
.Y();
781 aRect
.Top() += aTopLeft
.X();
782 aRect
.Right() -= aBottomRight
.Y();
783 aRect
.Bottom() -= aBottomRight
.X();
787 void SvxGrfCropPage::SvxCropExample::SetFrameSize( const Size
& rSz
)
790 if(!aFrameSize
.Width())
791 aFrameSize
.Width() = 1;
792 if(!aFrameSize
.Height())
793 aFrameSize
.Height() = 1;
794 Size
aWinSize( GetOutputSizePixel() );
795 Fraction
aXScale( aWinSize
.Width() * 4, aFrameSize
.Width() * 5 );
796 Fraction
aYScale( aWinSize
.Height() * 4, aFrameSize
.Height() * 5 );
798 if( aYScale
< aXScale
)
801 MapMode
aMapMode( GetMapMode() );
803 aMapMode
.SetScaleX( aXScale
);
804 aMapMode
.SetScaleY( aXScale
);
806 SetMapMode( aMapMode
);
810 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */