Update ooo320-m1
[ooovba.git] / dbaccess / source / ui / dlg / advancedsettings.cxx
blob825e5f66b4485bb64fae3fa68a9a36a1beae54e5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: advancedsettings.cxx,v $
10 * $Revision: 1.4.68.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "advancedsettings.hxx"
35 #include "advancedsettingsdlg.hxx"
36 #include "moduledbu.hxx"
37 #include "dsitems.hxx"
38 #include "DbAdminImpl.hxx"
39 #include "DriverSettings.hxx"
40 #include "datasourceui.hxx"
42 #include "dbu_resource.hrc"
43 #include "dbu_dlg.hrc"
44 #include "dbadmin.hrc"
45 #include "advancedsettings.hrc"
47 /** === begin UNO includes === **/
48 /** === end UNO includes === **/
50 #include <svtools/eitem.hxx>
51 #include <svtools/intitem.hxx>
52 #include <svtools/stritem.hxx>
54 #include <vcl/msgbox.hxx>
56 //........................................................................
57 namespace dbaui
59 //........................................................................
61 /** === begin UNO using === **/
62 using ::com::sun::star::uno::Reference;
63 using ::com::sun::star::lang::XMultiServiceFactory;
64 using ::com::sun::star::uno::Any;
65 using ::com::sun::star::beans::XPropertySet;
66 using ::com::sun::star::sdbc::XConnection;
67 using ::com::sun::star::sdbc::XDriver;
68 /** === end UNO using === **/
70 //========================================================================
71 //= SpecialSettingsPage
72 //========================================================================
73 struct BooleanSettingDesc
75 CheckBox** ppControl; // the dialog's control which displays this setting
76 USHORT nControlResId; // the resource ID to load the control from
77 USHORT nItemId; // the ID of the item (in an SfxItemSet) which corresponds to this setting
78 bool bInvertedDisplay; // true if and only if the checkbox is checked when the item is FALSE, and vice versa
81 //========================================================================
82 //= SpecialSettingsPage
83 //========================================================================
84 SpecialSettingsPage::SpecialSettingsPage( Window* pParent, const SfxItemSet& _rCoreAttrs, const DataSourceMetaData& _rDSMeta )
85 :OGenericAdministrationPage( pParent, ModuleRes( PAGE_ADVANCED_SETTINGS_SPECIAL ), _rCoreAttrs )
86 ,m_aTopLine( this, ModuleRes( FL_DATAHANDLING ) )
87 ,m_pIsSQL92Check( NULL )
88 ,m_pAppendTableAlias( NULL )
89 ,m_pAsBeforeCorrelationName( NULL )
90 ,m_pEnableOuterJoin( NULL )
91 ,m_pIgnoreDriverPrivileges( NULL )
92 ,m_pParameterSubstitution( NULL )
93 ,m_pSuppressVersionColumn( NULL )
94 ,m_pCatalog( NULL )
95 ,m_pSchema( NULL )
96 ,m_pIndexAppendix( NULL )
97 ,m_pDosLineEnds( NULL )
98 ,m_pCheckRequiredFields( NULL )
99 ,m_pIgnoreCurrency(NULL)
100 ,m_pEscapeDateTime(NULL)
101 ,m_pBooleanComparisonModeLabel( NULL )
102 ,m_pBooleanComparisonMode( NULL )
103 ,m_aControlDependencies()
104 ,m_aBooleanSettings()
105 ,m_aSupported( _rDSMeta.getAdvancedSettingsSupport() )
107 impl_initBooleanSettings();
109 DataSourceUI aDSUI( _rDSMeta );
110 // create all the check boxes for the boolean settings
111 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
112 setting != m_aBooleanSettings.end();
113 ++setting
116 USHORT nItemId = setting->nItemId;
117 if ( aDSUI.hasSetting( nItemId ) )
119 USHORT nID = setting->nControlResId;
120 (*setting->ppControl) = new CheckBox( this, ModuleRes( nID ) );
121 (*setting->ppControl)->SetClickHdl( getControlModifiedLink() );
125 if ( m_pAsBeforeCorrelationName && m_pAppendTableAlias )
126 // make m_pAsBeforeCorrelationName depend on m_pAppendTableAlias
127 m_aControlDependencies.enableOnCheckMark( *m_pAppendTableAlias, *m_pAsBeforeCorrelationName );
129 // move the controls to the appropriate positions
130 Point aPos( m_aTopLine.GetPosPixel() );
131 aPos.Move( 0, m_aTopLine.GetSizePixel().Height() );
132 Size aFirstDistance( LogicToPixel( Size( INDENTED_X, RELATED_CONTROLS ), MAP_APPFONT ) );
133 aPos.Move( aFirstDistance.Width(), aFirstDistance.Height() );
135 Size aUnrelatedControls( LogicToPixel( Size( RELATED_CONTROLS, RELATED_CONTROLS ), MAP_APPFONT ) );
137 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
138 setting != m_aBooleanSettings.end();
139 ++setting
142 if ( !*setting->ppControl )
143 continue;
145 (*setting->ppControl)->SetPosPixel( aPos );
146 aPos.Move( 0, (*setting->ppControl)->GetSizePixel().Height() );
147 aPos.Move( 0, aUnrelatedControls.Height() );
150 // create the controls for the boolean comparison mode
151 if ( m_aSupported.bBooleanComparisonMode )
153 m_pBooleanComparisonModeLabel = new FixedText( this, ModuleRes( FT_BOOLEANCOMPARISON ) );
154 m_pBooleanComparisonMode = new ListBox( this, ModuleRes( LB_BOOLEANCOMPARISON ) );
155 m_pBooleanComparisonMode->SetDropDownLineCount( 4 );
156 m_pBooleanComparisonMode->SetSelectHdl( getControlModifiedLink() );
158 Point aLabelPos( m_pBooleanComparisonModeLabel->GetPosPixel() );
159 Point aControlPos( m_pBooleanComparisonMode->GetPosPixel() );
160 long nMoveUp = aControlPos.Y() - aPos.Y();
162 m_pBooleanComparisonModeLabel->SetPosPixel( Point( aLabelPos.X(), aLabelPos.Y() - nMoveUp ) );
163 m_pBooleanComparisonMode->SetPosPixel( Point( aControlPos.X(), aControlPos.Y() - nMoveUp ) );
166 FreeResource();
169 // -----------------------------------------------------------------------
170 SpecialSettingsPage::~SpecialSettingsPage()
172 m_aControlDependencies.clear();
174 DELETEZ( m_pIsSQL92Check );
175 DELETEZ( m_pAppendTableAlias );
176 DELETEZ( m_pAsBeforeCorrelationName );
177 DELETEZ( m_pParameterSubstitution );
178 DELETEZ( m_pIgnoreDriverPrivileges );
179 DELETEZ( m_pSuppressVersionColumn );
180 DELETEZ( m_pEnableOuterJoin );
181 DELETEZ( m_pCatalog );
182 DELETEZ( m_pSchema );
183 DELETEZ( m_pIndexAppendix );
184 DELETEZ( m_pDosLineEnds );
185 DELETEZ( m_pCheckRequiredFields );
186 DELETEZ( m_pIgnoreCurrency );
187 DELETEZ( m_pEscapeDateTime );
188 DELETEZ( m_pBooleanComparisonModeLabel );
189 DELETEZ( m_pBooleanComparisonMode );
192 // -----------------------------------------------------------------------
193 void SpecialSettingsPage::impl_initBooleanSettings()
195 OSL_PRECOND( m_aBooleanSettings.empty(), "SpecialSettingsPage::impl_initBooleanSettings: called twice!" );
197 // for easier maintainance, write the table in this form, then copy it to m_aBooleanSettings
198 BooleanSettingDesc aSettings[] = {
199 { &m_pIsSQL92Check, CB_SQL92CHECK, DSID_SQL92CHECK, false },
200 { &m_pAppendTableAlias, CB_APPENDTABLEALIAS, DSID_APPEND_TABLE_ALIAS, false },
201 { &m_pAsBeforeCorrelationName, CB_AS_BEFORE_CORR_NAME, DSID_AS_BEFORE_CORRNAME, false },
202 { &m_pEnableOuterJoin, CB_ENABLEOUTERJOIN, DSID_ENABLEOUTERJOIN, false },
203 { &m_pIgnoreDriverPrivileges, CB_IGNOREDRIVER_PRIV, DSID_IGNOREDRIVER_PRIV, false },
204 { &m_pParameterSubstitution, CB_PARAMETERNAMESUBST, DSID_PARAMETERNAMESUBST, false },
205 { &m_pSuppressVersionColumn, CB_SUPPRESVERSIONCL, DSID_SUPPRESSVERSIONCL, true },
206 { &m_pCatalog, CB_CATALOG, DSID_CATALOG, false },
207 { &m_pSchema, CB_SCHEMA, DSID_SCHEMA, false },
208 { &m_pIndexAppendix, CB_IGNOREINDEXAPPENDIX, DSID_INDEXAPPENDIX, false },
209 { &m_pDosLineEnds, CB_DOSLINEENDS, DSID_DOSLINEENDS, false },
210 { &m_pCheckRequiredFields, CB_CHECK_REQUIRED, DSID_CHECK_REQUIRED_FIELDS, false },
211 { &m_pIgnoreCurrency, CB_IGNORECURRENCY, DSID_IGNORECURRENCY, false },
212 { &m_pEscapeDateTime, CB_ESCAPE_DATETIME, DSID_ESCAPE_DATETIME, false },
213 { NULL, 0, 0, false }
216 for ( const BooleanSettingDesc* pCopy = aSettings; pCopy->nItemId != 0; ++pCopy )
218 USHORT nID = pCopy->nItemId;
219 (void) nID;
220 m_aBooleanSettings.push_back( *pCopy );
224 // -----------------------------------------------------------------------
225 void SpecialSettingsPage::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
227 if ( m_aSupported.bBooleanComparisonMode )
229 _rControlList.push_back( new ODisableWrapper< FixedText >( m_pBooleanComparisonModeLabel ) );
233 // -----------------------------------------------------------------------
234 void SpecialSettingsPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
236 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
237 setting != m_aBooleanSettings.end();
238 ++setting
241 if ( *setting->ppControl )
243 _rControlList.push_back( new OSaveValueWrapper< CheckBox >( *setting->ppControl ) );
247 if ( m_aSupported.bBooleanComparisonMode )
248 _rControlList.push_back( new OSaveValueWrapper< ListBox >( m_pBooleanComparisonMode ) );
251 // -----------------------------------------------------------------------
252 void SpecialSettingsPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
254 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
255 sal_Bool bValid, bReadonly;
256 getFlags( _rSet, bValid, bReadonly );
258 if ( !bValid )
260 OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
261 return;
264 // the boolean items
265 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
266 setting != m_aBooleanSettings.end();
267 ++setting
270 if ( !*setting->ppControl )
271 continue;
273 SFX_ITEMSET_GET( _rSet, pItem, SfxBoolItem, setting->nItemId, sal_True );
274 bool bValue = pItem->GetValue();
275 if ( setting->bInvertedDisplay )
276 bValue = !bValue;
278 (*setting->ppControl)->Check( bValue );
281 // the non-boolean items
282 if ( m_aSupported.bBooleanComparisonMode )
284 SFX_ITEMSET_GET( _rSet, pBooleanComparison, SfxInt32Item, DSID_BOOLEANCOMPARISON, sal_True );
285 m_pBooleanComparisonMode->SelectEntryPos( static_cast< USHORT >( pBooleanComparison->GetValue() ) );
288 OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
291 // -----------------------------------------------------------------------
292 sal_Bool SpecialSettingsPage::FillItemSet( SfxItemSet& _rSet )
294 sal_Bool bChangedSomething = sal_False;
296 // the boolean items
297 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
298 setting != m_aBooleanSettings.end();
299 ++setting
302 if ( !*setting->ppControl )
303 continue;
304 fillBool( _rSet, *setting->ppControl, setting->nItemId, bChangedSomething, setting->bInvertedDisplay );
307 // the non-boolean items
308 if ( m_aSupported.bBooleanComparisonMode )
310 if ( m_pBooleanComparisonMode->GetSelectEntryPos() != m_pBooleanComparisonMode->GetSavedValue() )
312 _rSet.Put( SfxInt32Item( DSID_BOOLEANCOMPARISON, m_pBooleanComparisonMode->GetSelectEntryPos() ) );
313 bChangedSomething = sal_True;
316 return bChangedSomething;
319 //========================================================================
320 //= GeneratedValuesPage
321 //========================================================================
322 //------------------------------------------------------------------------
323 GeneratedValuesPage::GeneratedValuesPage( Window* pParent, const SfxItemSet& _rCoreAttrs )
324 :OGenericAdministrationPage(pParent, ModuleRes( PAGE_GENERATED_VALUES ), _rCoreAttrs)
325 ,m_aAutoFixedLine ( this, ModuleRes( FL_SEPARATORAUTO ) )
326 ,m_aAutoRetrievingEnabled( this, ModuleRes( CB_RETRIEVE_AUTO ) )
327 ,m_aAutoIncrementLabel ( this, ModuleRes( FT_AUTOINCREMENTVALUE ) )
328 ,m_aAutoIncrement ( this, ModuleRes( ET_AUTOINCREMENTVALUE ) )
329 ,m_aAutoRetrievingLabel ( this, ModuleRes( FT_RETRIEVE_AUTO ) )
330 ,m_aAutoRetrieving ( this, ModuleRes( ET_RETRIEVE_AUTO ) )
332 m_aAutoRetrievingEnabled.SetClickHdl( getControlModifiedLink() );
333 m_aAutoIncrement.SetModifyHdl( getControlModifiedLink() );
334 m_aAutoRetrieving.SetModifyHdl( getControlModifiedLink() );
336 m_aControlDependencies.enableOnCheckMark( m_aAutoRetrievingEnabled,
337 m_aAutoIncrementLabel, m_aAutoIncrement, m_aAutoRetrievingLabel, m_aAutoRetrieving );
339 FreeResource();
342 // -----------------------------------------------------------------------
343 GeneratedValuesPage::~GeneratedValuesPage()
345 m_aControlDependencies.clear();
348 // -----------------------------------------------------------------------
349 void GeneratedValuesPage::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
351 _rControlList.push_back( new ODisableWrapper< FixedLine >( &m_aAutoFixedLine ) );
352 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aAutoIncrementLabel ) );
353 _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aAutoRetrievingLabel ) );
356 // -----------------------------------------------------------------------
357 void GeneratedValuesPage::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
359 _rControlList.push_back( new OSaveValueWrapper< CheckBox >( &m_aAutoRetrievingEnabled ) );
360 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aAutoIncrement ) );
361 _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aAutoRetrieving ) );
364 // -----------------------------------------------------------------------
365 void GeneratedValuesPage::implInitControls( const SfxItemSet& _rSet, sal_Bool _bSaveValue )
367 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
368 sal_Bool bValid, bReadonly;
369 getFlags(_rSet, bValid, bReadonly);
371 // collect the items
372 SFX_ITEMSET_GET(_rSet, pAutoIncrementItem, SfxStringItem, DSID_AUTOINCREMENTVALUE, sal_True);
373 SFX_ITEMSET_GET(_rSet, pAutoRetrieveValueItem, SfxStringItem, DSID_AUTORETRIEVEVALUE, sal_True);
374 SFX_ITEMSET_GET(_rSet, pAutoRetrieveEnabledItem, SfxBoolItem, DSID_AUTORETRIEVEENABLED, sal_True);
376 // forward the values to the controls
377 if (bValid)
379 sal_Bool bEnabled = pAutoRetrieveEnabledItem->GetValue();
380 m_aAutoRetrievingEnabled.Check( bEnabled );
382 m_aAutoIncrement.SetText( pAutoIncrementItem->GetValue() );
383 m_aAutoIncrement.ClearModifyFlag();
384 m_aAutoRetrieving.SetText( pAutoRetrieveValueItem->GetValue() );
385 m_aAutoRetrieving.ClearModifyFlag();
387 OGenericAdministrationPage::implInitControls( _rSet, _bSaveValue );
390 // -----------------------------------------------------------------------
391 sal_Bool GeneratedValuesPage::FillItemSet(SfxItemSet& _rSet)
393 sal_Bool bChangedSomething = sal_False;
395 fillString( _rSet, &m_aAutoIncrement, DSID_AUTOINCREMENTVALUE, bChangedSomething );
396 fillBool( _rSet, &m_aAutoRetrievingEnabled, DSID_AUTORETRIEVEENABLED, bChangedSomething );
397 fillString( _rSet, &m_aAutoRetrieving, DSID_AUTORETRIEVEVALUE, bChangedSomething );
399 return bChangedSomething;
402 //========================================================================
403 //= AdvancedSettingsDialog
404 //========================================================================
405 //------------------------------------------------------------------------
406 AdvancedSettingsDialog::AdvancedSettingsDialog( Window* _pParent, SfxItemSet* _pItems,
407 const Reference< XMultiServiceFactory >& _rxORB, const Any& _aDataSourceName )
408 :SfxTabDialog(_pParent, ModuleRes(DLG_DATABASE_ADVANCED), _pItems)
409 ,m_pItemSet(_pItems)
411 m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,_pParent,this));
412 m_pImpl->setDataSourceOrName(_aDataSourceName);
413 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
414 m_pImpl->translateProperties(xDatasource, *_pItems);
415 SetInputSet(_pItems);
416 // propagate this set as our new input set and reset the example set
417 delete pExampleSet;
418 pExampleSet = new SfxItemSet(*GetInputSetImpl());
420 const ::rtl::OUString eType = m_pImpl->getDatasourceType(*_pItems);
422 DataSourceMetaData aMeta( eType );
423 const AdvancedSettingsSupport& rAdvancedSupport( aMeta.getAdvancedSettingsSupport() );
425 // auto-generated values?
426 if ( rAdvancedSupport.bGeneratedValues )
427 AddTabPage( PAGE_GENERATED_VALUES, String( ModuleRes( STR_GENERATED_VALUE ) ), ODriversSettings::CreateGeneratedValuesPage, NULL );
429 // any "special settings"?
430 if ( rAdvancedSupport.supportsAnySpecialSetting() )
431 AddTabPage( PAGE_ADVANCED_SETTINGS_SPECIAL, String( ModuleRes( STR_DS_BEHAVIOUR ) ), ODriversSettings::CreateSpecialSettingsPage, NULL );
433 // remove the reset button - it's meaning is much too ambiguous in this dialog
434 RemoveResetButton();
435 FreeResource();
438 // -----------------------------------------------------------------------
439 AdvancedSettingsDialog::~AdvancedSettingsDialog()
441 SetInputSet(NULL);
442 DELETEZ(pExampleSet);
445 // -----------------------------------------------------------------------
446 bool AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( const ::rtl::OUString& _sURL )
448 DataSourceMetaData aMeta( _sURL );
449 const AdvancedSettingsSupport& rSupport( aMeta.getAdvancedSettingsSupport() );
450 if ( rSupport.bGeneratedValues || rSupport.supportsAnySpecialSetting() )
451 return true;
452 return false;
455 // -----------------------------------------------------------------------
456 short AdvancedSettingsDialog::Execute()
458 short nRet = SfxTabDialog::Execute();
459 if ( nRet == RET_OK )
461 pExampleSet->Put(*GetOutputItemSet());
462 m_pImpl->saveChanges(*pExampleSet);
464 return nRet;
467 //-------------------------------------------------------------------------
468 void AdvancedSettingsDialog::PageCreated(USHORT _nId, SfxTabPage& _rPage)
470 // register ourself as modified listener
471 static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory(m_pImpl->getORB());
472 static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
474 AdjustLayout();
475 Window *pWin = GetViewWindow();
476 if(pWin)
477 pWin->Invalidate();
479 SfxTabDialog::PageCreated(_nId, _rPage);
482 // -----------------------------------------------------------------------------
483 const SfxItemSet* AdvancedSettingsDialog::getOutputSet() const
485 return pExampleSet;
488 // -----------------------------------------------------------------------------
489 SfxItemSet* AdvancedSettingsDialog::getWriteOutputSet()
491 return pExampleSet;
494 // -----------------------------------------------------------------------------
495 ::std::pair< Reference< XConnection >, sal_Bool > AdvancedSettingsDialog::createConnection()
497 return m_pImpl->createConnection();
500 // -----------------------------------------------------------------------------
501 Reference< XMultiServiceFactory > AdvancedSettingsDialog::getORB() const
503 return m_pImpl->getORB();
506 // -----------------------------------------------------------------------------
507 Reference< XDriver > AdvancedSettingsDialog::getDriver()
509 return m_pImpl->getDriver();
512 // -----------------------------------------------------------------------------
513 ::rtl::OUString AdvancedSettingsDialog::getDatasourceType(const SfxItemSet& _rSet) const
515 return m_pImpl->getDatasourceType(_rSet);
518 // -----------------------------------------------------------------------------
519 void AdvancedSettingsDialog::clearPassword()
521 m_pImpl->clearPassword();
524 // -----------------------------------------------------------------------------
525 void AdvancedSettingsDialog::setTitle(const ::rtl::OUString& _sTitle)
527 SetText(_sTitle);
530 //-------------------------------------------------------------------------
531 void AdvancedSettingsDialog::enableConfirmSettings( bool _bEnable )
533 (void)_bEnable;
536 //-------------------------------------------------------------------------
537 sal_Bool AdvancedSettingsDialog::saveDatasource()
539 return PrepareLeaveCurrentPage();
542 //........................................................................
543 } // namespace dbaui
544 //........................................................................