comparison dw.hpp @ 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
comparison
equal deleted inserted replaced
2920:c6b699a441fe 2921:235fef840df2
778 hpixmap = newpixmap; 778 hpixmap = newpixmap;
779 SetHandle(reinterpret_cast<void *>(newpixmap)); 779 SetHandle(reinterpret_cast<void *>(newpixmap));
780 } 780 }
781 HPIXMAP hpixmap; 781 HPIXMAP hpixmap;
782 unsigned long pwidth, pheight; 782 unsigned long pwidth, pheight;
783 bool hpmprot;
783 public: 784 public:
784 // Constructors 785 // Constructors
785 Pixmap(Render *window, unsigned long width, unsigned long height, int depth) { 786 Pixmap(Render *window, unsigned long width, unsigned long height, int depth) {
786 SetHPIXMAP(dw_pixmap_new(window ? window->GetHWND() : DW_NOHWND, width, height, depth)); 787 SetHPIXMAP(dw_pixmap_new(window ? window->GetHWND() : DW_NOHWND, width, height, depth));
787 pwidth = width; pheight = height; 788 pwidth = width; pheight = height;
789 hpmprot = false;
788 } 790 }
789 Pixmap(Render *window, unsigned long width, unsigned long height) { 791 Pixmap(Render *window, unsigned long width, unsigned long height) {
790 SetHPIXMAP(dw_pixmap_new(window ? window->GetHWND() : DW_NOHWND, width, height, 32)); 792 SetHPIXMAP(dw_pixmap_new(window ? window->GetHWND() : DW_NOHWND, width, height, 32));
791 pwidth = width; pheight = height; 793 pwidth = width; pheight = height;
794 hpmprot = false;
792 } 795 }
793 Pixmap(Render *window, const char *filename) { 796 Pixmap(Render *window, const char *filename) {
794 SetHPIXMAP(dw_pixmap_new_from_file(window ? window->GetHWND() : DW_NOHWND, filename)); 797 SetHPIXMAP(dw_pixmap_new_from_file(window ? window->GetHWND() : DW_NOHWND, filename));
798 hpmprot = false;
799 }
800 Pixmap(HPIXMAP hpm) {
801 SetHPIXMAP(hpm);
795 pwidth = hpixmap ? DW_PIXMAP_WIDTH(hpixmap) : 0; 802 pwidth = hpixmap ? DW_PIXMAP_WIDTH(hpixmap) : 0;
796 pheight = hpixmap ? DW_PIXMAP_HEIGHT(hpixmap) : 0; 803 pheight = hpixmap ? DW_PIXMAP_HEIGHT(hpixmap) : 0;
797 } 804 hpmprot = true;
805 }
806 // Destructor
807 ~Pixmap() { if(hpmprot == false) dw_pixmap_destroy(hpixmap); hpixmap = 0; }
798 808
799 // User functions 809 // User functions
800 HPIXMAP GetHPIXMAP() { return hpixmap; } 810 HPIXMAP GetHPIXMAP() { return hpixmap; }
801 void DrawPoint(int x, int y) { dw_draw_point(DW_NOHWND, hpixmap, x, y); } 811 void DrawPoint(int x, int y) { dw_draw_point(DW_NOHWND, hpixmap, x, y); }
802 void DrawLine(int x1, int y1, int x2, int y2) { dw_draw_line(DW_NOHWND, hpixmap, x1, y1, x2, y2); } 812 void DrawLine(int x1, int y1, int x2, int y2) { dw_draw_line(DW_NOHWND, hpixmap, x1, y1, x2, y2); }
1605 Notification(const char *title, const char *imagepath) { SetHWND(dw_notification_new(title, imagepath, NULL)); } 1615 Notification(const char *title, const char *imagepath) { SetHWND(dw_notification_new(title, imagepath, NULL)); }
1606 Notification(const char *title) { SetHWND(dw_notification_new(title, NULL, NULL)); } 1616 Notification(const char *title) { SetHWND(dw_notification_new(title, NULL, NULL)); }
1607 1617
1608 // User functions 1618 // User functions
1609 int Send() { int retval = dw_notification_send(hwnd); delete this; return retval; } 1619 int Send() { int retval = dw_notification_send(hwnd); delete this; return retval; }
1620 };
1621
1622 class Print : public Handle
1623 {
1624 private:
1625 HPRINT print;
1626 #ifdef DW_LAMBDA
1627 std::function<int(Pixmap *, int)> _ConnectDrawPage;
1628 #else
1629 int (*_ConnectDrawPage)(Pixmap *, int);
1630 #endif
1631 static int _OnDrawPage(HPRINT print, HPIXMAP hpm, int page_num, void *data) {
1632 int retval;
1633 Pixmap *pixmap = new Pixmap(hpm);
1634
1635 if(reinterpret_cast<Print *>(data)->_ConnectDrawPage)
1636 retval = reinterpret_cast<Print *>(data)->_ConnectDrawPage(pixmap, page_num);
1637 else
1638 retval = reinterpret_cast<Print *>(data)->OnDrawPage(pixmap, page_num);
1639
1640 delete pixmap;
1641 return retval;
1642 }
1643 public:
1644 // Constructors
1645 #ifdef DW_LAMBDA
1646 Print(const char *jobname, unsigned long flags, unsigned int pages, std::function<int(Pixmap *, int)> userfunc) {
1647 print = dw_print_new(jobname, flags, pages, DW_SIGNAL_FUNC(_OnDrawPage), this);
1648 SetHandle(reinterpret_cast<void *>(print));
1649 _ConnectDrawPage = userfunc;
1650 }
1651 #else
1652 Print(const char *jobname, unsigned long flags, unsigned int pages, int (*userfunc)(Pixmap *, int)) {
1653 print = dw_print_new(jobname, flags, pages, DW_SIGNAL_FUNC(_OnDrawPage), this);
1654 SetHandle(reinterpret_cast<void *>(print));
1655 _ConnectDrawPage = userfunc;
1656 }
1657 #endif
1658 // Destructor
1659 virtual ~Print() { if(print) dw_print_cancel(print); print = 0; }
1660
1661 // User functions
1662 void Cancel() { dw_print_cancel(print); delete this; }
1663 int Run(unsigned long flags) { int retval = dw_print_run(print, flags); delete this; return retval; }
1664 HPRINT GetHPRINT() { return print; }
1665 protected:
1666 // Our signal handler functions to be overriden...
1667 // If they are not overridden and an event is generated, remove the unused handler
1668 virtual int OnDrawPage(Pixmap *pixmap, int page_num) {
1669 if(print)
1670 dw_print_cancel(print);
1671 delete this;
1672 return FALSE;
1673 }
1610 }; 1674 };
1611 1675
1612 class App 1676 class App
1613 { 1677 {
1614 protected: 1678 protected: