Patch level : 10.0 148

Files correlati     : xvaga.dll
Ricompilazione Demo : [ ]
Commento            :
0000934: impostazione nuova stampante
Se selezione file ed imposta stampante, se scelgo la stampante mi da l'errore che allego, se la stessa operazione si fa dal pc di Salomoni campo si chiude senza dare errori.


git-svn-id: svn://10.65.10.50/trunk@17536 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2008-11-03 11:39:49 +00:00
parent 7b0bc699d2
commit 64c17343fb
5 changed files with 136 additions and 100 deletions

View File

@ -28,8 +28,16 @@ bool OsWin32_CheckPrinterInfo(const void* data, unsigned int size)
return ok; return ok;
} }
static void TestPaper(PDEVMODE dm) static int AdjustDevmodePlease(PDEVMODE dm)
{ {
// Forse dovremmo fare una Black List su file delle stampanti incompatibili):
// 1) "NRG SP 4100N PCL 5e"
// 2) aggiungere qui le altre
// Ma per ora zappiamo tutti i driver troppo grandi (> 3Kb)
if (dm->dmDriverExtra > 3*1024)
dm->dmDriverExtra = 0;
// Controllo il formato della carta
wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(dm->dmPaperSize); wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(dm->dmPaperSize);
if (paper == NULL) if (paper == NULL)
{ {
@ -37,12 +45,8 @@ static void TestPaper(PDEVMODE dm)
wxThePrintPaperDatabase->WXADDPAPER((wxPaperSize)dm->dmPaperSize /*wxPAPER_NONE*/, dm->dmPaperSize, wxThePrintPaperDatabase->WXADDPAPER((wxPaperSize)dm->dmPaperSize /*wxPAPER_NONE*/, dm->dmPaperSize,
dm->dmFormName, dm->dmPaperWidth, dm->dmPaperLength); dm->dmFormName, dm->dmPaperWidth, dm->dmPaperLength);
} }
}
static void adjust_extra(WORD& w) return dm->dmSize + dm->dmDriverExtra;
{
if (w > 4096)
w = 0;
} }
void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSize) void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSize)
@ -51,10 +55,8 @@ void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSiz
if (hGlobal != NULL) if (hGlobal != NULL)
{ {
PDEVMODE dm = (PDEVMODE)::GlobalLock(hGlobal); PDEVMODE dm = (PDEVMODE)::GlobalLock(hGlobal);
adjust_extra(dm->dmDriverExtra); nDataSize = AdjustDevmodePlease(dm);
nDataSize = dm->dmSize+dm->dmDriverExtra;
buff = new char[nDataSize]; buff = new char[nDataSize];
TestPaper(dm);
memcpy(buff, dm, nDataSize); memcpy(buff, dm, nDataSize);
::GlobalUnlock(hGlobal); ::GlobalUnlock(hGlobal);
} }
@ -63,14 +65,14 @@ void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSiz
void* OsWin32_ConvertToNativePrinterInfo(void* data, unsigned int nDataSize) void* OsWin32_ConvertToNativePrinterInfo(void* data, unsigned int nDataSize)
{ {
HGLOBAL hGlobal = ::GlobalAlloc(GHND, nDataSize); // Alloco lo spazio necessario HGLOBAL hGlobal = ::GlobalAlloc(GHND, nDataSize); // Alloco lo spazio necessario
if (hGlobal != NULL) if (hGlobal != NULL)
{ {
PDEVMODE dm = (PDEVMODE)::GlobalLock(hGlobal); // Trasformo l'handle in puntatore PDEVMODE dm = (PDEVMODE)::GlobalLock(hGlobal); // Trasformo l'handle in puntatore
memcpy(dm, data, nDataSize); // Ricopio i dati della stampante memcpy(dm, data, nDataSize); // Ricopio i dati della stampante
adjust_extra(dm->dmDriverExtra); const unsigned int sz = AdjustDevmodePlease(dm); // Metto a posto parametri non standard
TestPaper(dm); // Controllo il formato della carta wxASSERT(nDataSize == sz);
::GlobalUnlock(hGlobal); // Libero il lock sull'handle ::GlobalUnlock(hGlobal); // Libero il lock sull'handle
} }
return hGlobal; return hGlobal;
} }
@ -168,9 +170,10 @@ int OsWin32_EnumerateSizes(WXHDC hDC, const char* name, long* sizes, short* scal
void* OsWin32_GetPrinterInfo(int& size, const char* printer) void* OsWin32_GetPrinterInfo(int& size, const char* printer)
{ {
char name[_MAX_PATH]; LPDEVMODE pdm = NULL;
size = 0; size = 0;
char name[_MAX_PATH];
if (printer == NULL || *printer == '\0') if (printer == NULL || *printer == '\0')
{ {
if (::GetProfileString("windows", "device", ",,,", name, sizeof(name)) == 0) if (::GetProfileString("windows", "device", ",,,", name, sizeof(name)) == 0)
@ -179,18 +182,18 @@ void* OsWin32_GetPrinterInfo(int& size, const char* printer)
if (comma) *comma = '\0'; if (comma) *comma = '\0';
} }
else else
strncpy(name, printer, sizeof(name)); wxStrncpy(name, printer, sizeof(name));
LPDEVMODE pdm = NULL; HANDLE hPrinter = NULL;
HANDLE hPrinter; if (::OpenPrinter(name, &hPrinter, NULL))
if (::OpenPrinter(name, &hPrinter, NULL) != 0)
{ {
size = ::DocumentProperties(0, hPrinter, name, NULL, NULL, 0); // Determina dimensione DEVMODE size = ::DocumentProperties(0, hPrinter, name, NULL, NULL, 0); // Determina dimensione DEVMODE
if (size > 0) if (size > 0)
{ {
pdm = (LPDEVMODE)new char[size]; // Alloca un DEVMODE sufficientemente capiente pdm = (LPDEVMODE)new BYTE[size]; // Alloca un DEVMODE sufficientemente capiente
memset(pdm, 0, size); memset(pdm, 0, size); // Azzera tutto per bene
::DocumentProperties(0, hPrinter, name, pdm, NULL, DM_OUT_BUFFER); // Legge DEVMODE ::DocumentProperties(0, hPrinter, name, pdm, NULL, DM_OUT_BUFFER); // Legge DEVMODE
size = AdjustDevmodePlease(pdm);
} }
else else
size = 0; size = 0;

View File

@ -62,6 +62,7 @@ XVTDLL BOOLEAN xvt_cb_put_data(CB_FORMAT cbfmt, char *name, long size, PICTURE
XVTDLL void xvt_ctl_check_radio_button(WINDOW Win, WINDOW* Wins, int NbrWindows); XVTDLL void xvt_ctl_check_radio_button(WINDOW Win, WINDOW* Wins, int NbrWindows);
XVTDLL WINDOW xvt_ctl_create_def(WIN_DEF *win_def_p, WINDOW parent_win, long app_data); XVTDLL WINDOW xvt_ctl_create_def(WIN_DEF *win_def_p, WINDOW parent_win, long app_data);
XVTDLL void xvt_ctl_set_checked(WINDOW Win, BOOLEAN Check); XVTDLL void xvt_ctl_set_checked(WINDOW Win, BOOLEAN Check);
XVTDLL void xvt_ctl_set_colors(WINDOW win, const XVT_COLOR_COMPONENT* colors, XVT_COLOR_ACTION action);
XVTDLL void xvt_debug_printf(const char* fmt, ...); XVTDLL void xvt_debug_printf(const char* fmt, ...);

View File

@ -322,12 +322,15 @@ struct s_treeview {
} CONTROL_INFO; } CONTROL_INFO;
typedef struct s_xvt_color_component { typedef struct s_xvt_color_component {
XVT_COLOR_TYPE type; /* color component being defined */ XVT_COLOR_TYPE type; /* color component being defined */
COLOR color; /* RGB color value */ COLOR color; /* RGB color value */
} XVT_COLOR_COMPONENT; } XVT_COLOR_COMPONENT;
typedef enum s_xvt_color_action {
XVT_COLOR_ACTION_SET,/* set the colors */
XVT_COLOR_ACTION_UNSET/* unset the colors */
} XVT_COLOR_ACTION;
typedef struct s_win_def { typedef struct s_win_def {
WIN_TYPE wtype; /* WC_* or WO_* type */ WIN_TYPE wtype; /* WC_* or WO_* type */

View File

@ -258,7 +258,7 @@ WINDOW xvt_ctl_create_def(WIN_DEF* win_def_p, WINDOW parent_win, long app_data)
SORRY_BOX(); break; SORRY_BOX(); break;
} }
if (win != NULL) if (win != NULL_WIN)
{ {
wxWindow& w = *wxStaticCast((wxObject*)win, wxWindow); wxWindow& w = *wxStaticCast((wxObject*)win, wxWindow);
const long flags = win_def_p->v.ctl.flags; const long flags = win_def_p->v.ctl.flags;
@ -273,31 +273,7 @@ WINDOW xvt_ctl_create_def(WIN_DEF* win_def_p, WINDOW parent_win, long app_data)
const wxFont& font = ((TFontId*)font_id)->Font(NULL, win); const wxFont& font = ((TFontId*)font_id)->Font(NULL, win);
w.SetFont(font); w.SetFont(font);
} }
xvt_ctl_set_colors(win, win_def_p->ctlcolors, XVT_COLOR_ACTION_SET);
// Cerco l'eventuale colore dello sfondo del controllo
const XVT_COLOR_COMPONENT* xcc = win_def_p->ctlcolors;
if (xcc != NULL)
{
for (int c = 0; xcc[c].type != XVT_COLOR_NULL; c++)
{
CAST_COLOR(xcc[c].color, rgb);
switch (xcc[c].type)
{
case XVT_COLOR_FOREGROUND:
w.SetForegroundColour(rgb);
break;
case XVT_COLOR_BACKGROUND:
if (win_def_p->wtype == WC_PUSHBUTTON)
w.SetOwnBackgroundColour(rgb);
break;
case XVT_COLOR_BLEND:
if (win_def_p->wtype != WC_PUSHBUTTON)
w.SetOwnBackgroundColour(rgb);
break;
default: break;
}
}
}
} }
return win; return win;
@ -308,7 +284,7 @@ void xvt_ctl_check_radio_button(WINDOW win, WINDOW* wins, int NbrWindows)
wxASSERT(NbrWindows >= 2); wxASSERT(NbrWindows >= 2);
for (int i = 0; i < NbrWindows; i++) for (int i = 0; i < NbrWindows; i++)
{ {
wxRadioButton* rb = wxDynamicCast((wxWindow*)wins[i], wxRadioButton); wxRadioButton* rb = wxDynamicCast((wxObject*)wins[i], wxRadioButton);
if (rb != NULL) if (rb != NULL)
rb->SetValue(win == wins[i]); rb->SetValue(win == wins[i]);
} }
@ -321,6 +297,41 @@ void xvt_ctl_set_checked(WINDOW win, BOOLEAN bCheck)
cb->SetValue(bCheck != 0); cb->SetValue(bCheck != 0);
} }
void xvt_ctl_set_colors(WINDOW win, const XVT_COLOR_COMPONENT* colors, XVT_COLOR_ACTION action)
{
wxWindow* w = wxDynamicCast((wxObject*)win, wxWindow);
if (w != NULL && colors != NULL)
{
for (int i = 0; colors[i].type; i++)
{
CAST_COLOR(colors[i].color, rgb);
if (action == XVT_COLOR_ACTION_SET)
{
switch(colors[i].type)
{
case XVT_COLOR_BACKGROUND:
if (w->IsKindOf(CLASSINFO(wxButton)))
w->SetOwnBackgroundColour(rgb);
break;
case XVT_COLOR_FOREGROUND:
w->SetForegroundColour(rgb);
break;
case XVT_COLOR_TROUGH:
if (!w->IsKindOf(CLASSINFO(wxButton)))
w->SetOwnBackgroundColour(rgb);
break;
default:
break;
}
}
else
{
// ???
}
}
}
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Buttons // Buttons
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -329,7 +340,7 @@ void xvt_btn_set_images(WINDOW win, XVT_IMAGE up, XVT_IMAGE down)
{ {
if (win != NULL_WIN && up != NULL) if (win != NULL_WIN && up != NULL)
{ {
wxBitmapButton* pb = wxDynamicCast((wxWindow*)win, wxBitmapButton); wxBitmapButton* pb = wxDynamicCast((wxObject*)win, wxBitmapButton);
if (pb != NULL) if (pb != NULL)
{ {
wxBitmap bmpUp(Image2Bitmap(up, TRUE)); wxBitmap bmpUp(Image2Bitmap(up, TRUE));
@ -1464,7 +1475,7 @@ BOOLEAN xvt_list_set_sel(WINDOW win, int index, BOOLEAN select)
// ToolBar // ToolBar
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
#if wxCHECK_VERSION(2,9,0) #if wxCHECK_VERSION(3,0,0)
#include <wx/aui/auibar.h> #include <wx/aui/auibar.h>
#define TwxToolBarBase wxAuiToolBar #define TwxToolBarBase wxAuiToolBar
#else #else
@ -1498,7 +1509,7 @@ void TwxToolBar::OnTool(wxCommandEvent& evt)
e.v.ctl.id = evt.GetId(); e.v.ctl.id = evt.GetId();
e.v.ctl.ci.type = WC_ICON; // WC_PUSHBUTTON entra in conflitto coi bottoni e.v.ctl.ci.type = WC_ICON; // WC_PUSHBUTTON entra in conflitto coi bottoni
e.v.ctl.ci.win = WINDOW(this); e.v.ctl.ci.win = WINDOW(this);
TwxWindow* win = (TwxWindow*)GetParent(); TwxWindow* win = wxStaticCast(GetParent(), TwxWindow);
win->DoXvtEvent(e); win->DoXvtEvent(e);
} }
@ -1614,7 +1625,8 @@ WINDOW xvt_toolbar_create(int cid, int left, int top, int right, int bottom, lon
} }
#endif #endif
TwxToolBar* tb = new TwxToolBar((wxWindow*)parent, cid, ptPos, wxDefaultSize, nStyle); wxWindow* pParent = wxStaticCast((wxObject*)parent, wxWindow);
TwxToolBar* tb = new TwxToolBar(pParent, cid, ptPos, wxDefaultSize, nStyle);
tb->SetToolBitmapSize(wxSize(nIcoSize, nIcoSize)); tb->SetToolBitmapSize(wxSize(nIcoSize, nIcoSize));
return (WINDOW)tb; return (WINDOW)tb;
} }

View File

@ -44,12 +44,12 @@ struct TPRINT_RCD : public PRINT_RCD
#pragma pack() #pragma pack()
#ifdef WIN32 #ifdef WIN32
void TPRINT_RCD::SetData(void* data, unsigned int nSize) void TPRINT_RCD::SetData(void* data, unsigned int nSize)
{ {
if (nSize <= sizeof(m_data)) if (nSize <= sizeof(m_data))
{ {
memset(m_data, 0, sizeof(m_data)); // Azzero per bene anche tutto quanto segue nSize
memcpy(m_data, data, nSize); memcpy(m_data, data, nSize);
m_size = nSize; m_size = nSize;
} }
@ -154,6 +154,11 @@ static void RCD2data(const TPRINT_RCD* prcd, wxPrintData& data)
wxWindowsPrintNativeData ndb; wxWindowsPrintNativeData ndb;
ndb.SetDevMode(OsWin32_ConvertToNativePrinterInfo((void*)prcd->m_data, prcd->m_size)); ndb.SetDevMode(OsWin32_ConvertToNativePrinterInfo((void*)prcd->m_data, prcd->m_size));
ndb.TransferTo(data); ndb.TransferTo(data);
// in assenza di PDEVNAMES aggiorno il nome in questo modo
char strName[MAX_PATH] = "";
xvt_print_get_name(prcd, strName, sizeof(strName));
data.SetPrinterName(strName);
#else #else
prcd->GetData(data.GetNativeData()); prcd->GetData(data.GetNativeData());
data.ConvertFromNative(); data.ConvertFromNative();
@ -190,16 +195,10 @@ wxDC* TwxPrintOut::CreateDC(const TPRINT_RCD* prcd, const char* title)
} }
else else
{ {
wxPrintData data; wxPrintData data;
RCD2data(prcd, data); RCD2data(prcd, data);
const wxString strName = PrinterName();
data.SetPrinterName(strName);
const bool ispdf = IsPDF(); const bool ispdf = IsPDF();
if (ispdf) if (ispdf)
dc = new TwxPDFDC(data, title); dc = new TwxPDFDC(data, title);
else else
@ -209,30 +208,37 @@ wxDC* TwxPrintOut::CreateDC(const TPRINT_RCD* prcd, const char* title)
dc = new wxPostScriptDC(data); dc = new wxPostScriptDC(data);
#endif #endif
} }
wxSize s = dc->GetPPI();
if (s.x > 0) if (dc->IsOk())
{
wxSize s = dc->GetPPI();
SetPPIPrinter(s.x, s.y); SetPPIPrinter(s.x, s.y);
s = dc->GetSize(); s = dc->GetSize();
if (s.x > 0)
SetPageSizePixels(s.x, s.y); SetPageSizePixels(s.x, s.y);
SetDC(dc); SetDC(dc);
wxWindow* pAbort = wxPrinterBase::sm_abortWindow; wxWindow* pAbort = wxPrinterBase::sm_abortWindow;
if (pAbort != NULL) if (pAbort != NULL)
{
wxWindow* pStatic = pAbort->FindWindow(wxID_STATIC);
if (pStatic != NULL)
{ {
wxString strPrompt = wxT("Stampa su "); wxWindow* pStatic = pAbort->FindWindow(wxID_STATIC);
if (IsPDF()) if (pStatic != NULL)
strPrompt += wxT("PDF"); {
else wxString strPrompt = wxT("Stampa su ");
strPrompt += PrinterName(); if (IsPDF())
pStatic->SetLabel(strPrompt); strPrompt += wxT("PDF");
else
strPrompt += PrinterName();
pStatic->SetLabel(strPrompt);
}
} }
} }
else
{
// delete dc;
dc = NULL;
}
return dc; return dc;
} }
@ -240,16 +246,18 @@ void TwxPrintOut::InitDC(const TPRINT_RCD* prcd, const char* title)
{ {
ResetDC(); ResetDC();
wxDC* dc = CreateDC(prcd, title); wxDC* dc = CreateDC(prcd, title);
if (dc != NULL)
wxSize s = dc->GetPPI(); {
if (s.x > 0) wxSize s = dc->GetPPI();
SetPPIPrinter(s.x, s.y); if (s.x > 0)
SetPPIPrinter(s.x, s.y);
s = dc->GetSize(); s = dc->GetSize();
if (s.x > 0) if (s.x > 0)
SetPageSizePixels(s.x, s.y); SetPageSizePixels(s.x, s.y);
SetDC(dc);
SetDC(dc); }
m_bBadDriver = dc == NULL;
} }
TwxPrintOut::TwxPrintOut(const TPRINT_RCD* prcd) TwxPrintOut::TwxPrintOut(const TPRINT_RCD* prcd)
@ -333,7 +341,6 @@ TwxPrintOut& TwxPrintOutCache::Get(const TPRINT_RCD* prcd)
} }
} }
wxASSERT(m_po != NULL); wxASSERT(m_po != NULL);
return *m_po; return *m_po;
} }
@ -491,9 +498,12 @@ long xvt_fmap_get_families(PRINT_RCD *precp, char **family_array, long max_famil
if (xvt_print_is_valid(precp)) if (xvt_print_is_valid(precp))
{ {
TwxPrintOut& po = m_PrintoutCache.Get((TPRINT_RCD*)precp); TwxPrintOut& po = m_PrintoutCache.Get((TPRINT_RCD*)precp);
size = OsWin32_EnumerateFamilies(po.GetDC()->GetHDC(), family_array, max_families); if (!po.HasBadDriver())
if (size == 0) {
po.SetBadDriver(true); size = OsWin32_EnumerateFamilies(po.GetDC()->GetHDC(), family_array, max_families);
if (size == 0)
po.SetBadDriver(true);
}
} }
else else
{ {
@ -566,8 +576,8 @@ PRINT_RCD* xvt_print_create_by_name(int* sizep, const char* name)
{ {
TPRINT_RCD* pr = NULL; TPRINT_RCD* pr = NULL;
*sizep = 0; *sizep = 0;
const bool ispdf = (name && *name) && (xvt_str_compare_ignoring_case(name, XVT_PDF_PRINTER_NAME) == 0);
const bool ispdf = name != NULL && xvt_str_compare_ignoring_case(name, XVT_PDF_PRINTER_NAME) == 0;
if (ispdf) if (ispdf)
name = NULL; name = NULL;
@ -596,8 +606,6 @@ PRINT_RCD* xvt_print_create_by_name(int* sizep, const char* name)
} }
WINDOW xvt_print_create_win(PRINT_RCD* precp, const char* title) WINDOW xvt_print_create_win(PRINT_RCD* precp, const char* title)
{ {
TPRINT_RCD* rcd = (TPRINT_RCD*)precp; TPRINT_RCD* rcd = (TPRINT_RCD*)precp;
@ -665,7 +673,7 @@ BOOLEAN xvt_print_is_valid(const PRINT_RCD* precp)
BOOLEAN ok = precp != NULL && precp->pr == NULL; BOOLEAN ok = precp != NULL && precp->pr == NULL;
if (ok) if (ok)
{ {
TPRINT_RCD* rcd = (TPRINT_RCD*)precp; const TPRINT_RCD* rcd = (const TPRINT_RCD*)precp;
#ifdef WIN32 #ifdef WIN32
ok = OsWin32_CheckPrinterInfo(rcd->m_data, rcd->m_size); ok = OsWin32_CheckPrinterInfo(rcd->m_data, rcd->m_size);
@ -953,7 +961,7 @@ SLIST xvt_print_list_devices()
BOOLEAN xvt_print_set_default_device(const char* name) BOOLEAN xvt_print_set_default_device(const char* name)
{ {
BOOLEAN ok = name && *name > ' '; BOOLEAN ok = name != NULL && *name > ' ';
#ifdef WIN32 #ifdef WIN32
if (ok) if (ok)
{ {
@ -972,7 +980,16 @@ BOOLEAN xvt_print_set_default_device(const char* name)
BOOLEAN xvt_print_get_default_device(char* name, int namesize) BOOLEAN xvt_print_get_default_device(char* name, int namesize)
{ {
/*
wxString strName, strPort;
const BOOLEAN ok = wxGetDefaultDeviceName(strName, strPort);
if (ok)
wxStrncpy(name, strName, namesize);
else
*name = '\0';
*/
bool ok = FALSE; bool ok = FALSE;
#ifdef WIN32 #ifdef WIN32
ok = ::GetProfileString ("windows", "device", ",,,", name, namesize) != 0; ok = ::GetProfileString ("windows", "device", ",,,", name, namesize) != 0;
#else #else