LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - mvtabdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 157 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 <vcl/msgbox.hxx>
      37                 :            : 
      38                 :            : #include "mvtabdlg.hxx"
      39                 :            : #include "document.hxx"
      40                 :            : #include "docsh.hxx"
      41                 :            : #include "miscdlgs.hrc"
      42                 :            : #include "global.hxx"
      43                 :            : #include "scresid.hxx"
      44                 :            : #include "globstr.hrc"
      45                 :            : 
      46                 :            : //==================================================================
      47                 :            : 
      48                 :          0 : ScMoveTableDlg::ScMoveTableDlg(Window* pParent, const rtl::OUString& rDefault)
      49                 :            : 
      50                 :            :     :   ModalDialog ( pParent, ScResId( RID_SCDLG_MOVETAB ) ),
      51                 :            :         //
      52                 :            :         aFlAction   ( this, ScResId( FL_ACTION ) ),
      53                 :            :         aBtnMove    ( this, ScResId( BTN_MOVE ) ),
      54                 :            :         aBtnCopy    ( this, ScResId( BTN_COPY ) ),
      55                 :            :         aFlLocation ( this, ScResId( FL_LOCATION ) ),
      56                 :            :         aFtDoc      ( this, ScResId( FT_DEST ) ),
      57                 :            :         aLbDoc      ( this, ScResId( LB_DEST ) ),
      58                 :            :         aFtTable    ( this, ScResId( FT_INSERT ) ),
      59                 :            :         aLbTable    ( this, ScResId( LB_INSERT ) ),
      60                 :            :         aFlName     ( this, ScResId( FL_NAME ) ),
      61                 :            :         aFtTabName  ( this, ScResId( FT_TABNAME ) ),
      62                 :            :         aEdTabName  ( this, ScResId( ED_INPUT ) ),
      63                 :            :         aFtWarn     ( this, ScResId( FT_TABNAME_WARN ) ),
      64                 :            :         aBtnOk      ( this, ScResId( BTN_OK ) ),
      65                 :            :         aBtnCancel  ( this, ScResId( BTN_CANCEL ) ),
      66                 :            :         aBtnHelp    ( this, ScResId( BTN_HELP ) ),
      67                 :            : 
      68                 :            :         maStrTabNameUsed( SC_RESSTR(STR_TABNAME_WARN_USED) ),
      69                 :            :         maStrTabNameEmpty( SC_RESSTR(STR_TABNAME_WARN_EMPTY) ),
      70                 :            :         maStrTabNameInvalid( SC_RESSTR(STR_TABNAME_WARN_INVALID) ),
      71                 :            :         //
      72                 :            :         maDefaultName( rDefault ),
      73                 :            :         mnCurrentDocPos( 0 ),
      74                 :            :         nDocument   ( 0 ),
      75                 :            :         nTable      ( 0 ),
      76                 :            :         bCopyTable  ( false ),
      77                 :            :         bRenameTable( false ),
      78                 :          0 :         mbEverEdited( false )
      79                 :            : {
      80                 :          0 :     Init();
      81                 :          0 :     FreeResource();
      82                 :          0 : }
      83                 :            : 
      84                 :            : //------------------------------------------------------------------------
      85                 :            : 
      86                 :          0 : ScMoveTableDlg::~ScMoveTableDlg()
      87                 :            : {
      88                 :          0 : }
      89                 :            : 
      90                 :            : //------------------------------------------------------------------------
      91                 :            : 
      92                 :          0 : sal_uInt16 ScMoveTableDlg::GetSelectedDocument () const { return nDocument;  }
      93                 :            : 
      94                 :          0 : SCTAB ScMoveTableDlg::GetSelectedTable    () const { return nTable;     }
      95                 :            : 
      96                 :          0 : bool   ScMoveTableDlg::GetCopyTable        () const { return bCopyTable; }
      97                 :            : 
      98                 :          0 : bool   ScMoveTableDlg::GetRenameTable        () const { return bRenameTable; }
      99                 :            : 
     100                 :          0 : void ScMoveTableDlg::GetTabNameString( rtl::OUString& rString ) const
     101                 :            : {
     102                 :          0 :     rString = aEdTabName.GetText();
     103                 :          0 : }
     104                 :            : 
     105                 :          0 : void ScMoveTableDlg::SetForceCopyTable()
     106                 :            : {
     107                 :          0 :     aBtnCopy.Check(true);
     108                 :          0 :     aBtnMove.Disable();
     109                 :          0 :     aBtnCopy.Disable();
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : void ScMoveTableDlg::EnableCopyTable(sal_Bool bFlag)
     113                 :            : {
     114                 :          0 :     if(bFlag)
     115                 :          0 :         aBtnCopy.Enable();
     116                 :            :     else
     117                 :          0 :         aBtnCopy.Disable();
     118                 :          0 : }
     119                 :            : 
     120                 :          0 : void ScMoveTableDlg::EnableRenameTable(sal_Bool bFlag)
     121                 :            : {
     122                 :          0 :     bRenameTable = bFlag;
     123                 :          0 :     aEdTabName.Enable(bFlag);
     124                 :          0 :     aFtTabName.Enable(bFlag);
     125                 :          0 :     ResetRenameInput();
     126                 :          0 : }
     127                 :            : 
     128                 :          0 : void ScMoveTableDlg::ResetRenameInput()
     129                 :            : {
     130                 :          0 :     if (mbEverEdited)
     131                 :            :     {
     132                 :            :         // Don't reset the name when the sheet name has ever been edited.
     133                 :            :         // But check the name, as this is also called for change of copy/move
     134                 :            :         // buttons and document listbox selection.
     135                 :          0 :         CheckNewTabName();
     136                 :          0 :         return;
     137                 :            :     }
     138                 :            : 
     139                 :          0 :     if (!aEdTabName.IsEnabled())
     140                 :            :     {
     141                 :          0 :         aEdTabName.SetText(String());
     142                 :          0 :         return;
     143                 :            :     }
     144                 :            : 
     145                 :          0 :     bool bVal = aBtnCopy.IsChecked();
     146                 :          0 :     if (bVal)
     147                 :            :     {
     148                 :            :         // copy
     149                 :          0 :         ScDocument* pDoc = GetSelectedDoc();
     150                 :          0 :         if (pDoc)
     151                 :            :         {
     152                 :          0 :             rtl::OUString aStr = maDefaultName;
     153                 :          0 :             pDoc->CreateValidTabName(aStr);
     154                 :          0 :             aEdTabName.SetText(aStr);
     155                 :            :         }
     156                 :            :         else
     157                 :          0 :             aEdTabName.SetText(maDefaultName);
     158                 :            :     }
     159                 :            :     else
     160                 :            :         // move
     161                 :          0 :         aEdTabName.SetText(maDefaultName);
     162                 :            : 
     163                 :          0 :     CheckNewTabName();
     164                 :            : }
     165                 :            : 
     166                 :          0 : void ScMoveTableDlg::CheckNewTabName()
     167                 :            : {
     168                 :          0 :     const rtl::OUString aNewName = aEdTabName.GetText();
     169                 :          0 :     if (aNewName.isEmpty())
     170                 :            :     {
     171                 :            :         // New sheet name is empty.  This is not good.
     172                 :          0 :         aFtWarn.SetText(maStrTabNameEmpty);
     173                 :          0 :         aFtWarn.Show();
     174                 :          0 :         aBtnOk.Disable();
     175                 :            :         return;
     176                 :            :     }
     177                 :            : 
     178                 :          0 :     if (!ScDocument::ValidTabName(aNewName))
     179                 :            :     {
     180                 :            :         // New sheet name contains invalid characters.
     181                 :          0 :         aFtWarn.SetText(maStrTabNameInvalid);
     182                 :          0 :         aFtWarn.Show();
     183                 :          0 :         aBtnOk.Disable();
     184                 :            :         return;
     185                 :            :     }
     186                 :            : 
     187                 :          0 :     bool bMoveInCurrentDoc = (aBtnMove.IsChecked() && IsCurrentDocSelected());
     188                 :          0 :     bool bFound = false;
     189                 :          0 :     sal_uInt16 nLast  = aLbTable.GetEntryCount() - 1;
     190                 :          0 :     for ( sal_uInt16 i=0; i<=nLast && !bFound; ++i )
     191                 :            :     {
     192                 :          0 :         if ( aNewName.equals(aLbTable.GetEntry(i)) )
     193                 :            :         {
     194                 :            :             // Only for move within same document the same name is allowed.
     195                 :          0 :             if (!bMoveInCurrentDoc || !maDefaultName.equals( aEdTabName.GetText()))
     196                 :          0 :                 bFound = true;
     197                 :            :         }
     198                 :            :     }
     199                 :            : 
     200                 :          0 :     if ( bFound )
     201                 :            :     {
     202                 :          0 :         aFtWarn.SetText(maStrTabNameUsed);
     203                 :          0 :         aFtWarn.Show();
     204                 :          0 :         aBtnOk.Disable();
     205                 :            :     }
     206                 :            :     else
     207                 :            :     {
     208                 :          0 :         aFtWarn.Hide();
     209                 :          0 :         aBtnOk.Enable();
     210                 :          0 :     }
     211                 :            : }
     212                 :            : 
     213                 :          0 : ScDocument* ScMoveTableDlg::GetSelectedDoc()
     214                 :            : {
     215                 :          0 :     sal_uInt16 nPos = aLbDoc.GetSelectEntryPos();
     216                 :          0 :     return static_cast<ScDocument*>(aLbDoc.GetEntryData(nPos));
     217                 :            : }
     218                 :            : 
     219                 :          0 : bool ScMoveTableDlg::IsCurrentDocSelected() const
     220                 :            : {
     221                 :          0 :     return aLbDoc.GetSelectEntryPos() == mnCurrentDocPos;
     222                 :            : }
     223                 :            : 
     224                 :            : //------------------------------------------------------------------------
     225                 :            : 
     226                 :          0 : void ScMoveTableDlg::Init()
     227                 :            : {
     228                 :          0 :     aBtnOk.SetClickHdl   ( LINK( this, ScMoveTableDlg, OkHdl ) );
     229                 :          0 :     aLbDoc.SetSelectHdl  ( LINK( this, ScMoveTableDlg, SelHdl ) );
     230                 :          0 :     aBtnCopy.SetToggleHdl( LINK( this, ScMoveTableDlg, CheckBtnHdl ) );
     231                 :          0 :     aEdTabName.SetModifyHdl( LINK( this, ScMoveTableDlg, CheckNameHdl ) );
     232                 :          0 :     aBtnMove.Check( true );
     233                 :          0 :     aBtnCopy.Check( false );
     234                 :          0 :     aEdTabName.Enable(false);
     235                 :          0 :     aFtWarn.SetControlBackground( Color( COL_YELLOW ) );
     236                 :          0 :     aFtWarn.Hide();
     237                 :          0 :     InitDocListBox();
     238                 :          0 :     SelHdl( &aLbDoc );
     239                 :          0 : }
     240                 :            : 
     241                 :            : //------------------------------------------------------------------------
     242                 :            : 
     243                 :          0 : void ScMoveTableDlg::InitDocListBox()
     244                 :            : {
     245                 :          0 :     SfxObjectShell* pSh     = SfxObjectShell::GetFirst();
     246                 :          0 :     ScDocShell*     pScSh   = NULL;
     247                 :          0 :     sal_uInt16          nSelPos = 0;
     248                 :          0 :     sal_uInt16          i       = 0;
     249                 :          0 :     String          aEntryName;
     250                 :            : 
     251                 :          0 :     aLbDoc.Clear();
     252                 :          0 :     aLbDoc.SetUpdateMode( false );
     253                 :            : 
     254                 :          0 :     while ( pSh )
     255                 :            :     {
     256                 :          0 :         pScSh = PTR_CAST( ScDocShell, pSh );
     257                 :            : 
     258                 :          0 :         if ( pScSh )
     259                 :            :         {
     260                 :          0 :             aEntryName = pScSh->GetTitle();
     261                 :            : 
     262                 :          0 :             if ( pScSh == SfxObjectShell::Current() )
     263                 :            :             {
     264                 :          0 :                 mnCurrentDocPos = nSelPos = i;
     265                 :          0 :                 aEntryName += sal_Unicode( ' ' );
     266                 :          0 :                 aEntryName += String( ScResId( STR_CURRENTDOC ) );
     267                 :            :             }
     268                 :            : 
     269                 :          0 :             aLbDoc.InsertEntry( aEntryName, i );
     270                 :          0 :             aLbDoc.SetEntryData( i, (void*)pScSh->GetDocument() );
     271                 :            : 
     272                 :          0 :             i++;
     273                 :            :         }
     274                 :          0 :         pSh = SfxObjectShell::GetNext( *pSh );
     275                 :            :     }
     276                 :            : 
     277                 :          0 :     aLbDoc.SetUpdateMode( sal_True );
     278                 :          0 :     aLbDoc.InsertEntry( String( ScResId( STR_NEWDOC ) ) );
     279                 :          0 :     aLbDoc.SelectEntryPos( nSelPos );
     280                 :          0 : }
     281                 :            : 
     282                 :            : //------------------------------------------------------------------------
     283                 :            : // Handler:
     284                 :            : 
     285                 :          0 : IMPL_LINK( ScMoveTableDlg, CheckBtnHdl, void *, pBtn )
     286                 :            : {
     287                 :          0 :     if (pBtn == &aBtnCopy)
     288                 :          0 :         ResetRenameInput();
     289                 :            : 
     290                 :          0 :     return 0;
     291                 :            : }
     292                 :            : 
     293                 :          0 : IMPL_LINK_NOARG(ScMoveTableDlg, OkHdl)
     294                 :            : {
     295                 :          0 :     sal_uInt16  nDocSel     = aLbDoc.GetSelectEntryPos();
     296                 :          0 :     sal_uInt16  nDocLast    = aLbDoc.GetEntryCount()-1;
     297                 :          0 :     sal_uInt16  nTabSel     = aLbTable.GetSelectEntryPos();
     298                 :          0 :     sal_uInt16  nTabLast    = aLbTable.GetEntryCount()-1;
     299                 :            : 
     300                 :          0 :     nDocument   = (nDocSel != nDocLast) ? nDocSel : SC_DOC_NEW;
     301                 :          0 :     nTable      = (nTabSel != nTabLast) ? static_cast<SCTAB>(nTabSel) : SC_TAB_APPEND;
     302                 :          0 :     bCopyTable  = aBtnCopy.IsChecked();
     303                 :            : 
     304                 :          0 :     if (bCopyTable)
     305                 :            :     {
     306                 :            :         // Return an empty string when the new name is the same as the
     307                 :            :         // automatic name assigned by the document.
     308                 :          0 :         rtl::OUString aCopyName = maDefaultName;
     309                 :          0 :         ScDocument* pDoc = GetSelectedDoc();
     310                 :          0 :         if (pDoc)
     311                 :          0 :             pDoc->CreateValidTabName(aCopyName);
     312                 :          0 :         if (aCopyName == rtl::OUString(aEdTabName.GetText()))
     313                 :          0 :             aEdTabName.SetText( rtl::OUString() );
     314                 :            :     }
     315                 :            :     else
     316                 :            :     {
     317                 :            :         // Return an empty string, when the new name is the same as the
     318                 :            :         // original name.
     319                 :          0 :         if (maDefaultName.equals(aEdTabName.GetText()))
     320                 :          0 :             aEdTabName.SetText(rtl::OUString());
     321                 :            :     }
     322                 :            : 
     323                 :          0 :     EndDialog( RET_OK );
     324                 :            : 
     325                 :          0 :     return 0;
     326                 :            : }
     327                 :            : 
     328                 :          0 : IMPL_LINK( ScMoveTableDlg, SelHdl, ListBox *, pLb )
     329                 :            : {
     330                 :          0 :     if ( pLb == &aLbDoc )
     331                 :            :     {
     332                 :          0 :         ScDocument* pDoc = GetSelectedDoc();
     333                 :          0 :         rtl::OUString aName;
     334                 :            : 
     335                 :          0 :         aLbTable.Clear();
     336                 :          0 :         aLbTable.SetUpdateMode( false );
     337                 :          0 :         if ( pDoc )
     338                 :            :         {
     339                 :          0 :             SCTAB nLast = pDoc->GetTableCount()-1;
     340                 :          0 :             for ( SCTAB i=0; i<=nLast; i++ )
     341                 :            :             {
     342                 :          0 :                 pDoc->GetName( i, aName );
     343                 :          0 :                 aLbTable.InsertEntry( aName, static_cast<sal_uInt16>(i) );
     344                 :            :             }
     345                 :            :         }
     346                 :          0 :         aLbTable.InsertEntry( ScGlobal::GetRscString(STR_MOVE_TO_END) );
     347                 :          0 :         aLbTable.SetUpdateMode( sal_True );
     348                 :          0 :         aLbTable.SelectEntryPos( 0 );
     349                 :          0 :         ResetRenameInput();
     350                 :            :     }
     351                 :            : 
     352                 :          0 :     return 0;
     353                 :            : }
     354                 :            : 
     355                 :          0 : IMPL_LINK( ScMoveTableDlg, CheckNameHdl, Edit *, pEdt )
     356                 :            : {
     357                 :          0 :     if ( pEdt == &aEdTabName )
     358                 :            :     {
     359                 :          0 :         mbEverEdited = true;
     360                 :          0 :         CheckNewTabName();
     361                 :            :     }
     362                 :            : 
     363                 :          0 :     return 0;
     364                 :            : }
     365                 :            : 
     366                 :            : 
     367                 :            : 
     368                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10