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

📄 gprint.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:

    gint copies = 1;
    gboolean collate = false;
    gs_lgp->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate );
    m_printDialogData.SetNoCopies( copies );
    m_printDialogData.SetCollate( collate );

    switch (gs_lgp->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget ))
    {
        case GNOME_PRINT_RANGE_SELECTION:
            m_printDialogData.SetSelection( true );
            break;
        case GNOME_PRINT_RANGE_ALL:
            m_printDialogData.SetAllPages( true );
            m_printDialogData.SetFromPage( 0 );
            m_printDialogData.SetToPage( 9999 );
            break;
        case GNOME_PRINT_RANGE_RANGE:
        default:
            gint start,end;
            gs_lgp->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end );
            m_printDialogData.SetFromPage( start );
            m_printDialogData.SetToPage( end );
            break;
    }

    gtk_widget_destroy(m_widget);
    m_widget = NULL;

    if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW)
        return wxID_PREVIEW;

    return wxID_OK;
}

wxDC *wxGnomePrintDialog::GetPrintDC()
{
    // Later
    return NULL;
}

bool wxGnomePrintDialog::Validate()
{
    return true;
}

bool wxGnomePrintDialog::TransferDataToWindow()
{
    return true;
}

bool wxGnomePrintDialog::TransferDataFromWindow()
{
    return true;
}

//----------------------------------------------------------------------------
// wxGnomePageSetupDialog
//----------------------------------------------------------------------------

IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase)

wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow *parent,
                            wxPageSetupDialogData* data )
{
    if (data)
        m_pageDialogData = *data;

    wxGnomePrintNativeData *native =
      (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData();

    // This is required as the page setup dialog
    // calculates wrong values otherwise.
    gs_lgp->gnome_print_config_set( native->GetPrintConfig(),
                            (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT,
                            (const guchar*) "Pts" );

    m_widget = gtk_dialog_new();

    gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) );

    GtkWidget *main = gs_lgp->gnome_paper_selector_new_with_flags( native->GetPrintConfig(),
        GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION );
    gtk_container_set_border_width (GTK_CONTAINER (main), 8);
    gtk_widget_show (main);

    gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main );

    gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE);

    gtk_dialog_add_buttons (GTK_DIALOG (m_widget),
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OK, GTK_RESPONSE_OK,
                            NULL);

    gtk_dialog_set_default_response (GTK_DIALOG (m_widget),
                            GTK_RESPONSE_OK);
}

wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
{
}

wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData()
{
    return m_pageDialogData;
}

int wxGnomePageSetupDialog::ShowModal()
{
    wxGnomePrintNativeData *native =
      (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData();
    GnomePrintConfig *config = native->GetPrintConfig();

    // Transfer data from m_pageDialogData to native dialog

    int ret = gtk_dialog_run( GTK_DIALOG(m_widget) );

    if (ret == GTK_RESPONSE_OK)
    {
        // Transfer data back to m_pageDialogData

        // I don't know how querying the last parameter works
        // I cannot test it as the dialog is currently broken
        // anyways (it only works for points).
        double ml,mr,mt,mb,pw,ph;
        gs_lgp->gnome_print_config_get_length (config,
            (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL);
        gs_lgp->gnome_print_config_get_length (config,
            (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL);
        gs_lgp->gnome_print_config_get_length (config,
            (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL);
        gs_lgp->gnome_print_config_get_length (config,
            (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL);
        gs_lgp->gnome_print_config_get_length (config,
            (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL);
        gs_lgp->gnome_print_config_get_length (config,
            (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL);

        // This probably assumes that the user entered the
        // values in Pts. Since that is the only the dialog
        // works right now, we need to fix this later.
        const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" );
        const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" );
        gs_lgp->gnome_print_convert_distance( &ml, pts_unit, mm_unit );
        gs_lgp->gnome_print_convert_distance( &mr, pts_unit, mm_unit );
        gs_lgp->gnome_print_convert_distance( &mt, pts_unit, mm_unit );
        gs_lgp->gnome_print_convert_distance( &mb, pts_unit, mm_unit );
        gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit );
        gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit );

        m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) );
        m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) );

        m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) );

#if 0
        wxPrintf( wxT("paper %d %d, top margin %d\n"),
            m_pageDialogData.GetPaperSize().x,
            m_pageDialogData.GetPaperSize().y,
            m_pageDialogData.GetMarginTopLeft().x );
#endif

        ret = wxID_OK;
    }
    else
    {
        ret = wxID_CANCEL;
    }

    gtk_widget_destroy( m_widget );
    m_widget = NULL;

    return ret;
}

bool wxGnomePageSetupDialog::Validate()
{
    return true;
}

bool wxGnomePageSetupDialog::TransferDataToWindow()
{
    return true;
}

bool wxGnomePageSetupDialog::TransferDataFromWindow()
{
    return true;
}

//----------------------------------------------------------------------------
// wxGnomePrinter
//----------------------------------------------------------------------------

IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase)

wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) :
    wxPrinterBase( data )
{
    m_gpc = NULL;
    m_native_preview = false;
}

wxGnomePrinter::~wxGnomePrinter()
{
}

bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
{
    if (!printout)
    {
        sm_lastError = wxPRINTER_ERROR;
        return false;
    }

    wxPrintData printdata = GetPrintDialogData().GetPrintData();
    wxGnomePrintNativeData *native =
        (wxGnomePrintNativeData*) printdata.GetNativeData();

    GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() );
    m_gpc = gs_lgp->gnome_print_job_get_context (job);

    // The GnomePrintJob is temporarily stored in the
    // native print data as the native print dialog
    // needs to access it.
    native->SetPrintJob( job );


    printout->SetIsPreview(false);

    if (m_printDialogData.GetMinPage() < 1)
        m_printDialogData.SetMinPage(1);
    if (m_printDialogData.GetMaxPage() < 1)
        m_printDialogData.SetMaxPage(9999);

    wxDC *dc;
    if (prompt)
        dc = PrintDialog( parent );
    else
        dc = new wxGnomePrintDC( this );

    if (m_native_preview)
        printout->SetIsPreview(true);

    if (!dc)
    {
        gs_lgp->gnome_print_job_close( job );
        g_object_unref (job);
        sm_lastError = wxPRINTER_ERROR;
        return false;
    }

    wxSize ScreenPixels = wxGetDisplaySize();
    wxSize ScreenMM = wxGetDisplaySizeMM();

    printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
                            (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
    printout->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
                             wxGnomePrintDC::GetResolution() );

    printout->SetDC(dc);

    int w, h;
    dc->GetSize(&w, &h);
    printout->SetPageSizePixels((int)w, (int)h);
    dc->GetSizeMM(&w, &h);
    printout->SetPageSizeMM((int)w, (int)h);

    printout->OnPreparePrinting();

    // Get some parameters from the printout, if defined
    int fromPage, toPage;
    int minPage, maxPage;
    printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);

    if (maxPage == 0)
    {
        gs_lgp->gnome_print_job_close( job );
        g_object_unref (job);
        sm_lastError = wxPRINTER_ERROR;
        return false;
    }

    printout->OnBeginPrinting();

    int minPageNum = minPage, maxPageNum = maxPage;

    if ( !m_printDialogData.GetAllPages() )
    {
        minPageNum = m_printDialogData.GetFromPage();
        maxPageNum = m_printDialogData.GetToPage();
    }


    int copyCount;
    for ( copyCount = 1;
          copyCount <= m_printDialogData.GetNoCopies();
          copyCount++ )
    {
        if (!printout->OnBeginDocument(minPageNum, maxPageNum))
        {
            wxLogError(_("Could not start printing."));
            sm_lastError = wxPRINTER_ERROR;
            break;
        }

        int pn;
        for ( pn = minPageNum;
              pn <= maxPageNum && printout->HasPage(pn);
              pn++ )
        {
            dc->StartPage();
            printout->OnPrintPage(pn);
            dc->EndPage();
        }

        printout->OnEndDocument();
        printout->OnEndPrinting();
    }

    gs_lgp->gnome_print_job_close( job );
    if (m_native_preview)
    {
        const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview")));
        GtkWidget *preview = gs_lgp->gnome_print_job_preview_new
                                     (
                                        job,
                                        (const guchar *)title.data()
                                     );
        gtk_widget_show(preview);
    }
    else
    {
        gs_lgp->gnome_print_job_print( job );
    }

    g_object_unref (job);
    delete dc;

    return (sm_lastError == wxPRINTER_NO_ERROR);
}

wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent )
{
    wxGnomePrintDialog dialog( parent, &m_printDialogData );
    int ret = dialog.ShowModal();
    if (ret == wxID_CANCEL)
    {
        sm_lastError = wxPRINTER_CANCELLED;
        return NULL;
    }

    m_native_preview = ret == wxID_PREVIEW;

    m_printDialogData = dialog.GetPrintDialogData();
    return new wxGnomePrintDC( this );
}

bool wxGnomePrinter::Setup( wxWindow *parent )
{
    return false;
}

//-----------------------------------------------------------------------------
// wxGnomePrintDC
//-----------------------------------------------------------------------------

IMPLEMENT_CLASS(wxGnomePrintDC, wxDC)

wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer )
{
    m_printer = printer;

    m_gpc = printer->GetPrintContext();

    m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc );
    m_fontdesc = pango_font_description_from_string( "Sans 12" );

    m_currentRed = 0;
    m_currentBlue = 0;
    m_currentGreen = 0;

    m_signX =  1;  // default x-axis left to right
    m_signY = -1;  // default y-axis bottom up -> top down
}

wxGnomePrintDC::~wxGnomePrintDC()
{
}

bool wxGnomePrintDC::Ok() const
{
    return true;
}

bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style )
{
    return false;
}

bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const
{
    return false;
}

void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
    if  (m_pen.GetStyle() == wxTRANSPARENT) return;

    SetPen( m_pen );

    gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) );
    gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) );
    gs_lgp->gnome_print_stroke ( m_gpc);

    CalcBoundingBox( x1, y1 );
    CalcBoundingBox( x2, y2 );
}

void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y)
{
}

void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)
{
    double dx = x1 - xc;
    double dy = y1 - yc;
    double radius = sqrt((double)(dx*dx+dy*dy));
    double alpha1, alpha2;
    if (x1 == x2 && y1 == y2)
    {
        alpha1 = 0.0;
        alpha2 = 360.0;
    }
    else
    if (radius == 0.0)
    {
        alpha1 = alpha2 = 0.0;
    }
    else
    {
        alpha1 = (x1 - xc == 0) ?
            (y1 - yc < 0) ? 90.0 : -90.0 :
            -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG;
        alpha2 = (x2 - xc == 0) ?
            (y2 - yc < 0) ? 90.0 : -90.0 :
            -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG;

        while (alpha1 <= 0)   alpha1 += 360;
        while (alpha2 <= 0)   alpha2 += 360; // adjust angles to be between
        while (alpha1 > 360)  alpha1 -= 360; // 0 and 360 degree
        while (alpha2 > 360)  alpha2 -= 360;
    }

        if (m_brush.GetStyle() != wxTRANSPARENT)
        {
            SetBrush( m_brush );
            gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
            gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );

⌨️ 快捷键说明

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