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 <basic/basmgr.hxx>
21 :
22 : #include "macropg.hxx"
23 : #include <vcl/layout.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <svtools/svmedit.hxx>
26 : #include <svtools/svlbitm.hxx>
27 : #include "svtools/treelistentry.hxx"
28 : #include <svl/eitem.hxx>
29 : #include <tools/diagnose_ex.h>
30 : #include <sfx2/app.hxx>
31 : #include <sfx2/objsh.hxx>
32 : #include <sfx2/sfxdefs.hxx>
33 : #include <com/sun/star/container/NoSuchElementException.hpp>
34 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 : #include <dialmgr.hxx>
36 : #include "selector.hxx"
37 : #include "cfg.hxx"
38 : #include "helpid.hrc"
39 : #include <cuires.hrc>
40 : #include "headertablistbox.hxx"
41 : #include "macropg_impl.hxx"
42 : #include <svx/dialogs.hrc>
43 : #include <comphelper/namedvaluecollection.hxx>
44 :
45 : #include <algorithm>
46 : #include <set>
47 : #include <boost/scoped_ptr.hpp>
48 :
49 : using namespace ::com::sun::star;
50 : using namespace ::com::sun::star::uno;
51 :
52 0 : static OUString aVndSunStarUNO( "vnd.sun.star.UNO:" );
53 0 : static OUString aVndSunStarScript( "vnd.sun.star.script:" );
54 :
55 0 : _SvxMacroTabPage_Impl::_SvxMacroTabPage_Impl( const SfxItemSet& rAttrSet )
56 : : pAssignPB(NULL)
57 : , pAssignComponentPB(NULL)
58 : , pDeletePB(NULL)
59 : , pEventLB(NULL)
60 : , bReadOnly(false)
61 0 : , bIDEDialogMode(false)
62 : {
63 : const SfxPoolItem* pItem;
64 0 : if ( SfxItemState::SET == rAttrSet.GetItemState( SID_ATTR_MACROITEM, false, &pItem ) )
65 0 : bIDEDialogMode = static_cast<const SfxBoolItem*>(pItem)->GetValue();
66 0 : }
67 :
68 : // attention, this array is indexed directly (0, 1, ...) in the code
69 : static long nTabs[] =
70 : {
71 : 2, // Number of Tabs
72 : 0, 90
73 : };
74 :
75 : #define TAB_WIDTH_MIN 10
76 :
77 : // IDs for items in HeaderBar of EventLB
78 : #define ITEMID_EVENT 1
79 : #define ITMEID_ASSMACRO 2
80 :
81 :
82 : #define LB_MACROS_ITEMPOS 2
83 :
84 :
85 0 : IMPL_LINK( MacroEventListBox, HeaderEndDrag_Impl, HeaderBar*, pBar )
86 : {
87 : DBG_ASSERT( pBar == &maHeaderBar, "*MacroEventListBox::HeaderEndDrag_Impl: something is wrong here..." );
88 : (void)pBar;
89 :
90 0 : if( !maHeaderBar.GetCurItemId() )
91 0 : return 0;
92 :
93 0 : if( !maHeaderBar.IsItemMode() )
94 : {
95 0 : Size aSz;
96 0 : sal_uInt16 _nTabs = maHeaderBar.GetItemCount();
97 0 : long nWidth = maHeaderBar.GetItemSize( ITEMID_EVENT );
98 0 : long nBarWidth = maHeaderBar.GetSizePixel().Width();
99 :
100 0 : if( nWidth < TAB_WIDTH_MIN )
101 0 : maHeaderBar.SetItemSize( ITEMID_EVENT, TAB_WIDTH_MIN );
102 0 : else if( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
103 0 : maHeaderBar.SetItemSize( ITEMID_EVENT, nBarWidth - TAB_WIDTH_MIN );
104 :
105 : {
106 0 : long _nWidth, nTmpSz = 0;
107 0 : for( sal_uInt16 i = 1 ; i < _nTabs ; ++i )
108 : {
109 0 : _nWidth = maHeaderBar.GetItemSize( i );
110 0 : aSz.Width() = _nWidth + nTmpSz;
111 0 : nTmpSz += _nWidth;
112 0 : maListBox.SetTab( i, PixelToLogic( aSz, MapMode( MAP_APPFONT ) ).Width(), MAP_APPFONT );
113 : }
114 : }
115 : }
116 0 : return 1;
117 : }
118 :
119 0 : bool MacroEventListBox::Notify( NotifyEvent& rNEvt )
120 : {
121 0 : bool nRet = Control::Notify( rNEvt );
122 :
123 0 : if( rNEvt.GetType() == EVENT_GETFOCUS )
124 : {
125 0 : if ( rNEvt.GetWindow() != &maListBox )
126 0 : maListBox.GrabFocus();
127 : }
128 :
129 0 : return nRet;
130 : }
131 :
132 0 : MacroEventListBox::MacroEventListBox( vcl::Window* pParent, WinBits nStyle )
133 : : Control( pParent, nStyle )
134 : , maHeaderBar( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER )
135 0 : , maListBox( this, WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP )
136 : {
137 0 : maListBox.SetHelpId( HID_MACRO_HEADERTABLISTBOX );
138 :
139 : // enable the cell focus to show visible focus
140 0 : maListBox.EnableCellFocus();
141 0 : }
142 :
143 0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeMacroEventListBox(vcl::Window *pParent, VclBuilder::stringmap &rMap)
144 : {
145 0 : WinBits nWinBits = WB_TABSTOP;
146 :
147 0 : OString sBorder = VclBuilder::extractCustomProperty(rMap);
148 0 : if (!sBorder.isEmpty())
149 0 : nWinBits |= WB_BORDER;
150 :
151 0 : return new MacroEventListBox(pParent, nWinBits);
152 : }
153 :
154 0 : Size MacroEventListBox::GetOptimalSize() const
155 : {
156 0 : return LogicToPixel(Size(192, 72), MapMode(MAP_APPFONT ));
157 : }
158 :
159 0 : void MacroEventListBox::Resize()
160 : {
161 0 : Control::Resize();
162 :
163 : // calc pos and size of header bar
164 0 : Point aPnt( 0, 0 );
165 0 : Size aSize( maHeaderBar.CalcWindowSizePixel() );
166 0 : Size aCtrlSize( GetOutputSizePixel() );
167 0 : aSize.Width() = aCtrlSize.Width();
168 0 : maHeaderBar.SetPosSizePixel( aPnt, aSize );
169 :
170 : // calc pos and size of ListBox
171 0 : aPnt.Y() += aSize.Height();
172 0 : aSize.Height() = aCtrlSize.Height() - aSize.Height();
173 0 : maListBox.SetPosSizePixel( aPnt, aSize );
174 0 : }
175 :
176 0 : void MacroEventListBox::ConnectElements( void )
177 : {
178 0 : Resize();
179 :
180 : // set handler
181 0 : maHeaderBar.SetEndDragHdl( LINK( this, MacroEventListBox, HeaderEndDrag_Impl ) );
182 :
183 0 : maListBox.InitHeaderBar( &maHeaderBar );
184 0 : }
185 :
186 0 : void MacroEventListBox::Show( bool bVisible, sal_uInt16 nFlags )
187 : {
188 0 : maListBox.Show( bVisible, nFlags );
189 0 : maHeaderBar.Show( bVisible, nFlags );
190 0 : }
191 :
192 0 : void MacroEventListBox::Enable( bool bEnable, bool bChild )
193 : {
194 0 : maListBox.Enable( bEnable, bChild );
195 0 : maHeaderBar.Enable( bEnable, bChild );
196 0 : }
197 :
198 : // assign button ("Add Command") is enabled only if it is not read only
199 : // delete button ("Remove Command") is enabled if a current binding exists
200 : // and it is not read only
201 0 : void _SvxMacroTabPage::EnableButtons()
202 : {
203 0 : const SvTreeListEntry* pE = mpImpl->pEventLB->GetListBox().FirstSelected();
204 0 : if ( pE )
205 : {
206 0 : const SvLBoxString* pEventMacro = static_cast<const SvLBoxString*>(pE->GetItem( LB_MACROS_ITEMPOS ));
207 0 : mpImpl->pDeletePB->Enable( 0 != pEventMacro && !mpImpl->bReadOnly );
208 :
209 0 : mpImpl->pAssignPB->Enable( !mpImpl->bReadOnly );
210 0 : if( mpImpl->pAssignComponentPB )
211 0 : mpImpl->pAssignComponentPB->Enable( !mpImpl->bReadOnly );
212 : }
213 0 : }
214 :
215 0 : _SvxMacroTabPage::_SvxMacroTabPage(vcl::Window* pParent, const OString& rID,
216 : const OUString& rUIXMLDescription, const SfxItemSet& rAttrSet)
217 : : SfxTabPage( pParent, rID, rUIXMLDescription, &rAttrSet ),
218 : m_xAppEvents(0),
219 : m_xDocEvents(0),
220 : bReadOnly(false),
221 : bDocModified(false),
222 : bAppEvents(false),
223 0 : bInitialized(false)
224 : {
225 0 : mpImpl = new _SvxMacroTabPage_Impl( rAttrSet );
226 0 : }
227 :
228 0 : _SvxMacroTabPage::~_SvxMacroTabPage()
229 : {
230 0 : DELETEZ( mpImpl );
231 0 : }
232 :
233 0 : void _SvxMacroTabPage::InitResources()
234 : {
235 : // Note: the order here controls the order in which the events are displayed in the UI!
236 :
237 : // the event name to UI string mappings for App Events
238 0 : aDisplayNames.push_back( EventDisplayName( "OnStartApp", RID_SVXSTR_EVENT_STARTAPP ) );
239 0 : aDisplayNames.push_back( EventDisplayName( "OnCloseApp", RID_SVXSTR_EVENT_CLOSEAPP ) );
240 0 : aDisplayNames.push_back( EventDisplayName( "OnCreate", RID_SVXSTR_EVENT_CREATEDOC ) );
241 0 : aDisplayNames.push_back( EventDisplayName( "OnNew", RID_SVXSTR_EVENT_NEWDOC ) );
242 0 : aDisplayNames.push_back( EventDisplayName( "OnLoadFinished", RID_SVXSTR_EVENT_LOADDOCFINISHED ) );
243 0 : aDisplayNames.push_back( EventDisplayName( "OnLoad", RID_SVXSTR_EVENT_OPENDOC ) );
244 0 : aDisplayNames.push_back( EventDisplayName( "OnPrepareUnload", RID_SVXSTR_EVENT_PREPARECLOSEDOC ) );
245 0 : aDisplayNames.push_back( EventDisplayName( "OnUnload", RID_SVXSTR_EVENT_CLOSEDOC ) ) ;
246 0 : aDisplayNames.push_back( EventDisplayName( "OnViewCreated", RID_SVXSTR_EVENT_VIEWCREATED ) );
247 0 : aDisplayNames.push_back( EventDisplayName( "OnPrepareViewClosing", RID_SVXSTR_EVENT_PREPARECLOSEVIEW ) );
248 0 : aDisplayNames.push_back( EventDisplayName( "OnViewClosed", RID_SVXSTR_EVENT_CLOSEVIEW ) ) ;
249 0 : aDisplayNames.push_back( EventDisplayName( "OnFocus", RID_SVXSTR_EVENT_ACTIVATEDOC ) );
250 0 : aDisplayNames.push_back( EventDisplayName( "OnUnfocus", RID_SVXSTR_EVENT_DEACTIVATEDOC ) );
251 0 : aDisplayNames.push_back( EventDisplayName( "OnSave", RID_SVXSTR_EVENT_SAVEDOC ) );
252 0 : aDisplayNames.push_back( EventDisplayName( "OnSaveDone", RID_SVXSTR_EVENT_SAVEDOCDONE ) );
253 0 : aDisplayNames.push_back( EventDisplayName( "OnSaveFailed", RID_SVXSTR_EVENT_SAVEDOCFAILED ) );
254 0 : aDisplayNames.push_back( EventDisplayName( "OnSaveAs", RID_SVXSTR_EVENT_SAVEASDOC ) );
255 0 : aDisplayNames.push_back( EventDisplayName( "OnSaveAsDone", RID_SVXSTR_EVENT_SAVEASDOCDONE ) );
256 0 : aDisplayNames.push_back( EventDisplayName( "OnSaveAsFailed", RID_SVXSTR_EVENT_SAVEASDOCFAILED ) );
257 0 : aDisplayNames.push_back( EventDisplayName( "OnCopyTo", RID_SVXSTR_EVENT_COPYTODOC ) );
258 0 : aDisplayNames.push_back( EventDisplayName( "OnCopyToDone", RID_SVXSTR_EVENT_COPYTODOCDONE ) );
259 0 : aDisplayNames.push_back( EventDisplayName( "OnCopyToFailed", RID_SVXSTR_EVENT_COPYTODOCFAILED ) );
260 0 : aDisplayNames.push_back( EventDisplayName( "OnPrint", RID_SVXSTR_EVENT_PRINTDOC ) );
261 0 : aDisplayNames.push_back( EventDisplayName( "OnModifyChanged", RID_SVXSTR_EVENT_MODIFYCHANGED ) );
262 0 : aDisplayNames.push_back( EventDisplayName( "OnTitleChanged", RID_SVXSTR_EVENT_TITLECHANGED ) );
263 :
264 : // application specific events
265 0 : aDisplayNames.push_back( EventDisplayName( "OnMailMerge", RID_SVXSTR_EVENT_MAILMERGE ) );
266 0 : aDisplayNames.push_back( EventDisplayName( "OnMailMergeFinished", RID_SVXSTR_EVENT_MAILMERGE_END ) );
267 0 : aDisplayNames.push_back( EventDisplayName( "OnFieldMerge", RID_SVXSTR_EVENT_FIELDMERGE ) );
268 0 : aDisplayNames.push_back( EventDisplayName( "OnFieldMergeFinished", RID_SVXSTR_EVENT_FIELDMERGE_FINISHED ) );
269 0 : aDisplayNames.push_back( EventDisplayName( "OnPageCountChange", RID_SVXSTR_EVENT_PAGECOUNTCHANGE ) );
270 0 : aDisplayNames.push_back( EventDisplayName( "OnSubComponentOpened", RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED ) );
271 0 : aDisplayNames.push_back( EventDisplayName( "OnSubComponentClosed", RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED ) );
272 0 : aDisplayNames.push_back( EventDisplayName( "OnSelect", RID_SVXSTR_EVENT_SELECTIONCHANGED ) );
273 0 : aDisplayNames.push_back( EventDisplayName( "OnDoubleClick", RID_SVXSTR_EVENT_DOUBLECLICK ) );
274 0 : aDisplayNames.push_back( EventDisplayName( "OnRightClick", RID_SVXSTR_EVENT_RIGHTCLICK ) );
275 0 : aDisplayNames.push_back( EventDisplayName( "OnCalculate", RID_SVXSTR_EVENT_CALCULATE ) );
276 0 : aDisplayNames.push_back( EventDisplayName( "OnChange", RID_SVXSTR_EVENT_CONTENTCHANGED ) );
277 :
278 : // the event name to UI string mappings for forms & dialogs
279 :
280 0 : aDisplayNames.push_back( EventDisplayName( "approveAction", RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED ) );
281 0 : aDisplayNames.push_back( EventDisplayName( "actionPerformed", RID_SVXSTR_EVENT_ACTIONPERFORMED ) );
282 0 : aDisplayNames.push_back( EventDisplayName( "changed", RID_SVXSTR_EVENT_CHANGED ) );
283 0 : aDisplayNames.push_back( EventDisplayName( "textChanged", RID_SVXSTR_EVENT_TEXTCHANGED ) );
284 0 : aDisplayNames.push_back( EventDisplayName( "itemStateChanged", RID_SVXSTR_EVENT_ITEMSTATECHANGED ) );
285 0 : aDisplayNames.push_back( EventDisplayName( "focusGained", RID_SVXSTR_EVENT_FOCUSGAINED ) );
286 0 : aDisplayNames.push_back( EventDisplayName( "focusLost", RID_SVXSTR_EVENT_FOCUSLOST ) );
287 0 : aDisplayNames.push_back( EventDisplayName( "keyPressed", RID_SVXSTR_EVENT_KEYTYPED ) );
288 0 : aDisplayNames.push_back( EventDisplayName( "keyReleased", RID_SVXSTR_EVENT_KEYUP ) );
289 0 : aDisplayNames.push_back( EventDisplayName( "mouseEntered", RID_SVXSTR_EVENT_MOUSEENTERED ) );
290 0 : aDisplayNames.push_back( EventDisplayName( "mouseDragged", RID_SVXSTR_EVENT_MOUSEDRAGGED ) );
291 0 : aDisplayNames.push_back( EventDisplayName( "mouseMoved", RID_SVXSTR_EVENT_MOUSEMOVED ) );
292 0 : aDisplayNames.push_back( EventDisplayName( "mousePressed", RID_SVXSTR_EVENT_MOUSEPRESSED ) );
293 0 : aDisplayNames.push_back( EventDisplayName( "mouseReleased", RID_SVXSTR_EVENT_MOUSERELEASED ) );
294 0 : aDisplayNames.push_back( EventDisplayName( "mouseExited", RID_SVXSTR_EVENT_MOUSEEXITED ) );
295 0 : aDisplayNames.push_back( EventDisplayName( "approveReset", RID_SVXSTR_EVENT_APPROVERESETTED ) );
296 0 : aDisplayNames.push_back( EventDisplayName( "resetted", RID_SVXSTR_EVENT_RESETTED ) );
297 0 : aDisplayNames.push_back( EventDisplayName( "approveSubmit", RID_SVXSTR_EVENT_SUBMITTED ) );
298 0 : aDisplayNames.push_back( EventDisplayName( "approveUpdate", RID_SVXSTR_EVENT_BEFOREUPDATE ) );
299 0 : aDisplayNames.push_back( EventDisplayName( "updated", RID_SVXSTR_EVENT_AFTERUPDATE ) );
300 0 : aDisplayNames.push_back( EventDisplayName( "loaded", RID_SVXSTR_EVENT_LOADED ) );
301 0 : aDisplayNames.push_back( EventDisplayName( "reloading", RID_SVXSTR_EVENT_RELOADING ) );
302 0 : aDisplayNames.push_back( EventDisplayName( "reloaded", RID_SVXSTR_EVENT_RELOADED ) );
303 0 : aDisplayNames.push_back( EventDisplayName( "unloading", RID_SVXSTR_EVENT_UNLOADING ) );
304 0 : aDisplayNames.push_back( EventDisplayName( "unloaded", RID_SVXSTR_EVENT_UNLOADED ) );
305 0 : aDisplayNames.push_back( EventDisplayName( "confirmDelete", RID_SVXSTR_EVENT_CONFIRMDELETE ) );
306 0 : aDisplayNames.push_back( EventDisplayName( "approveRowChange", RID_SVXSTR_EVENT_APPROVEROWCHANGE ) );
307 0 : aDisplayNames.push_back( EventDisplayName( "rowChanged", RID_SVXSTR_EVENT_ROWCHANGE ) );
308 0 : aDisplayNames.push_back( EventDisplayName( "approveCursorMove", RID_SVXSTR_EVENT_POSITIONING ) );
309 0 : aDisplayNames.push_back( EventDisplayName( "cursorMoved", RID_SVXSTR_EVENT_POSITIONED ) );
310 0 : aDisplayNames.push_back( EventDisplayName( "approveParameter", RID_SVXSTR_EVENT_APPROVEPARAMETER ) );
311 0 : aDisplayNames.push_back( EventDisplayName( "errorOccurred", RID_SVXSTR_EVENT_ERROROCCURRED ) );
312 0 : aDisplayNames.push_back( EventDisplayName( "adjustmentValueChanged", RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED ) );
313 0 : }
314 :
315 : // the following method is called when the user clicks OK
316 : // We use the contents of the hashes to replace the settings
317 0 : bool _SvxMacroTabPage::FillItemSet( SfxItemSet* /*rSet*/ )
318 : {
319 : try
320 : {
321 0 : OUString eventName;
322 0 : if( m_xAppEvents.is() )
323 : {
324 0 : EventsHash::iterator h_itEnd = m_appEventsHash.end();
325 0 : EventsHash::iterator h_it = m_appEventsHash.begin();
326 0 : for ( ; h_it != h_itEnd; ++h_it )
327 : {
328 0 : eventName = h_it->first;
329 : try
330 : {
331 0 : m_xAppEvents->replaceByName( eventName, GetPropsByName( eventName, m_appEventsHash ) );
332 : }
333 0 : catch (const Exception&)
334 : {
335 : DBG_UNHANDLED_EXCEPTION();
336 : }
337 : }
338 : }
339 0 : if( m_xDocEvents.is() && bDocModified )
340 : {
341 0 : EventsHash::iterator h_itEnd = m_docEventsHash.end();
342 0 : EventsHash::iterator h_it = m_docEventsHash.begin();
343 0 : for ( ; h_it != h_itEnd; ++h_it )
344 : {
345 0 : eventName = h_it->first;
346 : try
347 : {
348 0 : m_xDocEvents->replaceByName( eventName, GetPropsByName( eventName, m_docEventsHash ) );
349 : }
350 0 : catch (const Exception&)
351 : {
352 : DBG_UNHANDLED_EXCEPTION();
353 : }
354 : }
355 : // if we have a valid XModifiable (in the case of doc events)
356 : // call setModified(true)
357 : // in principle this should not be necessary (see issue ??)
358 0 : if(m_xModifiable.is())
359 : {
360 0 : m_xModifiable->setModified( sal_True );
361 : }
362 0 : }
363 : }
364 0 : catch (const Exception&)
365 : {
366 : }
367 : // what is the return value about??
368 0 : return false;
369 : }
370 :
371 : // the following method clears the bindings in the hashes for both doc & app
372 0 : void _SvxMacroTabPage::Reset( const SfxItemSet* )
373 : {
374 : // called once in creation - don't reset the data this time
375 0 : if(!bInitialized)
376 : {
377 0 : bInitialized = true;
378 0 : return;
379 : }
380 :
381 : try
382 : {
383 0 : OUString sEmpty;
384 0 : if( m_xAppEvents.is() )
385 : {
386 0 : EventsHash::iterator h_itEnd = m_appEventsHash.end();
387 0 : EventsHash::iterator h_it = m_appEventsHash.begin();
388 0 : for ( ; h_it != h_itEnd; ++h_it )
389 : {
390 0 : h_it->second.second = sEmpty;
391 : }
392 : }
393 0 : if( m_xDocEvents.is() && bDocModified )
394 : {
395 0 : EventsHash::iterator h_itEnd = m_docEventsHash.end();
396 0 : EventsHash::iterator h_it = m_docEventsHash.begin();
397 0 : for ( ; h_it != h_itEnd; ++h_it )
398 : {
399 0 : h_it->second.second = sEmpty;
400 : }
401 : // if we have a valid XModifiable (in the case of doc events)
402 : // call setModified(true)
403 0 : if(m_xModifiable.is())
404 : {
405 0 : m_xModifiable->setModified( sal_True );
406 : }
407 0 : }
408 : }
409 0 : catch (const Exception&)
410 : {
411 : }
412 0 : DisplayAppEvents(bAppEvents);
413 : }
414 :
415 0 : void _SvxMacroTabPage::SetReadOnly( bool bSet )
416 : {
417 0 : mpImpl->bReadOnly = bSet;
418 0 : }
419 :
420 0 : bool _SvxMacroTabPage::IsReadOnly() const
421 : {
422 0 : return mpImpl->bReadOnly;
423 : }
424 :
425 :
426 0 : class IconLBoxString : public SvLBoxString
427 : {
428 : Image* m_pMacroImg;
429 : Image* m_pComponentImg;
430 : int m_nxImageOffset;
431 :
432 : public:
433 : IconLBoxString( SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& sText,
434 : Image* pMacroImg, Image* pComponentImg );
435 : virtual void Paint(
436 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
437 : };
438 :
439 :
440 0 : IconLBoxString::IconLBoxString( SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& sText,
441 : Image* pMacroImg, Image* pComponentImg )
442 : : SvLBoxString( pEntry, nFlags, sText )
443 : , m_pMacroImg( pMacroImg )
444 0 : , m_pComponentImg( pComponentImg )
445 : {
446 0 : m_nxImageOffset = 20;
447 0 : }
448 :
449 :
450 0 : void IconLBoxString::Paint(
451 : const Point& aPos, SvTreeListBox& aDevice, const SvViewDataEntry* /*pView*/,
452 : const SvTreeListEntry* /*pEntry*/)
453 : {
454 0 : OUString aTxt( GetText() );
455 0 : if( !aTxt.isEmpty() )
456 : {
457 0 : OUString aURL( aTxt );
458 0 : sal_Int32 nIndex = aURL.indexOf( aVndSunStarUNO );
459 0 : bool bUNO = nIndex == 0;
460 :
461 0 : const Image* pImg = bUNO ? m_pComponentImg : m_pMacroImg;
462 0 : aDevice.DrawImage( aPos, *pImg );
463 :
464 0 : OUString aPureMethod;
465 0 : if( bUNO )
466 : {
467 0 : sal_Int32 nBegin = aVndSunStarUNO.getLength();
468 0 : aPureMethod = aURL.copy( nBegin );
469 : }
470 : else
471 : {
472 0 : sal_Int32 nBegin = aVndSunStarScript.getLength();
473 0 : aPureMethod = aURL.copy( nBegin );
474 0 : aPureMethod = aPureMethod.copy( 0, aPureMethod.indexOf( '?' ) );
475 : }
476 :
477 0 : Point aPnt(aPos);
478 0 : aPnt.X() += m_nxImageOffset;
479 0 : aDevice.DrawText( aPnt, aPureMethod );
480 0 : }
481 0 : }
482 :
483 :
484 : // displays the app events if appEvents=true, otherwise displays the doc events
485 0 : void _SvxMacroTabPage::DisplayAppEvents( bool appEvents)
486 : {
487 0 : bAppEvents = appEvents;
488 :
489 0 : SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
490 0 : mpImpl->pEventLB->SetUpdateMode( false );
491 0 : rListBox.Clear();
492 : EventsHash* eventsHash;
493 0 : Reference< container::XNameReplace> nameReplace;
494 0 : if(bAppEvents)
495 : {
496 0 : eventsHash = &m_appEventsHash;
497 0 : nameReplace = m_xAppEvents;
498 : }
499 : else
500 : {
501 0 : eventsHash = &m_docEventsHash;
502 0 : nameReplace = m_xDocEvents;
503 : }
504 : // have to use the original XNameReplace since the hash iterators do
505 : // not guarantee the order in which the elements are returned
506 0 : if(!nameReplace.is())
507 0 : return;
508 :
509 0 : Sequence< OUString > eventNames = nameReplace->getElementNames();
510 0 : ::std::set< OUString > aEventNamesCache;
511 : ::std::copy(
512 : eventNames.getConstArray(),
513 0 : eventNames.getConstArray() + eventNames.getLength(),
514 : ::std::insert_iterator< ::std::set< OUString > >( aEventNamesCache, aEventNamesCache.end() )
515 0 : );
516 :
517 0 : for ( EventDisplayNames::const_iterator displayableEvent = aDisplayNames.begin();
518 0 : displayableEvent != aDisplayNames.end();
519 : ++displayableEvent
520 : )
521 : {
522 0 : OUString sEventName( OUString::createFromAscii( displayableEvent->pAsciiEventName ) );
523 0 : if ( !nameReplace->hasByName( sEventName ) )
524 0 : continue;
525 :
526 0 : EventsHash::iterator h_it = eventsHash->find( sEventName );
527 0 : if( h_it == eventsHash->end() )
528 : {
529 : OSL_FAIL( "_SvxMacroTabPage::DisplayAppEvents: something's suspicious here!" );
530 0 : continue;
531 : }
532 :
533 0 : OUString eventURL = h_it->second.second;
534 0 : OUString displayName( CUI_RES( displayableEvent->nEventResourceID ) );
535 :
536 0 : displayName += "\t";
537 :
538 0 : SvTreeListEntry* _pE = rListBox.InsertEntry( displayName );
539 0 : OUString* pEventName = new OUString( sEventName );
540 0 : _pE->SetUserData( (void*)pEventName );
541 0 : OUString sNew( eventURL );
542 : _pE->ReplaceItem( new IconLBoxString( _pE, 0, sNew,
543 0 : &mpImpl->aMacroImg, &mpImpl->aComponentImg ), LB_MACROS_ITEMPOS );
544 0 : rListBox.GetModel()->InvalidateEntry( _pE );
545 0 : rListBox.Select( _pE );
546 0 : rListBox.MakeVisible( _pE );
547 0 : }
548 :
549 0 : SvTreeListEntry* pE = rListBox.GetEntry(0);
550 0 : if( pE )
551 : {
552 0 : rListBox.Select( pE );
553 0 : rListBox.MakeVisible( pE );
554 : }
555 :
556 0 : rListBox.SetUpdateMode( true );
557 0 : EnableButtons();
558 : }
559 :
560 : // select event handler on the listbox
561 0 : IMPL_STATIC_LINK( _SvxMacroTabPage, SelectEvent_Impl, SvTabListBox*, EMPTYARG )
562 : {
563 0 : _SvxMacroTabPage_Impl* pImpl = pThis->mpImpl;
564 0 : SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
565 0 : SvTreeListEntry* pE = rListBox.FirstSelected();
566 : sal_uLong nPos;
567 :
568 0 : if( !pE || LISTBOX_ENTRY_NOTFOUND ==
569 0 : ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
570 : {
571 : DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
572 0 : return 0;
573 : }
574 :
575 0 : pThis->EnableButtons();
576 0 : return 0;
577 : }
578 :
579 0 : IMPL_STATIC_LINK( _SvxMacroTabPage, AssignDeleteHdl_Impl, PushButton*, pBtn )
580 : {
581 0 : return GenericHandler_Impl( pThis, pBtn );
582 : }
583 :
584 0 : IMPL_STATIC_LINK( _SvxMacroTabPage, DoubleClickHdl_Impl, SvTabListBox *, EMPTYARG )
585 : {
586 0 : return GenericHandler_Impl( pThis, NULL );
587 : }
588 :
589 : // handler for double click on the listbox, and for the assign/delete buttons
590 0 : long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage* pThis, PushButton* pBtn )
591 : {
592 0 : _SvxMacroTabPage_Impl* pImpl = pThis->mpImpl;
593 0 : SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
594 0 : SvTreeListEntry* pE = rListBox.FirstSelected();
595 : sal_uLong nPos;
596 0 : if( !pE || LISTBOX_ENTRY_NOTFOUND ==
597 0 : ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
598 : {
599 : DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
600 0 : return 0;
601 : }
602 :
603 0 : const bool bAssEnabled = pBtn != pImpl->pDeletePB && pImpl->pAssignPB->IsEnabled();
604 :
605 0 : OUString* pEventName = (OUString*)pE->GetUserData();
606 :
607 0 : OUString sEventURL;
608 0 : OUString sEventType;
609 0 : if(pThis->bAppEvents)
610 : {
611 0 : EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
612 0 : if(h_it != pThis->m_appEventsHash.end() )
613 : {
614 0 : sEventType = h_it->second.first;
615 0 : sEventURL = h_it->second.second;
616 : }
617 : }
618 : else
619 : {
620 0 : EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
621 0 : if(h_it != pThis->m_docEventsHash.end() )
622 : {
623 0 : sEventType = h_it->second.first;
624 0 : sEventURL = h_it->second.second;
625 : }
626 : }
627 :
628 0 : bool bDoubleClick = (pBtn == NULL);
629 0 : bool bUNOAssigned = sEventURL.startsWith( aVndSunStarUNO );
630 0 : if( pBtn == pImpl->pDeletePB )
631 : {
632 : // delete pressed
633 0 : sEventType = "Script" ;
634 0 : sEventURL = "";
635 0 : if(!pThis->bAppEvents)
636 0 : pThis->bDocModified = true;
637 : }
638 0 : else if ( ( ( pBtn != NULL )
639 0 : && ( pBtn == pImpl->pAssignComponentPB )
640 : )
641 0 : || ( bDoubleClick
642 0 : && bUNOAssigned
643 : )
644 : )
645 : {
646 0 : boost::scoped_ptr<AssignComponentDialog> pAssignDlg(new AssignComponentDialog( pThis, sEventURL ));
647 :
648 0 : short ret = pAssignDlg->Execute();
649 0 : if( ret )
650 : {
651 0 : sEventType = "UNO";
652 0 : sEventURL = pAssignDlg->getURL();
653 0 : if(!pThis->bAppEvents)
654 0 : pThis->bDocModified = true;
655 0 : }
656 : }
657 0 : else if( bAssEnabled )
658 : {
659 : // assign pressed
660 0 : boost::scoped_ptr<SvxScriptSelectorDialog> pDlg(new SvxScriptSelectorDialog( pThis, false, pThis->GetFrame() ));
661 0 : if( pDlg )
662 : {
663 0 : short ret = pDlg->Execute();
664 0 : if ( ret )
665 : {
666 0 : sEventType = "Script";
667 0 : sEventURL = pDlg->GetScriptURL();
668 0 : if(!pThis->bAppEvents)
669 0 : pThis->bDocModified = true;
670 : }
671 0 : }
672 : }
673 :
674 : // update the hashes
675 0 : if(pThis->bAppEvents)
676 : {
677 0 : EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
678 0 : h_it->second.first = sEventType;
679 0 : h_it->second.second = sEventURL;
680 : }
681 : else
682 : {
683 0 : EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
684 0 : h_it->second.first = sEventType;
685 0 : h_it->second.second = sEventURL;
686 : }
687 :
688 : // update the listbox entry
689 0 : pImpl->pEventLB->SetUpdateMode( false );
690 : pE->ReplaceItem( new IconLBoxString( pE, 0, sEventURL,
691 0 : &pImpl->aMacroImg, &pImpl->aComponentImg ), LB_MACROS_ITEMPOS );
692 :
693 0 : rListBox.GetModel()->InvalidateEntry( pE );
694 0 : rListBox.Select( pE );
695 0 : rListBox.MakeVisible( pE );
696 0 : rListBox.SetUpdateMode( true );
697 :
698 0 : pThis->EnableButtons();
699 0 : return 0;
700 : }
701 :
702 : // pass in the XNameReplace.
703 : // can remove the 3rd arg once issue ?? is fixed
704 0 : void _SvxMacroTabPage::InitAndSetHandler( Reference< container::XNameReplace> xAppEvents, Reference< container::XNameReplace> xDocEvents, Reference< util::XModifiable > xModifiable )
705 : {
706 0 : m_xAppEvents = xAppEvents;
707 0 : m_xDocEvents = xDocEvents;
708 0 : m_xModifiable = xModifiable;
709 0 : SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
710 0 : HeaderBar& rHeaderBar = mpImpl->pEventLB->GetHeaderBar();
711 0 : Link aLnk(STATIC_LINK(this, _SvxMacroTabPage, AssignDeleteHdl_Impl ));
712 0 : mpImpl->pDeletePB->SetClickHdl( aLnk );
713 0 : mpImpl->pAssignPB->SetClickHdl( aLnk );
714 0 : if( mpImpl->pAssignComponentPB )
715 0 : mpImpl->pAssignComponentPB->SetClickHdl( aLnk );
716 0 : rListBox.SetDoubleClickHdl( STATIC_LINK(this, _SvxMacroTabPage, DoubleClickHdl_Impl ) );
717 :
718 0 : rListBox.SetSelectHdl( STATIC_LINK( this, _SvxMacroTabPage, SelectEvent_Impl ));
719 :
720 0 : rListBox.SetSelectionMode( SINGLE_SELECTION );
721 0 : rListBox.SetTabs( &nTabs[0], MAP_APPFONT );
722 0 : Size aSize( nTabs[ 2 ], 0 );
723 0 : rHeaderBar.InsertItem( ITEMID_EVENT, mpImpl->sStrEvent, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
724 0 : aSize.Width() = 1764; // don't know what, so 42^2 is best to use...
725 0 : rHeaderBar.InsertItem( ITMEID_ASSMACRO, mpImpl->sAssignedMacro, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
726 0 : rListBox.SetSpaceBetweenEntries( 0 );
727 :
728 0 : mpImpl->pEventLB->Show();
729 0 : mpImpl->pEventLB->ConnectElements();
730 :
731 0 : long nMinLineHeight = mpImpl->aMacroImg.GetSizePixel().Height() + 2;
732 0 : if( nMinLineHeight > mpImpl->pEventLB->GetListBox().GetEntryHeight() )
733 0 : mpImpl->pEventLB->GetListBox().SetEntryHeight(
734 0 : sal::static_int_cast< short >(nMinLineHeight) );
735 :
736 0 : mpImpl->pEventLB->Enable( true );
737 :
738 0 : if(!m_xAppEvents.is())
739 : {
740 0 : return;
741 : }
742 0 : Sequence< OUString > eventNames = m_xAppEvents->getElementNames();
743 0 : sal_Int32 nEventCount = eventNames.getLength();
744 0 : for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
745 : {
746 : //need exception handling here
747 : try
748 : {
749 0 : m_appEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xAppEvents->getByName( eventNames[nEvent] ) );
750 : }
751 0 : catch (const Exception&)
752 : {
753 : }
754 : }
755 0 : if(m_xDocEvents.is())
756 : {
757 0 : eventNames = m_xDocEvents->getElementNames();
758 0 : nEventCount = eventNames.getLength();
759 0 : for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
760 : {
761 : try
762 : {
763 0 : m_docEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xDocEvents->getByName( eventNames[nEvent] ) );
764 : }
765 0 : catch (const Exception&)
766 : {
767 : }
768 : }
769 0 : }
770 : }
771 :
772 : // returns the two props EventType & Script for a given event name
773 0 : Any _SvxMacroTabPage::GetPropsByName( const OUString& eventName, EventsHash& eventsHash )
774 : {
775 0 : const ::std::pair< OUString, OUString >& rAssignedEvent( eventsHash[ eventName ] );
776 :
777 0 : Any aReturn;
778 0 : ::comphelper::NamedValueCollection aProps;
779 0 : if ( !(rAssignedEvent.first.isEmpty() || rAssignedEvent.second.isEmpty()) )
780 : {
781 0 : aProps.put( "EventType", rAssignedEvent.first );
782 0 : aProps.put( "Script", rAssignedEvent.second );
783 : }
784 0 : aReturn <<= aProps.getPropertyValues();
785 :
786 0 : return aReturn;
787 : }
788 :
789 : // converts the Any returned by GetByName into a pair which can be stored in
790 : // the EventHash
791 0 : ::std::pair< OUString, OUString > _SvxMacroTabPage::GetPairFromAny( Any aAny )
792 : {
793 0 : Sequence< beans::PropertyValue > props;
794 0 : OUString type, url;
795 0 : if( aAny >>= props )
796 : {
797 0 : ::comphelper::NamedValueCollection aProps( props );
798 0 : type = aProps.getOrDefault( "EventType", type );
799 0 : url = aProps.getOrDefault( "Script", url );
800 : }
801 0 : return ::std::make_pair( type, url );
802 : }
803 :
804 0 : SvxMacroTabPage::SvxMacroTabPage(vcl::Window* pParent,
805 : const Reference< frame::XFrame >& _rxDocumentFrame,
806 : const SfxItemSet& rSet,
807 : Reference< container::XNameReplace > xNameReplace,
808 : sal_uInt16 nSelectedIndex)
809 0 : : _SvxMacroTabPage(pParent, "MacroAssignPage", "cui/ui/macroassignpage.ui", rSet)
810 : {
811 0 : mpImpl->sStrEvent = get<FixedText>("eventft")->GetText();
812 0 : mpImpl->sAssignedMacro = get<FixedText>("assignft")->GetText();
813 0 : get(mpImpl->pEventLB, "assignments");
814 0 : get(mpImpl->pAssignPB, "assign");
815 0 : get(mpImpl->pDeletePB, "delete");
816 0 : get(mpImpl->pAssignComponentPB, "component");
817 0 : mpImpl->aMacroImg = get<FixedImage>("macroimg")->GetImage();
818 0 : mpImpl->aComponentImg = get<FixedImage>("componentimg")->GetImage();
819 :
820 0 : SetFrame( _rxDocumentFrame );
821 :
822 0 : if( !mpImpl->bIDEDialogMode )
823 : {
824 0 : mpImpl->pAssignComponentPB->Hide();
825 0 : mpImpl->pAssignComponentPB->Disable();
826 : }
827 :
828 0 : InitResources();
829 :
830 0 : InitAndSetHandler( xNameReplace, Reference< container::XNameReplace>(0), Reference< util::XModifiable >(0));
831 0 : DisplayAppEvents(true);
832 0 : SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
833 0 : SvTreeListEntry* pE = rListBox.GetEntry( (sal_uLong)nSelectedIndex );
834 0 : if( pE )
835 0 : rListBox.Select(pE);
836 0 : }
837 :
838 0 : SvxMacroAssignDlg::SvxMacroAssignDlg( vcl::Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet,
839 : const Reference< container::XNameReplace >& xNameReplace, sal_uInt16 nSelectedIndex )
840 0 : : SvxMacroAssignSingleTabDialog(pParent, rSet)
841 : {
842 0 : SetTabPage(new SvxMacroTabPage(get_content_area(), _rxDocumentFrame, rSet, xNameReplace, nSelectedIndex));
843 0 : }
844 :
845 :
846 :
847 0 : IMPL_LINK_NOARG(AssignComponentDialog, ButtonHandler)
848 : {
849 0 : OUString aMethodName = mpMethodEdit->GetText();
850 0 : maURL = "";
851 0 : if( !aMethodName.isEmpty() )
852 : {
853 0 : maURL = aVndSunStarUNO;
854 0 : maURL += aMethodName;
855 : }
856 0 : EndDialog(1);
857 0 : return 0;
858 : }
859 :
860 0 : AssignComponentDialog::AssignComponentDialog( vcl::Window * pParent, const OUString& rURL )
861 : : ModalDialog( pParent, "AssignComponent", "cui/ui/assigncomponentdialog.ui" )
862 0 : , maURL( rURL )
863 : {
864 0 : get(mpMethodEdit, "methodEntry");
865 0 : get(mpOKButton, "ok");
866 0 : mpOKButton->SetClickHdl(LINK(this, AssignComponentDialog, ButtonHandler));
867 :
868 0 : OUString aMethodName;
869 0 : if( maURL.startsWith( aVndSunStarUNO ) )
870 : {
871 0 : sal_Int32 nBegin = aVndSunStarUNO.getLength();
872 0 : aMethodName = maURL.copy( nBegin );
873 : }
874 0 : mpMethodEdit->SetText( aMethodName, Selection( 0, SELECTION_MAX ) );
875 0 : }
876 :
877 0 : AssignComponentDialog::~AssignComponentDialog()
878 : {
879 0 : }
880 :
881 :
882 :
883 0 : IMPL_LINK( SvxMacroAssignSingleTabDialog, OKHdl_Impl, Button *, pButton )
884 : {
885 : (void)pButton; //unused
886 0 : GetTabPage()->FillItemSet( 0 );
887 0 : EndDialog( RET_OK );
888 0 : return 0;
889 : }
890 :
891 :
892 :
893 0 : SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog(vcl::Window *pParent,
894 : const SfxItemSet& rSet)
895 0 : : SfxSingleTabDialog(pParent, rSet, "MacroAssignDialog", "cui/ui/macroassigndialog.ui")
896 : {
897 0 : GetOKButton()->SetClickHdl( LINK( this, SvxMacroAssignSingleTabDialog, OKHdl_Impl ) );
898 0 : }
899 :
900 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|