bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / customize / eventdlg.cxx
blob72cd08b168fa411700fc5b5cbceacd0b3f11efdf
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 <tools/diagnose_ex.h>
21 #include <com/sun/star/document/XEventsSupplier.hpp>
22 #include <com/sun/star/frame/Desktop.hpp>
23 #include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
24 #include <com/sun/star/frame/XStorable.hpp>
26 #include <comphelper/processfactory.hxx>
27 #include <comphelper/documentinfo.hxx>
28 #include <unotools/configmgr.hxx>
29 #include <rtl/ustring.hxx>
31 #include "eventdlg.hxx"
32 #include "macropg_impl.hxx"
34 #include <cfg.hxx>
36 using namespace ::com::sun::star;
39 SvxEventConfigPage::SvxEventConfigPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet,
40 SvxEventConfigPage::EarlyInit)
41 : SvxMacroTabPage_(pPage, pController, "cui/ui/eventsconfigpage.ui", "EventsConfigPage", rSet)
42 , m_xSaveInListBox(m_xBuilder->weld_combo_box("savein"))
44 mpImpl->xEventLB = m_xBuilder->weld_tree_view("events");
45 mpImpl->xAssignPB = m_xBuilder->weld_button("macro");
46 mpImpl->xDeletePB = m_xBuilder->weld_button("delete");
47 mpImpl->xAssignComponentPB = m_xBuilder->weld_button("component");
49 mpImpl->xEventLB->set_size_request(mpImpl->xEventLB->get_approximate_digit_width() * 70,
50 mpImpl->xEventLB->get_height_rows(20));
52 InitResources();
54 m_xSaveInListBox->connect_changed( LINK( this, SvxEventConfigPage,
55 SelectHdl_Impl ) );
57 uno::Reference< frame::XGlobalEventBroadcaster > xSupplier =
58 frame::theGlobalEventBroadcaster::get(::comphelper::getProcessComponentContext());
60 m_xAppEvents = xSupplier->getEvents();
61 m_xSaveInListBox->append(OUString::boolean(true), utl::ConfigManager::getProductName());
62 m_xSaveInListBox->set_active(0);
65 void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame )
67 SetFrame( _rxFrame );
68 ImplInitDocument();
70 InitAndSetHandler( m_xAppEvents, m_xDocumentEvents, m_xDocumentModifiable );
72 SelectHdl_Impl( *m_xSaveInListBox );
75 SvxEventConfigPage::~SvxEventConfigPage()
79 void SvxEventConfigPage::ImplInitDocument()
81 uno::Reference< frame::XFrame > xFrame( GetFrame() );
82 OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame );
83 if ( !xFrame.is() )
84 return;
86 try
88 uno::Reference< frame::XModel > xModel;
89 if ( !SvxConfigPage::CanConfig( aModuleId ) )
90 return;
92 uno::Reference< frame::XController > xController =
93 xFrame->getController();
95 if ( xController.is() )
97 xModel = xController->getModel();
100 if ( !xModel.is() )
101 return;
103 uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY );
105 if ( xSupplier.is() )
107 m_xDocumentEvents = xSupplier->getEvents();
108 m_xDocumentModifiable.set(xModel, css::uno::UNO_QUERY);
110 OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
112 m_xSaveInListBox->append(OUString::boolean(false), aTitle);
113 m_xSaveInListBox->set_active(m_xSaveInListBox->get_count() - 1);
116 catch( const uno::Exception& )
118 DBG_UNHANDLED_EXCEPTION("cui.customize");
122 IMPL_LINK_NOARG( SvxEventConfigPage, SelectHdl_Impl, weld::ComboBox&, void )
124 bool bApp = m_xSaveInListBox->get_active_id().toBoolean();
126 mpImpl->xEventLB->freeze();
127 if (bApp)
129 SetReadOnly( false );
130 SvxMacroTabPage_::DisplayAppEvents( true );
132 else
134 bool isReadonly = false;
136 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create(
137 ::comphelper::getProcessComponentContext() );
139 uno::Reference< frame::XFrame > xFrame =
140 xFramesSupplier->getActiveFrame();
142 if ( xFrame.is() )
144 uno::Reference< frame::XController > xController =
145 xFrame->getController();
147 if ( xController.is() )
149 uno::Reference< frame::XStorable > xStorable(
150 xController->getModel(), uno::UNO_QUERY );
151 isReadonly = xStorable->isReadonly();
155 SetReadOnly( isReadonly );
156 SvxMacroTabPage_::DisplayAppEvents( false );
159 mpImpl->xEventLB->thaw();
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */