From 9dab7eeac8176a28f7176c0e93e8776ad01a13bc Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Wed, 28 Mar 2012 14:03:46 +0200
Subject: [PATCH] set correct paper tray in UI

---
 vcl/source/gdi/print3.cxx |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index cd1cb51..51e4da2 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -172,9 +172,25 @@ public:
     // set by user through printer config dialog
     // if set, pages are centered and trimmed onto the fixed page
     Size                                                        maFixedPageSize;
+    // set by user through printer config dialog
     sal_Int32                                                   mnDefaultPaperBin;
+    // Set by user through printer preferences in print dialog.
+    // Overrides application-set tray for a page.
     sal_Int32                                                   mnFixedPaperBin;
 
+    // N.B. Apparently we have three levels of paper tray settings
+    // (latter overrides former):
+    // 1. default tray
+    // 2. tray set for a concrete page by an application, e.g., writer
+    //    allows setting a printer tray (for the default printer) for a
+    //    page style. This setting can be overriden by user by selecting
+    //    "Use only paper tray from printer preferences" on the Options
+    //    page in the print dialog, in which case the default tray is
+    //    used for all pages.
+    // 3. tray set in printer properties the printer dialog
+    // I'm not quite sure why 1. and 3. are distinct, but the commit
+    // history suggests this is intentional...
+
     ImplPrinterControllerData() :
         mbFirstPage( sal_True ),
         mbLastPage( sal_False ),
@@ -818,6 +834,11 @@ PrinterController::PageSize vcl::ImplPrinterControllerData::modifyJobSetup( cons
             mpPrinter->SetPaperSizeUser( aRealPaperSize, ! isFixedPageSize() );
     }
 
+    // paper bin set from properties in print dialog overrides
+    // application default for a page
+    if ( mnFixedPaperBin != -1 )
+        nPaperBin = mnFixedPaperBin;
+
     if( nPaperBin != -1 && nPaperBin != mpPrinter->GetPaperBin() )
         mpPrinter->SetPaperBin( nPaperBin );
 
-- 
1.7.10.4

