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