source: trunk/dll/newview.c@ 1034

Last change on this file since 1034 was 1034, checked in by Gregg Young, 17 years ago

More fortify changes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 115.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: newview.c 1034 2008-06-30 14:17:03Z gyoung $
5
6 New internal viewer
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2008 Steven H. Levine
10
11 01 Dec 03 SHL Comments
12 02 Dec 03 SHL Correct WM_VSCROLL math
13 23 May 05 SHL Use QWL_USER
14 06 Jun 05 SHL Indent -i2
15 06 Jun 05 SHL Correct reversed wrap logic
16 17 Jul 06 SHL Use Runtime_Error
17 26 Jul 06 SHL Use chop_at_crnl and convert_nl_to_nul
18 03 Nov 06 SHL Renames
19 03 Nov 06 SHL Count thread usage
20 22 Mar 07 GKY Use QWL_USER
21 30 Mar 07 GKY Remove GetPString for window class names
22 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
23 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
24 26 Aug 07 GKY Fixed fast viewer text load failure
25 28 Aug 07 GKY Reversed horizontal scrollbar behavior to be present for unwrapped text and absent for wrapped text & hex.
26 14 Sep 07 SHL Another attempt to correct the fast viewer text load failure
27 10 Oct 07 SHL Correct ReLineThread typo
28 17 Dec 07 GKY Make WPURLDEFAULTSETTINGS the fall back for ftp/httprun
29 28 Dec 07 GKY Add mailrun to allow mailto by clicking on an email address in the viewer
30 29 Dec 07 GKY Formated email address using "<mailto:"
31 29 Feb 08 GKY Use xfree where appropriate
32 29 Feb 08 GKY Refactor global command line variables to notebook.h
33
34***********************************************************************/
35
36#include <stdlib.h>
37#include <string.h>
38#include <process.h>
39#include <limits.h>
40#include <share.h>
41
42#define INCL_DOS
43#define INCL_WIN
44#define INCL_GPI
45#define INCL_LONGLONG
46
47#include "fm3dlg.h"
48#include "fm3str.h"
49#include "mle.h"
50#include "makelist.h" // AddToList
51#include "errutil.h" // Dos_Error...
52#include "strutil.h" // GetPString
53#include "notebook.h" // httprun etc
54#include "fm3dll.h"
55#include "fortify.h"
56
57#pragma data_seg(DATA2)
58
59static PSZ pszSrcFile = __FILE__;
60
61#define VF_SELECTED 0x01
62#define VF_FOUND 0x02
63#define VF_HTTP 0x04
64#define VF_FTP 0x08
65
66#define FIXED_FONT_LCID 5
67
68#define COLORS_MAX 14
69
70#define COLORS_CURSOREDNORMALBACK 0
71#define COLORS_CURSOREDSELECTEDBACK 1
72#define COLORS_NORMALBACK 2
73#define COLORS_SELECTEDBACK 3
74#define COLORS_NORMALFORE 4
75#define COLORS_FOUNDFORE 5
76#define COLORS_SELECTEDFORE 6
77#define COLORS_SELECTEDFOUNDFORE 7
78#define COLORS_HTTPBACK 8
79#define COLORS_HTTPFORE 9
80#define COLORS_FTPBACK 10
81#define COLORS_FTPFORE 11
82#define COLORS_MAILBACK 12
83#define COLORS_MAILFORE 13
84
85static LONG Colors[COLORS_MAX] = {
86 COLR_WHITE, COLR_DARKGRAY,
87 COLR_PALEGRAY, COLR_BLACK,
88 COLR_BLACK, COLR_RED,
89 COLR_WHITE, COLR_YELLOW,
90 COLR_PALEGRAY, COLR_DARKBLUE,
91 COLR_PALEGRAY, COLR_DARKGREEN,
92 COLR_PALEGRAY, COLR_DARKRED
93};
94
95#define SEARCHSTRINGLEN 1024
96
97typedef struct
98{
99 FATTRS fattrs;
100 LONG colors[COLORS_MAX];
101 CHAR *text;
102 CHAR **lines, *markedlines;
103 CHAR searchtext[SEARCHSTRINGLEN], *lastpos, szFacename[FACESIZE];
104 ULONG textsize, numlines, topline, cursored, selected, numalloc, multiplier,
105 lastselected, found;
106 LONG oldwidth, lastdirection, lMaxAscender, lMaxDescender, lMaxHeight,
107 maxx, horzscroll;
108 HMTX ScanSem;
109 HWND hvscroll, hwndMenu, hwndStatus1, hwndStatus2, hwndStatus3, hwndRestore,
110 hwndPopup, hwndListbox, hwndFrame, hwndDrag, hwndParent, hhscroll;
111 HPS hps;
112 USHORT size;
113 USHORT flags;
114 USHORT cliptype;
115 CHAR filename[CCHMAXPATH];
116 CHAR stopflag, busy;
117 BOOL hex, mousecaptured, sensitive, dummy, literalsearch, clientfocused,
118 alsoselect, wrapon, relining, httpin, ftpin, mailin, ignorehttp, ignoreftp,
119 ignoremail, needrefreshing;
120}
121VIEWDATA;
122
123typedef struct
124{
125 ULONG len;
126 CHAR *line;
127 USHORT size;
128 USHORT dummy;
129 CHAR url[SEARCHSTRINGLEN];
130}
131URLDATA;
132
133static BOOL Sensitive = FALSE;
134static USHORT Codepage = 0;
135static BOOL Firsttime = TRUE;
136static BOOL LiteralSearch = FALSE;
137static BOOL AlsoSelect = FALSE;
138static BOOL WrapOn = FALSE;
139static BOOL IgnoreFTP = FALSE;
140static BOOL IgnoreHTTP = FALSE;
141static BOOL IgnoreMail = FALSE;
142static FATTRS Fattrs;
143
144// mailstr checks for a designated character in a string then cuts the string
145//to the first word that contains the character then prepends <mailto: and appends >
146
147CHAR *mailstr(CHAR *pszSrc, CHAR *pszFindChar, LONG StrLens)
148{
149 CHAR *pszCharCounter;
150 CHAR *pszTestStr = pszSrc;
151 CHAR szMailTo[1024] = "mailto:";
152 //CHAR szMailEnd[] = ">";
153
154 if (!strnstr(pszTestStr, pszFindChar, StrLens))
155 return NULL;
156 bstripcr(pszSrc);
157 remove_first_occurence_of_character("\r", pszSrc);
158 remove_first_occurence_of_character("\n", pszSrc);
159 if (!strstr(pszSrc, " ")){
160 if (!stristr(pszSrc, "<mailto:") && !fNoMailtoMailRun) {
161 strip_lead_char("<", pszSrc);
162 strip_trail_char(">", pszSrc);
163 strcat(szMailTo, pszSrc);
164 // strcat(szMailTo, szMailEnd);
165 pszSrc = szMailTo;
166 return pszSrc;
167 }
168 else {
169 strip_lead_char("<", pszSrc);
170 strip_trail_char(">", pszSrc);
171 return pszSrc;
172 }
173 }
174 while (strchr(pszSrc, ' ') < strchr(pszSrc, *pszFindChar)){
175 pszCharCounter = pszSrc;
176 while (*pszCharCounter && *pszCharCounter != ' '){
177 *pszCharCounter = ' ';
178 pszCharCounter++;
179 }
180 lstrip(pszSrc);
181 }
182 pszCharCounter = pszSrc;
183 while (*pszCharCounter && *pszCharCounter != ' ' && *pszCharCounter != '\r' &&
184 *pszCharCounter != '\n' && *pszCharCounter != '\"')
185 pszCharCounter++;
186 *pszCharCounter = 0;
187 if (!stristr(pszSrc, "<mailto:") && !fNoMailtoMailRun) {
188 strip_lead_char("<", pszSrc);
189 strip_trail_char(">", pszSrc);
190 strcat(szMailTo, pszSrc);
191 //strcat(szMailTo, szMailEnd);
192 pszSrc = szMailTo;
193 return pszSrc;
194 }
195 else {
196 strip_lead_char("<", pszSrc);
197 strip_trail_char(">", pszSrc);
198 return pszSrc;
199 }
200}
201
202MRESULT EXPENTRY UrlDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
203{
204 URLDATA *urld;
205
206 switch (msg) {
207 case WM_INITDLG:
208 if (mp2) {
209 CHAR *p, *e, *pp;
210 SHORT count;
211
212 WinSetWindowPtr(hwnd, QWL_USER, mp2);
213 urld = mp2;
214 e = urld->line + urld->len + 1;
215 p = urld->line;
216 do {
217 p = strnstr(p, "http://", e - p);
218 if (p) {
219 strncpy(urld->url, p, min(e - p, SEARCHSTRINGLEN - 1));
220 urld->url[min(e - p, SEARCHSTRINGLEN - 1)] = 0;
221 pp = urld->url;
222 while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' &&
223 *pp != '\"')
224 pp++;
225 *pp = 0;
226 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
227 MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
228 p++;
229 }
230 }
231 while (p && *p && p < e);
232 p = urld->line;
233 do {
234 p = strnstr(p, "ftp://", e - p);
235 if (p) {
236 strncpy(urld->url, p, min(e - p, SEARCHSTRINGLEN - 1));
237 urld->url[min(e - p, SEARCHSTRINGLEN - 1)] = 0;
238 pp = urld->url;
239 while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' &&
240 *pp != '\"')
241 pp++;
242 *pp = 0;
243 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
244 MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
245 p++;
246 }
247 }
248 while (p && *p && p < e);
249 p = urld->line;
250 if (mailstr(p, "@", e - p)) {
251 pp = mailstr(p, "@", e - p);
252 strcpy(urld->url, pp);
253 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
254 MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
255 }
256 *urld->url = 0;
257 count = (SHORT) WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_QUERYITEMCOUNT,
258 MPVOID, MPVOID);
259 if (count) {
260 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_SELECTITEM,
261 MPFROMSHORT(0), MPFROMSHORT(TRUE));
262 if (count == 1)
263 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
264 else
265 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
266 break;
267 }
268 }
269 WinDismissDlg(hwnd, 0);
270 break;
271
272 case UM_SETUP:
273 WinShowWindow(hwnd, TRUE);
274 return 0;
275
276 case WM_CONTROL:
277 switch (SHORT1FROMMP(mp1)) {
278 case URL_LISTBOX:
279 switch (SHORT2FROMMP(mp1)) {
280 case LN_ENTER:
281 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
282 break;
283 }
284 break;
285 }
286 return 0;
287
288 case WM_COMMAND:
289 switch (SHORT1FROMMP(mp1)) {
290 case URL_BOOKMARK:
291 WinDismissDlg(hwnd, 3);
292 break;
293
294 case DID_OK:
295 {
296 SHORT select;
297
298 urld = WinQueryWindowPtr(hwnd, QWL_USER);
299 if (urld) {
300 select = (SHORT) WinSendDlgItemMsg(hwnd, URL_LISTBOX,
301 LM_QUERYSELECTION,
302 MPFROMSHORT(LIT_FIRST), MPVOID);
303 if (select >= 0) {
304 *urld->url = 0;
305 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_QUERYITEMTEXT,
306 MPFROM2SHORT(select, sizeof(urld->url)),
307 MPFROMP(urld->url));
308 if (*urld->url) {
309 if (!strncmp(urld->url, "http://", 7)) {
310 WinDismissDlg(hwnd, 1);
311 break;
312 }
313 else if (!strncmp(urld->url, "ftp://", 6)) {
314 memmove(urld->url, urld->url + 6, strlen(urld->url) + 1);
315 if (*urld->url) {
316 WinDismissDlg(hwnd, 2);
317 break;
318 }
319 }
320 else if (strchr(urld->url, '@')) {
321 WinDismissDlg(hwnd, 3);
322 break;
323 }
324 }
325 }
326 }
327 }
328 Runtime_Error(pszSrcFile, __LINE__, "no data");
329 break;
330
331 case DID_CANCEL:
332 WinDismissDlg(hwnd, 0);
333 break;
334
335 case IDM_HELP:
336 break;
337 }
338 return 0;
339 }
340 return WinDefDlgProc(hwnd, msg, mp1, mp2);
341}
342
343static ULONG NumLines(RECTL * rcl, VIEWDATA * ad)
344{
345 ULONG numlines;
346
347 numlines = (rcl->yTop - rcl->yBottom) / ad->lMaxHeight;
348 if (ad->lMaxDescender && numlines &&
349 ((rcl->yTop - rcl->yBottom) -
350 (numlines * ad->lMaxHeight) <= ad->lMaxDescender))
351 numlines--;
352 return numlines;
353}
354
355static CHAR **BuildAList(HWND hwnd)
356{
357 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
358 register ULONG x, y, z = 0;
359 ULONG width;
360 RECTL Rectl;
361 CHAR **list = NULL, s[SEARCHSTRINGLEN], a;
362 register CHAR *p, *e;
363 UINT numlines = 0, numalloc = 0;
364
365 if (ad && ad->selected) {
366 WinQueryWindowRect(hwnd, &Rectl);
367 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
368 if (!width && !ad->hex)
369 return list;
370 for (x = 0; x < ad->numlines; x++) {
371 if (ad->stopflag)
372 break;
373 if (ad->markedlines[x] & VF_SELECTED) {
374 if (ad->hex) {
375 width = ad->textsize - (x * 16);
376 width = min(width, 16);
377 sprintf(s, "%08lx ", x * 16);
378 p = s + 9;
379 for (y = 0; y < width; y++) {
380 sprintf(p, " %02x", (UCHAR)ad->text[(x * 16) + y]);
381 p += 3;
382 }
383 *p = ' ';
384 p++;
385 *p = ' ';
386 p++;
387 for (y = 0; y < width; y++) {
388 a = ad->text[(x * 16) + y];
389 if (a && a != '\n' && a != '\r' && a != '\t' && a != '\x1a')
390 *p = ad->text[(x * 16) + y];
391 else
392 *p = '.';
393 p++;
394 }
395 *p = 0;
396 }
397 else {
398 if (!ad->wrapon) {
399 e = p = ad->lines[x];
400 while (*e != '\r' && *e != '\n' && e < ad->text + ad->textsize)
401 e++;
402 /* fixme to be gone?
403 if((*e == '\r' || *e == '\n') && e > p)
404 e--;
405 */
406 width = e - p;
407 }
408 else {
409 p = ad->lines[x];
410 e = p + (width - 1);
411 if (e - ad->text > ad->textsize)
412 e = ad->text + ad->textsize;
413 while (p < e) {
414 if (*p == '\r' || *p == '\n') {
415 e = p;
416 break;
417 }
418 p++;
419 }
420 }
421 strncpy(s, ad->lines[x], e - ad->lines[x]);
422 s[e - ad->lines[x]] = 0;
423 }
424 if (AddToList(s, &list, &numlines, &numalloc))
425 break;
426 z++;
427 if (z >= ad->selected)
428 break;
429 }
430 }
431 }
432 return list;
433}
434
435static CHAR **BuildAList2(HWND hwnd)
436{
437 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
438 CHAR **list = NULL, s[SEARCHSTRINGLEN];
439 SHORT x, z;
440 UINT numlines = 0, numalloc = 0;
441
442 if (ad) {
443 z = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
444 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
445 z = max(z, 0);
446 for (x = 0; x < z; x++) {
447 if (ad->stopflag)
448 break;
449 *s = 0;
450 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_QUERYITEMTEXT,
451 MPFROM2SHORT(x, SEARCHSTRINGLEN), MPFROMP(s));
452 if (*s)
453 if (AddToList(s, &list, &numlines, &numalloc))
454 break;
455 }
456 }
457 return list;
458}
459
460MRESULT EXPENTRY ViewStatusProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
461{
462 switch (msg) {
463 case WM_CREATE:
464 return CommonTextProc(hwnd, msg, mp1, mp2);
465
466 case WM_MOUSEMOVE:
467 {
468 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
469
470 if (fOtherHelp) {
471 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
472 && !WinQueryCapture(HWND_DESKTOP)) {
473
474 char *s = NULL;
475
476 switch (id) {
477 case NEWVIEW_STATUS2:
478 s = GetPString(IDS_NVSTATUS2HELPTEXT);
479 break;
480 case NEWVIEW_STATUS3:
481 s = GetPString(IDS_NVSTATUS3HELPTEXT);
482 break;
483 case NEWVIEW_DRAG:
484 s = GetPString(IDS_NVDRAGHELPTEXT);
485 break;
486 }
487 if (s && *s)
488 MakeBubble(hwnd, TRUE, s);
489 else if (hwndBubble)
490 WinDestroyWindow(hwndBubble);
491 }
492 }
493 switch (id) {
494 case NEWVIEW_STATUS1:
495 break;
496 default:
497 return CommonTextButton(hwnd, msg, mp1, mp2);
498 }
499 }
500 break;
501
502 case WM_BUTTON3UP:
503 case WM_BUTTON1UP:
504 case WM_BUTTON1DOWN:
505 case WM_BUTTON3DOWN:
506 {
507 USHORT id;
508
509 id = WinQueryWindowUShort(hwnd, QWS_ID);
510 switch (id) {
511 case NEWVIEW_STATUS1:
512 break;
513 default:
514 return CommonTextButton(hwnd, msg, mp1, mp2);
515 }
516 }
517 break;
518
519 case UM_CLICKED:
520 case UM_CLICKED3:
521 {
522 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID), cmd = 0;
523
524 switch (id) {
525 case NEWVIEW_DRAG:
526 if (msg == UM_CLICKED)
527 cmd = (msg == UM_CLICKED) ? IDM_HEXMODE : IDM_DESELECTALL;
528 break;
529 case NEWVIEW_STATUS2:
530 cmd = (msg == UM_CLICKED) ? IDM_GOTOLINE : IDM_FINDFIRST;
531 break;
532 case NEWVIEW_STATUS3:
533 cmd = (msg == UM_CLICKED) ? IDM_GOTOOFFSET : IDM_FINDNEXT;
534 break;
535 default:
536 break;
537 }
538 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
539 FID_CLIENT),
540 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
541 }
542 return 0;
543
544 case WM_BEGINDRAG:
545 {
546 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
547
548 switch (id) {
549 case NEWVIEW_STATUS1:
550 case NEWVIEW_DRAG:
551 {
552 VIEWDATA *ad =
553 WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
554 QW_PARENT),
555 FID_CLIENT), QWL_USER);
556
557 if (ad)
558 DragOne(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
559 FID_CLIENT), (HWND) 0, ad->filename,
560 FALSE);
561 }
562 break;
563 default:
564 break;
565 }
566 }
567 break;
568
569 case WM_CONTEXTMENU:
570 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
571 FID_CLIENT), UM_CONTEXTMENU, MPVOID, MPVOID);
572 break;
573
574 case WM_SETFOCUS:
575 if (mp2)
576 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
577 break;
578
579 case WM_PAINT:
580 {
581 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
582 ULONG color;
583 VIEWDATA *ad = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
584 QW_PARENT),
585 FID_CLIENT), QWL_USER);
586 SWP swp;
587 POINTL ptl;
588 HPS hps;
589
590 switch (id) {
591 case NEWVIEW_STATUS1:
592 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, FALSE);
593 break;
594 default:
595 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
596 break;
597 }
598 hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
599 if (hps) {
600 WinQueryWindowPos(hwnd, &swp);
601 ptl.x = swp.x - 1;
602 ptl.y = swp.y + swp.cy + 2;
603 GpiMove(hps, &ptl);
604 switch (id) {
605 case NEWVIEW_STATUS1:
606 if (ad)
607 color =
608 (standardcolors[ad->colors[COLORS_NORMALBACK]] ==
609 CLR_WHITE) ? CLR_PALEGRAY : CLR_WHITE;
610 else
611 color = CLR_WHITE;
612 break;
613 default:
614 if (ad)
615 color =
616 (standardcolors[ad->colors[COLORS_NORMALBACK]] ==
617 CLR_PALEGRAY) ? CLR_DARKGRAY : CLR_PALEGRAY;
618 else
619 color = CLR_PALEGRAY;
620 break;
621 }
622 GpiSetColor(hps, color);
623 ptl.x = swp.x + swp.cx;
624 GpiLine(hps, &ptl);
625 WinReleasePS(hps);
626 }
627 }
628 break;
629
630 case UM_FOCUSME:
631 WinSetFocus(HWND_DESKTOP,
632 WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_CLIENT));
633 return 0;
634 }
635 return PFNWPStatic(hwnd, msg, mp1, mp2);
636}
637
638static VOID FreeViewerMem(HWND hwnd)
639{
640 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
641
642 if (ad) {
643 ad->selected = ad->textsize = ad->numlines = ad->numalloc = 0;
644 xfree(ad->text, pszSrcFile, __LINE__);
645 xfree(ad->lines, pszSrcFile, __LINE__);
646 xfree(ad->markedlines, pszSrcFile, __LINE__);
647 ad->text = NULL;
648 ad->lines = NULL;
649 ad->markedlines = NULL;
650 DosPostEventSem(CompactSem);
651# ifdef FORTIFY
652 xFortify_LeaveScope(pszSrcFile, __LINE__);
653# endif
654 }
655}
656
657static HPS InitWindow(HWND hwnd)
658{
659 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
660 HPS hps = (HPS) 0;
661 SIZEL sizel;
662 FONTMETRICS FontMetrics;
663
664 if (ad) {
665 sizel.cx = sizel.cy = 0;
666 hps = GpiCreatePS(WinQueryAnchorBlock(hwnd), WinOpenWindowDC(hwnd),
667 (PSIZEL) & sizel, PU_PELS | GPIF_DEFAULT | GPIT_MICRO |
668 GPIA_ASSOC);
669 if (hps) {
670 GpiSetCp(hps, (ULONG) ad->fattrs.usCodePage);
671 GpiCreateLogFont(hps, NULL, FIXED_FONT_LCID, &ad->fattrs);
672 GpiSetCharSet(hps, FIXED_FONT_LCID);
673 GpiQueryFontMetrics(hps, (long)sizeof(FONTMETRICS), &FontMetrics);
674 ad->fattrs.lAveCharWidth = FontMetrics.lAveCharWidth;
675 ad->fattrs.lMaxBaselineExt = FontMetrics.lMaxBaselineExt;
676 ad->lMaxAscender = max(FontMetrics.lMaxAscender, 0);
677 ad->lMaxDescender = max(FontMetrics.lMaxDescender, 0);
678 ad->lMaxHeight = ad->lMaxAscender + ad->lMaxDescender;
679 if (ad->fattrs.usCodePage != FontMetrics.usCodePage) {
680 ad->fattrs.usCodePage = FontMetrics.usCodePage;
681 Codepage = ad->fattrs.usCodePage;
682 PrfWriteProfileData(fmprof,
683 appname,
684 "Viewer.Codepage",
685 &ad->fattrs.usCodePage, sizeof(USHORT));
686 }
687 else if (ad->fattrs.usCodePage) {
688
689 HMQ hmq;
690 ULONG cps[50], len, x;
691
692 if (!DosQueryCp(sizeof(cps), cps, &len)) {
693 for (x = 0; x < len / sizeof(ULONG); x++) {
694 if (cps[x] == (ULONG) ad->fattrs.usCodePage) {
695 hmq = WinQueryWindowULong(hwnd, QWL_HMQ);
696 WinSetCp(hmq, ad->fattrs.usCodePage);
697 break;
698 }
699 }
700 }
701 DosSetProcessCp((ULONG) ad->fattrs.usCodePage);
702 }
703 GpiSetBackMix(hps, BM_OVERPAINT);
704 SetPresParamFromFattrs(WinWindowFromID(ad->hwndFrame, NEWVIEW_LISTBOX),
705 &ad->fattrs, FontMetrics.sNominalPointSize,
706 MAKEFIXED(FontMetrics.sNominalPointSize / 10,
707 0));
708 }
709 }
710 return (hps);
711}
712
713static VOID PaintLine(HWND hwnd, HPS hps, ULONG whichline, ULONG topline,
714 RECTL * Rectl)
715{
716 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
717 POINTL ptl;
718 ULONG width;
719 register CHAR *p, *e;
720 CHAR marker[] = " >";
721 RECTL rcl2;
722
723 if (ad && (ad->hex || ad->lines)) {
724 ptl.y = (Rectl->yTop - (ad->lMaxHeight *
725 (((whichline + 1) - topline) + 1)));
726 ptl.x = 0;
727 GpiMove(hps, &ptl);
728 GpiSetBackMix(hps, BM_OVERPAINT);
729 if (ad->markedlines) {
730 if (ad->markedlines[whichline] & VF_SELECTED) {
731 GpiSetColor(hps, ((ad->markedlines[whichline] & VF_FOUND) != 0) ?
732 standardcolors[ad->colors[COLORS_SELECTEDFOUNDFORE]] :
733 standardcolors[ad->colors[COLORS_SELECTEDFORE]]);
734 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
735 standardcolors[ad->
736 colors[COLORS_CURSOREDSELECTEDBACK]] :
737 standardcolors[ad->colors[COLORS_SELECTEDBACK]]);
738 }
739 else if (ad->markedlines[whichline] & VF_FOUND) {
740 GpiSetColor(hps, standardcolors[ad->colors[COLORS_FOUNDFORE]]);
741 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
742 standardcolors[ad->
743 colors[COLORS_CURSOREDNORMALBACK]] :
744 standardcolors[ad->colors[COLORS_NORMALBACK]]);
745 }
746 else {
747 GpiSetColor(hps, standardcolors[ad->colors[COLORS_NORMALFORE]]);
748 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
749 standardcolors[ad->
750 colors[COLORS_CURSOREDNORMALBACK]] :
751 standardcolors[ad->colors[COLORS_NORMALBACK]]);
752 }
753 }
754 else {
755 GpiSetColor(hps, standardcolors[ad->colors[COLORS_NORMALFORE]]);
756 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
757 standardcolors[ad->colors[COLORS_CURSOREDNORMALBACK]] :
758 standardcolors[ad->colors[COLORS_NORMALBACK]]);
759 }
760 if (!ad->hex) {
761 if (ad->wrapon) {
762 width = (Rectl->xRight - Rectl->xLeft) / ad->fattrs.lAveCharWidth;
763 if (width) {
764 GpiCharString(hps, 1, marker + (whichline == ad->cursored - 1));
765 p = ad->lines[whichline];
766 e = p + (width - 1);
767 if (e - ad->text > ad->textsize)
768 e = ad->text + ad->textsize;
769 while (p < e) {
770 if (*p == '\r' || *p == '\n') {
771 e = p;
772 break;
773 }
774 p++;
775 }
776 if (ad->ftpin && whichline != ad->cursored - 1
777 && (!ad->markedlines
778 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
779 && strnstr(ad->lines[whichline], "ftp://",
780 e - ad->lines[whichline])) {
781 GpiSetColor(hps, standardcolors[ad->colors[COLORS_FTPFORE]]);
782 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_FTPBACK]]);
783 }
784 if (ad->httpin && whichline != ad->cursored - 1
785 && (!ad->markedlines
786 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
787 && strnstr(ad->lines[whichline], "http://",
788 e - ad->lines[whichline])) {
789 GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
790 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
791 }
792
793 if (ad->mailin && whichline != ad->cursored - 1
794 && (!ad->markedlines
795 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
796 && strnstr(ad->lines[whichline], "@",e - ad->lines[whichline])) {
797 GpiSetColor(hps, standardcolors[ad->colors[COLORS_MAILFORE]]);
798 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_MAILBACK]]);
799 }
800 rcl2 = *Rectl;
801 rcl2.yTop = ptl.y + ad->lMaxAscender;
802 rcl2.yBottom = ptl.y - ad->lMaxDescender;
803 GpiCharString(hps, e - ad->lines[whichline], ad->lines[whichline]);
804 GpiQueryCurrentPosition(hps, &ptl);
805 rcl2.xLeft = ptl.x;
806 WinFillRect(hps, &rcl2,
807 standardcolors[ad->colors[COLORS_NORMALBACK]]);
808 }
809 }
810 else {
811 width = (Rectl->xRight - Rectl->xLeft) / ad->fattrs.lAveCharWidth;
812 if (width) {
813 GpiCharString(hps, 1, marker + (whichline == ad->cursored - 1));
814 p = ad->lines[whichline];
815 e = p + (abs(ad->horzscroll) / ad->fattrs.lAveCharWidth);
816 if (e - ad->text > ad->textsize)
817 e = ad->text + ad->textsize;
818 while (p < e) {
819 if (*p == '\r' || *p == '\n')
820 break;
821 p++;
822 }
823 if (*p != '\r' && *p != '\n') {
824
825 CHAR *pp;
826
827 e = p + (width - 1);
828 if (e - ad->text > ad->textsize)
829 e = ad->text + ad->textsize;
830 pp = p;
831 while (pp < e) {
832 if (*pp == '\r' || *pp == '\n') {
833 e = pp;
834 break;
835 }
836 pp++;
837 }
838 }
839 else
840 e = p;
841 if (ad->ftpin && whichline != ad->cursored - 1
842 && (!ad->markedlines
843 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
844 && strnstr(ad->lines[whichline], "ftp://",
845 e - ad->lines[whichline])) {
846 GpiSetColor(hps, standardcolors[ad->colors[COLORS_FTPFORE]]);
847 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_FTPBACK]]);
848 }
849 if (ad->httpin && whichline != ad->cursored - 1
850 && (!ad->markedlines
851 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
852 && strnstr(ad->lines[whichline], "http://",e - ad->lines[whichline])) {
853 GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
854 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
855 }
856
857 if (ad->mailin && whichline != ad->cursored - 1
858 && (!ad->markedlines
859 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
860 && strnstr(ad->lines[whichline], "@",e - ad->lines[whichline])) {
861 GpiSetColor(hps, standardcolors[ad->colors[COLORS_MAILFORE]]);
862 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_MAILBACK]]);
863 }
864 rcl2 = *Rectl;
865 rcl2.yTop = ptl.y + ad->lMaxAscender;
866 rcl2.yBottom = ptl.y - ad->lMaxDescender;
867 GpiCharString(hps, e - p, p);
868 GpiQueryCurrentPosition(hps, &ptl);
869 rcl2.xLeft = ptl.x;
870 WinFillRect(hps, &rcl2,
871 standardcolors[ad->colors[COLORS_NORMALBACK]]);
872 }
873 }
874 }
875 else {
876
877 CHAR s[80];
878 register ULONG x;
879
880 rcl2 = *Rectl;
881 rcl2.yTop = ptl.y + ad->lMaxAscender;
882 rcl2.yBottom = ptl.y - ad->lMaxDescender;
883 GpiCharString(hps, 1, marker + (whichline == ad->cursored - 1));
884 width = ad->textsize - (whichline * 16);
885 width = min(width, 16);
886 sprintf(s, "%08lx ", whichline * 16);
887 p = s + 9;
888 for (x = 0; x < width; x++) {
889 sprintf(p, " %02x", (UCHAR)ad->text[(whichline * 16) + x]);
890 p += 3;
891 }
892 for (; x < 16; x++) {
893 *p = ' ';
894 p++;
895 *p = ' ';
896 p++;
897 *p = ' ';
898 p++;
899 }
900 *p = ' ';
901 p++;
902 *p = ' ';
903 p++;
904 for (x = 0; x < width; x++) {
905 *p = ad->text[(whichline * 16) + x];
906 p++;
907 }
908 *p = 0;
909 GpiCharString(hps, (p - s) - (abs(ad->horzscroll) /
910 ad->fattrs.lAveCharWidth),
911 s + (abs(ad->horzscroll) / ad->fattrs.lAveCharWidth));
912 GpiQueryCurrentPosition(hps, &ptl);
913 if (ptl.x + abs(ad->horzscroll) + ad->fattrs.lAveCharWidth + 1 >
914 ad->maxx) {
915 ad->maxx = ptl.x + abs(ad->horzscroll) + ad->fattrs.lAveCharWidth + 1;
916 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
917 MPFROM2SHORT((SHORT) Rectl->xRight, (SHORT) ad->maxx),
918 MPVOID);
919 }
920 rcl2.xLeft = ptl.x;
921 WinFillRect(hps, &rcl2, standardcolors[ad->colors[COLORS_NORMALBACK]]);
922 }
923 }
924}
925
926static VOID SearchThread(VOID * args)
927{
928 HWND hwnd = (HWND) args;
929 HAB hab2;
930 HMQ hmq2;
931 VIEWDATA *ad;
932 register CHAR *p;
933 RECTL Rectl;
934 ULONG width, numlines, lastline, whichline, firstline = ULONG_MAX;
935 register ULONG x;
936 CHAR s[SEARCHSTRINGLEN], s2[SEARCHSTRINGLEN], *t, *n, markwith;
937
938 priority_normal();
939 hab2 = WinInitialize(0);
940 if (hab2) {
941 hmq2 = WinCreateMsgQueue(hab2, 0);
942 if (hmq2) {
943 WinCancelShutdown(hmq2, TRUE);
944 IncrThreadUsage();
945 ad = WinQueryWindowPtr(hwnd, QWL_USER);
946 if (ad) {
947 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
948 markwith = VF_FOUND | ((ad->alsoselect) ? VF_SELECTED : 0);
949 strcpy(s, ad->searchtext);
950 if (*s) {
951 WinQueryWindowRect(hwnd, &Rectl);
952 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
953 numlines = NumLines(&Rectl, ad);
954 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
955 NEWVIEW_STATUS1),
956 GetPString(IDS_SEARCHINGTEXT));
957 if (numlines && width && ad->markedlines && ad->numlines &&
958 ad->text && ad->textsize) {
959 for (x = 0; x < ad->numlines && !ad->stopflag; x++)
960 ad->markedlines[x] &= (~VF_FOUND);
961 ad->found = 0;
962 t = s;
963 while (t && !ad->stopflag) {
964 lastline = 1;
965 n = convert_nl_to_nul(t);
966 if (*t) {
967 strcpy(s2, t);
968 if (ad->literalsearch)
969 literal(s2);
970 p = ad->text;
971 while (p && !ad->stopflag) {
972 p = findstring(s2, strlen(s2), p,
973 ad->textsize - (p - ad->text),
974 ad->sensitive);
975 if (p) {
976 if (ad->hex) {
977 whichline = (p - ad->text) / 16;
978 if (whichline < firstline)
979 firstline = whichline;
980 if (!(ad->markedlines[whichline] & VF_FOUND))
981 ad->found++;
982 if (markwith & VF_SELECTED) {
983 if (!(ad->markedlines[whichline] & VF_SELECTED))
984 ad->selected++;
985 }
986 ad->markedlines[whichline] |= markwith;
987 if ((p - ad->text) + strlen(s2) >
988 (whichline + 1) * 16) {
989 whichline++;
990 if (!(ad->markedlines[whichline] & VF_FOUND))
991 ad->found++;
992 if (markwith & VF_SELECTED) {
993 if (!(ad->markedlines[whichline] & VF_SELECTED))
994 ad->selected++;
995 }
996 ad->markedlines[whichline] |= markwith;
997 }
998 p = ad->text + ((whichline + 1) * 16);
999 if (p >= ad->text + ad->textsize)
1000 break;
1001 }
1002 else {
1003 for (x = lastline; x < ad->numlines; x++) {
1004 if (ad->lines[x] > p) {
1005 if (x - 1 < firstline)
1006 firstline = x - 1;
1007 if (!(ad->markedlines[x - 1] & VF_FOUND))
1008 ad->found++;
1009 if (markwith & VF_SELECTED) {
1010 if (!(ad->markedlines[x - 1] & VF_SELECTED))
1011 ad->selected++;
1012 }
1013 ad->markedlines[x - 1] |= markwith;
1014 if (x + 1 < ad->numlines &&
1015 p + strlen(s2) > ad->lines[x]) {
1016 x++;
1017 if (!(ad->markedlines[x - 1] & VF_FOUND))
1018 ad->found++;
1019 if (markwith & VF_SELECTED) {
1020 if (!(ad->markedlines[x - 1] & VF_SELECTED))
1021 ad->selected++;
1022 }
1023 ad->markedlines[x - 1] |= markwith;
1024 }
1025 lastline = x;
1026 p = ad->lines[x];
1027 break;
1028 }
1029 }
1030 if (x >= ad->numlines) {
1031 if (markwith & VF_SELECTED) {
1032 if (!
1033 (ad->markedlines[numlines - 1] & VF_SELECTED))
1034 ad->selected++;
1035 if (!(ad->markedlines[numlines - 1] & VF_FOUND))
1036 ad->found++;
1037 }
1038 ad->markedlines[ad->numlines - 1] |= markwith;
1039 break;
1040 }
1041 }
1042 }
1043 }
1044 }
1045 t = n;
1046 }
1047 }
1048 DosReleaseMutexSem(ad->ScanSem);
1049 if (!ad->stopflag && firstline == ULONG_MAX) {
1050 DosBeep(50, 50);
1051 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1052 NEWVIEW_STATUS1),
1053 GetPString(IDS_NOMATCHINGTEXT));
1054 DosSleep(150);//05 Aug 07 GKY 1500
1055 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1056 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1057 }
1058 else if (!ad->stopflag) {
1059 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1060 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1061 PostMsg(hwnd, UM_CONTAINER_FILLED,
1062 MPFROMLONG(firstline + 1), MPFROMLONG(firstline + 1));
1063 }
1064 }
1065 else
1066 DosReleaseMutexSem(ad->ScanSem);
1067 }
1068 }
1069 WinDestroyMsgQueue(hmq2);
1070 }
1071 DecrThreadUsage();
1072 WinTerminate(hab2);
1073 }
1074 DosPostEventSem(CompactSem);
1075}
1076
1077static VOID ClipboardThread(VOID * args)
1078{
1079 HWND hwnd = (HWND) args;
1080 HAB hab2;
1081 HMQ hmq2;
1082 VIEWDATA *ad;
1083 CHAR **list;
1084 USHORT cmd;
1085 register ULONG x;
1086 BOOL released = FALSE;
1087
1088 priority_normal();
1089 hab2 = WinInitialize(0);
1090 if (hab2) {
1091 hmq2 = WinCreateMsgQueue(hab2, 0);
1092 if (hmq2) {
1093 WinCancelShutdown(hmq2, TRUE);
1094 IncrThreadUsage();
1095# ifdef FORTIFY
1096 Fortify_EnterScope();
1097# endif
1098 ad = WinQueryWindowPtr(hwnd, QWL_USER);
1099 if (ad) {
1100 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
1101 cmd = ad->cliptype;
1102 if (ad->numlines && ad->text && ad->textsize && ad->markedlines &&
1103 !ad->stopflag) {
1104 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1105 NEWVIEW_STATUS1),
1106 GetPString(IDS_BUILDINGLINELISTTEXT));
1107 if (cmd == IDM_SAVETOCLIP || cmd == IDM_APPENDTOCLIP ||
1108 cmd == IDM_SAVETOLIST)
1109 list = BuildAList(hwnd);
1110 else
1111 list = BuildAList2(hwnd);
1112 if (list) {
1113 if (!ad->stopflag) {
1114 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1115 NEWVIEW_STATUS1),
1116 (cmd == IDM_SAVETOCLIP ||
1117 cmd == IDM_SAVETOCLIP2) ?
1118 GetPString(IDS_SAVETOCLIPTEXT) :
1119 (cmd == IDM_APPENDTOCLIP ||
1120 cmd == IDM_APPENDTOCLIP2) ?
1121 GetPString(IDS_APPENDTOCLIPTEXT) :
1122 GetPString(IDS_WRITETOFILETEXT));
1123 DosReleaseMutexSem(ad->ScanSem);
1124 released = TRUE;
1125 if (cmd == IDM_SAVETOCLIP || cmd == IDM_APPENDTOCLIP ||
1126 cmd == IDM_SAVETOCLIP2 || cmd == IDM_APPENDTOCLIP2)
1127 ListToClipboardHab(hab2, list, (cmd == IDM_APPENDTOCLIP ||
1128 cmd == IDM_APPENDTOCLIP2));
1129 else {
1130
1131 FILE *fp;
1132 CHAR filename[CCHMAXPATH];
1133
1134 *filename = 0;
1135 if (export_filename(hwnd, filename, FALSE)) {
1136 fp = _fsopen(filename, "a+", SH_DENYWR);
1137 if (!fp) {
1138 saymsg(MB_CANCEL,
1139 hwnd,
1140 GetPString(IDS_ERRORTEXT),
1141 GetPString(IDS_CANTOPENFORWRITETEXT), filename);
1142 }
1143 else {
1144 fseek(fp, 0L, SEEK_END);
1145 for (x = 0; list[x]; x++)
1146 fprintf(fp, "%s\n", list[x]);
1147 fclose(fp);
1148 }
1149 }
1150 }
1151 }
1152 FreeList(list);
1153 }
1154 else {
1155 DosReleaseMutexSem(ad->ScanSem);
1156 released = TRUE;
1157 DosBeep(50, 100);
1158 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1159 NEWVIEW_STATUS1),
1160 GetPString(IDS_NVNOLINESSELTEXT));
1161 DosSleep(150);//05 Aug 07 GKY 1500
1162 }
1163 }
1164 if (!released)
1165 DosReleaseMutexSem(ad->ScanSem);
1166 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1167 }
1168 }
1169 WinDestroyMsgQueue(hmq2);
1170 }
1171 DecrThreadUsage();
1172 WinTerminate(hab2);
1173 }
1174 DosPostEventSem(CompactSem);
1175}
1176
1177static VOID ReLineThread(VOID * args)
1178{
1179 HWND hwnd = (HWND) args;
1180 HAB hab2;
1181 HMQ hmq2;
1182 VIEWDATA *ad;
1183 CHAR *p, *pp, *e, *whereiam = NULL;
1184 RECTL Rectl;
1185 ULONG width, numlines, firstline = 1, cursored = 1;
1186
1187 priority_normal();
1188 hab2 = WinInitialize(0);
1189 if (hab2) {
1190 hmq2 = WinCreateMsgQueue(hab2, 0);
1191 if (hmq2) {
1192 WinCancelShutdown(hmq2, TRUE);
1193 IncrThreadUsage();
1194 ad = WinQueryWindowPtr(hwnd, QWL_USER);
1195 if (!ad)
1196 Runtime_Error(pszSrcFile, __LINE__, "no data");
1197 else {
1198 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
1199 ad->relining = TRUE;
1200 ad->busy++;
1201 ad->maxx = 0;
1202 if (ad->text && ad->textsize) {
1203 if (ad->hex) {
1204 firstline = ad->topline;
1205 cursored = ad->cursored;
1206 }
1207 else if (ad->lines)
1208 whereiam = ad->lines[ad->cursored - 1];
1209 ad->found = 0;
1210 ad->selected = ad->numlines = ad->numalloc = 0;
1211 xfree(ad->lines, pszSrcFile, __LINE__);
1212 xfree(ad->markedlines, pszSrcFile, __LINE__);
1213# ifdef FORTIFY
1214 Fortify_LeaveScope();
1215# endif
1216 ad->lines = NULL;
1217 ad->markedlines = NULL;
1218 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1219 NEWVIEW_STATUS1),
1220 GetPString(IDS_FORMATTINGTEXT));
1221 if (!ad->hex) {
1222 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
1223 LM_QUERYITEMCOUNT, MPVOID, MPVOID)) {
1224 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
1225 LM_DELETEALL, MPVOID, MPVOID);
1226 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
1227 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
1228 }
1229 }
1230 WinSetFocus(HWND_DESKTOP, hwnd);
1231 if (!ad->hex) {
1232 WinQueryWindowRect(hwnd, &Rectl);
1233 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
1234 numlines = NumLines(&Rectl, ad);
1235 ad->oldwidth = width;
1236 p = ad->text;
1237 if (width) {
1238 while (p - ad->text < ad->textsize && !ad->stopflag) {
1239 if (ad->wrapon) {
1240 e = p + (width - 1);
1241 if (e - ad->text > ad->textsize)
1242 e = ad->text + ad->textsize;
1243 pp = p;
1244 while (pp < e) {
1245 if (*pp == '\r' || *pp == '\n') {
1246 e = pp;
1247 break;
1248 }
1249 pp++;
1250 }
1251 }
1252 else {
1253 pp = p;
1254 while (pp - ad->text < ad->textsize &&
1255 *pp != '\r' && *pp != '\n')
1256 pp++;
1257 e = pp;
1258 if (ad->maxx <
1259 (((e - p) + 1) * ad->fattrs.lAveCharWidth) + 1)
1260 ad->maxx = (((e - p) + 1) *
1261 ad->fattrs.lAveCharWidth) + 1;
1262 }
1263 if (whereiam && p >= whereiam && e <= whereiam) {
1264 cursored = firstline = ad->numlines + 1;
1265 whereiam = NULL;
1266 }
1267 /* assign ad->lines[ad->numlines] */
1268 if (ad->numlines + 1 > ad->numalloc) {
1269
1270 CHAR **temp;
1271
1272 temp = xrealloc(ad->lines, sizeof(CHAR *) *
1273 (ad->numalloc + 256), pszSrcFile,
1274 __LINE__);
1275 if (!temp)
1276 break;
1277 ad->lines = temp;
1278 ad->numalloc += 256;
1279 }
1280 ad->lines[ad->numlines] = p;
1281 ad->numlines++;
1282 if (ad->numlines == numlines) {
1283 /* display first page */
1284 register INT x;
1285
1286 for (x = 0; x < ad->numlines; x++) {
1287 if ((LONG) (Rectl.yTop -
1288 (ad->lMaxHeight * (((x + 1) -
1289 ad->topline) + 1))) < 0)
1290 break;
1291 PaintLine(hwnd, ad->hps, x, 1, &Rectl);
1292 }
1293 }
1294 p = e;
1295 if (p - ad->text < ad->textsize) {
1296 if (*p == '\r')
1297 p++;
1298 }
1299 if (p - ad->text < ad->textsize) {
1300 if (*p == '\n')
1301 p++;
1302 }
1303 }
1304 }
1305 if (ad->numalloc != ad->numlines) {
1306
1307 CHAR **temp;
1308
1309 temp =
1310 xrealloc(ad->lines, sizeof(CHAR *) * ad->numlines,
1311 pszSrcFile, __LINE__);
1312 if (temp) {
1313 ad->lines = temp;
1314 ad->numalloc = ad->numlines;
1315 }
1316 }
1317 }
1318 else {
1319 ad->numlines = ad->textsize / 16;
1320 if (ad->numlines * 16 < ad->textsize)
1321 ad->numlines++;
1322 }
1323 if (ad->numlines) {
1324 ad->markedlines = xmallocz(ad->numlines, pszSrcFile, __LINE__);
1325 if (ad->markedlines) {
1326 ad->selected = 0;
1327 }
1328 if ((*ftprun || fFtpRunWPSDefault) && !ad->ignoreftp &&
1329 strstr(ad->text, "ftp://"))
1330 ad->ftpin = TRUE;
1331 if ((*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
1332 strstr(ad->text, "http://"))
1333 ad->httpin = TRUE;
1334 if (*mailrun && !ad->ignoremail && strstr(ad->text, "@"))
1335 ad->mailin = TRUE;
1336 }
1337 }
1338 DosReleaseMutexSem(ad->ScanSem);
1339 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1340 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1341 ad->busy--;
1342 } // if got sim
1343 } // if got VIEWDATA
1344 WinDestroyMsgQueue(hmq2);
1345 }
1346 DecrThreadUsage();
1347 WinTerminate(hab2);
1348 }
1349 DosPostEventSem(CompactSem);
1350 if (ad && !ad->stopflag) {
1351 PostMsg(hwnd, UM_CONTAINER_FILLED, MPFROMLONG(firstline),
1352 MPFROMLONG(cursored));
1353 ad->relining = FALSE;
1354 }
1355}
1356
1357static VOID LoadFileThread(VOID * args)
1358{
1359 HWND hwnd = (HWND) args;
1360 HAB hab2;
1361 HMQ hmq2;
1362 VIEWDATA *ad;
1363 HFILE handle;
1364 ULONG action;
1365 ULONG len;
1366 APIRET rc;
1367 BOOL error = TRUE;
1368
1369 hab2 = WinInitialize(0);
1370 if (hab2) {
1371 hmq2 = WinCreateMsgQueue(hab2, 0);
1372 if (hmq2) {
1373 WinCancelShutdown(hmq2, TRUE);
1374 IncrThreadUsage();
1375# ifdef FORTIFY
1376 Fortify_EnterScope();
1377# endif
1378 ad = WinQueryWindowPtr(hwnd, QWL_USER);
1379 if (ad) {
1380 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
1381 ad->busy++;
1382 priority_normal();
1383 if (*ad->filename) {
1384 xfree(ad->text, pszSrcFile, __LINE__);
1385 xfree(ad->lines, pszSrcFile, __LINE__);
1386 xfree(ad->markedlines, pszSrcFile, __LINE__);
1387 ad->text = NULL;
1388 ad->lines = NULL;
1389 ad->markedlines = NULL;
1390 ad->ftpin = ad->httpin = ad->mailin = FALSE;
1391 ad->selected = ad->numlines = ad->textsize = ad->numalloc = 0;
1392 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
1393 MPVOID, MPVOID);
1394 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
1395 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
1396 WinSetFocus(HWND_DESKTOP, hwnd);
1397 rc = DosOpen(ad->filename, &handle, &action, 0, 0,
1398 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
1399 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
1400 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
1401 OPEN_ACCESS_READONLY, 0);
1402 if (rc) {
1403 Dos_Error(MB_CANCEL,
1404 rc,
1405 hwnd,
1406 pszSrcFile,
1407 __LINE__,
1408 GetPString(IDS_COMPCANTOPENTEXT), ad->filename);
1409 }
1410 else {
1411 DosChgFilePtr(handle, 0, FILE_END, &len);
1412 DosChgFilePtr(handle, 0, FILE_BEGIN, &action);
1413 if (!len) {
1414 saymsg(MB_CANCEL,
1415 hwnd,
1416 GetPString(IDS_ERRORTEXT),
1417 GetPString(IDS_ZEROLENGTHTEXT), ad->filename);
1418 }
1419 else {
1420 // 06 Oct 07 SHL Protect against 4096 NFTS driver small buffer defect
1421 ad->text = xmalloc(max(len + 2, 4096), // 05 Nov 07 SHL
1422 pszSrcFile,
1423 __LINE__);
1424 if (ad->text) {
1425 *ad->text = 0;
1426 ad->text[len] = 0;
1427 rc = DosRead(handle, ad->text, len, &ad->textsize);
1428 if (rc) {
1429 Dos_Error(MB_CANCEL,
1430 rc,
1431 hwnd,
1432 pszSrcFile,
1433 __LINE__,
1434 GetPString(IDS_ERRORREADINGTEXT), ad->filename);
1435 xfree(ad->text, pszSrcFile, __LINE__);
1436 ad->text = NULL;
1437 ad->textsize = 0;
1438 }
1439 else {
1440 ad->text[ad->textsize] = 0;
1441 if (!ad->hex && !(ad->flags & (8 | 16)) && ad->textsize) {
1442 ULONG x;
1443
1444 x = min(512, ad->textsize);
1445 if (fGuessType && IsBinary(ad->text, x))
1446 ad->hex = TRUE;
1447 }
1448 if (ad->textsize) {
1449 if (_beginthread
1450 (ReLineThread, NULL, 524288, (PVOID) hwnd) == -1)
1451 Runtime_Error(pszSrcFile, __LINE__,
1452 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1453 else
1454 error = FALSE;
1455 }
1456 }
1457 }
1458 }
1459 DosClose(handle);
1460 }
1461 }
1462 ad->busy--;
1463 DosReleaseMutexSem(ad->ScanSem);
1464 }
1465 }
1466 WinDestroyMsgQueue(hmq2);
1467 }
1468 DecrThreadUsage();
1469 WinTerminate(hab2);
1470# ifdef FORTIFY
1471 xFortify_LeaveScope(pszSrcFile, __LINE__);
1472# endif
1473 }
1474 if (error)
1475 PostMsg(hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
1476 DosPostEventSem(CompactSem);
1477}
1478
1479MRESULT EXPENTRY ViewFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
1480 MPARAM mp2)
1481{
1482 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
1483
1484 switch (msg) {
1485 case WM_CHAR:
1486 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
1487 break;
1488
1489 case WM_CONTROL:
1490 switch (SHORT1FROMMP(mp1)) {
1491 case NEWVIEW_LISTBOX:
1492 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), UM_CONTROL,
1493 mp1, mp2);
1494 }
1495 break;
1496
1497 case WM_CALCFRAMERECT:
1498 {
1499 MRESULT mr;
1500 PRECTL prectl;
1501 SHORT sSelect;
1502
1503 mr = oldproc(hwnd, msg, mp1, mp2);
1504
1505 /*
1506 * Calculate the position of the client rectangle.
1507 * Otherwise, we'll see a lot of redraw when we move the
1508 * client during WM_FORMATFRAME.
1509 */
1510
1511 if (mr && mp2) {
1512 prectl = (PRECTL) mp1;
1513 prectl->yBottom += 22;
1514 prectl->yTop -= 22;
1515 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, NEWVIEW_LISTBOX,
1516 LM_QUERYITEMCOUNT,
1517 MPVOID, MPVOID);
1518 if (sSelect > 0)
1519 prectl->yTop -= 48;
1520 }
1521 return mr;
1522 }
1523
1524 case WM_FORMATFRAME:
1525 {
1526 SHORT sCount, soldCount, sSelect;
1527 PSWP pswp, pswpClient, pswpNew1, pswpNew2, pswpNew3, pswpList,
1528 pswpScroll, pswpNew4, pswpUp, pswpDn;
1529
1530 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
1531 soldCount = sCount;
1532
1533 /*
1534 * Reformat the frame to "squeeze" the client
1535 * and make room for status window sibling beneath
1536 */
1537
1538 pswp = (PSWP) mp1;
1539 {
1540 SHORT x;
1541
1542 for (x = 0; x < sCount; x++) {
1543 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_CLIENT) {
1544 pswpClient = pswp;
1545 break;
1546 }
1547 pswp++;
1548 }
1549 }
1550 pswpNew1 = (PSWP) mp1 + soldCount;
1551 pswpNew2 = (PSWP) mp1 + (soldCount + 1);
1552 pswpNew3 = (PSWP) mp1 + (soldCount + 2);
1553 pswpNew4 = (PSWP) mp1 + (soldCount + 3);
1554 *pswpNew1 = *pswpClient;
1555 pswpNew1->hwnd = WinWindowFromID(hwnd, NEWVIEW_STATUS1);
1556 pswpNew1->x = pswpClient->x + 2;
1557 pswpNew1->y = pswpClient->y + 2;
1558 pswpNew1->cx = (pswpClient->cx / 3) - 3;
1559 pswpNew1->cy = 20;
1560 pswpClient->y = pswpNew1->y + pswpNew1->cy + 3;
1561 pswpClient->cy = (pswpClient->cy - pswpNew1->cy) - 5;
1562 *pswpNew2 = *pswpNew1;
1563 *pswpNew3 = *pswpNew1;
1564 *pswpNew4 = *pswpNew1;
1565 pswpNew2->hwnd = WinWindowFromID(hwnd, NEWVIEW_STATUS2);
1566 pswpNew3->hwnd = WinWindowFromID(hwnd, NEWVIEW_STATUS3);
1567 pswpNew4->hwnd = WinWindowFromID(hwnd, NEWVIEW_DRAG);
1568 pswpNew2->x = pswpNew1->x + pswpNew1->cx + 3;
1569 pswpNew3->x = pswpNew2->x + pswpNew2->cx + 3;
1570 pswpNew3->cx = ((pswpClient->x + pswpClient->cx) - pswpNew3->x) - 26;
1571 pswpNew4->x = pswpNew3->x + pswpNew3->cx + 3;
1572 pswpNew4->cx = 20;
1573 sCount += 4;
1574 pswpScroll = (PSWP) mp1;
1575 while (pswpScroll < pswpClient) {
1576 if (WinQueryWindowUShort(pswpScroll->hwnd, QWS_ID) == FID_VERTSCROLL)
1577 break;
1578 pswpScroll++;
1579 }
1580 if (pswpScroll == pswpClient)
1581 pswpScroll = NULL;
1582 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, NEWVIEW_LISTBOX,
1583 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
1584 if (sSelect > 0) {
1585 pswpList = (PSWP) mp1 + (soldCount + 4);
1586 *pswpList = *pswpClient;
1587 pswpList->hwnd = WinWindowFromID(hwnd, NEWVIEW_LISTBOX);
1588 pswpList->x = pswpClient->x;
1589 pswpList->cx = pswpClient->cx;
1590 if (pswpScroll) {
1591 pswpList->cx += pswpScroll->cx;
1592 pswpScroll->cy -= 48;
1593 }
1594 pswpList->y = (pswpClient->y + pswpClient->cy) - 48;
1595 pswpList->cy = 48;
1596 pswpClient->cy -= 48;
1597 sCount++;
1598 }
1599 WinShowWindow(WinWindowFromID(hwnd, NEWVIEW_LISTBOX), (sSelect > 0));
1600
1601 if (pswpScroll) {
1602 pswpUp = (PSWP) mp1 + (soldCount + 4 + (sSelect > 0));
1603 *pswpUp = *pswpClient;
1604 pswpUp->hwnd = WinWindowFromID(hwnd, IDM_PREVBLANKLINE);
1605 pswpUp->cx = pswpScroll->cx;
1606 pswpUp->x = pswpScroll->x;
1607 pswpUp->cy = WinQuerySysValue(HWND_DESKTOP, SV_CYVSCROLLARROW);
1608 pswpUp->y = (pswpScroll->y + pswpScroll->cy) - (pswpUp->cy + 1);
1609 pswpScroll->cy -= ((pswpUp->cy * 2) + 1);
1610 pswpDn = (PSWP) mp1 + (soldCount + 5 + (sSelect > 0));
1611 *pswpDn = *pswpUp;
1612 pswpDn->y = pswpScroll->y;
1613 pswpDn->hwnd = WinWindowFromID(hwnd, IDM_NEXTBLANKLINE);
1614 pswpScroll->y += pswpUp->cy;
1615 sCount += 2;
1616 }
1617 else {
1618 WinShowWindow(WinWindowFromID(hwnd, IDM_PREVBLANKLINE), FALSE);
1619 WinShowWindow(WinWindowFromID(hwnd, IDM_NEXTBLANKLINE), FALSE);
1620 }
1621 return MRFROMSHORT(sCount);
1622 }
1623
1624 case WM_QUERYFRAMECTLCOUNT:
1625 {
1626 SHORT sCount, sSelect;
1627
1628 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
1629 sCount += 6;
1630 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, NEWVIEW_LISTBOX,
1631 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
1632 if (sSelect > 0)
1633 sCount++;
1634 return MRFROMSHORT(sCount);
1635 }
1636 }
1637 return oldproc(hwnd, msg, mp1, mp2);
1638}
1639
1640MRESULT EXPENTRY FindStrDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1641{
1642 VIEWDATA *ad;
1643
1644 switch (msg) {
1645 case WM_INITDLG:
1646 if (!mp2)
1647 WinDismissDlg(hwnd, 0);
1648 else {
1649
1650 HWND hwndClient = *(HWND *) mp2;
1651
1652 WinSetWindowULong(hwnd, QWL_USER, (ULONG) hwndClient);
1653 ad = (VIEWDATA *) WinQueryWindowPtr(hwndClient, QWL_USER);
1654 MLEsetwrap(WinWindowFromID(hwnd, NEWFIND_MLE), FALSE);
1655 MLEsetlimit(WinWindowFromID(hwnd, NEWFIND_MLE), SEARCHSTRINGLEN);
1656 MLEsetformat(WinWindowFromID(hwnd, NEWFIND_MLE), MLFIE_NOTRANS);
1657 if (*ad->searchtext) {
1658
1659 IPT here = 0;
1660 ULONG len = strlen(ad->searchtext);
1661
1662 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1663 MLM_SETIMPORTEXPORT,
1664 MPFROMP(ad->searchtext), MPFROMLONG(SEARCHSTRINGLEN));
1665 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1666 MLM_IMPORT, MPFROMP(&here), MPFROMLONG(len));
1667 }
1668 WinCheckButton(hwnd, NEWFIND_ALSOSELECT, ad->alsoselect);
1669 WinCheckButton(hwnd, NEWFIND_SENSITIVE, ad->sensitive);
1670 WinCheckButton(hwnd, NEWFIND_LITERAL, ad->literalsearch);
1671 }
1672 break;
1673
1674 case WM_COMMAND:
1675 switch (SHORT1FROMMP(mp1)) {
1676 case DID_OK:
1677 {
1678 CHAR s[SEARCHSTRINGLEN];
1679 IPT here = 0;
1680 ULONG len;
1681 HWND hwndClient = WinQueryWindowULong(hwnd, QWL_USER);
1682
1683 ad = (VIEWDATA *) WinQueryWindowPtr(hwndClient, QWL_USER);
1684 memset(s, 0, SEARCHSTRINGLEN);
1685 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1686 MLM_SETIMPORTEXPORT,
1687 MPFROMP(s), MPFROMLONG(SEARCHSTRINGLEN));
1688 len = SEARCHSTRINGLEN;
1689 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1690 MLM_EXPORT, MPFROMP(&here), MPFROMLONG(&len));
1691 s[SEARCHSTRINGLEN - 1] = 0;
1692 if (!*s) {
1693 DosBeep(250, 100); // Complain
1694 break;
1695 }
1696 strcpy(ad->searchtext, s);
1697 ad->sensitive = WinQueryButtonCheckstate(hwnd, NEWFIND_SENSITIVE);
1698 if (ad->sensitive != Sensitive) {
1699 Sensitive = ad->sensitive;
1700 PrfWriteProfileData(fmprof,
1701 appname,
1702 "Viewer.Sensitive",
1703 &ad->sensitive, sizeof(BOOL));
1704 }
1705 ad->literalsearch = WinQueryButtonCheckstate(hwnd, NEWFIND_LITERAL);
1706 if (ad->literalsearch != LiteralSearch) {
1707 LiteralSearch = ad->literalsearch;
1708 PrfWriteProfileData(fmprof,
1709 appname,
1710 "Viewer.LiteralSearch",
1711 &ad->literalsearch, sizeof(BOOL));
1712 }
1713 ad->alsoselect = WinQueryButtonCheckstate(hwnd, NEWFIND_ALSOSELECT);
1714 if (ad->alsoselect != AlsoSelect) {
1715 AlsoSelect = ad->alsoselect;
1716 PrfWriteProfileData(fmprof,
1717 appname,
1718 "Viewer.AlsoSelect",
1719 &ad->alsoselect, sizeof(BOOL));
1720 }
1721 }
1722 WinDismissDlg(hwnd, 1);
1723 break;
1724 case DID_CANCEL:
1725 WinDismissDlg(hwnd, 0);
1726 break;
1727 }
1728 return 0;
1729 }
1730 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1731}
1732
1733MRESULT EXPENTRY ViewWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1734{
1735 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
1736
1737 switch (msg) {
1738 case WM_CREATE:
1739 {
1740 HWND temphwnd;
1741 HWND hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
1742
1743 temphwnd = WinCreateWindow(hwndFrame,
1744 WC_BUTTON,
1745 "<",
1746 WS_VISIBLE |
1747 BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
1748 0,
1749 0,
1750 0,
1751 0,
1752 hwndFrame,
1753 HWND_TOP, IDM_PREVBLANKLINE, NULL, NULL);
1754 if (!temphwnd)
1755 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1756 IDS_WINCREATEWINDOW);
1757 else {
1758 WinSetPresParam(temphwnd,
1759 PP_FONTNAMESIZE,
1760 strlen(GetPString(IDS_8HELVTEXT)) + 1,
1761 (PVOID) GetPString(IDS_8HELVTEXT));
1762 }
1763 temphwnd = WinCreateWindow(hwndFrame,
1764 WC_BUTTON,
1765 ">",
1766 WS_VISIBLE |
1767 BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
1768 0,
1769 0,
1770 0,
1771 0,
1772 hwndFrame,
1773 HWND_TOP, IDM_NEXTBLANKLINE, NULL, NULL);
1774 if (!temphwnd)
1775 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1776 IDS_WINCREATEWINDOW);
1777 else {
1778 WinSetPresParam(temphwnd,
1779 PP_FONTNAMESIZE,
1780 strlen(GetPString(IDS_8HELVTEXT)) + 1,
1781 (PVOID) GetPString(IDS_8HELVTEXT));
1782 }
1783 WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER5, 1000L);
1784 }
1785 break;
1786
1787 case WM_TIMER:
1788 if (ad &&
1789 ad->needrefreshing &&
1790 !ad->stopflag &&
1791 !ad->relining &&
1792 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
1793 ad->needrefreshing = FALSE;
1794 DosReleaseMutexSem(ad->ScanSem);
1795 WinInvalidateRect(hwnd, NULL, TRUE);
1796 }
1797 break;
1798
1799 case UM_SETUP:
1800 if (!ad)
1801 Runtime_Error(pszSrcFile, __LINE__, "no data");
1802 else {
1803 CHAR s[CCHMAXPATH + 8];
1804 APIRET rc;
1805
1806 ad->hwndMenu = WinWindowFromID(ad->hwndFrame, FID_MENU);
1807 ad->hvscroll = WinWindowFromID(ad->hwndFrame, FID_VERTSCROLL);
1808 ad->hhscroll = WinWindowFromID(ad->hwndFrame, FID_HORZSCROLL);
1809 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(1, 1), MPVOID);
1810 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(1, 1), MPVOID);
1811 sprintf(s, "%s: %s", FM2Str, ad->filename);
1812 WinSetWindowText(ad->hwndFrame, s);
1813 rc = DosCreateMutexSem(NULL, &ad->ScanSem, 0L, FALSE);
1814 if (rc)
1815 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
1816 "DosCreateMutexSem");
1817 else {
1818 PFNWP oldproc;
1819 HWND hwndFrame = ad->hwndFrame;
1820
1821 WinSendMsg(ad->hvscroll,
1822 SBM_SETSCROLLBAR, MPFROMSHORT(1), MPFROM2SHORT(1, 1));
1823 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR, MPFROMSHORT(1),
1824 MPFROM2SHORT(1, 1));
1825 ad->hwndStatus1 = WinCreateWindow(hwndFrame,
1826 WC_VIEWSTATUS,
1827 GetPString(IDS_LOADINGTEXT),
1828 WS_VISIBLE | SS_TEXT |
1829 DT_LEFT | DT_VCENTER,
1830 0,
1831 0,
1832 0,
1833 0,
1834 hwndFrame,
1835 HWND_TOP,
1836 NEWVIEW_STATUS1, NULL, NULL);
1837 if (!ad->hwndStatus1)
1838 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1839 IDS_WINCREATEWINDOW);
1840
1841 ad->hwndStatus2 = WinCreateWindow(hwndFrame,
1842 WC_VIEWSTATUS,
1843 NULL,
1844 WS_VISIBLE | SS_TEXT |
1845 DT_LEFT | DT_VCENTER,
1846 0,
1847 0,
1848 0,
1849 0,
1850 hwndFrame,
1851 HWND_TOP,
1852 NEWVIEW_STATUS2, NULL, NULL);
1853 if (!ad->hwndStatus2)
1854 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1855 IDS_WINCREATEWINDOW);
1856
1857 ad->hwndStatus3 = WinCreateWindow(hwndFrame,
1858 WC_VIEWSTATUS,
1859 NULL,
1860 WS_VISIBLE | SS_TEXT |
1861 DT_LEFT | DT_VCENTER,
1862 0,
1863 0,
1864 0,
1865 0,
1866 hwndFrame,
1867 HWND_TOP,
1868 NEWVIEW_STATUS3, NULL, NULL);
1869 if (!ad->hwndStatus3)
1870 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1871 IDS_WINCREATEWINDOW);
1872
1873 ad->hwndListbox = WinCreateWindow(hwndFrame,
1874 WC_LISTBOX,
1875 NULL,
1876 LS_NOADJUSTPOS,
1877 0,
1878 0,
1879 0,
1880 0,
1881 hwndFrame,
1882 HWND_TOP,
1883 NEWVIEW_LISTBOX, NULL, NULL);
1884 if (!ad->hwndListbox)
1885 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1886 IDS_WINCREATEWINDOW);
1887
1888 ad->hwndDrag = WinCreateWindow(hwndFrame,
1889 WC_VIEWSTATUS,
1890 "#100",
1891 WS_VISIBLE | SS_BITMAP,
1892 0,
1893 0,
1894 0,
1895 0,
1896 hwndFrame,
1897 HWND_TOP, NEWVIEW_DRAG, NULL, NULL);
1898 if (!ad->hwndDrag)
1899 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1900 IDS_WINCREATEWINDOW);
1901
1902 oldproc = WinSubclassWindow(hwndFrame, ViewFrameWndProc);
1903 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
1904 ad->hps = InitWindow(hwnd);
1905 if (_beginthread(LoadFileThread, NULL, 524288, (PVOID) hwnd) == -1)
1906 Runtime_Error(pszSrcFile, __LINE__,
1907 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1908 else {
1909 WinSendMsg(hwnd, UM_SETUP5, MPVOID, MPVOID);
1910 DosSleep(16); //05 Aug 07 GKY 32
1911 return (MRESULT) 1;
1912 }
1913 }
1914 }
1915 // Oops
1916 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
1917 return 0;
1918
1919 case UM_SETUP5:
1920 if (ad) {
1921 if (ad->hwndFrame ==
1922 WinQueryActiveWindow(WinQueryWindow(ad->hwndFrame,
1923 QW_PARENT)) &&
1924 !ParentIsDesktop(ad->hwndFrame, (HWND) 0)) {
1925 if (hwndStatus2)
1926 WinSetWindowText(hwndStatus2,
1927 (*ad->filename) ?
1928 ad->filename : GetPString(IDS_UNTITLEDTEXT));
1929 if (fMoreButtons) {
1930 WinSetWindowText(hwndName,
1931 (*ad->filename) ?
1932 ad->filename : GetPString(IDS_UNTITLEDTEXT));
1933 WinSetWindowText(hwndDate, NullStr);
1934 WinSetWindowText(hwndAttr, NullStr);
1935 }
1936 if (hwndStatus)
1937 WinSetWindowText(hwndStatus,
1938 GetPString(IDS_INTERNALVIEWERTITLETEXT));
1939 }
1940 }
1941 return 0;
1942
1943 case DM_DISCARDOBJECT:
1944 case DM_PRINTOBJECT:
1945 return MRFROMLONG(DRR_TARGET);
1946
1947 case UM_RESCAN:
1948 if (ad) {
1949 if (!ad->busy && !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
1950 if (ad->numlines) {
1951
1952 CHAR s[80], tb[34], tl[34];
1953
1954 commafmt(tb, sizeof(tb), ad->textsize);
1955 commafmt(tl, sizeof(tl), ad->numlines);
1956 sprintf(s,
1957 " %s %s%s %s %s%s",
1958 tb,
1959 GetPString(IDS_BYTETEXT),
1960 &"s"[ad->textsize == 1],
1961 tl, GetPString(IDS_LINETEXT), &"s"[ad->numlines == 1]);
1962 WinSetWindowText(ad->hwndStatus1, s);
1963 }
1964 else
1965 WinSetWindowText(ad->hwndStatus1, GetPString(IDS_NVNOLINESTEXT));
1966 DosReleaseMutexSem(ad->ScanSem);
1967 }
1968 else
1969 WinSetWindowText(ad->hwndStatus1, GetPString(IDS_WORKINGTEXT));
1970 }
1971 return 0;
1972
1973 case UM_SETUP2:
1974 /**
1975 * calculate width of client in characters, recalc lines if
1976 * oldwidth != newwidth, set ad->oldwidth for later comparison
1977 */
1978 if (ad) {
1979
1980 BOOL invalidate = FALSE;
1981
1982 if (ad->wrapon || ad->hex) { // GKY reverse case where hscroll bar is presnt
1983 if (WinQueryWindow(ad->hhscroll, QW_PARENT) == ad->hwndFrame) {
1984 invalidate = TRUE;
1985 WinSetOwner(ad->hhscroll, HWND_OBJECT);
1986 WinSetParent(ad->hhscroll, HWND_OBJECT, TRUE);
1987 ad->maxx = 0;
1988 ad->horzscroll = 0;
1989 }
1990 }
1991 else {
1992 if (WinQueryWindow(ad->hhscroll, QW_PARENT) != ad->hwndFrame) {
1993 invalidate = TRUE;
1994 WinSetOwner(ad->hhscroll, ad->hwndFrame);
1995 WinSetParent(ad->hhscroll, ad->hwndFrame, TRUE);
1996 }
1997 }
1998 if (invalidate) {
1999 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER),
2000 MPVOID);
2001 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2002 NEWVIEW_DRAG), NULL, FALSE);
2003 WinInvalidateRect(ad->hhscroll, NULL, FALSE);
2004 }
2005 }
2006
2007 if (ad && !ad->busy &&
2008 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2009
2010 RECTL rcl;
2011 ULONG newwidth;
2012
2013 WinQueryWindowRect(hwnd, &rcl);
2014 newwidth = (rcl.xRight - rcl.xLeft) / ad->fattrs.lAveCharWidth;
2015 if ((!ad->hex || ad->oldwidth == -1) &&
2016 newwidth != ad->oldwidth && ad->text && ad->textsize) {
2017 ad->oldwidth = newwidth;
2018 if (!ad->relining) {
2019 if (_beginthread(ReLineThread, NULL, 524288, (PVOID) hwnd) == -1) {
2020 Runtime_Error(pszSrcFile, __LINE__,
2021 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2022 DosReleaseMutexSem(ad->ScanSem);
2023 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
2024 return 0;
2025 }
2026 }
2027 }
2028 ad->oldwidth = newwidth;
2029 DosReleaseMutexSem(ad->ScanSem);
2030 }
2031 return MRFROMLONG(TRUE);
2032
2033 case WM_CHAR:
2034 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
2035 if (ad && !ad->busy && !(SHORT1FROMMP(mp1) & KC_KEYUP) &&
2036 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2037
2038 ULONG numlines, wascursored = ad->cursored;
2039 RECTL rcl;
2040
2041 WinQueryWindowRect(hwnd, &rcl);
2042 numlines = NumLines(&rcl, ad);
2043 if (numlines) {
2044 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
2045 switch (SHORT2FROMMP(mp2)) {
2046 case VK_LEFT:
2047 WinSendMsg(hwnd, WM_HSCROLL, MPFROM2SHORT(FID_HORZSCROLL, 0),
2048 MPFROM2SHORT(0, SB_LINELEFT));
2049 break;
2050 case VK_RIGHT:
2051 WinSendMsg(hwnd, WM_HSCROLL, MPFROM2SHORT(FID_HORZSCROLL, 0),
2052 MPFROM2SHORT(0, SB_LINERIGHT));
2053 break;
2054 case VK_PAGEUP:
2055 PostMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2056 MPFROM2SHORT(0, SB_PAGEUP));
2057 break;
2058 case VK_PAGEDOWN:
2059 PostMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2060 MPFROM2SHORT(0, SB_PAGEDOWN));
2061 break;
2062 case VK_UP:
2063 if (ad->cursored > 1) {
2064 if (shiftstate & KC_SHIFT)
2065 WinSendMsg(hwnd, WM_BUTTON1CLICK,
2066 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2067 ((rcl.yTop - (ad->lMaxHeight *
2068 ((ad->cursored) -
2069 ad->topline))) -
2070 ad->lMaxDescender) - 1),
2071 MPFROM2SHORT(TRUE, 0));
2072 ad->cursored--;
2073 if (ad->cursored < ad->topline) {
2074 PaintLine(hwnd, ad->hps, ad->cursored, ad->topline, &rcl);
2075 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2076 MPFROM2SHORT(0, SB_LINEUP));
2077 }
2078 else {
2079 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2080 PaintLine(hwnd, ad->hps, ad->cursored, ad->topline, &rcl);
2081 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2082 }
2083 }
2084 break;
2085 case VK_DOWN:
2086 if (ad->cursored < ad->numlines &&
2087 ad->cursored < ad->topline + numlines) {
2088 if (shiftstate & KC_SHIFT)
2089 WinSendMsg(hwnd, WM_BUTTON1CLICK,
2090 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2091 ((rcl.yTop - (ad->lMaxHeight *
2092 ((ad->cursored) -
2093 ad->topline))) -
2094 ad->lMaxDescender) - 1),
2095 MPFROM2SHORT(TRUE, 0));
2096 ad->cursored++;
2097 if (ad->cursored >= ad->topline + numlines) {
2098 PaintLine(hwnd, ad->hps, ad->cursored - 2, ad->topline, &rcl);
2099 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2100 MPFROM2SHORT(0, SB_LINEDOWN));
2101 }
2102 else {
2103 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2104 PaintLine(hwnd, ad->hps, ad->cursored - 2, ad->topline, &rcl);
2105 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2106 }
2107 }
2108 break;
2109 case VK_END:
2110 if ((shiftstate & KC_CTRL) ||
2111 ad->cursored == (ad->topline - 1) + numlines) {
2112 ad->cursored = ad->numlines;
2113 ad->topline = (ad->numlines + 1) - numlines;
2114 if (ad->topline > ad->numlines)
2115 ad->topline = 1;
2116 WinInvalidateRect(hwnd, NULL, FALSE);
2117 }
2118 else {
2119 ad->cursored = (ad->topline - 1) + numlines;
2120 if (ad->cursored > ad->numlines)
2121 ad->cursored = ad->numlines;
2122 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2123 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &rcl);
2124 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2125 }
2126 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2127 break;
2128 case VK_HOME:
2129 if ((shiftstate & KC_CTRL) || ad->cursored == ad->topline) {
2130 ad->topline = 1;
2131 ad->cursored = 1;
2132 WinInvalidateRect(hwnd, NULL, FALSE);
2133 }
2134 else {
2135 ad->cursored = ad->topline;
2136 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2137 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &rcl);
2138 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2139 }
2140 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2141 break;
2142 case VK_SPACE:
2143 WinSendMsg(hwnd, WM_BUTTON1CLICK,
2144 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2145 ((rcl.yTop - (ad->lMaxHeight *
2146 ((ad->cursored) -
2147 ad->topline))) -
2148 ad->lMaxDescender) - 1),
2149 MPFROM2SHORT(TRUE, 0));
2150 break;
2151 case VK_NEWLINE:
2152 case VK_ENTER:
2153 WinSendMsg(hwnd, WM_BUTTON1DBLCLK,
2154 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2155 ((rcl.yTop - (ad->lMaxHeight *
2156 ((ad->cursored) -
2157 ad->topline))) -
2158 ad->lMaxDescender) - 1), MPFROM2SHORT(0,
2159 0));
2160 break;
2161 }
2162 }
2163 else if (SHORT1FROMMP(mp1) & KC_CHAR) {
2164 switch (SHORT1FROMMP(mp2)) {
2165 case '\r':
2166 case '\n':
2167 WinSendMsg(hwnd, WM_BUTTON1DBLCLK,
2168 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2169 (rcl.yTop - (ad->lMaxHeight *
2170 ((ad->cursored) -
2171 ad->topline))) - 1),
2172 MPFROM2SHORT(0, 0));
2173 break;
2174 default:
2175 break;
2176 }
2177 }
2178 if (wascursored != ad->cursored)
2179 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2180 }
2181 DosReleaseMutexSem(ad->ScanSem);
2182 }
2183 break;
2184
2185 case WM_BUTTON1MOTIONSTART:
2186 WinSetFocus(HWND_DESKTOP, hwnd);
2187 if (ad && !ad->stopflag && !ad->busy &&
2188 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2189 ad->mousecaptured = TRUE;
2190 ad->lastselected = ULONG_MAX;
2191 ad->lastdirection = 0;
2192 WinSetCapture(HWND_DESKTOP, hwnd);
2193 WinSendMsg(hwnd, WM_BUTTON1CLICK, mp1, MPFROM2SHORT(TRUE, 0));
2194 }
2195 break;
2196
2197 case WM_MOUSEMOVE:
2198 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
2199 if (ad && ad->mousecaptured) {
2200
2201 ULONG numlines, whichline, x;
2202 LONG inc;
2203 RECTL Rectl;
2204 POINTS pts;
2205 BOOL outofwindow = FALSE;
2206
2207 WinQueryWindowRect(hwnd, &Rectl);
2208 numlines = NumLines(&Rectl, ad);
2209 if (numlines) {
2210 pts.x = SHORT1FROMMP(mp1);
2211 pts.y = SHORT2FROMMP(mp1);
2212 if (pts.y < 0) {
2213 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2214 MPFROM2SHORT(0, SB_LINEDOWN));
2215 pts.y = 1;
2216 outofwindow = TRUE;
2217 }
2218 else if (pts.y > Rectl.yTop - Rectl.yBottom) {
2219 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2220 MPFROM2SHORT(0, SB_LINEUP));
2221 pts.y = (Rectl.yTop - Rectl.yBottom) - 1;
2222 outofwindow = TRUE;
2223 }
2224 whichline = ((Rectl.yTop - Rectl.yBottom) -
2225 ((LONG) pts.y + ad->lMaxDescender)) / ad->lMaxHeight;
2226 if (whichline > numlines - 1)
2227 whichline = numlines - 1;
2228 whichline += (ad->topline - 1);
2229 if (whichline < ad->numlines && ad->lastselected != whichline) {
2230 if (ad->lastselected != ULONG_MAX) {
2231 inc = (ad->lastselected < whichline) ? 1 : -1;
2232 for (x = ad->lastselected + inc;
2233 x != whichline && x < ad->numlines;
2234 (ad->lastselected < whichline) ? x++ : x--) {
2235 if (ad->markedlines) {
2236 if (ad->markedlines[x] & VF_SELECTED) {
2237 ad->markedlines[x] &= (~VF_SELECTED);
2238 ad->selected--;
2239 }
2240 else {
2241 ad->markedlines[x] |= VF_SELECTED;
2242 ad->selected++;
2243 }
2244 }
2245 PaintLine(hwnd, ad->hps, x, ad->topline, &Rectl);
2246 }
2247 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2248 }
2249 WinSendMsg(hwnd, WM_BUTTON1CLICK, MPFROM2SHORT(pts.x, pts.y),
2250 MPFROM2SHORT(TRUE, 0));
2251 }
2252 }
2253 if (outofwindow) {
2254
2255 POINTL ptl;
2256
2257 WinQueryPointerPos(HWND_DESKTOP, &ptl);
2258 WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1L);
2259 if ((SHORT) ptl.y == (SHORT) SHORT2FROMMP(mp1) &&
2260 (SHORT) ptl.x == (SHORT) SHORT1FROMMP(mp1) &&
2261 ((SHORT) ptl.y < 0 || ptl.y > (Rectl.yTop - Rectl.yBottom))) {
2262 PostMsg(hwnd, UM_MOUSEMOVE, mp1, MPVOID);
2263 DosSleep(1);
2264 }
2265 }
2266 }
2267 break;
2268
2269 case UM_MOUSEMOVE:
2270 if (ad && ad->mousecaptured) {
2271
2272 POINTL ptl;
2273 RECTL Rectl;
2274
2275 WinQueryWindowRect(hwnd, &Rectl);
2276 WinQueryPointerPos(HWND_DESKTOP, &ptl);
2277 WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1);
2278 if ((SHORT) ptl.y == (SHORT) SHORT2FROMMP(mp1) &&
2279 (SHORT) ptl.x == (SHORT) SHORT1FROMMP(mp1) &&
2280 ((SHORT) ptl.y < 0 || ptl.y > (Rectl.yTop - Rectl.yBottom))) {
2281 DosSleep(1);
2282 PostMsg(hwnd, WM_MOUSEMOVE, mp1, MPFROM2SHORT(TRUE, 0));
2283 }
2284 }
2285 return 0;
2286
2287 case WM_BUTTON1UP:
2288 case WM_BUTTON1MOTIONEND:
2289 WinSetFocus(HWND_DESKTOP, hwnd);
2290 if (ad && ad->mousecaptured) {
2291 ad->mousecaptured = FALSE;
2292 ad->lastselected = ULONG_MAX;
2293 ad->lastdirection = 0;
2294 DosReleaseMutexSem(ad->ScanSem);
2295 WinSetCapture(HWND_DESKTOP, NULLHANDLE);
2296 }
2297 break;
2298
2299 case WM_BUTTON1DBLCLK:
2300 case WM_BUTTON1CLICK:
2301 WinSetFocus(HWND_DESKTOP, hwnd);
2302 if (ad && !ad->stopflag && ad->numlines && ad->text && !ad->busy &&
2303 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2304
2305 ULONG numlines, whichline, wascursored, width;
2306 RECTL Rectl;
2307 POINTS pts;
2308
2309 WinQueryWindowRect(hwnd, &Rectl);
2310 numlines = NumLines(&Rectl, ad);
2311 if (!numlines)
2312 break;
2313 pts.x = SHORT1FROMMP(mp1);
2314 pts.y = SHORT2FROMMP(mp1);
2315 whichline = ((Rectl.yTop - Rectl.yBottom) -
2316 ((LONG) pts.y + ad->lMaxDescender)) / ad->lMaxHeight;
2317 if (whichline > numlines - 1)
2318 whichline = numlines - 1;
2319 whichline += (ad->topline - 1);
2320 if (whichline + 1 > ad->numlines)
2321 break;
2322 wascursored = ad->cursored;
2323 ad->cursored = whichline + 1;
2324 if (msg == WM_BUTTON1CLICK) {
2325 if (ad->lastselected != ULONG_MAX) {
2326 if (whichline > ad->lastselected)
2327 ad->lastdirection = 1;
2328 else
2329 ad->lastdirection = 2;
2330 }
2331 else
2332 ad->lastdirection = 0;
2333 ad->lastselected = whichline;
2334 if (whichline < ad->numlines) {
2335 if (ad->markedlines) {
2336 if (ad->markedlines[whichline] & VF_SELECTED) {
2337 ad->selected--;
2338 ad->markedlines[whichline] &= (~VF_SELECTED);
2339 }
2340 else {
2341 ad->selected++;
2342 ad->markedlines[whichline] |= VF_SELECTED;
2343 }
2344 }
2345 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2346 }
2347 PaintLine(hwnd, ad->hps, whichline, ad->topline, &Rectl);
2348 if (ad->cursored != wascursored) {
2349 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
2350 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2351 }
2352 }
2353 else {
2354
2355 SHORT numsels, sSelect = 0, numinserted;
2356 ULONG linenum, size;
2357
2358 if (!ad->hex && ad->lines) {
2359
2360 CHAR *p, *e;
2361
2362 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
2363 e = p = ad->lines[whichline];
2364 while (*e != '\r' && *e != '\n' && e < ad->text + ad->textsize) {
2365 if (ad->wrapon && e - p == width)
2366 break;
2367 e++;
2368 }
2369 if ((*e == '\r' || *e == '\n') && e > p)
2370 e--;
2371 width = e - p;
2372 if (!width)
2373 goto NoAdd;
2374
2375 if ((ad->httpin && (*httprun || fHttpRunWPSDefault) &&
2376 strnstr(ad->lines[whichline], "http://", width)) ||
2377 (ad->ftpin && (*ftprun || fFtpRunWPSDefault) &&
2378 strnstr(ad->lines[whichline], "ftp://", width)) ||
2379 (ad->mailin && *mailrun && mailstr(ad->lines[whichline], "@", width))) {
2380
2381 USHORT ret;
2382 URLDATA *urld;
2383
2384 urld = xmallocz(sizeof(URLDATA), pszSrcFile, __LINE__);
2385 if (urld) {
2386 urld->size = sizeof(URLDATA);
2387 urld->line = ad->lines[whichline];
2388 urld->len = width;
2389 ret = (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, UrlDlgProc,
2390 FM3ModHandle, URL_FRAME, urld);
2391 switch (ret) {
2392 case 0:
2393 xfree(urld, pszSrcFile, __LINE__);
2394# ifdef FORTIFY
2395 Fortify_LeaveScope();
2396# endif
2397 goto NoAdd;
2398 case 1:
2399 if (*urld->url) {
2400 if (fHttpRunWPSDefault) {
2401 CHAR WPSDefaultHttpRun[CCHMAXPATH], WPSDefaultHttpRunDir[CCHMAXPATH];
2402
2403 size = sizeof(WPSDefaultHttpRun);
2404 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2405 "DefaultBrowserExe", WPSDefaultHttpRun, &size);
2406 size = sizeof(WPSDefaultHttpRunDir);
2407 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2408 "DefaultWorkingDir", WPSDefaultHttpRunDir, &size);
2409 runemf2(SEPARATE | WINDOWED,
2410 hwnd, pszSrcFile, __LINE__,
2411 WPSDefaultHttpRunDir,
2412 fLibPathStrictHttpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2413 "%s %s", WPSDefaultHttpRun, urld->url);
2414 }
2415 else
2416 runemf2(SEPARATE | WINDOWED,
2417 hwnd, pszSrcFile, __LINE__,
2418 httprundir,
2419 fLibPathStrictHttpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2420 "%s %s", httprun, urld->url);
2421 }
2422 xfree(urld, pszSrcFile, __LINE__);
2423# ifdef FORTIFY
2424 Fortify_LeaveScope();
2425# endif
2426 goto NoAdd;
2427 case 2:
2428 if (*urld->url){
2429 if (fFtpRunWPSDefault) {
2430 CHAR WPSDefaultFtpRun[CCHMAXPATH], WPSDefaultFtpRunDir[CCHMAXPATH];
2431
2432 size = sizeof(WPSDefaultFtpRun);
2433 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2434 "DefaultBrowserExe", WPSDefaultFtpRun, &size);
2435 size = sizeof(WPSDefaultFtpRunDir);
2436 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2437 "DefaultWorkingDir", WPSDefaultFtpRunDir, &size);
2438 runemf2(SEPARATE | WINDOWED,
2439 hwnd, pszSrcFile, __LINE__,
2440 WPSDefaultFtpRunDir,
2441 fLibPathStrictFtpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2442 "%s %s", WPSDefaultFtpRun, urld->url);
2443 }
2444 else
2445 runemf2(SEPARATE | WINDOWED,
2446 hwnd, pszSrcFile, __LINE__,
2447 ftprundir,
2448 fLibPathStrictFtpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2449 "%s %s", ftprun, urld->url);
2450 }
2451 xfree(urld, pszSrcFile, __LINE__);
2452# ifdef FORTIFY
2453 Fortify_LeaveScope();
2454# endif
2455 goto NoAdd;
2456 case 3:
2457 if (*urld->url){
2458 runemf2(SEPARATE | WINDOWED,
2459 hwnd, pszSrcFile, __LINE__,
2460 mailrundir,
2461 fLibPathStrictMailRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2462 "%s %s", mailrun, urld->url);
2463 }
2464 xfree(urld, pszSrcFile, __LINE__);
2465# ifdef FORTIFY
2466 Fortify_LeaveScope();
2467# endif
2468 goto NoAdd;
2469 default:
2470 break;
2471 }
2472 xfree(urld, pszSrcFile, __LINE__);
2473# ifdef FORTIFY
2474 Fortify_LeaveScope();
2475# endif
2476 }
2477 }
2478 }
2479 //Move line to selection box at top of viewer
2480 numsels = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2481 LM_QUERYITEMCOUNT, MPVOID,
2482 MPVOID);
2483 if (numsels > 0) {
2484 for (sSelect = 0; sSelect < numsels; sSelect++) {
2485 linenum =
2486 (ULONG) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2487 LM_QUERYITEMHANDLE,
2488 MPFROM2SHORT(sSelect, 0), MPVOID);
2489 if (linenum == whichline)
2490 goto NoAdd;
2491 }
2492 }
2493 {
2494 CHAR *s = NULL, *p;
2495
2496 if (!ad->hex && ad->lines) {
2497 s = xmalloc(width + 2, pszSrcFile, __LINE__);
2498 if (!s)
2499 goto NoAdd;
2500 strncpy(s, ad->lines[whichline], width + 1);
2501 s[width + 1] = 0;
2502 p = s;
2503 while (*p) {
2504 if (*p == '\r' || *p == '\n') {
2505 *p = 0;
2506 break;
2507 }
2508 p++;
2509 }
2510 }
2511 else {
2512
2513 register ULONG x;
2514
2515 width = ad->textsize - (whichline * 16);
2516 width = min(width, 16); //standard hexx line length
2517 //use 80 as width * 5 gives inconsistent format on short lines
2518 s = xmalloc(80, pszSrcFile, __LINE__);
2519 if (!s)
2520 goto NoAdd;
2521 sprintf(s, "%08lx ", whichline * 16);
2522 p = s + 9;
2523 for (x = 0; x < width; x++) {
2524 sprintf(p, " %02x", (UCHAR)ad->text[(whichline * 16) + x]);
2525 p += 3;
2526 }
2527 *p = ' ';
2528 p++;
2529 *p = ' ';
2530 p++;
2531 for (x = 0; x < width; x++) {
2532 *p = ad->text[(whichline * 16) + x];
2533 p++;
2534 }
2535 *p = 0;
2536 }
2537 if (s) {
2538 if (*s) {
2539 ad->dummy = TRUE;
2540 numinserted = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
2541 NEWVIEW_LISTBOX,
2542 LM_INSERTITEM,
2543 MPFROM2SHORT(LIT_END,
2544 0),
2545 MPFROMP(s));
2546 ad->dummy = FALSE;
2547 if (numinserted >= 0)
2548 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2549 LM_SETITEMHANDLE,
2550 MPFROM2SHORT(numinserted, 0),
2551 MPFROMLONG(whichline));
2552 }
2553 xfree(s, pszSrcFile, __LINE__);
2554# ifdef FORTIFY
2555 Fortify_LeaveScope();
2556# endif
2557 }
2558 }
2559 if (!numsels)
2560 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
2561 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
2562 }
2563 NoAdd:
2564 DosReleaseMutexSem(ad->ScanSem);
2565 DosPostEventSem(CompactSem);
2566 }
2567 break;
2568
2569 case WM_MENUEND:
2570 if (ad && ad->hwndPopup == (HWND) mp2) {
2571 WinDestroyWindow(ad->hwndPopup);
2572 ad->hwndPopup = (HWND) 0;
2573 }
2574 break;
2575
2576 case UM_CONTEXTMENU:
2577 case WM_CONTEXTMENU:
2578 if (ad) {
2579 if (!ad->hwndPopup) {
2580 ad->hwndPopup =
2581 WinLoadMenu(HWND_DESKTOP, FM3ModHandle, NEWVIEW_POPUP);
2582 if (ad->hwndPopup)
2583 WinSetPresParam(ad->hwndPopup,
2584 PP_FONTNAMESIZE,
2585 strlen(GetPString(IDS_8HELVTEXT)) + 1,
2586 GetPString(IDS_8HELVTEXT));
2587 }
2588 if (ad->hwndPopup) {
2589
2590 APIRET rc;
2591 SHORT sSelect;
2592
2593 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
2594 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOCLIP, (rc == 0 &&
2595 ad->selected != 0));
2596 WinEnableMenuItem(ad->hwndPopup, IDM_APPENDTOCLIP, (rc == 0 &&
2597 ad->selected !=
2598 0));
2599 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOLIST,
2600 (rc == 0 && ad->selected != 0));
2601 sSelect =
2602 (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2603 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
2604 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOCLIP2,
2605 (rc == 0 && sSelect > 0));
2606 WinEnableMenuItem(ad->hwndPopup, IDM_APPENDTOCLIP2,
2607 (rc == 0 && sSelect > 0));
2608 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOLIST2,
2609 (rc == 0 && sSelect > 0));
2610 WinEnableMenuItem(ad->hwndPopup, IDM_SELECTALL,
2611 (rc == 0 && ad->numlines != 0 && ad->markedlines));
2612 WinEnableMenuItem(ad->hwndPopup, IDM_DESELECTALL,
2613 (rc == 0 && ad->numlines != 0 && ad->markedlines
2614 && ad->selected != 0));
2615 WinEnableMenuItem(ad->hwndPopup, IDM_PREVSELECTED,
2616 (rc == 0 && ad->numlines != 0 && ad->markedlines
2617 && ad->selected != 0));
2618 WinEnableMenuItem(ad->hwndPopup, IDM_NEXTSELECTED,
2619 (rc == 0 && ad->numlines != 0 && ad->markedlines
2620 && ad->selected != 0));
2621 WinEnableMenuItem(ad->hwndPopup, IDM_SELECTFOUND,
2622 (rc == 0 && ad->numlines != 0 && ad->markedlines
2623 && ad->found != 0));
2624 WinEnableMenuItem(ad->hwndPopup, IDM_DESELECTFOUND,
2625 (rc == 0 && ad->numlines != 0 && ad->markedlines
2626 && ad->selected != 0 && ad->found != 0));
2627 WinEnableMenuItem(ad->hwndPopup, IDM_INVERT,
2628 (rc == 0 && ad->numlines != 0 && ad->markedlines));
2629 WinEnableMenuItem(ad->hwndPopup, IDM_FINDFIRST,
2630 (rc == 0 && ad->numlines != 0 && ad->markedlines));
2631 WinEnableMenuItem(ad->hwndPopup, IDM_FINDNEXT,
2632 (rc == 0 && ad->numlines != 0 && ad->markedlines
2633 && ad->found));
2634 WinEnableMenuItem(ad->hwndPopup, IDM_FINDPREV,
2635 (rc == 0 && ad->numlines != 0 && ad->markedlines
2636 && ad->found));
2637 WinEnableMenuItem(ad->hwndPopup, IDM_GOTOLINE,
2638 (rc == 0 && ad->numlines != 0));
2639 WinEnableMenuItem(ad->hwndPopup, IDM_GOTOOFFSET,
2640 (rc == 0 && ad->textsize != 0));
2641 if (!rc)
2642 DosReleaseMutexSem(ad->ScanSem);
2643 PopupMenu(hwnd, hwnd, ad->hwndPopup);
2644 }
2645 }
2646 break;
2647
2648 case UM_SETUP3:
2649 if (ad && !ad->busy &&
2650 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2651 ad->multiplier = ad->numlines / 32767;
2652 if (ad->multiplier * 32767 != ad->numlines)
2653 ad->multiplier++;
2654 if (!ad->multiplier)
2655 ad->multiplier++;
2656 {
2657 RECTL Rectl;
2658 ULONG numlines;
2659
2660 WinQueryWindowRect(hwnd, &Rectl);
2661 numlines = NumLines(&Rectl, ad);
2662 if (numlines) {
2663 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
2664 MPFROM2SHORT((SHORT) Rectl.xRight, (SHORT) ad->maxx),
2665 MPVOID);
2666 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
2667 MPFROM2SHORT((SHORT) numlines,
2668 (SHORT) min(ad->numlines, 32767)), MPVOID);
2669 if (ad->multiplier)
2670 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
2671 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
2672 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
2673 ad->multiplier) - numlines));
2674 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
2675 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
2676 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
2677 if (ad->numlines - ad->topline < numlines) {
2678 ad->topline = ((ad->numlines - ad->topline) - numlines);
2679 WinInvalidateRect(hwnd, NULL, FALSE);
2680 }
2681 }
2682 }
2683 DosReleaseMutexSem(ad->ScanSem);
2684 }
2685 return 0;
2686
2687 case UM_SETUP4:
2688 if (ad && !ad->busy &&
2689 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2690
2691 CHAR s[140], t[34];
2692 ULONG numlines;
2693 RECTL Rectl;
2694
2695 WinQueryWindowRect(hwnd, &Rectl);
2696 numlines = NumLines(&Rectl, ad);
2697 commafmt(t, sizeof(t), ad->cursored);
2698 strcpy(s, GetPString(IDS_LINECOLONTEXT));
2699 strcat(s, t);
2700 if (ad->selected) {
2701 if (ad->selected > ad->numlines)
2702 ad->selected = 0;
2703 else {
2704 commafmt(t, sizeof(t), ad->selected);
2705 strcat(s, " (");
2706 strcat(s, t);
2707 strcat(s, GetPString(IDS_SELECTEDPARENTEXT));
2708 }
2709 }
2710 if (ad->found) {
2711 if (ad->found > ad->numlines)
2712 ad->found = 0;
2713 else {
2714 commafmt(t, sizeof(t), ad->found);
2715 strcat(s, " (");
2716 strcat(s, t);
2717 strcat(s, GetPString(IDS_FOUNDPARENTEXT));
2718 }
2719 }
2720 WinSetWindowText(ad->hwndStatus2, s);
2721 if (!ad->hex && ad->lines)
2722 commafmt(t, sizeof(t), ad->lines[ad->cursored - 1] - ad->text);
2723 else
2724 commafmt(t, sizeof(t), (ad->cursored - 1) * 16);
2725 strcpy(s, GetPString(IDS_OFFSETCOLONTEXT));
2726 strcat(s, t);
2727 WinSetWindowText(ad->hwndStatus3, s);
2728 if (ad->multiplier)
2729 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
2730 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
2731 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
2732 ad->multiplier) - numlines));
2733 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
2734 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
2735 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
2736 DosReleaseMutexSem(ad->ScanSem);
2737 }
2738 return 0;
2739
2740 case UM_CONTAINER_FILLED:
2741 if (ad && !ad->busy &&
2742 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2743 ad->stopflag = 0;
2744 ad->topline = 1;
2745 ad->cursored = 1;
2746 ad->multiplier = 1;
2747 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2748 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2749 IDM_NEXTBLANKLINE), !ad->hex);
2750 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2751 IDM_PREVBLANKLINE), !ad->hex);
2752 if (ad->numlines)
2753 {
2754 if (mp1 && (ULONG) mp1 < ad->numlines + 1) {
2755
2756 RECTL Rectl;
2757 ULONG numlines;
2758
2759 WinQueryWindowRect(hwnd, &Rectl);
2760 numlines = NumLines(&Rectl, ad);
2761 if (numlines) {
2762 ad->topline = (ULONG) mp1;
2763 if (ad->numlines - ad->topline < numlines)
2764 ad->topline = ad->numlines - numlines;
2765 ad->cursored = (ULONG) mp1;
2766 if (mp2) {
2767 ad->cursored = (ULONG) mp2;
2768 if (ad->cursored > (ad->topline - 1) + numlines)
2769 ad->cursored = (ad->topline - 1) + numlines;
2770 }
2771 }
2772 }
2773 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
2774 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2775 WinInvalidateRect(hwnd, NULL, FALSE);
2776 }
2777 DosReleaseMutexSem(ad->ScanSem);
2778 }
2779 else if (ad)
2780 ad->needrefreshing = TRUE;
2781 return 0;
2782
2783 case WM_ERASEBACKGROUND:
2784 WinFillRect((HPS) mp1, (PRECTL) mp2,
2785 standardcolors[ad->colors[COLORS_NORMALBACK]]);
2786 return 0;
2787
2788 case WM_PAINT:
2789 if (ad) {
2790
2791 HPS hpsp;
2792 RECTL Rectl;
2793 register ULONG x;
2794 ULONG numlines, wascursored = ad->cursored;
2795
2796 hpsp = WinBeginPaint(hwnd, ad->hps, &Rectl);
2797 WinFillRect(hpsp, &Rectl,
2798 standardcolors[ad->colors[COLORS_NORMALBACK]]);
2799 if (!ad->stopflag && !ad->busy &&
2800 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2801 WinQueryWindowRect(hwnd, &Rectl);
2802 numlines = NumLines(&Rectl, ad);
2803 if (numlines) {
2804 if (ad->numlines && (ad->lines || ad->hex)) {
2805 if (ad->topline > (ad->numlines + 1) - numlines)
2806 ad->topline = (ad->numlines + 1) - numlines;
2807 if (ad->topline > ad->numlines)
2808 ad->topline = 1;
2809 if (!ad->topline)
2810 ad->topline = 1;
2811 if (ad->cursored < ad->topline)
2812 ad->cursored = ad->topline;
2813 else if (ad->cursored > (ad->topline + numlines) - 1)
2814 ad->cursored = (ad->topline + numlines) - 1;
2815 if (ad->cursored > ad->numlines)
2816 ad->cursored = ad->numlines;
2817 if (wascursored != ad->cursored)
2818 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2819 }
2820 else
2821 ad->topline = ad->cursored = 1;
2822 if (ad->numlines && (ad->lines || ad->hex)) {
2823 for (x = ad->topline - 1; x < ad->numlines; x++) {
2824 if (((LONG) (Rectl.yTop -
2825 (ad->lMaxHeight *
2826 (((x + 1) - ad->topline) + 1))) -
2827 ad->lMaxDescender) <= 0)
2828 break;
2829 PaintLine(hwnd, hpsp, x, ad->topline, &Rectl);
2830 }
2831 }
2832 }
2833 if (ad->multiplier)
2834 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
2835 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
2836 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
2837 ad->multiplier) - numlines));
2838 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
2839 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
2840 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
2841 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
2842 MPFROM2SHORT((SHORT) Rectl.xRight, (SHORT) ad->maxx),
2843 MPVOID);
2844 DosReleaseMutexSem(ad->ScanSem);
2845 ad->needrefreshing = FALSE;
2846 }
2847 else
2848 ad->needrefreshing = TRUE;
2849 WinEndPaint(hpsp);
2850 }
2851 else {
2852
2853 HPS hpsp;
2854
2855 hpsp = WinBeginPaint(hwnd, (HPS) 0, NULL);
2856 WinEndPaint(hpsp);
2857 }
2858 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2859 break;
2860
2861 case WM_HSCROLL:
2862 {
2863 RECTL rectl;
2864 BOOL invalidate = TRUE;
2865
2866 WinQueryWindowRect(hwnd, &rectl);
2867 switch (SHORT2FROMMP(mp2)) {
2868 case SB_PAGERIGHT:
2869 if (abs(ad->horzscroll) <= ad->maxx - rectl.xRight) {
2870 ad->horzscroll -= rectl.xRight;
2871 if (abs(ad->horzscroll) > ad->maxx - rectl.xRight)
2872 ad->horzscroll = -((ad->maxx - rectl.xRight) +
2873 ad->fattrs.lAveCharWidth);
2874 }
2875 else
2876 invalidate = FALSE;
2877 break;
2878
2879 case SB_PAGELEFT:
2880 if (ad->horzscroll < 0) {
2881 ad->horzscroll += rectl.xRight;
2882 if (ad->horzscroll > 0)
2883 ad->horzscroll = 0;
2884 }
2885 else
2886 invalidate = FALSE;
2887 break;
2888
2889 case SB_LINERIGHT:
2890 if (abs(ad->horzscroll) <= ad->maxx - rectl.xRight)
2891 ad->horzscroll -= ad->fattrs.lAveCharWidth;
2892 else
2893 invalidate = FALSE;
2894 break;
2895
2896 case SB_LINELEFT:
2897 if (ad->horzscroll < 0)
2898 ad->horzscroll += ad->fattrs.lAveCharWidth;
2899 else
2900 invalidate = FALSE;
2901 break;
2902
2903 case SB_SLIDERTRACK:
2904 ad->horzscroll = (SHORT1FROMMP(mp2) / ad->fattrs.lAveCharWidth) *
2905 ad->fattrs.lAveCharWidth;
2906 ad->horzscroll = -(ad->horzscroll);
2907 if (ad->horzscroll > 0)
2908 ad->horzscroll = 0;
2909 if (abs(ad->horzscroll) > (ad->maxx - rectl.xRight) +
2910 ad->fattrs.lAveCharWidth)
2911 ad->horzscroll = -(ad->maxx - rectl.xRight);
2912 break;
2913
2914 default:
2915 invalidate = FALSE;
2916 break;
2917 }
2918 if (invalidate)
2919 WinInvalidateRect(hwnd, NULL, FALSE);
2920 }
2921 break;
2922
2923 case WM_VSCROLL:
2924 if (ad && !ad->stopflag && ad->text && ad->numlines && !ad->busy &&
2925 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2926
2927 ULONG numlines, wascursored;
2928 RECTL rcl;
2929
2930 WinQueryWindowRect(hwnd, &rcl);
2931 numlines = NumLines(&rcl, ad);
2932 if (numlines) {
2933 wascursored = ad->cursored;
2934 switch (SHORT2FROMMP(mp2)) {
2935 case SB_PAGEUP:
2936 if (ad->topline > 1) {
2937 ad->topline -= numlines;
2938 if (ad->topline > ad->numlines ||
2939 ad->topline + numlines > (ad->numlines + 1))
2940 ad->topline = 1;
2941 if (ad->cursored > ad->topline + numlines)
2942 ad->cursored = ad->topline + numlines;
2943 if (ad->cursored > ad->numlines)
2944 ad->cursored = ad->numlines;
2945 WinInvalidateRect(hwnd, NULL, FALSE);
2946 }
2947 break;
2948 case SB_PAGEDOWN:
2949 if (ad->topline + numlines <= ad->numlines) {
2950 ad->topline += numlines;
2951 if (ad->topline + numlines > ad->numlines + 1)
2952 ad->topline = (ad->numlines + 1) - numlines;
2953 if (ad->cursored < ad->topline)
2954 ad->cursored = ad->topline;
2955 if (ad->cursored + 1 > ad->topline + numlines)
2956 ad->cursored = (ad->topline + numlines) - 1;
2957 if (ad->cursored > ad->numlines)
2958 ad->cursored = ad->numlines;
2959 WinInvalidateRect(hwnd, NULL, FALSE);
2960 }
2961 break;
2962 case SB_LINEDOWN:
2963 if (ad->topline + numlines <= ad->numlines) {
2964
2965 RECTL Rectl, iRectl;
2966
2967 ad->topline++;
2968 if (ad->cursored < ad->topline)
2969 ad->cursored = ad->topline;
2970 else if (ad->cursored + 1 > ad->topline + numlines)
2971 ad->cursored = (ad->topline + numlines) - 1;
2972 if (ad->cursored > ad->numlines)
2973 ad->cursored = ad->numlines;
2974 WinQueryWindowRect(hwnd, &Rectl);
2975 WinScrollWindow(hwnd, 0, ad->lMaxHeight,
2976 NULL, NULL, NULLHANDLE, &iRectl, 0);
2977 WinFillRect(ad->hps, &iRectl,
2978 standardcolors[ad->colors[COLORS_NORMALBACK]]);
2979 PaintLine(hwnd, ad->hps, (ad->topline + numlines) - 2,
2980 ad->topline, &Rectl);
2981 if (ad->cursored != ad->topline + numlines)
2982 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &Rectl);
2983 if (wascursored != ad->cursored &&
2984 wascursored < ad->topline + numlines &&
2985 wascursored >= ad->topline)
2986 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
2987 if (numlines >= ad->numlines)
2988 numlines = 0;
2989 if (ad->multiplier)
2990 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
2991 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
2992 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
2993 ad->multiplier) -
2994 numlines));
2995 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
2996 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
2997 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
2998 }
2999 break;
3000 case SB_LINEUP:
3001 if (ad->topline > 1) {
3002
3003 RECTL Rectl, iRectl;
3004
3005 ad->topline--;
3006 if (ad->cursored < ad->topline)
3007 ad->cursored = ad->topline;
3008 else if (ad->cursored + 1 > ad->topline + numlines)
3009 ad->cursored = (ad->topline + numlines) - 1;
3010 if (ad->cursored > ad->numlines)
3011 ad->cursored = ad->numlines;
3012 WinQueryWindowRect(hwnd, &Rectl);
3013 WinScrollWindow(hwnd, 0, -ad->lMaxHeight,
3014 NULL, NULL, NULLHANDLE, &iRectl, 0);
3015 WinFillRect(ad->hps, &iRectl,
3016 standardcolors[ad->colors[COLORS_NORMALBACK]]);
3017 iRectl = Rectl;
3018 iRectl.yTop -= ((numlines * ad->lMaxHeight) + ad->lMaxDescender);
3019 WinFillRect(ad->hps, &iRectl,
3020 standardcolors[ad->colors[COLORS_NORMALBACK]]);
3021 PaintLine(hwnd, ad->hps, ad->topline - 1, ad->topline, &Rectl);
3022 if (ad->cursored != ad->topline)
3023 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &Rectl);
3024 if (ad->cursored != wascursored &&
3025 wascursored >= ad->topline &&
3026 wascursored < ad->topline + numlines)
3027 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
3028 if (numlines >= ad->numlines)
3029 numlines = 0;
3030 if (ad->multiplier)
3031 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3032 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
3033 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
3034 ad->multiplier) -
3035 numlines));
3036 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3037 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
3038 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
3039 }
3040 break;
3041 case SB_SLIDERTRACK:
3042 if ((SHORT1FROMMP(mp2) >= 1) || (SHORT1FROMMP(mp2)) <= ad->numlines) {
3043 ad->topline = (ULONG) SHORT1FROMMP(mp2) * ad->multiplier;
3044 if (ad->topline + numlines > ad->numlines + 1)
3045 ad->topline = (ad->numlines + 1) - numlines;
3046 if (!ad->topline)
3047 ad->topline = 1;
3048 if (ad->cursored < ad->topline)
3049 ad->cursored = ad->topline;
3050 else if (ad->cursored > ad->topline + numlines)
3051 ad->cursored = ad->topline + numlines;
3052 if (ad->cursored > ad->numlines)
3053 ad->cursored = ad->numlines;
3054 WinInvalidateRect(hwnd, NULL, FALSE);
3055 }
3056 else
3057 WinAlarm(HWND_DESKTOP, WA_NOTE);
3058 break;
3059 }
3060 if (ad->cursored != wascursored)
3061 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3062 }
3063 DosReleaseMutexSem(ad->ScanSem);
3064 }
3065 break;
3066
3067 case WM_INITMENU:
3068 switch (SHORT1FROMMP(mp1)) {
3069 case IDM_FILESMENU:
3070 {
3071 APIRET rc;
3072 SHORT sSelect;
3073
3074 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3075 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP, (rc == 0 &&
3076 ad->selected != 0));
3077 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP, (rc == 0 &&
3078 ad->selected != 0));
3079 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST, (rc == 0 &&
3080 ad->selected != 0));
3081 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3082 LM_QUERYITEMCOUNT, MPVOID,
3083 MPVOID);
3084 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP2,
3085 (rc == 0 && sSelect > 0));
3086 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP2,
3087 (rc == 0 && sSelect > 0));
3088 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST2,
3089 (rc == 0 && sSelect > 0));
3090 if (!rc)
3091 DosReleaseMutexSem(ad->ScanSem);
3092 }
3093 break;
3094
3095 case IDM_VIEWSMENU:
3096 {
3097 APIRET rc;
3098
3099 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3100 WinEnableMenuItem((HWND) mp2, IDM_FONTPALETTE, (rc == 0));
3101 WinEnableMenuItem((HWND) mp2, IDM_HEXMODE, (rc == 0));
3102 WinEnableMenuItem((HWND) mp2, IDM_WRAP, (rc == 0));
3103 WinEnableMenuItem((HWND) mp2, IDM_CODEPAGE, (rc == 0));
3104 if (!rc)
3105 DosReleaseMutexSem(ad->ScanSem);
3106 }
3107 WinCheckMenuItem((HWND) mp2, IDM_HEXMODE, ad->hex);
3108 WinCheckMenuItem((HWND) mp2, IDM_WRAP, ad->wrapon);
3109 WinCheckMenuItem((HWND) mp2, IDM_IGNOREFTP, ad->ignoreftp);
3110 WinCheckMenuItem((HWND) mp2, IDM_IGNOREHTTP, ad->ignorehttp);
3111 WinCheckMenuItem((HWND) mp2, IDM_IGNOREMAIL, ad->ignoremail);
3112 break;
3113
3114 case IDM_SEARCHMENU:
3115 {
3116 APIRET rc;
3117
3118 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3119 WinEnableMenuItem((HWND) mp2, IDM_FINDFIRST, (rc == 0 &&
3120 ad->numlines != 0 &&
3121 ad->markedlines));
3122 WinEnableMenuItem((HWND) mp2, IDM_FINDNEXT, (rc == 0 &&
3123 ad->numlines != 0 &&
3124 ad->markedlines &&
3125 ad->found != 0));
3126 WinEnableMenuItem((HWND) mp2, IDM_FINDPREV, (rc == 0 &&
3127 ad->numlines != 0 &&
3128 ad->markedlines &&
3129 ad->found != 0));
3130 WinEnableMenuItem((HWND) mp2, IDM_NEXTBLANKLINE, (rc == 0 &&
3131 ad->numlines != 0 &&
3132 !ad->hex));
3133 WinEnableMenuItem((HWND) mp2, IDM_PREVBLANKLINE, (rc == 0 &&
3134 ad->numlines != 0 &&
3135 !ad->hex));
3136 WinEnableMenuItem((HWND) mp2, IDM_GOTOLINE, (rc == 0 &&
3137 ad->numlines != 0));
3138 WinEnableMenuItem((HWND) mp2, IDM_GOTOOFFSET, (rc == 0 &&
3139 ad->textsize != 0));
3140 if (!rc)
3141 DosReleaseMutexSem(ad->ScanSem);
3142 }
3143 break;
3144
3145 case IDM_SELECTSUBMENU:
3146 {
3147 APIRET rc;
3148
3149 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3150 WinEnableMenuItem((HWND) mp2, IDM_SELECTALL, (rc == 0 &&
3151 ad->numlines != 0 &&
3152 ad->markedlines &&
3153 (ad->selected !=
3154 ad->numlines ||
3155 !ad->selected)));
3156 WinEnableMenuItem((HWND) mp2, IDM_DESELECTALL, (rc == 0 &&
3157 ad->numlines != 0 &&
3158 ad->markedlines &&
3159 ad->selected != 0));
3160 WinEnableMenuItem((HWND) mp2, IDM_DESELECTFOUND, (rc == 0 &&
3161 ad->numlines != 0 &&
3162 ad->markedlines &&
3163 ad->selected != 0 &&
3164 ad->found != 0));
3165 WinEnableMenuItem((HWND) mp2, IDM_SELECTFOUND, (rc == 0 &&
3166 ad->numlines != 0 &&
3167 ad->markedlines &&
3168 ad->found != 0 &&
3169 (ad->numlines !=
3170 ad->selected ||
3171 !ad->selected)));
3172 WinEnableMenuItem((HWND) mp2, IDM_NEXTSELECTED, (rc == 0 &&
3173 ad->numlines != 0 &&
3174 ad->markedlines &&
3175 ad->selected != 0));
3176 WinEnableMenuItem((HWND) mp2, IDM_PREVSELECTED, (rc == 0 &&
3177 ad->numlines != 0 &&
3178 ad->markedlines &&
3179 ad->selected != 0));
3180 WinEnableMenuItem((HWND) mp2, IDM_INVERT, (rc == 0 &&
3181 ad->numlines != 0 &&
3182 ad->markedlines));
3183 if (!rc)
3184 DosReleaseMutexSem(ad->ScanSem);
3185 }
3186 break;
3187 }
3188 break;
3189
3190 case UM_CONTROL:
3191 switch (SHORT1FROMMP(mp1)) {
3192 case NEWVIEW_LISTBOX:
3193 switch (SHORT2FROMMP(mp1)) {
3194 case LN_SETFOCUS:
3195 if (ad) {
3196 if (!ad->clientfocused) {
3197 PostMsg(hwnd,
3198 WM_COMMAND, MPFROM2SHORT(IDM_NEXTWINDOW, 0), MPVOID);
3199 break;
3200 }
3201 ad->clientfocused = FALSE;
3202 }
3203 PostMsg(hwnd,
3204 UM_CONTROL, MPFROM2SHORT(NEWVIEW_LISTBOX, LN_SELECT), MPVOID);
3205 break;
3206 case LN_KILLFOCUS:
3207 if (ad) {
3208 ad->clientfocused = TRUE;
3209 WinSetFocus(HWND_DESKTOP, hwnd);
3210 }
3211 break;
3212 case LN_SELECT:
3213 if (ad && !ad->dummy) {
3214
3215 ULONG linenum, numlines;
3216 SHORT sSelect;
3217 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
3218 SHORT1FROMMP(mp1));
3219 RECTL Rectl;
3220
3221 sSelect = (SHORT) WinSendMsg(hwndUL,
3222 LM_QUERYSELECTION,
3223 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3224 if (sSelect >= 0) {
3225 linenum = (ULONG) WinSendMsg(hwndUL,
3226 LM_QUERYITEMHANDLE,
3227 MPFROM2SHORT(sSelect, 0), MPVOID);
3228 if (ad->topline != linenum + 1 && linenum < ad->numlines) {
3229 WinQueryWindowRect(hwnd, &Rectl);
3230 numlines = NumLines(&Rectl, ad);
3231 ad->topline = linenum + 1;
3232 if (ad->numlines - ad->topline < numlines)
3233 ad->topline = ad->numlines - numlines;
3234 ad->cursored = linenum + 1;
3235 WinInvalidateRect(hwnd, NULL, FALSE);
3236 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3237 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3238 }
3239 }
3240 else
3241 PostMsg(hwndUL, LM_SELECTITEM, MPFROM2SHORT(0, 0),
3242 MPFROM2SHORT(TRUE, 0));
3243 }
3244 break;
3245
3246 case LN_ENTER:
3247 if (ad) {
3248
3249 SHORT sSelect;
3250 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
3251 SHORT1FROMMP(mp1));
3252
3253 sSelect = (SHORT) WinSendMsg(hwndUL,
3254 LM_QUERYSELECTION,
3255 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3256 if (sSelect >= 0) {
3257 ad->dummy = TRUE;
3258 WinSendMsg(hwndUL, LM_DELETEITEM,
3259 MPFROM2SHORT(sSelect, 0), MPVOID);
3260 ad->dummy = FALSE;
3261 sSelect = (SHORT) WinSendMsg(hwndUL,
3262 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
3263 if (sSelect <= 0) {
3264 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
3265 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3266 WinSetFocus(HWND_DESKTOP, hwnd);
3267 }
3268 }
3269 }
3270 break;
3271
3272 default:
3273 break;
3274 }
3275 break;
3276
3277 default:
3278 break;
3279 }
3280 return 0;
3281
3282 case WM_COMMAND:
3283 switch (SHORT1FROMMP(mp1)) {
3284 case IDM_EDIT:
3285 if (*editor) {
3286
3287 CHAR *dummy[2];
3288
3289 dummy[0] = ad->filename;
3290 dummy[1] = NULL;
3291 ExecOnList(hwnd, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
3292 pszSrcFile, __LINE__);
3293 }
3294 else
3295 StartMLEEditor(ad->hwndParent, 4, ad->filename, ad->hwndFrame);
3296 ad->hwndRestore = (HWND) 0;
3297 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
3298 break;
3299
3300 case IDM_IGNOREFTP:
3301 ad->ignoreftp = (ad->ignoreftp) ? FALSE : TRUE;
3302 ad->ftpin = FALSE;
3303 if (ad->text && (*ftprun || fFtpRunWPSDefault) &&
3304 !ad->ignoreftp && strstr(ad->text, "ftp://"))
3305 ad->ftpin = TRUE;
3306 IgnoreFTP = ad->ignoreftp;
3307 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreFTP",
3308 &ad->ignoreftp, sizeof(BOOL));
3309 WinInvalidateRect(hwnd, NULL, FALSE);
3310 break;
3311
3312 case IDM_IGNOREHTTP:
3313 ad->ignorehttp = (ad->ignorehttp) ? FALSE : TRUE;
3314 ad->httpin = FALSE;
3315 if (ad->text && (*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
3316 strstr(ad->text, "http://"))
3317 ad->httpin = TRUE;
3318 IgnoreHTTP = ad->ignorehttp;
3319 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
3320 &ad->ignorehttp, sizeof(BOOL));
3321 WinInvalidateRect(hwnd, NULL, FALSE);
3322 break;
3323
3324 case IDM_IGNOREMAIL:
3325 ad->ignoremail = (ad->ignoremail) ? FALSE : TRUE;
3326 ad->mailin = FALSE;
3327 if (ad->text && *mailrun && !ad->ignoremail &&
3328 strstr(ad->text, "@"))
3329 ad->mailin = TRUE;
3330 IgnoreMail = ad->ignoremail;
3331 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreMail",
3332 &ad->ignoremail, sizeof(BOOL));
3333 WinInvalidateRect(hwnd, NULL, FALSE);
3334 break;
3335
3336 case IDM_PREVBLANKLINE:
3337 if (!ad->hex && ad->lines) {
3338
3339 ULONG x;
3340
3341 x = ad->cursored - 2;
3342 if (x >= ad->numlines)
3343 x = 0;
3344 while (x < ad->numlines &&
3345 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3346 x--;
3347 if (x >= ad->numlines)
3348 x = 0;
3349 for (; x < ad->numlines; x--) {
3350 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3351 if (x < ad->numlines - 1)
3352 x++;
3353 break;
3354 }
3355 }
3356 if (x < ad->numlines) {
3357 ad->topline = ad->cursored = x;
3358 WinInvalidateRect(hwnd, NULL, FALSE);
3359 }
3360 }
3361 break;
3362
3363 case IDM_NEXTBLANKLINE:
3364 if (!ad->hex && ad->lines) {
3365
3366 ULONG x;
3367
3368 x = ad->cursored;
3369 while (x < ad->numlines &&
3370 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3371 x++;
3372 for (; x < ad->numlines; x++) {
3373 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3374 if (x < ad->numlines - 1)
3375 x++;
3376 break;
3377 }
3378 }
3379 if (x < ad->numlines) {
3380 while (x < ad->numlines &&
3381 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3382 x++;
3383 if (x < ad->numlines) {
3384 ad->topline = ad->cursored = x;
3385 WinInvalidateRect(hwnd, NULL, FALSE);
3386 }
3387 }
3388 }
3389 break;
3390
3391 case IDM_VIEW:
3392 case IDM_OBJECT:
3393 if (!ad->hex && ad->lines) {
3394
3395 CHAR line[CCHMAXPATH], filename[CCHMAXPATH], *p;
3396
3397 strncpy(line, ad->lines[ad->cursored - 1], CCHMAXPATH);
3398 line[CCHMAXPATH - 1] = 0;
3399 chop_at_crnl(line);
3400 if (*line == '\"') {
3401 memmove(line, line + 1, strlen(line));
3402 p = strchr(line, '\"');
3403 lstrip(line);
3404 if (p)
3405 *p = 0;
3406 rstrip(line);
3407 }
3408 else {
3409 lstrip(line);
3410 p = strchr(line, ' ');
3411 if (p)
3412 *p = 0;
3413 rstrip(line);
3414 }
3415 if (!strchr(line, '\\') && !strchr(line, '/') && !strchr(line, ':')) {
3416 strcpy(filename, ad->filename);
3417 p = strrchr(filename, '\\');
3418 if (p)
3419 p++;
3420 else
3421 p = filename;
3422 strcpy(p, line);
3423 }
3424 else
3425 strcpy(filename, line);
3426 MakeFullName(filename);
3427 if (*filename && IsFile(filename) == 1) {
3428 if (SHORT1FROMMP(mp1) == IDM_OBJECT)
3429 OpenObject(filename, Default, ad->hwndFrame);
3430 else
3431 DefaultView(hwnd, ad->hwndFrame, HWND_DESKTOP, NULL, 0, filename);
3432 }
3433 }
3434 break;
3435
3436 case IDM_COLORPALETTE:
3437 {
3438 COLORS co;
3439 LONG temp[COLORS_MAX];
3440
3441 memset(&co, 0, sizeof(co));
3442 co.size = sizeof(co);
3443 co.numcolors = COLORS_MAX;
3444 co.colors = ad->colors;
3445 co.descriptions = IDS_NVCOLORS1TEXT;
3446 co.origs = temp;
3447 co.prompt = IDS_NVCOLORSPROMPTTEXT;
3448 memcpy(temp, ad->colors, sizeof(LONG) * COLORS_MAX);
3449 if (WinDlgBox(HWND_DESKTOP,
3450 hwnd,
3451 ColorDlgProc,
3452 FM3ModHandle, COLOR_FRAME, (PVOID) & co)) {
3453 memcpy(Colors, ad->colors, sizeof(LONG) * COLORS_MAX);
3454 PrfWriteProfileData(fmprof,
3455 appname,
3456 "Viewer.Colors",
3457 &ad->colors, sizeof(LONG) * COLORS_MAX);
3458 WinInvalidateRect(hwnd, NULL, FALSE);
3459 WinInvalidateRect(ad->hwndStatus1, NULL, FALSE);
3460 WinInvalidateRect(ad->hwndStatus2, NULL, FALSE);
3461 WinInvalidateRect(ad->hwndStatus3, NULL, FALSE);
3462 }
3463 }
3464 break;
3465
3466 case IDM_NEXTWINDOW:
3467 case IDM_PREVWINDOW:
3468 {
3469 SHORT sSelect;
3470
3471 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
3472 NEWVIEW_LISTBOX,
3473 LM_QUERYITEMCOUNT,
3474 MPVOID, MPVOID);
3475 if (sSelect) {
3476 if (!ad->clientfocused)
3477 WinSetFocus(HWND_DESKTOP, hwnd);
3478 else
3479 WinSetFocus(HWND_DESKTOP,
3480 WinWindowFromID(ad->hwndFrame, NEWVIEW_LISTBOX));
3481 }
3482 else
3483 WinSetFocus(HWND_DESKTOP, hwnd);
3484 }
3485 break;
3486
3487 case IDM_FINDFIRST:
3488 {
3489 APIRET rc;
3490
3491 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3492 if (!rc) {
3493 if (!ad->busy && ad->text && ad->numlines && ad->markedlines) {
3494
3495 ULONG numlines;
3496 RECTL Rectl;
3497 static char test[SEARCHSTRINGLEN];
3498
3499 WinQueryWindowRect(hwnd, &Rectl);
3500 numlines = NumLines(&Rectl, ad);
3501 if (!numlines)
3502 break;
3503 strcpy(test, ad->searchtext);
3504 if (WinDlgBox(HWND_DESKTOP, hwnd, FindStrDlgProc, FM3ModHandle,
3505 NEWFIND_FRAME, (PVOID) & hwnd)) {
3506 if (*ad->searchtext && strcmp(test, ad->searchtext))
3507 PrfWriteProfileString(fmprof,
3508 appname,
3509 "Viewer.Searchtext",
3510 (PVOID) ad->searchtext);
3511 if (_beginthread(SearchThread, NULL, 524288, (PVOID) hwnd) ==
3512 -1)
3513 Runtime_Error(pszSrcFile, __LINE__,
3514 GetPString(IDS_COULDNTSTARTTHREADTEXT));
3515 }
3516 }
3517 DosReleaseMutexSem(ad->ScanSem);
3518 }
3519 }
3520 break;
3521
3522 case IDM_PREVSELECTED:
3523 case IDM_NEXTSELECTED:
3524 case IDM_FINDPREV:
3525 case IDM_FINDNEXT:
3526 {
3527 APIRET rc;
3528
3529 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3530 if (!rc) {
3531 if (!ad->busy && ad->text && ad->markedlines) {
3532
3533 RECTL Rectl;
3534 register ULONG x;
3535 ULONG numlines;
3536 CHAR markedwith;
3537
3538 markedwith = (SHORT1FROMMP(mp1) == IDM_FINDNEXT ||
3539 SHORT1FROMMP(mp1) == IDM_FINDPREV) ?
3540 VF_FOUND : VF_SELECTED;
3541 WinQueryWindowRect(hwnd, &Rectl);
3542 numlines = NumLines(&Rectl, ad);
3543 if (!numlines)
3544 break;
3545 WinSetPointer(HWND_DESKTOP, hptrBusy);
3546 if (SHORT1FROMMP(mp1) == IDM_PREVSELECTED ||
3547 SHORT1FROMMP(mp1) == IDM_FINDPREV) {
3548 for (x = ad->cursored - 2; x < ULONG_MAX - 1; x--) {
3549 if (ad->markedlines[x] & markedwith) {
3550 ad->topline = x + 1;
3551 if (ad->numlines - ad->topline < numlines)
3552 ad->topline = ad->numlines - numlines;
3553 ad->cursored = x + 1;
3554 WinInvalidateRect(hwnd, NULL, FALSE);
3555 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3556 break;
3557 }
3558 }
3559 }
3560 else {
3561 for (x = ad->cursored; x < ad->numlines; x++) {
3562 if (ad->markedlines[x] & markedwith) {
3563 ad->topline = x + 1;
3564 if (ad->numlines - ad->topline < numlines)
3565 ad->topline = ad->numlines - numlines;
3566 ad->cursored = x + 1;
3567 WinInvalidateRect(hwnd, NULL, FALSE);
3568 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3569 break;
3570 }
3571 }
3572 }
3573 WinSetPointer(HWND_DESKTOP, hptrArrow);
3574 if (x >= ad->numlines)
3575 DosBeep(50, 100);
3576 }
3577 DosReleaseMutexSem(ad->ScanSem);
3578 }
3579 }
3580 break;
3581
3582 case IDM_SELECTFOUND:
3583 case IDM_DESELECTFOUND:
3584 {
3585 APIRET rc;
3586
3587 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3588 if (!rc) {
3589 if (!ad->busy && ad->text && ad->markedlines) {
3590
3591 RECTL Rectl;
3592 register ULONG x;
3593 ULONG numlines;
3594
3595 WinQueryWindowRect(hwnd, &Rectl);
3596 numlines = NumLines(&Rectl, ad);
3597 if (!numlines)
3598 break;
3599 WinSetPointer(HWND_DESKTOP, hptrBusy);
3600 for (x = 0; x < ad->numlines; x++) {
3601 if (SHORT1FROMMP(mp1) == IDM_SELECTFOUND) {
3602 if ((ad->markedlines[x] & VF_FOUND) &&
3603 !(ad->markedlines[x] & VF_SELECTED)) {
3604 ad->markedlines[x] |= VF_SELECTED;
3605 ad->selected++;
3606 }
3607 }
3608 else {
3609 if ((ad->markedlines[x] & VF_FOUND) &&
3610 (ad->markedlines[x] & VF_SELECTED)) {
3611 ad->markedlines[x] &= (~VF_SELECTED);
3612 ad->selected--;
3613 }
3614 }
3615 }
3616 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3617 WinSetPointer(HWND_DESKTOP, hptrArrow);
3618 WinInvalidateRect(hwnd, NULL, FALSE);
3619 }
3620 DosReleaseMutexSem(ad->ScanSem);
3621 }
3622 }
3623 break;
3624
3625 case IDM_GOTOLINE:
3626 case IDM_GOTOOFFSET:
3627 {
3628 APIRET rc;
3629
3630 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3631 if (!rc) {
3632 if (!ad->busy && ad->numlines) {
3633
3634 ULONG numlines, linenum;
3635 CHAR s[34], ss[134];
3636 STRINGINPARMS sip;
3637 RECTL Rectl;
3638 register ULONG x;
3639
3640 WinQueryWindowRect(hwnd, &Rectl);
3641 numlines = NumLines(&Rectl, ad);
3642 if (!numlines)
3643 break;
3644 if (ad->numlines <= numlines) {
3645 DosBeep(500, 100);
3646 break;
3647 }
3648 sip.help = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3649 GetPString(IDS_NVLINEJUMPTEXT) : GetPString(IDS_NVBYTEJUMPTEXT);
3650 sip.ret = s;
3651 *s = 0;
3652 sip.prompt = ss;
3653 sip.inputlen = 34;
3654 sip.title = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3655 GetPString(IDS_NVLINEJUMPTITLETEXT) :
3656 GetPString(IDS_NVBYTEJUMPTITLETEXT);
3657 sprintf(sip.prompt,
3658 GetPString(IDS_NVJUMPTEXT),
3659 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3660 GetPString(IDS_LINETEXT) :
3661 GetPString(IDS_OFFSETTEXT),
3662 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3663 1 :
3664 0,
3665 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3666 ad->numlines : ad->textsize - 1);
3667 WinDlgBox(HWND_DESKTOP,
3668 hwnd, InputDlgProc, FM3ModHandle, STR_FRAME, &sip);
3669 if (*s) {
3670 s[33] = 0;
3671 linenum = atol(s);
3672 switch (SHORT1FROMMP(mp1)) {
3673 case IDM_GOTOLINE:
3674 if (linenum > 0 && linenum <= ad->numlines) {
3675 ad->topline = linenum;
3676 ad->cursored = ad->topline;
3677 if (ad->numlines - ad->topline < numlines)
3678 ad->topline = (ad->numlines - numlines) + 1;
3679 WinInvalidateRect(hwnd, NULL, FALSE);
3680 }
3681 break;
3682 case IDM_GOTOOFFSET:
3683 if (linenum < ad->textsize) {
3684 if (ad->hex)
3685 ad->topline = (linenum / 16) + 1;
3686 else if (ad->lines) {
3687 ad->topline = (ULONG) - 1;
3688 for (x = 0; x < ad->numlines; x++) {
3689 if (ad->lines[x] > ad->text + linenum) {
3690 ad->topline = x + 1;
3691 break;
3692 }
3693 }
3694 if (ad->topline == (ULONG) - 1)
3695 ad->topline = ad->numlines;
3696 }
3697 ad->cursored = ad->topline;
3698 if (ad->numlines - ad->topline < numlines)
3699 ad->topline = (ad->numlines - numlines) + 1;
3700 WinInvalidateRect(hwnd, NULL, FALSE);
3701 }
3702 break;
3703 }
3704 }
3705 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3706 }
3707 DosReleaseMutexSem(ad->ScanSem);
3708 }
3709 }
3710 break;
3711
3712 case IDM_CODEPAGE:
3713 {
3714 INT cp;
3715
3716 cp = PickCodepage(hwnd);
3717 if (cp != -1) {
3718 ad->fattrs.usCodePage = (USHORT) cp;
3719 Codepage = ad->fattrs.usCodePage;
3720 PrfWriteProfileData(fmprof,
3721 appname,
3722 "Viewer.Codepage",
3723 &ad->fattrs.usCodePage, sizeof(USHORT));
3724 GpiDeleteSetId(ad->hps, FIXED_FONT_LCID);
3725 GpiAssociate(ad->hps, 0);
3726 GpiDestroyPS(ad->hps);
3727 ad->hps = InitWindow(hwnd);
3728 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3729 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3730 WinInvalidateRect(hwnd, NULL, FALSE);
3731 }
3732 }
3733 break;
3734
3735 case IDM_SAVETOLIST2:
3736 case IDM_SAVETOCLIP2:
3737 case IDM_APPENDTOCLIP2:
3738 case IDM_SAVETOLIST:
3739 case IDM_SAVETOCLIP:
3740 case IDM_APPENDTOCLIP:
3741 {
3742 APIRET rc;
3743
3744 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3745 if (!rc) {
3746 if (!ad->busy) {
3747 ad->cliptype = SHORT1FROMMP(mp1);
3748 if (_beginthread(ClipboardThread, NULL, 524288, (PVOID) hwnd) ==
3749 -1)
3750 Runtime_Error(pszSrcFile, __LINE__,
3751 GetPString(IDS_COULDNTSTARTTHREADTEXT));
3752 }
3753 DosReleaseMutexSem(ad->ScanSem);
3754 }
3755 }
3756 break;
3757
3758 case IDM_SELECTALL:
3759 case IDM_DESELECTALL:
3760 case IDM_INVERT:
3761 {
3762 APIRET rc;
3763
3764 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3765 if (!rc) {
3766 if (!ad->busy && ad->markedlines) {
3767
3768 register ULONG x;
3769
3770 for (x = 0; x < ad->numlines; x++) {
3771 switch (SHORT1FROMMP(mp1)) {
3772 case IDM_SELECTALL:
3773 if (!(ad->markedlines[x] & VF_SELECTED)) {
3774 ad->markedlines[x] |= VF_SELECTED;
3775 ad->selected++;
3776 }
3777 break;
3778 case IDM_DESELECTALL:
3779 if (ad->markedlines[x] & VF_SELECTED) {
3780 ad->markedlines[x] &= (~VF_SELECTED);
3781 ad->selected--;
3782 }
3783 break;
3784 case IDM_INVERT:
3785 if (ad->markedlines[x] & VF_SELECTED) {
3786 ad->markedlines[x] &= (~VF_SELECTED);
3787 ad->selected--;
3788 }
3789 else {
3790 ad->markedlines[x] |= VF_SELECTED;
3791 ad->selected++;
3792 }
3793 break;
3794 }
3795 }
3796 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3797 WinInvalidateRect(hwnd, NULL, FALSE);
3798 }
3799 DosReleaseMutexSem(ad->ScanSem);
3800 }
3801 }
3802 break;
3803
3804 case IDM_WRAP:
3805 {
3806 APIRET rc;
3807
3808 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3809 if (!rc) {
3810 if (!ad->busy) {
3811 ad->wrapon = ad->wrapon ? FALSE : TRUE;
3812 WrapOn = ad->wrapon;
3813 PrfWriteProfileData(fmprof, appname, "Viewer.WrapOn",
3814 &ad->wrapon, sizeof(BOOL));
3815 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3816 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3817 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3818 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3819 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
3820 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
3821 MPVOID, MPVOID);
3822 ad->oldwidth = -1;
3823 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3824 MPFROM2SHORT(1, 1), MPVOID);
3825 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3826 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3827 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3828 MPFROM2SHORT(1, 1), MPVOID);
3829 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3830 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3831 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
3832 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3833 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3834 NEWVIEW_DRAG), NULL, FALSE);
3835 //WinInvalidateRect(ad->hhscroll, NULL, FALSE);
3836 }
3837 DosReleaseMutexSem(ad->ScanSem);
3838 }
3839 }
3840 break;
3841
3842 case IDM_HEXMODE:
3843 {
3844 APIRET rc;
3845
3846 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3847 if (!rc) {
3848 if (!ad->busy) {
3849 ad->hex = (ad->hex) ? FALSE : TRUE;
3850 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3851 IDM_NEXTBLANKLINE), !ad->hex);
3852 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3853 IDM_PREVBLANKLINE), !ad->hex);
3854 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3855 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3856 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3857 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3858 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
3859 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
3860 MPVOID, MPVOID);
3861 ad->oldwidth = -1;
3862 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3863 MPFROM2SHORT(1, 1), MPVOID);
3864 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3865 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3866 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3867 MPFROM2SHORT(1, 1), MPVOID);
3868 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3869 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3870 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
3871 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3872 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3873 NEWVIEW_DRAG), NULL, FALSE);
3874 //WinInvalidateRect(ad->hhscroll, NULL, FALSE);
3875 }
3876 DosReleaseMutexSem(ad->ScanSem);
3877 }
3878 }
3879 break;
3880
3881 case IDM_FONTPALETTE:
3882 {
3883 APIRET rc;
3884
3885 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3886 if (!rc) {
3887 SetMLEFont(hwnd, &ad->fattrs, 11);
3888 PrfWriteProfileData(fmprof, appname, "Viewer.Fattrs",
3889 &ad->fattrs, sizeof(FATTRS));
3890 Fattrs = ad->fattrs;
3891 GpiDeleteSetId(ad->hps, FIXED_FONT_LCID);
3892 GpiAssociate(ad->hps, 0);
3893 GpiDestroyPS(ad->hps);
3894 ad->hps = InitWindow(hwnd);
3895 DosReleaseMutexSem(ad->ScanSem);
3896 WinSendMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3897 WinInvalidateRect(hwnd, NULL, FALSE);
3898 }
3899 }
3900 break;
3901
3902 case IDM_HELP:
3903 if (hwndHelp)
3904 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
3905 MPFROM2SHORT(HELP_NEWVIEW, 0), MPFROMSHORT(HM_RESOURCEID));
3906 break;
3907 }
3908 return 0;
3909
3910 case WM_SETFOCUS:
3911 if (mp2)
3912 WinSendMsg(hwnd, UM_SETUP5, MPVOID, MPVOID);
3913 if (mp2 && ad && ad->needrefreshing && !ad->stopflag &&
3914 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
3915 ad->needrefreshing = FALSE;
3916 DosReleaseMutexSem(ad->ScanSem);
3917 WinInvalidateRect(hwnd, NULL, TRUE);
3918 }
3919 break;
3920
3921 case WM_SIZE:
3922 if (SHORT1FROMMP(mp2) && SHORT2FROMMP(mp2)) {
3923 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3924 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3925 }
3926 break;
3927
3928 case WM_SAVEAPPLICATION:
3929 if (ad && ParentIsDesktop(hwnd, ad->hwndParent)) {
3930
3931 SWP swp;
3932
3933 WinQueryWindowPos(ad->hwndFrame, &swp);
3934 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
3935 PrfWriteProfileData(fmprof,
3936 appname, "NewViewSizePos", &swp, sizeof(swp));
3937 }
3938 break;
3939
3940 case WM_CLOSE:
3941 if (ad)
3942 ad->stopflag = 1;
3943 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
3944 return 0;
3945
3946 case WM_DESTROY:
3947 {
3948 BOOL dontclose = FALSE;
3949 HWND hwndRestore = (HWND) 0;
3950
3951 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER5);
3952 if (ad) {
3953 ad->stopflag = 1;
3954 if (ad->ScanSem) {
3955 DosRequestMutexSem(ad->ScanSem, 15000);
3956 DosCloseMutexSem(ad->ScanSem);
3957 }
3958 if (ad->busy)
3959 DosSleep(100); //05 Aug 07 GKY 128
3960 if (ad->hps) {
3961 GpiDeleteSetId(ad->hps, FIXED_FONT_LCID);
3962 GpiAssociate(ad->hps, 0);
3963 GpiDestroyPS(ad->hps);
3964 }
3965 hwndRestore = ad->hwndRestore;
3966 dontclose = ((ad->flags & 4) != 0) ? TRUE : FALSE;
3967 FreeViewerMem(hwnd);
3968 WinSetWindowPtr(hwnd, QWL_USER, NULL);
3969 xfree(ad, pszSrcFile, __LINE__);
3970# ifdef FORTIFY
3971 xFortify_LeaveScope(pszSrcFile, __LINE__);
3972# endif
3973 }
3974 if (hwndRestore && hwndRestore != HWND_DESKTOP) {
3975
3976 ULONG fl = SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER;
3977 SWP swp;
3978
3979 if (WinQueryWindowPos(hwndRestore, &swp)) {
3980 if (!(swp.fl & SWP_MAXIMIZE))
3981 fl |= SWP_RESTORE;
3982 WinSetWindowPos(hwndRestore, HWND_TOP, 0, 0, 0, 0, fl);
3983 }
3984 }
3985 if (!dontclose &&
3986 ParentIsDesktop(hwnd, WinQueryWindow(WinQueryWindow(hwnd,
3987 QW_PARENT),
3988 QW_PARENT))) {
3989 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
3990 DosExit(EXIT_PROCESS, 1);
3991 }
3992 }
3993 break;
3994 }
3995
3996 return WinDefWindowProc(hwnd, msg, mp1, mp2);
3997}
3998
3999HWND StartViewer(HWND hwndParent, USHORT flags, CHAR * filename,
4000 HWND hwndRestore)
4001{
4002 HWND hwndFrame = (HWND) 0, hwndClient;
4003 VIEWDATA *ad;
4004 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
4005 FCF_SIZEBORDER | FCF_MINMAX |
4006 FCF_NOBYTEALIGN | FCF_VERTSCROLL |
4007 FCF_MENU | FCF_ICON | FCF_ACCELTABLE | FCF_HORZSCROLL;
4008
4009 if (strcmp(realappname, FM3Str))
4010 hwndParent = HWND_DESKTOP;
4011 if (ParentIsDesktop(hwndParent, hwndParent))
4012 FrameFlags |= FCF_TASKLIST;
4013 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"\"%s\"\r\rparent %s desktop",filename,(ParentIsDesktop(hwndParent,hwndParent)) ? "is" : "isn't");
4014 hwndFrame = WinCreateStdWindow(hwndParent,
4015 0,
4016 &FrameFlags,
4017 WC_NEWVIEW,
4018 GetPString(IDS_FM2VIEWERTITLETEXT),
4019 fwsAnimate,
4020 FM3ModHandle, NEWVIEW_FRAME, &hwndClient);
4021 if (hwndFrame) {
4022
4023 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
4024
4025 if (!fToolbar && hwndMenu) {
4026 WinSendMsg(hwndMenu, MM_DELETEITEM,
4027 MPFROM2SHORT(IDM_FINDFIRST, FALSE), MPVOID);
4028 WinSendMsg(hwndMenu, MM_DELETEITEM,
4029 MPFROM2SHORT(IDM_FINDNEXT, FALSE), MPVOID);
4030 WinSendMsg(hwndMenu, MM_DELETEITEM,
4031 MPFROM2SHORT(IDM_FINDPREV, FALSE), MPVOID);
4032 WinSendMsg(hwndMenu, MM_DELETEITEM,
4033 MPFROM2SHORT(IDM_SAVETOCLIP, FALSE), MPVOID);
4034 }
4035 ad = xmallocz(sizeof(VIEWDATA), pszSrcFile, __LINE__);
4036 if (!ad) {
4037 WinDestroyWindow(hwndFrame);
4038 hwndFrame = (HWND)0;
4039 }
4040 else {
4041 ad->size = sizeof(VIEWDATA);
4042 ad->stopflag = 0;
4043 ad->multiplier = 1;
4044 ad->hwndRestore = hwndRestore;
4045 ad->hwndFrame = hwndFrame;
4046 ad->hwndParent = hwndParent;
4047 ad->clientfocused = TRUE;
4048 ad->oldwidth = -1;
4049 strcpy(ad->filename, filename);
4050 ad->flags = flags;
4051 if (ad->flags & 16)
4052 ad->hex = TRUE;
4053 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
4054 if (Firsttime) {
4055
4056 ULONG size;
4057
4058 size = sizeof(BOOL);
4059 PrfQueryProfileData(fmprof, appname, "Viewer.Sensitive",
4060 (PVOID) & Sensitive, &size);
4061 size = sizeof(USHORT);
4062 PrfQueryProfileData(fmprof, appname, "Viewer.Codepage",
4063 (PVOID) & Codepage, &size);
4064 size = sizeof(BOOL);
4065 PrfQueryProfileData(fmprof, appname, "Viewer.LiteralSearch",
4066 (PVOID) & LiteralSearch, &size);
4067 size = sizeof(BOOL);
4068 PrfQueryProfileData(fmprof, appname, "Viewer.AlsoSelect",
4069 (PVOID) & AlsoSelect, &size);
4070 size = sizeof(BOOL);
4071 PrfQueryProfileData(fmprof, appname, "Viewer.WrapOn",
4072 (PVOID) & WrapOn, &size);
4073 size = sizeof(BOOL);
4074 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreFTP",
4075 (PVOID) & IgnoreFTP, &size);
4076 size = sizeof(BOOL);
4077 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
4078 (PVOID) & IgnoreHTTP, &size);
4079 size = sizeof(BOOL);
4080 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreMail",
4081 (PVOID) & IgnoreMail, &size);
4082 memset(&Fattrs, 0, sizeof(FATTRS));
4083 size = sizeof(FATTRS);
4084 Fattrs.usRecordLength = sizeof(FATTRS);
4085 Fattrs.lMaxBaselineExt = 16;
4086 Fattrs.lAveCharWidth = 8;
4087 Fattrs.usCodePage = Codepage;
4088 strcpy(Fattrs.szFacename, GetPString(IDS_SYSMONOTEXT));
4089 PrfQueryProfileData(fmprof, appname, "Viewer.Fattrs",
4090 (PVOID) & Fattrs, &size);
4091 size = sizeof(LONG) * COLORS_MAX;
4092 PrfQueryProfileData(fmprof, appname, "Viewer.Colors",
4093 (PVOID) Colors, &size);
4094 Firsttime = FALSE;
4095 }
4096 {
4097 ULONG size = sizeof(ad->searchtext);
4098
4099 PrfQueryProfileData(fmprof, appname, "Viewer.Searchtext",
4100 (PVOID) ad->searchtext, &size);
4101 ad->searchtext[sizeof(ad->searchtext) - 1] = 0;
4102 }
4103 ad->sensitive = Sensitive;
4104 ad->literalsearch = LiteralSearch;
4105 ad->fattrs = Fattrs;
4106 ad->alsoselect = AlsoSelect;
4107 ad->fattrs.usCodePage = Codepage;
4108 ad->wrapon = WrapOn;
4109 ad->ignorehttp = IgnoreHTTP;
4110 ad->ignoreftp = IgnoreFTP;
4111 ad->ignoremail = IgnoreMail;
4112 memcpy(ad->colors, Colors, sizeof(LONG) * COLORS_MAX);
4113 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
4114 if (!WinSendMsg(hwndClient, UM_SETUP, MPVOID, MPVOID))
4115 hwndFrame = (HWND) 0;
4116 else {
4117 //DosSleep(32);
4118 if (!(FrameFlags & FCF_TASKLIST) && !(flags & 2)) {
4119 SWP swp;
4120
4121 FillClient(hwndParent, &swp, NULL, FALSE);
4122 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4123 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_RESTORE |
4124 SWP_ZORDER | SWP_ACTIVATE);
4125 }
4126 else if (FrameFlags & FCF_TASKLIST) {
4127
4128 SWP swp, swpD;
4129 ULONG size = sizeof(swp);
4130 LONG cxScreen, cyScreen;
4131
4132 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
4133 if (PrfQueryProfileData(fmprof,
4134 appname, "NewViewSizePos", &swpD, &size)) {
4135 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
4136 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
4137 if (swp.x + swpD.cx > cxScreen)
4138 swp.x = cxScreen - swpD.cx;
4139 if (swp.y + swpD.cy > cyScreen)
4140 swp.y = cyScreen - swpD.cy;
4141 swp.cx = swpD.cx;
4142 swp.cy = swpD.cy;
4143 }
4144 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4145 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
4146 SWP_ACTIVATE);
4147 }
4148 }
4149 }
4150 }
4151 return hwndFrame;
4152}
4153
4154#pragma alloc_text(NEWVIEW,ViewStatusProc,FreeViewerMem,LoadFileThread)
4155#pragma alloc_text(NEWVIEW,InitWindow,PaintLine,ViewWndProc)
4156#pragma alloc_text(NEWVIEW,ViewFrameWndProc,StartViewer,ReLineThread)
4157#pragma alloc_text(NEWVIEW,BuildAList,SearchThread,ClipboardThread,FindStrDlgProc)
4158#pragma alloc_text(NEWVIEW,BuildAList2,UrlDlgProc)
Note: See TracBrowser for help on using the repository browser.