Mercurial > dwindows
changeset 2921:235fef840df2
C++: Implement Print class and enable the print code in dwtestoo.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 29 Dec 2022 10:06:23 +0000 |
parents | c6b699a441fe |
children | 0919c2b82109 |
files | dw.hpp dwtestoo.cpp |
diffstat | 2 files changed, 65 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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<int(Pixmap *, int)> _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<Print *>(data)->_ConnectDrawPage) + retval = reinterpret_cast<Print *>(data)->_ConnectDrawPage(pixmap, page_num); + else + retval = reinterpret_cast<Print *>(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<int(Pixmap *, int)> userfunc) { + print = dw_print_new(jobname, flags, pages, DW_SIGNAL_FUNC(_OnDrawPage), this); + SetHandle(reinterpret_cast<void *>(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<void *>(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:
--- 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; });