%% options # __CHANGE__ 001: Correct copyright owner if necessary. copyright owner = Dirk Krause # __CHANGE__ 003: Correct copyright year(s) if necessary. copyright year = 2013-xxxx # __CHANGE__ 002: Correct license type if necessary. # Use "bsd", "gpl", "lgpl", or "commercial". license = bsd %% header /** Application class, derived from wxApp, one instance per program. */ class WinprintApp : public wxApp { protected: /** Helper object. */ DkWxAppHelper *pHelper; /** Controller fr online help. */ DkWxHelpController *helpController; /** Print configuration. */ dk3_print_conf_t *pc; /** Printer names. */ DK3_PCWXCHAR *pNames; /** Number of elements in pNames. */ size_t nNames; /** Index of the default printer in pNames. */ int nDefPrinter; protected: /** Show error message if there is not sufficient memory available. */ void ShowMemoryErrorMessage(void); public: /** Application initialization. @return true on success, false on error. */ virtual bool OnInit(); /** Application shutdown. @return 0 on success, any other value indicates an error. */ virtual int OnExit(); protected: /** Set printer names. */ void setPrinterNames(void); /** Release printer names. */ void releasePrinterNames(void); }; /** Declaration as the wxApp object. */ DECLARE_APP(WinprintApp) %% module #include "winprint.h" $!trace-include /** Localized wxChar texts. */ static wxChar const * winprint_texts[] = { $!string-table macro=wxT # # 0: Menu "File" # File # # 1: Menu item "File/Exit" # Exit # # 2: Tool tip text for menu item "File/Exit" # Exit the application # # 3: Menu "Help" # Help # # 4: Menu item "Help/About" # About # # 5: Tooltip text for menu item "Help/About" # Show version information # # 6: Menu item "Help/Contents" # Contents # # 7: Tooltip text for menu item "Help/Contents" # Open table of contents # # 8: Initial status text # Ready # # 9: Copyright notice. # Copyright (c) # # 10: Dialog box title "About ..." # About # # 11: This program uses the following libraries # This program uses the following libraries: # # 12: See # See: # # 13: __CHANGE__ 015: Text for dummy label, can be reused if lDummy removed. # Initializing print queue names. # # 14 # Success, exiting. # # 15 # Print # # 16 # Schedule a file to printer. # # 17 # Transferring print data. # # 18 # Choose file to print # # 19 # Aborted by user! # # 20 # Data transfer # # 21 # Cancel # # 22 # Cancel data transfer # # 23 # Data transfer cancelled, wait please... # # 24 # ERROR: Bad printer name! # # 25 # ERROR: No default printer found! # # 26 # ERROR: Failed to obtain print configuration! # # 27 # ERROR: Failed to create background thread! # # 28 # ERROR: Failed to create progress dialog! # # 29 # Error while scheduling print data # # 30 # Printer selection # # 31 # Choose printer: # # 32 # OK # # 33 # Use selected printer. # # 34 # Cancel # # 35 # Abort operation # # 36 # Choose the destination printer # # 37 # Transfer completed. # # 38 # Error while writing print data to job file! # # 39 # Failed to open input file! # # 40 # Failed to schedule job to print queue! # # 41 # Failed to create print job data file! # # 42 # Failed to add print job to queue! # # 43 # Failed to open print queue! # # 44 # File name conversion failed! # # 45 # Printer name conversion failed! $!end }; /** Non-localized wxChar texts. */ static wxChar const * winprint_nl_wx[] = { $!string-table macro=wxT # # 0: Program name. __CHANGE__ 004: Correct program name. # winprint # # 1: Program version. __CHANGE__ 005: Correct program version. # 1.0.0 # # 2: Copyright owner name. __CHANGE__ 001: Correct copyright owner name. # Dirk Krause # # 3: Software vendor name. __CHANGE__ 007: Correct software vendor name # if necessary. Must be one # string without spaces. # Dirk Krause # # 4: Resource name of Windows icon # aaaaa # # 5: Windows chm help file name # winprint.chm # # 6: non-Windows htb help file name # winprint.htb # # 7: Space # # # 8: Newline # \n # # 9 10 11 12 13 14 15: List of libraries used. # DK tools, wxWidgets, libpng, libjpeg, libtiff, zlib. http://dktools.sourceforge.net http://www.wxwidgets.org http://www.libpng.org/pub/png/libpng.html http://www.ijg.org http://www.remotesensing.org/libtiff http://www.zlib.net # # 16 17 # Error Not enough memory (RAM)! $!end }; /** Non-localized dkChar texts. */ static dkChar const * winprint_nl_dk[] = { $!string-table macro=dkT # # 0: Program group name. __CHANGE__ 006: Correct program group name. # dktools # # 1: String table name. # winprint.str $!end }; /** Implementation of the wxApp functionality. */ IMPLEMENT_APP(WinprintApp) bool WinprintApp::OnInit() { WinprintFrame *frame = NULL; /* Main window to show. */ wxChar const * const *localizedTexts = NULL; /* Localized texts. */ wxPNGHandler *phPng = NULL; wxXPMHandler *phXpm = NULL; wxICOHandler *phIco = NULL; wxZipFSHandler *phZipFs = NULL; bool back = false; $!trace-init winprint.deb /* Initialize members. */ nDefPrinter = 0; pNames = NULL; pHelper = NULL; helpController = NULL; pc = NULL; /* __CHANGE__ 009: Initialize further members here. */ /* Set up helper object. */ pHelper = new DkWxAppHelper( argv[0], winprint_nl_wx[3], winprint_nl_dk[0] ); if(!(pHelper)) { ShowMemoryErrorMessage(); goto finished; } if(!(pHelper->checkSetup())) { goto finished; } /* Add image and file system handlers for online help. */ phPng = new wxPNGHandler(); if (NULL != phPng) { wxImage::AddHandler(phPng); } else { ShowMemoryErrorMessage(); goto finished; } phXpm = new wxXPMHandler(); if (NULL != phXpm) { wxImage::AddHandler(phXpm); } else { ShowMemoryErrorMessage(); goto finished; } phIco = new wxICOHandler(); if (NULL != phIco) { wxImage::AddHandler(phIco); } else { ShowMemoryErrorMessage(); goto finished; } phZipFs = new wxZipFSHandler(); if (NULL != phZipFs) { wxFileSystem::AddHandler(phZipFs); } else { ShowMemoryErrorMessage(); goto finished; } localizedTexts = pHelper->getStringTable(winprint_texts, winprint_nl_dk[1]); if(!(localizedTexts)) { localizedTexts = winprint_texts; } /* Set up online help controller. */ helpController = new DkWxHelpController( pHelper, winprint_nl_wx[5], winprint_nl_wx[6] ); if(!(helpController)) { ShowMemoryErrorMessage(); goto finished; } pc = dk3print_conf_open(pHelper->getApp(), 0); if(!(pc)) { ShowMemoryErrorMessage(); goto finished; } setPrinterNames(); if(!(pNames)) { ShowMemoryErrorMessage(); goto finished; } /* Create and show frame. */ frame = new WinprintFrame( WinprintFrame_MainWindow, pHelper, helpController, argc, argv, localizedTexts, winprint_nl_wx, winprint_nl_dk, pc, pNames, nNames, nDefPrinter ); if(!(frame)) { ShowMemoryErrorMessage(); goto finished; } frame->Show(); frame->restorePosition(); back = true; /* Release resources if initialization failed. */ finished: if(!(back)) { if(pNames) { releasePrinterNames(); } if(helpController) { delete(helpController); helpController = NULL; } if(pHelper) { delete(pHelper); pHelper = NULL; } if(pc) { dk3print_conf_close(pc); pc = NULL; } } return back; } int WinprintApp::OnExit() { int back = 0; /* __CHANGE__ 009: Release resources allocated by further members. */ /* Release resources. */ if(pNames) { releasePrinterNames(); } if(pc) { dk3print_conf_close(pc); pc = NULL; } if(helpController) { delete(helpController); helpController = NULL; } if(pHelper) { delete(pHelper); pHelper = NULL; } $!trace-end /* __CHANGE__ 010: Set back to exit status code. */ return back; } void WinprintApp::setPrinterNames(void) { wxChar buf[512]; /* Conversion buffer. */ void *vptr; /* Printer as returned from iterator. */ dk3_printer_t *pr; /* Current printer. */ DK3_PCWXCHAR *wxptr; /* Printer name in wxChar. */ size_t n = 0; /* Number of printers. */ size_t i; /* Index of current printer. */ int wxe; /* wxChar encoding. */ int dke; /* dkChar encoding. */ if(pc) { dk3sto_it_reset(pc->iPrinters); while(NULL != (vptr = dk3sto_it_next(pc->iPrinters))) { pr = (dk3_printer_t *)vptr; if(DK3_PRINTER_TYPE_WINDOWS == pr->t_p) { if(pr->name) { n++; } } } if(n) { pNames = dk3_new_app(DK3_PCWXCHAR,n,pHelper->getApp()); if(pNames) { wxptr = pNames; for(i = 0; i < n; i++) { *(wxptr++) = NULL; } i = 0; wxptr = pNames; dk3sto_it_reset(pc->iPrinters); while(NULL != (vptr = dk3sto_it_next(pc->iPrinters))) { pr = (dk3_printer_t *)vptr; if(DK3_PRINTER_TYPE_WINDOWS == pr->t_p) { if(pr->name) { wxe = pHelper->getWxEncoding(); dke = pHelper->getDkEncoding(); if(dk3wxs_from_dkstr(buf,DK3_SIZEOF(buf,wxChar),wxe,pr->name,dke)) { *wxptr = dk3wxs_dup(buf); if(*wxptr) { if(pc->defPrinter) { if((pc->defPrinter)->name) { if(dk3str_cmp(pr->name, (pc->defPrinter)->name) == 0) { nDefPrinter = (int)i; } } } wxptr++; i++; } } } } } nNames = i; } } } } void WinprintApp::releasePrinterNames(void) { DK3_PCWXCHAR *wxptr; /* Current printer name to release. */ size_t i; /* Index of current printer name. */ $? "+ WinprintApp::releasePrinterNames" if(pNames) { wxptr = pNames; for(i = 0; i < nNames; i++) { if(*wxptr) { $? ". Printer name \"%ls\"", *wxptr dk3_release(*wxptr); wxptr++; } } dk3_delete(pNames); pNames = NULL; } $? "- WinprintApp::releasePrinterNames" } void WinprintApp::ShowMemoryErrorMessage(void) { const wxChar *s_title = NULL; const wxChar *s_text = NULL; if (NULL != pHelper) { s_title = pHelper->getBasicString(3); s_text = pHelper->getBasicString(9); } if (NULL == s_title) { s_title = winprint_nl_wx[16]; } if (NULL == s_text) { s_text = winprint_nl_wx[17]; } wxMessageBox(s_text, s_title, (wxOK | wxCENTRE | wxICON_ERROR)); }