Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sfx2/bindings.hxx>
30 : : #include <sfx2/dispatch.hxx>
31 : : #include <sfx2/viewfrm.hxx>
32 : : #include <svl/slstitm.hxx>
33 : : #include <svl/stritem.hxx>
34 : : #include <vcl/msgbox.hxx>
35 : : #include <vcl/svapp.hxx>
36 : : #include "navipi.hxx"
37 : : #include "popmenu.hxx"
38 : : #include "scresid.hxx"
39 : : #include "sc.hrc"
40 : : #include "globstr.hrc"
41 : :
42 : : //========================================================================
43 : : // class ScScenarioWindow ------------------------------------------------
44 : : //========================================================================
45 : :
46 : 0 : ScScenarioListBox::ScScenarioListBox( ScScenarioWindow& rParent ) :
47 : : ListBox( &rParent, WB_BORDER | WB_TABSTOP ),
48 [ # # ]: 0 : mrParent( rParent )
49 : : {
50 [ # # ]: 0 : Font aFont( GetFont() );
51 [ # # ]: 0 : aFont.SetTransparent( sal_True );
52 [ # # ]: 0 : aFont.SetWeight( WEIGHT_LIGHT );
53 [ # # ][ # # ]: 0 : SetFont( aFont );
54 : 0 : }
55 : :
56 : 0 : ScScenarioListBox::~ScScenarioListBox()
57 : : {
58 [ # # ]: 0 : }
59 : :
60 : 0 : void ScScenarioListBox::UpdateEntries( const std::vector<String> &aNewEntryList )
61 : : {
62 : 0 : Clear();
63 : 0 : maEntries.clear();
64 : :
65 [ # # # ]: 0 : switch( aNewEntryList.size() )
66 : : {
67 : : case 0:
68 : : // no scenarios in current sheet
69 : 0 : mrParent.SetComment( EMPTY_STRING );
70 : 0 : break;
71 : :
72 : : case 1:
73 : : // sheet is a scenario container, comment only
74 : 0 : mrParent.SetComment( aNewEntryList[0] );
75 : 0 : break;
76 : :
77 : : default:
78 : : {
79 : : // sheet contains scenarios
80 : : OSL_ENSURE( aNewEntryList.size() % 3 == 0, "ScScenarioListBox::UpdateEntries - wrong list size" );
81 [ # # ]: 0 : SetUpdateMode( false );
82 : :
83 : 0 : std::vector<String>::const_iterator iter;
84 [ # # ][ # # ]: 0 : for (iter = aNewEntryList.begin(); iter != aNewEntryList.end(); ++iter)
[ # # ]
85 : : {
86 [ # # ]: 0 : ScenarioEntry aEntry;
87 : :
88 : : // first entry of a triple is the scenario name
89 [ # # ][ # # ]: 0 : aEntry.maName = *iter;
90 : :
91 : : // second entry of a triple is the scenario comment
92 [ # # ]: 0 : ++iter;
93 [ # # ][ # # ]: 0 : aEntry.maComment = *iter;
94 : :
95 : : // third entry of a triple is the protection ("0" = not protected, "1" = protected)
96 [ # # ]: 0 : ++iter;
97 [ # # ][ # # ]: 0 : aEntry.mbProtected = (iter->Len() > 0) && (iter->GetChar( 0 ) != '0');
[ # # ][ # # ]
98 : :
99 [ # # ]: 0 : maEntries.push_back( aEntry );
100 [ # # ]: 0 : InsertEntry( aEntry.maName, LISTBOX_APPEND );
101 [ # # ]: 0 : }
102 [ # # ]: 0 : SetUpdateMode( sal_True );
103 [ # # ]: 0 : SetNoSelection();
104 [ # # ][ # # ]: 0 : mrParent.SetComment( EMPTY_STRING );
105 : : }
106 : : }
107 : 0 : }
108 : :
109 : 0 : void ScScenarioListBox::Select()
110 : : {
111 [ # # ]: 0 : if( const ScenarioEntry* pEntry = GetSelectedEntry() )
112 : 0 : mrParent.SetComment( pEntry->maComment );
113 : 0 : }
114 : :
115 : 0 : void ScScenarioListBox::DoubleClick()
116 : : {
117 : 0 : SelectScenario();
118 : 0 : }
119 : :
120 : 0 : long ScScenarioListBox::Notify( NotifyEvent& rNEvt )
121 : : {
122 : 0 : bool bHandled = false;
123 : :
124 [ # # ]: 0 : if( rNEvt.GetType() == EVENT_KEYINPUT )
125 : : {
126 [ # # ]: 0 : KeyCode aCode = rNEvt.GetKeyEvent()->GetKeyCode();
127 [ # # # ]: 0 : switch( aCode.GetCode() )
128 : : {
129 : : case KEY_RETURN:
130 [ # # ]: 0 : SelectScenario();
131 : 0 : bHandled = true;
132 : 0 : break;
133 : : case KEY_DELETE:
134 [ # # ]: 0 : DeleteScenario( true );
135 : 0 : bHandled = true;
136 : 0 : break;
137 : : }
138 : : }
139 [ # # ][ # # ]: 0 : else if ( rNEvt.GetType() == EVENT_COMMAND && GetSelectEntryCount() )
[ # # ]
140 : : {
141 : 0 : const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
142 [ # # ][ # # ]: 0 : if ( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
[ # # ]
143 : : {
144 [ # # ]: 0 : if( const ScenarioEntry* pEntry = GetSelectedEntry() )
145 : : {
146 [ # # ]: 0 : if( !pEntry->mbProtected )
147 : : {
148 [ # # ][ # # ]: 0 : ScPopupMenu aPopup( ScResId( RID_POPUP_NAVIPI_SCENARIO ) );
149 [ # # ]: 0 : aPopup.Execute( this, pCEvt->GetMousePosPixel() );
150 [ # # ]: 0 : if (aPopup.WasHit())
151 : : {
152 [ # # # ]: 0 : switch( aPopup.GetSelected() )
153 : : {
154 : : case RID_NAVIPI_SCENARIO_DELETE:
155 [ # # ]: 0 : DeleteScenario( true );
156 : 0 : break;
157 : : case RID_NAVIPI_SCENARIO_EDIT:
158 [ # # ]: 0 : EditScenario();
159 : 0 : break;
160 : : }
161 [ # # ]: 0 : }
162 : : }
163 : : }
164 : 0 : bHandled = true;
165 : : }
166 : : }
167 : :
168 [ # # ]: 0 : return bHandled ? 1 : ListBox::Notify( rNEvt );
169 : : }
170 : :
171 : 0 : const ScScenarioListBox::ScenarioEntry* ScScenarioListBox::GetSelectedEntry() const
172 : : {
173 : 0 : size_t nPos = GetSelectEntryPos();
174 [ # # ]: 0 : return (nPos < maEntries.size()) ? &maEntries[ nPos ] : 0;
175 : : }
176 : :
177 : 0 : void ScScenarioListBox::ExecuteScenarioSlot( sal_uInt16 nSlotId )
178 : : {
179 [ # # ]: 0 : if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
180 : : {
181 [ # # ][ # # ]: 0 : SfxStringItem aStringItem( nSlotId, GetSelectEntry() );
[ # # ]
182 [ # # ][ # # ]: 0 : pViewFrm->GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aStringItem, 0L, 0L );
183 : : }
184 : 0 : }
185 : :
186 : 0 : void ScScenarioListBox::SelectScenario()
187 : : {
188 [ # # ]: 0 : if( GetSelectEntryCount() > 0 )
189 : 0 : ExecuteScenarioSlot( SID_SELECT_SCENARIO );
190 : 0 : }
191 : :
192 : 0 : void ScScenarioListBox::EditScenario()
193 : : {
194 [ # # ]: 0 : if( GetSelectEntryCount() > 0 )
195 : 0 : ExecuteScenarioSlot( SID_EDIT_SCENARIO );
196 : 0 : }
197 : :
198 : 0 : void ScScenarioListBox::DeleteScenario( bool bQueryBox )
199 : : {
200 [ # # ]: 0 : if( GetSelectEntryCount() > 0 )
201 [ # # ][ # # ]: 0 : if( !bQueryBox || (::QueryBox( 0, WinBits( WB_YES_NO | WB_DEF_YES ), ScGlobal::GetRscString( STR_QUERY_DELSCENARIO ) ).Execute() == RET_YES) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
202 : 0 : ExecuteScenarioSlot( SID_DELETE_SCENARIO );
203 : 0 : }
204 : :
205 : : //========================================================================
206 : : // class ScScenarioWindow ------------------------------------------------
207 : : //========================================================================
208 : :
209 : 0 : ScScenarioWindow::ScScenarioWindow( Window* pParent,const String& aQH_List,
210 : : const String& aQH_Comment)
211 : : : Window ( pParent, WB_TABSTOP | WB_DIALOGCONTROL ),
212 : : aLbScenario ( *this ),
213 [ # # ][ # # ]: 0 : aEdComment ( this, WB_BORDER | WB_LEFT | WB_READONLY | WB_VSCROLL | WB_TABSTOP )
214 : : {
215 [ # # ]: 0 : Font aFont( GetFont() );
216 [ # # ]: 0 : aFont.SetTransparent( sal_True );
217 [ # # ]: 0 : aFont.SetWeight( WEIGHT_LIGHT );
218 [ # # ]: 0 : aEdComment.SetFont( aFont );
219 [ # # ]: 0 : aEdComment.SetMaxTextLen( 512 );
220 [ # # ]: 0 : aLbScenario.SetPosPixel( Point(0,0) );
221 [ # # ]: 0 : aLbScenario.SetHelpId(HID_SC_SCENWIN_TOP);
222 [ # # ]: 0 : aEdComment.SetHelpId(HID_SC_SCENWIN_BOTTOM);
223 [ # # ]: 0 : aLbScenario.Show();
224 [ # # ]: 0 : aEdComment.Show();
225 : :
226 [ # # ]: 0 : aLbScenario.SetQuickHelpText(aQH_List);
227 [ # # ]: 0 : aEdComment.SetQuickHelpText(aQH_Comment);
228 [ # # ][ # # ]: 0 : aEdComment.SetBackground( Color( COL_LIGHTGRAY ) );
[ # # ]
229 : :
230 [ # # ]: 0 : SfxViewFrame* pViewFrm = SfxViewFrame::Current();
231 [ # # ]: 0 : if (pViewFrm)
232 : : {
233 : 0 : SfxBindings& rBindings = pViewFrm->GetBindings();
234 [ # # ]: 0 : rBindings.Invalidate( SID_SELECT_SCENARIO );
235 [ # # ]: 0 : rBindings.Update( SID_SELECT_SCENARIO );
236 [ # # ]: 0 : }
237 : 0 : }
238 : :
239 : : // -----------------------------------------------------------------------
240 : :
241 [ # # ][ # # ]: 0 : ScScenarioWindow::~ScScenarioWindow()
242 : : {
243 [ # # ]: 0 : }
244 : :
245 : 0 : void ScScenarioWindow::Paint( const Rectangle& rRec )
246 : : {
247 [ # # ]: 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
248 : 0 : Color aBgColor = rStyleSettings.GetFaceColor();
249 : :
250 [ # # ][ # # ]: 0 : SetBackground( aBgColor );
[ # # ]
251 : :
252 [ # # ]: 0 : Window::Paint( rRec );
253 : 0 : }
254 : :
255 : : // -----------------------------------------------------------------------
256 : :
257 : 0 : void ScScenarioWindow::NotifyState( const SfxPoolItem* pState )
258 : : {
259 [ # # ]: 0 : if( pState )
260 : : {
261 : 0 : aLbScenario.Enable();
262 : :
263 [ # # ]: 0 : if ( pState->ISA(SfxStringItem) )
264 : : {
265 [ # # ]: 0 : String aNewEntry( ((const SfxStringItem*)pState)->GetValue() );
266 : :
267 [ # # ]: 0 : if ( aNewEntry.Len() > 0 )
268 [ # # ]: 0 : aLbScenario.SelectEntry( aNewEntry );
269 : : else
270 [ # # ][ # # ]: 0 : aLbScenario.SetNoSelection();
271 : : }
272 [ # # ]: 0 : else if ( pState->ISA(SfxStringListItem) )
273 : : {
274 : 0 : aLbScenario.UpdateEntries( ((SfxStringListItem*)pState)->GetList() );
275 : : }
276 : : }
277 : : else
278 : : {
279 : 0 : aLbScenario.Disable();
280 : 0 : aLbScenario.SetNoSelection();
281 : : }
282 : 0 : }
283 : :
284 : : // -----------------------------------------------------------------------
285 : :
286 : 0 : void ScScenarioWindow::SetSizePixel( const Size& rNewSize )
287 : : {
288 : 0 : Size aSize( rNewSize );
289 : 0 : long nHeight = aSize.Height() / 2;
290 : :
291 [ # # ]: 0 : Window::SetSizePixel( aSize );
292 : :
293 : 0 : aSize.Height() = nHeight;
294 [ # # ]: 0 : aLbScenario.SetSizePixel( aSize );
295 : :
296 : 0 : aSize.Height() -= 4;
297 [ # # ]: 0 : aEdComment.SetPosSizePixel( Point( 0, nHeight+4 ), aSize );
298 : 0 : }
299 : :
300 : :
301 : :
302 : :
303 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|