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

Generated by: LCOV version 1.10