1 /* Copyright (C) 1996, 2001, Ghostgum Software Pty Ltd. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 18 /* $Id: dwtext.h,v 1.7 2002/02/21 22:24:51 giles Exp $ */ 19 /* Text Window class */ 20 21 #ifndef dwtext_INCLUDED 22 # define dwtext_INCLUDED 23 24 25 #ifdef _WINDOWS 26 #define _Windows 27 #endif 28 29 30 typedef struct TEXTWINDOW_S { 31 const char *Title; /* required */ 32 HICON hIcon; /* optional */ 33 BYTE *ScreenBuffer; 34 POINT ScreenSize; /* optional */ 35 char *DragPre; /* optional */ 36 char *DragPost; /* optional */ 37 int nCmdShow; /* optional */ 38 39 HWND hwnd; 40 41 BYTE *KeyBuf; 42 BYTE *KeyBufIn; 43 BYTE *KeyBufOut; 44 unsigned int KeyBufSize; 45 BOOL quitnow; 46 47 char line_buf[256]; 48 int line_end; 49 int line_start; 50 BOOL line_complete; 51 BOOL line_eof; 52 53 BOOL bFocus; 54 BOOL bGetCh; 55 56 char *fontname; /* font name */ 57 int fontsize; /* font size in pts */ 58 59 HFONT hfont; 60 int CharAscent; 61 62 int CaretHeight; 63 int CursorFlag; 64 POINT CursorPos; 65 POINT ClientSize; 66 POINT CharSize; 67 POINT ScrollPos; 68 POINT ScrollMax; 69 70 int x, y, cx, cy; /* window position */ 71 } TW; 72 73 74 /* Create new TW structure */ 75 TW *text_new(void); 76 77 /* Destroy window and TW structure */ 78 void text_destroy(TW *tw); 79 80 /* test if a key has been pressed 81 * return TRUE if key hit 82 * return FALSE if no key 83 */ 84 int text_kbhit(TW *tw); 85 86 /* Get a character from the keyboard, waiting if necessary */ 87 int getch(void); 88 89 /* Get a line from the keyboard 90 * store line in buf, with no more than len characters 91 * including null character 92 * return number of characters read 93 */ 94 int text_gets(TW *tw, char *buf, int len); 95 96 /* Get a line from the keyboard 97 * store line in buf, with no more than len characters 98 * line is not null terminated 99 * return number of characters read 100 */ 101 int text_read_line(TW *tw, char *buf, int len); 102 103 /* Put a character to the window */ 104 int text_putch(TW *tw, int ch); 105 106 /* Write cnt character from buf to the window */ 107 void text_write_buf(TW *tw, const char *buf, int cnt); 108 109 /* Put a string to the window */ 110 void text_puts(TW *tw, const char *str); 111 112 /* Scroll window to make cursor visible */ 113 void text_to_cursor(TW *tw); 114 115 /* register window class */ 116 int text_register_class(TW *tw, HICON hicon); 117 118 /* Create and show window with given name and min/max/normal state */ 119 /* return 0 on success, non-zero on error */ 120 int text_create(TW *tw, const char *title, int cmdShow); 121 122 /* Set window font and size */ 123 /* a must choose monospaced */ 124 void text_font(TW *tw, const char *fontname, int fontsize); 125 126 /* Set screen size in characters */ 127 void text_size(TW *tw, int width, int height); 128 129 /* Set and get the window position and size */ 130 void text_setpos(TW *tw, int x, int y, int cx, int cy); 131 int text_getpos(TW *tw, int *px, int *py, int *pcx, int *pcy); 132 133 /* Set pre drag and post drag strings 134 * If a file is dropped on the window, the following will 135 * be poked into the keyboard buffer: 136 * the pre_drag string 137 * the file name 138 * the post_drag string 139 */ 140 void text_drag(TW *tw, const char *pre_drag, const char *post_drag); 141 142 /* provide access to window handle */ 143 HWND text_get_handle(TW *tw); 144 145 /* ================================== */ 146 147 148 #endif /* dwtext_INCLUDED */ 149