Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/fmcomp/fmgridcl.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <svx/fmgridif.hxx>
21
#include <fmprop.hxx>
22
#include <svx/fmtools.hxx>
23
#include <fmservs.hxx>
24
#include <fmurl.hxx>
25
#include <formcontrolfactory.hxx>
26
#include <gridcell.hxx>
27
#include <gridcols.hxx>
28
#include <svx/dbaexchange.hxx>
29
#include <svx/dialmgr.hxx>
30
#include <svx/strings.hrc>
31
#include <svx/fmgridcl.hxx>
32
#include <svx/svxdlg.hxx>
33
#include <svx/svxids.hrc>
34
#include <bitmaps.hlst>
35
36
#include <com/sun/star/form/XConfirmDeleteListener.hpp>
37
#include <com/sun/star/form/XFormComponent.hpp>
38
#include <com/sun/star/form/XGridColumnFactory.hpp>
39
#include <com/sun/star/io/XPersistObject.hpp>
40
#include <com/sun/star/sdb/CommandType.hpp>
41
#include <com/sun/star/sdb/RowChangeAction.hpp>
42
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
43
#include <com/sun/star/sdbc/DataType.hpp>
44
#include <com/sun/star/sdbc/SQLException.hpp>
45
#include <com/sun/star/sdbc/XPreparedStatement.hpp>
46
#include <com/sun/star/sdbc/XResultSetUpdate.hpp>
47
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
48
#include <com/sun/star/sdbcx/XDeleteRows.hpp>
49
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
50
#include <com/sun/star/util/XNumberFormats.hpp>
51
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
52
#include <com/sun/star/util/URLTransformer.hpp>
53
#include <com/sun/star/util/XURLTransformer.hpp>
54
#include <com/sun/star/view/XSelectionSupplier.hpp>
55
#include <comphelper/processfactory.hxx>
56
#include <comphelper/property.hxx>
57
#include <comphelper/string.hxx>
58
#include <comphelper/types.hxx>
59
#include <connectivity/dbtools.hxx>
60
#include <sfx2/dispatch.hxx>
61
#include <sfx2/viewfrm.hxx>
62
#include <svl/eitem.hxx>
63
#include <vcl/accessibility/AccessibleBrowseBoxObjType.hxx>
64
#include <vcl/commandevent.hxx>
65
#include <vcl/svapp.hxx>
66
#include <tools/debug.hxx>
67
#include <tools/mapunit.hxx>
68
#include <tools/multisel.hxx>
69
#include <comphelper/diagnose_ex.hxx>
70
#include <vcl/help.hxx>
71
#include <vcl/settings.hxx>
72
#include <vcl/weld/Builder.hxx>
73
#include <vcl/weld/Menu.hxx>
74
#include <vcl/weld/Window.hxx>
75
#include <sal/log.hxx>
76
#include <i18nlangtag/languagetag.hxx>
77
#include <memory>
78
79
using namespace ::com::sun::star::uno;
80
using namespace ::com::sun::star::view;
81
using namespace ::com::sun::star::beans;
82
using namespace ::com::sun::star::lang;
83
using namespace ::com::sun::star::sdbcx;
84
using namespace ::com::sun::star::sdbc;
85
using namespace ::com::sun::star::sdb;
86
using namespace ::com::sun::star::form;
87
using namespace ::com::sun::star::util;
88
using namespace ::com::sun::star::container;
89
using namespace ::cppu;
90
using namespace ::svxform;
91
using namespace ::svx;
92
using namespace ::dbtools;
93
94
struct FmGridHeaderData
95
{
96
    ODataAccessDescriptor   aDropData;
97
    Point                   aDropPosPixel;
98
    sal_Int8                nDropAction;
99
    Reference< XInterface > xDroppedStatement;
100
    Reference< XInterface > xDroppedResultSet;
101
};
102
103
static void InsertMenuItem(weld::Menu& rMenu, int nMenuPos, const OUString& id, const OUString& rText, const OUString& rImgId)
104
0
{
105
0
    rMenu.insert(nMenuPos, id, rText, &rImgId, nullptr, nullptr, TRISTATE_INDET);
106
0
}
107
108
FmGridHeader::FmGridHeader( BrowseBox* pParent, WinBits nWinBits)
109
0
        :EditBrowserHeader(pParent, nWinBits)
110
0
        ,DropTargetHelper(this)
111
0
        ,m_pImpl(new FmGridHeaderData)
112
0
{
113
0
}
Unexecuted instantiation: FmGridHeader::FmGridHeader(BrowseBox*, long)
Unexecuted instantiation: FmGridHeader::FmGridHeader(BrowseBox*, long)
114
115
FmGridHeader::~FmGridHeader()
116
0
{
117
0
    disposeOnce();
118
0
}
119
120
void FmGridHeader::dispose()
121
0
{
122
0
    m_pImpl.reset();
123
0
    DropTargetHelper::dispose();
124
0
    svt::EditBrowserHeader::dispose();
125
0
}
126
127
sal_uInt16 FmGridHeader::GetModelColumnPos(sal_uInt16 nId) const
128
0
{
129
0
    return static_cast<FmGridControl*>(GetParent())->GetModelColumnPos(nId);
130
0
}
131
132
void FmGridHeader::notifyColumnSelect(sal_uInt16 nColumnId)
133
0
{
134
0
    sal_uInt16 nPos = GetModelColumnPos(nColumnId);
135
0
    Reference< XIndexAccess >  xColumns = static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns();
136
0
    if ( nPos < xColumns->getCount() )
137
0
    {
138
0
        Reference< XSelectionSupplier >  xSelSupplier(xColumns, UNO_QUERY);
139
0
        if ( xSelSupplier.is() )
140
0
        {
141
0
            Reference< XPropertySet >  xColumn;
142
0
            xColumns->getByIndex(nPos) >>= xColumn;
143
0
            xSelSupplier->select(Any(xColumn));
144
0
        }
145
0
    }
146
0
}
147
148
void FmGridHeader::Select()
149
0
{
150
0
    EditBrowserHeader::Select();
151
0
    notifyColumnSelect(GetCurItemId());
152
0
}
153
154
void FmGridHeader::RequestHelp( const HelpEvent& rHEvt )
155
0
{
156
0
    sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
157
0
    if ( nItemId )
158
0
    {
159
0
        if ( rHEvt.GetMode() & (HelpEventMode::QUICK | HelpEventMode::BALLOON) )
160
0
        {
161
0
            tools::Rectangle aItemRect = GetItemRect( nItemId );
162
0
            Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
163
0
            aItemRect.SetLeft( aPt.X() );
164
0
            aItemRect.SetTop( aPt.Y() );
165
0
            aPt = OutputToScreenPixel( aItemRect.BottomRight() );
166
0
            aItemRect.SetRight( aPt.X() );
167
0
            aItemRect.SetBottom( aPt.Y() );
168
169
0
            sal_uInt16 nPos = GetModelColumnPos(nItemId);
170
0
            Reference< css::container::XIndexContainer >  xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
171
0
            try
172
0
            {
173
0
                Reference< css::beans::XPropertySet >  xColumn(xColumns->getByIndex(nPos),UNO_QUERY);
174
0
                OUString aHelpText;
175
0
                xColumn->getPropertyValue(FM_PROP_HELPTEXT) >>= aHelpText;
176
0
                if ( aHelpText.isEmpty() )
177
0
                    xColumn->getPropertyValue(FM_PROP_DESCRIPTION) >>= aHelpText;
178
0
                if ( !aHelpText.isEmpty() )
179
0
                {
180
0
                    if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
181
0
                        Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText );
182
0
                    else
183
0
                        Help::ShowQuickHelp( this, aItemRect, aHelpText );
184
0
                    return;
185
0
                }
186
0
            }
187
0
            catch(Exception&)
188
0
            {
189
0
                return;
190
0
            }
191
0
        }
192
0
    }
193
0
    EditBrowserHeader::RequestHelp( rHEvt );
194
0
}
195
196
sal_Int8 FmGridHeader::AcceptDrop( const AcceptDropEvent& rEvt )
197
0
{
198
    // drop allowed in design mode only
199
0
    if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode())
200
0
        return DND_ACTION_NONE;
201
202
    // search for recognized formats
203
0
    const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
204
0
    if (OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::COLUMN_DESCRIPTOR | ColumnTransferFormatFlags::FIELD_DESCRIPTOR))
205
0
        return rEvt.mnAction;
206
207
0
    return DND_ACTION_NONE;
208
0
}
209
210
sal_Int8 FmGridHeader::ExecuteDrop( const ExecuteDropEvent& _rEvt )
211
0
{
212
0
    if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode())
213
0
        return DND_ACTION_NONE;
214
215
0
    TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
216
217
    // check the formats
218
0
    bool bColumnDescriptor  = OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), ColumnTransferFormatFlags::COLUMN_DESCRIPTOR);
219
0
    bool bFieldDescriptor   = OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), ColumnTransferFormatFlags::FIELD_DESCRIPTOR);
220
0
    if (!bColumnDescriptor && !bFieldDescriptor)
221
0
    {
222
0
        OSL_FAIL("FmGridHeader::ExecuteDrop: should never have reached this (no extractable format)!");
223
0
        return DND_ACTION_NONE;
224
0
    }
225
226
    // extract the descriptor
227
0
    OUString sDatasource, sCommand, sFieldName,sDatabaseLocation;
228
0
    sal_Int32       nCommandType = CommandType::COMMAND;
229
0
    Reference< XPreparedStatement >     xStatement;
230
0
    Reference< XResultSet >             xResultSet;
231
0
    Reference< XPropertySet >           xField;
232
0
    Reference< XConnection >            xConnection;
233
234
0
    ODataAccessDescriptor aColumn = OColumnTransferable::extractColumnDescriptor(aDroppedData);
235
0
    if (aColumn.has(DataAccessDescriptorProperty::DataSource))  aColumn[DataAccessDescriptorProperty::DataSource]   >>= sDatasource;
236
0
    if (aColumn.has(DataAccessDescriptorProperty::DatabaseLocation))    aColumn[DataAccessDescriptorProperty::DatabaseLocation] >>= sDatabaseLocation;
237
0
    if (aColumn.has(DataAccessDescriptorProperty::Command))     aColumn[DataAccessDescriptorProperty::Command]      >>= sCommand;
238
0
    if (aColumn.has(DataAccessDescriptorProperty::CommandType)) aColumn[DataAccessDescriptorProperty::CommandType]  >>= nCommandType;
239
0
    if (aColumn.has(DataAccessDescriptorProperty::ColumnName))  aColumn[DataAccessDescriptorProperty::ColumnName]   >>= sFieldName;
240
0
    if (aColumn.has(DataAccessDescriptorProperty::ColumnObject))aColumn[DataAccessDescriptorProperty::ColumnObject] >>= xField;
241
0
    if (aColumn.has(DataAccessDescriptorProperty::Connection))  aColumn[DataAccessDescriptorProperty::Connection]   >>= xConnection;
242
243
0
    if  (   sFieldName.isEmpty()
244
0
        ||  sCommand.isEmpty()
245
0
        ||  (   sDatasource.isEmpty()
246
0
            &&  sDatabaseLocation.isEmpty()
247
0
            &&  !xConnection.is()
248
0
            )
249
0
        )
250
0
    {
251
0
        OSL_FAIL( "FmGridHeader::ExecuteDrop: somebody started a nonsense drag operation!!" );
252
0
        return DND_ACTION_NONE;
253
0
    }
254
255
0
    try
