LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - solvrdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 117 0.0 %
Date: 2012-08-25 Functions: 0 16 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 235 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                 :            : #include "rangelst.hxx"
      30                 :            : #include "scitems.hxx"
      31                 :            : #include <sfx2/dispatch.hxx>
      32                 :            : #include <svl/zforlist.hxx>
      33                 :            : #include <vcl/msgbox.hxx>
      34                 :            : 
      35                 :            : #include "uiitems.hxx"
      36                 :            : #include "reffact.hxx"
      37                 :            : #include "document.hxx"
      38                 :            : #include "scresid.hxx"
      39                 :            : #include "solvrdlg.hrc"
      40                 :            : 
      41                 :            : #define _SOLVRDLG_CXX
      42                 :            : #include "solvrdlg.hxx"
      43                 :            : #undef _SOLVERDLG_CXX
      44                 :            : 
      45                 :            : 
      46                 :            : #define ERRORBOX(s) ErrorBox( this, WinBits( WB_OK | WB_DEF_OK), s ).Execute()
      47                 :            : 
      48                 :            : 
      49                 :            : //============================================================================
      50                 :            : //  class ScSolverDlg
      51                 :            : //----------------------------------------------------------------------------
      52                 :            : 
      53                 :          0 : ScSolverDlg::ScSolverDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
      54                 :            :                           ScDocument* pDocument,
      55                 :            :                           ScAddress aCursorPos )
      56                 :            : 
      57                 :            :     :   ScAnyRefDlg         ( pB, pCW, pParent, RID_SCDLG_SOLVER ),
      58                 :            :         //
      59                 :            :         aFlVariables        ( this, ScResId( FL_VARIABLES ) ),
      60                 :            :         aFtFormulaCell      ( this, ScResId( FT_FORMULACELL ) ),
      61                 :            :         aEdFormulaCell      ( this, this, ScResId( ED_FORMULACELL ) ),
      62                 :            :         aRBFormulaCell      ( this, ScResId( RB_FORMULACELL ), &aEdFormulaCell, this ),
      63                 :            :         aFtTargetVal        ( this, ScResId( FT_TARGETVAL ) ),
      64                 :            :         aEdTargetVal        ( this, ScResId( ED_TARGETVAL ) ),
      65                 :            :         aFtVariableCell     ( this, ScResId( FT_VARCELL ) ),
      66                 :            :         aEdVariableCell     ( this, this, ScResId( ED_VARCELL ) ),
      67                 :            :         aRBVariableCell     ( this, ScResId( RB_VARCELL ), &aEdVariableCell, this ),
      68                 :            :         aBtnOk              ( this, ScResId( BTN_OK ) ),
      69                 :            :         aBtnCancel          ( this, ScResId( BTN_CANCEL ) ),
      70                 :            :         aBtnHelp            ( this, ScResId( BTN_HELP ) ),
      71                 :            :         //
      72                 :            :         theFormulaCell      ( aCursorPos ),
      73                 :            :         theVariableCell     ( aCursorPos ),
      74                 :            :         pDoc                ( pDocument ),
      75                 :          0 :         nCurTab             ( aCursorPos.Tab() ),
      76                 :            :         pEdActive           ( NULL ),
      77                 :            :         bDlgLostFocus       ( false ),
      78                 :            :         errMsgInvalidVar    ( ScResId( STR_INVALIDVAR ) ),
      79                 :            :         errMsgInvalidForm   ( ScResId( STR_INVALIDFORM ) ),
      80                 :            :         errMsgNoFormula     ( ScResId( STR_NOFORMULA ) ),
      81 [ #  # ][ #  # ]:          0 :         errMsgInvalidVal    ( ScResId( STR_INVALIDVAL ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      82                 :            : {
      83         [ #  # ]:          0 :     Init();
      84         [ #  # ]:          0 :     FreeResource();
      85                 :            : 
      86         [ #  # ]:          0 :     aRBFormulaCell.SetAccessibleRelationMemberOf(&aFlVariables);
      87         [ #  # ]:          0 :     aRBVariableCell.SetAccessibleRelationMemberOf(&aFlVariables);
      88                 :          0 : }
      89                 :            : 
      90                 :            : //----------------------------------------------------------------------------
      91                 :            : 
      92 [ #  # ][ #  # ]:          0 : ScSolverDlg::~ScSolverDlg()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      93                 :            : {
      94         [ #  # ]:          0 : }
      95                 :            : 
      96                 :            : //----------------------------------------------------------------------------
      97                 :            : 
      98                 :          0 : void ScSolverDlg::Init()
      99                 :            : {
     100         [ #  # ]:          0 :     String          aStr;
     101                 :            : 
     102         [ #  # ]:          0 :     aBtnOk.         SetClickHdl     ( LINK( this, ScSolverDlg, BtnHdl ) );
     103         [ #  # ]:          0 :     aBtnCancel.     SetClickHdl     ( LINK( this, ScSolverDlg, BtnHdl ) );
     104                 :            : 
     105         [ #  # ]:          0 :     Link aLink = LINK( this, ScSolverDlg, GetFocusHdl );
     106                 :          0 :     aEdFormulaCell. SetGetFocusHdl  ( aLink );
     107                 :          0 :     aRBFormulaCell. SetGetFocusHdl  ( aLink );
     108                 :          0 :     aEdVariableCell.SetGetFocusHdl  ( aLink );
     109                 :          0 :     aRBVariableCell.SetGetFocusHdl  ( aLink );
     110                 :          0 :     aEdTargetVal.   SetGetFocusHdl  ( aLink );
     111                 :            : 
     112         [ #  # ]:          0 :     aLink = LINK( this, ScSolverDlg, LoseFocusHdl );
     113                 :          0 :     aEdFormulaCell. SetLoseFocusHdl ( aLink );
     114                 :          0 :     aRBFormulaCell. SetLoseFocusHdl ( aLink );
     115                 :          0 :     aEdVariableCell.SetLoseFocusHdl ( aLink );
     116                 :          0 :     aRBVariableCell.SetLoseFocusHdl ( aLink );
     117                 :            : 
     118 [ #  # ][ #  # ]:          0 :     theFormulaCell.Format( aStr, SCA_ABS, NULL, pDoc->GetAddressConvention() );
     119                 :            : 
     120         [ #  # ]:          0 :     aEdFormulaCell.SetText( aStr );
     121         [ #  # ]:          0 :     aEdFormulaCell.GrabFocus();
     122         [ #  # ]:          0 :     pEdActive = &aEdFormulaCell;
     123                 :          0 : }
     124                 :            : 
     125                 :            : //----------------------------------------------------------------------------
     126                 :            : 
     127                 :          0 : sal_Bool ScSolverDlg::Close()
     128                 :            : {
     129                 :          0 :     return DoClose( ScSolverDlgWrapper::GetChildWindowId() );
     130                 :            : }
     131                 :            : 
     132                 :            : //----------------------------------------------------------------------------
     133                 :            : 
     134                 :          0 : void ScSolverDlg::SetActive()
     135                 :            : {
     136         [ #  # ]:          0 :     if ( bDlgLostFocus )
     137                 :            :     {
     138                 :          0 :         bDlgLostFocus = false;
     139         [ #  # ]:          0 :         if( pEdActive )
     140                 :          0 :             pEdActive->GrabFocus();
     141                 :            :     }
     142                 :            :     else
     143                 :            :     {
     144                 :          0 :         GrabFocus();
     145                 :            :     }
     146                 :          0 :     RefInputDone();
     147                 :          0 : }
     148                 :            : 
     149                 :            : //----------------------------------------------------------------------------
     150                 :            : 
     151                 :          0 : void ScSolverDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
     152                 :            : {
     153         [ #  # ]:          0 :     if( pEdActive )
     154                 :            :     {
     155         [ #  # ]:          0 :         if ( rRef.aStart != rRef.aEnd )
     156         [ #  # ]:          0 :             RefInputStart(pEdActive);
     157                 :            : 
     158         [ #  # ]:          0 :         String      aStr;
     159                 :          0 :         ScAddress   aAdr = rRef.aStart;
     160                 :          0 :         sal_uInt16      nFmt = ( aAdr.Tab() == nCurTab )
     161                 :            :                                 ? SCA_ABS
     162         [ #  # ]:          0 :                                 : SCA_ABS_3D;
     163                 :            : 
     164 [ #  # ][ #  # ]:          0 :         aAdr.Format( aStr, nFmt, pDocP, pDocP->GetAddressConvention() );
     165         [ #  # ]:          0 :         pEdActive->SetRefString( aStr );
     166                 :            : 
     167         [ #  # ]:          0 :         if ( pEdActive == &aEdFormulaCell )
     168                 :          0 :             theFormulaCell = aAdr;
     169         [ #  # ]:          0 :         else if ( pEdActive == &aEdVariableCell )
     170         [ #  # ]:          0 :             theVariableCell = aAdr;
     171                 :            :     }
     172                 :          0 : }
     173                 :            : 
     174                 :            : //----------------------------------------------------------------------------
     175                 :            : 
     176                 :          0 : void ScSolverDlg::RaiseError( ScSolverErr eError )
     177                 :            : {
     178   [ #  #  #  #  :          0 :     switch ( eError )
                      # ]
     179                 :            :     {
     180                 :            :         case SOLVERR_NOFORMULA:
     181         [ #  # ]:          0 :             ERRORBOX( errMsgNoFormula );
     182                 :          0 :             aEdFormulaCell.GrabFocus();
     183                 :          0 :             break;
     184                 :            : 
     185                 :            :         case SOLVERR_INVALID_FORMULA:
     186         [ #  # ]:          0 :             ERRORBOX( errMsgInvalidForm );
     187                 :          0 :             aEdFormulaCell.GrabFocus();
     188                 :          0 :             break;
     189                 :            : 
     190                 :            :         case SOLVERR_INVALID_VARIABLE:
     191         [ #  # ]:          0 :             ERRORBOX( errMsgInvalidVar );
     192                 :          0 :             aEdVariableCell.GrabFocus();
     193                 :          0 :             break;
     194                 :            : 
     195                 :            :         case SOLVERR_INVALID_TARGETVALUE:
     196         [ #  # ]:          0 :             ERRORBOX( errMsgInvalidVal );
     197                 :          0 :             aEdTargetVal.GrabFocus();
     198                 :          0 :             break;
     199                 :            :     }
     200                 :          0 : }
     201                 :            : 
     202                 :            : //----------------------------------------------------------------------------
     203                 :            : 
     204                 :          0 : sal_Bool ScSolverDlg::IsRefInputMode() const
     205                 :            : {
     206                 :          0 :     return pEdActive != NULL;
     207                 :            : }
     208                 :            : 
     209                 :            : //----------------------------------------------------------------------------
     210                 :            : 
     211                 :          0 : sal_Bool ScSolverDlg::CheckTargetValue( String& rStrVal )
     212                 :            : {
     213                 :          0 :     sal_uInt32 n1 = 0;
     214                 :            :     double n2;
     215                 :            : 
     216 [ #  # ][ #  # ]:          0 :     return pDoc->GetFormatTable()->IsNumberFormat( rStrVal, n1, n2 );
     217                 :            : }
     218                 :            : 
     219                 :            : //----------------------------------------------------------------------------
     220                 :            : // Handler:
     221                 :            : 
     222                 :          0 : IMPL_LINK( ScSolverDlg, BtnHdl, PushButton*, pBtn )
     223                 :            : {
     224         [ #  # ]:          0 :     if ( pBtn == &aBtnOk )
     225                 :            :     {
     226         [ #  # ]:          0 :         theTargetValStr = aEdTargetVal.GetText();
     227                 :            : 
     228                 :            :         // Zu ueberpruefen:
     229                 :            :         // 1. enthalten die Strings korrekte Tabellenkoordinaten/def.Namen?
     230                 :            :         // 2. verweist die Formel-Koordinate wirklich auf eine Formelzelle?
     231                 :            :         // 3. wurde ein korrekter Zielwert eingegeben
     232                 :            : 
     233                 :          0 :         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     234 [ #  # ][ #  # ]:          0 :         sal_uInt16  nRes1 = theFormulaCell .Parse( aEdFormulaCell.GetText(),  pDoc, eConv );
                 [ #  # ]
     235 [ #  # ][ #  # ]:          0 :         sal_uInt16  nRes2 = theVariableCell.Parse( aEdVariableCell.GetText(), pDoc, eConv );
                 [ #  # ]
     236                 :            : 
     237         [ #  # ]:          0 :         if ( SCA_VALID == ( nRes1 & SCA_VALID ) )
     238                 :            :         {
     239         [ #  # ]:          0 :             if ( SCA_VALID == ( nRes2 & SCA_VALID ) )
     240                 :            :             {
     241         [ #  # ]:          0 :                 if ( CheckTargetValue( theTargetValStr ) )
     242                 :            :                 {
     243                 :            :                     CellType eType;
     244                 :          0 :                     pDoc->GetCellType( theFormulaCell.Col(),
     245                 :            :                                        theFormulaCell.Row(),
     246                 :          0 :                                        theFormulaCell.Tab(),
     247         [ #  # ]:          0 :                                        eType );
     248                 :            : 
     249         [ #  # ]:          0 :                     if ( CELLTYPE_FORMULA  == eType )
     250                 :            :                     {
     251                 :            :                         ScSolveParam aOutParam( theFormulaCell,
     252                 :            :                                                 theVariableCell,
     253         [ #  # ]:          0 :                                                 theTargetValStr );
     254         [ #  # ]:          0 :                         ScSolveItem  aOutItem( SCITEM_SOLVEDATA, &aOutParam );
     255                 :            : 
     256         [ #  # ]:          0 :                         SetDispatcherLock( false );
     257                 :            : 
     258         [ #  # ]:          0 :                         SwitchToDocument();
     259                 :          0 :                         GetBindings().GetDispatcher()->Execute( SID_SOLVE,
     260                 :            :                                                   SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
     261         [ #  # ]:          0 :                                                   &aOutItem, 0L, 0L );
     262 [ #  # ][ #  # ]:          0 :                         Close();
                 [ #  # ]
     263                 :            :                     }
     264         [ #  # ]:          0 :                     else RaiseError( SOLVERR_NOFORMULA );
     265                 :            :                 }
     266                 :          0 :                 else RaiseError( SOLVERR_INVALID_TARGETVALUE );
     267                 :            :             }
     268                 :          0 :             else RaiseError( SOLVERR_INVALID_VARIABLE );
     269                 :            :         }
     270                 :          0 :         else RaiseError( SOLVERR_INVALID_FORMULA );
     271                 :            :     }
     272         [ #  # ]:          0 :     else if ( pBtn == &aBtnCancel )
     273                 :            :     {
     274                 :          0 :         Close();
     275                 :            :     }
     276                 :            : 
     277                 :          0 :     return 0;
     278                 :            : }
     279                 :            : 
     280                 :            : //----------------------------------------------------------------------------
     281                 :            : 
     282                 :          0 : IMPL_LINK( ScSolverDlg, GetFocusHdl, Control*, pCtrl )
     283                 :            : {
     284                 :          0 :     Edit* pEdit = NULL;
     285                 :          0 :     pEdActive = NULL;
     286                 :            : 
     287 [ #  # ][ #  # ]:          0 :     if( (pCtrl == (Control*)&aEdFormulaCell) || (pCtrl == (Control*)&aRBFormulaCell) )
     288                 :          0 :         pEdit = pEdActive = &aEdFormulaCell;
     289 [ #  # ][ #  # ]:          0 :     else if( (pCtrl == (Control*)&aEdVariableCell) || (pCtrl == (Control*)&aRBVariableCell) )
     290                 :          0 :         pEdit = pEdActive = &aEdVariableCell;
     291         [ #  # ]:          0 :     else if( pCtrl == (Control*)&aEdTargetVal )
     292                 :          0 :         pEdit = &aEdTargetVal;
     293                 :            : 
     294         [ #  # ]:          0 :     if( pEdit )
     295         [ #  # ]:          0 :         pEdit->SetSelection( Selection( 0, SELECTION_MAX ) );
     296                 :            : 
     297                 :          0 :     return 0;
     298                 :            : }
     299                 :            : 
     300                 :            : //----------------------------------------------------------------------------
     301                 :            : 
     302                 :          0 : IMPL_LINK_NOARG(ScSolverDlg, LoseFocusHdl)
     303                 :            : {
     304                 :          0 :     bDlgLostFocus = !IsActive();
     305                 :          0 :     return 0;
     306                 :            : }
     307                 :            : 
     308                 :            : 
     309                 :            : 
     310                 :            : 
     311                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10