2 * Copyright (c) 2007, Digital Signal Processing Laboratory, Universit� degli studi di Perugia (UPG), Italy
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
\r
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
24 * POSSIBILITY OF SUCH DAMAGE.
\r
26 /////////////////////////////////////////////////////////////////////////////
\r
28 // Purpose: Layout window/sash sample
\r
29 // Author: Julian Smart
\r
31 // Created: 04/01/98
\r
32 // RCS-ID: $Id: sashtest.h,v 1.5 2005/06/02 12:04:24 JS Exp $
\r
33 // Copyright: (c) Julian Smart
\r
34 // Licence: wxWindows license
\r
35 /////////////////////////////////////////////////////////////////////////////
\r
36 /////////////////////////////////////////////////////////////////////////////
\r
38 // Purpose: wxTreeCtrl sample
\r
39 // Author: Julian Smart
\r
41 // Created: 04/01/98
\r
42 // RCS-ID: $Id: treetest.h,v 1.50 2006/11/04 11:26:51 VZ Exp $
\r
43 // Copyright: (c) Julian Smart
\r
44 // Licence: wxWindows license
\r
45 /////////////////////////////////////////////////////////////////////////////
\r
47 #ifndef __OPJ_VIEWER_H__
\r
48 #define __OPJ_VIEWER_H__
\r
50 // For compilers that support precompilation, includes "wx/wx.h".
\r
51 #include "wx/wxprec.h"
\r
62 #include "wx/toolbar.h"
\r
63 #include "wx/laywin.h"
\r
64 #include "wx/treectrl.h"
\r
66 #include "icon1.xpm"
\r
67 #include "icon2.xpm"
\r
68 #include "icon3.xpm"
\r
69 #include "icon4.xpm"
\r
70 #include "icon5.xpm"
\r
72 #include "wx/filedlg.h"
\r
73 #include "wx/toolbar.h"
\r
74 #include <wx/filename.h>
\r
75 #include <wx/busyinfo.h>
\r
76 #include <wx/cmdline.h>
\r
77 #include <wx/file.h>
\r
78 #include "wx/notebook.h"
\r
80 #include "libopenjpeg\openjpeg.h"
\r
82 #include "imagj2k.h"
\r
83 #include "imagjp2.h"
\r
84 #include "imagmj2.h"
\r
86 #define USE_GENERIC_TREECTRL 0
\r
88 #if USE_GENERIC_TREECTRL
\r
89 #include "wx/generic/treectlg.h"
\r
91 #define wxTreeCtrl wxGenericTreeCtrl
\r
92 #define sm_classwxTreeCtrl sm_classwxGenericTreeCtrl
\r
96 #define OPJ_APPLICATION_NAME wxT("OpenJPEG Viewer")
\r
97 #define OPJ_APPLICATION_VERSION wxT("0.1 alpha")
\r
98 #define OPJ_APPLICATION_TITLEBAR OPJ_APPLICATION_NAME wxT(" ") OPJ_APPLICATION_VERSION
\r
99 #define OPJ_APPLICATION_COPYRIGHT wxT("(C) 2007, Giuseppe Baruffa")
\r
101 #define OPJ_CANVAS_BORDER 10
\r
102 #define OPJ_CANVAS_COLOUR *wxWHITE
\r
104 class OPJDecoThread;
\r
105 class OPJParseThread;
\r
106 WX_DEFINE_ARRAY_PTR(wxThread *, wxArrayThread);
\r
107 class OPJChildFrame;
\r
109 //////////////////////////////////
\r
110 // this is our main application //
\r
111 //////////////////////////////////
\r
112 class OPJViewerApp: public wxApp
\r
114 // public methods and variables
\r
117 // class constructor
\r
118 OPJViewerApp() { m_showImages = true; m_showButtons = false; }
\r
122 void SetShowImages(bool show) { m_showImages = show; }
\r
123 bool ShowImages() const { return m_showImages; }
\r
124 void ShowCmdLine(const wxCmdLineParser& parser);
\r
126 // all the threads currently alive - as soon as the thread terminates, it's
\r
127 // removed from the array
\r
128 wxArrayThread m_deco_threads, m_parse_threads;
\r
130 // crit section protects access to all of the arrays below
\r
131 wxCriticalSection m_deco_critsect, m_parse_critsect;
\r
133 // semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()
\r
134 wxSemaphore m_deco_semAllDone, m_parse_semAllDone;
\r
136 // the last exiting thread should post to m_semAllDone if this is true
\r
137 // (protected by the same m_critsect)
\r
138 bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone;
\r
140 // the list of all filenames written in the command line
\r
141 wxArrayString m_filelist;
\r
143 // private methods and variables
\r
145 bool m_showImages, m_showButtons;
\r
149 DECLARE_APP(OPJViewerApp)
\r
151 ///////////////////////////////////////////
\r
152 // this canvas is used to draw the image //
\r
153 ///////////////////////////////////////////
\r
154 class OPJCanvas: public wxScrolledWindow
\r
156 // public methods and variables
\r
159 // class constructor
\r
160 OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size);
\r
162 virtual void OnDraw(wxDC& dc);
\r
163 void OnEvent(wxMouseEvent& event);
\r
164 void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave();}
\r
165 OPJDecoThread *CreateDecoThread(void);
\r
168 wxFileName m_fname;
\r
170 DECLARE_EVENT_TABLE()
\r
173 ///////////////////////////////////////////////////
\r
174 // the data associated to each tree leaf or node //
\r
175 ///////////////////////////////////////////////////
\r
176 class OPJMarkerData : public wxTreeItemData
\r
178 // public methods and variables
\r
181 // class constructor
\r
182 OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname) { m_start = start; m_length = length; }
\r
184 void ShowInfo(wxTreeCtrl *tree);
\r
185 const wxChar *GetDesc1() const { return m_desc.c_str(); }
\r
186 const wxChar *GetDesc2() const { return m_filestring.c_str(); }
\r
187 wxFileOffset m_start, m_length;
\r
189 // private methods and variables
\r
192 wxString m_filestring;
\r
196 class OPJMarkerTree : public wxTreeCtrl
\r
202 TreeCtrlIcon_FileSelected,
\r
203 TreeCtrlIcon_Folder,
\r
204 TreeCtrlIcon_FolderSelected,
\r
205 TreeCtrlIcon_FolderOpened
\r
208 OPJMarkerTree() { };
\r
209 OPJMarkerTree(wxWindow *parent, wxFileName fname, wxString name, const wxWindowID id,
\r
210 const wxPoint& pos, const wxSize& size,
\r
212 virtual ~OPJMarkerTree(){};
\r
213 OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00);
\r
214 void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave(); }
\r
216 wxFileName m_fname;
\r
217 wxTextCtrl *m_peektextCtrl;
\r
219 /*void OnBeginDrag(wxTreeEvent& event);
\r
220 void OnBeginRDrag(wxTreeEvent& event);
\r
221 void OnEndDrag(wxTreeEvent& event);*/
\r
222 /*void OnBeginLabelEdit(wxTreeEvent& event);
\r
223 void OnEndLabelEdit(wxTreeEvent& event);*/
\r
224 /*void OnDeleteItem(wxTreeEvent& event);*/
\r
225 /*void OnContextMenu(wxContextMenuEvent& event);*/
\r
226 /*void OnItemMenu(wxTreeEvent& event);*/
\r
227 /*void OnGetInfo(wxTreeEvent& event);
\r
228 void OnSetInfo(wxTreeEvent& event);*/
\r
229 /*void OnItemExpanded(wxTreeEvent& event);*/
\r
230 void OnItemExpanding(wxTreeEvent& event);
\r
231 /*void OnItemCollapsed(wxTreeEvent& event);
\r
232 void OnItemCollapsing(wxTreeEvent& event);*/
\r
233 void OnSelChanged(wxTreeEvent& event);
\r
234 /*void OnSelChanging(wxTreeEvent& event);*/
\r
235 /*void OnTreeKeyDown(wxTreeEvent& event);*/
\r
236 /*void OnItemActivated(wxTreeEvent& event);*/
\r
237 /*void OnItemRClick(wxTreeEvent& event);*/
\r
238 /*void OnRMouseDown(wxMouseEvent& event);
\r
239 void OnRMouseUp(wxMouseEvent& event);
\r
240 void OnRMouseDClick(wxMouseEvent& event);*/
\r
241 /*void GetItemsRecursively(const wxTreeItemId& idParent,
\r
242 wxTreeItemIdValue cookie = 0);*/
\r
244 void CreateImageList(int size = 16);
\r
245 void CreateButtonsImageList(int size = 11);
\r
247 /*void AddTestItemsToTree(size_t numChildren, size_t depth);*/
\r
248 /*void DoSortChildren(const wxTreeItemId& item, bool reverse = false)
\r
249 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }*/
\r
250 /*void DoEnsureVisible() { if (m_lastItem.IsOk()) EnsureVisible(m_lastItem); }*/
\r
251 /*void DoToggleIcon(const wxTreeItemId& item);*/
\r
252 /*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/
\r
254 int ImageSize(void) const { return m_imageSize; }
\r
256 void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
\r
259 /*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/
\r
261 // is this the test item which we use in several event handlers?
\r
262 /*bool IsTestItem(const wxTreeItemId& item)
\r
264 // the test item is the first child folder
\r
265 return GetItemParent(item) == GetRootItem() && !GetPrevSibling(item);
\r
269 /*void AddItemsRecursively(const wxTreeItemId& idParent,
\r
274 void LogEvent(const wxChar *name, const wxTreeEvent& event);
\r
276 int m_imageSize; // current size of images
\r
277 bool m_reverseSort; // flag for OnCompareItems
\r
278 wxTreeItemId m_lastItem, // for OnEnsureVisible()
\r
279 m_draggedItem; // item being dragged right now
\r
281 // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
\r
282 // if you want your overloaded OnCompareItems() to be called.
\r
283 // OTOH, if you don't want it you may omit the next line - this will
\r
284 // make default (alphabetical) sorting much faster under wxMSW.
\r
285 DECLARE_DYNAMIC_CLASS(OPJMarkerTree)
\r
286 DECLARE_EVENT_TABLE()
\r
289 // this hash map stores all the trees of currently opened images, with an integer key
\r
290 WX_DECLARE_HASH_MAP(int, OPJMarkerTree*, wxIntegerHash, wxIntegerEqual, OPJMarkerTreeHash);
\r
292 // this hash map stores all the children of currently opened images, with an integer key
\r
293 WX_DECLARE_HASH_MAP(int, OPJChildFrame*, wxIntegerHash, wxIntegerEqual, OPJChildFrameHash);
\r
295 // Define a new frame
\r
296 class OPJFrame: public wxMDIParentFrame
\r
300 OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
\r
303 void OnSize(wxSizeEvent& event);
\r
304 void OnAbout(wxCommandEvent& WXUNUSED(event));
\r
305 void OnFileOpen(wxCommandEvent& WXUNUSED(event));
\r
306 void OnQuit(wxCommandEvent& WXUNUSED(event));
\r
307 void OnToggleWindow(wxCommandEvent& WXUNUSED(event));
\r
308 void OnSashDrag(wxSashEvent& event);
\r
309 void OpenFiles(wxArrayString paths, wxArrayString filenames);
\r
310 void OnNotebook(wxNotebookEvent& event);
\r
312 OPJMarkerTreeHash m_treehash;
\r
313 OPJChildFrameHash m_childhash;
\r
314 wxSashLayoutWindow* markerTreeWindow;
\r
315 wxSashLayoutWindow* loggingWindow;
\r
316 void Resize(int number);
\r
317 wxNotebook *m_bookCtrl;
\r
318 wxNotebook *m_bookCtrlbottom;
\r
319 wxTextCtrl *m_textCtrlbrowse;
\r
322 void TogStyle(int id, long flag);
\r
324 void DoSort(bool reverse = false);
\r
327 wxTextCtrl *m_textCtrl;
\r
329 void DoSetBold(bool bold = true);
\r
332 wxSashLayoutWindow* m_topWindow;
\r
333 wxSashLayoutWindow* m_leftWindow2;
\r
335 DECLARE_EVENT_TABLE()
\r
338 class OPJChildFrame: public wxMDIChildFrame
\r
341 OPJCanvas *m_canvas;
\r
342 OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
\r
343 ~OPJChildFrame(void);
\r
344 void OnActivate(wxActivateEvent& event);
\r
345 /*void OnQuit(wxCommandEvent& WXUNUSED(event));*/
\r
346 void OnClose(wxCloseEvent& event);
\r
347 void OnGotFocus(wxFocusEvent& event);
\r
348 /*void OnLostFocus(wxFocusEvent& event);*/
\r
350 wxFileName m_fname;
\r
353 DECLARE_EVENT_TABLE()
\r
356 #define SASHTEST_QUIT wxID_EXIT
\r
357 #define SASHTEST_NEW_WINDOW 2
\r
358 #define SASHTEST_REFRESH 3
\r
359 #define SASHTEST_CHILD_QUIT 4
\r
360 #define SASHTEST_ABOUT wxID_ABOUT
\r
361 #define SASHTEST_TOGGLE_WINDOW 6
\r
363 #define ID_WINDOW_TOP 100
\r
364 #define ID_WINDOW_LEFT1 101
\r
365 #define ID_WINDOW_LEFT2 102
\r
366 #define ID_WINDOW_BOTTOM 103
\r
368 // menu and control ids
\r
371 TreeTest_Quit = wxID_EXIT,
\r
372 TreeTest_About = wxID_ABOUT,
\r
373 TreeTest_TogButtons = wxID_HIGHEST,
\r
377 TreeTest_TogHideRoot,
\r
378 TreeTest_TogRootLines,
\r
379 TreeTest_TogBorder,
\r
380 TreeTest_TogFullHighlight,
\r
381 TreeTest_SetFgColour,
\r
382 TreeTest_SetBgColour,
\r
383 TreeTest_ResetStyle,
\r
384 TreeTest_Highlight,
\r
386 TreeTest_DumpSelected,
\r
392 TreeTest_ClearBold,
\r
395 TreeTest_DeleteChildren,
\r
396 TreeTest_DeleteAll,
\r
398 TreeTest_ToggleImages,
\r
399 TreeTest_ToggleButtons,
\r
400 TreeTest_SetImageSize,
\r
401 TreeTest_ToggleSel,
\r
402 TreeTest_CollapseAndReset,
\r
403 TreeTest_EnsureVisible,
\r
405 TreeTest_InsertItem,
\r
406 TreeTest_IncIndent,
\r
407 TreeTest_DecIndent,
\r
408 TreeTest_IncSpacing,
\r
409 TreeTest_DecSpacing,
\r
410 TreeTest_ToggleIcon,
\r
413 TreeTest_SelectRoot,
\r
414 TreeTest_Ctrl = 1000,
\r
415 BOTTOM_NOTEBOOK_ID,
\r
419 class OPJDecoThread : public wxThread
\r
422 OPJDecoThread(OPJCanvas *canvas);
\r
424 // thread execution starts here
\r
425 virtual void *Entry();
\r
427 // called when the thread exits - whether it terminates normally or is
\r
428 // stopped with Delete() (but not when it is Kill()ed!)
\r
429 virtual void OnExit();
\r
431 // write something to the text control
\r
432 void WriteText(const wxString& text);
\r
436 OPJCanvas *m_canvas;
\r
439 class OPJParseThread : public wxThread
\r
442 OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid = 0x00);
\r
444 // thread execution starts here
\r
445 virtual void *Entry();
\r
447 // called when the thread exits - whether it terminates normally or is
\r
448 // stopped with Delete() (but not when it is Kill()ed!)
\r
449 virtual void OnExit();
\r
451 // write something to the text control
\r
452 void WriteText(const wxString& text);
\r
453 void LoadFile(wxFileName fname);
\r
454 void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid);
\r
455 void ParseJP2File(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, wxTreeItemId parentid);
\r
458 OPJMarkerTree *m_tree;
\r
459 wxTreeItemId m_parentid;
\r
462 int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
\r
463 wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
\r
464 int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
\r
465 wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
\r
469 #endif //__OPJ_VIEWER_H__
\r