update credits
[LibreOffice.git] / svx / source / tbxctrls / lboxctrl.cxx
blobab150fa45deb64f8f8c8b0bc9a9a1924c07e29ff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #ifdef _TOOLS_DEBUG_HXX
22 #include <tools/debug.hxx>
23 #endif
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 <tools/urlobj.hxx>
43 #include <svx/svxids.hrc>
44 #include <svx/dialogs.hrc>
46 #include "lboxctrl.hrc"
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::frame;
53 class SvxPopupWindowListBox;
55 /////////////////////////////////////////////////////////////////
57 class SvxPopupWindowListBox : public SfxPopupWindow
59 using FloatingWindow::StateChanged;
61 ListBox * pListBox;
62 ToolBox & rToolBox;
63 bool bUserSel;
64 sal_uInt16 nTbxId;
65 OUString maCommandURL;
66 // disallow copy-constructor and assignment-operator
68 SvxPopupWindowListBox(const int& );
69 SvxPopupWindowListBox & operator = (const int& );
71 // SvxPopupWindowListBox( sal_uInt16 nSlotId, ToolBox& rTbx, sal_uInt16 nTbxItemId );
73 public:
74 SvxPopupWindowListBox( sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nTbxId, ToolBox& rTbx );
75 virtual ~SvxPopupWindowListBox();
77 // SfxPopupWindow
78 virtual SfxPopupWindow * Clone() const;
79 virtual void PopupModeEnd();
80 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
81 const SfxPoolItem* pState );
83 inline ListBox & GetListBox() { return *pListBox; }
85 bool IsUserSelected() const { return bUserSel; }
86 void SetUserSelected( bool bVal ) { bUserSel = bVal; }
87 /*virtual*/Window* GetPreferredKeyInputWindow();
90 /////////////////////////////////////////////////////////////////
92 SvxPopupWindowListBox::SvxPopupWindowListBox( sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nId, ToolBox& rTbx ) :
93 SfxPopupWindow( nSlotId, Reference< XFrame >(), SVX_RES( RID_SVXTBX_UNDO_REDO_CTRL ) ),
94 rToolBox ( rTbx ),
95 bUserSel ( false ),
96 nTbxId ( nId ),
97 maCommandURL( rCommandURL )
99 DBG_ASSERT( nSlotId == GetId(), "id mismatch" );
100 pListBox = new ListBox( this, SVX_RES( LB_SVXTBX_UNDO_REDO_CTRL ) );
101 FreeResource();
102 pListBox->EnableMultiSelection( sal_True, sal_True );
103 SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
104 AddStatusListener( rCommandURL );
108 SvxPopupWindowListBox::~SvxPopupWindowListBox()
110 delete pListBox;
114 SfxPopupWindow* SvxPopupWindowListBox::Clone() const
116 return new SvxPopupWindowListBox( GetId(), maCommandURL, nTbxId, rToolBox );
120 void SvxPopupWindowListBox::PopupModeEnd()
122 rToolBox.EndSelection();
123 SfxPopupWindow::PopupModeEnd();
124 //FloatingWindow::PopupModeEnd();
126 if( SfxViewShell::Current() )
128 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
129 if (pShellWnd)
130 pShellWnd->GrabFocus();
135 void SvxPopupWindowListBox::StateChanged(
136 sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
138 rToolBox.EnableItem( nTbxId, ( SfxToolBoxControl::GetItemState( pState ) != SFX_ITEM_DISABLED) );
139 SfxPopupWindow::StateChanged( nSID, eState, pState );
142 Window* SvxPopupWindowListBox::GetPreferredKeyInputWindow()
144 // allows forwarding key events in the correct window
145 // without setting the focus
146 return pListBox->GetPreferredKeyInputWindow();
149 /////////////////////////////////////////////////////////////////
151 SvxListBoxControl::SvxListBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
152 :SfxToolBoxControl( nSlotId, nId, rTbx ),
153 pPopupWin ( 0 )
155 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
156 rTbx.Invalidate();
160 SvxListBoxControl::~SvxListBoxControl()
165 SfxPopupWindow* SvxListBoxControl::CreatePopupWindow()
167 OSL_FAIL( "not implemented" );
168 return 0;
172 SfxPopupWindowType SvxListBoxControl::GetPopupWindowType() const
174 return SFX_POPUPWINDOW_ONTIMEOUT;
178 void SvxListBoxControl::StateChanged(
179 sal_uInt16, SfxItemState, const SfxPoolItem* pState )
181 GetToolBox().EnableItem( GetId(),
182 SFX_ITEM_DISABLED != GetItemState(pState) );
186 IMPL_LINK_NOARG(SvxListBoxControl, PopupModeEndHdl)
188 if( pPopupWin && 0 == pPopupWin->GetPopupModeFlags() &&
189 pPopupWin->IsUserSelected() )
191 sal_uInt16 nCount = pPopupWin->GetListBox().GetSelectEntryCount();
193 INetURLObject aObj( m_aCommandURL );
195 Sequence< PropertyValue > aArgs( 1 );
196 aArgs[0].Name = aObj.GetURLPath();
197 aArgs[0].Value = makeAny( sal_Int16( nCount ));
198 SfxToolBoxControl::Dispatch( m_aCommandURL, aArgs );
200 return 0;
204 void SvxListBoxControl::Impl_SetInfo( sal_uInt16 nCount )
206 DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" );
208 // ListBox &rListBox = pPopupWin->GetListBox();
210 sal_uInt16 nId;
211 if (nCount == 1)
212 nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTION : RID_SVXSTR_NUM_REDO_ACTION;
213 else
214 nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS;
216 aActionStr = String(SVX_RES(nId));
218 String aText( aActionStr );
219 aText.SearchAndReplaceAllAscii( "$(ARG1)", OUString::number( nCount ) );
220 pPopupWin->SetText( aText );
224 IMPL_LINK_NOARG(SvxListBoxControl, SelectHdl)
226 if (pPopupWin)
228 //pPopupWin->SetUserSelected( false );
230 ListBox &rListBox = pPopupWin->GetListBox();
231 if (rListBox.IsTravelSelect())
232 Impl_SetInfo( rListBox.GetSelectEntryCount() );
233 else
235 pPopupWin->SetUserSelected( true );
236 pPopupWin->EndPopupMode( 0 );
239 return 0;
242 /////////////////////////////////////////////////////////////////
244 SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem );
246 SvxUndoRedoControl::SvxUndoRedoControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
247 : SvxListBoxControl( nSlotId, nId, rTbx )
249 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
250 rTbx.Invalidate();
251 aDefaultText = MnemonicGenerator::EraseAllMnemonicChars( rTbx.GetItemText( nId ) );
254 SvxUndoRedoControl::~SvxUndoRedoControl()
258 void SvxUndoRedoControl::StateChanged(
259 sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
261 if ( nSID == SID_UNDO || nSID == SID_REDO )
263 if ( eState == SFX_ITEM_DISABLED )
265 ToolBox& rBox = GetToolBox();
266 rBox.SetQuickHelpText( GetId(), aDefaultText );
268 else if ( pState && pState->ISA( SfxStringItem ) )
270 SfxStringItem& rItem = *(SfxStringItem *)pState;
271 ToolBox& rBox = GetToolBox();
272 String aQuickHelpText = MnemonicGenerator::EraseAllMnemonicChars( rItem.GetValue() );
273 rBox.SetQuickHelpText( GetId(), aQuickHelpText );
275 SvxListBoxControl::StateChanged( nSID, eState, pState );
277 else
279 aUndoRedoList.clear();
281 if ( pState && pState->ISA( SfxStringListItem ) )
283 SfxStringListItem &rItem = *(SfxStringListItem *)pState;
285 const std::vector<String> &aLst = rItem.GetList();
286 for( long nI = 0, nEnd = aLst.size(); nI < nEnd; ++nI )
287 aUndoRedoList.push_back( OUString( aLst[nI] ));
292 SfxPopupWindow* SvxUndoRedoControl::CreatePopupWindow()
294 DBG_ASSERT(( SID_UNDO == GetSlotId() || SID_REDO == GetSlotId() ), "mismatching ids" );
296 if ( m_aCommandURL == ".uno:Undo" )
297 updateStatus( OUString( ".uno:GetUndoStrings" ));
298 else
299 updateStatus( OUString( ".uno:GetRedoStrings" ));
301 ToolBox& rBox = GetToolBox();
303 pPopupWin = new SvxPopupWindowListBox( GetSlotId(), m_aCommandURL, GetId(), rBox );
304 pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl,
305 PopupModeEndHdl ) );
306 ListBox &rListBox = pPopupWin->GetListBox();
307 rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) );
309 for( sal_uInt32 n = 0; n < aUndoRedoList.size(); n++ )
310 rListBox.InsertEntry( String( aUndoRedoList[n] ));
312 rListBox.SelectEntryPos( 0 );
313 aActionStr = String( SVX_RES( SID_UNDO == GetSlotId() ?
314 RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS ) );
315 Impl_SetInfo( rListBox.GetSelectEntryCount() );
317 // move focus in floating window without
318 // closing it (GrabFocus() would close it!)
319 pPopupWin->StartPopupMode( &rBox, FLOATWIN_POPUPMODE_GRABFOCUS );
320 //pPopupWin->GetListBox().GrabFocus();
322 return pPopupWin;
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */