1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "baside2.hxx"
12 #include <vcl/xtextedt.hxx>
13 #include <vcl/settings.hxx>
18 LineNumberWindow::LineNumberWindow (vcl::Window
* pParent
, ModulWindow
* pModulWindow
) :
19 Window(pParent
, WB_BORDER
),
20 m_pModulWindow(pModulWindow
),
23 SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
24 m_nBaseWidth
= GetTextWidth("8");
25 m_nWidth
= m_nBaseWidth
* 3 + m_nBaseWidth
/ 2;
28 LineNumberWindow::~LineNumberWindow()
33 void LineNumberWindow::dispose()
35 m_pModulWindow
.clear();
39 void LineNumberWindow::Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
44 ExtTextEngine
* txtEngine
= m_pModulWindow
->GetEditEngine();
48 TextView
* txtView
= m_pModulWindow
->GetEditView();
52 GetParent()->Resize();
54 int windowHeight
= rRenderContext
.GetOutputSize().Height();
55 int nLineHeight
= rRenderContext
.GetTextHeight();
61 int startY
= txtView
->GetStartDocPos().Y();
62 const sal_uInt32 nStartLine
= startY
/ nLineHeight
+ 1;
63 sal_uInt32 nEndLine
= (startY
+ windowHeight
) / nLineHeight
+ 1;
65 if (txtEngine
->GetParagraphCount() + 1 < 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 digit minimum, with a bit to spare for comfort
73 m_nWidth
= m_nBaseWidth
* 3 + m_nBaseWidth
/ 2;
74 sal_uInt32 i
= (nEndLine
+ 1) / 1000;
78 m_nWidth
+= m_nBaseWidth
;
81 sal_Int64 y
= (nStartLine
- 1) * static_cast<sal_Int64
>(nLineHeight
);
82 for (sal_uInt32 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
));
102 void LineNumberWindow::DoScroll(long nVertScroll
)
104 m_nCurYOffset
-= nVertScroll
;
105 Window::Scroll(0, nVertScroll
);
109 bool LineNumberWindow::SyncYOffset()
111 TextView
* pView
= m_pModulWindow
->GetEditView();
115 long nViewYOffset
= pView
->GetStartDocPos().Y();
116 if (m_nCurYOffset
== nViewYOffset
)
119 m_nCurYOffset
= nViewYOffset
;
125 } // namespace basctl
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */