Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 2007, Digital Signal Processing Laboratory, Universita' degli studi di Perugia (UPG), Italy
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
  15.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24.  * POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Name:        sashtest.cpp
  28. // Purpose:     Layout/sash sample
  29. // Author:      Julian Smart
  30. // Modified by:
  31. // Created:     04/01/98
  32. // RCS-ID:      $Id: sashtest.cpp,v 1.18 2005/08/23 15:54:35 ABX Exp $
  33. // Copyright:   (c) Julian Smart
  34. // Licence:     wxWindows license
  35. /////////////////////////////////////////////////////////////////////////////
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Name:        treetest.cpp
  38. // Purpose:     wxTreeCtrl sample
  39. // Author:      Julian Smart
  40. // Modified by:
  41. // Created:     04/01/98
  42. // RCS-ID:      $Id: treetest.cpp,v 1.110 2006/11/04 11:26:51 VZ Exp $
  43. // Copyright:   (c) Julian Smart
  44. // Licence:     wxWindows license
  45. /////////////////////////////////////////////////////////////////////////////
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Name:        dialogs.cpp
  48. // Purpose:     Common dialogs demo
  49. // Author:      Julian Smart
  50. // Modified by: ABX (2004) - adjustements for conditional building + new menu
  51. // Created:     04/01/98
  52. // RCS-ID:      $Id: dialogs.cpp,v 1.163 2006/11/04 10:57:24 VZ Exp $
  53. // Copyright:   (c) Julian Smart
  54. // Licence:     wxWindows license
  55. /////////////////////////////////////////////////////////////////////////////
  56. /////////////////////////////////////////////////////////////////////////////
  57. // Name:        thread.cpp
  58. // Purpose:     wxWidgets thread sample
  59. // Author:      Guilhem Lavaux, Vadim Zeitlin
  60. // Modified by:
  61. // Created:     06/16/98
  62. // RCS-ID:      $Id: thread.cpp,v 1.26 2006/10/02 05:36:28 PC Exp $
  63. // Copyright:   (c) 1998-2002 wxWidgets team
  64. // Licence:     wxWindows license
  65. /////////////////////////////////////////////////////////////////////////////
  66. ///////////////////////////////////////////////////////////////////////////////
  67. // Name:        samples/image/image.cpp
  68. // Purpose:     sample showing operations with wxImage
  69. // Author:      Robert Roebling
  70. // Modified by:
  71. // Created:     1998
  72. // RCS-ID:      $Id: image.cpp,v 1.120 2006/12/06 17:13:11 VZ Exp $
  73. // Copyright:   (c) 1998-2005 Robert Roebling
  74. // License:     wxWindows licence
  75. ///////////////////////////////////////////////////////////////////////////////
  76. /////////////////////////////////////////////////////////////////////////////
  77. // Name:        samples/console/console.cpp
  78. // Purpose:     A sample console (as opposed to GUI) program using wxWidgets
  79. // Author:      Vadim Zeitlin
  80. // Modified by:
  81. // Created:     04.10.99
  82. // RCS-ID:      $Id: console.cpp,v 1.206 2006/11/12 19:55:19 VZ Exp $
  83. // Copyright:   (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  84. // Licence:     wxWindows license
  85. /////////////////////////////////////////////////////////////////////////////
  86. /////////////////////////////////////////////////////////////////////////////
  87. // Name:        samples/notebook/notebook.cpp
  88. // Purpose:     a sample demonstrating notebook usage
  89. // Author:      Julian Smart
  90. // Modified by: Dimitri Schoolwerth
  91. // Created:     26/10/98
  92. // RCS-ID:      $Id: notebook.cpp,v 1.49 2006/11/04 18:24:07 RR Exp $
  93. // Copyright:   (c) 1998-2002 wxWidgets team
  94. // License:     wxWindows license
  95. /////////////////////////////////////////////////////////////////////////////
  96. /////////////////////////////////////////////////////////////////////////////
  97. // Name:        dialogs.cpp
  98. // Purpose:     Common dialogs demo
  99. // Author:      Julian Smart
  100. // Modified by: ABX (2004) - adjustements for conditional building + new menu
  101. // Created:     04/01/98
  102. // RCS-ID:      $Id: dialogs.cpp,v 1.163 2006/11/04 10:57:24 VZ Exp $
  103. // Copyright:   (c) Julian Smart
  104. // Licence:     wxWindows license
  105. /////////////////////////////////////////////////////////////////////////////
  106. /////////////////////////////////////////////////////////////////////////////
  107. // Name:        dnd.cpp
  108. // Purpose:     Drag and drop sample
  109. // Author:      Vadim Zeitlin
  110. // Modified by:
  111. // Created:     04/01/98
  112. // RCS-ID:      $Id: dnd.cpp,v 1.107 2006/10/30 20:23:41 VZ Exp $
  113. // Copyright:
  114. // Licence:     wxWindows licence
  115. /////////////////////////////////////////////////////////////////////////////
  116. /////////////////////////////////////////////////////////////////////////////
  117. // Name:        test.cpp
  118. // Purpose:     wxHtml testing example
  119. /////////////////////////////////////////////////////////////////////////////
  120.  
  121.  
  122. #include "OPJViewer.h"
  123.  
  124. IMPLEMENT_APP(OPJViewerApp)
  125.  
  126. // For drawing lines in a canvas
  127. long xpos = -1;
  128. long ypos = -1;
  129.  
  130. int winNumber = 1;
  131.  
  132. // Initialise this in OnInit, not statically
  133. bool OPJViewerApp::OnInit(void)
  134. {
  135.         int n;
  136. #if wxUSE_UNICODE
  137.  
  138.     wxChar **wxArgv = new wxChar *[argc + 1];
  139.  
  140.     for (n = 0; n < argc; n++ ) {
  141.         wxMB2WXbuf warg = wxConvertMB2WX((char *) argv[n]);
  142.         wxArgv[n] = wxStrdup(warg);
  143.     }
  144.  
  145.     wxArgv[n] = NULL;
  146.  
  147. #else // !wxUSE_UNICODE
  148.  
  149.     #define wxArgv argv
  150.  
  151. #endif // wxUSE_UNICODE/!wxUSE_UNICODE
  152.  
  153. #if wxUSE_CMDLINE_PARSER
  154.  
  155.     static const wxCmdLineEntryDesc cmdLineDesc[] =
  156.     {
  157.         { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"),
  158.             wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
  159.  
  160.         { wxCMD_LINE_PARAM,  NULL, NULL, _T("input file"),
  161.             wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
  162.  
  163.         { wxCMD_LINE_NONE }
  164.     };
  165.  
  166.     wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
  167.  
  168.     switch (parser.Parse()) {
  169.     case -1:
  170.         wxLogMessage(wxT("Help was given, terminating."));
  171.         break;
  172.  
  173.     case 0:
  174.         ShowCmdLine(parser);
  175.         break;
  176.  
  177.     default:
  178.         wxLogMessage(wxT("Syntax error detected."));
  179.         break;
  180.     }
  181.  
  182. #endif // wxUSE_CMDLINE_PARSER
  183.  
  184.     //wxInitAllImageHandlers();
  185. #if wxUSE_LIBJPEG
  186.   wxImage::AddHandler( new wxJPEGHandler );
  187. #endif
  188. #if wxUSE_LIBOPENJPEG
  189.   wxImage::AddHandler( new wxJPEG2000Handler );
  190. #endif
  191. #if USE_MXF
  192.   wxImage::AddHandler( new wxMXFHandler );
  193. #endif // USE_MXF
  194. #if OPJ_MANYFORMATS
  195.   wxImage::AddHandler( new wxBMPHandler );
  196.   wxImage::AddHandler( new wxPNGHandler );
  197.   wxImage::AddHandler( new wxGIFHandler );
  198.   wxImage::AddHandler( new wxPNMHandler );
  199.   wxImage::AddHandler( new wxTIFFHandler );
  200. #endif
  201.     // we use a XPM image in our HTML page
  202.     wxImage::AddHandler(new wxXPMHandler);
  203.  
  204.         // memory file system
  205.     wxFileSystem::AddHandler(new wxMemoryFSHandler);
  206.  
  207. #ifdef OPJ_INICONFIG
  208.         //load decoding engine parameters
  209.         OPJconfig = new wxConfig(OPJ_APPLICATION, OPJ_APPLICATION_VENDOR);
  210.  
  211.         OPJconfig->Read(wxT("decode/enabledeco"), &m_enabledeco, (bool) true);
  212.         OPJconfig->Read(wxT("decode/enableparse"), &m_enableparse, (bool) true);
  213.         OPJconfig->Read(wxT("decode/resizemethod"), &m_resizemethod, (long) 0);
  214.         OPJconfig->Read(wxT("decode/xxxreducefactor"), &m_reducefactor, (long) 0);
  215.         OPJconfig->Read(wxT("decode/xxxqualitylayers"), &m_qualitylayers, (long) 0);
  216.         OPJconfig->Read(wxT("decode/xxxcomponents"), &m_components, (long) 0);
  217.         OPJconfig->Read(wxT("decode/xxxframenum"), &m_framenum, (long) 0);
  218. #ifdef USE_JPWL
  219.         OPJconfig->Read(wxT("decode/enablejpwl"), &m_enablejpwl, (bool) true);
  220.         OPJconfig->Read(wxT("decode/expcomps"), &m_expcomps, (long) JPWL_EXPECTED_COMPONENTS);
  221.         OPJconfig->Read(wxT("decode/maxtiles"), &m_maxtiles, (long) JPWL_MAXIMUM_TILES);
  222. #endif // USE_JPWL
  223.  
  224.         OPJconfig->Write(wxT("teststring"), wxT("This is a test value"));
  225.         OPJconfig->Write(wxT("testbool"), (bool) true);
  226.         OPJconfig->Write(wxT("testlong"), (long) 245);
  227.  
  228.         OPJconfig->Read(wxT("showtoolbar"), &m_showtoolbar, (bool) true);
  229.         OPJconfig->Read(wxT("showbrowser"), &m_showbrowser, (bool) true);
  230.         OPJconfig->Read(wxT("showpeeker"), &m_showpeeker, (bool) true);
  231.         OPJconfig->Read(wxT("browserwidth"), &m_browserwidth, (long) OPJ_BROWSER_WIDTH);
  232.         OPJconfig->Read(wxT("peekerheight"), &m_peekerheight, (long) OPJ_PEEKER_HEIGHT);
  233.         OPJconfig->Read(wxT("framewidth"), &m_framewidth, (long) OPJ_FRAME_WIDTH);
  234.         OPJconfig->Read(wxT("frameheight"), &m_frameheight, (long) OPJ_FRAME_HEIGHT);
  235.  
  236.         // load encoding engine parameters
  237.         OPJconfig->Read(wxT("encode/subsampling"), &m_subsampling, (wxString) wxT("1,1"));
  238.         OPJconfig->Read(wxT("encode/origin"), &m_origin, (wxString) wxT("0,0"));
  239.         OPJconfig->Read(wxT("encode/rates"), &m_rates, (wxString) wxT("20,10,5"));
  240.         OPJconfig->Read(wxT("encode/quality"), &m_quality, (wxString) wxT("30,35,40"));
  241.         OPJconfig->Read(wxT("encode/enablequality"), &m_enablequality, (bool) false);
  242.         OPJconfig->Read(wxT("encode/multicomp"), &m_multicomp, (bool) false);  
  243.         OPJconfig->Read(wxT("encode/irreversible"), &m_irreversible, (bool) false);    
  244.         OPJconfig->Read(wxT("encode/resolutions"), &m_resolutions, (int) 6);   
  245.         OPJconfig->Read(wxT("encode/progression"), &m_progression, (int) 0);   
  246.         OPJconfig->Read(wxT("encode/cbsize"), &m_cbsize, (wxString) wxT("32,32"));
  247.         OPJconfig->Read(wxT("encode/prsize"), &m_prsize, (wxString) wxT("[128,128],[128,128]"));
  248.         OPJconfig->Read(wxT("encode/tsize"), &m_tsize, (wxString) wxT(""));
  249.         OPJconfig->Read(wxT("encode/torigin"), &m_torigin, (wxString) wxT("0,0"));
  250.         OPJconfig->Read(wxT("encode/enablesop"), &m_enablesop, (bool) false);  
  251.         OPJconfig->Read(wxT("encode/enableeph"), &m_enableeph, (bool) false);  
  252.         OPJconfig->Read(wxT("encode/enablebypass"), &m_enablebypass, (bool) false);    
  253.         OPJconfig->Read(wxT("encode/enablereset"), &m_enablereset, (bool) false);      
  254.         OPJconfig->Read(wxT("encode/enablerestart"), &m_enablerestart, (bool) false);  
  255.         OPJconfig->Read(wxT("encode/enablevsc"), &m_enablevsc, (bool) false);  
  256.         OPJconfig->Read(wxT("encode/enableerterm"), &m_enableerterm, (bool) false);    
  257.         OPJconfig->Read(wxT("encode/enablesegmark"), &m_enablesegmark, (bool) false);  
  258.         OPJconfig->Read(wxT("encode/enablecomm"), &m_enablecomm, (bool) true); 
  259.         OPJconfig->Read(wxT("encode/enablepoc"), &m_enablepoc, (bool) false);  
  260.         OPJconfig->Read(wxT("encode/comment"), &m_comment, (wxString) wxT(""));
  261.         OPJconfig->Read(wxT("encode/poc"), &m_poc, (wxString) wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL"));
  262.         OPJconfig->Read(wxT("encode/enableidx"), &m_enableidx, (bool) false);  
  263.         OPJconfig->Read(wxT("encode/index"), &m_index, (wxString) wxT("index.txt"));
  264. #ifdef USE_JPWL
  265.         OPJconfig->Read(wxT("encode/enablejpwl"), &m_enablejpwle, (bool) true);
  266.         for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) {
  267.                 OPJconfig->Read(wxT("encode/jpwl/hprotsel") + wxString::Format(wxT("%02d"), n), &m_hprotsel[n], 0);
  268.                 OPJconfig->Read(wxT("encode/jpwl/htileval") + wxString::Format(wxT("%02d"), n), &m_htileval[n], 0);
  269.                 OPJconfig->Read(wxT("encode/jpwl/pprotsel") + wxString::Format(wxT("%02d"), n), &m_pprotsel[n], 0);
  270.                 OPJconfig->Read(wxT("encode/jpwl/ptileval") + wxString::Format(wxT("%02d"), n), &m_ptileval[n], 0);
  271.                 OPJconfig->Read(wxT("encode/jpwl/ppackval") + wxString::Format(wxT("%02d"), n), &m_ppackval[n], 0);
  272.                 OPJconfig->Read(wxT("encode/jpwl/sensisel") + wxString::Format(wxT("%02d"), n), &m_sensisel[n], 0);
  273.                 OPJconfig->Read(wxT("encode/jpwl/stileval") + wxString::Format(wxT("%02d"), n), &m_stileval[n], 0);
  274.         }
  275. #endif // USE_JPWL
  276.  
  277. #else
  278.         // set decoding engine parameters
  279.         m_enabledeco = true;
  280.         m_enableparse = true;
  281.         m_resizemethod = 0;
  282.         m_reducefactor = 0;
  283.         m_qualitylayers = 0;
  284.         m_components = 0;
  285.         m_framenum = 0;
  286. #ifdef USE_JPWL
  287.         m_enablejpwl = true;
  288.         m_expcomps = JPWL_EXPECTED_COMPONENTS;
  289.         m_maxtiles = JPWL_MAXIMUM_TILES;
  290. #endif // USE_JPWL
  291.         m_showtoolbar = true;
  292.         m_showbrowser = true;
  293.         m_showpeeker = true;
  294.         m_browserwidth = OPJ_BROWSER_WIDTH;
  295.         m_peekerheight = OPJ_PEEKER_HEIGHT;
  296.         m_framewidth = OPJ_FRAME_WIDTH;
  297.         m_frameheight = OPJ_FRAME_HEIGHT;
  298.  
  299.         // set encoding engine parameters
  300.         m_subsampling = wxT("1,1");
  301.         m_origin = wxT("0,0");
  302.         m_rates = wxT("20,10,5");
  303.         m_quality = wxT("30,35,40");
  304.         m_enablequality = false;
  305.         m_multicomp = false;
  306.         m_irreversible = false;
  307.         m_resolutions = 6;
  308.         m_progression = 0;
  309.         m_cbsize= wxT("32,32");
  310.         m_prsize= wxT("[128,128],[128,128]");
  311.         m_tsize = wxT("");
  312.         m_torigin = wxT("0,0");
  313.         m_enablesop = false;
  314.         m_enableeph = false;
  315.         m_enablebypass = false;
  316.         m_enablereset = false;
  317.         m_enablerestart = false;
  318.         m_enablevsc = false;
  319.         m_enableerterm = false;
  320.         m_enablesegmark = false;
  321.         m_enableidx = false;
  322.         m_index = wxT("index.txt");
  323.         m_enablecomm = true;
  324.         m_comment = wxT("");
  325.         m_enablepoc = false;
  326.         m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL");
  327. #ifdef USE_JPWL
  328.         m_enablejpwle = true;
  329.         for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) {
  330.                 m_hprotsel[n] = 0;
  331.                 m_htileval[n] = 0;
  332.                 m_pprotsel[n] = 0;
  333.                 m_ptileval[n] = 0;
  334.                 m_sensisel[n] = 0;
  335.                 m_stileval[n] = 0;
  336.         }
  337. #endif // USE_JPWL
  338.  
  339. #endif // OPJ_INICONFIG
  340.  
  341.         if (m_comment == wxT("")) {
  342. #if defined __WXMSW__
  343.                 m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG  version ");
  344. #elif defined __WXGTK__
  345.                 m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");
  346. #else
  347.                 m_comment = wxT("Created by OPJViewer - OpenJPEG version ");
  348. #endif
  349.  
  350. #ifdef USE_JPWL
  351.                 m_comment += wxString::Format(wxT("%s with JPWL"), (char *) opj_version());
  352. #else
  353.                 m_comment += wxString::Format(wxT("%s"), (char *) opj_version());
  354. #endif
  355.         }
  356.  
  357.         // Create the main frame window
  358.   OPJFrame *frame = new OPJFrame(NULL, wxID_ANY, OPJ_APPLICATION_TITLEBAR,
  359.                                           wxDefaultPosition, wxSize(wxGetApp().m_framewidth, wxGetApp().m_frameheight),
  360.                       wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE |
  361.                       wxHSCROLL | wxVSCROLL);
  362.  
  363.   // Give it an icon (this is ignored in MDI mode: uses resources)
  364. #ifdef __WXMSW__
  365.   frame->SetIcon(wxIcon(wxT("OPJViewer16")));
  366. #endif
  367.  
  368.   frame->Show(true);
  369.  
  370.   SetTopWindow(frame);
  371.  
  372.         // if there are files on the command line, open them
  373.         if (!(m_filelist.IsEmpty())) {
  374.                 //wxLogMessage(wxT("Habemus files!!!"));
  375.                 wxArrayString paths, filenames;
  376.                 for (unsigned int f = 0; f < wxGetApp().m_filelist.GetCount(); f++) {
  377.                         paths.Add(wxFileName(wxGetApp().m_filelist[f]).GetFullPath());
  378.                         filenames.Add(wxFileName(wxGetApp().m_filelist[f]).GetFullName());
  379.                 }
  380.                 //wxLogMessage(paths[0]);
  381.                 frame->OpenFiles(paths, filenames);
  382.         }
  383.  
  384.   return true;
  385. }
  386.  
  387. int OPJViewerApp::OnExit()
  388. {
  389.         int n;
  390.  
  391. #ifdef OPJ_INICONFIG
  392.         OPJconfig->Write(wxT("decode/enabledeco"), m_enabledeco);
  393.         OPJconfig->Write(wxT("decode/enableparse"), m_enableparse);
  394.         OPJconfig->Write(wxT("decode/resizemethod"), m_resizemethod);
  395.         OPJconfig->Write(wxT("decode/reducefactor"), m_reducefactor);
  396.         OPJconfig->Write(wxT("decode/qualitylayers"), m_qualitylayers);
  397.         OPJconfig->Write(wxT("decode/components"), m_components);
  398.         OPJconfig->Write(wxT("decode/framenum"), m_framenum);
  399. #ifdef USE_JPWL
  400.         OPJconfig->Write(wxT("decode/enablejpwl"), m_enablejpwl);
  401.         OPJconfig->Write(wxT("decode/expcomps"), m_expcomps);
  402.         OPJconfig->Write(wxT("decode/maxtiles"), m_maxtiles);
  403. #endif // USE_JPWL
  404.         OPJconfig->Write(wxT("showtoolbar"), m_showtoolbar);
  405.         OPJconfig->Write(wxT("showbrowser"), m_showbrowser);
  406.         OPJconfig->Write(wxT("showpeeker"), m_showpeeker);
  407.         OPJconfig->Write(wxT("browserwidth"), m_browserwidth);
  408.         OPJconfig->Write(wxT("peekerheight"), m_peekerheight);
  409.         OPJconfig->Write(wxT("framewidth"), m_framewidth);
  410.         OPJconfig->Write(wxT("frameheight"), m_frameheight);
  411.  
  412.         OPJconfig->Write(wxT("encode/subsampling"), m_subsampling);
  413.         OPJconfig->Write(wxT("encode/origin"), m_origin);
  414.         OPJconfig->Write(wxT("encode/rates"), m_rates);
  415.         OPJconfig->Write(wxT("encode/quality"), m_quality);
  416.         OPJconfig->Write(wxT("encode/enablequality"), m_enablequality);
  417.         OPJconfig->Write(wxT("encode/multicomp"), m_multicomp);
  418.         OPJconfig->Write(wxT("encode/irreversible"), m_irreversible);
  419.         OPJconfig->Write(wxT("encode/resolutions"), m_resolutions);
  420.         OPJconfig->Write(wxT("encode/progression"), m_progression);
  421.         OPJconfig->Write(wxT("encode/cbsize"), m_cbsize);
  422.         OPJconfig->Write(wxT("encode/prsize"), m_prsize);
  423.         OPJconfig->Write(wxT("encode/tiles"), m_tsize);
  424.         OPJconfig->Write(wxT("encode/torigin"), m_torigin);
  425.         OPJconfig->Write(wxT("encode/enablesop"), m_enablesop);
  426.         OPJconfig->Write(wxT("encode/enableeph"), m_enableeph);
  427.         OPJconfig->Write(wxT("encode/enablebypass"), m_enablebypass);
  428.         OPJconfig->Write(wxT("encode/enablereset"), m_enablereset);
  429.         OPJconfig->Write(wxT("encode/enablerestart"), m_enablerestart);
  430.         OPJconfig->Write(wxT("encode/enablevsc"), m_enablevsc);
  431.         OPJconfig->Write(wxT("encode/enableerterm"), m_enableerterm);
  432.         OPJconfig->Write(wxT("encode/enablesegmark"), m_enablesegmark);
  433.         OPJconfig->Write(wxT("encode/enableidx"), m_enableidx);
  434.         OPJconfig->Write(wxT("encode/index"), m_index);
  435.         OPJconfig->Write(wxT("encode/enablecomm"), m_enablecomm);
  436.         OPJconfig->Write(wxT("encode/comment"), m_comment);
  437.         OPJconfig->Write(wxT("encode/enablepoc"), m_enablepoc);
  438.         OPJconfig->Write(wxT("encode/poc"), m_poc);
  439. #ifdef USE_JPWL
  440.         OPJconfig->Write(wxT("encode/enablejpwl"), m_enablejpwle);
  441.         for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) {
  442.                 OPJconfig->Write(wxT("encode/jpwl/hprotsel") + wxString::Format(wxT("%02d"), n), m_hprotsel[n]);
  443.                 OPJconfig->Write(wxT("encode/jpwl/htileval") + wxString::Format(wxT("%02d"), n), m_htileval[n]);
  444.                 OPJconfig->Write(wxT("encode/jpwl/pprotsel") + wxString::Format(wxT("%02d"), n), m_pprotsel[n]);
  445.                 OPJconfig->Write(wxT("encode/jpwl/ptileval") + wxString::Format(wxT("%02d"), n), m_ptileval[n]);
  446.                 OPJconfig->Write(wxT("encode/jpwl/ppackval") + wxString::Format(wxT("%02d"), n), m_ppackval[n]);
  447.                 OPJconfig->Write(wxT("encode/jpwl/sensisel") + wxString::Format(wxT("%02d"), n), m_sensisel[n]);
  448.                 OPJconfig->Write(wxT("encode/jpwl/stileval") + wxString::Format(wxT("%02d"), n), m_stileval[n]);
  449.         }
  450. #endif // USE_JPWL
  451.  
  452. #endif // OPJ_INICONFIG
  453.  
  454.         return 1;
  455. }
  456.  
  457. void OPJViewerApp::ShowCmdLine(const wxCmdLineParser& parser)
  458. {
  459.     wxString s = wxT("Command line parsed successfully:\nInput files: ");
  460.  
  461.     size_t count = parser.GetParamCount();
  462.     for (size_t param = 0; param < count; param++) {
  463.         s << parser.GetParam(param) << ';';
  464.                 m_filelist.Add(parser.GetParam(param));
  465.     }
  466.  
  467.     //wxLogMessage(s);
  468. }
  469.  
  470. // OPJFrame events
  471.  
  472. // Event class for sending text messages between worker and GUI threads
  473. BEGIN_EVENT_TABLE(OPJFrame, wxMDIParentFrame)
  474.     EVT_MENU(OPJFRAME_HELPABOUT, OPJFrame::OnAbout)
  475.     EVT_MENU(OPJFRAME_FILEOPEN, OPJFrame::OnFileOpen)
  476.     EVT_MENU(OPJFRAME_FILESAVEAS, OPJFrame::OnFileSaveAs)
  477.     EVT_MENU(OPJFRAME_MEMORYOPEN, OPJFrame::OnMemoryOpen)
  478.     EVT_SIZE(OPJFrame::OnSize)
  479.     EVT_MENU(OPJFRAME_FILEEXIT, OPJFrame::OnQuit)
  480.     EVT_MENU(OPJFRAME_FILECLOSE, OPJFrame::OnClose)
  481.     EVT_MENU(OPJFRAME_VIEWZOOM, OPJFrame::OnZoom)
  482.     EVT_MENU(OPJFRAME_VIEWFIT, OPJFrame::OnFit)
  483.     EVT_MENU(OPJFRAME_VIEWRELOAD, OPJFrame::OnReload)
  484.     EVT_MENU(OPJFRAME_VIEWPREVFRAME, OPJFrame::OnPrevFrame)
  485.     EVT_MENU(OPJFRAME_VIEWHOMEFRAME, OPJFrame::OnHomeFrame)
  486.     EVT_MENU(OPJFRAME_VIEWNEXTFRAME, OPJFrame::OnNextFrame)
  487.     EVT_MENU(OPJFRAME_VIEWLESSLAYERS, OPJFrame::OnLessLayers)
  488.     EVT_MENU(OPJFRAME_VIEWALLLAYERS, OPJFrame::OnAllLayers)
  489.     EVT_MENU(OPJFRAME_VIEWMORELAYERS, OPJFrame::OnMoreLayers)
  490.     EVT_MENU(OPJFRAME_VIEWLESSRES, OPJFrame::OnLessRes)
  491.     EVT_MENU(OPJFRAME_VIEWFULLRES, OPJFrame::OnFullRes)
  492.     EVT_MENU(OPJFRAME_VIEWMORERES, OPJFrame::OnMoreRes)
  493.     EVT_MENU(OPJFRAME_VIEWPREVCOMP, OPJFrame::OnPrevComp)
  494.     EVT_MENU(OPJFRAME_VIEWALLCOMPS, OPJFrame::OnAllComps)
  495.     EVT_MENU(OPJFRAME_VIEWNEXTCOMP, OPJFrame::OnNextComp)
  496.     EVT_MENU(OPJFRAME_FILETOGGLEB, OPJFrame::OnToggleBrowser)
  497.     EVT_MENU(OPJFRAME_FILETOGGLEP, OPJFrame::OnTogglePeeker)
  498.     EVT_MENU(OPJFRAME_FILETOGGLET, OPJFrame::OnToggleToolbar)
  499.     EVT_MENU(OPJFRAME_SETSENCO, OPJFrame::OnSetsEnco)
  500.     EVT_MENU(OPJFRAME_SETSDECO, OPJFrame::OnSetsDeco)
  501.     EVT_SASH_DRAGGED_RANGE(OPJFRAME_BROWSEWIN, OPJFRAME_LOGWIN, OPJFrame::OnSashDrag)
  502.     EVT_NOTEBOOK_PAGE_CHANGED(LEFT_NOTEBOOK_ID, OPJFrame::OnNotebook)
  503.     EVT_MENU(OPJFRAME_THREADLOGMSG, OPJFrame::OnThreadLogmsg)
  504. END_EVENT_TABLE()
  505.  
  506. // this is the frame constructor
  507. OPJFrame::OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
  508.                                    const wxPoint& pos, const wxSize& size, const long style)
  509.                 : wxMDIParentFrame(parent, id, title, pos, size, style)
  510. {
  511.         // file menu and its items
  512.         wxMenu *file_menu = new wxMenu;
  513.  
  514.         file_menu->Append(OPJFRAME_FILEOPEN, wxT("&Open\tCtrl+O"));
  515.         file_menu->SetHelpString(OPJFRAME_FILEOPEN, wxT("Open one or more files"));
  516.  
  517.         file_menu->Append(OPJFRAME_MEMORYOPEN, wxT("&Memory\tCtrl+M"));
  518.         file_menu->SetHelpString(OPJFRAME_MEMORYOPEN, wxT("Open a memory buffer"));
  519.  
  520.         file_menu->Append(OPJFRAME_FILECLOSE, wxT("&Close\tCtrl+C"));
  521.         file_menu->SetHelpString(OPJFRAME_FILECLOSE, wxT("Close current image"));
  522.  
  523.         file_menu->AppendSeparator();
  524.  
  525.         file_menu->Append(OPJFRAME_FILESAVEAS, wxT("&Save as\tCtrl+S"));
  526.         file_menu->SetHelpString(OPJFRAME_FILESAVEAS, wxT("Save the current image"));
  527.         //file_menu->Enable(OPJFRAME_FILESAVEAS, false);
  528.  
  529.         file_menu->AppendSeparator();
  530.  
  531.         file_menu->Append(OPJFRAME_FILETOGGLEB, wxT("Toggle &browser\tCtrl+B"));
  532.         file_menu->SetHelpString(OPJFRAME_FILETOGGLEB, wxT("Toggle the left browsing pane"));
  533.  
  534.         file_menu->Append(OPJFRAME_FILETOGGLEP, wxT("Toggle &peeker\tCtrl+P"));
  535.         file_menu->SetHelpString(OPJFRAME_FILETOGGLEP, wxT("Toggle the bottom peeking pane"));
  536.  
  537.         file_menu->Append(OPJFRAME_FILETOGGLET, wxT("Toggle &toolbar\tCtrl+T"));
  538.         file_menu->SetHelpString(OPJFRAME_FILETOGGLET, wxT("Toggle the toolbar"));
  539.  
  540.         file_menu->AppendSeparator();
  541.  
  542.         file_menu->Append(OPJFRAME_FILEEXIT, wxT("&Exit\tCtrl+Q"));
  543.         file_menu->SetHelpString(OPJFRAME_FILEEXIT, wxT("Quit this program"));
  544.  
  545.         // view menu and its items
  546.         wxMenu *view_menu = new wxMenu;
  547.  
  548.         view_menu->Append(OPJFRAME_VIEWZOOM, wxT("&Zoom\tCtrl+Z"));
  549.         view_menu->SetHelpString(OPJFRAME_VIEWZOOM, wxT("Rescale the image"));
  550.  
  551.         view_menu->Append(OPJFRAME_VIEWFIT, wxT("Zoom to &fit\tCtrl+F"));
  552.         view_menu->SetHelpString(OPJFRAME_VIEWFIT, wxT("Fit the image in canvas"));
  553.  
  554.         view_menu->Append(OPJFRAME_VIEWRELOAD, wxT("&Reload image\tCtrl+R"));
  555.         view_menu->SetHelpString(OPJFRAME_VIEWRELOAD, wxT("Reload the current image"));
  556.  
  557.         view_menu->AppendSeparator();
  558.  
  559.         view_menu->Append(OPJFRAME_VIEWPREVFRAME, wxT("&Prev frame\tLeft"));
  560.         view_menu->SetHelpString(OPJFRAME_VIEWPREVFRAME, wxT("View previous frame"));
  561.  
  562.         view_menu->Append(OPJFRAME_VIEWHOMEFRAME, wxT("&Start frame\tHome"));
  563.         view_menu->SetHelpString(OPJFRAME_VIEWHOMEFRAME, wxT("View starting frame"));
  564.  
  565.         view_menu->Append(OPJFRAME_VIEWNEXTFRAME, wxT("&Next frame\tRight"));
  566.         view_menu->SetHelpString(OPJFRAME_VIEWNEXTFRAME, wxT("View next frame"));
  567.  
  568.         view_menu->AppendSeparator();
  569.  
  570.         view_menu->Append(OPJFRAME_VIEWLESSLAYERS, wxT("&Less layers\t-"));
  571.         view_menu->SetHelpString(OPJFRAME_VIEWLESSLAYERS, wxT("Remove a layer"));
  572.  
  573.         view_menu->Append(OPJFRAME_VIEWALLLAYERS, wxT("&All layers\t0"));
  574.         view_menu->SetHelpString(OPJFRAME_VIEWALLLAYERS, wxT("Show all layers"));
  575.  
  576.         view_menu->Append(OPJFRAME_VIEWMORELAYERS, wxT("&More layers\t+"));
  577.         view_menu->SetHelpString(OPJFRAME_VIEWMORELAYERS, wxT("Add a layer"));
  578.  
  579.         view_menu->AppendSeparator();
  580.  
  581.         view_menu->Append(OPJFRAME_VIEWLESSRES, wxT("&Less resolution\t<"));
  582.         view_menu->SetHelpString(OPJFRAME_VIEWLESSRES, wxT("Reduce the resolution"));
  583.  
  584.         view_menu->Append(OPJFRAME_VIEWFULLRES, wxT("&Full resolution\tf"));
  585.         view_menu->SetHelpString(OPJFRAME_VIEWFULLRES, wxT("Full resolution"));
  586.  
  587.         view_menu->Append(OPJFRAME_VIEWMORERES, wxT("&More resolution\t>"));
  588.         view_menu->SetHelpString(OPJFRAME_VIEWMORERES, wxT("Increase the resolution"));
  589.  
  590.         view_menu->AppendSeparator();
  591.  
  592.         view_menu->Append(OPJFRAME_VIEWPREVCOMP, wxT("&Prev component\tDown"));
  593.         view_menu->SetHelpString(OPJFRAME_VIEWPREVCOMP, wxT("View previous component"));
  594.  
  595.         view_menu->Append(OPJFRAME_VIEWALLCOMPS, wxT("&All components\ta"));
  596.         view_menu->SetHelpString(OPJFRAME_VIEWALLCOMPS, wxT("View all components"));
  597.  
  598.         view_menu->Append(OPJFRAME_VIEWNEXTCOMP, wxT("&Next component\tUp"));
  599.         view_menu->SetHelpString(OPJFRAME_VIEWNEXTCOMP, wxT("View next component"));
  600.  
  601.  
  602.         // settings menu and its items
  603.         wxMenu *sets_menu = new wxMenu;
  604.  
  605.         sets_menu->Append(OPJFRAME_SETSENCO, wxT("&Encoder\tCtrl+E"));
  606.         sets_menu->SetHelpString(OPJFRAME_SETSENCO, wxT("Encoder settings"));
  607.  
  608.         sets_menu->Append(OPJFRAME_SETSDECO, wxT("&Decoder\tCtrl+D"));
  609.         sets_menu->SetHelpString(OPJFRAME_SETSDECO, wxT("Decoder settings"));
  610.  
  611.         // help menu and its items
  612.         wxMenu *help_menu = new wxMenu;
  613.  
  614.         help_menu->Append(OPJFRAME_HELPABOUT, wxT("&About\tF1"));
  615.         help_menu->SetHelpString(OPJFRAME_HELPABOUT, wxT("Basic info on the program"));
  616.  
  617.         // the whole menubar
  618.         wxMenuBar *menu_bar = new wxMenuBar;
  619.         menu_bar->Append(file_menu, wxT("&File"));
  620.         menu_bar->Append(view_menu, wxT("&View"));
  621.         menu_bar->Append(sets_menu, wxT("&Settings"));
  622.         menu_bar->Append(help_menu, wxT("&Help"));
  623.  
  624.         // Associate the menu bar with the frame
  625.         SetMenuBar(menu_bar);
  626.  
  627.         // the status bar
  628.         CreateStatusBar();
  629.  
  630.         // the toolbar
  631.         tool_bar = new wxToolBar(this, OPJFRAME_TOOLBAR,
  632.                                                                 wxDefaultPosition, wxDefaultSize,
  633.                                                                 wxTB_HORIZONTAL | wxNO_BORDER);
  634.         wxBitmap bmpOpen = wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_TOOLBAR,
  635.                                                                                                 wxDefaultSize);
  636.         wxBitmap bmpSaveAs = wxArtProvider::GetBitmap(wxART_FILE_SAVE_AS, wxART_TOOLBAR,
  637.                                                                                                 wxDefaultSize);
  638.         wxBitmap bmpZoom = wxArtProvider::GetBitmap(wxART_FIND, wxART_TOOLBAR,
  639.                                                                                                 wxDefaultSize);
  640.         wxBitmap bmpFit = wxArtProvider::GetBitmap(wxART_FIND_AND_REPLACE, wxART_TOOLBAR,
  641.                                                                                                 wxDefaultSize);
  642.         wxBitmap bmpReload = wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE, wxART_TOOLBAR,
  643.                                                                                                 wxDefaultSize);
  644.         wxBitmap bmpDecosettings = wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_TOOLBAR,
  645.                                                                                                 wxDefaultSize);
  646.         wxBitmap bmpEncosettings = wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_TOOLBAR,
  647.                                                                                                 wxDefaultSize);
  648.         wxBitmap bmpPrevframe = wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_TOOLBAR,
  649.                                                                                                 wxDefaultSize);
  650.         wxBitmap bmpHomeframe = wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_TOOLBAR,
  651.                                                                                                 wxDefaultSize);
  652.         wxBitmap bmpNextframe = wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_TOOLBAR,
  653.                                                                                                 wxDefaultSize);
  654.         wxBitmap bmpLesslayers = bmpPrevframe;
  655.         wxBitmap bmpAlllayers = wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_TOOLBAR,
  656.                                                                                                 wxDefaultSize);
  657.         wxBitmap bmpMorelayers = bmpNextframe;
  658.         wxBitmap bmpLessres = bmpPrevframe;
  659.         wxBitmap bmpFullres = wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_TOOLBAR,
  660.                                                                                                 wxDefaultSize);
  661.         wxBitmap bmpMoreres = bmpNextframe;
  662.         wxBitmap bmpPrevcomp = bmpPrevframe;
  663.         wxBitmap bmpAllcomps = wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_TOOLBAR,
  664.                                                                                                 wxDefaultSize);
  665.         wxBitmap bmpNextcomp = bmpNextframe;
  666.  
  667.         tool_bar->AddTool(OPJFRAME_FILEOPEN, bmpOpen, wxT("Open"));
  668.         tool_bar->AddTool(OPJFRAME_FILESAVEAS, bmpSaveAs, wxT("Save as "));
  669.         //tool_bar->EnableTool(OPJFRAME_FILESAVEAS, false);
  670.         tool_bar->AddSeparator();
  671.         tool_bar->AddTool(OPJFRAME_VIEWZOOM, bmpZoom, wxT("Zoom"));
  672.         tool_bar->AddTool(OPJFRAME_VIEWFIT, bmpFit, wxT("Zoom to fit"));
  673.         tool_bar->AddTool(OPJFRAME_VIEWRELOAD, bmpReload, wxT("Reload"));
  674.         tool_bar->AddSeparator();
  675.         tool_bar->AddTool(OPJFRAME_SETSDECO, bmpDecosettings, wxT("Decoder settings"));
  676.         tool_bar->AddTool(OPJFRAME_SETSENCO, bmpEncosettings, wxT("Encoder settings"));
  677.         tool_bar->AddSeparator();
  678.         tool_bar->AddTool(OPJFRAME_VIEWPREVFRAME, bmpPrevframe, wxT("Previous frame"));
  679.         tool_bar->AddTool(OPJFRAME_VIEWHOMEFRAME, bmpHomeframe, wxT("Starting frame"));
  680.         tool_bar->AddTool(OPJFRAME_VIEWNEXTFRAME, bmpNextframe, wxT("Next frame"));
  681.         tool_bar->AddSeparator();
  682.         tool_bar->AddTool(OPJFRAME_VIEWLESSLAYERS, bmpLesslayers, wxT("Remove a layer"));
  683.         tool_bar->AddTool(OPJFRAME_VIEWALLLAYERS, bmpAlllayers, wxT("Show all layers"));
  684.         tool_bar->AddTool(OPJFRAME_VIEWMORELAYERS, bmpMorelayers, wxT("Add a layer"));
  685.         tool_bar->AddSeparator();
  686.         tool_bar->AddTool(OPJFRAME_VIEWLESSRES, bmpLessres, wxT("Reduce the resolution"));
  687.         tool_bar->AddTool(OPJFRAME_VIEWFULLRES, bmpFullres, wxT("Full resolution"));
  688.         tool_bar->AddTool(OPJFRAME_VIEWMORERES, bmpMoreres, wxT("Increase the resolution"));
  689.         tool_bar->AddSeparator();
  690.         tool_bar->AddTool(OPJFRAME_VIEWPREVCOMP, bmpPrevcomp, wxT("Previous component"));
  691.         tool_bar->AddTool(OPJFRAME_VIEWALLCOMPS, bmpAllcomps, wxT("All components"));
  692.         tool_bar->AddTool(OPJFRAME_VIEWNEXTCOMP, bmpNextcomp, wxT("Next component"));
  693.         tool_bar->Realize();
  694.        
  695.         // associate the toolbar with the frame
  696.         SetToolBar(tool_bar);
  697.  
  698.         // show the toolbar?
  699.         if (!wxGetApp().m_showtoolbar)
  700.                 tool_bar->Show(false);
  701.         else
  702.                 tool_bar->Show(true);
  703.  
  704.         // the logging window
  705.         loggingWindow = new wxSashLayoutWindow(this, OPJFRAME_LOGWIN,
  706.                                                                                         wxDefaultPosition, wxSize(400, wxGetApp().m_peekerheight),
  707.                                                                                         wxNO_BORDER | wxSW_3D | wxCLIP_CHILDREN
  708.                                                                                         );
  709.         loggingWindow->SetDefaultSize(wxSize(1000, wxGetApp().m_peekerheight));
  710.         loggingWindow->SetOrientation(wxLAYOUT_HORIZONTAL);
  711.         loggingWindow->SetAlignment(wxLAYOUT_BOTTOM);
  712.         //loggingWindow->SetBackgroundColour(wxColour(0, 0, 255));
  713.         loggingWindow->SetSashVisible(wxSASH_TOP, true);
  714.  
  715.         // show the logging?
  716.         if (!wxGetApp().m_showpeeker)
  717.                 loggingWindow->Show(false);
  718.         else
  719.                 loggingWindow->Show(true);
  720.  
  721.         // create the bottom notebook
  722.         m_bookCtrlbottom = new wxNotebook(loggingWindow, BOTTOM_NOTEBOOK_ID,
  723.                                                                 wxDefaultPosition, wxDefaultSize,
  724.                                                                 wxBK_LEFT);
  725.  
  726.         // create the text control of the logger
  727.         m_textCtrl = new wxTextCtrl(m_bookCtrlbottom, wxID_ANY, wxT(""),
  728.                                                                 wxDefaultPosition, wxDefaultSize,
  729.                                                                 wxTE_MULTILINE | wxSUNKEN_BORDER | wxTE_READONLY
  730.                                                                 );
  731.         m_textCtrl->SetValue(_T("Logging window\n"));
  732.  
  733.         // add it to the notebook
  734.         m_bookCtrlbottom->AddPage(m_textCtrl, wxT("Log"));
  735.  
  736.         // create the text control of the browser
  737.         m_textCtrlbrowse = new wxTextCtrl(m_bookCtrlbottom, wxID_ANY, wxT(""),
  738.                                                                 wxDefaultPosition, wxDefaultSize,
  739.                                                                 wxTE_MULTILINE | wxSUNKEN_BORDER | wxTE_READONLY | wxTE_RICH
  740.                                                                 );
  741.         wxFont *browsefont = new wxFont(wxNORMAL_FONT->GetPointSize(),
  742.                 wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
  743.     m_textCtrlbrowse->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, *browsefont));
  744.         m_textCtrlbrowse->AppendText(wxT("Browsing window\n"));
  745.  
  746.         // add it the notebook
  747.         m_bookCtrlbottom->AddPage(m_textCtrlbrowse, wxT("Peek"), false);
  748.  
  749.         // the browser window
  750.         markerTreeWindow = new wxSashLayoutWindow(this, OPJFRAME_BROWSEWIN,
  751.                                                                                           wxDefaultPosition, wxSize(wxGetApp().m_browserwidth, 30),
  752.                                                                                           wxNO_BORDER | wxSW_3D | wxCLIP_CHILDREN
  753.                                                                                           );
  754.         markerTreeWindow->SetDefaultSize(wxSize(wxGetApp().m_browserwidth, 1000));
  755.         markerTreeWindow->SetOrientation(wxLAYOUT_VERTICAL);
  756.         markerTreeWindow->SetAlignment(wxLAYOUT_LEFT);
  757.         //markerTreeWindow->SetBackgroundColour(wxColour(0, 255, 0));
  758.         markerTreeWindow->SetSashVisible(wxSASH_RIGHT, true);
  759.         markerTreeWindow->SetExtraBorderSize(0);
  760.  
  761.         // create the browser notebook
  762.         m_bookCtrl = new wxNotebook(markerTreeWindow, LEFT_NOTEBOOK_ID,
  763.                                                                 wxDefaultPosition, wxDefaultSize,
  764.                                                                 wxBK_TOP);
  765.  
  766.         // show the browser?
  767.         if (!wxGetApp().m_showbrowser)
  768.                 markerTreeWindow->Show(false);
  769.         else
  770.                 markerTreeWindow->Show(true);
  771.  
  772. #ifdef __WXMOTIF__
  773.         // For some reason, we get a memcpy crash in wxLogStream::DoLogStream
  774.         // on gcc/wxMotif, if we use wxLogTextCtl. Maybe it's just gcc?
  775.         delete wxLog::SetActiveTarget(new wxLogStderr);
  776. #else
  777.         // set our text control as the log target
  778.         wxLogTextCtrl *logWindow = new wxLogTextCtrl(m_textCtrl);
  779.         delete wxLog::SetActiveTarget(logWindow);
  780. #endif
  781.  
  782.         // associate drop targets with the controls
  783.         SetDropTarget(new OPJDnDFile(this));
  784.  
  785. }
  786.  
  787. // this is the frame destructor
  788. OPJFrame::~OPJFrame(void)
  789. {
  790.         // save size settings
  791.         GetSize(&(wxGetApp().m_framewidth), &(wxGetApp().m_frameheight));
  792.  
  793.         // delete all possible things
  794.         delete m_bookCtrl;
  795.         m_bookCtrl = NULL;
  796.  
  797.         delete markerTreeWindow;
  798.         markerTreeWindow = NULL;
  799.  
  800.         delete m_textCtrl;
  801.         m_textCtrl = NULL;
  802.  
  803.         delete m_bookCtrlbottom;
  804.         m_bookCtrlbottom = NULL;
  805.  
  806.         delete loggingWindow;
  807.         loggingWindow = NULL;
  808. }
  809.  
  810. void OPJFrame::OnNotebook(wxNotebookEvent& event)
  811. {
  812.         int sel = event.GetSelection();
  813.         long childnum;
  814.  
  815.         m_bookCtrl->GetPageText(sel).ToLong(&childnum);
  816.  
  817.         if (m_childhash[childnum])
  818.                 m_childhash[childnum]->Activate();
  819.  
  820.         //wxLogMessage(wxT("Selection changed (now %d --> %d)"), childnum, m_childhash[childnum]->m_winnumber);
  821.  
  822. }
  823.  
  824.  
  825. void OPJFrame::Resize(int number)
  826. {
  827.         wxSize size = GetClientSize();
  828. }
  829.  
  830. void OPJFrame::OnSetsEnco(wxCommandEvent& event)
  831. {
  832.         int n;
  833.  
  834.     OPJEncoderDialog dialog(this, event.GetId());
  835.  
  836.     if (dialog.ShowModal() == wxID_OK) {
  837.  
  838.                 // load settings
  839.                 wxGetApp().m_subsampling = dialog.m_subsamplingCtrl->GetValue();
  840.                 wxGetApp().m_origin = dialog.m_originCtrl->GetValue();
  841.                 wxGetApp().m_rates = dialog.m_rateCtrl->GetValue();
  842.                 wxGetApp().m_quality = dialog.m_qualityCtrl->GetValue();
  843.                 wxGetApp().m_enablequality = dialog.m_qualityRadio->GetValue();
  844.                 wxGetApp().m_multicomp = dialog.m_mctCheck->GetValue();
  845.                 wxGetApp().m_irreversible = dialog.m_irrevCheck->GetValue();
  846.                 wxGetApp().m_resolutions = dialog.m_resolutionsCtrl->GetValue();
  847.                 wxGetApp().m_cbsize = dialog.m_cbsizeCtrl->GetValue();
  848.                 wxGetApp().m_prsize = dialog.m_prsizeCtrl->GetValue();
  849.                 wxGetApp().m_tsize = dialog.m_tsizeCtrl->GetValue();
  850.                 wxGetApp().m_torigin = dialog.m_toriginCtrl->GetValue();
  851.                 wxGetApp().m_progression = dialog.progressionBox->GetSelection();
  852.                 wxGetApp().m_enablesop = dialog.m_sopCheck->GetValue();
  853.                 wxGetApp().m_enableeph = dialog.m_ephCheck->GetValue();
  854.                 wxGetApp().m_enablebypass = dialog.m_enablebypassCheck->GetValue();
  855.                 wxGetApp().m_enablereset = dialog.m_enableresetCheck->GetValue();
  856.                 wxGetApp().m_enablerestart = dialog.m_enablerestartCheck->GetValue();
  857.                 wxGetApp().m_enablevsc = dialog.m_enablevscCheck->GetValue();
  858.                 wxGetApp().m_enableerterm = dialog.m_enableertermCheck->GetValue();
  859.                 wxGetApp().m_enablesegmark = dialog.m_enablesegmarkCheck->GetValue();
  860.                 wxGetApp().m_enableidx = dialog.m_enableidxCheck->GetValue();
  861.                 wxGetApp().m_index = dialog.m_indexCtrl->GetValue();
  862.                 wxGetApp().m_enablecomm = dialog.m_enablecommCheck->GetValue();
  863.                 wxGetApp().m_comment = dialog.m_commentCtrl->GetValue();
  864.                 wxGetApp().m_enablepoc = dialog.m_enablepocCheck->GetValue();
  865.                 wxGetApp().m_poc = dialog.m_pocCtrl->GetValue();
  866. #ifdef USE_JPWL
  867.                 wxGetApp().m_enablejpwle = dialog.m_enablejpwlCheck->GetValue();
  868.                 for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) {
  869.                         wxGetApp().m_hprotsel[n] = dialog.m_hprotChoice[n]->GetSelection();
  870.                         wxGetApp().m_htileval[n] = dialog.m_htileCtrl[n]->GetValue();
  871.                         wxGetApp().m_pprotsel[n] = dialog.m_pprotChoice[n]->GetSelection();
  872.                         wxGetApp().m_ptileval[n] = dialog.m_ptileCtrl[n]->GetValue();
  873.                         wxGetApp().m_ppackval[n] = dialog.m_ppackCtrl[n]->GetValue();
  874.                         wxGetApp().m_sensisel[n] = dialog.m_sensiChoice[n]->GetSelection();
  875.                         wxGetApp().m_stileval[n] = dialog.m_stileCtrl[n]->GetValue();
  876.                 }
  877. #endif // USE_JPWL
  878.         };
  879. }
  880.  
  881. void OPJFrame::OnSetsDeco(wxCommandEvent& event)
  882. {
  883.     OPJDecoderDialog dialog(this, event.GetId());
  884.  
  885.     if (dialog.ShowModal() == wxID_OK) {
  886.  
  887.                 // load settings
  888.                 wxGetApp().m_enabledeco = dialog.m_enabledecoCheck->GetValue();
  889.                 wxGetApp().m_enableparse = dialog.m_enableparseCheck->GetValue();
  890.                 wxGetApp().m_resizemethod = dialog.m_resizeBox->GetSelection() - 1;
  891.                 wxGetApp().m_reducefactor = dialog.m_reduceCtrl->GetValue();
  892.                 wxGetApp().m_qualitylayers = dialog.m_layerCtrl->GetValue();
  893.                 wxGetApp().m_components = dialog.m_numcompsCtrl->GetValue();
  894.                 wxGetApp().m_framenum = dialog.m_framenumCtrl->GetValue();
  895. #ifdef USE_JPWL
  896.                 wxGetApp().m_enablejpwl = dialog.m_enablejpwlCheck->GetValue();
  897.                 wxGetApp().m_expcomps = dialog.m_expcompsCtrl->GetValue();
  898.                 wxGetApp().m_maxtiles = dialog.m_maxtilesCtrl->GetValue();
  899. #endif // USE_JPWL
  900.  
  901.         };
  902. }
  903.  
  904. void OPJFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  905. {
  906.         Close(true);
  907. }
  908.  
  909. void OPJFrame::OnClose(wxCommandEvent& WXUNUSED(event))
  910. {
  911.         // current frame
  912.         OPJChildFrame *currframe = (OPJChildFrame *) GetActiveChild();
  913.  
  914.         if (!currframe)
  915.                 return;
  916.  
  917.         wxCloseEvent e;
  918.         currframe->OnClose(e);
  919. }
  920.  
  921. void OPJFrame::OnFit(wxCommandEvent& event)
  922. {
  923.         OPJChildFrame *currchild;
  924.         wxString eventstring = event.GetString();
  925.  
  926.         //wxLogMessage(wxT("OnFit:%d:%s"), event.GetInt(), eventstring);
  927.  
  928.         // current child
  929.         if (event.GetInt() >= 1) {
  930.                 currchild = m_childhash[event.GetInt()];
  931.         } else {
  932.                 currchild = (OPJChildFrame *) GetActiveChild();
  933.         }
  934.  
  935.         // problems
  936.         if (!currchild)
  937.                 return;
  938.  
  939.         // current canvas
  940.         OPJCanvas *currcanvas = currchild->m_canvas;
  941.  
  942.         // find a fit-to-width zoom
  943.         /*int zooml, wzooml, hzooml;
  944.         wxSize clientsize = currcanvas->GetClientSize();
  945.         wzooml = (int) ceil(100.0 * (double) (clientsize.GetWidth() - 2 * OPJ_CANVAS_BORDER) / (double) (currcanvas->m_image100.GetWidth()));
  946.         hzooml = (int) ceil(100.0 * (double) (clientsize.GetHeight() - 2 * OPJ_CANVAS_BORDER) / (double) (currcanvas->m_image100.GetHeight()));
  947.         zooml = wxMin(100, wxMin(wzooml, hzooml));*/
  948.  
  949.         // fit to width
  950.         Rescale(-1, currchild);
  951. }
  952.  
  953. void OPJFrame::OnZoom(wxCommandEvent& WXUNUSED(event))
  954. {
  955.         // current frame
  956.         OPJChildFrame *currframe = (OPJChildFrame *) GetActiveChild();
  957.  
  958.         if (!currframe)
  959.                 return;
  960.  
  961.         // get the preferred zoom
  962.         long zooml = wxGetNumberFromUser(wxT("Choose a scale between 5% and 300%"),
  963.                 wxT("Zoom (%)"),
  964.                 wxT("Image scale"),
  965.                 currframe->m_canvas->m_zooml, 5, 300, NULL, wxDefaultPosition);
  966.  
  967.         // rescale current frame image if necessary
  968.         if (zooml >= 5) {
  969.                 Rescale(zooml, currframe);
  970.                 wxLogMessage(wxT("zoom to %d%%"), zooml);
  971.         }
  972. }
  973.  
  974. void OPJFrame::Rescale(int zooml, OPJChildFrame *currframe)
  975. {
  976.         wxImage new_image = currframe->m_canvas->m_image100.ConvertToImage();
  977.  
  978.         // resizing enabled?
  979.         if (wxGetApp().m_resizemethod == -1) {
  980.  
  981.                 zooml = 100;
  982.  
  983.         } else {
  984.  
  985.                 if (zooml < 0) {
  986.                         // find a fit-to-width zoom
  987.                         int wzooml, hzooml;
  988.                         //wxSize clientsize = currframe->m_canvas->GetClientSize();
  989.                         wxSize clientsize = currframe->m_frame->GetActiveChild()->GetClientSize();
  990.                         wzooml = (int) floor(100.0 * (double) clientsize.GetWidth() / (double) (2 * OPJ_CANVAS_BORDER + currframe->m_canvas->m_image100.GetWidth()));
  991.                         hzooml = (int) floor(100.0 * (double) clientsize.GetHeight() / (double) (2 * OPJ_CANVAS_BORDER + currframe->m_canvas->m_image100.GetHeight()));
  992.                         zooml = wxMin(100, wxMin(wzooml, hzooml));
  993.                 }
  994.         }
  995.  
  996.         if (zooml != 100)
  997.                 new_image.Rescale((int) ((double) zooml * (double) new_image.GetWidth() / 100.0),
  998.                         (int) ((double) zooml * (double) new_image.GetHeight() / 100.0),
  999.                         wxGetApp().m_resizemethod ? wxIMAGE_QUALITY_HIGH : wxIMAGE_QUALITY_NORMAL);
  1000.         currframe->m_canvas->m_image = wxBitmap(new_image);
  1001.         currframe->m_canvas->SetScrollbars(20,
  1002.                                                                                 20,
  1003.                                                                                 (int)(0.5 + (double) new_image.GetWidth() / 20.0),
  1004.                                                                                 (int)(0.5 + (double) new_image.GetHeight() / 20.0)
  1005.                                                                                 );
  1006.  
  1007.         currframe->m_canvas->Refresh();
  1008.  
  1009.         wxLogMessage(wxT("Rescale said %d%%"), zooml);
  1010.  
  1011.         // update zoom
  1012.         currframe->m_canvas->m_zooml = zooml;
  1013. }
  1014.  
  1015.  
  1016. void OPJFrame::OnReload(wxCommandEvent& event)
  1017. {
  1018.         OPJChildFrame *currframe = (OPJChildFrame *) GetActiveChild();
  1019.  
  1020.         if (currframe) {
  1021.                 OPJDecoThread *dthread = currframe->m_canvas->CreateDecoThread();
  1022.  
  1023.                 if (dthread->Run() != wxTHREAD_NO_ERROR)
  1024.                         wxLogMessage(wxT("Can't start deco thread!"));
  1025.                 else
  1026.                         wxLogMessage(wxT("New deco thread started."));
  1027.  
  1028.                 currframe->m_canvas->Refresh();
  1029.  
  1030.                 // update zoom
  1031.                 //currframe->m_canvas->m_zooml = zooml;
  1032.         }
  1033. }
  1034.  
  1035. void OPJFrame::OnPrevFrame(wxCommandEvent& event)
  1036. {
  1037.         if (--wxGetApp().m_framenum < 0)
  1038.                 wxGetApp().m_framenum = 0;
  1039.  
  1040.         wxCommandEvent e;
  1041.         OnReload(e);
  1042. }
  1043.  
  1044. void OPJFrame::OnHomeFrame(wxCommandEvent& event)
  1045. {
  1046.         wxGetApp().m_framenum = 0;
  1047.  
  1048.         wxCommandEvent e;
  1049.         OnReload(e);
  1050. }
  1051.  
  1052. void OPJFrame::OnNextFrame(wxCommandEvent& event)
  1053. {
  1054.         ++wxGetApp().m_framenum;
  1055.  
  1056.         wxCommandEvent e;
  1057.         OnReload(e);
  1058. }
  1059.  
  1060. void OPJFrame::OnLessLayers(wxCommandEvent& event)
  1061. {
  1062.         if (--wxGetApp().m_qualitylayers < 1)
  1063.                 wxGetApp().m_qualitylayers = 1;
  1064.  
  1065.         wxCommandEvent e;
  1066.         OnReload(e);
  1067. }
  1068.  
  1069. void OPJFrame::OnAllLayers(wxCommandEvent& event)
  1070. {
  1071.         wxGetApp().m_qualitylayers = 0;
  1072.  
  1073.         wxCommandEvent e;
  1074.         OnReload(e);
  1075. }
  1076.  
  1077. void OPJFrame::OnMoreLayers(wxCommandEvent& event)
  1078. {
  1079.         ++wxGetApp().m_qualitylayers;
  1080.  
  1081.         wxCommandEvent e;
  1082.         OnReload(e);
  1083. }
  1084.  
  1085. void OPJFrame::OnLessRes(wxCommandEvent& event)
  1086. {
  1087.         ++wxGetApp().m_reducefactor;
  1088.  
  1089.         wxCommandEvent e;
  1090.         OnReload(e);
  1091. }
  1092.  
  1093. void OPJFrame::OnFullRes(wxCommandEvent& event)
  1094. {
  1095.         wxGetApp().m_reducefactor = 0;
  1096.  
  1097.         wxCommandEvent e;
  1098.         OnReload(e);
  1099. }
  1100.  
  1101. void OPJFrame::OnMoreRes(wxCommandEvent& event)
  1102. {
  1103.         if (--wxGetApp().m_reducefactor < 0)
  1104.                 wxGetApp().m_reducefactor = 0;
  1105.  
  1106.         wxCommandEvent e;
  1107.         OnReload(e);
  1108. }
  1109.  
  1110. void OPJFrame::OnPrevComp(wxCommandEvent& event)
  1111. {
  1112.         if (--wxGetApp().m_components < 1)
  1113.                 wxGetApp().m_components = 1;
  1114.  
  1115.         wxCommandEvent e;
  1116.         OnReload(e);
  1117. }
  1118.  
  1119. void OPJFrame::OnAllComps(wxCommandEvent& event)
  1120. {
  1121.         wxGetApp().m_components = 0;
  1122.  
  1123.         wxCommandEvent e;
  1124.         OnReload(e);
  1125. }
  1126.  
  1127. void OPJFrame::OnNextComp(wxCommandEvent& event)
  1128. {
  1129.         ++wxGetApp().m_components;
  1130.  
  1131.         wxCommandEvent e;
  1132.         OnReload(e);
  1133. }
  1134.  
  1135. void OPJFrame::OnToggleBrowser(wxCommandEvent& WXUNUSED(event))
  1136. {
  1137.     if (markerTreeWindow->IsShown())
  1138.         markerTreeWindow->Show(false);
  1139.     else
  1140.         markerTreeWindow->Show(true);
  1141.  
  1142.     wxLayoutAlgorithm layout;
  1143.     layout.LayoutMDIFrame(this);
  1144.  
  1145.         wxGetApp().m_showbrowser = markerTreeWindow->IsShown();
  1146.  
  1147.     // Leaves bits of itself behind sometimes
  1148.     GetClientWindow()->Refresh();
  1149. }
  1150.  
  1151. void OPJFrame::OnTogglePeeker(wxCommandEvent& WXUNUSED(event))
  1152. {
  1153.     if (loggingWindow->IsShown())
  1154.         loggingWindow->Show(false);
  1155.     else
  1156.         loggingWindow->Show(true);
  1157.  
  1158.     wxLayoutAlgorithm layout;
  1159.     layout.LayoutMDIFrame(this);
  1160.  
  1161.         wxGetApp().m_showpeeker = loggingWindow->IsShown();
  1162.  
  1163.     // Leaves bits of itself behind sometimes
  1164.     GetClientWindow()->Refresh();
  1165. }
  1166.  
  1167. void OPJFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
  1168. {
  1169.     if (tool_bar->IsShown())
  1170.         tool_bar->Show(false);
  1171.     else
  1172.         tool_bar->Show(true);
  1173.  
  1174.     wxLayoutAlgorithm layout;
  1175.     layout.LayoutMDIFrame(this);
  1176.  
  1177.         wxGetApp().m_showtoolbar = tool_bar->IsShown();
  1178.  
  1179.     // Leaves bits of itself behind sometimes
  1180.     GetClientWindow()->Refresh();
  1181. }
  1182.  
  1183. void OPJFrame::OnSashDrag(wxSashEvent& event)
  1184. {
  1185.         int wid, hei;
  1186.  
  1187.     if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
  1188.         return;
  1189.  
  1190.     switch (event.GetId()) {
  1191.                 case OPJFRAME_BROWSEWIN:
  1192.                 {
  1193.                         markerTreeWindow->SetDefaultSize(wxSize(event.GetDragRect().width, 1000));
  1194.                         break;
  1195.                 }
  1196.                 case OPJFRAME_LOGWIN:
  1197.                 {
  1198.                         loggingWindow->SetDefaultSize(wxSize(1000, event.GetDragRect().height));
  1199.                         break;
  1200.                 }
  1201.     }
  1202.  
  1203.     wxLayoutAlgorithm layout;
  1204.     layout.LayoutMDIFrame(this);
  1205.  
  1206.     // Leaves bits of itself behind sometimes
  1207.     GetClientWindow()->Refresh();
  1208.  
  1209.         // update dimensions
  1210.         markerTreeWindow->GetSize(&wid, &hei);
  1211.         wxGetApp().m_browserwidth = wid;
  1212.  
  1213.         loggingWindow->GetSize(&wid, &hei);
  1214.         wxGetApp().m_peekerheight = hei;
  1215.  
  1216. }
  1217.  
  1218. void OPJFrame::OnThreadLogmsg(wxCommandEvent& event)
  1219. {
  1220. #if 1
  1221.     wxLogMessage(wxT("Frame got message from worker thread: %d"), event.GetInt());
  1222.     wxLogMessage(event.GetString());
  1223. #else
  1224.     int n = event.GetInt();
  1225.     if ( n == -1 )
  1226.     {
  1227.         m_dlgProgress->Destroy();
  1228.         m_dlgProgress = (wxProgressDialog *)NULL;
  1229.  
  1230.         // the dialog is aborted because the event came from another thread, so
  1231.         // we may need to wake up the main event loop for the dialog to be
  1232.         // really closed
  1233.         wxWakeUpIdle();
  1234.     }
  1235.     else
  1236.     {
  1237.         if ( !m_dlgProgress->Update(n) )
  1238.         {
  1239.             wxCriticalSectionLocker lock(m_critsectWork);
  1240.  
  1241.             m_cancelled = true;
  1242.         }
  1243.     }
  1244. #endif
  1245. }
  1246.  
  1247.  
  1248. // physically save the file
  1249. void OPJFrame::SaveFile(wxArrayString paths, wxArrayString filenames)
  1250. {
  1251.         size_t count = paths.GetCount();
  1252.         wxString msg, s;
  1253.  
  1254.         if (wxFile::Exists(paths[0].c_str())) {
  1255.  
  1256.                 s.Printf(wxT("File %s already exists. Do you want to overwrite it?\n"), filenames[0].c_str());
  1257.                 wxMessageDialog dialog3(this, s, _T("File exists"), wxYES_NO);
  1258.                 if (dialog3.ShowModal() == wxID_NO)
  1259.                         return;
  1260.         }
  1261.  
  1262.         /*s.Printf(_T("File %d: %s (%s)\n"), (int)0, paths[0].c_str(), filenames[0].c_str());
  1263.         msg += s;
  1264.  
  1265.         wxMessageDialog dialog2(this, msg, _T("Selected files"));
  1266.         dialog2.ShowModal();*/
  1267.  
  1268.         if (!GetActiveChild())
  1269.                 return;
  1270.  
  1271.         ((OPJChildFrame *) GetActiveChild())->m_canvas->m_savename = paths[0];
  1272.  
  1273.         OPJEncoThread *ethread = ((OPJChildFrame *) GetActiveChild())->m_canvas->CreateEncoThread();
  1274.  
  1275.     if (ethread->Run() != wxTHREAD_NO_ERROR)
  1276.         wxLogMessage(wxT("Can't start enco thread!"));
  1277.     else
  1278.                 wxLogMessage(wxT("New enco thread started."));
  1279.  
  1280.  
  1281. }
  1282.  
  1283. // physically open the files
  1284. void OPJFrame::OpenFiles(wxArrayString paths, wxArrayString filenames)
  1285. {
  1286.  
  1287.         size_t count = paths.GetCount();
  1288.         for (size_t n = 0; n < count; n++) {
  1289.  
  1290.                 wxString msg, s;
  1291.                 s.Printf(_T("File %d: %s (%s)\n"), (int)n, paths[n].c_str(), filenames[n].c_str());
  1292.  
  1293.                 msg += s;
  1294.  
  1295.                 /*wxMessageDialog dialog2(this, msg, _T("Selected files"));
  1296.                 dialog2.ShowModal();*/
  1297.  
  1298.                 // Make another frame, containing a canvas
  1299.                 OPJChildFrame *subframe = new OPJChildFrame(this,
  1300.                                                                                                         paths[n],
  1301.                                                                                                         winNumber,
  1302.                                                                                                         wxT("Canvas Frame"),
  1303.                                                                                                         wxDefaultPosition, wxSize(300, 300),
  1304.                                                                                                         wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE
  1305.                                                                                                         );
  1306.                 m_childhash[winNumber] = subframe;
  1307.  
  1308.                 // create own marker tree
  1309.                 m_treehash[winNumber] = new OPJMarkerTree(m_bookCtrl, subframe, paths[n], wxT("Parsing..."), TreeTest_Ctrl,
  1310.                                                                                                   wxDefaultPosition, wxDefaultSize,
  1311.                                                                                                   wxTR_DEFAULT_STYLE | wxSUNKEN_BORDER
  1312.                                                                                                   );
  1313.  
  1314.                 m_bookCtrl->AddPage(m_treehash[winNumber], wxString::Format(wxT("%u"), winNumber), false);
  1315.  
  1316.                 for (unsigned int p = 0; p < m_bookCtrl->GetPageCount(); p++) {
  1317.                         if (m_bookCtrl->GetPageText(p) == wxString::Format(wxT("%u"), winNumber)) {
  1318.                                 m_bookCtrl->ChangeSelection(p);
  1319.                                 break;
  1320.                         }
  1321.                 }
  1322.  
  1323.                 winNumber++;
  1324.         }
  1325. }
  1326.  
  1327. void OPJFrame::OnFileOpen(wxCommandEvent& WXUNUSED(event))
  1328. {
  1329.     wxString wildcards =
  1330. #ifdef __WXMOTIF__
  1331.         wxT("JPEG 2000 files (*.jp2,*.j2k,*.j2c,*.mj2)|*.*j*2*");
  1332. #else
  1333. #if wxUSE_LIBOPENJPEG
  1334.         wxT("JPEG 2000 files (*.jp2,*.j2k,*.j2c,*.mj2)|*.jp2;*.j2k;*.j2c;*.mj2")
  1335. #endif
  1336. #if USE_MXF
  1337.         wxT("|MXF JPEG 2000 video (*.mxf)|*.mxf")
  1338. #endif // USE_MXF
  1339. #if wxUSE_LIBJPEG
  1340.                 wxT("|JPEG files (*.jpg)|*.jpg")
  1341. #endif
  1342. #if OPJ_MANYFORMATS
  1343.                 wxT("|BMP files (*.bmp)|*.bmp")
  1344.                 wxT("|PNG files (*.png)|*.png")
  1345.                 wxT("|GIF files (*.gif)|*.gif")
  1346.                 wxT("|PNM files (*.pnm)|*.pnm")
  1347.                 wxT("|TIFF files (*.tif,*.tiff)|*.tif*")
  1348. #endif
  1349.                 wxT("|All files|*");
  1350. #endif
  1351.     wxFileDialog dialog(this, _T("Open image file(s)"),
  1352.                         wxEmptyString, wxEmptyString, wildcards,
  1353.                         wxFD_OPEN|wxFD_MULTIPLE);
  1354.  
  1355.     if (dialog.ShowModal() == wxID_OK) {
  1356.         wxArrayString paths, filenames;
  1357.  
  1358.         dialog.GetPaths(paths);
  1359.         dialog.GetFilenames(filenames);
  1360.  
  1361.                 OpenFiles(paths, filenames);
  1362.     }
  1363.  
  1364. }
  1365.  
  1366. void OPJFrame::OnFileSaveAs(wxCommandEvent& WXUNUSED(event))
  1367. {
  1368.     wxString wildcards =
  1369. #ifdef wxUSE_LIBOPENJPEG
  1370. #ifdef __WXMOTIF__
  1371.         wxT("JPEG 2000 codestream (*.j2k)|*.*j*2*");
  1372. #else
  1373.         wxT("JPEG 2000 codestream (*.j2k)|*.j2k")
  1374.         wxT("|JPEG 2000 file format (*.jp2)|*.jp2");
  1375. #endif
  1376. #endif
  1377.  
  1378.     wxFileDialog dialog(this, _T("Save image file"),
  1379.                         wxEmptyString, wxEmptyString, wildcards,
  1380.                         wxFD_SAVE);
  1381.  
  1382.     if (dialog.ShowModal() == wxID_OK) {
  1383.         wxArrayString paths, filenames;
  1384.  
  1385.         dialog.GetPaths(paths);
  1386.         dialog.GetFilenames(filenames);
  1387.  
  1388.                 SaveFile(paths, filenames);
  1389.     }
  1390.  
  1391.  
  1392. }
  1393.  
  1394. void OPJFrame::OnMemoryOpen(wxCommandEvent& WXUNUSED(event))
  1395. {
  1396.         // do nothing
  1397.         return;
  1398.        
  1399.         wxTextEntryDialog dialog(this, wxT("Memory HEX address range: start_address-stop_address"),
  1400.                                                         wxT("Decode a memory buffer"),
  1401.                                                         wxT("0x-0x"),
  1402.                                                         wxOK | wxCANCEL | wxCENTRE,
  1403.                                                         wxDefaultPosition);
  1404.  
  1405.         if (dialog.ShowModal() == wxID_OK) {
  1406.  
  1407.         }
  1408.  
  1409. }
  1410.  
  1411. BEGIN_EVENT_TABLE(OPJCanvas, wxScrolledWindow)
  1412.     EVT_MOUSE_EVENTS(OPJCanvas::OnEvent)
  1413.     EVT_MENU(OPJCANVAS_THREADSIGNAL, OPJCanvas::OnThreadSignal)
  1414. END_EVENT_TABLE()
  1415.  
  1416. // Define a constructor for my canvas
  1417. OPJCanvas::OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size)
  1418.         : wxScrolledWindow(parent, wxID_ANY, pos, size,
  1419.                            wxSUNKEN_BORDER | wxNO_FULL_REPAINT_ON_RESIZE)
  1420. {
  1421.     SetBackgroundColour(OPJ_CANVAS_COLOUR);
  1422.  
  1423.         m_fname = fname;
  1424.         m_childframe = (OPJChildFrame *) parent;
  1425.         // 100% zoom
  1426.         m_zooml = 100;
  1427.  
  1428.  
  1429.     OPJDecoThread *dthread = CreateDecoThread();
  1430.  
  1431.     if (dthread->Run() != wxTHREAD_NO_ERROR)
  1432.         wxLogMessage(wxT("Can't start deco thread!"));
  1433.     else
  1434.                 wxLogMessage(wxT("New deco thread started."));
  1435.  
  1436.         // 100% zoom
  1437.         //m_zooml = 100;
  1438.  
  1439. }
  1440.  
  1441. OPJDecoThread *OPJCanvas::CreateDecoThread(void)
  1442. {
  1443.     OPJDecoThread *dthread = new OPJDecoThread(this);
  1444.  
  1445.     if (dthread->Create() != wxTHREAD_NO_ERROR)
  1446.                 wxLogError(wxT("Can't create deco thread!"));
  1447.  
  1448.     wxCriticalSectionLocker enter(wxGetApp().m_deco_critsect);
  1449.     wxGetApp().m_deco_threads.Add(dthread);
  1450.  
  1451.     return dthread;
  1452. }
  1453.  
  1454. OPJEncoThread *OPJCanvas::CreateEncoThread(void)
  1455. {
  1456.     OPJEncoThread *ethread = new OPJEncoThread(this);
  1457.  
  1458.     if (ethread->Create() != wxTHREAD_NO_ERROR)
  1459.                 wxLogError(wxT("Can't create enco thread!"));
  1460.  
  1461.     wxCriticalSectionLocker enter(wxGetApp().m_enco_critsect);
  1462.     wxGetApp().m_enco_threads.Add(ethread);
  1463.  
  1464.     return ethread;
  1465. }
  1466.  
  1467. #define activeoverlay 0
  1468. // Define the repainting behaviour
  1469. void OPJCanvas::OnDraw(wxDC& dc)
  1470. {
  1471.         if (m_image.Ok()) {
  1472.                 dc.DrawBitmap(m_image, OPJ_CANVAS_BORDER, OPJ_CANVAS_BORDER);
  1473.  
  1474.                 if (activeoverlay) {
  1475.                         dc.SetPen(*wxRED_PEN);
  1476.                         dc.SetBrush(*wxTRANSPARENT_BRUSH);
  1477.                         //int tw, th;
  1478.                         dc.DrawRectangle(OPJ_CANVAS_BORDER, OPJ_CANVAS_BORDER,
  1479.                                 (unsigned long int) (0.5 + (double) m_zooml * (double) m_childframe->m_twidth / 100.0),
  1480.                                 (unsigned long int) (0.5 + (double) m_zooml * (double) m_childframe->m_theight / 100.0));
  1481.                 }
  1482.  
  1483.         } else {
  1484.                 dc.SetFont(*wxSWISS_FONT);
  1485.                 dc.SetPen(*wxBLACK_PEN);
  1486. #ifdef __WXGTK__
  1487.                 dc.DrawText(_T("Decoding image, please wait... (press \"Zoom to Fit\" to show the image)"), 40, 50);
  1488. #else
  1489.                 dc.DrawText(_T("Decoding image, please wait..."), 40, 50);
  1490. #endif
  1491.         }
  1492. }
  1493.  
  1494. // This implements a tiny doodling program! Drag the mouse using
  1495. // the left button.
  1496. void OPJCanvas::OnEvent(wxMouseEvent& event)
  1497. {
  1498. #if USE_PENCIL_ON_CANVAS
  1499.   wxClientDC dc(this);
  1500.   PrepareDC(dc);
  1501.  
  1502.   wxPoint pt(event.GetLogicalPosition(dc));
  1503.  
  1504.   if ((xpos > -1) && (ypos > -1) && event.Dragging()) {
  1505.     dc.SetPen(*wxRED_PEN);
  1506.     dc.DrawLine(xpos, ypos, pt.x, pt.y);
  1507.   }
  1508.   xpos = pt.x;
  1509.   ypos = pt.y;
  1510. #endif
  1511. }
  1512.  
  1513. void OPJFrame::OnSize(wxSizeEvent& WXUNUSED(event))
  1514. {
  1515.     wxLayoutAlgorithm layout;
  1516.     layout.LayoutMDIFrame(this);
  1517. }
  1518.  
  1519. void OPJCanvas::OnThreadSignal(wxCommandEvent& event)
  1520. {
  1521. #if 1
  1522.     wxLogMessage(wxT("Canvas got signal from deco thread: %d"), event.GetInt());
  1523.     wxLogMessage(event.GetString());
  1524. #else
  1525.     int n = event.GetInt();
  1526.     if ( n == -1 )
  1527.     {
  1528.         m_dlgProgress->Destroy();
  1529.         m_dlgProgress = (wxProgressDialog *)NULL;
  1530.  
  1531.         // the dialog is aborted because the event came from another thread, so
  1532.         // we may need to wake up the main event loop for the dialog to be
  1533.         // really closed
  1534.         wxWakeUpIdle();
  1535.     }
  1536.     else
  1537.     {
  1538.         if ( !m_dlgProgress->Update(n) )
  1539.         {
  1540.             wxCriticalSectionLocker lock(m_critsectWork);
  1541.  
  1542.             m_cancelled = true;
  1543.         }
  1544.     }
  1545. #endif
  1546. }
  1547.  
  1548.  
  1549. // Note that OPJFRAME_FILEOPEN and OPJFRAME_HELPABOUT commands get passed
  1550. // to the parent window for processing, so no need to
  1551. // duplicate event handlers here.
  1552.  
  1553. BEGIN_EVENT_TABLE(OPJChildFrame, wxMDIChildFrame)
  1554.   /*EVT_MENU(SASHTEST_CHILD_QUIT, OPJChildFrame::OnQuit)*/
  1555.   EVT_CLOSE(OPJChildFrame::OnClose)
  1556.   EVT_SET_FOCUS(OPJChildFrame::OnGotFocus)
  1557.   EVT_KILL_FOCUS(OPJChildFrame::OnLostFocus)
  1558. END_EVENT_TABLE()
  1559.  
  1560. OPJChildFrame::OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size,
  1561. const long style):
  1562.   wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style)
  1563. {
  1564.         m_frame = (OPJFrame  *) parent;
  1565.         m_canvas = NULL;
  1566.         //my_children.Append(this);
  1567.         m_fname = fname;
  1568.         m_winnumber = winnumber;
  1569.         SetTitle(wxString::Format(_T("%d: "), m_winnumber) + m_fname.GetFullName());
  1570.  
  1571.           // Give it an icon (this is ignored in MDI mode: uses resources)
  1572. #ifdef __WXMSW__
  1573.         SetIcon(wxIcon(wxT("OPJChild16")));
  1574. #endif
  1575.  
  1576.         // Give it a status line
  1577.         /*CreateStatusBar();*/
  1578.  
  1579.         int width, height;
  1580.         GetClientSize(&width, &height);
  1581.  
  1582.         OPJCanvas *canvas = new OPJCanvas(fname, this, wxPoint(0, 0), wxSize(width, height));
  1583. #if USE_PENCIL_ON_CANVAS
  1584.         canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
  1585. #endif
  1586.         m_canvas = canvas;
  1587.  
  1588.         // Give it scrollbars
  1589.         canvas->SetScrollbars(20, 20, 5, 5);
  1590.  
  1591.         Show(true);
  1592.         Maximize(true);
  1593.  
  1594.         /*wxLogError(wxString::Format(wxT("Created tree %d (0x%x)"), m_winnumber, m_frame->m_treehash[m_winnumber]));*/
  1595.  
  1596. }
  1597.  
  1598. OPJChildFrame::~OPJChildFrame(void)
  1599. {
  1600.   //my_children.DeleteObject(this);
  1601. }
  1602.  
  1603.  
  1604. void OPJChildFrame::OnClose(wxCloseEvent& event)
  1605. {
  1606.         for (unsigned int p = 0; p < m_frame->m_bookCtrl->GetPageCount(); p++) {
  1607.                 if (m_frame->m_bookCtrl->GetPageText(p) == wxString::Format(wxT("%u"), m_winnumber)) {
  1608.                         m_frame->m_bookCtrl->DeletePage(p);
  1609.                         break;
  1610.                 }
  1611.         }
  1612.         Destroy();
  1613.  
  1614.         wxLogMessage(wxT("Closed: %d"), m_winnumber);
  1615. }
  1616.  
  1617. void OPJChildFrame::OnActivate(wxActivateEvent& event)
  1618. {
  1619.   /*if (event.GetActive() && m_canvas)
  1620.     m_canvas->SetFocus();*/
  1621. }
  1622.  
  1623. void OPJChildFrame::OnGotFocus(wxFocusEvent& event)
  1624. {
  1625.         // we need to check if the notebook is being destroyed or not
  1626.         if (!m_frame->m_bookCtrl)
  1627.                 return;
  1628.  
  1629.         for (unsigned int p = 0; p < m_frame->m_bookCtrl->GetPageCount(); p++) {
  1630.  
  1631.                 if (m_frame->m_bookCtrl->GetPageText(p) == wxString::Format(wxT("%u"), m_winnumber)) {
  1632.                         m_frame->m_bookCtrl->ChangeSelection(p);
  1633.                         break;
  1634.                 }
  1635.  
  1636.         }
  1637.  
  1638.         //wxLogMessage(wxT("Got focus: %d (%x)"), m_winnumber, event.GetWindow());
  1639. }
  1640.  
  1641. void OPJChildFrame::OnLostFocus(wxFocusEvent& event)
  1642. {
  1643.         //wxLogMessage(wxT("Lost focus: %d (%x)"), m_winnumber, event.GetWindow());
  1644. }
  1645.  
  1646.  
  1647. ////////////////////////////////
  1648. // drag and drop
  1649. ////////////////////////////////
  1650.  
  1651. bool OPJDnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames)
  1652. {
  1653.     /*size_t nFiles = filenames.GetCount();
  1654.     wxString str;
  1655.     str.Printf( _T("%d files dropped\n"), (int)nFiles);
  1656.     for ( size_t n = 0; n < nFiles; n++ ) {
  1657.         str << filenames[n] << wxT("\n");
  1658.     }
  1659.     wxLogMessage(str);*/
  1660.         m_pOwner->OpenFiles(filenames, filenames);
  1661.  
  1662.     return true;
  1663. }
  1664.  
  1665.