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"
11 #include "linenumberwindow.hxx"
13 #include <vcl/xtextedt.hxx>
14 #include <vcl/textview.hxx>
19 LineNumberWindow::LineNumberWindow (Window
* pParent
, ModulWindow
* pModulWindow
) :
20 Window(pParent
, WB_BORDER
),
21 m_pModulWindow(pModulWindow
),
24 SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
25 m_nBaseWidth
= GetTextWidth("8");
26 m_nWidth
= m_nBaseWidth
* 3 + m_nBaseWidth
/ 2;
29 LineNumberWindow::~LineNumberWindow()
32 void LineNumberWindow::Paint( const Rectangle
& )
37 ExtTextEngine
* txtEngine
= m_pModulWindow
->GetEditEngine();
41 TextView
* txtView
= m_pModulWindow
->GetEditView();
45 GetParent()->Resize();
47 int windowHeight
= GetOutputSize().Height();
48 int nLineHeight
= GetTextHeight();
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;
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
));
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();
112 long nViewYOffset
= pView
->GetStartDocPos().Y();
113 if (m_nCurYOffset
== nViewYOffset
)
116 m_nCurYOffset
= nViewYOffset
;
121 int LineNumberWindow::GetWidth()
126 } // namespace basctl
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */