masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / customize / eventdlg.cxx
blobde4b8dcbf46225789e3b5db3382a7f6227149c61
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 // include ***************************************************************
32 #include <svtools/svmedit.hxx>
33 #include <tools/diagnose_ex.h>
34 #include <com/sun/star/document/XEventsSupplier.hpp>
35 #include <com/sun/star/frame/XModuleManager.hpp>
37 #include <comphelper/processfactory.hxx>
38 #include <comphelper/documentinfo.hxx>
39 #include <unotools/configmgr.hxx>
40 #include <rtl/ustring.hxx>
42 #include "eventdlg.hxx"
44 #include <sfx2/viewfrm.hxx>
45 #include <sfx2/evntconf.hxx>
46 #include <sfx2/minfitem.hxx>
47 #include <sfx2/app.hxx>
48 #include <sfx2/objsh.hxx>
49 #include <sfx2/docfac.hxx>
50 #include <sfx2/fcontnr.hxx>
51 #include <unotools/eventcfg.hxx>
53 #include "headertablistbox.hxx"
54 #include "macropg_impl.hxx"
56 #include <dialmgr.hxx>
57 #include <cuires.hrc>
58 #include "eventdlg.hrc"
59 #include "helpid.hrc"
60 #include "selector.hxx"
61 #include "cfg.hxx"
64 using ::rtl::OUString;
65 using namespace ::com::sun::star;
66 // -----------------------------------------------------------------------
68 SvxEventConfigPage::SvxEventConfigPage( Window *pParent, const SfxItemSet& rSet, SvxEventConfigPage::EarlyInit ) :
70 _SvxMacroTabPage( pParent, CUI_RES(RID_SVXPAGE_EVENTS), rSet ),
71 aSaveInText( this, CUI_RES( TXT_SAVEIN ) ),
72 aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ),
73 bAppConfig ( sal_True )
75 mpImpl->pStrEvent = new String( CUI_RES( STR_EVENT ));
76 mpImpl->pAssignedMacro = new String( CUI_RES( STR_ASSMACRO ));
77 mpImpl->pEventLB = new _HeaderTabListBox( this, CUI_RES( LB_EVENT ));
78 mpImpl->pAssignFT = new FixedText( this, CUI_RES( FT_ASSIGN ));
79 mpImpl->pAssignPB = new PushButton( this, CUI_RES( PB_ASSIGN ));
80 mpImpl->pDeletePB = new PushButton( this, CUI_RES( PB_DELETE ));
81 mpImpl->pMacroImg = new Image( CUI_RES( IMG_MACRO) );
82 mpImpl->pComponentImg = new Image( CUI_RES( IMG_COMPONENT) );
83 mpImpl->pMacroImg_h = new Image( CUI_RES( IMG_MACRO_H) );
84 mpImpl->pComponentImg_h = new Image( CUI_RES( IMG_COMPONENT_H) );
86 FreeResource();
88 // must be done after FreeResource is called
89 InitResources();
91 mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT );
93 aSaveInListBox.SetSelectHdl( LINK( this, SvxEventConfigPage,
94 SelectHdl_Impl ) );
96 uno::Reference< document::XEventsSupplier > xSupplier;
98 // xSupplier = uno::Reference< document::XEventsSupplier >( new GlobalEventConfig());
99 xSupplier = uno::Reference< document::XEventsSupplier > (
100 ::comphelper::getProcessServiceFactory()->createInstance(
101 OUString::createFromAscii(
102 "com.sun.star.frame.GlobalEventBroadcaster" ) ),
103 uno::UNO_QUERY );
105 sal_uInt16 nPos(0);
106 if ( xSupplier.is() )
108 m_xAppEvents = xSupplier->getEvents();
109 OUString label;
110 utl::ConfigManager::GetDirectConfigProperty(
111 utl::ConfigManager::PRODUCTNAME ) >>= label;
112 nPos = aSaveInListBox.InsertEntry( label );
113 aSaveInListBox.SetEntryData( nPos, new bool(true) );
114 aSaveInListBox.SelectEntryPos( nPos, sal_True );
118 // -----------------------------------------------------------------------
119 void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame )
121 SetFrame( _rxFrame );
122 ImplInitDocument();
124 InitAndSetHandler( m_xAppEvents, m_xDocumentEvents, m_xDocumentModifiable );
126 SelectHdl_Impl( NULL );
129 // -----------------------------------------------------------------------
131 SvxEventConfigPage::~SvxEventConfigPage()
133 //DF Do I need to delete bools?
136 // -----------------------------------------------------------------------
138 void SvxEventConfigPage::ImplInitDocument()
140 uno::Reference< frame::XFrame > xFrame( GetFrame() );
141 OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame );
142 if ( !xFrame.is() )
143 return;
147 uno::Reference< frame::XModel > xModel;
148 if ( !SvxConfigPage::CanConfig( aModuleId ) )
149 return;
151 uno::Reference< frame::XController > xController =
152 xFrame->getController();
154 if ( xController.is() )
156 xModel = xController->getModel();
159 if ( !xModel.is() )
160 return;
162 uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY );
164 if ( xSupplier.is() )
166 m_xDocumentEvents = xSupplier->getEvents();
167 m_xDocumentModifiable = m_xDocumentModifiable.query( xModel );
169 OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
170 sal_uInt16 nPos = aSaveInListBox.InsertEntry( aTitle );
172 aSaveInListBox.SetEntryData( nPos, new bool(false) );
173 aSaveInListBox.SelectEntryPos( nPos, sal_True );
175 bAppConfig = false;
178 catch( const uno::Exception& )
180 DBG_UNHANDLED_EXCEPTION();
184 // -----------------------------------------------------------------------
186 IMPL_LINK( SvxEventConfigPage, SelectHdl_Impl, ListBox *, pBox )
188 (void)pBox;
190 bool* bApp = (bool*) aSaveInListBox.GetEntryData(
191 aSaveInListBox.GetSelectEntryPos());
193 mpImpl->pEventLB->SetUpdateMode( sal_False );
194 bAppConfig = *bApp;
195 if ( *bApp )
197 SetReadOnly( sal_False );
198 _SvxMacroTabPage::DisplayAppEvents( true );
200 else
202 bool isReadonly = sal_False;
204 uno::Reference< frame::XFramesSupplier > xFramesSupplier(
205 ::comphelper::getProcessServiceFactory()->createInstance(
206 OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
207 uno::UNO_QUERY );
209 uno::Reference< frame::XFrame > xFrame =
210 xFramesSupplier->getActiveFrame();
212 if ( xFrame.is() )
214 uno::Reference< frame::XController > xController =
215 xFrame->getController();
217 if ( xController.is() )
219 uno::Reference< frame::XStorable > xStorable(
220 xController->getModel(), uno::UNO_QUERY );
221 isReadonly = xStorable->isReadonly();
225 SetReadOnly( isReadonly );
226 _SvxMacroTabPage::DisplayAppEvents( false );
229 mpImpl->pEventLB->SetUpdateMode( sal_True );
230 return sal_True;
233 // -----------------------------------------------------------------------
235 sal_Bool SvxEventConfigPage::FillItemSet( SfxItemSet& rSet )
237 return _SvxMacroTabPage::FillItemSet( rSet );
240 // -----------------------------------------------------------------------
242 void SvxEventConfigPage::Reset( const SfxItemSet& )
244 _SvxMacroTabPage::Reset();