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

Caolán McNamara caolanm at redhat.com
Mon May 11 11:46:00 PDT 2015


 include/vcl/salnativewidgets.hxx              |   11 +++-
 vcl/source/control/tabctrl.cxx                |   19 +++++---
 vcl/source/outdev/nativecontrols.cxx          |    1 
 vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx |   59 ++++++++++++++++++++++----
 4 files changed, 70 insertions(+), 20 deletions(-)

New commits:
commit 686034d5ced19ea2a16127ba3f5af49e7f9e1b35
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon May 11 17:33:44 2015 +0100

    gtk3: insert a gap between tabs
    
    Change-Id: I7d502571719e58d1436b6651eb9f01e4ef46aa6a

diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
index 17ef6e2..906d3b2 100644
--- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
@@ -75,6 +75,7 @@ enum {
     RENDER_SCROLLBAR = 8,
     RENDER_SPINBUTTON = 9,
     RENDER_COMBOBOX = 10,
+    RENDER_EXTENSION = 11,
 };
 
 static void PrepareComboboxStyle( GtkStyleContext *context,
@@ -940,6 +941,7 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
         context = mpNoteBookStyle;
         if (nState & ControlState::SELECTED)
             flags = (GtkStateFlags) (flags | GTK_STATE_FLAG_ACTIVE);
+
         break;
     case CTRL_WINDOW_BACKGROUND:
         context = gtk_widget_get_style_context(mpWindow);
@@ -952,6 +954,11 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
     clipRegion(cr);
     cairo_translate(cr, rControlRegion.Left(), rControlRegion.Top());
 
+    long nX = 0;
+    long nY = 0;
+    long nWidth = rControlRegion.GetWidth();
+    long nHeight = rControlRegion.GetHeight();
+
     gtk_style_context_save(context);
     gtk_style_context_set_state(context, flags);
     if (nType == CTRL_TAB_ITEM)
@@ -969,6 +976,14 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
 
         gtk_style_context_add_region(mpNoteBookStyle, GTK_STYLE_REGION_TAB, eFlags);
         gtk_style_context_add_class(context, GTK_STYLE_CLASS_TOP);
+
+        gint initial_gap(0);
+        gtk_style_context_get_style(mpNoteBookStyle,
+                                "initial-gap", &initial_gap,
+                                NULL);
+
+        nX += initial_gap/2;
+        nWidth -= initial_gap;
     }
     if (styleClass)
     {
@@ -983,16 +998,15 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
     {
     case RENDER_BACKGROUND:
     case RENDER_BACKGROUND_AND_FRAME:
-        gtk_render_background(context, cr,
-                              0, 0,
-                              rControlRegion.GetWidth(), rControlRegion.GetHeight());
+        gtk_render_background(context, cr, nX, nY, nWidth, nHeight);
         if (renderType == RENDER_BACKGROUND_AND_FRAME)
         {
-            gtk_render_frame(context, cr,
-                             0, 0,
-                             rControlRegion.GetWidth(), rControlRegion.GetHeight());
+            gtk_render_frame(context, cr, nX, nY, nWidth, nHeight);
         }
         break;
+    case RENDER_EXTENSION:
+        gtk_render_extension(context, cr, nX, nY, nWidth, nHeight, GTK_POS_BOTTOM);
+        break;
     case RENDER_CHECK:
     case RENDER_RADIO:
         PaintCheckOrRadio(context, cr, rControlRegion, nType);
commit 0f8f60f2bef959389d45b2dd0a535cd8848ed8e9
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon May 11 16:43:25 2015 +0100

    gtk3: get the native tab item padding and borders size
    
    Change-Id: Id4dd1d7540cca83edbfa17f7ae70bfd61dcdefe3

diff --git a/include/vcl/salnativewidgets.hxx b/include/vcl/salnativewidgets.hxx
index 7ec4391..c8370aa 100644
--- a/include/vcl/salnativewidgets.hxx
+++ b/include/vcl/salnativewidgets.hxx
@@ -367,12 +367,14 @@ class VCL_DLLPUBLIC TabitemValue : public ImplControlValue
 {
     public:
         unsigned int    mnAlignment;
+        Rectangle       maContentRect;
 
-        inline TabitemValue()
-        : ImplControlValue( CTRL_TAB_ITEM, BUTTONVALUE_DONTKNOW, 0 )
+        TabitemValue(const Rectangle &rContentRect)
+            : ImplControlValue( CTRL_TAB_ITEM, BUTTONVALUE_DONTKNOW, 0 )
+            , mnAlignment(0)
+            , maContentRect(rContentRect)
         {
-            mnAlignment = 0;
-        };
+        }
         virtual ~TabitemValue();
         virtual TabitemValue* clone() const SAL_OVERRIDE;
 
@@ -382,6 +384,7 @@ class VCL_DLLPUBLIC TabitemValue : public ImplControlValue
         bool isNotAligned() const   { return (mnAlignment & (TABITEM_LEFTALIGNED | TABITEM_RIGHTALIGNED)) == 0; }
         bool isFirst() const        { return (mnAlignment & TABITEM_FIRST_IN_GROUP) != 0; }
         bool isLast() const         { return (mnAlignment & TABITEM_LAST_IN_GROUP) != 0; }
+        const Rectangle& getContentRect() const { return maContentRect; }
 };
 
 /* SpinbuttonValue:
diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx
index 66ac721..7a0e2a6 100644
--- a/vcl/source/control/tabctrl.cxx
+++ b/vcl/source/control/tabctrl.cxx
@@ -243,7 +243,9 @@ Size TabControl::ImplGetItemSize( ImplTabItem* pItem, long nMaxWidth )
 
     Rectangle aCtrlRegion( Point( 0, 0 ), aSize );
     Rectangle aBoundingRgn, aContentRgn;
-    const EditBoxValue aControlValue(GetTextHeight());
+    const TabitemValue aControlValue(Rectangle(TAB_TABOFFSET_X, TAB_TABOFFSET_Y,
+                                               aSize.Width() - TAB_TABOFFSET_X * 2,
+                                               aSize.Height() - TAB_TABOFFSET_Y * 2));
     if(GetNativeControlRegion( CTRL_TAB_ITEM, PART_ENTIRE_CONTROL, aCtrlRegion,
                                            ControlState::ENABLED, aControlValue, OUString(),
                                            aBoundingRgn, aContentRgn ) )
@@ -853,17 +855,20 @@ void TabControl::ImplDrawItem(vcl::RenderContext& /*rRenderContext*/, ImplTabIte
 
     if( !bLayout && (bNativeOK = IsNativeControlSupported(CTRL_TAB_ITEM, PART_ENTIRE_CONTROL)) )
     {
-        TabitemValue tiValue;
-        if(pItem->maRect.Left() < 5)
+        TabitemValue tiValue(Rectangle(pItem->maRect.Left() + TAB_TABOFFSET_X,
+                                       pItem->maRect.Right() - TAB_TABOFFSET_X,
+                                       pItem->maRect.Top() + TAB_TABOFFSET_Y,
+                                       pItem->maRect.Bottom() - TAB_TABOFFSET_Y));
+        if (pItem->maRect.Left() < 5)
             tiValue.mnAlignment |= TABITEM_LEFTALIGNED;
-        if(pItem->maRect.Right() > mnLastWidth - 5)
+        if (pItem->maRect.Right() > mnLastWidth - 5)
             tiValue.mnAlignment |= TABITEM_RIGHTALIGNED;
-        if ( bFirstInGroup )
+        if (bFirstInGroup)
             tiValue.mnAlignment |= TABITEM_FIRST_IN_GROUP;
-        if ( bLastInGroup )
+        if (bLastInGroup)
             tiValue.mnAlignment |= TABITEM_LAST_IN_GROUP;
 
-        Rectangle           aCtrlRegion( pItem->maRect );
+        Rectangle aCtrlRegion( pItem->maRect );
         bNativeOK = DrawNativeControl( CTRL_TAB_ITEM, PART_ENTIRE_CONTROL, aCtrlRegion, nState,
                     tiValue, OUString() );
     }
diff --git a/vcl/source/outdev/nativecontrols.cxx b/vcl/source/outdev/nativecontrols.cxx
index 5a963c2..95fbfaa 100644
--- a/vcl/source/outdev/nativecontrols.cxx
+++ b/vcl/source/outdev/nativecontrols.cxx
@@ -236,6 +236,7 @@ static std::shared_ptr< ImplControlValue > TransformControlValue( const ImplCont
         {
             const TabitemValue* pTIVal = static_cast<const TabitemValue*>(&rVal);
             TabitemValue* pNew = new TabitemValue( *pTIVal );
+            pNew->maContentRect = rDev.ImplLogicToDevicePixel(pTIVal->maContentRect);
             aResult.reset( pNew );
         }
         break;
diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
index 86c2879..17ef6e2 100644
--- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
@@ -1033,7 +1033,7 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co
     return true;
 }
 
-Rectangle AdjustRectForTextBordersPadding(GtkStyleContext* pStyle, long nTextHeight, const Rectangle& rControlRegion)
+Rectangle AdjustRectForTextBordersPadding(GtkStyleContext* pStyle, long nContentHeight, const Rectangle& rControlRegion)
 {
     gtk_style_context_save(pStyle);
 
@@ -1043,7 +1043,7 @@ Rectangle AdjustRectForTextBordersPadding(GtkStyleContext* pStyle, long nTextHei
     GtkBorder padding;
     gtk_style_context_get_padding(pStyle, GTK_STATE_FLAG_NORMAL, &padding);
 
-    gint nWidgetHeight = nTextHeight + padding.top + padding.bottom + border.top + border.bottom;
+    gint nWidgetHeight = nContentHeight + padding.top + padding.bottom + border.top + border.bottom;
 
     nWidgetHeight = std::max<gint>(nWidgetHeight, rControlRegion.GetHeight());
 
@@ -1054,6 +1054,29 @@ Rectangle AdjustRectForTextBordersPadding(GtkStyleContext* pStyle, long nTextHei
     return aEditRect;
 }
 
+Rectangle AdjustRectForTextBordersPadding(GtkStyleContext* pStyle, long nContentWidth, long nContentHeight, const Rectangle& rControlRegion)
+{
+    gtk_style_context_save(pStyle);
+
+    GtkBorder border;
+    gtk_style_context_get_border(pStyle, GTK_STATE_FLAG_NORMAL, &border);
+
+    GtkBorder padding;
+    gtk_style_context_get_padding(pStyle, GTK_STATE_FLAG_NORMAL, &padding);
+
+    gint nWidgetHeight = nContentHeight + padding.top + padding.bottom + border.top + border.bottom;
+    nWidgetHeight = std::max<gint>(nWidgetHeight, rControlRegion.GetHeight());
+
+    gint nWidgetWidth = nContentWidth + padding.left + padding.right + border.left + border.right;
+    nWidgetWidth = std::max<gint>(nWidgetWidth, rControlRegion.GetWidth());
+
+    Rectangle aEditRect(rControlRegion.TopLeft(), Size(nWidgetWidth, nWidgetHeight));
+
+    gtk_style_context_restore(pStyle);
+
+    return aEditRect;
+}
+
 bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState,
                                                 const ImplControlValue& rValue, const OUString&,
                                                 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion )
@@ -1168,7 +1191,11 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar
         gtk_style_context_add_region(mpNoteBookStyle, GTK_STYLE_REGION_TAB, GTK_REGION_ONLY);
         gtk_style_context_add_class(mpNoteBookStyle, GTK_STYLE_CLASS_TOP);
 
-        aEditRect = AdjustRectForTextBordersPadding(mpSpinStyle, rValue.getNumericVal(), rControlRegion);
+        const TabitemValue& rTabitemValue = static_cast<const TabitemValue&>(rValue);
+        const Rectangle& rTabitemRect = rTabitemValue.getContentRect();
+
+        aEditRect = AdjustRectForTextBordersPadding(mpNoteBookStyle, rTabitemRect.GetWidth(),
+                                                    rTabitemRect.GetHeight(), rControlRegion);
 
         gtk_style_context_restore(mpNoteBookStyle);
     }


More information about the Libreoffice-commits mailing list