LibreOffice Module extensions (master) 1
formcontrolcontainer.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
21#include <sal/log.hxx>
23
24#include <algorithm>
25
26namespace bib
27{
28
29
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::form;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::awt;
34
37 {
38 }
39
41 {
42 SAL_WARN_IF( isFormConnected(), "extensions.biblio", "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" );
43 if ( isFormConnected() )
45 }
48 {
49 ::osl::MutexGuard aGuard( m_aMutex );
50 SAL_WARN_IF( !isFormConnected(), "extensions.biblio", "FormControlContainer::connectForm: not connected!" );
51 if ( isFormConnected() )
52 {
53 m_xFormAdapter->dispose();
54 m_xFormAdapter.clear();
55 }
56 }
57
58 void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm )
59 {
60 SAL_WARN_IF( isFormConnected(), "extensions.biblio", "FormControlContainer::connectForm: already connected!" );
61
62 SAL_WARN_IF( !_rxForm.is(), "extensions.biblio", "FormControlContainer::connectForm: invalid form!" );
63 if ( !isFormConnected() && _rxForm.is() )
64 {
65 m_xFormAdapter = new OLoadListenerAdapter( _rxForm );
66 m_xFormAdapter->Init( this );
67
68 implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() );
69 }
70
71 m_xForm = _rxForm;
72 }
73
74 namespace {
75
76 struct ControlModeSwitch
77 {
78 bool bDesign;
79 explicit ControlModeSwitch( bool _bDesign ) : bDesign( _bDesign ) { }
80
81 void operator() ( const Reference< XControl >& _rxControl ) const
82 {
83 if ( _rxControl.is() )
84 _rxControl->setDesignMode( bDesign );
85 }
86 };
87
88 }
89
91 {
92 try
93 {
94 Reference< XControlContainer > xControlCont = getControlContainer();
95 if ( xControlCont.is() )
96 {
97 const Sequence<Reference<XControl>> aControls = xControlCont->getControls();
98
99 std::for_each(
100 aControls.begin(),
101 aControls.end(),
102 ControlModeSwitch( _bDesign )
103 );
104 }
105 }
106 catch( const Exception&)
107 {
108 TOOLS_WARN_EXCEPTION( "extensions.biblio", "FormControlContainer::implSetDesignMode" );
109 }
110 }
111
112 void FormControlContainer::_loaded( const css::lang::EventObject& /*_rEvent*/ )
113 {
114 implSetDesignMode( false );
115 }
116
117 void FormControlContainer::_unloading( const css::lang::EventObject& /*_rEvent*/ )
118 {
119 implSetDesignMode( true );
120 }
121
122 void FormControlContainer::_reloading( const css::lang::EventObject& /*_rEvent*/ )
123 {
124 implSetDesignMode( true );
125 }
126
127 void FormControlContainer::_reloaded( const css::lang::EventObject& /*_rEvent*/ )
128 {
129 implSetDesignMode( false );
130 }
131
132
133} // namespace bib
134
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void _unloading(const css::lang::EventObject &_rEvent) override
virtual css::uno::Reference< css::awt::XControlContainer > getControlContainer()=0
void implSetDesignMode(bool _bDesign)
css::uno::Reference< css::form::XLoadable > m_xForm
void connectForm(const css::uno::Reference< css::form::XLoadable > &_rxForm)
virtual void _loaded(const css::lang::EventObject &_rEvent) override
rtl::Reference< OLoadListenerAdapter > m_xFormAdapter
virtual void _reloaded(const css::lang::EventObject &_rEvent) override
virtual void _reloading(const css::lang::EventObject &_rEvent) override
virtual ~FormControlContainer() override
friend class OLoadListenerAdapter
mutable::osl::Mutex m_aMutex
#define TOOLS_WARN_EXCEPTION(area, stream)
bool bDesign
#define SAL_WARN_IF(condition, area, stream)
::osl::Mutex m_aMutex
Definition: logger.cxx:98
Definition: bibbeam.cxx:40
@ Exception