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