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