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