Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #ifdef _TOOLS_DEBUG_HXX
31 : : #include <tools/debug.hxx>
32 : : #endif
33 : : #include <vcl/lstbox.hxx>
34 : : #include <vcl/toolbox.hxx>
35 : : #include <vcl/event.hxx>
36 : : #include <sfx2/app.hxx>
37 : : #include <sfx2/tbxctrl.hxx>
38 : : #include <sfx2/bindings.hxx>
39 : : #include <sfx2/dispatch.hxx>
40 : : #include <sfx2/viewsh.hxx>
41 : : #include <tools/gen.hxx>
42 : : #include <svl/intitem.hxx>
43 : : #include <svl/eitem.hxx>
44 : : #include <svtools/stdctrl.hxx>
45 : : #include <svl/slstitm.hxx>
46 : : #include <svl/stritem.hxx>
47 : : #include <svx/dialmgr.hxx>
48 : : #include <svx/lboxctrl.hxx>
49 : : #include <vcl/mnemonic.hxx>
50 : : #include <tools/urlobj.hxx>
51 : :
52 : : #include <svx/svxids.hrc>
53 : : #include <svx/dialogs.hrc>
54 : :
55 : : #include "lboxctrl.hrc"
56 : :
57 : :
58 : : using namespace ::com::sun::star::uno;
59 : : using namespace ::com::sun::star::beans;
60 : : using namespace ::com::sun::star::frame;
61 : :
62 : : class SvxPopupWindowListBox;
63 : :
64 : : /////////////////////////////////////////////////////////////////
65 : :
66 : : class SvxPopupWindowListBox : public SfxPopupWindow
67 : : {
68 : : using FloatingWindow::StateChanged;
69 : :
70 : : ListBox * pListBox;
71 : : ToolBox & rToolBox;
72 : : sal_Bool bUserSel;
73 : : sal_uInt16 nTbxId;
74 : : rtl::OUString maCommandURL;
75 : : // disallow copy-constructor and assignment-operator
76 : :
77 : : SvxPopupWindowListBox(const int& );
78 : : SvxPopupWindowListBox & operator = (const int& );
79 : :
80 : : // SvxPopupWindowListBox( sal_uInt16 nSlotId, ToolBox& rTbx, sal_uInt16 nTbxItemId );
81 : :
82 : : public:
83 : : SvxPopupWindowListBox( sal_uInt16 nSlotId, const rtl::OUString& rCommandURL, sal_uInt16 nTbxId, ToolBox& rTbx );
84 : : virtual ~SvxPopupWindowListBox();
85 : :
86 : : // SfxPopupWindow
87 : : virtual SfxPopupWindow * Clone() const;
88 : : virtual void PopupModeEnd();
89 : : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
90 : : const SfxPoolItem* pState );
91 : :
92 : 0 : inline ListBox & GetListBox() { return *pListBox; }
93 : :
94 : 0 : sal_Bool IsUserSelected() const { return bUserSel; }
95 : 0 : void SetUserSelected( sal_Bool bVal ) { bUserSel = bVal; }
96 : : /*virtual*/Window* GetPreferredKeyInputWindow();
97 : : };
98 : :
99 : : /////////////////////////////////////////////////////////////////
100 : :
101 : 0 : SvxPopupWindowListBox::SvxPopupWindowListBox( sal_uInt16 nSlotId, const rtl::OUString& rCommandURL, sal_uInt16 nId, ToolBox& rTbx ) :
102 : 0 : SfxPopupWindow( nSlotId, Reference< XFrame >(), SVX_RES( RID_SVXTBX_UNDO_REDO_CTRL ) ),
103 : : rToolBox ( rTbx ),
104 : : bUserSel ( sal_False ),
105 : : nTbxId ( nId ),
106 [ # # ]: 0 : maCommandURL( rCommandURL )
107 : : {
108 : : DBG_ASSERT( nSlotId == GetId(), "id mismatch" );
109 [ # # ][ # # ]: 0 : pListBox = new ListBox( this, SVX_RES( LB_SVXTBX_UNDO_REDO_CTRL ) );
[ # # ]
110 [ # # ]: 0 : FreeResource();
111 [ # # ]: 0 : pListBox->EnableMultiSelection( sal_True, sal_True );
112 [ # # ][ # # ]: 0 : SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
[ # # ]
113 [ # # ]: 0 : AddStatusListener( rCommandURL );
114 : 0 : }
115 : :
116 : :
117 : 0 : SvxPopupWindowListBox::~SvxPopupWindowListBox()
118 : : {
119 [ # # ][ # # ]: 0 : delete pListBox;
120 [ # # ]: 0 : }
121 : :
122 : :
123 : 0 : SfxPopupWindow* SvxPopupWindowListBox::Clone() const
124 : : {
125 [ # # ]: 0 : return new SvxPopupWindowListBox( GetId(), maCommandURL, nTbxId, rToolBox );
126 : : }
127 : :
128 : :
129 : 0 : void SvxPopupWindowListBox::PopupModeEnd()
130 : : {
131 : 0 : rToolBox.EndSelection();
132 : 0 : SfxPopupWindow::PopupModeEnd();
133 : : //FloatingWindow::PopupModeEnd();
134 : :
135 [ # # ]: 0 : if( SfxViewShell::Current() )
136 : : {
137 : 0 : Window* pShellWnd = SfxViewShell::Current()->GetWindow();
138 [ # # ]: 0 : if (pShellWnd)
139 : 0 : pShellWnd->GrabFocus();
140 : : }
141 : 0 : }
142 : :
143 : :
144 : 0 : void SvxPopupWindowListBox::StateChanged(
145 : : sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
146 : : {
147 : 0 : rToolBox.EnableItem( nTbxId, ( SfxToolBoxControl::GetItemState( pState ) != SFX_ITEM_DISABLED) );
148 : 0 : SfxPopupWindow::StateChanged( nSID, eState, pState );
149 : 0 : }
150 : :
151 : 0 : Window* SvxPopupWindowListBox::GetPreferredKeyInputWindow()
152 : : {
153 : : // allows forwarding key events in the correct window
154 : : // without setting the focus
155 : 0 : return pListBox->GetPreferredKeyInputWindow();
156 : : }
157 : :
158 : : /////////////////////////////////////////////////////////////////
159 : :
160 : 2286 : SvxListBoxControl::SvxListBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
161 : : :SfxToolBoxControl( nSlotId, nId, rTbx ),
162 [ + - ]: 2286 : pPopupWin ( 0 )
163 : : {
164 [ + - ][ + - ]: 2286 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
165 [ + - ]: 2286 : rTbx.Invalidate();
166 : 2286 : }
167 : :
168 : :
169 [ + - ]: 2286 : SvxListBoxControl::~SvxListBoxControl()
170 : : {
171 [ - + ]: 2286 : }
172 : :
173 : :
174 : 0 : SfxPopupWindow* SvxListBoxControl::CreatePopupWindow()
175 : : {
176 : : OSL_FAIL( "not implemented" );
177 : 0 : return 0;
178 : : }
179 : :
180 : :
181 : 0 : SfxPopupWindowType SvxListBoxControl::GetPopupWindowType() const
182 : : {
183 : 0 : return SFX_POPUPWINDOW_ONTIMEOUT;
184 : : }
185 : :
186 : :
187 : 3572 : void SvxListBoxControl::StateChanged(
188 : : sal_uInt16, SfxItemState, const SfxPoolItem* pState )
189 : : {
190 : 3572 : GetToolBox().EnableItem( GetId(),
191 : 7144 : SFX_ITEM_DISABLED != GetItemState(pState) );
192 : 3572 : }
193 : :
194 : :
195 : 0 : IMPL_LINK_NOARG(SvxListBoxControl, PopupModeEndHdl)
196 : : {
197 [ # # ]: 0 : if( pPopupWin && 0 == pPopupWin->GetPopupModeFlags() &&
[ # # # # ]
[ # # ]
198 : 0 : pPopupWin->IsUserSelected() )
199 : : {
200 [ # # ]: 0 : sal_uInt16 nCount = pPopupWin->GetListBox().GetSelectEntryCount();
201 : :
202 [ # # ]: 0 : INetURLObject aObj( m_aCommandURL );
203 : :
204 [ # # ]: 0 : Sequence< PropertyValue > aArgs( 1 );
205 [ # # ][ # # ]: 0 : aArgs[0].Name = aObj.GetURLPath();
206 [ # # ][ # # ]: 0 : aArgs[0].Value = makeAny( sal_Int16( nCount ));
207 [ # # ][ # # ]: 0 : SfxToolBoxControl::Dispatch( m_aCommandURL, aArgs );
[ # # ]
208 : : }
209 : 0 : return 0;
210 : : }
211 : :
212 : :
213 : 0 : void SvxListBoxControl::Impl_SetInfo( sal_uInt16 nCount )
214 : : {
215 : : DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" );
216 : :
217 : : // ListBox &rListBox = pPopupWin->GetListBox();
218 : :
219 : : sal_uInt16 nId;
220 [ # # ]: 0 : if (nCount == 1)
221 [ # # ][ # # ]: 0 : nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTION : RID_SVXSTR_NUM_REDO_ACTION;
222 : : else
223 [ # # ][ # # ]: 0 : nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS;
224 : :
225 [ # # ][ # # ]: 0 : aActionStr = String(SVX_RES(nId));
[ # # ][ # # ]
226 : :
227 [ # # ]: 0 : String aText( aActionStr );
228 [ # # ][ # # ]: 0 : aText.SearchAndReplaceAllAscii( "$(ARG1)", String::CreateFromInt32( nCount ) );
[ # # ]
229 [ # # ][ # # ]: 0 : pPopupWin->SetText( aText );
230 : 0 : }
231 : :
232 : :
233 : 0 : IMPL_LINK_NOARG(SvxListBoxControl, SelectHdl)
234 : : {
235 [ # # ]: 0 : if (pPopupWin)
236 : : {
237 : : //pPopupWin->SetUserSelected( sal_False );
238 : :
239 : 0 : ListBox &rListBox = pPopupWin->GetListBox();
240 [ # # ]: 0 : if (rListBox.IsTravelSelect())
241 : 0 : Impl_SetInfo( rListBox.GetSelectEntryCount() );
242 : : else
243 : : {
244 : 0 : pPopupWin->SetUserSelected( sal_True );
245 : 0 : pPopupWin->EndPopupMode( 0 );
246 : : }
247 : : }
248 : 0 : return 0;
249 : : }
250 : :
251 : : /////////////////////////////////////////////////////////////////
252 : :
253 [ + - ]: 2604 : SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem );
254 : :
255 : 2286 : SvxUndoRedoControl::SvxUndoRedoControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
256 [ + - ]: 2286 : : SvxListBoxControl( nSlotId, nId, rTbx )
257 : : {
258 [ + - ][ + - ]: 2286 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
259 [ + - ]: 2286 : rTbx.Invalidate();
260 [ + - ][ + - ]: 2286 : aDefaultText = MnemonicGenerator::EraseAllMnemonicChars( rTbx.GetItemText( nId ) );
[ + - ][ + - ]
261 : 2286 : }
262 : :
263 : 2286 : SvxUndoRedoControl::~SvxUndoRedoControl()
264 : : {
265 [ - + ]: 4572 : }
266 : :
267 : 3572 : void SvxUndoRedoControl::StateChanged(
268 : : sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
269 : : {
270 [ + + ][ + - ]: 3572 : if ( nSID == SID_UNDO || nSID == SID_REDO )
271 : : {
272 [ + + ]: 3572 : if ( eState == SFX_ITEM_DISABLED )
273 : : {
274 : 2736 : ToolBox& rBox = GetToolBox();
275 [ + - ][ + - ]: 2736 : rBox.SetQuickHelpText( GetId(), aDefaultText );
276 : : }
277 [ + - ][ + - ]: 836 : else if ( pState && pState->ISA( SfxStringItem ) )
[ + - ]
278 : : {
279 : 836 : SfxStringItem& rItem = *(SfxStringItem *)pState;
280 [ + - ]: 836 : ToolBox& rBox = GetToolBox();
281 [ + - ]: 836 : String aQuickHelpText = MnemonicGenerator::EraseAllMnemonicChars( rItem.GetValue() );
282 [ + - ][ + - ]: 836 : rBox.SetQuickHelpText( GetId(), aQuickHelpText );
[ + - ]
283 : : }
284 : 3572 : SvxListBoxControl::StateChanged( nSID, eState, pState );
285 : : }
286 : : else
287 : : {
288 : 0 : aUndoRedoList.clear();
289 : :
290 [ # # ][ # # ]: 0 : if ( pState && pState->ISA( SfxStringListItem ) )
[ # # ]
291 : : {
292 : 0 : SfxStringListItem &rItem = *(SfxStringListItem *)pState;
293 : :
294 : 0 : const std::vector<String> &aLst = rItem.GetList();
295 [ # # ]: 0 : for( long nI = 0, nEnd = aLst.size(); nI < nEnd; ++nI )
296 [ # # ]: 0 : aUndoRedoList.push_back( rtl::OUString( aLst[nI] ));
297 : : }
298 : : }
299 : 3572 : }
300 : :
301 : 0 : SfxPopupWindow* SvxUndoRedoControl::CreatePopupWindow()
302 : : {
303 : : DBG_ASSERT(( SID_UNDO == GetSlotId() || SID_REDO == GetSlotId() ), "mismatching ids" );
304 : :
305 [ # # ]: 0 : if ( m_aCommandURL == ".uno:Undo" )
306 [ # # ]: 0 : updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GetUndoStrings" )));
307 : : else
308 [ # # ]: 0 : updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GetRedoStrings" )));
309 : :
310 : 0 : ToolBox& rBox = GetToolBox();
311 : :
312 [ # # ]: 0 : pPopupWin = new SvxPopupWindowListBox( GetSlotId(), m_aCommandURL, GetId(), rBox );
313 : : pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl,
314 : 0 : PopupModeEndHdl ) );
315 : 0 : ListBox &rListBox = pPopupWin->GetListBox();
316 : 0 : rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) );
317 : :
318 [ # # ]: 0 : for( sal_uInt32 n = 0; n < aUndoRedoList.size(); n++ )
319 [ # # ]: 0 : rListBox.InsertEntry( String( aUndoRedoList[n] ));
320 : :
321 : 0 : rListBox.SelectEntryPos( 0 );
322 : 0 : aActionStr = String( SVX_RES( SID_UNDO == GetSlotId() ?
323 [ # # ][ # # ]: 0 : RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS ) );
[ # # ][ # # ]
324 : 0 : Impl_SetInfo( rListBox.GetSelectEntryCount() );
325 : :
326 : : // move focus in floating window without
327 : : // closing it (GrabFocus() would close it!)
328 : 0 : pPopupWin->StartPopupMode( &rBox, FLOATWIN_POPUPMODE_GRABFOCUS );
329 : : //pPopupWin->GetListBox().GrabFocus();
330 : :
331 : 0 : return pPopupWin;
332 : : }
333 : :
334 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|