22#include <callbacks.hxx>
24#include <com/sun/star/awt/PopupMenuDirection.hpp>
25#include <com/sun/star/ui/XContextMenuInterceptor.hpp>
26#include <com/sun/star/uno/XComponentContext.hpp>
27#include <com/sun/star/frame/XController.hpp>
28#include <com/sun/star/frame/XPopupMenuController.hpp>
29#include <com/sun/star/lang/IllegalArgumentException.hpp>
59 ,
TreeListBox(m_xBuilder->weld_tree_view(
"treeview"), true)
60 , m_xStatusBar(m_xBuilder->weld_label(
"statusbar"))
84 : DropTargetHelper(rTreeView.GetWidget().get_drop_target())
85 , m_rTreeView(rTreeView)
109 : m_xTreeView(
std::move(xTreeView))
110 , m_aDropTargetHelper(*this)
111 , m_pActionListener(nullptr)
112 , m_pContextMenuProvider(nullptr)
113 , m_aTimer(
"dbaccess TreeListBox m_aTimer")
139 KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction();
140 bool bHandled =
false;
144 case KeyFuncType::COPY:
145 bHandled = m_aCopyHandler.IsSet() && !m_xTreeView->get_selected(
nullptr);
147 m_aCopyHandler.Call(
nullptr);
149 case KeyFuncType::PASTE:
150 bHandled = m_aPasteHandler.IsSet() && !m_xTreeView->get_selected(
nullptr);
152 m_aPasteHandler.Call(
nullptr);
154 case KeyFuncType::DELETE:
155 bHandled = m_aDeleteHandler.IsSet() && !m_xTreeView->get_selected(
nullptr);
157 m_aDeleteHandler.Call(
nullptr);
163 return bHandled || DoChildKeyInput(rKEvt);
180 implStartSelectionTimer();
218 rUnsetDragIcon =
false;
220 if (m_pActionListener)
222 m_xDragedEntry = m_xTreeView->make_iterator();
223 if (!m_xTreeView->get_selected(m_xDragedEntry.get()))
224 m_xDragedEntry.reset();
225 if (m_xDragedEntry && m_pActionListener->requestDrag(*m_xDragedEntry))
228 implStopSelectionTimer();
242 std::unique_ptr<weld::TreeIter> xDropTarget(
m_xTreeView->make_iterator());
243 if (!
m_xTreeView->get_dest_row_at_pos(aDropPos, xDropTarget.get(),
true))
247 std::unique_ptr<weld::TreeIter> xParent;
255 xParent =
m_xTreeView->make_iterator(xDropTarget.get());
276 nDropOption = nDropOption & ~DND_ACTION_MOVE;
295 OUString sQuickHelpText;
296 if (m_pActionListener &&
297 m_pActionListener->requestQuickHelp(weld::fromId<void*>(m_xTreeView->get_id(rIter)), sQuickHelpText))
299 return sQuickHelpText;
301 return m_xTreeView->get_tooltip_text();
307 typedef ::cppu::WeakImplHelper< XSelectionSupplier
308 > SelectionSupplier_Base;
309 class SelectionSupplier :
public SelectionSupplier_Base
312 explicit SelectionSupplier( Any _aSelection )
317 virtual sal_Bool SAL_CALL select(
const Any& xSelection )
override;
318 virtual Any SAL_CALL getSelection( )
override;
319 virtual void SAL_CALL addSelectionChangeListener(
const Reference< XSelectionChangeListener >& xListener )
override;
320 virtual void SAL_CALL removeSelectionChangeListener(
const Reference< XSelectionChangeListener >& xListener )
override;
323 virtual ~SelectionSupplier()
override
331 sal_Bool SAL_CALL SelectionSupplier::select(
const Any& )
333 throw IllegalArgumentException();
337 Any SAL_CALL SelectionSupplier::getSelection( )
342 void SAL_CALL SelectionSupplier::addSelectionChangeListener(
const Reference< XSelectionChangeListener >& )
344 OSL_FAIL(
"SelectionSupplier::removeSelectionChangeListener: no support!" );
348 void SAL_CALL SelectionSupplier::removeSelectionChangeListener(
const Reference< XSelectionChangeListener >& )
350 OSL_FAIL(
"SelectionSupplier::removeSelectionChangeListener: no support!" );
357 if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
360 ::Point aPos = rCEvt.GetMousePosPixel();
362 std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
363 if (m_xTreeView->get_dest_row_at_pos(aPos, xIter.get(),
false) && !m_xTreeView->is_selected(*xIter))
365 m_xTreeView->unselect_all();
366 m_xTreeView->set_cursor(*xIter);
367 m_xTreeView->select(*xIter);
368 SelectHdl(*m_xTreeView);
371 if (!m_pContextMenuProvider)
374 OUString aResourceName(m_pContextMenuProvider->getContextMenuResourceName());
375 if (aResourceName.isEmpty())
378 css::uno::Sequence< css::uno::Any > aArgs{
385 css::uno::Reference<css::frame::XPopupMenuController> xMenuController
386 (xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
387 "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext), css::uno::UNO_QUERY);
389 if (!xMenuController.is())
397 xMenuController->setPopupMenu( xPopupMenu );
401 if (pInterceptors && pInterceptors->
getLength())
403 OUString aMenuIdentifier(
"private:resource/popupmenu/" + aResourceName );
405 ContextMenuExecuteEvent
aEvent;
406 aEvent.SourceWindow = xSourceWindow;
407 aEvent.ExecutePosition.X = -1;
408 aEvent.ExecutePosition.Y = -1;
410 xPopupMenu, &aMenuIdentifier );
411 aEvent.Selection =
new SelectionSupplier(m_pContextMenuProvider->getCurrentSelection(*m_xTreeView));
414 bool bModifiedMenu =
false;
415 bool bAskInterceptors =
true;
419 if ( !xInterceptor.is() )
424 ContextMenuInterceptorAction eAction = xInterceptor->notifyContextMenuExecute(
aEvent );
427 case ContextMenuInterceptorAction_CANCELLED:
430 case ContextMenuInterceptorAction_EXECUTE_MODIFIED:
431 bModifiedMenu =
true;
432 bAskInterceptors =
false;
435 case ContextMenuInterceptorAction_CONTINUE_MODIFIED:
436 bModifiedMenu =
true;
437 bAskInterceptors =
true;
441 OSL_FAIL(
"DBTreeListBox::CreateContextMenu: unexpected return value of the interceptor call!" );
443 case ContextMenuInterceptorAction_IGNORED:
447 catch(
const DisposedException& e )
449 if ( e.Context == xInterceptor )
458 xPopupMenu,
aEvent.ActionTriggerContainer );
459 aEvent.ActionTriggerContainer.clear();
464 m_pContextMenuProvider->adjustMenuPosition(*m_xTreeView, aPos);
467 css::uno::Reference<css::awt::XWindowPeer> xParent(xSourceWindow, css::uno::UNO_QUERY);
468 xPopupMenu->execute(xParent, css::awt::Rectangle(aPos.
X(), aPos.
Y(), 1, 1), css::awt::PopupMenuDirection::EXECUTE_DOWN);
470 css::uno::Reference<css::lang::XComponent> xComponent(xMenuController, css::uno::UNO_QUERY);
472 xComponent->dispose();
473 xMenuController.clear();
480 implStopSelectionTimer();
482 m_aSelChangeHdl.Call(
nullptr );
489 std::unique_ptr<weld::TreeIter> xEntry(
m_xTreeView->make_iterator(pEntry));
496 : m_xBuilder(
Application::CreateBuilder(pContainer,
"dbaccess/ui/dbtreelist.ui"))
497 ,
m_xContainer(m_xBuilder->weld_container(
"DBTreeList"))
bool ChildKeyInput(const KeyEvent &rKEvt)
virtual void dispose() override
void InitControlBase(weld::Widget *pWidget)
constexpr tools::Long Y() const
constexpr tools::Long X() const
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
sal_Int32 getLength() const
css::uno::XInterface * next()
bool hasMoreElements() const
virtual ~DBTreeViewBase()
std::unique_ptr< weld::Builder > m_xBuilder
DBTreeViewBase(weld::Container *pContainer)
std::unique_ptr< TreeListBox > m_xTreeListBox
DBTreeView(weld::Container *pContainer, bool bSQLType)
virtual sal_Int8 queryDrop(const AcceptDropEvent &_rEvt, const DataFlavorExVector &_rFlavors)=0
check whether or not a drop request should be accepted
virtual sal_Int8 executeDrop(const ExecuteDropEvent &_rEvt)=0
execute a drop request
virtual bool includeEntry(const void *pUserData) const =0
virtual bool DoChildKeyInput(const KeyEvent &rKEvt) override
virtual ~InterimDBTreeListBox() override
std::unique_ptr< weld::Label > m_xStatusBar
virtual void dispose() override
InterimDBTreeListBox(vcl::Window *pParent)
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
TreeListBoxDropTarget(TreeListBox &rTreeView)
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
TreeListBox & m_rTreeView
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
std::unique_ptr< weld::TreeIter > GetEntryPosByName(std::u16string_view rName, const weld::TreeIter *pStart=nullptr, const IEntryFilter *pFilter=nullptr) const
std::unique_ptr< weld::TreeIter > GetRootLevelParent(const weld::TreeIter *pEntry) const
void implStopSelectionTimer()
std::unique_ptr< weld::TreeIter > m_xDragedEntry
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
virtual bool DoChildKeyInput(const KeyEvent &rKEvt)
TreeListBoxDropTarget m_aDropTargetHelper
IControlActionListener * m_pActionListener
weld::TreeView & GetWidget()
rtl::Reference< TransferDataContainer > m_xHelper
std::unique_ptr< weld::TreeView > m_xTreeView
TreeListBox(std::unique_ptr< weld::TreeView > xTreeView, bool bSQLType)
void implStartSelectionTimer()
static void CreateMenuFromActionTriggerContainer(const css::uno::Reference< css::awt::XPopupMenu > &rNewMenu, const css::uno::Reference< css::container::XIndexContainer > &rActionTriggerContainer)
static css::uno::Reference< css::container::XIndexContainer > CreateActionTriggerContainerFromMenu(const css::uno::Reference< css::awt::XPopupMenu > &rMenu, const OUString *pMenuIdentifier)
virtual bool get_dest_row_at_pos(const Point &rPos, weld::TreeIter *pResult, bool bDnDMode, bool bAutoScroll=true)=0
#define LINK(Instance, Class, Member)
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
Reference< XNameAccess > m_xContainer