campo-sirio/xvaga/xvtextra.cpp
guy b4592c4df8 Patch level : 1.32 nopatch
Files correlati     : di tutto e di più
Ricompilazione Demo : [ ]
Commento            :


git-svn-id: svn://10.65.10.50/trunk@10256 c028cbd2-c16b-5b4b-a496-9718f37d4682
2002-05-27 13:01:14 +00:00

303 lines
5.7 KiB
C++
Executable File

#include "wxinc.h"
#include "wx/print.h"
#include "wx/printdlg.h"
#include "xvt.h"
#include "xvtextra.h"
#include "oswin32.h"
#include "xvintern.h"
struct TPRINT_RCD : public PRINT_RCD
{
char m_data[4096];
TPRINT_RCD() { pr = NULL; memset(m_data, 0, sizeof(m_data)); }
};
///////////////////////////////////////////////////////////
// TwxPrintOut
///////////////////////////////////////////////////////////
class TwxPrintOut : public wxPrintout
{
protected:
virtual bool HasPage(int pageNum);
virtual bool OnPrintPage(int pageNum);
TPRINT_RCD* m_prcd;
public:
void InitDC(TPRINT_RCD* prcd);
TwxPrintOut(TPRINT_RCD* prcd = NULL);
virtual ~TwxPrintOut();
};
static TwxPrintOut* m_po = NULL;
bool TwxPrintOut::HasPage(int pageNum)
{ return TRUE; }
bool TwxPrintOut::OnPrintPage(int pageNum)
{ return FALSE; }
void TwxPrintOut::InitDC(TPRINT_RCD* prcd)
{
wxDC* dc = GetDC();
if (dc != NULL)
delete dc;
m_prcd = prcd;
if (m_prcd == NULL)
{
wxPrinter printer;
dc = new wxPrinterDC(printer.GetPrintDialogData().GetPrintData());
}
else
{
wxPrintData data;
#ifdef WIN32
data.SetNativeData(OsWin32_ConvertToNativePrinterInfo(prcd->m_data));
#else
data.SetNativeData(prcd->m_data);
#endif
data.ConvertFromNative();
dc = new wxPrinterDC(data);
}
wxSize s = dc->GetPPI();
SetPPIPrinter(s.x, s.y);
s = dc->GetSize();
SetPageSizePixels(s.x, s.y);
SetDC(dc);
}
TwxPrintOut::TwxPrintOut(TPRINT_RCD* prcd)
{
InitDC(prcd);
}
TwxPrintOut::~TwxPrintOut()
{
wxDC* dc = GetDC();
if (dc != NULL)
delete dc;
}
///////////////////////////////////////////////////////////
// TPrintDC
///////////////////////////////////////////////////////////
wxDC& TPrintDC::GetDC(bool)
{
_dc = m_po->GetDC(); // Forza display context corrente
return TDC::GetDC(false);
}
TPrintDC::TPrintDC(wxWindow* owner) : TDC(owner)
{ }
TPrintDC::~TPrintDC()
{
_dc = NULL; // Evita distruzione!
}
///////////////////////////////////////////////////////////
// Printing management :-(((((
///////////////////////////////////////////////////////////
BOOLEAN xvt_app_escape(int esc_code, PRINT_RCD* rcd, long* ph, long* pw, long* pvr, long* phr)
{
switch (esc_code)
{
case XVT_ESC_GET_PRINTER_INFO:
{
const bool temp = m_po == NULL;
if (temp)
m_po = new TwxPrintOut((TPRINT_RCD*)rcd);
int w, h;
m_po->GetPPIPrinter(&w, &h);
*phr = w; *pvr = h;
m_po->GetPageSizePixels(&w, &h);
*pw = w; *ph = h;
if (temp)
{
delete m_po;
m_po = NULL;
}
}
return TRUE;
default:
break;
}
return FALSE;
}
BOOLEAN xvt_dm_post_page_setup(PRINT_RCD* precp)
{
wxPageSetupDialog dlg((wxWindow*)TASK_WIN);
TPRINT_RCD* rcd = (TPRINT_RCD*)precp;
wxPageSetupData& pdd = dlg.GetPageSetupData();
pdd.EnablePrinter(false); // Vieta di cambiare stampante
wxPrintData& data = pdd.GetPrintData();
#ifdef WIN32
data.SetNativeData(OsWin32_ConvertToNativePrinterInfo(rcd->m_data));
#else
data.SetNativeData(rcd->m_data);
#endif
data.ConvertFromNative();
if (dlg.ShowModal() == wxID_OK)
{
data.ConvertToNative();
void* pHandle = data.GetNativeData();
#ifdef WIN32
void* ptr = OsWin32_ConvertFromNativePrinterInfo(pHandle);
memcpy(rcd->m_data, ptr, sizeof(rcd->m_data));
delete ptr;
#else
memcpy(rcd->m_data, pHandle, sizeof(rcd->m_data));
#endif
return TRUE;
}
return FALSE;
}
long xvt_fmap_get_family_sizes(PRINT_RCD *precp, char *family, long *size_array, BOOLEAN *scalable, long max_sizes)
{
long size = 1;
size_array[0] = 13;
*scalable = FALSE;
#ifdef WIN32
if (precp != NULL)
{
TwxPrintOut* po = new TwxPrintOut((TPRINT_RCD*)precp);
size = OsWin32_EnumerateSizes(po->GetDC()->GetHDC(), family, size_array, scalable, max_sizes);
}
#endif
return size;
}
long xvt_fmap_get_families(PRINT_RCD *precp, char **family_array, long max_families)
{
long size = 1;
family_array[0] = xvt_str_duplicate(XVT_FFN_COURIER);
#ifdef WIN32
if (precp != NULL)
{
TwxPrintOut* po = new TwxPrintOut((TPRINT_RCD*)precp);
size = OsWin32_EnumerateFamilies(po->GetDC()->GetHDC(), family_array, max_families);
}
#endif
return size;
}
void xvt_print_close(void)
{
// Nothing to do
}
BOOLEAN xvt_print_close_page(PRINT_RCD* /*precp*/)
{
BOOLEAN ok = m_po != NULL;
if (ok)
m_po->GetDC()->EndPage();
return ok;
}
PRINT_RCD* xvt_print_create(int *sizep)
{
TPRINT_RCD* pr = new TPRINT_RCD;
#ifdef WIN32
*sizep = OsWin32_GetDefaultPrinterInfo(pr->m_data, sizeof(pr->m_data));
#endif
*sizep += 4; // Unused pointer size
return pr;
}
WINDOW xvt_print_create_win(PRINT_RCD* precp, char* /* title */)
{
WINDOW win = NULL_WIN;
if (m_po != NULL)
{
m_po->InitDC((TPRINT_RCD*)precp);
m_po->OnBeginPrinting();
m_po->OnBeginDocument(1, 32000);
win = _print_win;
}
return win;
}
void xvt_print_destroy(PRINT_RCD *precp)
{
// Nothing to do!
}
RCT* xvt_print_get_next_band(void)
{
static bool yes = false;
static RCT rct;
yes = !yes;
if (m_po == NULL || !yes)
return NULL;
int w, h;
m_po->GetPageSizePixels(&w, &h);
rct.left = rct.top = 0;
rct.right = w;
rct.bottom = h;
return &rct;
}
BOOLEAN xvt_print_is_valid(PRINT_RCD* precp)
{
BOOLEAN ok = precp != NULL;
if (ok)
{
#ifdef WIN32
ok = OsWin32_CheckPrinterInfo(((TPRINT_RCD*)precp)->m_data);
#endif
}
return ok;
}
BOOLEAN xvt_print_open(void)
{
return m_po == NULL;
}
BOOLEAN xvt_print_start_thread(BOOLEAN(*print_fcn)(long), long data)
{
wxWindow* tw = (wxWindow*)TASK_WIN;
m_po = new TwxPrintOut;
print_fcn(data);
m_po->OnEndDocument();
m_po->OnEndPrinting();
delete m_po; m_po = NULL;
return TRUE;
}
BOOLEAN xvt_print_open_page(PRINT_RCD* /* precp */)
{
BOOLEAN ok = m_po != NULL;
if (ok)
m_po->GetDC()->StartPage();
return ok;
}