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