1 /* $Id: ttyctrl.cpp,v 1.9 2001/05/25 15:59:07 amura Exp $ */
2 /* OS dependent code used by Ng for WinCE.
3 * Copyright (C) 1998 Eiichiro Ito
4 * Modified for Ng for Win32
5 * Copyright (C) 1999,2000 Toru Imai
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * ree Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 /*
23 * $Log: ttyctrl.cpp,v $
24 * Revision 1.9 2001/05/25 15:59:07 amura
25 * WIN32 version support AUTOSAVE feature
26 *
27 * Revision 1.8 2001/01/05 14:07:09 amura
28 * first implementation of Hojo Kanji support
29 *
30 * Revision 1.7 2000/11/16 14:21:31 amura
31 * merge Ng for win32 0.5
32 *
33 * Revision 1.6 2000/10/23 16:52:51 amura
34 * add GPL copyright to header
35 *
36 * Revision 1.5 2000/09/21 17:19:30 amura
37 * TtyView::PutLine is replaced by old code for speed reason
38 *
39 * Revision 1.4 2000/07/24 15:34:55 amura
40 * rewrite PutLine()
41 *
42 * Revision 1.3 2000/07/22 20:46:33 amura
43 * support "Drag&Drop"
44 *
45 * Revision 1.2 2000/07/18 12:42:33 amura
46 * support IME convertion on the spot
47 *
48 * Revision 1.1.1.1 2000/06/27 01:48:00 amura
49 * import to CVS
50 *
51 */
52
53 #include "config.h"
54 #include <windows.h>
55 #include <windowsx.h>
56 #include <commctrl.h>
57 #include "def.h"
58 #include "ttyctrl.h"
59 #include "tools.h"
60 #include "resource.h"
61 #if defined(KANJI) && defined(USE_KCTRL)
62 #include "kctrl.h"
63 #include "cefep.h"
64 #endif
65 #ifndef USE_KCTRL
66 #define CONFIG_FONT
67 #endif
68
69 #ifdef KANJI
70 #ifndef SHIFTJIS_CHARSET
71 #define SHIFTJIS_CHARSET 128
72 #endif
73 #endif
74
75 #define is_kanji(x) (((x)>=0x81 && (x)<=0x9F)||((x)>=0xE0 && (x)<=0xFC))
76 #define MAX_KEYBUF 256
77 #define MAX_WINEVENTBUF 32
78 #ifdef DROPFILES /* 00.07.07 by sahf */
79 #define MAX_DROPBUF 32
80 #endif /* DROPFILES */
81
82 #ifdef KANJI
83 #ifndef USE_KCTRL
84 #define DEFAULT_HMARGIN 2
85 #define PUTLINE_ADJUSTMENT 0
86 #else /* if USE_KCTRL */
87 #define DEFAULT_HMARGIN 1
88 #define PUTLINE_ADJUSTMENT 1
89 #endif /* USE_KCTRL */
90 #else /* if !KANJI */
91 #define DEFAULT_POINT 9
92 #define DEFAULT_HMARGIN 0
93 #define PUTLINE_ADJUSTMENT 1
94 #endif /* !KANJI */
95
96 #ifndef USE_KCTRL
97 static LOGFONT lfont = {
98 #ifdef KANJI
99 #if 0
100 14, 7, 0, 0, 0x190, 0x00, 0x00, 0x00, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS,
101 CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FF_MODERN | FIXED_PITCH,
102 // {0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x0000}
103 TEXT("")
104 #else /* if !0 */
105 12, 6, 0, 0, 0x0, 0x00, 0x00, 0x00, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS,
106 CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FF_MODERN | FIXED_PITCH,
107 // {0xFF2D, 0xFF33, 0x0020, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x0000}
108 TEXT("")
109 #endif /* !0 */
110 #else /* if !KANJI */
111 12, 6, 0, 0, 0x0, 0x00, 0x00, 0x00, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
112 CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FF_MODERN | FIXED_PITCH,
113 #ifdef _WIN32_WCE
114 TEXT("Courier New")
115 #else /* if !_WIN32_WCE */
116 TEXT("")
117 #endif /* !_WIN32_WCE */
118 #endif /* !KANJI */
119 };
120 #endif /* !USE_KCTRL */
121
122 #if !defined(KANJI) || !defined(USE_KCTRL)
123 #define GetFontH() (lfont.lfHeight + 1)
124 #define GetFontHW() (lfont.lfWidth)
125 #define KDrawText(hdc, str, len, rect, f) do { HFONT hOldFont; \
126 hOldFont = (HFONT)SelectObject(hdc, m_hFont); \
127 DrawText(hdc, str, len, rect, (DT_NOPREFIX | DT_LEFT | DT_EXPANDTABS)); \
128 SelectObject(hdc, hOldFont); } while (0/*CONSTCOND*/)
129 #endif
130
131 class TtyView {
132 protected:
133 HWND m_hwnd ; /* Window handle of this control */
134 HWND m_hwndParent ; /* Parent window of the control */
135 WORD m_idCtrl ; /* Id of the control */
136 DWORD m_dwCols ; /* Number of columns in a line */
137 DWORD m_dwLines ; /* Number of lines in a screen */
138 DWORD m_dwHMargin ; /* Virtical margin */
139 DWORD m_dwFontW ; /* Font width */
140 DWORD m_dwFontH ; /* Font height */
141 DWORD m_dwTabSize ; /* TAB size */
142
143 HBITMAP m_bmpScreen ; /* Screen image */
144 RECT m_rcInvalidate ; /* RECT drawn by PutChar */
145 DWORD m_dwCurCol ; /* cursor column */
146 DWORD m_dwCurLine ; /* cursor row */
147 DWORD m_dwCurH ; /* Height of cursor */
148 DWORD m_dwLastCurWidth ; /* Width of cursor */
149 DWORD m_dwLastCurX ; /* Cursor horizontal position */
150 DWORD m_dwLastCurY ; /* Cursor virtical position */
151
152 HANDLE m_hevtKey ; /* Key input event */
153 WORD m_szKeyBuf[ MAX_KEYBUF ] ; /* Key input buffer */
154 DWORD m_dwKeyIn ; /* Key input point */
155 DWORD m_dwKeyOut ; /* Key output point */
156 int m_szWinEventBuf[MAX_WINEVENTBUF]; /* Window Event buffer */
157 DWORD m_dwWinEventOut; /* Window Event output pointer */
158 DWORD m_dwWinEventIn; /* Window Event input pointer */
159 #ifdef DROPFILES /* 00.07.07 by sahf */
160 HLOCAL m_szDropBuf[ MAX_DROPBUF ] ; /* Drag And Drop Infos */
161 int m_iDropLine[ MAX_DROPBUF ] ; /* Drag and Drop point saver */
162 DWORD m_dwDropIn ;
163 DWORD m_dwDropOut ;
164 #endif /* DROPFILES */
165 HFONT m_hFont; /* handle for font */
166 DWORD m_keyboardlocale; /* Keyboard locale */
167
168 #ifdef DROPFILES /* 00.07.07 by sahf */
169 int GetDropFiles( HLOCAL *lphMemory ) ;
170 #endif /* DROPFILES */
171 void SetupEvent( HANDLE hEvent ) ;
172 void ClearScreen() ;
173 void PutChar( BYTE c ) ;
174 void PutKChar( BYTE c1, BYTE c2 ) ;
175 void GotoXY( WORD x, WORD y ) ;
176 void EraseEOL() ;
177 void EraseEOP() ;
178 void PutLine( WORD y, WORD color, LPCSTR sjis ) ;
179 void Flush() ;
180 BOOL Kbhit() const ;
181 int GetChar() ;
182 DWORD GetWH() const ;
183 void AddMetaChar( TCHAR c ) ;
184 void AddChar( TCHAR c ) ;
185 void Command(WPARAM, LPARAM);
186 void SetKeyboardLocale(DWORD val);
187
188 void ShowCursor(void);
189 void HideCursor(void);
190 void ResetContent() ;
191 int GetWindowEvent(void);
192 void AddWindowEvent(int);
193 #ifndef USE_KCTRL
194 void SetFontValues(LOGFONT *, HDC);
195 #endif
196 void AdjustScreen(HWND, HDC);
197
198 public:
199 TtyView() ;
200 ~TtyView() ;
201
Create()202 BOOL Create() { return FALSE ; }
203
204 #ifdef DROPFILES /* 00.07.07 by sahf */
205 void WMDropFiles( HDROP hDrop ) ;
206 #endif /* DROPFILES */
207 void WMCreate( HWND hWnd, LPCREATESTRUCT lpcs ) ;
208 void WMPaint() ;
209 LRESULT WMCommand( HWND hWnd, UINT msg, WPARAM wp, LPARAM lp ) ;
210 BOOL WMCopydata( PCOPYDATASTRUCT cds ) ;
211 BOOL WMSysChar( TCHAR c, LONG keydata ) ;
212 void WMChar( TCHAR c, LONG keydata ) ;
213 BOOL WMKeyDown( int nVirtKey, LONG lKeyData ) ;
214 void WMMouseDown( WPARAM wParam, LPARAM lParam ) ;
215 void WMSize( DWORD fwSize, WORD nWidth, WORD nHeight ) ;
216 BOOL WMCopy(void) ;
217 void WMLButtonDown(int x, int y);
218 void WMSetFocus(void);
219 void WMKillFocus(void);
220
221 void SetTab( DWORD wParam, BOOL bUpdate ) ;
222 void SetHMargin( DWORD wParam, BOOL bUpdate ) ;
223 #ifdef CONFIG_FONT
224 void FontChanged(void);
225 #endif
226
227 friend LRESULT CALLBACK
228 TtyViewWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) ;
229 } ;
230 typedef TtyView *PTtyView ;
231
TtyView()232 TtyView::TtyView()
233 {
234 m_dwCols = 0 ;
235 m_dwLines = 0 ;
236 m_dwHMargin = DEFAULT_HMARGIN;
237 m_dwFontW = GetFontHW() ;
238 m_dwFontH = GetFontH() + m_dwHMargin ;
239 m_dwTabSize = 8 ;
240
241 m_bmpScreen = 0 ;
242 SetRectEmpty( &m_rcInvalidate ) ;
243 m_dwCurCol = 0 ;
244 m_dwCurLine = 0 ;
245 m_dwCurH = GetFontH() ;
246 m_dwLastCurWidth = 0 ;
247 m_dwLastCurX = 0 ;
248 m_dwLastCurY = 0 ;
249
250 m_hevtKey = 0 ;
251 m_dwKeyIn = 0 ;
252 m_dwKeyOut = 0 ;
253 m_dwWinEventIn = m_dwWinEventOut = 0;
254 #ifdef DROPFILES /* 00.07.07 by sahf */
255 m_dwDropIn = m_dwDropOut = 0;
256 #endif /* DROPFILES */
257
258 m_hFont = (HFONT)0;
259 }
260
~TtyView()261 TtyView::~TtyView()
262 {
263 if ( m_bmpScreen ) {
264 DeleteObject( m_bmpScreen ) ;
265 m_bmpScreen = 0 ;
266 }
267 if (m_hFont) {
268 DeleteObject(m_hFont);
269 m_hFont = (HFONT)0;
270 }
271 }
272
273 /*
274 * Clear screen buffer
275 */
276 void
ClearScreen()277 TtyView::ClearScreen()
278 {
279 RECT rect ;
280 HGDIOBJ hOldObj ;
281 HDC hDC, hdcBmp ;
282
283 HideCursor();
284 GetClientRect( m_hwnd, &rect ) ;
285 hDC = GetDC( m_hwnd ) ;
286 hdcBmp = CreateCompatibleDC( hDC ) ;
287 hOldObj = SelectObject( hdcBmp, m_bmpScreen ) ;
288 FillRect( hdcBmp, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
289 FillRect( hDC, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
290 SelectObject( hdcBmp, hOldObj ) ;
291 DeleteDC( hdcBmp ) ;
292 ReleaseDC( m_hwnd, hDC ) ;
293 ShowCursor();
294 }
295
296 void
SetupEvent(HANDLE hEvent)297 TtyView::SetupEvent( HANDLE hEvent )
298 {
299 m_hevtKey = hEvent ;
300 }
301
302 void
PutChar(BYTE c)303 TtyView::PutChar( BYTE c )
304 {
305 RECT rect ;
306 HGDIOBJ hOldObj ;
307 HDC hDC, hdcBmp ;
308 TCHAR unicode[ 2 ] ;
309
310 if ( c == '\b' ) {
311 if ( m_dwCurCol )
312 GotoXY( (WORD) (m_dwCurCol - 1), (WORD) m_dwCurLine ) ;
313 return ;
314 }
315 rect.left = m_dwCurCol * m_dwFontW ;
316 rect.top = m_dwCurLine * m_dwFontH ;
317 rect.right = rect.left + m_dwFontW - 1 ;
318 rect.bottom = rect.top + m_dwFontH - 1 ;
319 unicode[0] = sjis2unicode_char( c ) ;
320 unicode[1] = 0 ;
321
322 HideCursor();
323 hDC = GetDC( m_hwnd ) ;
324 hdcBmp = CreateCompatibleDC( hDC ) ;
325 hOldObj = SelectObject( hdcBmp, m_bmpScreen ) ;
326
327 if ( unicode[0] == TEXT(' ') ) {
328 rect.right ++ ;
329 rect.bottom ++ ;
330 FillRect( hdcBmp, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
331 // FillRect( hDC, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
332 rect.right -- ;
333 rect.bottom -- ;
334 } else {
335 KDrawText( hdcBmp, unicode, -1, &rect, 0 ) ;
336 // BitBlt( hDC, rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1,
337 // hdcBmp, rect.left, rect.top, SRCCOPY ) ;
338 }
339 UnionRect( &m_rcInvalidate, &m_rcInvalidate, &rect ) ;
340
341 SelectObject( hdcBmp, hOldObj ) ;
342 DeleteDC( hdcBmp ) ;
343
344 m_dwCurCol ++ ;
345 if ( m_dwCurCol >= m_dwCols ) {
346 m_dwCurCol = 0 ;
347 m_dwCurLine ++ ;
348 if ( m_dwCurLine >= m_dwLines ) {
349 m_dwCurLine = 0 ;
350 }
351 }
352 ReleaseDC( m_hwnd, hDC ) ;
353 ShowCursor();
354 }
355
356 void
PutKChar(BYTE c1,BYTE c2)357 TtyView::PutKChar(BYTE c1, BYTE c2)
358 {
359 RECT rect;
360 HGDIOBJ hOldObj;
361 HDC hDC, hdcBmp;
362 TCHAR unicode[2];
363 BYTE foo[3];
364
365 rect.left = m_dwCurCol * m_dwFontW;
366 rect.top = m_dwCurLine * m_dwFontH;
367 rect.right = rect.left + (m_dwFontW * 2) - 1;
368 rect.bottom = rect.top + m_dwFontH - 1;
369
370 foo[0] = c1;
371 foo[1] = c2;
372 foo[2] = (BYTE)0;
373 sjis2unicode(foo, unicode, sizeof(unicode));
374
375 HideCursor();
376 hDC = GetDC(m_hwnd);
377 hdcBmp = CreateCompatibleDC(hDC);
378 hOldObj = SelectObject(hdcBmp, m_bmpScreen);
379
380 KDrawText(hdcBmp, unicode, -1, &rect, 0);
381
382 UnionRect(&m_rcInvalidate, &m_rcInvalidate, &rect);
383
384 SelectObject(hdcBmp, hOldObj);
385 DeleteDC(hdcBmp);
386
387 m_dwCurCol += 2;
388 if (m_dwCurCol >= m_dwCols) {
389 m_dwCurCol = 0;
390 m_dwCurLine++;
391 if (m_dwCurLine >= m_dwLines)
392 m_dwCurLine = 0;
393 }
394 ReleaseDC(m_hwnd, hDC);
395 ShowCursor();
396 }
397
398 void
GotoXY(WORD x,WORD y)399 TtyView::GotoXY( WORD x, WORD y )
400 {
401 HideCursor();
402 m_dwCurCol = x ;
403 m_dwCurLine = y ;
404 ShowCursor();
405 #if defined(FEPCTRL) && !defined(USE_KCTRL)
406 {
407 HIMC hIMC = ImmGetContext(m_hwnd);
408 if (hIMC) {
409 COMPOSITIONFORM cf;
410 cf.dwStyle = CFS_POINT;
411 cf.ptCurrentPos.x = m_dwLastCurX;
412 cf.ptCurrentPos.y = m_dwLastCurY;
413 ImmSetCompositionWindow(hIMC, &cf);
414 ImmReleaseContext(m_hwnd, hIMC);
415 }
416 }
417 #endif
418 }
419
420 BOOL
Kbhit() const421 TtyView::Kbhit() const
422 {
423 return m_dwKeyIn != m_dwKeyOut ;
424 }
425
426 void
EraseEOL()427 TtyView::EraseEOL()
428 {
429 RECT rect ;
430 HGDIOBJ hOldObj ;
431 HDC hDC, hdcBmp ;
432
433 HideCursor();
434 hDC = GetDC( m_hwnd ) ;
435 hdcBmp = CreateCompatibleDC( hDC ) ;
436 hOldObj = SelectObject( hdcBmp, m_bmpScreen ) ;
437
438 rect.left = m_dwCurCol * m_dwFontW ;
439 rect.top = m_dwCurLine * m_dwFontH ;
440 rect.right = m_dwCols * m_dwFontW ;
441 rect.bottom = rect.top + m_dwFontH ;
442 FillRect( hdcBmp, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
443 // FillRect( hDC, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
444 UnionRect( &m_rcInvalidate, &m_rcInvalidate, &rect ) ;
445
446 SelectObject( hdcBmp, hOldObj ) ;
447 DeleteDC( hdcBmp ) ;
448 ReleaseDC( m_hwnd, hDC ) ;
449 ShowCursor();
450 }
451
452 void
EraseEOP()453 TtyView::EraseEOP()
454 {
455 RECT rect ;
456 HGDIOBJ hOldObj ;
457 HDC hDC, hdcBmp ;
458
459 HideCursor();
460 hDC = GetDC( m_hwnd ) ;
461 hdcBmp = CreateCompatibleDC( hDC ) ;
462 hOldObj = SelectObject( hdcBmp, m_bmpScreen ) ;
463
464 rect.left = m_dwCurCol * m_dwFontW ;
465 rect.top = m_dwCurLine * m_dwFontH ;
466 rect.right = m_dwCols * m_dwFontW ;
467 rect.bottom = rect.top + m_dwFontH ;
468 if ( !IsRectEmpty( &rect ) ) {
469 FillRect( hdcBmp, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
470 FillRect( hDC, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
471 }
472 rect.left = 0 ;
473 rect.top = (m_dwCurLine + 1) * m_dwFontH ;
474 rect.right = m_dwCols * m_dwFontW ;
475 rect.bottom = m_dwLines * m_dwFontH ;
476 if ( !IsRectEmpty( &rect ) ) {
477 FillRect( hdcBmp, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
478 FillRect( hDC, &rect, (HBRUSH) GetStockObject( WHITE_BRUSH ) ) ;
479 }
480
481 SelectObject( hdcBmp, hOldObj ) ;
482 DeleteDC( hdcBmp ) ;
483 ReleaseDC( m_hwnd, hDC ) ;
484 ShowCursor();
485 }
486
487 void
PutLine(WORD y,WORD color,LPCSTR sjis)488 TtyView::PutLine( WORD y, WORD color, LPCSTR sjis )
489 {
490 RECT rect ;
491 HGDIOBJ hOldObj ;
492 HDC hDC, hdcBmp ;
493 TCHAR unicode[ 256 ] ;
494 HideCursor();
495 hDC = GetDC( m_hwnd ) ;
496 hdcBmp = CreateCompatibleDC( hDC ) ;
497 hOldObj = SelectObject( hdcBmp, m_bmpScreen ) ;
498
499 rect.left = 0 ;
500 rect.top = y * m_dwFontH ;
501 rect.right = m_dwCols * m_dwFontW - 1 ;
502 rect.bottom = rect.top + m_dwFontH - 1 ;
503 sjis2unicode( (LPBYTE) sjis, unicode, sizeof unicode ) ;
504 KDrawText( hdcBmp, unicode, -1, &rect, 0 ) ;
505 if ( color ) {
506 PatBlt(hdcBmp,
507 rect.left, rect.top, rect.right - rect.left,
508 m_dwCurH - PUTLINE_ADJUSTMENT, PATINVERT);
509 }
510 BitBlt( hDC, rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1,
511 hdcBmp, rect.left, rect.top, SRCCOPY ) ;
512
513 SelectObject( hdcBmp, hOldObj ) ;
514 DeleteDC( hdcBmp ) ;
515 ReleaseDC( m_hwnd, hDC ) ;
516 ShowCursor();
517 }
518
519 void
Flush()520 TtyView::Flush()
521 {
522 if ( !IsRectEmpty( &m_rcInvalidate ) ) {
523 InvalidateRect( m_hwnd, &m_rcInvalidate, TRUE ) ;
524 // UpdateWindow( m_hwnd ) ;
525 SetRectEmpty( &m_rcInvalidate ) ;
526 }
527 }
528
529 /*
530 * Get one character
531 */
532 int
GetChar()533 TtyView::GetChar()
534 {
535 WORD c;
536
537 if (m_dwKeyIn == m_dwKeyOut)
538 return -1;
539
540 c = m_szKeyBuf[m_dwKeyOut];
541 m_dwKeyOut = (m_dwKeyOut + 1) % MAX_KEYBUF;
542 return (int) c;
543 }
544
545 DWORD
GetWH() const546 TtyView::GetWH() const
547 {
548 return MAKELONG( m_dwLines, m_dwCols ) ;
549 }
550
551 /* To process the commands which corresponds to push buttons on
552 the main window of MG */
553 void
Command(WPARAM wparam,LPARAM lparam)554 TtyView::Command(WPARAM wparam, LPARAM lparam)
555 {
556 switch (LOWORD(wparam)) {
557 case IDC_PRIOR:
558 AddMetaChar(TEXT('V'));
559 break;
560
561 case IDC_NEXT:
562 AddChar(TEXT('V') - TEXT('@'));
563 break;
564
565 case IDC_MARK:
566 AddChar(TEXT('@') - TEXT('@'));
567 break;
568
569 case IDC_CUT:
570 AddChar(TEXT('W') - TEXT('@'));
571 break;
572
573 case IDC_COPY:
574 AddMetaChar(TEXT('W'));
575 break;
576
577 case IDC_PASTE:
578 AddChar(TEXT('Y') - TEXT('@'));
579 break;
580
581 case IDC_CLOSE:
582 AddChar(TEXT('X') - TEXT('@'));
583 AddChar(TEXT('C') - TEXT('@'));
584 break;
585
586 default:
587 break;
588 }
589 }
590
591 void
AddMetaChar(TCHAR c)592 TtyView::AddMetaChar( TCHAR c )
593 {
594 DWORD next1 ;
595
596 next1 = (m_dwKeyIn + 1) % MAX_KEYBUF ;
597 if ( next1 == m_dwKeyOut ) {
598 return ;
599 }
600 #ifdef DO_METAKEY
601 m_szKeyBuf[ m_dwKeyIn ] = METABIT | (c % METABIT) ;
602 m_dwKeyIn = next1 ;
603 if ( m_hevtKey ) {
604 ::SetEvent( m_hevtKey ) ;
605 }
606 #else /* if !DO_METAKEY */
607 AddChar('\033'); /* ESC */
608 AddChar(c);
609 #endif
610 }
611
612 void
AddChar(TCHAR c)613 TtyView::AddChar( TCHAR c )
614 {
615 WORD sjisChar ;
616 DWORD next1, next2 ;
617
618 sjisChar = c ? unicode2sjis_char( c ) : 0 ;
619 next1 = (m_dwKeyIn + 1) % MAX_KEYBUF ;
620 if ( next1 == m_dwKeyOut )
621 return ;
622 if ( sjisChar / 0x100 ) {
623 next2 = (m_dwKeyIn + 2) % MAX_KEYBUF ;
624 if ( next2 == m_dwKeyOut ) {
625 return ;
626 }
627 m_szKeyBuf[ m_dwKeyIn ] = sjisChar / 0x100 ;
628 m_dwKeyIn = next1 ;
629 next1 = next2 ;
630 }
631 m_szKeyBuf[ m_dwKeyIn ] = sjisChar % 0x100 ;
632 m_dwKeyIn = next1 ;
633 if ( m_hevtKey ) {
634 ::SetEvent( m_hevtKey ) ;
635 }
636 }
637
638 #ifdef DROPFILES /* 00.07.07 by sahf */
639 /*
640 * Get Drag & Drop files (from main thread)
641 */
642
643 int
GetDropFiles(HLOCAL * lphMemory)644 TtyView::GetDropFiles( HLOCAL *lphMemory )
645 {
646 int line;
647
648 if ( lphMemory == NULL )
649 return -1;
650
651 if (m_dwDropIn == m_dwDropOut)
652 return -1;
653
654 *lphMemory = m_szDropBuf[m_dwDropOut];
655 line = m_iDropLine[m_dwDropOut];
656 m_dwDropOut = (m_dwDropOut + 1) % MAX_DROPBUF;
657
658 return line;
659 }
660 #endif /* DROPFILES */
661
662 /*
663 * Put a window event onto a queue.
664 */
665
666 int
GetWindowEvent()667 TtyView::GetWindowEvent()
668 {
669 int c;
670
671 if (m_dwWinEventIn == m_dwWinEventOut) {
672 return -1 ;
673 }
674 c = m_szWinEventBuf[m_dwWinEventOut];
675 m_dwWinEventOut = (m_dwWinEventOut + 1) % MAX_WINEVENTBUF;
676 return c;
677 }
678
679 /*
680 * Get a window event from a queue.
681 */
682
683 void
AddWindowEvent(int ev)684 TtyView::AddWindowEvent(int ev)
685 {
686 DWORD next1;
687
688 next1 = (m_dwWinEventIn + 1) % MAX_WINEVENTBUF;
689 if (next1 == m_dwWinEventOut) {
690 return;
691 }
692 m_szWinEventBuf[m_dwWinEventIn] = ev;
693 m_dwWinEventIn = next1;
694 if (m_hevtKey) {
695 ::SetEvent(m_hevtKey);
696 }
697 }
698
699
700 /*---------------------------------------------------------------------*
701 * Drawing cursor
702 *---------------------------------------------------------------------*/
703 #define CARETWIDTH 2
704
705 /*
706 * Show cursor
707 */
708
709 void
ShowCursor(void)710 TtyView::ShowCursor(void)
711 {
712 if (!m_dwLastCurWidth) {
713 m_dwLastCurWidth = CARETWIDTH;
714 m_dwLastCurX = m_dwFontW * m_dwCurCol;
715 m_dwLastCurY = m_dwFontH * m_dwCurLine;
716 SetCaretPos(m_dwLastCurX, m_dwLastCurY);
717 ShowCaret(m_hwnd);
718 }
719 }
720
721 /*
722 * Hide cursor
723 */
724
725 void
HideCursor(void)726 TtyView::HideCursor(void)
727 {
728 if (m_dwLastCurWidth) {
729 m_dwLastCurWidth = 0;
730 HideCaret(m_hwnd);
731 }
732 }
733
734 void
ResetContent()735 TtyView::ResetContent()
736 {
737 ClearScreen() ;
738 }
739
740 #ifndef USE_KCTRL
741 void
SetFontValues(LOGFONT * lf,HDC hdc)742 TtyView::SetFontValues(LOGFONT *lf, HDC hdc)
743 {
744 DWORD val, point, linespace;
745 FLOAT cyDpi, cxDpi;
746 POINT pt;
747 TCHAR fontname[LF_FACESIZE];
748
749 cxDpi = (FLOAT)GetDeviceCaps(hdc, LOGPIXELSX);
750 cyDpi = (FLOAT)GetDeviceCaps(hdc, LOGPIXELSY);
751
752 val = sizeof(fontname);
753 if (RegQueryString(HKEY_CURRENT_USER, NGREGKEY, NGFONTNAMEVAL,
754 fontname, &val) == ERROR_SUCCESS) {
755 point = RegQueryDWord(HKEY_CURRENT_USER, NGREGKEY, NGFONTSIZEVAL);
756 if (point > 0) {
757 linespace = RegQueryDWord(HKEY_CURRENT_USER, NGREGKEY, NGLINESPACEVAL);
758 #ifndef KANJI
759 calcsizes:
760 #endif
761 pt.x = (int)(point * cxDpi / 72);
762 pt.y = (int)(point * cyDpi / 72);
763 #ifndef _WIN32_WCE
764 DPtoLP(hdc, &pt, 1);
765 /* What should I do for Windows CE for above? */
766 #endif
767 if (pt.y < 0) {
768 /* obtain an absolute value */
769 pt.y = -pt.y;
770 }
771 /* specify character height, not cell one */
772 lf->lfHeight = -(int)pt.y;
773 lf->lfWidth = 0;
774 lstrcpy(lf->lfFaceName, fontname);
775 m_dwHMargin = linespace;
776 return;
777 }
778 }
779
780 m_dwHMargin = DEFAULT_HMARGIN;
781 #ifdef KANJI
782 /* reset to default values */
783 lf->lfHeight = 12;
784 lf->lfWidth = 6;
785
786 lf->lfFaceName[0] = TEXT('\0');
787 #else /* if !KANJI */
788 /* reset to default values */
789 point = DEFAULT_POINT;
790 linespace = DEFAULT_HMARGIN;
791 #ifdef _WIN32_WCE
792 lstrcpy(lf->lfFaceName, TEXT("Courier New"));
793 #else /* if !_WIN32_WCE */
794 lf->lfFaceName[0] = TEXT('\0');
795 #endif /* !_WIN32_WCE */
796 goto calcsizes;
797
798 #endif /* !KANJI */
799 }
800 #endif /* !USE_KCTRL */
801
802 void
AdjustScreen(HWND hWnd,HDC hDC)803 TtyView::AdjustScreen(HWND hWnd, HDC hDC)
804 {
805 RECT rect;
806 #ifndef USE_KCTRL
807 TEXTMETRIC tm;
808
809 /* create an handle of required font */
810 SetFontValues(&lfont, hDC);
811 m_hFont = CreateFontIndirect(&lfont);
812
813 /* re-calculate the font metrics */
814 SelectObject(hDC, m_hFont);
815 GetTextMetrics(hDC, &tm);
816 m_dwFontW = tm.tmAveCharWidth;
817 m_dwFontH = tm.tmHeight + m_dwHMargin;
818 m_dwCurH = tm.tmHeight;
819 #ifdef FEPCTRL
820 /* set font to imm */
821 {
822 HIMC hIMC = ImmGetContext(m_hwnd);
823 if (hIMC) {
824 ImmSetCompositionFont(hIMC, &lfont);
825 ImmReleaseContext(m_hwnd, hIMC);
826 }
827 }
828 #endif /* FEPCTRL */
829 #endif /* !USE_KCTRL */
830
831 /* Calculate the line numbers and column numbers */
832 GetClientRect(m_hwnd, &rect);
833 m_dwLines = rect.bottom / m_dwFontH;
834 m_dwCols = rect.right / m_dwFontW;
835
836 /* Create a display buffer */
837 if (m_bmpScreen)
838 DeleteObject(m_bmpScreen);
839 m_bmpScreen = CreateCompatibleBitmap(hDC, rect.right, rect.bottom);
840 }
841
842 void
SetKeyboardLocale(DWORD val)843 TtyView::SetKeyboardLocale(DWORD val)
844 {
845 m_keyboardlocale = val;
846 }
847
848 void
WMCreate(HWND hWnd,LPCREATESTRUCT lpcs)849 TtyView::WMCreate( HWND hWnd, LPCREATESTRUCT lpcs )
850 {
851 HDC hDC ;
852
853 m_hwnd = hWnd ;
854 m_hwndParent = lpcs->hwndParent ;
855 m_idCtrl = (WORD) lpcs->hMenu ;
856
857 hDC = GetDC(m_hwnd);
858 AdjustScreen(hWnd, hDC);
859 ReleaseDC(m_hwnd, hDC);
860
861 ClearScreen() ;
862 }
863
864 void
WMPaint()865 TtyView::WMPaint()
866 {
867 PAINTSTRUCT ps ;
868 RECT rect ;
869 HGDIOBJ hOldObj ;
870 HDC hDC, hdcBmp ;
871
872 GetClientRect( m_hwnd, &rect ) ;
873 hDC = ::BeginPaint( m_hwnd, &ps ) ;
874 /* HideCursor( hDC ) ; */
875 hdcBmp = CreateCompatibleDC( hDC ) ;
876 hOldObj = SelectObject( hdcBmp, m_bmpScreen ) ;
877
878 BitBlt( hDC, 0, 0, rect.right, rect.bottom,
879 hdcBmp, 0, 0, SRCCOPY ) ;
880
881 SelectObject( hdcBmp, hOldObj ) ;
882 DeleteDC( hdcBmp ) ;
883 /* ShowCursor( hDC ) ; */
884 ::EndPaint( m_hwnd, &ps ) ;
885 }
886
887 void
WMChar(TCHAR chCharCode,LONG lKeyData)888 TtyView::WMChar( TCHAR chCharCode, LONG lKeyData )
889 {
890 BOOL fControl = 0x80 & GetKeyState( VK_CONTROL ) ;
891
892 #if defined(KANJI) && defined(USE_KCTRL)
893 if ( Fep_WM_CHAR( m_hwnd, chCharCode, lKeyData ) ) {
894 return ;
895 } else
896 #endif
897 if ( chCharCode == TEXT(' ') && fControl ) {
898 chCharCode = 0 ;
899 }
900 AddChar( chCharCode ) ;
901 }
902
903 BOOL
WMSysChar(TCHAR chCharCode,LONG lKeyData)904 TtyView::WMSysChar( TCHAR chCharCode, LONG lKeyData )
905 {
906 #if defined(KANJI) && defined(USE_KCTRL)
907 if ( Fep_WM_SYSCHAR( m_hwnd, chCharCode, lKeyData ) ) {
908 return TRUE ;
909 } else
910 #endif
911 if ( !(lKeyData & 0x20000000) ) {
912 return FALSE ;
913 }
914 AddMetaChar( chCharCode ) ;
915 return TRUE ;
916 }
917
918 BOOL
WMKeyDown(int nVirtKey,LONG lKeyData)919 TtyView::WMKeyDown( int nVirtKey, LONG lKeyData )
920 {
921 BOOL fShift = 0x80 & GetKeyState( VK_SHIFT ) ;
922 BOOL fControl = 0x80 & GetKeyState( VK_CONTROL ) ;
923 BOOL fRepeat = (lKeyData & 0x000F) > 1 ? TRUE : FALSE ;
924
925 switch ( nVirtKey ) {
926 case VK_UP:
927 AddChar( TEXT('P') - TEXT('@') ) ;
928 break ;
929 case VK_DOWN:
930 AddChar( TEXT('N') - TEXT('@') ) ;
931 break ;
932 case VK_LEFT:
933 AddChar( TEXT('B') - TEXT('@') ) ;
934 break ;
935 case VK_RIGHT:
936 AddChar( TEXT('F') - TEXT('@') ) ;
937 break ;
938 case VK_PRIOR:
939 AddMetaChar( TEXT('V') ) ;
940 break ;
941 case VK_NEXT:
942 AddChar( TEXT('V') - TEXT('@') ) ;
943 break ;
944 case VK_HOME:
945 if (fControl)
946 AddMetaChar(TEXT('<'));
947 else
948 AddChar(TEXT('A') - TEXT('@'));
949 break ;
950 case VK_END:
951 if (fControl)
952 AddMetaChar(TEXT('>'));
953 else
954 AddChar(TEXT('E') - TEXT('@'));
955 break ;
956 case VK_DELETE:
957 AddChar(0x7f);
958 break;
959 #ifdef JAPANESE_KEYBOARD
960 /* The following mapping is achieved by observing the behavior of
961 Windows CE Japanese version. It looks as if the virtual key code
962 is the same as English one, but mapping from virtual key to
963 character differs. */
964 default:
965 if (m_keyboardlocale == NGKEYBOARD_JP) {
966 #if defined(VK_LBRACKET) || defined(VK_BACKQUOTE) || defined(VK_EQUAL)
967 switch (nVirtKey) {
968 #ifdef VK_LBRACKET
969 case VK_LBRACKET:
970 if (fControl)
971 AddChar(TEXT('@') - TEXT('@'));
972 break;
973 #endif
974
975 #ifdef VK_BACKQUOTE
976 case VK_BACKQUOTE:
977 if (fControl)
978 AddChar(TEXT('_') - TEXT('@'));
979 break;
980 #endif
981
982 #ifdef VK_EQUAL
983 case VK_EQUAL:
984 if (fControl)
985 AddChar(TEXT('^') - TEXT('@'));
986 break;
987 #endif
988 }
989 #endif /* defined(VK_LBRACKET) || defined(VK_BACKQUOTE) || defined(VK_EQUAL) */
990 }
991 #if 0
992 else {
993 switch (nVirtKey) {
994 #ifdef VK_LBRACKET
995 case VK_LBRACKET:
996 if (fControl)
997 AddChar(TEXT('[') - TEXT('@'));
998 break;
999 #endif
1000
1001 #ifdef VK_RBRACKET
1002 case VK_RBRACKET:
1003 if (fControl)
1004 AddChar(TEXT(']') - TEXT('@'));
1005 break;
1006 #endif
1007 }
1008 }
1009 #endif
1010 break;
1011 #else /* not JAPANESE_KEYBOARD */
1012 default:
1013 #endif /* JAPANESE_KEYBOARD */
1014 return FALSE;
1015 }
1016 return TRUE;
1017 }
1018
1019 LRESULT
WMCommand(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp)1020 TtyView::WMCommand( HWND hWnd, UINT msg, WPARAM wp, LPARAM lp )
1021 {
1022 int nVirtKey ;
1023
1024 switch ( LOWORD(wp) ) {
1025 case IDM_FEPOK:
1026 /* return ACK for accepting FEP */
1027 return IDM_FEPOK ;
1028 case IDM_FEPKEY:
1029 /* Key input from FEP */
1030 nVirtKey = lp & 0xFF ;
1031 WMKeyDown( nVirtKey, 0 ) ;
1032 break ;
1033 }
1034 return 0 ;
1035 }
1036
1037 BOOL
WMCopydata(PCOPYDATASTRUCT cds)1038 TtyView::WMCopydata( PCOPYDATASTRUCT cds )
1039 {
1040 TCHAR c ;
1041 LPCTSTR ptr = (LPCTSTR) cds->lpData ;
1042
1043 while ( c = *ptr++ ) {
1044 AddChar( c ) ;
1045 }
1046 return TRUE ;
1047 }
1048
1049 void
WMSize(DWORD fwSize,WORD nWidth,WORD nHeight)1050 TtyView::WMSize( DWORD fwSize, WORD nWidth, WORD nHeight )
1051 {
1052 HDC hDC ;
1053 RECT rect ;
1054 DWORD prevlines, prevcols;
1055
1056 prevlines = m_dwLines;
1057 prevcols = m_dwCols;
1058
1059 /* Get how many columns in a line and lines in a screen */
1060 GetClientRect( m_hwnd, &rect ) ;
1061 m_dwLines = rect.bottom / m_dwFontH ;
1062 m_dwCols = rect.right / m_dwFontW ;
1063 /* Create a screen buffer */
1064 if ( m_bmpScreen ) {
1065 DeleteObject( m_bmpScreen ) ;
1066 }
1067 /* Create a screen buffer */
1068 hDC = GetDC( m_hwnd ) ;
1069 m_bmpScreen = CreateCompatibleBitmap( hDC, rect.right, rect.bottom ) ;
1070 ReleaseDC( m_hwnd, hDC ) ;
1071 ResetContent() ;
1072 if (prevlines != m_dwLines || prevcols != m_dwCols) {
1073 AddWindowEvent(TTY_WM_RESIZE);
1074 }
1075 }
1076
1077 void
WMLButtonDown(int x,int y)1078 TtyView::WMLButtonDown(int x, int y)
1079 {
1080 int xx, yy;
1081 xx = x / m_dwFontW;
1082 yy = y / m_dwFontH;
1083 AddWindowEvent((yy << 18) | (xx << 4) | TTY_WM_MOUSE);
1084 }
1085
1086 #ifdef DROPFILES /* 00.07.07 by sahf */
1087 void
WMDropFiles(HDROP hDrop)1088 TtyView::WMDropFiles( HDROP hDrop )
1089 {
1090 UINT iFile ;
1091 HLOCAL hMemory ;
1092 POINT sDropPoint ;
1093
1094 /* allocate memory for store filename */
1095 hMemory = LocalAlloc(LPTR, 16) ;
1096
1097 /* get file count which is dropped */
1098 iFile = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0) ;
1099 if (iFile && hMemory) {
1100 UINT iMemSize ; /* allocated memory size */
1101 UINT iMemPos ;
1102
1103 DragQueryPoint(hDrop, &sDropPoint);
1104 iMemSize = LocalSize( hMemory ) ;
1105 iMemPos = 0 ;
1106 while (iFile--) {
1107 UINT bufsz ; /* filename length (unit : byte) */
1108 UINT newsize ; /* request memory size */
1109 char *fname ;
1110
1111 /* get filename length for allocate buffer */
1112 bufsz = DragQueryFile(hDrop, iFile, NULL, 0) ;
1113 ++bufsz ;
1114 bufsz *= sizeof(TCHAR) ;/* char count -> byte count */
1115
1116 /* check room of hMemory */
1117 newsize = iMemPos + bufsz + sizeof(TCHAR) ;
1118 if ( iMemSize < newsize ) {
1119 HLOCAL hNewMem ;
1120 /* realloc hMemory if it is too small */
1121 hNewMem = LocalAlloc(LPTR, newsize) ;
1122 if ( hNewMem == NULL ) {
1123 LocalFree( hMemory ); hMemory = NULL;
1124 break ;
1125 }
1126 CopyMemory(hNewMem, hMemory, iMemSize);
1127 LocalFree(hMemory);
1128 hMemory = hNewMem;
1129 iMemSize = LocalSize( hMemory ) ;
1130 }
1131
1132 /* beginning of filename is hMemory[iMemPos] */
1133 fname = (char *) hMemory ;
1134 fname += iMemPos ;
1135 iMemPos += bufsz ;
1136 fname[bufsz] = 0;
1137
1138 /* get filename */
1139 DragQueryFile(hDrop, iFile, (LPTSTR) fname, bufsz) ;
1140 }
1141 }
1142
1143 DragFinish(hDrop);
1144
1145 if ( hMemory ) {
1146 DWORD next1 ;
1147
1148 next1 = (m_dwDropIn + 1) % MAX_DROPBUF ;
1149 if ( next1 == m_dwDropOut ) {
1150 return ;
1151 }
1152 m_szDropBuf[ m_dwDropIn ] = hMemory ;
1153 m_iDropLine[ m_dwDropIn ] = sDropPoint.y / m_dwFontH ;
1154 m_dwDropIn = next1 ;
1155 }
1156
1157 AddWindowEvent(TTY_WM_DROPFILES);
1158 }
1159 #endif /* DROPFILES */
1160
1161 void
WMSetFocus(void)1162 TtyView::WMSetFocus(void)
1163 {
1164 CreateCaret(m_hwnd, NULL, CARETWIDTH, m_dwCurH);
1165 m_dwLastCurWidth = 0;
1166 ShowCursor();
1167 }
1168
1169 void
WMKillFocus(void)1170 TtyView::WMKillFocus(void)
1171 {
1172 HideCursor();
1173 DestroyCaret();
1174 }
1175
1176 #if 0
1177 /*
1178 * Set TAB size
1179 */
1180 void
1181 TtyView::SetTab( DWORD wParam, BOOL bUpdate )
1182 {
1183 if ( m_dwTabSize == wParam ) {
1184 return ;
1185 }
1186 m_dwTabSize = wParam ;
1187 if ( bUpdate ) {
1188 ResetContent() ;
1189 }
1190 }
1191 #endif
1192
1193 /*
1194 * Set virtical margin
1195 */
1196 void
SetHMargin(DWORD wParam,BOOL bUpdate)1197 TtyView::SetHMargin( DWORD wParam, BOOL bUpdate )
1198 {
1199 RECT rect ;
1200
1201 if ( m_dwHMargin == wParam ) {
1202 return ;
1203 }
1204 GetClientRect( m_hwnd, &rect ) ;
1205 m_dwHMargin = wParam ;
1206 m_dwFontH = GetFontH() + m_dwHMargin ;
1207 m_dwLines = rect.bottom / m_dwFontH ;
1208 if ( bUpdate ) {
1209 ResetContent() ;
1210 }
1211 }
1212
1213 #ifdef CONFIG_FONT
1214 /*
1215 * Notified if font was changed.
1216 */
1217 void
FontChanged(void)1218 TtyView::FontChanged(void)
1219 {
1220 HDC hDC ;
1221
1222 hDC = GetDC(m_hwnd);
1223
1224 AdjustScreen(m_hwnd, hDC);
1225 ReleaseDC(m_hwnd, hDC);
1226 ClearScreen() ;
1227
1228 AddWindowEvent(TTY_WM_RESIZE);
1229 }
1230 #endif
1231
1232 BOOL
TtyViewRegisterClass(HINSTANCE hInst)1233 TtyViewRegisterClass( HINSTANCE hInst )
1234 {
1235 WNDCLASS wc ;
1236
1237 wc.style = 0 ;
1238 wc.lpfnWndProc = (WNDPROC) TtyViewWndProc ;
1239 wc.cbClsExtra = 0 ;
1240 wc.cbWndExtra = 4 ;
1241 wc.hInstance = hInst ;
1242 wc.hIcon = NULL ;
1243 #ifndef IDC_ARROW
1244 wc.hCursor = NULL ;
1245 #else
1246 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
1247 #endif
1248 wc.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH ) ;
1249 wc.lpszMenuName = 0 ;
1250 wc.lpszClassName = CTRL_TTYVIEW ;
1251 return ::RegisterClass( &wc ) ;
1252 }
1253
1254 LRESULT CALLBACK
TtyViewWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)1255 TtyViewWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
1256 {
1257 PTtyView pWindow ;
1258
1259 if ( msg == WM_CREATE ) {
1260 LPCREATESTRUCT lpStruct = (LPCREATESTRUCT) lParam ;
1261 pWindow = new TtyView() ;
1262 SetWindowLong( hWnd, 0, (LONG) pWindow ) ;
1263 pWindow->WMCreate( hWnd, lpStruct ) ;
1264 #ifdef DROPFILES /* 00.07.07 by sahf */
1265 DragAcceptFiles(hWnd, TRUE) ;
1266 #endif /* DROPFILES */
1267 return 0 ;
1268 }
1269 pWindow = (PTtyView) GetWindowLong( hWnd, 0 ) ;
1270 if ( !pWindow )
1271 return DefWindowProc( hWnd, msg, wParam, lParam ) ;
1272 switch ( msg ) {
1273 case WM_DESTROY:
1274 #ifdef DROPFILES /* 00.07.07 by sahf */
1275 DragAcceptFiles( hWnd, FALSE ) ;
1276 #endif /* DROPFILES */
1277 delete pWindow ;
1278 SetWindowLong( hWnd, 0, (LONG) 0 ) ;
1279 break ;
1280 case WM_COMMAND:
1281 return pWindow->WMCommand( hWnd, msg, wParam, lParam ) ;
1282 case WM_COPYDATA:
1283 return pWindow->WMCopydata( (PCOPYDATASTRUCT) lParam ) ;
1284 case WM_PAINT:
1285 pWindow->WMPaint() ;
1286 break ;
1287 case WM_CHAR:
1288 pWindow->WMChar( (TCHAR) wParam, lParam ) ;
1289 break ;
1290 case WM_SYSCHAR:
1291 if ( !pWindow->WMSysChar( (TCHAR) wParam, lParam ) )
1292 DefWindowProc( hWnd, msg, wParam, lParam ) ;
1293 break ;
1294 case WM_KEYDOWN:
1295 if ( !pWindow->WMKeyDown( (int) wParam, lParam ) )
1296 return DefWindowProc( hWnd, msg, wParam, lParam ) ;
1297 break ;
1298 case WM_SIZE:
1299 pWindow->WMSize( wParam, LOWORD(lParam), HIWORD(lParam) ) ;
1300 break ;
1301 case WM_GETDLGCODE:
1302 return DLGC_WANTALLKEYS ;
1303 case WM_LBUTTONDOWN:
1304 pWindow->WMLButtonDown((int)(lParam & 0xffff),
1305 (int)((lParam >> 16) & 0xffff));
1306 break;
1307 #ifdef DROPFILES /* 00.07.07 by sahf */
1308 case WM_DROPFILES:
1309 pWindow->WMDropFiles( (HDROP) wParam ) ;
1310 break ;
1311 #endif /* DROPFILES */
1312 case WM_SETFOCUS:
1313 pWindow->WMSetFocus();
1314 break;
1315 case WM_KILLFOCUS:
1316 pWindow->WMKillFocus();
1317 break;
1318 #if 0
1319 case TTYM_SETTAB: pWindow->SetTab( (DWORD) wParam, (BOOL) lParam ) ; break ;
1320 case TTYM_SETHMARGIN: pWindow->SetHMargin( (DWORD) wParam, (BOOL) lParam ) ; break ;
1321 #endif
1322 case TTYM_SETEVENT: pWindow->SetupEvent( (HANDLE) wParam ) ; break ;
1323 #ifdef CONFIG_FONT
1324 case TTYM_FONTCHANGED:
1325 pWindow->FontChanged();
1326 break;
1327 #endif
1328 case TTYM_GOTOXY: pWindow->GotoXY( HIWORD(wParam), LOWORD(wParam) ) ; break ;
1329 case TTYM_PUTCHAR: pWindow->PutChar( (BYTE) wParam ) ; break ;
1330 case TTYM_PUTKCHAR: pWindow->PutKChar( (BYTE) HIWORD(wParam), (BYTE) LOWORD(wParam) ) ; break ;
1331 case TTYM_PUTLINE: pWindow->PutLine( HIWORD(wParam), LOWORD(wParam), (LPCSTR) lParam ) ; break ;
1332 case TTYM_ERASEEOL: pWindow->EraseEOL() ; break ;
1333 case TTYM_ERASEEOP: pWindow->EraseEOP() ; break ;
1334 case TTYM_FLUSH: pWindow->Flush() ; break ;
1335 case TTYM_KBHIT: return pWindow->Kbhit() ;
1336 case TTYM_GETCHAR: return pWindow->GetChar() ;
1337 case TTYM_GETWINDOWEVENT: return pWindow->GetWindowEvent() ;
1338 #ifdef DROPFILES /* 00.07.07 by sahf */
1339 case TTYM_DROPFILES:
1340 return pWindow->GetDropFiles( (LPHANDLE) lParam ) ;
1341 #endif /* DROPFILES */
1342 case TTYM_GETWH: return pWindow->GetWH() ;
1343 case TTYM_COMMAND:
1344 pWindow->Command(wParam, lParam);
1345 break;
1346 case TTYM_SETKEYBOARDLOCALE:
1347 pWindow->SetKeyboardLocale((DWORD)wParam);
1348 break;
1349
1350 default:
1351 return DefWindowProc( hWnd, msg, wParam, lParam ) ;
1352 }
1353 return 0 ;
1354 }
1355