1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: grfpage.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
41 #include <tools/shl.hxx>
42 #include <svtools/eitem.hxx>
43 #include <sfx2/app.hxx>
44 #include <sfx2/module.hxx>
45 #include <sfx2/sfxsids.hrc>
48 #include <svx/dialmgr.hxx>
49 #include <dlgutil.hxx>
50 #include <svx/sizeitem.hxx>
51 #include <svx/brshitem.hxx>
54 #include <grfpage.hxx>
56 #include <svx/grfcrop.hxx>
59 #include <grfpage.hrc>
61 #ifndef _SVX_DIALOGS_HRC
62 #include <svx/dialogs.hrc>
64 #ifndef _SVX_SVXIDS_HRC
65 #include <svx/svxids.hrc>
69 #define CM_1_TO_TWIP 567
72 inline long lcl_GetValue( MetricField
& rMetric
, FieldUnit eUnit
)
74 return static_cast<long>(rMetric
.Denormalize( rMetric
.GetValue( eUnit
)));
77 /*--------------------------------------------------------------------
78 Beschreibung: Grafik zuschneiden
79 --------------------------------------------------------------------*/
81 SvxGrfCropPage::SvxGrfCropPage ( Window
*pParent
, const SfxItemSet
&rSet
)
82 : SfxTabPage( pParent
, SVX_RES( RID_SVXPAGE_GRFCROP
), rSet
),
83 aCropFL( this, SVX_RES( FL_CROP
)),
84 aZoomConstRB( this, SVX_RES( RB_ZOOMCONST
)),
85 aSizeConstRB( this, SVX_RES( RB_SIZECONST
)),
86 aLeftFT( this, SVX_RES( FT_LEFT
)),
87 aLeftMF( this, SVX_RES( MF_LEFT
)),
88 aRightFT( this, SVX_RES( FT_RIGHT
)),
89 aRightMF( this, SVX_RES( MF_RIGHT
)),
90 aTopFT( this, SVX_RES( FT_TOP
)),
91 aTopMF( this, SVX_RES( MF_TOP
)),
92 aBottomFT( this, SVX_RES( FT_BOTTOM
)),
93 aBottomMF( this, SVX_RES( MF_BOTTOM
)),
94 aZoomFL( this, SVX_RES( FL_ZOOM
)),
95 aWidthZoomFT( this, SVX_RES( FT_WIDTHZOOM
)),
96 aWidthZoomMF( this, SVX_RES( MF_WIDTHZOOM
)),
97 aHeightZoomFT( this, SVX_RES( FT_HEIGHTZOOM
)),
98 aHeightZoomMF( this, SVX_RES( MF_HEIGHTZOOM
)),
99 aSizeFL( this, SVX_RES( FL_SIZE
)),
100 aWidthFT( this, SVX_RES( FT_WIDTH
)),
101 aWidthMF( this, SVX_RES( MF_WIDTH
)),
102 aHeightFT( this, SVX_RES( FT_HEIGHT
)),
103 aHeightMF( this, SVX_RES( MF_HEIGHT
)),
104 aOrigSizeFT( this, SVX_RES(FT_ORIG_SIZE
)),
105 aOrigSizePB( this, SVX_RES( PB_ORGSIZE
)),
106 aExampleWN( this, SVX_RES( WN_BSP
)),
113 SetExchangeSupport();
115 // set the correct metric
116 const FieldUnit eMetric
= GetModuleFieldUnit( &rSet
);
118 SetFieldUnit( aWidthMF
, eMetric
);
119 SetFieldUnit( aHeightMF
, eMetric
);
120 SetFieldUnit( aLeftMF
, eMetric
);
121 SetFieldUnit( aRightMF
, eMetric
);
122 SetFieldUnit( aTopMF
, eMetric
);
123 SetFieldUnit( aBottomMF
, eMetric
);
125 Link aLk
= LINK(this, SvxGrfCropPage
, SizeHdl
);
126 aWidthMF
.SetModifyHdl( aLk
);
127 aHeightMF
.SetModifyHdl( aLk
);
129 aLk
= LINK(this, SvxGrfCropPage
, ZoomHdl
);
130 aWidthZoomMF
.SetModifyHdl( aLk
);
131 aHeightZoomMF
.SetModifyHdl( aLk
);
133 aLk
= LINK(this, SvxGrfCropPage
, CropHdl
);
134 aLeftMF
.SetDownHdl( aLk
);
135 aRightMF
.SetDownHdl( aLk
);
136 aTopMF
.SetDownHdl( aLk
);
137 aBottomMF
.SetDownHdl( aLk
);
138 aLeftMF
.SetUpHdl( aLk
);
139 aRightMF
.SetUpHdl( aLk
);
140 aTopMF
.SetUpHdl( aLk
);
141 aBottomMF
.SetUpHdl( aLk
);
143 aLk
= LINK(this, SvxGrfCropPage
, CropModifyHdl
);
144 aLeftMF
.SetModifyHdl( aLk
);
145 aRightMF
.SetModifyHdl( aLk
);
146 aTopMF
.SetModifyHdl( aLk
);
147 aBottomMF
.SetModifyHdl( aLk
);
149 aLk
= LINK(this, SvxGrfCropPage
, CropLoseFocusHdl
);
150 aLeftMF
.SetLoseFocusHdl( aLk
);
151 aRightMF
.SetLoseFocusHdl( aLk
);
152 aTopMF
.SetLoseFocusHdl( aLk
);
153 aBottomMF
.SetLoseFocusHdl( aLk
);
155 aLk
= LINK(this, SvxGrfCropPage
, OrigSizeHdl
);
156 aOrigSizePB
.SetClickHdl( aLk
);
158 aTimer
.SetTimeoutHdl(LINK(this, SvxGrfCropPage
, Timeout
));
159 aTimer
.SetTimeout( 1500 );
162 /*--------------------------------------------------------------------
164 --------------------------------------------------------------------*/
166 SvxGrfCropPage::~SvxGrfCropPage()
171 /*--------------------------------------------------------------------
173 --------------------------------------------------------------------*/
175 SfxTabPage
* SvxGrfCropPage::Create(Window
*pParent
, const SfxItemSet
&rSet
)
177 return new SvxGrfCropPage( pParent
, rSet
);
179 /*--------------------------------------------------------------------
181 --------------------------------------------------------------------*/
183 void SvxGrfCropPage::Reset( const SfxItemSet
&rSet
)
185 const SfxPoolItem
* pItem
;
186 const SfxItemPool
& rPool
= *rSet
.GetPool();
188 if(SFX_ITEM_SET
== rSet
.GetItemState( rPool
.GetWhich(
189 SID_ATTR_GRAF_KEEP_ZOOM
), TRUE
, &pItem
))
191 if( ((const SfxBoolItem
*)pItem
)->GetValue() )
192 aZoomConstRB
.Check();
194 aSizeConstRB
.Check();
195 aZoomConstRB
.SaveValue();
198 USHORT nW
= rPool
.GetWhich( SID_ATTR_GRAF_CROP
);
199 if( SFX_ITEM_SET
== rSet
.GetItemState( nW
, TRUE
, &pItem
))
201 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
203 SvxGrfCrop
* pCrop
= (SvxGrfCrop
*)pItem
;
205 aExampleWN
.SetLeft( pCrop
->GetLeft());
206 aExampleWN
.SetRight( pCrop
->GetRight());
207 aExampleWN
.SetTop( pCrop
->GetTop());
208 aExampleWN
.SetBottom( pCrop
->GetBottom());
210 aLeftMF
.SetValue( aLeftMF
.Normalize( pCrop
->GetLeft()), eUnit
);
211 aRightMF
.SetValue( aRightMF
.Normalize( pCrop
->GetRight()), eUnit
);
212 aTopMF
.SetValue( aTopMF
.Normalize( pCrop
->GetTop()), eUnit
);
213 aBottomMF
.SetValue( aBottomMF
.Normalize( pCrop
->GetBottom()), eUnit
);
217 aLeftMF
.SetValue( 0 );
218 aRightMF
.SetValue( 0 );
219 aTopMF
.SetValue( 0 );
220 aBottomMF
.SetValue( 0 );
223 nW
= rPool
.GetWhich( SID_ATTR_PAGE_SIZE
);
224 if ( SFX_ITEM_SET
== rSet
.GetItemState( nW
, FALSE
, &pItem
) )
226 // Orientation und Size aus dem PageItem
227 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
229 aPageSize
= ((const SvxSizeItem
*)pItem
)->GetSize();
231 sal_Int64 nTmp
= aHeightMF
.Normalize(aPageSize
.Height());
232 aHeightMF
.SetMax( nTmp
, eUnit
);
233 nTmp
= aWidthMF
.Normalize(aPageSize
.Width());
234 aWidthMF
.SetMax( nTmp
, eUnit
);
235 nTmp
= aWidthMF
.Normalize( 23 );
236 aHeightMF
.SetMin( nTmp
, eUnit
);
237 aWidthMF
.SetMin( nTmp
, eUnit
);
241 aPageSize
= OutputDevice::LogicToLogic(
242 Size( CM_1_TO_TWIP
, CM_1_TO_TWIP
),
244 MapMode( (MapUnit
)rSet
.GetPool()->GetMetric( nW
) ) );
248 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_GRAPHIC
, FALSE
, &pItem
) )
250 const Graphic
* pGrf
= ((SvxBrushItem
*)pItem
)->GetGraphic();
252 aOrigSize
= GetGrfOrigSize( *pGrf
);
254 if( aOrigSize
.Width() && aOrigSize
.Height() )
257 aExampleWN
.SetGraphic( *pGrf
);
258 aExampleWN
.SetFrameSize( aOrigSize
);
261 if( ((SvxBrushItem
*)pItem
)->GetGraphicLink() )
262 aGraphicName
= *((SvxBrushItem
*)pItem
)->GetGraphicLink();
266 GraphicHasChanged( bFound
);
268 ActivatePage( rSet
);
272 /*--------------------------------------------------------------------
274 --------------------------------------------------------------------*/
276 BOOL
SvxGrfCropPage::FillItemSet(SfxItemSet
&rSet
)
278 const SfxItemPool
& rPool
= *rSet
.GetPool();
279 BOOL bModified
= FALSE
;
280 if( aWidthMF
.GetSavedValue() != aWidthMF
.GetText() ||
281 aHeightMF
.GetSavedValue() != aHeightMF
.GetText() )
283 USHORT nW
= rPool
.GetWhich( SID_ATTR_GRAF_FRMSIZE
);
284 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
286 SvxSizeItem
aSz( nW
);
288 // die Groesse koennte schon von einer anderen Page gesetzt worden sein
290 const SfxItemSet
* pExSet
= GetTabDialog() ? GetTabDialog()->GetExampleSet() : NULL
;
291 const SfxPoolItem
* pItem
= 0;
292 if( pExSet
&& SFX_ITEM_SET
==
293 pExSet
->GetItemState( nW
, FALSE
, &pItem
) )
294 aSz
= *(const SvxSizeItem
*)pItem
;
296 aSz
= (const SvxSizeItem
&)GetItemSet().Get( nW
);
298 Size
aTmpSz( aSz
.GetSize() );
299 if( aWidthMF
.GetText() != aWidthMF
.GetSavedValue() )
300 aTmpSz
.Width() = lcl_GetValue( aWidthMF
, eUnit
);
301 if( aHeightMF
.GetText() != aHeightMF
.GetSavedValue() )
302 aTmpSz
.Height() = lcl_GetValue( aHeightMF
, eUnit
);
303 aSz
.SetSize( aTmpSz
);
304 aWidthMF
.SaveValue();
305 aHeightMF
.SaveValue();
307 bModified
|= 0 != rSet
.Put( aSz
);
311 bModified
|= 0 != rSet
.Put( SvxSizeItem( rPool
.GetWhich(
312 SID_ATTR_GRAF_FRMSIZE_PERCENT
), Size( 0, 0 )) );
315 if( aLeftMF
.IsModified() || aRightMF
.IsModified() ||
316 aTopMF
.IsModified() || aBottomMF
.IsModified() )
318 USHORT nW
= rPool
.GetWhich( SID_ATTR_GRAF_CROP
);
319 FieldUnit eUnit
= MapToFieldUnit( rSet
.GetPool()->GetMetric( nW
));
320 SvxGrfCrop
* pNew
= (SvxGrfCrop
*)rSet
.Get( nW
).Clone();
322 pNew
->SetLeft( lcl_GetValue( aLeftMF
, eUnit
) );
323 pNew
->SetRight( lcl_GetValue( aRightMF
, eUnit
) );
324 pNew
->SetTop( lcl_GetValue( aTopMF
, eUnit
) );
325 pNew
->SetBottom( lcl_GetValue( aBottomMF
, eUnit
) );
326 bModified
|= 0 != rSet
.Put( *pNew
);
330 if( aZoomConstRB
.GetSavedValue() != aZoomConstRB
.IsChecked() )
332 bModified
|= 0 != rSet
.Put( SfxBoolItem( rPool
.GetWhich(
333 SID_ATTR_GRAF_KEEP_ZOOM
), aZoomConstRB
.IsChecked() ) );
336 bInitialized
= FALSE
;
341 /*--------------------------------------------------------------------
343 --------------------------------------------------------------------*/
345 void SvxGrfCropPage::ActivatePage(const SfxItemSet
& rSet
)
348 SfxItemPool
* pPool
= GetItemSet().GetPool();
349 DBG_ASSERT( pPool
, "Wo ist der Pool" );
352 bSetOrigSize
= FALSE
;
356 const SfxPoolItem
* pItem
;
357 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_FRMSIZE
, FALSE
, &pItem
) )
358 aSize
= ((const SvxSizeItem
*)pItem
)->GetSize();
360 nOldWidth
= aSize
.Width();
361 nOldHeight
= aSize
.Height();
363 sal_Int64 nWidth
= aWidthMF
.Normalize(nOldWidth
);
364 sal_Int64 nHeight
= aHeightMF
.Normalize(nOldHeight
);
366 if (nWidth
!= aWidthMF
.GetValue(FUNIT_TWIP
))
370 // Wert wurde von Umlauf-Tabpage geaendert und muss
371 // mit Modify-Flag gesetzt werden
372 aWidthMF
.SetUserValue(nWidth
, FUNIT_TWIP
);
375 aWidthMF
.SetValue(nWidth
, FUNIT_TWIP
);
377 aWidthMF
.SaveValue();
379 if (nHeight
!= aHeightMF
.GetValue(FUNIT_TWIP
))
383 // Wert wurde von Umlauf-Tabpage geaendert und muss
384 // mit Modify-Flag gesetzt werden
385 aHeightMF
.SetUserValue(nHeight
, FUNIT_TWIP
);
388 aHeightMF
.SetValue(nHeight
, FUNIT_TWIP
);
390 aHeightMF
.SaveValue();
393 if( SFX_ITEM_SET
== rSet
.GetItemState( SID_ATTR_GRAF_GRAPHIC
, FALSE
, &pItem
) )
395 const SvxBrushItem
& rBrush
= *(SvxBrushItem
*)pItem
;
396 if( rBrush
.GetGraphicLink() &&
397 aGraphicName
!= *rBrush
.GetGraphicLink() )
398 aGraphicName
= *rBrush
.GetGraphicLink();
400 const Graphic
* pGrf
= rBrush
.GetGraphic();
403 aExampleWN
.SetGraphic( *pGrf
);
404 aOrigSize
= GetGrfOrigSize( *pGrf
);
405 aExampleWN
.SetFrameSize(aOrigSize
);
406 GraphicHasChanged( aOrigSize
.Width() && aOrigSize
.Height() );
410 GraphicHasChanged( FALSE
);
416 /*--------------------------------------------------------------------
418 --------------------------------------------------------------------*/
420 int SvxGrfCropPage::DeactivatePage(SfxItemSet
*_pSet
)
423 FillItemSet( *_pSet
);
427 /*--------------------------------------------------------------------
428 Beschreibung: Massstab geaendert, Groesse anpassen
429 --------------------------------------------------------------------*/
431 IMPL_LINK( SvxGrfCropPage
, ZoomHdl
, MetricField
*, pField
)
433 SfxItemPool
* pPool
= GetItemSet().GetPool();
434 DBG_ASSERT( pPool
, "Wo ist der Pool" );
435 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
436 SID_ATTR_GRAF_CROP
) ) );
438 if( pField
== &aWidthZoomMF
)
440 long nLRBorders
= lcl_GetValue(aLeftMF
, eUnit
)
441 +lcl_GetValue(aRightMF
, eUnit
);
442 aWidthMF
.SetValue( aWidthMF
.Normalize(
443 ((aOrigSize
.Width() - nLRBorders
) * pField
->GetValue())/100L),
448 long nULBorders
= lcl_GetValue(aTopMF
, eUnit
)
449 +lcl_GetValue(aBottomMF
, eUnit
);
450 aHeightMF
.SetValue( aHeightMF
.Normalize(
451 ((aOrigSize
.Height() - nULBorders
) * pField
->GetValue())/100L) ,
458 /*--------------------------------------------------------------------
459 Beschreibung: Groesse aendern, Massstab anpassen
460 --------------------------------------------------------------------*/
462 IMPL_LINK( SvxGrfCropPage
, SizeHdl
, MetricField
*, pField
)
464 SfxItemPool
* pPool
= GetItemSet().GetPool();
465 DBG_ASSERT( pPool
, "Wo ist der Pool" );
466 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
467 SID_ATTR_GRAF_CROP
) ) );
469 Size
aSize( lcl_GetValue(aWidthMF
, eUnit
),
470 lcl_GetValue(aHeightMF
, eUnit
) );
472 if(pField
== &aWidthMF
)
474 long nWidth
= aOrigSize
.Width() -
475 ( lcl_GetValue(aLeftMF
, eUnit
) +
476 lcl_GetValue(aRightMF
, eUnit
) );
479 USHORT nZoom
= (USHORT
)( aSize
.Width() * 100L / nWidth
);
480 aWidthZoomMF
.SetValue(nZoom
);
484 long nHeight
= aOrigSize
.Height() -
485 ( lcl_GetValue(aTopMF
, eUnit
) +
486 lcl_GetValue(aBottomMF
, eUnit
));
489 USHORT nZoom
= (USHORT
)( aSize
.Height() * 100L/ nHeight
);
490 aHeightZoomMF
.SetValue(nZoom
);
496 /*--------------------------------------------------------------------
497 Beschreibung: Raender auswerten
498 --------------------------------------------------------------------*/
500 IMPL_LINK( SvxGrfCropPage
, CropHdl
, const MetricField
*, pField
)
502 SfxItemPool
* pPool
= GetItemSet().GetPool();
503 DBG_ASSERT( pPool
, "Wo ist der Pool" );
504 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
505 SID_ATTR_GRAF_CROP
) ) );
507 BOOL bZoom
= aZoomConstRB
.IsChecked();
508 if( pField
== &aLeftMF
|| pField
== &aRightMF
)
510 long nLeft
= lcl_GetValue( aLeftMF
, eUnit
);
511 long nRight
= lcl_GetValue( aRightMF
, eUnit
);
512 long nWidthZoom
= static_cast<long>(aWidthZoomMF
.GetValue());
513 if(bZoom
&& ( ( ( aOrigSize
.Width() - (nLeft
+ nRight
)) * nWidthZoom
)
514 / 100 >= aPageSize
.Width() ) )
516 if(pField
== &aLeftMF
)
518 // nLeft = aPageSize.Width() -
519 // ((nRight + aOrigSize.Width()) * nWidthZoom) / 100;
520 nLeft
= aOrigSize
.Width() -
521 ( aPageSize
.Width() * 100 / nWidthZoom
+ nRight
);
522 aLeftMF
.SetValue( aLeftMF
.Normalize( nLeft
), eUnit
);
526 // nRight = aPageSize.Width() -
527 // ((nLeft - aOrigSize.Width()) * nWidthZoom) / 100;
528 nRight
= aOrigSize
.Width() -
529 ( aPageSize
.Width() * 100 / nWidthZoom
+ nLeft
);
530 aRightMF
.SetValue( aRightMF
.Normalize( nRight
), eUnit
);
533 aExampleWN
.SetLeft(nLeft
);
534 aExampleWN
.SetRight(nRight
);
537 //Massstab bleibt -> Breite neu berechnen
538 ZoomHdl(&aWidthZoomMF
);
543 long nTop
= lcl_GetValue( aTopMF
, eUnit
);
544 long nBottom
= lcl_GetValue( aBottomMF
, eUnit
);
545 long nHeightZoom
= static_cast<long>(aHeightZoomMF
.GetValue());
546 if(bZoom
&& ( ( ( aOrigSize
.Height() - (nTop
+ nBottom
)) * nHeightZoom
)
547 / 100 >= aPageSize
.Height()))
549 if(pField
== &aTopMF
)
551 // nTop = aPageSize.Height() -
552 // ((aOrigSize.Height() - nBottom) * nHeightZoom)/ 100;
553 nTop
= aOrigSize
.Height() -
554 ( aPageSize
.Height() * 100 / nHeightZoom
+ nBottom
);
555 aTopMF
.SetValue( aWidthMF
.Normalize( nTop
), eUnit
);
559 // nBottom = aPageSize.Height() -
560 // ((aOrigSize.Height() - nTop)*nHeightZoom) / 100;
561 nBottom
= aOrigSize
.Height() -
562 ( aPageSize
.Height() * 100 / nHeightZoom
+ nTop
);
563 aBottomMF
.SetValue( aWidthMF
.Normalize( nBottom
), eUnit
);
566 aExampleWN
.SetTop( nTop
);
567 aExampleWN
.SetBottom( nBottom
);
570 //Massstab bleibt -> Hoehe neu berechnen
571 ZoomHdl(&aHeightZoomMF
);
574 aExampleWN
.Invalidate();
575 //Groesse und Raender veraendert -> Massstab neu berechnen
581 /*--------------------------------------------------------------------
582 Beschreibung: Originalgroesse einstellen
583 --------------------------------------------------------------------*/
585 IMPL_LINK( SvxGrfCropPage
, OrigSizeHdl
, PushButton
*, EMPTYARG
)
587 SfxItemPool
* pPool
= GetItemSet().GetPool();
588 DBG_ASSERT( pPool
, "Wo ist der Pool" );
589 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
590 SID_ATTR_GRAF_CROP
) ) );
592 long nWidth
= aOrigSize
.Width() -
593 lcl_GetValue( aLeftMF
, eUnit
) -
594 lcl_GetValue( aRightMF
, eUnit
);
595 aWidthMF
.SetValue( aWidthMF
.Normalize( nWidth
), eUnit
);
596 long nHeight
= aOrigSize
.Height() -
597 lcl_GetValue( aTopMF
, eUnit
) -
598 lcl_GetValue( aBottomMF
, eUnit
);
599 aHeightMF
.SetValue( aHeightMF
.Normalize( nHeight
), eUnit
);
600 aWidthZoomMF
.SetValue(100);
601 aHeightZoomMF
.SetValue(100);
605 /*--------------------------------------------------------------------
606 Beschreibung: Massstab berechnen
607 --------------------------------------------------------------------*/
609 void SvxGrfCropPage::CalcZoom()
611 SfxItemPool
* pPool
= GetItemSet().GetPool();
612 DBG_ASSERT( pPool
, "Wo ist der Pool" );
613 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
614 SID_ATTR_GRAF_CROP
) ) );
616 long nWidth
= lcl_GetValue( aWidthMF
, eUnit
);
617 long nHeight
= lcl_GetValue( aHeightMF
, eUnit
);
618 long nLRBorders
= lcl_GetValue( aLeftMF
, eUnit
) +
619 lcl_GetValue( aRightMF
, eUnit
);
620 long nULBorders
= lcl_GetValue( aTopMF
, eUnit
) +
621 lcl_GetValue( aBottomMF
, eUnit
);
624 if( (nDen
= aOrigSize
.Width() - nLRBorders
) > 0)
625 nZoom
= (USHORT
)((( nWidth
* 1000L / nDen
)+5)/10);
626 aWidthZoomMF
.SetValue(nZoom
);
627 if( (nDen
= aOrigSize
.Height() - nULBorders
) > 0)
628 nZoom
= (USHORT
)((( nHeight
* 1000L / nDen
)+5)/10);
631 aHeightZoomMF
.SetValue(nZoom
);
634 /*--------------------------------------------------------------------
635 Beschreibung: Minimal-/Maximalwerte fuer die Raender setzen
636 --------------------------------------------------------------------*/
638 void SvxGrfCropPage::CalcMinMaxBorder()
640 SfxItemPool
* pPool
= GetItemSet().GetPool();
641 DBG_ASSERT( pPool
, "Wo ist der Pool" );
642 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
643 SID_ATTR_GRAF_CROP
) ) );
644 long nR
= lcl_GetValue(aRightMF
, eUnit
);
645 long nMinWidth
= (aOrigSize
.Width() * 10) /11;
646 long nMin
= nMinWidth
- (nR
>= 0 ? nR
: 0);
647 aLeftMF
.SetMax( aLeftMF
.Normalize(nMin
), eUnit
);
649 long nL
= lcl_GetValue(aLeftMF
, eUnit
);
650 nMin
= nMinWidth
- (nL
>= 0 ? nL
: 0);
651 aRightMF
.SetMax( aRightMF
.Normalize(nMin
), eUnit
);
653 // Zoom nicht unter 2%
654 /* nMin = (aOrigSize.Width() * 102) /100;
655 aLeftMF.SetMax(aPageSize.Width() - nR - nMin);
656 aRightMF.SetMax(aPageSize.Width() - nL - nMin);
658 long nUp
= lcl_GetValue( aTopMF
, eUnit
);
659 long nMinHeight
= (aOrigSize
.Height() * 10) /11;
660 nMin
= nMinHeight
- (nUp
>= 0 ? nUp
: 0);
661 aBottomMF
.SetMax( aBottomMF
.Normalize(nMin
), eUnit
);
663 long nLow
= lcl_GetValue(aBottomMF
, eUnit
);
664 nMin
= nMinHeight
- (nLow
>= 0 ? nLow
: 0);
665 aTopMF
.SetMax( aTopMF
.Normalize(nMin
), eUnit
);
667 // Zoom nicht unter 2%
668 /* nMin = (aOrigSize.Height() * 102) /100;
669 aTopMF.SetMax(aPageSize.Height() - nLow - nMin);
670 aBottomMF.SetMax(aPageSize.Height() - nUp - nMin);*/
672 /*--------------------------------------------------------------------
673 Beschreibung: Spinsize auf 1/20 der Originalgroesse setzen,
674 FixedText mit der Originalgroesse fuellen
675 --------------------------------------------------------------------*/
677 void SvxGrfCropPage::GraphicHasChanged( BOOL bFound
)
681 SfxItemPool
* pPool
= GetItemSet().GetPool();
682 DBG_ASSERT( pPool
, "Wo ist der Pool" );
683 FieldUnit eUnit
= MapToFieldUnit( pPool
->GetMetric( pPool
->GetWhich(
684 SID_ATTR_GRAF_CROP
) ));
686 sal_Int64 nSpin
= aLeftMF
.Normalize(aOrigSize
.Width()) / 20;
687 nSpin
= MetricField::ConvertValue( nSpin
, aOrigSize
.Width(), 0,
688 eUnit
, aLeftMF
.GetUnit());
690 // Ist der Rand zu gross, wird er auf beiden Seiten auf 1/3 eingestellt.
691 long nR
= lcl_GetValue( aRightMF
, eUnit
);
692 long nL
= lcl_GetValue( aLeftMF
, eUnit
);
693 if((nL
+ nR
) < - aOrigSize
.Width())
695 long nVal
= aOrigSize
.Width() / -3;
696 aRightMF
.SetValue( aRightMF
.Normalize( nVal
), eUnit
);
697 aLeftMF
.SetValue( aLeftMF
.Normalize( nVal
), eUnit
);
698 aExampleWN
.SetLeft(nVal
);
699 aExampleWN
.SetRight(nVal
);
701 long nUp
= lcl_GetValue(aTopMF
, eUnit
);
702 long nLow
= lcl_GetValue(aBottomMF
, eUnit
);
703 if((nUp
+ nLow
) < - aOrigSize
.Height())
705 long nVal
= aOrigSize
.Height() / -3;
706 aTopMF
.SetValue( aTopMF
.Normalize( nVal
), eUnit
);
707 aBottomMF
.SetValue( aBottomMF
.Normalize( nVal
), eUnit
);
708 aExampleWN
.SetTop(nVal
);
709 aExampleWN
.SetBottom(nVal
);
712 aLeftMF
.SetSpinSize(nSpin
);
713 aRightMF
.SetSpinSize(nSpin
);
714 nSpin
= aTopMF
.Normalize(aOrigSize
.Height()) / 20;
715 nSpin
= MetricField::ConvertValue( nSpin
, aOrigSize
.Width(), 0,
716 eUnit
, aLeftMF
.GetUnit() );
717 aTopMF
.SetSpinSize(nSpin
);
718 aBottomMF
.SetSpinSize(nSpin
);
720 //Originalgroesse anzeigen
721 const FieldUnit eMetric
= GetModuleFieldUnit( &GetItemSet() );
723 MetricField
aFld(this, WB_HIDE
);
724 SetFieldUnit( aFld
, eMetric
);
725 aFld
.SetDecimalDigits( aWidthMF
.GetDecimalDigits() );
726 aFld
.SetMax( LONG_MAX
- 1 );
728 aFld
.SetValue( aFld
.Normalize( aOrigSize
.Width() ), eUnit
);
729 String sTemp
= aFld
.GetText();
730 aFld
.SetValue( aFld
.Normalize( aOrigSize
.Height() ), eUnit
);
731 sTemp
+= UniString::CreateFromAscii(" x ");
732 sTemp
+= aFld
.GetText();
733 aOrigSizeFT
.SetText(sTemp
);
735 aLeftFT
.Enable(bFound
);
736 aLeftMF
.Enable(bFound
);
737 aRightFT
.Enable(bFound
);
738 aRightMF
.Enable(bFound
);
739 aTopFT
.Enable(bFound
);
740 aTopMF
.Enable(bFound
);
741 aBottomFT
.Enable(bFound
);
742 aBottomMF
.Enable(bFound
);
743 aSizeConstRB
.Enable(bFound
);
744 aZoomConstRB
.Enable(bFound
);
745 aWidthFT
.Enable(bFound
);
746 aWidthMF
.Enable(bFound
);
747 aHeightFT
.Enable(bFound
);
748 aHeightMF
.Enable(bFound
);
749 aWidthZoomFT
.Enable(bFound
);
750 aWidthZoomMF
.Enable(bFound
);
751 aHeightZoomFT
.Enable(bFound
);
752 aHeightZoomMF
.Enable(bFound
);
753 aExampleWN
.Enable(bFound
);
754 aOrigSizePB
.Enable(bFound
);
755 aOrigSizeFT
.Enable(bFound
);
758 IMPL_LINK( SvxGrfCropPage
, Timeout
, Timer
*, EMPTYARG
)
760 DBG_ASSERT(pLastCropField
,"Timeout ohne Feld?");
761 CropHdl(pLastCropField
);
767 IMPL_LINK( SvxGrfCropPage
, CropLoseFocusHdl
, MetricField
*, pField
)
776 IMPL_LINK( SvxGrfCropPage
, CropModifyHdl
, MetricField
*, pField
)
779 pLastCropField
= pField
;
783 Size
SvxGrfCropPage::GetGrfOrigSize( const Graphic
& rGrf
) const
785 const MapMode
aMapTwip( MAP_TWIP
);
786 Size
aSize( rGrf
.GetPrefSize() );
787 if( MAP_PIXEL
== rGrf
.GetPrefMapMode().GetMapUnit() )
788 aSize
= PixelToLogic( aSize
, aMapTwip
);
790 aSize
= OutputDevice::LogicToLogic( aSize
,
791 rGrf
.GetPrefMapMode(), aMapTwip
);
795 /*****************************************************************/
797 SvxGrfCropPage::SvxCropExample::SvxCropExample( Window
* pPar
,
798 const ResId
& rResId
)
799 : Window( pPar
, rResId
),
800 aFrameSize( OutputDevice::LogicToLogic(
801 Size( CM_1_TO_TWIP
/ 2, CM_1_TO_TWIP
/ 2 ),
802 MapMode( MAP_TWIP
), GetMapMode() )),
803 aTopLeft(0,0), aBottomRight(0,0)
805 SetBorderStyle( WINDOW_BORDER_MONO
);
808 void SvxGrfCropPage::SvxCropExample::Paint( const Rectangle
& )
810 Size
aWinSize( PixelToLogic(GetOutputSizePixel() ));
812 SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
813 SetRasterOp( ROP_OVERPAINT
);
814 DrawRect( Rectangle( Point(), aWinSize
) );
816 SetLineColor( Color( COL_WHITE
) );
817 Rectangle
aRect(Point((aWinSize
.Width() - aFrameSize
.Width())/2,
818 (aWinSize
.Height() - aFrameSize
.Height())/2),
820 aGrf
.Draw( this, aRect
.TopLeft(), aRect
.GetSize() );
823 aSz
= PixelToLogic( aSz
);
824 SetFillColor( Color( COL_TRANSPARENT
) );
825 SetRasterOp( ROP_INVERT
);
826 aRect
.Left() += aTopLeft
.Y();
827 aRect
.Top() += aTopLeft
.X();
828 aRect
.Right() -= aBottomRight
.Y();
829 aRect
.Bottom() -= aBottomRight
.X();
833 void SvxGrfCropPage::SvxCropExample::SetFrameSize( const Size
& rSz
)
836 if(!aFrameSize
.Width())
837 aFrameSize
.Width() = 1;
838 if(!aFrameSize
.Height())
839 aFrameSize
.Height() = 1;
840 Size
aWinSize( GetOutputSizePixel() );
841 Fraction
aXScale( aWinSize
.Width() * 4, aFrameSize
.Width() * 5 );
842 Fraction
aYScale( aWinSize
.Height() * 4, aFrameSize
.Height() * 5 );
844 if( aYScale
< aXScale
)
847 MapMode
aMapMode( GetMapMode() );
849 aMapMode
.SetScaleX( aXScale
);
850 aMapMode
.SetScaleY( aXScale
);
852 SetMapMode( aMapMode
);