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::ucb
;
44 using namespace ::com::sun::star::graphic
;
45 using namespace ::com::sun::star::ui
;
46 using namespace ::com::sun::star::container
;
47 using namespace ::com::sun::star::beans
;
48 using ::com::sun::star::util::URL
;
49 using ::com::sun::star::sdb::application::NamedDatabaseObject
;
51 TaskEntry::TaskEntry( const OUString
& _rAsciiUNOCommand
, TranslateId _pHelpID
, TranslateId pTitleResourceID
, bool _bHideWhenDisabled
)
52 :sUNOCommand( _rAsciiUNOCommand
)
54 ,sTitle( DBA_RES(pTitleResourceID
) )
55 ,bHideWhenDisabled( _bHideWhenDisabled
)
59 void OTasksWindow::updateHelpText()
61 TranslateId pHelpTextId
;
62 int nCurEntry
= m_xTreeView
->get_selected_index();
64 pHelpTextId
= weld::fromId
<TaskEntry
*>(m_xTreeView
->get_id(nCurEntry
))->pHelpID
;
65 setHelpText(pHelpTextId
);
68 IMPL_LINK(OTasksWindow
, onSelected
, weld::TreeView
&, rTreeView
, bool)
70 m_nCursorIndex
= rTreeView
.get_cursor_index();
71 if (m_nCursorIndex
!= -1)
74 aCommand
.Complete
= weld::fromId
<TaskEntry
*>(rTreeView
.get_id(m_nCursorIndex
))->sUNOCommand
;
75 getDetailView()->getBorderWin().getView()->getAppController().executeChecked( aCommand
, Sequence
< PropertyValue
>() );
80 void OTasksWindow::GrabFocus()
84 m_xTreeView
->grab_focus();
87 bool OTasksWindow::HasChildPathFocus() const
89 return m_xTreeView
&& m_xTreeView
->has_focus();
92 IMPL_LINK_NOARG(OTasksWindow
, FocusInHdl
, weld::Widget
&, void)
94 m_xTreeView
->select(m_nCursorIndex
!= -1 ? m_nCursorIndex
: 0);
97 IMPL_LINK_NOARG(OTasksWindow
, FocusOutHdl
, weld::Widget
&, void)
99 m_nCursorIndex
= m_xTreeView
->get_cursor_index();
100 m_xTreeView
->unselect_all();
103 IMPL_LINK_NOARG(OTasksWindow
, OnEntrySelectHdl
, weld::TreeView
&, void)
105 m_nCursorIndex
= m_xTreeView
->get_cursor_index();
109 OTasksWindow::OTasksWindow(weld::Container
* pParent
, OApplicationDetailView
* pDetailView
)
110 : OChildWindow(pParent
, u
"dbaccess/ui/taskwindow.ui"_ustr
, u
"TaskWindow"_ustr
)
111 , m_xTreeView(m_xBuilder
->weld_tree_view(u
"treeview"_ustr
))
112 , m_xDescription(m_xBuilder
->weld_label(u
"description"_ustr
))
113 , m_xHelpText(m_xBuilder
->weld_text_view(u
"helptext"_ustr
))
114 , m_pDetailView(pDetailView
)
117 m_xContainer
->set_stack_background();
119 m_xTreeView
->set_help_id(HID_APP_CREATION_LIST
);
120 m_xTreeView
->connect_row_activated(LINK(this, OTasksWindow
, onSelected
));
121 m_xTreeView
->connect_selection_changed(LINK(this, OTasksWindow
, OnEntrySelectHdl
));
122 m_xTreeView
->connect_focus_in(LINK(this, OTasksWindow
, FocusInHdl
));
123 m_xTreeView
->connect_focus_out(LINK(this, OTasksWindow
, FocusOutHdl
));
124 // an arbitrary small size it's allowed to shrink to
125 m_xTreeView
->set_size_request(42, 42);
127 m_xHelpText
->set_help_id(HID_APP_HELP_TEXT
);
128 m_xDescription
->set_help_id(HID_APP_DESCRIPTION_TEXT
);
131 OTasksWindow::~OTasksWindow()
136 void OTasksWindow::setHelpText(TranslateId pId
)
139 m_xHelpText
->set_text(DBA_RES(pId
));
141 m_xHelpText
->set_text(OUString());
144 void OTasksWindow::fillTaskEntryList( const TaskEntryList
& _rList
)
150 Reference
< XModuleUIConfigurationManagerSupplier
> xModuleCfgMgrSupplier
=
151 theModuleUIConfigurationManagerSupplier::get( getDetailView()->getBorderWin().getView()->getORB() );
152 Reference
< XUIConfigurationManager
> xUIConfigMgr
= xModuleCfgMgrSupplier
->getUIConfigurationManager(
153 u
"com.sun.star.sdb.OfficeDatabaseDocument"_ustr
155 Reference
< XImageManager
> xImageMgr( xUIConfigMgr
->getImageManager(), UNO_QUERY
);
157 // copy the commands so we can use them with the config managers
158 Sequence
< OUString
> aCommands( _rList
.size() );
159 std::transform(_rList
.begin(), _rList
.end(), aCommands
.getArray(),
160 [](auto& copyTask
) { return copyTask
.sUNOCommand
; });
162 Sequence
< Reference
< XGraphic
> > aImages
= xImageMgr
->getImages(
163 ImageType::SIZE_DEFAULT
| ImageType::COLOR_NORMAL
,
166 assert(aImages
.size() == _rList
.size());
168 for (size_t nIndex
= 0; nIndex
< _rList
.size(); ++nIndex
)
170 OUString sId
= weld::toId(new TaskEntry(_rList
[nIndex
]));
171 m_xTreeView
->append(sId
, _rList
[nIndex
].sTitle
);
172 m_xTreeView
->set_image(nIndex
, aImages
[nIndex
]);
179 m_xTreeView
->unselect_all();
181 Enable(!_rList
.empty());
184 void OTasksWindow::Clear()
186 m_xTreeView
->all_foreach([this](weld::TreeIter
& rEntry
){
187 TaskEntry
* pUserData
= weld::fromId
<TaskEntry
*>(m_xTreeView
->get_id(rEntry
));
192 m_xTreeView
->clear();
195 OApplicationDetailView::OApplicationDetailView(weld::Container
* pParent
, OAppBorderWindow
& rBorder
,
196 PreviewMode ePreviewMode
)
197 : m_xBuilder(Application::CreateBuilder(pParent
, u
"dbaccess/ui/appdetailwindow.ui"_ustr
))
198 , m_xContainer(m_xBuilder
->weld_container(u
"AppDetailWindow"_ustr
))
199 , m_xHorzSplitter(m_xBuilder
->weld_paned(u
"splitter"_ustr
))
200 , m_xTasksParent(m_xBuilder
->weld_container(u
"tasks"_ustr
))
201 , m_xContainerParent(m_xBuilder
->weld_container(u
"container"_ustr
))
202 , m_xTasks(new dbaui::OTitleWindow(m_xTasksParent
.get(), STR_TASKS
))
203 , m_xTitleContainer(new dbaui::OTitleWindow(m_xContainerParent
.get(), TranslateId()))
204 , m_rBorderWin(rBorder
)
206 m_xControlHelper
= std::make_shared
<OAppDetailPageHelper
>(m_xTitleContainer
->getChildContainer(), m_rBorderWin
, ePreviewMode
);
207 m_xTitleContainer
->setChildWindow(m_xControlHelper
);
209 std::shared_ptr
<OChildWindow
> xTasks
= std::make_shared
<OTasksWindow
>(m_xTasks
->getChildContainer(), this);
210 xTasks
->Enable(!m_rBorderWin
.getView()->getCommandController().isDataSourceReadOnly());
211 m_xTasks
->setChildWindow(xTasks
);
214 OApplicationDetailView::~OApplicationDetailView()
218 void OApplicationDetailView::setTaskExternalMnemonics( MnemonicGenerator
const & rMnemonics
)
220 m_aExternalMnemonics
= rMnemonics
;
223 void OApplicationDetailView::createTablesPage(const Reference
< XConnection
>& _xConnection
)
225 impl_createPage( E_TABLE
, _xConnection
, nullptr );
228 void OApplicationDetailView::createPage( ElementType _eType
,const Reference
< XNameAccess
>& _xContainer
)
230 impl_createPage( _eType
, nullptr, _xContainer
);
233 void OApplicationDetailView::impl_createPage( ElementType _eType
, const Reference
< XConnection
>& _rxConnection
,
234 const Reference
< XNameAccess
>& _rxNonTableElements
)
236 // get the data for the pane
237 const TaskPaneData
& rData
= impl_getTaskPaneData( _eType
);
238 getTasksWindow().fillTaskEntryList( rData
.aTasks
);
240 // enable the pane as a whole, depending on the availability of the first command
241 OSL_ENSURE( !rData
.aTasks
.empty(), "OApplicationDetailView::impl_createPage: no tasks at all!?" );
242 bool bEnabled
= !rData
.aTasks
.empty()
243 && getBorderWin().getView()->getCommandController().isCommandEnabled( rData
.aTasks
[0].sUNOCommand
);
244 getTasksWindow().Enable( bEnabled
);
245 m_xTitleContainer
->setTitle(rData
.pTitleId
);
247 // let our helper create the object list
248 if ( _eType
== E_TABLE
)
249 GetControlHelper()->createTablesPage( _rxConnection
);
251 GetControlHelper()->createPage( _eType
, _rxNonTableElements
);
254 void OApplicationDetailView::impl_fillTaskPaneData(ElementType _eType
, TaskPaneData
& _rData
) const
256 TaskEntryList
& rList( _rData
.aTasks
);
257 rList
.clear(); rList
.reserve( 4 );
262 rList
.emplace_back( u
".uno:DBNewTable"_ustr
, RID_STR_TABLES_HELP_TEXT_DESIGN
, RID_STR_NEW_TABLE
);
263 rList
.emplace_back( u
".uno:DBNewTableAutoPilot"_ustr
, RID_STR_TABLES_HELP_TEXT_WIZARD
, RID_STR_NEW_TABLE_AUTO
);
264 rList
.emplace_back( u
".uno:DBNewView"_ustr
, RID_STR_VIEWS_HELP_TEXT_DESIGN
, RID_STR_NEW_VIEW
, true );
265 _rData
.pTitleId
= RID_STR_TABLES_CONTAINER
;
269 rList
.emplace_back( u
".uno:DBNewForm"_ustr
, RID_STR_FORMS_HELP_TEXT
, RID_STR_NEW_FORM
);
270 rList
.emplace_back( u
".uno:DBNewFormAutoPilot"_ustr
, RID_STR_FORMS_HELP_TEXT_WIZARD
, RID_STR_NEW_FORM_AUTO
);
271 _rData
.pTitleId
= RID_STR_FORMS_CONTAINER
;
275 rList
.emplace_back( u
".uno:DBNewReport"_ustr
, RID_STR_REPORT_HELP_TEXT
, RID_STR_NEW_REPORT
, true );
276 rList
.emplace_back( u
".uno:DBNewReportAutoPilot"_ustr
, RID_STR_REPORTS_HELP_TEXT_WIZARD
, RID_STR_NEW_REPORT_AUTO
);
277 _rData
.pTitleId
= RID_STR_REPORTS_CONTAINER
;
281 rList
.emplace_back( u
".uno:DBNewQuery"_ustr
, RID_STR_QUERIES_HELP_TEXT
, RID_STR_NEW_QUERY
);
282 rList
.emplace_back( u
".uno:DBNewQueryAutoPilot"_ustr
, RID_STR_QUERIES_HELP_TEXT_WIZARD
, RID_STR_NEW_QUERY_AUTO
);
283 rList
.emplace_back( u
".uno:DBNewQuerySql"_ustr
, RID_STR_QUERIES_HELP_TEXT_SQL
, RID_STR_NEW_QUERY_SQL
);
284 _rData
.pTitleId
= RID_STR_QUERIES_CONTAINER
;
288 OSL_FAIL( "OApplicationDetailView::impl_fillTaskPaneData: illegal element type!" );
291 // remove the entries which are not enabled currently
292 for (TaskEntryList::iterator pTask
= rList
.begin(); pTask
!= rList
.end();)
294 if ( pTask
->bHideWhenDisabled
295 && !getBorderWin().getView()->getCommandController().isCommandEnabled( pTask
->sUNOCommand
)
297 pTask
= rList
.erase( pTask
);
305 const TaskPaneData
& OApplicationDetailView::impl_getTaskPaneData( ElementType _eType
)
307 if ( m_aTaskPaneData
.empty() )
308 m_aTaskPaneData
.resize( size_t(E_ELEMENT_TYPE_COUNT
) );
309 OSL_ENSURE( ( _eType
>= 0 ) && ( _eType
< E_ELEMENT_TYPE_COUNT
), "OApplicationDetailView::impl_getTaskPaneData: illegal element type!" );
310 TaskPaneData
& rData
= m_aTaskPaneData
[ _eType
];
312 //oj: do not check, otherwise extensions will only be visible after a reload.
313 impl_fillTaskPaneData( _eType
, rData
);
318 OUString
OApplicationDetailView::getQualifiedName(const weld::TreeIter
* _pEntry
) const
320 return GetControlHelper()->getQualifiedName( _pEntry
);
323 bool OApplicationDetailView::isLeaf(const weld::TreeView
& rTreeView
, const weld::TreeIter
& rEntry
)
325 return OAppDetailPageHelper::isLeaf(rTreeView
, rEntry
);
328 bool OApplicationDetailView::isALeafSelected() const
330 return GetControlHelper()->isALeafSelected();
333 void OApplicationDetailView::selectAll()
335 GetControlHelper()->selectAll();
338 void OApplicationDetailView::sortDown()
340 GetControlHelper()->sortDown();
343 void OApplicationDetailView::sortUp()
345 GetControlHelper()->sortUp();
348 bool OApplicationDetailView::isFilled() const
350 return GetControlHelper()->isFilled();
353 ElementType
OApplicationDetailView::getElementType() const
355 return GetControlHelper()->getElementType();
358 void OApplicationDetailView::clearPages(bool _bTaskAlso
)
361 getTasksWindow().Clear();
362 GetControlHelper()->clearPages();
365 sal_Int32
OApplicationDetailView::getSelectionCount()
367 return GetControlHelper()->getSelectionCount();
370 sal_Int32
OApplicationDetailView::getElementCount() const
372 return GetControlHelper()->getElementCount();
375 void OApplicationDetailView::getSelectionElementNames( std::vector
< OUString
>& _rNames
) const
377 GetControlHelper()->getSelectionElementNames( _rNames
);
380 void OApplicationDetailView::describeCurrentSelectionForControl(const weld::TreeView
& rControl
, Sequence
< NamedDatabaseObject
>& out_rSelectedObjects
)
382 GetControlHelper()->describeCurrentSelectionForControl(rControl
, out_rSelectedObjects
);
385 void OApplicationDetailView::describeCurrentSelectionForType( const ElementType _eType
, Sequence
< NamedDatabaseObject
>& _out_rSelectedObjects
)
387 GetControlHelper()->describeCurrentSelectionForType( _eType
, _out_rSelectedObjects
);
390 vcl::Window
* OApplicationDetailView::getMenuParent() const
392 return GetControlHelper()->getMenuParent();
395 void OApplicationDetailView::adjustMenuPosition(const weld::TreeView
& rControl
, ::Point
& rPos
) const
397 return GetControlHelper()->adjustMenuPosition(rControl
, rPos
);
400 void OApplicationDetailView::selectElements(const Sequence
< OUString
>& _aNames
)
402 GetControlHelper()->selectElements( _aNames
);
405 std::unique_ptr
<weld::TreeIter
> OApplicationDetailView::getEntry(const Point
& rPoint
) const
407 return GetControlHelper()->getEntry(rPoint
);
410 bool OApplicationDetailView::isCutAllowed()
415 bool OApplicationDetailView::isCopyAllowed()
420 bool OApplicationDetailView::isPasteAllowed() { return true; }
422 void OApplicationDetailView::copy() { }
424 void OApplicationDetailView::cut() { }
426 void OApplicationDetailView::paste() { }
428 std::unique_ptr
<weld::TreeIter
> OApplicationDetailView::elementAdded(ElementType _eType
,const OUString
& _rName
, const Any
& _rObject
)
430 return GetControlHelper()->elementAdded(_eType
, _rName
, _rObject
);
433 void OApplicationDetailView::elementRemoved(ElementType _eType
,const OUString
& _rName
)
435 GetControlHelper()->elementRemoved(_eType
,_rName
);
438 void OApplicationDetailView::elementReplaced(ElementType _eType
439 ,const OUString
& _rOldName
440 ,const OUString
& _rNewName
)
442 GetControlHelper()->elementReplaced( _eType
, _rOldName
, _rNewName
);
445 PreviewMode
OApplicationDetailView::getPreviewMode() const
447 return GetControlHelper()->getPreviewMode();
450 bool OApplicationDetailView::isPreviewEnabled() const
452 return GetControlHelper()->isPreviewEnabled();
455 void OApplicationDetailView::switchPreview(PreviewMode _eMode
)
457 GetControlHelper()->switchPreview(_eMode
);
460 void OApplicationDetailView::showPreview(const Reference
< XContent
>& _xContent
)
462 GetControlHelper()->showPreview(_xContent
);
465 void OApplicationDetailView::showPreview( const OUString
& _sDataSourceName
,
466 const OUString
& _sName
,
469 GetControlHelper()->showPreview(_sDataSourceName
,_sName
,_bTable
);
472 bool OApplicationDetailView::isSortUp() const
474 return GetControlHelper()->isSortUp();
477 TreeListBox
* OApplicationDetailView::getTreeWindow() const
479 DBTreeViewBase
* pCurrent
= GetControlHelper()->getCurrentView();
482 return &pCurrent
->getListBox();
485 OAppDetailPageHelper
* OApplicationDetailView::GetControlHelper()
487 return static_cast<OAppDetailPageHelper
*>(m_xControlHelper
.get());
490 const OAppDetailPageHelper
* OApplicationDetailView::GetControlHelper() const
492 return static_cast<const OAppDetailPageHelper
*>(m_xControlHelper
.get());
495 bool OApplicationDetailView::HasChildPathFocus() const
497 return m_xHorzSplitter
->has_focus() ||
498 m_xTasks
->HasChildPathFocus() ||
499 m_xTitleContainer
->HasChildPathFocus();
502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */