LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/querydesign - TableWindowListBox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 173 0.6 %
Date: 2013-07-09 Functions: 2 27 7.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "TableWindowListBox.hxx"
      21             : #include "TableWindow.hxx"
      22             : #include "QueryDesignView.hxx"
      23             : #include "QueryTableView.hxx"
      24             : #include "querycontroller.hxx"
      25             : #include "JoinExchange.hxx"
      26             : #include <osl/diagnose.h>
      27             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      28             : #include <vcl/svapp.hxx>
      29             : 
      30             : using namespace dbaui;
      31             : using namespace ::com::sun::star::sdbc;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::datatransfer;
      34             : 
      35           0 : OJoinExchangeData::OJoinExchangeData(OTableWindowListBox* pBox)
      36             :     : pListBox(pBox)
      37           0 :     , pEntry(pBox->FirstSelected())
      38           0 : { }
      39             : 
      40             : const sal_uLong SCROLLING_TIMESPAN = 500;
      41             : const long LISTBOX_SCROLLING_AREA = 6;
      42             : //==================================================================
      43             : // class OTableWindowListBox
      44             : //==================================================================
      45             : DBG_NAME(OTableWindowListBox)
      46             : //------------------------------------------------------------------------------
      47           0 : OTableWindowListBox::OTableWindowListBox( OTableWindow* pParent )
      48             :     :SvTreeListBox( pParent, WB_HASBUTTONS | WB_BORDER)
      49             :     ,m_aMousePos( Point(0,0) )
      50             :     ,m_pTabWin( pParent )
      51             :     ,m_nDropEvent(0)
      52             :     ,m_nUiEvent(0)
      53           0 :     ,m_bReallyScrolled( sal_False )
      54             : {
      55             :     DBG_CTOR(OTableWindowListBox,NULL);
      56           0 :     m_aScrollTimer.SetTimeout( SCROLLING_TIMESPAN );
      57           0 :     SetDoubleClickHdl( LINK(this, OTableWindowListBox, OnDoubleClick) );
      58             : 
      59           0 :     SetSelectionMode(SINGLE_SELECTION);
      60             : 
      61           0 :     SetHighlightRange( );
      62           0 : }
      63             : 
      64             : //------------------------------------------------------------------------------
      65           0 : void OTableWindowListBox::dragFinished( )
      66             : {
      67             :     // first show the error msg when existing
      68           0 :     m_pTabWin->getDesignView()->getController().showError(m_pTabWin->getDesignView()->getController().clearOccurredError());
      69             :     // second look for ui activities which should happen after d&d
      70           0 :     if (m_nUiEvent)
      71           0 :         Application::RemoveUserEvent(m_nUiEvent);
      72           0 :     m_nUiEvent = Application::PostUserEvent(LINK(this, OTableWindowListBox, LookForUiHdl));
      73           0 : }
      74             : 
      75             : //------------------------------------------------------------------------------
      76           0 : OTableWindowListBox::~OTableWindowListBox()
      77             : {
      78             :     DBG_DTOR(OTableWindowListBox,NULL);
      79           0 :     if (m_nDropEvent)
      80           0 :         Application::RemoveUserEvent(m_nDropEvent);
      81           0 :     if (m_nUiEvent)
      82           0 :         Application::RemoveUserEvent(m_nUiEvent);
      83           0 :     if( m_aScrollTimer.IsActive() )
      84           0 :         m_aScrollTimer.Stop();
      85           0 :     m_pTabWin = NULL;
      86           0 : }
      87             : 
      88             : //------------------------------------------------------------------------------
      89           0 : SvTreeListEntry* OTableWindowListBox::GetEntryFromText( const String& rEntryText )
      90             : {
      91             :     //////////////////////////////////////////////////////////////////////
      92             :     // iterate through the list
      93           0 :     SvTreeList* pTreeList = GetModel();
      94           0 :     SvTreeListEntry* pEntry = pTreeList->First();
      95           0 :     OJoinDesignView* pView = m_pTabWin->getDesignView();
      96           0 :     OJoinController& rController = pView->getController();
      97             : 
      98           0 :     sal_Bool bCase = sal_False;
      99             :     try
     100             :     {
     101           0 :         Reference<XConnection> xConnection = rController.getConnection();
     102           0 :         if(xConnection.is())
     103             :         {
     104           0 :             Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
     105           0 :             if(xMeta.is())
     106           0 :                 bCase = xMeta->supportsMixedCaseQuotedIdentifiers();
     107             :         }
     108           0 :         while( pEntry )
     109             :         {
     110           0 :             if((bCase ? rEntryText == GetEntryText(pEntry) : rEntryText.EqualsIgnoreCaseAscii(GetEntryText(pEntry))))
     111             :             {
     112           0 :                 return pEntry;
     113             :             }
     114           0 :             pEntry = pTreeList->Next(pEntry);
     115           0 :         }
     116             :     }
     117           0 :     catch(SQLException&)
     118             :     {
     119             :     }
     120             : 
     121           0 :     return NULL;
     122             : }
     123             : 
     124             : //------------------------------------------------------------------------------
     125           0 : void OTableWindowListBox::NotifyScrolled()
     126             : {
     127           0 :     m_bReallyScrolled = sal_True;
     128           0 : }
     129             : 
     130             : //------------------------------------------------------------------------------
     131           0 : void OTableWindowListBox::NotifyEndScroll()
     132             : {
     133           0 :     if (m_bReallyScrolled)
     134             :         // connections of this table, if any,  should be redrawn
     135           0 :         m_pTabWin->getTableView()->Invalidate(INVALIDATE_NOCHILDREN);
     136             : 
     137             :         // without INVALIDATE_NOCHILDREN all tables would be redrawn,
     138             :         // so: flickering
     139           0 :     m_bReallyScrolled = sal_False;
     140           0 : }
     141             : 
     142             : //------------------------------------------------------------------------------
     143           0 : long OTableWindowListBox::PreNotify(NotifyEvent& rNEvt)
     144             : {
     145           0 :     sal_Bool bHandled = sal_False;
     146           0 :     switch (rNEvt.GetType())
     147             :     {
     148             :         case EVENT_KEYINPUT:
     149             :         {
     150           0 :             const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
     151           0 :             const KeyCode& rCode = pKeyEvent->GetKeyCode();
     152             : 
     153           0 :             if (rCode.GetCode() != KEY_RETURN)
     154             :             {
     155           0 :                 if(m_pTabWin)
     156             :                 {
     157           0 :                     bHandled = m_pTabWin->HandleKeyInput(*pKeyEvent);
     158             :                 }
     159           0 :                 break;
     160             :             }
     161             : 
     162           0 :             if (rCode.IsMod1() || rCode.IsMod2() || rCode.IsShift())
     163           0 :                 break;
     164           0 :             if (FirstSelected())
     165           0 :                 static_cast<OTableWindow*>(Window::GetParent())->OnEntryDoubleClicked(FirstSelected());
     166             :         }
     167           0 :         break;
     168             :     }
     169             : 
     170           0 :     if (!bHandled)
     171           0 :         return SvTreeListBox::PreNotify(rNEvt);
     172           0 :     return 1L;
     173             : }
     174             : 
     175             : //------------------------------------------------------------------------------
     176           0 : IMPL_LINK( OTableWindowListBox, ScrollUpHdl, SvTreeListBox*, /*pBox*/ )
     177             : {
     178           0 :     SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     179           0 :     if( !pEntry )
     180           0 :         return 0;
     181             : 
     182           0 :     if( pEntry != Last() )
     183             :     {
     184           0 :         ScrollOutputArea( -1 );
     185           0 :         pEntry = GetEntry( m_aMousePos );
     186           0 :         Select( pEntry, sal_True );
     187             :     }
     188             : 
     189           0 :     return 0;
     190             : }
     191             : 
     192             : //------------------------------------------------------------------------------
     193           0 : IMPL_LINK( OTableWindowListBox, ScrollDownHdl, SvTreeListBox*, /*pBox*/ )
     194             : {
     195           0 :     SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     196           0 :     if( !pEntry )
     197           0 :         return 0;
     198             : 
     199           0 :     if( pEntry != Last() )
     200             :     {
     201           0 :         ScrollOutputArea( 1 );
     202           0 :         pEntry = GetEntry( m_aMousePos );
     203           0 :         Select( pEntry, sal_True );
     204             :     }
     205             : 
     206           0 :     return 0;
     207             : }
     208             : 
     209             : //------------------------------------------------------------------------------
     210           0 : void OTableWindowListBox::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
     211             : {
     212           0 :     OJoinTableView* pCont = m_pTabWin->getTableView();
     213           0 :     if (!pCont->getDesignView()->getController().isReadOnly() && pCont->getDesignView()->getController().isConnected())
     214             :     {
     215             :         // asterix was not allowed to be copied to selection browsebox
     216           0 :         sal_Bool bFirstNotAllowed = FirstSelected() == First() && m_pTabWin->GetData()->IsShowAll();
     217           0 :         EndSelection();
     218             :         // create a description of the source
     219           0 :         OJoinExchangeData jxdSource(this);
     220             :         // put it into a exchange object
     221           0 :         OJoinExchObj* pJoin = new OJoinExchObj(jxdSource,bFirstNotAllowed);
     222           0 :         Reference< XTransferable > xEnsureDelete(pJoin);
     223           0 :         pJoin->StartDrag(this, DND_ACTION_LINK, this);
     224             :     }
     225           0 : }
     226             : 
     227             : //------------------------------------------------------------------------------
     228           0 : sal_Int8 OTableWindowListBox::AcceptDrop( const AcceptDropEvent& _rEvt )
     229             : {
     230           0 :     sal_Int8 nDND_Action = DND_ACTION_NONE;
     231             :     // check the format
     232           0 :     if ( !OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_TABID) // this means that the first entry is to be draged
     233           0 :         && OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_JOIN) )
     234             :     {   // don't drop into the window if it's the drag source itself
     235             : 
     236             :         // remove the selection if the dragging operation is leaving the window
     237           0 :         if (_rEvt.mbLeaving)
     238           0 :             SelectAll(sal_False);
     239             :         else
     240             :         {
     241             :             // hit test
     242           0 :             m_aMousePos = _rEvt.maPosPixel;
     243           0 :             Size aOutputSize = GetOutputSizePixel();
     244           0 :             SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     245           0 :             if( !pEntry )
     246           0 :                 return DND_ACTION_NONE;
     247             : 
     248             :             // Scrolling Areas
     249           0 :             Rectangle aBottomScrollArea( Point(0, aOutputSize.Height()-LISTBOX_SCROLLING_AREA),
     250           0 :                                          Size(aOutputSize.Width(), LISTBOX_SCROLLING_AREA) );
     251           0 :             Rectangle aTopScrollArea( Point(0,0), Size(aOutputSize.Width(), LISTBOX_SCROLLING_AREA) );
     252             : 
     253             :              // scroll up if the pointer is on the upper scroll area
     254           0 :             if( aBottomScrollArea.IsInside(m_aMousePos) )
     255             :             {
     256           0 :                 if( !m_aScrollTimer.IsActive() )
     257             :                 {
     258           0 :                     m_aScrollTimer.SetTimeoutHdl( LINK(this, OTableWindowListBox, ScrollUpHdl) );
     259           0 :                     ScrollUpHdl( this );
     260             :                 }
     261             :             }
     262             : 
     263             :            // scroll down if the pointer is on the lower scroll area
     264           0 :            else if( aTopScrollArea.IsInside(m_aMousePos) )
     265             :             {
     266           0 :                 if( !m_aScrollTimer.IsActive() )
     267             :                 {
     268           0 :                     m_aScrollTimer.SetTimeoutHdl( LINK(this, OTableWindowListBox, ScrollDownHdl) );
     269           0 :                     ScrollDownHdl( this );
     270             :                 }
     271             :             }
     272             :             else
     273             :             {
     274           0 :                 if( m_aScrollTimer.IsActive() )
     275           0 :                     m_aScrollTimer.Stop();
     276             :             }
     277             : 
     278             :             // automatically select right entry when dragging
     279           0 :             if ((FirstSelected() != pEntry) || (FirstSelected() && NextSelected(FirstSelected())))
     280           0 :                 SelectAll(sal_False);
     281           0 :             Select(pEntry, sal_True);
     282             : 
     283             :             // one cannot drop on the first (*) entry
     284           0 :             if(!( m_pTabWin->GetData()->IsShowAll() && (pEntry==First()) ))
     285           0 :                 nDND_Action = DND_ACTION_LINK;
     286             :         }
     287             :     }
     288           0 :     return nDND_Action;
     289             : }
     290             : // -----------------------------------------------------------------------------
     291             : 
     292             : //------------------------------------------------------------------------------
     293           0 : IMPL_LINK( OTableWindowListBox, LookForUiHdl, void *, /*EMPTY_ARG*/)
     294             : {
     295           0 :     m_nUiEvent = 0;
     296           0 :     m_pTabWin->getTableView()->lookForUiActivities();
     297           0 :     return 0L;
     298             : }
     299             : //------------------------------------------------------------------------------
     300           0 : IMPL_LINK( OTableWindowListBox, DropHdl, void *, /*EMPTY_ARG*/)
     301             : {
     302             :     // create the connection
     303           0 :     m_nDropEvent = 0;
     304             :     OSL_ENSURE(m_pTabWin,"No TableWindow!");
     305             :     try
     306             :     {
     307           0 :         OJoinTableView* pCont = m_pTabWin->getTableView();
     308             :         OSL_ENSURE(pCont,"No QueryTableView!");
     309           0 :         pCont->AddConnection(m_aDropInfo.aSource, m_aDropInfo.aDest);
     310             :     }
     311           0 :     catch(const SQLException& e)
     312             :     {
     313             :         // remember the exception so that we can show them later when d&d is finished
     314           0 :         m_pTabWin->getDesignView()->getController().setErrorOccurred(::dbtools::SQLExceptionInfo(e));
     315             :     }
     316           0 :     return 0L;
     317             : }
     318             : //------------------------------------------------------------------------------
     319           0 : sal_Int8 OTableWindowListBox::ExecuteDrop( const ExecuteDropEvent& _rEvt )
     320             : {
     321           0 :     TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
     322           0 :     if ( OJoinExchObj::isFormatAvailable(aDropped.GetDataFlavorExVector()))
     323             :     {   // don't drop into the window if it's the drag source itself
     324           0 :         m_aDropInfo.aSource = OJoinExchangeData(this);
     325           0 :         m_aDropInfo.aDest   = OJoinExchObj::GetSourceDescription(_rEvt.maDropEvent.Transferable);
     326             : 
     327           0 :         if (m_nDropEvent)
     328           0 :             Application::RemoveUserEvent(m_nDropEvent);
     329           0 :         m_nDropEvent = Application::PostUserEvent(LINK(this, OTableWindowListBox, DropHdl));
     330             : 
     331           0 :         return DND_ACTION_LINK;
     332             :     }
     333           0 :     return DND_ACTION_NONE;
     334             : }
     335             : 
     336             : //------------------------------------------------------------------------------
     337           0 : void OTableWindowListBox::LoseFocus()
     338             : {
     339           0 :     if(m_pTabWin)
     340           0 :         m_pTabWin->setActive(sal_False);
     341           0 :     SvTreeListBox::LoseFocus();
     342           0 : }
     343             : 
     344             : //------------------------------------------------------------------------------
     345           0 : void OTableWindowListBox::GetFocus()
     346             : {
     347           0 :     if(m_pTabWin)
     348           0 :         m_pTabWin->setActive();
     349             : 
     350           0 :     if (GetCurEntry() != NULL)
     351             :     {
     352           0 :         if ( GetSelectionCount() == 0 || GetCurEntry() != FirstSelected() )
     353             :         {
     354           0 :             if ( FirstSelected() )
     355           0 :                 Select(FirstSelected(), sal_False);
     356           0 :             Select(GetCurEntry(), sal_True);
     357             :         }
     358             :         else
     359           0 :             ShowFocusRect(FirstSelected());
     360             :     }
     361           0 :     SvTreeListBox::GetFocus();
     362           0 : }
     363             : 
     364             : //------------------------------------------------------------------------------
     365           0 : IMPL_LINK( OTableWindowListBox, OnDoubleClick, SvTreeListBox *, /*pBox*/ )
     366             : {
     367             :     // tell my parent
     368           0 :     Window* pParent = Window::GetParent();
     369             :     OSL_ENSURE(pParent != NULL, "OTableWindowListBox::OnDoubleClick : habe kein Parent !");
     370             : 
     371           0 :     static_cast<OTableWindow*>(pParent)->OnEntryDoubleClicked(GetHdlEntry());
     372             : 
     373           0 :     return 0;
     374             : }
     375             : // -----------------------------------------------------------------------------
     376           0 : void OTableWindowListBox::Command(const CommandEvent& rEvt)
     377             : {
     378           0 :     switch (rEvt.GetCommand())
     379             :     {
     380             :         case COMMAND_CONTEXTMENU:
     381             :         {
     382           0 :             static_cast<OTableWindow*>(Window::GetParent())->Command(rEvt);
     383           0 :             break;
     384             :         }
     385             :         default:
     386           0 :             SvTreeListBox::Command(rEvt);
     387             :     }
     388          12 : }
     389             : // -----------------------------------------------------------------------------
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10