tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / dbgui / scendlg.cxx
blob38da57a5849e661b6c175fa2bdf3f2b6f920a29a
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 <comphelper/string.hxx>
23 #include <svx/colorbox.hxx>
24 #include <unotools/useroptions.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/weld.hxx>
27 #include <unotools/localedatawrapper.hxx>
29 #include <global.hxx>
30 #include <globstr.hrc>
31 #include <scresid.hxx>
32 #include <tabvwsh.hxx>
33 #include <viewdata.hxx>
34 #include <document.hxx>
35 #include <scendlg.hxx>
37 ScNewScenarioDlg::ScNewScenarioDlg(weld::Window* pParent, const OUString& rName, bool bEdit, bool bSheetProtected)
38 : GenericDialogController(pParent, u"modules/scalc/ui/scenariodialog.ui"_ustr, u"ScenarioDialog"_ustr)
39 , aDefScenarioName(rName)
40 , bIsEdit(bEdit)
41 , m_xEdName(m_xBuilder->weld_entry(u"name"_ustr))
42 , m_xEdComment(m_xBuilder->weld_text_view(u"comment"_ustr))
43 , m_xCbShowFrame(m_xBuilder->weld_check_button(u"showframe"_ustr))
44 , m_xLbColor(new ColorListBox(m_xBuilder->weld_menu_button(u"bordercolor"_ustr), [this] { return m_xDialog.get(); }))
45 , m_xCbTwoWay(m_xBuilder->weld_check_button(u"copyback"_ustr))
46 , m_xCbCopyAll(m_xBuilder->weld_check_button(u"copysheet"_ustr))
47 , m_xCbProtect(m_xBuilder->weld_check_button(u"preventchanges"_ustr))
48 , m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr))
49 , m_xAltTitle(m_xBuilder->weld_label(u"alttitle"_ustr))
50 , m_xCreatedFt(m_xBuilder->weld_label(u"createdft"_ustr))
51 , m_xOnFt(m_xBuilder->weld_label(u"onft"_ustr))
53 m_xEdComment->set_size_request(m_xEdComment->get_approximate_digit_width() * 60,
54 m_xEdComment->get_height_rows(6));
56 if (bIsEdit)
57 m_xDialog->set_title(m_xAltTitle->get_label());
59 SvtUserOptions aUserOpt;
61 OUString sCreatedBy(m_xCreatedFt->get_label());
62 OUString sOn(m_xOnFt->get_label());
64 OUString aComment(sCreatedBy + " " + aUserOpt.GetFirstName() + " " +aUserOpt.GetLastName()
65 + ", " + sOn + " " + ScGlobal::getLocaleData().getDate(Date(Date::SYSTEM))
66 + ", " + ScGlobal::getLocaleData().getTime(tools::Time(tools::Time::SYSTEM)));
68 m_xEdComment->set_text(aComment);
69 m_xEdName->set_text(rName);
70 m_xBtnOk->connect_clicked(LINK(this, ScNewScenarioDlg, OkHdl));
71 m_xCbShowFrame->connect_toggled(LINK(this, ScNewScenarioDlg, EnableHdl));
73 m_xLbColor->SelectEntry( COL_LIGHTGRAY );
74 m_xCbShowFrame->set_active(true);
75 m_xCbTwoWay->set_active(true);
76 m_xCbCopyAll->set_active(false);
77 m_xCbProtect->set_active(true);
79 if (bIsEdit)
80 m_xCbCopyAll->set_active(false);
81 // If the Sheet is protected then we disable the Scenario Protect input
82 // and default it to true above. Note we are in 'Add' mode here as: if
83 // Sheet && scenario protection are true, then we cannot edit this dialog.
84 if (bSheetProtected)
85 m_xCbProtect->set_active(false);
88 ScNewScenarioDlg::~ScNewScenarioDlg()
92 void ScNewScenarioDlg::GetScenarioData( OUString& rName, OUString& rComment,
93 Color& rColor, ScScenarioFlags& rFlags ) const
95 rComment = m_xEdComment->get_text();
96 rName = m_xEdName->get_text();
98 if (rName.isEmpty())
99 rName = aDefScenarioName;
101 rColor = m_xLbColor->GetSelectEntryColor();
102 ScScenarioFlags nBits = ScScenarioFlags::NONE;
103 if (m_xCbShowFrame->get_active())
104 nBits |= ScScenarioFlags::ShowFrame;
105 if (m_xCbTwoWay->get_active())
106 nBits |= ScScenarioFlags::TwoWay;
107 if (m_xCbCopyAll->get_active())
108 nBits |= ScScenarioFlags::CopyAll;
109 if (m_xCbProtect->get_active())
110 nBits |= ScScenarioFlags::Protected;
111 rFlags = nBits;
114 void ScNewScenarioDlg::SetScenarioData(const OUString& rName, const OUString& rComment,
115 const Color& rColor, ScScenarioFlags nFlags)
117 m_xEdComment->set_text(rComment);
118 m_xEdName->set_text(rName);
119 m_xLbColor->SelectEntry(rColor);
121 m_xCbShowFrame->set_active( (nFlags & ScScenarioFlags::ShowFrame) != ScScenarioFlags::NONE );
122 EnableHdl(*m_xCbShowFrame);
123 m_xCbTwoWay->set_active( (nFlags & ScScenarioFlags::TwoWay) != ScScenarioFlags::NONE );
124 // not CopyAll
125 m_xCbProtect->set_active( (nFlags & ScScenarioFlags::Protected) != ScScenarioFlags::NONE );
128 IMPL_LINK_NOARG(ScNewScenarioDlg, OkHdl, weld::Button&, void)
130 OUString aName = comphelper::string::strip(m_xEdName->get_text(), ' ');
131 ScDocument& rDoc = static_cast<ScTabViewShell*>(SfxViewShell::Current())->GetViewData().GetDocument();
133 m_xEdName->set_text(aName);
135 if ( !ScDocument::ValidTabName( aName ) )
137 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
138 VclMessageType::Info, VclButtonsType::Ok,
139 ScResId(STR_INVALIDTABNAME)));
140 xInfoBox->run();
141 m_xEdName->grab_focus();
143 else if ( !bIsEdit && !rDoc.ValidNewTabName( aName ) )
145 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
146 VclMessageType::Info, VclButtonsType::Ok,
147 ScResId(STR_NEWTABNAMENOTUNIQUE)));
148 xInfoBox->run();
149 m_xEdName->grab_focus();
151 else
152 m_xDialog->response(RET_OK);
154 //! when editing, test whether another table has the name!
157 IMPL_LINK(ScNewScenarioDlg, EnableHdl, weld::Toggleable&, rBox, void)
159 if (&rBox == m_xCbShowFrame.get())
160 m_xLbColor->set_sensitive(m_xCbShowFrame->get_active());
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */