bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / basicide / linenumberwindow.cxx
blob0c3ed9156235287ea9cee7d62bfb98d978fc8a52
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"
12 #include <vcl/xtextedt.hxx>
13 #include <vcl/settings.hxx>
15 namespace basctl
18 LineNumberWindow::LineNumberWindow (vcl::Window* pParent, ModulWindow* pModulWindow) :
19 Window(pParent, WB_BORDER),
20 m_pModulWindow(pModulWindow),
21 m_nCurYOffset(0)
23 SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
24 m_nBaseWidth = GetTextWidth("8");
25 m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
28 LineNumberWindow::~LineNumberWindow()
30 disposeOnce();
33 void LineNumberWindow::dispose()
35 m_pModulWindow.clear();
36 Window::dispose();
39 void LineNumberWindow::Paint( vcl::RenderContext& rRenderContext, const Rectangle&)
41 if(SyncYOffset())
42 return;
44 ExtTextEngine* txtEngine = m_pModulWindow->GetEditEngine();
45 if (!txtEngine)
46 return;
48 TextView* txtView = m_pModulWindow->GetEditView();
49 if (!txtView)
50 return;
52 GetParent()->Resize();
54 int windowHeight = rRenderContext.GetOutputSize().Height();
55 int nLineHeight = rRenderContext.GetTextHeight();
56 if (!nLineHeight)
58 return;
61 int startY = txtView->GetStartDocPos().Y();
62 int nStartLine = startY / nLineHeight + 1;
63 int nEndLine = (startY + windowHeight) / nLineHeight + 1;
65 if (txtEngine->GetParagraphCount() + 1 < (unsigned int)nEndLine)
66 nEndLine = txtEngine->GetParagraphCount() + 1;
68 // FIXME: it would be best if we could get notified of a font change
69 // rather than doing that re-calculation at each Paint event
70 m_nBaseWidth = GetTextWidth("8");
72 // reserve enough for 3 sigit minimum, with a bit to spare for confort
73 m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
74 int i = (nEndLine + 1) / 1000;
75 while (i)
77 i /= 10;
78 m_nWidth += m_nBaseWidth;
81 sal_Int64 y = (nStartLine - 1) * (sal_Int64)nLineHeight;
82 for (sal_Int32 n = nStartLine; n <= nEndLine; ++n, y += nLineHeight)
83 rRenderContext.DrawText(Point(0, y - m_nCurYOffset), OUString::number(n));
86 void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
88 Window::DataChanged(rDCEvt);
89 if (rDCEvt.GetType() == DataChangedEventType::SETTINGS
90 && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
92 Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
93 const AllSettings* pOldSettings = rDCEvt.GetOldSettings();
94 if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetFieldColor())
96 SetBackground(Wallpaper(aColor));
97 Invalidate();
102 void LineNumberWindow::DoScroll(long nHorzScroll, long nVertScroll)
104 m_nCurYOffset -= nVertScroll;
105 Window::Scroll(nHorzScroll, nVertScroll);
109 bool LineNumberWindow::SyncYOffset()
111 TextView* pView = m_pModulWindow->GetEditView();
112 if (!pView)
113 return false;
115 long nViewYOffset = pView->GetStartDocPos().Y();
116 if (m_nCurYOffset == nViewYOffset)
117 return false;
119 m_nCurYOffset = nViewYOffset;
120 Invalidate();
121 return true;
125 } // namespace basctl
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */