[Libreoffice-commits] .: 2 commits - basctl/source
Norbert Thiebaud
nthiebaud at kemper.freedesktop.org
Thu Nov 17 19:49:25 PST 2011
basctl/source/basicide/basides1.cxx | 1
basctl/source/basicide/basidesh.cxx | 9 ++
basctl/source/basicide/linenumberwindow.cxx | 106 +++++++++++++++-------------
basctl/source/basicide/linenumberwindow.hxx | 25 +++---
4 files changed, 82 insertions(+), 59 deletions(-)
New commits:
commit 6e6546a5f7fb30ab35dc52e148a20b9d6d3d70b8
Author: Norbert Thiebaud <nthiebaud at gmail.com>
Date: Thu Nov 17 21:49:06 2011 -0600
calculate the width based on the font + general clean-up
diff --git a/basctl/source/basicide/linenumberwindow.cxx b/basctl/source/basicide/linenumberwindow.cxx
index fb7bed6..f8f566d 100644
--- a/basctl/source/basicide/linenumberwindow.cxx
+++ b/basctl/source/basicide/linenumberwindow.cxx
@@ -5,90 +5,102 @@
#include <svtools/textview.hxx>
LineNumberWindow::LineNumberWindow( Window* pParent, ModulWindow* pModulWin ) :
- Window( pParent, WB_BORDER ),
- pModulWindow(pModulWin),
- nWidth(1),
- nCurYOffset(0)
+ Window( pParent, WB_BORDER ),
+ m_pModulWindow(pModulWin),
+ m_nCurYOffset(0)
{
- SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
+ SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
+ m_nBaseWidth = GetTextWidth(String('8'));
+ m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;;
}
LineNumberWindow::~LineNumberWindow() { }
void LineNumberWindow::Paint( const Rectangle& )
{
- if(SyncYOffset())
- return;
+ if(SyncYOffset())
+ return;
- ExtTextEngine* txtEngine = pModulWindow->GetEditEngine();
- if(!txtEngine)
- return;
+ ExtTextEngine* txtEngine = m_pModulWindow->GetEditEngine();
+ if(!txtEngine)
+ return;
- TextView* txtView = pModulWindow->GetEditView();
- if(!txtView)
- return;
+ TextView* txtView = m_pModulWindow->GetEditView();
+ if(!txtView)
+ return;
- GetParent()->Resize();
+ GetParent()->Resize();
- int windowHeight = GetOutputSize().Height();
- int nLineHeight = GetTextHeight();
+ int windowHeight = GetOutputSize().Height();
+ int nLineHeight = GetTextHeight();
- int startY = txtView->GetStartDocPos().Y();
- int nStartLine = startY / nLineHeight + 1;
- int nEndLine = (startY + windowHeight) / nLineHeight + 1;
+ 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;
+ if(txtEngine->GetParagraphCount() + 1 < (unsigned int)nEndLine)
+ nEndLine = txtEngine->GetParagraphCount() + 1;
- nWidth = String::CreateFromInt64(nEndLine).Len() * 10;
+ // FIXME: it would be best if we could get notified of a font change
+ // rather than doing that re-calculation at each Paint event
+ m_nBaseWidth = GetTextWidth(String('8'));
- sal_Int64 y = (nStartLine - 1) * nLineHeight;
- for(int i = nStartLine; i <= nEndLine; ++i, y += nLineHeight)
- DrawText(Point(0, y - nCurYOffset), String::CreateFromInt64(i));
+ // reserve enough for 3 sigit minimum, with a bit to spare for confort
+ m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
+ int i = (nEndLine + 1) / 1000;
+ while(i)
+ {
+ i /= 10;
+ m_nWidth += m_nBaseWidth;
+ }
+
+ sal_Int64 y = (nStartLine - 1) * nLineHeight;
+ for(int i = nStartLine; i <= nEndLine; ++i, y += nLineHeight)
+ DrawText(Point(0, y - m_nCurYOffset), String::CreateFromInt32(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())
+ Window::DataChanged(rDCEvt);
+ if (rDCEvt.GetType() == DATACHANGED_SETTINGS
+ && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
{
- SetBackground(Wallpaper(aColor));
- Invalidate();
+ 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);
+ m_nCurYOffset -= nVertScroll;
+ Window::Scroll(nHorzScroll, nVertScroll);
}
long& LineNumberWindow::GetCurYOffset()
{
- return nCurYOffset;
+ return m_nCurYOffset;
}
bool LineNumberWindow::SyncYOffset()
{
- TextView* pView = pModulWindow->GetEditView();
- if (!pView)
- return false;
+ TextView* pView = m_pModulWindow->GetEditView();
+ if (!pView)
+ return false;
- long nViewYOffset = pView->GetStartDocPos().Y();
- if (nCurYOffset == nViewYOffset)
- return false;
+ long nViewYOffset = pView->GetStartDocPos().Y();
+ if (m_nCurYOffset == nViewYOffset)
+ return false;
- nCurYOffset = nViewYOffset;
- Invalidate();
- return true;
+ m_nCurYOffset = nViewYOffset;
+ Invalidate();
+ return true;
}
int LineNumberWindow::GetWidth()
{
- return (nWidth < 20 ? 20 : nWidth);
+ return m_nWidth;
}
diff --git a/basctl/source/basicide/linenumberwindow.hxx b/basctl/source/basicide/linenumberwindow.hxx
index b94fae9..74b16b8 100644
--- a/basctl/source/basicide/linenumberwindow.hxx
+++ b/basctl/source/basicide/linenumberwindow.hxx
@@ -8,25 +8,26 @@ class ModulWindow;
class LineNumberWindow : public Window
{
private:
- ModulWindow* pModulWindow;
- int nWidth;
- long nCurYOffset;
-
- virtual void DataChanged(DataChangedEvent const & rDCEvt);
+ ModulWindow* m_pModulWindow;
+ int m_nWidth;
+ long m_nCurYOffset;
+ int m_nCharWidth;
+ int m_nBaseWidth;
+ virtual void DataChanged(DataChangedEvent const & rDCEvt);
protected:
- virtual void Paint( const Rectangle& );
+ virtual void Paint( const Rectangle& );
public:
- LineNumberWindow( Window* pParent, ModulWindow* pModulWin );
- ~LineNumberWindow();
+ LineNumberWindow( Window* pParent, ModulWindow* pModulWin );
+ ~LineNumberWindow();
- void DoScroll( long nHorzScroll, long nVertScroll );
+ void DoScroll( long nHorzScroll, long nVertScroll );
- bool SyncYOffset();
- long& GetCurYOffset();
+ bool SyncYOffset();
+ long& GetCurYOffset();
- int GetWidth();
+ int GetWidth();
};
#endif // BASICIDE_LINENUMBERWINDOW_HXX
commit a1d800a7a7072c7003aa4f238a48074d3c281d0a
Author: Norbert Thiebaud <nthiebaud at gmail.com>
Date: Thu Nov 17 21:48:30 2011 -0600
SetLineNumberDisplay appropriately when opening or swithin modules
diff --git a/basctl/source/basicide/basides1.cxx b/basctl/source/basicide/basides1.cxx
index 68eaaa4..8a00b83 100644
--- a/basctl/source/basicide/basides1.cxx
+++ b/basctl/source/basicide/basides1.cxx
@@ -1143,6 +1143,7 @@ void BasicIDEShell::SetCurWindow( IDEBaseWindow* pNewWin, sal_Bool bUpdateTabBar
AdjustPosSizePixel( Point( 0, 0 ), GetViewFrame()->GetWindow().GetOutputSizePixel() );
if( pCurWin->IsA( TYPE( ModulWindow ) ) )
{
+ dynamic_cast<ModulWindow*>(pCurWin)->SetLineNumberDisplay(SourceLinesDisplayed());
GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
pModulLayout->SetModulWindow( (ModulWindow*)pCurWin );
pModulLayout->Show();
diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx
index 9e7379f..c1967f9 100644
--- a/basctl/source/basicide/basidesh.cxx
+++ b/basctl/source/basicide/basidesh.cxx
@@ -54,6 +54,7 @@
#include <tools/diagnose_ex.h>
#include <basidesh.hrc>
#include <basidesh.hxx>
+#include <baside2.hxx>
#include <basdoc.hxx>
#include <basobj.hxx>
#include <bastypes.hxx>
@@ -288,11 +289,19 @@ BasicIDEShell::~BasicIDEShell()
void BasicIDEShell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
{
+ if(pCurWin && pCurWin->IsA( TYPE(ModulWindow)))
+ {
+ dynamic_cast<ModulWindow*>(pCurWin)->SetLineNumberDisplay(SourceLinesDisplayed());
+ }
UpdateWindows();
}
void BasicIDEShell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
{
+ if(pCurWin && pCurWin->IsA( TYPE(ModulWindow)))
+ {
+ dynamic_cast<ModulWindow*>(pCurWin)->SetLineNumberDisplay(SourceLinesDisplayed());
+ }
UpdateWindows();
}
More information about the Libreoffice-commits
mailing list