1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifdef _TOOLS_DEBUG_HXX 28cdf0e10cSrcweir #include <tools/debug.hxx> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #include <vcl/lstbox.hxx> 31cdf0e10cSrcweir #include <vcl/toolbox.hxx> 32cdf0e10cSrcweir #include <vcl/event.hxx> 33cdf0e10cSrcweir #include <sfx2/app.hxx> 34cdf0e10cSrcweir #include <sfx2/tbxctrl.hxx> 35cdf0e10cSrcweir #include <sfx2/bindings.hxx> 36cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 37cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 38cdf0e10cSrcweir #include <tools/gen.hxx> 39cdf0e10cSrcweir #include <svl/intitem.hxx> 40cdf0e10cSrcweir #include <svl/eitem.hxx> 41cdf0e10cSrcweir #include <svtools/stdctrl.hxx> 42cdf0e10cSrcweir #include <svl/slstitm.hxx> 43cdf0e10cSrcweir #include <svl/stritem.hxx> 44cdf0e10cSrcweir #include <svx/dialmgr.hxx> 45cdf0e10cSrcweir #include <svx/lboxctrl.hxx> 46cdf0e10cSrcweir #ifndef _VCL_MNEMONIC_HXX_ 47cdf0e10cSrcweir #include <vcl/mnemonic.hxx> 48cdf0e10cSrcweir #endif 49cdf0e10cSrcweir #include <tools/urlobj.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include <svx/svxids.hrc> 52cdf0e10cSrcweir #include <svx/dialogs.hrc> 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include "lboxctrl.hrc" 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir using namespace ::com::sun::star::uno; 58cdf0e10cSrcweir using namespace ::com::sun::star::beans; 59cdf0e10cSrcweir using namespace ::com::sun::star::frame; 60cdf0e10cSrcweir 61cdf0e10cSrcweir class SvxPopupWindowListBox; 62cdf0e10cSrcweir 63cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 64cdf0e10cSrcweir 65cdf0e10cSrcweir class SvxPopupWindowListBox : public SfxPopupWindow 66cdf0e10cSrcweir { 67cdf0e10cSrcweir using FloatingWindow::StateChanged; 68cdf0e10cSrcweir 69cdf0e10cSrcweir FixedInfo aInfo; 70cdf0e10cSrcweir ListBox * pListBox; 71cdf0e10cSrcweir ToolBox & rToolBox; 72cdf0e10cSrcweir sal_Bool bUserSel; 73cdf0e10cSrcweir sal_uInt16 nTbxId; 74cdf0e10cSrcweir rtl::OUString maCommandURL; 75cdf0e10cSrcweir // disallow copy-constructor and assignment-operator 76cdf0e10cSrcweir 77cdf0e10cSrcweir SvxPopupWindowListBox(const int& ); 78cdf0e10cSrcweir SvxPopupWindowListBox & operator = (const int& ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir // SvxPopupWindowListBox( sal_uInt16 nSlotId, ToolBox& rTbx, sal_uInt16 nTbxItemId ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir public: 83cdf0e10cSrcweir SvxPopupWindowListBox( sal_uInt16 nSlotId, const rtl::OUString& rCommandURL, sal_uInt16 nTbxId, ToolBox& rTbx ); 84cdf0e10cSrcweir virtual ~SvxPopupWindowListBox(); 85cdf0e10cSrcweir 86cdf0e10cSrcweir // SfxPopupWindow 87cdf0e10cSrcweir virtual SfxPopupWindow * Clone() const; 88cdf0e10cSrcweir virtual void PopupModeEnd(); 89cdf0e10cSrcweir virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, 90cdf0e10cSrcweir const SfxPoolItem* pState ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir void StartSelection(); 93cdf0e10cSrcweir inline ListBox & GetListBox() { return *pListBox; } 94cdf0e10cSrcweir inline FixedInfo & GetInfo() { return aInfo; } 95cdf0e10cSrcweir 96cdf0e10cSrcweir sal_Bool IsUserSelected() const { return bUserSel; } 97cdf0e10cSrcweir void SetUserSelected( sal_Bool bVal ) { bUserSel = bVal; } 98cdf0e10cSrcweir /*virtual*/Window* GetPreferredKeyInputWindow(); 99cdf0e10cSrcweir }; 100cdf0e10cSrcweir 101cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 102cdf0e10cSrcweir 103cdf0e10cSrcweir SvxPopupWindowListBox::SvxPopupWindowListBox( sal_uInt16 nSlotId, const rtl::OUString& rCommandURL, sal_uInt16 nId, ToolBox& rTbx ) : 104cdf0e10cSrcweir SfxPopupWindow( nSlotId, Reference< XFrame >(), SVX_RES( RID_SVXTBX_UNDO_REDO_CTRL ) ), 105cdf0e10cSrcweir aInfo ( this, SVX_RES( FT_NUM_OPERATIONS ) ), 106cdf0e10cSrcweir rToolBox ( rTbx ), 107cdf0e10cSrcweir bUserSel ( sal_False ), 108cdf0e10cSrcweir nTbxId ( nId ), 109cdf0e10cSrcweir maCommandURL( rCommandURL ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir DBG_ASSERT( nSlotId == GetId(), "id mismatch" ); 112cdf0e10cSrcweir pListBox = new ListBox( this, SVX_RES( LB_SVXTBX_UNDO_REDO_CTRL ) ); 113cdf0e10cSrcweir FreeResource(); 114cdf0e10cSrcweir pListBox->EnableMultiSelection( sal_True, sal_True ); 115cdf0e10cSrcweir SetBackground( GetSettings().GetStyleSettings().GetDialogColor() ); 116cdf0e10cSrcweir AddStatusListener( rCommandURL ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir 120cdf0e10cSrcweir SvxPopupWindowListBox::~SvxPopupWindowListBox() 121cdf0e10cSrcweir { 122cdf0e10cSrcweir delete pListBox; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir 126cdf0e10cSrcweir SfxPopupWindow* SvxPopupWindowListBox::Clone() const 127cdf0e10cSrcweir { 128cdf0e10cSrcweir return new SvxPopupWindowListBox( GetId(), maCommandURL, nTbxId, rToolBox ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir 132cdf0e10cSrcweir void SvxPopupWindowListBox::PopupModeEnd() 133cdf0e10cSrcweir { 134cdf0e10cSrcweir rToolBox.EndSelection(); 135cdf0e10cSrcweir SfxPopupWindow::PopupModeEnd(); 136cdf0e10cSrcweir //FloatingWindow::PopupModeEnd(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir if( SfxViewShell::Current() ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir Window* pShellWnd = SfxViewShell::Current()->GetWindow(); 141cdf0e10cSrcweir if (pShellWnd) 142cdf0e10cSrcweir pShellWnd->GrabFocus(); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir 147cdf0e10cSrcweir void SvxPopupWindowListBox::StateChanged( 148cdf0e10cSrcweir sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir rToolBox.EnableItem( nTbxId, ( SfxToolBoxControl::GetItemState( pState ) != SFX_ITEM_DISABLED) ); 151cdf0e10cSrcweir SfxPopupWindow::StateChanged( nSID, eState, pState ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir 155cdf0e10cSrcweir void SvxPopupWindowListBox::StartSelection() 156cdf0e10cSrcweir { 157cdf0e10cSrcweir rToolBox.StartSelection(); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir Window* SvxPopupWindowListBox::GetPreferredKeyInputWindow() 161cdf0e10cSrcweir { 162cdf0e10cSrcweir // allows forwarding key events in the correct window 163cdf0e10cSrcweir // without setting the focus 164cdf0e10cSrcweir return pListBox->GetPreferredKeyInputWindow(); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 168cdf0e10cSrcweir 169cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( SvxListBoxControl, SfxStringItem ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir SvxListBoxControl::SvxListBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 173cdf0e10cSrcweir :SfxToolBoxControl( nSlotId, nId, rTbx ), 174cdf0e10cSrcweir pPopupWin ( 0 ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 177cdf0e10cSrcweir rTbx.Invalidate(); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir 181cdf0e10cSrcweir SvxListBoxControl::~SvxListBoxControl() 182cdf0e10cSrcweir { 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir SfxPopupWindow* SvxListBoxControl::CreatePopupWindow() 187cdf0e10cSrcweir { 188cdf0e10cSrcweir DBG_ERROR( "not implemented" ); 189cdf0e10cSrcweir return 0; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir 193cdf0e10cSrcweir SfxPopupWindowType SvxListBoxControl::GetPopupWindowType() const 194cdf0e10cSrcweir { 195cdf0e10cSrcweir return SFX_POPUPWINDOW_ONTIMEOUT; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir 199cdf0e10cSrcweir void SvxListBoxControl::StateChanged( 200cdf0e10cSrcweir sal_uInt16, SfxItemState, const SfxPoolItem* pState ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir GetToolBox().EnableItem( GetId(), 203cdf0e10cSrcweir SFX_ITEM_DISABLED != GetItemState(pState) ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir 207cdf0e10cSrcweir IMPL_LINK( SvxListBoxControl, PopupModeEndHdl, void *, EMPTYARG ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir if( pPopupWin && 0 == pPopupWin->GetPopupModeFlags() && 210cdf0e10cSrcweir pPopupWin->IsUserSelected() ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir sal_uInt16 nCount = pPopupWin->GetListBox().GetSelectEntryCount(); 213cdf0e10cSrcweir 214cdf0e10cSrcweir INetURLObject aObj( m_aCommandURL ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir Sequence< PropertyValue > aArgs( 1 ); 217cdf0e10cSrcweir aArgs[0].Name = aObj.GetURLPath(); 218cdf0e10cSrcweir aArgs[0].Value = makeAny( sal_Int16( nCount )); 219cdf0e10cSrcweir SfxToolBoxControl::Dispatch( m_aCommandURL, aArgs ); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir return 0; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir void SvxListBoxControl::Impl_SetInfo( sal_uInt16 nCount ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir // ListBox &rListBox = pPopupWin->GetListBox(); 230cdf0e10cSrcweir 231cdf0e10cSrcweir sal_uInt16 nId; 232cdf0e10cSrcweir if (nCount == 1) 233cdf0e10cSrcweir nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTION : RID_SVXSTR_NUM_REDO_ACTION; 234cdf0e10cSrcweir else 235cdf0e10cSrcweir nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS; 236cdf0e10cSrcweir 237cdf0e10cSrcweir aActionStr = String(SVX_RES(nId)); 238cdf0e10cSrcweir 239cdf0e10cSrcweir String aText( aActionStr ); 240cdf0e10cSrcweir aText.SearchAndReplaceAllAscii( "$(ARG1)", String::CreateFromInt32( nCount ) ); 241cdf0e10cSrcweir pPopupWin->GetInfo().SetText( aText ); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir 245cdf0e10cSrcweir IMPL_LINK( SvxListBoxControl, SelectHdl, void *, EMPTYARG ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir if (pPopupWin) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir //pPopupWin->SetUserSelected( sal_False ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir ListBox &rListBox = pPopupWin->GetListBox(); 252cdf0e10cSrcweir if (rListBox.IsTravelSelect()) 253cdf0e10cSrcweir Impl_SetInfo( rListBox.GetSelectEntryCount() ); 254cdf0e10cSrcweir else 255cdf0e10cSrcweir { 256cdf0e10cSrcweir pPopupWin->SetUserSelected( sal_True ); 257cdf0e10cSrcweir pPopupWin->EndPopupMode( 0 ); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir return 0; 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 264cdf0e10cSrcweir 265cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem ); 266cdf0e10cSrcweir 267cdf0e10cSrcweir SvxUndoRedoControl::SvxUndoRedoControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 268cdf0e10cSrcweir : SvxListBoxControl( nSlotId, nId, rTbx ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 271cdf0e10cSrcweir rTbx.Invalidate(); 272cdf0e10cSrcweir aDefaultText = MnemonicGenerator::EraseAllMnemonicChars( rTbx.GetItemText( nId ) ); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir SvxUndoRedoControl::~SvxUndoRedoControl() 276cdf0e10cSrcweir { 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir void SvxUndoRedoControl::StateChanged( 280cdf0e10cSrcweir sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir if ( nSID == SID_UNDO || nSID == SID_REDO ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir if ( eState == SFX_ITEM_DISABLED ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir ToolBox& rBox = GetToolBox(); 287cdf0e10cSrcweir rBox.SetQuickHelpText( GetId(), aDefaultText ); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir else if ( pState && pState->ISA( SfxStringItem ) ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir SfxStringItem& rItem = *(SfxStringItem *)pState; 292cdf0e10cSrcweir ToolBox& rBox = GetToolBox(); 293cdf0e10cSrcweir String aQuickHelpText = MnemonicGenerator::EraseAllMnemonicChars( rItem.GetValue() ); 294cdf0e10cSrcweir rBox.SetQuickHelpText( GetId(), aQuickHelpText ); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir SvxListBoxControl::StateChanged( nSID, eState, pState ); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir else 299cdf0e10cSrcweir { 300cdf0e10cSrcweir aUndoRedoList.clear(); 301cdf0e10cSrcweir 302cdf0e10cSrcweir if ( pState && pState->ISA( SfxStringListItem ) ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir SfxStringListItem &rItem = *(SfxStringListItem *)pState; 305cdf0e10cSrcweir const List* pLst = rItem.GetList(); 306cdf0e10cSrcweir DBG_ASSERT( pLst, "no undo actions available" ); 307cdf0e10cSrcweir if ( pLst ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir for( long nI = 0, nEnd = pLst->Count(); nI < nEnd; ++nI ) 310cdf0e10cSrcweir aUndoRedoList.push_back( rtl::OUString( *(String *)pLst->GetObject( nI ))); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir SfxPopupWindow* SvxUndoRedoControl::CreatePopupWindow() 317cdf0e10cSrcweir { 318cdf0e10cSrcweir DBG_ASSERT(( SID_UNDO == GetSlotId() || SID_REDO == GetSlotId() ), "mismatching ids" ); 319cdf0e10cSrcweir 320cdf0e10cSrcweir if ( m_aCommandURL.equalsAscii( ".uno:Undo" )) 321cdf0e10cSrcweir updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GetUndoStrings" ))); 322cdf0e10cSrcweir else 323cdf0e10cSrcweir updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GetRedoStrings" ))); 324cdf0e10cSrcweir 325cdf0e10cSrcweir ToolBox& rBox = GetToolBox(); 326cdf0e10cSrcweir 327cdf0e10cSrcweir pPopupWin = new SvxPopupWindowListBox( GetSlotId(), m_aCommandURL, GetId(), rBox ); 328cdf0e10cSrcweir pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl, 329cdf0e10cSrcweir PopupModeEndHdl ) ); 330cdf0e10cSrcweir ListBox &rListBox = pPopupWin->GetListBox(); 331cdf0e10cSrcweir rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) ); 332cdf0e10cSrcweir 333cdf0e10cSrcweir for( sal_uInt32 n = 0; n < aUndoRedoList.size(); n++ ) 334cdf0e10cSrcweir rListBox.InsertEntry( String( aUndoRedoList[n] )); 335cdf0e10cSrcweir 336cdf0e10cSrcweir rListBox.SelectEntryPos( 0 ); 337cdf0e10cSrcweir aActionStr = String( SVX_RES( SID_UNDO == GetSlotId() ? 338cdf0e10cSrcweir RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS ) ); 339cdf0e10cSrcweir Impl_SetInfo( rListBox.GetSelectEntryCount() ); 340cdf0e10cSrcweir 341cdf0e10cSrcweir // move focus in floating window without 342cdf0e10cSrcweir // closing it (GrabFocus() would close it!) 343cdf0e10cSrcweir pPopupWin->StartPopupMode( &rBox, FLOATWIN_POPUPMODE_GRABFOCUS ); 344cdf0e10cSrcweir //pPopupWin->GetListBox().GrabFocus(); 345cdf0e10cSrcweir 346cdf0e10cSrcweir return pPopupWin; 347cdf0e10cSrcweir } 348