1*2ee96f1cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2ee96f1cSAndrew Rist * distributed with this work for additional information 6*2ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance 9*2ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2ee96f1cSAndrew Rist * software distributed under the License is distributed on an 15*2ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the 17*2ee96f1cSAndrew Rist * specific language governing permissions and limitations 18*2ee96f1cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2ee96f1cSAndrew Rist *************************************************************/ 21*2ee96f1cSAndrew Rist 22*2ee96f1cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cui.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // include *************************************************************** 28cdf0e10cSrcweir #include <svtools/svmedit.hxx> 29cdf0e10cSrcweir #include <tools/diagnose_ex.h> 30cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp> 31cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 34cdf0e10cSrcweir #include <comphelper/documentinfo.hxx> 35cdf0e10cSrcweir #include <unotools/configmgr.hxx> 36cdf0e10cSrcweir #include <rtl/ustring.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include "eventdlg.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 41cdf0e10cSrcweir #include <sfx2/evntconf.hxx> 42cdf0e10cSrcweir #include <sfx2/minfitem.hxx> 43cdf0e10cSrcweir #include <sfx2/app.hxx> 44cdf0e10cSrcweir #include <sfx2/objsh.hxx> 45cdf0e10cSrcweir #include <sfx2/docfac.hxx> 46cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 47cdf0e10cSrcweir #include <unotools/eventcfg.hxx> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include "headertablistbox.hxx" 50cdf0e10cSrcweir #include "macropg_impl.hxx" 51cdf0e10cSrcweir 52cdf0e10cSrcweir #include <dialmgr.hxx> 53cdf0e10cSrcweir #include <cuires.hrc> 54cdf0e10cSrcweir #include "eventdlg.hrc" 55cdf0e10cSrcweir #include "helpid.hrc" 56cdf0e10cSrcweir #include "selector.hxx" 57cdf0e10cSrcweir #include "cfg.hxx" 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir using ::rtl::OUString; 61cdf0e10cSrcweir using namespace ::com::sun::star; 62cdf0e10cSrcweir // ----------------------------------------------------------------------- 63cdf0e10cSrcweir 64cdf0e10cSrcweir SvxEventConfigPage::SvxEventConfigPage( Window *pParent, const SfxItemSet& rSet, SvxEventConfigPage::EarlyInit ) : 65cdf0e10cSrcweir 66cdf0e10cSrcweir _SvxMacroTabPage( pParent, CUI_RES(RID_SVXPAGE_EVENTS), rSet ), 67cdf0e10cSrcweir aSaveInText( this, CUI_RES( TXT_SAVEIN ) ), 68cdf0e10cSrcweir aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ), 69cdf0e10cSrcweir bAppConfig ( sal_True ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir mpImpl->pStrEvent = new String( CUI_RES( STR_EVENT )); 72cdf0e10cSrcweir mpImpl->pAssignedMacro = new String( CUI_RES( STR_ASSMACRO )); 73cdf0e10cSrcweir mpImpl->pEventLB = new _HeaderTabListBox( this, CUI_RES( LB_EVENT )); 74cdf0e10cSrcweir mpImpl->pAssignFT = new FixedText( this, CUI_RES( FT_ASSIGN )); 75cdf0e10cSrcweir mpImpl->pAssignPB = new PushButton( this, CUI_RES( PB_ASSIGN )); 76cdf0e10cSrcweir mpImpl->pDeletePB = new PushButton( this, CUI_RES( PB_DELETE )); 77cdf0e10cSrcweir mpImpl->pMacroImg = new Image( CUI_RES( IMG_MACRO) ); 78cdf0e10cSrcweir mpImpl->pComponentImg = new Image( CUI_RES( IMG_COMPONENT) ); 79cdf0e10cSrcweir mpImpl->pMacroImg_h = new Image( CUI_RES( IMG_MACRO_H) ); 80cdf0e10cSrcweir mpImpl->pComponentImg_h = new Image( CUI_RES( IMG_COMPONENT_H) ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir FreeResource(); 83cdf0e10cSrcweir 84cdf0e10cSrcweir // must be done after FreeResource is called 85cdf0e10cSrcweir InitResources(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT ); 88cdf0e10cSrcweir 89cdf0e10cSrcweir aSaveInListBox.SetSelectHdl( LINK( this, SvxEventConfigPage, 90cdf0e10cSrcweir SelectHdl_Impl ) ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir uno::Reference< document::XEventsSupplier > xSupplier; 93cdf0e10cSrcweir 94cdf0e10cSrcweir // xSupplier = uno::Reference< document::XEventsSupplier >( new GlobalEventConfig()); 95cdf0e10cSrcweir xSupplier = uno::Reference< document::XEventsSupplier > ( 96cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance( 97cdf0e10cSrcweir OUString::createFromAscii( 98cdf0e10cSrcweir "com.sun.star.frame.GlobalEventBroadcaster" ) ), 99cdf0e10cSrcweir uno::UNO_QUERY ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir sal_uInt16 nPos(0); 102cdf0e10cSrcweir if ( xSupplier.is() ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir m_xAppEvents = xSupplier->getEvents(); 105cdf0e10cSrcweir OUString label; 106cdf0e10cSrcweir utl::ConfigManager::GetDirectConfigProperty( 107cdf0e10cSrcweir utl::ConfigManager::PRODUCTNAME ) >>= label; 108cdf0e10cSrcweir nPos = aSaveInListBox.InsertEntry( label ); 109cdf0e10cSrcweir aSaveInListBox.SetEntryData( nPos, new bool(true) ); 110cdf0e10cSrcweir aSaveInListBox.SelectEntryPos( nPos, sal_True ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ----------------------------------------------------------------------- 115cdf0e10cSrcweir void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir SetFrame( _rxFrame ); 118cdf0e10cSrcweir ImplInitDocument(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir InitAndSetHandler( m_xAppEvents, m_xDocumentEvents, m_xDocumentModifiable ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir SelectHdl_Impl( NULL ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir // ----------------------------------------------------------------------- 126cdf0e10cSrcweir 127cdf0e10cSrcweir SvxEventConfigPage::~SvxEventConfigPage() 128cdf0e10cSrcweir { 129cdf0e10cSrcweir //DF Do I need to delete bools? 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir // ----------------------------------------------------------------------- 133cdf0e10cSrcweir 134cdf0e10cSrcweir void SvxEventConfigPage::ImplInitDocument() 135cdf0e10cSrcweir { 136cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( GetFrame() ); 137cdf0e10cSrcweir OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame ); 138cdf0e10cSrcweir if ( !xFrame.is() ) 139cdf0e10cSrcweir return; 140cdf0e10cSrcweir 141cdf0e10cSrcweir try 142cdf0e10cSrcweir { 143cdf0e10cSrcweir uno::Reference< frame::XModel > xModel; 144cdf0e10cSrcweir if ( !SvxConfigPage::CanConfig( aModuleId ) ) 145cdf0e10cSrcweir return; 146cdf0e10cSrcweir 147cdf0e10cSrcweir uno::Reference< frame::XController > xController = 148cdf0e10cSrcweir xFrame->getController(); 149cdf0e10cSrcweir 150cdf0e10cSrcweir if ( xController.is() ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir xModel = xController->getModel(); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir if ( !xModel.is() ) 156cdf0e10cSrcweir return; 157cdf0e10cSrcweir 158cdf0e10cSrcweir uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir if ( xSupplier.is() ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir m_xDocumentEvents = xSupplier->getEvents(); 163cdf0e10cSrcweir m_xDocumentModifiable = m_xDocumentModifiable.query( xModel ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel ); 166cdf0e10cSrcweir sal_uInt16 nPos = aSaveInListBox.InsertEntry( aTitle ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir aSaveInListBox.SetEntryData( nPos, new bool(false) ); 169cdf0e10cSrcweir aSaveInListBox.SelectEntryPos( nPos, sal_True ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir bAppConfig = false; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir catch( const uno::Exception& ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir // ----------------------------------------------------------------------- 181cdf0e10cSrcweir 182cdf0e10cSrcweir IMPL_LINK( SvxEventConfigPage, SelectHdl_Impl, ListBox *, pBox ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir (void)pBox; 185cdf0e10cSrcweir 186cdf0e10cSrcweir bool* bApp = (bool*) aSaveInListBox.GetEntryData( 187cdf0e10cSrcweir aSaveInListBox.GetSelectEntryPos()); 188cdf0e10cSrcweir 189cdf0e10cSrcweir mpImpl->pEventLB->SetUpdateMode( sal_False ); 190cdf0e10cSrcweir bAppConfig = *bApp; 191cdf0e10cSrcweir if ( *bApp ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir SetReadOnly( sal_False ); 194cdf0e10cSrcweir _SvxMacroTabPage::DisplayAppEvents( true ); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir else 197cdf0e10cSrcweir { 198cdf0e10cSrcweir bool isReadonly = sal_False; 199cdf0e10cSrcweir 200cdf0e10cSrcweir uno::Reference< frame::XFramesSupplier > xFramesSupplier( 201cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance( 202cdf0e10cSrcweir OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), 203cdf0e10cSrcweir uno::UNO_QUERY ); 204cdf0e10cSrcweir 205cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame = 206cdf0e10cSrcweir xFramesSupplier->getActiveFrame(); 207cdf0e10cSrcweir 208cdf0e10cSrcweir if ( xFrame.is() ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir uno::Reference< frame::XController > xController = 211cdf0e10cSrcweir xFrame->getController(); 212cdf0e10cSrcweir 213cdf0e10cSrcweir if ( xController.is() ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir uno::Reference< frame::XStorable > xStorable( 216cdf0e10cSrcweir xController->getModel(), uno::UNO_QUERY ); 217cdf0e10cSrcweir isReadonly = xStorable->isReadonly(); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir SetReadOnly( isReadonly ); 222cdf0e10cSrcweir _SvxMacroTabPage::DisplayAppEvents( false ); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir mpImpl->pEventLB->SetUpdateMode( sal_True ); 226cdf0e10cSrcweir return sal_True; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir // ----------------------------------------------------------------------- 230cdf0e10cSrcweir 231cdf0e10cSrcweir sal_Bool SvxEventConfigPage::FillItemSet( SfxItemSet& rSet ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir return _SvxMacroTabPage::FillItemSet( rSet ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir // ----------------------------------------------------------------------- 237cdf0e10cSrcweir 238cdf0e10cSrcweir void SvxEventConfigPage::Reset( const SfxItemSet& ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir _SvxMacroTabPage::Reset(); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243