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