LCOV - code coverage report
Current view: top level - sc/source/ui/pagedlg - areasdlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 394 0.3 %
Date: 2014-11-03 Functions: 2 29 6.9 %
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 <rangelst.hxx>
      21             : 
      22             : #include <comphelper/string.hxx>
      23             : #include <sfx2/dispatch.hxx>
      24             : #include <svl/stritem.hxx>
      25             : #include <vcl/msgbox.hxx>
      26             : #include <unotools/charclass.hxx>
      27             : #include <stdlib.h>
      28             : 
      29             : #include "areasdlg.hxx"
      30             : #include "scresid.hxx"
      31             : #include "rangenam.hxx"
      32             : #include "reffact.hxx"
      33             : #include "tabvwsh.hxx"
      34             : #include "docsh.hxx"
      35             : #include "globstr.hrc"
      36             : #include "pagedlg.hrc"
      37             : #include "compiler.hxx"
      38             : #include "markdata.hxx"
      39             : 
      40             : // STATIC DATA ---------------------------------------------------------------
      41             : 
      42             : // List box positions for print range (PR)
      43             : const sal_uInt16 SC_AREASDLG_PR_ENTIRE  = 1;
      44             : const sal_uInt16 SC_AREASDLG_PR_USER    = 2;
      45             : const sal_uInt16 SC_AREASDLG_PR_SELECT  = 3;
      46             : 
      47             : // List box positions for repeat ranges (RR)
      48             : const sal_uInt16 SC_AREASDLG_RR_NONE    = 0;
      49             : const sal_uInt16 SC_AREASDLG_RR_USER    = 1;
      50             : const sal_uInt16 SC_AREASDLG_RR_OFFSET  = 2;
      51             : 
      52             : #define HDL(hdl)            LINK( this, ScPrintAreasDlg, hdl )
      53             : #define ERRORBOX(nId)       MessageDialog(this, ScGlobal::GetRscString(nId)).Execute()
      54             : 
      55             : // globale Funktionen (->am Ende der Datei):
      56             : 
      57             : static bool lcl_CheckRepeatString( const OUString& rStr, ScDocument* pDoc, bool bIsRow, ScRange* pRange );
      58             : static void lcl_GetRepeatRangeString( const ScRange* pRange, ScDocument* pDoc, bool bIsRow, OUString& rStr );
      59             : 
      60             : #if 0
      61             : // this method is useful when debugging address flags.
      62             : static void printAddressFlags(sal_uInt16 nFlag)
      63             : {
      64             :     if ((nFlag & SCA_COL_ABSOLUTE  ) == SCA_COL_ABSOLUTE  )  printf("SCA_COL_ABSOLUTE \n");
      65             :     if ((nFlag & SCA_ROW_ABSOLUTE  ) == SCA_ROW_ABSOLUTE  )  printf("SCA_ROW_ABSOLUTE \n");
      66             :     if ((nFlag & SCA_TAB_ABSOLUTE  ) == SCA_TAB_ABSOLUTE  )  printf("SCA_TAB_ABSOLUTE \n");
      67             :     if ((nFlag & SCA_TAB_3D        ) == SCA_TAB_3D        )  printf("SCA_TAB_3D       \n");
      68             :     if ((nFlag & SCA_COL2_ABSOLUTE ) == SCA_COL2_ABSOLUTE )  printf("SCA_COL2_ABSOLUTE\n");
      69             :     if ((nFlag & SCA_ROW2_ABSOLUTE ) == SCA_ROW2_ABSOLUTE )  printf("SCA_ROW2_ABSOLUTE\n");
      70             :     if ((nFlag & SCA_TAB2_ABSOLUTE ) == SCA_TAB2_ABSOLUTE )  printf("SCA_TAB2_ABSOLUTE\n");
      71             :     if ((nFlag & SCA_TAB2_3D       ) == SCA_TAB2_3D       )  printf("SCA_TAB2_3D      \n");
      72             :     if ((nFlag & SCA_VALID_ROW     ) == SCA_VALID_ROW     )  printf("SCA_VALID_ROW    \n");
      73             :     if ((nFlag & SCA_VALID_COL     ) == SCA_VALID_COL     )  printf("SCA_VALID_COL    \n");
      74             :     if ((nFlag & SCA_VALID_TAB     ) == SCA_VALID_TAB     )  printf("SCA_VALID_TAB    \n");
      75             :     if ((nFlag & SCA_FORCE_DOC     ) == SCA_FORCE_DOC     )  printf("SCA_FORCE_DOC    \n");
      76             :     if ((nFlag & SCA_VALID_ROW2    ) == SCA_VALID_ROW2    )  printf("SCA_VALID_ROW2   \n");
      77             :     if ((nFlag & SCA_VALID_COL2    ) == SCA_VALID_COL2    )  printf("SCA_VALID_COL2   \n");
      78             :     if ((nFlag & SCA_VALID_TAB2    ) == SCA_VALID_TAB2    )  printf("SCA_VALID_TAB2   \n");
      79             :     if ((nFlag & SCA_VALID         ) == SCA_VALID         )  printf("SCA_VALID        \n");
      80             :     if ((nFlag & SCA_ABS           ) == SCA_ABS           )  printf("SCA_ABS          \n");
      81             :     if ((nFlag & SCR_ABS           ) == SCR_ABS           )  printf("SCR_ABS          \n");
      82             :     if ((nFlag & SCA_ABS_3D        ) == SCA_ABS_3D        )  printf("SCA_ABS_3D       \n");
      83             :     if ((nFlag & SCR_ABS_3D        ) == SCR_ABS_3D        )  printf("SCR_ABS_3D       \n");
      84             : }
      85             : #endif
      86             : 
      87             : //  class ScPrintAreasDlg
      88             : 
      89           0 : ScPrintAreasDlg::ScPrintAreasDlg( SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* pParent )
      90             :     : ScAnyRefDlg(pB, pCW, pParent, "PrintAreasDialog", "modules/scalc/ui/printareasdialog.ui")
      91             :     , bDlgLostFocus(false)
      92             :     , pDoc(NULL)
      93             :     , pViewData(NULL)
      94           0 :     , nCurTab(0)
      95             : {
      96           0 :     get(pLbPrintArea,"lbprintarea");
      97           0 :     get(pEdPrintArea,"edprintarea");
      98           0 :     pEdPrintArea->SetReferences(this, get<VclFrame>("printframe")->get_label_widget());
      99           0 :     pRefInputEdit = pEdPrintArea;
     100           0 :     get(pRbPrintArea,"rbprintarea");
     101           0 :     pRbPrintArea->SetReferences(this, pEdPrintArea);
     102             : 
     103           0 :     get(pLbRepeatRow,"lbrepeatrow");
     104           0 :     get(pEdRepeatRow,"edrepeatrow");
     105           0 :     pEdRepeatRow->SetReferences(this, get<VclFrame>("rowframe")->get_label_widget());
     106           0 :     get(pRbRepeatRow,"rbrepeatrow");
     107           0 :     pRbRepeatRow->SetReferences(this, pEdRepeatRow);
     108             : 
     109           0 :     get(pLbRepeatCol,"lbrepeatcol");
     110           0 :     get(pEdRepeatCol,"edrepeatcol");
     111           0 :     pEdRepeatCol->SetReferences(this, get<VclFrame>("colframe")->get_label_widget());
     112           0 :     get(pRbRepeatCol,"rbrepeatcol");
     113           0 :     pRbRepeatCol->SetReferences(this, pEdRepeatCol);
     114             : 
     115           0 :     get(pBtnOk,"ok");
     116           0 :     get(pBtnCancel,"cancel");
     117             : 
     118           0 :     ScTabViewShell* pScViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
     119           0 :     ScDocShell*     pScDocSh  = PTR_CAST( ScDocShell,     SfxObjectShell::Current() );
     120             : 
     121             :     OSL_ENSURE( pScDocSh, "Current DocumentShell not found :-(" );
     122             : 
     123           0 :     pDoc = &pScDocSh->GetDocument();
     124             : 
     125           0 :     if ( pScViewSh )
     126             :     {
     127           0 :         pViewData = &pScViewSh->GetViewData();
     128           0 :         nCurTab   = pViewData->GetTabNo();
     129             :     }
     130             : 
     131           0 :     Impl_Reset();
     132             : 
     133             :     //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
     134             :     //SFX_APPWINDOW->Enable();
     135           0 : }
     136             : 
     137           0 : ScPrintAreasDlg::~ScPrintAreasDlg()
     138             : {
     139             :     // Extra-Data an ListBox-Entries abraeumen
     140           0 :     ListBox* aLb[3] = { pLbPrintArea, pLbRepeatRow, pLbRepeatCol };
     141             : 
     142           0 :     for (sal_uInt16 i = 0; i < SAL_N_ELEMENTS(aLb); ++i)
     143             :     {
     144           0 :         sal_uInt16 nCount = aLb[i]->GetEntryCount();
     145           0 :         for ( sal_uInt16 j=0; j<nCount; j++ )
     146           0 :             delete (OUString*)aLb[i]->GetEntryData(j);
     147             :     }
     148           0 : }
     149             : 
     150           0 : bool ScPrintAreasDlg::Close()
     151             : {
     152           0 :     return DoClose( ScPrintAreasDlgWrapper::GetChildWindowId() );
     153             : }
     154             : 
     155           0 : bool ScPrintAreasDlg::IsTableLocked() const
     156             : {
     157             :     //  Druckbereiche gelten pro Tabelle, darum macht es keinen Sinn,
     158             :     //  bei der Eingabe die Tabelle umzuschalten
     159             : 
     160           0 :     return true;
     161             : }
     162             : 
     163           0 : void ScPrintAreasDlg::SetReference( const ScRange& rRef, ScDocument* /* pDoc */ )
     164             : {
     165           0 :     if ( pRefInputEdit )
     166             :     {
     167           0 :         if ( rRef.aStart != rRef.aEnd )
     168           0 :             RefInputStart( pRefInputEdit );
     169             : 
     170           0 :         OUString  aStr;
     171           0 :         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     172             : 
     173           0 :         if ( pEdPrintArea == pRefInputEdit )
     174             :         {
     175           0 :             aStr = rRef.Format(SCR_ABS, pDoc, eConv);
     176           0 :             OUString aVal = pEdPrintArea->GetText();
     177           0 :             Selection aSel = pEdPrintArea->GetSelection();
     178           0 :             aSel.Justify();
     179           0 :             aVal = aVal.replaceAt( aSel.Min(), aSel.Len(), aStr );
     180           0 :             Selection aNewSel( aSel.Min(), aSel.Min()+aStr.getLength() );
     181           0 :             pEdPrintArea->SetRefString( aVal );
     182           0 :             pEdPrintArea->SetSelection( aNewSel );
     183             :         }
     184             :         else
     185             :         {
     186           0 :             bool bRow = ( pEdRepeatRow == pRefInputEdit );
     187           0 :             lcl_GetRepeatRangeString(&rRef, pDoc, bRow, aStr);
     188           0 :             pRefInputEdit->SetRefString( aStr );
     189             :         }
     190           0 :         Impl_ModifyHdl( pRefInputEdit );
     191             :     }
     192           0 : }
     193             : 
     194           0 : void ScPrintAreasDlg::AddRefEntry()
     195             : {
     196           0 :     if ( pRefInputEdit == pEdPrintArea )
     197             :     {
     198           0 :         const sal_Unicode sep = ScCompiler::GetNativeSymbolChar(ocSep);
     199           0 :         OUString aVal = pEdPrintArea->GetText();
     200           0 :         aVal += OUString(sep);
     201           0 :         pEdPrintArea->SetText(aVal);
     202             : 
     203           0 :         sal_Int32 nLen = aVal.getLength();
     204           0 :         pEdPrintArea->SetSelection( Selection( nLen, nLen ) );
     205             : 
     206           0 :         Impl_ModifyHdl( pEdPrintArea );
     207             :     }
     208           0 : }
     209             : 
     210           0 : void ScPrintAreasDlg::Deactivate()
     211             : {
     212           0 :     bDlgLostFocus = true;
     213           0 : }
     214             : 
     215           0 : void ScPrintAreasDlg::SetActive()
     216             : {
     217           0 :     if ( bDlgLostFocus )
     218             :     {
     219           0 :         bDlgLostFocus = false;
     220             : 
     221           0 :         if ( pRefInputEdit )
     222             :         {
     223           0 :             pRefInputEdit->GrabFocus();
     224           0 :             Impl_ModifyHdl( pRefInputEdit );
     225             :         }
     226             :     }
     227             :     else
     228           0 :         GrabFocus();
     229             : 
     230           0 :     RefInputDone();
     231           0 : }
     232             : 
     233           0 : void ScPrintAreasDlg::Impl_Reset()
     234             : {
     235           0 :     OUString        aStrRange;
     236           0 :     const ScRange*  pRepeatColRange = pDoc->GetRepeatColRange( nCurTab );
     237           0 :     const ScRange*  pRepeatRowRange = pDoc->GetRepeatRowRange( nCurTab );
     238             : 
     239           0 :     pEdPrintArea->SetModifyHdl   ( HDL(Impl_ModifyHdl) );
     240           0 :     pEdRepeatRow->SetModifyHdl   ( HDL(Impl_ModifyHdl) );
     241           0 :     pEdRepeatCol->SetModifyHdl   ( HDL(Impl_ModifyHdl) );
     242           0 :     pEdPrintArea->SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
     243           0 :     pEdRepeatRow->SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
     244           0 :     pEdRepeatCol->SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
     245           0 :     pLbPrintArea->SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
     246           0 :     pLbRepeatRow->SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
     247           0 :     pLbRepeatCol->SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
     248           0 :     pLbPrintArea->SetSelectHdl   ( HDL(Impl_SelectHdl) );
     249           0 :     pLbRepeatRow->SetSelectHdl   ( HDL(Impl_SelectHdl) );
     250           0 :     pLbRepeatCol->SetSelectHdl   ( HDL(Impl_SelectHdl) );
     251           0 :     pBtnOk->      SetClickHdl    ( HDL(Impl_BtnHdl)    );
     252           0 :     pBtnCancel->  SetClickHdl    ( HDL(Impl_BtnHdl)    );
     253             : 
     254           0 :     Impl_FillLists();
     255             : 
     256             :     // Druckbereich
     257             : 
     258           0 :     aStrRange = "";
     259           0 :     OUString aOne;
     260           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     261           0 :     const sal_Unicode sep = ScCompiler::GetNativeSymbolChar(ocSep);
     262           0 :     sal_uInt16 nRangeCount = pDoc->GetPrintRangeCount( nCurTab );
     263           0 :     for (sal_uInt16 i=0; i<nRangeCount; i++)
     264             :     {
     265           0 :         const ScRange* pPrintRange = pDoc->GetPrintRange( nCurTab, i );
     266           0 :         if (pPrintRange)
     267             :         {
     268           0 :             if ( !aStrRange.isEmpty() )
     269           0 :                 aStrRange += OUString(sep);
     270           0 :             aOne = pPrintRange->Format(SCR_ABS, pDoc, eConv);
     271           0 :             aStrRange += aOne;
     272             :         }
     273             :     }
     274           0 :     pEdPrintArea->SetText( aStrRange );
     275             : 
     276             :     // Wiederholungszeile
     277             : 
     278           0 :     lcl_GetRepeatRangeString(pRepeatRowRange, pDoc, true, aStrRange);
     279           0 :     pEdRepeatRow->SetText( aStrRange );
     280             : 
     281             :     // Wiederholungsspalte
     282             : 
     283           0 :     lcl_GetRepeatRangeString(pRepeatColRange, pDoc, false, aStrRange);
     284           0 :     pEdRepeatCol->SetText( aStrRange );
     285             : 
     286           0 :     Impl_ModifyHdl( pEdPrintArea );
     287           0 :     Impl_ModifyHdl( pEdRepeatRow );
     288           0 :     Impl_ModifyHdl( pEdRepeatCol );
     289           0 :     if( pDoc->IsPrintEntireSheet( nCurTab ) )
     290           0 :         pLbPrintArea->SelectEntryPos( SC_AREASDLG_PR_ENTIRE );
     291             : 
     292           0 :     pEdPrintArea->SaveValue();   // fuer FillItemSet() merken:
     293           0 :     pEdRepeatRow->SaveValue();
     294           0 :     pEdRepeatCol->SaveValue();
     295           0 : }
     296             : 
     297           0 : bool ScPrintAreasDlg::Impl_GetItem( Edit* pEd, SfxStringItem& rItem )
     298             : {
     299           0 :     OUString  aRangeStr = pEd->GetText();
     300           0 :     bool bDataChanged = pEd->IsValueChangedFromSaved();
     301             : 
     302           0 :     if ( !aRangeStr.isEmpty() && pEdPrintArea != pEd )
     303             :     {
     304           0 :         ScRange aRange;
     305           0 :         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     306           0 :         lcl_CheckRepeatString(aRangeStr, pDoc, pEdRepeatRow == pEd, &aRange);
     307           0 :         aRangeStr = aRange.Format(SCR_ABS, pDoc, eConv);
     308             :     }
     309             : 
     310           0 :     rItem.SetValue( aRangeStr );
     311             : 
     312           0 :     return bDataChanged;
     313             : }
     314             : 
     315           0 : bool ScPrintAreasDlg::Impl_CheckRefStrings()
     316             : {
     317           0 :     bool        bOk = false;
     318           0 :     OUString      aStrPrintArea   = pEdPrintArea->GetText();
     319           0 :     OUString      aStrRepeatRow   = pEdRepeatRow->GetText();
     320           0 :     OUString      aStrRepeatCol   = pEdRepeatCol->GetText();
     321             : 
     322           0 :     bool bPrintAreaOk = true;
     323           0 :     if ( !aStrPrintArea.isEmpty() )
     324             :     {
     325           0 :         const sal_uInt16 nValidAddr  = SCA_VALID | SCA_VALID_ROW | SCA_VALID_COL;
     326           0 :         const sal_uInt16 nValidRange = nValidAddr | SCA_VALID_ROW2 | SCA_VALID_COL2;
     327           0 :         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     328           0 :         const sal_Unicode sep  = ScCompiler::GetNativeSymbolChar(ocSep);
     329             : 
     330           0 :         ScAddress aAddr;
     331           0 :         ScRange aRange;
     332           0 :         sal_Int32 nSepCount = comphelper::string::getTokenCount(aStrPrintArea, sep);
     333           0 :         for ( sal_Int32 i = 0; i < nSepCount && bPrintAreaOk; ++i )
     334             :         {
     335           0 :             OUString aOne = aStrPrintArea.getToken(i, sep);
     336           0 :             sal_uInt16 nResult = aRange.Parse( aOne, pDoc, eConv );
     337           0 :             if ((nResult & nValidRange) != nValidRange)
     338             :             {
     339           0 :                 sal_uInt16 nAddrResult = aAddr.Parse( aOne, pDoc, eConv );
     340           0 :                 if ((nAddrResult & nValidAddr) != nValidAddr)
     341           0 :                     bPrintAreaOk = false;
     342             :             }
     343           0 :         }
     344             :     }
     345             : 
     346           0 :     bool bRepeatRowOk = aStrRepeatRow.isEmpty();
     347           0 :     if ( !bRepeatRowOk )
     348           0 :         bRepeatRowOk = lcl_CheckRepeatString(aStrRepeatRow, pDoc, true, NULL);
     349             : 
     350           0 :     bool bRepeatColOk = aStrRepeatCol.isEmpty();
     351           0 :     if ( !bRepeatColOk )
     352           0 :         bRepeatColOk = lcl_CheckRepeatString(aStrRepeatCol, pDoc, false, NULL);
     353             : 
     354             :     // Fehlermeldungen
     355             : 
     356           0 :     bOk = (bPrintAreaOk && bRepeatRowOk && bRepeatColOk);
     357             : 
     358           0 :     if ( !bOk )
     359             :     {
     360           0 :         Edit* pEd = NULL;
     361             : 
     362           0 :              if ( !bPrintAreaOk ) pEd = pEdPrintArea;
     363           0 :         else if ( !bRepeatRowOk ) pEd = pEdRepeatRow;
     364           0 :         else if ( !bRepeatColOk ) pEd = pEdRepeatCol;
     365             : 
     366           0 :         ERRORBOX( STR_INVALID_TABREF );
     367             : 
     368             :         OSL_ASSERT(pEd);
     369             : 
     370           0 :         if (pEd)
     371           0 :             pEd->GrabFocus();
     372             :     }
     373             : 
     374           0 :     return bOk;
     375             : }
     376             : 
     377           0 : void ScPrintAreasDlg::Impl_FillLists()
     378             : {
     379             : 
     380             :     // Selektion holen und String in PrintArea-ListBox merken
     381             : 
     382           0 :     ScRange  aRange;
     383           0 :     OUString aStrRange;
     384           0 :     bool bSimple = true;
     385             : 
     386           0 :     if ( pViewData )
     387           0 :         bSimple = (pViewData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE);
     388             : 
     389           0 :     formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     390             : 
     391           0 :     if ( bSimple )
     392           0 :         aStrRange = aRange.Format(SCR_ABS, pDoc, eConv);
     393             :     else
     394             :     {
     395           0 :         ScRangeListRef aList( new ScRangeList );
     396           0 :         pViewData->GetMarkData().FillRangeListWithMarks( aList, false );
     397           0 :         aList->Format(aStrRange, SCR_ABS, pDoc, eConv);
     398             :     }
     399             : 
     400           0 :     pLbPrintArea->SetEntryData( SC_AREASDLG_PR_SELECT, new OUString( aStrRange ) );
     401             : 
     402             :     // Ranges holen und in ListBoxen merken
     403             : 
     404           0 :     ScRangeName* pRangeNames = pDoc->GetRangeName();
     405             : 
     406           0 :     if (!pRangeNames || pRangeNames->empty())
     407             :         // No range names to process.
     408           0 :         return;
     409             : 
     410           0 :     ScRangeName::const_iterator itr = pRangeNames->begin(), itrEnd = pRangeNames->end();
     411           0 :     for (; itr != itrEnd; ++itr)
     412             :     {
     413           0 :         if (!itr->second->HasType(RT_ABSAREA) && !itr->second->HasType(RT_REFAREA) && !itr->second->HasType(RT_ABSPOS))
     414           0 :             continue;
     415             : 
     416           0 :         OUString aName = itr->second->GetName();
     417           0 :         OUString aSymbol;
     418           0 :         itr->second->GetSymbol(aSymbol);
     419           0 :         if (aRange.ParseAny(aSymbol, pDoc, eConv) & SCA_VALID)
     420             :         {
     421           0 :             if (itr->second->HasType(RT_PRINTAREA))
     422             :             {
     423           0 :                 aSymbol = aRange.Format(SCR_ABS, pDoc, eConv);
     424             :                 pLbPrintArea->SetEntryData(
     425             :                     pLbPrintArea->InsertEntry(aName),
     426           0 :                     new OUString(aSymbol) );
     427             :             }
     428             : 
     429           0 :             if (itr->second->HasType(RT_ROWHEADER))
     430             :             {
     431           0 :                 lcl_GetRepeatRangeString(&aRange, pDoc, true, aSymbol);
     432             :                 pLbRepeatRow->SetEntryData(
     433             :                     pLbRepeatRow->InsertEntry(aName),
     434           0 :                     new OUString(aSymbol) );
     435             :             }
     436             : 
     437           0 :             if (itr->second->HasType(RT_COLHEADER))
     438             :             {
     439           0 :                 lcl_GetRepeatRangeString(&aRange, pDoc, false, aSymbol);
     440             :                 pLbRepeatCol->SetEntryData(
     441             :                     pLbRepeatCol->InsertEntry(aName),
     442           0 :                     new OUString(aSymbol));
     443             :             }
     444             :         }
     445           0 :     }
     446             : }
     447             : 
     448             : // Handler:
     449             : 
     450           0 : IMPL_LINK( ScPrintAreasDlg, Impl_BtnHdl, PushButton*, pBtn )
     451             : {
     452           0 :     if ( pBtnOk == pBtn )
     453             :     {
     454           0 :         if ( Impl_CheckRefStrings() )
     455             :         {
     456           0 :             OUString        aStr;
     457           0 :             SfxStringItem   aPrintArea( SID_CHANGE_PRINTAREA, aStr );
     458           0 :             SfxStringItem   aRepeatRow( FN_PARAM_2, aStr );
     459           0 :             SfxStringItem   aRepeatCol( FN_PARAM_3, aStr );
     460             : 
     461             :             // Druckbereich veraendert?
     462             : 
     463             :             // first try the list box, if "Entite sheet" is selected
     464           0 :             bool bEntireSheet = (pLbPrintArea->GetSelectEntryPos() == SC_AREASDLG_PR_ENTIRE);
     465           0 :             SfxBoolItem aEntireSheet( FN_PARAM_4, bEntireSheet );
     466             : 
     467           0 :             bool bDataChanged = bEntireSheet != pDoc->IsPrintEntireSheet( nCurTab );
     468           0 :             if( !bEntireSheet )
     469             :             {
     470             :                 // if new list box selection is not "Entire sheet", get the edit field contents
     471           0 :                 bDataChanged |= Impl_GetItem( pEdPrintArea, aPrintArea );
     472             :             }
     473             : 
     474             :             // Wiederholungszeile veraendert?
     475             : 
     476           0 :             bDataChanged |= Impl_GetItem( pEdRepeatRow, aRepeatRow );
     477             : 
     478             :             // Wiederholungsspalte veraendert?
     479             : 
     480           0 :             bDataChanged |= Impl_GetItem( pEdRepeatCol, aRepeatCol );
     481             : 
     482           0 :             if ( bDataChanged )
     483             :             {
     484           0 :                 SetDispatcherLock( false );
     485           0 :                 SwitchToDocument();
     486           0 :                 GetBindings().GetDispatcher()->Execute( SID_CHANGE_PRINTAREA,
     487             :                                           SfxCallMode::SLOT | SfxCallMode::RECORD,
     488           0 :                                           &aPrintArea, &aRepeatRow, &aRepeatCol, &aEntireSheet, 0L );
     489             :             }
     490             : 
     491           0 :             Close();
     492             :         }
     493             :     }
     494           0 :     else if ( pBtnCancel == pBtn )
     495           0 :         Close();
     496             : 
     497           0 :     return 0;
     498             : }
     499             : 
     500           0 : IMPL_LINK( ScPrintAreasDlg, Impl_GetFocusHdl, Control*, pCtr )
     501             : {
     502           0 :     if ( pCtr ==(Control *) pEdPrintArea ||
     503           0 :          pCtr ==(Control *) pEdRepeatRow ||
     504           0 :          pCtr ==(Control *) pEdRepeatCol)
     505             :     {
     506           0 :          pRefInputEdit = static_cast<formula::RefEdit*>(pCtr);
     507             :     }
     508           0 :     else if ( pCtr ==(Control *) pLbPrintArea)
     509             :     {
     510           0 :         pRefInputEdit = pEdPrintArea;
     511             :     }
     512           0 :     else if ( pCtr ==(Control *) pLbRepeatRow)
     513             :     {
     514           0 :         pRefInputEdit = pEdRepeatRow;
     515             :     }
     516           0 :     else if ( pCtr ==(Control *) pLbRepeatCol)
     517             :     {
     518           0 :         pRefInputEdit = pEdRepeatCol;
     519             :     }
     520             : 
     521           0 :     return 0;
     522             : }
     523             : 
     524           0 : IMPL_LINK( ScPrintAreasDlg, Impl_SelectHdl, ListBox*, pLb )
     525             : {
     526           0 :     sal_uInt16 nSelPos = pLb->GetSelectEntryPos();
     527           0 :     Edit* pEd = NULL;
     528             : 
     529             :     // list box positions of specific entries, default to "repeat row/column" list boxes
     530           0 :     sal_uInt16 nAllSheetPos = SC_AREASDLG_RR_NONE;
     531           0 :     sal_uInt16 nUserDefPos = SC_AREASDLG_RR_USER;
     532           0 :     sal_uInt16 nFirstCustomPos = SC_AREASDLG_RR_OFFSET;
     533             : 
     534             :     // find edit field for list box, and list box positions
     535           0 :     if( pLb == pLbPrintArea )
     536             :     {
     537           0 :         pEd = pEdPrintArea;
     538           0 :         nAllSheetPos = SC_AREASDLG_PR_ENTIRE;
     539           0 :         nUserDefPos = SC_AREASDLG_PR_USER;
     540           0 :         nFirstCustomPos = SC_AREASDLG_PR_SELECT;    // "Selection" and following
     541             :     }
     542           0 :     else if( pLb == pLbRepeatCol )
     543           0 :         pEd = pEdRepeatCol;
     544           0 :     else if( pLb == pLbRepeatRow )
     545           0 :         pEd = pEdRepeatRow;
     546             :     else
     547           0 :         return 0;
     548             : 
     549             :     // fill edit field according to list box selection
     550           0 :     if( (nSelPos == 0) || (nSelPos == nAllSheetPos) )
     551           0 :         pEd->SetText( EMPTY_OUSTRING );
     552           0 :     else if( nSelPos == nUserDefPos && !pLb->IsTravelSelect() && pEd->GetText().isEmpty())
     553           0 :         pLb->SelectEntryPos( 0 );
     554           0 :     else if( nSelPos >= nFirstCustomPos )
     555           0 :         pEd->SetText( *static_cast< OUString* >( pLb->GetEntryData( nSelPos ) ) );
     556             : 
     557           0 :     return 0;
     558             : }
     559             : 
     560           0 : IMPL_LINK( ScPrintAreasDlg, Impl_ModifyHdl, formula::RefEdit*, pEd )
     561             : {
     562           0 :     ListBox* pLb = NULL;
     563             : 
     564             :     // list box positions of specific entries, default to "repeat row/column" list boxes
     565           0 :     sal_uInt16 nUserDefPos = SC_AREASDLG_RR_USER;
     566           0 :     sal_uInt16 nFirstCustomPos = SC_AREASDLG_RR_OFFSET;
     567             : 
     568           0 :     if( pEd == pEdPrintArea )
     569             :     {
     570           0 :         pLb = pLbPrintArea;
     571           0 :         nUserDefPos = SC_AREASDLG_PR_USER;
     572           0 :         nFirstCustomPos = SC_AREASDLG_PR_SELECT;    // "Selection" and following
     573             :     }
     574           0 :     else if( pEd == pEdRepeatCol )
     575           0 :         pLb = pLbRepeatCol;
     576           0 :     else if( pEd == pEdRepeatRow )
     577           0 :         pLb = pLbRepeatRow;
     578             :     else
     579           0 :         return 0;
     580             : 
     581             :     // set list box selection according to edit field
     582           0 :     sal_uInt16  nEntryCount = pLb->GetEntryCount();
     583           0 :     OUString aStrEd( pEd->GetText() );
     584           0 :     OUString aEdUpper = aStrEd.toAsciiUpperCase();
     585             : 
     586           0 :     if ( (nEntryCount > nFirstCustomPos) && !aStrEd.isEmpty() )
     587             :     {
     588           0 :         bool    bFound  = false;
     589           0 :         OUString* pSymbol = NULL;
     590             :         sal_uInt16 i;
     591             : 
     592           0 :         for ( i=nFirstCustomPos; i<nEntryCount && !bFound; i++ )
     593             :         {
     594           0 :             pSymbol = (OUString*)pLb->GetEntryData( i );
     595           0 :             bFound  = ( (*pSymbol)  ==aStrEd || (*pSymbol) == aEdUpper );
     596             :         }
     597             : 
     598           0 :         pLb->SelectEntryPos( bFound ? i-1 : nUserDefPos );
     599             :     }
     600             :     else
     601           0 :         pLb->SelectEntryPos( !aStrEd.isEmpty() ? nUserDefPos : 0 );
     602             : 
     603           0 :     return 0;
     604             : }
     605             : 
     606             : // globale Funktionen:
     607             : 
     608             : // TODO: It might make sense to move these functions to address.?xx. -kohei
     609             : 
     610           0 : static bool lcl_CheckOne_OOO( const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
     611             : {
     612             :     // Zulaessige Syntax fuer rStr:
     613             :     // Row: [$]1-MAXTAB
     614             :     // Col: [$]A-IV
     615             : 
     616           0 :     OUString    aStr    = rStr;
     617           0 :     sal_Int32   nLen    = aStr.getLength();
     618           0 :     SCCOLROW    nNum    = 0;
     619           0 :     bool    bStrOk  = ( nLen > 0 ) && ( bIsRow ? ( nLen < 6 ) : ( nLen < 4 ) );
     620             : 
     621           0 :     if ( bStrOk )
     622             :     {
     623           0 :         if ( '$' == aStr[0] )
     624           0 :             aStr = aStr.copy( 1 );
     625             : 
     626           0 :         if ( bIsRow )
     627             :         {
     628           0 :             bStrOk = CharClass::isAsciiNumeric(aStr);
     629             : 
     630           0 :             if ( bStrOk )
     631             :             {
     632           0 :                 sal_Int32 n = aStr.toInt32();
     633             : 
     634           0 :                 if ( ( bStrOk = (n > 0) && ( n <= MAXROWCOUNT ) ) )
     635           0 :                     nNum = static_cast<SCCOLROW>(n - 1);
     636             :             }
     637             :         }
     638             :         else
     639             :         {
     640           0 :             SCCOL nCol = 0;
     641           0 :             bStrOk = ::AlphaToCol( nCol, aStr);
     642           0 :             nNum = nCol;
     643             :         }
     644             :     }
     645             : 
     646           0 :     if ( bStrOk )
     647           0 :         rVal = nNum;
     648             : 
     649           0 :     return bStrOk;
     650             : }
     651             : 
     652           0 : static bool lcl_CheckOne_XL_A1( const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
     653             : {
     654             :     // XL A1 style is identical to OOO one for print range formats.
     655           0 :     return lcl_CheckOne_OOO(rStr, bIsRow, rVal);
     656             : }
     657             : 
     658           0 : static bool lcl_CheckOne_XL_R1C1( const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
     659             : {
     660           0 :     sal_Int32 nLen = rStr.getLength();
     661           0 :     if (nLen <= 1)
     662             :         // There must be at least two characters.
     663           0 :         return false;
     664             : 
     665           0 :     const sal_Unicode preUpper = bIsRow ? 'R' : 'C';
     666           0 :     const sal_Unicode preLower = bIsRow ? 'r' : 'c';
     667           0 :     if (rStr[0] != preUpper && rStr[0] != preLower)
     668           0 :         return false;
     669             : 
     670           0 :     OUString aNumStr = rStr.copy(1);
     671           0 :     if (!CharClass::isAsciiNumeric(aNumStr))
     672           0 :         return false;
     673             : 
     674           0 :     sal_Int32 nNum = aNumStr.toInt32();
     675             : 
     676           0 :     if (nNum <= 0)
     677           0 :         return false;
     678             : 
     679           0 :     if ((bIsRow && nNum > MAXROWCOUNT) || (!bIsRow && nNum > MAXCOLCOUNT))
     680           0 :         return false;
     681             : 
     682           0 :     rVal = static_cast<SCCOLROW>(nNum-1);
     683           0 :     return true;
     684             : }
     685             : 
     686           0 : static bool lcl_CheckRepeatOne( const OUString& rStr, formula::FormulaGrammar::AddressConvention eConv, bool bIsRow, SCCOLROW& rVal )
     687             : {
     688           0 :     switch (eConv)
     689             :     {
     690             :         case formula::FormulaGrammar::CONV_OOO:
     691           0 :             return lcl_CheckOne_OOO(rStr, bIsRow, rVal);
     692             :         case formula::FormulaGrammar::CONV_XL_A1:
     693           0 :             return lcl_CheckOne_XL_A1(rStr, bIsRow, rVal);
     694             :         case formula::FormulaGrammar::CONV_XL_R1C1:
     695           0 :             return lcl_CheckOne_XL_R1C1(rStr, bIsRow, rVal);
     696             :         default:
     697             :         {
     698             :             // added to avoid warnings
     699             :         }
     700             :     }
     701           0 :     return false;
     702             : }
     703             : 
     704           0 : static bool lcl_CheckRepeatString( const OUString& rStr, ScDocument* pDoc, bool bIsRow, ScRange* pRange )
     705             : {
     706             :     // Row: [valid row] rsep [valid row]
     707             :     // Col: [valid col] rsep [valid col]
     708             : 
     709           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     710           0 :     const sal_Unicode rsep = ScCompiler::GetNativeSymbolChar(ocRange);
     711             : 
     712           0 :     if (pRange)
     713             :     {
     714             :         // initialize the range value.
     715           0 :         pRange->aStart.SetCol(0);
     716           0 :         pRange->aStart.SetRow(0);
     717           0 :         pRange->aEnd.SetCol(0);
     718           0 :         pRange->aEnd.SetRow(0);
     719             :     }
     720             : 
     721           0 :     OUString aBuf;
     722           0 :     SCCOLROW nVal = 0;
     723           0 :     sal_Int32 nLen = rStr.getLength();
     724           0 :     bool bEndPos = false;
     725           0 :     for( sal_Int32 i = 0; i < nLen; ++i )
     726             :     {
     727           0 :         const sal_Unicode c = rStr[i];
     728           0 :         if (c == rsep)
     729             :         {
     730           0 :             if (bEndPos)
     731             :                 // We aren't supposed to have more than one range separator.
     732           0 :                 return false;
     733             : 
     734             :             // range separator
     735           0 :             if (aBuf.isEmpty())
     736           0 :                 return false;
     737             : 
     738           0 :             bool bRes = lcl_CheckRepeatOne(aBuf, eConv, bIsRow, nVal);
     739           0 :             if (!bRes)
     740           0 :                 return false;
     741             : 
     742           0 :             if (pRange)
     743             :             {
     744           0 :                 if (bIsRow)
     745             :                 {
     746           0 :                     pRange->aStart.SetRow(static_cast<SCROW>(nVal));
     747           0 :                     pRange->aEnd.SetRow(static_cast<SCROW>(nVal));
     748             :                 }
     749             :                 else
     750             :                 {
     751           0 :                     pRange->aStart.SetCol(static_cast<SCCOL>(nVal));
     752           0 :                     pRange->aEnd.SetCol(static_cast<SCCOL>(nVal));
     753             :                 }
     754             :             }
     755             : 
     756           0 :             aBuf = "";
     757           0 :             bEndPos = true;
     758             :         }
     759             :         else
     760           0 :             aBuf += OUString(c);
     761             :     }
     762             : 
     763           0 :     if (!aBuf.isEmpty())
     764             :     {
     765           0 :         bool bRes = lcl_CheckRepeatOne(aBuf, eConv, bIsRow, nVal);
     766           0 :         if (!bRes)
     767           0 :             return false;
     768             : 
     769           0 :         if (pRange)
     770             :         {
     771           0 :             if (bIsRow)
     772             :             {
     773           0 :                 if (!bEndPos)
     774           0 :                     pRange->aStart.SetRow(static_cast<SCROW>(nVal));
     775           0 :                 pRange->aEnd.SetRow(static_cast<SCROW>(nVal));
     776             :             }
     777             :             else
     778             :             {
     779           0 :                 if (!bEndPos)
     780           0 :                     pRange->aStart.SetCol(static_cast<SCCOL>(nVal));
     781           0 :                 pRange->aEnd.SetCol(static_cast<SCCOL>(nVal));
     782             :             }
     783             :         }
     784             :     }
     785             : 
     786           0 :     return true;
     787             : }
     788             : 
     789           0 : static void lcl_GetRepeatRangeString( const ScRange* pRange, ScDocument* pDoc, bool bIsRow, OUString& rStr )
     790             : {
     791           0 :     rStr = "";
     792           0 :     if (!pRange)
     793           0 :         return;
     794             : 
     795           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     796           0 :     const ScAddress& rStart = pRange->aStart;
     797           0 :     const ScAddress& rEnd   = pRange->aEnd;
     798             : 
     799           0 :     const sal_uInt16 nFmt = bIsRow ? (SCA_VALID_ROW | SCA_ROW_ABSOLUTE) : (SCA_VALID_COL | SCA_COL_ABSOLUTE);
     800           0 :     rStr += rStart.Format(nFmt, pDoc, eConv);
     801           0 :     if ((bIsRow && rStart.Row() != rEnd.Row()) || (!bIsRow && rStart.Col() != rEnd.Col()))
     802             :     {
     803           0 :         rStr += ScCompiler::GetNativeSymbol(ocRange);
     804           0 :         rStr += rEnd.Format(nFmt, pDoc, eConv);
     805             :     }
     806         228 : }
     807             : 
     808             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10