summaryrefslogtreecommitdiff
path: root/basctl/source/basicide/linenumberwindow.cxx
blob: fb7bed6118f33b90d3a56f808efc73da642be362 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#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),
  nCurYOffset(0)
{
  SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
}

LineNumberWindow::~LineNumberWindow() { }

void LineNumberWindow::Paint( const Rectangle& )
{
  if(SyncYOffset())
    return;

  ExtTextEngine* txtEngine = pModulWindow->GetEditEngine();
  if(!txtEngine)
    return;

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

  GetParent()->Resize();

  int windowHeight = GetOutputSize().Height();
  int nLineHeight = GetTextHeight();

  int startY = txtView->GetStartDocPos().Y();
  int nStartLine = startY / nLineHeight + 1;
  int nEndLine = (startY + windowHeight) / nLineHeight + 1;

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

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

  sal_Int64 y = (nStartLine - 1) * nLineHeight;
  for(int i = nStartLine; i <= nEndLine; ++i, y += nLineHeight)
    DrawText(Point(0, y - nCurYOffset), 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();
    }
  }
}

void LineNumberWindow::DoScroll(long nHorzScroll, long nVertScroll)
{
  nCurYOffset -= nVertScroll;
  Window::Scroll(nHorzScroll, nVertScroll);
}

long& LineNumberWindow::GetCurYOffset()
{
  return nCurYOffset;
}

bool LineNumberWindow::SyncYOffset()
{
  TextView* pView = pModulWindow->GetEditView();
  if (!pView)
    return false;

  long nViewYOffset = pView->GetStartDocPos().Y();
  if (nCurYOffset == nViewYOffset)
    return false;

  nCurYOffset = nViewYOffset;
  Invalidate();
  return true;
}

int LineNumberWindow::GetWidth()
{
  return (nWidth < 20 ? 20 : nWidth);
}