1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
24 #include "unodatbr.hxx"
25 #include "browserids.hxx"
26 #include "listviewitems.hxx"
27 #include "imageprovider.hxx"
28 #include <osl/diagnose.h>
29 #include "dbtreeview.hxx"
30 #include "dbtreelistbox.hxx"
31 #include "dbu_brw.hrc"
32 #include "dbtreemodel.hxx"
33 #include "svtools/treelistentry.hxx"
35 using namespace ::com::sun::star::frame
;
36 using namespace ::dbtools
;
37 using namespace ::svx
;
41 SbaTableQueryBrowser::EntryType
SbaTableQueryBrowser::getChildType( SvTreeListEntry
* _pEntry
) const
43 OSL_ENSURE(isContainer(_pEntry
), "SbaTableQueryBrowser::getChildType: invalid entry!");
44 switch (getEntryType(_pEntry
))
46 case etTableContainer
:
48 case etQueryContainer
:
56 OUString
SbaTableQueryBrowser::GetEntryText( SvTreeListEntry
* _pEntry
) const
58 return m_pTreeView
->getListBox().GetEntryText(_pEntry
);
61 SbaTableQueryBrowser::EntryType
SbaTableQueryBrowser::getEntryType( const SvTreeListEntry
* _pEntry
) const
66 SvTreeListEntry
* pRootEntry
= m_pTreeView
->getListBox().GetRootLevelParent(const_cast<SvTreeListEntry
*>(_pEntry
));
67 SvTreeListEntry
* pEntryParent
= m_pTreeView
->getListBox().GetParent(const_cast<SvTreeListEntry
*>(_pEntry
));
68 SvTreeListEntry
* pTables
= m_pTreeView
->getListBox().GetEntry(pRootEntry
, CONTAINER_TABLES
);
69 SvTreeListEntry
* pQueries
= m_pTreeView
->getListBox().GetEntry(pRootEntry
, CONTAINER_QUERIES
);
73 if (pTables
) sTest
= m_pTreeView
->getListBox().GetEntryText(pTables
);
74 if (pQueries
) sTest
= m_pTreeView
->getListBox().GetEntryText(pQueries
);
77 if (pRootEntry
== _pEntry
)
80 if (pTables
== _pEntry
)
81 return etTableContainer
;
83 if (pQueries
== _pEntry
)
84 return etQueryContainer
;
86 if (pTables
== pEntryParent
)
89 if (pQueries
== pEntryParent
)
91 DBTreeListUserData
* pEntryData
= static_cast<DBTreeListUserData
*>(_pEntry
->GetUserData());
93 return pEntryData
->eType
;
97 while( pEntryParent
!= pQueries
)
99 pEntryParent
= m_pTreeView
->getListBox().GetParent(pEntryParent
);
104 return etQueryContainer
;
107 void SbaTableQueryBrowser::select(SvTreeListEntry
* _pEntry
, bool _bSelect
)
109 SvLBoxItem
* pTextItem
= _pEntry
? _pEntry
->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING
) : NULL
;
112 static_cast<OBoldListboxString
*>(pTextItem
)->emphasize(_bSelect
);
113 m_pTreeModel
->InvalidateEntry(_pEntry
);
116 OSL_FAIL("SbaTableQueryBrowser::select: invalid entry!");
120 void SbaTableQueryBrowser::selectPath(SvTreeListEntry
* _pEntry
, bool _bSelect
)
124 select(_pEntry
, _bSelect
);
125 _pEntry
= m_pTreeModel
->GetParent(_pEntry
);
129 bool SbaTableQueryBrowser::isSelected(SvTreeListEntry
* _pEntry
)
131 SvLBoxItem
* pTextItem
= _pEntry
? _pEntry
->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING
) : NULL
;
133 return static_cast<OBoldListboxString
*>(pTextItem
)->isEmphasized();
135 OSL_FAIL("SbaTableQueryBrowser::isSelected: invalid entry!");
140 void SbaTableQueryBrowser::SelectionChanged()
144 InvalidateFeature(ID_BROWSER_INSERTCOLUMNS
);
145 InvalidateFeature(ID_BROWSER_INSERTCONTENT
);
146 InvalidateFeature(ID_BROWSER_FORMLETTER
);
148 InvalidateFeature(ID_BROWSER_COPY
);
149 InvalidateFeature(ID_BROWSER_CUT
);
152 void SbaTableQueryBrowser::describeSupportedFeatures()
154 SbaXDataBrowserController::describeSupportedFeatures();
156 implDescribeSupportedFeature( ".uno:Title", ID_BROWSER_TITLE
);
159 implDescribeSupportedFeature( ".uno:DSBrowserExplorer", ID_BROWSER_EXPLORER
, CommandGroup::VIEW
);
161 implDescribeSupportedFeature( ".uno:DSBFormLetter", ID_BROWSER_FORMLETTER
, CommandGroup::DOCUMENT
);
162 implDescribeSupportedFeature( ".uno:DSBInsertColumns", ID_BROWSER_INSERTCOLUMNS
, CommandGroup::INSERT
);
163 implDescribeSupportedFeature( ".uno:DSBInsertContent", ID_BROWSER_INSERTCONTENT
, CommandGroup::INSERT
);
164 implDescribeSupportedFeature( ".uno:DSBDocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE
, CommandGroup::VIEW
);
166 implDescribeSupportedFeature( ".uno:DataSourceBrowser/FormLetter", ID_BROWSER_FORMLETTER
);
167 implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertColumns", ID_BROWSER_INSERTCOLUMNS
);
168 implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertContent", ID_BROWSER_INSERTCONTENT
);
169 implDescribeSupportedFeature( ".uno:DataSourceBrowser/DocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE
);
172 implDescribeSupportedFeature( ".uno:CloseWin", ID_BROWSER_CLOSE
, CommandGroup::DOCUMENT
);
173 implDescribeSupportedFeature( ".uno:DBRebuildData", ID_BROWSER_REFRESH_REBUILD
, CommandGroup::DATA
);
176 sal_Int32
SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType
)
181 case etQueryContainer
:
182 return css::sdb::application::DatabaseObject::QUERY
;
184 case etTableContainer
:
185 return css::sdb::application::DatabaseObject::TABLE
;
189 OSL_FAIL( "SbaTableQueryBrowser::getDatabaseObjectType: folder types and 'Unknown' not allowed here!" );
190 return css::sdb::application::DatabaseObject::TABLE
;
193 void SbaTableQueryBrowser::notifyHiContrastChanged()
197 // change all bitmap entries
198 SvTreeListEntry
* pEntryLoop
= m_pTreeModel
->First();
201 DBTreeListUserData
* pData
= static_cast<DBTreeListUserData
*>(pEntryLoop
->GetUserData());
204 pEntryLoop
= m_pTreeModel
->Next(pEntryLoop
);
208 // the connection to which this entry belongs, if any
209 std::unique_ptr
< ImageProvider
> pImageProvider( getImageProviderFor( pEntryLoop
) );
211 // the images for this entry
213 if ( pData
->eType
== etDatasource
)
214 aImage
= ImageProvider::getDatabaseImage();
217 bool bIsFolder
= !isObject( pData
->eType
);
220 sal_Int32
nObjectType( getDatabaseObjectType( pData
->eType
) );
221 aImage
= ImageProvider::getFolderImage( nObjectType
);
225 sal_Int32
nObjectType( getDatabaseObjectType( pData
->eType
) );
226 pImageProvider
->getImages( GetEntryText( pEntryLoop
), nObjectType
, aImage
);
230 // find the proper item, and set its icons
231 sal_uInt16 nCount
= pEntryLoop
->ItemCount();
232 for (sal_uInt16 i
=0;i
<nCount
;++i
)
234 SvLBoxItem
* pItem
= pEntryLoop
->GetItem(i
);
235 if (!pItem
|| pItem
->GetType() != SV_ITEM_ID_LBOXCONTEXTBMP
)
238 SvLBoxContextBmp
* pContextBitmapItem
= static_cast< SvLBoxContextBmp
* >( pItem
);
240 pContextBitmapItem
->SetBitmap1( aImage
);
241 pContextBitmapItem
->SetBitmap2( aImage
);
245 pEntryLoop
= m_pTreeModel
->Next(pEntryLoop
);
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */