Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hello,

Here is some patchs :
0001 : one line, code simplification.
0002 : explicite NULL or 0 comparison in if. I don't know if LibreOffice
have a coding standard about that type of comparison ?
0003 : some rewriting of SfxViewShell::ExecPrint_Impl ; add some
comments, prevent a segfault (NULL pointer dereferencing ; add return
after "rReq.SetReturnValue(SfxBoolItem(0,sal_False))")…
0004 : Prevent the printer settings dialog to show help button when it's
called from a help window.

Regards.

-- 
Maxime de Roucy
Groupe LINAGORA - OSSA
80 rue Roque de Fillol
92800 PUTEAUX
Tel. : 0033(0)642004909


From 858e796808271d8280aece653704261839042922 Mon Sep 17 00:00:00 2001
From: Maxime de Roucy <mderoucy@linagora.com>
Date: Wed, 30 May 2012 10:45:02 +0200
Subject: [PATCH 1/4] Change unnecessary pointer dereference

Change-Id: I28404d9d1a18886361deae1aec583ef40c25ce85
---
 sw/source/ui/uno/SwXDocumentSettings.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sw/source/ui/uno/SwXDocumentSettings.cxx b/sw/source/ui/uno/SwXDocumentSettings.cxx
index d988bf5..ff56b00 100644
--- a/sw/source/ui/uno/SwXDocumentSettings.cxx
+++ b/sw/source/ui/uno/SwXDocumentSettings.cxx
@@ -839,7 +839,7 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf
         break;
         case HANDLE_PRINTER_SETUP:
         {
-            SfxPrinter *pPrinter = mpDocSh->GetDoc()->getPrinter( sal_False );
+            SfxPrinter *pPrinter = mpDoc->getPrinter( sal_False );
             if (pPrinter)
             {
                 SvMemoryStream aStream;
-- 
1.7.11

From 1ec537b448324972cdb59fcbea67e3b165228116 Mon Sep 17 00:00:00 2001
From: Maxime de Roucy <mderoucy@linagora.com>
Date: Wed, 30 May 2012 10:57:09 +0200
Subject: [PATCH 2/4] Explicit if statement

Change-Id: I80fb875cab4e15f0eeab1739804b7530d4e26198
---
 sw/source/ui/uno/SwXDocumentSettings.cxx | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sw/source/ui/uno/SwXDocumentSettings.cxx b/sw/source/ui/uno/SwXDocumentSettings.cxx
index ff56b00..49a6791 100644
--- a/sw/source/ui/uno/SwXDocumentSettings.cxx
+++ b/sw/source/ui/uno/SwXDocumentSettings.cxx
@@ -433,7 +433,7 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
             sal_Bool bIsKern = *(sal_Bool*)(rValue).getValue();
             mpDoc->set(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION, bIsKern);
             SwEditShell* pEditSh = mpDoc->GetEditShell();
-            if(pEditSh)
+            if(pEditSh != NULL)
                 pEditSh->ChgHyphenation();
         }
         break;
@@ -589,7 +589,7 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
             if(rValue >>= aNew)
             {
                 mpDoc->SetRedlinePassword(aNew);
-                if(aNew.getLength())
+                if(aNew.getLength() != 0)
                 {
                     sal_uInt16 eMode = mpDoc->GetRedlineMode();
                     eMode = eMode|nsRedlineMode_t::REDLINE_ON;
@@ -840,7 +840,7 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf
         case HANDLE_PRINTER_SETUP:
         {
             SfxPrinter *pPrinter = mpDoc->getPrinter( sal_False );
-            if (pPrinter)
+            if (pPrinter != NULL)
             {
                 SvMemoryStream aStream;
                 pPrinter->Store( aStream );
-- 
1.7.11

From 9dfe6c37bc57fbad5ec0ab00f2fcdba8e55b6b75 Mon Sep 17 00:00:00 2001
From: Maxime de Roucy <mderoucy@linagora.com>
Date: Fri, 15 Jun 2012 17:19:41 +0200
Subject: [PATCH 3/4] Some rewriting in SfxViewShell::ExecPrint_Impl
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* add comments
* reorganise if statement
* use of the IsAPI function
* prevent segfault (NULL pointer dereferencing)

Change-Id: Icbdac93e5250346bd5b4c465d00740b5fb51e8ac
---
 sfx2/source/view/viewprn.cxx | 89 ++++++++++++++++++++++----------------------
 1 file changed, 44 insertions(+), 45 deletions(-)

diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index a8c19a2..20e2ac7 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -137,7 +137,7 @@ SfxPrinterController::SfxPrinterController( const boost::shared_ptr<Printer>& i_
     // initialize extra ui options
     if( mxRenderable.is() )
     {
-        for (sal_Int32 nProp=0; nProp<rProps.getLength(); nProp++)
+        for (sal_Int32 nProp=0; nProp < rProps.getLength(); nProp++)
             setValue( rProps[nProp].Name, rProps[nProp].Value );
 
         Sequence< beans::PropertyValue > aRenderOptions( 3 );
@@ -654,15 +654,21 @@ Printer* SfxViewShell::GetActivePrinter() const
 
 void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
 {
-    sal_uInt16                  nDialogRet = RET_CANCEL;
+    sal_uInt16              nDialogRet = RET_CANCEL;
     SfxPrinter*             pPrinter = 0;
     SfxDialogExecutor_Impl* pExecutor = 0;
     bool                    bSilent = false;
-    sal_Bool bIsAPI = rReq.GetArgs() && rReq.GetArgs()->Count();
+
+    // does the function have been called by the user interface or by an API call
+    sal_Bool bIsAPI = rReq.IsAPI();
     if ( bIsAPI )
     {
+        // the function have been called by the API
+
+        // Should it be visible on the user interface,
+        // should it launch popup dialogue ?
         SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
-        bSilent = pSilentItem && pSilentItem->GetValue();
+        bSilent = ( pSilentItem != NULL && pSilentItem->GetValue() );
     }
 
     //FIXME: how to transport "bPrintOnHelp"?
@@ -678,27 +684,20 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
     const sal_uInt16 nId = rReq.GetSlot();
     switch( nId )
     {
-        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-        case SID_PRINTDOC:
-        case SID_PRINTDOCDIRECT:
+        case SID_PRINTDOC: // display the printer selection and properties dialogue : File > Print…
+        case SID_PRINTDOCDIRECT: // Print the document directly, without displaying the dialogue
         {
             SfxObjectShell* pDoc = GetObjectShell();
 
             // derived class may decide to abort this
-            if( !pDoc->QuerySlotExecutable( nId ) )
+            if( pDoc == NULL || !pDoc->QuerySlotExecutable( nId ) )
             {
                 rReq.SetReturnValue( SfxBoolItem( 0, sal_False ) );
                 return;
             }
 
-            bool bDetectHidden = ( !bSilent && pDoc );
-            if ( bDetectHidden && pDoc->QueryHiddenInformation( WhenPrinting, NULL ) != RET_YES )
-                break;
-
-            SFX_REQUEST_ARG(rReq, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False);
-            sal_Bool bSelection = pSelectItem && pSelectItem->GetValue();
-            if( pSelectItem && rReq.GetArgs()->Count() == 1 )
-                bIsAPI = sal_False;
+            if ( !bSilent && pDoc->QueryHiddenInformation( WhenPrinting, NULL ) != RET_YES )
+                return;
 
             uno::Sequence < beans::PropertyValue > aProps;
             if ( bIsAPI )
@@ -714,21 +713,28 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
                 // bool Asynchron
                 // bool Collate
                 // bool Silent
+
+                // the TransformItems function overwrite aProps
                 TransformItems( nId, *rReq.GetArgs(), aProps, GetInterface()->GetSlot(nId) );
-                for ( sal_Int32 nProp=0; nProp<aProps.getLength(); nProp++ )
+
+                for ( sal_Int32 nProp=0; nProp < aProps.getLength(); nProp++ )
                 {
                     if ( aProps[nProp].Name == "Copies" )
+                    {
                         aProps[nProp]. Name = rtl::OUString("CopyCount");
+                    }
                     else if ( aProps[nProp].Name == "RangeText" )
+                    {
                         aProps[nProp]. Name = rtl::OUString("Pages");
-                    if ( aProps[nProp].Name == "Asynchron" )
+                    }
+                    else if ( aProps[nProp].Name == "Asynchron" )
                     {
                         aProps[nProp]. Name = rtl::OUString("Wait");
                         sal_Bool bAsynchron = sal_False;
                         aProps[nProp].Value >>= bAsynchron;
                         aProps[nProp].Value <<= (sal_Bool) (!bAsynchron);
                     }
-                    if ( aProps[nProp].Name == "Silent" )
+                    else if ( aProps[nProp].Name == "Silent" )
                     {
                         aProps[nProp]. Name = rtl::OUString("MonitorVisible");
                         sal_Bool bPrintSilent = sal_False;
@@ -737,6 +743,7 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
                     }
                 }
             }
+
             // HACK: writer sets the SID_SELECTION item when printing directly and expects
             // to get only the selection document in that case (see getSelectionObject)
             // however it also reacts to the PrintContent property. We need this distinction here, 
too,
@@ -744,6 +751,10 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
             // it would be better if writer handled this internally
             if( nId == SID_PRINTDOCDIRECT )
             {
+                // should we print only the selection or the whole document
+                SFX_REQUEST_ARG(rReq, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False);
+                sal_Bool bSelection = ( pSelectItem != NULL && pSelectItem->GetValue() );
+
                 sal_Int32 nLen = aProps.getLength();
                 aProps.realloc( nLen + 1 );
                 aProps[nLen].Name = rtl::OUString( "PrintSelectionOnly"  );
@@ -756,8 +767,7 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
             rReq.Done();
             break;
         }
-
-        case SID_SETUPPRINTER :
+        case SID_SETUPPRINTER : // display the printer settings dialogue : File > Printer Settings…
         case SID_PRINTER_NAME : // only for recorded macros
         {
             // get printer and printer settings from the document
@@ -765,49 +775,42 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
 
             // look for printer in parameters
             SFX_REQUEST_ARG( rReq, pPrinterItem, SfxStringItem, SID_PRINTER_NAME, sal_False );
-            if ( pPrinterItem )
+            if ( pPrinterItem != NULL )
             {
                 // use PrinterName parameter to create a printer
                 pPrinter = new SfxPrinter( pDocPrinter->GetOptions().Clone(), ((const 
SfxStringItem*) pPrinterItem)->GetValue() );
 
                 // if printer is unknown, it can't be used - now printer from document will be used
-                if ( !pPrinter->IsOriginal() )
+                if ( !pPrinter->IsKnown() )
                     DELETEZ(pPrinter);
             }
 
-            if ( SID_PRINTER_NAME == nId )
-            {
-                // just set a recorded printer name
-                if ( pPrinter )
-                    SetPrinter( pPrinter, SFX_PRINTER_PRINTER  );
-                break;
-            }
-
             // no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer
-            if ( !pPrinter )
+            if ( pPrinter == NULL )
                 // use default printer from document
                 pPrinter = pDocPrinter;
 
-            if( !pPrinter || !pPrinter->IsValid() )
+            if( pPrinter == NULL || !pPrinter->IsValid() )
             {
                 // no valid printer either in ItemSet or at the document
-                if ( bSilent )
-                {
-                    rReq.SetReturnValue(SfxBoolItem(0,sal_False));
-                    break;
-                }
-                else
+                if ( !bSilent )
                     ErrorBox( NULL, WB_OK | WB_DEF_OK, String( SfxResId( STR_NODEFPRINTER ) ) 
).Execute();
+
+                rReq.SetReturnValue(SfxBoolItem(0,sal_False));
+
+                return;
             }
 
             // FIXME: printer isn't used for printing anymore!
             if( pPrinter->IsPrinting() )
             {
-                // if printer is busy, abort printing
+                // if printer is busy, abort configuration
                 if ( !bSilent )
                     InfoBox( NULL, String( SfxResId( STR_ERROR_PRINTER_BUSY ) ) ).Execute();
+
                 rReq.SetReturnValue(SfxBoolItem(0,sal_False));
-                break;
+
+                return;
             }
 
             // if no arguments are given, retrieve them from a dialog
@@ -879,14 +882,10 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
                     if ( SID_PRINTDOC == nId )
                         rReq.SetReturnValue(SfxBoolItem(0,sal_False));
                     if ( nId == SID_SETUPPRINTER )
-                    {
                         rReq.AppendItem( SfxBoolItem( SID_DIALOG_RETURN, sal_False ) );
-            }
                 }
             }
         }
-
-        break;
     }
 }
 
-- 
1.7.11

From d63f7c628439b25bf98b9d8e8697aa9d309f8cb6 Mon Sep 17 00:00:00 2001
From: Maxime de Roucy <mderoucy@linagora.com>
Date: Fri, 15 Jun 2012 17:28:37 +0200
Subject: [PATCH 4/4] Prevent print settings dialog to show help button

Prevent the printer settings dialog to show help button when it's called
from the help.
Add a PrinterController property : HideHelpButton

Change-Id: I9ce548075f79e09115632fffa12dd14258ea5263
---
 sfx2/source/view/viewprn.cxx   | 15 +++++++++++----
 vcl/source/window/printdlg.cxx |  3 +++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index 20e2ac7..5f99161 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -671,8 +671,6 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
         bSilent = ( pSilentItem != NULL && pSilentItem->GetValue() );
     }
 
-    //FIXME: how to transport "bPrintOnHelp"?
-
     // no help button in dialogs if called from the help window
     // (pressing help button would exchange the current page inside the help
     // document that is going to be printed!)
@@ -744,6 +742,11 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
                 }
             }
 
+            // we will add the "PrintSelectionOnly" or "HideHelpButton" properties
+            // we have to increase the capacity of aProps
+            sal_Int32 nLen = aProps.getLength();
+            aProps.realloc( nLen + 1 );
+
             // HACK: writer sets the SID_SELECTION item when printing directly and expects
             // to get only the selection document in that case (see getSelectionObject)
             // however it also reacts to the PrintContent property. We need this distinction here, 
too,
@@ -755,11 +758,15 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
                 SFX_REQUEST_ARG(rReq, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False);
                 sal_Bool bSelection = ( pSelectItem != NULL && pSelectItem->GetValue() );
 
-                sal_Int32 nLen = aProps.getLength();
-                aProps.realloc( nLen + 1 );
                 aProps[nLen].Name = rtl::OUString( "PrintSelectionOnly"  );
                 aProps[nLen].Value = makeAny( bSelection );
             }
+            else // if nId == SID_PRINTDOC ; nothing to do with the previous HACK
+            {
+                // should the printer selection and properties dialogue display an help button
+                aProps[nLen].Name = rtl::OUString( "HideHelpButton" );
+                aProps[nLen].Value = makeAny( bPrintOnHelp );
+            }
 
             ExecPrint( aProps, bIsAPI, (nId == SID_PRINTDOCDIRECT) );
 
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index d9aa5dd..9c05203 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -902,6 +902,9 @@ PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterCont
     // setup dependencies
     checkControlDependencies();
 
+    if ( maPController->getBoolProperty( rtl::OUString( "HideHelpButton" ), sal_False ) )
+        maHelpButton.Hide();
+
     // set initial focus to "Number of copies"
     maJobPage.maCopyCountField.GrabFocus();
     maJobPage.maCopyCountField.SetSelection( Selection(0, 0xFFFF) );
-- 
1.7.11

Attachment: signature.asc
Description: This is a digitally signed message part


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.