1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lboxctrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef _TOOLS_DEBUG_HXX
35 #include <tools/debug.hxx>
37 #include <vcl/lstbox.hxx>
38 #include <vcl/toolbox.hxx>
39 #include <vcl/event.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/tbxctrl.hxx>
42 #include <sfx2/bindings.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <sfx2/viewsh.hxx>
45 #include <tools/gen.hxx>
46 #include <svtools/intitem.hxx>
47 #include <svtools/eitem.hxx>
48 #include <svtools/stdctrl.hxx>
49 #include <svtools/slstitm.hxx>
50 #include <svtools/stritem.hxx>
51 #include <svx/dialmgr.hxx>
52 #include <lboxctrl.hxx>
53 #ifndef _VCL_MNEMONIC_HXX_
54 #include <vcl/mnemonic.hxx>
56 #include <tools/urlobj.hxx>
58 #include <svx/svxids.hrc>
59 #include <svx/dialogs.hrc>
61 #include "lboxctrl.hrc"
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::beans
;
66 using namespace ::com::sun::star::frame
;
68 class SvxPopupWindowListBox
;
70 /////////////////////////////////////////////////////////////////
72 class SvxPopupWindowListBox
: public SfxPopupWindow
74 using FloatingWindow::StateChanged
;
81 rtl::OUString maCommandURL
;
82 // disallow copy-constructor and assignment-operator
84 SvxPopupWindowListBox(const int& );
85 SvxPopupWindowListBox
& operator = (const int& );
87 // SvxPopupWindowListBox( USHORT nSlotId, ToolBox& rTbx, USHORT nTbxItemId );
90 SvxPopupWindowListBox( USHORT nSlotId
, const rtl::OUString
& rCommandURL
, USHORT nTbxId
, ToolBox
& rTbx
);
91 virtual ~SvxPopupWindowListBox();
94 virtual SfxPopupWindow
* Clone() const;
95 virtual void PopupModeEnd();
96 virtual void StateChanged( USHORT nSID
, SfxItemState eState
,
97 const SfxPoolItem
* pState
);
99 void StartSelection();
100 inline ListBox
& GetListBox() { return *pListBox
; }
101 inline FixedInfo
& GetInfo() { return aInfo
; }
103 BOOL
IsUserSelected() const { return bUserSel
; }
104 void SetUserSelected( BOOL bVal
) { bUserSel
= bVal
; }
105 /*virtual*/Window
* GetPreferredKeyInputWindow();
108 /////////////////////////////////////////////////////////////////
110 SvxPopupWindowListBox::SvxPopupWindowListBox( USHORT nSlotId
, const rtl::OUString
& rCommandURL
, USHORT nId
, ToolBox
& rTbx
) :
111 SfxPopupWindow( nSlotId
, Reference
< XFrame
>(), SVX_RES( RID_SVXTBX_UNDO_REDO_CTRL
) ),
112 aInfo ( this, SVX_RES( FT_NUM_OPERATIONS
) ),
116 maCommandURL( rCommandURL
)
118 DBG_ASSERT( nSlotId
== GetId(), "id mismatch" );
119 pListBox
= new ListBox( this, SVX_RES( LB_SVXTBX_UNDO_REDO_CTRL
) );
121 pListBox
->EnableMultiSelection( TRUE
, TRUE
);
122 SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
123 AddStatusListener( rCommandURL
);
127 SvxPopupWindowListBox::~SvxPopupWindowListBox()
133 SfxPopupWindow
* SvxPopupWindowListBox::Clone() const
135 return new SvxPopupWindowListBox( GetId(), maCommandURL
, nTbxId
, rToolBox
);
139 void SvxPopupWindowListBox::PopupModeEnd()
141 rToolBox
.EndSelection();
142 SfxPopupWindow::PopupModeEnd();
143 //FloatingWindow::PopupModeEnd();
145 if( SfxViewShell::Current() )
147 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
149 pShellWnd
->GrabFocus();
154 void SvxPopupWindowListBox::StateChanged(
155 USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
157 rToolBox
.EnableItem( nTbxId
, ( SfxToolBoxControl::GetItemState( pState
) != SFX_ITEM_DISABLED
) );
158 SfxPopupWindow::StateChanged( nSID
, eState
, pState
);
162 void SvxPopupWindowListBox::StartSelection()
164 rToolBox
.StartSelection();
167 Window
* SvxPopupWindowListBox::GetPreferredKeyInputWindow()
169 // allows forwarding key events in the correct window
170 // without setting the focus
171 return pListBox
->GetPreferredKeyInputWindow();
174 /////////////////////////////////////////////////////////////////
176 SFX_IMPL_TOOLBOX_CONTROL( SvxListBoxControl
, SfxStringItem
);
179 SvxListBoxControl::SvxListBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
)
180 :SfxToolBoxControl( nSlotId
, nId
, rTbx
),
183 rTbx
.SetItemBits( nId
, TIB_DROPDOWN
| rTbx
.GetItemBits( nId
) );
188 SvxListBoxControl::~SvxListBoxControl()
193 SfxPopupWindow
* SvxListBoxControl::CreatePopupWindow()
195 DBG_ERROR( "not implemented" );
200 SfxPopupWindowType
SvxListBoxControl::GetPopupWindowType() const
202 return SFX_POPUPWINDOW_ONTIMEOUT
;
206 void SvxListBoxControl::StateChanged(
207 USHORT
, SfxItemState
, const SfxPoolItem
* pState
)
209 GetToolBox().EnableItem( GetId(),
210 SFX_ITEM_DISABLED
!= GetItemState(pState
) );
214 IMPL_LINK( SvxListBoxControl
, PopupModeEndHdl
, void *, EMPTYARG
)
216 if( pPopupWin
&& 0 == pPopupWin
->GetPopupModeFlags() &&
217 pPopupWin
->IsUserSelected() )
219 USHORT nCount
= pPopupWin
->GetListBox().GetSelectEntryCount();
221 INetURLObject
aObj( m_aCommandURL
);
223 Sequence
< PropertyValue
> aArgs( 1 );
224 aArgs
[0].Name
= aObj
.GetURLPath();
225 aArgs
[0].Value
= makeAny( sal_Int16( nCount
));
226 SfxToolBoxControl::Dispatch( m_aCommandURL
, aArgs
);
232 void SvxListBoxControl::Impl_SetInfo( USHORT nCount
)
234 DBG_ASSERT( pPopupWin
, "NULL pointer, PopupWindow missing" );
236 // ListBox &rListBox = pPopupWin->GetListBox();
240 nId
= SID_UNDO
== GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTION
: RID_SVXSTR_NUM_REDO_ACTION
;
242 nId
= SID_UNDO
== GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTIONS
: RID_SVXSTR_NUM_REDO_ACTIONS
;
244 aActionStr
= String(SVX_RES(nId
));
246 String
aText( aActionStr
);
247 aText
.SearchAndReplaceAllAscii( "$(ARG1)", String::CreateFromInt32( nCount
) );
248 pPopupWin
->GetInfo().SetText( aText
);
252 IMPL_LINK( SvxListBoxControl
, SelectHdl
, void *, EMPTYARG
)
256 //pPopupWin->SetUserSelected( FALSE );
258 ListBox
&rListBox
= pPopupWin
->GetListBox();
259 if (rListBox
.IsTravelSelect())
260 Impl_SetInfo( rListBox
.GetSelectEntryCount() );
263 pPopupWin
->SetUserSelected( TRUE
);
264 pPopupWin
->EndPopupMode( 0 );
270 /////////////////////////////////////////////////////////////////
272 SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl
, SfxStringItem
);
274 SvxUndoRedoControl::SvxUndoRedoControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
)
275 : SvxListBoxControl( nSlotId
, nId
, rTbx
)
277 rTbx
.SetItemBits( nId
, TIB_DROPDOWN
| rTbx
.GetItemBits( nId
) );
279 aDefaultText
= MnemonicGenerator::EraseAllMnemonicChars( rTbx
.GetItemText( nId
) );
282 SvxUndoRedoControl::~SvxUndoRedoControl()
286 void SvxUndoRedoControl::StateChanged(
287 USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
289 if ( nSID
== SID_UNDO
|| nSID
== SID_REDO
)
291 if ( eState
== SFX_ITEM_DISABLED
)
293 ToolBox
& rBox
= GetToolBox();
294 rBox
.SetQuickHelpText( GetId(), aDefaultText
);
296 else if ( pState
&& pState
->ISA( SfxStringItem
) )
298 SfxStringItem
& rItem
= *(SfxStringItem
*)pState
;
299 ToolBox
& rBox
= GetToolBox();
300 String aQuickHelpText
= MnemonicGenerator::EraseAllMnemonicChars( rItem
.GetValue() );
301 rBox
.SetQuickHelpText( GetId(), aQuickHelpText
);
303 SvxListBoxControl::StateChanged( nSID
, eState
, pState
);
307 aUndoRedoList
.clear();
309 if ( pState
&& pState
->ISA( SfxStringListItem
) )
311 SfxStringListItem
&rItem
= *(SfxStringListItem
*)pState
;
312 const List
* pLst
= rItem
.GetList();
313 DBG_ASSERT( pLst
, "no undo actions available" );
316 for( long nI
= 0, nEnd
= pLst
->Count(); nI
< nEnd
; ++nI
)
317 aUndoRedoList
.push_back( rtl::OUString( *(String
*)pLst
->GetObject( nI
)));
323 SfxPopupWindow
* SvxUndoRedoControl::CreatePopupWindow()
325 DBG_ASSERT(( SID_UNDO
== GetSlotId() || SID_REDO
== GetSlotId() ), "mismatching ids" );
327 if ( m_aCommandURL
.equalsAscii( ".uno:Undo" ))
328 updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GetUndoStrings" )));
330 updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GetRedoStrings" )));
332 ToolBox
& rBox
= GetToolBox();
334 pPopupWin
= new SvxPopupWindowListBox( GetSlotId(), m_aCommandURL
, GetId(), rBox
);
335 pPopupWin
->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl
,
337 ListBox
&rListBox
= pPopupWin
->GetListBox();
338 rListBox
.SetSelectHdl( LINK( this, SvxUndoRedoControl
, SelectHdl
) );
340 for( sal_uInt32 n
= 0; n
< aUndoRedoList
.size(); n
++ )
341 rListBox
.InsertEntry( String( aUndoRedoList
[n
] ));
343 rListBox
.SelectEntryPos( 0 );
344 aActionStr
= String( SVX_RES( SID_UNDO
== GetSlotId() ?
345 RID_SVXSTR_NUM_UNDO_ACTIONS
: RID_SVXSTR_NUM_REDO_ACTIONS
) );
346 Impl_SetInfo( rListBox
.GetSelectEntryCount() );
348 // move focus in floating window without
349 // closing it (GrabFocus() would close it!)
350 pPopupWin
->StartPopupMode( &rBox
, FLOATWIN_POPUPMODE_GRABFOCUS
);
351 //pPopupWin->GetListBox().GrabFocus();