tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / optdlg / tpprint.cxx
bloba87b93b25804a071e3065491e7ffdacc2673d1bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <svl/eitem.hxx>
24 #include <tpprint.hxx>
25 #include <printopt.hxx>
26 #include <scmod.hxx>
27 #include <sc.hrc>
28 #include <officecfg/Office/Calc.hxx>
30 ScTpPrintOptions::ScTpPrintOptions( weld::Container* pPage, weld::DialogController* pController,
31 const SfxItemSet& rCoreAttrs )
32 : SfxTabPage(pPage, pController, u"modules/scalc/ui/optdlg.ui"_ustr, u"optCalcPrintPage"_ustr, &rCoreAttrs )
33 , m_xSkipEmptyPagesCB(m_xBuilder->weld_check_button(u"suppressCB"_ustr))
34 , m_xSkipEmptyPagesImg(m_xBuilder->weld_widget(u"locksuppressCB"_ustr))
35 , m_xSelectedSheetsCB(m_xBuilder->weld_check_button(u"printCB"_ustr))
36 , m_xSelectedSheetsImg(m_xBuilder->weld_widget(u"lockprintCB"_ustr))
37 , m_xForceBreaksCB(m_xBuilder->weld_check_button(u"forceBreaksCB"_ustr))
38 , m_xForceBreaksImg(m_xBuilder->weld_widget(u"lockforceBreaksCB"_ustr))
42 ScTpPrintOptions::~ScTpPrintOptions()
46 std::unique_ptr<SfxTabPage> ScTpPrintOptions::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
48 return std::make_unique<ScTpPrintOptions>(pPage, pController, *rAttrSet);
51 DeactivateRC ScTpPrintOptions::DeactivatePage( SfxItemSet* pSetP )
53 if ( pSetP )
54 FillItemSet( pSetP );
56 return DeactivateRC::LeavePage;
59 void ScTpPrintOptions::Reset( const SfxItemSet* rCoreSet )
61 ScPrintOptions aOptions;
63 if(const ScTpPrintItem* pItem = rCoreSet->GetItemIfSet(SID_SCPRINTOPTIONS, false))
64 aOptions = pItem->GetPrintOptions();
65 else
67 // when called from print dialog and no options set, use configuration
68 aOptions = ScModule::get()->GetPrintOptions();
71 if ( const SfxBoolItem* pItem = rCoreSet->GetItemIfSet( SID_PRINT_SELECTEDSHEET, false))
73 bool bChecked = pItem->GetValue();
74 m_xSelectedSheetsCB->set_active( bChecked );
76 else
78 m_xSelectedSheetsCB->set_active( !aOptions.GetAllSheets() );
81 m_xSkipEmptyPagesCB->set_active( aOptions.GetSkipEmpty() );
82 m_xForceBreaksCB->set_active(aOptions.GetForceBreaks());
84 m_xSkipEmptyPagesCB->set_sensitive(!officecfg::Office::Calc::Print::Page::EmptyPages::isReadOnly());
85 m_xSkipEmptyPagesImg->set_visible(officecfg::Office::Calc::Print::Page::EmptyPages::isReadOnly());
86 m_xSelectedSheetsCB->set_sensitive(!officecfg::Office::Calc::Print::Other::AllSheets::isReadOnly());
87 m_xSelectedSheetsImg->set_visible(officecfg::Office::Calc::Print::Other::AllSheets::isReadOnly());
88 m_xForceBreaksCB->set_sensitive(!officecfg::Office::Calc::Print::Page::ForceBreaks::isReadOnly());
89 m_xForceBreaksImg->set_visible(officecfg::Office::Calc::Print::Page::ForceBreaks::isReadOnly());
91 m_xSkipEmptyPagesCB->save_state();
92 m_xSelectedSheetsCB->save_state();
93 m_xForceBreaksCB->save_state();
96 OUString ScTpPrintOptions::GetAllStrings()
98 OUString sAllStrings;
99 OUString labels[] = { u"label1"_ustr, u"label2"_ustr };
101 for (const auto& label : labels)
103 if (const auto pString = m_xBuilder->weld_label(label))
104 sAllStrings += pString->get_label() + " ";
107 OUString checkButton[] = { u"suppressCB"_ustr, u"forceBreaksCB"_ustr, u"printCB"_ustr };
109 for (const auto& check : checkButton)
111 if (const auto pString = m_xBuilder->weld_check_button(check))
112 sAllStrings += pString->get_label() + " ";
115 return sAllStrings.replaceAll("_", "");
118 bool ScTpPrintOptions::FillItemSet( SfxItemSet* rCoreAttrs )
120 rCoreAttrs->ClearItem( SID_PRINT_SELECTEDSHEET );
122 bool bSkipEmptyChanged = m_xSkipEmptyPagesCB->get_state_changed_from_saved();
123 bool bSelectedSheetsChanged = m_xSelectedSheetsCB->get_state_changed_from_saved();
124 bool bForceBreaksChanged = m_xForceBreaksCB->get_state_changed_from_saved();
126 if ( bSkipEmptyChanged || bSelectedSheetsChanged || bForceBreaksChanged )
128 ScPrintOptions aOpt;
129 aOpt.SetSkipEmpty( m_xSkipEmptyPagesCB->get_active() );
130 aOpt.SetAllSheets( !m_xSelectedSheetsCB->get_active() );
131 aOpt.SetForceBreaks( m_xForceBreaksCB->get_active() );
132 rCoreAttrs->Put( ScTpPrintItem( aOpt ) );
133 if ( bSelectedSheetsChanged )
135 rCoreAttrs->Put( SfxBoolItem( SID_PRINT_SELECTEDSHEET, m_xSelectedSheetsCB->get_active() ) );
137 return true;
139 else
141 return false;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */