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