home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-4.ZIP / HDR_EXMP.ZIP / EXAMPLES.ZIP / W4EXAMPL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-17  |  38.8 KB  |  1,472 lines

  1.  
  2. /*  Screen I/O Example Program   g4example.c
  3.     (c)Copyright Sequiter Software Inc., 1987, 1988, 1989.  All rights reserved.
  4. */
  5.  
  6. #include  "d4base.h"  /* For Conversion Routine Prototype */
  7. #include  "w4.h"
  8. #include  "g4char.h"
  9.  
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <stdlib.h>
  13. #include <time.h>
  14.  
  15. #ifdef TURBO
  16.    unsigned int  _stklen =  10000 ;
  17. #else
  18.    #include <malloc.h>
  19. #endif
  20.  
  21. static  int  a_pulldown(void), b_pulldown(void), lotus_example(void),
  22.          menu_entry(void), double_example(void),
  23.          date_example(void), valid_example(void), delimiter_example(void),
  24.          handle_example(void), position_window(int), search_example(void),
  25.          color_menu(void), skipping(void), row_column(void), random_menu(void),
  26.              get_entry_help(void), lotus_help(void), search_help(void),
  27.              display_item(int), select_file(char *), skipping_help(void),
  28.              row_column_display(int,int,int) ;
  29.  
  30. static int  is_date_valid( GET * ), plus_or_minus( GET *), before_t( GET *),
  31.         n_valid( GET *), minus_four( GET *)  ;
  32.  
  33. extern int  v4default_window ;
  34. extern MENU *v4menu ;
  35.  
  36.  
  37. main()
  38. {
  39.    int  main_menu, w_ref, w_get_example ;
  40.  
  41.    w_ref =  w4define( 5,10, 19,68 ) ;
  42.    w4clear( -1 ) ;
  43.    w4cursor( -1,-1 ) ;
  44.    w4activate( w_ref ) ;
  45.  
  46.    w4centre( 1, "Code Base" ) ;
  47.    w4centre( 3, "Window, Menu and Data Entry Examples" ) ;
  48.    w4centre( 5, "(c)Copyright Sequiter Software Inc., 1987, 1988, 1989" ) ;
  49.    w4centre( 9, "Source to this example is in file \'w4example.c\'" ) ;
  50.    w4centre( 11,"Press a key to continue" ) ;
  51.  
  52.    g4char() ;
  53.  
  54.    /* Main Menu Definition */
  55.    main_menu   =  w4define( -1,-1,-1,-1 ) ;
  56.    w4title( 0,-1, " Main Menu ", F_WHITE | F_INTENSE ) ;
  57.  
  58.    n4skip_over( n4( "" ), 1 ) ;
  59.    n4( "Pulldown Menu - Type A" ) ;  n4action( a_pulldown) ;
  60.                      n4key( 'P', 0,0 ) ;
  61.    n4( "Pulldown Menu - Type B" ) ;  n4action( b_pulldown) ;
  62.                      n4key( 'P', 0,0 ) ;
  63.    n4( "Lotus-style Menu" ) ;         n4action( lotus_example) ;
  64.                      n4key( 'L', 0,0 ) ;
  65.    n4( "Get Examples" ) ;         n4action( n4activate, &w_get_example);
  66.                      n4key( 'G', 0,0 ) ;
  67.    n4( "File Name Search" ) ;         n4action( search_example) ;
  68.                      n4key( 'F', 0,0 ) ;
  69.    #ifndef UNIX
  70.       n4( "Color Menu" ) ;         n4action( color_menu) ;
  71.                      n4key( 'C', 0,0 ) ;
  72.    #endif
  73.    n4( "Menu Item Skipping" ) ;      n4action( skipping) ;
  74.                      n4key( 'M', 0,0 ) ;
  75.    n4( "Columns and Rows" ) ;         n4action( row_column ) ;
  76.                      n4key( 'C', 0,0 ) ;
  77.    n4( "Random Menu" ) ;         n4action( random_menu ) ;
  78.                      n4key( 'R', 0,0 ) ;
  79.    n4skip_over( n4( "" ), 1 ) ;
  80.    n4( "Exit" ) ;             n4action( (ACTION *) 0, -1 ) ;
  81.                      n4key( 'E', 0,0 ) ;
  82.    n4skip_over( n4( "" ), 1 ) ;
  83.  
  84.  
  85.    w_get_example =  w4define(-1,-1,-1,-1) ;
  86.  
  87.    n4( "F1 - Data Entry with Menus" ) ;   n4action( menu_entry) ;
  88.                       n4key( F1, 1, -1 ) ;
  89.    n4( "F2 - Numeric Entry" ) ;             n4action( double_example) ;
  90.                       n4key( F2, 1, -1 ) ;
  91.    n4( "F3 - Date Entry" ) ;                n4action( date_example) ;
  92.                       n4key( F3, 1, -1 ) ;
  93.    n4( "F4 - Data Validation" ) ;      n4action( valid_example) ;
  94.                       n4key( F4, 1, -1 ) ;
  95.    n4( "F5 - Delimiters and Attributes"); n4action( delimiter_example) ;
  96.                       n4key( F5, 1, -1 ) ;
  97.    n4( "F6 - Printer/Handle Example" ) ;  n4action( handle_example) ;
  98.                       n4key( F6, 1, -1 ) ;
  99.  
  100.    n4calc( main_menu, 4,1 ) ;
  101.  
  102.    w4select( main_menu ) ;
  103.    w4border( DOUBLE_TOP, F_WHITE ) ;
  104.  
  105.    n4activate( &main_menu ) ;
  106.  
  107.    w4exit(0) ;
  108. }
  109.  
  110. static int  get_entry_help()
  111. {
  112.    int  w_ref, c ;
  113.  
  114.    w4cursor( -1,-1 ) ;
  115.  
  116.    w_ref =  w4define( 7,13 ,19,67 ) ;
  117.    w4title( 0,-1, " Using Menus with Entry Areas ", F_WHITE | F_INTENSE ) ;
  118.    w4border( DOUBLE, F_WHITE ) ;
  119.    w4popup() ;
  120.  
  121.    w4activate( w_ref ) ;
  122.  
  123.    c =  2 ;
  124.    w4( 1,c,           "It is possible to move between entry areas, even" ) ;
  125.    w4( w4row()+1,c, "when using menus, using the following commands:" ) ;
  126.  
  127.    w4( w4row()+2,c, "<Ctrl Home> -  Move to the top entry area." ) ;
  128.    w4( w4row()+1,c, "<Ctrl End>  -  Move to the bottom entry area." ) ;
  129.    w4( w4row()+1,c, "<Tab>       -  Move to the next entry area." ) ;
  130.    w4( w4row()+1,c, "<Shift Tab> -  Move to the previous entry area." ) ;
  131.  
  132.    w4( w4row()+2,c, "Under Unix use <Ctrl Z> if there is no" ) ;
  133.    w4( w4row()+1,c, "<Shift Tab> key." ) ;
  134.    g4char() ;
  135.  
  136.    w4deactivate( w_ref ) ;
  137.    w4close( w_ref ) ;
  138.  
  139.    return 0 ;
  140. }
  141.  
  142.  
  143. static int  menu_entry()
  144. {
  145.    char  name_data[21], subject_data[11], date_data[10] ;
  146.    int   grade_data, name_window, subject_window, grade_window, entry_window ;
  147.    int   save_row ;
  148.  
  149.    /* Initialize the Data */
  150.    memset( name_data,   (int) ' ', sizeof(name_data) ) ;
  151.    name_data[20] = '\0' ;
  152.    memset( subject_data,(int) ' ', sizeof(subject_data) ) ;
  153.    subject_data[10] = '\0' ;
  154.    memset( date_data,   (int) ' ', sizeof(date_data) ) ;
  155.    date_data[8] = '\0' ;
  156.    grade_data =  0 ;
  157.  
  158.    /* Define the Windows for the Menu Data Entry */
  159.    name_window =  w4define(-1,-1,-1,-1) ;
  160.  
  161.    n4( "Menu Entry Help" ) ;
  162.    n4action( get_entry_help ) ;
  163.    n4skip_over( n4(""), 1 ) ;
  164.  
  165.    n4( "Alice Wonder" ) ;
  166.    n4( "Fred Calvert" ) ;
  167.    n4( "Jim Roberts" ) ;
  168.    n4( "John Short" ) ;
  169.    n4( "Lucy Williams" ) ;
  170.    n4( "Tony Smith" ) ;
  171.  
  172.    subject_window =  w4define(-1,-1,-1,-1) ;
  173.  
  174.    n4( "Menu Entry Help" ) ;
  175.    n4action( get_entry_help ) ;
  176.    n4skip_over( n4(""), 1 ) ;
  177.  
  178.    n4( "Biology  " ) ;
  179.    n4( "Chemistry" ) ;
  180.    n4( "English  " ) ;
  181.    n4( "History  " ) ;
  182.    n4( "Math     " ) ;
  183.    n4( "Physics  " ) ;
  184.  
  185.    grade_window =  w4define(-1,-1,-1,-1) ;
  186.  
  187.    n4( "Menu Entry Help" ) ;
  188.    n4action( get_entry_help ) ;
  189.    n4skip_over( n4(""), 1 ) ;
  190.  
  191.    n4( " 85  (A)" ) ;  n4key( 'A', 1, 6 ) ;
  192.    n4( " 75  (B)" ) ;  n4key( 'B', 1, 6 ) ;
  193.    n4( " 65  (C)" ) ;  n4key( 'C', 1, 6 ) ;
  194.    n4( " 55  (D)" ) ;  n4key( 'D', 1, 6 ) ;
  195.    n4( " 45  (F)" ) ;  n4key( 'F', 1, 6 ) ;
  196.  
  197.    /* Specify the GET Screen */
  198.    entry_window =  w4define( 5,10, 21,70 ) ;
  199.    w4border( SINGLE, F_WHITE ) ;
  200.    w4popup() ;
  201.  
  202.    w4activate( entry_window ) ;
  203.  
  204.    w4centre( 2, "Example Entry Screen Using Menus" ) ;
  205.  
  206.    #define  C1   4
  207.    #define  C2  13
  208.    #define  C3  36
  209.  
  210.    w4( 5,C1, "Name" ) ;
  211.    w4( w4row(),C3, "(May use menu)" ) ;
  212.    g4( w4row(),C2, name_data ) ;
  213.    g4call( g4menu_help, name_window ) ;
  214.    g4message( "Press F1 for Entry Possibilities" ) ;
  215.  
  216.    w4( w4row()+2,C1, "Subject" ) ;
  217.    w4( w4row(),C3, "(Must use menu)" ) ;
  218.    g4( w4row(),C2, subject_data ) ;
  219.    g4call( g4menu, subject_window ) ;
  220.  
  221.    w4( w4row()+2,C1, "Grade" ) ;
  222.    w4( w4row(),C3, "(May use menu)" ) ;
  223.    g4int( w4row(),C2, &grade_data ) ;
  224.    g4picture( "999" ) ;
  225.    g4call( g4menu_help, grade_window ) ;
  226.    g4message( "Press F1 for Entry Possibilities" ) ;
  227.  
  228.    w4( w4row()+2,C1, "Date" ) ;
  229.    w4( w4row(),C3, "(No menu available)") ;
  230.    g4date( w4row(),C2, date_data ) ;
  231.    g4picture( "MMM DD/CCYY" ) ;
  232.    g4message( "The format is MMM DD/CCYY;  Example: Mar 30/1989" ) ;
  233.    save_row =  w4row() ;
  234.  
  235.    n4get_calc( entry_window ) ;
  236.    g4read() ;
  237.  
  238.    w4( save_row+2,C2, "Press any key to continue" ) ;
  239.    g4char() ;
  240.  
  241.    w4deactivate( entry_window ) ;
  242.    w4close( entry_window ) ;
  243.    w4close( name_window ) ;
  244.    w4close( subject_window ) ;
  245.    w4close( grade_window ) ;
  246.  
  247.    w4cursor( -1,-1 ) ;
  248.  
  249.    return 0 ;
  250. }
  251.  
  252.  
  253. static int  double_example()
  254. {
  255.    double  d1, d2, d4 ;
  256.    char    n1[10], n2[10], n3[10], n4[10] ;
  257.  
  258.    int     r, save_r, c1, c2, c4, w_ref ;
  259.  
  260.    w_ref =  w4define( 0,0,23,79 ) ;
  261.    w4popup() ;
  262.    w4border( DOUBLE, B_WHITE ) ;
  263.    w4activate( w_ref ) ;
  264.  
  265.    r = 4 ;  c1 = 20 ;  c2 = 34 ;  c4 = 50 ;
  266.    d1 = 1234.0 ;  d2 = -4.2 ;  d4 = 0.0 ;
  267.  
  268.    w4attribute( F_WHITE | F_INTENSE ) ;
  269.    w4centre( r++, "Double/Numeric Examples" ) ;
  270.    w4attribute( F_WHITE ) ;
  271.    ++r ;
  272.  
  273.    w4( ++r,c1, "Picture" ) ;  w4( r,c2, "Data" ) ;  w4( r,c4, "Results" ) ;
  274.  
  275.    save_r =  ++r ;
  276.  
  277.    w4( ++r, c1, "Default" ) ;
  278.    g4double( r, c2, &d4 ) ;
  279.    g4message(  "2 Decimals, 8 Width" ) ;
  280.  
  281.    w4( ++r, c1, "9999" ) ;
  282.    g4double( r, c2, &d1 ) ;
  283.    g4picture( "9999" ) ;
  284.    g4message( "All Digits" ) ;
  285.  
  286.    w4( ++r, c1, "####.#" ) ;
  287.    g4double( r, c2, &d2 ) ;
  288.    g4picture( "####.#" ) ;
  289.    g4message( "One Decimal" ) ;
  290.  
  291.    w4( ++r, c1, "Default" ) ;
  292.    strcpy( n1, " -34.678" ) ;
  293.    g4numeric( r, c2, n1 ) ;
  294.    g4message( "Numeric Example" ) ;
  295.  
  296.    w4( ++r, c1, "####" ) ;
  297.    strcpy( n2, "8431" ) ;
  298.    g4numeric( r, c2, n2 ) ;
  299.    g4picture( "####" ) ;
  300.  
  301.    w4( ++r, c1, "9.9999" ) ;
  302.    strcpy( n3, "      " ) ;
  303.    g4numeric( r, c2, n3 ) ;
  304.    g4picture( "9.9999" ) ;
  305.    g4message( "Initially Blank" ) ;
  306.  
  307.    w4( ++r, c1, "999.99" ) ;
  308.    strcpy( n4, "  1.23" ) ;
  309.    g4numeric( r, c2, n4 ) ;
  310.    g4picture( "999.99" ) ;
  311.  
  312.    g4read() ;
  313.  
  314.    r =  save_r ;
  315.  
  316.    w4double( ++r, c4, d4, 8, 2 ) ;
  317.    w4double( ++r, c4, d1, 4, 0 ) ;
  318.    w4double( ++r, c4, d2, 6, 1 ) ;
  319.    w4( ++r, c4, n1 ) ;
  320.    w4( ++r, c4, n2 ) ;
  321.    w4( ++r, c4, n3 ) ;
  322.    w4( ++r, c4, n4 ) ;
  323.    ++r ;
  324.    w4( ++r, c1, "Press any key to continue ..." ) ;
  325.    w4cursor( -1,-1 ) ;
  326.    g4char() ;
  327.  
  328.    w4deactivate( w_ref ) ;
  329.    w4close( w_ref ) ;
  330.  
  331.    return 0 ;
  332. }
  333.  
  334.  
  335. static int  date_example()
  336. {
  337.    int r, save_r, i_data, c1, c2, c4, i, w_ref ;
  338.    char  date_data[6][8] ;
  339.  
  340.    w_ref =  w4define( 0,0, 23,79 ) ;
  341.    w4popup() ;
  342.    w4border( PANEL, F_WHITE ) ;
  343.    w4activate( w_ref ) ;
  344.  
  345.    memcpy( date_data[0], "19890228", 8 ) ;
  346.    memcpy( date_data[1], "19881030", 8 ) ;
  347.    memcpy( date_data[2], "19420622", 8 ) ;
  348.    memcpy( date_data[3], "        ", 8 ) ;
  349.    memcpy( date_data[4], "19670701", 8 ) ;
  350.  
  351.    r = 4 ;  i_data = 0 ;  c1 = 20 ;  c2 = 34 ;  c4 = 50 ;
  352.  
  353.    w4attribute( F_WHITE | F_INTENSE ) ;
  354.    w4centre( r++, "Date Entry Examples" ) ;
  355.    w4attribute( F_WHITE ) ;
  356.    ++r ;
  357.  
  358.    w4( ++r, c1, "Picture" ) ;  w4( r, c2, "Data" ) ;  w4( r, c4, "Results") ;
  359.  
  360.    save_r =  ++r ;
  361.  
  362.    w4( ++r, c1, DEFAULT_DATE ) ;
  363.    g4date(  r, c2, date_data[i_data++] ) ;
  364.    g4message( "This is the default date picture." ) ;
  365.  
  366.    w4( ++r, c1, "CCYY.MM.DD" ) ;
  367.    g4date(  r, c2, date_data[i_data++] ) ;
  368.    g4picture( "CCYY.MM.DD" ) ;
  369.  
  370.    w4( ++r, c1, "MM/DD/YY" ) ;
  371.    g4date(  r, c2, date_data[i_data++] ) ;
  372.    g4picture( "MM/DD/YY" ) ;
  373.  
  374.    w4( ++r, c1, "MMM DD/CCYY" ) ;
  375.    g4date(  r, c2, date_data[i_data++] ) ;
  376.    g4picture( "MMM DD/CCYY" ) ;
  377.    g4message( "A possible entry is \'Jan 01/1989\'" ) ;
  378.  
  379.    w4( ++r, c1, "DD/MMM" ) ;
  380.    g4date(  r, c2, date_data[i_data++] ) ;
  381.    g4picture( "DD/MMM" ) ;
  382.  
  383.    g4read() ;
  384.  
  385.    for ( i= 0; i< i_data; i++ )
  386.       w4num( save_r+i+1, c4, date_data[i], 8 ) ;
  387.  
  388.    ++r ;
  389.    w4( ++r, c1, "Press any key to continue ..." ) ;
  390.    w4cursor( -1,-1 ) ;
  391.    g4char() ;
  392.  
  393.    w4deactivate( w_ref ) ;
  394.    w4close( w_ref ) ;
  395.  
  396.    return 0 ;
  397. }
  398.  
  399.  
  400. static int  delimiter_example()
  401. {
  402.    char    data1[10], data2[10], data3[8], data4[10] ;
  403.    int     r, save_r, c1, c2, c4, l1, l2, w_ref ;
  404.  
  405.    w_ref =  w4define( 0,0, 23,79 ) ;
  406.    w4popup() ;
  407.    w4border( SINGLE, F_GREEN ) ;
  408.    w4activate( w_ref ) ;
  409.  
  410.    r = 4 ;  c1 = 14;  c2 = 36 ;  c4 = 52 ;
  411.  
  412.    w4attribute( F_WHITE | F_INTENSE ) ;
  413.    w4centre( r++, "Color/Screen/Delimiter Examples" ) ;
  414.    w4attribute( F_BLUE | F_GREEN ) ;
  415.    ++r ;
  416.  
  417.    w4( ++r,c1, "Description" ) ;  w4( r,c2, "Data") ;  w4( r,c4, "Results" ) ;
  418.  
  419.    save_r =  ++r ;
  420.  
  421.    w4( ++r,c1, "Small Screen Width" ) ;
  422.    g4delimiter( "[]" ) ;
  423.    g4attribute( F_RED | F_BLUE ) ;
  424.    strcpy( data1, "abcdefgh" ) ;
  425.    g4( r, c2, data1 ) ;
  426.    g4width( 6, 4 ) ;
  427.    g4message( "The data width is 6 and the screen width is 4" ) ;
  428.  
  429.    w4( ++r,c1, "Phone" ) ;
  430.    g4delimiter( "!!" ) ;
  431.    g4attribute( F_WHITE | F_INTENSE | B_WHITE | B_BLINK ) ;
  432.    strcpy( data2, "444444444" ) ;
  433.    g4( r, c2, data2 ) ;
  434.    g4picture( "999-9999" ) ;
  435.    g4message( "North American Phone Number" ) ;
  436.  
  437.    w4( ++r,c1, "Postal Code" ) ;
  438.    strcpy( data3, "T6E 0T8" ) ;
  439.    g4delimiter( "  " ) ;
  440.    g4attribute( F_RED | F_GREEN ) ;
  441.    g4( r,c2, data3 ) ;
  442.    g4picture( "!9! 9!9" ) ;
  443.    g4message( "Canadian Postal Code (Picture: \"!9! 9!9\" )" ) ;
  444.  
  445.    w4( ++r,c1, "Variety" ) ;
  446.    strcpy( data4, "a1 jT8kN" ) ;
  447.    g4( r,c2, data4 ) ;
  448.    g4picture( "!9#ALNXY" ) ;
  449.    g4message( "Read with a variety of picture characters: \'!9#ALNXY\'") ;
  450.  
  451.    /* Logical Reads */
  452.    l1 = 0 ;  l2 = 1 ;
  453.    g4delimiter( "##" ) ;
  454.  
  455.    w4( ++r,c1, "Logical One" ) ;
  456.    g4logical( r,c2, &l1 ) ;
  457.    g4picture( "L" ) ;
  458.    g4message( "Logical Read using \'g4logical\' with Picture \"L\"" ) ;
  459.  
  460.    w4( ++r,c1, "Logical Two" ) ;
  461.    g4logical( r,c2, &l2 ) ;
  462.    g4picture( "Y" ) ;
  463.    g4message( "Logical Read using \'g4logical\' with Picture \"Y\"" ) ;
  464.  
  465.    g4read() ;
  466.  
  467.    w4attribute( F_WHITE ) ;    /* Back to the defaults */
  468.    g4attribute( B_WHITE ) ;
  469.    g4delimiter( "\x00\x00" ) ;
  470.  
  471.    r =  save_r ;
  472.  
  473.    w4num( ++r, c4, data1, 6 ) ;
  474.    w4num( ++r, c4, data2, 8 ) ;
  475.    w4num( ++r, c4, data3, 7 ) ;
  476.    w4num( ++r, c4, data4, 7 ) ;
  477.    w4int( ++r, c4, l1, 1 ) ;
  478.    w4int( ++r, c4, l2, 1 ) ;
  479.  
  480.    ++r ;
  481.    w4( ++r, c1, "Press any key to continue ..." ) ;
  482.    w4cursor( -1,-1 ) ;
  483.    g4char() ;
  484.  
  485.    w4deactivate( w_ref ) ;
  486.    w4close( w_ref ) ;
  487.  
  488.    return 0 ;
  489. }
  490.  
  491.  
  492. static int  is_date_valid( get_ptr )
  493. GET  *get_ptr ;
  494. {
  495.    if ( memcmp( (char *) get_ptr->data+ 2, "80", 2 ) >= 0 )
  496.    {
  497.       w4display( " Date Entry Error ", "The Date Must be Before 1980", (char *) 0) ;
  498.       return -1 ;
  499.    }
  500.    return 0 ;
  501. }
  502.  
  503.  
  504. static int  minus_four( get_ptr )
  505. GET *get_ptr ;
  506. {
  507.    if ( * ((int *)get_ptr->data)  < -4 )   return 0 ;
  508.    w4display( " Entry Error ", "Must be Less Than -4", (char *) 0 ) ;
  509.    return -1 ;
  510. }
  511.  
  512.  
  513. static int  plus_or_minus( get_ptr )
  514. GET *get_ptr ;
  515. {
  516.    switch( get_ptr->type )
  517.    {
  518.       case 'l':
  519.      if ( *((long *)get_ptr->data) >  1  ||
  520.           *((long *)get_ptr->data) < -1 )   return 0 ;
  521.      break ;
  522.  
  523.       case 'd':
  524.      if ( *((double *)get_ptr->data) > 1.0 ||
  525.           *((double *)get_ptr->data) <-1.0 )   return 0 ;
  526.      break ;
  527.    }
  528.    w4display( " Entry Error ", "Not less than -1 or greater than 1", (char *) 0 ) ;
  529.    return -1 ;
  530. }
  531.  
  532.  
  533. static int  before_t( get_ptr )
  534. GET *get_ptr ;
  535. {
  536.    if ( *((char *)get_ptr->data) <= 'S' )  return 0 ;
  537.    w4display( " Illegal Letter ", "Must start with a letter before \'T\'", (char *) 0 ) ;
  538.    return -1 ;
  539. }
  540.  
  541.  
  542. static int  n_valid( get_ptr )
  543. GET *get_ptr ;
  544. {
  545.    if ( c4atod( get_ptr->data, get_ptr->width_data) < -18.5 )  return 0 ;
  546.    w4display( " Illegal Number ", "Must be less than -18.5", (char *) 0 ) ;
  547.    return -1 ;
  548. }
  549.  
  550.  
  551. static int  valid_example()
  552. {
  553.    int    i_data, r, save_r, c1, c2, c4, w_ref ;
  554.    long   l_data ;
  555.    double d_data ;
  556.    char   dt_data[10], c_data[10], n_data[10] ;
  557.  
  558.    w_ref =  w4define( 0,0, 23,79 ) ;
  559.    w4popup() ;
  560.    w4border( PANEL, F_WHITE ) ;
  561.    w4activate( w_ref ) ;
  562.  
  563.    c1 = 20 ;  c2 = 34 ;  c4 = 50 ;
  564.    r  =  4 ;
  565.  
  566.    i_data =  -4 ;
  567.    l_data =   2 ;
  568.    d_data =  -2.0 ;
  569.  
  570.    strcpy( n_data, " -19.234" ) ;
  571.    strcpy( c_data,  "TEST DATA" ) ;
  572.    strcpy( dt_data, "19790101" ) ;
  573.  
  574.    w4attribute( F_WHITE | F_INTENSE ) ;
  575.    w4centre( r++, "User Defined Validation Examples" ) ;
  576.    w4attribute( F_WHITE ) ;
  577.    ++r ;
  578.  
  579.    w4( ++r,c1, "Picture" ) ;  w4( r,c2, "Data" ) ;  w4( r,c4, "Results") ;
  580.  
  581.    save_r =  ++r ;
  582.  
  583.    w4( ++r,c1, "Date:" ) ;
  584.    g4date(  r,c2, dt_data ) ;
  585.    g4valid( is_date_valid ) ;
  586.    g4message( "The date must be before 1980" ) ;
  587.  
  588.    w4(  ++r, c1, "Integer:" ) ;
  589.    g4int( r, c2, &i_data ) ;
  590.    g4valid( minus_four ) ;
  591.    g4message( "This integer must be less than -4" ) ;
  592.  
  593.    w4(  ++r, c1, "Long:" ) ;
  594.    g4long(r, c2, &l_data ) ;
  595.    g4valid( plus_or_minus ) ;
  596.    g4message( "This long must be less than -1 or greater than 1" ) ;
  597.  
  598.    w4(  ++r, c1, "Double:" ) ;
  599.    g4double(r, c2, &d_data ) ;
  600.    g4valid( plus_or_minus ) ;
  601.    g4message( "This double must be less than -1 or greater than 1") ;
  602.  
  603.    w4(  ++r, c1, "Character:" ) ;
  604.    g4(    r, c2, c_data ) ;
  605.    g4upper() ;
  606.    g4valid( before_t ) ;
  607.    g4message( "The first character must be less than \'T\'" ) ;
  608.  
  609.    w4(  ++r, c1, "Numeric:" ) ;
  610.    g4numeric(r, c2, n_data ) ;
  611.    g4valid( n_valid ) ;
  612.    g4message( "This numeric character string must be less than -18.5" ) ;
  613.  
  614.    g4read() ;
  615.  
  616.    r = save_r ;
  617.  
  618.    w4( ++r, c4, dt_data ) ;
  619.    w4int( ++r, c4, i_data, 4 ) ;
  620.    w4long( ++r, c4, l_data, 8 ) ;
  621.    w4double( ++r, c4, d_data, 8,2 ) ;
  622.    w4( ++r, c4, c_data ) ;
  623.    w4( ++r, c4, n_data ) ;
  624.  
  625.    ++r ;
  626.    w4( ++r, c1, "Press any key to continue ...") ;
  627.    w4cursor( -1,-1 ) ;
  628.    g4char() ;
  629.  
  630.    w4deactivate( w_ref ) ;
  631.    w4close( w_ref ) ;
  632.  
  633.    return 0 ;
  634. }
  635.  
  636.  
  637. static int  handle_example()
  638. {
  639.    int r, choice, w_ref ;
  640.  
  641.    #ifndef UNIX
  642.       char  save_screen[4000] ;
  643.  
  644.       /* Save the complete screen as writing to the screen with handles
  645.      destroys it. */
  646.       w4read( 0,0, save_screen, sizeof(save_screen) ) ;
  647.    #endif
  648.  
  649.    w_ref =  w4define( 0,0,0,60 ) ;   /* The Window Width is Important */
  650.    w4handle( 1 ) ;
  651.    w4cursor( 24,0 ) ;       /* Move the cursor to the end of the screen */
  652.  
  653.    r = 0 ;
  654.    ++r ;
  655.  
  656.    w4( ++r,0, "  This output is going to handle \'1\'.  Observe that" ) ;
  657.    w4( ++r,0, "output to a handle is completely different than direct" ) ;
  658.    w4( ++r,0, "screen output." ) ;
  659.    ++r ;
  660.    w4( ++r,0, "Press a key to continue ..." ) ;
  661.  
  662.    g4char() ;
  663.  
  664.    r += 3 ;
  665.    w4( ++r,0, "Notice that output is quite a bit slower." ) ;
  666.  
  667.    r += 2 ;
  668.    w4( ++r, 10, "Selections: " ) ;
  669.    ++r ;
  670.    w4( ++r, 13, "S - Screen Output" ) ;
  671.    w4( ++r, 13, "P - Printer Output" ) ;
  672.  
  673.    ++r ;
  674.    w4( ++r, 10, "Press key according to selection ... " ) ;
  675.  
  676.    choice =  toupper( g4char() ) ;
  677.  
  678.    if ( choice == (int) 'P' )
  679.    {
  680.       r = 0 ;
  681.       w4handle( 4 ) ;
  682.       w4centre( r, "PRINTER OUTPUT" ) ;
  683.    }
  684.    else
  685.    {
  686.       w4handle( 1 ) ;
  687.       r += 5 ;
  688.       w4centre( r, "SCREEN OUTPUT" ) ;
  689.    }
  690.  
  691.    ++r ;
  692.    w4( ++r,0, "Now some other output routines will be executed:" ) ;
  693.    ++r ;
  694.    w4( ++r,0, "w4int -   " ) ;
  695.    w4int( r, w4col(), 4, 8 ) ;
  696.  
  697.    w4( ++r,0, "w4long -  " ) ;
  698.    w4long(r, w4col(), -10L, 8 ) ;
  699.    w4(++r,0, "w4double -  " ) ;
  700.    w4double( r, w4col(), 4.4, 8, 2 ) ;
  701.  
  702.    if ( choice == (int) 'P' )  w4eject() ;
  703.  
  704.    w4handle( 1 ) ;
  705.    r =  w4row()+1 ;
  706.    w4( ++r,0, "Press a key to restore the saved screen" ) ;
  707.    w4( ++r,0, "and to return to the main menu" ) ;
  708.    g4char() ;
  709.  
  710.    w4close( w_ref ) ;
  711.  
  712.    #ifdef UNIX
  713.       /* Force a Complete Screen Redraw */
  714.       w_ref =  w4define( 0,0, 24,79 ) ;
  715.       w4activate( w_ref ) ;
  716.       w4deactivate( w_ref ) ;
  717.       w4close( w_ref ) ;
  718.    #else
  719.       /* Restore the screen */
  720.       w4write( 0,0, save_screen, sizeof(save_screen) ) ;
  721.       w4cursor( -1,-1 ) ;
  722.    #endif
  723.  
  724.    return 0 ;
  725. }
  726.  
  727. static int  start_row = 10,  start_col = 20,  end_row = 14, end_col = 59 ;
  728.  
  729. static int  position_window( command )
  730. int  command ;
  731. {
  732.    int  pop_window, rc ;
  733.  
  734.    switch ( command )
  735.    {
  736.       case 0:   /* Move Up */
  737.      start_row-- ;
  738.      if ( start_row >= 0 )  end_row-- ;
  739.      break ;
  740.  
  741.       case 1:   /* Move Down */
  742.      end_row++ ;
  743.      if ( end_row <= 23 )  start_row++ ;
  744.      break ;
  745.  
  746.       case 2:   /* Move Right */
  747.      end_col++ ;
  748.      if ( end_col <= 79 )  start_col++ ;
  749.      break ;
  750.  
  751.       case 3:   /* Move Left */
  752.      start_col-- ;
  753.      if ( start_col >= 0 )  end_col-- ;
  754.      break ;
  755.  
  756.       case 4:  /* Size Up */
  757.      start_row-- ;
  758.      break ;
  759.  
  760.       case 5:  /* Size Down */
  761.      if ( start_row < end_row )  start_row++ ;
  762.      break ;
  763.  
  764.       case 6:  /* Size Right */
  765.      end_col++ ;
  766.      break ;
  767.  
  768.       case 7:  /* Size Left */
  769.      if ( start_col < end_col )  end_col-- ;
  770.      break ;
  771.    }
  772.  
  773.    if ( start_row < 0 )  start_row =  0 ;
  774.    if ( end_row > 23 )   end_row   = 23 ;
  775.    if ( start_col < 0 )  start_col =  0 ;
  776.    if ( end_col > 79 )   end_col   = 79 ;
  777.  
  778.    pop_window =  w4define( start_row, start_col, end_row, end_col ) ;
  779.    w4attribute( F_INTENSE | F_BLUE | F_GREEN ) ;
  780.    w4popup() ;
  781.    w4border( PANEL, F_GREEN ) ;
  782.    w4activate( pop_window ) ;
  783.  
  784.    if ( w4height(-1) > 0  &&  w4width(-1) > 0 )
  785.       w4centre( (end_row-start_row-2)/2, "Enter a menu command character.") ;
  786.    rc =  g4char() ;
  787.  
  788.    w4deactivate( pop_window ) ;
  789.    w4close( pop_window ) ;
  790.  
  791.    return( rc ) ;
  792. }
  793.  
  794. static int  a_pulldown()
  795. {
  796.    int  mov , size, pop_menu ;
  797.  
  798.    n4key_special( ESC, CTRL_C, 0x100, 0x7FFF ) ;
  799.  
  800.    pop_menu =  w4define( -1,-1,-1,-1 ) ;
  801.    n4( "Move <Alt M>"); n4reaction( n4activate, &mov );    n4key( ALT_M,0,10);
  802.    n4( "Size <Alt S>"); n4reaction( n4activate, &size);    n4key( ALT_S,0,10);
  803.    n4( "Exit <Alt X>"); n4action( (ACTION *) 0, ALT_X);    n4key( ALT_X,1,10);
  804.  
  805.    mov  =  w4define( -1,-1,-1,-1 ) ;
  806.    n4( "Up" ) ;    n4reaction( position_window, 0 );
  807.    n4( "Down" ) ;  n4reaction( position_window, 1 );
  808.    n4( "Right" ) ; n4reaction( position_window, 2 );
  809.    n4( "Left" ) ;  n4reaction( position_window, 3 );
  810.  
  811.    size =  w4define( -1,-1,-1,-1 ) ;
  812.    n4( "Up" ) ;    n4reaction( position_window, 4 );
  813.    n4( "Down" ) ;  n4reaction( position_window, 5 );
  814.    n4( "Right" ) ; n4reaction( position_window, 6 );
  815.    n4( "Left" ) ;  n4reaction( position_window, 7 );
  816.  
  817.    n4pulldown( pop_menu ) ;
  818.  
  819.    n4activate( &pop_menu ) ;
  820.  
  821.    w4close( mov  ) ;
  822.    w4close( size ) ;
  823.    w4close( pop_menu ) ;
  824.  
  825.    return( 0 ) ;
  826. }
  827.  
  828. static int  b_pulldown()
  829. {
  830.    int  mov , size, pop_menu ;
  831.  
  832.    n4key_special( ESC, CTRL_C, 0, 0 ) ;
  833.  
  834.    pop_menu =  w4define( 0,0, 0,79 ) ;
  835.    w4popup() ;  n4horizontal() ;
  836.    n4item_width( 8 ) ;
  837.    n4( "Move" ); n4action( n4activate, &mov  );     n4key(0,0,-1);
  838.    n4( "Size" ); n4action( n4activate, &size );     n4key(0,0,-1);
  839.    n4( "Exit" ); n4action( (ACTION *) 0, ALT_X );   n4key(0,0,-1);
  840.  
  841.    mov  =  w4define( 1,0, 6,8 ) ;
  842.    w4popup() ;     w4border( SINGLE, F_WHITE ) ;   n4arrow_exit() ;
  843.  
  844.    n4( "Up" ) ;    n4action( position_window, 0 );  n4key( 0,0, -1 ) ;
  845.    n4( "Down" ) ;  n4action( position_window, 1 );  n4key( 0,0, -1 ) ;
  846.    n4( "Right" ) ; n4action( position_window, 2 );  n4key( 0,0, -1 ) ;
  847.    n4( "Left" ) ;  n4action( position_window, 3 );  n4key( 0,0, -1 ) ;
  848.  
  849.    size =  w4define( 1,8, 6,16 ) ;
  850.    w4popup() ;     w4border( SINGLE, F_WHITE ) ;    n4arrow_exit() ;
  851.  
  852.    n4( "Up" ) ;    n4action( position_window, 4 );  n4key( 0,0, -1 ) ;
  853.    n4( "Down" ) ;  n4action( position_window, 5 );  n4key( 0,0, -1 ) ;
  854.    n4( "Right" ) ; n4action( position_window, 6 );  n4key( 0,0, -1 ) ;
  855.    n4( "Left" ) ;  n4action( position_window, 7 );  n4key( 0,0, -1 ) ;
  856.  
  857.    n4pulldown( pop_menu ) ;
  858.  
  859.    n4activate( &pop_menu ) ;
  860.  
  861.    w4close( mov  ) ;
  862.    w4close( size ) ;
  863.    w4close( pop_menu ) ;
  864.  
  865.    return( 0 ) ;
  866. }
  867.  
  868.  
  869. static int   language_display( char *, int ) ;
  870.  
  871. static int   language_display( ptr, i )
  872. char *ptr ;
  873. int i ;
  874. {
  875.    char  buffer[80] ;
  876.  
  877.    memset( buffer, (int) 0, sizeof(buffer) ) ;
  878.    strcpy( buffer, ptr ) ;
  879.    c4ltoa( (long) i, buffer+strlen(buffer), 2 ) ;
  880.  
  881.    return( w4display( "", buffer, (char *) 0 )   ) ;
  882. }
  883.  
  884.  
  885. static int  lotus_help()
  886. {
  887.    int  w_ref, r, c ;
  888.  
  889.    w_ref =  w4define( 3,10, 21,69 ) ;
  890.    w4popup() ;
  891.    w4border( DOUBLE, B_GREEN ) ;
  892.  
  893.    w4title( 0, -1, " Lotus-style Menu Help Window ", F_WHITE | F_INTENSE ) ;
  894.  
  895.    w4activate( w_ref ) ;
  896.  
  897.    r = 1 ; c = 4 ;
  898.    w4( ++r,c,  "The Lotus-style Menus have an user interface which" ) ;
  899.    w4( ++r,c,  "operates the same manner as Lotus 123 Menus.  You" ) ;
  900.    w4( ++r,c,  "have the following options:" ) ;
  901.    ++r ;
  902.    w4( ++r,c,  "   1.  Arrow left or right and then press <Enter>." ) ;
  903.    ++r ;
  904.    w4( ++r,c,  "   2.  Press the highlighted key." ) ;
  905.    ++r ;
  906.    w4( ++r,c,  "   3.  <Esc> moves up one menu." ) ;
  907.    ++r ;
  908.    w4( ++r,c,  "   4.  '/' moves to the top menu." ) ;
  909.    ++r ;
  910.    w4( ++r,c,  "Press any key to continue ..." ) ;
  911.  
  912.    g4char() ;
  913.  
  914.    w4deactivate( w_ref ) ;
  915.    w4close( w_ref ) ;
  916.  
  917.    return 0 ;
  918. }
  919.  
  920. extern int  v4menu_row, v4menu_col ;
  921.  
  922. /* Implements Some Lotus Style Menuing */
  923. static int  lotus_example()
  924. {
  925.    int  language, french, english, german ;
  926.    #define  RETURN_CODE  -2
  927.  
  928.    language =  w4define( -1,-1,-1,-1 ) ;
  929.    n4( "French" );  n4message( "Un, Deux, Trois, Quatre, Cinq, Six" ) ;
  930.             n4action( n4activate, &french ) ;
  931.    n4( "English" ); n4message( "One, Two, Three, Four" ) ;
  932.             n4action( n4activate, &english ) ;
  933.    n4( "German" );  n4message( "Eins, Zwei, Drei, Fier, Fuenf" ) ;
  934.             n4action( n4activate, &german ) ;
  935.    n4( "Help") ;    n4message( "Lotus-style Menu Help" ) ;
  936.             n4action( lotus_help ) ;
  937.    n4( "Return" );  n4message( "Return from the Lotus menu example." ) ;
  938.             n4action( (ACTION *) 0, RETURN_CODE ) ;
  939.  
  940.    french   =  w4define( -1,-1,-1,-1 ) ;
  941.    n4( "Un");      n4message( "Le nombre est un.");
  942.            n4action( language_display, "Le nombre est", 1 ) ;
  943.    n4( "Deux");    n4message( "Le nombre est deux." ) ;
  944.            n4action( language_display, "Le nombre est", 2 ) ;
  945.    n4( "Trois");   n4message( "Le nombre est trois." ) ;
  946.            n4action( language_display, "Le nombre est", 3 ) ;
  947.    n4( "Quatre");  n4message( "Le nombre est quatre." ) ;
  948.            n4action( language_display, "Le nombre est", 4 ) ;
  949.    n4( "Cinq");    n4message( "Le nombre est cinq." ) ;
  950.            n4action( language_display, "Le nombre est", 5 ) ;
  951.    n4( "Six");     n4message( "Le nombre est six." ) ;
  952.            n4action( language_display, "Le nombre est", 6 ) ;
  953.    n4( "Help") ;   n4message( "Lotus-style Menu Help" ) ;
  954.            n4action( lotus_help) ;
  955.  
  956.    english  =  w4define( -1,-1,-1,-1 ) ;
  957.    n4( "One");     n4message( "You are on number one." ) ;
  958.            n4action( language_display, "The number is", 1 ) ;
  959.    n4( "Two");     n4message( "You are on number two." ) ;
  960.            n4action( language_display, "The number is", 2 ) ;
  961.    n4( "Three");   n4message( "You are on number three." ) ;
  962.            n4action( language_display, "The number is", 3 ) ;
  963.    n4( "Four");    n4message( "You are on number four." ) ;
  964.            n4action( language_display, "The number is", 4 ) ;
  965.    n4( "Help");    n4message( "Lotus-style Menu Help" ) ;
  966.            n4action( lotus_help ) ;
  967.  
  968.    german   =  w4define( -1,-1,-1,-1 ) ;
  969.    n4( "Eins");    n4message( "Sie sind auf Nummer einz" ) ;
  970.            n4action( language_display, "Sie sind auf Nummer", 1 ) ;
  971.    n4( "Zwei");    n4message( "Sie sind auf Nummer zwei" ) ;
  972.            n4action( language_display, "Sie sind auf Nummer", 2 ) ;
  973.    n4( "Drei");    n4message( "Sie sind auf Nummer drei" ) ;
  974.            n4action( language_display, "Sie sind auf Nummer", 3 ) ;
  975.    n4( "Fier");    n4message( "Sie sind auf Nummer fier" ) ;
  976.            n4action( language_display, "Sie sind auf Nummer", 4 ) ;
  977.    n4( "Fuenf");   n4message( "Sie sind auf Nummer fuenf" ) ;
  978.            n4action( language_display, "Sie sind auf Nummer", 5 ) ;
  979.    n4( "Help") ;   n4message( "Lotus-style Menu Help" ) ;
  980.            n4action( lotus_help ) ;
  981.  
  982.    n4lotus( language ) ;
  983.  
  984.    while( n4activate( &language ) != RETURN_CODE )  ;
  985.  
  986.    w4close( language ) ;
  987.    w4close( french ) ;
  988.    w4close( english ) ;
  989.    w4close( german ) ;
  990.  
  991.    v4menu_row = 24 ;
  992.    v4menu_col =  0 ;
  993.  
  994.    return 0 ;
  995. }
  996.  
  997.  
  998. /* File Searching Example */
  999.  
  1000. static int  search_help()
  1001. {
  1002.     w4display( " Search Help ",
  1003.        "   In this search example, you are able to type a",
  1004.        "file name.  The menu highlighting bar is automatically",
  1005.        "positioned to the menu entry corresponding to the",
  1006.        "letters typed.",
  1007.        "",
  1008.        "   If you type the wrong character, <Back Space> will",
  1009.        "reverse the character entry.",
  1010.        "",
  1011.        "   To select a different set of files, select the search",
  1012.        "pattern menu option.",
  1013.        (char *) 0 ) ;
  1014.  
  1015.     return 0 ;
  1016. }
  1017.  
  1018. static int  display_item( item_ref )
  1019. int  item_ref ;
  1020. {
  1021.    w4display( " Selected File: ", v4menu[item_ref].item_ptr, (char *) 0 ) ;
  1022.    return 0 ;
  1023. }
  1024.  
  1025. static int  select_file( pattern )
  1026. char  *pattern ;
  1027. {
  1028.    int   w_ref, n_data, i, rc, item_ref ;
  1029.    char  count_data[14], *data ;
  1030.  
  1031.    for( rc =  u4file_first(pattern,count_data), n_data= 0; rc == 0; n_data +=14)
  1032.     rc =  u4file_next( count_data ) ;
  1033.  
  1034.    if ( n_data == 0 )
  1035.    {
  1036.       w4display( " No Files for Pattern ", pattern, (char *) 0 ) ;
  1037.       return 0 ;
  1038.    }
  1039.  
  1040.    w_ref =  w4define( -1,-1,-1,-1 ) ;
  1041.  
  1042.    n4skip_over( n4(""), 1 ) ;
  1043.  
  1044.    n4( "Help" ) ;
  1045.    n4action( search_help ) ;
  1046.  
  1047.    n4skip_over( n4(""), 1 ) ;
  1048.    n4skip_over( n4( "Search" ), 1 ) ;
  1049.    n4skip_over( n4( "Pattern:" ), 1 ) ;
  1050.    n4( pattern ) ;
  1051.    n4action( (ACTION *) 0, -2 ) ;
  1052.  
  1053.    n4skip_over( n4(""), 1 ) ;
  1054.  
  1055.    /* Allocate Enough File Memory */
  1056.    data =  (char *) h4alloc( n_data ) ;
  1057.  
  1058.    rc =  u4file_first(pattern, data ) ;
  1059.    item_ref =  n4( data ) ;  n4action( display_item, item_ref ) ;
  1060.  
  1061.    for ( i= 14; i< n_data ; i+= 14 )
  1062.    {
  1063.       if ( u4file_next( data+i )  != 0 )  break ;
  1064.       item_ref =  n4( data+i ) ;
  1065.       n4action(  display_item, item_ref ) ;
  1066.    }
  1067.  
  1068.    n4calc( w_ref, 2,79 ) ; /* Put in upper right hand corner */
  1069.    n4key_set( 2,1 ) ;      /* ** Searching On ** */
  1070.    w4border( DOUBLE, F_WHITE ) ;
  1071.    w4title( 0,-1, " File Search ", F_WHITE ) ;
  1072.    rc =  n4activate( &w_ref ) ;
  1073.    w4close( w_ref ) ;
  1074.    h4free_memory( data ) ;
  1075.  
  1076.    return  rc ;
  1077. }
  1078.  
  1079.  
  1080. static int  search_example()
  1081. {
  1082.    char pattern[14] ;
  1083.    int  rc, w_ref, len ;
  1084.  
  1085.    strcpy( pattern, "*.*" ) ;
  1086.  
  1087.    for( rc = select_file(pattern);  rc == -2; rc = select_file(pattern) )
  1088.    {
  1089.      /* Change Pattern Selected */
  1090.       w_ref =  w4define( 5,50, 9, 79 ) ;
  1091.       w4popup() ;
  1092.       w4border( DOUBLE, F_WHITE ) ;
  1093.       w4activate( w_ref ) ;
  1094.  
  1095.       w4( 1,3, "Pattern:  " ) ;
  1096.       len =  strlen(pattern) ;
  1097.       memset( pattern+len, (int) ' ', 12-len ) ;
  1098.       pattern[12] =  '\0' ;
  1099.       g4( w4row(),w4col(), pattern ) ;
  1100.       g4message( "Enter a new file pattern" ) ;
  1101.       g4upper() ;
  1102.  
  1103.       g4read() ;
  1104.       w4deactivate( w_ref ) ;
  1105.       w4close( w_ref ) ;
  1106.    }
  1107.    return 0 ;
  1108. }
  1109.  
  1110. #ifndef UNIX
  1111. /* Color Example */
  1112.  
  1113. typedef struct
  1114. {
  1115.    char  text[18] ;
  1116.    char  status[4] ;
  1117.    long  attribute ;
  1118.    int   item_ref ;
  1119.    int   mask ;
  1120. }  COLOR_DATA ;
  1121.  
  1122. static COLOR_DATA  color_data[] =
  1123. {
  1124.    { "Foreground Blue:  ", "",  B_BLUE  | F_WHITE, 0, 0x01 },
  1125.    { "Foreground Green: ", "",  B_GREEN | F_WHITE, 0, 0x02 },
  1126.    { "Foreground Red:   ", "",  B_RED   | F_WHITE, 0, 0x04 },
  1127.    { "Intensity:        ", "",  F_WHITE,       0, 0x08 },
  1128.    { "Background Blue:  ", "",  B_BLUE  | F_WHITE, 0, 0x10 },
  1129.    { "Background Green: ", "",  B_GREEN | F_WHITE, 0, 0x20 },
  1130.    { "Background Red:   ", "",  B_RED   | F_WHITE, 0, 0x40 },
  1131.    { "Blinking:         ", "",  F_WHITE,       0, 0x80 },
  1132. } ;
  1133.  
  1134. typedef struct
  1135. {
  1136.    char text[20] ;
  1137.    long attribute ;
  1138. }  ATT_CHOICE ;
  1139.  
  1140. static ATT_CHOICE  att_choices[] =
  1141. {
  1142.    { "Window Attribute", 0x70L },
  1143.    { "Title Attribute",  0x0FL },
  1144.    { "Border Attribute", 0x0FL },
  1145. } ;
  1146.  
  1147. static  char  choice_data[20] ;
  1148. static  long *attribute_ptr ;
  1149. static  int   explain_color(void) ;
  1150. static  int   change_bits(COLOR_DATA *), change_choice(ATT_CHOICE *) ;
  1151. static  void  init_all_bits(void) ;
  1152.  
  1153. static int  explain_color()
  1154. {
  1155.    int  rc, w_ref, r,c ;
  1156.  
  1157.    w_ref =  w4define(  2,30, 22,79 ) ;
  1158.    w4attribute( att_choices[0].attribute ) ;
  1159.    w4title( 0,-1, " Color Window ", att_choices[1].attribute ) ;
  1160.    w4border( PANEL, att_choices[2].attribute ) ;
  1161.    w4popup() ;
  1162.    w4activate( w_ref ) ;
  1163.  
  1164.    r=0 ;  c=2 ;
  1165.  
  1166.    w4( ++r,c, "  You may select a menu option to toggle its" ) ;
  1167.    w4( ++r,c, "setting.  For example, \'Foreground Blue\'" ) ;
  1168.    w4( ++r,c, "can be ON or OFF.  As each of these eight" ) ;
  1169.    w4( ++r,c, "menu options in the Color Menu corresponds");
  1170.    w4( ++r,c, "to a bit in an attribute byte, you are" ) ;
  1171.    w4( ++r,c, "flipping the bits in the attribute bytes" ) ;
  1172.    w4( ++r,c, "being displayed.  This lets you observe" ) ;
  1173.    w4( ++r,c, "all of the color possibilities." ) ;
  1174.    ++r ;
  1175.    w4( ++r,c, "  You may also change the color of this" ) ;
  1176.    w4( ++r,c, "windows title or border by selecting the" ) ;
  1177.    w4( ++r,c, "\'Choice\' option." ) ;
  1178.    ++r ;
  1179.    w4( ++r,c, "  Note that Code Base can also be programmed" ) ;
  1180.    w4( ++r,c, "to set the color attribute of individual menu" ) ;
  1181.    w4( ++r,c, "items or the color attribute of the currently" ) ;
  1182.    w4( ++r,c, "selected menu item." ) ;
  1183.  
  1184.    rc =  g4char() ;
  1185.    w4deactivate( w_ref ) ;
  1186.    w4close( w_ref ) ;
  1187.  
  1188.    return rc ;
  1189. }
  1190.  
  1191. static int  change_bits( data_ptr )
  1192. COLOR_DATA  *data_ptr ;
  1193. {
  1194.    *attribute_ptr ^=  data_ptr->mask ;
  1195.  
  1196.    if ( *attribute_ptr & data_ptr->mask )
  1197.    {
  1198.       strcpy( data_ptr->status, "ON " ) ;
  1199.       n4attribute_item( data_ptr->item_ref, data_ptr->attribute | F_INTENSE) ;
  1200.    }
  1201.    else
  1202.    {
  1203.       strcpy( data_ptr->status, "OFF" ) ;
  1204.       n4attribute_item( data_ptr->item_ref, data_ptr->attribute ) ;
  1205.    }
  1206.  
  1207.    return 0 ;
  1208. }
  1209.  
  1210. static void  init_all_bits()
  1211. {
  1212.    int i ;
  1213.    *attribute_ptr ^=  0xFF ;
  1214.    for ( i=0; i< 8; i++ )
  1215.       change_bits( color_data+i ) ;
  1216. }
  1217.  
  1218. static int  change_choice( choice_ptr )
  1219. ATT_CHOICE *choice_ptr ;
  1220. {
  1221.    attribute_ptr =  &choice_ptr->attribute ;
  1222.    memcpy( choice_data, choice_ptr->text, (int) sizeof(choice_data) ) ;
  1223.    return -2 ;  /* Return from 'n4activate' with this -2 code */
  1224. }
  1225.  
  1226. static int  color_menu()
  1227. {
  1228.    int  w_ref, choice_ref, i ;
  1229.  
  1230.    change_choice( att_choices ) ;
  1231.  
  1232.    n4key_special( ESC, CTRL_C, 0,0 ) ;
  1233.  
  1234.    w_ref =  w4define( -1,-1,-1,-1 ) ;
  1235.    w4border( SINGLE, F_WHITE ) ;
  1236.    w4title( 0,-1, " Color Menu ", B_WHITE ) ;
  1237.  
  1238.    n4skip_over( n4(""), 1 ) ;
  1239.    n4skip_over( n4( "Currently Changing:"), 1 ) ;
  1240.    n4( choice_data ) ;
  1241.    n4key( 0,0,-1 ) ;
  1242.    n4reaction( explain_color, (void *) 0 ) ;
  1243.    n4action( n4activate, &choice_ref ) ;
  1244.  
  1245.    n4skip_over( n4(""), 1 ) ;
  1246.  
  1247.    for ( i=0; i< 8; i++ )
  1248.    {
  1249.       color_data[i].item_ref =  n4( color_data[i].text ) ;
  1250.       n4reaction( explain_color, (void *) 0 ) ;
  1251.       n4action( change_bits, color_data+i ) ;
  1252.       n4key( 0,0, -1 ) ;
  1253.    }
  1254.  
  1255.  
  1256.    choice_ref =  w4define( -1,-1,-1,-1 ) ;
  1257.    w4border( SINGLE, F_WHITE ) ;
  1258.    for ( i=0; i< 3; i++ )
  1259.    {
  1260.       n4( att_choices[i].text ) ;
  1261.       n4action( change_choice, att_choices+i ) ;
  1262.    }
  1263.  
  1264.    init_all_bits() ;
  1265.    n4calc( w_ref, 12,2 ) ;
  1266.  
  1267.    while( n4activate(&w_ref) == -2 )    init_all_bits() ;
  1268.  
  1269.    w4close( w_ref ) ;
  1270.    w4close( choice_ref ) ;
  1271.  
  1272.    return 0 ;
  1273. }
  1274. #endif
  1275.  
  1276.  
  1277. /* Skipping Example */
  1278.  
  1279. static  int  main_window_ref, on_window_ref ;
  1280.  
  1281. typedef struct
  1282. {
  1283.    char  ptr[10] ;
  1284.    int   main_item_ref, on_item_ref ;
  1285. }  COUNT_DATA ;
  1286.  
  1287. COUNT_DATA  count_data[] =
  1288. {
  1289.    {"One"},
  1290.    {"Two"},
  1291.    {"Three"},
  1292.    {"Four"},
  1293. } ;
  1294.  
  1295. static int  change_status( COUNT_DATA *, int ) ;
  1296.  
  1297. static int  change_status( count_ptr, main_on_flag )
  1298. COUNT_DATA  *count_ptr ;
  1299. int  main_on_flag ;
  1300. {
  1301.    n4skip_over( count_ptr->main_item_ref, ! main_on_flag ) ;
  1302.  
  1303.    if ( main_on_flag )
  1304.    {
  1305.       n4attribute_item( count_ptr->main_item_ref, F_WHITE | F_INTENSE ) ;
  1306.       n4attribute_item( count_ptr->on_item_ref, F_WHITE ) ;
  1307.       n4refresh( main_window_ref ) ;
  1308.    }
  1309.    else
  1310.    {
  1311.       n4attribute_item( count_ptr->main_item_ref, F_WHITE ) ;
  1312.       n4attribute_item( count_ptr->on_item_ref, F_WHITE | F_INTENSE ) ;
  1313.    }
  1314.  
  1315.    return DOWN ;
  1316. }
  1317.  
  1318.  
  1319. static int  skipping_help()
  1320. {
  1321.    w4display( " Help for Menu Item Skipping ",
  1322.  
  1323.           "   This example illustrates how individual menu items",
  1324.           "can interactively be turned on and off.  When a menu item",
  1325.           "is turned off, it can no longer be chosen.  This is",
  1326.           "useful when a menu item is temporarily not needed.",
  1327.           "",
  1328.           "   Menu items \'One\', \'Two\', \'Three\' and \'Four\' can",
  1329.           "all be temporarily turned off by selecting them.  To turn",
  1330.           "one of these menu items back on, choose option \'Turn On\'.",
  1331.           (char *) 0 )  ;
  1332.    return 0 ;
  1333. }
  1334.  
  1335. static int  skipping()
  1336. {
  1337.    int  i, item_ref ;
  1338.  
  1339.    main_window_ref =  w4define( -1,-1,-1,-1 ) ;
  1340.    w4border( DOUBLE, F_WHITE ) ;
  1341.    w4popup() ;
  1342.    n4key_set( 0,0 ) ;
  1343.  
  1344.    item_ref =  n4( "Help" ) ;
  1345.    n4attribute_item( item_ref, F_WHITE | F_INTENSE ) ;
  1346.    n4action( skipping_help ) ;
  1347.  
  1348.    n4skip_over( n4( "" ), 1 ) ;
  1349.  
  1350.    item_ref =  n4( "Turn On") ;
  1351.    n4attribute_item( item_ref, F_WHITE | F_INTENSE ) ;
  1352.    n4action( n4activate, &on_window_ref ) ;
  1353.    n4skip_over( n4( "" ), 1) ;
  1354.  
  1355.    for ( i=0; i<4; i++ )
  1356.    {
  1357.       count_data[i].main_item_ref =  n4( count_data[i].ptr ) ;
  1358.       n4action( change_status, count_data+i, 0 ) ;
  1359.       n4attribute_item( count_data[i].main_item_ref, F_WHITE | F_INTENSE ) ;
  1360.    }
  1361.  
  1362.    on_window_ref =  w4define( -1,-1,-1,-1 ) ;
  1363.    w4border( DOUBLE, F_WHITE ) ;
  1364.    w4popup() ;
  1365.    n4key_set( 0,0 ) ;
  1366.  
  1367.    for ( i=0; i<4; i++ )
  1368.    {
  1369.       count_data[i].on_item_ref =  n4( count_data[i].ptr ) ;
  1370.       n4action( change_status, count_data+i, 1 ) ;
  1371.    }
  1372.  
  1373.    n4calc( main_window_ref, 13,2 ) ;
  1374.  
  1375.    n4activate( &main_window_ref ) ;
  1376.  
  1377.    w4close(main_window_ref) ;
  1378.    w4close(on_window_ref) ;
  1379.  
  1380.    return 0 ;
  1381. }
  1382.  
  1383.  
  1384. static int  row_column_display( item_ref, r,c )
  1385. int  item_ref, r,c ;
  1386. {
  1387.    int  w_ref, rc ;
  1388.  
  1389.    w_ref =  w4define( r*10, c*34, r*10+4, c*34+10 ) ;
  1390.    w4popup() ;
  1391.    w4border( PANEL, F_BLUE ) ;
  1392.  
  1393.    w4activate( w_ref ) ;
  1394.    w4( 1,2, n4item_text( item_ref ) ) ;
  1395.  
  1396.    rc =  g4char() ;
  1397.    w4deactivate( w_ref ) ;
  1398.    w4close( w_ref ) ;
  1399.  
  1400.    return rc ;
  1401. }
  1402.  
  1403. static int  row_column()
  1404. {
  1405.    int  w_ref, i_ref ;
  1406.  
  1407.    w_ref =  w4define(10,28,14,54) ;
  1408.    w4popup() ;
  1409.    w4border( DOUBLE, F_WHITE ) ;
  1410.    w4title( 0,-1, " Row/Column Menu ", B_WHITE ) ;
  1411.  
  1412.    i_ref =  n4( "One" ) ;     n4action( row_column_display, i_ref, 0,0 ) ;
  1413.    i_ref =  n4( "Two" ) ;     n4action( row_column_display, i_ref, 0,1 ) ;
  1414.    i_ref =  n4( "Three" ) ;      n4action( row_column_display, i_ref, 0,2 ) ;
  1415.    i_ref =  n4( "Four" ) ;       n4action( row_column_display, i_ref, 1,0 ) ;
  1416.    i_ref =  n4( "Five" ) ;       n4action( row_column_display, i_ref, 1,1 ) ;
  1417.    i_ref =  n4( "Six" ) ;     n4action( row_column_display, i_ref, 1,2 ) ;
  1418.    i_ref =  n4( "Seven" ) ;      n4action( row_column_display, i_ref, 2,0 ) ;
  1419.    i_ref =  n4( "Eight" ) ;      n4action( row_column_display, i_ref, 2,1 ) ;
  1420.    i_ref =  n4( "Nine" ) ;       n4action( row_column_display, i_ref, 2,2 ) ;
  1421.  
  1422.    n4item_width( 7 ) ;
  1423.    n4horizontal() ;
  1424.  
  1425.    n4activate( &w_ref ) ;
  1426.    w4close( w_ref ) ;
  1427.  
  1428.    return 0 ;
  1429. }
  1430.  
  1431.  
  1432. static  char  random_data[9][6] =
  1433. {
  1434.    "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
  1435. } ;
  1436.  
  1437.  
  1438.  
  1439. static int  random_menu()
  1440. {
  1441.    int     w_ref, num_items, i, i_ref, r,c ;
  1442.    time_t  t ;
  1443.  
  1444.    srand( (unsigned int) time(&t) ) ;
  1445.  
  1446.    #define  START_ROW    5
  1447.    #define  START_COL   30
  1448.    #define  END_ROW     20
  1449.    #define  END_COL     60
  1450.  
  1451.    w_ref =  w4define( START_ROW, START_COL, END_ROW, END_COL ) ;
  1452.    w4popup() ;
  1453.    w4border( DOUBLE, F_GREEN ) ;
  1454.    w4title( 0,-1, " Random Menu ", B_WHITE ) ;
  1455.  
  1456.    num_items =  rand() % 7 + 3 ;  /* 3 to 9 */
  1457.  
  1458.    for ( i=0; i< num_items; i++ )
  1459.    {
  1460.       r = rand() % ( END_ROW-START_ROW-1 ) ;
  1461.       c = rand() % ( END_COL-START_COL-1 ) ;
  1462.  
  1463.       i_ref =  n4item( r,c, random_data[i] ) ;
  1464.       n4action( row_column_display, i_ref,1,1 ) ;
  1465.    }
  1466.  
  1467.    n4activate( &w_ref ) ;
  1468.    w4close( w_ref ) ;
  1469.  
  1470.    return 0 ;   
  1471. }
  1472.