/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::container; using namespace ::com::sun::star::beans; class SwAddressTable : public SvSimpleTable { public: SwAddressTable(SvSimpleTableContainer& rParent, WinBits nBits = 0); void InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText, HeaderBarItemBits nBits); virtual void Resize() SAL_OVERRIDE; void setColSizes(); }; SwAddressTable::SwAddressTable(SvSimpleTableContainer& rParent, WinBits nBits) : SvSimpleTable(rParent, nBits) { SetSpaceBetweenEntries(3); SetSelectionMode(SINGLE_SELECTION); SetDragDropMode(0); EnableAsyncDrag(false); } void SwAddressTable::InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText, HeaderBarItemBits nBits) { GetTheHeaderBar().InsertItem( nColumn, rText, 0, nBits ); } void SwAddressTable::Resize() { SvSimpleTable::Resize(); setColSizes(); } void SwAddressTable::setColSizes() { HeaderBar &rHB = GetTheHeaderBar(); if (rHB.GetItemCount() < 2) return; long nWidth = rHB.GetSizePixel().Width(); nWidth /= 2; long nTabs_Impl[3]; nTabs_Impl[0] = 2; nTabs_Impl[1] = 0; nTabs_Impl[2] = nWidth; SvSimpleTable::SetTabs(&nTabs_Impl[0], MAP_PIXEL); } SwSelectDBTableDialog::SwSelectDBTableDialog(vcl::Window* pParent, const uno::Reference< sdbc::XConnection>& rConnection) : SfxModalDialog(pParent, "SelectTableDialog", "modules/swriter/ui/selecttabledialog.ui") , m_sName(SW_RES(ST_NAME)) , m_sType(SW_RES(ST_TYPE)) , m_sTable(SW_RES(ST_TABLE)) , m_sQuery(SW_RES(ST_QUERY)) , m_xConnection(rConnection) { get(m_pPreviewPB, "preview"); SvSimpleTableContainer *pHeaderTreeContainer = get("table"); Size aSize = pHeaderTreeContainer->LogicToPixel(Size(238 , 50), MAP_APPFONT); pHeaderTreeContainer->set_width_request(aSize.Width()); pHeaderTreeContainer->set_height_request(aSize.Height()); m_pTable = new SwAddressTable(*pHeaderTreeContainer); long aStaticTabs[]= { 2, 0, 0 }; m_pTable->SetTabs( aStaticTabs ); m_pTable->InsertHeaderItem(1, m_sName, HIB_LEFT | HIB_VCENTER); m_pTable->InsertHeaderItem(2, m_sType, HIB_LEFT | HIB_VCENTER); m_pPreviewPB->SetClickHdl(LINK(this, SwSelectDBTableDialog, PreviewHdl)); Reference xTSupplier(m_xConnection, UNO_QUERY); if (xTSupplier.is()) { Reference xTbls = xTSupplier->getTables(); Sequence aTbls = xTbls->getElementNames(); const OUString* pTbls = aTbls.getConstArray(); for(long i = 0; i < aTbls.getLength(); i++) { OUString sEntry = pTbls[i]; sEntry += "\t"; sEntry += m_sTable; SvTreeListEntry* pEntry = m_pTable->InsertEntry(sEntry); pEntry->SetUserData((void*)0); } } Reference xQSupplier(m_xConnection, UNO_QUERY); if (xQSupplier.is()) { Reference xQueries = xQSupplier->getQueries(); Sequence aQueries = xQueries->getElementNames(); const OUString* pQueries = aQueries.getConstArray(); for(long i = 0; i < aQueries.getLength(); i++) { OUString sEntry = pQueries[i]; sEntry += "\t"; sEntry += m_sQuery; SvTreeListEntry* pEntry = m_pTable->InsertEntry(sEntry); pEntry->SetUserData((void*)1); } } } SwSelectDBTableDialog::~SwSelectDBTableDialog() { delete m_pTable; } IMPL_LINK(SwSelectDBTableDialog, PreviewHdl, PushButton*, pButton) { SvTreeListEntry* pEntry = m_pTable->FirstSelected(); if(pEntry) { OUString sTableOrQuery = m_pTable->GetEntryText(pEntry, 0); sal_Int32 nCommandType = 0 == pEntry->GetUserData() ? 0 : 1; OUString sDataSourceName; Reference xChild(m_xConnection, UNO_QUERY); if(xChild.is()) { Reference xSource(xChild->getParent(), UNO_QUERY); Reference xPrSet(xSource, UNO_QUERY); xPrSet->getPropertyValue("Name") >>= sDataSourceName; } OSL_ENSURE(!sDataSourceName.isEmpty(), "no data source found"); Sequence aProperties(5); PropertyValue* pProperties = aProperties.getArray(); pProperties[0].Name = "DataSourceName"; pProperties[0].Value <<= sDataSourceName; pProperties[1].Name = "Command"; pProperties[1].Value <<= sTableOrQuery; pProperties[2].Name = "CommandType"; pProperties[2].Value <<= nCommandType; pProperties[3].Name = "ShowTreeView"; pProperties[3].Value <<= sal_False; pProperties[4].Name = "ShowTreeViewButton"; pProperties[4].Value <<= sal_False; boost::scoped_ptr pDlg(new SwDBTablePreviewDialog(pButton, aProperties)); pDlg->Execute(); } return 0; } OUString SwSelectDBTableDialog::GetSelectedTable(bool& bIsTable) { SvTreeListEntry* pEntry = m_pTable->FirstSelected(); bIsTable = pEntry->GetUserData() ? false : true; return m_pTable->GetEntryText(pEntry, 0); } void SwSelectDBTableDialog::SetSelectedTable(const OUString& rTable, bool bIsTable) { SvTreeListEntry* pEntry = m_pTable->First(); while(pEntry) { if((m_pTable->GetEntryText(pEntry, 0) == rTable) && ((pEntry->GetUserData() == 0 ) == bIsTable)) { m_pTable->Select(pEntry); break; } pEntry = m_pTable->Next( pEntry ); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */