1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: copydlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
38 #include "copydlg.hxx"
39 #include <svx/dlgutil.hxx>
40 #include <sfx2/module.hxx>
41 #include <svx/xcolit.hxx>
42 #include <svx/xflclit.hxx>
43 #include <svx/xdef.hxx>
44 #include <svx/xfillit0.hxx>
45 #include <svx/xenum.hxx>
47 #include <sfx2/app.hxx>
53 #include "copydlg.hrc"
55 #include "sdresid.hxx"
56 #include "drawdoc.hxx"
57 #include "res_bmp.hrc"
61 #define TOKEN (sal_Unicode(';'))
63 /*************************************************************************
65 |* Dialog zum Kopieren von Objekten
67 \************************************************************************/
71 const SfxItemSet
& rInAttrs
,
74 : SfxModalDialog ( pWindow
, SdResId( DLG_COPY
) ),
75 maFtCopies ( this, SdResId( FT_COPIES
) ),
76 maNumFldCopies ( this, SdResId( NUM_FLD_COPIES
) ),
77 maBtnSetViewData ( this, SdResId( BTN_SET_VIEWDATA
) ),
78 maFtMoveX ( this, SdResId( FT_MOVE_X
) ),
79 maMtrFldMoveX ( this, SdResId( MTR_FLD_MOVE_X
) ),
80 maFtMoveY ( this, SdResId( FT_MOVE_Y
) ),
81 maMtrFldMoveY ( this, SdResId( MTR_FLD_MOVE_Y
) ),
82 maFtAngle ( this, SdResId( FT_ANGLE
) ),
83 maMtrFldAngle ( this, SdResId( MTR_FLD_ANGLE
) ),
84 maGrpMovement ( this, SdResId( GRP_MOVEMENT
) ),
85 maFtWidth ( this, SdResId( FT_WIDTH
) ),
86 maMtrFldWidth ( this, SdResId( MTR_FLD_WIDTH
) ),
87 maFtHeight ( this, SdResId( FT_HEIGHT
) ),
88 maMtrFldHeight ( this, SdResId( MTR_FLD_HEIGHT
) ),
89 maGrpEnlargement ( this, SdResId( GRP_ENLARGEMENT
) ),
90 maFtStartColor ( this, SdResId( FT_START_COLOR
) ),
91 maLbStartColor ( this, SdResId( LB_START_COLOR
) ),
92 maFtEndColor ( this, SdResId( FT_END_COLOR
) ),
93 maLbEndColor ( this, SdResId( LB_END_COLOR
) ),
94 maGrpColor ( this, SdResId( GRP_COLOR
) ),
95 maBtnOK ( this, SdResId( BTN_OK
) ),
96 maBtnCancel ( this, SdResId( BTN_CANCEL
) ),
97 maBtnHelp ( this, SdResId( BTN_HELP
) ),
98 maBtnSetDefault ( this, SdResId( BTN_SET_DEFAULT
) ),
99 mrOutAttrs ( rInAttrs
),
100 mpColorTab ( pColTab
),
101 maUIScale(pInView
->GetDoc()->GetUIScale()),
106 // Set up the view data button (image and accessible name).
107 maBtnSetViewData
.SetModeImage( Image( SdResId( IMG_PIPETTE_H
) ), BMP_COLOR_HIGHCONTRAST
);
108 maBtnSetViewData
.SetAccessibleName (maBtnSetViewData
.GetQuickHelpText());
111 DBG_ASSERT( mpColorTab
, "Keine gueltige ColorTable uebergeben!" );
112 maLbStartColor
.Fill( mpColorTab
);
113 maLbEndColor
.CopyEntries( maLbStartColor
);
115 maLbStartColor
.SetSelectHdl( LINK( this, CopyDlg
, SelectColorHdl
) );
116 maBtnSetViewData
.SetClickHdl( LINK( this, CopyDlg
, SetViewData
) );
117 maBtnSetDefault
.SetClickHdl( LINK( this, CopyDlg
, SetDefault
) );
120 FieldUnit
eFUnit( GetModuleFieldUnit() );
122 SetFieldUnit( maMtrFldMoveX
, eFUnit
, TRUE
);
123 SetFieldUnit( maMtrFldMoveY
, eFUnit
, TRUE
);
124 SetFieldUnit( maMtrFldWidth
, eFUnit
, TRUE
);
125 SetFieldUnit( maMtrFldHeight
, eFUnit
, TRUE
);
130 /*************************************************************************
134 \************************************************************************/
138 String
& rStr
= GetExtraData();
140 rStr
= UniString::CreateFromInt64( maNumFldCopies
.GetValue() );
141 rStr
.Append( TOKEN
);
143 rStr
+= UniString::CreateFromInt64( maMtrFldMoveX
.GetValue() );
144 rStr
.Append( TOKEN
);
146 rStr
+= UniString::CreateFromInt64( maMtrFldMoveY
.GetValue() );
147 rStr
.Append( TOKEN
);
149 rStr
+= UniString::CreateFromInt64( maMtrFldAngle
.GetValue() );
150 rStr
.Append( TOKEN
);
152 rStr
+= UniString::CreateFromInt64( maMtrFldWidth
.GetValue() );
153 rStr
.Append( TOKEN
);
155 rStr
+= UniString::CreateFromInt64( maMtrFldHeight
.GetValue() );
156 rStr
.Append( TOKEN
);
158 rStr
+= UniString::CreateFromInt32( (long)maLbStartColor
.GetSelectEntryColor().GetColor() );
159 rStr
.Append( TOKEN
);
161 rStr
+= UniString::CreateFromInt32( (long)maLbEndColor
.GetSelectEntryColor().GetColor() );
164 /*************************************************************************
166 |* Liest uebergebenen Item-Set oder wertet den INI-String aus
168 \************************************************************************/
170 IMPL_LINK( CopyDlg
, Reset
, void*, EMPTYARG
)
172 const SfxPoolItem
* pPoolItem
= NULL
;
173 String
aStr( GetExtraData() );
175 if( aStr
.GetTokenCount( TOKEN
) < 8 )
177 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_NUMBER
, TRUE
, &pPoolItem
) )
178 maNumFldCopies
.SetValue( ( ( const SfxUInt16Item
* ) pPoolItem
)->GetValue() );
180 maNumFldCopies
.SetValue( 1L );
183 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_MOVE_X
, TRUE
, &pPoolItem
) )
184 nMoveX
= ( ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue() );
185 SetMetricValue( maMtrFldMoveX
, Fraction(nMoveX
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
188 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_MOVE_Y
, TRUE
, &pPoolItem
) )
189 nMoveY
= ( ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue() );
190 SetMetricValue( maMtrFldMoveY
, Fraction(nMoveY
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
192 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_ANGLE
, TRUE
, &pPoolItem
) )
193 maMtrFldAngle
.SetValue( ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue() );
195 maMtrFldAngle
.SetValue( 0L );
198 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_WIDTH
, TRUE
, &pPoolItem
) )
199 nWidth
= ( ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue() );
200 SetMetricValue( maMtrFldWidth
, Fraction(nWidth
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
203 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_HEIGHT
, TRUE
, &pPoolItem
) )
204 nHeight
= ( ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue() );
205 SetMetricValue( maMtrFldHeight
, Fraction(nHeight
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
207 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_START_COLOR
, TRUE
, &pPoolItem
) )
209 Color aColor
= ( ( const XColorItem
* ) pPoolItem
)->GetColorValue();
210 maLbStartColor
.SelectEntry( aColor
);
211 maLbEndColor
.SelectEntry( aColor
);
215 maLbStartColor
.SetNoSelection();
216 maLbEndColor
.SetNoSelection();
217 maLbEndColor
.Disable();
218 maFtEndColor
.Disable();
224 nTmp
= (long)aStr
.GetToken( 0, TOKEN
).ToInt32();
225 maNumFldCopies
.SetValue( nTmp
);
227 nTmp
= (long)aStr
.GetToken( 1, TOKEN
).ToInt32();
228 maMtrFldMoveX
.SetValue( nTmp
);
230 nTmp
= (long)aStr
.GetToken( 2, TOKEN
).ToInt32();
231 maMtrFldMoveY
.SetValue( nTmp
);
233 nTmp
= (long)aStr
.GetToken( 3, TOKEN
).ToInt32();
234 maMtrFldAngle
.SetValue( nTmp
);
236 nTmp
= (long)aStr
.GetToken( 4, TOKEN
).ToInt32();
237 maMtrFldWidth
.SetValue( nTmp
);
239 nTmp
= (long)aStr
.GetToken( 5, TOKEN
).ToInt32();
240 maMtrFldHeight
.SetValue( nTmp
);
242 nTmp
= (long)aStr
.GetToken( 6, TOKEN
).ToInt32();
243 maLbStartColor
.SelectEntry( Color( nTmp
) );
245 nTmp
= (long)aStr
.GetToken( 7, TOKEN
).ToInt32();
246 maLbEndColor
.SelectEntry( Color( nTmp
) );
252 /*************************************************************************
254 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
256 \************************************************************************/
258 void CopyDlg::GetAttr( SfxItemSet
& rOutAttrs
)
260 long nMoveX
= Fraction( GetCoreValue( maMtrFldMoveX
, SFX_MAPUNIT_100TH_MM
) ) * maUIScale
;
261 long nMoveY
= Fraction( GetCoreValue( maMtrFldMoveY
, SFX_MAPUNIT_100TH_MM
) ) * maUIScale
;
262 long nHeight
= Fraction( GetCoreValue( maMtrFldHeight
, SFX_MAPUNIT_100TH_MM
) ) * maUIScale
;
263 long nWidth
= Fraction( GetCoreValue( maMtrFldWidth
, SFX_MAPUNIT_100TH_MM
) ) * maUIScale
;
265 rOutAttrs
.Put( SfxUInt16Item( ATTR_COPY_NUMBER
, (UINT16
) maNumFldCopies
.GetValue() ) );
266 rOutAttrs
.Put( SfxInt32Item( ATTR_COPY_MOVE_X
, nMoveX
) );
267 rOutAttrs
.Put( SfxInt32Item( ATTR_COPY_MOVE_Y
, nMoveY
) );
268 rOutAttrs
.Put( SfxInt32Item( ATTR_COPY_ANGLE
, static_cast<INT32
>(maMtrFldAngle
.GetValue()) ) );
269 rOutAttrs
.Put( SfxInt32Item( ATTR_COPY_WIDTH
, nWidth
) );
270 rOutAttrs
.Put( SfxInt32Item( ATTR_COPY_HEIGHT
, nHeight
) );
272 if( maLbStartColor
.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
)
274 XColorItem
aXColorItem( ATTR_COPY_START_COLOR
, maLbStartColor
.GetSelectEntry(),
275 maLbStartColor
.GetSelectEntryColor() );
276 rOutAttrs
.Put( aXColorItem
);
278 if( maLbEndColor
.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
)
280 XColorItem
aXColorItem( ATTR_COPY_END_COLOR
, maLbEndColor
.GetSelectEntry(),
281 maLbEndColor
.GetSelectEntryColor() );
282 rOutAttrs
.Put( aXColorItem
);
286 /*************************************************************************
288 |* Enabled und selektiert Endfarben-LB
290 \************************************************************************/
292 IMPL_LINK( CopyDlg
, SelectColorHdl
, void *, EMPTYARG
)
294 USHORT nPos
= maLbStartColor
.GetSelectEntryPos();
296 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
&&
297 !maLbEndColor
.IsEnabled() )
299 maLbEndColor
.SelectEntryPos( nPos
);
300 maLbEndColor
.Enable();
301 maFtEndColor
.Enable();
306 /*************************************************************************
307 |* Setzt Werte der Selektion
308 \************************************************************************/
310 IMPL_LINK( CopyDlg
, SetViewData
, void*, EMPTYARG
)
312 Rectangle aRect
= mpView
->GetAllMarkedRect();
314 SetMetricValue( maMtrFldMoveX
, Fraction( aRect
.GetWidth() ) /
315 maUIScale
, SFX_MAPUNIT_100TH_MM
);
316 SetMetricValue( maMtrFldMoveY
, Fraction( aRect
.GetHeight() ) /
317 maUIScale
, SFX_MAPUNIT_100TH_MM
);
319 // Farb-Attribut setzen
320 const SfxPoolItem
* pPoolItem
= NULL
;
321 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_START_COLOR
, TRUE
, &pPoolItem
) )
323 Color aColor
= ( ( const XColorItem
* ) pPoolItem
)->GetColorValue();
324 maLbStartColor
.SelectEntry( aColor
);
330 /*************************************************************************
331 |* Setzt Werte auf Standard
332 \************************************************************************/
334 IMPL_LINK( CopyDlg
, SetDefault
, void*, EMPTYARG
)
336 maNumFldCopies
.SetValue( 1L );
339 SetMetricValue( maMtrFldMoveX
, Fraction(nValue
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
340 SetMetricValue( maMtrFldMoveY
, Fraction(nValue
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
343 maMtrFldAngle
.SetValue( nValue
);
344 SetMetricValue( maMtrFldWidth
, Fraction(nValue
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
345 SetMetricValue( maMtrFldHeight
, Fraction(nValue
) / maUIScale
, SFX_MAPUNIT_100TH_MM
);
347 // Farb-Attribut setzen
348 const SfxPoolItem
* pPoolItem
= NULL
;
349 if( SFX_ITEM_SET
== mrOutAttrs
.GetItemState( ATTR_COPY_START_COLOR
, TRUE
, &pPoolItem
) )
351 Color aColor
= ( ( const XColorItem
* ) pPoolItem
)->GetColorValue();
352 maLbStartColor
.SelectEntry( aColor
);
353 maLbEndColor
.SelectEntry( aColor
);
360 } // end of namespace sd