📄 reitp.c
字号:
cchTextMost += *pch++ - TEXT('0');
}
}
break;
}
}
else if(!*pszDoc)
{
while(*pch == TEXT(' '))
pch++;
if(*pch)
{
INT cch;
const TCHAR *pchT;
pchT = _tcschr(pch, TEXT(' '));
if(pchT)
cch = pchT - pch;
else
cch = lstrlen(pch);
*pszDoc = GlobalAllocPtr(GHND, cch + 1);
if(!*pszDoc)
break;
lstrcpyn(*pszDoc, (LPCSTR) pch, cch + 1);
(*pszDoc)[cch] = '\0';
}
}
pch = _tcschr(pch, TEXT(' '));
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
REDOC *predoc = (REDOC *) GetWindowLong(hwnd, 0);
#ifndef NO_OLE
LPOLEINPLACEACTIVEOBJECT pipaobj;
#endif // !NO_OLE
switch(msg)
{
case WM_NCCREATE:
predoc = (REDOC *) GlobalAllocPtr(GHND, sizeof(REDOC));
if(!predoc)
return 0;
SetWindowLong(hwnd, 0, (LONG) predoc);
predoc->hwndParent = hwnd;
#ifndef MAC
predoc->pd.lStructSize = sizeof(PRINTDLG);
predoc->pd.hwndOwner = hwnd;
predoc->pd.Flags = PD_RETURNDEFAULT;
if(!PrintDlg(&predoc->pd) && CommDlgExtendedError())
memset(&predoc->pd, 0, sizeof(PRINTDLG));
#endif
break;
case WM_NCDESTROY:
if(predoc)
{
if(predoc->pfr)
GlobalFreePtr(predoc->pfr);
GlobalFreePtr(predoc);
predoc = NULL;
SetWindowLong(hwnd, 0, 0);
}
break;
case WM_CREATE:
hwndMain = hwnd; // a bit of a cheat...
return HandleCreate(predoc,
(LPCSTR) ((CREATESTRUCT *) lparam)->lpCreateParams);
case WM_DESTROY:
PostQuitMessage(0);
return 0l;
case WM_ACTIVATEAPP:
#ifndef NO_OLE
// Notify in place active object of frame activation
if(predoc->pitpcall && (pipaobj = predoc->pitpcall->pipframe->pipaobj))
{
TraceTag(tagInPlace, "OnFrameWindowActivate(%d)", !!wparam);
pipaobj->lpVtbl->OnFrameWindowActivate(pipaobj, !!wparam);
}
#endif // !NO_OLE
break;
case WM_INITMENU:
if(predoc->hwndRE)
predoc->fUpdateEditMenu = TRUE;
break;
case WM_INITMENUPOPUP:
if(predoc->hwndRE)
SetupMenu(predoc, (int) lparam, (HMENU) wparam);
return 0;
case WM_GETMINMAXINFO:
((MINMAXINFO *) lparam)->ptMinTrackSize = ptMinTrackSize;
return 0;
case WM_COMMAND:
return HandleCommand(predoc, hwnd, wparam, lparam);
case WM_CLOSE:
if(predoc && predoc->hwndRE && CloseREDoc(predoc, fTrue, fFalse) < 0)
return 0;
if(!fPrint)
SaveWindowPos(hwnd);
DestroyWindow(hwnd);
return 0;
case WM_ACTIVATE:
if(predoc->hwndRE && LOWORD(wparam))
{
SetFocus(predoc->hwndRE);
return 0;
}
break;
case WM_SIZE:
if(predoc->hwndFormatBar)
SendMessage(predoc->hwndFormatBar, WM_SIZE, 0, 0);
if(predoc->hwndRE)
{
RECT rc;
GetClientRect(hwnd, &rc);
ResizeRedoc(predoc, rc);
#ifdef DEBUG
SendMessage(predoc->hwndRE, EM_REQUESTRESIZE, 0, 0);
#endif // DEBUG
}
break;
case WM_NOTIFY:
switch(((NMHDR *) lparam)->code)
{
case EN_SELCHANGE:
if(predoc->hwndFormatBar)
UpdateFormatBar(predoc);
return 0;
case EN_PROTECTED:
{
ENPROTECTED *penprotected = (ENPROTECTED *) lparam;
// allow change of protected attribute
if(penprotected->msg == EM_SETCHARFORMAT &&
((CHARFORMAT *) penprotected->lParam)->dwMask & CFM_PROTECTED)
{
return 0;
}
}
MessageBeep(0);
return 1;
case EN_CORRECTTEXT:
{
ENCORRECTTEXT *pct = (ENCORRECTTEXT *) lparam;
if(pct->chrg.cpMost - pct->chrg.cpMin > cchMaxCorrectText)
{
MessageBox(hwndMain,
"You are trying to correct too much text. "
"Decrease the size of your selection.",
"REITP: Correct Text", MB_OK);
return 0;
}
}
return 1;
#ifndef NO_OLE
case EN_DROPFILES:
# ifdef DEBUG
if(!QueryCheck(predoc, IDM_IGNOREDROPS))
return fFalse;
TraceTag(tagGeneral, "Ignoring drop of %d file(s) at position %d",
DragQueryFile(((ENDROPFILES *) lparam)->hDrop, (UINT) -1,
NULL, 0),
((ENDROPFILES *) lparam)->cp);
// ignore file drops
return fTrue;
# else // DEBUG
return ((ENDROPFILES *) lparam)->fProtected;
# endif // DEBUG, else
#endif // !NO_OLE
#ifdef DEBUG
case EN_MSGFILTER:
{
MSGFILTER * pmsgfilter = (MSGFILTER *) lparam;
// eat left button downs and 'e's
return (pmsgfilter->msg == WM_LBUTTONDOWN) ||
((pmsgfilter->msg == WM_CHAR) &&
(pmsgfilter->wParam == 'e'));
}
case EN_REQUESTRESIZE:
ResizeRedoc(predoc, ((REQRESIZE *) lparam)->rc);
return 0;
#endif // DEBUG
}
break;
default:
if(msg != msgFindReplace)
break;
if(((FINDREPLACE *) lparam)->Flags & FR_DIALOGTERM)
{
hwndFR = 0;
SendMessage(predoc->hwndRE, EM_HIDESELECTION, fTrue, fTrue);
return 0;
}
ProcessFindReplace(predoc, (FINDREPLACE *) lparam);
return 0;
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
LOCAL LRESULT HandleCreate(REDOC *predoc, LPCSTR szFile)
{
DWORD dwError;
if(!szFile || !*szFile)
goto no_file;
if((dwError = ReadREDoc(predoc, szFile, NULL, 0, FALSE)))
{
TCHAR szErr[300];
wsprintf(szErr, TEXT("Error opening %s [%ld]"), szFile, dwError);
MessageBoxA(hwndMain, szErr, NULL, MB_OK);
goto no_file;
}
if(fPrint)
{
PrintREDoc(predoc);
PostQuitMessage(0);
}
else
{
TCHAR szT[256];
wsprintf(szT, szFmtTitle, predoc->szTitle);
SetWindowText(predoc->hwndParent, szT);
SetMenu(hwndMain, hmenuFull);
SetupWordWrapMenu(predoc);
DrawMenuBar(hwndMain);
}
#ifdef TIME_OPEN
PostMessage(hwndMain, WM_CLOSE, 0, 0);
#endif // TIME_OPEN
return 0;
no_file:
if(NewREDoc(predoc, fFalse, fTrue) < 0)
{
SetMenu(hwndMain, hmenuLoaded);
}
else
{
SetMenu(hwndMain, hmenuFull);
SetupWordWrapMenu(predoc);
}
DrawMenuBar(hwndMain);
return 0;
}
LOCAL VOID ResizeRedoc(REDOC *predoc, RECT rc)
{
RECT rcParent;
#ifndef NO_OLE
LPOLEINPLACEACTIVEOBJECT pipaobj = NULL;
#endif // NO_OLE
GetClientRect(predoc->hwndParent, &rcParent);
InflateRect(&rcParent, dxRESize, dyRESize);
// If we have a format bar, take it into account
if(predoc->hwndFormatBar)
{
RECT rcFmtBar;
GetClientRect(predoc->hwndFormatBar, &rcFmtBar);
rcParent.top += rcFmtBar.bottom;
}
rc.top = max(rcParent.top, rc.top);
rc.left = max(rcParent.left, rc.left);
rc.right = min(rcParent.right, rc.right);
rc.bottom = max(rc.bottom, rc.top + ptMinTrackSize.y);
rc.bottom = min(rcParent.bottom, rc.bottom);
MoveWindow(predoc->hwndRE, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, fTrue);
if(GetMenuState(hmenuFull, IDM_SHOWMARGINS, MF_BYCOMMAND) & MF_CHECKED)
{
rc.bottom -= rc.top;
rc.right -= rc.left;
rc.top = 20;
rc.bottom -= 30;
if(rc.bottom < rc.top)
rc.bottom = rc.top;
rc.left = 30;
rc.right -= 30;
if(rc.right < rc.left)
rc.right = rc.left;
SendMessage(predoc->hwndRE, EM_SETRECT, 0, (LPARAM) &rc);
}
// Notify in place active object of resize
//
// NOTE : Do not change the following line so that it uses an &&
// operation, this causes the Mac to lock up since the compiler
// apparently checks the second half of an AND regardless of the
// initial half's value.
#ifndef NO_OLE
if(predoc->pitpcall && (pipaobj = predoc->pitpcall->pipframe->pipaobj))
{
TraceTag(tagInPlace, "ResizeBorder");
GetClientRect(hwndMain, &rc);
# ifdef MAC
pipaobj->lpVtbl->ResizeBorder(pipaobj, (RectPtr) &rc,
(LPOLEINPLACEUIWINDOW) predoc->pitpcall->pipframe, TRUE);
// Throw out the mem
# else // MAC
pipaobj->lpVtbl->ResizeBorder(pipaobj, &rc,
(LPOLEINPLACEUIWINDOW) predoc->pitpcall->pipframe, TRUE);
# endif // MAC, else
}
#endif // !NO_OLE
}
LOCAL VOID SetupMenu(REDOC *predoc, int iMenu, HMENU hmenu)
{
DWORD dw;
LPOLEOBJECT poleobj = NULL;
switch(iMenu)
{
case 0: // file
if(!predoc->szFile[0])
dw = 0;
else
dw = (DWORD) SendMessage(predoc->hwndRE, EM_GETMODIFY, 0, 0);
EnableMenuItem(hmenu, IDM_REVERT, dw ? uiMFEnabled : uiMFDisabled);
EnableMenuItem(hmenu, IDM_SAVE, predoc->fReadOnly
? uiMFDisabled : uiMFEnabled);
break;
case 1: // edit
dw = uiMFDisabled;
// see if something can be pasted
// let RichEdit figure out if it's read-only
if(SendMessage(predoc->hwndRE, EM_CANPASTE, 0, 0))
dw = uiMFEnabled;
EnableMenuItem(hmenu, IDM_PASTE, (UINT) dw);
dw = 0;
if(!predoc->fReadOnly)
dw = (DWORD) SendMessage(predoc->hwndRE, EM_CANUNDO, 0, 0);
EnableMenuItem(hmenu, IDM_UNDO, dw ? uiMFEnabled : uiMFDisabled);
//$ REVIEW: use EN_SELCHANGE?
dw = (DWORD) SendMessage(predoc->hwndRE, EM_SELECTIONTYPE, 0, 0);
EnableMenuItem(hmenu, IDM_COPY, dw ? uiMFEnabled : uiMFDisabled);
#ifdef DEBUG
if(predoc->fReadOnly && !QueryCheck(predoc, IDM_ENABLECUTREADONLY))
dw = 0;
EnableMenuItem(hmenu, IDM_CUT, dw ? uiMFEnabled : uiMFDisabled);
if(predoc->fReadOnly)
dw = 0;
#else // DEBUG
if(predoc->fReadOnly)
dw = 0;
EnableMenuItem(hmenu, IDM_CUT, dw ? uiMFEnabled : uiMFDisabled);
#endif // DEBUG, else
EnableMenuItem(hmenu, IDM_DELETE, dw ? uiMFEnabled : uiMFDisabled);
EnableMenuItem(hmenu, IDM_INSOBJ, predoc->fReadOnly
? uiMFDisabled : uiMFEnabled);
EnableMenuItem(hmenu, IDM_REPLACE, predoc->fReadOnly ?
uiMFDisabled : uiMFEnabled);
// That's all we need to do
if(!predoc->fUpdateEditMenu)
break;
#ifndef NO_OLE
// Find out if we have a single object to deal with
if(!(dw ^ SEL_OBJECT))
{
REOBJECT reobj = { 0 };
reobj.cbStruct = sizeof(REOBJECT);
reobj.cp = REO_CP_SELECTION;
if(!predoc->preole->lpVtbl->GetObject(predoc->preole,
REO_IOB_USE_CP, &reobj,
REO_GETOBJ_POLEOBJ))
{
poleobj = reobj.poleobj;
}
}
// Ask OLE to build the menu for us
# ifdef MAC
//$ FUTURE MAC
dw = IDM_OBJECTCONVERT;
# ifdef NEVER
macMenu1 = CheckoutMenu(hmenu, 2);
if(!macMenu1)
DebugStr("\pCheckoutMenu(macMenu1) failed");
macMenu2 = CheckoutMenu(predoc->hmenuVerbs, 2);
if(!macMenu2)
DebugStr("\pCheckoutMenu(macMenu2) failed");
if(!OleUIAddVerbMenu(poleobj,
NULL, // Ask OLE to look up the name for us
macMenu1, predoc->hmenuVerbs, ipos_Object,
TRUE, (short *) &dw))
{
DebugStr("\pOleUIAddVerbMenu failed!");
}
CheckinMenu(hmenu, 2);
CheckinMenu(predoc->hmenuVerbs, 2);
# endif // NEVER
# else // MAC
OleUIAddVerbMenu(poleobj,
NULL, // Ask OLE to look up the name for us
hmenu, ipos_Object, IDM_OBJECTMIN,
0, TRUE, IDM_OBJECTCONVERT, &predoc->hmenuVerbs);
# endif // MAC, else
if(poleobj)
poleobj->lpVtbl->Release(poleobj);
#endif // !NO_OLE
// We don't have to do all this hard work again unless the user leaves the
// menu
predoc->fUpdateEditMenu = FALSE;
break;
case 2: // format
{
BOOL fReadOnly = !!predoc->fReadOnly;
UINT uiSuperscript = MF_UNCHECKED;
UINT uiSubscript = MF_UNCHECKED;
UINT uiProtected = MF_UNCHECKED;
UINT uiLeft = MF_UNCHECKED;
UINT uiCenter = MF_UNCHECKED;
UINT uiRight = MF_UNCHECKED;
UINT uiFirstIndent = MF_UNCHECKED;
UINT uiFirstOutdent = MF_UNCHECKED;
CHARFORMAT cf;
PARAFORMAT pf;
cf.cbSize = sizeof(CHARFORMAT);
pf.cbSize = sizeof(PARAFORMAT);
SendMessage(predoc->hwndRE, EM_GETCHARFORMAT, fTrue, (LPARAM) &cf);
if(cf.yOffset > 0)
uiSuperscript = MF_CHECKED;
else if(cf.yOffset < 0)
uiSubscript = MF_CHECKED;
if(cf.dwEffects & CFE_PROTECTED)
uiProtected = MF_CHECKED;
SendMessage(predoc->hwndRE, EM_GETPARAFORMAT, 0, (LPARAM) &pf);
if(!pf.wAlignment || pf.wAlignment == PFA_LEFT)
uiLeft = MF_CHECKED;
else if(pf.wAlignment == PFA_CENTER)
uiCenter = MF_CHECKED;
else
uiRight = MF_CHECKED;
if(pf.dxOffset < 0)
uiFirstIndent = MF_CHECKED;
else if(pf.dxOffset > 0)
uiFirstOutdent = MF_CHECKED;
CheckMenuItem(hmenu, IDM_SUPERSCRIPT, uiSuperscript);
CheckMenuItem(hmenu, IDM_SUBSCRIPT, uiSubscript);
CheckMenuItem(hmenu, IDM_PROTECTED, uiProtected);
CheckMenuItem(hmenu, IDM_ALIGNLEFT, uiLeft);
CheckMenuItem(hmenu, IDM_ALIGNCENTER, uiCenter);
CheckMenuItem(hmenu, IDM_ALIGNRIGHT, uiRight);
CheckMenuItem(hmenu, IDM_INDENTFIRST, uiFirstIndent);
CheckMenuItem(hmenu, IDM_OUTDENTFIRST, uiFirstOutdent);
EnableMenuItem(hmenu, IDM_CHARFORMAT, fReadOnly
? uiMFDisabled : uiMFEnabled);
EnableMenuItem(hmenu, IDM_SUPERSCRIPT, fReadOnly
? uiMFDisabled : uiMFEnabled);
EnableMenuItem(hmenu, IDM_SUBSCRIPT, fReadOnly
? uiMFDisabled : uiMFEnabled);
EnableMenuItem(hmenu, IDM_ALIGNLEFT, fReadOnly
? uiMFDisabled : uiMFEnabled);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -