1 | // LispEditorDoc.cpp : implementation of the CLispEditorDoc class
|
---|
2 | //
|
---|
3 |
|
---|
4 | #include "stdafx.h"
|
---|
5 | #include "LispEditor.h"
|
---|
6 |
|
---|
7 | #include "LispEditorDoc.h"
|
---|
8 | #include "LispEditorView.h"
|
---|
9 | #include "CntrItem.h"
|
---|
10 |
|
---|
11 | #ifdef _DEBUG
|
---|
12 | #define new DEBUG_NEW
|
---|
13 | #undef THIS_FILE
|
---|
14 | static char THIS_FILE[] = __FILE__;
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | /////////////////////////////////////////////////////////////////////////////
|
---|
18 | // CLispEditorDoc
|
---|
19 |
|
---|
20 | IMPLEMENT_DYNCREATE(CLispEditorDoc, CRichEditDoc)
|
---|
21 |
|
---|
22 | BEGIN_MESSAGE_MAP(CLispEditorDoc, CRichEditDoc)
|
---|
23 | //{{AFX_MSG_MAP(CLispEditorDoc)
|
---|
24 | // NOTE - the ClassWizard will add and remove mapping macros here.
|
---|
25 | // DO NOT EDIT what you see in these blocks of generated code!
|
---|
26 | //}}AFX_MSG_MAP
|
---|
27 | // Enable default OLE container implementation
|
---|
28 | ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, CRichEditDoc::OnUpdateEditLinksMenu)
|
---|
29 | ON_COMMAND(ID_OLE_EDIT_LINKS, CRichEditDoc::OnEditLinks)
|
---|
30 | ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, CRichEditDoc::OnUpdateObjectVerbMenu)
|
---|
31 | END_MESSAGE_MAP()
|
---|
32 |
|
---|
33 | /////////////////////////////////////////////////////////////////////////////
|
---|
34 | // CLispEditorDoc construction/destruction
|
---|
35 |
|
---|
36 | CLispEditorDoc::CLispEditorDoc()
|
---|
37 | {
|
---|
38 | // TODO: add one-time construction code here
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 | CLispEditorDoc::~CLispEditorDoc()
|
---|
43 | {
|
---|
44 | }
|
---|
45 |
|
---|
46 | BOOL CLispEditorDoc::OnNewDocument()
|
---|
47 | {
|
---|
48 | if (!CRichEditDoc::OnNewDocument())
|
---|
49 | return FALSE;
|
---|
50 |
|
---|
51 | // TODO: add reinitialization code here
|
---|
52 | // (SDI documents will reuse this document)
|
---|
53 |
|
---|
54 | return TRUE;
|
---|
55 | }
|
---|
56 |
|
---|
57 | CRichEditCntrItem* CLispEditorDoc::CreateClientItem(REOBJECT* preo) const
|
---|
58 | {
|
---|
59 | // cast away constness of this
|
---|
60 | return new CLispEditorCntrItem(preo, (CLispEditorDoc*) this);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | /////////////////////////////////////////////////////////////////////////////
|
---|
66 | // CLispEditorDoc serialization
|
---|
67 |
|
---|
68 | void CLispEditorDoc::Serialize(CArchive& ar)
|
---|
69 | {
|
---|
70 | if (ar.IsStoring())
|
---|
71 | {
|
---|
72 | // TODO: add storing code here
|
---|
73 | }
|
---|
74 | else
|
---|
75 | {
|
---|
76 | // TODO: add loading code here
|
---|
77 | }
|
---|
78 |
|
---|
79 | // Calling the base class CRichEditDoc enables serialization
|
---|
80 | // of the container document's COleClientItem objects.
|
---|
81 | // TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text
|
---|
82 | CRichEditDoc::Serialize(ar);
|
---|
83 | }
|
---|
84 |
|
---|
85 | /////////////////////////////////////////////////////////////////////////////
|
---|
86 | // CLispEditorDoc diagnostics
|
---|
87 |
|
---|
88 | #ifdef _DEBUG
|
---|
89 | void CLispEditorDoc::AssertValid() const
|
---|
90 | {
|
---|
91 | CRichEditDoc::AssertValid();
|
---|
92 | }
|
---|
93 |
|
---|
94 | void CLispEditorDoc::Dump(CDumpContext& dc) const
|
---|
95 | {
|
---|
96 | CRichEditDoc::Dump(dc);
|
---|
97 | }
|
---|
98 | #endif //_DEBUG
|
---|
99 |
|
---|
100 | /////////////////////////////////////////////////////////////////////////////
|
---|
101 | // CLispEditorDoc commands
|
---|
102 |
|
---|
103 | BOOL CLispEditorDoc::OnSaveDocument(LPCTSTR lpszPathName)
|
---|
104 | {
|
---|
105 | long Start, End;
|
---|
106 | FINDTEXTEX Find;
|
---|
107 | ZeroMemory(&Find, sizeof(Find));
|
---|
108 | GetView()->GetRichEditCtrl().GetSel(Start, End);
|
---|
109 | CHARRANGE cr;
|
---|
110 | cr.cpMax = End;
|
---|
111 | cr.cpMin = Start;
|
---|
112 |
|
---|
113 | Start--;
|
---|
114 | GetView()->GetRichEditCtrl().SetSel(0, -1);
|
---|
115 | CString SearchSpace = GetView()->GetRichEditCtrl().GetSelText();
|
---|
116 |
|
---|
117 | HANDLE fh = CreateFile(lpszPathName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
---|
118 | DWORD Count;
|
---|
119 |
|
---|
120 | Count = SearchSpace.GetLength();
|
---|
121 | WriteFile(fh, (LPCSTR) SearchSpace, SearchSpace.GetLength(), &Count, NULL);
|
---|
122 |
|
---|
123 | CloseHandle(fh);
|
---|
124 | GetView()->GetRichEditCtrl().SetSel(cr);
|
---|
125 | SetModifiedFlag(FALSE);
|
---|
126 | return 1;
|
---|
127 | }
|
---|
128 |
|
---|
129 | static DWORD CALLBACK ReadStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
|
---|
130 | {
|
---|
131 | CFile* pFile = (CFile*) dwCookie;
|
---|
132 |
|
---|
133 | *pcb = pFile->Read(pbBuff, cb);
|
---|
134 |
|
---|
135 | return 0;
|
---|
136 | }
|
---|
137 |
|
---|
138 | BOOL CLispEditorDoc::OnOpenDocument(LPCTSTR lpszPathName)
|
---|
139 | {
|
---|
140 | // TODO: Add your specialized creation code here
|
---|
141 | CHARFORMAT cf;
|
---|
142 |
|
---|
143 | GetView()->GetRichEditCtrl().GetDefaultCharFormat(cf);
|
---|
144 | cf.crTextColor = RGB(255, 255, 255);
|
---|
145 | cf.dwMask = CFM_COLOR | CFM_BOLD | CFM_FACE;
|
---|
146 | cf.dwEffects = 0;
|
---|
147 | strcpy(cf.szFaceName, "Fixedsys");
|
---|
148 | GetView()->GetRichEditCtrl().SetDefaultCharFormat(cf);
|
---|
149 |
|
---|
150 |
|
---|
151 | CFile InFile(TEXT(lpszPathName), CFile::modeRead);
|
---|
152 | EDITSTREAM es;
|
---|
153 |
|
---|
154 | es.dwCookie = (DWORD) &InFile;
|
---|
155 | es.pfnCallback = ReadStreamInCallback;
|
---|
156 | GetView()->GetRichEditCtrl().StreamIn(SF_TEXT, es);
|
---|
157 |
|
---|
158 | GetView()->GetRichEditCtrl().SetModify(FALSE);
|
---|
159 | ((CLispEditorView*) GetView())->ColorRange(0, -1);
|
---|
160 | SetModifiedFlag(FALSE);
|
---|
161 | return TRUE;
|
---|
162 | }
|
---|