2007-03-27 17:47:10 +00:00
|
|
|
/*
|
|
|
|
* CiderPress
|
|
|
|
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
|
|
|
|
* See the file LICENSE for distribution terms.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Support for the "view files" dialog box.
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ViewFilesDialog.h"
|
|
|
|
#include "Main.h"
|
|
|
|
#include "Print.h"
|
|
|
|
#include "../util/UtilLib.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ===========================================================================
|
2014-11-04 00:26:53 +00:00
|
|
|
* ViewFilesDialog
|
2007-03-27 17:47:10 +00:00
|
|
|
* ===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const UINT gFindReplaceID = RegisterWindowMessage(FINDMSGSTRING);
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(ViewFilesDialog, CDialog)
|
2014-11-04 00:26:53 +00:00
|
|
|
ON_WM_CREATE()
|
|
|
|
ON_WM_DESTROY()
|
|
|
|
ON_WM_SIZE()
|
|
|
|
ON_WM_GETMINMAXINFO()
|
|
|
|
ON_REGISTERED_MESSAGE(gFindReplaceID, OnFindDialogMessage)
|
|
|
|
ON_COMMAND(IDC_FVIEW_NEXT, OnFviewNext)
|
|
|
|
ON_COMMAND(IDC_FVIEW_PREV, OnFviewPrev)
|
|
|
|
ON_COMMAND(IDC_FVIEW_FONT, OnFviewFont)
|
|
|
|
ON_COMMAND(IDC_FVIEW_PRINT, OnFviewPrint)
|
|
|
|
ON_COMMAND(IDC_FVIEW_FIND, OnFviewFind)
|
|
|
|
ON_BN_CLICKED(IDC_FVIEW_DATA, OnFviewData)
|
|
|
|
ON_BN_CLICKED(IDC_FVIEW_RSRC, OnFviewRsrc)
|
|
|
|
ON_BN_CLICKED(IDC_FVIEW_CMMT, OnFviewCmmt)
|
|
|
|
ON_COMMAND(IDC_FVIEW_FMT_BEST, OnFviewFmtBest)
|
|
|
|
ON_COMMAND(IDC_FVIEW_FMT_HEX, OnFviewFmtHex)
|
|
|
|
ON_COMMAND(IDC_FVIEW_FMT_RAW, OnFviewFmtRaw)
|
|
|
|
ON_CBN_SELCHANGE(IDC_FVIEW_FORMATSEL, OnFormatSelChange)
|
|
|
|
ON_COMMAND(IDHELP, OnHelp)
|
2007-03-27 17:47:10 +00:00
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
BOOL ViewFilesDialog::OnInitDialog(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("Now in VFD OnInitDialog!");
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpSelSet != NULL);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* delete dummy control and insert our own with modded styles */
|
|
|
|
CRichEditCtrl* pEdit = (CRichEditCtrl*)GetDlgItem(IDC_FVIEW_EDITBOX);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEdit != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
CRect rect;
|
|
|
|
pEdit->GetWindowRect(&rect);
|
|
|
|
pEdit->DestroyWindow();
|
|
|
|
ScreenToClient(&rect);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
DWORD styles = ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY |
|
2007-03-27 17:47:10 +00:00
|
|
|
WS_BORDER | WS_VSCROLL | WS_VISIBLE | WS_TABSTOP |
|
2014-11-04 00:26:53 +00:00
|
|
|
ES_NOHIDESEL;
|
|
|
|
if (fNoWrapText)
|
|
|
|
styles |= ES_AUTOHSCROLL | WS_HSCROLL;
|
|
|
|
fEditCtrl.Create(styles, rect, this, IDC_FVIEW_EDITBOX);
|
|
|
|
fEditCtrl.SetFocus();
|
|
|
|
/*
|
|
|
|
* HEY: I think we can do this with pEdit->ShowScrollBar(SB_BOTH) !!
|
|
|
|
* Could also use GetWindowLong/SetWindowLong to change the window style;
|
|
|
|
* probably need a SetWindowPos to cause changes to flush.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to adjust the size of the window to match the last size used.
|
|
|
|
* However, if we do this after creating the edit dialog but before it
|
|
|
|
* actually has data to display, then when we stuff data into it the
|
|
|
|
* scroll bar goodies are all out of whack.
|
|
|
|
*/
|
|
|
|
fFirstResize = true;
|
2007-03-27 17:47:10 +00:00
|
|
|
#if 0
|
2014-11-04 00:26:53 +00:00
|
|
|
const Preferences* pPreferences = GET_PREFERENCES();
|
|
|
|
long width = pPreferences->GetFileViewerWidth();
|
|
|
|
long height = pPreferences->GetFileViewerHeight();
|
|
|
|
CRect fullRect;
|
|
|
|
GetWindowRect(&fullRect);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI(" VFD pre-size %dx%d", fullRect.Width(), fullRect.Height());
|
2014-11-04 00:26:53 +00:00
|
|
|
fullRect.right = fullRect.left + width;
|
|
|
|
fullRect.bottom = fullRect.top + height;
|
|
|
|
MoveWindow(fullRect, FALSE);
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
// This invokes UpdateData, which calls DoDataExchange, which leads to
|
|
|
|
// the StreamIn call. So don't do this until everything else is ready.
|
|
|
|
CDialog::OnInitDialog();
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("VFD OnInitDialog done");
|
2014-11-04 00:26:53 +00:00
|
|
|
return FALSE; // don't let Windows set the focus
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
int ViewFilesDialog::OnCreate(LPCREATESTRUCT lpcs)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("VFD OnCreate");
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
HICON hIcon;
|
|
|
|
hIcon = ::AfxGetApp()->LoadIcon(IDI_FILE_VIEWER);
|
|
|
|
SetIcon(hIcon, TRUE);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
GetClientRect(&fLastWinSize);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
CRect initRect(fLastWinSize);
|
|
|
|
initRect.left = initRect.right - ::GetSystemMetrics(SM_CXVSCROLL);
|
|
|
|
initRect.top = initRect.bottom - ::GetSystemMetrics(SM_CYHSCROLL);
|
|
|
|
fGripper.Create(WS_CHILD | WS_VISIBLE |
|
|
|
|
SBS_SIZEBOX | SBS_SIZEBOXBOTTOMRIGHTALIGN | SBS_SIZEGRIP,
|
|
|
|
initRect, this, AFX_IDW_SIZE_BOX);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("VFD OnCreate done");
|
2014-11-04 00:26:53 +00:00
|
|
|
return 0;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnDestroy(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
Preferences* pPreferences = GET_PREFERENCES_WR();
|
|
|
|
CRect rect;
|
|
|
|
GetWindowRect(&rect);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
pPreferences->SetPrefLong(kPrFileViewerWidth, rect.Width());
|
|
|
|
pPreferences->SetPrefLong(kPrFileViewerHeight, rect.Height());
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
CDialog::OnDestroy();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnOK(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
if (fBusy)
|
|
|
|
MessageBeep(-1);
|
|
|
|
else {
|
|
|
|
CRect rect;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
GetWindowRect(&rect);
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD(" VFD size now %dx%d", rect.Width(), rect.Height());
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
CDialog::OnOK();
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
void ViewFilesDialog::OnCancel(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
if (fBusy)
|
|
|
|
MessageBeep(-1);
|
|
|
|
else
|
|
|
|
CDialog::OnCancel();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnGetMinMaxInfo(MINMAXINFO* pMMI)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
pMMI->ptMinTrackSize.x = 664;
|
|
|
|
pMMI->ptMinTrackSize.y = 200;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnSize(UINT nType, int cx, int cy)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CDialog::OnSize(nType, cx, cy);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
//LOGI("Dialog: old size %d,%d",
|
2014-11-04 00:26:53 +00:00
|
|
|
// fLastWinSize.Width(), fLastWinSize.Height());
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("Dialog: new size %d,%d", cx, cy);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (fLastWinSize.Width() == cx && fLastWinSize.Height() == cy) {
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("VFD OnSize: no change");
|
2014-11-04 00:26:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
int deltaX, deltaY;
|
|
|
|
deltaX = cx - fLastWinSize.Width();
|
|
|
|
deltaY = cy - fLastWinSize.Height();
|
2014-11-18 21:05:15 +00:00
|
|
|
//LOGI("Delta is %d,%d", deltaX, deltaY);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
ShiftControls(deltaX, deltaY);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
GetClientRect(&fLastWinSize);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::ShiftControls(int deltaX, int deltaY)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
HDWP hdwp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use deferred reposn so that they don't end up drawing on top of each
|
|
|
|
* other and getting all weird.
|
|
|
|
*
|
|
|
|
* IMPORTANT: the DeferWindowPos stuff changes the tab order of the
|
|
|
|
* items in the window. The controls must be added in the reverse
|
|
|
|
* order in which they appear in the window.
|
|
|
|
*/
|
|
|
|
hdwp = BeginDeferWindowPos(15);
|
|
|
|
hdwp = MoveControl(hdwp, this, AFX_IDW_SIZE_BOX, deltaX, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDHELP, deltaX, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_FONT, deltaX, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_PRINT, deltaX, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_FIND, deltaX, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_FMT_RAW, 0, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_FMT_HEX, 0, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_FMT_BEST, 0, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_PREV, 0, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_NEXT, 0, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_CMMT, 0, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_RSRC, 0, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDC_FVIEW_DATA, 0, deltaY);
|
|
|
|
hdwp = MoveStretchControl(hdwp, this, IDC_FVIEW_FORMATSEL, 0, deltaY, deltaX, 0);
|
|
|
|
hdwp = StretchControl(hdwp, this, IDC_FVIEW_EDITBOX, deltaX, deltaY);
|
|
|
|
hdwp = MoveControl(hdwp, this, IDOK, deltaX, deltaY);
|
|
|
|
if (!EndDeferWindowPos(hdwp)) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("EndDeferWindowPos failed");
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Work around buggy CRichEdit controls. The inner edit area is only
|
|
|
|
* resized when the box is shrunk, not when it's expanded, and the
|
|
|
|
* results are inconsistent between Win98 and Win2K.
|
|
|
|
*
|
|
|
|
* Set the internal size equal to the size of the entire edit box.
|
|
|
|
* This should be large enough to make everything work right, but small
|
|
|
|
* enough to avoid funky scrolling behavior. (If you want to set this
|
|
|
|
* more precisely, don't forget that scroll bars are not part of the
|
|
|
|
* edit control client area, and their sizes must be factored in.)
|
|
|
|
*/
|
|
|
|
CRect rect;
|
|
|
|
CRichEditCtrl* pEdit = (CRichEditCtrl*) GetDlgItem(IDC_FVIEW_EDITBOX);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEdit != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
//pEdit->GetClientRect(&rect);
|
|
|
|
pEdit->GetWindowRect(&rect);
|
|
|
|
//GetClientRect(&rect);
|
|
|
|
rect.left = 2;
|
|
|
|
rect.top = 2;
|
|
|
|
pEdit->SetRect(&rect);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::DoDataExchange(CDataExchange* pDX)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CDialog::DoDataExchange(pDX);
|
|
|
|
|
|
|
|
if (pDX->m_bSaveAndValidate) {
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("COPY OUT");
|
2014-11-04 00:26:53 +00:00
|
|
|
} else {
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("COPY IN");
|
2014-11-04 00:26:53 +00:00
|
|
|
OnFviewNext();
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
static void DumpBitmapInfo(HBITMAP hBitmap)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
BITMAP info;
|
|
|
|
CBitmap* pBitmap = CBitmap::FromHandle(hBitmap);
|
|
|
|
int gotten;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
gotten = pBitmap->GetObject(sizeof(info), &info);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("DumpBitmapInfo: gotten=%d of %d", gotten, sizeof(info));
|
|
|
|
LOGD(" bmType = %d", info.bmType);
|
|
|
|
LOGD(" bmWidth=%d, bmHeight=%d", info.bmWidth, info.bmHeight);
|
|
|
|
LOGD(" bmWidthBytes=%d", info.bmWidthBytes);
|
|
|
|
LOGD(" bmPlanes=%d", info.bmPlanes);
|
|
|
|
LOGD(" bmBitsPixel=%d", info.bmBitsPixel);
|
|
|
|
LOGD(" bmPits = 0x%p", info.bmBits);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 18:25:08 +00:00
|
|
|
bool ViewFilesDialog::IsSourceEmpty(const GenericEntry* pEntry,
|
|
|
|
ReformatHolder::ReformatPart part)
|
|
|
|
{
|
|
|
|
switch (part) {
|
|
|
|
case ReformatHolder::ReformatPart::kPartData:
|
|
|
|
return pEntry->GetDataForkLen() == 0;
|
|
|
|
case ReformatHolder::ReformatPart::kPartRsrc:
|
|
|
|
return pEntry->GetRsrcForkLen() == 0;
|
|
|
|
case ReformatHolder::ReformatPart::kPartCmmt:
|
|
|
|
return !pEntry->GetHasNonEmptyComment();
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewFilesDialog::DisplayText(const WCHAR* fileName, bool zeroSourceLen)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CWaitCursor wait; // streaming of big files can take a little while
|
|
|
|
bool errFlg;
|
|
|
|
bool emptyFlg = false;
|
|
|
|
bool editHadFocus = false;
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpOutput != NULL);
|
|
|
|
ASSERT(fileName != NULL);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
errFlg = fpOutput->GetOutputKind() == ReformatOutput::kOutputErrorMsg;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(fpOutput->GetOutputKind() != ReformatOutput::kOutputUnknown);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
CRichEditCtrl* pEdit = (CRichEditCtrl*) GetDlgItem(IDC_FVIEW_EDITBOX);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEdit != NULL);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* retain the selection even if we lose focus [can't do this in OnInit] */
|
|
|
|
pEdit->SetOptions(ECOOP_OR, ECO_SAVESEL);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
#if 0
|
2014-11-04 00:26:53 +00:00
|
|
|
/*
|
|
|
|
* Start by trashing anything that's there. Not strictly necessary,
|
|
|
|
* but it prevents the control from trying to maintain the old stuff
|
|
|
|
* in an undo buffer. (Not entirely sure if a stream-in operation is
|
|
|
|
* undoable, but it costs very little to be certain.)
|
|
|
|
*
|
|
|
|
* UPDATE: I turned this off because it was dinging the speaker (?!).
|
|
|
|
* Might be doing that because it's in read-only mode.
|
|
|
|
*/
|
|
|
|
pEdit->SetSel(0, -1);
|
|
|
|
pEdit->Clear();
|
|
|
|
pEdit->EmptyUndoBuffer();
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/*
|
|
|
|
* There's a redraw flash that goes away if you change the input
|
|
|
|
* focus to something other than the edit ctrl. (Move between large
|
|
|
|
* files; it looks like you can see the text being selected and
|
|
|
|
* hightlighted. The control doesn't have an "always highlight" flag
|
|
|
|
* set, so if the focus is on a different control it doesn't light up.)
|
|
|
|
*
|
|
|
|
* Since we're currently forcing the focus to be on the edit ctrl later
|
|
|
|
* on, we just jam it to something else here. If nothing has the focus,
|
|
|
|
* as can happen if we click on "resource fork" and then Alt-N to a
|
|
|
|
* file without a resource fork, we force the focus to return to the
|
|
|
|
* edit window.
|
|
|
|
*
|
|
|
|
* NOTE: this would look a little better if we used the Prev/Next
|
|
|
|
* buttons to hold the temporary focus, but we need to know which key
|
|
|
|
* 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".
|
2015-01-16 23:15:40 +00:00
|
|
|
*
|
|
|
|
* TODO: on Win7 you can sometimes see a blue flash. Not sure if it
|
|
|
|
* relates to this or some other aspect of the redraw.
|
2014-11-04 00:26:53 +00:00
|
|
|
*/
|
|
|
|
CWnd* pFocusWnd = GetFocus();
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pFocusWnd == NULL || pFocusWnd->m_hWnd == pEdit->m_hWnd) {
|
2014-11-04 00:26:53 +00:00
|
|
|
editHadFocus = true;
|
|
|
|
GetDlgItem(IDOK)->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The text color isn't getting reset when we reload the control. I
|
|
|
|
* can't find a "set default text color" call, so I'm reformatting
|
|
|
|
* part of the buffer.
|
|
|
|
*
|
|
|
|
* Here's the weird part: it doesn't seem to matter what color I
|
|
|
|
* set it to under Win2K. It reverts to black so long as I do anything
|
|
|
|
* here. Under Win98, it uses the new color.
|
|
|
|
*/
|
|
|
|
//if (0)
|
|
|
|
{
|
|
|
|
CHARFORMAT cf;
|
|
|
|
cf.cbSize = sizeof(CHARFORMAT);
|
|
|
|
cf.dwMask = CFM_COLOR;
|
|
|
|
cf.crTextColor = RGB(0, 0, 0);
|
|
|
|
pEdit->SetSel(0, 1); // must select at least one char
|
|
|
|
pEdit->SetSelectionCharFormat(cf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the appropriate data. If the "bitmap" flag is set, use the
|
|
|
|
* MyDIBitmap pointer instead.
|
|
|
|
*/
|
|
|
|
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputBitmap) {
|
|
|
|
CClientDC dcScreen(this);
|
|
|
|
HBITMAP hBitmap;
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
if (fpRichEditOle == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
/* can't do this in OnInitDialog -- m_pWnd isn't initialized */
|
|
|
|
fpRichEditOle = pEdit->GetIRichEditOle();
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpRichEditOle != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//FILE* fp = fopen("C:/test/output.bmp", "wb");
|
2014-11-18 05:13:13 +00:00
|
|
|
//if (fp != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
// pDib->WriteToFile(fp);
|
|
|
|
// fclose(fp);
|
|
|
|
//}
|
|
|
|
|
|
|
|
hBitmap = fpOutput->GetDIB()->ConvertToDDB(dcScreen.m_hDC);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hBitmap == NULL) {
|
2015-01-16 23:15:40 +00:00
|
|
|
LOGW("ConvertToDDB failed!");
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
pEdit->SetWindowText(L"Internal error.");
|
2014-11-04 00:26:53 +00:00
|
|
|
errFlg = true;
|
|
|
|
} else {
|
|
|
|
//DumpBitmapInfo(hBitmap);
|
|
|
|
//DumpBitmapInfo(pDib->GetHandle());
|
|
|
|
|
2015-01-16 23:15:40 +00:00
|
|
|
LOGD("Inserting bitmap");
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
pEdit->SetWindowText(L"");
|
2014-11-04 00:26:53 +00:00
|
|
|
CImageDataObject::InsertBitmap(fpRichEditOle, hBitmap);
|
|
|
|
|
|
|
|
/* RichEditCtrl has it now */
|
|
|
|
::DeleteObject(hBitmap);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Stream the data in, using the appropriate format. Since we don't
|
|
|
|
* have the "replace selection" flag set, this replaces everything
|
|
|
|
* that's currently in there.
|
|
|
|
*
|
|
|
|
* We can't use SetWindowText() unless we're willing to forgo viewing
|
|
|
|
* of binary files in "raw" form. There doesn't seem to be any other
|
|
|
|
* difference between the two approaches.
|
|
|
|
*/
|
|
|
|
const char* textBuf;
|
|
|
|
long textLen;
|
|
|
|
int streamFormat;
|
|
|
|
|
|
|
|
textBuf = fpOutput->GetTextBuf();
|
|
|
|
textLen = fpOutput->GetTextLen();
|
|
|
|
streamFormat = SF_TEXT;
|
|
|
|
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputRTF)
|
|
|
|
streamFormat = SF_RTF;
|
|
|
|
if (fpOutput->GetTextLen() == 0) {
|
2017-09-22 18:25:08 +00:00
|
|
|
if (zeroSourceLen) {
|
|
|
|
textBuf = "(file is empty)";
|
|
|
|
EnableFormatSelection(FALSE);
|
|
|
|
} else {
|
|
|
|
textBuf = "(converted output is empty)";
|
|
|
|
}
|
2014-11-04 00:26:53 +00:00
|
|
|
textLen = strlen(textBuf);
|
|
|
|
emptyFlg = true;
|
|
|
|
}
|
|
|
|
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputErrorMsg)
|
|
|
|
EnableFormatSelection(FALSE);
|
|
|
|
|
|
|
|
/* make sure the control will hold everything we throw at it */
|
|
|
|
pEdit->LimitText(textLen+1);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Streaming %ld bytes (kind=%d)",
|
2014-11-04 00:26:53 +00:00
|
|
|
textLen, fpOutput->GetOutputKind());
|
|
|
|
|
|
|
|
/* clear this early to avoid loading onto yellow */
|
|
|
|
if (errFlg)
|
|
|
|
pEdit->SetBackgroundColor(FALSE, RGB(255, 255, 0));
|
|
|
|
else if (emptyFlg)
|
|
|
|
pEdit->SetBackgroundColor(FALSE, RGB(192, 192, 192));
|
|
|
|
else
|
|
|
|
pEdit->SetBackgroundColor(TRUE, 0);
|
|
|
|
|
|
|
|
RichEditXfer xfer(textBuf, textLen);
|
|
|
|
EDITSTREAM es;
|
|
|
|
es.dwCookie = (DWORD) &xfer;
|
|
|
|
es.dwError = 0;
|
|
|
|
es.pfnCallback = RichEditXfer::EditStreamCallback;
|
|
|
|
long count;
|
|
|
|
count = pEdit->StreamIn(streamFormat, es);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("StreamIn returned count=%ld dwError=%d", count, es.dwError);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
if (es.dwError != 0) {
|
|
|
|
/* a -16 error can happen if the type is RTF but contents are not */
|
|
|
|
char errorText[256];
|
|
|
|
|
2015-01-16 23:15:40 +00:00
|
|
|
_snprintf(errorText, sizeof(errorText),
|
2014-11-04 00:26:53 +00:00
|
|
|
"ERROR: failed while loading data (err=0x%08lx)\n"
|
|
|
|
"(File contents might be too big for Windows to display)\n",
|
|
|
|
es.dwError);
|
|
|
|
RichEditXfer errXfer(errorText, strlen(errorText));
|
|
|
|
es.dwCookie = (DWORD) &errXfer;
|
|
|
|
es.dwError = 0;
|
|
|
|
|
|
|
|
count = pEdit->StreamIn(SF_TEXT, es);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Error StreamIn returned count=%ld dwError=%d", count, es.dwError);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
errFlg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//pEdit->SetSel(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move us back to the top */
|
|
|
|
pEdit->LineScroll(-pEdit->GetFirstVisibleLine());
|
|
|
|
|
|
|
|
/* just in case it's trying to hold on to something */
|
|
|
|
pEdit->EmptyUndoBuffer();
|
|
|
|
|
|
|
|
/* work around bug that creates unnecessary scroll bars */
|
|
|
|
pEdit->SetScrollRange(SB_VERT, 0, 0, TRUE);
|
|
|
|
pEdit->SetScrollRange(SB_HORZ, 0, 0, TRUE);
|
|
|
|
|
|
|
|
/* display the entire message in the user's selected font */
|
|
|
|
if (!fpOutput->GetMultipleFontsFlag()) {
|
|
|
|
// adjust the font, stripping default boldness from SF_TEXT
|
|
|
|
NewFontSelected(fpOutput->GetOutputKind() != ReformatOutput::kOutputRTF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable/disable the scroll bars */
|
|
|
|
//pEdit->EnableScrollBar(SB_BOTH, ESB_DISABLE_BOTH);
|
|
|
|
|
|
|
|
if (errFlg)
|
|
|
|
pEdit->SetBackgroundColor(FALSE, RGB(255, 255, 0));
|
|
|
|
else if (emptyFlg)
|
|
|
|
pEdit->SetBackgroundColor(FALSE, RGB(192, 192, 192));
|
|
|
|
else
|
|
|
|
pEdit->SetBackgroundColor(TRUE, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Work around a Windows bug that prevents the scroll bars from
|
|
|
|
* being displayed immediately. This makes them appear, but the
|
|
|
|
* vertical scroll bar comes out funky on short files (fixed with
|
|
|
|
* the SetScrollRange call above).
|
|
|
|
*
|
|
|
|
* Best guess: when the edit box is resized, it chooses the scroll bar
|
|
|
|
* configuration based on the currently-loaded data. If you resize it
|
|
|
|
* and *then* add data, you're stuck with the previous scroll bar
|
|
|
|
* values. This doesn't quite make sense though...
|
|
|
|
*
|
|
|
|
* This works:
|
|
|
|
* - Set up dialog.
|
|
|
|
* - Load data.
|
|
|
|
* - Do minor twiddling.
|
|
|
|
* - Resize box significantly.
|
|
|
|
*
|
|
|
|
* This works:
|
|
|
|
* - (box already has data in it)
|
|
|
|
* - Load new data.
|
|
|
|
* - Do minor twiddling.
|
|
|
|
*
|
|
|
|
* This doesn't:
|
|
|
|
* - Set up dialog
|
|
|
|
* - Resize box significantly.
|
|
|
|
* - Load data.
|
|
|
|
* - Do minor twiddling.
|
|
|
|
*
|
|
|
|
* There might be some first-time setup issues in here. Hard to say.
|
|
|
|
* 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).
|
2015-01-16 23:15:40 +00:00
|
|
|
*
|
|
|
|
* TODO: re-evaluate all this without worrying about Win9x
|
2014-11-04 00:26:53 +00:00
|
|
|
*/
|
|
|
|
if (fFirstResize) {
|
|
|
|
/* adjust the size of the window to match the last size used */
|
|
|
|
const Preferences* pPreferences = GET_PREFERENCES();
|
|
|
|
long width = pPreferences->GetPrefLong(kPrFileViewerWidth);
|
|
|
|
long height = pPreferences->GetPrefLong(kPrFileViewerHeight);
|
|
|
|
CRect fullRect;
|
|
|
|
GetWindowRect(&fullRect);
|
2014-11-18 21:05:15 +00:00
|
|
|
//LOGI(" VFD pre-size %dx%d", fullRect.Width(), fullRect.Height());
|
2014-11-04 00:26:53 +00:00
|
|
|
fullRect.right = fullRect.left + width;
|
|
|
|
fullRect.bottom = fullRect.top + height;
|
|
|
|
MoveWindow(fullRect, TRUE);
|
|
|
|
|
|
|
|
editHadFocus = true; // force focus on edit box
|
|
|
|
|
|
|
|
fFirstResize = false;
|
|
|
|
} else {
|
|
|
|
/* this should be enough */
|
|
|
|
ShiftControls(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputBitmap) {
|
|
|
|
/* get the cursor off of the image */
|
|
|
|
pEdit->SetSel(-1, -1);
|
2015-01-16 23:15:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want the focus to be on the text window so keyboard selection
|
|
|
|
* commands work. However, it's also nice to be able to arrow through
|
|
|
|
* the format selection box.
|
|
|
|
*/
|
|
|
|
if (editHadFocus)
|
|
|
|
pEdit->SetFocus();
|
|
|
|
|
|
|
|
fTitle = fileName;
|
|
|
|
//if (fpOutput->GetOutputKind() == ReformatOutput::kOutputText ||
|
|
|
|
// fpOutput->GetOutputKind() == ReformatOutput::kOutputRTF ||
|
|
|
|
// fpOutput->GetOutputKind() == ReformatOutput::kOutputCSV ||
|
|
|
|
// fpOutput->GetOutputKind() == ReformatOutput::kOutputBitmap ||
|
|
|
|
// fpOutput->GetOutputKind() == ReformatOutput::kOutputRaw)
|
|
|
|
//{
|
|
|
|
// not for error messages
|
|
|
|
fTitle += _T(" [");
|
|
|
|
fTitle += fpOutput->GetFormatDescr();
|
|
|
|
fTitle += _T("]");
|
|
|
|
//} else if (fpOutput->GetOutputKind() == ReformatOutput::kOutputRaw) {
|
|
|
|
// fTitle += _T(" [Raw]");
|
|
|
|
//}
|
|
|
|
|
|
|
|
CString winTitle = _T("File Viewer - ");
|
|
|
|
winTitle += fTitle;
|
|
|
|
SetWindowText(winTitle);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable or disable the next/prev buttons.
|
|
|
|
*/
|
|
|
|
CButton* pButton;
|
|
|
|
pButton = (CButton*) GetDlgItem(IDC_FVIEW_PREV);
|
|
|
|
pButton->EnableWindow(fpSelSet->IterHasPrev());
|
|
|
|
pButton = (CButton*) GetDlgItem(IDC_FVIEW_NEXT);
|
|
|
|
pButton->EnableWindow(fpSelSet->IterHasNext());
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewNext(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
// handles "next" button; also called from DoDataExchange
|
2014-11-04 00:26:53 +00:00
|
|
|
ReformatHolder::ReformatPart part;
|
|
|
|
ReformatHolder::ReformatID id;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (fBusy) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("BUSY!");
|
2014-11-04 00:26:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fBusy = true;
|
|
|
|
|
|
|
|
if (!fpSelSet->IterHasNext()) {
|
|
|
|
ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the pieces of the file.
|
|
|
|
*/
|
|
|
|
SelectionEntry* pSelEntry = fpSelSet->IterNext();
|
|
|
|
GenericEntry* pEntry = pSelEntry->GetEntry();
|
|
|
|
result = ReformatPrep(pEntry);
|
2007-03-27 17:47:10 +00:00
|
|
|
#if 0
|
2014-11-04 00:26:53 +00:00
|
|
|
{
|
|
|
|
// for debugging -- simulate failure
|
|
|
|
result = -1;
|
|
|
|
delete fpHolder;
|
2014-11-18 05:13:13 +00:00
|
|
|
fpHolder = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
delete fpOutput;
|
2014-11-18 05:13:13 +00:00
|
|
|
fpOutput = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
fBusy = false;
|
|
|
|
if (result != 0) {
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpHolder == NULL);
|
|
|
|
ASSERT(fpOutput == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format a piece.
|
|
|
|
*/
|
|
|
|
ConfigurePartButtons(pSelEntry->GetEntry());
|
|
|
|
part = GetSelectedPart();
|
|
|
|
id = ConfigureFormatSel(part);
|
|
|
|
Reformat(pSelEntry->GetEntry(), part, id);
|
|
|
|
|
2017-09-22 18:25:08 +00:00
|
|
|
DisplayText(pSelEntry->GetEntry()->GetDisplayName(),
|
|
|
|
IsSourceEmpty(pSelEntry->GetEntry(), part));
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewPrev(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
ReformatHolder::ReformatPart part;
|
|
|
|
ReformatHolder::ReformatID id;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (fBusy) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("BUSY!");
|
2014-11-04 00:26:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fBusy = true;
|
|
|
|
|
|
|
|
if (!fpSelSet->IterHasPrev()) {
|
|
|
|
ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the pieces of the file.
|
|
|
|
*/
|
|
|
|
SelectionEntry* pSelEntry = fpSelSet->IterPrev();
|
|
|
|
GenericEntry* pEntry = pSelEntry->GetEntry();
|
|
|
|
result = ReformatPrep(pEntry);
|
|
|
|
|
|
|
|
fBusy = false;
|
|
|
|
if (result != 0) {
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpHolder == NULL);
|
|
|
|
ASSERT(fpOutput == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format a piece.
|
|
|
|
*/
|
|
|
|
ConfigurePartButtons(pEntry);
|
|
|
|
part = GetSelectedPart();
|
|
|
|
id = ConfigureFormatSel(part);
|
|
|
|
Reformat(pEntry, part, id);
|
|
|
|
|
2017-09-22 18:25:08 +00:00
|
|
|
DisplayText(pEntry->GetDisplayName(), IsSourceEmpty(pEntry, part));
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::ConfigurePartButtons(const GenericEntry* pEntry)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
CButton* pDataWnd = (CButton*) GetDlgItem(IDC_FVIEW_DATA);
|
|
|
|
CButton* pRsrcWnd = (CButton*) GetDlgItem(IDC_FVIEW_RSRC);
|
|
|
|
CButton* pCmmtWnd = (CButton*) GetDlgItem(IDC_FVIEW_CMMT);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pDataWnd != NULL && pRsrcWnd != NULL && pCmmtWnd != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/* figure out what was checked before, ignoring if it's not available */
|
|
|
|
if (pDataWnd->GetCheck() == BST_CHECKED && pEntry->GetHasDataFork())
|
|
|
|
id = IDC_FVIEW_DATA;
|
|
|
|
else if (pRsrcWnd->GetCheck() == BST_CHECKED && pEntry->GetHasRsrcFork())
|
|
|
|
id = IDC_FVIEW_RSRC;
|
|
|
|
else if (pCmmtWnd->GetCheck() == BST_CHECKED && pEntry->GetHasComment())
|
|
|
|
id = IDC_FVIEW_CMMT;
|
|
|
|
|
|
|
|
/* couldn't keep previous check, find a new one */
|
|
|
|
if (id == 0) {
|
|
|
|
if (pEntry->GetHasDataFork())
|
|
|
|
id = IDC_FVIEW_DATA;
|
|
|
|
else if (pEntry->GetHasRsrcFork())
|
|
|
|
id = IDC_FVIEW_RSRC;
|
|
|
|
else if (pEntry->GetHasComment())
|
|
|
|
id = IDC_FVIEW_CMMT;
|
|
|
|
// else leave it set to 0
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set up the dialog */
|
|
|
|
pDataWnd->SetCheck(BST_UNCHECKED);
|
|
|
|
pRsrcWnd->SetCheck(BST_UNCHECKED);
|
|
|
|
pCmmtWnd->SetCheck(BST_UNCHECKED);
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pEntry == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
pDataWnd->EnableWindow(FALSE);
|
|
|
|
pRsrcWnd->EnableWindow(FALSE);
|
|
|
|
pCmmtWnd->EnableWindow(FALSE);
|
|
|
|
} else {
|
|
|
|
pDataWnd->EnableWindow(pEntry->GetHasDataFork());
|
|
|
|
pRsrcWnd->EnableWindow(pEntry->GetHasRsrcFork());
|
|
|
|
pCmmtWnd->EnableWindow(pEntry->GetHasComment());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == IDC_FVIEW_RSRC)
|
|
|
|
pRsrcWnd->SetCheck(BST_CHECKED);
|
|
|
|
else if (id == IDC_FVIEW_CMMT)
|
|
|
|
pCmmtWnd->SetCheck(BST_CHECKED);
|
|
|
|
else
|
|
|
|
pDataWnd->SetCheck(BST_CHECKED);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
ReformatHolder::ReformatPart ViewFilesDialog::GetSelectedPart(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CButton* pDataWnd = (CButton*) GetDlgItem(IDC_FVIEW_DATA);
|
|
|
|
CButton* pRsrcWnd = (CButton*) GetDlgItem(IDC_FVIEW_RSRC);
|
|
|
|
CButton* pCmmtWnd = (CButton*) GetDlgItem(IDC_FVIEW_CMMT);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pDataWnd != NULL && pRsrcWnd != NULL && pCmmtWnd != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
if (pDataWnd->GetCheck() == BST_CHECKED)
|
|
|
|
return ReformatHolder::kPartData;
|
|
|
|
else if (pRsrcWnd->GetCheck() == BST_CHECKED)
|
|
|
|
return ReformatHolder::kPartRsrc;
|
|
|
|
else if (pCmmtWnd->GetCheck() == BST_CHECKED)
|
|
|
|
return ReformatHolder::kPartCmmt;
|
|
|
|
else {
|
|
|
|
assert(false);
|
|
|
|
return ReformatHolder::kPartData;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
int ViewFilesDialog::ReformatPrep(GenericEntry* pEntry)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CWaitCursor waitc; // can be slow reading data from floppy
|
|
|
|
MainWindow* pMainWindow = GET_MAIN_WINDOW();
|
|
|
|
int result;
|
|
|
|
|
|
|
|
delete fpHolder;
|
2014-11-18 05:13:13 +00:00
|
|
|
fpHolder = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
result = pMainWindow->GetFileParts(pEntry, &fpHolder);
|
|
|
|
if (result != 0) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("GetFileParts(prev) failed!");
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpHolder == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set up the ReformatHolder */
|
|
|
|
MainWindow::ConfigureReformatFromPreferences(fpHolder);
|
|
|
|
|
|
|
|
/* prep for applicability test */
|
|
|
|
fpHolder->SetSourceAttributes(
|
|
|
|
pEntry->GetFileType(),
|
|
|
|
pEntry->GetAuxType(),
|
|
|
|
MainWindow::ReformatterSourceFormat(pEntry->GetSourceFS()),
|
2015-01-09 01:41:53 +00:00
|
|
|
pEntry->GetFileNameExtensionMOR());
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/* figure out which reformatters apply to this file */
|
2015-01-09 01:41:53 +00:00
|
|
|
LOGD("Testing reformatters");
|
2014-11-04 00:26:53 +00:00
|
|
|
fpHolder->TestApplicability();
|
|
|
|
|
|
|
|
return 0;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
int ViewFilesDialog::Reformat(const GenericEntry* pEntry,
|
2014-11-04 00:26:53 +00:00
|
|
|
ReformatHolder::ReformatPart part, ReformatHolder::ReformatID id)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CWaitCursor waitc;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
delete fpOutput;
|
2014-11-18 05:13:13 +00:00
|
|
|
fpOutput = NULL;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* run the best one */
|
|
|
|
fpOutput = fpHolder->Apply(part, id);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
//bail:
|
2014-11-18 05:13:13 +00:00
|
|
|
if (fpOutput != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
// success -- do some sanity checks
|
|
|
|
switch (fpOutput->GetOutputKind()) {
|
|
|
|
case ReformatOutput::kOutputText:
|
|
|
|
case ReformatOutput::kOutputRTF:
|
|
|
|
case ReformatOutput::kOutputCSV:
|
|
|
|
case ReformatOutput::kOutputErrorMsg:
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpOutput->GetTextBuf() != NULL);
|
|
|
|
ASSERT(fpOutput->GetDIB() == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
break;
|
|
|
|
case ReformatOutput::kOutputBitmap:
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpOutput->GetDIB() != NULL);
|
|
|
|
ASSERT(fpOutput->GetTextBuf() == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
break;
|
|
|
|
case ReformatOutput::kOutputRaw:
|
2014-11-18 05:13:13 +00:00
|
|
|
// text buf might be NULL
|
|
|
|
ASSERT(fpOutput->GetDIB() == NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/* shouldn't get here; handle it if we do */
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
static const char* kFailMsg = "Internal error\r\n";
|
2014-11-04 00:26:53 +00:00
|
|
|
fpOutput = new ReformatOutput;
|
|
|
|
fpOutput->SetTextBuf((char*) kFailMsg, strlen(kFailMsg), false);
|
|
|
|
fpOutput->SetOutputKind(ReformatOutput::kOutputErrorMsg);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
ReformatHolder::ReformatID ViewFilesDialog::ConfigureFormatSel(
|
|
|
|
ReformatHolder::ReformatPart part)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
//ReformatHolder::ReformatID prevID = ReformatHolder::kReformatUnknown;
|
|
|
|
ReformatHolder::ReformatID returnID = ReformatHolder::kReformatRaw;
|
|
|
|
CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_FVIEW_FORMATSEL);
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("--- ConfigureFormatSel");
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
//int sel;
|
|
|
|
//sel = pCombo->GetCurSel();
|
|
|
|
//if (sel != CB_ERR)
|
|
|
|
// prevID = (ReformatHolder::ReformatID) pCombo->GetItemData(sel);
|
2014-11-18 21:05:15 +00:00
|
|
|
//LOGI(" prevID = %d", prevID);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
EnableFormatSelection(TRUE);
|
|
|
|
pCombo->ResetContent();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill out the combo box with the reformatter entries.
|
|
|
|
*
|
|
|
|
* There's probably a way to do this that doesn't involve abusing
|
|
|
|
* enums, but this'll do for now.
|
|
|
|
*/
|
|
|
|
int applyIdx, idIdx;
|
|
|
|
bool preferred = true;
|
|
|
|
int comboIdx;
|
|
|
|
for (applyIdx = ReformatHolder::kApplicMAX;
|
|
|
|
applyIdx > ReformatHolder::kApplicNot; /*no incr*/)
|
|
|
|
{
|
|
|
|
if (applyIdx == ReformatHolder::kApplicMAX)
|
|
|
|
goto skip;
|
|
|
|
if (applyIdx == ReformatHolder::kApplicUnknown)
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
int testApplies;
|
|
|
|
|
|
|
|
testApplies = applyIdx;
|
|
|
|
if (preferred)
|
|
|
|
testApplies |= ReformatHolder::kApplicPreferred;
|
|
|
|
|
|
|
|
for (idIdx = 0; idIdx < ReformatHolder::kReformatMAX; idIdx++) {
|
|
|
|
if (idIdx == ReformatHolder::kReformatUnknown)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ReformatHolder::ReformatApplies applies;
|
|
|
|
|
|
|
|
applies = fpHolder->GetApplic(part,
|
|
|
|
(ReformatHolder::ReformatID) idIdx);
|
|
|
|
if ((int) applies == testApplies) {
|
|
|
|
/* match! */
|
|
|
|
CString str;
|
2014-11-18 21:05:15 +00:00
|
|
|
//LOGI("MATCH at %d (0x%02x)", idIdx, testApplies);
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
str.Format(L"%ls", ReformatHolder::GetReformatName(
|
|
|
|
(ReformatHolder::ReformatID) idIdx));
|
2014-11-04 00:26:53 +00:00
|
|
|
comboIdx = pCombo->AddString(str);
|
|
|
|
pCombo->SetItemData(comboIdx, idIdx);
|
|
|
|
|
|
|
|
/* define initial selection as best item */
|
|
|
|
if (comboIdx == 0)
|
|
|
|
pCombo->SetCurSel(comboIdx);
|
|
|
|
|
|
|
|
//if (idIdx == (int) prevID &&
|
|
|
|
// applyIdx == ReformatHolder::kApplicAlways)
|
|
|
|
//{
|
2014-11-18 21:05:15 +00:00
|
|
|
// LOGI(" Found 'always' prevID, selecting");
|
2014-11-04 00:26:53 +00:00
|
|
|
// pCombo->SetCurSel(comboIdx);
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
skip:
|
2014-11-04 00:26:53 +00:00
|
|
|
if (!preferred)
|
|
|
|
applyIdx--;
|
|
|
|
preferred = !preferred;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return whatever we now have selected */
|
|
|
|
int sel = pCombo->GetCurSel();
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD(" At end, sel is %d", sel);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (sel != CB_ERR)
|
|
|
|
returnID = (ReformatHolder::ReformatID) pCombo->GetItemData(sel);
|
|
|
|
|
|
|
|
return returnID;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFormatSelChange(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* The user has changed entries in the format selection drop box.
|
|
|
|
*
|
|
|
|
* Also called from the "quick change" buttons.
|
|
|
|
*/
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_FVIEW_FORMATSEL);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pCombo != NULL);
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD("+++ SELECTION IS NOW %d", pCombo->GetCurSel());
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
SelectionEntry* pSelEntry = fpSelSet->IterCurrent();
|
|
|
|
GenericEntry* pEntry = pSelEntry->GetEntry();
|
|
|
|
ReformatHolder::ReformatPart part;
|
|
|
|
ReformatHolder::ReformatID id;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
part = GetSelectedPart();
|
|
|
|
id = (ReformatHolder::ReformatID) pCombo->GetItemData(pCombo->GetCurSel());
|
|
|
|
Reformat(pEntry, part, id);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2017-09-22 18:25:08 +00:00
|
|
|
DisplayText(pEntry->GetDisplayName(), IsSourceEmpty(pEntry, part));
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewData(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
ForkSelectCommon(ReformatHolder::kPartData);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
void ViewFilesDialog::OnFviewRsrc(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
ForkSelectCommon(ReformatHolder::kPartRsrc);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
void ViewFilesDialog::OnFviewCmmt(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
ForkSelectCommon(ReformatHolder::kPartCmmt);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
2014-11-21 21:18:20 +00:00
|
|
|
|
|
|
|
void ViewFilesDialog::ForkSelectCommon(ReformatHolder::ReformatPart part)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
GenericEntry* pEntry;
|
|
|
|
ReformatHolder::ReformatID id;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Switching to file part=%d", part);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(fpHolder != NULL);
|
|
|
|
ASSERT(fpSelSet != NULL);
|
|
|
|
ASSERT(fpSelSet->IterCurrent() != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
pEntry = fpSelSet->IterCurrent()->GetEntry();
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEntry != NULL);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
id = ConfigureFormatSel(part);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
Reformat(pEntry, part, id);
|
2017-09-22 18:25:08 +00:00
|
|
|
DisplayText(pEntry->GetDisplayName(), IsSourceEmpty(pEntry, part));
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewFmtBest(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_FVIEW_FORMATSEL);
|
|
|
|
pCombo->SetCurSel(0); // best is always at the top
|
|
|
|
OnFormatSelChange();
|
|
|
|
pCombo->SetFocus();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewFmtHex(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_FVIEW_FORMATSEL);
|
|
|
|
int sel = FindByVal(pCombo, ReformatHolder::kReformatHexDump);
|
|
|
|
if (sel < 0)
|
|
|
|
sel = 0;
|
|
|
|
pCombo->SetCurSel(sel);
|
|
|
|
OnFormatSelChange();
|
|
|
|
pCombo->SetFocus();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewFmtRaw(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_FVIEW_FORMATSEL);
|
|
|
|
int sel = FindByVal(pCombo, ReformatHolder::kReformatRaw);
|
|
|
|
if (sel < 0)
|
|
|
|
sel = 0;
|
|
|
|
pCombo->SetCurSel(sel);
|
|
|
|
OnFormatSelChange();
|
|
|
|
pCombo->SetFocus();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::EnableFormatSelection(BOOL enable)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
GetDlgItem(IDC_FVIEW_FORMATSEL)->EnableWindow(enable);
|
|
|
|
GetDlgItem(IDC_FVIEW_FMT_BEST)->EnableWindow(enable);
|
|
|
|
GetDlgItem(IDC_FVIEW_FMT_HEX)->EnableWindow(enable);
|
|
|
|
GetDlgItem(IDC_FVIEW_FMT_RAW)->EnableWindow(enable);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
int ViewFilesDialog::FindByVal(CComboBox* pCombo, DWORD val)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
int count = pCombo->GetCount();
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (pCombo->GetItemData(i) == val)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewFont(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
// Choose a font, then apply the choice to all of the text in the box.
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
LOGFONT logFont;
|
|
|
|
CFont font;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/*
|
|
|
|
* Create a LOGFONT structure with the desired default characteristics,
|
|
|
|
* then use that to initialize the font dialog.
|
|
|
|
*/
|
|
|
|
CreateSimpleFont(&font, this, fTypeFace, fPointSize);
|
|
|
|
font.GetLogFont(&logFont);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
CFontDialog fontDlg(&logFont);
|
|
|
|
fontDlg.m_cf.Flags &= ~(CF_EFFECTS);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (fontDlg.DoModal() == IDOK) {
|
|
|
|
//fontDlg.GetCurrentFont(&logFont);
|
|
|
|
fTypeFace = fontDlg.GetFaceName();
|
|
|
|
fPointSize = fontDlg.GetSize() / 10;
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Now using %d-point '%ls'", fPointSize, (LPCWSTR) fTypeFace);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
NewFontSelected(false);
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::NewFontSelected(bool resetBold)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CRichEditCtrl* pEdit = (CRichEditCtrl*) GetDlgItem(IDC_FVIEW_EDITBOX);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEdit != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
CHARFORMAT cf;
|
|
|
|
cf.cbSize = sizeof(CHARFORMAT);
|
|
|
|
cf.dwMask = CFM_FACE | CFM_SIZE;
|
|
|
|
if (resetBold) {
|
|
|
|
cf.dwMask |= CFM_BOLD;
|
|
|
|
cf.dwEffects = 0;
|
|
|
|
}
|
|
|
|
::lstrcpy(cf.szFaceName, fTypeFace);
|
|
|
|
cf.yHeight = fPointSize * 20; // in twips
|
|
|
|
pEdit->SetSel(0, -1); // select all
|
|
|
|
pEdit->SetSelectionCharFormat(cf);
|
|
|
|
pEdit->SetSel(0, 0); // unselect
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewPrint(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
MainWindow* pMainWindow = GET_MAIN_WINDOW();
|
|
|
|
CPrintDialog dlg(FALSE); // use CPrintDialogEx for Win2K? CPageSetUpDialog?
|
|
|
|
PrintRichEdit pre;
|
|
|
|
CDC dc;
|
|
|
|
int numPages;
|
|
|
|
|
|
|
|
dlg.m_pd.nFromPage = dlg.m_pd.nMinPage = 1;
|
|
|
|
dlg.m_pd.nToPage = dlg.m_pd.nMaxPage = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Getting the expected number of pages requires a print test-run.
|
|
|
|
* However, if we use GetDefaults to get the DC, the call to DoModal
|
|
|
|
* returns immediately with IDCANCEL. So, we do our pre-flighting
|
|
|
|
* in a separate DC with a separate print dialog object.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
CPrintDialog countDlg(FALSE);
|
|
|
|
CDC countDC;
|
|
|
|
|
|
|
|
dlg.m_pd.hDevMode = pMainWindow->fhDevMode;
|
|
|
|
dlg.m_pd.hDevNames = pMainWindow->fhDevNames;
|
|
|
|
|
|
|
|
if (countDlg.GetDefaults() == TRUE) {
|
|
|
|
CWaitCursor waitc;
|
|
|
|
|
|
|
|
if (countDC.Attach(countDlg.GetPrinterDC()) != TRUE) {
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
pre.Setup(&countDC, this);
|
|
|
|
pre.PrintPreflight(&fEditCtrl, &numPages);
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Default printer generated %d pages", numPages);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
dlg.m_pd.nToPage = dlg.m_pd.nMaxPage = numPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
pMainWindow->fhDevMode = dlg.m_pd.hDevMode;
|
|
|
|
pMainWindow->fhDevNames = dlg.m_pd.hDevNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
long startChar, endChar;
|
|
|
|
fEditCtrl.GetSel(/*ref*/startChar, /*ref*/endChar);
|
|
|
|
|
|
|
|
if (endChar != startChar) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("GetSel returned start=%ld end=%ld", startChar, endChar);
|
2014-11-04 00:26:53 +00:00
|
|
|
dlg.m_pd.Flags &= ~(PD_NOSELECTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg.m_pd.hDevMode = pMainWindow->fhDevMode;
|
|
|
|
dlg.m_pd.hDevNames = pMainWindow->fhDevNames;
|
|
|
|
dlg.m_pd.Flags |= PD_USEDEVMODECOPIESANDCOLLATE;
|
|
|
|
dlg.m_pd.Flags &= ~(PD_NOPAGENUMS);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show them the print dialog.
|
|
|
|
*/
|
|
|
|
if (dlg.DoModal() != IDOK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab the chosen printer and prep ourselves.
|
|
|
|
*/
|
|
|
|
if (dc.Attach(dlg.GetPrinterDC()) != TRUE) {
|
|
|
|
CString msg;
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&msg, IDS_PRINTER_NOT_USABLE);
|
2014-11-04 00:26:53 +00:00
|
|
|
ShowFailureMsg(this, msg, IDS_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pre.Setup(&dc, this);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the printing.
|
|
|
|
*/
|
|
|
|
if (dlg.PrintRange())
|
|
|
|
pre.PrintPages(&fEditCtrl, fTitle, dlg.GetFromPage(), dlg.GetToPage());
|
|
|
|
else if (dlg.PrintSelection())
|
|
|
|
pre.PrintSelection(&fEditCtrl, fTitle, startChar, endChar);
|
|
|
|
else // dlg.PrintAll()
|
|
|
|
pre.PrintAll(&fEditCtrl, fTitle);
|
|
|
|
|
|
|
|
pMainWindow->fhDevMode = dlg.m_pd.hDevMode;
|
|
|
|
pMainWindow->fhDevNames = dlg.m_pd.hDevNames;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::OnFviewFind(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
// User hit the "Find..." button. Open the modeless Find dialog.
|
2014-11-04 00:26:53 +00:00
|
|
|
DWORD flags = 0;
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
if (fpFindDialog != NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (fFindDown)
|
|
|
|
flags |= FR_DOWN;
|
|
|
|
if (fFindMatchCase)
|
|
|
|
flags |= FR_MATCHCASE;
|
|
|
|
if (fFindMatchWholeWord)
|
|
|
|
flags |= FR_WHOLEWORD;
|
|
|
|
|
|
|
|
fpFindDialog = new CFindReplaceDialog;
|
|
|
|
fpFindDialog->Create(TRUE, // "find" only
|
|
|
|
fFindLastStr, // default string to search for
|
|
|
|
NULL, // default string to replace
|
|
|
|
flags, // flags
|
|
|
|
this); // parent
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
LRESULT ViewFilesDialog::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* Handle activity in the modeless "find" dialog.
|
|
|
|
*/
|
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
assert(fpFindDialog != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
fFindDown = (fpFindDialog->SearchDown() != 0);
|
|
|
|
fFindMatchCase = (fpFindDialog->MatchCase() != 0);
|
|
|
|
fFindMatchWholeWord = (fpFindDialog->MatchWholeWord() != 0);
|
|
|
|
|
|
|
|
if (fpFindDialog->IsTerminating()) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("VFD find dialog closing");
|
2014-11-18 05:13:13 +00:00
|
|
|
fpFindDialog = NULL;
|
2014-11-04 00:26:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fpFindDialog->FindNext()) {
|
|
|
|
fFindLastStr = fpFindDialog->GetFindString();
|
|
|
|
FindNext(fFindLastStr, fFindDown, fFindMatchCase, fFindMatchWholeWord);
|
|
|
|
} else {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Unexpected find dialog activity");
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void ViewFilesDialog::FindNext(const WCHAR* str, bool down, bool matchCase,
|
2014-11-04 00:26:53 +00:00
|
|
|
bool wholeWord)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("FindText '%ls' d=%d c=%d w=%d", str, down, matchCase, wholeWord);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
FINDTEXTEX findTextEx = { 0 };
|
|
|
|
CHARRANGE selChrg;
|
|
|
|
DWORD flags = 0;
|
|
|
|
long start, result;
|
|
|
|
|
2015-02-17 18:41:22 +00:00
|
|
|
if (down)
|
|
|
|
flags |= FR_DOWN;
|
2014-11-04 00:26:53 +00:00
|
|
|
if (matchCase)
|
|
|
|
flags |= FR_MATCHCASE;
|
|
|
|
if (wholeWord)
|
|
|
|
flags |= FR_WHOLEWORD;
|
|
|
|
|
|
|
|
fEditCtrl.GetSel(selChrg);
|
|
|
|
if (selChrg.cpMin == selChrg.cpMax)
|
|
|
|
start = selChrg.cpMin; // start at caret
|
|
|
|
else
|
|
|
|
start = selChrg.cpMin +1; // start past selection
|
2015-02-17 18:41:22 +00:00
|
|
|
LOGD(" selection is %ld,%ld; start=%ld",
|
|
|
|
selChrg.cpMin, selChrg.cpMax, start);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
findTextEx.lpstrText = str;
|
2015-02-17 18:41:22 +00:00
|
|
|
findTextEx.chrg.cpMin = start;
|
|
|
|
if (down) {
|
|
|
|
findTextEx.chrg.cpMax = -1;
|
|
|
|
} else {
|
|
|
|
findTextEx.chrg.cpMax = 0;
|
|
|
|
}
|
|
|
|
LOGV(" using cpMin=%ld cpMax=%ld",
|
|
|
|
findTextEx.chrg.cpMin, findTextEx.chrg.cpMax);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
2015-02-17 18:41:22 +00:00
|
|
|
result = fEditCtrl.FindText(flags, &findTextEx);
|
2014-11-04 00:26:53 +00:00
|
|
|
if (result == -1) {
|
2015-02-17 18:41:22 +00:00
|
|
|
LOGD(" not found, wrapping and retrying");
|
|
|
|
/* didn't find it, wrap around to start/end and retry */
|
|
|
|
if (down) {
|
|
|
|
findTextEx.chrg.cpMin = 0;
|
|
|
|
findTextEx.chrg.cpMax = -1;
|
|
|
|
} else {
|
|
|
|
findTextEx.chrg.cpMin = fEditCtrl.GetTextLength();
|
|
|
|
findTextEx.chrg.cpMax = 0;
|
|
|
|
}
|
Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.
* Switch from MBCS to UNICODE APIs
Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out. So it's
time to switch to wide strings.
This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode). The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.
There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion. These currently have fixed
place-holder "xyzzy" strings.
All UI strings are now wide.
Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow. This doesn't play well with gcc, so
only the Windows-specific parts use those.
* Various updates to vcxproj files
The project-file conversion had some cruft that is now largely
gone. The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.
* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots
The old "prebuilts" directory is now gone. The libraries are now
built as part of building the apps.
I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).
* Replace symbols used for include guards
Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
|
|
|
findTextEx.lpstrText = str;
|
2015-02-17 18:41:22 +00:00
|
|
|
result = fEditCtrl.FindText(flags, &findTextEx);
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
LOGD(" result=%ld min=%ld max=%ld", result,
|
2014-11-04 00:26:53 +00:00
|
|
|
findTextEx.chrgText.cpMin, findTextEx.chrgText.cpMax);
|
|
|
|
if (result != -1) {
|
|
|
|
/* select the text we found */
|
|
|
|
fEditCtrl.SetSel(findTextEx.chrgText);
|
|
|
|
} else {
|
|
|
|
/* remove selection, leaving caret at start of sel */
|
|
|
|
selChrg.cpMax = selChrg.cpMin;
|
|
|
|
fEditCtrl.SetSel(selChrg);
|
|
|
|
|
|
|
|
MainWindow* pMain = (MainWindow*)::AfxGetMainWnd();
|
|
|
|
pMain->FailureBeep();
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|