home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / motifpg2.zip / ch04 / xbitmap1.c < prev    next >
C/C++ Source or Header  |  1992-07-08  |  6KB  |  203 lines

  1. /*
  2.  * Copyright 1989, 1992 O'Reilly and Associates, Inc.
  3.  * See ../Copyright for complete rights and liability information.
  4.  */
  5.  
  6. /* 
  7.  *  xbitmap1.c - bitmap in main window with help and quit
  8.  */
  9.  
  10. /*  So that we can use fprintf: */
  11. #include <stdio.h>
  12.  
  13. /* Standard Toolkit include files: */
  14. #include <X11/Intrinsic.h>
  15. #include <Xm/Xm.h>
  16.  
  17. /* Public include files for widgets used in this file.  */
  18. #include <Xm/PushB.h>   /* push button */
  19. #include <Xm/MainW.h>    /* main window */
  20. #include <Xm/MessageB.h> /* message box */
  21. #include <Xm/CascadeB.h> /* cascade button */
  22. #include <Xm/RowColumn.h>/* row column (for menus) */
  23.  
  24. #include "BitmapEdit.h"
  25.  
  26. /*
  27.  * The printout routine prints an array of 1s and 0s representing the
  28.  * contents of the bitmap.  This data can be processed into any
  29.  * desired form, including standard X11 bitmap file format.
  30.  */
  31. /* ARGSUSED */
  32. static void 
  33. PrintOut(widget, client_data, call_data)
  34. Widget widget;
  35. XtPointer client_data;   /* cast to bigBitmap */
  36. XtPointer call_data;    /* unused */
  37. {
  38.     Widget bigBitmap = (Widget) client_data;
  39.     int x, y;
  40.     int width_in_cells, height_in_cells;
  41.     char *cell;
  42.  
  43.     cell = BitmapEditGetArray(bigBitmap, &width_in_cells, 
  44.              &height_in_cells);
  45.  
  46.     (void) putchar('\n');
  47.     for (y = 0; y < height_in_cells; y++) {
  48.         for (x = 0; x < width_in_cells; x++)
  49.             (void) putchar(cell[x + y * width_in_cells] ? '1' : '0');
  50.         (void) putchar('\n');
  51.     }
  52.     (void) putchar('\n');
  53. }
  54.  
  55. /* 
  56.  * callback to pop up help dialog widget 
  57.  */
  58. /*ARGSUSED*/
  59. void ShowHelp(w, client_data, call_data)
  60. Widget w;
  61. XtPointer client_data;
  62. XtPointer call_data;
  63. {
  64.     Widget dialog = (Widget) client_data;
  65.     XtManageChild(dialog);
  66. }
  67.  
  68. /*
  69.  * quit button callback function
  70.  */
  71. /*ARGSUSED*/
  72. void Quit(w, client_data, call_data)
  73. Widget w;
  74. XtPointer client_data, call_data;
  75.     exit(0); 
  76. }
  77.  
  78. main(argc, argv)
  79. int argc;
  80. char **argv;
  81. {
  82.     XtAppContext app_context;
  83.     Widget topLevel, mainWindow, menuBar;
  84.     Widget fileButton, fileMenu, quit, helpButton, helpMenu, help, helpBox;
  85.     Widget temp;
  86.     Widget bigBitmap, output;
  87.  
  88.     /* never call a Widget variable "exit"! */
  89.     extern exit();
  90.  
  91.     static XrmOptionDescRec table[] = {
  92.         {"-pw",            "*pixmapWidthInCells",        XrmoptionSepArg, NULL},
  93.         {"-pixmapwidth",   "*pixmapWidthInCells",        XrmoptionSepArg, NULL},
  94.         {"-ph",            "*pixmapHeightInCells",       XrmoptionSepArg, NULL},
  95.         {"-pixmapheight",  "*pixmapHeightInCells",       XrmoptionSepArg, NULL},
  96.         {"-cellsize",      "*cellSizeInPixels",           XrmoptionSepArg, NULL},
  97.  
  98.     };
  99.     
  100.     XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
  101.  
  102.     topLevel = XtVaAppInitialize( &app_context, "XBitmap1",
  103.             table, XtNumber(table), &argc, argv, NULL, NULL);
  104.  
  105.     /* create main window */
  106.     mainWindow = XtVaCreateManagedWidget( "mainWindow",
  107.             xmMainWindowWidgetClass, topLevel, NULL);
  108.  
  109.     /* create menu bar along top inside of main window */
  110.     menuBar = XmCreateMenuBar( mainWindow, "menuBar",
  111.             (ArgList) NULL, (Cardinal) 0);
  112.     XtManageChild(menuBar);
  113.  
  114.     bigBitmap = XtVaCreateManagedWidget("bigBitmap", 
  115.             bitmapEditWidgetClass, mainWindow, 
  116.             NULL);
  117.  
  118.     /*  Set MainWindow areas */
  119.     XmMainWindowSetAreas (mainWindow, menuBar, NULL, NULL, NULL,
  120.             bigBitmap);
  121.  
  122.     /*
  123.      *  CREATE FILE MENU AND CHILDREN
  124.      */
  125.  
  126.     /* create button that will pop up the menu */
  127.     fileButton = XtVaCreateManagedWidget("fileButton",
  128.             xmCascadeButtonWidgetClass, menuBar, NULL);
  129.  
  130.     /* create menu (really a Shell widget and RowColumn widget combo) */
  131.     fileMenu = XmCreatePulldownMenu( menuBar,
  132.             "fileMenu", NULL, 0);
  133.  
  134.     /*
  135.      *  CREATE BUTTON TO OUTPUT BITMAP
  136.      */
  137.  
  138.     /* create button that will pop up the menu */
  139.     output = XtVaCreateManagedWidget( "output",
  140.             xmPushButtonWidgetClass, fileMenu, NULL);
  141.  
  142.     XtAddCallback(output, XmNactivateCallback, PrintOut, bigBitmap);
  143.  
  144.     /* create the quit button up in the menu */
  145.     quit = XtVaCreateManagedWidget( "quit",
  146.             xmPushButtonWidgetClass, fileMenu, NULL);
  147.  
  148.     /* 
  149.      * Specify which menu fileButton will pop up.
  150.      */
  151.     XtVaSetValues(fileButton,
  152.             XmNsubMenuId, fileMenu,
  153.             NULL);
  154.  
  155.     /* arrange for quit button to call function that exits. */
  156.     XtAddCallback(quit, XmNactivateCallback, Quit, 0);
  157.  
  158.     /*
  159.      *  CREATE HELP BUTTON AND BOX
  160.      */
  161.  
  162.     /* create button that will bring up help menu */
  163.     helpButton = XtVaCreateManagedWidget( "helpButton",
  164.         xmCascadeButtonWidgetClass, menuBar, NULL);
  165.  
  166.     /* tell menuBar which is the help button (will be specially positioned) */
  167.     XtVaSetValues(menuBar,
  168.           XmNmenuHelpWidget, helpButton,
  169.           NULL);
  170.  
  171.     /* create menu (really a Shell widget and RowColumn widget combo) */
  172.     helpMenu = XmCreatePulldownMenu( menuBar,
  173.             "helpMenu", NULL, 0);
  174.  
  175.     /* create the help button up in the menu */
  176.     help = XtVaCreateManagedWidget( "help",
  177.             xmPushButtonWidgetClass, helpMenu, NULL);
  178.  
  179.     /* 
  180.      * Specify which menu helpButton will pop up.
  181.      */
  182.     XtVaSetValues(helpButton,
  183.           XmNsubMenuId, helpMenu,
  184.           NULL);
  185.  
  186.     /* create popup that will contain help */
  187.     helpBox = XmCreateMessageDialog( help,
  188.             "helpBox", NULL, 0);
  189.  
  190.     temp = XmMessageBoxGetChild (helpBox, XmDIALOG_CANCEL_BUTTON);
  191.     XtUnmanageChild (temp);
  192.     temp = XmMessageBoxGetChild (helpBox, XmDIALOG_HELP_BUTTON);
  193.     XtUnmanageChild (temp);
  194.  
  195.     /* arrange for getHelp button to pop up helpBox */
  196.     XtAddCallback(help, XmNactivateCallback, ShowHelp, helpBox);
  197.  
  198.     XtRealizeWidget(topLevel);
  199.  
  200.     XtAppMainLoop(app_context);
  201. }
  202.