LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/miscdlgs - instbdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 194 0.0 %
Date: 2013-07-09 Functions: 0 27 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             : 
      21             : #undef SC_DLLIMPLEMENTATION
      22             : 
      23             : 
      24             : 
      25             : //------------------------------------------------------------------
      26             : 
      27             : #include <sfx2/app.hxx>
      28             : #include <sfx2/docfile.hxx>
      29             : #include <sfx2/docinsert.hxx>
      30             : #include <sfx2/filedlghelper.hxx>
      31             : #include <svtools/ehdl.hxx>
      32             : #include <svtools/sfxecode.hxx>
      33             : #include <vcl/msgbox.hxx>
      34             : 
      35             : #include "global.hxx"
      36             : #include "docsh.hxx"
      37             : #include "viewdata.hxx"
      38             : #include "scresid.hxx"
      39             : #include "globstr.hrc"
      40             : 
      41             : #define SC_INSTBDLG_CXX
      42             : #include "instbdlg.hxx"
      43             : 
      44             : //==================================================================
      45             : 
      46           0 : ScInsertTableDlg::ScInsertTableDlg( Window* pParent, ScViewData& rData, SCTAB nTabCount, bool bFromFile )
      47             :     : ModalDialog(pParent, "InsertSheetDialog", "modules/scalc/ui/insertsheet.ui")
      48             :     , rViewData(rData)
      49           0 :     , rDoc(*rData.GetDocument())
      50             :     , pDocShTables(NULL)
      51             :     , pDocInserter(NULL)
      52             :     , bMustClose(false)
      53             :     , nSelTabIndex(0)
      54           0 :     , nTableCount(nTabCount)
      55             : {
      56           0 :     get(m_pBtnBefore, "before");
      57           0 :     get(m_pBtnBehind, "after");
      58           0 :     get(m_pBtnNew, "new");
      59           0 :     get(m_pBtnFromFile, "fromfile");
      60           0 :     get(m_pFtCount, "countft");
      61           0 :     get(m_pNfCount, "countnf");
      62           0 :     get(m_pFtName, "nameft");
      63           0 :     get(m_pEdName, "nameed");
      64           0 :     m_sSheetDotDotDot = m_pEdName->GetText();
      65           0 :     get(m_pLbTables, "tables");
      66           0 :     m_pLbTables->SetDropDownLineCount(8);
      67           0 :     get(m_pFtPath, "path");
      68           0 :     get(m_pBtnBrowse, "browse");
      69           0 :     get(m_pBtnLink, "link");
      70           0 :     get(m_pBtnOk, "ok");
      71           0 :     Init_Impl( bFromFile );
      72           0 : }
      73             : 
      74             : //------------------------------------------------------------------------
      75             : 
      76           0 : ScInsertTableDlg::~ScInsertTableDlg()
      77             : {
      78           0 :     if (pDocShTables)
      79           0 :         pDocShTables->DoClose();
      80           0 :     delete pDocInserter;
      81           0 : }
      82             : 
      83             : //------------------------------------------------------------------------
      84             : 
      85           0 : void ScInsertTableDlg::Init_Impl( bool bFromFile )
      86             : {
      87           0 :     m_pLbTables->EnableMultiSelection(true);
      88           0 :     m_pBtnBrowse->SetClickHdl( LINK( this, ScInsertTableDlg, BrowseHdl_Impl ) );
      89           0 :     m_pBtnNew->SetClickHdl( LINK( this, ScInsertTableDlg, ChoiceHdl_Impl ) );
      90           0 :     m_pBtnFromFile->SetClickHdl( LINK( this, ScInsertTableDlg, ChoiceHdl_Impl ) );
      91           0 :     m_pLbTables->SetSelectHdl( LINK( this, ScInsertTableDlg, SelectHdl_Impl ) );
      92           0 :     m_pNfCount->SetModifyHdl( LINK( this, ScInsertTableDlg, CountHdl_Impl));
      93           0 :     m_pBtnOk->SetClickHdl( LINK( this, ScInsertTableDlg, DoEnterHdl ));
      94           0 :     m_pBtnBefore->Check();
      95             : 
      96           0 :     m_pNfCount->SetText( OUString::number(nTableCount) );
      97           0 :     m_pNfCount->SetMax( MAXTAB - rDoc.GetTableCount() + 1 );
      98             : 
      99           0 :     if(nTableCount==1)
     100             :     {
     101           0 :         OUString aName;
     102           0 :         rDoc.CreateValidTabName( aName );
     103           0 :         m_pEdName->SetText( aName );
     104             :     }
     105             :     else
     106             :     {
     107           0 :         m_pEdName->SetText(m_sSheetDotDotDot);
     108           0 :         m_pFtName->Disable();
     109           0 :         m_pEdName->Disable();
     110             :     }
     111             : 
     112           0 :     bool bShared = ( rViewData.GetDocShell() ? rViewData.GetDocShell()->IsDocShared() : false );
     113             : 
     114           0 :     if ( !bFromFile || bShared )
     115             :     {
     116           0 :         m_pBtnNew->Check();
     117           0 :         SetNewTable_Impl();
     118           0 :         if ( bShared )
     119             :         {
     120           0 :             m_pBtnFromFile->Disable();
     121             :         }
     122             :     }
     123             :     else
     124             :     {
     125           0 :         m_pBtnFromFile->Check();
     126           0 :         SetFromTo_Impl();
     127             : 
     128           0 :         aBrowseTimer.SetTimeoutHdl( LINK( this, ScInsertTableDlg, BrowseTimeoutHdl ) );
     129           0 :         aBrowseTimer.SetTimeout( 200 );
     130             :     }
     131           0 : }
     132             : 
     133             : //------------------------------------------------------------------------
     134             : 
     135           0 : short ScInsertTableDlg::Execute()
     136             : {
     137             :     // set Parent of DocumentInserter and Doc-Manager
     138           0 :     Window* pOldDefParent = Application::GetDefDialogParent();
     139           0 :     Application::SetDefDialogParent( this );
     140             : 
     141           0 :     if ( m_pBtnFromFile->IsChecked() )
     142           0 :         aBrowseTimer.Start();
     143             : 
     144           0 :     short nRet = ModalDialog::Execute();
     145           0 :     Application::SetDefDialogParent( pOldDefParent );
     146           0 :     return nRet;
     147             : }
     148             : 
     149             : //------------------------------------------------------------------------
     150             : 
     151           0 : void ScInsertTableDlg::SetNewTable_Impl()
     152             : {
     153           0 :     if (m_pBtnNew->IsChecked() )
     154             :     {
     155           0 :         m_pNfCount->Enable();
     156           0 :         m_pFtCount->Enable();
     157           0 :         m_pLbTables->Disable();
     158           0 :         m_pFtPath->Disable();
     159           0 :         m_pBtnBrowse->Disable();
     160           0 :         m_pBtnLink->Disable();
     161             : 
     162           0 :         if(nTableCount==1)
     163             :         {
     164           0 :             m_pEdName->Enable();
     165           0 :             m_pFtName->Enable();
     166             :         }
     167             :     }
     168           0 : }
     169             : 
     170             : //------------------------------------------------------------------------
     171             : 
     172           0 : void ScInsertTableDlg::SetFromTo_Impl()
     173             : {
     174           0 :     if (m_pBtnFromFile->IsChecked() )
     175             :     {
     176           0 :         m_pEdName->Disable();
     177           0 :         m_pFtName->Disable();
     178           0 :         m_pFtCount->Disable();
     179           0 :         m_pNfCount->Disable();
     180           0 :         m_pLbTables->Enable();
     181           0 :         m_pFtPath->Enable();
     182           0 :         m_pBtnBrowse->Enable();
     183           0 :         m_pBtnLink->Enable();
     184             :     }
     185           0 : }
     186             : 
     187             : //------------------------------------------------------------------------
     188             : 
     189           0 : void ScInsertTableDlg::FillTables_Impl( ScDocument* pSrcDoc )
     190             : {
     191           0 :     m_pLbTables->SetUpdateMode( false );
     192           0 :     m_pLbTables->Clear();
     193             : 
     194           0 :     if ( pSrcDoc )
     195             :     {
     196           0 :         SCTAB nCount = pSrcDoc->GetTableCount();
     197           0 :         OUString aName;
     198             : 
     199           0 :         for ( SCTAB i=0; i<nCount; i++ )
     200             :         {
     201           0 :             pSrcDoc->GetName( i, aName );
     202           0 :             m_pLbTables->InsertEntry( aName );
     203           0 :         }
     204             :     }
     205             : 
     206           0 :     m_pLbTables->SetUpdateMode( sal_True );
     207             : 
     208           0 :     if(m_pLbTables->GetEntryCount()==1)
     209           0 :         m_pLbTables->SelectEntryPos(0);
     210           0 : }
     211             : 
     212             : //------------------------------------------------------------------------
     213             : 
     214           0 : const String* ScInsertTableDlg::GetFirstTable( sal_uInt16* pN )
     215             : {
     216           0 :     const String* pStr = NULL;
     217             : 
     218           0 :     if ( m_pBtnNew->IsChecked() )
     219             :     {
     220           0 :         aStrCurSelTable = m_pEdName->GetText();
     221           0 :         pStr = &aStrCurSelTable;
     222             :     }
     223           0 :     else if ( nSelTabIndex < m_pLbTables->GetSelectEntryCount() )
     224             :     {
     225           0 :         aStrCurSelTable = m_pLbTables->GetSelectEntry( 0 );
     226           0 :         pStr = &aStrCurSelTable;
     227           0 :         if ( pN )
     228           0 :             *pN = m_pLbTables->GetSelectEntryPos( 0 );
     229           0 :         nSelTabIndex = 1;
     230             :     }
     231             : 
     232           0 :     return pStr;
     233             : }
     234             : 
     235             : //------------------------------------------------------------------------
     236             : 
     237           0 : const String* ScInsertTableDlg::GetNextTable( sal_uInt16* pN )
     238             : {
     239           0 :     const String* pStr = NULL;
     240             : 
     241           0 :     if ( !m_pBtnNew->IsChecked() && nSelTabIndex < m_pLbTables->GetSelectEntryCount() )
     242             :     {
     243           0 :         aStrCurSelTable = m_pLbTables->GetSelectEntry( nSelTabIndex );
     244           0 :         pStr = &aStrCurSelTable;
     245           0 :         if ( pN )
     246           0 :             *pN = m_pLbTables->GetSelectEntryPos( nSelTabIndex );
     247           0 :         nSelTabIndex++;
     248             :     }
     249             : 
     250           0 :     return pStr;
     251             : }
     252             : 
     253             : 
     254             : //------------------------------------------------------------------------
     255             : // Handler:
     256             : //------------------------------------------------------------------------
     257             : 
     258           0 : IMPL_LINK_NOARG(ScInsertTableDlg, CountHdl_Impl)
     259             : {
     260           0 :     nTableCount = static_cast<SCTAB>(m_pNfCount->GetValue());
     261           0 :     if ( nTableCount==1)
     262             :     {
     263           0 :         OUString aName;
     264           0 :         rDoc.CreateValidTabName( aName );
     265           0 :         m_pEdName->SetText( aName );
     266           0 :         m_pFtName->Enable();
     267           0 :         m_pEdName->Enable();
     268             :     }
     269             :     else
     270             :     {
     271           0 :         m_pEdName->SetText(m_sSheetDotDotDot);
     272           0 :         m_pFtName->Disable();
     273           0 :         m_pEdName->Disable();
     274             :     }
     275             : 
     276           0 :     DoEnable_Impl();
     277           0 :     return 0;
     278             : }
     279             : 
     280             : //------------------------------------------------------------------------
     281           0 : IMPL_LINK_NOARG(ScInsertTableDlg, ChoiceHdl_Impl)
     282             : {
     283           0 :     if ( m_pBtnNew->IsChecked() )
     284           0 :         SetNewTable_Impl();
     285             :     else
     286           0 :         SetFromTo_Impl();
     287             : 
     288           0 :     DoEnable_Impl();
     289           0 :     return 0;
     290             : }
     291             : 
     292             : //------------------------------------------------------------------------
     293             : 
     294           0 : IMPL_LINK_NOARG(ScInsertTableDlg, BrowseHdl_Impl)
     295             : {
     296           0 :     if ( pDocInserter )
     297           0 :         delete pDocInserter;
     298             :     pDocInserter = new ::sfx2::DocumentInserter(
     299           0 :             OUString::createFromAscii( ScDocShell::Factory().GetShortName() ) );
     300           0 :     pDocInserter->StartExecuteModal( LINK( this, ScInsertTableDlg, DialogClosedHdl ) );
     301           0 :     return 0;
     302             : }
     303             : 
     304             : //------------------------------------------------------------------------
     305             : 
     306           0 : IMPL_LINK_NOARG(ScInsertTableDlg, SelectHdl_Impl)
     307             : {
     308           0 :     DoEnable_Impl();
     309           0 :     return 0;
     310             : }
     311             : 
     312             : //------------------------------------------------------------------------
     313             : 
     314           0 : void ScInsertTableDlg::DoEnable_Impl()
     315             : {
     316           0 :     if ( m_pBtnNew->IsChecked() || ( pDocShTables && m_pLbTables->GetSelectEntryCount() ) )
     317           0 :         m_pBtnOk->Enable();
     318             :     else
     319           0 :         m_pBtnOk->Disable();
     320           0 : }
     321             : 
     322           0 : IMPL_LINK_NOARG(ScInsertTableDlg, DoEnterHdl)
     323             : {
     324           0 :     if(nTableCount > 1 || rDoc.ValidTabName(m_pEdName->GetText()))
     325             :     {
     326           0 :         EndDialog(RET_OK);
     327             :     }
     328             :     else
     329             :     {
     330           0 :         String aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
     331           0 :         (void)ErrorBox( this,WinBits( WB_OK | WB_DEF_OK ),aErrMsg).Execute();
     332             :     }
     333           0 :     return 0;
     334             : }
     335             : 
     336           0 : IMPL_LINK_NOARG(ScInsertTableDlg, BrowseTimeoutHdl)
     337             : {
     338           0 :     bMustClose = true;
     339           0 :     BrowseHdl_Impl(m_pBtnBrowse);
     340           0 :     return 0;
     341             : }
     342             : 
     343           0 : IMPL_LINK( ScInsertTableDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
     344             : {
     345           0 :     if ( ERRCODE_NONE == _pFileDlg->GetError() )
     346             :     {
     347           0 :         SfxMedium* pMed = pDocInserter->CreateMedium();
     348           0 :         if ( pMed )
     349             :         {
     350             :             //  ERRCTX_SFX_OPENDOC -> "Fehler beim Laden des Dokumentes"
     351           0 :             SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() );
     352             : 
     353           0 :             if ( pDocShTables )
     354           0 :                 pDocShTables->DoClose();        // delete passiert beim Zuweisen auf die Ref
     355             : 
     356           0 :             pMed->UseInteractionHandler( sal_True );    // to enable the filter options dialog
     357             : 
     358           0 :             pDocShTables = new ScDocShell;
     359           0 :             aDocShTablesRef = pDocShTables;
     360             : 
     361           0 :             Pointer aOldPtr( GetPointer() );
     362           0 :             SetPointer( Pointer( POINTER_WAIT ) );
     363           0 :             pDocShTables->DoLoad( pMed );
     364           0 :             SetPointer( aOldPtr );
     365             : 
     366           0 :             sal_uLong nErr = pDocShTables->GetErrorCode();
     367           0 :             if ( nErr )
     368           0 :                 ErrorHandler::HandleError( nErr );              // auch Warnings
     369             : 
     370           0 :             if ( !pDocShTables->GetError() )                    // nur Errors
     371             :             {
     372           0 :                 FillTables_Impl( pDocShTables->GetDocument() );
     373           0 :                 m_pFtPath->SetText( pDocShTables->GetTitle( SFX_TITLE_FULLNAME ) );
     374             :             }
     375             :             else
     376             :             {
     377           0 :                 pDocShTables->DoClose();
     378           0 :                 aDocShTablesRef.Clear();
     379           0 :                 pDocShTables = NULL;
     380             : 
     381           0 :                 FillTables_Impl( NULL );
     382           0 :                 m_pFtPath->SetText( EMPTY_STRING );
     383           0 :             }
     384             :         }
     385             : 
     386           0 :         DoEnable_Impl();
     387             :     }
     388           0 :     else if ( bMustClose )
     389             :         // execute slot FID_INS_TABLE_EXT and cancel file dialog
     390           0 :         EndDialog( RET_CANCEL );
     391             : 
     392           0 :     return 0;
     393           0 : }
     394             : 
     395             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10