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