home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / linkedit / linkedit.lha / link-edit / LinkEdit / Box / box_public.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-13  |  12.2 KB  |  686 lines

  1. /* public.c: routines for public access */
  2.  
  3. #include <stdio.h>
  4. #include <X11/Xlib.h>
  5. #include "box_types.h"
  6. #include "box_global.h"
  7.  
  8. /* Routines to get at box selections */
  9.  
  10.  
  11. BoxStateChange(status)
  12.  
  13. VOID *status;
  14.  
  15. {
  16.   BoxStatus *gnrc;
  17.  
  18.   gnrc = (BoxStatus *) status;
  19.  
  20.   if(gnrc->state_change == BOX_YES) {
  21.      gnrc->state_change = BOX_NO;
  22.      return(1);
  23.     }
  24.   else {
  25.      return(0);
  26.     }
  27. }
  28.  
  29. ExtractBoxTopWindow(status)
  30. VOID *status;
  31. {
  32.   BoxStatus *gnrc;
  33.   gnrc= (BoxStatus *) status;
  34.   return((int) (gnrc->TopWindow));
  35. }
  36.  
  37. ExtractBoxSelection(status,choice)
  38.  
  39. VOID *status;
  40. int *choice;
  41.  
  42. /* Returns the selection id heierarchy (derived from current_box)
  43.    in choice, which is assumed to have enough space.  Return value
  44.    is the number of choices.  */
  45.  
  46. {
  47.   BoxStatus *gnrc;
  48.   BoxList *bx;
  49.   int i,num;
  50.  
  51.   gnrc = (BoxStatus *) status;
  52.   bx = gnrc->select_box;
  53.   num = bx->generation;
  54.  
  55.   i = num-1;
  56.   while(bx !=  &(gnrc->box)) {
  57.       choice[i] = bx->id;
  58.       i--;
  59.       bx = bx->parent;
  60.      }
  61.   gnrc->select_box = &(gnrc->box);
  62.   return(num);
  63. }
  64.  
  65. ExtractBoxTextEntryText(status,id,buff)
  66.  
  67. VOID *status;
  68. int id;
  69. char *buff;
  70.  
  71. {
  72.   BoxStatus *gnrc;
  73.   BoxList *bx;
  74.  
  75.   gnrc = (BoxStatus *) status;
  76.   bx = FindBoxByID(gnrc,id);
  77.   if(bx->type != BOX_TEXT_ENTRY) return(-1);
  78.  
  79.   strcpy(buff,bx->dflt.text);
  80.   return(0);
  81. }
  82.  
  83. ExtractBoxSliderValue(status,id,value)
  84.  
  85. VOID *status;
  86. int id;
  87. double *value;
  88.  
  89. {
  90.   BoxStatus *gnrc;
  91.   BoxList *bx;
  92.  
  93.   gnrc = (BoxStatus *) status;
  94.   bx = FindBoxByID(gnrc,id);
  95.   if(bx->type != BOX_HORIZONTAL_SLIDER && bx->type != BOX_VERTICAL_SLIDER)
  96.      return(-1);
  97.  
  98.   *value = bx->value;
  99.   return(0);
  100. }
  101.  
  102.  
  103. ExtractBoxToggleState(status,id,boolean)
  104.  
  105. VOID *status;
  106. int id;
  107. int *boolean;
  108.  
  109. {
  110.   BoxStatus *gnrc;
  111.   BoxList *bx;
  112.  
  113.   gnrc = (BoxStatus *) status;
  114.   bx = FindBoxByID(gnrc,id);
  115.   if(bx->type !=  BOX_TOGGLE)
  116.      return(-1);
  117.  
  118.   if(bx->state == BOX_YES) *boolean = 1;
  119.   else *boolean = 0;
  120.   return(0);
  121. }
  122.  
  123. ExtractBoxDimensions(status,id,x,y,width,height)
  124.  
  125. VOID *status;
  126. int id;
  127. int *x,*y,*width,*height;
  128.  
  129. {
  130.   BoxStatus *gnrc;
  131.   BoxList *bx;
  132.  
  133.   gnrc = (BoxStatus *) status;
  134.   bx = FindBoxByID(gnrc,id);
  135.   *x = bx->x; *y = bx->y;
  136.   *width = bx->width; *height = bx->height;
  137.   return(0);
  138. }
  139.  
  140. /* Routines to modify essential box variables */
  141.  
  142.  
  143. ChangeBoxSliderValue(status,box_id,value)
  144.  
  145. VOID *status; int box_id; double value;
  146.  
  147. {
  148.   BoxStatus *gnrc;
  149.   BoxList *bx;
  150.  
  151.   gnrc = (BoxStatus *) status;
  152.   bx = FindBoxByID(gnrc,box_id);
  153.   if(bx->type != BOX_HORIZONTAL_SLIDER &&
  154.              bx->type != BOX_VERTICAL_SLIDER) {
  155.      fprintf(stderr,"Box not slider.\n"); return(0);
  156.     }
  157.   bx->value = value;
  158.   DrawBox(gnrc,bx);
  159. }
  160.  
  161.  
  162. ChangeBoxTextPrompt(status,box_id,prompt,attr_id)
  163.  
  164. VOID *status;
  165. int box_id,attr_id;
  166. char *prompt;
  167.  
  168. {
  169.   BoxStatus *gnrc;
  170.   BoxList *bx;
  171.   BoxAttributeList *attr;
  172.   TextList *txt;
  173.  
  174.   gnrc = (BoxStatus *) status;
  175.   bx = FindBoxByID(gnrc,box_id);
  176.   if(bx->type != BOX_TEXT_ENTRY) {
  177.      fprintf(stderr,"Box not text entry.\n"); return(0);
  178.     }
  179.   attr = FindBoxAttributeByID(gnrc,attr_id);
  180.   txt = &(bx->prompt);
  181.   strcpy(txt->text,prompt);
  182.   txt->x = BOX_PAD; txt->y = (bx->height + attr->fth)/2;
  183.   txt->attr = attr;
  184.   DrawBox(gnrc,bx);
  185. }
  186.  
  187.  
  188.  
  189. ChangeBoxTextDefault(status,box_id,dflt,attr_id)
  190.  
  191. VOID *status;
  192. int box_id,attr_id;
  193. char *dflt;
  194.  
  195. {
  196.   BoxStatus *gnrc;
  197.   BoxList *bx;
  198.   BoxAttributeList *attr;
  199.   TextList *txt;
  200.   char *strng;
  201.  
  202.   gnrc = (BoxStatus *) status;
  203.   bx = FindBoxByID(gnrc,box_id);
  204.   if(bx->type != BOX_TEXT_ENTRY) {
  205.      fprintf(stderr,"Box not text entry.\n"); return(0);
  206.     }
  207.   attr = FindBoxAttributeByID(gnrc,attr_id);
  208.   txt = &(bx->dflt);
  209.   strcpy(txt->text,dflt);
  210.   strng = bx->prompt.text;  /* Prompt string */
  211.   txt->x = BOX_PAD + XTextWidth(attr->fontstruct,strng,strlen(strng));
  212.   txt->y = (bx->height + attr->fth)/2;
  213.   txt->attr = attr;
  214.   DrawBox(gnrc,bx);
  215. }
  216.  
  217.  
  218. ChangeBoxToggleState(status,box_id,state)
  219.  
  220. VOID *status;
  221. int box_id,state;
  222.  
  223. {
  224.   BoxStatus *gnrc;
  225.   BoxList *bx,*parent,*child;
  226.  
  227.   gnrc = (BoxStatus *) status;
  228.   bx = FindBoxByID(gnrc,box_id);
  229.   if(bx->type != BOX_TOGGLE) {
  230.      fprintf(stderr,"Box not text entry.\n"); return(0);
  231.     }
  232.   if(state == 1) bx->state = BOX_YES;
  233.   else bx->state = BOX_NO;
  234.   DrawBox(gnrc,bx);
  235.  
  236.   /* check exclusivity of parent */
  237.   parent = bx->parent;
  238.   if(parent->exclusive == BOX_YES) {
  239.      child = parent->child;
  240.      while(child != NULL) {
  241.          if(child->state == BOX_YES && child != bx &&
  242.               child->type == BOX_TOGGLE) {
  243.             child->state = BOX_NO; DrawBox(gnrc,child);
  244.            }
  245.          child = child->sibling;
  246.         }
  247.     }
  248.  
  249. }
  250.  
  251.  
  252. /* Routines for external control of box selection and display */
  253.  
  254. SelectBoxByID(status,id)
  255.  
  256. VOID *status;
  257. int id;
  258.  
  259. {
  260.   BoxStatus *gnrc;
  261.   BoxList *bx;
  262.  
  263.   gnrc = (BoxStatus *) status;
  264.   if((bx = FindBoxByID(gnrc,id)) == NULL) {
  265.      BoxPrintMessage(gnrc,"Invalid box!.");
  266.     }
  267.  
  268.   /* Check if valid choice of box */
  269.   if(!BoxIsValidChoice(gnrc,bx)) {
  270.     BoxPrintMessage(gnrc,"Current selection must be completed.");
  271.     return(-1);
  272.    }
  273.  
  274.   BoxSelect(gnrc,bx);
  275. }
  276.  
  277. BoxPublicKeyPress(status,key)
  278.  
  279. VOID *status;
  280. char key;
  281.  
  282. {
  283.   BoxStatus *gnrc;
  284.  
  285.   gnrc = (BoxStatus *) status;
  286.   BoxKeyPress(gnrc,key);
  287.   
  288. }
  289.  
  290. DrawBoxByID(status,id)
  291.  
  292. VOID *status;
  293. int id;
  294.  
  295. {
  296.   BoxStatus *gnrc;
  297.   BoxList *bx;
  298.  
  299.   gnrc = (BoxStatus *) status;
  300.   bx = FindBoxByID(gnrc,id);
  301.   DrawBox(gnrc,bx);
  302. }
  303.  
  304.  
  305. CreateBox(status,type,x,y,width,height)
  306.  
  307. VOID *status;
  308. int type,x,y,width,height;
  309.  
  310. /* Routine creates a new box with default settings.  Returns the id */
  311. /* of the box, or -1 if an error condition is encountered */
  312.  
  313. {
  314.   BoxStatus *gnrc;
  315.   int id,length;
  316.   BoxList *bx;
  317.   TextList *txt;
  318.  
  319.   gnrc = (BoxStatus *) status;
  320.   id = 1;
  321.   bx = &(gnrc->box); 
  322.  
  323.   while(bx->next != NULL) {
  324.     id++;
  325.     bx = bx->next;
  326.    }
  327.  
  328.   bx->next = (BoxList *) malloc(sizeof(BoxList));
  329.   bx = bx->next;
  330.   if(bx == NULL) {
  331.     fprintf(stderr,"Unable to allocate space for new box.\n");
  332.     return(-1);
  333.    }
  334.  
  335.   bx->x = x; bx->y = y;
  336.   bx->width = width; bx->height = height;
  337.   
  338.   bx->type = type; bx->id = id;
  339.   bx->generation = 1; bx->visible = BOX_YES;
  340.   bx->state = BOX_NO; bx->border = BOX_YES; bx->key = '\0';  
  341.   bx->exclusive = BOX_NO; bx->always_visible = BOX_NO;
  342.   bx->induce_state_change = BOX_YES;
  343.   bx->cleanup = BOX_NO;
  344.   bx->stop_cleanup = BOX_NO;
  345.  
  346.   bx->next = NULL; bx->child = NULL; bx->sibling = NULL;
  347.   bx->friend = NULL; bx->parent = &(gnrc->box);
  348.  
  349.   bx->data = (VOID *) NULL;
  350.   bx->btmp.next = NULL;
  351.   bx->dsn.next = NULL;
  352.   bx->txt.next = NULL;
  353.   bx->local_callback = NULL;
  354.   bx->global_callback = NULL;
  355.   bx->continuous_local_callback = NULL;
  356.   bx->continuous_global_callback = NULL;
  357.   bx->global_arg = (VOID *) NULL;
  358.  
  359.   /* Type specific stuff */
  360.   switch(type) {
  361.      case BOX_MENU:
  362.        bx->cleanup = BOX_YES;
  363.      case  BOX_TEXT_ENTRY:  /* Create prompt and default */
  364.        bx->prompt.text[0] = '\0'; bx->prompt.attr = &(gnrc->attribute);
  365.        bx->dflt.text[0] = '\0'; bx->dflt.attr = &(gnrc->attribute);
  366.        break;
  367.  
  368.      case BOX_HORIZONTAL_SLIDER:
  369.      case BOX_VERTICAL_SLIDER:
  370.        bx->value = 0.5;
  371.        break;
  372.     }
  373.   return(id);
  374. }
  375.  
  376.  
  377.  
  378. ToggleBoxAlwaysVisible(status,id,boolean)
  379.  
  380. VOID *status; int id,boolean;
  381.  
  382. {
  383.   BoxStatus *gnrc;
  384.   BoxList *bx;
  385.  
  386.   gnrc = (BoxStatus *) status;
  387.   bx = FindBoxByID(gnrc,id);
  388.   bx->always_visible = boolean;
  389. }
  390.  
  391. ToggleBoxExclusive(status,id,boolean)
  392.  
  393. VOID *status; int id,boolean;
  394.  
  395. {
  396.   BoxStatus *gnrc;
  397.   BoxList *bx;
  398.  
  399.   gnrc = (BoxStatus *) status;
  400.   bx = FindBoxByID(gnrc,id);
  401.   bx->exclusive = boolean;
  402. }
  403.  
  404. ToggleBoxStopCleanup(status,id,boolean)
  405.  
  406. VOID *status; int id,boolean;
  407.  
  408. {
  409.   BoxStatus *gnrc;
  410.   BoxList *bx;
  411.  
  412.   gnrc = (BoxStatus *) status;
  413.   bx = FindBoxByID(gnrc,id);
  414.   bx->stop_cleanup = boolean;
  415. }
  416.  
  417. ToggleBoxCleanup(status,id,boolean)
  418.  
  419. VOID *status; int id,boolean;
  420.  
  421. {
  422.   BoxStatus *gnrc;
  423.   BoxList *bx;
  424.  
  425.   gnrc = (BoxStatus *) status;
  426.   bx = FindBoxByID(gnrc,id);
  427.   bx->cleanup = boolean;
  428. }
  429.  
  430. ToggleBoxInduceStateChange(status,id,boolean)
  431.  
  432. VOID *status; int id,boolean;
  433.  
  434. {
  435.   BoxStatus *gnrc;
  436.   BoxList *bx;
  437.  
  438.   gnrc = (BoxStatus *) status;
  439.   bx = FindBoxByID(gnrc,id);
  440.   bx->induce_state_change = boolean;
  441. }
  442.  
  443. ChangeBoxKey(status,box_id,key)
  444.  
  445. VOID *status; int box_id; char key;
  446.  
  447. {
  448.   BoxStatus *gnrc;
  449.   BoxList *bx;
  450.  
  451.   gnrc = (BoxStatus *) status;
  452.   bx = FindBoxByID(gnrc,box_id);
  453.   bx->key = key;
  454. }
  455.  
  456.  
  457. AddBoxChild(status,child_id,parent_id) 
  458.  
  459. VOID *status;
  460. int child_id,parent_id;
  461.  
  462. {
  463.   BoxStatus *gnrc;
  464.   BoxList *child,*parent,*temp;
  465.  
  466.   gnrc = (BoxStatus *) status;
  467.  
  468.   child = FindBoxByID(gnrc,child_id);
  469.   parent = FindBoxByID(gnrc,parent_id);
  470.  
  471.   if(child == NULL || parent == NULL) {
  472.      fprintf(stderr,"Parent or child does not exist!\n");
  473.      return(0);
  474.     }
  475.  
  476.   child->parent = parent;
  477.   child->generation = 1 + parent->generation;
  478.   child->visible = BOX_NO; /* Default setting */
  479.  
  480.   if(parent->child == NULL) {
  481.      parent->child = child;
  482.     }
  483.   else { /* Add child to sibling list of last child */
  484.      temp = parent->child;
  485.      while(temp->sibling != NULL) {
  486.         temp = temp->sibling;
  487.         }
  488.      temp->sibling = child;
  489.     }
  490.  
  491.   /* Change some flags in parent */
  492.   switch(parent->type) {
  493.      case BOX_MENU:
  494.        parent->induce_state_change = BOX_NO;
  495.        parent->cleanup = BOX_NO;
  496.        break;
  497.     }
  498. }
  499.  
  500. AddBoxGlobalArg(status,id,arg)
  501.  
  502. VOID *status;
  503. int id;
  504. VOID *arg;
  505.  
  506. {
  507.   BoxStatus *gnrc;
  508.   BoxList *bx;
  509.  
  510.   gnrc = (BoxStatus *) status;
  511.   bx = FindBoxByID(gnrc,id);
  512.   if(bx == NULL) {
  513.     fprintf(stderr,"Cannot add callback: box does not exist with that id.\n");
  514.     return(0);
  515.    }
  516.   bx->global_arg = arg;
  517. }
  518.  
  519. AddBoxLocalCallback(status,id,callback)
  520.  
  521. VOID *status;
  522. int id;
  523. int (*callback)();
  524.  
  525. {
  526.   BoxStatus *gnrc;
  527.   BoxList *bx;
  528.  
  529.   gnrc = (BoxStatus *) status;
  530.   bx = FindBoxByID(gnrc,id);
  531.   if(bx == NULL) {
  532.     fprintf(stderr,"Cannot add callback: box does not exist with that id.\n");
  533.     return(0);
  534.    }
  535.   bx->local_callback = callback;
  536. }
  537.  
  538.  
  539. AddBoxGlobalCallback(status,id,callback)
  540.  
  541. VOID *status;
  542. int id;
  543. int (*callback)();
  544.  
  545. {
  546.   BoxStatus *gnrc;
  547.   BoxList *bx;
  548.  
  549.   gnrc = (BoxStatus *) status;
  550.   bx = FindBoxByID(gnrc,id);
  551.   if(bx == NULL) {
  552.     fprintf(stderr,"Cannot add callback: box does not exist with that id.\n");
  553.     return(0);
  554.    }
  555.   bx->global_callback = callback;
  556. }
  557.  
  558. AddBoxContinuousLocalCallback(status,id,callback)
  559.  
  560. VOID *status;
  561. int id;
  562. int (*callback)();
  563.  
  564. {
  565.   BoxStatus *gnrc;
  566.   BoxList *bx;
  567.  
  568.   gnrc = (BoxStatus *) status;
  569.   bx = FindBoxByID(gnrc,id);
  570.   if(bx == NULL) {
  571.     fprintf(stderr,"Cannot add callback: box does not exist with that id.\n");
  572.     return(0);
  573.    }
  574.   bx->continuous_local_callback = callback;
  575. }
  576.  
  577.  
  578. AddBoxContinuousGlobalCallback(status,id,callback)
  579.  
  580. VOID *status;
  581. int id;
  582. int (*callback)();
  583.  
  584. {
  585.   BoxStatus *gnrc;
  586.   BoxList *bx;
  587.  
  588.   gnrc = (BoxStatus *) status;
  589.   bx = FindBoxByID(gnrc,id);
  590.   if(bx == NULL) {
  591.     fprintf(stderr,"Cannot add callback: box does not exist with that id.\n");
  592.     return(0);
  593.    }
  594.   bx->continuous_global_callback = callback;
  595. }
  596.  
  597.  
  598.  
  599. ChangeBoxVisibility(status,id,visible)
  600.  
  601. VOID *status;
  602. int id,visible;
  603.  
  604. {
  605.   BoxStatus *gnrc;
  606.   BoxList *bx;
  607.  
  608.   gnrc = (BoxStatus *) status;
  609.   bx = FindBoxByID(gnrc,id); bx->visible = visible;
  610. }
  611.  
  612. AddBoxText(status,box_id,x,y,strng,attr_id)
  613.  
  614. VOID *status;
  615. int box_id,x,y,attr_id;
  616. char *strng;
  617.  
  618. {
  619.   BoxList *bx;
  620.   BoxStatus *gnrc;
  621.   TextList *txt;
  622.   BoxAttributeList *attr;
  623.  
  624.   gnrc = (BoxStatus *) status;
  625.  
  626.   if((bx = FindBoxByID(gnrc,box_id)) == NULL) {
  627.      fprintf(stderr,"No such box!\n"); return(0);
  628.     }
  629.   if((attr = FindBoxAttributeByID(gnrc,attr_id)) == NULL) {
  630.      fprintf(stderr,"No such attribute!\n"); return(0);
  631.     }
  632.   txt = &(bx->txt);
  633.   while(txt->next != NULL) txt = txt->next;
  634.   txt->next = (TextList *) malloc(sizeof(TextList));
  635.   if((txt = txt->next) == NULL) {
  636.      fprintf(stderr,"Could not allocate space for text!\n"); return(0);
  637.     }
  638.   strcpy(txt->text,strng); txt->x = x; txt->y = y;
  639.   txt->attr = attr; txt->next = NULL;
  640. }
  641.  
  642. BoxPublicPrintMessage(status,mssg)
  643.  
  644. VOID *status;
  645. char *mssg;
  646.  
  647. {
  648.   BoxStatus *gnrc;
  649.  
  650.   gnrc = (BoxStatus *) status;
  651.   BoxPrintMessage(gnrc,mssg);
  652. }
  653.  
  654. BoxPublicUrgentWindowDialogue(status,prmpt,rtrn)
  655.  
  656. VOID *status;
  657. char *prmpt,*rtrn;
  658.  
  659. {
  660.   BoxStatus *gnrc;
  661.   int num;
  662.  
  663.   gnrc = (BoxStatus *) status;
  664.   num = BoxUrgentWindowDialogue(gnrc,prmpt,rtrn);
  665.   return(num);
  666. }
  667.  
  668. BoxShow(status)
  669. VOID *status;
  670. {
  671.   BoxStatus *gnrc;
  672.   gnrc = (BoxStatus *) status;
  673.  
  674.   XMapWindow(dpy,gnrc->TopWindow);
  675. }
  676.  
  677. BoxHide(status)
  678. VOID *status;
  679. {
  680.   BoxStatus *gnrc;
  681.   gnrc = (BoxStatus *) status;
  682.  
  683.   XUnmapWindow(dpy,gnrc->TopWindow);
  684. }
  685.  
  686.