Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / inc / UITools.hxx
blobc622c73f65c533cb06e272d9121ef9d48df1e6b5
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 .
19 #pragma once
21 #include <connectivity/dbexception.hxx>
22 #include <comphelper/stl_types.hxx>
23 #include "TypeInfo.hxx"
24 #include <editeng/svxenum.hxx>
25 #include <vcl/taskpanelist.hxx>
26 #include <connectivity/dbtools.hxx>
27 #include <unotools/resmgr.hxx>
29 #include <memory>
30 #include <string_view>
32 #define RET_ALL 100
34 // we only need forward decl here
35 namespace com::sun::star {
37 namespace beans { class XPropertySet;}
38 namespace container
40 class XNameAccess;
41 class XHierarchicalNameContainer;
43 namespace lang
45 class XEventListener;
47 namespace awt
49 struct FontDescriptor;
50 class XWindow;
52 namespace sdbc
54 class XDatabaseMetaData;
55 class XConnection;
57 namespace util
59 struct URL;
60 class XNumberFormatter;
62 namespace ucb { class XContent; }
63 namespace uno { class XComponentContext; }
66 namespace svt
68 class EditBrowseBox;
71 namespace vcl { class Window; }
72 namespace weld {
73 class Widget;
74 class Window;
76 class ToolBox;
77 namespace vcl { class Font; }
78 class SvNumberFormatter;
79 class SfxFilter;
81 namespace dbaui
84 /** creates a new connection and appends the eventlistener
85 @param _rsDataSourceName name of the datasource
86 @param _xDatabaseContext the database context
87 @param _rxContext the UNO component context
88 @param _rEvtLst the eventlistener which will be added to the new created connection
89 @param _rOUTConnection this parameter will be filled with the new created connection
90 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false
92 ::dbtools::SQLExceptionInfo createConnection(
93 const OUString& _rsDataSourceName,
94 const css::uno::Reference< css::container::XNameAccess >& _xDatabaseContext,
95 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
96 css::uno::Reference< css::lang::XEventListener> const & _rEvtLst,
97 css::uno::Reference< css::sdbc::XConnection>& _rOUTConnection );
98 /** creates a new connection and appends the eventlistener
99 @param _xDataSource the datasource
100 @param _rxContext the UNO component context
101 @param _rEvtLst the eventlistener which will be added to the new created connection
102 @param _rOUTConnection this parameter will be filled with the new created connection
103 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false
105 ::dbtools::SQLExceptionInfo createConnection(
106 const css::uno::Reference< css::beans::XPropertySet >& _xDataSource,
107 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
108 css::uno::Reference< css::lang::XEventListener> const & _rEvtLst,
109 css::uno::Reference< css::sdbc::XConnection>& _rOUTConnection );
111 /** fills a map and a vector with localized type names
112 @param _rxConnection the connection to access the metadata
113 @param _rsTypeNames a list of localized type names separated with ';'
114 @param _rTypeInfoMap the filled map with the type names
115 @param _rTypeInfoIters the vector filled with map iterators
117 void fillTypeInfo( const css::uno::Reference< css::sdbc::XConnection>& _rxConnection,
118 std::u16string_view _rsTypeNames,
119 OTypeInfoMap& _rTypeInfoMap,
120 std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters);
122 /** fill a column with data of a field description
123 @param _rxColumn the column which should be filled
124 @param _pFieldDesc the source of the data
126 class OFieldDescription;
127 void setColumnProperties( const css::uno::Reference< css::beans::XPropertySet>& _rxColumn,
128 const OFieldDescription* _pFieldDesc);
130 OUString createDefaultName( const css::uno::Reference< css::sdbc::XDatabaseMetaData>& _xMetaData,
131 const css::uno::Reference< css::container::XNameAccess>& _xTables,
132 const OUString& _sName);
134 /** checks if the given name exists in the database context
136 bool checkDataSourceAvailable( const OUString& _sDataSourceName,
137 const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
139 /** maps SvxCellHorJustify to css::awt::TextAlign
140 @param SvxCellHorJustify& _eAlignment
141 @return the corresponding css::awt::TextAlign
143 sal_Int32 mapTextAlign(const SvxCellHorJustify& _eAlignment);
145 /** retrieves a data source given by name or URL, and displays an error if this fails
147 Any <type scope="css::sdbc">SQLException</type>s which occur will be displayed.
148 Additionally, and Exceptions which indicate a data source name pointing to a non-existent database
149 URL will also be denoted. Yet more additionally, and other exceptions will be forwarded to
150 a <type scope="css::sdb">InteractionHandler</type>.
152 @param _rDataSourceName
153 the URL of the database document, or the name of a registered data source
154 @param _pErrorMessageParent
155 the window to use as parent for error messages
156 @param _rxContext
157 a service factory to use for components to be created
158 @param _pErrorInfo
159 takes the error info in case of failure. If <NULL/>, the error is displayed to the user.
161 css::uno::Reference< css::sdbc::XDataSource >
162 getDataSourceByName(
163 const OUString& _rDataSourceName,
164 weld::Window* _pErrorMessageParent,
165 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
166 ::dbtools::SQLExceptionInfo* _pErrorInfo
169 /** returns either the model when data source is given as parameter,
170 or returns a data source when a model is given.
171 @param _xObject Either a data source or a model.
173 css::uno::Reference< css::uno::XInterface > getDataSourceOrModel(const css::uno::Reference< css::uno::XInterface >& _xObject);
175 /** maps css::awt::TextAlign to SvxCellHorJustify
176 @param css::awt::TextAlign& _nAlignment
177 @return the corresponding SvxCellHorJustify
179 SvxCellHorJustify mapTextJustify(sal_Int32 _nAlignment);
181 /** call the format dialog and set the selected format at the column
182 @param _xAffectedCol Font to be converted
183 @param _xField Font to be converted
185 void callColumnFormatDialog(const css::uno::Reference< css::beans::XPropertySet>& _xAffectedCol,
186 const css::uno::Reference< css::beans::XPropertySet>& _xField,
187 SvNumberFormatter* _pFormatter,
188 weld::Widget* _pParent);
190 /** second variant of the function before
192 bool callColumnFormatDialog(weld::Widget* _pParent,
193 SvNumberFormatter* _pFormatter,
194 sal_Int32 _nDataType,
195 sal_Int32& _nFormatKey,
196 SvxCellHorJustify& _eJustify,
197 bool _bHasFormat);
198 /** append a name to tablefilter of a datasource
199 @param xConnection the connection is need to get the datasource
200 @param rName the name which should be appended
201 @param rxContext needed to check if datasource is available
202 @param pParent needed when an error must be shown
203 @return false when datsource is not available otherwise true
205 bool appendToFilter(const css::uno::Reference< css::sdbc::XConnection>& xConnection,
206 const OUString& rName,
207 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
208 weld::Window* pParent);
210 /** notifySystemWindow adds or remove the given window _pToRegister at the Systemwindow found when search _pWindow.
211 @param _pWindow
212 The window which is used to search for the SystemWindow.
213 @param _pToRegister
214 The window which should be added or removed on the TaskPaneList.
215 @param _rMemFunc
216 The member function which should be called at the SystemWindow when found.
217 Possible values are:
218 ::comphelper::mem_fun(&TaskPaneList::AddWindow)
219 ::comphelper::mem_fun(&TaskPaneList::RemoveWindow)
221 void notifySystemWindow(vcl::Window const * _pWindow,
222 vcl::Window* _pToRegister,
223 const ::comphelper::mem_fun1_t<TaskPaneList,vcl::Window*>& _rMemFunc);
225 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId );
227 /** check if SQL92 name checking is enabled
228 @param _xConnection
229 Used to get the datasource as parent from the connection.
230 @return
231 <TRUE/> if so otherwise <FALSE/>
233 bool isSQL92CheckEnabled(const css::uno::Reference< css::sdbc::XConnection>& _xConnection);
235 /** check if the alias name of the table should be added at select statements
236 @param _xConnection
237 Used to get the datasource as parent from the connection.
238 @return
239 <TRUE/> if so otherwise <FALSE/>
241 bool isAppendTableAliasEnabled(const css::uno::Reference< css::sdbc::XConnection>& _xConnection);
243 /** determines whether when generating SQL statements, AS should be placed before a table alias
245 bool generateAsBeforeTableAlias( const css::uno::Reference< css::sdbc::XConnection>& _rxConnection );
247 /** fills the bool and string value with information out of the datasource info property
248 @param _xDatasource
249 Asked for the properties.
250 @param _rAutoIncrementValueEnabled
251 <OUT/> Set to sal_True when the property was set in the datasource.
252 @param _rsAutoIncrementValue
253 <OUT/> Set to the value when the property was set in the datasource.
255 void fillAutoIncrementValue(const css::uno::Reference< css::beans::XPropertySet>& _xDatasource
256 ,bool& _rAutoIncrementValueEnabled
257 ,OUString& _rsAutoIncrementValue);
259 /** fills the bool and string value with information out of the datasource info property
260 @param _xConnection
261 Used to get the datasource as parent from the connection.
262 @param _rAutoIncrementValueEnabled
263 <OUT/> Set to sal_True when the property was set in the datasource.
264 @param _rsAutoIncrementValue
265 <OUT/> Set to the value when the property was set in the datasource.
267 void fillAutoIncrementValue(const css::uno::Reference< css::sdbc::XConnection>& _xConnection
268 ,bool& _rAutoIncrementValueEnabled
269 ,OUString& _rsAutoIncrementValue);
271 /** set the evaluation flag at the number formatter
272 @param _rxFormatter
274 void setEvalDateFormatForFormatter(css::uno::Reference< css::util::XNumberFormatter > const & _rxFormatter);
276 /** query for a type info which can be used to create a primary key column
277 @param _rTypeInfo
278 The map which contains all available types.
279 @return
280 The type info which can be used to create a primary key column.
282 TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo);
284 /** query for a specific type.
285 @param _nDataType
286 The type we are searching.
287 @param _rTypeInfo
288 The map which contains all available types.
289 @return
290 The type or <NULL/> if we can't find it.
292 TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo);
294 /** returns the configuration node name of user defined drivers.
295 @return
296 the configuration node name of user defined drivers.
299 /** returns the result of the user action when view the query dialog.
300 @param pParent
301 The parent of the dialog
302 @param pTitle
303 A string resource id for the text which will be displayed as title.
304 @param pText
305 A string resource id for the text which will be displayed above the buttons.
306 When the string contains a #1. This will be replaced by the name.
307 @param bAll
308 When set to <TRUE/>, the all button will be appended.
309 @param rName
310 The name of the object to ask for.
311 @return
312 RET_YES, RET_NO, RET_ALL
314 sal_Int32 askForUserAction(weld::Window* pParent, TranslateId pTitle, TranslateId pText, bool bAll, std::u16string_view rName);
316 /** creates a new view from a query or table
317 @param _sName
318 The name of the view to be created.
319 @param _xConnection
320 The source connection.
321 @param _xSourceObject
322 The object for which a view should be created.
323 @return
324 The created view.
326 css::uno::Reference< css::beans::XPropertySet> createView( const OUString& _sName
327 ,const css::uno::Reference< css::sdbc::XConnection >& _xConnection
328 ,const css::uno::Reference< css::beans::XPropertySet>& _xSourceObject);
330 /** creates a view with the given command
332 css::uno::Reference< css::beans::XPropertySet> createView(
333 const OUString& _rName,
334 const css::uno::Reference< css::sdbc::XConnection >& _xConnection,
335 const OUString& _rCommand
338 /** returns the stripped database name.
339 @param _xDataSource
340 The data source
341 @param _rsDatabaseName
342 Will be filled with the original data source if it is empty.
343 @return
344 The stripped database name either the registered name or if it is a file url the last segment.
346 OUString getStrippedDatabaseName(const css::uno::Reference< css::beans::XPropertySet>& _xDataSource
347 ,OUString& _rsDatabaseName);
349 /** returns the standard database filter
350 @return
351 the filter
353 std::shared_ptr<const SfxFilter> getStandardDatabaseFilter();
355 /** opens a save dialog to store a form or report folder in the current hierarchy.
356 @param _pParent
357 The parent of the dialog.
358 @param _rxContext
359 a multi service factory which can be used to instantiate usual global services
360 @param _xNames
361 Where to insert the new object.
362 @param _sParentFolder
363 The name of the parent folder.
364 @param _bForm
365 <TRUE/> if a form should be inserted
366 @param _bCollection
367 A folder should be inserted
368 @param _xContent
369 The content which should be copied.
370 @param _bMove
371 if <TRUE/> the name of the content must be inserted without any change, otherwise not.
372 @return
373 <TRUE/> if the insert operation was successful, otherwise <FALSE/>.
375 bool insertHierarchyElement(
376 weld::Window* pParent,
377 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
378 const css::uno::Reference< css::container::XHierarchicalNameContainer>& _xNames,
379 const OUString& _sParentFolder,
380 bool _bForm,
381 bool _bCollection = true,
382 const css::uno::Reference< css::ucb::XContent>& _xContent = nullptr,
383 bool _bMove = false
386 /** creates a number formatter
387 @param _rxConnection
388 The connection is needed to create the formatter
389 @param _rxContext
390 The multi service factory
392 css::uno::Reference< css::util::XNumberFormatter > getNumberFormatter(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,const css::uno::Reference< css::uno::XComponentContext >& _rxContext );
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */