⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gprint.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/////////////////////////////////////////////////////////////////////////////
// Name:        src/gtk/gnome/gprint.cpp
// Author:      Robert Roebling
// Purpose:     Implement GNOME printing support
// Created:     09/20/04
// RCS-ID:      $Id: gprint.cpp,v 1.41 2006/06/15 17:58:20 ABX Exp $
// Copyright:   Robert Roebling
// Licence:     wxWindows Licence
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#include "wx/gtk/gnome/gprint.h"

#if wxUSE_LIBGNOMEPRINT

#ifndef WX_PRECOMP
    #include "wx/log.h"
    #include "wx/dcmemory.h"
    #include "wx/icon.h"
    #include "wx/math.h"
#endif

#include "wx/fontutil.h"
#include "wx/gtk/private.h"
#include "wx/module.h"
#include "wx/dynlib.h"

#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-pango.h>
#include <libgnomeprint/gnome-print-config.h>
#include <libgnomeprintui/gnome-print-dialog.h>
#include <libgnomeprintui/gnome-print-job-preview.h>
#include <libgnomeprintui/gnome-print-paper-selector.h>

static const double RAD2DEG  = 180.0 / M_PI;

#include "wx/html/forcelnk.h"
FORCE_LINK_ME(gnome_print)

//----------------------------------------------------------------------------
// wxGnomePrintLibrary
//----------------------------------------------------------------------------

#define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
    typedef rettype (* name ## Type) args ; \
    name ## Type pfn_ ## name; \
    rettype name args \
    { if (m_ok) return pfn_ ## name shortargs ; return defret; }

#define wxDL_METHOD_LOAD( lib, name, success ) \
    pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
    if (!success) return;

class wxGnomePrintLibrary
{
public:
    wxGnomePrintLibrary();
    ~wxGnomePrintLibrary();

    bool IsOk();
    void InitializeMethods();

private:
    bool              m_ok;
    wxDynamicLibrary *m_gnome_print_lib;
    wxDynamicLibrary *m_gnome_printui_lib;

public:
    wxDL_METHOD_DEFINE( gint, gnome_print_newpath,
        (GnomePrintContext *pc), (pc), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_moveto,
        (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_lineto,
        (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_arcto,
        (GnomePrintContext *pc, gdouble x, gdouble y, gdouble radius, gdouble angle1, gdouble angle2, gint direction ), (pc, x, y, radius, angle1, angle2, direction), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_curveto,
        (GnomePrintContext *pc, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3), (pc, x1, y1, x2, y2, x3, y3), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_closepath,
        (GnomePrintContext *pc), (pc), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_stroke,
        (GnomePrintContext *pc), (pc), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_fill,
        (GnomePrintContext *pc), (pc), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_setrgbcolor,
        (GnomePrintContext *pc, gdouble r, gdouble g, gdouble b), (pc, r, g, b), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_setlinewidth,
        (GnomePrintContext *pc, gdouble width), (pc, width), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_setdash,
        (GnomePrintContext *pc, gint n_values, const gdouble *values, gdouble offset), (pc, n_values, values, offset), 0 )

    wxDL_METHOD_DEFINE( gint, gnome_print_rgbimage,
        (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_rgbaimage,
        (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 )

    wxDL_METHOD_DEFINE( gint, gnome_print_concat,
        (GnomePrintContext *pc, const gdouble *matrix), (pc, matrix), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_scale,
        (GnomePrintContext *pc, gdouble sx, gdouble sy), (pc, sx, sy), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_rotate,
        (GnomePrintContext *pc, gdouble theta), (pc, theta), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_translate,
        (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 )

    wxDL_METHOD_DEFINE( gint, gnome_print_gsave,
        (GnomePrintContext *pc), (pc), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_grestore,
        (GnomePrintContext *pc), (pc), 0 )

    wxDL_METHOD_DEFINE( gint, gnome_print_beginpage,
        (GnomePrintContext *pc, const guchar* name), (pc, name), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_showpage,
        (GnomePrintContext *pc), (pc), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_end_doc,
        (GnomePrintContext *pc), (pc), 0 )

    wxDL_METHOD_DEFINE( PangoLayout*, gnome_print_pango_create_layout,
        (GnomePrintContext *gpc), (gpc), NULL )
    wxDL_METHOD_DEFINE( void, gnome_print_pango_layout,
        (GnomePrintContext *gpc, PangoLayout *layout), (gpc, layout), /**/ )

    wxDL_METHOD_DEFINE( GnomePrintJob*, gnome_print_job_new,
        (GnomePrintConfig *config), (config), NULL )
    wxDL_METHOD_DEFINE( GnomePrintContext*, gnome_print_job_get_context,
        (GnomePrintJob *job), (job), NULL )
    wxDL_METHOD_DEFINE( gint, gnome_print_job_close,
        (GnomePrintJob *job), (job), 0 )
    wxDL_METHOD_DEFINE( gint, gnome_print_job_print,
        (GnomePrintJob *job), (job), 0 )
    wxDL_METHOD_DEFINE( gboolean, gnome_print_job_get_page_size,
        (GnomePrintJob *job, gdouble *width, gdouble *height), (job, width, height), 0 )

    wxDL_METHOD_DEFINE( GnomePrintUnit*, gnome_print_unit_get_by_abbreviation,
        (const guchar *abbreviation), (abbreviation), NULL )
    wxDL_METHOD_DEFINE( gboolean, gnome_print_convert_distance,
        (gdouble *distance, const GnomePrintUnit *from, const GnomePrintUnit *to), (distance, from, to), false )

    wxDL_METHOD_DEFINE( GnomePrintConfig*, gnome_print_config_default,
        (void), (), NULL )
    wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set,
        (GnomePrintConfig *config, const guchar *key, const guchar *value), (config, key, value), false )
    wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_length,
        (GnomePrintConfig *config, const guchar *key, gdouble *val, const GnomePrintUnit **unit), (config, key, val, unit), false )

    wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_dialog_new,
        (GnomePrintJob *gpj, const guchar *title, gint flags), (gpj, title, flags), NULL )
    wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page,
        (GnomePrintDialog *gpd, gint flags, gint start, gint end,
        const guchar *currentlabel, const guchar *rangelabel),
        (gpd, flags, start, end, currentlabel, rangelabel), /**/ )
    wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies,
        (GnomePrintDialog *gpd, gint *copies, gboolean *collate), (gpd, copies, collate), /**/ )
    wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies,
        (GnomePrintDialog *gpd, gint copies, gint collate), (gpd, copies, collate), /**/ )
    wxDL_METHOD_DEFINE( GnomePrintRangeType, gnome_print_dialog_get_range,
        (GnomePrintDialog *gpd), (gpd), GNOME_PRINT_RANGETYPE_NONE )
    wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page,
        (GnomePrintDialog *gpd, gint *start, gint *end), (gpd, start, end), 0 )

    wxDL_METHOD_DEFINE( GtkWidget*, gnome_paper_selector_new_with_flags,
        (GnomePrintConfig *config, gint flags), (config, flags), NULL )

    wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new,
        (GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL )
};

wxGnomePrintLibrary::wxGnomePrintLibrary()
{
    m_gnome_print_lib = NULL;
    m_gnome_printui_lib = NULL;

    wxLogNull log;

    m_gnome_print_lib = new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
    m_ok = m_gnome_print_lib->IsLoaded();
    if (!m_ok) return;

    m_gnome_printui_lib = new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
    m_ok = m_gnome_printui_lib->IsLoaded();
    if (!m_ok) return;

    InitializeMethods();
}

wxGnomePrintLibrary::~wxGnomePrintLibrary()
{
    if (m_gnome_print_lib)
        delete m_gnome_print_lib;
    if (m_gnome_printui_lib)
        delete m_gnome_printui_lib;
}

bool wxGnomePrintLibrary::IsOk()
{
    return m_ok;
}

void wxGnomePrintLibrary::InitializeMethods()
{
    m_ok = false;
    bool success;

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_newpath, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_moveto, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_lineto, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_curveto, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_arcto, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_closepath, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_stroke, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_fill, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setrgbcolor, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setlinewidth, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_setdash, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbimage, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rgbaimage, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_concat, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_scale, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_rotate, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_translate, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_gsave, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_grestore, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_beginpage, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_showpage, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_end_doc, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_create_layout, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_pango_layout, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_new, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_context, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_close, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_print, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_job_get_page_size, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_unit_get_by_abbreviation, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_convert_distance, success )

    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_default, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_set, success )
    wxDL_METHOD_LOAD( m_gnome_print_lib, gnome_print_config_get_length, success )

    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_new, success )
    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_construct_range_page, success )
    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_copies, success )
    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_set_copies, success )
    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range, success )
    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_dialog_get_range_page, success )

    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_paper_selector_new_with_flags, success )

    wxDL_METHOD_LOAD( m_gnome_printui_lib, gnome_print_job_preview_new, success )

    m_ok = true;
}

