LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - instbdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 183 0.0 %
Date: 2012-08-25 Functions: 0 25 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #undef SC_DLLIMPLEMENTATION
      31                 :            : 
      32                 :            : 
      33                 :            : 
      34                 :            : //------------------------------------------------------------------
      35                 :            : 
      36                 :            : #include <sfx2/app.hxx>
      37                 :            : #include <sfx2/docfile.hxx>
      38                 :            : #include <sfx2/docinsert.hxx>
      39                 :            : #include <sfx2/filedlghelper.hxx>
      40                 :            : #include <svtools/ehdl.hxx>
      41                 :            : #include <svtools/sfxecode.hxx>
      42                 :            : #include <vcl/msgbox.hxx>
      43                 :            : 
      44                 :            : #include "global.hxx"
      45                 :            : #include "docsh.hxx"
      46                 :            : #include "viewdata.hxx"
      47                 :            : #include "scresid.hxx"
      48                 :            : #include "instbdlg.hrc"
      49                 :            : #include "globstr.hrc"
      50                 :            : 
      51                 :            : #define SC_INSTBDLG_CXX
      52                 :            : #include "instbdlg.hxx"
      53                 :            : 
      54                 :            : //==================================================================
      55                 :            : 
      56                 :          0 : ScInsertTableDlg::ScInsertTableDlg( Window* pParent, ScViewData& rData, SCTAB nTabCount, bool bFromFile )
      57                 :            : 
      58                 :            :     :   ModalDialog ( pParent, ScResId( RID_SCDLG_INSERT_TABLE ) ),
      59                 :            :         //
      60                 :            :         aFlPos          ( this, ScResId( FL_POSITION ) ),
      61                 :            :         aBtnBefore      ( this, ScResId( RB_BEFORE ) ),
      62                 :            :         aBtnBehind      ( this, ScResId( RB_BEHIND ) ),
      63                 :            :         aFlTable        ( this, ScResId( FL_TABLE ) ),
      64                 :            :         aBtnNew         ( this, ScResId( RB_NEW ) ),
      65                 :            :         aBtnFromFile    ( this, ScResId( RB_FROMFILE ) ),
      66                 :            :         aFtCount        ( this, ScResId( FT_COUNT ) ),
      67                 :            :         aNfCount        ( this, ScResId( NF_COUNT ) ),
      68                 :            :         aFtName         ( this, ScResId( FT_NAME ) ),
      69                 :            :         aEdName         ( this, ScResId( ED_TABNAME ) ),
      70                 :            :         aLbTables       ( this, ScResId( LB_TABLES ) ),
      71                 :            :         aFtPath         ( this, ScResId( FT_PATH ) ),
      72                 :            :         aBtnBrowse      ( this, ScResId( BTN_BROWSE ) ),
      73                 :            :         aBtnLink        ( this, ScResId( CB_LINK ) ),
      74                 :            :         aBtnOk          ( this, ScResId( BTN_OK ) ),
      75                 :            :         aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
      76                 :            :         aBtnHelp        ( this, ScResId( BTN_HELP ) ),
      77                 :            :         rViewData       ( rData ),
      78                 :          0 :         rDoc            ( *rData.GetDocument() ),
      79                 :            :         pDocShTables    ( NULL ),
      80                 :            :         pDocInserter    ( NULL ),
      81                 :            :         bMustClose      ( false ),
      82                 :            :         nSelTabIndex    ( 0 ),
      83                 :          0 :         nTableCount     (nTabCount)
      84                 :            : {
      85                 :          0 :     Init_Impl( bFromFile );
      86                 :          0 :     FreeResource();
      87                 :          0 :     aLbTables.SetAccessibleName(aBtnFromFile.GetText());
      88                 :          0 : }
      89                 :            : 
      90                 :            : //------------------------------------------------------------------------
      91                 :            : 
      92                 :          0 : ScInsertTableDlg::~ScInsertTableDlg()
      93                 :            : {
      94                 :          0 :     if (pDocShTables)
      95                 :          0 :         pDocShTables->DoClose();
      96                 :          0 :     delete pDocInserter;
      97                 :          0 : }
      98                 :            : 
      99                 :            : //------------------------------------------------------------------------
     100                 :            : 
     101                 :          0 : void ScInsertTableDlg::Init_Impl( bool bFromFile )
     102                 :            : {
     103                 :          0 :     aBtnBrowse      .SetClickHdl( LINK( this, ScInsertTableDlg, BrowseHdl_Impl ) );
     104                 :          0 :     aBtnNew         .SetClickHdl( LINK( this, ScInsertTableDlg, ChoiceHdl_Impl ) );
     105                 :          0 :     aBtnFromFile    .SetClickHdl( LINK( this, ScInsertTableDlg, ChoiceHdl_Impl ) );
     106                 :          0 :     aLbTables       .SetSelectHdl( LINK( this, ScInsertTableDlg, SelectHdl_Impl ) );
     107                 :          0 :     aNfCount        .SetModifyHdl( LINK( this, ScInsertTableDlg, CountHdl_Impl));
     108                 :          0 :     aBtnOk          .SetClickHdl( LINK( this, ScInsertTableDlg, DoEnterHdl ));
     109                 :          0 :     aBtnBefore.Check();
     110                 :            : 
     111                 :          0 :     aNfCount.SetText( String::CreateFromInt32(nTableCount) );
     112                 :          0 :     aNfCount.SetMax( MAXTAB - rDoc.GetTableCount() + 1 );
     113                 :            : 
     114                 :          0 :     if(nTableCount==1)
     115                 :            :     {
     116                 :          0 :         rtl::OUString aName;
     117                 :          0 :         rDoc.CreateValidTabName( aName );
     118                 :          0 :         aEdName.SetText( aName );
     119                 :            :     }
     120                 :            :     else
     121                 :            :     {
     122                 :          0 :         String aName=aFlTable.GetText();
     123                 :          0 :         aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM("..."));
     124                 :          0 :         aEdName.SetText( aName );
     125                 :          0 :         aFtName.Disable();
     126                 :          0 :         aEdName.Disable();
     127                 :            :     }
     128                 :            : 
     129                 :          0 :     bool bShared = ( rViewData.GetDocShell() ? rViewData.GetDocShell()->IsDocShared() : false );
     130                 :            : 
     131                 :          0 :     if ( !bFromFile || bShared )
     132                 :            :     {
     133                 :          0 :         aBtnNew.Check();
     134                 :          0 :         SetNewTable_Impl();
     135                 :          0 :         if ( bShared )
     136                 :            :         {
     137                 :          0 :             aBtnFromFile.Disable();
     138                 :            :         }
     139                 :            :     }
     140                 :            :     else
     141                 :            :     {
     142                 :          0 :         aBtnFromFile.Check();
     143                 :          0 :         SetFromTo_Impl();
     144                 :            : 
     145                 :          0 :         aBrowseTimer.SetTimeoutHdl( LINK( this, ScInsertTableDlg, BrowseTimeoutHdl ) );
     146                 :          0 :         aBrowseTimer.SetTimeout( 200 );
     147                 :            :     }
     148                 :          0 : }
     149                 :            : 
     150                 :            : //------------------------------------------------------------------------
     151                 :            : 
     152                 :          0 : short ScInsertTableDlg::Execute()
     153                 :            : {
     154                 :            :     // set Parent of DocumentInserter and Doc-Manager
     155                 :          0 :     Window* pOldDefParent = Application::GetDefDialogParent();
     156                 :          0 :     Application::SetDefDialogParent( this );
     157                 :            : 
     158                 :          0 :     if ( aBtnFromFile.IsChecked() )
     159                 :          0 :         aBrowseTimer.Start();
     160                 :            : 
     161                 :          0 :     short nRet = ModalDialog::Execute();
     162                 :          0 :     Application::SetDefDialogParent( pOldDefParent );
     163                 :          0 :     return nRet;
     164                 :            : }
     165                 :            : 
     166                 :            : //------------------------------------------------------------------------
     167                 :            : 
     168                 :          0 : void ScInsertTableDlg::SetNewTable_Impl()
     169                 :            : {
     170                 :          0 :     if (aBtnNew.IsChecked() )
     171                 :            :     {
     172                 :          0 :         aNfCount    .Enable();
     173                 :          0 :         aFtCount    .Enable();
     174                 :          0 :         aLbTables   .Disable();
     175                 :          0 :         aFtPath     .Disable();
     176                 :          0 :         aBtnBrowse  .Disable();
     177                 :          0 :         aBtnLink    .Disable();
     178                 :            : 
     179                 :          0 :         if(nTableCount==1)
     180                 :            :         {
     181                 :          0 :             aEdName.Enable();
     182                 :          0 :             aFtName.Enable();
     183                 :            :         }
     184                 :            :     }
     185                 :          0 : }
     186                 :            : 
     187                 :            : //------------------------------------------------------------------------
     188                 :            : 
     189                 :          0 : void ScInsertTableDlg::SetFromTo_Impl()
     190                 :            : {
     191                 :          0 :     if (aBtnFromFile.IsChecked() )
     192                 :            :     {
     193                 :          0 :         aEdName     .Disable();
     194                 :          0 :         aFtName     .Disable();
     195                 :          0 :         aFtCount    .Disable();
     196                 :          0 :         aNfCount    .Disable();
     197                 :          0 :         aLbTables   .Enable();
     198                 :          0 :         aFtPath     .Enable();
     199                 :          0 :         aBtnBrowse  .Enable();
     200                 :          0 :         aBtnLink    .Enable();
     201                 :            :     }
     202                 :          0 : }
     203                 :            : 
     204                 :            : //------------------------------------------------------------------------
     205                 :            : 
     206                 :          0 : void ScInsertTableDlg::FillTables_Impl( ScDocument* pSrcDoc )
     207                 :            : {
     208                 :          0 :     aLbTables.SetUpdateMode( false );
     209                 :          0 :     aLbTables.Clear();
     210                 :            : 
     211                 :          0 :     if ( pSrcDoc )
     212                 :            :     {
     213                 :          0 :         SCTAB nCount = pSrcDoc->GetTableCount();
     214                 :          0 :         rtl::OUString aName;
     215                 :            : 
     216                 :          0 :         for ( SCTAB i=0; i<nCount; i++ )
     217                 :            :         {
     218                 :          0 :             pSrcDoc->GetName( i, aName );
     219                 :          0 :             aLbTables.InsertEntry( aName );
     220                 :          0 :         }
     221                 :            :     }
     222                 :            : 
     223                 :          0 :     aLbTables.SetUpdateMode( sal_True );
     224                 :            : 
     225                 :          0 :     if(aLbTables.GetEntryCount()==1)
     226                 :          0 :         aLbTables.SelectEntryPos(0);
     227                 :          0 : }
     228                 :            : 
     229                 :            : //------------------------------------------------------------------------
     230                 :            : 
     231                 :          0 : const String* ScInsertTableDlg::GetFirstTable( sal_uInt16* pN )
     232                 :            : {
     233                 :          0 :     const String* pStr = NULL;
     234                 :            : 
     235                 :          0 :     if ( aBtnNew.IsChecked() )
     236                 :            :     {
     237                 :          0 :         aStrCurSelTable = aEdName.GetText();
     238                 :          0 :         pStr = &aStrCurSelTable;
     239                 :            :     }
     240                 :          0 :     else if ( nSelTabIndex < aLbTables.GetSelectEntryCount() )
     241                 :            :     {
     242                 :          0 :         aStrCurSelTable = aLbTables.GetSelectEntry( 0 );
     243                 :          0 :         pStr = &aStrCurSelTable;
     244                 :          0 :         if ( pN )
     245                 :          0 :             *pN = aLbTables.GetSelectEntryPos( 0 );
     246                 :          0 :         nSelTabIndex = 1;
     247                 :            :     }
     248                 :            : 
     249                 :          0 :     return pStr;
     250                 :            : }
     251                 :            : 
     252                 :            : //------------------------------------------------------------------------
     253                 :            : 
     254                 :          0 : const String* ScInsertTableDlg::GetNextTable( sal_uInt16* pN )
     255                 :            : {
     256                 :          0 :     const String* pStr = NULL;
     257                 :            : 
     258                 :          0 :     if ( !aBtnNew.IsChecked() && nSelTabIndex < aLbTables.GetSelectEntryCount() )
     259                 :            :     {
     260                 :          0 :         aStrCurSelTable = aLbTables.GetSelectEntry( nSelTabIndex );
     261                 :          0 :         pStr = &aStrCurSelTable;
     262                 :          0 :         if ( pN )
     263                 :          0 :             *pN = aLbTables.GetSelectEntryPos( nSelTabIndex );
     264                 :          0 :         nSelTabIndex++;
     265                 :            :     }
     266                 :            : 
     267                 :          0 :     return pStr;
     268                 :            : }
     269                 :            : 
     270                 :            : 
     271                 :            : //------------------------------------------------------------------------
     272                 :            : // Handler:
     273                 :            : //------------------------------------------------------------------------
     274                 :            : 
     275                 :          0 : IMPL_LINK_NOARG(ScInsertTableDlg, CountHdl_Impl)
     276                 :            : {
     277                 :          0 :     nTableCount = static_cast<SCTAB>(aNfCount.GetValue());
     278                 :          0 :     if ( nTableCount==1)
     279                 :            :     {
     280                 :          0 :         rtl::OUString aName;
     281                 :          0 :         rDoc.CreateValidTabName( aName );
     282                 :          0 :         aEdName.SetText( aName );
     283                 :          0 :         aFtName.Enable();
     284                 :          0 :         aEdName.Enable();
     285                 :            :     }
     286                 :            :     else
     287                 :            :     {
     288                 :          0 :         String aName=aFlTable.GetText();
     289                 :          0 :         aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM("..."));
     290                 :          0 :         aEdName.SetText( aName );
     291                 :          0 :         aFtName.Disable();
     292                 :          0 :         aEdName.Disable();
     293                 :            :     }
     294                 :            : 
     295                 :          0 :     DoEnable_Impl();
     296                 :          0 :     return 0;
     297                 :            : }
     298                 :            : 
     299                 :            : //------------------------------------------------------------------------
     300                 :          0 : IMPL_LINK_NOARG(ScInsertTableDlg, ChoiceHdl_Impl)
     301                 :            : {
     302                 :          0 :     if ( aBtnNew.IsChecked() )
     303                 :          0 :         SetNewTable_Impl();
     304                 :            :     else
     305                 :          0 :         SetFromTo_Impl();
     306                 :            : 
     307                 :          0 :     DoEnable_Impl();
     308                 :          0 :     return 0;
     309                 :            : }
     310                 :            : 
     311                 :            : //------------------------------------------------------------------------
     312                 :            : 
     313                 :          0 : IMPL_LINK_NOARG(ScInsertTableDlg, BrowseHdl_Impl)
     314                 :            : {
     315                 :          0 :     if ( pDocInserter )
     316                 :          0 :         delete pDocInserter;
     317                 :            :     pDocInserter = new ::sfx2::DocumentInserter(
     318                 :          0 :             rtl::OUString::createFromAscii( ScDocShell::Factory().GetShortName() ) );
     319                 :          0 :     pDocInserter->StartExecuteModal( LINK( this, ScInsertTableDlg, DialogClosedHdl ) );
     320                 :          0 :     return 0;
     321                 :            : }
     322                 :            : 
     323                 :            : //------------------------------------------------------------------------
     324                 :            : 
     325                 :          0 : IMPL_LINK_NOARG(ScInsertTableDlg, SelectHdl_Impl)
     326                 :            : {
     327                 :          0 :     DoEnable_Impl();
     328                 :          0 :     return 0;
     329                 :            : }
     330                 :            : 
     331                 :            : //------------------------------------------------------------------------
     332                 :            : 
     333                 :          0 : void ScInsertTableDlg::DoEnable_Impl()
     334                 :            : {
     335                 :          0 :     if ( aBtnNew.IsChecked() || ( pDocShTables && aLbTables.GetSelectEntryCount() ) )
     336                 :          0 :         aBtnOk.Enable();
     337                 :            :     else
     338                 :          0 :         aBtnOk.Disable();
     339                 :          0 : }
     340                 :            : 
     341                 :          0 : IMPL_LINK_NOARG(ScInsertTableDlg, DoEnterHdl)
     342                 :            : {
     343                 :          0 :     if(nTableCount > 1 || rDoc.ValidTabName(aEdName.GetText()))
     344                 :            :     {
     345                 :          0 :         EndDialog(RET_OK);
     346                 :            :     }
     347                 :            :     else
     348                 :            :     {
     349                 :          0 :         String aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
     350                 :          0 :         (void)ErrorBox( this,WinBits( WB_OK | WB_DEF_OK ),aErrMsg).Execute();
     351                 :            :     }
     352                 :          0 :     return 0;
     353                 :            : }
     354                 :            : 
     355                 :          0 : IMPL_LINK_NOARG(ScInsertTableDlg, BrowseTimeoutHdl)
     356                 :            : {
     357                 :          0 :     bMustClose = true;
     358                 :          0 :     BrowseHdl_Impl( &aBtnBrowse );
     359                 :          0 :     return 0;
     360                 :            : }
     361                 :            : 
     362                 :          0 : IMPL_LINK( ScInsertTableDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
     363                 :            : {
     364                 :          0 :     if ( ERRCODE_NONE == _pFileDlg->GetError() )
     365                 :            :     {
     366                 :          0 :         SfxMedium* pMed = pDocInserter->CreateMedium();
     367                 :          0 :         if ( pMed )
     368                 :            :         {
     369                 :            :             //  ERRCTX_SFX_OPENDOC -> "Fehler beim Laden des Dokumentes"
     370                 :          0 :             SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() );
     371                 :            : 
     372                 :          0 :             if ( pDocShTables )
     373                 :          0 :                 pDocShTables->DoClose();        // delete passiert beim Zuweisen auf die Ref
     374                 :            : 
     375                 :          0 :             pMed->UseInteractionHandler( sal_True );    // to enable the filter options dialog
     376                 :            : 
     377                 :          0 :             pDocShTables = new ScDocShell;
     378                 :          0 :             aDocShTablesRef = pDocShTables;
     379                 :            : 
     380                 :          0 :             Pointer aOldPtr( GetPointer() );
     381                 :          0 :             SetPointer( Pointer( POINTER_WAIT ) );
     382                 :          0 :             pDocShTables->DoLoad( pMed );
     383                 :          0 :             SetPointer( aOldPtr );
     384                 :            : 
     385                 :          0 :             sal_uLong nErr = pDocShTables->GetErrorCode();
     386                 :          0 :             if ( nErr )
     387                 :          0 :                 ErrorHandler::HandleError( nErr );              // auch Warnings
     388                 :            : 
     389                 :          0 :             if ( !pDocShTables->GetError() )                    // nur Errors
     390                 :            :             {
     391                 :          0 :                 FillTables_Impl( pDocShTables->GetDocument() );
     392                 :          0 :                 aFtPath.SetText( pDocShTables->GetTitle( SFX_TITLE_FULLNAME ) );
     393                 :            :             }
     394                 :            :             else
     395                 :            :             {
     396                 :          0 :                 pDocShTables->DoClose();
     397                 :          0 :                 aDocShTablesRef.Clear();
     398                 :          0 :                 pDocShTables = NULL;
     399                 :            : 
     400                 :          0 :                 FillTables_Impl( NULL );
     401                 :          0 :                 aFtPath.SetText( EMPTY_STRING );
     402                 :          0 :             }
     403                 :            :         }
     404                 :            : 
     405                 :          0 :         DoEnable_Impl();
     406                 :            :     }
     407                 :          0 :     else if ( bMustClose )
     408                 :            :         // execute slot FID_INS_TABLE_EXT and cancel file dialog
     409                 :          0 :         EndDialog( RET_CANCEL );
     410                 :            : 
     411                 :          0 :     return 0;
     412                 :            : }
     413                 :            : 
     414                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10