docthemes: Save themes def. to a file when added to ColorSets
[LibreOffice.git] / sw / source / uibase / fldui / xfldui.cxx
blob41f072418f52aa04958285072dfcb8496a6dfd66
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 <osl/diagnose.h>
21 #include <comphelper/diagnose_ex.hxx>
22 #include <com/sun/star/container/XNameAccess.hpp>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <com/sun/star/sdbc/XConnection.hpp>
25 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
26 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
27 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <fldmgr.hxx>
30 #include <dbmgr.hxx>
31 #include <wrtsh.hxx>
32 #include <view.hxx>
33 #include <swmodule.hxx>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::sdb;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::sdbcx;
40 using namespace ::com::sun::star::beans;
42 // This file contains all routines of the fldui directory, which must compile
43 // with exceptions. So we can reduce the code of the other files, which don't
44 // need any exception handling.
46 // Is the database field numeric?
47 // remark: in case of error true is returned
48 bool SwFieldMgr::IsDBNumeric( const OUString& rDBName, const OUString& rTableQryName,
49 bool bIsTable, const OUString& rFieldName)
51 bool bNumeric = true;
53 SwDBManager* pDBManager;
54 if (m_pWrtShell)
55 pDBManager = m_pWrtShell->GetDBManager();
56 else
58 if (SwView* pView = GetActiveView())
59 pDBManager = pView->GetWrtShell().GetDBManager();
60 else
61 return bNumeric;
64 Reference< XConnection> xConnection =
65 pDBManager->RegisterConnection(rDBName);
67 if( !xConnection.is() )
68 return bNumeric;
70 Reference<XColumnsSupplier> xColsSupplier;
71 if(bIsTable)
73 Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY);
74 if(xTSupplier.is())
76 Reference<XNameAccess> xTables = xTSupplier->getTables();
77 OSL_ENSURE(xTables->hasByName(rTableQryName), "table not available anymore?");
78 try
80 Any aTable = xTables->getByName(rTableQryName);
81 Reference<XPropertySet> xPropSet;
82 aTable >>= xPropSet;
83 xColsSupplier.set(xPropSet, UNO_QUERY);
85 catch (const Exception&)
90 else
92 Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY);
93 if(xQSupplier.is())
95 Reference<XNameAccess> xQueries = xQSupplier->getQueries();
96 OSL_ENSURE(xQueries->hasByName(rTableQryName), "table not available anymore?");
97 try
99 Any aQuery = xQueries->getByName(rTableQryName);
100 Reference<XPropertySet> xPropSet;
101 aQuery >>= xPropSet;
102 xColsSupplier.set(xPropSet, UNO_QUERY);
104 catch (const Exception&)
110 if(xColsSupplier.is())
112 Reference <XNameAccess> xCols;
115 xCols = xColsSupplier->getColumns();
117 catch (const Exception&)
119 TOOLS_WARN_EXCEPTION( "sw", "getColumns()");
121 if(xCols.is() && xCols->hasByName(rFieldName))
123 Any aCol = xCols->getByName(rFieldName);
124 Reference <XPropertySet> xCol;
125 aCol >>= xCol;
126 Any aType = xCol->getPropertyValue(u"Type"_ustr);
127 sal_Int32 eDataType = 0;
128 aType >>= eDataType;
129 switch(eDataType)
131 case DataType::BIT:
132 case DataType::BOOLEAN:
133 case DataType::TINYINT:
134 case DataType::SMALLINT:
135 case DataType::INTEGER:
136 case DataType::BIGINT:
137 case DataType::FLOAT:
138 case DataType::REAL:
139 case DataType::DOUBLE:
140 case DataType::NUMERIC:
141 case DataType::DECIMAL:
142 case DataType::DATE:
143 case DataType::TIME:
144 case DataType::TIMESTAMP:
145 break;
147 case DataType::BINARY:
148 case DataType::VARBINARY:
149 case DataType::LONGVARBINARY:
150 case DataType::SQLNULL:
151 case DataType::OTHER:
152 case DataType::OBJECT:
153 case DataType::DISTINCT:
154 case DataType::STRUCT:
155 case DataType::ARRAY:
156 case DataType::BLOB:
157 case DataType::CLOB:
158 case DataType::REF:
159 case DataType::CHAR:
160 case DataType::VARCHAR:
161 case DataType::LONGVARCHAR:
162 default:
163 bNumeric = false;
167 return bNumeric;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */