Hello,

I've attached a patch that attempts to add line numbers to the basic
ide. I believe it is mostly correct, although I am seeing a couple of
rendering issues that I haven't been able to track down yet. First,
the scrollbar seems to jump around and flicker a lot more than it does
without this patch. Second, typing so that the window has to scroll
horizontally causes the vertical scrollbar to move to a nonsensical
position. If anybody has a moment to take a look at this I would
really appreciate it! This has been bugging me for a while.

August Sodora
aug...@gmail.com
(201) 280-8138
From ae17befde6bf4173dd01edbff30464e841687591 Mon Sep 17 00:00:00 2001
From: August Sodora <aug...@gmail.com>
Date: Wed, 9 Nov 2011 21:28:55 -0500
Subject: [PATCH] Add line numbers to basic ide

---
 basctl/Library_basctl.mk                    |    1 +
 basctl/source/basicide/baside2.hxx          |    6 +++
 basctl/source/basicide/baside2b.cxx         |   29 ++++++++++----
 basctl/source/basicide/linenumberwindow.cxx |   58 +++++++++++++++++++++++++++
 basctl/source/basicide/linenumberwindow.hxx |   26 ++++++++++++
 5 files changed, 112 insertions(+), 8 deletions(-)
 create mode 100644 basctl/source/basicide/linenumberwindow.cxx
 create mode 100644 basctl/source/basicide/linenumberwindow.hxx

