[Libreoffice-commits] .: Branch 'feature/line-numbers-in-basicIDE' - basctl/source
August Sodora
augsod at kemper.freedesktop.org
Wed Nov 16 21:20:08 PST 2011
basctl/source/basicide/baside2b.cxx | 7 +++-
basctl/source/basicide/linenumberwindow.cxx | 44 +++++++++++++++++++++++++---
basctl/source/basicide/linenumberwindow.hxx | 8 ++++-
3 files changed, 53 insertions(+), 6 deletions(-)
New commits:
commit 3ee2d7b864fcf3364dbf1b8270b4aa176ff7d062
Author: August Sodora <augsod at gmail.com>
Date: Thu Nov 17 00:19:47 2011 -0500
Fixed scrolling bug
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 2a4d8ce..a80e9e4 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -333,6 +333,7 @@ void EditorWindow::Resize()
pEditView->SetStartDocPos( aStartDocPos );
pEditView->ShowCursor();
pModulWindow->GetBreakPointWindow().GetCurYOffset() = aStartDocPos.Y();
+ pModulWindow->GetLineNumberWindow().GetCurYOffset() = aStartDocPos.Y();
}
InitScrollBars();
if ( nVisY != pEditView->GetStartDocPos().Y() )
@@ -574,6 +575,7 @@ void EditorWindow::CreateEditEngine()
pEditView->SetStartDocPos( Point( 0, 0 ) );
pEditView->SetSelection( TextSelection() );
pModulWindow->GetBreakPointWindow().GetCurYOffset() = 0;
+ pModulWindow->GetLineNumberWindow().GetCurYOffset() = 0;
pEditEngine->SetUpdateMode( sal_True );
Update(); // has only been invalidated at UpdateMode = sal_True
@@ -661,7 +663,9 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
pModulWindow->GetEditVScrollBar().SetThumbPos( pEditView->GetStartDocPos().Y() );
pModulWindow->GetBreakPointWindow().DoScroll
( 0, pModulWindow->GetBreakPointWindow().GetCurYOffset() - pEditView->GetStartDocPos().Y() );
- pModulWindow->GetLineNumberWindow().Invalidate();
+ pModulWindow->GetLineNumberWindow().DoScroll
+ ( 0, pModulWindow->GetLineNumberWindow().GetCurYOffset() - pEditView->GetStartDocPos().Y() );
+ pModulWindow->Invalidate();
}
else if( rTextHint.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED )
{
@@ -1681,6 +1685,7 @@ IMPL_LINK( ComplexEditorWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
long nDiff = aEdtWindow.GetEditView()->GetStartDocPos().Y() - pCurScrollBar->GetThumbPos();
aEdtWindow.GetEditView()->Scroll( 0, nDiff );
aBrkWindow.DoScroll( 0, nDiff );
+ aLineNumberWindow.DoScroll(0, nDiff);
aEdtWindow.GetEditView()->ShowCursor( sal_False, sal_True );
pCurScrollBar->SetThumbPos( aEdtWindow.GetEditView()->GetStartDocPos().Y() );
}
diff --git a/basctl/source/basicide/linenumberwindow.cxx b/basctl/source/basicide/linenumberwindow.cxx
index 5168da1..deba85d 100644
--- a/basctl/source/basicide/linenumberwindow.cxx
+++ b/basctl/source/basicide/linenumberwindow.cxx
@@ -7,7 +7,8 @@
LineNumberWindow::LineNumberWindow( Window* pParent, ModulWindow* pModulWin ) :
Window( pParent, WB_BORDER ),
pModulWindow(pModulWin),
- nWidth(1)
+ nWidth(1),
+ nCurYOffset(0)
{
SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
}
@@ -16,6 +17,9 @@ LineNumberWindow::~LineNumberWindow() { }
void LineNumberWindow::Paint( const Rectangle& )
{
+ if(SyncYOffset())
+ return;
+
ExtTextEngine* txtEngine = pModulWindow->GetEditEngine();
if(!txtEngine)
return;
@@ -27,9 +31,9 @@ void LineNumberWindow::Paint( const Rectangle& )
GetParent()->Resize();
ulong windowHeight = GetOutputSize().Height();
- ulong startY = txtView->GetStartDocPos().Y();
ulong nLineHeight = GetTextHeight();
+ ulong startY = txtView->GetStartDocPos().Y();
ulong nStartLine = startY / nLineHeight + 1;
ulong nEndLine = (startY + windowHeight) / nLineHeight + 1;
@@ -38,8 +42,9 @@ void LineNumberWindow::Paint( const Rectangle& )
nWidth = String::CreateFromInt64(nEndLine).Len() * 10;
- for(ulong i = nStartLine, y = 0; i < nEndLine; ++i, y += nLineHeight)
- DrawText(Point(0, y), String::CreateFromInt64(i));
+ sal_Int64 y = (nStartLine - 1) * nLineHeight;
+ for(ulong i = nStartLine; i <= nEndLine; ++i, y += nLineHeight)
+ DrawText(Point(0, y - nCurYOffset), String::CreateFromInt64(i));
}
void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
@@ -56,3 +61,34 @@ void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
}
}
}
+
+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;
+}
+
+ulong LineNumberWindow::GetWidth()
+{
+ return (nWidth < 20 ? 20 : nWidth);
+}
diff --git a/basctl/source/basicide/linenumberwindow.hxx b/basctl/source/basicide/linenumberwindow.hxx
index 885ea14..fd30171 100644
--- a/basctl/source/basicide/linenumberwindow.hxx
+++ b/basctl/source/basicide/linenumberwindow.hxx
@@ -10,6 +10,7 @@ class LineNumberWindow : public Window
private:
ModulWindow* pModulWindow;
ulong nWidth;
+ long nCurYOffset;
virtual void DataChanged(DataChangedEvent const & rDCEvt);
@@ -20,7 +21,12 @@ public:
LineNumberWindow( Window* pParent, ModulWindow* pModulWin );
~LineNumberWindow();
- ulong GetWidth() { return (nWidth < 20 ? 20 : nWidth); }
+ void DoScroll( long nHorzScroll, long nVertScroll );
+
+ bool SyncYOffset();
+ long& GetCurYOffset();
+
+ ulong GetWidth();
};
#endif // BASICIDE_LINENUMBERWINDOW_HXX
More information about the Libreoffice-commits
mailing list