LCOV - code coverage report
Current view: top level - svx/source/tbxctrls - lboxctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 126 26.2 %
Date: 2015-06-13 12:38:46 Functions: 11 31 35.5 %
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 <sal/config.h>
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include <tools/debug.hxx>
      24             : #include <sal/types.h>
      25             : #include <vcl/lstbox.hxx>
      26             : #include <vcl/toolbox.hxx>
      27             : #include <vcl/event.hxx>
      28             : #include <sfx2/app.hxx>
      29             : #include <sfx2/tbxctrl.hxx>
      30             : #include <sfx2/bindings.hxx>
      31             : #include <sfx2/dispatch.hxx>
      32             : #include <sfx2/viewsh.hxx>
      33             : #include <svl/intitem.hxx>
      34             : #include <svl/eitem.hxx>
      35             : #include <svtools/stdctrl.hxx>
      36             : #include <svl/slstitm.hxx>
      37             : #include <svl/stritem.hxx>
      38             : #include <svx/dialmgr.hxx>
      39             : #include <svx/lboxctrl.hxx>
      40             : #include <vcl/mnemonic.hxx>
      41             : #include <vcl/settings.hxx>
      42             : #include <tools/urlobj.hxx>
      43             : 
      44             : #include <svx/svxids.hrc>
      45             : #include <svx/dialogs.hrc>
      46             : 
      47             : using namespace ::com::sun::star::uno;
      48             : using namespace ::com::sun::star::beans;
      49             : using namespace ::com::sun::star::frame;
      50             : 
      51             : class SvxPopupWindowListBox;
      52             : 
      53             : class SvxPopupWindowListBox: public SfxPopupWindow
      54             : {
      55             :     using FloatingWindow::StateChanged;
      56             : 
      57             :     VclPtr<ListBox> m_pListBox;
      58             :     ToolBox &       rToolBox;
      59             :     bool            bUserSel;
      60             :     sal_uInt16      nTbxId;
      61             :     OUString        maCommandURL;
      62             : 
      63             : public:
      64             :     SvxPopupWindowListBox( sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nTbxId, ToolBox& rTbx );
      65             :     virtual ~SvxPopupWindowListBox();
      66             :     virtual void dispose() SAL_OVERRIDE;
      67             : 
      68             :     // SfxPopupWindow
      69             :     virtual VclPtr<SfxPopupWindow> Clone() const SAL_OVERRIDE;
      70             :     virtual void                PopupModeEnd() SAL_OVERRIDE;
      71             :     virtual void                StateChanged( sal_uInt16 nSID, SfxItemState eState,
      72             :                                               const SfxPoolItem* pState ) SAL_OVERRIDE;
      73             : 
      74           0 :     inline ListBox &            GetListBox()    { return *m_pListBox; }
      75             : 
      76           0 :     bool                        IsUserSelected() const          { return bUserSel; }
      77           0 :     void                        SetUserSelected( bool bVal )    { bUserSel = bVal; }
      78             :     virtual vcl::Window*             GetPreferredKeyInputWindow() SAL_OVERRIDE;
      79             : };
      80             : 
      81           0 : SvxPopupWindowListBox::SvxPopupWindowListBox(sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nId, ToolBox& rTbx)
      82             :     : SfxPopupWindow(nSlotId, "FloatingUndoRedo", "svx/ui/floatingundoredo.ui")
      83             :     , rToolBox(rTbx)
      84             :     , bUserSel(false)
      85             :     , nTbxId(nId)
      86           0 :     , maCommandURL(rCommandURL)
      87             : {
      88             :     DBG_ASSERT( nSlotId == GetId(), "id mismatch" );
      89           0 :     get(m_pListBox, "treeview");
      90           0 :     WinBits nBits(m_pListBox->GetStyle());
      91           0 :     nBits &= ~(WB_SIMPLEMODE);
      92           0 :     m_pListBox->SetStyle(nBits);
      93           0 :     Size aSize(LogicToPixel(Size(100, 85), MAP_APPFONT));
      94           0 :     m_pListBox->set_width_request(aSize.Width());
      95           0 :     m_pListBox->set_height_request(aSize.Height());
      96           0 :     m_pListBox->EnableMultiSelection( true, true );
      97           0 :     SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
      98           0 :     AddStatusListener( rCommandURL );
      99           0 : }
     100             : 
     101           0 : SvxPopupWindowListBox::~SvxPopupWindowListBox()
     102             : {
     103           0 :     disposeOnce();
     104           0 : }
     105             : 
     106           0 : void SvxPopupWindowListBox::dispose()
     107             : {
     108           0 :     m_pListBox.clear();
     109           0 :     SfxPopupWindow::dispose();
     110           0 : }
     111             : 
     112           0 : VclPtr<SfxPopupWindow> SvxPopupWindowListBox::Clone() const
     113             : {
     114           0 :     return VclPtr<SvxPopupWindowListBox>::Create( GetId(), maCommandURL, nTbxId, rToolBox );
     115             : }
     116             : 
     117           0 : void SvxPopupWindowListBox::PopupModeEnd()
     118             : {
     119           0 :     rToolBox.EndSelection();
     120           0 :     SfxPopupWindow::PopupModeEnd();
     121             :     //FloatingWindow::PopupModeEnd();
     122             : 
     123           0 :     if( SfxViewShell::Current() )
     124             :     {
     125           0 :         vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
     126           0 :         if (pShellWnd)
     127           0 :             pShellWnd->GrabFocus();
     128             :     }
     129           0 : }
     130             : 
     131             : 
     132           0 : void SvxPopupWindowListBox::StateChanged(
     133             :         sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
     134             : {
     135           0 :     rToolBox.EnableItem( nTbxId, ( SfxToolBoxControl::GetItemState( pState ) != SfxItemState::DISABLED) );
     136           0 :     SfxPopupWindow::StateChanged( nSID, eState, pState );
     137           0 : }
     138             : 
     139           0 : vcl::Window* SvxPopupWindowListBox::GetPreferredKeyInputWindow()
     140             : {
     141             :     // allows forwarding key events in the correct window
     142             :     // without setting the focus
     143           0 :     return m_pListBox->GetPreferredKeyInputWindow();
     144             : }
     145             : 
     146        1176 : SvxListBoxControl::SvxListBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
     147             :     :SfxToolBoxControl( nSlotId, nId, rTbx ),
     148        1176 :     pPopupWin   ( 0 )
     149             : {
     150        1176 :     rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
     151        1176 :     rTbx.Invalidate();
     152        1176 : }
     153             : 
     154             : 
     155        1176 : SvxListBoxControl::~SvxListBoxControl()
     156        1176 : {}
     157             : 
     158           0 : VclPtr<SfxPopupWindow> SvxListBoxControl::CreatePopupWindow()
     159             : {
     160             :     OSL_FAIL( "not implemented" );
     161           0 :     return 0;
     162             : }
     163             : 
     164             : 
     165           0 : SfxPopupWindowType SvxListBoxControl::GetPopupWindowType() const
     166             : {
     167           0 :     return SfxPopupWindowType::ONTIMEOUT;
     168             : }
     169             : 
     170             : 
     171        2150 : void SvxListBoxControl::StateChanged(
     172             :         sal_uInt16, SfxItemState, const SfxPoolItem* pState )
     173             : {
     174        4300 :     GetToolBox().EnableItem( GetId(),
     175        6450 :                             SfxItemState::DISABLED != GetItemState(pState) );
     176        2150 : }
     177             : 
     178             : 
     179           0 : IMPL_LINK_NOARG(SvxListBoxControl, PopupModeEndHdl)
     180             : {
     181           0 :     if( pPopupWin && FloatWinPopupFlags::NONE == pPopupWin->GetPopupModeFlags()  &&
     182           0 :         pPopupWin->IsUserSelected() )
     183             :     {
     184           0 :         sal_uInt16 nCount = pPopupWin->GetListBox().GetSelectEntryCount();
     185             : 
     186           0 :         INetURLObject aObj( m_aCommandURL );
     187             : 
     188           0 :         Sequence< PropertyValue > aArgs( 1 );
     189           0 :         aArgs[0].Name   = aObj.GetURLPath();
     190           0 :         aArgs[0].Value  = makeAny( sal_Int16( nCount ));
     191           0 :         SfxToolBoxControl::Dispatch( m_aCommandURL, aArgs );
     192             :     }
     193           0 :     return 0;
     194             : }
     195             : 
     196             : 
     197           0 : void SvxListBoxControl::Impl_SetInfo( sal_uInt16 nCount )
     198             : {
     199             :     DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" );
     200             : 
     201             : //    ListBox &rListBox = pPopupWin->GetListBox();
     202             : 
     203             :     sal_uInt16 nId;
     204           0 :     if (nCount == 1)
     205           0 :         nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTION : RID_SVXSTR_NUM_REDO_ACTION;
     206             :     else
     207           0 :         nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS;
     208             : 
     209           0 :     aActionStr = SVX_RESSTR(nId);
     210             : 
     211           0 :     OUString aText = aActionStr.replaceAll("$(ARG1)", OUString::number(nCount));
     212           0 :     pPopupWin->SetText(aText);
     213           0 : }
     214             : 
     215             : 
     216           0 : IMPL_LINK_NOARG(SvxListBoxControl, SelectHdl)
     217             : {
     218           0 :     if (pPopupWin)
     219             :     {
     220             :         //pPopupWin->SetUserSelected( false );
     221             : 
     222           0 :         ListBox &rListBox = pPopupWin->GetListBox();
     223           0 :         if (rListBox.IsTravelSelect())
     224           0 :             Impl_SetInfo( rListBox.GetSelectEntryCount() );
     225             :         else
     226             :         {
     227           0 :             pPopupWin->SetUserSelected( true );
     228           0 :             pPopupWin->EndPopupMode();
     229             :         }
     230             :     }
     231           0 :     return 0;
     232             : }
     233             : 
     234             : 
     235             : 
     236        1468 : SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem );
     237             : 
     238        1176 : SvxUndoRedoControl::SvxUndoRedoControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
     239        1176 :     : SvxListBoxControl( nSlotId, nId, rTbx )
     240             : {
     241        1176 :     rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
     242        1176 :     rTbx.Invalidate();
     243        1176 :     aDefaultText = MnemonicGenerator::EraseAllMnemonicChars( rTbx.GetItemText( nId ) );
     244        1176 : }
     245             : 
     246        2352 : SvxUndoRedoControl::~SvxUndoRedoControl()
     247             : {
     248        2352 : }
     249             : 
     250        2150 : void SvxUndoRedoControl::StateChanged(
     251             :     sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
     252             : {
     253        2150 :     if ( nSID == SID_UNDO || nSID == SID_REDO )
     254             :     {
     255        2150 :         if ( eState == SfxItemState::DISABLED )
     256             :         {
     257        1718 :             ToolBox& rBox = GetToolBox();
     258        1718 :             rBox.SetQuickHelpText( GetId(), aDefaultText );
     259             :         }
     260         432 :         else if ( pState && pState->ISA( SfxStringItem ) )
     261             :         {
     262         432 :             const SfxStringItem& rItem = *static_cast<const SfxStringItem *>(pState);
     263         432 :             ToolBox& rBox = GetToolBox();
     264         432 :             OUString aQuickHelpText = MnemonicGenerator::EraseAllMnemonicChars( rItem.GetValue() );
     265         432 :             rBox.SetQuickHelpText( GetId(), aQuickHelpText );
     266             :         }
     267        2150 :         SvxListBoxControl::StateChanged( nSID, eState, pState );
     268             :     }
     269             :     else
     270             :     {
     271           0 :         aUndoRedoList.clear();
     272             : 
     273           0 :         if ( pState && pState->ISA( SfxStringListItem ) )
     274             :         {
     275           0 :             const SfxStringListItem &rItem = *static_cast<const SfxStringListItem *>(pState);
     276             : 
     277           0 :             const std::vector<OUString> &aLst = rItem.GetList();
     278           0 :             for( long nI = 0, nEnd = aLst.size(); nI < nEnd; ++nI )
     279           0 :                 aUndoRedoList.push_back( aLst[nI] );
     280             :         }
     281             :     }
     282        2150 : }
     283             : 
     284           0 : VclPtr<SfxPopupWindow> SvxUndoRedoControl::CreatePopupWindow()
     285             : {
     286             :     DBG_ASSERT(( SID_UNDO == GetSlotId() || SID_REDO == GetSlotId() ), "mismatching ids" );
     287             : 
     288           0 :     if ( m_aCommandURL == ".uno:Undo" )
     289           0 :         updateStatus( OUString( ".uno:GetUndoStrings" ));
     290             :     else
     291           0 :         updateStatus( OUString( ".uno:GetRedoStrings" ));
     292             : 
     293           0 :     ToolBox& rBox = GetToolBox();
     294             : 
     295           0 :     pPopupWin = VclPtr<SvxPopupWindowListBox>::Create( GetSlotId(), m_aCommandURL, GetId(), rBox );
     296           0 :     pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl,
     297           0 :                                             PopupModeEndHdl ) );
     298           0 :     ListBox &rListBox = pPopupWin->GetListBox();
     299           0 :     rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) );
     300             : 
     301           0 :     for( size_t n = 0; n < aUndoRedoList.size(); n++ )
     302           0 :         rListBox.InsertEntry( aUndoRedoList[n] );
     303             : 
     304           0 :     rListBox.SelectEntryPos( 0 );
     305           0 :     aActionStr = SVX_RESSTR(SID_UNDO == GetSlotId() ?
     306           0 :                                   RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS);
     307           0 :     Impl_SetInfo( rListBox.GetSelectEntryCount() );
     308             : 
     309             :     // move focus in floating window without
     310             :     // closing it (GrabFocus() would close it!)
     311           0 :     pPopupWin->StartPopupMode( &rBox, FloatWinPopupFlags::GrabFocus );
     312             :     //pPopupWin->GetListBox().GrabFocus();
     313             : 
     314           0 :     return pPopupWin;
     315         390 : }
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11