1 /*
2  * $Id: mfcterm.h,v 1.1 2005-09-18 22:05:38 dhmunro Exp $
3  * richedit class for play MDI development environment
4  */
5 /* Copyright (c) 2005, The Regents of the University of California.
6  * All rights reserved.
7  * This file is part of yorick (http://yorick.sourceforge.net).
8  * Read the accompanying LICENSE file for details.
9  */
10 
11 /*
12  * mfc_edit_view -- editor windows for yorick source code, data files
13  * 1. uses monospaced font (OnCreate)
14  * 2. prevents MFC from allowing files and other OLE/COM objects
15  *    from being pasted into files (QueryAcceptData)
16  * 3. turns off wordwrap to number lines correctly (constructor)
17  * 4. intercepts WM_DESTROY incomprehensibly ala MSVC++ (OnDestroy)
18  * X. experiment with richedit 2.0/3.0 (PreCreateWindow)
19  *
20  * mfc_edit_child -- MDIChild parent of mfc_edit_view
21  * 1. intercepts WM_CLOSE to prevent killing terminal, history windows
22  *
23  * mfc_edit_doc -- editor documents
24  * 1. forces files to be text format, not RTF (Serialize)
25  * 2. prevents save dialog box for terminal, history windows (SaveModified)
26  * 3. intercepts ID_FILE_CLOSE to prevent killing terminal, history windows
27  *
28  * mfc_term_view -- terminal and history windows
29  * 1. maintains "process mark" separating old input and output
30  *    from new input in terminal window - allows typeahead
31  *   -intercepts EN_SELCHANGE for this purpose (on_selchange, WindowProc)
32  * 2. new bindings for Enter, Up and Down arrows (latter only at eob),
33  *    extra processing for Delete and Home keys, cut, paste, undo, replace
34  *    messages (on_selchange, WindowProc)
35  */
36 
37 /*------------------------------------------------------------------------*/
38 
39 /* assumes mfcapp.h included first */
40 #include <afxrich.h>
41 
42 class mfc_edit_doc;
43 
44 class mfc_edit_view : public CRichEditView
45 {
46   DECLARE_DYNCREATE(mfc_edit_view)
47 public:
48   mfc_edit_view();
49   virtual ~mfc_edit_view();
50   int is_term, riched2;
51 
GetDocument()52   mfc_edit_doc* GetDocument() { return (mfc_edit_doc*)m_pDocument; }
53   virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
54 
55 protected:
56   virtual void OnInitialUpdate(); // called first time after construct
57   virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
58   virtual HRESULT QueryAcceptData(LPDATAOBJECT lpdataobj,
59                                   CLIPFORMAT* lpcfFormat, DWORD reco,
60                                   BOOL fReally, HGLOBAL hMetaPict);
61   int OnCreate(LPCREATESTRUCT lpcs);  // on WM_CREATE message
62 
63   afx_msg void on_choose_file();
64   afx_msg void on_goto_line();
65   afx_msg void on_goto_out();
66   afx_msg void on_select_out();
67   afx_msg void on_open_line();
68   afx_msg void on_redo();
69   afx_msg void on_update_term(CCmdUI *ui);
70   afx_msg void on_update_redo(CCmdUI *ui);
71   afx_msg void OnDestroy();
72 
73   DECLARE_MESSAGE_MAP()
74 };
75 
76 /*------------------------------------------------------------------------*/
77 
78 class mfc_edit_child : public CMDIChildWnd
79 {
80   DECLARE_DYNCREATE(mfc_edit_child)
81 public:
82   mfc_edit_child();
83   virtual ~mfc_edit_child();
84 
85 protected:
86   afx_msg void OnClose();
87 
88   DECLARE_MESSAGE_MAP()
89 };
90 
91 /*------------------------------------------------------------------------*/
92 
93 class mfc_edit_doc : public CRichEditDoc
94 {
95   DECLARE_DYNCREATE(mfc_edit_doc)
96 public:
97   mfc_edit_doc();
98   virtual ~mfc_edit_doc();
99   mfc_edit_doc(CMultiDocTemplate *mdt, int hist);
100 
101   virtual BOOL OnNewDocument();
102   virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
103   virtual void Serialize(CArchive& ar);
104 protected:
105   virtual BOOL SaveModified();
106   virtual CRichEditCntrItem* CreateClientItem(REOBJECT* preo) const;
107 
108   afx_msg void OnFileClose();
109 
110   DECLARE_MESSAGE_MAP()
111 };
112 
113 /*------------------------------------------------------------------------*/
114 
115 class mfc_term_view : public mfc_edit_view
116 {
117   DECLARE_DYNCREATE(mfc_term_view)
118 public:
119   mfc_term_view();
120   virtual ~mfc_term_view();
121 
GetDocument()122   mfc_edit_doc* GetDocument() { return (mfc_edit_doc*)m_pDocument; }
123 
124   int is_visible;
125 
126   long bol(int offset = 0);
127   long eol(int offset = 0);
128   long eob(int beg = 0);
129   int at_eob();
130   CString grab_line(int offset = 0) const;
131   void select_lines(int off1, int off2);
132   void get_state();
133   long smin, smax, len;  // set by get_state
134   int recursing;         // set if WindowProc recursing
135   int recalling;         // set during command recall sequences
136 
137   void save_line(const char *txt);   // to end of hist_view
138 
139   void set_command(const char *txt); // at end of term_view
140   void add_output(const char *txt);  // at end of term_view
141   void send_or_copy();  // bound to Enter in term_view
142   void recall_prev();   // bound to VK_UP in term_view
143   void recall_next();   // bound to VK_DOWN in term_view
144   void home_mark();     // called after VK_HOME in term_view
145 
146   void recall_line();   // bound to Enter in hist_view
147 
148   // TODO functions to:
149   // 1. select output block (back to previous prompt)
150   // 2. extract LINE/FILE, open and goto
151   // 3. goto line (in mfc_edit_view)
152 
153 public:
154   virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
155 
156 protected:
157   virtual void OnInitialUpdate(); // called first time after construct
158   virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
159 
160   long mark;  // process mark -- insertion point for p_stdout
161 
162   afx_msg void on_undo();
163   DECLARE_MESSAGE_MAP()
164 };
165 
166 /*------------------------------------------------------------------------*/
167 
168 extern mfc_term_view *term_view, *hist_view;
169 extern void mfc_term_init(void *arg);
170 extern int mfc_stdinit(void (**wout)(char*,long), void (**werr)(char*,long));
171 extern void mfc_reset_stdin();
172