Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / browser / dsEntriesNoExp.cxx
blob04fcbeb64627fbea43ade9bf3f8686797d3ff17e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "unodatbr.hxx"
31 #include "browserids.hxx"
32 #include "listviewitems.hxx"
33 #include "imageprovider.hxx"
34 #include <osl/diagnose.h>
35 #include "dbtreeview.hxx"
36 #include "dbtreelistbox.hxx"
37 #include "dbu_brw.hrc"
38 #include "dbtreemodel.hxx"
40 using namespace ::com::sun::star::frame;
41 using namespace ::dbtools;
42 using namespace ::svx;
44 // .........................................................................
45 namespace dbaui
47 // .........................................................................
48 // -----------------------------------------------------------------------------
49 SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType( SvLBoxEntry* _pEntry ) const
51 OSL_ENSURE(isContainer(_pEntry), "SbaTableQueryBrowser::getChildType: invalid entry!");
52 switch (getEntryType(_pEntry))
54 case etTableContainer:
55 return etTableOrView;
56 case etQueryContainer:
57 return etQuery;
58 default:
59 break;
61 return etUnknown;
64 // -----------------------------------------------------------------------------
65 String SbaTableQueryBrowser::GetEntryText( SvLBoxEntry* _pEntry ) const
67 return m_pTreeView->getListBox().GetEntryText(_pEntry);
70 // -----------------------------------------------------------------------------
71 SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvLBoxEntry* _pEntry ) const
73 if (!_pEntry)
74 return etUnknown;
76 SvLBoxEntry* pRootEntry = m_pTreeView->getListBox().GetRootLevelParent(_pEntry);
77 SvLBoxEntry* pEntryParent = m_pTreeView->getListBox().GetParent(_pEntry);
78 SvLBoxEntry* pTables = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_TABLES);
79 SvLBoxEntry* pQueries = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_QUERIES);
81 #ifdef DBG_UTIL
82 String sTest;
83 if (pTables) sTest = m_pTreeView->getListBox().GetEntryText(pTables);
84 if (pQueries) sTest = m_pTreeView->getListBox().GetEntryText(pQueries);
85 #endif
87 if (pRootEntry == _pEntry)
88 return etDatasource;
90 if (pTables == _pEntry)
91 return etTableContainer;
93 if (pQueries == _pEntry)
94 return etQueryContainer;
96 if (pTables == pEntryParent)
97 return etTableOrView;
99 if (pQueries == pEntryParent)
101 DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
102 if ( pEntryData )
103 return pEntryData->eType;
105 return etQuery;
107 while( pEntryParent != pQueries )
109 pEntryParent = m_pTreeView->getListBox().GetParent(pEntryParent);
110 if ( !pEntryParent )
111 return etUnknown;
114 return etQueryContainer;
116 //------------------------------------------------------------------------------
117 void SbaTableQueryBrowser::select(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
119 SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
120 if (pTextItem)
122 static_cast<OBoldListboxString*>(pTextItem)->emphasize(_bSelect);
123 m_pTreeModel->InvalidateEntry(_pEntry);
125 else {
126 OSL_FAIL("SbaTableQueryBrowser::select: invalid entry!");
130 //------------------------------------------------------------------------------
131 void SbaTableQueryBrowser::selectPath(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
133 while (_pEntry)
135 select(_pEntry, _bSelect);
136 _pEntry = m_pTreeModel->GetParent(_pEntry);
139 //------------------------------------------------------------------------------
140 sal_Bool SbaTableQueryBrowser::isSelected(SvLBoxEntry* _pEntry) const
142 SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
143 if (pTextItem)
144 return static_cast<OBoldListboxString*>(pTextItem)->isEmphasized();
145 else {
146 OSL_FAIL("SbaTableQueryBrowser::isSelected: invalid entry!");
148 return sal_False;
150 //------------------------------------------------------------------------------
151 void SbaTableQueryBrowser::SelectionChanged()
153 if ( !m_bShowMenu )
155 InvalidateFeature(ID_BROWSER_INSERTCOLUMNS);
156 InvalidateFeature(ID_BROWSER_INSERTCONTENT);
157 InvalidateFeature(ID_BROWSER_FORMLETTER);
159 InvalidateFeature(ID_BROWSER_COPY);
160 InvalidateFeature(ID_BROWSER_CUT);
162 //------------------------------------------------------------------------------
163 void SbaTableQueryBrowser::describeSupportedFeatures()
165 SbaXDataBrowserController::describeSupportedFeatures();
167 implDescribeSupportedFeature( ".uno:Title", ID_BROWSER_TITLE );
168 if ( !m_bShowMenu )
170 implDescribeSupportedFeature( ".uno:DSBrowserExplorer", ID_BROWSER_EXPLORER, CommandGroup::VIEW );
172 implDescribeSupportedFeature( ".uno:DSBFormLetter", ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT );
173 implDescribeSupportedFeature( ".uno:DSBInsertColumns", ID_BROWSER_INSERTCOLUMNS, CommandGroup::INSERT );
174 implDescribeSupportedFeature( ".uno:DSBInsertContent", ID_BROWSER_INSERTCONTENT, CommandGroup::INSERT );
175 implDescribeSupportedFeature( ".uno:DSBDocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE, CommandGroup::VIEW );
177 implDescribeSupportedFeature( ".uno:DataSourceBrowser/FormLetter", ID_BROWSER_FORMLETTER );
178 implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertColumns", ID_BROWSER_INSERTCOLUMNS );
179 implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertContent", ID_BROWSER_INSERTCONTENT );
180 implDescribeSupportedFeature( ".uno:DataSourceBrowser/DocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE );
183 implDescribeSupportedFeature( ".uno:CloseWin", ID_BROWSER_CLOSE, CommandGroup::DOCUMENT );
184 implDescribeSupportedFeature( ".uno:DBRebuildData", ID_BROWSER_REFRESH_REBUILD, CommandGroup::DATA );
187 // -----------------------------------------------------------------------------
188 sal_Int32 SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType )
190 switch ( _eType )
192 case etQuery:
193 case etQueryContainer:
194 return DatabaseObject::QUERY;
195 case etTableOrView:
196 case etTableContainer:
197 return DatabaseObject::TABLE;
198 default:
199 break;
201 OSL_FAIL( "SbaTableQueryBrowser::getDatabaseObjectType: folder types and 'Unknown' not allowed here!" );
202 return DatabaseObject::TABLE;
205 // -----------------------------------------------------------------------------
206 void SbaTableQueryBrowser::notifyHiContrastChanged()
208 if ( m_pTreeView )
210 // change all bitmap entries
211 SvLBoxEntry* pEntryLoop = m_pTreeModel->First();
212 while ( pEntryLoop )
214 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
215 if ( !pData )
217 pEntryLoop = m_pTreeModel->Next(pEntryLoop);
218 continue;
221 // the connection to which this entry belongs, if any
222 ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( pEntryLoop ) );
224 // the images for this entry
225 Image aImage;
226 if ( pData->eType == etDatasource )
227 aImage = pImageProvider->getDatabaseImage();
228 else
230 bool bIsFolder = !isObject( pData->eType );
231 if ( bIsFolder )
233 sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
234 aImage = pImageProvider->getFolderImage( nObjectType );
236 else
238 sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
239 pImageProvider->getImages( GetEntryText( pEntryLoop ), nObjectType, aImage );
243 // find the proper item, and set its icons
244 sal_uInt16 nCount = pEntryLoop->ItemCount();
245 for (sal_uInt16 i=0;i<nCount;++i)
247 SvLBoxItem* pItem = pEntryLoop->GetItem(i);
248 if ( !pItem || ( pItem->IsA() != SV_ITEM_ID_LBOXCONTEXTBMP ) )
249 continue;
251 SvLBoxContextBmp* pContextBitmapItem = static_cast< SvLBoxContextBmp* >( pItem );
253 pContextBitmapItem->SetBitmap1( aImage );
254 pContextBitmapItem->SetBitmap2( aImage );
255 break;
258 pEntryLoop = m_pTreeModel->Next(pEntryLoop);
262 // -----------------------------------------------------------------------------
263 // .........................................................................
264 } // namespace dbaui
265 // .........................................................................
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */