merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / sd / source / ui / dlg / copydlg.cxx
blob0553159870dfd0353bff92f4ee943699e76b99ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sd.hxx"
32 #ifdef SD_DLLIMPLEMENTATION
33 #undef SD_DLLIMPLEMENTATION
34 #endif
36 #include "copydlg.hxx"
37 #include <svx/dlgutil.hxx>
38 #include <sfx2/module.hxx>
39 #include <svx/xcolit.hxx>
40 #include <svx/xflclit.hxx>
41 #include <svx/xdef.hxx>
42 #include <svx/xfillit0.hxx>
43 #include <svx/xenum.hxx>
45 #include <sfx2/app.hxx>
49 #include "sdattr.hxx"
51 #include "copydlg.hrc"
52 #include "View.hxx"
53 #include "sdresid.hxx"
54 #include "drawdoc.hxx"
55 #include "res_bmp.hrc"
57 namespace sd {
59 #define TOKEN (sal_Unicode(';'))
61 /*************************************************************************
63 |* Dialog zum Kopieren von Objekten
65 \************************************************************************/
67 CopyDlg::CopyDlg(
68 ::Window* pWindow,
69 const SfxItemSet& rInAttrs,
70 XColorTable* pColTab,
71 ::sd::View* pInView )
72 : SfxModalDialog ( pWindow, SdResId( DLG_COPY ) ),
73 maFtCopies ( this, SdResId( FT_COPIES ) ),
74 maNumFldCopies ( this, SdResId( NUM_FLD_COPIES ) ),
75 maBtnSetViewData ( this, SdResId( BTN_SET_VIEWDATA ) ),
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 maGrpMovement ( this, SdResId( GRP_MOVEMENT ) ),
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 maGrpEnlargement ( this, SdResId( GRP_ENLARGEMENT ) ),
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 maGrpColor ( this, SdResId( GRP_COLOR ) ),
93 maBtnOK ( this, SdResId( BTN_OK ) ),
94 maBtnCancel ( this, SdResId( BTN_CANCEL ) ),
95 maBtnHelp ( this, SdResId( BTN_HELP ) ),
96 maBtnSetDefault ( this, SdResId( BTN_SET_DEFAULT ) ),
97 mrOutAttrs ( rInAttrs ),
98 mpColorTab ( pColTab ),
99 maUIScale(pInView->GetDoc()->GetUIScale()),
100 mpView ( pInView )
102 FreeResource();
104 // Set up the view data button (image and accessible name).
105 maBtnSetViewData.SetModeImage( Image( SdResId( IMG_PIPETTE_H ) ), BMP_COLOR_HIGHCONTRAST );
106 maBtnSetViewData.SetAccessibleName (maBtnSetViewData.GetQuickHelpText());
108 // Farbtabellen
109 DBG_ASSERT( mpColorTab, "Keine gueltige ColorTable uebergeben!" );
110 maLbStartColor.Fill( mpColorTab );
111 maLbEndColor.CopyEntries( maLbStartColor );
113 maLbStartColor.SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) );
114 maBtnSetViewData.SetClickHdl( LINK( this, CopyDlg, SetViewData ) );
115 maBtnSetDefault.SetClickHdl( LINK( this, CopyDlg, SetDefault ) );
118 FieldUnit eFUnit( SfxModule::GetCurrentFieldUnit() );
120 SetFieldUnit( maMtrFldMoveX, eFUnit, TRUE );
121 SetFieldUnit( maMtrFldMoveY, eFUnit, TRUE );
122 SetFieldUnit( maMtrFldWidth, eFUnit, TRUE );
123 SetFieldUnit( maMtrFldHeight, eFUnit, TRUE );
125 Reset(0L);
128 /*************************************************************************
130 |* Dtor
132 \************************************************************************/
134 CopyDlg::~CopyDlg()
136 String& rStr = GetExtraData();
138 rStr = UniString::CreateFromInt64( maNumFldCopies.GetValue() );
139 rStr.Append( TOKEN );
141 rStr += UniString::CreateFromInt64( maMtrFldMoveX.GetValue() );
142 rStr.Append( TOKEN );
144 rStr += UniString::CreateFromInt64( maMtrFldMoveY.GetValue() );
145 rStr.Append( TOKEN );
147 rStr += UniString::CreateFromInt64( maMtrFldAngle.GetValue() );
148 rStr.Append( TOKEN );
150 rStr += UniString::CreateFromInt64( maMtrFldWidth.GetValue() );
151 rStr.Append( TOKEN );
153 rStr += UniString::CreateFromInt64( maMtrFldHeight.GetValue() );
154 rStr.Append( TOKEN );
156 rStr += UniString::CreateFromInt32( (long)maLbStartColor.GetSelectEntryColor().GetColor() );
157 rStr.Append( TOKEN );
159 rStr += UniString::CreateFromInt32( (long)maLbEndColor.GetSelectEntryColor().GetColor() );
162 /*************************************************************************
164 |* Liest uebergebenen Item-Set oder wertet den INI-String aus
166 \************************************************************************/
168 IMPL_LINK( CopyDlg, Reset, void*, EMPTYARG )
170 const SfxPoolItem* pPoolItem = NULL;
171 String aStr( GetExtraData() );
173 if( aStr.GetTokenCount( TOKEN ) < 8 )
175 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_NUMBER, TRUE, &pPoolItem ) )
176 maNumFldCopies.SetValue( ( ( const SfxUInt16Item* ) pPoolItem )->GetValue() );
177 else
178 maNumFldCopies.SetValue( 1L );
180 long nMoveX = 500L;
181 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_X, TRUE, &pPoolItem ) )
182 nMoveX = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
183 SetMetricValue( maMtrFldMoveX, Fraction(nMoveX) / maUIScale, SFX_MAPUNIT_100TH_MM);
185 long nMoveY = 500L;
186 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_Y, TRUE, &pPoolItem ) )
187 nMoveY = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
188 SetMetricValue( maMtrFldMoveY, Fraction(nMoveY) / maUIScale, SFX_MAPUNIT_100TH_MM);
190 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_ANGLE, TRUE, &pPoolItem ) )
191 maMtrFldAngle.SetValue( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
192 else
193 maMtrFldAngle.SetValue( 0L );
195 long nWidth = 0L;
196 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_WIDTH, TRUE, &pPoolItem ) )
197 nWidth = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
198 SetMetricValue( maMtrFldWidth, Fraction(nWidth) / maUIScale, SFX_MAPUNIT_100TH_MM);
200 long nHeight = 0L;
201 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_HEIGHT, TRUE, &pPoolItem ) )
202 nHeight = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() );
203 SetMetricValue( maMtrFldHeight, Fraction(nHeight) / maUIScale, SFX_MAPUNIT_100TH_MM);
205 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, TRUE, &pPoolItem ) )
207 Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
208 maLbStartColor.SelectEntry( aColor );
209 maLbEndColor.SelectEntry( aColor );
211 else
213 maLbStartColor.SetNoSelection();
214 maLbEndColor.SetNoSelection();
215 maLbEndColor.Disable();
216 maFtEndColor.Disable();
219 else
221 long nTmp;
222 nTmp = (long)aStr.GetToken( 0, TOKEN ).ToInt32();
223 maNumFldCopies.SetValue( nTmp );
225 nTmp = (long)aStr.GetToken( 1, TOKEN ).ToInt32();
226 maMtrFldMoveX.SetValue( nTmp );
228 nTmp = (long)aStr.GetToken( 2, TOKEN ).ToInt32();
229 maMtrFldMoveY.SetValue( nTmp );
231 nTmp = (long)aStr.GetToken( 3, TOKEN ).ToInt32();
232 maMtrFldAngle.SetValue( nTmp );
234 nTmp = (long)aStr.GetToken( 4, TOKEN ).ToInt32();
235 maMtrFldWidth.SetValue( nTmp );
237 nTmp = (long)aStr.GetToken( 5, TOKEN ).ToInt32();
238 maMtrFldHeight.SetValue( nTmp );
240 nTmp = (long)aStr.GetToken( 6, TOKEN ).ToInt32();
241 maLbStartColor.SelectEntry( Color( nTmp ) );
243 nTmp = (long)aStr.GetToken( 7, TOKEN ).ToInt32();
244 maLbEndColor.SelectEntry( Color( nTmp ) );
247 return 0;
250 /*************************************************************************
252 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
254 \************************************************************************/
256 void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
258 long nMoveX = Fraction( GetCoreValue( maMtrFldMoveX, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
259 long nMoveY = Fraction( GetCoreValue( maMtrFldMoveY, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
260 long nHeight = Fraction( GetCoreValue( maMtrFldHeight, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
261 long nWidth = Fraction( GetCoreValue( maMtrFldWidth, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
263 rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, (UINT16) maNumFldCopies.GetValue() ) );
264 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) );
265 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) );
266 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_ANGLE, static_cast<INT32>(maMtrFldAngle.GetValue()) ) );
267 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) );
268 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );
270 if( maLbStartColor.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
272 XColorItem aXColorItem( ATTR_COPY_START_COLOR, maLbStartColor.GetSelectEntry(),
273 maLbStartColor.GetSelectEntryColor() );
274 rOutAttrs.Put( aXColorItem );
276 if( maLbEndColor.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
278 XColorItem aXColorItem( ATTR_COPY_END_COLOR, maLbEndColor.GetSelectEntry(),
279 maLbEndColor.GetSelectEntryColor() );
280 rOutAttrs.Put( aXColorItem );
284 /*************************************************************************
286 |* Enabled und selektiert Endfarben-LB
288 \************************************************************************/
290 IMPL_LINK( CopyDlg, SelectColorHdl, void *, EMPTYARG )
292 USHORT nPos = maLbStartColor.GetSelectEntryPos();
294 if( nPos != LISTBOX_ENTRY_NOTFOUND &&
295 !maLbEndColor.IsEnabled() )
297 maLbEndColor.SelectEntryPos( nPos );
298 maLbEndColor.Enable();
299 maFtEndColor.Enable();
301 return 0;
304 /*************************************************************************
305 |* Setzt Werte der Selektion
306 \************************************************************************/
308 IMPL_LINK( CopyDlg, SetViewData, void*, EMPTYARG )
310 Rectangle aRect = mpView->GetAllMarkedRect();
312 SetMetricValue( maMtrFldMoveX, Fraction( aRect.GetWidth() ) /
313 maUIScale, SFX_MAPUNIT_100TH_MM);
314 SetMetricValue( maMtrFldMoveY, Fraction( aRect.GetHeight() ) /
315 maUIScale, SFX_MAPUNIT_100TH_MM);
317 // Farb-Attribut setzen
318 const SfxPoolItem* pPoolItem = NULL;
319 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, TRUE, &pPoolItem ) )
321 Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
322 maLbStartColor.SelectEntry( aColor );
325 return 0;
328 /*************************************************************************
329 |* Setzt Werte auf Standard
330 \************************************************************************/
332 IMPL_LINK( CopyDlg, SetDefault, void*, EMPTYARG )
334 maNumFldCopies.SetValue( 1L );
336 long nValue = 500L;
337 SetMetricValue( maMtrFldMoveX, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
338 SetMetricValue( maMtrFldMoveY, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
340 nValue = 0L;
341 maMtrFldAngle.SetValue( nValue );
342 SetMetricValue( maMtrFldWidth, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
343 SetMetricValue( maMtrFldHeight, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
345 // Farb-Attribut setzen
346 const SfxPoolItem* pPoolItem = NULL;
347 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, TRUE, &pPoolItem ) )
349 Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
350 maLbStartColor.SelectEntry( aColor );
351 maLbEndColor.SelectEntry( aColor );
354 return 0;
358 } // end of namespace sd
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */