1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/diagnose_ex.hxx>
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"
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
, u
"cui/ui/eventsconfigpage.ui"_ustr
, u
"EventsConfigPage"_ustr
, rSet
)
42 , m_xSaveInListBox(m_xBuilder
->weld_combo_box(u
"savein"_ustr
))
44 mpImpl
->xEventLB
= m_xBuilder
->weld_tree_view(u
"events"_ustr
);
45 mpImpl
->xAssignPB
= m_xBuilder
->weld_button(u
"macro"_ustr
);
46 mpImpl
->xDeletePB
= m_xBuilder
->weld_button(u
"delete"_ustr
);
47 mpImpl
->xDeleteAllPB
= m_xBuilder
->weld_button(u
"deleteall"_ustr
);
48 mpImpl
->xAssignComponentPB
= m_xBuilder
->weld_button(u
"component"_ustr
);
50 mpImpl
->xEventLB
->set_size_request(mpImpl
->xEventLB
->get_approximate_digit_width() * 70,
51 mpImpl
->xEventLB
->get_height_rows(20));
53 m_xSaveInListBox
->connect_changed( LINK( this, SvxEventConfigPage
,
56 uno::Reference
< frame::XGlobalEventBroadcaster
> xSupplier
=
57 frame::theGlobalEventBroadcaster::get(::comphelper::getProcessComponentContext());
59 m_xAppEvents
= xSupplier
->getEvents();
60 m_xSaveInListBox
->append(OUString::boolean(true), utl::ConfigManager::getProductName());
61 m_xSaveInListBox
->set_active(0);
64 void SvxEventConfigPage::LateInit( const uno::Reference
< frame::XFrame
>& _rxFrame
)
69 InitAndSetHandler( m_xAppEvents
, m_xDocumentEvents
, m_xDocumentModifiable
);
71 SelectHdl_Impl( *m_xSaveInListBox
);
74 SvxEventConfigPage::~SvxEventConfigPage()
78 void SvxEventConfigPage::ImplInitDocument()
80 uno::Reference
< frame::XFrame
> xFrame( GetFrame() );
81 OUString aModuleId
= SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame
);
87 uno::Reference
< frame::XModel
> xModel
;
88 if ( !SvxConfigPage::CanConfig( aModuleId
) )
91 uno::Reference
< frame::XController
> xController
=
92 xFrame
->getController();
94 if ( xController
.is() )
96 xModel
= xController
->getModel();
102 uno::Reference
< document::XEventsSupplier
> xSupplier( xModel
, uno::UNO_QUERY
);
104 if ( xSupplier
.is() )
106 m_xDocumentEvents
= xSupplier
->getEvents();
107 m_xDocumentModifiable
.set(xModel
, css::uno::UNO_QUERY
);
109 OUString aTitle
= ::comphelper::DocumentInfo::getDocumentTitle( xModel
);
111 m_xSaveInListBox
->append(OUString::boolean(false), aTitle
);
112 m_xSaveInListBox
->set_active(m_xSaveInListBox
->get_count() - 1);
115 catch( const uno::Exception
& )
117 DBG_UNHANDLED_EXCEPTION("cui.customize");
121 IMPL_LINK_NOARG( SvxEventConfigPage
, SelectHdl_Impl
, weld::ComboBox
&, void )
123 bool bApp
= m_xSaveInListBox
->get_active_id().toBoolean();
127 SetReadOnly( false );
128 SvxMacroTabPage_::DisplayAppEvents( true );
132 bool isReadonly
= false;
134 uno::Reference
< frame::XDesktop2
> xFramesSupplier
= frame::Desktop::create(
135 ::comphelper::getProcessComponentContext() );
137 uno::Reference
< frame::XFrame
> xFrame
=
138 xFramesSupplier
->getActiveFrame();
142 uno::Reference
< frame::XController
> xController
=
143 xFrame
->getController();
145 if ( xController
.is() )
147 uno::Reference
< frame::XStorable
> xStorable(
148 xController
->getModel(), uno::UNO_QUERY
);
149 isReadonly
= xStorable
->isReadonly();
153 SetReadOnly( isReadonly
);
154 SvxMacroTabPage_::DisplayAppEvents( false );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */