xref: /aoo41x/main/sd/source/ui/dlg/copydlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #ifdef SD_DLLIMPLEMENTATION
32 #undef SD_DLLIMPLEMENTATION
33 #endif
34 
35 #include "copydlg.hxx"
36 #include <svx/dlgutil.hxx>
37 #include <sfx2/module.hxx>
38 #include <svx/xcolit.hxx>
39 #include <svx/xflclit.hxx>
40 #include <svx/xdef.hxx>
41 #include <svx/xfillit0.hxx>
42 #include <svx/xenum.hxx>
43 
44 #include <sfx2/app.hxx>
45 
46 
47 
48 #include "sdattr.hxx"
49 
50 #include "copydlg.hrc"
51 #include "View.hxx"
52 #include "sdresid.hxx"
53 #include "drawdoc.hxx"
54 #include "res_bmp.hrc"
55 
56 namespace sd {
57 
58 #define TOKEN (sal_Unicode(';'))
59 
60 /*************************************************************************
61 |*
62 |* Dialog zum Kopieren von Objekten
63 |*
64 \************************************************************************/
65 
66 CopyDlg::CopyDlg(
67     ::Window* pWindow,
68     const SfxItemSet& rInAttrs,
69     XColorTable* pColTab,
70     ::sd::View* pInView )
71     : SfxModalDialog     ( pWindow, SdResId( DLG_COPY ) ),
72       maFtCopies           ( this, SdResId( FT_COPIES ) ),
73       maNumFldCopies       ( this, SdResId( NUM_FLD_COPIES ) ),
74       maBtnSetViewData     ( this, SdResId( BTN_SET_VIEWDATA ) ),
75       maGrpMovement        ( this, SdResId( GRP_MOVEMENT ) ),
76       maFtMoveX            ( this, SdResId( FT_MOVE_X ) ),
77       maMtrFldMoveX        ( this, SdResId( MTR_FLD_MOVE_X ) ),
78       maFtMoveY            ( this, SdResId( FT_MOVE_Y ) ),
79       maMtrFldMoveY        ( this, SdResId( MTR_FLD_MOVE_Y ) ),
80       maFtAngle            ( this, SdResId( FT_ANGLE ) ),
81       maMtrFldAngle        ( this, SdResId( MTR_FLD_ANGLE ) ),
82       maGrpEnlargement     ( this, SdResId( GRP_ENLARGEMENT ) ),
83       maFtWidth            ( this, SdResId( FT_WIDTH ) ),
84       maMtrFldWidth        ( this, SdResId( MTR_FLD_WIDTH ) ),
85       maFtHeight           ( this, SdResId( FT_HEIGHT ) ),
86       maMtrFldHeight       ( this, SdResId( MTR_FLD_HEIGHT ) ),
87       maGrpColor           ( this, SdResId( GRP_COLOR ) ),
88       maFtStartColor       ( this, SdResId( FT_START_COLOR ) ),
89       maLbStartColor       ( this, SdResId( LB_START_COLOR ) ),
90       maFtEndColor         ( this, SdResId( FT_END_COLOR ) ),
91       maLbEndColor         ( this, SdResId( LB_END_COLOR ) ),
92       maBtnOK              ( this, SdResId( BTN_OK ) ),
93       maBtnCancel          ( this, SdResId( BTN_CANCEL ) ),
94       maBtnHelp            ( this, SdResId( BTN_HELP ) ),
95       maBtnSetDefault      ( this, SdResId( BTN_SET_DEFAULT ) ),
96       mrOutAttrs			( rInAttrs ),
97       mpColorTab			( pColTab ),
98 	  maUIScale(pInView->GetDoc()->GetUIScale()),
99       mpView				( pInView )
100 {
101 	FreeResource();
102 
103     // Set up the view data button (image and accessible name).
104 	maBtnSetViewData.SetModeImage( Image( SdResId( IMG_PIPETTE_H ) ), BMP_COLOR_HIGHCONTRAST );
105     maBtnSetViewData.SetAccessibleName (maBtnSetViewData.GetQuickHelpText());
106 
107 	// Farbtabellen
108 	DBG_ASSERT( mpColorTab, "Keine gueltige ColorTable uebergeben!" );
109 	maLbStartColor.Fill( mpColorTab );
110 	maLbEndColor.CopyEntries( maLbStartColor );
111 
112 	maLbStartColor.SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) );
113 	maBtnSetViewData.SetClickHdl( LINK( this, CopyDlg, SetViewData ) );
114 	maBtnSetDefault.SetClickHdl( LINK( this, CopyDlg, SetDefault ) );
115 
116 
117 	FieldUnit eFUnit( SfxModule::GetCurrentFieldUnit() );
118 
119 	SetFieldUnit( maMtrFldMoveX, eFUnit, sal_True );
120 	SetFieldUnit( maMtrFldMoveY, eFUnit, sal_True );
121 	SetFieldUnit( maMtrFldWidth, eFUnit, sal_True );
122 	SetFieldUnit( maMtrFldHeight, eFUnit, sal_True );
123 
124 	Reset(0L);
125 }
126 
127 /*************************************************************************
128 |*
129 |* Dtor
130 |*
131 \************************************************************************/
132 
133 CopyDlg::~CopyDlg()
134 {
135 	String& rStr = GetExtraData();
136 
137 	rStr = UniString::CreateFromInt64( maNumFldCopies.GetValue() );
138 	rStr.Append( TOKEN );
139 
140 	rStr += UniString::CreateFromInt64( maMtrFldMoveX.GetValue() );
141 	rStr.Append( TOKEN );
142 
143 	rStr += UniString::CreateFromInt64( maMtrFldMoveY.GetValue() );
144 	rStr.Append( TOKEN );
145 
146 	rStr += UniString::CreateFromInt64( maMtrFldAngle.GetValue() );
147 	rStr.Append( TOKEN );
148 
149 	rStr += UniString::CreateFromInt64( maMtrFldWidth.GetValue() );
150 	rStr.Append( TOKEN );
151 
152 	rStr += UniString::CreateFromInt64( maMtrFldHeight.GetValue() );
153 	rStr.Append( TOKEN );
154 
155 	rStr += UniString::CreateFromInt32( (long)maLbStartColor.GetSelectEntryColor().GetColor() );
156 	rStr.Append( TOKEN );
157 
158 	rStr += UniString::CreateFromInt32( (long)maLbEndColor.GetSelectEntryColor().GetColor() );
159 }
160 
161 /*************************************************************************
162 |*
163 |* Liest uebergebenen Item-Set oder wertet den INI-String aus
164 |*
165 \************************************************************************/
166 
167 IMPL_LINK( CopyDlg, Reset, void*, EMPTYARG )
168 {
169 	const SfxPoolItem* pPoolItem = NULL;
170 	String aStr( GetExtraData() );
171 
172 	if( aStr.GetTokenCount( TOKEN ) < 8 )
173 	{
174 		if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_NUMBER, sal_True, &pPoolItem ) )
175 			maNumFldCopies.SetValue( ( ( const SfxUInt16Item* ) pPoolItem )->GetValue() );
176 		else
177 			maNumFldCopies.SetValue( 1L );
178 
179 		long nMoveX = 500L;
180 		if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_X, sal_True, &pPoolItem ) )
181 			nMoveX = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
182 		SetMetricValue( maMtrFldMoveX, Fraction(nMoveX) / maUIScale, SFX_MAPUNIT_100TH_MM);
183 
184 		long nMoveY = 500L;
185 		if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_Y, sal_True, &pPoolItem ) )
186 			nMoveY = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
187 		SetMetricValue( maMtrFldMoveY, Fraction(nMoveY) / maUIScale, SFX_MAPUNIT_100TH_MM);
188 
189 		if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_ANGLE, sal_True, &pPoolItem ) )
190 			maMtrFldAngle.SetValue( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
191 		else
192 			maMtrFldAngle.SetValue( 0L );
193 
194 		long nWidth = 0L;
195 		if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_WIDTH, sal_True, &pPoolItem ) )
196 			nWidth = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
197 		SetMetricValue( maMtrFldWidth, Fraction(nWidth) / maUIScale, SFX_MAPUNIT_100TH_MM);
198 
199 		long nHeight = 0L;
200 		if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_HEIGHT, sal_True, &pPoolItem ) )
201 			nHeight = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
202 		SetMetricValue( maMtrFldHeight, Fraction(nHeight) / maUIScale, SFX_MAPUNIT_100TH_MM);
203 
204 		if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) )
205 		{
206 			Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
207 			maLbStartColor.SelectEntry( aColor );
208 			maLbEndColor.SelectEntry( aColor );
209 		}
210 		else
211 		{
212 			maLbStartColor.SetNoSelection();
213 			maLbEndColor.SetNoSelection();
214 			maLbEndColor.Disable();
215 			maFtEndColor.Disable();
216 		}
217 	}
218 	else
219 	{
220 		long nTmp;
221 		nTmp = (long)aStr.GetToken( 0, TOKEN ).ToInt32();
222 		maNumFldCopies.SetValue( nTmp );
223 
224 		nTmp = (long)aStr.GetToken( 1, TOKEN ).ToInt32();
225 		maMtrFldMoveX.SetValue( nTmp );
226 
227 		nTmp = (long)aStr.GetToken( 2, TOKEN ).ToInt32();
228 		maMtrFldMoveY.SetValue( nTmp );
229 
230 		nTmp = (long)aStr.GetToken( 3, TOKEN ).ToInt32();
231 		maMtrFldAngle.SetValue( nTmp );
232 
233 		nTmp = (long)aStr.GetToken( 4, TOKEN ).ToInt32();
234 		maMtrFldWidth.SetValue( nTmp );
235 
236 		nTmp = (long)aStr.GetToken( 5, TOKEN ).ToInt32();
237 		maMtrFldHeight.SetValue( nTmp );
238 
239 		nTmp = (long)aStr.GetToken( 6, TOKEN ).ToInt32();
240 		maLbStartColor.SelectEntry( Color( nTmp ) );
241 
242 		nTmp = (long)aStr.GetToken( 7, TOKEN ).ToInt32();
243 		maLbEndColor.SelectEntry( Color( nTmp ) );
244 	}
245 
246 	return 0;
247 }
248 
249 /*************************************************************************
250 |*
251 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
252 |*
253 \************************************************************************/
254 
255 void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
256 {
257 	long nMoveX = Fraction( GetCoreValue( maMtrFldMoveX, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
258 	long nMoveY = Fraction( GetCoreValue( maMtrFldMoveY, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
259 	long nHeight = Fraction( GetCoreValue( maMtrFldHeight, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
260 	long nWidth  = Fraction( GetCoreValue( maMtrFldWidth, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
261 
262 	rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, (sal_uInt16) maNumFldCopies.GetValue() ) );
263 	rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) );
264 	rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) );
265 	rOutAttrs.Put( SfxInt32Item( ATTR_COPY_ANGLE, static_cast<sal_Int32>(maMtrFldAngle.GetValue()) ) );
266 	rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) );
267 	rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );
268 
269 	if( maLbStartColor.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
270 	{
271 		XColorItem aXColorItem( ATTR_COPY_START_COLOR, maLbStartColor.GetSelectEntry(),
272 									maLbStartColor.GetSelectEntryColor() );
273 		rOutAttrs.Put( aXColorItem );
274 	}
275 	if( maLbEndColor.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
276 	{
277 		XColorItem aXColorItem( ATTR_COPY_END_COLOR, maLbEndColor.GetSelectEntry(),
278 									maLbEndColor.GetSelectEntryColor() );
279 		rOutAttrs.Put( aXColorItem );
280 	}
281 }
282 
283 /*************************************************************************
284 |*
285 |* Enabled und selektiert Endfarben-LB
286 |*
287 \************************************************************************/
288 
289 IMPL_LINK( CopyDlg, SelectColorHdl, void *, EMPTYARG )
290 {
291 	sal_uInt16 nPos = maLbStartColor.GetSelectEntryPos();
292 
293 	if( nPos != LISTBOX_ENTRY_NOTFOUND &&
294 		!maLbEndColor.IsEnabled() )
295 	{
296 		maLbEndColor.SelectEntryPos( nPos );
297 		maLbEndColor.Enable();
298 		maFtEndColor.Enable();
299 	}
300 	return 0;
301 }
302 
303 /*************************************************************************
304 |* Setzt Werte der Selektion
305 \************************************************************************/
306 
307 IMPL_LINK( CopyDlg, SetViewData, void*, EMPTYARG )
308 {
309 	Rectangle aRect = mpView->GetAllMarkedRect();
310 
311 	SetMetricValue( maMtrFldMoveX, Fraction( aRect.GetWidth() ) /
312 									maUIScale, SFX_MAPUNIT_100TH_MM);
313 	SetMetricValue( maMtrFldMoveY, Fraction( aRect.GetHeight() ) /
314 									maUIScale, SFX_MAPUNIT_100TH_MM);
315 
316 	// Farb-Attribut setzen
317 	const SfxPoolItem*	pPoolItem = NULL;
318 	if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) )
319 	{
320 		Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
321 		maLbStartColor.SelectEntry( aColor );
322 	}
323 
324 	return 0;
325 }
326 
327 /*************************************************************************
328 |* Setzt Werte auf Standard
329 \************************************************************************/
330 
331 IMPL_LINK( CopyDlg, SetDefault, void*, EMPTYARG )
332 {
333 	maNumFldCopies.SetValue( 1L );
334 
335 	long nValue = 500L;
336 	SetMetricValue( maMtrFldMoveX, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
337 	SetMetricValue( maMtrFldMoveY, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
338 
339 	nValue = 0L;
340 	maMtrFldAngle.SetValue( nValue );
341 	SetMetricValue( maMtrFldWidth, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
342 	SetMetricValue( maMtrFldHeight, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
343 
344 	// Farb-Attribut setzen
345 	const SfxPoolItem*	pPoolItem = NULL;
346 	if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) )
347 	{
348 		Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
349 		maLbStartColor.SelectEntry( aColor );
350 		maLbEndColor.SelectEntry( aColor );
351 	}
352 
353 	return 0;
354 }
355 
356 
357 } // end of namespace sd
358