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

Generated by: LCOV version 1.10