GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / navipi / scenwnd.cxx
blobb62298c8c0481a855836cdbeadb6f00f067b25fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <sfx2/bindings.hxx>
21 #include <sfx2/dispatch.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <svl/slstitm.hxx>
24 #include <svl/stritem.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <vcl/svapp.hxx>
27 #include "navipi.hxx"
28 #include "popmenu.hxx"
29 #include "scresid.hxx"
30 #include "sc.hrc"
31 #include "globstr.hrc"
33 //========================================================================
34 // class ScScenarioWindow ------------------------------------------------
35 //========================================================================
37 ScScenarioListBox::ScScenarioListBox( ScScenarioWindow& rParent ) :
38 ListBox( &rParent, WB_BORDER | WB_TABSTOP ),
39 mrParent( rParent )
41 Font aFont( GetFont() );
42 aFont.SetTransparent( sal_True );
43 aFont.SetWeight( WEIGHT_LIGHT );
44 SetFont( aFont );
47 ScScenarioListBox::~ScScenarioListBox()
51 void ScScenarioListBox::UpdateEntries( const std::vector<OUString> &aNewEntryList )
53 Clear();
54 maEntries.clear();
56 switch( aNewEntryList.size() )
58 case 0:
59 // no scenarios in current sheet
60 mrParent.SetComment( EMPTY_OUSTRING );
61 break;
63 case 1:
64 // sheet is a scenario container, comment only
65 mrParent.SetComment( aNewEntryList[0] );
66 break;
68 default:
70 // sheet contains scenarios
71 OSL_ENSURE( aNewEntryList.size() % 3 == 0, "ScScenarioListBox::UpdateEntries - wrong list size" );
72 SetUpdateMode( false );
74 std::vector<OUString>::const_iterator iter;
75 for (iter = aNewEntryList.begin(); iter != aNewEntryList.end(); ++iter)
77 ScenarioEntry aEntry;
79 // first entry of a triple is the scenario name
80 aEntry.maName = *iter;
82 // second entry of a triple is the scenario comment
83 ++iter;
84 aEntry.maComment = *iter;
86 // third entry of a triple is the protection ("0" = not protected, "1" = protected)
87 ++iter;
88 aEntry.mbProtected = !(*iter).isEmpty() && (*iter)[0] != '0';
90 maEntries.push_back( aEntry );
91 InsertEntry( aEntry.maName, LISTBOX_APPEND );
93 SetUpdateMode( sal_True );
94 SetNoSelection();
95 mrParent.SetComment( EMPTY_OUSTRING );
100 void ScScenarioListBox::Select()
102 if( const ScenarioEntry* pEntry = GetSelectedEntry() )
103 mrParent.SetComment( pEntry->maComment );
106 void ScScenarioListBox::DoubleClick()
108 SelectScenario();
111 long ScScenarioListBox::Notify( NotifyEvent& rNEvt )
113 bool bHandled = false;
115 if( rNEvt.GetType() == EVENT_KEYINPUT )
117 KeyCode aCode = rNEvt.GetKeyEvent()->GetKeyCode();
118 switch( aCode.GetCode() )
120 case KEY_RETURN:
121 SelectScenario();
122 bHandled = true;
123 break;
124 case KEY_DELETE:
125 DeleteScenario( true );
126 bHandled = true;
127 break;
130 else if ( rNEvt.GetType() == EVENT_COMMAND && GetSelectEntryCount() )
132 const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
133 if ( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
135 if( const ScenarioEntry* pEntry = GetSelectedEntry() )
137 if( !pEntry->mbProtected )
139 ScPopupMenu aPopup( ScResId( RID_POPUP_NAVIPI_SCENARIO ) );
140 aPopup.Execute( this, pCEvt->GetMousePosPixel() );
141 if (aPopup.WasHit())
143 switch( aPopup.GetSelected() )
145 case RID_NAVIPI_SCENARIO_DELETE:
146 DeleteScenario( true );
147 break;
148 case RID_NAVIPI_SCENARIO_EDIT:
149 EditScenario();
150 break;
155 bHandled = true;
159 return bHandled ? 1 : ListBox::Notify( rNEvt );
162 const ScScenarioListBox::ScenarioEntry* ScScenarioListBox::GetSelectedEntry() const
164 size_t nPos = GetSelectEntryPos();
165 return (nPos < maEntries.size()) ? &maEntries[ nPos ] : 0;
168 void ScScenarioListBox::ExecuteScenarioSlot( sal_uInt16 nSlotId )
170 if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
172 SfxStringItem aStringItem( nSlotId, GetSelectEntry() );
173 pViewFrm->GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aStringItem, 0L, 0L );
177 void ScScenarioListBox::SelectScenario()
179 if( GetSelectEntryCount() > 0 )
180 ExecuteScenarioSlot( SID_SELECT_SCENARIO );
183 void ScScenarioListBox::EditScenario()
185 if( GetSelectEntryCount() > 0 )
186 ExecuteScenarioSlot( SID_EDIT_SCENARIO );
189 void ScScenarioListBox::DeleteScenario( bool bQueryBox )
191 if( GetSelectEntryCount() > 0 )
192 if( !bQueryBox || (::QueryBox( 0, WinBits( WB_YES_NO | WB_DEF_YES ), ScGlobal::GetRscString( STR_QUERY_DELSCENARIO ) ).Execute() == RET_YES) )
193 ExecuteScenarioSlot( SID_DELETE_SCENARIO );
196 //========================================================================
197 // class ScScenarioWindow ------------------------------------------------
198 //========================================================================
200 ScScenarioWindow::ScScenarioWindow( Window* pParent, const OUString& aQH_List,
201 const OUString& aQH_Comment)
202 : Window ( pParent, WB_TABSTOP | WB_DIALOGCONTROL ),
203 aLbScenario ( *this ),
204 aEdComment ( this, WB_BORDER | WB_LEFT | WB_READONLY | WB_VSCROLL | WB_TABSTOP )
206 Font aFont( GetFont() );
207 aFont.SetTransparent( sal_True );
208 aFont.SetWeight( WEIGHT_LIGHT );
209 aEdComment.SetFont( aFont );
210 aEdComment.SetMaxTextLen( 512 );
211 aLbScenario.SetPosPixel( Point(0,0) );
212 aLbScenario.SetHelpId(HID_SC_SCENWIN_TOP);
213 aEdComment.SetHelpId(HID_SC_SCENWIN_BOTTOM);
214 aLbScenario.Show();
215 aEdComment.Show();
217 aLbScenario.SetQuickHelpText(aQH_List);
218 aEdComment.SetQuickHelpText(aQH_Comment);
219 aEdComment.SetBackground( Color( COL_LIGHTGRAY ) );
221 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
222 if (pViewFrm)
224 SfxBindings& rBindings = pViewFrm->GetBindings();
225 rBindings.Invalidate( SID_SELECT_SCENARIO );
226 rBindings.Update( SID_SELECT_SCENARIO );
230 // -----------------------------------------------------------------------
232 ScScenarioWindow::~ScScenarioWindow()
236 void ScScenarioWindow::Paint( const Rectangle& rRect )
238 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
239 Color aBgColor = rStyleSettings.GetFaceColor();
241 SetBackground( aBgColor );
243 Window::Paint( rRect );
246 // -----------------------------------------------------------------------
248 void ScScenarioWindow::NotifyState( const SfxPoolItem* pState )
250 if( pState )
252 aLbScenario.Enable();
254 if ( pState->ISA(SfxStringItem) )
256 OUString aNewEntry( ((const SfxStringItem*)pState)->GetValue() );
258 if ( !aNewEntry.isEmpty() )
259 aLbScenario.SelectEntry( aNewEntry );
260 else
261 aLbScenario.SetNoSelection();
263 else if ( pState->ISA(SfxStringListItem) )
265 aLbScenario.UpdateEntries( ((SfxStringListItem*)pState)->GetList() );
268 else
270 aLbScenario.Disable();
271 aLbScenario.SetNoSelection();
275 // -----------------------------------------------------------------------
277 void ScScenarioWindow::SetSizePixel( const Size& rNewSize )
279 Size aSize( rNewSize );
280 long nHeight = aSize.Height() / 2;
282 Window::SetSizePixel( aSize );
284 aSize.Height() = nHeight;
285 aLbScenario.SetSizePixel( aSize );
287 aSize.Height() -= 4;
288 aEdComment.SetPosSizePixel( Point( 0, nHeight+4 ), aSize );
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */