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