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 "AppDetailView.hxx"
21 #include <osl/diagnose.h>
23 #include <strings.hrc>
24 #include "AppView.hxx"
25 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
26 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
27 #include <com/sun/star/ui/XImageManager.hpp>
28 #include <com/sun/star/ui/ImageType.hpp>
29 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
30 #include <com/sun/star/graphic/XGraphic.hpp>
31 #include <com/sun/star/util/URL.hpp>
32 #include <core_resource.hxx>
33 #include <vcl/svapp.hxx>
34 #include "AppDetailPageHelper.hxx"
35 #include <dbaccess/IController.hxx>
37 #include <dbtreelistbox.hxx>
38 #include "AppController.hxx"
40 using namespace ::dbaui
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::sdbc
;
43 using namespace ::com::sun::star::sdbcx
;
44 using namespace ::com::sun::star::lang
;
45 using namespace ::com::sun::star::ucb
;
46 using namespace ::com::sun::star::graphic
;
47 using namespace ::com::sun::star::ui
;
48 using namespace ::com::sun::star::container
;
49 using namespace ::com::sun::star::beans
;
50 using ::com::sun::star::util::URL
;
51 using ::com::sun::star::sdb::application::NamedDatabaseObject
;
53 TaskEntry::TaskEntry( const char* _pAsciiUNOCommand
, TranslateId _pHelpID
, TranslateId pTitleResourceID
, bool _bHideWhenDisabled
)
54 :sUNOCommand( OUString::createFromAscii( _pAsciiUNOCommand
) )
56 ,sTitle( DBA_RES(pTitleResourceID
) )
57 ,bHideWhenDisabled( _bHideWhenDisabled
)
61 void OTasksWindow::updateHelpText()
63 TranslateId pHelpTextId
;
64 int nCurEntry
= m_xTreeView
->get_selected_index();
66 pHelpTextId
= weld::fromId
<TaskEntry
*>(m_xTreeView
->get_id(nCurEntry
))->pHelpID
;
67 setHelpText(pHelpTextId
);
70 IMPL_LINK(OTasksWindow
, onSelected
, weld::TreeView
&, rTreeView
, bool)
72 m_nCursorIndex
= rTreeView
.get_cursor_index();
73 if (m_nCursorIndex
!= -1)
76 aCommand
.Complete
= weld::fromId
<TaskEntry
*>(rTreeView
.get_id(m_nCursorIndex
))->sUNOCommand
;
77 getDetailView()->getBorderWin().getView()->getAppController().executeChecked( aCommand
, Sequence
< PropertyValue
>() );
82 void OTasksWindow::GrabFocus()
86 m_xTreeView
->grab_focus();
89 bool OTasksWindow::HasChildPathFocus() const
91 return m_xTreeView
&& m_xTreeView
->has_focus();
94 IMPL_LINK_NOARG(OTasksWindow
, FocusInHdl
, weld::Widget
&, void)
96 m_xTreeView
->select(m_nCursorIndex
!= -1 ? m_nCursorIndex
: 0);
99 IMPL_LINK_NOARG(OTasksWindow
, FocusOutHdl
, weld::Widget
&, void)
101 m_nCursorIndex
= m_xTreeView
->get_cursor_index();
102 m_xTreeView
->unselect_all();
105 IMPL_LINK_NOARG(OTasksWindow
, OnEntrySelectHdl
, weld::TreeView
&, void)
107 m_nCursorIndex
= m_xTreeView
->get_cursor_index();
111 OTasksWindow::OTasksWindow(weld::Container
* pParent
, OApplicationDetailView
* pDetailView
)
112 : OChildWindow(pParent
, "dbaccess/ui/taskwindow.ui", "TaskWindow")
113 , m_xTreeView(m_xBuilder
->weld_tree_view("treeview"))
114 , m_xDescription(m_xBuilder
->weld_label("description"))
115 , m_xHelpText(m_xBuilder
->weld_text_view("helptext"))
116 , m_pDetailView(pDetailView
)
119 m_xContainer
->set_stack_background();
121 m_xTreeView
->set_help_id(HID_APP_CREATION_LIST
);
122 m_xTreeView
->connect_row_activated(LINK(this, OTasksWindow
, onSelected
));
123 m_xTreeView
->connect_changed(LINK(this, OTasksWindow
, OnEntrySelectHdl
));
124 m_xTreeView
->connect_focus_in(LINK(this, OTasksWindow
, FocusInHdl
));
125 m_xTreeView
->connect_focus_out(LINK(this, OTasksWindow
, FocusOutHdl
));
126 // an arbitrary small size it's allowed to shrink to
127 m_xTreeView
->set_size_request(42, 42);
129 m_xHelpText
->set_help_id(HID_APP_HELP_TEXT
);
130 m_xDescription
->set_help_id(HID_APP_DESCRIPTION_TEXT
);
133 OTasksWindow::~OTasksWindow()
138 void OTasksWindow::setHelpText(TranslateId pId
)
141 m_xHelpText
->set_text(DBA_RES(pId
));
143 m_xHelpText
->set_text(OUString());
146 void OTasksWindow::fillTaskEntryList( const TaskEntryList
& _rList
)
152 Reference
< XModuleUIConfigurationManagerSupplier
> xModuleCfgMgrSupplier
=
153 theModuleUIConfigurationManagerSupplier::get( getDetailView()->getBorderWin().getView()->getORB() );
154 Reference
< XUIConfigurationManager
> xUIConfigMgr
= xModuleCfgMgrSupplier
->getUIConfigurationManager(
155 "com.sun.star.sdb.OfficeDatabaseDocument"
157 Reference
< XImageManager
> xImageMgr( xUIConfigMgr
->getImageManager(), UNO_QUERY
);
159 // copy the commands so we can use them with the config managers
160 Sequence
< OUString
> aCommands( _rList
.size() );
161 OUString
* pCommands
= aCommands
.getArray();
162 for (auto const& copyTask
: _rList
)
164 *pCommands
= copyTask
.sUNOCommand
;
168 Sequence
< Reference
< XGraphic
> > aImages
= xImageMgr
->getImages(
169 ImageType::SIZE_DEFAULT
| ImageType::COLOR_NORMAL
,
173 const Reference
< XGraphic
>* pImages( aImages
.getConstArray() );
176 for (auto const& task
: _rList
)
178 OUString sId
= weld::toId(new TaskEntry(task
));
179 m_xTreeView
->append(sId
, task
.sTitle
);
180 m_xTreeView
->set_image(nIndex
++, *pImages
++);
187 m_xTreeView
->unselect_all();
189 Enable(!_rList
.empty());
192 void OTasksWindow::Clear()
194 m_xTreeView
->all_foreach([this](weld::TreeIter
& rEntry
){
195 TaskEntry
* pUserData
= weld::fromId
<TaskEntry
*>(m_xTreeView
->get_id(rEntry
));
200 m_xTreeView
->clear();
203 OApplicationDetailView::OApplicationDetailView(weld::Container
* pParent
, OAppBorderWindow
& rBorder
,
204 PreviewMode ePreviewMode
)
205 : m_xBuilder(Application::CreateBuilder(pParent
, "dbaccess/ui/appdetailwindow.ui"))
206 , m_xContainer(m_xBuilder
->weld_container("AppDetailWindow"))
207 , m_xHorzSplitter(m_xBuilder
->weld_paned("splitter"))
208 , m_xTasksParent(m_xBuilder
->weld_container("tasks"))
209 , m_xContainerParent(m_xBuilder
->weld_container("container"))
210 , m_xTasks(new dbaui::OTitleWindow(m_xTasksParent
.get(), STR_TASKS
))
211 , m_xTitleContainer(new dbaui::OTitleWindow(m_xContainerParent
.get(), TranslateId()))
212 , m_rBorderWin(rBorder
)
214 m_xControlHelper
= std::make_shared
<OAppDetailPageHelper
>(m_xTitleContainer
->getChildContainer(), m_rBorderWin
, ePreviewMode
);
215 m_xTitleContainer
->setChildWindow(m_xControlHelper
);
217 std::shared_ptr
<OChildWindow
> xTasks
= std::make_shared
<OTasksWindow
>(m_xTasks
->getChildContainer(), this);
218 xTasks
->Enable(!m_rBorderWin
.getView()->getCommandController().isDataSourceReadOnly());
219 m_xTasks
->setChildWindow(xTasks
);
222 OApplicationDetailView::~OApplicationDetailView()
226 void OApplicationDetailView::setTaskExternalMnemonics( MnemonicGenerator
const & rMnemonics
)
228 m_aExternalMnemonics
= rMnemonics
;
231 void OApplicationDetailView::createTablesPage(const Reference
< XConnection
>& _xConnection
)
233 impl_createPage( E_TABLE
, _xConnection
, nullptr );
236 void OApplicationDetailView::createPage( ElementType _eType
,const Reference
< XNameAccess
>& _xContainer
)
238 impl_createPage( _eType
, nullptr, _xContainer
);
241 void OApplicationDetailView::impl_createPage( ElementType _eType
, const Reference
< XConnection
>& _rxConnection
,
242 const Reference
< XNameAccess
>& _rxNonTableElements
)
244 // get the data for the pane
245 const TaskPaneData
& rData
= impl_getTaskPaneData( _eType
);
246 getTasksWindow().fillTaskEntryList( rData
.aTasks
);
248 // enable the pane as a whole, depending on the availability of the first command
249 OSL_ENSURE( !rData
.aTasks
.empty(), "OApplicationDetailView::impl_createPage: no tasks at all!?" );
250 bool bEnabled
= !rData
.aTasks
.empty()
251 && getBorderWin().getView()->getCommandController().isCommandEnabled( rData
.aTasks
[0].sUNOCommand
);
252 getTasksWindow().Enable( bEnabled
);
253 m_xTitleContainer
->setTitle(rData
.pTitleId
);
255 // let our helper create the object list
256 if ( _eType
== E_TABLE
)
257 GetControlHelper()->createTablesPage( _rxConnection
);
259 GetControlHelper()->createPage( _eType
, _rxNonTableElements
);
262 void OApplicationDetailView::impl_fillTaskPaneData(ElementType _eType
, TaskPaneData
& _rData
) const
264 TaskEntryList
& rList( _rData
.aTasks
);
265 rList
.clear(); rList
.reserve( 4 );
270 rList
.emplace_back( ".uno:DBNewTable", RID_STR_TABLES_HELP_TEXT_DESIGN
, RID_STR_NEW_TABLE
);
271 rList
.emplace_back( ".uno:DBNewTableAutoPilot", RID_STR_TABLES_HELP_TEXT_WIZARD
, RID_STR_NEW_TABLE_AUTO
);
272 rList
.emplace_back( ".uno:DBNewView", RID_STR_VIEWS_HELP_TEXT_DESIGN
, RID_STR_NEW_VIEW
, true );
273 _rData
.pTitleId
= RID_STR_TABLES_CONTAINER
;
277 rList
.emplace_back( ".uno:DBNewForm", RID_STR_FORMS_HELP_TEXT
, RID_STR_NEW_FORM
);
278 rList
.emplace_back( ".uno:DBNewFormAutoPilot", RID_STR_FORMS_HELP_TEXT_WIZARD
, RID_STR_NEW_FORM_AUTO
);
279 _rData
.pTitleId
= RID_STR_FORMS_CONTAINER
;
283 rList
.emplace_back( ".uno:DBNewReport", RID_STR_REPORT_HELP_TEXT
, RID_STR_NEW_REPORT
, true );
284 rList
.emplace_back( ".uno:DBNewReportAutoPilot", RID_STR_REPORTS_HELP_TEXT_WIZARD
, RID_STR_NEW_REPORT_AUTO
);
285 _rData
.pTitleId
= RID_STR_REPORTS_CONTAINER
;
289 rList
.emplace_back( ".uno:DBNewQuery", RID_STR_QUERIES_HELP_TEXT
, RID_STR_NEW_QUERY
);
290 rList
.emplace_back( ".uno:DBNewQueryAutoPilot", RID_STR_QUERIES_HELP_TEXT_WIZARD
, RID_STR_NEW_QUERY_AUTO
);
291 rList
.emplace_back( ".uno:DBNewQuerySql", RID_STR_QUERIES_HELP_TEXT_SQL
, RID_STR_NEW_QUERY_SQL
);
292 _rData
.pTitleId
= RID_STR_QUERIES_CONTAINER
;
296 OSL_FAIL( "OApplicationDetailView::impl_fillTaskPaneData: illegal element type!" );
299 // remove the entries which are not enabled currently
300 for (TaskEntryList::iterator pTask
= rList
.begin(); pTask
!= rList
.end();)
302 if ( pTask
->bHideWhenDisabled
303 && !getBorderWin().getView()->getCommandController().isCommandEnabled( pTask
->sUNOCommand
)
305 pTask
= rList
.erase( pTask
);
313 const TaskPaneData
& OApplicationDetailView::impl_getTaskPaneData( ElementType _eType
)
315 if ( m_aTaskPaneData
.empty() )
316 m_aTaskPaneData
.resize( size_t(E_ELEMENT_TYPE_COUNT
) );
317 OSL_ENSURE( ( _eType
>= 0 ) && ( _eType
< E_ELEMENT_TYPE_COUNT
), "OApplicationDetailView::impl_getTaskPaneData: illegal element type!" );
318 TaskPaneData
& rData
= m_aTaskPaneData
[ _eType
];
320 //oj: do not check, otherwise extensions will only be visible after a reload.
321 impl_fillTaskPaneData( _eType
, rData
);
326 OUString
OApplicationDetailView::getQualifiedName(const weld::TreeIter
* _pEntry
) const
328 return GetControlHelper()->getQualifiedName( _pEntry
);
331 bool OApplicationDetailView::isLeaf(const weld::TreeView
& rTreeView
, const weld::TreeIter
& rEntry
)
333 return OAppDetailPageHelper::isLeaf(rTreeView
, rEntry
);
336 bool OApplicationDetailView::isALeafSelected() const
338 return GetControlHelper()->isALeafSelected();
341 void OApplicationDetailView::selectAll()
343 GetControlHelper()->selectAll();
346 void OApplicationDetailView::sortDown()
348 GetControlHelper()->sortDown();
351 void OApplicationDetailView::sortUp()
353 GetControlHelper()->sortUp();
356 bool OApplicationDetailView::isFilled() const
358 return GetControlHelper()->isFilled();
361 ElementType
OApplicationDetailView::getElementType() const
363 return GetControlHelper()->getElementType();
366 void OApplicationDetailView::clearPages(bool _bTaskAlso
)
369 getTasksWindow().Clear();
370 GetControlHelper()->clearPages();
373 sal_Int32
OApplicationDetailView::getSelectionCount()
375 return GetControlHelper()->getSelectionCount();
378 sal_Int32
OApplicationDetailView::getElementCount() const
380 return GetControlHelper()->getElementCount();
383 void OApplicationDetailView::getSelectionElementNames( std::vector
< OUString
>& _rNames
) const
385 GetControlHelper()->getSelectionElementNames( _rNames
);
388 void OApplicationDetailView::describeCurrentSelectionForControl(const weld::TreeView
& rControl
, Sequence
< NamedDatabaseObject
>& out_rSelectedObjects
)
390 GetControlHelper()->describeCurrentSelectionForControl(rControl
, out_rSelectedObjects
);
393 void OApplicationDetailView::describeCurrentSelectionForType( const ElementType _eType
, Sequence
< NamedDatabaseObject
>& _out_rSelectedObjects
)
395 GetControlHelper()->describeCurrentSelectionForType( _eType
, _out_rSelectedObjects
);
398 vcl::Window
* OApplicationDetailView::getMenuParent() const
400 return GetControlHelper()->getMenuParent();
403 void OApplicationDetailView::adjustMenuPosition(const weld::TreeView
& rControl
, ::Point
& rPos
) const
405 return GetControlHelper()->adjustMenuPosition(rControl
, rPos
);
408 void OApplicationDetailView::selectElements(const Sequence
< OUString
>& _aNames
)
410 GetControlHelper()->selectElements( _aNames
);
413 std::unique_ptr
<weld::TreeIter
> OApplicationDetailView::getEntry(const Point
& rPoint
) const
415 return GetControlHelper()->getEntry(rPoint
);
418 bool OApplicationDetailView::isCutAllowed()
423 bool OApplicationDetailView::isCopyAllowed()
428 bool OApplicationDetailView::isPasteAllowed() { return true; }
430 void OApplicationDetailView::copy() { }
432 void OApplicationDetailView::cut() { }
434 void OApplicationDetailView::paste() { }
436 std::unique_ptr
<weld::TreeIter
> OApplicationDetailView::elementAdded(ElementType _eType
,const OUString
& _rName
, const Any
& _rObject
)
438 return GetControlHelper()->elementAdded(_eType
, _rName
, _rObject
);
441 void OApplicationDetailView::elementRemoved(ElementType _eType
,const OUString
& _rName
)
443 GetControlHelper()->elementRemoved(_eType
,_rName
);
446 void OApplicationDetailView::elementReplaced(ElementType _eType
447 ,const OUString
& _rOldName
448 ,const OUString
& _rNewName
)
450 GetControlHelper()->elementReplaced( _eType
, _rOldName
, _rNewName
);
453 PreviewMode
OApplicationDetailView::getPreviewMode() const
455 return GetControlHelper()->getPreviewMode();
458 bool OApplicationDetailView::isPreviewEnabled() const
460 return GetControlHelper()->isPreviewEnabled();
463 void OApplicationDetailView::switchPreview(PreviewMode _eMode
)
465 GetControlHelper()->switchPreview(_eMode
);
468 void OApplicationDetailView::showPreview(const Reference
< XContent
>& _xContent
)
470 GetControlHelper()->showPreview(_xContent
);
473 void OApplicationDetailView::showPreview( const OUString
& _sDataSourceName
,
474 const OUString
& _sName
,
477 GetControlHelper()->showPreview(_sDataSourceName
,_sName
,_bTable
);
480 bool OApplicationDetailView::isSortUp() const
482 return GetControlHelper()->isSortUp();
485 TreeListBox
* OApplicationDetailView::getTreeWindow() const
487 DBTreeViewBase
* pCurrent
= GetControlHelper()->getCurrentView();
490 return &pCurrent
->getListBox();
493 OAppDetailPageHelper
* OApplicationDetailView::GetControlHelper()
495 return static_cast<OAppDetailPageHelper
*>(m_xControlHelper
.get());
498 const OAppDetailPageHelper
* OApplicationDetailView::GetControlHelper() const
500 return static_cast<const OAppDetailPageHelper
*>(m_xControlHelper
.get());
503 bool OApplicationDetailView::HasChildPathFocus() const
505 return m_xHorzSplitter
->has_focus() ||
506 m_xTasks
->HasChildPathFocus() ||
507 m_xTitleContainer
->HasChildPathFocus();
510 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */