[Libreoffice-commits] core.git: include/vcl vcl/source

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Wed May 22 21:01:41 UTC 2019


 include/vcl/texteng.hxx      |    3 +
 include/vcl/vclmedit.hxx     |    5 ++
 vcl/source/edit/texteng.cxx  |    7 ++--
 vcl/source/edit/vclmedit.cxx |   74 ++++++++++++-------------------------------
 4 files changed, 31 insertions(+), 58 deletions(-)

New commits:
commit cc223fa12a61ba0e580b884386a7f5d7efd0541f
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Thu May 16 01:25:19 2019 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Wed May 22 23:00:45 2019 +0200

    VCL keep / return the original set TextEngine font
    
    TextEngine::SetFont copies the font parameter and then modifies
    its color, transparency, fill color and alignment, so passing the
    same font again will not be detected as the same font.
    
    Therefore this patch stores the original font in addition to the
    modified one and also returns that one on the GetFont call.
    
    This allows us to merge the font setup in VclMultiLineEdit's
    ImplInitSettings and ApplySettings into a common function.
    
    Change-Id: I618d283ecd0ae14faf9b87a3aceec6ca1c37b526
    Reviewed-on: https://gerrit.libreoffice.org/72788
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/include/vcl/texteng.hxx b/include/vcl/texteng.hxx
index 7e6c9d452590..95da903bc1d4 100644
--- a/include/vcl/texteng.hxx
+++ b/include/vcl/texteng.hxx
@@ -106,6 +106,7 @@ class VCL_DLLPUBLIC TextEngine : public SfxBroadcaster
     std::unique_ptr<LocaleDataWrapper> mpLocaleDataWrapper;
 
     vcl::Font           maFont;
+    vcl::Font           maOrigFont;  // original font from SetFont
     Color               maTextColor;
 
     sal_Int32           mnMaxTextLen;
@@ -220,7 +221,7 @@ public:
     sal_Int32           GetTextLen( const TextSelection& rSel ) const;
 
     void                SetFont( const vcl::Font& rFont );
-    const vcl::Font&    GetFont() const { return maFont; }
+    const vcl::Font&    GetFont() const { return maOrigFont; }
 
     void                SetLeftMargin( sal_uInt16 n );
 
diff --git a/include/vcl/vclmedit.hxx b/include/vcl/vclmedit.hxx
index d52d040d028e..23381f5f8443 100644
--- a/include/vcl/vclmedit.hxx
+++ b/include/vcl/vclmedit.hxx
@@ -98,7 +98,10 @@ protected:
     TextView*       GetTextView() const;
     ExtTextEngine*  GetTextEngine() const;
 
-    virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
+    void ApplySettings(vcl::RenderContext&) override;
+    void ApplyBackgroundSettings(vcl::RenderContext&, const StyleSettings&);
+    void ApplyFontSettings(vcl::RenderContext&, const StyleSettings&);
+
 public:
                     VclMultiLineEdit( vcl::Window* pParent,
                                       WinBits nWinStyle );
diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx
index 097305df51c7..b6835dbc07a2 100644
--- a/vcl/source/edit/texteng.cxx
+++ b/vcl/source/edit/texteng.cxx
@@ -170,8 +170,9 @@ void TextEngine::SetActiveView( TextView* pTextView )
 
 void TextEngine::SetFont( const vcl::Font& rFont )
 {
-    if ( rFont == maFont )
+    if (rFont == maOrigFont)
         return;
+    maOrigFont = rFont;
 
     maFont = rFont;
     // #i40221# As the font's color now defaults to transparent (since i35764)
@@ -206,9 +207,9 @@ void TextEngine::SetFont( const vcl::Font& rFont )
     for ( auto nView = mpViews->size(); nView; )
     {
         TextView* pView = (*mpViews)[ --nView ];
-        pView->GetWindow()->SetInputContext( InputContext( GetFont(), !pView->IsReadOnly() ? InputContextFlags::Text|InputContextFlags::ExtText : InputContextFlags::NONE ) );
+        pView->GetWindow()->SetInputContext(InputContext(maFont, !pView->IsReadOnly()
+            ? InputContextFlags::Text|InputContextFlags::ExtText : InputContextFlags::NONE));
     }
-
 }
 
 void TextEngine::SetMaxTextLen( sal_Int32 nLen )
diff --git a/vcl/source/edit/vclmedit.cxx b/vcl/source/edit/vclmedit.cxx
index 9a6d6d018ea9..1419602fa34b 100644
--- a/vcl/source/edit/vclmedit.cxx
+++ b/vcl/source/edit/vclmedit.cxx
@@ -913,36 +913,8 @@ WinBits VclMultiLineEdit::ImplInitStyle( WinBits nStyle )
     return nStyle;
 }
 
-void VclMultiLineEdit::ApplySettings(vcl::RenderContext& rRenderContext)
+void VclMultiLineEdit::ApplyBackgroundSettings(vcl::RenderContext& rRenderContext, const StyleSettings& rStyleSettings)
 {
-    const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
-
-    // The Font has to be adjusted, as the TextEngine does not take care of
-    // TextColor/Background
-
-    Color aTextColor = rStyleSettings.GetFieldTextColor();
-    if (IsControlForeground())
-        aTextColor = GetControlForeground();
-
-    if (!IsEnabled())
-        aTextColor = rStyleSettings.GetDisableColor();
-
-    vcl::Font aFont = rStyleSettings.GetFieldFont();
-    aFont.SetTransparent(IsPaintTransparent());
-    ApplyControlFont(rRenderContext, aFont);
-
-    vcl::Font theFont = rRenderContext.GetFont();
-    theFont.SetColor(aTextColor);
-    if (IsPaintTransparent())
-        theFont.SetFillColor(COL_TRANSPARENT);
-    else
-        theFont.SetFillColor(IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor());
-
-    pImpVclMEdit->GetTextWindow()->SetFont(theFont);
-    // FIXME: next call causes infinite invalidation loop, rethink how to properly fix this situation
-    // pImpVclMEdit->GetTextWindow()->GetTextEngine()->SetFont(theFont);
-    pImpVclMEdit->GetTextWindow()->SetTextColor(aTextColor);
-
     if (IsPaintTransparent())
     {
         pImpVclMEdit->GetTextWindow()->SetPaintTransparent(true);
@@ -962,10 +934,8 @@ void VclMultiLineEdit::ApplySettings(vcl::RenderContext& rRenderContext)
     }
 }
 
-void VclMultiLineEdit::ImplInitSettings(bool bBackground)
+void VclMultiLineEdit::ApplyFontSettings(vcl::RenderContext& rRenderContext, const StyleSettings& rStyleSettings)
 {
-    const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
-
     // The Font has to be adjusted, as the TextEngine does not take care of
     // TextColor/Background
 
@@ -977,38 +947,36 @@ void VclMultiLineEdit::ImplInitSettings(bool bBackground)
 
     vcl::Font aFont = rStyleSettings.GetFieldFont();
     aFont.SetTransparent(IsPaintTransparent());
-    ApplyControlFont(*this, aFont);
+    ApplyControlFont(rRenderContext, aFont);
 
-    vcl::Font TheFont = GetFont();
+    vcl::Font TheFont = rRenderContext.GetFont();
     TheFont.SetColor(aTextColor);
     if (IsPaintTransparent())
         TheFont.SetFillColor(COL_TRANSPARENT);
     else
         TheFont.SetFillColor(IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor());
+
     pImpVclMEdit->GetTextWindow()->SetFont(TheFont);
     pImpVclMEdit->GetTextWindow()->GetTextEngine()->SetFont(TheFont);
     pImpVclMEdit->GetTextWindow()->SetTextColor(aTextColor);
+}
+
+void VclMultiLineEdit::ApplySettings(vcl::RenderContext& rRenderContext)
+{
+    const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
+
+    ApplyFontSettings(rRenderContext, rStyleSettings);
+    ApplyBackgroundSettings(rRenderContext, rStyleSettings);
+}
+
+void VclMultiLineEdit::ImplInitSettings(bool bBackground)
+{
+    const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+
+    ApplyFontSettings(*this, rStyleSettings);
 
     if (bBackground)
-    {
-        if (IsPaintTransparent())
-        {
-            pImpVclMEdit->GetTextWindow()->SetPaintTransparent(true);
-            pImpVclMEdit->GetTextWindow()->SetBackground();
-            pImpVclMEdit->GetTextWindow()->SetControlBackground();
-            SetBackground();
-            SetControlBackground();
-        }
-        else
-        {
-            if (IsControlBackground())
-                pImpVclMEdit->GetTextWindow()->SetBackground(GetControlBackground());
-            else
-                pImpVclMEdit->GetTextWindow()->SetBackground(rStyleSettings.GetFieldColor());
-            // also adjust for VclMultiLineEdit as the TextComponent might hide Scrollbars
-            SetBackground(pImpVclMEdit->GetTextWindow()->GetBackground());
-        }
-    }
+        ApplyBackgroundSettings(*this, rStyleSettings);
 }
 
 void VclMultiLineEdit::Modify()


More information about the Libreoffice-commits mailing list