static wxGnomePrintLibrary* gs_lgp = NULL;

//----------------------------------------------------------------------------
// wxGnomePrintNativeData
//----------------------------------------------------------------------------

IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase)

wxGnomePrintNativeData::wxGnomePrintNativeData()
{
    m_config = gs_lgp->gnome_print_config_default();
    m_job = gs_lgp->gnome_print_job_new( m_config );
}

wxGnomePrintNativeData::~wxGnomePrintNativeData()
{
    g_object_unref (m_config);
}

bool wxGnomePrintNativeData::TransferTo( wxPrintData &data )
{
    // TODO
    return true;
}

bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data )
{
    // TODO
    return true;
}

//----------------------------------------------------------------------------
// wxGnomePrintFactory
//----------------------------------------------------------------------------

wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data )
{
    return new wxGnomePrinter( data );
}

wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
                                                    wxPrintout *printout,
                                                    wxPrintDialogData *data )
{
    return new wxPostScriptPrintPreview( preview, printout, data );
}

wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
                                                    wxPrintout *printout,
                                                    wxPrintData *data )
{
    return new wxPostScriptPrintPreview( preview, printout, data );
}

wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
                                                  wxPrintDialogData *data )
{
    return new wxGnomePrintDialog( parent, data );
}

wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
                                                  wxPrintData *data )
{
    return new wxGnomePrintDialog( parent, data );
}

wxPageSetupDialogBase *wxGnomePrintFactory::CreatePageSetupDialog( wxWindow *parent,
                                                          wxPageSetupDialogData * data )
{
//  The native page setup dialog is broken. It
//  miscalculates newly entered values for the
//  margins if you have not chose "points" but
//  e.g. centimerters.
//  This has been fixed in GNOME CVS (maybe
//  fixed in libgnomeprintui 2.8.1)

    return new wxGnomePageSetupDialog( parent, data );
}

bool wxGnomePrintFactory::HasPrintSetupDialog()
{
    return false;
}

wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data )
{
    return NULL;
}

bool wxGnomePrintFactory::HasOwnPrintToFile()
{
    return true;
}

bool wxGnomePrintFactory::HasPrinterLine()
{
    return true;
}

wxString wxGnomePrintFactory::CreatePrinterLine()
{
    // redundant now
    return wxEmptyString;
}

bool wxGnomePrintFactory::HasStatusLine()
{
    // redundant now
    return true;
}

wxString wxGnomePrintFactory::CreateStatusLine()
{
    // redundant now
    return wxEmptyString;
}

wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData()
{
    return new wxGnomePrintNativeData;
}

//----------------------------------------------------------------------------
// wxGnomePrintSetupDialog
//----------------------------------------------------------------------------

IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase)

wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data )
                    : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
                               wxPoint(0, 0), wxSize(600, 600),
                               wxDEFAULT_DIALOG_STYLE |
                               wxTAB_TRAVERSAL)
{
    if (data)
        m_printDialogData = *data;

    Init();
}

wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data )
                    : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
                               wxPoint(0, 0), wxSize(600, 600),
                               wxDEFAULT_DIALOG_STYLE |
                               wxTAB_TRAVERSAL)
{
    if (data)
        m_printDialogData = *data;

    Init();
}

void wxGnomePrintDialog::Init()
{
    wxPrintData data = m_printDialogData.GetPrintData();

    wxGnomePrintNativeData *native =
      (wxGnomePrintNativeData*) data.GetNativeData();

    m_widget = gs_lgp->gnome_print_dialog_new( native->GetPrintJob(),
                                       (guchar*)"Print",
                                       GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES );

    int flag = 0;
    if (m_printDialogData.GetEnableSelection())
        flag |= GNOME_PRINT_RANGE_SELECTION;
    if (m_printDialogData.GetEnablePageNumbers())
        flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE;

    gs_lgp->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget,
                                             flag,
                                             m_printDialogData.GetMinPage(),
                                             m_printDialogData.GetMaxPage(),
                                             NULL,
                                             NULL );
}

wxGnomePrintDialog::~wxGnomePrintDialog()
{
    m_widget = NULL;
}

int wxGnomePrintDialog::ShowModal()
{
    // Transfer data from m_printDalogData to dialog here

    int response = gtk_dialog_run (GTK_DIALOG (m_widget));

    if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL)
    {
        gtk_widget_destroy(m_widget);
        m_widget = NULL;

        return wxID_CANCEL;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -