1 /* Copyright (C) 1996, 2001, Ghostgum Software Pty Ltd.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17  */
18 
19 
20 /* $Id: dwtext.h,v 1.4.2.2.2.1 2003/01/17 00:49:00 giles Exp $ */
21 /* Text Window class */
22 
23 #ifndef dwtext_INCLUDED
24 #  define dwtext_INCLUDED
25 
26 #ifdef _WINDOWS
27 #define _Windows
28 #endif
29 
30 
31 typedef struct TEXTWINDOW_S {
32     const char *Title;		/* required */
33     HICON hIcon;		/* optional */
34     BYTE *ScreenBuffer;
35     POINT ScreenSize;		/* optional */
36     char *DragPre;		/* optional */
37     char *DragPost;		/* optional */
38     int nCmdShow;		/* optional */
39 
40     HWND hwnd;
41 
42     BYTE *KeyBuf;
43     BYTE *KeyBufIn;
44     BYTE *KeyBufOut;
45     unsigned int KeyBufSize;
46     BOOL quitnow;
47 
48     char line_buf[256];
49     int line_end;
50     int line_start;
51     BOOL line_complete;
52     BOOL line_eof;
53 
54     BOOL bFocus;
55     BOOL bGetCh;
56 
57     char *fontname;	/* font name */
58     int fontsize;	/* font size in pts */
59 
60     HFONT hfont;
61     int CharAscent;
62 
63     int CaretHeight;
64     int CursorFlag;
65     POINT CursorPos;
66     POINT ClientSize;
67     POINT CharSize;
68     POINT ScrollPos;
69     POINT ScrollMax;
70 
71     int x, y, cx, cy;	/* window position */
72 } TW;
73 
74 
75 /* Create new TW structure */
76 TW *text_new(void);
77 
78 /* Destroy window and TW structure */
79 void text_destroy(TW *tw);
80 
81 /* test if a key has been pressed
82  * return TRUE if key hit
83  * return FALSE if no key
84  */
85 int text_kbhit(TW *tw);
86 
87 /* Get a character from the keyboard, waiting if necessary */
88 int getch(void);
89 
90 /* Get a line from the keyboard
91  * store line in buf, with no more than len characters
92  * including null character
93  * return number of characters read
94  */
95 int text_gets(TW *tw, char *buf, int len);
96 
97 /* Get a line from the keyboard
98  * store line in buf, with no more than len characters
99  * line is not null terminated
100  * return number of characters read
101  */
102 int text_read_line(TW *tw, char *buf, int len);
103 
104 /* Put a character to the window */
105 int text_putch(TW *tw, int ch);
106 
107 /* Write cnt character from buf to the window */
108 void text_write_buf(TW *tw, const char *buf, int cnt);
109 
110 /* Put a string to the window */
111 void text_puts(TW *tw, const char *str);
112 
113 /* Scroll window to make cursor visible */
114 void text_to_cursor(TW *tw);
115 
116 /* register window class */
117 int text_register_class(TW *tw, HICON hicon);
118 
119 /* Create and show window with given name and min/max/normal state */
120 /* return 0 on success, non-zero on error */
121 int text_create(TW *tw, const char *title, int cmdShow);
122 
123 /* Set window font and size */
124 /* a must choose monospaced */
125 void text_font(TW *tw, const char *fontname, int fontsize);
126 
127 /* Set screen size in characters */
128 void text_size(TW *tw, int width, int height);
129 
130 /* Set and get the window position and size */
131 void text_setpos(TW *tw, int x, int y, int cx, int cy);
132 int text_getpos(TW *tw, int *px, int *py, int *pcx, int *pcy);
133 
134 /* Set pre drag and post drag strings
135  * If a file is dropped on the window, the following will
136  * be poked into the keyboard buffer:
137  *   the pre_drag string
138  *   the file name
139  *   the post_drag string
140  */
141 void text_drag(TW *tw, const char *pre_drag, const char *post_drag);
142 
143 /* provide access to window handle */
144 HWND text_get_handle(TW *tw);
145 
146 /* ================================== */
147 
148 #endif /* dwtext_INCLUDED */
149