1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #include <com/sun/star/document/PrinterIndependentLayout.hpp> 21 #include <com/sun/star/frame/Desktop.hpp> 22 #include <com/sun/star/container/XEnumerationAccess.hpp> 23 #include <comphelper/processfactory.hxx> 24 #include <comphelper/string.hxx> 25 #include <com/sun/star/uno/Exception.hpp> 26 #include <sfx2/module.hxx> 27 #include <svx/svxids.hrc> 28 #include <svx/strarray.hxx> 29 #include <vcl/svapp.hxx> 30 #include <vcl/weld.hxx> 31 #include <svtools/unitconv.hxx> 32 33 #include <sdattr.hrc> 34 #include <sdresid.hxx> 35 #include <optsitem.hxx> 36 #include <tpoption.hxx> 37 #include <strings.hrc> 38 #include <app.hrc> 39 #include <svl/intitem.hxx> 40 41 using namespace ::com::sun::star; 42 using namespace ::com::sun::star::uno; 43 44 SdTpOptionsSnap::SdTpOptionsSnap(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs) 45 : SvxGridTabPage(pPage, pController, rInAttrs) 46 { 47 m_xSnapFrames->show(); 48 } 49 50 SdTpOptionsSnap::~SdTpOptionsSnap() 51 { 52 } 53 54 bool SdTpOptionsSnap::FillItemSet( SfxItemSet* rAttrs ) 55 { 56 SvxGridTabPage::FillItemSet(rAttrs); 57 SdOptionsSnapItem aOptsItem; 58 59 aOptsItem.GetOptionsSnap().SetSnapHelplines( m_xCbxSnapHelplines->get_active() ); 60 aOptsItem.GetOptionsSnap().SetSnapBorder( m_xCbxSnapBorder->get_active() ); 61 aOptsItem.GetOptionsSnap().SetSnapFrame( m_xCbxSnapFrame->get_active() ); 62 aOptsItem.GetOptionsSnap().SetSnapPoints( m_xCbxSnapPoints->get_active() ); 63 aOptsItem.GetOptionsSnap().SetOrtho( m_xCbxOrtho->get_active() ); 64 aOptsItem.GetOptionsSnap().SetBigOrtho( m_xCbxBigOrtho->get_active() ); 65 aOptsItem.GetOptionsSnap().SetRotate( m_xCbxRotate->get_active() ); 66 aOptsItem.GetOptionsSnap().SetSnapArea(static_cast<sal_Int16>(m_xMtrFldSnapArea->get_value(FieldUnit::PIXEL))); 67 aOptsItem.GetOptionsSnap().SetAngle(Degree100(m_xMtrFldAngle->get_value(FieldUnit::DEGREE))); 68 aOptsItem.GetOptionsSnap().SetEliminatePolyPointLimitAngle(Degree100(m_xMtrFldBezAngle->get_value(FieldUnit::DEGREE))); 69 70 rAttrs->Put( aOptsItem ); 71 72 // we get a possible existing GridItem, this ensures that we do not set 73 // some default values by accident 74 return true; 75 } 76 77 void SdTpOptionsSnap::Reset( const SfxItemSet* rAttrs ) 78 { 79 SvxGridTabPage::Reset(rAttrs); 80 81 SdOptionsSnapItem aOptsItem( static_cast<const SdOptionsSnapItem&>( rAttrs-> 82 Get( ATTR_OPTIONS_SNAP ) ) ); 83 84 m_xCbxSnapHelplines->set_active( aOptsItem.GetOptionsSnap().IsSnapHelplines() ); 85 m_xCbxSnapBorder->set_active( aOptsItem.GetOptionsSnap().IsSnapBorder() ); 86 m_xCbxSnapFrame->set_active( aOptsItem.GetOptionsSnap().IsSnapFrame() ); 87 m_xCbxSnapPoints->set_active( aOptsItem.GetOptionsSnap().IsSnapPoints() ); 88 m_xCbxOrtho->set_active( aOptsItem.GetOptionsSnap().IsOrtho() ); 89 m_xCbxBigOrtho->set_active( aOptsItem.GetOptionsSnap().IsBigOrtho() ); 90 m_xCbxRotate->set_active( aOptsItem.GetOptionsSnap().IsRotate() ); 91 m_xMtrFldSnapArea->set_value(aOptsItem.GetOptionsSnap().GetSnapArea(), FieldUnit::PIXEL); 92 m_xMtrFldAngle->set_value(aOptsItem.GetOptionsSnap().GetAngle().get(), FieldUnit::DEGREE); 93 m_xMtrFldBezAngle->set_value(aOptsItem.GetOptionsSnap().GetEliminatePolyPointLimitAngle().get(), FieldUnit::DEGREE); 94 95 ClickRotateHdl_Impl(*m_xCbxRotate); 96 } 97 98 std::unique_ptr<SfxTabPage> SdTpOptionsSnap::Create( weld::Container* pPage, weld::DialogController* pController, 99 const SfxItemSet* rAttrs ) 100 { 101 return std::make_unique<SdTpOptionsSnap>(pPage, pController, *rAttrs); 102 } 103 104 /************************************************************************* 105 |* 106 |* TabPage to adjust the content options 107 |* 108 \************************************************************************/ 109 SdTpOptionsContents::SdTpOptionsContents(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs) 110 : SfxTabPage(pPage, pController, "modules/simpress/ui/sdviewpage.ui", "SdViewPage", &rInAttrs) 111 , m_xCbxRuler(m_xBuilder->weld_check_button("ruler")) 112 , m_xCbxDragStripes(m_xBuilder->weld_check_button("dragstripes")) 113 , m_xCbxHandlesBezier(m_xBuilder->weld_check_button("handlesbezier")) 114 , m_xCbxMoveOutline(m_xBuilder->weld_check_button("moveoutline")) 115 { 116 } 117 118 SdTpOptionsContents::~SdTpOptionsContents() 119 { 120 } 121 122 bool SdTpOptionsContents::FillItemSet( SfxItemSet* rAttrs ) 123 { 124 bool bModified = false; 125 126 if( m_xCbxRuler->get_state_changed_from_saved() || 127 m_xCbxMoveOutline->get_state_changed_from_saved() || 128 m_xCbxDragStripes->get_state_changed_from_saved() || 129 m_xCbxHandlesBezier->get_state_changed_from_saved() ) 130 { 131 SdOptionsLayoutItem aOptsItem; 132 133 aOptsItem.GetOptionsLayout().SetRulerVisible( m_xCbxRuler->get_active() ); 134 aOptsItem.GetOptionsLayout().SetMoveOutline( m_xCbxMoveOutline->get_active() ); 135 aOptsItem.GetOptionsLayout().SetDragStripes( m_xCbxDragStripes->get_active() ); 136 aOptsItem.GetOptionsLayout().SetHandlesBezier( m_xCbxHandlesBezier->get_active() ); 137 138 rAttrs->Put( aOptsItem ); 139 bModified = true; 140 } 141 return bModified; 142 } 143 144 void SdTpOptionsContents::Reset( const SfxItemSet* rAttrs ) 145 { 146 SdOptionsLayoutItem aLayoutItem( static_cast<const SdOptionsLayoutItem&>( rAttrs-> 147 Get( ATTR_OPTIONS_LAYOUT ) ) ); 148 149 m_xCbxRuler->set_active( aLayoutItem.GetOptionsLayout().IsRulerVisible() ); 150 m_xCbxMoveOutline->set_active( aLayoutItem.GetOptionsLayout().IsMoveOutline() ); 151 m_xCbxDragStripes->set_active( aLayoutItem.GetOptionsLayout().IsDragStripes() ); 152 m_xCbxHandlesBezier->set_active( aLayoutItem.GetOptionsLayout().IsHandlesBezier() ); 153 154 m_xCbxRuler->save_state(); 155 m_xCbxMoveOutline->save_state(); 156 m_xCbxDragStripes->save_state(); 157 m_xCbxHandlesBezier->save_state(); 158 } 159 160 std::unique_ptr<SfxTabPage> SdTpOptionsContents::Create( weld::Container* pPage, weld::DialogController* pController, 161 const SfxItemSet* rAttrs ) 162 { 163 return std::make_unique<SdTpOptionsContents>(pPage, pController, *rAttrs); 164 } 165 166 /************************************************************************* 167 |* 168 |* TabPage to adjust the misc options 169 |* 170 \************************************************************************/ 171 #define TABLE_COUNT 12 172 #define TOKEN ':' 173 174 SdTpOptionsMisc::SdTpOptionsMisc(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs) 175 : SfxTabPage(pPage, pController, "modules/simpress/ui/optimpressgeneralpage.ui", "OptSavePage", &rInAttrs) 176 , nWidth(0) 177 , nHeight(0) 178 , m_xCbxQuickEdit(m_xBuilder->weld_check_button("qickedit")) 179 , m_xCbxPickThrough(m_xBuilder->weld_check_button("textselected")) 180 , m_xNewDocumentFrame(m_xBuilder->weld_frame("newdocumentframe")) 181 , m_xCbxStartWithTemplate(m_xBuilder->weld_check_button("startwithwizard")) 182 , m_xCbxMasterPageCache(m_xBuilder->weld_check_button("backgroundback")) 183 , m_xCbxCopy(m_xBuilder->weld_check_button("copywhenmove")) 184 , m_xCbxMarkedHitMovesAlways(m_xBuilder->weld_check_button("objalwymov")) 185 , m_xPresentationFrame(m_xBuilder->weld_frame("presentationframe")) 186 , m_xLbMetric(m_xBuilder->weld_combo_box("units")) 187 , m_xMtrFldTabstop(m_xBuilder->weld_metric_spin_button("metricFields", FieldUnit::MM)) 188 , m_xCbxEnableSdremote(m_xBuilder->weld_check_button("enremotcont")) 189 , m_xCbxEnablePresenterScreen(m_xBuilder->weld_check_button("enprsntcons")) 190 , m_xCbxUsePrinterMetrics(m_xBuilder->weld_check_button("printermetrics")) 191 , m_xCbxCompatibility(m_xBuilder->weld_check_button("cbCompatibility")) 192 , m_xScaleFrame(m_xBuilder->weld_frame("scaleframe")) 193 , m_xCbScale(m_xBuilder->weld_combo_box("scaleBox")) 194 , m_xNewDocLb(m_xBuilder->weld_label("newdoclbl")) 195 , m_xFiInfo1(m_xBuilder->weld_label("info1")) 196 , m_xMtrFldOriginalWidth(m_xBuilder->weld_metric_spin_button("metricWidthFields", FieldUnit::MM)) 197 , m_xWidthLb(m_xBuilder->weld_label("widthlbl")) 198 , m_xHeightLb(m_xBuilder->weld_label("heightlbl")) 199 , m_xFiInfo2(m_xBuilder->weld_label("info2")) 200 , m_xMtrFldOriginalHeight(m_xBuilder->weld_metric_spin_button("metricHeightFields", FieldUnit::MM)) 201 , m_xCbxDistort(m_xBuilder->weld_check_button("distortcb")) 202 , m_xMtrFldInfo1(m_xBuilder->weld_metric_spin_button("metricInfo1Fields", FieldUnit::MM)) 203 , m_xMtrFldInfo2(m_xBuilder->weld_metric_spin_button("metricInfo2Fields", FieldUnit::MM)) 204 { 205 SetExchangeSupport(); 206 207 // set metric 208 FieldUnit eFUnit; 209 210 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC ); 211 if ( rInAttrs.GetItemState( nWhich ) >= SfxItemState::DEFAULT ) 212 { 213 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rInAttrs.Get( nWhich )); 214 eFUnit = static_cast<FieldUnit>(rItem.GetValue()); 215 } 216 else 217 eFUnit = SfxModule::GetCurrentFieldUnit(); 218 219 SetFieldUnit( *m_xMtrFldTabstop , eFUnit ); 220 221 // Impress is default mode, let' hide the entire scale frame etc. 222 m_xCbxDistort->hide(); 223 m_xScaleFrame->hide(); 224 225 // fill ListBox with metrics 226 for (sal_uInt32 i = 0; i < SvxFieldUnitTable::Count(); ++i) 227 { 228 OUString sMetric = SvxFieldUnitTable::GetString(i); 229 sal_uInt32 nFieldUnit = sal_uInt32(SvxFieldUnitTable::GetValue(i)); 230 m_xLbMetric->append(OUString::number(nFieldUnit), sMetric); 231 } 232 m_xLbMetric->connect_changed( LINK( this, SdTpOptionsMisc, SelectMetricHdl_Impl ) ); 233 234 SetFieldUnit( *m_xMtrFldOriginalWidth, eFUnit ); 235 SetFieldUnit( *m_xMtrFldOriginalHeight, eFUnit ); 236 m_xMtrFldOriginalWidth->set_max(999999999, FieldUnit::NONE); 237 m_xMtrFldOriginalHeight->set_max(999999999, FieldUnit::NONE); 238 239 // temporary fields for info texts (for formatting/calculation) 240 m_xMtrFldInfo1->set_unit( eFUnit ); 241 m_xMtrFldInfo1->set_max(999999999, FieldUnit::NONE); 242 m_xMtrFldInfo1->set_digits( 2 ); 243 m_xMtrFldInfo2->set_unit( eFUnit ); 244 m_xMtrFldInfo2->set_max(999999999, FieldUnit::NONE); 245 m_xMtrFldInfo2->set_digits( 2 ); 246 247 // determine PoolUnit 248 SfxItemPool* pPool = rInAttrs.GetPool(); 249 DBG_ASSERT( pPool, "Where is the Pool?" ); 250 ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH ); 251 252 // Fill the CB 253 sal_uInt16 aTable[ TABLE_COUNT ] = 254 { 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 }; 255 256 for( sal_uInt16 i = TABLE_COUNT-1; i > 0 ; i-- ) 257 m_xCbScale->append_text( GetScale( 1, aTable[i] ) ); 258 for( sal_uInt16 i = 0; i < TABLE_COUNT; i++ ) 259 m_xCbScale->append_text( GetScale( aTable[i], 1 ) ); 260 } 261 262 SdTpOptionsMisc::~SdTpOptionsMisc() 263 { 264 } 265 266 void SdTpOptionsMisc::ActivatePage( const SfxItemSet& rSet ) 267 { 268 // We have to call save_state again since it can happen that the value 269 // has no effect on other TabPages 270 m_xLbMetric->save_value(); 271 // change metric if necessary (since TabPage is in the Dialog where 272 // the metric is set) 273 const SfxPoolItem* pAttr = nullptr; 274 if( SfxItemState::SET != rSet.GetItemState( SID_ATTR_METRIC , false, 275 &pAttr )) 276 return; 277 278 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pAttr); 279 280 FieldUnit eFUnit = static_cast<FieldUnit>(static_cast<tools::Long>(pItem->GetValue())); 281 282 if( eFUnit == m_xMtrFldOriginalWidth->get_unit() ) 283 return; 284 285 // set metrics 286 sal_Int64 nVal = m_xMtrFldOriginalWidth->denormalize( m_xMtrFldOriginalWidth->get_value( FieldUnit::TWIP ) ); 287 SetFieldUnit( *m_xMtrFldOriginalWidth, eFUnit, true ); 288 m_xMtrFldOriginalWidth->set_value( m_xMtrFldOriginalWidth->normalize( nVal ), FieldUnit::TWIP ); 289 290 nVal = m_xMtrFldOriginalHeight->denormalize( m_xMtrFldOriginalHeight->get_value( FieldUnit::TWIP ) ); 291 SetFieldUnit( *m_xMtrFldOriginalHeight, eFUnit, true ); 292 m_xMtrFldOriginalHeight->set_value( m_xMtrFldOriginalHeight->normalize( nVal ), FieldUnit::TWIP ); 293 294 if( nWidth == 0 || nHeight == 0 ) 295 return; 296 297 m_xMtrFldInfo1->set_unit( eFUnit ); 298 m_xMtrFldInfo2->set_unit( eFUnit ); 299 300 SetMetricValue( *m_xMtrFldInfo1, nWidth, ePoolUnit ); 301 aInfo1 = m_xMtrFldInfo1->get_text(); 302 m_xFiInfo1->set_label( aInfo1 ); 303 304 SetMetricValue( *m_xMtrFldInfo2, nHeight, ePoolUnit ); 305 aInfo2 = m_xMtrFldInfo2->get_text(); 306 m_xFiInfo2->set_label( aInfo2 ); 307 } 308 309 DeactivateRC SdTpOptionsMisc::DeactivatePage( SfxItemSet* pActiveSet ) 310 { 311 // check parser 312 sal_Int32 nX, nY; 313 if( SetScale( m_xCbScale->get_active_text(), nX, nY ) ) 314 { 315 if( pActiveSet ) 316 FillItemSet( pActiveSet ); 317 return DeactivateRC::LeavePage; 318 } 319 320 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(), 321 VclMessageType::Warning, VclButtonsType::YesNo, 322 SdResId(STR_WARN_SCALE_FAIL))); 323 if (xWarn->run() == RET_YES) 324 return DeactivateRC::KeepPage; 325 326 if( pActiveSet ) 327 FillItemSet( pActiveSet ); 328 329 return DeactivateRC::LeavePage; 330 } 331 332 bool SdTpOptionsMisc::FillItemSet( SfxItemSet* rAttrs ) 333 { 334 bool bModified = false; 335 336 if( m_xCbxStartWithTemplate->get_state_changed_from_saved() || 337 m_xCbxMarkedHitMovesAlways->get_state_changed_from_saved() || 338 m_xCbxQuickEdit->get_state_changed_from_saved() || 339 m_xCbxPickThrough->get_state_changed_from_saved() || 340 m_xCbxMasterPageCache->get_state_changed_from_saved() || 341 m_xCbxCopy->get_state_changed_from_saved() || 342 m_xCbxEnableSdremote->get_state_changed_from_saved() || 343 m_xCbxEnablePresenterScreen->get_state_changed_from_saved() || 344 m_xCbxCompatibility->get_state_changed_from_saved() || 345 m_xCbxUsePrinterMetrics->get_state_changed_from_saved() || 346 m_xCbxDistort->get_state_changed_from_saved()) 347 { 348 SdOptionsMiscItem aOptsItem; 349 350 aOptsItem.GetOptionsMisc().SetStartWithTemplate( m_xCbxStartWithTemplate->get_active() ); 351 aOptsItem.GetOptionsMisc().SetMarkedHitMovesAlways( m_xCbxMarkedHitMovesAlways->get_active() ); 352 aOptsItem.GetOptionsMisc().SetQuickEdit( m_xCbxQuickEdit->get_active() ); 353 aOptsItem.GetOptionsMisc().SetPickThrough( m_xCbxPickThrough->get_active() ); 354 aOptsItem.GetOptionsMisc().SetMasterPagePaintCaching( m_xCbxMasterPageCache->get_active() ); 355 aOptsItem.GetOptionsMisc().SetDragWithCopy( m_xCbxCopy->get_active() ); 356 aOptsItem.GetOptionsMisc().SetEnableSdremote( m_xCbxEnableSdremote->get_active() ); 357 aOptsItem.GetOptionsMisc().SetEnablePresenterScreen( m_xCbxEnablePresenterScreen->get_active() ); 358 aOptsItem.GetOptionsMisc().SetSummationOfParagraphs( m_xCbxCompatibility->get_active() ); 359 aOptsItem.GetOptionsMisc().SetPrinterIndependentLayout ( 360 m_xCbxUsePrinterMetrics->get_active() 361 ? css::document::PrinterIndependentLayout::DISABLED 362 : css::document::PrinterIndependentLayout::ENABLED); 363 aOptsItem.GetOptionsMisc().SetCrookNoContortion( m_xCbxDistort->get_active() ); 364 rAttrs->Put( aOptsItem ); 365 366 bModified = true; 367 } 368 369 // metric 370 if (m_xLbMetric->get_value_changed_from_saved()) 371 { 372 const sal_Int32 nMPos = m_xLbMetric->get_active(); 373 sal_uInt16 nFieldUnit = m_xLbMetric->get_id(nMPos).toUInt32(); 374 rAttrs->Put( SfxUInt16Item( GetWhich( SID_ATTR_METRIC ), nFieldUnit ) ); 375 bModified = true; 376 } 377 378 // tabulator space 379 if( m_xMtrFldTabstop->get_value_changed_from_saved() ) 380 { 381 sal_uInt16 nWh = GetWhich( SID_ATTR_DEFTABSTOP ); 382 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWh ); 383 SfxUInt16Item aDef( nWh,static_cast<sal_uInt16>(GetCoreValue( *m_xMtrFldTabstop, eUnit )) ); 384 rAttrs->Put( aDef ); 385 bModified = true; 386 } 387 388 sal_Int32 nX, nY; 389 if( SetScale( m_xCbScale->get_active_text(), nX, nY ) ) 390 { 391 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) ); 392 rAttrs->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) ); 393 394 bModified = true; 395 } 396 397 return bModified; 398 } 399 400 void SdTpOptionsMisc::Reset( const SfxItemSet* rAttrs ) 401 { 402 SdOptionsMiscItem aOptsItem( static_cast<const SdOptionsMiscItem&>( rAttrs-> 403 Get( ATTR_OPTIONS_MISC ) ) ); 404 405 m_xCbxStartWithTemplate->set_active( aOptsItem.GetOptionsMisc().IsStartWithTemplate() ); 406 m_xCbxMarkedHitMovesAlways->set_active( aOptsItem.GetOptionsMisc().IsMarkedHitMovesAlways() ); 407 m_xCbxQuickEdit->set_active( aOptsItem.GetOptionsMisc().IsQuickEdit() ); 408 m_xCbxPickThrough->set_active( aOptsItem.GetOptionsMisc().IsPickThrough() ); 409 m_xCbxMasterPageCache->set_active( aOptsItem.GetOptionsMisc().IsMasterPagePaintCaching() ); 410 m_xCbxCopy->set_active( aOptsItem.GetOptionsMisc().IsDragWithCopy() ); 411 m_xCbxEnableSdremote->set_active( aOptsItem.GetOptionsMisc().IsEnableSdremote() ); 412 m_xCbxEnablePresenterScreen->set_active( aOptsItem.GetOptionsMisc().IsEnablePresenterScreen() ); 413 m_xCbxCompatibility->set_active( aOptsItem.GetOptionsMisc().IsSummationOfParagraphs() ); 414 m_xCbxUsePrinterMetrics->set_active( aOptsItem.GetOptionsMisc().GetPrinterIndependentLayout()==1 ); 415 m_xCbxDistort->set_active( aOptsItem.GetOptionsMisc().IsCrookNoContortion() ); 416 m_xCbxStartWithTemplate->save_state(); 417 m_xCbxMarkedHitMovesAlways->save_state(); 418 m_xCbxQuickEdit->save_state(); 419 m_xCbxPickThrough->save_state(); 420 421 m_xCbxMasterPageCache->save_state(); 422 m_xCbxCopy->save_state(); 423 m_xCbxEnableSdremote->save_state(); 424 m_xCbxEnablePresenterScreen->save_state(); 425 m_xCbxCompatibility->save_state(); 426 m_xCbxUsePrinterMetrics->save_state(); 427 m_xCbxDistort->save_state(); 428 429 // metric 430 sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC ); 431 m_xLbMetric->set_active(-1); 432 433 if ( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT ) 434 { 435 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich )); 436 sal_uInt32 nFieldUnit = static_cast<sal_uInt32>(rItem.GetValue()); 437 438 for (sal_Int32 i = 0, nEntryCount = m_xLbMetric->get_count(); i < nEntryCount; ++i) 439 { 440 if (m_xLbMetric->get_id(i).toUInt32() == nFieldUnit) 441 { 442 m_xLbMetric->set_active( i ); 443 break; 444 } 445 } 446 } 447 448 // tabulator space 449 nWhich = GetWhich( SID_ATTR_DEFTABSTOP ); 450 if( rAttrs->GetItemState( nWhich ) >= SfxItemState::DEFAULT ) 451 { 452 MapUnit eUnit = rAttrs->GetPool()->GetMetric( nWhich ); 453 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(rAttrs->Get( nWhich )); 454 SetMetricValue( *m_xMtrFldTabstop, rItem.GetValue(), eUnit ); 455 } 456 m_xLbMetric->save_value(); 457 m_xMtrFldTabstop->save_value(); 458 //Scale 459 sal_Int32 nX = static_cast<const SfxInt32Item&>( rAttrs-> 460 Get( ATTR_OPTIONS_SCALE_X ) ).GetValue(); 461 sal_Int32 nY = static_cast<const SfxInt32Item&>( rAttrs-> 462 Get( ATTR_OPTIONS_SCALE_Y ) ).GetValue(); 463 nWidth = static_cast<const SfxUInt32Item&>( rAttrs-> 464 Get( ATTR_OPTIONS_SCALE_WIDTH ) ).GetValue(); 465 nHeight = static_cast<const SfxUInt32Item&>( rAttrs-> 466 Get( ATTR_OPTIONS_SCALE_HEIGHT ) ).GetValue(); 467 468 m_xCbScale->set_entry_text( GetScale( nX, nY ) ); 469 470 m_xMtrFldOriginalWidth->hide(); 471 m_xMtrFldOriginalWidth->set_text( aInfo1 ); // empty 472 m_xMtrFldOriginalHeight->hide(); 473 m_xMtrFldOriginalHeight->set_text( aInfo2 ); //empty 474 m_xFiInfo1->hide(); 475 m_xFiInfo2->hide(); 476 477 UpdateCompatibilityControls (); 478 } 479 480 std::unique_ptr<SfxTabPage> SdTpOptionsMisc::Create( weld::Container* pPage, weld::DialogController* pController, 481 const SfxItemSet* rAttrs ) 482 { 483 return std::make_unique<SdTpOptionsMisc>( pPage, pController, *rAttrs ); 484 } 485 486 IMPL_LINK_NOARG(SdTpOptionsMisc, SelectMetricHdl_Impl, weld::ComboBox&, void) 487 { 488 int nPos = m_xLbMetric->get_active(); 489 if (nPos != -1) 490 { 491 FieldUnit eUnit = static_cast<FieldUnit>(m_xLbMetric->get_id(nPos).toUInt32()); 492 sal_Int64 nVal = 493 m_xMtrFldTabstop->denormalize(m_xMtrFldTabstop->get_value(FieldUnit::TWIP)); 494 SetFieldUnit( *m_xMtrFldTabstop, eUnit ); 495 m_xMtrFldTabstop->set_value( m_xMtrFldTabstop->normalize( nVal ), FieldUnit::TWIP ); 496 } 497 } 498 499 void SdTpOptionsMisc::SetImpressMode() 500 { 501 #ifndef ENABLE_SDREMOTE_BLUETOOTH 502 m_xCbxEnableSdremote->hide(); 503 #else 504 (void) this; // loplugin:staticmethods 505 #endif 506 } 507 508 void SdTpOptionsMisc::SetDrawMode() 509 { 510 m_xScaleFrame->show(); 511 m_xNewDocumentFrame->hide(); 512 m_xCbxEnableSdremote->hide(); 513 m_xCbxEnablePresenterScreen->hide(); 514 m_xCbxCompatibility->hide(); 515 m_xNewDocLb->hide(); 516 m_xCbScale->show(); 517 m_xPresentationFrame->hide(); 518 m_xMtrFldInfo1->hide(); 519 m_xMtrFldInfo2->hide(); 520 m_xWidthLb->hide(); 521 m_xHeightLb->hide(); 522 m_xFiInfo1->show(); 523 m_xMtrFldOriginalWidth->show(); 524 m_xFiInfo2->show(); 525 m_xMtrFldOriginalHeight->show(); 526 m_xCbxDistort->show(); 527 m_xCbxCompatibility->hide(); 528 } 529 530 OUString SdTpOptionsMisc::GetScale( sal_Int32 nX, sal_Int32 nY ) 531 { 532 return OUString::number(nX) + OUStringChar(TOKEN) + OUString::number(nY); 533 } 534 535 bool SdTpOptionsMisc::SetScale( const OUString& aScale, sal_Int32& rX, sal_Int32& rY ) 536 { 537 if (aScale.isEmpty()) 538 return false; 539 540 sal_Int32 nIdx {0}; 541 542 OUString aTmp(aScale.getToken(0, TOKEN, nIdx)); 543 if (nIdx<0) 544 return false; // we expect another token! 545 546 if (!comphelper::string::isdigitAsciiString(aTmp)) 547 return false; 548 549 rX = static_cast<tools::Long>(aTmp.toInt32()); 550 if( rX == 0 ) 551 return false; 552 553 aTmp = aScale.getToken(0, TOKEN, nIdx); 554 if (nIdx>=0) 555 return false; // we require just 2 tokens! 556 557 if (!comphelper::string::isdigitAsciiString(aTmp)) 558 return false; 559 560 rY = static_cast<tools::Long>(aTmp.toInt32()); 561 return rY != 0; 562 } 563 564 void SdTpOptionsMisc::UpdateCompatibilityControls() 565 { 566 // Disable the compatibility controls by default. Enable them only when 567 // there is at least one open document. 568 bool bIsEnabled = false; 569 570 try 571 { 572 // Get a component enumeration from the desktop and search it for documents. 573 Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext()); 574 do 575 { 576 Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext); 577 578 Reference<container::XEnumerationAccess> xComponents = 579 xDesktop->getComponents(); 580 if ( ! xComponents.is()) 581 break; 582 583 Reference<container::XEnumeration> xEnumeration ( 584 xComponents->createEnumeration()); 585 if ( ! xEnumeration.is()) 586 break; 587 588 while (xEnumeration->hasMoreElements()) 589 { 590 Reference<frame::XModel> xModel (xEnumeration->nextElement(), UNO_QUERY); 591 if (xModel.is()) 592 { 593 // There is at least one model/document: Enable the compatibility controls. 594 bIsEnabled = true; 595 break; 596 } 597 } 598 599 } 600 while (false); // One 'loop'. 601 } 602 catch (const uno::Exception&) 603 { 604 // When there is an exception then simply use the default value of 605 // bIsEnabled and disable the controls. 606 } 607 608 m_xCbxCompatibility->set_sensitive(bIsEnabled); 609 m_xCbxUsePrinterMetrics->set_sensitive(bIsEnabled); 610 } 611 612 void SdTpOptionsMisc::PageCreated(const SfxAllItemSet& aSet) 613 { 614 const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_SDMODE_FLAG, false); 615 if (pFlagItem) 616 { 617 sal_uInt32 nFlags=pFlagItem->GetValue(); 618 if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE ) 619 SetDrawMode(); 620 if ( ( nFlags & SD_IMPRESS_MODE ) == SD_IMPRESS_MODE ) 621 SetImpressMode(); 622 } 623 } 624 625 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 626
