LCOV - code coverage report
Current view: top level - sc/source/ui/namedlg - namedlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 302 0.0 %
Date: 2012-08-25 Functions: 0 43 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 582 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 "global.hxx"
      30                 :            : #include "reffact.hxx"
      31                 :            : #include "document.hxx"
      32                 :            : #include "docfunc.hxx"
      33                 :            : #include "scresid.hxx"
      34                 :            : #include "globstr.hrc"
      35                 :            : #include "namedlg.hrc"
      36                 :            : #include "namedlg.hxx"
      37                 :            : #include "viewdata.hxx"
      38                 :            : #include "tabvwsh.hxx"
      39                 :            : 
      40                 :            : #include "globalnames.hxx"
      41                 :            : 
      42                 :            : #include "sfx2/app.hxx"
      43                 :            : 
      44                 :            : #include <vcl/msgbox.hxx>
      45                 :            : 
      46                 :            : #include <map>
      47                 :            : #include <memory>
      48                 :            : 
      49                 :            : // defines -------------------------------------------------------------------
      50                 :            : 
      51                 :            : #define ABS_SREF          SCA_VALID \
      52                 :            :     | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
      53                 :            : #define ABS_DREF          ABS_SREF \
      54                 :            :     | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
      55                 :            : #define ABS_DREF3D      ABS_DREF | SCA_TAB_3D
      56                 :            : 
      57                 :            : //logic
      58                 :            : 
      59                 :          0 : ScNameDlg::ScNameDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
      60                 :            :         ScViewData*       ptrViewData,
      61                 :            :         const ScAddress&  aCursorPos, boost::ptr_map<rtl::OUString, ScRangeName>* pRangeMap  )
      62                 :            : 
      63                 :            : :   ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_NAMES ),
      64                 :            :     //
      65                 :            :     maEdName         ( this, ScResId( ED_NAME2 ) ),
      66                 :            :     maEdAssign       ( this, this, ScResId( ED_ASSIGN ) ),
      67                 :            :     aRbAssign       ( this, ScResId( RB_ASSIGN ), &maEdAssign, this ),
      68                 :            :     maLbScope( this, ScResId(LB_SCOPE) ),
      69                 :            :     //
      70                 :            :     maBtnMore        ( this, ScResId( BTN_MORE ) ),
      71                 :            :     maBtnPrintArea   ( this, ScResId( BTN_PRINTAREA ) ),
      72                 :            :     maBtnColHeader   ( this, ScResId( BTN_COLHEADER ) ),
      73                 :            :     maBtnCriteria    ( this, ScResId( BTN_CRITERIA ) ),
      74                 :            :     maBtnRowHeader   ( this, ScResId( BTN_ROWHEADER ) ),
      75                 :            :     //
      76                 :            :     maBtnAdd         ( this, ScResId( BTN_ADD ) ),
      77                 :            :     maBtnDelete      ( this, ScResId( BTN_DELETE ) ),
      78                 :            :     maBtnHelp        ( this, ScResId( BTN_HELP ) ),
      79                 :            :     maBtnOk          ( this, ScResId( BTN_NAME_OK ) ),
      80                 :            :     maBtnCancel      ( this, ScResId( BTN_NAME_CANCEL ) ),
      81                 :            :     //
      82                 :            :     maFtScope( this, ScResId(FT_SCOPE) ),
      83                 :            :     maFtRange( this, ScResId(FT_RANGE) ),
      84                 :            :     maFtName( this,  ScResId(FT_NAME) ),
      85                 :            :     maFlDiv          ( this, ScResId( FL_DIV ) ),
      86                 :            :     maFtInfo         ( this, ScResId( FT_INFO ) ),
      87                 :            :     //
      88                 :            :     maNameMgrCtrl   ( this, ScResId( CTRL_MANAGENAMES ) ),
      89                 :            :     //
      90         [ #  # ]:          0 :     maGlobalNameStr  ( ScGlobal::GetRscString(STR_GLOBAL_SCOPE) ),
      91         [ #  # ]:          0 :     maErrInvalidNameStr( ScGlobal::GetRscString(STR_ERR_NAME_INVALID)),
      92         [ #  # ]:          0 :     maErrNameInUse   ( ScGlobal::GetRscString(STR_ERR_NAME_EXISTS)),
      93                 :            :     maStrInfoDefault ( SC_RESSTR(STR_DEFAULT_INFO)),
      94                 :            :     maStrMultiSelect ( SC_RESSTR(STR_MULTI_SELECT)),
      95                 :            :     //
      96                 :            :     mpViewData       ( ptrViewData ),
      97         [ #  # ]:          0 :     mpDoc            ( ptrViewData->GetDocument() ),
      98                 :            :     maCursorPos      ( aCursorPos ),
      99                 :            :     mbNeedUpdate     ( true ),
     100                 :            :     mbDataChanged    ( false ),
     101 [ #  # ][ #  # ]:          0 :     mbCloseWithoutUndo( false )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     102                 :            : {
     103         [ #  # ]:          0 :     if (!pRangeMap)
     104                 :            :     {
     105         [ #  # ]:          0 :         std::map<rtl::OUString, ScRangeName*> aRangeMap;
     106         [ #  # ]:          0 :         mpDoc->GetRangeNameMap(aRangeMap);
     107                 :          0 :         std::map<rtl::OUString, ScRangeName*>::iterator itr = aRangeMap.begin(), itrEnd = aRangeMap.end();
     108         [ #  # ]:          0 :         for (; itr != itrEnd; ++itr)
     109                 :            :         {
     110                 :          0 :             rtl::OUString aTemp(itr->first);
     111 [ #  # ][ #  # ]:          0 :             maRangeMap.insert(aTemp, new ScRangeName(*itr->second));
                 [ #  # ]
     112                 :          0 :         }
     113                 :            :     }
     114                 :            :     else
     115                 :            :     {
     116         [ #  # ]:          0 :         maRangeMap.swap(*pRangeMap);
     117                 :            :     }
     118         [ #  # ]:          0 :     Init();
     119         [ #  # ]:          0 :     FreeResource();
     120                 :          0 : }
     121                 :            : 
     122 [ #  # ][ #  # ]:          0 : ScNameDlg::~ScNameDlg()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     123                 :            : {
     124 [ #  # ][ #  # ]:          0 :     delete mpRangeManagerTable;
     125         [ #  # ]:          0 : }
     126                 :            : 
     127                 :          0 : void ScNameDlg::Init()
     128                 :            : {
     129                 :          0 :     ScRange aRange;
     130                 :            : 
     131                 :            :     OSL_ENSURE( mpViewData && mpDoc, "ViewData oder Document nicht gefunden!" );
     132                 :            : 
     133                 :            :     //init UI
     134         [ #  # ]:          0 :     maFtInfo.SetStyle(WB_VCENTER);
     135                 :            : 
     136 [ #  # ][ #  # ]:          0 :     mpRangeManagerTable = new ScRangeManagerTable(&maNameMgrCtrl, maRangeMap, maCursorPos);
     137         [ #  # ]:          0 :     mpRangeManagerTable->SetSelectHdl( LINK( this, ScNameDlg, SelectionChangedHdl_Impl ) );
     138         [ #  # ]:          0 :     mpRangeManagerTable->SetDeselectHdl( LINK( this, ScNameDlg, SelectionChangedHdl_Impl ) );
     139                 :            : 
     140         [ #  # ]:          0 :     maBtnOk.SetClickHdl  ( LINK( this, ScNameDlg, OkBtnHdl ) );
     141         [ #  # ]:          0 :     maBtnCancel.SetClickHdl  ( LINK( this, ScNameDlg, CancelBtnHdl ) );
     142         [ #  # ]:          0 :     maBtnAdd.SetClickHdl     ( LINK( this, ScNameDlg, AddBtnHdl ) );
     143         [ #  # ]:          0 :     maEdAssign.SetGetFocusHdl( LINK( this, ScNameDlg, AssignGetFocusHdl ) );
     144         [ #  # ]:          0 :     maEdAssign.SetModifyHdl  ( LINK( this, ScNameDlg, EdModifyHdl ) );
     145         [ #  # ]:          0 :     maEdName.SetModifyHdl ( LINK( this, ScNameDlg, EdModifyHdl ) );
     146         [ #  # ]:          0 :     maLbScope.SetSelectHdl( LINK(this, ScNameDlg, ScopeChangedHdl) );
     147         [ #  # ]:          0 :     maBtnDelete.SetClickHdl ( LINK( this, ScNameDlg, RemoveBtnHdl ) );
     148         [ #  # ]:          0 :     maBtnMore.SetClickHdl   ( LINK( this, ScNameDlg, MoreBtnHdl ) );
     149         [ #  # ]:          0 :     maBtnPrintArea.SetToggleHdl( LINK(this, ScNameDlg, EdModifyHdl ) );
     150         [ #  # ]:          0 :     maBtnCriteria.SetToggleHdl( LINK(this, ScNameDlg, EdModifyHdl ) );
     151         [ #  # ]:          0 :     maBtnRowHeader.SetToggleHdl( LINK(this, ScNameDlg, EdModifyHdl ) );
     152         [ #  # ]:          0 :     maBtnColHeader.SetToggleHdl( LINK(this, ScNameDlg, EdModifyHdl ) );
     153                 :            : 
     154         [ #  # ]:          0 :     maBtnCriteria .Hide();
     155         [ #  # ]:          0 :     maBtnPrintArea.Hide();
     156         [ #  # ]:          0 :     maBtnColHeader.Hide();
     157         [ #  # ]:          0 :     maBtnRowHeader.Hide();
     158                 :            : 
     159                 :            :     // Initialize scope list.
     160 [ #  # ][ #  # ]:          0 :     maLbScope.InsertEntry(maGlobalNameStr);
                 [ #  # ]
     161         [ #  # ]:          0 :     maLbScope.SelectEntryPos(0);
     162         [ #  # ]:          0 :     SCTAB n = mpDoc->GetTableCount();
     163         [ #  # ]:          0 :     for (SCTAB i = 0; i < n; ++i)
     164                 :            :     {
     165                 :          0 :         rtl::OUString aTabName;
     166         [ #  # ]:          0 :         mpDoc->GetName(i, aTabName);
     167 [ #  # ][ #  # ]:          0 :         maLbScope.InsertEntry(aTabName);
                 [ #  # ]
     168                 :          0 :     }
     169                 :            : 
     170                 :            : 
     171                 :            : 
     172         [ #  # ]:          0 :     if (mpRangeManagerTable->GetSelectionCount())
     173                 :            :     {
     174         [ #  # ]:          0 :         SelectionChanged();
     175                 :            :     }
     176                 :            : 
     177         [ #  # ]:          0 :     CheckForEmptyTable();
     178                 :            : 
     179                 :          0 : }
     180                 :            : 
     181                 :          0 : sal_Bool ScNameDlg::IsRefInputMode() const
     182                 :            : {
     183                 :          0 :     return maEdAssign.IsEnabled();
     184                 :            : }
     185                 :            : 
     186                 :          0 : void ScNameDlg::RefInputDone( sal_Bool bForced)
     187                 :            : {
     188                 :          0 :     ScAnyRefDlg::RefInputDone(bForced);
     189                 :          0 :     EdModifyHdl(&maEdAssign);
     190                 :          0 : }
     191                 :            : 
     192                 :          0 : void ScNameDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
     193                 :            : {
     194         [ #  # ]:          0 :     if ( maEdAssign.IsEnabled() )
     195                 :            :     {
     196         [ #  # ]:          0 :         if ( rRef.aStart != rRef.aEnd )
     197         [ #  # ]:          0 :             RefInputStart(&maEdAssign);
     198         [ #  # ]:          0 :         String aRefStr;
     199                 :            :         rRef.Format( aRefStr, ABS_DREF3D, pDocP,
     200 [ #  # ][ #  # ]:          0 :                 ScAddress::Details(pDocP->GetAddressConvention(), 0, 0) );
     201 [ #  # ][ #  # ]:          0 :         maEdAssign.SetRefString( aRefStr );
     202                 :            :     }
     203                 :          0 : }
     204                 :            : 
     205                 :          0 : sal_Bool ScNameDlg::Close()
     206                 :            : {
     207 [ #  # ][ #  # ]:          0 :     if (mbDataChanged && !mbCloseWithoutUndo)
     208                 :          0 :         mpViewData->GetDocFunc().ModifyAllRangeNames(maRangeMap);
     209                 :          0 :     return DoClose( ScNameDlgWrapper::GetChildWindowId() );
     210                 :            : }
     211                 :            : 
     212                 :          0 : void ScNameDlg::CheckForEmptyTable()
     213                 :            : {
     214         [ #  # ]:          0 :     if (!mpRangeManagerTable->GetEntryCount())
     215                 :            :     {
     216                 :          0 :         maBtnDelete.Disable();
     217                 :          0 :         maEdAssign.Disable();
     218                 :          0 :         aRbAssign.Disable();
     219                 :          0 :         maEdName.Disable();
     220                 :          0 :         maLbScope.Disable();
     221                 :            : 
     222                 :          0 :         maBtnCriteria.Disable();
     223                 :          0 :         maBtnPrintArea.Disable();
     224                 :          0 :         maBtnColHeader.Disable();
     225                 :          0 :         maBtnRowHeader.Disable();
     226                 :            :     }
     227                 :            :     else
     228                 :            :     {
     229                 :          0 :         maBtnDelete.Enable();
     230                 :          0 :         maEdAssign.Enable();
     231                 :          0 :         aRbAssign.Enable();
     232                 :          0 :         maEdName.Enable();
     233                 :          0 :         maLbScope.Enable();
     234                 :            : 
     235                 :            : 
     236                 :          0 :         maBtnCriteria.Enable();
     237                 :          0 :         maBtnPrintArea.Enable();
     238                 :          0 :         maBtnColHeader.Enable();
     239                 :          0 :         maBtnRowHeader.Enable();
     240                 :            :     }
     241                 :          0 : }
     242                 :            : 
     243                 :          0 : void ScNameDlg::CancelPushed()
     244                 :            : {
     245                 :          0 :     DoClose( ScNameDlgWrapper::GetChildWindowId() );
     246                 :          0 : }
     247                 :            : 
     248                 :          0 : void ScNameDlg::SetActive()
     249                 :            : {
     250                 :          0 :     maEdAssign.GrabFocus();
     251                 :          0 :     RefInputDone();
     252                 :          0 : }
     253                 :            : 
     254                 :          0 : void ScNameDlg::UpdateChecks(ScRangeData* pData)
     255                 :            : {
     256                 :            :     // remove handlers, we only want the handlers to process
     257                 :            :     // user input and not when we are syncing the controls  with our internal
     258                 :            :     // model ( also UpdateChecks is called already from some other event
     259                 :            :     // handlers, triggering handlers while already processing a handler can
     260                 :            :     // ( and does in this case ) corrupt the internal data
     261                 :            : 
     262         [ #  # ]:          0 :     maBtnCriteria.SetToggleHdl( Link() );
     263         [ #  # ]:          0 :     maBtnPrintArea.SetToggleHdl( Link() );
     264         [ #  # ]:          0 :     maBtnColHeader.SetToggleHdl( Link() );
     265         [ #  # ]:          0 :     maBtnRowHeader.SetToggleHdl( Link() );
     266                 :            : 
     267         [ #  # ]:          0 :     maBtnCriteria .Check( pData->HasType( RT_CRITERIA ) );
     268         [ #  # ]:          0 :     maBtnPrintArea.Check( pData->HasType( RT_PRINTAREA ) );
     269         [ #  # ]:          0 :     maBtnColHeader.Check( pData->HasType( RT_COLHEADER ) );
     270         [ #  # ]:          0 :     maBtnRowHeader.Check( pData->HasType( RT_ROWHEADER ) );
     271                 :            : 
     272                 :            :     // Restore handlers so user input is processed again
     273         [ #  # ]:          0 :     Link aToggleHandler = LINK( this, ScNameDlg, EdModifyHdl );
     274                 :          0 :     maBtnCriteria.SetToggleHdl( aToggleHandler );
     275                 :          0 :     maBtnPrintArea.SetToggleHdl( aToggleHandler );
     276                 :          0 :     maBtnColHeader.SetToggleHdl( aToggleHandler );
     277                 :          0 :     maBtnRowHeader.SetToggleHdl( aToggleHandler );
     278                 :          0 : }
     279                 :            : 
     280                 :          0 : bool ScNameDlg::IsNameValid()
     281                 :            : {
     282 [ #  # ][ #  # ]:          0 :     rtl::OUString aScope = maLbScope.GetSelectEntry();
                 [ #  # ]
     283 [ #  # ][ #  # ]:          0 :     rtl::OUString aName = maEdName.GetText();
                 [ #  # ]
     284                 :          0 :     aName = aName.trim();
     285                 :            : 
     286         [ #  # ]:          0 :     if (aName.isEmpty())
     287                 :          0 :         return false;
     288                 :            : 
     289         [ #  # ]:          0 :     ScRangeName* pRangeName = GetRangeName( aScope );
     290                 :            : 
     291 [ #  # ][ #  # ]:          0 :     if (!ScRangeData::IsNameValid( aName, mpDoc ))
         [ #  # ][ #  # ]
     292                 :            :     {
     293         [ #  # ]:          0 :         maFtInfo.SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor());
     294 [ #  # ][ #  # ]:          0 :         maFtInfo.SetText(maErrInvalidNameStr);
                 [ #  # ]
     295                 :          0 :         return false;
     296                 :            :     }
     297 [ #  # ][ #  # ]:          0 :     else if (pRangeName && pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(aName)))
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     298                 :            :     {
     299         [ #  # ]:          0 :         maFtInfo.SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor());
     300 [ #  # ][ #  # ]:          0 :         maFtInfo.SetText(maErrNameInUse);
                 [ #  # ]
     301                 :          0 :         return false;
     302                 :            :     }
     303 [ #  # ][ #  # ]:          0 :     maFtInfo.SetText( maStrInfoDefault );
                 [ #  # ]
     304                 :          0 :     return true;
     305                 :            : }
     306                 :            : 
     307                 :          0 : bool ScNameDlg::IsFormulaValid()
     308                 :            : {
     309         [ #  # ]:          0 :     ScCompiler aComp( mpDoc, maCursorPos);
     310 [ #  # ][ #  # ]:          0 :     aComp.SetGrammar( mpDoc->GetGrammar() );
     311 [ #  # ][ #  # ]:          0 :     ScTokenArray* pCode = aComp.CompileString(maEdAssign.GetText());
                 [ #  # ]
     312         [ #  # ]:          0 :     if (pCode->GetCodeError())
     313                 :            :     {
     314         [ #  # ]:          0 :         maFtInfo.SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor());
     315 [ #  # ][ #  # ]:          0 :         delete pCode;
     316                 :          0 :         return false;
     317                 :            :     }
     318                 :            :     else
     319                 :            :     {
     320 [ #  # ][ #  # ]:          0 :         delete pCode;
     321                 :          0 :         return true;
     322         [ #  # ]:          0 :     }
     323                 :            : }
     324                 :            : 
     325                 :          0 : ScRangeName* ScNameDlg::GetRangeName(const rtl::OUString& rScope)
     326                 :            : {
     327         [ #  # ]:          0 :     if (rScope == maGlobalNameStr)
     328 [ #  # ][ #  # ]:          0 :         return maRangeMap.find(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME)))->second;
     329                 :            :     else
     330         [ #  # ]:          0 :         return maRangeMap.find(rScope)->second;
     331                 :            : }
     332                 :            : 
     333                 :          0 : void ScNameDlg::ShowOptions(const ScRangeNameLine& rLine)
     334                 :            : {
     335                 :          0 :     ScRangeName* pRangeName = GetRangeName(rLine.aScope);
     336         [ #  # ]:          0 :     ScRangeData* pData = pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(rLine.aName));
     337         [ #  # ]:          0 :     if (pData)
     338                 :            :     {
     339                 :          0 :         UpdateChecks(pData);
     340                 :            :     }
     341                 :          0 : }
     342                 :            : 
     343                 :            : 
     344                 :          0 : bool ScNameDlg::AddPushed()
     345                 :            : {
     346                 :          0 :     mbCloseWithoutUndo = true;
     347                 :          0 :     ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
     348                 :          0 :     pViewSh->SwitchBetweenRefDialogs(this);
     349                 :          0 :     return false;
     350                 :            : }
     351                 :            : 
     352                 :          0 : void ScNameDlg::SetEntry(const rtl::OUString& rName, const rtl::OUString& rScope)
     353                 :            : {
     354         [ #  # ]:          0 :     if (!rName.isEmpty())
     355                 :            :     {
     356                 :          0 :         mbDataChanged = true;
     357                 :          0 :         ScRangeNameLine aLine;
     358                 :          0 :         aLine.aName = rName;
     359                 :          0 :         aLine.aScope = rScope;
     360         [ #  # ]:          0 :         mpRangeManagerTable->SetEntry(aLine);
     361                 :            :     }
     362                 :          0 : }
     363                 :            : 
     364                 :          0 : void ScNameDlg::RemovePushed()
     365                 :            : {
     366         [ #  # ]:          0 :     std::vector<ScRangeNameLine> maEntries = mpRangeManagerTable->GetSelectedEntries();
     367         [ #  # ]:          0 :     mpRangeManagerTable->DeleteSelectedEntries();
     368 [ #  # ][ #  # ]:          0 :     for (std::vector<ScRangeNameLine>::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
     369                 :            :     {
     370         [ #  # ]:          0 :         ScRangeName* pRangeName = GetRangeName(itr->aScope);
     371 [ #  # ][ #  # ]:          0 :         ScRangeData* pData = pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(itr->aName));
     372                 :            :         OSL_ENSURE(pData, "table and model should be in sync");
     373                 :            :         // be safe and check for possible problems
     374         [ #  # ]:          0 :         if (pData)
     375         [ #  # ]:          0 :             pRangeName->erase(*pData);
     376                 :            : 
     377                 :          0 :         mbDataChanged = true;
     378                 :            :     }
     379         [ #  # ]:          0 :     CheckForEmptyTable();
     380                 :          0 : }
     381                 :            : 
     382                 :          0 : void ScNameDlg::NameModified()
     383                 :            : {
     384                 :          0 :     ScRangeNameLine aLine;
     385         [ #  # ]:          0 :     mpRangeManagerTable->GetCurrentLine(aLine);
     386                 :          0 :     rtl::OUString aOldName = aLine.aName;
     387 [ #  # ][ #  # ]:          0 :     rtl::OUString aNewName = maEdName.GetText();
                 [ #  # ]
     388                 :          0 :     aNewName = aNewName.trim();
     389         [ #  # ]:          0 :     maFtInfo.SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor());
     390         [ #  # ]:          0 :     if (aNewName != aOldName)
     391                 :            :     {
     392 [ #  # ][ #  # ]:          0 :         if (!IsNameValid())
     393                 :            :             return;
     394                 :            :     }
     395                 :            :     else
     396                 :            :     {
     397 [ #  # ][ #  # ]:          0 :         maFtInfo.SetText( maStrInfoDefault );
                 [ #  # ]
     398                 :            :     }
     399                 :            : 
     400 [ #  # ][ #  # ]:          0 :     if (!IsFormulaValid())
     401                 :            :     {
     402                 :            :         //TODO: implement an info text
     403                 :            :         return;
     404                 :            :     }
     405                 :            : 
     406                 :          0 :     rtl::OUString aOldScope = aLine.aScope;
     407                 :            :     //empty table
     408         [ #  # ]:          0 :     if (aOldScope.isEmpty())
     409                 :            :         return;
     410 [ #  # ][ #  # ]:          0 :     rtl::OUString aExpr = maEdAssign.GetText();
                 [ #  # ]
     411 [ #  # ][ #  # ]:          0 :     rtl::OUString aNewScope = maLbScope.GetSelectEntry();
                 [ #  # ]
     412                 :            : 
     413         [ #  # ]:          0 :     ScRangeName* pOldRangeName = GetRangeName( aOldScope );
     414 [ #  # ][ #  # ]:          0 :     ScRangeData* pData = pOldRangeName->findByUpperName( ScGlobal::pCharClass->uppercase(aOldName) );
     415         [ #  # ]:          0 :     ScRangeName* pNewRangeName = GetRangeName( aNewScope );
     416                 :            :     OSL_ENSURE(pData, "model and table should be in sync");
     417                 :            :     // be safe and check for range data
     418         [ #  # ]:          0 :     if (pData)
     419                 :            :     {
     420         [ #  # ]:          0 :         pOldRangeName->erase(*pData);
     421                 :          0 :         mbNeedUpdate = false;
     422         [ #  # ]:          0 :         mpRangeManagerTable->DeleteSelectedEntries();
     423                 :            :         RangeType nType = RT_NAME |
     424         [ #  # ]:          0 :             (maBtnRowHeader.IsChecked() ? RT_ROWHEADER : RangeType(0))
     425         [ #  # ]:          0 :             |(maBtnColHeader.IsChecked() ? RT_COLHEADER : RangeType(0))
     426         [ #  # ]:          0 :             |(maBtnPrintArea.IsChecked() ? RT_PRINTAREA : RangeType(0))
     427 [ #  # ][ #  # ]:          0 :             |(maBtnCriteria.IsChecked()  ? RT_CRITERIA  : RangeType(0));
         [ #  # ][ #  # ]
                 [ #  # ]
     428                 :            : 
     429                 :            :         ScRangeData* pNewEntry = new ScRangeData( mpDoc, aNewName, aExpr,
     430 [ #  # ][ #  # ]:          0 :                 maCursorPos, nType);
         [ #  # ][ #  # ]
     431         [ #  # ]:          0 :         pNewRangeName->insert(pNewEntry);
     432                 :          0 :         aLine.aName = aNewName;
     433                 :          0 :         aLine.aExpression = aExpr;
     434                 :          0 :         aLine.aScope = aNewScope;
     435         [ #  # ]:          0 :         mpRangeManagerTable->addEntry(aLine);
     436                 :          0 :         mbNeedUpdate = true;
     437                 :          0 :         mbDataChanged = true;
     438 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
     439                 :            : }
     440                 :            : 
     441                 :          0 : void ScNameDlg::SelectionChanged()
     442                 :            : {
     443                 :            : 
     444                 :            : 
     445                 :            :     //don't update if we have just modified due to user input
     446         [ #  # ]:          0 :     if (!mbNeedUpdate)
     447                 :            :     {
     448                 :          0 :         return;
     449                 :            :     }
     450                 :            : 
     451         [ #  # ]:          0 :     if (mpRangeManagerTable->IsMultiSelection())
     452                 :            :     {
     453         [ #  # ]:          0 :         maEdName.SetText(maStrMultiSelect);
     454         [ #  # ]:          0 :         maEdAssign.SetText(maStrMultiSelect);
     455                 :            : 
     456                 :          0 :         maEdName.Disable();
     457                 :          0 :         maEdAssign.Disable();
     458                 :          0 :         aRbAssign.Disable();
     459                 :          0 :         maLbScope.Disable();
     460                 :          0 :         maBtnRowHeader.Disable();
     461                 :          0 :         maBtnColHeader.Disable();
     462                 :          0 :         maBtnPrintArea.Disable();
     463                 :          0 :         maBtnCriteria.Disable();
     464                 :            :     }
     465                 :            :     else
     466                 :            :     {
     467                 :          0 :         ScRangeNameLine aLine;
     468         [ #  # ]:          0 :         mpRangeManagerTable->GetCurrentLine(aLine);
     469 [ #  # ][ #  # ]:          0 :         maEdAssign.SetText(aLine.aExpression);
                 [ #  # ]
     470 [ #  # ][ #  # ]:          0 :         maEdName.SetText(aLine.aName);
                 [ #  # ]
     471 [ #  # ][ #  # ]:          0 :         maLbScope.SelectEntry(aLine.aScope);
                 [ #  # ]
     472         [ #  # ]:          0 :         ShowOptions(aLine);
     473         [ #  # ]:          0 :         maBtnDelete.Enable();
     474         [ #  # ]:          0 :         maEdName.Enable();
     475         [ #  # ]:          0 :         maEdAssign.Enable();
     476         [ #  # ]:          0 :         aRbAssign.Enable();
     477         [ #  # ]:          0 :         maLbScope.Enable();
     478         [ #  # ]:          0 :         maBtnRowHeader.Enable();
     479         [ #  # ]:          0 :         maBtnColHeader.Enable();
     480         [ #  # ]:          0 :         maBtnPrintArea.Enable();
     481         [ #  # ]:          0 :         maBtnCriteria.Enable();
     482                 :            :     }
     483                 :            : }
     484                 :            : 
     485                 :          0 : void ScNameDlg::ScopeChanged()
     486                 :            : {
     487                 :          0 :     NameModified();
     488                 :          0 : }
     489                 :            : 
     490                 :            : namespace {
     491                 :            : 
     492                 :          0 : void MoveWindow( Window& rButton, long nPixel)
     493                 :            : {
     494         [ #  # ]:          0 :     Point aPoint = rButton.GetPosPixel();
     495                 :          0 :     aPoint.Y() += nPixel;
     496         [ #  # ]:          0 :     rButton.SetPosPixel(aPoint);
     497                 :          0 : }
     498                 :            : 
     499                 :            : }
     500                 :            : 
     501                 :          0 : void ScNameDlg::MorePushed()
     502                 :            : {
     503         [ #  # ]:          0 :     Size nSize = GetSizePixel();
     504                 :            : 
     505                 :            :     //depending on the state of the button, move all elements below up/down
     506                 :          0 :     long nPixel = 60;
     507         [ #  # ]:          0 :     if (!maBtnMore.GetState())
     508                 :            :     {
     509                 :          0 :         nPixel *= -1;
     510         [ #  # ]:          0 :         maBtnRowHeader.Hide();
     511         [ #  # ]:          0 :         maBtnColHeader.Hide();
     512         [ #  # ]:          0 :         maBtnPrintArea.Hide();
     513         [ #  # ]:          0 :         maBtnCriteria.Hide();
     514                 :            :     }
     515                 :            :     else
     516                 :            :     {
     517         [ #  # ]:          0 :         maBtnRowHeader.Show();
     518         [ #  # ]:          0 :         maBtnColHeader.Show();
     519         [ #  # ]:          0 :         maBtnPrintArea.Show();
     520         [ #  # ]:          0 :         maBtnCriteria.Show();
     521                 :            :     }
     522                 :          0 :     nSize.Height() += nPixel;
     523         [ #  # ]:          0 :     SetSizePixel(nSize);
     524         [ #  # ]:          0 :     MoveWindow(maBtnAdd, nPixel);
     525         [ #  # ]:          0 :     MoveWindow(maBtnDelete, nPixel);
     526         [ #  # ]:          0 :     MoveWindow(maBtnHelp, nPixel);
     527         [ #  # ]:          0 :     MoveWindow(maBtnOk, nPixel);
     528         [ #  # ]:          0 :     MoveWindow(maBtnCancel, nPixel);
     529         [ #  # ]:          0 :     MoveWindow(maFlDiv, nPixel);
     530                 :          0 : }
     531                 :            : 
     532                 :          0 : void ScNameDlg::GetRangeNames(boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap)
     533                 :            : {
     534                 :          0 :     maRangeMap.swap(rRangeMap);
     535                 :          0 : }
     536                 :            : 
     537                 :          0 : IMPL_LINK_NOARG(ScNameDlg, OkBtnHdl)
     538                 :            : {
     539                 :          0 :     Close();
     540                 :          0 :     return 0;
     541                 :            : }
     542                 :            : 
     543                 :          0 : IMPL_LINK_NOARG(ScNameDlg, CancelBtnHdl)
     544                 :            : {
     545                 :          0 :     CancelPushed();
     546                 :          0 :     return 0;
     547                 :            : }
     548                 :            : 
     549                 :          0 : IMPL_LINK_NOARG(ScNameDlg, AddBtnHdl)
     550                 :            : {
     551                 :          0 :     return AddPushed();
     552                 :            : }
     553                 :            : 
     554                 :          0 : IMPL_LINK_NOARG(ScNameDlg, RemoveBtnHdl)
     555                 :            : {
     556                 :          0 :     RemovePushed();
     557                 :          0 :     return 0;
     558                 :            : }
     559                 :            : 
     560                 :          0 : IMPL_LINK_NOARG(ScNameDlg, EdModifyHdl)
     561                 :            : {
     562                 :          0 :     NameModified();
     563                 :          0 :     return 0;
     564                 :            : }
     565                 :            : 
     566                 :          0 : IMPL_LINK_NOARG(ScNameDlg, AssignGetFocusHdl)
     567                 :            : {
     568                 :          0 :     EdModifyHdl( &maEdAssign );
     569                 :          0 :     return 0;
     570                 :            : }
     571                 :            : 
     572                 :          0 : IMPL_LINK_NOARG(ScNameDlg, SelectionChangedHdl_Impl)
     573                 :            : {
     574                 :          0 :     SelectionChanged();
     575                 :          0 :     return 0;
     576                 :            : }
     577                 :            : 
     578                 :          0 : IMPL_LINK_NOARG(ScNameDlg, ScopeChangedHdl)
     579                 :            : {
     580                 :          0 :     ScopeChanged();
     581                 :          0 :     return 0;
     582                 :            : }
     583                 :            : 
     584                 :          0 : IMPL_LINK_NOARG(ScNameDlg, MoreBtnHdl)
     585                 :            : {
     586                 :          0 :     MorePushed();
     587                 :          0 :     return 0;
     588                 :            : }
     589                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10