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