fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / navipi / scenwnd.cxx
blobeedca0337742ec0e0f582629de587ab65eff76fc
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 <vcl/settings.hxx>
28 #include "navipi.hxx"
29 #include "popmenu.hxx"
30 #include "scresid.hxx"
31 #include "sc.hrc"
32 #include "globstr.hrc"
34 // class ScScenarioWindow ------------------------------------------------
36 ScScenarioListBox::ScScenarioListBox( ScScenarioWindow& rParent ) :
37 ListBox( &rParent, WB_BORDER | WB_TABSTOP ),
38 mrParent( rParent )
40 vcl::Font aFont( GetFont() );
41 aFont.SetTransparent( true );
42 aFont.SetWeight( WEIGHT_LIGHT );
43 SetFont( aFont );
46 ScScenarioListBox::~ScScenarioListBox()
50 void ScScenarioListBox::UpdateEntries( const std::vector<OUString> &aNewEntryList )
52 Clear();
53 maEntries.clear();
55 switch( aNewEntryList.size() )
57 case 0:
58 // no scenarios in current sheet
59 mrParent.SetComment( EMPTY_OUSTRING );
60 break;
62 case 1:
63 // sheet is a scenario container, comment only
64 mrParent.SetComment( aNewEntryList[0] );
65 break;
67 default:
69 // sheet contains scenarios
70 OSL_ENSURE( aNewEntryList.size() % 3 == 0, "ScScenarioListBox::UpdateEntries - wrong list size" );
71 SetUpdateMode( false );
73 std::vector<OUString>::const_iterator iter;
74 for (iter = aNewEntryList.begin(); iter != aNewEntryList.end(); ++iter)
76 ScenarioEntry aEntry;
78 // first entry of a triple is the scenario name
79 aEntry.maName = *iter;
81 // second entry of a triple is the scenario comment
82 ++iter;
83 aEntry.maComment = *iter;
85 // third entry of a triple is the protection ("0" = not protected, "1" = protected)
86 ++iter;
87 aEntry.mbProtected = !(*iter).isEmpty() && (*iter)[0] != '0';
89 maEntries.push_back( aEntry );
90 InsertEntry( aEntry.maName, LISTBOX_APPEND );
92 SetUpdateMode( true );
93 SetNoSelection();
94 mrParent.SetComment( EMPTY_OUSTRING );
99 void ScScenarioListBox::Select()
101 if( const ScenarioEntry* pEntry = GetSelectedEntry() )
102 mrParent.SetComment( pEntry->maComment );
105 void ScScenarioListBox::DoubleClick()
107 SelectScenario();
110 bool ScScenarioListBox::Notify( NotifyEvent& rNEvt )
112 bool bHandled = false;
114 if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
116 vcl::KeyCode aCode = rNEvt.GetKeyEvent()->GetKeyCode();
117 switch( aCode.GetCode() )
119 case KEY_RETURN:
120 SelectScenario();
121 bHandled = true;
122 break;
123 case KEY_DELETE:
124 DeleteScenario( true );
125 bHandled = true;
126 break;
129 else if ( rNEvt.GetType() == MouseNotifyEvent::COMMAND && GetSelectEntryCount() )
131 const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
132 if ( pCEvt && pCEvt->GetCommand() == CommandEventId::ContextMenu )
134 if( const ScenarioEntry* pEntry = GetSelectedEntry() )
136 if( !pEntry->mbProtected )
138 ScPopupMenu aPopup( ScResId( RID_POPUP_NAVIPI_SCENARIO ) );
139 aPopup.Execute( this, pCEvt->GetMousePosPixel() );
140 if (aPopup.WasHit())
142 switch( aPopup.GetSelected() )
144 case RID_NAVIPI_SCENARIO_DELETE:
145 DeleteScenario( true );
146 break;
147 case RID_NAVIPI_SCENARIO_EDIT:
148 EditScenario();
149 break;
154 bHandled = true;
158 return bHandled || ListBox::Notify( rNEvt );
161 const ScScenarioListBox::ScenarioEntry* ScScenarioListBox::GetSelectedEntry() const
163 size_t nPos = GetSelectEntryPos();
164 return (nPos < maEntries.size()) ? &maEntries[ nPos ] : 0;
167 void ScScenarioListBox::ExecuteScenarioSlot( sal_uInt16 nSlotId )
169 if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
171 SfxStringItem aStringItem( nSlotId, GetSelectEntry() );
172 pViewFrm->GetDispatcher()->Execute( nSlotId, SfxCallMode::SLOT | SfxCallMode::RECORD, &aStringItem, 0L, 0L );
176 void ScScenarioListBox::SelectScenario()
178 if( GetSelectEntryCount() > 0 )
179 ExecuteScenarioSlot( SID_SELECT_SCENARIO );
182 void ScScenarioListBox::EditScenario()
184 if( GetSelectEntryCount() > 0 )
185 ExecuteScenarioSlot( SID_EDIT_SCENARIO );
188 void ScScenarioListBox::DeleteScenario( bool bQueryBox )
190 if( GetSelectEntryCount() > 0 )
191 if( !bQueryBox || (ScopedVclPtr<QueryBox>::Create( nullptr, WinBits( WB_YES_NO | WB_DEF_YES ), ScGlobal::GetRscString( STR_QUERY_DELSCENARIO ) )->Execute() == RET_YES) )
192 ExecuteScenarioSlot( SID_DELETE_SCENARIO );
195 // class ScScenarioWindow ------------------------------------------------
197 ScScenarioWindow::ScScenarioWindow( vcl::Window* pParent, const OUString& aQH_List,
198 const OUString& aQH_Comment)
199 : Window ( pParent, WB_TABSTOP | WB_DIALOGCONTROL ),
200 aLbScenario ( VclPtr<ScScenarioListBox>::Create(*this) ),
201 aEdComment ( VclPtr<MultiLineEdit>::Create(this, WB_BORDER | WB_LEFT | WB_READONLY | WB_VSCROLL | WB_TABSTOP) )
203 vcl::Font aFont( GetFont() );
204 aFont.SetTransparent( true );
205 aFont.SetWeight( WEIGHT_LIGHT );
206 aEdComment->SetFont( aFont );
207 aEdComment->SetMaxTextLen( 512 );
208 aLbScenario->SetPosPixel( Point(0,0) );
209 aLbScenario->SetHelpId(HID_SC_SCENWIN_TOP);
210 aEdComment->SetHelpId(HID_SC_SCENWIN_BOTTOM);
211 aLbScenario->Show();
212 aEdComment->Show();
214 aLbScenario->SetQuickHelpText(aQH_List);
215 aEdComment->SetQuickHelpText(aQH_Comment);
216 aEdComment->SetBackground( Color( COL_LIGHTGRAY ) );
218 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
219 if (pViewFrm)
221 SfxBindings& rBindings = pViewFrm->GetBindings();
222 rBindings.Invalidate( SID_SELECT_SCENARIO );
223 rBindings.Update( SID_SELECT_SCENARIO );
227 ScScenarioWindow::~ScScenarioWindow()
229 disposeOnce();
232 void ScScenarioWindow::dispose()
234 aLbScenario.disposeAndClear();
235 aEdComment.disposeAndClear();
236 vcl::Window::dispose();
239 void ScScenarioWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
241 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
242 Color aBgColor = rStyleSettings.GetFaceColor();
244 SetBackground( aBgColor );
246 Window::Paint(rRenderContext, rRect);
249 void ScScenarioWindow::NotifyState( const SfxPoolItem* pState )
251 if( pState )
253 aLbScenario->Enable();
255 if ( pState->ISA(SfxStringItem) )
257 OUString aNewEntry( static_cast<const SfxStringItem*>(pState)->GetValue() );
259 if ( !aNewEntry.isEmpty() )
260 aLbScenario->SelectEntry( aNewEntry );
261 else
262 aLbScenario->SetNoSelection();
264 else if ( pState->ISA(SfxStringListItem) )
266 aLbScenario->UpdateEntries( static_cast<const SfxStringListItem*>(pState)->GetList() );
269 else
271 aLbScenario->Disable();
272 aLbScenario->SetNoSelection();
276 void ScScenarioWindow::SetSizePixel( const Size& rNewSize )
278 Size aSize( rNewSize );
279 long nHeight = aSize.Height() / 2;
281 Window::SetSizePixel( aSize );
283 aSize.Height() = nHeight;
284 aLbScenario->SetSizePixel( aSize );
286 aSize.Height() -= 4;
287 aEdComment->SetPosSizePixel( Point( 0, nHeight+4 ), aSize );
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */