1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef DBAUI_DBTREELISTBOX_HXX
24 #define DBAUI_DBTREELISTBOX_HXX
25 
26 #include "ScrollHelper.hxx"
27 #include "moduledbu.hxx"
28 
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 
31 #include <svtools/svtreebx.hxx>
32 #include <vcl/timer.hxx>
33 
34 #include <set>
35 
36 
37 namespace dbaui
38 {
39 	struct DBTreeEditedEntry
40 	{
41 		SvLBoxEntry*	pEntry;
42 		XubString		aNewText;
43 	};
44 
45     class IEntryFilter
46     {
47     public:
48         virtual bool    includeEntry( SvLBoxEntry* _pEntry ) const = 0;
49     };
50 
51 	//========================================================================
52 	class IControlActionListener;
53     class IContextMenuProvider;
54 	class DBTreeListBox		:public SvTreeListBox
55 	{
56 		OModuleClient               m_aModuleClient;
57 		OScrollHelper				m_aScrollHelper;
58 		Timer						m_aTimer; // is needed for table updates
59 		Point						m_aMousePos;
60         ::std::set< SvListEntry* >  m_aSelectedEntries;
61 		SvLBoxEntry*				m_pDragedEntry;
62 		IControlActionListener*		m_pActionListener;
63         IContextMenuProvider*
64                                     m_pContextMenuProvider;
65 
66 		Link						m_aPreExpandHandler;	// handler to be called before a node is expanded
67         Link                        m_aSelChangeHdl;        // handlet to be called (asynchronously) when the selection changes in any way
68 		Link						m_aCutHandler;			// called when someone press CTRL+X
69 		Link						m_aCopyHandler;			// called when someone press CTRL+C
70 		Link						m_aPasteHandler;		// called when someone press CTRL+V
71 		Link						m_aDeleteHandler;		// called when someone press DELETE Key
72 		Link						m_aEditingHandler;		// called before someone will edit an entry
73 		Link						m_aEditedHandler;		// called after someone edited an entry
74 		Link						m_aEnterKeyHdl;
75 
76 
77 		sal_Bool					m_bHandleEnterKey;
78 
79 	protected:
80 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xORB;
81 
82 	private:
83 		void init();
84 		DECL_LINK( OnTimeOut, void* );
85 		DECL_LINK( OnResetEntry, SvLBoxEntry* );
86 		DECL_LINK( ScrollUpHdl, SvTreeListBox* );
87 		DECL_LINK( ScrollDownHdl, SvTreeListBox* );
88 
89 	public:
90 		DBTreeListBox( Window* pParent
91 			,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
92 			,WinBits nWinStyle=0
93 			,sal_Bool _bHandleEnterKey = sal_False);
94 		DBTreeListBox( Window* pParent
95 			,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
96 			,const ResId& rResId
97 			,sal_Bool _bHandleEnterKey = sal_False);
98 		~DBTreeListBox();
99 
setControlActionListener(IControlActionListener * _pListener)100 		void					setControlActionListener( IControlActionListener* _pListener ) { m_pActionListener = _pListener; }
setContextMenuProvider(IContextMenuProvider * _pContextMenuProvider)101 		void			        setContextMenuProvider( IContextMenuProvider* _pContextMenuProvider ) { m_pContextMenuProvider = _pContextMenuProvider; }
102 
setORB(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _xORB)103 		inline void setORB(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB) { m_xORB = _xORB; }
104 
105 
SetPreExpandHandler(const Link & _rHdl)106 		void	SetPreExpandHandler(const Link& _rHdl)  { m_aPreExpandHandler = _rHdl; }
SetSelChangeHdl(const Link & _rHdl)107         void    SetSelChangeHdl( const Link& _rHdl )    { m_aSelChangeHdl = _rHdl; }
setCutHandler(const Link & _rHdl)108 		void	setCutHandler(const Link& _rHdl)	    { m_aCutHandler = _rHdl; }
setCopyHandler(const Link & _rHdl)109 		void	setCopyHandler(const Link& _rHdl)       { m_aCopyHandler = _rHdl; }
setPasteHandler(const Link & _rHdl)110 		void	setPasteHandler(const Link& _rHdl)      { m_aPasteHandler = _rHdl; }
setDeleteHandler(const Link & _rHdl)111 		void	setDeleteHandler(const Link& _rHdl)     { m_aDeleteHandler = _rHdl; }
setEditingHandler(const Link & _rHdl)112 		void	setEditingHandler(const Link& _rHdl)    { m_aEditingHandler = _rHdl; }
setEditedHandler(const Link & _rHdl)113 		void	setEditedHandler(const Link& _rHdl)     { m_aEditedHandler = _rHdl; }
114 
115 		// modified the given entry so that the expand handler is called whenever the entry is expanded
116 		// (normally, the expand handler is called only once)
117 		void			EnableExpandHandler(SvLBoxEntry* _pEntry);
118 
119 		SvLBoxEntry*	GetEntryPosByName( const String& aName, SvLBoxEntry* pStart = NULL, const IEntryFilter* _pFilter = NULL ) const;
120         virtual void	RequestingChilds( SvLBoxEntry* pParent );
121 		virtual void 	SelectHdl();
122 		virtual void 	DeselectHdl();
123 		// Window
124 		virtual void	KeyInput( const KeyEvent& rKEvt );
125 
126         virtual void    StateChanged( StateChangedType nStateChange );
127 		virtual void	InitEntry( SvLBoxEntry* pEntry, const XubString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp, SvLBoxButtonKind eButtonKind);
128 
129 		// enable editing for tables/views and queries
130 		virtual sal_Bool	EditingEntry( SvLBoxEntry* pEntry, Selection& );
131 		virtual sal_Bool	EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText );
132 
133 	    virtual sal_Bool 	DoubleClickHdl();
134 
135         virtual PopupMenu* CreateContextMenu( void );
136 		virtual void	ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry );
137 
SetEnterKeyHdl(const Link & rNewHdl)138 		void			SetEnterKeyHdl(const Link& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
139 
clearCurrentSelection()140         void            clearCurrentSelection() { m_aSelectedEntries.clear(); }
141 
142 	protected:
143 		virtual void		MouseButtonDown( const MouseEvent& rMEvt );
144         virtual void        RequestHelp( const HelpEvent& rHEvt );
145 
146 		// DragSourceHelper overridables
147 		virtual void		StartDrag( sal_Int8 nAction, const Point& rPosPixel );
148 		// DropTargetHelper overridables
149 		virtual sal_Int8	AcceptDrop( const AcceptDropEvent& _rEvt );
150 		virtual sal_Int8	ExecuteDrop( const ExecuteDropEvent& _rEvt );
151 
152 		virtual void 		ModelHasRemoved( SvListEntry* pEntry );
153 		virtual void 		ModelHasEntryInvalidated( SvListEntry* pEntry );
154 
155         void                implStopSelectionTimer();
156         void                implStartSelectionTimer();
157 
158     protected:
159         using SvTreeListBox::ExecuteDrop;
160 	};
161 }
162 
163 #endif // DBAUI_DBTREELISTBOX_HXX
164