update dev300-m58
[ooovba.git] / dbaccess / source / ui / querydesign / TableWindowListBox.cxx
blob8b018b937a515ba0b0223b7bd9ca393ec5041f83
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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"
35 #endif
36 #ifndef DBAUI_TABLEWINDOW_HXX
37 #include "TableWindow.hxx"
38 #endif
39 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
40 #include "QueryDesignView.hxx"
41 #endif
42 #ifndef DBAUI_QUERYTABLEVIEW_HXX
43 #include "QueryTableView.hxx"
44 #endif
45 #ifndef DBAUI_QUERYCONTROLLER_HXX
46 #include "querycontroller.hxx"
47 #endif
48 #ifndef DBAUI_JOINEXCHANGE_HXX
49 #include "JoinExchange.hxx"
50 #endif
51 #ifndef _TOOLS_DEBUG_HXX
52 #include <tools/debug.hxx>
53 #endif
54 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
55 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
56 #endif
57 #ifndef _SVX_DBEXCH_HRC
58 #include <svx/dbexch.hrc>
59 #endif
60 #ifndef _SV_SVAPP_HXX
61 #include <vcl/svapp.hxx>
62 #endif
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)
70 : pListBox(pBox)
71 , pEntry(pBox->FirstSelected())
72 { }
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) )
84 ,m_pTabWin( pParent )
85 ,m_nDropEvent(0)
86 ,m_nUiEvent(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);
95 SetHighlightRange( );
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
104 if (m_nUiEvent)
105 Application::RemoveUserEvent(m_nUiEvent);
106 m_nUiEvent = Application::PostUserEvent(LINK(this, OTableWindowListBox, LookForUiHdl));
109 //------------------------------------------------------------------------------
110 OTableWindowListBox::~OTableWindowListBox()
112 DBG_DTOR(OTableWindowListBox,NULL);
113 if (m_nDropEvent)
114 Application::RemoveUserEvent(m_nDropEvent);
115 if (m_nUiEvent)
116 Application::RemoveUserEvent(m_nUiEvent);
117 if( m_aScrollTimer.IsActive() )
118 m_aScrollTimer.Stop();
119 m_pTabWin = NULL;
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();
132 BOOL bCase = FALSE;
135 Reference<XConnection> xConnection = rController.getConnection();
136 if(xConnection.is())
138 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
139 if(xMeta.is())
140 bCase = xMeta->supportsMixedCaseQuotedIdentifiers();
142 while( pEntry )
144 if((bCase ? rEntryText == GetEntryText(pEntry) : rEntryText.EqualsIgnoreCaseAscii(GetEntryText(pEntry))))
146 return pEntry;
148 pEntry = (SvLBoxEntry*)pTreeList->Next( pEntry );
151 catch(SQLException&)
155 return NULL;
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())
181 case EVENT_KEYINPUT:
183 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
184 const KeyCode& rCode = pKeyEvent->GetKeyCode();
186 if (rCode.GetCode() != KEY_RETURN)
188 if(m_pTabWin)
190 bHandled = m_pTabWin->HandleKeyInput(*pKeyEvent);
191 // bHandled = TRUE;
193 break;
196 if (rCode.IsMod1() || rCode.IsMod2() || rCode.IsShift())
197 break;
198 if (FirstSelected())
199 static_cast<OTableWindow*>(Window::GetParent())->OnEntryDoubleClicked(FirstSelected());
201 break;
204 if (!bHandled)
205 return SvTreeListBox::PreNotify(rNEvt);
206 return 1L;
209 //------------------------------------------------------------------------------
210 IMPL_LINK( OTableWindowListBox, ScrollUpHdl, SvTreeListBox*, /*pBox*/ )
212 SvLBoxEntry* pEntry = GetEntry( m_aMousePos );
213 if( !pEntry )
214 return 0;
216 if( pEntry != Last() )
218 ScrollOutputArea( -1 );
219 pEntry = GetEntry( m_aMousePos );
220 Select( pEntry, TRUE );
221 // m_aScrollTimer.Start();
224 return 0;
227 //------------------------------------------------------------------------------
228 IMPL_LINK( OTableWindowListBox, ScrollDownHdl, SvTreeListBox*, /*pBox*/ )
230 SvLBoxEntry* pEntry = GetEntry( m_aMousePos );
231 if( !pEntry )
232 return 0;
234 if( pEntry != Last() )
236 ScrollOutputArea( 1 );
237 pEntry = GetEntry( m_aMousePos );
238 Select( pEntry, TRUE );
239 // m_aScrollTimer.Start();
242 return 0;
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();
253 EndSelection();
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;
267 // check the format
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
274 if (_rEvt.mbLeaving)
275 SelectAll(FALSE);
276 else
278 // hit test
279 m_aMousePos = _rEvt.maPosPixel;
280 Size aOutputSize = GetOutputSizePixel();
281 SvLBoxEntry* pEntry = GetEntry( m_aMousePos );
282 if( !pEntry )
283 return DND_ACTION_NONE;
285 // Scrolling Areas
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) );
296 ScrollUpHdl( this );
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 );
309 else
311 if( m_aScrollTimer.IsActive() )
312 m_aScrollTimer.Stop();
315 // Beim Drag automatisch den richtigen Eintrag selektieren
316 if ((FirstSelected() != pEntry) || (FirstSelected() && NextSelected(FirstSelected())))
317 SelectAll(FALSE);
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;
325 return nDND_Action;
327 // -----------------------------------------------------------------------------
329 //------------------------------------------------------------------------------
330 IMPL_LINK( OTableWindowListBox, LookForUiHdl, void *, /*EMPTY_ARG*/)
332 m_nUiEvent = 0;
333 m_pTabWin->getTableView()->lookForUiActivities();
334 return 0L;
336 //------------------------------------------------------------------------------
337 IMPL_LINK( OTableWindowListBox, DropHdl, void *, /*EMPTY_ARG*/)
339 // create the connection
340 m_nDropEvent = 0;
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));
353 return 0L;
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);
364 if (m_nDropEvent)
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()
376 if(m_pTabWin)
377 m_pTabWin->setActive(sal_False);
378 SvTreeListBox::LoseFocus();
381 //------------------------------------------------------------------------------
382 void OTableWindowListBox::GetFocus()
384 if(m_pTabWin)
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);
395 else
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());
410 return 0;
412 // -----------------------------------------------------------------------------
413 void OTableWindowListBox::Command(const CommandEvent& rEvt)
415 switch (rEvt.GetCommand())
417 case COMMAND_CONTEXTMENU:
419 static_cast<OTableWindow*>(Window::GetParent())->Command(rEvt);
420 break;
422 default:
423 SvTreeListBox::Command(rEvt);
426 // -----------------------------------------------------------------------------