Annotation of OpenXM_contrib2/windows/asir32gui/asir32guiview.cpp, Revision 1.8
1.1 noro 1: // asir32guiView.cpp : CAsir32guiView クラスの動作の定義を行います。
2: //
3:
4: #include "stdafx.h"
5:
6: #include "asir32gui.h"
7: #include "asir32guiDoc.h"
8: #include "asir32guiView.h"
9: #include "FatalDialog.h"
1.3 noro 10: #include <direct.h>
1.6 noro 11: #include <io.h>
1.1 noro 12:
13: #ifdef _DEBUG
14: #define new DEBUG_NEW
15: #undef THIS_FILE
16: static char THIS_FILE[] = __FILE__;
17: #endif
18:
1.5 noro 19: // const TextBufferSize = 32768;
20: const TextBufferSize = 16384;
1.1 noro 21:
22: CAsir32guiView *theView;
23:
24: extern "C"
25: {
26: char *prev_hist(void), *next_hist(void), *search_hist(char *p);
27: void read_input_history(),write_input_history();
28: void init_input_history();
29: void add_hist(char *p), reset_traverse(void);
30: void asir_terminate(void);
31: void Main(int,char*[]);
32: void loadfile(char *);
33: void put_line(char *);
34: void send_intr(void);
35: void insert_to_theView(char *);
36: void get_rootdir(char *,int,char *);
37: extern int bigfloat, prtime, prresult;
38: extern char *asir_libdir;
1.2 noro 39: extern int asirgui_kind;
1.1 noro 40:
41: void insert_to_theView(char *str)
42: {
43: (void)theView->Insert(str);
44: }
45: void flush_log()
46: {
47: if ( theView->Logging )
48: theView->OnFileLog();
49: }
50: }
51:
52: /////////////////////////////////////////////////////////////////////////////
53: // CAsir32guiView
54:
55: IMPLEMENT_DYNCREATE(CAsir32guiView, CEditView)
56:
57: BEGIN_MESSAGE_MAP(CAsir32guiView, CEditView)
58: //{{AFX_MSG_MAP(CAsir32guiView)
59: ON_WM_KEYDOWN()
60: ON_WM_CHAR()
61: ON_WM_LBUTTONUP()
62: ON_WM_RBUTTONDOWN()
63: ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
64: ON_COMMAND(ID_FILE_LOG, OnFileLog)
65: ON_COMMAND(ID_ASIRHELP, OnAsirhelp)
66: ON_UPDATE_COMMAND_UI(ID_FILE_LOG, OnUpdateFileLog)
67: ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
1.3 noro 68: ON_COMMAND(IDR_FONT, OnFont)
69: ON_WM_CREATE()
1.6 noro 70: ON_COMMAND(ID_CONTRIBHELP, OnContribhelp)
71: ON_UPDATE_COMMAND_UI(ID_CONTRIBHELP, OnUpdateContribhelp)
1.1 noro 72: //}}AFX_MSG_MAP
73: // 標準印刷コマンド
74: // ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
75: // ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
76: // ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
77: END_MESSAGE_MAP()
78:
79: /////////////////////////////////////////////////////////////////////////////
80: // CAsir32guiView クラスの構築/消滅
81:
82: CAsir32guiView::CAsir32guiView()
83: {
84: // TODO: この場所に構築用のコードを追加してください。
85: static int tmpView_created = 0;
86: char errmsg[BUFSIZ];
87:
88: init_input_history();
89: read_input_history();
90: DebugMode = 0;
91: DebugInMain = 0;
92: MaxLineLength = 80;
93: LogStart = 0;
94: Logging = 0;
95: Logfp = NULL;
96: ResetIndex();
97: theView = this;
98: }
99:
100: CAsir32guiView::~CAsir32guiView()
101: {
102: write_input_history();
103: }
104:
105: BOOL CAsir32guiView::PreCreateWindow(CREATESTRUCT& cs)
106: {
107: // TODO: この位置で CREATESTRUCT cs を修正して Window クラスまたはスタイルを
108: // 修正してください。
109:
110: m_dwDefaultStyle = dwStyleDefault & ~ES_AUTOHSCROLL ;
111: m_dwDefaultStyle &= ~WS_HSCROLL;
112: return CCtrlView::PreCreateWindow(cs);
113: }
114:
115: /////////////////////////////////////////////////////////////////////////////
116: // CAsir32guiView クラスの描画
117:
118: void CAsir32guiView::OnDraw(CDC* pDC)
119: {
120: CAsir32guiDoc* pDoc = GetDocument();
121: ASSERT_VALID(pDoc);
122:
123: // TODO: この場所にネイティブ データ用の描画コードを追加します。
124: }
125:
126: /////////////////////////////////////////////////////////////////////////////
127: // CAsir32guiView クラスの印刷
128:
129: BOOL CAsir32guiView::OnPreparePrinting(CPrintInfo* pInfo)
130: {
131: // デフォルトの印刷準備
132: return DoPreparePrinting(pInfo);
133: }
134:
135: void CAsir32guiView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
136: {
137: // TODO: 印刷前の特別な初期化処理を追加してください。
138: }
139:
140: void CAsir32guiView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
141: {
142: // TODO: 印刷後の後処理を追加してください。
143: }
144:
145: /////////////////////////////////////////////////////////////////////////////
146: // CAsir32guiView クラスの診断
147:
148: #ifdef _DEBUG
149: void CAsir32guiView::AssertValid() const
150: {
151: CEditView::AssertValid();
152: }
153:
154: void CAsir32guiView::Dump(CDumpContext& dc) const
155: {
156: CEditView::Dump(dc);
157: }
158:
159: CAsir32guiDoc* CAsir32guiView::GetDocument() // 非デバッグ バージョンはインラインです。
160: {
161: ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAsir32guiDoc)));
162: return (CAsir32guiDoc*)m_pDocument;
163: }
164: #endif //_DEBUG
165:
166: /////////////////////////////////////////////////////////////////////////////
167: // CAsir32guiView クラスのメッセージ ハンドラ
168:
169: void CAsir32guiView::PutChar(int c)
170: {
1.8 ! noro 171: int i,len;
1.1 noro 172: char buf[2];
173:
1.8 ! noro 174: if ( EndPos >= sizeof(Buffer)-1 ) {
! 175: Beep(); return;
! 176: }
1.1 noro 177: for ( i = EndPos-1; i >= CurrentPos; i-- )
1.8 ! noro 178: Buffer[i+1] = Buffer[i];
1.1 noro 179: Buffer[CurrentPos] = (char)c;
1.8 ! noro 180: // buf[0] = (char)c; buf[1] = 0;
! 181: // Insert(buf,FALSE);
! 182: len = GetWindowTextLength();
! 183: if ( len+1 >= TextBufferSize )
! 184: DeleteTop();
! 185: CEditView::OnChar(c, 1, 0);
1.1 noro 186: CurrentPos++;
187: EndPos++;
188: }
189:
190: void CAsir32guiView::DeleteChar(int count) {
191: int i,s,e;
192: char null = 0;
193:
194: if ( count > (EndPos-CurrentPos) )
195: count = EndPos - CurrentPos;
196: if ( count == 0 )
197: Beep();
198: else {
199: EndPos -= count;
200: for ( i = CurrentPos; i < EndPos; i++ )
201: Buffer[i] = Buffer[i+count];
202: GetEditCtrl().GetSel(s,e);
203: GetEditCtrl().SetSel(s,s+count);
204: GetEditCtrl().ReplaceSel(&null);
205: }
206: }
207:
208: void CAsir32guiView::Insert(char *buf,BOOL wrap)
209: {
210: char t[BUFSIZ*4];
211: char *p,*q,c;
212: int len;
213: int i;
214:
215: if ( wrap ) {
216: i = GetEditCtrl().LineLength(-1);
217: for ( p = t, q = buf; (c = *p++ = *q++) != 0; )
218: if ( c == '\r' ) {
219: *p++ = *q++; i = 0;
220: } else if ( (*q != '\r') && (++i == MaxLineLength) ) {
221: *p++ = '\r'; *p++ = '\r'; *p++ = '\n'; i = 0;
222: }
223: p = t;
224: } else
225: p = buf;
226: len = GetWindowTextLength();
227: if ( strlen(p) + len >= TextBufferSize )
228: DeleteTop();
229: GetEditCtrl().ReplaceSel(p);
230: }
231:
232: void CAsir32guiView::DeleteTop()
233: {
234: const char *p,*q;
235: const char *buf;
236: char null = 0;
237: int len,len0,len1;
238:
239: buf = LockBuffer();
240: len0 = len = strlen(buf);
241: for ( p = buf; len >= TextBufferSize/2; ) {
242: q = strchr(p,'\n');
243: if ( !q ) {
244: len = 0; break;
245: } else {
246: q++; len -= (q-p); p = q;
247: }
248: }
249: if ( Logging ) {
1.4 noro 250: if ( len < LogStart )
251: LogStart -= len;
252: else {
253: fwrite(buf+LogStart,1,len-LogStart,Logfp);
254: LogStart = 0;
255: }
1.1 noro 256: }
257: UnlockBuffer();
258: if ( q ) {
259: GetEditCtrl().SetSel(0,len);
260: GetEditCtrl().ReplaceSel(&null);
261: }
262: UpdateCursor(EndPos);
263: }
264:
265: void CAsir32guiView::UpdateCursor(int pos)
266: {
267: int s;
268: int len;
269:
270: if ( pos < 0 || pos > EndPos )
271: Beep();
272: else {
273: len = GetWindowTextLength();
274: CurrentPos = pos;
275: s = len-EndPos+CurrentPos;
276: GetEditCtrl().SetSel(s,s);
277: }
278: }
279:
280: void CAsir32guiView::ReplaceString(char *str)
281: {
282: UpdateCursor(0); DeleteChar(EndPos);
283: Insert(str,FALSE);
284: strcpy(Buffer,str);
285: EndPos = CurrentPos = strlen(str);
286: }
287:
288: void CAsir32guiView::Beep(void) {
289: ::MessageBeep(0xffffffff);
290: }
291:
292: void CAsir32guiView::Paste(void) {
1.8 ! noro 293: char buf[2*BUFSIZ];
! 294: const char *src;
! 295: char c;
! 296: int i,j,l;
! 297: HGLOBAL hClip;
! 298:
! 299: if ( asirgui_kind == ASIRGUI_MESSAGE ) {
! 300: Beep(); return;
! 301: }
1.2 noro 302:
1.8 ! noro 303: if ( OpenClipboard() == FALSE ) {
! 304: Beep(); return;
1.1 noro 305: }
306: hClip = GetClipboardData(CF_TEXT);
307: src = (const char *)::GlobalLock(hClip);
1.8 ! noro 308: if ( !src || (l = strlen(src)) >= sizeof(Buffer) ) {
1.1 noro 309: ::CloseClipboard();
310: Beep(); return;
311: }
1.8 ! noro 312: for ( i = j = 0; i < l; i++ )
! 313: if ( (c = src[i]) != '\n' && c != '\r' )
! 314: buf[j++] = c;
! 315: buf[j] = 0;
1.1 noro 316: ::GlobalUnlock(hClip);
317: ::CloseClipboard();
1.8 ! noro 318: if ( EndPos+j >= sizeof(Buffer)-1 ) {
! 319: Beep(); return;
! 320: }
1.1 noro 321: GetEditCtrl().ReplaceSel(buf);
1.8 ! noro 322: strncpy(Buffer+EndPos,buf,j);
! 323: EndPos += j; CurrentPos = EndPos;
1.1 noro 324: }
325:
326: #define CTRL(c) (c)&0x1f
327:
328: void CAsir32guiView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
329: {
330: // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください
331: char *exp_result;
332:
333: switch ( nChar ) {
334: case VK_LEFT:
335: UpdateCursor(CurrentPos-1); return;
336: case VK_RIGHT:
337: UpdateCursor(CurrentPos+1); return;
338: case VK_DELETE:
339: DeleteChar(1); return;
340: case VK_UP:
341: if ( (exp_result = prev_hist()) != 0 )
342: ReplaceString(exp_result);
343: else
344: Beep();
345: return;
346: case VK_DOWN:
347: if ( (exp_result = next_hist()) != 0 )
348: ReplaceString(exp_result);
349: else
350: Beep();
351: return;
352: default:
353: break;
354: }
355: CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
356: }
357:
358: void CAsir32guiView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
359: {
360: // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください
361: char *exp_result;
362:
1.2 noro 363: if ( asirgui_kind == ASIRGUI_MESSAGE ) {
364: Beep(); return;
365: }
366:
1.1 noro 367: switch ( nChar ) {
368: case CTRL('M'): case CTRL('J'):
369: UpdateCursor(EndPos);
370: Buffer[EndPos] = 0;
371: reset_traverse();
372: if ( Buffer[0] == '!' ) {
373: exp_result = search_hist(Buffer+1);
374: if ( exp_result )
375: ReplaceString(exp_result);
376: else {
377: UpdateCursor(0); DeleteChar(EndPos); Beep();
378: }
379: return;
380: } else {
381: add_hist(Buffer);
382: put_line(Buffer);
383: ResetIndex();
384: nChar = CTRL('M');
385: }
386: break;
387: case CTRL('N'):
388: if ( (exp_result = next_hist()) != 0 )
389: ReplaceString(exp_result);
390: else
391: Beep();
392: return;
393: case CTRL('P'):
394: if ( (exp_result = prev_hist()) != 0 )
395: ReplaceString(exp_result);
396: else
397: Beep();
398: return;
399: case CTRL('A'):
400: UpdateCursor(0); return;
401: case CTRL('E'):
402: UpdateCursor(EndPos); return;
403: case CTRL('F'):
404: UpdateCursor(CurrentPos+1); return;
405: case CTRL('B'):
406: UpdateCursor(CurrentPos-1); return;
407: case CTRL('K'):
408: DeleteChar(EndPos-CurrentPos); return;
409: case CTRL('U'):
410: UpdateCursor(0); DeleteChar(EndPos); return;
411: case CTRL('D'):
412: DeleteChar(1); return;
413: case CTRL('H'):
414: if ( CurrentPos > 0 ) {
415: UpdateCursor(CurrentPos-1); DeleteChar(1);
416: } else
417: Beep();
418: return;
419: case CTRL('C'):
420: send_intr();
421: /* wake up the engine */
422: put_line("");
423: return;
424: default :
425: if ( nChar >= 0x20 && nChar < 0x7f )
426: PutChar(nChar);
427: else
428: Beep();
429: return;
430: }
431: CEditView::OnChar(nChar, nRepCnt, nFlags);
432: }
433:
434: void CAsir32guiView::OnLButtonUp(UINT nFlags, CPoint point)
435: {
436: // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください
437: GetEditCtrl().Copy(); UpdateCursor(EndPos);
438: CEditView::OnLButtonUp(nFlags, point);
439: }
440:
441: void CAsir32guiView::OnRButtonDown(UINT nFlags, CPoint point)
442: {
443: // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください
444: Paste();
445:
446: // CEditView::OnRButtonDown(nFlags, point);
447: }
448:
449: void CAsir32guiView::OnFileOpen()
450: {
451: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
452: char cmd[BUFSIZ*2]; // XXX
453: char *p;
1.3 noro 454: static char errmsg[BUFSIZ];
455: static char prevdir[BUFSIZ];
1.1 noro 456:
1.3 noro 457: if ( !prevdir[0] ) {
458: get_rootdir(prevdir,sizeof(prevdir),errmsg);
459: strcat(prevdir,"\\lib");
460: }
461:
462: _chdir(prevdir);
1.1 noro 463: CFileDialog fileDialog(TRUE);
464: if ( fileDialog.DoModal() == IDOK ) {
465: CString pathName = fileDialog.GetPathName();
466: sprintf(cmd,"load(\"%s\");",pathName);
467: for ( p = cmd; *p; p++ )
468: if ( *p == '\\' )
469: *p = '/';
470: put_line(cmd);
1.3 noro 471: p = strrchr(pathName,'\\');
472: if ( p ) {
473: *p = 0;
474: strcpy(prevdir,pathName);
475: }
1.1 noro 476: }
477: }
478:
479: void CAsir32guiView::OnAsirhelp()
480: {
481: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
482: char root[BUFSIZ],errmsg[BUFSIZ],helpfile[BUFSIZ];
483:
484: get_rootdir(root,sizeof(root),errmsg);
485: sprintf(helpfile,"%s\\bin\\asirhelp.chm",root);
486: HtmlHelp(NULL, helpfile, HH_DISPLAY_TOPIC, 0);
487: }
488:
489: void CAsir32guiView::OnFileLog()
490: {
491: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
492: if ( !Logging ) {
493: CFileDialog fileDialog(TRUE);
494: if ( fileDialog.DoModal() == IDOK ) {
495: CString logfile = fileDialog.GetPathName();
496: Logfp = fopen(logfile,"ab");
497: if ( Logfp ) {
498: LogStart = GetWindowTextLength();
499: Logging = 1;
500: }
501: }
502: } else {
503: const char *buf;
504: buf = LockBuffer();
505: fwrite(buf+LogStart,1,strlen(buf)-LogStart,Logfp);
506: UnlockBuffer();
507: fclose(Logfp);
508: Logging = 0;
509: }
510: }
511:
512: void CAsir32guiView::OnUpdateFileLog(CCmdUI* pCmdUI)
513: {
514: // TODO: この位置に command update UI ハンドラ用のコードを追加してください
515: if ( Logging )
516: pCmdUI->SetCheck(1);
517: else
518: pCmdUI->SetCheck(0);
519: }
520:
521: void CAsir32guiView::OnEditPaste()
522: {
523: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
524: Paste();
1.3 noro 525: }
526:
527: void CAsir32guiView::OnFont()
528: {
529: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
530: int ret;
531: CFontDialog fd(NULL,CF_EFFECTS | CF_SCREENFONTS | CF_FIXEDPITCHONLY);
532: static CFont *f = 0;
533: LOGFONT lf;
534:
535: ret = fd.DoModal();
536: if ( ret == IDOK ) {
537: fd.GetCurrentFont(&lf);
538: if ( f )
539: delete f;
540: f = new CFont;
541: f->CreateFontIndirect(&lf);
542: SetFont(f);
543: }
544: }
545:
546: int CAsir32guiView::OnCreate(LPCREATESTRUCT lpCreateStruct)
547: {
548: if (CEditView::OnCreate(lpCreateStruct) == -1)
549: return -1;
550:
551: // TODO: この位置に固有の作成用コードを追加してください
552:
553: LOGFONT logFont; memset(&logFont, 0, sizeof(LOGFONT));
554: logFont.lfHeight = 20;
555: logFont.lfCharSet = DEFAULT_CHARSET;
556: strcpy(logFont.lfFaceName, "Terminal");
557: CFont *f = new CFont;
558: f->CreateFontIndirect(&logFont);
559: SetFont(f);
560: GetEditCtrl().LimitText(nMaxSize);
561: GetEditCtrl().SetTabStops(m_nTabStops);
562:
563: return 0;
1.6 noro 564: }
565:
566: void CAsir32guiView::OnContribhelp()
567: {
568: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
569: char root[BUFSIZ],errmsg[BUFSIZ],helpfile[BUFSIZ];
570:
571: get_rootdir(root,sizeof(root),errmsg);
572: sprintf(helpfile,"%s\\bin\\cmanhelp.chm",root);
573: HtmlHelp(NULL, helpfile, HH_DISPLAY_TOPIC, 0);
574: }
575:
576: void CAsir32guiView::OnUpdateContribhelp(CCmdUI* pCmdUI)
577: {
578: // TODO: この位置に command update UI ハンドラ用のコードを追加してください
579: char root[BUFSIZ],errmsg[BUFSIZ],helpfile[BUFSIZ];
580:
1.7 noro 581: if ( getenv("OpenXM_WIN_ROOT") ) {
582: get_rootdir(root,sizeof(root),errmsg);
583: sprintf(helpfile,"%s\\bin\\cmanhelp.chm",root);
584: if ( _access(helpfile,04) != -1 ) {
585: pCmdUI->Enable( TRUE );
586: return;
587: }
588: }
589: pCmdUI->Enable( FALSE );
1.1 noro 590: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>