256
0
    {
257
        // need a connection
258
0
        if (!xConnection.is())
259
0
        {   // the transferable did not contain the connection -> build an own one
260
0
            try
261
0
            {
262
0
                OUString sSignificantSource( sDatasource.isEmpty() ? sDatabaseLocation : sDatasource );
263
0
                xConnection = getConnection_withFeedback(sSignificantSource, OUString(), OUString(),
264
0
                                  static_cast<FmGridControl*>(GetParent())->getContext(), nullptr );
265
0
            }
266
0
            catch(NoSuchElementException&)
267
0
            {   // allowed, means sDatasource isn't a valid data source name...
268
0
            }
269
0
            catch(Exception&)
270
0
            {
271
0
                OSL_FAIL("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
272
0
            }
273
274
0
            if (!xConnection.is())
275
0
            {
276
0
                OSL_FAIL("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
277
0
                return DND_ACTION_NONE;
278
0
            }
279
0
        }
280
281
        // try to obtain the column object
282
0
        if (!xField.is())
283
0
        {
284
#ifdef DBG_UTIL
285
            Reference< XServiceInfo >  xServiceInfo(xConnection, UNO_QUERY);
286
            DBG_ASSERT(xServiceInfo.is() && xServiceInfo->supportsService(SRV_SDB_CONNECTION), "FmGridHeader::ExecuteDrop: invalid connection (no database access connection !)");
287
#endif
288
289
0
            Reference< XNameAccess > xFields;
290
0
            switch (nCommandType)
291
0
            {
292
0
                case CommandType::TABLE:
293
0
                {
294
0
                    Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
295
0
                    Reference< XColumnsSupplier >  xSupplyColumns;
296
0
                    xSupplyTables->getTables()->getByName(sCommand) >>= xSupplyColumns;
297
0
                    xFields = xSupplyColumns->getColumns();
298
0
                }
299
0
                break;
300
0
                case CommandType::QUERY:
301
0
                {
302
0
                    Reference< XQueriesSupplier > xSupplyQueries(xConnection, UNO_QUERY);
303
0
                    Reference< XColumnsSupplier > xSupplyColumns;
304
0
                    xSupplyQueries->getQueries()->getByName(sCommand) >>= xSupplyColumns;
305
0
                    xFields  = xSupplyColumns->getColumns();
306
0
                }
307
0
                break;
308
0
                default:
309
0
                {
310
0
                    xStatement = xConnection->prepareStatement(sCommand);
311
                    // not interested in any results
312
313
0
                    Reference< XPropertySet > xStatProps(xStatement,UNO_QUERY);
314
0
                    xStatProps->setPropertyValue(u"MaxRows"_ustr, Any(sal_Int32(0)));
315
316
0
                    xResultSet = xStatement->executeQuery();
317
0
                    Reference< XColumnsSupplier >  xSupplyCols(xResultSet, UNO_QUERY);
318
0
                    if (xSupplyCols.is())
319
0
                        xFields = xSupplyCols->getColumns();
320
0
                }
321
0
            }
322
323
0
            if (xFields.is() && xFields->hasByName(sFieldName))
324
0
                xFields->getByName(sFieldName) >>= xField;
325
326
0
            if (!xField.is())
327
0
            {
328
0
                ::comphelper::disposeComponent(xStatement);
329
0
                return DND_ACTION_NONE;
330
0
            }
331
0
        }
332
333
        // do the drop asynchronously
334
        // (85957 - UI actions within the drop are not allowed, but we want to open a popup menu)
335
0
        m_pImpl->aDropData = std::move(aColumn);
336
0
        m_pImpl->aDropData[DataAccessDescriptorProperty::Connection] <<= xConnection;
337
0
        m_pImpl->aDropData[DataAccessDescriptorProperty::ColumnObject] <<= xField;
338
339
0
        m_pImpl->nDropAction = _rEvt.mnAction;
340
0
        m_pImpl->aDropPosPixel = _rEvt.maPosPixel;
341
0
        m_pImpl->xDroppedStatement = xStatement;
342
0
        m_pImpl->xDroppedResultSet = xResultSet;
343
344
0
        PostUserEvent(LINK(this, FmGridHeader, OnAsyncExecuteDrop), nullptr, true);
345
0
    }
346
0
    catch (Exception&)
347
0
    {
348
0
        TOOLS_WARN_EXCEPTION("svx", "caught an exception while creatin' the column !");
349
0
        ::comphelper::disposeComponent(xStatement);
350
0
        return DND_ACTION_NONE;
351
0
    }
352
353
0
    return DND_ACTION_LINK;
354
0
}
355
356
IMPL_LINK_NOARG( FmGridHeader, OnAsyncExecuteDrop, void*, void )
357
0
{
358
0
    OUString             sCommand, sFieldName,sURL;
359
0
    sal_Int32                   nCommandType = CommandType::COMMAND;
360
0
    Reference< XPropertySet >   xField;
361
0
    Reference< XConnection >    xConnection;
362
363
0
    OUString sDatasource = m_pImpl->aDropData.getDataSource();
364
0
    if ( sDatasource.isEmpty() && m_pImpl->aDropData.has(DataAccessDescriptorProperty::ConnectionResource) )
365
0
        m_pImpl->aDropData[DataAccessDescriptorProperty::ConnectionResource]    >>= sURL;
366
0
    m_pImpl->aDropData[DataAccessDescriptorProperty::Command]       >>= sCommand;
367
0
    m_pImpl->aDropData[DataAccessDescriptorProperty::CommandType]   >>= nCommandType;
368
0
    m_pImpl->aDropData[DataAccessDescriptorProperty::ColumnName]    >>= sFieldName;
369
0
    m_pImpl->aDropData[DataAccessDescriptorProperty::Connection]    >>= xConnection;
370
0
    m_pImpl->aDropData[DataAccessDescriptorProperty::ColumnObject]  >>= xField;
371
372
0
    try
373
0
    {
374
        // need number formats
375
0
        Reference< XNumberFormatsSupplier > xSupplier = getNumberFormats(xConnection, true);
376
0
        Reference< XNumberFormats >  xNumberFormats;
377
0
        if (xSupplier.is())
378
0
            xNumberFormats = xSupplier->getNumberFormats();
379
0
        if (!xNumberFormats.is())
380
0
        {
381
0
            ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
382
0
            ::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
383
0
            return;
384
0
        }
385
386
        // The field now needs two pieces of information:
387
        // a.) Name of the field for label and ControlSource
388
        // b.) FormatKey, to determine which field is to be created
389
0
        sal_Int32 nDataType = 0;
390
0
        xField->getPropertyValue(FM_PROP_FIELDTYPE) >>= nDataType;
391
        // these datatypes can not be processed in Gridcontrol
392
0
        switch (nDataType)
393
0
        {
394
0
            case DataType::BLOB:
395
0
            case DataType::LONGVARBINARY:
396
0
            case DataType::BINARY:
397
0
            case DataType::VARBINARY:
398
0
            case DataType::OTHER:
399
0
                ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
400
0
                ::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
401
0
                return;
402
0
        }
403
404
        // Creating the column
405
0
        Reference< XIndexContainer >  xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
406
0
        Reference< XGridColumnFactory >  xFactory(xCols, UNO_QUERY);
407
408
0
        sal_uInt16 nColId = GetItemId(m_pImpl->aDropPosPixel);
409
        // insert position, always before the current column
410
0
        sal_uInt16 nPos = GetModelColumnPos(nColId);
411
0
        Reference< XPropertySet >  xCol, xSecondCol;
412
413
        // Create Column based on type, default textfield
414
0
        std::vector<OUString> aPossibleTypes;
415
0
        std::vector<OUString> aImgResId;
416
0
        std::vector<TranslateId> aStrResId;
417
418
0
        switch (nDataType)
419
0
        {
420
0
            case DataType::BIT:
421
0
            case DataType::BOOLEAN:
422
0
                aPossibleTypes.emplace_back(FM_COL_CHECKBOX);
423
0
                aImgResId.emplace_back(RID_SVXBMP_CHECKBOX);
424
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_CHECKBOX);
425
0
                break;
426
0
            case DataType::TINYINT:
427
0
            case DataType::SMALLINT:
428
0
            case DataType::INTEGER:
429
0
                aPossibleTypes.emplace_back(FM_COL_NUMERICFIELD);
430
0
                aImgResId.emplace_back(RID_SVXBMP_NUMERICFIELD);
431
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_NUMERICFIELD);
432
0
                aPossibleTypes.emplace_back(FM_COL_FORMATTEDFIELD);
433
0
                aImgResId.emplace_back(RID_SVXBMP_FORMATTEDFIELD);
434
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_FORMATTED);
435
0
                break;
436
0
            case DataType::REAL:
437
0
            case DataType::DOUBLE:
438
0
            case DataType::NUMERIC:
439
0
            case DataType::DECIMAL:
440
0
                aPossibleTypes.emplace_back(FM_COL_FORMATTEDFIELD);
441
0
                aImgResId.emplace_back(RID_SVXBMP_FORMATTEDFIELD);
442
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_FORMATTED);
443
0
                aPossibleTypes.emplace_back(FM_COL_NUMERICFIELD);
444
0
                aImgResId.emplace_back(RID_SVXBMP_NUMERICFIELD);
445
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_NUMERICFIELD);
446
0
                break;
447
0
            case DataType::TIMESTAMP:
448
0
                aPossibleTypes.emplace_back("dateandtimefield");
449
0
                aImgResId.emplace_back(RID_SVXBMP_DATE_N_TIME_FIELDS);
450
0
                aStrResId.emplace_back(RID_STR_DATE_AND_TIME);
451
0
                aPossibleTypes.emplace_back(FM_COL_DATEFIELD);
452
0
                aImgResId.emplace_back(RID_SVXBMP_DATEFIELD);
453
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_DATEFIELD);
454
0
                aPossibleTypes.emplace_back(FM_COL_TIMEFIELD);
455
0
                aImgResId.emplace_back(RID_SVXBMP_TIMEFIELD);
456
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_TIMEFIELD);
457
0
                aPossibleTypes.emplace_back(FM_COL_FORMATTEDFIELD);
458
0
                aImgResId.emplace_back(RID_SVXBMP_FORMATTEDFIELD);
459
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_FORMATTED);
460
0
                break;
461
0
            case DataType::DATE:
462
0
                aPossibleTypes.emplace_back(FM_COL_DATEFIELD);
463
0
                aImgResId.emplace_back(RID_SVXBMP_DATEFIELD);
464
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_DATEFIELD);
465
0
                aPossibleTypes.emplace_back(FM_COL_FORMATTEDFIELD);
466
0
                aImgResId.emplace_back(RID_SVXBMP_FORMATTEDFIELD);
467
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_FORMATTED);
468
0
                break;
469
0
            case DataType::TIME:
470
0
                aPossibleTypes.emplace_back(FM_COL_TIMEFIELD);
471
0
                aImgResId.emplace_back(RID_SVXBMP_TIMEFIELD);
472
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_TIMEFIELD);
473
0
                aPossibleTypes.emplace_back(FM_COL_FORMATTEDFIELD);
474
0
                aImgResId.emplace_back(RID_SVXBMP_FORMATTEDFIELD);
475
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_FORMATTED);
476
0
                break;
477
0
            case DataType::CHAR:
478
0
            case DataType::VARCHAR:
479
0
            case DataType::LONGVARCHAR:
480
0
            default:
481
0
                aPossibleTypes.emplace_back(FM_COL_TEXTFIELD);
482
0
                aImgResId.emplace_back(RID_SVXBMP_EDITBOX);
483
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_EDIT);
484
0
                aPossibleTypes.emplace_back(FM_COL_FORMATTEDFIELD);
485
0
                aImgResId.emplace_back(RID_SVXBMP_FORMATTEDFIELD);
486
0
                aStrResId.emplace_back(RID_STR_PROPTITLE_FORMATTED);
487
0
                break;
488
0
        }
489
        // if it's a currency field, a "currency field" option
490
0
        try
491
0
        {
492
0
            if  (   ::comphelper::hasProperty(FM_PROP_ISCURRENCY, xField)
493
0
                &&  ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISCURRENCY)))
494
0
            {
495
0
                aPossibleTypes.insert(aPossibleTypes.begin(), u"" FM_COL_CURRENCYFIELD ""_ustr);
496
0
                aImgResId.insert(aImgResId.begin(), RID_SVXBMP_CURRENCYFIELD);
497
0
                aStrResId.insert(aStrResId.begin(), RID_STR_PROPTITLE_CURRENCYFIELD);
498
0
            }
499
0
        }
500
0
        catch (const Exception&)
501
0
        {
502
0
            TOOLS_WARN_EXCEPTION("svx", "");
503
0
        }
504
505
0
        assert(aPossibleTypes.size() == aImgResId.size());
506
507
0
        bool bDateNTimeCol = false;
508
0
        if (!aPossibleTypes.empty())
509
0
        {
510
0
            OUString sPreferredType = aPossibleTypes[0];
511
0
            if ((m_pImpl->nDropAction == DND_ACTION_LINK) && (aPossibleTypes.size() > 1))
512
0
            {
513
0
                std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, u"svx/ui/colsmenu.ui"_ustr));
514
0
                std::unique_ptr<weld::Menu> xTypeMenu(xBuilder->weld_menu(u"insertmenu"_ustr));
515
516
0
                int nMenuPos = 0;
517
0
                std::vector<OUString>::const_iterator iter;
518
0
                std::vector<TranslateId>::const_iterator striter;
519
0
                std::vector<OUString>::const_iterator imgiter;
520
0
                for (iter = aPossibleTypes.begin(), imgiter = aImgResId.begin(), striter = aStrResId.begin();
521
0
                     iter != aPossibleTypes.end(); ++iter, ++striter, ++imgiter)
