LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - TableWindowListBox.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 173 0.0 %
Date: 2014-04-14 Functions: 0 25 0.0 %
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             : // class OTableWindowListBox
      43           0 : OTableWindowListBox::OTableWindowListBox( OTableWindow* pParent )
      44             :     :SvTreeListBox( pParent, WB_HASBUTTONS | WB_BORDER)
      45             :     ,m_aMousePos( Point(0,0) )
      46             :     ,m_pTabWin( pParent )
      47             :     ,m_nDropEvent(0)
      48             :     ,m_nUiEvent(0)
      49           0 :     ,m_bReallyScrolled( sal_False )
      50             : {
      51           0 :     m_aScrollTimer.SetTimeout( SCROLLING_TIMESPAN );
      52           0 :     SetDoubleClickHdl( LINK(this, OTableWindowListBox, OnDoubleClick) );
      53             : 
      54           0 :     SetSelectionMode(SINGLE_SELECTION);
      55             : 
      56           0 :     SetHighlightRange( );
      57           0 : }
      58             : 
      59           0 : void OTableWindowListBox::dragFinished( )
      60             : {
      61             :     // first show the error msg when existing
      62           0 :     m_pTabWin->getDesignView()->getController().showError(m_pTabWin->getDesignView()->getController().clearOccurredError());
      63             :     // second look for ui activities which should happen after d&d
      64           0 :     if (m_nUiEvent)
      65           0 :         Application::RemoveUserEvent(m_nUiEvent);
      66           0 :     m_nUiEvent = Application::PostUserEvent(LINK(this, OTableWindowListBox, LookForUiHdl));
      67           0 : }
      68             : 
      69           0 : OTableWindowListBox::~OTableWindowListBox()
      70             : {
      71           0 :     if (m_nDropEvent)
      72           0 :         Application::RemoveUserEvent(m_nDropEvent);
      73           0 :     if (m_nUiEvent)
      74           0 :         Application::RemoveUserEvent(m_nUiEvent);
      75           0 :     if( m_aScrollTimer.IsActive() )
      76           0 :         m_aScrollTimer.Stop();
      77           0 :     m_pTabWin = NULL;
      78           0 : }
      79             : 
      80           0 : SvTreeListEntry* OTableWindowListBox::GetEntryFromText( const OUString& rEntryText )
      81             : {
      82             :     // iterate through the list
      83           0 :     SvTreeList* pTreeList = GetModel();
      84           0 :     SvTreeListEntry* pEntry = pTreeList->First();
      85           0 :     OJoinDesignView* pView = m_pTabWin->getDesignView();
      86           0 :     OJoinController& rController = pView->getController();
      87             : 
      88           0 :     sal_Bool bCase = sal_False;
      89             :     try
      90             :     {
      91           0 :         Reference<XConnection> xConnection = rController.getConnection();
      92           0 :         if(xConnection.is())
      93             :         {
      94           0 :             Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
      95           0 :             if(xMeta.is())
      96           0 :                 bCase = xMeta->supportsMixedCaseQuotedIdentifiers();
      97             :         }
      98           0 :         while( pEntry )
      99             :         {
     100           0 :             if((bCase ? rEntryText == GetEntryText(pEntry) : rEntryText.equalsIgnoreAsciiCase(GetEntryText(pEntry))))
     101             :             {
     102           0 :                 return pEntry;
     103             :             }
     104           0 :             pEntry = pTreeList->Next(pEntry);
     105           0 :         }
     106             :     }
     107           0 :     catch(SQLException&)
     108             :     {
     109             :     }
     110             : 
     111           0 :     return NULL;
     112             : }
     113             : 
     114           0 : void OTableWindowListBox::NotifyScrolled()
     115             : {
     116           0 :     m_bReallyScrolled = sal_True;
     117           0 : }
     118             : 
     119           0 : void OTableWindowListBox::NotifyEndScroll()
     120             : {
     121           0 :     if (m_bReallyScrolled)
     122             :         // connections of this table, if any,  should be redrawn
     123           0 :         m_pTabWin->getTableView()->Invalidate(INVALIDATE_NOCHILDREN);
     124             : 
     125             :         // without INVALIDATE_NOCHILDREN all tables would be redrawn,
     126             :         // so: flickering
     127           0 :     m_bReallyScrolled = sal_False;
     128           0 : }
     129             : 
     130           0 : bool OTableWindowListBox::PreNotify(NotifyEvent& rNEvt)
     131             : {
     132           0 :     sal_Bool bHandled = sal_False;
     133           0 :     switch (rNEvt.GetType())
     134             :     {
     135             :         case EVENT_KEYINPUT:
     136             :         {
     137           0 :             const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
     138           0 :             const KeyCode& rCode = pKeyEvent->GetKeyCode();
     139             : 
     140           0 :             if (rCode.GetCode() != KEY_RETURN)
     141             :             {
     142           0 :                 if(m_pTabWin)
     143             :                 {
     144           0 :                     bHandled = m_pTabWin->HandleKeyInput(*pKeyEvent);
     145             :                 }
     146           0 :                 break;
     147             :             }
     148             : 
     149           0 :             if (rCode.IsMod1() || rCode.IsMod2() || rCode.IsShift())
     150           0 :                 break;
     151           0 :             if (FirstSelected())
     152           0 :                 static_cast<OTableWindow*>(Window::GetParent())->OnEntryDoubleClicked(FirstSelected());
     153             :         }
     154           0 :         break;
     155             :     }
     156             : 
     157           0 :     if (!bHandled)
     158           0 :         return SvTreeListBox::PreNotify(rNEvt);
     159           0 :     return true;
     160             : }
     161             : 
     162           0 : IMPL_LINK( OTableWindowListBox, ScrollUpHdl, SvTreeListBox*, /*pBox*/ )
     163             : {
     164           0 :     SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     165           0 :     if( !pEntry )
     166           0 :         return 0;
     167             : 
     168           0 :     if( pEntry != Last() )
     169             :     {
     170           0 :         ScrollOutputArea( -1 );
     171           0 :         pEntry = GetEntry( m_aMousePos );
     172           0 :         Select( pEntry, true );
     173             :     }
     174             : 
     175           0 :     return 0;
     176             : }
     177             : 
     178           0 : IMPL_LINK( OTableWindowListBox, ScrollDownHdl, SvTreeListBox*, /*pBox*/ )
     179             : {
     180           0 :     SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     181           0 :     if( !pEntry )
     182           0 :         return 0;
     183             : 
     184           0 :     if( pEntry != Last() )
     185             :     {
     186           0 :         ScrollOutputArea( 1 );
     187           0 :         pEntry = GetEntry( m_aMousePos );
     188           0 :         Select( pEntry, true );
     189             :     }
     190             : 
     191           0 :     return 0;
     192             : }
     193             : 
     194           0 : void OTableWindowListBox::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
     195             : {
     196           0 :     OJoinTableView* pCont = m_pTabWin->getTableView();
     197           0 :     if (!pCont->getDesignView()->getController().isReadOnly() && pCont->getDesignView()->getController().isConnected())
     198             :     {
     199             :         // asterisk was not allowed to be copied to selection browsebox
     200           0 :         sal_Bool bFirstNotAllowed = FirstSelected() == First() && m_pTabWin->GetData()->IsShowAll();
     201           0 :         EndSelection();
     202             :         // create a description of the source
     203           0 :         OJoinExchangeData jxdSource(this);
     204             :         // put it into a exchange object
     205           0 :         OJoinExchObj* pJoin = new OJoinExchObj(jxdSource,bFirstNotAllowed);
     206           0 :         Reference< XTransferable > xEnsureDelete(pJoin);
     207           0 :         pJoin->StartDrag(this, DND_ACTION_LINK, this);
     208             :     }
     209           0 : }
     210             : 
     211           0 : sal_Int8 OTableWindowListBox::AcceptDrop( const AcceptDropEvent& _rEvt )
     212             : {
     213           0 :     sal_Int8 nDND_Action = DND_ACTION_NONE;
     214             :     // check the format
     215           0 :     if ( !OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_TABID) // this means that the first entry is to be draged
     216           0 :         && OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_JOIN) )
     217             :     {   // don't drop into the window if it's the drag source itself
     218             : 
     219             :         // remove the selection if the dragging operation is leaving the window
     220           0 :         if (_rEvt.mbLeaving)
     221           0 :             SelectAll(false);
     222             :         else
     223             :         {
     224             :             // hit test
     225           0 :             m_aMousePos = _rEvt.maPosPixel;
     226           0 :             Size aOutputSize = GetOutputSizePixel();
     227           0 :             SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     228           0 :             if( !pEntry )
     229           0 :                 return DND_ACTION_NONE;
     230             : 
     231             :             // Scrolling Areas
     232           0 :             Rectangle aBottomScrollArea( Point(0, aOutputSize.Height()-LISTBOX_SCROLLING_AREA),
     233           0 :                                          Size(aOutputSize.Width(), LISTBOX_SCROLLING_AREA) );
     234           0 :             Rectangle aTopScrollArea( Point(0,0), Size(aOutputSize.Width(), LISTBOX_SCROLLING_AREA) );
     235             : 
     236             :              // scroll up if the pointer is on the upper scroll area
     237           0 :             if( aBottomScrollArea.IsInside(m_aMousePos) )
     238             :             {
     239           0 :                 if( !m_aScrollTimer.IsActive() )
     240             :                 {
     241           0 :                     m_aScrollTimer.SetTimeoutHdl( LINK(this, OTableWindowListBox, ScrollUpHdl) );
     242           0 :                     ScrollUpHdl( this );
     243             :                 }
     244             :             }
     245             : 
     246             :            // scroll down if the pointer is on the lower scroll area
     247           0 :            else if( aTopScrollArea.IsInside(m_aMousePos) )
     248             :             {
     249           0 :                 if( !m_aScrollTimer.IsActive() )
     250             :                 {
     251           0 :                     m_aScrollTimer.SetTimeoutHdl( LINK(this, OTableWindowListBox, ScrollDownHdl) );
     252           0 :                     ScrollDownHdl( this );
     253             :                 }
     254             :             }
     255             :             else
     256             :             {
     257           0 :                 if( m_aScrollTimer.IsActive() )
     258           0 :                     m_aScrollTimer.Stop();
     259             :             }
     260             : 
     261             :             // automatically select right entry when dragging
     262           0 :             if ((FirstSelected() != pEntry) || (FirstSelected() && NextSelected(FirstSelected())))
     263           0 :                 SelectAll(false);
     264           0 :             Select(pEntry, true);
     265             : 
     266             :             // one cannot drop on the first (*) entry
     267           0 :             if(!( m_pTabWin->GetData()->IsShowAll() && (pEntry==First()) ))
     268           0 :                 nDND_Action = DND_ACTION_LINK;
     269             :         }
     270             :     }
     271           0 :     return nDND_Action;
     272             : }
     273             : 
     274           0 : IMPL_LINK( OTableWindowListBox, LookForUiHdl, void *, /*EMPTY_ARG*/)
     275             : {
     276           0 :     m_nUiEvent = 0;
     277           0 :     m_pTabWin->getTableView()->lookForUiActivities();
     278           0 :     return 0L;
     279             : }
     280             : 
     281           0 : IMPL_LINK( OTableWindowListBox, DropHdl, void *, /*EMPTY_ARG*/)
     282             : {
     283             :     // create the connection
     284           0 :     m_nDropEvent = 0;
     285             :     OSL_ENSURE(m_pTabWin,"No TableWindow!");
     286             :     try
     287             :     {
     288           0 :         OJoinTableView* pCont = m_pTabWin->getTableView();
     289             :         OSL_ENSURE(pCont,"No QueryTableView!");
     290           0 :         pCont->AddConnection(m_aDropInfo.aSource, m_aDropInfo.aDest);
     291             :     }
     292           0 :     catch(const SQLException& e)
     293             :     {
     294             :         // remember the exception so that we can show them later when d&d is finished
     295           0 :         m_pTabWin->getDesignView()->getController().setErrorOccurred(::dbtools::SQLExceptionInfo(e));
     296             :     }
     297           0 :     return 0L;
     298             : }
     299             : 
     300           0 : sal_Int8 OTableWindowListBox::ExecuteDrop( const ExecuteDropEvent& _rEvt )
     301             : {
     302           0 :     TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
     303           0 :     if ( OJoinExchObj::isFormatAvailable(aDropped.GetDataFlavorExVector()))
     304             :     {   // don't drop into the window if it's the drag source itself
     305           0 :         m_aDropInfo.aSource = OJoinExchangeData(this);
     306           0 :         m_aDropInfo.aDest   = OJoinExchObj::GetSourceDescription(_rEvt.maDropEvent.Transferable);
     307             : 
     308           0 :         if (m_nDropEvent)
     309           0 :             Application::RemoveUserEvent(m_nDropEvent);
     310           0 :         m_nDropEvent = Application::PostUserEvent(LINK(this, OTableWindowListBox, DropHdl));
     311             : 
     312           0 :         return DND_ACTION_LINK;
     313             :     }
     314           0 :     return DND_ACTION_NONE;
     315             : }
     316             : 
     317           0 : void OTableWindowListBox::LoseFocus()
     318             : {
     319           0 :     if(m_pTabWin)
     320           0 :         m_pTabWin->setActive(sal_False);
     321           0 :     SvTreeListBox::LoseFocus();
     322           0 : }
     323             : 
     324           0 : void OTableWindowListBox::GetFocus()
     325             : {
     326           0 :     if(m_pTabWin)
     327           0 :         m_pTabWin->setActive();
     328             : 
     329           0 :     if (GetCurEntry() != NULL)
     330             :     {
     331           0 :         if ( GetSelectionCount() == 0 || GetCurEntry() != FirstSelected() )
     332             :         {
     333           0 :             if ( FirstSelected() )
     334           0 :                 Select(FirstSelected(), false);
     335           0 :             Select(GetCurEntry(), true);
     336             :         }
     337             :         else
     338           0 :             ShowFocusRect(FirstSelected());
     339             :     }
     340           0 :     SvTreeListBox::GetFocus();
     341           0 : }
     342             : 
     343           0 : IMPL_LINK( OTableWindowListBox, OnDoubleClick, SvTreeListBox *, /*pBox*/ )
     344             : {
     345             :     // tell my parent
     346           0 :     Window* pParent = Window::GetParent();
     347             :     OSL_ENSURE(pParent != NULL, "OTableWindowListBox::OnDoubleClick : habe kein Parent !");
     348             : 
     349           0 :     static_cast<OTableWindow*>(pParent)->OnEntryDoubleClicked(GetHdlEntry());
     350             : 
     351           0 :     return 0;
     352             : }
     353             : 
     354           0 : void OTableWindowListBox::Command(const CommandEvent& rEvt)
     355             : {
     356           0 :     switch (rEvt.GetCommand())
     357             :     {
     358             :         case COMMAND_CONTEXTMENU:
     359             :         {
     360           0 :             static_cast<OTableWindow*>(Window::GetParent())->Command(rEvt);
     361           0 :             break;
     362             :         }
     363             :         default:
     364           0 :             SvTreeListBox::Command(rEvt);
     365             :     }
     366           0 : }
     367             : 
     368             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10