LCOV - code coverage report
Current view: top level - libreoffice/basctl/source/basicide - linenumberwindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 61 0.0 %
Date: 2012-12-17 Functions: 0 9 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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * [ Copyright (C) 2011 August Sodora <augsod@gmail.com> (initial developer) ]
      17             :  *
      18             :  * All Rights Reserved.
      19             :  *
      20             :  * For minor contributions see the git repository.
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : #include "baside2.hxx"
      30             : #include "linenumberwindow.hxx"
      31             : 
      32             : #include <vcl/xtextedt.hxx>
      33             : #include <vcl/textview.hxx>
      34             : 
      35             : namespace basctl
      36             : {
      37             : 
      38           0 : LineNumberWindow::LineNumberWindow (Window* pParent, ModulWindow* pModulWindow) :
      39             :     Window(pParent, WB_BORDER),
      40             :     m_pModulWindow(pModulWindow),
      41           0 :     m_nCurYOffset(0)
      42             : {
      43           0 :     SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
      44           0 :     m_nBaseWidth = GetTextWidth('8');
      45           0 :     m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
      46           0 : }
      47             : 
      48           0 : LineNumberWindow::~LineNumberWindow()
      49           0 : { }
      50             : 
      51           0 : void LineNumberWindow::Paint( const Rectangle& )
      52             : {
      53           0 :     if(SyncYOffset())
      54           0 :         return;
      55             : 
      56           0 :     ExtTextEngine* txtEngine = m_pModulWindow->GetEditEngine();
      57           0 :     if(!txtEngine)
      58           0 :         return;
      59             : 
      60           0 :     TextView* txtView = m_pModulWindow->GetEditView();
      61           0 :     if(!txtView)
      62           0 :         return;
      63             : 
      64           0 :     GetParent()->Resize();
      65             : 
      66           0 :     int windowHeight = GetOutputSize().Height();
      67           0 :     int nLineHeight = GetTextHeight();
      68             : 
      69           0 :     int startY = txtView->GetStartDocPos().Y();
      70           0 :     int nStartLine = startY / nLineHeight + 1;
      71           0 :     int nEndLine = (startY + windowHeight) / nLineHeight + 1;
      72             : 
      73           0 :     if(txtEngine->GetParagraphCount() + 1 < (unsigned int)nEndLine)
      74           0 :         nEndLine = txtEngine->GetParagraphCount() + 1;
      75             : 
      76             :     // FIXME: it would be best if we could get notified of a font change
      77             :     // rather than doing that re-calculation at each Paint event
      78           0 :     m_nBaseWidth = GetTextWidth(OUString('8'));
      79             : 
      80             :     // reserve enough for 3 sigit minimum, with a bit to spare for confort
      81           0 :     m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
      82           0 :     int i = (nEndLine + 1) / 1000;
      83           0 :     while(i)
      84             :     {
      85           0 :         i /= 10;
      86           0 :         m_nWidth += m_nBaseWidth;
      87             :     }
      88             : 
      89           0 :     sal_Int64 y = (nStartLine - 1) * nLineHeight;
      90           0 :     for(sal_Int32 n = nStartLine; n <= nEndLine; ++n, y += nLineHeight)
      91           0 :         DrawText(Point(0, y - m_nCurYOffset), OUString::valueOf(n));
      92             : }
      93             : 
      94           0 : void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
      95             : {
      96           0 :     Window::DataChanged(rDCEvt);
      97           0 :     if (rDCEvt.GetType() == DATACHANGED_SETTINGS
      98           0 :         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
      99             :     {
     100           0 :         Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
     101           0 :         if (aColor != rDCEvt.GetOldSettings()->GetStyleSettings().GetFieldColor())
     102             :         {
     103           0 :             SetBackground(Wallpaper(aColor));
     104           0 :             Invalidate();
     105             :         }
     106             :     }
     107           0 : }
     108             : 
     109           0 : void LineNumberWindow::DoScroll(long nHorzScroll, long nVertScroll)
     110             : {
     111           0 :     m_nCurYOffset -= nVertScroll;
     112           0 :     Window::Scroll(nHorzScroll, nVertScroll);
     113           0 : }
     114             : 
     115           0 : long& LineNumberWindow::GetCurYOffset()
     116             : {
     117           0 :     return m_nCurYOffset;
     118             : }
     119             : 
     120           0 : bool LineNumberWindow::SyncYOffset()
     121             : {
     122           0 :     TextView* pView = m_pModulWindow->GetEditView();
     123           0 :     if (!pView)
     124           0 :         return false;
     125             : 
     126           0 :     long nViewYOffset = pView->GetStartDocPos().Y();
     127           0 :     if (m_nCurYOffset == nViewYOffset)
     128           0 :         return false;
     129             : 
     130           0 :     m_nCurYOffset = nViewYOffset;
     131           0 :     Invalidate();
     132           0 :     return true;
     133             : }
     134             : 
     135           0 : int LineNumberWindow::GetWidth()
     136             : {
     137           0 :     return m_nWidth;
     138             : }
     139             : 
     140             : } // namespace basctl
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10