bump product version to 4.1.6.2
[LibreOffice.git] / cui / source / customize / eventdlg.cxx
blob54c8f847995dde0bc0878f1fe399201183b09744
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/Desktop.hpp>
24 #include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
25 #include <com/sun/star/frame/XModuleManager.hpp>
27 #include <comphelper/processfactory.hxx>
28 #include <comphelper/documentinfo.hxx>
29 #include <unotools/configmgr.hxx>
30 #include <rtl/ustring.hxx>
32 #include "eventdlg.hxx"
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/evntconf.hxx>
36 #include <sfx2/minfitem.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <sfx2/docfac.hxx>
40 #include <sfx2/fcontnr.hxx>
41 #include <unotools/eventcfg.hxx>
43 #include "headertablistbox.hxx"
44 #include "macropg_impl.hxx"
46 #include <dialmgr.hxx>
47 #include <cuires.hrc>
48 #include "eventdlg.hrc"
49 #include "helpid.hrc"
50 #include "selector.hxx"
51 #include "cfg.hxx"
54 using namespace ::com::sun::star;
55 // -----------------------------------------------------------------------
57 SvxEventConfigPage::SvxEventConfigPage( Window *pParent, const SfxItemSet& rSet, SvxEventConfigPage::EarlyInit ) :
59 _SvxMacroTabPage( pParent, CUI_RES(RID_SVXPAGE_EVENTS), rSet ),
60 aSaveInText( this, CUI_RES( TXT_SAVEIN ) ),
61 aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ),
62 bAppConfig ( sal_True )
64 mpImpl->pStrEvent = new String( CUI_RES( STR_EVENT ));
65 mpImpl->pAssignedMacro = new String( CUI_RES( STR_ASSMACRO ));
66 mpImpl->pEventLB = new _HeaderTabListBox( this, CUI_RES( LB_EVENT ));
67 mpImpl->pAssignFT = new FixedText( this, CUI_RES( FT_ASSIGN ));
68 mpImpl->pAssignPB = new PushButton( this, CUI_RES( PB_ASSIGN ));
69 mpImpl->pDeletePB = new PushButton( this, CUI_RES( PB_DELETE ));
70 mpImpl->pMacroImg = new Image( CUI_RES( IMG_MACRO) );
71 mpImpl->pComponentImg = new Image( CUI_RES( IMG_COMPONENT) );
73 FreeResource();
75 // must be done after FreeResource is called
76 InitResources();
78 mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT );
80 aSaveInListBox.SetSelectHdl( LINK( this, SvxEventConfigPage,
81 SelectHdl_Impl ) );
83 uno::Reference< frame::XGlobalEventBroadcaster > xSupplier;
85 xSupplier =
86 frame::GlobalEventBroadcaster::create(::comphelper::getProcessComponentContext());
88 sal_uInt16 nPos(0);
89 m_xAppEvents = xSupplier->getEvents();
90 nPos = aSaveInListBox.InsertEntry(
91 utl::ConfigManager::getProductName() );
92 aSaveInListBox.SetEntryData( nPos, new bool(true) );
93 aSaveInListBox.SelectEntryPos( nPos, sal_True );
96 // -----------------------------------------------------------------------
97 void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame )
99 SetFrame( _rxFrame );
100 ImplInitDocument();
102 InitAndSetHandler( m_xAppEvents, m_xDocumentEvents, m_xDocumentModifiable );
104 SelectHdl_Impl( NULL );
107 // -----------------------------------------------------------------------
109 SvxEventConfigPage::~SvxEventConfigPage()
111 //DF Do I need to delete bools?
114 // -----------------------------------------------------------------------
116 void SvxEventConfigPage::ImplInitDocument()
118 uno::Reference< frame::XFrame > xFrame( GetFrame() );
119 OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame );
120 if ( !xFrame.is() )
121 return;
125 uno::Reference< frame::XModel > xModel;
126 if ( !SvxConfigPage::CanConfig( aModuleId ) )
127 return;
129 uno::Reference< frame::XController > xController =
130 xFrame->getController();
132 if ( xController.is() )
134 xModel = xController->getModel();
137 if ( !xModel.is() )
138 return;
140 uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY );
142 if ( xSupplier.is() )
144 m_xDocumentEvents = xSupplier->getEvents();
145 m_xDocumentModifiable = m_xDocumentModifiable.query( xModel );
147 OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
148 sal_uInt16 nPos = aSaveInListBox.InsertEntry( aTitle );
150 aSaveInListBox.SetEntryData( nPos, new bool(false) );
151 aSaveInListBox.SelectEntryPos( nPos, sal_True );
153 bAppConfig = false;
156 catch( const uno::Exception& )
158 DBG_UNHANDLED_EXCEPTION();
162 // -----------------------------------------------------------------------
164 IMPL_LINK( SvxEventConfigPage, SelectHdl_Impl, ListBox *, pBox )
166 (void)pBox;
168 bool* bApp = (bool*) aSaveInListBox.GetEntryData(
169 aSaveInListBox.GetSelectEntryPos());
171 mpImpl->pEventLB->SetUpdateMode( sal_False );
172 bAppConfig = *bApp;
173 if ( *bApp )
175 SetReadOnly( sal_False );
176 _SvxMacroTabPage::DisplayAppEvents( true );
178 else
180 bool isReadonly = sal_False;
182 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create(
183 ::comphelper::getProcessComponentContext() );
185 uno::Reference< frame::XFrame > xFrame =
186 xFramesSupplier->getActiveFrame();
188 if ( xFrame.is() )
190 uno::Reference< frame::XController > xController =
191 xFrame->getController();
193 if ( xController.is() )
195 uno::Reference< frame::XStorable > xStorable(
196 xController->getModel(), uno::UNO_QUERY );
197 isReadonly = xStorable->isReadonly();
201 SetReadOnly( isReadonly );
202 _SvxMacroTabPage::DisplayAppEvents( false );
205 mpImpl->pEventLB->SetUpdateMode( sal_True );
206 return sal_True;
209 // -----------------------------------------------------------------------
211 sal_Bool SvxEventConfigPage::FillItemSet( SfxItemSet& rSet )
213 return _SvxMacroTabPage::FillItemSet( rSet );
216 // -----------------------------------------------------------------------
218 void SvxEventConfigPage::Reset( const SfxItemSet& )
220 _SvxMacroTabPage::Reset();
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */