cwin.h 8.6 KB

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