-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKPCMAIN.cpp
335 lines (307 loc) · 10.5 KB
/
PKPCMAIN.cpp
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
/****PROGRAM: Prekin.c****STRUCTURE connector: PDB to KIN*******************/
#define EXTERN
#include "PKIN.h"
#include "PKINDLOG.h"
#include "PKINMENU.h"
/****WinMain()**************************************************************/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
/*HINSTANCE hInstance; current instance
HINSTANCE hPrevInstance; previous instance
LPSTR lpCmdLine; command line
int nCmdShow; show-window type (open/icon) */
{
MSG msg; /* message*/
if (*lpCmdLine != '\0') filearg = lpCmdLine;
else filearg = NULL;
IPC = 1;
IMAC = 0;
/*Ltestprint = TRUE;*/ /*test option, compile as TRUE to invoke,*/
Ltestprint = 0; /* as FALSE for distribution, can also set in Kludges */
Lerr =0;
initialvalues(); /*starting general values */
getversion();
if (filearg)
{
dissectcommandline(filearg);
}
if (Lquiet == 0)
{/*running with GUI*/
if (!InitInstance(hInstance, nCmdShow))
{
return (FALSE);
}
beginnings();
}
else
{/*running quiet from commandline*/
for (;;)
{
mainlooprouter();
if(Lerr) break; /*030228 to fail gracefully*/
}
return(0);
}
/*Drop through to here if running NOT Lquiet, i.e. using GUI */
/*Acquire and dispatch messages until a WM_QUIT message is received.*/
/* Master endless loop for GUI*/
/*this GetMessage stuff should be equivalent to Mac HandleEvent stuff*/
/* besides working as the endless Loop */
while (GetMessage(&msg, /* message structure */
NULL, /* handle of window receiving the message*/
0, /* lowest message to examine */
0)) /* highest message to examine*/
{
mainlooprouter(); /*PKININIT, common router*/
if(Lerr) break;
if(Lquiet==0) /*was Lcommanded 990402*/
{
if (!TranslateAccelerator (PrekinWindow, PrekinAccel, &msg))
{
TranslateMessage(&msg); /* Translates virtual key codes */
DispatchMessage(&msg); /* Dispatches message to window */
}
}
}
return (msg.wParam); /* Returns the value from PostQuitMessage*/
}
/*___WinMain_______________________________________________________________*/
/****MainWndProc()***********************************************************/
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
int iadjust;
long linecount, currentline, totallines;
LPSTR textbuf;
switch (message)
{
case WM_CREATE:
currentline = GetWindowLong(hWnd,TEXTLINECURRENT);
totallines = GetWindowLong(hWnd,TEXTLINESTOTAL);
textbuf = (LPSTR)GetWindowLong(hWnd,TEXTHANDLE);
case WM_PAINT:
hDC = BeginPaint(PrekinWindow,&ps);
RePaint(hWnd, hDC);
EndPaint(PrekinWindow,&ps);
return(0);
case WM_COMMAND:
/* message: command from application menu? */
switch (LOWORD(wParam))
{ /*processing routines in PKPCMENU.C */
case PKIN_FILEOPENFILE:
PKIN_FileOpenFile();
break;
case PKIN_FILENEWPASS:
PKIN_FileNewPass();
break;
case PKIN_LAUNCHCURRENT:
launchcurrentkinemage();
break;
case PKIN_FILEQUIT:
PKIN_FileQuit();
break;
case PKIN_OPTIONSABOUTOPTIONS:
PKIN_OptionsAboutOptions();
break;
case PKIN_OPTIONSMUTATIONS:
PKIN_OptionsMutations();
break;
case PKIN_OPTIONSHELPHTML:
writehelptohtmlfile(0); /*PKININIT.c*/
break;
default: return(DefWindowProc(hWnd, message, wParam, lParam));
}
return(0);
case WM_SIZE:
/* calculate new line start array and resetscrollbars done in completetext*/
if (wParam != SIZE_MINIMIZED) completetext();
return (DefWindowProc(hWnd,message,wParam,lParam));
case WM_VSCROLL:
linecount = linesonascreen(hWnd);
/* messages from the scroll bar */
currentline = GetWindowLong(hWnd, TEXTLINECURRENT);
iadjust = 1;
switch (LOWORD(wParam))
{
case SB_LINEDOWN:
if (currentline == (GetWindowLong(hWnd,TEXTLINESTOTAL) - linecount))
iadjust = 0; /* already at bottom, don't redraw */
else ++currentline;
break;
case SB_LINEUP:
if (currentline == 0) iadjust = 0;
/* already at top, don't redraw */
else --currentline;
break;
case SB_PAGEDOWN:
if (currentline == (GetWindowLong(hWnd,TEXTLINESTOTAL) - linecount))
iadjust = 0; /* already at bottom, don't redraw */
else currentline += linecount-1;
break;
case SB_PAGEUP:
if (currentline == 0) iadjust = 0;
/* already at top, don't redraw */
else currentline -= linecount+1;
break;
case SB_THUMBTRACK:
if (currentline != HIWORD(wParam)) currentline = HIWORD(wParam);
else iadjust = 0;
break;
default:
iadjust = 0;
return (DefWindowProc(hWnd,message,wParam,lParam));
}
if(iadjust)
{
if (currentline < 0) currentline = 0;
if (currentline > (GetWindowLong(hWnd,TEXTLINESTOTAL)-linecount))
currentline = (GetWindowLong(hWnd,TEXTLINESTOTAL)-linecount);
SetWindowLong(hWnd,TEXTLINECURRENT,currentline);
resetscrollbarvalues(hWnd);
InvalidateRect(hWnd,NULL,TRUE);
}
return(0);
case WM_MOUSEWHEEL:
linecount = linesonascreen(hWnd);
if (linecount <= GetWindowLong(hWnd,TEXTLINESTOTAL)-1)
{/*don't do any of this if screen not full of text*/
currentline = GetWindowLong(hWnd,TEXTLINECURRENT);
iadjust = 1; /* by default redraw the screen */
if(((short)HIWORD(wParam) > 0) && (currentline > 0)) currentline--;
else if(((short)HIWORD(wParam) < 0) &&
(currentline < (GetWindowLong(hWnd,TEXTLINESTOTAL)-linecount)))
currentline++;
else if (currentline < 0) currentline = 0;
else if (currentline > (GetWindowLong(hWnd,TEXTLINESTOTAL)-linecount))
currentline = (GetWindowLong(hWnd,TEXTLINESTOTAL)-linecount);
else iadjust = 0; /* at top or bottom of text, don't redraw */
if (iadjust)
{
SetWindowLong(hWnd,TEXTLINECURRENT,currentline);
resetscrollbarvalues(hWnd);
InvalidateRect(hWnd,NULL,TRUE);
}
}
return(0);
case WM_KEYDOWN:
linecount = linesonascreen(hWnd);
if (linecount <= GetWindowLong(hWnd,TEXTLINESTOTAL)-1)
{/*don't do any of this if screen not full of text*/
currentline = GetWindowLong(hWnd,TEXTLINECURRENT);
iadjust = 1;
switch (wParam)
{
case VK_HOME:
if (currentline == 0) iadjust = 0;
/* already at top, don't redraw */
else currentline = 0;
break;
case VK_END:
if (currentline == (GetWindowLong(hWnd,TEXTLINESTOTAL) - linecount))
iadjust = 0; /* already at bottom, don't redraw */
else currentline = GetWindowLong(hWnd,TEXTLINESTOTAL) - linecount;
break;
case VK_PRIOR:
if (currentline == 0)iadjust = 0;
/* already at top, don't redraw */
else currentline -= linecount+1;
break;
case VK_NEXT:
if (currentline == (GetWindowLong(hWnd,TEXTLINESTOTAL) - linecount))
iadjust = 0; /* already at bottom, don't redraw */
else currentline += linecount-1;
break;
case VK_UP:
if (currentline == 0)iadjust = 0;
/* already at top, don't redraw */
else --currentline;
break;
case VK_DOWN:
if (currentline == (GetWindowLong(hWnd,TEXTLINESTOTAL) - linecount))
iadjust = 0; /* already at bottom, don't redraw */
else ++currentline;
break;
default:
iadjust = 0;
return(DefWindowProc(hWnd, message, wParam, lParam));
}
if (iadjust==1)
{
if (currentline < 0) currentline = 0;
if (currentline > (GetWindowLong(hWnd,TEXTLINESTOTAL)-linecount))
currentline = (GetWindowLong(hWnd,TEXTLINESTOTAL)-linecount);
SetWindowLong(hWnd,TEXTLINECURRENT,currentline);
resetscrollbarvalues(hWnd);
InvalidateRect(hWnd,NULL,TRUE);
}
}
return(0);
case WM_DESTROY:
if (GetWindowLong(hWnd,TEXTHANDLE))
free((HANDLE)GetWindowLong(hWnd,TEXTHANDLE));
if (GetWindowLong(hWnd,TEXTLINESTARTHANDLE))
free((HANDLE)GetWindowLong(hWnd,TEXTLINESTARTHANDLE));
PostQuitMessage(0);
return(0);
default: /* Passes it on if unproccessed */
return (DefWindowProc(hWnd, message, wParam, lParam));
}
}
/*___MainWndProc()__________________________________________________________*/
/****SetPrekinCaption()******************************************************/
/* Set the caption of the "PrekinWindow" */
void SetPrekinCaption()
{
SetTextCaption(PrekinWindow,lstrcat(dirstrip(NameStr)," - Prekin"));
}
/*___SetPrekinCaption()_____________________________________________________*/
/****dirstrip()**************************************************************/
char* dirstrip (char oldNameStr[256])
{
int n,i,h;
static char TestStr[256];
/* static necessary b/c we return the address of the char array */
n = -1; /*keeps track of last \ directory boundary in full path name*/
for(i=0;i<256;i++)
{/*isolate local, simple name from Full Path Name*/
if(oldNameStr[i] == '\\') n=i;
if(oldNameStr[i] == '\0') break;
}
h = 0; /*index for working version of input name*/
/*n is either==0, or set to first char of simple name in the Full Path name*/
for(i=n+1;i<256;i++) /*just work in actual local file name part*/
{/*make copy of working part of input file name, flagged for last . */
TestStr[h] = oldNameStr[i]; /*this has exact name of current input file*/
if(TestStr[h] == '\0') break;
h++;
}
return (TestStr);
}
/*___dirstrip()_____________________________________________________________*/
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/****getkeydownstate()*******************************************************/
int getkeydownstate()
{
return(0);
}
/*___getkeydownstate()______________________________________________________*/
/****TickCount()-dummy-******************************************************/
long TickCount()
{
return(0);
}
/*___TickCount()-dummy-_____________________________________________________*/
/****makecursorwait()********************************************************/
void makecursorwait(void)
{
SetCursor(LoadCursor(NULL,IDC_WAIT));
}
/*___makecursorwait()_______________________________________________________*/
/****makecursoractive()******************************************************/
void makecursoractive(void)
{
SetCursor(LoadCursor(NULL,IDC_ARROW));
}
/*___makecursoractive()_____________________________________________________*/