xref: /trunk/main/dbaccess/source/ui/inc/dbtreelistbox.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #ifndef DBAUI_DBTREELISTBOX_HXX
28*cdf0e10cSrcweir #define DBAUI_DBTREELISTBOX_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "ScrollHelper.hxx"
31*cdf0e10cSrcweir #include "moduledbu.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
36*cdf0e10cSrcweir #include <vcl/timer.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <set>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir namespace dbaui
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir     struct DBTreeEditedEntry
44*cdf0e10cSrcweir     {
45*cdf0e10cSrcweir         SvLBoxEntry*    pEntry;
46*cdf0e10cSrcweir         XubString       aNewText;
47*cdf0e10cSrcweir     };
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     class IEntryFilter
50*cdf0e10cSrcweir     {
51*cdf0e10cSrcweir     public:
52*cdf0e10cSrcweir         virtual bool    includeEntry( SvLBoxEntry* _pEntry ) const = 0;
53*cdf0e10cSrcweir     };
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     //========================================================================
56*cdf0e10cSrcweir     class IControlActionListener;
57*cdf0e10cSrcweir     class IContextMenuProvider;
58*cdf0e10cSrcweir     class DBTreeListBox     :public SvTreeListBox
59*cdf0e10cSrcweir     {
60*cdf0e10cSrcweir         OModuleClient               m_aModuleClient;
61*cdf0e10cSrcweir         OScrollHelper               m_aScrollHelper;
62*cdf0e10cSrcweir         Timer                       m_aTimer; // is needed for table updates
63*cdf0e10cSrcweir         Point                       m_aMousePos;
64*cdf0e10cSrcweir         ::std::set< SvListEntry* >  m_aSelectedEntries;
65*cdf0e10cSrcweir         SvLBoxEntry*                m_pDragedEntry;
66*cdf0e10cSrcweir         IControlActionListener*     m_pActionListener;
67*cdf0e10cSrcweir         IContextMenuProvider*
68*cdf0e10cSrcweir                                     m_pContextMenuProvider;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir         Link                        m_aPreExpandHandler;    // handler to be called before a node is expanded
71*cdf0e10cSrcweir         Link                        m_aSelChangeHdl;        // handlet to be called (asynchronously) when the selection changes in any way
72*cdf0e10cSrcweir         Link                        m_aCutHandler;          // called when someone press CTRL+X
73*cdf0e10cSrcweir         Link                        m_aCopyHandler;         // called when someone press CTRL+C
74*cdf0e10cSrcweir         Link                        m_aPasteHandler;        // called when someone press CTRL+V
75*cdf0e10cSrcweir         Link                        m_aDeleteHandler;       // called when someone press DELETE Key
76*cdf0e10cSrcweir         Link                        m_aEditingHandler;      // called before someone will edit an entry
77*cdf0e10cSrcweir         Link                        m_aEditedHandler;       // called after someone edited an entry
78*cdf0e10cSrcweir         Link                        m_aEnterKeyHdl;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir         sal_Bool                    m_bHandleEnterKey;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     protected:
84*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xORB;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     private:
87*cdf0e10cSrcweir         void init();
88*cdf0e10cSrcweir         DECL_LINK( OnTimeOut, void* );
89*cdf0e10cSrcweir         DECL_LINK( OnResetEntry, SvLBoxEntry* );
90*cdf0e10cSrcweir         DECL_LINK( ScrollUpHdl, SvTreeListBox* );
91*cdf0e10cSrcweir         DECL_LINK( ScrollDownHdl, SvTreeListBox* );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     public:
94*cdf0e10cSrcweir         DBTreeListBox( Window* pParent
95*cdf0e10cSrcweir             ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
96*cdf0e10cSrcweir             ,WinBits nWinStyle=0
97*cdf0e10cSrcweir             ,sal_Bool _bHandleEnterKey = sal_False);
98*cdf0e10cSrcweir         DBTreeListBox( Window* pParent
99*cdf0e10cSrcweir             ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
100*cdf0e10cSrcweir             ,const ResId& rResId
101*cdf0e10cSrcweir             ,sal_Bool _bHandleEnterKey = sal_False);
102*cdf0e10cSrcweir         ~DBTreeListBox();
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir         void                    setControlActionListener( IControlActionListener* _pListener ) { m_pActionListener = _pListener; }
105*cdf0e10cSrcweir         void                    setContextMenuProvider( IContextMenuProvider* _pContextMenuProvider ) { m_pContextMenuProvider = _pContextMenuProvider; }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         inline void setORB(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB) { m_xORB = _xORB; }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         void    SetPreExpandHandler(const Link& _rHdl)  { m_aPreExpandHandler = _rHdl; }
111*cdf0e10cSrcweir         void    SetSelChangeHdl( const Link& _rHdl )    { m_aSelChangeHdl = _rHdl; }
112*cdf0e10cSrcweir         void    setCutHandler(const Link& _rHdl)        { m_aCutHandler = _rHdl; }
113*cdf0e10cSrcweir         void    setCopyHandler(const Link& _rHdl)       { m_aCopyHandler = _rHdl; }
114*cdf0e10cSrcweir         void    setPasteHandler(const Link& _rHdl)      { m_aPasteHandler = _rHdl; }
115*cdf0e10cSrcweir         void    setDeleteHandler(const Link& _rHdl)     { m_aDeleteHandler = _rHdl; }
116*cdf0e10cSrcweir         void    setEditingHandler(const Link& _rHdl)    { m_aEditingHandler = _rHdl; }
117*cdf0e10cSrcweir         void    setEditedHandler(const Link& _rHdl)     { m_aEditedHandler = _rHdl; }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         // modified the given entry so that the expand handler is called whenever the entry is expanded
120*cdf0e10cSrcweir         // (normally, the expand handler is called only once)
121*cdf0e10cSrcweir         void            EnableExpandHandler(SvLBoxEntry* _pEntry);
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir         SvLBoxEntry*    GetEntryPosByName( const String& aName, SvLBoxEntry* pStart = NULL, const IEntryFilter* _pFilter = NULL ) const;
124*cdf0e10cSrcweir         virtual void    RequestingChilds( SvLBoxEntry* pParent );
125*cdf0e10cSrcweir         virtual void    SelectHdl();
126*cdf0e10cSrcweir         virtual void    DeselectHdl();
127*cdf0e10cSrcweir         // Window
128*cdf0e10cSrcweir         virtual void    KeyInput( const KeyEvent& rKEvt );
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         virtual void    StateChanged( StateChangedType nStateChange );
131*cdf0e10cSrcweir         virtual void    InitEntry( SvLBoxEntry* pEntry, const XubString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp, SvLBoxButtonKind eButtonKind);
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         // enable editing for tables/views and queries
134*cdf0e10cSrcweir         virtual sal_Bool    EditingEntry( SvLBoxEntry* pEntry, Selection& );
135*cdf0e10cSrcweir         virtual sal_Bool    EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         virtual sal_Bool    DoubleClickHdl();
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         virtual PopupMenu* CreateContextMenu( void );
140*cdf0e10cSrcweir         virtual void    ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry );
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         void            SetEnterKeyHdl(const Link& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         void            clearCurrentSelection() { m_aSelectedEntries.clear(); }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     protected:
147*cdf0e10cSrcweir         virtual void        MouseButtonDown( const MouseEvent& rMEvt );
148*cdf0e10cSrcweir         virtual void        RequestHelp( const HelpEvent& rHEvt );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         // DragSourceHelper overridables
151*cdf0e10cSrcweir         virtual void        StartDrag( sal_Int8 nAction, const Point& rPosPixel );
152*cdf0e10cSrcweir         // DropTargetHelper overridables
153*cdf0e10cSrcweir         virtual sal_Int8    AcceptDrop( const AcceptDropEvent& _rEvt );
154*cdf0e10cSrcweir         virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& _rEvt );
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir         virtual void        ModelHasRemoved( SvListEntry* pEntry );
157*cdf0e10cSrcweir         virtual void        ModelHasEntryInvalidated( SvListEntry* pEntry );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         void                implStopSelectionTimer();
160*cdf0e10cSrcweir         void                implStartSelectionTimer();
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     protected:
163*cdf0e10cSrcweir         using SvTreeListBox::ExecuteDrop;
164*cdf0e10cSrcweir     };
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir #endif // DBAUI_DBTREELISTBOX_HXX
168