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