📄 fshedview.cpp
字号:
strcat (buf, " *");
strcat (buf, "]");
if (Doc->bPartialOpen==TRUE)
strcat (buf, " - P");
strcat (buf, " - frhed");
SetWindowText (buf);
Doc->bFilestatusChanged = FALSE;
}
// Selection going on.
if (bSelected == TRUE)
{
if (iEndOfSelection >= iStartOfSelection)
{
sprintf (buf, "Selected: Offset %d=0x%x to %d=0x%x (%d byte(s))", iStartOfSelection, iStartOfSelection,
iEndOfSelection, iEndOfSelection, iEndOfSelection-iStartOfSelection+1);
}
else
{
sprintf (buf, "Selected: Offset %d=0x%x to %d=0x%x (%d byte(s))", iEndOfSelection, iEndOfSelection,
iStartOfSelection, iStartOfSelection, iStartOfSelection-iEndOfSelection+1);
}
::SendMessage (hwndStatusBar, SB_SETTEXT, 0, (LPARAM) buf);
}
else // Normal display.
{
//Pabs changed - \t removed from end of string literal ("Offset %d=0x%x\t" -> "Offset %d=0x%x")
sprintf (buf, "Offset %d=0x%x", m_stScreenSettings.iCurByte, m_stScreenSettings.iCurByte);
//end
int wordval, longval;
char buf2[80];
//Pabs changed - line insert
if (Doc->DataArray.GetLength()-m_stScreenSettings.iCurByte > 0){//if we are not looking at the End byte
// R. Kibria: changed the output slightly (used to be "Bits = 0b").
strcat (buf, " Bits=");//append stuff to status text
unsigned char zzz = Doc->DataArray[m_stScreenSettings.iCurByte];//quicker to have a tmp var than to call operator[] 8 times
for(int i=0;i<8;i++)buf2[i]=((zzz>>i)&0x1?'1':'0');//Extract bits
for(i=0;i<4;i++)swap(buf2[i],buf2[7-i]);//flip order-for some reason it doesn't display correctly going i-- or i++ in for loop
buf2[8]='\0';//terminate string
strcat (buf, buf2);//append to status text
}
strcat (buf, "\t");//add that \t back on to the status text
//end
if (App->m_bUnsignedView) // Values signed/unsigned?
{
// UNSIGNED
if (App->m_iBinaryMode == LITTLEENDIAN_MODE)
{
// UNSIGNED LITTLEENDIAN_MODE
// Decimal value of byte.
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 1)
{
sprintf (buf2, "\tUnsigned: B:%u", (unsigned int) Doc->DataArray[m_stScreenSettings.iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word?
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 2)
{
// Space enough for a word.
wordval = (Doc->DataArray[m_stScreenSettings.iCurByte+1] << 8) | Doc->DataArray[m_stScreenSettings.iCurByte];
sprintf (buf2, ",W:%u", (unsigned int) wordval);
strcat (buf, buf2);
}
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 4)
{
// Space enough for a longword.
longval = wordval | (((Doc->DataArray[m_stScreenSettings.iCurByte + 3] << 8) | Doc->DataArray[m_stScreenSettings.iCurByte + 2]) << 16);
sprintf (buf2, ",L:%u", (unsigned int) longval);
strcat (buf, buf2);
}
}
else
{
// UNSIGNED BIGENDIAN_MODE
// Decimal value of byte.
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 1)
{
sprintf (buf2, "\tUnsigned: B:%u", (unsigned int) Doc->DataArray[m_stScreenSettings.iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word?
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 2)
{
// Space enough for a word.
wordval = (Doc->DataArray[m_stScreenSettings.iCurByte] << 8) | Doc->DataArray[m_stScreenSettings.iCurByte+1];
sprintf (buf2, ",W:%u", (unsigned int) wordval);
strcat (buf, buf2);
}
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 4)
{
// Space enough for a longword.
longval = (wordval<<16) | (Doc->DataArray[m_stScreenSettings.iCurByte+2]<<8) | (Doc->DataArray[m_stScreenSettings.iCurByte+3]);
sprintf (buf2, ",L:%u", (unsigned int) longval);
strcat (buf, buf2);
}
}
}
else // SIGNED
{
if (App->m_iBinaryMode == LITTLEENDIAN_MODE)
{
// SIGNED LITTLEENDIAN_MODE
// Decimal value of byte.
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 1)
{
sprintf (buf2, "\tSigned: B:%d", (int) (signed char) Doc->DataArray[m_stScreenSettings.iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word?
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 2)
{
// Space enough for a word.
wordval = (Doc->DataArray[m_stScreenSettings.iCurByte + 1] << 8) | Doc->DataArray[m_stScreenSettings.iCurByte];
sprintf (buf2, ",W:%d", (int) (signed short) wordval);
strcat (buf, buf2);
}
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 4)
{
// Space enough for a longword.
longval = wordval | (((Doc->DataArray[m_stScreenSettings.iCurByte + 3] << 8) | Doc->DataArray[m_stScreenSettings.iCurByte + 2]) << 16);
sprintf (buf2, ",L:%d", (signed int) longval);
strcat (buf, buf2);
}
}
else
{
// SIGNED BIGENDIAN_MODE
// Decimal value of byte.
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 1)
{
sprintf (buf2, "\tSigned: B:%d", (signed char) Doc->DataArray[m_stScreenSettings.iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word.
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 2)
{
// Space enough for a longword.
wordval = (Doc->DataArray[m_stScreenSettings.iCurByte] << 8) | Doc->DataArray[m_stScreenSettings.iCurByte+1];
sprintf (buf2, ",W:%d", (int) (signed short) wordval);
strcat (buf, buf2);
}
if (Doc->DataArray.GetLength ()-m_stScreenSettings.iCurByte >= 4)
{
// Space enough for a longword.
longval = (wordval<<16) | (Doc->DataArray[m_stScreenSettings.iCurByte+2]<<8) | (Doc->DataArray[m_stScreenSettings.iCurByte+3]);
sprintf (buf2, ",L:%d", (signed int) longval);
strcat (buf, buf2);
}
}
}
::SendMessage (hwndStatusBar, SB_SETTEXT, 0, (LPARAM) buf);
// Character set, input mode or read-only, binary mode.
switch (App->m_iCharacterSet)
{
case ANSI_FIXED_FONT:
sprintf (buf, "\tANSI");
break;
case OEM_FIXED_FONT:
sprintf (buf, "\tOEM");
break;
}
if (Doc->bReadOnly)
{
sprintf (buf2, " / READ");
strcat (buf, buf2);
}
else if (iInsertMode)
{
sprintf (buf2, " / INS");
strcat (buf, buf2);
}
else
{
sprintf (buf2, " / OVR");
strcat (buf, buf2);
}
if (App->m_iBinaryMode == LITTLEENDIAN_MODE)
{
sprintf (buf2, " / L"); // Intel
strcat (buf, buf2);
}
else if (App->m_iBinaryMode == BIGENDIAN_MODE)
{
sprintf (buf2, " / B"); // Motorola
strcat (buf, buf2);
}
::SendMessage (hwndStatusBar, SB_SETTEXT, 1, (LPARAM) buf);
// File size.
sprintf (buf, "\tSize: %u", Doc->DataArray.GetLength ());
::SendMessage (hwndStatusBar, SB_SETTEXT, 2, (LPARAM) buf);
}
}
else
{
SetWindowText ("frhed");
::SendMessage (hwndStatusBar, WM_SETTEXT, 0, (LPARAM) "No file loaded");
}
}
//--------------------------------------------------------------------------------------------
// Set Caret position.
void CFshedView::set_caret_pos ()
{
if (bSelected)
{
::SetCaretPos (-m_stScreenSettings.cxChar, -m_stScreenSettings.cyChar + m_stScreenSettings.iToolbarHeight);
return;
}
int iCaretLine = m_stScreenSettings.iCurByte / App->m_iBytesPerLine,
iBottomLine = m_stScreenSettings.iCurLine + m_stScreenSettings.cyBuffer - 1;
switch (m_iEnteringMode)
{
case CHARS:
if (iCaretLine >= m_stScreenSettings.iCurLine && iCaretLine <= iBottomLine && Doc->filename[0] != '\0')
{
int y = iCaretLine - m_stScreenSettings.iCurLine,
x = App->m_iOffsetLen+m_stScreenSettings.iByteSpace+App->m_iBytesPerLine*3+m_stScreenSettings.iCharSpace
- m_stScreenSettings.iHscrollPos + (m_stScreenSettings.iCurByte%App->m_iBytesPerLine);
::SetCaretPos (CLIENT_BORDER_WIDTH + x*m_stScreenSettings.cxChar, CLIENT_BORDER_WIDTH + y*m_stScreenSettings.cyChar + m_stScreenSettings.iToolbarHeight);
}
else
::SetCaretPos (-m_stScreenSettings.cxChar, -m_stScreenSettings.cyChar + m_stScreenSettings.iToolbarHeight);
break;
case BYTES:
// If caret in vertical visible area...
if (iCaretLine >= m_stScreenSettings.iCurLine && iCaretLine <= iBottomLine && Doc->filename[0] != '\0')
{
int y = iCaretLine - m_stScreenSettings.iCurLine,
x = App->m_iOffsetLen+m_stScreenSettings.iByteSpace + (m_stScreenSettings.iCurByte%App->m_iBytesPerLine)*3 - m_stScreenSettings.iHscrollPos + m_stScreenSettings.iCurNibble;
::SetCaretPos (CLIENT_BORDER_WIDTH + x*m_stScreenSettings.cxChar, CLIENT_BORDER_WIDTH + y*m_stScreenSettings.cyChar + m_stScreenSettings.iToolbarHeight);
}
else
::SetCaretPos (-m_stScreenSettings.cxChar, -m_stScreenSettings.cyChar + m_stScreenSettings.iToolbarHeight);
}
}
//--------------------------------------------------------------------------------------------
// Repaints the whole window.
int CFshedView::repaint( int line )
{
HideCaret();
iUpdateLine = line;
InvalidateRect(NULL, FALSE );
UpdateWindow();
ShowCaret();
return 0;
}
//--------------------------------------------------------------------------------------------
// Clear everything up.
void CFshedView::clear_all ()
{
App->m_iOffsetLen = 8;
m_stScreenSettings.iByteSpace = 2;
App->m_iBytesPerLine = 16;
m_stScreenSettings.iCharSpace = 1;
m_stScreenSettings.iCharsPerLine = App->m_iOffsetLen + m_stScreenSettings.iByteSpace + App->m_iBytesPerLine*3 + m_stScreenSettings.iCharSpace + App->m_iBytesPerLine;
Doc->DataArray.ClearAll ();
Doc->filename[0] = '\0';
m_stScreenSettings.iVscrollMax = 0;
m_stScreenSettings.iVscrollPos = 0;
m_stScreenSettings.iVscrollInc = 0;
m_stScreenSettings.iHscrollMax = 0;
m_stScreenSettings.iHscrollPos = 0;
m_stScreenSettings.iHscrollInc = 0;
m_stScreenSettings.iCurLine = 0;
m_stScreenSettings.iCurByte = 0;
m_stScreenSettings.iCurNibble = 0;
}
//--------------------------------------------------------------------------------------------
// Set the vertical scrollbar position.
void CFshedView::adjust_vscrollbar ()
{
m_stScreenSettings.iVscrollPos = (int) ((float)m_stScreenSettings.iCurLine * ((float)m_stScreenSettings.iVscrollMax)/(float)(m_stScreenSettings.iNumlines-1));
SCROLLINFO si;
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = m_stScreenSettings.iVscrollPos;
::SetScrollInfo(hwndVBar, SB_CTL, &si, TRUE);
// ::SetScrollPos (hwndVBar, SB_CTL, m_stScreenSettings.iVscrollPos, TRUE);
}
//--------------------------------------------------------------------------------------------
// Set the horizontal scrollbar position.
void CFshedView::adjust_hscrollbar ()
{
SCROLLINFO si;
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = m_stScreenSettings.iHscrollPos;
::SetScrollInfo(hwndHBar, SB_CTL, &si, TRUE);
// ::SetScrollPos (hwndHBar, SB_CTL, m_stScreenSettings.iHscrollPos, TRUE);
}
//-------------------------------------------------------------------
int CFshedView::make_font ()
{
if (m_bPrinting)
return 0;
if (hFont != NULL)
DeleteObject (hFont);
HDC hdc = ::GetDC (m_hWnd);
int nHeight = -MulDiv(App->m_iFontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
::ReleaseDC (m_hWnd, hdc);
int cset;
if (App->m_iCharacterSet==ANSI_FIXED_FONT)
cset = ANSI_CHARSET;
else
cset = OEM_CHARSET;
hFont = CreateFont (nHeight,0,0,0,0,0,0,0,cset,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH | FF_DONTCARE,0);
return 1;
}
//--------------------------------------------------------------------------------------------
// Repaint one line in the window.
void CFshedView::print_line (HDC hdc, int line, char* linbuf, HBRUSH hbr )
{
// line = absolute line number.
// if line not visible:
if (line < m_stScreenSettings.iCurLine || line > m_stScreenSettings.iCurLine + m_stScreenSettings.cyBuffer)
return;
if (line < 0)
{
TRACE("Invalid line %d not drawn\n", line);
return;
}
int startpos = line * App->m_iBytesPerLine, endpos, i = 0, m;
char buf[80], c;
// Return if this line does not even contain the end-of-file double
// underscore (at index upperbound+1).
if( startpos > Doc->DataArray.GetUpperBound() + 1 )
{
return;
}
// Write offset.
sprintf (buf, "%%%d.%dx", App->m_iOffsetLen, App->m_iOffsetLen);
for (m=0; m<m_stScreenSettings.iByteSpace; m++)
buf[5+m] = ' ';
buf[5+m] = '\0';
sprintf (linbuf, buf, startpos);
// Last line reached? Then only write rest of bytes.
// startpos+App->m_iBytesPerLine-1 = Last byte in current line.
if (startpos+App->m_iBytesPerLine > Doc->DataArray.GetLength ())
{
// If the first byte of the next line would not be valid, then
// only print the bytes up to and including the last byte of the file.
endpos = Doc->DataArray.GetUpperBound()+1;
}
else
{
// Print the bytes up to the end of this line, they are all valid.
endpos = startpos+App->m_iBytesPerLine-1;
}
// Could happen on arrow down, so that last line is on bottom of window:
if( endpos < startpos )
{
endpos = startpos;
}
// Write bytes.
m = App->m_iOffsetLen+m_stScreenSettings.iByteSpace; // Index of first byte in line.
for (i=startpos; i<=endpos; i++)
{
if (i == Doc->DataArray.GetLength())
{
linbuf[m++] = '_';
linbuf[m++] = '_';
linbuf[m++] = ' ';
}
else
{
c = (Doc->DataArray[i] >> 4);
if( c < 10 )
c += '0';
else
c = c - 10 + 'a';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -