xref: /aoo41x/main/cui/source/customize/eventdlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
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>
36 
37 #include <comphelper/processfactory.hxx>
38 #include <comphelper/documentinfo.hxx>
39 #include <unotools/configmgr.hxx>
40 #include <rtl/ustring.hxx>
41 
42 #include "eventdlg.hxx"
43 
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>
52 
53 #include "headertablistbox.hxx"
54 #include "macropg_impl.hxx"
55 
56 #include <dialmgr.hxx>
57 #include <cuires.hrc>
58 #include "eventdlg.hrc"
59 #include "helpid.hrc"
60 #include "selector.hxx"
61 #include "cfg.hxx"
62 
63 
64 using ::rtl::OUString;
65 using namespace ::com::sun::star;
66 // -----------------------------------------------------------------------
67 
68 SvxEventConfigPage::SvxEventConfigPage( Window *pParent, const SfxItemSet& rSet, SvxEventConfigPage::EarlyInit ) :
69 
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 )
74 {
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) );
85 
86 	FreeResource();
87 
88     // must be done after FreeResource is called
89     InitResources();
90 
91     mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT );
92 
93     aSaveInListBox.SetSelectHdl( LINK( this, SvxEventConfigPage,
94                 SelectHdl_Impl ) );
95 
96     uno::Reference< document::XEventsSupplier > xSupplier;
97 
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 );
104 
105     sal_uInt16 nPos(0);
106     if ( xSupplier.is() )
107     {
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 );
115     }
116 }
117 
118 // -----------------------------------------------------------------------
119 void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame  )
120 {
121     SetFrame( _rxFrame );
122     ImplInitDocument();
123 
124 	InitAndSetHandler( m_xAppEvents, m_xDocumentEvents, m_xDocumentModifiable );
125 
126     SelectHdl_Impl( NULL );
127 }
128 
129 // -----------------------------------------------------------------------
130 
131 SvxEventConfigPage::~SvxEventConfigPage()
132 {
133     //DF Do I need to delete bools?
134 }
135 
136 // -----------------------------------------------------------------------
137 
138 void SvxEventConfigPage::ImplInitDocument()
139 {
140     uno::Reference< frame::XFrame > xFrame( GetFrame() );
141     OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame );
142     if ( !xFrame.is() )
143         return;
144 
145     try
146     {
147         uno::Reference< frame::XModel > xModel;
148 		if ( !SvxConfigPage::CanConfig( aModuleId ) )
149             return;
150 
151         uno::Reference< frame::XController > xController =
152 			xFrame->getController();
153 
154 		if ( xController.is() )
155 		{
156 			xModel = xController->getModel();
157 		}
158 
159         if ( !xModel.is() )
160             return;
161 
162         uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY );
163 
164         if ( xSupplier.is() )
165         {
166             m_xDocumentEvents = xSupplier->getEvents();
167             m_xDocumentModifiable = m_xDocumentModifiable.query( xModel );
168 
169 			OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
170             sal_uInt16 nPos = aSaveInListBox.InsertEntry( aTitle );
171 
172             aSaveInListBox.SetEntryData( nPos, new bool(false) );
173             aSaveInListBox.SelectEntryPos( nPos, sal_True );
174 
175             bAppConfig = false;
176         }
177     }
178     catch( const uno::Exception& )
179     {
180     	DBG_UNHANDLED_EXCEPTION();
181     }
182 }
183 
184 // -----------------------------------------------------------------------
185 
186 IMPL_LINK( SvxEventConfigPage, SelectHdl_Impl, ListBox *, pBox )
187 {
188 	(void)pBox;
189 
190 	bool* bApp = (bool*) aSaveInListBox.GetEntryData(
191             aSaveInListBox.GetSelectEntryPos());
192 
193 	mpImpl->pEventLB->SetUpdateMode( sal_False );
194 	bAppConfig = *bApp;
195 	if ( *bApp )
196 	{
197 		SetReadOnly( sal_False );
198 		_SvxMacroTabPage::DisplayAppEvents( true );
199 	}
200 	else
201 	{
202 		bool isReadonly = sal_False;
203 
204 		uno::Reference< frame::XFramesSupplier > xFramesSupplier(
205 			::comphelper::getProcessServiceFactory()->createInstance(
206 				OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
207 			uno::UNO_QUERY );
208 
209 		uno::Reference< frame::XFrame > xFrame =
210 			xFramesSupplier->getActiveFrame();
211 
212 		if ( xFrame.is() )
213 		{
214 			uno::Reference< frame::XController > xController =
215 				xFrame->getController();
216 
217 			if ( xController.is() )
218 			{
219 				uno::Reference< frame::XStorable > xStorable(
220 					xController->getModel(), uno::UNO_QUERY );
221 				isReadonly = xStorable->isReadonly();
222 			}
223 		}
224 
225 		SetReadOnly( isReadonly );
226 		_SvxMacroTabPage::DisplayAppEvents( false );
227 	}
228 
229 	mpImpl->pEventLB->SetUpdateMode( sal_True );
230 	return sal_True;
231 }
232 
233 // -----------------------------------------------------------------------
234 
235 sal_Bool SvxEventConfigPage::FillItemSet( SfxItemSet& rSet )
236 {
237 	return _SvxMacroTabPage::FillItemSet( rSet );
238 }
239 
240 // -----------------------------------------------------------------------
241 
242 void SvxEventConfigPage::Reset( const SfxItemSet& )
243 {
244 	_SvxMacroTabPage::Reset();
245 }
246 
247