fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableWindowData.cxx
blobf6bfa841c49a760e518f66b6ddaa0d58338cefef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "TableWindowData.hxx"
21 #include <osl/diagnose.h>
22 #include <tools/debug.hxx>
23 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
24 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
25 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
26 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/container/XIndexAccess.hpp>
30 using namespace dbaui;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::sdb;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::container;
39 // class OTableWindowData
40 OTableWindowData::OTableWindowData( const Reference< XPropertySet>& _xTable
41 ,const OUString& _rComposedName
42 ,const OUString& rTableName
43 ,const OUString& rWinName )
44 :m_xTable(_xTable)
45 ,m_aTableName( rTableName )
46 ,m_aWinName( rWinName )
47 ,m_sComposedName(_rComposedName)
48 ,m_aPosition( Point(-1,-1) )
49 ,m_aSize( Size(-1,-1) )
50 ,m_bShowAll( true )
51 ,m_bIsQuery(false)
52 ,m_bIsValid(true)
54 if( m_aWinName.isEmpty() )
55 m_aWinName = m_aTableName;
57 listen();
60 OTableWindowData::~OTableWindowData()
62 Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
63 if ( xComponent.is() )
64 stopComponentListening( xComponent );
67 bool OTableWindowData::HasPosition() const
69 return ( (m_aPosition.X() != -1) && (m_aPosition.Y() != -1) );
72 bool OTableWindowData::HasSize() const
74 return ( (m_aSize.Width() != -1) && (m_aSize.Height() !=-1) );
77 void OTableWindowData::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
79 ::osl::MutexGuard aGuard( m_aMutex );
80 // it doesn't matter which one was disposed
81 m_xColumns.clear();
82 m_xKeys.clear();
83 m_xTable.clear();
86 bool OTableWindowData::init(const Reference< XConnection >& _xConnection,bool _bAllowQueries)
88 OSL_ENSURE(!m_xTable.is(),"We are already connected to a table!");
90 ::osl::MutexGuard aGuard( m_aMutex );
92 Reference< XQueriesSupplier > xSupQueries( _xConnection, UNO_QUERY_THROW );
93 Reference< XNameAccess > xQueries( xSupQueries->getQueries(), UNO_QUERY_THROW );
94 bool bIsKnownQuery = _bAllowQueries && xQueries->hasByName( m_sComposedName );
96 Reference< XTablesSupplier > xSupTables( _xConnection, UNO_QUERY_THROW );
97 Reference< XNameAccess > xTables( xSupTables->getTables(), UNO_QUERY_THROW );
98 bool bIsKnownTable = xTables->hasByName( m_sComposedName );
100 if ( bIsKnownQuery )
101 m_xTable.set( xQueries->getByName( m_sComposedName ), UNO_QUERY );
102 else if ( bIsKnownTable )
103 m_xTable.set( xTables->getByName( m_sComposedName ), UNO_QUERY );
104 else
105 m_bIsValid = false;
107 // if we survived so far, we know whether it's a query
108 m_bIsQuery = bIsKnownQuery;
110 listen();
112 Reference< XIndexAccess > xColumnsAsIndex( m_xColumns,UNO_QUERY );
113 return xColumnsAsIndex.is() && ( xColumnsAsIndex->getCount() > 0 );
116 void OTableWindowData::listen()
118 if ( m_xTable.is() )
120 // listen for the object being disposed
121 Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
122 if ( xComponent.is() )
123 startComponentListening( xComponent );
125 // obtain the columns
126 Reference< XColumnsSupplier > xColumnsSups( m_xTable, UNO_QUERY);
127 if ( xColumnsSups.is() )
128 m_xColumns = xColumnsSups->getColumns();
130 Reference<XKeysSupplier> xKeySup(m_xTable,UNO_QUERY);
131 if ( xKeySup.is() )
132 m_xKeys = xKeySup->getKeys();
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */