Skip to content

Commit

Permalink
Fixed some CopyAs functions.
Browse files Browse the repository at this point in the history
Fixed Custom Hex Formatting address bar.
Fixed TAG save/load ordering.
  • Loading branch information
EUA committed Feb 22, 2014
1 parent de7f376 commit f1246e1
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BINDIR = $(PREFIX)/bin
DATADIR = $(PREFIX)/share
LOCALEDIR = $(DATADIR)/locale

VERSION = 0.22 Beta
VERSION = 0.23 Beta Development

all:$(EXECUTABLE) langs

Expand Down
89 changes: 49 additions & 40 deletions src/HexDialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,26 +1816,33 @@ void CopyAsDialog::PrepareFullText( wxString& cb, wxMemoryBuffer& buff ){
}
}

void CopyAsDialog::PrepareFullTextWithTAGs( wxString& cb, wxMemoryBuffer& buff, wxString startup=wxEmptyString ){
void CopyAsDialog::PrepareFullTextWithTAGs( wxString& cb, wxMemoryBuffer& buff, wxString startup, wxString ending, wxString blank ){
int selection = chcOption->GetSelection();
bool TAGenable=true;

wxString x3Blank=blank+blank+blank;

unsigned BytePerLine = spnBytePerLine->GetValue();
wxString last_color_hex,last_color_text;
cb += startup+wxT("TAG List:")+wxNewline;
for( unsigned i =0 ; i < MainTagArray->Count() ; i++ ){
TagElement *tag = MainTagArray->Item(i);
if(( tag->start < select->GetStart() and tag->end >= select->GetStart() ) or
( tag->start >= select->GetStart() and tag->start <= select->GetEnd() ) or
( tag->end >= select->GetStart() and tag->end <= select->GetEnd() ) ){

cb += startup+wxT("<span style=\"background-color:") + tag->SoftColour( tag->NoteClrData.GetColour() ).GetAsString(wxC2S_HTML_SYNTAX) +
wxT(";color:") + tag->FontClrData.GetColour().GetAsString(wxC2S_HTML_SYNTAX) + wxT(";\">") + tag->tag +wxT("</span>")+wxNewline;
if(TAGenable){
cb += startup+wxT("TAG List:")+ending;
for( unsigned i =0 ; i < MainTagArray->Count() ; i++ ){
TagElement *tag = MainTagArray->Item(i);
if(( tag->start < select->GetStart() and tag->end >= select->GetStart() ) or
( tag->start >= select->GetStart() and tag->start <= select->GetEnd() ) or
( tag->end >= select->GetStart() and tag->end <= select->GetEnd() ) ){

cb += startup+wxT("<span style=\"background-color:") + tag->SoftColour( tag->NoteClrData.GetColour() ).GetAsString(wxC2S_HTML_SYNTAX) +
wxT(";color:") + tag->FontClrData.GetColour().GetAsString(wxC2S_HTML_SYNTAX) + wxT(";\">") + tag->tag +wxT("</span>")+ending;
}
}
cb += startup+ending;
}
cb += startup+wxNewline;

for(unsigned current_offset = 0; current_offset < select->GetSize() ; current_offset += BytePerLine){
if(chkOffset->GetValue()){
cb += startup + parent->GetFormatedOffsetString( select->GetStart() + current_offset );
cb += wxT(" ");
cb += x3Blank;
}

if(chkHex->GetValue()){
Expand All @@ -1854,31 +1861,33 @@ void CopyAsDialog::PrepareFullTextWithTAGs( wxString& cb, wxMemoryBuffer& buff,
for(unsigned i = 0 ; i < BytePerLine ; i++){

//TAG Paint Loop
for( unsigned j = 0 ; j< MainTagArray->Count() ; j++ ){
TagElement *tg = MainTagArray->Item(j);
if( MainTagArray->Item(j)->start == i + current_offset + select->GetStart()){
last_color_hex = tg->SoftColour(tg->NoteClrData.GetColour()).GetAsString(wxC2S_HTML_SYNTAX);
cb += wxT("<span style=\"background-color:") + last_color_hex + wxT(";\">");
}
if( MainTagArray->Item(j)->end +1== i + current_offset + select->GetStart() ){
cb += wxT("</span>");
last_color_hex = wxEmptyString;
if(TAGenable)
for( unsigned j = 0 ; j< MainTagArray->Count() ; j++ ){
TagElement *tg = MainTagArray->Item(j);
if( MainTagArray->Item(j)->start == i + current_offset + select->GetStart()){
last_color_hex = tg->SoftColour(tg->NoteClrData.GetColour()).GetAsString(wxC2S_HTML_SYNTAX);
cb += wxT("<span style=\"background-color:") + last_color_hex + wxT(";\">");
}
if( MainTagArray->Item(j)->end +1== i + current_offset + select->GetStart() ){
cb += wxT("</span>");
last_color_hex = wxEmptyString;
}
}
}

if( i + current_offset < select->GetSize())
cb+= wxString::Format( wxT("%02X "), (unsigned char)buff[ current_offset + i] );
else{
if(last_color_hex.Len() )
cb += wxT("</span>");
last_color_hex = wxEmptyString;
cb+= wxT(" "); //fill with zero to make text area at proper location
cb+= x3Blank; //fill with zero to make text area at proper location
}
//This avoid to paint text section.
if(last_color_hex.Len() and i==BytePerLine-1)
cb += wxT("</span>");
}
cb += wxT(" "); //Why only 2 ? Because we got extra 1 space from Hex
//cb += wxT(" "); //Why only 2 ? Because we got extra 1 space from Hex
cb += blank+blank; //Why only 2 ? Because we got extra 1 space from Hex
}

if(chkText->GetValue()){
Expand All @@ -1897,18 +1906,19 @@ void CopyAsDialog::PrepareFullTextWithTAGs( wxString& cb, wxMemoryBuffer& buff,
for(unsigned i = 0 ; i < BytePerLine ; i++){
if( i + current_offset < select->GetSize()){

//TAG Paint Loop
for( unsigned j = 0 ; j< MainTagArray->Count() ; j++ ){
TagElement *tg = MainTagArray->Item(j);
if( MainTagArray->Item(j)->start == i + current_offset + select->GetStart()){
last_color_text = tg->SoftColour( tg->NoteClrData.GetColour()).GetAsString(wxC2S_HTML_SYNTAX);
cb += wxT("<span style=\"background-color:") + last_color_text + wxT(";\">");
}
if( MainTagArray->Item(j)->end +1== i + current_offset + select->GetStart()){
cb += wxT("</span>");
last_color_text = wxEmptyString;
//TAG Paint Loop
if(TAGenable)
for( unsigned j = 0 ; j< MainTagArray->Count() ; j++ ){
TagElement *tg = MainTagArray->Item(j);
if( MainTagArray->Item(j)->start == i + current_offset + select->GetStart()){
last_color_text = tg->SoftColour( tg->NoteClrData.GetColour()).GetAsString(wxC2S_HTML_SYNTAX);
cb += wxT("<span style=\"background-color:") + last_color_text + wxT(";\">");
}
if( MainTagArray->Item(j)->end +1== i + current_offset + select->GetStart()){
cb += wxT("</span>");
last_color_text = wxEmptyString;
}
}
}

//Char filter for ascii
chr = buff[ current_offset + i];
Expand All @@ -1921,13 +1931,12 @@ void CopyAsDialog::PrepareFullTextWithTAGs( wxString& cb, wxMemoryBuffer& buff,
cb += wxT("</span>");
}
}
cb += wxNewline;
cb += ending;
}
cb += startup + wxNewline;
cb += startup + ending;
}

void CopyAsDialog::Copy( void ){
chcOption->GetSelection();
if( select->GetState() ) {
int BytePerLine = spnBytePerLine->GetValue();
wxString cb;
Expand Down Expand Up @@ -1980,7 +1989,7 @@ void CopyAsDialog::Copy( void ){

else if( chcOption->GetSelection() == 1 ){ //HTML with Tags
cb += wxT("<pre><code style=\"color:#000000;\">");
PrepareFullTextWithTAGs( cb, buff );
PrepareFullTextWithTAGs( cb, buff, wxT(""), wxT("<br\>"), wxT("&nbsp;") );
cb += wxT("</code></pre><font size=\"-3\">Generated by <a href=\"http://www.wxHexEditor.org\">wxHexEditor</a></font>");
}

Expand All @@ -1996,7 +2005,7 @@ void CopyAsDialog::Copy( void ){
cb += wxT("</pre> Generated by [http://www.wxHexEditor.org/ wxHexEditor]" wxNewline);
}
else if( chcOption->GetSelection() == 4 ){ //WiKi with TAGs
PrepareFullTextWithTAGs( cb, buff, wxT(" ") );
PrepareFullTextWithTAGs( cb, buff, wxT(" "),wxT("\n"),wxT(" ") );
cb += wxT(" Generated by [http://www.wxHexEditor.org/ wxHexEditor]" wxNewline);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/HexDialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CopyAsDialog : public CopyAsDialogGui{
void Copy( void );
void PrepareOptions( int SelectedFunction );
void PrepareFullText( wxString& , wxMemoryBuffer& );
void PrepareFullTextWithTAGs( wxString& , wxMemoryBuffer& , wxString startup);
void PrepareFullTextWithTAGs( wxString& , wxMemoryBuffer& , wxString startup, wxString ending, wxString blank);
wxString GetDigitFormat( void );
};

Expand Down
7 changes: 5 additions & 2 deletions src/HexEditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
#ifndef WXHEXEDITORAPP_H
#define WXHEXEDITORAPP_H

#define _VERSION_ "0.22"
#define _VERSION_S_ _VERSION_ " Beta"
#ifndef _VERSION_
#define _VERSION_ "0.23"
#define _VERSION_S_ _VERSION_ " Beta Development"
#endif // _VERSION_

#ifdef __WXMSW__
#define _VERSION_STR_ _VERSION_S_ " for Windows"
#elif defined(__WXOSX__)
Expand Down
40 changes: 26 additions & 14 deletions src/HexEditorCtrl/HexEditorCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ void HexEditorCtrl::OnResize( wxSizeEvent &event ){

//Preparing Sizer
wxFlexGridSizer* fgSizer1 = new wxFlexGridSizer( 2, 4, 0, 0 );
#if 1
fgSizer1->Add( m_static_offset, 0, wxALIGN_CENTER|wxLEFT, 5 );
fgSizer1->Add( m_static_address, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 2 );
fgSizer1->Add( m_static_byteview, 0, wxALIGN_CENTER|wxALL, 0 );
Expand All @@ -593,7 +594,20 @@ void HexEditorCtrl::OnResize( wxSizeEvent &event ){
fgSizer1->Add( text_ctrl, 0, wxALIGN_CENTER|wxALL|wxEXPAND, 0 );
fgSizer1->Add( offset_scroll_real, 0, wxEXPAND, 0 );

// offset_ctrl->BytePerLine = BytePerLine(); //Not needed, Updated via ReadFromBuffer
#else
fgSizer1->Add( m_static_offset, 0, wxALIGN_CENTER|wxLEFT, 0 );
fgSizer1->Add( m_static_address, 0, wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL|wxLEFT, 0 );
fgSizer1->Add( m_static_byteview, 0, wxALIGN_CENTER|wxALL, 0 );
fgSizer1->Add( m_static_null, 0, wxALIGN_CENTER, 0 );
fgSizer1->Add( offset_ctrl, 0, wxALIGN_CENTER|wxALL|wxEXPAND, 0 );
fgSizer1->Add( hex_ctrl, 0, wxALIGN_CENTER|wxALL, 0 );
fgSizer1->Add( text_ctrl, 0, wxALIGN_CENTER|wxALL|wxEXPAND, 0 );
fgSizer1->Add( offset_scroll_real, 0, wxEXPAND, 0 );
fgSizer1->AddGrowableCol(1,1);
// fgSizer1->AddGrowableRow(1,1);
#endif

this->SetSizer( fgSizer1 );
this->Layout();
Expand All @@ -607,23 +621,19 @@ void HexEditorCtrl::OnResize( wxSizeEvent &event ){

//Formating Hex and byteview column labels
//This needed bellow hex_ctrl->ChangeSize() because it's updates the IsDenied function.
wxString address,byteview;
wxString address,byteview,temp_address;

int h=0;
for( int j = 0 ; j < ByteShownPerLine ; j++ ){
byteview << wxString::Format( wxT("%01X"), j%0x10 );

while(hex_ctrl->IsDenied(h)){
address << wxT(" ");
h++;
}

address << wxString::Format( wxT("%02X"), j%0x100 );
h+=2;
temp_address << wxString::Format( wxT("%02X"), j%0x100 );
}

if(address.Last()==' ')
address.RemoveLast(); //Remove last ' ' for unwrap
//Adjusting custom hex formatting bar - Converting 00010203 -> 00 01 02 03 for "xx " format.
for( int x = 0, i=0 ; x < hex_x and i < temp.Len() ; x++ )
if(hex_ctrl->IsDenied(x))
address << wxT(" ");
else
address << temp_address[i++];

m_static_address->SetLabel(address);
m_static_byteview->SetLabel( byteview );
Expand Down Expand Up @@ -855,6 +865,7 @@ bool HexEditorCtrl::LoadTAGS( wxFileName flnm ){
}
child = child->GetNext();
}
MainTagArray.Sort(TagElementSort);
PreparePaintTAGs();
ClearPaint();
text_ctrl->RePaint();
Expand Down Expand Up @@ -896,7 +907,8 @@ bool HexEditorCtrl::SaveTAGS( wxFileName flnm ){
wxXmlNode *node_File = new wxXmlNode( node_Root, wxXML_ELEMENT_NODE, wxT("filename"), flnm.GetFullPath(), prop_filename , NULL);

MainTagArray.Sort(TagElementSort);
for(unsigned i = 0 ; i < MainTagArray.Count() ; i++ ){
for(signed i = MainTagArray.Count()-1 ; i>=0 ; i-- ){
//Used reverse order for make XML offsets increasing.
TagElement *TAG = MainTagArray.Item(i);

wxXmlProperty *ID = new wxXmlProperty( wxT("id"), wxString::Format(wxT("%d"),i), NULL );
Expand Down
16 changes: 8 additions & 8 deletions src/HexEditorCtrl/HexEditorCtrlGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ HexEditorCtrlGui::HexEditorCtrlGui( wxWindow* parent, wxWindowID id, const wxPoi
fgSizerMain->AddGrowableRow( 2 );
fgSizerMain->SetFlexibleDirection( wxBOTH );

m_static_offset = new wxStaticText( this, ID_DEFAULT, _("Offset"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
m_static_offset = new wxStaticText( this, ID_DEFAULT, wxT("Offset"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
m_static_offset->Wrap( -1 );
m_static_offset->SetFont( wxFont( 10, 70, 90, 90, false, _("sans") ) );
m_static_offset->SetFont( wxFont( 10, 70, 90, 90, false, wxT("sans") ) );

fgSizerMain->Add( m_static_offset, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );

m_static_address = new wxStaticText( this, ID_DEFAULT, _("Address"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
m_static_address = new wxStaticText( this, ID_DEFAULT, wxT("Address"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
m_static_address->Wrap( -1 );
m_static_address->SetFont( wxFont( 10, 70, 90, 90, false, _("sans") ) );
m_static_address->SetFont( wxFont( 10, 70, 90, 90, false, wxT("sans") ) );

fgSizerMain->Add( m_static_address, 1, wxALIGN_CENTER_HORIZONTAL|wxLEFT, 2 );

m_static_byteview = new wxStaticText( this, ID_DEFAULT, _("Byte View"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
m_static_byteview = new wxStaticText( this, ID_DEFAULT, wxT("Byte View"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
m_static_byteview->Wrap( -1 );
m_static_byteview->SetFont( wxFont( 10, 70, 90, 90, false, _("sans") ) );
m_static_byteview->SetFont( wxFont( 10, 70, 90, 90, false, wxT("sans") ) );

fgSizerMain->Add( m_static_byteview, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );

Expand All @@ -53,7 +53,7 @@ HexEditorCtrlGui::HexEditorCtrlGui( wxWindow* parent, wxWindowID id, const wxPoi
fgSizerMain->Add( m_static_null, 0, 0, 5 );

offset_ctrl = new wxHexOffsetCtrl( this, ID_DEFAULT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
offset_ctrl->SetFont( wxFont( 10, 70, 90, 90, false, _("sans") ) );
offset_ctrl->SetFont( wxFont( 10, 70, 90, 90, false, wxT("sans") ) );
offset_ctrl->SetMinSize( wxSize( 104,100 ) );

fgSizerMain->Add( offset_ctrl, 1, wxEXPAND|wxLEFT, 0 );
Expand All @@ -64,7 +64,7 @@ HexEditorCtrlGui::HexEditorCtrlGui( wxWindow* parent, wxWindowID id, const wxPoi
fgSizerMain->Add( hex_ctrl, 1, wxEXPAND, 2 );

text_ctrl = new wxHexTextCtrl( this, ID_TEXTBOX, wxEmptyString, wxDefaultPosition, wxSize( -1,-1 ), 0 );
text_ctrl->SetFont( wxFont( 10, 70, 90, 90, false, _("sans") ) );
text_ctrl->SetFont( wxFont( 10, 70, 90, 90, false, wxT("sans") ) );
text_ctrl->SetMinSize( wxSize( 45,100 ) );

fgSizerMain->Add( text_ctrl, 1, wxEXPAND|wxRIGHT, 2 );
Expand Down
1 change: 1 addition & 0 deletions src/HexEditorCtrl/wxHexCtrl/wxHexCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <wx/config.h>
#include <wx/dcbuffer.h>
#include <wx/clipbrd.h>

#include "Tag.h"

#define __idTagAddSelect__ 1500
Expand Down
Loading

0 comments on commit f1246e1

Please sign in to comment.