Line data Source code
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 "scitems.hxx"
23 : #include <comphelper/string.hxx>
24 : #include <svx/drawitem.hxx>
25 : #include <svx/xtable.hxx>
26 : #include <sfx2/objsh.hxx>
27 : #include <unotools/useroptions.hxx>
28 : #include <vcl/msgbox.hxx>
29 : #include <unotools/localedatawrapper.hxx>
30 :
31 : #include "global.hxx"
32 : #include "globstr.hrc"
33 : #include "tabvwsh.hxx"
34 : #include "viewdata.hxx"
35 : #include "document.hxx"
36 : #include "scresid.hxx"
37 : #include "scendlg.hxx"
38 :
39 0 : ScNewScenarioDlg::ScNewScenarioDlg( vcl::Window* pParent, const OUString& rName, bool bEdit, bool bSheetProtected)
40 :
41 : : ModalDialog(pParent, "ScenarioDialog",
42 : "modules/scalc/ui/scenariodialog.ui")
43 : , aDefScenarioName(rName)
44 0 : , bIsEdit(bEdit)
45 : {
46 0 : get(m_pEdName, "name");
47 0 : get(m_pEdComment, "comment");
48 0 : Size aSize(m_pEdComment->LogicToPixel(Size(183, 46), MAP_APPFONT));
49 0 : m_pEdComment->set_width_request(aSize.Width());
50 0 : m_pEdComment->set_height_request(aSize.Height());
51 0 : get(m_pCbShowFrame, "showframe");
52 0 : get(m_pLbColor, "bordercolor");
53 0 : get(m_pCbTwoWay, "copyback");
54 0 : get(m_pCbCopyAll, "copysheet");
55 0 : get(m_pCbProtect, "preventchanges");
56 0 : get(m_pBtnOk, "ok");
57 :
58 0 : if (bIsEdit)
59 0 : SetText(get<FixedText>("alttitle")->GetText());
60 :
61 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
62 0 : if ( pDocSh )
63 : {
64 0 : const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
65 0 : if ( pItem )
66 : {
67 0 : XColorListRef pColorList = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
68 0 : if (pColorList.is())
69 : {
70 0 : m_pLbColor->SetUpdateMode( false );
71 0 : long nCount = pColorList->Count();
72 0 : for ( long n=0; n<nCount; n++ )
73 : {
74 0 : XColorEntry* pEntry = pColorList->GetColor(n);
75 0 : m_pLbColor->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
76 : }
77 0 : m_pLbColor->SetUpdateMode( true );
78 0 : }
79 : }
80 : }
81 :
82 0 : SvtUserOptions aUserOpt;
83 :
84 0 : OUString sCreatedBy(get<FixedText>("createdft")->GetText());
85 0 : OUString sOn(get<FixedText>("onft")->GetText());
86 :
87 0 : OUString aComment(sCreatedBy + " " + aUserOpt.GetFirstName() + " " +aUserOpt.GetLastName()
88 0 : + ", " + sOn + " " + ScGlobal::GetpLocaleData()->getDate(Date(Date::SYSTEM))
89 0 : + ", " + ScGlobal::GetpLocaleData()->getTime(tools::Time(tools::Time::SYSTEM)));
90 :
91 0 : m_pEdComment->SetText(aComment);
92 0 : m_pEdName->SetText(rName);
93 0 : m_pBtnOk->SetClickHdl( LINK( this, ScNewScenarioDlg, OkHdl ) );
94 0 : m_pCbShowFrame->SetClickHdl( LINK( this, ScNewScenarioDlg, EnableHdl ) );
95 :
96 0 : m_pLbColor->SelectEntry( Color( COL_LIGHTGRAY ) );
97 0 : m_pCbShowFrame->Check(true);
98 0 : m_pCbTwoWay->Check(true);
99 0 : m_pCbCopyAll->Check(false);
100 0 : m_pCbProtect->Check(true);
101 :
102 0 : if (bIsEdit)
103 0 : m_pCbCopyAll->Enable(false);
104 : // If the Sheet is protected then we disable the Scenario Protect input
105 : // and default it to true above. Note we are in 'Add' mode here as: if
106 : // Sheet && scenario protection are true, then we cannot edit this dialog.
107 0 : if (bSheetProtected)
108 0 : m_pCbProtect->Enable(false);
109 0 : }
110 :
111 0 : ScNewScenarioDlg::~ScNewScenarioDlg()
112 : {
113 0 : disposeOnce();
114 0 : }
115 :
116 0 : void ScNewScenarioDlg::dispose()
117 : {
118 0 : m_pEdName.clear();
119 0 : m_pEdComment.clear();
120 0 : m_pCbShowFrame.clear();
121 0 : m_pLbColor.clear();
122 0 : m_pCbTwoWay.clear();
123 0 : m_pCbCopyAll.clear();
124 0 : m_pCbProtect.clear();
125 0 : m_pBtnOk.clear();
126 0 : ModalDialog::dispose();
127 0 : }
128 :
129 0 : void ScNewScenarioDlg::GetScenarioData( OUString& rName, OUString& rComment,
130 : Color& rColor, sal_uInt16& rFlags ) const
131 : {
132 0 : rComment = m_pEdComment->GetText();
133 0 : rName = m_pEdName->GetText();
134 :
135 0 : if (rName.isEmpty())
136 0 : rName = aDefScenarioName;
137 :
138 0 : rColor = m_pLbColor->GetSelectEntryColor();
139 0 : sal_uInt16 nBits = 0;
140 0 : if (m_pCbShowFrame->IsChecked())
141 0 : nBits |= SC_SCENARIO_SHOWFRAME;
142 0 : if (m_pCbTwoWay->IsChecked())
143 0 : nBits |= SC_SCENARIO_TWOWAY;
144 0 : if (m_pCbCopyAll->IsChecked())
145 0 : nBits |= SC_SCENARIO_COPYALL;
146 0 : if (m_pCbProtect->IsChecked())
147 0 : nBits |= SC_SCENARIO_PROTECT;
148 0 : rFlags = nBits;
149 0 : }
150 :
151 0 : void ScNewScenarioDlg::SetScenarioData( const OUString& rName, const OUString& rComment,
152 : const Color& rColor, sal_uInt16 nFlags )
153 : {
154 0 : m_pEdComment->SetText(rComment);
155 0 : m_pEdName->SetText(rName);
156 0 : m_pLbColor->SelectEntry(rColor);
157 :
158 0 : m_pCbShowFrame->Check ( (nFlags & SC_SCENARIO_SHOWFRAME) != 0 );
159 0 : EnableHdl(m_pCbShowFrame);
160 0 : m_pCbTwoWay->Check ( (nFlags & SC_SCENARIO_TWOWAY) != 0 );
161 : // CopyAll nicht
162 0 : m_pCbProtect->Check ( (nFlags & SC_SCENARIO_PROTECT) != 0 );
163 0 : }
164 :
165 0 : IMPL_LINK_NOARG(ScNewScenarioDlg, OkHdl)
166 : {
167 0 : OUString aName = comphelper::string::strip(m_pEdName->GetText(), ' ');
168 0 : ScDocument* pDoc = static_cast<ScTabViewShell*>(SfxViewShell::Current())->GetViewData().GetDocument();
169 :
170 0 : m_pEdName->SetText( aName );
171 :
172 0 : if ( !ScDocument::ValidTabName( aName ) )
173 : {
174 0 : ScopedVclPtr<InfoBox>::Create( this, ScGlobal::GetRscString( STR_INVALIDTABNAME ) )->Execute();
175 0 : m_pEdName->GrabFocus();
176 : }
177 0 : else if ( !bIsEdit && !pDoc->ValidNewTabName( aName ) )
178 : {
179 0 : ScopedVclPtr<InfoBox>::Create( this, ScGlobal::GetRscString( STR_NEWTABNAMENOTUNIQUE ) )->Execute();
180 0 : m_pEdName->GrabFocus();
181 : }
182 : else
183 0 : EndDialog( RET_OK );
184 0 : return 0;
185 :
186 : //! beim Editieren testen, ob eine andere Tabelle den Namen hat!
187 : }
188 :
189 0 : IMPL_LINK( ScNewScenarioDlg, EnableHdl, CheckBox *, pBox )
190 : {
191 0 : if (pBox == m_pCbShowFrame)
192 0 : m_pLbColor->Enable( m_pCbShowFrame->IsChecked() );
193 0 : return 0;
194 0 : }
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|