source: vendor/emx/current/src/pmgdb/pmtty.cc

Last change on this file was 18, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.9 KB
Line 
1/* pmtty.cc
2 Copyright (c) 1996 Eberhard Mattes
3
4This file is part of pmgdb.
5
6pmgdb is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11pmgdb is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with pmgdb; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21
22// TODO: jump to end on input
23
24#define INCL_DOS
25#define INCL_WIN
26#include <os2.h>
27#include <stdlib.h>
28#include <string.h>
29#include "string.h"
30#include "pmapp.h"
31#include "pmframe.h"
32#include "pmtxt.h"
33#include "pmtty.h"
34
35
36#define IDT_CURSOR 1
37
38pmtty::pmtty (pmapp *in_app, unsigned in_id, ULONG frame_flags,
39 const SWP *pswp, const char *fontnamesize)
40 : pmtxt (in_app, in_id, frame_flags, pswp, fontnamesize)
41{
42 x = 0; y = 0;
43 line_width = max_line_len;
44 cursor_enabled = false; cursor_painted = false; cursor_hidden = 0;
45 sel_attr = get_default_attr ();
46 create_hpsCursor ();
47 cursor_width = (int)WinQuerySysValue (HWND_DESKTOP, SV_CXBORDER);
48}
49
50
51pmtty::~pmtty ()
52{
53}
54
55
56void pmtty::set_line_width (int width)
57{
58 if (width > max_line_len)
59 width = max_line_len;
60 if (x >= width)
61 puts ("\n", 1);
62 line_width = width;
63}
64
65
66void pmtty::create_hpsCursor ()
67{
68 hpsCursor = WinGetPS (get_hwndClient ());
69 set_font (hpsCursor);
70}
71
72
73
74// Roll our own cursor because a cursor created with WinCreateCursor
75// can be hidden and destroyed only by the thread which created it.
76
77void pmtty::paint_cursor ()
78{
79 POINTL ptl;
80
81 if (get_bbox_pos (hpsCursor, &ptl, y, x))
82 {
83 // TODO: Nicer cursor (WinDrawPointer?)
84 rclCursor.xLeft = ptl.x;
85 rclCursor.xRight = rclCursor.xLeft + cursor_width;
86 rclCursor.yBottom = ptl.y;
87 rclCursor.yTop = rclCursor.yBottom + get_cyChar ();
88 WinInvertRect (hpsCursor, &rclCursor);
89 cursor_painted = true;
90 }
91}
92
93
94void pmtty::remove_cursor ()
95{
96 WinInvertRect (hpsCursor, &rclCursor);
97 cursor_painted = false;
98}
99
100
101inline void pmtty::cursor_on ()
102{
103 if (--cursor_hidden == 0 && cursor_enabled && !cursor_painted
104 && WinQueryFocus (HWND_DESKTOP) == get_hwndClient ())
105 paint_cursor ();
106}
107
108
109inline void pmtty::cursor_off ()
110{
111 if (++cursor_hidden == 1 && cursor_enabled && cursor_painted)
112 remove_cursor ();
113}
114
115
116void pmtty::puts1 (const char *s, size_t len)
117{
118 while (x + (int)len >= line_width)
119 {
120 size_t n = line_width - x;
121 put (y, x, n, s, sel_attr, true);
122 x = 0; ++y;
123 s += n; len -= n;
124 }
125 if (len != 0)
126 {
127 put (y, x, len, s, sel_attr, true);
128 x += len;
129 }
130}
131
132
133void pmtty::puts (const char *s, size_t len)
134{
135 if (len == 0)
136 return;
137 cursor_off ();
138 while (len != 0)
139 {
140 size_t i;
141 for (i = 0; i < len; ++i)
142 if (s[i] == '\n' || s[i] == '\t')
143 break;
144 if (i >= len)
145 {
146 puts1 (s, len);
147 break;
148 }
149 if (i != 0)
150 puts1 (s, i);
151 if (s[i] == '\t')
152 {
153 int tab_width = (x | 7) + 1 - x;
154 puts1 (" ", tab_width);
155 }
156 else
157 {
158 x = 0; ++y;
159 }
160 len -= i + 1; s += i + 1;
161 }
162 if (x == 0)
163 put (y, x, 0, "", sel_attr, true);
164 // TODO: Optionally scroll horizontally/vertically to make cursor visible
165 cursor_on ();
166}
167
168
169class pmtty_const_str
170{
171public:
172 char *str;
173 pmtty_const_str (char c, size_t len)
174 {
175 str = new char[len + 1];
176 memset (str, c, len);
177 str[len] = 0;
178 }
179};
180
181
182static pmtty_const_str spaces (' ', pmtxt::max_line_len);
183
184void pmtty::backspace (int n)
185{
186 if (n > x)
187 n = x;
188 if (n > 0)
189 {
190 x -= n;
191 cursor_off ();
192 put (y, x, n, spaces.str, sel_attr, true);
193 cursor_on ();
194 }
195}
196
197
198void pmtty::cursor (bool on)
199{
200 if (on && !cursor_enabled)
201 {
202 cursor_enabled = true;
203 if (cursor_hidden == 0
204 && WinQueryFocus (HWND_DESKTOP) == get_hwndClient ())
205 paint_cursor ();
206 // TODO: Restart timer when SV_CURSORRATE is changed
207 WinStartTimer (get_hab (), get_hwndClient (), IDT_CURSOR,
208 WinQuerySysValue (HWND_DESKTOP, SV_CURSORRATE));
209 }
210 else if (!on && cursor_enabled)
211 {
212 WinStopTimer (get_hab(), get_hwndClient (), IDT_CURSOR);
213 cursor_enabled = false;
214 if (cursor_painted)
215 remove_cursor ();
216 }
217}
218
219
220MRESULT pmtty::wm_setfocus (HWND, ULONG, MPARAM, MPARAM mp2)
221{
222 if (SHORT1FROMMP (mp2))
223 {
224 if (cursor_enabled && cursor_hidden == 0 && !cursor_painted)
225 paint_cursor ();
226 }
227 else
228 {
229 if (cursor_painted)
230 remove_cursor ();
231 }
232 return 0;
233}
234
235
236MRESULT pmtty::wm_timer (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
237{
238 if (SHORT1FROMMP (mp1) == IDT_CURSOR)
239 {
240 if (cursor_painted)
241 remove_cursor ();
242 else if (cursor_enabled && cursor_hidden == 0
243 && WinQueryFocus (HWND_DESKTOP) == get_hwndClient ())
244 paint_cursor ();
245 return FALSE;
246 }
247 else
248 return WinDefWindowProc (hwnd, msg, mp1, mp2);
249}
250
251
252MRESULT pmtty::wm_presparamchanged (HWND hwnd, ULONG msg,
253 MPARAM mp1, MPARAM mp2)
254{
255 parent::wm_presparamchanged (hwnd, msg, mp1, mp2);
256 if (LONGFROMMP (mp1) == PP_FONTNAMESIZE && !get_initializing_font ())
257 {
258 WinReleasePS (hpsCursor);
259 create_hpsCursor ();
260 }
261 return 0;
262}
263
264
265void pmtty::font_changed ()
266{
267 set_font (hpsCursor);
268}
269
270
271void pmtty::painting (bool start)
272{
273 if (start)
274 cursor_off ();
275 else
276 cursor_on ();
277}
278
279
280void pmtty::delete_all ()
281{
282 cursor_off ();
283 x = 0; y = 0;
284 parent::delete_all ();
285}
286
287
288bool pmtty::get_xy (POINTL *ptl)
289{
290 return get_bbox_pos (hpsCursor, ptl, y, x);
291}
Note: See TracBrowser for help on using the repository browser.