Kaydet (Commit) 823d4a39 authored tarafından David Tardon's avatar David Tardon

check for printing support dynamically

üst 5628699d
......@@ -33,6 +33,7 @@ $(eval $(call gb_Library_set_include,vclplug_gtk,\
$$(INCLUDE) \
-I$(SRCDIR)/vcl/inc \
-I$(SRCDIR)/vcl/unx \
-I$(SRCDIR)/vcl/unx/gtk/inc \
-I$(SRCDIR)/solenv/inc \
-I$(OUTDIR)/inc \
$(shell pkg-config --cflags gtk+-unix-print-2.0) \
......@@ -104,6 +105,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gtk,\
vcl/unx/gtk/app/gtkdata \
vcl/unx/gtk/app/gtkinst \
vcl/unx/gtk/app/gtksys \
vcl/unx/gtk/gdi/gtkprintwrapper \
vcl/unx/gtk/gdi/salnativewidgets-gtk \
vcl/unx/gtk/gdi/salprn-gtk \
vcl/unx/gtk/window/gtkframe \
......
......@@ -29,11 +29,21 @@
#ifndef _VCL_GTKINST_HXX
#define _VCL_GTKINST_HXX
#include <boost/shared_ptr.hpp>
#include <unx/salinst.h>
#include <generic/gensys.h>
#include <headless/svpinst.hxx>
#include <gtk/gtk.h>
namespace vcl
{
namespace unx
{
class GtkPrintWrapper;
}
}
class GenPspGraphics;
class GtkYieldMutex : public SalYieldMutex
{
......@@ -125,6 +135,8 @@ public:
// for managing a mirror of the in-flight un-dispatched gdk event queue
void addEvent( sal_uInt16 nMask );
void subtractEvent( sal_uInt16 nMask );
boost::shared_ptr<vcl::unx::GtkPrintWrapper> getPrintWrapper() const;
private:
std::vector<GtkSalTimer *> m_aTimers;
bool IsTimerExpired();
......@@ -132,6 +144,7 @@ public:
// count of in-flight un-dispatched gdk events of a given input type
sal_uInt32 m_nAnyInput[16];
void resetEvents();
mutable boost::shared_ptr<vcl::unx::GtkPrintWrapper> m_pPrintWrapper;
};
#endif // _VCL_GTKINST_HXX
......
......@@ -52,6 +52,8 @@
#include <fcntl.h>
#include <unistd.h>
#include "gtkprintwrapper.hxx"
GtkHookedYieldMutex::GtkHookedYieldMutex()
{
}
......@@ -629,6 +631,14 @@ GenPspGraphics *GtkInstance::CreatePrintGraphics()
return new GenPspGraphics();
}
boost::shared_ptr<vcl::unx::GtkPrintWrapper>
GtkInstance::getPrintWrapper() const
{
if (!m_pPrintWrapper)
m_pPrintWrapper.reset(new vcl::unx::GtkPrintWrapper);
return m_pPrintWrapper;
}
#if GTK_CHECK_VERSION(3,0,0)
#include "../../../headless/svpinst.cxx"
#endif
......
This diff is collapsed.
......@@ -27,7 +27,11 @@
* instead of those above.
*/
#include "gtkprintwrapper.hxx"
#include "unx/gtk/gtkdata.hxx"
#include "unx/gtk/gtkframe.hxx"
#include "unx/gtk/gtkinst.hxx"
#include "unx/gtk/gtkprn.hxx"
#include "vcl/configsettings.hxx"
......@@ -71,6 +75,8 @@ namespace sheet = com::sun::star::sheet;
namespace io = com::sun::star::io;
namespace view = com::sun::star::view;
using vcl::unx::GtkPrintWrapper;
using uno::UNO_QUERY;
class GtkPrintDialog
......@@ -80,11 +86,11 @@ public:
bool run();
GtkPrinter* getPrinter() const
{
return gtk_print_unix_dialog_get_selected_printer(GTK_PRINT_UNIX_DIALOG(m_pDialog));
return m_pWrapper->print_unix_dialog_get_selected_printer(GTK_PRINT_UNIX_DIALOG(m_pDialog));
}
GtkPrintSettings* getSettings() const
{
return gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(m_pDialog));
return m_pWrapper->print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(m_pDialog));
}
void updateControllerPrintRange();
#if 0
......@@ -125,6 +131,7 @@ private:
vcl::PrinterController& m_rController;
std::map<GtkWidget*, rtl::OUString> m_aControlToPropertyMap;
std::map<GtkWidget*, sal_Int32> m_aControlToNumValMap;
boost::shared_ptr<GtkPrintWrapper> m_pWrapper;
};
......@@ -161,6 +168,17 @@ GtkSalPrinter_Impl::~GtkSalPrinter_Impl()
}
}
namespace
{
GtkInstance const&
lcl_getGtkSalInstance()
{
// we _know_ this is GtkInstance
return *static_cast<GtkInstance*>(GetGtkSalData()->m_pInstance);
}
}
GtkSalPrinter::GtkSalPrinter(SalInfoPrinter* const i_pInfoPrinter)
: PspSalPrinter(i_pInfoPrinter)
......@@ -273,7 +291,9 @@ GtkSalPrinter::EndJob()
if (!bRet || !m_pImpl || m_pImpl->m_sSpoolFile.isEmpty())
return bRet;
GtkPageSetup* pPageSetup = gtk_page_setup_new();
boost::shared_ptr<GtkPrintWrapper> const pWrapper(lcl_getGtkSalInstance().getPrintWrapper());
GtkPageSetup* pPageSetup = pWrapper->page_setup_new();
#if 0
//todo
gtk_page_setup_set_orientation(pPageSetup,);
......@@ -284,14 +304,14 @@ GtkSalPrinter::EndJob()
gtk_page_setup_set_right_margin(pPageSetup,);
#endif
GtkPrintJob* const pJob = gtk_print_job_new(
GtkPrintJob* const pJob = pWrapper->print_job_new(
rtl::OUStringToOString(m_pImpl->m_sJobName, RTL_TEXTENCODING_UTF8).getStr(),
m_pImpl->m_pPrinter, m_pImpl->m_pSettings, pPageSetup);
GError* error = NULL;
bRet = gtk_print_job_set_source_file(pJob, m_pImpl->m_sSpoolFile.getStr(), &error);
bRet = pWrapper->print_job_set_source_file(pJob, m_pImpl->m_sSpoolFile.getStr(), &error);
if (bRet)
gtk_print_job_send(pJob, NULL, NULL, NULL);
pWrapper->print_job_send(pJob, NULL, NULL, NULL);
else
{
//To-Do, do something with this
......@@ -371,7 +391,8 @@ lcl_extractHelpTextsOrIds(
}
GtkPrintDialog::GtkPrintDialog(vcl::PrinterController& io_rController)
: m_rController(io_rController)
: m_rController(io_rController)
, m_pWrapper(lcl_getGtkSalInstance().getPrintWrapper())
{
impl_initDialog();
impl_initCustomTab();
......@@ -384,7 +405,7 @@ void
GtkPrintDialog::impl_initDialog()
{
//To-Do, like fpicker, set UI language
m_pDialog = gtk_print_unix_dialog_new(NULL, NULL);
m_pDialog = m_pWrapper->print_unix_dialog_new(NULL, NULL);
Window* const pTopWindow(Application::GetActiveTopWindow());
if (pTopWindow)
......@@ -398,7 +419,7 @@ GtkPrintDialog::impl_initDialog()
}
}
gtk_print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(m_pDialog),
m_pWrapper->print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(m_pDialog),
GtkPrintCapabilities(GTK_PRINT_CAPABILITY_COPIES | GTK_PRINT_CAPABILITY_COLLATE |
// GTK_PRINT_CAPABILITY_REVERSE|GTK_PRINT_CAPABILITY_GENERATE_PDF|GTK_PRINT_CAPABILITY_GENERATE_PS |
GTK_PRINT_CAPABILITY_REVERSE|GTK_PRINT_CAPABILITY_GENERATE_PS |
......@@ -692,7 +713,7 @@ GtkPrintDialog::impl_initCustomTab()
for (CustomTabs_t::const_reverse_iterator aI = aCustomTabs.rbegin(); aI != aEnd; ++aI)
{
gtk_widget_show_all(aI->first);
gtk_print_unix_dialog_add_custom_tab(GTK_PRINT_UNIX_DIALOG(m_pDialog), aI->first,
m_pWrapper->print_unix_dialog_add_custom_tab(GTK_PRINT_UNIX_DIALOG(m_pDialog), aI->first,
gtk_label_new(rtl::OUStringToOString(aI->second, RTL_TEXTENCODING_UTF8).getStr()));
}
#endif
......@@ -713,12 +734,12 @@ GtkPrintDialog::impl_initPrintRange()
if (nSelectionType == 2)
{
GtkPrintUnixDialog* const pDialog(GTK_PRINT_UNIX_DIALOG(m_pDialog));
gtk_print_unix_dialog_set_support_selection(pDialog, TRUE);
gtk_print_unix_dialog_set_has_selection(pDialog, TRUE);
m_pWrapper->print_unix_dialog_set_support_selection(pDialog, TRUE);
m_pWrapper->print_unix_dialog_set_has_selection(pDialog, TRUE);
GtkPrintSettings* const pSettings(getSettings());
gtk_print_settings_set_print_pages(pSettings, GTK_PRINT_PAGES_SELECTION);
gtk_print_unix_dialog_set_settings(pDialog, pSettings);
m_pWrapper->print_settings_set_print_pages(pSettings, GTK_PRINT_PAGES_SELECTION);
m_pWrapper->print_unix_dialog_set_settings(pDialog, pSettings);
g_object_unref(G_OBJECT(pSettings));
}
}
......@@ -970,7 +991,8 @@ void
GtkPrintDialog::updateControllerPrintRange()
{
GtkPrintSettings* const pSettings(getSettings());
if (const gchar* const pStr = gtk_print_settings_get(pSettings, GTK_PRINT_SETTINGS_PRINT_PAGES))
// TODO: use get_print_pages
if (const gchar* const pStr = m_pWrapper->print_settings_get(pSettings, GTK_PRINT_SETTINGS_PRINT_PAGES))
{
beans::PropertyValue* pVal = m_rController.getValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintRange")));
if (!pVal)
......@@ -995,7 +1017,7 @@ GtkPrintDialog::updateControllerPrintRange()
{
rtl::OUStringBuffer sBuf;
gint num_ranges;
const GtkPageRange* const pRanges = gtk_print_settings_get_page_ranges(pSettings, &num_ranges);
const GtkPageRange* const pRanges = m_pWrapper->print_settings_get_page_ranges(pSettings, &num_ranges);
for (gint i = 0; i != num_ranges && pRanges; ++i)
{
sBuf.append(pRanges[i].start+1);
......@@ -1037,25 +1059,25 @@ GtkPrintDialog::impl_readFromSettings()
bool bChanged(false);
const gint nOldCopyCount(gtk_print_settings_get_n_copies(pSettings));
const gint nOldCopyCount(m_pWrapper->print_settings_get_n_copies(pSettings));
const sal_Int32 nCopyCount(aCopyCount.toInt32());
if (nCopyCount > 0 && nOldCopyCount != nCopyCount)
{
bChanged = true;
gtk_print_settings_set_n_copies(pSettings, sal::static_int_cast<gint>(nCopyCount));
m_pWrapper->print_settings_set_n_copies(pSettings, sal::static_int_cast<gint>(nCopyCount));
}
const gboolean bOldCollate(gtk_print_settings_get_collate(pSettings));
const gboolean bOldCollate(m_pWrapper->print_settings_get_collate(pSettings));
const bool bCollate(aCollate.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")));
if (bOldCollate != bCollate)
{
bChanged = true;
gtk_print_settings_set_collate(pSettings, bCollate);
m_pWrapper->print_settings_set_collate(pSettings, bCollate);
}
// TODO: wth was this var. meant for?
(void) bChanged;
gtk_print_unix_dialog_set_settings(GTK_PRINT_UNIX_DIALOG(m_pDialog), pSettings);
m_pWrapper->print_unix_dialog_set_settings(GTK_PRINT_UNIX_DIALOG(m_pDialog), pSettings);
g_object_unref(G_OBJECT(pSettings));
}
......@@ -1070,10 +1092,10 @@ const
const rtl::OUString aPrintDialogStr(RTL_CONSTASCII_USTRINGPARAM("PrintDialog"));
pItem->setValue(aPrintDialogStr,
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CopyCount")),
rtl::OUString::valueOf(gtk_print_settings_get_n_copies(pSettings)));
rtl::OUString::valueOf(m_pWrapper->print_settings_get_n_copies(pSettings)));
pItem->setValue(aPrintDialogStr,
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Collate")),
gtk_print_settings_get_collate(pSettings)
m_pWrapper->print_settings_get_collate(pSettings)
? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))
: rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false")))
;
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2011 David Tardon, Red Hat Inc. <dtardon@redhat.com> (initial developer)
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#ifndef UNX_GTK_INC_GTKPRINTWRAPPER_HXX_INCLUDED
#define UNX_GTK_INC_GTKPRINTWRAPPER_HXX_INCLUDED
#include <boost/noncopyable.hpp>
#include <gtk/gtk.h>
#include <gtk/gtkunixprint.h>
#include <osl/module.hxx>
namespace vcl
{
namespace unx
{
class GtkPrintWrapper : private boost::noncopyable
{
public:
GtkPrintWrapper();
~GtkPrintWrapper();
bool supportsPrinting() const;
bool supportsPrintSelection() const;
// general printing support, since 2.10.0
GtkPageSetup* page_setup_new() const;
GtkPrintJob* print_job_new(const gchar* title, GtkPrinter* printer, GtkPrintSettings* settings, GtkPageSetup* page_setup) const;
void print_job_send(GtkPrintJob* job, GtkPrintJobCompleteFunc callback, gpointer user_data, GDestroyNotify dnotify) const;
gboolean print_job_set_source_file(GtkPrintJob* job, const gchar* filename, GError** error) const;
const gchar* print_settings_get(GtkPrintSettings* settings, const gchar* key) const;
gboolean print_settings_get_collate(GtkPrintSettings* settings) const;
void print_settings_set_collate(GtkPrintSettings* settings, gboolean collate) const;
gint print_settings_get_n_copies(GtkPrintSettings* settings) const;
void print_settings_set_n_copies(GtkPrintSettings* settings, gint num_copies) const;
GtkPageRange* print_settings_get_page_ranges(GtkPrintSettings* settings, gint* num_ranges) const;
void print_settings_set_print_pages(GtkPrintSettings* settings, GtkPrintPages pages) const;
GtkWidget* print_unix_dialog_new(const gchar* title, GtkWindow* parent) const;
void print_unix_dialog_add_custom_tab(GtkPrintUnixDialog* dialog, GtkWidget* child, GtkWidget* tab_label) const;
GtkPrinter* print_unix_dialog_get_selected_printer(GtkPrintUnixDialog* dialog) const;
void print_unix_dialog_set_manual_capabilities(GtkPrintUnixDialog* dialog, GtkPrintCapabilities capabilities) const;
GtkPrintSettings* print_unix_dialog_get_settings(GtkPrintUnixDialog* dialog) const;
void print_unix_dialog_set_settings(GtkPrintUnixDialog* dialog, GtkPrintSettings* settings) const;
// print selection support, since 2.17.4
void print_operation_set_support_selection(GtkPrintOperation* op, gboolean support_selection) const;
void print_operation_set_has_selection(GtkPrintOperation* op, gboolean has_selection) const;
void print_unix_dialog_set_support_selection(GtkPrintUnixDialog* dialog, gboolean support_selection) const;
void print_unix_dialog_set_has_selection(GtkPrintUnixDialog* dialog, gboolean has_selection) const;
private:
void impl_load();
private:
typedef GtkPageSetup* (* page_setup_new_t)();
typedef GtkPrintJob* (* print_job_new_t)(const gchar*, GtkPrinter*, GtkPrintSettings*, GtkPageSetup*);
typedef void (* print_job_send_t)(GtkPrintJob*, GtkPrintJobCompleteFunc, gpointer, GDestroyNotify);
typedef gboolean (* print_job_set_source_file_t)(GtkPrintJob*, const gchar*, GError**);
typedef const gchar* (* print_settings_get_t)(GtkPrintSettings*, const gchar*);
typedef gboolean (* print_settings_get_collate_t)(GtkPrintSettings*);
typedef void (* print_settings_set_collate_t)(GtkPrintSettings*, gboolean);
typedef gint (* print_settings_get_n_copies_t)(GtkPrintSettings*);
typedef void (* print_settings_set_n_copies_t)(GtkPrintSettings*, gint);
typedef GtkPageRange* (* print_settings_get_page_ranges_t)(GtkPrintSettings*, gint*);
typedef void (* print_settings_set_print_pages_t)(GtkPrintSettings*, GtkPrintPages);
typedef GtkWidget* (* print_unix_dialog_new_t)(const gchar*, GtkWindow*);
typedef void (* print_unix_dialog_add_custom_tab_t)(GtkPrintUnixDialog*, GtkWidget*, GtkWidget*);
typedef GtkPrinter* (* print_unix_dialog_get_selected_printer_t)(GtkPrintUnixDialog*);
typedef void (* print_unix_dialog_set_manual_capabilities_t)(GtkPrintUnixDialog*, GtkPrintCapabilities);
typedef GtkPrintSettings* (* print_unix_dialog_get_settings_t)(GtkPrintUnixDialog*);
typedef void (* print_unix_dialog_set_settings_t)(GtkPrintUnixDialog*, GtkPrintSettings*);
typedef void (* print_operation_set_support_selection_t)(GtkPrintOperation*, gboolean);
typedef void (* print_operation_set_has_selection_t)(GtkPrintOperation*, gboolean);
typedef void (* print_unix_dialog_set_support_selection_t)(GtkPrintUnixDialog*, gboolean);
typedef void (* print_unix_dialog_set_has_selection_t)(GtkPrintUnixDialog*, gboolean);
private:
osl::Module m_aModule;
// general printing support, since 2.10.0
page_setup_new_t m_page_setup_new;
print_job_new_t m_print_job_new;
print_job_send_t m_print_job_send;
print_job_set_source_file_t m_print_job_set_source_file;
print_settings_get_t m_print_settings_get;
print_settings_get_collate_t m_print_settings_get_collate;
print_settings_set_collate_t m_print_settings_set_collate;
print_settings_get_n_copies_t m_print_settings_get_n_copies;
print_settings_set_n_copies_t m_print_settings_set_n_copies;
print_settings_get_page_ranges_t m_print_settings_get_page_ranges;
print_settings_set_print_pages_t m_print_settings_set_print_pages;
print_unix_dialog_new_t m_print_unix_dialog_new;
print_unix_dialog_add_custom_tab_t m_print_unix_dialog_add_custom_tab;
print_unix_dialog_get_selected_printer_t m_print_unix_dialog_get_selected_printer;
print_unix_dialog_set_manual_capabilities_t m_print_unix_dialog_set_manual_capabilities;
print_unix_dialog_get_settings_t m_print_unix_dialog_get_settings;
print_unix_dialog_set_settings_t m_print_unix_dialog_set_settings;
// print selection support, since 2.17.4
print_operation_set_support_selection_t m_print_operation_set_support_selection;
print_operation_set_has_selection_t m_print_operation_set_has_selection;
print_unix_dialog_set_support_selection_t m_print_unix_dialog_set_support_selection;
print_unix_dialog_set_has_selection_t m_print_unix_dialog_set_has_selection;
};
}
}
#endif // UNX_GTK_INC_GTKPRINTWRAPPER_HXX_INCLUDED
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment