-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditfcn.c
More file actions
5737 lines (4630 loc) · 213 KB
/
editfcn.c
File metadata and controls
5737 lines (4630 loc) · 213 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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//***************************************************************************
// NARS2000 -- Function Editor
//***************************************************************************
/***************************************************************************
NARS2000 -- An Experimental APL Interpreter
Copyright (C) 2006-2016 Sudley Place Software
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include "headers.h"
#include "unitranstab.h"
#include "scancodes.h"
#include "debug.h" // For xxx_TEMP_OPEN macros
extern DWORD LclGetTabbedTextExtentW (HFONT, HFONT, HDC, LPWSTR, int, int, const LPINT);
// ToDo
/*
* Redo
* Move Undo Code into EDITCTRL.C
* Allow external editor
*
*/
#ifdef DEBUG
//#define DEBUG_WM_KEYDOWN
//#define DEBUG_WM_KEYUP
//#define DEBUG_WM_CHAR
#endif
extern UBOOL bMainDestroy;
extern TKACTSTR fsaActTableTK [][TKCOL_LENGTH];
char szCloseMessage[] = "You have changed the body of this function;"
" save the changes?";
// VK_CANCEL scan code for some keyboards
// The initial value is unimportant as it is overridden
// by the first and all subsequent calls to VK_CANCEL.
UINT uCancelCode = 0x46;
// Define struct for passing parameters to WM_NCCREATE/WM_CREATE
// for the Function Edit window
typedef struct tagFE_CREATESTRUCTW
{
LPAPLCHAR lpwszLine;
UINT ErrCode;
} UNALIGNED FE_CREATESTRUCTW, *LPFE_CREATESTRUCTW;
typedef struct tagCLIPFMTS
{
UINT uFmtNum; // Format #
HGLOBAL hGlbFmt; // Handle for this format #
} CLIPFMTS, *LPCLIPFMTS;
typedef enum tagFCNMEMVIRTENUM
{
FCNMEMVIRT_UNDOBEG, // 00: lpUndoBeg
FCNMEMVIRT_LENGTH // 01: # entries
} FCNMEMVIRTENUM;
//***************************************************************************
// $CreateFcnWindow
//
// Create a function window
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- CreateFcnWindow"
#else
#define APPEND_NAME
#endif
UBOOL CreateFcnWindow
(LPWCHAR lpwszLine) // Ptr to text after {del}
{
HWND hWnd, // Handle for Function Editor window
hWndNxt; // Next window handle in doubly-linked list
// of FE window handles
FE_CREATESTRUCTW feCreateStructW; // CreateStruct for Function Editor window
LPPERTABDATA lpMemPTD; // Ptr to PerTabData global memory
UINT uLen; // Length of the function name
// Get ptr to PerTabData global memory
lpMemPTD = GetMemPTD ();
// Skip over the initial UTF16_DEL, if present
if (lpwszLine[0] EQ UTF16_DEL)
lpwszLine++;
// Skip over leading blanks
while (isspaceW (*lpwszLine))
lpwszLine++;
// Calculate the length of the function name
uLen = (UINT) (SkipToCharW (lpwszLine, L';') - lpwszLine);
// If there's a name, ...
if (uLen NE 0)
{
// Check to see if this function name is already being edited
// If so, switch to that window instead of opening a new one
hWndNxt = lpMemPTD->hWndFENxt;
while (hWndNxt NE NULL)
{
// Ask the window if this function name is theirs
if (SendMessageW (hWndNxt, MYWM_CMPNAME, uLen, (LPARAM) (HANDLE_PTR) lpwszLine))
break;
// Get the next FE window handle in sequence
hWndNxt = (HWND) GetWindowLongPtrW (hWndNxt, GWLFE_HWNDNXT);
} // End WHILE
// If we found a matching window, ...
if (hWndNxt NE NULL)
{
// Activate the other window
SendMessageW (lpMemPTD->hWndMC, WM_MDIACTIVATE, (WPARAM) hWndNxt, 0);
return TRUE;
} // End IF
} // End IF
// Save a ptr to the line
feCreateStructW.lpwszLine = lpwszLine;
// Initialize the return error code
feCreateStructW.ErrCode = 0;
hWnd =
CreateMDIWindowW (LFEWNDCLASS, // Class name
NULL, // Window title
0, // Styles
CW_USEDEFAULT, // X-pos
CW_USEDEFAULT, // Y-pos
CW_USEDEFAULT, // Height
CW_USEDEFAULT, // Width
lpMemPTD->hWndMC, // Parent
_hInstance, // Instance
(LPARAM) &feCreateStructW); // Extra data,
// If it didn't succeed, ...
if (hWnd EQ NULL)
{
switch (feCreateStructW.ErrCode)
{
case NAMETYPE_VAR:
MB (pszNoEditVars);
break;
case NAMETYPE_FN12:
case NAMETYPE_OP1:
case NAMETYPE_OP2:
case NAMETYPE_OP3:
case NAMETYPE_TRN:
MB (pszNoEditPrimFns);
break;
case NAMETYPE_UNK:
case NAMETYPE_FN0:
MB (pszNoCreateFEWnd);
break;
defstop
break;
} // End SWITCH
return FALSE;
} // End IF
// Make the window visible; update its client area
ShowWindow (hWnd, SW_SHOWNORMAL);
UpdateWindow (hWnd);
// Set the appropriate font in place
SendMessageW (hWnd, WM_SETFONT, (WPARAM) GetFSIndFontHandle (FONTENUM_FE), MAKELPARAM (TRUE, 0));
return TRUE;
} // End CreateFcnWindow
#undef APPEND_NAME
//***************************************************************************
// $LftMarginsFE
//
// Return the left margin for a Function Editor window
//***************************************************************************
UINT LftMarginsFE
(HWND hWndEC, // Window handle to the Edit Ctrl
UBOOL bIncludeLC) // TRUE iff we should include the Line Continuation markers
{
UINT uLeft; // Left margin
HWND hWndParent; // Window handle of parent
// Get the window handle of the parent window
hWndParent = GetParent (hWndEC);
Assert (IzitFE (hWndParent));
// Make room for Line Continuation markers
uLeft = bIncludeLC ? uWidthLC[FONTENUM_FE] : 0;
// If we're displaying function line #s, ...
if (GetWindowLongW (hWndParent, GWLSF_FLN))
// Make room for the function line numbers and
uLeft += FCN_INDENT * GetFSIndAveCharSize (FONTENUM_FE)->cx;
return uLeft;
} // End LftMarginsFE
//***************************************************************************
// $SetMarginsFE
//
// Set the margins for a Function Editor window
//***************************************************************************
void SetMarginsFE
(HWND hWndEC) // Window handle to the Edit Ctrl
{
UINT uLeft; // Left margin
// Return the left margin
uLeft = LftMarginsFE (hWndEC, TRUE);
// Tell the Edit Ctrl about it
SendMessageW (hWndEC, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG (uLeft, 0));
} // End SetMarginsFE
//***************************************************************************
// $IzitAFE
//
// Is this is an Edit Ctrl from an AFO with bMakeAfe
//***************************************************************************
UBOOL IzitAFE
(HWND hWndEC, // Window handle to Edit Ctrl
UBOOL bAllow) // TRUE iff we should allow the operation regardless of the line #
{
HGLOBAL hGlbDfnHdr; // User-defined function/operator header global memory handle
LPDFN_HEADER lpMemDfnHdr; // Ptr to user-defined function/operator header global memory
UBOOL bAFO = FALSE; // TRUE iff this is an AFO
if (!IzitFE (GetParent (hWndEC)))
return FALSE;
// Get the previous function global memory handle (if any)
hGlbDfnHdr = (HGLOBAL) GetWindowLongPtrW (GetParent (hWndEC), GWLSF_HGLBDFNHDR);
// If the handle is valid, ...
if (hGlbDfnHdr NE NULL && !bAllow)
{
// Lock the memory to get a ptr to it
lpMemDfnHdr = MyGlobalLockDfn (hGlbDfnHdr);
// Save the flag
bAFO = lpMemDfnHdr->bAFO;
// We no longer need this ptr
MyGlobalUnlock (hGlbDfnHdr); lpMemDfnHdr = NULL;
} // End IF
// If this is an AFO, ...
if (bAFO && !bAllow)
{
UINT uLineNum;
// Get the current line #
uLineNum = (UINT) SendMessageW (hWndEC, EM_LINEFROMCHAR, (WPARAM) -1, 0);
// If the selection is on the header (line 0), ...
if (uLineNum EQ 0)
{
MessageBeep (MB_ICONWARNING);
return TRUE;
} // End IF
} // End IF
return FALSE;
} // End IzitAFE
//***************************************************************************
// $ReplaceSel
//
// Replace a selection in a FE Edit Ctrl
//***************************************************************************
void ReplaceSel
(HWND hWndEC, // Window handle to Edit Ctrl
UBOOL bAllow, // TRUE iff we should allow the operation regardless of the line #
LPARAM lParam) // Ptr to the replacement text
{
// Izit an AFO called with bMakeAFE?
if (IzitAFE (hWndEC, bAllow))
// Pass on the message as a NOP
SendMessageW (hWndEC , EM_REPLACESEL, FALSE, (LPARAM) L"");
else
// Pass on the message
SendMessageW (hWndEC , EM_REPLACESEL, FALSE, lParam);
} // End ReplaceSel
//***************************************************************************
// $FE_Create
//
// Perform window-specific initialization
//***************************************************************************
void FE_Create
(HWND hWnd)
{
} // End FE_Create
//***************************************************************************
// $FE_Delete
//
// Perform window-specific uninitialization
//***************************************************************************
void FE_Delete
(HWND hWnd)
{
} // End FE_Delete
//***************************************************************************
// $FEWndProc
//
// Message processing routine for the Function Editor window
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- FEWndProc"
#else
#define APPEND_NAME
#endif
LRESULT APIENTRY FEWndProc
(HWND hWnd, // Window handle
UINT message, // Type of message
WPARAM wParam, // Additional information
LPARAM lParam) // ...
{
HWND hWndEC, // Handle of Edit Ctrl window
hWndNxt, // Next window handle in doubly-linked list
hWndPrv; // Previous ...
LPUNDO_BUF lpUndoBeg, // Ptr to start of Undo Buffer
lpUndoNxt; // ... next available slot in the Undo Buffer
LPMEMVIRTSTR lpLclMemVirtStr; // Ptr to local MemVirtStr
LPPERTABDATA lpMemPTD; // Ptr to PerTabData global memory
////static DWORD aHelpIDs[] = {
//// IDOK, IDH_OK,
//// IDCANCEL, IDH_CANCEL,
//// IDC_APPLY, IDH_APPLY,
//// IDC_HELP2, IDH_HELP2,
//// 0, 0,
//// };
////LCLODSAPI ("FE: ", hWnd, message, wParam, lParam);
// Get the handle to the Edit Ctrl
hWndEC = (HWND) GetWindowLongPtrW (hWnd, GWLSF_HWNDEC);
switch (message)
{
#define lpMDIcs ((LPMDICREATESTRUCTW) ((*(LPCREATESTRUCTW *) &lParam)->lpCreateParams))
case WM_NCCREATE:
// Allocate room for FCNMEMVIRT_LENGTH MemVirtStrs
// (see FCNMEMVIRTENUM)
lpLclMemVirtStr =
MyVirtualAlloc (NULL, // Any address (FIXED SIZE)
FCNMEMVIRT_LENGTH * sizeof (MEMVIRTSTR),
MEM_COMMIT | MEM_TOP_DOWN,
PAGE_READWRITE);
if (lpLclMemVirtStr EQ NULL)
{
// ***FIXME*** -- Display error msg
DbgMsgW (L"FEWndProc/WM_NCCREATE: MyVirtualAlloc for <lpLclMemVirtStr> failed");
return -1;
} // End IF
// Save the ptr in window extra bytes
SetWindowLongPtrW (hWnd, GWLSF_LPMVS, (APLU3264) (LONG_PTR) lpLclMemVirtStr);
// Save the initial function line # display state in window extra bytes
SetWindowLongW (hWnd, GWLSF_FLN, OptionFlags.bDefDispFcnLineNums);
break;
#undef lpMDIcs
#define lpMDIcs ((LPMDICREATESTRUCTW) ((*(LPCREATESTRUCTW *) &lParam)->lpCreateParams))
case WM_CREATE: // lpcs = (LPCREATESTRUCTW) lParam; // Structure with creation data
{
LPSYMENTRY lpSymName; // Ptr to function name STE
HGLOBAL hGlbDfnHdr = NULL; // User-defined function/operator header global memory handle
LPDFN_HEADER lpMemDfnHdr; // Ptr to user-defined function/operator header global memory
// Get ptr to PerTabData global memory
lpMemPTD = GetMemPTD ();
// Initialize variables
cfFE.hwndOwner = hWnd;
// Save the ptr to this window's menu positions
SetPropW (hWnd, PROP_IDMPOSFN, (HANDLE) GetIDMPOS_FE);
// See if there is an existing function
lpSymName = ParseFunctionName (hWnd, (*(LPFE_CREATESTRUCTW *) &lpMDIcs->lParam)->lpwszLine);
if (lpSymName NE NULL)
{
// If it has a value and is not a user-defined function/operator, ...
if (lpSymName->stFlags.Value
&& !lpSymName->stFlags.UsrDfn)
{
((LPFE_CREATESTRUCTW) (lpMDIcs->lParam))->ErrCode = lpSymName->stFlags.stNameType;
return -1;
} else
if (lpSymName->stData.stGlbData NE NULL)
{
// Get the global memory handle
hGlbDfnHdr = lpSymName->stData.stGlbData;
// Lock the memory to get a ptr to it
lpMemDfnHdr = MyGlobalLockDfn (hGlbDfnHdr);
} // End IF/ELSE
} // End IF
// Get the ptr to the local virtual memory struc
(HANDLE_PTR) lpLclMemVirtStr = GetWindowLongPtrW (hWnd, GWLSF_LPMVS);
// *************** Undo Buffer *****************************
// _BEG is the (static) ptr to the beginning of the virtual memory.
// _NXT is the (dynamic) ptr to the next available entry.
// Undo entries are between _NXT[-1] and _BEG, inclusive.
// _LST is the (dynamic) ptr to the last available entry.
// Redo entries are between _NXT and _LST[-1], inclusive.
// Allocate virtual memory for the Undo Buffer
lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG].lpText = "lpUndoBeg in <FEWndProc>";
lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG].IncrSize = DEF_UNDOBUF_INCRNELM * sizeof (UNDO_BUF);
lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG].MaxSize = DEF_UNDOBUF_MAXNELM * sizeof (UNDO_BUF);
lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG].IniAddr = (LPUCHAR)
lpUndoBeg =
GuardAlloc (NULL, // Any address
lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG].MaxSize,
MEM_RESERVE,
PAGE_READWRITE);
if (lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG].IniAddr EQ NULL)
{
// ***FIXME*** -- WS FULL before we got started???
DbgMsgW (L"FEWndProc/WM_CREATE: VirtualAlloc for <lpUndoBeg> failed");
return -1;
} // End IF
// Link this struc into the chain
LinkMVS (&lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG]);
// Commit the intial size
MyVirtualAlloc (lpLclMemVirtStr[FCNMEMVIRT_UNDOBEG].IniAddr,
DEF_UNDOBUF_INITNELM * sizeof (UNDO_BUF),
MEM_COMMIT,
PAGE_READWRITE);
// Save in window extra bytes
SetWindowLongPtrW (hWnd, GWLSF_UNDO_BEG, (APLU3264) (LONG_PTR) lpUndoBeg);
SetWindowLongPtrW (hWnd, GWLSF_UNDO_NXT, (APLU3264) (LONG_PTR) lpUndoBeg);
SetWindowLongPtrW (hWnd, GWLSF_UNDO_LST, (APLU3264) (LONG_PTR) lpUndoBeg);
////////////SetWindowLongW (hWnd, GWLSF_UNDO_GRP, 0); // Already zero
// Start with an initial action of nothing
AppendUndo (hWnd, // FE Window handle
GWLSF_UNDO_NXT, // Offset in hWnd extra bytes of lpUndoNxt
undoNone, // Action
0, // Beginning char position
0, // Ending ...
UNDO_NOGROUP, // Group index
0); // Character
// Save incremented starting ptr in window extra bytes
SetWindowLongPtrW (hWnd, GWLSF_UNDO_BEG, (APLU3264) (LONG_PTR) ++lpUndoBeg);
// If there's a pre-existing function,
// and there's an Undo Buffer
if (hGlbDfnHdr NE NULL
&& lpMemDfnHdr->hGlbUndoBuff)
{
LPUNDO_BUF lpMemUndo; // Ptr to Undo Buffer global memory
SIZE_T uUndoSize; // Size of Undo Buffer in bytes
HGLOBAL hGlbUndoBuff;
// Get the handle
hGlbUndoBuff = lpMemDfnHdr->hGlbUndoBuff;
// Get the size in bytes
uUndoSize = MyGlobalSize (hGlbUndoBuff);
// Lock the memory to get a ptr to it
lpMemUndo = MyGlobalLock (hGlbUndoBuff);
__try
{
// Copy the previous Undo Buffer contents
CopyMemory (lpUndoBeg, lpMemUndo, uUndoSize);
} __except (CheckVirtAlloc (GetExceptionInformation (),
L"FEWndProc/WM_CREATE"))
{} // End __try/__except
// We no longer need this ptr
MyGlobalUnlock (hGlbUndoBuff); lpMemUndo = NULL;
// Get the ptr to the next available entry
lpUndoNxt = (LPUNDO_BUF) ByteAddr (&lpUndoBeg[1], uUndoSize);
// Save in window extra bytes
SetWindowLongPtrW (hWnd, GWLSF_UNDO_NXT, (APLU3264) (LONG_PTR) lpUndoNxt);
SetWindowLongPtrW (hWnd, GWLSF_UNDO_LST, (APLU3264) (LONG_PTR) lpUndoNxt);
} // End IF
// Create an Edit Ctrl within which we can edit
hWndEC =
CreateWindowExW (0L, // Extended styles
LECWNDCLASS, // Class name
L"", // Initial text
0
| WS_CHILD
| WS_VSCROLL
| ES_MULTILINE
| ES_WANTRETURN
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
, // Styles
0, // X-position
0, // Y-...
CW_USEDEFAULT, // Width
CW_USEDEFAULT, // Height
hWnd, // Parent window
(HMENU) IDWC_FE_EC, // ID
_hInstance, // Instance
0); // lParam
if (hWndEC EQ NULL)
{
MB (pszNoCreateFEEditCtrl);
return -1; // Stop the whole process
} // End IF
// Save in window extra bytes
SetWindowLongPtrW (hWnd, GWLSF_HWNDEC , (APLU3264) (LONG_PTR) hWndEC);
SetWindowLongPtrW (hWnd, GWLSF_HGLBDFNHDR, (APLU3264) (LONG_PTR) hGlbDfnHdr);
// Set the paint hook
SendMessageW (hWndEC, EM_SETPAINTHOOK, 0, (LPARAM) &LclECPaintHook);
// Set the soft-break flag
SendMessageW (hWndEC, EM_FMTLINES, TRUE, 0);
// If there's a pre-existing function,
// read in its lines as the initial text
if (hGlbDfnHdr NE NULL)
{
HGLOBAL hGlbTxtLine; // Line/header text global memory handle
LPMEMTXT_UNION lpMemTxtLine; // Ptr to header/line text global memory
UINT numFcnLines, // # lines in the function
uLineNum; // Line #
LPFCNLINE lpFcnLines; // Ptr to array function line structs (FCNLINE[numFcnLines])
// If this function is an AFO, ...
if (lpMemDfnHdr->bAFO)
{
HGLOBAL hGlbName; // Name text global memory handle
LPWCHAR lpMemName; // Ptr to the name's text
Assert (lpSymName NE NULL);
// Get the global memory handle of the AFO name
hGlbName = lpSymName->stHshEntry->htGlbName;
// Lock the memory to get a ptr to it
lpMemName = MyGlobalLockWsz (hGlbName);
// Append the text to the Edit Ctrl
ReplaceSel (hWndEC, TRUE, (LPARAM) lpMemName);
// We no longer need this ptr
MyGlobalUnlock (hGlbName); lpMemName = NULL;
} else
{
// Get the function header text global memory handle
hGlbTxtLine = lpMemDfnHdr->hGlbTxtHdr;
// Lock the memory to get a ptr to it
lpMemTxtLine = MyGlobalLockTxt (hGlbTxtLine);
// Append the text to the Edit Ctrl
ReplaceSel (hWndEC, TRUE, (LPARAM) &lpMemTxtLine->C);
// We no longer need this ptr
MyGlobalUnlock (hGlbTxtLine); lpMemTxtLine = NULL;
} // End IF/ELSE
// Get the # logical lines in the function
numFcnLines = lpMemDfnHdr->numFcnLines;
// Get ptr to array of function line structs (FCNLINE[numFcnLines])
lpFcnLines = (LPFCNLINE) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offFcnLines);
// Loop through the lines, appending the text to the Edit Ctrl
for (uLineNum = 0; uLineNum < numFcnLines; uLineNum++)
{
// Append a CRLF to the Edit Ctrl
ReplaceSel (hWndEC, TRUE, (LPARAM) WS_CRLF);
// Get the line text global memory handle
hGlbTxtLine = lpFcnLines->hGlbTxtLine;
// Lock the memory to get a ptr to it
lpMemTxtLine = MyGlobalLockTxt (hGlbTxtLine);
// Append the text to the Edit Ctrl
ReplaceSel (hWndEC, TRUE, (LPARAM) &lpMemTxtLine->C);
// We no longer need this ptr
MyGlobalUnlock (hGlbTxtLine); lpMemTxtLine = NULL;
// Skip to the next struct
lpFcnLines++;
} // End FOR
} else
// Set the initial text
ReplaceSel (hWndEC,
TRUE,
(LPARAM) (((LPFE_CREATESTRUCTW) (lpMDIcs->lParam))->lpwszLine));
// Mark as no changes so far
SetWindowLongW (hWnd, GWLSF_CHANGED, FALSE);
// If there's a pre-existing function, ...
if (hGlbDfnHdr NE NULL)
{
// We no longer need this ptr
MyGlobalUnlock (hGlbDfnHdr); lpMemDfnHdr = NULL;
} // End IF
// Paint the window
ShowWindow (hWndEC, SW_SHOWNORMAL);
UpdateWindow (hWndEC);
// Use Post here as we need to wait for the EC window
// to be drawn.
PostMessageW (hWnd, MYWM_INIT_EC, 0, 0);
// Link this FE window into the doubly-linked list of FE windows
hWndNxt = lpMemPTD->hWndFENxt;
// Save as our next window
SetWindowLongPtrW (hWnd, GWLFE_HWNDNXT, (APLU3264) (LONG_PTR) hWndNxt);
// Clear our prev window
SetWindowLongPtrW (hWnd, GWLFE_HWNDPRV, (APLU3264) (LONG_PTR) NULL);
// If there are other FE windows, ...
if (hWndNxt NE NULL)
{
Assert ((HWND) GetWindowLongPtrW (hWndNxt, GWLFE_HWNDPRV) EQ NULL);
// Save our window handle as the next's prev
SetWindowLongPtrW (hWndNxt, GWLFE_HWNDPRV, (APLU3264) (LONG_PTR) hWnd);
} // End IF
// Save our window handle as the new next
lpMemPTD->hWndFENxt = hWnd;
break;
} // End WM_CREATE
#undef lpMDIcs
case MYWM_INIT_EC:
{
UINT uLineLen; // Line length
UBOOL bAFO; // TRUE iff this window is an AFO
// Write out the FE window title
bAFO = SetFETitle (hWnd);
// Draw the line #s
DrawLineNumsFE (hWndEC);
// Get the length of the function header block
uLineLen = GetBlockLength (hWndEC, 0);
// If it's an AFO, ...
if (bAFO)
// Plus the line terminator and the length of the first line
uLineLen = sizeof (WS_CRLF) + GetBlockLength (hWndEC, 1);
// Set the caret to that character
SendMessageW (hWndEC, EM_SETSEL, uLineLen, uLineLen);
return FALSE; // We handled the msg
} // End MYWM_INIT_EC
#define uLen ((UINT) wParam)
#define lpwName ((LPWCHAR) lParam)
case MYWM_CMPNAME: // uLen = (UINT) wParam
// lpwName = (LPWCHAR) lParam
{
UINT uNameLen; // Function name length
LPWCHAR lpwszTemp; // Ptr to temporary storage
LRESULT lResult; // Result
VARS_TEMP_OPEN
// Get ptr to PerTabData global memory
lpMemPTD = GetMemPTD ();
// Get ptr to temporary storage
lpwszTemp = lpMemPTD->lpwszTemp;
CHECK_TEMP_OPEN
// Get this window's function name (if any)
uNameLen = GetFunctionName (hWnd, lpwszTemp, NULL);
if (uNameLen NE 0 && uNameLen EQ uLen)
lResult = (strncmpW (lpwszTemp, lpwName, uNameLen) EQ 0);
else
lResult = FALSE;
EXIT_TEMP_OPEN
return lResult; // TRUE iff the names are equal
} // End MYWM_CMPNAME
#undef lpwName
#undef uLen
case MYWM_SAVE_FN:
// Save the function (if well-formed)
SaveFunction (hWnd);
return FALSE; // We handled the msg
case MYWM_SAVECLOSE_FN:
// Save the function (if well-formed)
if (SaveFunction (hWnd))
// Close the function (if allowed)
CloseFunction (hWnd);
return FALSE; // We handled the msg
case MYWM_CLOSE_FN:
// Close the function (if allowed)
CloseFunction (hWnd);
return FALSE; // We handled the msg
////////case MYWM_SAVE_AS_FN:
//////// // Save the function (if well-formed) under a different name
//////// SaveAsFunction (hWnd);
////////
//////// return FALSE; // We handled the msg
case WM_SYSCOLORCHANGE:
case WM_SETTINGCHANGE:
// Uninitialize window-specific resources
FE_Delete (hWnd);
// Initialize window-specific resources
FE_Create (hWnd);
break; // Continue with next handler
case WM_CTLCOLOREDIT: // hdcEdit = (HDC) wParam; // handle of display context
// hwndEdit = (HWND) lParam; // handle of static control
// Ensure it's from our Edit Ctrl
if (hWndEC EQ (HWND) lParam)
return (LRESULT) ghBrushBG;
else
break;
#define lpnmEC (*(LPNMEDITCTRL *) &lParam)
case WM_NOTIFY: // idCtrl = (int) wParam;
// pnmh = (LPNMHDR) lParam;
// Ensure it's from our Edit Ctrl
if (lpnmEC->nmHdr.hwndFrom EQ hWndEC)
// Pass on to LclEditCtrlWndProc
SendMessageW (hWndEC, MYWM_NOTIFY, wParam, lParam);
return FALSE; // We handled the msg
#undef lpnmEC
#define fwSizeType wParam
#define nWidth (LOWORD (lParam))
#define nHeight (HIWORD (lParam))
case WM_SIZE: // fwSizeType = wParam; // Resizing flag
// nWidth = LOWORD(lParam); // Width of client area
// nHeight = HIWORD(lParam); // Height of client area
if (fwSizeType NE SIZE_MINIMIZED)
SetWindowPos (hWndEC, // Window handle to position
0, // SWP_NOZORDER
0, // X-position
0, // Y-...
nWidth, // Width
nHeight, // Height
SWP_NOZORDER // Flags
| SWP_SHOWWINDOW
);
break; // *MUST* pass on to DefMDIChildProcW
#undef nHeight
#undef nWidth
#undef fwSizeType
case WM_SETFONT:
// Pass on to the Edit Ctrl
SendMessageW (hWndEC, message, wParam, lParam);
// Changing the font also means changing the size
// of the margins as the character width might change
SetMarginsFE (hWndEC);
return FALSE; // We handled the msg
case MYWM_SETFOCUS:
// Set the focus to the Function Editor so the cursor displays
SetFocus (hWnd);
return FALSE; // We handled the msg
case WM_SETFOCUS:
// Pass on to the Edit Ctrl
SetFocus (hWndEC);
// Draw the line #s
DrawLineNumsFE (hWndEC);
break; // *MUST* pass on to DefMDIChildProcW
case WM_MDIACTIVATE: // Activate/de-activate a child window
// If we're being activated, ...
if (GET_WM_MDIACTIVATE_FACTIVATE (hWnd, wParam, lParam))
{
ActivateMDIMenu (WINDOWCLASS_FE, hWnd);
SetFocus (hWnd);
SendMessageW (hWndEC, EM_SCROLLCARET, 0, 0);
} // End IF
break; // Continue with DefMDIChildProcW
case WM_UNDO:
case MYWM_REDO:
case WM_COPY:
case MYWM_COPY_APL:
case WM_CUT:
case WM_PASTE:
case MYWM_PASTE_APL:
case WM_CLEAR:
case MYWM_SELECTALL:
// Pass on to the Edit Ctrl
SendMessageW (hWndEC, message, wParam, lParam);
return FALSE; // We handled the msg
#define wNotifyCode (HIWORD (wParam))
#define wID (LOWORD (wParam))
#define hWndCtrl MakeGlbFromVal (lParam)
case WM_COMMAND: // wNotifyCode = HIWORD (wParam); // Notification code
// wID = LOWORD (wParam); // Item, control, or accelerator identifier
// hwndCtrl = (HWND) lParam; // Handle of control
// This message should be from the Edit Ctrl
Assert (wID EQ IDWC_FE_EC);
Assert (hWndCtrl EQ hWndEC);
// Split cases based upon the notify code
switch (wNotifyCode)
{
UBOOL bChanged;
UINT iLinePos,
iLineNum;
case EN_CHANGE: // idEditCtrl = (int) LOWORD(wParam); // identifier of Edit Ctrl
// hwndEditCtrl = (HWND) lParam; // handle of Edit Ctrl
// Split cases based upon the last key
switch (GetWindowLongW (hWnd, GWLSF_LASTKEY))
{
case VK_RETURN:
case VK_BACK:
case VK_DELETE:
// Draw the line #s
DrawLineNumsFE (hWndEC);
break;
} // End SWITCH
// Get the current changed flag
bChanged = GetWindowLongW (hWnd, GWLSF_CHANGED);
// The contents of the Edit Ctrl have changed,
// set the changed flag
SetWindowLongW (hWnd, GWLSF_CHANGED, TRUE);
// If the Changed flag has changed, ...
if (!bChanged)
// Write out the FE window title
SetFETitle (hWnd);
// Get the char index of the first char in the current line
iLinePos = (UINT) SendMessageW (hWndEC, EM_LINEINDEX, -1, 0);
// Get the line number that contains the specified position
iLineNum = (UINT) SendMessageW (hWndEC, EM_LINEFROMCHAR, iLinePos, 0);
// If the cursor is in block #0 (the function header),
// the user might have changed the name of the function,
// so we need to rewrite the Function Editor window title,
// or if Syntax Coloring is in effect, the user might
// have changed the localization status of a var,
// so we need to repaint the whole window to reflect
// the possible change in syntax colors.
if (0 EQ GetBlockStartLine (hWndEC, iLineNum))
{
// If the Changed flag didn't change, ...
if (bChanged)
// Write out the FE window title
SetFETitle (hWnd);
// If we're Syntax Coloring function lines, ...
if (OptionFlags.bSyntClrFcns)
InvalidateRect (hWndEC, NULL, FALSE);
} // End IF
break;
case EN_MAXTEXT: // idEditCtrl = (int) LOWORD(wParam); // Identifier of Edit Ctrl
// hwndEditCtrl = (HWND) lParam; // Handle of Edit Ctrl
// The Edit Ctrl has exceed its maximum # chars
// The default maximum is 32K, so we increase it by that amount
SendMessageW (hWndEC,
EM_SETLIMITTEXT,
SendMessageW (hWndEC, EM_GETLIMITTEXT, 0, 0) + 32*1024, 0);
break;
//// case EN_SETFOCUS: // 0x0100
//// case EN_KILLFOCUS: // 0x0200
//// case EN_CHANGE: // 0x0300
//// case EN_UPDATE: // 0x0400
//// case EN_ERRSPACE: // 0x0500
//// case EN_MAXTEXT: // 0x0501
//// case EN_HSCROLL: // 0x0601
//// case EN_VSCROLL: // 0x0602
break;
} // End SWITCH
break;
#undef hWndCtrl
#undef wID
#undef wNotifyCode
case WM_QUERYENDSESSION:
case WM_CLOSE:
// If it's OK to close the window, do so, else ignore
if (!QueryCloseFE (hWnd))
return FALSE; // Do not close
break; // Default action is to close
case WM_DESTROY:
// *************** FCNMEMVIRTENUM Entries ******************
// Get the MemVirtStr ptr
lpLclMemVirtStr = (LPMEMVIRTSTR) GetWindowLongPtrW (hWnd, GWLSF_LPMVS);