LCOV - code coverage report
Current view: top level - sc/source/ui/navipi - scenwnd.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 140 0.7 %
Date: 2014-11-03 Functions: 2 20 10.0 %
Legend: Lines: hit not hit

          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             : #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"
      33             : 
      34             : // class ScScenarioWindow ------------------------------------------------
      35             : 
      36           0 : ScScenarioListBox::ScScenarioListBox( ScScenarioWindow& rParent ) :
      37             :     ListBox( &rParent, WB_BORDER | WB_TABSTOP ),
      38           0 :     mrParent( rParent )
      39             : {
      40           0 :     vcl::Font aFont( GetFont() );
      41           0 :     aFont.SetTransparent( true );
      42           0 :     aFont.SetWeight( WEIGHT_LIGHT );
      43           0 :     SetFont( aFont );
      44           0 : }
      45             : 
      46           0 : ScScenarioListBox::~ScScenarioListBox()
      47             : {
      48           0 : }
      49             : 
      50           0 : void ScScenarioListBox::UpdateEntries( const std::vector<OUString> &aNewEntryList )
      51             : {
      52           0 :     Clear();
      53           0 :     maEntries.clear();
      54             : 
      55           0 :     switch( aNewEntryList.size() )
      56             :     {
      57             :         case 0:
      58             :             // no scenarios in current sheet
      59           0 :             mrParent.SetComment( EMPTY_OUSTRING );
      60           0 :         break;
      61             : 
      62             :         case 1:
      63             :             // sheet is a scenario container, comment only
      64           0 :             mrParent.SetComment( aNewEntryList[0] );
      65           0 :         break;
      66             : 
      67             :         default:
      68             :         {
      69             :             // sheet contains scenarios
      70             :             OSL_ENSURE( aNewEntryList.size() % 3 == 0, "ScScenarioListBox::UpdateEntries - wrong list size" );
      71           0 :             SetUpdateMode( false );
      72             : 
      73           0 :             std::vector<OUString>::const_iterator iter;
      74           0 :             for (iter = aNewEntryList.begin(); iter != aNewEntryList.end(); ++iter)
      75             :             {
      76           0 :                 ScenarioEntry aEntry;
      77             : 
      78             :                 // first entry of a triple is the scenario name
      79           0 :                 aEntry.maName = *iter;
      80             : 
      81             :                 // second entry of a triple is the scenario comment
      82           0 :                 ++iter;
      83           0 :                 aEntry.maComment = *iter;
      84             : 
      85             :                 // third entry of a triple is the protection ("0" = not protected, "1" = protected)
      86           0 :                 ++iter;
      87           0 :                 aEntry.mbProtected = !(*iter).isEmpty() && (*iter)[0] != '0';
      88             : 
      89           0 :                 maEntries.push_back( aEntry );
      90           0 :                 InsertEntry( aEntry.maName, LISTBOX_APPEND );
      91           0 :             }
      92           0 :             SetUpdateMode( true );
      93           0 :             SetNoSelection();
      94           0 :             mrParent.SetComment( EMPTY_OUSTRING );
      95             :         }
      96             :     }
      97           0 : }
      98             : 
      99           0 : void ScScenarioListBox::Select()
     100             : {
     101           0 :     if( const ScenarioEntry* pEntry = GetSelectedEntry() )
     102           0 :         mrParent.SetComment( pEntry->maComment );
     103           0 : }
     104             : 
     105           0 : void ScScenarioListBox::DoubleClick()
     106             : {
     107           0 :     SelectScenario();
     108           0 : }
     109             : 
     110           0 : bool ScScenarioListBox::Notify( NotifyEvent& rNEvt )
     111             : {
     112           0 :     bool bHandled = false;
     113             : 
     114           0 :     if( rNEvt.GetType() == EVENT_KEYINPUT )
     115             :     {
     116           0 :         vcl::KeyCode aCode = rNEvt.GetKeyEvent()->GetKeyCode();
     117           0 :         switch( aCode.GetCode() )
     118             :         {
     119             :             case KEY_RETURN:
     120           0 :                 SelectScenario();
     121           0 :                 bHandled = true;
     122           0 :             break;
     123             :             case KEY_DELETE:
     124           0 :                 DeleteScenario( true );
     125           0 :                 bHandled = true;
     126           0 :             break;
     127             :         }
     128             :     }
     129           0 :     else if ( rNEvt.GetType() == EVENT_COMMAND && GetSelectEntryCount() )
     130             :     {
     131           0 :         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
     132           0 :         if ( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
     133             :         {
     134           0 :             if( const ScenarioEntry* pEntry = GetSelectedEntry() )
     135             :             {
     136           0 :                 if( !pEntry->mbProtected )
     137             :                 {
     138           0 :                     ScPopupMenu aPopup( ScResId( RID_POPUP_NAVIPI_SCENARIO ) );
     139           0 :                     aPopup.Execute( this, pCEvt->GetMousePosPixel() );
     140           0 :                     if (aPopup.WasHit())
     141             :                     {
     142           0 :                         switch( aPopup.GetSelected() )
     143             :                         {
     144             :                             case RID_NAVIPI_SCENARIO_DELETE:
     145           0 :                                 DeleteScenario( true );
     146           0 :                             break;
     147             :                             case RID_NAVIPI_SCENARIO_EDIT:
     148           0 :                                 EditScenario();
     149           0 :                             break;
     150             :                         }
     151           0 :                     }
     152             :                 }
     153             :             }
     154           0 :             bHandled = true;
     155             :         }
     156             :     }
     157             : 
     158           0 :     return bHandled || ListBox::Notify( rNEvt );
     159             : }
     160             : 
     161           0 : const ScScenarioListBox::ScenarioEntry* ScScenarioListBox::GetSelectedEntry() const
     162             : {
     163           0 :     size_t nPos = GetSelectEntryPos();
     164           0 :     return (nPos < maEntries.size()) ? &maEntries[ nPos ] : 0;
     165             : }
     166             : 
     167           0 : void ScScenarioListBox::ExecuteScenarioSlot( sal_uInt16 nSlotId )
     168             : {
     169           0 :     if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
     170             :     {
     171           0 :         SfxStringItem aStringItem( nSlotId, GetSelectEntry() );
     172           0 :         pViewFrm->GetDispatcher()->Execute( nSlotId, SfxCallMode::SLOT | SfxCallMode::RECORD, &aStringItem, 0L, 0L );
     173             :     }
     174           0 : }
     175             : 
     176           0 : void ScScenarioListBox::SelectScenario()
     177             : {
     178           0 :     if( GetSelectEntryCount() > 0 )
     179           0 :         ExecuteScenarioSlot( SID_SELECT_SCENARIO );
     180           0 : }
     181             : 
     182           0 : void ScScenarioListBox::EditScenario()
     183             : {
     184           0 :     if( GetSelectEntryCount() > 0 )
     185           0 :         ExecuteScenarioSlot( SID_EDIT_SCENARIO );
     186           0 : }
     187             : 
     188           0 : void ScScenarioListBox::DeleteScenario( bool bQueryBox )
     189             : {
     190           0 :     if( GetSelectEntryCount() > 0 )
     191           0 :         if( !bQueryBox || (::QueryBox( 0, WinBits( WB_YES_NO | WB_DEF_YES ), ScGlobal::GetRscString( STR_QUERY_DELSCENARIO ) ).Execute() == RET_YES) )
     192           0 :             ExecuteScenarioSlot( SID_DELETE_SCENARIO );
     193           0 : }
     194             : 
     195             : // class ScScenarioWindow ------------------------------------------------
     196             : 
     197           0 : ScScenarioWindow::ScScenarioWindow( vcl::Window* pParent, const OUString& aQH_List,
     198             :                                     const OUString& aQH_Comment)
     199             :     :   Window      ( pParent, WB_TABSTOP | WB_DIALOGCONTROL ),
     200             :         aLbScenario ( *this ),
     201           0 :         aEdComment  ( this,  WB_BORDER | WB_LEFT | WB_READONLY | WB_VSCROLL | WB_TABSTOP )
     202             : {
     203           0 :     vcl::Font aFont( GetFont() );
     204           0 :     aFont.SetTransparent( true );
     205           0 :     aFont.SetWeight( WEIGHT_LIGHT );
     206           0 :     aEdComment.SetFont( aFont );
     207           0 :     aEdComment.SetMaxTextLen( 512 );
     208           0 :     aLbScenario.SetPosPixel( Point(0,0) );
     209           0 :     aLbScenario.SetHelpId(HID_SC_SCENWIN_TOP);
     210           0 :     aEdComment.SetHelpId(HID_SC_SCENWIN_BOTTOM);
     211           0 :     aLbScenario.Show();
     212           0 :     aEdComment.Show();
     213             : 
     214           0 :     aLbScenario.SetQuickHelpText(aQH_List);
     215           0 :     aEdComment.SetQuickHelpText(aQH_Comment);
     216           0 :     aEdComment.SetBackground( Color( COL_LIGHTGRAY ) );
     217             : 
     218           0 :     SfxViewFrame* pViewFrm = SfxViewFrame::Current();
     219           0 :     if (pViewFrm)
     220             :     {
     221           0 :         SfxBindings& rBindings = pViewFrm->GetBindings();
     222           0 :         rBindings.Invalidate( SID_SELECT_SCENARIO );
     223           0 :         rBindings.Update( SID_SELECT_SCENARIO );
     224           0 :     }
     225           0 : }
     226             : 
     227           0 : ScScenarioWindow::~ScScenarioWindow()
     228             : {
     229           0 : }
     230             : 
     231           0 : void ScScenarioWindow::Paint( const Rectangle& rRect )
     232             : {
     233           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     234           0 :     Color aBgColor = rStyleSettings.GetFaceColor();
     235             : 
     236           0 :     SetBackground( aBgColor );
     237             : 
     238           0 :     Window::Paint( rRect );
     239           0 : }
     240             : 
     241           0 : void ScScenarioWindow::NotifyState( const SfxPoolItem* pState )
     242             : {
     243           0 :     if( pState )
     244             :     {
     245           0 :         aLbScenario.Enable();
     246             : 
     247           0 :         if ( pState->ISA(SfxStringItem) )
     248             :         {
     249           0 :             OUString aNewEntry( static_cast<const SfxStringItem*>(pState)->GetValue() );
     250             : 
     251           0 :             if ( !aNewEntry.isEmpty() )
     252           0 :                 aLbScenario.SelectEntry( aNewEntry );
     253             :             else
     254           0 :                 aLbScenario.SetNoSelection();
     255             :         }
     256           0 :         else if ( pState->ISA(SfxStringListItem) )
     257             :         {
     258           0 :             aLbScenario.UpdateEntries( static_cast<const SfxStringListItem*>(pState)->GetList() );
     259             :         }
     260             :     }
     261             :     else
     262             :     {
     263           0 :         aLbScenario.Disable();
     264           0 :         aLbScenario.SetNoSelection();
     265             :     }
     266           0 : }
     267             : 
     268           0 : void ScScenarioWindow::SetSizePixel( const Size& rNewSize )
     269             : {
     270           0 :     Size aSize( rNewSize );
     271           0 :     long nHeight = aSize.Height() / 2;
     272             : 
     273           0 :     Window::SetSizePixel( aSize );
     274             : 
     275           0 :     aSize.Height() = nHeight;
     276           0 :     aLbScenario.SetSizePixel( aSize );
     277             : 
     278           0 :     aSize.Height() -= 4;
     279           0 :     aEdComment.SetPosSizePixel( Point( 0, nHeight+4 ), aSize );
     280         228 : }
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10