1 /***********************************(GPL)********************************
2 * wxHexEditor is a hex edit tool for editing massive files in Linux *
3 * Copyright (C) 2010 Erdem U. Altinyurt *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; *
17 * if not, write to the Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
19 * *
20 * home : www.wxhexeditor.org *
21 * email : spamjunkeater@gmail.com *
22 *************************************************************************/
23
24 /***************************************************************
25 * Name: wxHexEditorApp.cpp
26 * Purpose: Code for Application Class
27 * Author: Death Knight
28 * Created: 2008-05-12
29 * Copyright: Erdem U. Altinyurt
30 * License:...GPL
31 **************************************************************/
32
33 #ifdef WX_PRECOMP
34 #include "wx_pch.h"
35 #endif
36
37 #ifdef __BORLANDC__
38 #pragma hdrstop
39 #endif //__BORLANDC__
40
41 #include "HexEditorApp.h"
IMPLEMENT_APP(wxHexEditorApp)42 IMPLEMENT_APP(wxHexEditorApp)
43
44 bool wxHexEditorApp::OnInit() {
45 wxImage::AddHandler(new wxPNGHandler);
46 SetLanguage();
47 frame = new HexEditorFrame( 0L );
48 // frame->Connect( wxEVT_MOTION, wxMouseEventHandler(wxHexEditorApp::OnMouseMove),NULL, this);
49 frame->Show();
50 wxYield();
51
52 ///Moved file opening via argv to OnEventLoopEnter()->MyFrameInit() because of need to wait FileSystemWatcher initialization.
53 return true;
54 }
55
MyAppInit()56 void wxHexEditorApp::MyAppInit(){
57 // Open all of the files specified on the command line (assumes no flags)
58 //processing --flags
59 if(argc == 4) {
60 wxString str(argv[1]);
61 //Initializes comparison startup
62 if(str.Lower().StartsWith(wxT("--compare"))){
63 wxArrayString cfiles;
64 for(int j = 1; j < argc; ++j){
65 wxString str(argv[j]);
66 if(!str.Lower().StartsWith(wxT("--compare")) )
67 cfiles.Add(str);
68 }
69
70 ::CompareDialog mcd( frame, cfiles[0], cfiles[1]);
71 mcd.ShowModal();
72 return;
73 }
74 }
75
76 for(int ii = 1; ii < argc; ++ii) {
77 wxString str(argv[ii]);
78 wxFileName fn = wxFileName(str);
79 // if(fn.FileExists() || str.Lower().StartsWith(wxT("-pid")))
80 frame->OpenFile(fn.GetFullPath());
81 }
82 }
83
84 // create the file system watcher here, because it needs an active loop
OnEventLoopEnter(wxEventLoopBase * WXUNUSED (loop))85 void wxHexEditorApp::OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop)) //wxOVERRIDE
86 {
87 static bool first_run=true;
88 if(first_run){
89 first_run=false;
90 #if _FSWATCHER_
91 if(frame->file_watcher == NULL ){
92 frame->file_watcher = new wxFileSystemWatcher();
93 frame->file_watcher->SetOwner(frame);
94 }
95 #endif // _FSWATCHER_
96 MyAppInit();
97 }
98 }
99
SetLanguage(void)100 void wxHexEditorApp::SetLanguage(void){
101 wxString lang = myConfigBase::Get()->Read( _T("Language"), wxEmptyString );
102
103 if ( lang.IsEmpty() )
104 lang= wxLocale::GetLanguageName( wxLocale::GetSystemLanguage() );
105
106 if ( wxLocale::FindLanguageInfo( lang ) == NULL )
107 lang=wxT("English"); //Defaulting to english.
108
109 myConfigBase::Get()->Write( _T("Language"), lang );
110 myConfigBase::Get()->Flush();
111
112 ///Add catalog paths
113 wxFileName flnm(argv[0]); //take current path and search "locale" directory
114 myLocale.AddCatalogLookupPathPrefix( flnm.GetPath(wxPATH_GET_SEPARATOR) + _T("locale") );
115 //myLocale.AddCatalogLookupPathPrefix( _T("./locale") );
116
117 #ifdef _UNIX_
118 myLocale.AddCatalogLookupPathPrefix( _T("/usr/share/locale/") );
119 #endif
120
121 #ifdef __WXMAC__
122 myLocale.AddCatalogLookupPathPrefix( flnm.GetPath(wxPATH_GET_SEPARATOR) +
123 _T("..") + wxFileName::GetPathSeparator() + _T("Resources") + wxFileName::GetPathSeparator() + _T("locale") );
124 #endif
125
126 ///init first
127 int langid = wxLocale::FindLanguageInfo( lang )->Language;
128 if( lang!=wxT("English") ) //Not init for English.
129 if ( !myLocale.Init( langid, wxLOCALE_LOAD_DEFAULT ) ){
130 wxLogError(_T("This language is not supported by the system."));
131 //return; //not return here for continue to load this program catalog
132 }
133 ///And add catalogs
134 myLocale.AddCatalog(_T("wxHexEditor"));
135 }
136
137 #ifdef _DEBUG_EVENTS_
FilterEvent(wxEvent & mevent)138 int wxHexEditorApp::FilterEvent(wxEvent &mevent){
139 if( mevent.IsKindOf(CLASSINFO(wxFocusEvent)) )
140 {
141 wxFocusEvent* event = static_cast<wxFocusEvent*>(&mevent);
142 std::cout << "Frame : " << frame << std::endl;
143 std::cout << "event.GetEventType(): " << event->GetEventType() << std::endl;
144 std::cout << "event.GetEventObject(): " << event->GetEventObject() << std::endl;
145 }
146 if( mevent.IsKindOf(CLASSINFO(wxMouseEvent)) ){
147 wxMouseEvent* event = static_cast<wxMouseEvent*>(&mevent);
148 {
149 std::cout << "Frame : " << frame << std::endl;
150 std::cout << "event.GetEventType(): " << event->GetEventType() << std::endl;
151 std::cout << "event.GetEventObject(): " << event->GetEventObject() << std::endl;
152
153 if(event->GetEventType() == wxEVT_MOUSE_CAPTURE_LOST)
154 std::cout << "event.wxEVT_MOUSE_CAPTURE_LOSTwxEVT_MOUSE_CAPTURE_LOSTwxEVT_MOUSE_CAPTURE_LOST(): " << std::endl;
155 }
156 }
157 mevent.Skip( );
158 return -1;
159 }
160
161
OnMouseMove(wxMouseEvent & event)162 void wxHexEditorApp::OnMouseMove(wxMouseEvent &event){
163 if( event.Moving() )
164 std::cout << "HexEditorApp::OnMouseMove Coordinate X:Y = " << event.m_x << " " << event.m_y
165 << "\tLeft mouse button:" << event.LeftIsDown() << std::endl;
166 else
167 std::cout << "HexEditorApp::OnMouseMove Strange Event" << std::endl;
168 event.Skip();
169 return;
170 }
171 #endif
172