xref: /AOO41X/main/cui/source/tabpages/grfpage.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/shl.hxx>
32*cdf0e10cSrcweir #include <svl/eitem.hxx>
33*cdf0e10cSrcweir #include <sfx2/app.hxx>
34*cdf0e10cSrcweir #include <sfx2/module.hxx>
35*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
36*cdf0e10cSrcweir #include <dialmgr.hxx>
37*cdf0e10cSrcweir #include <svx/dlgutil.hxx>
38*cdf0e10cSrcweir #include <editeng/sizeitem.hxx>
39*cdf0e10cSrcweir #include <editeng/brshitem.hxx>
40*cdf0e10cSrcweir #include <grfpage.hxx>
41*cdf0e10cSrcweir #include <svx/grfcrop.hxx>
42*cdf0e10cSrcweir #include <grfpage.hrc>
43*cdf0e10cSrcweir #include <cuires.hrc>
44*cdf0e10cSrcweir #include <svx/dialogs.hrc> // for RID_SVXPAGE_GRFCROP
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #define CM_1_TO_TWIP 		567
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir inline long lcl_GetValue( MetricField& rMetric, FieldUnit eUnit )
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir 	return static_cast<long>(rMetric.Denormalize( rMetric.GetValue( eUnit )));
52*cdf0e10cSrcweir }
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir /*--------------------------------------------------------------------
55*cdf0e10cSrcweir 	Beschreibung: Grafik zuschneiden
56*cdf0e10cSrcweir  --------------------------------------------------------------------*/
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir SvxGrfCropPage::SvxGrfCropPage ( Window *pParent, const SfxItemSet &rSet )
59*cdf0e10cSrcweir 	: SfxTabPage( pParent, 	CUI_RES( RID_SVXPAGE_GRFCROP ), rSet ),
60*cdf0e10cSrcweir     aCropFL(        this, CUI_RES( FL_CROP    )),
61*cdf0e10cSrcweir     aZoomConstRB(   this, CUI_RES( RB_ZOOMCONST)),
62*cdf0e10cSrcweir     aSizeConstRB(   this, CUI_RES( RB_SIZECONST)),
63*cdf0e10cSrcweir     aLeftFT(        this, CUI_RES( FT_LEFT    )),
64*cdf0e10cSrcweir     aLeftMF(        this, CUI_RES( MF_LEFT    )),
65*cdf0e10cSrcweir     aRightFT(       this, CUI_RES( FT_RIGHT   )),
66*cdf0e10cSrcweir     aRightMF(       this, CUI_RES( MF_RIGHT   )),
67*cdf0e10cSrcweir     aTopFT(         this, CUI_RES( FT_TOP     )),
68*cdf0e10cSrcweir     aTopMF(         this, CUI_RES( MF_TOP     )),
69*cdf0e10cSrcweir     aBottomFT(      this, CUI_RES( FT_BOTTOM  )),
70*cdf0e10cSrcweir     aBottomMF(      this, CUI_RES( MF_BOTTOM  )),
71*cdf0e10cSrcweir     aZoomFL(        this, CUI_RES( FL_ZOOM    )),
72*cdf0e10cSrcweir     aWidthZoomFT(   this, CUI_RES( FT_WIDTHZOOM )),
73*cdf0e10cSrcweir 	aWidthZoomMF( 	this, CUI_RES( MF_WIDTHZOOM )),
74*cdf0e10cSrcweir 	aHeightZoomFT( 	this, CUI_RES( FT_HEIGHTZOOM)),
75*cdf0e10cSrcweir 	aHeightZoomMF( 	this, CUI_RES( MF_HEIGHTZOOM)),
76*cdf0e10cSrcweir     aSizeFL(        this, CUI_RES( FL_SIZE    )),
77*cdf0e10cSrcweir     aWidthFT(       this, CUI_RES( FT_WIDTH   )),
78*cdf0e10cSrcweir     aWidthMF(       this, CUI_RES( MF_WIDTH   )),
79*cdf0e10cSrcweir     aHeightFT(      this, CUI_RES( FT_HEIGHT  )),
80*cdf0e10cSrcweir     aHeightMF(      this, CUI_RES( MF_HEIGHT  )),
81*cdf0e10cSrcweir     aOrigSizeFT(    this, CUI_RES(FT_ORIG_SIZE)),
82*cdf0e10cSrcweir 	aOrigSizePB( 	this, CUI_RES( PB_ORGSIZE )),
83*cdf0e10cSrcweir     aExampleWN(     this, CUI_RES( WN_BSP     )),
84*cdf0e10cSrcweir     pLastCropField(0),
85*cdf0e10cSrcweir 	bInitialized(sal_False),
86*cdf0e10cSrcweir 	bSetOrigSize(sal_False)
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir 	FreeResource();
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	SetExchangeSupport();
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     // set the correct metric
93*cdf0e10cSrcweir 	const FieldUnit eMetric = GetModuleFieldUnit( rSet );
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	SetFieldUnit( aWidthMF, eMetric );
96*cdf0e10cSrcweir 	SetFieldUnit( aHeightMF, eMetric );
97*cdf0e10cSrcweir 	SetFieldUnit( aLeftMF, eMetric );
98*cdf0e10cSrcweir 	SetFieldUnit( aRightMF, eMetric );
99*cdf0e10cSrcweir 	SetFieldUnit( aTopMF , eMetric );
100*cdf0e10cSrcweir 	SetFieldUnit( aBottomMF, eMetric );
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	Link aLk = LINK(this, SvxGrfCropPage, SizeHdl);
103*cdf0e10cSrcweir 	aWidthMF.SetModifyHdl( aLk );
104*cdf0e10cSrcweir 	aHeightMF.SetModifyHdl( aLk );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	aLk = LINK(this, SvxGrfCropPage, ZoomHdl);
107*cdf0e10cSrcweir 	aWidthZoomMF.SetModifyHdl( aLk );
108*cdf0e10cSrcweir 	aHeightZoomMF.SetModifyHdl( aLk );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	aLk = LINK(this, SvxGrfCropPage, CropHdl);
111*cdf0e10cSrcweir 	aLeftMF.SetDownHdl( aLk );
112*cdf0e10cSrcweir 	aRightMF.SetDownHdl( aLk );
113*cdf0e10cSrcweir 	aTopMF.SetDownHdl( aLk );
114*cdf0e10cSrcweir 	aBottomMF.SetDownHdl( aLk );
115*cdf0e10cSrcweir 	aLeftMF.SetUpHdl( aLk );
116*cdf0e10cSrcweir 	aRightMF.SetUpHdl( aLk );
117*cdf0e10cSrcweir 	aTopMF.SetUpHdl( aLk );
118*cdf0e10cSrcweir 	aBottomMF.SetUpHdl( aLk );
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	aLk = LINK(this, SvxGrfCropPage, CropModifyHdl);
121*cdf0e10cSrcweir 	aLeftMF.SetModifyHdl( aLk );
122*cdf0e10cSrcweir 	aRightMF.SetModifyHdl( aLk );
123*cdf0e10cSrcweir 	aTopMF.SetModifyHdl( aLk );
124*cdf0e10cSrcweir 	aBottomMF.SetModifyHdl( aLk );
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	aLk = LINK(this, SvxGrfCropPage, CropLoseFocusHdl);
127*cdf0e10cSrcweir 	aLeftMF.SetLoseFocusHdl( aLk );
128*cdf0e10cSrcweir 	aRightMF.SetLoseFocusHdl( aLk );
129*cdf0e10cSrcweir 	aTopMF.SetLoseFocusHdl( aLk );
130*cdf0e10cSrcweir 	aBottomMF.SetLoseFocusHdl( aLk );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	aLk = LINK(this, SvxGrfCropPage, OrigSizeHdl);
133*cdf0e10cSrcweir 	aOrigSizePB.SetClickHdl( aLk );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	aTimer.SetTimeoutHdl(LINK(this, SvxGrfCropPage, Timeout));
136*cdf0e10cSrcweir 	aTimer.SetTimeout( 1500 );
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	aOrigSizePB.SetAccessibleRelationLabeledBy( &aOrigSizeFT );
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir /*--------------------------------------------------------------------
142*cdf0e10cSrcweir 	Beschreibung:
143*cdf0e10cSrcweir  --------------------------------------------------------------------*/
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir SvxGrfCropPage::~SvxGrfCropPage()
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir 	aTimer.Stop();
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir /*--------------------------------------------------------------------
151*cdf0e10cSrcweir 	Beschreibung:
152*cdf0e10cSrcweir  --------------------------------------------------------------------*/
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir SfxTabPage* SvxGrfCropPage::Create(Window *pParent, const SfxItemSet &rSet)
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir 	return new SvxGrfCropPage( pParent, rSet );
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir /*--------------------------------------------------------------------
159*cdf0e10cSrcweir 	Beschreibung:
160*cdf0e10cSrcweir  --------------------------------------------------------------------*/
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir void SvxGrfCropPage::Reset( const SfxItemSet &rSet )
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir 	const SfxPoolItem* pItem;
165*cdf0e10cSrcweir 	const SfxItemPool& rPool = *rSet.GetPool();
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	if(SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich(
168*cdf0e10cSrcweir 									SID_ATTR_GRAF_KEEP_ZOOM ), sal_True, &pItem ))
169*cdf0e10cSrcweir 	{
170*cdf0e10cSrcweir 		if( ((const SfxBoolItem*)pItem)->GetValue() )
171*cdf0e10cSrcweir 			aZoomConstRB.Check();
172*cdf0e10cSrcweir 		else
173*cdf0e10cSrcweir 			aSizeConstRB.Check();
174*cdf0e10cSrcweir 		aZoomConstRB.SaveValue();
175*cdf0e10cSrcweir 	}
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP );
178*cdf0e10cSrcweir 	if( SFX_ITEM_SET == rSet.GetItemState( nW, sal_True, &pItem))
179*cdf0e10cSrcweir 	{
180*cdf0e10cSrcweir 		FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 		SvxGrfCrop* pCrop =  (SvxGrfCrop*)pItem;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 		aExampleWN.SetLeft(		pCrop->GetLeft());
185*cdf0e10cSrcweir 		aExampleWN.SetRight(	pCrop->GetRight());
186*cdf0e10cSrcweir 		aExampleWN.SetTop(		pCrop->GetTop());
187*cdf0e10cSrcweir 		aExampleWN.SetBottom(	pCrop->GetBottom());
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 		aLeftMF.SetValue( aLeftMF.Normalize( pCrop->GetLeft()), eUnit );
190*cdf0e10cSrcweir 		aRightMF.SetValue( aRightMF.Normalize( pCrop->GetRight()), eUnit );
191*cdf0e10cSrcweir 		aTopMF.SetValue( aTopMF.Normalize( pCrop->GetTop()), eUnit );
192*cdf0e10cSrcweir 		aBottomMF.SetValue( aBottomMF.Normalize( pCrop->GetBottom()), eUnit );
193*cdf0e10cSrcweir 	}
194*cdf0e10cSrcweir 	else
195*cdf0e10cSrcweir 	{
196*cdf0e10cSrcweir 		aLeftMF.SetValue( 0 );
197*cdf0e10cSrcweir 		aRightMF.SetValue( 0 );
198*cdf0e10cSrcweir 		aTopMF.SetValue( 0 );
199*cdf0e10cSrcweir 		aBottomMF.SetValue( 0 );
200*cdf0e10cSrcweir 	}
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 	nW = rPool.GetWhich( SID_ATTR_PAGE_SIZE );
203*cdf0e10cSrcweir 	if ( SFX_ITEM_SET == rSet.GetItemState( nW, sal_False, &pItem ) )
204*cdf0e10cSrcweir 	{
205*cdf0e10cSrcweir 		// Orientation und Size aus dem PageItem
206*cdf0e10cSrcweir 		FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 		aPageSize = ((const SvxSizeItem*)pItem)->GetSize();
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 		sal_Int64 nTmp = aHeightMF.Normalize(aPageSize.Height());
211*cdf0e10cSrcweir 		aHeightMF.SetMax( nTmp, eUnit );
212*cdf0e10cSrcweir 		nTmp = aWidthMF.Normalize(aPageSize.Width());
213*cdf0e10cSrcweir 		aWidthMF.SetMax( nTmp, eUnit );
214*cdf0e10cSrcweir 		nTmp = aWidthMF.Normalize( 23 );
215*cdf0e10cSrcweir 		aHeightMF.SetMin( nTmp, eUnit );
216*cdf0e10cSrcweir 		aWidthMF.SetMin( nTmp, eUnit );
217*cdf0e10cSrcweir 	}
218*cdf0e10cSrcweir 	else
219*cdf0e10cSrcweir 	{
220*cdf0e10cSrcweir 		aPageSize = OutputDevice::LogicToLogic(
221*cdf0e10cSrcweir 						Size( CM_1_TO_TWIP,  CM_1_TO_TWIP ),
222*cdf0e10cSrcweir 						MapMode( MAP_TWIP ),
223*cdf0e10cSrcweir 						MapMode( (MapUnit)rSet.GetPool()->GetMetric( nW ) ) );
224*cdf0e10cSrcweir 	}
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
227*cdf0e10cSrcweir 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRAF_GRAPHIC, sal_False, &pItem ) )
228*cdf0e10cSrcweir 	{
229*cdf0e10cSrcweir 		const Graphic* pGrf = ((SvxBrushItem*)pItem)->GetGraphic();
230*cdf0e10cSrcweir 		if( pGrf )
231*cdf0e10cSrcweir 			aOrigSize = GetGrfOrigSize( *pGrf );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 		if( aOrigSize.Width() && aOrigSize.Height() )
234*cdf0e10cSrcweir 		{
235*cdf0e10cSrcweir 			CalcMinMaxBorder();
236*cdf0e10cSrcweir 			aExampleWN.SetGraphic( *pGrf );
237*cdf0e10cSrcweir 			aExampleWN.SetFrameSize( aOrigSize );
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 			bFound = sal_True;
240*cdf0e10cSrcweir 			if( ((SvxBrushItem*)pItem)->GetGraphicLink() )
241*cdf0e10cSrcweir 				aGraphicName = *((SvxBrushItem*)pItem)->GetGraphicLink();
242*cdf0e10cSrcweir 		}
243*cdf0e10cSrcweir 	}
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	GraphicHasChanged( bFound );
246*cdf0e10cSrcweir 	bReset = sal_True;
247*cdf0e10cSrcweir 	ActivatePage( rSet );
248*cdf0e10cSrcweir 	bReset = sal_False;
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir /*--------------------------------------------------------------------
252*cdf0e10cSrcweir 	Beschreibung:
253*cdf0e10cSrcweir  --------------------------------------------------------------------*/
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir sal_Bool SvxGrfCropPage::FillItemSet(SfxItemSet &rSet)
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir 	const SfxItemPool& rPool = *rSet.GetPool();
258*cdf0e10cSrcweir 	sal_Bool bModified = sal_False;
259*cdf0e10cSrcweir 	if( aWidthMF.GetSavedValue() != aWidthMF.GetText() ||
260*cdf0e10cSrcweir 		aHeightMF.GetSavedValue() != aHeightMF.GetText() )
261*cdf0e10cSrcweir 	{
262*cdf0e10cSrcweir 		sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_FRMSIZE );
263*cdf0e10cSrcweir 		FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 		SvxSizeItem aSz( nW );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 		// die Groesse koennte schon von einer anderen Page gesetzt worden sein
268*cdf0e10cSrcweir 		// #44204#
269*cdf0e10cSrcweir 		const SfxItemSet* pExSet = GetTabDialog() ? GetTabDialog()->GetExampleSet() : NULL;
270*cdf0e10cSrcweir 		const SfxPoolItem* pItem = 0;
271*cdf0e10cSrcweir 		if( pExSet && SFX_ITEM_SET ==
272*cdf0e10cSrcweir 				pExSet->GetItemState( nW, sal_False, &pItem ) )
273*cdf0e10cSrcweir 			aSz = *(const SvxSizeItem*)pItem;
274*cdf0e10cSrcweir 		else
275*cdf0e10cSrcweir 			aSz = (const SvxSizeItem&)GetItemSet().Get( nW );
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 		Size aTmpSz( aSz.GetSize() );
278*cdf0e10cSrcweir 		if( aWidthMF.GetText() != aWidthMF.GetSavedValue() )
279*cdf0e10cSrcweir 			aTmpSz.Width() = lcl_GetValue( aWidthMF, eUnit );
280*cdf0e10cSrcweir 		if( aHeightMF.GetText() != aHeightMF.GetSavedValue() )
281*cdf0e10cSrcweir 			aTmpSz.Height() = lcl_GetValue( aHeightMF, eUnit );
282*cdf0e10cSrcweir 		aSz.SetSize( aTmpSz );
283*cdf0e10cSrcweir 		aWidthMF.SaveValue();
284*cdf0e10cSrcweir 		aHeightMF.SaveValue();
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 		bModified |= 0 != rSet.Put( aSz );
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 		if( bSetOrigSize )
289*cdf0e10cSrcweir 		{
290*cdf0e10cSrcweir 			bModified |= 0 != rSet.Put( SvxSizeItem( rPool.GetWhich(
291*cdf0e10cSrcweir 						SID_ATTR_GRAF_FRMSIZE_PERCENT ), Size( 0, 0 )) );
292*cdf0e10cSrcweir 		}
293*cdf0e10cSrcweir 	}
294*cdf0e10cSrcweir 	if( aLeftMF.IsModified() || aRightMF.IsModified() ||
295*cdf0e10cSrcweir 		aTopMF.IsModified()  ||	aBottomMF.IsModified() )
296*cdf0e10cSrcweir 	{
297*cdf0e10cSrcweir 		sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP );
298*cdf0e10cSrcweir 		FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
299*cdf0e10cSrcweir 		SvxGrfCrop* pNew = (SvxGrfCrop*)rSet.Get( nW ).Clone();
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 		pNew->SetLeft( lcl_GetValue( aLeftMF, eUnit ) );
302*cdf0e10cSrcweir 		pNew->SetRight( lcl_GetValue( aRightMF, eUnit ) );
303*cdf0e10cSrcweir 		pNew->SetTop( lcl_GetValue( aTopMF, eUnit ) );
304*cdf0e10cSrcweir 		pNew->SetBottom( lcl_GetValue( aBottomMF, eUnit ) );
305*cdf0e10cSrcweir 		bModified |= 0 != rSet.Put( *pNew );
306*cdf0e10cSrcweir 		delete pNew;
307*cdf0e10cSrcweir 	}
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 	if( aZoomConstRB.GetSavedValue() != aZoomConstRB.IsChecked() )
310*cdf0e10cSrcweir 	{
311*cdf0e10cSrcweir 		bModified |= 0 != rSet.Put( SfxBoolItem( rPool.GetWhich(
312*cdf0e10cSrcweir 					SID_ATTR_GRAF_KEEP_ZOOM), aZoomConstRB.IsChecked() ) );
313*cdf0e10cSrcweir 	}
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	bInitialized = sal_False;
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 	return bModified;
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir /*--------------------------------------------------------------------
321*cdf0e10cSrcweir 	Beschreibung:
322*cdf0e10cSrcweir  --------------------------------------------------------------------*/
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet)
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir #ifdef DBG_UTIL
327*cdf0e10cSrcweir 	SfxItemPool* pPool = GetItemSet().GetPool();
328*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool" );
329*cdf0e10cSrcweir #endif
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	bSetOrigSize = sal_False;
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir 	// Size
334*cdf0e10cSrcweir 	Size aSize;
335*cdf0e10cSrcweir 	const SfxPoolItem* pItem;
336*cdf0e10cSrcweir 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRAF_FRMSIZE, sal_False, &pItem ) )
337*cdf0e10cSrcweir 		aSize = ((const SvxSizeItem*)pItem)->GetSize();
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	nOldWidth = aSize.Width();
340*cdf0e10cSrcweir 	nOldHeight = aSize.Height();
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	sal_Int64 nWidth = aWidthMF.Normalize(nOldWidth);
343*cdf0e10cSrcweir 	sal_Int64 nHeight = aHeightMF.Normalize(nOldHeight);
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	if (nWidth != aWidthMF.GetValue(FUNIT_TWIP))
346*cdf0e10cSrcweir 	{
347*cdf0e10cSrcweir 		if(!bReset)
348*cdf0e10cSrcweir 		{
349*cdf0e10cSrcweir 			// Wert wurde von Umlauf-Tabpage geaendert und muss
350*cdf0e10cSrcweir 			// mit Modify-Flag gesetzt werden
351*cdf0e10cSrcweir 			aWidthMF.SetUserValue(nWidth, FUNIT_TWIP);
352*cdf0e10cSrcweir 		}
353*cdf0e10cSrcweir 		else
354*cdf0e10cSrcweir 			aWidthMF.SetValue(nWidth, FUNIT_TWIP);
355*cdf0e10cSrcweir 	}
356*cdf0e10cSrcweir 	aWidthMF.SaveValue();
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 	if (nHeight != aHeightMF.GetValue(FUNIT_TWIP))
359*cdf0e10cSrcweir 	{
360*cdf0e10cSrcweir 		if (!bReset)
361*cdf0e10cSrcweir 		{
362*cdf0e10cSrcweir 			// Wert wurde von Umlauf-Tabpage geaendert und muss
363*cdf0e10cSrcweir 			// mit Modify-Flag gesetzt werden
364*cdf0e10cSrcweir 			aHeightMF.SetUserValue(nHeight, FUNIT_TWIP);
365*cdf0e10cSrcweir 		}
366*cdf0e10cSrcweir 		else
367*cdf0e10cSrcweir 			aHeightMF.SetValue(nHeight, FUNIT_TWIP);
368*cdf0e10cSrcweir 	}
369*cdf0e10cSrcweir 	aHeightMF.SaveValue();
370*cdf0e10cSrcweir 	bInitialized = sal_True;
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRAF_GRAPHIC, sal_False, &pItem ) )
373*cdf0e10cSrcweir 	{
374*cdf0e10cSrcweir 		const SvxBrushItem& rBrush = *(SvxBrushItem*)pItem;
375*cdf0e10cSrcweir 		if( rBrush.GetGraphicLink() &&
376*cdf0e10cSrcweir 			aGraphicName != *rBrush.GetGraphicLink() )
377*cdf0e10cSrcweir 			aGraphicName = *rBrush.GetGraphicLink();
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 		const Graphic* pGrf = rBrush.GetGraphic();
380*cdf0e10cSrcweir 		if( pGrf )
381*cdf0e10cSrcweir 		{
382*cdf0e10cSrcweir 			aExampleWN.SetGraphic( *pGrf );
383*cdf0e10cSrcweir 			aOrigSize = GetGrfOrigSize( *pGrf );
384*cdf0e10cSrcweir 			aExampleWN.SetFrameSize(aOrigSize);
385*cdf0e10cSrcweir 			GraphicHasChanged( aOrigSize.Width() && aOrigSize.Height() );
386*cdf0e10cSrcweir 			CalcMinMaxBorder();
387*cdf0e10cSrcweir 		}
388*cdf0e10cSrcweir 		else
389*cdf0e10cSrcweir 			GraphicHasChanged( sal_False );
390*cdf0e10cSrcweir 	}
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 	CalcZoom();
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir /*--------------------------------------------------------------------
396*cdf0e10cSrcweir 	Beschreibung:
397*cdf0e10cSrcweir  --------------------------------------------------------------------*/
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir int SvxGrfCropPage::DeactivatePage(SfxItemSet *_pSet)
400*cdf0e10cSrcweir {
401*cdf0e10cSrcweir     if ( _pSet )
402*cdf0e10cSrcweir         FillItemSet( *_pSet );
403*cdf0e10cSrcweir 	return sal_True;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir /*--------------------------------------------------------------------
407*cdf0e10cSrcweir 	Beschreibung: Massstab geaendert, Groesse anpassen
408*cdf0e10cSrcweir  --------------------------------------------------------------------*/
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir IMPL_LINK( SvxGrfCropPage, ZoomHdl, MetricField *, pField )
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir 	SfxItemPool* pPool = GetItemSet().GetPool();
413*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool" );
414*cdf0e10cSrcweir 	FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
415*cdf0e10cSrcweir 													SID_ATTR_GRAF_CROP ) ) );
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	if( pField == &aWidthZoomMF )
418*cdf0e10cSrcweir 	{
419*cdf0e10cSrcweir 		long nLRBorders = lcl_GetValue(aLeftMF, eUnit)
420*cdf0e10cSrcweir 						 +lcl_GetValue(aRightMF, eUnit);
421*cdf0e10cSrcweir 		aWidthMF.SetValue( aWidthMF.Normalize(
422*cdf0e10cSrcweir 			((aOrigSize.Width() - nLRBorders) * pField->GetValue())/100L),
423*cdf0e10cSrcweir 			eUnit);
424*cdf0e10cSrcweir 	}
425*cdf0e10cSrcweir 	else
426*cdf0e10cSrcweir 	{
427*cdf0e10cSrcweir 		long nULBorders = lcl_GetValue(aTopMF, eUnit)
428*cdf0e10cSrcweir 						 +lcl_GetValue(aBottomMF, eUnit);
429*cdf0e10cSrcweir 		aHeightMF.SetValue( aHeightMF.Normalize(
430*cdf0e10cSrcweir 			((aOrigSize.Height() - nULBorders ) * pField->GetValue())/100L) ,
431*cdf0e10cSrcweir 			eUnit );
432*cdf0e10cSrcweir 	}
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 	return 0;
435*cdf0e10cSrcweir }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir /*--------------------------------------------------------------------
438*cdf0e10cSrcweir 	Beschreibung: Groesse aendern, Massstab anpassen
439*cdf0e10cSrcweir  --------------------------------------------------------------------*/
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir IMPL_LINK( SvxGrfCropPage, SizeHdl, MetricField *, pField )
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	SfxItemPool* pPool = GetItemSet().GetPool();
444*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool" );
445*cdf0e10cSrcweir 	FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
446*cdf0e10cSrcweir 													SID_ATTR_GRAF_CROP ) ) );
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	Size aSize( lcl_GetValue(aWidthMF, eUnit),
449*cdf0e10cSrcweir 				lcl_GetValue(aHeightMF, eUnit) );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 	if(pField == &aWidthMF)
452*cdf0e10cSrcweir 	{
453*cdf0e10cSrcweir 		long nWidth = aOrigSize.Width() -
454*cdf0e10cSrcweir 				( lcl_GetValue(aLeftMF, eUnit) +
455*cdf0e10cSrcweir 				  lcl_GetValue(aRightMF, eUnit) );
456*cdf0e10cSrcweir 		if(!nWidth)
457*cdf0e10cSrcweir 			nWidth++;
458*cdf0e10cSrcweir 		sal_uInt16 nZoom = (sal_uInt16)( aSize.Width() * 100L / nWidth);
459*cdf0e10cSrcweir 		aWidthZoomMF.SetValue(nZoom);
460*cdf0e10cSrcweir 	}
461*cdf0e10cSrcweir 	else
462*cdf0e10cSrcweir 	{
463*cdf0e10cSrcweir 		long nHeight = aOrigSize.Height() -
464*cdf0e10cSrcweir 				( lcl_GetValue(aTopMF, eUnit) +
465*cdf0e10cSrcweir 				  lcl_GetValue(aBottomMF, eUnit));
466*cdf0e10cSrcweir 		if(!nHeight)
467*cdf0e10cSrcweir 			nHeight++;
468*cdf0e10cSrcweir 		sal_uInt16 nZoom = (sal_uInt16)( aSize.Height() * 100L/ nHeight);
469*cdf0e10cSrcweir 		aHeightZoomMF.SetValue(nZoom);
470*cdf0e10cSrcweir 	}
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 	return 0;
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir /*--------------------------------------------------------------------
476*cdf0e10cSrcweir 	Beschreibung: Raender auswerten
477*cdf0e10cSrcweir  --------------------------------------------------------------------*/
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir IMPL_LINK( SvxGrfCropPage, CropHdl, const MetricField *, pField )
480*cdf0e10cSrcweir {
481*cdf0e10cSrcweir 	SfxItemPool* pPool = GetItemSet().GetPool();
482*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool" );
483*cdf0e10cSrcweir 	FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
484*cdf0e10cSrcweir 													SID_ATTR_GRAF_CROP ) ) );
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 	sal_Bool bZoom = aZoomConstRB.IsChecked();
487*cdf0e10cSrcweir 	if( pField == &aLeftMF || pField == &aRightMF )
488*cdf0e10cSrcweir 	{
489*cdf0e10cSrcweir 		long nLeft = lcl_GetValue( aLeftMF, eUnit );
490*cdf0e10cSrcweir 		long nRight = lcl_GetValue( aRightMF, eUnit );
491*cdf0e10cSrcweir 		long nWidthZoom = static_cast<long>(aWidthZoomMF.GetValue());
492*cdf0e10cSrcweir 		if(bZoom && ( ( ( aOrigSize.Width() - (nLeft + nRight )) * nWidthZoom )
493*cdf0e10cSrcweir 							/ 100 >= aPageSize.Width() ) )
494*cdf0e10cSrcweir 		{
495*cdf0e10cSrcweir 			if(pField == &aLeftMF)
496*cdf0e10cSrcweir 			{
497*cdf0e10cSrcweir //				nLeft = aPageSize.Width() -
498*cdf0e10cSrcweir //					((nRight + aOrigSize.Width()) * nWidthZoom) / 100;
499*cdf0e10cSrcweir 				nLeft = aOrigSize.Width() -
500*cdf0e10cSrcweir 							( aPageSize.Width() * 100 / nWidthZoom + nRight );
501*cdf0e10cSrcweir 				aLeftMF.SetValue( aLeftMF.Normalize( nLeft ), eUnit );
502*cdf0e10cSrcweir 			}
503*cdf0e10cSrcweir 			else
504*cdf0e10cSrcweir 			{
505*cdf0e10cSrcweir //				nRight = aPageSize.Width() -
506*cdf0e10cSrcweir //					((nLeft - aOrigSize.Width()) * nWidthZoom) / 100;
507*cdf0e10cSrcweir 				nRight = aOrigSize.Width() -
508*cdf0e10cSrcweir 							( aPageSize.Width() * 100 / nWidthZoom + nLeft );
509*cdf0e10cSrcweir 				aRightMF.SetValue( aRightMF.Normalize( nRight ), eUnit );
510*cdf0e10cSrcweir 			}
511*cdf0e10cSrcweir 		}
512*cdf0e10cSrcweir 		aExampleWN.SetLeft(nLeft);
513*cdf0e10cSrcweir 		aExampleWN.SetRight(nRight);
514*cdf0e10cSrcweir 		if(bZoom)
515*cdf0e10cSrcweir 		{
516*cdf0e10cSrcweir 			//Massstab bleibt -> Breite neu berechnen
517*cdf0e10cSrcweir 			ZoomHdl(&aWidthZoomMF);
518*cdf0e10cSrcweir 		}
519*cdf0e10cSrcweir 	}
520*cdf0e10cSrcweir 	else
521*cdf0e10cSrcweir 	{
522*cdf0e10cSrcweir 		long nTop = lcl_GetValue( aTopMF, eUnit );
523*cdf0e10cSrcweir 		long nBottom = lcl_GetValue( aBottomMF, eUnit );
524*cdf0e10cSrcweir 		long nHeightZoom = static_cast<long>(aHeightZoomMF.GetValue());
525*cdf0e10cSrcweir 		if(bZoom && ( ( ( aOrigSize.Height() - (nTop + nBottom )) * nHeightZoom)
526*cdf0e10cSrcweir 											/ 100 >= aPageSize.Height()))
527*cdf0e10cSrcweir 		{
528*cdf0e10cSrcweir 			if(pField == &aTopMF)
529*cdf0e10cSrcweir 			{
530*cdf0e10cSrcweir //				nTop = aPageSize.Height() -
531*cdf0e10cSrcweir //					((aOrigSize.Height() - nBottom) * nHeightZoom)/ 100;
532*cdf0e10cSrcweir 				nTop = aOrigSize.Height() -
533*cdf0e10cSrcweir 							( aPageSize.Height() * 100 / nHeightZoom + nBottom);
534*cdf0e10cSrcweir 				aTopMF.SetValue( aWidthMF.Normalize( nTop ), eUnit );
535*cdf0e10cSrcweir 			}
536*cdf0e10cSrcweir 			else
537*cdf0e10cSrcweir 			{
538*cdf0e10cSrcweir //				nBottom = aPageSize.Height() -
539*cdf0e10cSrcweir //					((aOrigSize.Height() - nTop)*nHeightZoom) / 100;
540*cdf0e10cSrcweir 				nBottom = aOrigSize.Height() -
541*cdf0e10cSrcweir 							( aPageSize.Height() * 100 / nHeightZoom + nTop);
542*cdf0e10cSrcweir 				aBottomMF.SetValue( aWidthMF.Normalize( nBottom ), eUnit );
543*cdf0e10cSrcweir 			}
544*cdf0e10cSrcweir 		}
545*cdf0e10cSrcweir 		aExampleWN.SetTop( nTop );
546*cdf0e10cSrcweir 		aExampleWN.SetBottom( nBottom );
547*cdf0e10cSrcweir 		if(bZoom)
548*cdf0e10cSrcweir 		{
549*cdf0e10cSrcweir 			//Massstab bleibt -> Hoehe neu berechnen
550*cdf0e10cSrcweir 			ZoomHdl(&aHeightZoomMF);
551*cdf0e10cSrcweir 		}
552*cdf0e10cSrcweir 	}
553*cdf0e10cSrcweir 	aExampleWN.Invalidate();
554*cdf0e10cSrcweir 	//Groesse und Raender veraendert -> Massstab neu berechnen
555*cdf0e10cSrcweir 	if(!bZoom)
556*cdf0e10cSrcweir 		CalcZoom();
557*cdf0e10cSrcweir 	CalcMinMaxBorder();
558*cdf0e10cSrcweir 	return 0;
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir /*--------------------------------------------------------------------
561*cdf0e10cSrcweir 	Beschreibung: Originalgroesse einstellen
562*cdf0e10cSrcweir  --------------------------------------------------------------------*/
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir IMPL_LINK( SvxGrfCropPage, OrigSizeHdl, PushButton *, EMPTYARG )
565*cdf0e10cSrcweir {
566*cdf0e10cSrcweir 	SfxItemPool* pPool = GetItemSet().GetPool();
567*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool" );
568*cdf0e10cSrcweir 	FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
569*cdf0e10cSrcweir 													SID_ATTR_GRAF_CROP ) ) );
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 	long nWidth = aOrigSize.Width() -
572*cdf0e10cSrcweir 		lcl_GetValue( aLeftMF, eUnit ) -
573*cdf0e10cSrcweir 		lcl_GetValue( aRightMF, eUnit );
574*cdf0e10cSrcweir 	aWidthMF.SetValue( aWidthMF.Normalize( nWidth ), eUnit );
575*cdf0e10cSrcweir 	long nHeight = aOrigSize.Height() -
576*cdf0e10cSrcweir 		lcl_GetValue( aTopMF, eUnit ) -
577*cdf0e10cSrcweir 		lcl_GetValue( aBottomMF, eUnit );
578*cdf0e10cSrcweir 	aHeightMF.SetValue( aHeightMF.Normalize( nHeight ), eUnit );
579*cdf0e10cSrcweir 	aWidthZoomMF.SetValue(100);
580*cdf0e10cSrcweir 	aHeightZoomMF.SetValue(100);
581*cdf0e10cSrcweir 	bSetOrigSize = sal_True;
582*cdf0e10cSrcweir 	return 0;
583*cdf0e10cSrcweir }
584*cdf0e10cSrcweir /*--------------------------------------------------------------------
585*cdf0e10cSrcweir 	Beschreibung: Massstab berechnen
586*cdf0e10cSrcweir  --------------------------------------------------------------------*/
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir void SvxGrfCropPage::CalcZoom()
589*cdf0e10cSrcweir {
590*cdf0e10cSrcweir 	SfxItemPool* pPool = GetItemSet().GetPool();
591*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool" );
592*cdf0e10cSrcweir 	FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
593*cdf0e10cSrcweir 													SID_ATTR_GRAF_CROP ) ) );
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 	long nWidth = lcl_GetValue( aWidthMF, eUnit );
596*cdf0e10cSrcweir 	long nHeight = lcl_GetValue( aHeightMF, eUnit );
597*cdf0e10cSrcweir 	long nLRBorders = lcl_GetValue( aLeftMF, eUnit ) +
598*cdf0e10cSrcweir 					  lcl_GetValue( aRightMF, eUnit );
599*cdf0e10cSrcweir 	long nULBorders = lcl_GetValue( aTopMF, eUnit ) +
600*cdf0e10cSrcweir 					  lcl_GetValue( aBottomMF, eUnit );
601*cdf0e10cSrcweir 	sal_uInt16 nZoom = 0;
602*cdf0e10cSrcweir 	long nDen;
603*cdf0e10cSrcweir 	if( (nDen = aOrigSize.Width() - nLRBorders) > 0)
604*cdf0e10cSrcweir 		nZoom = (sal_uInt16)((( nWidth  * 1000L / nDen )+5)/10);
605*cdf0e10cSrcweir 	aWidthZoomMF.SetValue(nZoom);
606*cdf0e10cSrcweir 	if( (nDen = aOrigSize.Height() - nULBorders) > 0)
607*cdf0e10cSrcweir 		nZoom = (sal_uInt16)((( nHeight * 1000L / nDen )+5)/10);
608*cdf0e10cSrcweir 	else
609*cdf0e10cSrcweir 		nZoom = 0;
610*cdf0e10cSrcweir 	aHeightZoomMF.SetValue(nZoom);
611*cdf0e10cSrcweir }
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir /*--------------------------------------------------------------------
614*cdf0e10cSrcweir 	Beschreibung: Minimal-/Maximalwerte fuer die Raender setzen
615*cdf0e10cSrcweir  --------------------------------------------------------------------*/
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir void SvxGrfCropPage::CalcMinMaxBorder()
618*cdf0e10cSrcweir {
619*cdf0e10cSrcweir 	SfxItemPool* pPool = GetItemSet().GetPool();
620*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool" );
621*cdf0e10cSrcweir 	FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
622*cdf0e10cSrcweir 													SID_ATTR_GRAF_CROP ) ) );
623*cdf0e10cSrcweir 	long nR = lcl_GetValue(aRightMF, eUnit );
624*cdf0e10cSrcweir 	long nMinWidth = (aOrigSize.Width() * 10) /11;
625*cdf0e10cSrcweir 	long nMin = nMinWidth - (nR >= 0 ? nR : 0);
626*cdf0e10cSrcweir 	aLeftMF.SetMax( aLeftMF.Normalize(nMin), eUnit );
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir 	long nL = lcl_GetValue(aLeftMF, eUnit );
629*cdf0e10cSrcweir 	nMin = nMinWidth - (nL >= 0 ? nL : 0);
630*cdf0e10cSrcweir 	aRightMF.SetMax( aRightMF.Normalize(nMin), eUnit );
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 	// Zoom nicht unter 2%
633*cdf0e10cSrcweir /*	nMin = (aOrigSize.Width() * 102) /100;
634*cdf0e10cSrcweir 	aLeftMF.SetMax(aPageSize.Width() - nR - nMin);
635*cdf0e10cSrcweir 	aRightMF.SetMax(aPageSize.Width() - nL - nMin);
636*cdf0e10cSrcweir */
637*cdf0e10cSrcweir 	long nUp  = lcl_GetValue( aTopMF, eUnit );
638*cdf0e10cSrcweir 	long nMinHeight = (aOrigSize.Height() * 10) /11;
639*cdf0e10cSrcweir 	nMin = nMinHeight - (nUp >= 0 ? nUp : 0);
640*cdf0e10cSrcweir 	aBottomMF.SetMax( aBottomMF.Normalize(nMin), eUnit );
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 	long nLow = lcl_GetValue(aBottomMF, eUnit );
643*cdf0e10cSrcweir 	nMin = nMinHeight - (nLow >= 0 ? nLow : 0);
644*cdf0e10cSrcweir 	aTopMF.SetMax( aTopMF.Normalize(nMin), eUnit );
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 	// Zoom nicht unter 2%
647*cdf0e10cSrcweir /*	nMin = (aOrigSize.Height() * 102) /100;
648*cdf0e10cSrcweir 	aTopMF.SetMax(aPageSize.Height() - nLow - nMin);
649*cdf0e10cSrcweir 	aBottomMF.SetMax(aPageSize.Height() - nUp - nMin);*/
650*cdf0e10cSrcweir }
651*cdf0e10cSrcweir /*--------------------------------------------------------------------
652*cdf0e10cSrcweir 	Beschreibung: 	Spinsize auf 1/20 der Originalgroesse setzen,
653*cdf0e10cSrcweir 					FixedText mit der Originalgroesse fuellen
654*cdf0e10cSrcweir  --------------------------------------------------------------------*/
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir void SvxGrfCropPage::GraphicHasChanged( sal_Bool bFound )
657*cdf0e10cSrcweir {
658*cdf0e10cSrcweir 	if( bFound )
659*cdf0e10cSrcweir 	{
660*cdf0e10cSrcweir 		SfxItemPool* pPool = GetItemSet().GetPool();
661*cdf0e10cSrcweir 		DBG_ASSERT( pPool, "Wo ist der Pool" );
662*cdf0e10cSrcweir 		FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
663*cdf0e10cSrcweir 													SID_ATTR_GRAF_CROP ) ));
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir 		sal_Int64 nSpin = aLeftMF.Normalize(aOrigSize.Width()) / 20;
666*cdf0e10cSrcweir 		nSpin = MetricField::ConvertValue( nSpin, aOrigSize.Width(), 0,
667*cdf0e10cSrcweir 									   		eUnit, aLeftMF.GetUnit());
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 		// Ist der Rand zu gross, wird er auf beiden Seiten auf 1/3 eingestellt.
670*cdf0e10cSrcweir 		long nR = lcl_GetValue( aRightMF, eUnit );
671*cdf0e10cSrcweir 		long nL = lcl_GetValue( aLeftMF, eUnit );
672*cdf0e10cSrcweir 		if((nL + nR) < - aOrigSize.Width())
673*cdf0e10cSrcweir 		{
674*cdf0e10cSrcweir 			long nVal = aOrigSize.Width() / -3;
675*cdf0e10cSrcweir 			aRightMF.SetValue( aRightMF.Normalize( nVal ), eUnit );
676*cdf0e10cSrcweir 			aLeftMF.SetValue( aLeftMF.Normalize( nVal ), eUnit );
677*cdf0e10cSrcweir 			aExampleWN.SetLeft(nVal);
678*cdf0e10cSrcweir 			aExampleWN.SetRight(nVal);
679*cdf0e10cSrcweir 		}
680*cdf0e10cSrcweir 		long nUp  = lcl_GetValue(aTopMF, eUnit );
681*cdf0e10cSrcweir 		long nLow = lcl_GetValue(aBottomMF, eUnit );
682*cdf0e10cSrcweir 		if((nUp + nLow) < - aOrigSize.Height())
683*cdf0e10cSrcweir 		{
684*cdf0e10cSrcweir 			long nVal = aOrigSize.Height() / -3;
685*cdf0e10cSrcweir 			aTopMF.SetValue( aTopMF.Normalize( nVal ), eUnit );
686*cdf0e10cSrcweir 			aBottomMF.SetValue( aBottomMF.Normalize( nVal ), eUnit );
687*cdf0e10cSrcweir 			aExampleWN.SetTop(nVal);
688*cdf0e10cSrcweir 			aExampleWN.SetBottom(nVal);
689*cdf0e10cSrcweir 		}
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir 		aLeftMF.SetSpinSize(nSpin);
692*cdf0e10cSrcweir 		aRightMF.SetSpinSize(nSpin);
693*cdf0e10cSrcweir 		nSpin = aTopMF.Normalize(aOrigSize.Height()) / 20;
694*cdf0e10cSrcweir 		nSpin = MetricField::ConvertValue( nSpin, aOrigSize.Width(), 0,
695*cdf0e10cSrcweir 									   		eUnit, aLeftMF.GetUnit() );
696*cdf0e10cSrcweir 		aTopMF.SetSpinSize(nSpin);
697*cdf0e10cSrcweir 		aBottomMF.SetSpinSize(nSpin);
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir 		//Originalgroesse anzeigen
700*cdf0e10cSrcweir 		const FieldUnit eMetric = GetModuleFieldUnit( GetItemSet() );
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 		MetricField aFld(this, WB_HIDE);
703*cdf0e10cSrcweir 		SetFieldUnit( aFld, eMetric );
704*cdf0e10cSrcweir 		aFld.SetDecimalDigits( aWidthMF.GetDecimalDigits() );
705*cdf0e10cSrcweir         aFld.SetMax( LONG_MAX - 1 );
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 		aFld.SetValue( aFld.Normalize( aOrigSize.Width() ), eUnit );
708*cdf0e10cSrcweir 		String sTemp = aFld.GetText();
709*cdf0e10cSrcweir 		aFld.SetValue( aFld.Normalize( aOrigSize.Height() ), eUnit );
710*cdf0e10cSrcweir 		sTemp += UniString::CreateFromAscii(" x ");
711*cdf0e10cSrcweir 		sTemp += aFld.GetText();
712*cdf0e10cSrcweir 		aOrigSizeFT.SetText(sTemp);
713*cdf0e10cSrcweir 	}
714*cdf0e10cSrcweir 	aLeftFT			.Enable(bFound);
715*cdf0e10cSrcweir 	aLeftMF         .Enable(bFound);
716*cdf0e10cSrcweir 	aRightFT        .Enable(bFound);
717*cdf0e10cSrcweir 	aRightMF        .Enable(bFound);
718*cdf0e10cSrcweir 	aTopFT          .Enable(bFound);
719*cdf0e10cSrcweir 	aTopMF          .Enable(bFound);
720*cdf0e10cSrcweir 	aBottomFT       .Enable(bFound);
721*cdf0e10cSrcweir 	aBottomMF       .Enable(bFound);
722*cdf0e10cSrcweir 	aSizeConstRB    .Enable(bFound);
723*cdf0e10cSrcweir 	aZoomConstRB    .Enable(bFound);
724*cdf0e10cSrcweir 	aWidthFT        .Enable(bFound);
725*cdf0e10cSrcweir 	aWidthMF        .Enable(bFound);
726*cdf0e10cSrcweir 	aHeightFT       .Enable(bFound);
727*cdf0e10cSrcweir 	aHeightMF		.Enable(bFound);
728*cdf0e10cSrcweir 	aWidthZoomFT    .Enable(bFound);
729*cdf0e10cSrcweir 	aWidthZoomMF    .Enable(bFound);
730*cdf0e10cSrcweir 	aHeightZoomFT   .Enable(bFound);
731*cdf0e10cSrcweir 	aHeightZoomMF   .Enable(bFound);
732*cdf0e10cSrcweir 	aExampleWN      .Enable(bFound);
733*cdf0e10cSrcweir 	aOrigSizePB     .Enable(bFound);
734*cdf0e10cSrcweir 	aOrigSizeFT     .Enable(bFound);
735*cdf0e10cSrcweir }
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir IMPL_LINK( SvxGrfCropPage, Timeout, Timer *, EMPTYARG )
738*cdf0e10cSrcweir {
739*cdf0e10cSrcweir 	DBG_ASSERT(pLastCropField,"Timeout ohne Feld?");
740*cdf0e10cSrcweir 	CropHdl(pLastCropField);
741*cdf0e10cSrcweir 	pLastCropField = 0;
742*cdf0e10cSrcweir 	return 0;
743*cdf0e10cSrcweir }
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir IMPL_LINK( SvxGrfCropPage, CropLoseFocusHdl, MetricField*, pField )
747*cdf0e10cSrcweir {
748*cdf0e10cSrcweir 	aTimer.Stop();
749*cdf0e10cSrcweir 	CropHdl(pField);
750*cdf0e10cSrcweir 	pLastCropField = 0;
751*cdf0e10cSrcweir 	return 0;
752*cdf0e10cSrcweir }
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir IMPL_LINK( SvxGrfCropPage, CropModifyHdl, MetricField *, pField )
756*cdf0e10cSrcweir {
757*cdf0e10cSrcweir 	aTimer.Start();
758*cdf0e10cSrcweir 	pLastCropField = pField;
759*cdf0e10cSrcweir 	return 0;
760*cdf0e10cSrcweir }
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir Size SvxGrfCropPage::GetGrfOrigSize( const Graphic& rGrf ) const
763*cdf0e10cSrcweir {
764*cdf0e10cSrcweir     const MapMode aMapTwip( MAP_TWIP );
765*cdf0e10cSrcweir     Size aSize( rGrf.GetPrefSize() );
766*cdf0e10cSrcweir     if( MAP_PIXEL == rGrf.GetPrefMapMode().GetMapUnit() )
767*cdf0e10cSrcweir         aSize = PixelToLogic( aSize, aMapTwip );
768*cdf0e10cSrcweir     else
769*cdf0e10cSrcweir         aSize = OutputDevice::LogicToLogic( aSize,
770*cdf0e10cSrcweir 										rGrf.GetPrefMapMode(), aMapTwip );
771*cdf0e10cSrcweir 	return aSize;
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir /*****************************************************************/
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir SvxGrfCropPage::SvxCropExample::SvxCropExample( Window* pPar,
777*cdf0e10cSrcweir 												const ResId& rResId )
778*cdf0e10cSrcweir 	: Window( pPar, rResId ),
779*cdf0e10cSrcweir     aFrameSize( OutputDevice::LogicToLogic(
780*cdf0e10cSrcweir                             Size( CM_1_TO_TWIP / 2, CM_1_TO_TWIP / 2 ),
781*cdf0e10cSrcweir                             MapMode( MAP_TWIP ), GetMapMode() )),
782*cdf0e10cSrcweir     aTopLeft(0,0), aBottomRight(0,0)
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO );
785*cdf0e10cSrcweir }
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir void SvxGrfCropPage::SvxCropExample::Paint( const Rectangle& )
788*cdf0e10cSrcweir {
789*cdf0e10cSrcweir 	Size aWinSize( PixelToLogic(GetOutputSizePixel() ));
790*cdf0e10cSrcweir     SetLineColor();
791*cdf0e10cSrcweir 	SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
792*cdf0e10cSrcweir 	SetRasterOp( ROP_OVERPAINT );
793*cdf0e10cSrcweir     DrawRect( Rectangle( Point(), aWinSize ) );
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir     SetLineColor( Color( COL_WHITE ) );
796*cdf0e10cSrcweir 	Rectangle aRect(Point((aWinSize.Width() - aFrameSize.Width())/2,
797*cdf0e10cSrcweir 						  (aWinSize.Height() - aFrameSize.Height())/2),
798*cdf0e10cSrcweir 						  aFrameSize );
799*cdf0e10cSrcweir 	aGrf.Draw( this,  aRect.TopLeft(), aRect.GetSize() );
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 	Size aSz( 2, 0 );
802*cdf0e10cSrcweir 	aSz = PixelToLogic( aSz );
803*cdf0e10cSrcweir 	SetFillColor( Color( COL_TRANSPARENT ) );
804*cdf0e10cSrcweir 	SetRasterOp( ROP_INVERT );
805*cdf0e10cSrcweir 	aRect.Left() 	+= aTopLeft.Y();
806*cdf0e10cSrcweir 	aRect.Top() 	+= aTopLeft.X();
807*cdf0e10cSrcweir 	aRect.Right() 	-= aBottomRight.Y();
808*cdf0e10cSrcweir 	aRect.Bottom() 	-= aBottomRight.X();
809*cdf0e10cSrcweir 	DrawRect( aRect );
810*cdf0e10cSrcweir }
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir void SvxGrfCropPage::SvxCropExample::SetFrameSize( const Size& rSz )
813*cdf0e10cSrcweir {
814*cdf0e10cSrcweir 	aFrameSize = rSz;
815*cdf0e10cSrcweir 	if(!aFrameSize.Width())
816*cdf0e10cSrcweir 		aFrameSize.Width() = 1;
817*cdf0e10cSrcweir 	if(!aFrameSize.Height())
818*cdf0e10cSrcweir 		aFrameSize.Height() = 1;
819*cdf0e10cSrcweir 	Size aWinSize( GetOutputSizePixel() );
820*cdf0e10cSrcweir 	Fraction aXScale( aWinSize.Width() * 4, aFrameSize.Width() * 5 );
821*cdf0e10cSrcweir 	Fraction aYScale( aWinSize.Height() * 4, aFrameSize.Height() * 5 );
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir 	if( aYScale < aXScale )
824*cdf0e10cSrcweir 		aXScale = aYScale;
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir 	MapMode aMapMode( GetMapMode() );
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir 	aMapMode.SetScaleX( aXScale );
829*cdf0e10cSrcweir 	aMapMode.SetScaleY( aXScale );
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir 	SetMapMode( aMapMode );
832*cdf0e10cSrcweir 	Invalidate();
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir 
838