522
0
                {
523
0
                    InsertMenuItem(*xTypeMenu, nMenuPos++, *iter, SvxResId(*striter), *imgiter);
524
0
                }
525
526
0
                ::tools::Rectangle aRect(m_pImpl->aDropPosPixel, Size(1,1));
527
0
                weld::Window* pParent = weld::GetPopupParent(*this, aRect);
528
0
                OUString sResult = xTypeMenu->popup_at_rect(pParent, aRect);
529
0
                if (!sResult.isEmpty())
530
0
                    sPreferredType = sResult;
531
0
            }
532
533
0
            bDateNTimeCol = sPreferredType == "dateandtimefield";
534
0
            sal_uInt16 nColCount = bDateNTimeCol ? 2 : 1;
535
0
            OUString sFieldService;
536
0
            while (nColCount--)
537
0
            {
538
0
                if (bDateNTimeCol)
539
0
                    sPreferredType = nColCount ? FM_COL_DATEFIELD : FM_COL_TIMEFIELD;
540
541
0
                sFieldService = sPreferredType;
542
0
                Reference< XPropertySet >  xThisRoundCol;
543
0
                if ( !sFieldService.isEmpty() )
544
0
                    xThisRoundCol = xFactory->createColumn(sFieldService);
545
0
                if (nColCount)
546
0
                    xSecondCol = std::move(xThisRoundCol);
547
0
                else
548
0
                    xCol = std::move(xThisRoundCol);
549
0
            }
550
0
        }
551
552
0
        if (!xCol.is() || (bDateNTimeCol && !xSecondCol.is()))
553
0
        {
554
0
            ::comphelper::disposeComponent(xCol);   // in case only the creation of the second column failed
555
0
            ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
556
0
            ::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
557
0
            return;
558
0
        }
559
560
0
        if (bDateNTimeCol)
561
0
        {
562
0
            OUString sTimePostfix(SvxResId(RID_STR_POSTFIX_TIME));
563
0
            xCol->setPropertyValue(FM_PROP_LABEL, Any( OUString( sFieldName + sTimePostfix ) ) );
564
565
0
            OUString sDatePostfix(SvxResId( RID_STR_POSTFIX_DATE));
566
0
            xSecondCol->setPropertyValue(FM_PROP_LABEL, Any( OUString( sFieldName + sDatePostfix ) ) );
567
0
        }
568
0
        else
569
0
            xCol->setPropertyValue(FM_PROP_LABEL, Any(sFieldName));
570
571
        // insert now
572
0
        Any aElement;
573
0
        aElement <<= xCol;
574
575
0
        xCols->insertByIndex(nPos, aElement);
576
577
0
        FormControlFactory aControlFactory;
578
0
        aControlFactory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xCol );
579
0
        FormControlFactory::initializeFieldDependentProperties( xField, xCol, xNumberFormats );
580
581
0
        xCol->setPropertyValue(FM_PROP_CONTROLSOURCE, Any(sFieldName));
582
0
        if ( xSecondCol.is() )
583
0
            xSecondCol->setPropertyValue(FM_PROP_CONTROLSOURCE, Any(sFieldName));
584
585
0
        if (bDateNTimeCol)
586
0
        {
587
0
            OUString aPostfix[] = {
588
0
                SvxResId(RID_STR_POSTFIX_DATE),
589
0
                SvxResId(RID_STR_POSTFIX_TIME)
590
0
            };
591
592
0
            for ( size_t i=0; i<2; ++i )
593
0
            {
594
0
                OUString sPurePostfix = comphelper::string::stripStart(aPostfix[i], ' ');
595
0
                sPurePostfix = comphelper::string::stripStart(sPurePostfix, '(');
596
0
                sPurePostfix = comphelper::string::stripEnd(sPurePostfix, ')');
597
0
                OUString sRealName = sFieldName + "_" + sPurePostfix;
598
0
                if (i)
599
0
                    xSecondCol->setPropertyValue(FM_PROP_NAME, Any(sRealName));
600
0
                else
601
0
                    xCol->setPropertyValue(FM_PROP_NAME, Any(sRealName));
602
0
            }
603
0
        }
604
0
        else
605
0
            xCol->setPropertyValue(FM_PROP_NAME, Any(sFieldName));
606
607
0
        if (bDateNTimeCol)
608
0
        {
609
0
            aElement <<= xSecondCol;
610
0
            xCols->insertByIndex(nPos == sal_uInt16(-1) ? nPos : ++nPos, aElement);
611
0
        }
612
613
        // is the component::Form tied to the database?
614
0
        Reference< XFormComponent >  xFormCp(xCols, UNO_QUERY);
615
0
        Reference< XPropertySet >  xForm(xFormCp->getParent(), UNO_QUERY);
616
0
        if (xForm.is())
617
0
        {
618
0
            if (::comphelper::getString(xForm->getPropertyValue(FM_PROP_DATASOURCE)).isEmpty())
619
0
            {
620
0
                if ( !sDatasource.isEmpty() )
621
0
                    xForm->setPropertyValue(FM_PROP_DATASOURCE, Any(sDatasource));
622
0
                else
623
0
                    xForm->setPropertyValue(FM_PROP_URL, Any(sURL));
624
0
            }
625
626
0
            if (::comphelper::getString(xForm->getPropertyValue(FM_PROP_COMMAND)).isEmpty())
627
0
            {
628
0
                xForm->setPropertyValue(FM_PROP_COMMAND, Any(sCommand));
629
0
                Any aCommandType;
630
0
                switch (nCommandType)
631
0
                {
632
0
                    case CommandType::TABLE:
633
0
                        aCommandType <<= sal_Int32(CommandType::TABLE);
634
0
                        break;
635
0
                    case CommandType::QUERY:
636
0
                        aCommandType <<= sal_Int32(CommandType::QUERY);
637
0
                        break;
638
0
                    default:
639
0
                        aCommandType <<= sal_Int32(CommandType::COMMAND);
640
0
                        xForm->setPropertyValue(FM_PROP_ESCAPE_PROCESSING, css::uno::Any(2 == nCommandType));
641
0
                        break;
642
0
                }
643
0
                xForm->setPropertyValue(FM_PROP_COMMANDTYPE, aCommandType);
644
0
            }
645
0
        }
646
0
    }
647
0
    catch (Exception&)
648
0
    {
649
0
        TOOLS_WARN_EXCEPTION("svx", "caught an exception while creatin' the column !");
650
0
        ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
651
0
        ::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
652
0
        return;
653
0
    }
654
655
0
    ::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
656
0
    ::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
657
0
}
658
659
void FmGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, weld::Menu& rMenu,
660
                                               weld::Menu& rInsertMenu, weld::Menu& rChangeMenu,
661
                                               weld::Menu& rShowMenu)
662
0
{
663
0
    bool bDesignMode = static_cast<FmGridControl*>(GetParent())->IsDesignMode();
664
665
0
    Reference< css::container::XIndexContainer >  xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
666
    // Building of the Insert Menu
667
    // mark the column if nColId != HEADERBAR_ITEM_NOTFOUND
668
0
    if(nColId > 0)
669
0
    {
670
0
        sal_uInt16 nPos2 = GetModelColumnPos(nColId);
671
672
0
        Reference< css::container::XIndexContainer >  xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
673
0
        Reference< css::beans::XPropertySet>          xColumn( xColumns->getByIndex(nPos2), css::uno::UNO_QUERY);
674
0
        Reference< css::view::XSelectionSupplier >    xSelSupplier(xColumns, UNO_QUERY);
675
0
        if (xSelSupplier.is())
676
0
            xSelSupplier->select(Any(xColumn));
677
0
    }
678
679
    // insert position, always before the current column
680
0
    sal_uInt16 nPos = GetModelColumnPos(nColId);
681
0
    bool bMarked = nColId && static_cast<FmGridControl*>(GetParent())->isColumnMarked(nColId);
682
683
0
    if (bDesignMode)
684
0
    {
685
0
        int nMenuPos = 0;
686
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_TEXTFIELD ""_ustr, SvxResId(RID_STR_PROPTITLE_EDIT), RID_SVXBMP_EDITBOX);
687
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_CHECKBOX ""_ustr, SvxResId(RID_STR_PROPTITLE_CHECKBOX), RID_SVXBMP_CHECKBOX);
688
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_COMBOBOX ""_ustr, SvxResId(RID_STR_PROPTITLE_COMBOBOX), RID_SVXBMP_COMBOBOX);
689
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_LISTBOX ""_ustr, SvxResId(RID_STR_PROPTITLE_LISTBOX), RID_SVXBMP_LISTBOX);
690
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_DATEFIELD ""_ustr, SvxResId(RID_STR_PROPTITLE_DATEFIELD), RID_SVXBMP_DATEFIELD);
691
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_TIMEFIELD ""_ustr, SvxResId(RID_STR_PROPTITLE_TIMEFIELD), RID_SVXBMP_TIMEFIELD);
692
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_NUMERICFIELD ""_ustr, SvxResId(RID_STR_PROPTITLE_NUMERICFIELD), RID_SVXBMP_NUMERICFIELD);
693
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_CURRENCYFIELD ""_ustr, SvxResId(RID_STR_PROPTITLE_CURRENCYFIELD), RID_SVXBMP_CURRENCYFIELD);
694
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_PATTERNFIELD ""_ustr, SvxResId(RID_STR_PROPTITLE_PATTERNFIELD), RID_SVXBMP_PATTERNFIELD);
695
0
        InsertMenuItem(rInsertMenu, nMenuPos++, u"" FM_COL_FORMATTEDFIELD ""_ustr, SvxResId(RID_STR_PROPTITLE_FORMATTED), RID_SVXBMP_FORMATTEDFIELD);
696
0
    }
697
698
0
    if (xCols.is() && nColId)
699
0
    {
700
0
        Reference< css::beans::XPropertySet > xPropSet( xCols->getByIndex(nPos), css::uno::UNO_QUERY);
701
702
0
        Reference< css::io::XPersistObject >  xServiceQuestion(xPropSet, UNO_QUERY);
703
0
        sal_Int32 nColType = xServiceQuestion.is() ? getColumnTypeByModelName(xServiceQuestion->getServiceName()) : 0;
704
0
        if (nColType == TYPE_TEXTFIELD)
705
0
        {   // edit fields and formatted fields have the same service name, thus getColumnTypeByModelName returns TYPE_TEXTFIELD
706
            // in both cases. And as columns don't have a css::lang::XServiceInfo interface, we have to distinguish both
707
            // types via the existence of special properties
708
0
            if (xPropSet.is())
709
0
            {
710
0
                Reference< css::beans::XPropertySetInfo >  xPropsInfo = xPropSet->getPropertySetInfo();
711
0
                if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(FM_PROP_FORMATSSUPPLIER))
712
0
                    nColType = TYPE_FORMATTEDFIELD;
713
0
            }
714
0
        }
715
716
0
        if (bDesignMode)
717
0
        {
718
0
            int nMenuPos = 0;
719
0
            if (nColType != TYPE_TEXTFIELD)
720
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_TEXTFIELD"1"_ustr, SvxResId(RID_STR_PROPTITLE_EDIT), RID_SVXBMP_EDITBOX);
721
0
            if (nColType != TYPE_CHECKBOX)
722
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_CHECKBOX"1"_ustr, SvxResId(RID_STR_PROPTITLE_CHECKBOX), RID_SVXBMP_CHECKBOX);
723
0
            if (nColType != TYPE_COMBOBOX)
724
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_COMBOBOX"1"_ustr, SvxResId(RID_STR_PROPTITLE_COMBOBOX), RID_SVXBMP_COMBOBOX);
725
0
            if (nColType != TYPE_LISTBOX)
726
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_LISTBOX"1"_ustr, SvxResId(RID_STR_PROPTITLE_LISTBOX), RID_SVXBMP_LISTBOX);
727
0
            if (nColType != TYPE_DATEFIELD)
728
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_DATEFIELD"1"_ustr, SvxResId(RID_STR_PROPTITLE_DATEFIELD), RID_SVXBMP_DATEFIELD);
729
0
            if (nColType != TYPE_TIMEFIELD)
730
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_TIMEFIELD"1"_ustr, SvxResId(RID_STR_PROPTITLE_TIMEFIELD), RID_SVXBMP_TIMEFIELD);
731
0
            if (nColType != TYPE_NUMERICFIELD)
732
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_NUMERICFIELD"1"_ustr, SvxResId(RID_STR_PROPTITLE_NUMERICFIELD), RID_SVXBMP_NUMERICFIELD);
733
0
            if (nColType != TYPE_CURRENCYFIELD)
734
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_CURRENCYFIELD"1"_ustr, SvxResId(RID_STR_PROPTITLE_CURRENCYFIELD), RID_SVXBMP_CURRENCYFIELD);
735
0
            if (nColType != TYPE_PATTERNFIELD)
