merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / browser / dsEntriesNoExp.cxx
blobc108a66c0c9de348077ff53eb93091e2dcd84be9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dsEntriesNoExp.cxx,v $
10 * $Revision: 1.23 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _SBA_UNODATBR_HXX_
35 #include "unodatbr.hxx"
36 #endif
37 #ifndef DBACCESS_UI_BROWSER_ID_HXX
38 #include "browserids.hxx"
39 #endif
40 #ifndef _DBAUI_LISTVIEWITEMS_HXX_
41 #include "listviewitems.hxx"
42 #endif
43 #ifndef DBACCESS_IMAGEPROVIDER_HXX
44 #include "imageprovider.hxx"
45 #endif
46 #ifndef _TOOLS_DEBUG_HXX
47 #include <tools/debug.hxx>
48 #endif
49 #ifndef DBACCESS_UI_DBTREEVIEW_HXX
50 #include "dbtreeview.hxx"
51 #endif
52 #ifndef DBAUI_DBTREELISTBOX_HXX
53 #include "dbtreelistbox.hxx"
54 #endif
55 #ifndef _DBU_BRW_HRC_
56 #include "dbu_brw.hrc"
57 #endif
58 #ifndef DBAUI_DBTREEMODEL_HXX
59 #include "dbtreemodel.hxx"
60 #endif
62 using namespace ::com::sun::star::frame;
63 using namespace ::dbtools;
64 using namespace ::svx;
66 // .........................................................................
67 namespace dbaui
69 // .........................................................................
70 // -----------------------------------------------------------------------------
71 SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType( SvLBoxEntry* _pEntry ) const
73 DBG_ASSERT(isContainer(_pEntry), "SbaTableQueryBrowser::getChildType: invalid entry!");
74 switch (getEntryType(_pEntry))
76 case etTableContainer:
77 return etTableOrView;
78 case etQueryContainer:
79 return etQuery;
80 default:
81 break;
83 return etUnknown;
86 // -----------------------------------------------------------------------------
87 String SbaTableQueryBrowser::GetEntryText( SvLBoxEntry* _pEntry ) const
89 return m_pTreeView->getListBox().GetEntryText(_pEntry);
92 // -----------------------------------------------------------------------------
93 SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvLBoxEntry* _pEntry ) const
95 if (!_pEntry)
96 return etUnknown;
98 SvLBoxEntry* pRootEntry = m_pTreeView->getListBox().GetRootLevelParent(_pEntry);
99 SvLBoxEntry* pEntryParent = m_pTreeView->getListBox().GetParent(_pEntry);
100 SvLBoxEntry* pTables = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_TABLES);
101 SvLBoxEntry* pQueries = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_QUERIES);
103 #ifdef DBG_UTIL
104 String sTest;
105 if (pTables) sTest = m_pTreeView->getListBox().GetEntryText(pTables);
106 if (pQueries) sTest = m_pTreeView->getListBox().GetEntryText(pQueries);
107 #endif
109 if (pRootEntry == _pEntry)
110 return etDatasource;
112 if (pTables == _pEntry)
113 return etTableContainer;
115 if (pQueries == _pEntry)
116 return etQueryContainer;
118 if (pTables == pEntryParent)
119 return etTableOrView;
121 if (pQueries == pEntryParent)
122 return etQuery;
124 return etUnknown;
126 //------------------------------------------------------------------------------
127 void SbaTableQueryBrowser::select(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
129 SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
130 if (pTextItem)
132 static_cast<OBoldListboxString*>(pTextItem)->emphasize(_bSelect);
133 m_pTreeModel->InvalidateEntry(_pEntry);
135 else {
136 DBG_ERROR("SbaTableQueryBrowser::select: invalid entry!");
140 //------------------------------------------------------------------------------
141 void SbaTableQueryBrowser::selectPath(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
143 while (_pEntry)
145 select(_pEntry, _bSelect);
146 _pEntry = m_pTreeModel->GetParent(_pEntry);
149 //------------------------------------------------------------------------------
150 sal_Bool SbaTableQueryBrowser::isSelected(SvLBoxEntry* _pEntry) const
152 SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
153 if (pTextItem)
154 return static_cast<OBoldListboxString*>(pTextItem)->isEmphasized();
155 else {
156 DBG_ERROR("SbaTableQueryBrowser::isSelected: invalid entry!");
158 return sal_False;
160 //------------------------------------------------------------------------------
161 void SbaTableQueryBrowser::SelectionChanged()
163 if ( !m_bShowMenu )
165 InvalidateFeature(ID_BROWSER_INSERTCOLUMNS);
166 InvalidateFeature(ID_BROWSER_INSERTCONTENT);
167 InvalidateFeature(ID_BROWSER_FORMLETTER);
168 } // if ( !m_bShowMenu )
169 InvalidateFeature(ID_BROWSER_COPY);
170 InvalidateFeature(ID_BROWSER_CUT);
172 //------------------------------------------------------------------------------
173 void SbaTableQueryBrowser::describeSupportedFeatures()
175 SbaXDataBrowserController::describeSupportedFeatures();
177 implDescribeSupportedFeature( ".uno:Title", ID_BROWSER_TITLE );
178 if ( !m_bShowMenu )
180 implDescribeSupportedFeature( ".uno:DSBrowserExplorer", ID_BROWSER_EXPLORER, CommandGroup::VIEW );
182 implDescribeSupportedFeature( ".uno:DSBFormLetter", ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT );
183 implDescribeSupportedFeature( ".uno:DSBInsertColumns", ID_BROWSER_INSERTCOLUMNS, CommandGroup::INSERT );
184 implDescribeSupportedFeature( ".uno:DSBInsertContent", ID_BROWSER_INSERTCONTENT, CommandGroup::INSERT );
185 implDescribeSupportedFeature( ".uno:DSBDocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE, CommandGroup::VIEW );
187 implDescribeSupportedFeature( ".uno:DataSourceBrowser/FormLetter", ID_BROWSER_FORMLETTER );
188 implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertColumns", ID_BROWSER_INSERTCOLUMNS );
189 implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertContent", ID_BROWSER_INSERTCONTENT );
190 implDescribeSupportedFeature( ".uno:DataSourceBrowser/DocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE );
193 implDescribeSupportedFeature( ".uno:CloseWin", ID_BROWSER_CLOSE, CommandGroup::DOCUMENT );
194 implDescribeSupportedFeature( ".uno:DBRebuildData", ID_BROWSER_REFRESH_REBUILD, CommandGroup::DATA );
197 // -----------------------------------------------------------------------------
198 sal_Int32 SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType )
200 switch ( _eType )
202 case etQuery:
203 case etQueryContainer:
204 return DatabaseObject::QUERY;
205 case etTableOrView:
206 case etTableContainer:
207 return DatabaseObject::TABLE;
208 default:
209 break;
211 OSL_ENSURE( false, "SbaTableQueryBrowser::getDatabaseObjectType: folder types and 'Unknown' not allowed here!" );
212 return DatabaseObject::TABLE;
215 // -----------------------------------------------------------------------------
216 void SbaTableQueryBrowser::notifyHiContrastChanged()
218 if ( m_pTreeView )
220 // change all bitmap entries
221 SvLBoxEntry* pEntryLoop = m_pTreeModel->First();
222 while ( pEntryLoop )
224 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
225 if ( !pData )
227 pEntryLoop = m_pTreeModel->Next(pEntryLoop);
228 continue;
231 // the connection to which this entry belongs, if any
232 ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( pEntryLoop ) );
234 // the images for this entry
235 Image aImage, aImageHC;
236 if ( pData->eType == etDatasource )
238 aImage = pImageProvider->getDatabaseImage( false );
239 aImageHC = pImageProvider->getDatabaseImage( true );
241 else
243 bool bIsFolder = !isObject( pData->eType );
244 if ( bIsFolder )
246 sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
247 aImage = pImageProvider->getFolderImage( nObjectType, false );
248 aImageHC = pImageProvider->getFolderImage( nObjectType, true );
250 else
252 sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
253 pImageProvider->getImages( GetEntryText( pEntryLoop ), nObjectType, aImage, aImageHC );
257 // find the proper item, and set its icons
258 USHORT nCount = pEntryLoop->ItemCount();
259 for (USHORT i=0;i<nCount;++i)
261 SvLBoxItem* pItem = pEntryLoop->GetItem(i);
262 if ( !pItem || ( pItem->IsA() != SV_ITEM_ID_LBOXCONTEXTBMP ) )
263 continue;
265 SvLBoxContextBmp* pContextBitmapItem = static_cast< SvLBoxContextBmp* >( pItem );
267 pContextBitmapItem->SetBitmap1( aImage, BMP_COLOR_NORMAL );
268 pContextBitmapItem->SetBitmap2( aImage, BMP_COLOR_NORMAL );
269 pContextBitmapItem->SetBitmap1( aImageHC, BMP_COLOR_HIGHCONTRAST );
270 pContextBitmapItem->SetBitmap2( aImageHC, BMP_COLOR_HIGHCONTRAST );
271 break;
274 pEntryLoop = m_pTreeModel->Next(pEntryLoop);
278 // -----------------------------------------------------------------------------
279 // .........................................................................
280 } // namespace dbaui
281 // .........................................................................