196de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 396de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 496de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 596de5490SAndrew Rist * distributed with this work for additional information 696de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 796de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 896de5490SAndrew Rist * "License"); you may not use this file except in compliance 996de5490SAndrew Rist * with the License. You may obtain a copy of the License at 1096de5490SAndrew Rist * 1196de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1296de5490SAndrew Rist * 1396de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 1496de5490SAndrew Rist * software distributed under the License is distributed on an 1596de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1696de5490SAndrew Rist * KIND, either express or implied. See the License for the 1796de5490SAndrew Rist * specific language governing permissions and limitations 1896de5490SAndrew Rist * under the License. 1996de5490SAndrew Rist * 2096de5490SAndrew Rist *************************************************************/ 2196de5490SAndrew Rist 2296de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25*b63233d8Sdamjan #include "precompiled_dbui.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: TextResetOperatorEventFilter()48cdf0e10cSrcweir TextResetOperatorEventFilter() 49cdf0e10cSrcweir { 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir // IWindowEventFilter payAttentionTo(const VclWindowEvent & _rEvent) const53cdf0e10cSrcweir 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: TextResetOperator(const String & _rDisabledText)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 //-------------------------------------------------------------------- operateOn(const VclWindowEvent & _rTrigger,Window & _rOperateOn) const82cdf0e10cSrcweir 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: TextResetOperatorController_Base(const String & _rDisabledText)119cdf0e10cSrcweir TextResetOperatorController_Base( const String& _rDisabledText ) 120cdf0e10cSrcweir :m_pEventFilter( new TextResetOperatorEventFilter ) 121cdf0e10cSrcweir ,m_pOperator( new TextResetOperator( _rDisabledText ) ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir } 124cdf0e10cSrcweir getEventFilter() const125cdf0e10cSrcweir inline ::svt::PWindowEventFilter getEventFilter() const { return m_pEventFilter; } getOperator() const126cdf0e10cSrcweir 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: TextResetOperatorController(Window & _rObservee,const String & _rDisabledText)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 //-------------------------------------------------------------------- MySQLNativeSettings(Window & _rParent,const Link & _rControlModificationLink)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 ); 1694d78d4d8SAriel Constenla-Haile m_aSocket.SetModifyHdl( _rControlModificationLink ); 170cdf0e10cSrcweir m_aNamedPipe.SetModifyHdl( _rControlModificationLink ); 171cdf0e10cSrcweir m_aSocketRadio.SetToggleHdl( _rControlModificationLink ); 172cdf0e10cSrcweir m_aNamedPipeRadio.SetToggleHdl( _rControlModificationLink ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aHostPortRadio, m_aHostNameLabel, m_aHostName, m_aPortLabel, m_aPort, m_aDefaultPort ); 175cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aSocketRadio, m_aSocket ); 176cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aNamedPipeRadio, m_aNamedPipe ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir m_aControlDependencies.addController( ::svt::PDialogController( 179cdf0e10cSrcweir new TextResetOperatorController( m_aHostName, String::CreateFromAscii( "localhost" ) ) 180cdf0e10cSrcweir ) ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir // sockets are available on Unix systems only, named pipes only on Windows 183cdf0e10cSrcweir #ifdef UNX 184cdf0e10cSrcweir m_aNamedPipeRadio.Hide(); 185cdf0e10cSrcweir m_aNamedPipe.Hide(); 186cdf0e10cSrcweir #else 187cdf0e10cSrcweir m_aSocketRadio.Hide(); 188cdf0e10cSrcweir m_aSocket.Hide(); 189cdf0e10cSrcweir #endif 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir //-------------------------------------------------------------------- ~MySQLNativeSettings()193cdf0e10cSrcweir MySQLNativeSettings::~MySQLNativeSettings() 194cdf0e10cSrcweir { 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir //-------------------------------------------------------------------- fillControls(::std::vector<ISaveValueWrapper * > & _rControlList)198cdf0e10cSrcweir void MySQLNativeSettings::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aDatabaseName ) ); 201cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aHostName ) ); 202cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aPort ) ); 203cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aSocket ) ); 204cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aNamedPipe ) ); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir //-------------------------------------------------------------------- fillWindows(::std::vector<ISaveValueWrapper * > & _rControlList)208cdf0e10cSrcweir void MySQLNativeSettings::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDatabaseNameLabel ) ); 211cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aHostNameLabel ) ); 212cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aPortLabel ) ); 213cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDefaultPort ) ); 214cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aSocketRadio ) ); 215cdf0e10cSrcweir _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aNamedPipeRadio ) ); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir //-------------------------------------------------------------------- FillItemSet(SfxItemSet & _rSet)219cdf0e10cSrcweir sal_Bool MySQLNativeSettings::FillItemSet( SfxItemSet& _rSet ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir sal_Bool bChangedSomething = sal_False; 222cdf0e10cSrcweir 223cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aHostName, DSID_CONN_HOSTNAME, bChangedSomething ); 224cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aDatabaseName, DSID_DATABASENAME, bChangedSomething ); 225cdf0e10cSrcweir OGenericAdministrationPage::fillInt32 ( _rSet, &m_aPort, DSID_MYSQL_PORTNUMBER, bChangedSomething ); 226cdf0e10cSrcweir #ifdef UNX 227cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aSocket, DSID_CONN_SOCKET, bChangedSomething ); 228cdf0e10cSrcweir #else 229cdf0e10cSrcweir OGenericAdministrationPage::fillString( _rSet, &m_aNamedPipe, DSID_NAMED_PIPE, bChangedSomething ); 230cdf0e10cSrcweir #endif 231cdf0e10cSrcweir 232cdf0e10cSrcweir return bChangedSomething; 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir //-------------------------------------------------------------------- implInitControls(const SfxItemSet & _rSet)236cdf0e10cSrcweir void MySQLNativeSettings::implInitControls(const SfxItemSet& _rSet ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True ); 239cdf0e10cSrcweir bool bValid = !pInvalid || !pInvalid->GetValue(); 240cdf0e10cSrcweir if ( !bValid ) 241cdf0e10cSrcweir return; 242cdf0e10cSrcweir 243cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pDatabaseName, SfxStringItem, DSID_DATABASENAME, sal_True ); 244cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True ); 245cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pPortNumber, SfxInt32Item, DSID_MYSQL_PORTNUMBER, sal_True ); 246cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pSocket, SfxStringItem, DSID_CONN_SOCKET, sal_True ); 247cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pNamedPipe, SfxStringItem, DSID_NAMED_PIPE, sal_True ); 248cdf0e10cSrcweir 249cdf0e10cSrcweir m_aDatabaseName.SetText( pDatabaseName->GetValue() ); 250cdf0e10cSrcweir m_aDatabaseName.ClearModifyFlag(); 251cdf0e10cSrcweir 252cdf0e10cSrcweir m_aHostName.SetText( pHostName->GetValue() ); 253cdf0e10cSrcweir m_aHostName.ClearModifyFlag(); 254cdf0e10cSrcweir 255cdf0e10cSrcweir m_aPort.SetValue( pPortNumber->GetValue() ); 256cdf0e10cSrcweir m_aPort.ClearModifyFlag(); 257cdf0e10cSrcweir 258cdf0e10cSrcweir m_aSocket.SetText( pSocket->GetValue() ); 259cdf0e10cSrcweir m_aSocket.ClearModifyFlag(); 260cdf0e10cSrcweir 261cdf0e10cSrcweir m_aNamedPipe.SetText( pNamedPipe->GetValue() ); 262cdf0e10cSrcweir m_aNamedPipe.ClearModifyFlag(); 263cdf0e10cSrcweir 264cdf0e10cSrcweir // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over 265cdf0e10cSrcweir // the port 266cdf0e10cSrcweir #ifdef UNX 267cdf0e10cSrcweir RadioButton& rSocketPipeRadio = m_aSocketRadio; 268cdf0e10cSrcweir const SfxStringItem* pSocketPipeItem = pSocket; 269cdf0e10cSrcweir #else 270cdf0e10cSrcweir RadioButton& rSocketPipeRadio = m_aNamedPipeRadio; 271cdf0e10cSrcweir const SfxStringItem* pSocketPipeItem = pNamedPipe; 272cdf0e10cSrcweir #endif 273cdf0e10cSrcweir String sSocketPipe( pSocketPipeItem->GetValue() ); 274cdf0e10cSrcweir if ( sSocketPipe.Len() > 0 ) 275cdf0e10cSrcweir rSocketPipeRadio.Check(); 276cdf0e10cSrcweir else 277cdf0e10cSrcweir m_aHostPortRadio.Check(); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir //-------------------------------------------------------------------- canAdvance() const281cdf0e10cSrcweir bool MySQLNativeSettings::canAdvance() const 282cdf0e10cSrcweir { 283cdf0e10cSrcweir if ( m_aDatabaseName.GetText().Len() == 0 ) 284cdf0e10cSrcweir return false; 285cdf0e10cSrcweir 286cdf0e10cSrcweir if ( m_aHostPortRadio.IsChecked() 287cdf0e10cSrcweir && ( ( m_aHostName.GetText().Len() == 0 ) 288cdf0e10cSrcweir || ( m_aPort.GetText().Len() == 0 ) 289cdf0e10cSrcweir ) 290cdf0e10cSrcweir ) 291cdf0e10cSrcweir return false; 292cdf0e10cSrcweir 293cdf0e10cSrcweir #ifdef UNX 294cdf0e10cSrcweir if ( ( m_aSocketRadio.IsChecked() ) 295cdf0e10cSrcweir && ( m_aSocket.GetText().Len() == 0 ) 296cdf0e10cSrcweir ) 297cdf0e10cSrcweir #else 298cdf0e10cSrcweir if ( ( m_aNamedPipeRadio.IsChecked() ) 299cdf0e10cSrcweir && ( m_aNamedPipe.GetText().Len() == 0 ) 300cdf0e10cSrcweir ) 301cdf0e10cSrcweir #endif 302cdf0e10cSrcweir return false; 303cdf0e10cSrcweir 304cdf0e10cSrcweir return true; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir //........................................................................ 308cdf0e10cSrcweir } // namespace dbaui 309cdf0e10cSrcweir //........................................................................ 310