# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1672308383 0 # Node ID 235fef840df24b374473f35583288de7b717d219 # Parent c6b699a441feef8c3a75b7f4ad01f1c7f264f287 C++: Implement Print class and enable the print code in dwtestoo. diff -r c6b699a441fe -r 235fef840df2 dw.hpp --- a/dw.hpp Wed Dec 28 21:13:04 2022 +0000 +++ b/dw.hpp Thu Dec 29 10:06:23 2022 +0000 @@ -780,21 +780,31 @@ } HPIXMAP hpixmap; unsigned long pwidth, pheight; + bool hpmprot; public: // Constructors Pixmap(Render *window, unsigned long width, unsigned long height, int depth) { SetHPIXMAP(dw_pixmap_new(window ? window->GetHWND() : DW_NOHWND, width, height, depth)); pwidth = width; pheight = height; + hpmprot = false; } Pixmap(Render *window, unsigned long width, unsigned long height) { SetHPIXMAP(dw_pixmap_new(window ? window->GetHWND() : DW_NOHWND, width, height, 32)); pwidth = width; pheight = height; + hpmprot = false; } Pixmap(Render *window, const char *filename) { SetHPIXMAP(dw_pixmap_new_from_file(window ? window->GetHWND() : DW_NOHWND, filename)); + hpmprot = false; + } + Pixmap(HPIXMAP hpm) { + SetHPIXMAP(hpm); pwidth = hpixmap ? DW_PIXMAP_WIDTH(hpixmap) : 0; pheight = hpixmap ? DW_PIXMAP_HEIGHT(hpixmap) : 0; + hpmprot = true; } + // Destructor + ~Pixmap() { if(hpmprot == false) dw_pixmap_destroy(hpixmap); hpixmap = 0; } // User functions HPIXMAP GetHPIXMAP() { return hpixmap; } @@ -1609,6 +1619,60 @@ int Send() { int retval = dw_notification_send(hwnd); delete this; return retval; } }; +class Print : public Handle +{ +private: + HPRINT print; +#ifdef DW_LAMBDA + std::function _ConnectDrawPage; +#else + int (*_ConnectDrawPage)(Pixmap *, int); +#endif + static int _OnDrawPage(HPRINT print, HPIXMAP hpm, int page_num, void *data) { + int retval; + Pixmap *pixmap = new Pixmap(hpm); + + if(reinterpret_cast(data)->_ConnectDrawPage) + retval = reinterpret_cast(data)->_ConnectDrawPage(pixmap, page_num); + else + retval = reinterpret_cast(data)->OnDrawPage(pixmap, page_num); + + delete pixmap; + return retval; + } +public: + // Constructors +#ifdef DW_LAMBDA + Print(const char *jobname, unsigned long flags, unsigned int pages, std::function userfunc) { + print = dw_print_new(jobname, flags, pages, DW_SIGNAL_FUNC(_OnDrawPage), this); + SetHandle(reinterpret_cast(print)); + _ConnectDrawPage = userfunc; + } +#else + Print(const char *jobname, unsigned long flags, unsigned int pages, int (*userfunc)(Pixmap *, int)) { + print = dw_print_new(jobname, flags, pages, DW_SIGNAL_FUNC(_OnDrawPage), this); + SetHandle(reinterpret_cast(print)); + _ConnectDrawPage = userfunc; + } +#endif + // Destructor + virtual ~Print() { if(print) dw_print_cancel(print); print = 0; } + + // User functions + void Cancel() { dw_print_cancel(print); delete this; } + int Run(unsigned long flags) { int retval = dw_print_run(print, flags); delete this; return retval; } + HPRINT GetHPRINT() { return print; } +protected: + // Our signal handler functions to be overriden... + // If they are not overridden and an event is generated, remove the unused handler + virtual int OnDrawPage(Pixmap *pixmap, int page_num) { + if(print) + dw_print_cancel(print); + delete this; + return FALSE; + } +}; + class App { protected: diff -r c6b699a441fe -r 235fef840df2 dwtestoo.cpp --- a/dwtestoo.cpp Wed Dec 28 21:13:04 2022 +0000 +++ b/dwtestoo.cpp Thu Dec 29 10:06:23 2022 +0000 @@ -798,9 +798,8 @@ return TRUE; }); - printbutton->ConnectClicked([]() -> int + printbutton->ConnectClicked([this]() -> int { -#if 0 // TODO DW::Print *print = new DW::Print("DWTest Job", 0, 2, [this](DW::Pixmap *pixmap, int page_num) -> int { pixmap->SetFont(FIXEDFONT); @@ -843,7 +842,6 @@ return TRUE; }); print->Run(0); -#endif return TRUE; });