home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / adaptor / src / xmenu.c < prev    next >
C/C++ Source or Header  |  1993-07-08  |  20KB  |  410 lines

  1. /****************************************************************************
  2. *                                                                           *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                             *
  4. *  Date        : Nov 92                                                     *
  5. *  Last Update : Jan 93                                *
  6. *                                                                           *
  7. *  Module      : xmenu                                                      *
  8. *                                                                           *
  9. *  Function    : *****                                                      *
  10. *                                                                           *
  11. *  Export :                                                                 *
  12. *                                                                           *
  13. *    xmenu (int argc, char ** argv);                                        *
  14. *                                                                           *
  15. *                                                                           *
  16. *     topLevel :  frame    -------------------------------------------      *
  17. *                          | logo commands                           |      *
  18. *                          |                                         |      *
  19. *                          |      filelabel                          |      *
  20. *                          |                                         |      *
  21. *                          |      message_widget                     |      *
  22. *                          -------------------------------------------      *
  23. *                          | vp_mytext                               |      *
  24. *                          |                                         |      *
  25. *                          |                                         |      *
  26. *                          |                                         |      *
  27. *                          -------------------------------------------      *
  28. *                          | label_units           label_vars        |      *
  29. *                          -------------------------------------------      *
  30. *                          | vp_units              vp_vars           |      *
  31. *                          |                                         |      *
  32. *                          -------------------------------------------      *
  33. *                                                                           *
  34. *                                                                           *
  35. ****************************************************************************/
  36.  
  37. #include "xglobal.h"
  38. #include "xcommands.h"
  39. #include "xunits.h"
  40. #include "xhelp.h"            /* show_help         */
  41. #include "xoptions.h"         /* KeyTranslations   */
  42.  
  43. #define HIGH 0                /* HIGH = 1 for higher widget */
  44.  
  45. /****************************************************************************
  46. *                                                                           *
  47. *   GMD Bitmap                                                              *
  48. *                                                                           *
  49. ****************************************************************************/
  50.  
  51. #define gmd_width 56
  52. #define gmd_height 56
  53. static char gmd_bits[] = {
  54.    0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0xff, 0xff, 0xff,
  55.    0xff, 0x7f, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x03, 0x00, 0x00,
  56.    0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03,
  57.    0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  58.    0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00,
  59.    0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00,
  60.    0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
  61.    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00,
  62.    0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00,
  63.    0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03,
  64.    0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  65.    0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00,
  66.    0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00,
  67.    0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
  68.    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00,
  69.    0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00,
  70.    0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03,
  71.    0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  72.    0xc0, 0x03, 0x70, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0, 0x80, 0x00,
  73.    0x30, 0x80, 0xc1, 0x03, 0x80, 0x81, 0x01, 0x30, 0x00, 0xc3, 0x03, 0x00,
  74.    0x83, 0x01, 0x30, 0x00, 0xc6, 0x03, 0x07, 0x03, 0x03, 0x30, 0x3c, 0xcc,
  75.    0x83, 0xe3, 0x03, 0x03, 0x30, 0x7c, 0xcc, 0xc3, 0xe1, 0x03, 0x06, 0x30,
  76.    0x4c, 0xcc, 0xc3, 0x00, 0x00, 0x06, 0x30, 0x0c, 0xcc, 0xc3, 0x00, 0x40,
  77.    0x0c, 0x30, 0x0c, 0xcc, 0xc3, 0x00, 0x43, 0x0c, 0x32, 0x0c, 0xcc, 0xc3,
  78.    0x00, 0xc3, 0x18, 0x32, 0x0c, 0xcc, 0xc3, 0x00, 0xc3, 0x18, 0x33, 0x0c,
  79.    0xcc, 0xc3, 0x38, 0xc3, 0x10, 0x33, 0x0c, 0xcc, 0xc3, 0x38, 0xc3, 0x80,
  80.    0x31, 0x0c, 0xcc, 0xc3, 0x00, 0xc3, 0x80, 0x31, 0x0c, 0xcc, 0x83, 0x01,
  81.    0xc3, 0xc0, 0x30, 0x0c, 0xcc, 0x03, 0x00, 0xc3, 0xc0, 0x30, 0x00, 0xc6,
  82.    0x33, 0x30, 0xc3, 0x60, 0x30, 0x00, 0xc3, 0xf3, 0xff, 0xf3, 0x70, 0x3c,
  83.    0xff, 0xc1, 0xc3, 0xef, 0xf3, 0x30, 0x3c, 0xff, 0xc0, 0x03, 0x00, 0x00,
  84.    0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x06,
  85.    0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
  86.    0x7f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f};
  87.  
  88. void create_pixmap ()
  89. {
  90.    /* set global gmdPixmap */
  91.  
  92.    gmdPixmap = XCreatePixmapFromBitmapData (
  93.           XtDisplay (topLevel),
  94.           RootWindowOfScreen (XtScreen (topLevel)),
  95.           gmd_bits, gmd_width, gmd_height,
  96.           1, 0, 1);
  97.  
  98. }
  99.  
  100. void update_pixmap ()
  101.  
  102. {
  103.         if (DefaultDepthOfScreen (XtScreen(gmdBitmap)) == 1)
  104.            XCopyArea (XtDisplay (gmdBitmap), gmdPixmap, XtWindow (gmdBitmap),
  105.                    DefaultGCOfScreen (XtScreen (gmdBitmap)), 0, 0,
  106.                    gmd_width, gmd_height, 0, 0);
  107.          else
  108.            XCopyPlane(XtDisplay (gmdBitmap), gmdPixmap, XtWindow (gmdBitmap),
  109.                    DefaultGCOfScreen (XtScreen (gmdBitmap)), 0, 0,
  110.                    gmd_width, gmd_height, 0, 0, 1);
  111.  
  112. }
  113.  
  114. /****************************************************************************
  115. *                                                                           *
  116. *   END of  GMD Bitmap                                                      *
  117. *                                                                           *
  118. ****************************************************************************/
  119.  
  120. Widget frame;  /* global used */
  121. xmenu (argc, argv)
  122. int argc;
  123. char **argv;
  124. {
  125.     XtAppContext app_context;
  126.     Widget vp_units, vp_vars, label_units, label_vars;
  127.     Arg args[20];
  128.     int n;
  129.  
  130.     static XtActionsRec window_actions[] = {
  131.     { "update_pixmap", update_pixmap },
  132.     { "show_help", show_help},
  133.     { "return_key", return_key},
  134.     { "is_no_digit_or_return", is_no_digit_or_return}
  135.     };
  136.  
  137.     /* Initialization of the global file variable */
  138.  
  139.     strcpy (selected_file, PHOME);
  140.     strcat (selected_file, "/welcome");
  141.  
  142.     strcpy (last_message, "No Errors.");
  143.  
  144.     /* Displays the welcome message at the beginning of the session */
  145.  
  146. /****************************************************************************
  147. *                                                                           *
  148. *  topLevel :  frame                                                        *
  149. *                                                                           *
  150. ****************************************************************************/
  151.  
  152.     topLevel = XtVaAppInitialize(
  153.         &app_context,       /* Application context */
  154.         "XAdapt",            /* Application class */
  155.         NULL, 0,            /* command line option list */
  156.         &argc, argv,        /* command line args */
  157.         NULL,               /* for missing app-defaults file */
  158.         NULL);              /* terminate varargs list */
  159.  
  160. /****************************************************************************
  161. *                                                                           *
  162. *  formWidget                                                               *
  163. *                                                                           *
  164. *  frame :  commands                                                        *
  165. *           vp_text, vp_units, vp_vars                                      *
  166. *                                                                           *
  167. ****************************************************************************/
  168.  
  169.         frame = XtCreateManagedWidget(
  170.                 "frame",                      /* widget name */
  171.                 formWidgetClass,              /* widget class */
  172.                 topLevel,                     /* parent widget*/
  173.                 NULL, 0);                     /* terminate varargs list */
  174.                 
  175. /****************************************************************************
  176. *                                                                           *
  177. *  bitmapWidget: gmdBitmap                                                  *
  178. *                                                                           *
  179. ****************************************************************************/
  180.  
  181.         XtAppAddActions (app_context, window_actions,
  182.                           XtNumber (window_actions));
  183.  
  184.         n = 0;
  185.         XtSetArg (args[n], XtNlabel, "GMD");  n++;
  186.         XtSetArg (args[n], XtNvertDistance, 10);  n++;
  187.         XtSetArg (args[n], XtNwidth, gmd_width); n++;
  188.         XtSetArg (args[n], XtNheight, gmd_height); n++;
  189.         XtSetArg (args[n], XtNborderWidth, 0);  n++;
  190.         XtSetArg (args[n], XtNtranslations,
  191.           XtParseTranslationTable ("<Expose>:  update_pixmap()")); n++;
  192.  
  193.         gmdBitmap = XtCreateManagedWidget ("GMD",
  194.                     widgetClass, frame, args, n);
  195.  
  196.         make_help_available (gmdBitmap);
  197.  
  198. /****************************************************************************
  199. *                                                                           *
  200. *  boxWidget : commands                                                     *
  201. *                                                                           *
  202. ****************************************************************************/
  203.  
  204.         n = 0;
  205.         XtSetArg (args[n], XtNfromHoriz, gmdBitmap);  n++;
  206.         XtSetArg (args[n], XtNhorizDistance, 10);  n++;
  207.         XtSetArg (args[n], XtNwidth, MyTextWidth); n++; 
  208.         XtSetArg (args[n], XtNborderWidth, 0); n++; 
  209.  
  210.         commands = XtCreateManagedWidget(
  211.                 "commands",                    /* widget name */
  212.                 boxWidgetClass,        /* widget class */
  213.                 frame,                     /* parent widget*/
  214.                 args, n);                  /* terminate varargs list */
  215.  
  216.         make_commands (commands);
  217.  
  218. /****************************************************************************
  219. *                                                                           *
  220. *  labelWidget : filelabel                                                  *
  221. *                                                                           *
  222. ****************************************************************************/
  223.  
  224.         n = 0;
  225.         XtSetArg (args[n], XtNvertDistance, 5);  n++;
  226.         XtSetArg (args[n], XtNhorizDistance, 10);  n++;
  227.         XtSetArg (args[n], XtNfromVert, commands);  n++;
  228.         XtSetArg (args[n], XtNfromHoriz, gmdBitmap);  n++;
  229.         XtSetArg (args[n], XtNborderWidth, 0);  n++;
  230.         XtSetArg (args[n], XtNlabel, selected_file);  n++;
  231.  
  232.         filelabel = XtCreateManagedWidget (
  233.                  "filelabel",
  234.                  labelWidgetClass,
  235.                  frame,
  236.                  args, n);
  237.  
  238. /****************************************************************************
  239. *                                                                           *
  240. *  labelWidget : message_widget                                             *
  241. *                                                                           *
  242. ****************************************************************************/
  243.  
  244.         n = 0;
  245.         XtSetArg (args[n], XtNvertDistance, 5);  n++;
  246.         XtSetArg (args[n], XtNfromVert, filelabel);  n++;
  247.         XtSetArg (args[n], XtNfromHoriz, gmdBitmap);  n++;
  248.         XtSetArg (args[n], XtNhorizDistance, 10);  n++;
  249.         XtSetArg (args[n], XtNborderWidth, 3);  n++;
  250.         XtSetArg (args[n], XtNlabel, last_message);  n++;
  251.  
  252.         message_widget = XtCreateManagedWidget (
  253.                  "message",
  254.                  labelWidgetClass,
  255.                  frame,
  256.                  args, n);
  257.  
  258. /****************************************************************************
  259. *                                                                           *
  260. *  viewportWidget : vp_mytext                                               *
  261. *                                                                           *
  262. ****************************************************************************/
  263.  
  264.         n = 0;
  265.         XtSetArg (args[n], XtNheight, MyTextHeight); n++; 
  266.         XtSetArg (args[n], XtNwidth, MyTextWidth);  n++;
  267.         XtSetArg (args[n], XtNvertDistance, 10);  n++;
  268.         XtSetArg (args[n], XtNfromVert, message_widget);  n++;
  269.  
  270.         vp_mytext = XtCreateManagedWidget (
  271.                     "mytext",
  272.                     viewportWidgetClass,
  273.                     frame,
  274.                     args, n);  /* will be managed when filename is set */
  275.        
  276.         n = 0;
  277.  
  278.         XtSetArg (args[n], XtNeditType, XawtextRead);  n++;
  279.         XtSetArg (args[n], XtNtype, XawAsciiFile);  n++;
  280.         XtSetArg (args[n], XtNstring, selected_file);  n++;
  281.         /* XtSetArg (args[n], XtNscrollVertical, 1);  n++;
  282.            XtSetArg (args[n], XtNscrollHorizontal, 1);  n++; */
  283.  
  284.         mytext = XtCreateManagedWidget (
  285.                  "editor",
  286.                  asciiTextWidgetClass,
  287.                  vp_mytext,
  288.                  args, n);  /* will be managed when filename is set */
  289.  
  290.         make_help_available (mytext);
  291.  
  292.         /* units is a list widget that contains unit entries */
  293.  
  294. /****************************************************************************
  295. *                                                                           *
  296. *  labelWidget : label_units                                                *
  297. *                                                                           *
  298. ****************************************************************************/
  299.  
  300.         n = 0;
  301.         if (HIGH == 1)
  302.           { XtSetArg (args[n], XtNvertDistance, 10);  n++;
  303.             XtSetArg (args[n], XtNfromVert, vp_mytext);  n++;  
  304.           }
  305.          else
  306.           { XtSetArg (args[n], XtNvertDistance, 10);  n++;
  307.             XtSetArg (args[n], XtNfromVert, message_widget);  n++;
  308.             XtSetArg (args[n], XtNhorizDistance, 10);  n++;
  309.             XtSetArg (args[n], XtNfromHoriz, vp_mytext);  n++;
  310.           }
  311.         XtSetArg (args[n], XtNborderWidth, 0);  n++;
  312.         XtSetArg (args[n], XtNlabel,
  313.                            "Units (program, subroutine, function)");  n++;
  314.  
  315.         label_units = XtCreateManagedWidget (
  316.                  "units",
  317.                  labelWidgetClass,
  318.                  frame,
  319.                  args, n);
  320.  
  321.         make_help_available (label_units);
  322.  
  323. /****************************************************************************
  324. *                                                                           *
  325. *  viewportWidget : vp_units                                                *
  326. *                                                                           *
  327. ****************************************************************************/
  328.  
  329.         n = 0;
  330.         XtSetArg (args[n], XtNvertDistance, 10);  n++;
  331.         XtSetArg (args[n], XtNfromVert, label_units);  n++;
  332.         if (HIGH != 1)
  333.          { XtSetArg (args[n], XtNhorizDistance, 10);  n++;
  334.            XtSetArg (args[n], XtNfromHoriz, vp_mytext);  n++;
  335.          }
  336.         XtSetArg (args[n], XtNheight, MyUnitHeight); n++; 
  337.         XtSetArg (args[n], XtNwidth, MyUnitWidth);  n++;  
  338.         XtSetArg (args[n], XtNallowHoriz, TRUE);  n++;
  339.         XtSetArg (args[n], XtNallowVert, TRUE);  n++;
  340.  
  341.         vp_units = XtCreateManagedWidget(
  342.                 "vp_units",                        /* widget name */
  343.                 viewportWidgetClass,            /* widget class */
  344.                 frame,                        /* parent widget*/
  345.                 args, n);                     /* terminate varargs list */
  346.  
  347.         init_units (vp_units);
  348.  
  349. /****************************************************************************
  350. *                                                                           *
  351. *  labelWidget : label_vars                                                 *
  352. *                                                                           *
  353. ****************************************************************************/
  354.  
  355.         n = 0;
  356.         XtSetArg (args[n], XtNvertDistance, 10);  n++;
  357.         XtSetArg (args[n], XtNhorizDistance, 10);  n++;
  358.         if (HIGH == 1)
  359.           { XtSetArg (args[n], XtNfromVert, vp_mytext);  n++;
  360.             XtSetArg (args[n], XtNfromHoriz, vp_units);  n++; }
  361.          else
  362.           { XtSetArg (args[n], XtNfromVert, vp_units);  n++;
  363.             XtSetArg (args[n], XtNfromHoriz, vp_mytext);  n++; }
  364.         XtSetArg (args[n], XtNborderWidth, 0);  n++;
  365.         XtSetArg (args[n], XtNlabel, "Definitions in a unit");  n++;
  366.  
  367.         label_vars = XtCreateManagedWidget (
  368.                  "definitions",
  369.                  labelWidgetClass,
  370.                  frame,
  371.                  args, n);
  372.  
  373.         make_help_available (label_vars);
  374.  
  375. /****************************************************************************
  376. *                                                                           *
  377. *  viewportWidget : vp_vars                                                 *
  378. *                                                                           *
  379. ****************************************************************************/
  380.  
  381.         /* vars is a list widget that contains var entries */
  382.  
  383.         n = 0;
  384.         XtSetArg (args[n], XtNvertDistance, 10);  n++;
  385.         XtSetArg (args[n], XtNfromVert, label_vars);  n++;
  386.         XtSetArg (args[n], XtNhorizDistance, 10);  n++;
  387.         if (HIGH == 1)
  388.            { XtSetArg (args[n], XtNfromHoriz, vp_units);  n++; }
  389.           else
  390.            { XtSetArg (args[n], XtNfromHoriz, vp_mytext);  n++; }
  391.         XtSetArg (args[n], XtNwidth, MyVarWidth);  n++;
  392.         XtSetArg (args[n], XtNheight, MyVarHeight);  n++;
  393.         XtSetArg (args[n], XtNallowHoriz, TRUE);  n++;
  394.         XtSetArg (args[n], XtNallowVert, TRUE);  n++;
  395.  
  396.         vp_vars = XtCreateManagedWidget(
  397.                 "vp_vars",                        /* widget name */
  398.                 viewportWidgetClass,            /* widget class */
  399.                 frame,                        /* parent widget*/
  400.                 args, n);                     /* terminate varargs list */
  401.  
  402.         init_vars (vp_vars);
  403.  
  404.         create_pixmap ();
  405.  
  406.         XtRealizeWidget(topLevel);
  407.  
  408.         XtAppMainLoop(app_context);
  409. }
  410.