summaryrefslogtreecommitdiff
path: root/basctl/source/basicide/linenumberwindow.cxx
blob: 5168da1b092a9e5cc461f8c36cf76ce328a62fed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "baside2.hxx"
#include "linenumberwindow.hxx"

#include <svtools/xtextedt.hxx>
#include <svtools/textview.hxx>

LineNumberWindow::LineNumberWindow( Window* pParent, ModulWindow* pModulWin ) :
  Window( pParent, WB_BORDER ),
  pModulWindow(pModulWin),
  nWidth(1)
{
  SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
}

LineNumberWindow::~LineNumberWindow() { }

void LineNumberWindow::Paint( const Rectangle& )
{
  ExtTextEngine* txtEngine = pModulWindow->GetEditEngine();
  if(!txtEngine)
    return;

  TextView* txtView = pModulWindow->GetEditView();
  if(!txtView)
    return;

  GetParent()->Resize();

  ulong windowHeight = GetOutputSize().Height();
  ulong startY = txtView->GetStartDocPos().Y();
  ulong nLineHeight = GetTextHeight();

  ulong nStartLine = startY / nLineHeight + 1;
  ulong nEndLine = (startY + windowHeight) / nLineHeight + 1;

  if(txtEngine->GetParagraphCount() + 1 < nEndLine)
    nEndLine = txtEngine->GetParagraphCount() + 1;

  nWidth = String::CreateFromInt64(nEndLine).Len() * 10;

  for(ulong i = nStartLine, y = 0; i < nEndLine; ++i, y += nLineHeight)
    DrawText(Point(0, y), String::CreateFromInt64(i));
}

void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
{
  Window::DataChanged(rDCEvt);
  if (rDCEvt.GetType() == DATACHANGED_SETTINGS
      && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
  {
    Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
    if (aColor != rDCEvt.GetOldSettings()->GetStyleSettings().GetFieldColor())
    {
      SetBackground(Wallpaper(aColor));
      Invalidate();
    }
  }
}