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 |* 58 |* Dialog zum Kopieren von Objekten 59 |* 60 \************************************************************************/ 61 62 CopyDlg::CopyDlg( 63 ::Window* pWindow, 64 const SfxItemSet& rInAttrs, 65 XColorTable* pColTab, 66 ::sd::View* pInView ) 67 : SfxModalDialog ( pWindow, SdResId( DLG_COPY ) ), 68 maFtCopies ( this, SdResId( FT_COPIES ) ), 69 maNumFldCopies ( this, SdResId( NUM_FLD_COPIES ) ), 70 maBtnSetViewData ( this, SdResId( BTN_SET_VIEWDATA ) ), 71 maGrpMovement ( this, SdResId( GRP_MOVEMENT ) ), 72 maFtMoveX ( this, SdResId( FT_MOVE_X ) ), 73 maMtrFldMoveX ( this, SdResId( MTR_FLD_MOVE_X ) ), 74 maFtMoveY ( this, SdResId( FT_MOVE_Y ) ), 75 maMtrFldMoveY ( this, SdResId( MTR_FLD_MOVE_Y ) ), 76 maFtAngle ( this, SdResId( FT_ANGLE ) ), 77 maMtrFldAngle ( this, SdResId( MTR_FLD_ANGLE ) ), 78 maGrpEnlargement ( this, SdResId( GRP_ENLARGEMENT ) ), 79 maFtWidth ( this, SdResId( FT_WIDTH ) ), 80 maMtrFldWidth ( this, SdResId( MTR_FLD_WIDTH ) ), 81 maFtHeight ( this, SdResId( FT_HEIGHT ) ), 82 maMtrFldHeight ( this, SdResId( MTR_FLD_HEIGHT ) ), 83 maGrpColor ( this, SdResId( GRP_COLOR ) ), 84 maFtStartColor ( this, SdResId( FT_START_COLOR ) ), 85 maLbStartColor ( this, SdResId( LB_START_COLOR ) ), 86 maFtEndColor ( this, SdResId( FT_END_COLOR ) ), 87 maLbEndColor ( this, SdResId( LB_END_COLOR ) ), 88 maBtnOK ( this, SdResId( BTN_OK ) ), 89 maBtnCancel ( this, SdResId( BTN_CANCEL ) ), 90 maBtnHelp ( this, SdResId( BTN_HELP ) ), 91 maBtnSetDefault ( this, SdResId( BTN_SET_DEFAULT ) ), 92 mrOutAttrs ( rInAttrs ), 93 mpColorTab ( pColTab ), 94 maUIScale(pInView->GetDoc()->GetUIScale()), 95 mpView ( pInView ) 96 { 97 FreeResource(); 98 99 // Set up the view data button (image and accessible name). 100 maBtnSetViewData.SetModeImage( Image( SdResId( IMG_PIPETTE_H ) ), BMP_COLOR_HIGHCONTRAST ); 101 maBtnSetViewData.SetAccessibleName (maBtnSetViewData.GetQuickHelpText()); 102 103 // Farbtabellen 104 DBG_ASSERT( mpColorTab, "Keine gueltige ColorTable uebergeben!" ); 105 maLbStartColor.Fill( mpColorTab ); 106 maLbEndColor.CopyEntries( maLbStartColor ); 107 108 maLbStartColor.SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) ); 109 maBtnSetViewData.SetClickHdl( LINK( this, CopyDlg, SetViewData ) ); 110 maBtnSetDefault.SetClickHdl( LINK( this, CopyDlg, SetDefault ) ); 111 112 113 FieldUnit eFUnit( SfxModule::GetCurrentFieldUnit() ); 114 115 SetFieldUnit( maMtrFldMoveX, eFUnit, sal_True ); 116 SetFieldUnit( maMtrFldMoveY, eFUnit, sal_True ); 117 SetFieldUnit( maMtrFldWidth, eFUnit, sal_True ); 118 SetFieldUnit( maMtrFldHeight, eFUnit, sal_True ); 119 120 Reset(0L); 121 } 122 123 /************************************************************************* 124 |* 125 |* Dtor 126 |* 127 \************************************************************************/ 128 129 CopyDlg::~CopyDlg() 130 { 131 String& rStr = GetExtraData(); 132 133 rStr = UniString::CreateFromInt64( maNumFldCopies.GetValue() ); 134 rStr.Append( TOKEN ); 135 136 rStr += UniString::CreateFromInt64( maMtrFldMoveX.GetValue() ); 137 rStr.Append( TOKEN ); 138 139 rStr += UniString::CreateFromInt64( maMtrFldMoveY.GetValue() ); 140 rStr.Append( TOKEN ); 141 142 rStr += UniString::CreateFromInt64( maMtrFldAngle.GetValue() ); 143 rStr.Append( TOKEN ); 144 145 rStr += UniString::CreateFromInt64( maMtrFldWidth.GetValue() ); 146 rStr.Append( TOKEN ); 147 148 rStr += UniString::CreateFromInt64( maMtrFldHeight.GetValue() ); 149 rStr.Append( TOKEN ); 150 151 rStr += UniString::CreateFromInt32( (long)maLbStartColor.GetSelectEntryColor().GetColor() ); 152 rStr.Append( TOKEN ); 153 154 rStr += UniString::CreateFromInt32( (long)maLbEndColor.GetSelectEntryColor().GetColor() ); 155 } 156 157 /************************************************************************* 158 |* 159 |* Liest uebergebenen Item-Set oder wertet den INI-String aus 160 |* 161 \************************************************************************/ 162 163 IMPL_LINK( CopyDlg, Reset, void*, EMPTYARG ) 164 { 165 const SfxPoolItem* pPoolItem = NULL; 166 String aStr( GetExtraData() ); 167 168 if( aStr.GetTokenCount( TOKEN ) < 8 ) 169 { 170 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_NUMBER, sal_True, &pPoolItem ) ) 171 maNumFldCopies.SetValue( ( ( const SfxUInt16Item* ) pPoolItem )->GetValue() ); 172 else 173 maNumFldCopies.SetValue( 1L ); 174 175 long nMoveX = 500L; 176 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_X, sal_True, &pPoolItem ) ) 177 nMoveX = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() ); 178 SetMetricValue( maMtrFldMoveX, Fraction(nMoveX) / maUIScale, SFX_MAPUNIT_100TH_MM); 179 180 long nMoveY = 500L; 181 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_Y, sal_True, &pPoolItem ) ) 182 nMoveY = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() ); 183 SetMetricValue( maMtrFldMoveY, Fraction(nMoveY) / maUIScale, SFX_MAPUNIT_100TH_MM); 184 185 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_ANGLE, sal_True, &pPoolItem ) ) 186 maMtrFldAngle.SetValue( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() ); 187 else 188 maMtrFldAngle.SetValue( 0L ); 189 190 long nWidth = 0L; 191 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_WIDTH, sal_True, &pPoolItem ) ) 192 nWidth = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() ); 193 SetMetricValue( maMtrFldWidth, Fraction(nWidth) / maUIScale, SFX_MAPUNIT_100TH_MM); 194 195 long nHeight = 0L; 196 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_HEIGHT, sal_True, &pPoolItem ) ) 197 nHeight = ( ( ( const SfxInt32Item* ) pPoolItem )->GetValue() ); 198 SetMetricValue( maMtrFldHeight, Fraction(nHeight) / maUIScale, SFX_MAPUNIT_100TH_MM); 199 200 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) ) 201 { 202 Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue(); 203 maLbStartColor.SelectEntry( aColor ); 204 maLbEndColor.SelectEntry( aColor ); 205 } 206 else 207 { 208 maLbStartColor.SetNoSelection(); 209 maLbEndColor.SetNoSelection(); 210 maLbEndColor.Disable(); 211 maFtEndColor.Disable(); 212 } 213 } 214 else 215 { 216 long nTmp; 217 nTmp = (long)aStr.GetToken( 0, TOKEN ).ToInt32(); 218 maNumFldCopies.SetValue( nTmp ); 219 220 nTmp = (long)aStr.GetToken( 1, TOKEN ).ToInt32(); 221 maMtrFldMoveX.SetValue( nTmp ); 222 223 nTmp = (long)aStr.GetToken( 2, TOKEN ).ToInt32(); 224 maMtrFldMoveY.SetValue( nTmp ); 225 226 nTmp = (long)aStr.GetToken( 3, TOKEN ).ToInt32(); 227 maMtrFldAngle.SetValue( nTmp ); 228 229 nTmp = (long)aStr.GetToken( 4, TOKEN ).ToInt32(); 230 maMtrFldWidth.SetValue( nTmp ); 231 232 nTmp = (long)aStr.GetToken( 5, TOKEN ).ToInt32(); 233 maMtrFldHeight.SetValue( nTmp ); 234 235 nTmp = (long)aStr.GetToken( 6, TOKEN ).ToInt32(); 236 maLbStartColor.SelectEntry( Color( nTmp ) ); 237 238 nTmp = (long)aStr.GetToken( 7, TOKEN ).ToInt32(); 239 maLbEndColor.SelectEntry( Color( nTmp ) ); 240 } 241 242 return 0; 243 } 244 245 /************************************************************************* 246 |* 247 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen 248 |* 249 \************************************************************************/ 250 251 void CopyDlg::GetAttr( SfxItemSet& rOutAttrs ) 252 { 253 long nMoveX = Fraction( GetCoreValue( maMtrFldMoveX, SFX_MAPUNIT_100TH_MM) ) * maUIScale; 254 long nMoveY = Fraction( GetCoreValue( maMtrFldMoveY, SFX_MAPUNIT_100TH_MM) ) * maUIScale; 255 long nHeight = Fraction( GetCoreValue( maMtrFldHeight, SFX_MAPUNIT_100TH_MM) ) * maUIScale; 256 long nWidth = Fraction( GetCoreValue( maMtrFldWidth, SFX_MAPUNIT_100TH_MM) ) * maUIScale; 257 258 rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, (sal_uInt16) maNumFldCopies.GetValue() ) ); 259 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) ); 260 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) ); 261 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_ANGLE, static_cast<sal_Int32>(maMtrFldAngle.GetValue()) ) ); 262 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) ); 263 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) ); 264 265 if( maLbStartColor.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND ) 266 { 267 XColorItem aXColorItem( ATTR_COPY_START_COLOR, maLbStartColor.GetSelectEntry(), 268 maLbStartColor.GetSelectEntryColor() ); 269 rOutAttrs.Put( aXColorItem ); 270 } 271 if( maLbEndColor.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND ) 272 { 273 XColorItem aXColorItem( ATTR_COPY_END_COLOR, maLbEndColor.GetSelectEntry(), 274 maLbEndColor.GetSelectEntryColor() ); 275 rOutAttrs.Put( aXColorItem ); 276 } 277 } 278 279 /************************************************************************* 280 |* 281 |* Enabled und selektiert Endfarben-LB 282 |* 283 \************************************************************************/ 284 285 IMPL_LINK( CopyDlg, SelectColorHdl, void *, EMPTYARG ) 286 { 287 sal_uInt16 nPos = maLbStartColor.GetSelectEntryPos(); 288 289 if( nPos != LISTBOX_ENTRY_NOTFOUND && 290 !maLbEndColor.IsEnabled() ) 291 { 292 maLbEndColor.SelectEntryPos( nPos ); 293 maLbEndColor.Enable(); 294 maFtEndColor.Enable(); 295 } 296 return 0; 297 } 298 299 /************************************************************************* 300 |* Setzt Werte der Selektion 301 \************************************************************************/ 302 303 IMPL_LINK( CopyDlg, SetViewData, void*, EMPTYARG ) 304 { 305 Rectangle aRect = mpView->GetAllMarkedRect(); 306 307 SetMetricValue( maMtrFldMoveX, Fraction( aRect.GetWidth() ) / 308 maUIScale, SFX_MAPUNIT_100TH_MM); 309 SetMetricValue( maMtrFldMoveY, Fraction( aRect.GetHeight() ) / 310 maUIScale, SFX_MAPUNIT_100TH_MM); 311 312 // Farb-Attribut setzen 313 const SfxPoolItem* pPoolItem = NULL; 314 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) ) 315 { 316 Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue(); 317 maLbStartColor.SelectEntry( aColor ); 318 } 319 320 return 0; 321 } 322 323 /************************************************************************* 324 |* Setzt Werte auf Standard 325 \************************************************************************/ 326 327 IMPL_LINK( CopyDlg, SetDefault, void*, EMPTYARG ) 328 { 329 maNumFldCopies.SetValue( 1L ); 330 331 long nValue = 500L; 332 SetMetricValue( maMtrFldMoveX, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM); 333 SetMetricValue( maMtrFldMoveY, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM); 334 335 nValue = 0L; 336 maMtrFldAngle.SetValue( nValue ); 337 SetMetricValue( maMtrFldWidth, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM); 338 SetMetricValue( maMtrFldHeight, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM); 339 340 // Farb-Attribut setzen 341 const SfxPoolItem* pPoolItem = NULL; 342 if( SFX_ITEM_SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) ) 343 { 344 Color aColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue(); 345 maLbStartColor.SelectEntry( aColor ); 346 maLbEndColor.SelectEntry( aColor ); 347 } 348 349 return 0; 350 } 351 352 353 } // end of namespace sd 354