LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/miscdlgs - datafdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 209 0.0 %
Date: 2013-07-09 Functions: 0 23 0.0 %
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             : 
      10             : #undef SC_DLLIMPLEMENTATION
      11             : 
      12             : //------------------------------------------------------------------
      13             : 
      14             : #include "datafdlg.hxx"
      15             : #include "scresid.hxx"
      16             : #include "viewdata.hxx"
      17             : #include "docsh.hxx"
      18             : #include "refundo.hxx"
      19             : #include "undodat.hxx"
      20             : 
      21             : #include "rtl/ustrbuf.hxx"
      22             : 
      23             : #define HDL(hdl)            LINK( this, ScDataFormDlg, hdl )
      24             : 
      25             : 
      26           0 : ScDataFormDlg::ScDataFormDlg(Window* pParent, ScTabViewShell* pTabViewShellOri)
      27             :     : ModalDialog(pParent, "DataFormDialog", "modules/scalc/ui/dataform.ui")
      28           0 :     , pTabViewShell(pTabViewShellOri)
      29             : {
      30           0 :     get(m_pBtnNew, "new");
      31           0 :     get(m_pBtnDelete, "delete");
      32           0 :     get(m_pBtnRestore, "restore");
      33           0 :     get(m_pBtnPrev, "prev");
      34           0 :     get(m_pBtnNext, "next");
      35           0 :     get(m_pBtnClose, "close");
      36           0 :     get(m_pFixedText, "label");
      37           0 :     sNewRecord = m_pFixedText->GetText();
      38           0 :     get(m_pSlider, "scrollbar");
      39           0 :     get(m_pGrid, "grid");
      40             : 
      41             :     //read header form current document, and add new controls
      42             :     OSL_ENSURE( pTabViewShell, "pTabViewShell is NULL! :-/" );
      43           0 :     ScViewData* pViewData = pTabViewShell->GetViewData();
      44             : 
      45           0 :     pDoc = pViewData->GetDocument();
      46           0 :     if (pDoc)
      47             :     {
      48           0 :         ScRange aRange;
      49           0 :         pViewData->GetSimpleArea( aRange );
      50           0 :         ScAddress aStart = aRange.aStart;
      51           0 :         ScAddress aEnd = aRange.aEnd;
      52             : 
      53           0 :         nStartCol = aStart.Col();
      54           0 :         nEndCol = aEnd.Col();
      55           0 :         nStartRow   = aStart.Row();
      56           0 :         nEndRow = aEnd.Row();
      57             : 
      58           0 :         nTab = pViewData->GetTabNo();
      59             :         //if there is no selection
      60           0 :         if ((nStartCol == nEndCol) && (nStartRow == nEndRow))
      61           0 :             bNoSelection = true;
      62             : 
      63           0 :         if (bNoSelection)
      64             :         {
      65             :             //find last not blank cell in row
      66           0 :             for (int i=1;i<=MAX_DATAFORM_COLS;i++)
      67             :             {
      68           0 :                 nEndCol++;
      69           0 :                 OUString aColName = pDoc->GetString(nEndCol, nStartRow, nTab);
      70           0 :                 int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
      71           0 :                 if (aColName.isEmpty() && nColWidth)
      72             :                 {
      73           0 :                     nEndCol--;
      74           0 :                     break;
      75             :                 }
      76           0 :             }
      77             : 
      78             :             //find first not blank cell in row
      79           0 :             for (int i=1;i<=MAX_DATAFORM_COLS;i++)
      80             :             {
      81           0 :                 if (nStartCol <= 0)
      82           0 :                     break;
      83           0 :                 nStartCol--;
      84             : 
      85           0 :                 OUString aColName = pDoc->GetString(nStartCol, nStartRow, nTab);
      86           0 :                 int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
      87           0 :                 if (aColName.isEmpty() && nColWidth)
      88             :                 {
      89           0 :                     nStartCol++;
      90           0 :                     break;
      91             :                 }
      92           0 :             }
      93             : 
      94             :             //skip leading hide column
      95           0 :             for (int i=1;i<=MAX_DATAFORM_COLS;i++)
      96             :             {
      97           0 :                 int nColWidth = pDoc->GetColWidth( nStartCol, nTab );
      98           0 :                 if (nColWidth)
      99           0 :                     break;
     100           0 :                 nStartCol++;
     101             :             }
     102             : 
     103           0 :             if (nEndCol < nStartCol)
     104           0 :                 nEndCol = nStartCol;
     105             : 
     106             :             //find last not blank cell in row
     107           0 :             for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
     108             :             {
     109           0 :                 nEndRow++;
     110           0 :                 OUString aColName = pDoc->GetString(nStartCol, nEndRow, nTab);
     111           0 :                 if (aColName.isEmpty())
     112             :                 {
     113           0 :                     nEndRow--;
     114           0 :                     break;
     115             :                 }
     116           0 :             }
     117             : 
     118             :             //find first not blank cell in row
     119           0 :             for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
     120             :             {
     121           0 :                 if (nStartRow <= 0)
     122           0 :                     break;
     123           0 :                 nStartRow--;
     124             : 
     125           0 :                 OUString aColName = pDoc->GetString(nStartCol, nStartRow, nTab);
     126           0 :                 if (aColName.isEmpty())
     127             :                 {
     128           0 :                     nStartRow++;
     129           0 :                     break;
     130             :                 }
     131           0 :             }
     132             : 
     133           0 :             if (nEndRow < nStartRow)
     134           0 :                 nEndRow = nStartRow;
     135             :         }
     136             : 
     137           0 :         nCurrentRow = nStartRow + 1;
     138             : 
     139           0 :         aColLength = nEndCol - nStartCol + 1;
     140             : 
     141             :         //new the controls
     142           0 :         maFixedTexts.reserve(aColLength);
     143           0 :         maEdits.reserve(aColLength);
     144             : 
     145           0 :         sal_Int32 nGridRow = 0;
     146           0 :         for(sal_uInt16 nIndex = 0; nIndex < aColLength; ++nIndex)
     147             :         {
     148           0 :             OUString aFieldName = pDoc->GetString(nIndex + nStartCol, nStartRow, nTab);
     149           0 :             int nColWidth = pDoc->GetColWidth( nIndex + nStartCol, nTab );
     150           0 :             if (nColWidth)
     151             :             {
     152           0 :                 maFixedTexts.push_back( new FixedText(m_pGrid) );
     153           0 :                 maEdits.push_back( new Edit(m_pGrid, WB_BORDER) );
     154             : 
     155           0 :                 maFixedTexts[nIndex].set_grid_left_attach(0);
     156           0 :                 maEdits[nIndex].set_grid_left_attach(1);
     157           0 :                 maFixedTexts[nIndex].set_grid_top_attach(nGridRow);
     158           0 :                 maEdits[nIndex].set_grid_top_attach(nGridRow);
     159             : 
     160           0 :                 maEdits[nIndex].SetWidthInChars(32);
     161           0 :                 maEdits[nIndex].set_hexpand(true);
     162             : 
     163           0 :                 ++nGridRow;
     164             : 
     165           0 :                 maFixedTexts[nIndex].SetText(aFieldName);
     166           0 :                 maFixedTexts[nIndex].Show();
     167           0 :                 maEdits[nIndex].Show();
     168             :             }
     169             :             else
     170             :             {
     171           0 :                 maFixedTexts.push_back( NULL );
     172           0 :                 maEdits.push_back( NULL );
     173             :             }
     174           0 :             if (!maEdits.is_null(nIndex))
     175           0 :                 maEdits[nIndex].SetModifyHdl( HDL(Impl_DataModifyHdl) );
     176           0 :         }
     177             :     }
     178             : 
     179           0 :     FillCtrls(nCurrentRow);
     180             : 
     181           0 :     m_pSlider->SetPageSize( 10 );
     182           0 :     m_pSlider->SetVisibleSize( 1 );
     183           0 :     m_pSlider->SetLineSize( 1 );
     184           0 :     m_pSlider->SetRange( Range( 0, nEndRow - nStartRow + 1) );
     185           0 :     m_pSlider->Show();
     186             : 
     187           0 :     m_pBtnNew->SetClickHdl(HDL(Impl_NewHdl));
     188           0 :     m_pBtnPrev->SetClickHdl(HDL(Impl_PrevHdl));
     189           0 :     m_pBtnNext->SetClickHdl(HDL(Impl_NextHdl));
     190             : 
     191           0 :     m_pBtnRestore->SetClickHdl(HDL(Impl_RestoreHdl));
     192           0 :     m_pBtnDelete->SetClickHdl(HDL(Impl_DeleteHdl));
     193           0 :     m_pBtnClose->SetClickHdl(HDL(Impl_CloseHdl));
     194             : 
     195           0 :     m_pSlider->SetEndScrollHdl(HDL(Impl_ScrollHdl));
     196             : 
     197           0 :     SetButtonState();
     198           0 : }
     199             : 
     200           0 : ScDataFormDlg::~ScDataFormDlg()
     201             : {
     202             : 
     203           0 : }
     204             : 
     205           0 : void ScDataFormDlg::FillCtrls(SCROW /*nCurrentRow*/)
     206             : {
     207           0 :     String  aFieldName;
     208           0 :     for (sal_uInt16 i = 0; i < aColLength; ++i)
     209             :     {
     210           0 :         if (!maEdits.is_null(i))
     211             :         {
     212           0 :             if (nCurrentRow<=nEndRow)
     213             :             {
     214           0 :                 aFieldName = pDoc->GetString(i + nStartCol, nCurrentRow, nTab);
     215           0 :                 maEdits[i].SetText(aFieldName);
     216             :             }
     217             :             else
     218           0 :                 maEdits[i].SetText(String());
     219             :         }
     220             :     }
     221             : 
     222           0 :     if (nCurrentRow <= nEndRow)
     223             :     {
     224           0 :         OUStringBuffer aBuf;
     225           0 :         aBuf.append(static_cast<sal_Int32>(nCurrentRow - nStartRow));
     226           0 :         aBuf.appendAscii(" / ");
     227           0 :         aBuf.append(static_cast<sal_Int32>(nEndRow - nStartRow));
     228           0 :         m_pFixedText->SetText(aBuf.makeStringAndClear());
     229             :     }
     230             :     else
     231           0 :         m_pFixedText->SetText(sNewRecord);
     232             : 
     233           0 :     m_pSlider->SetThumbPos(nCurrentRow-nStartRow-1);
     234           0 : }
     235             : 
     236           0 : IMPL_LINK( ScDataFormDlg, Impl_DataModifyHdl, Edit*, pEdit)
     237             : {
     238           0 :     if ( pEdit->IsModified() )
     239           0 :         m_pBtnRestore->Enable( true );
     240           0 :     return 0;
     241             : }
     242             : 
     243           0 : IMPL_LINK_NOARG(ScDataFormDlg, Impl_NewHdl)
     244             : {
     245           0 :     ScViewData* pViewData = pTabViewShell->GetViewData();
     246           0 :     ScDocShell* pDocSh = pViewData->GetDocShell();
     247           0 :     if ( pDoc )
     248             :     {
     249           0 :         bool bHasData = false;
     250           0 :         boost::ptr_vector<Edit>::iterator itr = maEdits.begin(), itrEnd = maEdits.end();
     251           0 :         for(; itr != itrEnd; ++itr)
     252           0 :             if (!boost::is_null(itr))
     253           0 :                 if ( !(*itr).GetText().isEmpty() )
     254             :                 {
     255           0 :                     bHasData = true;
     256           0 :                     break;
     257             :                 }
     258             : 
     259           0 :         if ( bHasData )
     260             :         {
     261           0 :             pTabViewShell->DataFormPutData( nCurrentRow , nStartRow , nStartCol , nEndRow , nEndCol , maEdits , aColLength );
     262           0 :             nCurrentRow++;
     263           0 :             if (nCurrentRow >= nEndRow + 2)
     264             :             {
     265           0 :                     nEndRow ++ ;
     266           0 :                     m_pSlider->SetRange( Range( 0, nEndRow - nStartRow + 1) );
     267             :             }
     268           0 :             SetButtonState();
     269           0 :             FillCtrls(nCurrentRow);
     270           0 :             pDocSh->SetDocumentModified();
     271           0 :             pDocSh->PostPaintGridAll();
     272             :             }
     273             :     }
     274           0 :     return 0;
     275             : }
     276             : 
     277           0 : IMPL_LINK_NOARG(ScDataFormDlg, Impl_PrevHdl)
     278             : {
     279           0 :     if (pDoc)
     280             :     {
     281           0 :         if ( nCurrentRow > nStartRow +1 )
     282           0 :             nCurrentRow--;
     283             : 
     284           0 :         SetButtonState();
     285           0 :         FillCtrls(nCurrentRow);
     286             :     }
     287           0 :     return 0;
     288             : }
     289             : 
     290           0 : IMPL_LINK_NOARG(ScDataFormDlg, Impl_NextHdl)
     291             : {
     292           0 :     if (pDoc)
     293             :     {
     294           0 :         if ( nCurrentRow <= nEndRow)
     295           0 :             nCurrentRow++;
     296             : 
     297           0 :         SetButtonState();
     298           0 :         FillCtrls(nCurrentRow);
     299             :     }
     300           0 :     return 0;
     301             : }
     302             : 
     303           0 : IMPL_LINK_NOARG(ScDataFormDlg, Impl_RestoreHdl)
     304             : {
     305           0 :     if (pDoc)
     306             :     {
     307           0 :         FillCtrls(nCurrentRow);
     308             :     }
     309           0 :     return 0;
     310             : }
     311             : 
     312           0 : IMPL_LINK_NOARG(ScDataFormDlg, Impl_DeleteHdl)
     313             : {
     314           0 :     ScViewData* pViewData = pTabViewShell->GetViewData();
     315           0 :     ScDocShell* pDocSh = pViewData->GetDocShell();
     316           0 :     if (pDoc)
     317             :     {
     318           0 :         ScRange aRange(nStartCol, nCurrentRow, nTab, nEndCol, nCurrentRow, nTab);
     319           0 :         pDoc->DeleteRow(aRange);
     320           0 :         nEndRow--;
     321             : 
     322           0 :         SetButtonState();
     323           0 :         pDocSh->GetUndoManager()->Clear();
     324             : 
     325           0 :         FillCtrls(nCurrentRow);
     326           0 :         pDocSh->SetDocumentModified();
     327           0 :         pDocSh->PostPaintGridAll();
     328             :     }
     329           0 :     return 0;
     330             : }
     331             : 
     332           0 : IMPL_LINK_NOARG(ScDataFormDlg, Impl_CloseHdl)
     333             : {
     334           0 :     EndDialog( );
     335           0 :     return 0;
     336             : }
     337             : 
     338           0 : IMPL_LINK_NOARG(ScDataFormDlg, Impl_ScrollHdl)
     339             : {
     340           0 :     long nOffset = m_pSlider->GetThumbPos();
     341           0 :     nCurrentRow = nStartRow + nOffset + 1;
     342           0 :     SetButtonState();
     343           0 :     FillCtrls(nCurrentRow);
     344           0 :     return 0;
     345             : }
     346             : 
     347           0 : void ScDataFormDlg::SetButtonState()
     348             : {
     349           0 :     if (nCurrentRow > nEndRow)
     350             :     {
     351           0 :         m_pBtnDelete->Enable( false );
     352           0 :         m_pBtnNext->Enable( false );
     353             :     }
     354             :     else
     355             :     {
     356           0 :         m_pBtnDelete->Enable( true );
     357           0 :         m_pBtnNext->Enable( true );
     358             :     }
     359             : 
     360           0 :     if (nCurrentRow == nStartRow + 1)
     361           0 :         m_pBtnPrev->Enable( false );
     362             :     else
     363           0 :         m_pBtnPrev->Enable( true );
     364             : 
     365           0 :     m_pBtnRestore->Enable( false );
     366           0 :     if ( maEdits.size()>=1 && !maEdits.is_null(0) )
     367           0 :         maEdits[0].GrabFocus();
     368           0 : }
     369             : 
     370             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10