LCOV - code coverage report
Current view: top level - libreoffice/cui/source/customize - macropg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 535 0.6 %
Date: 2012-12-27 Functions: 2 51 3.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10