736
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_PATTERNFIELD"1"_ustr, SvxResId(RID_STR_PROPTITLE_PATTERNFIELD), RID_SVXBMP_PATTERNFIELD);
737
0
            if (nColType != TYPE_FORMATTEDFIELD)
738
0
                InsertMenuItem(rChangeMenu, nMenuPos++, u"" FM_COL_FORMATTEDFIELD"1"_ustr, SvxResId(RID_STR_PROPTITLE_FORMATTED), RID_SVXBMP_FORMATTEDFIELD);
739
0
        }
740
741
742
0
        rMenu.set_visible(u"change"_ustr, bDesignMode && bMarked && xCols.is());
743
0
        rMenu.set_sensitive(u"change"_ustr, bDesignMode && bMarked && xCols.is());
744
0
    }
745
0
    else
746
0
    {
747
0
        rMenu.set_visible(u"change"_ustr, false);
748
0
        rMenu.set_sensitive(u"change"_ustr, false);
749
0
    }
750
751
0
    rMenu.set_visible(u"insert"_ustr, bDesignMode && xCols.is());
752
0
    rMenu.set_sensitive(u"insert"_ustr, bDesignMode && xCols.is());
753
0
    rMenu.set_visible(u"delete"_ustr, bDesignMode && bMarked && xCols.is());
754
0
    rMenu.set_sensitive(u"delete"_ustr, bDesignMode && bMarked && xCols.is());
755
0
    rMenu.set_visible(u"column"_ustr, bDesignMode && bMarked && xCols.is());
756
0
    rMenu.set_sensitive(u"column"_ustr, bDesignMode && bMarked && xCols.is());
757
758
0
    sal_uInt16 nHiddenCols = 0;
759
0
    if (xCols.is())
760
0
    {
761
        // check for hidden cols
762
0
        Reference< css::beans::XPropertySet >  xCurCol;
763
0
        Any aHidden,aName;
764
0
        for (sal_Int32 i=0; i<xCols->getCount(); ++i)
765
0
        {
766
0
            xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY);
767
0
            DBG_ASSERT(xCurCol.is(), "FmGridHeader::PreExecuteColumnContextMenu : the Peer has invalid columns !");
768
0
            aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN);
769
0
            DBG_ASSERT(aHidden.getValueTypeClass() == TypeClass_BOOLEAN,
770
0
                "FmGridHeader::PreExecuteColumnContextMenu : the property 'hidden' should be boolean !");
771
0
            if (::comphelper::getBOOL(aHidden))
772
0
            {
773
                // put the column name into the 'show col' menu
774
0
                if (nHiddenCols < 16)
775
0
                {
776
                    // (only the first 16 items to keep the menu rather small)
777
0
                    aName = xCurCol->getPropertyValue(FM_PROP_LABEL);
778
                    // the ID is arbitrary, but should be unique within the whole menu
779
0
                    rMenu.insert(nHiddenCols, OUString::number(nHiddenCols + 1), ::comphelper::getString(aName),
780
0
                        nullptr, nullptr, nullptr, TRISTATE_INDET);
781
0
                }
782
0
                ++nHiddenCols;
783
0
            }
784
0
        }
785
0
    }
786
0
    rShowMenu.set_visible(u"more"_ustr, xCols.is() && (nHiddenCols > 16));
787
0
    rMenu.set_visible(u"show"_ustr, xCols.is() && (nHiddenCols > 0));
788
0
    rMenu.set_sensitive(u"show"_ustr, xCols.is() && (nHiddenCols > 0));
789
790
    // allow the 'hide column' item ?
791
0
    bool bAllowHide = bMarked;                                          // a column is marked
792
0
    bAllowHide = bAllowHide || (!bDesignMode && (nPos != sal_uInt16(-1)));  // OR we are in alive mode and have hit a column
793
0
    bAllowHide = bAllowHide && xCols.is();                              // AND we have a column container
794
0
    bAllowHide = bAllowHide && (xCols->getCount()-nHiddenCols > 1);     // AND there are at least two visible columns
795
0
    rMenu.set_visible(u"hide"_ustr, bAllowHide);
796
0
    rMenu.set_sensitive(u"hide"_ustr, bAllowHide);
797
798
0
    if (!bMarked)
799
0
        return;
800
801
0
    SfxViewFrame* pCurrentFrame = SfxViewFrame::Current();
802
    // ask the bindings of the current view frame (which should be the one we're residing in) for the state
803
0
    if (pCurrentFrame)
804
0
    {
805
0
        std::unique_ptr<SfxBoolItem> pItem;
806
0
        SfxItemState eState = pCurrentFrame->GetBindings().QueryState(SID_FM_CTL_PROPERTIES, pItem);
807
808
0
        if (eState >= SfxItemState::DEFAULT && pItem)
809
0
        {
810
0
            rMenu.set_active(u"column"_ustr, pItem->GetValue());
811
0
        }
812
0
    }
813
0
}
814
815
namespace {
816
817
enum InspectorAction { eOpenInspector, eCloseInspector, eUpdateInspector, eNone };
818
819
}
820
821
void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const weld::Menu& rMenu, const OUString& rExecutionResult)
822
0
{
823
0
    Reference< css::container::XIndexContainer >  xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
824
0
    sal_uInt16 nPos = GetModelColumnPos(nColId);
825
826
0
    OUString aFieldType;
827
0
    bool    bReplace = false;
828
0
    InspectorAction eInspectorAction = eNone;
829
830
0
    if (rExecutionResult == "delete")
831
0
    {
832
0
        Reference< XInterface > xCol(
833
0
            xCols->getByIndex(nPos), css::uno::UNO_QUERY);
834
0
        xCols->removeByIndex(nPos);
835
0
        ::comphelper::disposeComponent(xCol);
836
0
    }
837
0
    else if (rExecutionResult == "hide")
838
0
    {
839
0
        Reference< css::beans::XPropertySet > xCurCol( xCols->getByIndex(nPos), css::uno::UNO_QUERY);
840
0
        xCurCol->setPropertyValue(FM_PROP_HIDDEN, Any(true));
841
0
    }
842
0
    else if (rExecutionResult == "column")
843
0
    {
844
0
        eInspectorAction = rMenu.get_active(u"column"_ustr) ? eOpenInspector : eCloseInspector;
845
0
    }
846
0
    else if (rExecutionResult.startsWith(FM_COL_TEXTFIELD))
847
0
    {
848
0
        if (rExecutionResult != FM_COL_TEXTFIELD)
849
0
            bReplace = true;
850
0
        aFieldType = FM_COL_TEXTFIELD;
851
0
    }
852
0
    else if (rExecutionResult.startsWith(FM_COL_COMBOBOX))
853
0
    {
854
0
        if (rExecutionResult != FM_COL_COMBOBOX)
855
0
            bReplace = true;
856
0
        aFieldType = FM_COL_COMBOBOX;
857
0
    }
858
0
    else if (rExecutionResult.startsWith(FM_COL_LISTBOX))
859
0
    {
860
0
        if (rExecutionResult != FM_COL_LISTBOX)
861
0
            bReplace = true;
862
0
        aFieldType = FM_COL_LISTBOX;
863
0
    }
864
0
    else if (rExecutionResult.startsWith(FM_COL_CHECKBOX))
865
0
    {
866
0
        if (rExecutionResult != FM_COL_CHECKBOX)
867
0
            bReplace = true;
868
0
        aFieldType = FM_COL_CHECKBOX;
869
0
    }
870
0
    else if (rExecutionResult.startsWith(FM_COL_DATEFIELD))
871
0
    {
872
0
        if (rExecutionResult != FM_COL_DATEFIELD)
873
0
            bReplace = true;
874
0
        aFieldType = FM_COL_DATEFIELD;
875
0
    }
876
0
    else if (rExecutionResult.startsWith(FM_COL_TIMEFIELD))
877
0
    {
878
0
        if (rExecutionResult != FM_COL_TIMEFIELD)
879
0
            bReplace = true;
880
0
        aFieldType = FM_COL_TIMEFIELD;
881
0
    }
882
0
    else if (rExecutionResult.startsWith(FM_COL_NUMERICFIELD))
883
0
    {
884
0
        if (rExecutionResult != FM_COL_NUMERICFIELD)
885
0
            bReplace = true;
886
0
        aFieldType = FM_COL_NUMERICFIELD;
887
0
    }
888
0
    else if (rExecutionResult.startsWith(FM_COL_CURRENCYFIELD))
889
0
    {
890
0
        if (rExecutionResult != FM_COL_CURRENCYFIELD)
891
0
            bReplace = true;
892
0
        aFieldType = FM_COL_CURRENCYFIELD;
893
0
    }
894
0
    else if (rExecutionResult.startsWith(FM_COL_PATTERNFIELD))
895
0
    {
896
0
        if (rExecutionResult != FM_COL_PATTERNFIELD)
897
0
            bReplace = true;
898
0
        aFieldType = FM_COL_PATTERNFIELD;
899
0
    }
900
0
    else if (rExecutionResult.startsWith(FM_COL_FORMATTEDFIELD))
901
0
    {
902
0
        if (rExecutionResult != FM_COL_FORMATTEDFIELD)
903
0
            bReplace = true;
904
0
        aFieldType = FM_COL_FORMATTEDFIELD;
905
0
    }
906
0
    else if (rExecutionResult == "more")
907
0
    {
908
0
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
909
0
        ScopedVclPtr<AbstractFmShowColsDialog> pDlg(pFact->CreateFmShowColsDialog(GetFrameWeld()));
910
0
        pDlg->SetColumns(xCols);
911
0
        pDlg->Execute();
912
0
    }
913
0
    else if (rExecutionResult == "all")
914
0
    {
915
        // just iterate through all the cols ...
916
0
        Reference< css::beans::XPropertySet >  xCurCol;
917
0
        for (sal_Int32 i=0; i<xCols->getCount(); ++i)
918
0
        {
919
0
            xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY);
920
0
            xCurCol->setPropertyValue(FM_PROP_HIDDEN, Any(false));
921
0
        }
922
        // TODO : there must be a more clever way to do this...
923
        // with the above the view is updated after every single model update ...
924
0
    }
925
0
    else if (!rExecutionResult.isEmpty())
926
0
    {
927
0
        sal_Int32 nExecutionResult = rExecutionResult.toInt32();
928
0
        if (nExecutionResult>0 && nExecutionResult<=16)
929
0
        {
930
            // it was a "show column/<colname>" command (there are at most 16 such items)
931
            // search the nExecutionResult'th hidden col
932
0
            Reference< css::beans::XPropertySet >  xCurCol;
933
0
            for (sal_Int32 i=0; i<xCols->getCount() && nExecutionResult; ++i)
934
0
            {
935
0
                xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY);
936
0
                Any aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN);
937
0
                if (::comphelper::getBOOL(aHidden))
938
0
                    if (!--nExecutionResult)
939
0
                    {
940
0
                        xCurCol->setPropertyValue(FM_PROP_HIDDEN, Any(false));
941
0
                        break;
942
0
                    }
943
0
            }
944
0
        }
945
0
    }
946
947
0
    if ( !aFieldType.isEmpty() )
948
0
    {
949
0
        try
950
0
        {
951
0
            Reference< XGridColumnFactory > xFactory( xCols, UNO_QUERY_THROW );
952
0
            Reference< XPropertySet > xNewCol( xFactory->createColumn( aFieldType ), UNO_SET_THROW );
953
954
0
            if ( bReplace )
955
0
            {
956
                // rescue over a few properties
957
0
                Reference< XPropertySet > xReplaced( xCols->getByIndex( nPos ), UNO_QUERY );
958
959
0
                TransferFormComponentProperties(
960
0
                    xReplaced, xNewCol, Application::GetSettings().GetUILanguageTag().getLocale() );
961
962
0
                xCols->replaceByIndex( nPos, Any( xNewCol ) );
963
0
                ::comphelper::disposeComponent( xReplaced );
964
965
0
                eInspectorAction = eUpdateInspector;
966
0
            }
967
0
            else
968
0
            {
969
0
                FormControlFactory factory;
970
971
0
                OUString sLabel = FormControlFactory::getDefaultUniqueName_ByComponentType(
972
0
                    Reference< XNameAccess >( xCols, UNO_QUERY_THROW ), xNewCol );
973
0
                xNewCol->setPropertyValue( FM_PROP_LABEL, Any( sLabel ) );
974
0
                xNewCol->setPropertyValue( FM_PROP_NAME, Any( sLabel ) );
975
976
0
                factory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xNewCol );
977
978
0
                xCols->insertByIndex( nPos, Any( xNewCol ) );
979
0
            }
980
0
        }
