LibreOffice Module extensions (master) 1
commoncontrol.hxx
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#pragma once
21
22#include <com/sun/star/inspection/XPropertyControl.hpp>
23#include <com/sun/star/lang/DisposedException.hpp>
26#include <tools/link.hxx>
27#include <vcl/weld.hxx>
28#include <vcl/weldutils.hxx>
29
30class NotifyEvent;
31class ColorListBox;
32class SvtCalendarBox;
33
34namespace pcr
35{
36
37 //= CommonBehaviourControlHelper
38
45 {
46 private:
47 sal_Int16 m_nControlType;
48 css::uno::Reference< css::inspection::XPropertyControlContext >
50 css::inspection::XPropertyControl&
53
54 public:
64 sal_Int16 nControlType,
65 css::inspection::XPropertyControl& rAntiImpl);
66
68
69 virtual void setModified() { m_bModified = true; }
70
71 virtual void editChanged();
72
73 // XPropertyControl
75 ::sal_Int16 getControlType() const { return m_nControlType; }
77 const css::uno::Reference< css::inspection::XPropertyControlContext >& getControlContext() const { return m_xContext; }
79 void setControlContext( const css::uno::Reference< css::inspection::XPropertyControlContext >& controlcontext );
81 bool isModified( ) const { return m_bModified; }
83 void notifyModifiedValue( );
84
85 virtual weld::Widget* getWidget() = 0;
86
88 DECL_LINK( ModifiedHdl, weld::ComboBox&, void );
89 DECL_LINK( ColorModifiedHdl, ColorListBox&, void );
90 DECL_LINK( EditModifiedHdl, weld::Entry&, void );
91 DECL_LINK( MetricModifiedHdl, weld::MetricSpinButton&, void );
92 DECL_LINK( FormattedModifiedHdl, weld::FormattedSpinButton&, void );
93 DECL_LINK( TimeModifiedHdl, weld::FormattedSpinButton&, void );
94 DECL_LINK( DateModifiedHdl, SvtCalendarBox&, void );
95 DECL_LINK( GetFocusHdl, weld::Widget&, void );
96 DECL_LINK( LoseFocusHdl, weld::Widget&, void );
97 };
98
99
100 //= CommonBehaviourControl
101
110 template < class TControlInterface, class TControlWindow >
112 ,public ::cppu::WeakComponentImplHelper< TControlInterface >
114 {
115 protected:
116 typedef ::cppu::WeakComponentImplHelper< TControlInterface > ComponentBaseClass;
117
118 inline CommonBehaviourControl(sal_Int16 nControlType,
119 std::unique_ptr<weld::Builder> xBuilder,
120 std::unique_ptr<TControlWindow> xWidget,
121 bool bReadOnly);
122
123 virtual ~CommonBehaviourControl() override
124 {
126 }
127
128 // XPropertyControl - delegated to ->m_aImplControl
129 virtual ::sal_Int16 SAL_CALL getControlType() override
131 virtual css::uno::Reference< css::inspection::XPropertyControlContext > SAL_CALL getControlContext() override
133 virtual void SAL_CALL setControlContext( const css::uno::Reference< css::inspection::XPropertyControlContext >& controlcontext ) override
135 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getControlWindow() override
136 { return new weld::TransportAsXWindow(getWidget()); }
137 virtual sal_Bool SAL_CALL isModified( ) override
139 virtual void SAL_CALL notifyModifiedValue( ) override
141
143 {
144 if (!m_xControlWindow)
145 return;
146 weld::Widget* pWidget = getWidget();
147 std::unique_ptr<weld::Container> xParent(pWidget->weld_parent());
148 xParent->move(pWidget, nullptr);
149 m_xControlWindow.reset();
150 m_xBuilder.reset();
151 }
152
153 // XComponent
154 virtual void SAL_CALL disposing() override
155 {
157 }
158
159 TControlWindow* getTypedControlWindow()
160 { return m_xControlWindow.get(); }
161 const TControlWindow* getTypedControlWindow() const
162 { return m_xControlWindow.get(); }
163
164 virtual void SetModifyHandler()
165 {
166 m_xControlWindow->connect_focus_in( LINK( this, CommonBehaviourControlHelper, GetFocusHdl ) );
167 m_xControlWindow->connect_focus_out( LINK( this, CommonBehaviourControlHelper, LoseFocusHdl ) );
168 }
169
174 inline void impl_checkDisposed_throw();
175 protected:
176 std::unique_ptr<weld::Builder> m_xBuilder;
177 private:
178 std::unique_ptr<TControlWindow> m_xControlWindow;
179 };
180
181 //= CommonBehaviourControl - implementation
182 template< class TControlInterface, class TControlWindow >
184 std::unique_ptr<weld::Builder> xBuilder,
185 std::unique_ptr<TControlWindow> xWidget,
186 bool bReadOnly)
188 , CommonBehaviourControlHelper( nControlType, *this )
189 , m_xBuilder(std::move(xBuilder))
190 , m_xControlWindow(std::move(xWidget))
191 {
192 if (bReadOnly)
193 {
194 // disable widget by default, entries will override to enable the widget but set it non-editable
195 m_xControlWindow->set_sensitive(false);
196 }
197 }
198
199 template< class TControlInterface, class TControlWindow >
201 {
202 if ( ComponentBaseClass::rBHelper.bDisposed )
203 throw css::lang::DisposedException( OUString(), *this );
204 }
205
206} // namespace pcr
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A helper class for implementing the <type scope="css::inspection">XPropertyControl</type> or one of i...
CommonBehaviourControlHelper(sal_Int16 nControlType, css::inspection::XPropertyControl &rAntiImpl)
creates the instance
css::uno::Reference< css::inspection::XPropertyControlContext > m_xContext
DECL_LINK(LoseFocusHdl, weld::Widget &, void)
DECL_LINK(TimeModifiedHdl, weld::FormattedSpinButton &, void)
DECL_LINK(EditModifiedHdl, weld::Entry &, void)
void setControlContext(const css::uno::Reference< css::inspection::XPropertyControlContext > &controlcontext)
::sal_Int16 getControlType() const
virtual weld::Widget * getWidget()=0
css::inspection::XPropertyControl & m_rAntiImpl
DECL_LINK(MetricModifiedHdl, weld::MetricSpinButton &, void)
DECL_LINK(ModifiedHdl, weld::ComboBox &, void)
may be used by derived classes, they forward the event to the PropCtrListener
DECL_LINK(DateModifiedHdl, SvtCalendarBox &, void)
DECL_LINK(GetFocusHdl, weld::Widget &, void)
DECL_LINK(FormattedModifiedHdl, weld::FormattedSpinButton &, void)
const css::uno::Reference< css::inspection::XPropertyControlContext > & getControlContext() const
DECL_LINK(ColorModifiedHdl, ColorListBox &, void)
implements a base class for <type scope="css::inspection">XPropertyControl</type> implementations
virtual ~CommonBehaviourControl() override
virtual void SAL_CALL notifyModifiedValue() override
std::unique_ptr< TControlWindow > m_xControlWindow
virtual void SAL_CALL setControlContext(const css::uno::Reference< css::inspection::XPropertyControlContext > &controlcontext) override
std::unique_ptr< weld::Builder > m_xBuilder
virtual css::uno::Reference< css::inspection::XPropertyControlContext > SAL_CALL getControlContext() override
const TControlWindow * getTypedControlWindow() const
virtual ::sal_Int16 SAL_CALL getControlType() override
TControlWindow * getTypedControlWindow()
CommonBehaviourControl(sal_Int16 nControlType, std::unique_ptr< weld::Builder > xBuilder, std::unique_ptr< TControlWindow > xWidget, bool bReadOnly)
void impl_checkDisposed_throw()
checks whether the instance is already disposed
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getControlWindow() override
virtual void SAL_CALL disposing() override
virtual sal_Bool SAL_CALL isModified() override
::cppu::WeakComponentImplHelper< TControlInterface > ComponentBaseClass
virtual std::unique_ptr< Container > weld_parent() const=0
bool bReadOnly
::osl::Mutex m_aMutex
Definition: logger.cxx:98
a property handler for any virtual string properties
Definition: browserline.cxx:39
unsigned char sal_Bool
Reference< XWindow2 > m_xControlWindow