[Libreoffice-commits] core.git: cui/source cui/uiconfig sw/source

Miklos Vajna vmiklos at suse.cz
Tue Feb 12 07:38:53 PST 2013


 cui/source/inc/backgrnd.hxx       |   16 ++++
 cui/source/tabpages/backgrnd.cxx  |  138 +++++++++++++++++++++++++++++++-------
 cui/uiconfig/ui/backgroundpage.ui |   74 ++++++++++++++++++++
 sw/source/core/bastyp/init.cxx    |    4 -
 sw/source/ui/frmdlg/frmdlg.cxx    |   16 ++++
 5 files changed, 224 insertions(+), 24 deletions(-)

New commits:
commit d884f8f65cc73cf932cde1e40cadf13556a7d44e
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Tue Feb 12 16:14:23 2013 +0100

    SwFrmDlg: initial gradient background UI
    
    Change-Id: I7d8612d6b2d3eb2262ed148153a0c249bcb36599

diff --git a/cui/source/inc/backgrnd.hxx b/cui/source/inc/backgrnd.hxx
index b70732b..24a8ccc 100644
--- a/cui/source/inc/backgrnd.hxx
+++ b/cui/source/inc/backgrnd.hxx
@@ -34,6 +34,8 @@ struct SvxBackgroundTable_Impl;
 struct SvxBackgroundPara_Impl;
 struct SvxBackgroundPage_Impl;
 class SvxBrushItem;
