bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / dlg / admincontrols.cxx
blobfd2c978b502c100bcb74b419035c2ff91912fe5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "admincontrols.hxx"
22 #include "admincontrols.hrc"
23 #include "dbu_dlg.hrc"
24 #include "dsitems.hxx"
25 #include "moduledbu.hxx"
27 #include <svl/eitem.hxx>
28 #include <svl/stritem.hxx>
29 #include <svl/intitem.hxx>
31 //........................................................................
32 namespace dbaui
34 //........................................................................
36 //====================================================================
37 //= TextResetOperatorEventFilter
38 //====================================================================
39 class TextResetOperatorEventFilter : public ::svt::IWindowEventFilter
41 public:
42 TextResetOperatorEventFilter()
46 // IWindowEventFilter
47 virtual bool payAttentionTo( const VclWindowEvent& _rEvent ) const
49 return ( _rEvent.GetId() == VCLEVENT_WINDOW_ENABLED )
50 || ( _rEvent.GetId() == VCLEVENT_WINDOW_DISABLED )
51 || ( _rEvent.GetId() == VCLEVENT_EDIT_MODIFY );
55 //====================================================================
56 //= TextResetOperator
57 //====================================================================
58 class TextResetOperator :public ::svt::IWindowOperator
60 public:
61 TextResetOperator( const String& _rDisabledText )
62 :m_sDisabledText( _rDisabledText )
66 // IWindowOperator
67 virtual void operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const;
69 private:
70 const String m_sDisabledText;
71 String m_sUserText;
74 //--------------------------------------------------------------------
75 void TextResetOperator::operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const
77 OSL_ENSURE( _rTrigger.GetWindow() == &_rOperateOn, "TextResetOperator::operateOn: you're misusing this implementation!" );
79 switch ( _rTrigger.GetId() )
81 case 0:
82 // initial call
83 const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
84 break;
86 case VCLEVENT_EDIT_MODIFY:
87 if ( _rTrigger.GetWindow()->IsEnabled() )
88 const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
89 break;
91 case VCLEVENT_WINDOW_ENABLED:
92 _rOperateOn.SetText( m_sUserText );
93 break;
95 case VCLEVENT_WINDOW_DISABLED:
96 _rOperateOn.SetText( m_sDisabledText );
97 break;
99 default:
100 OSL_FAIL( "TextResetOperator::operateOn: unexpected event ID!" );
101 // all those IDs should have been filtered out by payAttentionTo
102 break;
106 //====================================================================
107 //= TextResetOperatorController
108 //====================================================================
109 class TextResetOperatorController_Base
111 protected:
112 TextResetOperatorController_Base( const String& _rDisabledText )
113 :m_pEventFilter( new TextResetOperatorEventFilter )
114 ,m_pOperator( new TextResetOperator( _rDisabledText ) )
118 inline ::svt::PWindowEventFilter getEventFilter() const { return m_pEventFilter; }
119 inline ::svt::PWindowOperator getOperator() const { return m_pOperator; }
121 private:
122 ::svt::PWindowEventFilter m_pEventFilter;
123 ::svt::PWindowOperator m_pOperator;
126 class TextResetOperatorController :public TextResetOperatorController_Base
127 ,public ::svt::DialogController
129 public:
130 TextResetOperatorController( Window& _rObservee, const String& _rDisabledText )
131 :TextResetOperatorController_Base( _rDisabledText )
132 ,::svt::DialogController( _rObservee, getEventFilter(), getOperator() )
134 addDependentWindow( _rObservee );
138 //====================================================================
139 //= MySQLNativeSettings
140 //====================================================================
141 //--------------------------------------------------------------------
142 MySQLNativeSettings::MySQLNativeSettings( Window& _rParent, const Link& _rControlModificationLink )
143 :Control( &_rParent, ModuleRes( RID_MYSQL_NATIVE_SETTINGS ).SetAutoRelease( sal_False ) )
144 ,m_aDatabaseNameLabel ( this, ModuleRes( FT_MYSQL_DATABASE_NAME ) )
145 ,m_aDatabaseName ( this, ModuleRes( ED_MYSQL_DATABASE_NAME ) )
146 ,m_aHostPortRadio ( this, ModuleRes( RB_MYSQL_HOST_PORT ) )
147 ,m_aSocketRadio ( this, ModuleRes( RB_MYSQL_SOCKET ) )
148 ,m_aNamedPipeRadio ( this, ModuleRes( RB_MYSQL_NAMED_PIPE ) )
149 ,m_aHostNameLabel ( this, ModuleRes( FT_COMMON_HOST_NAME ) )
150 ,m_aHostName ( this, ModuleRes( ED_COMMON_HOST_NAME ) )
151 ,m_aPortLabel ( this, ModuleRes( FT_COMMON_PORT ) )
152 ,m_aPort ( this, ModuleRes( NF_COMMON_PORT ) )
153 ,m_aDefaultPort ( this, ModuleRes( FT_COMMON_PORT_DEFAULT ) )
154 ,m_aSocket ( this, ModuleRes( ED_MYSQL_SOCKET ) )
155 ,m_aNamedPipe ( this, ModuleRes( ED_MYSQL_NAMED_PIPE ) )
157 FreeResource();
159 m_aDatabaseName.SetModifyHdl( _rControlModificationLink );
160 m_aHostName.SetModifyHdl( _rControlModificationLink );
161 m_aPort.SetModifyHdl( _rControlModificationLink );
162 m_aNamedPipe.SetModifyHdl( _rControlModificationLink );
163 m_aSocketRadio.SetToggleHdl( _rControlModificationLink );
164 m_aNamedPipeRadio.SetToggleHdl( _rControlModificationLink );
166 m_aControlDependencies.enableOnRadioCheck( m_aHostPortRadio, m_aHostNameLabel, m_aHostName, m_aPortLabel, m_aPort, m_aDefaultPort );
167 m_aControlDependencies.enableOnRadioCheck( m_aSocketRadio, m_aSocket );
168 m_aControlDependencies.enableOnRadioCheck( m_aNamedPipeRadio, m_aNamedPipe );
170 m_aControlDependencies.addController( ::svt::PDialogController(
171 new TextResetOperatorController( m_aHostName, OUString("localhost") )
172 ) );
174 // sockets are available on Unix systems only, named pipes only on Windows
175 #ifdef UNX
176 m_aNamedPipeRadio.Hide();
177 m_aNamedPipe.Hide();
178 #else
179 m_aSocketRadio.Hide();
180 m_aSocket.Hide();
181 #endif
184 //--------------------------------------------------------------------
185 MySQLNativeSettings::~MySQLNativeSettings()
189 //--------------------------------------------------------------------
190 void MySQLNativeSettings::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
192 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aDatabaseName ) );
193 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aHostName ) );
194 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aPort ) );
195 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aSocket ) );
196 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aNamedPipe ) );
199 //--------------------------------------------------------------------
200 void MySQLNativeSettings::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
202 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDatabaseNameLabel ) );
203 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aHostNameLabel ) );
204 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aPortLabel ) );
205 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDefaultPort ) );
206 _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aSocketRadio ) );
207 _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aNamedPipeRadio ) );
210 //--------------------------------------------------------------------
211 sal_Bool MySQLNativeSettings::FillItemSet( SfxItemSet& _rSet )
213 sal_Bool bChangedSomething = sal_False;
215 OGenericAdministrationPage::fillString( _rSet, &m_aHostName, DSID_CONN_HOSTNAME, bChangedSomething );
216 OGenericAdministrationPage::fillString( _rSet, &m_aDatabaseName, DSID_DATABASENAME, bChangedSomething );
217 OGenericAdministrationPage::fillInt32 ( _rSet, &m_aPort, DSID_MYSQL_PORTNUMBER, bChangedSomething );
218 #ifdef UNX
219 OGenericAdministrationPage::fillString( _rSet, &m_aSocket, DSID_CONN_SOCKET, bChangedSomething );
220 #else
221 OGenericAdministrationPage::fillString( _rSet, &m_aNamedPipe, DSID_NAMED_PIPE, bChangedSomething );
222 #endif
224 return bChangedSomething;
227 //--------------------------------------------------------------------
228 void MySQLNativeSettings::implInitControls(const SfxItemSet& _rSet )
230 SFX_ITEMSET_GET( _rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True );
231 bool bValid = !pInvalid || !pInvalid->GetValue();
232 if ( !bValid )
233 return;
235 SFX_ITEMSET_GET( _rSet, pDatabaseName, SfxStringItem, DSID_DATABASENAME, sal_True );
236 SFX_ITEMSET_GET( _rSet, pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True );
237 SFX_ITEMSET_GET( _rSet, pPortNumber, SfxInt32Item, DSID_MYSQL_PORTNUMBER, sal_True );
238 SFX_ITEMSET_GET( _rSet, pSocket, SfxStringItem, DSID_CONN_SOCKET, sal_True );
239 SFX_ITEMSET_GET( _rSet, pNamedPipe, SfxStringItem, DSID_NAMED_PIPE, sal_True );
241 m_aDatabaseName.SetText( pDatabaseName->GetValue() );
242 m_aDatabaseName.ClearModifyFlag();
244 m_aHostName.SetText( pHostName->GetValue() );
245 m_aHostName.ClearModifyFlag();
247 m_aPort.SetValue( pPortNumber->GetValue() );
248 m_aPort.ClearModifyFlag();
250 m_aSocket.SetText( pSocket->GetValue() );
251 m_aSocket.ClearModifyFlag();
253 m_aNamedPipe.SetText( pNamedPipe->GetValue() );
254 m_aNamedPipe.ClearModifyFlag();
256 // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over
257 // the port
258 #ifdef UNX
259 RadioButton& rSocketPipeRadio = m_aSocketRadio;
260 const SfxStringItem* pSocketPipeItem = pSocket;
261 #else
262 RadioButton& rSocketPipeRadio = m_aNamedPipeRadio;
263 const SfxStringItem* pSocketPipeItem = pNamedPipe;
264 #endif
265 String sSocketPipe( pSocketPipeItem->GetValue() );
266 if ( sSocketPipe.Len() > 0 )
267 rSocketPipeRadio.Check();
268 else
269 m_aHostPortRadio.Check();
272 //--------------------------------------------------------------------
273 bool MySQLNativeSettings::canAdvance() const
275 if ( m_aDatabaseName.GetText().isEmpty() )
276 return false;
278 if ( m_aHostPortRadio.IsChecked()
279 && ( ( m_aHostName.GetText().isEmpty() )
280 || ( m_aPort.GetText().isEmpty() )
283 return false;
285 #ifdef UNX
286 if ( ( m_aSocketRadio.IsChecked() )
287 && ( m_aSocket.GetText().isEmpty() )
289 #else
290 if ( ( m_aNamedPipeRadio.IsChecked() )
291 && ( m_aNamedPipe.GetText().isEmpty() )
293 #endif
294 return false;
296 return true;
299 //........................................................................
300 } // namespace dbaui
301 //........................................................................
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */