-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneral.cpp
More file actions
402 lines (348 loc) · 11.4 KB
/
General.cpp
File metadata and controls
402 lines (348 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/// =====================================================================================
//
// The following routines are used internally by MMF, and should not need to be modified
//
// =====================================================================================
#include "common.h"
__inline int mvGetAppCodePage(LPMV mV, LPVOID pApp) \
{ return mV->mvCallFunction(NULL, 115, (LPARAM)pApp, (LPARAM)0, (LPARAM)0); }
HINSTANCE hInstLib;
EXT_INIT()
// ============================================================================
//
// LIBRARY ENTRY & QUIT POINTS
//
// ============================================================================
// -----------------
// Entry points
// -----------------
// Usually you do not need to do any initialization here: it is preferable to
// do it in "Initialize" found in Edittime.cpp
BOOL WINAPI DllMain(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
conditionsInfos = getConditionInfos();
actionsInfos = getActionInfos();
expressionsInfos = getExpressionInfos();
ConditionJumps = getConditions();
ActionJumps = getActions();
ExpressionJumps = getExpressions();
switch (dwReason)
{
// DLL is attaching to the address space of the current process.
case DLL_PROCESS_ATTACH:
hInstLib = hDLL; // Store HINSTANCE
break;
// A new thread is being created in the current process.
case DLL_THREAD_ATTACH:
break;
// A thread is exiting cleanly.
case DLL_THREAD_DETACH:
break;
// The calling process is detaching the DLL from its address space.
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// -----------------
// Initialize
// -----------------
// Where you want to do COLD-START initialization.
// Called when the extension is loaded into memory.
//
extern "C" int WINAPI DLLExport Initialize(mv _far *mV, int quiet)
{
// No error
return 0;
}
// -----------------
// Free
// -----------------
// Where you want to kill and initialized data opened in the above routine
// Called just before freeing the DLL.
//
extern "C" int WINAPI DLLExport Free(mv _far *mV)
{
// No error
return 0;
}
// ============================================================================
//
// GENERAL INFO
//
// ============================================================================
// -----------------
// Get Infos
// -----------------
//
extern "C"
{
DWORD WINAPI DLLExport GetInfos(int info)
{
switch (info)
{
case KGI_VERSION:
return EXT_VERSION2;
case KGI_PLUGIN:
return EXT_PLUGIN_VERSION1;
case KGI_PRODUCT:
return ForVersion;
case KGI_BUILD:
return MinimumBuild;
case KGI_UNICODE:
#ifdef _UNICODE
return TRUE;
#else
return FALSE;
#endif
default:
return 0;
}
}
}
// ----------------------------------------------------------
// GetRunObjectInfos
// ----------------------------------------------------------
// Fills an information structure that tells MMF2 everything
// about the object, its actions, conditions and expressions
//
short WINAPI DLLExport GetRunObjectInfos(mv _far *mV, fpKpxRunInfos infoPtr)
{
infoPtr->conditions = (LPBYTE)ConditionJumps;
infoPtr->actions = (LPBYTE)ActionJumps;
infoPtr->expressions = (LPBYTE)ExpressionJumps;
infoPtr->numOfConditions = Conditions.size();
infoPtr->numOfActions = Actions.size();
infoPtr->numOfExpressions = Expressions.size();
infoPtr->editDataSize = sizeof(EDITDATA);
MagicFlags(infoPtr->editFlags);
infoPtr->windowProcPriority = WINDOWPROC_PRIORITY;
MagicPrefs(infoPtr->editPrefs);
infoPtr->identifier = IDENTIFIER;
#ifndef UNICODE //This is used so conversion between ASCII and Unicode EDITDATA is registered
infoPtr->version = 3;
#else //ASCII
infoPtr->version = 4;
#endif
return TRUE;
}
// ----------------------------------------------------------
// GetDependencies
// ----------------------------------------------------------
// Returns the name of the external modules that you wish MMF to include
// with stand-alone applications (these modules must be in the MMF
// Data\Runtime folder).
//
LPCSTR szDep[] = {
"MyDll.dll",
NULL
};
LPCSTR* WINAPI DLLExport GetDependencies()
{
// Do some rSDK stuff
#include "rGetDependencies.h"
return NULL; // szDep;
}
// -----------------
// LoadObject
// -----------------
// Routine called for each object when the object is read from the MFA file (edit time)
// or from the CCN or EXE file (run time).
// You can load data here, reserve memory etc...
//
int WINAPI DLLExport LoadObject(mv _far *mV, LPCSTR fileName, LPEDATA edPtr, int reserved)
{
return 0;
}
// -----------------
// UnloadObject
// -----------------
// The counterpart of the above routine: called just before the object is
// deleted from the frame.
//
void WINAPI DLLExport UnloadObject(mv _far *mV, LPEDATA edPtr, int reserved)
{
}
// --------------------
// UpdateEditStructure
// --------------------
// For you to update your object structure to newer versions
// Called at both edit time and run time
//
#define p(foo) NewEdPtr->##foo = OldEdPtr->##foo
HGLOBAL WINAPI DLLExport UpdateEditStructure(mv __far *mV, OLDEDITDATA * AnyEdPtr)
{
//Version 1 -> 3
if (AnyEdPtr->eHeader.extVersion < 2)
{
LPEDATA NewEdPtr=0;
OLDEDITDATA* OldEdPtr = AnyEdPtr;
NewEdPtr = (EDITDATA*)GlobalAlloc(GPTR,sizeof(EDITDATA));
memcpy(&NewEdPtr->eHeader, &OldEdPtr->eHeader, sizeof(extHeader));
NewEdPtr->eHeader.extSize = sizeof(EDITDATA); // Update the EDITDATA structure size
NewEdPtr->eHeader.extVersion = 3;
p(nWidth); p(nHeight);
p(textColor); p(backColor);
p(dwAlignFlags); p(dwFlags);
memcpy(&NewEdPtr->textFont, &OldEdPtr->textFont, sizeof(LOGFONT));
memcpy(&NewEdPtr->opts, &OldEdPtr->opts, sizeof(bool)*4);
NewEdPtr->iconH = 16;
NewEdPtr->iconW = 16;
NewEdPtr->maxIcon = 256;
NewEdPtr->buttonStyle = 0;
NewEdPtr->tabDir = 0;
NewEdPtr->lineMode = 0;
NewEdPtr->tabMode = 0;
NewEdPtr->sText[0] = 0;
for (int i=0;i<16;i++)
NewEdPtr->wImages[i] = 0;
NewEdPtr->nImages = 0;
return (HGLOBAL)NewEdPtr;
}
//Version 2 -> 3
else if (AnyEdPtr->eHeader.extVersion == 2)
{
LPEDATA NewEdPtr=0;
OLDEDITDATA2* OldEdPtr = (OLDEDITDATA2*)AnyEdPtr;
NewEdPtr = (EDITDATA*)GlobalAlloc(GPTR,sizeof(EDITDATA));
memcpy(&NewEdPtr->eHeader, &OldEdPtr->eHeader, sizeof(extHeader));
NewEdPtr->eHeader.extSize = sizeof(EDITDATA); // Update the EDITDATA structure size
NewEdPtr->eHeader.extVersion = 3;
p(nWidth); p(nHeight);
p(textColor); p(backColor);
p(dwAlignFlags); p(dwFlags);
memcpy(&NewEdPtr->textFont, &OldEdPtr->textFont, sizeof(LOGFONT));
memcpy(&NewEdPtr->opts, &OldEdPtr->opts, sizeof(bool)*4);
p(iconH); p(iconW);
p(maxIcon);
p(buttonStyle);
p(tabDir);
p(lineMode);
p(tabMode);
NewEdPtr->sText[0] = 0;
for (int i=0;i<16;i++)
NewEdPtr->wImages[i] = 0;
NewEdPtr->nImages = 0;
return (HGLOBAL)NewEdPtr;
}
#if defined(UNICODE) && !defined(RUN_ONLY) //If data is in ASCII format
//Version 3 -> 4 (ASCII -> Unicode)
else if (AnyEdPtr->eHeader.extVersion == 3)
{
//Initialise EDITDATAs
EDITDATAA* OldEdPtr = (EDITDATAA*)AnyEdPtr;
EDITDATAW* NewEdPtr = (EDITDATAW*)GlobalAlloc(GPTR,sizeof(EDITDATAW));
// Copy eHeader
memcpy(&NewEdPtr->eHeader, &OldEdPtr->eHeader, sizeof(extHeader));
NewEdPtr->eHeader.extSize = sizeof(EDITDATAW); // Update the EDITDATA structure size
NewEdPtr->eHeader.extVersion = 4;
// Copy until the LogFont structure
p(nWidth); p(nHeight);
p(textColor); p(backColor);
p(dwAlignFlags); p(dwFlags);
// Copy all similarities between LOGFONTA and LOGFONTW
p(textFont.lfHeight); p(textFont.lfWidth);
p(textFont.lfEscapement); p(textFont.lfOrientation);
p(textFont.lfWeight); p(textFont.lfItalic);
p(textFont.lfUnderline); p(textFont.lfStrikeOut);
p(textFont.lfCharSet); p(textFont.lfOutPrecision);
p(textFont.lfClipPrecision); p(textFont.lfQuality);
p(textFont.lfPitchAndFamily);
// LOGFONTA has char [] so
MultiByteToWideChar(mvGetAppCodePage(mV, mV->mvEditApp), 0, OldEdPtr->textFont.lfFaceName, LF_FACESIZE, NewEdPtr->textFont.lfFaceName, LF_FACESIZE);
//Continue with other properties
memcpy(&NewEdPtr->opts, &OldEdPtr->opts, sizeof(bool)*4);
p(iconH); p(iconW);
p(maxIcon);
p(buttonStyle);
p(tabDir);
p(lineMode);
p(tabMode);
for (int i=0;i<16;i++)
p(wImages[i]);
p(nImages);
// Copy final char [], sText
MultiByteToWideChar(mvGetAppCodePage(mV, mV->mvEditApp), 0, OldEdPtr->sText, sizeof(OldEdPtr->sText), NewEdPtr->sText, sizeof(NewEdPtr->sText));
// Done
return (HGLOBAL)NewEdPtr;
}
#elif !defined(UNICODE) && !defined(RUN_ONLY) //If old data is Unicode, but running ASCII MMF2...
//Version 4 -> 3 (Unicode -> ASCII)
else if (AnyEdPtr->eHeader.extVersion == 4)
{
//None of that long copying thing. Let's do memory copying.
//First declare the two pointers.
EDITDATAW* OldEdPtr = (EDITDATAW*)AnyEdPtr;
EDITDATAA* NewEdPtr = (EDITDATAA*)GlobalAlloc(GPTR,sizeof(EDITDATAA));
// Copy eHeader
memcpy(&NewEdPtr->eHeader, &OldEdPtr->eHeader, sizeof(extHeader));
NewEdPtr->eHeader.extSize = sizeof(EDITDATAA); // Update the EDITDATA structure size
NewEdPtr->eHeader.extVersion = 3;
// Copy until the LogFont structure
p(nWidth); p(nHeight);
p(textColor); p(backColor);
p(dwAlignFlags); p(dwFlags);
// Copy all similarities between LOGFONTA and LOGFONTW
p(textFont.lfHeight); p(textFont.lfWidth);
p(textFont.lfEscapement); p(textFont.lfOrientation);
p(textFont.lfWeight); p(textFont.lfItalic);
p(textFont.lfUnderline); p(textFont.lfStrikeOut);
p(textFont.lfCharSet); p(textFont.lfOutPrecision);
p(textFont.lfClipPrecision); p(textFont.lfQuality);
p(textFont.lfPitchAndFamily);
// LOGFONTA has char [] so
WideCharToMultiByte(mvGetAppCodePage(mV, mV->mvEditApp), 0, OldEdPtr->textFont.lfFaceName, LF_FACESIZE, NewEdPtr->textFont.lfFaceName, LF_FACESIZE,NULL,NULL);
//Continue with other properties
memcpy(&NewEdPtr->opts, &OldEdPtr->opts, sizeof(bool)*4);
p(iconH); p(iconW);
p(maxIcon);
p(buttonStyle);
p(tabDir);
p(lineMode);
p(tabMode);
for (int i=0;i<16;i++)
p(wImages[i]);
p(nImages);
// Copy final char [], sText
WideCharToMultiByte(mvGetAppCodePage(mV, mV->mvEditApp), 0, OldEdPtr->textFont.lfFaceName, LF_FACESIZE, NewEdPtr->textFont.lfFaceName, LF_FACESIZE,NULL,NULL);
return (HGLOBAL)NewEdPtr;
}
#endif
return NULL;
}
// --------------------
// UpdateFileNames
// --------------------
// If you store file names in your datazone, they have to be relocated when the
// application is moved to a different directory: this routine does it.
// Called at edit time and run time.
//
// Call lpfnUpdate to update your file pathname (refer to the documentation)
//
void WINAPI DLLExport UpdateFileNames(mv _far *mV, LPSTR appName, LPEDATA edPtr, void (WINAPI * lpfnUpdate)(LPSTR, LPSTR))
{
}
// ---------------------
// EnumElts
// ---------------------
//
// Uncomment this function if you need to store an image in the image bank.
//
// Note: do not forget to enable the function in the .def file
// if you remove the comments below.
//
int WINAPI DLLExport EnumElts (mv __far *mV, LPEDATA edPtr, ENUMELTPROC enumProc, ENUMELTPROC undoProc, LPARAM lp1, LPARAM lp2)
{
int error = FALSE;
// Enum images
for (int i=0;i<edPtr->nImages;i++) {
error = enumProc(&edPtr->wImages[i],IMG_TAB,lp1,lp2);
if (error) {
// Undo enum images
for (int j=i-1;j>=0;j--)
undoProc(&edPtr->wImages[j],IMG_TAB,lp1,lp2);
break;
}
}
return error;
}