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 4 : class IEntryFilter
41 : {
42 : public:
43 : virtual bool includeEntry( SvTreeListEntry* _pEntry ) const = 0;
44 :
45 : protected:
46 4 : ~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( OnTimeOut, 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 :
88 8 : void setControlActionListener( IControlActionListener* _pListener ) { m_pActionListener = _pListener; }
89 8 : void setContextMenuProvider( IContextMenuProvider* _pContextMenuProvider ) { m_pContextMenuProvider = _pContextMenuProvider; }
90 :
91 2 : void SetPreExpandHandler(const Link& _rHdl) { m_aPreExpandHandler = _rHdl; }
92 8 : void SetSelChangeHdl( const Link& _rHdl ) { m_aSelChangeHdl = _rHdl; }
93 6 : void setCutHandler(const Link& _rHdl) { m_aCutHandler = _rHdl; }
94 8 : void setCopyHandler(const Link& _rHdl) { m_aCopyHandler = _rHdl; }
95 6 : void setPasteHandler(const Link& _rHdl) { m_aPasteHandler = _rHdl; }
96 6 : void setDeleteHandler(const Link& _rHdl) { m_aDeleteHandler = _rHdl; }
97 : void setEditingHandler(const Link& _rHdl) { m_aEditingHandler = _rHdl; }
98 : void setEditedHandler(const Link& _rHdl) { m_aEditedHandler = _rHdl; }
99 :
100 : // modified the given entry so that the expand handler is called whenever the entry is expanded
101 : // (normally, the expand handler is called only once)
102 : void EnableExpandHandler(SvTreeListEntry* _pEntry);
103 :
104 : SvTreeListEntry* GetEntryPosByName( const OUString& aName, SvTreeListEntry* pStart = NULL, const IEntryFilter* _pFilter = NULL ) const;
105 : virtual void RequestingChildren( SvTreeListEntry* pParent ) SAL_OVERRIDE;
106 : virtual void SelectHdl() SAL_OVERRIDE;
107 : virtual void DeselectHdl() SAL_OVERRIDE;
108 : // Window
109 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
110 :
111 : virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
112 : virtual void InitEntry(SvTreeListEntry* pEntry, const OUString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp, SvLBoxButtonKind eButtonKind) SAL_OVERRIDE;
113 :
114 : // enable editing for tables/views and queries
115 : virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& ) SAL_OVERRIDE;
116 : virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) SAL_OVERRIDE;
117 :
118 : virtual bool DoubleClickHdl() SAL_OVERRIDE;
119 :
120 : virtual PopupMenu* CreateContextMenu( void ) SAL_OVERRIDE;
121 : virtual void ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) SAL_OVERRIDE;
122 :
123 6 : void SetEnterKeyHdl(const Link& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
124 :
125 12 : void clearCurrentSelection() { m_aSelectedEntries.clear(); }
126 :
127 : protected:
128 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
129 : virtual void RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
130 :
131 : // DragSourceHelper overridables
132 : virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) SAL_OVERRIDE;
133 : // DropTargetHelper overridables
134 : virtual sal_Int8 AcceptDrop( const AcceptDropEvent& _rEvt ) SAL_OVERRIDE;
135 : virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& _rEvt ) SAL_OVERRIDE;
136 :
137 : virtual void ModelHasRemoved( SvTreeListEntry* pEntry ) SAL_OVERRIDE;
138 : virtual void ModelHasEntryInvalidated( SvTreeListEntry* pEntry ) SAL_OVERRIDE;
139 :
140 : void implStopSelectionTimer();
141 : void implStartSelectionTimer();
142 :
143 : protected:
144 : using SvTreeListBox::ExecuteDrop;
145 : };
146 : }
147 :
148 : #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_DBTREELISTBOX_HXX
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|