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