merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / dlg / admincontrols.cxx
blob00feec0fa362b2352190c10d3ece110ec309a920
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org. If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
24 ************************************************************************/
26 // MARKER(update_precomp.py): autogen include statement, do not remove
27 #include "precompiled_dbaccess.hxx"
29 #include "admincontrols.hxx"
30 #include "admincontrols.hrc"
31 #include "dbu_dlg.hrc"
32 #include "dsitems.hxx"
33 #include "moduledbu.hxx"
35 #include <svtools/eitem.hxx>
36 #include <svtools/stritem.hxx>
37 #include <svtools/intitem.hxx>
39 //........................................................................
40 namespace dbaui
42 //........................................................................
44 //====================================================================
45 //= TextResetOperatorEventFilter
46 //====================================================================
47 class TextResetOperatorEventFilter : public ::svt::IWindowEventFilter
49 public:
50 TextResetOperatorEventFilter()
54 // IWindowEventFilter
55 virtual bool payAttentionTo( const VclWindowEvent& _rEvent ) const
57 return ( _rEvent.GetId() == VCLEVENT_WINDOW_ENABLED )
58 || ( _rEvent.GetId() == VCLEVENT_WINDOW_DISABLED )
59 || ( _rEvent.GetId() == VCLEVENT_EDIT_MODIFY );
63 //====================================================================
64 //= TextResetOperator
65 //====================================================================
66 class TextResetOperator :public ::svt::IWindowOperator
68 public:
69 TextResetOperator( const String& _rDisabledText )
70 :m_sDisabledText( _rDisabledText )
74 // IWindowOperator
75 virtual void operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const;
77 private:
78 const String m_sDisabledText;
79 String m_sUserText;
80 BOOL m_bLastKnownEnabledState;
83 //--------------------------------------------------------------------
84 void TextResetOperator::operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const
86 OSL_ENSURE( _rTrigger.GetWindow() == &_rOperateOn, "TextResetOperator::operateOn: you're misusing this implementation!" );
88 switch ( _rTrigger.GetId() )
90 case 0:
91 // initial call
92 const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
93 break;
95 case VCLEVENT_EDIT_MODIFY:
96 if ( _rTrigger.GetWindow()->IsEnabled() )
97 const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
98 break;
100 case VCLEVENT_WINDOW_ENABLED:
101 _rOperateOn.SetText( m_sUserText );
102 break;
104 case VCLEVENT_WINDOW_DISABLED:
105 _rOperateOn.SetText( m_sDisabledText );
106 break;
108 default:
109 OSL_ENSURE( false, "TextResetOperator::operateOn: unexpected event ID!" );
110 // all those IDs should have been filtered out by payAttentionTo
111 break;
115 //====================================================================
116 //= TextResetOperatorController
117 //====================================================================
118 class TextResetOperatorController_Base
120 protected:
121 TextResetOperatorController_Base( const String& _rDisabledText )
122 :m_pEventFilter( new TextResetOperatorEventFilter )
123 ,m_pOperator( new TextResetOperator( _rDisabledText ) )
127 inline ::svt::PWindowEventFilter getEventFilter() const { return m_pEventFilter; }
128 inline ::svt::PWindowOperator getOperator() const { return m_pOperator; }
130 private:
131 ::svt::PWindowEventFilter m_pEventFilter;
132 ::svt::PWindowOperator m_pOperator;
135 class TextResetOperatorController :public TextResetOperatorController_Base
136 ,public ::svt::DialogController
138 public:
139 TextResetOperatorController( Window& _rObservee, const String& _rDisabledText )
140 :TextResetOperatorController_Base( _rDisabledText )
141 ,::svt::DialogController( _rObservee, getEventFilter(), getOperator() )
143 addDependentWindow( _rObservee );
147 //====================================================================
148 //= MySQLNativeSettings
149 //====================================================================
150 //--------------------------------------------------------------------
151 MySQLNativeSettings::MySQLNativeSettings( Window& _rParent, const Link& _rControlModificationLink )
152 :Control( &_rParent, ModuleRes( RID_MYSQL_NATIVE_SETTINGS ).SetAutoRelease( FALSE ) )
153 ,m_aDatabaseNameLabel ( this, ModuleRes( FT_MYSQL_DATABASE_NAME ) )
154 ,m_aDatabaseName ( this, ModuleRes( ED_MYSQL_DATABASE_NAME ) )
155 ,m_aHostPortRadio ( this, ModuleRes( RB_MYSQL_HOST_PORT ) )
156 ,m_aSocketRadio ( this, ModuleRes( RB_MYSQL_SOCKET ) )
157 ,m_aNamedPipeRadio ( this, ModuleRes( RB_MYSQL_NAMED_PIPE ) )
158 ,m_aHostNameLabel ( this, ModuleRes( FT_COMMON_HOST_NAME ) )
159 ,m_aHostName ( this, ModuleRes( ED_COMMON_HOST_NAME ) )
160 ,m_aPortLabel ( this, ModuleRes( FT_COMMON_PORT ) )
161 ,m_aPort ( this, ModuleRes( NF_COMMON_PORT ) )
162 ,m_aDefaultPort ( this, ModuleRes( FT_COMMON_PORT_DEFAULT ) )
163 ,m_aSocket ( this, ModuleRes( ED_MYSQL_SOCKET ) )
164 ,m_aNamedPipe ( this, ModuleRes( ED_MYSQL_NAMED_PIPE ) )
166 FreeResource();
168 m_aDatabaseName.SetModifyHdl( _rControlModificationLink );
169 m_aHostName.SetModifyHdl( _rControlModificationLink );
170 m_aPort.SetModifyHdl( _rControlModificationLink );
171 m_aNamedPipe.SetModifyHdl( _rControlModificationLink );
172 m_aSocketRadio.SetToggleHdl( _rControlModificationLink );
173 m_aNamedPipeRadio.SetToggleHdl( _rControlModificationLink );
175 m_aControlDependencies.enableOnRadioCheck( m_aHostPortRadio, m_aHostNameLabel, m_aHostName, m_aPortLabel, m_aPort, m_aDefaultPort );
176 m_aControlDependencies.enableOnRadioCheck( m_aSocketRadio, m_aSocket );
177 m_aControlDependencies.enableOnRadioCheck( m_aNamedPipeRadio, m_aNamedPipe );
179 m_aControlDependencies.addController( ::svt::PDialogController(
180 new TextResetOperatorController( m_aHostName, String::CreateFromAscii( "localhost" ) )
181 ) );
183 // sockets are available on Unix systems only, named pipes only on Windows
184 #ifdef UNX
185 m_aNamedPipeRadio.Hide();
186 m_aNamedPipe.Hide();
187 #else
188 m_aSocketRadio.Hide();
189 m_aSocket.Hide();
190 #endif
193 //--------------------------------------------------------------------
194 MySQLNativeSettings::~MySQLNativeSettings()
198 //--------------------------------------------------------------------
199 void MySQLNativeSettings::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
201 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aDatabaseName ) );
202 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aHostName ) );
203 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aPort ) );
204 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aSocket ) );
205 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aNamedPipe ) );
208 //--------------------------------------------------------------------
209 void MySQLNativeSettings::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
211 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDatabaseNameLabel ) );
212 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aHostNameLabel ) );
213 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aPortLabel ) );
214 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDefaultPort ) );
215 _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aSocketRadio ) );
216 _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aNamedPipeRadio ) );
219 //--------------------------------------------------------------------
220 BOOL MySQLNativeSettings::FillItemSet( SfxItemSet& _rSet )
222 sal_Bool bChangedSomething = sal_False;
224 OGenericAdministrationPage::fillString( _rSet, &m_aHostName, DSID_CONN_HOSTNAME, bChangedSomething );
225 OGenericAdministrationPage::fillString( _rSet, &m_aDatabaseName, DSID_DATABASENAME, bChangedSomething );
226 OGenericAdministrationPage::fillInt32 ( _rSet, &m_aPort, DSID_MYSQL_PORTNUMBER, bChangedSomething );
227 #ifdef UNX
228 OGenericAdministrationPage::fillString( _rSet, &m_aSocket, DSID_CONN_SOCKET, bChangedSomething );
229 #else
230 OGenericAdministrationPage::fillString( _rSet, &m_aNamedPipe, DSID_NAMED_PIPE, bChangedSomething );
231 #endif
233 return bChangedSomething;
236 //--------------------------------------------------------------------
237 void MySQLNativeSettings::implInitControls(const SfxItemSet& _rSet )
239 SFX_ITEMSET_GET( _rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True );
240 bool bValid = !pInvalid || !pInvalid->GetValue();
241 if ( !bValid )
242 return;
244 SFX_ITEMSET_GET( _rSet, pDatabaseName, SfxStringItem, DSID_DATABASENAME, sal_True );
245 SFX_ITEMSET_GET( _rSet, pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True );
246 SFX_ITEMSET_GET( _rSet, pPortNumber, SfxInt32Item, DSID_MYSQL_PORTNUMBER, sal_True );
247 SFX_ITEMSET_GET( _rSet, pSocket, SfxStringItem, DSID_CONN_SOCKET, sal_True );
248 SFX_ITEMSET_GET( _rSet, pNamedPipe, SfxStringItem, DSID_NAMED_PIPE, sal_True );
250 m_aDatabaseName.SetText( pDatabaseName->GetValue() );
251 m_aDatabaseName.ClearModifyFlag();
253 m_aHostName.SetText( pHostName->GetValue() );
254 m_aHostName.ClearModifyFlag();
256 m_aPort.SetValue( pPortNumber->GetValue() );
257 m_aPort.ClearModifyFlag();
259 m_aSocket.SetText( pSocket->GetValue() );
260 m_aSocket.ClearModifyFlag();
262 m_aNamedPipe.SetText( pNamedPipe->GetValue() );
263 m_aNamedPipe.ClearModifyFlag();
265 // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over
266 // the port
267 #ifdef UNX
268 RadioButton& rSocketPipeRadio = m_aSocketRadio;
269 const SfxStringItem* pSocketPipeItem = pSocket;
270 #else
271 RadioButton& rSocketPipeRadio = m_aNamedPipeRadio;
272 const SfxStringItem* pSocketPipeItem = pNamedPipe;
273 #endif
274 String sSocketPipe( pSocketPipeItem->GetValue() );
275 if ( sSocketPipe.Len() > 0 )
276 rSocketPipeRadio.Check();
277 else
278 m_aHostPortRadio.Check();
281 //--------------------------------------------------------------------
282 bool MySQLNativeSettings::canAdvance() const
284 if ( m_aDatabaseName.GetText().Len() == 0 )
285 return false;
287 if ( m_aHostPortRadio.IsChecked()
288 && ( ( m_aHostName.GetText().Len() == 0 )
289 || ( m_aPort.GetText().Len() == 0 )
292 return false;
294 #ifdef UNX
295 if ( ( m_aSocketRadio.IsChecked() )
296 && ( m_aSocket.GetText().Len() == 0 )
298 #else
299 if ( ( m_aNamedPipeRadio.IsChecked() )
300 && ( m_aNamedPipe.GetText().Len() == 0 )
302 #endif
303 return false;
305 return true;
308 //........................................................................
309 } // namespace dbaui
310 //........................................................................