summaryrefslogtreecommitdiffstats
path: root/basctl/source/basicide/linenumberwindow.cxx
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2011-11-17 21:49:06 -0600
committerNorbert Thiebaud <nthiebaud@gmail.com>2011-11-17 21:49:06 -0600
commit6e6546a5f7fb30ab35dc52e148a20b9d6d3d70b8 (patch)
tree8c4cf35b5be3efb755c890a6aefff20fe731e4bd /basctl/source/basicide/linenumberwindow.cxx
parentSetLineNumberDisplay appropriately when opening or swithin modules (diff)
downloadcore-6e6546a5f7fb30ab35dc52e148a20b9d6d3d70b8.tar.gz
core-6e6546a5f7fb30ab35dc52e148a20b9d6d3d70b8.zip
calculate the width based on the font + general clean-up
Diffstat (limited to 'basctl/source/basicide/linenumberwindow.cxx')
-rw-r--r--basctl/source/basicide/linenumberwindow.cxx106
1 files changed, 59 insertions, 47 deletions
diff --git a/basctl/source/basicide/linenumberwindow.cxx b/basctl/source/basicide/linenumberwindow.cxx
index fb7bed6118f3..f8f566da1ad4 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;
}