bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / customize / eventdlg.cxx
blob970bd055bbd501fa553c0eab25f773b5c8e4a5e9
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/theGlobalEventBroadcaster.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>
42 #include <svtools/treelistentry.hxx>
44 #include "headertablistbox.hxx"
45 #include "macropg_impl.hxx"
47 #include <dialmgr.hxx>
48 #include <cuires.hrc>
49 #include "helpid.hrc"
50 #include "selector.hxx"
51 #include "cfg.hxx"
54 using namespace ::com::sun::star;
57 SvxEventConfigPage::SvxEventConfigPage(vcl::Window *pParent, const SfxItemSet& rSet,
58 SvxEventConfigPage::EarlyInit)
59 : _SvxMacroTabPage(pParent, "EventsConfigPage",
60 "cui/ui/eventsconfigpage.ui", rSet)
61 , bAppConfig(true)
63 get(m_pSaveInListBox, "savein");
65 mpImpl->sStrEvent = get<FixedText>("eventft")->GetText();
66 mpImpl->sAssignedMacro = get<FixedText>("actionft")->GetText();
67 get(mpImpl->pEventLB, "events");
68 Size aSize(LogicToPixel(Size(205, 229), MAP_APPFONT));
69 mpImpl->pEventLB->set_width_request(aSize.Width());
70 mpImpl->pEventLB->set_height_request(aSize.Height());
71 get(mpImpl->pAssignPB, "macro");
72 get(mpImpl->pDeletePB, "delete");
73 mpImpl->aMacroImg = get<FixedImage>("macroimg")->GetImage();
74 mpImpl->aComponentImg = get<FixedImage>("componentimg")->GetImage();
76 InitResources();
78 m_pSaveInListBox->SetSelectHdl( LINK( this, SvxEventConfigPage,
79 SelectHdl_Impl ) );
81 uno::Reference< frame::XGlobalEventBroadcaster > xSupplier;
83 xSupplier =
84 frame::theGlobalEventBroadcaster::get(::comphelper::getProcessComponentContext());
86 sal_uInt16 nPos(0);
87 m_xAppEvents = xSupplier->getEvents();
88 nPos = m_pSaveInListBox->InsertEntry(
89 utl::ConfigManager::getProductName() );
90 m_pSaveInListBox->SetEntryData( nPos, new bool(true) );
91 m_pSaveInListBox->SelectEntryPos( nPos, true );
94 void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame )
96 SetFrame( _rxFrame );
97 ImplInitDocument();
99 InitAndSetHandler( m_xAppEvents, m_xDocumentEvents, m_xDocumentModifiable );
101 SelectHdl_Impl( NULL );
104 SvxEventConfigPage::~SvxEventConfigPage()
106 disposeOnce();
109 void SvxEventConfigPage::dispose()
111 // need to delete the user data
112 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
113 SvTreeListEntry* pE = rListBox.GetEntry( 0 );
114 while( pE )
116 OUString const * pEventName = static_cast<OUString const *>(pE->GetUserData());
117 delete pEventName;
118 pE->SetUserData((void*)0);
119 pE = SvTreeListBox::NextSibling( pE );
121 m_pSaveInListBox.clear();
122 _SvxMacroTabPage::dispose();
125 void SvxEventConfigPage::ImplInitDocument()
127 uno::Reference< frame::XFrame > xFrame( GetFrame() );
128 OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame );
129 if ( !xFrame.is() )
130 return;
134 uno::Reference< frame::XModel > xModel;
135 if ( !SvxConfigPage::CanConfig( aModuleId ) )
136 return;
138 uno::Reference< frame::XController > xController =
139 xFrame->getController();
141 if ( xController.is() )
143 xModel = xController->getModel();
146 if ( !xModel.is() )
147 return;
149 uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY );
151 if ( xSupplier.is() )
153 m_xDocumentEvents = xSupplier->getEvents();
154 m_xDocumentModifiable.set(xModel, css::uno::UNO_QUERY);
156 OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
157 sal_uInt16 nPos = m_pSaveInListBox->InsertEntry( aTitle );
159 m_pSaveInListBox->SetEntryData( nPos, new bool(false) );
160 m_pSaveInListBox->SelectEntryPos( nPos, true );
162 bAppConfig = false;
165 catch( const uno::Exception& )
167 DBG_UNHANDLED_EXCEPTION();
171 IMPL_LINK( SvxEventConfigPage, SelectHdl_Impl, ListBox *, pBox )
173 (void)pBox;
175 bool* bApp = static_cast<bool*>(m_pSaveInListBox->GetEntryData(
176 m_pSaveInListBox->GetSelectEntryPos()));
178 mpImpl->pEventLB->SetUpdateMode( false );
179 bAppConfig = *bApp;
180 if ( *bApp )
182 SetReadOnly( false );
183 _SvxMacroTabPage::DisplayAppEvents( true );
185 else
187 bool isReadonly = false;
189 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create(
190 ::comphelper::getProcessComponentContext() );
192 uno::Reference< frame::XFrame > xFrame =
193 xFramesSupplier->getActiveFrame();
195 if ( xFrame.is() )
197 uno::Reference< frame::XController > xController =
198 xFrame->getController();
200 if ( xController.is() )
202 uno::Reference< frame::XStorable > xStorable(
203 xController->getModel(), uno::UNO_QUERY );
204 isReadonly = xStorable->isReadonly();
208 SetReadOnly( isReadonly );
209 _SvxMacroTabPage::DisplayAppEvents( false );
212 mpImpl->pEventLB->SetUpdateMode( true );
213 return sal_IntPtr(true);
216 bool SvxEventConfigPage::FillItemSet( SfxItemSet* rSet )
218 return _SvxMacroTabPage::FillItemSet( rSet );
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */