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