LibreOffice Module sc (master) 1
scendlg.cxx
Go to the documentation of this file.
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#undef SC_DLLIMPLEMENTATION
21
22#include <comphelper/string.hxx>
23#include <svx/colorbox.hxx>
25#include <vcl/svapp.hxx>
26#include <vcl/weld.hxx>
28
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>
36
37ScNewScenarioDlg::ScNewScenarioDlg(weld::Window* pParent, const OUString& rName, bool bEdit, bool bSheetProtected)
38 : GenericDialogController(pParent, "modules/scalc/ui/scenariodialog.ui", "ScenarioDialog")
39 , aDefScenarioName(rName)
40 , bIsEdit(bEdit)
41 , m_xEdName(m_xBuilder->weld_entry("name"))
42 , m_xEdComment(m_xBuilder->weld_text_view("comment"))
43 , m_xCbShowFrame(m_xBuilder->weld_check_button("showframe"))
44 , m_xLbColor(new ColorListBox(m_xBuilder->weld_menu_button("bordercolor"), [this] { return m_xDialog.get(); }))
45 , m_xCbTwoWay(m_xBuilder->weld_check_button("copyback"))
46 , m_xCbCopyAll(m_xBuilder->weld_check_button("copysheet"))
47 , m_xCbProtect(m_xBuilder->weld_check_button("preventchanges"))
48 , m_xBtnOk(m_xBuilder->weld_button("ok"))
49 , m_xAltTitle(m_xBuilder->weld_label("alttitle"))
50 , m_xCreatedFt(m_xBuilder->weld_label("createdft"))
51 , m_xOnFt(m_xBuilder->weld_label("onft"))
52{
53 m_xEdComment->set_size_request(m_xEdComment->get_approximate_digit_width() * 60,
54 m_xEdComment->get_height_rows(6));
55
56 if (bIsEdit)
57 m_xDialog->set_title(m_xAltTitle->get_label());
58
59 SvtUserOptions aUserOpt;
60
61 OUString sCreatedBy(m_xCreatedFt->get_label());
62 OUString sOn(m_xOnFt->get_label());
63
64 OUString aComment(sCreatedBy + " " + aUserOpt.GetFirstName() + " " +aUserOpt.GetLastName()
65 + ", " + sOn + " " + ScGlobal::getLocaleData().getDate(Date(Date::SYSTEM))
67
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));
72
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);
78
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);
86}
87
89{
90}
91
92void ScNewScenarioDlg::GetScenarioData( OUString& rName, OUString& rComment,
93 Color& rColor, ScScenarioFlags& rFlags ) const
94{
95 rComment = m_xEdComment->get_text();
96 rName = m_xEdName->get_text();
97
98 if (rName.isEmpty())
99 rName = aDefScenarioName;
100
101 rColor = m_xLbColor->GetSelectEntryColor();
103 if (m_xCbShowFrame->get_active())
105 if (m_xCbTwoWay->get_active())
107 if (m_xCbCopyAll->get_active())
109 if (m_xCbProtect->get_active())
111 rFlags = nBits;
112}
113
114void ScNewScenarioDlg::SetScenarioData(const OUString& rName, const OUString& rComment,
115 const Color& rColor, ScScenarioFlags nFlags)
116{
117 m_xEdComment->set_text(rComment);
118 m_xEdName->set_text(rName);
119 m_xLbColor->SelectEntry(rColor);
120
122 EnableHdl(*m_xCbShowFrame);
123 m_xCbTwoWay->set_active( (nFlags & ScScenarioFlags::TwoWay) != ScScenarioFlags::NONE );
124 // not CopyAll
126}
127
129{
130 OUString aName = comphelper::string::strip(m_xEdName->get_text(), ' ');
131 ScDocument& rDoc = static_cast<ScTabViewShell*>(SfxViewShell::Current())->GetViewData().GetDocument();
132
133 m_xEdName->set_text(aName);
134
136 {
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();
142 }
143 else if ( !bIsEdit && !rDoc.ValidNewTabName( aName ) )
144 {
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();
150 }
151 else
152 m_xDialog->response(RET_OK);
153
155}
156
158{
159 if (&rBox == m_xCbShowFrame.get())
160 m_xLbColor->set_sensitive(m_xCbShowFrame->get_active());
161}
162
163/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString getDate(const Date &rDate) const
SC_DLLPUBLIC bool ValidNewTabName(const OUString &rName) const
Definition: document.cxx:357
static SC_DLLPUBLIC bool ValidTabName(const OUString &rName)
Definition: document.cxx:318
static SC_DLLPUBLIC const LocaleDataWrapper & getLocaleData()
Definition: global.cxx:1055
std::unique_ptr< weld::CheckButton > m_xCbTwoWay
Definition: scendlg.hxx:46
void GetScenarioData(OUString &rName, OUString &rComment, Color &rColor, ScScenarioFlags &rFlags) const
Definition: scendlg.cxx:92
virtual ~ScNewScenarioDlg() override
Definition: scendlg.cxx:88
OUString aDefScenarioName
Definition: scendlg.hxx:40
std::unique_ptr< weld::TextView > m_xEdComment
Definition: scendlg.hxx:43
std::unique_ptr< weld::CheckButton > m_xCbProtect
Definition: scendlg.hxx:48
std::unique_ptr< weld::CheckButton > m_xCbShowFrame
Definition: scendlg.hxx:44
std::unique_ptr< ColorListBox > m_xLbColor
Definition: scendlg.hxx:45
void SetScenarioData(const OUString &rName, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: scendlg.cxx:114
ScNewScenarioDlg(weld::Window *pParent, const OUString &rName, bool bEdit, bool bSheetProtected)
Definition: scendlg.cxx:37
std::unique_ptr< weld::CheckButton > m_xCbCopyAll
Definition: scendlg.hxx:47
std::unique_ptr< weld::Entry > m_xEdName
Definition: scendlg.hxx:42
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
OUString GetFirstName() const
OUString GetLastName() const
std::shared_ptr< weld::Dialog > m_xDialog
ScScenarioFlags
Definition: global.hxx:226
OUString aName
OString strip(const OString &rIn, char c)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
IMPL_LINK(ScNewScenarioDlg, EnableHdl, weld::Toggleable &, rBox, void)
Definition: scendlg.cxx:157
IMPL_LINK_NOARG(ScNewScenarioDlg, OkHdl, weld::Button &, void)
Definition: scendlg.cxx:128
RET_OK