Hello,

> > 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.
> 
> I guess we'll leave the other two until your updated patches. Right ?,
> or is 0004 still valid ?

Here is the a new 0003 and 0004 without the bug.

Regards

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


Le lundi 25 juin 2012 à 16:56 +0100, Caolán McNamara a écrit :
> On Tue, 2012-06-19 at 16:05 +0200, Maxime de Roucy wrote:
> > Hello,
> > 
> > Here is some patchs :
> > 0001 : one line, code simplification.
> 
> I've pushed this one anyway.
> 
> > 0002 : explicite NULL or 0 comparison in if. I don't know if LibreOffice
> > have a coding standard about that type of comparison ?
> 
> meh, I don't think we have any coding standards around it. But I'd skip
> this one as in the absence of a coding standard I don't see the value in
> swapping from one equally valid syntax to another.
> 
> > 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.
> 
> I guess we'll leave the other two until your updated patches. Right ?,
> or is 0004 still valid ?
> 
> C.
> 
From 221450ef23f6984a87c7a6ac4ddcc85a7a622c63 Mon Sep 17 00:00:00 2001
From: Maxime de Roucy <mdero...@linagora.com>
Date: Tue, 26 Jun 2012 15:00:38 +0200
Subject: [PATCH 1/2] 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: Ib26399b297aa991e37825f0b3d31574ff1253d4f
---
 sfx2/source/view/viewprn.cxx | 85 ++++++++++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 38 deletions(-)

diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index a8c19a2..fb3b9fd 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,52 @@ 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;
+
+                return;
             }
 
             // 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 +892,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.1

From 3a50cb7b92bc2ed69b61e2f7fe26c1a8af93ee1b Mon Sep 17 00:00:00 2001
From: Maxime de Roucy <mdero...@linagora.com>
Date: Tue, 26 Jun 2012 15:01:35 +0200
Subject: [PATCH 2/2] 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: I02ea6c68dd3de62429e5a11d316981c2b6418bff
---
 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 fb3b9fd..d6e24db 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.1

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

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to