[Libreoffice-commits] .: starmath/inc starmath/source

Jonas Finnemann Jensen jopsen at kemper.freedesktop.org
Wed Nov 17 13:29:48 PST 2010


 starmath/inc/cursor.hxx      |    2 +-
 starmath/inc/view.hxx        |    6 ++++--
 starmath/inc/visitors.hxx    |    3 ++-
 starmath/source/cursor.cxx   |    4 ++--
 starmath/source/view.cxx     |   14 ++++++++++++--
 starmath/source/visitors.cxx |   38 +++++++++++++++++++++++++++++---------
 6 files changed, 50 insertions(+), 17 deletions(-)

New commits:
commit ddff6d62aa75f60da08dca5582101b991367f988
Author: Luke Dixon <6b8b4567 at gmail.com>
Date:   Tue Nov 16 23:37:09 2010 +0000

    Draw a visible line under the current line in the visual formula editor.

diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx
index 7c4fa85..139d5c4 100644
--- a/starmath/inc/cursor.hxx
+++ b/starmath/inc/cursor.hxx
@@ -226,7 +226,7 @@ public:
     static SmNode* FindTopMostNodeInLine(SmNode* pSNode, bool MoveUpIfSelected = false);
 
     /** Draw the caret */
-    void Draw(OutputDevice& pDev, Point Offset);
+    void Draw(OutputDevice& pDev, Point Offset, bool isCaretVisible);
 
 private:
     friend class SmDocShell;
diff --git a/starmath/inc/view.hxx b/starmath/inc/view.hxx
index cbaf501..e5899ce 100644
--- a/starmath/inc/view.hxx
+++ b/starmath/inc/view.hxx
@@ -57,11 +57,13 @@ class SmGraphicWindow : public ScrollableWindow
     // old style editing pieces
     Rectangle aCursorRect;
     bool      bIsCursorVisible;
-
-    AutoTimer     aCaretBlinkTimer;
+    bool      bIsLineVisible;
+    AutoTimer aCaretBlinkTimer;
 public:
     bool IsCursorVisible() const { return bIsCursorVisible; }
     void ShowCursor(bool bShow);
+    bool IsLineVisible() const { return bIsLineVisible; }
+    void ShowLine(bool bShow);
     const SmNode * SetCursorPos(USHORT nRow, USHORT nCol);
 protected:
     void		SetIsCursorVisible(bool bVis) { bIsCursorVisible = bVis; }
diff --git a/starmath/inc/visitors.hxx b/starmath/inc/visitors.hxx
index 2b89b6f..cff09dc 100644
--- a/starmath/inc/visitors.hxx
+++ b/starmath/inc/visitors.hxx
@@ -152,13 +152,14 @@ class SmCaretDrawingVisitor : public SmDefaultingVisitor
 {
 public:
     /** Given position and device this constructor will draw the caret */
-    SmCaretDrawingVisitor( OutputDevice& rDevice, SmCaretPos position, Point offset );
+    SmCaretDrawingVisitor( OutputDevice& rDevice, SmCaretPos position, Point offset, bool caretVisible );
     void Visit( SmTextNode* pNode );
 private:
     OutputDevice &rDev;
     SmCaretPos pos;
     /** Offset to draw from */
     Point Offset;
+    bool isCaretVisible;
 protected:
     /** Default method for drawing pNodes */
     void DefaultVisit( SmNode* pNode );
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index 948a02b..1219595 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -180,8 +180,8 @@ void SmCursor::AnnotateSelection(){
     SmSetSelectionVisitor(anchor->CaretPos, position->CaretPos, pTree);
 }
 
-void SmCursor::Draw(OutputDevice& pDev, Point Offset){
-    SmCaretDrawingVisitor(pDev, GetPosition(), Offset);
+void SmCursor::Draw(OutputDevice& pDev, Point Offset, bool isCaretVisible){
+    SmCaretDrawingVisitor(pDev, GetPosition(), Offset, isCaretVisible);
 }
 
 void SmCursor::Delete(){
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 6d2752d..75871e6 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -116,6 +116,7 @@ SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell):
     SetHelpId(HID_SMA_WIN_DOCUMENT);
     SetUniqueId(HID_SMA_WIN_DOCUMENT);
 
+    ShowLine(false);
     CaretBlinkInit();
 }
 
@@ -224,6 +225,7 @@ void SmGraphicWindow::GetFocus()
     //Let view shell know what insertions should be done in visual editor
     pViewShell->SetInsertIntoEditWindow(false);
     SetIsCursorVisible(true);
+    ShowLine(true);
     CaretBlinkStart();
     RepaintViewShellDoc();
 }
@@ -242,6 +244,7 @@ void SmGraphicWindow::LoseFocus()
     if (!IsInlineEditEnabled())
         return;
     SetIsCursorVisible(false);
+    ShowLine(false);
     CaretBlinkStop();
     RepaintViewShellDoc();
 }
@@ -299,6 +302,13 @@ void SmGraphicWindow::ShowCursor(bool bShow)
     SetIsCursorVisible(bShow);
 }
 
+void SmGraphicWindow::ShowLine(bool bShow)
+{
+    if (!IsInlineEditEnabled())
+        return;
+
+    bIsLineVisible = bShow;
+}
 
 void SmGraphicWindow::SetCursor(const SmNode *pNode)
 {
@@ -371,8 +381,8 @@ void SmGraphicWindow::Paint(const Rectangle&)
     SetFormulaDrawPos(aPoint);
     if(IsInlineEditEnabled()) {
         //Draw cursor if any...
-        if(pViewShell->GetDoc()->HasCursor() && IsCursorVisible())
-            pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint);
+        if(pViewShell->GetDoc()->HasCursor() && IsLineVisible())
+            pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint, IsCursorVisible());
     } else {
     SetIsCursorVisible(false);	// (old) cursor must be drawn again
 
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 8f69b2e..6ca86fd 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -339,11 +339,13 @@ void SmDefaultingVisitor::Visit( SmVerticalBraceNode* pNode )
 
 SmCaretDrawingVisitor::SmCaretDrawingVisitor( OutputDevice& rDevice,
                                              SmCaretPos position,
-                                             Point offset )
+                                             Point offset,
+                                             bool caretVisible )
  : rDev( rDevice )
 {
     pos = position;
     Offset = offset;
+    isCaretVisible = caretVisible;
     j_assert( position.IsValid( ), "Cannot draw invalid position!" );
     if( !position.IsValid( ) )
         return;
@@ -369,14 +371,23 @@ void SmCaretDrawingVisitor::Visit( SmTextNode* pNode )
     long left = pNode->GetLeft( ) + rDev.GetTextWidth( pNode->GetText( ), 0, i ) + Offset.X( );
     long top = pLine->GetTop( ) + Offset.Y( );
     long height = pLine->GetHeight( );
+    long left_line = pLine->GetLeft( ) + Offset.X( );
+    long right_line = pLine->GetRight( ) + Offset.X( );
 
     //Set color
     rDev.SetLineColor( Color( COL_BLACK ) );
 
-    //Draw vertical line
-    Point p1( left, top );
-    Point p2( left, top + height );
-    rDev.DrawLine( p1, p2 );
+    if ( isCaretVisible ) {
+        //Draw vertical line
+        Point p1( left, top );
+        Point p2( left, top + height );
+        rDev.DrawLine( p1, p2 );
+    }
+
+    //Underline the line
+    Point pLeft( left_line, top + height );
+    Point pRight( right_line, top + height );
+    rDev.DrawLine( pLeft, pRight );
 }
 
 void SmCaretDrawingVisitor::DefaultVisit( SmNode* pNode )
@@ -390,14 +401,23 @@ void SmCaretDrawingVisitor::DefaultVisit( SmNode* pNode )
     long left = pNode->GetLeft( ) + Offset.X( ) + ( pos.Index == 1 ? pNode->GetWidth( ) : 0 );
     long top = pLine->GetTop( ) + Offset.Y( );
     long height = pLine->GetHeight( );
+    long left_line = pLine->GetLeft( ) + Offset.X( );
+    long right_line = pLine->GetRight( ) + Offset.X( );
 
     //Set color
     rDev.SetLineColor( Color( COL_BLACK ) );
 
-    //Draw vertical line
-    Point p1( left, top );
-    Point p2( left, top + height );
-    rDev.DrawLine( p1, p2 );
+    if ( isCaretVisible ) {
+        //Draw vertical line
+        Point p1( left, top );
+        Point p2( left, top + height );
+        rDev.DrawLine( p1, p2 );
+    }
+
+    //Underline the line
+    Point pLeft( left_line, top + height );
+    Point pRight( right_line, top + height );
+    rDev.DrawLine( pLeft, pRight );
 }
 
 /////////////////////////////// SmCaretPos2LineVisitor ////////////////////////////////


More information about the Libreoffice-commits mailing list