xref: /AOO41X/main/dbaccess/source/ui/control/dbtreelistbox.cxx (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 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef DBAUI_DBTREELISTBOX_HXX
32*cdf0e10cSrcweir #include "dbtreelistbox.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #ifndef _DBU_RESOURCE_HRC_
35*cdf0e10cSrcweir #include "dbu_resource.hrc"
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
38*cdf0e10cSrcweir #include "browserids.hxx"
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #ifndef _DBAUI_LISTVIEWITEMS_HXX_
41*cdf0e10cSrcweir #include "listviewitems.hxx"
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #ifndef _DBACCESS_UI_CALLBACKS_HXX_
44*cdf0e10cSrcweir #include "callbacks.hxx"
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DATATRANSFER_DND_XDRAGGESTURELISTENER_HDL_
48*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDragGestureListener.hdl>
49*cdf0e10cSrcweir #endif
50*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DATATRANSFER_DND_XDRAGGESTURERECOGNIZER_HPP_
51*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp>
52*cdf0e10cSrcweir #endif
53*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_XCONTEXTMENUINTERCEPTOR_HPP_
54*cdf0e10cSrcweir #include <com/sun/star/ui/XContextMenuInterceptor.hpp>
55*cdf0e10cSrcweir #endif
56*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
57*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
58*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
59*cdf0e10cSrcweir #endif
60*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE1_HXX_
61*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
64*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
65*cdf0e10cSrcweir #endif
66*cdf0e10cSrcweir #ifndef _SV_HELP_HXX
67*cdf0e10cSrcweir #include <vcl/help.hxx>
68*cdf0e10cSrcweir #endif
69*cdf0e10cSrcweir #ifndef _DBAUI_TABLETREE_HRC_
70*cdf0e10cSrcweir #include "tabletree.hrc"
71*cdf0e10cSrcweir #endif
72*cdf0e10cSrcweir #ifndef DBAUI_ICONTROLLER_HXX
73*cdf0e10cSrcweir #include "IController.hxx"
74*cdf0e10cSrcweir #endif
75*cdf0e10cSrcweir #ifndef __FRAMEWORK_HELPER_ACTIONTRIGGERHELPER_HXX_
76*cdf0e10cSrcweir #include <framework/actiontriggerhelper.hxx>
77*cdf0e10cSrcweir #endif
78*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
79*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
80*cdf0e10cSrcweir #endif
81*cdf0e10cSrcweir #include <framework/imageproducer.hxx>
82*cdf0e10cSrcweir #include <vcl/svapp.hxx>
83*cdf0e10cSrcweir #include <memory>
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir // .........................................................................
86*cdf0e10cSrcweir namespace dbaui
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir // .........................................................................
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir using namespace ::com::sun::star;
91*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
92*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
93*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
94*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
95*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
96*cdf0e10cSrcweir using namespace ::com::sun::star::ui;
97*cdf0e10cSrcweir using namespace ::com::sun::star::view;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir DBG_NAME(DBTreeListBox)
100*cdf0e10cSrcweir #define SPACEBETWEENENTRIES		4
101*cdf0e10cSrcweir //========================================================================
102*cdf0e10cSrcweir // class DBTreeListBox
103*cdf0e10cSrcweir //========================================================================
104*cdf0e10cSrcweir //------------------------------------------------------------------------
105*cdf0e10cSrcweir DBTreeListBox::DBTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, WinBits nWinStyle ,sal_Bool _bHandleEnterKey)
106*cdf0e10cSrcweir 	:SvTreeListBox(pParent,nWinStyle)
107*cdf0e10cSrcweir 	,m_pDragedEntry(NULL)
108*cdf0e10cSrcweir 	,m_pActionListener(NULL)
109*cdf0e10cSrcweir 	,m_pContextMenuProvider( NULL )
110*cdf0e10cSrcweir 	,m_bHandleEnterKey(_bHandleEnterKey)
111*cdf0e10cSrcweir 	,m_xORB(_rxORB)
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	DBG_CTOR(DBTreeListBox,NULL);
114*cdf0e10cSrcweir 	init();
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir // -----------------------------------------------------------------------------
117*cdf0e10cSrcweir DBTreeListBox::DBTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, const ResId& rResId,sal_Bool _bHandleEnterKey)
118*cdf0e10cSrcweir 	:SvTreeListBox(pParent,rResId)
119*cdf0e10cSrcweir 	,m_pDragedEntry(NULL)
120*cdf0e10cSrcweir 	,m_pActionListener(NULL)
121*cdf0e10cSrcweir 	,m_pContextMenuProvider( NULL )
122*cdf0e10cSrcweir 	,m_bHandleEnterKey(_bHandleEnterKey)
123*cdf0e10cSrcweir 	,m_xORB(_rxORB)
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	DBG_CTOR(DBTreeListBox,NULL);
126*cdf0e10cSrcweir 	init();
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir // -----------------------------------------------------------------------------
129*cdf0e10cSrcweir void DBTreeListBox::init()
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir 	sal_uInt16 nSize = SPACEBETWEENENTRIES;
132*cdf0e10cSrcweir 	SetSpaceBetweenEntries(nSize);
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	m_aTimer.SetTimeout(900);
135*cdf0e10cSrcweir 	m_aTimer.SetTimeoutHdl(LINK(this, DBTreeListBox, OnTimeOut));
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	m_aScrollHelper.setUpScrollMethod( LINK(this, DBTreeListBox, ScrollUpHdl) );
138*cdf0e10cSrcweir 	m_aScrollHelper.setDownScrollMethod( LINK(this, DBTreeListBox, ScrollDownHdl) );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	SetNodeDefaultImages( );
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	EnableContextMenuHandling();
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     SetStyle( GetStyle() | WB_QUICK_SEARCH );
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir //------------------------------------------------------------------------
147*cdf0e10cSrcweir DBTreeListBox::~DBTreeListBox()
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	DBG_DTOR(DBTreeListBox,NULL);
150*cdf0e10cSrcweir     implStopSelectionTimer();
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir //------------------------------------------------------------------------
153*cdf0e10cSrcweir SvLBoxEntry* DBTreeListBox::GetEntryPosByName( const String& aName, SvLBoxEntry* pStart, const IEntryFilter* _pFilter ) const
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir 	SvLBoxTreeList*	myModel = GetModel();
156*cdf0e10cSrcweir 	SvTreeEntryList* pChilds = myModel->GetChildList(pStart);
157*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = NULL;
158*cdf0e10cSrcweir 	if ( pChilds )
159*cdf0e10cSrcweir 	{
160*cdf0e10cSrcweir 		sal_uLong nCount = pChilds->Count();
161*cdf0e10cSrcweir 		for (sal_uLong i=0; i < nCount; ++i)
162*cdf0e10cSrcweir 		{
163*cdf0e10cSrcweir 			pEntry = static_cast<SvLBoxEntry*>(pChilds->GetObject(i));
164*cdf0e10cSrcweir 			SvLBoxString* pItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
165*cdf0e10cSrcweir 			if ( pItem->GetText().Equals(aName) )
166*cdf0e10cSrcweir             {
167*cdf0e10cSrcweir                 if ( !_pFilter || _pFilter->includeEntry( pEntry ) )
168*cdf0e10cSrcweir                     // found
169*cdf0e10cSrcweir                     break;
170*cdf0e10cSrcweir             }
171*cdf0e10cSrcweir 			pEntry = NULL;
172*cdf0e10cSrcweir 		}
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	return pEntry;
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir // -------------------------------------------------------------------------
179*cdf0e10cSrcweir void DBTreeListBox::EnableExpandHandler(SvLBoxEntry* _pEntry)
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	LINK(this, DBTreeListBox, OnResetEntry).Call(_pEntry);
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir // -------------------------------------------------------------------------
185*cdf0e10cSrcweir void DBTreeListBox::RequestingChilds( SvLBoxEntry* pParent )
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir 	if (m_aPreExpandHandler.IsSet())
188*cdf0e10cSrcweir 	{
189*cdf0e10cSrcweir 		if (!m_aPreExpandHandler.Call(pParent))
190*cdf0e10cSrcweir 		{
191*cdf0e10cSrcweir 			// an error occured. The method calling us will reset the entry flags, so it can't be expanded again.
192*cdf0e10cSrcweir 			// But we want that the user may do a second try (i.e. because he misstypes a password in this try), so
193*cdf0e10cSrcweir 			// we have to reset these flags controlling the expand ability
194*cdf0e10cSrcweir 			PostUserEvent(LINK(this, DBTreeListBox, OnResetEntry), pParent);
195*cdf0e10cSrcweir 		}
196*cdf0e10cSrcweir 	}
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir // -------------------------------------------------------------------------
200*cdf0e10cSrcweir void DBTreeListBox::InitEntry( SvLBoxEntry* _pEntry, const XubString& aStr, const Image& _rCollEntryBmp, const Image& _rExpEntryBmp, SvLBoxButtonKind eButtonKind)
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir 	SvTreeListBox::InitEntry( _pEntry, aStr, _rCollEntryBmp,_rExpEntryBmp, eButtonKind);
203*cdf0e10cSrcweir 	SvLBoxItem* pTextItem(_pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
204*cdf0e10cSrcweir 	SvLBoxString* pString = new OBoldListboxString( _pEntry, 0, aStr );
205*cdf0e10cSrcweir 	_pEntry->ReplaceItem( pString,_pEntry->GetPos(pTextItem));
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir // -------------------------------------------------------------------------
209*cdf0e10cSrcweir void DBTreeListBox::implStopSelectionTimer()
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir 	if ( m_aTimer.IsActive() )
212*cdf0e10cSrcweir 		m_aTimer.Stop();
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir // -------------------------------------------------------------------------
216*cdf0e10cSrcweir void DBTreeListBox::implStartSelectionTimer()
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     implStopSelectionTimer();
219*cdf0e10cSrcweir 	m_aTimer.Start();
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir // -----------------------------------------------------------------------------
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir void DBTreeListBox::DeselectHdl()
225*cdf0e10cSrcweir {
226*cdf0e10cSrcweir     m_aSelectedEntries.erase( GetHdlEntry() );
227*cdf0e10cSrcweir     SvTreeListBox::DeselectHdl();
228*cdf0e10cSrcweir 	implStartSelectionTimer();
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir // -------------------------------------------------------------------------
231*cdf0e10cSrcweir void DBTreeListBox::SelectHdl()
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir     m_aSelectedEntries.insert( GetHdlEntry() );
234*cdf0e10cSrcweir     SvTreeListBox::SelectHdl();
235*cdf0e10cSrcweir 	implStartSelectionTimer();
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir // -------------------------------------------------------------------------
239*cdf0e10cSrcweir void DBTreeListBox::MouseButtonDown( const MouseEvent& rMEvt )
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir 	sal_Bool bHitEmptySpace = (NULL == GetEntry(rMEvt.GetPosPixel(), sal_True));
242*cdf0e10cSrcweir 	if (bHitEmptySpace && (rMEvt.GetClicks() == 2) && rMEvt.IsMod1())
243*cdf0e10cSrcweir 		Control::MouseButtonDown(rMEvt);
244*cdf0e10cSrcweir 	else
245*cdf0e10cSrcweir 		SvTreeListBox::MouseButtonDown(rMEvt);
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir // -------------------------------------------------------------------------
249*cdf0e10cSrcweir IMPL_LINK(DBTreeListBox, OnResetEntry, SvLBoxEntry*, pEntry)
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	// set the flag which allows if the entry can be expanded
252*cdf0e10cSrcweir 	pEntry->SetFlags( (pEntry->GetFlags() & ~(SV_ENTRYFLAG_NO_NODEBMP | SV_ENTRYFLAG_HAD_CHILDREN)) | SV_ENTRYFLAG_CHILDS_ON_DEMAND );
253*cdf0e10cSrcweir 	// redraw the entry
254*cdf0e10cSrcweir 	GetModel()->InvalidateEntry( pEntry );
255*cdf0e10cSrcweir 	return 0L;
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir // -----------------------------------------------------------------------------
258*cdf0e10cSrcweir void DBTreeListBox::ModelHasEntryInvalidated( SvListEntry* _pEntry )
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	SvTreeListBox::ModelHasEntryInvalidated( _pEntry );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     if ( m_aSelectedEntries.find( _pEntry ) != m_aSelectedEntries.end() )
263*cdf0e10cSrcweir 	{
264*cdf0e10cSrcweir 		SvLBoxItem* pTextItem = static_cast< SvLBoxEntry* >( _pEntry )->GetFirstItem( SV_ITEM_ID_BOLDLBSTRING );
265*cdf0e10cSrcweir 		if ( pTextItem && !static_cast< OBoldListboxString* >( pTextItem )->isEmphasized() )
266*cdf0e10cSrcweir 		{
267*cdf0e10cSrcweir             implStopSelectionTimer();
268*cdf0e10cSrcweir             m_aSelectedEntries.erase( _pEntry );
269*cdf0e10cSrcweir                 // ehm - why?
270*cdf0e10cSrcweir 		}
271*cdf0e10cSrcweir 	}
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir // -------------------------------------------------------------------------
274*cdf0e10cSrcweir void DBTreeListBox::ModelHasRemoved( SvListEntry* _pEntry )
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir 	SvTreeListBox::ModelHasRemoved(_pEntry);
277*cdf0e10cSrcweir     if ( m_aSelectedEntries.find( _pEntry ) != m_aSelectedEntries.end() )
278*cdf0e10cSrcweir 	{
279*cdf0e10cSrcweir         implStopSelectionTimer();
280*cdf0e10cSrcweir         m_aSelectedEntries.erase( _pEntry );
281*cdf0e10cSrcweir 	}
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir // -------------------------------------------------------------------------
285*cdf0e10cSrcweir sal_Int8 DBTreeListBox::AcceptDrop( const AcceptDropEvent& _rEvt )
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir 	sal_Int8 nDropOption = DND_ACTION_NONE;
288*cdf0e10cSrcweir 	if ( m_pActionListener )
289*cdf0e10cSrcweir 	{
290*cdf0e10cSrcweir 		SvLBoxEntry* pDroppedEntry = GetEntry(_rEvt.maPosPixel);
291*cdf0e10cSrcweir 		// check if drag is on child entry, which is not allowed
292*cdf0e10cSrcweir 		SvLBoxEntry* pParent = NULL;
293*cdf0e10cSrcweir 		if ( _rEvt.mnAction & DND_ACTION_MOVE )
294*cdf0e10cSrcweir 		{
295*cdf0e10cSrcweir 			if ( !m_pDragedEntry ) // no entry to move
296*cdf0e10cSrcweir 			{
297*cdf0e10cSrcweir 				nDropOption = m_pActionListener->queryDrop( _rEvt, GetDataFlavorExVector() );
298*cdf0e10cSrcweir 				m_aMousePos = _rEvt.maPosPixel;
299*cdf0e10cSrcweir 				m_aScrollHelper.scroll(m_aMousePos,GetOutputSizePixel());
300*cdf0e10cSrcweir 				return nDropOption;
301*cdf0e10cSrcweir 			}
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 			pParent = pDroppedEntry ? GetParent(pDroppedEntry) : NULL;
304*cdf0e10cSrcweir 			while ( pParent && pParent != m_pDragedEntry )
305*cdf0e10cSrcweir 				pParent = GetParent(pParent);
306*cdf0e10cSrcweir 		}
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 		if ( !pParent )
309*cdf0e10cSrcweir 		{
310*cdf0e10cSrcweir 			nDropOption = m_pActionListener->queryDrop( _rEvt, GetDataFlavorExVector() );
311*cdf0e10cSrcweir 			// check if move is allowed
312*cdf0e10cSrcweir 			if ( nDropOption & DND_ACTION_MOVE )
313*cdf0e10cSrcweir 			{
314*cdf0e10cSrcweir 				if ( m_pDragedEntry == pDroppedEntry || GetEntryPosByName(GetEntryText(m_pDragedEntry),pDroppedEntry) )
315*cdf0e10cSrcweir 					nDropOption = nDropOption & ~DND_ACTION_MOVE;//DND_ACTION_NONE;
316*cdf0e10cSrcweir 			}
317*cdf0e10cSrcweir 			m_aMousePos = _rEvt.maPosPixel;
318*cdf0e10cSrcweir 			m_aScrollHelper.scroll(m_aMousePos,GetOutputSizePixel());
319*cdf0e10cSrcweir 		}
320*cdf0e10cSrcweir 	}
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 	return nDropOption;
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir // -------------------------------------------------------------------------
326*cdf0e10cSrcweir sal_Int8 DBTreeListBox::ExecuteDrop( const ExecuteDropEvent& _rEvt )
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir 	if ( m_pActionListener )
329*cdf0e10cSrcweir 		return m_pActionListener->executeDrop( _rEvt );
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	return DND_ACTION_NONE;
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir // -------------------------------------------------------------------------
335*cdf0e10cSrcweir void DBTreeListBox::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	if ( m_pActionListener )
338*cdf0e10cSrcweir 	{
339*cdf0e10cSrcweir 		m_pDragedEntry = GetEntry(_rPosPixel);
340*cdf0e10cSrcweir 		if ( m_pDragedEntry && m_pActionListener->requestDrag( _nAction, _rPosPixel ) )
341*cdf0e10cSrcweir 		{
342*cdf0e10cSrcweir 			// if the (asynchronous) drag started, stop the selection timer
343*cdf0e10cSrcweir             implStopSelectionTimer();
344*cdf0e10cSrcweir 			// and stop selecting entries by simply moving the mouse
345*cdf0e10cSrcweir 			EndSelection();
346*cdf0e10cSrcweir 		}
347*cdf0e10cSrcweir 	}
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir // -------------------------------------------------------------------------
351*cdf0e10cSrcweir void DBTreeListBox::RequestHelp( const HelpEvent& rHEvt )
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir     if ( !m_pActionListener )
354*cdf0e10cSrcweir     {
355*cdf0e10cSrcweir         SvTreeListBox::RequestHelp( rHEvt );
356*cdf0e10cSrcweir         return;
357*cdf0e10cSrcweir     }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 	if( rHEvt.GetMode() & HELPMODE_QUICK )
360*cdf0e10cSrcweir 	{
361*cdf0e10cSrcweir 		Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
362*cdf0e10cSrcweir         SvLBoxEntry* pEntry = GetEntry( aPos );
363*cdf0e10cSrcweir 		if( pEntry )
364*cdf0e10cSrcweir 		{
365*cdf0e10cSrcweir             String sQuickHelpText;
366*cdf0e10cSrcweir             if ( m_pActionListener->requestQuickHelp( pEntry, sQuickHelpText ) )
367*cdf0e10cSrcweir             {
368*cdf0e10cSrcweir                 Size aSize( GetOutputSizePixel().Width(), GetEntryHeight() );
369*cdf0e10cSrcweir                 Rectangle aScreenRect( OutputToScreenPixel( GetEntryPosition( pEntry ) ), aSize );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir                 Help::ShowQuickHelp( this, aScreenRect,
372*cdf0e10cSrcweir 									 sQuickHelpText, QUICKHELP_LEFT | QUICKHELP_VCENTER );
373*cdf0e10cSrcweir                 return;
374*cdf0e10cSrcweir             }
375*cdf0e10cSrcweir         }
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir     SvTreeListBox::RequestHelp( rHEvt );
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir // -----------------------------------------------------------------------------
382*cdf0e10cSrcweir void DBTreeListBox::KeyInput( const KeyEvent& rKEvt )
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir 	KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction();
385*cdf0e10cSrcweir 	sal_uInt16		nCode = rKEvt.GetKeyCode().GetCode();
386*cdf0e10cSrcweir 	sal_Bool bHandled = sal_False;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 	if(eFunc != KEYFUNC_DONTKNOW)
389*cdf0e10cSrcweir 	{
390*cdf0e10cSrcweir 		switch(eFunc)
391*cdf0e10cSrcweir 		{
392*cdf0e10cSrcweir 			case KEYFUNC_CUT:
393*cdf0e10cSrcweir                 bHandled = ( m_aCutHandler.IsSet() && !m_aSelectedEntries.empty() );
394*cdf0e10cSrcweir 				if ( bHandled )
395*cdf0e10cSrcweir 					m_aCutHandler.Call( NULL );
396*cdf0e10cSrcweir 				break;
397*cdf0e10cSrcweir 			case KEYFUNC_COPY:
398*cdf0e10cSrcweir                 bHandled = ( m_aCopyHandler.IsSet() && !m_aSelectedEntries.empty() );
399*cdf0e10cSrcweir 				if ( bHandled )
400*cdf0e10cSrcweir 					m_aCopyHandler.Call( NULL );
401*cdf0e10cSrcweir 				break;
402*cdf0e10cSrcweir 			case KEYFUNC_PASTE:
403*cdf0e10cSrcweir                 bHandled = ( m_aPasteHandler.IsSet() && !m_aSelectedEntries.empty() );
404*cdf0e10cSrcweir 				if ( bHandled )
405*cdf0e10cSrcweir 					m_aPasteHandler.Call( NULL );
406*cdf0e10cSrcweir 				break;
407*cdf0e10cSrcweir 			case KEYFUNC_DELETE:
408*cdf0e10cSrcweir                 bHandled = ( m_aDeleteHandler.IsSet() && !m_aSelectedEntries.empty() );
409*cdf0e10cSrcweir 				if ( bHandled )
410*cdf0e10cSrcweir 					m_aDeleteHandler.Call( NULL );
411*cdf0e10cSrcweir 				break;
412*cdf0e10cSrcweir             default:
413*cdf0e10cSrcweir                 break;
414*cdf0e10cSrcweir 		}
415*cdf0e10cSrcweir 	}
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	if ( KEY_RETURN == nCode )
418*cdf0e10cSrcweir 	{
419*cdf0e10cSrcweir 		bHandled = m_bHandleEnterKey;
420*cdf0e10cSrcweir 		if ( m_aEnterKeyHdl.IsSet() )
421*cdf0e10cSrcweir 			m_aEnterKeyHdl.Call(this);
422*cdf0e10cSrcweir 		// this is a HACK. If the data source browser is opened in the "beamer", while the main frame
423*cdf0e10cSrcweir 		// contains a writer document, then pressing enter in the DSB would be rerouted to the writer
424*cdf0e10cSrcweir 		// document if we would not do this hack here.
425*cdf0e10cSrcweir 		// The problem is that the Writer uses RETURN as _accelerator_ (which is quite weird itself),
426*cdf0e10cSrcweir 		// so the SFX framework is _obligated_ to pass it to the Writer if nobody else handled it. There
427*cdf0e10cSrcweir 		// is no chance to distinguish between
428*cdf0e10cSrcweir 		//   "accelerators which are to be executed if the main document has the focus"
429*cdf0e10cSrcweir 		// and
430*cdf0e10cSrcweir 		//   "accelerators which are always to be executed"
431*cdf0e10cSrcweir 		//
432*cdf0e10cSrcweir 		// Thus we cannot prevent the handling of this key in the writer without declaring the key event
433*cdf0e10cSrcweir 		// as "handled" herein.
434*cdf0e10cSrcweir 		//
435*cdf0e10cSrcweir 		// The bad thing about this approach is that it does not scale. Every other accelerator which
436*cdf0e10cSrcweir 		// is used by the document will raise a similar bug once somebody discovers it.
437*cdf0e10cSrcweir 		// If this is the case, we should discuss a real solution with the framework (SFX) and the
438*cdf0e10cSrcweir 		// applications.
439*cdf0e10cSrcweir 		//
440*cdf0e10cSrcweir 		// 2002-12-02 - 105831 - fs@openoffice.org
441*cdf0e10cSrcweir 	}
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 	if ( !bHandled )
444*cdf0e10cSrcweir 		SvTreeListBox::KeyInput(rKEvt);
445*cdf0e10cSrcweir }
446*cdf0e10cSrcweir // -----------------------------------------------------------------------------
447*cdf0e10cSrcweir sal_Bool DBTreeListBox::EditingEntry( SvLBoxEntry* pEntry, Selection& /*_aSelection*/)
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir 	return m_aEditingHandler.Call(pEntry) != 0;
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir // -----------------------------------------------------------------------------
452*cdf0e10cSrcweir sal_Bool DBTreeListBox::EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText )
453*cdf0e10cSrcweir {
454*cdf0e10cSrcweir 	DBTreeEditedEntry aEntry;
455*cdf0e10cSrcweir 	aEntry.pEntry = pEntry;
456*cdf0e10cSrcweir 	aEntry.aNewText  =rNewText;
457*cdf0e10cSrcweir 	if(m_aEditedHandler.Call(&aEntry) != 0)
458*cdf0e10cSrcweir 	{
459*cdf0e10cSrcweir         implStopSelectionTimer();
460*cdf0e10cSrcweir         m_aSelectedEntries.erase( pEntry );
461*cdf0e10cSrcweir 	}
462*cdf0e10cSrcweir 	SetEntryText(pEntry,aEntry.aNewText);
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 	return sal_False;  // we never want that the base change our text
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir // -----------------------------------------------------------------------------
468*cdf0e10cSrcweir sal_Bool DBTreeListBox::DoubleClickHdl()
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir 	long nResult = aDoubleClickHdl.Call( this );
471*cdf0e10cSrcweir     // continue default processing if the DoubleClickHandler didn't handle it
472*cdf0e10cSrcweir     return nResult == 0;
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir // -----------------------------------------------------------------------------
476*cdf0e10cSrcweir void scrollWindow(DBTreeListBox* _pListBox, const Point& _rPos,sal_Bool _bUp)
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = _pListBox->GetEntry( _rPos );
479*cdf0e10cSrcweir 	if( pEntry && pEntry != _pListBox->Last() )
480*cdf0e10cSrcweir 	{
481*cdf0e10cSrcweir 		_pListBox->ScrollOutputArea( _bUp ? -1 : 1 );
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir }
484*cdf0e10cSrcweir // -----------------------------------------------------------------------------
485*cdf0e10cSrcweir IMPL_LINK( DBTreeListBox, ScrollUpHdl, SvTreeListBox*, /*pBox*/ )
486*cdf0e10cSrcweir {
487*cdf0e10cSrcweir 	scrollWindow(this,m_aMousePos,sal_True);
488*cdf0e10cSrcweir 	return 0;
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir //------------------------------------------------------------------------------
492*cdf0e10cSrcweir IMPL_LINK( DBTreeListBox, ScrollDownHdl, SvTreeListBox*, /*pBox*/ )
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir 	scrollWindow(this,m_aMousePos,sal_False);
495*cdf0e10cSrcweir 	return 0;
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir // -----------------------------------------------------------------------------
498*cdf0e10cSrcweir namespace
499*cdf0e10cSrcweir {
500*cdf0e10cSrcweir 	void lcl_enableEntries( PopupMenu* _pPopup, IController& _rController )
501*cdf0e10cSrcweir 	{
502*cdf0e10cSrcweir 		if ( !_pPopup )
503*cdf0e10cSrcweir 			return;
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 		sal_uInt16 nCount = _pPopup->GetItemCount();
506*cdf0e10cSrcweir 		for (sal_uInt16 i=0; i < nCount; ++i)
507*cdf0e10cSrcweir 		{
508*cdf0e10cSrcweir 			if ( _pPopup->GetItemType(i) != MENUITEM_SEPARATOR )
509*cdf0e10cSrcweir 			{
510*cdf0e10cSrcweir 				sal_uInt16 nId = _pPopup->GetItemId(i);
511*cdf0e10cSrcweir 				PopupMenu* pSubPopUp = _pPopup->GetPopupMenu(nId);
512*cdf0e10cSrcweir 				if ( pSubPopUp )
513*cdf0e10cSrcweir                 {
514*cdf0e10cSrcweir 					lcl_enableEntries( pSubPopUp, _rController );
515*cdf0e10cSrcweir                     _pPopup->EnableItem(nId,pSubPopUp->HasValidEntries());
516*cdf0e10cSrcweir                 }
517*cdf0e10cSrcweir 				else
518*cdf0e10cSrcweir                 {
519*cdf0e10cSrcweir                     ::rtl::OUString sCommandURL( _pPopup->GetItemCommand( nId ) );
520*cdf0e10cSrcweir                     bool bEnabled = ( sCommandURL.getLength() )
521*cdf0e10cSrcweir                                   ? _rController.isCommandEnabled( sCommandURL )
522*cdf0e10cSrcweir                                   : _rController.isCommandEnabled( nId );
523*cdf0e10cSrcweir 					_pPopup->EnableItem( nId, bEnabled );
524*cdf0e10cSrcweir                 }
525*cdf0e10cSrcweir 			}
526*cdf0e10cSrcweir 		}
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 		_pPopup->RemoveDisabledEntries();
529*cdf0e10cSrcweir 	}
530*cdf0e10cSrcweir }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir // -----------------------------------------------------------------------------
533*cdf0e10cSrcweir namespace
534*cdf0e10cSrcweir {
535*cdf0e10cSrcweir     void lcl_adjustMenuItemIDs( Menu& _rMenu, IController& _rCommandController )
536*cdf0e10cSrcweir     {
537*cdf0e10cSrcweir 	    sal_uInt16 nCount = _rMenu.GetItemCount();
538*cdf0e10cSrcweir 	    for ( sal_uInt16 pos = 0; pos < nCount; ++pos )
539*cdf0e10cSrcweir 	    {
540*cdf0e10cSrcweir             // do not adjust separators
541*cdf0e10cSrcweir             if ( _rMenu.GetItemType( pos ) == MENUITEM_SEPARATOR )
542*cdf0e10cSrcweir                 continue;
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir 		    sal_uInt16 nId = _rMenu.GetItemId(pos);
545*cdf0e10cSrcweir 			String aCommand = _rMenu.GetItemCommand( nId );
546*cdf0e10cSrcweir 		    PopupMenu* pPopup = _rMenu.GetPopupMenu( nId );
547*cdf0e10cSrcweir 		    if ( pPopup )
548*cdf0e10cSrcweir 		    {
549*cdf0e10cSrcweir 			    lcl_adjustMenuItemIDs( *pPopup, _rCommandController );
550*cdf0e10cSrcweir                 continue;
551*cdf0e10cSrcweir 		    } // if ( pPopup )
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir             const sal_uInt16 nCommandId = _rCommandController.registerCommandURL( aCommand );
554*cdf0e10cSrcweir 		    _rMenu.InsertItem( nCommandId, _rMenu.GetItemText( nId ), _rMenu.GetItemImage( nId ),
555*cdf0e10cSrcweir                 _rMenu.GetItemBits( nId ), pos );
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir             // more things to preserve:
558*cdf0e10cSrcweir             // - the help command
559*cdf0e10cSrcweir             ::rtl::OUString sHelpURL = _rMenu.GetHelpCommand( nId );
560*cdf0e10cSrcweir             if ( sHelpURL.getLength() )
561*cdf0e10cSrcweir                 _rMenu.SetHelpCommand(  nCommandId, sHelpURL  );
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir             // remove the "old" item
564*cdf0e10cSrcweir             _rMenu.RemoveItem( pos+1 );
565*cdf0e10cSrcweir 	    }
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir     void lcl_insertMenuItemImages( Menu& _rMenu, IController& _rCommandController )
568*cdf0e10cSrcweir     {
569*cdf0e10cSrcweir         const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
570*cdf0e10cSrcweir         const sal_Bool bHiContrast = rSettings.GetHighContrastMode();
571*cdf0e10cSrcweir         uno::Reference< frame::XController > xController = _rCommandController.getXController();
572*cdf0e10cSrcweir         uno::Reference< frame::XFrame> xFrame;
573*cdf0e10cSrcweir         if ( xController.is() )
574*cdf0e10cSrcweir             xFrame = xController->getFrame();
575*cdf0e10cSrcweir 	    sal_uInt16 nCount = _rMenu.GetItemCount();
576*cdf0e10cSrcweir 	    for ( sal_uInt16 pos = 0; pos < nCount; ++pos )
577*cdf0e10cSrcweir 	    {
578*cdf0e10cSrcweir             // do not adjust separators
579*cdf0e10cSrcweir             if ( _rMenu.GetItemType( pos ) == MENUITEM_SEPARATOR )
580*cdf0e10cSrcweir                 continue;
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir 		    sal_uInt16 nId = _rMenu.GetItemId(pos);
583*cdf0e10cSrcweir 			String aCommand = _rMenu.GetItemCommand( nId );
584*cdf0e10cSrcweir 		    PopupMenu* pPopup = _rMenu.GetPopupMenu( nId );
585*cdf0e10cSrcweir 		    if ( pPopup )
586*cdf0e10cSrcweir 		    {
587*cdf0e10cSrcweir 			    lcl_insertMenuItemImages( *pPopup, _rCommandController );
588*cdf0e10cSrcweir                 continue;
589*cdf0e10cSrcweir 		    } // if ( pPopup )
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir             if ( xFrame.is() )
592*cdf0e10cSrcweir                 _rMenu.SetItemImage(nId,framework::GetImageFromURL(xFrame,aCommand,sal_False,bHiContrast));
593*cdf0e10cSrcweir 	    }
594*cdf0e10cSrcweir     }
595*cdf0e10cSrcweir     // =========================================================================
596*cdf0e10cSrcweir     // = SelectionSupplier
597*cdf0e10cSrcweir     // =========================================================================
598*cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper1 <   XSelectionSupplier
599*cdf0e10cSrcweir                                     >   SelectionSupplier_Base;
600*cdf0e10cSrcweir     class SelectionSupplier : public SelectionSupplier_Base
601*cdf0e10cSrcweir     {
602*cdf0e10cSrcweir     public:
603*cdf0e10cSrcweir         SelectionSupplier( const Any& _rSelection )
604*cdf0e10cSrcweir             :m_aSelection( _rSelection )
605*cdf0e10cSrcweir         {
606*cdf0e10cSrcweir         }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL select( const Any& xSelection ) throw (IllegalArgumentException, RuntimeException);
609*cdf0e10cSrcweir         virtual Any SAL_CALL getSelection(  ) throw (RuntimeException);
610*cdf0e10cSrcweir         virtual void SAL_CALL addSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException);
611*cdf0e10cSrcweir         virtual void SAL_CALL removeSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException);
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir     protected:
614*cdf0e10cSrcweir         virtual ~SelectionSupplier()
615*cdf0e10cSrcweir         {
616*cdf0e10cSrcweir         }
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir     private:
619*cdf0e10cSrcweir         Any m_aSelection;
620*cdf0e10cSrcweir     };
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir     //--------------------------------------------------------------------
623*cdf0e10cSrcweir     ::sal_Bool SAL_CALL SelectionSupplier::select( const Any& /*_Selection*/ ) throw (IllegalArgumentException, RuntimeException)
624*cdf0e10cSrcweir     {
625*cdf0e10cSrcweir         throw IllegalArgumentException();
626*cdf0e10cSrcweir         // API bug: this should be a NoSupportException
627*cdf0e10cSrcweir     }
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir     //--------------------------------------------------------------------
630*cdf0e10cSrcweir     Any SAL_CALL SelectionSupplier::getSelection(  ) throw (RuntimeException)
631*cdf0e10cSrcweir     {
632*cdf0e10cSrcweir         return m_aSelection;
633*cdf0e10cSrcweir     }
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir     //--------------------------------------------------------------------
636*cdf0e10cSrcweir     void SAL_CALL SelectionSupplier::addSelectionChangeListener( const Reference< XSelectionChangeListener >& /*_Listener*/ ) throw (RuntimeException)
637*cdf0e10cSrcweir     {
638*cdf0e10cSrcweir         OSL_ENSURE( false, "SelectionSupplier::removeSelectionChangeListener: no support!" );
639*cdf0e10cSrcweir         // API bug: this should be a NoSupportException
640*cdf0e10cSrcweir     }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir     //--------------------------------------------------------------------
643*cdf0e10cSrcweir     void SAL_CALL SelectionSupplier::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& /*_Listener*/ ) throw (RuntimeException)
644*cdf0e10cSrcweir     {
645*cdf0e10cSrcweir         OSL_ENSURE( false, "SelectionSupplier::removeSelectionChangeListener: no support!" );
646*cdf0e10cSrcweir         // API bug: this should be a NoSupportException
647*cdf0e10cSrcweir     }
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir // -----------------------------------------------------------------------------
651*cdf0e10cSrcweir PopupMenu* DBTreeListBox::CreateContextMenu( void )
652*cdf0e10cSrcweir {
653*cdf0e10cSrcweir     ::std::auto_ptr< PopupMenu > pContextMenu;
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 	if ( !m_pContextMenuProvider )
656*cdf0e10cSrcweir         return pContextMenu.release();
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir     // the basic context menu
659*cdf0e10cSrcweir 	pContextMenu.reset( m_pContextMenuProvider->getContextMenu( *this ) );
660*cdf0e10cSrcweir     // disable what is not available currently
661*cdf0e10cSrcweir 	lcl_enableEntries( pContextMenu.get(), m_pContextMenuProvider->getCommandController() );
662*cdf0e10cSrcweir 	// set images
663*cdf0e10cSrcweir     lcl_insertMenuItemImages( *pContextMenu, m_pContextMenuProvider->getCommandController() );
664*cdf0e10cSrcweir     // allow context menu interception
665*cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pInterceptors = m_pContextMenuProvider->getContextMenuInterceptors();
666*cdf0e10cSrcweir     if ( !pInterceptors || !pInterceptors->getLength() )
667*cdf0e10cSrcweir         return pContextMenu.release();
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir     ContextMenuExecuteEvent aEvent;
670*cdf0e10cSrcweir     aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
671*cdf0e10cSrcweir     aEvent.ExecutePosition.X = -1;
672*cdf0e10cSrcweir     aEvent.ExecutePosition.Y = -1;
673*cdf0e10cSrcweir     aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
674*cdf0e10cSrcweir         m_xORB, pContextMenu.get(), 0 );
675*cdf0e10cSrcweir     aEvent.Selection = new SelectionSupplier( m_pContextMenuProvider->getCurrentSelection( *this ) );
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir     ::cppu::OInterfaceIteratorHelper aIter( *pInterceptors );
678*cdf0e10cSrcweir     bool bModifiedMenu = false;
679*cdf0e10cSrcweir     bool bAskInterceptors = true;
680*cdf0e10cSrcweir     while ( aIter.hasMoreElements() && bAskInterceptors )
681*cdf0e10cSrcweir     {
682*cdf0e10cSrcweir         Reference< XContextMenuInterceptor > xInterceptor( aIter.next(), UNO_QUERY );
683*cdf0e10cSrcweir         if ( !xInterceptor.is() )
684*cdf0e10cSrcweir             continue;
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir         try
687*cdf0e10cSrcweir         {
688*cdf0e10cSrcweir             ContextMenuInterceptorAction eAction = xInterceptor->notifyContextMenuExecute( aEvent );
689*cdf0e10cSrcweir             switch ( eAction )
690*cdf0e10cSrcweir             {
691*cdf0e10cSrcweir                 case ContextMenuInterceptorAction_CANCELLED:
692*cdf0e10cSrcweir                     return NULL;
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir                 case ContextMenuInterceptorAction_EXECUTE_MODIFIED:
695*cdf0e10cSrcweir                     bModifiedMenu = true;
696*cdf0e10cSrcweir                     bAskInterceptors = false;
697*cdf0e10cSrcweir                     break;
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir                 case ContextMenuInterceptorAction_CONTINUE_MODIFIED:
700*cdf0e10cSrcweir                     bModifiedMenu = true;
701*cdf0e10cSrcweir                     bAskInterceptors = true;
702*cdf0e10cSrcweir                     break;
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir                 default:
705*cdf0e10cSrcweir                     DBG_ERROR( "DBTreeListBox::CreateContextMenu: unexpected return value of the interceptor call!" );
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir                 case ContextMenuInterceptorAction_IGNORED:
708*cdf0e10cSrcweir                     break;
709*cdf0e10cSrcweir             }
710*cdf0e10cSrcweir         }
711*cdf0e10cSrcweir         catch( const DisposedException& e )
712*cdf0e10cSrcweir         {
713*cdf0e10cSrcweir             if ( e.Context == xInterceptor )
714*cdf0e10cSrcweir                 aIter.remove();
715*cdf0e10cSrcweir         }
716*cdf0e10cSrcweir     }
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir     if ( bModifiedMenu )
719*cdf0e10cSrcweir     {
720*cdf0e10cSrcweir         // the interceptor(s) modified the menu description => create a new PopupMenu
721*cdf0e10cSrcweir         PopupMenu* pModifiedMenu = new PopupMenu;
722*cdf0e10cSrcweir         ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(
723*cdf0e10cSrcweir             pModifiedMenu, aEvent.ActionTriggerContainer );
724*cdf0e10cSrcweir         aEvent.ActionTriggerContainer.clear();
725*cdf0e10cSrcweir         pContextMenu.reset( pModifiedMenu );
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir         // the interceptors only know command URLs, but our menus primarily work
728*cdf0e10cSrcweir         // with IDs -> we need to translate the commands to IDs
729*cdf0e10cSrcweir         lcl_adjustMenuItemIDs( *pModifiedMenu, m_pContextMenuProvider->getCommandController() );
730*cdf0e10cSrcweir     } // if ( bModifiedMenu )
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir     return pContextMenu.release();
733*cdf0e10cSrcweir }
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir // -----------------------------------------------------------------------------
736*cdf0e10cSrcweir void DBTreeListBox::ExcecuteContextMenuAction( sal_uInt16 _nSelectedPopupEntry )
737*cdf0e10cSrcweir {
738*cdf0e10cSrcweir 	if ( m_pContextMenuProvider && _nSelectedPopupEntry )
739*cdf0e10cSrcweir 		m_pContextMenuProvider->getCommandController().executeChecked( _nSelectedPopupEntry, Sequence< PropertyValue >() );
740*cdf0e10cSrcweir }
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir // -----------------------------------------------------------------------------
743*cdf0e10cSrcweir IMPL_LINK(DBTreeListBox, OnTimeOut, void*, /*EMPTY_ARG*/)
744*cdf0e10cSrcweir {
745*cdf0e10cSrcweir     implStopSelectionTimer();
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir     m_aSelChangeHdl.Call( NULL );
748*cdf0e10cSrcweir 	return 0L;
749*cdf0e10cSrcweir }
750*cdf0e10cSrcweir // -----------------------------------------------------------------------------
751*cdf0e10cSrcweir void DBTreeListBox::StateChanged( StateChangedType nStateChange )
752*cdf0e10cSrcweir {
753*cdf0e10cSrcweir     if ( nStateChange == STATE_CHANGE_VISIBLE )
754*cdf0e10cSrcweir         implStopSelectionTimer();
755*cdf0e10cSrcweir }
756*cdf0e10cSrcweir // .........................................................................
757*cdf0e10cSrcweir }	// namespace dbaui
758*cdf0e10cSrcweir // .........................................................................
759