home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
NOTEPAD2.ZIP
/
MNOTIFY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-08
|
4KB
|
114 lines
/*
* mnotify.c -- Notify owner of events
*
* Created by Microsoft Corporation, 1989
*/
#define INCL_WIN
#include <os2.h>
#include "mle.h"
#include "mtypes.h"
#include "mfuncs.h"
/* public function
*
* VOID NotifyOwner(PED ped, USHORT usENCode, MPARAM mparam)
*
* Send an EN_* notification to the edit window's owner. The edit
* notification code will be usENCode, and the second parameter of
* the message sent will be mparam.
*
* The function doesn't return until the owner has processed the
* notification message.
*/
public VOID NotifyOwner(PED ped, USHORT usENCode, MPARAM mparam)
{
HWND hwndOwner = WinQueryWindow (ped->hwnd, QW_OWNER, FALSE);
/* we can't store this, since owner could change at any time */
if (hwndOwner != NULL) {
WinSendMsg (hwndOwner, WM_CONTROL,
MPFROM2SHORT (ped->idChild, usENCode), mparam);
}
}
/* public function
*
* VOID NotifyScroll(PED ped, USHORT usCode, BOOL fForce)
*
* Notify owner that we may be about to scroll, sending it the appropriate
* new slider position. usCode must be either EN_HSCROLL or EN_VSCROLL.
*
* If fForce is TRUE, we will definitely send the notification. This option
* should be used when the window is actually scrolled. Otherwise, we'll
* only notify the owner if the slider position has change (as it may in
* response to changes in the text length).
*
* This routine should be called before the scroll actually happens. The
* message is sent using WinSendMsg, so the routine doesn't return until the
* owner has processed the message.
*
* SIDE EFFECT: Resets ped->iHSlider or ped->iVSlider.
*
* We figure the slider positions as fractions in the range [0, 1],
* then translate and/or scale them to cover the range [SLIDER_MIN,
* SLIDER_MAX].
*
* For horizontal scrolling, the fraction is given by
*
* number of pixels scrolled off the left edge (hScroll)
* -------------------------------------------------------------
* maximum allowable value of hScroll (pixCurMax - AveCharWidth)
*
* Note that when word wrap is on, pixCurMax will always be the
* width of the window.
*
* For vertical scrolling, the ideal fraction would be
*
* ipt of first char of first visible line
* -----------------------------------------
* ipt of first char of last line in text
*
* However, we may not have available the last line of text.
* Since the denominator of the fraction is the same as
* the number of chars in the text minus the length of the
* last line, we estimate this by approximating the length of
* the last line with that of the current line. The important
* fact is that this comes out right at the boundary conditions,
* i.e., the fraction is 0 for the first line and 1 for the last.
*
* We always round down on the slider position, i.e., the fraction
* never reaches 1 until the window is scrolled as far right or
* down as possible.
*/
public VOID NotifyScroll(PED ped, SHORT usCode, BOOL fForce)
{
USHORT iSlider;
ULONG range;
iSlider = SLIDER_MIN;
if (usCode==EN_HSCROLL) { /* horiz scroll */
range = (ULONG)(ped->pixCurMax - ped->AveCharWidth);
if (range > 0) {
iSlider += MultDivNR((SLIDER_MAX-SLIDER_MIN),
(USHORT) ped->hScroll, (USHORT) range);
}
if (fForce || (iSlider != ped->iHSlider)) {
NotifyOwner (ped, EN_HSCROLL, MPFROMSHORT (iSlider));
}
ped->iHSlider = iSlider;
} else { // vert scroll
if ((ped->iptMac-TxtLineLength(ped,(PPR)ped->pmrFVL))>0) {
iSlider += MultDivNR((SLIDER_MAX - SLIDER_MIN),
(USHORT) ped->iptFVL,
(USHORT) (ped->iptMac-TxtLineLength(ped,(PPR)ped->pmrFVL)));
}
if (fForce || iSlider != ped->iVSlider) {
NotifyOwner(ped, EN_VSCROLL, MPFROMSHORT (iSlider));
}
ped->iVSlider = iSlider;
}
}