summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basctl/source/basicide/linenumberwindow.cxx106
-rw-r--r--basctl/source/basicide/linenumberwindow.hxx25
2 files changed, 72 insertions, 59 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;
}
diff --git a/basctl/source/basicide/linenumberwindow.hxx b/basctl/source/basicide/linenumberwindow.hxx
index b94fae9e2a78..74b16b835382 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