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