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

Generated by: LCOV version 1.10