LibreOffice Module cui (master)  1
eventdlg.cxx
Go to the documentation of this file.
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 <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>
25 
28 #include <unotools/configmgr.hxx>
29 #include <rtl/ustring.hxx>
30 
31 #include "eventdlg.hxx"
32 #include "macropg_impl.hxx"
33 
34 #include <cfg.hxx>
35 
36 using namespace ::com::sun::star;
37 
38 
41  : SvxMacroTabPage_(pPage, pController, "cui/ui/eventsconfigpage.ui", "EventsConfigPage", rSet)
42  , m_xSaveInListBox(m_xBuilder->weld_combo_box("savein"))
43 {
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");
48 
49  mpImpl->xEventLB->set_size_request(mpImpl->xEventLB->get_approximate_digit_width() * 70,
50  mpImpl->xEventLB->get_height_rows(20));
51 
52  InitResources();
53 
54  m_xSaveInListBox->connect_changed( LINK( this, SvxEventConfigPage,
55  SelectHdl_Impl ) );
56 
57  uno::Reference< frame::XGlobalEventBroadcaster > xSupplier =
58  frame::theGlobalEventBroadcaster::get(::comphelper::getProcessComponentContext());
59 
60  m_xAppEvents = xSupplier->getEvents();
61  m_xSaveInListBox->append(OUString::boolean(true), utl::ConfigManager::getProductName());
62  m_xSaveInListBox->set_active(0);
63 }
64 
65 void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame )
66 {
67  SetFrame( _rxFrame );
69 
71 
72  SelectHdl_Impl( *m_xSaveInListBox );
73 }
74 
76 {
77 }
78 
80 {
81  uno::Reference< frame::XFrame > xFrame( GetFrame() );
82  OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame );
83  if ( !xFrame.is() )
84  return;
85 
86  try
87  {
88  uno::Reference< frame::XModel > xModel;
89  if ( !SvxConfigPage::CanConfig( aModuleId ) )
90  return;
91 
92  uno::Reference< frame::XController > xController =
93  xFrame->getController();
94 
95  if ( xController.is() )
96  {
97  xModel = xController->getModel();
98  }
99 
100  if ( !xModel.is() )
101  return;
102 
103  uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY );
104 
105  if ( xSupplier.is() )
106  {
107  m_xDocumentEvents = xSupplier->getEvents();
108  m_xDocumentModifiable.set(xModel, css::uno::UNO_QUERY);
109 
110  OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
111 
112  m_xSaveInListBox->append(OUString::boolean(false), aTitle);
113  m_xSaveInListBox->set_active(m_xSaveInListBox->get_count() - 1);
114  }
115  }
116  catch( const uno::Exception& )
117  {
118  DBG_UNHANDLED_EXCEPTION("cui.customize");
119  }
120 }
121 
123 {
124  bool bApp = m_xSaveInListBox->get_active_id().toBoolean();
125 
126  mpImpl->xEventLB->freeze();
127  if (bApp)
128  {
129  SetReadOnly( false );
131  }
132  else
133  {
134  bool isReadonly = false;
135 
136  uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create(
138 
139  uno::Reference< frame::XFrame > xFrame =
140  xFramesSupplier->getActiveFrame();
141 
142  if ( xFrame.is() )
143  {
144  uno::Reference< frame::XController > xController =
145  xFrame->getController();
146 
147  if ( xController.is() )
148  {
149  uno::Reference< frame::XStorable > xStorable(
150  xController->getModel(), uno::UNO_QUERY );
151  isReadonly = xStorable->isReadonly();
152  }
153  }
154 
155  SetReadOnly( isReadonly );
157  }
158 
159  mpImpl->xEventLB->thaw();
160 }
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DisplayAppEvents(bool appEvents)
Definition: macropg.cxx:305
css::uno::Reference< css::container::XNameReplace > m_xAppEvents
Definition: eventdlg.hxx:29
Reference< XFrame > xFrame
void ImplInitDocument()
Definition: eventdlg.cxx:79
std::unique_ptr< weld::ComboBox > m_xSaveInListBox
Definition: eventdlg.hxx:33
this is only to let callers know that there is a LateInit which must be called
Definition: eventdlg.hxx:43
Reference< XController > xController
static bool CanConfig(const OUString &rModuleId)
Definition: cfg.cxx:158
void SetFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
std::unique_ptr< SvxMacroTabPage_Impl > mpImpl
Definition: macropg.hxx:63
IMPL_LINK_NOARG(SvxEventConfigPage, SelectHdl_Impl, weld::ComboBox &, void)
Definition: eventdlg.cxx:122
#define DBG_UNHANDLED_EXCEPTION(...)
void InitAndSetHandler(const css::uno::Reference< css::container::XNameReplace > &xAppEvents, const css::uno::Reference< css::container::XNameReplace > &xDocEvents, const css::uno::Reference< css::util::XModifiable > &xModifiable)
Definition: macropg.cxx:499
css::uno::Reference< css::frame::XFrame > GetFrame() const
static OUString getProductName()
css::uno::Reference< css::util::XModifiable > m_xDocumentModifiable
Definition: eventdlg.hxx:31
SvxEventConfigPage(const SvxEventConfigPage &)=delete
virtual ~SvxEventConfigPage() override
Definition: eventdlg.cxx:75
void LateInit(const css::uno::Reference< css::frame::XFrame > &_rxFrame)
Definition: eventdlg.cxx:65
css::uno::Reference< css::container::XNameReplace > m_xDocumentEvents
Definition: eventdlg.hxx:30
Reference< XComponentContext > getProcessComponentContext()
void InitResources()
Definition: macropg.cxx:90
Reference< XModel > xModel
static OUString GetFrameWithDefaultAndIdentify(css::uno::Reference< css::frame::XFrame > &_inout_rxFrame)
identifies the module in the given frame.
Definition: cfg.cxx:1239