/* Copyright (C) 2018-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: Bmpp4App.cpt */ /** @file Bmpp4App.cpp The Bmpp4App module. */ #line 151 "Bmpp4App.cpt" #include "wxbmpp.h" #ifndef DK4VERS_H_INCLUDED #include "dk4vers.h" #endif #ifndef DK4MEM_H_INCLUDED #include "dk4mem.h" #endif #ifndef DK4STRD_H_INCLUDED #include "dk4strd.h" #endif #ifndef DK4MPL_H_INCLUDED #include "dk4mpl.h" #endif #ifndef DK4PAPEA_H_INCLUDED #include "dk4papea.h" #endif #ifndef DK4GRCOA_H_INCLUDED #include "dk4grcoa.h" #endif #ifndef DK4STRX_H_INCLUDED #include "dk4strx.h" #endif #line 185 "Bmpp4App.cpt" /** Localized wxChar texts. */ static wxChar const * const wxbmpp_texts[] = { /* 0 */ wxT("File"), /* 1 */ wxT("Quit"), /* 2 */ wxT("Exit the application"), /* 3 */ wxT("Help"), /* 4 */ wxT("About"), /* 5 */ wxT("Show version information"), /* 6 */ wxT("Contents"), /* 7 */ wxT("Open table of contents"), /* 8 */ wxT("Ready"), /* 9 */ wxT("Copyright (c) "), /* 10 */ wxT("About "), /* 11 */ wxT("This program uses the following libraries:"), /* 12 */ wxT("See:"), /* 13 */ wxT("Make"), /* 14 */ wxT("Avoid unnecessary conversions"), /* 15 */ wxT("Color"), /* 16 */ wxT("Produce colored output"), /* 17 */ wxT("Output:"), /* 18 */ wxT("PDF object"), /* 19 */ wxT("PDF image"), /* 20 */ wxT("PDF document"), /* 21 */ wxT("EPS image"), /* 22 */ wxT("PS image"), /* 23 */ wxT("PS document"), /* 24 */ wxT("Set output file type and intended purpose"), /* 25 */ wxT("Interpolation"), /* 26 */ wxT("Set image interpolation flag"), /* 27 */ wxT("PS level:"), /* 28 */ wxT("2"), /* 29 */ wxT("3"), /* 30 */ wxT("Choose the PS language level"), /* 31 */ wxT("DSC"), /* 32 */ wxT("Write DSC comments to PS output"), /* 33 */ wxT("LZW"), /* 34 */ wxT("Allow LZW compression in PS level 2 output"), /* 35 */ wxT("JPEG DCT data"), /* 36 */ wxT("Directly re-use DCT encoded data from JPEG files"), /* 37 */ wxT("Paper size:"), /* 38 */ wxT("Specify paper size"), /* 39 */ wxT("Rotation"), /* 40 */ wxT("Allow image rotation for better page fitting"), /* 41 */ wxT("DCT interpolation"), /* 42 */ wxT("Allow image interpolation for directly re-used DCT data from JPEG files"), /* 43 */ wxT("Finishing:"), /* 44 */ wxT("Single side"), /* 45 */ wxT("Duplex"), /* 46 */ wxT("Duplex+Tumble"), /* 47 */ wxT("Choose single side printing or duplex printing like a book or calendar"), /* 48 */ wxT("Analyze bit depth"), /* 49 */ wxT("Attempt to reduce the number of bits per component"), /* 50 */ wxT("Resolution:"), /* 51 */ wxT("How to handle image resolution (use information from file, ignore or specify)"), /* 52 */ wxT("from file"), /* 53 */ wxT("ignore"), /* 54 */ wxT("specify"), /* 55 */ wxT("72.0"), /* 56 */ wxT(""), /* 57 */ wxT("Analyze color use"), /* 58 */ wxT("Analyze use of colors, switch output to gray if no colors used"), /* 59 */ wxT("Background:"), /* 60 */ wxT("Choose a background color"), /* 61 */ wxT("Enforce background"), /* 62 */ wxT("Use specified background color even if the input file provides a background"), /* 63 */ wxT("Analyze alpha"), /* 64 */ wxT("Analyze alpha channel data"), /* 65 */ wxT("Choose directory"), /* 66 */ wxT("Choose directory containing the images to convert"), /* 67 */ wxT("Conversion"), /* 68 */ wxT("Run"), /* 69 */ wxT("Run conversion"), /* 70 */ wxT("No directory specified yet!"), /* 71 */ wxT("Choose directory"), /* 72 */ wxT("Extras"), /* 73 */ wxT("Reset options"), /* 74 */ wxT("Reset options - are you sure?"), /* 75 */ wxT("Do you really want to reset all options to default values?"), /* 76 */ wxT("Luma BT.601"), /* 77 */ wxT("Luma short"), /* 78 */ wxT("Luma BT.709"), /* 79 */ wxT("fast"), /* 80 */ wxT("faster"), /* 81 */ wxT("average"), /* 82 */ wxT("desaturation"), /* 83 */ wxT("decomposition (min)"), /* 84 */ wxT("decomposition (med)"), /* 85 */ wxT("decomposition (max)"), /* 86 */ wxT("red"), /* 87 */ wxT("green"), /* 88 */ wxT("blue"), /* 89 */ wxT("RGB to gray:"), /* 90 */ wxT("Choose method for RGB to gray conversions"), /* 91 */ wxT("Success, application will exit."), /* 92 */ wxT("Error, application will exit."), /* 93 */ wxT("Reading image from file."), /* 94 */ wxT("Generating output."), /* 95 */ wxT("Writing output file."), /* 96 */ wxT("Cancel"), /* 97 */ wxT("Abort processing"), /* 98 */ wxT("Conversion progress"), /* 99 */ wxT("Not enough memory!\n"), /* 100 */ wxT("No files found in directory!\n"), /* 101 */ wxT("Finished."), /* 102 */ wxT("Error"), /* 103 */ wxT("Internal error (bug): No argv[0] argument found!"), /* 104 */ wxT("Internal error (bug): Application group name not found!"), /* 105 */ wxT("Illegal characters in language/options string!"), /* 106 */ wxT("Failed to parse command line options!"), /* 107 */ wxT("Too many paper sizes configured!"), /* 108 */ wxT("Illegal character(s) in paper size names!"), /* 109 */ wxT("Internal error (bug): Paper size without a name!"), /* 110 */ wxT("Failed to obtain paper size information!"), /* 111 */ wxT("Paper size not correctly configured!"), /* 112 */ wxT("Not enough memory (RAM)!\n"), /* 113 */ wxT(":\nERROR: Illegal character(s) in file name!\n"), /* 114 */ wxT(":\nERROR: File name too long!\n"), /* 115 */ wxT(":\nERROR: Empty directory\n"), /* 116 */ wxT(":\nERROR: Not enough memory!\n"), /* 117 */ wxT(":\nERROR: Failed to read image from file!\n"), /* 118 */ wxT(":\nERROR: Failed to open graphics output!\n"), /* 119 */ wxT(":\nERROR: Failed to select frame!\n"), /* 120 */ wxT(":\nERROR: Failed to write graphics output to file!\n"), /* 121 */ wxT("Aborted by user."), /* 122 */ wxT("Reset all options to default values"), NULL #line 532 "Bmpp4App.cpt" }; /** Non-localized wxChar texts. */ static wxChar const * const wxbmpp_nl_wx[] = { /* 0 */ wxT("wxbmpp"), /* 1 */ wxT("1.0.0"), /* 2 */ wxT("Dirk Krause"), /* 3 */ wxT("DKrause"), /* 4 */ wxT("aaaaa"), /* 5 */ wxT(""), /* 6 */ wxT(""), /* 7 */ wxT(" "), /* 8 */ wxT("\n"), /* 9 */ wxT("DK tools, wxWidgets, libpng, libjpeg, libtiff, zlib."), /* 10 */ wxT("http://sourceforge.net/p/dktools/wiki/Home/"), /* 11 */ wxT("http://www.wxwidgets.org"), /* 12 */ wxT("http://www.libpng.org/pub/png/libpng.html"), /* 13 */ wxT("http://www.ijg.org"), /* 14 */ wxT("http://www.remotesensing.org/libtiff"), /* 15 */ wxT("http://www.zlib.net"), /* 16 */ wxT("Error"), /* 17 */ wxT("Not enough memory (RAM)!"), NULL #line 592 "Bmpp4App.cpt" }; /** Non-localized dkChar texts. */ static dkChar const * const wxbmpp_nl_dk[] = { /* 0 */ dkT("dktools"), /* 1 */ dkT("wxbmpp4.str"), /* 2 */ dkT("wxbmpp.chm"), /* 3 */ dkT("wxbmpp.htb"), /* 4 */ dkT("dummy.txt"), NULL #line 621 "Bmpp4App.cpt" }; /** Empty dummy text for help text and license file for application. */ static dkChar const * dummy_text[] = { NULL #line 630 "Bmpp4App.cpt" }; static dkChar const versno_dk[] = { DKT_VERSION_DK }; /** Implementation of the wxApp functionality. */ #if wxCHECK_VERSION(3,0,0) wxIMPLEMENT_APP(Bmpp4App); #else IMPLEMENT_APP(Bmpp4App) #endif bool Bmpp4App::OnInit() { Bmpp4Frame *frame = NULL; wxChar const * const *localizedTexts = NULL; wxPNGHandler *phPng = NULL; wxXPMHandler *phXpm = NULL; wxICOHandler *phIco = NULL; wxArchiveFSHandler *phArchiveFS = NULL; bool back = false; #line 658 "Bmpp4App.cpt" /* Initialize members. */ pAh = NULL; pHc = NULL; bRestoreGx = true; bRestoreMake = true; bRestoreLocation = true; bMakeMode = false; bAutorun = false; pPaperSizes = NULL; pasPaperSizes = NULL; pDirname = NULL; szPaperSizes = 0; dk4gra_conf_init(&graconf); /* __CHANGE__ 009: Initialize further members here. */ /* Set up helper object. */ pAh = new Dk4WxApplicationHelper(); if (NULL == pAh) { ShowMemoryErrorMessage(); goto finished; } if (!(pAh->Initialize(argv[0], wxbmpp_nl_wx[3], wxbmpp_nl_dk[0]))) { 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; } phArchiveFS = new wxArchiveFSHandler(); if (NULL != phArchiveFS) { wxFileSystem::AddHandler(phArchiveFS); } else { ShowMemoryErrorMessage(); goto finished; } /* Set up help controller. */ pHc = new Dk4WxHelpController(); if (NULL == pHc) { ShowMemoryErrorMessage(); goto finished; } if (!(pHc->Initialize(pAh, wxbmpp_nl_dk[2], wxbmpp_nl_dk[3]))) { goto finished; } /* Attempt to obtain localized texts in users preferred language. */ localizedTexts = pAh->GetStringTable(wxbmpp_nl_dk[1], wxbmpp_texts); if(!(localizedTexts)) { localizedTexts = wxbmpp_texts; } /* Find list of paper sizes and process options. */ #line 746 "Bmpp4App.cpt" pasPaperSizes = new wxArrayString(); if (NULL == pasPaperSizes) { #line 748 "Bmpp4App.cpt" ShowMemoryErrorMessage(); goto finished; } #line 751 "Bmpp4App.cpt" if (!ProcessOptionsAndInitializeComponents(localizedTexts)) { #line 753 "Bmpp4App.cpt" goto finished; } #line 755 "Bmpp4App.cpt" /* Create and show frame. */ frame = new Bmpp4Frame( Bmpp4Frame_MainWindow, pAh, pHc, localizedTexts, wxbmpp_nl_wx, wxbmpp_nl_dk, &graconf, pasPaperSizes, pDirname, szPaperSizes, bRestoreGx, bRestoreMake, bRestoreLocation, bMakeMode, bAutorun, pPaperSizes ); if(!(frame)) { ShowMemoryErrorMessage(); goto finished; } /* Show frame, restore position and indicate success. */ frame->RestoreSettings(); frame->CorrectGUI(); frame->RestorePosition(); frame->Show(); back = true; /* Release resources if initialization failed. */ finished: if(!(back)) { if (NULL != pPaperSizes) { dk4mem_free(pPaperSizes); pPaperSizes = NULL; } if (NULL != pDirname) { #line 798 "Bmpp4App.cpt" dk4mem_free(pDirname); pDirname = NULL; } if (NULL != pasPaperSizes) { #line 802 "Bmpp4App.cpt" delete(pasPaperSizes); pasPaperSizes = NULL; #line 804 "Bmpp4App.cpt" } if (NULL != pHc) { pHc->Cleanup(); delete(pHc); pHc = NULL; } if (NULL != pAh) { pAh->Cleanup(); delete(pAh); pAh = NULL; } } #line 813 "Bmpp4App.cpt" return back; } int Bmpp4App::OnExit() { int back = 0; #line 824 "Bmpp4App.cpt" /* __CHANGE__ 009: Release resources allocated by further members. */ /* Release resources. */ if (NULL != pPaperSizes) { #line 831 "Bmpp4App.cpt" dk4mem_free(pPaperSizes); } if (NULL != pDirname) { #line 834 "Bmpp4App.cpt" dk4mem_free(pDirname); #line 835 "Bmpp4App.cpt" } if (NULL != pasPaperSizes) { #line 837 "Bmpp4App.cpt" delete(pasPaperSizes); pasPaperSizes = NULL; #line 839 "Bmpp4App.cpt" } if (NULL != pHc) { pHc->Cleanup(); delete(pHc); pHc = NULL; } if (NULL != pAh) { pAh->Cleanup(); delete(pAh); pAh = NULL; } /* __CHANGE__ 010: Set exit status code. */ #line 850 "Bmpp4App.cpt" return back; } void Bmpp4App::ShowMemoryErrorMessage(void) { const wxChar *s_title = NULL; const wxChar *s_text = NULL; if (NULL != pAh) { s_title = pAh->GetBasicString(6); s_text = pAh->GetBasicString(7); } if (NULL == s_title) { s_title = wxbmpp_nl_wx[16]; } if (NULL == s_text) { s_text = wxbmpp_nl_wx[17]; } wxMessageBox(s_text, s_title, (wxOK | wxCENTRE | wxICON_ERROR)); } bool Bmpp4App::ProcessOptionsAndInitializeComponents( wxChar const * const *localizedTexts ) { dkChar *margv[4]; dk4_app_t *app = NULL; dkChar *argv0 = NULL; dkChar const *pahargv0 = NULL; dkChar const *grname = NULL; bool back = false; #line 888 "Bmpp4App.cpt" pahargv0 = pAh->GetDkArgv0(); if (NULL == pahargv0) { #line 890 "Bmpp4App.cpt" /* ERROR: No argv[0] */ wxMessageBox( localizedTexts[103], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); goto finished; } #line 897 "Bmpp4App.cpt" argv0 = dk4str_dup(pahargv0, NULL); if (NULL == argv0) { #line 899 "Bmpp4App.cpt" /* ERROR: Memory */ ShowMemoryErrorMessage(); goto finished; } #line 903 "Bmpp4App.cpt" grname = pAh->GetDkGroupName(); if (NULL == grname) { #line 905 "Bmpp4App.cpt" /* ERROR: No group name */ wxMessageBox( localizedTexts[104], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); goto finished; } #line 912 "Bmpp4App.cpt" margv[0] = argv0; margv[1] = NULL; app = dk4app_open_silent( 1, margv, NULL, 0, grname, versno_dk, wxbmpp_nl_dk[4], dummy_text, dummy_text ); if (NULL == app) { #line 919 "Bmpp4App.cpt" /* ERROR: No app */ ShowMemoryErrorMessage(); goto finished; } #line 923 "Bmpp4App.cpt" back = ProcessOptions(app, localizedTexts); finished: if (NULL != app) { dk4app_close(app); } if (NULL != argv0) { dk4mem_free(argv0); } #line 933 "Bmpp4App.cpt" return back; } #if __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif static const wxCmdLineEntryDesc wxbmpp_cmd_line_desc[] = { { wxCMD_LINE_OPTION, wxT_2("l"), wxT_2("language"), wxT_2("Choose output language"), wxCMD_LINE_VAL_STRING }, { wxCMD_LINE_SWITCH, wxT_2("m"), wxT_2("make"), wxT_2("Run in make mode") }, { wxCMD_LINE_PARAM, NULL, NULL, wxT_2("input file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE } }; #if __GNUC__ #pragma GCC diagnostic pop #endif bool Bmpp4App::ProcessOptions(dk4_app_t *app, wxChar const * const *localizedTexts) { dkChar cobu[DK4_MAX_PATH]; wxChar buf[256]; wxString sLanguage(wxT("")); dk4_paper_size_collection_t *pscoll = NULL; dk4_paper_size_t const *paps = NULL; wxChar const *ptr = NULL; size_t i; int res = -1; bool back = false; #line 987 "Bmpp4App.cpt" { wxCmdLineParser parser(wxbmpp_cmd_line_desc, argc, argv); { wxLogNull log; res = parser.Parse(false); } if (0 == res) { back = true; if(parser.Found(wxT("l"), &sLanguage)) { bRestoreGx = false; bRestoreMake = false; bAutorun = true; wxCStrData sLanguageData = sLanguage.c_str(); ptr = (wxChar const *)sLanguageData; if (NULL != ptr) { if (pAh->StringToDk(cobu, DK4_MAX_PATH, ptr, NULL)) { (void)dk4gra_conf_setup( &graconf, cobu, 1, DK4_GRA_CONF_SCOPE_BMPP, app ); } else { /* ERROR: Conversion to dkChar string failed */ wxMessageBox( localizedTexts[105], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); back = false; goto finished; } } else { /* ERROR: No c_str (can not happen) */ back = false; goto finished; } } if(parser.Found(wxT("m"))) { bMakeMode = true; } if(parser.GetParamCount() > 0) { wxString cmdfn = parser.GetParam(0); wxFileName fn(cmdfn); fn.Normalize( wxPATH_NORM_LONG | wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE ); #if 0 /* 2018-04-04 Change Whenever wxbmpp is called with -l option the program starts a conversion automatically, now for both directories and single files. */ if (!(fn.FileExists())) { bAutorun = false; } #endif cmdfn = fn.GetFullPath(); wxCStrData fnstrdata = cmdfn.c_str(); ptr = (wxChar const *)fnstrdata; if (NULL != ptr) { pDirname = dk4strx_dup(ptr, NULL); if (NULL != pDirname) { bRestoreLocation = false; } else { /* ERROR: Memory */ ShowMemoryErrorMessage(); back = false; goto finished; } } } else { bAutorun = false; } } else { /* ERROR: In command line options */ wxMessageBox( localizedTexts[106], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); goto finished; } } pscoll = dk4app_get_paper_sizes(app); if (NULL != pscoll) { dk4papersize_coll_reset(pscoll); do { paps = dk4papersize_coll_next(pscoll); if (NULL != paps) { if (NULL != paps->name) { #line 1079 "Bmpp4App.cpt" if ( pAh->StringToWx( buf, DK4_SIZEOF(buf,wxChar), paps->name, NULL ) ) { if (SIZE_MAX > szPaperSizes) { pasPaperSizes->Add(buf); szPaperSizes += 1; } else { /* ERROR: Too many paper sizes */ wxMessageBox( localizedTexts[107], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); back = false; } } else { /* ERROR: Failed to convert to wx */ wxMessageBox( localizedTexts[108], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); back = false; } } else { /* ERROR: Paper size with no name (bug) */ wxMessageBox( localizedTexts[109], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); } } } while((NULL != paps) && (back)); if ((0 < szPaperSizes) && (back)) { pPaperSizes = dk4mem_new(dk4_paper_size_t,szPaperSizes,NULL); for (i = 0; i < szPaperSizes; i++) { pPaperSizes[i].name = NULL; pPaperSizes[i].name = NULL; pPaperSizes[i].w = 595.0; pPaperSizes[i].h = 842.0; pPaperSizes[i].i = 56.0; pPaperSizes[i].o = 28.0; pPaperSizes[i].b = 14.0; pPaperSizes[i].t = 14.0; } if (NULL != pPaperSizes) { dk4papersize_coll_reset(pscoll); i = 0; do { paps = dk4papersize_coll_next(pscoll); if (NULL != paps) { DK4_MEMCPY(&(pPaperSizes[i]),paps,sizeof(dk4_paper_size_t)); pPaperSizes[i].name = NULL; } i++; } while((NULL != paps) && (i < szPaperSizes)); } else { /* ERROR: Memory */ ShowMemoryErrorMessage(); back = false; } } dk4papersize_coll_close(pscoll); #line 1147 "Bmpp4App.cpt" } else { /* ERROR: Failed to obtain paper sizes collection */ wxMessageBox( localizedTexts[110], localizedTexts[102], (wxOK | wxCENTRE | wxICON_ERROR) ); back = false; } finished: #line 1159 "Bmpp4App.cpt" return back; } /* vim: set ai sw=4 ts=4 : */