Line data Source code
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 "commoncontrol.hxx"
21 : #include "pcrcommon.hxx"
22 : #include <tools/debug.hxx>
23 : #include <tools/diagnose_ex.h>
24 : #include <vcl/combobox.hxx>
25 : #include <toolkit/helper/vclunohelper.hxx>
26 :
27 :
28 : namespace pcr
29 : {
30 :
31 :
32 : using ::com::sun::star::uno::RuntimeException;
33 : using ::com::sun::star::uno::Reference;
34 : using ::com::sun::star::inspection::XPropertyControlContext;
35 : using ::com::sun::star::awt::XWindow;
36 : using ::com::sun::star::uno::Exception;
37 : using ::com::sun::star::inspection::XPropertyControl;
38 :
39 0 : ControlHelper::ControlHelper( vcl::Window* _pControlWindow, sal_Int16 _nControlType, XPropertyControl& _rAntiImpl, IModifyListener* _pModifyListener )
40 : :m_pControlWindow( _pControlWindow )
41 : ,m_nControlType( _nControlType )
42 : ,m_rAntiImpl( _rAntiImpl )
43 : ,m_pModifyListener( _pModifyListener )
44 0 : ,m_bModified( false )
45 : {
46 : DBG_ASSERT( m_pControlWindow != nullptr, "ControlHelper::ControlHelper: invalid window!" );
47 0 : }
48 :
49 :
50 0 : ControlHelper::~ControlHelper()
51 : {
52 0 : }
53 :
54 0 : void SAL_CALL ControlHelper::setControlContext( const Reference< XPropertyControlContext >& _controlcontext ) throw (RuntimeException)
55 : {
56 0 : m_xContext = _controlcontext;
57 0 : }
58 :
59 :
60 0 : Reference< XWindow > SAL_CALL ControlHelper::getControlWindow() throw (RuntimeException)
61 : {
62 0 : return VCLUnoHelper::GetInterface( m_pControlWindow );
63 : }
64 :
65 :
66 :
67 :
68 0 : void SAL_CALL ControlHelper::notifyModifiedValue( ) throw (RuntimeException)
69 : {
70 0 : if ( isModified() && m_xContext.is() )
71 : {
72 : try
73 : {
74 0 : m_xContext->valueChanged( &m_rAntiImpl );
75 0 : m_bModified = false;
76 : }
77 0 : catch( const Exception& )
78 : {
79 : DBG_UNHANDLED_EXCEPTION();
80 : }
81 : }
82 0 : }
83 :
84 :
85 0 : void SAL_CALL ControlHelper::dispose()
86 : {
87 0 : m_pControlWindow.disposeAndClear();
88 0 : }
89 :
90 :
91 0 : void ControlHelper::autoSizeWindow()
92 : {
93 : OSL_PRECOND( m_pControlWindow, "ControlHelper::autoSizeWindow: no window!" );
94 0 : if ( !m_pControlWindow )
95 0 : return;
96 :
97 0 : ScopedVclPtrInstance< ComboBox > aComboBox(m_pControlWindow, WB_DROPDOWN);
98 0 : aComboBox->SetPosSizePixel(Point(0,0), Size(100,100));
99 0 : m_pControlWindow->SetSizePixel(aComboBox->GetSizePixel());
100 :
101 : // TODO/UNOize: why do the controls this themselves? Shouldn't this be the task
102 : // of the browser listbox/line?
103 : }
104 :
105 :
106 0 : void ControlHelper::impl_activateNextControl_nothrow() const
107 : {
108 : try
109 : {
110 0 : if ( m_xContext.is() )
111 0 : m_xContext->activateNextControl( &m_rAntiImpl );
112 : }
113 0 : catch( const Exception& )
114 : {
115 : DBG_UNHANDLED_EXCEPTION();
116 : }
117 0 : }
118 :
119 :
120 0 : bool ControlHelper::handlePreNotify(NotifyEvent& rNEvt)
121 : {
122 0 : if (MouseNotifyEvent::KEYINPUT == rNEvt.GetType())
123 : {
124 0 : const vcl::KeyCode& aKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
125 0 : sal_uInt16 nKey = aKeyCode.GetCode();
126 :
127 0 : if (nKey == KEY_RETURN && !aKeyCode.IsShift())
128 : {
129 0 : LoseFocusHdl(m_pControlWindow);
130 0 : impl_activateNextControl_nothrow();
131 0 : return true;
132 : }
133 : }
134 0 : return false;
135 : }
136 :
137 :
138 0 : IMPL_LINK( ControlHelper, ModifiedHdl, vcl::Window*, /*_pWin*/ )
139 : {
140 0 : if ( m_pModifyListener )
141 0 : m_pModifyListener->modified();
142 0 : return 0;
143 : }
144 :
145 :
146 0 : IMPL_LINK( ControlHelper, GetFocusHdl, vcl::Window*, /*_pWin*/ )
147 : {
148 : try
149 : {
150 0 : if ( m_xContext.is() )
151 0 : m_xContext->focusGained( &m_rAntiImpl );
152 : }
153 0 : catch( const Exception& )
154 : {
155 : DBG_UNHANDLED_EXCEPTION();
156 : }
157 0 : return 0;
158 : }
159 :
160 :
161 0 : IMPL_LINK( ControlHelper, LoseFocusHdl, vcl::Window*, /*_pWin*/ )
162 : {
163 : // TODO/UNOize: should this be outside the default control's implementations? If somebody
164 : // has an own control implementation, which does *not* do this - would this be allowed?
165 : // If not, then we must move this logic out of here.
166 0 : notifyModifiedValue();
167 0 : return 0;
168 : }
169 :
170 :
171 6 : } // namespace pcr
172 :
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|