diff options
Diffstat (limited to 'extensions/source/dbpilots')
30 files changed, 6167 insertions, 0 deletions
diff --git a/extensions/source/dbpilots/commonpagesdbp.cxx b/extensions/source/dbpilots/commonpagesdbp.cxx new file mode 100644 index 000000000000..88d8e2eb352e --- /dev/null +++ b/extensions/source/dbpilots/commonpagesdbp.cxx @@ -0,0 +1,509 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "commonpagesdbp.hxx" +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#include "dbpresid.hrc" +#endif +#include "componentmodule.hxx" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sdb/XCompletedConnection.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/sdb/XQueriesSupplier.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> +#include <com/sun/star/sdb/SQLContext.hpp> +#include <com/sun/star/sdbc/SQLWarning.hpp> +#include <com/sun/star/sdb/CommandType.hpp> +#include <tools/debug.hxx> +#include <svtools/localresaccess.hxx> +#include <comphelper/interaction.hxx> +#include <connectivity/dbtools.hxx> +#include <vcl/stdtext.hxx> +#include <vcl/waitobj.hxx> +#include <sfx2/docfilt.hxx> +#include <unotools/pathoptions.hxx> +#include <sfx2/filedlghelper.hxx> +#ifndef SVTOOLS_FILENOTATION_HXX_ +#include <svl/filenotation.hxx> +#endif +//......................................................................... +namespace dbp +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::sdb; + using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::task; + using namespace ::comphelper; + + //===================================================================== + //= OTableSelectionPage + //===================================================================== + //--------------------------------------------------------------------- + OTableSelectionPage::OTableSelectionPage(OControlWizard* _pParent) + :OControlWizardPage(_pParent, ModuleRes(RID_PAGE_TABLESELECTION)) + ,m_aData (this, ModuleRes(FL_DATA)) + ,m_aExplanation (this, ModuleRes(FT_EXPLANATION)) + ,m_aDatasourceLabel (this, ModuleRes(FT_DATASOURCE)) + ,m_aDatasource (this, ModuleRes(LB_DATASOURCE)) + ,m_aSearchDatabase (this, ModuleRes(PB_FORMDATASOURCE)) + ,m_aTableLabel (this, ModuleRes(FT_TABLE)) + ,m_aTable (this, ModuleRes(LB_TABLE)) + { + FreeResource(); + + implCollectDatasource(); + + m_aDatasource.SetSelectHdl(LINK(this, OTableSelectionPage, OnListboxSelection)); + m_aTable.SetSelectHdl(LINK(this, OTableSelectionPage, OnListboxSelection)); + m_aTable.SetDoubleClickHdl(LINK(this, OTableSelectionPage, OnListboxDoubleClicked)); + m_aSearchDatabase.SetClickHdl(LINK(this, OTableSelectionPage, OnSearchClicked)); + + m_aDatasource.SetDropDownLineCount(10); + } + + //--------------------------------------------------------------------- + void OTableSelectionPage::ActivatePage() + { + OControlWizardPage::ActivatePage(); + m_aDatasource.GrabFocus(); + } + + //--------------------------------------------------------------------- + bool OTableSelectionPage::canAdvance() const + { + if (!OControlWizardPage::canAdvance()) + return false; + + if (0 == m_aDatasource.GetSelectEntryCount()) + return false; + + if (0 == m_aTable.GetSelectEntryCount()) + return false; + + return sal_True; + } + + //--------------------------------------------------------------------- + void OTableSelectionPage::initializePage() + { + OControlWizardPage::initializePage(); + + const OControlWizardContext& rContext = getContext(); + try + { + ::rtl::OUString sDataSourceName; + rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSourceName; + + Reference< XConnection > xConnection; + bool bEmbedded = ::dbtools::isEmbeddedInDatabase( rContext.xForm, xConnection ); + if ( bEmbedded ) + { + m_aDatasource.Hide(); + m_aDatasourceLabel.Hide(); + m_aSearchDatabase.Hide(); + m_aTableLabel.SetPosPixel(m_aDatasourceLabel.GetPosPixel()); + m_aTable.SetPosPixel(m_aDatasource.GetPosPixel()); + m_aDatasource.InsertEntry(sDataSourceName); + } + m_aDatasource.SelectEntry(sDataSourceName); + + implFillTables(xConnection); + + ::rtl::OUString sCommand; + OSL_VERIFY( rContext.xForm->getPropertyValue( ::rtl::OUString::createFromAscii("Command") ) >>= sCommand ); + sal_Int32 nCommandType = CommandType::TABLE; + OSL_VERIFY( rContext.xForm->getPropertyValue( ::rtl::OUString::createFromAscii("CommandType") ) >>= nCommandType ); + + // search the entry of the given type with the given name + XubString sLookup( sCommand ); + for ( USHORT nLookup = 0; nLookup < m_aTable.GetEntryCount(); ++nLookup ) + { + if ( m_aTable.GetEntry( nLookup ) == sLookup ) + if ( reinterpret_cast< sal_IntPtr >( m_aTable.GetEntryData( nLookup ) ) == nCommandType ) + { + m_aTable.SelectEntryPos( nLookup ); + break; + } + } + } + catch(Exception&) + { + DBG_ERROR("OTableSelectionPage::initializePage: caught an exception!"); + } + } + + //--------------------------------------------------------------------- + sal_Bool OTableSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OControlWizardPage::commitPage(_eReason)) + return sal_False; + + const OControlWizardContext& rContext = getContext(); + try + { + Reference< XConnection > xOldConn; + if ( !rContext.bEmbedded ) + { + xOldConn = getFormConnection(); + + ::rtl::OUString sDataSource = m_aDatasource.GetSelectEntry(); + rContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("DataSourceName"), makeAny( sDataSource ) ); + } + ::rtl::OUString sCommand = m_aTable.GetSelectEntry(); + sal_Int32 nCommandType = reinterpret_cast< sal_IntPtr >( m_aTable.GetEntryData( m_aTable.GetSelectEntryPos() ) ); + + rContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("Command"), makeAny( sCommand ) ); + rContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("CommandType"), makeAny( nCommandType ) ); + + if ( !rContext.bEmbedded ) + setFormConnection( xOldConn, sal_False ); + + if (!updateContext()) + return sal_False; + } + catch(Exception&) + { + DBG_ERROR("OTableSelectionPage::commitPage: caught an exception!"); + } + + return sal_True; + } + + //--------------------------------------------------------------------- + IMPL_LINK( OTableSelectionPage, OnSearchClicked, PushButton*, /*_pButton*/ ) + { + ::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK); + aFileDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() ); + + static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)"); + const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType); + OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!"); + if ( pFilter ) + { + aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension()); + } + + if (0 == aFileDlg.Execute()) + { + String sDataSourceName = aFileDlg.GetPath(); + ::svt::OFileNotation aFileNotation(sDataSourceName); + sDataSourceName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM); + m_aDatasource.InsertEntry(sDataSourceName); + m_aDatasource.SelectEntry(sDataSourceName); + LINK(this, OTableSelectionPage, OnListboxSelection).Call(&m_aDatasource); + } + return 0L; + } + //--------------------------------------------------------------------- + IMPL_LINK( OTableSelectionPage, OnListboxDoubleClicked, ListBox*, _pBox ) + { + if (_pBox->GetSelectEntryCount()) + getDialog()->travelNext(); + return 0L; + } + + //--------------------------------------------------------------------- + IMPL_LINK( OTableSelectionPage, OnListboxSelection, ListBox*, _pBox ) + { + if (&m_aDatasource == _pBox) + { // new data source selected + implFillTables(); + } + else + { + } + + updateDialogTravelUI(); + + return 0L; + } + + //--------------------------------------------------------------------- + namespace + { + void lcl_fillEntries( ListBox& _rListBox, const Sequence< ::rtl::OUString >& _rNames, const Image& _rImage, sal_Int32 _nCommandType ) + { + const ::rtl::OUString* pNames = _rNames.getConstArray(); + const ::rtl::OUString* pNamesEnd = _rNames.getConstArray() + _rNames.getLength(); + sal_uInt16 nPos = 0; + while ( pNames != pNamesEnd ) + { + nPos = _rListBox.InsertEntry( *pNames++, _rImage ); + _rListBox.SetEntryData( nPos, reinterpret_cast< void* >( _nCommandType ) ); + } + } + } + + //--------------------------------------------------------------------- + void OTableSelectionPage::implFillTables(const Reference< XConnection >& _rxConn) + { + m_aTable.Clear(); + + WaitObject aWaitCursor(this); + + // will be the table tables of the selected data source + Sequence< ::rtl::OUString > aTableNames; + Sequence< ::rtl::OUString > aQueryNames; + + // connect to the data source + Any aSQLException; + Reference< XConnection > xConn = _rxConn; + if ( !xConn.is() ) + { + if (!m_xDSContext.is()) + return; + // connect to the data source + try + { + ::rtl::OUString sCurrentDatasource = m_aDatasource.GetSelectEntry(); + if (sCurrentDatasource.getLength()) + { + // obtain the DS object + Reference< XCompletedConnection > xDatasource; + // check if I know this one otherwise transform it into a file URL + if ( !m_xDSContext->hasByName(sCurrentDatasource) ) + { + ::svt::OFileNotation aFileNotation(sCurrentDatasource); + sCurrentDatasource = aFileNotation.get(::svt::OFileNotation::N_URL); + } + + if (m_xDSContext->getByName(sCurrentDatasource) >>= xDatasource) + { // connect + // get the default SDB interaction handler + Reference< XInteractionHandler > xHandler = getDialog()->getInteractionHandler(this); + if (!xHandler.is() ) + return; + xConn = xDatasource->connectWithCompletion(xHandler); + setFormConnection( xConn ); + } + else + { + DBG_ERROR("OTableSelectionPage::implFillTables: invalid data source object returned by the context"); + } + } + } + catch(SQLContext& e) { aSQLException <<= e; } + catch(SQLWarning& e) { aSQLException <<= e; } + catch(SQLException& e) { aSQLException <<= e; } + catch (Exception&) + { + DBG_ERROR("OTableSelectionPage::implFillTables: could not fill the table list!"); + } + } + + // will be the table tables of the selected data source + if ( xConn.is() ) + { + try + { + // get the tables + Reference< XTablesSupplier > xSupplTables(xConn, UNO_QUERY); + if ( xSupplTables.is() ) + { + Reference< XNameAccess > xTables(xSupplTables->getTables(), UNO_QUERY); + if (xTables.is()) + aTableNames = xTables->getElementNames(); + } + + // and the queries + Reference< XQueriesSupplier > xSuppQueries( xConn, UNO_QUERY ); + if ( xSuppQueries.is() ) + { + Reference< XNameAccess > xQueries( xSuppQueries->getQueries(), UNO_QUERY ); + if ( xQueries.is() ) + aQueryNames = xQueries->getElementNames(); + } + } + catch(SQLContext& e) { aSQLException <<= e; } + catch(SQLWarning& e) { aSQLException <<= e; } + catch(SQLException& e) { aSQLException <<= e; } + catch (Exception&) + { + DBG_ERROR("OTableSelectionPage::implFillTables: could not fill the table list!"); + } + } + + + if ( aSQLException.hasValue() ) + { // an SQLException (or derivee) was thrown ... + Reference< XInteractionRequest > xRequest = new OInteractionRequest(aSQLException); + try + { + // get the default SDB interaction handler + Reference< XInteractionHandler > xHandler = getDialog()->getInteractionHandler(this); + if ( xHandler.is() ) + xHandler->handle(xRequest); + } + catch(Exception&) { } + return; + } + + Image aTableImage, aQueryImage; + { + ::svt::OLocalResourceAccess aLocalResAccess( ModuleRes( RID_PAGE_TABLESELECTION ), RSC_TABPAGE ); + + bool bIsHiContrast = m_aTable.GetSettings().GetStyleSettings().GetHighContrastMode(); + aTableImage = Image( ModuleRes( bIsHiContrast ? IMG_TABLE_HC : IMG_TABLE ) ); + aQueryImage = Image( ModuleRes( bIsHiContrast ? IMG_QUERY_HC : IMG_QUERY ) ); + } + lcl_fillEntries( m_aTable, aTableNames, aTableImage, CommandType::TABLE ); + lcl_fillEntries( m_aTable, aQueryNames, aQueryImage, CommandType::QUERY ); + } + + //--------------------------------------------------------------------- + void OTableSelectionPage::implCollectDatasource() + { + try + { + m_xDSContext = getContext().xDatasourceContext; + if (m_xDSContext.is()) + fillListBox(m_aDatasource, m_xDSContext->getElementNames()); + } + catch (Exception&) + { + DBG_ERROR("OTableSelectionPage::implCollectDatasource: could not collect the data source names!"); + } + } + + //===================================================================== + //= OMaybeListSelectionPage + //===================================================================== + //--------------------------------------------------------------------- + OMaybeListSelectionPage::OMaybeListSelectionPage( OControlWizard* _pParent, const ResId& _rId ) + :OControlWizardPage(_pParent, _rId) + ,m_pYes(NULL) + ,m_pNo(NULL) + ,m_pList(NULL) + { + } + + //--------------------------------------------------------------------- + void OMaybeListSelectionPage::announceControls(RadioButton& _rYesButton, RadioButton& _rNoButton, ListBox& _rSelection) + { + m_pYes = &_rYesButton; + m_pNo = &_rNoButton; + m_pList = &_rSelection; + + m_pYes->SetClickHdl(LINK(this, OMaybeListSelectionPage, OnRadioSelected)); + m_pNo->SetClickHdl(LINK(this, OMaybeListSelectionPage, OnRadioSelected)); + implEnableWindows(); + } + + //--------------------------------------------------------------------- + IMPL_LINK( OMaybeListSelectionPage, OnRadioSelected, RadioButton*, /*NOTINTERESTEDIN*/ ) + { + implEnableWindows(); + return 0L; + } + + //--------------------------------------------------------------------- + void OMaybeListSelectionPage::implInitialize(const String& _rSelection) + { + DBG_ASSERT(m_pYes, "OMaybeListSelectionPage::implInitialize: no controls announced!"); + sal_Bool bIsSelection = (0 != _rSelection.Len()); + m_pYes->Check(bIsSelection); + m_pNo->Check(!bIsSelection); + m_pList->Enable(bIsSelection); + + m_pList->SelectEntry(bIsSelection ? _rSelection : String()); + } + + //--------------------------------------------------------------------- + void OMaybeListSelectionPage::implCommit(String& _rSelection) + { + _rSelection = m_pYes->IsChecked() ? m_pList->GetSelectEntry() : String(); + } + + //--------------------------------------------------------------------- + void OMaybeListSelectionPage::implEnableWindows() + { + m_pList->Enable(m_pYes->IsChecked()); + } + + //--------------------------------------------------------------------- + void OMaybeListSelectionPage::ActivatePage() + { + OControlWizardPage::ActivatePage(); + + DBG_ASSERT(m_pYes, "OMaybeListSelectionPage::ActivatePage: no controls announced!"); + if (m_pYes->IsChecked()) + m_pList->GrabFocus(); + else + m_pNo->GrabFocus(); + } + + //===================================================================== + //= ODBFieldPage + //===================================================================== + //--------------------------------------------------------------------- + ODBFieldPage::ODBFieldPage( OControlWizard* _pParent ) + :OMaybeListSelectionPage(_pParent, ModuleRes(RID_PAGE_OPTION_DBFIELD)) + ,m_aFrame (this, ModuleRes(FL_DATABASEFIELD_EXPL)) + ,m_aDescription (this, ModuleRes(FT_DATABASEFIELD_EXPL)) + ,m_aQuestion (this, ModuleRes(FT_DATABASEFIELD_QUEST)) + ,m_aStoreYes (this, ModuleRes(RB_STOREINFIELD_YES)) + ,m_aStoreNo (this, ModuleRes(LB_STOREINFIELD)) + ,m_aStoreWhere (this, ModuleRes(RB_STOREINFIELD_NO)) + { + FreeResource(); + announceControls(m_aStoreYes, m_aStoreNo, m_aStoreWhere); + m_aStoreWhere.SetDropDownLineCount(10); + } + + //--------------------------------------------------------------------- + void ODBFieldPage::initializePage() + { + OMaybeListSelectionPage::initializePage(); + + // fill the fields page + fillListBox(m_aStoreWhere, getContext().aFieldNames); + + implInitialize(getDBFieldSetting()); + } + + //--------------------------------------------------------------------- + sal_Bool ODBFieldPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OMaybeListSelectionPage::commitPage(_eReason)) + return sal_False; + + implCommit(getDBFieldSetting()); + + return sal_True; + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/commonpagesdbp.hxx b/extensions/source/dbpilots/commonpagesdbp.hxx new file mode 100644 index 000000000000..a20587b36d72 --- /dev/null +++ b/extensions/source/dbpilots/commonpagesdbp.hxx @@ -0,0 +1,146 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_COMMONPAGESDBP_HXX_ +#define _EXTENSIONS_DBP_COMMONPAGESDBP_HXX_ + +#include "controlwizard.hxx" +#include <vcl/fixed.hxx> +#include <vcl/lstbox.hxx> +#include <com/sun/star/container/XNameAccess.hpp> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + //===================================================================== + //= OTableSelectionPage + //===================================================================== + class OTableSelectionPage : public OControlWizardPage + { + protected: + FixedLine m_aData; + FixedText m_aExplanation; + FixedText m_aDatasourceLabel; + ListBox m_aDatasource; + PushButton m_aSearchDatabase; + FixedText m_aTableLabel; + ListBox m_aTable; + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + m_xDSContext; + + public: + OTableSelectionPage(OControlWizard* _pParent); + + protected: + // TabPage overridables + void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + + protected: + DECL_LINK( OnListboxSelection, ListBox* ); + DECL_LINK( OnListboxDoubleClicked, ListBox* ); + DECL_LINK( OnSearchClicked, PushButton* ); + + void implCollectDatasource(); + void implFillTables(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& + _rxConn = ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >()); + + // OControlWizardPage overridables + virtual bool canAdvance() const; + }; + + //===================================================================== + //= OMaybeListSelectionPage + //===================================================================== + class OMaybeListSelectionPage : public OControlWizardPage + { + protected: + RadioButton* m_pYes; + RadioButton* m_pNo; + ListBox* m_pList; + + public: + OMaybeListSelectionPage( OControlWizard* _pParent, const ResId& _rId ); + + protected: + DECL_LINK( OnRadioSelected, RadioButton* ); + + // TabPage overridables + void ActivatePage(); + + // own helper + void announceControls( + RadioButton& _rYesButton, + RadioButton& _rNoButton, + ListBox& _rSelection); + + void implEnableWindows(); + + void implInitialize(const String& _rSelection); + void implCommit(String& _rSelection); + }; + + //===================================================================== + //= ODBFieldPage + //===================================================================== + class ODBFieldPage : public OMaybeListSelectionPage + { + protected: + FixedLine m_aFrame; + FixedText m_aDescription; + FixedText m_aQuestion; + RadioButton m_aStoreYes; + RadioButton m_aStoreNo; + ListBox m_aStoreWhere; + + public: + ODBFieldPage( OControlWizard* _pParent ); + + protected: + void setDescriptionText(const String& _rDesc) { m_aDescription.SetText(_rDesc); } + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + + // own overridables + virtual String& getDBFieldSetting() = 0; + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + + +#endif // _EXTENSIONS_DBP_COMMONPAGESDBP_HXX_ + diff --git a/extensions/source/dbpilots/commonpagesdbp.src b/extensions/source/dbpilots/commonpagesdbp.src new file mode 100644 index 000000000000..41d199a70209 --- /dev/null +++ b/extensions/source/dbpilots/commonpagesdbp.src @@ -0,0 +1,230 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#include "dbpresid.hrc" +#endif + +TabPage RID_PAGE_TABLESELECTION +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + Text [ en-US ] = "Data"; + + FixedLine FL_DATA + { + Pos = MAP_APPFONT ( 4 , 3 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + Text [ en-US ] = "Data"; + }; + FixedText FT_EXPLANATION + { + Pos = MAP_APPFONT ( 7 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10 , WINDOW_SIZE_Y - 21 ) ; + WordBreak = TRUE; + Group = TRUE; + Text [ en-US ] = "Currently, the form the control belongs to is not (or not completely) bound to a data source.\n\nPlease choose a data source and a table.\n\n\nPlease note that the settings made on this page will take effect immediately upon leaving the page."; + }; + FixedText FT_DATASOURCE + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10 , 8) ; + Group = TRUE; + Text [ en-US ] = "~Data source:"; + }; + ListBox LB_DATASOURCE + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 26 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 27 , 14 ) ; + SVLook = TRUE ; + Border = TRUE ; + DropDown = TRUE ; + AutoHScroll = TRUE ; + }; + + PushButton PB_FORMDATASOURCE + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 + WINDOW_HALF_SIZE_X - 24 , 25 ) ; + Size = MAP_APPFONT ( 14 , 14 ) ; + Text [ en-US ] = "~..."; + }; + + FixedText FT_TABLE + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3, 46 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 14 , 8) ; + Group = TRUE; + Text [ en-US ] = "~Table / Query:"; + }; + ListBox LB_TABLE + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3, 57 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10 , WINDOW_SIZE_Y - 6 - 57 ) ; + SVLook = TRUE ; + Border = TRUE ; + Sort = TRUE; + AutoHScroll = TRUE ; + }; + + Image IMG_TABLE + { + ImageBitmap = Bitmap { File = "sx03188.bmp"; }; + MaskColor = Color { Red = 0xFFFF; Green = 0x0; Blue = 0xFFFF; }; + }; + + Image IMG_TABLE_HC + { + ImageBitmap = Bitmap { File = "sxh03188.bmp"; }; + MaskColor = Color { Red = 0xFFFF; Green = 0x0; Blue = 0xFFFF; }; + }; + + Image IMG_QUERY + { + ImageBitmap = Bitmap { File = "sx03202.bmp"; }; + MaskColor = Color { Red = 0xFFFF; Green = 0x0; Blue = 0xFFFF; }; + }; + + Image IMG_QUERY_HC + { + ImageBitmap = Bitmap { File = "sxh03202.bmp"; }; + MaskColor = Color { Red = 0xFFFF; Green = 0x0; Blue = 0xFFFF; }; + }; + +}; + +TabPage RID_PAGE_OPTION_DBFIELD +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + Text [ en-US ] = "Database Field"; + + FixedLine FL_DATABASEFIELD_EXPL + { + Pos = MAP_APPFONT ( 4 , 3 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + }; + FixedText FT_DATABASEFIELD_EXPL + { + Pos = MAP_APPFONT ( 7 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 16 ) ; + WordBreak = TRUE; + }; + FixedText FT_DATABASEFIELD_QUEST + { + Pos = MAP_APPFONT ( 7 , 34 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 16 ) ; + WordBreak = TRUE; + Text [ en-US ] = "Do you want to save the value in a database field?"; + }; + RadioButton RB_STOREINFIELD_YES + { + Pos = MAP_APPFONT ( 7 , 53 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 20, 10 ) ; + Group = TRUE; + TabStop = TRUE; + Text [ en-US ] = "~Yes, I want to save it in the following database field:"; + }; + ListBox LB_STOREINFIELD + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 23, 51 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 30, 14 ) ; + TabStop = TRUE; + SVLook = TRUE ; + Border = TRUE ; + DropDown = TRUE; + AutoHScroll = TRUE ; + }; + RadioButton RB_STOREINFIELD_NO + { + Pos = MAP_APPFONT ( 7 , 68 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 10 ) ; + TabStop = FALSE; + Text [ en-US ] = "~No, I only want to save the value in the form."; + }; +}; + +TabPage RID_PAGE_FORM_DATASOURCE_STATUS +{ + FixedLine FL_FORMSETINGS + { + Pos = MAP_APPFONT ( 4 , 3 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + Text [ en-US ] = "Form"; + }; + FixedText FT_FORMDATASOURCELABEL + { + Pos = MAP_APPFONT ( 7 , 15 ) ; + Size = MAP_APPFONT ( 60 , 8 ) ; + Text [ en-US ] = "Data source"; + }; + FixedText FT_FORMDATASOURCE + { + Pos = MAP_APPFONT ( 7 + 60 + 3 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X / 2 - 80 - 3 , 19 ) ; + WordBreak = TRUE; + }; + + FixedText FT_FORMCONTENTTYPELABEL + { + Pos = MAP_APPFONT ( WINDOW_SIZE_X / 2 + 3, 15 ) ; + Size = MAP_APPFONT ( 60 , 8 ) ; + Text [ en-US ] = "Content type"; + }; + FixedText FT_FORMCONTENTTYPE + { + Pos = MAP_APPFONT ( WINDOW_SIZE_X / 2 + 3 + 60 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - ( WINDOW_SIZE_X / 2 + 3 + 60 ) - 7 , 8 ) ; + }; + + FixedText FT_FORMTABLELABEL + { + Pos = MAP_APPFONT ( WINDOW_SIZE_X / 2 + 3, 26 ) ; + Size = MAP_APPFONT ( 60 , 8 ) ; + Text [ en-US ] = "Content"; + }; + FixedText FT_FORMTABLE + { + Pos = MAP_APPFONT ( WINDOW_SIZE_X / 2 + 3 + 60 , 26 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - ( WINDOW_SIZE_X / 2 + 3 + 60 ) - 7 , 8 ) ; + }; +}; + +String RID_STR_TYPE_TABLE +{ + Text [ en-US ] = "Table"; +}; + +String RID_STR_TYPE_QUERY +{ + Text [ en-US ] = "Query"; +}; + +String RID_STR_TYPE_COMMAND +{ + Text [ en-US ] = "SQL command"; +}; + diff --git a/extensions/source/dbpilots/controlwizard.cxx b/extensions/source/dbpilots/controlwizard.cxx new file mode 100644 index 000000000000..c5d816486ecc --- /dev/null +++ b/extensions/source/dbpilots/controlwizard.cxx @@ -0,0 +1,777 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "controlwizard.hxx" +#include <tools/debug.hxx> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/sdb/XQueriesSupplier.hpp> +#include <com/sun/star/sdbc/XPreparedStatement.hpp> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/drawing/XDrawView.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/sdb/CommandType.hpp> +#include <com/sun/star/sdbc/SQLWarning.hpp> +#include <com/sun/star/sdb/SQLContext.hpp> +#include <comphelper/types.hxx> +#include <connectivity/dbtools.hxx> +#include <vcl/msgbox.hxx> +#include <comphelper/interaction.hxx> +#include <vcl/stdtext.hxx> +#include <svtools/localresaccess.hxx> +#include <connectivity/conncleanup.hxx> +#include <com/sun/star/sdbc/DataType.hpp> +#include <tools/urlobj.hxx> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::sdb; + using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::drawing; + using namespace ::com::sun::star::frame; + using namespace ::com::sun::star::sheet; + using namespace ::com::sun::star::form; + using namespace ::com::sun::star::task; + using namespace ::svt; + using namespace ::comphelper; + using namespace ::dbtools; + + //===================================================================== + //= OAccessRegulator + //===================================================================== + struct OAccessRegulator + { + friend class OControlWizardPage; + + protected: + OAccessRegulator() { } + }; + + //===================================================================== + //= OControlWizardPage + //===================================================================== + //--------------------------------------------------------------------- + OControlWizardPage::OControlWizardPage( OControlWizard* _pParent, const ResId& _rResId ) + :OControlWizardPage_Base( _pParent, _rResId ) + ,m_pFormSettingsSeparator(NULL) + ,m_pFormDatasourceLabel(NULL) + ,m_pFormDatasource(NULL) + ,m_pFormContentTypeLabel(NULL) + ,m_pFormContentType(NULL) + ,m_pFormTableLabel(NULL) + ,m_pFormTable(NULL) + { + } + + //--------------------------------------------------------------------- + OControlWizardPage::~OControlWizardPage() + { + delete m_pFormSettingsSeparator; + delete m_pFormDatasourceLabel; + delete m_pFormDatasource; + delete m_pFormContentTypeLabel; + delete m_pFormContentType; + delete m_pFormTableLabel; + delete m_pFormTable; + } + + //--------------------------------------------------------------------- + OControlWizard* OControlWizardPage::getDialog() + { + return static_cast< OControlWizard* >(GetParent()); + } + + //--------------------------------------------------------------------- + const OControlWizard* OControlWizardPage::getDialog() const + { + return static_cast< OControlWizard* >(GetParent()); + } + + //--------------------------------------------------------------------- + sal_Bool OControlWizardPage::updateContext() + { + return getDialog()->updateContext(OAccessRegulator()); + } + + //--------------------------------------------------------------------- + Reference< XConnection > OControlWizardPage::getFormConnection() const + { + return getDialog()->getFormConnection(OAccessRegulator()); + } + + //--------------------------------------------------------------------- + void OControlWizardPage::setFormConnection( const Reference< XConnection >& _rxConn, sal_Bool _bAutoDispose ) + { + getDialog()->setFormConnection( OAccessRegulator(), _rxConn, _bAutoDispose ); + } + + //--------------------------------------------------------------------- + const OControlWizardContext& OControlWizardPage::getContext() + { + return getDialog()->getContext(); + } + + //--------------------------------------------------------------------- + void OControlWizardPage::fillListBox(ListBox& _rList, const Sequence< ::rtl::OUString >& _rItems, sal_Bool _bClear) + { + if (_bClear) + _rList.Clear(); + const ::rtl::OUString* pItems = _rItems.getConstArray(); + const ::rtl::OUString* pEnd = pItems + _rItems.getLength(); + ::svt::WizardTypes::WizardState nPos; + sal_Int32 nIndex = 0; + for (;pItems < pEnd; ++pItems, ++nIndex) + { + nPos = _rList.InsertEntry(*pItems); + _rList.SetEntryData(nPos, reinterpret_cast<void*>(nIndex)); + } + } + + //--------------------------------------------------------------------- + void OControlWizardPage::fillListBox(ComboBox& _rList, const Sequence< ::rtl::OUString >& _rItems, sal_Bool _bClear) + { + if (_bClear) + _rList.Clear(); + const ::rtl::OUString* pItems = _rItems.getConstArray(); + const ::rtl::OUString* pEnd = pItems + _rItems.getLength(); + ::svt::WizardTypes::WizardState nPos; + sal_Int32 nIndex = 0; + for (;pItems < pEnd; ++pItems) + { + nPos = _rList.InsertEntry(*pItems); + _rList.SetEntryData(nPos, reinterpret_cast<void*>(nIndex)); + } + } + + //--------------------------------------------------------------------- + void OControlWizardPage::enableFormDatasourceDisplay() + { + if (m_pFormSettingsSeparator) + // nothing to do + return; + + ModuleRes aModuleRes(RID_PAGE_FORM_DATASOURCE_STATUS); + OLocalResourceAccess aLocalControls(aModuleRes, RSC_TABPAGE); + + m_pFormSettingsSeparator = new FixedLine(this, ModuleRes(FL_FORMSETINGS)); + m_pFormDatasourceLabel = new FixedText(this, ModuleRes(FT_FORMDATASOURCELABEL)); + m_pFormDatasource = new FixedText(this, ModuleRes(FT_FORMDATASOURCE)); + m_pFormContentTypeLabel = new FixedText(this, ModuleRes(FT_FORMCONTENTTYPELABEL)); + m_pFormContentType = new FixedText(this, ModuleRes(FT_FORMCONTENTTYPE)); + m_pFormTableLabel = new FixedText(this, ModuleRes(FT_FORMTABLELABEL)); + m_pFormTable = new FixedText(this, ModuleRes(FT_FORMTABLE)); + + const OControlWizardContext& rContext = getContext(); + if ( rContext.bEmbedded ) + { + m_pFormDatasourceLabel->Hide(); + m_pFormDatasource->Hide(); + m_pFormContentTypeLabel->SetPosPixel(m_pFormDatasourceLabel->GetPosPixel()); + m_pFormContentType->SetPosPixel(m_pFormDatasource->GetPosPixel()); + m_pFormTableLabel->SetPosPixel(::Point(m_pFormDatasourceLabel->GetPosPixel().X(),m_pFormTableLabel->GetPosPixel().Y())); + m_pFormTable->SetPosPixel(::Point(m_pFormDatasource->GetPosPixel().X(),m_pFormTable->GetPosPixel().Y())); + } + } + + //--------------------------------------------------------------------- + void OControlWizardPage::adjustControlForNoDSDisplay(Control* _pControl, sal_Bool _bConstLowerDistance) + { + ::Size aDistanceToMove = LogicToPixel( ::Size( 0, 37 ), MAP_APPFONT ); + + ::Point aPos = _pControl->GetPosPixel(); + aPos.Y() -= aDistanceToMove.Height(); + _pControl->SetPosPixel(aPos); + + if (_bConstLowerDistance) + { + ::Size aSize = _pControl->GetSizePixel(); + aSize.Height() += aDistanceToMove.Height(); + _pControl->SetSizePixel(aSize); + } + } + + //--------------------------------------------------------------------- + void OControlWizardPage::initializePage() + { + if (m_pFormDatasource && m_pFormContentTypeLabel && m_pFormTable) + { + const OControlWizardContext& rContext = getContext(); + ::rtl::OUString sDataSource; + ::rtl::OUString sCommand; + sal_Int32 nCommandType = CommandType::COMMAND; + try + { + rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSource; + rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("Command")) >>= sCommand; + rContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")) >>= nCommandType; + } + catch(const Exception&) + { + DBG_ERROR("OControlWizardPage::initializePage: caught an exception!"); + } + + INetURLObject aURL( sDataSource ); + if( aURL.GetProtocol() != INET_PROT_NOT_VALID ) + sDataSource = aURL.GetName(INetURLObject::DECODE_WITH_CHARSET); + m_pFormDatasource->SetText(sDataSource); + m_pFormTable->SetText(sCommand); + + ::svt::WizardTypes::WizardState nCommandTypeResourceId = 0; + switch (nCommandType) + { + case CommandType::TABLE: + nCommandTypeResourceId = RID_STR_TYPE_TABLE; + break; + + case CommandType::QUERY: + nCommandTypeResourceId = RID_STR_TYPE_QUERY; + break; + + default: + nCommandTypeResourceId = RID_STR_TYPE_COMMAND; + break; + } + m_pFormContentType->SetText(String(ModuleRes(nCommandTypeResourceId))); + } + + OControlWizardPage_Base::initializePage(); + } + + //===================================================================== + //= OControlWizard + //===================================================================== + //--------------------------------------------------------------------- + OControlWizard::OControlWizard( Window* _pParent, const ResId& _rId, + const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB ) + :OWizardMachine(_pParent, _rId, WZB_CANCEL | WZB_PREVIOUS | WZB_NEXT | WZB_FINISH) + ,m_xORB(_rxORB) + { + m_aContext.xObjectModel = _rxObjectModel; + initContext(); + + SetPageSizePixel(LogicToPixel(::Size(WINDOW_SIZE_X, WINDOW_SIZE_Y), MAP_APPFONT)); + ShowButtonFixedLine(sal_True); + defaultButton(WZB_NEXT); + enableButtons(WZB_FINISH, sal_False); + } + + //--------------------------------------------------------------------- + OControlWizard::~OControlWizard() + { + } + + //--------------------------------------------------------------------- + short OControlWizard::Execute() + { + // get the class id of the control we're dealing with + sal_Int16 nClassId = FormComponentType::CONTROL; + try + { + getContext().xObjectModel->getPropertyValue(::rtl::OUString::createFromAscii("ClassId")) >>= nClassId; + } + catch(Exception&) + { + DBG_ERROR("OControlWizard::activate: could not obtain the class id!"); + } + if (!approveControl(nClassId)) + { + // TODO: MessageBox or exception + return RET_CANCEL; + } + + ActivatePage(); + + return OControlWizard_Base::Execute(); + } + + //--------------------------------------------------------------------- + void OControlWizard::ActivatePage() + { + OControlWizard_Base::ActivatePage(); + } + + //--------------------------------------------------------------------- + void OControlWizard::implDetermineShape() + { + Reference< XIndexAccess > xPageObjects(m_aContext.xDrawPage, UNO_QUERY); + DBG_ASSERT(xPageObjects.is(), "OControlWizard::implDetermineShape: invalid page!"); + + // for comparing the model + Reference< XControlModel > xModelCompare(m_aContext.xObjectModel, UNO_QUERY); + + if (xPageObjects.is()) + { + // loop through all objects of the page + sal_Int32 nObjects = xPageObjects->getCount(); + Reference< XControlShape > xControlShape; + Reference< XControlModel > xControlModel; + for (sal_Int32 i=0; i<nObjects; ++i) + { + if (xPageObjects->getByIndex(i) >>= xControlShape) + { // it _is_ a control shape + xControlModel = xControlShape->getControl(); + DBG_ASSERT(xControlModel.is(), "OControlWizard::implDetermineShape: control shape without model!"); + if (xModelCompare.get() == xControlModel.get()) + { + m_aContext.xObjectShape = xControlShape; + break; + } + } + } + } + } + + //--------------------------------------------------------------------- + void OControlWizard::implDetermineForm() + { + Reference< XChild > xModelAsChild(m_aContext.xObjectModel, UNO_QUERY); + Reference< XInterface > xControlParent; + if (xModelAsChild.is()) + xControlParent = xModelAsChild->getParent(); + + m_aContext.xForm = Reference< XPropertySet >(xControlParent, UNO_QUERY); + m_aContext.xRowSet = Reference< XRowSet >(xControlParent, UNO_QUERY); + DBG_ASSERT(m_aContext.xForm.is() && m_aContext.xRowSet.is(), + "OControlWizard::implDetermineForm: missing some interfaces of the control parent!"); + + } + + //--------------------------------------------------------------------- + void OControlWizard::implDeterminePage() + { + try + { + // get the document model + Reference< XChild > xControlAsChild(m_aContext.xObjectModel, UNO_QUERY); + Reference< XChild > xModelSearch(xControlAsChild->getParent(), UNO_QUERY); + + Reference< XModel > xModel(xModelSearch, UNO_QUERY); + while (xModelSearch.is() && !xModel.is()) + { + xModelSearch = Reference< XChild >(xModelSearch->getParent(), UNO_QUERY); + xModel = Reference< XModel >(xModelSearch, UNO_QUERY); + } + + Reference< XDrawPage > xPage; + if (xModel.is()) + { + m_aContext.xDocumentModel = xModel; + + Reference< XDrawPageSupplier > xPageSupp(xModel, UNO_QUERY); + if (xPageSupp.is()) + { // it's a document with only one page -> Writer + xPage = xPageSupp->getDrawPage(); + } + else + { + // get the controller currently working on this model + Reference< XController > xController = xModel->getCurrentController(); + DBG_ASSERT(xController.is(), "OControlWizard::implDeterminePage: no current controller!"); + + // maybe it's a spredsheet + Reference< XSpreadsheetView > xView(xController, UNO_QUERY); + if (xView.is()) + { // okay, it is one + Reference< XSpreadsheet > xSheet = xView->getActiveSheet(); + xPageSupp = Reference< XDrawPageSupplier >(xSheet, UNO_QUERY); + DBG_ASSERT(xPageSupp.is(), "OControlWizard::implDeterminePage: a spreadsheet which is no page supplier!"); + if (xPageSupp.is()) + xPage = xPageSupp->getDrawPage(); + } + else + { // can be a draw/impress doc only + Reference< XDrawView > xDrawView(xController, UNO_QUERY); + DBG_ASSERT(xDrawView.is(), "OControlWizard::implDeterminePage: no alternatives left ... can't determine the page!"); + if (xDrawView.is()) + xPage = xDrawView->getCurrentPage(); + } + } + } + else + { + DBG_ASSERT(xPage.is(), "OControlWizard::implDeterminePage: can't determine the page (no model)!"); + } + m_aContext.xDrawPage = xPage; + } + catch(Exception&) + { + DBG_ERROR("OControlWizard::implDeterminePage: caught an exception!"); + } + } + + //--------------------------------------------------------------------- + void OControlWizard::implGetDSContext() + { + Reference< XMultiServiceFactory > xORB = getServiceFactory(); + try + { + DBG_ASSERT(xORB.is(), "OControlWizard::implGetDSContext: invalid service factory!"); + + Reference< XInterface > xContext; + if (xORB.is()) + xContext = xORB->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdb.DatabaseContext")); + DBG_ASSERT(xContext.is(), "OControlWizard::implGetDSContext: invalid database context!"); + + m_aContext.xDatasourceContext = Reference< XNameAccess >(xContext, UNO_QUERY); + DBG_ASSERT(m_aContext.xDatasourceContext.is() || !xContext.is(), "OControlWizard::implGetDSContext: invalid database context (missing the XNameAccess)!"); + } + catch(Exception&) + { + DBG_ERROR("OControlWizard::implGetDSContext: invalid database context!"); + } + } + + //--------------------------------------------------------------------- + Reference< XConnection > OControlWizard::getFormConnection(const OAccessRegulator&) const + { + return getFormConnection(); + } + //--------------------------------------------------------------------- + Reference< XConnection > OControlWizard::getFormConnection() const + { + Reference< XConnection > xConn; + try + { + if ( !::dbtools::isEmbeddedInDatabase(m_aContext.xForm,xConn) ) + m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("ActiveConnection")) >>= xConn; + } + catch(const Exception&) + { + DBG_ERROR("OControlWizard::getFormConnection: caught an exception!"); + } + return xConn; + } + + //--------------------------------------------------------------------- + void OControlWizard::setFormConnection( const OAccessRegulator& _rAccess, const Reference< XConnection >& _rxConn, sal_Bool _bAutoDispose ) + { + try + { + Reference< XConnection > xOldConn = getFormConnection(_rAccess); + if (xOldConn.get() == _rxConn.get()) + return; + + disposeComponent(xOldConn); + + // set the new connection + if ( _bAutoDispose ) + { + // for this, use a AutoDisposer (so the conn is cleaned up when the form dies or get's another connection) + Reference< XRowSet > xFormRowSet( m_aContext.xForm, UNO_QUERY ); + OAutoConnectionDisposer* pAutoDispose = new OAutoConnectionDisposer( xFormRowSet, _rxConn ); + Reference< XPropertyChangeListener > xEnsureDelete( pAutoDispose ); + } + else + { + m_aContext.xForm->setPropertyValue( ::rtl::OUString::createFromAscii("ActiveConnection"), makeAny( _rxConn ) ); + } + } + catch(const Exception&) + { + DBG_ERROR("OControlWizard::setFormConnection: caught an exception!"); + } + } + + //--------------------------------------------------------------------- + sal_Bool OControlWizard::updateContext(const OAccessRegulator&) + { + return initContext(); + } + //--------------------------------------------------------------------- + Reference< XInteractionHandler > OControlWizard::getInteractionHandler(Window* _pWindow) const + { + const ::rtl::OUString sInteractionHandlerServiceName = ::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler"); + Reference< XInteractionHandler > xHandler; + try + { + if (getServiceFactory().is()) + xHandler = Reference< XInteractionHandler >(getServiceFactory()->createInstance(sInteractionHandlerServiceName), UNO_QUERY); + } + catch(Exception&) { } + if (!xHandler.is()) + ShowServiceNotAvailableError(_pWindow, sInteractionHandlerServiceName, sal_True); + return xHandler; + } + //--------------------------------------------------------------------- + sal_Bool OControlWizard::initContext() + { + DBG_ASSERT(m_aContext.xObjectModel.is(), "OGroupBoxWizard::initContext: have no control model to work with!"); + if (!m_aContext.xObjectModel.is()) + return sal_False; + + // reset the context + m_aContext.xForm.clear(); + m_aContext.xRowSet.clear(); + m_aContext.xDocumentModel.clear(); + m_aContext.xDrawPage.clear(); + m_aContext.xObjectShape.clear(); + m_aContext.aFieldNames.realloc(0); + + m_aContext.xObjectContainer.clear(); + m_aContext.aTypes.clear(); + m_aContext.bEmbedded = sal_False; + + Any aSQLException; + Reference< XPreparedStatement > xStatement; + try + { + // get the datasource context + implGetDSContext(); + + // first, determine the form the control belongs to + implDetermineForm(); + + // need the page, too + implDeterminePage(); + + // the shape of the control + implDetermineShape(); + + // get the columns of the object the settins refer to + Reference< XNameAccess > xColumns; + + if (m_aContext.xForm.is()) + { + // collect some properties of the form + ::rtl::OUString sObjectName = ::comphelper::getString(m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("Command"))); + sal_Int32 nObjectType = ::comphelper::getINT32(m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("CommandType"))); + + // calculate the connection the rowset is working with + Reference< XConnection > xConnection; + m_aContext.bEmbedded = ::dbtools::isEmbeddedInDatabase( m_aContext.xForm, xConnection ); + if ( !m_aContext.bEmbedded ) + xConnection = ::dbtools::connectRowset( m_aContext.xRowSet, getServiceFactory(), sal_True ); + + // get the fields + if (xConnection.is()) + { + switch (nObjectType) + { + case 0: + { + Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY); + if (xSupplyTables.is() && xSupplyTables->getTables().is() && xSupplyTables->getTables()->hasByName(sObjectName)) + { + Reference< XColumnsSupplier > xSupplyColumns; + m_aContext.xObjectContainer = xSupplyTables->getTables(); + m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns; + DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid table columns!"); + xColumns = xSupplyColumns->getColumns(); + } + } + break; + case 1: + { + Reference< XQueriesSupplier > xSupplyQueries(xConnection, UNO_QUERY); + if (xSupplyQueries.is() && xSupplyQueries->getQueries().is() && xSupplyQueries->getQueries()->hasByName(sObjectName)) + { + Reference< XColumnsSupplier > xSupplyColumns; + m_aContext.xObjectContainer = xSupplyQueries->getQueries(); + m_aContext.xObjectContainer->getByName(sObjectName) >>= xSupplyColumns; + DBG_ASSERT(xSupplyColumns.is(), "OControlWizard::initContext: invalid query columns!"); + xColumns = xSupplyColumns->getColumns(); + } + } + break; + default: + { + xStatement = xConnection->prepareStatement(sObjectName); + + // not interested in any results, only in the fields + Reference< XPropertySet > xStatementProps(xStatement, UNO_QUERY); + xStatementProps->setPropertyValue(::rtl::OUString::createFromAscii("MaxRows"), makeAny(sal_Int32(0))); + + // TODO: think about handling local SQLExceptions here ... + Reference< XColumnsSupplier > xSupplyCols(xStatement->executeQuery(), UNO_QUERY); + if (xSupplyCols.is()) + xColumns = xSupplyCols->getColumns(); + } + } + } + } + + if (xColumns.is()) + { + m_aContext.aFieldNames = xColumns->getElementNames(); + static const ::rtl::OUString s_sFieldTypeProperty = ::rtl::OUString::createFromAscii("Type"); + const ::rtl::OUString* pBegin = m_aContext.aFieldNames.getConstArray(); + const ::rtl::OUString* pEnd = pBegin + m_aContext.aFieldNames.getLength(); + for(;pBegin != pEnd;++pBegin) + { + sal_Int32 nFieldType = DataType::OTHER; + try + { + Reference< XPropertySet > xColumn; + xColumns->getByName(*pBegin) >>= xColumn; + xColumn->getPropertyValue(s_sFieldTypeProperty) >>= nFieldType; + } + catch(Exception&) + { + DBG_ERROR("OControlWizard::initContext: unexpected exception while gathering column information!"); + } + m_aContext.aTypes.insert(OControlWizardContext::TNameTypeMap::value_type(*pBegin,nFieldType)); + } + } + } + catch(SQLContext& e) { aSQLException <<= e; } + catch(SQLWarning& e) { aSQLException <<= e; } + catch(SQLException& e) { aSQLException <<= e; } + catch(Exception&) + { + DBG_ERROR("OControlWizard::initContext: could not retrieve the control context (caught an exception)!"); + } + + ::comphelper::disposeComponent(xStatement); + + if (aSQLException.hasValue()) + { // an SQLException (or derivee) was thrown ... + + // prepend an extra SQLContext explaining what we were doing + SQLContext aContext; + aContext.Message = String(ModuleRes(RID_STR_COULDNOTOPENTABLE)); + aContext.NextException = aSQLException; + + // create an interaction handler to display this exception + Reference< XInteractionHandler > xHandler = getInteractionHandler(this); + if ( !xHandler.is() ) + return sal_False; + + Reference< XInteractionRequest > xRequest = new OInteractionRequest(makeAny(aContext)); + try + { + xHandler->handle(xRequest); + } + catch(Exception&) { } + return sal_False; + } + + return 0 != m_aContext.aFieldNames.getLength(); + } + + //--------------------------------------------------------------------- + void OControlWizard::commitControlSettings(OControlWizardSettings* _pSettings) + { + DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::commitControlSettings: have no control model to work with!"); + if (!m_aContext.xObjectModel.is()) + return; + + // the only thing we have at the moment is the label + try + { + ::rtl::OUString sLabelPropertyName = ::rtl::OUString::createFromAscii("Label"); + Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo(); + if (xInfo.is() && xInfo->hasPropertyByName(sLabelPropertyName)) + { + ::rtl::OUString sControlLabel(_pSettings->sControlLabel); + m_aContext.xObjectModel->setPropertyValue( + ::rtl::OUString::createFromAscii("Label"), + makeAny(sControlLabel) + ); + } + } + catch(Exception&) + { + DBG_ERROR("OControlWizard::commitControlSettings: could not commit the basic control settings!"); + } + } + + //--------------------------------------------------------------------- + void OControlWizard::initControlSettings(OControlWizardSettings* _pSettings) + { + DBG_ASSERT(m_aContext.xObjectModel.is(), "OControlWizard::initControlSettings: have no control model to work with!"); + if (!m_aContext.xObjectModel.is()) + return; + + // initialize some settings from the control model give + try + { + ::rtl::OUString sLabelPropertyName = ::rtl::OUString::createFromAscii("Label"); + Reference< XPropertySetInfo > xInfo = m_aContext.xObjectModel->getPropertySetInfo(); + if (xInfo.is() && xInfo->hasPropertyByName(sLabelPropertyName)) + { + ::rtl::OUString sControlLabel; + m_aContext.xObjectModel->getPropertyValue(sLabelPropertyName) >>= sControlLabel; + _pSettings->sControlLabel = sControlLabel; + } + } + catch(Exception&) + { + DBG_ERROR("OControlWizard::initControlSettings: could not retrieve the basic control settings!"); + } + } + + //--------------------------------------------------------------------- + sal_Bool OControlWizard::needDatasourceSelection() + { + // lemme see ... + return (0 == getContext().aFieldNames.getLength()); + // if we got fields, the data source is valid ... +// try +// { +// // first, we need a valid data source name +// ::rtl::OUString sDataSourceName; +// m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("DataSourceName")) >>= sDataSourceName; +// if (m_aContext.xDatasourceContext.is() && m_aContext.xDatasourceContext->hasByName(sDataSourceName)) +// { // at least the data source name is valid ... +// // then, a CommandType "table" would be nice ... +// sal_Int32 nCommandType = CommandType::COMMAND; +// m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")) >>= nCommandType; +// if (CommandType::TABLE == nCommandType) +// { // okay .... +// // now the table itself should be valid +// ::rtl::OUString sTableName; +// m_aContext.xForm->getPropertyValue(::rtl::OUString::createFromAscii("Command")) >>= sTableName; +// if (m_aContext.xObjectContainer.is() && m_aContext.xObjectContainer->hasByName(sTableName)) +// return sal_False; +// } +// } +// } +// catch(Exception&) +// { +// DBG_ERROR("OControlWizard::needDatasourceSelection: caught an exception while checking the form settings!"); +// } +// return sal_True; + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/controlwizard.hxx b/extensions/source/dbpilots/controlwizard.hxx new file mode 100644 index 000000000000..13920c5978f7 --- /dev/null +++ b/extensions/source/dbpilots/controlwizard.hxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_CONTROLWIZARD_HXX +#define _EXTENSIONS_DBP_CONTROLWIZARD_HXX + +#include <svtools/wizardmachine.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/form/FormComponentType.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> +#include <com/sun/star/task/XInteractionHandler.hpp> +#include <vcl/fixed.hxx> +#include <vcl/edit.hxx> +#ifndef _SV_BUTTON_HXX +#include <vcl/button.hxx> +#endif +#include <vcl/lstbox.hxx> +#include <vcl/combobox.hxx> +#include "dbptypes.hxx" +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#include "dbpresid.hrc" +#endif +#include "componentmodule.hxx" +#include "wizardcontext.hxx" + +class ResId; +//......................................................................... +namespace dbp +{ +//......................................................................... + + //===================================================================== + //= OControlWizardSettings + //===================================================================== + struct OControlWizardSettings + { + String sControlLabel; + }; + + //===================================================================== + //= OControlWizardPage + //===================================================================== + class OControlWizard; + typedef ::svt::OWizardPage OControlWizardPage_Base; + class OControlWizardPage : public OControlWizardPage_Base + { + protected: + FixedLine* m_pFormSettingsSeparator; + FixedText* m_pFormDatasourceLabel; + FixedText* m_pFormDatasource; + FixedText* m_pFormContentTypeLabel; + FixedText* m_pFormContentType; + FixedText* m_pFormTableLabel; + FixedText* m_pFormTable; + + protected: + OControlWizard* getDialog(); + const OControlWizard* getDialog() const; + const OControlWizardContext& getContext(); + sal_Bool updateContext(); + void setFormConnection(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn, sal_Bool _bAutoDispose = sal_True ); + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > + getFormConnection() const; + + public: + OControlWizardPage( OControlWizard* _pParent, const ResId& _rResId ); + ~OControlWizardPage(); + + protected: + void fillListBox( + ListBox& _rList, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rItems, + sal_Bool _bClear = sal_True); + void fillListBox( + ComboBox& _rList, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rItems, + sal_Bool _bClear = sal_True); + + protected: + void enableFormDatasourceDisplay(); + void adjustControlForNoDSDisplay(Control* _pControl, sal_Bool bConstLowerDistance = sal_False); + + protected: + // OWizardPage overridables + virtual void initializePage(); + }; + + struct OAccessRegulator; + //===================================================================== + //= OControlWizard + //===================================================================== + typedef ::svt::OWizardMachine OControlWizard_Base; + class OControlWizard : public OControlWizard_Base + { + private: + OControlWizardContext m_aContext; + + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xORB; + + public: + OControlWizard( + Window* _pParent, + const ResId& _rId, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObjectModel, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB + ); + ~OControlWizard(); + + // make the some base class methods public + sal_Bool travelNext() { return OControlWizard_Base::travelNext(); } + + public: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + getServiceFactory() const { return m_xORB; } + + const OControlWizardContext& getContext() const { return m_aContext; } + sal_Bool updateContext(const OAccessRegulator&); + void setFormConnection(const OAccessRegulator&, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn, sal_Bool _bAutoDispose = sal_True ); + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > + getFormConnection(const OAccessRegulator&) const; + + /** returns the com.sun.star.task.InteractionHandler + @param _pWindow The window will be used when an error message has to be shown. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > getInteractionHandler(Window* _pWindow) const; + + protected: + // initialize the derivees settings (which have to be derived from OControlWizardSettings) + // with some common data extracted from the control model + void initControlSettings(OControlWizardSettings* _pSettings); + // commit the control-relevant settings + void commitControlSettings(OControlWizardSettings* _pSettings); + + sal_Bool needDatasourceSelection(); + + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > + getFormConnection() const; + + virtual sal_Bool approveControl(sal_Int16 _nClassId) = 0; + + // ModalDialog overridables + virtual short Execute(); + + private: + sal_Bool initContext(); + + void implGetDSContext(); + void implDetermineForm(); + void implDeterminePage(); + void implDetermineShape(); + + // made private. Not to be used by derived (or external) classes + virtual void ActivatePage(); + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBP_CONTROLWIZARD_HXX + diff --git a/extensions/source/dbpilots/dbp.component b/extensions/source/dbpilots/dbp.component new file mode 100644 index 000000000000..84ec98713b2a --- /dev/null +++ b/extensions/source/dbpilots/dbp.component @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="org.openoffice.comp.dbp.OGridWizard"> + <service name="com.sun.star.sdb.GridControlAutoPilot"/> + </implementation> + <implementation name="org.openoffice.comp.dbp.OGroupBoxWizard"> + <service name="com.sun.star.sdb.GroupBoxAutoPilot"/> + </implementation> + <implementation name="org.openoffice.comp.dbp.OListComboWizard"> + <service name="com.sun.star.sdb.ListComboBoxAutoPilot"/> + </implementation> +</component> diff --git a/extensions/source/dbpilots/dbpilots.src b/extensions/source/dbpilots/dbpilots.src new file mode 100644 index 000000000000..fa96cbead1eb --- /dev/null +++ b/extensions/source/dbpilots/dbpilots.src @@ -0,0 +1,78 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#include "dbpresid.hrc" +#endif + +ModalDialog RID_DLG_GROUPBOXWIZARD +{ + Text [ en-US ] = "Group Element Wizard"; + + OutputSize = TRUE ; + SVLook = TRUE ; + Moveable = TRUE ; + Closeable = TRUE ; + Hide = TRUE; +}; + +ModalDialog RID_DLG_LISTCOMBOWIZARD +{ + OutputSize = TRUE ; + SVLook = TRUE ; + Moveable = TRUE ; + Closeable = TRUE ; + Hide = TRUE; +}; + +ModalDialog RID_DLG_GRIDWIZARD +{ + OutputSize = TRUE ; + SVLook = TRUE ; + Moveable = TRUE ; + Closeable = TRUE ; + Hide = TRUE; + + Text [ en-US ] = "Table Element Wizard"; +}; + +String RID_STR_LISTWIZARD_TITLE +{ + Text [ en-US ] = "List Box Wizard"; +}; + +String RID_STR_COMBOWIZARD_TITLE +{ + Text [ en-US ] = "Combo Box Wizard"; +}; + +String RID_STR_COULDNOTOPENTABLE +{ + Text [ en-US ] = "The table connection to the data source could not be established."; +}; + + diff --git a/extensions/source/dbpilots/dbpresid.hrc b/extensions/source/dbpilots/dbpresid.hrc new file mode 100644 index 000000000000..ecb424c5e3b7 --- /dev/null +++ b/extensions/source/dbpilots/dbpresid.hrc @@ -0,0 +1,233 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#define _EXTENSIONS_DBP_DBPRESID_HRC_ + +#include "dbpilots.hrc" + +//======================================================================== +// basics + +#define RID_DIALOG_START RID_DBP_START +#define RID_PAGE_START RID_DBP_START +#define RID_STRING_START RID_DBP_START +#define RID_ERRORBOX_START RID_DBP_START + +//======================================================================== +// strings + +#define RID_STR_GROUPWIZ_DBFIELD (RID_STRING_START + 1 ) +#define RID_STR_COMBOWIZ_DBFIELD (RID_STRING_START + 2 ) +#define RID_STR_LISTWIZARD_TITLE (RID_STRING_START + 3 ) +#define RID_STR_COMBOWIZARD_TITLE (RID_STRING_START + 4 ) +#define RID_STR_COULDNOTOPENTABLE (RID_STRING_START + 5 ) +#define RID_STR_DATEPOSTFIX (RID_STRING_START + 6 ) +#define RID_STR_TIMEPOSTFIX (RID_STRING_START + 7 ) +#define RID_STR_TYPE_QUERY (RID_STRING_START + 8 ) +#define RID_STR_TYPE_TABLE (RID_STRING_START + 9 ) +#define RID_STR_TYPE_COMMAND (RID_STRING_START + 10 ) + +// please adjust RID_STRING_END (below) when adding new strings +#define RID_STRING_END RID_STR_TIMEPOSTFIX + +//======================================================================== +// dialogs + +#define RID_DLG_GROUPBOXWIZARD ( RID_DIALOG_START + 1 ) +#define RID_DLG_LISTCOMBOWIZARD ( RID_DIALOG_START + 2 ) +#define RID_DLG_GRIDWIZARD ( RID_DIALOG_START + 3 ) + +// please adjust RID_DIALOG_END (below) when adding new dialogs +#define RID_DIALOG_END RID_DLG_GRIDWIZARD + +//======================================================================== +// tab pages + +#define RID_PAGE_TABLESELECTION ( RID_PAGE_START + 1 ) +#define RID_PAGE_GROUPRADIOSELECTION ( RID_PAGE_START + 2 ) +#define RID_PAGE_DEFAULTFIELDSELECTION ( RID_PAGE_START + 3 ) +#define RID_PAGE_OPTIONVALUES ( RID_PAGE_START + 4 ) +#define RID_PAGE_OPTION_DBFIELD ( RID_PAGE_START + 5 ) +#define RID_PAGE_OPTIONS_FINAL ( RID_PAGE_START + 6 ) +#define RID_PAGE_LCW_CONTENTSELECTION_TABLE ( RID_PAGE_START + 7 ) +#define RID_PAGE_LCW_CONTENTSELECTION_FIELD ( RID_PAGE_START + 8 ) +#define RID_PAGE_LCW_FIELDLINK ( RID_PAGE_START + 9 ) +#define RID_PAGE_GW_FIELDSELECTION ( RID_PAGE_START + 10 ) +#define RID_PAGE_FORM_DATASOURCE_STATUS ( RID_PAGE_START + 11 ) + +// please adjust RID_PAGE_END (below) when adding new tab pages +#define RID_PAGE_END RID_PAGE_GW_FIELDSELECTION + +//======================================================================== +// ErrorBox + +#define RID_ERR_INVALID_FORM_CONNECTION ( RID_ERRORBOX_START + 1 ) + +// please adjust RID_ERRORBOX_END (below) when adding new error boxes +#define RID_ERRORBOX_END RID_ERR_INVALID_FORM_CONNECTION + + +//======================================================================== +//======================================================================== +//= range checks + +#if RID_STRING_END > RID_DBP_END + #error "please adjust the resource id ranges!!" +#endif +#if RID_DIALOG_END > RID_DBP_END + #error "please adjust the resource id ranges!!" +#endif +#if RID_PAGE_END > RID_DBP_END + #error "please adjust the resource id ranges!!" +#endif +#if RID_ERRORBOX_END > RID_DBP_END + #error "please adjust the resource id ranges!!" +#endif + +//======================================================================== +// local ids + +//........................................................................ +// FixedLine + +#define FL_DATA 1 +#define FL_DEFAULTSELECTION 2 +#define FL_OPTIONVALUES 3 +#define FL_DATABASEFIELD_EXPL 4 +#define FL_NAMEIT 5 +#define FL_FRAME 6 +#define FL_FORMSETINGS 7 + +//........................................................................ +// FixedText + +#define FT_DATASOURCE 1 +#define FT_TABLE 2 +#define FT_RADIOLABELS 3 +#define FT_RADIOBUTTONS 4 +#define FT_DEFAULTSELECTION 5 +#define FT_OPTIONVALUES_EXPL 6 +#define FT_OPTIONVALUES 7 +#define FT_DATABASEFIELD_EXPL 8 +#define FT_DATABASEFIELD_QUEST 9 +#define FT_NAMEIT 10 +#define FT_THATSALL 11 +#define FT_SELECTTABLE_LABEL 12 +#define FT_TABLEFIELDS 13 +#define FT_DISPLAYEDFIELD 14 +#define FT_CONTENTFIELD_INFO 15 +#define FT_VALUELISTFIELD 16 +#define FT_TABLEFIELD 17 +#define FT_EXPLANATION 18 +#define FT_EXISTING_FIELDS 19 +#define FT_SELECTED_FIELDS 20 +#define FT_FIELDLINK_DESC 21 +#define FT_FORMDATASOURCELABEL 22 +#define FT_FORMDATASOURCE 23 +#define FT_FORMTABLELABEL 24 +#define FT_FORMTABLE 25 +#define FT_FORMCONTENTTYPELABEL 26 +#define FT_FORMCONTENTTYPE 27 + +//........................................................................ +// ListBox + +#define LB_DATASOURCE 1 +#define LB_TABLE 2 +#define LB_RADIOBUTTONS 3 +#define LB_DEFSELECTIONFIELD 3 +#define LB_STOREINFIELD 4 +#define LB_SELECTTABLE 5 +#define LB_SELECTFIELD 6 +#define LB_EXISTING_FIELDS 7 +#define LB_SELECTED_FIELDS 8 + +//........................................................................ +// Edit + +#define ET_RADIOLABELS 1 +#define ET_OPTIONVALUE 2 +#define ET_NAMEIT 3 +#define ET_DISPLAYEDFIELD 4 + +//........................................................................ +// PushButton + +#define PB_MOVETORIGHT 1 +#define PB_MOVETOLEFT 2 +#define PB_FIELDRIGHT 3 +#define PB_ALLFIELDSRIGHT 4 +#define PB_FIELDLEFT 5 +#define PB_ALLFIELDSLEFT 6 +#define PB_FORMDATASOURCE 7 + +//........................................................................ +// RadioButton + +#define RB_DEFSELECTION_YES 1 +#define RB_DEFSELECTION_NO 2 +#define RB_STOREINFIELD_YES 3 +#define RB_STOREINFIELD_NO 4 + +//........................................................................ +// ComboBox + +#define CMB_VALUELISTFIELD 1 +#define CMB_TABLEFIELD 2 + +//........................................................................ +// String + +#define STR_FIELDINFO_LISTBOX 1 +#define STR_FIELDINFO_COMBOBOX 2 + +//........................................................................ +// Image + +#define IMG_TABLE 1 +#define IMG_TABLE_HC 2 +#define IMG_QUERY 3 +#define IMG_QUERY_HC 4 + +//======================================================================== +// defines + +#define WINDOW_SIZE_X 260 +#define WINDOW_SIZE_Y 185 +#define WINDOW_HALF_SIZE_X ( WINDOW_SIZE_X / 2 ) + +#define BUTTON_SIZE_X 50 +#define BUTTON_SIZE_Y 14 + +#define ITEM_BUTTON_SIZE_X 20 +#define ITEM_BUTTON_SIZE_Y 12 + + + +#endif // _EXTENSIONS_DBP_DBPRESID_HRC_ + diff --git a/extensions/source/dbpilots/dbpservices.cxx b/extensions/source/dbpilots/dbpservices.cxx new file mode 100644 index 000000000000..6cb77dde19bb --- /dev/null +++ b/extensions/source/dbpilots/dbpservices.cxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "componentmodule.hxx" + +//--------------------------------------------------------------------------------------- + +using namespace ::rtl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL createRegistryInfo_OGroupBoxWizard(); +extern "C" void SAL_CALL createRegistryInfo_OListComboWizard(); +extern "C" void SAL_CALL createRegistryInfo_OGridWizard(); + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL dbp_initializeModule() +{ + static sal_Bool s_bInit = sal_False; + if (!s_bInit) + { + createRegistryInfo_OGroupBoxWizard(); + createRegistryInfo_OListComboWizard(); + createRegistryInfo_OGridWizard(); + ::dbp::OModule::setResourceFilePrefix("dbp"); + s_bInit = sal_True; + } +} + +//--------------------------------------------------------------------------------------- + +extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL +component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment ** /*ppEnv*/ + ) +{ + dbp_initializeModule(); + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( + const sal_Char* pImplementationName, + void* pServiceManager, + void* /*pRegistryKey*/) +{ + Reference< XInterface > xRet; + if (pServiceManager && pImplementationName) + { + xRet = ::dbp::OModule::getComponentFactory( + ::rtl::OUString::createFromAscii(pImplementationName), + static_cast< XMultiServiceFactory* >(pServiceManager)); + } + + if (xRet.is()) + xRet->acquire(); + return xRet.get(); +}; + + diff --git a/extensions/source/dbpilots/dbptools.cxx b/extensions/source/dbpilots/dbptools.cxx new file mode 100644 index 000000000000..ae9bd066b79c --- /dev/null +++ b/extensions/source/dbpilots/dbptools.cxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "dbptools.hxx" +#include <tools/debug.hxx> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::container; + + //--------------------------------------------------------------------- + void disambiguateName(const Reference< XNameAccess >& _rxContainer, ::rtl::OUString& _rElementsName) + { + DBG_ASSERT(_rxContainer.is(), "::dbp::disambiguateName: invalid container!"); + if (!_rxContainer.is()) + return; + + try + { + ::rtl::OUString sBase(_rElementsName); + for (sal_Int32 i=1; i<0x7FFFFFFF; ++i) + { + _rElementsName = sBase; + _rElementsName += ::rtl::OUString::valueOf((sal_Int32)i); + if (!_rxContainer->hasByName(_rElementsName)) + return; + } + // can't do anything ... no free names + _rElementsName = sBase; + } + catch(Exception&) + { + DBG_ERROR("::dbp::disambiguateName: something went (strangely) wrong!"); + } + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/dbptools.hxx b/extensions/source/dbpilots/dbptools.hxx new file mode 100644 index 000000000000..efe897d999f5 --- /dev/null +++ b/extensions/source/dbpilots/dbptools.hxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPTOOLS_HXX_ +#define _EXTENSIONS_DBP_DBPTOOLS_HXX_ + +#include <com/sun/star/container/XNameAccess.hpp> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + void disambiguateName( + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainer, + ::rtl::OUString& _rElementsName); + +//......................................................................... +} // namespace dbp +//......................................................................... + + +#endif // _EXTENSIONS_DBP_DBPTOOLS_HXX_ + diff --git a/extensions/source/dbpilots/dbptypes.hxx b/extensions/source/dbpilots/dbptypes.hxx new file mode 100644 index 000000000000..57a871315981 --- /dev/null +++ b/extensions/source/dbpilots/dbptypes.hxx @@ -0,0 +1,47 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPTYPES_HXX_ +#define _EXTENSIONS_DBP_DBPTYPES_HXX_ + +#include <comphelper/stl_types.hxx> +#include <tools/string.hxx> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + DECLARE_STL_VECTOR( String, StringArray ); + DECLARE_STL_STDKEY_SET( String, StringBag ); + DECLARE_STL_STDKEY_MAP( sal_uInt32, String, MapInt2String ); + +//......................................................................... +} // namespace dbp +//......................................................................... +#endif // _EXTENSIONS_DBP_DBPTYPES_HXX_ + diff --git a/extensions/source/dbpilots/gridpages.src b/extensions/source/dbpilots/gridpages.src new file mode 100644 index 000000000000..5aca75b77d55 --- /dev/null +++ b/extensions/source/dbpilots/gridpages.src @@ -0,0 +1,114 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#include "dbpresid.hrc" +#endif + +TabPage RID_PAGE_GW_FIELDSELECTION +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + + Text [ en-US ] = "Field Selection"; + + FixedLine FL_FRAME + { + Pos = MAP_APPFONT ( 4 , 40 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + Text [ en-US ] = "Table element"; + }; + + FixedText FT_EXISTING_FIELDS + { + Pos = MAP_APPFONT ( 7, 52 ); + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 13, 8 ); + Text [ en-US ] = "Existing fields"; + }; + ListBox LB_EXISTING_FIELDS + { + Pos = MAP_APPFONT ( 7 , 63 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 13, WINDOW_SIZE_Y - 63 - 6 ) ; + SVLook = TRUE ; + Border = TRUE ; + AutoHScroll = TRUE ; + Sort = FALSE; + DropDown = FALSE; + }; + PushButton PB_FIELDRIGHT + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2, 63 ); + Size = MAP_APPFONT ( ITEM_BUTTON_SIZE_X, ITEM_BUTTON_SIZE_Y ); + Text = "->"; + }; + PushButton PB_ALLFIELDSRIGHT + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2, 63 + ITEM_BUTTON_SIZE_Y + 3 ); + Size = MAP_APPFONT ( ITEM_BUTTON_SIZE_X, ITEM_BUTTON_SIZE_Y ); + Text = "=>>"; + }; + PushButton PB_FIELDLEFT + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2, 63 + ITEM_BUTTON_SIZE_Y + 3 + ITEM_BUTTON_SIZE_Y + 12 ); + Size = MAP_APPFONT ( ITEM_BUTTON_SIZE_X, ITEM_BUTTON_SIZE_Y ); + Text = "<-"; + }; + PushButton PB_ALLFIELDSLEFT + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2, 63 + ITEM_BUTTON_SIZE_Y + 3 + ITEM_BUTTON_SIZE_Y + 12 + ITEM_BUTTON_SIZE_Y + 3 ); + Size = MAP_APPFONT ( ITEM_BUTTON_SIZE_X, ITEM_BUTTON_SIZE_Y ); + Text = "<<="; + }; + FixedText FT_SELECTED_FIELDS + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + ITEM_BUTTON_SIZE_X / 2 + 6, 52 ); + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 13, 8 ); + Text [ en-US ] = "Selected fields"; + }; + ListBox LB_SELECTED_FIELDS + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + ITEM_BUTTON_SIZE_X / 2 + 6 , 63 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 13, WINDOW_SIZE_Y - 63 - 6 ) ; + SVLook = TRUE ; + Border = TRUE ; + AutoHScroll = TRUE ; + Sort = FALSE; + DropDown = FALSE; + }; +}; + +String RID_STR_DATEPOSTFIX +{ + Text [ en-US ] = " (Date)"; +}; + +String RID_STR_TIMEPOSTFIX +{ + Text [ en-US ] = " (Time)"; +}; + + diff --git a/extensions/source/dbpilots/gridwizard.cxx b/extensions/source/dbpilots/gridwizard.cxx new file mode 100644 index 000000000000..7606fc7bec65 --- /dev/null +++ b/extensions/source/dbpilots/gridwizard.cxx @@ -0,0 +1,485 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "gridwizard.hxx" +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <com/sun/star/sdbc/DataType.hpp> +#include <comphelper/stl_types.hxx> +#include <tools/string.hxx> +#include <com/sun/star/form/XGridColumnFactory.hpp> +#include <com/sun/star/awt/MouseWheelBehavior.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <tools/debug.hxx> +#include "dbptools.hxx" +#include "dbpilots.hrc" + +#define GW_STATE_DATASOURCE_SELECTION 0 +#define GW_STATE_FIELDSELECTION 1 + +//......................................................................... +namespace dbp +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::form; + using namespace ::com::sun::star::awt; + using namespace ::svt; + + //===================================================================== + //= OGridWizard + //===================================================================== + //--------------------------------------------------------------------- + OGridWizard::OGridWizard( Window* _pParent, + const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB ) + :OControlWizard(_pParent, ModuleRes(RID_DLG_GRIDWIZARD), _rxObjectModel, _rxORB) + ,m_bHadDataSelection(sal_True) + { + initControlSettings(&m_aSettings); + + m_pPrevPage->SetHelpId(HID_GRIDWIZARD_PREVIOUS); + m_pNextPage->SetHelpId(HID_GRIDWIZARD_NEXT); + m_pCancel->SetHelpId(HID_GRIDWIZARD_CANCEL); + m_pFinish->SetHelpId(HID_GRIDWIZARD_FINISH); + + // if we do not need the data source selection page ... + if (!needDatasourceSelection()) + { // ... skip it! + skip(1); + m_bHadDataSelection = sal_False; + } + } + + //--------------------------------------------------------------------- + sal_Bool OGridWizard::approveControl(sal_Int16 _nClassId) + { + if (FormComponentType::GRIDCONTROL != _nClassId) + return sal_False; + + Reference< XGridColumnFactory > xColumnFactory(getContext().xObjectModel, UNO_QUERY); + if (!xColumnFactory.is()) + return sal_False; + + return sal_True; + } + + //--------------------------------------------------------------------- + void OGridWizard::implApplySettings() + { + const OControlWizardContext& rContext = getContext(); + + // the factory for the columns + Reference< XGridColumnFactory > xColumnFactory(rContext.xObjectModel, UNO_QUERY); + DBG_ASSERT(xColumnFactory.is(), "OGridWizard::implApplySettings: should never have made it 'til here!"); + // (if we're here, what the hell happened in approveControl??) + + // the container for the columns + Reference< XNameContainer > xColumnContainer(rContext.xObjectModel, UNO_QUERY); + DBG_ASSERT(xColumnContainer.is(), "OGridWizard::implApplySettings: no container!"); + + if (!xColumnFactory.is() || !xColumnContainer.is()) + return; + + static const ::rtl::OUString s_sDataFieldProperty = ::rtl::OUString::createFromAscii("DataField"); + static const ::rtl::OUString s_sLabelProperty = ::rtl::OUString::createFromAscii("Label"); + static const ::rtl::OUString s_sWidthProperty = ::rtl::OUString::createFromAscii("Width"); + static const ::rtl::OUString s_sMouseWheelBehavior = ::rtl::OUString::createFromAscii("MouseWheelBehavior"); + static const ::rtl::OUString s_sEmptyString; + + // collect "descriptors" for the to-be-created (grid)columns + DECLARE_STL_VECTOR( ::rtl::OUString, StringArray ); + StringArray aColumnServiceNames; // service names to be used with the XGridColumnFactory + StringArray aColumnLabelPostfixes; // postfixes to append to the column labels + StringArray aFormFieldNames; // data field names + + aColumnServiceNames.reserve(getSettings().aSelectedFields.getLength()); + aColumnLabelPostfixes.reserve(getSettings().aSelectedFields.getLength()); + aFormFieldNames.reserve(getSettings().aSelectedFields.getLength()); + + // loop through the selected field names + const ::rtl::OUString* pSelectedFields = getSettings().aSelectedFields.getConstArray(); + const ::rtl::OUString* pEnd = pSelectedFields + getSettings().aSelectedFields.getLength(); + for (;pSelectedFields < pEnd; ++pSelectedFields) + { + // get the information for the selected column + sal_Int32 nFieldType = DataType::OTHER; + OControlWizardContext::TNameTypeMap::const_iterator aFind = rContext.aTypes.find(*pSelectedFields); + if ( aFind != rContext.aTypes.end() ) + nFieldType = aFind->second; + + aFormFieldNames.push_back(*pSelectedFields); + switch (nFieldType) + { + case DataType::BIT: + case DataType::BOOLEAN: + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("CheckBox")); + aColumnLabelPostfixes.push_back(s_sEmptyString); + break; + + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("NumericField")); + aColumnLabelPostfixes.push_back(s_sEmptyString); + break; + + case DataType::FLOAT: + case DataType::REAL: + case DataType::DOUBLE: + case DataType::NUMERIC: + case DataType::DECIMAL: + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("FormattedField")); + aColumnLabelPostfixes.push_back(s_sEmptyString); + break; + + case DataType::DATE: + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("DateField")); + aColumnLabelPostfixes.push_back(s_sEmptyString); + break; + + case DataType::TIME: + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("TimeField")); + aColumnLabelPostfixes.push_back(s_sEmptyString); + break; + + case DataType::TIMESTAMP: + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("DateField")); + aColumnLabelPostfixes.push_back(String(ModuleRes(RID_STR_DATEPOSTFIX))); + + aFormFieldNames.push_back(*pSelectedFields); + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("TimeField")); + aColumnLabelPostfixes.push_back(String(ModuleRes(RID_STR_TIMEPOSTFIX))); + break; + + default: + aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("TextField")); + aColumnLabelPostfixes.push_back(s_sEmptyString); + } + } + + DBG_ASSERT( aFormFieldNames.size() == aColumnServiceNames.size() + && aColumnServiceNames.size() == aColumnLabelPostfixes.size(), + "OGridWizard::implApplySettings: inconsistent descriptor sequences!"); + + // now loop through the descriptions and create the (grid)columns out of th descriptors + { + Reference< XNameAccess > xExistenceChecker(xColumnContainer.get()); + + ConstStringArrayIterator pColumnServiceName = aColumnServiceNames.begin(); + ConstStringArrayIterator pColumnLabelPostfix = aColumnLabelPostfixes.begin(); + ConstStringArrayIterator pFormFieldName = aFormFieldNames.begin(); + ConstStringArrayIterator pColumnServiceNameEnd = aColumnServiceNames.end(); + + for (;pColumnServiceName < pColumnServiceNameEnd; ++pColumnServiceName, ++pColumnLabelPostfix, ++pFormFieldName) + { + // create a (grid)column for the (resultset)column + try + { + Reference< XPropertySet > xColumn( xColumnFactory->createColumn(*pColumnServiceName), UNO_SET_THROW ); + Reference< XPropertySetInfo > xColumnPSI( xColumn->getPropertySetInfo(), UNO_SET_THROW ); + + ::rtl::OUString sColumnName(*pColumnServiceName); + disambiguateName(xExistenceChecker, sColumnName); + + // the data field the column should be bound to + xColumn->setPropertyValue(s_sDataFieldProperty, makeAny(*pFormFieldName)); + // the label + xColumn->setPropertyValue(s_sLabelProperty, makeAny(::rtl::OUString(*pFormFieldName) += *pColumnLabelPostfix)); + // the width (<void/> => column will be auto-sized) + xColumn->setPropertyValue(s_sWidthProperty, Any()); + + if ( xColumnPSI->hasPropertyByName( s_sMouseWheelBehavior ) ) + xColumn->setPropertyValue( s_sMouseWheelBehavior, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) ); + + // insert the column + xColumnContainer->insertByName(sColumnName, makeAny(xColumn)); + } + catch(Exception&) + { + DBG_ERROR( ::rtl::OString("OGridWizard::implApplySettings: unexpected exception while creating the grid column for field ") + += ::rtl::OString(pFormFieldName->getStr(), pFormFieldName->getLength(), gsl_getSystemTextEncoding()) + += ::rtl::OString("!")); + } + } + } + } + + //--------------------------------------------------------------------- + OWizardPage* OGridWizard::createPage(WizardState _nState) + { + switch (_nState) + { + case GW_STATE_DATASOURCE_SELECTION: + return new OTableSelectionPage(this); + case GW_STATE_FIELDSELECTION: + return new OGridFieldsSelection(this); + } + + return NULL; + } + + //--------------------------------------------------------------------- + WizardTypes::WizardState OGridWizard::determineNextState( WizardState _nCurrentState ) const + { + switch (_nCurrentState) + { + case GW_STATE_DATASOURCE_SELECTION: + return GW_STATE_FIELDSELECTION; + case GW_STATE_FIELDSELECTION: + return WZS_INVALID_STATE; + } + + return WZS_INVALID_STATE; + } + + //--------------------------------------------------------------------- + void OGridWizard::enterState(WizardState _nState) + { + OControlWizard::enterState(_nState); + + enableButtons(WZB_PREVIOUS, m_bHadDataSelection ? (GW_STATE_DATASOURCE_SELECTION < _nState) : GW_STATE_FIELDSELECTION < _nState); + enableButtons(WZB_NEXT, GW_STATE_FIELDSELECTION != _nState); + if (_nState < GW_STATE_FIELDSELECTION) + enableButtons(WZB_FINISH, sal_False); + + if (GW_STATE_FIELDSELECTION == _nState) + defaultButton(WZB_FINISH); + } + + //--------------------------------------------------------------------- + sal_Bool OGridWizard::leaveState(WizardState _nState) + { + if (!OControlWizard::leaveState(_nState)) + return sal_False; + + if (GW_STATE_FIELDSELECTION == _nState) + defaultButton(WZB_NEXT); + + return sal_True; + } + + //--------------------------------------------------------------------- + sal_Bool OGridWizard::onFinish() + { + if ( !OControlWizard::onFinish() ) + return sal_False; + + implApplySettings(); + + return sal_True; + } + + //===================================================================== + //= OGridFieldsSelection + //===================================================================== + //--------------------------------------------------------------------- + OGridFieldsSelection::OGridFieldsSelection( OGridWizard* _pParent ) + :OGridPage(_pParent, ModuleRes(RID_PAGE_GW_FIELDSELECTION)) + ,m_aFrame (this, ModuleRes(FL_FRAME)) + ,m_aExistFieldsLabel (this, ModuleRes(FT_EXISTING_FIELDS)) + ,m_aExistFields (this, ModuleRes(LB_EXISTING_FIELDS)) + ,m_aSelectOne (this, ModuleRes(PB_FIELDRIGHT)) + ,m_aSelectAll (this, ModuleRes(PB_ALLFIELDSRIGHT)) + ,m_aDeselectOne (this, ModuleRes(PB_FIELDLEFT)) + ,m_aDeselectAll (this, ModuleRes(PB_ALLFIELDSLEFT)) + ,m_aSelFieldsLabel (this, ModuleRes(FT_SELECTED_FIELDS)) + ,m_aSelFields (this, ModuleRes(LB_SELECTED_FIELDS)) + { + FreeResource(); + + enableFormDatasourceDisplay(); + + m_aSelectOne.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveOneEntry)); + m_aSelectAll.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveAllEntries)); + m_aDeselectOne.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveOneEntry)); + m_aDeselectAll.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveAllEntries)); + + m_aExistFields.SetSelectHdl(LINK(this, OGridFieldsSelection, OnEntrySelected)); + m_aSelFields.SetSelectHdl(LINK(this, OGridFieldsSelection, OnEntrySelected)); + m_aExistFields.SetDoubleClickHdl(LINK(this, OGridFieldsSelection, OnEntryDoubleClicked)); + m_aSelFields.SetDoubleClickHdl(LINK(this, OGridFieldsSelection, OnEntryDoubleClicked)); + } + + //--------------------------------------------------------------------- + void OGridFieldsSelection::ActivatePage() + { + OGridPage::ActivatePage(); + m_aExistFields.GrabFocus(); + } + + //--------------------------------------------------------------------- + bool OGridFieldsSelection::canAdvance() const + { + return false; + // we're the last page in our wizard + } + + //--------------------------------------------------------------------- + void OGridFieldsSelection::initializePage() + { + OGridPage::initializePage(); + + const OControlWizardContext& rContext = getContext(); + fillListBox(m_aExistFields, rContext.aFieldNames); + + m_aSelFields.Clear(); + const OGridSettings& rSettings = getSettings(); + const ::rtl::OUString* pSelected = rSettings.aSelectedFields.getConstArray(); + const ::rtl::OUString* pEnd = pSelected + rSettings.aSelectedFields.getLength(); + for (; pSelected < pEnd; ++pSelected) + { + m_aSelFields.InsertEntry(*pSelected); + m_aExistFields.RemoveEntry(*pSelected); + } + + implCheckButtons(); + } + + //--------------------------------------------------------------------- + sal_Bool OGridFieldsSelection::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OGridPage::commitPage(_eReason)) + return sal_False; + + OGridSettings& rSettings = getSettings(); + USHORT nSelected = m_aSelFields.GetEntryCount(); + + rSettings.aSelectedFields.realloc(nSelected); + ::rtl::OUString* pSelected = rSettings.aSelectedFields.getArray(); + + for (USHORT i=0; i<nSelected; ++i, ++pSelected) + *pSelected = m_aSelFields.GetEntry(i); + + return sal_True; + } + + //--------------------------------------------------------------------- + void OGridFieldsSelection::implCheckButtons() + { + m_aSelectOne.Enable(m_aExistFields.GetSelectEntryCount() != 0); + m_aSelectAll.Enable(m_aExistFields.GetEntryCount() != 0); + + m_aDeselectOne.Enable(m_aSelFields.GetSelectEntryCount() != 0); + m_aDeselectAll.Enable(m_aSelFields.GetEntryCount() != 0); + + getDialog()->enableButtons(WZB_FINISH, 0 != m_aSelFields.GetEntryCount()); + } + + //--------------------------------------------------------------------- + IMPL_LINK(OGridFieldsSelection, OnEntryDoubleClicked, ListBox*, _pList) + { + PushButton* pSimulateButton = &m_aExistFields == _pList ? &m_aSelectOne : &m_aDeselectOne; + if (pSimulateButton->IsEnabled()) + return OnMoveOneEntry( pSimulateButton ); + else + return 1L; + } + + //--------------------------------------------------------------------- + IMPL_LINK(OGridFieldsSelection, OnEntrySelected, ListBox*, /*NOTINTERESTEDIN*/) + { + implCheckButtons(); + return 0L; + } + + //--------------------------------------------------------------------- + IMPL_LINK(OGridFieldsSelection, OnMoveOneEntry, PushButton*, _pButton) + { + sal_Bool bMoveRight = (&m_aSelectOne == _pButton); + ListBox& rMoveTo = bMoveRight ? m_aSelFields : m_aExistFields; + + // the index of the selected entry + USHORT nSelected = bMoveRight ? m_aExistFields.GetSelectEntryPos() : m_aSelFields.GetSelectEntryPos(); + // the (original) relative position of the entry + sal_IntPtr nRelativeIndex = reinterpret_cast<sal_IntPtr>(bMoveRight ? m_aExistFields.GetEntryData(nSelected) : m_aSelFields.GetEntryData(nSelected)); + + USHORT nInsertPos = LISTBOX_APPEND; + if (!bMoveRight) + { // need to determine an insert pos which reflects the original + nInsertPos = 0; + while (nInsertPos < rMoveTo.GetEntryCount()) + { + if (reinterpret_cast<sal_IntPtr>(rMoveTo.GetEntryData(nInsertPos)) > nRelativeIndex) + break; + ++nInsertPos; + } + } + + // the text of the entry to move + String sMovingEntry = bMoveRight ? m_aExistFields.GetEntry(nSelected) : m_aSelFields.GetEntry(nSelected); + + // insert the entry + nInsertPos = rMoveTo.InsertEntry(sMovingEntry, nInsertPos); + // preserve it's "relative position" entry data + rMoveTo.SetEntryData(nInsertPos, reinterpret_cast<void*>(nRelativeIndex)); + + // remove the entry from it's old list + if (bMoveRight) + { + USHORT nSelectPos = m_aExistFields.GetSelectEntryPos(); + m_aExistFields.RemoveEntry(nSelected); + if ((LISTBOX_ENTRY_NOTFOUND != nSelectPos) && (nSelectPos < m_aExistFields.GetEntryCount())) + m_aExistFields.SelectEntryPos(nSelectPos); + + m_aExistFields.GrabFocus(); + } + else + { + USHORT nSelectPos = m_aSelFields.GetSelectEntryPos(); + m_aSelFields.RemoveEntry(nSelected); + if ((LISTBOX_ENTRY_NOTFOUND != nSelectPos) && (nSelectPos < m_aSelFields.GetEntryCount())) + m_aSelFields.SelectEntryPos(nSelectPos); + + m_aSelFields.GrabFocus(); + } + + implCheckButtons(); + return 0; + } + + //--------------------------------------------------------------------- + IMPL_LINK(OGridFieldsSelection, OnMoveAllEntries, PushButton*, _pButton) + { + sal_Bool bMoveRight = (&m_aSelectAll == _pButton); + m_aExistFields.Clear(); + m_aSelFields.Clear(); + fillListBox(bMoveRight ? m_aSelFields : m_aExistFields, getContext().aFieldNames); + + implCheckButtons(); + return 0; + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/gridwizard.hxx b/extensions/source/dbpilots/gridwizard.hxx new file mode 100644 index 000000000000..85b91d274345 --- /dev/null +++ b/extensions/source/dbpilots/gridwizard.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_GRIDWIZARD_HXX_ +#define _EXTENSIONS_DBP_GRIDWIZARD_HXX_ + +#include "controlwizard.hxx" +#include "commonpagesdbp.hxx" + +//......................................................................... +namespace dbp +{ +//......................................................................... + + //===================================================================== + //= OGridSettings + //===================================================================== + struct OGridSettings : public OControlWizardSettings + { + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSelectedFields; + }; + + //===================================================================== + //= OGridWizard + //===================================================================== + class OGridWizard : public OControlWizard + { + protected: + OGridSettings m_aSettings; + sal_Bool m_bHadDataSelection : 1; + + public: + OGridWizard( + Window* _pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObjectModel, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB + ); + + OGridSettings& getSettings() { return m_aSettings; } + + protected: + // OWizardMachine overridables + virtual ::svt::OWizardPage* createPage( WizardState _nState ); + virtual WizardState determineNextState( WizardState _nCurrentState ) const; + virtual void enterState( WizardState _nState ); + virtual sal_Bool leaveState( WizardState _nState ); + virtual sal_Bool onFinish(); + + virtual sal_Bool approveControl(sal_Int16 _nClassId); + + protected: + void implApplySettings(); + }; + + //===================================================================== + //= OGridPage + //===================================================================== + class OGridPage : public OControlWizardPage + { + public: + OGridPage( OGridWizard* _pParent, const ResId& _rId ) : OControlWizardPage(_pParent, _rId) { } + + protected: + OGridSettings& getSettings() { return static_cast<OGridWizard*>(getDialog())->getSettings(); } + }; + + //===================================================================== + //= OGridFieldsSelection + //===================================================================== + class OGridFieldsSelection : public OGridPage + { + protected: + FixedLine m_aFrame; + FixedText m_aExistFieldsLabel; + ListBox m_aExistFields; + PushButton m_aSelectOne; + PushButton m_aSelectAll; + PushButton m_aDeselectOne; + PushButton m_aDeselectAll; + FixedText m_aSelFieldsLabel; + ListBox m_aSelFields; + + public: + OGridFieldsSelection( OGridWizard* _pParent ); + + protected: + // TabPage overridables + virtual void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + virtual bool canAdvance() const; + + protected: + DECL_LINK(OnMoveOneEntry, PushButton*); + DECL_LINK(OnMoveAllEntries, PushButton*); + DECL_LINK(OnEntrySelected, ListBox*); + DECL_LINK(OnEntryDoubleClicked, ListBox*); + + void implCheckButtons(); + void implApplySettings(); + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > implGetColumns(sal_Bool _bShowError = sal_True); + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBP_GRIDWIZARD_HXX_ + diff --git a/extensions/source/dbpilots/groupboxpages.src b/extensions/source/dbpilots/groupboxpages.src new file mode 100644 index 000000000000..6b651e848010 --- /dev/null +++ b/extensions/source/dbpilots/groupboxpages.src @@ -0,0 +1,226 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#include "dbpresid.hrc" +#endif + +TabPage RID_PAGE_GROUPRADIOSELECTION +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + Text [ en-US ] = "Data"; + + FixedLine FL_DATA + { + Pos = MAP_APPFONT ( 4 , 40 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + }; + FixedText FT_RADIOLABELS + { + Pos = MAP_APPFONT ( 7 , 52 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 13, 24 ) ; + WordBreak = TRUE; + Group = TRUE; + Text [ en-US ] = "Which ~names do you want to give the option fields?"; + }; + Edit ET_RADIOLABELS + { + Pos = MAP_APPFONT ( 7 , 79 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 13, 12 ) ; + SVLook = TRUE ; + Border = TRUE ; + }; + PushButton PB_MOVETORIGHT + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 , 79 ) ; + Size = MAP_APPFONT ( ITEM_BUTTON_SIZE_X , ITEM_BUTTON_SIZE_Y ) ; + Text = "~>>"; + }; + PushButton PB_MOVETOLEFT + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 , 79 + ITEM_BUTTON_SIZE_Y + 3 ) ; + Size = MAP_APPFONT ( ITEM_BUTTON_SIZE_X , ITEM_BUTTON_SIZE_Y ) ; + Text = "~<<"; + }; + FixedText FT_RADIOBUTTONS + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + ITEM_BUTTON_SIZE_X / 2 + 6 , 52 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 6 - 7, 8 ) ; + Group = TRUE; + Text [ en-US ] = "~Option fields"; + }; + ListBox LB_RADIOBUTTONS + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + ITEM_BUTTON_SIZE_X / 2 + 6 , 79 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - WINDOW_HALF_SIZE_X - ITEM_BUTTON_SIZE_X / 2 - 6 - 7, WINDOW_SIZE_Y - 79 - 6 ) ; + SVLook = TRUE ; + Border = TRUE ; + AutoHScroll = TRUE ; + Sort = FALSE; + }; +}; + +TabPage RID_PAGE_DEFAULTFIELDSELECTION +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + Text [ en-US ] = "Default Field Selection"; + + FixedLine FL_DEFAULTSELECTION + { + Pos = MAP_APPFONT ( 4 , 3 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + }; + FixedText FT_DEFAULTSELECTION + { + Pos = MAP_APPFONT ( 7 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 24 ) ; + WordBreak = TRUE; + + Text [ en-US ] = "Should one option field be selected as a default?"; + }; + RadioButton RB_DEFSELECTION_YES + { + Pos = MAP_APPFONT ( 7 , 44 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 10 ) ; + Group = TRUE; + TabStop = TRUE; + Text [ en-US ] = "~Yes, the following:"; + }; + ListBox LB_DEFSELECTIONFIELD + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 42 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 14 ) ; + TabStop = TRUE; + SVLook = TRUE ; + Border = TRUE ; + DropDown = TRUE; + AutoHScroll = TRUE ; + Sort = FALSE; + }; + RadioButton RB_DEFSELECTION_NO + { + Pos = MAP_APPFONT ( 7 , 59 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 10 ) ; + TabStop = FALSE; + Text [ en-US ] = "No, one particular field is not going to be selected."; + }; +}; + +TabPage RID_PAGE_OPTIONVALUES +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + Text [ en-US ] = "Field Values"; + + FixedLine FL_OPTIONVALUES + { + Pos = MAP_APPFONT ( 4 , 3 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + }; + FixedText FT_OPTIONVALUES_EXPL + { + Pos = MAP_APPFONT ( 7 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 24 ) ; + WordBreak = TRUE; + Text [ en-US ] = "When you select an option, the option group is given a specific value."; + }; + FixedText FT_OPTIONVALUES + { + Pos = MAP_APPFONT ( 7 , 42 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 16 ) ; + WordBreak = TRUE; + Group = TRUE; + Text [ en-US ] = "Which ~value do you want to assign to each option?"; + }; + Edit ET_OPTIONVALUE + { + Pos = MAP_APPFONT ( 7 , 61 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 12 ) ; + SVLook = TRUE ; + Border = TRUE ; + TabStop = TRUE; + }; + FixedText FT_RADIOBUTTONS + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14 , 8 ) ; + Text [ en-US ] = "~Option fields"; + }; + ListBox LB_RADIOBUTTONS + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 26 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10 , WINDOW_SIZE_Y - 32 ) ; + SVLook = TRUE ; + Border = TRUE ; + AutoHScroll = TRUE ; + DropDown = FALSE; + }; +}; + +TabPage RID_PAGE_OPTIONS_FINAL +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + Text [ en-US ] = "Create Option Group"; + + FixedLine FL_NAMEIT + { + Pos = MAP_APPFONT ( 4 , 3 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + }; + FixedText FT_NAMEIT + { + Pos = MAP_APPFONT ( 7 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 16 ) ; + WordBreak = TRUE; + Text [ en-US ] = "Which ~caption is to be given to your option group?"; + }; + Edit ET_NAMEIT + { + Pos = MAP_APPFONT ( 7 , 34 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 12 ) ; + SVLook = TRUE ; + Border = TRUE ; + }; + FixedText FT_THATSALL + { + Pos = MAP_APPFONT ( 7 , WINDOW_SIZE_Y - 22 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14, 16 ) ; + WordBreak = TRUE; + Center = TRUE; + Text [ en-US ] = "These were all details needed to create the option group."; + }; +}; + +String RID_STR_GROUPWIZ_DBFIELD +{ + Text [ en-US ] = "You can either save the value of the option group in a database field or use it for a later action."; +}; + + diff --git a/extensions/source/dbpilots/groupboxwiz.cxx b/extensions/source/dbpilots/groupboxwiz.cxx new file mode 100644 index 000000000000..9956cfe86428 --- /dev/null +++ b/extensions/source/dbpilots/groupboxwiz.cxx @@ -0,0 +1,561 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "groupboxwiz.hxx" +#include "commonpagesdbp.hxx" +#include <tools/debug.hxx> +#include <vcl/svapp.hxx> +#include <vcl/msgbox.hxx> +#include "optiongrouplayouter.hxx" +#include "dbpilots.hrc" + + +//#define GBW_STATE_DATASELECTION 0 +#define GBW_STATE_OPTIONLIST 0 +#define GBW_STATE_DEFAULTOPTION 1 +#define GBW_STATE_OPTIONVALUES 2 +#define GBW_STATE_DBFIELD 3 +#define GBW_STATE_FINALIZE 4 + +//......................................................................... +namespace dbp +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::form; + using namespace ::svt; + + //===================================================================== + //= OGroupBoxWizard + //===================================================================== + //--------------------------------------------------------------------- + OGroupBoxWizard::OGroupBoxWizard( Window* _pParent, + const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB ) + :OControlWizard(_pParent, ModuleRes(RID_DLG_GROUPBOXWIZARD), _rxObjectModel, _rxORB) + ,m_bVisitedDefault(sal_False) + ,m_bVisitedDB(sal_False) + { + initControlSettings(&m_aSettings); + + m_pPrevPage->SetHelpId(HID_GROUPWIZARD_PREVIOUS); + m_pNextPage->SetHelpId(HID_GROUPWIZARD_NEXT); + m_pCancel->SetHelpId(HID_GROUPWIZARD_CANCEL); + m_pFinish->SetHelpId(HID_GROUPWIZARD_FINISH); + } + + //--------------------------------------------------------------------- + sal_Bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId) + { + return FormComponentType::GROUPBOX == _nClassId; + } + + //--------------------------------------------------------------------- + OWizardPage* OGroupBoxWizard::createPage(::svt::WizardTypes::WizardState _nState) + { + switch (_nState) + { +// case GBW_STATE_DATASELECTION: +// return new OTableSelectionPage(this); +// + case GBW_STATE_OPTIONLIST: + return new ORadioSelectionPage(this); + + case GBW_STATE_DEFAULTOPTION: + return new ODefaultFieldSelectionPage(this); + + case GBW_STATE_OPTIONVALUES: + return new OOptionValuesPage(this); + + case GBW_STATE_DBFIELD: + return new OOptionDBFieldPage(this); + + case GBW_STATE_FINALIZE: + return new OFinalizeGBWPage(this); + } + + return NULL; + } + + //--------------------------------------------------------------------- + WizardTypes::WizardState OGroupBoxWizard::determineNextState( ::svt::WizardTypes::WizardState _nCurrentState ) const + { + switch (_nCurrentState) + { +// case GBW_STATE_DATASELECTION: +// return GBW_STATE_OPTIONLIST; +// + case GBW_STATE_OPTIONLIST: + return GBW_STATE_DEFAULTOPTION; + + case GBW_STATE_DEFAULTOPTION: + return GBW_STATE_OPTIONVALUES; + + case GBW_STATE_OPTIONVALUES: + if (getContext().aFieldNames.getLength()) + return GBW_STATE_DBFIELD; + else + return GBW_STATE_FINALIZE; + + case GBW_STATE_DBFIELD: + return GBW_STATE_FINALIZE; + } + + return WZS_INVALID_STATE; + } + + //--------------------------------------------------------------------- + void OGroupBoxWizard::enterState(::svt::WizardTypes::WizardState _nState) + { + // some stuff to do before calling the base class (modifying our settings) + switch (_nState) + { + case GBW_STATE_DEFAULTOPTION: + if (!m_bVisitedDefault) + { // assume that the first of the radio buttons should be selected + DBG_ASSERT(m_aSettings.aLabels.size(), "OGroupBoxWizard::enterState: should never have reached this state!"); + m_aSettings.sDefaultField = m_aSettings.aLabels[0]; + } + m_bVisitedDefault = sal_True; + break; + + case GBW_STATE_DBFIELD: + if (!m_bVisitedDB) + { // try to generate a default for the DB field + // (simply use the first field in the DB names collection) + if (getContext().aFieldNames.getLength()) + m_aSettings.sDBField = getContext().aFieldNames[0]; + } + m_bVisitedDB = sal_True; + break; + } + + // setting the def button .... to be done before the base class is called, too, 'cause the base class + // calls the pages, which are allowed to override our def button behaviour + defaultButton(GBW_STATE_FINALIZE == _nState ? WZB_FINISH : WZB_NEXT); + + // allow "finish" on the last page only + enableButtons(WZB_FINISH, GBW_STATE_FINALIZE == _nState); + // allow previous on all pages but the first one + enableButtons(WZB_PREVIOUS, GBW_STATE_OPTIONLIST != _nState); + // allow next on all pages but the last one + enableButtons(WZB_NEXT, GBW_STATE_FINALIZE != _nState); + + OControlWizard::enterState(_nState); + } + + //--------------------------------------------------------------------- + void OGroupBoxWizard::createRadios() + { + try + { + OOptionGroupLayouter aLayouter(getServiceFactory()); + aLayouter.doLayout(getContext(), getSettings()); + } + catch(Exception&) + { + DBG_ERROR("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!"); + } + } + + //--------------------------------------------------------------------- + sal_Bool OGroupBoxWizard::onFinish() + { + // commit the basic control setttings + commitControlSettings(&m_aSettings); + + // create the radio buttons + createRadios(); + + return OControlWizard::onFinish(); + } + + //===================================================================== + //= ORadioSelectionPage + //===================================================================== + //--------------------------------------------------------------------- + ORadioSelectionPage::ORadioSelectionPage( OControlWizard* _pParent ) + :OGBWPage(_pParent, ModuleRes(RID_PAGE_GROUPRADIOSELECTION)) + ,m_aFrame (this, ModuleRes(FL_DATA)) + ,m_aRadioNameLabel (this, ModuleRes(FT_RADIOLABELS)) + ,m_aRadioName (this, ModuleRes(ET_RADIOLABELS)) + ,m_aMoveRight (this, ModuleRes(PB_MOVETORIGHT)) + ,m_aMoveLeft (this, ModuleRes(PB_MOVETOLEFT)) + ,m_aExistingRadiosLabel (this, ModuleRes(FT_RADIOBUTTONS)) + ,m_aExistingRadios (this, ModuleRes(LB_RADIOBUTTONS)) + { + FreeResource(); + + if (getContext().aFieldNames.getLength()) + { + enableFormDatasourceDisplay(); + } + else + { + adjustControlForNoDSDisplay(&m_aFrame); + adjustControlForNoDSDisplay(&m_aRadioNameLabel); + adjustControlForNoDSDisplay(&m_aRadioName); + adjustControlForNoDSDisplay(&m_aMoveRight); + adjustControlForNoDSDisplay(&m_aMoveLeft); + adjustControlForNoDSDisplay(&m_aExistingRadiosLabel); + adjustControlForNoDSDisplay(&m_aExistingRadios, sal_True); + } + + m_aMoveLeft.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry)); + m_aMoveRight.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry)); + m_aRadioName.SetModifyHdl(LINK(this, ORadioSelectionPage, OnNameModified)); + m_aExistingRadios.SetSelectHdl(LINK(this, ORadioSelectionPage, OnEntrySelected)); + + implCheckMoveButtons(); + m_aExistingRadios.EnableMultiSelection(sal_True); + + getDialog()->defaultButton(&m_aMoveRight); + } + + //--------------------------------------------------------------------- + void ORadioSelectionPage::ActivatePage() + { + OGBWPage::ActivatePage(); + m_aRadioName.GrabFocus(); + } + + //--------------------------------------------------------------------- + void ORadioSelectionPage::initializePage() + { + OGBWPage::initializePage(); + + m_aRadioName.SetText(String()); + + // no need to initialize the list of radios here + // (we're the only one affecting this special setting, so it will be in the same state as last time this + // page was commited) + + implCheckMoveButtons(); + } + + //--------------------------------------------------------------------- + sal_Bool ORadioSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OGBWPage::commitPage(_eReason)) + return sal_False; + + // copy the names of the radio buttons to be inserted + // and initialize the values + OOptionGroupSettings& rSettings = getSettings(); + rSettings.aLabels.clear(); + rSettings.aValues.clear(); + rSettings.aLabels.reserve(m_aExistingRadios.GetEntryCount()); + rSettings.aValues.reserve(m_aExistingRadios.GetEntryCount()); + for (::svt::WizardTypes::WizardState i=0; i<m_aExistingRadios.GetEntryCount(); ++i) + { + rSettings.aLabels.push_back(m_aExistingRadios.GetEntry(i)); + rSettings.aValues.push_back(String::CreateFromInt32((sal_Int32)(i + 1))); + } + + return sal_True; + } + + //--------------------------------------------------------------------- + IMPL_LINK( ORadioSelectionPage, OnMoveEntry, PushButton*, _pButton ) + { + sal_Bool bMoveLeft = (&m_aMoveLeft == _pButton); + if (bMoveLeft) + { + while (m_aExistingRadios.GetSelectEntryCount()) + m_aExistingRadios.RemoveEntry(m_aExistingRadios.GetSelectEntryPos(0)); + } + else + { + m_aExistingRadios.InsertEntry(m_aRadioName.GetText()); + m_aRadioName.SetText(String()); + } + + implCheckMoveButtons(); + + //adjust the focus + if (bMoveLeft) + m_aExistingRadios.GrabFocus(); + else + m_aRadioName.GrabFocus(); + return 0L; + } + + //--------------------------------------------------------------------- + IMPL_LINK( ORadioSelectionPage, OnEntrySelected, ListBox*, /*_pList*/ ) + { + implCheckMoveButtons(); + return 0L; + } + + //--------------------------------------------------------------------- + IMPL_LINK( ORadioSelectionPage, OnNameModified, Edit*, /*_pList*/ ) + { + implCheckMoveButtons(); + return 0L; + } + + //--------------------------------------------------------------------- + bool ORadioSelectionPage::canAdvance() const + { + return 0 != m_aExistingRadios.GetEntryCount(); + } + + //--------------------------------------------------------------------- + void ORadioSelectionPage::implCheckMoveButtons() + { + sal_Bool bHaveSome = (0 != m_aExistingRadios.GetEntryCount()); + sal_Bool bSelectedSome = (0 != m_aExistingRadios.GetSelectEntryCount()); + sal_Bool bUnfinishedInput = (0 != m_aRadioName.GetText().Len()); + + m_aMoveLeft.Enable(bSelectedSome); + m_aMoveRight.Enable(bUnfinishedInput); + + getDialog()->enableButtons(WZB_NEXT, bHaveSome); + + if (bUnfinishedInput) + { + if (0 == (m_aMoveRight.GetStyle() & WB_DEFBUTTON)) + getDialog()->defaultButton(&m_aMoveRight); + } + else + { + if (WB_DEFBUTTON == (m_aMoveRight.GetStyle() & WB_DEFBUTTON)) + getDialog()->defaultButton(WZB_NEXT); + } + } + + //===================================================================== + //= ODefaultFieldSelectionPage + //===================================================================== + //--------------------------------------------------------------------- + ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard* _pParent ) + :OMaybeListSelectionPage(_pParent, ModuleRes(RID_PAGE_DEFAULTFIELDSELECTION)) + ,m_aFrame (this, ModuleRes(FL_DEFAULTSELECTION)) + ,m_aDefaultSelectionLabel (this, ModuleRes(FT_DEFAULTSELECTION)) + ,m_aDefSelYes (this, ModuleRes(RB_DEFSELECTION_YES)) + ,m_aDefSelNo (this, ModuleRes(RB_DEFSELECTION_NO)) + ,m_aDefSelection (this, ModuleRes(LB_DEFSELECTIONFIELD)) + { + FreeResource(); + + announceControls(m_aDefSelYes, m_aDefSelNo, m_aDefSelection); + m_aDefSelection.SetDropDownLineCount(10); + } + + //--------------------------------------------------------------------- + void ODefaultFieldSelectionPage::initializePage() + { + OMaybeListSelectionPage::initializePage(); + + const OOptionGroupSettings& rSettings = getSettings(); + + // fill the listbox + m_aDefSelection.Clear(); + for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin(); + aLoop != rSettings.aLabels.end(); + ++aLoop + ) + m_aDefSelection.InsertEntry(*aLoop); + + + implInitialize(rSettings.sDefaultField); + } + + //--------------------------------------------------------------------- + sal_Bool ODefaultFieldSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OMaybeListSelectionPage::commitPage(_eReason)) + return sal_False; + + OOptionGroupSettings& rSettings = getSettings(); + implCommit(rSettings.sDefaultField); + + return sal_True; + } + + //===================================================================== + //= OOptionValuesPage + //===================================================================== + //--------------------------------------------------------------------- + OOptionValuesPage::OOptionValuesPage( OControlWizard* _pParent ) + :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONVALUES)) + ,m_aFrame (this, ModuleRes(FL_OPTIONVALUES)) + ,m_aDescription (this, ModuleRes(FT_OPTIONVALUES_EXPL)) + ,m_aValueLabel (this, ModuleRes(FT_OPTIONVALUES)) + ,m_aValue (this, ModuleRes(ET_OPTIONVALUE)) + ,m_aOptionsLabel (this, ModuleRes(FT_RADIOBUTTONS)) + ,m_aOptions (this, ModuleRes(LB_RADIOBUTTONS)) + ,m_nLastSelection((::svt::WizardTypes::WizardState)-1) + { + FreeResource(); + + m_aOptions.SetSelectHdl(LINK(this, OOptionValuesPage, OnOptionSelected)); + } + + //--------------------------------------------------------------------- + IMPL_LINK( OOptionValuesPage, OnOptionSelected, ListBox*, /*NOTINTERESTEDIN*/ ) + { + implTraveledOptions(); + return 0L; + } + + //--------------------------------------------------------------------- + void OOptionValuesPage::ActivatePage() + { + OGBWPage::ActivatePage(); + m_aValue.GrabFocus(); + } + + //--------------------------------------------------------------------- + void OOptionValuesPage::implTraveledOptions() + { + if ((::svt::WizardTypes::WizardState)-1 != m_nLastSelection) + { + // save the value for the last option + DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!"); + m_aUncommittedValues[m_nLastSelection] = m_aValue.GetText(); + } + + m_nLastSelection = m_aOptions.GetSelectEntryPos(); + DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!"); + m_aValue.SetText(m_aUncommittedValues[m_nLastSelection]); + } + + //--------------------------------------------------------------------- + void OOptionValuesPage::initializePage() + { + OGBWPage::initializePage(); + + const OOptionGroupSettings& rSettings = getSettings(); + DBG_ASSERT(rSettings.aLabels.size(), "OOptionValuesPage::initializePage: no options!!"); + DBG_ASSERT(rSettings.aLabels.size() == rSettings.aValues.size(), "OOptionValuesPage::initializePage: inconsistent data!"); + + // fill the list with all available options + m_aOptions.Clear(); + m_nLastSelection = -1; + for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin(); + aLoop != rSettings.aLabels.end(); + ++aLoop + ) + m_aOptions.InsertEntry(*aLoop); + + // remember the values ... can't set them directly in the settings without the explicit commit call + // so we need have a copy of the values + m_aUncommittedValues = rSettings.aValues; + + // select the first entry + m_aOptions.SelectEntryPos(0); + implTraveledOptions(); + } + + //--------------------------------------------------------------------- + sal_Bool OOptionValuesPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OGBWPage::commitPage(_eReason)) + return sal_False; + + OOptionGroupSettings& rSettings = getSettings(); + + // commit the current value + implTraveledOptions(); + // copy the uncommitted values + rSettings.aValues = m_aUncommittedValues; + + return sal_True; + } + + //===================================================================== + //= OOptionDBFieldPage + //===================================================================== + //--------------------------------------------------------------------- + OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard* _pParent ) + :ODBFieldPage(_pParent) + { + setDescriptionText(String(ModuleRes(RID_STR_GROUPWIZ_DBFIELD))); + } + + //--------------------------------------------------------------------- + String& OOptionDBFieldPage::getDBFieldSetting() + { + return getSettings().sDBField; + } + + //===================================================================== + //= OFinalizeGBWPage + //===================================================================== + //--------------------------------------------------------------------- + OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard* _pParent ) + :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONS_FINAL)) + ,m_aFrame (this, ModuleRes(FL_NAMEIT)) + ,m_aNameLabel (this, ModuleRes(FT_NAMEIT)) + ,m_aName (this, ModuleRes(ET_NAMEIT)) + ,m_aThatsAll (this, ModuleRes(FT_THATSALL)) + { + FreeResource(); + } + + //--------------------------------------------------------------------- + void OFinalizeGBWPage::ActivatePage() + { + OGBWPage::ActivatePage(); + m_aName.GrabFocus(); + } + + //--------------------------------------------------------------------- + bool OFinalizeGBWPage::canAdvance() const + { + return false; + } + + //--------------------------------------------------------------------- + void OFinalizeGBWPage::initializePage() + { + OGBWPage::initializePage(); + + const OOptionGroupSettings& rSettings = getSettings(); + m_aName.SetText(rSettings.sControlLabel); + } + + //--------------------------------------------------------------------- + sal_Bool OFinalizeGBWPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OGBWPage::commitPage(_eReason)) + return sal_False; + + getSettings().sControlLabel = m_aName.GetText(); + + return sal_True; + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/groupboxwiz.hxx b/extensions/source/dbpilots/groupboxwiz.hxx new file mode 100644 index 000000000000..de0f9767f3a4 --- /dev/null +++ b/extensions/source/dbpilots/groupboxwiz.hxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_GROUPBOXWIZ_HXX_ +#define _EXTENSIONS_DBP_GROUPBOXWIZ_HXX_ + +#include "controlwizard.hxx" +#include "commonpagesdbp.hxx" + +//......................................................................... +namespace dbp +{ +//......................................................................... + + //===================================================================== + //= OOptionGroupSettings + //===================================================================== + struct OOptionGroupSettings : public OControlWizardSettings + { + StringArray aLabels; + StringArray aValues; + String sDefaultField; + String sDBField; + String sName; + }; + + //===================================================================== + //= OGroupBoxWizard + //===================================================================== + class OGroupBoxWizard : public OControlWizard + { + protected: + OOptionGroupSettings m_aSettings; + + sal_Bool m_bVisitedDefault : 1; + sal_Bool m_bVisitedDB : 1; + + public: + OGroupBoxWizard( + Window* _pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObjectModel, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB + ); + + OOptionGroupSettings& getSettings() { return m_aSettings; } + + protected: + // OWizardMachine overridables + virtual ::svt::OWizardPage* createPage( WizardState _nState ); + virtual WizardState determineNextState( WizardState _nCurrentState ) const; + virtual void enterState( WizardState _nState ); + virtual sal_Bool onFinish(); + + virtual sal_Bool approveControl(sal_Int16 _nClassId); + + protected: + void createRadios(); + }; + + //===================================================================== + //= OGBWPage + //===================================================================== + class OGBWPage : public OControlWizardPage + { + public: + OGBWPage( OControlWizard* _pParent, const ResId& _rId ) : OControlWizardPage(_pParent, _rId) { } + + protected: + OOptionGroupSettings& getSettings() { return static_cast<OGroupBoxWizard*>(getDialog())->getSettings(); } + }; + + //===================================================================== + //= ORadioSelectionPage + //===================================================================== + class ORadioSelectionPage : public OGBWPage + { + protected: + FixedLine m_aFrame; + FixedText m_aRadioNameLabel; + Edit m_aRadioName; + PushButton m_aMoveRight; + PushButton m_aMoveLeft; + FixedText m_aExistingRadiosLabel; + ListBox m_aExistingRadios; + + public: + ORadioSelectionPage( OControlWizard* _pParent ); + + protected: + // TabPage overridables + void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + virtual bool canAdvance() const; + + DECL_LINK( OnMoveEntry, PushButton* ); + DECL_LINK( OnEntrySelected, ListBox* ); + DECL_LINK( OnNameModified, Edit* ); + + void implCheckMoveButtons(); + }; + + //===================================================================== + //= ODefaultFieldSelectionPage + //===================================================================== + class ODefaultFieldSelectionPage : public OMaybeListSelectionPage + { + protected: + FixedLine m_aFrame; + FixedText m_aDefaultSelectionLabel; + RadioButton m_aDefSelYes; + RadioButton m_aDefSelNo; + ListBox m_aDefSelection; + + public: + ODefaultFieldSelectionPage( OControlWizard* _pParent ); + + protected: + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + + OOptionGroupSettings& getSettings() { return static_cast<OGroupBoxWizard*>(getDialog())->getSettings(); } + }; + + //===================================================================== + //= OOptionValuesPage + //===================================================================== + class OOptionValuesPage : public OGBWPage + { + protected: + FixedLine m_aFrame; + FixedText m_aDescription; + FixedText m_aValueLabel; + Edit m_aValue; + FixedText m_aOptionsLabel; + ListBox m_aOptions; + + StringArray m_aUncommittedValues; + ::svt::WizardTypes::WizardState + m_nLastSelection; + + public: + OOptionValuesPage( OControlWizard* _pParent ); + + protected: + // TabPage overridables + void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + + void implTraveledOptions(); + + DECL_LINK( OnOptionSelected, ListBox* ); + }; + + //===================================================================== + //= OOptionDBFieldPage + //===================================================================== + class OOptionDBFieldPage : public ODBFieldPage + { + public: + OOptionDBFieldPage( OControlWizard* _pParent ); + + protected: + OOptionGroupSettings& getSettings() { return static_cast<OGroupBoxWizard*>(getDialog())->getSettings(); } + + // ODBFieldPage overridables + virtual String& getDBFieldSetting(); + }; + + //===================================================================== + //= OFinalizeGBWPage + //===================================================================== + class OFinalizeGBWPage : public OGBWPage + { + protected: + FixedLine m_aFrame; + FixedText m_aNameLabel; + Edit m_aName; + FixedText m_aThatsAll; + + public: + OFinalizeGBWPage( OControlWizard* _pParent ); + + protected: + // TabPage overridables + void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + virtual bool canAdvance() const; + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBP_GROUPBOXWIZ_HXX_ + diff --git a/extensions/source/dbpilots/listcombopages.src b/extensions/source/dbpilots/listcombopages.src new file mode 100644 index 000000000000..eb83140de316 --- /dev/null +++ b/extensions/source/dbpilots/listcombopages.src @@ -0,0 +1,203 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_DBPRESID_HRC_ +#include "dbpresid.hrc" +#endif + +TabPage RID_PAGE_LCW_CONTENTSELECTION_TABLE +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + + Text [ en-US ] = "Table Selection"; + + FixedLine FL_FRAME + { + Pos = MAP_APPFONT ( 4 , 40 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + Text [ en-US ] = "Control"; + }; + + FixedText FT_SELECTTABLE_LABEL + { + Pos = MAP_APPFONT ( 7 , 52 ) ; + Size = MAP_APPFONT ( 120, WINDOW_SIZE_Y - 21 ) ; + WordBreak = TRUE; + Group = TRUE; + Text [ en-US ] = "On the right side, you see all the tables from the data source of the form.\n\n\nChoose the table from which the data should be used as basis for the list content:"; + }; + ListBox LB_SELECTTABLE + { + Pos = MAP_APPFONT ( 130 , 52 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 130 - 7, WINDOW_SIZE_Y - 52 - 6 ) ; + SVLook = TRUE ; + Border = TRUE ; + AutoHScroll = TRUE ; + Sort = FALSE; + DropDown = FALSE; + }; +}; + +TabPage RID_PAGE_LCW_CONTENTSELECTION_FIELD +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + + Text [ en-US ] = "Field Selection"; + + FixedLine FL_FRAME + { + Pos = MAP_APPFONT ( 4 , 3 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + }; + + FixedText FT_TABLEFIELDS + { + Pos = MAP_APPFONT ( 7 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 3, 8 ) ; + WordBreak = TRUE; + Group = TRUE; + Text [ en-US ] = "Existing fields"; + }; + ListBox LB_SELECTFIELD + { + Pos = MAP_APPFONT ( 7 , 26 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, WINDOW_SIZE_Y - 32 ) ; + SVLook = TRUE ; + Border = TRUE ; + AutoHScroll = TRUE ; + Sort = FALSE; + DropDown = FALSE; + }; + FixedText FT_DISPLAYEDFIELD + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 15 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 8 ) ; + Text [ en-US ] = "Display field"; + }; + Edit ET_DISPLAYEDFIELD + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 26 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 12 ) ; + SVLook = TRUE ; + Border = TRUE ; + ReadOnly = TRUE; + }; + FixedText FT_CONTENTFIELD_INFO + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 45 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, WINDOW_SIZE_Y - 51 ) ; + WordBreak = TRUE; + }; + String STR_FIELDINFO_COMBOBOX + { + Text [ en-US ] = "The contents of the field selected will be shown in the combo box list."; + }; + + String STR_FIELDINFO_LISTBOX + { + Text [ en-US ] = "The contents of the selected field will be shown in the list box if the linked fields are identical."; + }; +}; + +TabPage RID_PAGE_LCW_FIELDLINK +{ + SVLook = TRUE ; + Size = MAP_APPFONT ( WINDOW_SIZE_X , WINDOW_SIZE_Y ) ; + + Text [ en-US ] = "Field Link"; + + FixedText FT_FIELDLINK_DESC + { + Pos = MAP_APPFONT ( 7 , 6 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 14 , 16 ) ; + WordBreak = TRUE; + Text [ en-US ] = "This is where you select fields with matching contents so that the value from the display field will be shown."; + }; + FixedLine FL_FRAME + { + Pos = MAP_APPFONT ( 4 , 25 ) ; + Size = MAP_APPFONT ( WINDOW_SIZE_X - 8 , 8 ) ; + }; + FixedText FT_VALUELISTFIELD + { + Pos = MAP_APPFONT ( 7 , 37 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 8 ) ; + Group = TRUE; + Text [ en-US ] = "Field from the ~Value Table"; + }; + ComboBox CMB_VALUELISTFIELD + { + Pos = MAP_APPFONT ( 7 , 48 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, WINDOW_SIZE_Y - 54 ) ; + SVLook = TRUE ; + Border = TRUE ; + DropDown = FALSE; + Sort = FALSE; + AutoHScroll = TRUE; + }; + FixedText FT_TABLEFIELD + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 37 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, 8 ) ; + Group = TRUE; + Text [ en-US ] = "Field from the ~List Table"; + }; + ComboBox CMB_TABLEFIELD + { + Pos = MAP_APPFONT ( WINDOW_HALF_SIZE_X + 3 , 48 ) ; + Size = MAP_APPFONT ( WINDOW_HALF_SIZE_X - 10, WINDOW_SIZE_Y - 54 ) ; + SVLook = TRUE ; + Border = TRUE ; + DropDown = FALSE; + Sort = FALSE; + AutoHScroll = TRUE; + }; +}; + +String RID_STR_COMBOWIZ_DBFIELD +{ + Text [ en-US ] = "You can either save the value of the combo box in a database field or use it for display purposes."; +}; + + + + + + + + + + + + + + + + + diff --git a/extensions/source/dbpilots/listcombowizard.cxx b/extensions/source/dbpilots/listcombowizard.cxx new file mode 100644 index 000000000000..bf3f56781d63 --- /dev/null +++ b/extensions/source/dbpilots/listcombowizard.cxx @@ -0,0 +1,562 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "listcombowizard.hxx" +#include "commonpagesdbp.hxx" +#include <com/sun/star/sdbc/XConnection.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/form/ListSourceType.hpp> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <tools/debug.hxx> +#include <vcl/msgbox.hxx> +#include <connectivity/dbtools.hxx> +#include "dbpilots.hrc" +#include <comphelper/extract.hxx> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::form; + using namespace ::svt; + using namespace ::dbtools; + + //===================================================================== + //= OListComboWizard + //===================================================================== + //--------------------------------------------------------------------- + OListComboWizard::OListComboWizard( Window* _pParent, + const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB ) + :OControlWizard(_pParent, ModuleRes(RID_DLG_LISTCOMBOWIZARD), _rxObjectModel, _rxORB) + ,m_bListBox(sal_False) + ,m_bHadDataSelection(sal_True) + { + initControlSettings(&m_aSettings); + + m_pPrevPage->SetHelpId(HID_LISTWIZARD_PREVIOUS); + m_pNextPage->SetHelpId(HID_LISTWIZARD_NEXT); + m_pCancel->SetHelpId(HID_LISTWIZARD_CANCEL); + m_pFinish->SetHelpId(HID_LISTWIZARD_FINISH); + + // if we do not need the data source selection page ... + if (!needDatasourceSelection()) + { // ... skip it! + skip(1); + m_bHadDataSelection = sal_False; + } + } + + //--------------------------------------------------------------------- + sal_Bool OListComboWizard::approveControl(sal_Int16 _nClassId) + { + switch (_nClassId) + { + case FormComponentType::LISTBOX: + m_bListBox = sal_True; + setTitleBase(String(ModuleRes(RID_STR_LISTWIZARD_TITLE))); + return sal_True; + case FormComponentType::COMBOBOX: + m_bListBox = sal_False; + setTitleBase(String(ModuleRes(RID_STR_COMBOWIZARD_TITLE))); + return sal_True; + } + return sal_False; + } + + //--------------------------------------------------------------------- + OWizardPage* OListComboWizard::createPage(WizardState _nState) + { + switch (_nState) + { + case LCW_STATE_DATASOURCE_SELECTION: + return new OTableSelectionPage(this); + case LCW_STATE_TABLESELECTION: + return new OContentTableSelection(this); + case LCW_STATE_FIELDSELECTION: + return new OContentFieldSelection(this); + case LCW_STATE_FIELDLINK: + return new OLinkFieldsPage(this); + case LCW_STATE_COMBODBFIELD: + return new OComboDBFieldPage(this); + } + + return NULL; + } + + //--------------------------------------------------------------------- + WizardTypes::WizardState OListComboWizard::determineNextState( WizardState _nCurrentState ) const + { + switch (_nCurrentState) + { + case LCW_STATE_DATASOURCE_SELECTION: + return LCW_STATE_TABLESELECTION; + case LCW_STATE_TABLESELECTION: + return LCW_STATE_FIELDSELECTION; + case LCW_STATE_FIELDSELECTION: + return getFinalState(); + } + + return WZS_INVALID_STATE; + } + + //--------------------------------------------------------------------- + void OListComboWizard::enterState(WizardState _nState) + { + OControlWizard::enterState(_nState); + + enableButtons(WZB_PREVIOUS, m_bHadDataSelection ? (LCW_STATE_DATASOURCE_SELECTION < _nState) : LCW_STATE_TABLESELECTION < _nState); + enableButtons(WZB_NEXT, getFinalState() != _nState); + if (_nState < getFinalState()) + enableButtons(WZB_FINISH, sal_False); + + if (getFinalState() == _nState) + defaultButton(WZB_FINISH); + } + + //--------------------------------------------------------------------- + sal_Bool OListComboWizard::leaveState(WizardState _nState) + { + if (!OControlWizard::leaveState(_nState)) + return sal_False; + + if (getFinalState() == _nState) + defaultButton(WZB_NEXT); + + return sal_True; + } + + //--------------------------------------------------------------------- + void OListComboWizard::implApplySettings() + { + try + { + // for quoting identifiers, we need the connection meta data + Reference< XConnection > xConn = getFormConnection(); + DBG_ASSERT(xConn.is(), "OListComboWizard::implApplySettings: no connection, unable to quote!"); + Reference< XDatabaseMetaData > xMetaData; + if (xConn.is()) + xMetaData = xConn->getMetaData(); + + // do some quotings + if (xMetaData.is()) + { + ::rtl::OUString sQuoteString = xMetaData->getIdentifierQuoteString(); + if (isListBox()) // only when we have a listbox this should be not empty + getSettings().sLinkedListField = quoteName(sQuoteString, getSettings().sLinkedListField); + + ::rtl::OUString sCatalog, sSchema, sName; + ::dbtools::qualifiedNameComponents( xMetaData, getSettings().sListContentTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation ); + getSettings().sListContentTable = ::dbtools::composeTableNameForSelect( xConn, sCatalog, sSchema, sName ); + + getSettings().sListContentField = quoteName(sQuoteString, getSettings().sListContentField); + } + + // ListSourceType: SQL + getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("ListSourceType"), makeAny((sal_Int32)ListSourceType_SQL)); + + if (isListBox()) + { + // BoundColumn: 1 + getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("BoundColumn"), makeAny((sal_Int16)1)); + + // build the statement to set as list source + String sStatement; + sStatement.AppendAscii("SELECT "); + sStatement += getSettings().sListContentField; + sStatement.AppendAscii(", "); + sStatement += getSettings().sLinkedListField; + sStatement.AppendAscii(" FROM "); + sStatement += getSettings().sListContentTable; + Sequence< ::rtl::OUString > aListSource(1); + aListSource[0] = sStatement; + getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("ListSource"), makeAny(aListSource)); + } + else + { + // build the statement to set as list source + String sStatement; + sStatement.AppendAscii("SELECT DISTINCT "); + sStatement += getSettings().sListContentField; + sStatement.AppendAscii(" FROM "); + sStatement += getSettings().sListContentTable; + getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("ListSource"), makeAny(::rtl::OUString(sStatement))); + } + + // the bound field + getContext().xObjectModel->setPropertyValue(::rtl::OUString::createFromAscii("DataField"), makeAny(::rtl::OUString(getSettings().sLinkedFormField))); + } + catch(Exception&) + { + DBG_ERROR("OListComboWizard::implApplySettings: could not set the property values for the listbox!"); + } + } + + //--------------------------------------------------------------------- + sal_Bool OListComboWizard::onFinish() + { + if ( !OControlWizard::onFinish() ) + return sal_False; + + implApplySettings(); + return sal_True; + } + + //===================================================================== + //= OLCPage + //===================================================================== + //--------------------------------------------------------------------- + Reference< XNameAccess > OLCPage::getTables(sal_Bool _bNeedIt) + { + Reference< XConnection > xConn = getFormConnection(); + DBG_ASSERT(!_bNeedIt || xConn.is(), "OLCPage::getTables: should have an active connection when reaching this page!"); + (void)_bNeedIt; + + Reference< XTablesSupplier > xSuppTables(xConn, UNO_QUERY); + Reference< XNameAccess > xTables; + if (xSuppTables.is()) + xTables = xSuppTables->getTables(); + + DBG_ASSERT(!_bNeedIt || xTables.is() || !xConn.is(), "OLCPage::getTables: got no tables from the connection!"); + + return xTables; + } + + //--------------------------------------------------------------------- + Sequence< ::rtl::OUString > OLCPage::getTableFields(sal_Bool _bNeedIt) + { + Reference< XNameAccess > xTables = getTables(_bNeedIt); + Sequence< ::rtl::OUString > aColumnNames; + if (xTables.is()) + { + try + { + // the list table as XColumnsSupplier + Reference< XColumnsSupplier > xSuppCols; + xTables->getByName(getSettings().sListContentTable) >>= xSuppCols; + DBG_ASSERT(!_bNeedIt || xSuppCols.is(), "OLCPage::getTableFields: no columns supplier!"); + + // the columns + Reference< XNameAccess > xColumns; + if (xSuppCols.is()) + xColumns = xSuppCols->getColumns(); + + // the column names + if (xColumns.is()) + aColumnNames = xColumns->getElementNames(); + } + catch(Exception&) + { + DBG_ASSERT(!_bNeedIt, "OLinkFieldsPage::initializePage: caught an exception while retrieving the columns!"); + } + } + return aColumnNames; + } + + //===================================================================== + //= OContentTableSelection + //===================================================================== + //--------------------------------------------------------------------- + OContentTableSelection::OContentTableSelection( OListComboWizard* _pParent ) + :OLCPage(_pParent, ModuleRes(RID_PAGE_LCW_CONTENTSELECTION_TABLE)) + ,m_aFrame (this, ModuleRes(FL_FRAME)) + ,m_aSelectTableLabel (this, ModuleRes(FT_SELECTTABLE_LABEL)) + ,m_aSelectTable (this, ModuleRes(LB_SELECTTABLE)) + { + FreeResource(); + + enableFormDatasourceDisplay(); + + m_aSelectTable.SetDoubleClickHdl(LINK(this, OContentTableSelection, OnTableDoubleClicked)); + m_aSelectTable.SetSelectHdl(LINK(this, OContentTableSelection, OnTableSelected)); + } + + //--------------------------------------------------------------------- + void OContentTableSelection::ActivatePage() + { + OLCPage::ActivatePage(); + m_aSelectTable.GrabFocus(); + } + + //--------------------------------------------------------------------- + bool OContentTableSelection::canAdvance() const + { + if (!OLCPage::canAdvance()) + return false; + + return 0 != m_aSelectTable.GetSelectEntryCount(); + } + + //--------------------------------------------------------------------- + IMPL_LINK( OContentTableSelection, OnTableSelected, ListBox*, /*_pListBox*/ ) + { + updateDialogTravelUI(); + return 0L; + } + + //--------------------------------------------------------------------- + IMPL_LINK( OContentTableSelection, OnTableDoubleClicked, ListBox*, _pListBox ) + { + if (_pListBox->GetSelectEntryCount()) + getDialog()->travelNext(); + return 0L; + } + + //--------------------------------------------------------------------- + void OContentTableSelection::initializePage() + { + OLCPage::initializePage(); + + // fill the list with the table name + m_aSelectTable.Clear(); + try + { + Reference< XNameAccess > xTables = getTables(sal_True); + Sequence< ::rtl::OUString > aTableNames; + if (xTables.is()) + aTableNames = xTables->getElementNames(); + fillListBox(m_aSelectTable, aTableNames); + } + catch(Exception&) + { + DBG_ERROR("OContentTableSelection::initializePage: could not retrieve the table names!"); + } + + m_aSelectTable.SelectEntry(getSettings().sListContentTable); + } + + //--------------------------------------------------------------------- + sal_Bool OContentTableSelection::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OLCPage::commitPage(_eReason)) + return sal_False; + + OListComboSettings& rSettings = getSettings(); + rSettings.sListContentTable = m_aSelectTable.GetSelectEntry(); + if (!rSettings.sListContentTable.Len() && (::svt::WizardTypes::eTravelBackward != _eReason)) + // need to select a table + return sal_False; + + return sal_True; + } + + //===================================================================== + //= OContentFieldSelection + //===================================================================== + //--------------------------------------------------------------------- + OContentFieldSelection::OContentFieldSelection( OListComboWizard* _pParent ) + :OLCPage(_pParent, ModuleRes(RID_PAGE_LCW_CONTENTSELECTION_FIELD)) + ,m_aFrame (this, ModuleRes(FL_FRAME)) + ,m_aTableFields (this, ModuleRes(FT_TABLEFIELDS)) + ,m_aSelectTableField (this, ModuleRes(LB_SELECTFIELD)) + ,m_aDisplayedFieldLabel (this, ModuleRes(FT_DISPLAYEDFIELD)) + ,m_aDisplayedField (this, ModuleRes(ET_DISPLAYEDFIELD)) + ,m_aInfo (this, ModuleRes(FT_CONTENTFIELD_INFO)) + { + m_aInfo.SetText(String(ModuleRes( isListBox() ? STR_FIELDINFO_LISTBOX : STR_FIELDINFO_COMBOBOX))); + FreeResource(); + m_aSelectTableField.SetSelectHdl(LINK(this, OContentFieldSelection, OnFieldSelected)); + m_aSelectTableField.SetDoubleClickHdl(LINK(this, OContentFieldSelection, OnTableDoubleClicked)); + } + + //--------------------------------------------------------------------- + void OContentFieldSelection::ActivatePage() + { + OLCPage::ActivatePage(); + m_aTableFields.GrabFocus(); + } + + //--------------------------------------------------------------------- + void OContentFieldSelection::initializePage() + { + OLCPage::initializePage(); + + // fill the list of fields + fillListBox(m_aSelectTableField, getTableFields(sal_True)); + + m_aSelectTableField.SelectEntry(getSettings().sListContentField); + m_aDisplayedField.SetText(getSettings().sListContentField); + } + + //--------------------------------------------------------------------- + bool OContentFieldSelection::canAdvance() const + { + if (!OLCPage::canAdvance()) + return false; + + return 0 != m_aSelectTableField.GetSelectEntryCount(); + } + + //--------------------------------------------------------------------- + IMPL_LINK( OContentFieldSelection, OnTableDoubleClicked, ListBox*, /*NOTINTERESTEDIN*/ ) + { + if (m_aSelectTableField.GetSelectEntryCount()) + getDialog()->travelNext(); + return 0L; + } + + //--------------------------------------------------------------------- + IMPL_LINK( OContentFieldSelection, OnFieldSelected, ListBox*, /*NOTINTERESTEDIN*/ ) + { + updateDialogTravelUI(); + m_aDisplayedField.SetText(m_aSelectTableField.GetSelectEntry()); + return 0L; + } + + //--------------------------------------------------------------------- + sal_Bool OContentFieldSelection::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OLCPage::commitPage(_eReason)) + return sal_False; + + getSettings().sListContentField = m_aSelectTableField.GetSelectEntry(); + + return sal_True; + } + + //===================================================================== + //= OLinkFieldsPage + //===================================================================== + //--------------------------------------------------------------------- + OLinkFieldsPage::OLinkFieldsPage( OListComboWizard* _pParent ) + :OLCPage(_pParent, ModuleRes(RID_PAGE_LCW_FIELDLINK)) + ,m_aDescription (this, ModuleRes(FT_FIELDLINK_DESC)) + ,m_aFrame (this, ModuleRes(FL_FRAME)) + ,m_aValueListFieldLabel (this, ModuleRes(FT_VALUELISTFIELD)) + ,m_aValueListField (this, ModuleRes(CMB_VALUELISTFIELD)) + ,m_aTableFieldLabel (this, ModuleRes(FT_TABLEFIELD)) + ,m_aTableField (this, ModuleRes(CMB_TABLEFIELD)) + { + FreeResource(); + + m_aValueListField.SetModifyHdl(LINK(this, OLinkFieldsPage, OnSelectionModified)); + m_aTableField.SetModifyHdl(LINK(this, OLinkFieldsPage, OnSelectionModified)); + m_aValueListField.SetSelectHdl(LINK(this, OLinkFieldsPage, OnSelectionModified)); + m_aTableField.SetSelectHdl(LINK(this, OLinkFieldsPage, OnSelectionModified)); + } + + //--------------------------------------------------------------------- + void OLinkFieldsPage::ActivatePage() + { + OLCPage::ActivatePage(); + m_aValueListField.GrabFocus(); + } + + //--------------------------------------------------------------------- + void OLinkFieldsPage::initializePage() + { + OLCPage::initializePage(); + + // fill the value list + fillListBox(m_aValueListField, getContext().aFieldNames); + // fill the table field list + fillListBox(m_aTableField, getTableFields(sal_True)); + + // the initial selections + m_aValueListField.SetText(getSettings().sLinkedFormField); + m_aTableField.SetText(getSettings().sLinkedListField); + + implCheckFinish(); + } + + //--------------------------------------------------------------------- + bool OLinkFieldsPage::canAdvance() const + { + // we're on the last page here, no travelNext allowed ... + return false; + } + + //--------------------------------------------------------------------- + void OLinkFieldsPage::implCheckFinish() + { + sal_Bool bInvalidSelection = (COMBOBOX_ENTRY_NOTFOUND == m_aValueListField.GetEntryPos(m_aValueListField.GetText())); + bInvalidSelection |= (COMBOBOX_ENTRY_NOTFOUND == m_aTableField.GetEntryPos(m_aTableField.GetText())); + getDialog()->enableButtons(WZB_FINISH, !bInvalidSelection); + } + + //--------------------------------------------------------------------- + IMPL_LINK(OLinkFieldsPage, OnSelectionModified, void*, EMPTYARG) + { + implCheckFinish(); + return 0L; + } + + //--------------------------------------------------------------------- + sal_Bool OLinkFieldsPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) + { + if (!OLCPage::commitPage(_eReason)) + return sal_False; + + getSettings().sLinkedFormField = m_aValueListField.GetText(); + getSettings().sLinkedListField = m_aTableField.GetText(); + + return sal_True; + } + + //===================================================================== + //= OComboDBFieldPage + //===================================================================== + //--------------------------------------------------------------------- + OComboDBFieldPage::OComboDBFieldPage( OControlWizard* _pParent ) + :ODBFieldPage(_pParent) + { + setDescriptionText(String(ModuleRes(RID_STR_COMBOWIZ_DBFIELD))); + } + + //--------------------------------------------------------------------- + String& OComboDBFieldPage::getDBFieldSetting() + { + return getSettings().sLinkedFormField; + } + + //--------------------------------------------------------------------- + void OComboDBFieldPage::ActivatePage() + { + ODBFieldPage::ActivatePage(); + getDialog()->enableButtons(WZB_FINISH, sal_True); + } + + //--------------------------------------------------------------------- + bool OComboDBFieldPage::canAdvance() const + { + // we're on the last page here, no travelNext allowed ... + return false; + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/listcombowizard.hxx b/extensions/source/dbpilots/listcombowizard.hxx new file mode 100644 index 000000000000..05f7f70ea65d --- /dev/null +++ b/extensions/source/dbpilots/listcombowizard.hxx @@ -0,0 +1,227 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_LISTCOMBOWIZARD_HXX_ +#define _EXTENSIONS_DBP_LISTCOMBOWIZARD_HXX_ + +#include "controlwizard.hxx" +#include "commonpagesdbp.hxx" + +//......................................................................... +namespace dbp +{ +//......................................................................... + +#define LCW_STATE_DATASOURCE_SELECTION 0 +#define LCW_STATE_TABLESELECTION 1 +#define LCW_STATE_FIELDSELECTION 2 +#define LCW_STATE_FIELDLINK 3 +#define LCW_STATE_COMBODBFIELD 4 + + //===================================================================== + //= OListComboSettings + //===================================================================== + struct OListComboSettings : public OControlWizardSettings + { + String sListContentTable; + String sListContentField; + String sLinkedFormField; + String sLinkedListField; + }; + + //===================================================================== + //= OListComboWizard + //===================================================================== + class OListComboWizard : public OControlWizard + { + protected: + OListComboSettings m_aSettings; + sal_Bool m_bListBox : 1; + sal_Bool m_bHadDataSelection : 1; + + public: + OListComboWizard( + Window* _pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObjectModel, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB + ); + + OListComboSettings& getSettings() { return m_aSettings; } + + sal_Bool isListBox() const { return m_bListBox; } + + protected: + // OWizardMachine overridables + virtual ::svt::OWizardPage* createPage( WizardState _nState ); + virtual WizardState determineNextState( WizardState _nCurrentState ) const; + virtual void enterState( WizardState _nState ); + virtual sal_Bool leaveState( WizardState _nState ); + virtual sal_Bool onFinish(); + + virtual sal_Bool approveControl(sal_Int16 _nClassId); + + WizardState getFinalState() const { return isListBox() ? LCW_STATE_FIELDLINK : LCW_STATE_COMBODBFIELD; } + + private: + void implApplySettings(); + }; + + //===================================================================== + //= OLCPage + //===================================================================== + class OLCPage : public OControlWizardPage + { + public: + OLCPage( OListComboWizard* _pParent, const ResId& _rId ) : OControlWizardPage(_pParent, _rId) { } + + protected: + OListComboSettings& getSettings() { return static_cast<OListComboWizard*>(getDialog())->getSettings(); } + sal_Bool isListBox() { return static_cast<OListComboWizard*>(getDialog())->isListBox(); } + + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + getTables(sal_Bool _bNeedIt); + ::com::sun::star::uno::Sequence< ::rtl::OUString > + getTableFields(sal_Bool _bNeedIt); + }; + + //===================================================================== + //= OContentTableSelection + //===================================================================== + class OContentTableSelection : public OLCPage + { + protected: + FixedLine m_aFrame; + FixedText m_aSelectTableLabel; + ListBox m_aSelectTable; + + public: + OContentTableSelection( OListComboWizard* _pParent ); + + protected: + // TabPage overridables + virtual void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + virtual bool canAdvance() const; + + protected: + DECL_LINK( OnTableDoubleClicked, ListBox* ); + DECL_LINK( OnTableSelected, ListBox* ); + }; + + //===================================================================== + //= OContentFieldSelection + //===================================================================== + class OContentFieldSelection : public OLCPage + { + protected: + FixedLine m_aFrame; + FixedText m_aTableFields; + ListBox m_aSelectTableField; + FixedText m_aDisplayedFieldLabel; + Edit m_aDisplayedField; + FixedText m_aInfo; + + + public: + OContentFieldSelection( OListComboWizard* _pParent ); + + protected: + DECL_LINK( OnFieldSelected, ListBox* ); + DECL_LINK( OnTableDoubleClicked, ListBox* ); + + // TabPage overridables + virtual void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + virtual bool canAdvance() const; + }; + + //===================================================================== + //= OLinkFieldsPage + //===================================================================== + class OLinkFieldsPage : public OLCPage + { + protected: + FixedText m_aDescription; + FixedLine m_aFrame; + FixedText m_aValueListFieldLabel; + ComboBox m_aValueListField; + FixedText m_aTableFieldLabel; + ComboBox m_aTableField; + + + public: + OLinkFieldsPage( OListComboWizard* _pParent ); + + protected: + // TabPage overridables + virtual void ActivatePage(); + + // OWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( ::svt::WizardTypes::CommitPageReason _eReason ); + virtual bool canAdvance() const; + + private: + void implCheckFinish(); + + DECL_LINK(OnSelectionModified, void*); + }; + + //===================================================================== + //= OComboDBFieldPage + //===================================================================== + class OComboDBFieldPage : public ODBFieldPage + { + public: + OComboDBFieldPage( OControlWizard* _pParent ); + + protected: + OListComboSettings& getSettings() { return static_cast<OListComboWizard*>(getDialog())->getSettings(); } + + // TabPage overridables + virtual void ActivatePage(); + + // OWizardPage overridables + virtual bool canAdvance() const; + + // ODBFieldPage overridables + virtual String& getDBFieldSetting(); + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBP_LISTCOMBOWIZARD_HXX_ + diff --git a/extensions/source/dbpilots/makefile.mk b/extensions/source/dbpilots/makefile.mk new file mode 100644 index 000000000000..e37ab0a546ac --- /dev/null +++ b/extensions/source/dbpilots/makefile.mk @@ -0,0 +1,111 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. +PRJINC=..$/inc + +PRJNAME=extensions +TARGET=dbp +ENABLE_EXCEPTIONS=TRUE +VISIBILITY_HIDDEN=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- defines ------------------------------------------------------ + +CDEFS+=-DCOMPMOD_NAMESPACE=dbp + +# --- Files -------------------------------------------------------- + +CXXFILES= dbptools.cxx \ + gridwizard.cxx \ + listcombowizard.cxx \ + optiongrouplayouter.cxx \ + commonpagesdbp.cxx \ + groupboxwiz.cxx \ + wizardservices.cxx \ + controlwizard.cxx \ + moduledbp.cxx \ + dbpservices.cxx + +SLOFILES= $(SLO)$/dbptools.obj \ + $(SLO)$/gridwizard.obj \ + $(SLO)$/listcombowizard.obj \ + $(SLO)$/optiongrouplayouter.obj \ + $(SLO)$/commonpagesdbp.obj \ + $(SLO)$/groupboxwiz.obj \ + $(SLO)$/wizardservices.obj \ + $(SLO)$/controlwizard.obj \ + $(SLO)$/moduledbp.obj \ + $(SLO)$/dbpservices.obj + + +SRS1NAME=$(TARGET) +SRC1FILES= gridpages.src \ + commonpagesdbp.src \ + dbpilots.src \ + groupboxpages.src \ + listcombopages.src + +RESLIB1NAME=dbp +RESLIB1SRSFILES= $(SRS)$/dbp.srs + +SHL1TARGET= $(TARGET)$(DLLPOSTFIX) +SHL1VERSIONMAP=$(SOLARENV)/src/component.map + +SHL1STDLIBS= \ + $(SVTOOLLIB) \ + $(VCLLIB) \ + $(TOOLSLIB) \ + $(SVLLIB) \ + $(SFXLIB) \ + $(DBTOOLSLIB) \ + $(UNOTOOLSLIB) \ + $(COMPHELPERLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) + +SHL1LIBS= $(SLB)$/$(TARGET).lib +SHL1IMPLIB= i$(TARGET) +SHL1DEPN= $(SHL1LIBS) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +ALLTAR : $(MISC)/dbp.component + +$(MISC)/dbp.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ + dbp.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt dbp.component diff --git a/extensions/source/dbpilots/moduledbp.cxx b/extensions/source/dbpilots/moduledbp.cxx new file mode 100644 index 000000000000..9f6d3d2b9e30 --- /dev/null +++ b/extensions/source/dbpilots/moduledbp.cxx @@ -0,0 +1,32 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" + +#include "componentmodule.cxx" + diff --git a/extensions/source/dbpilots/optiongrouplayouter.cxx b/extensions/source/dbpilots/optiongrouplayouter.cxx new file mode 100644 index 000000000000..c4288a645217 --- /dev/null +++ b/extensions/source/dbpilots/optiongrouplayouter.cxx @@ -0,0 +1,216 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "optiongrouplayouter.hxx" +#include <tools/debug.hxx> +#include <tools/string.hxx> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/drawing/XShapeGrouper.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include "controlwizard.hxx" +#include "groupboxwiz.hxx" +#include "dbptools.hxx" + +//......................................................................... +namespace dbp +{ +//......................................................................... + +#define BUTTON_HEIGHT 300 +#define TOP_HEIGHT 300 +#define HEIGHT 450 +#define OFFSET 300 +#define MIN_WIDTH 600 + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::drawing; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::text; + using namespace ::com::sun::star::view; + + //===================================================================== + //= OOptionGroupLayouter + //===================================================================== + //--------------------------------------------------------------------- + OOptionGroupLayouter::OOptionGroupLayouter(const Reference< XMultiServiceFactory >& _rxORB) + :m_xORB(_rxORB) + { + } + + //--------------------------------------------------------------------- + void OOptionGroupLayouter::doLayout(const OControlWizardContext& _rContext, const OOptionGroupSettings& _rSettings) + { + Reference< XShapes > xPageShapes(_rContext.xDrawPage, UNO_QUERY); + if (!xPageShapes.is()) + { + DBG_ERROR("OOptionGroupLayouter::OOptionGroupLayouter: missing the XShapes interface for the page!"); + return; + } + + Reference< XMultiServiceFactory > xDocFactory(_rContext.xDocumentModel, UNO_QUERY); + if (!xDocFactory.is()) + { + DBG_ERROR("OOptionGroupLayouter::OOptionGroupLayouter: no document service factory!"); + return; + } + + // no. of buttons to create + sal_Int32 nRadioButtons = _rSettings.aLabels.size(); + + sal_Int32 nTopSpace = 0; + + // the shape of the groupbox + ::com::sun::star::awt::Size aControlShapeSize = _rContext.xObjectShape->getSize(); + // maybe need to adjust the size if the control shapes + sal_Int32 nMinShapeHeight = BUTTON_HEIGHT*(nRadioButtons+1) + BUTTON_HEIGHT + BUTTON_HEIGHT/4; + if (aControlShapeSize.Height < nMinShapeHeight) + aControlShapeSize.Height = nMinShapeHeight; + if (aControlShapeSize.Width < MIN_WIDTH) + aControlShapeSize.Width = MIN_WIDTH; + _rContext.xObjectShape->setSize(aControlShapeSize); + + // if we're working on a writer document, we need to anchor the shape + implAnchorShape(Reference< XPropertySet >(_rContext.xObjectShape, UNO_QUERY)); + + // shape collection (for grouping the shapes) + Reference< XShapes > xButtonCollection(m_xORB->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.drawing.ShapeCollection")), + UNO_QUERY); + // first member : the shape of the control + xButtonCollection->add(_rContext.xObjectShape.get()); + + sal_Int32 nTempHeight = (aControlShapeSize.Height - BUTTON_HEIGHT/4) / (nRadioButtons + 1); + + ::com::sun::star::awt::Point aShapePosition = _rContext.xObjectShape->getPosition(); + + ::com::sun::star::awt::Size aButtonSize(aControlShapeSize); + aButtonSize.Width = aControlShapeSize.Width - OFFSET; + aButtonSize.Height = HEIGHT; + ::com::sun::star::awt::Point aButtonPosition; + aButtonPosition.X = aShapePosition.X + OFFSET; + + ::rtl::OUString sElementsName = ::rtl::OUString::createFromAscii("RadioGroup"); + disambiguateName(Reference< XNameAccess >(_rContext.xForm, UNO_QUERY), sElementsName); + + StringArray::const_iterator aLabelIter = _rSettings.aLabels.begin(); + StringArray::const_iterator aValueIter = _rSettings.aValues.begin(); + for (sal_Int32 i=0; i<nRadioButtons; ++i, ++aLabelIter, ++aValueIter) + { + aButtonPosition.Y = aShapePosition.Y + (i+1) * nTempHeight + nTopSpace; + + Reference< XPropertySet > xRadioModel( + xDocFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.form.component.RadioButton")), + UNO_QUERY); + + // the label + xRadioModel->setPropertyValue(::rtl::OUString::createFromAscii("Label"), makeAny(rtl::OUString(*aLabelIter))); + // the value + xRadioModel->setPropertyValue(::rtl::OUString::createFromAscii("RefValue"), makeAny(rtl::OUString(*aValueIter))); + + // default selection + if (_rSettings.sDefaultField == *aLabelIter) + xRadioModel->setPropertyValue(::rtl::OUString::createFromAscii("DefaultState"), makeAny(sal_Int16(1))); + + // the connection to the database field + if (0 != _rSettings.sDBField.Len()) + xRadioModel->setPropertyValue(::rtl::OUString::createFromAscii("DataField"), makeAny(::rtl::OUString(_rSettings.sDBField))); + + // the name for the model + xRadioModel->setPropertyValue(::rtl::OUString::createFromAscii("Name"), makeAny(sElementsName)); + + // create a shape for the radio button + Reference< XControlShape > xRadioShape( + xDocFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.drawing.ControlShape")), + UNO_QUERY); + Reference< XPropertySet > xShapeProperties(xRadioShape, UNO_QUERY); + + // if we're working on a writer document, we need to anchor the shape + implAnchorShape(xShapeProperties); + + // position it + xRadioShape->setSize(aButtonSize); + xRadioShape->setPosition(aButtonPosition); + // knitting with the model + xRadioShape->setControl(Reference< XControlModel >(xRadioModel, UNO_QUERY)); + + // the name of the shape + if (xShapeProperties.is()) + xShapeProperties->setPropertyValue(::rtl::OUString::createFromAscii("Name"), makeAny(sElementsName)); + + // add to the page + xPageShapes->add(xRadioShape.get()); + // add to the collection (for the later grouping) + xButtonCollection->add(xRadioShape.get()); + + // set the GroupBox as "LabelControl" for the RadioButton + // (_after_ having inserted the model into the page!) + xRadioModel->setPropertyValue(::rtl::OUString::createFromAscii("LabelControl"), makeAny(_rContext.xObjectModel)); + } + + // group the shapes + try + { + Reference< XShapeGrouper > xGrouper(_rContext.xDrawPage, UNO_QUERY); + if (xGrouper.is()) + { + Reference< XShapeGroup > xGroupedOptions = xGrouper->group(xButtonCollection); + Reference< XSelectionSupplier > xSelector(_rContext.xDocumentModel->getCurrentController(), UNO_QUERY); + if (xSelector.is()) + xSelector->select(makeAny(xGroupedOptions)); + } + } + catch(Exception&) + { + DBG_ERROR("OOptionGroupLayouter::doLayout: caught an exception while grouping the shapes!"); + } + } + + //--------------------------------------------------------------------- + void OOptionGroupLayouter::implAnchorShape(const Reference< XPropertySet >& _rxShapeProps) + { + static const ::rtl::OUString s_sAnchorPropertyName = ::rtl::OUString::createFromAscii("AnchorType"); + Reference< XPropertySetInfo > xPropertyInfo; + if (_rxShapeProps.is()) + xPropertyInfo = _rxShapeProps->getPropertySetInfo(); + if (xPropertyInfo.is() && xPropertyInfo->hasPropertyByName(s_sAnchorPropertyName)) + _rxShapeProps->setPropertyValue(s_sAnchorPropertyName, makeAny(TextContentAnchorType_AT_PAGE)); + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/optiongrouplayouter.hxx b/extensions/source/dbpilots/optiongrouplayouter.hxx new file mode 100644 index 000000000000..ddc23a5e199c --- /dev/null +++ b/extensions/source/dbpilots/optiongrouplayouter.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_OPTIONGROUPLAYOUTER_HXX_ +#define _EXTENSIONS_DBP_OPTIONGROUPLAYOUTER_HXX_ + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include "dbptypes.hxx" + +//......................................................................... +namespace dbp +{ +//......................................................................... + + struct OControlWizardContext; + struct OOptionGroupSettings; + //===================================================================== + //= OOptionGroupLayouter + //===================================================================== + class OOptionGroupLayouter + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xORB; + + public: + OOptionGroupLayouter( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB + ); + + public: + void doLayout( + const OControlWizardContext& _rContext, + const OOptionGroupSettings& _rSettings + ); + + protected: + void implAnchorShape( + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxShapeProps + ); + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBP_OPTIONGROUPLAYOUTER_HXX_ + diff --git a/extensions/source/dbpilots/unoautopilot.hxx b/extensions/source/dbpilots/unoautopilot.hxx new file mode 100644 index 000000000000..1ed89d280a6c --- /dev/null +++ b/extensions/source/dbpilots/unoautopilot.hxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_UNOAUTOPILOT_HXX_ +#define _EXTENSIONS_DBP_UNOAUTOPILOT_HXX_ + +#include <svtools/genericunodialog.hxx> +#include <comphelper/proparrhlp.hxx> +#include "componentmodule.hxx" +#include <cppuhelper/typeprovider.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + //===================================================================== + //= IServiceInfo + //===================================================================== + /** interface for the SERVICEINFO template parameter of the OUnoAutoPilot class + */ + struct IServiceInfo + { + public: + ::rtl::OUString getImplementationName() const; + ::com::sun::star::uno::Sequence< ::rtl::OUString > + getServiceNames() const; + }; + + //===================================================================== + //= OUnoAutoPilot + //===================================================================== + typedef ::svt::OGenericUnoDialog OUnoAutoPilot_Base; + template <class TYPE, class SERVICEINFO> + class OUnoAutoPilot + :public OUnoAutoPilot_Base + ,public ::comphelper::OPropertyArrayUsageHelper< OUnoAutoPilot< TYPE, SERVICEINFO > > + ,public OModuleResourceClient + { + OUnoAutoPilot(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB); + + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + m_xObjectModel; + + public: + // XTypeProvider + virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); + virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); + + // XServiceInfo - static methods + static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException ); + static ::rtl::OUString getImplementationName_Static(void) throw( ::com::sun::star::uno::RuntimeException ); + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + SAL_CALL Create(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >&); + + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException); + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; + + protected: + // OGenericUnoDialog overridables + virtual Dialog* createDialog(Window* _pParent); + virtual void implInitialize(const com::sun::star::uno::Any& _rValue); + }; + +#include "unoautopilot.inl" + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBP_UNOAUTOPILOT_HXX_ + diff --git a/extensions/source/dbpilots/unoautopilot.inl b/extensions/source/dbpilots/unoautopilot.inl new file mode 100644 index 000000000000..0e3a953bcad1 --- /dev/null +++ b/extensions/source/dbpilots/unoautopilot.inl @@ -0,0 +1,134 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// no include protecttion +// this file is included from unoautopilot.hxx directly + +//using namespace ::com::sun::star::uno; +//using namespace ::com::sun::star::lang; +//using namespace ::com::sun::star::beans; +// +//===================================================================== +//= OUnoAutoPilot +//===================================================================== +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +OUnoAutoPilot<TYPE, SERVICEINFO>::OUnoAutoPilot(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB) + :OUnoAutoPilot_Base(_rxORB) +{ +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL OUnoAutoPilot<TYPE, SERVICEINFO>::getImplementationId( ) throw(::com::sun::star::uno::RuntimeException) +{ + static ::cppu::OImplementationId aId; + return aId.getImplementationId(); +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL OUnoAutoPilot<TYPE, SERVICEINFO>::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) +{ + return *(new OUnoAutoPilot<TYPE, SERVICEINFO>(_rxFactory)); +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::rtl::OUString SAL_CALL OUnoAutoPilot<TYPE, SERVICEINFO>::getImplementationName() throw(::com::sun::star::uno::RuntimeException) +{ + return getImplementationName_Static(); +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::rtl::OUString OUnoAutoPilot<TYPE, SERVICEINFO>::getImplementationName_Static() throw(::com::sun::star::uno::RuntimeException) +{ + return SERVICEINFO().getImplementationName(); +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::comphelper::StringSequence SAL_CALL OUnoAutoPilot<TYPE, SERVICEINFO>::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::comphelper::StringSequence OUnoAutoPilot<TYPE, SERVICEINFO>::getSupportedServiceNames_Static() throw(::com::sun::star::uno::RuntimeException) +{ + return SERVICEINFO().getServiceNames(); +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OUnoAutoPilot<TYPE, SERVICEINFO>::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +//--------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::cppu::IPropertyArrayHelper& OUnoAutoPilot<TYPE, SERVICEINFO>::getInfoHelper() +{ + return *const_cast<OUnoAutoPilot*>(this)->getArrayHelper(); +} + +//-------------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +::cppu::IPropertyArrayHelper* OUnoAutoPilot<TYPE, SERVICEINFO>::createArrayHelper( ) const +{ + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} + +//-------------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +Dialog* OUnoAutoPilot<TYPE, SERVICEINFO>::createDialog(Window* _pParent) +{ + return new TYPE(_pParent, m_xObjectModel, m_aContext.getLegacyServiceFactory()); +} + +//-------------------------------------------------------------------------- +template <class TYPE, class SERVICEINFO> +void OUnoAutoPilot<TYPE, SERVICEINFO>::implInitialize(const com::sun::star::uno::Any& _rValue) +{ + ::com::sun::star::beans::PropertyValue aArgument; + if (_rValue >>= aArgument) + if (0 == aArgument.Name.compareToAscii("ObjectModel")) + { + aArgument.Value >>= m_xObjectModel; + return; + } + + OUnoAutoPilot_Base::implInitialize(_rValue); +} + + diff --git a/extensions/source/dbpilots/wizardcontext.hxx b/extensions/source/dbpilots/wizardcontext.hxx new file mode 100644 index 000000000000..d79f4bec0890 --- /dev/null +++ b/extensions/source/dbpilots/wizardcontext.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBP_WIZARDCONTEXT_HXX_ +#define _EXTENSIONS_DBP_WIZARDCONTEXT_HXX_ + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sdbc/XRowSet.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <comphelper/stl_types.hxx> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + //===================================================================== + //= OControlWizardContext + //===================================================================== + struct OControlWizardContext + { + // the global data source context + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + xDatasourceContext; + + // the control mode + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + xObjectModel; + // the form the control model belongs to + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + xForm; + // the form as rowset + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > + xRowSet; + + // the model of the document + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > + xDocumentModel; + // the page where the control mode resides + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > + xDrawPage; + // the shape which carries the control + ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XControlShape > + xObjectShape; + + // the tables or queries of the data source the form is bound to (if any) + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + xObjectContainer; + // the column types container of the object the form is bound to (table, query or SQL statement) + DECLARE_STL_USTRINGACCESS_MAP(sal_Int32,TNameTypeMap); + TNameTypeMap aTypes; + // the column names of the object the form is bound to (table, query or SQL statement) + ::com::sun::star::uno::Sequence< ::rtl::OUString > + aFieldNames; + + sal_Bool bEmbedded; + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBP_WIZARDCONTEXT_HXX_ + diff --git a/extensions/source/dbpilots/wizardservices.cxx b/extensions/source/dbpilots/wizardservices.cxx new file mode 100644 index 000000000000..36af518fc44f --- /dev/null +++ b/extensions/source/dbpilots/wizardservices.cxx @@ -0,0 +1,122 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" + +#ifndef _EXTENSIONS_DBP_WIZARDSERVICES_HXX_ +#include "wizardservices.hxx" +#endif +#include "unoautopilot.hxx" +#include "groupboxwiz.hxx" +#include "listcombowizard.hxx" +#include "gridwizard.hxx" + +// the registration methods +extern "C" void SAL_CALL createRegistryInfo_OGroupBoxWizard() +{ + static ::dbp::OMultiInstanceAutoRegistration< + ::dbp::OUnoAutoPilot< ::dbp::OGroupBoxWizard, ::dbp::OGroupBoxSI > + > aAutoRegistration; +} + +extern "C" void SAL_CALL createRegistryInfo_OListComboWizard() +{ + static ::dbp::OMultiInstanceAutoRegistration< + ::dbp::OUnoAutoPilot< ::dbp::OListComboWizard, ::dbp::OListComboSI > + > aAutoRegistration; +} + +extern "C" void SAL_CALL createRegistryInfo_OGridWizard() +{ + static ::dbp::OMultiInstanceAutoRegistration< + ::dbp::OUnoAutoPilot< ::dbp::OGridWizard, ::dbp::OGridSI > + > aAutoRegistration; +} + +//......................................................................... +namespace dbp +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + + //===================================================================== + //= OGroupBoxSI + //===================================================================== + //--------------------------------------------------------------------- + ::rtl::OUString OGroupBoxSI::getImplementationName() const + { + return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbp.OGroupBoxWizard"); + } + + //--------------------------------------------------------------------- + Sequence< ::rtl::OUString > OGroupBoxSI::getServiceNames() const + { + Sequence< ::rtl::OUString > aReturn(1); + aReturn[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.GroupBoxAutoPilot"); + return aReturn; + } + + //===================================================================== + //= OListComboSI + //===================================================================== + //--------------------------------------------------------------------- + ::rtl::OUString OListComboSI::getImplementationName() const + { + return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbp.OListComboWizard"); + } + + //--------------------------------------------------------------------- + Sequence< ::rtl::OUString > OListComboSI::getServiceNames() const + { + Sequence< ::rtl::OUString > aReturn(1); + aReturn[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ListComboBoxAutoPilot"); + return aReturn; + } + + //===================================================================== + //= OGridSI + //===================================================================== + //--------------------------------------------------------------------- + ::rtl::OUString OGridSI::getImplementationName() const + { + return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbp.OGridWizard"); + } + + //--------------------------------------------------------------------- + Sequence< ::rtl::OUString > OGridSI::getServiceNames() const + { + Sequence< ::rtl::OUString > aReturn(1); + aReturn[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.GridControlAutoPilot"); + return aReturn; + } + +//......................................................................... +} // namespace dbp +//......................................................................... + diff --git a/extensions/source/dbpilots/wizardservices.hxx b/extensions/source/dbpilots/wizardservices.hxx new file mode 100644 index 000000000000..a9bf9a72b478 --- /dev/null +++ b/extensions/source/dbpilots/wizardservices.hxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXTENSIONS_DBW_WIZARDSERVICES_HXX_ +#define _EXTENSIONS_DBW_WIZARDSERVICES_HXX_ + +#include <com/sun/star/uno/Sequence.hxx> +#include <rtl/ustring.hxx> + +//......................................................................... +namespace dbp +{ +//......................................................................... + + //===================================================================== + //= OGroupBoxSI + //===================================================================== + /// service info for the group box wizard + struct OGroupBoxSI + { + public: + ::rtl::OUString getImplementationName() const; + ::com::sun::star::uno::Sequence< ::rtl::OUString > + getServiceNames() const; + }; + + //===================================================================== + //= OListComboSI + //===================================================================== + /// service info for the list/combo box wizard + struct OListComboSI + { + public: + ::rtl::OUString getImplementationName() const; + ::com::sun::star::uno::Sequence< ::rtl::OUString > + getServiceNames() const; + }; + + //===================================================================== + //= OGridSI + //===================================================================== + /// service info for the grid wizard + struct OGridSI + { + public: + ::rtl::OUString getImplementationName() const; + ::com::sun::star::uno::Sequence< ::rtl::OUString > + getServiceNames() const; + }; + +//......................................................................... +} // namespace dbp +//......................................................................... + +#endif // _EXTENSIONS_DBW_WIZARDSERVICES_HXX_ + |