+class XFillStyleItem;
+class XFillGradientItem;
 /** class SvxBackgroundTabPage --------------------------------------------
 {k:\svx\prototyp\dialog\backgrnd.bmp}
     [Description]
@@ -85,6 +87,17 @@ private:
     MetricField*            m_pColTransMF;
     CheckBox*               m_pBtnPreview;
 
+    // Gradient controls
+    VclFrame*               m_pBackGroundGradientFrame;
+    GradientLB*             m_pLbGradients;
+    SvxXRectPreview*        m_pCtlPreview;
+
+    // Gradient data
+    XGradientListRef        m_pGradientList;
+    SfxItemPool*            m_pXPool;
+    XFillAttrSetItem        m_aXFillAttr;
+    SfxItemSet&             m_rXFillSet;
+
     // Background Bitmap ----------------------------------
     VclContainer*           m_pFileFrame;
     PushButton*             m_pBtnBrowse;
@@ -128,6 +141,8 @@ private:
     void                HideColorUI_Impl();
     void                ShowBitmapUI_Impl();
     void                HideBitmapUI_Impl();
+    void                ShowGradientUI_Impl();
+    void                HideGradientUI_Impl();
     sal_Bool                LoadLinkedGraphic_Impl();
     void                RaiseLoadError_Impl();
     void                SetGraphicPosition_Impl( SvxGraphicPosition ePos );
@@ -145,6 +160,7 @@ private:
     DECL_LINK(BackgroundColorHdl_Impl, void *);
     DECL_LINK( TblDestinationHdl_Impl, ListBox* );
     DECL_LINK( ParaDestinationHdl_Impl, ListBox* );
+    DECL_LINK(ModifyGradientHdl_Impl, void *);
 #endif
 };
 
diff --git a/cui/source/tabpages/backgrnd.cxx b/cui/source/tabpages/backgrnd.cxx
index 6715f6f..fdeb7bc 100644
--- a/cui/source/tabpages/backgrnd.cxx
+++ b/cui/source/tabpages/backgrnd.cxx
@@ -52,6 +52,8 @@
 #include <svx/htmlmode.hxx>
 #include <svtools/controldims.hrc>
 #include <svx/flagsdef.hxx>
+#include <svx/xfillit0.hxx>
+#include <svx/xflgrit.hxx>
 #include <svl/intitem.hxx>
 #include <sfx2/request.hxx>
 using namespace ::com::sun::star;
@@ -320,6 +322,9 @@ void BackgroundPreviewImpl::DataChanged( const DataChangedEvent& rDCEvt )
 
 SvxBackgroundTabPage::SvxBackgroundTabPage(Window* pParent, const SfxItemSet& rCoreSet)
     : SvxTabPage(pParent, "BackgroundPage", "cui/ui/backgroundpage.ui", rCoreSet)
+    , m_pXPool(rCoreSet.GetPool())
+    , m_aXFillAttr(m_pXPool)
+    , m_rXFillSet(m_aXFillAttr.GetItemSet())
     , nHtmlMode(0)
     , bAllowShowSelector(true)
     , bIsGraphicValid(false)
@@ -345,6 +350,17 @@ SvxBackgroundTabPage::SvxBackgroundTabPage(Window* pParent, const SfxItemSet& rC
     get(m_pColTransMF, "transparencymf");
     get(m_pBtnPreview, "showpreview");
 
+    // Initialize gradient controls
+    get(m_pBackGroundGradientFrame, "backgroundgradientframe");
+    get(m_pLbGradients, "gradientslb");
+    Size aSize = LogicToPixel(Size(88, 110), MAP_APPFONT);
+    m_pLbGradients->set_width_request(aSize.Width());
+    m_pLbGradients->set_height_request(aSize.Height());
+    get(m_pCtlPreview, "previewctl");
+    aSize = LogicToPixel(Size(88, 42), MAP_APPFONT);
+    m_pCtlPreview->set_width_request(aSize.Width());
+    m_pCtlPreview->set_height_request(aSize.Height());
+
     get(m_pFileFrame, "fileframe");
     get(m_pBtnBrowse, "browse");
     get(m_pBtnLink, "link");
@@ -743,6 +759,7 @@ sal_Bool SvxBackgroundTabPage::FillItemSet( SfxItemSet& rCoreSet )
         const SvxBrushItem& rOldItem    = (const SvxBrushItem&)*pOld;
         SvxGraphicPosition  eOldPos     = rOldItem.GetGraphicPos();
         const sal_Bool          bIsBrush    = ( 0 == m_pLbSelect->GetSelectEntryPos() );
+        const bool bIsGradient = ( 2 == m_pLbSelect->GetSelectEntryPos() );
 
         // transparency has to be set if enabled, the color not already set to "No fill" and
         if( bColTransparency &&
@@ -750,22 +767,34 @@ sal_Bool SvxBackgroundTabPage::FillItemSet( SfxItemSet& rCoreSet )
         {
             aBgdColor.SetTransparency(lcl_PercentToTransparency(static_cast<long>(m_pColTransMF->GetValue())));
         }
-        if (   ( (GPOS_NONE == eOldPos) && bIsBrush  )
-            || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
+        if (   ( (GPOS_NONE == eOldPos) && (bIsBrush || bIsGradient)  )
+            || ( (GPOS_NONE != eOldPos) && !(bIsBrush || bIsGradient) ) ) // Brush <-> Bitmap changed?
         {
             // background art hasn't been changed:
 
             if ( (GPOS_NONE == eOldPos) || !m_pLbSelect->IsVisible() )
             {
-                // Brush-treatment:
-                if ( rOldItem.GetColor() != aBgdColor ||
-                        (SFX_ITEM_AVAILABLE >= eOldItemState && !m_pBackgroundColorSet->IsNoSelection()))
+                if (bIsBrush)
                 {
-                    bModified = sal_True;
-                    rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
+                    // Brush-treatment:
+                    if ( rOldItem.GetColor() != aBgdColor ||
+                            (SFX_ITEM_AVAILABLE >= eOldItemState && !m_pBackgroundColorSet->IsNoSelection()))
+                    {
+                        bModified = sal_True;
+                        rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
+                    }
+                    else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
+                        rCoreSet.ClearItem( nWhich );
+                }
+                else
+                {
+                    XFillStyleItem aFillStyleItem(((const XFillStyleItem&)m_rXFillSet.Get(XATTR_FILLSTYLE)).GetValue(), GetWhich(SID_ATTR_FILL_STYLE));
+                    rCoreSet.Put(aFillStyleItem);
+
+                    const XFillGradientItem& rFillGradientItem = (const XFillGradientItem&)m_rXFillSet.Get(XATTR_FILLGRADIENT);
+                    XFillGradientItem aFillGradientItem(rFillGradientItem.GetName(), rFillGradientItem.GetGradientValue(), GetWhich(SID_ATTR_FILL_GRADIENT));
+                    rCoreSet.Put(aFillGradientItem);
                 }
-                else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
-                    rCoreSet.ClearItem( nWhich );
             }
             else
             {
@@ -1054,6 +1083,7 @@ void SvxBackgroundTabPage::ShowSelector()
         m_pBtnArea->SetClickHdl( HDL(RadioClickHdl_Impl) );
         m_pBtnTile->SetClickHdl( HDL(RadioClickHdl_Impl) );
         m_pBtnPosition->SetClickHdl( HDL(RadioClickHdl_Impl) );
+        m_pLbGradients->SetSelectHdl(HDL(ModifyGradientHdl_Impl));
 
         // delayed loading via timer (because of UI-Update)
         pPageImpl->pLoadTimer = new Timer;
@@ -1166,6 +1196,7 @@ void SvxBackgroundTabPage::ShowColorUI_Impl()
     if (!m_pBackGroundColorFrame->IsVisible())
     {
         HideBitmapUI_Impl();
+        HideGradientUI_Impl();
         m_pBackGroundColorFrame->Show();
 
         if(bColTransparency)
@@ -1196,6 +1227,7 @@ void SvxBackgroundTabPage::ShowBitmapUI_Impl()
          (m_pBackGroundColorFrame->IsVisible() || !m_pFileFrame->IsVisible()))
     {
         HideColorUI_Impl();
+        HideGradientUI_Impl();
 
         m_pBtnPreview->Show();
 
@@ -1225,6 +1257,21 @@ void SvxBackgroundTabPage::HideBitmapUI_Impl()
         m_pGraphTransFrame->Hide();
 }
 
+void SvxBackgroundTabPage::ShowGradientUI_Impl()
+{
+    if (!m_pBackGroundGradientFrame->IsVisible())
+    {
+        HideColorUI_Impl();
+        HideBitmapUI_Impl();
+
+        m_pBackGroundGradientFrame->Show();
+    }
+}
+
+void SvxBackgroundTabPage::HideGradientUI_Impl()
+{
+    m_pBackGroundGradientFrame->Hide();
+}
 
 //------------------------------------------------------------------------
 
@@ -1326,11 +1373,15 @@ IMPL_LINK_NOARG(SvxBackgroundTabPage, SelectHdl_Impl)
         ShowColorUI_Impl();
         m_pParaLBox->Enable(); // drawing background can't be a bitmap
     }
-    else
+    else if ( 1 == m_pLbSelect->GetSelectEntryPos() )
     {
         ShowBitmapUI_Impl();
         m_pParaLBox->Enable(sal_False); // drawing background can't be a bitmap
     }
+    else
+    {
+        ShowGradientUI_Impl();
+    }
     return 0;
 }
 
@@ -1403,6 +1454,21 @@ IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
     return 0;
 }
 
+IMPL_LINK_NOARG(SvxBackgroundTabPage, ModifyGradientHdl_Impl)
+{
+    sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
+
+    if (nPos != LISTBOX_ENTRY_NOTFOUND)
+    {
+        XGradientEntry* pEntry = m_pGradientList->GetGradient(nPos);
+        m_rXFillSet.Put( XFillStyleItem( XFILL_GRADIENT ) );
+        m_rXFillSet.Put( XFillGradientItem( String(), pEntry->GetGradient() ) );
+    }
+    m_pCtlPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
+    m_pCtlPreview->Invalidate();
+    return 0;
+}
+
 //------------------------------------------------------------------------
 
 IMPL_LINK_NOARG(SvxBackgroundTabPage, BrowseHdl_Impl)
@@ -1690,24 +1756,36 @@ void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
 
     if ( GPOS_NONE == ePos || !m_pLbSelect->IsVisible() )
     {
-        m_pLbSelect->SelectEntryPos( 0 );
-        ShowColorUI_Impl();
-        Color aTrColor( COL_TRANSPARENT );
-        aBgdColor = rColor;
+        // We don't have a graphic, do we have gradient fill style?
+        if (!m_rXFillSet.HasItem(XATTR_FILLSTYLE) || ((const XFillStyleItem&)m_rXFillSet.Get(XATTR_FILLSTYLE)).GetValue() != XFILL_GRADIENT)
+        {
+            m_pLbSelect->SelectEntryPos( 0 );
+            ShowColorUI_Impl();
+            Color aTrColor( COL_TRANSPARENT );
+            aBgdColor = rColor;
 
-        sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
-            GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor) : 0;
+            sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
+                GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor) : 0;
 
-        if( aTrColor != aBgdColor && nCol == 0)
-        {
-            m_pBackgroundColorSet->SetNoSelection();
+            if( aTrColor != aBgdColor && nCol == 0)
+            {
+                m_pBackgroundColorSet->SetNoSelection();
+            }
+            else
+            {
+                m_pBackgroundColorSet->SelectItem( nCol );
+            }
+
+            m_pPreviewWin1->NotifyChange( aBgdColor );
         }
         else
         {
-            m_pBackgroundColorSet->SelectItem( nCol );
+            // Gradient fill style, then initialize preview with data from Writer.
+            m_pLbSelect->SelectEntryPos( 2 );
+            ShowGradientUI_Impl();
+            m_pCtlPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
+            m_pCtlPreview->Invalidate();
         }
-
-        m_pPreviewWin1->NotifyChange( aBgdColor );
         if ( m_pLbSelect->IsVisible() ) // initialize graphic part
         {
             aBgdGraphicFilter.Erase();
@@ -1813,6 +1891,8 @@ void SvxBackgroundTabPage::EnableTransparency(sal_Bool bColor, sal_Bool bGraphic
 void SvxBackgroundTabPage::PageCreated (SfxAllItemSet aSet)
 {
     SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,sal_False);
+    SFX_ITEMSET_ARG (&aSet,pGradientListItem,SvxGradientListItem,SID_GRADIENT_LIST,sal_False);
+
     if (pFlagItem)
     {
         sal_uInt32 nFlags=pFlagItem->GetValue();
@@ -1825,6 +1905,20 @@ void SvxBackgroundTabPage::PageCreated (SfxAllItemSet aSet)
         if ( ( nFlags & SVX_ENABLE_TRANSPARENCY ) == SVX_ENABLE_TRANSPARENCY )
             EnableTransparency(sal_True, sal_True);
     }
+
+    if (pGradientListItem)
+    {
+        // If we get a gradient list, also read fill and gradient style.
+        m_pGradientList = pGradientListItem->GetGradientList();
+        m_pLbGradients->Fill(m_pGradientList);
+        const XFillStyleItem& rFillStyleItem = (const XFillStyleItem&)aSet.Get(SID_ATTR_FILL_STYLE);
+        m_rXFillSet.Put(XFillStyleItem(rFillStyleItem.GetValue()));
+        const XFillGradientItem& rFillGradientItem = (const XFillGradientItem&)aSet.Get(SID_ATTR_FILL_GRADIENT);
+        m_rXFillSet.Put(XFillGradientItem(rFillGradientItem.GetGradientValue()));
+    }
+    else
+        // Otherwise hide the gradient UI.
+        m_pLbSelect->RemoveEntry(2);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/uiconfig/ui/backgroundpage.ui b/cui/uiconfig/ui/backgroundpage.ui
index 96b0fd5..d601ca9 100644
--- a/cui/uiconfig/ui/backgroundpage.ui
+++ b/cui/uiconfig/ui/backgroundpage.ui
@@ -44,6 +44,7 @@
             <items>
               <item translatable="yes">Color</item>
               <item translatable="yes">Graphic</item>
+              <item translatable="yes">Gradient</item>
             </items>
           </object>
           <packing>
@@ -624,5 +625,78 @@
         <property name="height">1</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkGrid" id="backgroundgradient">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkFrame" id="backgroundgradientframe">
+            <property name="can_focus">False</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <object class="GtkAlignment" id="alignment5">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="top_padding">6</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkGrid" id="grid11">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="svxlo:GradientLB" id="gradientslb">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="svxlo:SvxXRectPreview" id="previewctl">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Background gradient</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">3</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
   </object>
 </interface>
diff --git a/sw/source/core/bastyp/init.cxx b/sw/source/core/bastyp/init.cxx
index 8bc3623..e3b64ac 100644
--- a/sw/source/core/bastyp/init.cxx
+++ b/sw/source/core/bastyp/init.cxx
@@ -381,8 +381,8 @@ SfxItemInfo aSlotTab[] =
     { 0, 0 },                                           // RES_AUTO_STYLE
     { 0, SFX_ITEM_POOLABLE },                           // RES_FRMATR_STYLE_NAME
     { 0, SFX_ITEM_POOLABLE },                           // RES_FRMATR_CONDITIONAL_STYLE_NAME
-    { 0, SFX_ITEM_POOLABLE },                           // RES_FILL_STYLE
-    { 0, SFX_ITEM_POOLABLE },                           // RES_FILL_GRADIENT
+    { SID_ATTR_FILL_STYLE, SFX_ITEM_POOLABLE },                           // RES_FILL_STYLE
+    { SID_ATTR_FILL_GRADIENT, SFX_ITEM_POOLABLE },                           // RES_FILL_GRADIENT
 
     { 0, SFX_ITEM_POOLABLE },                           // RES_GRFATR_MIRRORGRF
     { SID_ATTR_GRAF_CROP, SFX_ITEM_POOLABLE },          // RES_GRFATR_CROPGRF
diff --git a/sw/source/ui/frmdlg/frmdlg.cxx b/sw/source/ui/frmdlg/frmdlg.cxx
index b1b2550..aaccdf4 100644
--- a/sw/source/ui/frmdlg/frmdlg.cxx
+++ b/sw/source/ui/frmdlg/frmdlg.cxx
@@ -23,6 +23,7 @@
 #include <svx/htmlmode.hxx>
 #include <fmtfsize.hxx>
 #include <wrtsh.hxx>
+#include <doc.hxx>
 #include <view.hxx>
 #include <docsh.hxx>
 #include <viewopt.hxx>
@@ -37,6 +38,10 @@
 #include <svx/svxids.hrc>
 #include <svx/flagsdef.hxx>
 #include <svx/svxdlg.hxx>
+#include <svx/svdmodel.hxx>
+#include <svx/drawitem.hxx>
+#include <svx/xfillit0.hxx>
+#include <svx/xflgrit.hxx>
 
 /*--------------------------------------------------------------------
     Description:    the dialog's carrier
@@ -173,6 +178,17 @@ void SwFrmDlg::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
             if(!m_bHTMLMode)
                 nFlagType |= SVX_ENABLE_TRANSPARENCY;
             aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, nFlagType));
+
+            SvxGradientListItem aGradientListItem(m_pWrtShell->GetDoc()->GetOrCreateDrawModel()->GetGradientList(), SID_GRADIENT_LIST);
+            aSet.Put(aGradientListItem);
+
+            XFillStyleItem aFillStyleItem(((const XFillStyleItem&)m_rSet.Get(RES_FILL_STYLE)).GetValue(), SID_ATTR_FILL_STYLE);
+            aSet.Put(aFillStyleItem);
+
+            const XFillGradientItem& rFillGradientItem = (const XFillGradientItem&)m_rSet.Get(RES_FILL_GRADIENT);
+            XFillGradientItem aFillGradientItem(rFillGradientItem.GetName(), rFillGradientItem.GetGradientValue(), SID_ATTR_FILL_GRADIENT);
+            aSet.Put(aFillGradientItem);
+
             rPage.PageCreated(aSet);
         }
         break;


More information about the Libreoffice-commits mailing list