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 // .........................................................................
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
:
56 case etQueryContainer
:
64 // -----------------------------------------------------------------------------
65 String
SbaTableQueryBrowser::GetEntryText( SvLBoxEntry
* _pEntry
) const
67 return m_pTreeView
->getListBox().GetEntryText(_pEntry
);
70 // -----------------------------------------------------------------------------
71 SbaTableQueryBrowser::EntryType
SbaTableQueryBrowser::getEntryType( SvLBoxEntry
* _pEntry
) const
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
);
83 if (pTables
) sTest
= m_pTreeView
->getListBox().GetEntryText(pTables
);
84 if (pQueries
) sTest
= m_pTreeView
->getListBox().GetEntryText(pQueries
);
87 if (pRootEntry
== _pEntry
)
90 if (pTables
== _pEntry
)
91 return etTableContainer
;
93 if (pQueries
== _pEntry
)
94 return etQueryContainer
;
96 if (pTables
== pEntryParent
)
99 if (pQueries
== pEntryParent
)
101 DBTreeListUserData
* pEntryData
= static_cast<DBTreeListUserData
*>(_pEntry
->GetUserData());
103 return pEntryData
->eType
;
107 while( pEntryParent
!= pQueries
)
109 pEntryParent
= m_pTreeView
->getListBox().GetParent(pEntryParent
);
114 return etQueryContainer
;
116 //------------------------------------------------------------------------------
117 void SbaTableQueryBrowser::select(SvLBoxEntry
* _pEntry
, sal_Bool _bSelect
)
119 SvLBoxItem
* pTextItem
= _pEntry
? _pEntry
->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING
) : NULL
;
122 static_cast<OBoldListboxString
*>(pTextItem
)->emphasize(_bSelect
);
123 m_pTreeModel
->InvalidateEntry(_pEntry
);
126 OSL_FAIL("SbaTableQueryBrowser::select: invalid entry!");
130 //------------------------------------------------------------------------------
131 void SbaTableQueryBrowser::selectPath(SvLBoxEntry
* _pEntry
, sal_Bool _bSelect
)
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
;
144 return static_cast<OBoldListboxString
*>(pTextItem
)->isEmphasized();
146 OSL_FAIL("SbaTableQueryBrowser::isSelected: invalid entry!");
150 //------------------------------------------------------------------------------
151 void SbaTableQueryBrowser::SelectionChanged()
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
);
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
)
193 case etQueryContainer
:
194 return DatabaseObject::QUERY
;
196 case etTableContainer
:
197 return DatabaseObject::TABLE
;
201 OSL_FAIL( "SbaTableQueryBrowser::getDatabaseObjectType: folder types and 'Unknown' not allowed here!" );
202 return DatabaseObject::TABLE
;
205 // -----------------------------------------------------------------------------
206 void SbaTableQueryBrowser::notifyHiContrastChanged()
210 // change all bitmap entries
211 SvLBoxEntry
* pEntryLoop
= m_pTreeModel
->First();
214 DBTreeListUserData
* pData
= static_cast<DBTreeListUserData
*>(pEntryLoop
->GetUserData());
217 pEntryLoop
= m_pTreeModel
->Next(pEntryLoop
);
221 // the connection to which this entry belongs, if any
222 ::std::auto_ptr
< ImageProvider
> pImageProvider( getImageProviderFor( pEntryLoop
) );
224 // the images for this entry
226 if ( pData
->eType
== etDatasource
)
227 aImage
= pImageProvider
->getDatabaseImage();
230 bool bIsFolder
= !isObject( pData
->eType
);
233 sal_Int32
nObjectType( getDatabaseObjectType( pData
->eType
) );
234 aImage
= pImageProvider
->getFolderImage( nObjectType
);
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
) )
251 SvLBoxContextBmp
* pContextBitmapItem
= static_cast< SvLBoxContextBmp
* >( pItem
);
253 pContextBitmapItem
->SetBitmap1( aImage
);
254 pContextBitmapItem
->SetBitmap2( aImage
);
258 pEntryLoop
= m_pTreeModel
->Next(pEntryLoop
);
262 // -----------------------------------------------------------------------------
263 // .........................................................................
265 // .........................................................................
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */