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