home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / iv26_w_3.zip / EXAMPLES / ALERT / ALERT.C next >
C/C++ Source or Header  |  1992-03-30  |  3KB  |  108 lines

  1. /*
  2.  *  alert - displays a message in a dialog box at centre screen
  3.  */
  4.  
  5. #include <InterViews/button.h>
  6. #include <InterViews/box.h>
  7. #include <InterViews/dialog.h>
  8. #include <InterViews/font.h>
  9. #include <InterViews/frame.h>
  10. #include <InterViews/glue.h>
  11. #include <InterViews/message.h>
  12. #include <InterViews/painter.h>
  13. #include <InterViews/world.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. static PropertyData props[] = {
  18.     { "*quitbutton", "OK, OK ..." },
  19.     { "*font", "9x15" },
  20.     { "*transient", "on" },
  21.     { nil }
  22. };
  23.  
  24. static OptionDesc options[] = {
  25.     { "font=", "*font", OptionValueAfter },
  26.     { "button=", "*quitbutton", OptionValueAfter },
  27.     { "-top", "*transient", OptionValueImplicit, "off" },
  28.     { nil }
  29. };
  30.  
  31. static Interactor* MakeDialog(ButtonState*, const char*);
  32.  
  33. int IVMain (int argc, char** argv) {
  34.     World* world = new World("alert", props, options, argc, argv);
  35.  
  36.     ButtonState* quit = new ButtonState;
  37.     Interactor* body = MakeDialog(quit, world->GetAttribute("quitbutton"));
  38.  
  39.     Dialog* dialog;
  40.     Coord x = world->Width() / 2;
  41.     Coord y = world->Height() / 2;
  42.     if (strcmp(world->GetAttribute("transient"), "on") == 0) {
  43.     dialog = new Dialog(quit, new ShadowFrame(body));
  44.     world->InsertTransient(dialog, dialog, x, y, Center);
  45.     } else {
  46.     dialog = new Dialog(quit, body);
  47.     world->Insert(dialog, x, y, Center);
  48.     }
  49.     world->RingBell(0);
  50.     return dialog->Accept() ? 0 : 1;
  51. }
  52.  
  53. static Interactor* MakeMessage(Button*);
  54.  
  55. static Interactor* MakeDialog (ButtonState* quit, const char* label) {
  56.     return new VBox(
  57.     new VGlue(round(.25*inch)),
  58.     new HBox(
  59.         new HGlue(round(.5*inch)),
  60.         MakeMessage(new PushButton(label, quit, true)),
  61.         new HGlue(round(.5*inch))
  62.     ),
  63.     new VGlue(round(.25*inch))
  64.     );
  65. }
  66.  
  67. static Interactor* MakeMessage (Button* quit) {
  68.     VBox* b;
  69.     char buffer[1024];
  70.     char* s;
  71.     int n;
  72.     char* strings[] = { { "First message\n" },
  73.                         { "Second message\n" },
  74.                         { "This is the third message\n" } };
  75.  
  76.     b = new VBox;
  77.  
  78.     for (int i = 0; i < 3; i++) {
  79.         strcpy(buffer, strings[i]);
  80.     n = strlen(buffer) - 1;
  81.     if (buffer[n] == '\n') {
  82.         buffer[n] = '\0';
  83.     } else {
  84.         ++n;
  85.     }
  86.     s = new char[n + 1];
  87.     strcpy(s, buffer);
  88.     b->Insert(new HBox(new Message(s), new HGlue));
  89.     }
  90.  
  91.  
  92. /*    while (fgets(buffer, sizeof(buffer), stdin) != nil) {
  93.     n = strlen(buffer) - 1;
  94.     if (buffer[n] == '\n') {
  95.         buffer[n] = '\0';
  96.     } else {
  97.         ++n;
  98.     }
  99.     s = new char[n + 1];
  100.     strcpy(s, buffer);
  101.     b->Insert(new HBox(new Message(s), new HGlue));
  102.     }
  103. */
  104.     b->Insert(new VGlue(round(.25*inch)));
  105.     b->Insert(new HBox(new HGlue, quit));
  106.     return b;
  107. }
  108.