home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / BORDIMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-12  |  7.5 KB  |  292 lines

  1. /*
  2.     bordimo.c    5/20/89
  3.  
  4.     % Border Request handler function for use by mouse borders & maybe others.
  5.     By JMD
  6.  
  7.     Also contains outline draw routines.
  8.  
  9.     OWL 1.2
  10.     Copyright (c) 1989, by Oakland Group, Inc.
  11.     ALL RIGHTS RESERVED.
  12.  
  13.     Revision History:
  14.     -----------------
  15.      5/23/89 jmd    added "border features"
  16.      7/06/89 ted    Fixed sizing in graphics mode by making bbox use char coords.
  17.                         and cleaned up various other stuff.
  18.      8/02/89 jdc    added mvpnt.x, mvpnt.y initialization for resize
  19.      8/04/89 jmd    added BD_TOP feature
  20.      8/08/89 jmd    made request messages into functions
  21.     12/20/89 ted    Added support for border mousethru feature.
  22.      3/28/90 jmd    ansi-fied
  23.      6/22/90 ted    added "void" to no-parameter function per ansii.
  24.      8/03/90 jmd    added aux messages
  25.     12/11/90 jdc    fixed sizing below 1, 1 bug
  26. */
  27.  
  28. #include "oakhead.h"
  29. #include "disppriv.h"
  30. #include "bordobj.h"
  31. #include "bordod.h"
  32.  
  33. #include "scancode.h"    /* for mouse pseudo-scancodes */
  34.  
  35. enum action_flag {
  36.     ACT_NO, ACT_MOVE, ACT_SIZEUL, ACT_SIZEUR, ACT_SIZELR, ACT_SIZELL
  37.     };
  38.  
  39. OSTATIC objreq_func (bdreq_mouse);
  40. OSTATIC int OWLPRIV bord_mouse(border_od *bdd, mev_struct *mev, unsigned features);
  41.  
  42. /* -------------------------------------------------------------------------- */
  43.  
  44. void bord_MouseInit(void)
  45. {
  46.     bdreq_mousefptr = bdreq_mouse;
  47. }
  48.  
  49. static int bdreq_mouse(VOID *objdata, int msg, VOID *indata, VOID *outdata)
  50. /*
  51.     Standard handler for border mouse messages. Handles topping, moving and
  52.     resizing depending on which border features are turned on.
  53.     Returns 0 if unable to do anything, 1 if if it does something,
  54.     or a scancode (set by the window's aux function) to be returned
  55.     via kb_Read.
  56. */
  57. {
  58.     mev_struct *mev;
  59.     border_od *bdd;
  60.     unsigned features;
  61.     int      ret;
  62.  
  63.     oak_notused(outdata);
  64.     
  65.     mev = (mev_struct *) indata;
  66.     bdd = (border_od *) objdata;
  67.     features = bord_getxdfeature(bordod_GetSelf(bdd));
  68.  
  69.     switch(msg) {
  70.     case BDM_STARTMOUSE:
  71.     case BDM_ENDMOUSE:        /* Mouse left the border. */
  72.         /* Ignore mouse if button pressed when mouse first enters */
  73.         /* (we don't care if mouse is exiting, but what the poot). */
  74.  
  75.         bdd->debounced = mev_IsButtonDown(mev);
  76.         if (!(features & BD_MOUSETHRU)) {
  77.             mev_ClearEvent(mev);
  78.         }
  79.         break;
  80.  
  81.     case BDM_MOUSE:
  82.         if (!mev_IsEventClear(mev)) {
  83.             ret = bord_mouse(bdd, mev, features);
  84.             if ((ret != 0) || !(features & BD_MOUSETHRU)) {
  85.                 mev_ClearEvent(mev);
  86.             }
  87.  
  88.             if (ret != 0 && ret != 1) {
  89.                 return(ret);
  90.             }
  91.         }
  92.         break;
  93.     }
  94.  
  95.     return(1);
  96. }
  97. /* -------------------------------------------------------------------------- */
  98.  
  99. static int OWLPRIV bord_mouse(border_od *bdd, mev_struct *mev, unsigned features)
  100. /*
  101.     Mouse proccessing for borders.
  102.  
  103.     returns 0 if unable to do anything,
  104.     1 if if it does something
  105.     or a scancode (set by the window's aux function) to be returned
  106.     via kb_Read
  107. */
  108. {
  109.     win_type    win;
  110.     opoint         mvpnt, szpnt;
  111.     opcoord        mx, my, offx, offy;
  112.     enum action_flag  action = ACT_NO;
  113.     boolean     oldrawn = FALSE;    /* flag for outline window currently drawn */
  114.     boolean     olmoved = FALSE;    /* flag for outline window actually changed */
  115.     opbox        olbox;
  116.     ocbox        bbox;
  117.     int            ret, evcode = MOU_IGNORE;
  118.  
  119.     if (mev_IsButtonDown(mev)) {
  120.         if (bdd->debounced) {
  121.             return(0);
  122.         }
  123.     }
  124.     else {
  125.         bdd->debounced = FALSE;
  126.         return(0);
  127.     }
  128.  
  129.     win = bdd->win;
  130.  
  131.     /* send an aux message to the window */
  132.     ret = obj_DoAux(win, WINA_BORDERCLICK, (VOID *) mev, (VOID *) &evcode);
  133.     if (evcode != MOU_IGNORE) {
  134.         /* return a scancode via kb_Read() */
  135.         return(evcode);
  136.     }
  137.     if (ret == 0) {
  138.         /* ignore mouse click */
  139.         return(0);
  140.     }
  141.  
  142.     /* If enabled, move the window to the top */
  143.     if (features & BD_TOP) {
  144.         win_Top(win);
  145.         /* Not setting didsomething because we might already be topped */
  146.     }
  147.  
  148.     /* Get the border corners */
  149.     bord_GetBox(win, &bbox);
  150.  
  151.     /* Find offset of mouse from upper corner of window */
  152.     offx = mev_GetX(mev);
  153.     offy = mev_GetY(mev);
  154.  
  155.     /* Assume a MOVE action, then test for others */
  156.     action = (features & BD_MOVE) ? ACT_MOVE : ACT_NO;
  157.  
  158.     if (features & BD_RESIZE) {
  159.         if (mev_GetRow(mev) == bbox.toprow && mev_GetCol(mev) == bbox.leftcol) {
  160.             /* Resize window: Upper Left Corner */
  161.             action = ACT_SIZEUL;
  162.         }
  163.         else if (mev_GetRow(mev) == bbox.toprow && mev_GetCol(mev) == bbox.rightcol) {
  164.             /* Resize window: Upper Right Corner */
  165.             action = ACT_SIZEUR;
  166.             offx -= win_GetPixWidth(win);
  167.         }
  168.         else if (mev_GetRow(mev) == bbox.botrow && mev_GetCol(mev) == bbox.rightcol) {
  169.             /* Resize window: Lower Right */
  170.             action = ACT_SIZELR;
  171.             offx -= win_GetPixWidth(win);
  172.             offy -= win_GetPixHeight(win);
  173.         }
  174.         else if (mev_GetRow(mev) == bbox.botrow && mev_GetCol(mev) == bbox.leftcol) {
  175.             /* Resize window: Lower Left */
  176.             action = ACT_SIZELL;
  177.             offy -= win_GetPixHeight(win);
  178.         }
  179.     }
  180.     if (action == ACT_NO) {
  181.         return(0);
  182.     }
  183.  
  184.     /* Do the action */
  185.     for(;;) {
  186.         /* Size or Move while the mouse is dragged */
  187.  
  188.         /* Get next mouse event in local mev struct */
  189.         if (win_ReadEvent(win, mev) == MOU_EVENT) {
  190.             if (oldrawn) {
  191.                 /* erase the last drawn box */
  192.                 bord_EraseOutline(win, &olbox);
  193.                 oldrawn = FALSE;
  194.             }
  195.             if (!mev_IsButtonDown(mev)) {
  196.                 break;    /* break out of loop */
  197.             }
  198.             else {
  199.                 /* figure out how far we've moved */
  200.                 mx = mev_GetX(mev) - offx;
  201.                 my = mev_GetY(mev) - offy;
  202.                 mvpnt.x = win_GetXmin(win);
  203.                 mvpnt.y = win_GetYmin(win);
  204.  
  205.                 switch (action) {
  206.                 case ACT_MOVE:
  207.                     mvpnt.x += mx;
  208.                     mvpnt.y += my;
  209.                     break;
  210.  
  211.                 case ACT_SIZEUL:
  212.                     if (win_GetPixWidth(win) > 1 || mx < 0) {
  213.                         mvpnt.x += mx;
  214.                         if ((szpnt.x = win_GetPixWidth(win) - mx) < 1) {
  215.                             mvpnt.x += szpnt.x - 1;
  216.                         }
  217.                     }
  218.                     if (win_GetPixHeight(win) > 1 || my < 0) {
  219.                         mvpnt.y += my;
  220.                         if ((szpnt.y = win_GetPixHeight(win) - my) < 1) {
  221.                             mvpnt.y += szpnt.y - 1;
  222.                         }
  223.                     }
  224.                     break;
  225.  
  226.                 case ACT_SIZEUR:
  227.                     szpnt.x = mev_GetX(mev);
  228.                     if (win_GetPixHeight(win) > 1 || my < 0) {
  229.                         mvpnt.y += my;
  230.                         if ((szpnt.y = win_GetPixHeight(win) - my) < 1) {
  231.                             mvpnt.y += szpnt.y - 1;
  232.                         }
  233.                     }
  234.                     break;
  235.  
  236.                 case ACT_SIZELR:
  237.                     szpnt.x = mx;
  238.                     szpnt.y = my;
  239.                     break;
  240.  
  241.                 case ACT_SIZELL:
  242.                     if (win_GetPixWidth(win) > 1 || mx < 0) {
  243.                         mvpnt.x += mx;
  244.                         if ((szpnt.x = win_GetPixWidth(win) - mx) < 1) {
  245.                             mvpnt.x += szpnt.x - 1;
  246.                         }
  247.                     }
  248.                     szpnt.y = my;
  249.                     break;
  250.                 }
  251.                 szpnt.x = int_max(szpnt.x, 1);
  252.                 szpnt.y = int_max(szpnt.y, 1);
  253.  
  254.                 /* Adjust size and position for SIZE */
  255.                 if (features & BD_OUTLINE) {
  256.                     bord_GetPixBox(win, &olbox);
  257.                     opbox_trans(&olbox, mvpnt.x, mvpnt.y);
  258.                     if (action != ACT_MOVE) {    /* Size action */
  259.                         olbox.xmax += szpnt.x - win_GetPixWidth(win);
  260.                         olbox.ymax += szpnt.y - win_GetPixHeight(win);
  261.                     }
  262.                     bord_DrawOutline(win, &olbox);
  263.                     oldrawn = TRUE;
  264.                     olmoved = TRUE; /* keep quick click from having effect */
  265.                 }
  266.                 else {
  267.                     /* move the window */
  268.                     win_SetPixPosition(win, mvpnt.x, mvpnt.y);
  269.  
  270.                     if (action != ACT_MOVE) {    /* Size action */
  271.                         /* resize the window */
  272.                         win_SetPixSize(win, szpnt.x, szpnt.y);
  273.                     }
  274.                 }
  275.             }
  276.         }
  277.     }
  278.     if (olmoved) {
  279.         /* move the window for real */
  280.         win_SetPixPosition(win, mvpnt.x, mvpnt.y);
  281.  
  282.         if (action != ACT_MOVE) {    /* Size action */
  283.             /* resize the window for real */
  284.             win_SetPixSize(win, szpnt.x, szpnt.y);
  285.         }
  286.     }
  287.  
  288.     return(1);
  289. }
  290. /* -------------------------------------------------------------------------- */
  291.  
  292.