cwin.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * "cwin.h" 1995-2002, A C Norman
  3. *
  4. * This defines the public interface supported by the "cwin" window
  5. * interface.
  6. *
  7. */
  8. /*
  9. * This code may be used and modified, and redistributed in binary
  10. * or source form, subject to the "CCL Public License", which should
  11. * accompany it. This license is a variant on the BSD license, and thus
  12. * permits use of code derived from this in either open and commercial
  13. * projects: but it does require that updates to this code be made
  14. * available back to the originators of the package.
  15. * Before merging other code in with this or linking this code
  16. * with other packages or libraries please check that the license terms
  17. * of the other material are compatible with those of this.
  18. */
  19. /*
  20. * The code here is provides a windowed framework in which reasonably
  21. * ordinary C code can run. The functions described here are the
  22. * interface. Version for Windows 95 as well as win32s and Windows NT.
  23. */
  24. /* Signature: 368013b1 10-Oct-2002 */
  25. #ifndef header_cwin_h
  26. #define header_cwin_h 1
  27. #include <stdarg.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /*
  32. * The "C" code will eventually be entered at cwin_main() in what looks like a
  33. * normal way. The function cwin_main() MUST return. There is no provision
  34. * for anything like the exit() function present in normal C libraries. The
  35. * reason for this uncomfortable situation is that my window manager code
  36. * needs to regain cotrol to close things down and tidy up at the end.
  37. * Furthermore conflicts between C++ exceptions and C "setjmp" appear to make
  38. * it hard to find a reliable way of skipping down stack frames across the
  39. * two languages. So I have to insist that that user deals will all
  40. * necessary unwinding by hand. Apologies.
  41. */
  42. extern int cwin_main(int argc, char *argv[]);
  43. /*
  44. * cwin_full_program_name is a string like "d:\xxx\yyy\something.exe" This is
  45. * made available so that applications can edit it to generate names of
  46. * resource files (eg by just altering the ".exe" bit on the end into some
  47. * other suffix.
  48. */
  49. extern char *cwin_full_program_name;
  50. /*
  51. * programName[] holds just the "something" out of cwin_full_program_name.
  52. */
  53. extern char programName[64];
  54. /*
  55. * Something that is SPECIAL and IMPORTANT to this code is that all the
  56. * code executed via cwin_main() must arrange to call
  57. * cwin_poll_window_manager(0);
  58. * every so often. If this does not happen the window system will become
  59. * unresponsive. If you are happy to be suspended (eg waiting for a keystroke)
  60. * you can give an arg of TRUE, otherwise give FALSE (0).
  61. */
  62. extern void cwin_poll_window_manager(int waitForEvent);
  63. /*
  64. * To finish off you can either return from cwin_main(), or you can go
  65. * cwin_exit(n);
  66. * The system will forcibly close down for you if the EXIT item on
  67. * the FILE menu or the CLOSE item on the SYSTEM menu gets selected. But
  68. * direct use of the C function "exit()" is not considered proper.
  69. */
  70. extern void cwin_exit(int return_code);
  71. /*
  72. * To be on the safe side I make exit() a macro for cwin_exit(). This is
  73. * a function that does not exist! It is declared here so that attempts to
  74. * call it will lead to suitable link-time diagnostics.
  75. */
  76. #undef exit
  77. #define exit(n) cwin_exit(n)
  78. extern void cwin_exit(int n);
  79. /*
  80. * If, when the program is stopping, cwin_pause_at_end has been set to
  81. * be non-zero (by default it will be zero) then an alert box is displayed
  82. * forcing the user to give positive confirmation before the main window
  83. * is closed. This does not give an opportunity to cancel the exit, just to
  84. * read the final state of the screen... This effect does not occur if
  85. * program exit is caused by selecting EXIT from the FILE menu or CLOSE
  86. * from the system menu. That is (deliberate in my code) because in those
  87. * cases the user has taken explicit interactive action to terminate the
  88. * program so an extra prompt seems unnecessary.
  89. */
  90. extern int cwin_pause_at_end;
  91. /*
  92. * cwin_minimize() indicates that the window should be shrunk to be just
  93. * an icon.
  94. */
  95. extern void cwin_minimize(void);
  96. /*
  97. * cwin_maximize() indicates that the window should be restored to
  98. * regular size. I do know that in Windows the term "maximize" would more
  99. * usually indicate expansion to fill the whole screen, and what I am
  100. * doing here is a "restore to normal size", but I have chosen not to
  101. * provide an option that explodes windows to full screen size.
  102. */
  103. extern void cwin_maximize(void);
  104. /*
  105. * Rather than using putchar() and printf(), here are the calls
  106. * the can be made to get output onto the screen. NOTE that cwin_puts()
  107. * is more like fputs than puts in that it just dumps the characters in its
  108. * string to the screen [it does not add an extra newline in the way that
  109. * puts does].
  110. * These functions support printable ASCII characters.
  111. * I have not thought too hard about TAB and FormFeed here... yet.
  112. * Some control codes may be used to change fonts and colours, but at
  113. * present I will not document that here.
  114. */
  115. extern void cwin_putchar(int c);
  116. extern void cwin_puts(const char *s);
  117. extern void
  118. #ifdef _MSC_VER
  119. __cdecl
  120. #endif
  121. cwin_printf(const char *fmt, ...);
  122. extern void cwin_vfprintf(const char *fmt, va_list a);
  123. /*
  124. * cwin_linelength holds the number of normal-sized (ie the basic
  125. * fixed-pitch font being used) characters that fit across the screen.
  126. * Its value can change at any time. When the screen is minimized its value
  127. * will remain at the pre-minimized value. An attempt is made to create
  128. * the initial window to make this have the value 80.
  129. */
  130. extern int cwin_linelength;
  131. #ifdef SOMETIME_LATER_ON
  132. /* Transliteration between Roman and Greek alphabets */
  133. extern char latinOf[26];
  134. #endif /* SOMETIME_LATER_ON */
  135. /*
  136. * ensure_screen() causes the display to catch up with whatever else has
  137. * been going on.
  138. */
  139. extern void cwin_ensure_screen(void);
  140. /*
  141. * cwin_getchar() behaves rather as one might expect getchar() to - it
  142. * grabs a character from the keyboard input buffer.
  143. */
  144. extern int cwin_getchar(void);
  145. /*
  146. * cwin_getchar_nowait() is just like cwin_getchar() except that if
  147. * no character is immediately available it returns EOF instead of
  148. * waiting.
  149. */
  150. extern int cwin_getchar_nowait(void);
  151. /*
  152. * If any characters had already been typed and were waiting to be
  153. * read, this abandons them.
  154. */
  155. extern void cwin_discard_input(void);
  156. /*
  157. * cwin_set_prompt() tells cwin what string (of up to 32 characters)
  158. * should be used as a prompt.
  159. */
  160. extern void cwin_set_prompt(const char *s);
  161. /*
  162. * The following is just for use by REDUCE. It adjusts menu entries
  163. * to support loading packages and setting/clearing REDUCE switches.
  164. */
  165. extern void cwin_menus(char **modules, char **switches);
  166. /*
  167. * cwin_interrupt_pending can be set by the "interrupt" menu and is intended
  168. * to be used to halt calculations in the main program. It gets set to 1
  169. * on "INTERRUPT" and to 3 on "BACKTRACE".
  170. */
  171. extern int cwin_interrupt_pending;
  172. /*
  173. * Short messages can be displayed at the left middle and right of the
  174. * main title-ribbon of your window. These functions set the text to be
  175. * displayed there. If there is not much room then only the middle one
  176. * will remain visible. Each message should be limited to around 30 chars
  177. * (and will be best if kept shorter than that). The default position was
  178. * once that the left position displayed the time & date (but it is
  179. * now left blank), the middle one the name of the program being run and
  180. * the right one is blank. cwin_report_left(NULL) or cwin_report_mid(NULL)
  181. * re-instate the default display. Use cwin_report_left("") is a yet clearer
  182. * way of indicating that blank info to the left is required.
  183. */
  184. extern void cwin_report_left(const char *msg);
  185. extern void cwin_report_mid(const char *msg);
  186. extern void cwin_report_right(const char *msg);
  187. /*
  188. * The following four strings may be updated (but PLEASE keep within the
  189. * length limit) to make the display in the "ABOUT" box reflect your
  190. * particular application.
  191. */
  192. extern char about_box_title[32]; /* "About XXX"; */
  193. extern char about_box_description[32]; /* "XXX version 1.1"; */
  194. /* <icon appears here> */
  195. extern char about_box_rights_1[32]; /* "Copyright Whoever"; */
  196. extern char about_box_rights_2[32]; /* "Date or whatever"; */
  197. /*
  198. * The HELP drop-down menu in cwin always has some basic items on it, but
  199. * the user can add more by calling cwin_setHelpFile() where arg 1 is the
  200. * text to appear on the menu and arg 2 identifies the help file that will be
  201. * opened if the menu item is selected. Specifying NULL as the second item
  202. * removes the key. The information about help keys is kept in the registry
  203. * not in any file that CSL has direct access to, and the new help items may
  204. * not be visible until the user exits from CSL and re-starts it.
  205. */
  206. extern void cwin_set_help_file(const char *key, const char *path);
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. #endif /* header_cwin_h */
  211. /* end of "cwin.h" */