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