1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "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>
32 #include "globstr.hrc"
33 #include "tabvwsh.hxx"
34 #include "viewdata.hxx"
35 #include "document.hxx"
36 #include "scresid.hxx"
37 #include "scendlg.hxx"
39 ScNewScenarioDlg::ScNewScenarioDlg( vcl::Window
* pParent
, const OUString
& rName
, bool bEdit
, bool bSheetProtected
)
41 : ModalDialog(pParent
, "ScenarioDialog",
42 "modules/scalc/ui/scenariodialog.ui")
43 , aDefScenarioName(rName
)
46 get(m_pEdName
, "name");
47 get(m_pEdComment
, "comment");
48 Size
aSize(m_pEdComment
->LogicToPixel(Size(183, 46), MAP_APPFONT
));
49 m_pEdComment
->set_width_request(aSize
.Width());
50 m_pEdComment
->set_height_request(aSize
.Height());
51 get(m_pCbShowFrame
, "showframe");
52 get(m_pLbColor
, "bordercolor");
53 get(m_pCbTwoWay
, "copyback");
54 get(m_pCbCopyAll
, "copysheet");
55 get(m_pCbProtect
, "preventchanges");
59 SetText(get
<FixedText
>("alttitle")->GetText());
61 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
64 const SfxPoolItem
* pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
);
67 XColorListRef pColorList
= static_cast<const SvxColorListItem
*>(pItem
)->GetColorList();
70 m_pLbColor
->SetUpdateMode( false );
71 long nCount
= pColorList
->Count();
72 for ( long n
=0; n
<nCount
; n
++ )
74 XColorEntry
* pEntry
= pColorList
->GetColor(n
);
75 m_pLbColor
->InsertEntry( pEntry
->GetColor(), pEntry
->GetName() );
77 m_pLbColor
->SetUpdateMode( true );
82 SvtUserOptions aUserOpt
;
84 OUString
sCreatedBy(get
<FixedText
>("createdft")->GetText());
85 OUString
sOn(get
<FixedText
>("onft")->GetText());
87 OUString
aComment(sCreatedBy
+ " " + aUserOpt
.GetFirstName() + " " +aUserOpt
.GetLastName()
88 + ", " + sOn
+ " " + ScGlobal::GetpLocaleData()->getDate(Date(Date::SYSTEM
))
89 + ", " + ScGlobal::GetpLocaleData()->getTime(tools::Time(tools::Time::SYSTEM
)));
91 m_pEdComment
->SetText(aComment
);
92 m_pEdName
->SetText(rName
);
93 m_pBtnOk
->SetClickHdl( LINK( this, ScNewScenarioDlg
, OkHdl
) );
94 m_pCbShowFrame
->SetClickHdl( LINK( this, ScNewScenarioDlg
, EnableHdl
) );
96 m_pLbColor
->SelectEntry( Color( COL_LIGHTGRAY
) );
97 m_pCbShowFrame
->Check(true);
98 m_pCbTwoWay
->Check(true);
99 m_pCbCopyAll
->Check(false);
100 m_pCbProtect
->Check(true);
103 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.
108 m_pCbProtect
->Enable(false);
111 ScNewScenarioDlg::~ScNewScenarioDlg()
116 void ScNewScenarioDlg::dispose()
119 m_pEdComment
.clear();
120 m_pCbShowFrame
.clear();
123 m_pCbCopyAll
.clear();
124 m_pCbProtect
.clear();
126 ModalDialog::dispose();
129 void ScNewScenarioDlg::GetScenarioData( OUString
& rName
, OUString
& rComment
,
130 Color
& rColor
, sal_uInt16
& rFlags
) const
132 rComment
= m_pEdComment
->GetText();
133 rName
= m_pEdName
->GetText();
136 rName
= aDefScenarioName
;
138 rColor
= m_pLbColor
->GetSelectEntryColor();
139 sal_uInt16 nBits
= 0;
140 if (m_pCbShowFrame
->IsChecked())
141 nBits
|= SC_SCENARIO_SHOWFRAME
;
142 if (m_pCbTwoWay
->IsChecked())
143 nBits
|= SC_SCENARIO_TWOWAY
;
144 if (m_pCbCopyAll
->IsChecked())
145 nBits
|= SC_SCENARIO_COPYALL
;
146 if (m_pCbProtect
->IsChecked())
147 nBits
|= SC_SCENARIO_PROTECT
;
151 void ScNewScenarioDlg::SetScenarioData( const OUString
& rName
, const OUString
& rComment
,
152 const Color
& rColor
, sal_uInt16 nFlags
)
154 m_pEdComment
->SetText(rComment
);
155 m_pEdName
->SetText(rName
);
156 m_pLbColor
->SelectEntry(rColor
);
158 m_pCbShowFrame
->Check ( (nFlags
& SC_SCENARIO_SHOWFRAME
) != 0 );
159 EnableHdl(m_pCbShowFrame
);
160 m_pCbTwoWay
->Check ( (nFlags
& SC_SCENARIO_TWOWAY
) != 0 );
162 m_pCbProtect
->Check ( (nFlags
& SC_SCENARIO_PROTECT
) != 0 );
165 IMPL_LINK_NOARG(ScNewScenarioDlg
, OkHdl
)
167 OUString aName
= comphelper::string::strip(m_pEdName
->GetText(), ' ');
168 ScDocument
* pDoc
= static_cast<ScTabViewShell
*>(SfxViewShell::Current())->GetViewData().GetDocument();
170 m_pEdName
->SetText( aName
);
172 if ( !ScDocument::ValidTabName( aName
) )
174 ScopedVclPtr
<InfoBox
>::Create( this, ScGlobal::GetRscString( STR_INVALIDTABNAME
) )->Execute();
175 m_pEdName
->GrabFocus();
177 else if ( !bIsEdit
&& !pDoc
->ValidNewTabName( aName
) )
179 ScopedVclPtr
<InfoBox
>::Create( this, ScGlobal::GetRscString( STR_NEWTABNAMENOTUNIQUE
) )->Execute();
180 m_pEdName
->GrabFocus();
186 //! beim Editieren testen, ob eine andere Tabelle den Namen hat!
189 IMPL_LINK( ScNewScenarioDlg
, EnableHdl
, CheckBox
*, pBox
)
191 if (pBox
== m_pCbShowFrame
)
192 m_pLbColor
->Enable( m_pCbShowFrame
->IsChecked() );
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */