[Libreoffice-commits] .: Branch 'feature/calc-multiline-input' - sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Tue May 31 13:48:36 PDT 2011


 sc/source/ui/app/inputwin.cxx |  214 +++++++++++++++++-------------------------
 sc/source/ui/inc/inputwin.hxx |    1 
 2 files changed, 90 insertions(+), 125 deletions(-)

New commits:
commit 17114c1d598f4127e99bb771b120dabee2649a3b
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue May 31 16:46:18 2011 -0400

    Always use edit engine to draw text in the input bar.
    
    This simplifies the code significantly.

diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index d6b7bf9..db934bd 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -782,44 +782,12 @@ ScTextWnd::~ScTextWnd()
 
 void ScTextWnd::Paint( const Rectangle& rRec )
 {
-   if (pEditView)
-        {
-          long x =    GetOutputSizePixel().Width();
-          long hHeight=LogicToPixel(Size(0,pEditEngine->GetLineHeight(0,0))).Height();
-          long lCount=pEditEngine->GetLineCount(0);
-
-          pEditEngine->Draw(this, rRec,  Point(TEXT_STARTPOS, (lCount-1)*hHeight), true);
-//        pEditView->Paint(rRec);
-          printf("rectangle drawn height %ld count %ld\n",hHeight,lCount);
-//        pEditEngine->SetPaperSize(PixelToLogic(Size(x,lCount>1?(lCount)*hHeight:hHeight)));
-        }
-    else
-    {
-        SetFont( aTextFont );
-        long a =    GetOutputSizePixel().Height();
-        long b =    GetOutputSizePixel().Width();
-        long c =    LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
-        long d =    LogicToPixel( Size( 0, GetTextHeight() ) ).Width();
-        long nDiff =  GetOutputSizePixel().Height()
-                    - LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
-//		if (nDiff<2) nDiff=2;		// mind. 1 Pixel
-
-        long nStartPos = TEXT_STARTPOS;
-        printf("ScTextWnd::Paint() nDiff: %ld GOSPH %ld GOSPW %ld\n",nDiff,a,b);
-        if ( bIsRTL )
-        {
-            //	right-align
-            nStartPos += GetOutputSizePixel().Width() - 2*TEXT_STARTPOS -
-                        LogicToPixel( Size( GetTextWidth( aString ), 0 ) ).Width();
-
-            //	LayoutMode isn't changed as long as ModifyRTLDefaults doesn't include SvxFrameDirectionItem
-        }
+    // We always use edit engine to draw text at all times.
+    if (!pEditEngine)
+        InitEditEngine(SfxObjectShell::Current());
 
-        printf("ScTextWnd::Paint() text Height  %ld text width %ld \n",c,d);
-
-        DrawText( PixelToLogic( Point( nStartPos, nDiff/2 ) ), aString );
-//        pEditEngine->Draw(this, rRec, Point( nStartPos, nDiff/2 ) ,false);
-    }
+    if (pEditView)
+        pEditView->Paint(rRec);
 }
 
 void ScTextWnd::Resize()
@@ -827,21 +795,11 @@ void ScTextWnd::Resize()
     if (pEditView)
     {
         Size aSize = GetOutputSizePixel();
-        long a =    aSize.Height();
-        long b =    aSize.Width();
-        long c =    LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
-        long d =    LogicToPixel( Size( 0, GetTextHeight() ) ).Width();
-
-        long nDiff =  aSize.Height()
-                    - LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
-
-        aSize.Width() -= 2 * TEXT_STARTPOS - 1;
-
-        printf("ScTextWnd:Resize() nDiff %ld gosph %ld gospw %ld text h %ld text w %ld \n",nDiff,a,b,c,d);
-
+        Point aPos(0, 0);
+        // TODO : When in single line mode, set the height to the height of a
+        // single line, and set the position so that the text look centered.
         pEditView->SetOutputArea(
-            PixelToLogic( Rectangle( Point( TEXT_STARTPOS, (nDiff > 0) ? nDiff/2 : 1 ),
-                                     aSize ) ) );
+            PixelToLogic(Rectangle(aPos, aSize)));
     }
 }
 
@@ -1061,100 +1019,104 @@ void lcl_ModifyRTLVisArea( EditView* pEditView )
     pEditView->SetVisArea(aVisArea);
 }
 
-void ScTextWnd::StartEditEngine()
+void ScTextWnd::InitEditEngine(SfxObjectShell* pObjSh)
 {
-    //	Bei "eigener Modalitaet" (Doc-modale Dialoge) nicht aktivieren
-
-    SfxObjectShell* pObjSh = SfxObjectShell::Current();
-    if ( pObjSh && pObjSh->IsInModalMode() )
-        return;
-
-    if ( !pEditView || !pEditEngine )
+    ScFieldEditEngine* pNew;
+    ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
+    if ( pViewSh )
     {
-        printf("Starting EditEngine\n");
-        ScFieldEditEngine* pNew;
-        ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
-        if ( pViewSh )
-        {
-            const ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
-            pNew = new ScFieldEditEngine( pDoc->GetEnginePool(), pDoc->GetEditPool() );
-        }
-        else
-            pNew = new ScFieldEditEngine( EditEngine::CreatePool(),	NULL, sal_True );
-        pNew->SetExecuteURL( false );
-        pEditEngine = pNew;
+        const ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
+        pNew = new ScFieldEditEngine( pDoc->GetEnginePool(), pDoc->GetEditPool() );
+    }
+    else
+        pNew = new ScFieldEditEngine( EditEngine::CreatePool(),	NULL, sal_True );
+    pNew->SetExecuteURL( false );
+    pEditEngine = pNew;
 
-        Size barSize=GetOutputSizePixel();
+    Size barSize=GetOutputSizePixel();
 
-        long barHeight=barSize.Height();
-        long textHeight=LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
-        long nDiff =  barHeight - textHeight;
+    long barHeight=barSize.Height();
+    long textHeight=LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
+    long nDiff =  barHeight - textHeight;
 
-        barSize.Height()=nDiff+barHeight;
-        barSize.Width() -= 2*TEXT_STARTPOS-4;
-        pEditEngine->SetUpdateMode( false );
-        pEditEngine->SetPaperSize( PixelToLogic(Size(barSize.Width(),10000)) );
-        pEditEngine->SetWordDelimiters(
-                        ScEditUtil::ModifyDelimiters( pEditEngine->GetWordDelimiters() ) );
+    barSize.Height()=nDiff+barHeight;
+    barSize.Width() -= 2*TEXT_STARTPOS-4;
+    pEditEngine->SetUpdateMode( false );
+    pEditEngine->SetPaperSize( PixelToLogic(Size(barSize.Width(),10000)) );
+    pEditEngine->SetWordDelimiters(
+                    ScEditUtil::ModifyDelimiters( pEditEngine->GetWordDelimiters() ) );
 
-        UpdateAutoCorrFlag();
+    UpdateAutoCorrFlag();
 
-        {
-            SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() );
-            pEditEngine->SetFontInfoInItemSet( *pSet, aTextFont );
-            lcl_ExtendEditFontAttribs( *pSet );
-            // turn off script spacing to match DrawText output
-            pSet->Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
-            if ( bIsRTL )
-                lcl_ModifyRTLDefaults( *pSet );
-            pEditEngine->SetDefaults( pSet );
-        }
+    {
+        SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() );
+        pEditEngine->SetFontInfoInItemSet( *pSet, aTextFont );
+        lcl_ExtendEditFontAttribs( *pSet );
+        // turn off script spacing to match DrawText output
+        pSet->Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
+        if ( bIsRTL )
+            lcl_ModifyRTLDefaults( *pSet );
+        pEditEngine->SetDefaults( pSet );
+    }
 
-        //	Wenn in der Zelle URL-Felder enthalten sind, muessen die auch in
-        //	die Eingabezeile uebernommen werden, weil sonst die Positionen nicht stimmen.
+    //	Wenn in der Zelle URL-Felder enthalten sind, muessen die auch in
+    //	die Eingabezeile uebernommen werden, weil sonst die Positionen nicht stimmen.
 
-        sal_Bool bFilled = false;
-        ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
-        if ( pHdl )			//!	Testen, ob's der richtige InputHdl ist?
-            bFilled = pHdl->GetTextAndFields( *pEditEngine );
+    sal_Bool bFilled = false;
+    ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
+    if ( pHdl )			//!	Testen, ob's der richtige InputHdl ist?
+        bFilled = pHdl->GetTextAndFields( *pEditEngine );
 
-        pEditEngine->SetUpdateMode( sal_True );
+    pEditEngine->SetUpdateMode( sal_True );
 
-        //	aString ist die Wahrheit...
-        if ( bFilled && pEditEngine->GetText() == aString )
-            Invalidate();						// Repaint fuer (hinterlegte) Felder
-        else
-            pEditEngine->SetText(aString);		// dann wenigstens den richtigen Text
+    //	aString ist die Wahrheit...
+    if ( bFilled && pEditEngine->GetText() == aString )
+        Invalidate();						// Repaint fuer (hinterlegte) Felder
+    else
+        pEditEngine->SetText(aString);		// dann wenigstens den richtigen Text
 
-        pEditView = new EditView( pEditEngine, this );
-        pEditView->SetInsertMode(bIsInsertMode);
+    pEditView = new EditView( pEditEngine, this );
+    pEditView->SetInsertMode(bIsInsertMode);
 
-        // Text aus Clipboard wird als ASCII einzeilig uebernommen
-        sal_uLong n = pEditView->GetControlWord();
-        pEditView->SetControlWord( n | EV_CNTRL_SINGLELINEPASTE	);
+    // Text aus Clipboard wird als ASCII einzeilig uebernommen
+    sal_uLong n = pEditView->GetControlWord();
+    pEditView->SetControlWord( n | EV_CNTRL_SINGLELINEPASTE	);
 
-        pEditEngine->InsertView( pEditView, EE_APPEND );
+    pEditEngine->InsertView( pEditView, EE_APPEND );
 
-        Resize();
+    Resize();
 
-        if ( bIsRTL )
-            lcl_ModifyRTLVisArea( pEditView );
+    if ( bIsRTL )
+        lcl_ModifyRTLVisArea( pEditView );
 
-        pEditEngine->SetModifyHdl(LINK(this, ScTextWnd, NotifyHdl));
+    pEditEngine->SetModifyHdl(LINK(this, ScTextWnd, NotifyHdl));
 
-        if (!maAccTextDatas.empty())
-            maAccTextDatas.back()->StartEdit();
+    if (!maAccTextDatas.empty())
+        maAccTextDatas.back()->StartEdit();
 
-        //	as long as EditEngine and DrawText sometimes differ for CTL text,
-        //	repaint now to have the EditEngine's version visible
+    //	as long as EditEngine and DrawText sometimes differ for CTL text,
+    //	repaint now to have the EditEngine's version visible
 //        SfxObjectShell* pObjSh = SfxObjectShell::Current();
-        if ( pObjSh && pObjSh->ISA(ScDocShell) )
-        {
-            ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument();	// any document
-            sal_uInt8 nScript = pDoc->GetStringScriptType( aString );
-            if ( nScript & SCRIPTTYPE_COMPLEX )
-                Invalidate();
-        }
+    if ( pObjSh && pObjSh->ISA(ScDocShell) )
+    {
+        ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument();	// any document
+        sal_uInt8 nScript = pDoc->GetStringScriptType( aString );
+        if ( nScript & SCRIPTTYPE_COMPLEX )
+            Invalidate();
+    }
+}
+
+void ScTextWnd::StartEditEngine()
+{
+    //	Bei "eigener Modalitaet" (Doc-modale Dialoge) nicht aktivieren
+
+    SfxObjectShell* pObjSh = SfxObjectShell::Current();
+    if ( pObjSh && pObjSh->IsInModalMode() )
+        return;
+
+    if ( !pEditView || !pEditEngine )
+    {
+        InitEditEngine(pObjSh);
     }
 
     SC_MOD()->SetInputMode( SC_INPUT_TOP );
@@ -1183,6 +1145,7 @@ IMPL_LINK(ScTextWnd, NotifyHdl, EENotify*, EMPTYARG)
 void ScTextWnd::StopEditEngine( sal_Bool bAll )
 {
     printf("stopping editEngine\n");
+#if 0 // Make this a no-op for now.
     if (pEditView)
     {
         if (!maAccTextDatas.empty())
@@ -1209,6 +1172,7 @@ void ScTextWnd::StopEditEngine( sal_Bool bAll )
         if (bSelection)
             Invalidate();			// damit Selektion nicht stehenbleibt
     }
+#endif
 }
 
 void ScTextWnd::SetTextString( const String& rNewString )
diff --git a/sc/source/ui/inc/inputwin.hxx b/sc/source/ui/inc/inputwin.hxx
index ef1db4f..d629376 100644
--- a/sc/source/ui/inc/inputwin.hxx
+++ b/sc/source/ui/inc/inputwin.hxx
@@ -63,6 +63,7 @@ public:
                         // fuer FunktionsAutopiloten
     void			MakeDialogEditView();
 
+    void            InitEditEngine(SfxObjectShell* pObjSh);
     void			StartEditEngine();
     void			StopEditEngine( sal_Bool bAll );
 


More information about the Libreoffice-commits mailing list