bump product version to 4.1.6.2
[LibreOffice.git] / basctl / source / basicide / linenumberwindow.cxx
blob8baa2fe31bd033f8d807f47df0f38f788db1df86
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "baside2.hxx"
11 #include "linenumberwindow.hxx"
13 #include <vcl/xtextedt.hxx>
14 #include <vcl/textview.hxx>
16 namespace basctl
19 LineNumberWindow::LineNumberWindow (Window* pParent, ModulWindow* pModulWindow) :
20 Window(pParent, WB_BORDER),
21 m_pModulWindow(pModulWindow),
22 m_nCurYOffset(0)
24 SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
25 m_nBaseWidth = GetTextWidth("8");
26 m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
29 LineNumberWindow::~LineNumberWindow()
30 { }
32 void LineNumberWindow::Paint( const Rectangle& )
34 if(SyncYOffset())
35 return;
37 ExtTextEngine* txtEngine = m_pModulWindow->GetEditEngine();
38 if(!txtEngine)
39 return;
41 TextView* txtView = m_pModulWindow->GetEditView();
42 if(!txtView)
43 return;
45 GetParent()->Resize();
47 int windowHeight = GetOutputSize().Height();
48 int nLineHeight = GetTextHeight();
49 if(!nLineHeight)
51 return;
54 int startY = txtView->GetStartDocPos().Y();
55 int nStartLine = startY / nLineHeight + 1;
56 int nEndLine = (startY + windowHeight) / nLineHeight + 1;
58 if(txtEngine->GetParagraphCount() + 1 < (unsigned int)nEndLine)
59 nEndLine = txtEngine->GetParagraphCount() + 1;
61 // FIXME: it would be best if we could get notified of a font change
62 // rather than doing that re-calculation at each Paint event
63 m_nBaseWidth = GetTextWidth("8");
65 // reserve enough for 3 sigit minimum, with a bit to spare for confort
66 m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
67 int i = (nEndLine + 1) / 1000;
68 while(i)
70 i /= 10;
71 m_nWidth += m_nBaseWidth;
74 sal_Int64 y = (nStartLine - 1) * (sal_Int64)nLineHeight;
75 for(sal_Int32 n = nStartLine; n <= nEndLine; ++n, y += nLineHeight)
76 DrawText(Point(0, y - m_nCurYOffset), OUString::valueOf(n));
79 void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
81 Window::DataChanged(rDCEvt);
82 if (rDCEvt.GetType() == DATACHANGED_SETTINGS
83 && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
85 Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
86 const AllSettings* pOldSettings = rDCEvt.GetOldSettings();
87 if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetFieldColor())
89 SetBackground(Wallpaper(aColor));
90 Invalidate();
95 void LineNumberWindow::DoScroll(long nHorzScroll, long nVertScroll)
97 m_nCurYOffset -= nVertScroll;
98 Window::Scroll(nHorzScroll, nVertScroll);
101 long& LineNumberWindow::GetCurYOffset()
103 return m_nCurYOffset;
106 bool LineNumberWindow::SyncYOffset()
108 TextView* pView = m_pModulWindow->GetEditView();
109 if (!pView)
110 return false;
112 long nViewYOffset = pView->GetStartDocPos().Y();
113 if (m_nCurYOffset == nViewYOffset)
114 return false;
116 m_nCurYOffset = nViewYOffset;
117 Invalidate();
118 return true;
121 int LineNumberWindow::GetWidth()
123 return m_nWidth;
126 } // namespace basctl
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */