Line data Source code
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 : #include "moduledbu.hxx"
24 :
25 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 :
27 : #include <svtools/treelistbox.hxx>
28 : #include <vcl/timer.hxx>
29 :
30 : #include <set>
31 :
32 : namespace dbaui
33 : {
34 0 : struct DBTreeEditedEntry
35 : {
36 : SvTreeListEntry* pEntry;
37 : OUString aNewText;
38 : };
39 :
40 2 : class IEntryFilter
41 : {
42 : public:
43 : virtual bool includeEntry( SvTreeListEntry* _pEntry ) const = 0;
44 :
45 : protected:
46 2 : ~IEntryFilter() {}
47 : };
48 :
49 : class IControlActionListener;
50 : class IContextMenuProvider;
51 : class DBTreeListBox :public SvTreeListBox
52 : {
53 : OModuleClient m_aModuleClient;
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*
61 : m_pContextMenuProvider;
62 :
63 : Link<> m_aPreExpandHandler; // handler to be called before a node is expanded
64 : Link<> m_aSelChangeHdl; // handlet to be called (asynchronously) when the selection changes in any way
65 : Link<> m_aCutHandler; // called when someone press CTRL+X
66 : Link<> m_aCopyHandler; // called when someone press CTRL+C
67 : Link<> m_aPasteHandler; // called when someone press CTRL+V
68 : Link<> m_aDeleteHandler; // called when someone press DELETE Key
69 : Link<> m_aEditingHandler; // called before someone will edit an entry
70 : Link<> m_aEditedHandler; // called after someone edited an entry
71 : Link<> m_aEnterKeyHdl;
72 :
73 : bool m_bHandleEnterKey;
74 :
75 : private:
76 : void init();
77 : DECL_LINK_TYPED( OnTimeOut, Timer*, void );
78 : DECL_LINK( OnResetEntry, SvTreeListEntry* );
79 : DECL_LINK( ScrollUpHdl, SvTreeListBox* );
80 : DECL_LINK( ScrollDownHdl, SvTreeListBox* );
81 :
82 : public:
83 : DBTreeListBox( vcl::Window* pParent
84 : ,WinBits nWinStyle=0
85 : ,bool _bHandleEnterKey = false);
86 : virtual ~DBTreeListBox();
87 : virtual void dispose() SAL_OVERRIDE;
88 :
89 4 : void setControlActionListener( IControlActionListener* _pListener ) { m_pActionListener = _pListener; }
90 4 : void setContextMenuProvider( IContextMenuProvider* _pContextMenuProvider ) { m_pContextMenuProvider = _pContextMenuProvider; }
91 :
92 1 : void SetPreExpandHandler(const Link<>& _rHdl) { m_aPreExpandHandler = _rHdl; }
93 4 : void SetSelChangeHdl( const Link<>& _rHdl ) { m_aSelChangeHdl = _rHdl; }
94 3 : void setCutHandler(const Link<>& _rHdl) { m_aCutHandler = _rHdl; }
95 4 : void setCopyHandler(const Link<>& _rHdl) { m_aCopyHandler = _rHdl; }
96 3 : void setPasteHandler(const Link<>& _rHdl) { m_aPasteHandler = _rHdl; }
97 3 : void setDeleteHandler(const Link<>& _rHdl) { m_aDeleteHandler = _rHdl; }
98 : void setEditingHandler(const Link<>& _rHdl) { m_aEditingHandler = _rHdl; }
99 : void setEditedHandler(const Link<>& _rHdl) { m_aEditedHandler = _rHdl; }
100 :
101 : // modified the given entry so that the expand handler is called whenever the entry is expanded
102 : // (normally, the expand handler is called only once)
103 : void EnableExpandHandler(SvTreeListEntry* _pEntry);
104 :
105 : SvTreeListEntry* GetEntryPosByName( const OUString& aName, SvTreeListEntry* pStart = NULL, const IEntryFilter* _pFilter = NULL ) const;
106 : virtual void RequestingChildren( SvTreeListEntry* pParent ) SAL_OVERRIDE;
107 : virtual void SelectHdl() SAL_OVERRIDE;
108 : virtual void DeselectHdl() SAL_OVERRIDE;
109 : // Window
110 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
111 :
112 : virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
113 : virtual void InitEntry(SvTreeListEntry* pEntry, const OUString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp, SvLBoxButtonKind eButtonKind) SAL_OVERRIDE;
114 :
115 : // enable editing for tables/views and queries
116 : virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& ) SAL_OVERRIDE;
117 : virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) SAL_OVERRIDE;
118 :
119 : virtual bool DoubleClickHdl() SAL_OVERRIDE;
120 :
121 : virtual PopupMenu* CreateContextMenu() SAL_OVERRIDE;
122 : virtual void ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) SAL_OVERRIDE;
123 :
124 3 : void SetEnterKeyHdl(const Link<>& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
125 :
126 6 : void clearCurrentSelection() { m_aSelectedEntries.clear(); }
127 :
128 : protected:
129 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
130 : virtual void RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
131 :
132 : // DragSourceHelper overridables
133 : virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) SAL_OVERRIDE;
134 : // DropTargetHelper overridables
135 : virtual sal_Int8 AcceptDrop( const AcceptDropEvent& _rEvt ) SAL_OVERRIDE;
136 : virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& _rEvt ) SAL_OVERRIDE;
137 :
138 : virtual void ModelHasRemoved( SvTreeListEntry* pEntry ) SAL_OVERRIDE;
139 : virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry ) SAL_OVERRIDE;
140 :
141 : void implStopSelectionTimer();
142 : void implStartSelectionTimer();
143 :
144 : protected:
145 : using SvTreeListBox::ExecuteDrop;
146 : };
147 : }
148 :
149 : #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|