LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - tabopdlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 170 0.6 %
Date: 2014-11-03 Functions: 2 17 11.8 %
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 :     Hide();
      80           0 : }
      81             : 
      82           0 : void ScTabOpDlg::Init()
      83             : {
      84           0 :     m_pBtnOk->SetClickHdl     ( LINK( this, ScTabOpDlg, BtnHdl ) );
      85           0 :     m_pBtnCancel->SetClickHdl     ( LINK( this, ScTabOpDlg, BtnHdl ) );
      86             : 
      87           0 :     Link aLink = LINK( this, ScTabOpDlg, GetFocusHdl );
      88           0 :     m_pEdFormulaRange->SetGetFocusHdl( aLink );
      89           0 :     m_pRBFormulaRange->SetGetFocusHdl( aLink );
      90           0 :     m_pEdRowCell->SetGetFocusHdl( aLink );
      91           0 :     m_pRBRowCell->SetGetFocusHdl( aLink );
      92           0 :     m_pEdColCell->SetGetFocusHdl( aLink );
      93           0 :     m_pRBColCell->SetGetFocusHdl( aLink );
      94             : 
      95           0 :     aLink = LINK( this, ScTabOpDlg, LoseFocusHdl );
      96           0 :     m_pEdFormulaRange->SetLoseFocusHdl( aLink );
      97           0 :     m_pRBFormulaRange->SetLoseFocusHdl( aLink );
      98           0 :     m_pEdRowCell->SetLoseFocusHdl( aLink );
      99           0 :     m_pRBRowCell->SetLoseFocusHdl( aLink );
     100           0 :     m_pEdColCell->SetLoseFocusHdl( aLink );
     101           0 :     m_pRBColCell->SetLoseFocusHdl( aLink );
     102             : 
     103           0 :     m_pEdFormulaRange->GrabFocus();
     104           0 :     pEdActive = m_pEdFormulaRange;
     105             : 
     106             :     //@BugID 54702 Enable/Disable only in the base class
     107             :     //SFX_APPWINDOW->Enable();
     108           0 : }
     109             : 
     110           0 : bool ScTabOpDlg::Close()
     111             : {
     112           0 :     return DoClose( ScTabOpDlgWrapper::GetChildWindowId() );
     113             : }
     114             : 
     115           0 : void ScTabOpDlg::SetActive()
     116             : {
     117           0 :     if ( bDlgLostFocus )
     118             :     {
     119           0 :         bDlgLostFocus = false;
     120           0 :         if( pEdActive )
     121           0 :             pEdActive->GrabFocus();
     122             :     }
     123             :     else
     124           0 :         GrabFocus();
     125             : 
     126           0 :     RefInputDone();
     127           0 : }
     128             : 
     129           0 : void ScTabOpDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
     130             : {
     131           0 :     if ( pEdActive )
     132             :     {
     133           0 :         ScAddress::Details aDetails(pDocP->GetAddressConvention(), 0, 0);
     134             : 
     135           0 :         if ( rRef.aStart != rRef.aEnd )
     136           0 :             RefInputStart(pEdActive);
     137             : 
     138           0 :         OUString      aStr;
     139           0 :         sal_uInt16      nFmt = ( rRef.aStart.Tab() == nCurTab )
     140             :                                 ? SCR_ABS
     141           0 :                                 : SCR_ABS_3D;
     142             : 
     143           0 :         if (pEdActive == m_pEdFormulaRange)
     144             :         {
     145           0 :             theFormulaCell.Set( rRef.aStart, false, false, false);
     146           0 :             theFormulaEnd.Set( rRef.aEnd, false, false, false);
     147           0 :             aStr = rRef.Format(nFmt, pDocP, aDetails);
     148             :         }
     149           0 :         else if ( pEdActive == m_pEdRowCell )
     150             :         {
     151           0 :             theRowCell.Set( rRef.aStart, false, false, false);
     152           0 :             aStr = rRef.aStart.Format(nFmt, pDocP, aDetails);
     153             :         }
     154           0 :         else if ( pEdActive == m_pEdColCell )
     155             :         {
     156           0 :             theColCell.Set( rRef.aStart, false, false, false);
     157           0 :             aStr = rRef.aStart.Format(nFmt, pDocP, aDetails);
     158             :         }
     159             : 
     160           0 :         pEdActive->SetRefString( aStr );
     161             :     }
     162           0 : }
     163             : 
     164           0 : void ScTabOpDlg::RaiseError( ScTabOpErr eError )
     165             : {
     166           0 :     const OUString* pMsg = &errMsgNoFormula;
     167           0 :     Edit*           pEd  = m_pEdFormulaRange;
     168             : 
     169           0 :     switch ( eError )
     170             :     {
     171             :         case TABOPERR_NOFORMULA:
     172           0 :             pMsg = &errMsgNoFormula;
     173           0 :             pEd  = m_pEdFormulaRange;
     174           0 :             break;
     175             : 
     176             :         case TABOPERR_NOCOLROW:
     177           0 :             pMsg = &errMsgNoColRow;
     178           0 :             pEd  = m_pEdRowCell;
     179           0 :             break;
     180             : 
     181             :         case TABOPERR_WRONGFORMULA:
     182           0 :             pMsg = &errMsgWrongFormula;
     183           0 :             pEd  = m_pEdFormulaRange;
     184           0 :             break;
     185             : 
     186             :         case TABOPERR_WRONGROW:
     187           0 :             pMsg = &errMsgWrongRowCol;
     188           0 :             pEd  = m_pEdRowCell;
     189           0 :             break;
     190             : 
     191             :         case TABOPERR_NOCOLFORMULA:
     192           0 :             pMsg = &errMsgNoColFormula;
     193           0 :             pEd  = m_pEdFormulaRange;
     194           0 :             break;
     195             : 
     196             :         case TABOPERR_WRONGCOL:
     197           0 :             pMsg = &errMsgWrongRowCol;
     198           0 :             pEd  = m_pEdColCell;
     199           0 :             break;
     200             : 
     201             :         case TABOPERR_NOROWFORMULA:
     202           0 :             pMsg = &errMsgNoRowFormula;
     203           0 :             pEd  = m_pEdFormulaRange;
     204           0 :             break;
     205             :     }
     206             : 
     207           0 :     MessageDialog(this, *pMsg, VCL_MESSAGE_ERROR, VCL_BUTTONS_OK_CANCEL).Execute();
     208           0 :     pEd->GrabFocus();
     209           0 : }
     210             : 
     211           0 : static bool lcl_Parse( const OUString& rString, ScDocument* pDoc, SCTAB nCurTab,
     212             :                 ScRefAddress& rStart, ScRefAddress& rEnd )
     213             : {
     214           0 :     bool bRet = false;
     215           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     216           0 :     if ( rString.indexOf(':') != -1 )
     217           0 :         bRet = ConvertDoubleRef( pDoc, rString, nCurTab, rStart, rEnd, eConv );
     218             :     else
     219             :     {
     220           0 :         bRet = ConvertSingleRef( pDoc, rString, nCurTab, rStart, eConv );
     221           0 :         rEnd = rStart;
     222             :     }
     223           0 :     return bRet;
     224             : }
     225             : 
     226             : // Handler:
     227             : 
     228           0 : IMPL_LINK( ScTabOpDlg, BtnHdl, PushButton*, pBtn )
     229             : {
     230           0 :     if (pBtn == m_pBtnOk)
     231             :     {
     232           0 :         ScTabOpParam::Mode eMode = ScTabOpParam::Column;
     233           0 :         sal_uInt16 nError = 0;
     234             : 
     235             :         // The following code checks:
     236             :         // 1. do the strings contain correct cell references / defined names?
     237             :         // 2. is formula range row if row is empty or column if column is empty
     238             :         //    or single reference if both?
     239             :         // 3. is at least one of row or column non-empty?
     240             : 
     241           0 :         if (m_pEdFormulaRange->GetText().isEmpty())
     242           0 :             nError = TABOPERR_NOFORMULA;
     243           0 :         else if (m_pEdRowCell->GetText().isEmpty() &&
     244           0 :                  m_pEdColCell->GetText().isEmpty())
     245           0 :             nError = TABOPERR_NOCOLROW;
     246           0 :         else if ( !lcl_Parse( m_pEdFormulaRange->GetText(), pDoc, nCurTab,
     247           0 :                                 theFormulaCell, theFormulaEnd ) )
     248           0 :             nError = TABOPERR_WRONGFORMULA;
     249             :         else
     250             :         {
     251           0 :             const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     252           0 :             if (!m_pEdRowCell->GetText().isEmpty())
     253             :             {
     254           0 :                 if (!ConvertSingleRef( pDoc, m_pEdRowCell->GetText(), nCurTab,
     255           0 :                                        theRowCell, eConv ))
     256           0 :                     nError = TABOPERR_WRONGROW;
     257             :                 else
     258             :                 {
     259           0 :                     if (m_pEdColCell->GetText().isEmpty() &&
     260           0 :                         theFormulaCell.Col() != theFormulaEnd.Col())
     261           0 :                         nError = TABOPERR_NOCOLFORMULA;
     262             :                     else
     263           0 :                         eMode = ScTabOpParam::Row;
     264             :                 }
     265             :             }
     266           0 :             if (!m_pEdColCell->GetText().isEmpty())
     267             :             {
     268           0 :                 if (!ConvertSingleRef( pDoc, m_pEdColCell->GetText(), nCurTab,
     269           0 :                                        theColCell, eConv ))
     270           0 :                     nError = TABOPERR_WRONGCOL;
     271             :                 else
     272             :                 {
     273           0 :                     if (eMode == ScTabOpParam::Row)                         // both
     274             :                     {
     275           0 :                         eMode = ScTabOpParam::Both;
     276           0 :                         ConvertSingleRef( pDoc, m_pEdFormulaRange->GetText(), nCurTab,
     277           0 :                                           theFormulaCell, eConv );
     278             :                     }
     279           0 :                     else if (theFormulaCell.Row() != theFormulaEnd.Row())
     280           0 :                         nError = TABOPERR_NOROWFORMULA;
     281             :                     else
     282           0 :                         eMode = ScTabOpParam::Column;
     283             :                 }
     284             :             }
     285             :         }
     286             : 
     287           0 :         if (nError)
     288           0 :             RaiseError( (ScTabOpErr) nError );
     289             :         else
     290             :         {
     291           0 :             ScTabOpParam aOutParam(theFormulaCell, theFormulaEnd, theRowCell, theColCell, eMode);
     292           0 :             ScTabOpItem  aOutItem( SID_TABOP, &aOutParam );
     293             : 
     294           0 :             SetDispatcherLock( false );
     295           0 :             SwitchToDocument();
     296           0 :             GetBindings().GetDispatcher()->Execute( SID_TABOP,
     297             :                                       SfxCallMode::SLOT | SfxCallMode::RECORD,
     298           0 :                                       &aOutItem, 0L, 0L );
     299           0 :             Close();
     300             :         }
     301             :     }
     302           0 :     else if (pBtn == m_pBtnCancel)
     303           0 :         Close();
     304             : 
     305           0 :     return 0;
     306             : }
     307             : 
     308           0 : IMPL_LINK( ScTabOpDlg, GetFocusHdl, Control*, pCtrl )
     309             : {
     310           0 :     if( (pCtrl == (Control*)m_pEdFormulaRange) || (pCtrl == (Control*)m_pRBFormulaRange) )
     311           0 :         pEdActive = m_pEdFormulaRange;
     312           0 :     else if( (pCtrl == (Control*)m_pEdRowCell) || (pCtrl == (Control*)m_pRBRowCell) )
     313           0 :         pEdActive = m_pEdRowCell;
     314           0 :     else if( (pCtrl == (Control*)m_pEdColCell) || (pCtrl == (Control*)m_pRBColCell) )
     315           0 :         pEdActive = m_pEdColCell;
     316             :     else
     317           0 :         pEdActive = NULL;
     318             : 
     319           0 :     if( pEdActive )
     320           0 :         pEdActive->SetSelection( Selection( 0, SELECTION_MAX ) );
     321             : 
     322           0 :     return 0;
     323             : }
     324             : 
     325           0 : IMPL_LINK_NOARG(ScTabOpDlg, LoseFocusHdl)
     326             : {
     327           0 :     bDlgLostFocus = !IsActive();
     328           0 :     return 0;
     329         228 : }
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10