981
0
        catch( const Exception& )
982
0
        {
983
0
            DBG_UNHANDLED_EXCEPTION("svx");
984
0
        }
985
0
    }
986
987
0
    SfxViewFrame* pCurrentFrame = SfxViewFrame::Current();
988
0
    OSL_ENSURE( pCurrentFrame, "FmGridHeader::PostExecuteColumnContextMenu: no view frame -> no bindings -> no property browser!" );
989
0
    if ( !pCurrentFrame )
990
0
        return;
991
992
0
    if ( eInspectorAction == eUpdateInspector )
993
0
    {
994
0
        if ( !pCurrentFrame->HasChildWindow( SID_FM_SHOW_PROPERTIES ) )
995
0
            eInspectorAction = eNone;
996
0
    }
997
998
0
    if ( eInspectorAction != eNone )
999
0
    {
1000
0
        SfxBoolItem aShowItem( SID_FM_SHOW_PROPERTIES, eInspectorAction != eCloseInspector );
1001
1002
0
        pCurrentFrame->GetBindings().GetDispatcher()->ExecuteList(
1003
0
                SID_FM_SHOW_PROPERTY_BROWSER, SfxCallMode::ASYNCHRON,
1004
0
                { &aShowItem });
1005
0
    }
1006
0
}
1007
1008
void FmGridHeader::triggerColumnContextMenu( const ::Point& _rPreferredPos )
1009
0
{
1010
    // the affected col
1011
0
    sal_uInt16 nColId = GetItemId( _rPreferredPos );
1012
1013
    // the menu
1014
0
    std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, u"svx/ui/colsmenu.ui"_ustr));
1015
0
    std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu(u"menu"_ustr));
1016
0
    std::unique_ptr<weld::Menu> xInsertMenu(xBuilder->weld_menu(u"insertmenu"_ustr));
1017
0
    std::unique_ptr<weld::Menu> xChangeMenu(xBuilder->weld_menu(u"changemenu"_ustr));
1018
0
    std::unique_ptr<weld::Menu> xShowMenu(xBuilder->weld_menu(u"showmenu"_ustr));
1019
1020
    // let derivatives modify the menu
1021
0
    PreExecuteColumnContextMenu(nColId, *xContextMenu, *xInsertMenu, *xChangeMenu, *xShowMenu);
1022
1023
0
    bool bEmpty = true;
1024
0
    for (int i = 0, nCount = xContextMenu->n_children(); i < nCount; ++i)
1025
0
    {
1026
0
        bEmpty = !xContextMenu->get_sensitive(xContextMenu->get_id(i));
1027
0
        if (!bEmpty)
1028
0
            break;
1029
0
    }
1030
0
    if (bEmpty)
1031
0
        return;
1032
1033
    // execute the menu
1034
0
    ::tools::Rectangle aRect(_rPreferredPos, Size(1,1));
1035
0
    weld::Window* pParent = weld::GetPopupParent(*this, aRect);
1036
0
    OUString sResult = xContextMenu->popup_at_rect(pParent, aRect);
1037
1038
    // let derivatives handle the result
1039
0
    PostExecuteColumnContextMenu(nColId, *xContextMenu, sResult);
1040
0
}
1041
1042
void FmGridHeader::Command(const CommandEvent& rEvt)
1043
0
{
1044
0
    switch (rEvt.GetCommand())
1045
0
    {
1046
0
        case CommandEventId::ContextMenu:
1047
0
        {
1048
0
            if (!rEvt.IsMouseEvent())
1049
0
                return;
1050
1051
0
            triggerColumnContextMenu( rEvt.GetMousePosPixel() );
1052
0
        }
1053
0
        break;
1054
0
        default:
1055
0
            EditBrowserHeader::Command(rEvt);
1056
0
    }
1057
0
}
1058
1059
FmGridControl::FmGridControl(
1060
                const Reference< css::uno::XComponentContext >& _rxContext,
1061
                vcl::Window* pParent,
1062
                FmXGridPeer* _pPeer,
1063
                WinBits nBits)
1064
0
        :DbGridControl(_rxContext, pParent, nBits)
1065
0
        ,m_pPeer(_pPeer)
1066
0
        ,m_nCurrentSelectedColumn(-1)
1067
        ,m_nMarkedColumnId(BROWSER_INVALIDID)
1068
0
        ,m_bSelecting(false)
1069
0
        ,m_bInColumnMove(false)
1070
0
{
1071
0
    EnableInteractiveRowHeight( );
1072
0
}
Unexecuted instantiation: FmGridControl::FmGridControl(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, vcl::Window*, FmXGridPeer*, long)
Unexecuted instantiation: FmGridControl::FmGridControl(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, vcl::Window*, FmXGridPeer*, long)
1073
1074
void FmGridControl::Command(const CommandEvent& _rEvt)
1075
0
{
1076
0
    if ( CommandEventId::ContextMenu == _rEvt.GetCommand() )
1077
0
    {
1078
0
        FmGridHeader* pMyHeader = static_cast< FmGridHeader* >( GetHeaderBar() );
1079
0
        if ( pMyHeader && !_rEvt.IsMouseEvent() )
1080
0
        {   // context menu requested by keyboard
1081
0
            if  ( 1 == GetSelectColumnCount() || IsDesignMode() )
1082
0
            {
1083
0
                sal_uInt16 nSelId = GetColumnId(
1084
0
                    sal::static_int_cast< sal_uInt16 >( FirstSelectedColumn() ) );
1085
0
                ::tools::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, false ) );
1086
1087
0
                Point aRelativePos( pMyHeader->ScreenToOutputPixel( OutputToScreenPixel( aColRect.TopCenter() ) ) );
1088
0
                pMyHeader->triggerColumnContextMenu(aRelativePos);
1089
1090
                // handled
1091
0
                return;
1092
0
            }
1093
0
        }
1094
0
    }
1095
1096
0
    DbGridControl::Command( _rEvt );
1097
0
}
1098
1099
// css::beans::XPropertyChangeListener
1100
void FmGridControl::propertyChange(const css::beans::PropertyChangeEvent& evt)
1101
0
{
1102
0
    if (evt.PropertyName == FM_PROP_ROWCOUNT)
1103
0
    {
1104
        // if we're not in the main thread call AdjustRows asynchronously
1105
0
        implAdjustInSolarThread(true);
1106
0
        return;
1107
0
    }
1108
1109
0
    const DbGridRowRef& xRow = GetCurrentRow();
1110
    // no adjustment of the properties is carried out during positioning
1111
0
    Reference<XPropertySet> xSet(evt.Source,UNO_QUERY);
1112
0
    if (!(xRow.is() && (::cppu::any2bool(xSet->getPropertyValue(FM_PROP_ISNEW))|| CompareBookmark(getDataSource()->getBookmark(), xRow->GetBookmark()))))
1113
0
        return;
1114
1115
0
    if (evt.PropertyName == FM_PROP_ISMODIFIED)
1116
0
    {
1117
        // modified or clean ?
1118
0
        GridRowStatus eStatus = ::comphelper::getBOOL(evt.NewValue) ? GridRowStatus::Modified : GridRowStatus::Clean;
1119
0
        if (eStatus != xRow->GetStatus())
1120
0
        {
1121
0
            xRow->SetStatus(eStatus);
1122
0
            SolarMutexGuard aGuard;
1123
0
            RowModified(GetCurrentPos());
1124
0
        }
1125
0
    }
1126
0
}
1127
1128
void FmGridControl::SetDesignMode(bool bMode)
1129
0
{
1130
0
    bool bOldMode = IsDesignMode();
1131
0
    DbGridControl::SetDesignMode(bMode);
1132
0
    if (bOldMode == bMode)
1133
0
        return;
1134
1135
0
    if (!bMode)
1136
0
    {
1137
        // cancel selection
1138
0
        markColumn(USHRT_MAX);
1139
0
    }
1140
0
    else
1141
0
    {
1142
0
        Reference< css::container::XIndexContainer >  xColumns(GetPeer()->getColumns());
1143
0
        Reference< css::view::XSelectionSupplier >  xSelSupplier(xColumns, UNO_QUERY);
1144
0
        if (xSelSupplier.is())
1145
0
        {
1146
0
            Any aSelection = xSelSupplier->getSelection();
1147
0
            Reference< css::beans::XPropertySet >  xColumn;
1148
0
            if (aSelection.getValueTypeClass() == TypeClass_INTERFACE)
1149
0
                xColumn.set(aSelection, css::uno::UNO_QUERY);
1150
0
            Reference< XInterface >  xCurrent;
1151
0
            for (sal_Int32 i=0; i<xColumns->getCount(); ++i)
1152
0
            {
1153
0
                xCurrent.set(xColumns->getByIndex(i), css::uno::UNO_QUERY);
1154
0
                if (xCurrent == xColumn)
1155
0
                {
1156
0
                    markColumn(GetColumnIdFromModelPos(i));
1157
0
                    break;
1158
0
                }
1159
0
            }
1160
0
        }
1161
0
    }
1162
0
}
1163
1164
void FmGridControl::DeleteSelectedRows()
1165
0
{
1166
0
    if (!m_pSeekCursor)
1167
0
        return;
1168
1169
    // how many rows are selected?
1170
0
    sal_Int32 nSelectedRows = GetSelectRowCount();
1171
1172
    // the current line should be deleted but it is currently in edit mode
1173
0
    if ( IsCurrentAppending() )
1174
0
        return;
1175
    // is the insert row selected
1176
0
    if (GetEmptyRow().is() && IsRowSelected(GetRowCount() - 1))
1177
0
        nSelectedRows -= 1;
1178
1179
    // nothing to do
1180
0
    if (nSelectedRows <= 0)
1181
0
        return;
1182
1183
    // try to confirm the delete
1184
0
    Reference< css::frame::XDispatchProvider >  xDispatcher = static_cast<css::frame::XDispatchProvider*>(GetPeer());
1185
0
    if (xDispatcher.is())
1186
0
    {
1187
0
        css::util::URL aUrl;
1188
0
        aUrl.Complete = FMURL_CONFIRM_DELETION;
1189
0
        Reference< css::util::XURLTransformer > xTransformer(
1190
0
            css::util::URLTransformer::create(::comphelper::getProcessComponentContext()) );
1191
0
        xTransformer->parseStrict( aUrl );
1192
1193
0
        Reference< css::frame::XDispatch >  xDispatch = xDispatcher->queryDispatch(aUrl, OUString(), 0);
1194
0
        Reference< css::form::XConfirmDeleteListener >  xConfirm(xDispatch, UNO_QUERY);
1195
0
        if (xConfirm.is())
1196
0
        {
1197
0
            css::sdb::RowChangeEvent aEvent;
1198
0
            aEvent.Source = Reference< XInterface >(*getDataSource());
1199
0
            aEvent.Rows = nSelectedRows;
1200
0
            aEvent.Action = css::sdb::RowChangeAction::DELETE;
1201
0
            if (!xConfirm->confirmDelete(aEvent))
1202
0
                return;
1203
0
        }
1204
0
    }
1205
1206
0
    const MultiSelection* pRowSelection = GetSelection();
1207
0
    if ( pRowSelection && pRowSelection->IsAllSelected() )
1208
0
    {
1209
0
        BeginCursorAction();
1210
0
        CursorWrapper* pCursor = getDataSource();
1211
0
        Reference< XResultSetUpdate >  xUpdateCursor(Reference< XInterface >(*pCursor), UNO_QUERY);
1212
0
        try
1213
0
        {
1214
0
            pCursor->beforeFirst();
1215
0
            while( pCursor->next() )
1216
0
                xUpdateCursor->deleteRow();
1217
1218
0
            SetUpdateMode(false);
1219
0
            SetNoSelection();
1220
1221
0
            xUpdateCursor->moveToInsertRow();
1222
0
        }
1223
0
        catch(const Exception&)
1224
0
        {
1225
0
            TOOLS_WARN_EXCEPTION("svx", "Exception caught while deleting rows!");
1226
0
        }
1227
        // adapt to the data cursor
1228
0
        AdjustDataSource(true);
1229
0
        EndCursorAction();
1230
0
        SetUpdateMode(true);
1231
0
    }
1232
0
    else
1233
0
    {
1234
0
        Reference< css::sdbcx::XDeleteRows >  xDeleteThem(Reference< XInterface >(*getDataSource()), UNO_QUERY);
1235
1236
        // collect the bookmarks of the selected rows
1237
0
        Sequence < Any> aBookmarks = getSelectionBookmarks();
1238
1239
        // determine the next row to position after deletion
1240
0
        Any aBookmark;
1241
0
        bool bNewPos = false;
1242
        // if the current row isn't selected we take the row as row after deletion
1243
0
        OSL_ENSURE( GetCurrentRow().is(), "FmGridControl::DeleteSelectedRows: no current row here?" );
1244
            // crash reports suggest it can happen we don't have a current row - how?
1245
            // #154303# / 2008-04-23 / frank.schoenheit@sun.com
1246
0
        if ( !IsRowSelected( GetCurrentPos() ) && !IsCurrentAppending() && GetCurrentRow().is() )
1247
0
        {
1248
0
            aBookmark = GetCurrentRow()->GetBookmark();
1249
0
            bNewPos   = true;
1250
0
        }
1251
0
        else
1252
0
        {
1253
            // we look for the first row after the selected block for selection
1254
0
            tools::Long nIdx = LastSelectedRow() + 1;
1255
0
            if (nIdx < GetRowCount() - 1)
1256
0
            {
1257
                // there is a next row to position on
1258
0
                if (SeekCursor(nIdx))
1259
0
                {
1260
0
                    GetSeekRow()->SetState(m_pSeekCursor.get(), true);
1261
1262
0
                    bNewPos = true;
1263
                    // if it's not the row for inserting we keep the bookmark
1264
0
                    if (!IsInsertionRow(nIdx))
1265
0
                        aBookmark = m_pSeekCursor->getBookmark();
1266
0
                }
1267
0
            }
1268
0
            else
1269
0
            {
1270
                // we look for the first row before the selected block for selection after deletion
1271
0
                nIdx = FirstSelectedRow() - 1;
1272
0
                if (nIdx >= 0 && SeekCursor(nIdx))
1273
0
                {
1274
0
                    GetSeekRow()->SetState(m_pSeekCursor.get(), true);
1275
1276
0
                    bNewPos = true;
1277
0
                    aBookmark = m_pSeekCursor->getBookmark();
1278
0
                }
1279
0
            }
1280
0
        }
1281
1282
        // Are all rows selected?
1283
        // Second condition if no insertion line exists
1284
0
        bool bAllSelected = GetTotalCount() == nSelectedRows || GetRowCount() == nSelectedRows;
1285
1286
0
        BeginCursorAction();
1287
1288
        // now delete the row
1289
0
        Sequence<sal_Int32> aDeletedRows;
1290
0
        SetUpdateMode( false );
1291
0
        try
1292
0
        {
1293
0
            aDeletedRows = xDeleteThem->deleteRows(aBookmarks);
1294
0
        }
1295
0
        catch(SQLException&)
1296
0
        {
1297
0
        }
1298
0
        SetUpdateMode( true );
1299
1300
        // how many rows are deleted?
1301
0
        sal_Int32 nDeletedRows = static_cast<sal_Int32>(std::count_if(std::cbegin(aDeletedRows), std::cend(aDeletedRows),
1302
0
                                                                      [](const sal_Int32 nRow) { return nRow != 0; }));
1303
1304
        // have rows been deleted?
1305
0
        if (nDeletedRows)
1306
0
        {
1307
0
            SetUpdateMode(false);
1308
0
            SetNoSelection();
1309
0
            try
1310
0
            {
1311
                // did we delete all the rows than try to move to the next possible row
1312
0
                if (nDeletedRows == aDeletedRows.getLength())
1313
0
                {
1314
                    // there exists a new position to move on
1315
0
                    if (bNewPos)
1316
0
                    {
1317
0
                        if (aBookmark.hasValue())
1318
0
                            getDataSource()->moveToBookmark(aBookmark);
1319
                        // no valid bookmark so move to the insert row
1320
0
                        else
1321
0
                        {
1322
0
                            Reference< XResultSetUpdate >  xUpdateCursor(Reference< XInterface >(*m_pDataCursor), UNO_QUERY);
1323
0
                            xUpdateCursor->moveToInsertRow();
1324
0
                        }
1325
0
                    }
1326
0
                    else
1327
0
                    {
1328
0
                        Reference< css::beans::XPropertySet >  xSet(Reference< XInterface >(*m_pDataCursor), UNO_QUERY);
1329
1330
0
                        sal_Int32 nRecordCount(0);
1331
0
                        xSet->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount;
1332
0
                        if ( m_pDataCursor->rowDeleted() )
1333
0
                            --nRecordCount;
1334
1335
                        // there are no rows left and we have an insert row
1336
0
                        if (!nRecordCount && GetEmptyRow().is())
1337
0
                        {
1338
0
                            Reference< XResultSetUpdate >  xUpdateCursor(Reference< XInterface >(*m_pDataCursor), UNO_QUERY);
1339
0
                            xUpdateCursor->moveToInsertRow();
1340
0
                        }
1341
0
                        else if (nRecordCount)
1342
                            // move to the first row
1343
0
                            getDataSource()->first();
1344
0
                    }
1345
0
                }
1346
                // not all the rows where deleted, so move to the first row which remained in the resultset
1347
0
                else
1348
0
                {
1349
0
                    auto pRow = std::find(std::cbegin(aDeletedRows), std::cend(aDeletedRows), 0);
1350
0
                    if (pRow != std::cend(aDeletedRows))
1351
0
                    {
1352
0
                        auto i = static_cast<sal_Int32>(std::distance(std::cbegin(aDeletedRows), pRow));
1353
0
                        getDataSource()->moveToBookmark(aBookmarks[i]);
1354
0
                    }
1355
0
                }
1356
0
            }
1357
0
            catch(const Exception&)
1358
0
            {
1359
0
                try
1360
0
                {
1361
                    // positioning went wrong so try to move to the first row
1362
0
                    getDataSource()->first();
1363
0
                }
1364
0
                catch(const Exception&)
1365
0
                {
1366
0
                }
1367
0
            }
1368
1369
            // adapt to the data cursor
1370
0
            AdjustDataSource(true);
1371
1372
            // not all rows could be deleted;
1373
            // never select again there the ones that could not be deleted
1374
0
            if (nDeletedRows < nSelectedRows)
1375
0
            {
1376
                // were all selected
1377
0
                if (bAllSelected)
1378
0
                {
1379
0
                    SelectAll();
1380
0
                    if (IsInsertionRow(GetRowCount() - 1))  // not the insertion row
1381
0
                        SelectRow(GetRowCount() - 1, false);
1382
0
                }
1383
0
                else
1384
0
                {
1385
                    // select the remaining rows
1386
0
                    for (const sal_Int32 nSuccess : aDeletedRows)
1387
0
                    {
1388
0
                        try
1389
0
                        {
1390
0
                            if (!nSuccess)
1391
0
                            {
1392
0
                                m_pSeekCursor->moveToBookmark(m_pDataCursor->getBookmark());
1393
0
                                SetSeekPos(m_pSeekCursor->getRow() - 1);
1394
0
                                SelectRow(GetSeekPos());
1395
0
                            }
1396
0
                        }
1397
0
                        catch(const Exception&)
1398
0
                        {
1399
                            // keep the seekpos in all cases
1400
0
                            SetSeekPos(m_pSeekCursor->getRow() - 1);
1401
0
                        }
1402
0
                    }
1403
0
                }
1404
0
            }
1405
1406
0
            EndCursorAction();
1407
0
            SetUpdateMode(true);
1408
0
        }
1409
0
        else // row could not be deleted
1410
0
        {
1411
0
            EndCursorAction();
1412
0
            try
1413
0
            {
1414
                // currentrow is the insert row?
1415
0
                if (!IsCurrentAppending())
1416
0
                    getDataSource()->refreshRow();
1417
0
            }
1418
0
            catch(const Exception&)
1419
0
            {
1420
0
            }
1421
0
        }
1422
0
    }
1423
1424
    // if there is no selection anymore we can start editing
1425
0
    if (!GetSelectRowCount())
1426
0
        ActivateCell();
1427
0
}
1428
1429
// XCurrentRecordListener
1430
void FmGridControl::positioned()
1431
0
{
1432
0
    SAL_INFO("svx.fmcomp", "FmGridControl::positioned");
1433
    // position on the data source (force it to be done in the main thread)
1434
0
    implAdjustInSolarThread(false);
1435
0
}
1436
1437
bool FmGridControl::commit()
1438
0
{
1439
    // execute commit only if an update is not already executed by the
1440
    // css::form::component::GridControl
1441
0
    if (!IsUpdating())
1442
0
    {
1443
0
        if (Controller().is() && Controller()->IsValueChangedFromSaved())
1444
0
        {
1445
0
            if (!SaveModified())
1446
0
                return false;
1447
0
        }
1448
0
    }
1449
0
    return true;
1450
0
}
1451
1452
void FmGridControl::inserted()
1453
0
{
1454
0
    const DbGridRowRef& xRow = GetCurrentRow();
1455
0
    if (!xRow.is())
1456
0
        return;
1457
1458
    // line has been inserted, then reset the status and mode
1459
0
    xRow->SetState(m_pDataCursor.get(), false);
1460
0
    xRow->SetNew(false);
1461
1462
0
}
1463
1464
VclPtr<svt::EditBrowserHeader> FmGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
1465
0
{
1466
0
    DBG_ASSERT( pParent == this, "FmGridControl::imp_CreateHeaderBar: parent?" );
1467
0
    return VclPtr<FmGridHeader>::Create( pParent );
1468
0
}
1469
1470
void FmGridControl::markColumn(sal_uInt16 nId)
1471
0
{
1472
0
    if (!(GetHeaderBar() && m_nMarkedColumnId != nId))
1473
0
        return;
1474
1475
    // deselect
1476
0
    if (m_nMarkedColumnId != BROWSER_INVALIDID)
1477
0
    {
1478
0
        HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(m_nMarkedColumnId) & ~HeaderBarItemBits::FLAT;
1479
0
        GetHeaderBar()->SetItemBits(m_nMarkedColumnId, aBits);
1480
0
    }
1481
1482
1483
0
    if (nId != BROWSER_INVALIDID)
1484
0
    {
1485
0
        HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(nId) | HeaderBarItemBits::FLAT;
1486
0
        GetHeaderBar()->SetItemBits(nId, aBits);
1487
0
    }
1488
0
    m_nMarkedColumnId = nId;
1489
0
}
1490
1491
bool FmGridControl::isColumnMarked(sal_uInt16 nId) const
1492
0
{
1493
0
    return m_nMarkedColumnId == nId;
1494
0
}
1495
1496
tools::Long FmGridControl::QueryMinimumRowHeight()
1497
0
{
1498
0
    tools::Long const nMinimalLogicHeight = 20; // 0.2 cm
1499
0
    tools::Long nMinimalPixelHeight = LogicToPixel(Point(0, nMinimalLogicHeight), MapMode(MapUnit::Map10thMM)).Y();
1500
0
    return CalcZoom( nMinimalPixelHeight );
1501
0
}
1502
1503
void FmGridControl::RowHeightChanged()
1504
0
{
1505
0
    DbGridControl::RowHeightChanged();
1506
1507
0
    Reference< XPropertySet > xModel( GetPeer()->getColumns(), UNO_QUERY );
1508
0
    DBG_ASSERT( xModel.is(), "FmGridControl::RowHeightChanged: no model!" );
1509
0
    if ( !xModel.is() )
1510
0
        return;
1511
1512
0
    try
1513
0
    {
1514
0
        sal_Int32 nUnzoomedPixelHeight = CalcReverseZoom( GetDataRowHeight() );
1515
0
        Any aProperty( static_cast<sal_Int32>(PixelToLogic( Point(0, nUnzoomedPixelHeight), MapMode(MapUnit::Map10thMM)).Y()) );
1516
0
        xModel->setPropertyValue( FM_PROP_ROWHEIGHT, aProperty );
1517
0
    }
1518
0
    catch( const Exception& )
1519
0
    {
1520
0
        TOOLS_WARN_EXCEPTION( "svx", "FmGridControl::RowHeightChanged" );
1521
0
    }
1522
0
}
1523
1524
void FmGridControl::ColumnResized(sal_uInt16 nId)
1525
0
{
1526
0
    DbGridControl::ColumnResized(nId);
1527
1528
    // transfer value to the model
1529
0
    DbGridColumn* pCol = DbGridControl::GetColumns()[ GetModelColumnPos(nId) ].get();
1530
0
    const Reference< css::beans::XPropertySet >&  xColModel(pCol->getModel());
1531
0
    if (xColModel.is())
1532
0
    {
1533
0
        Any aWidth;
1534
0
        sal_Int32 nColumnWidth = GetColumnWidth(nId);
1535
0
        nColumnWidth = CalcReverseZoom(nColumnWidth);
1536
        // convert to 10THMM
1537
0
        aWidth <<= static_cast<sal_Int32>(PixelToLogic(Point(nColumnWidth, 0), MapMode(MapUnit::Map10thMM)).X());
1538
0
        xColModel->setPropertyValue(FM_PROP_WIDTH, aWidth);
1539
0
    }
1540
0
}
1541
1542
void FmGridControl::CellModified()
1543
0
{
1544
0
    DbGridControl::CellModified();
1545
0
    GetPeer()->CellModified();
1546
0
}
1547
1548
void FmGridControl::BeginCursorAction()
1549
0
{
1550
0
    DbGridControl::BeginCursorAction();
1551
0
    m_pPeer->stopCursorListening();
1552
0
}
1553
1554
void FmGridControl::EndCursorAction()
1555
0
{
1556
0
    m_pPeer->startCursorListening();
1557
0
    DbGridControl::EndCursorAction();
1558
0
}
1559
1560
void FmGridControl::ColumnMoved(sal_uInt16 nId)
1561
0
{
1562
0
    m_bInColumnMove = true;
1563
1564
0
    DbGridControl::ColumnMoved(nId);
1565
0
    Reference< css::container::XIndexContainer >  xColumns(GetPeer()->getColumns());
1566
1567
0
    if (xColumns.is())
1568
0
    {
1569
        // locate the column and move in the model;
1570
        // get ColumnPos
1571
0
        DbGridColumn* pCol = DbGridControl::GetColumns()[ GetModelColumnPos(nId) ].get();
1572
0
        Reference< css::beans::XPropertySet >  xCol;
1573
1574
        // inserting must be based on the column positions
1575
0
        sal_Int32 i;
1576
0
        Reference< XInterface > xCurrent;
1577
0
        for (i = 0; !xCol.is() && i < xColumns->getCount(); i++)
1578
0
        {
1579
0
            xCurrent.set(xColumns->getByIndex(i), css::uno::UNO_QUERY);
1580
0
            if (xCurrent == pCol->getModel())
1581
0
            {
1582
0
                xCol = pCol->getModel();
1583
0
                break;
1584
0
            }
1585
0
        }
1586
1587
0
        DBG_ASSERT(i < xColumns->getCount(), "Wrong css::sdbcx::Index");
1588
0
        xColumns->removeByIndex(i);
1589
0
        Any aElement;
1590
0
        aElement <<= xCol;
1591
0
        xColumns->insertByIndex(GetModelColumnPos(nId), aElement);
1592
0
        pCol->setModel(xCol);
1593
        // if the column which is shown here is selected ...
1594
0
        if ( isColumnSelected(pCol) )
1595
0
            markColumn(nId); // ... -> mark it
1596
0
    }
1597
1598
0
    m_bInColumnMove = false;
1599
0
}
1600
1601
void FmGridControl::InitColumnsByModels(const Reference< css::container::XIndexContainer >& xColumns)
1602
0
{
1603
    // reset columns;
1604
    // if there is only one HandleColumn, then don't
1605
0
    if (GetModelColCount())
1606
0
    {
1607
0
        RemoveColumns();
1608
0
        InsertHandleColumn();
1609
0
    }
1610
1611
0
    if (!xColumns.is())
1612
0
        return;
1613
1614
0
    SetUpdateMode(false);
1615
1616
    // inserting must be based on the column positions
1617
0
    sal_Int32 i;
1618
0
    Any aWidth;
1619
0
    for (i = 0; i < xColumns->getCount(); ++i)
1620
0
    {
1621
0
        Reference< css::beans::XPropertySet > xCol(
1622
0
            xColumns->getByIndex(i), css::uno::UNO_QUERY);
1623
1624
0
        OUString aName(
1625
0
            comphelper::getString(xCol->getPropertyValue(FM_PROP_LABEL)));
1626
1627
0
        aWidth = xCol->getPropertyValue(FM_PROP_WIDTH);
1628
0
        sal_Int32 nWidth = 0;
1629
0
        if (aWidth >>= nWidth)
1630
0
            nWidth = LogicToPixel(Point(nWidth, 0), MapMode(MapUnit::Map10thMM)).X();
1631
1632
0
        AppendColumn(aName, static_cast<sal_uInt16>(nWidth));
1633
0
        DbGridColumn* pCol = DbGridControl::GetColumns()[ i ].get();
1634
0
        pCol->setModel(xCol);
1635
0
    }
1636
1637
    // and now remove the hidden columns as well
1638
    // (we did not already make it in the upper loop, since we would then have gotten
1639
    // problems with the IDs of the columns: AppendColumn allocates them automatically,
1640
    // but the column _after_ a hidden one needs an ID increased by one ...)
1641
0
    Any aHidden;
1642
0
    for (i = 0; i < xColumns->getCount(); ++i)
1643
0
    {
1644
0
        Reference< css::beans::XPropertySet > xCol( xColumns->getByIndex(i), css::uno::UNO_QUERY);
1645
0
        aHidden = xCol->getPropertyValue(FM_PROP_HIDDEN);
1646
0
        if (::comphelper::getBOOL(aHidden))
1647
0
            HideColumn(GetColumnIdFromModelPos(static_cast<sal_uInt16>(i)));
1648
0
    }
1649
1650
0
    SetUpdateMode(true);
1651
0
}
1652
1653
void FmGridControl::InitColumnByField(
1654
    DbGridColumn* _pColumn, const Reference< XPropertySet >& _rxColumnModel,
1655
    const Reference< XNameAccess >& _rxFieldsByNames, const Reference< XIndexAccess >& _rxFieldsByIndex )
