LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - mvtabdlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 172 0.0 %
Date: 2014-11-03 Functions: 0 23 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             : #undef SC_DLLIMPLEMENTATION
      21             : 
      22             : #include <vcl/msgbox.hxx>
      23             : 
      24             : #include "mvtabdlg.hxx"
      25             : #include "document.hxx"
      26             : #include "docsh.hxx"
      27             : #include "miscdlgs.hrc"
      28             : #include "global.hxx"
      29             : #include "scresid.hxx"
      30             : #include "globstr.hrc"
      31             : 
      32           0 : ScMoveTableDlg::ScMoveTableDlg(vcl::Window* pParent, const OUString& rDefault)
      33             : 
      34             :     :   ModalDialog ( pParent, "MoveCopySheetDialog", "modules/scalc/ui/movecopysheet.ui" ),
      35             :         maDefaultName( rDefault ),
      36             :         mnCurrentDocPos( 0 ),
      37             :         nDocument   ( 0 ),
      38             :         nTable      ( 0 ),
      39             :         bCopyTable  ( false ),
      40             :         bRenameTable( false ),
      41           0 :         mbEverEdited( false )
      42             : {
      43           0 :     get(pBtnMove, "move");
      44           0 :     get(pBtnCopy, "copy");
      45           0 :     get(pLbDoc, "toDocument");
      46             : 
      47             :     assert(pLbDoc->GetEntryCount() == 2);
      48           0 :     msCurrentDoc = pLbDoc->GetEntry(0);
      49           0 :     msNewDoc = pLbDoc->GetEntry(1);
      50           0 :     pLbDoc->Clear();
      51             :     assert(pLbDoc->GetEntryCount() == 0);
      52             : 
      53           0 :     get(pLbTable, "insertBefore");
      54           0 :     pLbTable->set_height_request(pLbTable->GetTextHeight() * 8);
      55           0 :     get(pEdTabName, "newName");
      56           0 :     get(pFtWarn, "newNameWarn");
      57           0 :     get(pBtnOk, "ok");
      58             : 
      59           0 :     msStrTabNameUsed = get<FixedText>("warnunused")->GetText();
      60           0 :     msStrTabNameEmpty = get<FixedText>("warnempty")->GetText();
      61           0 :     msStrTabNameInvalid = get<FixedText>("warninvalid")->GetText();
      62             : 
      63           0 :     Init();
      64           0 : }
      65             : 
      66           0 : ScMoveTableDlg::~ScMoveTableDlg()
      67             : {
      68           0 : }
      69             : 
      70           0 : void ScMoveTableDlg::GetTabNameString( OUString& rString ) const
      71             : {
      72           0 :     rString = pEdTabName->GetText();
      73           0 : }
      74             : 
      75           0 : void ScMoveTableDlg::SetForceCopyTable()
      76             : {
      77           0 :     pBtnCopy->Check(true);
      78           0 :     pBtnMove->Disable();
      79           0 :     pBtnCopy->Disable();
      80           0 : }
      81             : 
      82           0 : void ScMoveTableDlg::EnableCopyTable(bool bFlag)
      83             : {
      84           0 :     if(bFlag)
      85           0 :         pBtnCopy->Enable();
      86             :     else
      87           0 :         pBtnCopy->Disable();
      88           0 : }
      89             : 
      90           0 : void ScMoveTableDlg::EnableRenameTable(bool bFlag)
      91             : {
      92           0 :     bRenameTable = bFlag;
      93           0 :     pEdTabName->Enable(bFlag);
      94           0 :     ResetRenameInput();
      95           0 : }
      96             : 
      97           0 : void ScMoveTableDlg::ResetRenameInput()
      98             : {
      99           0 :     if (mbEverEdited)
     100             :     {
     101             :         // Don't reset the name when the sheet name has ever been edited.
     102             :         // But check the name, as this is also called for change of copy/move
     103             :         // buttons and document listbox selection.
     104           0 :         CheckNewTabName();
     105           0 :         return;
     106             :     }
     107             : 
     108           0 :     if (!pEdTabName->IsEnabled())
     109             :     {
     110           0 :         pEdTabName->SetText(OUString());
     111           0 :         return;
     112             :     }
     113             : 
     114           0 :     bool bVal = pBtnCopy->IsChecked();
     115           0 :     if (bVal)
     116             :     {
     117             :         // copy
     118           0 :         ScDocument* pDoc = GetSelectedDoc();
     119           0 :         if (pDoc)
     120             :         {
     121           0 :             OUString aStr = maDefaultName;
     122           0 :             pDoc->CreateValidTabName(aStr);
     123           0 :             pEdTabName->SetText(aStr);
     124             :         }
     125             :         else
     126           0 :             pEdTabName->SetText(maDefaultName);
     127             :     }
     128             :     else
     129             :         // move
     130           0 :         pEdTabName->SetText(maDefaultName);
     131             : 
     132           0 :     CheckNewTabName();
     133             : }
     134             : 
     135           0 : void ScMoveTableDlg::CheckNewTabName()
     136             : {
     137           0 :     const OUString aNewName = pEdTabName->GetText();
     138           0 :     if (aNewName.isEmpty())
     139             :     {
     140             :         // New sheet name is empty.  This is not good.
     141           0 :         pFtWarn->Show(true);
     142           0 :         pFtWarn->SetControlBackground(Color(COL_YELLOW));
     143           0 :         pFtWarn->SetText(msStrTabNameEmpty);
     144           0 :         pBtnOk->Disable();
     145           0 :         return;
     146             :     }
     147             : 
     148           0 :     if (!ScDocument::ValidTabName(aNewName))
     149             :     {
     150             :         // New sheet name contains invalid characters.
     151           0 :         pFtWarn->Show(true);
     152           0 :         pFtWarn->SetControlBackground(Color(COL_YELLOW));
     153           0 :         pFtWarn->SetText(msStrTabNameInvalid);
     154           0 :         pBtnOk->Disable();
     155           0 :         return;
     156             :     }
     157             : 
     158           0 :     bool bMoveInCurrentDoc = (pBtnMove->IsChecked() && IsCurrentDocSelected());
     159           0 :     bool bFound = false;
     160           0 :     sal_uInt16 nLast  = pLbTable->GetEntryCount() - 1;
     161           0 :     for ( sal_uInt16 i=0; i<=nLast && !bFound; ++i )
     162             :     {
     163           0 :         if ( aNewName.equals(pLbTable->GetEntry(i)) )
     164             :         {
     165             :             // Only for move within same document the same name is allowed.
     166           0 :             if (!bMoveInCurrentDoc || !maDefaultName.equals( pEdTabName->GetText()))
     167           0 :                 bFound = true;
     168             :         }
     169             :     }
     170             : 
     171           0 :     if ( bFound )
     172             :     {
     173           0 :         pFtWarn->Show(true);
     174           0 :         pFtWarn->SetControlBackground(Color(COL_YELLOW));
     175           0 :         pFtWarn->SetText(msStrTabNameUsed);
     176           0 :         pBtnOk->Disable();
     177             :     }
     178             :     else
     179             :     {
     180           0 :         pFtWarn->Hide();
     181           0 :         pFtWarn->SetControlBackground();
     182           0 :         pFtWarn->SetText(OUString());
     183           0 :         pBtnOk->Enable();
     184           0 :     }
     185             : }
     186             : 
     187           0 : ScDocument* ScMoveTableDlg::GetSelectedDoc()
     188             : {
     189           0 :     sal_Int32 nPos = pLbDoc->GetSelectEntryPos();
     190           0 :     return static_cast<ScDocument*>(pLbDoc->GetEntryData(nPos));
     191             : }
     192             : 
     193           0 : bool ScMoveTableDlg::IsCurrentDocSelected() const
     194             : {
     195           0 :     return pLbDoc->GetSelectEntryPos() == mnCurrentDocPos;
     196             : }
     197             : 
     198           0 : void ScMoveTableDlg::Init()
     199             : {
     200           0 :     pBtnOk->SetClickHdl   ( LINK( this, ScMoveTableDlg, OkHdl ) );
     201           0 :     pLbDoc->SetSelectHdl  ( LINK( this, ScMoveTableDlg, SelHdl ) );
     202           0 :     pBtnCopy->SetToggleHdl( LINK( this, ScMoveTableDlg, CheckBtnHdl ) );
     203           0 :     pEdTabName->SetModifyHdl( LINK( this, ScMoveTableDlg, CheckNameHdl ) );
     204           0 :     pBtnMove->Check( true );
     205           0 :     pBtnCopy->Check( false );
     206           0 :     pEdTabName->Enable(false);
     207           0 :     pFtWarn->Hide();
     208           0 :     InitDocListBox();
     209           0 :     SelHdl( pLbDoc );
     210           0 : }
     211             : 
     212           0 : void ScMoveTableDlg::InitDocListBox()
     213             : {
     214           0 :     SfxObjectShell* pSh     = SfxObjectShell::GetFirst();
     215           0 :     ScDocShell*     pScSh   = NULL;
     216           0 :     sal_uInt16          nSelPos = 0;
     217           0 :     sal_uInt16          i       = 0;
     218           0 :     OUString          aEntryName;
     219             : 
     220           0 :     pLbDoc->Clear();
     221           0 :     pLbDoc->SetUpdateMode( false );
     222             : 
     223           0 :     while ( pSh )
     224             :     {
     225           0 :         pScSh = PTR_CAST( ScDocShell, pSh );
     226             : 
     227           0 :         if ( pScSh )
     228             :         {
     229           0 :             aEntryName = pScSh->GetTitle();
     230             : 
     231           0 :             if ( pScSh == SfxObjectShell::Current() )
     232             :             {
     233           0 :                 mnCurrentDocPos = nSelPos = i;
     234           0 :                 aEntryName += " ";
     235           0 :                 aEntryName += msCurrentDoc;
     236             :             }
     237             : 
     238           0 :             pLbDoc->InsertEntry( aEntryName, i );
     239           0 :             pLbDoc->SetEntryData( i, (void*)&pScSh->GetDocument() );
     240             : 
     241           0 :             i++;
     242             :         }
     243           0 :         pSh = SfxObjectShell::GetNext( *pSh );
     244             :     }
     245             : 
     246           0 :     pLbDoc->SetUpdateMode( true );
     247           0 :     pLbDoc->InsertEntry(msNewDoc);
     248           0 :     pLbDoc->SelectEntryPos( nSelPos );
     249           0 : }
     250             : 
     251             : // Handler:
     252             : 
     253           0 : IMPL_LINK( ScMoveTableDlg, CheckBtnHdl, void *, pBtn )
     254             : {
     255           0 :     if (pBtn == pBtnCopy)
     256           0 :         ResetRenameInput();
     257             : 
     258           0 :     return 0;
     259             : }
     260             : 
     261           0 : IMPL_LINK_NOARG(ScMoveTableDlg, OkHdl)
     262             : {
     263           0 :     sal_uInt16  nDocSel     = pLbDoc->GetSelectEntryPos();
     264           0 :     sal_uInt16  nDocLast    = pLbDoc->GetEntryCount()-1;
     265           0 :     sal_uInt16  nTabSel     = pLbTable->GetSelectEntryPos();
     266           0 :     sal_uInt16  nTabLast    = pLbTable->GetEntryCount()-1;
     267             : 
     268           0 :     nDocument   = (nDocSel != nDocLast) ? nDocSel : SC_DOC_NEW;
     269           0 :     nTable      = (nTabSel != nTabLast) ? static_cast<SCTAB>(nTabSel) : SC_TAB_APPEND;
     270           0 :     bCopyTable  = pBtnCopy->IsChecked();
     271             : 
     272           0 :     if (bCopyTable)
     273             :     {
     274             :         // Return an empty string when the new name is the same as the
     275             :         // automatic name assigned by the document.
     276           0 :         OUString aCopyName = maDefaultName;
     277           0 :         ScDocument* pDoc = GetSelectedDoc();
     278           0 :         if (pDoc)
     279           0 :             pDoc->CreateValidTabName(aCopyName);
     280           0 :         if (aCopyName == pEdTabName->GetText())
     281           0 :             pEdTabName->SetText( OUString() );
     282             :     }
     283             :     else
     284             :     {
     285             :         // Return an empty string, when the new name is the same as the
     286             :         // original name.
     287           0 :         if (maDefaultName.equals(pEdTabName->GetText()))
     288           0 :             pEdTabName->SetText(OUString());
     289             :     }
     290             : 
     291           0 :     EndDialog( RET_OK );
     292             : 
     293           0 :     return 0;
     294             : }
     295             : 
     296           0 : IMPL_LINK( ScMoveTableDlg, SelHdl, ListBox *, pLb )
     297             : {
     298           0 :     if ( pLb == pLbDoc )
     299             :     {
     300           0 :         ScDocument* pDoc = GetSelectedDoc();
     301           0 :         OUString aName;
     302             : 
     303           0 :         pLbTable->Clear();
     304           0 :         pLbTable->SetUpdateMode( false );
     305           0 :         if ( pDoc )
     306             :         {
     307           0 :             SCTAB nLast = pDoc->GetTableCount()-1;
     308           0 :             for ( SCTAB i=0; i<=nLast; i++ )
     309             :             {
     310           0 :                 pDoc->GetName( i, aName );
     311           0 :                 pLbTable->InsertEntry( aName, static_cast<sal_uInt16>(i) );
     312             :             }
     313             :         }
     314           0 :         pLbTable->InsertEntry( ScGlobal::GetRscString(STR_MOVE_TO_END) );
     315           0 :         pLbTable->SetUpdateMode( true );
     316           0 :         pLbTable->SelectEntryPos( 0 );
     317           0 :         ResetRenameInput();
     318             :     }
     319             : 
     320           0 :     return 0;
     321             : }
     322             : 
     323           0 : IMPL_LINK( ScMoveTableDlg, CheckNameHdl, Edit *, pEdt )
     324             : {
     325           0 :     if ( pEdt == pEdTabName )
     326             :     {
     327           0 :         mbEverEdited = true;
     328           0 :         CheckNewTabName();
     329             :     }
     330             : 
     331           0 :     return 0;
     332           0 : }
     333             : 
     334             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10