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