LCOV - code coverage report
Current view: top level - libreoffice/vcl/unx/gtk/gdi - salprn-gtk.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 466 0.0 %
Date: 2012-12-17 Functions: 0 33 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2011 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
      17             :  *  (initial developer)
      18             :  * Copyright (C) 2011 Red Hat, Inc., David Tardon <dtardon@redhat.com> ]
      19             :  *
      20             :  * All Rights Reserved.
      21             :  *
      22             :  * For minor contributions see the git repository.
      23             :  *
      24             :  * Alternatively, the contents of this file may be used under the terms of
      25             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      26             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      27             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      28             :  * instead of those above.
      29             :  */
      30             : 
      31             : #include "gtkprintwrapper.hxx"
      32             : 
      33             : #include "unx/gtk/gtkdata.hxx"
      34             : #include "unx/gtk/gtkframe.hxx"
      35             : #include "unx/gtk/gtkinst.hxx"
      36             : #include "unx/gtk/gtkprn.hxx"
      37             : 
      38             : #include "vcl/configsettings.hxx"
      39             : #include "vcl/help.hxx"
      40             : #include "vcl/print.hxx"
      41             : #include "vcl/svapp.hxx"
      42             : #include "vcl/window.hxx"
      43             : 
      44             : #include <gtk/gtk.h>
      45             : #include <gtk/gtkunixprint.h>
      46             : 
      47             : #include <comphelper/processfactory.hxx>
      48             : 
      49             : #include <com/sun/star/beans/PropertyValue.hpp>
      50             : #include <com/sun/star/container/XNamed.hpp>
      51             : #include <com/sun/star/document/XExporter.hpp>
      52             : #include <com/sun/star/document/XFilter.hpp>
      53             : #include <com/sun/star/frame/XFrame.hpp>
      54             : #include <com/sun/star/io/XOutputStream.hpp>
      55             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      56             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      57             : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
      58             : #include <com/sun/star/view/PrintableState.hpp>
      59             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      60             : 
      61             : #include <officecfg/Office/Common.hxx>
      62             : 
      63             : #include <rtl/ustring.hxx>
      64             : 
      65             : #include <unotools/streamwrap.hxx>
      66             : 
      67             : #include <cstring>
      68             : #include <map>
      69             : 
      70             : namespace frame = com::sun::star::frame;
      71             : namespace beans = com::sun::star::beans;
      72             : namespace container = com::sun::star::container;
      73             : namespace uno = com::sun::star::uno;
      74             : namespace document = com::sun::star::document;
      75             : namespace sheet = com::sun::star::sheet;
      76             : namespace io = com::sun::star::io;
      77             : namespace view = com::sun::star::view;
      78             : 
      79             : using vcl::unx::GtkPrintWrapper;
      80             : 
      81             : using uno::UNO_QUERY;
      82             : 
      83             : class GtkPrintDialog
      84             : {
      85             : public:
      86             :     GtkPrintDialog(vcl::PrinterController& io_rController);
      87             :     bool run();
      88           0 :     GtkPrinter* getPrinter() const
      89             :     {
      90           0 :         return m_pWrapper->print_unix_dialog_get_selected_printer(GTK_PRINT_UNIX_DIALOG(m_pDialog));
      91             :     }
      92           0 :     GtkPrintSettings* getSettings() const
      93             :     {
      94           0 :         return m_pWrapper->print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(m_pDialog));
      95             :     }
      96             :     void updateControllerPrintRange();
      97             : #if 0
      98             :     void ExportAsPDF(const rtl::OUString &rFileURL, GtkPrintSettings* pSettings) const;
      99             : #endif
     100             :     ~GtkPrintDialog();
     101             : 
     102           0 :     static void UIOption_CheckHdl(GtkWidget* i_pWidget, GtkPrintDialog* io_pThis)
     103             :     {
     104           0 :         io_pThis->impl_UIOption_CheckHdl(i_pWidget);
     105           0 :     }
     106           0 :     static void UIOption_RadioHdl(GtkWidget* i_pWidget, GtkPrintDialog* io_pThis)
     107             :     {
     108           0 :         io_pThis->impl_UIOption_RadioHdl(i_pWidget);
     109           0 :     }
     110           0 :     static void UIOption_SelectHdl(GtkWidget* i_pWidget, GtkPrintDialog* io_pThis)
     111             :     {
     112           0 :         io_pThis->impl_UIOption_SelectHdl(i_pWidget);
     113           0 :     }
     114             : 
     115             : private:
     116             :     beans::PropertyValue* impl_queryPropertyValue(GtkWidget* i_pWidget) const;
     117             :     void impl_checkOptionalControlDependencies();
     118             : 
     119             :     void impl_UIOption_CheckHdl(GtkWidget* i_pWidget);
     120             :     void impl_UIOption_RadioHdl(GtkWidget* i_pWidget);
     121             :     void impl_UIOption_SelectHdl(GtkWidget* i_pWidget);
     122             : 
     123             :     void impl_initDialog();
     124             :     void impl_initCustomTab();
     125             :     void impl_initPrintContent(uno::Sequence<sal_Bool> const& i_rDisabled);
     126             : 
     127             :     void impl_readFromSettings();
     128             :     void impl_storeToSettings() const;
     129             : 
     130             : private:
     131             :     GtkWidget* m_pDialog;
     132             :     vcl::PrinterController& m_rController;
     133             :     std::map<GtkWidget*, rtl::OUString> m_aControlToPropertyMap;
     134             :     std::map<GtkWidget*, sal_Int32> m_aControlToNumValMap;
     135             :     boost::shared_ptr<GtkPrintWrapper> m_pWrapper;
     136             : };
     137             : 
     138             : 
     139             : struct GtkSalPrinter_Impl
     140             : {
     141             :     rtl::OString m_sSpoolFile;
     142             :     rtl::OUString m_sJobName;
     143             :     GtkPrinter* m_pPrinter;
     144             :     GtkPrintSettings* m_pSettings;
     145             : 
     146             :     GtkSalPrinter_Impl();
     147             :     ~GtkSalPrinter_Impl();
     148             : };
     149             : 
     150             : 
     151           0 : GtkSalPrinter_Impl::GtkSalPrinter_Impl()
     152             :     : m_pPrinter(0)
     153           0 :     , m_pSettings(0)
     154             : {
     155           0 : }
     156             : 
     157             : 
     158           0 : GtkSalPrinter_Impl::~GtkSalPrinter_Impl()
     159             : {
     160           0 :     if (m_pPrinter)
     161             :     {
     162           0 :         g_object_unref(G_OBJECT(m_pPrinter));
     163           0 :         m_pPrinter = NULL;
     164             :     }
     165           0 :     if (m_pSettings)
     166             :     {
     167           0 :         g_object_unref(G_OBJECT(m_pSettings));
     168           0 :         m_pSettings = NULL;
     169             :     }
     170           0 : }
     171             : 
     172             : namespace
     173             : {
     174             : 
     175             : GtkInstance const&
     176           0 : lcl_getGtkSalInstance()
     177             : {
     178             :     // we _know_ this is GtkInstance
     179           0 :     return *static_cast<GtkInstance*>(GetGtkSalData()->m_pInstance);
     180             : }
     181             : 
     182             : bool
     183           0 : lcl_useSystemPrintDialog()
     184             : {
     185             :     return officecfg::Office::Common::Misc::UseSystemPrintDialog::get()
     186             :         && officecfg::Office::Common::Misc::ExperimentalMode::get()
     187           0 :         && lcl_getGtkSalInstance().getPrintWrapper()->supportsPrinting();
     188             : }
     189             : 
     190             : }
     191             : 
     192           0 : GtkSalPrinter::GtkSalPrinter(SalInfoPrinter* const i_pInfoPrinter)
     193           0 :     : PspSalPrinter(i_pInfoPrinter)
     194             : {
     195           0 : }
     196             : 
     197             : 
     198             : bool
     199           0 : GtkSalPrinter::impl_doJob(
     200             :         const rtl::OUString* const i_pFileName,
     201             :         const rtl::OUString& i_rJobName,
     202             :         const rtl::OUString& i_rAppName,
     203             :         ImplJobSetup* const io_pSetupData,
     204             :         const int i_nCopies,
     205             :         const bool i_bCollate,
     206             :         vcl::PrinterController& io_rController)
     207             : {
     208           0 :     io_rController.setJobState(view::PrintableState_JOB_STARTED);
     209           0 :     io_rController.jobStarted();
     210             :     const bool bJobStarted(
     211             :             PspSalPrinter::StartJob(i_pFileName, i_rJobName, i_rAppName,
     212           0 :                 i_nCopies, i_bCollate, true, io_pSetupData))
     213             :         ;
     214             : 
     215           0 :     if (bJobStarted)
     216             :     {
     217           0 :         io_rController.createProgressDialog();
     218           0 :         const int nPages(io_rController.getFilteredPageCount());
     219           0 :         for (int nPage(0); nPage != nPages; ++nPage)
     220             :         {
     221           0 :             if (nPage == nPages - 1)
     222           0 :                 io_rController.setLastPage(sal_True);
     223           0 :             io_rController.printFilteredPage(nPage);
     224             :         }
     225           0 :         io_rController.setJobState(view::PrintableState_JOB_COMPLETED);
     226             :     }
     227             : 
     228           0 :     return bJobStarted;
     229             : }
     230             : 
     231             : 
     232             : sal_Bool
     233           0 : GtkSalPrinter::StartJob(
     234             :         const rtl::OUString* const i_pFileName,
     235             :         const rtl::OUString& i_rJobName,
     236             :         const rtl::OUString& i_rAppName,
     237             :         ImplJobSetup* io_pSetupData,
     238             :         vcl::PrinterController& io_rController)
     239             : {
     240           0 :     if (!lcl_useSystemPrintDialog())
     241           0 :         return PspSalPrinter::StartJob(i_pFileName, i_rJobName, i_rAppName, io_pSetupData, io_rController);
     242             : 
     243             :     assert(!m_pImpl);
     244             : 
     245           0 :     m_pImpl.reset(new GtkSalPrinter_Impl());
     246           0 :     m_pImpl->m_sJobName = i_rJobName;
     247             : 
     248           0 :     rtl::OString sFileName;
     249           0 :     if (i_pFileName)
     250           0 :         sFileName = rtl::OUStringToOString(*i_pFileName, osl_getThreadTextEncoding());
     251             : 
     252           0 :     GtkPrintDialog aDialog(io_rController);
     253           0 :     if (!aDialog.run())
     254             :     {
     255           0 :         io_rController.abortJob();
     256           0 :         return sal_False;
     257             :     }
     258           0 :     aDialog.updateControllerPrintRange();
     259           0 :     m_pImpl->m_pPrinter = aDialog.getPrinter();
     260           0 :     m_pImpl->m_pSettings = aDialog.getSettings();
     261             : 
     262             : #if 0
     263             :     if (const gchar *uri = gtk_print_settings_get(m_pImpl->m_pSettings, GTK_PRINT_SETTINGS_OUTPUT_URI))
     264             :     {
     265             :         const gchar *pStr = gtk_print_settings_get(m_pImpl->m_pSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
     266             :         if (pStr && !strcmp(pStr, "pdf"))
     267             :         {
     268             :             aDialog.ExportAsPDF(rtl::OUString((const sal_Char *)uri, strlen((const sal_Char *)uri), RTL_TEXTENCODING_UTF8), m_pImpl->m_pSettings);
     269             :             bDoJob = false;
     270             :         }
     271             :     }
     272             : 
     273             :     if (!bDoJob)
     274             :         return false;
     275             : #endif
     276           0 :     int nCopies = 1;
     277           0 :     bool bCollate = false;
     278             : 
     279             :     //To-Do proper name, watch for encodings
     280           0 :     sFileName = rtl::OString("/tmp/hacking.ps");
     281           0 :     m_pImpl->m_sSpoolFile = sFileName;
     282             : 
     283           0 :     rtl::OUString aFileName = rtl::OStringToOUString(sFileName, osl_getThreadTextEncoding());
     284             : 
     285             :     //To-Do, swap ps/pdf for gtk_printer_accepts_ps()/gtk_printer_accepts_pdf() ?
     286             : 
     287           0 :     return impl_doJob(&aFileName, i_rJobName, i_rAppName, io_pSetupData, nCopies, bCollate, io_rController);
     288             : }
     289             : 
     290             : 
     291             : sal_Bool
     292           0 : GtkSalPrinter::EndJob()
     293             : {
     294           0 :     sal_Bool bRet = PspSalPrinter::EndJob();
     295             : 
     296           0 :     if (!lcl_useSystemPrintDialog())
     297           0 :         return bRet;
     298             : 
     299             :     assert(m_pImpl);
     300             : 
     301           0 :     if (!bRet || m_pImpl->m_sSpoolFile.isEmpty())
     302           0 :         return bRet;
     303             : 
     304           0 :     boost::shared_ptr<GtkPrintWrapper> const pWrapper(lcl_getGtkSalInstance().getPrintWrapper());
     305             : 
     306           0 :     GtkPageSetup* pPageSetup = pWrapper->page_setup_new();
     307             : #if 0
     308             :     //todo
     309             :     gtk_page_setup_set_orientation(pPageSetup,);
     310             :     gtk_page_setup_set_paper_size(pPageSetup,);
     311             :     gtk_page_setup_set_top_margin(pPageSetup,);
     312             :     gtk_page_setup_set_bottom_margin(pPageSetup,);
     313             :     gtk_page_setup_set_left_margin(pPageSetup,);
     314             :     gtk_page_setup_set_right_margin(pPageSetup,);
     315             : #endif
     316             : 
     317             :     GtkPrintJob* const pJob = pWrapper->print_job_new(
     318           0 :         rtl::OUStringToOString(m_pImpl->m_sJobName, RTL_TEXTENCODING_UTF8).getStr(),
     319           0 :         m_pImpl->m_pPrinter, m_pImpl->m_pSettings, pPageSetup);
     320             : 
     321           0 :     GError* error = NULL;
     322           0 :     bRet = pWrapper->print_job_set_source_file(pJob, m_pImpl->m_sSpoolFile.getStr(), &error);
     323           0 :     if (bRet)
     324           0 :         pWrapper->print_job_send(pJob, NULL, NULL, NULL);
     325             :     else
     326             :     {
     327             :         //To-Do, do something with this
     328           0 :         fprintf(stderr, "error was %s\n", error->message);
     329           0 :         g_error_free(error);
     330             :     }
     331             : 
     332           0 :     g_object_unref(pPageSetup);
     333           0 :     m_pImpl.reset();
     334             : 
     335             :     //To-Do, remove temp spool file
     336             : 
     337           0 :     return bRet;
     338             : }
     339             : 
     340             : 
     341             : namespace
     342             : {
     343             : 
     344             : void
     345           0 : lcl_setHelpText(
     346             :         GtkWidget* const io_pWidget,
     347             :         const uno::Sequence<rtl::OUString>& i_rHelpTexts,
     348             :         const sal_Int32 i_nIndex)
     349             : {
     350             : #if GTK_CHECK_VERSION(2,12,0)
     351           0 :     if (i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength())
     352             :         gtk_widget_set_tooltip_text(io_pWidget,
     353           0 :             rtl::OUStringToOString(i_rHelpTexts.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8).getStr());
     354             : #else
     355             :     (void)io_pWidget;
     356             :     (void)i_rHelpTexts;
     357             :     (void)i_nIndex;
     358             : #endif
     359           0 : }
     360             : 
     361             : 
     362             : static GtkWidget*
     363           0 : lcl_makeFrame(
     364             :         GtkWidget* const i_pChild,
     365             :         const rtl::OUString &i_rText,
     366             :         const uno::Sequence<rtl::OUString> &i_rHelpTexts,
     367             :         sal_Int32* const io_pCurHelpText)
     368             : {
     369           0 :     GtkWidget* const pLabel = gtk_label_new(NULL);
     370           0 :     lcl_setHelpText(pLabel, i_rHelpTexts, !io_pCurHelpText ? 0 : (*io_pCurHelpText)++);
     371           0 :     gtk_misc_set_alignment(GTK_MISC(pLabel), 0.0, 0.5);
     372             : 
     373             :     {
     374             :         gchar* const pText = g_markup_printf_escaped("<b>%s</b>",
     375           0 :             rtl::OUStringToOString(i_rText, RTL_TEXTENCODING_UTF8).getStr());
     376           0 :         gtk_label_set_markup_with_mnemonic(GTK_LABEL(pLabel), pText);
     377           0 :         g_free(pText);
     378             :     }
     379             : 
     380           0 :     GtkWidget* const pFrame = gtk_vbox_new(FALSE, 6);
     381           0 :     gtk_box_pack_start(GTK_BOX(pFrame), pLabel, FALSE, FALSE, 0);
     382             : 
     383           0 :     GtkWidget* const pAlignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
     384           0 :     gtk_alignment_set_padding(GTK_ALIGNMENT(pAlignment), 0, 0, 12, 0);
     385           0 :     gtk_box_pack_start(GTK_BOX(pFrame), pAlignment, FALSE, FALSE, 0);
     386             : 
     387           0 :     gtk_container_add(GTK_CONTAINER(pAlignment), i_pChild);
     388           0 :     return pFrame;
     389             : }
     390             : 
     391             : void
     392           0 : lcl_extractHelpTextsOrIds(
     393             :         const beans::PropertyValue& rEntry,
     394             :         uno::Sequence<rtl::OUString>& rHelpStrings)
     395             : {
     396           0 :     if (!(rEntry.Value >>= rHelpStrings))
     397             :     {
     398           0 :         rtl::OUString aHelpString;
     399           0 :         if ((rEntry.Value >>= aHelpString))
     400             :         {
     401           0 :             rHelpStrings.realloc(1);
     402           0 :             *rHelpStrings.getArray() = aHelpString;
     403           0 :         }
     404             :     }
     405           0 : }
     406             : 
     407             : GtkWidget*
     408           0 : lcl_combo_box_text_new()
     409             : {
     410             : #if GTK_CHECK_VERSION(3,0,0)
     411             :     return gtk_combo_box_text_new();
     412             : #else
     413           0 :     return gtk_combo_box_new_text();
     414             : #endif
     415             : }
     416             : 
     417             : void
     418           0 : lcl_combo_box_text_append(GtkWidget* const pWidget, gchar const* const pText)
     419             : {
     420             : #if GTK_CHECK_VERSION(3,0,0)
     421             :     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pWidget), pText);
     422             : #else
     423           0 :     gtk_combo_box_append_text(GTK_COMBO_BOX(pWidget), pText);
     424             : #endif
     425           0 : }
     426             : 
     427             : }
     428             : 
     429           0 : GtkPrintDialog::GtkPrintDialog(vcl::PrinterController& io_rController)
     430             :     : m_rController(io_rController)
     431           0 :     , m_pWrapper(lcl_getGtkSalInstance().getPrintWrapper())
     432             : {
     433             :     assert(m_pWrapper->supportsPrinting());
     434           0 :     impl_initDialog();
     435           0 :     impl_initCustomTab();
     436           0 :     impl_readFromSettings();
     437           0 : }
     438             : 
     439             : 
     440             : void
     441           0 : GtkPrintDialog::impl_initDialog()
     442             : {
     443             :     //To-Do, like fpicker, set UI language
     444           0 :     m_pDialog = m_pWrapper->print_unix_dialog_new(NULL, NULL);
     445             : 
     446           0 :     Window* const pTopWindow(Application::GetActiveTopWindow());
     447           0 :     if (pTopWindow)
     448             :     {
     449           0 :         GtkSalFrame* const pFrame(dynamic_cast<GtkSalFrame*>(pTopWindow->ImplGetFrame()));
     450           0 :         if (pFrame)
     451             :         {
     452           0 :             GtkWindow* const pParent(GTK_WINDOW(pFrame->getWindow()));
     453           0 :             if (pParent)
     454           0 :                 gtk_window_set_transient_for(GTK_WINDOW(m_pDialog), pParent);
     455             :         }
     456             :     }
     457             : 
     458           0 :     m_pWrapper->print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(m_pDialog),
     459             :         GtkPrintCapabilities(GTK_PRINT_CAPABILITY_COPIES
     460             :             | GTK_PRINT_CAPABILITY_COLLATE
     461             :             | GTK_PRINT_CAPABILITY_REVERSE
     462             :             | GTK_PRINT_CAPABILITY_GENERATE_PS
     463             : #if GTK_CHECK_VERSION(2,12,0)
     464             :             | GTK_PRINT_CAPABILITY_NUMBER_UP
     465             : #endif
     466             : #if GTK_CHECK_VERSION(2,14,0)
     467             :             | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT
     468             : #endif
     469           0 :        ));
     470           0 : }
     471             : 
     472             : 
     473             : void
     474           0 : GtkPrintDialog::impl_initCustomTab()
     475             : {
     476             :     typedef std::map<rtl::OUString, GtkWidget*> DependencyMap_t;
     477             :     typedef std::vector<std::pair<GtkWidget*, rtl::OUString> > CustomTabs_t;
     478             : 
     479           0 :     const uno::Sequence<beans::PropertyValue>& rOptions(m_rController.getUIOptions());
     480           0 :     DependencyMap_t aPropertyToDependencyRowMap;
     481           0 :     CustomTabs_t aCustomTabs;
     482           0 :     GtkWidget* pCurParent = NULL;
     483           0 :     GtkWidget* pCurTabPage = NULL;
     484           0 :     GtkWidget* pCurSubGroup = NULL;
     485           0 :     GtkWidget* pStandardPrintRangeContainer = NULL;
     486           0 :     bool bIgnoreSubgroup = false;
     487           0 :     for (int i = 0; i != rOptions.getLength(); i++)
     488             :     {
     489           0 :         uno::Sequence<beans::PropertyValue> aOptProp;
     490           0 :         rOptions[i].Value >>= aOptProp;
     491             : 
     492           0 :         rtl::OUString aCtrlType;
     493           0 :         rtl::OUString aText;
     494           0 :         rtl::OUString aPropertyName;
     495           0 :         uno::Sequence<rtl::OUString> aChoices;
     496           0 :         uno::Sequence<sal_Bool> aChoicesDisabled;
     497           0 :         uno::Sequence<rtl::OUString> aHelpTexts;
     498           0 :         sal_Int64 nMinValue = 0, nMaxValue = 0;
     499           0 :         sal_Int32 nCurHelpText = 0;
     500           0 :         rtl::OUString aDependsOnName;
     501           0 :         sal_Int32 nDependsOnValue = 0;
     502           0 :         sal_Bool bUseDependencyRow = sal_False;
     503           0 :         sal_Bool bIgnore = sal_False;
     504           0 :         GtkWidget* pGroup = NULL;
     505           0 :         bool bGtkInternal = false;
     506             : 
     507           0 :         for (int n = 0; n != aOptProp.getLength(); n++)
     508             :         {
     509           0 :             const beans::PropertyValue& rEntry(aOptProp[ n ]);
     510           0 :             if ( rEntry.Name == "Text" )
     511             :             {
     512           0 :                 rtl::OUString aValue;
     513           0 :                 rEntry.Value >>= aValue;
     514           0 :                 aText = aValue.replace('~', '_');
     515             :             }
     516           0 :             else if ( rEntry.Name == "ControlType" )
     517           0 :                 rEntry.Value >>= aCtrlType;
     518           0 :             else if ( rEntry.Name == "Choices" )
     519           0 :                 rEntry.Value >>= aChoices;
     520           0 :             else if ( rEntry.Name == "ChoicesDisabled" )
     521           0 :                 rEntry.Value >>= aChoicesDisabled;
     522           0 :             else if ( rEntry.Name == "Property" )
     523             :             {
     524           0 :                 beans::PropertyValue aVal;
     525           0 :                 rEntry.Value >>= aVal;
     526           0 :                 aPropertyName = aVal.Name;
     527             :             }
     528           0 :             else if ( rEntry.Name == "DependsOnName" )
     529           0 :                 rEntry.Value >>= aDependsOnName;
     530           0 :             else if ( rEntry.Name == "DependsOnEntry" )
     531           0 :                 rEntry.Value >>= nDependsOnValue;
     532           0 :             else if ( rEntry.Name == "AttachToDependency" )
     533           0 :                 rEntry.Value >>= bUseDependencyRow;
     534           0 :             else if ( rEntry.Name == "MinValue" )
     535           0 :                 rEntry.Value >>= nMinValue;
     536           0 :             else if ( rEntry.Name == "MaxValue" )
     537           0 :                 rEntry.Value >>= nMaxValue;
     538           0 :             else if ( rEntry.Name == "HelpId" )
     539             :             {
     540           0 :                 uno::Sequence<rtl::OUString> aHelpIds;
     541           0 :                 lcl_extractHelpTextsOrIds(rEntry, aHelpIds);
     542           0 :                 Help* const pHelp = Application::GetHelp();
     543           0 :                 if (pHelp)
     544             :                 {
     545           0 :                     const int nLen = aHelpIds.getLength();
     546           0 :                     aHelpTexts.realloc(nLen);
     547           0 :                     for (int j = 0; j != nLen; ++j)
     548           0 :                         aHelpTexts[j] = pHelp->GetHelpText(aHelpIds[j], 0);
     549             :                 }
     550             :                 else // fallback
     551           0 :                     aHelpTexts = aHelpIds;
     552             :             }
     553           0 :             else if ( rEntry.Name == "HelpText" )
     554           0 :                 lcl_extractHelpTextsOrIds(rEntry, aHelpTexts);
     555           0 :             else if ( rEntry.Name == "InternalUIOnly" )
     556           0 :                 rEntry.Value >>= bIgnore;
     557           0 :             else if ( rEntry.Name == "Enabled" )
     558             :             {
     559             :                 // Ignore this. We use UIControlOptions::isUIOptionEnabled
     560             :                 // to check whether a control should be enabled.
     561             :             }
     562           0 :             else if ( rEntry.Name == "GroupingHint" )
     563             :             {
     564             :                 // Ignore this. We cannot add/modify controls to/on existing
     565             :                 // tabs of the Gtk print dialog.
     566             :             }
     567             :             else
     568             :             {
     569             :                 SAL_INFO("vcl.gtk", "unhandled UI option entry: " << rEntry.Name);
     570             :             }
     571             :         }
     572             : 
     573           0 :         if ( aPropertyName == "PrintContent" )
     574           0 :             bGtkInternal = true;
     575             : 
     576           0 :         if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Group")) || !pCurParent)
     577             :         {
     578           0 :             pCurTabPage = gtk_vbox_new(FALSE, 12);
     579           0 :             gtk_container_set_border_width(GTK_CONTAINER(pCurTabPage), 6);
     580           0 :             lcl_setHelpText(pCurTabPage, aHelpTexts, 0);
     581             : 
     582           0 :             pCurParent = pCurTabPage;
     583           0 :             aCustomTabs.push_back(std::make_pair(pCurTabPage, aText));
     584             :         }
     585           0 :         else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) && (pCurParent /*|| bOnJobPageValue*/))
     586             :         {
     587           0 :             bIgnoreSubgroup = bIgnore;
     588           0 :             if (bIgnore)
     589           0 :                 continue;
     590           0 :             pCurParent = gtk_vbox_new(FALSE, 12);
     591           0 :             gtk_container_set_border_width(GTK_CONTAINER(pCurParent), 0);
     592             : 
     593           0 :             pCurSubGroup = lcl_makeFrame(pCurParent, aText, aHelpTexts, NULL);
     594           0 :             gtk_box_pack_start(GTK_BOX(pCurTabPage), pCurSubGroup, FALSE, FALSE, 0);
     595             :         }
     596             :         // special case: we need to map these to controls of the gtk print dialog
     597           0 :         else if (bGtkInternal)
     598             :         {
     599           0 :             if ( aPropertyName == "PrintContent" )
     600             :             {
     601             :                 // What to print? And, more importantly, is there a selection?
     602           0 :                 impl_initPrintContent(aChoicesDisabled);
     603             :             }
     604             :         }
     605           0 :         else if (bIgnoreSubgroup || bIgnore)
     606           0 :             continue;
     607             :         else
     608             :         {
     609             :             // change handlers for all the controls set up in this block
     610             :             // should be set _after_ the control has been made (in)active,
     611             :             // because:
     612             :             // 1. value of the property is _known_--we are using it to
     613             :             //    _set_ the control, right?--no need to change it back .-)
     614             :             // 2. it may cause warning because the widget may not
     615             :             //    have been placed in m_aControlToPropertyMap yet
     616             : 
     617           0 :             GtkWidget* pWidget = NULL;
     618           0 :             beans::PropertyValue* pVal = NULL;
     619           0 :             if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Bool")) && pCurParent)
     620             :             {
     621             :                 pWidget = gtk_check_button_new_with_mnemonic(
     622           0 :                     rtl::OUStringToOString(aText, RTL_TEXTENCODING_UTF8).getStr());
     623           0 :                 lcl_setHelpText(pWidget, aHelpTexts, 0);
     624           0 :                 m_aControlToPropertyMap[pWidget] = aPropertyName;
     625             : 
     626           0 :                 sal_Bool bVal = sal_False;
     627           0 :                 pVal = m_rController.getValue(aPropertyName);
     628           0 :                 if (pVal)
     629           0 :                     pVal->Value >>= bVal;
     630           0 :                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pWidget), bVal);
     631             :                 gtk_widget_set_sensitive(pWidget,
     632           0 :                     m_rController.isUIOptionEnabled(aPropertyName) && pVal != NULL);
     633           0 :                 g_signal_connect(pWidget, "toggled", G_CALLBACK(GtkPrintDialog::UIOption_CheckHdl), this);
     634             :             }
     635           0 :             else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Radio")) && pCurParent)
     636             :             {
     637           0 :                 GtkWidget* const pVbox = gtk_vbox_new(FALSE, 12);
     638           0 :                 gtk_container_set_border_width(GTK_CONTAINER(pVbox), 0);
     639             : 
     640           0 :                 if (!aText.isEmpty())
     641           0 :                     pGroup = lcl_makeFrame(pVbox, aText, aHelpTexts, &nCurHelpText);
     642             : 
     643           0 :                 sal_Int32 nSelectVal = 0;
     644           0 :                 pVal = m_rController.getValue(aPropertyName);
     645           0 :                 if (pVal && pVal->Value.hasValue())
     646           0 :                     pVal->Value >>= nSelectVal;
     647             : 
     648           0 :                 for (sal_Int32 m = 0; m != aChoices.getLength(); m++)
     649             :                 {
     650             :                     pWidget = gtk_radio_button_new_with_mnemonic_from_widget(
     651           0 :                         GTK_RADIO_BUTTON(m == 0 ? NULL : pWidget),
     652           0 :                         rtl::OUStringToOString(aChoices[m].replace('~', '_'), RTL_TEXTENCODING_UTF8).getStr());
     653           0 :                     lcl_setHelpText(pWidget, aHelpTexts, nCurHelpText++);
     654           0 :                     m_aControlToPropertyMap[pWidget] = aPropertyName;
     655           0 :                     m_aControlToNumValMap[pWidget] = m;
     656           0 :                     GtkWidget* const pRow = gtk_hbox_new(FALSE, 12);
     657           0 :                     gtk_box_pack_start(GTK_BOX(pVbox), pRow, FALSE, FALSE, 0);
     658           0 :                     gtk_box_pack_start(GTK_BOX(pRow), pWidget, FALSE, FALSE, 0);
     659           0 :                     aPropertyToDependencyRowMap[aPropertyName + rtl::OUString::valueOf(m)] = pRow;
     660           0 :                     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pWidget), m == nSelectVal);
     661             :                     gtk_widget_set_sensitive(pWidget,
     662           0 :                         m_rController.isUIOptionEnabled(aPropertyName) && pVal != NULL);
     663           0 :                     g_signal_connect(pWidget, "toggled",
     664           0 :                             G_CALLBACK(GtkPrintDialog::UIOption_RadioHdl), this);
     665             :                 }
     666             : 
     667           0 :                 if (pGroup)
     668           0 :                     pWidget = pGroup;
     669             :                 else
     670           0 :                     pWidget = pVbox;
     671             :             }
     672           0 :             else if ((aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("List"))   ||
     673           0 :                        aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range"))  ||
     674           0 :                        aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit"))
     675             :                     ) && pCurParent)
     676             :             {
     677           0 :                 GtkWidget* const pHbox = gtk_hbox_new(FALSE, 12);
     678           0 :                 gtk_container_set_border_width(GTK_CONTAINER(pHbox), 0);
     679             : 
     680           0 :                 if ( aCtrlType == "List" )
     681             :                 {
     682           0 :                    pWidget = lcl_combo_box_text_new();
     683             : 
     684           0 :                    for (sal_Int32 m = 0; m != aChoices.getLength(); m++)
     685             :                    {
     686             :                        lcl_combo_box_text_append(pWidget,
     687           0 :                            rtl::OUStringToOString(aChoices[m], RTL_TEXTENCODING_UTF8).getStr());
     688             :                    }
     689             : 
     690           0 :                    sal_Int32 nSelectVal = 0;
     691           0 :                    pVal = m_rController.getValue(aPropertyName);
     692           0 :                    if (pVal && pVal->Value.hasValue())
     693           0 :                        pVal->Value >>= nSelectVal;
     694           0 :                    gtk_combo_box_set_active(GTK_COMBO_BOX(pWidget), nSelectVal);
     695           0 :                    g_signal_connect(pWidget, "changed", G_CALLBACK(GtkPrintDialog::UIOption_SelectHdl), this);
     696             :                 }
     697           0 :                 else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit")) && pCurParent)
     698             :                 {
     699           0 :                    pWidget = gtk_entry_new();
     700             : 
     701           0 :                    rtl::OUString aCurVal;
     702           0 :                    pVal = m_rController.getValue(aPropertyName);
     703           0 :                    if (pVal && pVal->Value.hasValue())
     704           0 :                        pVal->Value >>= aCurVal;
     705           0 :                    gtk_entry_set_text(GTK_ENTRY(pWidget),
     706           0 :                        rtl::OUStringToOString(aCurVal, RTL_TEXTENCODING_UTF8).getStr());
     707             :                 }
     708           0 :                 else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range")) && pCurParent)
     709             :                 {
     710           0 :                     pWidget = gtk_spin_button_new_with_range(nMinValue, nMaxValue, 1.0);
     711             : 
     712           0 :                     sal_Int64 nCurVal = 0;
     713           0 :                     pVal = m_rController.getValue(aPropertyName);
     714           0 :                     if (pVal && pVal->Value.hasValue())
     715           0 :                         pVal->Value >>= nCurVal;
     716           0 :                     gtk_spin_button_set_value(GTK_SPIN_BUTTON(pWidget), nCurVal);
     717             :                 }
     718             : 
     719           0 :                 lcl_setHelpText(pWidget, aHelpTexts, 0);
     720           0 :                 m_aControlToPropertyMap[pWidget] = aPropertyName;
     721             : 
     722             :                 gtk_widget_set_sensitive(pWidget,
     723           0 :                     m_rController.isUIOptionEnabled(aPropertyName) && pVal != NULL);
     724             : 
     725           0 :                 if (!aText.isEmpty())
     726             :                 {
     727             :                     GtkWidget* const pLabel = gtk_label_new_with_mnemonic(
     728           0 :                         rtl::OUStringToOString(aText, RTL_TEXTENCODING_UTF8).getStr());
     729           0 :                     gtk_label_set_mnemonic_widget(GTK_LABEL(pLabel), pWidget);
     730           0 :                     gtk_box_pack_start(GTK_BOX(pHbox), pLabel, FALSE, FALSE, 0);
     731             :                 }
     732             : 
     733           0 :                 gtk_box_pack_start(GTK_BOX(pHbox), pWidget, FALSE, FALSE, 0);
     734             : 
     735           0 :                 pWidget = pHbox;
     736             : 
     737             :             }
     738             :             else
     739             :                 SAL_INFO("vcl.gtk", "unhandled option type: " << aCtrlType);
     740             : 
     741           0 :             GtkWidget* pRow = NULL;
     742           0 :             if (pWidget)
     743             :             {
     744           0 :                 if (bUseDependencyRow && !aDependsOnName.isEmpty())
     745             :                 {
     746           0 :                     pRow = aPropertyToDependencyRowMap[aDependsOnName + rtl::OUString::valueOf(nDependsOnValue)];
     747           0 :                     if (!pRow)
     748             :                     {
     749           0 :                         gtk_widget_destroy(pWidget);
     750           0 :                         pWidget = NULL;
     751             :                     }
     752             :                 }
     753             :             }
     754           0 :             if (pWidget)
     755             :             {
     756           0 :                 if (!pRow)
     757             :                 {
     758           0 :                     pRow = gtk_hbox_new(FALSE, 12);
     759           0 :                     gtk_box_pack_start(GTK_BOX(pCurParent), pRow, FALSE, FALSE, 0);
     760             :                 }
     761           0 :                 if (!pGroup)
     762           0 :                     aPropertyToDependencyRowMap[aPropertyName + rtl::OUString::valueOf(sal_Int32(0))] = pRow;
     763           0 :                 gtk_box_pack_start(GTK_BOX(pRow), pWidget, FALSE, FALSE, 0);
     764             :             }
     765             :         }
     766           0 :     }
     767             : 
     768           0 :     if (pStandardPrintRangeContainer)
     769           0 :         gtk_widget_destroy(pStandardPrintRangeContainer);
     770             : 
     771           0 :     CustomTabs_t::const_reverse_iterator aEnd = aCustomTabs.rend();
     772           0 :     for (CustomTabs_t::const_reverse_iterator aI = aCustomTabs.rbegin(); aI != aEnd; ++aI)
     773             :     {
     774           0 :         gtk_widget_show_all(aI->first);
     775           0 :         m_pWrapper->print_unix_dialog_add_custom_tab(GTK_PRINT_UNIX_DIALOG(m_pDialog), aI->first,
     776           0 :             gtk_label_new(rtl::OUStringToOString(aI->second, RTL_TEXTENCODING_UTF8).getStr()));
     777           0 :     }
     778           0 : }
     779             : 
     780             : 
     781             : void
     782           0 : GtkPrintDialog::impl_initPrintContent(uno::Sequence<sal_Bool> const& i_rDisabled)
     783             : {
     784             :     SAL_WARN_IF(i_rDisabled.getLength() != 3, "vcl.gtk", "there is more choices than we expected");
     785           0 :     if (i_rDisabled.getLength() != 3)
     786           0 :         return;
     787             : 
     788           0 :     GtkPrintUnixDialog* const pDialog(GTK_PRINT_UNIX_DIALOG(m_pDialog));
     789             : 
     790             :     // XXX: This is a hack that depends on the number and the ordering of
     791             :     // the controls in the rDisabled sequence (cf. the intialization of
     792             :     // the "PrintContent" UI option in SwPrintUIOptions::SwPrintUIOptions,
     793             :     // sw/source/core/view/printdata.cxx)
     794           0 :     if (m_pWrapper->supportsPrintSelection() && !i_rDisabled[2])
     795             :     {
     796           0 :         m_pWrapper->print_unix_dialog_set_support_selection(pDialog, TRUE);
     797           0 :         m_pWrapper->print_unix_dialog_set_has_selection(pDialog, TRUE);
     798             :     }
     799             : 
     800             :     beans::PropertyValue* const pPrintContent(
     801           0 :             m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintContent"))));
     802             : 
     803           0 :     if (pPrintContent)
     804             :     {
     805           0 :         sal_Int32 nSelectionType(0);
     806           0 :         pPrintContent->Value >>= nSelectionType;
     807           0 :         GtkPrintSettings* const pSettings(getSettings());
     808           0 :         GtkPrintPages ePrintPages(GTK_PRINT_PAGES_ALL);
     809           0 :         switch (nSelectionType)
     810             :         {
     811             :             case 0:
     812           0 :                 ePrintPages = GTK_PRINT_PAGES_ALL;
     813           0 :                 break;
     814             :             case 1:
     815           0 :                 ePrintPages = GTK_PRINT_PAGES_RANGES;
     816           0 :                 break;
     817             :             case 2:
     818             : #if GTK_CHECK_VERSION(2,14,0)
     819           0 :                 if (m_pWrapper->supportsPrintSelection())
     820           0 :                     ePrintPages = GTK_PRINT_PAGES_SELECTION;
     821             :                 else
     822             : #endif
     823             :                     SAL_INFO("vcl.gtk", "the application wants to print a selection, but the present gtk version does not support it");
     824           0 :                 break;
     825             :             default:
     826             :                 SAL_WARN("vcl.gtk", "unexpected selection type: " << nSelectionType);
     827             :         }
     828           0 :         m_pWrapper->print_settings_set_print_pages(pSettings, ePrintPages);
     829           0 :         m_pWrapper->print_unix_dialog_set_settings(pDialog, pSettings);
     830           0 :         g_object_unref(G_OBJECT(pSettings));
     831             :     }
     832             : }
     833             : 
     834             : 
     835             : void
     836           0 : GtkPrintDialog::impl_checkOptionalControlDependencies()
     837             : {
     838           0 :     for (std::map<GtkWidget*, rtl::OUString>::iterator it = m_aControlToPropertyMap.begin();
     839           0 :          it != m_aControlToPropertyMap.end(); ++it)
     840             :     {
     841           0 :         gtk_widget_set_sensitive(it->first, m_rController.isUIOptionEnabled(it->second));
     842             :     }
     843           0 : }
     844             : 
     845             : 
     846             : beans::PropertyValue*
     847           0 : GtkPrintDialog::impl_queryPropertyValue(GtkWidget* const i_pWidget) const
     848             : {
     849           0 :     beans::PropertyValue* pVal(0);
     850           0 :     std::map<GtkWidget*, rtl::OUString>::const_iterator aIt(m_aControlToPropertyMap.find(i_pWidget));
     851           0 :     if (aIt != m_aControlToPropertyMap.end())
     852             :     {
     853           0 :         pVal = m_rController.getValue(aIt->second);
     854             :         SAL_WARN_IF(!pVal, "vcl.gtk", "property value not found");
     855             :     }
     856             :     else
     857             :     {
     858             :         SAL_WARN("vcl.gtk", "changed control not in property map");
     859             :     }
     860           0 :     return pVal;
     861             : }
     862             : 
     863             : 
     864             : void
     865           0 : GtkPrintDialog::impl_UIOption_CheckHdl(GtkWidget* const i_pWidget)
     866             : {
     867           0 :     beans::PropertyValue* const pVal = impl_queryPropertyValue(i_pWidget);
     868           0 :     if (pVal)
     869             :     {
     870           0 :         const bool bVal = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(i_pWidget));
     871           0 :         pVal->Value <<= bVal;
     872             : 
     873           0 :         impl_checkOptionalControlDependencies();
     874             :     }
     875           0 : }
     876             : 
     877             : 
     878             : void
     879           0 : GtkPrintDialog::impl_UIOption_RadioHdl(GtkWidget* const i_pWidget)
     880             : {
     881           0 :     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(i_pWidget)))
     882             :     {
     883           0 :         beans::PropertyValue* const pVal = impl_queryPropertyValue(i_pWidget);
     884           0 :         std::map<GtkWidget*, sal_Int32>::const_iterator it = m_aControlToNumValMap.find(i_pWidget);
     885           0 :         if (pVal && it != m_aControlToNumValMap.end())
     886             :         {
     887             : 
     888           0 :             const sal_Int32 nVal = it->second;
     889           0 :             pVal->Value <<= nVal;
     890             : 
     891           0 :             impl_checkOptionalControlDependencies();
     892             :         }
     893             :     }
     894           0 : }
     895             : 
     896             : 
     897             : void
     898           0 : GtkPrintDialog::impl_UIOption_SelectHdl(GtkWidget* const i_pWidget)
     899             : {
     900           0 :     beans::PropertyValue* const pVal = impl_queryPropertyValue(i_pWidget);
     901           0 :     if (pVal)
     902             :     {
     903           0 :         const sal_Int32 nVal(gtk_combo_box_get_active(GTK_COMBO_BOX(i_pWidget)));
     904           0 :         pVal->Value <<= nVal;
     905             : 
     906           0 :         impl_checkOptionalControlDependencies();
     907             :     }
     908           0 : }
     909             : 
     910             : 
     911             : bool
     912           0 : GtkPrintDialog::run()
     913             : {
     914           0 :     bool bDoJob = false;
     915           0 :     bool bContinue = true;
     916           0 :     while (bContinue)
     917             :     {
     918           0 :         bContinue = false;
     919           0 :         const gint nStatus = gtk_dialog_run(GTK_DIALOG(m_pDialog));
     920           0 :         switch (nStatus)
     921             :         {
     922             :             case GTK_RESPONSE_HELP:
     923           0 :                 fprintf(stderr, "To-Do: Help ?\n");
     924           0 :                 bContinue = true;
     925           0 :                 break;
     926             :             case GTK_RESPONSE_OK:
     927           0 :                 bDoJob = true;
     928           0 :                 break;
     929             :             default:
     930           0 :                 break;
     931             :         }
     932             :     }
     933           0 :     gtk_widget_hide(m_pDialog);
     934           0 :     impl_storeToSettings();
     935           0 :     return bDoJob;
     936             : }
     937             : 
     938             : #if 0
     939             : void GtkPrintDialog::ExportAsPDF(const rtl::OUString &rFileURL, GtkPrintSettings *pSettings) const
     940             : {
     941             :     uno::Reference < XFramesSupplier > xDesktop =
     942             :             uno::Reference < XFramesSupplier >(
     943             :     ::comphelper::getProcessServiceFactory()->
     944             :         createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))), UNO_QUERY);
     945             :     uno::Reference < XFrame > xFrame(xDesktop->getActiveFrame());
     946             :     if (!xFrame.is())
     947             :         xFrame = uno::Reference < XFrame >(xDesktop, UNO_QUERY);
     948             : 
     949             :     uno::Reference < XFilter > xFilter(
     950             :         ::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.PDFFilter"))),
     951             :         UNO_QUERY);
     952             : 
     953             :     if (xFilter.is())
     954             :     {
     955             :         uno::Reference< XController > xController;
     956             :         uno::Reference< XComponent > xDoc;
     957             :         if (xFrame.is())
     958             :             xController = xFrame->getController();
     959             :         if (xController.is())
     960             :             xDoc = uno::Reference< XComponent >(xController->getModel(), UNO_QUERY);
     961             : 
     962             :         SvFileStream aStream(rFileURL, STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC);
     963             :         uno::Reference< XOutputStream > xOStm(new utl::OOutputStreamWrapper(aStream));
     964             : 
     965             :         uno::Reference< XExporter > xExport(xFilter, UNO_QUERY);
     966             :         xExport->setSourceDocument(xDoc);
     967             :         uno::Sequence<beans::PropertyValue> aFilterData(2);
     968             :         aFilterData[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageLayout"));
     969             :         aFilterData[0].Value <<= sal_Int32(0);
     970             :         aFilterData[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FirstPageOnLeft"));
     971             :         aFilterData[1].Value <<= sal_False;
     972             : 
     973             : 
     974             :         const gchar *pStr = gtk_print_settings_get(pSettings, GTK_PRINT_SETTINGS_PRINT_PAGES);
     975             :         if (pStr && !strcmp(pStr, "ranges"))
     976             :         {
     977             :             String aRangeText;
     978             :             gint num_ranges;
     979             :             const GtkPageRange* pRanges = gtk_print_settings_get_page_ranges(pSettings, &num_ranges);
     980             :             for (gint i = 0; i < num_ranges; ++i)
     981             :             {
     982             :                 aRangeText.Append(String::CreateFromInt32(pRanges[i].start+1));
     983             :                 if (pRanges[i].start != pRanges[i].end)
     984             :                 {
     985             :                     aRangeText.AppendAscii("-");
     986             :                     aRangeText.Append(String::CreateFromInt32(pRanges[i].end+1));
     987             :                 }
     988             : 
     989             :                 if (i != num_ranges-1)
     990             :                     aRangeText.AppendAscii(",");
     991             :             }
     992             :             aFilterData.realloc(aFilterData.getLength()+1);
     993             :             aFilterData[aFilterData.getLength()-1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageRange"));
     994             :             aFilterData[aFilterData.getLength()-1].Value <<= rtl::OUString(aRangeText);
     995             :         }
     996             :         else if (pStr && !strcmp(pStr, "current"))
     997             :         {
     998             :             try
     999             :             {
    1000             :                    uno::Reference< XSpreadsheetView > xSpreadsheetView;
    1001             :                    uno::Reference< XSpreadsheet> xSheet;
    1002             :                    uno::Reference< XSpreadsheetDocument > xSheetDoc;
    1003             :                    uno::Reference< XIndexAccess > xSheets;
    1004             :                    uno::Reference< XNamed > xName;
    1005             : 
    1006             :                    if (xController.is())
    1007             :                        xSpreadsheetView = uno::Reference< XSpreadsheetView >(xController, UNO_QUERY);
    1008             :                    if (xSpreadsheetView.is())
    1009             :                        xSheet = uno::Reference< XSpreadsheet>(xSpreadsheetView->getActiveSheet());
    1010             :                    if (xSheet.is())
    1011             :                        xName = uno::Reference < XNamed >(xSheet, UNO_QUERY);
    1012             :                    if (xName.is())
    1013             :                        xSheetDoc = uno::Reference< XSpreadsheetDocument >(xController->getModel(), UNO_QUERY);
    1014             :                    if (xSheetDoc.is())
    1015             :                        xSheets = uno::Reference< XIndexAccess >(xSheetDoc->getSheets(), UNO_QUERY);
    1016             :                    if (xSheets.is())
    1017             :                    {
    1018             :                        const rtl::OUString &rName = xName->getName();
    1019             : 
    1020             :                        sal_Int32 i;
    1021             : 
    1022             :                        for (i = 0; i < xSheets->getCount(); ++i)
    1023             :                        {
    1024             :                            uno::Reference < XNamed > xItem =
    1025             :                                uno::Reference < XNamed >(xSheets->getByIndex(i), UNO_QUERY);
    1026             :                            if (rName == xItem->getName())
    1027             :                                break;
    1028             :                        }
    1029             : 
    1030             :                        if (i < xSheets->getCount())
    1031             :                        {
    1032             :                             aFilterData.realloc(aFilterData.getLength()+1);
    1033             :                             aFilterData[aFilterData.getLength()-1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageRange"));
    1034             :                             aFilterData[aFilterData.getLength()-1].Value <<= rtl::OUString(String::CreateFromInt32(i + 1));
    1035             :                        }
    1036             :                    }
    1037             :             }
    1038             :             catch (...) {}
    1039             :         }
    1040             : #if GTK_CHECK_VERSION(2,17,5)
    1041             :         if (gtk_print_unix_dialog_get_has_selection(GTK_PRINT_UNIX_DIALOG(m_pDialog)))
    1042             :         {
    1043             :             uno::Any aSelection;
    1044             :             try
    1045             :             {
    1046             :                 if (xController.is())
    1047             :                 {
    1048             :                     uno::Reference<view::XSelectionSupplier> xView(xController, UNO_QUERY);
    1049             :                     if (xView.is())
    1050             :                         xView->getSelection() >>= aSelection;
    1051             :                 }
    1052             :             }
    1053             :             catch (const uno::RuntimeException &)
    1054             :             {
    1055             :             }
    1056             :             if (aSelection.hasValue())
    1057             :             {
    1058             :                 aFilterData.realloc(aFilterData.getLength()+1);
    1059             :                 aFilterData[aFilterData.getLength()-1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Selection"));
    1060             :                 aFilterData[aFilterData.getLength()-1].Value <<= aSelection;
    1061             :             }
    1062             :         }
    1063             : #endif
    1064             :         uno::Sequence<beans::PropertyValue> aArgs(2);
    1065             :         aArgs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FilterData"));
    1066             :         aArgs[0].Value <<= aFilterData;
    1067             :         aArgs[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutputStream"));
    1068             :         aArgs[1].Value <<= xOStm;
    1069             :         xFilter->filter(aArgs);
    1070             :     }
    1071             : }
    1072             : #endif
    1073             : 
    1074             : 
    1075             : void
    1076           0 : GtkPrintDialog::updateControllerPrintRange()
    1077             : {
    1078           0 :     GtkPrintSettings* const pSettings(getSettings());
    1079             :     // TODO: use get_print_pages
    1080           0 :     if (const gchar* const pStr = m_pWrapper->print_settings_get(pSettings, GTK_PRINT_SETTINGS_PRINT_PAGES))
    1081             :     {
    1082           0 :         beans::PropertyValue* pVal = m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintRange")));
    1083           0 :         if (!pVal)
    1084           0 :             pVal = m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintContent")));
    1085             :         SAL_WARN_IF(!pVal, "vcl.gtk", "Nothing to map standard print options to!");
    1086           0 :         if (pVal)
    1087             :         {
    1088           0 :             sal_Int32 nVal = 0;
    1089           0 :             if (!strcmp(pStr, "all"))
    1090           0 :                 nVal = 0;
    1091           0 :             else if (!strcmp(pStr, "ranges"))
    1092           0 :                 nVal = 1;
    1093           0 :             else if (!strcmp(pStr, "selection"))
    1094           0 :                 nVal = 2;
    1095           0 :             pVal->Value <<= nVal;
    1096             : 
    1097           0 :             if (nVal == 1)
    1098             :             {
    1099           0 :                 pVal = m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageRange")));
    1100             :                 SAL_WARN_IF(!pVal, "vcl.gtk", "PageRange doesn't exist!");
    1101           0 :                 if (pVal)
    1102             :                 {
    1103           0 :                     rtl::OUStringBuffer sBuf;
    1104             :                     gint num_ranges;
    1105           0 :                     const GtkPageRange* const pRanges = m_pWrapper->print_settings_get_page_ranges(pSettings, &num_ranges);
    1106           0 :                     for (gint i = 0; i != num_ranges && pRanges; ++i)
    1107             :                     {
    1108           0 :                         sBuf.append(sal_Int32(pRanges[i].start+1));
    1109           0 :                         if (pRanges[i].start != pRanges[i].end)
    1110             :                         {
    1111           0 :                             sBuf.append(sal_Unicode('-'));
    1112           0 :                             sBuf.append(sal_Int32(pRanges[i].end+1));
    1113             :                         }
    1114             : 
    1115           0 :                         if (i != num_ranges-1)
    1116           0 :                             sBuf.append(sal_Unicode(','));
    1117             :                     }
    1118           0 :                     pVal->Value <<= sBuf.makeStringAndClear();
    1119             :                 }
    1120             :             }
    1121             :         }
    1122             :     }
    1123           0 :     g_object_unref(G_OBJECT(pSettings));
    1124           0 : }
    1125             : 
    1126             : 
    1127           0 : GtkPrintDialog::~GtkPrintDialog()
    1128             : {
    1129           0 :     gtk_widget_destroy(m_pDialog);
    1130           0 : }
    1131             : 
    1132             : 
    1133             : void
    1134           0 : GtkPrintDialog::impl_readFromSettings()
    1135             : {
    1136           0 :     vcl::SettingsConfigItem* const pItem(vcl::SettingsConfigItem::get());
    1137           0 :     GtkPrintSettings* const pSettings(getSettings());
    1138             : 
    1139           0 :     const rtl::OUString aPrintDialogStr(RTL_CONSTASCII_USTRINGPARAM("PrintDialog"));
    1140             :     const rtl::OUString aCopyCount(pItem->getValue(aPrintDialogStr,
    1141           0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CopyCount"))));
    1142             :     const rtl::OUString aCollate(pItem->getValue(aPrintDialogStr,
    1143           0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Collate"))));
    1144             : 
    1145           0 :     bool bChanged(false);
    1146             : 
    1147           0 :     const gint nOldCopyCount(m_pWrapper->print_settings_get_n_copies(pSettings));
    1148           0 :     const sal_Int32 nCopyCount(aCopyCount.toInt32());
    1149           0 :     if (nCopyCount > 0 && nOldCopyCount != nCopyCount)
    1150             :     {
    1151           0 :         bChanged = true;
    1152           0 :         m_pWrapper->print_settings_set_n_copies(pSettings, sal::static_int_cast<gint>(nCopyCount));
    1153             :     }
    1154             : 
    1155           0 :     const gboolean bOldCollate(m_pWrapper->print_settings_get_collate(pSettings));
    1156           0 :     const bool bCollate(aCollate.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")));
    1157           0 :     if (bOldCollate != bCollate)
    1158             :     {
    1159           0 :         bChanged = true;
    1160           0 :         m_pWrapper->print_settings_set_collate(pSettings, bCollate);
    1161             :     }
    1162             :     // TODO: wth was this var. meant for?
    1163             :     (void) bChanged;
    1164             : 
    1165           0 :     m_pWrapper->print_unix_dialog_set_settings(GTK_PRINT_UNIX_DIALOG(m_pDialog), pSettings);
    1166           0 :     g_object_unref(G_OBJECT(pSettings));
    1167           0 : }
    1168             : 
    1169             : 
    1170             : void
    1171           0 : GtkPrintDialog::impl_storeToSettings()
    1172             : const
    1173             : {
    1174           0 :     vcl::SettingsConfigItem* const pItem(vcl::SettingsConfigItem::get());
    1175           0 :     GtkPrintSettings* const pSettings(getSettings());
    1176             : 
    1177           0 :     const rtl::OUString aPrintDialogStr(RTL_CONSTASCII_USTRINGPARAM("PrintDialog"));
    1178             :     pItem->setValue(aPrintDialogStr,
    1179             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CopyCount")),
    1180           0 :             rtl::OUString::valueOf(sal_Int32(m_pWrapper->print_settings_get_n_copies(pSettings))));
    1181             :     pItem->setValue(aPrintDialogStr,
    1182             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Collate")),
    1183           0 :             m_pWrapper->print_settings_get_collate(pSettings)
    1184             :                 ? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))
    1185           0 :                 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false")))
    1186           0 :         ;
    1187             :     // pItem->setValue(aPrintDialog, rtl::OUString::createFromAscii("ToFile"), );
    1188           0 :     g_object_unref(G_OBJECT(pSettings));
    1189           0 :     pItem->Commit();
    1190           0 : }
    1191             : 
    1192             : 
    1193             : sal_uLong
    1194           0 : GtkSalInfoPrinter::GetCapabilities(
    1195             :         const ImplJobSetup* const i_pSetupData,
    1196             :         const sal_uInt16 i_nType)
    1197             : {
    1198           0 :     if (i_nType == PRINTER_CAPABILITIES_EXTERNALDIALOG && lcl_useSystemPrintDialog())
    1199           0 :         return 1;
    1200           0 :     return PspSalInfoPrinter::GetCapabilities(i_pSetupData, i_nType);
    1201             : }
    1202             : 
    1203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10