Line data Source code
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 <sal/config.h>
21 :
22 : #include <memory>
23 :
24 : #include "unodatbr.hxx"
25 : #include "browserids.hxx"
26 : #include "listviewitems.hxx"
27 : #include "imageprovider.hxx"
28 : #include <osl/diagnose.h>
29 : #include "dbtreeview.hxx"
30 : #include "dbtreelistbox.hxx"
31 : #include "dbu_brw.hrc"
32 : #include "dbtreemodel.hxx"
33 : #include "svtools/treelistentry.hxx"
34 :
35 : using namespace ::com::sun::star::frame;
36 : using namespace ::dbtools;
37 : using namespace ::svx;
38 :
39 : namespace dbaui
40 : {
41 0 : SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType( SvTreeListEntry* _pEntry ) const
42 : {
43 : OSL_ENSURE(isContainer(_pEntry), "SbaTableQueryBrowser::getChildType: invalid entry!");
44 0 : switch (getEntryType(_pEntry))
45 : {
46 : case etTableContainer:
47 0 : return etTableOrView;
48 : case etQueryContainer:
49 0 : return etQuery;
50 : default:
51 0 : break;
52 : }
53 0 : return etUnknown;
54 : }
55 :
56 10 : OUString SbaTableQueryBrowser::GetEntryText( SvTreeListEntry* _pEntry ) const
57 : {
58 10 : return m_pTreeView->getListBox().GetEntryText(_pEntry);
59 : }
60 :
61 4 : SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( const SvTreeListEntry* _pEntry ) const
62 : {
63 4 : if (!_pEntry)
64 0 : return etUnknown;
65 :
66 4 : SvTreeListEntry* pRootEntry = m_pTreeView->getListBox().GetRootLevelParent(const_cast<SvTreeListEntry*>(_pEntry));
67 4 : SvTreeListEntry* pEntryParent = m_pTreeView->getListBox().GetParent(const_cast<SvTreeListEntry*>(_pEntry));
68 4 : SvTreeListEntry* pTables = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_TABLES);
69 4 : SvTreeListEntry* pQueries = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_QUERIES);
70 :
71 : #ifdef DBG_UTIL
72 : OUString sTest;
73 : if (pTables) sTest = m_pTreeView->getListBox().GetEntryText(pTables);
74 : if (pQueries) sTest = m_pTreeView->getListBox().GetEntryText(pQueries);
75 : #endif
76 :
77 4 : if (pRootEntry == _pEntry)
78 0 : return etDatasource;
79 :
80 4 : if (pTables == _pEntry)
81 0 : return etTableContainer;
82 :
83 4 : if (pQueries == _pEntry)
84 4 : return etQueryContainer;
85 :
86 0 : if (pTables == pEntryParent)
87 0 : return etTableOrView;
88 :
89 0 : if (pQueries == pEntryParent)
90 : {
91 0 : DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
92 0 : if ( pEntryData )
93 0 : return pEntryData->eType;
94 :
95 0 : return etQuery;
96 : }
97 0 : while( pEntryParent != pQueries )
98 : {
99 0 : pEntryParent = m_pTreeView->getListBox().GetParent(pEntryParent);
100 0 : if ( !pEntryParent )
101 0 : return etUnknown;
102 : }
103 :
104 0 : return etQueryContainer;
105 : }
106 :
107 6 : void SbaTableQueryBrowser::select(SvTreeListEntry* _pEntry, bool _bSelect)
108 : {
109 6 : SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
110 6 : if (pTextItem)
111 : {
112 6 : static_cast<OBoldListboxString*>(pTextItem)->emphasize(_bSelect);
113 6 : m_pTreeModel->InvalidateEntry(_pEntry);
114 : }
115 : else {
116 : OSL_FAIL("SbaTableQueryBrowser::select: invalid entry!");
117 : }
118 6 : }
119 :
120 4 : void SbaTableQueryBrowser::selectPath(SvTreeListEntry* _pEntry, bool _bSelect)
121 : {
122 14 : while (_pEntry)
123 : {
124 6 : select(_pEntry, _bSelect);
125 6 : _pEntry = m_pTreeModel->GetParent(_pEntry);
126 : }
127 4 : }
128 :
129 0 : bool SbaTableQueryBrowser::isSelected(SvTreeListEntry* _pEntry) const
130 : {
131 0 : SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
132 0 : if (pTextItem)
133 0 : return static_cast<OBoldListboxString*>(pTextItem)->isEmphasized();
134 : else {
135 : OSL_FAIL("SbaTableQueryBrowser::isSelected: invalid entry!");
136 : }
137 0 : return false;
138 : }
139 :
140 0 : void SbaTableQueryBrowser::SelectionChanged()
141 : {
142 0 : if ( !m_bShowMenu )
143 : {
144 0 : InvalidateFeature(ID_BROWSER_INSERTCOLUMNS);
145 0 : InvalidateFeature(ID_BROWSER_INSERTCONTENT);
146 0 : InvalidateFeature(ID_BROWSER_FORMLETTER);
147 : }
148 0 : InvalidateFeature(ID_BROWSER_COPY);
149 0 : InvalidateFeature(ID_BROWSER_CUT);
150 0 : }
151 :
152 2 : void SbaTableQueryBrowser::describeSupportedFeatures()
153 : {
154 2 : SbaXDataBrowserController::describeSupportedFeatures();
155 :
156 2 : implDescribeSupportedFeature( ".uno:Title", ID_BROWSER_TITLE );
157 2 : if ( !m_bShowMenu )
158 : {
159 2 : implDescribeSupportedFeature( ".uno:DSBrowserExplorer", ID_BROWSER_EXPLORER, CommandGroup::VIEW );
160 :
161 2 : implDescribeSupportedFeature( ".uno:DSBFormLetter", ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT );
162 2 : implDescribeSupportedFeature( ".uno:DSBInsertColumns", ID_BROWSER_INSERTCOLUMNS, CommandGroup::INSERT );
163 2 : implDescribeSupportedFeature( ".uno:DSBInsertContent", ID_BROWSER_INSERTCONTENT, CommandGroup::INSERT );
164 2 : implDescribeSupportedFeature( ".uno:DSBDocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE, CommandGroup::VIEW );
165 :
166 2 : implDescribeSupportedFeature( ".uno:DataSourceBrowser/FormLetter", ID_BROWSER_FORMLETTER );
167 2 : implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertColumns", ID_BROWSER_INSERTCOLUMNS );
168 2 : implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertContent", ID_BROWSER_INSERTCONTENT );
169 2 : implDescribeSupportedFeature( ".uno:DataSourceBrowser/DocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE );
170 : }
171 :
172 2 : implDescribeSupportedFeature( ".uno:CloseWin", ID_BROWSER_CLOSE, CommandGroup::DOCUMENT );
173 2 : implDescribeSupportedFeature( ".uno:DBRebuildData", ID_BROWSER_REFRESH_REBUILD, CommandGroup::DATA );
174 2 : }
175 :
176 2 : sal_Int32 SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType )
177 : {
178 2 : switch ( _eType )
179 : {
180 : case etQuery:
181 : case etQueryContainer:
182 0 : return css::sdb::application::DatabaseObject::QUERY;
183 : case etTableOrView:
184 : case etTableContainer:
185 2 : return css::sdb::application::DatabaseObject::TABLE;
186 : default:
187 0 : break;
188 : }
189 : OSL_FAIL( "SbaTableQueryBrowser::getDatabaseObjectType: folder types and 'Unknown' not allowed here!" );
190 0 : return css::sdb::application::DatabaseObject::TABLE;
191 : }
192 :
193 0 : void SbaTableQueryBrowser::notifyHiContrastChanged()
194 : {
195 0 : if ( m_pTreeView )
196 : {
197 : // change all bitmap entries
198 0 : SvTreeListEntry* pEntryLoop = m_pTreeModel->First();
199 0 : while ( pEntryLoop )
200 : {
201 0 : DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
202 0 : if ( !pData )
203 : {
204 0 : pEntryLoop = m_pTreeModel->Next(pEntryLoop);
205 0 : continue;
206 : }
207 :
208 : // the connection to which this entry belongs, if any
209 0 : std::unique_ptr< ImageProvider > pImageProvider( getImageProviderFor( pEntryLoop ) );
210 :
211 : // the images for this entry
212 0 : Image aImage;
213 0 : if ( pData->eType == etDatasource )
214 0 : aImage = pImageProvider->getDatabaseImage();
215 : else
216 : {
217 0 : bool bIsFolder = !isObject( pData->eType );
218 0 : if ( bIsFolder )
219 : {
220 0 : sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
221 0 : aImage = pImageProvider->getFolderImage( nObjectType );
222 : }
223 : else
224 : {
225 0 : sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
226 0 : pImageProvider->getImages( GetEntryText( pEntryLoop ), nObjectType, aImage );
227 : }
228 : }
229 :
230 : // find the proper item, and set its icons
231 0 : sal_uInt16 nCount = pEntryLoop->ItemCount();
232 0 : for (sal_uInt16 i=0;i<nCount;++i)
233 : {
234 0 : SvLBoxItem* pItem = pEntryLoop->GetItem(i);
235 0 : if (!pItem || pItem->GetType() != SV_ITEM_ID_LBOXCONTEXTBMP)
236 0 : continue;
237 :
238 0 : SvLBoxContextBmp* pContextBitmapItem = static_cast< SvLBoxContextBmp* >( pItem );
239 :
240 0 : pContextBitmapItem->SetBitmap1( aImage );
241 0 : pContextBitmapItem->SetBitmap2( aImage );
242 0 : break;
243 : }
244 :
245 0 : pEntryLoop = m_pTreeModel->Next(pEntryLoop);
246 0 : }
247 : }
248 0 : }
249 :
250 72 : } // namespace dbaui
251 :
252 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|