home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / NOTEPAD2.ZIP / MNOTIFY.C < prev    next >
C/C++ Source or Header  |  1989-02-08  |  4KB  |  114 lines

  1. /*
  2.  * mnotify.c -- Notify owner of events
  3.  *
  4.  * Created by Microsoft Corporation, 1989
  5.  */
  6.  
  7. #define INCL_WIN
  8. #include <os2.h>
  9. #include "mle.h"
  10. #include "mtypes.h"
  11. #include "mfuncs.h"
  12.  
  13. /* public function
  14.  *
  15.  * VOID NotifyOwner(PED ped, USHORT usENCode, MPARAM mparam)
  16.  *
  17.  * Send an EN_* notification to the edit window's owner.  The edit
  18.  * notification code will be usENCode, and the second parameter of
  19.  * the message sent will be mparam.
  20.  *
  21.  * The function doesn't return until the owner has processed the
  22.  * notification message.
  23.  */
  24. public VOID NotifyOwner(PED ped, USHORT usENCode, MPARAM mparam)
  25. {
  26.     HWND hwndOwner = WinQueryWindow (ped->hwnd, QW_OWNER, FALSE);
  27.             /* we can't store this, since owner could change at any time */
  28.  
  29.     if (hwndOwner != NULL) {
  30.             WinSendMsg (hwndOwner, WM_CONTROL,
  31.                     MPFROM2SHORT (ped->idChild, usENCode), mparam);
  32.     }
  33. }
  34.  
  35.  
  36. /* public function
  37.  *
  38.  * VOID NotifyScroll(PED ped, USHORT usCode, BOOL fForce)
  39.  *
  40.  * Notify owner that we may be about to scroll, sending it the appropriate
  41.  * new slider position.  usCode must be either EN_HSCROLL or EN_VSCROLL.
  42.  *
  43.  * If fForce is TRUE, we will definitely send the notification.  This option
  44.  * should be used when the window is actually scrolled.  Otherwise, we'll
  45.  * only notify the owner if the slider position has change (as it may in
  46.  * response to changes in the text length).
  47.  *
  48.  * This routine should be called before the scroll actually happens.  The
  49.  * message is sent using WinSendMsg, so the routine doesn't return until the
  50.  * owner has processed the message.
  51.  *
  52.  * SIDE EFFECT: Resets ped->iHSlider or ped->iVSlider.
  53.  *
  54.  *     We figure the slider positions as fractions in the range [0, 1],
  55.  *     then translate and/or scale them to cover the range [SLIDER_MIN,
  56.  *     SLIDER_MAX].
  57.  *
  58.  *     For horizontal scrolling, the fraction is given by
  59.  *
  60.  *           number of pixels scrolled off the left edge (hScroll)
  61.  *       -------------------------------------------------------------
  62.  *       maximum allowable value of hScroll (pixCurMax - AveCharWidth)
  63.  *
  64.  *       Note that when word wrap is on, pixCurMax will always be the
  65.  *       width of the window.
  66.  *
  67.  *     For vertical scrolling, the ideal fraction would be
  68.  *
  69.  *                 ipt of first char of first visible line
  70.  *                -----------------------------------------
  71.  *                 ipt of first char of last line in text
  72.  *
  73.  *     However, we may not have available the last line of text.
  74.  *     Since the denominator of the fraction is the same as
  75.  *     the number of chars in the text minus the length of the
  76.  *     last line, we estimate this by approximating the length of
  77.  *     the last line with that of the current line.  The important
  78.  *     fact is that this comes out right at the boundary conditions,
  79.  *     i.e., the fraction is 0 for the first line and 1 for the last.
  80.  *
  81.  *     We always round down on the slider position, i.e., the fraction
  82.  *     never reaches 1 until the window is scrolled as far right or
  83.  *     down as possible.
  84.  */
  85. public VOID NotifyScroll(PED ped, SHORT usCode, BOOL fForce)
  86. {
  87.     USHORT iSlider;
  88.     ULONG range;
  89.  
  90.     iSlider = SLIDER_MIN;
  91.  
  92.     if (usCode==EN_HSCROLL) {               /* horiz scroll */
  93.         range = (ULONG)(ped->pixCurMax - ped->AveCharWidth);
  94.         if (range > 0) {
  95.         iSlider += MultDivNR((SLIDER_MAX-SLIDER_MIN),
  96.             (USHORT) ped->hScroll, (USHORT) range);
  97.         }
  98.         if (fForce || (iSlider != ped->iHSlider)) {
  99.             NotifyOwner (ped, EN_HSCROLL, MPFROMSHORT (iSlider));
  100.         }
  101.         ped->iHSlider = iSlider;
  102.     } else {                                    // vert scroll
  103.         if ((ped->iptMac-TxtLineLength(ped,(PPR)ped->pmrFVL))>0) {
  104.             iSlider += MultDivNR((SLIDER_MAX - SLIDER_MIN),
  105.             (USHORT) ped->iptFVL,
  106.                 (USHORT) (ped->iptMac-TxtLineLength(ped,(PPR)ped->pmrFVL)));
  107.         }
  108.         if (fForce || iSlider != ped->iVSlider) {
  109.             NotifyOwner(ped, EN_VSCROLL, MPFROMSHORT (iSlider));
  110.         }
  111.         ped->iVSlider = iSlider;
  112.     }
  113. }
  114.