home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
NOTEPAD2.ZIP
/
MWND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-08
|
19KB
|
475 lines
/*
* mwnd.c -- Window management
*
* Created by Microsoft Corporation, 1989
*/
#define INCL_WIN
#define INCL_GPI
#include <os2.h>
#include <opendlg.h>
#include "mle.h"
#include "mtypes.h"
#include "mfuncs.h"
VOID DispVScrollToIpt(PED, IPT, SHORT);
/***********************************************************************
* Window procedure for MLE window
***********************************************************************/
MRESULT CALLBACK MleWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
PED ped;
RECTL rcl;
if (msg >= WM_MOUSEFIRST && msg <= WM_MOUSELAST) {
ProcessMouse (GETPED (hwnd), msg, (SHORT) LOSHORTFROMMP (mp1), (SHORT) HISHORTFROMMP (mp1));
if (msg == WM_MOUSEMOVE)
return (TRUE); // indicate we processed the message
}
else switch (msg) {
case WM_CREATE: /* Prepare to edit an empty document */
InitInstance(hwnd);
break;
case WM_SIZE: /* Recalc line breaks, etc. */
ped = GETPED(hwnd);
DispChangeSize(ped,LOSHORTFROMMP(mp2),HISHORTFROMMP(mp2));
break;
case WM_SETFOCUS: /* Receive or lose input focus */
SetFocus(GETPED(hwnd), LOSHORTFROMMP(mp2));
break;
case WM_PAINT:
ped = GETPED (hwnd);
WinBeginPaint(hwnd, ped->hps, &rcl);
WinEndPaint(ped->hps);
DispRefresh(ped, TRUE, rcl);
break;
case WM_CHAR: /* Process keyboard input */
if (! (LONGFROMMP(mp1) & KC_KEYUP)) { // if key's not just being released
ped = GETPED(hwnd);
ProcessKey (ped, HISHORTFROMMP (mp2),
LOSHORTFROMMP (mp2), LOSHORTFROMMP(mp1),
(SHORT) LOUCHAR (HISHORTFROMMP (mp1)));
ZeroRect(rcl);
DispRefresh(ped, FALSE, rcl);
return (TRUE); // indicate we processed the message
}
break;
case WM_TIMER: // timer message
// Timer message for mouse scrolling
if ((SHORT)LOSHORTFROMMP(mp1) == TID_MOUSESCROLL) {
POINTL ptl;
WinQueryMsgPos((HAB) NULL, &ptl);
WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1);
ProcessMouse(GETPED(hwnd),msg,(SHORT)ptl.x,(SHORT)ptl.y);
} else // some system timer
return WinDefWindowProc(hwnd, msg, mp1, mp2);
break;
case WM_HSCROLL: // scroll bar message, forwarded from frame window
// The rule here is the same as for vertical scroll: we can
// scroll right until the end of the longest line is about
// to disappear (i.e., its last character is still visible).
// The "longest line" here means the longest line in the document
// that we know about, i.e., with length pixCurMax.
ped = GETPED (hwnd);
switch (HISHORTFROMMP (mp2)) { /* which message? */
case SB_LINELEFT:
DispHScroll(ped, -(DISPLAY_SCROLLACWS*ped->AveCharWidth),
TRUE);
break;
case SB_LINERIGHT:
DispHScroll(ped,DISPLAY_SCROLLACWS*ped->AveCharWidth,TRUE);
break;
case SB_PAGELEFT:
DispHScroll(ped, -(DispWidth(ped)/2), TRUE);
break;
case SB_PAGERIGHT:
DispHScroll(ped, +(DispWidth(ped)/2), TRUE);
break;
case SB_SLIDERTRACK:
case SB_SLIDERPOSITION:
DispHScrollTo(ped, ((ped->pixCurMax - ped->AveCharWidth) *
(LOSHORTFROMMP (mp2) - SLIDER_MIN)) /
(SLIDER_MAX - SLIDER_MIN),
(HISHORTFROMMP(mp2) == SB_SLIDERPOSITION));
break;
default:
return (0L); /* do nothing */
}
break;
case WM_VSCROLL: // scroll bar message, forwarded from frame window
ped = GETPED (hwnd);
switch (HISHORTFROMMP (mp2)) {
case SB_LINEUP:
DispVScroll(ped, (LINE) -1,TRUE);
break;
case SB_LINEDOWN:
DispVScroll(ped, (LINE) 1,TRUE);
break;
case SB_PAGEUP:
DispVScroll(ped, (LINE)(-DispHeight(ped)+1), TRUE);
break;
case SB_PAGEDOWN:
DispVScroll(ped, (LINE)(DispHeight(ped)-1), TRUE);
break;
case SB_SLIDERTRACK:
case SB_SLIDERPOSITION:
// The user's moved the slider. If the new slider
// position is 75 on a scale of 0 to 100 (for example),
// we find the line containing the 75% point of the
// document. Note that this is not quite the inverse of
// the method NotifyScroll uses to find the slider
// position from the text in the document, since to get
// that right we'd need to know the length of the line we
// were trying to scroll to. This is OK because
// our method here still has the following properties:
// (1) If the slider hasn't moved at all, we're guaranteed
// to stay in the same place, and (2) if the slider's
// moved to the top or bottom, we're guaranteed to go to
// the first or last line of the document. Anyway, we're
// going to send back a new slider position based on the
// ipt we actually do move to.
{
IPT ul;
ul = (ped->iptMac*(LOSHORTFROMMP(mp2)-SLIDER_MIN))
/ (SLIDER_MAX - SLIDER_MIN);
DispVScrollToIpt(ped, ul,
(HISHORTFROMMP(mp2)==SB_SLIDERPOSITION));
break;
}
default:
return (0L); /* return w/o doing anything */
}
break;
case EM_SETTEXTLIMIT:
return(TxtSetLimit(GETPED(hwnd),LONGFROMMP(mp1)));
case EM_QTL: /* query text length */
return(MRFROMLONG(TxtLength(GETPED (hwnd))));
case EM_CHARFROMLINE: /* return ipt given absolute line # */
return(0L);
case EM_LINEFROMCHAR: /* return abs line # containing ipt */
return(0L);
case EM_SETWRAP: /* turn word wrap on or off */
ped = GETPED(hwnd);
TxtSetWordWrap(ped,(BOOL) (!! (LOSHORTFROMMP (mp1))));
DispRefresh(ped,FALSE,ped->rclWnd);
break;
case EM_QUERYFONT: /* Return current font information */
/* Send back the current pfattrs entry to the caller.
Note that this can be NULL, which indicates the default
system font, whatever it may be. */
return (MRESULT) (GETPED (hwnd))->pfattrs;
case EM_SETFONT: /* Set the current font */
/* This sets the font that the MLE window uses, based on
the font information contained within the fattr that the
caller provides. GpiCreateLogFont will be called using this
fattr, so it should be set up accordingly. The return value
is the same as for EM_QUERYFONT, so the caller should compare
this to the intended result to verify success. */
ped = GETPED (hwnd);
DispChangeFont(ped, (PFATTRS) PVOIDFROMMP (mp1));
DispChangeSize(ped, (USHORT) ped->rclWnd.xRight,
(USHORT) ped->rclWnd.yTop);
DispRefresh(ped,TRUE,ped->rclWnd);
return (MRESULT) ped->pfattrs;
case EM_QUERYSEL: /* What's currently selected? */
/* Based on the last 3 bits of mp1, return:
0 MAKEULONG (min ipt of selection, max ipt of selection)
Rounds down to 65535 if over. This is the format
supported by Windows MLE and PM SLE.
1 min ipt of selection
2 max ipt of selection
3 starting ipt of selection (anchor point)
4 ending ipt of selection (cursor point)
5 }
6 } undefined (reserved)
7 }
*/
{
IPT iptCursor, iptAnchor;
ped = GETPED (hwnd);
iptCursor = TxtQueryCursor(ped);
iptAnchor = TxtQueryAnchor(ped);
switch ((USHORT) mp1 & 0x0007) {
case 0:
if (iptCursor > 65535) iptCursor = 65535;
if (iptAnchor > 65535) iptAnchor = 65535;
if (iptCursor <= iptAnchor)
return (MRFROM2SHORT (iptCursor, iptAnchor));
else
return (MRFROM2SHORT (iptAnchor, iptCursor));
case 1:
return (MRFROMLONG (min (iptCursor, iptAnchor)));
case 2:
return (MRFROMLONG (max (iptCursor, iptAnchor)));
case 3:
return (MRFROMLONG (iptAnchor));
case 4:
return (MRFROMLONG (iptCursor));
default:
return ((MRESULT) 0);
}
}
case EM_SETSEL: /* set the selection */
/* mp1 specifies the anchor point, mp2 the cursor
point. If both are valid insertion points, set the selection
and return TRUE; otherwise return FALSE.
Note that LONGFROMMP actually returns a ULONG.
*/
ped = GETPED (hwnd);
if (((LONG)(mp1)>ped->iptMac) || ((LONG)(mp2)>ped->iptMac)) {
return ((MRESULT) FALSE);
} else {
TxtSetAnchorCursor(ped, (LONG)mp1, (LONG)mp2);
ZeroRect(rcl);
DispRefresh(ped,FALSE,rcl);
return ((MRESULT) TRUE);
}
case EM_QUERYCHANGED:
// If the text has been changed since the last EM_QUERYCHANGED
// or WM_QUERYWINDOWPARAMS message, return TRUE, otherwise FALSE.
// As a side effect, set fChanged to FALSE.
return((MRESULT)TxtSetChanged(GETPED(hwnd), FALSE));
case EM_SETCHANGED:
// sets the 'changed' flag to a particular value.
return((MRESULT)TxtSetChanged(GETPED(hwnd), (BOOL)mp1));
case EM_QUERYTYPING:
// returns the 'typing allowed' flag
return(QueryTyping(GETPED(hwnd)));
case EM_SETTYPING:
// sets or clears the 'typing allowed' flag
return(SetTyping(GETPED(hwnd),(BOOL)mp1));
case EM_QUERYTABSIZE:
// returns the current tab size
return(QueryTabWidth(GETPED(hwnd)));
case EM_SETTABSIZE:
{
PIX TabSize;
// sets or clears the 'typing allowed' flag
ped = GETPED(hwnd);
TabSize = SetTabWidth(ped, SHORT1FROMMP(mp1));
TxtReformat(ped, ped->pprHead, TRUE);
ZeroRect(rcl);
DispRefresh(ped,FALSE,rcl);
return(MRFROMLONG(TabSize));
}
case EM_CLEAR: /* Clear the current selection. */
ped = GETPED(hwnd);
return(TxtClipClear(ped,
TxtQueryAnchor(ped),
TxtQueryCursor(ped)));
case EM_CUT: /* cut selection to clipboard */
ped = GETPED(hwnd);
return(TxtClipCut(ped,
TxtQueryAnchor(ped),
TxtQueryCursor(ped)));
case EM_COPY: /* copy selection to clipboard */
ped = GETPED(hwnd);
return(TxtClipCopy(ped,
TxtQueryAnchor(ped),
TxtQueryCursor(ped)));
case EM_PASTE: /* paste into selection from clipboard */
ped = GETPED(hwnd);
return(TxtClipPaste(ped,
TxtQueryAnchor(ped),
TxtQueryCursor(ped)));
case EM_FORMAT: // set the transfer format
return(BufSetFormat(GETPED(hwnd),SHORT1FROMMP(mp1)));
case EM_SETIMPORTEXPORT: // set block buffer
return(BufSetBuf(GETPED(hwnd),
PVOIDFROMMP(mp1),
SHORT1FROMMP(mp2)));
case EM_IMPORT: // insert a buffer
/* Insert at mp1 the block of mp2 chars from the block
* buffer. Return TRUE iff successful.
*
* We don't ensure that the cursor's visible when we're done; the
* caller may send an EM_SETSEL if it does want the text to be
* scrolled.
*/
ped = GETPED(hwnd);
return(BufCopyIn(ped,
LONGFROMMP(mp1),
LONGFROMMP(mp1),
BufQueryBuf(ped),
min(SHORT1FROMMP(mp2), BufQueryBufSize(ped))));
case EM_EXPORT: // copy a block of text into the block buffer
/* Copy into the block buffer the block that starts at insertion
* point mp1 and continues for mp2 characters. Return
* TRUE iff successful.
*/
ped = GETPED (hwnd);
return(BufCopyOut(ped,
LONGFROMMP(mp1),
BufQueryFormat(ped),
BufQueryBuf(ped),
BufQueryBufSize(ped)));
case EM_DELETE: // delete a block
/* Delete the block that starts at the insertion point mp1
* and continues for mp2 characters. Return TRUE iff
* successful.
*
* We don't ensure that the cursor's visible when we're done; the
* caller may send an EM_SETSEL if it does want the text to be
* scrolled.
*/
ped = GETPED(hwnd);
if (LONGFROMMP(mp1)+LONGFROMMP(mp2)>TxtLength(ped)) {
return(FALSE);
}
return(TxtChange(ped,
LONGFROMMP(mp1),
LONGFROMMP(mp1)+LONGFROMMP(mp2),
NULL,
0));
case EM_REPLACE: // replace a block with buffer contents
/* replace the block that starts at the insertion point mp1
* and continues for mp2 characters with the contents of the
* transfer buffer. Return TRUE iff successful.
*
* We don't ensure that the cursor's visible when we're done; the
* caller may send an EM_SETSEL if it does want the text to be
* scrolled.
*/
ped = GETPED(hwnd);
if (LONGFROMMP(mp1)+LONGFROMMP(mp2)>TxtLength(ped)) {
return(FALSE);
}
return(BufCopyIn(ped,
LONGFROMMP(mp1),
LONGFROMMP(mp1)+LONGFROMMP(mp2),
BufQueryBuf(ped),
BufQueryBufSize(ped)));
case EM_GETTEXT: /* get a block of text */
/* Return a pointer to a block of text. mp1 specifies the
ipt of the block beginning; mp2 points to a USHORT in
which the length of the block will be returned.
If mp1 >= iptMac, the routine will return NULL and
set *mp2 to 0. Otherwise *mp2 is guaranteed to be
at least 1.
Note that LONGFROMMP actually returns a ULONG.
*/
ped = GETPED (hwnd);
if (LONGFROMMP (mp1) >= TxtLength(ped)) {
*((PUSHORT) PVOIDFROMMP(mp2)) = 0;
return (MRFROMP (NULL));
} else {
PPR ppr;
IPT ipt;
ipt = LONGFROMMP(mp1);
ppr = TxtPPROfIpt(ped, &ipt);
if (fIsMarker(ppr)) {
ppr = SkipMarkers(ppr, MARKER_ANY);
ipt = 0;
}
*((PUSHORT)PVOIDFROMMP(mp2))=ppr->cchText-(USHORT)ipt;
return(MRFROMP(ppr->pchText + ipt));
}
case WM_DESTROY: /* window is about to be destroyed */
ped = GETPED (hwnd);
GpiDestroyRegion (ped->hps, ped->hrgnT); /* destroy region temp variable associated with PS */
GpiDestroyPS (ped->hps); /* destroy its PS */
break;
default:
return WinDefWindowProc (hwnd, msg, mp1, mp2);
}
return(0L);
}