1656
0
{
1657
0
    DBG_ASSERT( _rxFieldsByNames == _rxFieldsByIndex, "FmGridControl::InitColumnByField: invalid container interfaces!" );
1658
1659
    // lookup the column which belongs to the control source
1660
0
    OUString sFieldName;
1661
0
    _rxColumnModel->getPropertyValue( FM_PROP_CONTROLSOURCE ) >>= sFieldName;
1662
0
    Reference< XPropertySet > xField;
1663
0
    _rxColumnModel->getPropertyValue( FM_PROP_BOUNDFIELD ) >>= xField;
1664
1665
1666
0
    if ( !xField.is() && /*sFieldName.getLength() && */_rxFieldsByNames->hasByName( sFieldName ) ) // #i93452# do not check for name length
1667
0
        _rxFieldsByNames->getByName( sFieldName ) >>= xField;
1668
1669
    // determine the position of this column
1670
0
    sal_Int32 nFieldPos = -1;
1671
0
    if ( xField.is() )
1672
0
    {
1673
0
        Reference< XPropertySet > xCheck;
1674
0
        sal_Int32 nFieldCount = _rxFieldsByIndex->getCount();
1675
0
        for ( sal_Int32 i = 0; i < nFieldCount; ++i)
1676
0
        {
1677
0
            _rxFieldsByIndex->getByIndex( i ) >>= xCheck;
1678
0
            if ( xField.get() == xCheck.get() )
1679
0
            {
1680
0
                nFieldPos = i;
1681
0
                break;
1682
0
            }
1683
0
        }
1684
0
    }
1685
1686
0
    if ( xField.is() && ( nFieldPos >= 0 ) )
1687
0
    {
1688
        // some data types are not allowed
1689
0
        sal_Int32 nDataType = DataType::OTHER;
1690
0
        xField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType;
1691
1692
0
        bool bIllegalType = false;
1693
0
        switch ( nDataType )
1694
0
        {
1695
0
            case DataType::BLOB:
1696
0
            case DataType::LONGVARBINARY:
1697
0
            case DataType::BINARY:
1698
0
            case DataType::VARBINARY:
1699
0
            case DataType::OTHER:
1700
0
                bIllegalType = true;
1701
0
                break;
1702
0
        }
1703
1704
0
        if ( bIllegalType )
1705
0
        {
1706
0
            _pColumn->SetObject( static_cast<sal_Int16>(nFieldPos) );
1707
0
            return;
1708
0
        }
1709
0
    }
1710
1711
    // the control type is determined by the ColumnServiceName
1712
0
    static constexpr OUString s_sPropColumnServiceName = u"ColumnServiceName"_ustr;
1713
0
    if ( !::comphelper::hasProperty( s_sPropColumnServiceName, _rxColumnModel ) )
1714
0
        return;
1715
1716
0
    _pColumn->setModel( _rxColumnModel );
1717
1718
0
    OUString sColumnServiceName;
1719
0
    _rxColumnModel->getPropertyValue( s_sPropColumnServiceName ) >>= sColumnServiceName;
1720
1721
0
    sal_Int32 nTypeId = getColumnTypeByModelName( sColumnServiceName );
1722
0
    _pColumn->CreateControl( nFieldPos, xField, nTypeId );
1723
0
}
1724
1725
void FmGridControl::InitColumnsByFields(const Reference< css::container::XIndexAccess >& _rxFields)
1726
0
{
1727
0
    if ( !_rxFields.is() )
1728
0
        return;
1729
1730
    // initialize columns
1731
0
    Reference< XIndexContainer > xColumns( GetPeer()->getColumns() );
1732
0
    Reference< XNameAccess > xFieldsAsNames( _rxFields, UNO_QUERY );
1733
1734
    // inserting must be based on the column positions
1735
0
    for (sal_Int32 i = 0; i < xColumns->getCount(); i++)
1736
0
    {
1737
0
        DbGridColumn* pCol = GetColumns()[ i ].get();
1738
0
        OSL_ENSURE(pCol,"No grid column!");
1739
0
        if ( pCol )
1740
0
        {
1741
0
            Reference< XPropertySet > xColumnModel(
1742
0
                xColumns->getByIndex( i ), css::uno::UNO_QUERY);
1743
1744
0
            InitColumnByField( pCol, xColumnModel, xFieldsAsNames, _rxFields );
1745
0
        }
1746
0
    }
1747
0
}
1748
1749
void FmGridControl::HideColumn(sal_uInt16 nId)
1750
0
{
1751
0
    DbGridControl::HideColumn(nId);
1752
1753
0
    sal_uInt16 nPos = GetModelColumnPos(nId);
1754
0
    if (nPos == sal_uInt16(-1))
1755
0
        return;
1756
1757
0
    DbGridColumn* pColumn = GetColumns()[ nPos ].get();
1758
0
    if (pColumn->IsHidden())
1759
0
        GetPeer()->columnHidden(pColumn);
1760
1761
0
    if (nId == m_nMarkedColumnId)
1762
0
        m_nMarkedColumnId = sal_uInt16(-1);
1763
0
}
1764
1765
bool FmGridControl::isColumnSelected(DbGridColumn const * _pColumn) const
1766
0
{
1767
0
    assert(_pColumn && "Column can not be null!");
1768
0
    bool bSelected = false;
1769
    // if the column which is shown here is selected ...
1770
0
    Reference< css::view::XSelectionSupplier >  xSelSupplier(GetPeer()->getColumns(), UNO_QUERY);
1771
0
    if ( xSelSupplier.is() )
1772
0
    {
1773
0
        Reference< css::beans::XPropertySet >  xColumn;
1774
0
        xSelSupplier->getSelection() >>= xColumn;
1775
0
        bSelected = (xColumn.get() == _pColumn->getModel().get());
1776
0
    }
1777
0
    return bSelected;
1778
0
}
1779
1780
void FmGridControl::ShowColumn(sal_uInt16 nId)
1781
0
{
1782
0
    DbGridControl::ShowColumn(nId);
1783
1784
0
    sal_uInt16 nPos = GetModelColumnPos(nId);
1785
0
    if (nPos == sal_uInt16(-1))
1786
0
        return;
1787
1788
0
    DbGridColumn* pColumn = GetColumns()[ nPos ].get();
1789
0
    if (!pColumn->IsHidden())
1790
0
        GetPeer()->columnVisible(pColumn);
1791
1792
    // if the column which is shown here is selected ...
1793
0
    if ( isColumnSelected(pColumn) )
1794
0
        markColumn(nId); // ... -> mark it
1795
0
}
1796
1797
bool FmGridControl::selectBookmarks(const Sequence< Any >& _rBookmarks)
1798
0
{
1799
0
    SolarMutexGuard aGuard;
1800
        // need to lock the SolarMutex so that no paint call disturbs us ...
1801
1802
0
    if ( !m_pSeekCursor )
1803
0
    {
1804
0
        OSL_FAIL( "FmGridControl::selectBookmarks: no seek cursor!" );
1805
0
        return false;
1806
0
    }
1807
1808
0
    SetNoSelection();
1809
1810
0
    bool bAllSuccessful = true;
1811
0
    try
1812
0
    {
1813
0
        for (const Any& rBookmark : _rBookmarks)
1814
0
        {
1815
            // move the seek cursor to the row given
1816
0
            if (m_pSeekCursor->moveToBookmark(rBookmark))
1817
0
                SelectRow( m_pSeekCursor->getRow() - 1);
1818
0
            else
1819
0
                bAllSuccessful = false;
1820
0
        }
1821
0
    }
1822
0
    catch(Exception&)
1823
0
    {
1824
0
        OSL_FAIL("FmGridControl::selectBookmarks: could not move to one of the bookmarks!");
1825
0
        return false;
1826
0
    }
1827
1828
0
    return bAllSuccessful;
1829
0
}
1830
1831
Sequence< Any> FmGridControl::getSelectionBookmarks()
1832
0
{
1833
    // lock our update so no paint-triggered seeks interfere ...
1834
0
    SetUpdateMode(false);
1835
1836
0
    sal_Int32 nSelectedRows = GetSelectRowCount(), i = 0;
1837
0
    Sequence< Any> aBookmarks(nSelectedRows);
1838
0
    if ( nSelectedRows )
1839
0
    {
1840
0
        Any* pBookmarks = aBookmarks.getArray();
1841
1842
        // (I'm not sure if the problem isn't deeper: The scenario: a large table displayed by a grid with a
1843
        // thread-safe cursor (dBase). On loading the sdb-cursor started a counting thread. While this counting progress
1844
        // was running, I tried do delete 3 records from within the grid. Deletion caused a SeekCursor, which made a
1845
        // m_pSeekCursor->moveRelative and a m_pSeekCursor->getPosition.
1846
        // Unfortunately the first call caused a propertyChanged(RECORDCOUNT) which resulted in a repaint of the
1847
        // navigation bar and the grid. The latter itself will result in SeekRow calls. So after (successfully) returning
1848
        // from the moveRelative the getPosition returns an invalid value. And so the SeekCursor fails.
1849
        // In the consequence ALL parts of code where two calls to the seek cursor are done, while the second call _relies_ on
1850
        // the first one, should be secured against recursion, with a broad-minded interpretation of "recursion": if any of these
1851
        // code parts is executed, no other should be accessible. But this sounds very difficult to achieve...
1852
        // )
1853
1854
        // The next problem caused by the same behavior (SeekCursor causes a propertyChanged): when adjusting rows we implicitly
1855
        // change our selection. So a "FirstSelected(); SeekCursor(); NextSelected();" may produce unpredictable results.
1856
        // That's why we _first_ collect the indices of the selected rows and _then_ their bookmarks.
1857
0
        tools::Long nIdx = FirstSelectedRow();
1858
0
        while (nIdx != BROWSER_ENDOFSELECTION)
1859
0
        {
1860
            // (we misuse the bookmarks array for this ...)
1861
0
            pBookmarks[i++] <<= static_cast<sal_Int32>(nIdx);
1862
0
            nIdx = NextSelectedRow();
1863
0
        }
1864
0
        DBG_ASSERT(i == nSelectedRows, "FmGridControl::DeleteSelectedRows : could not collect the row indices !");
1865
1866
0
        for (i=0; i<nSelectedRows; ++i)
1867
0
        {
1868
0
            nIdx = ::comphelper::getINT32(pBookmarks[i]);
1869
0
            if (IsInsertionRow(nIdx))
1870
0
            {
1871
                // do not delete empty row
1872
0
                aBookmarks.realloc(--nSelectedRows);
1873
0
                SelectRow(nIdx, false);          // cancel selection for empty row
1874
0
                break;
1875
0
            }
1876
1877
            // first, position the data cursor on the selected block
1878
0
            if (SeekCursor(nIdx))
1879
0
            {
1880
0
                GetSeekRow()->SetState(m_pSeekCursor.get(), true);
1881
1882
0
                pBookmarks[i] = m_pSeekCursor->getBookmark();
1883
0
            }
1884
    #ifdef DBG_UTIL
1885
            else
1886
                OSL_FAIL("FmGridControl::DeleteSelectedRows : a bookmark could not be determined !");
1887
    #endif
1888
0
        }
1889
0
    }
1890
0
    SetUpdateMode(true);
1891
1892
    // if one of the SeekCursor-calls failed...
1893
0
    aBookmarks.realloc(i);
1894
1895
    // (the alternative : while collecting the bookmarks lock our propertyChanged, this should resolve both our problems.
1896
    // but this would be incompatible as we need a locking flag, then...)
1897
1898
0
    return aBookmarks;
1899
0
}
1900
1901
namespace
1902
{
1903
    OUString getColumnPropertyFromPeer(FmXGridPeer* _pPeer,sal_Int32 _nPosition,const OUString& _sPropName)
1904
0
    {
1905
0
        OUString sRetText;
1906
0
        if ( _pPeer && _nPosition != -1)
1907
0
        {
1908
0
            Reference<XIndexContainer> xIndex = _pPeer->getColumns();
1909
0
            if ( xIndex.is() && xIndex->getCount() > _nPosition )
1910
0
            {
1911
0
                Reference<XPropertySet> xProp;
1912
0
                xIndex->getByIndex( _nPosition ) >>= xProp;
1913
0
                if ( xProp.is() )
1914
0
                {
1915
0
                    try {
1916
0
                        xProp->getPropertyValue( _sPropName ) >>= sRetText;
1917
0
                    } catch (UnknownPropertyException const&) {
1918
0
                        TOOLS_WARN_EXCEPTION("svx.fmcomp", "");
1919
0
                    }
1920
0
                }
1921
0
            }
1922
0
        }
1923
0
        return sRetText;
1924
0
    }
1925
}
1926
1927
// Object data and state
1928
OUString FmGridControl::GetAccessibleObjectName( AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const
1929
0
{
1930
0
    OUString sRetText;
1931
0
    switch( _eObjType )
1932
0
    {
1933
0
        case AccessibleBrowseBoxObjType::BrowseBox:
1934
0
            if ( GetPeer() )
1935
0
            {
1936
0
                Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY);
1937
0
                if ( xProp.is() )
1938
0
                    xProp->getPropertyValue(FM_PROP_NAME) >>= sRetText;
1939
0
            }
1940
0
            break;
1941
0
        case AccessibleBrowseBoxObjType::ColumnHeaderCell:
1942
0
            sRetText = getColumnPropertyFromPeer(
1943
0
                GetPeer(),
1944
0
                GetModelColumnPos(
1945
0
                    sal::static_int_cast< sal_uInt16 >(_nPosition)),
1946
0
                FM_PROP_LABEL);
1947
0
            break;
1948
0
        default:
1949
0
            sRetText = DbGridControl::GetAccessibleObjectName(_eObjType,_nPosition);
1950
0
    }
1951
0
    return sRetText;
1952
0
}
1953
1954
OUString FmGridControl::GetAccessibleObjectDescription( AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const
1955
0
{
1956
0
    OUString sRetText;
1957
0
    switch( _eObjType )
1958
0
    {
1959
0
        case AccessibleBrowseBoxObjType::BrowseBox:
1960
0
            if ( GetPeer() )
1961
0
            {
1962
0
                Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY);
1963
0
                if ( xProp.is() )
1964
0
                {
1965
0
                    xProp->getPropertyValue(FM_PROP_HELPTEXT) >>= sRetText;
1966
0
                    if ( sRetText.isEmpty() )
1967
0
                        xProp->getPropertyValue(FM_PROP_DESCRIPTION) >>= sRetText;
1968
0
                }
1969
0
            }
1970
0
            break;
1971
0
        case AccessibleBrowseBoxObjType::ColumnHeaderCell:
1972
0
            sRetText = getColumnPropertyFromPeer(
1973
0
                GetPeer(),
1974
0
                GetModelColumnPos(
1975
0
                    sal::static_int_cast< sal_uInt16 >(_nPosition)),
1976
0
                FM_PROP_HELPTEXT);
1977
0
            if ( sRetText.isEmpty() )
1978
0
                sRetText = getColumnPropertyFromPeer(
1979
0
                            GetPeer(),
1980
0
                            GetModelColumnPos(
1981
0
                                sal::static_int_cast< sal_uInt16 >(_nPosition)),
1982
0
                            FM_PROP_DESCRIPTION);
1983
1984
0
            break;
1985
0
        default:
1986
0
            sRetText = DbGridControl::GetAccessibleObjectDescription(_eObjType,_nPosition);
1987
0
    }
1988
0
    return sRetText;
1989
0
}
1990
1991
void FmGridControl::Select()
1992
0
{
1993
0
    DbGridControl::Select();
1994
    // ... does it affect our columns?
1995
0
    const MultiSelection* pColumnSelection = GetColumnSelection();
1996
1997
0
    sal_uInt16 nSelectedColumn =
1998
0
        pColumnSelection && pColumnSelection->GetSelectCount()
1999
0
            ? sal::static_int_cast< sal_uInt16 >(
2000
0
                const_cast<MultiSelection*>(pColumnSelection)->FirstSelected())
2001
0
            : SAL_MAX_UINT16;
2002
    // the HandleColumn is not selected
2003
0
    switch (nSelectedColumn)
2004
0
    {
2005
0
        case SAL_MAX_UINT16: break; // no selection
2006
0
        case  0 : nSelectedColumn = SAL_MAX_UINT16; break;
2007
                    // handle col can't be selected
2008
0
        default :
2009
            // get the model col pos instead of the view col pos
2010
0
            nSelectedColumn = GetModelColumnPos(GetColumnIdFromViewPos(nSelectedColumn - 1));
2011
0
            break;
2012
0
    }
2013
2014
0
    if (nSelectedColumn == m_nCurrentSelectedColumn)
2015
0
        return;
2016
2017
    // BEFORE calling the select at the SelectionSupplier!
2018
0
    m_nCurrentSelectedColumn = nSelectedColumn;
2019
2020
0
    if (m_bSelecting)
2021
0
        return;
2022
2023
0
    m_bSelecting = true;
2024
2025
0
    try
2026
0
    {
2027
0
        Reference< XIndexAccess >  xColumns = GetPeer()->getColumns();
2028
0
        Reference< XSelectionSupplier >  xSelSupplier(xColumns, UNO_QUERY);
2029
0
        if (xSelSupplier.is())
2030
0
        {
2031
0
            if (nSelectedColumn != SAL_MAX_UINT16)
2032
0
            {
2033
0
                Reference< XPropertySet >  xColumn(
2034
0
                    xColumns->getByIndex(nSelectedColumn),
2035
0
                    css::uno::UNO_QUERY);
2036
0
                xSelSupplier->select(Any(xColumn));
2037
0
            }
2038
0
            else
2039
0
            {
2040
0
                xSelSupplier->select(Any());
2041
0
            }
2042
0
        }
2043
0
    }
2044
0
    catch(Exception&)
2045
0
    {
2046
0
    }
2047
2048
2049
0
    m_bSelecting = false;
2050
0
}
2051
2052
2053
void FmGridControl::KeyInput( const KeyEvent& rKEvt )
2054
0
{
2055
0
    bool bDone = false;
2056
0
    const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
2057
0
    if (    IsDesignMode()
2058
0
        &&  !rKeyCode.IsShift()
2059
0
        &&  !rKeyCode.IsMod1()
2060
0
        &&  !rKeyCode.IsMod2()
2061
0
        &&  GetParent() )
2062
0
    {
2063
0
        switch ( rKeyCode.GetCode() )
2064
0
        {
2065
0
            case KEY_ESCAPE:
2066
0
                GetParent()->GrabFocus();
2067
0
                bDone = true;
2068
0
                break;
2069
0
            case KEY_DELETE:
2070
0
                if ( GetSelectColumnCount() && GetPeer() && m_nCurrentSelectedColumn >= 0 )
2071
0
                {
2072
0
                    Reference< css::container::XIndexContainer >  xCols(GetPeer()->getColumns());
2073
0
                    if ( xCols.is() )
2074
0
                    {
2075
0
                        try
2076
0
                        {
2077
0
                            if ( m_nCurrentSelectedColumn < xCols->getCount() )
2078
0
                            {
2079
0
                                Reference< XInterface >  xCol;
2080
0
                                xCols->getByIndex(m_nCurrentSelectedColumn) >>= xCol;
2081
0
                                xCols->removeByIndex(m_nCurrentSelectedColumn);
2082
0
                                ::comphelper::disposeComponent(xCol);
2083
0
                            }
2084
0
                        }
2085
0
                        catch(const Exception&)
2086
0
                        {
2087
0
                            TOOLS_WARN_EXCEPTION("svx", "exception occurred while deleting a column");
2088
0
                        }
2089
0
                    }
2090
0
                }
2091
0
                bDone = true;
2092
0
                break;
2093
0
        }
2094
0
    }
2095
0
    if ( !bDone )
2096
0
        DbGridControl::KeyInput( rKEvt );
2097
0
}
2098
2099
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */