1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "admincontrols.hxx" 28cdf0e10cSrcweir #include "admincontrols.hrc" 29cdf0e10cSrcweir #include "dbu_dlg.hrc" 30cdf0e10cSrcweir #include "dsitems.hxx" 31cdf0e10cSrcweir #include "moduledbu.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <svl/eitem.hxx> 34cdf0e10cSrcweir #include <svl/stritem.hxx> 35cdf0e10cSrcweir #include <svl/intitem.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir //........................................................................ 38cdf0e10cSrcweir namespace dbaui 39cdf0e10cSrcweir { 40cdf0e10cSrcweir //........................................................................ 41cdf0e10cSrcweir 42cdf0e10cSrcweir //==================================================================== 43cdf0e10cSrcweir //= TextResetOperatorEventFilter 44cdf0e10cSrcweir //==================================================================== 45cdf0e10cSrcweir class TextResetOperatorEventFilter : public ::svt::IWindowEventFilter 46cdf0e10cSrcweir { 47cdf0e10cSrcweir public: 48cdf0e10cSrcweir TextResetOperatorEventFilter() 49cdf0e10cSrcweir { 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir // IWindowEventFilter 53cdf0e10cSrcweir virtual bool payAttentionTo( const VclWindowEvent& _rEvent ) const 54cdf0e10cSrcweir { 55cdf0e10cSrcweir return ( _rEvent.GetId() == VCLEVENT_WINDOW_ENABLED ) 56cdf0e10cSrcweir || ( _rEvent.GetId() == VCLEVENT_WINDOW_DISABLED ) 57cdf0e10cSrcweir || ( _rEvent.GetId() == VCLEVENT_EDIT_MODIFY ); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir }; 60cdf0e10cSrcweir 61cdf0e10cSrcweir //==================================================================== 62cdf0e10cSrcweir //= TextResetOperator 63cdf0e10cSrcweir //==================================================================== 64cdf0e10cSrcweir class TextResetOperator :public ::svt::IWindowOperator 65cdf0e10cSrcweir { 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir TextResetOperator( const String& _rDisabledText ) 68cdf0e10cSrcweir :m_sDisabledText( _rDisabledText ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir // IWindowOperator 73cdf0e10cSrcweir virtual void operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const; 74cdf0e10cSrcweir 75cdf0e10cSrcweir private: 76cdf0e10cSrcweir const String m_sDisabledText; 77cdf0e10cSrcweir String m_sUserText; 78cdf0e10cSrcweir sal_Bool m_bLastKnownEnabledState; 79cdf0e10cSrcweir }; 80cdf0e10cSrcweir 81cdf0e10cSrcweir //-------------------------------------------------------------------- 82cdf0e10cSrcweir void TextResetOperator::operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const 83cdf0e10cSrcweir { 84cdf0e10cSrcweir OSL_ENSURE( _rTrigger.GetWindow() == &_rOperateOn, "TextResetOperator::operateOn: you're misusing this implementation!" ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir switch ( _rTrigger.GetId() ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir case 0: 89cdf0e10cSrcweir // initial call 90cdf0e10cSrcweir const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText(); 91cdf0e10cSrcweir break; 92cdf0e10cSrcweir 93cdf0e10cSrcweir case VCLEVENT_EDIT_MODIFY: 94cdf0e10cSrcweir if ( _rTrigger.GetWindow()->IsEnabled() ) 95cdf0e10cSrcweir const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText(); 96cdf0e10cSrcweir break; 97cdf0e10cSrcweir 98cdf0e10cSrcweir case VCLEVENT_WINDOW_ENABLED: 99cdf0e10cSrcweir _rOperateOn.SetText( m_sUserText ); 100cdf0e10cSrcweir break; 101cdf0e10cSrcweir 102cdf0e10cSrcweir case VCLEVENT_WINDOW_DISABLED: 103cdf0e10cSrcweir _rOperateOn.SetText( m_sDisabledText ); 104cdf0e10cSrcweir break; 105cdf0e10cSrcweir 106cdf0e10cSrcweir default: 107cdf0e10cSrcweir OSL_ENSURE( false, "TextResetOperator::operateOn: unexpected event ID!" ); 108cdf0e10cSrcweir // all those IDs should have been filtered out by payAttentionTo 109cdf0e10cSrcweir break; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir //==================================================================== 114cdf0e10cSrcweir //= TextResetOperatorController 115cdf0e10cSrcweir //==================================================================== 116cdf0e10cSrcweir class TextResetOperatorController_Base 117cdf0e10cSrcweir { 118cdf0e10cSrcweir protected: 119cdf0e10cSrcweir TextResetOperatorController_Base( const String& _rDisabledText ) 120cdf0e10cSrcweir :m_pEventFilter( new TextResetOperatorEventFilter ) 121cdf0e10cSrcweir ,m_pOperator( new TextResetOperator( _rDisabledText ) ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir inline ::svt::PWindowEventFilter getEventFilter() const { return m_pEventFilter; } 126cdf0e10cSrcweir inline ::svt::PWindowOperator getOperator() const { return m_pOperator; } 127cdf0e10cSrcweir 128cdf0e10cSrcweir private: 129cdf0e10cSrcweir ::svt::PWindowEventFilter m_pEventFilter; 130cdf0e10cSrcweir ::svt::PWindowOperator m_pOperator; 131cdf0e10cSrcweir }; 132cdf0e10cSrcweir 133cdf0e10cSrcweir class TextResetOperatorController :public TextResetOperatorController_Base 134cdf0e10cSrcweir ,public ::svt::DialogController 135cdf0e10cSrcweir { 136cdf0e10cSrcweir public: 137cdf0e10cSrcweir TextResetOperatorController( Window& _rObservee, const String& _rDisabledText ) 138cdf0e10cSrcweir :TextResetOperatorController_Base( _rDisabledText ) 139cdf0e10cSrcweir ,::svt::DialogController( _rObservee, getEventFilter(), getOperator() ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir addDependentWindow( _rObservee ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir }; 144cdf0e10cSrcweir 145cdf0e10cSrcweir //==================================================================== 146cdf0e10cSrcweir //= MySQLNativeSettings 147cdf0e10cSrcweir //==================================================================== 148cdf0e10cSrcweir //-------------------------------------------------------------------- 149cdf0e10cSrcweir MySQLNativeSettings::MySQLNativeSettings( Window& _rParent, const Link& _rControlModificationLink ) 150cdf0e10cSrcweir :Control( &_rParent, ModuleRes( RID_MYSQL_NATIVE_SETTINGS ).SetAutoRelease( sal_False ) ) 151cdf0e10cSrcweir ,m_aDatabaseNameLabel ( this, ModuleRes( FT_MYSQL_DATABASE_NAME ) ) 152cdf0e10cSrcweir ,m_aDatabaseName ( this, ModuleRes( ED_MYSQL_DATABASE_NAME ) ) 153cdf0e10cSrcweir ,m_aHostPortRadio ( this, ModuleRes( RB_MYSQL_HOST_PORT ) ) 154cdf0e10cSrcweir ,m_aSocketRadio ( this, ModuleRes( RB_MYSQL_SOCKET ) ) 155cdf0e10cSrcweir ,m_aNamedPipeRadio ( this, ModuleRes( RB_MYSQL_NAMED_PIPE ) ) 156cdf0e10cSrcweir ,m_aHostNameLabel ( this, ModuleRes( FT_COMMON_HOST_NAME ) ) 157cdf0e10cSrcweir ,m_aHostName ( this, ModuleRes( ED_COMMON_HOST_NAME ) ) 158cdf0e10cSrcweir ,m_aPortLabel ( this, ModuleRes( FT_COMMON_PORT ) ) 159cdf0e10cSrcweir ,m_aPort ( this, ModuleRes( NF_COMMON_PORT ) ) 160cdf0e10cSrcweir ,m_aDefaultPort ( this, ModuleRes( FT_COMMON_PORT_DEFAULT ) ) 161cdf0e10cSrcweir ,m_aSocket ( this, ModuleRes( ED_MYSQL_SOCKET ) ) 162cdf0e10cSrcweir ,m_aNamedPipe ( this, ModuleRes( ED_MYSQL_NAMED_PIPE ) ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir FreeResource(); 165cdf0e10cSrcweir 166cdf0e10cSrcweir m_aDatabaseName.SetModifyHdl( _rControlModificationLink ); 167cdf0e10cSrcweir m_aHostName.SetModifyHdl( _rControlModificationLink ); 168cdf0e10cSrcweir m_aPort.SetModifyHdl( _rControlModificationLink ); 169cdf0e10cSrcweir m_aNamedPipe.SetModifyHdl( _rControlModificationLink ); 170cdf0e10cSrcweir m_aSocketRadio.SetToggleHdl( _rControlModificationLink ); 171cdf0e10cSrcweir m_aNamedPipeRadio.SetToggleHdl( _rControlModificationLink ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aHostPortRadio, m_aHostNameLabel, m_aHostName, m_aPortLabel, m_aPort, m_aDefaultPort ); 174cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aSocketRadio, m_aSocket ); 175cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aNamedPipeRadio, m_aNamedPipe ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir m_aControlDependencies.addController( ::svt::PDialogController( 178cdf0e10cSrcweir new TextResetOperatorController( m_aHostName, String::CreateFromAscii( "localhost" ) ) 179cdf0e10cSrcweir ) ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir // sockets are available on Unix systems only, named pipes only on Windows 182cdf0e10cSrcweir #ifdef UNX 183cdf0e10cSrcweir m_aNamedPipeRadio.Hide(); 184cdf0e10cSrcweir m_aNamedPipe.Hide(); 185cdf0e10cSrcweir #else 186cdf0e10cSrcweir m_aSocketRadio.Hide(); 187cdf0e10cSrcweir m_aSocket.Hide(); 188cdf0e10cSrcweir #endif 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir //-------------------------------------------------------------------- 192cdf0e10cSrcweir MySQLNativeSettings::~MySQLNativeSettings() 193cdf0e10cSrcweir { 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir //-------------------------------------------------------------------- 197cdf0e10cSrcweir void MySQLNativeSettings::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aDatabaseName ) ); 200cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aHostName ) ); 201cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aPort ) ); 202cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aSocket ) ); 203cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aNamedPipe ) ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir //-------------------------------------------------------------------- 207cdf0e10cSrcweir void MySQLNativeSettings::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDatabaseNameLabel ) ); 210cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aHostNameLabel ) ); 211cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aPortLabel ) ); 212cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDefaultPort ) ); 213cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aSocketRadio ) ); 214cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aNamedPipeRadio ) ); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir //-------------------------------------------------------------------- 218cdf0e10cSrcweir sal_Bool MySQLNativeSettings::FillItemSet( SfxItemSet& _rSet ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir sal_Bool bChangedSomething = sal_False; 221cdf0e10cSrcweir 222cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aHostName, DSID_CONN_HOSTNAME, bChangedSomething ); 223cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aDatabaseName, DSID_DATABASENAME, bChangedSomething ); 224cdf0e10cSrcweir OGenericAdministrationPage::fillInt32 ( _rSet, &m_aPort, DSID_MYSQL_PORTNUMBER, bChangedSomething ); 225cdf0e10cSrcweir #ifdef UNX 226cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aSocket, DSID_CONN_SOCKET, bChangedSomething ); 227cdf0e10cSrcweir #else 228cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aNamedPipe, DSID_NAMED_PIPE, bChangedSomething ); 229cdf0e10cSrcweir #endif 230cdf0e10cSrcweir 231cdf0e10cSrcweir return bChangedSomething; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir //-------------------------------------------------------------------- 235cdf0e10cSrcweir void MySQLNativeSettings::implInitControls(const SfxItemSet& _rSet ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True ); 238cdf0e10cSrcweir bool bValid = !pInvalid || !pInvalid->GetValue(); 239cdf0e10cSrcweir if ( !bValid ) 240cdf0e10cSrcweir return; 241cdf0e10cSrcweir 242cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pDatabaseName, SfxStringItem, DSID_DATABASENAME, sal_True ); 243cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True ); 244cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pPortNumber, SfxInt32Item, DSID_MYSQL_PORTNUMBER, sal_True ); 245cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pSocket, SfxStringItem, DSID_CONN_SOCKET, sal_True ); 246cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pNamedPipe, SfxStringItem, DSID_NAMED_PIPE, sal_True ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir m_aDatabaseName.SetText( pDatabaseName->GetValue() ); 249cdf0e10cSrcweir m_aDatabaseName.ClearModifyFlag(); 250cdf0e10cSrcweir 251cdf0e10cSrcweir m_aHostName.SetText( pHostName->GetValue() ); 252cdf0e10cSrcweir m_aHostName.ClearModifyFlag(); 253cdf0e10cSrcweir 254cdf0e10cSrcweir m_aPort.SetValue( pPortNumber->GetValue() ); 255cdf0e10cSrcweir m_aPort.ClearModifyFlag(); 256cdf0e10cSrcweir 257cdf0e10cSrcweir m_aSocket.SetText( pSocket->GetValue() ); 258cdf0e10cSrcweir m_aSocket.ClearModifyFlag(); 259cdf0e10cSrcweir 260cdf0e10cSrcweir m_aNamedPipe.SetText( pNamedPipe->GetValue() ); 261cdf0e10cSrcweir m_aNamedPipe.ClearModifyFlag(); 262cdf0e10cSrcweir 263cdf0e10cSrcweir // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over 264cdf0e10cSrcweir // the port 265cdf0e10cSrcweir #ifdef UNX 266cdf0e10cSrcweir RadioButton& rSocketPipeRadio = m_aSocketRadio; 267cdf0e10cSrcweir const SfxStringItem* pSocketPipeItem = pSocket; 268cdf0e10cSrcweir #else 269cdf0e10cSrcweir RadioButton& rSocketPipeRadio = m_aNamedPipeRadio; 270cdf0e10cSrcweir const SfxStringItem* pSocketPipeItem = pNamedPipe; 271cdf0e10cSrcweir #endif 272cdf0e10cSrcweir String sSocketPipe( pSocketPipeItem->GetValue() ); 273cdf0e10cSrcweir if ( sSocketPipe.Len() > 0 ) 274cdf0e10cSrcweir rSocketPipeRadio.Check(); 275cdf0e10cSrcweir else 276cdf0e10cSrcweir m_aHostPortRadio.Check(); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir //-------------------------------------------------------------------- 280cdf0e10cSrcweir bool MySQLNativeSettings::canAdvance() const 281cdf0e10cSrcweir { 282cdf0e10cSrcweir if ( m_aDatabaseName.GetText().Len() == 0 ) 283cdf0e10cSrcweir return false; 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( m_aHostPortRadio.IsChecked() 286cdf0e10cSrcweir && ( ( m_aHostName.GetText().Len() == 0 ) 287cdf0e10cSrcweir || ( m_aPort.GetText().Len() == 0 ) 288cdf0e10cSrcweir ) 289cdf0e10cSrcweir ) 290cdf0e10cSrcweir return false; 291cdf0e10cSrcweir 292cdf0e10cSrcweir #ifdef UNX 293cdf0e10cSrcweir if ( ( m_aSocketRadio.IsChecked() ) 294cdf0e10cSrcweir && ( m_aSocket.GetText().Len() == 0 ) 295cdf0e10cSrcweir ) 296cdf0e10cSrcweir #else 297cdf0e10cSrcweir if ( ( m_aNamedPipeRadio.IsChecked() ) 298cdf0e10cSrcweir && ( m_aNamedPipe.GetText().Len() == 0 ) 299cdf0e10cSrcweir ) 300cdf0e10cSrcweir #endif 301cdf0e10cSrcweir return false; 302cdf0e10cSrcweir 303cdf0e10cSrcweir return true; 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir //........................................................................ 307cdf0e10cSrcweir } // namespace dbaui 308cdf0e10cSrcweir //........................................................................ 309