diff --git a/basctl/Library_basctl.mk b/basctl/Library_basctl.mk
index c806980..b1badf4 100644
--- a/basctl/Library_basctl.mk
+++ b/basctl/Library_basctl.mk
@@ -94,6 +94,7 @@ $(eval $(call gb_Library_add_exception_objects,basctl,\
 	basctl/source/basicide/docsignature \
 	basctl/source/basicide/documentenumeration \
 	basctl/source/basicide/iderdll \
+	basctl/source/basicide/linenumberwindow \
 	basctl/source/basicide/localizationmgr \
 	basctl/source/basicide/macrodlg \
 	basctl/source/basicide/moduldl2 \
diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 6af6c06..1de34d7 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -42,6 +42,7 @@ class SvxSearchItem;
 #include <svtools/headbar.hxx>
 
 #include <vcl/button.hxx>
+#include <basic/sbstar.hxx>
 #include <basic/sbmod.hxx>
 #include <vcl/split.hxx>
 #include "svl/lstner.hxx"
@@ -50,6 +51,8 @@ class SvxSearchItem;
 #include <sfx2/progress.hxx>
 #include <svtools/syntaxhighlight.hxx>
 
+#include "linenumberwindow.hxx"
+
 DBG_NAMEEX( ModulWindow )
 
 #define MARKER_NOMARKER 0xFFFF
@@ -284,6 +287,7 @@ class ComplexEditorWindow : public Window
 {
 private:
     BreakPointWindow    aBrkWindow;
+    LineNumberWindow    aLineNumberWindow;
     EditorWindow        aEdtWindow;
     ScrollBar           aEWVScrollBar;
 
@@ -297,6 +301,7 @@ public:
                         ComplexEditorWindow( ModulWindow* pParent );
 
     BreakPointWindow&   GetBrkWindow()      { return aBrkWindow; }
+    LineNumberWindow&   GetLineNumberWindow() { return aLineNumberWindow; }
     EditorWindow&       GetEdtWindow()      { return aEdtWindow; }
     ScrollBar&          GetEWVScrollBar()   { return aEWVScrollBar; }
 };
@@ -402,6 +407,7 @@ public:
 
     EditorWindow&       GetEditorWindow()       { return aXEditorWindow.GetEdtWindow(); }
     BreakPointWindow&   GetBreakPointWindow()   { return aXEditorWindow.GetBrkWindow(); }
+    LineNumberWindow&   GetLineNumberWindow()   { return aXEditorWindow.GetLineNumberWindow(); }
     ScrollBar&          GetEditVScrollBar()     { return aXEditorWindow.GetEWVScrollBar(); }
     ExtTextEngine*      GetEditEngine()         { return GetEditorWindow().GetEditEngine(); }
     ExtTextView*        GetEditView()           { return GetEditorWindow().GetEditView(); }
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 8f348d2..21b0f76 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -580,6 +580,7 @@ void EditorWindow::CreateEditEngine()
     pModulWindow->GetLayout()->GetWatchWindow().Update();
     pModulWindow->GetLayout()->GetStackWindow().Update();
     pModulWindow->GetBreakPointWindow().Update();
+    pModulWindow->GetLineNumberWindow().Update();
 
     pEditView->ShowCursor( sal_True, sal_True );
 
@@ -660,6 +661,7 @@ 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();
         }
         else if( rTextHint.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED )
         {
@@ -669,6 +671,8 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
                 long nTextHeight = pEditEngine->GetTextHeight();
                 if ( nTextHeight < nOutHeight )
                     pEditView->Scroll( 0, pEditView->GetStartDocPos().Y() );
+
+                pModulWindow->GetLineNumberWindow().Invalidate();
             }
 
             SetScrollBarRanges();
@@ -792,7 +796,10 @@ void EditorWindow::ImplSetFont()
         aFont = GetFont();
 
         if ( pModulWindow )
+        {
             pModulWindow->GetBreakPointWindow().SetFont( aFont );
+            pModulWindow->GetLineNumberWindow().SetFont( aFont );
+        }
 
         if ( pEditEngine )
         {
@@ -873,6 +880,7 @@ void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, sal_Bool bInserted
     {
         pModulWindow->GetBreakPoints().reset();
         pModulWindow->GetBreakPointWindow().Invalidate();
+        pModulWindow->GetLineNumberWindow().Invalidate();
         aHighlighter.initialize( HIGHLIGHT_BASIC );
     }
     else
@@ -886,6 +894,11 @@ void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, sal_Bool bInserted
         aInvRec.Top() = nY;
         pModulWindow->GetBreakPointWindow().Invalidate( aInvRec );
 
+        Size aLnSz(pModulWindow->GetLineNumberWindow().GetWidth(),
+                   GetOutputSizePixel().Height() - 2 * DWBORDER);
+        pModulWindow->GetLineNumberWindow().SetPosSizePixel(Point(DWBORDER + 19, DWBORDER), aLnSz);
+        pModulWindow->GetLineNumberWindow().Invalidate();
+
         if ( bDoSyntaxHighlight )
         {
             String aDummy;
@@ -1612,12 +1625,10 @@ void StackWindow::UpdateCalls()
     aTreeListBox.SetUpdateMode( sal_True );
 }
 
-
-
-
 ComplexEditorWindow::ComplexEditorWindow( ModulWindow* pParent ) :
     Window( pParent, WB_3DLOOK | WB_CLIPCHILDREN ),
     aBrkWindow( this ),
+    aLineNumberWindow( this, pParent ),
     aEdtWindow( this ),
     aEWVScrollBar( this, WB_VSCROLL | WB_DRAG )
 {
@@ -1625,6 +1636,7 @@ ComplexEditorWindow::ComplexEditorWindow( ModulWindow* pParent ) :
     aBrkWindow.SetModulWindow( pParent );
     aEdtWindow.Show();
     aBrkWindow.Show();
+    aLineNumberWindow.Show();
 
     aEWVScrollBar.SetLineSize( SCROLL_LINE );
     aEWVScrollBar.SetPageSize( SCROLL_PAGE );
@@ -1632,8 +1644,6 @@ ComplexEditorWindow::ComplexEditorWindow( ModulWindow* pParent ) :
     aEWVScrollBar.Show();
 }
 
-
-
 void ComplexEditorWindow::Resize()
 {
     Size aOutSz = GetOutputSizePixel();
@@ -1643,11 +1653,14 @@ void ComplexEditorWindow::Resize()
     long nBrkWidth = 20;
     long nSBWidth = aEWVScrollBar.GetSizePixel().Width();
 
-    Size aBrkSz( Size( nBrkWidth, aSz.Height() ) );
+    Size aBrkSz(nBrkWidth, aSz.Height());
     aBrkWindow.SetPosSizePixel( Point( DWBORDER, DWBORDER ), aBrkSz );
 
-    Size aEWSz( Size( aSz.Width() - nBrkWidth - nSBWidth + 2, aSz.Height() ) );
-    aEdtWindow.SetPosSizePixel( Point( DWBORDER+aBrkSz.Width()-1, DWBORDER ), aEWSz );
+    Size aLnSz(aLineNumberWindow.GetWidth(), aSz.Height());
+    aLineNumberWindow.SetPosSizePixel(Point(DWBORDER+aBrkSz.Width() - 1, DWBORDER), aLnSz);
+
+    Size aEWSz(aSz.Width() - nBrkWidth - nSBWidth + 2, aSz.Height());
+    aEdtWindow.SetPosSizePixel( Point( DWBORDER+aBrkSz.Width()+aLnSz.Width()-1, DWBORDER ), aEWSz );
 
     aEWVScrollBar.SetPosSizePixel( Point( aOutSz.Width()-DWBORDER-nSBWidth, DWBORDER ), Size( nSBWidth, aSz.Height() ) );
 }
diff --git a/basctl/source/basicide/linenumberwindow.cxx b/basctl/source/basicide/linenumberwindow.cxx
new file mode 100644
index 0000000..5168da1
--- /dev/null
+++ b/basctl/source/basicide/linenumberwindow.cxx
@@ -0,0 +1,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();
+    }
+  }
+}
diff --git a/basctl/source/basicide/linenumberwindow.hxx b/basctl/source/basicide/linenumberwindow.hxx
new file mode 100644
index 0000000..885ea14
--- /dev/null
+++ b/basctl/source/basicide/linenumberwindow.hxx
@@ -0,0 +1,26 @@
+#ifndef BASICIDE_LINENUMBERWINDOW_HXX
+#define BASICIDE_LINENUMBERWINDOW_HXX
+
+#include <vcl/window.hxx>
+
+class ModulWindow;
+
+class LineNumberWindow : public Window
+{
+private:
+  ModulWindow* pModulWindow;
+  ulong nWidth;
+
+  virtual void DataChanged(DataChangedEvent const & rDCEvt);
+
+protected:
+  virtual void Paint( const Rectangle& );
+
+public:
+  LineNumberWindow( Window* pParent, ModulWindow* pModulWin );
+  ~LineNumberWindow();
+
+  ulong GetWidth() { return (nWidth < 20 ? 20 : nWidth); }
+};
+
+#endif // BASICIDE_LINENUMBERWINDOW_HXX
-- 
1.7.4.4

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to