1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <memory>
#include <unodatbr.hxx>
#include <browserids.hxx>
#include <listviewitems.hxx>
#include <imageprovider.hxx>
#include <osl/diagnose.h>
#include "dbtreeview.hxx"
#include <dbtreelistbox.hxx>
#include "dbtreemodel.hxx"
#include <vcl/treelistentry.hxx>
using namespace ::com::sun::star::frame;
using namespace ::dbtools;
using namespace ::svx;
namespace dbaui
{
SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType( SvTreeListEntry const * _pEntry ) const
{
OSL_ENSURE(isContainer(_pEntry), "SbaTableQueryBrowser::getChildType: invalid entry!");
switch (getEntryType(_pEntry))
{
case etTableContainer:
return etTableOrView;
case etQueryContainer:
return etQuery;
default:
break;
}
return etUnknown;
}
OUString SbaTableQueryBrowser::GetEntryText( SvTreeListEntry* _pEntry ) const
{
return m_pTreeView->getListBox().GetEntryText(_pEntry);
}
SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( const SvTreeListEntry* _pEntry ) const
{
if (!_pEntry)
return etUnknown;
SvTreeListEntry* pRootEntry = m_pTreeView->getListBox().GetRootLevelParent(const_cast<SvTreeListEntry*>(_pEntry));
SvTreeListEntry* pEntryParent = m_pTreeView->getListBox().GetParent(const_cast<SvTreeListEntry*>(_pEntry));
SvTreeListEntry* pTables = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_TABLES);
SvTreeListEntry* pQueries = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_QUERIES);
#ifdef DBG_UTIL
OUString sTest;
if (pTables) sTest = m_pTreeView->getListBox().GetEntryText(pTables);
if (pQueries) sTest = m_pTreeView->getListBox().GetEntryText(pQueries);
#endif
if (pRootEntry == _pEntry)
return etDatasource;
if (pTables == _pEntry)
return etTableContainer;
if (pQueries == _pEntry)
return etQueryContainer;
if (pTables == pEntryParent)
return etTableOrView;
if (pQueries == pEntryParent)
{
DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
if ( pEntryData )
return pEntryData->eType;
return etQuery;
}
while( pEntryParent != pQueries )
{
pEntryParent = m_pTreeView->getListBox().GetParent(pEntryParent);
if ( !pEntryParent )
return etUnknown;
}
return etQueryContainer;
}
void SbaTableQueryBrowser::select(SvTreeListEntry* _pEntry, bool _bSelect)
{
SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SvLBoxItemType::String) : nullptr;
if (pTextItem)
{
static_cast<OBoldListboxString*>(pTextItem)->emphasize(_bSelect);
m_pTreeView->GetTreeModel()->InvalidateEntry(_pEntry);
}
else {
OSL_FAIL("SbaTableQueryBrowser::select: invalid entry!");
}
}
void SbaTableQueryBrowser::selectPath(SvTreeListEntry* _pEntry, bool _bSelect)
{
while (_pEntry)
{
select(_pEntry, _bSelect);
_pEntry = m_pTreeView->GetTreeModel()->GetParent(_pEntry);
}
}
bool SbaTableQueryBrowser::isSelected(SvTreeListEntry* _pEntry)
{
SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SvLBoxItemType::String) : nullptr;
if (pTextItem)
return static_cast<OBoldListboxString*>(pTextItem)->isEmphasized();
else {
OSL_FAIL("SbaTableQueryBrowser::isSelected: invalid entry!");
}
return false;
}
void SbaTableQueryBrowser::SelectionChanged()
{
if ( !m_bShowMenu )
{
InvalidateFeature(ID_BROWSER_INSERTCOLUMNS);
InvalidateFeature(ID_BROWSER_INSERTCONTENT);
InvalidateFeature(ID_BROWSER_FORMLETTER);
}
InvalidateFeature(ID_BROWSER_COPY);
InvalidateFeature(ID_BROWSER_CUT);
}
void SbaTableQueryBrowser::describeSupportedFeatures()
{
SbaXDataBrowserController::describeSupportedFeatures();
implDescribeSupportedFeature( ".uno:Title", ID_BROWSER_TITLE );
if ( !m_bShowMenu )
{
implDescribeSupportedFeature( ".uno:DSBEditDB", ID_TREE_EDIT_DATABASE );
implDescribeSupportedFeature( ".uno:DSBCloseConnection", ID_TREE_CLOSE_CONN );
implDescribeSupportedFeature( ".uno:DSBAdministrate", ID_TREE_ADMINISTRATE );
implDescribeSupportedFeature( ".uno:DSBrowserExplorer", ID_BROWSER_EXPLORER, CommandGroup::VIEW );
implDescribeSupportedFeature( ".uno:DSBFormLetter", ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT );
implDescribeSupportedFeature( ".uno:DSBInsertColumns", ID_BROWSER_INSERTCOLUMNS, CommandGroup::INSERT );
implDescribeSupportedFeature( ".uno:DSBInsertContent", ID_BROWSER_INSERTCONTENT, CommandGroup::INSERT );
implDescribeSupportedFeature( ".uno:DSBDocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE, CommandGroup::VIEW );
implDescribeSupportedFeature( ".uno:DataSourceBrowser/FormLetter", ID_BROWSER_FORMLETTER );
implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertColumns", ID_BROWSER_INSERTCOLUMNS );
implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertContent", ID_BROWSER_INSERTCONTENT );
implDescribeSupportedFeature( ".uno:DataSourceBrowser/DocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE );
}
implDescribeSupportedFeature( ".uno:CloseWin", ID_BROWSER_CLOSE, CommandGroup::DOCUMENT );
implDescribeSupportedFeature( ".uno:DBRebuildData", ID_BROWSER_REFRESH_REBUILD, CommandGroup::DATA );
}
sal_Int32 SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType )
{
switch ( _eType )
{
case etQuery:
case etQueryContainer:
return css::sdb::application::DatabaseObject::QUERY;
case etTableOrView:
case etTableContainer:
return css::sdb::application::DatabaseObject::TABLE;
default:
break;
}
OSL_FAIL( "SbaTableQueryBrowser::getDatabaseObjectType: folder types and 'Unknown' not allowed here!" );
return css::sdb::application::DatabaseObject::TABLE;
}
void SbaTableQueryBrowser::notifyHiContrastChanged()
{
if ( !m_pTreeView )
return;
auto pTreeModel = m_pTreeView->GetTreeModel();
// change all bitmap entries
SvTreeListEntry* pEntryLoop = pTreeModel->First();
while ( pEntryLoop )
{
DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
if ( !pData )
{
pEntryLoop = pTreeModel->Next(pEntryLoop);
continue;
}
// the connection to which this entry belongs, if any
std::unique_ptr< ImageProvider > pImageProvider( getImageProviderFor( pEntryLoop ) );
// the images for this entry
Image aImage;
if ( pData->eType == etDatasource )
aImage = ImageProvider::getDatabaseImage();
else
{
bool bIsFolder = !isObject( pData->eType );
if ( bIsFolder )
{
sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
aImage = ImageProvider::getFolderImage( nObjectType );
}
else
{
sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
pImageProvider->getImages( GetEntryText( pEntryLoop ), nObjectType, aImage );
}
}
// find the proper item, and set its icons
sal_uInt16 nCount = pEntryLoop->ItemCount();
for (sal_uInt16 i=0;i<nCount;++i)
{
SvLBoxItem& rItem = pEntryLoop->GetItem(i);
if (rItem.GetType() != SvLBoxItemType::ContextBmp)
continue;
SvLBoxContextBmp& rContextBitmapItem = static_cast< SvLBoxContextBmp& >( rItem );
rContextBitmapItem.SetBitmap1( aImage );
rContextBitmapItem.SetBitmap2( aImage );
break;
}
pEntryLoop = pTreeModel->Next(pEntryLoop);
}
}
} // namespace dbaui
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|