Fix file viewer position for tall SHR images

The images in Paintworks PNT files are 2x the height of the SHR
screen.  The rich edit control was ending up scrolled to the bottom
of the image, which is bad because many of the image files don't
really have anything interesting in the bottom half.  This shifts
the position back to the top.

Also, some minor source code touch-ups.
This commit is contained in:
Andy McFadden 2015-01-16 15:15:40 -08:00
parent 61c4069031
commit 357aba39ec
4 changed files with 49 additions and 34 deletions

View File

@ -2334,7 +2334,8 @@ void MainWindow::GetFilePart(const GenericEntry* pEntry, int whichThread,
if (threadLen > fPreferences.GetPrefLong(kPrMaxViewFileSize)) {
errMsg.Format(
L"[File size (%I64d KBytes) exceeds file viewer maximum (%ld KBytes).]\n",
L"[File size (%I64d KBytes) exceeds file viewer maximum (%ld KBytes). "
L"The limit can be adjusted in the file viewer preferences.]\n",
((LONGLONG) threadLen + 1023) / 1024,
(fPreferences.GetPrefLong(kPrMaxViewFileSize) + 1023) / 1024);
pHolder->SetErrorMsg(part, errMsg);

View File

@ -83,7 +83,7 @@ static const WCHAR gFileTypeNames[256][4] = {
static const WCHAR kUnknownTypeStr[] = L"???";
/*static*/ const WCHAR* PathProposal::FileTypeString(unsigned long fileType)
/*static*/ const WCHAR* PathProposal::FileTypeString(uint32_t fileType)
{
// Note to self: code down below tests first char for '?'.
if (fileType < NELEM(gFileTypeNames))
@ -102,26 +102,25 @@ static const WCHAR kUnknownTypeStr[] = L"???";
* file rather than a hard-coded table. Ought to fix that someday.
*/
static const struct {
const WCHAR* label;
unsigned short fileType;
unsigned long auxType;
unsigned char flags;
const WCHAR* label;
uint8_t fileType;
uint16_t auxType;
} gRecognizedExtensions[] = {
{ L"ASM", 0xb0, 0x0003, 0 }, /* APW assembly source */
{ L"C", 0xb0, 0x000a, 0 }, /* APW C source */
{ L"H", 0xb0, 0x000a, 0 }, /* APW C header */
{ L"CPP", 0xb0, 0x0000, 0 }, /* generic source file */
{ L"BNY", 0xe0, 0x8000, 0 }, /* Binary II lib */
{ L"BQY", 0xe0, 0x8000, 0 }, /* Binary II lib, w/ compress */
{ L"BXY", 0xe0, 0x8000, 0 }, /* Binary II wrap around SHK */
{ L"BSE", 0xe0, 0x8000, 0 }, /* Binary II wrap around SEA */
{ L"SEA", 0xb3, 0xdb07, 0 }, /* GSHK SEA */
{ L"TEXT", 0x04, 0x0000, 0 }, /* ASCII Text */
{ L"GIF", 0xc0, 0x8006, 0 }, /* GIF image */
{ L"JPG", 0x06, 0x0000, 0 }, /* JPEG (nicer than 'NON') */
{ L"JPEG", 0x06, 0x0000, 0 }, /* JPEG (nicer than 'NON') */
//{ L"ACU", 0xe0, 0x8001, 0 }, /* ACU archive */
{ L"SHK", 0xe0, 0x8002, 0 }, /* ShrinkIt archive */
{ L"ASM", 0xb0, 0x0003 }, /* APW assembly source */
{ L"C", 0xb0, 0x000a }, /* APW C source */
{ L"H", 0xb0, 0x000a }, /* APW C header */
{ L"CPP", 0xb0, 0x0000 }, /* generic source file */
{ L"BNY", 0xe0, 0x8000 }, /* Binary II lib */
{ L"BQY", 0xe0, 0x8000 }, /* Binary II lib, w/ compress */
{ L"BXY", 0xe0, 0x8000 }, /* Binary II wrap around SHK */
{ L"BSE", 0xe0, 0x8000 }, /* Binary II wrap around SEA */
{ L"SEA", 0xb3, 0xdb07 }, /* GSHK SEA */
{ L"TEXT", 0x04, 0x0000 }, /* ASCII Text */
{ L"GIF", 0xc0, 0x8006 }, /* GIF image */
{ L"JPG", 0x06, 0x0000 }, /* JPEG (nicer than 'NON') */
{ L"JPEG", 0x06, 0x0000 }, /* JPEG (nicer than 'NON') */
//{ L"ACU", 0xe0, 0x8001 }, /* ACU archive */
{ L"SHK", 0xe0, 0x8002 }, /* ShrinkIt archive */
};
/*
@ -134,11 +133,13 @@ static const struct {
* "FTD" file type description file that the IIgs Finder used. Might have
* made sense to just ship that and load it on startup (although copyright
* issues would have to be investigated).
*
* This list should be complete as of the May 1992 "about" note.
*/
static const struct {
unsigned short fileType;
unsigned short minAuxType; // start of range for which this applies
unsigned short maxAuxType; // end of range
uint8_t fileType;
uint16_t minAuxType; // start of range for which this applies
uint16_t maxAuxType; // end of range
const WCHAR* descr;
} gTypeDescriptions[] = {
/*NON*/ { 0x00, 0x0000, 0xffff, L"Untyped file" },
@ -763,7 +764,7 @@ void PathProposal::Win32NormalizeFileName(const WCHAR* srcp, long srcLen,
char fssep, WCHAR** pDstp, long dstLen)
{
/*
* TODO: consider supporting the "Mac Roman" characters
* TODO(Unicode): do proper conversion
* TODO: don't allow the filename to end with a space or period (Windows
* requirement)
*/
@ -779,7 +780,7 @@ void PathProposal::Win32NormalizeFileName(const WCHAR* srcp, long srcLen,
if (wcsnicmp(srcp, *ppcch, 3) == 0 &&
(srcp[3] == '.' || srcLen == 3))
{
LOGI("--- fixing '%ls'", *ppcch);
LOGD("--- fixing '%ls'", *ppcch);
if (fPreservation) {
*dstp++ = kForeignIndic;
*dstp++ = '0';
@ -797,7 +798,7 @@ void PathProposal::Win32NormalizeFileName(const WCHAR* srcp, long srcLen,
if (wcsnicmp(srcp, *ppcch, 4) == 0 &&
(srcp[4] == '.' || srcLen == 4))
{
LOGI("--- fixing '%ls'", *ppcch);
LOGD("--- fixing '%ls'", *ppcch);
if (fPreservation) {
*dstp++ = kForeignIndic;
*dstp++ = '0';
@ -822,7 +823,6 @@ void PathProposal::Win32NormalizeFileName(const WCHAR* srcp, long srcLen,
*srcp < 0x20 || *srcp >= 0x7f)
{
/* change invalid char to "%2f" or '_' */
// TODO: this assumes 8-bit input; should convert to UTF-8
if (fPreservation) {
*dstp++ = kForeignIndic;
*dstp++ = HexConv(*srcp >> 4 & 0x0f);

View File

@ -77,8 +77,8 @@ public:
// filesystem separator char (or '\0' for things like DOS 3.3)
char fStoredFssep;
// file type, aux type, and what piece of the file this is
unsigned long fFileType;
unsigned long fAuxType;
uint32_t fFileType;
uint32_t fAuxType;
int fThreadKind; // GenericEntry, e.g. kDataThread
/*
@ -101,7 +101,7 @@ public:
/*
* Return a pointer to the three-letter representation of the file type name.
*/
static const WCHAR* FileTypeString(unsigned long fileType);
static const WCHAR* FileTypeString(uint32_t fileType);
/*
* Find an entry in the type description table that matches both file type and

View File

@ -319,6 +319,9 @@ void ViewFilesDialog::DisplayText(const WCHAR* fileName)
* the user hit. We could also create a bogus control, move it into
* negative space where it will be invisible, and use that as a "focus
* holder".
*
* TODO: on Win7 you can sometimes see a blue flash. Not sure if it
* relates to this or some other aspect of the redraw.
*/
CWnd* pFocusWnd = GetFocus();
if (pFocusWnd == NULL || pFocusWnd->m_hWnd == pEdit->m_hWnd) {
@ -367,14 +370,14 @@ void ViewFilesDialog::DisplayText(const WCHAR* fileName)
hBitmap = fpOutput->GetDIB()->ConvertToDDB(dcScreen.m_hDC);
if (hBitmap == NULL) {
LOGI("ConvertToDDB failed!");
LOGW("ConvertToDDB failed!");
pEdit->SetWindowText(L"Internal error.");
errFlg = true;
} else {
//DumpBitmapInfo(hBitmap);
//DumpBitmapInfo(pDib->GetHandle());
LOGI("Inserting bitmap");
LOGD("Inserting bitmap");
pEdit->SetWindowText(L"");
CImageDataObject::InsertBitmap(fpRichEditOle, hBitmap);
@ -435,7 +438,7 @@ void ViewFilesDialog::DisplayText(const WCHAR* fileName)
/* a -16 error can happen if the type is RTF but contents are not */
char errorText[256];
sprintf(errorText,
_snprintf(errorText, sizeof(errorText),
"ERROR: failed while loading data (err=0x%08lx)\n"
"(File contents might be too big for Windows to display)\n",
es.dwError);
@ -510,6 +513,8 @@ void ViewFilesDialog::DisplayText(const WCHAR* fileName)
* Anything related to RichEdit controls is extremely fragile, and must
* be tested with a variety of inputs, preference settings, and under
* at least Win98 and Win2K (which are *very* different).
*
* TODO: re-evaluate all this without worrying about Win9x
*/
if (fFirstResize) {
/* adjust the size of the window to match the last size used */
@ -534,6 +539,15 @@ void ViewFilesDialog::DisplayText(const WCHAR* fileName)
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputBitmap) {
/* get the cursor off of the image */
pEdit->SetSel(-1, -1);
/*
* Tall Super Hi-Res graphics (e.g. Paintworks PNT) cause the edit
* control to scroll to the bottom. Move it back to the top.
*
* SetScrollInfo just moves the scrollbar without changing the
* view position.
*/
pEdit->SendMessage(WM_VSCROLL, SB_TOP, 0);
}
/*