LCOV - code coverage report
Current view: top level - vcl/unx/gtk/gdi - salprn-gtk.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 466 0.0 %
Date: 2012-08-25 Functions: 0 33 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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/oustringostreaminserter.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                 :          0 :     if (i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength())
     351                 :            :         gtk_widget_set_tooltip_text(io_pWidget,
     352                 :          0 :             rtl::OUStringToOString(i_rHelpTexts.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8).getStr());
     353                 :          0 : }
     354                 :            : 
     355                 :            : 
     356                 :            : static GtkWidget*
     357                 :          0 : lcl_makeFrame(
     358                 :            :         GtkWidget* const i_pChild,
     359                 :            :         const rtl::OUString &i_rText,
     360                 :            :         const uno::Sequence<rtl::OUString> &i_rHelpTexts,
     361                 :            :         sal_Int32* const io_pCurHelpText)
     362                 :            : {
     363                 :          0 :     GtkWidget* const pLabel = gtk_label_new(NULL);
     364                 :          0 :     lcl_setHelpText(pLabel, i_rHelpTexts, !io_pCurHelpText ? 0 : (*io_pCurHelpText)++);
     365                 :          0 :     gtk_misc_set_alignment(GTK_MISC(pLabel), 0.0, 0.5);
     366                 :            : 
     367                 :            :     {
     368                 :            :         gchar* const pText = g_markup_printf_escaped("<b>%s</b>",
     369                 :          0 :             rtl::OUStringToOString(i_rText, RTL_TEXTENCODING_UTF8).getStr());
     370                 :          0 :         gtk_label_set_markup_with_mnemonic(GTK_LABEL(pLabel), pText);
     371                 :          0 :         g_free(pText);
     372                 :            :     }
     373                 :            : 
     374                 :          0 :     GtkWidget* const pFrame = gtk_vbox_new(FALSE, 6);
     375                 :          0 :     gtk_box_pack_start(GTK_BOX(pFrame), pLabel, FALSE, FALSE, 0);
     376                 :            : 
     377                 :          0 :     GtkWidget* const pAlignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
     378                 :          0 :     gtk_alignment_set_padding(GTK_ALIGNMENT(pAlignment), 0, 0, 12, 0);
     379                 :          0 :     gtk_box_pack_start(GTK_BOX(pFrame), pAlignment, FALSE, FALSE, 0);
     380                 :            : 
     381                 :          0 :     gtk_container_add(GTK_CONTAINER(pAlignment), i_pChild);
     382                 :          0 :     return pFrame;
     383                 :            : }
     384                 :            : 
     385                 :            : void
     386                 :          0 : lcl_extractHelpTextsOrIds(
     387                 :            :         const beans::PropertyValue& rEntry,
     388                 :            :         uno::Sequence<rtl::OUString>& rHelpStrings)
     389                 :            : {
     390                 :          0 :     if (!(rEntry.Value >>= rHelpStrings))
     391                 :            :     {
     392                 :          0 :         rtl::OUString aHelpString;
     393                 :          0 :         if ((rEntry.Value >>= aHelpString))
     394                 :            :         {
     395                 :          0 :             rHelpStrings.realloc(1);
     396                 :          0 :             *rHelpStrings.getArray() = aHelpString;
     397                 :          0 :         }
     398                 :            :     }
     399                 :          0 : }
     400                 :            : 
     401                 :            : GtkWidget*
     402                 :          0 : lcl_combo_box_text_new()
     403                 :            : {
     404                 :            : #if GTK_CHECK_VERSION(3,0,0)
     405                 :            :     return gtk_combo_box_text_new();
     406                 :            : #else
     407                 :          0 :     return gtk_combo_box_new_text();
     408                 :            : #endif
     409                 :            : }
     410                 :            : 
     411                 :            : void
     412                 :          0 : lcl_combo_box_text_append(GtkWidget* const pWidget, gchar const* const pText)
     413                 :            : {
     414                 :            : #if GTK_CHECK_VERSION(3,0,0)
     415                 :            :     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pWidget), pText);
     416                 :            : #else
     417                 :          0 :     gtk_combo_box_append_text(GTK_COMBO_BOX(pWidget), pText);
     418                 :            : #endif
     419                 :          0 : }
     420                 :            : 
     421                 :            : }
     422                 :            : 
     423                 :          0 : GtkPrintDialog::GtkPrintDialog(vcl::PrinterController& io_rController)
     424                 :            :     : m_rController(io_rController)
     425                 :          0 :     , m_pWrapper(lcl_getGtkSalInstance().getPrintWrapper())
     426                 :            : {
     427                 :            :     assert(m_pWrapper->supportsPrinting());
     428                 :          0 :     impl_initDialog();
     429                 :          0 :     impl_initCustomTab();
     430                 :          0 :     impl_readFromSettings();
     431                 :          0 : }
     432                 :            : 
     433                 :            : 
     434                 :            : void
     435                 :          0 : GtkPrintDialog::impl_initDialog()
     436                 :            : {
     437                 :            :     //To-Do, like fpicker, set UI language
     438                 :          0 :     m_pDialog = m_pWrapper->print_unix_dialog_new(NULL, NULL);
     439                 :            : 
     440                 :          0 :     Window* const pTopWindow(Application::GetActiveTopWindow());
     441                 :          0 :     if (pTopWindow)
     442                 :            :     {
     443                 :          0 :         GtkSalFrame* const pFrame(dynamic_cast<GtkSalFrame*>(pTopWindow->ImplGetFrame()));
     444                 :          0 :         if (pFrame)
     445                 :            :         {
     446                 :          0 :             GtkWindow* const pParent(GTK_WINDOW(pFrame->getWindow()));
     447                 :          0 :             if (pParent)
     448                 :          0 :                 gtk_window_set_transient_for(GTK_WINDOW(m_pDialog), pParent);
     449                 :            :         }
     450                 :            :     }
     451                 :            : 
     452                 :          0 :     m_pWrapper->print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(m_pDialog),
     453                 :            :         GtkPrintCapabilities(GTK_PRINT_CAPABILITY_COPIES
     454                 :            :             | GTK_PRINT_CAPABILITY_COLLATE
     455                 :            :             | GTK_PRINT_CAPABILITY_REVERSE
     456                 :            :             | GTK_PRINT_CAPABILITY_GENERATE_PS
     457                 :            : #if GTK_CHECK_VERSION(2,12,0)
     458                 :            :             | GTK_PRINT_CAPABILITY_NUMBER_UP
     459                 :            : #endif
     460                 :            : #if GTK_CHECK_VERSION(2,14,0)
     461                 :            :             | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT
     462                 :            : #endif
     463                 :          0 :        ));
     464                 :          0 : }
     465                 :            : 
     466                 :            : 
     467                 :            : void
     468                 :          0 : GtkPrintDialog::impl_initCustomTab()
     469                 :            : {
     470                 :            :     typedef std::map<rtl::OUString, GtkWidget*> DependencyMap_t;
     471                 :            :     typedef std::vector<std::pair<GtkWidget*, rtl::OUString> > CustomTabs_t;
     472                 :            : 
     473                 :          0 :     const uno::Sequence<beans::PropertyValue>& rOptions(m_rController.getUIOptions());
     474                 :          0 :     DependencyMap_t aPropertyToDependencyRowMap;
     475                 :          0 :     CustomTabs_t aCustomTabs;
     476                 :          0 :     GtkWidget* pCurParent = NULL;
     477                 :          0 :     GtkWidget* pCurTabPage = NULL;
     478                 :          0 :     GtkWidget* pCurSubGroup = NULL;
     479                 :          0 :     GtkWidget* pStandardPrintRangeContainer = NULL;
     480                 :          0 :     bool bIgnoreSubgroup = false;
     481                 :          0 :     for (int i = 0; i != rOptions.getLength(); i++)
     482                 :            :     {
     483                 :          0 :         uno::Sequence<beans::PropertyValue> aOptProp;
     484                 :          0 :         rOptions[i].Value >>= aOptProp;
     485                 :            : 
     486                 :          0 :         rtl::OUString aCtrlType;
     487                 :          0 :         rtl::OUString aText;
     488                 :          0 :         rtl::OUString aPropertyName;
     489                 :          0 :         uno::Sequence<rtl::OUString> aChoices;
     490                 :          0 :         uno::Sequence<sal_Bool> aChoicesDisabled;
     491                 :          0 :         uno::Sequence<rtl::OUString> aHelpTexts;
     492                 :          0 :         sal_Int64 nMinValue = 0, nMaxValue = 0;
     493                 :          0 :         sal_Int32 nCurHelpText = 0;
     494                 :          0 :         rtl::OUString aDependsOnName;
     495                 :          0 :         sal_Int32 nDependsOnValue = 0;
     496                 :          0 :         sal_Bool bUseDependencyRow = sal_False;
     497                 :          0 :         sal_Bool bIgnore = sal_False;
     498                 :          0 :         GtkWidget* pGroup = NULL;
     499                 :          0 :         bool bGtkInternal = false;
     500                 :            : 
     501                 :          0 :         for (int n = 0; n != aOptProp.getLength(); n++)
     502                 :            :         {
     503                 :          0 :             const beans::PropertyValue& rEntry(aOptProp[ n ]);
     504                 :          0 :             if ( rEntry.Name == "Text" )
     505                 :            :             {
     506                 :          0 :                 rtl::OUString aValue;
     507                 :          0 :                 rEntry.Value >>= aValue;
     508                 :          0 :                 aText = aValue.replace('~', '_');
     509                 :            :             }
     510                 :          0 :             else if ( rEntry.Name == "ControlType" )
     511                 :          0 :                 rEntry.Value >>= aCtrlType;
     512                 :          0 :             else if ( rEntry.Name == "Choices" )
     513                 :          0 :                 rEntry.Value >>= aChoices;
     514                 :          0 :             else if ( rEntry.Name == "ChoicesDisabled" )
     515                 :          0 :                 rEntry.Value >>= aChoicesDisabled;
     516                 :          0 :             else if ( rEntry.Name == "Property" )
     517                 :            :             {
     518                 :          0 :                 beans::PropertyValue aVal;
     519                 :          0 :                 rEntry.Value >>= aVal;
     520                 :          0 :                 aPropertyName = aVal.Name;
     521                 :            :             }
     522                 :          0 :             else if ( rEntry.Name == "DependsOnName" )
     523                 :          0 :                 rEntry.Value >>= aDependsOnName;
     524                 :          0 :             else if ( rEntry.Name == "DependsOnEntry" )
     525                 :          0 :                 rEntry.Value >>= nDependsOnValue;
     526                 :          0 :             else if ( rEntry.Name == "AttachToDependency" )
     527                 :          0 :                 rEntry.Value >>= bUseDependencyRow;
     528                 :          0 :             else if ( rEntry.Name == "MinValue" )
     529                 :          0 :                 rEntry.Value >>= nMinValue;
     530                 :          0 :             else if ( rEntry.Name == "MaxValue" )
     531                 :          0 :                 rEntry.Value >>= nMaxValue;
     532                 :          0 :             else if ( rEntry.Name == "HelpId" )
     533                 :            :             {
     534                 :          0 :                 uno::Sequence<rtl::OUString> aHelpIds;
     535                 :          0 :                 lcl_extractHelpTextsOrIds(rEntry, aHelpIds);
     536                 :          0 :                 Help* const pHelp = Application::GetHelp();
     537                 :          0 :                 if (pHelp)
     538                 :            :                 {
     539                 :          0 :                     const int nLen = aHelpIds.getLength();
     540                 :          0 :                     aHelpTexts.realloc(nLen);
     541                 :          0 :                     for (int j = 0; j != nLen; ++j)
     542                 :          0 :                         aHelpTexts[j] = pHelp->GetHelpText(aHelpIds[j], 0);
     543                 :            :                 }
     544                 :            :                 else // fallback
     545                 :          0 :                     aHelpTexts = aHelpIds;
     546                 :            :             }
     547                 :          0 :             else if ( rEntry.Name == "HelpText" )
     548                 :          0 :                 lcl_extractHelpTextsOrIds(rEntry, aHelpTexts);
     549                 :          0 :             else if ( rEntry.Name == "InternalUIOnly" )
     550                 :          0 :                 rEntry.Value >>= bIgnore;
     551                 :          0 :             else if ( rEntry.Name == "Enabled" )
     552                 :            :             {
     553                 :            :                 // Ignore this. We use UIControlOptions::isUIOptionEnabled
     554                 :            :                 // to check whether a control should be enabled.
     555                 :            :             }
     556                 :          0 :             else if ( rEntry.Name == "GroupingHint" )
     557                 :            :             {
     558                 :            :                 // Ignore this. We cannot add/modify controls to/on existing
     559                 :            :                 // tabs of the Gtk print dialog.
     560                 :            :             }
     561                 :            :             else
     562                 :            :             {
     563                 :            :                 SAL_INFO("vcl.gtk", "unhandled UI option entry: " << rEntry.Name);
     564                 :            :             }
     565                 :            :         }
     566                 :            : 
     567                 :          0 :         if ( aPropertyName == "PrintContent" )
     568                 :          0 :             bGtkInternal = true;
     569                 :            : 
     570                 :          0 :         if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Group")) || !pCurParent)
     571                 :            :         {
     572                 :          0 :             pCurTabPage = gtk_vbox_new(FALSE, 12);
     573                 :          0 :             gtk_container_set_border_width(GTK_CONTAINER(pCurTabPage), 6);
     574                 :          0 :             lcl_setHelpText(pCurTabPage, aHelpTexts, 0);
     575                 :            : 
     576                 :          0 :             pCurParent = pCurTabPage;
     577                 :          0 :             aCustomTabs.push_back(std::make_pair(pCurTabPage, aText));
     578                 :            :         }
     579                 :          0 :         else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) && (pCurParent /*|| bOnJobPageValue*/))
     580                 :            :         {
     581                 :          0 :             bIgnoreSubgroup = bIgnore;
     582                 :          0 :             if (bIgnore)
     583                 :          0 :                 continue;
     584                 :          0 :             pCurParent = gtk_vbox_new(FALSE, 12);
     585                 :          0 :             gtk_container_set_border_width(GTK_CONTAINER(pCurParent), 0);
     586                 :            : 
     587                 :          0 :             pCurSubGroup = lcl_makeFrame(pCurParent, aText, aHelpTexts, NULL);
     588                 :          0 :             gtk_box_pack_start(GTK_BOX(pCurTabPage), pCurSubGroup, FALSE, FALSE, 0);
     589                 :            :         }
     590                 :            :         // special case: we need to map these to controls of the gtk print dialog
     591                 :          0 :         else if (bGtkInternal)
     592                 :            :         {
     593                 :          0 :             if ( aPropertyName == "PrintContent" )
     594                 :            :             {
     595                 :            :                 // What to print? And, more importantly, is there a selection?
     596                 :          0 :                 impl_initPrintContent(aChoicesDisabled);
     597                 :            :             }
     598                 :            :         }
     599                 :          0 :         else if (bIgnoreSubgroup || bIgnore)
     600                 :          0 :             continue;
     601                 :            :         else
     602                 :            :         {
     603                 :            :             // change handlers for all the controls set up in this block
     604                 :            :             // should be set _after_ the control has been made (in)active,
     605                 :            :             // because:
     606                 :            :             // 1. value of the property is _known_--we are using it to
     607                 :            :             //    _set_ the control, right?--no need to change it back .-)
     608                 :            :             // 2. it may cause warning because the widget may not
     609                 :            :             //    have been placed in m_aControlToPropertyMap yet
     610                 :            : 
     611                 :          0 :             GtkWidget* pWidget = NULL;
     612                 :          0 :             beans::PropertyValue* pVal = NULL;
     613                 :          0 :             if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Bool")) && pCurParent)
     614                 :            :             {
     615                 :            :                 pWidget = gtk_check_button_new_with_mnemonic(
     616                 :          0 :                     rtl::OUStringToOString(aText, RTL_TEXTENCODING_UTF8).getStr());
     617                 :          0 :                 lcl_setHelpText(pWidget, aHelpTexts, 0);
     618                 :          0 :                 m_aControlToPropertyMap[pWidget] = aPropertyName;
     619                 :            : 
     620                 :          0 :                 sal_Bool bVal = sal_False;
     621                 :          0 :                 pVal = m_rController.getValue(aPropertyName);
     622                 :          0 :                 if (pVal)
     623                 :          0 :                     pVal->Value >>= bVal;
     624                 :          0 :                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pWidget), bVal);
     625                 :            :                 gtk_widget_set_sensitive(pWidget,
     626                 :          0 :                     m_rController.isUIOptionEnabled(aPropertyName) && pVal != NULL);
     627                 :          0 :                 g_signal_connect(pWidget, "toggled", G_CALLBACK(GtkPrintDialog::UIOption_CheckHdl), this);
     628                 :            :             }
     629                 :          0 :             else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Radio")) && pCurParent)
     630                 :            :             {
     631                 :          0 :                 GtkWidget* const pVbox = gtk_vbox_new(FALSE, 12);
     632                 :          0 :                 gtk_container_set_border_width(GTK_CONTAINER(pVbox), 0);
     633                 :            : 
     634                 :          0 :                 if (!aText.isEmpty())
     635                 :          0 :                     pGroup = lcl_makeFrame(pVbox, aText, aHelpTexts, &nCurHelpText);
     636                 :            : 
     637                 :          0 :                 sal_Int32 nSelectVal = 0;
     638                 :          0 :                 pVal = m_rController.getValue(aPropertyName);
     639                 :          0 :                 if (pVal && pVal->Value.hasValue())
     640                 :          0 :                     pVal->Value >>= nSelectVal;
     641                 :            : 
     642                 :          0 :                 for (sal_Int32 m = 0; m != aChoices.getLength(); m++)
     643                 :            :                 {
     644                 :            :                     pWidget = gtk_radio_button_new_with_mnemonic_from_widget(
     645                 :          0 :                         GTK_RADIO_BUTTON(m == 0 ? NULL : pWidget),
     646                 :          0 :                         rtl::OUStringToOString(aChoices[m].replace('~', '_'), RTL_TEXTENCODING_UTF8).getStr());
     647                 :          0 :                     lcl_setHelpText(pWidget, aHelpTexts, nCurHelpText++);
     648                 :          0 :                     m_aControlToPropertyMap[pWidget] = aPropertyName;
     649                 :          0 :                     m_aControlToNumValMap[pWidget] = m;
     650                 :          0 :                     GtkWidget* const pRow = gtk_hbox_new(FALSE, 12);
     651                 :          0 :                     gtk_box_pack_start(GTK_BOX(pVbox), pRow, FALSE, FALSE, 0);
     652                 :          0 :                     gtk_box_pack_start(GTK_BOX(pRow), pWidget, FALSE, FALSE, 0);
     653                 :          0 :                     aPropertyToDependencyRowMap[aPropertyName + rtl::OUString::valueOf(m)] = pRow;
     654                 :          0 :                     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pWidget), m == nSelectVal);
     655                 :            :                     gtk_widget_set_sensitive(pWidget,
     656                 :          0 :                         m_rController.isUIOptionEnabled(aPropertyName) && pVal != NULL);
     657                 :          0 :                     g_signal_connect(pWidget, "toggled",
     658                 :          0 :                             G_CALLBACK(GtkPrintDialog::UIOption_RadioHdl), this);
     659                 :            :                 }
     660                 :            : 
     661                 :          0 :                 if (pGroup)
     662                 :          0 :                     pWidget = pGroup;
     663                 :            :                 else
     664                 :          0 :                     pWidget = pVbox;
     665                 :            :             }
     666                 :          0 :             else if ((aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("List"))   ||
     667                 :          0 :                        aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range"))  ||
     668                 :          0 :                        aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit"))
     669                 :            :                     ) && pCurParent)
     670                 :            :             {
     671                 :          0 :                 GtkWidget* const pHbox = gtk_hbox_new(FALSE, 12);
     672                 :          0 :                 gtk_container_set_border_width(GTK_CONTAINER(pHbox), 0);
     673                 :            : 
     674                 :          0 :                 if ( aCtrlType == "List" )
     675                 :            :                 {
     676                 :          0 :                    pWidget = lcl_combo_box_text_new();
     677                 :            : 
     678                 :          0 :                    for (sal_Int32 m = 0; m != aChoices.getLength(); m++)
     679                 :            :                    {
     680                 :            :                        lcl_combo_box_text_append(pWidget,
     681                 :          0 :                            rtl::OUStringToOString(aChoices[m], RTL_TEXTENCODING_UTF8).getStr());
     682                 :            :                    }
     683                 :            : 
     684                 :          0 :                    sal_Int32 nSelectVal = 0;
     685                 :          0 :                    pVal = m_rController.getValue(aPropertyName);
     686                 :          0 :                    if (pVal && pVal->Value.hasValue())
     687                 :          0 :                        pVal->Value >>= nSelectVal;
     688                 :          0 :                    gtk_combo_box_set_active(GTK_COMBO_BOX(pWidget), nSelectVal);
     689                 :          0 :                    g_signal_connect(pWidget, "changed", G_CALLBACK(GtkPrintDialog::UIOption_SelectHdl), this);
     690                 :            :                 }
     691                 :          0 :                 else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit")) && pCurParent)
     692                 :            :                 {
     693                 :          0 :                    pWidget = gtk_entry_new();
     694                 :            : 
     695                 :          0 :                    rtl::OUString aCurVal;
     696                 :          0 :                    pVal = m_rController.getValue(aPropertyName);
     697                 :          0 :                    if (pVal && pVal->Value.hasValue())
     698                 :          0 :                        pVal->Value >>= aCurVal;
     699                 :          0 :                    gtk_entry_set_text(GTK_ENTRY(pWidget),
     700                 :          0 :                        rtl::OUStringToOString(aCurVal, RTL_TEXTENCODING_UTF8).getStr());
     701                 :            :                 }
     702                 :          0 :                 else if (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range")) && pCurParent)
     703                 :            :                 {
     704                 :          0 :                     pWidget = gtk_spin_button_new_with_range(nMinValue, nMaxValue, 1.0);
     705                 :            : 
     706                 :          0 :                     sal_Int64 nCurVal = 0;
     707                 :          0 :                     pVal = m_rController.getValue(aPropertyName);
     708                 :          0 :                     if (pVal && pVal->Value.hasValue())
     709                 :          0 :                         pVal->Value >>= nCurVal;
     710                 :          0 :                     gtk_spin_button_set_value(GTK_SPIN_BUTTON(pWidget), nCurVal);
     711                 :            :                 }
     712                 :            : 
     713                 :          0 :                 lcl_setHelpText(pWidget, aHelpTexts, 0);
     714                 :          0 :                 m_aControlToPropertyMap[pWidget] = aPropertyName;
     715                 :            : 
     716                 :            :                 gtk_widget_set_sensitive(pWidget,
     717                 :          0 :                     m_rController.isUIOptionEnabled(aPropertyName) && pVal != NULL);
     718                 :            : 
     719                 :          0 :                 if (!aText.isEmpty())
     720                 :            :                 {
     721                 :            :                     GtkWidget* const pLabel = gtk_label_new_with_mnemonic(
     722                 :          0 :                         rtl::OUStringToOString(aText, RTL_TEXTENCODING_UTF8).getStr());
     723                 :          0 :                     gtk_label_set_mnemonic_widget(GTK_LABEL(pLabel), pWidget);
     724                 :          0 :                     gtk_box_pack_start(GTK_BOX(pHbox), pLabel, FALSE, FALSE, 0);
     725                 :            :                 }
     726                 :            : 
     727                 :          0 :                 gtk_box_pack_start(GTK_BOX(pHbox), pWidget, FALSE, FALSE, 0);
     728                 :            : 
     729                 :          0 :                 pWidget = pHbox;
     730                 :            : 
     731                 :            :             }
     732                 :            :             else
     733                 :            :                 SAL_INFO("vcl.gtk", "unhandled option type: " << aCtrlType);
     734                 :            : 
     735                 :          0 :             GtkWidget* pRow = NULL;
     736                 :          0 :             if (pWidget)
     737                 :            :             {
     738                 :          0 :                 if (bUseDependencyRow && !aDependsOnName.isEmpty())
     739                 :            :                 {
     740                 :          0 :                     pRow = aPropertyToDependencyRowMap[aDependsOnName + rtl::OUString::valueOf(nDependsOnValue)];
     741                 :          0 :                     if (!pRow)
     742                 :            :                     {
     743                 :          0 :                         gtk_widget_destroy(pWidget);
     744                 :          0 :                         pWidget = NULL;
     745                 :            :                     }
     746                 :            :                 }
     747                 :            :             }
     748                 :          0 :             if (pWidget)
     749                 :            :             {
     750                 :          0 :                 if (!pRow)
     751                 :            :                 {
     752                 :          0 :                     pRow = gtk_hbox_new(FALSE, 12);
     753                 :          0 :                     gtk_box_pack_start(GTK_BOX(pCurParent), pRow, FALSE, FALSE, 0);
     754                 :            :                 }
     755                 :          0 :                 if (!pGroup)
     756                 :          0 :                     aPropertyToDependencyRowMap[aPropertyName + rtl::OUString::valueOf(sal_Int32(0))] = pRow;
     757                 :          0 :                 gtk_box_pack_start(GTK_BOX(pRow), pWidget, FALSE, FALSE, 0);
     758                 :            :             }
     759                 :            :         }
     760                 :          0 :     }
     761                 :            : 
     762                 :          0 :     if (pStandardPrintRangeContainer)
     763                 :          0 :         gtk_widget_destroy(pStandardPrintRangeContainer);
     764                 :            : 
     765                 :          0 :     CustomTabs_t::const_reverse_iterator aEnd = aCustomTabs.rend();
     766                 :          0 :     for (CustomTabs_t::const_reverse_iterator aI = aCustomTabs.rbegin(); aI != aEnd; ++aI)
     767                 :            :     {
     768                 :          0 :         gtk_widget_show_all(aI->first);
     769                 :          0 :         m_pWrapper->print_unix_dialog_add_custom_tab(GTK_PRINT_UNIX_DIALOG(m_pDialog), aI->first,
     770                 :          0 :             gtk_label_new(rtl::OUStringToOString(aI->second, RTL_TEXTENCODING_UTF8).getStr()));
     771                 :          0 :     }
     772                 :          0 : }
     773                 :            : 
     774                 :            : 
     775                 :            : void
     776                 :          0 : GtkPrintDialog::impl_initPrintContent(uno::Sequence<sal_Bool> const& i_rDisabled)
     777                 :            : {
     778                 :            :     SAL_WARN_IF(i_rDisabled.getLength() != 3, "vcl.gtk", "there is more choices than we expected");
     779                 :          0 :     if (i_rDisabled.getLength() != 3)
     780                 :          0 :         return;
     781                 :            : 
     782                 :          0 :     GtkPrintUnixDialog* const pDialog(GTK_PRINT_UNIX_DIALOG(m_pDialog));
     783                 :            : 
     784                 :            :     // XXX: This is a hack that depends on the number and the ordering of
     785                 :            :     // the controls in the rDisabled sequence (cf. the intialization of
     786                 :            :     // the "PrintContent" UI option in SwPrintUIOptions::SwPrintUIOptions,
     787                 :            :     // sw/source/core/view/printdata.cxx)
     788                 :          0 :     if (m_pWrapper->supportsPrintSelection() && !i_rDisabled[2])
     789                 :            :     {
     790                 :          0 :         m_pWrapper->print_unix_dialog_set_support_selection(pDialog, TRUE);
     791                 :          0 :         m_pWrapper->print_unix_dialog_set_has_selection(pDialog, TRUE);
     792                 :            :     }
     793                 :            : 
     794                 :            :     beans::PropertyValue* const pPrintContent(
     795                 :          0 :             m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintContent"))));
     796                 :            : 
     797                 :          0 :     if (pPrintContent)
     798                 :            :     {
     799                 :          0 :         sal_Int32 nSelectionType(0);
     800                 :          0 :         pPrintContent->Value >>= nSelectionType;
     801                 :          0 :         GtkPrintSettings* const pSettings(getSettings());
     802                 :          0 :         GtkPrintPages ePrintPages(GTK_PRINT_PAGES_ALL);
     803                 :          0 :         switch (nSelectionType)
     804                 :            :         {
     805                 :            :             case 0:
     806                 :          0 :                 ePrintPages = GTK_PRINT_PAGES_ALL;
     807                 :          0 :                 break;
     808                 :            :             case 1:
     809                 :          0 :                 ePrintPages = GTK_PRINT_PAGES_RANGES;
     810                 :          0 :                 break;
     811                 :            :             case 2:
     812                 :            : #if GTK_CHECK_VERSION(2,14,0)
     813                 :          0 :                 if (m_pWrapper->supportsPrintSelection())
     814                 :          0 :                     ePrintPages = GTK_PRINT_PAGES_SELECTION;
     815                 :            :                 else
     816                 :            : #endif
     817                 :            :                     SAL_INFO("vcl.gtk", "the application wants to print a selection, but the present gtk version does not support it");
     818                 :          0 :                 break;
     819                 :            :             default:
     820                 :            :                 SAL_WARN("vcl.gtk", "unexpected selection type: " << nSelectionType);
     821                 :            :         }
     822                 :          0 :         m_pWrapper->print_settings_set_print_pages(pSettings, ePrintPages);
     823                 :          0 :         m_pWrapper->print_unix_dialog_set_settings(pDialog, pSettings);
     824                 :          0 :         g_object_unref(G_OBJECT(pSettings));
     825                 :            :     }
     826                 :            : }
     827                 :            : 
     828                 :            : 
     829                 :            : void
     830                 :          0 : GtkPrintDialog::impl_checkOptionalControlDependencies()
     831                 :            : {
     832                 :          0 :     for (std::map<GtkWidget*, rtl::OUString>::iterator it = m_aControlToPropertyMap.begin();
     833                 :          0 :          it != m_aControlToPropertyMap.end(); ++it)
     834                 :            :     {
     835                 :          0 :         gtk_widget_set_sensitive(it->first, m_rController.isUIOptionEnabled(it->second));
     836                 :            :     }
     837                 :          0 : }
     838                 :            : 
     839                 :            : 
     840                 :            : beans::PropertyValue*
     841                 :          0 : GtkPrintDialog::impl_queryPropertyValue(GtkWidget* const i_pWidget) const
     842                 :            : {
     843                 :          0 :     beans::PropertyValue* pVal(0);
     844                 :          0 :     std::map<GtkWidget*, rtl::OUString>::const_iterator aIt(m_aControlToPropertyMap.find(i_pWidget));
     845                 :          0 :     if (aIt != m_aControlToPropertyMap.end())
     846                 :            :     {
     847                 :          0 :         pVal = m_rController.getValue(aIt->second);
     848                 :            :         SAL_WARN_IF(!pVal, "vcl.gtk", "property value not found");
     849                 :            :     }
     850                 :            :     else
     851                 :            :     {
     852                 :            :         SAL_WARN("vcl.gtk", "changed control not in property map");
     853                 :            :     }
     854                 :          0 :     return pVal;
     855                 :            : }
     856                 :            : 
     857                 :            : 
     858                 :            : void
     859                 :          0 : GtkPrintDialog::impl_UIOption_CheckHdl(GtkWidget* const i_pWidget)
     860                 :            : {
     861                 :          0 :     beans::PropertyValue* const pVal = impl_queryPropertyValue(i_pWidget);
     862                 :          0 :     if (pVal)
     863                 :            :     {
     864                 :          0 :         const bool bVal = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(i_pWidget));
     865                 :          0 :         pVal->Value <<= bVal;
     866                 :            : 
     867                 :          0 :         impl_checkOptionalControlDependencies();
     868                 :            :     }
     869                 :          0 : }
     870                 :            : 
     871                 :            : 
     872                 :            : void
     873                 :          0 : GtkPrintDialog::impl_UIOption_RadioHdl(GtkWidget* const i_pWidget)
     874                 :            : {
     875                 :          0 :     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(i_pWidget)))
     876                 :            :     {
     877                 :          0 :         beans::PropertyValue* const pVal = impl_queryPropertyValue(i_pWidget);
     878                 :          0 :         std::map<GtkWidget*, sal_Int32>::const_iterator it = m_aControlToNumValMap.find(i_pWidget);
     879                 :          0 :         if (pVal && it != m_aControlToNumValMap.end())
     880                 :            :         {
     881                 :            : 
     882                 :          0 :             const sal_Int32 nVal = it->second;
     883                 :          0 :             pVal->Value <<= nVal;
     884                 :            : 
     885                 :          0 :             impl_checkOptionalControlDependencies();
     886                 :            :         }
     887                 :            :     }
     888                 :          0 : }
     889                 :            : 
     890                 :            : 
     891                 :            : void
     892                 :          0 : GtkPrintDialog::impl_UIOption_SelectHdl(GtkWidget* const i_pWidget)
     893                 :            : {
     894                 :          0 :     beans::PropertyValue* const pVal = impl_queryPropertyValue(i_pWidget);
     895                 :          0 :     if (pVal)
     896                 :            :     {
     897                 :          0 :         const sal_Int32 nVal(gtk_combo_box_get_active(GTK_COMBO_BOX(i_pWidget)));
     898                 :          0 :         pVal->Value <<= nVal;
     899                 :            : 
     900                 :          0 :         impl_checkOptionalControlDependencies();
     901                 :            :     }
     902                 :          0 : }
     903                 :            : 
     904                 :            : 
     905                 :            : bool
     906                 :          0 : GtkPrintDialog::run()
     907                 :            : {
     908                 :          0 :     bool bDoJob = false;
     909                 :          0 :     bool bContinue = true;
     910                 :          0 :     while (bContinue)
     911                 :            :     {
     912                 :          0 :         bContinue = false;
     913                 :          0 :         const gint nStatus = gtk_dialog_run(GTK_DIALOG(m_pDialog));
     914                 :          0 :         switch (nStatus)
     915                 :            :         {
     916                 :            :             case GTK_RESPONSE_HELP:
     917                 :          0 :                 fprintf(stderr, "To-Do: Help ?\n");
     918                 :          0 :                 bContinue = true;
     919                 :          0 :                 break;
     920                 :            :             case GTK_RESPONSE_OK:
     921                 :          0 :                 bDoJob = true;
     922                 :          0 :                 break;
     923                 :            :             default:
     924                 :          0 :                 break;
     925                 :            :         }
     926                 :            :     }
     927                 :          0 :     gtk_widget_hide(m_pDialog);
     928                 :          0 :     impl_storeToSettings();
     929                 :          0 :     return bDoJob;
     930                 :            : }
     931                 :            : 
     932                 :            : #if 0
     933                 :            : void GtkPrintDialog::ExportAsPDF(const rtl::OUString &rFileURL, GtkPrintSettings *pSettings) const
     934                 :            : {
     935                 :            :     uno::Reference < XFramesSupplier > xDesktop =
     936                 :            :             uno::Reference < XFramesSupplier >(
     937                 :            :     ::comphelper::getProcessServiceFactory()->
     938                 :            :         createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))), UNO_QUERY);
     939                 :            :     uno::Reference < XFrame > xFrame(xDesktop->getActiveFrame());
     940                 :            :     if (!xFrame.is())
     941                 :            :         xFrame = uno::Reference < XFrame >(xDesktop, UNO_QUERY);
     942                 :            : 
     943                 :            :     uno::Reference < XFilter > xFilter(
     944                 :            :         ::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.PDFFilter"))),
     945                 :            :         UNO_QUERY);
     946                 :            : 
     947                 :            :     if (xFilter.is())
     948                 :            :     {
     949                 :            :         uno::Reference< XController > xController;
     950                 :            :         uno::Reference< XComponent > xDoc;
     951                 :            :         if (xFrame.is())
     952                 :            :             xController = xFrame->getController();
     953                 :            :         if (xController.is())
     954                 :            :             xDoc = uno::Reference< XComponent >(xController->getModel(), UNO_QUERY);
     955                 :            : 
     956                 :            :         SvFileStream aStream(rFileURL, STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC);
     957                 :            :         uno::Reference< XOutputStream > xOStm(new utl::OOutputStreamWrapper(aStream));
     958                 :            : 
     959                 :            :         uno::Reference< XExporter > xExport(xFilter, UNO_QUERY);
     960                 :            :         xExport->setSourceDocument(xDoc);
     961                 :            :         uno::Sequence<beans::PropertyValue> aFilterData(2);
     962                 :            :         aFilterData[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageLayout"));
     963                 :            :         aFilterData[0].Value <<= sal_Int32(0);
     964                 :            :         aFilterData[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FirstPageOnLeft"));
     965                 :            :         aFilterData[1].Value <<= sal_False;
     966                 :            : 
     967                 :            : 
     968                 :            :         const gchar *pStr = gtk_print_settings_get(pSettings, GTK_PRINT_SETTINGS_PRINT_PAGES);
     969                 :            :         if (pStr && !strcmp(pStr, "ranges"))
     970                 :            :         {
     971                 :            :             String aRangeText;
     972                 :            :             gint num_ranges;
     973                 :            :             const GtkPageRange* pRanges = gtk_print_settings_get_page_ranges(pSettings, &num_ranges);
     974                 :            :             for (gint i = 0; i < num_ranges; ++i)
     975                 :            :             {
     976                 :            :                 aRangeText.Append(String::CreateFromInt32(pRanges[i].start+1));
     977                 :            :                 if (pRanges[i].start != pRanges[i].end)
     978                 :            :                 {
     979                 :            :                     aRangeText.AppendAscii("-");
     980                 :            :                     aRangeText.Append(String::CreateFromInt32(pRanges[i].end+1));
     981                 :            :                 }
     982                 :            : 
     983                 :            :                 if (i != num_ranges-1)
     984                 :            :                     aRangeText.AppendAscii(",");
     985                 :            :             }
     986                 :            :             aFilterData.realloc(aFilterData.getLength()+1);
     987                 :            :             aFilterData[aFilterData.getLength()-1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageRange"));
     988                 :            :             aFilterData[aFilterData.getLength()-1].Value <<= rtl::OUString(aRangeText);
     989                 :            :         }
     990                 :            :         else if (pStr && !strcmp(pStr, "current"))
     991                 :            :         {
     992                 :            :             try
     993                 :            :             {
     994                 :            :                    uno::Reference< XSpreadsheetView > xSpreadsheetView;
     995                 :            :                    uno::Reference< XSpreadsheet> xSheet;
     996                 :            :                    uno::Reference< XSpreadsheetDocument > xSheetDoc;
     997                 :            :                    uno::Reference< XIndexAccess > xSheets;
     998                 :            :                    uno::Reference< XNamed > xName;
     999                 :            : 
    1000                 :            :                    if (xController.is())
    1001                 :            :                        xSpreadsheetView = uno::Reference< XSpreadsheetView >(xController, UNO_QUERY);
    1002                 :            :                    if (xSpreadsheetView.is())
    1003                 :            :                        xSheet = uno::Reference< XSpreadsheet>(xSpreadsheetView->getActiveSheet());
    1004                 :            :                    if (xSheet.is())
    1005                 :            :                        xName = uno::Reference < XNamed >(xSheet, UNO_QUERY);
    1006                 :            :                    if (xName.is())
    1007                 :            :                        xSheetDoc = uno::Reference< XSpreadsheetDocument >(xController->getModel(), UNO_QUERY);
    1008                 :            :                    if (xSheetDoc.is())
    1009                 :            :                        xSheets = uno::Reference< XIndexAccess >(xSheetDoc->getSheets(), UNO_QUERY);
    1010                 :            :                    if (xSheets.is())
    1011                 :            :                    {
    1012                 :            :                        const rtl::OUString &rName = xName->getName();
    1013                 :            : 
    1014                 :            :                        sal_Int32 i;
    1015                 :            : 
    1016                 :            :                        for (i = 0; i < xSheets->getCount(); ++i)
    1017                 :            :                        {
    1018                 :            :                            uno::Reference < XNamed > xItem =
    1019                 :            :                                uno::Reference < XNamed >(xSheets->getByIndex(i), UNO_QUERY);
    1020                 :            :                            if (rName == xItem->getName())
    1021                 :            :                                break;
    1022                 :            :                        }
    1023                 :            : 
    1024                 :            :                        if (i < xSheets->getCount())
    1025                 :            :                        {
    1026                 :            :                             aFilterData.realloc(aFilterData.getLength()+1);
    1027                 :            :                             aFilterData[aFilterData.getLength()-1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageRange"));
    1028                 :            :                             aFilterData[aFilterData.getLength()-1].Value <<= rtl::OUString(String::CreateFromInt32(i + 1));
    1029                 :            :                        }
    1030                 :            :                    }
    1031                 :            :             }
    1032                 :            :             catch (...) {}
    1033                 :            :         }
    1034                 :            : #if GTK_CHECK_VERSION(2,17,5)
    1035                 :            :         if (gtk_print_unix_dialog_get_has_selection(GTK_PRINT_UNIX_DIALOG(m_pDialog)))
    1036                 :            :         {
    1037                 :            :             uno::Any aSelection;
    1038                 :            :             try
    1039                 :            :             {
    1040                 :            :                 if (xController.is())
    1041                 :            :                 {
    1042                 :            :                     uno::Reference<view::XSelectionSupplier> xView(xController, UNO_QUERY);
    1043                 :            :                     if (xView.is())
    1044                 :            :                         xView->getSelection() >>= aSelection;
    1045                 :            :                 }
    1046                 :            :             }
    1047                 :            :             catch (const uno::RuntimeException &)
    1048                 :            :             {
    1049                 :            :             }
    1050                 :            :             if (aSelection.hasValue())
    1051                 :            :             {
    1052                 :            :                 aFilterData.realloc(aFilterData.getLength()+1);
    1053                 :            :                 aFilterData[aFilterData.getLength()-1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Selection"));
    1054                 :            :                 aFilterData[aFilterData.getLength()-1].Value <<= aSelection;
    1055                 :            :             }
    1056                 :            :         }
    1057                 :            : #endif
    1058                 :            :         uno::Sequence<beans::PropertyValue> aArgs(2);
    1059                 :            :         aArgs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FilterData"));
    1060                 :            :         aArgs[0].Value <<= aFilterData;
    1061                 :            :         aArgs[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutputStream"));
    1062                 :            :         aArgs[1].Value <<= xOStm;
    1063                 :            :         xFilter->filter(aArgs);
    1064                 :            :     }
    1065                 :            : }
    1066                 :            : #endif
    1067                 :            : 
    1068                 :            : 
    1069                 :            : void
    1070                 :          0 : GtkPrintDialog::updateControllerPrintRange()
    1071                 :            : {
    1072                 :          0 :     GtkPrintSettings* const pSettings(getSettings());
    1073                 :            :     // TODO: use get_print_pages
    1074                 :          0 :     if (const gchar* const pStr = m_pWrapper->print_settings_get(pSettings, GTK_PRINT_SETTINGS_PRINT_PAGES))
    1075                 :            :     {
    1076                 :          0 :         beans::PropertyValue* pVal = m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintRange")));
    1077                 :          0 :         if (!pVal)
    1078                 :          0 :             pVal = m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintContent")));
    1079                 :            :         SAL_WARN_IF(!pVal, "vcl.gtk", "Nothing to map standard print options to!");
    1080                 :          0 :         if (pVal)
    1081                 :            :         {
    1082                 :          0 :             sal_Int32 nVal = 0;
    1083                 :          0 :             if (!strcmp(pStr, "all"))
    1084                 :          0 :                 nVal = 0;
    1085                 :          0 :             else if (!strcmp(pStr, "ranges"))
    1086                 :          0 :                 nVal = 1;
    1087                 :          0 :             else if (!strcmp(pStr, "selection"))
    1088                 :          0 :                 nVal = 2;
    1089                 :          0 :             pVal->Value <<= nVal;
    1090                 :            : 
    1091                 :          0 :             if (nVal == 1)
    1092                 :            :             {
    1093                 :          0 :                 pVal = m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageRange")));
    1094                 :            :                 SAL_WARN_IF(!pVal, "vcl.gtk", "PageRange doesn't exist!");
    1095                 :          0 :                 if (pVal)
    1096                 :            :                 {
    1097                 :          0 :                     rtl::OUStringBuffer sBuf;
    1098                 :            :                     gint num_ranges;
    1099                 :          0 :                     const GtkPageRange* const pRanges = m_pWrapper->print_settings_get_page_ranges(pSettings, &num_ranges);
    1100                 :          0 :                     for (gint i = 0; i != num_ranges && pRanges; ++i)
    1101                 :            :                     {
    1102                 :          0 :                         sBuf.append(sal_Int32(pRanges[i].start+1));
    1103                 :          0 :                         if (pRanges[i].start != pRanges[i].end)
    1104                 :            :                         {
    1105                 :          0 :                             sBuf.append(sal_Unicode('-'));
    1106                 :          0 :                             sBuf.append(sal_Int32(pRanges[i].end+1));
    1107                 :            :                         }
    1108                 :            : 
    1109                 :          0 :                         if (i != num_ranges-1)
    1110                 :          0 :                             sBuf.append(sal_Unicode(','));
    1111                 :            :                     }
    1112                 :          0 :                     pVal->Value <<= sBuf.makeStringAndClear();
    1113                 :            :                 }
    1114                 :            :             }
    1115                 :            :         }
    1116                 :            :     }
    1117                 :          0 :     g_object_unref(G_OBJECT(pSettings));
    1118                 :          0 : }
    1119                 :            : 
    1120                 :            : 
    1121                 :          0 : GtkPrintDialog::~GtkPrintDialog()
    1122                 :            : {
    1123                 :          0 :     gtk_widget_destroy(m_pDialog);
    1124                 :          0 : }
    1125                 :            : 
    1126                 :            : 
    1127                 :            : void
    1128                 :          0 : GtkPrintDialog::impl_readFromSettings()
    1129                 :            : {
    1130                 :          0 :     vcl::SettingsConfigItem* const pItem(vcl::SettingsConfigItem::get());
    1131                 :          0 :     GtkPrintSettings* const pSettings(getSettings());
    1132                 :            : 
    1133                 :          0 :     const rtl::OUString aPrintDialogStr(RTL_CONSTASCII_USTRINGPARAM("PrintDialog"));
    1134                 :            :     const rtl::OUString aCopyCount(pItem->getValue(aPrintDialogStr,
    1135                 :          0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CopyCount"))));
    1136                 :            :     const rtl::OUString aCollate(pItem->getValue(aPrintDialogStr,
    1137                 :          0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Collate"))));
    1138                 :            : 
    1139                 :          0 :     bool bChanged(false);
    1140                 :            : 
    1141                 :          0 :     const gint nOldCopyCount(m_pWrapper->print_settings_get_n_copies(pSettings));
    1142                 :          0 :     const sal_Int32 nCopyCount(aCopyCount.toInt32());
    1143                 :          0 :     if (nCopyCount > 0 && nOldCopyCount != nCopyCount)
    1144                 :            :     {
    1145                 :          0 :         bChanged = true;
    1146                 :          0 :         m_pWrapper->print_settings_set_n_copies(pSettings, sal::static_int_cast<gint>(nCopyCount));
    1147                 :            :     }
    1148                 :            : 
    1149                 :          0 :     const gboolean bOldCollate(m_pWrapper->print_settings_get_collate(pSettings));
    1150                 :          0 :     const bool bCollate(aCollate.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")));
    1151                 :          0 :     if (bOldCollate != bCollate)
    1152                 :            :     {
    1153                 :          0 :         bChanged = true;
    1154                 :          0 :         m_pWrapper->print_settings_set_collate(pSettings, bCollate);
    1155                 :            :     }
    1156                 :            :     // TODO: wth was this var. meant for?
    1157                 :            :     (void) bChanged;
    1158                 :            : 
    1159                 :          0 :     m_pWrapper->print_unix_dialog_set_settings(GTK_PRINT_UNIX_DIALOG(m_pDialog), pSettings);
    1160                 :          0 :     g_object_unref(G_OBJECT(pSettings));
    1161                 :          0 : }
    1162                 :            : 
    1163                 :            : 
    1164                 :            : void
    1165                 :          0 : GtkPrintDialog::impl_storeToSettings()
    1166                 :            : const
    1167                 :            : {
    1168                 :          0 :     vcl::SettingsConfigItem* const pItem(vcl::SettingsConfigItem::get());
    1169                 :          0 :     GtkPrintSettings* const pSettings(getSettings());
    1170                 :            : 
    1171                 :          0 :     const rtl::OUString aPrintDialogStr(RTL_CONSTASCII_USTRINGPARAM("PrintDialog"));
    1172                 :            :     pItem->setValue(aPrintDialogStr,
    1173                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CopyCount")),
    1174                 :          0 :             rtl::OUString::valueOf(sal_Int32(m_pWrapper->print_settings_get_n_copies(pSettings))));
    1175                 :            :     pItem->setValue(aPrintDialogStr,
    1176                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Collate")),
    1177                 :          0 :             m_pWrapper->print_settings_get_collate(pSettings)
    1178                 :            :                 ? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))
    1179                 :          0 :                 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false")))
    1180                 :          0 :         ;
    1181                 :            :     // pItem->setValue(aPrintDialog, rtl::OUString::createFromAscii("ToFile"), );
    1182                 :          0 :     g_object_unref(G_OBJECT(pSettings));
    1183                 :          0 :     pItem->Commit();
    1184                 :          0 : }
    1185                 :            : 
    1186                 :            : 
    1187                 :            : sal_uLong
    1188                 :          0 : GtkSalInfoPrinter::GetCapabilities(
    1189                 :            :         const ImplJobSetup* const i_pSetupData,
    1190                 :            :         const sal_uInt16 i_nType)
    1191                 :            : {
    1192                 :          0 :     if (i_nType == PRINTER_CAPABILITIES_EXTERNALDIALOG && lcl_useSystemPrintDialog())
    1193                 :          0 :         return 1;
    1194                 :          0 :     return PspSalInfoPrinter::GetCapabilities(i_pSetupData, i_nType);
    1195                 :            : }
    1196                 :            : 
    1197                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10