home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / xaes_new / formdial.c < prev    next >
C/C++ Source or Header  |  1994-12-11  |  13KB  |  425 lines

  1. /********************************************************************
  2.  *                                                                1.10*
  3.  *    XAES: Dialog-forming library                                    *
  4.  *    by Ken Hollis                                                    *
  5.  *                                                                    *
  6.  *    Copyright (c) 1994, Bitgate Software.  All Rights Reserved.        *
  7.  *                                                                    *
  8.  *    This is that type of module that desperately cries out, "PLEASE!*
  9.  *    OPTIMIZE ME!"  It shall be done soon...  I just need to get        *
  10.  *    around to speeding things up in the next release...                *
  11.  *                                                                    *
  12.  ********************************************************************/
  13.  
  14. #include "xaes.h"
  15.  
  16. GLOBAL void Objc_Change(WINDOW *win, int ob_cobject, int ob_crecvd, int ob_cnewstate, int ob_credraw)
  17. {
  18.     if (win)
  19.         if (win->tree || win->iconify) {
  20.         objc_change((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), ob_cobject, ob_crecvd, 0, 0, 0, 0, ob_cnewstate, 0);
  21.  
  22.         if ((ob_credraw) && (win->state & W_OPEN)) {
  23.             GRECT own, temp;
  24.             int x, y, tx, ty, tw, th;
  25.  
  26.             WMoveWindow(win, -1, -1, -1, -1);
  27.  
  28.             objc_offset((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), ob_cobject, &x, &y);
  29.             wind_get(win->handle, WF_WORKXYWH, &tx, &ty, &tw, &th);
  30.  
  31.             if (win->style & W_CUSTOMWINDOW) {
  32.                 if (win->wind_type == WC_WINDOW) {
  33.                     own.g_x = tx + win->wind[25].ob_x - 1;
  34.                     own.g_y = ty + win->wind[25].ob_y - 1;
  35.                     own.g_w = win->wind[25].ob_width + 1;
  36.                     own.g_h = win->wind[25].ob_height + 1;
  37.                 }
  38.  
  39.                 if (win->wind_type == WC_SWINDOW) {
  40.                     own.g_x = tx + win->wind[32].ob_x - 1;
  41.                     own.g_y = ty + win->wind[32].ob_y - 1;
  42.                     own.g_w = win->wind[32].ob_width + 1;
  43.                     own.g_h = win->wind[32].ob_height + 1;
  44.                 }
  45.             } else {
  46.                 own.g_x = tx;
  47.                 own.g_y = ty;
  48.                 own.g_w = tw;
  49.                 own.g_h = th;
  50.             }
  51.  
  52.             wind_update(BEG_UPDATE);
  53.  
  54.             WWindGet(win, WF_FIRSTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  55.             WMoveWindow(win, -1, -1, -1, -1);
  56.  
  57.             while (temp.g_w && temp.g_h) {
  58.                 if (rc_intersect(&temp, &own)) {
  59.                     switch ((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[ob_cobject].ob_type & 0xFF : win->tree[ob_cobject].ob_type & 0xFF)) {
  60.                         case G_BUTTON:
  61.                         case G_USERDEF:
  62.                         case G_BOXCHAR:
  63.                         case G_BOX:
  64.                         case G_STRING:
  65.                         case G_IMAGE:
  66.                             if (ob_cobject == 0)
  67.                                 objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), 0, 99, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  68.                             else
  69.                                 objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), ob_cobject, 2, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  70.  
  71.                             break;
  72.  
  73.                         default:
  74.                             if ((ob_cobject == 0) || ((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[ob_cobject].ob_type & 0x0F : win->tree[ob_cobject].ob_type & 0x0F)) == G_IMAGE)
  75.                                 objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), 0, 99, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  76.                             else
  77.                                 objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), ob_cobject, 2, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  78.  
  79.                             break;
  80.                     }
  81.                 }
  82.  
  83.                 WWindGet(win, WF_NEXTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  84.             }
  85.  
  86.             wind_update(END_UPDATE);
  87.         }
  88.  
  89.         WMoveWindow(win, -1, -1, -1, -1);
  90.     }
  91. }
  92.  
  93. GLOBAL void WObjc_Change(WINDOW *win, int ob_cobject, int ob_crecvd, int ob_cnewstate, int ob_credraw)
  94. {
  95.     if (win)
  96.         if (win->style & W_CUSTOMWINDOW) {
  97.             objc_change(win->wind, ob_cobject, ob_crecvd, 0, 0, 0, 0, ob_cnewstate, 0);
  98.  
  99.             if ((ob_credraw) && (win->state & W_OPEN)) {
  100.                 GRECT own, temp;
  101.                 int x, y, tx, ty, tw, th;
  102.  
  103.                 objc_offset(win->wind, ob_cobject, &x, &y);
  104.                 wind_get(win->handle, WF_WORKXYWH, &tx, &ty, &tw, &th);
  105.  
  106.                 own.g_x = tx;
  107.                 own.g_y = ty;
  108.                 own.g_w = tx + tw;
  109.                 own.g_h = ty + th;
  110.  
  111.                 wind_update(BEG_UPDATE);
  112.  
  113.                 WWindGet(win, WF_FIRSTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  114.                 WMoveWindow(win, -1, -1, -1, -1);
  115.  
  116.                 while (temp.g_w && temp.g_h) {
  117.                     if (rc_intersect(&temp, &own))
  118.                         switch (win->wind[ob_cobject].ob_type & 0xff) {
  119.                             case G_BUTTON:
  120.                             case G_USERDEF:
  121.                             case G_BOXCHAR:
  122.                             case G_BOX:
  123.                             case G_STRING:
  124.                             case G_IMAGE:
  125.                                 if (ob_cobject == 0)
  126.                                     objc_draw(win->wind, 0, 7, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  127.                                 else
  128.                                     objc_draw(win->wind, ob_cobject, 7, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  129.                                 break;
  130.  
  131.                             default:
  132.                                 if ((ob_cobject == 0) || ((win->wind[ob_cobject].ob_type & 0x0F) == G_IMAGE))
  133.                                     objc_draw(win->wind, 0, 7, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  134.                                 else
  135.                                     objc_draw(win->wind, ob_cobject, 7, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  136.                                 break;
  137.                         }
  138.  
  139.                     WWindGet(win, WF_NEXTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  140.                 }
  141.  
  142.                 wind_update(END_UPDATE);
  143.             }
  144.         }
  145.  
  146.         WMoveWindow(win, -1, -1, -1, -1);
  147. }
  148.  
  149. GLOBAL int WForm_button(WINDOW *win, int obj, int clicks, int *nxtobj)
  150. {
  151.     OBJECT *tree, *obptr;
  152.     int flags, state;
  153.  
  154.     if (win) {
  155.         if ((clicks == 2) && (*nxtobj == win->icon_num))
  156.             WWindSet(win, WF_UNICONIFIED, 1);
  157.         else {
  158.         WMoveWindow(win, -1, -1, -1, -1);
  159.  
  160.         tree = (((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree);
  161.         obptr = tree + obj;
  162.         flags = obptr->ob_flags;
  163.         state = obptr->ob_state;
  164.  
  165.         if (helpmode) {
  166.             WCallBHelpDispatcher(win, obj);
  167.             return 1;
  168.         }
  169.  
  170.         wind_update(BEG_MCTRL);
  171.  
  172.         if (clicks == 2) {}
  173.         if (clicks == 3) {}
  174.         if ((flags & SELECTABLE) && ! (state & DISABLED)) {
  175.             *nxtobj = obj;
  176.  
  177.             if ((flags & RBUTTON) && (state & SELECTED))
  178.                 no_click();
  179.             else {
  180.                 state ^= SELECTED;
  181.                 if (flags & (RBUTTON | TOUCHEXIT)) {
  182.                     if (flags & SELECTABLE)
  183.                         Objc_Change(win, obj, 0, state, 1);
  184.  
  185.                     if (flags & TOUCHEXIT) {
  186.                         int d, button;
  187.  
  188.                         do {
  189.                             graf_mkstate(&d, &d, &button, &d);
  190.                             switch((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[obj].ob_type >> 8 : win->tree[obj].ob_type >> 8)) {
  191.                                 case SLIDERLEFT:
  192.                                 case SLIDERRIGHT:
  193.                                 case SLIDERUP:
  194.                                 case SLIDERDOWN:
  195.                                 case SLIDERTRACK:
  196.                                     WHandleSlider(win, obj);
  197.                                     break;
  198.  
  199.                                 case SLIDERSLIDE:
  200.                                     if (xaes.config1 & X_MOUSESLIDERS) {
  201.                                         EXTINFO *ex = (EXTINFO *)((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[obj].ob_spec.userblk->ub_parm : win->tree[obj].ob_spec.userblk->ub_parm));
  202.  
  203.                                         if (ex->te_slider.slide_type == SLIDER_HOR)
  204.                                             WGrafMouse(LRSLIDE_MOUSE);
  205.                                         if (ex->te_slider.slide_type == SLIDER_VER)
  206.                                             WGrafMouse(UDSLIDE_MOUSE);
  207.                                     }
  208.  
  209.                                     WHandleSlider(win, obj);
  210.                                     break;
  211.                             }
  212.  
  213.                             WCallDlgDispatcher(win, obj);
  214.                         } while(button);
  215.  
  216.                         WGrafMouse(ARROW);
  217.                     }
  218.  
  219.                     if (flags & RBUTTON) {
  220.                         register int act = obj, lst, new;
  221.  
  222.                         for (;;) {
  223.                             lst = act;
  224.                             new = obptr->ob_next;
  225.  
  226.                             for (;;) {
  227.                                 act = new;
  228.                                 obptr = tree + act;
  229.  
  230.                                 if (obptr->ob_tail == lst) {
  231.                                     new = obptr->ob_head;
  232.                                     lst = act;
  233.                                 } else {
  234.                                     if (act == obj)
  235.                                         goto rb_exit;
  236.  
  237.                                     if ((obptr->ob_state & SELECTED) && (obptr->ob_flags & RBUTTON)) {
  238.                                         Objc_Change(win, act, 0, obptr->ob_state ^ SELECTED, 1);
  239.                                         goto rb_exit;
  240.                                     } else
  241.                                         break;
  242.                                 }
  243.                             }
  244.                         }
  245. rb_exit:                no_click();
  246.                     }
  247.                 } else {
  248.                     register OBJECT *ob = tree + obj;
  249.                     EVENT event;
  250.                     int x, y, dummy, events;
  251.  
  252.                     event.ev_mflags = MU_BUTTON | MU_M1;
  253.                     event.ev_mbclicks = 1;
  254.                     event.ev_bmask = 0x11;
  255.                     event.ev_mbstate = 0;
  256.  
  257.                     objc_offset(tree, obj, &event.ev_mm1x, &event.ev_mm1y);
  258.                     event.ev_mm1width = ob->ob_width;
  259.                     event.ev_mm1height = ob->ob_height;
  260.  
  261.                     graf_mkstate(&x, &y, &dummy, &dummy);
  262.                     if (rc_inside(x, y, (GRECT *) &event.ev_mm1x)) {
  263.                         event.ev_mm1flags = 1;
  264.                         Objc_Change(win, obj, 0, ob->ob_state ^ SELECTED, 1);
  265.                     } else
  266.                         event.ev_mm1flags = 0;
  267.  
  268.                     do {
  269.                         events = EvntMulti(&event);
  270.                         if (events & MU_M1)    {
  271.                             event.ev_mm1flags = 1 - event.ev_mm1flags;
  272.                             Objc_Change(win, obj, 0, ob->ob_state ^ SELECTED, 1);
  273.                         }
  274.                     } while (!(events & MU_BUTTON));
  275.  
  276.                     if (!(ob->ob_state & SELECTED))
  277.                         *nxtobj = 0;
  278.                 }
  279.             }
  280.         } else
  281.             if (flags & EDITABLE)
  282.                 *nxtobj = obj;
  283.             else
  284.                 *nxtobj = 0;
  285.  
  286.         wind_update(END_MCTRL);
  287.  
  288.         if (*nxtobj)
  289.             if ((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[*nxtobj].ob_flags & (EXIT | TOUCHEXIT) : win->tree[*nxtobj].ob_flags & (EXIT | TOUCHEXIT)))
  290.                 return 0;
  291.         }
  292.     }
  293.  
  294.     return 1;
  295. }
  296.  
  297. GLOBAL void WUpdateWindow(WINDOW *win, int x, int y, int w, int h, int obj)
  298. {
  299.     GRECT own, temp;
  300.  
  301.     if (win) {
  302.         WMoveWindow(win, -1, -1, -1, -1);
  303.  
  304.         own.g_x = x;
  305.         own.g_y = y;
  306.         own.g_w = w;
  307.         own.g_h = h;
  308.  
  309.         wind_update(BEG_UPDATE);
  310.         wind_update(BEG_MCTRL);
  311.  
  312.         WWindGet(win, WF_FIRSTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  313.         WMoveWindow(win, -1, -1, -1, -1);
  314.  
  315.         while (temp.g_w && temp.g_h) {
  316.             if (rc_intersect(&temp, &own))
  317.                 if (obj == 0)
  318.                     if ((win->wind) && (win->style & W_CUSTOMWINDOW)) {
  319.                         objc_draw(win->wind, 0, 7, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  320.                         objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), 0, 99, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  321.                     } else if (((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree)) && !(win->style & W_CUSTOMWINDOW))
  322.                         objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), 0, 99, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  323.                 else
  324.                     if ((win->wind) && (win->style & W_CUSTOMWINDOW))
  325.                         objc_draw(win->wind, obj, 7, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  326.                     else if (((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree)) && !(win->style & W_CUSTOMWINDOW))
  327.                         objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), obj, 99, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  328.  
  329.             WWindGet(win, WF_NEXTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  330.         }
  331.  
  332.         wind_update(END_MCTRL);
  333.         wind_update(END_UPDATE);
  334.     }
  335.  
  336.     WMoveWindow(win, -1, -1, -1, -1);
  337. }
  338.  
  339. GLOBAL void WUpdateWindowDlg(WINDOW *win, int obj)
  340. {
  341.     GRECT own, temp;
  342.     int tx, ty, tw, th;
  343.  
  344.     if (win) {
  345.         WMoveWindow(win, -1, -1, -1, -1);
  346.  
  347.         if (win->state & W_OPEN) {
  348.             wind_get(win->handle, WF_WORKXYWH, &tx, &ty, &tw, &th);
  349.  
  350.             if (obj == 0)
  351.                 if (win->style & W_CUSTOMWINDOW) {
  352.                     if (win->wind_type == WC_WINDOW) {
  353.                         own.g_x = tx + win->wind[25].ob_x - 1;
  354.                         own.g_y = ty + win->wind[25].ob_y - 1;
  355.                         own.g_w = win->wind[25].ob_width + 1;
  356.                         own.g_h = win->wind[25].ob_height + 1;
  357.                     }
  358.  
  359.                     if (win->wind_type == WC_SWINDOW) {
  360.                         own.g_x = tx + win->wind[32].ob_x - 1;
  361.                         own.g_y = ty + win->wind[32].ob_y - 1;
  362.                         own.g_w = win->wind[32].ob_width + 1;
  363.                         own.g_h = win->wind[32].ob_height + 1;
  364.                     }
  365.                 } else {
  366.                     own.g_x = tx;
  367.                     own.g_y = ty;
  368.                     own.g_w = tw;
  369.                     own.g_h = th;
  370.                 }
  371.             else {
  372.                 own.g_x = tx + (((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[obj].ob_x - 1 : win->tree[obj].ob_x - 1);
  373.                 own.g_y = ty + (((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[obj].ob_y - 1 : win->tree[obj].ob_y - 1);
  374.                 own.g_w = (((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[obj].ob_width + 1 : win->tree[obj].ob_width + 1);
  375.                 own.g_h = (((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify[obj].ob_height + 1 : win->tree[obj].ob_height + 1);
  376.             }
  377.  
  378.             wind_update(BEG_UPDATE);
  379.             wind_update(BEG_MCTRL);
  380.  
  381.             WWindGet(win, WF_FIRSTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  382.             WMoveWindow(win, -1, -1, -1, -1);
  383.  
  384.             while (temp.g_w && temp.g_h) {
  385.                 if (rc_intersect(&temp, &own))
  386.                     if (obj != 0)
  387.                         if ((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree))
  388.                             objc_draw((((win->state & W_ICONIFIED) && (win->iconify)) ? win->iconify : win->tree), obj, 99, temp.g_x, temp.g_y, temp.g_w, temp.g_h);
  389.  
  390.                 WWindGet(win, WF_NEXTXYWH, &temp.g_x, &temp.g_y, &temp.g_w, &temp.g_h);
  391.             }
  392.  
  393.             wind_update(END_MCTRL);
  394.             wind_update(END_UPDATE);
  395.         }
  396.  
  397.         WMoveWindow(win, -1, -1, -1, -1);
  398.     }
  399. }
  400.  
  401. GLOBAL int rc_intersect(GRECT *r1, GRECT *r2)
  402. {
  403.     r1->g_w = min(r1->g_x + r1->g_w, r2->g_x + r2->g_w );
  404.     r1->g_h = min(r1->g_y + r1->g_h, r2->g_y + r2->g_h );
  405.     r1->g_x = max(r1->g_x, r2->g_x);
  406.     r1->g_y = max(r1->g_y, r2->g_y);
  407.     r1->g_w -= r1->g_x;
  408.     r1->g_h -= r1->g_y;
  409.     return (r1->g_w > 0 && r1->g_h > 0) ? TRUE : FALSE;
  410. }
  411.  
  412. GLOBAL int rc_inside(int x, int y, GRECT *r)
  413. {
  414.     return (x > r->g_x && x < (r->g_x + r->g_w) &&
  415.              y > r->g_y && y < (r->g_y + r->g_h));
  416. }
  417.  
  418. GLOBAL void no_click(void)
  419. {
  420.     int dummy, bstate;
  421.  
  422.     graf_mkstate(&dummy, &dummy, &bstate, &dummy);
  423.     if (bstate & 1)
  424.         evnt_button(1, 3, 0, &dummy, &dummy, &dummy, &dummy);
  425. }