diff --git a/xvaga/oswin32.cpp b/xvaga/oswin32.cpp index 4a7bbef4e..ee32e98b9 100755 --- a/xvaga/oswin32.cpp +++ b/xvaga/oswin32.cpp @@ -28,8 +28,16 @@ bool OsWin32_CheckPrinterInfo(const void* data, unsigned int size) 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); if (paper == NULL) { @@ -37,12 +45,8 @@ static void TestPaper(PDEVMODE dm) wxThePrintPaperDatabase->WXADDPAPER((wxPaperSize)dm->dmPaperSize /*wxPAPER_NONE*/, dm->dmPaperSize, dm->dmFormName, dm->dmPaperWidth, dm->dmPaperLength); } -} -static void adjust_extra(WORD& w) -{ - if (w > 4096) - w = 0; + return dm->dmSize + dm->dmDriverExtra; } void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSize) @@ -51,10 +55,8 @@ void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSiz if (hGlobal != NULL) { PDEVMODE dm = (PDEVMODE)::GlobalLock(hGlobal); - adjust_extra(dm->dmDriverExtra); - nDataSize = dm->dmSize+dm->dmDriverExtra; + nDataSize = AdjustDevmodePlease(dm); buff = new char[nDataSize]; - TestPaper(dm); memcpy(buff, dm, nDataSize); ::GlobalUnlock(hGlobal); } @@ -63,14 +65,14 @@ void* OsWin32_ConvertFromNativePrinterInfo(void* hGlobal, unsigned int& nDataSiz 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) { - PDEVMODE dm = (PDEVMODE)::GlobalLock(hGlobal); // Trasformo l'handle in puntatore - memcpy(dm, data, nDataSize); // Ricopio i dati della stampante - adjust_extra(dm->dmDriverExtra); - TestPaper(dm); // Controllo il formato della carta - ::GlobalUnlock(hGlobal); // Libero il lock sull'handle + PDEVMODE dm = (PDEVMODE)::GlobalLock(hGlobal); // Trasformo l'handle in puntatore + memcpy(dm, data, nDataSize); // Ricopio i dati della stampante + const unsigned int sz = AdjustDevmodePlease(dm); // Metto a posto parametri non standard + wxASSERT(nDataSize == sz); + ::GlobalUnlock(hGlobal); // Libero il lock sull'handle } 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) { - char name[_MAX_PATH]; - + LPDEVMODE pdm = NULL; size = 0; + + char name[_MAX_PATH]; if (printer == NULL || *printer == '\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'; } else - strncpy(name, printer, sizeof(name)); + wxStrncpy(name, printer, sizeof(name)); - LPDEVMODE pdm = NULL; - HANDLE hPrinter; - if (::OpenPrinter(name, &hPrinter, NULL) != 0) + HANDLE hPrinter = NULL; + if (::OpenPrinter(name, &hPrinter, NULL)) { size = ::DocumentProperties(0, hPrinter, name, NULL, NULL, 0); // Determina dimensione DEVMODE if (size > 0) { - pdm = (LPDEVMODE)new char[size]; // Alloca un DEVMODE sufficientemente capiente - memset(pdm, 0, size); + pdm = (LPDEVMODE)new BYTE[size]; // Alloca un DEVMODE sufficientemente capiente + memset(pdm, 0, size); // Azzera tutto per bene ::DocumentProperties(0, hPrinter, name, pdm, NULL, DM_OUT_BUFFER); // Legge DEVMODE + size = AdjustDevmodePlease(pdm); } else size = 0; diff --git a/xvaga/xvt.h b/xvaga/xvt.h index da77bd54d..3825b3321 100755 --- a/xvaga/xvt.h +++ b/xvaga/xvt.h @@ -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 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_colors(WINDOW win, const XVT_COLOR_COMPONENT* colors, XVT_COLOR_ACTION action); XVTDLL void xvt_debug_printf(const char* fmt, ...); diff --git a/xvaga/xvt_type.h b/xvaga/xvt_type.h index 18dc64553..4b44849d9 100755 --- a/xvaga/xvt_type.h +++ b/xvaga/xvt_type.h @@ -322,12 +322,15 @@ struct s_treeview { } CONTROL_INFO; typedef struct s_xvt_color_component { - XVT_COLOR_TYPE type; /* color component being defined */ COLOR color; /* RGB color value */ - } 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 { WIN_TYPE wtype; /* WC_* or WO_* type */ diff --git a/xvaga/xvtctl.cpp b/xvaga/xvtctl.cpp index c91c061b4..7552636ae 100755 --- a/xvaga/xvtctl.cpp +++ b/xvaga/xvtctl.cpp @@ -258,7 +258,7 @@ WINDOW xvt_ctl_create_def(WIN_DEF* win_def_p, WINDOW parent_win, long app_data) SORRY_BOX(); break; } - if (win != NULL) + if (win != NULL_WIN) { wxWindow& w = *wxStaticCast((wxObject*)win, wxWindow); 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); w.SetFont(font); } - - // 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; - } - } - } + xvt_ctl_set_colors(win, win_def_p->ctlcolors, XVT_COLOR_ACTION_SET); } return win; @@ -308,7 +284,7 @@ void xvt_ctl_check_radio_button(WINDOW win, WINDOW* wins, int NbrWindows) wxASSERT(NbrWindows >= 2); for (int i = 0; i < NbrWindows; i++) { - wxRadioButton* rb = wxDynamicCast((wxWindow*)wins[i], wxRadioButton); + wxRadioButton* rb = wxDynamicCast((wxObject*)wins[i], wxRadioButton); if (rb != NULL) rb->SetValue(win == wins[i]); } @@ -321,6 +297,41 @@ void xvt_ctl_set_checked(WINDOW win, BOOLEAN bCheck) 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 /////////////////////////////////////////////////////////// @@ -329,7 +340,7 @@ void xvt_btn_set_images(WINDOW win, XVT_IMAGE up, XVT_IMAGE down) { if (win != NULL_WIN && up != NULL) { - wxBitmapButton* pb = wxDynamicCast((wxWindow*)win, wxBitmapButton); + wxBitmapButton* pb = wxDynamicCast((wxObject*)win, wxBitmapButton); if (pb != NULL) { wxBitmap bmpUp(Image2Bitmap(up, TRUE)); @@ -1464,7 +1475,7 @@ BOOLEAN xvt_list_set_sel(WINDOW win, int index, BOOLEAN select) // ToolBar /////////////////////////////////////////////////////////// -#if wxCHECK_VERSION(2,9,0) +#if wxCHECK_VERSION(3,0,0) #include #define TwxToolBarBase wxAuiToolBar #else @@ -1498,7 +1509,7 @@ void TwxToolBar::OnTool(wxCommandEvent& evt) e.v.ctl.id = evt.GetId(); e.v.ctl.ci.type = WC_ICON; // WC_PUSHBUTTON entra in conflitto coi bottoni e.v.ctl.ci.win = WINDOW(this); - TwxWindow* win = (TwxWindow*)GetParent(); + TwxWindow* win = wxStaticCast(GetParent(), TwxWindow); win->DoXvtEvent(e); } @@ -1614,7 +1625,8 @@ WINDOW xvt_toolbar_create(int cid, int left, int top, int right, int bottom, lon } #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)); return (WINDOW)tb; } diff --git a/xvaga/xvtextra.cpp b/xvaga/xvtextra.cpp index 2f56599b7..b70027cb9 100755 --- a/xvaga/xvtextra.cpp +++ b/xvaga/xvtextra.cpp @@ -44,12 +44,12 @@ struct TPRINT_RCD : public PRINT_RCD #pragma pack() - #ifdef WIN32 void TPRINT_RCD::SetData(void* data, unsigned int nSize) { 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); m_size = nSize; } @@ -154,6 +154,11 @@ static void RCD2data(const TPRINT_RCD* prcd, wxPrintData& data) wxWindowsPrintNativeData ndb; ndb.SetDevMode(OsWin32_ConvertToNativePrinterInfo((void*)prcd->m_data, prcd->m_size)); 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 prcd->GetData(data.GetNativeData()); data.ConvertFromNative(); @@ -190,16 +195,10 @@ wxDC* TwxPrintOut::CreateDC(const TPRINT_RCD* prcd, const char* title) } else { - wxPrintData data; - + wxPrintData data; RCD2data(prcd, data); - const wxString strName = PrinterName(); - - data.SetPrinterName(strName); - const bool ispdf = IsPDF(); - if (ispdf) dc = new TwxPDFDC(data, title); else @@ -209,30 +208,37 @@ wxDC* TwxPrintOut::CreateDC(const TPRINT_RCD* prcd, const char* title) dc = new wxPostScriptDC(data); #endif } - wxSize s = dc->GetPPI(); - if (s.x > 0) + + if (dc->IsOk()) + { + wxSize s = dc->GetPPI(); SetPPIPrinter(s.x, s.y); - s = dc->GetSize(); - if (s.x > 0) + s = dc->GetSize(); SetPageSizePixels(s.x, s.y); - SetDC(dc); - - wxWindow* pAbort = wxPrinterBase::sm_abortWindow; - if (pAbort != NULL) - { - wxWindow* pStatic = pAbort->FindWindow(wxID_STATIC); - if (pStatic != NULL) + SetDC(dc); + + wxWindow* pAbort = wxPrinterBase::sm_abortWindow; + if (pAbort != NULL) { - wxString strPrompt = wxT("Stampa su "); - if (IsPDF()) - strPrompt += wxT("PDF"); - else - strPrompt += PrinterName(); - pStatic->SetLabel(strPrompt); + wxWindow* pStatic = pAbort->FindWindow(wxID_STATIC); + if (pStatic != NULL) + { + wxString strPrompt = wxT("Stampa su "); + if (IsPDF()) + strPrompt += wxT("PDF"); + else + strPrompt += PrinterName(); + pStatic->SetLabel(strPrompt); + } } } + else + { +// delete dc; + dc = NULL; + } return dc; } @@ -240,16 +246,18 @@ void TwxPrintOut::InitDC(const TPRINT_RCD* prcd, const char* title) { ResetDC(); wxDC* dc = CreateDC(prcd, title); - - wxSize s = dc->GetPPI(); - if (s.x > 0) - SetPPIPrinter(s.x, s.y); + if (dc != NULL) + { + wxSize s = dc->GetPPI(); + if (s.x > 0) + SetPPIPrinter(s.x, s.y); - s = dc->GetSize(); - if (s.x > 0) - SetPageSizePixels(s.x, s.y); - - SetDC(dc); + s = dc->GetSize(); + if (s.x > 0) + SetPageSizePixels(s.x, s.y); + SetDC(dc); + } + m_bBadDriver = dc == NULL; } TwxPrintOut::TwxPrintOut(const TPRINT_RCD* prcd) @@ -333,7 +341,6 @@ TwxPrintOut& TwxPrintOutCache::Get(const TPRINT_RCD* prcd) } } wxASSERT(m_po != NULL); - 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)) { TwxPrintOut& po = m_PrintoutCache.Get((TPRINT_RCD*)precp); - size = OsWin32_EnumerateFamilies(po.GetDC()->GetHDC(), family_array, max_families); - if (size == 0) - po.SetBadDriver(true); + if (!po.HasBadDriver()) + { + size = OsWin32_EnumerateFamilies(po.GetDC()->GetHDC(), family_array, max_families); + if (size == 0) + po.SetBadDriver(true); + } } else { @@ -566,8 +576,8 @@ PRINT_RCD* xvt_print_create_by_name(int* sizep, const char* name) { TPRINT_RCD* pr = NULL; *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) 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) - - { 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; if (ok) { - TPRINT_RCD* rcd = (TPRINT_RCD*)precp; + const TPRINT_RCD* rcd = (const TPRINT_RCD*)precp; #ifdef WIN32 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 ok = name && *name > ' '; + BOOLEAN ok = name != NULL && *name > ' '; #ifdef WIN32 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) { +/* + wxString strName, strPort; + const BOOLEAN ok = wxGetDefaultDeviceName(strName, strPort); + if (ok) + wxStrncpy(name, strName, namesize); + else + *name = '\0'; +*/ bool ok = FALSE; + #ifdef WIN32 ok = ::GetProfileString ("windows", "device", ",,,", name, namesize) != 0; #else