home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / driver / show / amiga / am_menu.c next >
Encoding:
C/C++ Source or Header  |  1994-08-07  |  51.9 KB  |  2,081 lines

  1. /*
  2. **    This file generated by localize 2.9 (AmigaDOS 2.1) from am_menu.c
  3. */
  4. /** am_menu.c **/
  5.  
  6. #ifdef AMIGA
  7.  
  8.  
  9. #include "defines.h"
  10.  
  11. #include <stdio.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/imageclass.h>
  14. #include <intuition/screens.h>
  15. #include <libraries/dos.h>
  16. #include <libraries/gadtools.h>
  17. #include <dos/dostags.h>
  18.  
  19. #include "globals.h"
  20.  
  21. #ifdef ANSI
  22. #  include <stdlib.h>
  23. #  include <string.h>
  24. #endif
  25.  
  26. #ifdef AZTEC_C
  27. #  include <functions.h>
  28. #endif
  29.  
  30.  
  31. #include <dos.h>
  32.  
  33. #include <clib/exec_protos.h>
  34. #include <clib/intuition_protos.h>
  35. #include <clib/dos_protos.h>
  36. #include <clib/graphics_protos.h>
  37. #include <clib/gadtools_protos.h>
  38.  
  39. #include <pragmas/exec_pragmas.h>
  40. #include <pragmas/intuition_pragmas.h>
  41. #include <pragmas/dos_pragmas.h>
  42. #include <pragmas/graphics_pragmas.h>
  43. #include <pragmas/gadtools_pragmas.h>
  44.  
  45. #include "amscreen.h"
  46. #include "am_menu.h"
  47. #include "gad_def.h"        /* dir_Gad and fil_Gad */
  48.  
  49. #include "amscreen.i"
  50. #include "messwin.i"
  51. #include "gadget.i"
  52. #include "am_menu.i"
  53. #include "am_requ.i"
  54. #include "globals.i"
  55. #include "showdvi.i"
  56. #include "config.i"
  57. #include "dvihand.i"
  58. #include "prefwin.i"
  59. #include "local.i"
  60.  
  61. #include "newcli.i"
  62.  
  63.  
  64.  
  65.  
  66.  
  67. /* lokale Funktionen */
  68.  
  69. static void draw_arrow            Args((struct RastPort *rp,
  70.                           long x,
  71.                           long y));
  72. static void draw_frame            Args((struct RastPort *rp,
  73.                           long x,
  74.                           long y,
  75.                           long width,
  76.                           long height));
  77. static void check_bounds        Args((long *x,
  78.                           long *y,
  79.                           long width,
  80.                           long height));
  81. static void prepare_menu        Args((struct RastPort *rp,
  82.                           struct RastPort *save_rp,
  83.                           long x,
  84.                           long y,
  85.                           long width,
  86.                           long height));
  87. static void clear_current_submenu    Args((int menu));
  88. static void display_submenu_outfit    Args((void));
  89. static void display_submenu_load    Args((void));
  90. static void display_submenu_resolution    Args((void));
  91. static void display_menu        Args((int menu,
  92.                                       int zeile,
  93.                                       int col,
  94.                                       int sub_zeile));
  95. static void mark_line_sub_menu        Args((struct RastPort *rp,
  96.                           int menu,
  97.                           int zeile));
  98. static void mark_line_main_menu        Args((struct RastPort *rp,
  99.                           int zeile,
  100.                           int spalte));
  101. static void work_with_submenu        Args((struct RastPort *rp,
  102.                           int x,
  103.                                       int y,
  104.                                       int menu,
  105.                                       int *old_sub_zeile));
  106. static void work_with_menu        Args((struct RastPort *rp,
  107.                           int x,
  108.                                       int y,
  109.                                       int *menu,
  110.                                       int *old_zeile,
  111.                                       int *old_col,
  112.                                       int *old_sub_zeile));
  113. static long do_menu            Args((int menu,
  114.                                   int zeile,
  115.                                   int col,
  116.                                   int sub_zeile,
  117.                                   int mx,
  118.                                   int my));
  119. static void init_bmap            Args((struct BitMap *bm,
  120.                           struct RastPort *rp,
  121.                           long width,
  122.                           long height));
  123. static void free_bmap            Args((struct BitMap *bm,
  124.                           long width,
  125.                           long height));
  126.  
  127. static struct MenuItem *FindMenuEntry    Args((struct Menu *Menu,
  128.                           short menunum, short itemnum, short subnum));
  129. static void MenuAnAus            Args((struct Menu *Men,
  130.                           short menunum, short item, short sub,
  131.                           short on));
  132. static void MyLayoutMenu        Args((void));
  133. static struct MenuItem *LayoutOneMenu    Args((struct RastPort *rp,
  134.                           struct MenuLayout *MLay,
  135.                           int NrEntries,
  136.                           int spacelen,
  137.                           int width));
  138.  
  139.  
  140.   
  141. #define MenuAn(men,num,item,sub)    MenuAnAus(men,num,item,sub,TRUE)
  142. #define MenuAus(men,num,item,sub)    MenuAnAus(men,num,item,sub,FALSE)
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. /* Globale Variablen innerhalb des Moduls */
  150.  
  151. static struct RastPort        menu_save_rp,
  152.                 smenu_o_save_rp,    /* SubM outfit */
  153.                 smenu_l_save_rp,    /* SubM load DVI */
  154.                 smenu_r_save_rp;    /* SubM resolution */
  155.  
  156. static struct BitMap        menu_save_bm,
  157.                 smenu_o_save_bm,
  158.                 smenu_l_save_bm,
  159.                 smenu_r_save_bm;
  160.  
  161. static long            menu_offset_x,
  162.                 menu_offset_y,
  163.                 current_submenu_x,
  164.                 current_submenu_y;
  165.  
  166. static short menu_width,
  167.          menu_height,
  168.          smenu_o_width,
  169.          smenu_o_height,
  170.          smenu_l_width,
  171.          smenu_l_height,
  172.          smenu_r_width,
  173.          smenu_r_height;
  174.  
  175.  
  176. static short            last_zeile,
  177.                 last_sub_zeile,
  178.                 last_col;
  179.  
  180. static short            txt_width,
  181.                 txt_height;
  182.  
  183. static struct TextFont        *menu_font,
  184.                 *normal_font;
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192. /* externe Variablen */
  193.  
  194. extern struct ArpBase        *ArpBase;
  195. extern long            resolution;
  196. extern struct TextFont        *font8,
  197.                 *font11;
  198. extern char             PubScreenName[];
  199. extern char             MyPubScreenName[];
  200.  
  201.  
  202.  
  203. /**** lokale Funktionen ************/
  204.  
  205. static void draw_arrow(struct RastPort *rp, long x, long y)
  206. {
  207.   x += 4;
  208.  
  209.   Move(rp,x,y-4);
  210.   Draw(rp,x+6,y-4);
  211.   Move(rp,x,y-2);
  212.   Draw(rp,x+6,y-2);
  213.   Move(rp,x+4,y-6);
  214.   Draw(rp,x+8,y-3);
  215.   Draw(rp,x+4,y);
  216. }
  217.  
  218. static void draw_frame(struct RastPort *rp, long x, long y, long width, long height)
  219. {
  220.   Move(rp,x,y);
  221.   Draw(rp,x+width-4,y);
  222.   Draw(rp,x+width-4,y+height-4);
  223.   Draw(rp,x,y+height-4);
  224.   Draw(rp,x,y);
  225.  
  226.   Move(rp,x+width-1,y+4);
  227.   Draw(rp,x+width-1,y+height-1);
  228.   Draw(rp,x+4,y+height-1);
  229.  
  230.   Move(rp,x+width-2,y+4);
  231.   Draw(rp,x+width-2,y+height-2);
  232.   Draw(rp,x+4,y+height-2);
  233.  
  234.   Move(rp,x+width-3,y+4);
  235.   Draw(rp,x+width-3,y+height-3);
  236.   Draw(rp,x+4,y+height-3);
  237. }
  238.  
  239. static void check_bounds(long *x, long *y, long width, long height)
  240. {
  241.   if (*x + width > x_win_width) {
  242.     *x = x_win_width - width;
  243.   }
  244.   else {
  245.     if (*x < 0) {
  246.       *x = 0;
  247.     }
  248.   }
  249.   if (*y + height > x_win_height) {
  250.     *y = x_win_height - height;
  251.   }
  252.   else {
  253.     if (*y < 0) {
  254.       *y = 0;
  255.     }
  256.   }
  257. }
  258.  
  259.  
  260. static void prepare_menu(struct RastPort *rp, struct RastPort *save_rp,
  261.              long x, long y, long width, long height)
  262. {
  263.   /* save data */
  264.   ClipBlit(rp,(long)x,(long)y,save_rp, 0L, 0L,(long)width,(long)height,(long)192);
  265.  
  266.   /* clear block */
  267.   SetAPen(rp,0);
  268.   RectFill(rp,x,y,x+width-4,y+height-4);    /* -4 because border */
  269.   SetAPen(rp,1);
  270.  
  271.   /* draw frame */
  272.   draw_frame(rp,x,y,width,height);
  273. }
  274.  
  275.  
  276. static void clear_current_submenu(int menu)
  277. {
  278.   register struct RastPort *rp = win2->RPort, *srp;
  279.   register long width, height;
  280.  
  281.   if (menu != MAIN_MENU) {
  282.     if (menu == SMENU_OUTFIT) {
  283.       width = SMENU_O_WIDTH;
  284.       height = SMENU_O_HEIGHT;
  285.       srp = &smenu_o_save_rp;
  286.     }
  287.     else if (menu == SMENU_LOAD) {
  288.       width = SMENU_L_WIDTH;
  289.       height = SMENU_L_HEIGHT;
  290.       srp = &smenu_l_save_rp;
  291.     }
  292.     else if (menu == SMENU_RESOLUTION) {
  293.       width = SMENU_R_WIDTH;
  294.       height = SMENU_R_HEIGHT;
  295.       srp = &smenu_r_save_rp;
  296.     }
  297.     else {
  298.       Fatal(20,MSG_UNKNOWN_POP_SUBMENU);
  299.     }
  300.     ClipBlit(srp,0L,0L,rp,current_submenu_x,current_submenu_y,width,height,192L);
  301.   }
  302. }
  303.  
  304.  
  305. static void display_submenu_outfit(void)
  306. {
  307.   register struct RastPort *rp = win2->RPort;
  308.   long smenu_o_offset_x, smenu_o_offset_y;
  309.   register long y;
  310.  
  311.   smenu_o_offset_x = menu_offset_x + SUBMENU_SPALTE;
  312.   smenu_o_offset_y = menu_offset_y + YOFFSET * (SMENU_O_START_LINE-1);
  313.  
  314.   check_bounds(&smenu_o_offset_x,&smenu_o_offset_y,SMENU_O_WIDTH,SMENU_O_HEIGHT);
  315.  
  316.   prepare_menu(rp,&smenu_o_save_rp,smenu_o_offset_x,smenu_o_offset_y,
  317.         SMENU_O_WIDTH,SMENU_O_HEIGHT);
  318.  
  319.   current_submenu_x = smenu_o_offset_x;
  320.   current_submenu_y = smenu_o_offset_y;
  321.  
  322.   y = smenu_o_offset_y+TXTHEIGHT;
  323.   if (!is_bmenu) y++;
  324.  
  325.   SetFont(rp,menu_font);
  326.  
  327.   Move(rp,smenu_o_offset_x+3,y);
  328.   if (is_lace) {
  329.     Text(rp,"unset lace     i",16);
  330.   }
  331.   else {
  332.     Text(rp,"set lace       i",16);
  333.   }
  334.   y += YOFFSET;
  335.   Move(rp,smenu_o_offset_x+3,y);
  336.   if (is_gadg) {
  337.     Text(rp,"hide scrollbar o",16);
  338.   }
  339.   else {
  340.     Text(rp,"show scrollbar o",16);
  341.   }
  342.   y += YOFFSET;
  343.   Move(rp,smenu_o_offset_x+3,y);
  344.   Text(rp,"change color  Ac",16);
  345.   y += YOFFSET;
  346.   Move(rp,smenu_o_offset_x+3,y);
  347.   Text(rp,"save config   Aw",16);
  348.  
  349.   SetFont(rp,normal_font);
  350. }
  351.  
  352. static void display_submenu_load(void)
  353. {
  354.   register struct RastPort *rp = win2->RPort;
  355.   long smenu_l_offset_x, smenu_l_offset_y;
  356.   long y;
  357.  
  358.   smenu_l_offset_x = menu_offset_x + SUBMENU_SPALTE;
  359.   smenu_l_offset_y = menu_offset_y + YOFFSET * (SMENU_L_START_LINE-1);
  360.  
  361.   check_bounds(&smenu_l_offset_x,&smenu_l_offset_y,SMENU_L_WIDTH,SMENU_L_HEIGHT);
  362.  
  363.   prepare_menu(rp,&smenu_l_save_rp,smenu_l_offset_x,smenu_l_offset_y,
  364.         SMENU_L_WIDTH,SMENU_L_HEIGHT);
  365.  
  366.   current_submenu_x = smenu_l_offset_x;
  367.   current_submenu_y = smenu_l_offset_y;
  368.  
  369.   y = smenu_l_offset_y+TXTHEIGHT;
  370.   if (!is_bmenu) y++;
  371.  
  372.   SetFont(rp,menu_font);
  373.  
  374.   Move(rp,smenu_l_offset_x+3,y);
  375.   Text(rp,"load file again a",17);
  376.   y += YOFFSET;
  377.   Move(rp,smenu_l_offset_x+3,y);
  378.   Text(rp,"load new file  Ao",17);
  379.  
  380.   SetFont(rp,normal_font);
  381. }
  382.  
  383. static void display_submenu_resolution(void)
  384. {
  385.   register struct RastPort *rp = win2->RPort;
  386.   long smenu_r_offset_x, smenu_r_offset_y;
  387.   long height, i, len;
  388.   long y;
  389.   char str[50], hstr[20];
  390.  
  391.   smenu_r_offset_x = menu_offset_x + SUBMENU_SPALTE;
  392.   smenu_r_offset_y = menu_offset_y + YOFFSET * (SMENU_R_START_LINE-1);
  393.  
  394.   height = SMENU_R_HEIGHT;
  395.  
  396.   check_bounds(&smenu_r_offset_x,&smenu_r_offset_y,SMENU_R_WIDTH,height);
  397.  
  398.   prepare_menu(rp,&smenu_r_save_rp,smenu_r_offset_x,smenu_r_offset_y,
  399.         SMENU_R_WIDTH,height);
  400.  
  401.   current_submenu_x = smenu_r_offset_x;
  402.   current_submenu_y = smenu_r_offset_y;
  403.  
  404.   y = smenu_r_offset_y+TXTHEIGHT;
  405.   if (!is_bmenu) y++;
  406.  
  407.   SetFont(rp,menu_font);
  408.  
  409.   for (i=0; i<show_state.menu_res_lines; i++) {
  410.     Move(rp,smenu_r_offset_x+3,y);
  411.     y += YOFFSET;
  412.     if (show_state.mres[i] == resolution) {
  413.       len = sprintf(str,"»%4ld dpi",(long)show_state.mres[i]);
  414.     }
  415.     else {
  416.       len = sprintf(str," %4ld dpi",(long)show_state.mres[i]);
  417.     }
  418.     if (i < 9) {
  419.       len += sprintf(hstr, " A%ld", i+1);
  420.       strcat(str, hstr);
  421.     }
  422.     else {
  423.       if (i == 9) {
  424.         len += 3;
  425.         strcat(str, " A9");
  426.       }
  427.     }
  428.     Text(rp,str,len);
  429.   }
  430.  
  431.   SetFont(rp,normal_font);
  432. }
  433.  
  434. static void display_menu(int menu, int zeile, int col, int sub_zeile)
  435. {
  436.   register struct RastPort *rp = win2->RPort;
  437.   register long y;
  438.  
  439.   check_bounds(&menu_offset_x,&menu_offset_y,MENU_WIDTH,MENU_HEIGHT);
  440.  
  441.   prepare_menu(win2->RPort,&menu_save_rp,menu_offset_x,menu_offset_y,
  442.         MENU_WIDTH,MENU_HEIGHT);
  443.  
  444.   SetFont(rp,menu_font);
  445.  
  446.   /* line 1 */
  447.   y = menu_offset_y+TXTHEIGHT;
  448.   if (!is_bmenu) y++;
  449.  
  450.   Move(rp,menu_offset_x+3,y);
  451.   Text(rp,"about       HELP",16);
  452.  
  453.   /* line 2 */
  454.   y += YOFFSET;
  455.   Move(rp,menu_offset_x+3,y);
  456.   Text(rp,"+",1);
  457.   Move(rp,menu_offset_x+SPALTE-2,y);
  458.   Text(rp," ++",3);
  459.  
  460.   /* line 3 */
  461.   y += YOFFSET;
  462.   Move(rp,menu_offset_x+3,y);
  463.   Text(rp,"-",1);
  464.   Move(rp,menu_offset_x+SPALTE-2,y);
  465.   Text(rp," --",3);
  466.  
  467.   /* line 4 */
  468.   y += YOFFSET;
  469.   Move(rp,menu_offset_x+3,y);
  470.   if (is_show) {
  471.     Text(rp,"show page      f",16);
  472.   }
  473.   else {
  474.     Text(rp,"show full page f",16);
  475.   }
  476.  
  477.   /* line 5 */
  478.   y += YOFFSET;
  479.   Move(rp,menu_offset_x+3,y);
  480.   Text(rp,"clear counter  c",16);
  481.  
  482.   /* line 6 => submenu outfit */
  483.   y += YOFFSET;
  484.   Move(rp,menu_offset_x+3,y);
  485.   Text(rp,"outfit",6);
  486.   draw_arrow(rp,menu_offset_x+SUBMENU_ARROW,y);
  487.  
  488.   /* line 7 => submenu load */
  489.   y += YOFFSET;
  490.   Move(rp,menu_offset_x+3,y);
  491.   Text(rp,"load DVI",8);
  492.   draw_arrow(rp,menu_offset_x+SUBMENU_ARROW,y);
  493.  
  494.   /* line 8  => submenu resolution */
  495.   y += YOFFSET;
  496.   Move(rp,menu_offset_x+3,y);
  497.   Text(rp,"resolution",10);
  498.   draw_arrow(rp,menu_offset_x+SUBMENU_ARROW,y);
  499.  
  500.   /* line 9 */
  501.   y += YOFFSET;
  502.   Move(rp,menu_offset_x+3,y);
  503.   if (is_print) {
  504.     Text(rp,"cancel print   p",16);
  505.   }
  506.   else {
  507.     Text(rp,"print page     p",16);
  508.   }
  509.  
  510.   /* line 10 */
  511.   y += YOFFSET;
  512.   Move(rp,menu_offset_x+3,y);
  513.   if (is_escex) {
  514.     Text(rp,"hide",4);
  515.   }
  516.   else {
  517.     Text(rp,"hide ESC",8);
  518.   }
  519.   Move(rp,menu_offset_x+SPALTE,y);
  520.   Text(rp,"quit Aq",7);
  521.  
  522.   SetDrMd(win2->RPort,COMPLEMENT);
  523.   mark_line_main_menu(rp,zeile,col);
  524.   if (menu != MAIN_MENU) {
  525.     SetDrMd(win2->RPort,JAM1);
  526.     if (menu == SMENU_OUTFIT) {
  527.       display_submenu_outfit();
  528.     }
  529.     else if (menu == SMENU_LOAD) {
  530.       display_submenu_load();
  531.     }
  532.     else {
  533.       display_submenu_resolution();
  534.     }
  535.     SetDrMd(win2->RPort,COMPLEMENT);
  536.     mark_line_sub_menu(rp,menu,sub_zeile);
  537.   }
  538.   SetDrMd(win2->RPort,JAM1);
  539.   SetFont(rp,normal_font);
  540. }
  541.  
  542. static void mark_line_sub_menu(struct RastPort *rp, int menu, int zeile)
  543. {
  544.   int sub_w;
  545.   long xw, yw;
  546.  
  547.   if (menu == SMENU_OUTFIT) {
  548.     sub_w = SMENU_O_WIDTH;
  549.   }
  550.   else if (menu == SMENU_LOAD) {
  551.     sub_w = SMENU_L_WIDTH;
  552.   }
  553.   else if (menu == SMENU_RESOLUTION) {
  554.     sub_w = SMENU_R_WIDTH;
  555.   }
  556.   else {
  557.     return; /* nie!! */
  558.   }
  559.  
  560.   xw = current_submenu_x + 2;
  561.   yw = current_submenu_y + (zeile-1)*YOFFSET+2;
  562.  
  563.   if (zeile != 0) {
  564.     RectFill(rp,xw,yw,xw+sub_w-8,yw+YOFFSET-1);
  565.   }
  566. }
  567.  
  568. static void mark_line_main_menu(struct RastPort *rp, int zeile, int spalte)
  569. {
  570.   long xw, yw;
  571.  
  572.   xw = menu_offset_x+2;
  573.   yw = menu_offset_y+(zeile-1)*YOFFSET+2;
  574.   if (zeile != 0) {
  575.     if (zeile == 3 || zeile == 2 || zeile == 10) {
  576.       if (spalte == 1) {
  577.         RectFill(rp,xw,yw,xw+SPALTE-4,yw+YOFFSET-1);
  578.       }
  579.       else {
  580.         RectFill(rp,xw+SPALTE-3,yw,xw+MENU_WIDTH-8,yw+YOFFSET-1);
  581.       }
  582.     }
  583.     else {
  584.       RectFill(rp,xw,yw,xw+MENU_WIDTH-8,yw+YOFFSET-1);
  585.     }
  586.   }
  587. }
  588.  
  589. static void work_with_submenu(struct RastPort *rp, int x, int y,
  590.                 int menu, int *old_sub_zeile)
  591. {
  592.   int sub_w, sub_h, i;
  593.   int zeile, nr_lines;
  594.  
  595.   /** Maus innerhalb eines Submenus */
  596.   if (menu == SMENU_OUTFIT) {
  597.     sub_w = SMENU_O_WIDTH;
  598.     sub_h = SMENU_O_HEIGHT;
  599.     nr_lines = NR_SMENU_O_LINES;
  600.   }
  601.   else if (menu == SMENU_LOAD) {
  602.     sub_w = SMENU_L_WIDTH;
  603.     sub_h = SMENU_L_HEIGHT;
  604.     nr_lines = NR_SMENU_L_LINES;
  605.   }
  606.   else if (menu == SMENU_RESOLUTION) {
  607.     sub_w = SMENU_R_WIDTH;
  608.     sub_h = SMENU_R_HEIGHT;
  609.     nr_lines = show_state.menu_res_lines;
  610.  
  611.   }
  612.   else {
  613.     *old_sub_zeile = 0;
  614.     return;    /* nie! */
  615.   }
  616.  
  617.   i = y - current_submenu_y-2;
  618.   if (i < 0 || x < current_submenu_x+2 || y < current_submenu_y+2
  619.     || x > current_submenu_x+sub_w-2 || y > current_submenu_y+sub_h-2) {
  620.     zeile = 0;
  621.   }
  622.   else {
  623.     zeile = 1 + i / YOFFSET;
  624.   }
  625.   if (zeile > nr_lines) zeile = 0;
  626.  
  627.   if (zeile != *old_sub_zeile) {
  628.     mark_line_sub_menu(rp,menu,*old_sub_zeile);
  629.     mark_line_sub_menu(rp,menu,zeile);
  630.     *old_sub_zeile = zeile;
  631.   }
  632. }
  633.  
  634. static void work_with_menu(struct RastPort *rp,int x,int y,int *menu,
  635.             int *old_zeile,int *old_col,int *old_sub_zeile)
  636. {
  637.   int zeile, col, i;
  638.   int sub_w, sub_h;
  639.  
  640.   i = y - menu_offset_y-2;
  641.   if (i < 0 || x < menu_offset_x+2 || y < menu_offset_y+2
  642.     || x > menu_offset_x+MENU_WIDTH-2 || y > menu_offset_y+MENU_HEIGHT-2) {
  643.     zeile = 0;
  644.   }
  645.   else {
  646.     zeile = 1 + i / YOFFSET;
  647.   }
  648.   if (zeile > NR_MENU_LINES) zeile = 0;
  649.  
  650.   col = (x-menu_offset_x-2 < SPALTE) ? 1 : 2;
  651.   if (zeile != 2 && zeile != 3 && zeile != 10) col = 0;
  652.   if ((zeile == SMENU_O_START_LINE || zeile == SMENU_L_START_LINE ||
  653.     zeile == SMENU_R_START_LINE) && x-menu_offset_x > SUBMENU_SPALTE) {
  654.     col = 3;
  655.   }
  656.  
  657.   /** Maus innerhalb eines Submenus */
  658.   if (*menu == SMENU_OUTFIT) {
  659.     sub_w = SMENU_O_WIDTH;
  660.     sub_h = SMENU_O_HEIGHT;
  661.   }
  662.   else if (*menu == SMENU_LOAD) {
  663.     sub_w = SMENU_L_WIDTH;
  664.     sub_h = SMENU_L_HEIGHT;
  665.   }
  666.   else if (*menu == SMENU_RESOLUTION) {
  667.     sub_w = SMENU_R_WIDTH;
  668.     sub_h = SMENU_R_HEIGHT;
  669.   }
  670.  
  671.   if (*menu != MAIN_MENU && x >= current_submenu_x && 
  672.     x < current_submenu_x+sub_w-2 && y >= current_submenu_y+2 &&
  673.     y < current_submenu_y+sub_h-2) {
  674.     work_with_submenu(rp,x,y,*menu,old_sub_zeile);
  675.   }
  676.   else {
  677.     if (*menu != MAIN_MENU) {
  678.       clear_current_submenu(*menu);
  679.       *menu = MAIN_MENU;
  680.       *old_sub_zeile = 0;
  681.     }
  682.  
  683.     if (zeile == *old_zeile && col == *old_col) {
  684.       return;        /* keine Anderung --> weg */
  685.     }
  686.  
  687.     /* loeschen */
  688.     mark_line_main_menu(rp,*old_zeile,*old_col);
  689.  
  690.     if (col == 3) {
  691.       mark_line_main_menu(rp,zeile,col);        /* setzen */
  692.       SetDrMd(win2->RPort,JAM1);
  693.       if (zeile == SMENU_O_START_LINE) {
  694.         *menu = SMENU_OUTFIT;
  695.         display_submenu_outfit();
  696.       }
  697.       else if (zeile == SMENU_L_START_LINE) {
  698.         *menu = SMENU_LOAD;
  699.         display_submenu_load();
  700.       }
  701.       else {
  702.         *menu = SMENU_RESOLUTION;
  703.         display_submenu_resolution();
  704.       }
  705.       SetDrMd(win2->RPort,COMPLEMENT);
  706.       *old_col = 3;
  707.       *old_zeile = zeile;
  708.       work_with_submenu(rp,x,y,*menu,old_sub_zeile);
  709.     }
  710.     else {
  711.       mark_line_main_menu(rp,zeile,col);
  712.       *old_col = col;
  713.       *old_zeile = zeile;
  714.     }
  715.   }    /* else innerhalb eines Submenus */
  716.   return;
  717. }
  718.  
  719.  
  720. /* Auswertung */
  721. static long do_menu(int menu,int zeile,int col,int sub_zeile,int mx,int my)
  722. {
  723.   register long ret = 5L;
  724.  
  725.   switch (zeile) {
  726.     case 1: AboutWinUp();
  727.         ret = 5L;
  728.             break;
  729.     case 2: if (is_print) {
  730.              ret = 6L;
  731.            }
  732.            else {
  733.           if (col == 1) {
  734.             ret = 1L;
  735.               }
  736.               else {
  737.                 ret = 2L;
  738.               }
  739.             }
  740.             break;
  741.     case 3: if (is_print) {
  742.              ret = 6L;
  743.            }
  744.            else {
  745.           if (col == 1) {
  746.             ret = -1L;
  747.               }
  748.               else {
  749.                 ret = -2L;
  750.               }
  751.             }
  752.             break;
  753.     case 4: if (is_dvif) {
  754.           show_full_page(FALSE);
  755.           ret = 5L;
  756.         }
  757.         else {            /* noch kein DVI-File geladen */
  758.           ret = 7L;
  759.         }
  760.             break;
  761.     case 5: clear_counter(0);
  762.         ret = 5L;
  763.             break;
  764.     case 6: switch (sub_zeile) {
  765.               case 0:
  766.               case 1:
  767.         if (is_show) {
  768.           show_full_page(FALSE);  /* show-Modus ausschalten */
  769.         }
  770.         change_resolution();
  771.         break;
  772.           case 2:
  773.             if (!is_show) {
  774.               toggle_scrollbar(FALSE);
  775.             }
  776.             break;
  777.           case 3:
  778.             show_col_request();
  779.             break;
  780.           case 4:
  781.             write_config_file();
  782.             break;
  783.         }
  784.         ret = 5L;
  785.             break;
  786.     case 7: if (is_print) {
  787.           ret = 6L;
  788.             }
  789.             else {
  790.           switch (sub_zeile) {
  791.             case 0:
  792.             case 1:
  793.               if (is_dvif) {
  794.                 OpenNewDVI(filename, FALSE);
  795.                 ret = 3L;        /* neues File, Name nicht geaendert. */
  796.               }
  797.               else {
  798.                 ret = 7L;
  799.               }
  800.                   break;
  801.         case 2:
  802.           ret = LoadFileReq();
  803.           break;
  804.           }
  805.         }
  806.         break;
  807.     case 8: if (is_print) {
  808.           ret = 6L;
  809.             }
  810.             else {
  811.               int new_res;
  812.  
  813.               if (sub_zeile <= show_state.menu_res_lines) {
  814.                 if (sub_zeile == 0) {
  815.                   new_res = show_state.mres[0];
  816.                 }
  817.                 else {
  818.                   new_res = show_state.mres[sub_zeile-1];
  819.                 }
  820.           }
  821.           if (new_res != resolution) {
  822.             resolution = new_res;
  823.             hconvresolution = resolution;
  824.             vconvresolution = resolution;
  825.                 if (is_dvif) {
  826.                   OpenNewDVI(filename, TRUE);
  827.                   set_chres;
  828.                   if (is_show) {
  829.                     show_full_page(TRUE); /* full-page modus off (no_refresh=TRUE) */
  830.                   }
  831.                   ret = 3L;          /* neues File, Name nicht geaendert. */
  832.                 }
  833.         set_checked_os_menu();
  834.               }
  835.         }
  836.            break;
  837.     case 9:  
  838.             if (is_dvif) {
  839.           printing();
  840.         }
  841.         else {
  842.           Message(MSG_NO_DVI_FILE);
  843.           beep();
  844.         }
  845.         ret = 5L;
  846.             break;
  847.     case 10: if (col == 1) {
  848.            ScreenToBack(screen);        /* Screen weg!! */
  849.            make_old_active();
  850.            ret = 5L;
  851.              }
  852.              else {
  853.            if (real_prog_end()) {
  854.              Enable_Abort = 0;        /* am Ende nicht noch ein ^C */
  855.              ret = 10L;
  856.            }
  857.            else {
  858.              ret = 5L;
  859.            }
  860.              }
  861.              break;
  862.     default: ret = 5L;
  863.              break;
  864.   }
  865.   if (ret == 6L) {
  866.     Message(MSG_NOT_WHILE_PRINTING);
  867.     ret = 5L;
  868.   }
  869.   else {
  870.     if (ret == 7L) {
  871.       Message(MSG_NO_DVI_FILE);
  872.       beep();
  873.       ret = 5L;
  874.     }
  875.   }
  876.   return (ret);
  877. }
  878.  
  879. static void init_bmap(struct BitMap *bm, struct RastPort *rp, long width, long height)
  880. {
  881.   int i;
  882.  
  883.   for (i=0; i<8; i++) {        /* wichtig fuer free_bmap() */
  884.     bm->Planes[i] = NULL;
  885.   }
  886.  
  887.   if (is_col4) {
  888.     InitBitMap(bm,2L,width,height);
  889.     bm->Planes[0] = AllocRaster(width,height);
  890.     bm->Planes[1] = AllocRaster(width,height);
  891.   }
  892.   else {
  893.     InitBitMap(bm,1L,width,height);
  894.     bm->Planes[0] = AllocRaster(width,height);
  895.   }
  896.   if (bm->Planes[0] == NULL || (is_col4 && bm->Planes[1] == NULL)) { 
  897.     Fatal(10,MSG_NO_CHIPMEM);
  898.   }
  899.   BltClear((char *)bm->Planes[0],(width*height)/8,1L);
  900.   if (is_col4) {
  901.     BltClear((char *)bm->Planes[1],(width*height)/8,1L);
  902.   }
  903.   InitRastPort(rp);
  904.   rp->BitMap = bm;
  905. }
  906.  
  907. static void free_bmap(struct BitMap *bm, long width, long height)
  908. {
  909.   int i;
  910.   
  911.   for (i=0; i<8; i++) {
  912.     if (bm->Planes[i] != NULL) {
  913.       FreeRaster(bm->Planes[i],width,height);
  914.       bm->Planes[i] = NULL;
  915.     }
  916.   }
  917. }
  918.  
  919.  
  920.  
  921.  
  922. /****************************************************************************/
  923. /** Schnittstelle: **/
  924.  
  925. void SetDosMenu(void)
  926. {
  927.   SetMenuStrip(win2, &DosMenu[0]);
  928. }
  929.  
  930. void ClearDosMenu(void)
  931. {
  932.   ClearMenuStrip(win2);
  933. }
  934.  
  935.  
  936. /* Speicher freigeben */
  937. void free_menu(void)
  938. {
  939.   free_os_menu();
  940.   if (!is_osmenu || is_midmenu) {
  941.     free_bmap(&menu_save_bm,    MENU_WIDTH,    MENU_HEIGHT);
  942.     free_bmap(&smenu_o_save_bm, SMENU_O_WIDTH, SMENU_O_HEIGHT);
  943.     free_bmap(&smenu_l_save_bm, SMENU_L_WIDTH, SMENU_L_HEIGHT);
  944.     free_bmap(&smenu_r_save_bm, SMENU_R_WIDTH, SMENU_R_HEIGHT);
  945.   }
  946. }
  947.  
  948. /* Speicher allocieren */
  949. void init_menu(void)
  950. {
  951.   if (!is_osmenu || is_midmenu) {
  952.     normal_font = font8;
  953.  
  954.     if (is_bmenu && font11 != NULL) {
  955.       txt_height = 11;
  956.       txt_width  = 8;
  957.       menu_font  = font11;
  958.     }
  959.     else {
  960.       txt_height = 8;
  961.       txt_width  = 8;
  962.       menu_font  = font8;
  963.       unset_bmenu;
  964.     }
  965.  
  966.     menu_width     = CALC_MENU_WIDTH;
  967.     menu_height     = CALC_MENU_HEIGHT;
  968.     smenu_o_width     = CALC_SMENU_O_WIDTH;
  969.     smenu_o_height = CALC_SMENU_O_HEIGHT;
  970.     smenu_l_width     = CALC_SMENU_L_WIDTH;
  971.     smenu_l_height = CALC_SMENU_L_HEIGHT;
  972.     smenu_r_width     = CALC_SMENU_R_WIDTH;
  973.     smenu_r_height = CALC_SMENU_R_HEIGHT;
  974.  
  975.     init_bmap(&menu_save_bm,    &menu_save_rp,    MENU_WIDTH,    MENU_HEIGHT);
  976.     init_bmap(&smenu_o_save_bm, &smenu_o_save_rp, SMENU_O_WIDTH, SMENU_O_HEIGHT);
  977.     init_bmap(&smenu_l_save_bm, &smenu_l_save_rp, SMENU_L_WIDTH, SMENU_L_HEIGHT);
  978.     init_bmap(&smenu_r_save_bm, &smenu_r_save_rp, SMENU_R_WIDTH, SMENU_R_HEIGHT);
  979.   }
  980. }
  981.  
  982.  
  983. /* Menu anzeigen */
  984. long show_menu(UWORD Code, WORD MouseX, WORD MouseY)
  985. {
  986.   register struct RastPort *rp;
  987.   register struct IntuiMessage *msg2;
  988.   ULONG msg_class;
  989.   int x, y, menu = 0, zeile = 0, col = 0, sub_zeile = 0;
  990.   long ret;
  991.   int middle_menu;
  992.   
  993.   if (win2 == NULL) return 5;
  994.   
  995.   rp = win2->RPort;
  996.   SetDrMd(rp, JAM1);
  997.  
  998.   menu_offset_x = x = MouseX;
  999.   menu_offset_y = y = MouseY;
  1000.   
  1001.   middle_menu = (Code == MIDDLEDOWN);
  1002.  
  1003.   if (is_osmenu && !middle_menu) {
  1004.     return 5;        /* no menu */
  1005.   }
  1006.  
  1007.   menu = MAIN_MENU;
  1008.  
  1009.   if (is_imenu) {
  1010.     if (last_zeile != 0) {
  1011.       menu_offset_y -= (last_zeile - 1) * YOFFSET;
  1012.       zeile = last_zeile;
  1013.       if (last_zeile == SMENU_O_START_LINE
  1014.         || last_zeile == SMENU_L_START_LINE
  1015.         || last_zeile == SMENU_R_START_LINE) {
  1016.         menu_offset_x -= SUBMENU_SPALTE;
  1017.         sub_zeile = last_sub_zeile;
  1018.         if (last_sub_zeile > 0) {
  1019.           menu_offset_y -= (last_sub_zeile - 1) * YOFFSET;
  1020.           if (last_zeile == SMENU_O_START_LINE)       menu = SMENU_OUTFIT;
  1021.           else if (last_zeile == SMENU_L_START_LINE) menu = SMENU_LOAD;
  1022.           else if (last_zeile == SMENU_R_START_LINE) menu = SMENU_RESOLUTION;
  1023.           //col = 3;
  1024.         }
  1025.       }
  1026.       else {
  1027.         if ((last_zeile == 2 || last_zeile == 3) && last_col == 2) {
  1028.           menu_offset_x -= SPALTE;
  1029.           //col = 2;
  1030.         }
  1031.       }
  1032.       /* die Grenzen werden in display_menu korrigiert */
  1033.     }
  1034.     menu_offset_x -= 15;
  1035.     menu_offset_y -= 7;
  1036.   }
  1037.  
  1038.   last_zeile = last_sub_zeile = col = 0;
  1039.  
  1040.   current_submenu_x = 0;    /* init */
  1041.   current_submenu_y = 0;
  1042.   
  1043.   /* show menu/sub menu and mark the line */
  1044.   display_menu(menu,zeile,col,sub_zeile);
  1045.  
  1046.   SetDrMd(rp,COMPLEMENT);
  1047.   work_with_menu(rp,x,y,&menu,&zeile,&col,&sub_zeile);
  1048.  
  1049.   add_mmove;
  1050.   MyModifyIDCMP(MOUSEMOVE, 0L);
  1051.  
  1052.   do {
  1053.     WaitPort(win2->UserPort);
  1054.     while ( !((middle_menu && Code == MIDDLEUP) || (!middle_menu && Code == MENUUP)) && 
  1055.        (msg2 = (struct IntuiMessage *)GetMsg(win2->UserPort)) != NULL) {
  1056.       msg_class = msg2->Class;
  1057.       Code = msg2->Code;
  1058.       x = msg2->MouseX;
  1059.       y = msg2->MouseY;
  1060.       ReplyMsg(&(msg2->ExecMessage));
  1061.       if (msg_class == MOUSEMOVE) {
  1062.         work_with_menu(rp,x,y,&menu,&zeile,&col,&sub_zeile);
  1063.       }
  1064.     }
  1065.   } while (!((middle_menu && Code == MIDDLEUP) || (!middle_menu && Code == MENUUP)));
  1066.  
  1067.   sub_mmove;
  1068.   if (!is_mmove) {
  1069.     MyModifyIDCMP(0L, MOUSEMOVE);
  1070.   }
  1071.  
  1072.   if (menu != 0) {
  1073.     clear_current_submenu(menu);
  1074.   }
  1075.   ClipBlit(&menu_save_rp,0L,0L,rp,(long)menu_offset_x,
  1076.     (long)menu_offset_y,(long)MENU_WIDTH,(long)MENU_HEIGHT,(long)192);
  1077.  
  1078.   SetDrMd(rp,JAM1);
  1079.  
  1080.   /* save the menu */
  1081.   if (zeile > 0 && zeile <= NR_MENU_LINES) {
  1082.     last_zeile = zeile;
  1083.     if (zeile == SMENU_O_START_LINE) {
  1084.       if (sub_zeile > 0 && sub_zeile <= NR_SMENU_O_LINES) {
  1085.         last_sub_zeile = sub_zeile;
  1086.       }
  1087.     }
  1088.     else {
  1089.       if (zeile == SMENU_L_START_LINE) {
  1090.         if (sub_zeile > 0 && sub_zeile <= NR_SMENU_L_LINES) {
  1091.           last_sub_zeile = sub_zeile;
  1092.         }
  1093.       }
  1094.       else {
  1095.         if (zeile == SMENU_R_START_LINE) {
  1096.           if (sub_zeile > 0 && sub_zeile <= show_state.menu_res_lines) {
  1097.             last_sub_zeile = sub_zeile;
  1098.           }
  1099.         }
  1100.         else {
  1101.           if (zeile == 2) {
  1102.             last_col = col;
  1103.           }
  1104.           else {
  1105.             if (zeile == 3) {
  1106.               last_col = col;
  1107.             }
  1108.           }
  1109.         }
  1110.       }
  1111.     }
  1112.   }
  1113.  
  1114.   ret = do_menu(menu,zeile,col,sub_zeile,x,y);
  1115.   return ((long)ret);
  1116. }
  1117.  
  1118.  
  1119. /****************************************************************************************/
  1120. /****************************************************************************************/
  1121. /****************************************************************************************/
  1122. /****************************************************************************************/
  1123.  
  1124.  
  1125. /************* OS MENU ******************/
  1126.  
  1127.  
  1128. static int os_menu_ready = FALSE;
  1129.  
  1130.  
  1131. struct MenuItem *MyItemAddress(unsigned long menuNumber)
  1132. {
  1133.   return ItemAddress(&DosMenu[0], menuNumber);
  1134. }
  1135.  
  1136.  
  1137. void init_os_menu(void)
  1138. {
  1139.   MyLayoutMenu();
  1140.   os_menu_ready = TRUE;
  1141.   set_checked_os_menu();
  1142. }
  1143.  
  1144.  
  1145. void free_os_menu(void)
  1146. {
  1147.   os_menu_ready = FALSE;
  1148. }
  1149.  
  1150.  
  1151. void set_checked_os_menu(void)
  1152. {
  1153.   short nr_res = show_state.menu_res_lines;
  1154.   short i;
  1155.   register struct Menu *men;
  1156.   
  1157.  
  1158.   if (!os_menu_ready) return;    // Menu nicht initialisiert!
  1159.  
  1160.  
  1161.   men = &(DosMenu[0]);
  1162.  
  1163.   if (win2 != NULL) {
  1164.     ClearDosMenu();    /* !!!!!! */
  1165.   }
  1166.  
  1167.   /* Das ganze CHECKED koennte man sich sparen. Nur wenn die Funktionen per Tastatur */
  1168.   /* aufgerufen wird muss das gemacht werden. Also mach ma´s immer. :-()         */
  1169.  
  1170.   for (i=0; i<nr_res; i++) {
  1171.     if (show_state.mres[i] == resolution) {
  1172.       FindMenuEntry(men, 3, i, NOSUB)->Flags |= CHECKED;
  1173.     }
  1174.     else {
  1175.       FindMenuEntry(men, 3, i, NOSUB)->Flags &= ~CHECKED;
  1176.     }
  1177.   }
  1178.  
  1179.   if (is_lace)  FindMenuEntry(men, 1, 2, NOSUB)->Flags |= CHECKED;    /* lace */
  1180.   else         FindMenuEntry(men, 1, 2, NOSUB)->Flags &= (~CHECKED);    /* lace */
  1181.  
  1182.   if (is_gadg)  FindMenuEntry(men, 1, 3, NOSUB)->Flags |= CHECKED;    /* scrollbar */
  1183.   else         FindMenuEntry(men, 1, 3, NOSUB)->Flags &= (~CHECKED);    /* scrollbar */
  1184.  
  1185.   if (is_show)  {
  1186.     FindMenuEntry(men, 1, 4, NOSUB)->Flags |= CHECKED;            /* full page */
  1187.     MenuAus(men, 1, 3, NOSUB);                         /* scrollbar */
  1188.   }
  1189.   else {
  1190.     FindMenuEntry(men, 1, 4, NOSUB)->Flags &= (~CHECKED);        /* full page */
  1191.     MenuAn(men, 1, 3, NOSUB);                        /* scrollbar */
  1192.   }
  1193.  
  1194.   if (is_messwin) FindMenuEntry(men, 1, 5, NOSUB)->Flags |= CHECKED;    /* mess-win */
  1195.   else          FindMenuEntry(men, 1, 5, NOSUB)->Flags &= (~CHECKED);    /* mess-win */
  1196.  
  1197.   if (is_dotbord) FindMenuEntry(men, 1, 6, NOSUB)->Flags |= CHECKED;    /* border line */
  1198.   else           FindMenuEntry(men, 1, 6, NOSUB)->Flags &= (~CHECKED);    /* border line */
  1199.  
  1200.   if (is_col4)    FindMenuEntry(men, 1, 9, NOSUB)->Flags |= CHECKED;    /* use 4 colors */
  1201.   else           FindMenuEntry(men, 1, 9, NOSUB)->Flags &= (~CHECKED);    /* use 4 colors */
  1202.  
  1203.   //if (is_pscro)   FindMenuEntry(men, 1, 10, NOSUB)->Flags |= CHECKED;    /* page scroll */
  1204.   //else         FindMenuEntry(men, 1, 10, NOSUB)->Flags &= (~CHECKED);    /* page scroll */
  1205.  
  1206.   if (is_usephy)  FindMenuEntry(men, 2, 12, NOSUB)->Flags |= CHECKED;    /* use phy */
  1207.   else           FindMenuEntry(men, 2, 12, NOSUB)->Flags &= (~CHECKED);/* use phy */
  1208.  
  1209.   if (is_autoag)  FindMenuEntry(men, 0, 4, NOSUB)->Flags |= CHECKED;    /* auto again */
  1210.   else           FindMenuEntry(men, 0, 4, NOSUB)->Flags &= (~CHECKED);    /* auto again */
  1211.  
  1212.  
  1213.   switch (show_state.whunit) {
  1214.     case 0:                                /* inch */
  1215.     FindMenuEntry(men, 1, 11, 0)->Flags |= CHECKED;
  1216.     FindMenuEntry(men, 1, 11, 1)->Flags &= (~CHECKED);
  1217.     FindMenuEntry(men, 1, 11, 2)->Flags &= (~CHECKED);
  1218.     break;
  1219.     case 1:                                /* cm */
  1220.     FindMenuEntry(men, 1, 11, 1)->Flags |= CHECKED;
  1221.     FindMenuEntry(men, 1, 11, 0)->Flags &= (~CHECKED);
  1222.     FindMenuEntry(men, 1, 11, 2)->Flags &= (~CHECKED);
  1223.     break;
  1224.     case 2:                                /* pt */
  1225.     FindMenuEntry(men, 1, 11, 2)->Flags |= CHECKED;
  1226.     FindMenuEntry(men, 1, 11, 0)->Flags &= (~CHECKED);
  1227.     FindMenuEntry(men, 1, 11, 1)->Flags &= (~CHECKED);
  1228.     break;
  1229.   }
  1230.  
  1231.   if (is_ownscr && is_myscr) {
  1232.     MenuAn(men, 1, 2, NOSUB);        /* lace */
  1233.     MenuAn(men, 1, 9, NOSUB);        /* 4 color */
  1234.     MenuAn(men, 1, 13, NOSUB);        /* clone wb color */
  1235.     MenuAn(men, 1, 12, NOSUB);        /* color */
  1236.   }
  1237.   else {
  1238.     MenuAus(men, 1, 2, NOSUB);        /* lace */
  1239.     MenuAus(men, 1, 9, NOSUB);        /* 4 color */
  1240.     MenuAus(men, 1, 13, NOSUB);        /* clone wb color */
  1241.     MenuAus(men, 1, 12, NOSUB);        /* color (nicht die Farbe eines fremden Screens aendern) */
  1242.   }
  1243.  
  1244.   if (!is_os2) {
  1245.     MenuAus(men, 0, 7, 1);    /* Execute command... */
  1246.     MenuAus(men, 0, 7, 2);    /* TeX script */
  1247.     MenuAus(men, 0, 7, 3);    /* ARexx TeX Shell */
  1248.     MenuAus(men, 0, 7, 4);    /* Set ENV:TEXFORMAT */
  1249.     MenuAus(men, 0, 7, 5);    /* SpecialHost */
  1250.     MenuAus(men, 1, 14, NOSUB);    /* set screen size */
  1251.   }
  1252.  
  1253.   if (!is_print) {
  1254.     MenuAn(men, 0, 2, NOSUB);                        /* load again */
  1255.     MenuAn(men, 0, 3, NOSUB);                        /* load new */
  1256.     //MenuAn(men, 1, 10, NOSUB);                    /* page scroll */
  1257.     MenuAn(men, 2, NOITEM, NOSUB);
  1258.     MenuAn(men, 3, NOITEM, NOSUB);
  1259.     // MenItem[MEN_PRINT].ItemFill = (APTR)&MenItem_Text[START_1+8];
  1260.   }
  1261.   else {
  1262.     MenuAus(men, 0, 2, NOSUB);                        /* load again */
  1263.     MenuAus(men, 0, 3, NOSUB);                        /* load new */
  1264.     //MenuAus(men, 1, 10, NOSUB);                    /* page scroll */
  1265.     MenuAus(men, 2, NOITEM, NOSUB);
  1266.     MenuAus(men, 3, NOITEM, NOSUB);
  1267.     // MenItem[MEN_PRINT].ItemFill = (APTR)&MenChars_Text[13];
  1268.   }
  1269.   if (is_dvif) {
  1270.     if (!is_print) {
  1271.       MenuAn(men, 0, 2, NOSUB);                        /* load again */
  1272.       MenuAn(men, 0, 9, NOSUB);                        /* print page */
  1273.       //MenuAn(men, 1, 10, NOSUB);                    /* page scroll */
  1274.       MenuAn(men, 2, NOITEM, NOSUB);
  1275.     }
  1276.     MenuAn(men, 1, 4, NOSUB);                        /* full page */
  1277.     MenuAn(men, 1, 5, NOSUB);                        /* mess win */
  1278.     MenuAn(men, 1, 6, NOSUB);                        /* border line */
  1279.   }
  1280.   else {
  1281.     MenuAus(men, 0, 2, NOSUB);                        /* load again */
  1282.     MenuAus(men, 0, 9, NOSUB);                        /* print page */
  1283.     MenuAus(men, 1, 5, NOSUB);                        /* mess win */
  1284.     MenuAus(men, 1, 6, NOSUB);                        /* border line */
  1285.     //MenuAus(men, 1, 10, NOSUB);                    /* page scroll */
  1286.     MenuAus(men, 1, 4, NOSUB);                        /* full page */
  1287.     MenuAus(men, 2, NOITEM, NOSUB);
  1288.   }
  1289.  
  1290. #if defined(REQ_LIBRARY)
  1291.   if (ReqBase == NULL) {
  1292.     MenuAus(men, 0, 3, NOSUB);            /* load new */
  1293.     MenuAus(men, 1, 12, NOSUB);            /* color */
  1294.   }
  1295. #endif
  1296.  
  1297.   if (win2 != NULL) {
  1298.     SetDosMenu();    /* !!!!!! */
  1299.   }
  1300. }
  1301.  
  1302.  
  1303. static struct TagItem system_tags[] = {
  1304.               { SYS_Input,    NULL    },
  1305.               { SYS_Output,    NULL    },
  1306.               { SYS_Asynch,    NULL    },
  1307.                           { TAG_DONE,    0L    },
  1308.   };
  1309.  
  1310.  
  1311.  
  1312.  
  1313. long work_with_os_menu(UBYTE MenuNum, UBYTE ItemNum, UBYTE SubNum)
  1314. {
  1315.   long ex = KOMM + 5L;
  1316.   long new_res;
  1317.   long page;
  1318.  
  1319.   /* die Abfrage nach is_print kann gespart werden, */
  1320.   /* da die Menues alle nicht anwaehlbar sind.      */
  1321.   /* Leider doch nicht mehr, da das Menue nun auch  */
  1322.   /* ueber ARexx angesprochen werden kann!        */
  1323.   /* Deshalb nun die Abfrage auf ITEMENABLED!        */
  1324.   /* MENUENABLED lass ich einfach ausser acht!!        */
  1325.   
  1326.   if (!FindMenuEntry(&(DosMenu[0]), MenuNum, ItemNum, SubNum)->Flags & ITEMENABLED) {
  1327.     return ex;
  1328.   }
  1329.  
  1330.   switch (MenuNum) {
  1331.     case 0:
  1332.       switch (ItemNum) {
  1333.     case 0:                /* About */
  1334.       AboutWinUp();
  1335.       break;
  1336.     case 2:                /* Open */
  1337.         if (is_dvif) {
  1338.           OpenNewDVI(filename, FALSE);
  1339.           ex = KOMM + 3L;        /* neues File, Name nicht geaendert. */
  1340.         }
  1341.         else {
  1342.           Message(MSG_NO_DVI_FILE);
  1343.           beep();
  1344.         }
  1345.       break;
  1346.     case 3:                /* Open new */
  1347.        if (!is_print) {
  1348.         ex = KOMM + LoadFileReq();
  1349.       }
  1350.       break;
  1351.     case 4:                /* auto load again */
  1352.           if (is_autoag ^ ((FindMenuEntry(&(DosMenu[0]), 0, 4, NOSUB)->Flags & CHECKED) != 0)) {
  1353.         ToggleAutoAgain();
  1354.       }
  1355.       break;
  1356.     case 5:                /* save as IFF file */
  1357.       if (is_dvif) {
  1358.         m_string[0] = '\0';
  1359.         if (MyGetString(GetTeXString(MSG_FILENAME), m_string)) {
  1360.               SavePageIFF(m_string);
  1361.             }
  1362.       }
  1363.       else {            /* noch kein DVI-File geladen */
  1364.         ex = KOMM + 7L;
  1365.       }
  1366.       break;
  1367.     case 7:                /* shell commands */
  1368.       switch (SubNum) {
  1369.         case 0:                        /* newcli */
  1370.               make_newcli(screen);
  1371.               break;
  1372.         case 1:                        /* execute command */
  1373.           if (is_os2) {
  1374.             char buf[200];
  1375.             *buf = '\0';
  1376.             if (MyGetString(GetTeXString(MSG_ENTER_COMMAND), buf)) {
  1377.               if (start_command(GetTeXString(MSG_EXECUTE_COMMAND), buf, NULL) != 0) {
  1378.                 Warning(MSG_CANT_EXECUTE_COMMAND);
  1379.               }
  1380.             }
  1381.           }
  1382.           break;
  1383.         case 2:
  1384.           execute_script(show_state.command, FALSE);    /* run command */
  1385.           break;
  1386.             case 3:                        /* TeX-Server */
  1387.               if (is_os2) {
  1388.                 char buf[MAXPUBSCREENNAME+1];
  1389.                 struct Screen *pscr = NULL;
  1390.                 int loop = TRUE;
  1391.                 
  1392.                 strcpy(buf, GetCurrentPubScr());
  1393.                 while (loop) {
  1394.                   if (MyGetString(GetTeXString(MSG_USE_WHICH_PUBSCR), buf)) {
  1395.                     if ((pscr = LockPubScreen(buf)) == NULL) {
  1396.                       int k = MySimpleRequest(3, NULL, NULL, "New", NULL, 
  1397.               GetTeXString(MSG_DONT_FIND_PUBSCR_USE_WB), buf);
  1398.               if (k == 0) {
  1399.                 return ex;        /* CANCEL */
  1400.               }
  1401.               else if (k == 1) {    /* OK */
  1402.             loop = FALSE;
  1403.             strcpy(buf, "Workbench");
  1404.             pscr = LockPubScreen(buf);
  1405.               }
  1406.               else {            /* NEW */
  1407.                 ;
  1408.               }
  1409.                     }
  1410.                     else {
  1411.                       loop = FALSE;    /* PubScr gefunden */
  1412.                     }
  1413.                   }
  1414.                 }
  1415.                 /* (void)SetVar("TeXServer-PubScr-Name", buf, -1,GVF_GLOBAL_ONLY); */
  1416.                 sprintf(m_string, "%s %s", show_state.arexxstart, buf);
  1417.         if (start_command(GetTeXString(MSG_SHOWDVI_TEX_SHELL), m_string, buf) != 0) {
  1418.           Warning(MSG_CANT_START, show_state.arexxstart);
  1419.         }
  1420.           if (pscr != NULL) {
  1421.             UnlockPubScreen(NULL, pscr);
  1422.           }
  1423.               }
  1424.               break;
  1425.         case 4:            /* change format */
  1426.           if (is_os2) {
  1427.             ChangeFormatFile();
  1428.           }
  1429.           break;
  1430.             case 5:            /* call SpecialHost */
  1431.               if (is_os2) {
  1432.                 if (start_command(GetTeXString(MSG_START_SPECIALHOST), "SpecialHost", NULL) != 0) {
  1433.             Warning(MSG_CANT_START, "SpecialHost");
  1434.           }
  1435.               }
  1436.               break;
  1437.         default:
  1438.           Warning(MSG_UNKNOWN_SUBITEM, (int)MenuNum, (int)ItemNum, (int)SubNum);
  1439.       }
  1440.       break;
  1441.     case 9:                /* Print page */
  1442.       printing();
  1443.       break;
  1444.     case 11:            /* WB to front */
  1445.       (void)WBenchToFront();
  1446.       make_old_active();
  1447.       break;
  1448.     case 12:            /* Hide */
  1449.       ScreenToBack(screen);
  1450.       make_old_active();
  1451.       break;
  1452.     case 13:            /* save config */
  1453.       write_config_file();
  1454.       break;
  1455.     case 15:            /* Quit */
  1456.       if (real_prog_end()) {
  1457.         Enable_Abort = 0;        /* am Ende nicht noch ein ^C */
  1458.         ex = KOMM + 10L;
  1459.       }
  1460.       break;
  1461.     default:
  1462.       Warning(MSG_UNKNOWN_SUBMENU, (int)MenuNum, (int)ItemNum, (int)SubNum);
  1463.       }
  1464.       break;
  1465.     case 1:
  1466.       switch (ItemNum) {
  1467.         case 0:                /* copy */
  1468.       if (is_dvif) {
  1469.             SavePageIFF("CLIP");
  1470.       }
  1471.       else {            /* noch kein DVI-File geladen */
  1472.         ex = KOMM + 7L;
  1473.       }
  1474.           break;
  1475.     case 2:                /* lace */
  1476.       if (is_lace ^ ((FindMenuEntry(&(DosMenu[0]), 1, 2, NOSUB)->Flags & CHECKED) != 0)) {
  1477.         if (is_show) {
  1478.           show_full_page(FALSE);      /* show-Modus ausschalten */
  1479.         }
  1480.         change_resolution();
  1481.       }
  1482.       break;
  1483.     case 3:                /* scrollbar */
  1484.       if (is_gadg ^ ((FindMenuEntry(&(DosMenu[0]), 1, 3, NOSUB)->Flags & CHECKED) != 0)) {
  1485.         if (!is_show) {
  1486.           toggle_scrollbar(FALSE);
  1487.         }
  1488.       }
  1489.       break;
  1490.     case 4:                /* full page */
  1491.       if (is_show ^ ((FindMenuEntry(&(DosMenu[0]), 1, 4, NOSUB)->Flags & CHECKED) != 0)) {
  1492.         if (is_dvif) {
  1493.           show_full_page(FALSE);
  1494.           ex = KOMM + 5L;
  1495.         }
  1496.         else {            /* noch kein DVI-File geladen */
  1497.           ex = KOMM + 7L;
  1498.         }
  1499.       }
  1500.       break;
  1501.     case 5:                /* mess window */
  1502.       if (is_messwin ^ ((FindMenuEntry(&(DosMenu[0]), 1, 5, NOSUB)->Flags & CHECKED) != 0)) {
  1503.         ToggleMessWin(-1, -1);
  1504.       }
  1505.       break;
  1506.     case 6:                /* dotted border line */
  1507.       if (is_dotbord ^ ((FindMenuEntry(&(DosMenu[0]), 1, 6, NOSUB)->Flags & CHECKED) != 0)) {
  1508.           if (is_dvif) {
  1509.           DrawDottedBorder(TRUE, FALSE);    /* toggle == TRUE, no_refresh == FALSE */
  1510.         }
  1511.         else {
  1512.           ex = KOMM + 7L;
  1513.         }
  1514.       }
  1515.       break;
  1516.     case 8:                /* set margin point */
  1517.       SetupMargin();
  1518.       break;
  1519.     case 9:                /* 4 colors -- 2 colors */
  1520.       if (is_col4 ^ ((FindMenuEntry(&(DosMenu[0]), 1, 9, NOSUB)->Flags & CHECKED) != 0)) {
  1521.         ToggleColorDepth();
  1522.       }
  1523.       break;
  1524.     case 11:                /* UNIT */
  1525.       switch (SubNum) {
  1526.         case 0:
  1527.           set_unit_in;
  1528.           break;
  1529.         case 1:
  1530.           set_unit_cm;
  1531.           break;
  1532.         case 2:
  1533.           set_unit_pt;
  1534.           break;
  1535.         default:
  1536.           Warning(MSG_UNKNOWN_SUBITEM, (int)MenuNum, (int)ItemNum, (int)SubNum);
  1537.       }
  1538.       SetUpMessWin(FALSE);        /* no delta */
  1539.       break;
  1540.     case 12:            /* color */
  1541.       show_col_request();
  1542.       break;
  1543.     case 13:            /* clone wb color */
  1544.       { int old = is_clwbcol;
  1545.         set_clwbcol;
  1546.         init_screen_colors();
  1547.         if (!old) unset_clwbcol;
  1548.         set_screen_colors();
  1549.       }
  1550.       break;
  1551.     case 14:            /* set screen size */
  1552.       if (is_os2) {
  1553.         TogglePrefWin();
  1554.       }
  1555.       break;
  1556.     default:
  1557.       Warning(MSG_UNKNOWN_SUBMENU, (int)MenuNum, (int)ItemNum, (int)SubNum);
  1558.       }
  1559.       break;
  1560.     case 2:
  1561.       if (ItemNum == 13 || ItemNum == 14 || ItemNum == 15 ||ItemNum == 16) {
  1562.     set_tusephy;
  1563.       }
  1564.       switch (ItemNum) {
  1565.         case 0:                /* search string */
  1566.           ex = KOMM + StartSearch(SO_OpenSearchWin);
  1567.           break;
  1568.     case 2:                /* prev page */
  1569.     case 13:
  1570.       ex = KOMM - 1L;
  1571.       break;
  1572.     case 3:                /* next page */
  1573.     case 14:
  1574.       ex = KOMM + 1L;
  1575.       break;
  1576.     case 4:                /* first page */
  1577.     case 15:
  1578.       ex = KOMM - 2L;
  1579.       break;
  1580.     case 5:                /* last page */
  1581.     case 16:
  1582.       ex = KOMM + 2L;
  1583.       break;
  1584.     case 8:                /* jump to page... */
  1585.       if (is_pscro) {
  1586. #if 0
  1587.         blatt_ok_gad(&page);
  1588.         if (page != 0L) {
  1589.           ex = page;
  1590.         }
  1591. #endif
  1592.       }
  1593.       else {
  1594.         page = clear_counter(0);
  1595.         if (page != -1) {
  1596.           ex = page;
  1597.           if (ex == 0) ex = -1;    /* hack for page number 0 (intui_message) */
  1598.         }
  1599.       }
  1600.       break;
  1601.     case 9:                /* clear page counter */
  1602.       (void)clear_counter(0);
  1603.       break;
  1604.     case 12:            /* use physical numbering */
  1605.           if (is_usephy ^ ((FindMenuEntry(&(DosMenu[0]), 2, 12, NOSUB)->Flags & CHECKED) != 0)) {
  1606.             toggle_usephy;
  1607.         write_status();
  1608.         Set_PgGadPageCur();
  1609.       }
  1610.       break;
  1611.     default:
  1612.       Warning(MSG_UNKNOWN_SUBMENU, (int)MenuNum, (int)ItemNum, (int)SubNum);
  1613.       }
  1614.       break;
  1615.     case 3:
  1616.       new_res = show_state.mres[ItemNum];
  1617.       if (new_res != resolution) {
  1618.     resolution = new_res;
  1619.     hconvresolution = resolution;
  1620.     vconvresolution = resolution;
  1621.     if (is_dvif) {
  1622.       OpenNewDVI(filename, TRUE);
  1623.       set_chres;
  1624.       if (is_show) {
  1625.         show_full_page(TRUE); /* full-page modus off (no_refresh=TRUE) */
  1626.       }
  1627.       ex = KOMM +3L;          /* neues File, Name nicht geaendert. */
  1628.     }
  1629.     set_checked_os_menu();
  1630.       }
  1631.       break;
  1632.     default:
  1633.     Warning(MSG_UNKNOWN_MENU, (int)MenuNum, (int)ItemNum, (int)SubNum);
  1634.   }
  1635.   
  1636.   if (ex == KOMM + 7L) {
  1637.     Message(MSG_NO_DVI_FILE);
  1638.     beep();
  1639.     ex = KOMM + 5L;
  1640.   }
  1641.  
  1642.   return ex;
  1643. }
  1644.  
  1645.  
  1646.  
  1647. void work_with_os_help_menu(UBYTE MenuNum, UBYTE ItemNum, UBYTE SubNum)
  1648. {
  1649.   char *ptr, line[128], pattern[40];
  1650.   char *buffer;
  1651.   int len, found;
  1652.   FILE *fp;
  1653.  
  1654.   fp = OpenConfigFile("ShowDVI.help", MODE_READ);
  1655.  
  1656.   if (fp == NULL) {
  1657.     Warning(MSG_CANT_OPEN_HELP_FILE, "ShowDVI.help");
  1658.   }
  1659.   else {
  1660.     /* so nun auf die Suche nach dem Menu-Eintrag */
  1661.     sprintf(pattern, "#menu (%d, %d, %d)", (int)MenuNum, (int)ItemNum, (int)SubNum);
  1662.     len = strlen(pattern);
  1663.  
  1664.     /* suche den Anfang der Hilfe... */
  1665.     do {
  1666.       ptr = fgets(line, 127, fp);
  1667.       found = (strncmp(line, pattern, len) == 0);
  1668.     } while (ptr != NULL && !found);
  1669.     
  1670.     if (found) {
  1671.       /* Anfang gefunden, nun muss der Text zusammengesetzt und ausgegeben werden */
  1672.       buffer = xmalloc(4000*sizeof(char));
  1673.       *buffer = '\0';
  1674.       line[127] = '\0';
  1675.       do {
  1676.         ptr = fgets(line, 127, fp);
  1677.         if (ptr == NULL || *ptr == '#') {
  1678.           found = FALSE;
  1679.         }
  1680.         else {
  1681.           strcat(buffer, line);
  1682.         }
  1683.       } while (found);
  1684.       
  1685.       ptr = strrchr(&(buffer[0]), '\n');
  1686.       if (ptr != NULL) *ptr = '\0';    /* letztes Return kommt weg */
  1687.  
  1688.       if (MenuNum == 3 && ItemNum != NOITEM) { /* resolution Menu */
  1689.         if (ItemNum < show_state.menu_res_lines) {
  1690.           MySimpleRequest(1, NULL, NULL, NULL, GetTeXString(MSG_SHOWDVI_MENU_HELP), buffer, (long)show_state.mres[ItemNum]);
  1691.         }
  1692.       }
  1693.       else {
  1694.         if (MenuNum == 0 && ItemNum == 6) {
  1695.           switch (SubNum) {
  1696.             case 2:  MySimpleRequest(1, NULL, NULL, NULL, GetTeXString(MSG_SHOWDVI_MENU_HELP), buffer, show_state.command, GetCurrentPubScr());
  1697.              break;
  1698.         case 3:  MySimpleRequest(1, NULL, NULL, NULL, GetTeXString(MSG_SHOWDVI_MENU_HELP), buffer,
  1699.             show_state.arexxstart, GetCurrentPubScr());
  1700.              break;
  1701.         default: MySimpleRequest(1, NULL, NULL, NULL, GetTeXString(MSG_SHOWDVI_MENU_HELP), buffer);
  1702.              break;
  1703.           }
  1704.         }
  1705.         else {
  1706.           MySimpleRequest(1, NULL, NULL, NULL, GetTeXString(MSG_SHOWDVI_MENU_HELP), buffer);
  1707.         }
  1708.       }
  1709.       xfree(buffer);
  1710.     }
  1711.     else {
  1712.       Warning(MSG_NO_HELP_FOR_MENU, (int)MenuNum, (int)ItemNum, (int)SubNum);
  1713.     }
  1714.     fclose(fp);
  1715.   }
  1716.   
  1717.   set_checked_os_menu();    /* das muss sein nach einer Help-Msg.. */
  1718. }
  1719.  
  1720.  
  1721.  
  1722. static struct MenuItem *FindMenuEntry(struct Menu *Menu, short menunum, short itemnum, short subnum)
  1723. {
  1724.   int i;
  1725.   struct Menu *men;
  1726.   struct MenuItem *item, *sub, *ret;
  1727.   int reason = 3;
  1728.   
  1729.   for (men = Menu, i = 0; men != NULL && i < menunum; men = men->NextMenu, i++) ;
  1730.   if (men == NULL) {
  1731.     ret = NULL;
  1732.     reason = 1;
  1733.   }
  1734.   else {
  1735.     for (item = men->FirstItem, i = 0; item != NULL && i < itemnum; item = item->NextItem, i++) ;
  1736.     if (item == NULL) {
  1737.       ret = NULL;
  1738.       reason = 2;
  1739.     }
  1740.     else {
  1741.       if (subnum == NOSUB) {
  1742.         ret = item;
  1743.       }
  1744.       else {
  1745.         for (sub = item->SubItem, i = 0; sub != NULL && i < subnum; sub = sub->NextItem, i++) ;
  1746.         ret = sub;
  1747.       }
  1748.     }
  1749.   }
  1750.   
  1751.   if (ret == NULL) {
  1752.     Fatal(29,MSG_INTERNAL_ERROR_MENU_ENTRY, menunum, itemnum, subnum, reason);
  1753.   }
  1754.   
  1755.   return ret;
  1756. }
  1757.  
  1758.  
  1759.  
  1760. /* MenuAnAus macht fast das selbe wie On/Off/MEnu(), nur dass es nicht ein eigenes */
  1761. /* Clear() Set() macht, sondern innerhalb eines solchen aufgerufen wird.           */
  1762. /* Dies ist erheblich schneller, falls mehr ein oder ausgeschalten werden soll.    */
  1763.  
  1764. static void MenuAnAus(struct Menu *Men, short menunum, short item, short sub, short on)
  1765. {
  1766.   struct Menu *m;
  1767.   int i;
  1768.   /* struct IntuiText *txt; */
  1769.  
  1770.   if (item == NOITEM) {
  1771.     for (m = Men, i = 0; m != NULL && i < menunum; m = m->NextMenu, i++) ;
  1772.     if (m != NULL) {
  1773.       if (on) {
  1774.         m->Flags |= MENUENABLED;
  1775.         /* printf("Enable Menu %s\n", m->MenuName); */
  1776.       }
  1777.       else {
  1778.         m->Flags &= (~MENUENABLED);
  1779.         /* printf("Disable Menu %s\n", m->MenuName); */
  1780.       }
  1781.     }
  1782.   }
  1783.   else {
  1784.     if (on) {
  1785.       FindMenuEntry(Men, menunum, item, sub)->Flags |= ITEMENABLED;
  1786.       /* txt = FindMenuEntry(Men, menunum, item, sub)->ItemFill; printf("Enable Item %s\n", txt->IText);*/
  1787.     }
  1788.     else {
  1789.       FindMenuEntry(Men, menunum, item, sub)->Flags &= (~ITEMENABLED);
  1790.       /* txt = FindMenuEntry(Men, menunum, item, sub)->ItemFill; printf("Disable Item %s\n", txt->IText);*/
  1791.     }
  1792.   }
  1793. }
  1794.  
  1795.  
  1796.  
  1797.  
  1798. static void MyLayoutMenu(void)
  1799. {
  1800.   register struct RastPort *rp;
  1801.   struct MenuItem *mi, *mih;
  1802.   int spacelen, len;
  1803.  
  1804.   if (screen == NULL || !is_os2) return;
  1805.  
  1806.   rp = &(screen->RastPort);  
  1807.   
  1808.   if (rp == NULL) return;
  1809.  
  1810.  
  1811.   spacelen = TextLength(rp, "m", 1);
  1812.  
  1813.   DosMenu = xmalloc(4 * sizeof(struct Menu));
  1814.   
  1815.   DosMenu[0].NextMenu = &(DosMenu[1]);
  1816.   DosMenu[0].MenuName = GetTeXString(MSG_PROJECT_MENU);
  1817.   DosMenu[0].LeftEdge = 0;
  1818.   len = TextLength(rp, DosMenu[0].MenuName, strlen(DosMenu[0].MenuName)) + spacelen;
  1819.   DosMenu[0].Width = len;
  1820.  
  1821.   DosMenu[1].NextMenu = &(DosMenu[2]);
  1822.   DosMenu[1].MenuName = GetTeXString(MSG_OUTFIT_MENU);
  1823.   DosMenu[1].LeftEdge = DosMenu[0].LeftEdge + DosMenu[0].Width + spacelen;
  1824.   len = TextLength(rp, DosMenu[1].MenuName, strlen(DosMenu[1].MenuName)) + spacelen;
  1825.   DosMenu[1].Width = len;
  1826.  
  1827.   DosMenu[2].NextMenu = &(DosMenu[3]);
  1828.   DosMenu[2].MenuName = GetTeXString(MSG_MOVE_MENU);
  1829.   DosMenu[2].LeftEdge = DosMenu[1].LeftEdge + DosMenu[1].Width + spacelen;
  1830.   len = TextLength(rp, DosMenu[2].MenuName, strlen(DosMenu[2].MenuName)) + spacelen;
  1831.   DosMenu[2].Width = len;
  1832.  
  1833.   DosMenu[3].NextMenu = NULL;
  1834.   DosMenu[3].MenuName = GetTeXString(MSG_RESOLUTION_MENU);
  1835.   DosMenu[3].LeftEdge = DosMenu[2].LeftEdge + DosMenu[2].Width + spacelen;
  1836.   len = TextLength(rp, DosMenu[3].MenuName, strlen(DosMenu[3].MenuName)) + spacelen;
  1837.   DosMenu[3].Width = len;
  1838.   
  1839.   DosMenu[0].Flags = DosMenu[1].Flags = DosMenu[2].Flags = DosMenu[3].Flags = MENUENABLED;
  1840.   DosMenu[0].Height = DosMenu[1].Height = DosMenu[2].Height = DosMenu[3].Height = screen->BarHeight;
  1841.   DosMenu[0].TopEdge = DosMenu[1].TopEdge = DosMenu[2].TopEdge = DosMenu[3].TopEdge = 0;
  1842.   
  1843.  
  1844.   mi = LayoutOneMenu(rp, ProjectMenu, MEN_1_ENTRIES, spacelen, 0);
  1845.   DosMenu[0].FirstItem = mih = mi;
  1846.  
  1847.   mi = LayoutOneMenu(rp, ProjectShellMenu, 6, spacelen, mi[0].Width);
  1848.   mih[7].SubItem = mi;
  1849.  
  1850.   mi = LayoutOneMenu(rp, OutfitMenu, MEN_2_ENTRIES, spacelen, 0);
  1851.   DosMenu[1].FirstItem = mih = mi;
  1852.  
  1853.   mi = LayoutOneMenu(rp, OutfitUnitMenu, 3, spacelen, mi[0].Width);
  1854.   mi[0].MutualExclude = ~1;
  1855.   mi[1].MutualExclude = ~2;
  1856.   mi[2].MutualExclude = ~3;
  1857.   mih[11].SubItem = mi;
  1858.  
  1859.   mi = LayoutOneMenu(rp, MoveMenu, MEN_3_ENTRIES, spacelen, 0);
  1860.   DosMenu[2].FirstItem = mi;
  1861.  
  1862.   /* spacelen = TextLength(rp, "8888", 1); */
  1863.   mi = LayoutOneMenu(rp, NULL, MEN_4_ENTRIES, spacelen, 0);
  1864.   DosMenu[3].FirstItem = mi;
  1865.   mi[show_state.menu_res_lines-1].NextItem = NULL;
  1866. }
  1867.  
  1868.  
  1869.  
  1870. static struct MenuItem *LayoutOneMenu(struct RastPort *rp, struct MenuLayout *MLay,
  1871.                 int NrEntries, int spacelen, int width)
  1872. {
  1873.   /* MLay == NULL => wir sind beim Resolution Menu! */
  1874.  
  1875.   register struct MenuItem *mi;
  1876.   register struct IntuiText *it;
  1877.   struct IntuiText *itArr;
  1878.   int i;
  1879.   int maxlen, maxlen2, max, len, len2, lineheight, pos;
  1880.  
  1881.   mi = xmalloc(NrEntries * sizeof(struct MenuItem));
  1882.  
  1883.   lineheight = rp->Font->tf_YSize+1;
  1884.  
  1885.   /*
  1886.    * Achtung: Es *muss* gelten: sizeof(struct Image) < sizeof(struct IntuiText)
  1887.    */
  1888.   itArr = xmalloc(NrEntries * sizeof(struct IntuiText));
  1889.  
  1890.   maxlen = maxlen2 = max = 0;
  1891.  
  1892.   for (i=0; i<NrEntries; i++) {
  1893.  
  1894.     /* zuerst wird die Menue Struktur aufgebaut */
  1895.  
  1896.     mi[i] = DefaultMenuItem;
  1897.     if (i < NrEntries-1) {
  1898.       mi[i].NextItem = &(mi[i+1]);
  1899.     }
  1900.     else {
  1901.       mi[i].NextItem = NULL;
  1902.     }
  1903.  
  1904.     if (MLay == NULL) {
  1905.       /* Resolution Menu */
  1906.       char buf[8];
  1907.       sprintf(buf, "%d", i+1);
  1908.       if (i<9) {
  1909.         mi[i].Command = buf[0];
  1910.         mi[i].Flags = DEFFLAGS|MENUTOGGLE|CHECKIT|COMMSEQ;
  1911.       }
  1912.       else {
  1913.         mi[i].Command = '\0';
  1914.         mi[i].Flags = DEFFLAGS|MENUTOGGLE|CHECKIT;
  1915.       }
  1916.       mi[i].MutualExclude = ~(i+1);
  1917.     }
  1918.     else {
  1919.       mi[i].Command = MLay[i].Command;
  1920.       mi[i].Flags = MLay[i].Flags;
  1921.     }
  1922.  
  1923.     /* nun wird die IText Struktur aufgebaut */
  1924.  
  1925.     it = &(itArr[i]);
  1926.     *it = DefaultIText;
  1927.  
  1928.     // V39 Menue Farben setzen
  1929.     if (SDVI_DRI && SDVI_DRI->dri_Version >= 2) {
  1930.       it->FrontPen = SDVI_DRI->dri_Pens[BARDETAILPEN];
  1931.       it->BackPen  = SDVI_DRI->dri_Pens[BARBLOCKPEN];
  1932.     }
  1933.  
  1934.     //printf("dri vers: %d, front: %d, back: %d, det: %d, block: %d\n",
  1935.     //    SDVI_DRI->dri_Version, it->FrontPen, it->BackPen, BARDETAILPEN, BARBLOCKPEN);
  1936.  
  1937.     if (mi[i].Flags & CHECKIT) {
  1938.       it->LeftEdge = CHECKWIDTH;
  1939.     }
  1940.     if (MLay != NULL) {
  1941.       if (MLay[i].Special & SPECIAL_EMPTY) {
  1942.         ;    /* es wird ein Image verwendet */
  1943.       }
  1944.       else {
  1945.         it->IText = GetTeXString(MLay[i].StringNr);
  1946.         if (MLay[i].RightString || (MLay[i].Special & SPECIAL_HAS_SUB)) {
  1947.           struct IntuiText * rit = xmalloc(sizeof(struct IntuiText));
  1948.           *rit = DefaultIText;
  1949.  
  1950.           // V39 Menue Farben setzen
  1951.           if (SDVI_DRI && SDVI_DRI->dri_Version >= 2) {
  1952.             rit->FrontPen = SDVI_DRI->dri_Pens[BARDETAILPEN];
  1953.             rit->BackPen  = SDVI_DRI->dri_Pens[BARBLOCKPEN];
  1954.           }
  1955.  
  1956.           if (MLay[i].RightString){
  1957.             rit->IText = MLay[i].RightString;
  1958.           }
  1959.           else {
  1960.             rit->IText = "»";
  1961.           }
  1962.  
  1963.           it->NextText = rit;
  1964.         }
  1965.         else {
  1966.           it->NextText = NULL;
  1967.         }
  1968.       }
  1969.     }
  1970.     else {
  1971.       /* dann sind wir im Resolution Menu */
  1972.       char buf[20];
  1973.       sprintf(buf,"%4ld dpi",((i<show_state.menu_res_lines) ? (long)show_state.mres[i] : 0));
  1974.       it->IText = strdup(buf);
  1975.       it->NextText = NULL;
  1976.     }
  1977.  
  1978.  
  1979.     if (MLay && MLay[i].Special & SPECIAL_EMPTY) {
  1980.       mi[i].ItemFill = xmalloc(sizeof(struct Image));
  1981.       ((struct Image *)mi[i].ItemFill)->NextImage = xmalloc(sizeof(struct Image));
  1982.     }
  1983.     else {
  1984.       mi[i].ItemFill = (APTR)it;
  1985.     }
  1986.  
  1987.  
  1988.  
  1989.     /* linker Teil */
  1990.     if (it->IText == NULL) {
  1991.       len = 0;
  1992.     }
  1993.     else {
  1994.       len = TextLength(rp, it->IText, strlen(it->IText));
  1995.     }
  1996.  
  1997.     if (mi[i].Flags & CHECKIT) {
  1998.       len += CHECKWIDTH;
  1999.     }
  2000.     if (len > maxlen) maxlen = len;
  2001.  
  2002.     /* rechter Teil */
  2003.     len2 = 0;
  2004.     if (mi[i].Flags & COMMSEQ) {
  2005.       char str[2];    /* zur Sicherheit, damit ich nicht & auf BYTE mache */
  2006.       str[0] = mi[i].Command;
  2007.       str[1] = '\0';
  2008.       len2 = COMMWIDTH + TextLength(rp, str, 1);
  2009.     }
  2010.     if (it->NextText != NULL) {
  2011.       len2 += TextLength(rp, it->NextText->IText, strlen(it->NextText->IText));
  2012.     }
  2013.     if (len2 > maxlen2) maxlen2 = len2;
  2014.     if (len+len2 > max) max = len+len2;
  2015.   }
  2016. #if 0
  2017.   len = maxlen + maxlen2 + spacelen*2 + 2;    /* Breite des Menues */
  2018. #else
  2019.   len = max + spacelen*2 + 2;            /* Ueberlappende Breite */
  2020. #endif
  2021.   
  2022.  
  2023.   /* und nun wird das Menue aufgebaut */
  2024.   pos = 0;
  2025.   for (i=0; i<NrEntries; i++) {
  2026.     it = (struct IntuiText *)mi[i].ItemFill;
  2027.  
  2028.     mi[i].TopEdge = pos;
  2029.     if (MLay && MLay[i].Special & SPECIAL_IS_SUB) {
  2030.       mi[i].LeftEdge = width*3/5;
  2031.     }
  2032.     mi[i].Width = len;
  2033.     if (MLay && MLay[i].Special & SPECIAL_EMPTY) {
  2034.       register struct Image * img = (struct Image *)it;
  2035.       mi[i].Height = lineheight/2;
  2036.       img->Depth    = 1;
  2037.       img->TopEdge  = (mi[i].Height-1)/2;
  2038.       img->LeftEdge = 1;
  2039.       img->Height   = 0;
  2040.       img->Width    = 0; //len-2;
  2041.       if (is_os3) img->PlaneOnOff = 1;
  2042.       img->NextImage->Depth    = 1;
  2043.       img->NextImage->TopEdge  = img->TopEdge;
  2044.       img->NextImage->LeftEdge = 1;
  2045.       img->NextImage->Height   = 2;
  2046.       img->NextImage->Width    = len-2;
  2047.       if (is_os3) img->NextImage->PlaneOnOff = 1;
  2048.       //img->NextImage = NULL;
  2049.     }
  2050.     else {
  2051.       mi[i].Height = lineheight;
  2052.     }
  2053.     pos += mi[i].Height;
  2054.  
  2055.     if (!MLay || !(MLay[i].Special & SPECIAL_EMPTY)) {
  2056.       it->ITextFont = NULL;
  2057.       it->TopEdge = 1;
  2058.       if (it->NextText && it->NextText->IText) {
  2059.         int tmplen = TextLength(rp, it->NextText->IText, strlen(it->NextText->IText));
  2060.       
  2061.         //printf("X rp: %x, it: %x, it->NextText: %x, it->NextText->IText: %x\n", 
  2062.         //    rp, it, it->NextText, it->NextText->IText);
  2063.       
  2064.         if (tmplen < spacelen) tmplen = spacelen;
  2065. #if 0
  2066.         it->NextText->LeftEdge = maxlen + spacelen*2 + maxlen2 - tmplen;
  2067. #else
  2068.         it->NextText->LeftEdge = max + spacelen*2 - tmplen;
  2069. #endif
  2070.         it->NextText->ITextFont = NULL;
  2071.         it->TopEdge = 1;
  2072.       }
  2073.     }
  2074.   }
  2075.   
  2076.   return mi;
  2077. }
  2078.  
  2079.  
  2080. #endif /* AMIGA */
  2081.