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 :
21 : #undef SC_DLLIMPLEMENTATION
22 :
23 :
24 :
25 : #include "scitems.hxx"
26 : #include <comphelper/string.hxx>
27 : #include <svx/drawitem.hxx>
28 : #include <svx/xtable.hxx>
29 : #include <sfx2/objsh.hxx>
30 : #include <unotools/useroptions.hxx>
31 : #include <vcl/msgbox.hxx>
32 : #include <unotools/localedatawrapper.hxx>
33 :
34 : #include "global.hxx"
35 : #include "globstr.hrc"
36 : #include "tabvwsh.hxx"
37 : #include "viewdata.hxx"
38 : #include "document.hxx"
39 : #include "scresid.hxx"
40 : #include "scendlg.hrc"
41 : #include "scendlg.hxx"
42 :
43 : //========================================================================
44 :
45 0 : ScNewScenarioDlg::ScNewScenarioDlg( Window* pParent, const String& rName, sal_Bool bEdit, sal_Bool bSheetProtected)
46 :
47 : : ModalDialog ( pParent, ScResId( RID_SCDLG_NEWSCENARIO ) ),
48 : aFlName ( this, ScResId( FL_NAME )),
49 : aEdName ( this, ScResId( ED_NAME ) ),
50 : aFlComment ( this, ScResId( FL_COMMENT ) ),
51 : aEdComment ( this, ScResId( ED_COMMENT ) ),
52 : aFlOptions ( this, ScResId( FL_OPTIONS ) ),
53 : aCbShowFrame ( this, ScResId( CB_SHOWFRAME ) ),
54 : aLbColor ( this, ScResId( LB_COLOR ) ),
55 : //aCbPrintFrame ( this, ScResId( CB_PRINTFRAME ) ),
56 : aCbTwoWay ( this, ScResId( CB_TWOWAY ) ),
57 : //aCbAttrib ( this, ScResId( CB_ATTRIB ) ),
58 : //aCbValue ( this, ScResId( CB_VALUE ) ),
59 : aCbCopyAll ( this, ScResId( CB_COPYALL ) ),
60 : aCbProtect ( this, ScResId( CB_PROTECT ) ),
61 : aBtnOk ( this, ScResId( BTN_OK ) ),
62 : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
63 : aBtnHelp ( this, ScResId( BTN_HELP ) ),
64 : aDefScenarioName( rName ),
65 0 : bIsEdit ( bEdit )
66 : {
67 0 : if (bIsEdit)
68 0 : SetText(String(ScResId(STR_EDIT)));
69 :
70 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
71 0 : if ( pDocSh )
72 : {
73 0 : const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
74 0 : if ( pItem )
75 : {
76 0 : XColorListRef pColorList = ((SvxColorListItem*)pItem)->GetColorList();
77 0 : if (pColorList.is())
78 : {
79 0 : aLbColor.SetUpdateMode( false );
80 0 : long nCount = pColorList->Count();
81 0 : for ( long n=0; n<nCount; n++ )
82 : {
83 0 : XColorEntry* pEntry = pColorList->GetColor(n);
84 0 : aLbColor.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
85 : }
86 0 : aLbColor.SetUpdateMode( sal_True );
87 0 : }
88 : }
89 : }
90 :
91 0 : SvtUserOptions aUserOpt;
92 :
93 0 : String aComment( ScResId( STR_CREATEDBY ) );
94 :
95 0 : aComment += ' ';
96 0 : aComment += (String)aUserOpt.GetFirstName();
97 0 : aComment += ' ';
98 0 : aComment += (String)aUserOpt.GetLastName();
99 0 : aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
100 0 : aComment += String( ScResId( STR_ON ) );
101 0 : aComment += ' ';
102 0 : aComment += ScGlobal::GetpLocaleData()->getDate( Date( Date::SYSTEM ) );
103 0 : aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
104 0 : aComment += ScGlobal::GetpLocaleData()->getTime( Time( Time::SYSTEM ) );
105 :
106 0 : aEdComment .SetText( aComment );
107 0 : aEdName .SetText( rName );
108 0 : aBtnOk .SetClickHdl( LINK( this, ScNewScenarioDlg, OkHdl ) );
109 0 : aCbShowFrame.SetClickHdl( LINK( this, ScNewScenarioDlg, EnableHdl ) );
110 :
111 0 : aLbColor.SetAccessibleName(String(ScResId( STR_COLOR ) ));
112 :
113 0 : FreeResource();
114 :
115 0 : aLbColor.SelectEntry( Color( COL_LIGHTGRAY ) );
116 0 : aCbShowFrame.Check(sal_True);
117 : //aCbPrintFrame.Check(sal_True);
118 0 : aCbTwoWay.Check(sal_True);
119 : //aCbAttrib.Check(sal_False);
120 : //aCbValue.Check(sal_False);
121 0 : aCbCopyAll.Check(false);
122 0 : aCbProtect.Check(sal_True);
123 :
124 0 : if (bIsEdit)
125 0 : aCbCopyAll.Enable(false);
126 : // If the Sheet is protected then we disable the Scenario Protect input
127 : // and default it to true above. Note we are in 'Add' mode here as: if
128 : // Sheet && scenario protection are true, then we cannot edit this dialog.
129 0 : if (bSheetProtected)
130 0 : aCbProtect.Enable(false);
131 :
132 : //! die drei funktionieren noch nicht...
133 : /*
134 : aCbPrintFrame.Enable(sal_False);
135 : aCbAttrib.Enable(sal_False);
136 : aCbValue.Enable(sal_False);
137 : */
138 :
139 0 : aEdComment.SetAccessibleRelationMemberOf(&aFlComment);
140 0 : aLbColor.SetAccessibleRelationLabeledBy(&aCbShowFrame);
141 0 : }
142 :
143 : //------------------------------------------------------------------------
144 :
145 0 : ScNewScenarioDlg::~ScNewScenarioDlg()
146 : {
147 0 : }
148 :
149 : //------------------------------------------------------------------------
150 :
151 0 : void ScNewScenarioDlg::GetScenarioData( rtl::OUString& rName, rtl::OUString& rComment,
152 : Color& rColor, sal_uInt16& rFlags ) const
153 : {
154 0 : rComment = aEdComment.GetText();
155 0 : rName = aEdName.GetText();
156 :
157 0 : if (rName.isEmpty())
158 0 : rName = aDefScenarioName;
159 :
160 0 : rColor = aLbColor.GetSelectEntryColor();
161 0 : sal_uInt16 nBits = 0;
162 0 : if (aCbShowFrame.IsChecked())
163 0 : nBits |= SC_SCENARIO_SHOWFRAME;
164 : /*
165 : if (aCbPrintFrame.IsChecked())
166 : nBits |= SC_SCENARIO_PRINTFRAME;
167 : */
168 0 : if (aCbTwoWay.IsChecked())
169 0 : nBits |= SC_SCENARIO_TWOWAY;
170 : /*
171 : if (aCbAttrib.IsChecked())
172 : nBits |= SC_SCENARIO_ATTRIB;
173 : if (aCbValue.IsChecked())
174 : nBits |= SC_SCENARIO_VALUE;
175 : */
176 0 : if (aCbCopyAll.IsChecked())
177 0 : nBits |= SC_SCENARIO_COPYALL;
178 0 : if (aCbProtect.IsChecked())
179 0 : nBits |= SC_SCENARIO_PROTECT;
180 0 : rFlags = nBits;
181 0 : }
182 :
183 0 : void ScNewScenarioDlg::SetScenarioData( const rtl::OUString& rName, const rtl::OUString& rComment,
184 : const Color& rColor, sal_uInt16 nFlags )
185 : {
186 0 : aEdComment.SetText(rComment);
187 0 : aEdName.SetText(rName);
188 0 : aLbColor.SelectEntry(rColor);
189 :
190 0 : aCbShowFrame.Check ( (nFlags & SC_SCENARIO_SHOWFRAME) != 0 );
191 0 : EnableHdl( &aCbShowFrame );
192 : //aCbPrintFrame.Check( (nFlags & SC_SCENARIO_PRINTFRAME) != 0 );
193 0 : aCbTwoWay.Check ( (nFlags & SC_SCENARIO_TWOWAY) != 0 );
194 : //aCbAttrib.Check ( (nFlags & SC_SCENARIO_ATTRIB) != 0 );
195 : //aCbValue.Check ( (nFlags & SC_SCENARIO_VALUE) != 0 );
196 : // CopyAll nicht
197 0 : aCbProtect.Check ( (nFlags & SC_SCENARIO_PROTECT) != 0 );
198 0 : }
199 :
200 : //------------------------------------------------------------------------
201 :
202 0 : IMPL_LINK_NOARG(ScNewScenarioDlg, OkHdl)
203 : {
204 0 : String aName = comphelper::string::strip(aEdName.GetText(), ' ');
205 0 : ScDocument* pDoc = ((ScTabViewShell*)SfxViewShell::Current())->
206 0 : GetViewData()->GetDocument();
207 :
208 0 : aEdName.SetText( aName );
209 :
210 0 : if ( !pDoc->ValidTabName( aName ) )
211 : {
212 0 : InfoBox( this, ScGlobal::GetRscString( STR_INVALIDTABNAME ) ).
213 0 : Execute();
214 0 : aEdName.GrabFocus();
215 : }
216 0 : else if ( !bIsEdit && !pDoc->ValidNewTabName( aName ) )
217 : {
218 0 : InfoBox( this, ScGlobal::GetRscString( STR_NEWTABNAMENOTUNIQUE ) ).
219 0 : Execute();
220 0 : aEdName.GrabFocus();
221 : }
222 : else
223 0 : EndDialog( RET_OK );
224 0 : return 0;
225 :
226 : //! beim Editieren testen, ob eine andere Tabelle den Namen hat!
227 : }
228 :
229 : //------------------------------------------------------------------------
230 :
231 0 : IMPL_LINK( ScNewScenarioDlg, EnableHdl, CheckBox *, pBox )
232 : {
233 0 : if( pBox == &aCbShowFrame )
234 0 : aLbColor.Enable( aCbShowFrame.IsChecked() );
235 0 : return 0;
236 0 : }
237 :
238 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|