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

Generated by: LCOV version 1.11