LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/querydesign - TableWindowListBox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 173 0.0 %
Date: 2012-12-27 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             : //==================================================================
      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             :     // Liste durchiterieren
      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             :         // die Verbindungen, die diese Tabelle eventuell hat, muessen neu gezeichnet werden
     135           0 :         m_pTabWin->getTableView()->Invalidate(INVALIDATE_NOCHILDREN);
     136             :         // ohne das INVALIDATE_NOCHILDREN wuerden auch alle Tabellen neu gezeichnet werden,
     137             :         // sprich : es flackert
     138           0 :     m_bReallyScrolled = sal_False;
     139           0 : }
     140             : 
     141             : //------------------------------------------------------------------------------
     142           0 : long OTableWindowListBox::PreNotify(NotifyEvent& rNEvt)
     143             : {
     144           0 :     sal_Bool bHandled = sal_False;
     145           0 :     switch (rNEvt.GetType())
     146             :     {
     147             :         case EVENT_KEYINPUT:
     148             :         {
     149           0 :             const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
     150           0 :             const KeyCode& rCode = pKeyEvent->GetKeyCode();
     151             : 
     152           0 :             if (rCode.GetCode() != KEY_RETURN)
     153             :             {
     154           0 :                 if(m_pTabWin)
     155             :                 {
     156           0 :                     bHandled = m_pTabWin->HandleKeyInput(*pKeyEvent);
     157             :                 }
     158           0 :                 break;
     159             :             }
     160             : 
     161           0 :             if (rCode.IsMod1() || rCode.IsMod2() || rCode.IsShift())
     162           0 :                 break;
     163           0 :             if (FirstSelected())
     164           0 :                 static_cast<OTableWindow*>(Window::GetParent())->OnEntryDoubleClicked(FirstSelected());
     165             :         }
     166           0 :         break;
     167             :     }
     168             : 
     169           0 :     if (!bHandled)
     170           0 :         return SvTreeListBox::PreNotify(rNEvt);
     171           0 :     return 1L;
     172             : }
     173             : 
     174             : //------------------------------------------------------------------------------
     175           0 : IMPL_LINK( OTableWindowListBox, ScrollUpHdl, SvTreeListBox*, /*pBox*/ )
     176             : {
     177           0 :     SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     178           0 :     if( !pEntry )
     179           0 :         return 0;
     180             : 
     181           0 :     if( pEntry != Last() )
     182             :     {
     183           0 :         ScrollOutputArea( -1 );
     184           0 :         pEntry = GetEntry( m_aMousePos );
     185           0 :         Select( pEntry, sal_True );
     186             :     }
     187             : 
     188           0 :     return 0;
     189             : }
     190             : 
     191             : //------------------------------------------------------------------------------
     192           0 : IMPL_LINK( OTableWindowListBox, ScrollDownHdl, SvTreeListBox*, /*pBox*/ )
     193             : {
     194           0 :     SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     195           0 :     if( !pEntry )
     196           0 :         return 0;
     197             : 
     198           0 :     if( pEntry != Last() )
     199             :     {
     200           0 :         ScrollOutputArea( 1 );
     201           0 :         pEntry = GetEntry( m_aMousePos );
     202           0 :         Select( pEntry, sal_True );
     203             :     }
     204             : 
     205           0 :     return 0;
     206             : }
     207             : 
     208             : //------------------------------------------------------------------------------
     209           0 : void OTableWindowListBox::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
     210             : {
     211           0 :     OJoinTableView* pCont = m_pTabWin->getTableView();
     212           0 :     if (!pCont->getDesignView()->getController().isReadOnly() && pCont->getDesignView()->getController().isConnected())
     213             :     {
     214             :         // asterix was not allowed to be copied to selection browsebox
     215           0 :         sal_Bool bFirstNotAllowed = FirstSelected() == First() && m_pTabWin->GetData()->IsShowAll();
     216           0 :         EndSelection();
     217             :         // create a description of the source
     218           0 :         OJoinExchangeData jxdSource(this);
     219             :         // put it into a exchange object
     220           0 :         OJoinExchObj* pJoin = new OJoinExchObj(jxdSource,bFirstNotAllowed);
     221           0 :         Reference< XTransferable > xEnsureDelete(pJoin);
     222           0 :         pJoin->StartDrag(this, DND_ACTION_LINK, this);
     223             :     }
     224           0 : }
     225             : 
     226             : //------------------------------------------------------------------------------
     227           0 : sal_Int8 OTableWindowListBox::AcceptDrop( const AcceptDropEvent& _rEvt )
     228             : {
     229           0 :     sal_Int8 nDND_Action = DND_ACTION_NONE;
     230             :     // check the format
     231           0 :     if ( !OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_TABID) // this means that the first entry is to be draged
     232           0 :         && OJoinExchObj::isFormatAvailable(GetDataFlavorExVector(),SOT_FORMATSTR_ID_SBA_JOIN) )
     233             :     {   // don't drop into the window if it's the drag source itself
     234             : 
     235             :         // remove the selection if the dragging operation is leaving the window
     236           0 :         if (_rEvt.mbLeaving)
     237           0 :             SelectAll(sal_False);
     238             :         else
     239             :         {
     240             :             // hit test
     241           0 :             m_aMousePos = _rEvt.maPosPixel;
     242           0 :             Size aOutputSize = GetOutputSizePixel();
     243           0 :             SvTreeListEntry* pEntry = GetEntry( m_aMousePos );
     244           0 :             if( !pEntry )
     245           0 :                 return DND_ACTION_NONE;
     246             : 
     247             :             // Scrolling Areas
     248           0 :             Rectangle aBottomScrollArea( Point(0, aOutputSize.Height()-LISTBOX_SCROLLING_AREA),
     249           0 :                                          Size(aOutputSize.Width(), LISTBOX_SCROLLING_AREA) );
     250           0 :             Rectangle aTopScrollArea( Point(0,0), Size(aOutputSize.Width(), LISTBOX_SCROLLING_AREA) );
     251             : 
     252             :             // Wenn Zeiger auf der oberen ScrollingArea steht, nach oben scrollen
     253           0 :             if( aBottomScrollArea.IsInside(m_aMousePos) )
     254             :             {
     255           0 :                 if( !m_aScrollTimer.IsActive() )
     256             :                 {
     257           0 :                     m_aScrollTimer.SetTimeoutHdl( LINK(this, OTableWindowListBox, ScrollUpHdl) );
     258           0 :                     ScrollUpHdl( this );
     259             :                 }
     260             :             }
     261             : 
     262             :             // Wenn Zeiger auf der oberen ScrollingArea steht, nach unten scrollen
     263           0 :             else if( aTopScrollArea.IsInside(m_aMousePos) )
     264             :             {
     265           0 :                 if( !m_aScrollTimer.IsActive() )
     266             :                 {
     267           0 :                     m_aScrollTimer.SetTimeoutHdl( LINK(this, OTableWindowListBox, ScrollDownHdl) );
     268           0 :                     ScrollDownHdl( this );
     269             :                 }
     270             :             }
     271             :             else
     272             :             {
     273           0 :                 if( m_aScrollTimer.IsActive() )
     274           0 :                     m_aScrollTimer.Stop();
     275             :             }
     276             : 
     277             :             // Beim Drag automatisch den richtigen Eintrag selektieren
     278           0 :             if ((FirstSelected() != pEntry) || (FirstSelected() && NextSelected(FirstSelected())))
     279           0 :                 SelectAll(sal_False);
     280           0 :             Select(pEntry, sal_True);
     281             : 
     282             :             // Auf den ersten Eintrag (*) kann nicht gedroppt werden
     283           0 :             if(!( m_pTabWin->GetData()->IsShowAll() && (pEntry==First()) ))
     284           0 :                 nDND_Action = DND_ACTION_LINK;
     285             :         }
     286             :     }
     287           0 :     return nDND_Action;
     288             : }
     289             : // -----------------------------------------------------------------------------
     290             : 
     291             : //------------------------------------------------------------------------------
     292           0 : IMPL_LINK( OTableWindowListBox, LookForUiHdl, void *, /*EMPTY_ARG*/)
     293             : {
     294           0 :     m_nUiEvent = 0;
     295           0 :     m_pTabWin->getTableView()->lookForUiActivities();
     296           0 :     return 0L;
     297             : }
     298             : //------------------------------------------------------------------------------
     299           0 : IMPL_LINK( OTableWindowListBox, DropHdl, void *, /*EMPTY_ARG*/)
     300             : {
     301             :     // create the connection
     302           0 :     m_nDropEvent = 0;
     303             :     OSL_ENSURE(m_pTabWin,"No TableWindow!");
     304             :     try
     305             :     {
     306           0 :         OJoinTableView* pCont = m_pTabWin->getTableView();
     307             :         OSL_ENSURE(pCont,"No QueryTableView!");
     308           0 :         pCont->AddConnection(m_aDropInfo.aSource, m_aDropInfo.aDest);
     309             :     }
     310           0 :     catch(const SQLException& e)
     311             :     {
     312             :         // remember the exception so that we can show them later when d&d is finished
     313           0 :         m_pTabWin->getDesignView()->getController().setErrorOccurred(::dbtools::SQLExceptionInfo(e));
     314             :     }
     315           0 :     return 0L;
     316             : }
     317             : //------------------------------------------------------------------------------
     318           0 : sal_Int8 OTableWindowListBox::ExecuteDrop( const ExecuteDropEvent& _rEvt )
     319             : {
     320           0 :     TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
     321           0 :     if ( OJoinExchObj::isFormatAvailable(aDropped.GetDataFlavorExVector()))
     322             :     {   // don't drop into the window if it's the drag source itself
     323           0 :         m_aDropInfo.aSource = OJoinExchangeData(this);
     324           0 :         m_aDropInfo.aDest   = OJoinExchObj::GetSourceDescription(_rEvt.maDropEvent.Transferable);
     325             : 
     326           0 :         if (m_nDropEvent)
     327           0 :             Application::RemoveUserEvent(m_nDropEvent);
     328           0 :         m_nDropEvent = Application::PostUserEvent(LINK(this, OTableWindowListBox, DropHdl));
     329             : 
     330           0 :         return DND_ACTION_LINK;
     331             :     }
     332           0 :     return DND_ACTION_NONE;
     333             : }
     334             : 
     335             : //------------------------------------------------------------------------------
     336           0 : void OTableWindowListBox::LoseFocus()
     337             : {
     338           0 :     if(m_pTabWin)
     339           0 :         m_pTabWin->setActive(sal_False);
     340           0 :     SvTreeListBox::LoseFocus();
     341           0 : }
     342             : 
     343             : //------------------------------------------------------------------------------
     344           0 : void OTableWindowListBox::GetFocus()
     345             : {
     346           0 :     if(m_pTabWin)
     347           0 :         m_pTabWin->setActive();
     348             : 
     349           0 :     if (GetCurEntry() != NULL)
     350             :     {
     351           0 :         if ( GetSelectionCount() == 0 || GetCurEntry() != FirstSelected() )
     352             :         {
     353           0 :             if ( FirstSelected() )
     354           0 :                 Select(FirstSelected(), sal_False);
     355           0 :             Select(GetCurEntry(), sal_True);
     356             :         }
     357             :         else
     358           0 :             ShowFocusRect(FirstSelected());
     359             :     }
     360           0 :     SvTreeListBox::GetFocus();
     361           0 : }
     362             : 
     363             : //------------------------------------------------------------------------------
     364           0 : IMPL_LINK( OTableWindowListBox, OnDoubleClick, SvTreeListBox *, /*pBox*/ )
     365             : {
     366             :     // meinem Elter Bescheid sagen
     367           0 :     Window* pParent = Window::GetParent();
     368             :     OSL_ENSURE(pParent != NULL, "OTableWindowListBox::OnDoubleClick : habe kein Parent !");
     369             : 
     370           0 :     static_cast<OTableWindow*>(pParent)->OnEntryDoubleClicked(GetHdlEntry());
     371             : 
     372           0 :     return 0;
     373             : }
     374             : // -----------------------------------------------------------------------------
     375           0 : void OTableWindowListBox::Command(const CommandEvent& rEvt)
     376             : {
     377           0 :     switch (rEvt.GetCommand())
     378             :     {
     379             :         case COMMAND_CONTEXTMENU:
     380             :         {
     381           0 :             static_cast<OTableWindow*>(Window::GetParent())->Command(rEvt);
     382           0 :             break;
     383             :         }
     384             :         default:
     385           0 :             SvTreeListBox::Command(rEvt);
     386             :     }
     387           0 : }
     388             : // -----------------------------------------------------------------------------
     389             : 
     390             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10