1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _SBA_UNODATBR_HXX_
28cdf0e10cSrcweir #include "unodatbr.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
31cdf0e10cSrcweir #include "browserids.hxx"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _DBAUI_LISTVIEWITEMS_HXX_
34cdf0e10cSrcweir #include "listviewitems.hxx"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef DBACCESS_IMAGEPROVIDER_HXX
37cdf0e10cSrcweir #include "imageprovider.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
40cdf0e10cSrcweir #include <tools/debug.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef DBACCESS_UI_DBTREEVIEW_HXX
43cdf0e10cSrcweir #include "dbtreeview.hxx"
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef DBAUI_DBTREELISTBOX_HXX
46cdf0e10cSrcweir #include "dbtreelistbox.hxx"
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _DBU_BRW_HRC_
49cdf0e10cSrcweir #include "dbu_brw.hrc"
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef DBAUI_DBTREEMODEL_HXX
52cdf0e10cSrcweir #include "dbtreemodel.hxx"
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using namespace ::com::sun::star::frame;
56cdf0e10cSrcweir using namespace ::dbtools;
57cdf0e10cSrcweir using namespace ::svx;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // .........................................................................
60cdf0e10cSrcweir namespace dbaui
61cdf0e10cSrcweir {
62cdf0e10cSrcweir // .........................................................................
63cdf0e10cSrcweir // -----------------------------------------------------------------------------
64cdf0e10cSrcweir SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getChildType( SvLBoxEntry* _pEntry ) const
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	DBG_ASSERT(isContainer(_pEntry), "SbaTableQueryBrowser::getChildType: invalid entry!");
67cdf0e10cSrcweir 	switch (getEntryType(_pEntry))
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		case etTableContainer:
70cdf0e10cSrcweir 			return etTableOrView;
71cdf0e10cSrcweir 		case etQueryContainer:
72cdf0e10cSrcweir 			return etQuery;
73cdf0e10cSrcweir         default:
74cdf0e10cSrcweir             break;
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 	return etUnknown;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir // -----------------------------------------------------------------------------
80cdf0e10cSrcweir String SbaTableQueryBrowser::GetEntryText( SvLBoxEntry* _pEntry ) const
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	return m_pTreeView->getListBox().GetEntryText(_pEntry);
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // -----------------------------------------------------------------------------
86cdf0e10cSrcweir SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvLBoxEntry* _pEntry ) const
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	if (!_pEntry)
89cdf0e10cSrcweir 		return etUnknown;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	SvLBoxEntry* pRootEntry 	= m_pTreeView->getListBox().GetRootLevelParent(_pEntry);
92cdf0e10cSrcweir 	SvLBoxEntry* pEntryParent	= m_pTreeView->getListBox().GetParent(_pEntry);
93cdf0e10cSrcweir 	SvLBoxEntry* pTables		= m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_TABLES);
94cdf0e10cSrcweir 	SvLBoxEntry* pQueries		= m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_QUERIES);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir #ifdef DBG_UTIL
97cdf0e10cSrcweir 	String sTest;
98cdf0e10cSrcweir 	if (pTables) sTest = m_pTreeView->getListBox().GetEntryText(pTables);
99cdf0e10cSrcweir 	if (pQueries) sTest = m_pTreeView->getListBox().GetEntryText(pQueries);
100cdf0e10cSrcweir #endif
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	if (pRootEntry == _pEntry)
103cdf0e10cSrcweir 		return etDatasource;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	if (pTables == _pEntry)
106cdf0e10cSrcweir 		return etTableContainer;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	if (pQueries == _pEntry)
109cdf0e10cSrcweir 		return etQueryContainer;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	if (pTables == pEntryParent)
112cdf0e10cSrcweir 		return etTableOrView;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	if (pQueries == pEntryParent)
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
117cdf0e10cSrcweir         if ( pEntryData )
118cdf0e10cSrcweir             return pEntryData->eType;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		return etQuery;
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir     while( pEntryParent != pQueries )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         pEntryParent = m_pTreeView->getListBox().GetParent(pEntryParent);
125cdf0e10cSrcweir         if ( !pEntryParent )
126cdf0e10cSrcweir             return etUnknown;
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	return etQueryContainer;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir //------------------------------------------------------------------------------
132cdf0e10cSrcweir void SbaTableQueryBrowser::select(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
135cdf0e10cSrcweir 	if (pTextItem)
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		static_cast<OBoldListboxString*>(pTextItem)->emphasize(_bSelect);
138cdf0e10cSrcweir 		m_pTreeModel->InvalidateEntry(_pEntry);
139cdf0e10cSrcweir 	}
140cdf0e10cSrcweir 	else {
141cdf0e10cSrcweir 		DBG_ERROR("SbaTableQueryBrowser::select: invalid entry!");
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir //------------------------------------------------------------------------------
146cdf0e10cSrcweir void SbaTableQueryBrowser::selectPath(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	while (_pEntry)
149cdf0e10cSrcweir 	{
150cdf0e10cSrcweir 		select(_pEntry, _bSelect);
151cdf0e10cSrcweir 		_pEntry = m_pTreeModel->GetParent(_pEntry);
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir }
154cdf0e10cSrcweir //------------------------------------------------------------------------------
155cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::isSelected(SvLBoxEntry* _pEntry) const
156cdf0e10cSrcweir {
157cdf0e10cSrcweir 	SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
158cdf0e10cSrcweir 	if (pTextItem)
159cdf0e10cSrcweir 		return static_cast<OBoldListboxString*>(pTextItem)->isEmphasized();
160cdf0e10cSrcweir 	else {
161cdf0e10cSrcweir 		DBG_ERROR("SbaTableQueryBrowser::isSelected: invalid entry!");
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 	return sal_False;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir //------------------------------------------------------------------------------
166cdf0e10cSrcweir void SbaTableQueryBrowser::SelectionChanged()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     if ( !m_bShowMenu )
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir 	    InvalidateFeature(ID_BROWSER_INSERTCOLUMNS);
171cdf0e10cSrcweir 	    InvalidateFeature(ID_BROWSER_INSERTCONTENT);
172cdf0e10cSrcweir 	    InvalidateFeature(ID_BROWSER_FORMLETTER);
173cdf0e10cSrcweir     } // if ( !m_bShowMenu )
174cdf0e10cSrcweir     InvalidateFeature(ID_BROWSER_COPY);
175cdf0e10cSrcweir     InvalidateFeature(ID_BROWSER_CUT);
176cdf0e10cSrcweir }
177cdf0e10cSrcweir //------------------------------------------------------------------------------
178cdf0e10cSrcweir void SbaTableQueryBrowser::describeSupportedFeatures()
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	SbaXDataBrowserController::describeSupportedFeatures();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:Title",                             ID_BROWSER_TITLE );
183cdf0e10cSrcweir 	if ( !m_bShowMenu )
184cdf0e10cSrcweir 	{
185cdf0e10cSrcweir 	    implDescribeSupportedFeature( ".uno:DSBrowserExplorer",                 ID_BROWSER_EXPLORER, CommandGroup::VIEW );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         implDescribeSupportedFeature( ".uno:DSBFormLetter",                     ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT );
188cdf0e10cSrcweir 	    implDescribeSupportedFeature( ".uno:DSBInsertColumns",                  ID_BROWSER_INSERTCOLUMNS, CommandGroup::INSERT );
189cdf0e10cSrcweir         implDescribeSupportedFeature( ".uno:DSBInsertContent",                  ID_BROWSER_INSERTCONTENT, CommandGroup::INSERT );
190cdf0e10cSrcweir 	    implDescribeSupportedFeature( ".uno:DSBDocumentDataSource",             ID_BROWSER_DOCUMENT_DATASOURCE, CommandGroup::VIEW );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         implDescribeSupportedFeature( ".uno:DataSourceBrowser/FormLetter",          ID_BROWSER_FORMLETTER );
193cdf0e10cSrcweir 	    implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertColumns",       ID_BROWSER_INSERTCOLUMNS );
194cdf0e10cSrcweir         implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertContent",       ID_BROWSER_INSERTCONTENT );
195cdf0e10cSrcweir 	    implDescribeSupportedFeature( ".uno:DataSourceBrowser/DocumentDataSource",  ID_BROWSER_DOCUMENT_DATASOURCE );
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:CloseWin",      ID_BROWSER_CLOSE, CommandGroup::DOCUMENT );
199cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBRebuildData", ID_BROWSER_REFRESH_REBUILD, CommandGroup::DATA );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir // -----------------------------------------------------------------------------
203cdf0e10cSrcweir sal_Int32 SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     switch ( _eType )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir     case etQuery:
208cdf0e10cSrcweir     case etQueryContainer:
209cdf0e10cSrcweir         return DatabaseObject::QUERY;
210cdf0e10cSrcweir     case etTableOrView:
211cdf0e10cSrcweir     case etTableContainer:
212cdf0e10cSrcweir         return DatabaseObject::TABLE;
213cdf0e10cSrcweir     default:
214cdf0e10cSrcweir         break;
215cdf0e10cSrcweir     }
216cdf0e10cSrcweir     OSL_ENSURE( false, "SbaTableQueryBrowser::getDatabaseObjectType: folder types and 'Unknown' not allowed here!" );
217cdf0e10cSrcweir     return DatabaseObject::TABLE;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir // -----------------------------------------------------------------------------
221cdf0e10cSrcweir void SbaTableQueryBrowser::notifyHiContrastChanged()
222cdf0e10cSrcweir {
223cdf0e10cSrcweir 	if ( m_pTreeView )
224cdf0e10cSrcweir 	{
225cdf0e10cSrcweir 		// change all bitmap entries
226cdf0e10cSrcweir 		SvLBoxEntry* pEntryLoop = m_pTreeModel->First();
227cdf0e10cSrcweir 		while ( pEntryLoop )
228cdf0e10cSrcweir 		{
229cdf0e10cSrcweir 			DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
230cdf0e10cSrcweir 			if ( !pData )
231cdf0e10cSrcweir             {
232cdf0e10cSrcweir 				pEntryLoop = m_pTreeModel->Next(pEntryLoop);
233cdf0e10cSrcweir                 continue;
234cdf0e10cSrcweir             }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir             // the connection to which this entry belongs, if any
237cdf0e10cSrcweir             ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( pEntryLoop ) );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir             // the images for this entry
240cdf0e10cSrcweir             Image aImage, aImageHC;
241cdf0e10cSrcweir             if ( pData->eType == etDatasource )
242cdf0e10cSrcweir             {
243cdf0e10cSrcweir                 aImage = pImageProvider->getDatabaseImage( false );
244cdf0e10cSrcweir                 aImageHC = pImageProvider->getDatabaseImage( true );
245cdf0e10cSrcweir             }
246cdf0e10cSrcweir             else
247cdf0e10cSrcweir             {
248cdf0e10cSrcweir                 bool bIsFolder = !isObject( pData->eType );
249cdf0e10cSrcweir                 if ( bIsFolder )
250cdf0e10cSrcweir                 {
251cdf0e10cSrcweir                     sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
252cdf0e10cSrcweir                     aImage = pImageProvider->getFolderImage( nObjectType, false );
253cdf0e10cSrcweir                     aImageHC = pImageProvider->getFolderImage( nObjectType, true );
254cdf0e10cSrcweir                 }
255cdf0e10cSrcweir                 else
256cdf0e10cSrcweir                 {
257cdf0e10cSrcweir                     sal_Int32 nObjectType( getDatabaseObjectType( pData->eType ) );
258cdf0e10cSrcweir                     pImageProvider->getImages( GetEntryText( pEntryLoop ), nObjectType, aImage, aImageHC );
259cdf0e10cSrcweir                 }
260cdf0e10cSrcweir             }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir             // find the proper item, and set its icons
263cdf0e10cSrcweir 			sal_uInt16 nCount = pEntryLoop->ItemCount();
264cdf0e10cSrcweir 			for (sal_uInt16 i=0;i<nCount;++i)
265cdf0e10cSrcweir 			{
266cdf0e10cSrcweir 				SvLBoxItem* pItem = pEntryLoop->GetItem(i);
267cdf0e10cSrcweir 				if ( !pItem || ( pItem->IsA() != SV_ITEM_ID_LBOXCONTEXTBMP ) )
268cdf0e10cSrcweir                     continue;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir                 SvLBoxContextBmp* pContextBitmapItem = static_cast< SvLBoxContextBmp* >( pItem );
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 				pContextBitmapItem->SetBitmap1( aImage, BMP_COLOR_NORMAL );
273cdf0e10cSrcweir 				pContextBitmapItem->SetBitmap2( aImage, BMP_COLOR_NORMAL );
274cdf0e10cSrcweir 				pContextBitmapItem->SetBitmap1( aImageHC, BMP_COLOR_HIGHCONTRAST );
275cdf0e10cSrcweir 				pContextBitmapItem->SetBitmap2( aImageHC, BMP_COLOR_HIGHCONTRAST );
276cdf0e10cSrcweir 				break;
277cdf0e10cSrcweir 			}
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 			pEntryLoop = m_pTreeModel->Next(pEntryLoop);
280cdf0e10cSrcweir 		}
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir }
283cdf0e10cSrcweir // -----------------------------------------------------------------------------
284cdf0e10cSrcweir // .........................................................................
285cdf0e10cSrcweir }	// namespace dbaui
286cdf0e10cSrcweir // .........................................................................
287cdf0e10cSrcweir 
288