Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / dbaccess / source / ui / inc / dbtreelistbox.hxx
blob21723a70ad7fa47a3ef86c94600388a99b2deedf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
20 #define INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
22 #include "ScrollHelper.hxx"
23 #include "moduledbu.hxx"
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <svtools/treelistbox.hxx>
28 #include <vcl/timer.hxx>
30 #include <memory>
31 #include <set>
33 namespace dbaui
35 struct DBTreeEditedEntry
37 SvTreeListEntry* pEntry;
38 OUString aNewText;
41 class IEntryFilter
43 public:
44 virtual bool includeEntry( SvTreeListEntry* _pEntry ) const = 0;
46 protected:
47 ~IEntryFilter() {}
50 class IControlActionListener;
51 class IContextMenuProvider;
52 class DBTreeListBox :public SvTreeListBox
54 OModuleClient m_aModuleClient;
55 OScrollHelper m_aScrollHelper;
56 Timer m_aTimer; // is needed for table updates
57 Point m_aMousePos;
58 std::set<SvTreeListEntry*> m_aSelectedEntries;
59 SvTreeListEntry* m_pDragedEntry;
60 IControlActionListener* m_pActionListener;
61 IContextMenuProvider*
62 m_pContextMenuProvider;
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;
71 bool m_bHandleEnterKey;
73 private:
74 void init();
75 DECL_LINK_TYPED( OnTimeOut, Timer*, void );
76 DECL_LINK_TYPED( OnResetEntry, void*, void );
77 DECL_LINK_TYPED( ScrollUpHdl, LinkParamNone*, void );
78 DECL_LINK_TYPED( ScrollDownHdl, LinkParamNone*, void );
80 public:
81 DBTreeListBox( vcl::Window* pParent, WinBits nWinStyle=0);
82 virtual ~DBTreeListBox();
83 virtual void dispose() override;
85 void setControlActionListener( IControlActionListener* _pListener ) { m_pActionListener = _pListener; }
86 void setContextMenuProvider( IContextMenuProvider* _pContextMenuProvider ) { m_pContextMenuProvider = _pContextMenuProvider; }
88 void SetPreExpandHandler(const Link<SvTreeListEntry*,bool>& _rHdl) { m_aPreExpandHandler = _rHdl; }
89 void SetSelChangeHdl( const Link<LinkParamNone*,void>& _rHdl ) { m_aSelChangeHdl = _rHdl; }
90 void setCopyHandler(const Link<LinkParamNone*,void>& _rHdl) { m_aCopyHandler = _rHdl; }
91 void setPasteHandler(const Link<LinkParamNone*,void>& _rHdl) { m_aPasteHandler = _rHdl; }
92 void setDeleteHandler(const Link<LinkParamNone*,void>& _rHdl) { m_aDeleteHandler = _rHdl; }
94 // modified the given entry so that the expand handler is called whenever the entry is expanded
95 // (normally, the expand handler is called only once)
96 void EnableExpandHandler(SvTreeListEntry* _pEntry);
98 SvTreeListEntry* GetEntryPosByName( const OUString& aName, SvTreeListEntry* pStart = nullptr, const IEntryFilter* _pFilter = nullptr ) const;
99 virtual void RequestingChildren( SvTreeListEntry* pParent ) override;
100 virtual void SelectHdl() override;
101 virtual void DeselectHdl() override;
102 // Window
103 virtual void KeyInput( const KeyEvent& rKEvt ) override;
105 virtual void StateChanged( StateChangedType nStateChange ) override;
106 virtual void InitEntry(SvTreeListEntry* pEntry, const OUString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp, SvLBoxButtonKind eButtonKind) override;
108 // enable editing for tables/views and queries
109 virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& ) override;
110 virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) override;
112 virtual bool DoubleClickHdl() override;
114 virtual std::unique_ptr<PopupMenu> CreateContextMenu() override;
115 virtual void ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override;
117 void SetEnterKeyHdl(const Link<DBTreeListBox*,void>& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
119 void clearCurrentSelection() { m_aSelectedEntries.clear(); }
121 protected:
122 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
123 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
125 // DragSourceHelper overridables
126 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
127 // DropTargetHelper overridables
128 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& _rEvt ) override;
129 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& _rEvt ) override;
131 virtual void ModelHasRemoved( SvTreeListEntry* pEntry ) override;
132 virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry ) override;
134 void implStopSelectionTimer();
135 void implStartSelectionTimer();
137 protected:
138 using SvTreeListBox::ExecuteDrop;
142 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */