home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / WINCLIP / MANUAL.DOC < prev    next >
Text File  |  1993-12-01  |  543KB  |  16,982 lines

  1.                            THE C WINDOW LIBRARY
  2.  
  3.                     (c) Copyright P. A. McKenzie 1990, 1991
  4.                            All Rights Reserved
  5.  
  6.                                Version 1.01
  7.  
  8.  
  9.                        T A B L E   O F   C O N T E N T S
  10.   INTRODUCTION ....................................................... 1
  11.      Defining Windows ................................................ 1
  12.      Properties of Windows ........................................... 1
  13.      Writing to Overlapping Windows .................................. 1
  14.      Window Ranks .................................................... 2
  15.      Detection of Video Hardware ..................................... 2
  16.      Window Coordinates .............................................. 2
  17.      Video Attributes ................................................ 3
  18.      Direct Screen Writes and BIOS Screen Updates .................... 4
  19.      Video Paging .................................................... 5
  20.      Error Codes ..................................................... 6
  21.      Window Manager .................................................. 7
  22.  
  23.  
  24.   MANDATORY FUNCTIONS AND HEADER FILES ............................... 8
  25.      WindowInitializeSystem() ........................................ 8
  26.  
  27.  
  28.   CREATING WINDOWS ................................................... 9
  29.      The WINDOW structure and WPOINTER structure pointer ............. 9
  30.      WindowSaveInitial() ............................................. 9
  31.      WindowInitialize() .............................................. 10
  32.      CREATE_VIDEO_ATTRIBUTE() macro .................................. 11
  33.      Box types ....................................................... 11
  34.  
  35.  
  36.   OPENING WINDOWS FOR READING AND WRITING ............................ 13
  37.      WindowOpen() .................................................... 13
  38.  
  39.  
  40.   DISPLAYING WINDOWS ................................................. 14
  41.      The WindowDisplay() function and Explosion Effects .............. 14
  42.      Displaying Multiple Windows ..................................... 18
  43.  
  44.  
  45.   CLOSING WINDOWS .................................................... 20
  46.      WindowClose() ................................................... 20
  47.      WindowFree() .................................................... 22
  48.  
  49.  
  50.   CHANGING WINDOW CHARACTERISTICS .................................... 23
  51.      WindowChangeTextAttribute() ..................................... 23
  52.      WindowChangeBorderAttribute() ................................... 24
  53.      WindowDrawBorder() .............................................. 25
  54.      WindowRemoveBorder() ............................................ 26
  55.      WindowResizeHeight() ............................................ 26
  56.      WindowResizeWidth() ............................................. 27
  57.  
  58.  
  59.   WRITING TEXT TO WINDOWS ............................................ 30
  60.      Null Terminated Write Functions ................................. 30
  61.         WindowWriteString() .......................................... 30
  62.         WindowWriteStringAttr() ...................................... 31
  63.  
  64.  Page i                     The C Window Library                    Page i
  65.                        T A B L E   O F   C O N T E N T S
  66.  
  67.         WindowWriteCenterString() .................................... 32
  68.         WindowWriteCenterStringAttr() ................................ 33
  69.         WindowWriteStringCC() ........................................ 33
  70.         WindowWriteStringCCAttr() .................................... 34
  71.         WindowWriteStringRJ() ........................................ 35
  72.         WindowWriteStringRJAttr() .................................... 36
  73.      Length Controlled Write Functions ............................... 37
  74.         WindowWriteCharacters() ...................................... 37
  75.         WindowWriteAttributes() ...................................... 38
  76.         WindowWriteCharAndAttr() ..................................... 39
  77.         WindowWriteCharactersAttr() .................................. 40
  78.         WindowWriteRepeatAttribute() ................................. 41
  79.         WindowWriteRepeatCharacter() ................................. 42
  80.      Formatted Write Functions ....................................... 43
  81.         Where output is placed in the window ......................... 43
  82.         WindowSetWrap() .............................................. 43
  83.         WindowPrintf() ............................................... 44
  84.         WindowPrintfAttr() ........................................... 45
  85.      Writing Titles .................................................. 46
  86.  
  87.  
  88.   READING CHARACTERS AND ATTRIBUTES FROM WINDOWS ..................... 47
  89.      WindowReadCharacters() .......................................... 47
  90.      WindowReadAttributes() .......................................... 48
  91.      WindowReadCharAndAttr() ......................................... 49
  92.  
  93.  
  94.   HIDING WINDOWS ..................................................... 51
  95.      WindowHide() .................................................... 51
  96.  
  97.  
  98.   SCROLLING TEXT IN WINDOWS .......................................... 53
  99.      WindowScroll() .................................................. 53
  100.      WindowScrollRegion() ............................................ 54
  101.      WindowScrollAttr() .............................................. 55
  102.      WindowScrollRegionAttr() ........................................ 56
  103.  
  104.  
  105.   CLEARING WINDOWS ................................................... 58
  106.      WindowClear() ................................................... 58
  107.      WindowClearAttr() ............................................... 59
  108.      WindowClearRegion() ............................................. 59
  109.      WindowClearRegionAttr() ......................................... 60
  110.  
  111.  
  112.   WRITING WINDOW CONTENTS TO A FILE .................................. 62
  113.      WindowWriteTextToFile() ......................................... 62
  114.  
  115.  
  116.   SHADOWING WINDOWS .................................................. 64
  117.      WindowDrawShadow() .............................................. 64
  118.      WindowRemoveShadow() ............................................ 66
  119.  
  120.  Page ii                    The C Window Library                    Page ii
  121.                        T A B L E   O F   C O N T E N T S
  122.  
  123.   SEE-THRU WINDOWS ................................................... 67
  124.      WindowMakeSeeThru() ............................................. 67
  125.      WindowMakeNormal() .............................................. 68
  126.  
  127.  
  128.   MOVING AND SLIDING WINDOWS ......................................... 69
  129.      WindowMove() .................................................... 69
  130.      WindowSlide() ................................................... 70
  131.  
  132.  
  133.   CURSOR POSITIONING IN WINDOWS ...................................... 71
  134.      Cursor Maintenance in The C Window Library ...................... 71
  135.      Creating Cursor Shapes .......................................... 71
  136.      WindowChangeCursor() ............................................ 71
  137.      WindowMoveCursor() .............................................. 72
  138.      WindowGetCursorShape() .......................................... 73
  139.      WindowGetCursorPosition() ....................................... 74
  140.  
  141.  
  142.   GETTING INPUT FROM WINDOWS ......................................... 76
  143.      Input Manager ................................................... 76
  144.      Regular Expressions ............................................. 76
  145.      Editing Input ................................................... 80
  146.      Last Key Value .................................................. 81
  147.      Default Cursor Types and Editing Mode ........................... 82
  148.      Editing using a character mask .................................. 83
  149.      Editing Functions ............................................... 83
  150.         WindowGetString() ............................................ 83
  151.         WindowGetStringAttr() ........................................ 86
  152.         WindowGetMaskString() ........................................ 87
  153.         WindowGetMaskStringAttr() .................................... 88
  154.         Getting Passwords ............................................ 89
  155.            WindowGetPassword() ....................................... 89
  156.            WindowGetPasswordAttr() ................................... 90
  157.            WindowGetMaskPassword() ................................... 91
  158.            WindowGetMaskPasswordAttr() ............................... 91
  159.  
  160.  
  161.      UNDEFINED KEYSTROKE PROCESSING .................................. 93
  162.         The undef_fkey_func and undef_akey_func function pointers .... 93
  163.            Return Values To The Input Manager ........................ 94
  164.  
  165.  
  166.      INPUT OPTIONS ................................................... 96
  167.         CHECKREGEXP and the reg_exp_error_func function pointer ...... 97
  168.      THE num_chars_entered_func FUNCTION POINTER ..................... 99
  169.  
  170.  
  171.      OTHER INPUT RELATED FUNCTIONS ................................... 100
  172.         TranslateStringToMaskString() ................................ 100
  173.         TranslateMaskStringToString() ................................ 102
  174.  
  175.  
  176.  Page iii                   The C Window Library                    Page iii
  177.                        T A B L E   O F   C O N T E N T S
  178.  
  179.   VIRTUAL WINDOWS .................................................... 103
  180.      Using Windows as Viewports ...................................... 103
  181.      Attributed and Non-Attributed Virtual Windows ................... 103
  182.      Virtual Window's Logical Cursor ................................. 104
  183.  
  184.  
  185.      CREATING VIRTUAL WINDOWS ........................................ 105
  186.         VirtualInitialize() .......................................... 105
  187.  
  188.  
  189.      ASSIGNING VIEWPORTS AND CLOSING VIEWPORTS ....................... 107
  190.         WindowAssignToVirtual() ...................................... 107
  191.         Out of bounds Coordinates .................................... 108
  192.         WindowCloseViewport() ........................................ 109
  193.  
  194.  
  195.      WRITING TEXT TO VIRTUAL WINDOWS ................................. 111
  196.         Null Terminated String Functions ............................. 111
  197.            VirtualWriteString() ...................................... 111
  198.            VirtualWriteStringAttr() .................................. 112
  199.            VirtualWriteCenterString() ................................ 113
  200.            VirtualWriteCenterStringAttr() ............................ 114
  201.            VirtualWriteStringCC() .................................... 115
  202.            VirtualWriteStringCCAttr() ................................ 116
  203.            VirtualWriteStringRJ() .................................... 117
  204.            VirtualWriteStringRJAttr() ................................ 118
  205.         Length Controlled Functions .................................. 119
  206.            VirtualWriteCharacters() .................................. 119
  207.            VirtualWriteAttributes() .................................. 120
  208.            VirtualWriteCharAndAttr() ................................. 121
  209.            VirtualWriteRepeatAttribute() ............................. 122
  210.            VirtualWriteRepeatCharacter() ............................. 123
  211.         Formatted Write Functions .................................... 124
  212.            Format String ............................................. 124
  213.            Where Output is Placed .................................... 124
  214.            VirtualSetWrap() .......................................... 124
  215.            VirtualPrintf() ........................................... 125
  216.            VirtualPrintfAttr() ....................................... 126
  217.  
  218.  
  219.      READING CHARACTERS AND ATTRIBUTES FROM VIRTUAL WINDOWS .......... 127
  220.         VirtualReadCharacters() ...................................... 127
  221.         VirtualReadAttributes() ...................................... 128
  222.         VirtualReadCharAndAttr() ..................................... 129
  223.  
  224.  
  225.      REPOSITIONING THE VIEWPORT ...................................... 131
  226.         WindowPositionViewport() ..................................... 131
  227.  
  228.  
  229.      SCROLLING THE VIEWPORTS ......................................... 135
  230.         WindowScrollVirtual() ........................................ 135
  231.  
  232.  Page iv                    The C Window Library                    Page iv
  233.                        T A B L E   O F   C O N T E N T S
  234.  
  235.      WRITING VIRTUAL WINDOW CONTENTS TO A FILE ....................... 138
  236.         VirtualWriteTextToFile() ..................................... 138
  237.  
  238.  
  239.      MOVING THE LOGICAL CURSOR ....................................... 140
  240.         VirtualMoveCursor() .......................................... 140
  241.         VirtualGetCursorPosition() ................................... 140
  242.  
  243.  
  244.      CLEARING VIRTUAL WINDOWS ........................................ 142
  245.         VirtualClear() ............................................... 142
  246.         VirtualClearAttr() ........................................... 143
  247.         VirtualClearRegion() ......................................... 143
  248.         VirtualClearRegionAttr() ..................................... 144
  249.  
  250.  
  251.      FREEZING VIEWPORTS .............................................. 146
  252.         WindowFreeze() ............................................... 146
  253.  
  254.  
  255.      DISPOSING OF VIRTUAL WINDOWS .................................... 148
  256.         VirtualFree() ................................................ 148
  257.  
  258.  
  259.   INTRODUCTION TO MENU SYSTEM ........................................ 150
  260.      Menu Manager .................................................... 150
  261.      Necessary "include" files ....................................... 150
  262.  
  263.  
  264.      POP-UP MENUS .................................................... 151
  265.         Description .................................................. 151
  266.         Windows and Virtual Windows .................................. 151
  267.  
  268.  
  269.      CREATING POP-UP MENUS ........................................... 152
  270.         The POPUP_MENU_ENTRY structure ............................... 152
  271.            Defining Hotkeys .......................................... 153
  272.            Assigning the function to perform ......................... 154
  273.         Coloring Popup Menus ......................................... 154
  274.         PopupCreateMenu() function ................................... 155
  275.            Default Popup Window and Creating Your own Windows ........ 157
  276.            Default Virtual Window and ................................ 158
  277.            Creating Your own Virtual Windows ......................... 158
  278.            Accessing Popup Windows and Virtual Windows ............... 158
  279.            Warnings .................................................. 159
  280.            Return Values for PopupCreateMenu() ....................... 159
  281.  
  282.  
  283.      SELECTING FROM POPUP MENUS ...................................... 161
  284.         PopupSelectMenu() function ................................... 161
  285.            Values passed to menu function ............................ 163
  286.  
  287.  
  288.  Page v                     The C Window Library                    Page v
  289.                        T A B L E   O F   C O N T E N T S
  290.  
  291.            Values returned to menu manager ........................... 163
  292.            Return Values for PopupSelectMenu() ....................... 164
  293.  
  294.  
  295.      SETTING OPTIONS IN POPUP MENUS .................................. 165
  296.         Type of Options .............................................. 165
  297.         The PopupSetOptions() function ............................... 165
  298.            Setting Multiple Options .................................. 167
  299.            Setting the PopupSetConfirmFunction() ..................... 167
  300.            Return Values for PopupSetOptions() function .............. 168
  301.  
  302.  
  303.      MAKING MENU ENTRIES AVAILABLE AND UNAVAILABLE ................... 169
  304.         PopupMakeEntryAvailable() and ................................ 169
  305.         PopupMakeEntryUnavailable() functions ........................ 169
  306.            POPUPOVERRIDE option ...................................... 169
  307.         Return Values for PopupMakeEntryAvaialble() and .............. 169
  308.         PopupMakeEntryUnavailable() functions ........................ 169
  309.  
  310.  
  311.      CHANGING THE MENU ENTRY STRINGS ................................. 171
  312.         PopupChangeEntryString() function ............................ 171
  313.         Return Values for PopupChangeEntryString() function .......... 171
  314.  
  315.  
  316.      REDEFINING MENU KEYS ............................................ 172
  317.         Setting Global Key Definitions and ........................... 172
  318.         the popup_key_definition Array ............................... 172
  319.         Setting Local Key Definitions ................................ 172
  320.            PopupAssignKeys() function ................................ 173
  321.            Return Values for PopupAssignKeys() function .............. 173
  322.  
  323.  
  324.      PROCESSING UNDEFINED KEYS ....................................... 174
  325.         The popup_undef_key function pointer ......................... 174
  326.            Values returned to menu manager ........................... 174
  327.  
  328.  
  329.      PRE-INPUT FUNCTION .............................................. 177
  330.         Setting the global_popup_prefunc function pointer ............ 177
  331.  
  332.  
  333.      DISPOSING OF POPUP MENUS ........................................ 179
  334.         PopupMenuFree() .............................................. 179
  335.         Return Values for PopupMenuFree() ............................ 179
  336.  
  337.  
  338.   BAR MENUS .......................................................... 180
  339.      Description ..................................................... 180
  340.      Windows and Virtual Windows ..................................... 180
  341.  
  342.  
  343.  
  344.  Page vi                    The C Window Library                    Page vi
  345.                        T A B L E   O F   C O N T E N T S
  346.  
  347.      CREATING BAR MENUS .............................................. 181
  348.         The BAR_MENU_ENTRY structure ................................. 181
  349.            Defining Hotkeys .......................................... 182
  350.            Assigning the function to perform ......................... 183
  351.         Coloring Bar Menus ........................................... 183
  352.         BarCreateMenu() function ..................................... 184
  353.            Default Bar Menu Window and Creating Your own Windows ..... 186
  354.            Accessing bar menu windows ................................ 187
  355.            Warnings .................................................. 187
  356.            Return Values for BarCreateMenu() ......................... 187
  357.  
  358.  
  359.      SELECTING FROM BAR MENUS ........................................ 189
  360.         BarSelectMenu() function ..................................... 189
  361.            Values passed to menu function ............................ 190
  362.            Values returned to menu manager ........................... 191
  363.            Return Values for BarMenuSelect() ......................... 191
  364.  
  365.  
  366.      SETTING OPTIONS IN BAR MENUS .................................... 192
  367.         Type of Options .............................................. 192
  368.         The BarSetOptions() function ................................. 192
  369.            Setting Multiple Options .................................. 194
  370.            Setting the BarSetConfirmFunction() ....................... 194
  371.            Return Values for BarSetOptions() function ................ 195
  372.  
  373.  
  374.      MAKING ENTRIES AVAILABLE AND UNAVAILABLE ........................ 196
  375.         BarMakeEntryAvailable() and .................................. 196
  376.         BarMakeEntryUnavailable() functions .......................... 196
  377.            BAROVERRIDE option ........................................ 196
  378.         Return Values for BarMakeEntryAvaialble() and ................ 196
  379.         BarMakeEntryUnavailable() functions .......................... 196
  380.  
  381.  
  382.      CHANGING THE MENU OPTIONS STRING ................................ 197
  383.         BarChangeEntryString() function .............................. 197
  384.            Return Values for BarChangeEntryString() function ......... 197
  385.  
  386.  
  387.      REDEFINING THE MENU KEYS ........................................ 198
  388.         Setting Global Key Definitions and ........................... 198
  389.         the bar_key_definition Array ................................. 198
  390.         Setting Local Key Definitions ................................ 198
  391.            BarAssignKeys() function .................................. 198
  392.            Return Values for BarAssignKeys() function ................ 199
  393.  
  394.  
  395.      PROCESSING UNDEFINED KEYS ....................................... 200
  396.         The bar_undef_key function pointer ........................... 200
  397.            Values returned to menu manager ........................... 200
  398.  
  399.  
  400.  Page vii                   The C Window Library                    Page vii
  401.                        T A B L E   O F   C O N T E N T S
  402.  
  403.      PRE-INPUT FUNCTION .............................................. 203
  404.         Setting the global_bar_prefunc function pointer .............. 203
  405.  
  406.  
  407.      DISPOSING OF BAR MENUS .......................................... 205
  408.         BarMenuFree() function ....................................... 205
  409.         Return Values for BarMenuFree() .............................. 205
  410.  
  411.  
  412.   PULLDOWN MENUS ..................................................... 206
  413.      Description ..................................................... 206
  414.      Bar Menu and Popup Menu levels .................................. 206
  415.  
  416.  
  417.      CREATING PULLDOWN MENUS ......................................... 207
  418.         The PulldownCreateMenu() function ............................ 208
  419.            Automatic Adjustment of Popup Windows ..................... 210
  420.         Return values for PulldownCreateMenu() ....................... 212
  421.  
  422.  
  423.      SELECTING FROM PULLDOWN MENUS ................................... 213
  424.         The PulldownSelectMenu() function ............................ 213
  425.            Immediate Mode ............................................ 213
  426.            Values passed to the selected menu function ............... 214
  427.            Values returned to the menu manager ....................... 214
  428.            Return Values for PulldownSelectMenu() .................... 214
  429.  
  430.  
  431.      REDEFINING KEY DEFINITIONS ...................................... 215
  432.  
  433.  
  434.         REDEFINING KEY DEFINITIONS FOR POPUP MENUS ................... 216
  435.            Setting Popup Menu Global Key Definitions ................. 216
  436.            Setting Popup Menu Local Definitions ...................... 216
  437.  
  438.  
  439.         REDEFINING KEY DEFINITIONS FOR THE BAR MENU .................. 218
  440.            Setting bar menu global key definitions ................... 218
  441.            Setting Bar Menu Local definitions ........................ 218
  442.  
  443.  
  444.      PROCESSING UNDEFINED POPUP MENU KEYS ............................ 219
  445.  
  446.  
  447.      PROCESSING UNDEFINED BAR MENU KEYS .............................. 220
  448.  
  449.  
  450.      DISPOSING OF PULLDOWN MENUS ..................................... 221
  451.         The PulldownMenuFree() function .............................. 221
  452.         The PulldownMenuFreeAll() function ........................... 221
  453.  
  454.  
  455.  
  456.  Page viii                  The C Window Library                    Page viii
  457.                        T A B L E   O F   C O N T E N T S
  458.  
  459.      SUMMARY OF PULLDOWN MENUS ....................................... 222
  460.  
  461.  
  462.      EXAMPLE OF PULLDOWN MENU SYSTEM ................................. 223
  463.  
  464.  
  465.   MISCELLANEOUS FUNCTIONS ............................................ 228
  466.  
  467.  
  468.      SETTING AND CHECKING VIDEO PAGES ................................ 228
  469.         CheckVideoPage() ............................................. 228
  470.         SetActiveVideoPage() function ................................ 229
  471.         SetVisibleVideoPage() function ............................... 230
  472.  
  473.  
  474.      GENERAL STRING WRITING FUNCTIONS ................................ 232
  475.         VideoWriteString() ........................................... 232
  476.         VideoWriteStringAttr() ....................................... 233
  477.         VideoWriteAttributes() ....................................... 233
  478.         VideoWriteCenterString() ..................................... 234
  479.         VideoWriteCenterStringAttr() ................................. 235
  480.         VideoWriteCharAndAttr() ...................................... 235
  481.         VideoWriteStringCC() ......................................... 236
  482.         VideoWriteStringCCAttr() ..................................... 237
  483.         VideoWriteStringRJ() ......................................... 237
  484.         VideoWriteStringRJAttr() ..................................... 238
  485.         VideoPrintf() ................................................ 239
  486.         VideoPrintfAttr() ............................................ 239
  487.  
  488.  
  489.      READING CHARACTERS AND ATTRIBUTES FROM THE SCREEN ............... 240
  490.         VideoReadCharacters() ........................................ 240
  491.         VideoReadAttributes() ........................................ 240
  492.         VideoReadCharAndAttr() ....................................... 241
  493.  
  494.  
  495.      DRAWING BOXES ................................................... 242
  496.         VideoDrawBox() ............................................... 242
  497.         VideoDrawBoxAttr() ........................................... 242
  498.  
  499.  
  500.      SAVING AND RESTORING SCREEN IMAGES .............................. 244
  501.         VideoSave() .................................................. 244
  502.         VideoMove() .................................................. 245
  503.         VideoRestore() ............................................... 245
  504.         VideoFree() .................................................. 246
  505.  
  506.  
  507.      CLEARING SCREENS ................................................ 247
  508.         ClearScreen() ................................................ 247
  509.         ClearRegion() ................................................ 247
  510.  
  511.  
  512.  Page ix                    The C Window Library                    Page ix
  513.                        T A B L E   O F   C O N T E N T S
  514.  
  515.      SCROLLING SCREENS ............................................... 249
  516.         ScrollScreenUp() ............................................. 249
  517.         ScrollScreenDown() ........................................... 249
  518.  
  519.  
  520.      CHANGING THE VIDEO MODE ......................................... 251
  521.         SetVideoMode() ............................................... 251
  522.  
  523.  
  524.      CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE SCREEN ........... 252
  525.         Changing rows ................................................ 252
  526.            AdjustScreenInfo() ........................................ 252
  527.            AdjustGlobalData() ........................................ 253
  528.            SetVideoRows() ............................................ 253
  529.         Changing columns ............................................. 256
  530.            40 column and 80 column modes ............................. 256
  531.            Modes higher than 80 columns .............................. 256
  532.  
  533.  
  534.      CURSOR MANIPULATION ............................................. 258
  535.         MoveCursor() ................................................. 258
  536.         ChangeCursor() ............................................... 258
  537.         GetCursorShape() ............................................. 259
  538.         GetCursorPosition() .......................................... 259
  539.         HideCursor() ................................................. 260
  540.         BlockCursor() ................................................ 260
  541.         ThinCursor() ................................................. 260
  542.  
  543.  
  544.      GETTING VIDEO INFORMATION ....................................... 262
  545.         VIDEO_CONFIG structure ....................................... 262
  546.         GetVideoBiosInfo() ........................................... 262
  547.  
  548.  
  549.      TIMED DELAYS .................................................... 264
  550.         delay() ...................................................... 264
  551.  
  552.  
  553.      SOUND FUNCTIONS ................................................. 265
  554.         sound() and nosound() ........................................ 265
  555.         MakeSound() .................................................. 265
  556.  
  557.  
  558.      ERROR HANDLING .................................................. 267
  559.         The window_error_func function pointer ....................... 267
  560.  
  561.  
  562.      WINDOW AND VIRTUAL WINDOW MACROS ................................ 269
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  Page x                     The C Window Library                    Page x
  569.                        T A B L E   O F   C O N T E N T S
  570.  
  571.      MENU MACROS ..................................................... 271
  572.         Popup Menu Macros ............................................ 271
  573.         Bar Menu Macros .............................................. 272
  574.  
  575.  
  576.  
  577.      VIDEO MACROS .................................................... 273
  578.  
  579.  
  580.      BOX MACROS ...................................................... 276
  581.  
  582.  
  583.      EXPLOSION MACROS ................................................ 277
  584.  
  585.  
  586.      KEYBOARD MACROS ................................................. 278
  587.  
  588.  
  589.      CURSOR MACROS ................................................... 279
  590.  
  591.  
  592.   IMPORTANT GLOBAL VARIABLES ......................................... 280
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  Page xi                    The C Window Library                    Page xi
  625.  
  626.                                  INTRODUCTION
  627.                                  ------------
  628.  
  629.   Defining Windows
  630.   ----------------
  631.  
  632.   A window is an area of the screen that is separate and independent from the
  633.   other areas of the screen.  With windows, you can scroll, write text, delete
  634.   text, etc. in a defined section of the screen.  An example of windows in
  635.   application programs are the resident memory utilities that pop up on the
  636.   screen when invoked, and restore the text to its original state when the
  637.   resident application is terminated.  Sidekick is a good example of what you
  638.   can do with windows.  As a matter of fact, most professional programs use
  639.   windows in some manner.  Some applications use windows to make pulldown menus
  640.   i.e. the integrated environment in the Turbo languages and in Microsoft Quick
  641.   C's integrated environment.  Other applications such as text editors and word
  642.   processors use windows to display and edit a files contents.  With The C
  643.   Window Library, you can create professional looking application program easily
  644.   and without worrying about the tricky details of window management.  At your
  645.   disposal are tools that can help you create pull-down menus, popup menus, bar
  646.   menus, and just fast output.
  647.  
  648.  
  649.   Properties of Windows
  650.   ---------------------
  651.  
  652.   Windows should have the following properties:
  653.     - more than one window can be displayed on the screen simultaneously.
  654.     - windows are allowed to overlap without disturbing the contents of
  655.       the windows underneath.
  656.     - a window that is under a pile of windows can be brought to the top.
  657.     - a window that is under a pile of windows can be written to without
  658.       interfering with other windows.
  659.     - windows can be disposed of when not needed, and erased from the screen.
  660.       When erased, the contents of the screen underneath the window is restored.
  661.     - windows can be written to at any time.
  662.     - the window application should automatically detect the type of video
  663.       hardware used.
  664.     - the window functions should return an error if something goes wrong.
  665.  
  666.  
  667.   Writing to Overlapping Windows
  668.   ------------------------------
  669.  
  670.   With The C Window Library, if a window does overlap another window, this
  671.   overlap will be displayed on the physical screen.  The C Window Library
  672.   allows you to direct output to any window at any time.  When output is
  673.   written to a window, the window contents are updated in memory, but only the
  674.   visible portions of the window will be updated on the screen.
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  Page 1                     The C Window Library                    Page 1
  681.  
  682.  
  683.   Window Ranks
  684.   ------------
  685.  
  686.   The rank order of the windows on the screen will determine which window has
  687.   priority of the screen.
  688.  
  689.   Windows with lower rank numbers overlap windows with higher rank numbers.  The
  690.   lowest rank number is 1, and the highest is 254.  If a new window is opened
  691.   with the same rank number as another previously opened window, the new window
  692.   takes over the rank position, and the previous window's rank is increased
  693.   by 1.   If there is a window with the same rank as the previous window's new
  694.   rank, its rank is increased by 1 etc.  When a window is closed, all windows
  695.   with a higher rank number are decreased by 1.
  696.  
  697.  
  698.  
  699.   Detection of Video Hardware
  700.   ---------------------------
  701.  
  702.   With The C Window Library, automatic detection of the type of video hardware
  703.   is necessary.  Since The C Window Library can write directly to screen memory,
  704.   the starting memory address of screen memory must be known.  Depending on the
  705.   video adapter, the starting address of screen memory is different.  For
  706.   monochrome systems, the starting address is different from a color system.
  707.   If the window routines think that they are writing to a color system instead
  708.   of a monochrome system, crazy things will probably happen.  For most
  709.   adapters, The C Window Library will detect them and assign the starting
  710.   address of screen memory to a global variable, so there is no need to specify
  711.   the starting address yourself.
  712.  
  713.  
  714.  
  715.   Window Coordinates
  716.   ------------------
  717.  
  718.   A position on the screen can be specified as a pair of numbers.  These numbers
  719.   will denote the row and column of the desired position.  Rows and columns are
  720.   numbered from 1 to the maximum row or column number.  The upper left hand
  721.   corner of the screen would be at row 1, column 1.  For simplicity, row y,
  722.   column x will be abbreviated as (y,x).  The position (1,1) is called  the home
  723.   position.
  724.  
  725.   However, when specifying a position in a window, this position is numbered
  726.   relative to the window itself.  No matter where a window resides on the
  727.   screen, the upper left position of the window is (1,1), the second row of the
  728.   window is row 2, the fourth column is column 4, etc.  The window coordinates
  729.   are called window relative coordinates.  There are some window functions that
  730.   require you to enter physical screen (absolute) coordinates, but for most
  731.   functions, a window relative position would be needed.  For example:
  732.  
  733.  
  734.  
  735.  
  736.  Page 2                     The C Window Library                    Page 2
  737.  
  738.   -------------------------------------------------------------------
  739.   |(1,1)                                                      (80,1)|
  740.   |                                                                 |
  741.   |                Valid Absolute Screen Coordinates                |
  742.   |                      For 80 x 25 Screen                         |
  743.   |                                                                 |
  744.   |     This window opened at absolute (12,15)                      |
  745.   |            |                                                    |
  746.   |            v                                                    |
  747.   |            -----------------------                              |
  748.   |            |(1,1)          (1,30)|                              |
  749.   |            |                     |                              |
  750.   |            |                     |                              |
  751.   |            |(14,1)        (14,30)|                              |
  752.   |            -----------------------                              |
  753.   |(1,25)                                                    (80,25)|
  754.   -------------------------------------------------------------------
  755.  
  756.  
  757.  
  758.   Video Attributes
  759.   ----------------
  760.  
  761.   With The C Window Library, a window can have an assortment of colors for text
  762.   and background.  Each character that is displayed on the screen has its
  763.   corresponding attribute byte.  The attribute byte is an 8-bit quantity that
  764.   specifies a character's color, intensity, and blink status.  The format of the
  765.   attribute byte is as follows:
  766.  
  767.                       7  6  5  4  3  2  1  0
  768.                     --------------------------
  769.                     |B | bground |I|fground  |
  770.                     |__|_________|_|_________|
  771.  
  772.  
  773.   The B is the blink bit and the I is the intensity bit.  Bits 0 thru 2
  774.   is a color code for the foreground (text) color.  Bits 4 thru 6 determine
  775.   the color code for the background (screen) color.
  776.  
  777.   If the blink bit is 1, then the character will blink.  If the intensity bit is
  778.   on, the character will appear brighter than usual.  Some monitors cannot
  779.   display high intensity characters, so the intensity bit may not change the
  780.   characters brightness at all.
  781.  
  782.        Here is a list of color values along with the color they represent:
  783.  
  784.  
  785.      Value      Color                 Value        Color
  786.  
  787.        0        Black                  8          Gray
  788.        1        Blue                   9          Light blue
  789.        2        Green                 10          Light green
  790.  
  791.  
  792.  Page 3                     The C Window Library                    Page 3
  793.  
  794.        3        Cyan                  11          Light cyan
  795.        4        Red                   12          Light red
  796.        5        Magenta               13          Light magenta
  797.        6        Brown                 14          Yellow
  798.        7        White                 15          Intense white
  799.  
  800.   If the video system is a monochrome system, the color values specified above
  801.   will give unpredictable results if not used carefully.  Monochrome systems
  802.   also have an underline mode, that color systems (unless if you program the
  803.   EGA or VGA adapters) cannot display.  Upcoming is a list of color values
  804.   that should work on monochrome systems along with the type of display that
  805.   will be produced:
  806.  
  807.  
  808.      Display          Background      Foreground
  809.  
  810.      No display          0                 0
  811.      Underline           0                 1
  812.      Normal Video        0                 7
  813.      Reverse Video       7                 0
  814.  
  815.   When programming a monochrome system, you can change the values of the colors
  816.   not supported to black and white combinations supported on the monochrome
  817.   system.  For example, you can change the light green color's value from 10 to
  818.   7.  Now if light green is selected as a foreground color and the background
  819.   color is black, you will have a normal video display on a monochrome system.
  820.  
  821.  
  822.  
  823.   Direct Screen Writes and BIOS Screen Updates
  824.   --------------------------------------------
  825.  
  826.   By default, The C Window Library writes directly to screen memory.  This
  827.   results in very fast screen output.  If you have ever wondered how commercial
  828.   programs can display output so rapidly on the screen, direct screen writing
  829.   is the major reason.  The disadvantage of writing directly to the screen is
  830.   that it is ill- behaved with programs like Microsoft Windows or Quarterdeck's
  831.   DesQView (although DesQView386 running on an 80386 machine is well behaved
  832.   with direct screen writes).  Also on some color systems, the screen output is
  833.   so fast that the video display produces "snow" on the screen.  However, The C
  834.   Window Library will automatically detect whether "snow" should be checked
  835.   when writing directly to the screen.  The old IBM Color Graphics Adapters
  836.   suffer from this problem, but most other adapters including monochrome,
  837.   Hercules, EGA, VGA, and newer CGA's do not suffer from this problem.  When
  838.   checking for snow, the screen writes are not as fast as when there is no snow
  839.   checking, but it is fast enough.
  840.  
  841.   The other method of updating the screen is by making a call to the video
  842.   functions contained in the ROM BIOS.  BIOS stands for Basic Input Output
  843.   System.  The BIOS provides routines that are needed for the operation of the
  844.   computer.  Some of these routines are video functions needed to write
  845.   characters and attributes, move the cursor, and scroll portions of the
  846.   screen.  Using the BIOS instead of writing directly to screen memory results
  847.  
  848.  Page 4                     The C Window Library                    Page 4
  849.  
  850.   in much slower screen updates, but will be compatible with programs like
  851.   Microsoft Windows and DesQView.
  852.  
  853.   With The C Window Library, you are allowed to use either method.
  854.  
  855.  
  856.  
  857.  
  858.   Video Paging
  859.   ------------
  860.  
  861.   Since most video display adapters have enough memory to store more than one
  862.   screen of characters,  these video adapters will support multiple video pages.
  863.   With multiple video pages, you can write to a hidden video page and then
  864.   display the entire video page instantaneously. The only adapter that does
  865.   not support video paging is the Monochrome Display Adapter (MDA).  All
  866.   CGA's, EGA's and VGA's support multiple video pages.   The maximum number
  867.   of pages a card will support is determined by the amount of RAM included in
  868.   the video board, and the maximum number of characters that can be displayed
  869.   on each page.  A list of the maximum number of video pages in each mode for
  870.   each card is as follows:
  871.  
  872.  
  873.  
  874.         BIOS        Mode                               Max. #
  875.         Mode #      Type           Adapter            of pages
  876.         ----        ----           -------            --------
  877.         0,1         Text        CGA, EGA, VGA             8
  878.         2,3         Text        CGA,                      4
  879.                                 EGA, VGA                  8
  880.         7           Text        MDA, Hercules             1
  881.                                 EGA, VGA                  8
  882.  
  883.   With The C Window Library, the video page displayed on the screen is called
  884.   the visible page.  When creating a window, its page number is recorded.
  885.   When updating windows, the video page number where the window resides is
  886.   used to direct the output to the appropriate video page.  There are also
  887.   functions in The C Window Library that allow you to switch video pages.
  888.   With these routines, you can create very sophisticated user interfaces.
  889.   If you are using a clone Hercules Monochrome adapter, you may have access to
  890.   more than one video page.  The original Hercules card has only one page of
  891.   text memory.  The problem of accessing the other pages in the clone cards is
  892.   that there is no universal way to determine how many pages that the card
  893.   has.  If you are writing an application that targets a specific Hercules
  894.   clone card, and you want to take advantage of the multiple pages, you can
  895.   modify a global variable that contains the maximum number of available video
  896.   pages, as well as the array that contains the segment:offset of each video
  897.   page.  Make sure you have the full documentation for the card, or know
  898.   off-hand the number of pages and their addresses.
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  Page 5                     The C Window Library                    Page 5
  905.  
  906.   Error Codes
  907.   -----------
  908.  
  909.   With most of The C Window Library functions, window_error_code, which is a
  910.   global integer variable is set to an error number when a function cannot be
  911.   completed.  Throughout this documentation, you are to assume that
  912.   window_error_code is set to any error condition that is documented for
  913.   each function.  The window_error_code variable IS NOT reset when a function
  914.   has been completed successfully.  A list of error codes is as follows:
  915.  
  916.  
  917.      Error Constant       Error Code           Definition
  918.      --------------       ----------           ----------
  919.  
  920.     NO_HEAP_MEM               -1          Not enough memory to allocate from
  921.                                           the heap.
  922.  
  923.     BAD_DISPLAY_PAGE          -2          Video Display page is invalid.
  924.  
  925.     INVALID_VIDEO_MODE        -3          Invalid video mode.
  926.  
  927.     INVALID_ROWS              -4          Invalid number of screen rows
  928.                                           specified.
  929.  
  930.     BAD_WINDOW                -100        Window does not exist.
  931.  
  932.     BAD_WINDOW_SIZE           -101        Window dimensions are invalid.
  933.  
  934.     WINDOW_NOT_OPEN           -102        Window not open for read/write.
  935.  
  936.     WINDOW_BOUND              -103        Coordinates specified for window are
  937.                                           out of bounds.
  938.  
  939.     MAX_WINDOW                -104        Maximum number of windows defined.
  940.  
  941.  
  942.     WINDOW_INV_PARAM          -105        An invalid parameter was encountered
  943.                                           in the function call.
  944.  
  945.     NO_INPUT_CHARS            -106        Trying to input a field of 0
  946.                                           characters.
  947.  
  948.     BAD_V_WINDOW              -200        The virtual window does not exist.
  949.  
  950.     END_V_WINDOW              -201        Internally used by The C Window
  951.                                           Library.
  952.  
  953.     V_WINDOW_BOUND            -202        Coordinates specified for virtual
  954.                                           window are out of bounds.
  955.  
  956.     MAX_V_WINDOW              -203        Maximum number of virtual windows
  957.                                           defined.
  958.  
  959.  
  960.  Page 6                     The C Window Library                    Page 6
  961.  
  962.     NO_ATTRIB                 -204        Virtual window does not have
  963.                                           attributes.
  964.  
  965.     FILE_NO_EXIST             -300        File does not exist.
  966.  
  967.     FILE_CANT_CLOSE           -301        Cannot close file.
  968.  
  969.     FILE_CANT_OPEN            -302        Cannot open file.
  970.  
  971.     MENU_ENTRY_INVALID        -400        An invalid menu entry was specified.
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.   Window Manager
  979.   --------------
  980.  
  981.   The window manager is the code in The C Window Library that handles window
  982.   initialization, movement, coloring, and other functions that control window
  983.   management.
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  Page 7                     The C Window Library                    Page 7
  1017.  
  1018.                      MANDATORY FUNCTIONS AND HEADER FILES
  1019.                      ------------------------------------
  1020.  
  1021.   The only mandatory function is WindowInitializeSystem(), explained below.
  1022.   The window.h header file must be included in any module that will call
  1023.   functions included in The C Window Library.
  1024.  
  1025.  
  1026.   WindowInitializeSystem()
  1027.   ------------------------
  1028.  
  1029.   This function MUST be called before any other function defined in The C
  1030.   Window Library.  This function also sets global variables, so it is also
  1031.   mandatory to call WindowInitializeSystem() before accessing any global
  1032.   variables defined by The C Window Library.
  1033.  
  1034.   WindowInitializeSystem() detects the type of video display used, the number
  1035.   of rows and columns that the screen currently displays, and initializes data
  1036.   structures and global variables.
  1037.  
  1038.   Example:
  1039.  
  1040.       #include "window.h"
  1041.  
  1042.       main()
  1043.       {
  1044.         WindowInitializeSystem();   /* Initialization function */
  1045.         /* Now it is safe to use C Window Library functions and global
  1046.            variables */
  1047.       }
  1048.  
  1049.   There is no return value for WindowInitializeSystem().
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  Page 8                     The C Window Library                    Page 8
  1073.  
  1074.                                CREATING WINDOWS
  1075.                                ----------------
  1076.  
  1077.   We will now look how a window is created by defining a WINDOW, WPOINTER, and
  1078.   using the WindowSaveInitial() and WindowInitialize() function.
  1079.  
  1080.  
  1081.  
  1082.   The WINDOW structure and WPOINTER structure pointer
  1083.   ---------------------------------------------------
  1084.  
  1085.   When a window is created, the upper left hand column and row, the width,
  1086.   height, etc. must be recorded.  It would be very tedious if for every
  1087.   function call that acts on these windows we have to specify width, height,
  1088.   upper left hand row, etc. as function parameters.  The C Window Library
  1089.   conveniently has a structure called WINDOW, and its corresponding pointer
  1090.   called a WPOINTER to alleviate these problems.
  1091.  
  1092.   When a window is created, its characteristics are stored in a WINDOW
  1093.   structure, and most functions require that a pointer to this structure be
  1094.   passed.  This pointer is called a WPOINTER.  By only referring to the
  1095.   WPOINTER, argument lists to functions become much shorter.
  1096.  
  1097.  
  1098.  
  1099.  
  1100.   WindowSaveInitial()
  1101.   -------------------
  1102.  
  1103.   The WindowSaveInitial() function saves the base screen as a window.  This
  1104.   MUST be called prior to creating any windows.  Here is a prototype:
  1105.  
  1106.        int WindowSaveInitial(int page)
  1107.  
  1108.  
  1109.   The page argument is the video page of the base screen to save.  If you are
  1110.   creating windows that will be manipulated on video page 0, you must call
  1111.   WindowSaveInitial() with 0 as the argument:
  1112.  
  1113.        #include "window.h"
  1114.  
  1115.        main()
  1116.        {
  1117.          WindowInitializeSystem();  /* Initialize global variables */
  1118.          WindowSaveInitial(0);      /* Save video page 0's base screen */
  1119.        }
  1120.  
  1121.   In most applications, the initial screen page is page 0.  However, it is
  1122.   safer to use the global variable active_video_page (explained on page 276) to
  1123.   determine the page.  If you are changing video pages in an application, and
  1124.   the new page has not been accessed, you should call WindowSaveInitial() for
  1125.   that page.  It is important to save the base screen before writing windows on
  1126.   the screen.  If the base is not saved, the window manager will not update the
  1127.  
  1128.  Page 9                     The C Window Library                    Page 9
  1129.  
  1130.   screen properly when moving windows, hiding windows, etc.  This function must
  1131.   be called only once in an application for each screen page desired.
  1132.  
  1133.   If there is no error, WindowSaveInitial() returns NO_ERROR.
  1134.   If there is an error, WindowSaveInitial() returns the following values:
  1135.  
  1136.     BAD_DISPLAY_PAGE if the page desired does not exist, or was not detected
  1137.       by The C Window Library.
  1138.  
  1139.     NO_HEAP_MEM if there is no memory to save the initial screen.
  1140.  
  1141.     MAX_WINDOW if the maximum number of windows has already been defined.
  1142.  
  1143.  
  1144.  
  1145.   WindowInitialize()
  1146.   ------------------
  1147.  
  1148.   The next function is WindowInitialize().  This function sets up a window with
  1149.   the position on the screen to place the window, width, height, colors,
  1150.   and box type.  If successful, this function returns a new WPOINTER.  Here is
  1151.   an example:
  1152.  
  1153.         #include "window.h"
  1154.         #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1155.  
  1156.         WPOINTER w;
  1157.         main()
  1158.         {
  1159.           WindowInitializeSystem();
  1160.           WindowSaveInitial(0);
  1161.           w = WindowInitialize(BORDER,1,1,30,15,NORM,NORM,SINGLEBOX);
  1162.           ...
  1163.         }
  1164.  
  1165.   In the above example, we have defined a variable w as having a WPOINTER type.
  1166.   This variable will ultimately point to a valid WINDOW structure.  The first
  1167.   argument to WindowInitialize() is a constant called BORDER.  This tells the
  1168.   window manager that the window desired is going to have a border.  If no
  1169.   border was desired, the constant would be NOBORDER. The second and third
  1170.   arguments tells the window manager the row and column of the screen where the
  1171.   upper left corner of the window will be located.  Since the upper left corner
  1172.   of the screen is row 1, column 1, the upper left hand corner of the window
  1173.   will be placed at the upper left corner of the video screen.  The fourth and
  1174.   fifth argument denotes the width and the height of the window.  DO NOT
  1175.   INCLUDE THE BORDERS (if any) TO DETERMINE THE WIDTH AND HEIGHT OF THE WINDOW.
  1176.   Our window will have a width of 30 characters and a height of 15 characters.
  1177.   The sixth and seventh arguments are the video attributes of the inside of the
  1178.   window and the border respectively.
  1179.  
  1180.   The last argument tells us what type of border the window will have.  We use
  1181.   the constant SINGLEBOX to tell the window manager that we want a window with
  1182.  
  1183.  
  1184.  Page 10                     The C Window Library                    Page 10
  1185.  
  1186.   a border made up of single lines.
  1187.  
  1188.   If there is no error, WindowInitialize() returns a valid WPOINTER.
  1189.   If there is an error, WindowInitialize() returns a WIN_NULL_PTR (a null
  1190.   window pointer) and sets window_error_code to one of the following values:
  1191.  
  1192.    NO_HEAP_MEM if there is not enough memory to allocate for the window
  1193.      structure.
  1194.  
  1195.    BAD_WINDOW_SIZE if the dimensions for the window are too large for the
  1196.      physical screen.
  1197.  
  1198.    MAX_WINDOW if there are > 254 windows defined.
  1199.  
  1200.  
  1201.   Even though there is a structure type called WINDOW, you should always use
  1202.   the pointer to the structure (WPOINTER) rather than the WINDOW structure
  1203.   itself.
  1204.  
  1205.  
  1206.  
  1207.   CREATE_VIDEO_ATTRIBUTE() macro
  1208.   ------------------------------
  1209.  
  1210.   Please note the use of the macro CREATE_VIDEO_ATTRIBUTE() in the previous
  1211.   example to create an integer representing the foreground and background
  1212.   colors.  This macro uses the first argument as the background color, and the
  1213.   second argument is the foreground color.  In the above example we have a
  1214.   constant called NORM which uses CREATE_VIDEO_ATTRIBUTE() to create a black
  1215.   background and a white foreground color combination.
  1216.  
  1217.  
  1218.  
  1219.   Box types
  1220.   ---------
  1221.   For ease of use, There are predefined constants found in the vidsys.h
  1222.   header file that contains definitions of common border types.  These
  1223.   constants are as follows:
  1224.  
  1225.   DOUBLEBOX -- defines border characters for double box windows.
  1226.  
  1227.   SINGLEBOX -- defines border characters for single box windows.
  1228.  
  1229.   MIXEDBOX1 -- defines double lines for top and bottom and single lines on the
  1230.                sides.
  1231.  
  1232.   MIXEDBOX2 -- defines single lines for top and bottom and double lines on the
  1233.                sides.
  1234.  
  1235.   HATCHBOX1 -- defines a 'dotty' box.
  1236.  
  1237.   HATCHBOX2 -- Another 'dotty' box.
  1238.  
  1239.  
  1240.  Page 11                     The C Window Library                    Page 11
  1241.  
  1242.   HATCHBOX3 -- Yet another 'dotty' box.
  1243.  
  1244.   SOLIDBOX1 -- defines a box of solid characters.
  1245.  
  1246.   SOLIDBOX2 -- defines another box of different solid characters.
  1247.  
  1248.   BLANKBOX  -- defines a box with a blank border.  When using these characters,
  1249.                do not get confused with a window with no border, and a window
  1250.                with a blank border.
  1251.  
  1252.   DOTTEDLINE -- defines a box with dotted lines.
  1253.  
  1254.  
  1255.   Although there are predefined border types in The C Window Library, you can
  1256.   define your own types.  The window border characters are represented by an 8
  1257.   byte character string.  Each character in this string refers to a border
  1258.   character to be used in drawing the window border.  A list of what each
  1259.   position in the string stands for is as follows:
  1260.  
  1261.   position                Representation
  1262.   --------           ---------------------------
  1263.      0               Upper left corner character.
  1264.      1               Top line character.
  1265.      2               Upper right corner character.
  1266.      3               Left side character.
  1267.      4               Right side character.
  1268.      5               Bottom left corner character.
  1269.      6               Bottom line character.
  1270.      7               Bottom right corner character.
  1271.  
  1272.  
  1273.   This character string is sent to the window functions that call for a string
  1274.   of box drawing characters.  For example, you can create your own customized
  1275.   set of characters with something like this:
  1276.  
  1277.   #define MYBOXCHARS  "+-+||+-+"
  1278.  
  1279.   MYBOXCHARS is a literal string of box drawing characters.  Using the rules of
  1280.   box drawing characters defined above, the upper left hand corner of the box is
  1281.   the plus sign, the top line is the hyphen, the upper right and corner is the
  1282.   plus sign, the left side is a pipe character, as is the right side, and the
  1283.   bottom part of the box is defined the same as the upper part.  Then you would
  1284.   use it in a call to any function that asks for a box drawing string like this
  1285.  
  1286.              w = WindowInitialize(BORDER, ... ,MYBOXCHARS);
  1287.  
  1288.  
  1289.   The '... ' are the other arguments that you would normally put for the
  1290.   WindowInitialize() function.
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  Page 12                     The C Window Library                    Page 12
  1297.  
  1298.                     OPENING WINDOWS FOR READING AND WRITING
  1299.                     ---------------------------------------
  1300.  
  1301.   The next step is to allocate memory for the window's text buffer.  This will
  1302.   allow writing and reading characters to the window even though it is not
  1303.   visible.
  1304.  
  1305.  
  1306.  
  1307.   WindowOpen()
  1308.   ------------
  1309.  
  1310.   The WindowOpen() function is used to allocate memory for the window's text
  1311.   buffer.  This function MUST be called if you are going to do many of the
  1312.   window functions.  Here is the previous example with the WindowOpen() call:
  1313.  
  1314.         #include "window.h"
  1315.         #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1316.  
  1317.         WPOINTER w;
  1318.         main()
  1319.         {
  1320.           WindowInitializeSystem();
  1321.           WindowSaveInitial(0);
  1322.           w = WindowInitialize(BORDER,1,1,20,15,NORM,NORM,SINGLEBOX);
  1323.           WindowOpen(w);
  1324.           ...
  1325.         }
  1326.  
  1327.  
  1328.   The WindowOpen() function does not display the window.  The argument tells
  1329.   the window manager what window to open.  In this case we want to open our new
  1330.   window, w.  The window buffer is cleared to spaces using the window's text
  1331.   attribute, and the border (if there is a border) is drawn internally.  When a
  1332.   window is opened with WindowOpen(), you can then write or read characters to
  1333.   a window, move, scroll, etc.  almost any function that you can do with a
  1334.   visible window.
  1335.  
  1336.   If there is no error, WindowOpen() returns NO_ERROR.
  1337.   If there is an error, WindowOpen() returns one of the following:
  1338.  
  1339.   1) NO_HEAP_MEM if there is not enough memory to allocate for the window
  1340.      buffer.
  1341.  
  1342.   2) BAD_WINDOW if the window does not exist.
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  Page 13                     The C Window Library                    Page 13
  1353.  
  1354.                               DISPLAYING WINDOWS
  1355.                               ------------------
  1356.  
  1357.   Now we will display the window we created in the previous example.
  1358.  
  1359.  
  1360.   The WindowDisplay() function and Explosion Effects
  1361.   --------------------------------------------------
  1362.  
  1363.   The WindowDisplay() function displays a window.  Here is the previous
  1364.   example with WindowDisplay() added to it:
  1365.  
  1366.         #include "window.h"
  1367.         #define  NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1368.  
  1369.         WPOINTER w;
  1370.         main()
  1371.         {
  1372.           WindowInitializeSystem();
  1373.           WindowSaveInitial(0);
  1374.           w = WindowInitialize(BORDER,1,1,20,15,NORM,NORM,SINGLEBOX);
  1375.           WindowOpen(w);
  1376.           WindowDisplay(w,1,NOEFFECT);
  1377.           ...
  1378.         }
  1379.  
  1380.   The first argument to WindowDisplay() is the window to display, in our case,
  1381.   w is the window.  The second argument is the rank order of the window.
  1382.   Since the rank order we desire is 1, this window will lie on top of all
  1383.   windows, unless another window is opened with a rank of 1.  Remember, any
  1384.   window with a rank number n will have windows with rank n-1, n-2,...,1 to be
  1385.   displayed on top of it.  You can change the rank order of a window at any
  1386.   time by calling WindowDisplay() with a different rank number.
  1387.  
  1388.   The third argument to WindowDisplay() is the explosion effect of the window
  1389.   when it is displayed.  There are currently 12 ways to explode a window on the
  1390.   screen, numbered from 0 thru 11.  Here is an overview of each effect:
  1391.  
  1392.  
  1393.         Defined Constant        Value            Effect
  1394.         ----------------        -----            ------
  1395.  
  1396.            NOEFFECT               0          ┌─────────────┐
  1397.                                              │             │
  1398.                                              │             │
  1399.                                              │             │
  1400.                                              │             │
  1401.                                              │             │
  1402.                                              │             │
  1403.                                              │             │
  1404.                                              └─────────────┘
  1405.  
  1406.  
  1407.  
  1408.  Page 14                     The C Window Library                    Page 14
  1409.  
  1410.            EXPLODE                1       ┌─────────────────┐
  1411.                                           │        ^        │
  1412.                                           │        |        │
  1413.                                           │        |        │
  1414.                                           │<--           -->│
  1415.                                           │                 │
  1416.                                           │        |        │
  1417.                                           │        |        │
  1418.                                           │        v        │
  1419.                                           └─────────────────┘
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.            CONTRACT               2       ┌─────────────────┐
  1426.                                           │        |        │
  1427.                                           │        |        │
  1428.                                           │        v        │
  1429.                                           │-->           <--│
  1430.                                           │        ^        │
  1431.                                           │        |        │
  1432.                                           │        |        │
  1433.                                           └─────────────────┘
  1434.  
  1435.  
  1436.            BRICKS                 3        ┌────────────────┐
  1437.                                            │█     █    █   █│
  1438.                                            │ █              │
  1439.                                            │     █     █  █ │
  1440.                                            │        █       │
  1441.                                            │  █  █    █   █ │
  1442.                                            │█        █      │
  1443.                                            └────────────────┘
  1444.  
  1445.  
  1446.  
  1447.  
  1448.                                                     ^
  1449.            MIDDLEROWOUT           4                 |
  1450.                                             ┌───────────────┐
  1451.                                             └───────────────┘
  1452.                                                     |
  1453.                                                     v
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  Page 15                     The C Window Library                    Page 15
  1465.  
  1466.            TOPBOTTOMIN            5         ┌───────────────┐
  1467.                                             └───────────────┘
  1468.                                                     |
  1469.                                                     v
  1470.  
  1471.                                                     ^
  1472.                                                     |
  1473.                                             ┌───────────────┐
  1474.                                             └───────────────┘
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.            TOPDOWN                6         ┌───────────────┐
  1483.                                             └───────────────┘
  1484.                                                     |
  1485.                                                     v
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.                                                     ^
  1493.            BOTTOMUP               7                 |
  1494.                                             ┌───────────────┐
  1495.                                             └───────────────┘
  1496.  
  1497.  
  1498.  
  1499.  
  1500.            MIDDLECOLOUT           8                ┌┐
  1501.                                                    ││
  1502.                                                    ││
  1503.                                                    ││
  1504.                                                  <-││->
  1505.                                                    ││
  1506.                                                    ││
  1507.                                                    ││
  1508.                                                    └┘
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  Page 16                     The C Window Library                    Page 16
  1521.  
  1522.            LEFTRIGHTIN            9              ┌┐      ┌┐
  1523.                                                  ││      ││
  1524.                                                  ││      ││
  1525.                                                  ││      ││
  1526.                                                  ││->  <-││
  1527.                                                  ││      ││
  1528.                                                  ││      ││
  1529.                                                  ││      ││
  1530.                                                  ││      ││
  1531.                                                  └┘      └┘
  1532.  
  1533.  
  1534.  
  1535.  
  1536.            LEFTTORIGHT            10             ┌┐
  1537.                                                  ││
  1538.                                                  ││
  1539.                                                  ││
  1540.                                                  ││->
  1541.                                                  ││
  1542.                                                  ││
  1543.                                                  ││
  1544.                                                  ││
  1545.                                                  └┘
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.            RIGHTTOLEFT            11             ┌┐
  1552.                                                  ││
  1553.                                                  ││
  1554.                                                  ││
  1555.                                                <-││
  1556.                                                  ││
  1557.                                                  ││
  1558.                                                  ││
  1559.                                                  ││
  1560.                                                  └┘
  1561.  
  1562.  
  1563.   If there is no error, WindowDisplay() will return NO_ERROR.
  1564.   If there is an error, WindowDisplay() will return one of the following:
  1565.  
  1566.   BAD_WINDOW if the window does not exist.
  1567.  
  1568.   WINDOW_NOT_OPEN if the window was not open with WindowOpen().
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  Page 17                     The C Window Library                    Page 17
  1577.  
  1578.   Displaying Multiple Windows
  1579.   ---------------------------
  1580.  
  1581.   If you are creating multiple windows you can change the rank of the window by
  1582.   calling WindowDisplay() with a different rank number.  Here is an example:
  1583.  
  1584.  
  1585.  
  1586.    #include "window.h"
  1587.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define video
  1588.                                                           attribute */
  1589.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  1590.                                                            video attribute */
  1591.    #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  1592.    #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  1593.  
  1594.    main()
  1595.    {
  1596.      int i;
  1597.      WPOINTER w1,w2,w3;             /* pointers to a window structures */
  1598.      WindowInitializeSystem();     /* system initialization function */
  1599.      WindowSaveInitial(0);
  1600.      w1 = WindowInitialize(BORDER,          /* Window has a border */
  1601.             1,               /* row on the screen to open window */
  1602.             1,               /* column on screen to open window */
  1603.             30,              /* width in characters of the window */
  1604.             15,              /* height of characters in window */
  1605.             BLUEONBLACK,     /* video attribute of text area of window */
  1606.             NORM,            /* video attribute of border */
  1607.             SINGLEBOX);      /* type of border to draw */
  1608.  
  1609.      /* define second window */
  1610.      w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,DOUBLEBOX);
  1611.  
  1612.      /* define third window */
  1613.  
  1614.      w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,SINGLEBOX);
  1615.  
  1616.      WindowOpen(w1);      /* make window 1 ok to write */
  1617.  
  1618.      WindowOpen(w2);      /* make window 2 ok to write */
  1619.  
  1620.      WindowOpen(w3);      /* make window 3 ok to write */
  1621.  
  1622.      WindowDisplay(w1,1,NOEFFECT);
  1623.      WindowDisplay(w2,2,NOEFFECT);
  1624.      WindowDisplay(w3,3,NOEFFECT);
  1625.  
  1626.      GET_KEY();
  1627.  
  1628.      WindowDisplay(w2,1,NOEFFECT);
  1629.  
  1630.      GET_KEY();
  1631.  
  1632.  Page 18                     The C Window Library                    Page 18
  1633.  
  1634.      WindowDisplay(w3,1,NOEFFECT);
  1635.  
  1636.      GET_KEY();
  1637.  
  1638.      WindowDisplay(w1,1,NOEFFECT);
  1639.  
  1640.      GET_KEY();
  1641.    }
  1642.  
  1643.  
  1644.  
  1645.   In the above program, w1, w2, and w3 are displayed with rank numbers of 1, 2,
  1646.   and 3, respectively.  The ordering means that w1 will overlay w2, and w2 will
  1647.   overlay w3.
  1648.  
  1649.   Note that after the windows w1, w2, and w3 are initially displayed, they are
  1650.   redisplayed by making another call to WindowDisplay().  You can redisplay a
  1651.   window and change its rank by calling the WindowDisplay() function again.  For
  1652.   example, w2 is redisplayed with a rank of 1.  This promotes w2 to the top of
  1653.   the stack of displayed windows, and demotes w1 with a rank of 2.  Each and
  1654.   every window has a unique rank number.  The window manager keeps track of
  1655.   conflicts in rank numbers, and adjusts the data structures involved in
  1656.   maintaining the windows in working order.  Therefore, there is really no need
  1657.   for you to remember whether a rank number is used or not.
  1658.  
  1659.   The macro GET_KEY() pauses the program until you press a key.
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  Page 19                     The C Window Library                    Page 19
  1689.  
  1690.                                 CLOSING WINDOWS
  1691.                                 ---------------
  1692.  
  1693.   In this section, we will discuss closing windows with and without destroying
  1694.   the window pointer.
  1695.  
  1696.  
  1697.  
  1698.   WindowClose()
  1699.   -------------
  1700.  
  1701.   The WindowClose() function hides a window from the screen and deallocates any
  1702.   memory that was allocated by the WindowOpen() function described in the
  1703.   previous section.  This DOES NOT destroy the window pointer (WPOINTER),
  1704.   however you must call WindowOpen() again if you want to use this window again
  1705.   for most other window functions.  Here is the prototype:
  1706.  
  1707.  
  1708.                  int WindowClose(WPOINTER w, int effect)
  1709.  
  1710.   The first argument is the window.  The second argument is the special effect
  1711.   to use when closing the window.  This argument is only meaningful if the
  1712.   window is visible.  For a list of effects refer back to page 14.  This
  1713.   function can be used if you are short of memory, but you do not want to
  1714.   destroy the WPOINTER.
  1715.  
  1716.  
  1717.  
  1718.   Example:
  1719.  
  1720.  
  1721.    #include "window.h"
  1722.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define video
  1723.                                                           attribute */
  1724.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  1725.                                                            video attribute */
  1726.    #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  1727.    #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  1728.  
  1729.    main()
  1730.    {
  1731.      int i;
  1732.      WPOINTER w1,w2,w3;             /* pointers to a window structures */
  1733.      WindowInitializeSystem();     /* system initialization function */
  1734.      WindowSaveInitial(0);
  1735.      w1 = WindowInitialize(BORDER,          /* Window has a border */
  1736.             1,               /* row on the screen to open window */
  1737.             1,               /* column on screen to open window */
  1738.  
  1739.             30,              /* width in characters of the window */
  1740.             15,              /* height of characters in window */
  1741.             BLUEONBLACK,     /* video attribute of text area of window */
  1742.             NORM,            /* video attribute of border */
  1743.  
  1744.  Page 20                     The C Window Library                    Page 20
  1745.  
  1746.             SINGLEBOX);      /* type of border to draw */
  1747.  
  1748.      /* define second window */
  1749.      w2 = WindowInitialize(BORDER,3,3,30,15,REDONBLACK,NORM,DOUBLEBOX);
  1750.  
  1751.      /* define third window */
  1752.  
  1753.      w3 = WindowInitialize(BORDER,5,5,30,15,GREENONBLACK,NORM,SINGLEBOX);
  1754.  
  1755.      WindowOpen(w1);      /* make window 1 ok to write */
  1756.  
  1757.      WindowOpen(w2);      /* make window 2 ok to write */
  1758.  
  1759.      WindowOpen(w3);      /* make window 3 ok to write */
  1760.  
  1761.      WindowDisplay(w1,1,NOEFFECT);
  1762.      WindowDisplay(w2,2,NOEFFECT);
  1763.      WindowDisplay(w3,3,NOEFFECT);
  1764.  
  1765.      GET_KEY();
  1766.  
  1767.      WindowDisplay(w2,1,NOEFFECT);
  1768.  
  1769.      GET_KEY();
  1770.  
  1771.      WindowDisplay(w3,1,NOEFFECT);
  1772.  
  1773.      GET_KEY();
  1774.  
  1775.      WindowDisplay(w1,1,NOEFFECT);
  1776.  
  1777.      GET_KEY();
  1778.  
  1779.      WindowClose(w2,NOEFFECT);
  1780.  
  1781.      GET_KEY();
  1782.  
  1783.      WindowClose(w3,NOEFFECT);
  1784.  
  1785.      GET_KEY();
  1786.  
  1787.      WindowClose(w1,NOEFFECT);
  1788.    }
  1789.  
  1790.  
  1791.   The example above calls WindowClose() on all three windows.
  1792.  
  1793.  
  1794.   If there are no errors, WindowClose() returns NO_ERROR.
  1795.   If there are errors, WindowClose() returns the following value:
  1796.  
  1797.   BAD_WINDOW if the window w does not exist.
  1798.  
  1799.  
  1800.  Page 21                     The C Window Library                    Page 21
  1801.  
  1802.   WindowFree()
  1803.   ------------
  1804.  
  1805.   The WindowFree() function acts just like the WindowClose() function except
  1806.   that the WPOINTER is also deallocated.  This means that the WPOINTER cannot
  1807.   be used anymore unless it is initialized again using WindowInitialize(), or
  1808.   is assigned to another valid WPOINTER.  Here is the prototype:
  1809.  
  1810.                int WindowFree(WPOINTER w, int effect)
  1811.  
  1812.   Refer to WindowClose() for definitions of arguments and return values.
  1813.  
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  Page 22                     The C Window Library                    Page 22
  1857.  
  1858.                         CHANGING WINDOW CHARACTERISTICS
  1859.                         -------------------------------
  1860.  
  1861.   In this section, we will discuss changing the window attributes, border
  1862.   style, and the window's height and width.
  1863.  
  1864.  
  1865.   WindowChangeTextAttribute()
  1866.   ---------------------------
  1867.  
  1868.  
  1869.   This function changes the attribute of the text portion of the window.  The
  1870.   text portion is the inside of the window.  Here is a prototype:
  1871.  
  1872.        int WindowChangeTextAttribute(WPOINTER w, int color)
  1873.  
  1874.   where w is the WPOINTER to change the text attribute, and color is the new
  1875.   color.  You can use the CREATE_VIDEO_ATTRIBUTE() macro discussed on page 11
  1876.   to define the color.
  1877.  
  1878.   Example:
  1879.  
  1880.   #include "window.h"
  1881.  
  1882.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1883.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  1884.  
  1885.   WPOINTER w;
  1886.  
  1887.   main()
  1888.   {
  1889.     WindowInitializeSystem();
  1890.     WindowSaveInitial(0);
  1891.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  1892.     WindowOpen(w);
  1893.     WindowDisplay(w,1,NOEFFECT);
  1894.     GET_KEY();
  1895.     WindowChangeTextAttribute(w,REVERSE);
  1896.   }
  1897.  
  1898.   If there is no error, WindowChangeTextAttribute() returns NO_ERROR.
  1899.   If there is an error, the following value is returned:
  1900.  
  1901.      BAD_WINDOW if the window does not exist.
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  Page 23                     The C Window Library                    Page 23
  1913.  
  1914.   WindowChangeBorderAttribute()
  1915.   -----------------------------
  1916.  
  1917.   This function changes the video attribute of the border of the window.  If
  1918.   the window does not have a border, nothing is changed.  Here is a prototype:
  1919.  
  1920.        int WindowChangeBorderAttribute(WPOINTER w, int color)
  1921.  
  1922.   where w is the WPOINTER to change the border attribute, and color is the new
  1923.   color.  You can use the CREATE_VIDEO_ATTRIBUTE() macro discussed on page 11
  1924.   to define the color.
  1925.  
  1926.  
  1927.  
  1928.   Example:
  1929.  
  1930.  
  1931.   #include "window.h"
  1932.  
  1933.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  1934.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  1935.  
  1936.   WPOINTER w;
  1937.  
  1938.   main()
  1939.   {
  1940.     WindowInitializeSystem();
  1941.     WindowSaveInitial(0);
  1942.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  1943.     WindowOpen(w);
  1944.     WindowDisplay(w,1,NOEFFECT);
  1945.     GET_KEY();
  1946.     WindowChangeBorderAttribute(w,REVERSE);
  1947.   }
  1948.  
  1949.   If there is no error, or if the window does not have a border,
  1950.   WindowChangeBorderAttribute() returns NO_ERROR.
  1951.  
  1952.   If there is an error, WindowChangeBorderAttribute() returns the following
  1953.   value:
  1954.  
  1955.      BAD_WINDOW if the WPOINTER w does not exist.
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  Page 24                     The C Window Library                    Page 24
  1969.  
  1970.   WindowDrawBorder()
  1971.   ------------------
  1972.  
  1973.   You can also change the border type, or draw a border on an unbordered
  1974.   window by calling the WindowDrawBorder() function.
  1975.  
  1976.   Here is a prototype:
  1977.  
  1978.       int WindowDrawBorder(WPOINTER w, char *box)
  1979.  
  1980.   The first argument is the window we want to change the border of.  The
  1981.   second argument is a string of border characters.  This string denotes the
  1982.   type of border that the window should now have.  In the example given below,
  1983.   w is initialized with a SINGLEBOX border, but WindowDrawBorder() changes this
  1984.   to a DOUBLEBOX.
  1985.  
  1986.   The WindowDrawBorder() function is also used to draw borders on borderless
  1987.   windows.  When drawing borders on a NOBORDER window, the window must not have
  1988.   any of its sides touching the edges of the physical screen.  In other words,
  1989.   the window must "have room" for a border to be drawn.  If there is no room to
  1990.   draw the border, there is no change to the window.
  1991.  
  1992.   Example:
  1993.  
  1994.  
  1995.   #include "window.h"
  1996.  
  1997.   #define REVERSE   CREATE_VIDEO_ATTRIBUTE(white,black)
  1998.  
  1999.   WPOINTER w;
  2000.  
  2001.   main()
  2002.   {
  2003.     WindowInitializeSystem();
  2004.     WindowSaveInitial(0);
  2005.     w = WindowInitialize(NOBORDER,2,2,10,10,REVERSE,REVERSE,SINGLEBOX);
  2006.     WindowOpen(w);
  2007.     WindowDisplay(w,1,NOEFFECT);
  2008.     GET_KEY();
  2009.     WindowDrawBorder(w,DOUBLEBOX);  /* Draws a double box around NOBORDER
  2010.                                        window */
  2011.   }
  2012.  
  2013.  
  2014.   If there is no error, WindowDrawBorder() returns NO_ERROR.
  2015.   If there is an error, WindowDrawBorder() returns one of the following values:
  2016.  
  2017.   BAD_WINDOW if the window w does not exist.
  2018.  
  2019.   NO_HEAP_MEM if there is not enough memory to allocate for temporary buffer.
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  Page 25                     The C Window Library                    Page 25
  2025.  
  2026.   WindowRemoveBorder()
  2027.   --------------------
  2028.  
  2029.   This function removes a border from a bordered window.  Here is the
  2030.   prototype:
  2031.  
  2032.        int WindowRemoveBorder(WPOINTER w)
  2033.  
  2034.   If the window does not have a border, nothing is changed.
  2035.  
  2036.   Example:
  2037.  
  2038.   #include "window.h"
  2039.   #define REVERSE   CREATE_VIDEO_ATTRIBUTE(white,black)
  2040.  
  2041.   WPOINTER w;
  2042.  
  2043.   main()
  2044.   {
  2045.     WindowInitializeSystem();
  2046.     WindowSaveInitial(0);
  2047.     w = WindowInitialize(BORDER,1,1,10,10,REVERSE,REVERSE,SINGLEBOX);
  2048.     WindowOpen(w);
  2049.     WindowDisplay(w,1,NOEFFECT);
  2050.     GET_KEY();
  2051.     WindowRemoveBorder(w);  /* Removes the double box around BORDERed
  2052.                                        window */
  2053.   }
  2054.  
  2055.   If there is no error, WindowRemoveBorder() returns NO_ERROR.
  2056.   If there is an error, WindowRemoveBorder returns one of the following values:
  2057.  
  2058.     BAD_WINDOW if the window w does not exist.
  2059.  
  2060.     NO_HEAP_MEM if there is not enough memory to allocate for temporary buffer.
  2061.  
  2062.  
  2063.  
  2064.   WindowResizeHeight()
  2065.   --------------------
  2066.  
  2067.   This function changes the inside (text portion) height of the window.  Here
  2068.   is a prototype:
  2069.  
  2070.     int WindowResizeHeight(WPOINTER w, int newheight, int anchor)
  2071.  
  2072.   The newheight argument is the new height of the window.  If the height will
  2073.   exceed the bounds of the screen, the window is given its maximum height.  The
  2074.   anchor argument determines which side to "hold down" while the window is
  2075.   being resized.  If the anchor is ANCHORTOP, the top line of the window is
  2076.   held in its current position and the window is resized accordingly.  If
  2077.   anchor is ANCHORBOTTOM, the bottom of the window is held and the window is
  2078.   resized accordingly.
  2079.  
  2080.  Page 26                     The C Window Library                    Page 26
  2081.  
  2082.   If there is text in the window, the text will be truncated if the window is
  2083.   made shorter (unless the window is a viewport to a virtual window.  Virtual
  2084.   windows are discussed on page 103).
  2085.  
  2086.   Example:
  2087.  
  2088.   #include "window.h"
  2089.  
  2090.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2091.  
  2092.   WPOINTER w;
  2093.  
  2094.   main()
  2095.   {
  2096.     WindowInitializeSystem();
  2097.     WindowSaveInitial(0);
  2098.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2099.     WindowOpen(w);
  2100.     WindowDisplay(w,1,NOEFFECT);
  2101.     GET_KEY();
  2102.     WindowResizeHeight(w,15,ANCHORTOP);  /* Resize the window with a new
  2103.                                             height of 15 */
  2104.     GET_KEY();
  2105.     WindowResizeHeight(w,5,ANCHORBOTTOM); /* Resize window with new
  2106.                                              height of 5 */
  2107.   }
  2108.  
  2109.  
  2110.   If there were no errors, NO_ERROR is returned.
  2111.  
  2112.   If there is an error, WindowResizeHeight() returns one of the following
  2113.   values:
  2114.  
  2115.      BAD_WINDOW if the WPOINTER w does not exist.
  2116.  
  2117.      NO_HEAP_MEM if there was not enough memory to allocate for the resized
  2118.      window.
  2119.  
  2120.  
  2121.  
  2122.   WindowResizeWidth()
  2123.   -------------------
  2124.  
  2125.   This function changes the inside (text portion) width of the window.  Here
  2126.   is a prototype:
  2127.  
  2128.     int WindowResizeWidth(WPOINTER w, int newwidth, int anchor)
  2129.  
  2130.   The newwidth argument is the new width of the window.  If the width will
  2131.   exceed the bounds of the screen, the window is given its maximum width.  The
  2132.   anchor argument determines which side to "hold down" while the window is
  2133.   being resized.  If the anchor is ANCHORLEFT, the left side of the window is
  2134.   held in its current position and the window is resized accordingly.  If
  2135.  
  2136.  Page 27                     The C Window Library                    Page 27
  2137.  
  2138.   anchor is ANCHORRIGHT, the right side of the window is held and the window is
  2139.   resized accordingly.
  2140.  
  2141.   If there is text in the window, the text will be truncated if the window is
  2142.   made shorter (unless the window is a viewport to a virtual window.  Virtual
  2143.   windows are discussed on page 103).
  2144.  
  2145.  
  2146.   main()
  2147.   {
  2148.     WindowInitializeSystem();
  2149.     WindowSaveInitial(0);
  2150.     w = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  2151.     WindowOpen(w);
  2152.     WindowDisplay(w,1,NOEFFECT);
  2153.     GET_KEY();
  2154.     WindowResizeWidth(w,15,ANCHORLEFT);  /* Resize the window with a new
  2155.                                             width of 15 */
  2156.     GET_KEY();
  2157.     WindowResizeWidth(w,5,ANCHORRIGHT);   /* Resize window with new width
  2158.                                              of 5 */
  2159.   }
  2160.  
  2161.  
  2162.   If there were no errors, NO_ERROR is returned.
  2163.  
  2164.   If there is an error, WindowResizeWidth() returns one of the following:
  2165.  
  2166.      BAD_WINDOW if the WPOINTER w does not exist.
  2167.  
  2168.      NO_HEAP_MEM if there was not enough memory to allocate for the resized
  2169.      window.
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.  
  2187.  
  2188.  
  2189.  
  2190.  
  2191.  
  2192.  Page 28                     The C Window Library                    Page 28
  2193.  
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.  
  2200.                        This page intentionally left blank
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  Page 29                     The C Window Library                    Page 29
  2249.  
  2250.                             WRITING TEXT TO WINDOWS
  2251.                             -----------------------
  2252.  
  2253.   There are various functions that will write text to a window.  These
  2254.   functions are divided into two groups: Functions that specify a null
  2255.   terminated string, and functions that require the length of the string of
  2256.   characters to write to be an explicit argument.
  2257.  
  2258.  
  2259.   Null Terminated Write Functions
  2260.   -------------------------------
  2261.  
  2262.   WindowWriteString()
  2263.   -------------------
  2264.  
  2265.   The WindowWriteString() function writes a null terminated string of characters
  2266.   to a window at a specified row and column of the window.  If the string is too
  2267.   long to fit in the boundaries of the window, the string is clipped (truncated)
  2268.   to fit in the boundaries of the window.
  2269.  
  2270.   Here is the prototype:
  2271.  
  2272.        int WindowWriteString(WPOINTER w, char *string, int row, int col)
  2273.  
  2274.   The first argument is the window to write the string to.  The second argument
  2275.   is the null terminated string to write.  The third and fourth arguments are
  2276.   the row and column of the window to place the string.  The video attribute
  2277.   used when writing the string is the video attribute of the inside of the
  2278.   window.
  2279.  
  2280.  
  2281.   Example:
  2282.  
  2283.  
  2284.   #include "window.h"
  2285.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2286.  
  2287.   WPOINTER w;
  2288.   int i;
  2289.  
  2290.   main()
  2291.   {
  2292.     WindowInitializeSystem();
  2293.     WindowSaveInitial(0);
  2294.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2295.     WindowOpen(w);
  2296.     WindowDisplay(w,1,NOEFFECT);
  2297.     GET_KEY();
  2298.     for (i=1;i<=10;i++)
  2299.       WindowWriteString(w,"Hello World",i,1);
  2300.   }
  2301.  
  2302.  
  2303.  
  2304.  Page 30                     The C Window Library                    Page 30
  2305.  
  2306.   The above example writes the string "Hello World" to each line of the window
  2307.   w.
  2308.  
  2309.   If there is no error WindowWriteString() returns NO_ERROR.
  2310.   If there is an error WindowWriteString() returns the following:
  2311.  
  2312.   BAD_WINDOW if the WPOINTER w does not exist.
  2313.  
  2314.   WINDOW_BOUND if the row or column specified are out of bounds of the window.
  2315.  
  2316.   WINDOW_NOT_OPEN if the window was not open for writing (did not use
  2317.   WindowOpen() on the window)
  2318.  
  2319.  
  2320.  
  2321.   WindowWriteStringAttr()
  2322.   -----------------------
  2323.  
  2324.   The WindowWriteStringAttr() function works the same as the WindowWriteString()
  2325.   function except that an extra argument determines the color used to write the
  2326.   string.  Here is the prototype:
  2327.  
  2328.    int WindowWriteStringAttr(WPOINTER w, char *string, int row, int col,
  2329.                              int attr)
  2330.  
  2331.   The first argument is the window to write the string to.  The second argument
  2332.   is the null terminated string to write.  The third and fourth arguments are
  2333.   the row and column of the window to place the string. The last argument is the
  2334.   video attribute to use.
  2335.  
  2336.  
  2337.   Example:
  2338.  
  2339.  
  2340.   #include "window.h"
  2341.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2342.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2343.  
  2344.   WPOINTER w;
  2345.   int i;
  2346.  
  2347.   main()
  2348.   {
  2349.     WindowInitializeSystem();
  2350.     WindowSaveInitial(0);
  2351.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2352.     WindowOpen(w);
  2353.     WindowDisplay(w,1,NOEFFECT);
  2354.     GET_KEY();
  2355.     for (i=1;i<=10;i++)
  2356.       WindowWriteStringAttr(w,"Hello World",i,1,REVERSE);
  2357.   }
  2358.  
  2359.  
  2360.  Page 31                     The C Window Library                    Page 31
  2361.  
  2362.   The above example writes the string "Hello World" to each line of the window
  2363.   w using the video attribute defined by the constant REVERSE.
  2364.  
  2365.   The return values to WindowWriteStringAttr() are the same as
  2366.   WindowWriteString().
  2367.  
  2368.  
  2369.  
  2370.   WindowWriteCenterString()
  2371.   -------------------------
  2372.  
  2373.   The WindowWriteCenterString() function centers a null terminated string in a
  2374.   window.  Here is a prototype:
  2375.  
  2376.       int WindowWriteCenterString(WPOINTER w, char *string, int row)
  2377.  
  2378.   The first argument is the window.  The second argument is the string to write.
  2379.   The third argument is the row that the string will be centered.
  2380.  
  2381.   The attribute used to write the string is the attribute of the inside of the
  2382.   window.
  2383.  
  2384.   Example:
  2385.  
  2386.   #include "window.h"
  2387.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2388.  
  2389.   WPOINTER w;
  2390.   int i;
  2391.  
  2392.   main()
  2393.   {
  2394.     WindowInitializeSystem();
  2395.     WindowSaveInitial(0);
  2396.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2397.     WindowOpen(w);
  2398.     WindowDisplay(w,1,NOEFFECT);
  2399.     GET_KEY();
  2400.     for (i=1;i<=10;i++)
  2401.       WindowWriteCenterString(w,"Hello World",i);
  2402.   }
  2403.  
  2404.  
  2405.   The above example writes and centers the string "Hello World" to each line of
  2406.   the window w.
  2407.  
  2408.   The return values for WindowWriteCenterString() are the same as
  2409.   WindowWriteString().
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  Page 32                     The C Window Library                    Page 32
  2417.  
  2418.   WindowWriteCenterStringAttr()
  2419.   -----------------------------
  2420.  
  2421.   The WindowWriteCenterStringAttr() function works the same as the
  2422.   WindowWriteCenterString() function except that an extra argument determines
  2423.   the color used to write the string.  Here is the prototype:
  2424.  
  2425.   int WindowWriteCenterStringAttr(WPOINTER w, char *string, int row, int attr)
  2426.  
  2427.   The first argument is the window.  The second argument is the string to write.
  2428.   The third argument is the row that the string will be centered.  The last
  2429.   argument is the video attribute to use to write the string.
  2430.  
  2431.   Example:
  2432.  
  2433.   #include "window.h"
  2434.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2435.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2436.  
  2437.   WPOINTER w;
  2438.   int i;
  2439.  
  2440.   main()
  2441.   {
  2442.     WindowInitializeSystem();
  2443.     WindowSaveInitial(0);
  2444.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2445.     WindowOpen(w);
  2446.     WindowDisplay(w,1,NOEFFECT);
  2447.     GET_KEY();
  2448.     for (i=1;i<=10;i++)
  2449.       WindowWriteCenterStringAttr(w,"Hello World",i,REVERSE);
  2450.   }
  2451.  
  2452.  
  2453.   The above example writes and centers the string "Hello World" to each line of
  2454.   the window w using REVERSE as the video attribute.
  2455.  
  2456.   The return values for WindowWriteCenterStringAttr() are the same as
  2457.   WindowWriteString().
  2458.  
  2459.  
  2460.  
  2461.   WindowWriteStringCC()
  2462.   ---------------------
  2463.  
  2464.   Centers and writes a string around a column of the window (the CC stands
  2465.   for Centered Column).  If the string is longer than the width of the window,
  2466.   the string is placed on column 1 of the window and is clipped at the right
  2467.   edge of the window.  Here is the prototype:
  2468.  
  2469.   The attribute used to write the string is the attribute of the inside of the
  2470.   window.
  2471.  
  2472.  Page 33                     The C Window Library                    Page 33
  2473.  
  2474.       int WindowWriteStringCC(WPOINTER w, char *string, int row)
  2475.  
  2476.   The first argument is the window.  The second argument is the string. The
  2477.   third argument is the row to write the string, and the last argument is the
  2478.   column to center the string on.
  2479.  
  2480.  
  2481.   Example:
  2482.  
  2483.  
  2484.   #include "window.h"
  2485.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2486.  
  2487.   WPOINTER w;
  2488.  
  2489.   main()
  2490.   {
  2491.     WindowInitializeSystem();
  2492.     WindowSaveInitial(0);
  2493.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2494.     WindowOpen(w);
  2495.     WindowDisplay(w,1,NOEFFECT);
  2496.     GET_KEY();
  2497.     WindowWriteStringCC(w,"This",1,10);
  2498.     WindowWriteStringCC(w,"is",2,10);
  2499.     WindowWriteStringCC(w,"centered",3,10);
  2500.     WindowWriteStringCC(w,"around",4,10);
  2501.     WindowWriteStringCC(w,"column",5,10);
  2502.     WindowWriteStringCC(w,"10",6,10);
  2503.   }
  2504.  
  2505.   The example above writes the text centered around column 10 of the window w.
  2506.  
  2507.   The return values for WindowWriteStringCC() are the same as
  2508.   WindowWriteString().
  2509.  
  2510.  
  2511.  
  2512.  
  2513.   WindowWriteStringCCAttr()
  2514.   -------------------------
  2515.  
  2516.   The WindowWriteStringCCAttr() function works the same as the
  2517.   WindowWriteStringCC() function except that an extra argument determines
  2518.   the color used to write the string.  Here is the prototype:
  2519.  
  2520.   int WindowWriteStringCCAttr(WPOINTER w, char *string, int row, int col,
  2521.                               int attr)
  2522.  
  2523.   The first argument is the window.  The second argument is the string to write.
  2524.   The third argument is the row that the string will be centered.  The column
  2525.   argument is the column to center the string on. The last argument is the
  2526.   video attribute to use to write the string.
  2527.  
  2528.  Page 34                     The C Window Library                    Page 34
  2529.  
  2530.   Example:
  2531.  
  2532.  
  2533.   #include "window.h"
  2534.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2535.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2536.  
  2537.   WPOINTER w;
  2538.  
  2539.   main()
  2540.   {
  2541.     WindowInitializeSystem();
  2542.     WindowSaveInitial(0);
  2543.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2544.     WindowOpen(w);
  2545.     WindowDisplay(w,1,NOEFFECT);
  2546.     GET_KEY();
  2547.     WindowWriteStringCCAttr(w,"This",1,10,REVERSE);
  2548.     WindowWriteStringCCAttr(w,"is",2,10,REVERSE);
  2549.     WindowWriteStringCCAttr(w,"centered",3,10,REVERSE);
  2550.     WindowWriteStringCCAttr(w,"around",4,10,REVERSE);
  2551.     WindowWriteStringCCAttr(w,"column",5,10,REVERSE);
  2552.     WindowWriteStringCCAttr(w,"10",6,10,REVERSE);
  2553.   }
  2554.  
  2555.  
  2556.   The example above writes the text centered around column 10 of the window w
  2557.   using the video attribute REVERSE.
  2558.  
  2559.   The return values for WindowWriteStringCCAttr() are the same as
  2560.   WindowWriteString().
  2561.  
  2562.  
  2563.  
  2564.   WindowWriteStringRJ()
  2565.   ---------------------
  2566.  
  2567.   The WindowWriteStringRJ() function writes a right justified string.  Here is
  2568.   the prototype:
  2569.  
  2570.      int WindowWriteStringRJ(WPOINTER w, char *string, int row, int col)
  2571.  
  2572.   The first argument is the window.  The second argument is the string. The
  2573.   third argument is the row to write the string, and the last argument is the
  2574.   column to place the right edge of the string.
  2575.  
  2576.  
  2577.   Example:
  2578.  
  2579.   #include "window.h"
  2580.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2581.  
  2582.   WPOINTER w;
  2583.  
  2584.  Page 35                     The C Window Library                    Page 35
  2585.  
  2586.   main()
  2587.   {
  2588.     WindowInitializeSystem();
  2589.     WindowSaveInitial(0);
  2590.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2591.     WindowOpen(w);
  2592.     WindowDisplay(w,1,NOEFFECT);
  2593.     GET_KEY();
  2594.     WindowWriteStringRJ(w,"This",1,10);
  2595.     WindowWriteStringRJ(w,"is",2,10);
  2596.     WindowWriteStringRJ(w,"right",3,10);
  2597.     WindowWriteStringRJ(w,"justified",4,10);
  2598.     WindowWriteStringRJ(w,"on ",5,10);
  2599.     WindowWriteStringRJ(w,"column",6,10);
  2600.     WindowWriteStringRJ(w,"10",7,10);
  2601.   }
  2602.  
  2603.   The example above writes the text right justified on column 10 of the window
  2604.   w.
  2605.  
  2606.   The attribute used to write the string is the attribute of the inside of the
  2607.   window.
  2608.  
  2609.   The return values for WindowWriteStringRJ() are the same as
  2610.   WindowWriteString().
  2611.  
  2612.  
  2613.  
  2614.   WindowWriteStringRJAttr()
  2615.   -------------------------
  2616.  
  2617.   The WindowWriteStringRJAttr() function works the same as the
  2618.   WindowWriteStringRJ() function except that an extra argument determines the
  2619.   color used to write the string.  Here is the prototype:
  2620.  
  2621.   int WindowWriteStringRJAttr(WPOINTER w, char *string, int row, int col,
  2622.                               int attr)
  2623.  
  2624.   The first argument is the window.  The second argument is the string to write.
  2625.   The third argument is the row to write the string.  The col is the column to
  2626.   right justify the string. The last argument is the video attribute to use to
  2627.   write the string.
  2628.  
  2629.  
  2630.   Example:
  2631.  
  2632.  
  2633.   #include "window.h"
  2634.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2635.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2636.  
  2637.   WPOINTER w;
  2638.  
  2639.  
  2640.  Page 36                     The C Window Library                    Page 36
  2641.  
  2642.   main()
  2643.   {
  2644.     WindowInitializeSystem();
  2645.     WindowSaveInitial(0);
  2646.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2647.     WindowOpen(w);
  2648.     WindowDisplay(w,1,NOEFFECT);
  2649.     GET_KEY();
  2650.     WindowWriteStringRJAttr(w,"This",1,10,REVERSE);
  2651.     WindowWriteStringRJAttr(w,"is",2,10,REVERSE);
  2652.     WindowWriteStringRJAttr(w,"right",3,10,REVERSE);
  2653.     WindowWriteStringRJAttr(w,"justified",4,10,REVERSE);
  2654.     WindowWriteStringRJAttr(w,"on ",5,10,REVERSE);
  2655.     WindowWriteStringRJAttr(w,"column",6,10,REVERSE);
  2656.     WindowWriteStringRJAttr(w,"10",7,10,REVERSE);
  2657.   }
  2658.  
  2659.   The example above writes the text right justified at  column 10 of the window
  2660.   w using the video attribute REVERSE.
  2661.  
  2662.   The return values for WindowWriteStringRJAttr() are the same as
  2663.   WindowWriteString().
  2664.  
  2665.  
  2666.  
  2667.  
  2668.   Length Controlled Write Functions
  2669.   ---------------------------------
  2670.  
  2671.   The upcoming functions must have the length explicitly stated as one of the
  2672.   arguments.  These functions do not stop writing characters if the null
  2673.   character in the string to write is reached.
  2674.  
  2675.  
  2676.  
  2677.  
  2678.   WindowWriteCharacters()
  2679.   -----------------------
  2680.  
  2681.   This function writes characters from a buffer to the window.  Here is the
  2682.   prototype:
  2683.  
  2684.   int WindowWriteCharacters(WPOINTER w, char *buffer, int row, int col,
  2685.                             int length)
  2686.  
  2687.   The first argument is the window.  The second argument is a pointer to the
  2688.   buffer where the characters are stored.  The third and fourth arguments are
  2689.   the (row,col) position in the window to write the string, and the last
  2690.   argument is the number of characters from buffer to write.  The attribute
  2691.   used is the attribute of the inside of the window.
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  Page 37                     The C Window Library                    Page 37
  2697.  
  2698.   Example:
  2699.  
  2700.  
  2701.   #include "window.h"
  2702.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2703.  
  2704.   WPOINTER w;
  2705.   char buf[] = "Hello World!!";
  2706.  
  2707.   main()
  2708.   {
  2709.     WindowInitializeSystem();
  2710.     WindowSaveInitial(0);
  2711.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2712.     WindowOpen(w);
  2713.     WindowDisplay(w,1,NOEFFECT);
  2714.     GET_KEY();
  2715.     WindowWriteCharacters(w,buf,1,1,11);  /* Writes "Hello World"   */
  2716.     WindowWriteCharacters(w,buf,2,1,13);  /* Writes "Hello World!!" */
  2717.   }
  2718.  
  2719.   The return values for WindowWriteCharacters() are the same as
  2720.   WindowWriteString().
  2721.  
  2722.  
  2723.  
  2724.  
  2725.   WindowWriteAttributes()
  2726.   -----------------------
  2727.  
  2728.   This function writes attributes from a buffer to the window.  Here is the
  2729.   prototype:
  2730.  
  2731.   int WindowWriteAttributes(WPOINTER w, char *buffer, int row, int col,
  2732.                             int length)
  2733.  
  2734.   The first argument is the window.  The second argument is a pointer to the
  2735.   buffer where the attributes are stored.  The third and fourth arguments are
  2736.   the (row,col) position in the window to write the string, and the last
  2737.   argument is the number of attributes from buffer to write.
  2738.  
  2739.  
  2740.   Example:
  2741.  
  2742.  
  2743.   #include "window.h"
  2744.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2745.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2746.  
  2747.   WPOINTER w;
  2748.   char buf[13];
  2749.  
  2750.  
  2751.  
  2752.  Page 38                     The C Window Library                    Page 38
  2753.  
  2754.   main()
  2755.   {
  2756.     int i;
  2757.     WindowInitializeSystem();
  2758.     WindowSaveInitial(0);
  2759.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2760.     WindowOpen(w);
  2761.     WindowDisplay(w,1,NOEFFECT);
  2762.  
  2763.     for (i=0;i<13;i++)
  2764.       if (i % 2)
  2765.         buf[i] = NORM;
  2766.       else
  2767.         buf[i] = REVERSE;
  2768.  
  2769.     WindowWriteString(w,"Hello World!!",1,1);
  2770.     GET_KEY();
  2771.     WindowWriteAttributes(w,buf,1,1,13);  /* Writes alternating NORM and
  2772.                                              REVERSE attributes */
  2773.   }
  2774.  
  2775.  
  2776.   The return values for WindowWriteAttributes() are the same as
  2777.   WindowWriteString().
  2778.  
  2779.  
  2780.  
  2781.  
  2782.   WindowWriteCharAndAttr()
  2783.   ------------------------
  2784.  
  2785.   The WindowWriteCharAndAttr() function writes a string of character/attribute
  2786.   pairs to a window.  Use this function if you have created a string of
  2787.   character/attribute pairs, and want to output them easily.  The string
  2788.   consists of character and attributes in the following manner:
  2789.  
  2790.            char-attr-char-attr...
  2791.  
  2792.   Each character is followed by its corresponding video attribute.
  2793.  
  2794.  
  2795.   Here is the prototype:
  2796.  
  2797.   int WindowWriteCharAndAttr(WPOINTER w, char *buffer, int row, int col,
  2798.                              int length)
  2799.  
  2800.  
  2801.   The first argument is the window. The second is the buffer where the
  2802.   character and attributes are stored.  The third and fourth is the (row,col)
  2803.   position in the window to write, and the length argument is the number of
  2804.   character/attribute pairs from the buffer to write.  Please note the
  2805.   difference in the meaning of the length argument in this function as opposed
  2806.   to its use in the preceding functions.
  2807.  
  2808.  Page 39                     The C Window Library                    Page 39
  2809.  
  2810.   Example:
  2811.  
  2812.  
  2813.   #include "window.h"
  2814.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2815.  
  2816.   WPOINTER w;
  2817.   char buf[26];
  2818.   char *str = "Hello World!!";
  2819.   main()
  2820.   {
  2821.     int i;
  2822.     WindowInitializeSystem();
  2823.     WindowSaveInitial(0);
  2824.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2825.     WindowOpen(w);
  2826.     WindowDisplay(w,1,NOEFFECT);
  2827.  
  2828.     for (i=0;i<26;i+=2,str++)
  2829.     {
  2830.       buf[i] = *str;
  2831.       buf[i+1] = NORM;
  2832.     }
  2833.  
  2834.     WindowWriteCharAndAttr(w,buf,1,1,13);
  2835.   }
  2836.  
  2837.  
  2838.   The return values for WindowWriteCharAndAttr() are the same as
  2839.   WindowWriteString().
  2840.  
  2841.  
  2842.  
  2843.   WindowWriteCharactersAttr()
  2844.   ---------------------------
  2845.  
  2846.   The WindowWriteCharactersAttr() function writes characters from a buffer to a
  2847.   window.  The difference between this function and WindowWriteCharacters() is
  2848.   that a video attribute is specified.  Here is the prototype:
  2849.  
  2850.     int WindowWriteCharactersAttr(WPOINTER w, char *buffer, int row, int col,
  2851.                                   int attr, int length)
  2852.  
  2853.   The attr argument is the video attribute to use when writing the characters.
  2854.  
  2855.  
  2856.   Example:
  2857.  
  2858.   #include "window.h"
  2859.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2860.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2861.  
  2862.  
  2863.  
  2864.  Page 40                     The C Window Library                    Page 40
  2865.  
  2866.   WPOINTER w;
  2867.   char buf[] = "Hello World!!";
  2868.  
  2869.   main()
  2870.   {
  2871.     WindowInitializeSystem();
  2872.     WindowSaveInitial(0);
  2873.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2874.     WindowOpen(w);
  2875.     WindowDisplay(w,1,NOEFFECT);
  2876.     GET_KEY();
  2877.     WindowWriteCharactersAttr(w,buf,2,1,REVERSE,13);  /* Writes "Hello World!!"
  2878.                                                          using the REVERSE
  2879.                                                          attribute */
  2880.   }
  2881.  
  2882.  
  2883.   The return values for WindowWriteCharactersAttr() are the same as
  2884.   WindowWriteString().
  2885.  
  2886.  
  2887.  
  2888.   WindowWriteRepeatAttribute()
  2889.   ----------------------------
  2890.  
  2891.  
  2892.   The WindowWriteRepeatAttribute() function writes an attribute a specified
  2893.   number of times to a window.  Here is a prototype:
  2894.  
  2895.  
  2896.   int WindowWriteRepeatAttribute(WPOINTER w, int attr, int row, int col,
  2897.                                  int count)
  2898.  
  2899.  
  2900.   The attr argument is the attribute to use.  The count argument specifies the
  2901.   number of times to write the attribute attr to the window starting at
  2902.   (row,col).
  2903.  
  2904.   Example:
  2905.  
  2906.   #include "window.h"
  2907.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2908.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2909.  
  2910.   WPOINTER w;
  2911.  
  2912.   main()
  2913.   {
  2914.     WindowInitializeSystem();
  2915.     WindowSaveInitial(0);
  2916.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2917.     WindowOpen(w);
  2918.     WindowDisplay(w,1,NOEFFECT);
  2919.  
  2920.  Page 41                     The C Window Library                    Page 41
  2921.  
  2922.     WindowWriteString(w,"Hello World!!",1,1);
  2923.     GET_KEY();
  2924.     WindowWriteRepeatAttribute(w,REVERSE,1,1,13);
  2925.   }
  2926.  
  2927.   The example above illustrates that the WindowWriteRepeatAttribute() writes
  2928.   the REVERSE attribute 13 times starting at row 1, column 1 of the window w.
  2929.  
  2930.   The return values for WindowWriteRepeatAttribute() are the same as
  2931.   WindowWriteString().
  2932.  
  2933.  
  2934.  
  2935.  
  2936.   WindowWriteRepeatCharacter()
  2937.   ----------------------------
  2938.  
  2939.   The WindowWriteRepeatCharacter() function writes a character a specified
  2940.   number of times to a window.  Here is a prototype:
  2941.  
  2942.  
  2943.   int WindowWriteRepeatCharacter(WPOINTER w, int ch, int row, int col,
  2944.                                  int count)
  2945.  
  2946.  
  2947.   The count argument is the character to use.  The count argument specifies the
  2948.   number of times to write the character ch to the window starting at (row,col).
  2949.  
  2950.   #include "window.h"
  2951.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  2952.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  2953.  
  2954.   WPOINTER w;
  2955.  
  2956.   main()
  2957.   {
  2958.     WindowInitializeSystem();
  2959.     WindowSaveInitial(0);
  2960.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  2961.     WindowOpen(w);
  2962.     WindowDisplay(w,1,NOEFFECT);
  2963.     WindowWriteRepeatCharacter(w,'a',1,1,5);
  2964.     WindowWriteRepeatCharacter(w,'b',2,1,5);
  2965.     WindowWriteRepeatCharacter(w,'c',3,1,5);
  2966.   }
  2967.  
  2968.   The example above illustrates that the WindowWriteRepeatCharacter() writes
  2969.   the letter 'a', 'b', and 'c' 5 times on rows 1, 2, and 3 respectively.
  2970.  
  2971.   The return values for WindowWriteRepeatCharacter() are the same as
  2972.   WindowWriteString().
  2973.  
  2974.  
  2975.  
  2976.  Page 42                     The C Window Library                    Page 42
  2977.  
  2978.   Formatted Write Functions
  2979.   -------------------------
  2980.  
  2981.   These functions write formatted output to windows just like the printf()
  2982.   function.  There are two functions that do this, namely WindowPrintf()
  2983.   and WindowPrintfAttr().  These functions use a format string that is similar
  2984.   to the format string found in printf().  For example, %d, %s, %lf, etc. and
  2985.   most of the escape sequences are supported.  The list of escape sequences
  2986.   supported are as follows:
  2987.  
  2988.                         \n - newline
  2989.                         \b - backspace
  2990.                         \t - tab
  2991.                         \a - bell
  2992.                         \r - carriage return
  2993.                         \x - hexadecimal
  2994.  
  2995.  
  2996.   Where output is placed in the window
  2997.   ------------------------------------
  2998.  
  2999.   The row and column of where the string will be written is determined by the
  3000.   window's logical cursor.  The logical cursor is advanced by both of these
  3001.   functions to one column position after the last character is printed.  If you
  3002.   want to start at a particular row and column of the window, you must move the
  3003.   cursor yourself by calling the WindowMoveCursor() function.  This function is
  3004.   explained on page 72.  If the window is displayed, the logical cursor of
  3005.   the window is equivalent to the screen cursor.  If the output to the window
  3006.   will be obscured by other windows, the screen cursor will also be hidden.
  3007.  
  3008.   When the window is first opened using WindowOpen(), the logical cursor is
  3009.   automatically moved to (1,1) of the window.
  3010.  
  3011.  
  3012.  
  3013.   WindowSetWrap()
  3014.   ---------------
  3015.  
  3016.   With these functions, any text that will exceed the boundaries of the window
  3017.   will be wrapped to the next line.  If the output will exceed the last row of
  3018.   the window, the window is automatically scrolled up by one line.  This is the
  3019.   default action that is taken when characters exceed the right edge of the
  3020.   window.  If you want the output clipped instead of wrapped, you must set the
  3021.   window's wrap flag using the WindowSetWrap() function.
  3022.  
  3023.   The WindowSetWrap() function sets the window's wrap flag to either on or off.
  3024.   Here is the prototype:
  3025.  
  3026.               int WindowSetWrap(WPOINTER w, int option)
  3027.  
  3028.   The second argument will be 0 if you want to turn the wrap flag off, or 1 if
  3029.   you want to turn it on.  If the wrap flag is off, the output generated by
  3030.   WindowPrintf() and WindowPrintfAttr() will be terminated when the right edge
  3031.  
  3032.  Page 43                     The C Window Library                    Page 43
  3033.  
  3034.   of the window is reached.  If the wrap flag is on, the output is wrapped to
  3035.   the next line when the right edge is reached, and the window will be scrolled
  3036.   up by one line if the output will exceed the last row.
  3037.  
  3038.   You can set the wrap flag to a window at any time.
  3039.  
  3040.  
  3041.  
  3042.   WindowPrintf()
  3043.   --------------
  3044.  
  3045.   The WindowPrintf() function writes formatted output to the window.  Here is
  3046.   the prototype:
  3047.  
  3048.             int WindowPrintf(WPOINTER w, char *format [,arg1,...])
  3049.  
  3050.   The first argument is the window.  The second argument is a format string.
  3051.   The rest of the arguments are optional arguments that are written to the
  3052.   window.
  3053.  
  3054.   Example:
  3055.  
  3056.   #include "window.h"
  3057.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3058.   WPOINTER w;
  3059.   char *s1 = "This string will wrap around to the next line\n";
  3060.   char *s2 = "This escape code will ring the bell \a";
  3061.   int i = 3;
  3062.   double j = 5.6;
  3063.  
  3064.   main()
  3065.   {
  3066.     WindowInitializeSystem();
  3067.     WindowSaveInitial(0);
  3068.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  3069.     WindowOpen(w);
  3070.     WindowDisplay(w,1,NOEFFECT);
  3071.     WindowPrintf(w,"3+2 is equal to %d\n",3+2);
  3072.     GET_KEY();
  3073.     WindowPrintf(w,"i is equal to %d\nj is equal to %lf\n",i,j);
  3074.     GET_KEY();
  3075.     WindowPrintf(w,s1);
  3076.     GET_KEY();
  3077.     WindowPrintf(w,s2);
  3078.   }
  3079.  
  3080.   The above example illustrates how WindowPrintf() is used to print formatted
  3081.   strings.
  3082.  
  3083.   The return values for WindowPrintf() are the same as WindowWriteString().
  3084.  
  3085.  
  3086.  
  3087.  
  3088.  Page 44                     The C Window Library                    Page 44
  3089.  
  3090.   WindowPrintfAttr()
  3091.   ------------------
  3092.  
  3093.   The WindowPrintfAttr() function writes formatted output to the window.
  3094.   The difference between WindowPrintf() and WindowPrintfAttr() is that
  3095.   WindowPrintfAttr() uses a video attribute specified as an argument.  Here is
  3096.   the prototype:
  3097.  
  3098.       int WindowPrintfAttr(WPOINTER w, int attr, char *format [,arg1,...])
  3099.  
  3100.   The first argument is the window.  The second argument is the video
  3101.   attribute to use.  The third argument is the format string.  The rest of the
  3102.   arguments are optional arguments that are written to the window.
  3103.  
  3104.  
  3105.   Example:
  3106.  
  3107.   #include "window.h"
  3108.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3109.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  3110.  
  3111.   WPOINTER w;
  3112.   char *s1 = "This string will wrap around to the next line\n";
  3113.   char *s2 = "This escape code will ring the bell \a";
  3114.   int i = 3;
  3115.   double j = 5.6;
  3116.  
  3117.   main()
  3118.   {
  3119.     WindowInitializeSystem();
  3120.     WindowSaveInitial(0);
  3121.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  3122.     WindowOpen(w);
  3123.     WindowDisplay(w,1,NOEFFECT);
  3124.     WindowPrintfAttr(w,REVERSE,"3+2 is equal to %d\n",3+2);
  3125.     GET_KEY();
  3126.     WindowPrintfAttr(w,REVERSE,"i is equal to %d\nj is equal to %lf\n",i,j);
  3127.     GET_KEY();
  3128.     WindowPrintfAttr(w,REVERSE,s1);
  3129.     GET_KEY();
  3130.     WindowPrintfAttr(w,REVERSE,s2);
  3131.   }
  3132.  
  3133.   The above example illustrates how WindowPrintfAttr() is used to print
  3134.   formatted strings.
  3135.  
  3136.   The return values for WindowPrintfAttr() are the same as WindowWriteString().
  3137.  
  3138.  
  3139.  
  3140.  
  3141.  
  3142.  
  3143.  
  3144.  Page 45                     The C Window Library                    Page 45
  3145.  
  3146.   Writing Titles
  3147.   --------------
  3148.  
  3149.   This section only applies to bordered windows.  Except for the
  3150.   WindowPrintf...() functions, if you specify the row number to be 0, the text
  3151.   is written on the upper border of the window. If the row number is equal to
  3152.   the window height + 1, the text is written on the lower border of the window.
  3153.   This is good if you want titles on a window with borders.  To access the
  3154.   window's height use the WPOINTER structure member called height.
  3155.  
  3156.   If you want to write a formatted string on the border of the window, use the
  3157.   standard library function sprintf() to create a string of formatted output,
  3158.   and then write this string with one of the WindowWrite...() functions.
  3159.  
  3160.   Any text that is written on the borders of a window are not retained if the
  3161.   window is resized using one of the WindowResize...() functions, or if the
  3162.   border is changed using WindowDrawBorder().  Therefore it is a good idea to
  3163.   maintain what is on the borders of the window in your own string variables.
  3164.  
  3165.  
  3166.   Example:
  3167.  
  3168.  
  3169.   #include "window.h"
  3170.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3171.  
  3172.   WPOINTER w;
  3173.   int i;
  3174.  
  3175.   main()
  3176.   {
  3177.     WindowInitializeSystem();
  3178.     WindowSaveInitial(0);
  3179.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3180.     WindowOpen(w);
  3181.     WindowDisplay(w,1,NOEFFECT);
  3182.     GET_KEY();
  3183.  
  3184.     /* Specify row 0 to write on */
  3185.     WindowWriteCenterString(w,"This is a title",0);
  3186.  
  3187.     /* Now write title on bottom by using the height structure member */
  3188.  
  3189.     WindowWriteCenterString(w,"This is a title",w->height + 1);
  3190.   }
  3191.  
  3192.  
  3193.  
  3194.  
  3195.  
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  Page 46                     The C Window Library                    Page 46
  3201.  
  3202.                 READING CHARACTERS AND ATTRIBUTES FROM WINDOWS
  3203.                 ----------------------------------------------
  3204.  
  3205.   With The C Window Library, you can read the contents of a window into a
  3206.   character buffer.  These functions provide the programmer with the contents of
  3207.   the window at any time.  The functions to perform this are
  3208.   WindowReadAttributes(), WindowReadCharacters(), and WindowReadCharAndAttr().
  3209.  
  3210.  
  3211.  
  3212.   WindowReadCharacters()
  3213.   ----------------------
  3214.  
  3215.   The WindowReadCharacters() function reads the characters from a window into a
  3216.   buffer.  Here is the prototype.
  3217.  
  3218.   int WindowReadCharacters(WPOINTER w, char *buffer, int row, int col,
  3219.                            int length)
  3220.  
  3221.   The first argument is the window.  The second argument is the buffer to store
  3222.   the characters in.  The third and fourth arguments are the (row,col) position
  3223.   in the window to start reading from.  The last argument is the number of
  3224.   characters to read.
  3225.  
  3226.   You must make sure that buffer has enough room to hold all of the characters
  3227.   read in.
  3228.  
  3229.  
  3230.   Example:
  3231.  
  3232.   #include "window.h"
  3233.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3234.  
  3235.   WPOINTER w;
  3236.   char buf[14] = {0};      /* Null all elements of buf */
  3237.  
  3238.   main()
  3239.   {
  3240.     int i;
  3241.     WindowInitializeSystem();
  3242.     WindowSaveInitial(0);
  3243.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3244.     WindowOpen(w);
  3245.     WindowDisplay(w,1,NOEFFECT);
  3246.     WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  3247.     WindowReadCharacters(w,buf,1,1,13);      /* Read characters */
  3248.     GET_KEY();
  3249.     WindowWriteString(w,buf,2,1);            /* Write what we have read */
  3250.   }
  3251.  
  3252.  
  3253.  
  3254.  
  3255.  
  3256.  Page 47                     The C Window Library                    Page 47
  3257.  
  3258.   The example above illustrates the use of WindowReadCharacters(), which reads
  3259.   the window's contents starting at (1,1) of the window.  This happens to be
  3260.   the string "Hello World!!".  After GET_KEY() is called, the results of the
  3261.   buffer are written on line 2 of the window.
  3262.  
  3263.   If the length exceeds the right edge of the window, WindowReadCharacters()
  3264.   will read up to the right edge of the window.
  3265.  
  3266.  
  3267.   If there are no errors, WindowReadCharacters() returns NO_ERROR.
  3268.   If there are errors, WindowReadCharacters() returns one of the following:
  3269.  
  3270.   BAD_WINDOW if the window does not exist.
  3271.  
  3272.   WINDOW_NOT_OPEN if the window was not open for reading (use WindowOpen())
  3273.  
  3274.   WINDOW_BOUND if the row or column specified in the window is out of bounds.
  3275.  
  3276.  
  3277.  
  3278.  
  3279.   WindowReadAttributes()
  3280.   ----------------------
  3281.  
  3282.   The WindowReadAttributes() function reads the attributes from a window into a
  3283.   buffer.  Here is the prototype.
  3284.  
  3285.   int WindowReadAttributes(WPOINTER w, char *buffer, int row, int col,
  3286.                            int length)
  3287.  
  3288.   The first argument is the window.  The second argument is the buffer to store
  3289.   the attributes in.  The third and fourth arguments are the (row,col) position
  3290.   in the window to start reading from.  The last argument is the number of
  3291.   attributes to read.
  3292.  
  3293.   You must make sure that buffer has enough room to hold all of the attributes
  3294.   read in.
  3295.  
  3296.  
  3297.   Example:
  3298.  
  3299.   #include "window.h"
  3300.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3301.  
  3302.   WPOINTER w;
  3303.   char buf[14] = {0};      /* Null all elements of buf */
  3304.  
  3305.   main()
  3306.   {
  3307.     int i;
  3308.     WindowInitializeSystem();
  3309.     WindowSaveInitial(0);
  3310.  
  3311.  
  3312.  Page 48                     The C Window Library                    Page 48
  3313.  
  3314.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3315.     WindowOpen(w);
  3316.     WindowDisplay(w,1,NOEFFECT);
  3317.     WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  3318.     WindowReadAttributes(w,buf,1,1,13);      /* Read attributes */
  3319.     GET_KEY();
  3320.     WindowWriteString(w,buf,2,1);            /* Write what we have read */
  3321.   }
  3322.  
  3323.   The example above illustrates the use of WindowReadAttributes(), which reads
  3324.   the window's attribute contents starting at (1,1) of the window.  This
  3325.   happens to be the attributes of the string "Hello World!!", which is the
  3326.   NORM attribute.  After GET_KEY() is called, the results of the buffer are
  3327.   written on line 2 of the window.
  3328.  
  3329.   If the length exceeds the right edge of the window, WindowReadAttributes()
  3330.   will read up to the right edge of the window.
  3331.  
  3332.  
  3333.   If there are no errors, WindowReadAttributes() returns NO_ERROR.
  3334.   If there are errors, WindowReadAttributes() returns one of the following:
  3335.  
  3336.   BAD_WINDOW if the window does not exist.
  3337.  
  3338.   WINDOW_NOT_OPEN if the window was not open for reading (use WindowOpen())
  3339.  
  3340.   WINDOW_BOUND if the row or column specified in the window is out of bounds.
  3341.  
  3342.  
  3343.  
  3344.  
  3345.   WindowReadCharAndAttr()
  3346.   ----------------------
  3347.  
  3348.   The WindowReadCharAndAttr() function reads character/attribute pairs from a
  3349.   window into a buffer.  Here is the prototype.
  3350.  
  3351.   int WindowReadCharAndAttr(WPOINTER w, char *buffer, int row, int col,
  3352.                             int length)
  3353.  
  3354.   The first argument is the window.  The second argument is the buffer to store
  3355.   the character/attribute pairs in.  The third and fourth arguments are the
  3356.   (row,col) position in the window to start reading from.  The last argument is
  3357.   the number of character/attribute pairs to read.
  3358.  
  3359.   You must make sure that buffer has enough room to hold all of the
  3360.   character/attribute pairs read in.
  3361.  
  3362.  
  3363.  
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  Page 49                     The C Window Library                    Page 49
  3369.  
  3370.   Example:
  3371.  
  3372.   #include "window.h"
  3373.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3374.  
  3375.   WPOINTER w;
  3376.   char buf[27] = {0};      /* Null all elements of buf */
  3377.  
  3378.   main()
  3379.   {
  3380.     int i;
  3381.     WindowInitializeSystem();
  3382.     WindowSaveInitial(0);
  3383.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3384.     WindowOpen(w);
  3385.     WindowDisplay(w,1,NOEFFECT);
  3386.     WindowWriteString(w,"Hello World!!",1,1);/* Write String */
  3387.     WindowReadCharAndAttr(w,buf,1,1,13);      /* Read character/attributes */
  3388.     GET_KEY();
  3389.     WindowWriteCharAndAttr(w,buf,2,1,13);     /* Write what we have read */
  3390.   }
  3391.  
  3392.   The example above illustrates the use of WindowReadCharAndAttr(), which reads
  3393.   the window's character/attribute contents starting at (1,1) of the window.
  3394.   This happens to be the characters/attributes of the string "Hello World!!".
  3395.   After GET_KEY() is called, the results of the buffer are written on line 2 of
  3396.   the window.
  3397.  
  3398.   If the length exceeds the right edge of the window,
  3399.   WindowReadCharAndAttr() will read up to the right edge of the window.
  3400.  
  3401.  
  3402.   If there are no errors, WindowReadCharAndAttr() returns NO_ERROR.
  3403.   If there are errors, WindowReadCharAndAttr() returns one of the following:
  3404.  
  3405.   BAD_WINDOW if the window does not exist.
  3406.  
  3407.   WINDOW_NOT_OPEN if the window was not open for reading (use WindowOpen())
  3408.  
  3409.   WINDOW_BOUND if the row or column specified in the window is out of bounds.
  3410.  
  3411.  
  3412.  
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  Page 50                     The C Window Library                    Page 50
  3425.  
  3426.                                 HIDING WINDOWS
  3427.                                 --------------
  3428.  
  3429.   With The C Window Library, you can hide windows at any time without
  3430.   disturbing the contents of other windows.
  3431.  
  3432.  
  3433.  
  3434.   WindowHide()
  3435.   ------------
  3436.  
  3437.   The WindowHide() function hides a window on the screen from view.  The window
  3438.   retains all text and shadows that may be present.  Here is a prototype:
  3439.  
  3440.                   int WindowHide(WPOINTER w, int effect)
  3441.  
  3442.   The first argument is the window, and the last argument is the special effect
  3443.   to use when hiding the window.  For a list of special effects, refer to page
  3444.   14.
  3445.  
  3446.   Example :
  3447.  
  3448.  
  3449.   #include "window.h"
  3450.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3451.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  3452.   #define BLACKONWHITE  CREATE_VIDEO_ATTRIBUTE(white,black)
  3453.  
  3454.  
  3455.   WPOINTER w1,w2,w3;
  3456.  
  3457.   main()
  3458.   {
  3459.     WindowInitializeSystem();
  3460.     WindowSaveInitial(0);
  3461.  
  3462.     /* Initialize all windows */
  3463.     w1 = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3464.     w2 = WindowInitialize(BORDER,2,2,20,10,REDONWHITE,NORM,DOUBLEBOX);
  3465.     w3 = WindowInitialize(BORDER,3,3,20,10,BLACKONWHITE,NORM,SINGLEBOX);
  3466.  
  3467.     /* Open all windows */
  3468.     WindowOpen(w1);
  3469.     WindowOpen(w2);
  3470.     WindowOpen(w3);
  3471.  
  3472.     /* Display All windows */
  3473.     WindowDisplay(w1,1,NOEFFECT);
  3474.     WindowDisplay(w2,2,NOEFFECT);
  3475.     WindowDisplay(w3,3,NOEFFECT);
  3476.  
  3477.  
  3478.  
  3479.  
  3480.  Page 51                     The C Window Library                    Page 51
  3481.  
  3482.     WindowWriteString(w1,"This is window 1",1,1);
  3483.     WindowWriteString(w2,"This is window 2",2,1);
  3484.     WindowWriteString(w3,"This is window 3",3,1);
  3485.  
  3486.     GET_KEY();
  3487.     WindowHide(w3,NOEFFECT);
  3488.     GET_KEY();
  3489.     WindowHide(w2,BRICKS);
  3490.     GET_KEY();
  3491.     WindowHide(w1,CONTRACT);
  3492.   }
  3493.  
  3494.  
  3495.   The example initializes, opens, and displays three windows.  Note that you
  3496.   can hide windows regardless of the order in which they were displayed.  This
  3497.   makes for very flexible window management.
  3498.  
  3499.   If there is no error, WindowHide() returns NO_ERROR.
  3500.  
  3501.   The only error that can occur is if the WPOINTER w does not exist.
  3502.   WindowHide() returns BAD_WINDOW if this is the case.
  3503.  
  3504.  
  3505.  
  3506.  
  3507.  
  3508.  
  3509.  
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.  
  3521.  
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  Page 52                     The C Window Library                    Page 52
  3537.  
  3538.                            SCROLLING TEXT IN WINDOWS
  3539.                            -------------------------
  3540.  
  3541.   With The C Window Library, you can scroll text in a window up, or down, or
  3542.   scroll just particular regions of a window.  The functions used to scroll
  3543.   windows are WindowScroll(), WindowScrollAttr(), WindowScrollRegion(), and
  3544.   WindowScrollRegionAttr().
  3545.  
  3546.   When specifying a direction, use the constant UP to scroll up or DOWN to
  3547.   scroll down.  These constants are defined in window.h.
  3548.  
  3549.  
  3550.  
  3551.   WindowScroll()
  3552.   --------------
  3553.  
  3554.   If you want to scroll the entire window either up or down, you can use the
  3555.   WindowScroll() function.  Here is a prototype:
  3556.  
  3557.     int WindowScroll(WPOINTER w, int numlines, int direction)
  3558.  
  3559.  
  3560.   The first argument is the window to scroll.   The second argument is the
  3561.   number of lines to scroll. The last argument is the direction to scroll the
  3562.   window (either UP or DOWN).
  3563.  
  3564.  
  3565.   Example:
  3566.  
  3567.   #include "window.h"
  3568.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3569.  
  3570.   WPOINTER w;
  3571.  
  3572.   main()
  3573.   {
  3574.     int i;
  3575.     WindowInitializeSystem();
  3576.     WindowSaveInitial(0);
  3577.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3578.     WindowOpen(w);
  3579.     WindowDisplay(w,1,NOEFFECT);
  3580.     for (i=0;i<10;i++)
  3581.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  3582.     GET_KEY();
  3583.     WindowScroll(w,1,UP);
  3584.     GET_KEY();
  3585.     WindowScroll(w,3,DOWN);
  3586.   }
  3587.  
  3588.   The above example creates text using WindowWriteRepeatCharacter() function.
  3589.   The WindowScroll() calls will scroll the window up by one line, and then
  3590.   scroll the window down by 3 lines.
  3591.  
  3592.  Page 53                     The C Window Library                    Page 53
  3593.  
  3594.   If there is no error, WindowScroll() returns NO_ERROR.
  3595.   If there is an error, WindowScroll() will return the following values:
  3596.  
  3597.   BAD_WINDOW if the WPOINTER w does not exist.
  3598.  
  3599.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen() to
  3600.   open the window for writing).
  3601.  
  3602.  
  3603.  
  3604.  
  3605.   WindowScrollRegion()
  3606.   --------------------
  3607.  
  3608.   The WindowScrollRegion() functions scrolls a specified region of a window.
  3609.   To use the WindowScrollRegion() function, you must describe the rectangular
  3610.   region to scroll.  Here is the prototype:
  3611.  
  3612.   int WindowScrollRegion(WPOINTER w, int numlines, int urow, int ucol, int lrow,
  3613.                          int lcol, int direction)
  3614.  
  3615.   Arguments 3 thru 6 describe the rectangular region.  They are in the order of
  3616.   upper left row, upper left column, lower right row, lower right column.  All
  3617.   of these coordinates are window relative.  The second argument is the number
  3618.   of lines to scroll.  The last argument is the direction.
  3619.  
  3620.  
  3621.   Example:
  3622.  
  3623.   #include "window.h"
  3624.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3625.  
  3626.   WPOINTER w;
  3627.  
  3628.   main()
  3629.   {
  3630.     int i;
  3631.     WindowInitializeSystem();
  3632.     WindowSaveInitial(0);
  3633.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3634.     WindowOpen(w);
  3635.     WindowDisplay(w,1,NOEFFECT);
  3636.     for (i=0;i<10;i++)
  3637.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  3638.     GET_KEY();
  3639.     WindowScrollRegion(w,1,2,2,4,10,UP);
  3640.     GET_KEY();
  3641.     WindowScrollRegion(w,3,7,2,9,8,DOWN);
  3642.   }
  3643.  
  3644.  
  3645.  
  3646.  
  3647.  
  3648.  Page 54                     The C Window Library                    Page 54
  3649.  
  3650.   The above example creates text using WindowWriteRepeatCharacter() function.
  3651.   The first WindowScrollRegion() call will scroll the region described by
  3652.   the rectangular coordinates (2,2) and (4,10).  This region is scrolled up one
  3653.   line.  The second call to WindowScrollRegion() scrolls the region defined by
  3654.   the rectangular region (7,2) and (9,8).  This region is scrolled down by
  3655.   three lines.
  3656.  
  3657.   If there is no error, WindowScrollRegion() returns NO_ERROR.
  3658.  
  3659.   If there is an error, the WindowScrollRegion() function will return of the
  3660.   following values:
  3661.  
  3662.   BAD_WINDOW if the WPOINTER w does not exist.
  3663.  
  3664.   WINDOW_BOUND if the rectangular region defined is out of bounds of the
  3665.   window.
  3666.  
  3667.   WINDOW_NOT_OPEN if the window was not open for writing (use WindowOpen() to
  3668.   open the window for writing).
  3669.  
  3670.  
  3671.  
  3672.  
  3673.   WindowScrollAttr()
  3674.   ------------------
  3675.   This function works the same way as the WindowScroll() function except that
  3676.   an attribute is defined for the blank lines that are created when the window
  3677.   is scrolled.  Here is a prototype:
  3678.  
  3679.   int WindowScrollAttr(WPOINTER w, int numlines, int direction, int attr)
  3680.  
  3681.   The last argument is the attribute to use for the blank lines created.
  3682.  
  3683.   Example:
  3684.  
  3685.   #include "window.h"
  3686.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3687.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  3688.  
  3689.   WPOINTER w;
  3690.  
  3691.   main()
  3692.   {
  3693.     int i;
  3694.     WindowInitializeSystem();
  3695.     WindowSaveInitial(0);
  3696.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3697.     WindowOpen(w);
  3698.     WindowDisplay(w,1,NOEFFECT);
  3699.     for (i=0;i<10;i++)
  3700.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  3701.     GET_KEY();
  3702.  
  3703.  
  3704.  Page 55                     The C Window Library                    Page 55
  3705.  
  3706.     WindowScrollAttr(w,1,UP,REDONWHITE);
  3707.     GET_KEY();
  3708.     WindowScrollAttr(w,3,DOWN,REDONWHITE);
  3709.   }
  3710.  
  3711.   The above example creates text using WindowWriteRepeatCharacter() function.
  3712.   The WindowScrollAttr() calls will scroll the window up by one line, and then
  3713.   scroll the window down by 3 lines with both scrolls using REDONWHITE as the
  3714.   video attribute.
  3715.  
  3716.   WindowScrollAttr() returns the same values as WindowScroll().
  3717.  
  3718.  
  3719.  
  3720.  
  3721.   WindowScrollRegionAttr()
  3722.   ------------------------
  3723.  
  3724.   This function works the same way as the WindowScrollRegion() function
  3725.   except that an attribute is defined for the blank lines that are created when
  3726.   the window is scrolled.  Here is a prototype:
  3727.  
  3728.   int WindowScrollRegionAttr(WPOINTER w, int numlines, int urow, int ucol,
  3729.                             int lrow, int lcol,int direction, int attr)
  3730.  
  3731.   The last argument is the attribute to use for the blank lines created.
  3732.  
  3733.  
  3734.   Example:
  3735.  
  3736.   #include "window.h"
  3737.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3738.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  3739.  
  3740.   WPOINTER w;
  3741.  
  3742.   main()
  3743.   {
  3744.     int i;
  3745.     WindowInitializeSystem();
  3746.     WindowSaveInitial(0);
  3747.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3748.     WindowOpen(w);
  3749.     WindowDisplay(w,1,NOEFFECT);
  3750.     for (i=0;i<10;i++)
  3751.       WindowWriteRepeatCharacter(w,'A'+i,i+1,1,20);
  3752.     GET_KEY();
  3753.     WindowScrollRegionAttr(w,1,3,5,6,15,UP,REDONWHITE);
  3754.     GET_KEY();
  3755.     WindowScrollRegionAttr(w,3,8,4,10,12,DOWN,REDONWHITE);
  3756.   }
  3757.  
  3758.  
  3759.  
  3760.  Page 56                     The C Window Library                    Page 56
  3761.  
  3762.   The above example creates text using WindowWriteRepeatCharacter() function.
  3763.   The first WindowScrollRegionAttr() call will scroll the region described by
  3764.   the rectangular coordinates (2,2) and (4,10).  This region is scrolled one
  3765.   line.  The second call to WindowScrollRegionAttr() scrolls the region defined
  3766.   by the rectangular region (7,2) and (9,8).  This region is scrolled down by
  3767.   three lines.  All blank lines use the video attribute REDONWHITE.
  3768.  
  3769.   WindowScrollRegionAttr() returns the same values as WindowScrollRegion().
  3770.  
  3771.  
  3772.  
  3773.  
  3774.  
  3775.  
  3776.  
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  Page 57                     The C Window Library                    Page 57
  3817.  
  3818.                                CLEARING WINDOWS
  3819.                                ----------------
  3820.  
  3821.   The C Window Library contains functions that clears the entire window, or
  3822.   clears defined rectangular regions of the window.
  3823.  
  3824.  
  3825.   WindowClear()
  3826.   -------------
  3827.  
  3828.   The WindowClear() function clears an entire window to spaces.  The attribute
  3829.   used is the current attribute of the text area of the window.  Here is the
  3830.   prototype:
  3831.  
  3832.                  int WindowClear(WPOINTER w)
  3833.  
  3834.   The only argument is the window to clear.
  3835.  
  3836.   Example:
  3837.  
  3838.   #include "window.h"
  3839.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3840.  
  3841.   WPOINTER w;
  3842.  
  3843.   main()
  3844.   {
  3845.     int i;
  3846.     WindowInitializeSystem();
  3847.     WindowSaveInitial(0);
  3848.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3849.     WindowOpen(w);
  3850.     WindowDisplay(w,1,NOEFFECT);
  3851.     for (i=1;i<=10;i++)
  3852.       WindowWriteString(w,"Hello World!!",i,1);
  3853.     GET_KEY();
  3854.     WindowClear(w);
  3855.   }
  3856.  
  3857.   If there is no error, WindowClear() returns NO_ERROR.
  3858.  
  3859.   If there is an error, WindowClear() returns the following values:
  3860.  
  3861.   BAD_WINDOW if the WPOINTER w does not exist.
  3862.  
  3863.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen() to
  3864.   open the window for writing).
  3865.  
  3866.  
  3867.  
  3868.  
  3869.  
  3870.  
  3871.  
  3872.  Page 58                     The C Window Library                    Page 58
  3873.  
  3874.   WindowClearAttr()
  3875.   -----------------
  3876.  
  3877.   The WindowClearAttr() function works the same way as the WindowClear()
  3878.   function except that an attribute is specified.  Here is the prototype:
  3879.  
  3880.      int WindowClearAttr(WPOINTER w, int attr)
  3881.  
  3882.   The second argument is the video attribute to use.
  3883.  
  3884.  
  3885.   Example:
  3886.  
  3887.   #include "window.h"
  3888.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3889.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  3890.  
  3891.   WPOINTER w;
  3892.  
  3893.   main()
  3894.   {
  3895.     int i;
  3896.     WindowInitializeSystem();
  3897.     WindowSaveInitial(0);
  3898.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3899.     WindowOpen(w);
  3900.     WindowDisplay(w,1,NOEFFECT);
  3901.     for (i=1;i<=10;i++)
  3902.       WindowWriteString(w,"Hello World!!",i,1);
  3903.     GET_KEY();
  3904.     WindowClearAttr(w,REDONWHITE);
  3905.   }
  3906.  
  3907.   The return values for WindowClearAttr() are the same as WindowClear().
  3908.  
  3909.  
  3910.  
  3911.  
  3912.  
  3913.   WindowClearRegion()
  3914.   -------------------
  3915.  
  3916.   The WindowClearRegion() function clears a region of a window.  To use the
  3917.   WindowClearRegion() function, you must describe the rectangular region to
  3918.   clear.  Here is the prototype:
  3919.  
  3920.   int WindowClearRegion(WPOINTER w, int urow, int ucol, int lrow, int lcol)
  3921.  
  3922.   where (urow,ucol) describes the upper left of the rectangle and (lrow,lcol)
  3923.   is the lower right of the window.  These coordinates are window relative.
  3924.  
  3925.  
  3926.  
  3927.  
  3928.  Page 59                     The C Window Library                    Page 59
  3929.  
  3930.   Example:
  3931.  
  3932.   #include "window.h"
  3933.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3934.  
  3935.   WPOINTER w;
  3936.  
  3937.   main()
  3938.   {
  3939.     int i;
  3940.     WindowInitializeSystem();
  3941.     WindowSaveInitial(0);
  3942.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  3943.     WindowOpen(w);
  3944.     WindowDisplay(w,1,NOEFFECT);
  3945.     for (i=1;i<=10;i++)
  3946.       WindowWriteString(w,"Hello World!!",i,1);
  3947.     GET_KEY();
  3948.     WindowClearRegion(w,4,4,8,15);
  3949.   }
  3950.  
  3951.  
  3952.   The WindowClearRegion() call will clear the region described by the
  3953.   rectangular coordinates (4,4) and (8,15).
  3954.  
  3955.   If there is no error, WindowClearRegion() returns NO_ERROR.
  3956.  
  3957.   If there is an error, the WindowClearRegion() function will return the
  3958.   following values:
  3959.  
  3960.   BAD_WINDOW if the WPOINTER w does not exist.
  3961.  
  3962.   WINDOW_BOUND if the rectangular region defined is out of bounds of the
  3963.   window.
  3964.  
  3965.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen() to
  3966.   open the window for writing).
  3967.  
  3968.  
  3969.  
  3970.  
  3971.  
  3972.   WindowClearRegionAttr()
  3973.   -----------------------
  3974.  
  3975.   The WindowClearRegionAttr() function works the same as the
  3976.   WindowClearRegion() function, except that a video attribute is specified.
  3977.   Here is the prototype:
  3978.  
  3979.   int WindowClearRegionAttr(WPOINTER w, int urow, int ucol, int lrow, int lcol,
  3980.                             int attr)
  3981.  
  3982.   The attr argument is a video attribute to use to clear the region.
  3983.  
  3984.  Page 60                     The C Window Library                    Page 60
  3985.  
  3986.   Example:
  3987.  
  3988.   #include "window.h"
  3989.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  3990.   #define REDONWHITE  CREATE_VIDEO_ATTRIBUTE(red,white)
  3991.  
  3992.   WPOINTER w;
  3993.  
  3994.   main()
  3995.   {
  3996.     int i;
  3997.     WindowInitializeSystem();
  3998.     WindowSaveInitial(0);
  3999.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4000.     WindowOpen(w);
  4001.     WindowDisplay(w,1,NOEFFECT);
  4002.     for (i=1;i<=10;i++)
  4003.       WindowWriteString(w,"Hello World!!",i,1);
  4004.     GET_KEY();
  4005.     WindowClearRegionAttr(w,4,4,8,15,REDONWHITE);
  4006.   }
  4007.  
  4008.  
  4009.   The WindowClearRegionAttr() call will clear the region described by the
  4010.   rectangular coordinates (4,4) and (8,15) using the video attribute defined
  4011.   by the constant REDONWHITE.
  4012.  
  4013.   The WindowClearRegionAttr() returns the same values as WindowClearRegion().
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.  
  4032.  
  4033.  
  4034.  
  4035.  
  4036.  
  4037.  
  4038.  
  4039.  
  4040.  Page 61                     The C Window Library                    Page 61
  4041.  
  4042.                        WRITING WINDOW CONTENTS TO A FILE
  4043.                        ---------------------------------
  4044.  
  4045.   The C Window Library allows you to print the contents of a window using the
  4046.   WindowWriteTextToFile() function.
  4047.  
  4048.  
  4049.   WindowWriteTextToFile()
  4050.   -----------------------
  4051.  
  4052.   The WindowWriteTextToFile() function allows you to print the contents of a
  4053.   window to a file.  Here is the prototype:
  4054.  
  4055.   int WindowWriteTextToFile(WPOINTER w, char *filename, int mode)
  4056.  
  4057.  
  4058.   The first argument is the window.  The second argument is the file name.
  4059.   This file can be any of the DOS filenames ("con", "prn", "aux", etc.).
  4060.   The file specified by filename must be closed before calling
  4061.   WindowWriteTextToFile(), and the file handle is automatically closed before
  4062.   exiting WindowWriteTextToFile().
  4063.  
  4064.   The last argument is the mode switch.  If mode is 1, a newline ('\n') is
  4065.   written to the file after each line of the window is written to the file.  If
  4066.   mode is 0, no newline character is written.
  4067.  
  4068.  
  4069.  
  4070.   Example:
  4071.  
  4072.   #include "window.h"
  4073.   #include <stdio.h>
  4074.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4075.  
  4076.   WPOINTER w;
  4077.   FILE *outfile;
  4078.   char *filename = "wintext";
  4079.   char *filename2 = "wintext2";
  4080.  
  4081.   main()
  4082.   {
  4083.     int i;
  4084.     WindowInitializeSystem();
  4085.     WindowSaveInitial(0);
  4086.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  4087.     WindowOpen(w);
  4088.     WindowDisplay(w,1,NOEFFECT);
  4089.     for (i=1;i<=10;i++)
  4090.       WindowWriteString(w,"Hello World!!",i,1);
  4091.     GET_KEY();
  4092.     WindowWriteTextToFile(w,filename,1);  /* use newlines */
  4093.     WindowWriteTextToFile(w,filename2,0); /* no newlines */
  4094.   }
  4095.  
  4096.  Page 62                     The C Window Library                    Page 62
  4097.  
  4098.   The example above illustrates two calls to WindowWriteTextToFile().  The
  4099.   first call writes the contents of the window w to a file called "wintext".
  4100.   Note that the mode parameter for the first call is 1.  This will cause '\n'
  4101.   to be written to the file for each line of the window.  The second call
  4102.   writes the window text to a file call "wintest2", with the mode parameter
  4103.   being 0 (no '\n').
  4104.  
  4105.   Please note that WindowWriteTextToFile() does not check if the file already
  4106.   exists, so be careful that you do not replace files that are important to
  4107.   you.
  4108.  
  4109.  
  4110.  
  4111.   If there are no errors, WindowWriteTextToFile() returns NO_ERROR.
  4112.  
  4113.   If there are errors, WindowWriteTextToFile() will return one of the following:
  4114.  
  4115.  
  4116.   BAD_WINDOW if the window does not exist.
  4117.  
  4118.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen())
  4119.  
  4120.   FILE_CANT_OPEN if the file specified by filename cannot be open.
  4121.  
  4122.   FILE_CANT_CLOSE if the file specified by filename cannot be closed.
  4123.  
  4124.  
  4125.  
  4126.  
  4127.  
  4128.  
  4129.  
  4130.  
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.  
  4139.  
  4140.  
  4141.  
  4142.  
  4143.  
  4144.  
  4145.  
  4146.  
  4147.  
  4148.  
  4149.  
  4150.  
  4151.  
  4152.  Page 63                     The C Window Library                    Page 63
  4153.  
  4154.                                SHADOWING WINDOWS
  4155.                                -----------------
  4156.  
  4157.   With The C Window Library, you can place shadows on the windows created.
  4158.   Shadows create a nice effect when displayed with the proper background color.
  4159.   There are four positions where you can place a shadow on a window: the upper
  4160.   left corner of the window, the upper right corner, the lower left corner or
  4161.   the lower right corner.
  4162.  
  4163.   The shadow consists of two components.  One of these components is the part of
  4164.   the shadow that is drawn either on the left or right side of the window.  You
  4165.   can control the width of this portion of the shadow.  The other component that
  4166.   makes up the shadow is the portion that is drawn either on top of or
  4167.   underneath a window.  You can control the height of this portion of the
  4168.   shadow.
  4169.  
  4170.   You can also control the shadows video attribute, as well as the character
  4171.   that makes up the shadow itself.  My suggestion is to use ASCII character 219
  4172.   for the shadow character.  Other ones that work well are ASCII 176, 178, and
  4173.   178.
  4174.  
  4175.   Transparent shadows are also supported.
  4176.  
  4177.   You can place a shadow on a window at any time or take it off at any time.
  4178.   The only restriction with the shadow is that the window's current position
  4179.   must have room to draw the shadow.
  4180.  
  4181.  
  4182.   WindowDrawShadow()
  4183.   ------------------
  4184.  
  4185.   The WindowDrawShadow() function places a shadow on a window.  Here is the
  4186.   prototype:
  4187.  
  4188.     int WindowDrawShadow(WPOINTER w, int shadowpos, int width, int height, int
  4189.                          shadowchar, int shadowattr, int transflag)
  4190.  
  4191.   The first argument is the window that the shadow will be drawn.  The second
  4192.   argument is the position of the shadow.  There are four possible positions:
  4193.  
  4194.          SHADOWUPRIGHT - draws shadow on upper right corner of the window.
  4195.          SHADOWUPLEFT -  draws shadow on upper left corner of the window.
  4196.          SHADOWLOWRIGHT - draws shadow on lower right corner of window.
  4197.          SHADOWLOWLEFT - draws shadow on lower left corner of window.
  4198.  
  4199.   The third argument is the width of the strip of the shadow that is drawn on
  4200.   the right or left side of the window.  The fourth argument is the height of
  4201.   the strip of the shadow that is drawn on top or underneath the window.  The
  4202.   fifth argument is the character to use for the shadow.  The sixth argument is
  4203.   the attribute to use for the shadow.  The last argument is a flag denoting
  4204.   whether the shadow should be a transparent shadow.  If the flag is 0, the
  4205.   shadow is solid, otherwise the shadow is transparent.
  4206.  
  4207.  
  4208.  Page 64                     The C Window Library                    Page 64
  4209.  
  4210.   Example:
  4211.  
  4212.     #include "window.h"
  4213.     #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define normal video
  4214.                                                            attribute */
  4215.     #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue) /* define a
  4216.                                                               blue on black
  4217.                                                              video attribute */
  4218.     #define REDONBLACK   CREATE_VIDEO_ATTRIBUTE(black,red)
  4219.     #define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
  4220.     #define REVERSE      CREATE_VIDEO_ATTRIBUTE(white,black)
  4221.  
  4222.     main()
  4223.     {
  4224.       WPOINTER w0,w1;               /* pointers to a window structures */
  4225.       WindowInitializeSystem();     /* system initialization function */
  4226.       WindowSaveInitial(0);
  4227.       w0 = WindowInitialize(NOBORDER,1,1,80,25,REVERSE,REVERSE,0);
  4228.       WindowOpen(w0);
  4229.       WindowDisplay(w0,1,NOEFFECT);
  4230.       w1 = WindowInitialize(BORDER,5,5,40,15,BLUEONBLACK,REDONBLACK,SINGLEBOX);
  4231.       WindowOpen(w1);
  4232.       WindowDrawShadow(w1,SHADOWUPLEFT,2,1,219,REVERSE,0);
  4233.       WindowDisplay(w1,1,NOEFFECT);
  4234.       WindowWriteString(w1,"Press a key to move shadow",1,1);
  4235.       GET_KEY();
  4236.       WindowDrawShadow(w1,SHADOWUPRIGHT,2,1,219,REVERSE,0);
  4237.       WindowWriteString(w1,"Press a key again",2,1);
  4238.       GET_KEY();
  4239.       WindowDrawShadow(w1,SHADOWLOWLEFT,2,1,219,REVERSE,0);
  4240.       WindowWriteString(w1,"Press a key once more",3,1);
  4241.       GET_KEY();
  4242.       WindowDrawShadow(w1,SHADOWLOWRIGHT,2,1,219,REVERSE,0);
  4243.       GET_KEY();
  4244.       WindowClose(w1,NOEFFECT);
  4245.       WindowClose(w0,NOEFFECT);
  4246.     }
  4247.  
  4248.   The above example illustrates the use of WindowDrawShadow().
  4249.  
  4250.   If there is no error, WindowDrawShadow() returns NO_ERROR.
  4251.  
  4252.   If there are errors, WindowDrawShadow() returns one of the following:
  4253.  
  4254.   BAD_WINDOW if the window does not exist.
  4255.  
  4256.   WINDOW_BOUND if a shadow could not be drawn because of window location and
  4257.   the height and/or width of the shadow will exceed the screen edges.
  4258.  
  4259.  
  4260.  
  4261.  
  4262.  
  4263.  
  4264.  Page 65                     The C Window Library                    Page 65
  4265.  
  4266.   WindowRemoveShadow()
  4267.   --------------------
  4268.  
  4269.   The WindowRemoveShadow() function removes a shadow from a window, and takes
  4270.   a single argument, namely the window pointer.  Here is the prototype:
  4271.  
  4272.                    int WindowRemoveShadow(WPOINTER w)
  4273.  
  4274.   If there are no errors or the window does not have a shadow,
  4275.   WindowRemoveShadow() returns NO_ERROR.
  4276.  
  4277.   If there are errors, WindowRemoveShadow() returns the following value:
  4278.  
  4279.   BAD_WINDOW if the window does not exist.
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.  
  4296.  
  4297.  
  4298.  
  4299.  
  4300.  
  4301.  
  4302.  
  4303.  
  4304.  
  4305.  
  4306.  
  4307.  
  4308.  
  4309.  
  4310.  
  4311.  
  4312.  
  4313.  
  4314.  
  4315.  
  4316.  
  4317.  
  4318.  
  4319.  
  4320.  Page 66                     The C Window Library                    Page 66
  4321.  
  4322.                                SEE-THRU WINDOWS
  4323.                                ----------------
  4324.  
  4325.   You can create windows that have borders, but do not overwrite the screen
  4326.   underneath.  These windows are called see-thru windows.
  4327.  
  4328.   When creating see-thru windows the WindowMakeSeeThru() function is used to
  4329.   make a defined window a see-thru window.
  4330.  
  4331.   You can turn a non-seethru window into a seethru window and vice-versa by
  4332.   calling the WindowMakeNormal() function.
  4333.  
  4334.  
  4335.  
  4336.   WindowMakeSeeThru()
  4337.   -------------------
  4338.  
  4339.   The WindowMakeSeeThru() function turns a normal window into a see-thru
  4340.   window.  Here is a prototype:
  4341.  
  4342.                     int WindowMakeSeeThru(WPOINTER w)
  4343.  
  4344.   The only argument is the window pointer.  You can make a window a see-thru
  4345.   window at any time, including if it is hidden.  If there is text in the
  4346.   normal window before making it a see-thru window, the text is retained.  If
  4347.   text is written to a see-thru window, the text is written to the window's
  4348.   internal write buffer, but is not displayed on the screen.
  4349.  
  4350.  
  4351.   Example:
  4352.  
  4353.     #include "window.h"
  4354.  
  4355.     #define NORM            CREATE_VIDEO_ATTRIBUTE(black,white)
  4356.  
  4357.     WPOINTER w;
  4358.  
  4359.     main()
  4360.     {
  4361.       WindowInitializeSystem();
  4362.       WindowSaveInitial(0);
  4363.       w = WindowInitialize(BORDER,1,1,20,5,NORM,NORM,SINGLEBOX);
  4364.       WindowOpen(w);
  4365.       WindowDisplay(w,1,NOEFFECT);
  4366.       GET_KEY();
  4367.       WindowMakeSeeThru(w);
  4368.       GET_KEY();
  4369.       WindowFree(w,NOEFFECT);
  4370.     }
  4371.  
  4372.  
  4373.  
  4374.  
  4375.  
  4376.  Page 67                     The C Window Library                    Page 67
  4377.  
  4378.   The example above displays a normal window, and then turns the normal window
  4379.   into a see-thru window when a key is pressed.
  4380.  
  4381.   If there are no errors, WindowMakeSeeThru() returns NO_ERROR.
  4382.  
  4383.   If there are errors, WindowMakeSeeThru() returns the following value:
  4384.  
  4385.   BAD_WINDOW if the window does not exist.
  4386.  
  4387.  
  4388.  
  4389.  
  4390.   WindowMakeNormal()
  4391.   ------------------
  4392.  
  4393.   The WindowMakeNormal() function turns a see-thru window into a normal text
  4394.   window.  Any text that may have been written to the window will be displayed.
  4395.   Here is the prototype:
  4396.  
  4397.                 int WindowMakeNormal(WPOINTER w)
  4398.  
  4399.   Example:
  4400.  
  4401.     #include "window.h"
  4402.  
  4403.     #define NORM            CREATE_VIDEO_ATTRIBUTE(black,white)
  4404.  
  4405.     WPOINTER w;
  4406.  
  4407.     main()
  4408.     {
  4409.       WindowInitializeSystem();
  4410.       WindowSaveInitial(0);
  4411.       w = WindowInitialize(BORDER,1,1,20,5,NORM,NORM,SINGLEBOX);
  4412.       WindowOpen(w);
  4413.       WindowDisplay(w,1,NOEFFECT);
  4414.       GET_KEY();
  4415.       WindowMakeSeeThru(w);
  4416.       GET_KEY();
  4417.       WindowMakeNormal(w);
  4418.     }
  4419.  
  4420.  
  4421.   The example above demonstrates the WindowMakeNormal() function.
  4422.  
  4423.   If there are no errors, WindowMakeNormal() returns NO_ERROR.
  4424.  
  4425.   If there are errors, WindowMakeNormal() returns the following value:
  4426.  
  4427.   BAD_WINDOW if the window does not exist.
  4428.  
  4429.  
  4430.  
  4431.  
  4432.  Page 68                     The C Window Library                    Page 68
  4433.  
  4434.                           MOVING AND SLIDING WINDOWS
  4435.                           --------------------------
  4436.  
  4437.   With The C Window Library, you can move and slide windows on the screen.  The
  4438.   functions that perform this are the WindowMove() and WindowSlide().
  4439.  
  4440.  
  4441.   WindowMove()
  4442.   ------------
  4443.  
  4444.   The WindowMove() function moves a window to a new location on the screen.
  4445.   Here is the prototype:
  4446.  
  4447.                  int WindowMove(WPOINTER w, int row, int col)
  4448.  
  4449.   The first argument is the window.  The second and third arguments are the
  4450.   row and column on the physical screen to place the upper left hand corner of
  4451.   the window.  Note that row and column are screen relative coordinates, not
  4452.   window relative.  This is one of the few functions where row and column
  4453.   denote a screen relative coordinate and not a window relative coordinate.
  4454.  
  4455.   If the row and/or column is out of bounds, the window is moved as far as
  4456.   possible.
  4457.  
  4458.    Example:
  4459.  
  4460.    #include "window.h"
  4461.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define  video
  4462.                                                           attribute */
  4463.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  4464.                                                            video attribute */
  4465.    main()
  4466.    {
  4467.      WPOINTER w;             /* pointer to a window structure */
  4468.      WindowInitializeSystem();     /* system initialization function */
  4469.      WindowSaveInitial(0);
  4470.      w = WindowInitialize(BORDER,1,1,30,15,BLUEONBLACK,NORM,SINGLEBOX);
  4471.      WindowOpen(w);              /* display window on the screen */
  4472.      WindowWriteString(w,"Press a key to move me",1,1);
  4473.      WindowDisplay(w,1,NOEFFECT);
  4474.      GET_KEY();
  4475.      WindowMove(w,12,14);       /* move the window to row 12, column 14 of the
  4476.                                 screen */
  4477.    }
  4478.  
  4479.   The example above moves the window from its original position (1,1) to
  4480.   (12,14).
  4481.  
  4482.   If there is no error WindowMove() returns NO_ERROR.
  4483.  
  4484.   If there are errors WindowMove() returns the following value:
  4485.  
  4486.   BAD_WINDOW if the window does not exist.
  4487.  
  4488.  Page 69                     The C Window Library                    Page 69
  4489.  
  4490.   WindowSlide()
  4491.   -------------
  4492.  
  4493.   The WindowSlide() function "slides" a window from one position on the screen
  4494.   to another.  Here is the prototype:
  4495.  
  4496.       int WindowSlide(WPOINTER w, int direction, int units)
  4497.  
  4498.   The first argument is the window.  The second argument tells in which
  4499.   direction to move the window, either up, down, left, or right.  The
  4500.   constants to use for up, down, left, and right are UP, DOWN, LEFT, and
  4501.   RIGHT, respectively.  The third argument tells how many rows or columns to
  4502.   move the window.  If the number of units will cause the window to exceed the
  4503.   boundaries of the screen, the window is moved as far as possible.
  4504.  
  4505.  
  4506.   Example:
  4507.  
  4508.    #include "window.h"
  4509.    #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)  /* define  video
  4510.                                                           attribute */
  4511.    #define BLUEONBLACK  CREATE_VIDEO_ATTRIBUTE(black,blue)  /* define
  4512.                                                            video attribute */
  4513.  
  4514.    main()
  4515.    {
  4516.      WPOINTER w;             /* pointer to a window structure */
  4517.      WindowInitializeSystem();     /* system initialization function */
  4518.      WindowSaveInitial(0);
  4519.      w = WindowInitialize(BORDER,1,1,30,10,BLUEONBLACK,NORM,SINGLEBOX);
  4520.      WindowOpen(w);              /* display window on the screen */
  4521.      WindowWriteString(w,"Press a key to slide right",1,1);
  4522.      WindowDisplay(w,1,NOEFFECT);
  4523.      GET_KEY();
  4524.      WindowSlide(w,RIGHT,20);
  4525.      WindowWriteString(w,"Press a key to slide down",2,1);
  4526.      GET_KEY();
  4527.      WindowSlide(w,DOWN,10);
  4528.      WindowWriteString(w,"Press a key to slide left",3,1);
  4529.      GET_KEY();
  4530.      WindowSlide(w,LEFT,20);
  4531.      WindowWriteString(w,"Press a key to slide up",4,1);
  4532.      GET_KEY();
  4533.      WindowSlide(w,UP,20);
  4534.    }
  4535.  
  4536.  
  4537.    The example above illustrates how to use the WindowSlide() function.
  4538.  
  4539.    The return values for WindowSlide() are the same as WindowMove().
  4540.  
  4541.  
  4542.  
  4543.  
  4544.  Page 70                     The C Window Library                    Page 70
  4545.  
  4546.                          CURSOR POSITIONING IN WINDOWS
  4547.                          -----------------------------
  4548.  
  4549.   You can change the position of the cursor and its shape in the windows you
  4550.   create with The C Window Library.
  4551.  
  4552.  
  4553.  
  4554.   Cursor Maintenance in The C Window Library
  4555.   ------------------------------------------
  4556.  
  4557.   As was stated before, The C Window Library can write to any window at any
  4558.   time.  This makes the question "which window owns the cursor?" a hard
  4559.   question to answer.  One method is that the window being updated either by
  4560.   writing text, clearing, etc. should have immediate control of the cursor.
  4561.   The approach The C Window Library has taken is that the top-most window
  4562.   always has control of the cursor.  The topmost window is determined by its
  4563.   rank number.  Windows with low rank numbers overlay windows with higher rank
  4564.   numbers.
  4565.  
  4566.  
  4567.  
  4568.   Creating Cursor Shapes
  4569.   ----------------------
  4570.  
  4571.   The C Window Library has three pre-defined cursor shapes; INVISIBLE, THIN,
  4572.   and BLOCK.  An INVISIBLE cursor hides the cursor, a BLOCK shape creates a
  4573.   "fat" cursor, and THIN creates a thin cursor.  If you want to define your own
  4574.   cursor shapes, use the CREATE_CURSOR_SHAPE() macro.  This macro takes two
  4575.   arguments the first argument is the beginning scan line, and the second
  4576.   argument is the ending scan line.  Scan lines determine the height of the
  4577.   cursor.  For monochrome systems, the scan lines range from 0 to 13.  In a
  4578.   color system, the scan lines range from 0 to 7.  A THIN cursor has its
  4579.   starting scan line at 6 and its ending scan line at 7 for color systems, and
  4580.   for monochrome systems, the starting scan line is 11 and its ending scan line
  4581.   is at 12.  If the starting scan line number is greater than the ending scan
  4582.   line number, the cursor takes on a 'double' cursor shape.  Experiment with
  4583.   different starting and ending scan lines for the desired effect.
  4584.  
  4585.  
  4586.  
  4587.   WindowChangeCursor()
  4588.   --------------------
  4589.  
  4590.   The WindowChangeCursor() function changes the shape of the cursor in a
  4591.   window.  Here is the prototype:
  4592.  
  4593.                int WindowChangeCursor(WPOINTER w, int shape)
  4594.  
  4595.   The first argument is the window.  The second argument is the desired cursor
  4596.   shape.
  4597.  
  4598.  
  4599.  
  4600.  Page 71                     The C Window Library                    Page 71
  4601.  
  4602.   Example:
  4603.  
  4604.   #include "window.h"
  4605.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4606.  
  4607.  
  4608.  
  4609.   WPOINTER w;
  4610.  
  4611.   main()
  4612.   {
  4613.     WindowInitializeSystem();
  4614.     WindowSaveInitial(0);
  4615.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  4616.     WindowOpen(w);
  4617.     WindowDisplay(w,1,NOEFFECT);
  4618.     WindowWriteString(w,"Press a key to change cursor",1,1);/* Write String */
  4619.     GET_KEY();
  4620.     WindowChangeCursor(w,BLOCK);
  4621.     WindowWriteString(w,"Press a key to change cursor again",2,1);
  4622.     GET_KEY();
  4623.     WindowChangeCursor(w,INVISIBLE);
  4624.     WindowWriteString(w,"Press a key to change cursor again",3,1);
  4625.     GET_KEY();
  4626.     WindowChangeCursor(w,THIN);
  4627.   }
  4628.  
  4629.  
  4630.   If there are no errors, WindowChangeCursor() returns NO_ERROR.
  4631.   If there are errors, WindowChangeCursor() returns the following value:
  4632.  
  4633.   BAD_WINDOW if the window does not exist.
  4634.  
  4635.  
  4636.  
  4637.  
  4638.  
  4639.   WindowMoveCursor()
  4640.   ------------------
  4641.  
  4642.   The WindowMoveCursor() functions moves the cursor in a window to a new
  4643.   location in the window.  Here is the prototype:
  4644.  
  4645.  
  4646.            int WindowMoveCursor(WPOINTER w, int row, int col)
  4647.  
  4648.   The first argument is the window, and the second and third arguments are the
  4649.   new (row,col) position in the window to place the cursor.
  4650.  
  4651.  
  4652.  
  4653.  
  4654.  
  4655.  
  4656.  Page 72                     The C Window Library                    Page 72
  4657.  
  4658.   Example:
  4659.  
  4660.   #include "window.h"
  4661.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4662.  
  4663.   WPOINTER w;
  4664.  
  4665.   main()
  4666.   {
  4667.     WindowInitializeSystem();
  4668.     WindowSaveInitial(0);
  4669.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  4670.     WindowOpen(w);
  4671.     WindowDisplay(w,1,NOEFFECT);
  4672.     WindowWriteString(w,"Press a key to move cursor",1,1);/* Write String */
  4673.     GET_KEY();
  4674.     WindowMoveCursor(w,7,5); /* Move Cursor To row 7, column 5 of the window */
  4675.   }
  4676.  
  4677.  
  4678.   If there are no errors, WindowMoveCursor() returns NO_ERROR.
  4679.   If there are errors, WindowMoveCursor() returns the following values:
  4680.  
  4681.   BAD_WINDOW if the window does not exist.
  4682.  
  4683.   WINDOW_BOUND if either new row or column number is out of the boundaries of
  4684.   the window.
  4685.  
  4686.  
  4687.  
  4688.  
  4689.   WindowGetCursorShape()
  4690.   ----------------------
  4691.  
  4692.   The WindowGetCursorShape() function returns the starting and ending scan lines
  4693.   of the cursor defined in a window.  Here is the prototype:
  4694.  
  4695.  
  4696.         int WindowGetCursorShape(WPOINTER w, int *startline, int *endline)
  4697.  
  4698.   The startline and endline arguments are pointers to integers that will
  4699.   contain the starting and ending scan lines of the cursor when
  4700.   WindowGetCursorShape() returns.
  4701.  
  4702.  
  4703.  
  4704.  
  4705.  
  4706.  
  4707.  
  4708.  
  4709.  
  4710.  
  4711.  
  4712.  Page 73                     The C Window Library                    Page 73
  4713.  
  4714.   Example:
  4715.  
  4716.   #include "window.h"
  4717.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4718.  
  4719.   WPOINTER w;
  4720.  
  4721.   main()
  4722.   {
  4723.     int startline,endline;
  4724.     WindowInitializeSystem();
  4725.     WindowSaveInitial(0);
  4726.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  4727.     WindowOpen(w);
  4728.     WindowDisplay(w,1,NOEFFECT);
  4729.     WindowGetCursorShape(w,&startline,&endline);
  4730.     WindowPrintf(w,"The starting scan line is %d\nThe ending scan line is %d",
  4731.                  startline,endline);
  4732.   }
  4733.  
  4734.   The example above calls WindowGetCursorShape() and uses WindowPrintf() to
  4735.   print what the starting and ending scan lines are.
  4736.  
  4737.   If there are no errors, WindowGetCursorShape() returns NO_ERROR.
  4738.   If there are errors, WindowGetCursorShape() returns the following values:
  4739.  
  4740.   BAD_WINDOW if the window does not exist.
  4741.  
  4742.  
  4743.  
  4744.  
  4745.  
  4746.   WindowGetCursorPosition()
  4747.   -------------------------
  4748.  
  4749.   The WindowGetCursorPosition() function gives the current row and column of
  4750.   the cursor in a window.  Here is the prototype:
  4751.  
  4752.  
  4753.          int WindowGetCursorPosition(WPOINTER w, int *row, int *col)
  4754.  
  4755.   The row and col arguments are pointers to integers that will contain the row
  4756.   and column of the cursor after WindowGetCursorPosition() is called.
  4757.  
  4758.  
  4759.  
  4760.  
  4761.  
  4762.  
  4763.  
  4764.  
  4765.  
  4766.  
  4767.  
  4768.  Page 74                     The C Window Library                    Page 74
  4769.  
  4770.   Example:
  4771.  
  4772.   #include "window.h"
  4773.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  4774.  
  4775.   WPOINTER w;
  4776.  
  4777.   main()
  4778.   {
  4779.     int row,col;
  4780.     WindowInitializeSystem();
  4781.     WindowSaveInitial(0);
  4782.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  4783.     WindowOpen(w);
  4784.     WindowDisplay(w,1,NOEFFECT);
  4785.     WindowMoveCursor(w,7,4);
  4786.     WindowGetCursorPosition(w,&row,&col);
  4787.     WindowPrintf(w,
  4788.         "The row of the cursor is %d\nThe column of the cursor is %d",
  4789.          row,col);
  4790.   }
  4791.  
  4792.   If there are no errors, WindowGetCursorPosition() returns NO_ERROR.
  4793.   If there are errors, WindowGetCursorPosition() returns the following value:
  4794.  
  4795.   BAD_WINDOW if the window does not exist.
  4796.  
  4797.  
  4798.  
  4799.  
  4800.  
  4801.  
  4802.  
  4803.  
  4804.  
  4805.  
  4806.  
  4807.  
  4808.  
  4809.  
  4810.  
  4811.  
  4812.  
  4813.  
  4814.  
  4815.  
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  
  4823.  
  4824.  Page 75                     The C Window Library                    Page 75
  4825.  
  4826.                           GETTING INPUT FROM WINDOWS
  4827.                           --------------------------
  4828.  
  4829.   With The C Window Library, you can read input from windows.  The input can be
  4830.   simple string input, or inputting strings with a character mask.  There is
  4831.   also support for scrolling input fields.
  4832.  
  4833.  
  4834.  
  4835.  
  4836.   Input Manager
  4837.   -------------
  4838.  
  4839.   The input manager are functions internal in The C Window Library that control
  4840.   editing, checking for invalid characters, cursor movement, etc.
  4841.  
  4842.  
  4843.   Regular Expressions
  4844.   -------------------
  4845.   With The C Window Library, you specify exactly what characters are to be
  4846.   expected for every input position by using a special string of characters
  4847.   called a regular expression (a pattern matching string).
  4848.  
  4849.   Note:
  4850.   For those who are familiar with regular expressions, there is a difference
  4851.   between the regular expressions you will see here, and the regular
  4852.   expressions you will find in certain text editors, or in computer language
  4853.   syntax definitions.  One major difference is that there are no wild cards
  4854.   denoting an arbitrary number of repeated characters (which is usually denoted
  4855.   by a '*' or a '+'), and there are no 'match begin of string' and 'match end
  4856.   of string' functions.
  4857.  
  4858.  
  4859.  
  4860.   An example of a regular expression would be the string "[A-Z]" which means
  4861.   only those characters that are between  A and Z, inclusive, are to be
  4862.   accepted as valid input characters.  Of course, the ASCII collating sequence
  4863.   is used.
  4864.  
  4865.   The following characters have special meanings in regular expressions:
  4866.  
  4867.    Character                      Purpose
  4868.    ---------                      -------
  4869.  
  4870.    Forward Slash (/)              Removes the special meaning of the next
  4871.                                   character in the regular expression.
  4872.  
  4873.  
  4874.    Brackets ([])                  Encloses a set of characters to be matched
  4875.                                   with the current character entered at the
  4876.                                   keyboard.  There are other special symbols
  4877.                                   that can appear in brackets:
  4878.                                   ---------------------------------------------
  4879.  
  4880.  Page 76                     The C Window Library                    Page 76
  4881.  
  4882.                                   Carat (^)    This symbol states that the
  4883.                                                character entered at the keyboard
  4884.                                                must not match any character in
  4885.                                                the brackets.  The carat must be
  4886.                                                the first character after the
  4887.                                                left bracket ([), otherwise the
  4888.                                                carat is taken literally as just
  4889.                                                another character.
  4890.  
  4891.                                   Dash  (-)    Matches character entered at
  4892.                                                keyboard with characters in ASCII
  4893.                                                order between (inclusive) the
  4894.                                                characters on either side of the
  4895.                                                dash.
  4896.  
  4897.                                   Dot   (.)    Matches any displayable ASCII
  4898.                                                character.
  4899.  
  4900.   There are two categories of regular expressions; namely simple and complex.
  4901.   Simple regular expressions only specify a single character to be entered from
  4902.   the keyboard, while complex regular expressions specify that more than a
  4903.   single character must be entered from the keyboard.
  4904.  
  4905.   Here are examples of simple regular expressions:
  4906.  
  4907.  
  4908.  
  4909.        Simple
  4910.   Regular Expression              What will be accepted
  4911.   ------------------              ---------------------
  4912.  
  4913.        [0-9]                      Accept any single digit character.
  4914.  
  4915.        [3-7]                      Accept single digit character between '3' and
  4916.                                   '7' inclusive.
  4917.  
  4918.        [A-Z]                      Accept a letter between 'A' and 'Z' inclusive.
  4919.  
  4920.        [A-Za-z]                   Accept a letter between 'A' and 'Z' or a
  4921.                                   letter between 'a' and 'z'.
  4922.  
  4923.  
  4924.        [ABCD]                     Accept either 'A', 'B', 'C', or 'D'.
  4925.  
  4926.        [A-Za-z0-9]                Accept anything between 'A' and 'Z', or
  4927.                                   'a' and 'z', or '0' and '9'
  4928.  
  4929.        [0-9ABCD]                  Accept '0' thru '9', 'A', 'B', 'C', or 'D'.
  4930.  
  4931.        [^A]                       Accept any character except 'A'.
  4932.  
  4933.        [^A-Z]                     Accept any character except the characters
  4934.                                   between 'A' and 'Z' (inclusive).
  4935.  
  4936.  Page 77                     The C Window Library                    Page 77
  4937.  
  4938.        [A-/[]                     Accept any character between 'A' and '[',
  4939.                                   inclusive.  Please note the use of the forward
  4940.                                   slash to denote that the left bracket has no
  4941.                                   special meaning.
  4942.  
  4943.        [A Z]                      Accept 'A', the space character, or 'Z'.
  4944.  
  4945.        [A/-Z]                     Accept 'A', the minus (-), or 'Z'.
  4946.  
  4947.        [/-///]]                   Accept the minus (-), the forward slash (/),
  4948.                                   or the right bracket (]).
  4949.  
  4950.        [!-&]                      Accept the ASCII characters between '!' and
  4951.                                   '&', inclusive.
  4952.  
  4953.        A                          Accept the letter 'A'.  Note that this is
  4954.                                   equivalent to [A].
  4955.  
  4956.        [9]                        Accept the digit '9'.
  4957.  
  4958.        .                          Accept any character.
  4959.  
  4960.   Remember, all of the above expressions process only one character entered at
  4961.   the keyboard, even though some of the expressions can accept a variety of
  4962.   characters.
  4963.  
  4964.   As you can see there are many possibilities you can make up.  However the
  4965.   above forms of a regular expressions only work for one character entered at
  4966.   the keyboard.  What if you want to enter a persons name, address, social
  4967.   security number etc.?  You can concatenate (glue together) the regular
  4968.   expressions above to form a chain of regular expressions.  This resulting
  4969.   chain is called a complex regular expression.
  4970.  
  4971.   Here are a few examples of complex regular expressions:
  4972.  
  4973.   Regular Expression              What will be accepted
  4974.   ------------------              ---------------------
  4975.      [A-Z][0-9]                   The first character entered must be between
  4976.                                   'A' and 'Z'.  The second character entered
  4977.                                   must be between '0' and '9'.
  4978.  
  4979.      [A-Z][^A-Z][0-9]             Enter three characters.  The first must be
  4980.                                   between 'A' and 'Z'.  The second can be any
  4981.                                   character except anything between 'A' and 'Z',
  4982.                                   and the third character must be between '0'
  4983.                                   and '9'.
  4984.  
  4985.   [1-9][0-9][0-9][0-9][0-9]       Enter five characters.  The first must
  4986.                                   be between '1' and '9'.  The other four
  4987.                                   characters must be between '0' and '9'.
  4988.  
  4989.  
  4990.  
  4991.  
  4992.  Page 78                     The C Window Library                    Page 78
  4993.  
  4994.   As you can see again, the strings can get pretty long if you wanted to setup a
  4995.   thirty character input specification, for instance, a persons name.  To save
  4996.   time typing, you can use a multiplying factor in the regular expression.  A
  4997.   multiplying factor is a number that is placed before a simple regular
  4998.   expression to denote that the simple regular expression is repeated.
  4999.  
  5000.   Here are a few examples:
  5001.  
  5002.   Regular Expression              What will be accepted
  5003.   ------------------              ---------------------
  5004.  
  5005.     25[A-Z]                       Enter twenty-five characters.  All the
  5006.                                   characters must be between 'A' and 'Z'.
  5007.  
  5008.     10[0-9]                       Enter ten characters.  All must be between
  5009.                                   '0' and '9'.
  5010.  
  5011.     5[A-C] 3[1-3]                 Enter nine characters. The first five must be
  5012.                                   between 'A' and 'C' the sixth must be the
  5013.                                   space character, and the last three must be
  5014.                                   between '1' and '3'.  Please note the space
  5015.                                   embedded in the string just before the
  5016.                                   multiplying factor 3.
  5017.  
  5018.     [1-9]2X/[5[^A-Z]/1            Enter nine characters.  The first must be
  5019.                                   between '1' and '9'.  The second and third
  5020.                                   must be 'X'. The fourth is the left bracket
  5021.                                   ([).  The next five characters entered can be
  5022.                                   any character except anything between 'A' and
  5023.                                   'Z', and the last character to accept is a
  5024.                                   '1'.  Please note the use of the forward slash
  5025.                                   just before the second left bracket and just
  5026.                                   before the last character ('1').  The
  5027.                                   forward slash before the '1' makes sure the
  5028.                                   '1' is not to be confused with a multiplying
  5029.                                   factor of 1.
  5030.  
  5031.     [A-Z]/..                      Enter three characters.  The first must be
  5032.                                   between 'A' and 'Z'.  The second is the '.',
  5033.                                   and the third is any character.
  5034.  
  5035.   The only  limitation to what you can do with regular expressions is that you
  5036.   cannot nest regular expressions.  For example:
  5037.  
  5038.                  [A-[A-Z]]     or     20[20[a-z]]
  5039.  
  5040.  
  5041.   It is ok to say [9-0] instead of [0-9].  They are both equivalent and both
  5042.   accepted by The C Window Library, so there is no need to know your ASCII
  5043.   table by heart, although it is advantageous to learn it if you want to create
  5044.   sophisticated regular expression strings.  You can even use the IBM extended
  5045.   character set (ASCII values above 127) in the regular expression string.
  5046.  
  5047.  
  5048.  Page 79                     The C Window Library                    Page 79
  5049.  
  5050.   Editing Input
  5051.   -------------
  5052.  
  5053.   The C library function gets(x), gets a string from the keyboard and points
  5054.   the character pointer x to the string.  This function has limited editing
  5055.   capabilities.  The only keys recognized are the backspace, which serves as a
  5056.   destructive backspace (erases character immediately to the left) and the
  5057.   enter key when the user has typed in the desired string.  With The C Window
  5058.   Library, you have much more editing capabilities.
  5059.  
  5060.  
  5061.   The editing functions have the following default key values:
  5062.  
  5063.                                                                Mapped
  5064.        Function                               Key             Position
  5065.        --------                               ---              ------
  5066.      Move cursor left                    Left Arrow              0
  5067.      Move cursor right                   Right Arrow             1
  5068.      Delete character at cursor          Del (on keypad)         2
  5069.      Toggle Insert/Overwrite mode        Insert (on keypad)      3
  5070.      Erase Input and go to first column  ^E                      4
  5071.      Destructive backspace               Backspace               5
  5072.      Accept Input and return             Enter                   6
  5073.      Accept default and return           Escape                  7
  5074.      Go to first column                  Home                    8
  5075.      Move cursor to last char. entered   End                     9
  5076.  
  5077.   Here is a list of what the key functions perform:
  5078.  
  5079.  
  5080.   Move cursor left - Moves the cursor left one character.  If the beginning of
  5081.                      the input field is encountered the cursor is not moved.
  5082.  
  5083.   Move cursor right - Moves the cursor right one character.  If the end of the
  5084.                       input field is encountered, the cursor is not moved.
  5085.  
  5086.   Delete character at cursor - Deletes the character at the position of the
  5087.                                cursor.  If in insert mode, any input to the
  5088.                                right of the cursor is moved one character to
  5089.                                the left.  If in overwrite mode, no characters
  5090.                                are moved.
  5091.  
  5092.   Toggle Insert/Overwrite Mode - toggles the input between insert and overwrite
  5093.                                  mode.  If in insert mode, the default cursor
  5094.                                  is an underline cursor.  If in overwrite mode,
  5095.                                  the default cursor is a full block.
  5096.  
  5097.   Erase Input - Deletes all characters inputted and moves the cursor to the
  5098.                 first input position.
  5099.  
  5100.  
  5101.  
  5102.  
  5103.  
  5104.  Page 80                     The C Window Library                    Page 80
  5105.  
  5106.   Destructive Backspace - deletes the character immediately to the left of the
  5107.                           cursor and moves the cursor to the left one
  5108.                           character. If insert mode is on, the characters from
  5109.                           the current cursor position to the end of the input
  5110.                           field are also moved.
  5111.  
  5112.   Accept string - Accepts the string that is inputted and returns the string.
  5113.  
  5114.   Accept default and return - Returns the default string given to the input
  5115.                               routine.
  5116.  
  5117.   Go to first column - Moves cursor to the first input position.
  5118.  
  5119.   Go to last character - Moves cursor to the last character in the current input
  5120.   string.
  5121.  
  5122.  
  5123.   The keys used to perform these functions can be changed.  The mapped position
  5124.   is the offset in a table of key functions.  By changing the value there, you
  5125.   can change the key used to perform these functions.  If you do want to change
  5126.   these keys, I recommend using the key definitions found in the keycodes.h
  5127.   file.  For example, if you wanted Control-B to be the destructive backspace
  5128.   you would do as follows:
  5129.  
  5130.         window_edit_key[5] = CTRLB;
  5131.  
  5132.   The table of key functions is stored in the array window_edit_key.  The CTRLB
  5133.   stands for Control-B and its definition is found in the keycodes.h file.  To
  5134.   totally undefine a key definition, assign a 0 to the desired array position
  5135.   in window_edit_key.  For example:
  5136.  
  5137.         window_edit_key[2] = 0;
  5138.  
  5139.    undefines the delete character at cursor definition.
  5140.  
  5141.   When changing keys, make sure that the definitions all have unique key
  5142.   combinations.  If you desire more keystrokes for a particular key function,
  5143.   see Undefined Keystroke Processing below.
  5144.  
  5145.  
  5146.  
  5147.   Last Key Value
  5148.   --------------
  5149.  
  5150.   On exit of any of the input functions, the global integer last_key_hit
  5151.   contains the ascii code (scan code) of the key that was used to exit the
  5152.   input function.
  5153.  
  5154.  
  5155.  
  5156.  
  5157.  
  5158.  
  5159.  
  5160.  Page 81                     The C Window Library                    Page 81
  5161.  
  5162.   Default Cursor Types and Editing Mode
  5163.   -------------------------------------
  5164.  
  5165.   By default, The C Window Library starts editing input in overstrike mode.
  5166.   This means that characters are overwritten when the cursor is placed on a
  5167.   character.  The opposite of overstrike mode is insert mode, which pushes the
  5168.   characters to the right of the cursor over by one input position when a
  5169.   character is entered.  Also, the default cursor type for overstrike mode is a
  5170.   block cursor, and the default cursor for insert mode is a thin cursor.  You
  5171.   can change the startup mode, as well as the cursor types.
  5172.  
  5173.   The global variables default_cursor_type and default_cursor_mode store the
  5174.   values of the cursor shapes and the startup mode.
  5175.  
  5176.   The default_cursor_type is an array of two integers.  The OVERSTRIKEMODE
  5177.   constant is the position in the default_cursor_type array of where the
  5178.   overstrike shape of the cursor is stored.  The INSERTMODE constant is
  5179.   the position in default_cursor_type of where the insert shape of the
  5180.   cursor is stored.  Here is an example of how you would change the
  5181.   cursor types.
  5182.  
  5183.   #include "window.h"
  5184.  
  5185.   main()
  5186.   {
  5187.     WindowInitializeSystem();
  5188.     /*...*/                  /* Some code */
  5189.  
  5190.     default_cursor_type[OVERSTRIKEMODE] = CREATE_CURSOR_SHAPE(6,7);
  5191.     default_cursor_type[INSERTMODE] = THIN;
  5192.   }
  5193.  
  5194.   The CREATE_CURSOR_SHAPE() macro creates a cursor shape by using the first
  5195.   argument as the starting scan line of the cursor, and the second argument as
  5196.   the ending scan line.  Refer to page 275 for more information on
  5197.   CREATE_CURSOR_SHAPE().  The THIN constant is a predefined constant that
  5198.   stands for a thin cursor.  The other predefined constants for cursor shapes
  5199.   are BLOCK and INVISIBLE.
  5200.  
  5201.   To change the startup mode when an input function is called, you must change
  5202.   the default_cursor_mode global variable.  Here is how you would change the
  5203.   default mode:
  5204.  
  5205.   #include "window.h"
  5206.  
  5207.   main()
  5208.   {
  5209.     WindowInitializeSystem();
  5210.     /*...*/                  /* Some code */
  5211.     default_cursor_mode = OVERSTRIKEMODE;
  5212.   }
  5213.  
  5214.   Use the constants OVERSTRIKEMODE and INSERTMODE for the desired mode.
  5215.  
  5216.  Page 82                     The C Window Library                    Page 82
  5217.  
  5218.   Editing using a character mask
  5219.   ------------------------------
  5220.  
  5221.   The C Window Library also provides input functions that use character masks.
  5222.   For example to enter a date, you might want the user to enter a date in
  5223.   MM-DD-YY format.  Instead of the user having to enter the hyphens, it would be
  5224.   advantageous if the input field already had hyphens, and the cursor will
  5225.   advance or back up to the next input position, jumping over any hyphens
  5226.   encountered.  You can accomplish this by using a character mask.
  5227.  
  5228.   The mask is a character string which is made up of displayable characters, and
  5229.   a special character used to denote an input position.  For example, a date
  5230.   mask would look like this:
  5231.  
  5232.                                __-__-__
  5233.  
  5234.   The hyphens are displayed in the window, but the underscores are not
  5235.   displayed.  The underscores are used as a place holder, i.e. a place where
  5236.   input is expected.  By default, the input position character is an underscore,
  5237.   but you can change this.  Another example would be a social security mask:
  5238.  
  5239.                             ___-__-____
  5240.  
  5241.    a telephone mask:
  5242.                            (___) ___-____ ext: ____
  5243.  
  5244.    another date mask:
  5245.                            __/__/__
  5246.  
  5247.  
  5248.   If a character is deleted or inserted, the input manager is smart enough to
  5249.   move characters so that they do not clobber the characters that are not part
  5250.   of the input field.
  5251.  
  5252.  
  5253.  
  5254.   Editing Functions
  5255.   -----------------
  5256.  
  5257.   The following are functions that can be used to edit input with The C Window
  5258.   Library.
  5259.  
  5260.  
  5261.  
  5262.   WindowGetString()
  5263.   -----------------
  5264.  
  5265.   The WindowGetString() function gets a string from a window starting at a
  5266.   certain row and column of the window.  Here is the prototype:
  5267.  
  5268.     int WindowGetString(WPOINTER w, int row, int col, char *buffer,
  5269.                         int fillchar, int minchars, int maxwidth, int options,
  5270.                         char *regexp)
  5271.  
  5272.  Page 83                     The C Window Library                    Page 83
  5273.  
  5274.   The first argument is the window pointer.  The second and third arguments are
  5275.   the row and column of where the input begins.  The fourth argument is a
  5276.   pointer to a character buffer where the input characters will be stored.
  5277.   Whatever null terminated string is stored in the character buffer prior to
  5278.   calling WindowGetString() will be used as a default string.   For example:
  5279.  
  5280.       strcpy(str,"ABC");
  5281.       WindowGetString(w,2,1,str,' ',3,3,0,"3[A-Z]");
  5282.  
  5283.   The default value of "ABC" will be displayed in the window when
  5284.   WindowGetString() is called.  Therefore, make sure that your string buffer
  5285.   has a 0 in the 0th position if you want to make sure your input is empty when
  5286.   WindowGetString() is called.  When inputting information, hitting the Escape
  5287.   key (or whatever the current key definition is for window_edit_key[7]) will
  5288.   abort input and will return the original default string.
  5289.  
  5290.   The fifth argument is the fill character.  This character is used to fill any
  5291.   unfilled input positions on the window.  Instead of having spaces for unfilled
  5292.   positions, you can have any character.  Try ASCII 177 or the underline
  5293.   character.  You may like the effect.
  5294.  
  5295.   The sixth argument is the minimum number of characters to accept.  If the
  5296.   number of characters entered is less than minchars, the input manager will
  5297.   not accept the input.  However, you can change this by allowing the input
  5298.   manager to call a user defined routine when it detects that the minimum
  5299.   number of characters was not satisfied.  More information on this later in
  5300.   this section.
  5301.  
  5302.   The seventh argument is the maximum width of the displayable input field.
  5303.   This argument allows for scrollable input fields.  If the maximum width of
  5304.   the displayable field is less than the total number of characters in the
  5305.   input field, the field will scroll right and left depending on the input
  5306.   position.  If the input cursor exceeds the right edge of the displayable
  5307.   field, the input is scrolled right until the next input position is visible.
  5308.   If the cursor is moved beyond the left edge of the displayable field, the
  5309.   input is scrolled left until the previous input position comes into view.
  5310.   Scrolling input fields allow for large input fields in small windows.
  5311.  
  5312.   The eighth argument is an integer representing the various options available
  5313.   for the input field.  The various options available will be discussed later
  5314.   on.
  5315.  
  5316.   The last argument is the regular expression to use for the input.  Make sure
  5317.   that the input buffer you provide is large enough to hold the maximum number
  5318.   of characters plus one more character for the terminating null character.
  5319.  
  5320.   More Examples:
  5321.  
  5322.              WindowGetString(w,2,1,str,' ',1,1,0,"[YyNn]");
  5323.  
  5324.   This will accept one character but only if the character is 'Y','y','N', or
  5325.   'n'.  Another example is this:
  5326.  
  5327.  
  5328.  Page 84                     The C Window Library                    Page 84
  5329.  
  5330.              WindowGetString(w,2,1,str,' ',5,5,0,"5[0-9]");
  5331.  
  5332.   This will allow the user to enter five digit characters.
  5333.  
  5334.  
  5335.   To accept all characters, use this:
  5336.              WindowGetString(w,2,1,str,' ',3,3,0,".");
  5337.  
  5338.  
  5339.   Example Program:
  5340.  
  5341.  
  5342.   #include "window.h"
  5343.   #include <string.h>
  5344.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  5345.  
  5346.   WPOINTER w;
  5347.   char buffer[80];
  5348.   main()
  5349.   {
  5350.     int i,row,col;
  5351.     buffer[0] = 0;   /* Make sure first character is null */
  5352.     WindowInitializeSystem();
  5353.     WindowSaveInitial(0);
  5354.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5355.     WindowOpen(w);
  5356.     WindowDisplay(w,1,NOEFFECT);
  5357.     buffer[0] = 0;   /* Make sure first character is NULL */
  5358.     WindowWriteString(w,"Enter Your first name :",1,1);
  5359.     WindowGetString(w,2,1,buffer,' ',0,40,0,"40.");
  5360.     WindowWriteString(w,"You entered the following:",3,1);
  5361.     WindowWriteString(w,buffer,4,1);
  5362.     GET_KEY();
  5363.     WindowWriteString(w,"Now Enter your last name:",6,1);
  5364.  
  5365.     /* Note that the last string is now used as a default */
  5366.     WindowGetString(w,7,1,buffer,' ',0,40,0,"40.");
  5367.     WindowWriteString(w,"You entered the following:",8,1);
  5368.     WindowWriteString(w,buffer,9,1);
  5369.   }
  5370.  
  5371.  
  5372.   If there are no errors, WindowGetString() returns NO_ERROR.
  5373.   If there are errors, WindowGetString() returns the following:
  5374.  
  5375.   BAD_WINDOW if the window does not exist.
  5376.  
  5377.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen())
  5378.  
  5379.   NO_HEAP_MEM if there is not enough memory to allocate for internal buffers.
  5380.  
  5381.   NO_INPUT_CHARS if the regular expression indicates no characters to accept.
  5382.  
  5383.  
  5384.  Page 85                     The C Window Library                    Page 85
  5385.  
  5386.   WindowGetStringAttr()
  5387.   ---------------------
  5388.  
  5389.   The WindowGetStringAttr() function is the same as the WindowGetString()
  5390.   function described above except that a video attribute is used for the input
  5391.   entered.  Here is the prototype:
  5392.  
  5393.     int WindowGetStringAttr(WPOINTER w, int row, int col, char *buffer,
  5394.                             int fillchar, int minchars, int maxwidth,
  5395.                             int options, int attr, char *regexp)
  5396.  
  5397.   Note that attr is an extra argument.  This is the video attribute to use when
  5398.   receiving input.
  5399.  
  5400.  
  5401.   Example Program:
  5402.  
  5403.  
  5404.   #include "window.h"
  5405.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5406.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  5407.  
  5408.   WPOINTER w;
  5409.   char buffer[80];
  5410.   main()
  5411.   {
  5412.     int i,row,col;
  5413.     buffer[0] = 0;   /* Make sure first character is NULL */
  5414.     WindowInitializeSystem();
  5415.     WindowSaveInitial(0);
  5416.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5417.     WindowOpen(w);
  5418.     WindowDisplay(w,1,NOEFFECT);
  5419.     buffer[0] = 0;   /* Make sure first character is null */
  5420.     WindowWriteString(w,"Enter Your first name :",1,1);
  5421.     WindowGetStringAttr(w,2,1,buffer,' ',0,40,0,REVERSE,"40.");
  5422.     WindowWriteString(w,"You entered the following:",3,1);
  5423.     WindowWriteString(w,buffer,4,1);
  5424.     GET_KEY();
  5425.     WindowWriteString(w,"Now Enter your last name:",6,1);
  5426.  
  5427.     /* Note that the last string is now used as a default */
  5428.     WindowGetStringAttr(w,7,1,buffer,' ',0,40,0,REVERSE,"40.");
  5429.     WindowWriteString(w,"You entered the following:",8,1);
  5430.     WindowWriteString(w,buffer,9,1);
  5431.   }
  5432.  
  5433.   The return values for WindowGetStringAttr() are the same as
  5434.   WindowGetString().
  5435.  
  5436.  
  5437.  
  5438.  
  5439.  
  5440.  Page 86                     The C Window Library                    Page 86
  5441.  
  5442.   WindowGetMaskString()
  5443.   ---------------------
  5444.  
  5445.   The WindowGetMaskString() function is the same as the WindowGetString()
  5446.   except that a character mask is used when editing the input.  Here is the
  5447.   prototype:
  5448.  
  5449.     int WindowGetMaskString(WPOINTER w, int row, int col, char *buffer,
  5450.                             char *mask, int fillchar, int minchars,
  5451.                             int maxwidth, int options, char *regexp)
  5452.  
  5453.   The mask argument is an extra argument.  This is the character mask to use
  5454.   when editing the input.  The string returned in the buffer does not contain
  5455.   any characters that are used for the mask.  For instance, if the mask is
  5456.   "__/__/__", and the string entered is "121589", WindowGetMaskString() will
  5457.   place "121589" into the buffer.  If you want to create a string with the
  5458.   components separated according to a mask pattern, use the
  5459.   TranslateStringToMaskString() function described on page 100.
  5460.  
  5461.   Example:
  5462.  
  5463.   #include "window.h"
  5464.   #include <string.h>
  5465.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5466.   #define TELMASK "(___)___-____ ext:____"
  5467.   #define SSMASK  "___-__-____"
  5468.  
  5469.   WPOINTER w;
  5470.   char buffer[80];
  5471.   main()
  5472.   {
  5473.     int i,row,col;
  5474.     buffer[0] = 0;   /* Make sure first character is null */
  5475.     WindowInitializeSystem();
  5476.     WindowSaveInitial(0);
  5477.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5478.     WindowOpen(w);
  5479.     WindowDisplay(w,1,NOEFFECT);
  5480.     buffer[0] = 0;   /* Make sure first character is null */
  5481.     WindowWriteString(w,"Enter Your Telephone No.",1,1);
  5482.     WindowGetMaskString(w,2,1,buffer,TELMASK,' ',0,40,0,"40.");
  5483.     WindowWriteString(w,"You entered the following phone no:",3,1);
  5484.     WindowWriteString(w,buffer,4,1);
  5485.     GET_KEY();
  5486.     memset(buffer,0,sizeof(buffer));
  5487.     WindowWriteString(w,"Now Enter your Soc. Sec. Number:",6,1);
  5488.     WindowGetMaskString(w,7,1,buffer,SSMASK,' ',0,40,0,"40.");
  5489.     WindowWriteString(w,"You entered the following:",8,1);
  5490.     WindowWriteString(w,buffer,9,1);
  5491.   }
  5492.  
  5493.   If there are no errors, WindowGetMaskString() returns NO_ERROR.
  5494.   If there are errors, WindowGetMaskString() returns the following:
  5495.  
  5496.  Page 87                     The C Window Library                    Page 87
  5497.  
  5498.  
  5499.   BAD_WINDOW if the window does not exist.
  5500.  
  5501.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen())
  5502.  
  5503.   NO_HEAP_MEM if there is not enough memory to allocate for internal buffers.
  5504.  
  5505.  
  5506.  
  5507.  
  5508.   WindowGetMaskStringAttr()
  5509.   -------------------------
  5510.  
  5511.   The WindowGetMaskStringAttr() functions works the same way as
  5512.   WindowGetMaskString() except that WindowGetMaskStringAttr() allows you to
  5513.   specify a video attribute to use for the characters that are entered.  Here
  5514.   is the prototype:
  5515.  
  5516.   int WindowGetMaskStringAttr(WPOINTER w, int row, int col, char *buffer,
  5517.                               char *mask, int fillchar, int minchars,
  5518.                               int maxwidth, int options, int attr, char *regexp)
  5519.  
  5520.   Example:
  5521.  
  5522.   #include "window.h"
  5523.   #include <string.h>
  5524.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5525.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  5526.   #define TELMASK "(___)___-____ ext:____"
  5527.   #define SSMASK  "___-__-____"
  5528.   WPOINTER w;
  5529.   char buffer[80];
  5530.   main()
  5531.   {
  5532.     int i,row,col;
  5533.     buffer[0] = 0;   /* Make sure first character is null */
  5534.     WindowInitializeSystem();
  5535.     WindowSaveInitial(0);
  5536.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5537.     WindowOpen(w);
  5538.     WindowDisplay(w,1,NOEFFECT);
  5539.     buffer[0] = 0;   /* Make sure first character is null */
  5540.     WindowWriteString(w,"Enter Your Telephone No.",1,1);
  5541.     WindowGetMaskStringAttr(w,2,1,buffer,TELMASK,' ',0,40,0,REVERSE,"40.");
  5542.     WindowWriteString(w,"You entered the following phone no:",3,1);
  5543.     WindowWriteString(w,buffer,4,1);
  5544.     GET_KEY();
  5545.     memset(buffer,0,sizeof(buffer));
  5546.     WindowWriteString(w,"Now Enter your Soc. Sec. Number:",6,1);
  5547.     WindowGetMaskStringAttr(w,7,1,buffer,SSMASK,' ',0,40,0,REVERSE,"40.");
  5548.     WindowWriteString(w,"You entered the following:",8,1);
  5549.     WindowWriteString(w,buffer,9,1);
  5550.   }
  5551.  
  5552.  Page 88                     The C Window Library                    Page 88
  5553.  
  5554.   The return values for WindowGetMaskStringAttr() are the same as
  5555.   WindowGetMaskString().
  5556.  
  5557.  
  5558.   Getting Passwords
  5559.   -----------------
  5560.  
  5561.   The C Window Library also allows you to receive hidden input.  The functions
  5562.   to perform this are WindowGetPassword(), WindowGetMaskPassword(),
  5563.   WindowGetPasswordAttr() and WindowGetMaskPasswordAttr().  These functions are
  5564.   similar to the other WindowGetxx() functions. except that a character
  5565.   specified by you is displayed instead of the actual key pressed.
  5566.  
  5567.  
  5568.   WindowGetPassword()
  5569.   -------------------
  5570.  
  5571.   The WindowGetPassword() function gets hidden input from a window.  Here is
  5572.   the prototype:
  5573.  
  5574.   int WindowGetPassword(WPOINTER w, int row, int col, char *buffer,
  5575.                         int fillchar, int passchar, int minchars, int maxwidth,
  5576.                         int options, char *regexp)
  5577.  
  5578.   The first argument is the window pointer.  The second and third arguments are
  5579.   the (row,col) to start receiving input.  The fourth argument is the buffer
  5580.   to store the inputted characters.  The fifth argument is the character to use
  5581.   to fill empty input positions on the screen.  The sixth argument is the
  5582.   character to display to the screen when a key is pressed.  The last four
  5583.   arguments are the same as the WindowGetString()'s last four arguments.
  5584.  
  5585.   For example, if the user typed "ABCDEF", and the passchar is '*', the screen
  5586.   will display "******".  Notice the asterisk is displayed instead of the
  5587.   actual characters inputted.
  5588.  
  5589.   Example Program:
  5590.  
  5591.   #include "window.h"
  5592.   #include <string.h>
  5593.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5594.  
  5595.   WPOINTER w;
  5596.   char buffer[80];
  5597.   main()
  5598.   {
  5599.     int i,row,col;
  5600.     buffer[0] = 0;   /* Make sure first character is null */
  5601.     WindowInitializeSystem();
  5602.     WindowSaveInitial(0);
  5603.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5604.     WindowOpen(w);
  5605.     WindowDisplay(w,1,NOEFFECT);
  5606.     buffer[0] = 0;   /* Make sure first character is null */
  5607.  
  5608.  Page 89                     The C Window Library                    Page 89
  5609.  
  5610.     WindowWriteString(w,"Enter A Password",1,1);
  5611.     WindowGetPassword(w,2,1,buffer,' ','*',0,40,0,"40.");
  5612.     WindowWriteString(w,"You entered the following:",3,1);
  5613.     WindowWriteString(w,buffer,4,1);
  5614.   }
  5615.  
  5616.   The return values for WindowGetPassword() are the same as
  5617.   WindowGetMaskString().
  5618.  
  5619.  
  5620.  
  5621.   WindowGetPasswordAttr()
  5622.   -----------------------
  5623.  
  5624.   The WindowGetPasswordAttr() function is the same as WindowGetPassword() except
  5625.   that a video attribute is specified for the input characters.  Here is the
  5626.   prototype:
  5627.  
  5628.   int WindowGetPasswordAttr(WPOINTER w, int row, int col, char *buffer,
  5629.                             int fillchar, int passchar, int minchars,
  5630.                             int maxwidth, int options, int attr, char *regexp)
  5631.  
  5632.   Please note that the attribute argument is the next to last argument in the
  5633.   function.
  5634.  
  5635.  
  5636.   Example Program:
  5637.  
  5638.   #include "window.h"
  5639.   #include <string.h>
  5640.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5641.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  5642.  
  5643.   WPOINTER w;
  5644.   char buffer[80];
  5645.   main()
  5646.   {
  5647.     int i,row,col;
  5648.     buffer[0] = 0;   /* Make sure first character is null */
  5649.     WindowInitializeSystem();
  5650.     WindowSaveInitial(0);
  5651.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5652.     WindowOpen(w);
  5653.     WindowDisplay(w,1,NOEFFECT);
  5654.     buffer[0] = 0;   /* Make sure first character is null */
  5655.     WindowWriteString(w,"Enter A Password",1,1);
  5656.     WindowGetPasswordAttr(w,2,1,buffer,' ','*',0,40,0,REVERSE,"40.");
  5657.     WindowWriteString(w,"You entered the following:",3,1);
  5658.     WindowWriteString(w,buffer,4,1);
  5659.   }
  5660.  
  5661.   The return values for WindowGetPasswordAttr() are the same as
  5662.   WindowGetMaskString().
  5663.  
  5664.  Page 90                     The C Window Library                    Page 90
  5665.  
  5666.   WindowGetMaskPassword()
  5667.   -----------------------
  5668.  
  5669.   The WindowGetMaskPassword() function works just like WindowGetPassword()
  5670.   except that a character mask is supplied.  Here is the prototype:
  5671.  
  5672.  
  5673.   int WindowGetMaskPassword(WPOINTER w, int row, int col, char *buffer,
  5674.                             char *mask, int fillchar, int passchar,
  5675.                             int minchars, int maxwidth, int options,
  5676.                             char *regexp)
  5677.  
  5678.  
  5679.   Example:
  5680.  
  5681.  
  5682.   #include "window.h"
  5683.   #include <string.h>
  5684.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5685.   #define CREDITCARDMASK "____-____-____-____"
  5686.  
  5687.   WPOINTER w;
  5688.   char buffer[80];
  5689.   main()
  5690.   {
  5691.     int i,row,col;
  5692.     buffer[0] = 0;   /* Make sure first character is null */
  5693.     WindowInitializeSystem();
  5694.     WindowSaveInitial(0);
  5695.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5696.     WindowOpen(w);
  5697.     WindowDisplay(w,1,NOEFFECT);
  5698.     buffer[0] = 0;   /* Make sure first character is null */
  5699.     WindowWriteString(w,"Enter A Credit Card #",1,1);
  5700.     WindowGetMaskPassword(w,2,1,buffer,CREDITCARDMASK,' ','*',0,40,0,"40.");
  5701.     WindowWriteString(w,"You entered the following:",3,1);
  5702.     WindowWriteString(w,buffer,4,1);
  5703.   }
  5704.  
  5705.  
  5706.   The return values for WindowGetMaskPassword() are the same as
  5707.   WindowGetMaskString().
  5708.  
  5709.  
  5710.  
  5711.  
  5712.   WindowGetMaskPasswordAttr()
  5713.   ---------------------------
  5714.  
  5715.   The WindowGetMaskPasswordAttr() function works just like
  5716.   WindowGetMaskPassword() except that a video attribute is supplied. Here is
  5717.   the prototype:
  5718.  
  5719.  
  5720.  Page 91                     The C Window Library                    Page 91
  5721.  
  5722.   int WindowGetMaskPasswordAttr(WPOINTER w, int row, int col, char *buffer,
  5723.                                 char *mask, int fillchar, int passchar,
  5724.                                 int minchars, int maxwidth, int options,
  5725.                                 int attr, char *regexp)
  5726.  
  5727.  
  5728.   Example:
  5729.  
  5730.  
  5731.   #include "window.h"
  5732.   #include <string.h>
  5733.   #define NORM    CREATE_VIDEO_ATTRIBUTE(black,white)
  5734.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  5735.   #define CREDITCARDMASK "____-____-____-____"
  5736.  
  5737.   WPOINTER w;
  5738.   char buffer[80];
  5739.   main()
  5740.   {
  5741.     int i,row,col;
  5742.     buffer[0] = 0;   /* Make sure first character is null */
  5743.     WindowInitializeSystem();
  5744.     WindowSaveInitial(0);
  5745.     w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  5746.     WindowOpen(w);
  5747.     WindowDisplay(w,1,NOEFFECT);
  5748.     buffer[0] = 0;   /* Make sure first character is null */
  5749.     WindowWriteString(w,"Enter A Credit Card #",1,1);
  5750.     WindowGetMaskPasswordAttr(w,2,1,buffer,CREDITCARDMASK,' ','*',0,40,0,
  5751.                               REVERSE, "40.");
  5752.     WindowWriteString(w,"You entered the following:",3,1);
  5753.     WindowWriteString(w,buffer,4,1);
  5754.   }
  5755.  
  5756.  
  5757.   The return values for WindowGetMaskPasswordAttr() are the same as
  5758.   WindowGetMaskString().
  5759.  
  5760.  
  5761.  
  5762.  
  5763.  
  5764.  
  5765.  
  5766.  
  5767.  
  5768.  
  5769.  
  5770.  
  5771.  
  5772.  
  5773.  
  5774.  
  5775.  
  5776.  Page 92                     The C Window Library                    Page 92
  5777.  
  5778.                         UNDEFINED KEYSTROKE PROCESSING
  5779.                         ------------------------------
  5780.  
  5781.   Another powerful feature of the input functions is that you can call a
  5782.   function for keys that are not in the current key definitions.  For instance,
  5783.   say you want the Enter key AND Control-R to mean accept the input.  Since
  5784.   there is only room for one definition for accept input, you can write a
  5785.   function that checks for the Control-R key, and return a number to the input
  5786.   manager as to what action to take.
  5787.  
  5788.  
  5789.   The undef_fkey_func and undef_akey_func function pointers
  5790.   ---------------------------------------------------------
  5791.  
  5792.   There are two global variables, undef_fkey_func and undef_akey_func.  Both of
  5793.   these function pointers are defined in the file key.h.  These two variables
  5794.   are pointers to functions that return an integer.  By setting these functions
  5795.   to point to your own functions, you can process undefined keystrokes yourself
  5796.   and return to the input manager what action to take.
  5797.  
  5798.   The undef_fkey_func is used to define keys that are not normal ASCII keys.
  5799.   For instance, Control key and Alt key combinations, the F-keys, PgDn and PgUp,
  5800.   etc.  The undef_akey_func is used to define normal ASCII keys (keys with ASCII
  5801.   values between 32 and 255, inclusive).
  5802.  
  5803.   Whenever an undefined key is encountered, the input manager will pass the
  5804.   string that has been currently entered, the current key pressed, and the
  5805.   current position number of the character being processed to your function.
  5806.   The prototype for this function is as follows:
  5807.  
  5808.             int (*undef_fkey_func)(char *str,/* string currently entered */
  5809.                                     int key,  /* key that was pressed */
  5810.                                     int pos)  /* position number of current
  5811.                                                 character being processed */
  5812.  
  5813.   The prototype to the undef_akey_func is similar to the one above.
  5814.  
  5815.   The str is a pointer to a null-terminated string of characters that has been
  5816.   currently entered.  For instance, if the string currently entered is
  5817.  
  5818.               ABC123
  5819.  
  5820.   str will point to "ABC123".   The position number is the number of the current
  5821.   character that the cursor is on.  The first character is at position number 0,
  5822.   the second character in the input field is 1, etc.  If there is an input mask
  5823.   (as in WindowGetMaskString() and WindowGetMaskStringAttr()) the position
  5824.   number does not include any characters that are used to create the non-input
  5825.   positions.  For instance:
  5826.  
  5827.                       "__/__/__ "
  5828.                        01 23 45
  5829.   The numbers under the mask are the position numbers for each character.
  5830.  
  5831.  
  5832.  Page 93                     The C Window Library                    Page 93
  5833.  
  5834.   You should use the values defined in the header file "keycodes.h" if you
  5835.   want to check for non-ascii keys.  This will ensure that you are properly
  5836.   checking the keystroke desired.  For instance, if you want to check if the
  5837.   key pressed was the Page Up key, use the constant PGUP defined in
  5838.   keycodes.h.
  5839.  
  5840.  
  5841.  
  5842.   Return Values To The Input Manager
  5843.   ----------------------------------
  5844.  
  5845.   When writing your function you must return an integer to the input manager.
  5846.   This integer will inform the input manager as to what action to take.  Here
  5847.   are a list of the return values and what they inform the input manager:
  5848.  
  5849.  
  5850.     Return                         Action to
  5851.     Value                            Take
  5852.     ------                         ---------
  5853.  
  5854.     DONT_PROCESS           Do not Process keystroke and continue getting
  5855.                            input.
  5856.     MOVE_CURSOR_LEFT       Move cursor left.
  5857.     MOVE_CURSOR_RIGHT      Move cursor right.
  5858.     DELETE_AT_CURSOR       Delete character at cursor.
  5859.     TOGGLE_INSERT          Toggle Insert/Overwrite mode.
  5860.     DESTRUCT_BACKSPACE     Destructive Backspace.
  5861.     ACCEPT_INPUT           Accept Input and return string.
  5862.     ACCEPT_DEFAULT         Accept default string and return.
  5863.     ERASE_INPUT            Erase Input and go to first character in input field.
  5864.     GOTO_FIRST             Go to first input character in field.
  5865.     GOTO_LAST              Move cursor to last input character in field.
  5866.     INSERT_CHARACTER       Accept character as valid and insert it at the
  5867.                            current cursor position.
  5868.  
  5869.  
  5870.   The last option (INSERT_CHARACTER) only applies to the function pointed to
  5871.   by undef_akey_func.
  5872.  
  5873.   These user-defined functions can do anything, not just process keystrokes.
  5874.   For instance, if you want F1 to be a help key, where the help function is
  5875.   in a function called do_help() you must make sure that:
  5876.  
  5877.   a) the F1 key is undefined (not defined in the window_edit_key array)
  5878.   b) the undef_fkey_func function pointer points to your function
  5879.   c) return an integer to the input manager from your function.
  5880.  
  5881.   Here is a typical way that this would be set up:
  5882.  
  5883.  
  5884.  
  5885.  
  5886.  
  5887.  
  5888.  Page 94                     The C Window Library                    Page 94
  5889.  
  5890.   #include "window.h"
  5891.  
  5892.   /*  ... Other #includes and #defines */
  5893.  
  5894.   int do_help();           /* define help function */
  5895.  
  5896.   main()
  5897.   {
  5898.     WindowInitializeSystem();
  5899.  
  5900.     /* ...Some code */
  5901.     undef_fkey_func = do_help;       /* point function pointer to do_help */
  5902.     WindowGetString(/*  ... Parameters */);    /* call input function */
  5903.  
  5904.     /* ... Other code */
  5905.   }
  5906.  
  5907.  
  5908.   int do_help(char *str, int ch, int pos)
  5909.   {
  5910.     if (ch == F1)                     /* check for F1 */
  5911.     {
  5912.        /* help function goes here */
  5913.  
  5914.     }
  5915.     return DONT_PROCESS;  /* make sure input manager does not process this
  5916.                              or any other undefined keystroke */
  5917.   }
  5918.  
  5919.  
  5920.   With this flexibility in the input functions, you can totally control how
  5921.   input is handled.
  5922.  
  5923.  
  5924.  
  5925.  
  5926.  
  5927.  
  5928.  
  5929.  
  5930.  
  5931.  
  5932.  
  5933.  
  5934.  
  5935.  
  5936.  
  5937.  
  5938.  
  5939.  
  5940.  
  5941.  
  5942.  
  5943.  
  5944.  Page 95                     The C Window Library                    Page 95
  5945.  
  5946.                                  INPUT OPTIONS
  5947.                                  -------------
  5948.  
  5949.   In the previous examples, the available options were discussed briefly.
  5950.   These options provide further control of the input functions.  Here is a list
  5951.   of the options that are available:
  5952.  
  5953.           Option                   Definition
  5954.           ------                   ----------
  5955.           UPPERCASE             Translates and displays lower case to upper
  5956.                                 case.
  5957.  
  5958.           LOWERCASE             Translates and displays upper case to lower
  5959.                                 case.
  5960.  
  5961.           CHECKSPACES           Spaces are counted when determining whether
  5962.                                 the minimum number of characters are entered.
  5963.  
  5964.           ENHANCEDKEY           Use the enhanced keyboard keys and
  5965.                                 distinguish between keypad keys and separate
  5966.                                 cursor pad keys.  Also detect F11 and F12 keys.
  5967.  
  5968.           CHECKREGEXP           Check to see if all characters entered agree
  5969.                                 with the regular expression provided.
  5970.  
  5971.           AUTORETURN            Automatically accept the input when a character
  5972.                                 in the last input position is entered.
  5973.  
  5974.  
  5975.  
  5976.  
  5977.   UPPERCASE
  5978.   ---------
  5979.   The UPPERCASE option converts and displays all lower case letters to upper
  5980.   case while the user is inputting characters.
  5981.  
  5982.  
  5983.  
  5984.  
  5985.   LOWERCASE
  5986.   ---------
  5987.   The LOWERCASE option converts and displays all upper case letters to lower
  5988.   case while the user is inputting characters.
  5989.  
  5990.  
  5991.  
  5992.  
  5993.   CHECKSPACES
  5994.   -----------
  5995.   The CHECKSPACES option will cause the input manager to count any embedded
  5996.   spaces when determining whether the minimum number of characters are reached.
  5997.   Trailing spaces are counted only if the user explicitly put them there.
  5998.  
  5999.  
  6000.  
  6001.  Page 96                     The C Window Library                    Page 96
  6002.  
  6003.   ENHANCEDKEY
  6004.   -----------
  6005.   The ENHANCEDKEY option will distinguish between the cursor keys on the keypad
  6006.   from the dedicated cursor keys on the enhanced keyboards as well as the Ins,
  6007.   Home, Del, PgUp and PgDn keys.  Also the F11 and F12 keys will be detected.
  6008.  
  6009.  
  6010.  
  6011.  
  6012.   CHECKREGEXP and the reg_exp_error_func function pointer
  6013.   -------------------------------------------------------
  6014.  
  6015.   The CHECKREGEXP option will check to make sure that every character inputted
  6016.   is a valid character according to the regular expression.  When inserting or
  6017.   deleting characters during input, characters may be moved left or right
  6018.   depending on whether the input is in insert or overwrite mode.  When the
  6019.   characters are moved, the resulting pattern of characters may not match the
  6020.   regular expression desired.  For instance, if the regular expression is
  6021.   "3[A-Z]2[0-9]", meaning 3 characters between A and Z followed by 2 characters
  6022.   between 0 and 9, and the current input entered is as follows :
  6023.  
  6024.                  ABC34
  6025.  
  6026.   If the cursor is currently under the 'C', the delete key is pressed, and
  6027.   the input is currently in insert mode, the '34' will be moved one character to
  6028.   the left.  The resulting input would then look like this:
  6029.  
  6030.                  AB34
  6031.  
  6032.   As you can see, the input does not match the regular expression "3[A-Z]2[0-9]"
  6033.   because the '3' is in a position that should be occupied by a letter.  When
  6034.   the CHECKREGEXP option is chosen, each position is checked when the user wants
  6035.   to accept the string, not while the user is entering characters.  If the
  6036.   input is not OK, the input manager will not accept the string. You can
  6037.   override this by setting the reg_exp_error_func function pointer.
  6038.  
  6039.  
  6040.   The global function pointer reg_exp_error_func is prototyped as follows:
  6041.  
  6042.      int (*reg_exp_error_func)(char *buf, int nomatch);
  6043.  
  6044.   where buf is the current string entered, and nomatch is the position of the
  6045.   first non-matching character that did not match the regular expression.  The
  6046.   first character of the string is at position 0.
  6047.  
  6048.   Your function must return an integer back as to what to do.  There are two
  6049.   valid return values, namely ACCEPT_INPUT and DONT_PROCESS.  A return value of
  6050.   ACCEPT_INPUT will accept the input, even though all of the characters do not
  6051.   match the regular expression.  DONT_PROCESS tells the input manager to keep
  6052.   getting input.  Here is an example:
  6053.  
  6054.  
  6055.  
  6056.  
  6057.  Page 97                     The C Window Library                    Page 97
  6058.  
  6059.     int my_check_func();
  6060.     main()
  6061.     {
  6062.         ...
  6063.        reg_exp_error_func = my_check_func;
  6064.  
  6065.        WindowGetString(other parameters, CHECKREGEXP,"[A-Z][0-9]");
  6066.  
  6067.         ...
  6068.     }
  6069.  
  6070.     int my_check_func(char *buf, int mistake_pos)
  6071.     {
  6072.       /* Assume w is initialized and open for writing */
  6073.  
  6074.       WindowPrintf(w,
  6075.               "Illegal input for %s.  Illegal character at position %d",buf,
  6076.                mistake_pos);
  6077.       GET_KEY();
  6078.       WindowHide(w,NOEFFECT);
  6079.       return DONT_PROCESS;
  6080.     }
  6081.  
  6082.  
  6083.   The above example shows a function called my_check_func() which will be
  6084.   called when the input manager detects that all of the characters in the
  6085.   buffer buf do not match the regular expression.  The function displays a
  6086.   message in a window and waits for a key to be pressed.  Then the function
  6087.   returns DONT_PROCESS back to the input manager.
  6088.  
  6089.  
  6090.  
  6091.  
  6092.   AUTORETURN
  6093.   ----------
  6094.  
  6095.   The AUTORETURN will automatically accept the input and return to the calling
  6096.   function if the cursor is on the last input position and the user types a
  6097.   valid character.  Of course, if CHECKREGEXP is on, the input is checked for
  6098.   validity.
  6099.  
  6100.  
  6101.   Examples of Input Options
  6102.   -------------------------
  6103.  
  6104.   Examples:
  6105.  
  6106.     a) WindowGetString(w,1,1,str,' ',1,1,UPPERCASE,"[YyNn]");
  6107.  
  6108.     b) WindowGetString(w,1,1,str,' ',1,1,LOWERCASE,"[YyNn]");
  6109.  
  6110.     c) WindowGetStringAttr(w,2,1,str,' ',CREATE_VIDEO_ATTRIBUTE(black,white),1,
  6111.                            1,UPPERCASE | AUTORETURN,"[YyNn]");
  6112.  
  6113.  Page 98                     The C Window Library                    Page 98
  6114.  
  6115.     d) WindowGetString(w,1,1,str,' ',10,10,UPPERCASE | ENHANCEDKEY,"10.");
  6116.  
  6117.     e) WindowGetString(w,1,1,str,' ',20,10,CHECKREGEXP,"10[A-Z]10[0-9]");
  6118.  
  6119.  
  6120.  
  6121.   Example a) gets one character and will automatically set this character to
  6122.              upper case.
  6123.  
  6124.           b) same as a) except character is converted to lower case.
  6125.  
  6126.           c) converts one character to uppercase and automatically accepts the
  6127.              input because the input cursor was on the last input position.
  6128.              Note the use of the bitwise OR (|) to set multiple options.
  6129.  
  6130.           d) Converts the input to uppercase and treats extra keys on an
  6131.              enhanced keyboard as different than their "normal" keys.
  6132.  
  6133.           e) On accepting of the input field, the input is checked to see if
  6134.              every position on the input field is checked to see if it matches
  6135.              the regular expression.
  6136.  
  6137.  
  6138.  
  6139.  
  6140.   THE num_chars_entered_func FUNCTION POINTER
  6141.   -------------------------------------------
  6142.  
  6143.   If the number of characters entered is not enough to satisfy the minimum
  6144.   number of characters allowed, by default the input manager will not return
  6145.   until the required number of characters is entered.  However, a global
  6146.   function pointer can be assigned to a user-written function that will
  6147.   be called when the input manager detects that the minimum number of
  6148.   characters was not reached.  The function pointer num_chars_entered_func is
  6149.   prototyped as follows:
  6150.  
  6151.           int (*num_chars_entered_func)(char *buf, int minchars);
  6152.  
  6153.   where buf is the current string that is entered, and minchars is the minimum
  6154.   number of characters to expect.
  6155.  
  6156.   Your function must return an integer back as to what to do.  There are two
  6157.   valid return values, namely ACCEPT_INPUT and DONT_PROCESS.  A return value of
  6158.   ACCEPT_INPUT will accept the input, even though the minimum number of
  6159.   characters was not reached.  DONT_PROCESS tells the input manager to keep
  6160.   getting input.  Here is an example:
  6161.  
  6162.  
  6163.  
  6164.  
  6165.  
  6166.  
  6167.  
  6168.  
  6169.  Page 99                     The C Window Library                    Page 99
  6170.  
  6171.     int my_min_func();
  6172.     main()
  6173.     {
  6174.  
  6175.         ...
  6176.        num_chars_entered_func = my_min_func;
  6177.         ...
  6178.     }
  6179.  
  6180.     int my_min_func(char *buf, int m)
  6181.     {
  6182.  
  6183.       /* Assume w is initialized and open for writing */
  6184.  
  6185.       WindowWriteString(w,"Not enough characters!",1,1);
  6186.       GET_KEY();
  6187.       WindowHide(w,NOEFFECT);
  6188.       return DONT_PROCESS;
  6189.     }
  6190.  
  6191.   The above example shows a function called my_min_func() which will be called
  6192.   when the input manager detects that the number of characters in the buffer
  6193.   buf, does not meet the minimum requirements.  The function displays a message
  6194.   in a window and waits for a key to be pressed.  Then the function returns
  6195.   DONT_PROCESS back to the input manager.
  6196.  
  6197.  
  6198.  
  6199.  
  6200.   OTHER INPUT RELATED FUNCTIONS
  6201.   -----------------------------
  6202.  
  6203.   There are other input related functions that you can use to translate strings
  6204.   into their character mask equivalents and vice-versa.
  6205.  
  6206.  
  6207.   TranslateStringToMaskString()
  6208.   -----------------------------
  6209.  
  6210.   This TranslateStringToMaskString() function takes a string and either places
  6211.   spaces, or the actual mask character between the characters in the string.  A
  6212.   pointer to the translated string is returned.  Here is the prototype:
  6213.  
  6214.     char *TranslateStringToMaskString(char *buffer, char *mask, char *buf2,
  6215.                                       int maskchar, int flag)
  6216.  
  6217.   The first argument is a pointer to the string to translate.  The second
  6218.   argument is the mask string to use. The third argument is a pointer to the
  6219.   buffer that will store the translated string.  The fourth argument is the
  6220.   mask character that is to be used.  This character determines where the input
  6221.   positions are.  The flag argument tells whether to include spaces between
  6222.   each component, or to use the character in the mask.
  6223.  
  6224.  
  6225.  Page 100                     The C Window Library                    Page 100
  6226.  
  6227.   You must make sure that buf2 is big enough to hold the translated string.
  6228.  
  6229.   The string length of the mask determines how far to translate the string.  If
  6230.   the mask string is shorter than the string to translate, the string is
  6231.   truncated up to the last character in the mask.  If the string to translate
  6232.   runs out of characters before the mask has been totally scanned, the extra
  6233.   characters in buf2 will either be spaces, or the characters in the mask (not
  6234.   the mask character specified in argument 4) will be copied over.
  6235.  
  6236.  
  6237.   Example:
  6238.  
  6239.       #include "window.h"
  6240.  
  6241.       #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6242.       #define DATEMASK "__/__/__"
  6243.       char buf1[] = "123456";
  6244.       char buf2[9];
  6245.       WPOINTER w;
  6246.  
  6247.       main()
  6248.       {
  6249.         WindowInitializeSystem();
  6250.         WindowSaveInitial(0);
  6251.         w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6252.         WindowOpen(w);
  6253.         WindowDisplay(w,1,NOEFFECT);
  6254.         TranslateStringToMaskString(buf1,DATEMASK,buf2,'_',0);
  6255.         WindowPrintf(w,
  6256.             "The original string is %s\nThe translated string is %s\n",
  6257.              buf1,buf2);
  6258.         TranslateStringToMaskString(buf1,DATEMASK,buf2,'_',1);
  6259.         WindowPrintf(w,
  6260.             "The original string is %s\nThe translated string is %s\n",
  6261.              buf1,buf2);
  6262.       }
  6263.  
  6264.  
  6265.   The example above takes the string "123456" with the mask of "__/__/__".  The
  6266.   results of a translate with a flag of 0, and with a flag value of 1, is
  6267.   displayed in window w.
  6268.  
  6269.  
  6270.   The return value for TranslateStringToMaskString() is the pointer to the
  6271.   buffer that holds the translated string.  This string is automatically null
  6272.   terminated.
  6273.  
  6274.  
  6275.  
  6276.  
  6277.  
  6278.  
  6279.  
  6280.  
  6281.  Page 101                     The C Window Library                    Page 101
  6282.  
  6283.   TranslateMaskStringToString()
  6284.   -----------------------------
  6285.  
  6286.   This TranslateMaskStringToString() function does the opposite of
  6287.   TranslateStringToMaskString().  This function takes a string that has been
  6288.   translated with the TranslateStringToMaskString() or contains mask characters
  6289.   and returns the string without the extra characters.  Here is the prototype:
  6290.  
  6291.     char *TranslateMaskStringToString(char *buffer, char *mask, char *buf2,
  6292.                                       int maskchar)
  6293.  
  6294.   The first argument is a pointer to the translated string.  The second argument
  6295.   is the mask string to use. The third argument is a pointer to the buffer that
  6296.   will store the resulting string.  The fourth argument is the mask character
  6297.   that is to be used.  This character determines where the input positions are.
  6298.  
  6299.   You must make sure that buf2 is big enough to hold the new string.
  6300.  
  6301.   The translation stops when either the end of the buffer is reached, or the end
  6302.   of the mask string is reached.
  6303.  
  6304.  
  6305.   Example:
  6306.  
  6307.       #include "window.h"
  6308.       #include <string.h>
  6309.  
  6310.       #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  6311.       #define DATEMASK "__/__/__"
  6312.       char buf1[] = "12/34/56";
  6313.       char buf2[9];
  6314.       WPOINTER w;
  6315.  
  6316.       main()
  6317.       {
  6318.         memset(buf2,0,sizeof(buf2));
  6319.         WindowInitializeSystem();
  6320.         WindowSaveInitial(0);
  6321.         w = WindowInitialize(BORDER,1,1,40,10,NORM,NORM,SINGLEBOX);
  6322.         WindowOpen(w);
  6323.         WindowDisplay(w,1,NOEFFECT);
  6324.         TranslateMaskStringToString(buf1,DATEMASK,buf2,'_');
  6325.         WindowPrintf(w,"The original string is %s\n"
  6326.                        "The untranslated string is %s\n", buf1,buf2);
  6327.       }
  6328.  
  6329.  
  6330.   The example above takes the string "12/34/56" with the mask of "__/__/__".
  6331.   The results of the translation is displayed in window w.
  6332.  
  6333.   The return value for TranslateMaskStringToString() is the pointer to the
  6334.   buffer that holds the translated string.  This string is automatically null
  6335.   terminated.
  6336.  
  6337.  Page 102                     The C Window Library                    Page 102
  6338.                              VIRTUAL WINDOWS
  6339.                              ---------------
  6340.  
  6341.   A virtual window can be thought of as a rectangular area filled with text.
  6342.   This rectangular region can be broken up into rows and columns, just as a
  6343.   normal window can be divided into rows and columns.  The differences between
  6344.   a virtual window and a regular window is that a virtual window's dimensions
  6345.   can be larger than the physical screen, and a virtual window is not displayed
  6346.   on the screen.  Then what good is it if you cannot display it?  You use
  6347.   regular windows to display portions of the virtual window.  If a regular
  6348.   window is used to view a virtual window, the regular window is called a
  6349.   viewport.  With this method, you can use a viewport to display a virtual
  6350.   window, and then 'pan' around, viewing different sections of the virtual
  6351.   window.  Text editors use this method to display files.  Scrolling popup
  6352.   menus also use virtual windows.
  6353.  
  6354.   With The C Window Library, you can create virtual windows of any size, up to
  6355.   available user memory.  You can have a maximum of 256 virtual windows defined
  6356.   at the same time.
  6357.  
  6358.  
  6359.  
  6360.   Using Windows as Viewports
  6361.   --------------------------
  6362.  
  6363.   If text is written to a virtual window, and there is a viewport that is
  6364.   displaying the portion of the virtual window that has changed, the viewport
  6365.   will show the change immediately.  You do not have to "repaint" or "refresh"
  6366.   the viewport to show an updated change.  That is handled internally in The C
  6367.   Window Library.  However, there is an option that will "freeze" a viewport,
  6368.   i.e. will not update automatically, if there is a change in the virtual
  6369.   window.  When the viewport is unfrozen, the changes to the virtual window are
  6370.   than displayed.
  6371.  
  6372.  
  6373.  
  6374.  
  6375.   Attributed and Non-Attributed Virtual Windows
  6376.   ---------------------------------------------
  6377.  
  6378.   There are two types of virtual windows.  You can have either a virtual window
  6379.   with its own video attributes or a virtual window which gets its video
  6380.   attributes from the viewport that is displaying the virtual window.
  6381.   Virtual windows without attributes use half as much memory as a virtual
  6382.   window with attributes, but attributed virtual window's are more flexible.
  6383.   For instance, lets say you have highlighted some text in the virtual window.
  6384.   If the virtual window is not attributed, you must write the highlight
  6385.   attribute to the viewport window using one of the window functions
  6386.   (WindowWriteStringAttr() for example), since the virtual window does not have
  6387.   the capacity to store the video attribute.  If you were to scroll the
  6388.   highlighted portion out of the viewport, you lose the highlight attribute,
  6389.   and must call the window function again to highlight the text, if the text is
  6390.   displayed again in the viewport.  With an attributed virtual window, you
  6391.  
  6392.  
  6393.  Page 103                     The C Window Library                    Page 103
  6394.  
  6395.   write the attributes to the virtual window.  Since the attributes are stored
  6396.   in the virtual window structure itself, the attributes are retained until you
  6397.   change them.
  6398.  
  6399.   From this point on, virtual windows without attributes are called NOATTRIBUTE
  6400.   virtual windows.  Virtual windows with attributes will be called ATTRIBUTE
  6401.   virtual windows.
  6402.  
  6403.  
  6404.   Virtual Window's Logical Cursor
  6405.   -------------------------------
  6406.  
  6407.   Each virtual window has its own logical cursor.  This cursor is updated
  6408.   automatically when calling VirtualPrintf(), and VirtualWriteCharacter()
  6409.   functions, or can be updated manually by calling the VirtualMoveCursor()
  6410.   function.  This cursor is independent of the screen cursor.
  6411.  
  6412.  
  6413.  
  6414.  
  6415.  
  6416.  
  6417.  
  6418.  
  6419.  
  6420.  
  6421.  
  6422.  
  6423.  
  6424.  
  6425.  
  6426.  
  6427.  
  6428.  
  6429.  
  6430.  
  6431.  
  6432.  
  6433.  
  6434.  
  6435.  
  6436.  
  6437.  
  6438.  
  6439.  
  6440.  
  6441.  
  6442.  
  6443.  
  6444.  
  6445.  
  6446.  
  6447.  
  6448.  
  6449.  Page 104                     The C Window Library                    Page 104
  6450.  
  6451.                            CREATING VIRTUAL WINDOWS
  6452.                            ------------------------
  6453.  
  6454.   The section will discuss creating virtual windows using the
  6455.   VirtualInitialize() function.
  6456.  
  6457.  
  6458.   VirtualInitialize()
  6459.   -------------------
  6460.  
  6461.   Virtual windows are created by calling the VirtualInitialize() function.
  6462.   Here is the prototype:
  6463.  
  6464.    VWPOINTER VirtualInitialize(int vwtype, unsigned nrows, unsigned ncols,
  6465.                                int attr)
  6466.  
  6467.   The VirtualInitialize() function returns a pointer to a virtual window
  6468.   structure (a VWPOINTER).  The first argument to VirtualInitialize() tells
  6469.   whether the virtual window will or will not have its own video attributes.
  6470.   If this argument is NOATTRIBUTE, the virtual window will not have attributes,
  6471.   otherwise if it is ATTRIBUTE, the virtual window will have its own
  6472.   attributes.  The second argument is the number of rows of the virtual window.
  6473.   The third argument is the number of columns.  The fourth argument is the
  6474.   attribute to use for the virtual window.  This argument is ignored if the
  6475.   virtual window is NOATTRIBUTE.
  6476.  
  6477.    Example:
  6478.  
  6479.    #include "window.h"
  6480.    #include <stdio.h>
  6481.  
  6482.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6483.    VWPOINTER vw1,          /* virtual window pointers */
  6484.              vw2;
  6485.    main()
  6486.    {
  6487.      WindowInitializeSystem();
  6488.      /* set up a NOATTRIBUTE virtual window */
  6489.      vw1 = VirtualInitialize(NOATTRIBUTE,  /* virtual window type */
  6490.                              30,             /* Number of rows */
  6491.                              80,             /* Number of cols */
  6492.                              0);             /* Attribute      */
  6493.      /* set up an ATTRIBUTE virtual window */
  6494.      vw2 = VirtualInitialize(ATTRIBUTE,       /* virtual window type */
  6495.                              30,               /* Number of rows */
  6496.                              100,              /* Number of cols */
  6497.                              NORM);            /* Attribute      */
  6498.      if (vw1 == (VWPOINTER)0 ||
  6499.          vw2 == (VWPOINTER)0 ) /* Check if allocation worked */
  6500.        printf("Error in allocating virtual window.  The error number is %d",
  6501.                window_error_code);
  6502.    }
  6503.  
  6504.  
  6505.  Page 105                     The C Window Library                    Page 105
  6506.  
  6507.   In the above program, the VirtualInitialize() function is called.  This
  6508.   function allocates memory for the virtual window, and does other
  6509.   initializations.  Once this function is called, you can write to and read
  6510.   characters from the virtual window.
  6511.  
  6512.   Notice that the first argument to VirtualInitialize() is either the constant
  6513.   NOATTRIBUTE or ATTRIBUTE.
  6514.  
  6515.   Also note that there is a check to see whether the virtual windows could be
  6516.   allocated.   If there are no errors, VirtualInitialize() returns a valid
  6517.   VWPOINTER.  If there are errors, VirtualInitialize() returns a null VWPOINTER
  6518.   and sets the global variable window_error_code to one of the following:
  6519.  
  6520.   NO_HEAP_MEM if there is not enough memory to allocate for the virtual window.
  6521.  
  6522.   MAX_V_WINDOW if there are already 256 virtual windows defined.
  6523.  
  6524.  
  6525.  
  6526.  
  6527.  
  6528.  
  6529.  
  6530.  
  6531.  
  6532.  
  6533.  
  6534.  
  6535.  
  6536.  
  6537.  
  6538.  
  6539.  
  6540.  
  6541.  
  6542.  
  6543.  
  6544.  
  6545.  
  6546.  
  6547.  
  6548.  
  6549.  
  6550.  
  6551.  
  6552.  
  6553.  
  6554.  
  6555.  
  6556.  
  6557.  
  6558.  
  6559.  
  6560.  
  6561.  Page 106                     The C Window Library                    Page 106
  6562.  
  6563.                    ASSIGNING VIEWPORTS AND CLOSING VIEWPORTS
  6564.                    -----------------------------------------
  6565.  
  6566.   For a virtual window to have any useful purpose, it should be displayed on
  6567.   the screen.  However the virtual window may be larger than the physical
  6568.   screen.  The problem is solved by using normal windows to display parts of
  6569.   the virtual window.
  6570.  
  6571.  
  6572.  
  6573.   WindowAssignToVirtual()
  6574.   -----------------------
  6575.  
  6576.   To turn a window into a viewport onto a virtual window, you use the
  6577.   WindowAssignToVirtual() function.
  6578.  
  6579.   Here is the prototype:
  6580.  
  6581.      int WindowAssignToVirtual(WPOINTER w, VWPOINTER vw, unsigned row,
  6582.                                unsigned col)
  6583.  
  6584.   The first argument is the window that will be turned into a viewport.  The
  6585.   second argument is the virtual window that w will be assigned to.  The third
  6586.   and fourth arguments are the (row,col) of the virtual window.  This position
  6587.   is where the upper left hand corner of the viewport's text area will be
  6588.   placed.
  6589.  
  6590.   To illustrate this, here is a sample call to WindowAssignToVirtual():
  6591.  
  6592.          WindowAssignToVirtual(w,vw,5,10)
  6593.  
  6594.   The following description shows how this is to be interpreted:
  6595.  
  6596.                            VIRTUAL WINDOW
  6597.    -------------------------------------------------------------------
  6598.   |(1,1)                                                      (100,1)|
  6599.   |                                                                  |
  6600.   |         (5,10) of the virtual window is equivalent to (1,1) of   |
  6601.   |           |    the viewport.                                     |
  6602.   |           v                                                      |
  6603.   |           -----------------------                                |
  6604.   |           |(1,1) of the viewport|                                |
  6605.   |           |                     |                                |
  6606.   |           |   VIEWPORT WINDOW   |                                |
  6607.   |           |(14,1)        (14,30)|                                |
  6608.   |           -----------------------                                |
  6609.   |                                                                  |
  6610.   |(100,1)                                                 (100,100) |
  6611.   --------------------------------------------------------------------
  6612.  
  6613.  
  6614.   The viewport relative position of (1,1) is located at (5,10) of the virtual
  6615.   window.
  6616.  
  6617.  Page 107                     The C Window Library                    Page 107
  6618.  
  6619.   Example:
  6620.  
  6621.    #include "window.h"
  6622.  
  6623.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6624.    VWPOINTER vw;          /* virtual window pointers */
  6625.    WPOINTER w;
  6626.    main()
  6627.    {
  6628.      WindowInitializeSystem();
  6629.      WindowSaveInitial(0);
  6630.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  6631.      w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  6632.      WindowOpen(w);
  6633.      WindowDisplay(w,1,NOEFFECT);
  6634.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to virtual
  6635.                                                       window */
  6636.      WindowAssignToVirtual(w,vw,1,1);      /* Assign viewport to virtual
  6637.                                               window */
  6638.    }
  6639.  
  6640.   The above program opens a virtual window, vw, and opens a normal window, w.
  6641.   In the above example, the VirtualWriteString() function is used to write
  6642.   strings to the virtual window.  See page 111 for more information on
  6643.   VirtualWriteString().
  6644.  
  6645.   Once a window is turned into a viewport, nothing is stopping you from using
  6646.   the other window functions.  You can still use WindowWriteString(),
  6647.   WindowMove(), WindowPrintf(), etc.  Writing text to a viewport window via the
  6648.   normal window functions does not effect the virtual window in any way.
  6649.  
  6650.   If there are no errors, WindowAssignToVirtual() returns NO_ERROR.
  6651.   If there are errors, WindowAssignToVirtual() returns the following values:
  6652.  
  6653.   BAD_WINDOW if the window does not exist.
  6654.  
  6655.   BAD_V_WINDOW if the virtual window does not exist.
  6656.  
  6657.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen()).
  6658.  
  6659.  
  6660.   Out of bounds Coordinates
  6661.   -------------------------
  6662.  
  6663.   The next question is "What do you do if the coordinates given in
  6664.   WindowAssignToVirtual() are out of bounds of the range of the virtual
  6665.   window?".  For instance, if the virtual window has 100 rows, but the call to
  6666.   WindowAssignToVirtual() specifies row 97, and the viewport itself has a
  6667.   height of 10 rows.  The window manager will fill the viewport with as much of
  6668.   the virtual window as possible, and will clear the contents of the viewport
  6669.   that are not inside the virtual window.
  6670.  
  6671.   Here is another view of what happens in this case:
  6672.  
  6673.  Page 108                     The C Window Library                    Page 108
  6674.  
  6675.                            VIRTUAL WINDOW
  6676.    -------------------------------------------------------------------
  6677.   |(1,1)                                                      (100,1)|
  6678.   |                                                                  |
  6679.   |           (97,10) of the virtual window is the same as (1,1) of  |
  6680.   |             |     the viewport window.                           |
  6681.   |             v                                                    |
  6682.   |             -----------------------                              |
  6683.   |             |(1,1) of the viewport|                              |
  6684.   |             |                     |                              |
  6685.   |(100,1)      |   VIEWPORT WINDOW   |                    (100,100) |
  6686.   --------------------------------------------------------------------
  6687.                 |This portion of the  |
  6688.                 |  window is cleared  |
  6689.                 -----------------------
  6690.  
  6691.   The above picture shows a viewport that is partially contained in the virtual
  6692.   window.  The contents of the window above the last row of the virtual window
  6693.   is updated, while the portion of the viewport below the line is cleared.
  6694.  
  6695.  
  6696.  
  6697.  
  6698.   WindowCloseViewport()
  6699.   ---------------------
  6700.  
  6701.   To turn a viewport back to a normal window, WindowCloseViewport() is called.
  6702.   Here is the prototype:
  6703.  
  6704.            int WindowCloseViewport(WPOINTER w, int hide, int effect)
  6705.  
  6706.   where w is the viewport to be turned back into a regular window.  When this
  6707.   function is called, the window w is cleared with its own video attribute.
  6708.   The second argument tells if the window is to be hidden. If hide is 1, the
  6709.   window is hidden.  If it is 0, the window remains on the screen.  The effect
  6710.   argument is a special effect to use when hiding the window.  A list of
  6711.   special effects are defined on page 14.  This function DOES NOT close the
  6712.   virtual window or does a WindowClose() to the viewport window.  (See page 20
  6713.   for a discussion of WindowClose()).
  6714.  
  6715.  
  6716.   Example:
  6717.  
  6718.  
  6719.    #include "window.h"
  6720.  
  6721.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6722.    VWPOINTER vw;          /* virtual window pointers */
  6723.    WPOINTER w;
  6724.    main()
  6725.    {
  6726.      WindowInitializeSystem();
  6727.      WindowSaveInitial(0);
  6728.  
  6729.  Page 109                     The C Window Library                    Page 109
  6730.  
  6731.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  6732.      w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  6733.      WindowOpen(w);
  6734.      WindowDisplay(w,1,NOEFFECT);
  6735.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to virtual
  6736.                                                       window */
  6737.      WindowAssignToVirtual(w,vw,1,1);      /* Assign viewport to virtual
  6738.                                               window */
  6739.      GET_KEY();
  6740.      WindowCloseViewport(w,1,NOEFFECT);
  6741.      GETKEY();
  6742.    }
  6743.  
  6744.  
  6745.   The example above opens a virtual windows and a normal.  It then assigns the
  6746.   windows to the virtual window by calling WindowAssignToVirtual().  The
  6747.   program then unassigns the viewport by calling WindowCloseViewport().
  6748.  
  6749.   If there are no errors, WindowCloseViewport() returns NO_ERROR.
  6750.   If there are errors, WindowCloseViewport() returns the following values:
  6751.  
  6752.   BAD_WINDOW if the window does not exist.
  6753.  
  6754.   BAD_V_WINDOW if the virtual window that w is a viewport on does not exist.
  6755.  
  6756.   WINDOW_NOT_OPEN if the window is not open for writing (use WindowOpen()).
  6757.  
  6758.  
  6759.  
  6760.  
  6761.  
  6762.  
  6763.  
  6764.  
  6765.  
  6766.  
  6767.  
  6768.  
  6769.  
  6770.  
  6771.  
  6772.  
  6773.  
  6774.  
  6775.  
  6776.  
  6777.  
  6778.  
  6779.  
  6780.  
  6781.  
  6782.  
  6783.  
  6784.  
  6785.  Page 110                     The C Window Library                    Page 110
  6786.  
  6787.                         WRITING TEXT TO VIRTUAL WINDOWS
  6788.                         -------------------------------
  6789.  
  6790.   There are several functions that write strings to virtual windows.  They are
  6791.   divided into two groups: functions that take null terminated strings as
  6792.   arguments, and functions that use character buffers and a length argument.
  6793.  
  6794.   When any of the text functions are called, any viewport that is displaying
  6795.   any portion of the virtual window that has been changed will display the
  6796.   update.
  6797.  
  6798.  
  6799.   Null Terminated String Functions
  6800.   --------------------------------
  6801.  
  6802.   VirtualWriteString()
  6803.   --------------------
  6804.  
  6805.   The VirtualWriteString() function writes a null terminated to a virtual
  6806.   window at a specific row and column of the virtual window.  Here is the
  6807.   prototype:
  6808.  
  6809.         int VirtualWriteString(VWPOINTER vw, char *string, unsigned row,
  6810.                                unsigned col)
  6811.  
  6812.   The first argument is the virtual window pointer.  The second argument is the
  6813.   string to write.  The third and fourth arguments are the row and column of
  6814.   the virtual window that the string is to be written to.  If the string will
  6815.   exceed the boundaries of the virtual window, the string is truncated.
  6816.  
  6817.   Example:
  6818.  
  6819.    #include "window.h"
  6820.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6821.    VWPOINTER vw;          /* virtual window pointers */
  6822.    WPOINTER w1, w2;
  6823.    main()
  6824.    {
  6825.      WindowInitializeSystem();
  6826.      WindowSaveInitial(0);
  6827.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  6828.      w1 = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  6829.      w2 = WindowInitialize(BORDER,13,1,20,10,NORM,NORM,DOUBLEBOX);
  6830.      WindowOpen(w1);
  6831.      WindowOpen(w2);
  6832.      WindowDisplay(w1,1,NOEFFECT);
  6833.      WindowDisplay(w2,2,NOEFFECT);
  6834.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to virtual
  6835.                                                       window */
  6836.      WindowAssignToVirtual(w1,vw,1,1); /* Assign viewport to virtual window */
  6837.      WindowAssignToVirtual(w2,vw,1,10);  /* Assign viewport to virtual
  6838.                                             window */
  6839.    }
  6840.  
  6841.  Page 111                     The C Window Library                    Page 111
  6842.  
  6843.   The example above writes the string "This is a string" to the virtual window
  6844.   at row 1, column 1.  The windows w1 and w2 are viewports on the virtual
  6845.   window vw.  The window w1 is located at (1,1) of the virtual window, while w2
  6846.   is located at (1,10) of the virtual window.  The window w1 will display "This
  6847.   is a string", but w2 will only display "string" since it is situated at
  6848.   column 10 of the virtual window.
  6849.  
  6850.  
  6851.   If there are no errors, VirtualWriteString() returns NO_ERROR.
  6852.  
  6853.   If there are errors, VirtualWriteString() returns the following values:
  6854.  
  6855.  
  6856.   BAD_V_WINDOW if the virtual window does not exist.
  6857.  
  6858.   V_WINDOW_BOUND if the either row or col is out of bounds of the virtual
  6859.   window.
  6860.  
  6861.  
  6862.  
  6863.  
  6864.   VirtualWriteStringAttr()
  6865.   ------------------------
  6866.  
  6867.   The VirtualWriteStringAttr() works the same way as the VirtualWriteString()
  6868.   except that a video attribute is used.  Here is the prototype:
  6869.  
  6870.      int VirtualWriteStringAttr(VWPOINTER vw, char *string, unsigned row,
  6871.                                 unsigned col, int attr)
  6872.  
  6873.   The last argument is the video attribute to use.  If the virtual window is
  6874.   NOATTRIBUTE, the attribute is ignored, and only the string is written.  Any
  6875.   viewports that are assigned to NOATTRIBUTE virtual windows will not reflect
  6876.   the change in the attribute.
  6877.  
  6878.   Example:
  6879.  
  6880.    #include "window.h"
  6881.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  6882.    #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  6883.    VWPOINTER vw;          /* virtual window pointers */
  6884.    WPOINTER w;
  6885.    main()
  6886.    {
  6887.      WindowInitializeSystem();
  6888.      WindowSaveInitial(0);
  6889.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  6890.      w = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  6891.      WindowOpen(w);
  6892.      WindowDisplay(w,1,NOEFFECT);
  6893.      VirtualWriteStringAttr(vw,"This is a string",1,1,REVERSE);
  6894.      WindowAssignToVirtual(w,vw,1,1);   /* Assign viewport to virtual window */
  6895.    }
  6896.  
  6897.  Page 112                     The C Window Library                    Page 112
  6898.  
  6899.   The example above writes the string "This is a string" in the virtual window
  6900.   with a video attribute defined by the constant REVERSE.
  6901.  
  6902.   If there are no errors, VirtualWriteStringAttr() returns NO_ERROR.
  6903.  
  6904.   If there are errors, VirtualWriteStringAttr() returns the following values:
  6905.  
  6906.   BAD_V_WINDOW if the virtual window does not exist.
  6907.  
  6908.   V_WINDOW_BOUND if the either row or col is out of bounds of the virtual
  6909.   window.
  6910.  
  6911.   NO_ATTRIB if the virtual window is NOATTRIBUTE.  If this error occurs,
  6912.   only the string is written.
  6913.  
  6914.  
  6915.  
  6916.  
  6917.   VirtualWriteCenterString()
  6918.   --------------------------
  6919.  
  6920.   The VirtualWriteCenterString() writes a centered string in a virtual window.
  6921.   Here is the prototype:
  6922.  
  6923.     int VirtualWriteCenterString(VWPOINTER vw, char *string, unsigned row)
  6924.  
  6925.   The row argument is the row to center the string on.
  6926.  
  6927.  
  6928.   Example:
  6929.  
  6930.    #include "window.h"
  6931.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  6932.    VWPOINTER vw;          /* virtual window pointers */
  6933.    WPOINTER w;
  6934.  
  6935.    main()
  6936.    {
  6937.      WindowInitializeSystem();
  6938.      WindowSaveInitial(0);
  6939.      vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  6940.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  6941.      WindowOpen(w);
  6942.      WindowDisplay(w,1,NOEFFECT);
  6943.      VirtualWriteCenterString(vw,"This is a string",1);
  6944.      WindowAssignToVirtual(w,vw,1,1);
  6945.    }
  6946.  
  6947.  
  6948.  
  6949.  
  6950.  
  6951.  
  6952.  
  6953.  Page 113                     The C Window Library                    Page 113
  6954.  
  6955.   The above example illustrates the use of VirtualWriteCenterString().  The
  6956.   viewport window w is just used as a guide to display what has happened.
  6957.  
  6958.   If there are no errors, VirtualWriteCenterString() returns NO_ERROR.
  6959.  
  6960.   If there are errors, VirtualWriteCenterString() returns the following values:
  6961.  
  6962.  
  6963.   BAD_V_WINDOW if the virtual window does not exist.
  6964.  
  6965.   V_WINDOW_BOUND if the row is out of bounds of the virtual window.
  6966.  
  6967.  
  6968.  
  6969.  
  6970.   VirtualWriteCenterStringAttr()
  6971.   ------------------------------
  6972.  
  6973.  
  6974.   The VirtualWriteCenterStringAttr() function works the same way as
  6975.   VirtualWriteCenterString() except that a video attribute is specified.  Here
  6976.   is the prototype:
  6977.  
  6978.     int VirtualWriteCenterStringAttr(VWPOINTER vw, char *string, unsigned row,
  6979.                                      int attr)
  6980.  
  6981.   The attr argument is the video attribute to use.  If the virtual window is
  6982.   NOATTRIBUTE, the attribute is ignored and only the string is written to the
  6983.   virtual window.
  6984.  
  6985.  
  6986.    #include "window.h"
  6987.  
  6988.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  6989.    #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  6990.    VWPOINTER vw;          /* virtual window pointers */
  6991.    WPOINTER w;
  6992.    main()
  6993.    {
  6994.      WindowInitializeSystem();
  6995.      WindowSaveInitial(0);
  6996.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  6997.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  6998.      WindowOpen(w);
  6999.      WindowDisplay(w,1,NOEFFECT);
  7000.      VirtualWriteCenterStringAttr(vw,"This is a string",1,REVERSE);
  7001.      WindowAssignToVirtual(w,vw,1,1);  /* Assign viewport to virtual window */
  7002.    }
  7003.  
  7004.  
  7005.  
  7006.  
  7007.  
  7008.  
  7009.  Page 114                     The C Window Library                    Page 114
  7010.  
  7011.   If there are no errors, VirtualWriteCenterStringAttr() returns NO_ERROR.
  7012.  
  7013.   If there are errors, VirtualWriteCenterStringAttr() returns the following
  7014.   values:
  7015.  
  7016.   BAD_V_WINDOW if the virtual window does not exist.
  7017.  
  7018.   V_WINDOW_BOUND if the row is out of bounds of the virtual window.
  7019.  
  7020.   NO_ATTRIB if the virtual window is NOATTRIBUTE.  If this error occurs,
  7021.   only the string is written.
  7022.  
  7023.  
  7024.  
  7025.  
  7026.   VirtualWriteStringCC()
  7027.   ----------------------
  7028.  
  7029.   The VirtualWriteStringCC() function centers and writes a string around a
  7030.   column of the virtual window (the CC stands for Centered Column).  If the
  7031.   string is longer than the width of the virtual window, the string is placed
  7032.   on column 1 is clipped at the right edge of the virtual window.
  7033.   Here is the prototype:
  7034.  
  7035.   int VirtualWriteStringCC(VWPOINTER vw, char *string, unsigned row,
  7036.                            unsigned col)
  7037.  
  7038.   The first argument is the window.  The second argument is the string. The
  7039.   third argument is the row to write the string, and the last argument is the
  7040.   column to center the string on.
  7041.  
  7042.   Example:
  7043.  
  7044.    #include "window.h"
  7045.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  7046.    VWPOINTER vw;          /* virtual window pointers */
  7047.    WPOINTER w;
  7048.    main()
  7049.    {
  7050.      WindowInitializeSystem();
  7051.      WindowSaveInitial(0);
  7052.      vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  7053.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7054.      WindowOpen(w);
  7055.      WindowDisplay(w,1,NOEFFECT);
  7056.      VirtualWriteStringCC(vw,"This",1,10);
  7057.      VirtualWriteStringCC(vw,"is",2,10);
  7058.      VirtualWriteStringCC(vw,"centered",3,10);
  7059.      VirtualWriteStringCC(vw,"around",4,10);
  7060.      VirtualWriteStringCC(vw,"column",5,10);
  7061.      VirtualWriteStringCC(vw,"10",6,10);
  7062.      WindowAssignToVirtual(w,vw,1,1);
  7063.    }
  7064.  
  7065.  Page 115                     The C Window Library                    Page 115
  7066.  
  7067.   The example above writes the text centered around column 10 of the virtual
  7068.   window w.
  7069.  
  7070.   The return values for VirtualWriteStringCC() are the same as
  7071.   VirtualWriteString().
  7072.  
  7073.  
  7074.  
  7075.  
  7076.  
  7077.   VirtualWriteStringCCAttr()
  7078.   --------------------------
  7079.  
  7080.   The VirtualWriteStringCCAttr() works the same way as the
  7081.   VirtualWriteStringCC() function except that a video attribute is specified.
  7082.   Here is the prototype:
  7083.  
  7084.   int VirtualWriteStringCCAttr(VWPOINTER vw, char *string, unsigned row,
  7085.                                unsigned col, int attr)
  7086.  
  7087.   The attribute to use is the last argument.  If the virtual window is
  7088.   NOATTRIBUTE, the attr argument is ignored, and only the string is written
  7089.   to the virtual window.
  7090.  
  7091.   Example:
  7092.  
  7093.    #include "window.h"
  7094.  
  7095.    #define NORM     CREATE_VIDEO_ATTRIBUTE(black,white)
  7096.    #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  7097.  
  7098.    VWPOINTER vw;          /* virtual window pointers */
  7099.    WPOINTER w;
  7100.    main()
  7101.    {
  7102.      WindowInitializeSystem();
  7103.      WindowSaveInitial(0);
  7104.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7105.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7106.      WindowOpen(w);
  7107.      WindowDisplay(w,1,NOEFFECT);
  7108.      VirtualWriteStringCCAttr(vw,"This",1,10,REVERSE);
  7109.      VirtualWriteStringCCAttr(vw,"is",2,10,REVERSE);
  7110.      VirtualWriteStringCCAttr(vw,"centered",3,10,REVERSE);
  7111.      VirtualWriteStringCCAttr(vw,"around",4,10,REVERSE);
  7112.      VirtualWriteStringCCAttr(vw,"column",5,10,REVERSE);
  7113.      VirtualWriteStringCCAttr(vw,"10",6,10,REVERSE);
  7114.      WindowAssignToVirtual(w,vw,1,1);
  7115.    }
  7116.  
  7117.  
  7118.   The return values for VirtualWriteStringCCAttr() are the same as
  7119.   VirtualWriteStringAttr().
  7120.  
  7121.  Page 116                     The C Window Library                    Page 116
  7122.  
  7123.   VirtualWriteStringRJ()
  7124.   ----------------------
  7125.  
  7126.   The VirtualWriteStringRJ() function writes a right justified string in a
  7127.   virtual window.  Here is the prototype:
  7128.  
  7129.      int VirtualWriteStringRJ(WPOINTER w, char *string, unsigned row,
  7130.                               unsigned col)
  7131.  
  7132.   The first argument is the virtual window.  The second argument is the string.
  7133.   The third argument is the row to write the string, and the last argument is
  7134.   the column to place the right edge of the string.
  7135.  
  7136.  
  7137.   Example:
  7138.  
  7139.  
  7140.   #include "window.h"
  7141.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7142.  
  7143.    VWPOINTER vw;          /* virtual window pointers */
  7144.    WPOINTER w;
  7145.    main()
  7146.    {
  7147.      WindowInitializeSystem();
  7148.      WindowSaveInitial(0);
  7149.      vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  7150.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7151.      WindowOpen(w);
  7152.      WindowDisplay(w,1,NOEFFECT);
  7153.      VirtualWriteStringRJ(vw,"This",1,10);
  7154.      VirtualWriteStringRJ(vw,"is",2,10);
  7155.      VirtualWriteStringRJ(vw,"right",3,10);
  7156.      VirtualWriteStringRJ(vw,"justified",4,10);
  7157.      VirtualWriteStringRJ(vw,"on ",5,10);
  7158.      VirtualWriteStringRJ(vw,"column",6,10);
  7159.      VirtualWriteStringRJ(vw,"10",7,10);
  7160.      WindowAssignToVirtual(w,vw,1,1);
  7161.    }
  7162.  
  7163.  
  7164.   The example above writes the text right justified on column 10 of the
  7165.   virtual window.
  7166.  
  7167.   The return values for VirtualWriteStringRJ() are the same as
  7168.   VirtualWriteString().
  7169.  
  7170.  
  7171.  
  7172.  
  7173.  
  7174.  
  7175.  
  7176.  
  7177.  Page 117                     The C Window Library                    Page 117
  7178.  
  7179.   VirtualWriteStringRJAttr()
  7180.   --------------------------
  7181.  
  7182.   The VirtualWriteStringRJAttr() writes a right justified string in a virtual
  7183.   window, and allows you to specify a video attribute. Here is the prototype:
  7184.  
  7185.      int VirtualWriteStringRJAttr(WPOINTER w, char *string, unsigned row,
  7186.                                   unsigned col, int attr)
  7187.  
  7188.   The last argument is the attribute to use.
  7189.  
  7190.  
  7191.   Example:
  7192.  
  7193.  
  7194.   #include "window.h"
  7195.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7196.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  7197.  
  7198.    VWPOINTER vw;          /* virtual window pointers */
  7199.    WPOINTER w;
  7200.    main()
  7201.    {
  7202.      WindowInitializeSystem();
  7203.      WindowSaveInitial(0);
  7204.      vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7205.      w = WindowInitialize(BORDER,1, 1,50,12,NORM,NORM,SINGLEBOX);
  7206.      WindowOpen(w);
  7207.      WindowDisplay(w,1,NOEFFECT);
  7208.      VirtualWriteStringRJAttr(vw,"This",1,10,REVERSE);
  7209.      VirtualWriteStringRJAttr(vw,"is",2,10,REVERSE);
  7210.      VirtualWriteStringRJAttr(vw,"right",3,10,REVERSE);
  7211.      VirtualWriteStringRJAttr(vw,"justified",4,10,REVERSE);
  7212.      VirtualWriteStringRJAttr(vw,"on ",5,10,REVERSE);
  7213.      VirtualWriteStringRJAttr(vw,"column",6,10,REVERSE);
  7214.      VirtualWriteStringRJAttr(vw,"10",7,10,REVERSE);
  7215.      WindowAssignToVirtual(w,vw,1,1);
  7216.    }
  7217.  
  7218.  
  7219.   The example above writes the text right justified on column 10 of the
  7220.   virtual window.  If the virtual window is NOATTRIBUTE, only the string is
  7221.   written.
  7222.  
  7223.   The return values for VirtualWriteStringRJAttr() are the same as
  7224.   VirtualWriteStringAttr().
  7225.  
  7226.  
  7227.  
  7228.  
  7229.  
  7230.  
  7231.  
  7232.  
  7233.  Page 118                     The C Window Library                    Page 118
  7234.  
  7235.   Length Controlled Functions
  7236.   ---------------------------
  7237.  
  7238.  
  7239.  
  7240.   VirtualWriteCharacters()
  7241.   ------------------------
  7242.  
  7243.   The VirtualWriteCharacters() writes a specified number of characters from a
  7244.   buffer to the virtual window.  Here is the prototype:
  7245.  
  7246.  
  7247.     int VirtualWriteCharacters(VWPOINTER vw, char *buffer, unsigned row,
  7248.                                unsigned col, unsigned length)
  7249.  
  7250.  
  7251.   The first argument is the virtual window.  The second argument is the buffer
  7252.   where the characters are stored.  The third and fourth arguments are the
  7253.   (row,col) of where the characters will be placed in the virtual window.  The
  7254.   last argument is the number of characters from buffer that will be written.
  7255.  
  7256.  
  7257.   Example:
  7258.  
  7259.  
  7260.   #include "window.h"
  7261.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7262.  
  7263.   WPOINTER w;
  7264.   VWPOINTER vw;
  7265.   char buf[] = "Hello World!!";
  7266.  
  7267.   main()
  7268.   {
  7269.     WindowInitializeSystem();
  7270.     WindowSaveInitial(0);
  7271.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  7272.     vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  7273.     WindowOpen(w);
  7274.     WindowDisplay(w,1,NOEFFECT);
  7275.     VirtualWriteCharacters(vw,buf,1,1,11);  /* Writes "Hello World"   */
  7276.     VirtualWriteCharacters(vw,buf,2,1,13);  /* Writes "Hello World!!" */
  7277.     WindowAssignToVirtual(w,vw,1,1);
  7278.   }
  7279.  
  7280.  
  7281.   The return values for VirtualWriteCharacters() are the same as
  7282.   VirtualWriteString().
  7283.  
  7284.  
  7285.  
  7286.  
  7287.  
  7288.  
  7289.  Page 119                     The C Window Library                    Page 119
  7290.  
  7291.   VirtualWriteAttributes()
  7292.   ------------------------
  7293.  
  7294.   The VirtualWriteAttributes() writes a specified number of attributes from a
  7295.   buffer to the virtual window.  Here is the prototype:
  7296.  
  7297.  
  7298.     int VirtualWriteAttributes(VWPOINTER vw, char *buffer, unsigned row,
  7299.                                unsigned col, unsigned length)
  7300.  
  7301.  
  7302.   The first argument is the virtual window.  The second argument is the buffer
  7303.   where the attributes are stored.  The third and fourth arguments are the
  7304.   (row,col) of where the attributes will be placed in the virtual window.  The
  7305.   last argument is the number of attributes from buffer that will be written.
  7306.   If the window is NOATTRIBUTE, this function does nothing.
  7307.  
  7308.   Example:
  7309.  
  7310.  
  7311.   #include "window.h"
  7312.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7313.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  7314.   WPOINTER w;
  7315.   VWPOINTER vw;
  7316.   char buf[13];
  7317.  
  7318.   main()
  7319.   {
  7320.     int i;
  7321.     WindowInitializeSystem();
  7322.     WindowSaveInitial(0);
  7323.     for (i=0;i<13;i++)
  7324.       if (i % 2)
  7325.         buf[i] = NORM;
  7326.       else
  7327.         buf[i] = REVERSE;
  7328.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  7329.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7330.     WindowOpen(w);
  7331.     WindowDisplay(w,1,NOEFFECT);
  7332.     VirtualWriteString(vw,"Hello World!!",1,1);
  7333.     VirtualWriteAttributes(vw,buf,1,1,13);  /* Writes alternating NORM and
  7334.                                                REVERSE attributes */
  7335.     WindowAssignToVirtual(w,vw,1,1);
  7336.   }
  7337.  
  7338.  
  7339.   The return values for VirtualWriteAttributes() are the same as
  7340.   VirtualWriteStringAttr().
  7341.  
  7342.  
  7343.  
  7344.  
  7345.  Page 120                     The C Window Library                    Page 120
  7346.  
  7347.   VirtualWriteCharAndAttr()
  7348.   -------------------------
  7349.  
  7350.   The VirtualWriteCharAndAttr() function writes a string of character/attribute
  7351.   pairs to a virtual window.  Use this function if you have created a string of
  7352.   character/attribute pairs, and want to output them easily.  The string
  7353.   consists of character and attributes in the following manner:
  7354.  
  7355.            char-attr-char-attr...
  7356.  
  7357.   Each character is followed by its corresponding video attribute.
  7358.   Here is the prototype:
  7359.  
  7360.   int VirtualWriteCharAndAttr(WPOINTER w, char *buffer, int row, int col,
  7361.                              int length)
  7362.  
  7363.   The first argument is the virtual window. The second is the buffer where the
  7364.   character and attributes are stored.  The third and fourth is the (row,col)
  7365.   position in the virtual window to write, and the length argument is the
  7366.   number of character/attribute pairs from the buffer to write.  Please note
  7367.   the difference in the meaning of the length argument in this function as
  7368.   opposed to its use in the preceding functions.
  7369.  
  7370.   If the virtual window is NOATTRIBUTE, nothing is written to the virtual
  7371.   window.
  7372.  
  7373.   Example:
  7374.  
  7375.   #include "window.h"
  7376.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7377.  
  7378.   WPOINTER w;
  7379.   VWPOINTER vw;
  7380.   char buf[26];
  7381.   char *str = "Hello World!!";
  7382.   main()
  7383.   {
  7384.     int i;
  7385.     WindowInitializeSystem();
  7386.     WindowSaveInitial(0);
  7387.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  7388.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7389.     WindowOpen(w);
  7390.     WindowDisplay(w,1,NOEFFECT);
  7391.  
  7392.     for (i=0;i<26;i+=2,str++)
  7393.     {
  7394.       buf[i] = *str;
  7395.       buf[i+1] = NORM;
  7396.     }
  7397.     VirtualWriteCharAndAttr(vw,buf,1,1,13);
  7398.     WindowAssignToVirtual(w,vw,1,1);
  7399.   }
  7400.  
  7401.  Page 121                     The C Window Library                    Page 121
  7402.  
  7403.   The return values for VirtualWriteCharAndAttr() are the same as
  7404.   VirtualWriteStringAttr().
  7405.  
  7406.  
  7407.  
  7408.   VirtualWriteRepeatAttribute()
  7409.   -----------------------------
  7410.  
  7411.   The VirtualWriteRepeatAttribute() function writes an attribute a specified
  7412.   number of times to a virtual window.  Here is a prototype:
  7413.  
  7414.  
  7415.   int VirtualWriteRepeatAttribute(VWPOINTER vw, int attr, unsigned row,
  7416.                                   unsigned col, int count)
  7417.  
  7418.   The attr argument is the attribute to use.  The count argument specifies the
  7419.   number of times to write the attribute attr to the virtual window starting at
  7420.   (row,col).  If the virtual window is NOATTRIBUTE, this function returns an
  7421.   error.
  7422.  
  7423.  
  7424.   Example:
  7425.  
  7426.   #include "window.h"
  7427.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7428.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  7429.  
  7430.   WPOINTER w;
  7431.   VWPOINTER vw;
  7432.   main()
  7433.   {
  7434.     WindowInitializeSystem();
  7435.     WindowSaveInitial(0);
  7436.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  7437.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7438.     WindowOpen(w);
  7439.     WindowDisplay(w,1,NOEFFECT);
  7440.     VirtualWriteString(vw,"Hello World!!",1,1);
  7441.     VirtualWriteRepeatAttribute(vw,REVERSE,1,1,13);
  7442.     WindowAssignToVirtual(w,vw,1,1);
  7443.   }
  7444.  
  7445.  
  7446.   The example above illustrates that the VirtualWriteRepeatAttribute() writes
  7447.   the REVERSE attribute 13 times starting at row 1, column 1 of the
  7448.   virtual window w.
  7449.  
  7450.   The return values for VirtualWriteRepeatAttribute() are the same as
  7451.   VirtualWriteStringAttr().
  7452.  
  7453.  
  7454.  
  7455.  
  7456.  
  7457.  Page 122                     The C Window Library                    Page 122
  7458.  
  7459.   VirtualWriteRepeatCharacter()
  7460.   -----------------------------
  7461.  
  7462.   The VirtualWriteRepeatCharacter() function writes a character a specified
  7463.   number of times to a virtual window.  Here is a prototype:
  7464.  
  7465.  
  7466.   int VirtualWriteRepeatCharacter(WPOINTER w, int ch, int row, int col,
  7467.                                   int count)
  7468.  
  7469.  
  7470.   The count argument is the character to use.  The count argument specifies the
  7471.   number of times to write the character ch to the virtual window starting at
  7472.   (row,col).
  7473.  
  7474.   Example:
  7475.  
  7476.   #include "window.h"
  7477.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7478.  
  7479.   VWPOINTER vw;
  7480.   WPOINTER w;
  7481.  
  7482.   main()
  7483.   {
  7484.     WindowInitializeSystem();
  7485.     WindowSaveInitial(0);
  7486.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  7487.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  7488.     WindowOpen(w);
  7489.     WindowDisplay(w,1,NOEFFECT);
  7490.     VirtualWriteRepeatCharacter(vw,'a',1,1,5);
  7491.     VirtualWriteRepeatCharacter(vw,'b',2,1,5);
  7492.     VirtualWriteRepeatCharacter(vw,'c',3,1,5);
  7493.     WindowAssignToVirtual(w,vw,1,1);
  7494.   }
  7495.  
  7496.  
  7497.   The example above illustrates that the VirtualWriteRepeatCharacter() writes
  7498.   the letter 'a', 'b', and 'c' 5 times on rows 1, 2, and 3 respectively.
  7499.  
  7500.   The return values for VirtualWriteRepeatCharacter() are the same as
  7501.   VirtualWriteString().
  7502.  
  7503.  
  7504.  
  7505.  
  7506.  
  7507.  
  7508.  
  7509.  
  7510.  
  7511.  
  7512.  
  7513.  Page 123                     The C Window Library                    Page 123
  7514.  
  7515.   Formatted Write Functions
  7516.   -------------------------
  7517.  
  7518.  
  7519.   Format String
  7520.   -------------
  7521.  
  7522.   These functions write formatted output to virtual windows just like the
  7523.   printf() function.  There are two functions that do this, namely
  7524.   VirtualPrintf() and VirtualPrintfAttr().  These functions use a format
  7525.   string that is similar to the format string found in printf().  For example,
  7526.   %d, %s, %lf, etc. and most of the escape sequences are supported.  The list
  7527.   of escape sequences supported are as follows:
  7528.  
  7529.                         \n - newline
  7530.                         \t - tab
  7531.                         \r - carriage return
  7532.                         \x - hexadecimal
  7533.  
  7534.  
  7535.   Where Output is Placed
  7536.   ----------------------
  7537.  
  7538.   The row and column of where the string will be written is determined by the
  7539.   virtual window's logical cursor.  The logical cursor is advanced by both of
  7540.   these functions to one column position after the last character is printed.
  7541.   If you want to start at a particular row and column of the window, you must
  7542.   move the cursor yourself by calling the VirtualMoveCursor() function.  This
  7543.   function is explained on page 140.
  7544.  
  7545.   When the virtual window is first initialized using VirtualInitialize(), the
  7546.   logical cursor is automatically moved to (1,1) of the virtual window.
  7547.  
  7548.  
  7549.  
  7550.   VirtualSetWrap()
  7551.   ----------------
  7552.  
  7553.   With these functions, any text that will exceed the boundaries of the window
  7554.   will be wrapped to the next line.  If the output will exceed the last row of
  7555.   the window, the window is automatically scrolled up by one line.  This is the
  7556.   default action to take when characters exceed the right edge of the
  7557.   virtual window.  If you want the output clipped instead of wrapped, you must
  7558.   set the virtual window's wrap flag using the VirtualSetWrap() function.
  7559.  
  7560.   The VirtualSetWrap() function sets the virtual window's wrap flag to either
  7561.   on or off.  Here is the prototype:
  7562.  
  7563.               int VirtualSetWrap(VWPOINTER vw, int option)
  7564.  
  7565.   The second argument will be 0 if you want to turn the wrap flag off, or 1 if
  7566.   you want to turn it on.  If the wrap flag is off, the output generated by
  7567.  
  7568.  
  7569.  Page 124                     The C Window Library                    Page 124
  7570.  
  7571.   VirtualPrintf() and VirtualPrintfAttr() will be terminated when the right edge
  7572.   of the window is reached.  If the wrap flag is on, the output is wrapped to
  7573.   the next line when the right edge is reached.  Unlike regular windows, the
  7574.   output is not scrolled if the last line of the virtual window is reached.
  7575.  
  7576.   You can set the wrap flag to a virtual window at any time.
  7577.  
  7578.  
  7579.  
  7580.   VirtualPrintf()
  7581.   --------------
  7582.  
  7583.   The VirtualPrintf() function writes formatted output to the virtual window.
  7584.   Here is the prototype:
  7585.  
  7586.             int VirtualPrintf(VWPOINTER vw, char *format [,arg1,...])
  7587.  
  7588.   The first argument is the virtual window.  The second argument is a format
  7589.   string.  The rest of the arguments are optional arguments that are written to
  7590.   the virtual window.
  7591.  
  7592.  
  7593.   Example:
  7594.  
  7595.   #include "window.h"
  7596.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7597.  
  7598.   WPOINTER w;
  7599.   VWPOINTER vw;
  7600.   int i = 3;
  7601.   double j = 5.6;
  7602.  
  7603.   main()
  7604.   {
  7605.     WindowInitializeSystem();
  7606.     WindowSaveInitial(0);
  7607.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  7608.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  7609.     WindowOpen(w);
  7610.     WindowDisplay(w,1,NOEFFECT);
  7611.     WindowAssignToVirtual(w,vw,1,1);
  7612.     VirtualPrintf(vw,"3+2 is equal to %d\n",3+2);
  7613.     GET_KEY();
  7614.     VirtualPrintf(vw,"i is equal to %d\nj is equal to %lf\n",i,j);
  7615.   }
  7616.  
  7617.  
  7618.   The above example illustrates how VirtualPrintf() is used to print formatted
  7619.   strings to a virtual window.
  7620.  
  7621.   The return values for VirtualPrintf() are the same as VirtualWriteString().
  7622.  
  7623.  
  7624.  
  7625.  Page 125                     The C Window Library                    Page 125
  7626.  
  7627.   VirtualPrintfAttr()
  7628.   -------------------
  7629.  
  7630.   The VirtualPrintfAttr() function writes formatted output to the virtual
  7631.   window.  The difference between VirtualPrintf() and VirtualPrintfAttr() is
  7632.   that VirtualPrintfAttr() uses a video attribute specified as an argument.
  7633.   Here is the prototype:
  7634.  
  7635.      int VirtualPrintfAttr(VWPOINTER vw, int attr, char *format [,arg1,...])
  7636.  
  7637.   The first argument is the virtual window.  The second argument is the video
  7638.   attribute to use.  The third argument is the format string.  The rest of the
  7639.   arguments are optional arguments that are written to the virtual window.
  7640.   If the virtual window is NOATTRIBUTE, only the string is written to the
  7641.   window.
  7642.  
  7643.   Example:
  7644.  
  7645.   #include "window.h"
  7646.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7647.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  7648.  
  7649.   WPOINTER w;
  7650.   VWPOINTER vw;
  7651.   int i = 3;
  7652.   double j = 5.6;
  7653.  
  7654.   main()
  7655.   {
  7656.     WindowInitializeSystem();
  7657.     WindowSaveInitial(0);
  7658.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  7659.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  7660.     WindowOpen(w);
  7661.     WindowDisplay(w,1,NOEFFECT);
  7662.     WindowAssignToVirtual(w,vw,1,1);
  7663.     VirtualPrintfAttr(vw,REVERSE,"3+2 is equal to %d\n",3+2);
  7664.     GET_KEY();
  7665.     VirtualPrintfAttr(vw,REVERSE,"i is equal to %d\nj is equal to %lf\n",i,j);
  7666.   }
  7667.  
  7668.  
  7669.   The above example illustrates how VirtualPrintfAttr() is used to print
  7670.   formatted strings.
  7671.  
  7672.   The return values for VirtualPrintfAttr() are the same as
  7673.   VirtualWriteStringAttr().
  7674.  
  7675.  
  7676.  
  7677.  
  7678.  
  7679.  
  7680.  
  7681.  Page 126                     The C Window Library                    Page 126
  7682.  
  7683.             READING CHARACTERS AND ATTRIBUTES FROM VIRTUAL WINDOWS
  7684.             ------------------------------------------------------
  7685.  
  7686.  
  7687.   With The C Window Library, you can read the contents of a virtual window into
  7688.   a character buffer.  These functions provide the programmer with the contents
  7689.   of the virtual window at any time.  The functions to perform this are
  7690.   VirtualReadAttributes(), VirtualReadCharacters() and VirtualReadCharAndAttr().
  7691.  
  7692.  
  7693.  
  7694.   VirtualReadCharacters()
  7695.   -----------------------
  7696.  
  7697.   The VirtualReadCharacters() function reads the characters from a virtual
  7698.   window into a buffer.  Here is the prototype.
  7699.  
  7700.   int VirtualReadCharacters(VWPOINTER vw, char *buffer, unsigned row,
  7701.                             unsigned col, unsigned length)
  7702.  
  7703.   The first argument is the virtual window.  The second argument is the buffer
  7704.   to store the characters in.  The third and fourth arguments are the (row,col)
  7705.   position in the virtual window to start reading from.  The last argument is
  7706.   the number of characters to read.
  7707.  
  7708.   You must make sure that buffer has enough room to hold all of the characters
  7709.   read in.
  7710.  
  7711.  
  7712.   Example:
  7713.  
  7714.   #include "window.h"
  7715.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7716.  
  7717.   VWPOINTER vw;
  7718.   char buf[14] = {0};      /* Null all elements of buf */
  7719.  
  7720.   main()
  7721.   {
  7722.     int i;
  7723.     WindowInitializeSystem();
  7724.     WindowSaveInitial(0);
  7725.     vw = VirtualInitialize(NOATTRIBUTE,10,80,NORM);
  7726.     VirtualWriteString(vw,"Hello World!!",1,1);/* Write String */
  7727.     VirtualReadCharacters(vw,buf,1,1,13);      /* Read characters */
  7728.   }
  7729.  
  7730.   The example above illustrates the use of VirtualReadCharacters(), which reads
  7731.   the virtual window's contents starting at (1,1).  This happens to be the
  7732.   string "Hello World!!".
  7733.  
  7734.   If the length exceeds the right edge of the virtual window,
  7735.   VirtualReadCharacters() will read up to the right edge of the virtual window.
  7736.  
  7737.  Page 127                     The C Window Library                    Page 127
  7738.  
  7739.   If there are no errors, VirtualReadCharacters() returns NO_ERROR.
  7740.  
  7741.   If there are errors, VirtualReadCharacters() returns one of the following:
  7742.  
  7743.   BAD_V_WINDOW if the virtual window does not exist.
  7744.  
  7745.   V_WINDOW_BOUND if the row or column specified in the virtual window is out of
  7746.   bounds.
  7747.  
  7748.  
  7749.  
  7750.  
  7751.  
  7752.   VirtualReadAttributes()
  7753.   ----------------------
  7754.  
  7755.   The VirtualReadAttributes() function reads the attributes from a virtual
  7756.   window into a buffer.  Here is the prototype.
  7757.  
  7758.   int VirtualReadAttributes(VWPOINTER w, char *buffer, unsigned row,
  7759.                             unsigned col, unsigned length)
  7760.  
  7761.   The first argument is the virtual window.  The second argument is the buffer
  7762.   to store the attributes in.  The third and fourth arguments are the (row,col)
  7763.   position in the virtual window to start reading from.  The last argument is
  7764.   the number of attributes to read.  If the virtual window is NOATTRIBUTE,
  7765.   nothing is read.
  7766.  
  7767.   You must make sure that buffer has enough room to hold all of the attributes
  7768.   read in.
  7769.  
  7770.  
  7771.   Example:
  7772.  
  7773.   #include "window.h"
  7774.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7775.  
  7776.   VWPOINTER vw;
  7777.   char buf[14] = {0};      /* Null all elements of buf */
  7778.  
  7779.   main()
  7780.   {
  7781.     int i;
  7782.     WindowInitializeSystem();
  7783.     WindowSaveInitial(0);
  7784.     vw = VirtualInitialize(ATTRIBUTE,10,80,NORM);
  7785.     VirtualReadAttributes(vw,buf,1,1,13);      /* Read attributes */
  7786.   }
  7787.  
  7788.   The example above illustrates the use of VirtualReadAttributes(), which reads
  7789.   the virtual window's attribute contents starting at (1,1) of the virtual
  7790.   window.
  7791.  
  7792.  
  7793.  Page 128                     The C Window Library                    Page 128
  7794.  
  7795.   If the length exceeds the right edge of the virtual window,
  7796.   VirtualReadAttributes() will read up to the right edge of the virtual window.
  7797.  
  7798.  
  7799.   If there are no errors, VirtualReadAttributes() returns NO_ERROR.
  7800.  
  7801.   If there are errors, VirtualReadAttributes() returns one of the following:
  7802.  
  7803.   BAD_V_WINDOW if the virtual window does not exist.
  7804.  
  7805.   V_WINDOW_BOUND if the row or column specified in the virtual window is out of
  7806.   bounds.
  7807.  
  7808.   NO_ATTRIB if the virtual window is NOATTRIBUTE.
  7809.  
  7810.  
  7811.  
  7812.  
  7813.   VirtualReadCharAndAttr()
  7814.   ------------------------
  7815.  
  7816.   The VirtualReadCharAndAttr() function reads character/attribute pairs from a
  7817.   virtual window into a buffer.  Here is the prototype.
  7818.  
  7819.   int VirtualReadCharAndAttr(VWPOINTER w, char *buffer, unsigned row,
  7820.                              unsigned col, unsigned length)
  7821.  
  7822.   The first argument is the virtual window.  The second argument is the buffer
  7823.   to store the character/attribute pairs in.  The third and fourth arguments
  7824.   are the (row,col) position in the virtual window to start reading from.  The
  7825.   last argument is the number of character/attribute pairs to read.  If the
  7826.   window is NOATTRIBUTE, nothing is read.
  7827.  
  7828.   You must make sure that buffer has enough room to hold all of the
  7829.   character/attribute pairs read in.
  7830.  
  7831.   Example:
  7832.  
  7833.   #include "window.h"
  7834.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  7835.  
  7836.   VWPOINTER vw;
  7837.   char buf[27] = {0};      /* Null all elements of buf */
  7838.  
  7839.   main()
  7840.   {
  7841.     int i;
  7842.     WindowInitializeSystem();
  7843.     WindowSaveInitial(0);
  7844.     vw = VirtualInitialize(ATTRIBUTE,10,80,NORM);
  7845.     VirtualWriteString(vw,"Hello World!!",1,1);/* Write String */
  7846.     VirtualReadCharAndAttr(vw,buf,1,1,13);      /* Read character/attributes */
  7847.   }
  7848.  
  7849.  Page 129                     The C Window Library                    Page 129
  7850.  
  7851.   The example above illustrates the use of VirtualReadCharAndAttr(), which reads
  7852.   the virtual window's character/attribute contents starting at (1,1) of the
  7853.   virtual window.  This happens to be the characters/attributes of the string
  7854.   "Hello World!!".
  7855.  
  7856.   If the length exceeds the right edge of the virtual window,
  7857.   VirtualReadCharAndAttr() will read up to the right edge of the virtual window.
  7858.  
  7859.  
  7860.   If there are no errors, VirtualReadCharAndAttr() returns NO_ERROR.
  7861.  
  7862.   If there are errors, VirtualReadCharAndAttr() returns one of the following:
  7863.  
  7864.   BAD_V_WINDOW if the virtual window does not exist.
  7865.  
  7866.   V_WINDOW_BOUND if the row or column specified in the virtual window is out of
  7867.   bounds.
  7868.  
  7869.   NO_ATTRIB if the virtual window is NOATTRIBUTE.
  7870.  
  7871.  
  7872.  
  7873.  
  7874.  
  7875.  
  7876.  
  7877.  
  7878.  
  7879.  
  7880.  
  7881.  
  7882.  
  7883.  
  7884.  
  7885.  
  7886.  
  7887.  
  7888.  
  7889.  
  7890.  
  7891.  
  7892.  
  7893.  
  7894.  
  7895.  
  7896.  
  7897.  
  7898.  
  7899.  
  7900.  
  7901.  
  7902.  
  7903.  
  7904.  
  7905.  Page 130                     The C Window Library                    Page 130
  7906.  
  7907.                           REPOSITIONING THE VIEWPORT
  7908.                           --------------------------
  7909.  
  7910.   A viewport can be repositioned anywhere on the virtual window.  This allows
  7911.   to view different parts of the virtual window.
  7912.  
  7913.  
  7914.   WindowPositionViewport()
  7915.   ------------------------
  7916.  
  7917.   The WindowPositionViewport() function positions the viewport to a new
  7918.   location on the virtual window it is associated with.  Here is the prototype:
  7919.  
  7920.  
  7921.      int WindowPositionViewport(WPOINTER w, unsigned row, unsigned col)
  7922.  
  7923.   The first argument is the viewport window.  The second argument and third
  7924.   arguments are is the (row,col) position of the virtual window associated with
  7925.   w.  This position will be where the upper left hand corner of the viewport's
  7926.   text area will be placed.
  7927.  
  7928.  
  7929.   Example:
  7930.  
  7931.   #include <stdio.h>
  7932.   #include <string.h>
  7933.   #include "window.h"
  7934.  
  7935.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  7936.  
  7937.                     /* define filename characters */
  7938.   #define FILENAMECHARS  "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  7939.  
  7940.   VWPOINTER vw;          /* virtual window pointer */
  7941.   WPOINTER w;            /* Window pointer */
  7942.   char filename[26];
  7943.   FILE *infile;          /* input file handle */
  7944.  
  7945.   main()
  7946.   {
  7947.     unsigned int i,j,row,col;
  7948.     WindowInitializeSystem();
  7949.     WindowSaveInitial(0);
  7950.  
  7951.     /* set up a Type 0 virtual window */
  7952.     vw = VirtualInitialize(NOATTRIBUTE,  /* virtual window type number */
  7953.                            200,      /* Number of rows */
  7954.                            80,      /* Number of cols */
  7955.                            0);      /* Attribute      */
  7956.  
  7957.  
  7958.  
  7959.  
  7960.  
  7961.  Page 131                     The C Window Library                    Page 131
  7962.  
  7963.     /* set up viewport window */
  7964.     w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  7965.     WindowOpen(w);
  7966.     WindowDisplay(w,1,NOEFFECT);
  7967.  
  7968.     /* read a file name */
  7969.     read_file();
  7970.  
  7971.     /* display file in viewport */
  7972.     WindowAssignToVirtual(w,vw,1,1);    /* Assign viewport to virtual window */
  7973.  
  7974.     row = col = 1;
  7975.     flush_keyboard_flag = TRUE;        /* Set keyboard flush to TRUE */
  7976.     while (1)
  7977.     {
  7978.       switch (GET_KEY())    /* Keep getting keys until ESCAPE key is hit */
  7979.       {
  7980.          case UARROW:      /* Move viewport up 1 line */
  7981.  
  7982.            if (row > 1)
  7983.              WindowPositionViewport(w,--row,col);
  7984.          break;
  7985.          case DARROW:      /* Move viewport down 1 line */
  7986.            if (row < 189)
  7987.              WindowPositionViewport(w,++row,col);
  7988.          break;
  7989.          case LARROW:      /* Move viewport left 1 line */
  7990.            if (col > 1)
  7991.              WindowPositionViewport(w,row,--col);
  7992.          break;
  7993.          case RARROW:      /* Move viewport right 1 line */
  7994.            if (col < 69)
  7995.              WindowPositionViewport(w,row,++col);
  7996.          break;
  7997.          case ESC:         /* End program */
  7998.            close_all();
  7999.          break;
  8000.       }
  8001.     }
  8002.   }
  8003.  
  8004.  
  8005.  
  8006.  
  8007.  
  8008.  
  8009.  
  8010.  
  8011.  
  8012.  
  8013.  
  8014.  
  8015.  
  8016.  
  8017.  Page 132                     The C Window Library                    Page 132
  8018.  
  8019.   read_file()         /* Gets a filename and displays it in the window */
  8020.   {
  8021.      int ch;
  8022.      unsigned r = 1, c = 1;
  8023.      filename[0] = 0;
  8024.      WindowWriteString(w,"Please enter a file name: ",1,1);
  8025.      WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  8026.      if ((infile = fopen(filename,"r")) == NULL)
  8027.      {
  8028.        WindowMoveCursor(w,3,1);
  8029.        WindowPrintf(w,"File name %s does not exist\nPress a key to continue",
  8030.                 filename);
  8031.        GET_KEY();
  8032.        close_all();
  8033.      }
  8034.      else
  8035.      while(1)         /* Read characters into virtual window */
  8036.      {
  8037.        ch = fgetc(infile);
  8038.        if (feof(infile))
  8039.          break;
  8040.        if (ch != '\n')
  8041.          VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  8042.        else
  8043.        {
  8044.          r++;
  8045.          c=1;
  8046.  
  8047.        }
  8048.      }
  8049.      fclose(infile);
  8050.   }
  8051.  
  8052.  
  8053.  
  8054.   close_all()
  8055.   {
  8056.     WindowClose(w,NOEFFECT);
  8057.     exit(0);
  8058.   }
  8059.  
  8060.  
  8061.   The above example reads in a text file and uses WindowPositionViewport() to
  8062.   move left, right, up, or down.  There is no checking to see if you have
  8063.   scrolled past the end of the file.
  8064.  
  8065.   The read_file() function reads a file and copies each character in the file to
  8066.   the virtual window called vw.
  8067.  
  8068.   In the main program, the global variable flush_keyboard_flag (which is defined
  8069.   on page 280) is set to TRUE.  When flush_keyboard is TRUE, the keyboard buffer
  8070.   is flushed before any incoming keystrokes are accepted.  Otherwise the
  8071.   keyboard buffer is not flushed.
  8072.  
  8073.  Page 133                     The C Window Library                    Page 133
  8074.  
  8075.   In the while(1) loop of the main program, the constants UARROW, DARROW,
  8076.   LARROW, and RARROW, stands for the up, down, left, and the right arrow keys on
  8077.   the keypad, respectively.  The constants UARROW, DARROW, LARROW, and RARROW
  8078.   are defined in keycodes.h.  Depending on the key that is hit, the viewport is
  8079.   repositioned to point to a new row or column.  The call to
  8080.   WindowPositionViewport() has three arguments.  The first is the pointer to the
  8081.   viewport window, the second and the third are the row and the column of the
  8082.   virtual window to place the upper left hand corner of the viewport.
  8083.  
  8084.   There is minimal bounds checking in the above example, however you can enhance
  8085.   it by putting in more bounds checking and by implementing a page down, or page
  8086.   up function.
  8087.  
  8088.  
  8089.   If there are no errors, WindowPositionViewport() returns NO_ERROR.
  8090.   If there are errors, WindowPositionViewport() will return one of the
  8091.   following values:
  8092.  
  8093.   BAD_WINDOW if the viewport window does not exist.
  8094.  
  8095.   BAD_V_WINDOW if the viewport is pointing to a virtual window that does not
  8096.   exist.
  8097.  
  8098.   V_WINDOW_BOUND if the row and col arguments are out of bounds of the virtual
  8099.   window.
  8100.  
  8101.  
  8102.  
  8103.  
  8104.  
  8105.  
  8106.  
  8107.  
  8108.  
  8109.  
  8110.  
  8111.  
  8112.  
  8113.  
  8114.  
  8115.  
  8116.  
  8117.  
  8118.  
  8119.  
  8120.  
  8121.  
  8122.  
  8123.  
  8124.  
  8125.  
  8126.  
  8127.  
  8128.  
  8129.  Page 134                     The C Window Library                    Page 134
  8130.  
  8131.                              SCROLLING THE VIEWPORTS
  8132.                              -----------------------
  8133.  
  8134.   Viewports can have its display scrolled left, right, up, or down using the
  8135.   WindowScrollViewport() function described below.
  8136.  
  8137.  
  8138.   WindowScrollViewport()
  8139.   ---------------------
  8140.  
  8141.   This functions scrolls the viewport specific number of characters.
  8142.   Here is the prototype:
  8143.  
  8144.       int WindowScrollViewport(WPOINTER w, unsigned num, int direction)
  8145.  
  8146.   The first argument is the viewport and the second argument is the number of
  8147.   characters to scroll.  The last argument is the direction to scroll.  This
  8148.   direction can be UP, DOWN, LEFT, or RIGHT.
  8149.  
  8150.  
  8151.   Example:
  8152.  
  8153.  
  8154.   #include <stdio.h>
  8155.   #include <string.h>
  8156.   #include "window.h"
  8157.  
  8158.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8159.  
  8160.                     /* define filename characters */
  8161.   #define FILENAMECHARS  "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  8162.  
  8163.   VWPOINTER vw;          /* virtual window pointer */
  8164.   WPOINTER w;            /* Window pointer */
  8165.   char filename[26];
  8166.   FILE *infile;          /* input file handle */
  8167.  
  8168.   main()
  8169.   {
  8170.     unsigned int i,j,row,col;
  8171.     WindowInitializeSystem();
  8172.     WindowSaveInitial(0);
  8173.     /* set up a Type 0 virtual window */
  8174.     vw = VirtualInitialize(NOATTRIBUTE,  /* virtual window type number */
  8175.                            200,      /* Number of rows */
  8176.                            80,      /* Number of cols */
  8177.                            0);      /* Attribute      */
  8178.  
  8179.     /* set up viewport window */
  8180.     w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  8181.     WindowOpen(w);
  8182.     WindowDisplay(w,1,NOEFFECT);
  8183.  
  8184.  
  8185.  Page 135                     The C Window Library                    Page 135
  8186.  
  8187.     /* read a file name */
  8188.     read_file();
  8189.  
  8190.     /* display file in viewport */
  8191.     WindowAssignToVirtual(w,vw,1,1);   /* Assign viewport to virtual window */
  8192.     flush_keyboard_flag = TRUE;        /* Set keyboard flush to TRUE */
  8193.     while (1)
  8194.     {
  8195.       switch (GET_KEY())    /* Keep getting keys until ESCAPE key is hit */
  8196.       {
  8197.          case UARROW:      /* Move viewport up 1 line */
  8198.            WindowScrollViewport(w,1,UP);
  8199.          break;
  8200.          case DARROW:      /* Move viewport down 1 line */
  8201.            WindowScrollViewport(w,1,DOWN);
  8202.          break;
  8203.          case LARROW:      /* Move viewport left 1 line */
  8204.            WindowScrollViewport(w,1,LEFT);
  8205.          break;
  8206.          case RARROW:      /* Move viewport right 1 line */
  8207.            WindowScrollViewport(w,1,RIGHT);
  8208.          break;
  8209.          case ESC:         /* End program */
  8210.            close_all();
  8211.          break;
  8212.       }
  8213.     }
  8214.   }
  8215.  
  8216.   read_file()         /* Gets a filename and displays it in the window */
  8217.   {
  8218.      int ch;
  8219.      unsigned r = 1, c = 1;
  8220.      filename[0]=0;
  8221.      WindowWriteString(w,"Please enter a file name: ",1,1);
  8222.      WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  8223.      if ((infile = fopen(filename,"r")) == NULL)
  8224.      {
  8225.        WindowMoveCursor(w,3,1);
  8226.        WindowPrintf(w,"File name %s does not exist\nPress a key to continue",
  8227.                 filename);
  8228.        GET_KEY();
  8229.        close_all();
  8230.      }
  8231.      else
  8232.      while(1)         /* Read characters into virtual window */
  8233.      {
  8234.        ch = fgetc(infile);
  8235.        if (feof(infile))
  8236.          break;
  8237.        if (ch != '\n')
  8238.          VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  8239.  
  8240.  
  8241.  Page 136                     The C Window Library                    Page 136
  8242.  
  8243.        else
  8244.        {
  8245.          r++;
  8246.          c=1;
  8247.  
  8248.        }
  8249.      }
  8250.      fclose(infile);
  8251.   }
  8252.  
  8253.  
  8254.  
  8255.   close_all()
  8256.   {
  8257.     WindowClose(w,NOEFFECT);
  8258.     exit(0);
  8259.   }
  8260.  
  8261.  
  8262.   The example above is the same as the example for the
  8263.   WindowPositionViewport() function, except that the call to
  8264.   WindowPositionViewport() is replaced with the appropriate
  8265.   WindowScrollViewport() call.
  8266.  
  8267.  
  8268.   For WindowScrollViewport(), the window is never scrolled if the scroll will
  8269.   result in the upper left hand corner of the viewport being out of bounds of
  8270.   the virtual window.  For example, you cannot scroll left 1 character if the
  8271.   viewport is located at (1,1) of the virtual window, similarly you cannot
  8272.   scroll right if the virtual window has a maximum of 80 characters and the
  8273.   upper left hand corner of the viewport is situated at (1,80).  The same
  8274.   restrictions apply for scrolling up and down.
  8275.  
  8276.   If there are no errors, all of the WindowScrollViewport() functions will
  8277.   return NO_ERROR.
  8278.  
  8279.   If there are errors, these functions will return the following value:
  8280.  
  8281.   V_WINDOW_BOUND if the scroll will cause the upper left hand position of the
  8282.   viewport to be out of bounds.
  8283.  
  8284.  
  8285.  
  8286.  
  8287.  
  8288.  
  8289.  
  8290.  
  8291.  
  8292.  
  8293.  
  8294.  
  8295.  
  8296.  
  8297.  Page 137                     The C Window Library                    Page 137
  8298.  
  8299.                    WRITING VIRTUAL WINDOW CONTENTS TO A FILE
  8300.                    -----------------------------------------
  8301.  
  8302.   The C Window Library allows you to print the contents of a virtual window
  8303.   using the VirtualWriteTextToFile() function.
  8304.  
  8305.  
  8306.  
  8307.   VirtualWriteTextToFile()
  8308.   ------------------------
  8309.  
  8310.   The VirtualWriteTextToFile() function allows you to print the contents of a
  8311.   virtual window to a file.  Here is the prototype:
  8312.  
  8313.   int VirtualWriteTextToFile(VWPOINTER vw, char *filename, int mode)
  8314.  
  8315.  
  8316.   The first argument is the virtual window.  The second argument is the file
  8317.   name.  This file can be any of the DOS filenames ("con", "prn", "aux", etc.).
  8318.   The file specified by filename must be closed before calling
  8319.   VirtualWriteTextToFile(), and the file handle is automatically closed before
  8320.   exiting VirtualWriteTextToFile().
  8321.  
  8322.   The last argument is the mode switch.  If mode is 1, a newline ('\n') is
  8323.   written to the file after each line of the virtual window written to the
  8324.   file.  If mode is 0, no newline character is written.  When mode 0 is chosen,
  8325.   the file is open in binary mode, else it is open in text mode.
  8326.  
  8327.   Example:
  8328.  
  8329.   #include "window.h"
  8330.  
  8331.   VWPOINTER vw;
  8332.   char *filename = "wintext";
  8333.   char *filename2 = "wintext2";
  8334.  
  8335.   main()
  8336.   {
  8337.     int i;
  8338.     WindowInitializeSystem();
  8339.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8340.     for (i=1;i<=10;i++)
  8341.       VirtualWriteString(vw,"Hello World!!",i,1);
  8342.     VirtualWriteTextToFile(vw,filename,1);  /* use newlines */
  8343.     VirtualWriteTextToFile(vw,filename2,0); /* no newlines */
  8344.   }
  8345.  
  8346.   The example above illustrates two calls to VirtualWriteTextToFile().  The
  8347.   first call writes the contents of the virtual window vw to a file called
  8348.   "wintext".  Note that the mode parameter for the first call is 1.  This will
  8349.   cause '\n' to be written to the file for each line of the virtual window.
  8350.   The second call writes the virtual window text to a file call "wintest2",
  8351.   with the mode parameter being 0 (no '\n').
  8352.  
  8353.  Page 138                     The C Window Library                    Page 138
  8354.  
  8355.   Please note that VirtualWriteTextToFile() does not check if the file already
  8356.   exists, so be careful that you do not replace files that are important to
  8357.   you.
  8358.  
  8359.  
  8360.  
  8361.   If there are no errors, VirtualWriteTextToFile() returns NO_ERROR.
  8362.  
  8363.   If there are errors, VirtualWriteTextToFile() will return one of the
  8364.   following:
  8365.  
  8366.  
  8367.   BAD_V_WINDOW if the virtual window does not exist.
  8368.  
  8369.   FILE_CANT_OPEN if the file specified by filename cannot be open.
  8370.  
  8371.   FILE_CANT_CLOSE if the file specified by filename cannot be closed.
  8372.  
  8373.  
  8374.  
  8375.  
  8376.  
  8377.  
  8378.  
  8379.  
  8380.  
  8381.  
  8382.  
  8383.  
  8384.  
  8385.  
  8386.  
  8387.  
  8388.  
  8389.  
  8390.  
  8391.  
  8392.  
  8393.  
  8394.  
  8395.  
  8396.  
  8397.  
  8398.  
  8399.  
  8400.  
  8401.  
  8402.  
  8403.  
  8404.  
  8405.  
  8406.  
  8407.  
  8408.  
  8409.  Page 139                     The C Window Library                    Page 139
  8410.  
  8411.                            MOVING THE LOGICAL CURSOR
  8412.                            -------------------------
  8413.  
  8414.   You can move and get the position of the logical cursor in a virtual window.
  8415.  
  8416.  
  8417.  
  8418.   VirtualMoveCursor()
  8419.   -------------------
  8420.  
  8421.   The VirtualMoveCursor() function moves a virtual window's logical cursor to a
  8422.   new location.  Here is the prototype:
  8423.  
  8424.      int VirtualMoveCursor(VWPOINTER vw, unsigned row, unsigned col)
  8425.  
  8426.   The first argument is the virtual window, and the second and third arguments
  8427.   denote the new (row,col) position of the logical cursor.
  8428.  
  8429.   Example:
  8430.  
  8431.   #include "window.h"
  8432.  
  8433.   VWPOINTER vw;
  8434.  
  8435.   main()
  8436.   {
  8437.     int i;
  8438.     WindowInitializeSystem();
  8439.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8440.     VirtualMoveCursor(vw,10,10);  /* Moves the logical cursor to row 10, column
  8441.                                      10 of the virtual window */
  8442.   }
  8443.  
  8444.   If there are no errors, VirtualMoveCursor() returns NO_ERROR.
  8445.   If there are errors, VirtualMoveCursor() returns one of the following values:
  8446.  
  8447.   BAD_V_WINDOW if the virtual window does not exist.
  8448.  
  8449.   V_WINDOW_BOUND if either the row or column specified is out of bounds.
  8450.  
  8451.  
  8452.  
  8453.  
  8454.   VirtualGetCursorPosition()
  8455.   --------------------------
  8456.  
  8457.   The VirtualGetCursorPosition() function gives the current row and column of
  8458.   the cursor in a virtual window.  Here is the prototype:
  8459.  
  8460.     int VirtualGetCursorPosition(VWPOINTER vw, unsigned *row, unsigned *col)
  8461.  
  8462.   The row and col arguments are pointers to unsigned integers that will contain
  8463.   the row and column of the cursor after VirtualGetCursorPosition() is called.
  8464.  
  8465.  Page 140                     The C Window Library                    Page 140
  8466.  
  8467.   Example:
  8468.  
  8469.   #include "window.h"
  8470.  
  8471.   VWPOINTER vw;
  8472.  
  8473.   main()
  8474.   {
  8475.     unsigned row,col;
  8476.     WindowInitializeSystem();
  8477.     vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8478.     VirtualMoveCursor(vw,7,4);
  8479.     VirtualGetCursorPosition(vw,&row,&col);
  8480.   }
  8481.  
  8482.   If there are no errors, VirtualGetCursorPosition() returns NO_ERROR.
  8483.   If there are errors, VirtualGetCursorPosition() returns the following value:
  8484.  
  8485.   BAD_V_WINDOW if the window does not exist.
  8486.  
  8487.  
  8488.  
  8489.  
  8490.  
  8491.  
  8492.  
  8493.  
  8494.  
  8495.  
  8496.  
  8497.  
  8498.  
  8499.  
  8500.  
  8501.  
  8502.  
  8503.  
  8504.  
  8505.  
  8506.  
  8507.  
  8508.  
  8509.  
  8510.  
  8511.  
  8512.  
  8513.  
  8514.  
  8515.  
  8516.  
  8517.  
  8518.  
  8519.  
  8520.  
  8521.  Page 141                     The C Window Library                    Page 141
  8522.  
  8523.                            CLEARING VIRTUAL WINDOWS
  8524.                            ------------------------
  8525.  
  8526.  
  8527.   The C Window Library contains functions that clears the entire virtual
  8528.   window, or clears defined rectangular regions of the virtual window.
  8529.  
  8530.  
  8531.   VirtualClear()
  8532.   --------------
  8533.  
  8534.   The VirtualClear() function clears an entire virtual window to spaces.  Here
  8535.   is the prototype:
  8536.  
  8537.                       int VirtualClear(VWPOINTER vw)
  8538.  
  8539.   The only argument is the virtual window to clear.
  8540.  
  8541.   Example:
  8542.  
  8543.   #include "window.h"
  8544.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8545.  
  8546.   VWPOINTER vw;
  8547.   WPOINTER w;
  8548.  
  8549.   main()
  8550.   {
  8551.     int i;
  8552.     WindowInitializeSystem();
  8553.     WindowSaveInitial(0);
  8554.     w = WindowInitialize(BORDER,1,1,20,10,NORM,NORM,SINGLEBOX);
  8555.     vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  8556.     WindowOpen(w);
  8557.     WindowDisplay(w,1,NOEFFECT);
  8558.     WindowAssignToVirtual(w,vw,1,1);
  8559.     for (i=1;i<=10;i++)
  8560.       VirtualWriteString(vw,"Hello World!!",i,1);
  8561.     GET_KEY();
  8562.     VirtualClear(vw);
  8563.   }
  8564.  
  8565.   If there is no error, VirtualClear() returns NO_ERROR.
  8566.  
  8567.   If there is an error, VirtualClear() returns the following values:
  8568.  
  8569.   BAD_V_WINDOW if the virtual window does not exist.
  8570.  
  8571.  
  8572.  
  8573.  
  8574.  
  8575.  
  8576.  
  8577.  Page 142                     The C Window Library                    Page 142
  8578.  
  8579.   VirtualClearAttr()
  8580.   ------------------
  8581.  
  8582.   The VirtualClearAttr() function works the same way as the VirtualClear()
  8583.   function except that an attribute is specified.  Here is the prototype:
  8584.  
  8585.               int VirtualClearAttr(VWPOINTER vw, int attr)
  8586.  
  8587.   The second argument is the video attribute to use.  If the virtual window is
  8588.   NOATTRIBUTE, this function only clears the text.
  8589.  
  8590.   Example:
  8591.  
  8592.   #include "window.h"
  8593.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8594.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  8595.   WPOINTER w;
  8596.   VWPOINTER vw;
  8597.  
  8598.   main()
  8599.   {
  8600.     int i;
  8601.     WindowInitializeSystem();
  8602.     WindowSaveInitial(0);
  8603.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  8604.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8605.     WindowOpen(w);
  8606.     WindowDisplay(w,1,NOEFFECT);
  8607.     WindowAssignToVirtual(w,vw,1,1);
  8608.     for (i=1;i<=10;i++)
  8609.       VirtualWriteString(vw,"Hello World!!",i,1);
  8610.     GET_KEY();
  8611.     VirtualClearAttr(vw,REVERSE);
  8612.   }
  8613.  
  8614.   The return values for VirtualClearAttr() are the same as VirtualClear(),
  8615.   except for the following error:
  8616.  
  8617.     NO_ATTRIB if the virtual window is NOATTRIBUTE.
  8618.  
  8619.  
  8620.   VirtualClearRegion()
  8621.   -------------------
  8622.  
  8623.   The VirtualClearRegion() function clears a region of a virtual window.  To
  8624.   use the VirtualClearRegion() function, you must describe the rectangular
  8625.   region to clear.  Here is the prototype:
  8626.  
  8627.   int VirtualClearRegion(VWPOINTER vw, unsigned urow, unsigned ucol,
  8628.                          unsigned lrow, unsigned lcol)
  8629.  
  8630.   where (urow,ucol) describes the upper left of the rectangle and (lrow,lcol)
  8631.   is the lower right of the virtual window.
  8632.  
  8633.  Page 143                     The C Window Library                    Page 143
  8634.  
  8635.   Example:
  8636.  
  8637.   #include "window.h"
  8638.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8639.   WPOINTER w;
  8640.   VWPOINTER vw;
  8641.  
  8642.   main()
  8643.   {
  8644.     int i;
  8645.     WindowInitializeSystem();
  8646.     WindowSaveInitial(0);
  8647.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  8648.     vw = VirtualInitialize(NOATTRIBUTE,30,80,NORM);
  8649.     WindowOpen(w);
  8650.     WindowDisplay(w,1,NOEFFECT);
  8651.     WindowAssignToVirtual(w,vw,1,1);
  8652.     for (i=1;i<=10;i++)
  8653.       VirtualWriteString(vw,"Hello World!!",i,1);
  8654.     GET_KEY();
  8655.     VirtualClearRegion(vw,4,4,8,15);
  8656.   }
  8657.  
  8658.  
  8659.   The VirtualClearRegion() call will clear the region described by the
  8660.   rectangular coordinates (4,4) and (8,15).
  8661.  
  8662.   If there is no error, VirtualClearRegion() returns NO_ERROR.
  8663.  
  8664.   If there is an error, the VirtualClearRegion() function will return the
  8665.   following values:
  8666.  
  8667.   BAD_V_WINDOW if the VWPOINTER vw does not exist.
  8668.  
  8669.   V_WINDOW_BOUND if the rectangular region defined is out of bounds of the
  8670.                  virtual window.
  8671.  
  8672.  
  8673.  
  8674.  
  8675.  
  8676.   VirtualClearRegionAttr()
  8677.   ------------------------
  8678.  
  8679.   The VirtualClearRegionAttr() function works the same as the
  8680.   VirtualClearRegion() function, except that a video attribute is specified.
  8681.   Here is the prototype:
  8682.  
  8683.   int VirtualClearRegionAttr(VWPOINTER vw, unsigned urow, unsigned ucol,
  8684.                              unsigned lrow, unsigned lcol, int attr)
  8685.  
  8686.   The attr argument is a video attribute to use to clear the region.  If the
  8687.   virtual window is NOATTRIBUTE, the attribute argument is ignored.
  8688.  
  8689.  Page 144                     The C Window Library                    Page 144
  8690.  
  8691.   Example:
  8692.  
  8693.   #include "window.h"
  8694.   #define NORM   CREATE_VIDEO_ATTRIBUTE(black,white)
  8695.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  8696.   WPOINTER w;
  8697.   VWPOINTER vw;
  8698.  
  8699.   main()
  8700.   {
  8701.     int i;
  8702.     WindowInitializeSystem();
  8703.     WindowSaveInitial(0);
  8704.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  8705.     vw = VirtualInitialize(ATTRIBUTE,30,80,NORM);
  8706.     WindowOpen(w);
  8707.     WindowDisplay(w,1,NOEFFECT);
  8708.     WindowAssignToVirtual(w,vw,1,1);
  8709.     for (i=1;i<=10;i++)
  8710.       VirtualWriteString(vw,"Hello World!!",i,1);
  8711.     GET_KEY();
  8712.     VirtualClearRegionAttr(vw,4,4,8,15,REVERSE);
  8713.   }
  8714.  
  8715.  
  8716.   The VirtualClearRegionAttr() call will clear the region described by the
  8717.   rectangular coordinates (4,4) and (8,15) using the video attribute defined
  8718.   by the constant REVERSE.
  8719.  
  8720.   The VirtualClearRegionAttr() returns the same values as VirtualClearRegion()
  8721.   with an additional error condition:
  8722.  
  8723.     NO_ATTRIB if the virtual window is NOATTRIBUTE.
  8724.  
  8725.  
  8726.  
  8727.  
  8728.  
  8729.  
  8730.  
  8731.  
  8732.  
  8733.  
  8734.  
  8735.  
  8736.  
  8737.  
  8738.  
  8739.  
  8740.  
  8741.  
  8742.  
  8743.  
  8744.  
  8745.  Page 145                     The C Window Library                    Page 145
  8746.  
  8747.                               FREEZING VIEWPORTS
  8748.                               ------------------
  8749.  
  8750.  
  8751.   You can temporarily suspend or 'freeze' a viewport window from displaying
  8752.   updates to the virtual window.  This is good if there is data being written
  8753.   to the virtual window which takes a long time to generate.  The viewport can
  8754.   be frozen when the information is being written, and unfrozen when the
  8755.   writing of the data is terminated.
  8756.  
  8757.  
  8758.   WindowFreeze()
  8759.   --------------
  8760.  
  8761.   The WindowFreeze() function suspends or resumes displaying of virtual window
  8762.   updates on a viewport window.  Here is the prototype:
  8763.  
  8764.        int WindowFreeze(WPOINTER w, int option)
  8765.  
  8766.   The first argument is the viewport window, and the second argument is the
  8767.   option flag.  If this flag is 0, the window is unfrozen, i.e. the window will
  8768.   display virtual window updates.  If it is 1, the window will suspend virtual
  8769.   window updates from being displayed.
  8770.  
  8771.   Example:
  8772.  
  8773.   #include "window.h"
  8774.  
  8775.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8776.  
  8777.   VWPOINTER vw;
  8778.   WPOINTER w;
  8779.  
  8780.   main()
  8781.   {
  8782.     int i;
  8783.     WindowInitializeSystem();
  8784.     WindowSaveInitial(0);
  8785.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  8786.     vw = VirtualInitialize(NOATTRIBUTE,10,80,NORM);
  8787.     WindowOpen(w);
  8788.     WindowAssignToVirtual(w,vw,1,1);
  8789.     WindowDisplay(w,1,NOEFFECT);
  8790.     /* Freeze Viewport */
  8791.     WindowFreeze(w,1);
  8792.     for (i=1;i<=10;i++)
  8793.     {
  8794.       delay(1000);
  8795.       VirtualPrintf(vw,"Line %d\n",i);
  8796.     }
  8797.     /* Unfreeze window */
  8798.     WindowFreeze(w,0);
  8799.     GET_KEY();
  8800.  
  8801.  Page 146                     The C Window Library                    Page 146
  8802.  
  8803.     /* Now try with window always displaying data */
  8804.     VirtualClear(vw);
  8805.     for (i=1;i<=10;i++)
  8806.     {
  8807.       delay(1000);
  8808.       VirtualPrintf(vw,"Line %d\n",i);
  8809.     }
  8810.   }
  8811.  
  8812.  
  8813.  
  8814.   The above program first freezes the viewport w with the first call to
  8815.   WindowFreeze().  Then text is written slowly to the virtual window vw.  This
  8816.   text is not displayed until the window is unfrozen again with the second call
  8817.   to WindowFreeze().  Everything is reset and the writing of the text to the
  8818.   virtual window is done again, but this time the viewport is always displaying
  8819.   virtual window updates, even when the text is being written to the virtual
  8820.   window.
  8821.  
  8822.   The delay() function is discussed on page 264.
  8823.  
  8824.  
  8825.   If there is no error WindowFreeze() returns NO_ERROR.
  8826.  
  8827.   If there are errors, WindowFreeze() returns one of the following values:
  8828.  
  8829.   BAD_WINDOW if the viewport window does not exist.
  8830.  
  8831.   BAD_V_WINDOW if the virtual window that the viewport is displaying does not
  8832.   exist.
  8833.  
  8834.  
  8835.  
  8836.  
  8837.  
  8838.  
  8839.  
  8840.  
  8841.  
  8842.  
  8843.  
  8844.  
  8845.  
  8846.  
  8847.  
  8848.  
  8849.  
  8850.  
  8851.  
  8852.  
  8853.  
  8854.  
  8855.  
  8856.  
  8857.  Page 147                     The C Window Library                    Page 147
  8858.  
  8859.                          DISPOSING OF VIRTUAL WINDOWS
  8860.                          ----------------------------
  8861.  
  8862.  
  8863.   The last step is to dispose of the virtual window.  The function to do this
  8864.   is the VirtualFree() function.
  8865.  
  8866.  
  8867.   VirtualFree()
  8868.   -------------
  8869.  
  8870.   The VirtualFree() function frees all the memory allocated to the virtual
  8871.   window and destroys the virtual window pointer.  Here is the prototype:
  8872.  
  8873.        int VirtualFree(VWPOINTER vw, int hideflag, int effect)
  8874.  
  8875.   The first argument is the virtual window.  The second argument is a flag that
  8876.   determines whether any viewports displaying the virtual window should be
  8877.   hidden.  If this argument is 1, all viewports displaying the virtual window
  8878.   is hidden.  If the argument is 0, all viewports are cleared, but not hidden.
  8879.   The third argument is the special effect to use when hiding the viewports.
  8880.   This argument is ignored if hideflag is 0.  For a list of special effects,
  8881.   see page 14.
  8882.  
  8883.   Once VirtualFree() is called you must not use the VWPOINTER again unless you
  8884.   assign it to another virtual window, or create a new virtual window.
  8885.  
  8886.   Example:
  8887.  
  8888.    #include "window.h"
  8889.  
  8890.    #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  8891.    VWPOINTER vw;          /* virtual window pointer */
  8892.    WPOINTER w1, w2;
  8893.    main()
  8894.    {
  8895.      WindowInitializeSystem();
  8896.      WindowSaveInitial(0);
  8897.      vw = VirtualInitialize(NOATTRIBUTE,30,80,0);
  8898.      w1 = WindowInitialize(BORDER,1, 1,20,12,NORM,NORM,SINGLEBOX);
  8899.      w2 = WindowInitialize(BORDER,13,1,20,10,NORM,NORM,DOUBLEBOX);
  8900.      WindowOpen(w1);
  8901.      WindowOpen(w2);
  8902.      WindowDisplay(w1,1,NOEFFECT);
  8903.      WindowDisplay(w2,2,NOEFFECT);
  8904.      VirtualWriteString(vw,"This is a string",1,1);/* Write string to
  8905.                                                        virtual window */
  8906.      WindowAssignToVirtual(w1,vw,1,1); /* Assign viewport to virtual window */
  8907.      WindowAssignToVirtual(w2,vw,1,1); /* Assign viewport to virtual window */
  8908.      GET_KEY();
  8909.      VirtualFree(vw,1,NOEFFECT);  /* Destroy virtual window and hide
  8910.                                      w1,w2 */
  8911.    }
  8912.  
  8913.  Page 148                     The C Window Library                    Page 148
  8914.  
  8915.    If there are no errors, VirtualFree() returns NO_ERROR.
  8916.  
  8917.    If there are errors, VirtualFree() returns the following value:
  8918.  
  8919.    BAD_V_WINDOW if the virtual window does not exist.
  8920.  
  8921.  
  8922.  
  8923.  
  8924.  
  8925.  
  8926.  
  8927.  
  8928.  
  8929.  
  8930.  
  8931.  
  8932.  
  8933.  
  8934.  
  8935.  
  8936.  
  8937.  
  8938.  
  8939.  
  8940.  
  8941.  
  8942.  
  8943.  
  8944.  
  8945.  
  8946.  
  8947.  
  8948.  
  8949.  
  8950.  
  8951.  
  8952.  
  8953.  
  8954.  
  8955.  
  8956.  
  8957.  
  8958.  
  8959.  
  8960.  
  8961.  
  8962.  
  8963.  
  8964.  
  8965.  
  8966.  
  8967.  
  8968.  
  8969.  Page 149                     The C Window Library                    Page 149
  8970.  
  8971.                           INTRODUCTION TO MENU SYSTEM
  8972.                           ---------------------------
  8973.  
  8974.   Menu systems are important entities in any program.  The C Window Library has
  8975.   functions that create popup, pull-down, and bar menus.  The popup menus are
  8976.   scrollable menus with a limit of 65,535 selections.  The bar menus can have
  8977.   any number of entries.  As of this version, the bar menus are not scrollable,
  8978.   although there will be an implementation of scrolling bar menus in a future
  8979.   version.  The pull-down menus are a combination of popup and bar menus.
  8980.   You can change entries, hide entries, use hotkeys to invoke a menu entry,
  8981.   and many more things.
  8982.  
  8983.  
  8984.   Menu Manager
  8985.   ------------
  8986.  
  8987.   The menu manager is the code in The C Window Library that handles moving the
  8988.   highlight bar in the menu, calling the menu functions when they are selected,
  8989.   keeps tracks of available entries, and other functions that keep track of the
  8990.   menu when selections are made.
  8991.  
  8992.  
  8993.  
  8994.   Necessary "include" files
  8995.   -------------------------
  8996.  
  8997.   To use the menu system in your program, you must include the "menu.h" file
  8998.   supplied.  This file automatically includes the "window.h" file, therefore
  8999.   you do not have to include "window.h" when you use "menu.h".
  9000.  
  9001.  
  9002.  
  9003.  
  9004.  
  9005.  
  9006.  
  9007.  
  9008.  
  9009.  
  9010.  
  9011.  
  9012.  
  9013.  
  9014.  
  9015.  
  9016.  
  9017.  
  9018.  
  9019.  
  9020.  
  9021.  
  9022.  
  9023.  
  9024.  
  9025.  
  9026.  Page 150                     The C Window Library                    Page 150
  9027.  
  9028.                                POP-UP MENUS
  9029.                                ------------
  9030.  
  9031.  
  9032.   Description
  9033.   -----------
  9034.  
  9035.   A popup menu is a vertical menu with a list of entries that are selected by
  9036.   placing a highlight bar on the entry and pressing return, or by invoking the
  9037.   function by using a hotkey.  Pop-up menus can be scrollable, in other words,
  9038.   if there are more entries than can be displayed in the window, the menu will
  9039.   scroll through the rest of the selections.  You can have up to 65,535
  9040.   selections in the popup menu.
  9041.  
  9042.   Here is a partial list of the various options you can have with popup menus:
  9043.  
  9044.      * Highlight bar wrapping - wrap highlight bar to first or last option
  9045.                                 when there are no more selections.
  9046.  
  9047.      * Static Menus - menu remains on the screen when entry is selected.
  9048.  
  9049.      * Perpetual Menus - menu remain on the screen regardless of whether the
  9050.        PopupSelectMenu() function (explained later) is called or not.
  9051.  
  9052.      * Hidden (Unavailable) entries - You can make an entry in the popup menu
  9053.                                       unavailable or available at any time.
  9054.  
  9055.      * Color scheme of the menu - You can customize the color of the highlight
  9056.                                   bar, the hotkey letters, hidden entries,
  9057.                                   etc.
  9058.  
  9059.      * Change entry names   - You can safely change the names displayed in
  9060.                                the menu at any time.
  9061.  
  9062.  
  9063.  
  9064.  
  9065.   Windows and Virtual Windows
  9066.   ---------------------------
  9067.  
  9068.   Pop-up menus use virtual windows to write menu selections, and use normal
  9069.   windows to display the selections.  This method of using virtual windows
  9070.   enables the menu manager to scroll through the menu selections if the window
  9071.   is not tall enough to display all of the selections.
  9072.  
  9073.  
  9074.  
  9075.  
  9076.  
  9077.  
  9078.  
  9079.  
  9080.  
  9081.  
  9082.  Page 151                     The C Window Library                    Page 151
  9083.  
  9084.                              CREATING POP-UP MENUS
  9085.                              ---------------------
  9086.  
  9087.  
  9088.   The POPUP_MENU_ENTRY structure
  9089.   ------------------------------
  9090.  
  9091.   The two most important parts of the popup menu are the POPUP_MENU_ENTRY
  9092.   structure and the POPUP_MENU_PTR structure.  The POPUP_MENU_ENTRY structure
  9093.   is the first step in creating a popup menu and is discussed here.
  9094.  
  9095.   Each entry in the popup menu has its own POPUP_MENU_ENTRY structure
  9096.   associated with it.  The layout of this structure is as follows:
  9097.  
  9098.  
  9099.  
  9100.   char     *entry_name    -- This is the string that is displayed in the
  9101.                               popup virtual window.
  9102.  
  9103.   unsigned  row            -- Row in the virtual window to display entry_name.
  9104.  
  9105.   char      hotkey_letter  -- This is a character in entry_name that is
  9106.                               highlighted from the rest of the characters in
  9107.                               entry_name.  This letter will automatically
  9108.                               invoke the menu function associated with
  9109.                               entry_name.
  9110.  
  9111.   unsigned  ext_hotkey     -- This is a secondary hotkey.  The difference
  9112.                               between hotkey_letter and ext_hotkey is that
  9113.                               ext_hotkey can handle keys that are not ASCII keys
  9114.                               (the F keys, Alt and Ctrl key combinations, etc.).
  9115.  
  9116.   int (*func)()            -- Pointer to function that is invoked when option
  9117.                               is selected.
  9118.  
  9119.   An array of POPUP_MENU_ENTRY's are needed to create all of the entries on the
  9120.   popup menu.  The order of the array elements determine the order of how they
  9121.   are placed in the virtual window.  A code sample to create an array of
  9122.   POPUP_MENU_ENTRY's would be as follows:
  9123.  
  9124.   #include "menu.h"
  9125.   int menu_func();
  9126.  
  9127.   POPUP_MENU_ENTRY menu_items[] = {
  9128.                                   " Load      F3", /* entry name */
  9129.                                     1,             /* row number */
  9130.                                    'L',            /* hotkey */
  9131.                                     F3,            /* secondary hotkey */
  9132.                                     menu_func,     /* function to call if
  9133.                                                       chosen */
  9134.  
  9135.  
  9136.  
  9137.  
  9138.  Page 152                     The C Window Library                    Page 152
  9139.  
  9140.                                  /* now do rest of the popup entries */
  9141.  
  9142.                                   " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  9143.                                   " New"         ,3, 'N',0,menu_func,
  9144.                                   " Save      F2",4, 'S',F2,menu_func,
  9145.                                   " Write to    ",5, 'W',0,menu_func,
  9146.                                   " Directory   ",6, 'D',0,menu_func,
  9147.                                   " Change Dir"  ,7, 'C',0,menu_func,
  9148.                                   " OS shell"    ,8, 'O',0,menu_func,
  9149.                                   " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  9150.  
  9151.                                  /* Terminate with a CWL_NULL and 0 */
  9152.                                   CWL_NULL,0};
  9153.  
  9154.  
  9155.   The first include file, menu.h, is must be included in each source file that
  9156.   calls menu functions.
  9157.  
  9158.   As you can see, there is an array of POPUP_MENU_ENTRY's, namely menu_items.
  9159.   Each entry consists of an entry name, row number, hotkey letter, secondary
  9160.   hotkey, and a function to call when the entry is selected.  The list of
  9161.   POPUP_MENU_ENTRY's MUST be terminated by a CWL_NULL entry name, and a row
  9162.   number of 0. If this rule is violated, the menu manager will not know where
  9163.   the last entry is, and will cause chaos when the program is run.
  9164.  
  9165.   If you are an advanced C programmer, you will no doubt find other ways in
  9166.   creating the array of POPUP_MENU_ENTRY's.  Other methods would be by dynamic
  9167.   allocation, reading in the entries from a disk file, etc.  The above example
  9168.   illustrates the easiest way to create the POPUP_MENU_ENTRY's.
  9169.  
  9170.  
  9171.  
  9172.   Defining Hotkeys
  9173.   ----------------
  9174.  
  9175.   The hotkey_letter defined in the POPUP_MENU_ENTRY structure must match one of
  9176.   the letters in its corresponding entry_name.  For example, " Load     F3",
  9177.   has the hotkey_letter defined as 'L'.  Since 'L' matches the first letter in
  9178.   " Load     F3",  the first 'L' in " Load     F3" is highlighted.  If there is
  9179.   no match, or if the hotkey_letter is 0, there is no hotkey associated with
  9180.   this option.  When the menu is displayed, either the 'l' or 'L' will be
  9181.   accepted as a valid selection to the entry " Load     F3".   If there is a
  9182.   POPUP_MENU_ENTRY with the same hotkey letter as another POPUP_MENU_ENTRY, the
  9183.   POPUP_MENU_ENTRY closest to the first entry is chosen.
  9184.  
  9185.   The ext_hotkey is used if the hotkey cannot be defined as a single character,
  9186.   or if you want another hotkey definition.  In the above example, the
  9187.   " Load     F3" entry_name has an ext_hotkey of F3 (defined in keycodes.h).
  9188.   If the F3 key is pressed, the function menu_func() is automatically invoked.
  9189.   If the ext_hotkey letter is 0, there is no ext_hotkey defined.  If there is a
  9190.   POPUP_MENU_ENTRY with the same ext_hotkey as another POPUP_MENU_ENTRY, the
  9191.   POPUP_MENU_ENTRY closest to the first entry is chosen.
  9192.  
  9193.  
  9194.  Page 153                     The C Window Library                    Page 153
  9195.  
  9196.   Assigning the function to perform
  9197.   ---------------------------------
  9198.  
  9199.   The func() member is the function that is performed when its corresponding
  9200.   entry_name is chosen.  More information on what is passed to this function
  9201.   when it is called is on page 163
  9202.  
  9203.   This is the first step in completing the total popup menu.  Once the array of
  9204.   POPUP_MENU_ENTRY's is created the next step is to define the colors for each
  9205.   element of the popup menu.
  9206.  
  9207.  
  9208.  
  9209.   Coloring Popup Menus
  9210.   --------------------
  9211.  
  9212.   An array of unsigned integers is used to define the color scheme of the popup
  9213.   menu.  Each element of this array stands for a certain area of the popup
  9214.   menu.  Here is a list of array positions and what they stand for.
  9215.  
  9216.   Position
  9217.   Constant
  9218.   --------
  9219.  
  9220.   ENTRYCOLOR    --  color of the text area of the viewport window.
  9221.   BORDERCOLOR    --  color of the border of the viewport window.
  9222.   HOTKEYCOLOR    --  color of the hotkey letter.
  9223.   HIGHLIGHTCOLOR --  color of the highlight bar.
  9224.   UNAVAILCOLOR   --  color of the unavailable entries.
  9225.  
  9226.   Position ENTRYCOLOR of the array defines the color of the text area of the
  9227.   viewport window.  This in turn defines the color of each entry_name of all
  9228.   of the POPUP_MENU_ENTRY's.
  9229.  
  9230.   Position BORDERCOLOR defines the color of the border of the viewport window.
  9231.   As was stated above, the menu is written to a virtual window, and a viewport
  9232.   is used to display the menu entries.  If the viewport window does not have a
  9233.   border, this attribute is ignored.
  9234.  
  9235.   Position HOTKEYCOLOR defines the color to use for the hotkey letter.  In the
  9236.   above example, the 'L', 'P', 'N', etc. of each respective entry_name is
  9237.   displayed using this color.
  9238.  
  9239.   Position HIGHLIGHTCOLOR defines the color used for the highlight bar.  This
  9240.   bar is moved up and down when the user is making a selection.
  9241.  
  9242.   Position UNAVAILCOLOR defines the color of the unavailable menu entries.
  9243.   Whenever a menu entry is unavailable, the entry_name string displayed takes
  9244.   on this color.
  9245.  
  9246.   Colors can be created by using the CREATE_VIDEO_ATTRIBUTE() macro described in
  9247.   on page 11.  A code sample to create the colors is as follows:
  9248.  
  9249.  
  9250.  Page 154                     The C Window Library                    Page 154
  9251.  
  9252.   #include "menu.h"
  9253.   unsigned int menu_colors[5];
  9254.  
  9255.   main()
  9256.   {
  9257.     {... code ...}
  9258.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  9259.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  9260.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  9261.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  9262.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  9263.       /* rest of the program */
  9264.   }
  9265.  
  9266.   As in creating the POPUP_MENU_ENTRY's, if you are an advanced programmer,
  9267.   you will find other ways in assigning the colors.
  9268.  
  9269.  
  9270.  
  9271.   PopupCreateMenu() function
  9272.   --------------------------
  9273.  
  9274.   Now that you have created the POPUP_MENU_ENTRY's, and defined the color
  9275.   scheme, it is time to wrap all of these loose ends in one package.  The next
  9276.   step is to call the PopupCreateMenu() function.  This function combines all
  9277.   of the POPUP_MENU_ENTRY's, the colors you have defined, and other information
  9278.   into one entity called a POPUP_MENU_PTR.
  9279.  
  9280.   A POPUP_MENU_PTR is a pointer to a popup menu structure.  Just like a
  9281.   WPOINTER is a pointer to a window, a POPUP_MENU_PTR is used to reference the
  9282.   popup menu.
  9283.  
  9284.   A prototype of the call to PopupCreateMenu() is as follows:
  9285.  
  9286.   POPUP_MENU_PTR PopupCreateMenu(POPUP_MENU_ENTRY *p, unsigned *color, int row,
  9287.                                  int col, int height, WPOINTER (*wfunc)(),
  9288.                                  VWPOINTER (*vfunc)())
  9289.  
  9290.   To illustrate how to use this call, let's use the POPUP_MENU_ENTRY's and
  9291.   colors created in the previous examples:
  9292.  
  9293.   #include "menu.h"
  9294.   int menu_func();
  9295.   POPUP_MENU_ENTRY menu_items[] = {
  9296.                                   " Load      F3", /* entry name */
  9297.                                     1,             /* row number */
  9298.                                    'L',            /* hotkey */
  9299.                                     F3,            /* secondary hotkey */
  9300.                                     menu_func,     /* function to call if
  9301.                                                       chosen */
  9302.  
  9303.                                  /* now do rest of the popup entries */
  9304.  
  9305.  
  9306.  Page 155                     The C Window Library                    Page 155
  9307.  
  9308.                                   " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  9309.                                   " New"         ,3, 'N',0,menu_func,
  9310.                                   " Save      F2",4, 'S',F2,menu_func,
  9311.                                   " Write to    ",5, 'W',0,menu_func,
  9312.                                   " Directory   ",6, 'D',0,menu_func,
  9313.                                   " Change Dir"  ,7, 'C',0,menu_func,
  9314.                                   " OS shell"    ,8, 'O',0,menu_func,
  9315.                                   " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  9316.  
  9317.  
  9318.                                  /* Terminate with a CWL_NULL and 0 */
  9319.  
  9320.                                   CWL_NULL,0};
  9321.  
  9322.   unsigned int menu_colors[5];
  9323.   POPUP_MENU_PTR p;
  9324.  
  9325.   main()
  9326.   {
  9327.     WindowInitializeSystem();          /* Initialize C Window Library */
  9328.  
  9329.    /* define colors */
  9330.  
  9331.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  9332.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  9333.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  9334.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  9335.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  9336.  
  9337.    /* create a POPUP_MENU_PTR */
  9338.  
  9339.    WindowSaveInitial(0);  /* Save initial screen    */
  9340.    p = PopupCreateMenu(menu_items,menu_colors, 10,10,9,WNULLFN,VWNULLFN);
  9341.   /* rest of the code */
  9342.   }
  9343.  
  9344.  
  9345.   In the example above there are two function calls that must be done before
  9346.   calling PopupCreateMenu().  The first mandatory function is
  9347.   WindowInitializeSystem().  The other function must be WindowSaveInitial()
  9348.   The WindowInitializeSystem() function must be called to initialize global
  9349.   variables used by the menu manager.  The WindowSaveInitial() function is a
  9350.   mandatory function because the PopupCreateMenu() function creates windows and
  9351.   virtual windows and assumes that the base screen has been saved.
  9352.  
  9353.   The example above declares the variable p to be a POPUP_MENU_PTR.  This
  9354.   POPUP_MENU_PTR is going to be used to reference the popup menu throughout the
  9355.   program.
  9356.  
  9357.   The first argument to PopupCreateMenu() is a pointer to the first
  9358.   POPUP_MENU_ENTRY.  In the above example,  menu_items is a pointer to the
  9359.   first POPUP_MENU_ENTRY.
  9360.  
  9361.  
  9362.  Page 156                     The C Window Library                    Page 156
  9363.  
  9364.   The second argument is a pointer to the array of colors.  In our example,
  9365.   menu_colors is our array of colors.
  9366.  
  9367.   The third and fourth arguments denote the row and column to place the upper
  9368.   left hand corner of the popup menu window.
  9369.  
  9370.   The fifth argument is the height of the popup menu window.  If the height of
  9371.   the window will not accommodate all of the menu items, the menu manager will
  9372.   scroll the window so that the entries that are obscured come into view.
  9373.  
  9374.   The last two arguments to PopupCreateMenu() are defined in the next sections.
  9375.  
  9376.  
  9377.   Default Popup Window and Creating Your own Windows
  9378.   --------------------------------------------------
  9379.  
  9380.   The sixth argument to the PopupCreateMenu() function is a pointer to a
  9381.   function that will open a popup menu window.  If this is a NULL function
  9382.   pointer (WNULLFN), the menu manager will create a window.  For most
  9383.   applications, the window that the menu manager will create is adequate.  The
  9384.   menu manager uses these defaults when making the popup window:
  9385.  
  9386.      - A bordered window with the border consisting of single lines (SINGLEBOX).
  9387.      - The width of the window is determined by the longest entry_name in the
  9388.        POPUP_MENU_ENTRY's.
  9389.  
  9390.   If you want to create your own popup menu window, your function must return a
  9391.   WPOINTER.  Inside your function you must create and open a window using
  9392.   WindowInitialize() and WindowOpen().  For most applications, you do not have
  9393.   to display the window, instead the menu manager can do the displaying and
  9394.   hiding of the windows.
  9395.  
  9396.   Here is an example of creating your own custom window function:
  9397.  
  9398.   #include "menu.h"
  9399.   /* Other includes and menu stuff */
  9400.   WPOINTER my_open();
  9401.   POPUP_MENU_PTR p;
  9402.   main()
  9403.   {
  9404.      /*   Other code */
  9405.      p = PopupCreateMenu(menu_items,menu_colors,10,10,9,my_open,WNULLFN);
  9406.      /* More code */
  9407.   }
  9408.  
  9409.   WPOINTER my_open()
  9410.   {
  9411.     WPOINTER w;
  9412.     w = WindowInitialize(NOBORDER,1,1,20,10,BLACKONWHITE,BLACKONWHITE,"");
  9413.     WindowOpen(w);
  9414.     return w;       /* May be WIN_NULL_PTR, but must return to
  9415.                        PopupCreateMenu() */
  9416.   }
  9417.  
  9418.  Page 157                     The C Window Library                    Page 157
  9419.  
  9420.   The example above lets the menu manager know that the window creation
  9421.   function is a user written function called my_open.  The row, column and
  9422.   height arguments (arguments 3, 4 and 5) of PopupCreateMenu() will be ignored
  9423.   when using a custom window function.  The row, column and height parameters
  9424.   used to create the window in the call to WindowInitialize() in my_window()
  9425.   will take precedence over the arguments 3, 4, and 5 used in PopupCreateMenu().
  9426.  
  9427.  
  9428.  
  9429.   Default Virtual Window and
  9430.   Creating Your own Virtual Windows
  9431.   ---------------------------------
  9432.  
  9433.   The last argument to PopupCreateMenu() is a pointer to a function that will
  9434.   return a VWPOINTER.  This function creates the virtual window used to write
  9435.   the menu entries.  If this is a NULL function pointer (VWNULLFN), the menu
  9436.   manager will create the virtual window.  If you do specify a function,  your
  9437.   virtual window must have enough rows to hold all of the POPUP_MENU_ENTRY's,
  9438.   and be wide enough to hold the length of the longest entry_name.
  9439.  
  9440.   When the menu manager creates the virtual window, the following defaults are
  9441.   assumed:
  9442.  
  9443.    a) the virtual window has its own video attributes.
  9444.    b) Must be large enough to hold all the POPUP_MENU_ENTRY's.
  9445.  
  9446.   Your custom function should create a virtual window which follows both rules.
  9447.  
  9448.  
  9449.   You must also make sure that the virtual window was created and opened
  9450.   successfully.  If the virtual window cannot be created because of a lack of
  9451.   memory, you must return the NULL virtual window pointer instead.  From there,
  9452.   PopupCreateMenu() will do any cleaning up and will return with a null
  9453.   POPUP_MENU_PTR.
  9454.  
  9455.   My last advice when calling the PopupCreateMenu() function is that your best
  9456.   bet is to let the menu manager create the windows and virtual windows.  You
  9457.   can always resize, change border types, etc. later on.  Since virtual
  9458.   window's are not visible anyway, it makes sense to let the menu manager
  9459.   determine how the virtual window should be created.  The last two arguments
  9460.   to the PopupCreateMenu() function are for those programmers who need full
  9461.   control of window, and virtual window management.
  9462.  
  9463.  
  9464.  
  9465.   Accessing Popup Windows and Virtual Windows
  9466.   -------------------------------------------
  9467.  
  9468.   After calling the PopupCreateMenu() function, you can access the popup window
  9469.   by using the POPUP_WINDOW() macro.  In the above example, p is the
  9470.   POPUP_MENU_PTR and the value of POPUP_WINDOW(p) is a pointer to the popup
  9471.   menu's window.  If you want to change borders move, slide, or anything you
  9472.   can do with normal windows, you must access the popup window in this way.
  9473.  
  9474.  Page 158                     The C Window Library                    Page 158
  9475.  
  9476.   For example, if you want to change the border of the popup window you would
  9477.   do the following:
  9478.  
  9479.  
  9480.       p = PopupCreateMenu(...  /* other arguments */ )
  9481.       WindowDrawBorder(POPUP_WINDOW(p),DOUBLEBOX);  /* change border to a
  9482.                                                        double lined box */
  9483.  
  9484.   The example calls WindowDrawBorder() to change the border of the popup
  9485.   window.
  9486.  
  9487.   If you want to write information to the virtual window created by the
  9488.   PopupCreateMenu() function, you can access the virtual window by using the
  9489.   POPUP_VIRTUAL_WINDOW() macro.  By accessing the popup-menu's virtual window,
  9490.   you can read and write to and from the virtual window.  This is very useful
  9491.   if you want to draw horizontal lines in your menu.  An example would be as
  9492.   follows:
  9493.  
  9494.       char *h = "----------------------";
  9495.  
  9496.       /* ...Some code... */
  9497.  
  9498.       p = PopupCreateMenu(menu_items,menu_colors,10,10,9,WNULLFN,VWNULLFN);
  9499.       VirtualWriteString(POPUP_VIRTUAL_WINDOW(p),h,8,1);
  9500.  
  9501.  
  9502.   Warnings
  9503.   --------
  9504.  
  9505.   Do not call WindowFree(), WindowClose() or VirtualFree() on the window or the
  9506.   virtual window of the popup menu.  The menu manager will call these functions
  9507.   when PopupMenuFree() is called.  If you close the popup window, or the
  9508.   virtual window on an active menu, the menu manager will assume that these
  9509.   windows still exist.  Doing so will almost guarantee your application will
  9510.   bomb out.
  9511.  
  9512.  
  9513.   Return Values for PopupCreateMenu()
  9514.   -----------------------------------
  9515.   If there are no errors, PopupCreateMenu() returns a valid POPUP_MENU_PTR
  9516.   pointer.  If there is an error when PopupCreateMenu() is called, a null
  9517.   POPUP_MENU_PTR is returned.  Here are the possible reasons why an error has
  9518.   occurred:
  9519.  
  9520.     1) There is not enough memory to allocate for the POPUP_MENU_PTR or its
  9521.        internal data structures.
  9522.  
  9523.     2) There is not enough memory to allocate for the popup window.
  9524.  
  9525.     3) There is not enough memory to allocate for the virtual window.
  9526.  
  9527.     4) The popup window's size was invalid.
  9528.  
  9529.  
  9530.  Page 159                     The C Window Library                    Page 159
  9531.  
  9532.   Problems 1,2, and 3 all are caused by a lack of heap memory.  Problem 4 stems
  9533.   from having invalid parameters in the PopupCreateMenu().  The arguments that
  9534.   are suspect are the third, fourth, and fifth arguments.  To remedy this
  9535.   problem, adjust these arguments such that the window can fit on the screen.
  9536.  
  9537.   For all of the above conditions, you can get the actual error code by
  9538.   checking the value of the global integer window_error_code.  If
  9539.   window_error_code is equal to NO_HEAP_MEM, then condition 1, 2, or 3 has
  9540.   occurred.  If it is equal to BAD_WINDOW_SIZE, then condition 4 has occurred.
  9541.  
  9542.   If you have a custom window or virtual window opening function, it is your
  9543.   responsibility to check the error conditions that may occur, and return
  9544.   correct values or null pointers if you cannot rectify the error in your
  9545.   custom routine.
  9546.  
  9547.  
  9548.   Here is an example:
  9549.  
  9550.   Example:
  9551.        int status;
  9552.        POPUP_MENU_PTR p;
  9553.        p = PopupCreateMenu(...);
  9554.        if (p == (POPUP_MENU_PTR)0)  {   /* check for null pointer */
  9555.          if (window_error_code == NO_HEAP_MEM)
  9556.             /* ... Condition 1,2, or 3 occurred */
  9557.          else
  9558.            /* Condition 4 occurred */
  9559.        }
  9560.  
  9561.  
  9562.  
  9563.  
  9564.  
  9565.  
  9566.  
  9567.  
  9568.  
  9569.  
  9570.  
  9571.  
  9572.  
  9573.  
  9574.  
  9575.  
  9576.  
  9577.  
  9578.  
  9579.  
  9580.  
  9581.  
  9582.  
  9583.  
  9584.  
  9585.  
  9586.  Page 160                     The C Window Library                    Page 160
  9587.  
  9588.                           SELECTING FROM POPUP MENUS
  9589.                           --------------------------
  9590.  
  9591.   We have now created the popup menu.  Now how do we get the menu manager to
  9592.   act on our popup window?  The answer is the PopupSelectMenu() function.
  9593.  
  9594.  
  9595.   PopupSelectMenu() function
  9596.   --------------------------
  9597.  
  9598.   The PopupSelectMenu() function displays the popup window, and allows the
  9599.   user to move the highlight bar until he/she has placed the bar on the desired
  9600.   option, or the user presses a hotkey to invoke one of the entries.
  9601.  
  9602.   Before the call to the PopupSelectMenu(), nothing has been displayed.  This
  9603.   means that you can resize the popup window, change borders, write strings to
  9604.   the popup menus virtual window, etc. while everything is hidden away from
  9605.   view.  The only time when the popup menu is displayed is when the call to
  9606.   PopupSelectMenu() is made (or unless you have displayed the popup window
  9607.   yourself using WindowDisplay()).
  9608.  
  9609.   A prototype of the call to PopupSelectMenu() is as follows:
  9610.  
  9611.        int PopupSelectMenu(POPUP_MENU_PTR p, int rank, unsigned start)
  9612.  
  9613.   The first argument is the POPUP_MENU_PTR.  The second argument is the rank of
  9614.   the popup window.  As with other windows, the rank determines how the window
  9615.   will be situated on the screen with respect to the other windows.  If you want
  9616.   more information on window ranks, please refer to page 2.  The last argument
  9617.   is the number of the menu entry of where the highlight bar should be
  9618.   situated.  Usually this is 1, but this will give you the option to start on
  9619.   any one of the menu entries.  If the start value is out of bounds (say you
  9620.   have specified start to be 5 while there are only 4 menu entries) the menu
  9621.   manager will default to the first menu option.
  9622.  
  9623.   Now let's put everything together:
  9624.  
  9625.  
  9626.   #include "menu.h"
  9627.   int menu_func();
  9628.  
  9629.   POPUP_MENU_ENTRY menu_items[] = {
  9630.                                   " Load      F3", /* entry name */
  9631.                                     1,             /* row number */
  9632.                                    'L',            /* hotkey */
  9633.                                     F3,            /* secondary hotkey */
  9634.                                     menu_func,     /* function to call
  9635.                                                       if chosen */
  9636.  
  9637.                                  /* now do rest of the popup entries */
  9638.  
  9639.  
  9640.  
  9641.  
  9642.  Page 161                     The C Window Library                    Page 161
  9643.  
  9644.                                   " Pick  Alt-F3",2, 'P',ALTF3,menu_func,
  9645.                                   " New"         ,3, 'N',0,menu_func,
  9646.                                   " Save      F2",4, 'S',F2,menu_func,
  9647.                                   " Write to    ",5, 'W',0,menu_func,
  9648.                                   " Directory   ",6, 'D',0,menu_func,
  9649.                                   " Change Dir"  ,7, 'C',0,menu_func,
  9650.                                   " OS shell"    ,8, 'O',0,menu_func,
  9651.                                   " Quit  Alt-X"  ,9,'Q',ALTX,menu_func,
  9652.  
  9653.                                  /* Terminate with a CWL_NULL and 0 */
  9654.  
  9655.                                   CWL_NULL,0};
  9656.   unsigned int menu_colors[5];
  9657.   POPUP_MENU_PTR p;
  9658.  
  9659.   main()
  9660.   {
  9661.     WindowInitializeSystem();
  9662.     WindowSaveInitial(0);  /* Remember to save the initial screen */
  9663.    /* define colors */
  9664.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  9665.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  9666.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  9667.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  9668.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  9669.  
  9670.    /* create a POPUP_MENU_PTR */
  9671.    p = PopupCreateMenu(menu_items,menu_colors, 1,1,6,WNULLFN,VWNULLFN);
  9672.    PopupSetOptions(p,POPUPSTATIC,1);
  9673.    PopupSelectMenu(p,  /* POPUP_MENU_PTR */
  9674.                      1,  /* rank of popup window */
  9675.                      1   /* menu entry to start on */
  9676.                     );
  9677.   }
  9678.  
  9679.  
  9680.   int menu_func(POPUP_MENU_PTR p, unsigned which)
  9681.   {
  9682.     WPOINTER w;
  9683.     w = WindowInitialize(BORDER,15,15,40,4,CREATE_VIDEO_ATTRIBUTE(black,white),
  9684.                          CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
  9685.     WindowOpen(w);
  9686.     WindowClear(w);
  9687.     WindowPrintf(w,"You have selected %s",POPUP_ENTRY_STRING(p,which));
  9688.     WindowWriteCenterString(w,"Press a key to continue",3);
  9689.     WindowDisplay(w,1,NOEFFECT);
  9690.     GET_KEY();
  9691.     WindowFree(w,NOEFFECT);
  9692.     if (which == 9)
  9693.       return POPUP_EXIT;
  9694.     else
  9695.     return POPUP_CONTINUE;
  9696.   }
  9697.  
  9698.  Page 162                     The C Window Library                    Page 162
  9699.  
  9700.   The above example has a call to PopupSelectMenu().  The arguments passed are
  9701.   p as the POPUP_MENU_PTR, a window rank of 1, and a starting position of 1.
  9702.   The POPUP_ENTRY_STRING() macro in the menu_func() function returns the entry
  9703.   string for the particualr menu entry.  The first argument is the
  9704.   POPUP_MENU_PTR and the second argument is the entry number.
  9705.  
  9706.  
  9707.  
  9708.  
  9709.   Values passed to menu function
  9710.   ------------------------------
  9711.  
  9712.   When a selection is made, the menu manager will call the function defined
  9713.   for the selection, and pass two arguments to this function.  The first
  9714.   argument passed is the POPUP_MENU_PTR of the current popup menu and the
  9715.   second argument is the number of the entry selected.  Entry numbers are
  9716.   numbered from 1 to the highest entry in the menu.  For example, if the " Load
  9717.   F3" entry is selected, the menu manager will pass the POPUP_MENU_PTR p, and a
  9718.   1 to func().  If " Pick ALT-F3" is chosen, the menu manager passes a 2 as the
  9719.   second argument to func() etc.
  9720.  
  9721.  
  9722.  
  9723.  
  9724.   Values returned to menu manager
  9725.   -------------------------------
  9726.  
  9727.   The user function must return an integer back to the menu manager.  If the
  9728.   value returned to the menu manager is POPUP_EXIT, the menu manager will exit
  9729.   from the current menu and will return control back to the function that
  9730.   called it.  If the return value is POPUP_CONTINUE, the menu continues to
  9731.   process selections.
  9732.  
  9733.   The menu_func() function defined above creates a window, displays the entry
  9734.   you have chosen, and returns a value back to the menu manager.  If the value
  9735.   is POPUP_EXIT, the menu manager returns control back to the function that
  9736.   called it.  In this case, main() called PopupSelectMenu().  A return value of
  9737.   POPUP_CONTINUE will cause the menu manager to let the user make another
  9738.   selection.
  9739.  
  9740.   The menu_func() function is a simple implementation.  However your function
  9741.   can do much more sophisticated things, including opening other popup menus.
  9742.   If another popup menu is called while in another popup menu, the new popup
  9743.   menu gets its own menu manager and will not interfere with the original menu
  9744.   manager.  This is good if a menu function will call another menu function.
  9745.  
  9746.  
  9747.  
  9748.  
  9749.  
  9750.  
  9751.  
  9752.  
  9753.  
  9754.  Page 163                     The C Window Library                    Page 163
  9755.  
  9756.   Return Values for PopupSelectMenu()
  9757.   -----------------------------------
  9758.  
  9759.   If no errors occurred when PopupSelectMenu() is called the menu manager
  9760.   returns NO_ERROR when the menu is closed.  There are three possibilities for
  9761.   errors when calling PopupSelectMenu().  Here are the three possible errors:
  9762.  
  9763.   1) The popup menus window does not exist.
  9764.  
  9765.   2) The popup menus window is not opened.
  9766.  
  9767.   3) The virtual window does not exist.
  9768.  
  9769.   The first error occurred because the PopupCreateMenu() function or your
  9770.   custom window function could not initialize the popup menu window, you
  9771.   inadvertently called WindowFree() on the popup menu's window, or you are
  9772.   overwriting data with a stray pointer.
  9773.  
  9774.   Error 2 can occur if the you inadvertently called WindowClose() on the popup
  9775.   menu's window, or you are overwriting data with a stray pointer.
  9776.  
  9777.   Error 3 can occur if PopupCreateMenu() or your custom virtual window
  9778.   function could not create the virtual window, or a stray pointer is
  9779.   overwriting data.
  9780.  
  9781.   For all of the above conditions, you can get the actual error code by
  9782.   checking the value of the global integer window_error_code or by checking
  9783.   the return value of PopupSelectMenu().  Here is a list of return values and
  9784.   their corresponding reasons:
  9785.  
  9786.     Return Value               Condition
  9787.     ------------               ---------
  9788.     BAD_WINDOW                    1
  9789.     WINDOW_NOT_OPEN               2
  9790.     BAD_V_WINDOW                  3
  9791.  
  9792.  
  9793.  
  9794.  
  9795.  
  9796.  
  9797.  
  9798.  
  9799.  
  9800.  
  9801.  
  9802.  
  9803.  
  9804.  
  9805.  
  9806.  
  9807.  
  9808.  
  9809.  
  9810.  
  9811.  Page 164                     The C Window Library                    Page 164
  9812.  
  9813.                         SETTING OPTIONS IN POPUP MENUS
  9814.                         ------------------------------
  9815.  
  9816.   Type of Options
  9817.   ---------------
  9818.  
  9819.   By default the menu manager assumes the following things:
  9820.  
  9821.     1)  The highlight bar does not wrap if the user wants to move the bar past
  9822.         the last entry, or before the first entry.
  9823.  
  9824.     2)  The menu will be hidden from the screen when a selection is made and
  9825.         will reappear when control is returned to the menu manager.
  9826.  
  9827.     3)  A function is automatically invoked when the hotkey is pressed instead
  9828.         of calling a user-defined function which will tell the menu manager
  9829.         whether the menu entry is to be executed.
  9830.  
  9831.     4)  The popup menu window is hidden when the menu manager returns control
  9832.         to the calling function.
  9833.  
  9834.     5)  The highlight bar will skip unavailable entries.
  9835.  
  9836.     6)  The menu manager does not recognize enhanced keys (F11, F12, etc.).
  9837.  
  9838.   All of these assumptions can be changed at any time by calling the
  9839.   PopupSetOptions() function.
  9840.  
  9841.  
  9842.   The PopupSetOptions() function
  9843.   ------------------------------
  9844.  
  9845.   The PopupSetOptions() function turns either one or more of the above
  9846.   options on or off.  The prototype to the call is as follows:
  9847.  
  9848.          int PopupSetOptions(POPUP_MENU_PTR p, int option, int switch)
  9849.  
  9850.   The first argument is the POPUP_MENU_PTR.  The second argument are the
  9851.   options that you wish to change.  The third argument is whether you want to
  9852.   switch the options on or off.   What is meant by on and off is that the
  9853.   default options described above are "off".  By turning the options on you do
  9854.   the opposite of the default settings.  The "on" selection will do the
  9855.   following to each option:
  9856.  
  9857.     1)  The highlight bar will wrap around if the user wants to move the bar
  9858.         past the last entry or before the first entry.
  9859.  
  9860.     2)  The menu will not be hidden from the screen when a selection is made.
  9861.  
  9862.     3)  A user-defined function is called before invoking the hotkey that was
  9863.         selected.  This function will then return an integer back to the menu
  9864.         manager informing whether the function selected should be invoked, or
  9865.         the request should be rejected.
  9866.  
  9867.  Page 165                     The C Window Library                    Page 165
  9868.  
  9869.     4)  The popup window is not hidden when the menu manager returns control to
  9870.         the calling function.
  9871.  
  9872.     5)  Unavailable entries will be accepted by the menu manager.
  9873.  
  9874.     6)  The menu manager will recognize enhanced keys.
  9875.  
  9876.  
  9877.   Here is a definition of the available options:
  9878.  
  9879.      Option Name              Definition
  9880.      -----------              ----------
  9881.       POPUPWRAP             Highlight bar wrapping.
  9882.       POPUPSTATIC           Hide menu when selection is made.
  9883.       POPUPCONFIRM          Confirmation when selection is made via hotkey.
  9884.       POPUPDISPLAY          Display menu even after exit.
  9885.       POPUPOVERRIDE         Accept Unavailable entries.
  9886.       POPUPENHANCEDKEY      Recognize enhanced keys.
  9887.  
  9888.  
  9889.     Here are some sample calls to PopupSetOptions:
  9890.  
  9891.       a) PopupSetOptions(p,POPUPWRAP,1)
  9892.       b) PopupSetOptions(p,POPUPSTATIC,1)
  9893.       c) PopupSetOptions(p,POPUPCONFIRM,1)
  9894.       d) PopupSetOptions(p,POPUPSTATIC,0)
  9895.       e) PopupSetOptions(p,POPUPDISPLAY,1)
  9896.       f) PopupSetOptions(p,POPUPOVERRIDE,1)
  9897.       g) PopupSetOptions(p,POPUPENHANCEDKEY,1)
  9898.  
  9899.   The third argument is 1 for "on", 0 for "off".
  9900.  
  9901.   Example a) sets the highlight bar so that it will wrap.
  9902.  
  9903.   Example b) informs the menu manager that the menu will not be hidden when a
  9904.   selection is made.
  9905.  
  9906.   Example c) will tell the menu manager to call a user defined function that
  9907.   will inform the menu manager whether to invoke the selection in the menu.
  9908.  
  9909.   Example d) Informs the menu manager to hide the menu window when a menu
  9910.   function is invoked.
  9911.  
  9912.   Example e) Informs the menu manager not to hide the menu when control is
  9913.   returned to the function that called PopupSelectMenu().
  9914.  
  9915.   Example f) Informs the menu manager to process unavailable entries.  This is
  9916.   useful if you want to set up your own error routine if the user selects an
  9917.   unavailable entry.
  9918.  
  9919.   Example g) imforms the menu manager to distinguish between normal keys and
  9920.   enhanced keys.
  9921.  
  9922.  
  9923.  Page 166                     The C Window Library                    Page 166
  9924.  
  9925.   Setting Multiple Options
  9926.   ------------------------
  9927.   You can also set multiple options with a single call by using a bitwise OR
  9928.   (|).  For example:
  9929.  
  9930.     PopupSetOptions(p,POPUPWRAP | POPUPSTATIC | POPUPCONFIRM,1)
  9931.  
  9932.   will set options POPUPWRAP, POPUPSTATIC, and POPUPCONFIRM defined above.
  9933.  
  9934.  
  9935.  
  9936.   Setting the PopupSetConfirmFunction()
  9937.   -------------------------------------
  9938.  
  9939.   When using the POPUPCONFIRM option, you must also use the
  9940.   PopupSetConfirmFunction() function to point the menu to the confirmation
  9941.   function that will be called when a hotkey is pressed.  Here is a prototype
  9942.   of the PopupSetConfirmFunction():
  9943.  
  9944.            PopupSetConfirmFunction(POPUP_MENU_PTR p, int (*func)())
  9945.  
  9946.   where p is the desired popup menu to assign the confirmation function to,
  9947.   and func is a pointer to a function that will return a value back to the menu
  9948.   manager that will inform it to either invoke the option, or ignore the
  9949.   option.
  9950.  
  9951.   When the confirmation function is called, the menu manager passes three
  9952.   arguments to func.  The prototype for your user defined function should be as
  9953.   follows:
  9954.  
  9955.         int my_confirm_func(POPUP_MENU_PTR p, unsigned key, unsigned sel)
  9956.  
  9957.   where p is the POPUP_MENU_PTR that is currently being processed, key is the
  9958.   hotkey that was pressed, and sel is the selection where the highlight bar is
  9959.   now positioned.  The highlight bar is always positioned on the hotkey
  9960.   selection even if it may not be invoked.  This user defined function must
  9961.   return a value back to the menu manager.  The valid values that can be
  9962.   returned are POPUP_CONTINUE and POPUP_DO_CHOICE.  If POPUP_CONTINUE is
  9963.   returned, the menu selection is not invoked, if POPUP_DO_CHOICE is selected,
  9964.   the menu entry is invoked.  Here is an example:
  9965.  
  9966.      #include "menu.h"
  9967.  
  9968.      int my_confirm_func();
  9969.      POPUP_MENU_PTR p;
  9970.  
  9971.      /* ... */
  9972.      main()
  9973.      {
  9974.        PopupSetOptions(p,POPUPCONFIRM,1);
  9975.        PopupSetConfirmFunction(p,my_confirm_func);
  9976.        /* ... */
  9977.      }
  9978.  
  9979.  
  9980.  Page 167                     The C Window Library                    Page 167
  9981.  
  9982.      my_confirm_func(POPUP_MENU_PTR p, unsigned k, unsigned sel)
  9983.      {
  9984.        /* ... */
  9985.        if (k == 'C' || k == 'c' || k == ALTF)
  9986.          return POPUP_CONTINUE;
  9987.        else
  9988.          return POPUP_DO_CHOICE;
  9989.      }
  9990.  
  9991.   The above function invokes the menu selection if the hotkey that was pressed
  9992.   is not a 'C', 'c', or ALT-F.
  9993.  
  9994.   The confirmation function can do anything, including setting options in the
  9995.   popup menu, displaying other windows etc.
  9996.  
  9997.  
  9998.  
  9999.   Return Values for PopupSetOptions() function
  10000.   --------------------------------------------
  10001.  
  10002.   You can use the PopupSetOptions() function at any time, including before
  10003.   calling the PopupSelectMenu() function.  If the option is not a valid option,
  10004.   the function returns NO_ERROR, but does not change anything.  If the switch
  10005.   is not 0 or 1, a 1 is assumed.
  10006.  
  10007.   If there is an error, the error conditions and reasons are the same as the
  10008.   PopupSelectMenu() function defined above.
  10009.  
  10010.  
  10011.  
  10012.  
  10013.  
  10014.  
  10015.  
  10016.  
  10017.  
  10018.  
  10019.  
  10020.  
  10021.  
  10022.  
  10023.  
  10024.  
  10025.  
  10026.  
  10027.  
  10028.  
  10029.  
  10030.  
  10031.  
  10032.  
  10033.  
  10034.  
  10035.  
  10036.  Page 168                     The C Window Library                    Page 168
  10037.  
  10038.                  MAKING MENU ENTRIES AVAILABLE AND UNAVAILABLE
  10039.                  ---------------------------------------------
  10040.  
  10041.   There may be cases when a menu entry should be made unavailable.  The entry
  10042.   shows up in the menu, but it is a different color than the other entries, and
  10043.   the highlight bar will just skip over this unavailable entry.
  10044.  
  10045.  
  10046.  
  10047.   PopupMakeEntryAvailable() and
  10048.   PopupMakeEntryUnavailable() functions
  10049.   -------------------------------------
  10050.  
  10051.   With The C Window Library, you can make entries available and unavailable at
  10052.   any time.  The PopupMakeEntryAvailable() and the PopupMakeEntryUnavailable()
  10053.   functions perform these tasks.
  10054.  
  10055.   A prototype of the call to both of these functions is as follows:
  10056.  
  10057.         int PopupMakeEntryAvailable(POPUP_MENU_PTR p, unsigned entry)
  10058.         int PopupMakeEntryUnavailable(POPUP_MENU_PTR p, unsigned entry)
  10059.  
  10060.   The first argument is the POPUP_MENU_PTR.  The second argument is the number
  10061.   of the entry that you wish to change.  Entry numbers range from 1 to the
  10062.   highest entry in the menu.
  10063.  
  10064.  
  10065.  
  10066.   POPUPOVERRIDE option
  10067.   --------------------
  10068.  
  10069.   If the POPUPOVERRIDE option is set (see above), the menu manager will still
  10070.   process unavailable entries.  You must turn off POPUPOVERRIDE by using the
  10071.   PopupSetOptions() function if you do not want to process unavailable entries.
  10072.  
  10073.  
  10074.  
  10075.   Return Values for PopupMakeEntryAvaialble() and
  10076.   PopupMakeEntryUnavailable() functions
  10077.   -----------------------------------------------
  10078.  
  10079.   If there is no error, both of these functions return NO_ERROR.
  10080.   If there is an error, the following possibilities can occur:
  10081.  
  10082.   1) The error can be one of the errors defined above for the PopupSelectMenu()
  10083.  
  10084.   2) The menu entry is invalid.
  10085.  
  10086.   Refer to the PopupSelectMenu() return values and reasons for failure defined
  10087.   above for error condition 1).  If the error is 2), check to see if the entry
  10088.   number supplied is valid.  The entry number cannot be < 1 or greater than the
  10089.   number of selections in the popup menu.
  10090.  
  10091.  
  10092.  Page 169                     The C Window Library                    Page 169
  10093.  
  10094.   If error 2) has occurred, the PopupMakeEntryAvailable() and the
  10095.   PopupMakeEntryUnavailable() return MENU_ENTRY_INVALID.
  10096.  
  10097.  
  10098.  
  10099.  
  10100.  
  10101.  
  10102.  
  10103.  
  10104.  
  10105.  
  10106.  
  10107.  
  10108.  
  10109.  
  10110.  
  10111.  
  10112.  
  10113.  
  10114.  
  10115.  
  10116.  
  10117.  
  10118.  
  10119.  
  10120.  
  10121.  
  10122.  
  10123.  
  10124.  
  10125.  
  10126.  
  10127.  
  10128.  
  10129.  
  10130.  
  10131.  
  10132.  
  10133.  
  10134.  
  10135.  
  10136.  
  10137.  
  10138.  
  10139.  
  10140.  
  10141.  
  10142.  
  10143.  
  10144.  
  10145.  
  10146.  
  10147.  
  10148.  Page 170                     The C Window Library                    Page 170
  10149.  
  10150.                      CHANGING THE MENU ENTRY STRINGS
  10151.                      -------------------------------
  10152.  
  10153.   There may be times when you want to change a POPUP_MENU_ENTRY entry_name
  10154.   string.  For instance, you may have a menu entry with the following
  10155.   entry_name:
  10156.  
  10157.           "Default File Name     ABC.DAT"
  10158.  
  10159.  
  10160.   If the user selects this choice, the file name should change to another file
  10161.   name the user wants.  From there the menu should reflect the new choice the
  10162.   user has made.  Let's say the user has changed the default file name to
  10163.   DEF.DAT.  The menu then should say:
  10164.  
  10165.           "Default File Name     DEF.DAT"
  10166.  
  10167.  
  10168.  
  10169.   PopupChangeEntryString() function
  10170.   ---------------------------------
  10171.  
  10172.   How do you change the entry string?  One way is to fool around with the
  10173.   POPUP_MENU_PTR's structure members, and change the string yourself.  This is
  10174.   not recommended for the novice to average C programmer, since it is not a good
  10175.   idea to change the structure members directly without a full understanding of
  10176.   the structure.
  10177.  
  10178.   A safer way is to call the PopupChangeEntryString() function.  A prototype of
  10179.   this function is as follows:
  10180.  
  10181.      PopupChangeEntryString(POPUP_MENU_PTR p, unsigned entry, char *newstring)
  10182.  
  10183.   The first argument is the POPUP_MENU_PTR.  The second argument is the number
  10184.   of the entry that you wish to change.  Entry numbers range from 1 to the
  10185.   highest entry in the menu.  The third argument is a pointer to the new
  10186.   character string.  The newstring cannot be longer than the current
  10187.   POPUP_MENU_ENTRY entry_name string.
  10188.  
  10189.  
  10190.  
  10191.  
  10192.   Return Values for PopupChangeEntryString() function
  10193.   ---------------------------------------------------
  10194.  
  10195.   If there is no error, NO_ERROR is returned.
  10196.  
  10197.   If there is an error, the error conditions and reasons are the same as the
  10198.   PopupMakeEntryAvailable() function defined above.
  10199.  
  10200.  
  10201.  
  10202.  
  10203.  
  10204.  Page 171                     The C Window Library                    Page 171
  10205.  
  10206.                            REDEFINING MENU KEYS
  10207.                            --------------------
  10208.  
  10209.  
  10210.   Setting Global Key Definitions and
  10211.   the popup_key_definition Array
  10212.   ----------------------------------
  10213.  
  10214.   You can redefine the keys used to control moving the highlight bar, accepting
  10215.   the menu choice, and exiting from the menu.  Here is a list of the default key
  10216.   mapping:
  10217.  
  10218.        Function                      Key             Constant
  10219.        --------                      ---              ------
  10220.      Move highlight bar up         Up Arrow        POPUP_UPKEY
  10221.      Move highlight bar down       Down Arrow      POPUP_DOWNKEY
  10222.      Accept Menu Choice            Enter           POPUP_ACCEPTKEY
  10223.      Escape Pop-up menu            Escape          POPUP_QUITKEY
  10224.      Move To First Menu Item       Home            POPUP_HOMEKEY
  10225.      Move to Last Menu Item        End             POPUP_ENDKEY
  10226.     *Move To Next Popup Menu       Not Assigned    POPUP_RIGHTKEY
  10227.     *Move to Previous Popup Menu   Not Assigned    POPUP_LEFTKEY
  10228.     *Escape Pulldown Menu          Not Assigned    POPUP_PULLDOWN_QUITKEY
  10229.  
  10230.   The global array popup_key_definition contains the values of the default
  10231.   popup menu key definitions.  The names under the Constant heading are the
  10232.   offsets in the popup_key_definition array of where the key value for the
  10233.   function is defined.  For instance, the value for the "Move highlight bar up"
  10234.   function is located at popup_key_definition[POPUP_UPKEY].  You can change the
  10235.   values in popup_key_definition at any time, but make sure that a definition
  10236.   for "Escape Pop-up menu" always exists, and that there are no duplicate
  10237.   definitions (i.e.  the "Move highlight bar up" key definition is the same as
  10238.   the "Move highlight bar down" key definition).  When defining new key values,
  10239.   you should use the values defined in the keycodes.h header file for non-ascii
  10240.   keys.
  10241.  
  10242.   * The POPUP_RIGHTKEY, POPUP_LEFTKEY, and the POPUP_PULLDOWN_QUITKEY
  10243.     definitions only apply to popup menus that are incorporated in a pulldown
  10244.     menu.  See the section on pulldown menus for more information.
  10245.  
  10246.  
  10247.  
  10248.  
  10249.   Setting Local Key Definitions
  10250.   -----------------------------
  10251.  
  10252.   Another way of redefining menu keys is to load your own array of key
  10253.   definitions with your desired values, and then calling the PopupAssignKeys()
  10254.   function.  With this method, each menu can have different key definitions.
  10255.  
  10256.  
  10257.  
  10258.  
  10259.  
  10260.  Page 172                     The C Window Library                    Page 172
  10261.  
  10262.   PopupAssignKeys() function
  10263.   --------------------------
  10264.  
  10265.   Here is a prototype of the PopupAssignKeys() function:
  10266.  
  10267.               int PopupAssignKeys(POPUP_MENU_PTR p, unsigned *keys)
  10268.  
  10269.   where p is the POPUP_MENU_PTR, and keys is an array of key definitions.  Here
  10270.   is a small code example:
  10271.  
  10272.  
  10273.   #include "menu.h"
  10274.  
  10275.   unsigned mykeys[8] = {CTRLU,CTRLD,RETURN,ESC,HOME,END,0,0,0};
  10276.   POPUP_MENU_PTR p;
  10277.  
  10278.   /* Other stuff...*/
  10279.  
  10280.   main()
  10281.   {
  10282.     /* Assume p is initialized */
  10283.  
  10284.     PopupAssignKeys(p,mykeys); /* Assigns my key definitions to popup menu p */
  10285.   }
  10286.  
  10287.   The above example uses the constants defined in keycodes.h to assign to the
  10288.   array mykeys.  Each position in the mykeys array uses the default key mapping
  10289.   explained above.  In other words, mykeys[POPUP_UPKEY] is CTRLU, etc.
  10290.  
  10291.  
  10292.  
  10293.   Return Values for PopupAssignKeys() function
  10294.   --------------------------------------------
  10295.  
  10296.   If there is no error, then NO_ERROR is returned.
  10297.  
  10298.   If there is an error, the error conditions and reasons are the same as the
  10299.   PopupSelectMenu() function defined above.
  10300.  
  10301.  
  10302.  
  10303.  
  10304.  
  10305.  
  10306.  
  10307.  
  10308.  
  10309.  
  10310.  
  10311.  
  10312.  
  10313.  
  10314.  
  10315.  
  10316.  Page 173                     The C Window Library                    Page 173
  10317.  
  10318.                            PROCESSING UNDEFINED KEYS
  10319.                            -------------------------
  10320.  
  10321.   If you are an advanced programmer and/or have experience in using other
  10322.   window/menu libraries, you may be wondering "how do I define a function that
  10323.   supplies context-sensitive help for each POPUP_MENU_ENTRY?  There is no
  10324.   structure member in POPUP_MENU_ENTRY that supplies this".  With The C Window
  10325.   Library, any key that is not recognized by the menu manager (i.e. the key
  10326.   struck does not invoke a menu option, move the highlight bar up or down, or
  10327.   ends processing of the menu) can be processed by calling a user written
  10328.   function.   The WindowGet...() family of functions allowed us to define a
  10329.   function that will be called if a key that has no current definition is
  10330.   pressed.  For popup menus, we can do the same thing.
  10331.  
  10332.  
  10333.   The popup_undef_key function pointer
  10334.   ------------------------------------
  10335.  
  10336.   The global function pointer, popup_undef_key, can point to a user written
  10337.   function that will be called when the menu manager encounters a key that is
  10338.   not defined.  The declaration for popup_undef_key is as follows:
  10339.  
  10340.     unsigned int (*popup_undef_key)(POPUP_MENU_PTR p, unsigned int sel,
  10341.                                     unsigned int *choice)
  10342.  
  10343.   The user written function takes three arguments.  The first argument is a
  10344.   pointer to the popup menu that the menu manager is currently processing. The
  10345.   second argument is an integer that contains the value of the key that was
  10346.   pressed.  The third argument is a pointer to an integer that will contain the
  10347.   number of the menu choice to execute.  Initially, choice points to an integer
  10348.   that contains the current menu choice that the menu highlight bar is situated.
  10349.   For instance, if the highlight bar is on the first menu choice when an
  10350.   undefined key is pressed, *choice will be equal to 1.  If popup_undef_key is
  10351.   equal to a Null Function pointer (NULLFN), no user defined function is called.
  10352.   By default, popup_undef_key is assigned to NULLFN.
  10353.  
  10354.  
  10355.   Values returned to menu manager
  10356.   -------------------------------
  10357.  
  10358.   If popup_undef_key is assigned to a function, the function must return an
  10359.   integer back to the menu manager.  This integer value will tell the menu
  10360.   manager how to proceed.  Here is a list of the valid return values that the
  10361.   user written function can return:
  10362.  
  10363.  
  10364.  
  10365.  
  10366.  
  10367.  
  10368.  
  10369.  
  10370.  
  10371.  
  10372.  Page 174                     The C Window Library                    Page 174
  10373.  
  10374.     Return                         Action to
  10375.     Value                            Take
  10376.     ------                         ---------
  10377.  
  10378.    POPUP_CONTINUE          No Action. Continue processing the popup menu.
  10379.    POPUP_MOVE_UP           Move the highlight bar up.
  10380.    POPUP_MOVE_DOWN         Move the highlight bar down.
  10381.    POPUP_DO_CHOICE         Accept and invoke menu entry assigned to *choice.
  10382.    POPUP_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  10383.                               *choice and continue processing menu.
  10384.    POPUP_ESCAPE            Escape the popup menu.
  10385.    POPUP_MOVE_HOME         Move highlight to first available menu entry.
  10386.    POPUP_MOVE_END          Move highlight to last available menu entry.
  10387.   *POPUP_MOVE_LEFT         Move to next popup menu.
  10388.   *POPUP_MOVE_RIGHT        Move to previous popup menu.
  10389.   *POPUP_PULLDOWN_ESCAPE   Escape pulldown menu
  10390.  
  10391.   A return value of POPUP_CONTINUE is a "do nothing" command to the menu
  10392.   manager.
  10393.  
  10394.   If POPUP_DO_CHOICE is returned to the menu manager, the integer assigned to
  10395.   the parameter *choice is used as the menu entry to invoke.  The highlight
  10396.   bar will automatically be moved to the menu choice specified, and the menu
  10397.   function will be called.  If POPUP_MOVE_CONTINUE is returned to the menu
  10398.   manager, the highlight bar will be moved to the entry specified by the
  10399.   value of *choice, but no function is called.
  10400.  
  10401.   Return values of POPUP_DO_CHOICE and POPUP_MOVE_CONTINUE only work when the
  10402.   menu entry specified by *choice is an available entry or the POPUPVERRIDE
  10403.   option is on , otherwise the menu manager just continues processing the
  10404.   popup menu.
  10405.  
  10406.  
  10407.   * The POPUP_MOVE_RIGHT, POPUP_MOVE_LEFT, and POPUP_PULLDOWN_ESCAPE only apply
  10408.     to popup menus that are incorporated in a pulldown menu system.  See the
  10409.     section on pulldown menus for more information.
  10410.  
  10411.   Here is an example of using a user defined function for the undefined keys:
  10412.  
  10413.   #include "menu.h"
  10414.  
  10415.   /*  Other includes */
  10416.  
  10417.   int user_func();
  10418.  
  10419.  
  10420.   main()
  10421.  
  10422.   {
  10423.     popup_undef_key = user_func;
  10424.  
  10425.     /* Other code */
  10426.   }
  10427.  
  10428.  Page 175                     The C Window Library                    Page 175
  10429.  
  10430.   unsigned int user_func(POPUP_MENU_PTR p, unsigned sel, unsigned *choice)
  10431.   {
  10432.     switch(sel)
  10433.  
  10434.     {
  10435.       case F1:
  10436.         help(*choice);         /* call help function */
  10437.         return POPUP_CONTINUE; /* return "do nothing" command to menu manager */
  10438.       case F2:
  10439.         *choice = 6;  /* let menu manager know to do choice 6 on the menu */
  10440.         return POPUP_DO_CHOICE;     /* Also let menu manager know we are
  10441.                                      returning the "do the function assigned to
  10442.                                      *choice" command */
  10443.       default:
  10444.         return POPUP_CONTINUE;
  10445.         /* let menu manager know not to do anything */
  10446.     }
  10447.   }
  10448.  
  10449.   int help(int choice)
  10450.   {  /* help function */
  10451.     switch (choice)
  10452.     {
  10453.       case 1:
  10454.         /* do context-sensitive help for entry 1 */
  10455.       break;
  10456.       case 2:
  10457.         /* do context-sensitive help for entry 2 */
  10458.       break;
  10459.        /* do more entries */
  10460.        /* ... */
  10461.     }
  10462.   }
  10463.  
  10464.   In the above example, if the user hits F1, a help function is called.  If you
  10465.   wanted to know how to incorporate a help function in the popup menus, here is
  10466.   the way to do it.
  10467.  
  10468.   If the user hits F2, the integer pointed to by choice is assigned a 6, and
  10469.   user_func() returns POPUP_DO_CHOICE to the menu manager.  This tells the
  10470.   menu manager to invoke the function assigned to menu entry 6.
  10471.  
  10472.  
  10473.  
  10474.  
  10475.  
  10476.  
  10477.  
  10478.  
  10479.  
  10480.  
  10481.  
  10482.  
  10483.  
  10484.  Page 176                     The C Window Library                    Page 176
  10485.  
  10486.                               PRE-INPUT FUNCTION
  10487.                               ------------------
  10488.  
  10489.   With The C Window Library, you can define a function that will be performed
  10490.   just before the menu manager waits for the user to enter a keystroke.  This
  10491.   function can perform just about anything.
  10492.  
  10493.  
  10494.   Setting the global_popup_prefunc function pointer
  10495.   -------------------------------------------------
  10496.  
  10497.   The global_popup_prefunc function pointer points to this user written
  10498.   function.  Here is the prototype:
  10499.  
  10500.       void (*global_popup_prefunc)(POPUP_MENU_PTR p, unsigned sel)
  10501.  
  10502.   The arguments that will be passed to your function are the following:
  10503.  
  10504.   a)  The POPUP_MENU_PTR of the popup menu that called your function, and
  10505.   b)  The number of the selection that the highlight bar is currently on.
  10506.  
  10507.   The selection number ranges from 1 to the highest entry number of the menu.
  10508.  
  10509.   By default, global_popup_prefunc points to a NULLFN, and therefore will not be
  10510.   performed.  However, you can implement pre-input functions depending on the
  10511.   current selection.  For instance, you can write a function that displays
  10512.   extra information for each entry like so:
  10513.  
  10514.   #include "menu.h"
  10515.  
  10516.   char *mess[] = {
  10517.                    " This option saves and loads files",
  10518.                    " This brings you in edit mode",
  10519.                    " This compiles and/or links the current program",
  10520.  
  10521.                    /* ... More stuff */
  10522.                    };
  10523.  
  10524.  
  10525.   WPOINTER message_window;
  10526.  
  10527.   void disp_info();
  10528.  
  10529.   main()
  10530.   {
  10531.     /* ... */
  10532.  
  10533.     global_popup_prefunc = disp_info;
  10534.  
  10535.     /* ... */
  10536.   }
  10537.  
  10538.  
  10539.  Page 177                     The C Window Library                    Page 177
  10540.  
  10541.   void disp_info(POPUP_MENU_PTR p, unsigned sel)
  10542.   {
  10543.      /* Assume message_window already created and opened */
  10544.  
  10545.     WindowClear(message_window,CREATE_VIDEO_ATTRIBUTE(black,white));
  10546.     WindowWriteString(message_window,mess[sel-1],1,1);
  10547.   }
  10548.  
  10549.  
  10550.   For simplicity, the menu definitions are left out of the preceding code
  10551.   sample.  The disp_info displays the appropriate description in the window
  10552.   message_window.  The user written function must be declared as void.  Once the
  10553.   function exits, the function returns control to the menu manager, and the menu
  10554.   manager then looks for a keystroke from the user (i.e. to move the highlight
  10555.   bar up, down, escape the menu, hotkey, etc.).
  10556.  
  10557.  
  10558.  
  10559.  
  10560.  
  10561.  
  10562.  
  10563.  
  10564.  
  10565.  
  10566.  
  10567.  
  10568.  
  10569.  
  10570.  
  10571.  
  10572.  
  10573.  
  10574.  
  10575.  
  10576.  
  10577.  
  10578.  
  10579.  
  10580.  
  10581.  
  10582.  
  10583.  
  10584.  
  10585.  
  10586.  
  10587.  
  10588.  
  10589.  
  10590.  
  10591.  
  10592.  
  10593.  
  10594.  
  10595.  Page 178                     The C Window Library                    Page 178
  10596.  
  10597.                            DISPOSING OF POPUP MENUS
  10598.                            ------------------------
  10599.  
  10600.  
  10601.   PopupMenuFree()
  10602.   ---------------
  10603.  
  10604.   If the popup menu is no longer needed, the PopupMenuFree() function will
  10605.   dispose of the popup menu and return any memory allocated to the popup menu,
  10606.   window, and virtual window memory back to the heap.  The call to the function
  10607.   is very simple:
  10608.  
  10609.          PopupMenuFree(POPUP_MENU_PTR p)
  10610.  
  10611.   where p is the POPUP_MENU_PTR to dispose of.  Since this function destroys the
  10612.   POPUP_MENU_PTR p, p must not be used for any popup menu functions, unless p
  10613.   is pointing to a valid POPUP_MENU_PTR.
  10614.  
  10615.  
  10616.  
  10617.   Return Values for PopupMenuFree()
  10618.   ---------------------------------
  10619.  
  10620.   The return values and the reasons for failure are the same as
  10621.   PopupSelectMenu().
  10622.  
  10623.  
  10624.  
  10625.  
  10626.  
  10627.  
  10628.  
  10629.  
  10630.  
  10631.  
  10632.  
  10633.  
  10634.  
  10635.  
  10636.  
  10637.  
  10638.  
  10639.  
  10640.  
  10641.  
  10642.  
  10643.  
  10644.  
  10645.  
  10646.  
  10647.  
  10648.  
  10649.  
  10650.  
  10651.  Page 179                     The C Window Library                    Page 179
  10652.  
  10653.                                BAR MENUS
  10654.                                ---------
  10655.  
  10656.   Description
  10657.   -----------
  10658.  
  10659.  
  10660.   A bar menu is a horizontal menu with a list of entries that are selected by
  10661.   placing a highlight bar on the option and pressing return, or by invoking the
  10662.   function by using a hotkey.  Bar menus can span several lines. In other
  10663.   words, menu entries do not have to fit on a single line.
  10664.  
  10665.  
  10666.   Here is a partial list of the various options you can have with bar menus:
  10667.  
  10668.      * Highlight bar wrapping - wrap highlight bar to first or last option
  10669.                                 when there are no more selections.
  10670.  
  10671.      * Static Menus           - menu remains on the screen when entry is
  10672.                                 selected.
  10673.  
  10674.      * Perpetual Menus        - menu remain on the screen regardless of
  10675.                                 whether the BarSelectMenu() function
  10676.                                 (explained later) is called or not.
  10677.  
  10678.      * Hidden (Unavailable) entries - You can make an entry in the bar menu
  10679.                                       unavailable or available at any time.
  10680.  
  10681.      * Color scheme of the menu - You can customize the color of the highlight
  10682.                                   bar, the hotkey letters, hidden entries,
  10683.                                   etc.
  10684.  
  10685.      * Change entry names       - You can safely change the names displayed in
  10686.                                   the menu at any time.
  10687.  
  10688.  
  10689.  
  10690.  
  10691.   Windows and Virtual Windows
  10692.   ---------------------------
  10693.  
  10694.   Unlike popup menus, bar menus do not use virtual windows.  Only normal text
  10695.   windows are used.
  10696.  
  10697.  
  10698.  
  10699.  
  10700.  
  10701.  
  10702.  
  10703.  
  10704.  
  10705.  
  10706.  
  10707.  Page 180                     The C Window Library                    Page 180
  10708.  
  10709.                              CREATING BAR MENUS
  10710.                              ------------------
  10711.  
  10712.  
  10713.  
  10714.   The BAR_MENU_ENTRY structure
  10715.   ----------------------------
  10716.  
  10717.   The two most important parts of the bar menu are the BAR_MENU_ENTRY structure
  10718.   and the BAR_MENU_PTR structure.  The BAR_MENU_ENTRY structure is the first
  10719.   step in creating a bar menu and is discussed here.
  10720.  
  10721.   Each entry in the bar menu has its own BAR_MENU_ENTRY structure associated
  10722.   with it.  The layout of this structure is as follows:
  10723.  
  10724.  
  10725.   char     *entry_name     -- This is the string that is displayed in the
  10726.                               bar window.
  10727.  
  10728.   unsigned  row            -- Row in the window to display entry_name.
  10729.  
  10730.   char      hotkey_letter  -- This is a character in entry_name that is
  10731.                               highlighted from the rest of the characters in
  10732.                               entry_name.  This letter will automatically
  10733.                               invoke the menu function associated with
  10734.                               entry_name.
  10735.  
  10736.   unsigned  ext_hotkey     -- This is a secondary hotkey.  The difference
  10737.                               between hotkey_letter and ext_hotkey is that
  10738.                               ext_hotkey can handle keys that are not ASCII keys
  10739.                               (the F keys, Alt and Ctrl key combinations, etc.).
  10740.  
  10741.   int (*func)()            -- Pointer to function that is invoked when option
  10742.                               is selected.
  10743.  
  10744.  
  10745.   An array of BAR_MENU_ENTRY's are needed to create all of the entries on the
  10746.   bar menu.  The order of the array elements determine the order of how they
  10747.   are placed in the  window.  A code sample to create an array of
  10748.   BAR_MENU_ENTRY's would be as follows:
  10749.  
  10750.   #include "menu.h"
  10751.   int menu_func();
  10752.  
  10753.   BAR_MENU_ENTRY bar_items[] = {
  10754.                         "File",    /* option name */
  10755.                          1,        /* row in window to display option name */
  10756.                          4,        /* col. in window to display option */
  10757.                         'F',       /* hotkey letter */
  10758.                         ALTF,      /* secondary hotkey */
  10759.                         rt2,       /* function to do if chosen */ ,
  10760.  
  10761.  
  10762.  
  10763.  Page 181                     The C Window Library                    Page 181
  10764.  
  10765.                         /* Now define the rest of the BAR_MENU_ENTRY's */
  10766.                         "Edit",1,10,'E',0,menu_func,
  10767.                         "Run",1,17,'R',0,menu_func,
  10768.                         "Compile",1,23,'C',0,menu_func,
  10769.                         "Project",1,33,'P',0,menu_func,
  10770.                         "Options",1,43,'O',0,menu_func,
  10771.                         "Debug",1,53,'D',0,menu_func,
  10772.                         "Break/watch",1,61,'B',0,menu_func,
  10773.  
  10774.                         /* Now terminate with a CWL_NULL option_name */
  10775.                          CWL_NULL};
  10776.  
  10777.  
  10778.   The first include file, menu.h, is must be included in each source file that
  10779.   calls menu functions.
  10780.  
  10781.   As you can see, there is an array of BAR_MENU_ENTRY's, namely bar_items.
  10782.   Each entry consists of an entry name, row number, column number, hotkey
  10783.   letter, secondary hotkey, and a function to call when the entry is selected.
  10784.   The list of BAR_MENU_ENTRY's MUST be terminated by a CWL_NULL entry name.
  10785.  
  10786.   If you are an advanced C programmer, you will no doubt find other ways in
  10787.   creating the array of BAR_MENU_ENTRY's.  Other methods would be by dynamic
  10788.   allocation, reading in the entries from a disk file, etc.  The above example
  10789.   illustrates the easiest way to create the BAR_MENU_ENTRY's.
  10790.  
  10791.   If you are an advanced C programmer, you will no doubt find other ways in
  10792.   creating the array of BAR_MENU_ENTRY's.  Other methods would be by dynamic
  10793.   allocation, reading in the entries from a disk file, etc.  The above example
  10794.   illustrates the easiest way to create the BAR_MENU_ENTRY's.
  10795.  
  10796.  
  10797.  
  10798.   Defining Hotkeys
  10799.   ----------------
  10800.  
  10801.   The hotkey_letter defined in the BAR_MENU_ENTRY structure must match one of
  10802.   the letters in its corresponding entry_name.  For example, "File", has the
  10803.   hotkey_letter defined as 'F'.  Since 'F' matches the first letter in "File",
  10804.   the first 'F' in "File" is highlighted.  If there is no match, or if the
  10805.   hotkey_letter is 0, there is no hotkey associated with this entry.  When the
  10806.   menu is displayed, either the 'f' or 'F' will be accepted as a valid selection
  10807.   to the entry "File".   If there is a BAR_MENU_ENTRY with the same hotkey
  10808.   letter as another BAR_MENU_ENTRY, the BAR_MENU_ENTRY closest to the first
  10809.   entry is chosen.
  10810.  
  10811.   The ext_hotkey is used if the hotkey cannot be defined as a single character,
  10812.   or if you want another hotkey definition.  In the above example, the "File"
  10813.   entry_name has an ext_hotkey of ALTF3 (defined in keycodes.h).  If the ALT-F3
  10814.   key is pressed, the function rt2() is automatically invoked.  If the
  10815.   ext_hotkey letter is 0, there is no ext_hotkey defined.  If there is a
  10816.   BAR_MENU_ENTRY with the same ext_hotkey as another BAR_MENU_ENTRY, the
  10817.   BAR_MENU_ENTRY closest to the first entry is chosen.
  10818.  
  10819.  Page 182                     The C Window Library                    Page 182
  10820.  
  10821.   Assigning the function to perform
  10822.   ---------------------------------
  10823.  
  10824.   The func() member is the function that is performed when its corresponding
  10825.   entry_name is chosen.  More information on what is passed to this function
  10826.   when it is called is defined on page 190.
  10827.  
  10828.   This is the first step in completing the total bar menu.  Once the array of
  10829.   BAR_MENU_ENTRY's is created the next step is to define the colors for each
  10830.   element of the bar menu.
  10831.  
  10832.  
  10833.  
  10834.   Coloring Bar Menus
  10835.   ------------------
  10836.  
  10837.   An array of unsigned integers is used to define the color scheme of the bar
  10838.   menu.  Each element of this array stands for a certain area of the bar
  10839.   menu.  Here is a list of array positions and what they stand for.
  10840.  
  10841.  
  10842.   Position
  10843.   Constant
  10844.   --------
  10845.  
  10846.   ENTRYCOLOR    --  color of the text area of the window.
  10847.   BORDERCOLOR    --  color of the border of the window.
  10848.   HOTKEYCOLOR    --  color of the hotkey letter.
  10849.   HIGHLIGHTCOLOR --  color of the highlight bar.
  10850.   UNAVAILCOLOR   --  color of the unavailable entries.
  10851.  
  10852.   Position ENTRYCOLOR of the array defines the color of the text area of the
  10853.   viewport window.  This in turn defines the color of each entry_name of all
  10854.   of the BAR_MENU_ENTRY's.
  10855.  
  10856.   Position BORDERCOLOR defines the color of the border of the window.  If
  10857.   the window does not have a border, this attribute is ignored.
  10858.  
  10859.   Position HOTKEYCOLOR defines the color to use for the hotkey letter.  In the
  10860.   above example, the 'L', 'P', 'N', etc. of each respective entry_name is
  10861.   displayed using this color.
  10862.  
  10863.   Position HIGHLIGHTCOLOR defines the color used for the highlight bar.  This
  10864.   bar is moved up and down when the user is making a selection.
  10865.  
  10866.   Position UNAVAILCOLOR defines the color of the unavailable menu entries.
  10867.   Whenever a menu entry is unavailable, the entry_name string displayed takes
  10868.   on this color.
  10869.  
  10870.   Colors can be created by using the CREATE_VIDEO_ATTRIBUTE() macro described
  10871.   on page 11.  A code sample to create the colors is as follows:
  10872.  
  10873.  
  10874.  
  10875.  Page 183                     The C Window Library                    Page 183
  10876.  
  10877.   #include "menu.h"
  10878.   unsigned int menu_colors[5];
  10879.  
  10880.   main()
  10881.   {
  10882.     {... code ...}
  10883.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  10884.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  10885.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  10886.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  10887.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  10888.       /* rest of the program */
  10889.   }
  10890.  
  10891.  
  10892.   As in creating the BAR_MENU_ENTRY's, if you are an advanced programmer,
  10893.   you will find other ways in assigning the colors.
  10894.  
  10895.  
  10896.   BarCreateMenu() function
  10897.   ------------------------
  10898.  
  10899.   Now that you have created the BAR_MENU_ENTRY's, and defined the color
  10900.   scheme, it is time to wrap all of these loose ends in one package.  The next
  10901.   step is to call the BarCreateMenu() function.  This function combines all
  10902.   of the BAR_MENU_ENTRY's, the colors you have defined, and other information
  10903.   into one entity called a BAR_MENU_PTR.
  10904.  
  10905.   A BAR_MENU_PTR is a bar menu structure.  Just like a WPOINTER is a
  10906.   pointer to a window, a BAR_MENU_PTR is used to reference the bar menu.
  10907.  
  10908.   A prototype of the call to BarCreateMenu() is as follows:
  10909.  
  10910.   BAR_MENU_PTR BarCreateMenu(BAR_MENU_ENTRY *b, unsigned *c, int row,
  10911.                                  int col, WPOINTER (*wfunc)())
  10912.  
  10913.   To illustrate how to use this call, let's use the BAR_MENU_ENTRY's and
  10914.   colors created in the previous examples:
  10915.  
  10916.   #include "menu.h"
  10917.   int menu_func();
  10918.  
  10919.   BAR_MENU_ENTRY bar_items[] = {
  10920.                                "File",1,4,'F',ALTF,NULLFN,
  10921.                                "Edit",1,10,'E',0,edit,
  10922.                                "Run",1,17,'R',0,NULLFN,
  10923.                                "Compile",1,23,'C',0,NULLFN,
  10924.                                "Project",1,33,'P',0,NULLFN,
  10925.                                "Options", 1,43,'O',0,NULLFN,
  10926.                                "Debug",1,53,'D',0,NULLFN,
  10927.                                "Break/watch",1,61,'B',0,NULLFN,
  10928.                                CWL_NULL};
  10929.  
  10930.  
  10931.  Page 184                     The C Window Library                    Page 184
  10932.  
  10933.   unsigned int menu_colors[5];
  10934.   BAR_MENU_PTR b;
  10935.  
  10936.   main()
  10937.   {
  10938.     WindowInitializeSystem();          /* Initialize C Window Library */
  10939.  
  10940.    /* define colors */
  10941.  
  10942.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  10943.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  10944.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(blue,white);
  10945.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,cyan);
  10946.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  10947.  
  10948.    /* create a BAR_MENU_PTR */
  10949.  
  10950.    WindowSaveInitial(0);  /* Save initial screen    */
  10951.    b = BarCreateMenu(menu_items,menu_colors, 1,1,WNULLFN);
  10952.   /* rest of the code */
  10953.   }
  10954.  
  10955.  
  10956.   In the example above there are two function calls that must be done before
  10957.   calling BarCreateMenu().  The first mandatory function is
  10958.   WindowInitializeSystem().  The other function must be WindowSaveInitial()
  10959.   The WindowInitializeSystem() function must be called to initialize global
  10960.   variables used by the menu manager.  The WindowSaveInitial() function is a
  10961.   mandatory function because the BarCreateMenu() function creates windows and
  10962.   assumes that the base screen has been saved.
  10963.  
  10964.  
  10965.   The example above declares the variable b to be a BAR_MENU_PTR.  This
  10966.   BAR_MENU_PTR is going to be used to reference the bar menu throughout the
  10967.   program.
  10968.  
  10969.   The first argument is a pointer to the first BAR_MENU_ENTRY.  In the above
  10970.   example,  menu_items is a pointer to the first BAR_MENU_ENTRY.
  10971.  
  10972.   The second argument is a pointer to the array of colors.  In our example,
  10973.   menu_colors is our array of colors.
  10974.  
  10975.   The third and fourth arguments denote the row and column to place the upper
  10976.   left hand corner of the bar menu window.
  10977.  
  10978.   The last argument to BarCreateMenu() is defined in the next sections.
  10979.  
  10980.  
  10981.  
  10982.  
  10983.  
  10984.  
  10985.  
  10986.  
  10987.  Page 185                     The C Window Library                    Page 185
  10988.  
  10989.   Default Bar Menu Window and Creating Your own Windows
  10990.   -----------------------------------------------------
  10991.  
  10992.   The sixth argument to the BarCreateMenu() function is a pointer to a
  10993.   function that will open a bar menu window.  If this is a NULL function
  10994.   pointer (WNULLFN), the menu manager will create a window.  For most
  10995.   applications, the window that the menu manager will create is adequate.  The
  10996.   menu manager uses these defaults when making the bar window:
  10997.  
  10998.      - A bordered window with the border consisting of single lines (SINGLEBOX).
  10999.      - The width of the window is determined by the longest row of entry names.
  11000.  
  11001.   If you want to create your own bar menu window, your function must return a
  11002.   WPOINTER.  Inside your function you must create and open a window using
  11003.   WindowInitialize() and WindowOpen().  For most applications, you do not have
  11004.   to display the window, instead the menu manager can do the displaying and
  11005.   hiding of the windows.
  11006.  
  11007.  
  11008.   Here is an example of creating your own custom window function:
  11009.  
  11010.  
  11011.  
  11012.   #include "menu.h"
  11013.   /* Other includes and menu stuff */
  11014.   WPOINTER my_open();
  11015.   BAR_MENU_PTR b;
  11016.  
  11017.   main()
  11018.   {
  11019.      /*   Other code */
  11020.      b = BarCreateMenu(menu_items,menu_colors,1,1,my_open);
  11021.      /* More code */
  11022.   }
  11023.  
  11024.  
  11025.  
  11026.   WPOINTER my_open()
  11027.   {
  11028.     WPOINTER w;
  11029.     w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,BLACKONWHITE,"");
  11030.     WindowOpen(w);
  11031.     return w;       /* May be null pointer,
  11032.                        but must return to BarCreateMenu() */
  11033.   }
  11034.  
  11035.  
  11036.   The example above lets the menu manager know that the window creation
  11037.   function is a user written function called my_open.  The row, column and
  11038.   height arguments (arguments 3 and 4) of BarCreateMenu() will be ignored
  11039.   when using a custom window function.  The row and column height parameters
  11040.   used to create the window in the call to WindowInitialize() in my_window()
  11041.   will take precedence over the arguments 3 and 4 used in BarCreateMenu().
  11042.  
  11043.  Page 186                     The C Window Library                    Page 186
  11044.  
  11045.   It is the programmer's responsibility to make sure that the window that is
  11046.   created is wide and tall enough to hold all of the menu entries.  If not, the
  11047.   results will be unpredictable.
  11048.  
  11049.  
  11050.  
  11051.   Accessing bar menu windows
  11052.   --------------------------
  11053.  
  11054.   After calling the BarCreateMenu() function, you can access the bar window
  11055.   by using the BAR_WINDOW() macro.  In the above example, b is the
  11056.   BAR_MENU_PTR and the value of BAR_WINDOW(b) is a pointer to the bar
  11057.   menu's window.  If you want to change borders move, slide, or anything you
  11058.   can do with normal windows, you must access the bar window in this way.
  11059.  
  11060.   For example, if you want to change the border of the bar window you would
  11061.   do the following:
  11062.  
  11063.  
  11064.       b = BarCreateMenu(...  /* other arguments */ )
  11065.       WindowDrawBorder(BAR_WINDOW(b),DOUBLEBOX);  /* change border to a
  11066.                                                        double lined box */
  11067.  
  11068.   The example calls WindowDrawBorder() to change the border of the bar
  11069.   window.
  11070.  
  11071.  
  11072.  
  11073.   Warnings
  11074.   --------
  11075.  
  11076.   Do not call WindowFree(), WindowClose() on the window of the bar menu.  The
  11077.   menu manager will call these functions when BarMenuFree() is called.  If you
  11078.   close the bar window on an active menu, the menu manager will assume that the
  11079.   bar window still exists.  Doing so will almost guarantee your application
  11080.   will bomb out.
  11081.  
  11082.  
  11083.  
  11084.   Return Values for BarCreateMenu()
  11085.   ---------------------------------
  11086.  
  11087.   If there are no errors, BarCreateMenu() returns a valid BAR_MENU_PTR
  11088.   pointer.  If there is an error when BarCreateMenu() is called, a null
  11089.   BAR_MENU_PTR is returned.  Here are the possible reasons why an error has
  11090.   occurred:
  11091.  
  11092.     1) There is not enough memory to allocate for the BAR_MENU_PTR or its
  11093.        internal data structures.
  11094.  
  11095.     2) There is not enough memory to allocate for the bar window.
  11096.  
  11097.     3) The bar window's size was invalid.
  11098.  
  11099.  Page 187                     The C Window Library                    Page 187
  11100.  
  11101.   Problems 1 and 2 all are caused by a lack of heap memory.  Problem 3 stems
  11102.   from having invalid parameters in the BarCreateMenu().  The arguments that
  11103.   are suspect are the third and fourth.  To remedy this problem, adjust these
  11104.   arguments such that the window can fit on the screen.
  11105.  
  11106.   For all of the above conditions, you can get the actual error code by
  11107.   checking the value of the global integer window_error_code.  If
  11108.   window_error_code is equal to NO_HEAP_MEM, then condition 1 or 2 has
  11109.   occurred.  If it is equal to BAD_WINDOW_SIZE, then condition 3 has occurred.
  11110.  
  11111.   If you have a custom window opening function, it is your responsibility to
  11112.   check the error conditions that may occur, and return a correct value or a
  11113.   null pointer if you cannot rectify the error in your custom routine.
  11114.  
  11115.  
  11116.   Here is an example:
  11117.  
  11118.   Example:
  11119.        int status;
  11120.        BAR_MENU_PTR b;
  11121.        b = BarCreateMenu(...);
  11122.        if (b == (BAR_MENU_PTR)0)  {   /* check for null BAR_MENU_PTR pointer */
  11123.          if (window_error_code == NO_HEAP_MEM)
  11124.             /* ... Condition 1 or 2 occurred */
  11125.          else
  11126.            /* Condition 3 occurred */
  11127.        }
  11128.  
  11129.  
  11130.  
  11131.  
  11132.  
  11133.  
  11134.  
  11135.  
  11136.  
  11137.  
  11138.  
  11139.  
  11140.  
  11141.  
  11142.  
  11143.  
  11144.  
  11145.  
  11146.  
  11147.  
  11148.  
  11149.  
  11150.  
  11151.  
  11152.  
  11153.  
  11154.  
  11155.  Page 188                     The C Window Library                    Page 188
  11156.  
  11157.                           SELECTING FROM BAR MENUS
  11158.                           ------------------------
  11159.  
  11160.   We have now created the bar menu.  Now how do we get the menu manager to
  11161.   act on our bar window?  The answer is the BarSelectMenu() function.
  11162.  
  11163.  
  11164.   BarSelectMenu() function
  11165.   ------------------------
  11166.  
  11167.   The BarSelectMenu() function displays the bar window, and allows the
  11168.   user to move the highlight bar until he/she has placed the bar on the desired
  11169.   entry, or the user presses a hotkey to invoke one of the entries.
  11170.  
  11171.   Before the call to the BarSelectMenu(), nothing has been displayed.  This
  11172.   means that you can resize the bar window, change borders etc. while
  11173.   everything is hidden away from view.  The only time when the bar menu is
  11174.   displayed is when the call to BarSelectMenu() is made (or unless you have
  11175.   displayed the bar window yourself using WindowDisplay()).
  11176.  
  11177.   A prototype of the call to BarSelectMenu() is as follows:
  11178.  
  11179.        int BarSelectMenu(BAR_MENU_PTR b, int rank, unsigned start)
  11180.  
  11181.   The first argument is the BAR_MENU_PTR.  The second argument is the rank of
  11182.   the bar window.  As with other windows, the rank determines how the window
  11183.   will be situated on the screen with respect to the other windows.  If you want
  11184.   more information on window ranks, please read page 2.  The last argument is
  11185.   the number of the menu entry of where the highlight bar should be situated.
  11186.   Usually this is 1, but this will give you the option to start on any one of
  11187.   the menu entries.  If the start value is out of bounds (say you have
  11188.   specified start to be 5 while there are only 4 menu entries) the menu manager
  11189.   will default to the first menu entry.
  11190.  
  11191.   Now let's put everything together:
  11192.  
  11193.   #include "menu.h"
  11194.  
  11195.   int menu_func();
  11196.  
  11197.   BAR_MENU_ENTRY bar_items[] = {
  11198.                                "File",1,4,'F',ALTF,menu_func,
  11199.                                "Edit",1,10,'E',0,menu_func,
  11200.                                "Run",1,17,'R',0,menu_func,
  11201.                                "Compile",1,23,'C',0,menu_func,
  11202.                                "Project",1,33,'P',0,menu_func,
  11203.                                "Options", 1,43,'O',0,menu_func,
  11204.                                "Debug",1,53,'D',0,menu_func,
  11205.                                "Break/watch",1,61,'B',0,menu_func,
  11206.                                CWL_NULL};
  11207.  
  11208.  
  11209.  
  11210.  
  11211.  Page 189                     The C Window Library                    Page 189
  11212.  
  11213.   unsigned int menu_colors[5];
  11214.   BAR_MENU_PTR b;
  11215.  
  11216.   main()
  11217.   {
  11218.     WindowInitializeSystem();
  11219.     WindowSaveInitial(0);  /* Remember to save the initial screen */
  11220.     menu_colors[ENTRYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  11221.     menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  11222.     menu_colors[HOTKEYCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  11223.     menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  11224.     menu_colors[UNAVAILCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  11225.    /* create a BAR_MENU_PTR */
  11226.    b = BarCreateMenu(bar_items,menu_colors, 1,1,WNULLFN);
  11227.    BarSetOptions(b,BARSTATIC | BARWRAP,1);
  11228.    BarSelectMenu(b,1,1);
  11229.   }
  11230.  
  11231.   int menu_func(BAR_MENU_PTR b, unsigned which)
  11232.   {
  11233.     WPOINTER w;
  11234.     w = WindowInitialize(BORDER,15,15,40,4,CREATE_VIDEO_ATTRIBUTE(black,white),
  11235.                          CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
  11236.     WindowOpen(w);
  11237.     WindowPrintf(w,"You have selected %s",BAR_ENTRY_STRING(b,which));
  11238.     WindowWriteCenterString(w,"Press a key to continue",3);
  11239.     WindowDisplay(w,1,NOEFFECT);
  11240.     GET_KEY();
  11241.     WindowFree(w,NOEFFECT);
  11242.     if (which == 9)
  11243.       return BAR_EXIT;
  11244.     else return BAR_CONTINUE;
  11245.   }
  11246.  
  11247.   The above example has a call to BarSelectMenu().  The arguments passed are
  11248.   b as the BAR_MENU_PTR, a window rank of 1, and a starting position of 1.  The
  11249.   BAR_ENTRY_STRING() macro that is called in menu_func() returns the entry
  11250.   string of a desired entry in a BAR_MENU_PTR.  The first argument is the
  11251.   BAR_MENU_PTR, and the second argument is the entry number of the entry
  11252.   desired.
  11253.  
  11254.  
  11255.   Values passed to menu function
  11256.   ------------------------------
  11257.  
  11258.   When a selection is made, the menu manager will call the function defined
  11259.   for the selection, and pass two arguments to this function.  The first
  11260.   argument passed is the BAR_MENU_PTR of the current bar menu and the
  11261.   second argument is the number of the item selected.  Item numbers are
  11262.   numbered from 1 to the highest entry in the menu.  For example, if the "File"
  11263.   entry is selected, the menu manager will pass the BAR_MENU_PTR b, and a
  11264.   1 to func().  If "Edit" is chosen, the menu manager passes a 2 as the
  11265.   second argument to func() etc.
  11266.  
  11267.  Page 190                     The C Window Library                    Page 190
  11268.  
  11269.   Values returned to menu manager
  11270.   -------------------------------
  11271.  
  11272.   The user function must return an integer back to the menu manager.  If the
  11273.   value returned to the menu manager is BAR_EXIT, the menu manager will exit
  11274.   from the current menu and will return control back to the function that
  11275.   called it.  If the return value is BAR_CONTINUE, the menu continues to
  11276.   process selections.
  11277.  
  11278.   The menu_func() function defined above creates a window, displays the entry
  11279.   you have chosen, and returns a value back to the menu manager.  If the value
  11280.   is BAR_EXIT, the menu manager returns control back to the function that
  11281.   called it.  In this case, main() called BarSelectMenu().  A return value of
  11282.   BAR_CONTINUE will cause the menu manager to let the user make another
  11283.   selection.
  11284.  
  11285.   The menu_func() function is a simple implementation.  However your function
  11286.   can do much more sophisticated things, including opening other bar menus.  If
  11287.   another bar menu is called while in another bar menu, the new bar menu gets
  11288.   its own menu manager and will not interfere with the original menu manager.
  11289.   This is good if a menu function will call another menu function.
  11290.  
  11291.  
  11292.  
  11293.   Return Values for BarSelectMenu()
  11294.   ---------------------------------
  11295.  
  11296.   If no errors occurred when BarSelectMenu() is called the menu manager
  11297.   returns NO_ERROR when the menu is closed.  There are three possibilities for
  11298.   errors when calling BarSelectMenu().  Here are the three possible errors:
  11299.  
  11300.   1) The bar menu's window does not exist.
  11301.  
  11302.   2) The bar menu's window is not opened.
  11303.  
  11304.   The first error occurred because the BarCreateMenu() function or your
  11305.   custom window function could not initialize the bar menu window, you
  11306.   inadvertently called WindowFree() on the bar menu's window, or you are
  11307.   overwriting data with a stray pointer.
  11308.  
  11309.   Error 2 can occur if the you inadvertently called WindowClose() on the bar
  11310.   menu's window, or you are overwriting data with a stray pointer.
  11311.  
  11312.   For all of the above conditions, you can get the actual error code by
  11313.   checking the value of the global integer window_error_code or by checking
  11314.   the return value of BarSelectMenu().  Here is a list of return values and
  11315.   their corresponding reasons:
  11316.  
  11317.  
  11318.     Return Value               Condition
  11319.     ------------               ---------
  11320.     BAD_WINDOW                    1
  11321.     WINDOW_NOT_OPEN               2
  11322.  
  11323.  Page 191                     The C Window Library                    Page 191
  11324.  
  11325.                          SETTING OPTIONS IN BAR MENUS
  11326.                          ----------------------------
  11327.  
  11328.   Type of Options
  11329.   ---------------
  11330.  
  11331.   By default the menu manager assumes the following things:
  11332.  
  11333.     1)  The highlight bar does not wrap if the user wants to move the bar past
  11334.         the last entry, or before the first entry.
  11335.  
  11336.     2)  The menu will be hidden from the screen when a selection is made and
  11337.         will reappear when control is returned to the menu manager.
  11338.  
  11339.     3)  A function is automatically invoked when the hotkey is pressed instead
  11340.         of calling a user-defined function which will tell the menu manager
  11341.         whether the menu entry is to be executed.
  11342.  
  11343.     4)  The bar menu window is hidden when the menu manager returns control
  11344.         to the calling function.
  11345.  
  11346.     5)  The highlight bar will skip unavailable entries.
  11347.  
  11348.     6)  The menu manager does not recognize enhanced keys (F11, F12, etc.).
  11349.  
  11350.   All of these assumptions can be changed at any time by calling the
  11351.   BarSetOptions() function.
  11352.  
  11353.  
  11354.   The BarSetOptions() function
  11355.   ----------------------------
  11356.  
  11357.   The BarSetOptions() function turns either one or more of the above
  11358.   options on or off.  The prototype to the call is as follows:
  11359.  
  11360.          int BarSetOptions(BAR_MENU_PTR b, int option, int switch)
  11361.  
  11362.   The first argument is the BAR_MENU_PTR.  The second argument are the
  11363.   options that you wish to change.  The third argument is whether you want to
  11364.   switch the options on or off.   What is meant by on and off is that the
  11365.   default options described above are "off".  By turning the options on you do
  11366.   the opposite of the default settings.  The "on" selection will do the
  11367.   following to each option:
  11368.  
  11369.     1)  The highlight bar will wrap around if the user wants to move the bar
  11370.         past the last entry or before the first entry.
  11371.  
  11372.     2)  The menu will not be hidden from the screen when a selection is made.
  11373.  
  11374.     3)  A user-defined function is called before invoking the hotkey that was
  11375.         selected.  This function will then return an integer back to the menu
  11376.         manager informing whether the function selected should be invoked, or
  11377.         the request should be rejected.
  11378.  
  11379.  Page 192                     The C Window Library                    Page 192
  11380.  
  11381.     4)  The bar window is not hidden when the menu manager returns control to
  11382.         the calling function.
  11383.  
  11384.     5)  Unavailable entries will be accepted by the menu manager.
  11385.  
  11386.     6)  The menu manager will recognize enhanced keys.
  11387.  
  11388.   Here is a definition of the available options:
  11389.  
  11390.      Option Name              Definition
  11391.      -----------              ----------
  11392.       BARWRAP             Highlight bar wrapping.
  11393.       BARSTATIC           Hide menu when selection is made.
  11394.       BARCONFIRM          Confirmation when selection is made via hotkey.
  11395.       BARDISPLAY          Display menu even after exit.
  11396.       BAROVERRIDE         Accept Unavailable entries.
  11397.       BARENHANCEDKEY      Recognize enhanced keys.
  11398.  
  11399.     Here are some sample calls to BarSetOptions:
  11400.  
  11401.       a) BarSetOptions(b,BARWRAP,1)
  11402.       b) BarSetOptions(b,BARSTATIC,1)
  11403.       c) BarSetOptions(b,BARCONFIRM,1)
  11404.       d) BarSetOptions(b,BARSTATIC,0)
  11405.       e) BarSetOptions(b,BARDISPLAY,1)
  11406.       f) BarSetOptions(b,BAROVERRIDE,1)
  11407.       g) BarSetOptions(b,BARENHANCEDKEY,1)
  11408.  
  11409.   The third argument is 1 for "on", 0 for "off".
  11410.  
  11411.   Example a) sets the highlight bar so that it will wrap.
  11412.  
  11413.   Example b) informs the menu manager that the menu will not be hidden when a
  11414.   selection is made.
  11415.  
  11416.   Example c) will tell the menu manager to call a user defined function that
  11417.   will inform the menu manager whether to invoke the selection in the menu.
  11418.  
  11419.   Example d) Informs the menu manager to hide the menu window when a menu
  11420.   function is invoked.
  11421.  
  11422.   Example e) Informs the menu manager not to hide the menu when control is
  11423.   returned to the function that called BarSelectMenu().
  11424.  
  11425.   Example f) Informs the menu manager to process unavailable entries.  This is
  11426.   useful if you want to set up your own error routine if the user selects an
  11427.   unavailable entry.
  11428.  
  11429.   Example g) imforms the menu manager to distinguish between normal keys and
  11430.   enhanced keys.
  11431.  
  11432.  
  11433.  
  11434.  
  11435.  Page 193                     The C Window Library                    Page 193
  11436.  
  11437.   Setting Multiple Options
  11438.   ------------------------
  11439.   You can also set multiple options with a single call by using a bitwise OR
  11440.   (|).  For example:
  11441.  
  11442.     BarSetOptions(b,BARWRAP | BARSTATIC | BARCONFIRM,1)
  11443.  
  11444.   will set options BARWRAP, BARSTATIC, and BARCONFIRM defined above.
  11445.  
  11446.  
  11447.  
  11448.   Setting the BarSetConfirmFunction()
  11449.   -----------------------------------
  11450.  
  11451.   When using the BARCONFIRM option, you must also use the
  11452.   BarSetConfirmFunction() function to point the menu to the confirmation
  11453.   function that will be called when a hotkey is pressed.  Here is a prototype
  11454.   of the BarSetConfirmFunction():
  11455.  
  11456.            BarSetConfirmFunction(BAR_MENU_PTR b, int (*func)())
  11457.  
  11458.   where b is the desired bar menu to assign the confirmation function to,
  11459.   and func is a pointer to a function that will return a value back to the menu
  11460.   manager that will inform it to either invoke the option, or ignore the
  11461.   option.
  11462.  
  11463.   When the confirmation function is called, the menu manager passes three
  11464.   arguments to func.  The prototype for your user defined function should be as
  11465.   follows:
  11466.  
  11467.         int my_confirm_func(BAR_MENU_PTR b, unsigned key, unsigned sel)
  11468.  
  11469.   where b is the BAR_MENU_PTR that is currently being processed, key is
  11470.   the hotkey that was pressed, and sel is the selection where the highlight bar
  11471.   is now positioned.  The highlight bar is always positioned on the hotkey
  11472.   selection even if it may not be invoked.  This user defined function must
  11473.   return a value back to the menu manager.  The valid values that can be
  11474.   returned are BAR_CONTINUE and BAR_DO_CHOICE.  If BAR_CONTINUE is
  11475.   returned, the menu selection is not invoked, if BAR_DO_CHOICE is selected,
  11476.   the menu entry is invoked.  Here is an example:
  11477.  
  11478.      #include "menu.h"
  11479.  
  11480.      int my_confirm_func();
  11481.      BAR_MENU_PTR b;
  11482.      /* ... */
  11483.      main()
  11484.      {
  11485.        BarSetOptions(b,BARCONFIRM,1);
  11486.        BarSetConfirmFunction(b,my_confirm_func);
  11487.        /* ... */
  11488.      }
  11489.  
  11490.  
  11491.  Page 194                     The C Window Library                    Page 194
  11492.  
  11493.      my_confirm_func(BAR_MENU_PTR b, unsigned k, unsigned sel)
  11494.      {
  11495.        /* ... */
  11496.        if (k == 'C' || k == 'c' || k == ALTF)
  11497.          return BAR_CONTINUE;
  11498.        else
  11499.          return BAR_DO_CHOICE;
  11500.      }
  11501.  
  11502.   The above function invokes the menu selection if the hotkey that was pressed
  11503.   is not a 'C', 'c', or ALT-F.
  11504.  
  11505.   The confirmation function can do anything, including setting options in the
  11506.   bar menu, displaying other windows etc.
  11507.  
  11508.  
  11509.  
  11510.   Return Values for BarSetOptions() function
  11511.   ------------------------------------------
  11512.  
  11513.   You can use the BarSetOptions() function at any time, including before
  11514.   calling the BarSelectMenu() function.  If the option is not a valid option,
  11515.   the function returns NO_ERROR, but does not change anything.  If the switch
  11516.   is not 0 or 1, a 1 is assumed.
  11517.  
  11518.   If there is an error, the error conditions and reasons are the same as the
  11519.   BarSelectMenu() function defined above.
  11520.  
  11521.  
  11522.  
  11523.  
  11524.  
  11525.  
  11526.  
  11527.  
  11528.  
  11529.  
  11530.  
  11531.  
  11532.  
  11533.  
  11534.  
  11535.  
  11536.  
  11537.  
  11538.  
  11539.  
  11540.  
  11541.  
  11542.  
  11543.  
  11544.  
  11545.  
  11546.  
  11547.  Page 195                     The C Window Library                    Page 195
  11548.  
  11549.                    MAKING ENTRIES AVAILABLE AND UNAVAILABLE
  11550.                    ----------------------------------------
  11551.  
  11552.   There may be cases when a menu entry should be made unavailable.  The entry
  11553.   shows up in the menu, but it is a different color than the other entries, and
  11554.   the highlight bar will just skip over this unavailable entry.
  11555.  
  11556.  
  11557.   BarMakeEntryAvailable() and
  11558.   BarMakeEntryUnavailable() functions
  11559.   -----------------------------------
  11560.  
  11561.   With The C Window Library, you can make entries available and unavailable at
  11562.   any time.  The BarMakeEntryAvailable() and the BarMakeEntryUnavailable()
  11563.   functions perform these tasks.
  11564.  
  11565.   A prototype of the call to both of these functions is as follows:
  11566.  
  11567.         int BarMakeEntryAvailable(BAR_MENU_PTR b, unsigned entry)
  11568.         int BarMakeEntryUnavailable(BAR_MENU_PTR b, unsigned entry)
  11569.  
  11570.   The first argument is the BAR_MENU_PTR.  The second argument is the number
  11571.   of the entry that you wish to change.  Entry numbers range from 1 to the
  11572.   highest entry in the menu.
  11573.  
  11574.  
  11575.  
  11576.   BAROVERRIDE option
  11577.   ------------------
  11578.  
  11579.   If the BAROVERRIDE option is set (see above), the menu manager will still
  11580.   process unavailable entries.  You must turn off BAROVERRIDE by using the
  11581.   BarSetOptions() function if you do not want to process unavailable entries.
  11582.  
  11583.  
  11584.   Return Values for BarMakeEntryAvaialble() and
  11585.   BarMakeEntryUnavailable() functions
  11586.   ---------------------------------------------
  11587.  
  11588.   If there is no error, both of these functions return NO_ERROR.
  11589.   If there is an error, the following possibilities can occur:
  11590.  
  11591.   1) The error can be one of the errors defined above for the BarSelectMenu()
  11592.  
  11593.   2) The menu entry is invalid.
  11594.  
  11595.   Refer to the BarSelectMenu() return values and reasons for failure defined
  11596.   above for error condition 1).  If the error is 2), check to see if the entry
  11597.   number supplied is valid.  The entry number cannot be < 1 or greater than the
  11598.   number of selections in the bar menu.
  11599.  
  11600.   If error 2) has occurred, the BarMakeEntryAvailable() and the
  11601.   BarMakeEntryUnavailable() return MENU_ENTRY_INVALID.
  11602.  
  11603.  Page 196                     The C Window Library                    Page 196
  11604.  
  11605.                        CHANGING THE MENU OPTIONS STRING
  11606.                        --------------------------------
  11607.  
  11608.   There may be times when you want to change a BAR_MENU_ENTRY entry_name
  11609.   string.  For instance, you may have a menu entry with the following
  11610.   entry_name:
  11611.  
  11612.           "Default File Name     ABC.DAT"
  11613.  
  11614.  
  11615.   If the user selects this choice, the file name should change to another file
  11616.   name the user wants.  From there the menu should reflect the new choice the
  11617.   user has made.  Let's say the user has changed the default file name to
  11618.   DEF.DAT.  The menu then should say:
  11619.  
  11620.  
  11621.           "Default File Name     DEF.DAT"
  11622.  
  11623.  
  11624.  
  11625.  
  11626.   BarChangeEntryString() function
  11627.   -------------------------------
  11628.  
  11629.   How do you change the entry string?  One way is to fool around with the
  11630.   BAR_MENU_PTR's structure members, and change the string yourself.  This is
  11631.   not recommended for the novice to average C programmer, since it is not a good
  11632.   idea to change the structure members directly without a full understanding of
  11633.   the structure.
  11634.  
  11635.   A safer way is to call the BarChangeEntryString() function.  A prototype of
  11636.   this function is as follows:
  11637.  
  11638.      BarChangeEntryString(BAR_MENU_PTR b, unsigned entry, char *newstring)
  11639.  
  11640.   The first argument is the BAR_MENU_PTR.  The second argument is the number
  11641.   of the entry that you wish to change.  Entry numbers range from 1 to the
  11642.   highest entry in the menu.  The third argument is a pointer to the new
  11643.   character string.  Remember that the width of the bar menu's window is equal
  11644.   to the width of the longest line of entry_name entries, therefore
  11645.   newstring cannot exceed the boundaries of the bar menu window (unless you
  11646.   will called WindowResizeWidth() or WindowResizeHeight() to resize the window).
  11647.  
  11648.  
  11649.  
  11650.   Return Values for BarChangeEntryString() function
  11651.   -------------------------------------------------
  11652.  
  11653.   If there is no error, then NO_ERROR is returned.
  11654.  
  11655.   If there is an error, the error conditions and reasons are the same as the
  11656.   BarMakeEntryAvailable() function defined above.
  11657.  
  11658.  
  11659.  Page 197                     The C Window Library                    Page 197
  11660.  
  11661.                            REDEFINING THE MENU KEYS
  11662.                            ------------------------
  11663.  
  11664.  
  11665.   Setting Global Key Definitions and
  11666.   the bar_key_definition Array
  11667.   ----------------------------------
  11668.  
  11669.   You can redefine the keys used to control moving the highlight bar, accepting
  11670.   the menu choice, and exiting from the menu.  Here is a list of the default key
  11671.   mapping:
  11672.  
  11673.        Function                               Key             Constant
  11674.        --------                               ---              ------
  11675.      Move highlight bar right               Up Arrow        BAR_RIGHTKEY
  11676.      Move highlight bar left                Down Arrow      BAR_LEFTKEY
  11677.      Accept Menu Choice                     Enter           BAR_ACCEPTKEY
  11678.      Escape Bar menu                        Escape          BAR_QUITKEY
  11679.      Move To First Menu Item                Home            BAR_HOMEKEY
  11680.      Move to Last Menu Item                 End             BAR_ENDKEY
  11681.  
  11682.   The global array bar_key_definition contains the values of the default
  11683.   bar menu key definitions.  The names under the Constant heading are the
  11684.   offsets in the bar_key_definition array of where the key value for the
  11685.   function is defined.  For instance, the value for the "Move highlight bar up"
  11686.   function is located at bar_key_definition[BAR_RIGHTKEY].  You can change the
  11687.   values in bar_key_definition at any time, but make sure that a definition
  11688.   for "Escape Bar menu" always exists, and that there are no duplicate
  11689.   definitions (i.e.  the "Move highlight bar up" key definition is the same as
  11690.   the "Move highlight bar down" key definition).  When defining new key values,
  11691.   you should use the values defined in the keycodes.h header file for non-ascii
  11692.   keys.
  11693.  
  11694.  
  11695.  
  11696.   Setting Local Key Definitions
  11697.   -----------------------------
  11698.  
  11699.   Another way of redefining menu keys is to load your own array of key
  11700.   definitions with your desired values, and then calling the BarAssignKeys()
  11701.   function.  With this method, each menu can have different key definitions.
  11702.  
  11703.  
  11704.   BarAssignKeys() function
  11705.   ------------------------
  11706.  
  11707.   Here is a prototype of the BarAssignKeys() function:
  11708.  
  11709.               int BarAssignKeys(BAR_MENU_PTR b, unsigned *keys)
  11710.  
  11711.   where b is the BAR_MENU_PTR, and keys is an array of key definitions.  Here
  11712.   is a small code example:
  11713.  
  11714.  
  11715.  Page 198                     The C Window Library                    Page 198
  11716.  
  11717.   #include "menu.h"
  11718.  
  11719.   unsigned mykeys[8] = {CTRLR,CTRLL,RETURN,ESC,HOME,END};
  11720.   BAR_MENU_PTR b;
  11721.  
  11722.   /* Other stuff...*/
  11723.  
  11724.   main()
  11725.   {
  11726.     /* Assume b is initialized */
  11727.  
  11728.     BarAssignKeys(b,mykeys); /* Assigns my key definitions to bar menu b */
  11729.   }
  11730.  
  11731.   The above example uses the constants defined in keycodes.h to assign to the
  11732.   array mykeys.  Each position in the mykeys array uses the default key mapping
  11733.   explained above.  In other words, mykeys[BAR_RIGHTKEY] is CTRLR, etc.
  11734.  
  11735.  
  11736.  
  11737.   Return Values for BarAssignKeys() function
  11738.   ------------------------------------------
  11739.  
  11740.   If there is no error, then NO_ERROR is returned.
  11741.  
  11742.   If there is an error, the error conditions and reasons are the same as the
  11743.   BarSelectMenu() function defined above.
  11744.  
  11745.  
  11746.  
  11747.  
  11748.  
  11749.  
  11750.  
  11751.  
  11752.  
  11753.  
  11754.  
  11755.  
  11756.  
  11757.  
  11758.  
  11759.  
  11760.  
  11761.  
  11762.  
  11763.  
  11764.  
  11765.  
  11766.  
  11767.  
  11768.  
  11769.  
  11770.  
  11771.  Page 199                     The C Window Library                    Page 199
  11772.  
  11773.                            PROCESSING UNDEFINED KEYS
  11774.                            -------------------------
  11775.  
  11776.   If you are an advanced programmer and/or have experience in using other
  11777.   window/menu libraries, you may be wondering "how do I define a function that
  11778.   supplies context-sensitive help for each BAR_MENU_ENTRY?  There is no
  11779.   structure member in BAR_MENU_ENTRY that supplies this".  With The C Window
  11780.   Library, any key that is not recognized by the menu manager (i.e. the key
  11781.   struck does not invoke a menu option, move the highlight bar up or down, or
  11782.   ends processing of the menu) can be processed by calling a user written
  11783.   function.   The WindowGet...() family of functions allowed us to define a
  11784.   function that will be called if a key that has no current definition is
  11785.   pressed.  For bar menus, we can do the same thing.
  11786.  
  11787.  
  11788.   The bar_undef_key function pointer
  11789.   ----------------------------------
  11790.  
  11791.   The global function pointer, bar_undef_key, can point to a user written
  11792.   function that will be called when the menu manager encounters a key that is
  11793.   not defined.  The declaration for bar_undef_key is as follows:
  11794.  
  11795.     unsigned int (*bar_undef_key)(BAR_MENU_PTR b, unsigned int sel,
  11796.                                     unsigned int *choice)
  11797.  
  11798.   The user written function takes three arguments.  The first argument is a
  11799.   pointer to the bar menu that the menu manager is currently processing. The
  11800.   second argument is an integer that contains the value of the key that was
  11801.   pressed.  The third argument is a pointer to an integer that will contain the
  11802.   number of the menu choice to execute.  Initially, choice points to an integer
  11803.   that contains the current menu choice that the menu highlight bar is situated.
  11804.   For instance, if the highlight bar is on the first menu choice when an
  11805.   undefined key is pressed, *choice will be equal to 1.  If bar_undef_key is
  11806.   equal to a Null Function pointer (NULLFN), no user defined function is called.
  11807.   By default, bar_undef_key is assigned to NULLFN.
  11808.  
  11809.  
  11810.   Values returned to menu manager
  11811.   -------------------------------
  11812.  
  11813.   If bar_undef_key is assigned to a function, the function must return an
  11814.   integer back to the menu manager.  This integer value will tell the menu
  11815.   manager how to proceed.  Here is a list of the valid return values that the
  11816.   user written function can return:
  11817.  
  11818.  
  11819.  
  11820.  
  11821.  
  11822.  
  11823.  
  11824.  
  11825.  
  11826.  
  11827.  Page 200                     The C Window Library                    Page 200
  11828.  
  11829.     Return                         Action to
  11830.     Value                            Take
  11831.     ------                         ---------
  11832.    BAR_CONTINUE          No Action. Continue processing the bar menu.
  11833.    BAR_DO_CHOICE         Accept and invoke menu entry assigned to *choice.
  11834.    BAR_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  11835.                               *choice and continue processing menu.
  11836.    BAR_ESCAPE            Escape the bar menu.
  11837.    BAR_MOVE_LEFT         Move to next bar menu.
  11838.    BAR_MOVE_RIGHT        Move to previous bar menu.
  11839.    BAR_MOVE_HOME         Move highlight to first available menu entry.
  11840.    BAR_MOVE_END          Move highlight to last available menu entry.
  11841.  
  11842.   A return value of BAR_CONTINUE is a "do nothing" command to the menu
  11843.   manager.
  11844.  
  11845.   If BAR_DO_CHOICE is returned to the menu manager, the integer assigned to
  11846.   the parameter *choice is used as the menu entry to invoke.  The highlight
  11847.   bar will automatically be moved to the menu choice specified, and the menu
  11848.   function will be called.  If BAR_MOVE_CONTINUE is returned to the menu
  11849.   manager, the highlight bar will be moved to the entry specified by the
  11850.   value of *choice, but no function is called.
  11851.  
  11852.   Return values of BAR_DO_CHOICE and BAR_MOVE_CONTINUE only work when the
  11853.   menu entry specified by *choice is an available entry or the BAROVERRIDE
  11854.   option is on , otherwise the menu manager just continues processing the
  11855.   bar menu.
  11856.  
  11857.  
  11858.   Here is an example of using a user defined function for the undefined keys:
  11859.  
  11860.  
  11861.   #include "menu.h"
  11862.  
  11863.   /*  Other includes */
  11864.  
  11865.   int user_func();
  11866.  
  11867.  
  11868.   main()
  11869.  
  11870.   {
  11871.     bar_undef_key = user_func;
  11872.  
  11873.     /* Other code */
  11874.   }
  11875.  
  11876.  
  11877.  
  11878.  
  11879.  
  11880.  
  11881.  
  11882.  
  11883.  Page 201                     The C Window Library                    Page 201
  11884.  
  11885.   unsigned int user_func(BAR_MENU_PTR b, unsigned sel, unsigned *choice)
  11886.   {
  11887.     switch(sel)
  11888.  
  11889.     {
  11890.       case F1:
  11891.         help(*choice);         /* call help function */
  11892.         return BAR_CONTINUE; /* return "do nothing" command to menu manager */
  11893.       case F2:
  11894.         *choice = 6;  /* let menu manager know to do choice 6 on the menu */
  11895.         return BAR_DO_CHOICE;     /* Also let menu manager know we are
  11896.                                      returning the "do the function assigned to
  11897.                                      *choice" command */
  11898.       default:
  11899.         return BAR_CONTINUE;
  11900.         /* let menu manager know not to do anything */
  11901.     }
  11902.   }
  11903.  
  11904.   int help(int choice)
  11905.   {  /* help function */
  11906.     switch (choice)
  11907.     {
  11908.       case 1:
  11909.         /* do context-sensitive help for entry 1 */
  11910.       break;
  11911.       case 2:
  11912.         /* do context-sensitive help for entry 2 */
  11913.       break;
  11914.        /* do more entries */
  11915.        /* ... */
  11916.     }
  11917.   }
  11918.  
  11919.   In the above example, if the user hits F1, a help function is called.  If you
  11920.   wanted to know how to incorporate a help function in the bar menus, here is
  11921.   the way to do it.
  11922.  
  11923.   If the user hits F2, the integer pointed to by choice is assigned a 6, and
  11924.   user_func() returns BAR_DO_CHOICE to the menu manager.  This tells the
  11925.   menu manager to invoke the function assigned to menu entry 6.
  11926.  
  11927.  
  11928.  
  11929.  
  11930.  
  11931.  
  11932.  
  11933.  
  11934.  
  11935.  
  11936.  
  11937.  
  11938.  
  11939.  Page 202                     The C Window Library                    Page 202
  11940.  
  11941.                               PRE-INPUT FUNCTION
  11942.                               ------------------
  11943.  
  11944.   With The C Window Library, you can define a function that will be performed
  11945.   just before the menu manager waits for the user to enter a keystroke.  This
  11946.   function can perform just about anything.
  11947.  
  11948.  
  11949.   Setting the global_bar_prefunc function pointer
  11950.   -----------------------------------------------
  11951.  
  11952.   The global_bar_prefunc function pointer points to this user written
  11953.   function.  Here is the prototype:
  11954.  
  11955.       void (*global_bar_prefunc)(BAR_MENU_PTR b, unsigned sel)
  11956.  
  11957.   The arguments that will be passed to your function are the following:
  11958.  
  11959.   a)  The BAR_MENU_PTR of the bar menu that called your function, and
  11960.   b)  The number of the selection that the highlight bar is currently on.
  11961.  
  11962.   The selection number ranges from 1 to the highest entry number of the menu.
  11963.  
  11964.   By default, global_bar_prefunc points to a NULLFN, and therefore will not be
  11965.   performed.  However, you can implement pre-input functions depending on the
  11966.   current selection.  For instance, you can write a function that displays
  11967.   extra information for each entry like so:
  11968.  
  11969.   #include "menu.h"
  11970.  
  11971.   char *mess[] = {
  11972.                    " This option saves and loads files",
  11973.                    " This brings you in edit mode",
  11974.                    " This compiles and/or links the current program",
  11975.  
  11976.                    /* ... More stuff */
  11977.                    };
  11978.  
  11979.  
  11980.   WPOINTER message_window;
  11981.  
  11982.   void disp_info();
  11983.  
  11984.   main()
  11985.   {
  11986.  
  11987.     /* ... */
  11988.  
  11989.     global_bar_prefunc = disp_info;
  11990.  
  11991.     /* ... */
  11992.   }
  11993.  
  11994.  Page 203                     The C Window Library                    Page 203
  11995.  
  11996.   void disp_info(BAR_MENU_PTR b, unsigned sel)
  11997.   {
  11998.      /* Assume message_window already created and opened */
  11999.  
  12000.     WindowClear(message_window,CREATE_VIDEO_ATTRIBUTE(black,white));
  12001.     WindowWriteString(message_window,mess[sel-1],1,1);
  12002.   }
  12003.  
  12004.  
  12005.   For simplicity, the menu definitions are left out of the preceding example.
  12006.   The disp_info displays the appropriate description in the window
  12007.   message_window.  The user written function must be declared as void.  Once
  12008.   the function exits, the function returns control to the menu manager, and the
  12009.   menu manager then looks for a keystroke from the user (i.e. to move the
  12010.   highlight bar up, down, escape the menu, hotkey, etc.).
  12011.  
  12012.  
  12013.  
  12014.  
  12015.  
  12016.  
  12017.  
  12018.  
  12019.  
  12020.  
  12021.  
  12022.  
  12023.  
  12024.  
  12025.  
  12026.  
  12027.  
  12028.  
  12029.  
  12030.  
  12031.  
  12032.  
  12033.  
  12034.  
  12035.  
  12036.  
  12037.  
  12038.  
  12039.  
  12040.  
  12041.  
  12042.  
  12043.  
  12044.  
  12045.  
  12046.  
  12047.  
  12048.  
  12049.  
  12050.  Page 204                     The C Window Library                    Page 204
  12051.  
  12052.                             DISPOSING OF BAR MENUS
  12053.                             ----------------------
  12054.  
  12055.   BarMenuFree() function
  12056.   ----------------------
  12057.  
  12058.   If the bar menu is no longer needed, the BarMenuFree() function will
  12059.   dispose of the bar menu and return any memory allocated to the bar menu,
  12060.   window, and  window memory back to the heap.  The call to the function
  12061.   is very simple:
  12062.  
  12063.          BarMenuFree(BAR_MENU_PTR b)
  12064.  
  12065.   where b is the BAR_MENU_PTR to dispose of.  Since this function destroys the
  12066.   BAR_MENU_PTR b, b must not be used for any bar menu functions, unless b
  12067.   is pointing to a valid BAR_MENU_PTR.
  12068.  
  12069.  
  12070.  
  12071.   Return Values for BarMenuFree()
  12072.   -------------------------------
  12073.  
  12074.   The return values and the reasons for failure are the same as
  12075.   BarSelectMenu().  Please refer to this section.
  12076.  
  12077.  
  12078.  
  12079.  
  12080.  
  12081.  
  12082.  
  12083.  
  12084.  
  12085.  
  12086.  
  12087.  
  12088.  
  12089.  
  12090.  
  12091.  
  12092.  
  12093.  
  12094.  
  12095.  
  12096.  
  12097.  
  12098.  
  12099.  
  12100.  
  12101.  
  12102.  
  12103.  
  12104.  
  12105.  
  12106.  Page 205                     The C Window Library                    Page 205
  12107.  
  12108.                                 PULLDOWN MENUS
  12109.                                 --------------
  12110.  
  12111.   Description
  12112.   -----------
  12113.  
  12114.   A pulldown menu is a combination of popup menus and a bar menu.  The bar menu
  12115.   portion of the pulldown menu acts the same way as a normal bar menu.  However
  12116.   when a choice is made from the bar menu, a popup menu appears with more
  12117.   options to choose.  An example of a pulldown menu is the integrated environ-
  12118.   ments of the Quick C and Turbo C compilers.
  12119.  
  12120.   Most of what was discussed previously will apply to pulldown menus.  Make
  12121.   sure that you have read the sections on popup menus and bar menus before
  12122.   preceding.
  12123.  
  12124.  
  12125.  
  12126.   Bar Menu and Popup Menu levels
  12127.   ------------------------------
  12128.  
  12129.   With pulldown menus there are two levels; the bar menu level and the popup
  12130.   menu level.  When in the bar menu level, no popup menu's are displayed, and
  12131.   the move right and move left keys move the highlight bar to the next or
  12132.   previous selection in the bar menu.  When in the popup menu level, the move
  12133.   right and move left keys not only move the highlight in the bar menu, but
  12134.   will also display the popup menu associated with the bar menu option.
  12135.  
  12136.  
  12137.  
  12138.  
  12139.  
  12140.  
  12141.  
  12142.  
  12143.  
  12144.  
  12145.  
  12146.  
  12147.  
  12148.  
  12149.  
  12150.  
  12151.  
  12152.  
  12153.  
  12154.  
  12155.  
  12156.  
  12157.  
  12158.  
  12159.  
  12160.  
  12161.  
  12162.  Page 206                     The C Window Library                    Page 206
  12163.  
  12164.                             CREATING PULLDOWN MENUS
  12165.                             -----------------------
  12166.  
  12167.  
  12168.   There are 4 steps that must be done when creating pulldown menus.  They are as
  12169.   follows:
  12170.  
  12171.      Step 1)  Create the bar menu portion by calling BarCreateMenu().
  12172.  
  12173.      Step 2)  Create each popup menu to be displayed underneath the bar by
  12174.               calling the PopupCreateMenu() function.
  12175.  
  12176.      Step 3)  Group all popup menus created in step 2 into an array of popup
  12177.               menu's.
  12178.  
  12179.      Step 4)  Call PulldownCreateMenu().
  12180.  
  12181.  
  12182.  
  12183.   For Step 1) the bar menu is created the same way as described in the Bar
  12184.   Menu section of this manual.  The only difference is that if there is a
  12185.   popup window that will be displayed under the bar menu option, the function
  12186.   pointer for that BAR_MENU_ENTRY must be a NULLFN (null integer function
  12187.   pointer).  Otherwise, if there is no popup menu defined for that bar menu
  12188.   option, the BAR_MENU_ENTRY's function pointer must point to a valid function.
  12189.   For instance, here is a sample array of BAR_MENU_ENTRY's used to create the
  12190.   Turbo C integrated environments bar menu:
  12191.  
  12192.  
  12193.     BAR_MENU_ENTRY bar_items[] = {
  12194.                 "File",       1,4, 'F',0,NULLFN,
  12195.                 "Edit",       1,10,'E',0,menu_func,
  12196.                 "Run",        1,17,'R',0,NULLFN,
  12197.                 "Compile",    1,23,'C',0,NULLFN,
  12198.                 "Project",    1,33,'P',0,NULLFN,
  12199.                 "Options",    1,43,'O',0,NULLFN,
  12200.                 "Debug",      1,53,'D',0,NULLFN,
  12201.                 "Break/watch",1,61,'B',0,NULLFN,
  12202.                           CWL_NULL};
  12203.  
  12204.   In the above example, All of the entries have a NULLFN function pointer except
  12205.   for the "Edit" entry.  The entries with NULLFN function pointers will have
  12206.   popup windows displayed under them when they are selected.  The "Edit" option
  12207.   will not have a popup menu displayed under it.  Instead, the menu_func()
  12208.   function is performed instead when "Edit" is chosen.
  12209.  
  12210.  
  12211.   Step 2) is as described in the Popup windows section.
  12212.  
  12213.   Step 3) can be done as follows:
  12214.  
  12215.  
  12216.  
  12217.  
  12218.  Page 207                     The C Window Library                    Page 207
  12219.  
  12220.   POPUP_MENU_PTR popup_list[8];
  12221.  
  12222.   main() {
  12223.   /* ... */
  12224.  
  12225.   popup_list[0] = PopupCreateMenu(/*..argument list..*/);
  12226.   popup_list[1] = (POPUP_MENU_PTR)0; /* No popup, so value must be NULL */
  12227.   popup_list[2] = PopupCreateMenu(/*..argument list..*/);
  12228.   popup_list[3] = PopupCreateMenu(/*..argument list..*/);
  12229.   popup_list[4] = PopupCreateMenu(/*..argument list..*/);
  12230.   popup_list[5] = PopupCreateMenu(/*..argument list..*/);
  12231.   popup_list[6] = PopupCreateMenu(/*..argument list..*/);
  12232.   popup_list[7] = PopupCreateMenu(/*..argument list..*/);
  12233.  
  12234.  
  12235.   The above example shows each element of popup_list is assigned to the return
  12236.   value of PopupCreateMenu(), except for popup_list[1].  Note that
  12237.   popup_list[1] is a null POPUP_MENU_PTR.  Here is the reason.  Let's say that
  12238.   there is an option on the bar menu that DOES NOT have a popup menu associated
  12239.   with it.  In other words, it is just a single function option, and no
  12240.   sub-functions are possible.  The entry in the array of POPUP_MENU_PTR's that
  12241.   will correspond to the position of where there is no popup menu should be
  12242.   NULL.  The above example shows that the second POPUP_MENU_PTR is non-existent
  12243.   (matches with the BAR_MENU_ENTRY called "Edit", which is the second bar
  12244.   entry).
  12245.  
  12246.   Once the bar menu and popup menus are created, you can set options by
  12247.   calling the BarSetOptions() or the PopupSetOptions() function, assign menu
  12248.   keys using the BarAssignKeys() or PopupAssignKeys() functions, etc. just as
  12249.   described earlier in this manual.  Remember that a pulldown menu just
  12250.   incorporates all of your menus into one manageable entity.
  12251.  
  12252.  
  12253.  
  12254.   The PulldownCreateMenu() function
  12255.   ---------------------------------
  12256.  
  12257.   The next step (Step 4) is done by calling the PulldownCreateMenu() function.
  12258.   This function integrates the bar menu and the array of popup menus in a
  12259.   single unit.  A pointer to this unit is returned.  This pointer is declared
  12260.   as a PULLDOWN_MENU_PTR.  The prototype form the PulldownCreateMenu() function
  12261.   is as follows:
  12262.  
  12263.          PULLDOWN_MENU_PTR PulldownCreateMenu(POPUP_MENU_PTR popups[],
  12264.                                               BAR_MENU_PTR bar,
  12265.                                               int adjust)
  12266.  
  12267.   The first argument is a pointer to an array of POPUP_MENU_PTR's.  In the
  12268.   above example, the second argument is the BAR_MENU_PTR.  Here is an example of
  12269.   how to use the PulldownCreateMenu() function:
  12270.  
  12271.  
  12272.  
  12273.  
  12274.  Page 208                     The C Window Library                    Page 208
  12275.  
  12276.   #include "menu.h"
  12277.  
  12278.   BAR_MENU_ENTRY bar_items[] = {
  12279.                 "File",       1,4, 'F',0,NULLFN,
  12280.                 "Edit",       1,10,'E',0,menu_func,
  12281.                 "Run",        1,17,'R',0,NULLFN,
  12282.                 "Compile",    1,23,'C',0,NULLFN,
  12283.                 "Project",    1,33,'P',0,NULLFN,
  12284.                 "Options",    1,43,'O',0,NULLFN,
  12285.                 "Debug",      1,53,'D',0,NULLFN,
  12286.                 "Break/watch",1,61,'B',0,NULLFN,
  12287.                           CWL_NULL};
  12288.  
  12289.  
  12290.   POPOP_MENU_ENTRY p1[] = {
  12291.                           /* Popup entries */,
  12292.                           CWL_NULL,0 };
  12293.  
  12294.   POPUP_MENU_ENTRY p2[] = POPUP_NULL_ENTRY; /* This constant defines an empty
  12295.                                                POPUP_MENU_ENTRY  */
  12296.  
  12297.   POPUP_MENU_ENTRY p3[] = {
  12298.                           /* More popup entries */
  12299.                         CWL_NULL, 0 };
  12300.  
  12301.   POPUP_MENU_ENTRY p4[] = {
  12302.                           /* More popup entries */
  12303.                         CWL_NULL, 0 };
  12304.  
  12305.  
  12306.   POPUP_MENU_ENTRY p5[] = {
  12307.                           /* More popup entries */
  12308.                         CWL_NULL, 0 };
  12309.  
  12310.   POPUP_MENU_ENTRY p6[] = {
  12311.                           /* More popup entries */
  12312.                         CWL_NULL, 0 };
  12313.  
  12314.   POPUP_MENU_ENTRY p7[] = {
  12315.                           /* More popup entries */
  12316.                         CWL_NULL, 0 };
  12317.  
  12318.   POPUP_MENU_ENTRY p7[] = {
  12319.                           /* More popup entries */
  12320.                         CWL_NULL, 0 };
  12321.  
  12322.   POPUP_MENU_PTR popup_list[8];
  12323.  
  12324.  
  12325.   BAR_MENU_PTR bar;
  12326.  
  12327.   PULLDOWN_MENU_PTR pull;
  12328.  
  12329.  
  12330.  Page 209                     The C Window Library                    Page 209
  12331.  
  12332.   main()
  12333.   {
  12334.     int i;
  12335.     WindowInitializeSystem();
  12336.     WindowSaveInitial(0);
  12337.     bar = BarCreateMenu(bar_items, { other arguments } );
  12338.  
  12339.     popup_list[0] = PopupCreateMenu(p1, { other arguments } );
  12340.     popup_list[1] = p2;
  12341.     popup_list[2] = PopupCreateMenu(p3, { other arguments } );
  12342.     popup_list[3] = PopupCreateMenu(p4, { other arguments } );
  12343.     popup_list[4] = PopupCreateMenu(p5, { other arguments } );
  12344.     popup_list[5] = PopupCreateMenu(p6, { other arguments } );
  12345.     popup_list[6] = PopupCreateMenu(p7, { other arguments } );
  12346.     popup_list[7] = PopupCreateMenu(p8, { other arguments } );
  12347.  
  12348.     pull = PulldownCreateMenu(popup_list,bar,1);
  12349.     {...}
  12350.   }
  12351.  
  12352.   In the above example, bar is a BAR_MENU_PTR, p1, p2, p3, p4, etc. are all
  12353.   lists of POPUP_MENU_ENTRY's.  The array of POPUP_MENU_PTR's is called
  12354.   popup_list, and the PULLDOWN_MENU_PTR is called pull.  Please note the use of
  12355.   the POPUP_NULL_ENTRY constant.  Use this constant when initializing a
  12356.   POPUP_MENU_ENTRY list to no items.
  12357.  
  12358.   The bar menu is initialized by calling BarCreateMenu() using bar_items as the
  12359.   list of BAR_MENU_ENTRY's.  The PopupCreateMenu() is called for each member of
  12360.   the popup_list array.  Note that the popup_list[1] is assigned a null
  12361.   POPUP_MENU_PTR.  This indicates that there is no popup menu for the second
  12362.   bar item ("Edit").  Even though it is not shown, you should check to see if
  12363.   BarCreateMenu() and all of the PopupCreateMenu() function calls returned
  12364.   without error.
  12365.  
  12366.   The call to PulldownCreateMenu() is done with the first argument being the
  12367.   the pointer to the array of POPUP_MENU_PTR's, namely popup_list.  The second
  12368.   argument is the BAR_MENU_PTR bar, and the last argument is discussed in the
  12369.   next section.
  12370.  
  12371.  
  12372.  
  12373.   Automatic Adjustment of Popup Windows
  12374.   -------------------------------------
  12375.  
  12376.   The last argument to PulldownCreateMenu() will inform the menu manager to
  12377.   adjust all the popup menu window positions, so that they fit neatly under the
  12378.   bar menu.  If the adjust argument in PulldownCreateMenu() is a 1, the
  12379.   previous (row,col) positions of each popup menu window is ignored
  12380.   (Arguments 3 and 4 of PopupCreateMenu()), and the menu manager decides where
  12381.   the popup window should be placed on the screen.  Otherwise, if adjust is 0,
  12382.   the previous values of the (row,col) position of the popup menu is used.
  12383.  
  12384.   Here is how the menu manager decides where the popup window should be placed:
  12385.  
  12386.  Page 210                     The C Window Library                    Page 210
  12387.  
  12388.   a)  The first attempt tries to place the left hand corner of the popup window
  12389.       under the first character of the option name in the bar menu.  If the
  12390.       column on the screen where we have placed the popup window, plus the
  12391.       popup windows width does not exceed the width of the bar, then we have
  12392.       found a "good" position for the popup window, if not then do step b).
  12393.  
  12394.   b)  We place the upper right hand corner of the popup window underneath the
  12395.       last column of the bar menu's window.  If the upper left-hand corner of
  12396.       the popup window can be placed in a screen column greater than or equal
  12397.       to 1, then we have found the "good" position.  If the upper left-hand
  12398.       corner cannot be placed in column 1 then do step c).
  12399.  
  12400.   c)  Place the upper left hand corner of the popup window at the first column
  12401.       of the bar menu window.  If this does not work then do step d).
  12402.  
  12403.   d)  place the popup window in column 1 of the screen.
  12404.  
  12405.   Here are a few examples of the above scenarios:
  12406.  
  12407.    1)
  12408.         -------------------------------------------------------------
  12409.         |  File      Edit      Compile      Options    Project      |
  12410.         |                                                           |
  12411.         -------------------------------------------------------------
  12412.           |            |
  12413.           |Condition a)|
  12414.           |  worked!   |
  12415.           |            |
  12416.           |------------|
  12417.  
  12418.    2a)
  12419.         -------------------------------------------------------------
  12420.         |  File      Edit      Compile      Options    Project      |
  12421.         |                                                           |
  12422.         ----------------------------------------------------------------------
  12423.                                             |                                |
  12424.                                             |  Too wide! option a) failed!   |
  12425.                                             |                                |
  12426.                                             |         Try option b)          |
  12427.                                             |                                |
  12428.                                             |--------------------------------|
  12429.  
  12430.    2b)
  12431.  
  12432.         -------------------------------------------------------------
  12433.         |  File      Edit      Compile      Options    Project      |
  12434.         |                                                           |
  12435.         -------------------------- ------------------------- --------                                   ----------
  12436.                                    |                                |
  12437.                                    |       option b) worked!        |
  12438.                                    |                                |
  12439.                                    |--------------------------------|
  12440.  
  12441.  
  12442.  Page 211                     The C Window Library                    Page 211
  12443.  
  12444.   In the first example, 1), the assumption is that the menu manager tries to
  12445.   place a popup window underneath the "File" in the bar menu.  It satisfies
  12446.   condition a), so we have found a good position.
  12447.  
  12448.   In the second example, 2a), the assumption is that the menu manager is trying
  12449.   to place a popup window under the "Compile" in the bar menu.   The first
  12450.   attempt fails because the popup window is too wide to be contained entirely
  12451.   in the bar menu.  We then try again to see if condition b) can be satisfied.
  12452.   Example 2b) shows that we can place the popup window according to condition
  12453.   b), and we have found a good condition.
  12454.  
  12455.   The other conditions, c) and d) should be self-explanatory at this point.
  12456.  
  12457.   Remember, if you do not like the way the menu manager selects the window
  12458.   position, you can either
  12459.  
  12460.   a)  specify the row and column positions of each popup menu window yourself
  12461.       when calling PopupCreateMenu(), and then calling PulldownCreateMenu()
  12462.       with a 0 (no adjustment) as the third argument or
  12463.  
  12464.   b)  Let the menu manager decide where to put the windows, and then adjust the
  12465.       positions yourself by calling WindowMove().
  12466.  
  12467.  
  12468.  
  12469.  
  12470.   Return values for PulldownCreateMenu()
  12471.   --------------------------------------
  12472.  
  12473.   If there is no error, PulldownCreateMenu() returns a valid PULLDOWN_MENU_PTR.
  12474.   If there is an error, PulldownCreateMenu() returns a null PULLDOWN_MENU_PTR.
  12475.  
  12476.   Here are the possible reasons why an error has occurred:
  12477.  
  12478.   1) There was not enough memory to allocate for the PULLDOWN_MENU_PTR or its
  12479.      internal data structures.
  12480.  
  12481.   2) The window for the bar menu did not exist.
  12482.  
  12483.   The first error results from a lack of heap memory.  If this error occurs,
  12484.   the global integer window_error_code will be set to NO_HEAP_MEM.
  12485.  
  12486.   If the second error occurs, this is an indication that the BAR_MENU_PTR was
  12487.   not created properly.  Check the return values for BarCreateMenu() if this
  12488.   happens.  The window_error_code is set to BAD_WINDOW if this error occurs.
  12489.  
  12490.   There is no check to see if the POPUP_MENU_PTR's are valid.  It is
  12491.   conceivable that there may be some entries on the bar that do not have popup
  12492.   menu's under them.  Therefore no check can be made for valid
  12493.   POPUP_WINDOW_PTR's.  It is the programmer's responsibility to check for
  12494.   invalid POPUP_MENU_PTR's when creating the popup menus.
  12495.  
  12496.  
  12497.  
  12498.  Page 212                     The C Window Library                    Page 212
  12499.  
  12500.                          SELECTING FROM PULLDOWN MENUS
  12501.                          -----------------------------
  12502.  
  12503.  
  12504.   The PulldownSelectMenu() function
  12505.   ---------------------------------
  12506.  
  12507.  
  12508.   The PulldownSelectMenu() allows selection from a pulldown menu.  This
  12509.   function has 6 arguments.  The prototype to this function is as follows:
  12510.  
  12511.       int PulldownSelectMenu(PULLDOWN_MENU_PTR pull, int barrank,
  12512.                              unsigned barstart, int *poprank,
  12513.                              unsigned *popstart, int imm)
  12514.  
  12515.  
  12516.   The first argument is a pointer to the PULLDOWN_MENU_PTR.  The second
  12517.   argument is the window rank of the bar menu window.  The third argument is
  12518.   the menu option where the bar menu should start beginning processing.  If the
  12519.   option is invalid or unavailable, the starting entry is the first available
  12520.   entry or the first entry if the BAROVERRIDE option is on for the bar menu.
  12521.  
  12522.   The fourth argument is an array of window ranks for each popup menu's window.
  12523.   This array will correspond to each of the popup menu's windows, including
  12524.   null popup menus.
  12525.  
  12526.   Example:
  12527.         int ranks[] = {1,1,1,1,1,1,1,1};
  12528.         unsigned start[] = {1,1,1,1,1,1,1,1};
  12529.  
  12530.         main() {
  12531.         /* ... */
  12532.           PulldownSelectMenu(pull,1,1,ranks,start,1);
  12533.  
  12534.         }
  12535.  
  12536.  
  12537.   The fifth argument is an array of starting entry numbers for each popup menu.
  12538.   This array will correspond to each of the popup menus, including NULL popup
  12539.   menus.  The previous example illustrates how this could be done.
  12540.  
  12541.  
  12542.  
  12543.   Immediate Mode
  12544.   --------------
  12545.  
  12546.   The last argument to PulldownSelectMenu() determines whether the menu will
  12547.   start in immediate mode.  Immediate mode will display the bar menu, and will
  12548.   also display the popup menu defined for the bar option.  If immediate mode
  12549.   is desired, the last argument is a 1, otherwise it is a 0.
  12550.  
  12551.  
  12552.  
  12553.  
  12554.  Page 213                     The C Window Library                    Page 213
  12555.  
  12556.   Values passed to the selected menu function
  12557.   -------------------------------------------
  12558.  
  12559.   When a selection is made, the menu manager will call the function defined
  12560.   for the selection, and pass five arguments to this function.  The first
  12561.   argument passed is the PULLDOWN_MENU_PTR of the current pulldown menu.  The
  12562.   second argument is the BAR_MENU_PTR of the pulldown menu.  The third argument
  12563.   is the POPUP_MENU_PTR of the selected entry.  If there is no popup menu,  the
  12564.   value passed for this argument is a NULL pointer.  The fourth argument is the
  12565.   number of the item selected on the bar menu.  The fifth argument is the
  12566.   number of the item selected on the popup menu.
  12567.  
  12568.  
  12569.  
  12570.   Values returned to the menu manager
  12571.   -----------------------------------
  12572.  
  12573.   Your function must return a value back to the menu manager.  There are three
  12574.   possible return values, PULLDOWN_EXIT, PULLDOWN_CONTINUE, and
  12575.   PULLDOWN_POPUP_EXIT.
  12576.  
  12577.   The PULLDOWN_EXIT return value will cause the menu manager to close both the
  12578.   popup menu window (if one was displayed), and the bar menu.  Then control is
  12579.   returned back to the function that called PulldownSelectMenu().
  12580.  
  12581.   The PULLDOWN_CONTINUE return value will cause the menu manager to continue
  12582.   processing the pulldown menu without closing the popup window (if one was
  12583.   displayed).
  12584.  
  12585.   The PULLDOWN_POPUP_EXIT value will cause the menu manager to close the popup
  12586.   menu, but will continue processing the bar portion of the window.  To display
  12587.   the popup menu's again, a selection must be made on the bar menu.
  12588.  
  12589.  
  12590.  
  12591.   If the return value is not one of the ones mentioned above, PULLDOWN_CONTINUE
  12592.   is assumed.
  12593.  
  12594.  
  12595.  
  12596.   Return Values for PulldownSelectMenu()
  12597.   --------------------------------------
  12598.  
  12599.   If there are no errors, PulldownSelectMenu() returns NO_ERROR.
  12600.  
  12601.   If the bar menu window does not exist, PulldownSelectMenu() immediately
  12602.   returns with BAD_WINDOW.
  12603.  
  12604.   If the bar menu window is not open, PulldownSelectMenu() immediately returns
  12605.   with WINDOW_NOT_OPEN.
  12606.  
  12607.  
  12608.  
  12609.  
  12610.  Page 214                     The C Window Library                    Page 214
  12611.  
  12612.                           REDEFINING KEY DEFINITIONS
  12613.                           --------------------------
  12614.  
  12615.   The bar menu key definitions are invoked when the pulldown menu is at the bar
  12616.   menu level.  The popup menu keys are invoked when the pulldown menu is at the
  12617.   popup menu level.
  12618.  
  12619.   If the bar option does not have a popup menu associated with it, the bar menu
  12620.   keys are always used.
  12621.  
  12622.  
  12623.  
  12624.  
  12625.  
  12626.  
  12627.  
  12628.  
  12629.  
  12630.  
  12631.  
  12632.  
  12633.  
  12634.  
  12635.  
  12636.  
  12637.  
  12638.  
  12639.  
  12640.  
  12641.  
  12642.  
  12643.  
  12644.  
  12645.  
  12646.  
  12647.  
  12648.  
  12649.  
  12650.  
  12651.  
  12652.  
  12653.  
  12654.  
  12655.  
  12656.  
  12657.  
  12658.  
  12659.  
  12660.  
  12661.  
  12662.  
  12663.  
  12664.  
  12665.  
  12666.  Page 215                     The C Window Library                    Page 215
  12667.  
  12668.                   REDEFINING KEY DEFINITIONS FOR POPUP MENUS
  12669.                   ------------------------------------------
  12670.  
  12671.   Setting Popup Menu Global Key Definitions
  12672.   -----------------------------------------
  12673.  
  12674.   In the previous sections on popup menus, there was a global array of key
  12675.   definitions used for popup menus.  Recall that there were 3 key definitions
  12676.   that were not assigned.  These definitions were POPUP_RIGHTKEY,
  12677.   POPUP_LEFTKEY, and POPUP_PULLDOWN_ESCAPE.  When a popup menu is
  12678. incorporated
  12679.   into a pulldown menu (after the PulldownCreateMenu() is called), the global
  12680.   array popup_key_definition is assigned the default values for these
  12681.   definitions.  Here are the default values for the popup portion of the
  12682.   pulldown menu:
  12683.  
  12684.  
  12685.        Function                      Key             Constant
  12686.        --------                      ---              ------
  12687.      Move highlight bar up         Up Arrow        POPUP_UPKEY
  12688.      Move highlight bar down       Down Arrow      POPUP_DOWNKEY
  12689.      Accept Menu Choice            Enter           POPUP_ACCEPTKEY
  12690.      Escape Pop-up menu            Escape          POPUP_QUITKEY
  12691.      Move To First Menu Item       Home            POPUP_HOMEKEY
  12692.      Move to Last Menu Item        End             POPUP_ENDKEY
  12693.      Move To Next Popup Menu       Right Arrow     POPUP_RIGHTKEY
  12694.      Move to Previous Popup Menu   Left Arrow      POPUP_LEFTKEY
  12695.      Escape Pulldown Menu          Not Assigned    POPUP_PULLDOWN_QUITKEY
  12696.  
  12697.   The global array popup_key_definition contains the values of the default
  12698.   popup menu key definitions.  The names under the Constant heading are the
  12699.   offsets in the popup_key_definition array of where the key value for the
  12700.   function is defined.  For instance, the value for the "Move highlight bar up"
  12701.   function is located at popup_key_definition[POPUP_UPKEY].  You can change the
  12702.   values in popup_key_definition at any time, but make sure that a definition
  12703.   for "Escape Pop-up menu" and/or "Escape Pulldown Menu" always exists, and
  12704.   that there are no duplicate definitions (i.e.  the "Move highlight bar up"
  12705.   key definition is the same as the "Move highlight bar down" key definition).
  12706.   When defining new key values, you should use the values defined in the
  12707.   keycodes.h header file for non-ascii keys.
  12708.  
  12709.   Also note that popup_key_definition[POPUP_PULLDOWN_QUITKEY] is not assigned.
  12710.   Since the key that is usually used to quit a pulldown menu is the Escape
  12711.   (ESC) key, and this definition conflicts with the "Escape Popup menu", it is
  12712.   better to let the programmer change the definition explicitly.
  12713.  
  12714.  
  12715.  
  12716.   Setting Popup Menu Local Definitions
  12717.   ------------------------------------
  12718.  
  12719.   You can use the PopupAssignKeys() function explained on page 172 to redefine
  12720.   the popup menu keys for each popup menu.
  12721.  
  12722.  Page 216                     The C Window Library                    Page 216
  12723.  
  12724.  
  12725.  
  12726.  
  12727.  
  12728.  
  12729.  
  12730.  
  12731.                       This page intentionally left blank.
  12732.  
  12733.  
  12734.  
  12735.  
  12736.  
  12737.  
  12738.  
  12739.  
  12740.  
  12741.  
  12742.  
  12743.  
  12744.  
  12745.  
  12746.  
  12747.  
  12748.  
  12749.  
  12750.  
  12751.  
  12752.  
  12753.  
  12754.  
  12755.  
  12756.  
  12757.  
  12758.  
  12759.  
  12760.  
  12761.  
  12762.  
  12763.  
  12764.  
  12765.  
  12766.  
  12767.  
  12768.  
  12769.  
  12770.  
  12771.  
  12772.  
  12773.  
  12774.  
  12775.  
  12776.  
  12777.  
  12778.  Page 217                     The C Window Library                    Page 217
  12779.  
  12780.                 REDEFINING KEY DEFINITIONS FOR THE BAR MENU
  12781.                 -------------------------------------------
  12782.  
  12783.  
  12784.   Setting bar menu global key definitions
  12785.   ---------------------------------------
  12786.  
  12787.   As was explained on page 198, you can redefine the keys used to control moving
  12788.   the highlight bar, accepting the menu choice, and exiting from the menu.
  12789.   Here is a list of the default key mapping:
  12790.  
  12791.        Function                               Key             Constant
  12792.        --------                               ---              ------
  12793.      Move highlight bar right               Up Arrow        BAR_RIGHTKEY
  12794.      Move highlight bar left                Down Arrow      BAR_LEFTKEY
  12795.      Accept Menu Choice                     Enter           BAR_ACCEPTKEY
  12796.      Escape Bar menu (Escape Pulldown Menu) Escape          BAR_QUITKEY
  12797.      Move To First Menu Item                Home            BAR_HOMEKEY
  12798.      Move to Last Menu Item                 End             BAR_ENDKEY
  12799.  
  12800.  
  12801.  
  12802.   The global array bar_key_definition contains the values of the default
  12803.   bar menu key definitions.  The names under the Constant heading are the
  12804.   offsets in the bar_key_definition array of where the key value for the
  12805.   function is defined.  For instance, the value for the "Move highlight bar up"
  12806.   function is located at bar_key_definition[BAR_RIGHTKEY].  You can change the
  12807.   values in bar_key_definition at any time, but make sure that a definition
  12808.   for "Escape Bar menu" always exists, and that there are no duplicate
  12809.   definitions (i.e.  the "Move highlight bar up" key definition is the same as
  12810.   the "Move highlight bar down" key definition).  When defining new key values,
  12811.   you should use the values defined in the keycodes.h header file for non-ascii
  12812.   keys.
  12813.  
  12814.   Note that "Escape Bar Menu" will also escape the pulldown menu.
  12815.  
  12816.  
  12817.  
  12818.  
  12819.   Setting Bar Menu Local definitions
  12820.   ----------------------------------
  12821.  
  12822.   You can use the BarAssignKeys() function explained on page 198 to redefine
  12823.   the bar menu keys.
  12824.  
  12825.  
  12826.  
  12827.  
  12828.  
  12829.  
  12830.  
  12831.  
  12832.  
  12833.  
  12834.  Page 218                     The C Window Library                    Page 218
  12835.  
  12836.                        PROCESSING UNDEFINED POPUP MENU KEYS
  12837.                        ------------------------------------
  12838.  
  12839.   Processing undefined keys is the same as explained on page 174 for popup
  12840.   menus.  However, there are 3 new return values that can be used for popup
  12841.   menus that are incorporated in pulldown menus.
  12842.  
  12843.   The popup_undef_key function pointer acts the same way as described
  12844.   previously.  Here are the possible values that the function pointed to by
  12845.   popup_undef_key must return:
  12846.  
  12847.  
  12848.     Return                         Action to
  12849.     Value                            Take
  12850.     ------                         ---------
  12851.    POPUP_CONTINUE          No Action. Continue processing the popup menu.
  12852.    POPUP_MOVE_UP           Move the highlight bar up.
  12853.    POPUP_MOVE_DOWN         Move the highlight bar down.
  12854.    POPUP_DO_CHOICE         Accept and invoke menu entry assigned to *choice.
  12855.    POPUP_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  12856.                               *choice and continue processing menu.
  12857.    POPUP_ESCAPE            Escape the popup menu.
  12858.    POPUP_MOVE_HOME         Move highlight to first available menu entry.
  12859.    POPUP_MOVE_END          Move highlight to last available menu entry.
  12860.    POPUP_MOVE_LEFT         Move to next popup menu.
  12861.    POPUP_MOVE_RIGHT        Move to previous popup menu.
  12862.    POPUP_PULLDOWN_ESCAPE   Escape pulldown menu
  12863.  
  12864.   Please note the new return values POPUP_MOVE_LEFT, POPUP_MOVE_RIGHT, and
  12865.   POPUP_PULLDOWN_ESCAPE.
  12866.  
  12867.  
  12868.  
  12869.  
  12870.  
  12871.  
  12872.  
  12873.  
  12874.  
  12875.  
  12876.  
  12877.  
  12878.  
  12879.  
  12880.  
  12881.  
  12882.  
  12883.  
  12884.  
  12885.  
  12886.  
  12887.  
  12888.  
  12889.  
  12890.  Page 219                     The C Window Library                    Page 219
  12891.  
  12892.                       PROCESSING UNDEFINED BAR MENU KEYS
  12893.                       ----------------------------------
  12894.  
  12895.   Processing bar menu keys is the same as explained on page 198.  Here are the
  12896.   return values that the function pointed to by bar_undef_key must return.
  12897.  
  12898.     Return                         Action to
  12899.     Value                            Take
  12900.     ------                         ---------
  12901.    BAR_CONTINUE          No Action. Continue processing the bar menu.
  12902.    BAR_DO_CHOICE         Accept and invoke menu entry assigned to *choice, or
  12903.                               display popup menu underneath bar entry.
  12904.    BAR_MOVE_CONTINUE     Move the highlight bar to menu entry assigned to
  12905.                               *choice and continue processing menu.
  12906.    BAR_ESCAPE            Escape the bar menu (or pulldown menu).
  12907.    BAR_MOVE_LEFT         Move to next bar menu.
  12908.    BAR_MOVE_RIGHT        Move to previous bar menu.
  12909.    BAR_MOVE_HOME         Move highlight to first available menu entry.
  12910.    BAR_MOVE_END          Move highlight to last available menu entry.
  12911.  
  12912.  
  12913.   Please note that BAR_DO_CHOICE will either do the function assigned to the
  12914.   bar entry assigned to *choice, or display the popup menu underneath the bar
  12915.   menu entry assigned to *choice.
  12916.  
  12917.  
  12918.  
  12919.  
  12920.  
  12921.  
  12922.  
  12923.  
  12924.  
  12925.  
  12926.  
  12927.  
  12928.  
  12929.  
  12930.  
  12931.  
  12932.  
  12933.  
  12934.  
  12935.  
  12936.  
  12937.  
  12938.  
  12939.  
  12940.  
  12941.  
  12942.  
  12943.  
  12944.  
  12945.  
  12946.  Page 220                     The C Window Library                    Page 220
  12947.  
  12948.                      DISPOSING OF PULLDOWN MENUS
  12949.                      ---------------------------
  12950.  
  12951.   There are two functions that are used to dispose of pulldown menus.  The
  12952.   first is the PulldownMenuFree() function.
  12953.  
  12954.  
  12955.  
  12956.   The PulldownMenuFree() function
  12957.   -------------------------------
  12958.  
  12959.   The PulldownMenuFree() function disposes of the PULLDOWN_MENU_PTR and returns
  12960.   memory allocated back to the heap.  The bar menu and the popup menus
  12961.   associated with the pulldown menu remain intact.
  12962.  
  12963.   Here is a prototype of the call to PulldownMenuFree():
  12964.  
  12965.       int PulldownMenuFree(PULLDOWN_MENU_PTR pull)
  12966.  
  12967.  
  12968.  
  12969.  
  12970.   The PulldownMenuFreeAll() function
  12971.   ----------------------------------
  12972.  
  12973.  
  12974.   To dispose of the pulldown menu, the bar menu, and all of the popup menus,
  12975.   use the PulldownMenuFreeAll() function.  Here is a prototype:
  12976.  
  12977.              int PulldownMenuFreeAll(PULLDOWN_MENU_PTR pull)
  12978.  
  12979.  
  12980.  
  12981.  
  12982.  
  12983.  
  12984.  
  12985.  
  12986.  
  12987.  
  12988.  
  12989.  
  12990.  
  12991.  
  12992.  
  12993.  
  12994.  
  12995.  
  12996.  
  12997.  
  12998.  
  12999.  
  13000.  
  13001.  
  13002.  Page 221                     The C Window Library                    Page 221
  13003.  
  13004.                            SUMMARY OF PULLDOWN MENUS
  13005.                            -------------------------
  13006.  
  13007.   A pulldown menu is:
  13008.  
  13009.     1)  Made up of a bar menu and popup menus.
  13010.  
  13011.  
  13012.     2)  Consists of two levels, namely the bar menu level and the popup menu
  13013.         level.
  13014.  
  13015.  
  13016.     3)  The bar menu level uses the bar menu key definitions, while the popup
  13017.         menu level uses the popup menu key definitions.
  13018.  
  13019.     4)  The popup menus are initialized by using an array of POPUP_MENU_PTR's.
  13020.         The order of where the popup menus are defined in this array
  13021.         corresponds to each of the bar menu options.
  13022.  
  13023.     5)  A bar menu option may or may not have a popup menu defined for it.
  13024.  
  13025.     6)  When initializing a pulldown menu, you can allow the menu manager to
  13026.         position the popup windows under the bar menu, or you can specify your
  13027.         own positions on the screen for the popup menu windows.
  13028.  
  13029.     7)  When the menu manager calls the user written function the
  13030.         PULLDOWN_MENU_PTR, BAR_MENU_PTR, POPUP_MENU_PTR, the number of the bar
  13031.         entry selected, and the number of the popup selection are passed to
  13032.         the user function.  If there is no popup menu, the POPUP_MENU_PTR
  13033.         passed is a null, and the popup selection number is 0.
  13034.  
  13035.     8)  You can open a pulldown menu from the bar level, or from the pull down
  13036.         level by calling PulldownSelectMenu().
  13037.  
  13038.     9)  You can close a pulldown menu in two ways:  by just disposing of the
  13039.         PULLDOWN_MENU_PTR by calling PulldownMenuFree(), or disposing of all
  13040.         menus used to create the pulldown menu by calling PulldownMenuFreeAll().
  13041.  
  13042.  
  13043.  
  13044.  
  13045.  
  13046.  
  13047.  
  13048.  
  13049.  
  13050.  
  13051.  
  13052.  
  13053.  
  13054.  
  13055.  
  13056.  
  13057.  
  13058.  Page 222                     The C Window Library                    Page 222
  13059.  
  13060.                         EXAMPLE OF PULLDOWN MENU SYSTEM
  13061.                         -------------------------------
  13062.  
  13063.   Here is an example of a pulldown menu system.  This program emulates the
  13064.   Turbo C integrated environment.
  13065.  
  13066.  
  13067.   #include "menu.h"
  13068.  
  13069.   #define BLACKONWHITE   CREATE_VIDEO_ATTRIBUTE(white,black)
  13070.  
  13071.  
  13072.   int menu_routine();
  13073.  
  13074.   POPUP_MENU_ENTRY menu_items1[] = {
  13075.                                     " Load      F3",1,'L',F3,menu_routine,
  13076.                                     " Pick  Alt-F3",2, 'P',ALTF3,menu_routine,
  13077.                                     " New"         ,3, 'N',0,menu_routine,
  13078.                                     " Save      F2",4, 'S',F2,menu_routine,
  13079.                                     " Write to    ",5, 'W',0,menu_routine,
  13080.                                     " Directory   ",6, 'D',0,menu_routine,
  13081.                                     " Change Dir"  ,7, 'C',0,menu_routine,
  13082.                                     " OS shell"    ,8, 'O',0,menu_routine,
  13083.                                     " Quit  Alt-X"  ,9,'Q',ALTX,menu_routine,
  13084.                                     CWL_NULL,0};
  13085.  
  13086.  
  13087.  
  13088.   POPUP_MENU_ENTRY menu_items3[] = {
  13089.                         " Run             Ctrl-F9 ",1,'R',CTRLF9,menu_routine,
  13090.                         " Program reset   Ctrl-F2 ",2,'P',CTRLF2,menu_routine,
  13091.                         " Go to Cursor         F4 ",3,'G',F4,menu_routine,
  13092.                         " Trace into           F7 ",4,'T',F7,menu_routine,
  13093.                         " Step over            F8 ",5,'S',F8,menu_routine,
  13094.                         " User screen      Alt-F5 ",6,'U',ALTF5,menu_routine,
  13095.                         CWL_NULL,0};
  13096.  
  13097.  
  13098.   POPUP_MENU_ENTRY menu_items4[] = {
  13099.           " Compile to OBJ                   ",1,'C',0,menu_routine,
  13100.           " Make EXE file                    ",2,'M',0,menu_routine,
  13101.           " Link EXE file                    ",3,'L',0,menu_routine,
  13102.           " Build all                        ",4,'B',0,menu_routine,
  13103.           " Primary C file:                  ",5,'P',0,menu_routine,
  13104.           " Get info                         ",6,'G',0,menu_routine,
  13105.             CWL_NULL,0};
  13106.  
  13107.  
  13108.  
  13109.  
  13110.  
  13111.  
  13112.  
  13113.  
  13114.  Page 223                     The C Window Library                    Page 223
  13115.  
  13116.   POPUP_MENU_ENTRY menu_items5[] = {
  13117.           " Project Name                     ",1,'P',0,menu_routine,
  13118.           " Break make on                    ",2,'B',0,menu_routine,
  13119.           " Auto dependencies                ",3,'A',0,menu_routine,
  13120.           " Clear project                    ",4,'C',0,menu_routine,
  13121.           " Remove messages                  ",5,'R',0,menu_routine,
  13122.             CWL_NULL,0};
  13123.  
  13124.  
  13125.   POPUP_MENU_ENTRY menu_items6[] = {
  13126.           " Compiler          ",1,'C',0,menu_routine,
  13127.           " Linker            ",2,'L',0,menu_routine,
  13128.           " Environment       ",3,'E',0,menu_routine,
  13129.           " Directories       ",4,'D',0,menu_routine,
  13130.           " Arguments         ",5,'A',0,menu_routine,
  13131.           " Save Options      ",6,'S',0,menu_routine,
  13132.           " Retrieve options  ",7,'R',0,menu_routine,
  13133.           CWL_NULL,0};
  13134.  
  13135.  
  13136.   POPUP_MENU_ENTRY menu_items7[] = {
  13137.           " Evaluate    Ctrl-F4           ",1,'E',CTRLF4,menu_routine,
  13138.           " Call Stack  Ctrl-F3           ",2,'C',CTRLF3,menu_routine,
  13139.           " Find Function                 ",3,'F',0,menu_routine,
  13140.           " Refresh display               ",4,'R',0,menu_routine,
  13141.           " Display swapping     Smart    ",5,'D',0,menu_routine,
  13142.           " Source debugging              ",6,'S',0,menu_routine,
  13143.           CWL_NULL,0};
  13144.  
  13145.  
  13146.   POPUP_MENU_ENTRY menu_items8[] = {
  13147.           " Add watch           Ctrl-F7 ",1,'A',CTRLF7,menu_routine,
  13148.           " Delete watch                ",2,'D',0,menu_routine,
  13149.           " Edit Watch                  ",3,'E',0,menu_routine,
  13150.           " Remove all watches          ",4,'R',0,menu_routine,
  13151.           " Toggle breakpoint   Ctrl-F8 ",6,'T',CTRLF8,menu_routine,
  13152.           " Clear all breakpoints       ",7,'C',0,menu_routine,
  13153.           " View next breakpoint        ",8,'V',0,menu_routine,
  13154.           CWL_NULL,0};
  13155.  
  13156.  
  13157.   BAR_MENU_ENTRY bar_items[] = {
  13158.               "File",1,4,'F',0,NULLFN,
  13159.         "Edit",1,10,'E',0,menu_routine,
  13160.               "Run",1,17,'R',0,NULLFN,
  13161.               "Compile",1,23,'C',0,NULLFN,
  13162.               "Project",1,33,'P',0,NULLFN,
  13163.               "Options", 1,43,'O',0,NULLFN,
  13164.               "Debug",1,53,'D',0,NULLFN,
  13165.               "Break/watch",1,61,'B',0,NULLFN,
  13166.                                     CWL_NULL};
  13167.  
  13168.  
  13169.  
  13170.  Page 224                     The C Window Library                    Page 224
  13171.  
  13172.   POPUP_MENU_ENTRY  *pentry[] = {menu_items1, POPUP_NULL_ENTRY,
  13173.                                  menu_items3,
  13174.                                  menu_items4, menu_items5, menu_items6,
  13175.                                  menu_items7, menu_items8};
  13176.  
  13177.   unsigned menu_colors[5];    /* Menu colors */
  13178.   BAR_MENU_PTR bar;           /* Pointer to bar menu */
  13179.   POPUP_MENU_PTR popups[8];   /* Array of pointers to popup menus */
  13180.   PULLDOWN_MENU_PTR pull;     /* Pointer to pulldown menu */
  13181.  
  13182.   WPOINTER my_open();         /* Pointer to custom bar window open function */
  13183.   unsigned int popuprank[] = {1,1,1,1,1,1,1,1};  /* Ranks of popup windows */
  13184.   int popupstart[] = {1,1,1,1,1,1,1,1}; /* Starting option for each popup
  13185.                                            menu */
  13186.   int height[] = {9,0,6,6,5,7,6,8};     /* height of each window */
  13187.  
  13188.   WPOINTER pw;  /* Misc. windows, not part of menu
  13189.                                             system */
  13190.  
  13191.   char *line =
  13192.           "─────────────────────────────"; /* Horizontal line */
  13193.  
  13194.  
  13195.   main()
  13196.   {
  13197.     int i;
  13198.     WindowInitializeSystem();
  13199.     WindowSaveInitial(0);
  13200.     pw = WindowInitialize(BORDER,5,10,70,5,BLACKONWHITE,BLACKONWHITE,
  13201.                           SINGLEBOX);
  13202.     WindowOpen(pw);
  13203.    /* define colors */
  13204.     menu_colors[0] = CREATE_VIDEO_ATTRIBUTE(white,black);
  13205.     menu_colors[1] = CREATE_VIDEO_ATTRIBUTE(white,black);
  13206.     menu_colors[2] = CREATE_VIDEO_ATTRIBUTE(white,blue);
  13207.     menu_colors[3] = CREATE_VIDEO_ATTRIBUTE(cyan,black);
  13208.     menu_colors[4] = CREATE_VIDEO_ATTRIBUTE(white,black);
  13209.  
  13210.     bar = BarCreateMenu(bar_items,  /* Array of BAR_MENU_ENTRY's   */
  13211.                         menu_colors,/* Pointer to menu colors      */
  13212.                         6,          /* Row to open bar menu window */
  13213.                         1,          /* Column to open bar menu window */
  13214.                         my_open);   /* Customized window open function */
  13215.  
  13216.                   /* Now set bar options  */
  13217.  
  13218.     BarSetOptions(bar,BARWRAP | BARSTATIC,1);   /* Wrap highlight bar */
  13219.  
  13220.                  /* Now loop to create all popup menus
  13221.           Be careful and assign NULL to the second popup menu */
  13222.  
  13223.  
  13224.  
  13225.  
  13226.  Page 225                     The C Window Library                    Page 225
  13227.  
  13228.     for (i=0; i<8; i++)       /* Loop for all popup menus */
  13229.     {
  13230.       if (pentry[i] != POPUP_NULL_ENTRY)  /* Skip over NULL popup entry */
  13231.       {
  13232.         popups[i] =
  13233.         PopupCreateMenu(pentry[i],   /* Array of POPUP_MENU_ENTRY's */
  13234.                         menu_colors, /* Array of menu colors,        */
  13235.  
  13236.                           /* The next two arguments will later be ignored */
  13237.                           1,           /* Row to open popup window on */
  13238.                           1,           /* Column to open popup */
  13239.                           height[i], /* height of the popup window   */
  13240.                                            /* No custom window open
  13241.                                               functions */
  13242.                           WNULLFN,
  13243.                           VWNULLFN);
  13244.  
  13245.               /* Now set the popup menu options */
  13246.         PopupSetOptions(popups[i],POPUPWRAP | POPUPSTATIC,1);   /* Wrap the
  13247.                                                                    window */
  13248.       }
  13249.       else
  13250.         popups[i] = (POPUP_MENU_PTR)0;  /* Make this a null POPUP_MENU_PTR */
  13251.     }  /* end for (i=0 ... */
  13252.  
  13253.     VirtualWriteString(POPUP_VIRTUAL_WINDOW(popups[7]),line,5,1);
  13254.     PopupMakeEntryUnavailable(popups[6],2);   /* hide 2nd and 3rd entries in */
  13255.     PopupMakeEntryUnavailable(popups[6],3);   /* popups[6]  */
  13256.     PopupSetOptions(popups[6],POPUPOVERRIDE,1);
  13257.  
  13258.     pull = PulldownCreateMenu(popups,bar,1);
  13259.     PulldownSelectMenu(pull,1,1,popuprank,popupstart,1);
  13260.     PulldownMenuFree(pull);
  13261.   }
  13262.  
  13263.   int menu_routine(PULLDOWN_MENU_PTR p, BAR_MENU_PTR b,
  13264.                    POPUP_MENU_PTR pop,
  13265.                    unsigned int hs, unsigned int vs)
  13266.   {
  13267.     int ch;
  13268.     WindowClear(pw);
  13269.     WindowPrintf(pw,
  13270.              "You have selected bar option %s\npopup option %s\n",
  13271.               BAR_ENTRY_STRING(b,hs),POPUP_ENTRY_STRING(pop,vs));
  13272.     WindowWriteCenterString(pw,"Press Escape to Quit",3);
  13273.     WindowWriteCenterString(pw,"Press any other key to continue...",4);
  13274.     WindowDisplay(pw,1,NOEFFECT);
  13275.     ch = GET_KEY();
  13276.     WindowHide(pw,NOEFFECT);
  13277.     if (ch == ESC)
  13278.       return PULLDOWN_EXIT;
  13279.     return PULLDOWN_CONTINUE;
  13280.   }
  13281.  
  13282.  Page 226                     The C Window Library                    Page 226
  13283.  
  13284.   WPOINTER my_open()          /* Custom window open function for bar menu */
  13285.   {
  13286.     WPOINTER w;
  13287.     w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,BLACKONWHITE,"");
  13288.     WindowOpen(w);
  13289.     return w;
  13290.   }
  13291.  
  13292.  
  13293.  
  13294.  
  13295.  
  13296.  
  13297.  
  13298.  
  13299.  
  13300.  
  13301.  
  13302.  
  13303.  
  13304.  
  13305.  
  13306.  
  13307.  
  13308.  
  13309.  
  13310.  
  13311.  
  13312.  
  13313.  
  13314.  
  13315.  
  13316.  
  13317.  
  13318.  
  13319.  
  13320.  
  13321.  
  13322.  
  13323.  
  13324.  
  13325.  
  13326.  
  13327.  
  13328.  
  13329.  
  13330.  
  13331.  
  13332.  
  13333.  
  13334.  
  13335.  
  13336.  
  13337.  
  13338.  Page 227                     The C Window Library                    Page 227
  13339.  
  13340.                            MISCELLANEOUS FUNCTIONS
  13341.                            -----------------------
  13342.  
  13343.   There are other functions in The C Window Library that you can use without
  13344.   defining windows.
  13345.  
  13346.  
  13347.  
  13348.                        SETTING AND CHECKING VIDEO PAGES
  13349.                        --------------------------------
  13350.  
  13351.   The following functions sets and checks video pages.  Your video setup must
  13352.   support multiple video pages for the examples given in this section to work.
  13353.   Please refer to page 5 for a discussion of video adapters and the number of
  13354.   pages each will support.
  13355.  
  13356.  
  13357.  
  13358.   CheckVideoPage()
  13359.   ----------------
  13360.  
  13361.   This function checks to see if the video page is valid.  Here is the
  13362.   prototype:
  13363.  
  13364.  
  13365.                  int CheckVideoPage(int page)
  13366.  
  13367.   If page is valid, CheckVideoPage() returns NO_ERROR.  If it is not, the return
  13368.   value is INVALID_PAGE.
  13369.  
  13370.  
  13371.   Example:
  13372.  
  13373.  
  13374.   #include "window.h"
  13375.  
  13376.   main()
  13377.   {
  13378.     int i;
  13379.     WindowInitializeSystem();
  13380.     for (i=0;i<8;i++)
  13381.     {
  13382.       if (CheckVideoPage(i) == NO_ERROR)
  13383.         printf("\nValid video page #%d",i);
  13384.       else
  13385.         printf("\nInvalid video page #%d",i);
  13386.     }
  13387.   }
  13388.  
  13389.  
  13390.  
  13391.  
  13392.  
  13393.  
  13394.  
  13395.  Page 228                     The C Window Library                    Page 228
  13396.  
  13397.   SetActiveVideoPage() function
  13398.   -----------------------------
  13399.  
  13400.   The SetActiveVideoPage() function sets the active video page.  Here is a
  13401.   prototype:
  13402.  
  13403.            int SetActiveVideoPage(int page)
  13404.  
  13405.   Any windows initialized with WindowInitialize() will have its output directed
  13406.   to the current active video page on initialization.  This function DOES NOT
  13407.   change the visible display page.
  13408.  
  13409.   Example:
  13410.  
  13411.   #include "window.h"
  13412.   #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  13413.  
  13414.   WPOINTER w1, w2;
  13415.   main()
  13416.   {
  13417.     WindowInitializeSystem();
  13418.  
  13419.     /* Save Base Screen for video pages 0 and 1 */
  13420.     WindowSaveInitial(0);
  13421.     WindowSaveInitial(1);
  13422.  
  13423.     /* Set the active video page */
  13424.     SetActiveVideoPage(0);
  13425.     w1 = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  13426.     SetActiveVideoPage(1);
  13427.     w2 = WindowInitialize(BORDER,1,1,10,10,NORM,NORM,SINGLEBOX);
  13428.   }
  13429.  
  13430.   The above example shows two windows, w1 and w2, being open on different video
  13431.   pages.  Please note the two calls to WindowSaveInitial().  The first saves
  13432.   the base screen on video page 0, and the second call saves the initial screen
  13433.   on page 1.  The first call to SetActiveVideoPage() sets the active video page
  13434.   to page 0.  This is usually the active video page on startup.  Since the
  13435.   active page is 0, w1 is opened with page 0 as its video page.  The second
  13436.   call to SetActiveVideoPage() makes page 1 the active page, therefore w2 is
  13437.   initialized to send its output to video page 1.
  13438.  
  13439.   If there are no errors, SetActiveVideoPage() returns NO_ERROR.
  13440.  
  13441.   If there are errors, SetActiveVideoPage() returns INVALID_PAGE if the video
  13442.   page is invalid.
  13443.  
  13444.  
  13445.  
  13446.  
  13447.  
  13448.  
  13449.  
  13450.  
  13451.  Page 229                     The C Window Library                    Page 229
  13452.  
  13453.   SetVisibleVideoPage() function
  13454.   ------------------------------
  13455.  
  13456.   The SetVisibleVideoPage() function sets the visible video page.  Here is a
  13457.   prototype:
  13458.  
  13459.            int SetVisibleVideoPage(int page)
  13460.  
  13461.   The visible video page is the page displayed on the screen.
  13462.  
  13463.  
  13464.   Example:
  13465.  
  13466.   #include "window.h"
  13467.   #define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
  13468.  
  13469.   WPOINTER w1,w2;
  13470.  
  13471.   main()
  13472.   {
  13473.     WindowInitializeSystem();
  13474.  
  13475.     /* Make sure video page is 0 */
  13476.     SetVisibleVideoPage(0);
  13477.     SetActiveVideoPage(0);
  13478.  
  13479.     /*Save Base screen for video pages 0 and 1 */
  13480.     WindowSaveInitial(0);
  13481.     WindowSaveInitial(1);
  13482.  
  13483.     /* Initialize Windows */
  13484.     w1 = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  13485.     SetActiveVideoPage(1);
  13486.     w2 = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  13487.     WindowOpen(w1);
  13488.     WindowOpen(w2);
  13489.     WindowWriteString(w1,"This is window 1 on page 0",1,1);
  13490.     WindowWriteString(w2,"This is window 2 on page 1",1,1);
  13491.  
  13492.     /* Display video page 0 */
  13493.     WindowDisplay(w1,1,NOEFFECT);
  13494.     GET_KEY();
  13495.  
  13496.     /* Change to video page 1 and display */
  13497.     SetVisibleVideoPage(1);
  13498.     WindowDisplay(w2,1,NOEFFECT);
  13499.     GET_KEY();
  13500.  
  13501.     /* Reset to page 0 */
  13502.     SetVisibleVideoPage(0);
  13503.   }
  13504.  
  13505.  
  13506.  
  13507.  Page 230                     The C Window Library                    Page 230
  13508.  
  13509.   The example above initializes two windows.  w1 is initialized on page 0 and
  13510.   w2 is initialized on page 1.  Also note that there are two calls to
  13511.   WindowSaveInitial(), one for page 0 and another for page 1.  The first window
  13512.   displayed is w1.  Once a key is pressed the visible page is switched to page
  13513.   1 by calling SetVisibleVideoPage().  The last line of the program sets the
  13514.   visible page back to page 0.  You should do this on exit of any program that
  13515.   changes video pages.
  13516.  
  13517.   If there are no errors, SetVisibleVideoPage() returns NO_ERROR.
  13518.  
  13519.   If there are errors, SetVisibleVideoPage() returns INVALID_PAGE if the video
  13520.   page is invalid.
  13521.  
  13522.  
  13523.  
  13524.  
  13525.  
  13526.  
  13527.  
  13528.  
  13529.  
  13530.  
  13531.  
  13532.  
  13533.  
  13534.  
  13535.  
  13536.  
  13537.  
  13538.  
  13539.  
  13540.  
  13541.  
  13542.  
  13543.  
  13544.  
  13545.  
  13546.  
  13547.  
  13548.  
  13549.  
  13550.  
  13551.  
  13552.  
  13553.  
  13554.  
  13555.  
  13556.  
  13557.  
  13558.  
  13559.  
  13560.  
  13561.  
  13562.  
  13563.  Page 231                     The C Window Library                    Page 231
  13564.  
  13565.                        GENERAL STRING WRITING FUNCTIONS
  13566.                        --------------------------------
  13567.  
  13568.   The following functions write strings to the active video page.  These
  13569.   functions are not window functions, therefore you should use these functions
  13570.   when you are not using windows created with The C Window Library unless you
  13571.   are careful in using them.  The advantage of using these functions instead of
  13572.   the normal string writing functions found in most C compiler libraries (i.e.
  13573.   printf(), puts(), etc.) is that the output is written directly to screen
  13574.   memory, which results in fast output.  If the BIOS option is selected, BIOS
  13575.   functions are used to write the strings.  Refer to page 4 for a discussion of
  13576.   direct screen writing and BIOS functions.
  13577.  
  13578.  
  13579.  
  13580.  
  13581.   VideoWriteString()
  13582.   ------------------
  13583.  
  13584.   This function writes a null terminated string to the active video page.  Here
  13585.   is the prototype:
  13586.  
  13587.             void VideoWriteString(char *string, int row, int col)
  13588.  
  13589.   The first argument is the string, and the second and third arguments are the
  13590.   (row,col) position of the active video page to place the string.  There is no
  13591.   check to see if (row,col) is out of bounds.  The attribute that is used is
  13592.   determined by the current video attribute at each character position on the
  13593.   screen.
  13594.  
  13595.  
  13596.   Example:
  13597.  
  13598.  
  13599.   #include "window.h"
  13600.  
  13601.   main()
  13602.   {
  13603.     int i;
  13604.     WindowInitializeSystem();
  13605.     for (i=1;i<=10;i++)
  13606.       VideoWriteString("Hello, World",i,1);
  13607.   }
  13608.  
  13609.  
  13610.   There is no return value for VideoWriteString().
  13611.  
  13612.  
  13613.  
  13614.  
  13615.  
  13616.  
  13617.  
  13618.  
  13619.  Page 232                     The C Window Library                    Page 232
  13620.  
  13621.   VideoWriteStringAttr()
  13622.   ----------------------
  13623.  
  13624.   This function writes a null terminated string to the active video page using
  13625.   a video attribute.  Here is the prototype:
  13626.  
  13627.        void VideoWriteStringAttr(char *string, int row, int col, int attr)
  13628.  
  13629.   The first argument is the string, the second and third arguments are the
  13630.   (row,col) position of the active video page to place the string, and the
  13631.   last argument is the video attribute to use.  There is no check to see if
  13632.   (row,col) is out of bounds.  The last argument is the video attribute to use.
  13633.  
  13634.  
  13635.   Example:
  13636.  
  13637.  
  13638.   #include "window.h"
  13639.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  13640.  
  13641.   main()
  13642.   {
  13643.     int i;
  13644.     WindowInitializeSystem();
  13645.     for (i=1;i<=10;i++)
  13646.       VideoWriteStringAttr("Hello, World",i,1,REVERSE);
  13647.   }
  13648.  
  13649.  
  13650.   There is no return value for VideoWriteStringAttr().
  13651.  
  13652.  
  13653.  
  13654.  
  13655.  
  13656.   VideoWriteAttributes()
  13657.   ----------------------
  13658.  
  13659.   This function writes a string of attributes to the active video page.
  13660.   Here is the prototype:
  13661.  
  13662.      void VideoWriteAttributes(char *buffer, int row, int col, int num)
  13663.  
  13664.   The first argument is the buffer that contains the video attributes.  The
  13665.   second and third arguments are the (row,col) position of the active video
  13666.   page to place the attributes, and the last arguments is the number of
  13667.   attributes to write from the buffer.  There is no check to see if (row,col)
  13668.   is out of bounds, or if num attributes will exceed the right edge of the
  13669.   screen.
  13670.  
  13671.  
  13672.  
  13673.  
  13674.  
  13675.  Page 233                     The C Window Library                    Page 233
  13676.  
  13677.   Example:
  13678.  
  13679.  
  13680.   #include "window.h"
  13681.   #include <string.h>
  13682.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  13683.   char buf[12];
  13684.  
  13685.   main()
  13686.   {
  13687.     WindowInitializeSystem();
  13688.     VideoWriteString("Hello, World",1,1);
  13689.     GET_KEY();
  13690.     memset(buf,REVERSE,sizeof(buf));
  13691.     VideoWriteAttributes(buf,1,1,sizeof(buf));
  13692.   }
  13693.  
  13694.   The example above writes a string using the VideoWriteString() function and
  13695.   then changes the attribute of the string by setting a buffer to the REVERSE
  13696.   attribute and using the VideoWriteAttributes() function with this buffer.
  13697.  
  13698.   There is no return value for VideoWriteAttributes().
  13699.  
  13700.  
  13701.  
  13702.   VideoWriteCenterString()
  13703.   ------------------------
  13704.  
  13705.   The VideoWriteCenterString() function centers a string at a certain row of
  13706.   the active video page.  Here is the prototype:
  13707.  
  13708.              void VideoWriteCenterString(char *string, int row)
  13709.  
  13710.   The first argument is the string and the second argument is the row to write
  13711.   on the active video page to write the string.   There is no check to see if
  13712.   row is out of bounds.
  13713.  
  13714.  
  13715.   Example:
  13716.  
  13717.  
  13718.   #include "window.h"
  13719.  
  13720.   main()
  13721.   {
  13722.     int i;
  13723.     WindowInitializeSystem();
  13724.     for (i=1;i<=10;i++)
  13725.       VideoWriteCenterString("Hello, World",i);
  13726.   }
  13727.  
  13728.  
  13729.   There is no return value for VideoWriteCenterString().
  13730.  
  13731.  Page 234                     The C Window Library                    Page 234
  13732.  
  13733.   VideoWriteCenterStringAttr()
  13734.   ----------------------------
  13735.  
  13736.   The VideoWriteCenterStringAttr() function centers a string at a certain row
  13737.   of the active video page with a specified video attribute.  Here is the
  13738.   prototype:
  13739.  
  13740.           void VideoWriteCenterStringAttr(char *string, int row, int attr)
  13741.  
  13742.   The first argument is the string and the second argument is the row to write
  13743.   on the active video page to write the string.  The third argument is the
  13744.   video attribute to use.   There is no check to see if row is out of bounds.
  13745.  
  13746.  
  13747.   Example:
  13748.  
  13749.  
  13750.   #include "window.h"
  13751.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  13752.  
  13753.   main()
  13754.   {
  13755.     int i;
  13756.     WindowInitializeSystem();
  13757.     for (i=1;i<=10;i++)
  13758.       VideoWriteCenterStringAttr("Hello, World",i,REVERSE);
  13759.   }
  13760.  
  13761.   There is no return value for VideoWriteCenterStringAttr().
  13762.  
  13763.  
  13764.  
  13765.  
  13766.   VideoWriteCharAndAttr()
  13767.   -----------------------
  13768.  
  13769.   The VideoWriteCharAndAttr() function writes a string of character-attribute
  13770.   pairs to the active video page.  Here is the prototype:
  13771.  
  13772.       void VideoWriteCharAndAttr(char *buffer, int row, int col, int num)
  13773.  
  13774.   The first argument is the buffer that holds the character attribute pairs.
  13775.   This buffer should be in the following form:
  13776.  
  13777.        -----------------------------------------------
  13778.        |char1 | attr1 | char2 | attr2 | char3 | attr3| ...
  13779.        -----------------------------------------------
  13780.  
  13781.   The second and third arguments are the (row,col) position of the active video
  13782.   page to write the string.  The last argument is the number of
  13783.   character-attribute pairs to write.
  13784.  
  13785.  
  13786.  
  13787.  Page 235                     The C Window Library                    Page 235
  13788.  
  13789.   Example:
  13790.  
  13791.   #include "window.h"
  13792.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  13793.   char buf[24];
  13794.  
  13795.   main()
  13796.   {
  13797.     int i,j;
  13798.     WindowInitializeSystem();
  13799.     for (i=0,j='A'; i<24; i+=2,j++)
  13800.     {
  13801.       buf[i] = j;
  13802.       buf[i+1] = REVERSE;
  13803.     }
  13804.     for (i=1;i<=10;i++)
  13805.       VideoWriteCharAndAttr(buf,i,1,12);
  13806.   }
  13807.  
  13808.   The example above creates a string of character attribute pairs and then
  13809.   writes this string using the VideoWriteCharAndAttr() function.
  13810.  
  13811.   There is no return value for VideoWriteCharAndAttr().
  13812.  
  13813.  
  13814.   VideoWriteStringCC()
  13815.   --------------------
  13816.  
  13817.   This function writes a string centered around a column on the active video
  13818.   page.  Here is the prototype:
  13819.  
  13820.           void VideoWriteStringCC(char *string, int row, int col)
  13821.  
  13822.   The first argument is the string.  The second argument is the row, and the
  13823.   third argument is the column to center the string around.
  13824.  
  13825.   Example:
  13826.  
  13827.   #include "window.h"
  13828.  
  13829.   main()
  13830.   {
  13831.     int i;
  13832.     WindowInitializeSystem();
  13833.     VideoWriteStringCC("This",1,10);
  13834.     VideoWriteStringCC("is",2,10);
  13835.     VideoWriteStringCC("centered",3,10);
  13836.     VideoWriteStringCC("around",4,10);
  13837.     VideoWriteStringCC("column",5,10);
  13838.     VideoWriteStringCC("10",6,10);
  13839.   }
  13840.  
  13841.   There is no return value for VideoWriteStringCC().
  13842.  
  13843.  Page 236                     The C Window Library                    Page 236
  13844.  
  13845.   VideoWriteStringCCAttr()
  13846.   ------------------------
  13847.  
  13848.   This function writes a string centered around a column on the active video
  13849.   page with a specified video attribute.  Here is the prototype:
  13850.  
  13851.       void VideoWriteStringCCAttr(char *string, int row, int col, int attr)
  13852.  
  13853.   The first argument is the string.  The second argument is the row.  The third
  13854.   argument is the column to center the string around, and the fourth argument
  13855.   is the attribute to use.
  13856.  
  13857.  
  13858.   Example:
  13859.  
  13860.   #include "window.h"
  13861.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(white,black)
  13862.   main()
  13863.   {
  13864.     int i;
  13865.     WindowInitializeSystem();
  13866.     VideoWriteStringCCAttr("This",1,10,REVERSE);
  13867.     VideoWriteStringCCAttr("is",2,10,REVERSE);
  13868.     VideoWriteStringCCAttr("centered",3,10,REVERSE);
  13869.     VideoWriteStringCCAttr("around",4,10,REVERSE);
  13870.     VideoWriteStringCCAttr("column",5,10,REVERSE);
  13871.     VideoWriteStringCCAttr("10",6,10,REVERSE);
  13872.   }
  13873.  
  13874.   There is no return value for VideoWriteStringCCAttr().
  13875.  
  13876.  
  13877.  
  13878.  
  13879.   VideoWriteStringRJ()
  13880.   --------------------
  13881.  
  13882.   The VideoWriteStringRJ() function writes a string to the screen that is right
  13883.   justified at column col.  If the string will not fit within column 1, the
  13884.   string is still right justified, but excess characters to the left of column
  13885.   1 are clipped.  This function writes a string  column on the active video
  13886.   page.  Here is the prototype:
  13887.  
  13888.           void VideoWriteStringRJ(char *string, int row, int col)
  13889.  
  13890.   The first argument is the string.  The second argument is the row, and the
  13891.   third argument is the column to right justify the string on.
  13892.  
  13893.  
  13894.  
  13895.  
  13896.  
  13897.  
  13898.  
  13899.  Page 237                     The C Window Library                    Page 237
  13900.  
  13901.   Example:
  13902.  
  13903.   #include "window.h"
  13904.   main()
  13905.   {
  13906.     int i;
  13907.     WindowInitializeSystem();
  13908.     VideoWriteStringRJ("This",1,10);
  13909.     VideoWriteStringRJ("is",2,10);
  13910.     VideoWriteStringRJ("right",3,10);
  13911.     VideoWriteStringRJ("justified",4,10);
  13912.     VideoWriteStringRJ("on ",5,10);
  13913.     VideoWriteStringRJ("column",6,10);
  13914.     VideoWriteStringRJ("10",7,10);
  13915.   }
  13916.  
  13917.   There is no return value for VideoWriteStringRJ().
  13918.  
  13919.  
  13920.  
  13921.   VideoWriteStringRJAttr()
  13922.   ------------------------
  13923.  
  13924.   The VideoWriteStringRJAttr() function writes a string to the screen that is
  13925.   right justified at column col with a specified video attribute.  If the
  13926.   string will not fit within column 1, the string is still right justified, but
  13927.   excess characters to the left of column 1 are clipped.  This function writes
  13928.   a string  column on the active video page.  Here is the prototype:
  13929.  
  13930.       void VideoWriteStringRJAttr(char *string, int row, int col, int attr)
  13931.  
  13932.   The first argument is the string.  The second argument is the row.  The third
  13933.   argument is the column to right justify the string on, and the last argument
  13934.   is the video attribute to use.
  13935.  
  13936.   Example:
  13937.  
  13938.   #include "window.h"
  13939.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  13940.   main()
  13941.   {
  13942.     int i;
  13943.     WindowInitializeSystem();
  13944.     VideoWriteStringRJAttr("This",1,10,REVERSE);
  13945.     VideoWriteStringRJAttr("is",2,10,REVERSE);
  13946.     VideoWriteStringRJAttr("right",3,10,REVERSE);
  13947.     VideoWriteStringRJAttr("justified",4,10,REVERSE);
  13948.     VideoWriteStringRJAttr("on ",5,10,REVERSE);
  13949.     VideoWriteStringRJAttr("column",6,10,REVERSE);
  13950.     VideoWriteStringRJAttr("10",7,10,REVERSE);
  13951.   }
  13952.  
  13953.   There is no return value for VideoWriteStringRJAttr().
  13954.  
  13955.  Page 238                     The C Window Library                    Page 238
  13956.  
  13957.   VideoPrintf()
  13958.   -------------
  13959.  
  13960.   The VideoPrintf() function writes formatted strings to the active video page.
  13961.   This function works exactly the same as printf() except that output is
  13962.   written directly to the screen.  Here is the prototype:
  13963.  
  13964.                 void VideoPrintf(char *format, [arg1,arg2...])
  13965.  
  13966.   The location of the output is placed at the current cursor position.  The
  13967.   cursor is advanced to one character beyond the last character of output.
  13968.  
  13969.   Example:
  13970.  
  13971.   #include "window.h"
  13972.   int i = 3;
  13973.   double j = 5.6;
  13974.   main()
  13975.   {
  13976.     WindowInitializeSystem();
  13977.     VideoPrintf("3+2 is equal to %d\n",3+2);
  13978.     VideoPrintf("i is equal to %d\nj is equal to %lf\n",i,j);
  13979.   }
  13980.  
  13981.   Unlike printf(), there is no return value with VideoPrintf().
  13982.  
  13983.  
  13984.  
  13985.   VideoPrintfAttr()
  13986.   -----------------
  13987.  
  13988.   The VideoPrintfAttr() function works the same as VideoPrintf() except that a
  13989.   video attribute is specified.  Here is the prototype:
  13990.  
  13991.                 void VideoPrintfAttr(int attr, char *format, [arg1,arg2...])
  13992.  
  13993.   The first argument is the attribute to use.  The second argument is the
  13994.   format string, and the other arguments are optional arguments.
  13995.  
  13996.   Example:
  13997.  
  13998.   #include "window.h"
  13999.   #define REVERSE  CREATE_VIDEO_ATTRIBUTE(white,black)
  14000.   int i = 3;
  14001.   double j = 5.6;
  14002.   main()
  14003.   {
  14004.     WindowInitializeSystem();
  14005.     VideoPrintfAttr(REVERSE,"3+2 is equal to %d\n",3+2);
  14006.     VideoPrintfAttr(REVERSE,"i is equal to %d\nj is equal to %lf\n",i,j);
  14007.   }
  14008.  
  14009.   Unlike printf(), there is no return value with VideoPrintfAttr().
  14010.  
  14011.  Page 239                     The C Window Library                    Page 239
  14012.  
  14013.                READING CHARACTERS AND ATTRIBUTES FROM THE SCREEN
  14014.                -------------------------------------------------
  14015.  
  14016.   These functions read characters and/or attributes from the active video page.
  14017.  
  14018.  
  14019.   VideoReadCharacters()
  14020.   ---------------------
  14021.  
  14022.   This function reads characters from the active video page into a buffer.
  14023.   Here is the prototype:
  14024.  
  14025.  
  14026.     void VideoReadCharacters(char *buffer, int row, int col, int num)
  14027.  
  14028.   The first argument is the buffer to store the characters.  The second and
  14029.   third arguments are the (row,col) position on the active video page.  The
  14030.   last argument is the number of characters to read in.  There is no check to
  14031.   see if the row, col, or the num arguments are in bounds of the screen.
  14032.  
  14033.  
  14034.   Example:
  14035.  
  14036.   #include "window.h"
  14037.  
  14038.   char buf[25];
  14039.  
  14040.   main()
  14041.   {
  14042.     WindowInitializeSystem();
  14043.     VideoReadCharacters(buf,1,1,25);
  14044.   }
  14045.  
  14046.  
  14047.   The example above reads the characters on the screen starting at position
  14048.   (1,1).
  14049.  
  14050.   There is no return value for VideoReadCharacters().
  14051.  
  14052.  
  14053.  
  14054.   VideoReadAttributes()
  14055.   ---------------------
  14056.  
  14057.   This function reads attributes from the active video page into a buffer.
  14058.   Here is the prototype:
  14059.  
  14060.     void VideoReadAttributes(char *buffer, int row, int col, int num)
  14061.  
  14062.   The first argument is the buffer to store the attributes.  The second and
  14063.   third arguments are the (row,col) position on the active video page.  The
  14064.   last argument is the number of attributes to read in.  There is no check to
  14065.   see if the row, col, or the num arguments are in bounds of the screen.
  14066.  
  14067.  Page 240                     The C Window Library                    Page 240
  14068.  
  14069.   Example:
  14070.  
  14071.   #include "window.h"
  14072.  
  14073.   char buf[25];
  14074.  
  14075.   main()
  14076.   {
  14077.     WindowInitializeSystem();
  14078.     VideoReadAttributes(buf,1,1,25);
  14079.   }
  14080.  
  14081.  
  14082.   The example above reads the attributes on the screen starting at position
  14083.   (1,1).
  14084.  
  14085.   There is no return value for VideoReadAttributes().
  14086.  
  14087.  
  14088.  
  14089.  
  14090.   VideoReadCharAndAttr()
  14091.   ----------------------
  14092.  
  14093.   This function reads character-attribute pairs from the active video page
  14094.   into a buffer.  Here is the prototype:
  14095.  
  14096.  
  14097.     void VideoReadCharAndAttr(char *buffer, int row, int col, int num)
  14098.  
  14099.   The first argument is the buffer to store the character-attribute pairs.  The
  14100.   second and third arguments are the (row,col) position on the active video
  14101.   page.  The last argument is the number of character-attribute pairs to read
  14102.   in.  There is no check to see if the row, col, or the num arguments are in
  14103.   bounds of the screen.
  14104.  
  14105.   Example:
  14106.  
  14107.   #include "window.h"
  14108.  
  14109.   char buf[26];
  14110.  
  14111.   main()
  14112.   {
  14113.     WindowInitializeSystem();
  14114.     VideoReadCharAndAttr(buf,1,1,13);
  14115.   }
  14116.  
  14117.   The example above reads the character-attribute pairs on the screen starting
  14118.   at position (1,1).
  14119.  
  14120.   There is no return value for VideoReadCharAndAttr().
  14121.  
  14122.  
  14123.  Page 241                     The C Window Library                    Page 241
  14124.  
  14125.                                  DRAWING BOXES
  14126.                                  -------------
  14127.  
  14128.   The following functions draw boxes on the screen.
  14129.  
  14130.  
  14131.   VideoDrawBox()
  14132.   --------------
  14133.  
  14134.   The VideoDrawBox() function draws a box on the screen.  Here is the
  14135.   prototype:
  14136.  
  14137.      void VideoDrawBox(int urow, int ucol, int lrow, int lcol, char *boxchars)
  14138.  
  14139.   The box is defined by a rectangular region.  The urow and ucol arguments are
  14140.   the coordinates of the upper left hand corner of the box.  The lrow and lcol
  14141.   arguments are the coordinates of the lower right hand corner of the box.  The
  14142.   last argument is a string of box drawing characters to use.  You can use the
  14143.   predefined box types in the header file vidsys.h, or you can make your own.
  14144.   Refer to page 11 for more information on box types.
  14145.  
  14146.   There is no check to see if the coordinates are in bounds.
  14147.  
  14148.   Example:
  14149.  
  14150.   #include "window.h"
  14151.  
  14152.   main()
  14153.   {
  14154.     WindowInitializeSystem();
  14155.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  14156.  
  14157.     /* Draw two boxes */
  14158.     VideoDrawBox(1,1,10,10,SINGLEBOX);
  14159.     VideoDrawBox(1,11,10,21,DOUBLEBOX);
  14160.   }
  14161.  
  14162.   There is no return value for VideoDrawBox().
  14163.  
  14164.  
  14165.  
  14166.   VideoDrawBoxAttr()
  14167.   ------------------
  14168.  
  14169.   The VideoDrawBoxAttr() function draws a box on the screen with a specified
  14170.   video attribute.  Here is the prototype:
  14171.  
  14172.   void VideoDrawBoxAttr(int urow, int ucol, int lrow, int lcol, char *boxchars,
  14173.                         int attr)
  14174.  
  14175.   This function works the same way as the VideoDrawBox() function.  Note that
  14176.   the last argument is the video attribute to use.  There is no check to see if
  14177.   the coordinates are in bounds.
  14178.  
  14179.  Page 242                     The C Window Library                    Page 242
  14180.  
  14181.   Example:
  14182.  
  14183.   #include "window.h"
  14184.   #define REVERSE CREATE_VIDEO_ATTRIBUTE(black,white)
  14185.  
  14186.   main()
  14187.   {
  14188.     WindowInitializeSystem();
  14189.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  14190.  
  14191.     /* Draw two boxes */
  14192.     VideoDrawBoxAttr(1,1,10,10,SINGLEBOX,REVERSE);
  14193.     VideoDrawBoxAttr(1,11,10,21,DOUBLEBOX,REVERSE);
  14194.   }
  14195.  
  14196.  
  14197.   There is no return value for VideoDrawBoxAttr().
  14198.  
  14199.  
  14200.  
  14201.  
  14202.  
  14203.  
  14204.  
  14205.  
  14206.  
  14207.  
  14208.  
  14209.  
  14210.  
  14211.  
  14212.  
  14213.  
  14214.  
  14215.  
  14216.  
  14217.  
  14218.  
  14219.  
  14220.  
  14221.  
  14222.  
  14223.  
  14224.  
  14225.  
  14226.  
  14227.  
  14228.  
  14229.  
  14230.  
  14231.  
  14232.  
  14233.  
  14234.  
  14235.  Page 243                     The C Window Library                    Page 243
  14236.  
  14237.                       SAVING AND RESTORING SCREEN IMAGES
  14238.                       ----------------------------------
  14239.  
  14240.   The following functions save rectangular regions of the screen in a buffer,
  14241.   and restore rectangular portions of the screen.  These routines exist in the
  14242.   C Window Library so that advanced C programmers can have general screen
  14243.   saving/restoring routines handy.  As always, you should be careful in using
  14244.   these functions at the same time you are using windows created with The C
  14245.   Window Library.
  14246.  
  14247.  
  14248.  
  14249.   VideoSave()
  14250.   -----------
  14251.  
  14252.   The VideoSave() function saves a rectangular portion of the screen into a
  14253.   structure called a VBLOCK.  A pointer to this structure is called a
  14254.   VBLOCKPTR.  Here is the prototype:
  14255.  
  14256.  
  14257.      VBLOCKPTR VideoSave(int urow, int ucol, int lrow, int lcol)
  14258.  
  14259.   This function returns a VBLOCKPTR.  The VBLOCKPTR will be used to move or
  14260.   restore this saved region.  The first two arguments are the coordinates of
  14261.   the upper left hand corner of the rectangle to save (urow,ucol).  The last
  14262.   two arguments are the coordinates of the lower right hand corner of the
  14263.   rectangle (lrow,lcol).  There is no check to see if the coordinates are out
  14264.   of bounds.  You can use this function to save the base screen, and then use
  14265.   VideoRestore() to restore the base screen on exit.
  14266.  
  14267.   Example:
  14268.  
  14269.   #include "window.h"
  14270.  
  14271.   VBLOCKPTR v;
  14272.  
  14273.   main()
  14274.   {
  14275.     WindowInitializeSystem();
  14276.     v = VideoSave(1,1,25,80);   /* Save Rectangular region */
  14277.  
  14278.     /* Check if NULL */
  14279.     if (v == (VBLOCKPTR)0)
  14280.       VideoWriteString("Trouble saving video");
  14281.   }
  14282.  
  14283.   If there are no errors, VideoSave() returns a valid VBLOCKPTR.
  14284.  
  14285.   If there are errors VideoSave() returns a null VBLOCKPTR and sets the global
  14286.   integer window_error_code to the following value:
  14287.  
  14288.   NO_HEAP_MEM if there is not enough memory for the save buffer of the
  14289.   VBLOCKPTR.
  14290.  
  14291.  Page 244                     The C Window Library                    Page 244
  14292.  
  14293.   VideoMove()
  14294.   -----------
  14295.  
  14296.   The VideoMove() function moves a region saved by VideoSave() to a different
  14297.   location of the screen.  This location will be the new upper left hand corner
  14298.   of the rectangular region that was saved.  The move is not displayed until
  14299.   you call VideoRestore(), which is defined later.   Here is the prototype:
  14300.  
  14301.                void VideoMove(VBLOCKPTR v, int row, int col)
  14302.  
  14303.   The first argument is the VBLOCKPTR.  The second and third arguments are the
  14304.   new upper left hand position of the saved area.  There is NO check to see if
  14305.   the VBLOCKPTR exists, or the row or column are valid.
  14306.  
  14307.   Example:
  14308.  
  14309.   #include "window.h"
  14310.  
  14311.   VBLOCKPTR v;
  14312.  
  14313.   main()
  14314.   {
  14315.     WindowInitializeSystem();
  14316.     v = VideoSave(1,1,10,10);   /* Save Rectangular region defined by (1,1)
  14317.                                    (10,10) */
  14318.     VideoMove(v,1,10);
  14319.   }
  14320.  
  14321.   There is no return value for VideoMove().
  14322.  
  14323.  
  14324.  
  14325.  
  14326.   VideoRestore()
  14327.   --------------
  14328.  
  14329.   The VideoRestore() function takes a rectangular area of the screen saved with
  14330.   VideoSave() and redisplays the area.  Here is the prototype:
  14331.  
  14332.                      void VideoRestore(VBLOCKPTR v)
  14333.  
  14334.   The only argument is the VBLOCKPTR.  There is no check to see if the
  14335.   VBLOCKPTR is valid.
  14336.  
  14337.  
  14338.  
  14339.  
  14340.  
  14341.  
  14342.  
  14343.  
  14344.  
  14345.  
  14346.  
  14347.  Page 245                     The C Window Library                    Page 245
  14348.  
  14349.   Example:
  14350.  
  14351.  
  14352.   #include "window.h"
  14353.  
  14354.   VBLOCKPTR v;
  14355.  
  14356.   main()
  14357.   {
  14358.     WindowInitializeSystem();
  14359.     v = VideoSave(1,1,10,10);
  14360.     for (i=1;i<=10;i++)
  14361.       VideoWriteString("This is the save area.  Press a key to restore.",i,1);
  14362.     GET_KEY();
  14363.     VideoRestore(v);
  14364.   }
  14365.  
  14366.  
  14367.   There is no return value for VideoRestore().
  14368.  
  14369.  
  14370.  
  14371.  
  14372.   VideoFree()
  14373.   -----------
  14374.  
  14375.   The VideoFree() function frees a previously defined VBLOCKPTR.  Here is the
  14376.   prototype:
  14377.  
  14378.            void VideoFree(VBLOCKPTR v)
  14379.  
  14380.   The only argument is the VBLOCKPTR.  There is NO check to see if the
  14381.   VBLOCKPTR is valid,  therefore you must be very careful to call this function
  14382.   on a valid VBLOCKPTR.  If not, the heap will become corrupted.
  14383.  
  14384.   Example:
  14385.  
  14386.   #include "window.h"
  14387.  
  14388.   VBLOCKPTR v;
  14389.  
  14390.   main()
  14391.   {
  14392.     WindowInitializeSystem();
  14393.     v = VideoSave(1,1,10,10);
  14394.     for (i=1;i<=10;i++)
  14395.       VideoWriteString("This is the save area.  Press a key to restore.",i,1);
  14396.     GET_KEY();
  14397.     VideoRestore(v);
  14398.     VideoFree(v);
  14399.   }
  14400.  
  14401.   There is no return value for VideoFree().
  14402.  
  14403.  Page 246                     The C Window Library                    Page 246
  14404.  
  14405.                                CLEARING SCREENS
  14406.                                ----------------
  14407.  
  14408.   The following functions clears the visible video page, and clears regions of
  14409.   the visible screen.
  14410.  
  14411.  
  14412.  
  14413.   ClearScreen()
  14414.   -------------
  14415.  
  14416.   The ClearScreen() function clears the visible video page with a specified
  14417.   attribute and moves the screen cursor to position (1,1).  Here is the
  14418.   prototype:
  14419.  
  14420.                       void ClearScreen(int attr)
  14421.  
  14422.   The only argument is the video attribute to use.
  14423.  
  14424.   Example:
  14425.  
  14426.  
  14427.   #include "window.h"
  14428.  
  14429.   main()
  14430.   {
  14431.     WindowInitializeSystem();
  14432.  
  14433.     /* Clear the entire screen */
  14434.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  14435.   }
  14436.  
  14437.   There is no return value for ClearScreen().
  14438.  
  14439.  
  14440.  
  14441.  
  14442.  
  14443.   ClearRegion()
  14444.   -------------
  14445.  
  14446.   This function clears a rectangular region of the screen.  Here is the
  14447.   prototype:
  14448.  
  14449.         void ClearRegion(int urow, int ucol, int lrow, int lcol, int attr)
  14450.  
  14451.   The first two arguments represent the coordinate of the upper left hand
  14452.   coordinates of the rectangular region to clear.  The third and fourth
  14453.   arguments represent the coordinate of the lower right hand corner of the
  14454.   rectangular region.  The last argument is the attribute to use.  There is no
  14455.   check to see if the coordinates are in bounds.
  14456.  
  14457.  
  14458.  
  14459.  Page 247                     The C Window Library                    Page 247
  14460.  
  14461.   Example:
  14462.  
  14463.   #include "window.h"
  14464.  
  14465.   main()
  14466.   {
  14467.     WindowInitializeSystem();
  14468.  
  14469.     /* Clear Region defined by (1,1) as the upper right hand corner and (10,10)
  14470.        as the lower right hand corner */
  14471.  
  14472.     ClearRegion(1,1,10,10,CREATE_VIDEO_ATTRIBUTE(black,white));
  14473.   }
  14474.  
  14475.  
  14476.   There is no return value for ClearRegion().
  14477.  
  14478.  
  14479.  
  14480.  
  14481.  
  14482.  
  14483.  
  14484.  
  14485.  
  14486.  
  14487.  
  14488.  
  14489.  
  14490.  
  14491.  
  14492.  
  14493.  
  14494.  
  14495.  
  14496.  
  14497.  
  14498.  
  14499.  
  14500.  
  14501.  
  14502.  
  14503.  
  14504.  
  14505.  
  14506.  
  14507.  
  14508.  
  14509.  
  14510.  
  14511.  
  14512.  
  14513.  
  14514.  
  14515.  Page 248                     The C Window Library                    Page 248
  14516.  
  14517.                                SCROLLING SCREENS
  14518.                                -----------------
  14519.  
  14520.   These functions scroll portions of the screen up or down.
  14521.  
  14522.  
  14523.  
  14524.   ScrollScreenUp()
  14525.   ----------------
  14526.  
  14527.   The ScrollScreenUp() function scrolls a rectangular portion of the screen up
  14528.   a specified number of lines.  Here is the prototype:
  14529.  
  14530.   void ScrollScreenUp(int numlines, int urow, int ucol, int lrow, int lcol,
  14531.                       int attr)
  14532.  
  14533.   The first argument is the number of lines to scroll the region.  The second
  14534.   and third arguments are the (row,col) coordinates of the upper left hand
  14535.   corner of the rectangular region to scroll.  The fourth and fifth arguments
  14536.   are the (row,col) of the lower right hand corner of the rectangular region.
  14537.   The last argument is the attribute to use for blank lines created when the
  14538.   region is scrolled.
  14539.  
  14540.  
  14541.   Example:
  14542.  
  14543.   #include "window.h"
  14544.  
  14545.   main()
  14546.   {
  14547.     WindowInitializeSystem();
  14548.     ScrollScreenUp(1,1,3,5,10,CREATE_VIDEO_ATTRIBUTE(black,white));
  14549.   }
  14550.  
  14551.   There is no return value for ScrollScreenUp().
  14552.  
  14553.  
  14554.  
  14555.   ScrollScreenDown()
  14556.   ------------------
  14557.  
  14558.   The ScrollScreenDown() function scrolls a rectangular portion of the screen
  14559.   down a specified number of lines.  Here is the prototype:
  14560.  
  14561.   void ScrollScreenDown(int numlines, int urow, int ucol, int lrow, int lcol,
  14562.                       int attr)
  14563.  
  14564.   The first argument is the number of lines to scroll the region.  The second
  14565.   and third arguments are the (row,col) coordinates of the upper left hand
  14566.   corner of the rectangular region to scroll.  The fourth and fifth arguments
  14567.   are the (row,col) of the lower right hand corner of the rectangular region.
  14568.   The last argument is the attribute to use for blank lines created when the
  14569.   region is scrolled.
  14570.  
  14571.  Page 249                     The C Window Library                    Page 249
  14572.  
  14573.   Example:
  14574.  
  14575.   #include "window.h"
  14576.  
  14577.   main()
  14578.   {
  14579.     WindowInitializeSystem();
  14580.     ScrollScreenDown(1,1,3,5,10,CREATE_VIDEO_ATTRIBUTE(black,white));
  14581.   }
  14582.  
  14583.   There is no return value for ScrollScreenDown().
  14584.  
  14585.  
  14586.  
  14587.  
  14588.  
  14589.  
  14590.  
  14591.  
  14592.  
  14593.  
  14594.  
  14595.  
  14596.  
  14597.  
  14598.  
  14599.  
  14600.  
  14601.  
  14602.  
  14603.  
  14604.  
  14605.  
  14606.  
  14607.  
  14608.  
  14609.  
  14610.  
  14611.  
  14612.  
  14613.  
  14614.  
  14615.  
  14616.  
  14617.  
  14618.  
  14619.  
  14620.  
  14621.  
  14622.  
  14623.  
  14624.  
  14625.  
  14626.  
  14627.  Page 250                     The C Window Library                    Page 250
  14628.  
  14629.                             CHANGING THE VIDEO MODE
  14630.                             -----------------------
  14631.  
  14632.   With The C Window Library, you can change the video mode at any time.  The
  14633.   video mode determines the width of the screen, and whether the screen is in
  14634.   text or graphics mode.
  14635.  
  14636.  
  14637.   SetVideoMode()
  14638.   --------------
  14639.  
  14640.   The SetVideoMode() function changes the video mode.  Here is a prototype:
  14641.  
  14642.           void SetVideoMode(int modenum)
  14643.  
  14644.   The only argument is the mode number.  Refer to the Video Paging section on
  14645.   page 5 for more information on mode numbers and what they display.
  14646.  
  14647.   When the video mode is changed, the screen is cleared.  This cannot be
  14648.   prevented.  You must redisplay any windows that were on the screen.  If the
  14649.   change of video mode results in a change in screen dimensions, then you must
  14650.   read the following sections on CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE
  14651.   SCREEN.  Even though The C Window Library does not support graphics mode, you
  14652.   can change to graphics mode in The C Window Library,
  14653.  
  14654.   Example:
  14655.  
  14656.   #include "window.h"
  14657.  
  14658.   main()
  14659.   {
  14660.     WindowInitializeSystem();
  14661.     SetVideoMode(3);          /* Change to video mode 3 */
  14662.   }
  14663.  
  14664.   There is no return value for SetVideoMode().
  14665.  
  14666.  
  14667.  
  14668.  
  14669.  
  14670.  
  14671.  
  14672.  
  14673.  
  14674.  
  14675.  
  14676.  
  14677.  
  14678.  
  14679.  
  14680.  
  14681.  
  14682.  
  14683.  Page 251                     The C Window Library                    Page 251
  14684.  
  14685.              CHANGING THE NUMBER OF ROWS AND COLUMNS ON THE SCREEN
  14686.              -----------------------------------------------------
  14687.  
  14688.  
  14689.   Changing rows
  14690.   -------------
  14691.  
  14692.   With The C Window Library, you can change the number of rows on the video
  14693.   screen.  However, there are some things to watch out for when changing the
  14694.   number of rows, especially if you have windows displayed on the screen.  If
  14695.   you are not using any window related functions, you can change the number of
  14696.   displayable rows safely by doing two things:
  14697.  
  14698.   a) Call the SetVideoRows() function to change the number of rows.
  14699.  
  14700.   b) Call AdjustGlobalData() to adjust the global variables used by The C
  14701.      Window Library that keep track of the screen dimensions.
  14702.  
  14703.  
  14704.   If you are going to create or have created windows you must do three things:
  14705.  
  14706.   a)  Make sure that any window defined will have valid coordinates when the
  14707.       number of rows are changed.  There may be cases where a window occupies a
  14708.       row that exists in one screen mode, but the row does not exist in another
  14709.       screen mode.  If there are windows that will have invalid coordinates in
  14710.       another screen configuration, you must resize them, remove them, or
  14711.       whatever it takes to resolve the invalid coordinates.
  14712.  
  14713.   b)  Call the SetVideoRows() function.
  14714.  
  14715.   c)  Call the AdjustScreenInfo() function.  This function adjusts all global
  14716.       variables defined in The C Window Library to reflect the new number of
  14717.       rows.
  14718.  
  14719.   Whether there are or are not windows defined, the visible video page MUST be
  14720.   page 0 before changing the number of screen rows.
  14721.  
  14722.  
  14723.  
  14724.   AdjustScreenInfo()
  14725.   ------------------
  14726.  
  14727.   This function must be called after SetVideoRows() is called if you are
  14728.   going to, or have initialized and/or displayed windows.  Here is the
  14729.   prototype:
  14730.  
  14731.                      int AdjustScreenInfo(int page)
  14732.  
  14733.   The only argument is the video page to adjust to the new screen height.
  14734.   Because of the new dimension of the screen, there has to be a reshuffling of
  14735.   a few global arrays, constants, variables, etc.  The AdjustScreenInfo()
  14736.   function does just this.  If you do not call AdjustScreenInfo(), you may see
  14737.   problems if you try to manipulate windows on the new screen.
  14738.  
  14739.  Page 252                     The C Window Library                    Page 252
  14740.  
  14741.   See SetVideoRows() for an example of AdjustScreenInfo().
  14742.  
  14743.   If there are no errors, AdjustScreenInfo() returns NO_ERROR.
  14744.  
  14745.   If there are errors, AdjustScreenInfo() returns the following value:
  14746.  
  14747.   NO_HEAP_MEM if there is not enough memory to allocate for the global arrays,
  14748.   structures, etc.
  14749.  
  14750.  
  14751.  
  14752.  
  14753.   AdjustGlobalData()
  14754.   ------------------
  14755.  
  14756.   The AdjustGlobalData() function should be called after you have changed the
  14757.   number of video rows using SetVideoRows() (defined below).  This resets the
  14758.   global variables necessary for non-window functions to execute properly.
  14759.   Here is the prototype:
  14760.  
  14761.                   void AdjustGlobalData(void)
  14762.  
  14763.   There are no arguments and no return value for AdjustGlobalData().  If you
  14764.   have called AdjustScreenInfo(), you do not have to call AdjustGlobalData().
  14765.  
  14766.   See below for an example of AdjustGlobalData().
  14767.  
  14768.  
  14769.  
  14770.  
  14771.  
  14772.   SetVideoRows()
  14773.   --------------
  14774.  
  14775.   The SetVideoRows() function changes the number of video rows on the screen.
  14776.   Here is a list of video adapters and there row number capabilities:
  14777.  
  14778.       Video Type                 Number of Rows
  14779.                                     Possible
  14780.       ----------                 --------------
  14781.       CGA, MDA, Hercules              25
  14782.  
  14783.       EGA                            25, 43
  14784.  
  14785.       MCGA                           25, 50
  14786.  
  14787.       VGA                            12, 14, 21, 25, 28, 43, 50
  14788.  
  14789.   The list above are the values SetVideoRows() uses, depending on the adapter
  14790.   that The C Window Library has detected.  If your video card supports a row
  14791.   configuration that is not supported by the SetVideoRows() function,  consult
  14792.   the 'Changing columns' section on page 256 and proceed as if you are changing
  14793.   the number of columns.
  14794.  
  14795.  Page 253                     The C Window Library                    Page 253
  14796.  
  14797.   Here is the prototype for SetVideoRows():
  14798.  
  14799.              int SetVideoRows(int numrows, int modeflag)
  14800.  
  14801.   The first argument is the number of screen rows.  The modeflag tells whether
  14802.   the video mode should be reset.  If modeflag is 0, the video mode is not
  14803.   reset.  Any other value for modeflag will cause a video mode reset.  This
  14804.   reset may or may not be necessary, so experiment with both values for
  14805.   modeflag.
  14806.  
  14807.   Example:
  14808.  
  14809.   #include "window.h"
  14810.  
  14811.   main()
  14812.   {
  14813.     WindowInitializeSystem();
  14814.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  14815.     VideoWriteString("Press a key to change to a new video mode",1,1);
  14816.     GET_KEY();
  14817.     if (VGA_MODE_ON || MCGA_MODE_ON)
  14818.       SetVideoRows(50,0);
  14819.     else
  14820.     if (EGA_MODE_ON)
  14821.       SetVideoRows(43,0);
  14822.     else
  14823.     {
  14824.       VideoWriteString("Hardware does not support changing video rows",2,1);
  14825.       exit(0);
  14826.     }
  14827.  
  14828.     AdjustGlobalData();
  14829.     VideoWriteString("Press a key again to change to 25 lines",2,1);
  14830.     GET_KEY();
  14831.     SetVideoRows(25,0);
  14832.     AdjustGlobalData();
  14833.   }
  14834.  
  14835.  
  14836.   The example above uses the constants VGA_MODE_ON, MCGA_MODE_ON, and
  14837.   EGA_MODE_ON.  These constants are discussed on page 271.
  14838.  
  14839.  
  14840.   Here is another example, but now we have a window on the screen.
  14841.  
  14842.  
  14843.  
  14844.  
  14845.  
  14846.  
  14847.  
  14848.  
  14849.  
  14850.  
  14851.  Page 254                     The C Window Library                    Page 254
  14852.  
  14853.   Example:
  14854.  
  14855.   #include "window.h"
  14856.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  14857.  
  14858.   WPOINTER w;
  14859.  
  14860.   main()
  14861.   {
  14862.     WindowInitializeSystem();
  14863.     WindowSaveInitial(0);
  14864.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  14865.     WindowOpen(w);
  14866.     WindowDisplay(w,1,NOEFFECT);
  14867.     WindowWriteString(w,"Press a key to change rows",1,1);
  14868.     GET_KEY();
  14869.     if (VGA_MODE_ON || MCGA_MODE_ON)
  14870.       SetVideoRows(50,0);
  14871.     else
  14872.     if (EGA_MODE_ON)
  14873.       SetVideoRows(43,0);
  14874.     else
  14875.     {
  14876.       WindowWriteString(w,"Cannot change rows",1,1);
  14877.       exit(0);
  14878.     }
  14879.  
  14880.     /* Adjust the screen information */
  14881.     AdjustScreenInfo(0);
  14882.  
  14883.     /* OK to adjust to new height */
  14884.     WindowResizeHeight(w,40,ANCHORTOP);
  14885.  
  14886.     WindowWriteString(w,"Now press a key to change back",2,1);
  14887.     GET_KEY();
  14888.  
  14889.     /*  First we must resize window */
  14890.     WindowResizeHeight(w,10,ANCHORTOP);
  14891.  
  14892.     SetVideoRows(25,0);
  14893.  
  14894.     AdjustScreenInfo(0);
  14895.  
  14896.   }
  14897.  
  14898.   Note the use of AdjustScreenInfo() after a reset is made.
  14899.  
  14900.   If there are no errors, SetVideoRows() returns no errors.
  14901.  
  14902.   If there are errors SetVideoRows() returns the following value:
  14903.  
  14904.   INVALID_ROWS if the number of rows is not supported for the detected monitor
  14905.   type.
  14906.  
  14907.  Page 255                     The C Window Library                    Page 255
  14908.  
  14909.   Changing columns
  14910.   ----------------
  14911.  
  14912.   The number of columns can be changed, but there are two things to watch out
  14913.   for.  First, to change from 40 column mode to 80 column mode or vice-versa,
  14914.   is a matter of changing the video mode.  Changing the video mode from 40 to
  14915.   80 column mode or from 80 to 40 requires a BIOS function that is present on
  14916.   all systems that support 40 column mode.
  14917.  
  14918.  
  14919.  
  14920.   40 column and 80 column modes
  14921.   -----------------------------
  14922.  
  14923.   To change to 40 column mode do the following:
  14924.  
  14925.   SetVideoMode(0);   /* this changes to 40 column black and white mode */
  14926.  
  14927.        or
  14928.  
  14929.   SetVideoMode(1);   /* this changes to 40 column color mode */
  14930.  
  14931.   The example above only works if you have a CGA, EGA, MCGA, or VGA card.
  14932.  
  14933.  
  14934.  
  14935.   To change to 80 column mode do the following:
  14936.  
  14937.   SetVideoMode(2);  /* this changes to Black and White 80 column mode */
  14938.  
  14939.        or
  14940.  
  14941.   SetVideoMode(3);  /* use this for color 80 column mode */
  14942.  
  14943.        or
  14944.  
  14945.   SetVideoMode(7);  /* use this for mono cards */
  14946.  
  14947.   SetVideoMode(7) works for all adapters, while SetVideoMode(2) and
  14948.   SetVideoMode(3) works only for CGA, EGA, MCGA, or VGA cards.
  14949.  
  14950.  
  14951.   Modes higher than 80 columns
  14952.   ----------------------------
  14953.  
  14954.   There are video systems that support video modes greater than 80 columns.
  14955.   The problem is that for each different brand of video adapter, there is a
  14956.   unique way of changing to a higher column mode.  Most of these adapters
  14957.   support an additional BIOS function that must be called to change to any
  14958.   screen column mode higher than 80.  Therefore, it is up to you (the
  14959.   programmer) to find out how to change the video system from 80 columns to a
  14960.   higher column mode.  Once you are familiar with how to do this, changing the
  14961.   number of columns is almost the same as changing the number of rows.
  14962.  
  14963.  Page 256                     The C Window Library                    Page 256
  14964.  
  14965.   If you are using any window related functions, you can change the number
  14966.   of displayable columns safely by doing three things:
  14967.  
  14968.   a) Call the appropriate routine to change the number of columns.  If this is
  14969.      a call to SetVideoMode(), the screen will be cleared.
  14970.  
  14971.   b) Call AdjustScreenInfo() to adjust the global variables used by The C
  14972.      Window Library that keep track of the screen dimensions.
  14973.  
  14974.   c) Readjust and/or redraw any windows on the screen.  Make sure that all
  14975.      windows fit on the screen, whether they are hidden or not.
  14976.  
  14977.   If you are not using any windows in your application, replace the call to
  14978.   AdjustScreenInfo() in step b) with a call to AdjustGlobalData().
  14979.  
  14980.   This example works for the ATI VGA card.  This changes the mode to 132
  14981.   columns:
  14982.  
  14983.   #include "window.h"
  14984.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  14985.  
  14986.   WPOINTER w;
  14987.  
  14988.   main()
  14989.   {
  14990.     WindowInitializeSystem();
  14991.     WindowSaveInitial(0);
  14992.     w = WindowInitialize(BORDER,1,1,30,10,NORM,NORM,SINGLEBOX);
  14993.     WindowOpen(w);
  14994.     WindowDisplay(w,1,NOEFFECT);
  14995.     WindowWriteString(w,"Press a key to change columns",1,1);
  14996.     GET_KEY();
  14997.  
  14998.     /* Set Video Mode to 132 rows x 25 columns (Works for ATI VGA card) */
  14999.     SetVideoMode(0x23);
  15000.     /* Adjust the screen information and redisplay window */
  15001.     AdjustScreenInfo(0);
  15002.     WindowDisplay(w,1,NOEFFECT);
  15003.  
  15004.     /* OK to adjust to new height */
  15005.     WindowResizeWidth(w,100,ANCHORLEFT);
  15006.  
  15007.     WindowWriteString(w,"Now press a key to change back",2,1);
  15008.     GET_KEY();
  15009.  
  15010.     /*  First we must resize window */
  15011.     WindowResizeWidth(w,30,ANCHORLEFT);
  15012.  
  15013.     /* Set back to 80 column mode */
  15014.     SetVideoMode(3);
  15015.     AdjustScreenInfo(0);
  15016.     WindowDisplay(w,1,NOEFFECT);
  15017.   }
  15018.  
  15019.  Page 257                     The C Window Library                    Page 257
  15020.  
  15021.                               CURSOR MANIPULATION
  15022.                               -------------------
  15023.  
  15024.   The functions defined in this section manipulate the cursor.  The
  15025.   following functions can be called without calling WindowInitializeSystem().
  15026.  
  15027.  
  15028.  
  15029.  
  15030.   MoveCursor()
  15031.   ------------
  15032.   This function moves the cursor to a different location.  Here is the
  15033.   prototype:
  15034.  
  15035.              void MoveCursor(int row, int col, int page)
  15036.  
  15037.   The first two arguments are the row and column positions of where to move the
  15038.   cursor.  The last argument is the video page of the cursor you want to move.
  15039.  
  15040.  
  15041.   Example:
  15042.  
  15043.   #include "window.h"
  15044.  
  15045.   main()
  15046.   {
  15047.     MoveCursor(1,5,0);    /* Move cursor to row 1 column 5 on video page 0 */
  15048.   }
  15049.  
  15050.   There is no return value for MoveCursor().
  15051.  
  15052.  
  15053.  
  15054.  
  15055.  
  15056.   ChangeCursor()
  15057.   --------------
  15058.  
  15059.   The ChangeCursor() function changes the shape of the cursor.  The shape of
  15060.   the cursor is determined by its starting and ending scan lines.  Here is a
  15061.   prototype:
  15062.  
  15063.              void ChangeCursor(unsigned startline, unsigned endline)
  15064.  
  15065.   The first argument is the starting scan line and the second argument is the
  15066.   ending scan line.  For monochrome systems, there are 12 scan lines numbered 0
  15067.   thru 11, while on color systems there are 8 scan lines numbered 0 thru 7.
  15068.   The starting scan line is the top line of the cursor, and the ending scan
  15069.   line is the last line of the cursor.  There is no check to see if the
  15070.   starting scan line and the ending scan lines are valid.
  15071.  
  15072.  
  15073.  
  15074.  
  15075.  Page 258                     The C Window Library                    Page 258
  15076.  
  15077.   Example:
  15078.  
  15079.   #include "window.h"
  15080.  
  15081.   main()
  15082.   {
  15083.     WindowInitializeSystem();
  15084.     ChangeCursor(6,7);  /* This is an underline cursor */
  15085.     GET_KEY();
  15086.     ChangeCursor(0,7);  /* This is a thick cursor */
  15087.   }
  15088.  
  15089.   There is no return for ChangeCursor().
  15090.  
  15091.  
  15092.  
  15093.  
  15094.   GetCursorShape()
  15095.   ----------------
  15096.  
  15097.   This function returns the shape of the cursor in scan lines.  Here is the
  15098.   prototype:
  15099.  
  15100.           void GetCursorShape(unsigned *startline, unsigned *endline)
  15101.  
  15102.   When this function returns, the staring scan line is placed in the integer
  15103.   pointed to by scanline, and the ending scan line is placed in the integer
  15104.   pointed to by endline.
  15105.  
  15106.   Example:
  15107.  
  15108.   #include "window.h"
  15109.  
  15110.   main()
  15111.   {
  15112.     int start, end;
  15113.     WindowInitializeSystem();
  15114.     GetCursorShape(&start, &end);
  15115.     VideoPrintf("\nThe starting scan line is %d\nThe ending scan line is %d",
  15116.                  start,end);
  15117.   }
  15118.  
  15119.   There is no return value for GetCursorShape().
  15120.  
  15121.  
  15122.  
  15123.   GetCursorPosition()
  15124.   -------------------
  15125.  
  15126.   This function gets the current cursor position.  Here is the prototype:
  15127.  
  15128.          void GetCursorPosition(int *row, int *col, int page)
  15129.  
  15130.  
  15131.  Page 259                     The C Window Library                    Page 259
  15132.  
  15133.   The first argument is a pointer to an integer that will be set to the current
  15134.   row.  The second argument is a pointer to an integer that will be set to the
  15135.   current column.  The last argument is the video page of the cursor.
  15136.  
  15137.   Example:
  15138.  
  15139.  
  15140.   #include "window.h"
  15141.  
  15142.   main()
  15143.   {
  15144.     int row,col;
  15145.     MoveCursor(10,15);
  15146.     GetCursorPosition(&row,&col,0);
  15147.     WindowInitializeSystem();
  15148.     VideoPrintf("\nThe row of the cursor is %d\nThe column is %d",
  15149.                  row,col);
  15150.   }
  15151.  
  15152.  
  15153.   There is no return value for GetCursorPosition().
  15154.  
  15155.  
  15156.  
  15157.  
  15158.  
  15159.   The following functions serve as shortcuts in changing the cursor shape.
  15160.  
  15161.  
  15162.   HideCursor()
  15163.   ------------
  15164.  
  15165.   Hides the cursor on the screen.  Here is the prototype:
  15166.  
  15167.                        void HideCursor(void)
  15168.  
  15169.  
  15170.   BlockCursor()
  15171.   -------------
  15172.  
  15173.   Displays the cursor as a thick block.
  15174.  
  15175.                        void BlockCursor(void)
  15176.  
  15177.   ThinCursor()
  15178.   ------------
  15179.  
  15180.   Displays the cursor as an underline cursor.
  15181.  
  15182.                        void ThinCursor(void)
  15183.  
  15184.  
  15185.  
  15186.  
  15187.  Page 260                     The C Window Library                    Page 260
  15188.  
  15189.   Example:
  15190.  
  15191.  
  15192.   #include "window.h"
  15193.  
  15194.   main()
  15195.   {
  15196.     WindowInitializeSystem();
  15197.     MoveCursor(1,1,0);
  15198.     VideoWriterString("Press a key to hide the cursor",1,1);
  15199.     GET_KEY();
  15200.     HideCursor();
  15201.     VideoWriterString("Press a key to change cursor to a block",2,1);
  15202.     GET_KEY();
  15203.     BlockCursor();
  15204.     VideoWriterString("Press a key to change cursor to a thin cursor",3,1);
  15205.     GET_KEY();
  15206.     ThinCursor();
  15207.   }
  15208.  
  15209.  
  15210.   There are no return values for HideCursor(), BlockCursor(), or ThinCursor().
  15211.  
  15212.  
  15213.  
  15214.  
  15215.  
  15216.  
  15217.  
  15218.  
  15219.  
  15220.  
  15221.  
  15222.  
  15223.  
  15224.  
  15225.  
  15226.  
  15227.  
  15228.  
  15229.  
  15230.  
  15231.  
  15232.  
  15233.  
  15234.  
  15235.  
  15236.  
  15237.  
  15238.  
  15239.  
  15240.  
  15241.  
  15242.  
  15243.  Page 261                     The C Window Library                    Page 261
  15244.  
  15245.                            GETTING VIDEO INFORMATION
  15246.                            -------------------------
  15247.  
  15248.   You can get information about the video configuration by calling the
  15249.   GetVideoBiosInfo() function.
  15250.  
  15251.  
  15252.   VIDEO_CONFIG structure
  15253.   ----------------------
  15254.  
  15255.   To get information about the video configuration, you must pass a pointer
  15256.   to a VIDEO_CONFIG structure.  This structure is defined as follows:
  15257.  
  15258.  
  15259.       typedef struct
  15260.       {
  15261.         unsigned int video_mode;          /* Current video mode */
  15262.         unsigned int cursor_startline;    /* Starting scan line of cursor */
  15263.         unsigned int cursor_endline;      /* Ending scan line of cursor */
  15264.         unsigned int cursor_row;          /* Screen row of cursor */
  15265.         unsigned int cursor_col;          /* Column of cursor */
  15266.         unsigned int video_page;          /* Current visible video page */
  15267.         unsigned int video_pagesize;      /* Size in bytes of the video page */
  15268.         unsigned int video_rows;          /* Number of displayable rows */
  15269.         unsigned int video_cols;          /* Number of displayable columns */
  15270.         unsigned int char_height;         /* Height (in scan lines) of a
  15271.                                              character  */
  15272.         unsigned int crt_port_address;    /* Address of CRT status port */
  15273.         unsigned int crt_mode_setting;    /* Current CRT Mode Setting   */
  15274.         unsigned int crt_color_setting;   /* Current CRT color settings */
  15275.       } VIDEO_CONFIG;
  15276.  
  15277.  
  15278.  
  15279.   GetVideoBiosInfo()
  15280.   ------------------
  15281.  
  15282.   This function returns information about the current video configuration.
  15283.   Here is the prototype:
  15284.  
  15285.              void GetVideoBiosInfo(VIDEO_CONFIG *v)
  15286.  
  15287.   The only argument is a pointer to a VIDEO_CONFIG structure.  This structure
  15288.   is filled in with the appropriate values.
  15289.  
  15290.  
  15291.  
  15292.  
  15293.  
  15294.  
  15295.  
  15296.  
  15297.  
  15298.  
  15299.  Page 262                     The C Window Library                    Page 262
  15300.  
  15301.   Example:
  15302.  
  15303.   #include "window.h"
  15304.  
  15305.   VIDEO_CONFIG v;
  15306.  
  15307.   main()
  15308.   {
  15309.     WindowInitializeSystem();
  15310.  
  15311.     /* Get video information */
  15312.     ClearScreen(CREATE_VIDEO_ATTRIBUTE(black,white));
  15313.     GetVideoBiosInfo(&v);
  15314.     VideoPrintf("The video mode is %d\n"
  15315.                 "The starting scan line of the cursor is %d\n"
  15316.                 "The ending scan line of the cursor is %d \n"
  15317.                 "The row of the cursor is %d \n"
  15318.                 "The column of the cursor is %d\n"
  15319.                 "The video page is %d\n"
  15320.                 "The size of the video page is %d\n"
  15321.                 "The number of rows is %d\n"
  15322.                 "The number of columns is %d\n"
  15323.                 "The height of the characters is %d\n",
  15324.                 v.video_mode, v.cursor_startline, v.cursor_endline,
  15325.                 v.cursor_row,v.cursor_col,
  15326.                 v.video_page, v.video_pagesize, v.video_rows, v.video_cols,
  15327.                 v.char_height);
  15328.   }
  15329.  
  15330.  
  15331.   There is no return value for GetVideoBiosInfo().
  15332.  
  15333.  
  15334.  
  15335.  
  15336.  
  15337.  
  15338.  
  15339.  
  15340.  
  15341.  
  15342.  
  15343.  
  15344.  
  15345.  
  15346.  
  15347.  
  15348.  
  15349.  
  15350.  
  15351.  
  15352.  
  15353.  
  15354.  
  15355.  Page 263                     The C Window Library                    Page 263
  15356.  
  15357.                                  TIMED DELAYS
  15358.                                  ------------
  15359.  
  15360.   One of the problems that has been addressed in The C Window Library is the
  15361.   lack of a delay() function in most C compiler packages.  The delay() function
  15362.   delays program execution for a certain number of milliseconds.  Borland's
  15363.   Turbo C compiler is one of the few that has a delay() function.  The other
  15364.   compilers may have a sleep() function, but usually these functions do not
  15365.   have millisecond accuracy.
  15366.  
  15367.   One of the problems was to write a delay() function that would work for all
  15368.   the major C compilers, work with millisecond accuracy, work for any speed
  15369.   PC, and last but not least, without using floating point arithmetic.  This
  15370.   function was written in assembly language for accuracy.  The use of the
  15371.   delay() is used extensively in displaying and hiding windows with certain
  15372.   special effects.
  15373.  
  15374.  
  15375.   delay()
  15376.   -------
  15377.  
  15378.   The delay() function delays the program for a certain number of milliseconds.
  15379.   Here is the prototype:
  15380.  
  15381.                 void delay(unsigned millisecs)
  15382.  
  15383.   The only argument is the number of milliseconds to delay.  If you are using
  15384.   the Turbo C version of The C Window Library, this function is already
  15385.   included in the Turbo C library.  However, if you are using another compiler
  15386.   you now have a delay() function!
  15387.  
  15388.  
  15389.   Example:
  15390.  
  15391.   main()
  15392.   {
  15393.     WindowInitializeSystem();
  15394.     delay(50);   /* Delay for 50 milliseconds */
  15395.   }
  15396.  
  15397.   You must call WindowInitializeSystem() before using delay().
  15398.  
  15399.   There is no return value for delay().
  15400.  
  15401.  
  15402.  
  15403.  
  15404.  
  15405.  
  15406.  
  15407.  
  15408.  
  15409.  
  15410.  
  15411.  Page 264                     The C Window Library                    Page 264
  15412.  
  15413.                                 SOUND FUNCTIONS
  15414.                                 ---------------
  15415.  
  15416.   The C Window Library also supports sound functions for compilers that are
  15417.   lacking these functions.
  15418.  
  15419.  
  15420.   sound() and nosound()
  15421.   ---------------------
  15422.  
  15423.   The sound() function sounds a tone with a specified frequency in Hertz
  15424.   (cycles per second).  Here is a prototype:
  15425.  
  15426.                        void sound(unsigned frequency)
  15427.  
  15428.   The nosound() function turns off the tone generated by the sound() function.
  15429.  
  15430.  
  15431.     Example:
  15432.  
  15433.     #include "window.h"
  15434.  
  15435.     main()
  15436.     {
  15437.       unsigned i;
  15438.       WindowInitializeSystem();
  15439.       for (i=100;i<=1000;i++)
  15440.         sound(i);
  15441.       for(i=1000;i>=100;i--)
  15442.         sound(i);
  15443.       nosound();
  15444.     }
  15445.  
  15446.   Note for Turbo users:
  15447.  
  15448.   You should include "dos.h" in your files that contain sound() and nosound().
  15449.   All other compilers should include "window.h".
  15450.  
  15451.   Note for Power C users:
  15452.   If you are using the Power C compiler, you must include "window.h" or any
  15453.   file that includes window.h after bios.h.  This is to ensure that the linker
  15454.   does not get confused with the Power C function  called sound(), which works
  15455.   differently than the sound() function defined above.
  15456.  
  15457.  
  15458.  
  15459.   MakeSound()
  15460.   -----------
  15461.  
  15462.   The MakeSound() function sounds a tone for a duration of time.  Here is the
  15463.   prototype:
  15464.  
  15465.            void MakeSound(unsigned freq, unsigned millisec)
  15466.  
  15467.  Page 265                     The C Window Library                    Page 265
  15468.  
  15469.   where freq, is the frequency of the tone (in Hertz) and millisec is the
  15470.   number of milliseconds to sound the tone.
  15471.  
  15472.  
  15473.   Example:
  15474.   --------
  15475.  
  15476.   #include "window.h"
  15477.  
  15478.   main()
  15479.   {
  15480.     WindowInitializeSystem();
  15481.     /* Produce a 440 Hertz tone for 3 seconds */
  15482.     MakeSound(440,3000);
  15483.   }
  15484.  
  15485.   There is no error return for this function.
  15486.  
  15487.  
  15488.  
  15489.  
  15490.  
  15491.  
  15492.  
  15493.  
  15494.  
  15495.  
  15496.  
  15497.  
  15498.  
  15499.  
  15500.  
  15501.  
  15502.  
  15503.  
  15504.  
  15505.  
  15506.  
  15507.  
  15508.  
  15509.  
  15510.  
  15511.  
  15512.  
  15513.  
  15514.  
  15515.  
  15516.  
  15517.  
  15518.  
  15519.  
  15520.  
  15521.  
  15522.  
  15523.  Page 266                     The C Window Library                    Page 266
  15524.  
  15525.                                 ERROR HANDLING
  15526.                                 --------------
  15527.  
  15528.   Whenever an error has occurred in The C Window Library, a user defined error
  15529.   function can be called.
  15530.  
  15531.  
  15532.   The window_error_func function pointer
  15533.   --------------------------------------
  15534.  
  15535.   The window_error_func function pointer can point to an error function that
  15536.   is performed whenever there is an error encountered in one of The C Window
  15537.   Library functions.  If the global variable check_existence_flag is set to 1
  15538.   and there is an error, The C Window Library will automatically call
  15539.   window_error_func.  Here is the prototype:
  15540.  
  15541.        void (*window_error_func)(int errcode, char *sourcefile, int sourceline,
  15542.                                  char *funcname)
  15543.  
  15544.   The errcode is one of the defined error codes included in The C Window
  15545.   Library.  Refer to page 6 of the main documentation for more information of
  15546.   the error codes and their definitions.  The second argument is the name of
  15547.   the file where the error occurred.  Only users with the source code to The
  15548.   C Window Library will have access to this file.  The third argument is the
  15549.   offending line in the source file of where the error occurred.  The last
  15550.   argument is the name of the function of where the error occurred.
  15551.  
  15552.   By default window_error_func points to a void null function (VOIDNULLFN),
  15553.   therefore no error function is called.
  15554.  
  15555.       Here is an example of how to implement automatic error checking:
  15556.  
  15557.   #include "window.h"
  15558.   #define WHITEONRED CREATE_VIDEO_ATTRIBUTE(red,white)
  15559.   void custom_error_func(int, char *, int, char *);
  15560.  
  15561.   WPOINTER w, error_window;
  15562.   void initialize_error();
  15563.   main()
  15564.   {
  15565.     WindowInitializeSystem();
  15566.     WindowSaveInitial(0);
  15567.     window_error_func = custom_error_func;  /* Assign error function */
  15568.     initialize_error();
  15569.     WindowOpen(w);               /* will be flagged for an error */
  15570.   }
  15571.  
  15572.   void initialize_error()    /* Initialize error window and error handler */
  15573.   {
  15574.     error_window =
  15575.           WindowInitialize(BORDER,1,1,60,5,WHITEONRED,WHITEONRED,SINGLEBOX);
  15576.     WindowOpen(error_window);
  15577.   }
  15578.  
  15579.  Page 267                     The C Window Library                    Page 267
  15580.  
  15581.   void custom_error_func(int errcode, char *sourcefile, int sourceline,
  15582.                          char *funcname)
  15583.   {
  15584.     int ch;
  15585.     MakeSound(100,500);           /* Produce an error beep */
  15586.     if (errcode == NO_HEAP_MEM)   /* Always check for the heap memory error
  15587.                                      separately */
  15588.     {
  15589.       VideoWriteString("You have ran out of Heap Memory",1,1);
  15590.       VideoWriteString(
  15591.         "Press 'Q' to quit program, Any other key to Continue...",2,1);
  15592.     }
  15593.  
  15594.     else                         /* Display error window */
  15595.     {
  15596.       WindowClear(error_window);
  15597.       WindowDisplay(error_window,1,EXPLODE);
  15598.       WindowPrintf(error_window,
  15599.        "Error Code: %d\nSource File: %s\nSource Line %d\nError Occurred in %s",
  15600.        errcode,sourcefile,sourceline,funcname);
  15601.       WindowWriteString(error_window,
  15602.         "Press 'Q' to quit program, Any other key to Continue...",5,1);
  15603.     }
  15604.  
  15605.     ch = GET_KEY();
  15606.     if (ch == 'Q' || ch == 'q')
  15607.       exit(0);
  15608.     else
  15609.     if (errcode != NO_HEAP_MEM)
  15610.       WindowHide(error_window,CONTRACT);
  15611.   }
  15612.  
  15613.  
  15614.   The above example initializes an error window and sets the window_error_func
  15615.   function pointer to point to the function custom_error_func().  Whenever an
  15616.   error occurs in The C Window Library, custom_error_func() will be called.
  15617.  
  15618.   Please note the check to see if the NO_HEAP_MEM error has occurred.  It is
  15619.   important that you check for this error condition separately.  The reason for
  15620.   this is that if there is not enough heap memory, you may inadvertently call a
  15621.   function in your error handler that calls on malloc() or any of the other
  15622.   memory allocation related functions.  This will either freeze your system,
  15623.   or more peculiarly, cause your error handler to be called in an infinite
  15624.   loop because of the repeated failing calls to malloc() or its related
  15625.   functions.  In the latter case, you will run out of stack space.
  15626.  
  15627.   If you want to unassign the window_error_code function pointer, use the
  15628.   following line in your code:
  15629.  
  15630.                     window_error_func = VOIDNULLFN;
  15631.  
  15632.  
  15633.  
  15634.  
  15635.  Page 268                     The C Window Library                    Page 268
  15636.  
  15637.                        WINDOW AND VIRTUAL WINDOW MACROS
  15638.                        --------------------------------
  15639.  
  15640.   Note : These macros should be used after making a call to
  15641.   WindowInitializeSystem() or else unpredictable values will be returned.
  15642.  
  15643.  
  15644.   The following macros are defined in the window.h file.
  15645.   The window w is NOT CHECKED for validity.
  15646.  
  15647.  
  15648.   ISBORDER(w)    -  Returns 1 if window has a border, 0 otherwise.
  15649.  
  15650.   ISWRAP(w)      -  Returns 1 if window wrap is on, 0 otherwise.
  15651.  
  15652.   ISOPEN(w)      -  Returns 1 if window has been opened for read/write, 0
  15653.                     otherwise.
  15654.  
  15655.   ISVISIBLE(w)   -  Returns 1 if window is visible, 0 otherwise.
  15656.  
  15657.   ISVIEWPORT(w)  -  Returns 1 if window is a viewport, 0 otherwise.
  15658.  
  15659.   ISWINDOW(vw)   -  Returns 1 if virtual window has any viewports, 0 otherwise.
  15660.  
  15661.   ISBUFSAVE(w)   -  Returns 1 if text buffer for window was successfully,
  15662.                     allocated, 0 otherwise.
  15663.  
  15664.   ISSEETHRU(w)   -  Returns 1 if window is in see-thru mode, 0 otherwise.
  15665.  
  15666.   ISFROZEN(w)    -  Returns 1 if window is frozen from doing screen updates when
  15667.                     the virtual window has changed, 0 otherwise.
  15668.  
  15669.   ISSHADOW(w)    -  Returns 1 if the window has a shadow, 0 otherwise.
  15670.  
  15671.   ISSHADOWTRANS(w) - Returns 1 if the shadow is transparent, 0 otherwise.
  15672.  
  15673.   SHADOW_POS(w) -   Returns the position of the shadow as an integer.  The valid
  15674.                     positions are as follows:
  15675.  
  15676.                      Shadow Position                Return Value
  15677.                      ---------------                ------------
  15678.                        SHADOWUPLEFT                       1
  15679.                        SHADOWUPRIGHT                      2
  15680.                        SHADOWLOWLEFT                      3
  15681.                        SHADOWLOWRIGHT                     4
  15682.  
  15683.                      If there is no shadow, a 0 is returned.
  15684.  
  15685.   SHADOW_CHAR(w) -  Returns the current character used to draw the window's
  15686.                     shadow.  Return value is undefined if the window has no
  15687.                     shadow.
  15688.  
  15689.  
  15690.  
  15691.  Page 269                     The C Window Library                    Page 269
  15692.  
  15693.   SHADOW_ATTR(w) -  Returns the current video attribute used to draw the
  15694.                     window's shadow.  Return value is undefined if the window
  15695.                     has no shadow
  15696.  
  15697.   SHADOW_WIDTH(w) - Returns the width of the window's shadow.  Return value is
  15698.                     undefined if the window has no shadow.
  15699.  
  15700.   SHADOW_HEIGHT(w) - Returns the height of the window's shadow.  Return value is
  15701.                      undefined if the window has no shadow.
  15702.  
  15703.   VIRTUAL_WINDOW_EXIST(vw) - Returns 1 if virtual window was initialized, 0
  15704.                              otherwise.
  15705.  
  15706.   VIRTUAL_WINDOW(w) - Returns the virtual window that the viewport w is currently
  15707.                       viewing.
  15708.  
  15709.   VIEWPORT_ROW(w) - Returns the upper left row of where the viewport w is
  15710.                     positioned on the virtual window.
  15711.  
  15712.   VIEWPORT_COLUMN(w) - Returns the upper left column of where the viewport w is
  15713.                        positioned on the virtual window.
  15714.  
  15715.   VIRTUAL_COORD_IN_VIEWPORT(w,row,col) - Returns 1 if the virtual window
  15716.                                          coordinates (row,col) are inside the
  15717.                                          viewport w, 0 otherwise.  The virtual
  15718.                                          window must have w as a viewport.
  15719.  
  15720.  
  15721.   WINDOW_BORDER_COLOR(w) - Returns the border color of the window w.
  15722.  
  15723.  
  15724.   WINDOW_COLUMN(w) - Returns the absolute column of the upper left hand corner
  15725.                      of the window.
  15726.  
  15727.   WINDOW_EXIST(w)  - Returns 1 if window was initialized, 0 otherwise.
  15728.  
  15729.   WINDOW_HEIGHT(w) - Returns the height of the text area of the window w.
  15730.  
  15731.  
  15732.   WINDOW_PAGENUM(w) - Returns the video page of where the window will be
  15733.                       displayed.
  15734.  
  15735.   WINDOW_RANK(w) - Returns the rank of the window w.
  15736.  
  15737.  
  15738.   WINDOW_ROW(w) - Returns the absolute row coordinate of the upper left hand
  15739.                   corner of the window w.
  15740.  
  15741.  
  15742.   WINDOW_TEXT_COLOR(w) - Returns the text color of the window w.
  15743.  
  15744.  
  15745.   WINDOW_WIDTH(w) - Returns the width of the text area of the window w.
  15746.  
  15747.  Page 270                     The C Window Library                    Page 270
  15748.  
  15749.                                   MENU MACROS
  15750.                                   -----------
  15751.  
  15752.   The following macros are defined in the header file menu.h.
  15753.  
  15754.  
  15755.   Popup Menu Macros
  15756.   -----------------
  15757.  
  15758.   POPUP_CONFIRM_ON(p) - Returns 1 if the POPUP_MENU_PTR p has the confirmation
  15759.                         for hotkey selections on, 0 otherwise.
  15760.  
  15761.   POPUP_DISPLAY_ON(p) - Returns 1 if the POPUP_MENU_PTR p's window is to be
  15762.                         displayed regardless if the menu manager has returned
  15763.                         to the calling function, 0 otherwise.
  15764.  
  15765.   POPUP_ENHANCED_ON(p) - Returns 1 if the popup menu will recognize enhanced
  15766.                          keys, 0 otherwise.
  15767.  
  15768.   POPUP_ENTRY_STRING(p,entry) - Returns the entry string of POPUP_MENU_ENTRY
  15769.                                 entry.
  15770.  
  15771.   POPUP_EXPLODE(p) -    Returns the special effect constant of the
  15772.                         POPUP_MENU_PTR p.  This special effect is used to hide,
  15773.                         close, and open the popup menu's window.
  15774.  
  15775.   POPUP_NUMBER_OF_ENTRIES(p) - Returns the total number of entries defined in
  15776.                                the POPUP_MENU_PTR p.
  15777.  
  15778.   POPUP_OVERRIDE_ON(p) - Returns 1 if POPUP_MENU_PTR p will have unavailable
  15779.                          options processed, 0 otherwise.
  15780.  
  15781.   POPUP_PULLDOWN_ON(p) - Returns 1 if the POPUP_MENU_PTR p is incorporated in a
  15782.                          pulldown menu system, 0 otherwise.
  15783.  
  15784.   POPUP_STATIC_ON(p) -  Returns 1 if the POPUP_MENU_PTR p will remain on the
  15785.                         screen when an entry is selected, 0 otherwise.
  15786.  
  15787.   POPUP_STRING_IN_WINDOW(p,entry) - Returns 1 if the POPUP_MENU_PTR p has entry
  15788.                                     number entry displayed in the popup menu's
  15789.                                     window, 0 otherwise.  This macro is useful
  15790.                                     if you have a scrolling popup menu and want
  15791.                                     to know if a particular entry is displayed
  15792.                                     in the window.
  15793.  
  15794.   POPUP_VIRTUAL_WINDOW(p) - Returns the VWPOINTER of the popup menu.
  15795.  
  15796.   POPUP_WINDOW(p) - Returns the WPOINTER of the popup menu.
  15797.  
  15798.   POPUP_WRAP_ON(p) -    Returns 1 if the highlight wrap of POPUP_MENU_PTR p is
  15799.                         on, otherwise 0.
  15800.  
  15801.  
  15802.  
  15803.  Page 271                     The C Window Library                    Page 271
  15804.  
  15805.   Bar Menu Macros
  15806.   ---------------
  15807.  
  15808.   BAR_CONFIRM_ON(b) - Returns 1 if the BAR_MENU_PTR b has the confirmation for
  15809.                       hotkey selections on, 0 otherwise.
  15810.  
  15811.   BAR_DISPLAY_ON(b) - Returns 1 if the BAR_MENU_PTR b's window is to be
  15812.                       displayed regardless if the menu manager has returned to
  15813.                       the calling function, 0 otherwise.
  15814.  
  15815.   BAR_ENHANCED_ON(p) - Returns 1 if the bar menu will recognize enhanced keys,
  15816.                        0 otherwise.
  15817.  
  15818.   BAR_ENTRY_AVAILABLE(b,entry) - Returns 1 if the BAR_MENU_ENTRY entry is
  15819.                                  available, 0 otherwise.
  15820.  
  15821.   BAR_ENTRY_STRING(b,entry) - Returns the entry string of BAR_MENU_ENTRY entry.
  15822.  
  15823.   BAR_EXPLODE(b) -  Returns the special effect constant of the BAR_MENU_PTR b.
  15824.                     This special effect is used to hide, close, and open the
  15825.                     popup menu's window.
  15826.  
  15827.   BAR_NUMBER_OF_ENTRIES(b) - Returns the total number of entries defined in
  15828.                              the BAR_MENU_PTR b.
  15829.  
  15830.   BAR_OVERRIDE_ON(b) - Returns 1 if BAR_MENU_PTR b will have unavailable
  15831.                        options processed, 0 otherwise.
  15832.  
  15833.   BAR_PULLDOWN_ON(b) - Returns 1 if the BAR_MENU_PTR b is incorporated in a
  15834.                        pulldown menu system, 0 otherwise.
  15835.  
  15836.   BAR_STATIC_ON(b) -  Returns 1 if the BAR_MENU_PTR b will remain on the screen
  15837.                       when an entry is selected, 0 otherwise.
  15838.  
  15839.   BAR_WINDOW(b) - Returns the WPOINTER of the bar menu.
  15840.  
  15841.   BAR_WRAP_ON(b) -    Returns 1 if the highlight wrap of BAR_MENU_PTR b is on,
  15842.                       otherwise 0.
  15843.  
  15844.  
  15845.  
  15846.  
  15847.  
  15848.  
  15849.  
  15850.  
  15851.  
  15852.  
  15853.  
  15854.  
  15855.  
  15856.  
  15857.  
  15858.  
  15859.  Page 272                     The C Window Library                    Page 272
  15860.  
  15861.                                  VIDEO MACROS
  15862.                                  ------------
  15863.  
  15864.   The following macros are defined in the vidsys.h file.
  15865.   Note:  by including window.h in your source files, vidsys.h is automatically
  15866.   included.
  15867.  
  15868.   CHECK_SNOW - Returns 1 if during direct screen writes that video "snow" is
  15869.                eliminated.  You can also assign values to this macro.  This
  15870.                macro is a pseudonym for the variable chksnow_.
  15871.  
  15872.                Example:
  15873.                 #include "vidsys.h"
  15874.                     ...
  15875.                 int a;
  15876.                 a = CHECK_SNOW;  /* Returns 1 if snow checking on,
  15877.                                     0 otherwise */
  15878.                 CHECK_SNOW = 0;  /* Turn off snow checking */
  15879.  
  15880.   CREATE_VIDEO_ATTRIBUTE(bg,fg) - creates a video attribute using bg as the
  15881.                   background color, and fg as the foreground color.  The
  15882.                   following variables can be used:
  15883.  
  15884.       Variable                     |    Variable
  15885.         Name       Color    Value  |     Name           Color          Value
  15886.       -------      -----    -----  |    -------         -----          -----
  15887.         black      Black      0    |    gray            Gray             8
  15888.         blue       Blue       1    |    lightblue       Light Blue       9
  15889.         green      Green      2    |    lightgreen      Light green     10
  15890.         cyan       Cyan       3    |    lightcyan       Light cyan      11
  15891.         red        Red        4    |    lightred        Light red       12
  15892.         magenta    Magenta    5    |    lightmagenta    Light magenta   13
  15893.         brown      Brown      6    |    yellow          Yellow          14
  15894.         white      White      7    |    lightwhite      Intense white   15
  15895.  
  15896.             For monochrome systems, the only colors that are available are
  15897.             black, white, and intense white.  An attribute of blue creates
  15898.             an underline attribute, and light blue creates an intense
  15899.             underlined attribute.  Any other combination on a monochrome
  15900.             system is undefined.
  15901.  
  15902.   GET_BGROUND_COLOR(c) - Returns the background color of the video attribute c.
  15903.  
  15904.   GET_FGROUND_COLOR(c) - Returns the foreground color of the video attribute c.
  15905.  
  15906.   GET_OFFSET(x) -  Returns the offset of a pointer x.  The pointer can be either
  15907.                    near or far.
  15908.  
  15909.   GET_SEGMENT(x) - Returns the segment address of a pointer x.  The pointer can
  15910.                    be either near or far.
  15911.  
  15912.   MAKE_FAR_POINTER(a,b) - Creates a far pointer made up of segment address a,
  15913.                           and offset address b.
  15914.  
  15915.  Page 273                     The C Window Library                    Page 273
  15916.  
  15917.   SCREEN_OFFSET(r,c,a) -  Returns the screen offset of the address of a
  15918.                           character located at row r and column c of the video
  15919.                           page a.  The screen segment is defined in the macro
  15920.                           SCREEN_SEGMENT.  both r and c should be >= 1.
  15921.  
  15922.            Example:
  15923.                char far *p;
  15924.                p = MAKE_FAR_POINTER(SCREEN_SEGMENT,SCREEN_OFFSET(1,1,0));
  15925.  
  15926.            The above example has created a far pointer p that points to the
  15927.            screen buffer memory at row 1, column 1, on video page 0.
  15928.  
  15929.   SCREEN_OFFSET_ATTR(r,c,a) - Returns the screen offset of the address of a
  15930.                        attribute located at row r and column c of the video page
  15931.                        a.  The screen segment is defined in the macro
  15932.                        SCREEN_SEGMENT. both r and c should be >= 1.
  15933.  
  15934.   SCREEN_SEGMENT - Returns the screen segment of video page 0.  This macro is a
  15935.                    pseudonym for the variable scrnseg_.
  15936.  
  15937.  
  15938.   SCREEN_WRITE_METHOD - Returns 1 if writing directly to the screen, 0 if using
  15939.                         the BIOS.  You can also use this macro to assign the
  15940.                         particular writing method.  This macro controls the way
  15941.                         The C Window Library will do screen updates.  The
  15942.                         default is 1 (write directly to screen).
  15943.  
  15944.          Example:
  15945.              #include "vidsys.h"
  15946.              int a,b;
  15947.              a = SCREEN_WRITE_METHOD;  /* a now has the current write method */
  15948.              SCREEN_WRITE_METHOD = 1;  /* set write method to direct screen
  15949.                                           memory */
  15950.  
  15951.              This macro is a pseudonym for the variable scrnwrt_flag which is a
  15952.              member of the SYS_FLAGS structure video_system_flags.
  15953.  
  15954.  
  15955.   VIDEO_PAGESIZE - Returns the size (in bytes) of a video page.  You can also
  15956.                    assign values to VIDEO_PAGESIZE, but the best thing to do is
  15957.                    to leave it alone unless you are familiar with the video
  15958.                    system you are using.  This macro is a pseudonym for the
  15959.                    variable pagesize_.
  15960.  
  15961.                    Example:
  15962.                    #include "vidsys.h"
  15963.                    int psize;
  15964.                    psize = VIDEO_PAGESIZE; /* Return the current
  15965.                                                video page size */
  15966.  
  15967.  
  15968.  
  15969.  
  15970.  
  15971.  Page 274                     The C Window Library                    Page 274
  15972.  
  15973.   The following macros are used to identify the monitor type and video card
  15974.   being used in the system.
  15975.   Note :  These macros are pseudonyms for members in the SYS_FLAGS structure
  15976.           called video_system_flags.
  15977.  
  15978.  
  15979.    CGA_ACTIVE    -   Returns 1 if Color Graphics Adapter is active, 0 otherwise.
  15980.    EGA_ACTIVE    -   Returns 1 if EGA is active, 0 otherwise.
  15981.    EGA_COLOR_ATTACHED - Returns 1 if monitor hooked up to EGA is a high
  15982.                         resolution color monitor, 0 otherwise.
  15983.    EGA_COLOR_ON  - Returns 1 if EGA is in color mode, 0 otherwise.
  15984.    EGA_INSTALLED - Returns 1 if EGA is installed, 0 otherwise.
  15985.    HERCULES_ACTIVE - Returns 1 if Hercules adapter is active, 0 otherwise.
  15986.    MCGA_ACTIVE    - Returns 1 if the MCGA is the active video card.
  15987.    MCGA_COLOR_ON - Returns 1 if MCGA is in color mode, 0 otherwise.
  15988.    MCGA_INSTALLED - Returns 1 if MCGA is installed (IBM PS/2 Model 30),
  15989.                     0 otherwise.
  15990.    MDA_ACTIVE    -   Returns 1 if MDA (Monochrome) adapter is active,
  15991.                      0 otherwise.
  15992.    MONO_MODE_ON  -   Returns 1 if Monochrome mode is on regardless of the
  15993.                      adapter, 0 otherwise.
  15994.    VGA_ACTIVE    -   Returns 1 if VGA is active adapter, 0 otherwise.
  15995.    VGA_COLOR_ATTACHED - Returns 1 if monitor hooked up to VGA is analog color,
  15996.                         0 otherwise.
  15997.    VGA_COLOR_ON  -   Returns 1 if VGA is in color mode, 0 otherwise.
  15998.    VGA_INSTALLED -   Returns 1 if VGA Adapter is installed, 0 otherwise.
  15999.  
  16000.  
  16001.    You should always check the ..._ACTIVE constants before checking for other
  16002.    aspects of the video system.  For example, make sure that VGA_ACTIVE returns
  16003.    1 before checking any other VGA_... macro.  If VGA_ACTIVE is 1, then all
  16004.    VGA_... macros are valid.  The same thing goes for EGA.  MONO_MODE_ON is the
  16005.    only macro that can be tested regardless of the video adapter.
  16006.  
  16007.    The following are macros defined in version 1.0 of The C Window Library,
  16008.    which are still supported:
  16009.  
  16010.    CGA_MODE_ON  - Same as CGA_ACTIVE.
  16011.    EGA_MODE_ON  - Same as EGA_ACTIVE.
  16012.    VGA_MODE_ON  - Same as VGA_ACTIVE.
  16013.    MCGA_MODE_ON - Same as MCGA_ACTIVE.
  16014.    EGA_MONO_ON  - Returns 1 if EGA is in mono mode.
  16015.    VGA_MONO_ON  - Returns 1 if VGA is in mono mode.
  16016.    MCGA_MONO_ON - Returns 1 if MCGA is in mono mode.
  16017.  
  16018.    You should not assign values to the above pseudo-constants unless you are
  16019.    completely familiar with The C Window Library's internal functions.
  16020.  
  16021.    LINEMODE25 - Returns 1 if screen displays 25 lines, 0 otherwise.
  16022.    LINEMODE43 - Returns 1 if screen displays 43 lines (EGA and VGA), 0
  16023.                 otherwise.
  16024.    LINEMODE50 - Returns 1 if screen displays 50 lines (VGA), 0 otherwise.
  16025.  
  16026.  
  16027.  
  16028.  Page 275                     The C Window Library                    Page 275
  16029.  
  16030.                                   BOX MACROS
  16031.                                   ----------
  16032.  
  16033.  
  16034.    The list of defined box drawing macros is as follows:
  16035.  
  16036.                           DOUBLEBOX
  16037.                           SINGLEBOX
  16038.                           MIXEDBOX1
  16039.                           MIXEDBOX2
  16040.                           HATCHBOX1
  16041.                           HATCHBOX2
  16042.                           HATCHBOX3
  16043.                           SOLIDBOX1
  16044.                           SOLIDBOX2
  16045.                           BLANKBOX
  16046.                           DOTTEDLINE
  16047.  
  16048.    Each one of these macros are 8 character strings that can be used in
  16049.    functions that call for a string of box drawing characters.
  16050.  
  16051.  
  16052.  
  16053.  
  16054.  
  16055.  
  16056.  
  16057.  
  16058.  
  16059.  
  16060.  
  16061.  
  16062.  
  16063.  
  16064.  
  16065.  
  16066.  
  16067.  
  16068.  
  16069.  
  16070.  
  16071.  
  16072.  
  16073.  
  16074.  
  16075.  
  16076.  
  16077.  
  16078.  
  16079.  
  16080.  
  16081.  
  16082.  
  16083.  
  16084.  Page 276                     The C Window Library                    Page 276
  16085.  
  16086.                                EXPLOSION MACROS
  16087.                                ----------------
  16088.  
  16089.    The list of explosion constants is as follows:
  16090.  
  16091.                           NOEFFECT
  16092.                           EXPLODE
  16093.                           CONTRACT
  16094.                           BRICKS
  16095.                           MIDDLEROWOUT
  16096.                           TOPBOTTOMIN
  16097.                           TOPDOWN
  16098.                           BOTTOMUP
  16099.                           MIDDLECOLOUT
  16100.                           LEFTRIGHTIN
  16101.                           LEFTTORIGHT
  16102.                           RIGHTTOLEFT
  16103.  
  16104.  
  16105.  
  16106.  
  16107.  
  16108.  
  16109.  
  16110.  
  16111.  
  16112.  
  16113.  
  16114.  
  16115.  
  16116.  
  16117.  
  16118.  
  16119.  
  16120.  
  16121.  
  16122.  
  16123.  
  16124.  
  16125.  
  16126.  
  16127.  
  16128.  
  16129.  
  16130.  
  16131.  
  16132.  
  16133.  
  16134.  
  16135.  
  16136.  
  16137.  
  16138.  
  16139.  
  16140.  Page 277                     The C Window Library                    Page 277
  16141.  
  16142.                                  KEYBOARD MACROS
  16143.                                  ---------------
  16144.  
  16145.   The following macros are used to get characters from the keyboard.
  16146.   They are prototyped in the file key.h.
  16147.  
  16148.  
  16149.   ENHANCED_KEYBOARD() - Returns 1 if there is an enhanced keyboard attached, 0
  16150.                         otherwise.
  16151.  
  16152.   FLUSH_KEYBOARD() - Flushes the keyboard buffer.
  16153.  
  16154.   GET_KEY() - Returns what key was pressed either as a character, or as a
  16155.               scan code if a non-ascii key is pressed.  A list of scan codes are
  16156.               found in the file keycodes.h.
  16157.  
  16158.   GET_ENHANCED_KEY() - Same as GET_KEY() except that keys on the enhanced
  16159.                        keyboards are distinguishable.  For instance, the  key on
  16160.                        the keypad will return a different scan code than the
  16161.                        Home key on the separate cursor movement pad.
  16162.  
  16163.   GET_SHIFT_STATE() - Returns the shift state of the keyboard.  The shift state
  16164.                       tells whether the Alt, Ctrl or Shift key was pressed, or
  16165.                       if the Num Lock, Scroll Lock, or Caps Lock keys are on or
  16166.                       off.  The shift state is updated after each call to
  16167.                       GET_KEY() or GET_ENHANCED_KEY().  Use a bitwise AND (&)
  16168.                       when testing for these keys, as the example below
  16169.                       demonstrates:
  16170.  
  16171.                       Example:
  16172.  
  16173.                       #include "key.h"
  16174.                       #include "keycodes.h"
  16175.  
  16176.                          ...
  16177.                       int CurrentShift;
  16178.                       GET_KEY();
  16179.                       CurrentShift = GET_SHIFT_STATE() & ALT;
  16180.  
  16181.                       printf("The Alt key was %s pressed",
  16182.                       CurrentShift?"":"not");
  16183.  
  16184.   ISKEYREADY() - Returns 1 if there is a key ready in the keyboard buffer, 0
  16185.                   otherwise.
  16186.  
  16187.  
  16188.  
  16189.  
  16190.  
  16191.  
  16192.  
  16193.  
  16194.  
  16195.  
  16196.  Page 278                     The C Window Library                    Page 278
  16197.  
  16198.                                  CURSOR MACROS
  16199.                                  -------------
  16200.  
  16201.  
  16202.   The following macros are used for cursor manipulation.
  16203.  
  16204.  
  16205.   CREATE_CURSOR_SHAPE(startline, endline) - Forms an integer quantity
  16206.                       representing a cursor with a starting scan line of
  16207.                       scanline, and an ending scan line of endline.
  16208.  
  16209.   THIN - constant for a thin (underline) cursor.
  16210.  
  16211.   BLOCK - constant for a block (fat) cursor.
  16212.  
  16213.   INVISIBLE - constant for a hidden cursor.
  16214.  
  16215.  
  16216.  
  16217.  
  16218.  
  16219.  
  16220.  
  16221.  
  16222.  
  16223.  
  16224.  
  16225.  
  16226.  
  16227.  
  16228.  
  16229.  
  16230.  
  16231.  
  16232.  
  16233.  
  16234.  
  16235.  
  16236.  
  16237.  
  16238.  
  16239.  
  16240.  
  16241.  
  16242.  
  16243.  
  16244.  
  16245.  
  16246.  
  16247.  
  16248.  
  16249.  
  16250.  
  16251.  
  16252.  Page 279                     The C Window Library                    Page 279
  16253.                       IMPORTANT GLOBAL VARIABLES
  16254.                       --------------------------
  16255.  
  16256.   There are global variables that you should be aware of in The C Window
  16257.   Library.  Most of these variables can be changed, while others should be left
  16258.   alone.  You must call WindowInitializeSystem() before modifying any of these
  16259.   variables.
  16260.  
  16261.   When describing the global variable, the following scheme is used:
  16262.  
  16263.  
  16264.  
  16265.  
  16266.  
  16267.   Variable         variable name
  16268.  
  16269.   Defined in       XXXXXX.h  (file where variable is declared)
  16270.  
  16271.   Initialized in   function call (function where variable gets its initial
  16272.                                   value)
  16273.  
  16274.   Purpose          Description of variable's purpose.
  16275.  
  16276.   Default Value    default value for variable.
  16277.  
  16278.   Modify Info      Tells if variable should be modified.
  16279.  
  16280.  
  16281.  
  16282.   These variables are described in alphabetical order.
  16283.  
  16284.  
  16285.  
  16286.  
  16287.  
  16288.  
  16289.  
  16290.   Variable         int active_video_page
  16291.  
  16292.   Defined in       vidsys.h
  16293.  
  16294.   Initialized in   WindowInitializeSystem()
  16295.  
  16296.   Purpose          Current active video page.
  16297.  
  16298.   Modify Info      Should be modified only by calling the SetActiveVideoPage()
  16299.                    function.
  16300.  
  16301.  
  16302.  
  16303.  
  16304.  
  16305.  
  16306.  
  16307.  
  16308.  Page 280                     The C Window Library                    Page 280
  16309.  
  16310.   Variable         int caldelay_
  16311.  
  16312.   Defined          vidsys.h
  16313.  
  16314.   Initialized in   WindowInitializeSystem()
  16315.  
  16316.   Purpose          This is a calibration count for the delay() function.
  16317.  
  16318.   Modify Info      Should only be modified if the delay() function is giving
  16319.                    inaccurate delay times.  If the delay is too long, then
  16320.                    caldelay_ should be decreased.  If it is too short, then
  16321.                    caldelay_ should be increased.
  16322.  
  16323.  
  16324.  
  16325.  
  16326.   Variable         int check_existence_flag
  16327.  
  16328.   Defined in       window.h
  16329.  
  16330.   Initialized in   WindowInitializeSystem()
  16331.  
  16332.   Purpose          Informs The C Window Library to check for window, virtual
  16333.                    window, and for non-open window errors.  If this variable is
  16334.                    1, the library routines will check for these conditions.  If
  16335.                    0, these conditions are not checked.
  16336.  
  16337.   Default Value    1.
  16338.  
  16339.   Modify Info      Can be modified at any time, but is recommended that this
  16340.                    flag be left on for development work.  Make sure that your
  16341.                    application program is stable if you plan to turn off
  16342.                    checking.
  16343.  
  16344.  
  16345.  
  16346.  
  16347.   Variable         int chksnow_
  16348.  
  16349.   Defined          vidsys.h
  16350.  
  16351.   Initialized in   WindowInitializeSystem()
  16352.  
  16353.   Purpose          This variable controls whether the display should be checked
  16354.                    for snow when writing directly to the screen.  A value of
  16355.                    1 will check for snow, while a value of 0 will turn off
  16356.                    snow checking.
  16357.  
  16358.   Default Value    0 (no snow checking).
  16359.  
  16360.   Modify Info      Can be modified at any time.
  16361.  
  16362.  
  16363.  
  16364.  Page 281                     The C Window Library                    Page 281
  16365.  
  16366.   Variable         int crt_status_port
  16367.  
  16368.   Defined          vidsys.h
  16369.  
  16370.   Initialized in   WindowInitializeSystem()
  16371.  
  16372.   Purpose          This variable holds the value of the CRT status port.  This
  16373.                    port is used to test when it is safe to read or write
  16374.                    characters to the screen without producing snow.
  16375.  
  16376.   Modify Info      Should not be modified.
  16377.  
  16378.  
  16379.  
  16380.  
  16381.   Variable         int default_cursor_mode
  16382.  
  16383.   Defined          key.h
  16384.  
  16385.   Initialized in   WindowInitializeSystem()
  16386.  
  16387.   Purpose          Holds the mode that the WindowGet...() functions will
  16388.                    operate in when called.  The modes are either OVERSTRIKEMODE
  16389.                    or INSERTMODE.
  16390.  
  16391.   Default Value    OVERSTRIKEMODE.
  16392.  
  16393.   Modify Info      Can be modified at any time.
  16394.  
  16395.                    Example:
  16396.  
  16397.                    default_cursor_mode = INSERTMODE;
  16398.  
  16399.  
  16400.  
  16401.   Variable         int default_cursor_type[2]
  16402.  
  16403.   Defined          key.h
  16404.  
  16405.   Initialized in   WindowInitializeSystem()
  16406.  
  16407.   Purpose          Holds the cursor shapes for OVERSTRIKEMODE and INSERTMODE
  16408.                    input modes.
  16409.  
  16410.   Default Value    default_cursor_type[OVERSTRIKEMODE] is set to a block cursor.
  16411.                    default_cursor_type[INSERTMODE] is set to an underline
  16412.                    cursor.
  16413.  
  16414.   Modify Info      Can be modified at any time.
  16415.  
  16416.                    Example:
  16417.  
  16418.                    default_cursor_type[INSERTMODE] = CREATE_CURSOR_SHAPE(5,7);
  16419.  
  16420.  Page 282                     The C Window Library                    Page 282
  16421.  
  16422.   Variable         int default_screen_attr
  16423.  
  16424.   Defined in       vidsys.h
  16425.  
  16426.   Initialized in   WindowInitializeSystem()
  16427.  
  16428.   Purpose          Default video attribute used when any Video...() functions
  16429.                    are called to write to the screen.
  16430.  
  16431.   Default Value    7 (black background, white foreground).
  16432.  
  16433.   Modify Info      Can be modified at any time.
  16434.  
  16435.  
  16436.  
  16437.  
  16438.  
  16439.   Variable         int enhanced_keyboard
  16440.  
  16441.   Defined in       key.h
  16442.  
  16443.   Initialized in   WindowInitializeSystem()
  16444.  
  16445.   Purpose          Tells if an enhanced keyboard is attached.  If
  16446.                    enhanced_keyboard is 1, an enhanced keyboard is active,
  16447.                    otherwise if 0, the keyboard is not an enhanced keyboard.
  16448.  
  16449.   Modify Info      Can be modified safely.
  16450.  
  16451.  
  16452.  
  16453.  
  16454.   Variable         int explosion_speed[12]
  16455.  
  16456.   Defined in       window.h
  16457.  
  16458.   Initialized in   WindowInitializeSystem()
  16459.  
  16460.   Purpose          This array holds the number of milliseconds of delay for
  16461.                    each of the special effects supported in The C Window
  16462.                    Library.
  16463.  
  16464.   Default Value    10 (10 ms.), except for explosion_speed[BRICKS], which is 1
  16465.                    ms.
  16466.  
  16467.   Modify Info      Can be modified safely at anytime.  The way you would modify
  16468.                    the values is to use the special effects constants.  For
  16469.                    example:
  16470.  
  16471.                         explosion_speed[CONTRACT] = 5;
  16472.  
  16473.                    The above example changes the explosion delay for the
  16474.                    CONTRACT special effect to 5 ms.
  16475.  
  16476.  Page 283                     The C Window Library                    Page 283
  16477.  
  16478.   Variable         int flush_keyboard_flag.
  16479.  
  16480.   Defined in       key.h
  16481.  
  16482.   Initialized in   WindowInitializeSystem().
  16483.  
  16484.   Purpose          Tells if the keyboard buffer should be flushed whenever
  16485.                    the GET_KEY() or GET_ENHANCED_KEY() macros are called.  A
  16486.                    value of 1 means the buffer will be flushed.
  16487.  
  16488.   Default Value    0 (no flush).
  16489.  
  16490.   Modify Info      Can be modified at any time.
  16491.  
  16492.  
  16493.  
  16494.  
  16495.  
  16496.   Variable         VIDEO_CONFIG initial_video_startup
  16497.  
  16498.   Defined in       vidsys.h
  16499.  
  16500.   Initialized in   WindowInitializeSystem()
  16501.  
  16502.   Purpose          Structure that holds the video configuration when
  16503.                    WindowInitializeSystem() is called.
  16504.  
  16505.   Modify info      Should not be modified if the initial video startup is
  16506.                    desired when exiting an application.
  16507.  
  16508.  
  16509.  
  16510.  
  16511.  
  16512.  
  16513.   Variable         char input_mask_char
  16514.  
  16515.   Defined in       window.h
  16516.  
  16517.   Initialized in   WindowInitializeSystem()
  16518.  
  16519.   Purpose          Holds the mask character that is used for input routines.
  16520.                    The character defined in input_mask_char is used in input
  16521.                    masks to specify an input position in the edit field.  Refer
  16522.                    to the functions WindowGet..() functions for more
  16523.                    information concerning character masks.
  16524.  
  16525.   Default Value    '_'  (0x5F).
  16526.  
  16527.   Modify Info      Can be modified safely at any time, except when in the middle
  16528.                    of a user defined function that was called by The C Window
  16529.                    Library's input routines.
  16530.  
  16531.  
  16532.  Page 284                     The C Window Library                    Page 284
  16533.  
  16534.   Variable         int max_video_pages
  16535.  
  16536.   Defined in       vidsys.h
  16537.  
  16538.   Initialized in   WindowInitializeSystem()
  16539.  
  16540.   Purpose          Total number of video pages detected by The C Window Library.
  16541.  
  16542.   Modify Info      Should not be modified unless a modification to the
  16543.                    screen_page_offset array was done.
  16544.  
  16545.  
  16546.  
  16547.  
  16548.  
  16549.  
  16550.   Variable         int max_window_rank
  16551.  
  16552.   Defined in       window.h
  16553.  
  16554.   Initialized in   WindowInitializeSystem()
  16555.  
  16556.   Purpose          Holds the rank value of the bottom-most (i.e. the
  16557.                    window that will have all other windows covering it).
  16558.  
  16559.   Modify Info      Do not modify.
  16560.  
  16561.  
  16562.  
  16563.  
  16564.  
  16565.  
  16566.   Variable         int min_window_rank
  16567.  
  16568.   Defined in       window.h
  16569.  
  16570.   Initialized in   WindowInitializeSystem()
  16571.  
  16572.   Purpose          Holds the rank value of the top-most visible window.
  16573.  
  16574.   Modify Info      Do not modify.
  16575.  
  16576.  
  16577.  
  16578.  
  16579.  
  16580.  
  16581.  
  16582.  
  16583.  
  16584.  
  16585.  
  16586.  
  16587.  
  16588.  Page 285                     The C Window Library                    Page 285
  16589.  
  16590.   Variable         int (*num_chars_entered_func)(char *string, int minchars)
  16591.  
  16592.   Defined in       key.h
  16593.  
  16594.   Arguments        string - string that was entered.
  16595.                    minchars - minimum number of characters expected.
  16596.  
  16597.   Initialized in   WindowInitializeSystem()
  16598.  
  16599.   Purpose          Pointer to user-defined function that will be executed when
  16600.                    the input manager detects that there were not enough
  16601.                    characters entered.
  16602.  
  16603.   Default Value    NULLFN.
  16604.  
  16605.   Modify info      Can be modified at any time.
  16606.  
  16607.   Return Values    Must return DONT_PROCESS or ACCEPT_INPUT.  Refer to page 99
  16608.                    for more information.
  16609.  
  16610.  
  16611.  
  16612.  
  16613.  
  16614.   Variable         int num_transparent_shadows[16]
  16615.  
  16616.   Defined in       window.h
  16617.  
  16618.   Initialized in   WindowInitializeSystem()
  16619.  
  16620.   Purpose          Array of the number of transparent shadows that are currently
  16621.                    displayed for each display page.
  16622.  
  16623.   Default Value    0 for each array element.
  16624.  
  16625.   Modify Info      Do not modify.
  16626.  
  16627.  
  16628.  
  16629.  
  16630.  
  16631.  
  16632.  
  16633.  
  16634.  
  16635.  
  16636.  
  16637.  
  16638.  
  16639.  
  16640.  
  16641.  
  16642.  
  16643.  
  16644.  Page 286                     The C Window Library                    Page 286
  16645.  
  16646.   Variable         WPOINTER orig_screen[16]
  16647.  
  16648.   Defined in       window.h
  16649.  
  16650.   Initialized in   WindowSaveInitial()
  16651.  
  16652.   Purpose          Array of windows created when WindowSaveInitial() is called.
  16653.                    The original screen for video page 0 is orig_screen[0], page
  16654.                    1 is orig_screen[1], etc.
  16655.   Modify Info      You can use any window function on the original screen,
  16656.                    except for ones that resize, move, hide, display, or close.
  16657.                    If you write strings to the original screen, you will
  16658.                    permanently destroy the contents of the original screen at
  16659.                    the positions that have been modified.
  16660.  
  16661.                    Example:
  16662.  
  16663.                    WindowWriteString(orig_screen[0],"123",1,1);
  16664.  
  16665.                    The above example writes "123" to the upper left hand corner
  16666.                    of the original screen of video page 0.
  16667.  
  16668.  
  16669.  
  16670.  
  16671.  
  16672.   Variable         int pagesize_
  16673.  
  16674.   Defined in       window.h
  16675.  
  16676.   Initialized in   WindowInitializeSystem()
  16677.  
  16678.   Purpose          Holds the size of a display page in bytes.
  16679.  
  16680.   Modify Info      Should not be modified unless The C Window Library did not
  16681.                    detect the correct video page size.
  16682.  
  16683.  
  16684.  
  16685.  
  16686.  
  16687.  
  16688.  
  16689.  
  16690.  
  16691.  
  16692.  
  16693.  
  16694.  
  16695.  
  16696.  
  16697.  
  16698.  
  16699.  
  16700.  Page 287                     The C Window Library                    Page 287
  16701.  
  16702.   Variable         int (*reg_exp_error_func)(char *string, int nomatch);
  16703.  
  16704.   Defined in       key.h
  16705.  
  16706.   Arguments        string - string that was entered.
  16707.                    nomatch - position of the first non-matching character.
  16708.  
  16709.   Initialized in   WindowInitializeSystem()
  16710.  
  16711.   Purpose          Pointer to user-defined function that will be executed when
  16712.                    the input manager detects that there are illegal characters
  16713.                    in the string when it is compared to the regular
  16714.                    expression.  This function is only called when it is not
  16715.                    equal to NULLFN, and the CHECKREGEXP option is on.
  16716.  
  16717.   Default Value    NULLFN.
  16718.  
  16719.   Modify info      Can be modified at any time.
  16720.  
  16721.   Return Values    Must return DONT_PROCESS or ACCEPT_INPUT.  Refer to the
  16722.                    page 97 for more information.
  16723.  
  16724.  
  16725.  
  16726.   Variable         unsigned char *screen_image[16]
  16727.  
  16728.   Defined in       window.h
  16729.  
  16730.   Initialized in   WindowInitializeSystem()
  16731.  
  16732.   Purpose          Used for internal window management.  Each pointer in the
  16733.                    screen_image array points to an image of the current
  16734.                    window organization of the screen. For example
  16735.                    screen_image[0] is a pointer to the current window "layout"
  16736.                    for video page 0.
  16737.  
  16738.   Modify Info      DO NOT modify this.  This array is VERY important when window
  16739.                    updates are done.
  16740.  
  16741.  
  16742.  
  16743.  
  16744.  
  16745.  
  16746.  
  16747.  
  16748.  
  16749.  
  16750.  
  16751.  
  16752.  
  16753.  
  16754.  
  16755.  
  16756.  Page 288                     The C Window Library                    Page 288
  16757.  
  16758.   Variable         unsigned char far *screen_page_offset[16]
  16759.  
  16760.   Defined in       window.h
  16761.  
  16762.   Initialized in   WindowInitializeSystem()
  16763.  
  16764.   Purpose          Array of starting addresses of each video page.
  16765.  
  16766.   Modify Info      You can modify if The C Window Library fails to detect video
  16767.                    pages that your video card may have.
  16768.  
  16769.                    Invalid video pages will set screen_page_offset[page] to a
  16770.                    far NULL pointer, where page is the invalid video page.
  16771.  
  16772.                    If there is a failure to detect video pages that your card
  16773.                    may have, you can use the MAKE_FAR_POINTER macro to
  16774.                    initialize.
  16775.                    Example: screen_page_offset[page] =
  16776.                             MAKE_FAR_POINTER(0xB000,0x2000);
  16777.  
  16778.                    where page is the page to initialize.  You should have the
  16779.                    documentation of the video card on hand so that you are sure
  16780.                    of the starting address of the video page.
  16781.  
  16782.                    You must also adjust the global variable max_video_pages to
  16783.                    reflect the new number of pages, and the pagesize_ variable.
  16784.  
  16785.  
  16786.  
  16787.  
  16788.  
  16789.  
  16790.   Variable         int (*undef_akey_func)(char *string, unsigned key, int pos)
  16791.  
  16792.   Defined in       key.h
  16793.  
  16794.   Arguments        string - string currently entered.
  16795.                    key - key that was hit.
  16796.                    pos - position where cursor is in the input string.
  16797.  
  16798.   Purpose          Pointer to a function that is executed when a key that is not
  16799.                    defined in an input routines regular expression is pressed.
  16800.                    Refer to page 93 for more information.
  16801.  
  16802.   Default Value    NULLFN.
  16803.  
  16804.   Modify Info      Can be modified at any time.
  16805.  
  16806.   Return Values    Refer to page 93 for more information.
  16807.  
  16808.  
  16809.  
  16810.  
  16811.  
  16812.  Page 289                     The C Window Library                    Page 289
  16813.  
  16814.   Variable         int (*undef_fkey_func)(char *string, unsigned key, int pos)
  16815.  
  16816.   Defined in       key.h
  16817.  
  16818.   Arguments        string - string currently entered.
  16819.                    key - key that was hit.
  16820.                    pos - position where cursor is in the input string.
  16821.  
  16822.   Purpose          Pointer to a function that is executed when a key that is not
  16823.                    defined in an input routines regular expression is pressed.
  16824.                    Refer to page 93 for more information.
  16825.  
  16826.   Purpose          Pointer to a function that is executed when a key that is not
  16827.                    defined in the window_edit_key array is pressed.
  16828.  
  16829.   Default Value    NULLFN.
  16830.  
  16831.   Modify Info      Can be modified at any time.
  16832.  
  16833.   Return Values    Refer to page 93 for more information.
  16834.  
  16835.  
  16836.  
  16837.  
  16838.  
  16839.  
  16840.   Variable         VWPOINTER virtual_window_ptrs[256]
  16841.  
  16842.   Defined in       window.h
  16843.  
  16844.   Purpose          Array of all initialized virtual window pointers.
  16845.  
  16846.   Modify Info      Do not modify.
  16847.  
  16848.  
  16849.  
  16850.  
  16851.  
  16852.   Variable         int visible_video_page
  16853.  
  16854.   Defined in       vidsys.h
  16855.  
  16856.   Initialized in   WindowInitializeSystem()
  16857.  
  16858.   Purpose          Current visible video page.
  16859.  
  16860.   Modify Info      Should be modified only by calling the SetVisibleVideoPage()
  16861.                    function.
  16862.  
  16863.  
  16864.  
  16865.  
  16866.  
  16867.  
  16868.  Page 290                     The C Window Library                    Page 290
  16869.  
  16870.   Variable         unsigned window_edit_key[12]
  16871.  
  16872.   Defined in       window.h
  16873.  
  16874.   Initialized in   WindowInitializeSystem()
  16875.  
  16876.   Purpose          Array of edit key definitions.  This array is used in the
  16877.                    window input routines.
  16878.  
  16879.   Modify Info      You can modify values in the array, provided that there are
  16880.                    no duplicate definitions, and there is a definition for a key
  16881.                    that terminates user input.  Refer to the GETTING INPUT FROM
  16882.                    WINDOWS section on page 76 for more information.
  16883.  
  16884.  
  16885.  
  16886.  
  16887.  
  16888.   Variable         int window_error_code
  16889.  
  16890.   Defined in       window.h
  16891.  
  16892.   Initialized in   WindowInitializeSystem()
  16893.  
  16894.   Purpose          Holds the last error that occurred as an integer.  You should
  16895.                    always check the value of window_error_code to determine what
  16896.                    has happened if a function fails.  All of the window and
  16897.                    virtual window functions return an error status when things
  16898.                    go wrong.  However, only selected functions from the Video...
  16899.                    family of functions set window_error_code.  The value in
  16900.                    window_error_code corresponds to the values found in
  16901.                    the file werror.h.
  16902.  
  16903.                    window_error_code does not reset itself if there are no
  16904.                    errors.
  16905.  
  16906.   Default Value    0.
  16907.  
  16908.   Modify Info      Safe to modify, but will always reset itself to an error
  16909.                    condition if a function fails.
  16910.  
  16911.  
  16912.  
  16913.  
  16914.  
  16915.   Variable         WPOINTER window_ptrs[256];
  16916.  
  16917.   Defined in       window.h
  16918.  
  16919.   Purpose          Array of all initialized windows.
  16920.  
  16921.   Modify Info      DO NOT modify.
  16922.  
  16923.  
  16924.  Page 291                     The C Window Library                    Page 291
  16925.  
  16926.   Variable         WPOINTER window_rank[257];
  16927.  
  16928.   Defined in       window.h
  16929.  
  16930.   Purpose          Array of all visible windows in rank order.
  16931.  
  16932.   Modify Info      DO NOT modify.
  16933.  
  16934.  
  16935.  
  16936.  
  16937.  
  16938.  
  16939.  
  16940.  
  16941.  
  16942.  
  16943.  
  16944.  
  16945.  
  16946.  
  16947.  
  16948.  
  16949.  
  16950.  
  16951.  
  16952.  
  16953.  
  16954.  
  16955.  
  16956.  
  16957.  
  16958.  
  16959.  
  16960.  
  16961.  
  16962.  
  16963.  
  16964.  
  16965.  
  16966.  
  16967.  
  16968.  
  16969.  
  16970.  
  16971.  
  16972.  
  16973.  
  16974.  
  16975.  
  16976.  
  16977.  
  16978.  
  16979.  
  16980.  Page 292                     The C Window Library                    Page 292
  16981.  
  16982.