home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1990 / 12 / entsming.asc < prev    next >
Text File  |  1990-11-15  |  8KB  |  320 lines

  1. _EXAMINING THE ZINC INTERFACE LIBRARY_
  2. by Gary Entsminger
  3.  
  4. [LISTING ONE]
  5.  
  6. //database/field window code
  7. // Construct a window databaselike window.
  8.  
  9. + new UIW_PROMPT(38, 0, "#", WOF_NO_FLAGS)
  10. + new UIW_NUMBER(40, 0, 6, &recordNumber, "",
  11.   NMF_NO_FLAGS, WOF_NO_ALLOCATE_DATA | WOF_NON_SELECTABLE)
  12.  
  13. + new UIW_PROMPT(2, 1, "Name......", WOF_NO_FLAGS)
  14. + new UIW_STRING(15, 1, 27, tmpRecord.name, 26,
  15.   STF_NO_FLAGS, WOF_BORDER | WOF_NO_ALLOCATE_DATA)
  16.  
  17. + new UIW_PROMPT(2, 2, "Address...", WOF_NO_FLAGS)
  18. + new UIW_STRING(15, 2, 27, tmpRecord.address1, 26,
  19.   STF_NO_FLAGS, WOF_BORDER | WOF_NO_ALLOCATE_DATA)
  20.  
  21. + new UIW_STRING(15, 3, 27, tmpRecord.address2, 26,
  22.   STF_NO_FLAGS, WOF_BORDER | WOF_NO_ALLOCATE_DATA)
  23.  
  24. + new UIW_PROMPT(2, 4, "Phone.....", WOF_NO_FLAGS)
  25. + new UIW_FORMATTED_STRING(15, 4, 27, tmpRecord.phone,
  26.   "LNNNLLNNNLCCCC", "(...) ...-....", WOF_BORDER
  27.   | WOF_NO_ALLOCATE_DATA);
  28.  
  29. [LISTING TWO]
  30.  
  31. // Line Editor example using Zinc Interface Library -- (c) Gary Entsminger
  32.  
  33. #include <ui_win.hpp>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37.  
  38. // Derive a new class which adds File I/O to a window.
  39. class Line_editor: public UIW_WINDOW
  40. {
  41. public :
  42.    Line_editor();      // Constructor
  43.   ~Line_editor();      // Destructor
  44.    char * line_buffer[64];
  45.  };  // end class Line_editor declaration
  46.  
  47. // Define Line_editor's constructor
  48. Line_editor :: Line_editor() : UIW_WINDOW(2,2,70,5,
  49.                        WOF_NO_FLAGS, WOAF_NO_FLAGS)
  50. {
  51. FILE *textfile; // pointer to file
  52. char ln[64];    // local char array to hold lines read from file
  53.  
  54.    // Open file
  55.    if ((textfile = fopen("mk.bat", "r")) == NULL)
  56.    {
  57.       printf("Error opening text file\n Aborting.");
  58.       exit(0);
  59.    }
  60.  
  61.    // Read first 64 characters of file
  62.    fseek(textfile,SEEK_SET,0);
  63.    fread(ln,64,1,textfile);
  64.  
  65.    // Close file
  66.    fclose(textfile);
  67.  
  68.   strcpy(*line_buffer,ln);
  69. }  // end Line_editor constructor
  70.  
  71.   //  Define Line_editor's destructor.
  72. Line_editor:: ~Line_editor()
  73. {
  74. FILE *textfile; // pointer to file
  75. char ln[64];  // char array to hold a line read from file
  76.  
  77.   // Open Make file (MK.BAT)
  78.    if ((textfile = fopen("mk.bat", "w")) == NULL)
  79.    {
  80.       printf("Error opening text file. Aborting. \n");
  81.       exit(0);
  82.    }
  83.  
  84. // Write edited text to the file
  85. strcpy(ln,*line_buffer);
  86. fwrite(ln,64,1,textfile);
  87.  
  88.    // Close file
  89.  fclose(textfile);
  90.  
  91. } // end destructor.
  92.  
  93. main()
  94. {
  95. // Construct the display, trying for graphics first.
  96. UI_DISPLAY *display = new UI_DOS_BGI_DISPLAY;
  97. if (!display->installed)
  98. {
  99. delete display;
  100. display = new UI_DOS_TEXT_DISPLAY;
  101. }
  102.  
  103. // Construct the event manager and add three devices to it.
  104. UI_EVENT_MANAGER *eventManager =
  105.   new UI_EVENT_MANAGER(100, display);
  106.  
  107. *eventManager
  108.                   + new UI_BIOS_KEYBOARD
  109.                   + new UI_MS_MOUSE
  110.                   + new UI_CURSOR;
  111.  
  112. // Construct the window manager.
  113. UI_WINDOW_MANAGER *windowManager =
  114.    new UI_WINDOW_MANAGER(display, eventManager);
  115.  
  116. // Construct a new Line_editor in window 1.
  117. Line_editor *window1 = new Line_editor();
  118.  
  119. // Construct a new string field for the Line_editor in window1.
  120. UIW_STRING *stringfield = new UIW_STRING(1,1,64,
  121.              *window1->line_buffer, 64,
  122.              STF_NO_FLAGS, WOF_NO_ALLOCATE_DATA);
  123.  
  124. // Add the window objects to the line_editor in window 1.
  125. *window1
  126. + new UIW_BORDER
  127. + new UIW_MAXIMIZE_BUTTON
  128. + new UIW_MINIMIZE_BUTTON
  129. + new UIW_SYSTEM_BUTTON
  130. + new UIW_TITLE("MAKE .BAT editor", WOF_JUSTIFY_CENTER)
  131. + stringfield;  // Add the string field we constructed to window1
  132.  
  133. // Add  window1 to the window manager.
  134. *windowManager + window1;
  135.  
  136. // Loop for user response.
  137. int ccode;
  138. UI_EVENT event;
  139.  
  140. do
  141. {
  142. // Get input from the user.
  143. eventManager->Get(event, Q_NORMAL);
  144.  
  145. // Send event information to the window manager.
  146. ccode = windowManager->Event(event);
  147. }
  148. while (ccode != L_EXIT && ccode != S_NO_OBJECT);
  149.  
  150. // Manually decouple stringfield from window1. Destruct all the objects we 
  151. // constructed in the opposite order in which we created them.
  152. *window1 - stringfield;
  153. delete stringfield;
  154. delete window1;
  155. delete windowManager;
  156. delete eventManager;
  157. delete display;
  158. } // end main.
  159.  
  160.  
  161. [LISTING THREE]
  162.  
  163. #include <ui_win.hpp>
  164. #include "editor.hlh"
  165.  
  166. main()
  167. {
  168. // Initialize the display, try for graphics first.
  169. UI_DISPLAY *display = new UI_DOS_BGI_DISPLAY;
  170. if (!display->installed)
  171. {
  172.    delete display;
  173.    display = new UI_DOS_TEXT_DISPLAY;
  174. }
  175.  
  176. // Initialize the event manager.
  177. UI_EVENT_MANAGER *eventManager = new UI_EVENT_MANAGER(100, display);
  178. *eventManager + new UI_BIOS_KEYBOARD + new UI_MS_MOUSE + new
  179. UI_CURSOR;
  180.  
  181. // Initialize the window manager.
  182. UI_WINDOW_MANAGER *windowManager =
  183.    new UI_WINDOW_MANAGER(display, eventManager);
  184.  
  185. // Initialize the help window system.
  186. _helpSystem = new UI_HELP_WINDOW_SYSTEM("notepad.hlp",
  187.    windowManager, HELP_GENERAL);
  188.  
  189. // Initialize the error window system.
  190. _errorSystem = new UI_ERROR_WINDOW_SYSTEM;
  191.  
  192. // Create a field editor window.
  193. UIW_WINDOW *editor = new UIW_WINDOW(4, 5, 66, 12,
  194.     WOF_NO_FLAGS, WOAF_NO_FLAGS);
  195.  
  196. // Add window objects to editor.
  197. *editor
  198.   + new UIW_BORDER
  199.   + new UIW_MAXIMIZE_BUTTON
  200.   + new UIW_MINIMIZE_BUTTON
  201.   + new UIW_SYSTEM_BUTTON
  202.   + new UIW_TITLE("FieldEditor", WOF_JUSTIFY_CENTER)
  203.  
  204.   + new UIW_PROMPT(2, 1, "To:", WOF_NO_FLAGS)
  205.   + new UIW_STRING(6, 1, 15, "Dr. Dobbs folk", 40, STF_NO_FLAGS,
  206.     WOF_BORDER)
  207.  
  208.   + new UIW_PROMPT(28, 1, "Date:", WOF_NO_FLAGS)
  209.   + new UIW_DATE(35, 1, 20, &UI_DATE(), "",
  210.         DTF_SYSTEM | DTF_ALPHA_MONTH, WOF_BORDER,
  211.                 NO_HELP_CONTEXT)
  212.  
  213.   + new UIW_PROMPT(2, 2, "Message:", WOF_NO_FLAGS)
  214.   + new UIW_TEXT(2, 3, 60, 4, "", 1028, TXF_NO_FLAGS, WOF_BORDER);
  215.  
  216. // Add field editor to the window manager.
  217. *windowManager + editor;
  218.  
  219. // Wait for user response.
  220. int ccode;
  221. UI_EVENT event;
  222. do
  223. {
  224.     eventManager->Get(event, Q_NORMAL);
  225.     ccode = windowManager->Event(event);
  226. } while (ccode != L_EXIT && ccode != S_NO_OBJECT);
  227.  
  228. // Clean up.
  229.   delete _helpSystem;
  230.   delete _errorSystem;
  231.   delete windowManager;
  232.   delete eventManager;
  233.   delete display;
  234. }
  235.  
  236.  
  237. // Contents of editor.hlh........
  238. // This file was created by the GENHELP utility.
  239.  
  240. const int HELP_GENERAL = 1;   // General Help
  241. const int HELP_EDITOR  = 2;   // Editor  Help
  242.  
  243.  
  244. [Example 1]
  245.  
  246. class AnyType : public Node
  247. {
  248.    AnyType;  // constructor
  249.   ~AnyType;  // destructor
  250.   virtual void Action; { } // abstract inline
  251. };
  252.  
  253.  
  254.  
  255.  
  256. [Example 2]
  257.  
  258. // Construct a graphics display if possible.
  259. UI_DISPLAY *display = new UI_DOS_BGI_DISPLAY;
  260. if (!display ->installed)
  261.     // if this system can't handle graphics,
  262.     // delete the graphics
  263.     // display we just created with new.
  264. {
  265.    delete display;
  266.    // then create a text display.
  267.    display = new UI_DOS_TEXT_DISPLAY;
  268. }
  269.   // Construct an event manager.
  270. UI_EVENT_MANAGER *eventManager =
  271.    new UI_EVENT_MANAGER(100, display);
  272.                            // 100 = MaxNoEvents
  273. *eventManager              // add devices by constructing
  274.                            // new instances of device class.
  275.    + new UI_BIOS_KEYBOARD
  276.    + new UI_MS_MOUSE
  277.    + new UI_CURSOR;
  278.   // Construct a window manager.
  279. UI_WINDOW_MANAGER *windowManager =
  280.    new UI_WINDOW_MANAGER(display, eventManager):
  281.   // Construct and add a window to the window manager.
  282. UIW_WINDOW *window1 = new UIW_WINDOW(1,1,50,20,WOF_NO_FLAGS, WOAF_NO_FLAGS);
  283. *window1 // add window objects by constructing instances
  284.          // of the window object class.
  285.    + new UIW_BORDER
  286.    + new UIW_TITLE("WIN1", WOF_JUSTIFY_CENTER);
  287.  
  288.  
  289. [Example 3]
  290.  
  291. UI_WINDOW_MANAGER &operator+(void *object)
  292.   { Add((UI_WINDOW_OBJECT *)object); return(*this); }
  293.  
  294.  
  295.  
  296.  
  297. [Example 4]
  298.  
  299. + new MY_OBJECT
  300.  
  301. [Example 5]
  302.  
  303. int ccode;
  304. UI_EVENT event; // an event is an instance of class UI_EVENT
  305. do    // loop:  do-while event not equal to ESCAPE
  306. {
  307.      // Get input from a user.
  308.       eventManager.Get(event, Q_NORMAL);
  309.  
  310.      // If ESC message, exit.
  311.       If (event.type == E_KEY && event.rawCode == ESCAPE)
  312.           event.type = L_EXIT;
  313.  
  314.      // Send event information to the window manager
  315.       ccode = windowManager.Event(event);
  316. }  while (ccode != L_EXIT);
  317.  
  318.  
  319.  
  320.