LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - tabopdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 186 0.5 %
Date: 2015-06-13 12:38:46 Functions: 2 18 11.1 %
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             : #include "scitems.hxx"
      21             : #include <sfx2/dispatch.hxx>
      22             : #include <vcl/layout.hxx>
      23             : 
      24             : #include "uiitems.hxx"
      25             : #include "global.hxx"
      26             : #include "document.hxx"
      27             : #include "scresid.hxx"
      28             : #include "sc.hrc"
      29             : #include "reffact.hxx"
      30             : 
      31             : #include "tabopdlg.hxx"
      32             : 
      33             : //  class ScTabOpDlg
      34             : 
      35           0 : ScTabOpDlg::ScTabOpDlg( SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* pParent,
      36             :                         ScDocument*         pDocument,
      37             :                         const ScRefAddress& rCursorPos )
      38             : 
      39             :     : ScAnyRefDlg(pB, pCW, pParent, "MultipleOperationsDialog",
      40             :         "modules/scalc/ui/multipleoperationsdialog.ui")
      41             :     , theFormulaCell(rCursorPos)
      42             :     , pDoc(pDocument)
      43           0 :     , nCurTab(theFormulaCell.Tab())
      44             :     , pEdActive(NULL)
      45             :     , bDlgLostFocus(false)
      46             :     , errMsgNoFormula(ScResId(STR_NOFORMULASPECIFIED))
      47             :     , errMsgNoColRow(ScResId(STR_NOCOLROW))
      48             :     , errMsgWrongFormula(ScResId(STR_WRONGFORMULA))
      49             :     , errMsgWrongRowCol(ScResId(STR_WRONGROWCOL))
      50             :     , errMsgNoColFormula(ScResId(STR_NOCOLFORMULA))
      51           0 :     , errMsgNoRowFormula(ScResId(STR_NOROWFORMULA))
      52             : {
      53           0 :     get(m_pFtFormulaRange, "formulasft");
      54           0 :     get(m_pEdFormulaRange, "formulas");
      55           0 :     m_pEdFormulaRange->SetReferences(this, m_pFtFormulaRange);
      56           0 :     get(m_pRBFormulaRange, "formulasref");
      57           0 :     m_pRBFormulaRange->SetReferences(this, m_pEdFormulaRange);
      58             : 
      59           0 :     get(m_pFtRowCell, "rowft");
      60           0 :     get(m_pEdRowCell, "row");
      61           0 :     m_pEdRowCell->SetReferences(this, m_pFtRowCell);
      62           0 :     get(m_pRBRowCell, "rowref");
      63           0 :     m_pRBRowCell->SetReferences(this, m_pEdRowCell);
      64             : 
      65           0 :     get(m_pFtColCell, "colft");
      66           0 :     get(m_pEdColCell, "col");
      67           0 :     m_pEdColCell->SetReferences(this, m_pFtColCell);
      68           0 :     get(m_pRBColCell, "colref");
      69           0 :     m_pRBColCell->SetReferences(this, m_pEdColCell);
      70             : 
      71           0 :     get(m_pBtnOk, "ok");
      72           0 :     get(m_pBtnCancel, "cancel");
      73             : 
      74           0 :     Init();
      75           0 : }
      76             : 
      77           0 : ScTabOpDlg::~ScTabOpDlg()
      78             : {
      79           0 :     disposeOnce();
      80           0 : }
      81             : 
      82           0 : void ScTabOpDlg::dispose()
      83             : {
      84           0 :     Hide();
      85           0 :     m_pFtFormulaRange.clear();
      86           0 :     m_pEdFormulaRange.clear();
      87           0 :     m_pRBFormulaRange.clear();
      88           0 :     m_pFtRowCell.clear();
      89           0 :     m_pEdRowCell.clear();
      90           0 :     m_pRBRowCell.clear();
      91           0 :     m_pFtColCell.clear();
      92           0 :     m_pEdColCell.clear();
      93           0 :     m_pRBColCell.clear();
      94           0 :     m_pBtnOk.clear();
      95           0 :     m_pBtnCancel.clear();
      96           0 :     pEdActive.clear();
      97           0 :     ScAnyRefDlg::dispose();
      98           0 : }
      99             : 
     100             : 
     101           0 : void ScTabOpDlg::Init()
     102             : {
     103           0 :     m_pBtnOk->SetClickHdl     ( LINK( this, ScTabOpDlg, BtnHdl ) );
     104           0 :     m_pBtnCancel->SetClickHdl     ( LINK( this, ScTabOpDlg, BtnHdl ) );
     105             : 
     106           0 :     Link<> aLink = LINK( this, ScTabOpDlg, GetFocusHdl );
     107           0 :     m_pEdFormulaRange->SetGetFocusHdl( aLink );
     108           0 :     m_pRBFormulaRange->SetGetFocusHdl( aLink );
     109           0 :     m_pEdRowCell->SetGetFocusHdl( aLink );
     110           0 :     m_pRBRowCell->SetGetFocusHdl( aLink );
     111           0 :     m_pEdColCell->SetGetFocusHdl( aLink );
     112           0 :     m_pRBColCell->SetGetFocusHdl( aLink );
     113             : 
     114           0 :     aLink = LINK( this, ScTabOpDlg, LoseFocusHdl );
     115           0 :     m_pEdFormulaRange->SetLoseFocusHdl( aLink );
     116           0 :     m_pRBFormulaRange->SetLoseFocusHdl( aLink );
     117           0 :     m_pEdRowCell->SetLoseFocusHdl( aLink );
     118           0 :     m_pRBRowCell->SetLoseFocusHdl( aLink );
     119           0 :     m_pEdColCell->SetLoseFocusHdl( aLink );
     120           0 :     m_pRBColCell->SetLoseFocusHdl( aLink );
     121             : 
     122           0 :     m_pEdFormulaRange->GrabFocus();
     123           0 :     pEdActive = m_pEdFormulaRange;
     124             : 
     125             :     //@BugID 54702 Enable/Disable only in the base class
     126             :     //SFX_APPWINDOW->Enable();
     127           0 : }
     128             : 
     129           0 : bool ScTabOpDlg::Close()
     130             : {
     131           0 :     return DoClose( ScTabOpDlgWrapper::GetChildWindowId() );
     132             : }
     133             : 
     134           0 : void ScTabOpDlg::SetActive()
     135             : {
     136           0 :     if ( bDlgLostFocus )
     137             :     {
     138           0 :         bDlgLostFocus = false;
     139           0 :         if( pEdActive )
     140           0 :             pEdActive->GrabFocus();
     141             :     }
     142             :     else
     143           0 :         GrabFocus();
     144             : 
     145           0 :     RefInputDone();
     146           0 : }
     147             : 
     148           0 : void ScTabOpDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
     149             : {
     150           0 :     if ( pEdActive )
     151             :     {
     152           0 :         ScAddress::Details aDetails(pDocP->GetAddressConvention(), 0, 0);
     153             : 
     154           0 :         if ( rRef.aStart != rRef.aEnd )
     155           0 :             RefInputStart(pEdActive);
     156             : 
     157           0 :         OUString      aStr;
     158           0 :         sal_uInt16      nFmt = ( rRef.aStart.Tab() == nCurTab )
     159             :                                 ? SCR_ABS
     160           0 :                                 : SCR_ABS_3D;
     161             : 
     162           0 :         if (pEdActive == m_pEdFormulaRange)
     163             :         {
     164           0 :             theFormulaCell.Set( rRef.aStart, false, false, false);
     165           0 :             theFormulaEnd.Set( rRef.aEnd, false, false, false);
     166           0 :             aStr = rRef.Format(nFmt, pDocP, aDetails);
     167             :         }
     168           0 :         else if ( pEdActive == m_pEdRowCell )
     169             :         {
     170           0 :             theRowCell.Set( rRef.aStart, false, false, false);
     171           0 :             aStr = rRef.aStart.Format(nFmt, pDocP, aDetails);
     172             :         }
     173           0 :         else if ( pEdActive == m_pEdColCell )
     174             :         {
     175           0 :             theColCell.Set( rRef.aStart, false, false, false);
     176           0 :             aStr = rRef.aStart.Format(nFmt, pDocP, aDetails);
     177             :         }
     178             : 
     179           0 :         pEdActive->SetRefString( aStr );
     180             :     }
     181           0 : }
     182             : 
     183           0 : void ScTabOpDlg::RaiseError( ScTabOpErr eError )
     184             : {
     185           0 :     const OUString* pMsg = &errMsgNoFormula;
     186           0 :     Edit*           pEd  = m_pEdFormulaRange;
     187             : 
     188           0 :     switch ( eError )
     189             :     {
     190             :         case TABOPERR_NOFORMULA:
     191           0 :             pMsg = &errMsgNoFormula;
     192           0 :             pEd  = m_pEdFormulaRange;
     193           0 :             break;
     194             : 
     195             :         case TABOPERR_NOCOLROW:
     196           0 :             pMsg = &errMsgNoColRow;
     197           0 :             pEd  = m_pEdRowCell;
     198           0 :             break;
     199             : 
     200             :         case TABOPERR_WRONGFORMULA:
     201           0 :             pMsg = &errMsgWrongFormula;
     202           0 :             pEd  = m_pEdFormulaRange;
     203           0 :             break;
     204             : 
     205             :         case TABOPERR_WRONGROW:
     206           0 :             pMsg = &errMsgWrongRowCol;
     207           0 :             pEd  = m_pEdRowCell;
     208           0 :             break;
     209             : 
     210             :         case TABOPERR_NOCOLFORMULA:
     211           0 :             pMsg = &errMsgNoColFormula;
     212           0 :             pEd  = m_pEdFormulaRange;
     213           0 :             break;
     214             : 
     215             :         case TABOPERR_WRONGCOL:
     216           0 :             pMsg = &errMsgWrongRowCol;
     217           0 :             pEd  = m_pEdColCell;
     218           0 :             break;
     219             : 
     220             :         case TABOPERR_NOROWFORMULA:
     221           0 :             pMsg = &errMsgNoRowFormula;
     222           0 :             pEd  = m_pEdFormulaRange;
     223           0 :             break;
     224             :     }
     225             : 
     226           0 :     ScopedVclPtrInstance<MessageDialog>::Create(this, *pMsg, VCL_MESSAGE_ERROR, VCL_BUTTONS_OK_CANCEL)->Execute();
     227           0 :     pEd->GrabFocus();
     228           0 : }
     229             : 
     230           0 : static bool lcl_Parse( const OUString& rString, ScDocument* pDoc, SCTAB nCurTab,
     231             :                 ScRefAddress& rStart, ScRefAddress& rEnd )
     232             : {
     233           0 :     bool bRet = false;
     234           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     235           0 :     if ( rString.indexOf(':') != -1 )
     236           0 :         bRet = ConvertDoubleRef( pDoc, rString, nCurTab, rStart, rEnd, eConv );
     237             :     else
     238             :     {
     239           0 :         bRet = ConvertSingleRef( pDoc, rString, nCurTab, rStart, eConv );
     240           0 :         rEnd = rStart;
     241             :     }
     242           0 :     return bRet;
     243             : }
     244             : 
     245             : // Handler:
     246             : 
     247           0 : IMPL_LINK( ScTabOpDlg, BtnHdl, PushButton*, pBtn )
     248             : {
     249           0 :     if (pBtn == m_pBtnOk)
     250             :     {
     251           0 :         ScTabOpParam::Mode eMode = ScTabOpParam::Column;
     252           0 :         sal_uInt16 nError = 0;
     253             : 
     254             :         // The following code checks:
     255             :         // 1. do the strings contain correct cell references / defined names?
     256             :         // 2. is formula range row if row is empty or column if column is empty
     257             :         //    or single reference if both?
     258             :         // 3. is at least one of row or column non-empty?
     259             : 
     260           0 :         if (m_pEdFormulaRange->GetText().isEmpty())
     261           0 :             nError = TABOPERR_NOFORMULA;
     262           0 :         else if (m_pEdRowCell->GetText().isEmpty() &&
     263           0 :                  m_pEdColCell->GetText().isEmpty())
     264           0 :             nError = TABOPERR_NOCOLROW;
     265           0 :         else if ( !lcl_Parse( m_pEdFormulaRange->GetText(), pDoc, nCurTab,
     266           0 :                                 theFormulaCell, theFormulaEnd ) )
     267           0 :             nError = TABOPERR_WRONGFORMULA;
     268             :         else
     269             :         {
     270           0 :             const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     271           0 :             if (!m_pEdRowCell->GetText().isEmpty())
     272             :             {
     273           0 :                 if (!ConvertSingleRef( pDoc, m_pEdRowCell->GetText(), nCurTab,
     274           0 :                                        theRowCell, eConv ))
     275           0 :                     nError = TABOPERR_WRONGROW;
     276             :                 else
     277             :                 {
     278           0 :                     if (m_pEdColCell->GetText().isEmpty() &&
     279           0 :                         theFormulaCell.Col() != theFormulaEnd.Col())
     280           0 :                         nError = TABOPERR_NOCOLFORMULA;
     281             :                     else
     282           0 :                         eMode = ScTabOpParam::Row;
     283             :                 }
     284             :             }
     285           0 :             if (!m_pEdColCell->GetText().isEmpty())
     286             :             {
     287           0 :                 if (!ConvertSingleRef( pDoc, m_pEdColCell->GetText(), nCurTab,
     288           0 :                                        theColCell, eConv ))
     289           0 :                     nError = TABOPERR_WRONGCOL;
     290             :                 else
     291             :                 {
     292           0 :                     if (eMode == ScTabOpParam::Row)                         // both
     293             :                     {
     294           0 :                         eMode = ScTabOpParam::Both;
     295           0 :                         ConvertSingleRef( pDoc, m_pEdFormulaRange->GetText(), nCurTab,
     296           0 :                                           theFormulaCell, eConv );
     297             :                     }
     298           0 :                     else if (theFormulaCell.Row() != theFormulaEnd.Row())
     299           0 :                         nError = TABOPERR_NOROWFORMULA;
     300             :                     else
     301           0 :                         eMode = ScTabOpParam::Column;
     302             :                 }
     303             :             }
     304             :         }
     305             : 
     306           0 :         if (nError)
     307           0 :             RaiseError( (ScTabOpErr) nError );
     308             :         else
     309             :         {
     310           0 :             ScTabOpParam aOutParam(theFormulaCell, theFormulaEnd, theRowCell, theColCell, eMode);
     311           0 :             ScTabOpItem  aOutItem( SID_TABOP, &aOutParam );
     312             : 
     313           0 :             SetDispatcherLock( false );
     314           0 :             SwitchToDocument();
     315           0 :             GetBindings().GetDispatcher()->Execute( SID_TABOP,
     316             :                                       SfxCallMode::SLOT | SfxCallMode::RECORD,
     317           0 :                                       &aOutItem, 0L, 0L );
     318           0 :             Close();
     319             :         }
     320             :     }
     321           0 :     else if (pBtn == m_pBtnCancel)
     322           0 :         Close();
     323             : 
     324           0 :     return 0;
     325             : }
     326             : 
     327           0 : IMPL_LINK( ScTabOpDlg, GetFocusHdl, Control*, pCtrl )
     328             : {
     329           0 :     if( (pCtrl == static_cast<Control*>(m_pEdFormulaRange)) || (pCtrl == static_cast<Control*>(m_pRBFormulaRange)) )
     330           0 :         pEdActive = m_pEdFormulaRange;
     331           0 :     else if( (pCtrl == static_cast<Control*>(m_pEdRowCell)) || (pCtrl == static_cast<Control*>(m_pRBRowCell)) )
     332           0 :         pEdActive = m_pEdRowCell;
     333           0 :     else if( (pCtrl == static_cast<Control*>(m_pEdColCell)) || (pCtrl == static_cast<Control*>(m_pRBColCell)) )
     334           0 :         pEdActive = m_pEdColCell;
     335             :     else
     336           0 :         pEdActive = NULL;
     337             : 
     338           0 :     if( pEdActive )
     339           0 :         pEdActive->SetSelection( Selection( 0, SELECTION_MAX ) );
     340             : 
     341           0 :     return 0;
     342             : }
     343             : 
     344           0 : IMPL_LINK_NOARG(ScTabOpDlg, LoseFocusHdl)
     345             : {
     346           0 :     bDlgLostFocus = !IsActive();
     347           0 :     return 0;
     348         156 : }
     349             : 
     350             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11