1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
20 #define INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
21 
22 #include "ScrollHelper.hxx"
23 
24 #include <com/sun/star/frame/XPopupMenuController.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 
27 #include <vcl/treelistbox.hxx>
28 #include <vcl/timer.hxx>
29 #include <vcl/weld.hxx>
30 
31 #include <memory>
32 #include <set>
33 
34 namespace dbaui
35 {
36     struct DBTreeEditedEntry
37     {
38         OUString       aNewText;
39     };
40 
41     class IEntryFilter
42     {
43     public:
44         virtual bool    includeEntry(const void* pUserData) const = 0;
45 
46     protected:
~IEntryFilter()47         ~IEntryFilter() {}
48     };
49 
50     class IControlActionListener;
51     class IContextMenuProvider;
52     class DBTreeListBox     :public SvTreeListBox
53     {
54         OScrollHelper               m_aScrollHelper;
55         Timer                       m_aTimer; // is needed for table updates
56         Point                       m_aMousePos;
57         std::set<SvTreeListEntry*>  m_aSelectedEntries;
58         SvTreeListEntry*            m_pDragedEntry;
59         IControlActionListener*     m_pActionListener;
60         IContextMenuProvider*       m_pContextMenuProvider;
61         ImplSVEvent*                m_pResetEvent;
62         css::uno::Reference<css::frame::XPopupMenuController> m_xMenuController;
63 
64         Link<SvTreeListEntry*,bool> m_aPreExpandHandler;    // handler to be called before a node is expanded
65         Link<LinkParamNone*,void>   m_aSelChangeHdl;        // handler to be called (asynchronously) when the selection changes in any way
66         Link<LinkParamNone*,void>   m_aCopyHandler;         // called when someone press CTRL+C
67         Link<LinkParamNone*,void>   m_aPasteHandler;        // called when someone press CTRL+V
68         Link<LinkParamNone*,void>   m_aDeleteHandler;       // called when someone press DELETE Key
69         Link<DBTreeListBox*,void>   m_aEnterKeyHdl;
70 
71     private:
72         void init();
73         DECL_LINK( OnTimeOut, Timer*, void );
74         DECL_LINK( OnResetEntryHdl, void*, void );
75         DECL_LINK( ScrollUpHdl, LinkParamNone*, void );
76         DECL_LINK( ScrollDownHdl, LinkParamNone*, void );
77         DECL_LINK( MenuEventListener, VclMenuEvent&, void );
78 
79     public:
80         DBTreeListBox( vcl::Window* pParent, WinBits nWinStyle);
81         virtual ~DBTreeListBox() override;
82         virtual void dispose() override;
83 
setControlActionListener(IControlActionListener * _pListener)84         void                    setControlActionListener( IControlActionListener* _pListener ) { m_pActionListener = _pListener; }
setContextMenuProvider(IContextMenuProvider * _pContextMenuProvider)85         void                    setContextMenuProvider( IContextMenuProvider* _pContextMenuProvider ) { m_pContextMenuProvider = _pContextMenuProvider; }
86 
SetPreExpandHandler(const Link<SvTreeListEntry *,bool> & _rHdl)87         void    SetPreExpandHandler(const Link<SvTreeListEntry*,bool>& _rHdl)  { m_aPreExpandHandler = _rHdl; }
SetSelChangeHdl(const Link<LinkParamNone *,void> & _rHdl)88         void    SetSelChangeHdl( const Link<LinkParamNone*,void>& _rHdl )      { m_aSelChangeHdl = _rHdl; }
setCopyHandler(const Link<LinkParamNone *,void> & _rHdl)89         void    setCopyHandler(const Link<LinkParamNone*,void>& _rHdl)         { m_aCopyHandler = _rHdl; }
setPasteHandler(const Link<LinkParamNone *,void> & _rHdl)90         void    setPasteHandler(const Link<LinkParamNone*,void>& _rHdl)        { m_aPasteHandler = _rHdl; }
setDeleteHandler(const Link<LinkParamNone *,void> & _rHdl)91         void    setDeleteHandler(const Link<LinkParamNone*,void>& _rHdl)       { m_aDeleteHandler = _rHdl; }
92 
93         // modified the given entry so that the expand handler is called whenever the entry is expanded
94         // (normally, the expand handler is called only once)
95         void            EnableExpandHandler(SvTreeListEntry* _pEntry);
96 
97         SvTreeListEntry*    GetEntryPosByName( const OUString& aName, SvTreeListEntry* pStart = nullptr, const IEntryFilter* _pFilter = nullptr ) const;
98         virtual void    RequestingChildren( SvTreeListEntry* pParent ) override;
99         virtual void    SelectHdl() override;
100         virtual void    DeselectHdl() override;
101         // Window
102         virtual void    KeyInput( const KeyEvent& rKEvt ) override;
103 
104         virtual void    StateChanged( StateChangedType nStateChange ) override;
105         virtual void    InitEntry(SvTreeListEntry* pEntry, const OUString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp) override;
106 
107         // enable editing for tables/views and queries
108         virtual bool    EditingEntry( SvTreeListEntry* pEntry, Selection& ) override;
109         virtual bool    EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) override;
110 
111         virtual bool    DoubleClickHdl() override;
112 
113         virtual VclPtr<PopupMenu> CreateContextMenu() override;
114         virtual void    ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override;
115 
SetEnterKeyHdl(const Link<DBTreeListBox *,void> & rNewHdl)116         void            SetEnterKeyHdl(const Link<DBTreeListBox*,void>& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
117 
clearCurrentSelection()118         void            clearCurrentSelection() { m_aSelectedEntries.clear(); }
119 
120     protected:
121         virtual void        MouseButtonDown( const MouseEvent& rMEvt ) override;
122         virtual void        RequestHelp( const HelpEvent& rHEvt ) override;
123 
124         // DragSourceHelper overridables
125         virtual void        StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
126         // DropTargetHelper overridables
127         virtual sal_Int8    AcceptDrop( const AcceptDropEvent& _rEvt ) override;
128         virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& _rEvt ) override;
129 
130         virtual void        ModelHasRemoved( SvTreeListEntry* pEntry ) override;
131         virtual void        ModelHasEntryInvalidated( SvTreeListEntry* pEntry ) override;
132 
133         void                implStopSelectionTimer();
134         void                implStartSelectionTimer();
135 
136     protected:
137         using SvTreeListBox::ExecuteDrop;
138     };
139 }
140 
141 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
144