home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / pollmouse < prev    next >
Encoding:
Text File  |  1991-02-04  |  30.9 KB  |  682 lines

  1. /* > $.CLIB.C.pollmouse
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *     routine to perform mouse related reason code returns from
  21.  *     SWI(Wimp_Poll)
  22.  */
  23. #include "c.poll_h"
  24.  
  25. int haswin_poll_drag(int (*user)(int, buffer *), buffer *pbuf) {
  26.  
  27.         _kernel_swi_regs  regs;
  28.  
  29.         if (!(haswin_flags & HASWIN_FLAGS_DRAG)) {
  30.                 haswin_internalerror("A drag request while not dragging is inconsistant!");
  31.                 return(HASWIN_FALSE);
  32.         }
  33.         if (haswin_dragwindow)
  34.                 pbuf->i[4] = haswin_dragwindow->handle;
  35.         else
  36.                 pbuf->i[4] = -1;
  37.         if (haswin_dragicon)
  38.                 pbuf->i[5] = haswin_dragicon->ihandle;
  39.         else
  40.                 pbuf->i[5] = -1;
  41.         pbuf->i[6] = (int)haswin_dragwindow;
  42.         pbuf->i[7] = (int)haswin_dragicon;
  43.         if ((haswin_dragicon) && (haswin_dragicon->dragroutine)) {
  44.                 if (!((*haswin_dragicon->dragroutine)(haswin_dragwindow, haswin_dragicon, &haswin_dragmouse, pbuf)))
  45.                         return(HASWIN_TRUE);
  46.                 if ((user) && (!((*user)(HASWIN_POLL_Drag, pbuf))))
  47.                         return(HASWIN_FALSE);
  48.                 regs.r[1] = 0;
  49.                 return(haswin_swi(HASWIN_Drag_box, ®s));
  50.         }
  51.         if ((haswin_dragwindow) && (haswin_dragwindow->dragroutine) && (!((*haswin_dragwindow->dragroutine)(haswin_dragwindow, haswin_dragicon, &haswin_dragmouse, pbuf))))
  52.                 return(HASWIN_TRUE);
  53.         if ((user) && (!((*user)(HASWIN_POLL_Drag, pbuf))))
  54.                 return(HASWIN_FALSE);
  55.         regs.r[1] = 0;
  56.         return(haswin_swi(HASWIN_Drag_box, ®s));
  57. }
  58.  
  59. /*
  60.  *      this small piece of code handles HASWINs attempts to drag an
  61.  *      object from a mouse click.  It should be called *ONLY* from
  62.  *      "haswin_poll_mouse()" below
  63.  */
  64. static int tryrightdrag(window *wptr, icon *iptr, buffer *pbuf, int err) {
  65.  
  66.         int                     adjx, adjy;
  67.         _kernel_swi_regs        regs;
  68.         buffer                  buff;
  69.  
  70.         /* right ADJUST button dragged */
  71.         if (((int)wptr > 0) && (pbuf->i[4] == -1) &&
  72.             (!(wptr->flags & WINDOW_DRAGADJ))) {
  73.                 if (err)
  74.                         haswin_internalerror("dragging is not allowed in this window");
  75.                 return(HASWIN_FALSE);
  76.         }
  77.         if (((int)iptr > 0) && (!(iptr->flags & ICON_DRAGADJ))) {
  78.                 if (err)
  79.                         haswin_internalerror("dragging is not allowed in this icon");
  80.                 return(HASWIN_FALSE);
  81.         }
  82.         if (haswin_flags & HASWIN_FLAGS_DRAG) {
  83.                 regs.r[1] = 0;
  84.                 haswin_swi(HASWIN_Drag_box, ®s);
  85.         }
  86.         haswin_getpointerinfo(&haswin_dragmouse);
  87.         if (((int)iptr > 0) && (iptr->dragroutine) && (!((*iptr->dragroutine)(wptr, iptr, &haswin_dragmouse, 0))))
  88.                 return(HASWIN_TRUE);
  89. else if (((int)wptr > 0) && (wptr->dragroutine) && (!((*wptr->dragroutine)(wptr, iptr, &haswin_dragmouse, 0))))
  90.                 return(HASWIN_TRUE);
  91.         haswin_flags &= ~HASWIN_FLAGS_DRAG;
  92.         haswin_dragwindow = wptr;
  93.         haswin_dragicon = iptr;
  94.         if (pbuf->i[4] == -1) {
  95.                 buff.i[0] = pbuf->i[3];
  96.                 buff.i[1] = 6;
  97.                 buff.i[2] = pbuf->i[0];
  98.                 buff.i[3] = pbuf->i[1];
  99.                 buff.i[4] = pbuf->i[0]+1;
  100.                 buff.i[5] = pbuf->i[1]+1;
  101.                 buff.i[6] = 0;
  102.                 buff.i[7] = 0;
  103.                 buff.i[8] = haswin_readvduvariable(VDUVAR_ScreenXsize);
  104.                 buff.i[9] = haswin_readvduvariable(VDUVAR_ScreenYsize);
  105.                 regs.r[1] = (int)&buff;
  106.                 if (haswin_swi(HASWIN_Drag_box, ®s))
  107.                         haswin_flags |= HASWIN_FLAGS_DRAG;
  108.                 else
  109.                         return(HASWIN_FALSE);
  110.        } else if ((int)wptr > 0) {
  111.                 adjx = ((int *)(wptr->win))[0] -
  112.                        ((int *)(wptr->win))[4];
  113.                 adjy = ((int *)(wptr->win))[3] -
  114.                        ((int *)(wptr->win))[5];
  115.                 buff.i[0] = pbuf->i[3];
  116.                 buff.i[1] = pbuf->i[4];
  117.                 regs.r[1] = (int)&buff;
  118.                 haswin_swi(HASWIN_Get_icon_state, ®s);
  119.                 buff.i[0] = pbuf->i[3];
  120.                 buff.i[1] = 5;
  121.                 buff.i[2] += adjx;
  122.                 buff.i[3] += adjy;
  123.                 buff.i[4] += adjx;
  124.                 buff.i[5] += adjy;
  125.                 buff.i[6] = 0;
  126.                 buff.i[7] = 0;
  127.                 buff.i[8] = haswin_readvduvariable(VDUVAR_ScreenXsize);
  128.                 buff.i[9] = haswin_readvduvariable(VDUVAR_ScreenYsize);
  129.                 regs.r[1] = (int)&buff;
  130.                 if (haswin_swi(HASWIN_Drag_box, ®s))
  131.                         haswin_flags |= HASWIN_FLAGS_DRAG;
  132.                 else
  133.                         return(HASWIN_FALSE);
  134.         }
  135.         return(HASWIN_TRUE);
  136. }
  137.  
  138. /*
  139.  *      this small piece of code handles HASWINs attempts to drag an
  140.  *      object from a mouse click.  It should be called *ONLY* from
  141.  *      "haswin_poll_mouse()" below.
  142.  */
  143. static int tryleftdrag(window *wptr, icon *iptr, buffer *pbuf, int err) {
  144.  
  145.         int                     adjx, adjy;
  146.         _kernel_swi_regs        regs;
  147.         buffer                  buff;
  148.  
  149.         /* left SELECT button dragged */
  150.         if (((int)wptr > 0) && (pbuf->i[4] == -1) &&
  151.             (!(wptr->flags &  WINDOW_DRAGSEL)) &&
  152.             (!(wptr->flags & WINDOW_AUTOTEXT)) ) {
  153.                 if (err)
  154.                         haswin_internalerror("dragging is not allowed in this window");
  155.                 return(HASWIN_FALSE);
  156.         }
  157.         if (((int)iptr > 0) && (!(iptr->flags & ICON_DRAGSEL))) {
  158.                 if (err)
  159.                         haswin_internalerror("dragging is not allowed in this icon");
  160.                 return(HASWIN_FALSE);
  161.         }
  162.         if (haswin_flags & HASWIN_FLAGS_DRAG) {
  163.                 regs.r[1] = 0;
  164.                 haswin_swi(HASWIN_Drag_box, ®s);
  165.         }
  166.         haswin_getpointerinfo(&haswin_dragmouse);
  167.         if (((int)iptr > 0) && (iptr->dragroutine) && (!((*iptr->dragroutine)(wptr, iptr, &haswin_dragmouse, 0))))
  168.                 return(HASWIN_TRUE);
  169.         else if (((int)wptr > 0) && (wptr->dragroutine) && (!((*wptr->dragroutine)(wptr, iptr, &haswin_dragmouse, 0))))
  170.                 return(HASWIN_TRUE);
  171.         haswin_flags &= ~HASWIN_FLAGS_DRAG;
  172.         haswin_dragwindow = wptr;
  173.         haswin_dragicon = iptr;
  174.         if (pbuf->i[4] == -1) {
  175.                 buff.i[0] = pbuf->i[3];
  176.                 buff.i[1] = 6;
  177.                 buff.i[2] = pbuf->i[0];
  178.                 buff.i[3] = pbuf->i[1];
  179.                 buff.i[4] = pbuf->i[0]+1;
  180.                 buff.i[5] = pbuf->i[1]+1;
  181.                 buff.i[6] = 0;
  182.                 buff.i[7] = 0;
  183.                 buff.i[8] = haswin_readvduvariable(VDUVAR_ScreenXsize);
  184.                 buff.i[9] = haswin_readvduvariable(VDUVAR_ScreenYsize);
  185.                 regs.r[1] = (int)&buff;
  186.                 if (haswin_swi(HASWIN_Drag_box, ®s))
  187.                         haswin_flags |= HASWIN_FLAGS_DRAG;
  188.                 else
  189.                         return(HASWIN_FALSE);
  190.        } else if ((int)wptr > 0) {
  191.                 adjx = ((int *)(wptr->win))[0] -
  192.                        ((int *)(wptr->win))[4];
  193.                 adjy = ((int *)(wptr->win))[3] -
  194.                        ((int *)(wptr->win))[5];
  195.                 buff.i[0] = pbuf->i[3];
  196.                 buff.i[1] = pbuf->i[4];
  197.                 regs.r[1] = (int)&buff;
  198.                 haswin_swi(HASWIN_Get_icon_state, ®s);
  199.                 buff.i[0] = pbuf->i[3];
  200.                 buff.i[1] = 5;
  201.                 buff.i[2] += adjx;
  202.                 buff.i[3] += adjy;
  203.                 buff.i[4] += adjx;
  204.                 buff.i[5] += adjy;
  205.                 buff.i[6] = 0;
  206.                 buff.i[7] = 0;
  207.                 buff.i[8] = haswin_readvduvariable(VDUVAR_ScreenXsize);
  208.                 buff.i[9] = haswin_readvduvariable(VDUVAR_ScreenYsize);
  209.                 regs.r[1] = (int)&buff;
  210.                 if (haswin_swi(HASWIN_Drag_box, ®s))
  211.                         haswin_flags |= HASWIN_FLAGS_DRAG;
  212.                 else
  213.                         return(HASWIN_FALSE);
  214.         }
  215.         return(HASWIN_TRUE);
  216. }
  217.  
  218. /*
  219.  *      Mouse click routine.
  220.  */
  221. int haswin_poll_mouse(int (*user)(int, buffer *), buffer *pbuf) {
  222.  
  223.         window  *wptr;
  224.         icon    *iptr;
  225.         pointer *mouse;
  226.         buffer  buff;
  227.  
  228.         wptr = haswin_findwindowhandle(pbuf->i[3]);
  229.         iptr = haswin_findiconhandle(wptr, pbuf->i[4]);
  230.         pbuf->i[6] = (int)wptr;
  231.         pbuf->i[7] = (int)iptr;
  232.         pbuf->i[8] = haswin_buttonWIMPtoHASWIN(wptr, iptr, pbuf->i[2]);
  233.         /* first try to get around the whole process by passing it on
  234.            to the user routine */
  235.         if ((user) && (!((*user)(HASWIN_POLL_Mouse, pbuf))))
  236.                 return(HASWIN_TRUE);  /* user processed it, so complete */
  237.         if ((pbuf->i[3] == -1) && (pbuf->i[4] == -1)) {
  238.                 haswin_internalerror("cannot handle mouse press, no window or icon");
  239.                 return(HASWIN_TRUE);  /* cannot process it, so complete */
  240.         }
  241.         switch (pbuf->i[8]) {
  242.         case HASWIN_MOUSE_L:
  243.                 /*
  244.                  * select action (fall through items until "return" is done)
  245.                  *
  246.                  * mouse in icon...
  247.                  *        if window to open
  248.                  *                open or close it
  249.                  *                if ICON_DOCODE flag == 0 return
  250.                  *        if icon routine to do
  251.                  *                do it
  252.                  *        try to drag icon, if successful return.
  253.                  * mouse in window...
  254.                  *        if text flag on in window and not in icon as well
  255.                  *                move text cursor.
  256.                  *                if WINDOW_DOCODE flag == 0 return
  257.                  *        else if caret to move and not in icon as well
  258.                  *                move it
  259.                  *                if WINDOW_DOCODE flag == 0 return
  260.                  *        if window routine to do
  261.                  *                do it, return
  262.                  *        try to drag window, if successful return.
  263.                  * display error message.
  264.                  * return.
  265.                  */
  266.                 if ((int)iptr > 0) {
  267.                         /* mouse on icon in icon bar or window */
  268.                         if (iptr->window) {
  269.                                 /* we have a window, so open it */
  270. /* inform the userpoll routine that a window is about to be opened */
  271.                                 haswin_updatewindowinfo(iptr->window);
  272.                                 buff.i[0]=iptr->window->handle;
  273.                                 buff.i[1]=haswin_getwindowxmin(iptr->window);
  274.                                 buff.i[2]=haswin_getwindowymin(iptr->window);
  275.                                 buff.i[3]=haswin_getwindowxmax(iptr->window);
  276.                                 buff.i[4]=haswin_getwindowymax(iptr->window);
  277.                                 buff.i[5]=haswin_getwindowxscroll(iptr->window);
  278.                                 buff.i[6]=haswin_getwindowyscroll(iptr->window);
  279.                                 buff.i[7]=haswin_getwindowbhandle(iptr->window);
  280.                                 buff.i[8]=(int)iptr->window;
  281.                                 if (haswin_getwindowflags(iptr->window) & WINDOW_OPEN) {
  282.                                         if ((user) && (!(*user)(HASWIN_POLL_poll_Close, &buff)))
  283.                                                 return(HASWIN_FALSE);
  284.                                         haswin_closewindow(iptr->window);
  285.                                 } else {
  286.                                         if ((user) && (!(*user)(HASWIN_POLL_poll_Open, &buff)))
  287.                                                 return(HASWIN_FALSE);
  288.                                         haswin_openwindow(iptr->window, buff.i[1], buff.i[2], buff.i[3], buff.i[4], buff.i[5], buff.i[6], buff.i[7]);
  289.                                 }
  290.                                 if (!(haswin_geticonflags(iptr)&ICON_DOCODE))
  291.                                         return(HASWIN_TRUE);
  292.                                 if (iptr->mousebutton)
  293.                                         return((*iptr->mousebutton)(iptr, pbuf));
  294.                                 return(HASWIN_TRUE);
  295.                         }
  296.                         if (iptr->mousebutton) {
  297.                                 if ((*iptr->mousebutton)(iptr, pbuf))
  298.                                         return(HASWIN_TRUE);
  299.                         }
  300.                         if (tryleftdrag(wptr, iptr, pbuf, HASWIN_FALSE))
  301.                                 return(HASWIN_TRUE);
  302.                 }
  303.                 /* try an action for the window, no icon */
  304.                 if ((int)wptr > 0) {
  305.                         if ((wptr->text) && (!iptr) && (haswin_getwindowflags(wptr)&WINDOW_AUTOTEXT) && (wptr->text->text)) {
  306.                                 mouse = haswin_getpointerinfo(0);
  307.                                 haswin_textmove(wptr,
  308.                                    haswin_convertscrxtotxt(wptr,mouse->mx),
  309.                                    haswin_convertscrytotxt(wptr,mouse->my));
  310.                                 haswin_freeptr(&mouse);
  311.                                 if (!(haswin_getwindowflags(wptr) & WINDOW_DOCODE))
  312.                                         return(HASWIN_TRUE);
  313.                         } else if ((wptr->caret) && (!iptr)) {
  314.                                 /* we have a caret so move it to the
  315.                                    mouse (only if not under an icon) */
  316.                                 mouse = haswin_getpointerinfo(0);
  317.                                 wptr->caret->win = mouse->win;
  318.                                 wptr->caret->ic = (icon *)(-1);
  319.                                 wptr->caret->x = haswin_convertscrxtowin(wptr, mouse->mx);
  320.                                 wptr->caret->y = haswin_convertscrytowin(wptr, mouse->my);
  321.                                 haswin_freeptr(&mouse);
  322.                                 haswin_setcaret(wptr->caret);
  323.                                 if (!(haswin_getwindowflags(wptr) & WINDOW_DOCODE))
  324.                                         return(HASWIN_TRUE);
  325.                         }
  326.                         if (wptr->mousebutton) {
  327.                                 if ((*wptr->mousebutton)(wptr, pbuf))
  328.                                         return(HASWIN_TRUE);
  329.                         }
  330.                         if (tryleftdrag(wptr, iptr, pbuf, HASWIN_FALSE))
  331.                                 return(HASWIN_TRUE);
  332.                         if (((int)iptr > 0) && (iptr->mousebutton))
  333.                                 return(HASWIN_TRUE);
  334.                         if ((int)iptr > 0)
  335.                                 haswin_internalerror("this icon has no select action");
  336.                         else
  337.                                 haswin_internalerror("this window has no select action");
  338.                         return(HASWIN_FALSE);
  339.                 }
  340.                 haswin_internalerror("this non HASWIN window has no select action");
  341.                 break;
  342.         case HASWIN_MOUSE_M:
  343.                 /*
  344.                  * menu action (fall through items until "return" is done)
  345.                  * mouse in icon...
  346.                  *        if menu to open
  347.                  *                open it
  348.                  *                if ICON_DOCODE flag == 0 return
  349.                  *        if icon routine to do
  350.                  *                do it and if successful return
  351.                  *        try to create a menu for the icon automatically
  352.                  *        (Help, Quit, Window, Info, Files, etc. fields)
  353.                  *        and if this is successful return.
  354.                  * mouse in window...
  355.                  *        if menu to open
  356.                  *                open it
  357.                  *                if WINDOW_DOCODE flag == 0 return
  358.                  *        if window routine to do
  359.                  *                do it and if successful return
  360.                  *        try to create a menu for the window automatically
  361.                  *        (Help, Quit, Window, Info, Files, etc. fields)
  362.                  *        and if this is successful return.
  363.                  * display error message.
  364.                  * return.
  365.                  */
  366. /* inform the userpoll routine that a menu is about to be opened */
  367.                 if ((user) && (!(*user)(HASWIN_POLL_poll_Menu, pbuf)))
  368.                         return(HASWIN_TRUE);
  369.                 if ((int)iptr > 0) {
  370.                         /* icon on icon bar or window */
  371.                         if (iptr->menu) {
  372.                                 /* we have a menu */
  373.                                 iptr->menu->wfrom=pbuf->i[3];
  374.                                 iptr->menu->ifrom=pbuf->i[4];
  375.                                 if ((iptr->menu->makemenu) &&
  376.                                     (!(*iptr->menu->makemenu)(iptr->menu)))
  377.                                         return(HASWIN_TRUE);
  378.                                 if (haswin_createmenu(wptr, iptr, 0, 0,
  379.                                                    pbuf->i[0]-iptr->menu->x,
  380.                                                    pbuf->i[1]+iptr->menu->y))
  381.                                         if (!(haswin_geticonflags(iptr)&ICON_DOCODE))
  382.                                                 return(HASWIN_TRUE);
  383.                         }
  384.                         if (iptr->mousebutton) {
  385.                                 if ((*iptr->mousebutton)(iptr, pbuf))
  386.                                         return(HASWIN_TRUE);
  387.                         }
  388.                         if (haswin_createmenu(wptr, iptr, 0, 0, pbuf->i[0],
  389.                                               pbuf->i[1]))
  390.                                 return(HASWIN_TRUE);
  391.                 }
  392.                 /* try an action for the window, no icon */
  393.                 if ((int)wptr > 0) {
  394.                         if (wptr->menu) {
  395.                                 wptr->menu->wfrom = pbuf->i[3];
  396.                                 wptr->menu->ifrom = -1;
  397.                                 if ((wptr->menu->makemenu) &&
  398.                                     (!(*wptr->menu->makemenu)(wptr->menu)))
  399.                                         return(HASWIN_TRUE);
  400.                                 if (haswin_createmenu(wptr, 0, 0, 0,
  401.                                                    pbuf->i[0]-wptr->menu->x,
  402.                                                    pbuf->i[1]+wptr->menu->y))
  403.                                         if (!(haswin_geticonflags(iptr)&ICON_DOCODE))
  404.                                                 return(HASWIN_TRUE);
  405.                         }
  406.                         if (wptr->mousebutton) {
  407.                                 if ((*wptr->mousebutton)(wptr, pbuf))
  408.                                         return(HASWIN_TRUE);
  409.                         }
  410.                         if (haswin_createmenu(wptr, 0, 0, 0, pbuf->i[0],
  411.                                                              pbuf->i[1]))
  412.                                 return(HASWIN_TRUE);
  413.                         if ((((int)iptr > 0) && (iptr->mousebutton)) ||
  414.                             (wptr->mousebutton))
  415.                                 return(HASWIN_TRUE);
  416.                         if (iptr)
  417.                                 haswin_internalerror("this icon has no menu action");
  418.                         else
  419.                                 haswin_internalerror("this window has no menu action");
  420.                         return(HASWIN_FALSE);
  421.                 }
  422.                 haswin_internalerror("this non HASWIN window has no menu action");
  423.                 return(HASWIN_FALSE);
  424.                 break;
  425.         case HASWIN_MOUSE_R:
  426.                 /*
  427.                  * adjust action (fall through items until "return" is done)
  428.                  * mouse in icon...
  429.                  *        if icon routine to do
  430.                  *                do it and if successful return
  431.                  *        try to drag icon, if successful return.
  432.                  * mouse in window...
  433.                  *        if window routine to do
  434.                  *                do it and if successful return
  435.                  *        try to drag window, if successful return.
  436.                  * display error message.
  437.                  * return.
  438.                  */
  439.                 if ((int)iptr > 0) {
  440.                         if (iptr->mousebutton) {
  441.                                 if ((*iptr->mousebutton)(iptr, pbuf))
  442.                                         return(HASWIN_TRUE);
  443.                         }
  444.                         if (tryrightdrag(wptr, iptr, pbuf, HASWIN_FALSE))
  445.                                 return(HASWIN_TRUE);
  446.                 }
  447.                 /* try an action for the window, no icon */
  448.                 if ((int)wptr > 0) {
  449.                         if ((wptr->mousebutton) &&
  450.                             (!(*wptr->mousebutton)(wptr, pbuf)))
  451.                                 return(HASWIN_TRUE);
  452.                         if (tryrightdrag(wptr, iptr, pbuf, HASWIN_FALSE))
  453.                                 return(HASWIN_TRUE);
  454.                         if (((iptr) && (iptr->mousebutton)) ||
  455.                             (wptr->mousebutton))
  456.                                 return(HASWIN_TRUE);
  457.                         if ((int)iptr > 0)
  458.                                 haswin_internalerror("this icon has no adjust action");
  459.                         else
  460.                                 haswin_internalerror("this window has no adjust action");
  461.                         return(HASWIN_FALSE);
  462.                 }
  463.                 break;
  464.         case HASWIN_MOUSE_LDRAG:
  465.                 /*
  466.                  *      select drag action, call the dragging routine
  467.                  */
  468.                 return(tryleftdrag(wptr, iptr, pbuf, HASWIN_TRUE));
  469.                 break;
  470.         case HASWIN_MOUSE_RDRAG:
  471.                 return(tryrightdrag(wptr, iptr, pbuf, HASWIN_TRUE));
  472.                 /*
  473.                  *      adjust drag action, call the dragging routine
  474.                  */
  475.                 break;
  476.         case HASWIN_MOUSE_LDOUB:
  477.                 /*
  478.                  * select double-click action (fall through items until
  479.                  * "return" is done)
  480.                  * mouse in icon...
  481.                  *        if icon routine to do
  482.                  *                do it and if successful return
  483.                  * mouse in window...
  484.                  *        if window routine to do
  485.                  *                do it and if successful return
  486.                  * display error message.
  487.                  * return.
  488.                  */
  489.                 if (((int)iptr > 0) && (iptr->mousebutton)) {
  490.                         if ((*iptr->mousebutton)(iptr, pbuf))
  491.                                 return(HASWIN_TRUE);
  492.                 }
  493.                 /* try an action for the window, no icon */
  494.                 if ((int)wptr > 0) {
  495.                         if (wptr->mousebutton) {
  496.                                 if ((*wptr->mousebutton)(wptr, pbuf))
  497.                                         return(HASWIN_TRUE);
  498.                         }
  499.                         if (((iptr) && (iptr->mousebutton)) ||
  500.                             (wptr->mousebutton))
  501.                                 return(HASWIN_TRUE);
  502.                         if ((int)iptr > 0)
  503.                                 haswin_internalerror("this icon has no select double-click action");
  504.                         else
  505.                                 haswin_internalerror("this window has no select double-click action");
  506.                         return(HASWIN_FALSE);
  507.                 }
  508.                 break;
  509.         case HASWIN_MOUSE_RDOUB:
  510.                 /*
  511.                  * adjust double-click action (fall through items until
  512.                  * "return" is done)
  513.                  * mouse in icon...
  514.                  *        if icon routine to do
  515.                  *                do it and if successful return
  516.                  * mouse in window...
  517.                  *        if window routine to do
  518.                  *                do it and if successful return
  519.                  * display error message.
  520.                  * return.
  521.                  */
  522.                 if (((int)iptr > 0) && (iptr->mousebutton)) {
  523.                         if ((*iptr->mousebutton)(iptr, pbuf))
  524.                                 return(HASWIN_TRUE);
  525.                 }
  526.                 /* try an action for the window, no icon */
  527.                 if ((int)wptr > 0) {
  528.                         if (wptr->mousebutton) {
  529.                                 if ((*wptr->mousebutton)(wptr, pbuf))
  530.                                         return(HASWIN_TRUE);
  531.                         }
  532.                         if (((iptr) && (iptr->mousebutton)) ||
  533.                             (wptr->mousebutton))
  534.                                 return(HASWIN_TRUE);
  535.                         if ((int)iptr > 0)
  536.                                 haswin_internalerror("this icon has no adjust double-click action");
  537.                         else
  538.                                 haswin_internalerror("this window has no adjust double-click action");
  539.                         return(HASWIN_FALSE);
  540.                 }
  541.                 break;
  542.         case 0:
  543.                 /*
  544.                  * position report action (fall through items until
  545.                  * "return" is done)
  546.                  * mouse in icon...
  547.                  *        if icon routine to do
  548.                  *                do it and if successful return
  549.                  * mouse in window...
  550.                  *        if window routine to do
  551.                  *                do it and if successful return
  552.                  * return.
  553.                  */
  554.                 if (((int)iptr > 0) && (iptr->mousebutton)) {
  555.                         if ((*iptr->mousebutton)(iptr, pbuf))
  556.                                 return(HASWIN_TRUE);
  557.                 }
  558.                 /* try an action for the window, no icon */
  559.                 if ((int)wptr > 0) {
  560.                         if (wptr->mousebutton) {
  561.                                 if ((*wptr->mousebutton)(wptr, pbuf))
  562.                                         return(HASWIN_TRUE);
  563.                         }
  564.                         return(HASWIN_FALSE);
  565.                 }
  566.                 break;
  567.         default:
  568.                 haswin_interrorprintf("illegal mouse button action %4.4X", pbuf->i[2]);
  569.                 return(HASWIN_TRUE);
  570.                 break;
  571.         }
  572.         return(HASWIN_TRUE);
  573. }
  574.  
  575. int haswin_poll_scroll(int (*user)(int, buffer *), buffer *pbuf) {
  576.  
  577.         int                     charx, chary;
  578.         window                  *wptr;
  579.         _kernel_swi_regs        regs;
  580.  
  581.         charx = haswin_readvduvariable(VDUVAR_CharXsize);
  582.         chary = haswin_readvduvariable(VDUVAR_CharYsize);
  583.         wptr = haswin_findwindowhandle(pbuf->i[0]);
  584.         pbuf->i[10] = (int)wptr;
  585.         if ((user) && (!((*user)(HASWIN_POLL_Scroll, pbuf))))
  586.                 return(HASWIN_FALSE);
  587.         if ((int)wptr <= 0) {
  588.                 switch (pbuf->i[8]) {    /* perform the X scroll */
  589.                 case -2:
  590.                          pbuf->i[5] -= pbuf->i[3]-pbuf->i[1];
  591.                          break;
  592.                 case -1:
  593.                          pbuf->i[5] -= charx;
  594.                          break;
  595.                 case  1:
  596.                          pbuf->i[5] += charx;
  597.                          break;
  598.                 case  2:
  599.                          pbuf->i[5] += pbuf->i[3]-pbuf->i[1];
  600.                          break;
  601.                 }
  602.                 switch (pbuf->i[9]) {    /* perform the Y scroll */
  603.                 case -2:
  604.                          pbuf->i[6] -= pbuf->i[4]-pbuf->i[2];
  605.                          break;
  606.                 case -1:
  607.                          pbuf->i[6] -= chary;
  608.                          break;
  609.                 case  1:
  610.                          pbuf->i[6] += chary;
  611.                          break;
  612.                 case  2:
  613.                          pbuf->i[6] += pbuf->i[4]-pbuf->i[2];
  614.                          break;
  615.                 }
  616.         } else {
  617.                 switch (pbuf->i[8]) {    /* perform the X scroll */
  618.                 case -2:
  619.                          if (wptr->pagex)
  620.                                  pbuf->i[5] -= wptr->pagex;
  621.                          else
  622.                                  pbuf->i[5] -= pbuf->i[3]-pbuf->i[1];
  623.                          break;
  624.                 case -1:
  625.                          if (wptr->scrollx)
  626.                                  pbuf->i[5] -= wptr->scrollx;
  627.                          else
  628.                                  pbuf->i[5] -= charx;
  629.                          break;
  630.                 case  1:
  631.                          if (wptr->scrollx)
  632.                                  pbuf->i[5] += wptr->scrollx;
  633.                          else
  634.                                  pbuf->i[5] += charx;
  635.                          break;
  636.                 case  2:
  637.                          if (wptr->pagex)
  638.                                  pbuf->i[5] += wptr->pagex;
  639.                          else
  640.                                  pbuf->i[5] += pbuf->i[3]-pbuf->i[1];
  641.                          break;
  642.                 }
  643.                 switch (pbuf->i[9]) {    /* perform the Y scroll */
  644.                 case -2:
  645.                          if (wptr->pagey)
  646.                                  pbuf->i[6] -= wptr->pagey;
  647.                          else
  648.                                  pbuf->i[6] -= pbuf->i[4]-pbuf->i[2];
  649.                          break;
  650.                 case -1:
  651.                          if (wptr->scrolly)
  652.                                  pbuf->i[6] -= wptr->scrolly;
  653.                          else
  654.                                  pbuf->i[6] -= chary;
  655.                          break;
  656.                 case  1:
  657.                          if (wptr->scrolly)
  658.                                  pbuf->i[6] += wptr->scrolly;
  659.                          else
  660.                                  pbuf->i[6] += chary;
  661.                          break;
  662.                 case  2:
  663.                          if (wptr->pagey)
  664.                                  pbuf->i[6] += wptr->pagey;
  665.                          else
  666.                                  pbuf->i[6] += pbuf->i[4]-pbuf->i[2];
  667.                          break;
  668.                 }
  669.         }
  670.         if ((user) && (!((*user)(HASWIN_POLL_Scrolled, pbuf))))
  671.                 return(HASWIN_FALSE);
  672.         if (((int)wptr > 0) && (*wptr->openroutine) &&
  673.             (!((*wptr->openroutine)(wptr, pbuf))))
  674.                 return(HASWIN_FALSE);
  675.         if ((int)wptr > 0) {
  676.                 regs.r[1] = (int)pbuf;
  677.                 return(haswin_swi(HASWIN_Open_window, ®s));
  678.         }
  679.         return(HASWIN_TRUE);
  680. }
  681.  
  682.