[Libreoffice-commits] core.git: sc/inc sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Mar 19 14:57:30 PDT 2014


 sc/inc/globstr.hrc             |    5 ++-
 sc/source/ui/inc/preview.hxx   |    1 
 sc/source/ui/inc/printfun.hxx  |    3 +
 sc/source/ui/src/globstr.src   |   10 ++++++
 sc/source/ui/view/preview.cxx  |   63 +++++++++++++++++++++++++++++++++++++++++
 sc/source/ui/view/printfun.cxx |   19 +++++++++++-
 6 files changed, 98 insertions(+), 3 deletions(-)

New commits:
commit 9040ef49f0b2886a51630878c06b2fb9cf94b927
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Mar 19 14:05:04 2014 -0400

    cp#1000022: Display message in print preview when there is nothing to show.
    
    To make this experience slightly less confusing.
    
    Change-Id: I844dd2cdbc0349433d445955cdcf5e9723673286

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 3dfb79b..8456944 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -689,7 +689,10 @@
 
 #define STR_ROWCOL_SELCOUNT         528
 
-#define SC_GLOBSTR_STR_COUNT        529     /**< the count of permanently resident strings */
+#define STR_PRINT_PREVIEW_NODATA        529
+#define STR_PRINT_PREVIEW_EMPTY_RANGE   530
+
+#define SC_GLOBSTR_STR_COUNT            531     /**< the count of permanently resident strings */
 
 #endif
 
diff --git a/sc/source/ui/inc/preview.hxx b/sc/source/ui/inc/preview.hxx
index fe1f642..f9d1b5c 100644
--- a/sc/source/ui/inc/preview.hxx
+++ b/sc/source/ui/inc/preview.hxx
@@ -80,6 +80,7 @@ private:
     bool            bFooterRulerChange:1;
     bool            bPageMargin:1;
     bool            bColRulerMove:1;
+    bool            mbHasEmptyRangeTable:1; /// we have at least one sheet with empty print range (print range set to '- none -').
 
     ScRange         aPageArea;
     long            nRight[ MAXCOL+1 ];
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index a0306b0..47a2a4e 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -167,6 +167,7 @@ private:
     sal_uInt16          nZoom;
     bool                bPrintCurrentTable;
     bool                bMultiArea;
+    bool                mbHasPrintRange;
     long                nTabPages;
     long                nTotalPages;
 
@@ -276,6 +277,8 @@ public:
     ScPrintHFParam  GetHeader(){return aHdr;}
     ScPrintHFParam  GetFooter(){return aFtr;}
 
+    bool HasPrintRange() const;
+
 private:
     void            Construct( const ScPrintOptions* pOptions );
     void            InitParam( const ScPrintOptions* pOptions );
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 82eb914..9897db3 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -2061,6 +2061,16 @@ Resource RID_GLOBSTR
     {
         Text [ en-US ] = "click to open hyperlink:";
     };
+
+    String STR_PRINT_PREVIEW_NODATA
+    {
+        Text [ en-US ] = "Empty Content";
+    };
+
+    String STR_PRINT_PREVIEW_EMPTY_RANGE
+    {
+        Text [ en-US ] = "Empty Print Range";
+    };
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx
index 5d2b015..9930741 100644
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@ -53,6 +53,8 @@
 #include <svx/algitem.hxx>
 #include <editeng/lrspitem.hxx>
 #include <editeng/ulspitem.hxx>
+#include <editeng/colritem.hxx>
+#include <editeng/fhgtitem.hxx>
 #include "attrib.hxx"
 #include "pagepar.hxx"
 #include <com/sun/star/accessibility/XAccessible.hpp>
@@ -60,6 +62,10 @@
 #include <vcl/svapp.hxx>
 #include "viewutil.hxx"
 #include <columnspanset.hxx>
+#include <docpool.hxx>
+#include <patattr.hxx>
+
+#include <boost/scoped_ptr.hpp>
 
 // STATIC DATA -----------------------------------------------------------
 
@@ -118,6 +124,7 @@ ScPreview::ScPreview( Window* pParent, ScDocShell* pDocSh, ScPreviewShell* pView
     bFooterRulerChange( false ),
     bPageMargin ( false ),
     bColRulerMove( false ),
+    mbHasEmptyRangeTable(false),
     mnScale( 0 ),
     nColNumberButttonDown( 0 ),
     nHeaderHeight ( 0 ),
@@ -258,6 +265,9 @@ void ScPreview::CalcPages()
         long nThisStart = nTotalPages;
         ScPrintFunc aPrintFunc( this, pDocShell, i, nAttrPage, 0, NULL, &aOptions );
         long nThisTab = aPrintFunc.GetTotalPages();
+        if (!aPrintFunc.HasPrintRange())
+            mbHasEmptyRangeTable = true;
+
         nPages[i] = nThisTab;
         nTotalPages += nThisTab;
         nFirstAttr[i] = aPrintFunc.GetFirstPageNo();    // to keep or from template
@@ -481,6 +491,59 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
         bool bRight  = nPageEndX <= aWinEnd.X();
         bool bBottom = nPageEndY <= aWinEnd.Y();
 
+        if (!nTotalPages)
+        {
+            // There is no data to print. Print a friendly warning message and
+            // bail out.
+
+            SetMapMode(aMMMode);
+
+            // Draw background first.
+            SetLineColor();
+            SetFillColor(aBackColor);
+            DrawRect(Rectangle(0, 0, aWinEnd.X(), aWinEnd.Y()));
+
+            const ScPatternAttr& rDefPattern =
+                static_cast<const ScPatternAttr&>(
+                    pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN));
+
+            boost::scoped_ptr<ScEditEngineDefaulter> pEditEng(
+                new ScEditEngineDefaulter(EditEngine::CreatePool(), true));
+
+            pEditEng->SetRefMapMode(aMMMode);
+            SfxItemSet* pEditDefaults = new SfxItemSet( pEditEng->GetEmptyItemSet() );
+            rDefPattern.FillEditItemSet(pEditDefaults);
+            pEditEng->SetDefaults(pEditDefaults, true);
+
+            Color aTextColor(COL_LIGHTGRAY);
+            pEditDefaults->Put(SvxColorItem(aTextColor, EE_CHAR_COLOR));
+
+            OUString aEmptyMsg;
+            if (mbHasEmptyRangeTable)
+                aEmptyMsg = ScGlobal::GetRscString(STR_PRINT_PREVIEW_EMPTY_RANGE);
+            else
+                aEmptyMsg = ScGlobal::GetRscString(STR_PRINT_PREVIEW_NODATA);
+
+            long nHeight = 3000;
+            pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT));
+            pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT_CJK));
+            pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT_CTL));
+
+            pEditEng->SetText(aEmptyMsg);
+
+            // Calculate text position so that the text appears at the center
+            // of the screen center-aligned.
+            Size aTextSize(pEditEng->CalcTextWidth(), pEditEng->GetTextHeight());
+
+            Point aCenter(
+                (aWinEnd.X() - pEditEng->CalcTextWidth())/2,
+                (aWinEnd.Y() - pEditEng->GetTextHeight())/2);
+
+            pEditEng->Draw(this, aCenter);
+
+            return;
+        }
+
         if( bPageMargin && bValidPage )
         {
             SetMapMode(aMMMode);
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 4ddbf6c..034ef3b 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -227,6 +227,7 @@ ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTa
         bSourceRangeValid   ( false ),
         bPrintCurrentTable  ( false ),
         bMultiArea          ( false ),
+        mbHasPrintRange(true),
         nTabPages           ( 0 ),
         nTotalPages         ( 0 ),
         nPagesX(0),
@@ -253,6 +254,7 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
         bSourceRangeValid   ( false ),
         bPrintCurrentTable  ( false ),
         bMultiArea          ( false ),
+        mbHasPrintRange(true),
         nTabPages           ( 0 ),
         nTotalPages         ( 0 ),
         nPagesX(0),
@@ -273,6 +275,7 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
         bSourceRangeValid   ( false ),
         bPrintCurrentTable  ( false ),
         bMultiArea          ( false ),
+        mbHasPrintRange(true),
         nPagesX(0),
         nPagesY(0),
         nTotalY(0),
@@ -313,6 +316,11 @@ void ScPrintFunc::GetPrintState( ScPrintState& rState )
     rState.nDocPages    = nDocPages;
 }
 
+bool ScPrintFunc::HasPrintRange() const
+{
+    return mbHasPrintRange;
+}
+
 bool ScPrintFunc::GetLastSourceRange( ScRange& rRange ) const
 {
     rRange = aLastSourceRange;
@@ -948,6 +956,13 @@ void ScPrintFunc::InitParam( const ScPrintOptions* pOptions )
 
     //  ignoring ATTR_PAGE_PRINTTABLES
 
+    bool bHasPrintRange = pDoc->HasPrintRange();
+    sal_uInt16 nPrintRangeCount = pDoc->GetPrintRangeCount(nPrintTab);
+    bool bPrintEntireSheet = pDoc->IsPrintEntireSheet(nPrintTab);
+
+    if (!bPrintEntireSheet && !nPrintRangeCount)
+        mbHasPrintRange = false;
+
     if ( pUserArea )                // UserArea (selection) has prority
     {
         bPrintCurrentTable    =
@@ -958,7 +973,7 @@ void ScPrintFunc::InitParam( const ScPrintOptions* pOptions )
         aAreaParam.aPrintArea.aStart.SetTab(nPrintTab);
         aAreaParam.aPrintArea.aEnd.SetTab(nPrintTab);
     }
-    else if ( pDoc->HasPrintRange() )
+    else if (bHasPrintRange)
     {
         if ( pPrintArea )                               // at least one set?
         {
@@ -966,7 +981,7 @@ void ScPrintFunc::InitParam( const ScPrintOptions* pOptions )
             aAreaParam.bPrintArea = true;
             aAreaParam.aPrintArea = *pPrintArea;
 
-            bMultiArea = ( pDoc->GetPrintRangeCount(nPrintTab) > 1 );
+            bMultiArea = nPrintRangeCount > 1;
         }
         else
         {


More information about the Libreoffice-commits mailing list