1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableWindowListBox.cxx,v $
10 * $Revision: 1.35.26.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
34 #include "TableWindowListBox.hxx"
36 #ifndef DBAUI_TABLEWINDOW_HXX
37 #include "TableWindow.hxx"
39 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
40 #include "QueryDesignView.hxx"
42 #ifndef DBAUI_QUERYTABLEVIEW_HXX
43 #include "QueryTableView.hxx"
45 #ifndef DBAUI_QUERYCONTROLLER_HXX
46 #include "querycontroller.hxx"
48 #ifndef DBAUI_JOINEXCHANGE_HXX
49 #include "JoinExchange.hxx"
51 #ifndef _TOOLS_DEBUG_HXX
52 #include <tools/debug.hxx>
54 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
55 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
57 #ifndef _SVX_DBEXCH_HRC
58 #include <svx/dbexch.hrc>
61 #include <vcl/svapp.hxx>
64 using namespace dbaui
;
65 using namespace ::com::sun::star::sdbc
;
66 using namespace ::com::sun::star::uno
;
67 using namespace ::com::sun::star::datatransfer
;
69 OJoinExchangeData::OJoinExchangeData(OTableWindowListBox
* pBox
)
71 , pEntry(pBox
->FirstSelected())
74 const ULONG SCROLLING_TIMESPAN
= 500;
75 const long LISTBOX_SCROLLING_AREA
= 6;
76 //==================================================================
77 // class OTableWindowListBox
78 //==================================================================
79 DBG_NAME(OTableWindowListBox
)
80 //------------------------------------------------------------------------------
81 OTableWindowListBox::OTableWindowListBox( OTableWindow
* pParent
)
82 :SvTreeListBox( pParent
, WB_HASBUTTONS
| WB_BORDER
)
83 ,m_aMousePos( Point(0,0) )
87 ,m_bReallyScrolled( sal_False
)
89 DBG_CTOR(OTableWindowListBox
,NULL
);
90 m_aScrollTimer
.SetTimeout( SCROLLING_TIMESPAN
);
91 SetDoubleClickHdl( LINK(this, OTableWindowListBox
, OnDoubleClick
) );
93 SetSelectionMode(SINGLE_SELECTION
);
98 //------------------------------------------------------------------------------
99 void OTableWindowListBox::dragFinished( )
101 // first show the error msg when existing
102 m_pTabWin
->getDesignView()->getController().showError(m_pTabWin
->getDesignView()->getController().clearOccuredError());
103 // second look for ui activities which should happen after d&d
105 Application::RemoveUserEvent(m_nUiEvent
);
106 m_nUiEvent
= Application::PostUserEvent(LINK(this, OTableWindowListBox
, LookForUiHdl
));
109 //------------------------------------------------------------------------------
110 OTableWindowListBox::~OTableWindowListBox()
112 DBG_DTOR(OTableWindowListBox
,NULL
);
114 Application::RemoveUserEvent(m_nDropEvent
);
116 Application::RemoveUserEvent(m_nUiEvent
);
117 if( m_aScrollTimer
.IsActive() )
118 m_aScrollTimer
.Stop();
122 //------------------------------------------------------------------------------
123 SvLBoxEntry
* OTableWindowListBox::GetEntryFromText( const String
& rEntryText
)
125 //////////////////////////////////////////////////////////////////////
126 // Liste durchiterieren
127 SvTreeList
* pTreeList
= GetModel();
128 SvLBoxEntry
* pEntry
= (SvLBoxEntry
*)pTreeList
->First();
129 OJoinDesignView
* pView
= m_pTabWin
->getDesignView();
130 OJoinController
& rController
= pView
->getController();
135 Reference
<XConnection
> xConnection
= rController
.getConnection();
138 Reference
<XDatabaseMetaData
> xMeta
= xConnection
->getMetaData();
140 bCase
= xMeta
->supportsMixedCaseQuotedIdentifiers();
144 if((bCase
? rEntryText
== GetEntryText(pEntry
) : rEntryText
.EqualsIgnoreCaseAscii(GetEntryText(pEntry
))))
148 pEntry
= (SvLBoxEntry
*)pTreeList
->Next( pEntry
);
158 //------------------------------------------------------------------------------
159 void OTableWindowListBox::NotifyScrolled()
161 m_bReallyScrolled
= TRUE
;
164 //------------------------------------------------------------------------------
165 void OTableWindowListBox::NotifyEndScroll()
167 if (m_bReallyScrolled
)
168 // die Verbindungen, die diese Tabelle eventuell hat, muessen neu gezeichnet werden
169 m_pTabWin
->getTableView()->Invalidate(INVALIDATE_NOCHILDREN
);
170 // ohne das INVALIDATE_NOCHILDREN wuerden auch alle Tabellen neu gezeichnet werden,
171 // sprich : es flackert
172 m_bReallyScrolled
= FALSE
;
175 //------------------------------------------------------------------------------
176 long OTableWindowListBox::PreNotify(NotifyEvent
& rNEvt
)
178 BOOL bHandled
= FALSE
;
179 switch (rNEvt
.GetType())
183 const KeyEvent
* pKeyEvent
= rNEvt
.GetKeyEvent();
184 const KeyCode
& rCode
= pKeyEvent
->GetKeyCode();
186 if (rCode
.GetCode() != KEY_RETURN
)
190 bHandled
= m_pTabWin
->HandleKeyInput(*pKeyEvent
);
196 if (rCode
.IsMod1() || rCode
.IsMod2() || rCode
.IsShift())
199 static_cast<OTableWindow
*>(Window::GetParent())->OnEntryDoubleClicked(FirstSelected());
205 return SvTreeListBox::PreNotify(rNEvt
);
209 //------------------------------------------------------------------------------
210 IMPL_LINK( OTableWindowListBox
, ScrollUpHdl
, SvTreeListBox
*, /*pBox*/ )
212 SvLBoxEntry
* pEntry
= GetEntry( m_aMousePos
);
216 if( pEntry
!= Last() )
218 ScrollOutputArea( -1 );
219 pEntry
= GetEntry( m_aMousePos
);
220 Select( pEntry
, TRUE
);
221 // m_aScrollTimer.Start();
227 //------------------------------------------------------------------------------
228 IMPL_LINK( OTableWindowListBox
, ScrollDownHdl
, SvTreeListBox
*, /*pBox*/ )
230 SvLBoxEntry
* pEntry
= GetEntry( m_aMousePos
);
234 if( pEntry
!= Last() )
236 ScrollOutputArea( 1 );
237 pEntry
= GetEntry( m_aMousePos
);
238 Select( pEntry
, TRUE
);
239 // m_aScrollTimer.Start();
245 //------------------------------------------------------------------------------
246 void OTableWindowListBox::StartDrag( sal_Int8
/*nAction*/, const Point
& /*rPosPixel*/ )
248 OJoinTableView
* pCont
= m_pTabWin
->getTableView();
249 if (!pCont
->getDesignView()->getController().isReadOnly() && pCont
->getDesignView()->getController().isConnected())
251 // #100271# OJ asterix was not allowed to be copied to selection browsebox
252 sal_Bool bFirstNotAllowed
= FirstSelected() == First() && m_pTabWin
->GetData()->IsShowAll();
254 // create a description of the source
255 OJoinExchangeData
jxdSource(this);
256 // put it into a exchange object
257 OJoinExchObj
* pJoin
= new OJoinExchObj(jxdSource
,bFirstNotAllowed
);
258 Reference
< XTransferable
> xEnsureDelete(pJoin
);
259 pJoin
->StartDrag(this, DND_ACTION_LINK
, this);
263 //------------------------------------------------------------------------------
264 sal_Int8
OTableWindowListBox::AcceptDrop( const AcceptDropEvent
& _rEvt
)
266 sal_Int8 nDND_Action
= DND_ACTION_NONE
;
268 if ( !OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_TABID
) // this means that the first entry is to be draged
269 && OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_JOIN
) )
270 { // don't drop into the window if it's the drag source itself
273 // remove the selection if the dragging operation is leaving the window
279 m_aMousePos
= _rEvt
.maPosPixel
;
280 Size aOutputSize
= GetOutputSizePixel();
281 SvLBoxEntry
* pEntry
= GetEntry( m_aMousePos
);
283 return DND_ACTION_NONE
;
286 Rectangle
aBottomScrollArea( Point(0, aOutputSize
.Height()-LISTBOX_SCROLLING_AREA
),
287 Size(aOutputSize
.Width(), LISTBOX_SCROLLING_AREA
) );
288 Rectangle
aTopScrollArea( Point(0,0), Size(aOutputSize
.Width(), LISTBOX_SCROLLING_AREA
) );
290 // Wenn Zeiger auf der oberen ScrollingArea steht, nach oben scrollen
291 if( aBottomScrollArea
.IsInside(m_aMousePos
) )
293 if( !m_aScrollTimer
.IsActive() )
295 m_aScrollTimer
.SetTimeoutHdl( LINK(this, OTableWindowListBox
, ScrollUpHdl
) );
300 // Wenn Zeiger auf der oberen ScrollingArea steht, nach unten scrollen
301 else if( aTopScrollArea
.IsInside(m_aMousePos
) )
303 if( !m_aScrollTimer
.IsActive() )
305 m_aScrollTimer
.SetTimeoutHdl( LINK(this, OTableWindowListBox
, ScrollDownHdl
) );
306 ScrollDownHdl( this );
311 if( m_aScrollTimer
.IsActive() )
312 m_aScrollTimer
.Stop();
315 // Beim Drag automatisch den richtigen Eintrag selektieren
316 if ((FirstSelected() != pEntry
) || (FirstSelected() && NextSelected(FirstSelected())))
318 Select(pEntry
, TRUE
);
320 // Auf den ersten Eintrag (*) kann nicht gedroppt werden
321 if(!( m_pTabWin
->GetData()->IsShowAll() && (pEntry
==First()) ))
322 nDND_Action
= DND_ACTION_LINK
;
327 // -----------------------------------------------------------------------------
329 //------------------------------------------------------------------------------
330 IMPL_LINK( OTableWindowListBox
, LookForUiHdl
, void *, /*EMPTY_ARG*/)
333 m_pTabWin
->getTableView()->lookForUiActivities();
336 //------------------------------------------------------------------------------
337 IMPL_LINK( OTableWindowListBox
, DropHdl
, void *, /*EMPTY_ARG*/)
339 // create the connection
341 OSL_ENSURE(m_pTabWin
,"No TableWindow!");
344 OJoinTableView
* pCont
= m_pTabWin
->getTableView();
345 OSL_ENSURE(pCont
,"No QueryTableView!");
346 pCont
->AddConnection(m_aDropInfo
.aSource
, m_aDropInfo
.aDest
);
348 catch(const SQLException
& e
)
350 // remember the exception so that we can show them later when d&d is finished
351 m_pTabWin
->getDesignView()->getController().setErrorOccured(::dbtools::SQLExceptionInfo(e
));
355 //------------------------------------------------------------------------------
356 sal_Int8
OTableWindowListBox::ExecuteDrop( const ExecuteDropEvent
& _rEvt
)
358 TransferableDataHelper
aDropped(_rEvt
.maDropEvent
.Transferable
);
359 if ( OJoinExchObj::isFormatAvailable(aDropped
.GetDataFlavorExVector()))
360 { // don't drop into the window if it's the drag source itself
361 m_aDropInfo
.aSource
= OJoinExchangeData(this);
362 m_aDropInfo
.aDest
= OJoinExchObj::GetSourceDescription(_rEvt
.maDropEvent
.Transferable
);
365 Application::RemoveUserEvent(m_nDropEvent
);
366 m_nDropEvent
= Application::PostUserEvent(LINK(this, OTableWindowListBox
, DropHdl
));
368 return DND_ACTION_LINK
;
370 return DND_ACTION_NONE
;
373 //------------------------------------------------------------------------------
374 void OTableWindowListBox::LoseFocus()
377 m_pTabWin
->setActive(sal_False
);
378 SvTreeListBox::LoseFocus();
381 //------------------------------------------------------------------------------
382 void OTableWindowListBox::GetFocus()
385 m_pTabWin
->setActive();
387 if (GetCurEntry() != NULL
)
389 if ( GetSelectionCount() == 0 || GetCurEntry() != FirstSelected() )
391 if ( FirstSelected() )
392 Select(FirstSelected(), FALSE
);
393 Select(GetCurEntry(), TRUE
);
396 ShowFocusRect(FirstSelected());
398 SvTreeListBox::GetFocus();
401 //------------------------------------------------------------------------------
402 IMPL_LINK( OTableWindowListBox
, OnDoubleClick
, SvTreeListBox
*, /*pBox*/ )
404 // meinem Elter Bescheid sagen
405 Window
* pParent
= Window::GetParent();
406 DBG_ASSERT(pParent
!= NULL
, "OTableWindowListBox::OnDoubleClick : habe kein Parent !");
408 static_cast<OTableWindow
*>(pParent
)->OnEntryDoubleClicked(GetHdlEntry());
412 // -----------------------------------------------------------------------------
413 void OTableWindowListBox::Command(const CommandEvent
& rEvt
)
415 switch (rEvt
.GetCommand())
417 case COMMAND_CONTEXTMENU
:
419 static_cast<OTableWindow
*>(Window::GetParent())->Command(rEvt
);
423 SvTreeListBox::Command(rEvt
);
426 // -----------------------------------------------------------------------------