1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 #include <tools/shl.hxx>
32 #include <svl/eitem.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/module.hxx>
35 #include <sfx2/sfxsids.hrc>
36 #include <dialmgr.hxx>
37 #include <svx/dlgutil.hxx>
38 #include <editeng/sizeitem.hxx>
39 #include <editeng/brshitem.hxx>
40 #include <grfpage.hxx>
41 #include <svx/grfcrop.hxx>
42 #include <grfpage.hrc>
44 #include <svx/dialogs.hrc> // for RID_SVXPAGE_GRFCROP
46 #define CM_1_TO_TWIP 567
49 inline long lcl_GetValue( MetricField
& rMetric
, FieldUnit eUnit
)
51 return static_cast<long>(rMetric
.Denormalize( rMetric
.GetValue( eUnit
)));
54 /*--------------------------------------------------------------------
55 Beschreibung: Grafik zuschneiden
56 --------------------------------------------------------------------*/
58 SvxGrfCropPage::SvxGrfCropPage ( Window
*pParent
, const SfxItemSet
&rSet
)
59 : SfxTabPage( pParent
, CUI_RES( RID_SVXPAGE_GRFCROP
), rSet
),
60 aCropFL( this, CUI_RES( FL_CROP
)),
61 aZoomConstRB( this, CUI_RES( RB_ZOOMCONST
)),
62 aSizeConstRB( this, CUI_RES( RB_SIZECONST
)),
63 aLeftFT( this, CUI_RES( FT_LEFT
)),
64 aLeftMF( this, CUI_RES( MF_LEFT
)),
65 aRightFT( this, CUI_RES( FT_RIGHT
)),
66 aRightMF( this, CUI_RES( MF_RIGHT
)),
67 aTopFT( this, CUI_RES( FT_TOP
)),
68 aTopMF( this, CUI_RES( MF_TOP
)),
69 aBottomFT( this, CUI_RES( FT_BOTTOM
)),
70 aBottomMF( this, CUI_RES( MF_BOTTOM
)),
71 aZoomFL( this, CUI_RES( FL_ZOOM
)),
72 aWidthZoomFT( this, CUI_RES( FT_WIDTHZOOM
)),
73 aWidthZoomMF( this, CUI_RES( MF_WIDTHZOOM
)),
74 aHeightZoomFT( this, CUI_RES( FT_HEIGHTZOOM
)),
75 aHeightZoomMF( this, CUI_RES( MF_HEIGHTZOOM
)),
76 aSizeFL( this, CUI_RES( FL_SIZE
)),
77 aWidthFT( this, CUI_RES( FT_WIDTH
)),
78 aWidthMF( this, CUI_RES( MF_WIDTH
)),
79 aHeightFT( this, CUI_RES( FT_HEIGHT
)),
80 aHeightMF( this, CUI_RES( MF_HEIGHT
)),
81 aOrigSizeFT( this, CUI_RES(FT_ORIG_SIZE
)),
82 aOrigSizePB( this, CUI_RES( PB_ORGSIZE
)),
83 aExampleWN( this, CUI_RES( WN_BSP
)),
85 bInitialized(sal_False
),
86 bSetOrigSize(sal_False
)
92 // set the correct metric
93 const FieldUnit eMetric
= GetModuleFieldUnit( rSet
);
95 SetFieldUnit( aWidthMF
, eMetric
);
96 SetFieldUnit( aHeightMF
, eMetric
);
97 SetFieldUnit( aLeftMF
, eMetric
);
98 SetFieldUnit( aRightMF
, eMetric
);
99 SetFieldUnit( aTopMF
, eMetric
);
100 SetFieldUnit( aBottomMF
, eMetric
);
102 Link aLk
= LINK(this, SvxGrfCropPage
, SizeHdl
);
103 aWidthMF
.SetModifyHdl( aLk
);
104 aHeightMF
.SetModifyHdl( aLk
);
106 aLk
= LINK(this, SvxGrfCropPage
, ZoomHdl
);
107 aWidthZoomMF
.SetModifyHdl( aLk
);
108 aHeightZoomMF
.SetModifyHdl( aLk
);
110 aLk
= LINK(this, SvxGrfCropPage
, CropHdl
);
111 aLeftMF
.SetDownHdl( aLk
);
112 aRightMF
.SetDownHdl( aLk
);
113 aTopMF
.SetDownHdl( aLk
);
114 aBottomMF
.SetDownHdl( aLk
);
115 aLeftMF
.SetUpHdl( aLk
);
116 aRightMF
.SetUpHdl( aLk
);
117 aTopMF
.SetUpHdl( aLk
);
118 aBottomMF
.SetUpHdl( aLk
);
120 aLk
= LINK(this, SvxGrfCropPage
, CropModifyHdl
);
121 aLeftMF
.SetModifyHdl( aLk
);
122 aRightMF
.SetModifyHdl( aLk
);
123 aTopMF
.SetModifyHdl( aLk
);
124 aBottomMF
.SetModifyHdl( aLk
);
126 aLk
= LINK(this, SvxGrfCropPage
, CropLoseFocusHdl
);
127 aLeftMF
.SetLoseFocusHdl( aLk
);
128 aRightMF
.SetLoseFocusHdl( aLk
);
129 aTopMF
.SetLoseFocusHdl( aLk
);
130 aBottomMF
.SetLoseFocusHdl( aLk
);
132 aLk
= LINK(this, SvxGrfCropPage
, OrigSizeHdl
);
133 aOrigSizePB
.SetClickHdl( aLk
);
135 aTimer
.SetTimeoutHdl(LINK(this, SvxGrfCropPage
, Timeout
));
136 aTimer
.SetTimeout( 1500 );
138 aOrigSizePB
.SetAccessibleRelationLabeledBy( &aOrigSizeFT
);
141 /*--------------------------------------------------------------------
143 --------------------------------------------------------------------*/
145 SvxGrfCropPage::~SvxGrfCropPage()
150 /*--------------------------------------------------------------------
152 --------------------------------------------------------------------*/
154 SfxTabPage
* SvxGrfCropPage::Create(Window
*pParent
, const SfxItemSet
&rSet
)
156 return new SvxGrfCropPage( pParent
, rSet
);
158 /*--------------------------------------------------------------------
160 --------------------------------------------------------------------*/
162 void SvxGrfCropPage::Reset( const SfxItemSet
&rSet
)
164 const SfxPoolItem
* pItem
;
165 const SfxItemPool
& rPool
= *rSet
.GetPool();
167 if(SFX_ITEM_SET
== rSet
.GetItemState( rPool
.GetWhich(
168 SID_ATTR_GRAF_KEEP_ZOOM
), sal_True
, &pItem
))
170 if( ((const SfxBoolItem
*)pItem
)->GetValue() )
171 aZoomConstRB
.Check();
173 aSizeConstRB
.Check();
174 aZoomConstRB
.SaveValue();
177 sal_uInt16 nW
= rPool
.GetWhich( SID_ATTR_GRAF_CROP
);
178 if( SFX_ITEM_SET
== rSet
.GetItemState( nW
, sal_True
, &pItem
))
180 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
182 SvxGrfCrop
* pCrop
= (SvxGrfCrop
*)pItem
;
184 aExampleWN
.SetLeft( pCrop
->GetLeft());
185 aExampleWN
.SetRight( pCrop
->GetRight());
186 aExampleWN
.SetTop( pCrop
->GetTop());
187 aExampleWN
.SetBottom( pCrop
->GetBottom());
189 aLeftMF
.SetValue( aLeftMF
.Normalize( pCrop
->GetLeft()), eUnit
);
190 aRightMF
.SetValue( aRightMF
.Normalize( pCrop
->GetRight()), eUnit
);
191 aTopMF
.SetValue( aTopMF
.Normalize( pCrop
->GetTop()), eUnit
);
192 aBottomMF
.SetValue( aBottomMF
.Normalize( pCrop
->GetBottom()), eUnit
);
196 aLeftMF
.SetValue( 0 );
197 aRightMF
.SetValue( 0 );
198 aTopMF
.SetValue( 0 );
199 aBottomMF
.SetValue( 0 );
202 nW
= rPool
.GetWhich( SID_ATTR_PAGE_SIZE
);
203 if ( SFX_ITEM_SET
== rSet
.GetItemState( nW
, sal_False
, &pItem
) )
205 // Orientation und Size aus dem PageItem
206 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
208 aPageSize
= ((const SvxSizeItem
*)pItem
)->GetSize();
210 sal_Int64 nTmp
= aHeightMF
.Normalize(aPageSize
.Height());
211 aHeightMF
.SetMax( nTmp
, eUnit
);
212 nTmp
= aWidthMF
.Normalize(aPageSize
.Width());
213 aWidthMF
.SetMax( nTmp
, eUnit
);
214 nTmp
= aWidthMF
.Normalize( 23 );
215 aHeightMF
.SetMin( nTmp
, eUnit
);
216 aWidthMF
.SetMin( nTmp
, eUnit
);
220 aPageSize
= OutputDevice::LogicToLogic(
221 Size( CM_1_TO_TWIP
, CM_1_TO_TWIP
),
223 MapMode( (MapUnit
)rSet
.GetPool()->GetMetric( nW
) ) );
226 sal_Bool bFound
= sal_False
;
227 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_GRAPHIC
, sal_False
, &pItem
) )
229 const Graphic
* pGrf
= ((SvxBrushItem
*)pItem
)->GetGraphic();
231 aOrigSize
= GetGrfOrigSize( *pGrf
);
233 if( aOrigSize
.Width() && aOrigSize
.Height() )
236 aExampleWN
.SetGraphic( *pGrf
);
237 aExampleWN
.SetFrameSize( aOrigSize
);
240 if( ((SvxBrushItem
*)pItem
)->GetGraphicLink() )
241 aGraphicName
= *((SvxBrushItem
*)pItem
)->GetGraphicLink();
245 GraphicHasChanged( bFound
);
247 ActivatePage( rSet
);
251 /*--------------------------------------------------------------------
253 --------------------------------------------------------------------*/
255 sal_Bool
SvxGrfCropPage::FillItemSet(SfxItemSet
&rSet
)
257 const SfxItemPool
& rPool
= *rSet
.GetPool();
258 sal_Bool bModified
= sal_False
;
259 if( aWidthMF
.GetSavedValue() != aWidthMF
.GetText() ||
260 aHeightMF
.GetSavedValue() != aHeightMF
.GetText() )
262 sal_uInt16 nW
= rPool
.GetWhich( SID_ATTR_GRAF_FRMSIZE
);
263 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
265 SvxSizeItem
aSz( nW
);
267 // die Groesse koennte schon von einer anderen Page gesetzt worden sein
269 const SfxItemSet
* pExSet
= GetTabDialog() ? GetTabDialog()->GetExampleSet() : NULL
;
270 const SfxPoolItem
* pItem
= 0;
271 if( pExSet
&& SFX_ITEM_SET
==
272 pExSet
->GetItemState( nW
, sal_False
, &pItem
) )
273 aSz
= *(const SvxSizeItem
*)pItem
;
275 aSz
= (const SvxSizeItem
&)GetItemSet().Get( nW
);
277 Size
aTmpSz( aSz
.GetSize() );
278 if( aWidthMF
.GetText() != aWidthMF
.GetSavedValue() )
279 aTmpSz
.Width() = lcl_GetValue( aWidthMF
, eUnit
);
280 if( aHeightMF
.GetText() != aHeightMF
.GetSavedValue() )
281 aTmpSz
.Height() = lcl_GetValue( aHeightMF
, eUnit
);
282 aSz
.SetSize( aTmpSz
);
283 aWidthMF
.SaveValue();
284 aHeightMF
.SaveValue();
286 bModified
|= 0 != rSet
.Put( aSz
);
290 bModified
|= 0 != rSet
.Put( SvxSizeItem( rPool
.GetWhich(
291 SID_ATTR_GRAF_FRMSIZE_PERCENT
), Size( 0, 0 )) );
294 if( aLeftMF
.IsModified() || aRightMF
.IsModified() ||
295 aTopMF
.IsModified() || aBottomMF
.IsModified() )
297 sal_uInt16 nW
= rPool
.GetWhich( SID_ATTR_GRAF_CROP
);
298 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
299 SvxGrfCrop
* pNew
= (SvxGrfCrop
*)rSet
.Get( nW
).Clone();
301 pNew
->SetLeft( lcl_GetValue( aLeftMF
, eUnit
) );
302 pNew
->SetRight( lcl_GetValue( aRightMF
, eUnit
) );
303 pNew
->SetTop( lcl_GetValue( aTopMF
, eUnit
) );
304 pNew
->SetBottom( lcl_GetValue( aBottomMF
, eUnit
) );
305 bModified
|= 0 != rSet
.Put( *pNew
);
309 if( aZoomConstRB
.GetSavedValue() != aZoomConstRB
.IsChecked() )
311 bModified
|= 0 != rSet
.Put( SfxBoolItem( rPool
.GetWhich(
312 SID_ATTR_GRAF_KEEP_ZOOM
), aZoomConstRB
.IsChecked() ) );
315 bInitialized
= sal_False
;
320 /*--------------------------------------------------------------------
322 --------------------------------------------------------------------*/
324 void SvxGrfCropPage::ActivatePage(const SfxItemSet
& rSet
)
327 SfxItemPool
* pPool
= GetItemSet().GetPool();
328 DBG_ASSERT( pPool
, "Wo ist der Pool" );
331 bSetOrigSize
= sal_False
;
335 const SfxPoolItem
* pItem
;
336 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_FRMSIZE
, sal_False
, &pItem
) )
337 aSize
= ((const SvxSizeItem
*)pItem
)->GetSize();
339 nOldWidth
= aSize
.Width();
340 nOldHeight
= aSize
.Height();
342 sal_Int64 nWidth
= aWidthMF
.Normalize(nOldWidth
);
343 sal_Int64 nHeight
= aHeightMF
.Normalize(nOldHeight
);
345 if (nWidth
!= aWidthMF
.GetValue(FUNIT_TWIP
))
349 // Wert wurde von Umlauf-Tabpage geaendert und muss
350 // mit Modify-Flag gesetzt werden
351 aWidthMF
.SetUserValue(nWidth
, FUNIT_TWIP
);
354 aWidthMF
.SetValue(nWidth
, FUNIT_TWIP
);
356 aWidthMF
.SaveValue();
358 if (nHeight
!= aHeightMF
.GetValue(FUNIT_TWIP
))
362 // Wert wurde von Umlauf-Tabpage geaendert und muss
363 // mit Modify-Flag gesetzt werden
364 aHeightMF
.SetUserValue(nHeight
, FUNIT_TWIP
);
367 aHeightMF
.SetValue(nHeight
, FUNIT_TWIP
);
369 aHeightMF
.SaveValue();
370 bInitialized
= sal_True
;
372 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_GRAPHIC
, sal_False
, &pItem
) )
374 const SvxBrushItem
& rBrush
= *(SvxBrushItem
*)pItem
;
375 if( rBrush
.GetGraphicLink() &&
376 aGraphicName
!= *rBrush
.GetGraphicLink() )
377 aGraphicName
= *rBrush
.GetGraphicLink();
379 const Graphic
* pGrf
= rBrush
.GetGraphic();
382 aExampleWN
.SetGraphic( *pGrf
);
383 aOrigSize
= GetGrfOrigSize( *pGrf
);
384 aExampleWN
.SetFrameSize(aOrigSize
);
385 GraphicHasChanged( aOrigSize
.Width() && aOrigSize
.Height() );
389 GraphicHasChanged( sal_False
);
395 /*--------------------------------------------------------------------
397 --------------------------------------------------------------------*/
399 int SvxGrfCropPage::DeactivatePage(SfxItemSet
*_pSet
)
402 FillItemSet( *_pSet
);
406 /*--------------------------------------------------------------------
407 Beschreibung: Massstab geaendert, Groesse anpassen
408 --------------------------------------------------------------------*/
410 IMPL_LINK( SvxGrfCropPage
, ZoomHdl
, MetricField
*, pField
)
412 SfxItemPool
* pPool
= GetItemSet().GetPool();
413 DBG_ASSERT( pPool
, "Wo ist der Pool" );
414 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
415 SID_ATTR_GRAF_CROP
) ) );
417 if( pField
== &aWidthZoomMF
)
419 long nLRBorders
= lcl_GetValue(aLeftMF
, eUnit
)
420 +lcl_GetValue(aRightMF
, eUnit
);
421 aWidthMF
.SetValue( aWidthMF
.Normalize(
422 ((aOrigSize
.Width() - nLRBorders
) * pField
->GetValue())/100L),
427 long nULBorders
= lcl_GetValue(aTopMF
, eUnit
)
428 +lcl_GetValue(aBottomMF
, eUnit
);
429 aHeightMF
.SetValue( aHeightMF
.Normalize(
430 ((aOrigSize
.Height() - nULBorders
) * pField
->GetValue())/100L) ,
437 /*--------------------------------------------------------------------
438 Beschreibung: Groesse aendern, Massstab anpassen
439 --------------------------------------------------------------------*/
441 IMPL_LINK( SvxGrfCropPage
, SizeHdl
, MetricField
*, pField
)
443 SfxItemPool
* pPool
= GetItemSet().GetPool();
444 DBG_ASSERT( pPool
, "Wo ist der Pool" );
445 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
446 SID_ATTR_GRAF_CROP
) ) );
448 Size
aSize( lcl_GetValue(aWidthMF
, eUnit
),
449 lcl_GetValue(aHeightMF
, eUnit
) );
451 if(pField
== &aWidthMF
)
453 long nWidth
= aOrigSize
.Width() -
454 ( lcl_GetValue(aLeftMF
, eUnit
) +
455 lcl_GetValue(aRightMF
, eUnit
) );
458 sal_uInt16 nZoom
= (sal_uInt16
)( aSize
.Width() * 100L / nWidth
);
459 aWidthZoomMF
.SetValue(nZoom
);
463 long nHeight
= aOrigSize
.Height() -
464 ( lcl_GetValue(aTopMF
, eUnit
) +
465 lcl_GetValue(aBottomMF
, eUnit
));
468 sal_uInt16 nZoom
= (sal_uInt16
)( aSize
.Height() * 100L/ nHeight
);
469 aHeightZoomMF
.SetValue(nZoom
);
475 /*--------------------------------------------------------------------
476 Beschreibung: Raender auswerten
477 --------------------------------------------------------------------*/
479 IMPL_LINK( SvxGrfCropPage
, CropHdl
, const MetricField
*, pField
)
481 SfxItemPool
* pPool
= GetItemSet().GetPool();
482 DBG_ASSERT( pPool
, "Wo ist der Pool" );
483 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
484 SID_ATTR_GRAF_CROP
) ) );
486 sal_Bool bZoom
= aZoomConstRB
.IsChecked();
487 if( pField
== &aLeftMF
|| pField
== &aRightMF
)
489 long nLeft
= lcl_GetValue( aLeftMF
, eUnit
);
490 long nRight
= lcl_GetValue( aRightMF
, eUnit
);
491 long nWidthZoom
= static_cast<long>(aWidthZoomMF
.GetValue());
492 if(bZoom
&& ( ( ( aOrigSize
.Width() - (nLeft
+ nRight
)) * nWidthZoom
)
493 / 100 >= aPageSize
.Width() ) )
495 if(pField
== &aLeftMF
)
497 // nLeft = aPageSize.Width() -
498 // ((nRight + aOrigSize.Width()) * nWidthZoom) / 100;
499 nLeft
= aOrigSize
.Width() -
500 ( aPageSize
.Width() * 100 / nWidthZoom
+ nRight
);
501 aLeftMF
.SetValue( aLeftMF
.Normalize( nLeft
), eUnit
);
505 // nRight = aPageSize.Width() -
506 // ((nLeft - aOrigSize.Width()) * nWidthZoom) / 100;
507 nRight
= aOrigSize
.Width() -
508 ( aPageSize
.Width() * 100 / nWidthZoom
+ nLeft
);
509 aRightMF
.SetValue( aRightMF
.Normalize( nRight
), eUnit
);
512 aExampleWN
.SetLeft(nLeft
);
513 aExampleWN
.SetRight(nRight
);
516 //Massstab bleibt -> Breite neu berechnen
517 ZoomHdl(&aWidthZoomMF
);
522 long nTop
= lcl_GetValue( aTopMF
, eUnit
);
523 long nBottom
= lcl_GetValue( aBottomMF
, eUnit
);
524 long nHeightZoom
= static_cast<long>(aHeightZoomMF
.GetValue());
525 if(bZoom
&& ( ( ( aOrigSize
.Height() - (nTop
+ nBottom
)) * nHeightZoom
)
526 / 100 >= aPageSize
.Height()))
528 if(pField
== &aTopMF
)
530 // nTop = aPageSize.Height() -
531 // ((aOrigSize.Height() - nBottom) * nHeightZoom)/ 100;
532 nTop
= aOrigSize
.Height() -
533 ( aPageSize
.Height() * 100 / nHeightZoom
+ nBottom
);
534 aTopMF
.SetValue( aWidthMF
.Normalize( nTop
), eUnit
);
538 // nBottom = aPageSize.Height() -
539 // ((aOrigSize.Height() - nTop)*nHeightZoom) / 100;
540 nBottom
= aOrigSize
.Height() -
541 ( aPageSize
.Height() * 100 / nHeightZoom
+ nTop
);
542 aBottomMF
.SetValue( aWidthMF
.Normalize( nBottom
), eUnit
);
545 aExampleWN
.SetTop( nTop
);
546 aExampleWN
.SetBottom( nBottom
);
549 //Massstab bleibt -> Hoehe neu berechnen
550 ZoomHdl(&aHeightZoomMF
);
553 aExampleWN
.Invalidate();
554 //Groesse und Raender veraendert -> Massstab neu berechnen
560 /*--------------------------------------------------------------------
561 Beschreibung: Originalgroesse einstellen
562 --------------------------------------------------------------------*/
564 IMPL_LINK( SvxGrfCropPage
, OrigSizeHdl
, PushButton
*, EMPTYARG
)
566 SfxItemPool
* pPool
= GetItemSet().GetPool();
567 DBG_ASSERT( pPool
, "Wo ist der Pool" );
568 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
569 SID_ATTR_GRAF_CROP
) ) );
571 long nWidth
= aOrigSize
.Width() -
572 lcl_GetValue( aLeftMF
, eUnit
) -
573 lcl_GetValue( aRightMF
, eUnit
);
574 aWidthMF
.SetValue( aWidthMF
.Normalize( nWidth
), eUnit
);
575 long nHeight
= aOrigSize
.Height() -
576 lcl_GetValue( aTopMF
, eUnit
) -
577 lcl_GetValue( aBottomMF
, eUnit
);
578 aHeightMF
.SetValue( aHeightMF
.Normalize( nHeight
), eUnit
);
579 aWidthZoomMF
.SetValue(100);
580 aHeightZoomMF
.SetValue(100);
581 bSetOrigSize
= sal_True
;
584 /*--------------------------------------------------------------------
585 Beschreibung: Massstab berechnen
586 --------------------------------------------------------------------*/
588 void SvxGrfCropPage::CalcZoom()
590 SfxItemPool
* pPool
= GetItemSet().GetPool();
591 DBG_ASSERT( pPool
, "Wo ist der Pool" );
592 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
593 SID_ATTR_GRAF_CROP
) ) );
595 long nWidth
= lcl_GetValue( aWidthMF
, eUnit
);
596 long nHeight
= lcl_GetValue( aHeightMF
, eUnit
);
597 long nLRBorders
= lcl_GetValue( aLeftMF
, eUnit
) +
598 lcl_GetValue( aRightMF
, eUnit
);
599 long nULBorders
= lcl_GetValue( aTopMF
, eUnit
) +
600 lcl_GetValue( aBottomMF
, eUnit
);
601 sal_uInt16 nZoom
= 0;
603 if( (nDen
= aOrigSize
.Width() - nLRBorders
) > 0)
604 nZoom
= (sal_uInt16
)((( nWidth
* 1000L / nDen
)+5)/10);
605 aWidthZoomMF
.SetValue(nZoom
);
606 if( (nDen
= aOrigSize
.Height() - nULBorders
) > 0)
607 nZoom
= (sal_uInt16
)((( nHeight
* 1000L / nDen
)+5)/10);
610 aHeightZoomMF
.SetValue(nZoom
);
613 /*--------------------------------------------------------------------
614 Beschreibung: Minimal-/Maximalwerte fuer die Raender setzen
615 --------------------------------------------------------------------*/
617 void SvxGrfCropPage::CalcMinMaxBorder()
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
) ) );
623 long nR
= lcl_GetValue(aRightMF
, eUnit
);
624 long nMinWidth
= (aOrigSize
.Width() * 10) /11;
625 long nMin
= nMinWidth
- (nR
>= 0 ? nR
: 0);
626 aLeftMF
.SetMax( aLeftMF
.Normalize(nMin
), eUnit
);
628 long nL
= lcl_GetValue(aLeftMF
, eUnit
);
629 nMin
= nMinWidth
- (nL
>= 0 ? nL
: 0);
630 aRightMF
.SetMax( aRightMF
.Normalize(nMin
), eUnit
);
632 // Zoom nicht unter 2%
633 /* nMin = (aOrigSize.Width() * 102) /100;
634 aLeftMF.SetMax(aPageSize.Width() - nR - nMin);
635 aRightMF.SetMax(aPageSize.Width() - nL - nMin);
637 long nUp
= lcl_GetValue( aTopMF
, eUnit
);
638 long nMinHeight
= (aOrigSize
.Height() * 10) /11;
639 nMin
= nMinHeight
- (nUp
>= 0 ? nUp
: 0);
640 aBottomMF
.SetMax( aBottomMF
.Normalize(nMin
), eUnit
);
642 long nLow
= lcl_GetValue(aBottomMF
, eUnit
);
643 nMin
= nMinHeight
- (nLow
>= 0 ? nLow
: 0);
644 aTopMF
.SetMax( aTopMF
.Normalize(nMin
), eUnit
);
646 // Zoom nicht unter 2%
647 /* nMin = (aOrigSize.Height() * 102) /100;
648 aTopMF.SetMax(aPageSize.Height() - nLow - nMin);
649 aBottomMF.SetMax(aPageSize.Height() - nUp - nMin);*/
651 /*--------------------------------------------------------------------
652 Beschreibung: Spinsize auf 1/20 der Originalgroesse setzen,
653 FixedText mit der Originalgroesse fuellen
654 --------------------------------------------------------------------*/
656 void SvxGrfCropPage::GraphicHasChanged( sal_Bool bFound
)
660 SfxItemPool
* pPool
= GetItemSet().GetPool();
661 DBG_ASSERT( pPool
, "Wo ist der Pool" );
662 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
663 SID_ATTR_GRAF_CROP
) ));
665 sal_Int64 nSpin
= aLeftMF
.Normalize(aOrigSize
.Width()) / 20;
666 nSpin
= MetricField::ConvertValue( nSpin
, aOrigSize
.Width(), 0,
667 eUnit
, aLeftMF
.GetUnit());
669 // Ist der Rand zu gross, wird er auf beiden Seiten auf 1/3 eingestellt.
670 long nR
= lcl_GetValue( aRightMF
, eUnit
);
671 long nL
= lcl_GetValue( aLeftMF
, eUnit
);
672 if((nL
+ nR
) < - aOrigSize
.Width())
674 long nVal
= aOrigSize
.Width() / -3;
675 aRightMF
.SetValue( aRightMF
.Normalize( nVal
), eUnit
);
676 aLeftMF
.SetValue( aLeftMF
.Normalize( nVal
), eUnit
);
677 aExampleWN
.SetLeft(nVal
);
678 aExampleWN
.SetRight(nVal
);
680 long nUp
= lcl_GetValue(aTopMF
, eUnit
);
681 long nLow
= lcl_GetValue(aBottomMF
, eUnit
);
682 if((nUp
+ nLow
) < - aOrigSize
.Height())
684 long nVal
= aOrigSize
.Height() / -3;
685 aTopMF
.SetValue( aTopMF
.Normalize( nVal
), eUnit
);
686 aBottomMF
.SetValue( aBottomMF
.Normalize( nVal
), eUnit
);
687 aExampleWN
.SetTop(nVal
);
688 aExampleWN
.SetBottom(nVal
);
691 aLeftMF
.SetSpinSize(nSpin
);
692 aRightMF
.SetSpinSize(nSpin
);
693 nSpin
= aTopMF
.Normalize(aOrigSize
.Height()) / 20;
694 nSpin
= MetricField::ConvertValue( nSpin
, aOrigSize
.Width(), 0,
695 eUnit
, aLeftMF
.GetUnit() );
696 aTopMF
.SetSpinSize(nSpin
);
697 aBottomMF
.SetSpinSize(nSpin
);
699 //Originalgroesse anzeigen
700 const FieldUnit eMetric
= GetModuleFieldUnit( GetItemSet() );
702 MetricField
aFld(this, WB_HIDE
);
703 SetFieldUnit( aFld
, eMetric
);
704 aFld
.SetDecimalDigits( aWidthMF
.GetDecimalDigits() );
705 aFld
.SetMax( LONG_MAX
- 1 );
707 aFld
.SetValue( aFld
.Normalize( aOrigSize
.Width() ), eUnit
);
708 String sTemp
= aFld
.GetText();
709 aFld
.SetValue( aFld
.Normalize( aOrigSize
.Height() ), eUnit
);
710 sTemp
+= UniString::CreateFromAscii(" x ");
711 sTemp
+= aFld
.GetText();
712 aOrigSizeFT
.SetText(sTemp
);
714 aLeftFT
.Enable(bFound
);
715 aLeftMF
.Enable(bFound
);
716 aRightFT
.Enable(bFound
);
717 aRightMF
.Enable(bFound
);
718 aTopFT
.Enable(bFound
);
719 aTopMF
.Enable(bFound
);
720 aBottomFT
.Enable(bFound
);
721 aBottomMF
.Enable(bFound
);
722 aSizeConstRB
.Enable(bFound
);
723 aZoomConstRB
.Enable(bFound
);
724 aWidthFT
.Enable(bFound
);
725 aWidthMF
.Enable(bFound
);
726 aHeightFT
.Enable(bFound
);
727 aHeightMF
.Enable(bFound
);
728 aWidthZoomFT
.Enable(bFound
);
729 aWidthZoomMF
.Enable(bFound
);
730 aHeightZoomFT
.Enable(bFound
);
731 aHeightZoomMF
.Enable(bFound
);
732 aExampleWN
.Enable(bFound
);
733 aOrigSizePB
.Enable(bFound
);
734 aOrigSizeFT
.Enable(bFound
);
737 IMPL_LINK( SvxGrfCropPage
, Timeout
, Timer
*, EMPTYARG
)
739 DBG_ASSERT(pLastCropField
,"Timeout ohne Feld?");
740 CropHdl(pLastCropField
);
746 IMPL_LINK( SvxGrfCropPage
, CropLoseFocusHdl
, MetricField
*, pField
)
755 IMPL_LINK( SvxGrfCropPage
, CropModifyHdl
, MetricField
*, pField
)
758 pLastCropField
= pField
;
762 Size
SvxGrfCropPage::GetGrfOrigSize( const Graphic
& rGrf
) const
764 const MapMode
aMapTwip( MAP_TWIP
);
765 Size
aSize( rGrf
.GetPrefSize() );
766 if( MAP_PIXEL
== rGrf
.GetPrefMapMode().GetMapUnit() )
767 aSize
= PixelToLogic( aSize
, aMapTwip
);
769 aSize
= OutputDevice::LogicToLogic( aSize
,
770 rGrf
.GetPrefMapMode(), aMapTwip
);
774 /*****************************************************************/
776 SvxGrfCropPage::SvxCropExample::SvxCropExample( Window
* pPar
,
777 const ResId
& rResId
)
778 : Window( pPar
, rResId
),
779 aFrameSize( OutputDevice::LogicToLogic(
780 Size( CM_1_TO_TWIP
/ 2, CM_1_TO_TWIP
/ 2 ),
781 MapMode( MAP_TWIP
), GetMapMode() )),
782 aTopLeft(0,0), aBottomRight(0,0)
784 SetBorderStyle( WINDOW_BORDER_MONO
);
787 void SvxGrfCropPage::SvxCropExample::Paint( const Rectangle
& )
789 Size
aWinSize( PixelToLogic(GetOutputSizePixel() ));
791 SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
792 SetRasterOp( ROP_OVERPAINT
);
793 DrawRect( Rectangle( Point(), aWinSize
) );
795 SetLineColor( Color( COL_WHITE
) );
796 Rectangle
aRect(Point((aWinSize
.Width() - aFrameSize
.Width())/2,
797 (aWinSize
.Height() - aFrameSize
.Height())/2),
799 aGrf
.Draw( this, aRect
.TopLeft(), aRect
.GetSize() );
802 aSz
= PixelToLogic( aSz
);
803 SetFillColor( Color( COL_TRANSPARENT
) );
804 SetRasterOp( ROP_INVERT
);
805 aRect
.Left() += aTopLeft
.Y();
806 aRect
.Top() += aTopLeft
.X();
807 aRect
.Right() -= aBottomRight
.Y();
808 aRect
.Bottom() -= aBottomRight
.X();
812 void SvxGrfCropPage::SvxCropExample::SetFrameSize( const Size
& rSz
)
815 if(!aFrameSize
.Width())
816 aFrameSize
.Width() = 1;
817 if(!aFrameSize
.Height())
818 aFrameSize
.Height() = 1;
819 Size
aWinSize( GetOutputSizePixel() );
820 Fraction
aXScale( aWinSize
.Width() * 4, aFrameSize
.Width() * 5 );
821 Fraction
aYScale( aWinSize
.Height() * 4, aFrameSize
.Height() * 5 );
823 if( aYScale
< aXScale
)
826 MapMode
aMapMode( GetMapMode() );
828 aMapMode
.SetScaleX( aXScale
);
829 aMapMode
.SetScaleY( aXScale
);
831 SetMapMode( aMapMode
);