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 : #include <sal/config.h>
21 :
22 : #include <boost/noncopyable.hpp>
23 : #include <tools/debug.hxx>
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 <vcl/settings.hxx>
42 : #include <tools/urlobj.hxx>
43 :
44 : #include <svx/svxids.hrc>
45 : #include <svx/dialogs.hrc>
46 :
47 : using namespace ::com::sun::star::uno;
48 : using namespace ::com::sun::star::beans;
49 : using namespace ::com::sun::star::frame;
50 :
51 : class SvxPopupWindowListBox;
52 :
53 0 : class SvxPopupWindowListBox: public SfxPopupWindow
54 : {
55 : using FloatingWindow::StateChanged;
56 :
57 : ListBox * m_pListBox;
58 : ToolBox & rToolBox;
59 : bool bUserSel;
60 : sal_uInt16 nTbxId;
61 : OUString maCommandURL;
62 :
63 : public:
64 : SvxPopupWindowListBox( sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nTbxId, ToolBox& rTbx );
65 :
66 : // SfxPopupWindow
67 : virtual SfxPopupWindow * Clone() const SAL_OVERRIDE;
68 : virtual void PopupModeEnd() SAL_OVERRIDE;
69 : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
70 : const SfxPoolItem* pState ) SAL_OVERRIDE;
71 :
72 0 : inline ListBox & GetListBox() { return *m_pListBox; }
73 :
74 0 : bool IsUserSelected() const { return bUserSel; }
75 0 : void SetUserSelected( bool bVal ) { bUserSel = bVal; }
76 : virtual vcl::Window* GetPreferredKeyInputWindow() SAL_OVERRIDE;
77 : };
78 :
79 0 : SvxPopupWindowListBox::SvxPopupWindowListBox(sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nId, ToolBox& rTbx)
80 : : SfxPopupWindow(nSlotId, "FloatingUndoRedo", "svx/ui/floatingundoredo.ui")
81 : , rToolBox(rTbx)
82 : , bUserSel(false)
83 : , nTbxId(nId)
84 0 : , maCommandURL(rCommandURL)
85 : {
86 : DBG_ASSERT( nSlotId == GetId(), "id mismatch" );
87 0 : get(m_pListBox, "treeview");
88 0 : WinBits nBits(m_pListBox->GetStyle());
89 0 : nBits &= ~(WB_SIMPLEMODE);
90 0 : m_pListBox->SetStyle(nBits);
91 0 : Size aSize(LogicToPixel(Size(100, 85), MAP_APPFONT));
92 0 : m_pListBox->set_width_request(aSize.Width());
93 0 : m_pListBox->set_height_request(aSize.Height());
94 0 : m_pListBox->EnableMultiSelection( true, true );
95 0 : SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
96 0 : AddStatusListener( rCommandURL );
97 0 : }
98 :
99 0 : SfxPopupWindow* SvxPopupWindowListBox::Clone() const
100 : {
101 0 : return new SvxPopupWindowListBox( GetId(), maCommandURL, nTbxId, rToolBox );
102 : }
103 :
104 0 : void SvxPopupWindowListBox::PopupModeEnd()
105 : {
106 0 : rToolBox.EndSelection();
107 0 : SfxPopupWindow::PopupModeEnd();
108 : //FloatingWindow::PopupModeEnd();
109 :
110 0 : if( SfxViewShell::Current() )
111 : {
112 0 : vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
113 0 : if (pShellWnd)
114 0 : pShellWnd->GrabFocus();
115 : }
116 0 : }
117 :
118 :
119 0 : void SvxPopupWindowListBox::StateChanged(
120 : sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
121 : {
122 0 : rToolBox.EnableItem( nTbxId, ( SfxToolBoxControl::GetItemState( pState ) != SfxItemState::DISABLED) );
123 0 : SfxPopupWindow::StateChanged( nSID, eState, pState );
124 0 : }
125 :
126 0 : vcl::Window* SvxPopupWindowListBox::GetPreferredKeyInputWindow()
127 : {
128 : // allows forwarding key events in the correct window
129 : // without setting the focus
130 0 : return m_pListBox->GetPreferredKeyInputWindow();
131 : }
132 :
133 2928 : SvxListBoxControl::SvxListBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
134 : :SfxToolBoxControl( nSlotId, nId, rTbx ),
135 2928 : pPopupWin ( 0 )
136 : {
137 2928 : rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
138 2928 : rTbx.Invalidate();
139 2928 : }
140 :
141 :
142 2928 : SvxListBoxControl::~SvxListBoxControl()
143 : {
144 2928 : }
145 :
146 :
147 0 : SfxPopupWindow* SvxListBoxControl::CreatePopupWindow()
148 : {
149 : OSL_FAIL( "not implemented" );
150 0 : return 0;
151 : }
152 :
153 :
154 0 : SfxPopupWindowType SvxListBoxControl::GetPopupWindowType() const
155 : {
156 0 : return SFX_POPUPWINDOW_ONTIMEOUT;
157 : }
158 :
159 :
160 2607 : void SvxListBoxControl::StateChanged(
161 : sal_uInt16, SfxItemState, const SfxPoolItem* pState )
162 : {
163 5214 : GetToolBox().EnableItem( GetId(),
164 7821 : SfxItemState::DISABLED != GetItemState(pState) );
165 2607 : }
166 :
167 :
168 0 : IMPL_LINK_NOARG(SvxListBoxControl, PopupModeEndHdl)
169 : {
170 0 : if( pPopupWin && 0 == pPopupWin->GetPopupModeFlags() &&
171 0 : pPopupWin->IsUserSelected() )
172 : {
173 0 : sal_uInt16 nCount = pPopupWin->GetListBox().GetSelectEntryCount();
174 :
175 0 : INetURLObject aObj( m_aCommandURL );
176 :
177 0 : Sequence< PropertyValue > aArgs( 1 );
178 0 : aArgs[0].Name = aObj.GetURLPath();
179 0 : aArgs[0].Value = makeAny( sal_Int16( nCount ));
180 0 : SfxToolBoxControl::Dispatch( m_aCommandURL, aArgs );
181 : }
182 0 : return 0;
183 : }
184 :
185 :
186 0 : void SvxListBoxControl::Impl_SetInfo( sal_uInt16 nCount )
187 : {
188 : DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" );
189 :
190 : // ListBox &rListBox = pPopupWin->GetListBox();
191 :
192 : sal_uInt16 nId;
193 0 : if (nCount == 1)
194 0 : nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTION : RID_SVXSTR_NUM_REDO_ACTION;
195 : else
196 0 : nId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS;
197 :
198 0 : aActionStr = SVX_RESSTR(nId);
199 :
200 0 : OUString aText = aActionStr.replaceAll("$(ARG1)", OUString::number(nCount));
201 0 : pPopupWin->SetText(aText);
202 0 : }
203 :
204 :
205 0 : IMPL_LINK_NOARG(SvxListBoxControl, SelectHdl)
206 : {
207 0 : if (pPopupWin)
208 : {
209 : //pPopupWin->SetUserSelected( false );
210 :
211 0 : ListBox &rListBox = pPopupWin->GetListBox();
212 0 : if (rListBox.IsTravelSelect())
213 0 : Impl_SetInfo( rListBox.GetSelectEntryCount() );
214 : else
215 : {
216 0 : pPopupWin->SetUserSelected( true );
217 0 : pPopupWin->EndPopupMode( 0 );
218 : }
219 : }
220 0 : return 0;
221 : }
222 :
223 :
224 :
225 3376 : SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem );
226 :
227 2928 : SvxUndoRedoControl::SvxUndoRedoControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
228 2928 : : SvxListBoxControl( nSlotId, nId, rTbx )
229 : {
230 2928 : rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
231 2928 : rTbx.Invalidate();
232 2928 : aDefaultText = MnemonicGenerator::EraseAllMnemonicChars( rTbx.GetItemText( nId ) );
233 2928 : }
234 :
235 5856 : SvxUndoRedoControl::~SvxUndoRedoControl()
236 : {
237 5856 : }
238 :
239 2607 : void SvxUndoRedoControl::StateChanged(
240 : sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
241 : {
242 2607 : if ( nSID == SID_UNDO || nSID == SID_REDO )
243 : {
244 2607 : if ( eState == SfxItemState::DISABLED )
245 : {
246 2081 : ToolBox& rBox = GetToolBox();
247 2081 : rBox.SetQuickHelpText( GetId(), aDefaultText );
248 : }
249 526 : else if ( pState && pState->ISA( SfxStringItem ) )
250 : {
251 526 : const SfxStringItem& rItem = *static_cast<const SfxStringItem *>(pState);
252 526 : ToolBox& rBox = GetToolBox();
253 526 : OUString aQuickHelpText = MnemonicGenerator::EraseAllMnemonicChars( rItem.GetValue() );
254 526 : rBox.SetQuickHelpText( GetId(), aQuickHelpText );
255 : }
256 2607 : SvxListBoxControl::StateChanged( nSID, eState, pState );
257 : }
258 : else
259 : {
260 0 : aUndoRedoList.clear();
261 :
262 0 : if ( pState && pState->ISA( SfxStringListItem ) )
263 : {
264 0 : const SfxStringListItem &rItem = *static_cast<const SfxStringListItem *>(pState);
265 :
266 0 : const std::vector<OUString> &aLst = rItem.GetList();
267 0 : for( long nI = 0, nEnd = aLst.size(); nI < nEnd; ++nI )
268 0 : aUndoRedoList.push_back( aLst[nI] );
269 : }
270 : }
271 2607 : }
272 :
273 0 : SfxPopupWindow* SvxUndoRedoControl::CreatePopupWindow()
274 : {
275 : DBG_ASSERT(( SID_UNDO == GetSlotId() || SID_REDO == GetSlotId() ), "mismatching ids" );
276 :
277 0 : if ( m_aCommandURL == ".uno:Undo" )
278 0 : updateStatus( OUString( ".uno:GetUndoStrings" ));
279 : else
280 0 : updateStatus( OUString( ".uno:GetRedoStrings" ));
281 :
282 0 : ToolBox& rBox = GetToolBox();
283 :
284 0 : pPopupWin = new SvxPopupWindowListBox( GetSlotId(), m_aCommandURL, GetId(), rBox );
285 : pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl,
286 0 : PopupModeEndHdl ) );
287 0 : ListBox &rListBox = pPopupWin->GetListBox();
288 0 : rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) );
289 :
290 0 : for( sal_uInt32 n = 0; n < aUndoRedoList.size(); n++ )
291 0 : rListBox.InsertEntry( aUndoRedoList[n] );
292 :
293 0 : rListBox.SelectEntryPos( 0 );
294 0 : aActionStr = SVX_RESSTR(SID_UNDO == GetSlotId() ?
295 0 : RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS);
296 0 : Impl_SetInfo( rListBox.GetSelectEntryCount() );
297 :
298 : // move focus in floating window without
299 : // closing it (GrabFocus() would close it!)
300 0 : pPopupWin->StartPopupMode( &rBox, FLOATWIN_POPUPMODE_GRABFOCUS );
301 : //pPopupWin->GetListBox().GrabFocus();
302 :
303 0 : return pPopupWin;
304 594 : }
305 :
306 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|