home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 01 / gui.asc < prev    next >
Text File  |  1990-12-07  |  3KB  |  119 lines

  1. _DESIGNING A PORTABLE GUI TOOLKIT_
  2. by Robert T. Nicholson
  3.  
  4. [LISTING ONE]
  5.  
  6. /* make_my_window -- Application code to create a window demonstrates use of 
  7.      attributes for overspecification. The programmer can specify values for 
  8.      window properties applying to any underlying GUI, or can accept 
  9.      platform-specific defaults. Routines and constants prefaced with the
  10.      letters "ui" are toolkit routines.  
  11. */
  12.  
  13. uiWindow make_my_window(private_data)
  14.  
  15. ptr_t    private_data;
  16.  
  17. {
  18. struct 
  19. uiWindowAttr    window_attr;    /* window attributes */
  20.   
  21. uiWindow        the_window;    /* The window created */
  22.  
  23. /* Set the attibute "mask" for the attributes we're concerned with */
  24. window_attr.mask =    uiWINDOW_A_EVENT |
  25.     uiWINDOW_A_TYPE |
  26.     uiWINDOW_A_MODALITY |
  27.     uiWINDOW_A_POSITION |
  28.     uiWINDOW_A_SIZE |
  29.     uiWINDOW_A_TITLE |
  30.     uiWINDOW_A_CANRESIZE |
  31.     uiWINDOW_A_CANCLOSE |
  32.     uiWINDOW_A_CANMINIMIZE |
  33.     uiWINDOW_A_CANMAXIMIZE |
  34.     uiWINDOW_A_CANTITLE |
  35.     uiWINDOW_A_VSATYPE |
  36.     uiWINDOW_A_HSATYPE;
  37.  
  38. /* Set the desired attribute values */
  39. /* EVENT - register the event handler, and a pointer to an application data 
  40.    structure that will be passed to the event routine when it is called.  */
  41. window_attr.eventproc = my_event_routine; 
  42. window_attr.eventarg = private_data; 
  43.  
  44. /* TYPE & MODALITY - a non-modal document window */
  45. window_attr.type = uiWINDOW_DOCUMENT;  
  46. window_attr.modality = uiWINDOW_MODALITY_NONE;
  47.  
  48. /* POSITION, SIZE, and TITLE */
  49. window_attr.x = 200;   
  50. window_attr.y = 100;
  51. window_attr.width = 500;
  52. window_attr.height = 300;
  53. window_attr.title = "Untitled"; 
  54.  
  55. /* CANRESIZE, CANCLOSE, CANMINIMIZE, CANMAXIMIZE, CANTITLE - these permissions
  56.      determine how the user can manipulate this window. We could simply accept
  57.      platform-specific defaults for these, to maintain local look and feel.  */
  58. window_attr.canresize = TRUE; 
  59. window_attr.canclose = TRUE;    
  60. window_attr.canminimize = TRUE; 
  61. window_attr.canmaximize = TRUE; 
  62. window_attr.cantitle = TRUE;
  63.  
  64. /* VSATYPE & HSATYPE - window will have vertical and horizontal scrollbars */
  65. window_attr.vsatype = uiWINDOW_SATYPE_BAR; 
  66. window_attr.hsatype = uiWINDOW_SATYPE_BAR; 
  67.  
  68. the_window = uiWindowCreate(&window_attr);
  69.  
  70. return the_window;
  71. }
  72.  
  73.  
  74. [LISTING TWO]
  75.  
  76. /*  button_routine -- A sample of an event handler routine that processes 
  77.      events for three buttons in a dialog box. Data structures prefaced with 
  78.      the letters "ui" are toolkit structures.
  79. */
  80.  
  81. void button_routine(the_event, private_data)
  82.  
  83. uiEvent *the_event;        /* Event record pointer */
  84. ptr_t    private_data;        /* Dialog's data pointer */
  85. {
  86.  
  87. switch (the_event->type)
  88.     {
  89.     /* Handle button-push events for all three of the
  90.         dialog's buttons. */
  91.     case uiEVENT_PUSHB:
  92.     if (the_event->recipient == 
  93.         ((dialog_data_struct *) private_data)->yes_button)
  94.         do_yes_action(private_data);
  95.     if (the_event->recipient == 
  96.         ((dialog_data_struct *) private_data)->no_button)
  97.         do_no_action(private_data);
  98.     if (the_event->recipient == 
  99.         ((dialog_data_struct *) private_data)->cancel_button)
  100.         do_cancel_action(private_data);
  101.     break;
  102.  
  103.     /* Handle key events - if the user pressed the Return
  104.         key, treat it the same as the "Yes" button, which
  105.         is the default button for this dialog.    */
  106.     case uiEVENT_KEY:
  107.     if (((uiEventKey *) the_event)->key) == '\n')
  108.         do_yes_action(private_data);
  109.     else
  110.         uiWSBeep();
  111.     /* (Not interested in any other events that the buttons
  112.         may receive.)  */
  113.     }
  114. return;
  115. }
  116.  
  117.  
  118.  
  119.