LCOV - code coverage report
Current view: top level - extensions/source/bibliography - bibview.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 96 1.0 %
Date: 2015-06-13 12:38:46 Functions: 2 17 11.8 %
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             : 
      21             : #include "bib.hrc"
      22             : #include "bibcont.hxx"
      23             : #include "bibbeam.hxx"
      24             : #include "general.hxx"
      25             : #include "bibview.hxx"
      26             : #include "datman.hxx"
      27             : #include "bibresid.hxx"
      28             : #include "bibmod.hxx"
      29             : #include "bibconfig.hxx"
      30             : 
      31             : 
      32             : #include <vcl/svapp.hxx>
      33             : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
      34             : #include <com/sun/star/form/XLoadable.hpp>
      35             : #include <vcl/msgbox.hxx>
      36             : #include <tools/debug.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::form;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::com::sun::star::uno;
      43             : 
      44             : 
      45             : namespace bib
      46             : {
      47             : 
      48             : 
      49             : 
      50           0 :     BibView::BibView( vcl::Window* _pParent, BibDataManager* _pManager, WinBits _nStyle )
      51             :         :BibWindow( _pParent, _nStyle )
      52             :         ,m_pDatMan( _pManager )
      53             :         ,m_xDatMan( _pManager )
      54             :         ,m_pGeneralPage( NULL )
      55           0 :         ,m_aFormControlContainer(this)
      56             :     {
      57           0 :         if ( m_xDatMan.is() )
      58           0 :             m_aFormControlContainer.connectForm( m_xDatMan );
      59           0 :     }
      60             : 
      61             : 
      62           0 :     BibView::~BibView()
      63             :     {
      64           0 :         disposeOnce();
      65           0 :     }
      66             : 
      67           0 :     void BibView::dispose()
      68             :     {
      69           0 :         BibGeneralPage* pGeneralPage = m_pGeneralPage;
      70           0 :         m_pGeneralPage.clear();
      71             : 
      72           0 :         pGeneralPage->CommitActiveControl();
      73           0 :         Reference< XForm > xForm = m_pDatMan->getForm();
      74           0 :         Reference< XPropertySet > xProps( xForm, UNO_QUERY );
      75           0 :         Reference< sdbc::XResultSetUpdate > xResUpd( xProps, UNO_QUERY );
      76             :         DBG_ASSERT( xResUpd.is(), "BibView::~BibView: invalid form!" );
      77             : 
      78           0 :         if ( xResUpd.is() )
      79             :         {
      80           0 :             Any aModified = xProps->getPropertyValue( "IsModified" );
      81           0 :             bool bFlag = false;
      82           0 :             if ( ( aModified >>= bFlag ) && bFlag )
      83             :             {
      84             : 
      85             :                 try
      86             :                 {
      87           0 :                     Any aNew = xProps->getPropertyValue( "IsNew" );
      88           0 :                     aNew >>= bFlag;
      89           0 :                     if ( bFlag )
      90           0 :                         xResUpd->insertRow();
      91             :                     else
      92           0 :                         xResUpd->updateRow();
      93             :                 }
      94           0 :                 catch( const uno::Exception& rEx)
      95             :                 {
      96             :                    (void) rEx;
      97             :                 }
      98           0 :             }
      99             :         }
     100             : 
     101           0 :         if ( m_aFormControlContainer.isFormConnected() )
     102           0 :             m_aFormControlContainer.disconnectForm();
     103             : 
     104           0 :         pGeneralPage->RemoveListeners();
     105           0 :         m_xGeneralPage = NULL;
     106           0 :         BibWindow::dispose();
     107           0 :     }
     108             : 
     109           0 :     void BibView::UpdatePages()
     110             :     {
     111             :         // TODO:
     112             :         // this is _strange_: Why not updating the existent general page?
     113             :         // I consider the current behaviour a HACK.
     114             :         // frank.schoenheit@sun.com
     115           0 :         if ( m_pGeneralPage )
     116             :         {
     117           0 :             m_pGeneralPage->Hide();
     118           0 :             m_pGeneralPage->RemoveListeners();
     119           0 :             m_xGeneralPage = 0;
     120             :         }
     121             : 
     122           0 :         m_pGeneralPage = VclPtr<BibGeneralPage>::Create( this, m_pDatMan );
     123           0 :         m_xGeneralPage = &m_pGeneralPage->GetFocusListener();
     124           0 :         m_pGeneralPage->Show();
     125             : 
     126           0 :         if( HasFocus() )
     127             :             // "delayed" GetFocus() because GetFocus() is initially called before GeneralPage is created
     128           0 :             m_pGeneralPage->GrabFocus();
     129             : 
     130           0 :         OUString sErrorString( m_pGeneralPage->GetErrorString() );
     131           0 :         if ( !sErrorString.isEmpty() )
     132             :         {
     133           0 :             bool bExecute = BibModul::GetConfig()->IsShowColumnAssignmentWarning();
     134           0 :             if(!m_pDatMan->HasActiveConnection())
     135             :             {
     136             :                 //no connection is available -> the data base has to be assigned
     137           0 :                 m_pDatMan->DispatchDBChangeDialog();
     138           0 :                 bExecute = false;
     139             :             }
     140           0 :             else if(bExecute)
     141             :             {
     142           0 :                 sErrorString += "\n";
     143           0 :                 sErrorString += BIB_RESSTR(RID_MAP_QUESTION);
     144           0 :                 ScopedVclPtrInstance< QueryBox > aQuery(this, WB_YES_NO, sErrorString);
     145           0 :                 aQuery->SetDefaultCheckBoxText();
     146           0 :                 short nResult = aQuery->Execute();
     147             :                 BibModul::GetConfig()->SetShowColumnAssignmentWarning(
     148           0 :                     !aQuery->GetCheckBoxState());
     149           0 :                 if( RET_YES != nResult )
     150             :                 {
     151           0 :                     bExecute = false;
     152           0 :                 }
     153             :             }
     154           0 :             if(bExecute)
     155             :             {
     156           0 :                 Application::PostUserEvent( LINK( this, BibView, CallMappingHdl ), NULL, true );
     157             :             }
     158           0 :         }
     159           0 :     }
     160             : 
     161           0 :     BibViewFormControlContainer::BibViewFormControlContainer(BibView *pBibView) : mpBibView(pBibView) {}
     162             : 
     163           0 :     void BibViewFormControlContainer::_loaded( const EventObject& _rEvent )
     164             :     {
     165           0 :         mpBibView->UpdatePages();
     166           0 :         FormControlContainer::_loaded( _rEvent );
     167           0 :         mpBibView->Resize();
     168           0 :     }
     169             : 
     170           0 :     void BibViewFormControlContainer::_reloaded( const EventObject& _rEvent )
     171             :     {
     172           0 :         mpBibView->UpdatePages();
     173           0 :         FormControlContainer::_loaded( _rEvent );
     174           0 :         mpBibView->Resize();
     175           0 :     }
     176             : 
     177           0 :     IMPL_LINK( BibView, CallMappingHdl, BibView*, )
     178             :     {
     179           0 :         m_pDatMan->CreateMappingDialog( this );
     180           0 :         return 0;
     181             :     }
     182             : 
     183           0 :     void BibView::Resize()
     184             :     {
     185           0 :         if ( m_pGeneralPage )
     186             :         {
     187           0 :             ::Size aSz( GetOutputSizePixel() );
     188           0 :             m_pGeneralPage->SetSizePixel( aSz );
     189             :         }
     190           0 :         Window::Resize();
     191           0 :     }
     192             : 
     193           0 :     Reference< awt::XControlContainer > BibViewFormControlContainer::getControlContainer()
     194             :     {
     195           0 :         return mpBibView->getControlContainer();
     196             :     }
     197             : 
     198           0 :     Reference< awt::XControlContainer > BibView::getControlContainer()
     199             :     {
     200           0 :         Reference< awt::XControlContainer > xReturn;
     201           0 :         if ( m_pGeneralPage )
     202           0 :             xReturn = m_pGeneralPage->GetControlContainer();
     203           0 :         return xReturn;
     204             :     }
     205             : 
     206           0 :     void BibView::GetFocus()
     207             :     {
     208           0 :         if( m_pGeneralPage )
     209           0 :             m_pGeneralPage->GrabFocus();
     210           0 :     }
     211             : 
     212           0 :     bool BibView::HandleShortCutKey( const KeyEvent& rKeyEvent )
     213             :     {
     214           0 :         return m_pGeneralPage && m_pGeneralPage->HandleShortCutKey( rKeyEvent );
     215             :     }
     216             : 
     217             : 
     218           6 : }   // namespace bib
     219             : 
     220             : 
     221             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11