source: trunk/dll/newview.c@ 1036

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

More fortify changes eliminated the leave scope wrapper except in mainwnd.c Wrapper only unlaods stuuff (archivers, commands, etc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 116.2 KB
Line 
1
2/***********************************************************************
3
4 $Id: newview.c 1036 2008-07-01 22:53:51Z 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 Fortify_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# ifdef FORTIFY
944 Fortify_EnterScope();
945# endif
946 WinCancelShutdown(hmq2, TRUE);
947 IncrThreadUsage();
948 ad = WinQueryWindowPtr(hwnd, QWL_USER);
949 if (ad) {
950 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
951 markwith = VF_FOUND | ((ad->alsoselect) ? VF_SELECTED : 0);
952 strcpy(s, ad->searchtext);
953 if (*s) {
954 WinQueryWindowRect(hwnd, &Rectl);
955 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
956 numlines = NumLines(&Rectl, ad);
957 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
958 NEWVIEW_STATUS1),
959 GetPString(IDS_SEARCHINGTEXT));
960 if (numlines && width && ad->markedlines && ad->numlines &&
961 ad->text && ad->textsize) {
962 for (x = 0; x < ad->numlines && !ad->stopflag; x++)
963 ad->markedlines[x] &= (~VF_FOUND);
964 ad->found = 0;
965 t = s;
966 while (t && !ad->stopflag) {
967 lastline = 1;
968 n = convert_nl_to_nul(t);
969 if (*t) {
970 strcpy(s2, t);
971 if (ad->literalsearch)
972 literal(s2);
973 p = ad->text;
974 while (p && !ad->stopflag) {
975 p = findstring(s2, strlen(s2), p,
976 ad->textsize - (p - ad->text),
977 ad->sensitive);
978 if (p) {
979 if (ad->hex) {
980 whichline = (p - ad->text) / 16;
981 if (whichline < firstline)
982 firstline = whichline;
983 if (!(ad->markedlines[whichline] & VF_FOUND))
984 ad->found++;
985 if (markwith & VF_SELECTED) {
986 if (!(ad->markedlines[whichline] & VF_SELECTED))
987 ad->selected++;
988 }
989 ad->markedlines[whichline] |= markwith;
990 if ((p - ad->text) + strlen(s2) >
991 (whichline + 1) * 16) {
992 whichline++;
993 if (!(ad->markedlines[whichline] & VF_FOUND))
994 ad->found++;
995 if (markwith & VF_SELECTED) {
996 if (!(ad->markedlines[whichline] & VF_SELECTED))
997 ad->selected++;
998 }
999 ad->markedlines[whichline] |= markwith;
1000 }
1001 p = ad->text + ((whichline + 1) * 16);
1002 if (p >= ad->text + ad->textsize)
1003 break;
1004 }
1005 else {
1006 for (x = lastline; x < ad->numlines; x++) {
1007 if (ad->lines[x] > p) {
1008 if (x - 1 < firstline)
1009 firstline = x - 1;
1010 if (!(ad->markedlines[x - 1] & VF_FOUND))
1011 ad->found++;
1012 if (markwith & VF_SELECTED) {
1013 if (!(ad->markedlines[x - 1] & VF_SELECTED))
1014 ad->selected++;
1015 }
1016 ad->markedlines[x - 1] |= markwith;
1017 if (x + 1 < ad->numlines &&
1018 p + strlen(s2) > ad->lines[x]) {
1019 x++;
1020 if (!(ad->markedlines[x - 1] & VF_FOUND))
1021 ad->found++;
1022 if (markwith & VF_SELECTED) {
1023 if (!(ad->markedlines[x - 1] & VF_SELECTED))
1024 ad->selected++;
1025 }
1026 ad->markedlines[x - 1] |= markwith;
1027 }
1028 lastline = x;
1029 p = ad->lines[x];
1030 break;
1031 }
1032 }
1033 if (x >= ad->numlines) {
1034 if (markwith & VF_SELECTED) {
1035 if (!
1036 (ad->markedlines[numlines - 1] & VF_SELECTED))
1037 ad->selected++;
1038 if (!(ad->markedlines[numlines - 1] & VF_FOUND))
1039 ad->found++;
1040 }
1041 ad->markedlines[ad->numlines - 1] |= markwith;
1042 break;
1043 }
1044 }
1045 }
1046 }
1047 }
1048 t = n;
1049 }
1050 }
1051 DosReleaseMutexSem(ad->ScanSem);
1052 if (!ad->stopflag && firstline == ULONG_MAX) {
1053 DosBeep(50, 50);
1054 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1055 NEWVIEW_STATUS1),
1056 GetPString(IDS_NOMATCHINGTEXT));
1057 DosSleep(150);//05 Aug 07 GKY 1500
1058 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1059 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1060 }
1061 else if (!ad->stopflag) {
1062 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1063 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1064 PostMsg(hwnd, UM_CONTAINER_FILLED,
1065 MPFROMLONG(firstline + 1), MPFROMLONG(firstline + 1));
1066 }
1067 }
1068 else
1069 DosReleaseMutexSem(ad->ScanSem);
1070 }
1071 }
1072 WinDestroyMsgQueue(hmq2);
1073# ifdef FORTIFY
1074 Fortify_LeaveScope(pszSrcFile, __LINE__);
1075# endif
1076 }
1077 DecrThreadUsage();
1078 WinTerminate(hab2);
1079 }
1080 DosPostEventSem(CompactSem);
1081}
1082
1083static VOID ClipboardThread(VOID * args)
1084{
1085 HWND hwnd = (HWND) args;
1086 HAB hab2;
1087 HMQ hmq2;
1088 VIEWDATA *ad;
1089 CHAR **list;
1090 USHORT cmd;
1091 register ULONG x;
1092 BOOL released = FALSE;
1093
1094 priority_normal();
1095 hab2 = WinInitialize(0);
1096 if (hab2) {
1097 hmq2 = WinCreateMsgQueue(hab2, 0);
1098 if (hmq2) {
1099 WinCancelShutdown(hmq2, TRUE);
1100 IncrThreadUsage();
1101# ifdef FORTIFY
1102 Fortify_EnterScope();
1103# endif
1104 ad = WinQueryWindowPtr(hwnd, QWL_USER);
1105 if (ad) {
1106 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
1107 cmd = ad->cliptype;
1108 if (ad->numlines && ad->text && ad->textsize && ad->markedlines &&
1109 !ad->stopflag) {
1110 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1111 NEWVIEW_STATUS1),
1112 GetPString(IDS_BUILDINGLINELISTTEXT));
1113 if (cmd == IDM_SAVETOCLIP || cmd == IDM_APPENDTOCLIP ||
1114 cmd == IDM_SAVETOLIST)
1115 list = BuildAList(hwnd);
1116 else
1117 list = BuildAList2(hwnd);
1118 if (list) {
1119 if (!ad->stopflag) {
1120 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1121 NEWVIEW_STATUS1),
1122 (cmd == IDM_SAVETOCLIP ||
1123 cmd == IDM_SAVETOCLIP2) ?
1124 GetPString(IDS_SAVETOCLIPTEXT) :
1125 (cmd == IDM_APPENDTOCLIP ||
1126 cmd == IDM_APPENDTOCLIP2) ?
1127 GetPString(IDS_APPENDTOCLIPTEXT) :
1128 GetPString(IDS_WRITETOFILETEXT));
1129 DosReleaseMutexSem(ad->ScanSem);
1130 released = TRUE;
1131 if (cmd == IDM_SAVETOCLIP || cmd == IDM_APPENDTOCLIP ||
1132 cmd == IDM_SAVETOCLIP2 || cmd == IDM_APPENDTOCLIP2)
1133 ListToClipboardHab(hab2, list, (cmd == IDM_APPENDTOCLIP ||
1134 cmd == IDM_APPENDTOCLIP2));
1135 else {
1136
1137 FILE *fp;
1138 CHAR filename[CCHMAXPATH];
1139
1140 *filename = 0;
1141 if (export_filename(hwnd, filename, FALSE)) {
1142 fp = _fsopen(filename, "a+", SH_DENYWR);
1143 if (!fp) {
1144 saymsg(MB_CANCEL,
1145 hwnd,
1146 GetPString(IDS_ERRORTEXT),
1147 GetPString(IDS_CANTOPENFORWRITETEXT), filename);
1148 }
1149 else {
1150 fseek(fp, 0L, SEEK_END);
1151 for (x = 0; list[x]; x++)
1152 fprintf(fp, "%s\n", list[x]);
1153 fclose(fp);
1154 }
1155 }
1156 }
1157 }
1158 FreeList(list);
1159 }
1160 else {
1161 DosReleaseMutexSem(ad->ScanSem);
1162 released = TRUE;
1163 DosBeep(50, 100);
1164 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1165 NEWVIEW_STATUS1),
1166 GetPString(IDS_NVNOLINESSELTEXT));
1167 DosSleep(150);//05 Aug 07 GKY 1500
1168 }
1169 }
1170 if (!released)
1171 DosReleaseMutexSem(ad->ScanSem);
1172 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1173 }
1174 }
1175 WinDestroyMsgQueue(hmq2);
1176 }
1177# ifdef FORTIFY
1178 Fortify_LeaveScope();
1179# endif
1180 DecrThreadUsage();
1181 WinTerminate(hab2);
1182 }
1183 DosPostEventSem(CompactSem);
1184}
1185
1186static VOID ReLineThread(VOID * args)
1187{
1188 HWND hwnd = (HWND) args;
1189 HAB hab2;
1190 HMQ hmq2;
1191 VIEWDATA *ad;
1192 CHAR *p, *pp, *e, *whereiam = NULL;
1193 RECTL Rectl;
1194 ULONG width, numlines, firstline = 1, cursored = 1;
1195
1196 priority_normal();
1197 hab2 = WinInitialize(0);
1198 if (hab2) {
1199 hmq2 = WinCreateMsgQueue(hab2, 0);
1200 if (hmq2) {
1201 WinCancelShutdown(hmq2, TRUE);
1202 IncrThreadUsage();
1203# ifdef FORTIFY
1204 Fortify_EnterScope();
1205# endif
1206 ad = WinQueryWindowPtr(hwnd, QWL_USER);
1207 if (!ad)
1208 Runtime_Error(pszSrcFile, __LINE__, "no data");
1209 else {
1210 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
1211 ad->relining = TRUE;
1212 ad->busy++;
1213 ad->maxx = 0;
1214 if (ad->text && ad->textsize) {
1215 if (ad->hex) {
1216 firstline = ad->topline;
1217 cursored = ad->cursored;
1218 }
1219 else if (ad->lines)
1220 whereiam = ad->lines[ad->cursored - 1];
1221 ad->found = 0;
1222 ad->selected = ad->numlines = ad->numalloc = 0;
1223 xfree(ad->lines, pszSrcFile, __LINE__);
1224 xfree(ad->markedlines, pszSrcFile, __LINE__);
1225 ad->lines = NULL;
1226 ad->markedlines = NULL;
1227 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1228 NEWVIEW_STATUS1),
1229 GetPString(IDS_FORMATTINGTEXT));
1230 if (!ad->hex) {
1231 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
1232 LM_QUERYITEMCOUNT, MPVOID, MPVOID)) {
1233 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
1234 LM_DELETEALL, MPVOID, MPVOID);
1235 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
1236 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
1237 }
1238 }
1239 WinSetFocus(HWND_DESKTOP, hwnd);
1240 if (!ad->hex) {
1241 WinQueryWindowRect(hwnd, &Rectl);
1242 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
1243 numlines = NumLines(&Rectl, ad);
1244 ad->oldwidth = width;
1245 p = ad->text;
1246 if (width) {
1247 while (p - ad->text < ad->textsize && !ad->stopflag) {
1248 if (ad->wrapon) {
1249 e = p + (width - 1);
1250 if (e - ad->text > ad->textsize)
1251 e = ad->text + ad->textsize;
1252 pp = p;
1253 while (pp < e) {
1254 if (*pp == '\r' || *pp == '\n') {
1255 e = pp;
1256 break;
1257 }
1258 pp++;
1259 }
1260 }
1261 else {
1262 pp = p;
1263 while (pp - ad->text < ad->textsize &&
1264 *pp != '\r' && *pp != '\n')
1265 pp++;
1266 e = pp;
1267 if (ad->maxx <
1268 (((e - p) + 1) * ad->fattrs.lAveCharWidth) + 1)
1269 ad->maxx = (((e - p) + 1) *
1270 ad->fattrs.lAveCharWidth) + 1;
1271 }
1272 if (whereiam && p >= whereiam && e <= whereiam) {
1273 cursored = firstline = ad->numlines + 1;
1274 whereiam = NULL;
1275 }
1276 /* assign ad->lines[ad->numlines] */
1277 if (ad->numlines + 1 > ad->numalloc) {
1278
1279 CHAR **temp;
1280
1281 temp = xrealloc(ad->lines, sizeof(CHAR *) *
1282 (ad->numalloc + 256), pszSrcFile,
1283 __LINE__);
1284 if (!temp)
1285 break;
1286 ad->lines = temp;
1287 ad->numalloc += 256;
1288 }
1289 ad->lines[ad->numlines] = p;
1290 ad->numlines++;
1291 if (ad->numlines == numlines) {
1292 /* display first page */
1293 register INT x;
1294
1295 for (x = 0; x < ad->numlines; x++) {
1296 if ((LONG) (Rectl.yTop -
1297 (ad->lMaxHeight * (((x + 1) -
1298 ad->topline) + 1))) < 0)
1299 break;
1300 PaintLine(hwnd, ad->hps, x, 1, &Rectl);
1301 }
1302 }
1303 p = e;
1304 if (p - ad->text < ad->textsize) {
1305 if (*p == '\r')
1306 p++;
1307 }
1308 if (p - ad->text < ad->textsize) {
1309 if (*p == '\n')
1310 p++;
1311 }
1312 }
1313 }
1314 if (ad->numalloc != ad->numlines) {
1315
1316 CHAR **temp;
1317
1318 temp =
1319 xrealloc(ad->lines, sizeof(CHAR *) * ad->numlines,
1320 pszSrcFile, __LINE__);
1321 if (temp) {
1322 ad->lines = temp;
1323 ad->numalloc = ad->numlines;
1324 }
1325 }
1326 }
1327 else {
1328 ad->numlines = ad->textsize / 16;
1329 if (ad->numlines * 16 < ad->textsize)
1330 ad->numlines++;
1331 }
1332 if (ad->numlines) {
1333 ad->markedlines = xmallocz(ad->numlines, pszSrcFile, __LINE__);
1334 if (ad->markedlines) {
1335 ad->selected = 0;
1336 }
1337 if ((*ftprun || fFtpRunWPSDefault) && !ad->ignoreftp &&
1338 strstr(ad->text, "ftp://"))
1339 ad->ftpin = TRUE;
1340 if ((*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
1341 strstr(ad->text, "http://"))
1342 ad->httpin = TRUE;
1343 if (*mailrun && !ad->ignoremail && strstr(ad->text, "@"))
1344 ad->mailin = TRUE;
1345 }
1346 }
1347 DosReleaseMutexSem(ad->ScanSem);
1348 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1349 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1350 ad->busy--;
1351 } // if got sim
1352 } // if got VIEWDATA
1353 WinDestroyMsgQueue(hmq2);
1354 }
1355 DecrThreadUsage();
1356 WinTerminate(hab2);
1357# ifdef FORTIFY
1358 Fortify_LeaveScope(pszSrcFile, __LINE__);
1359# endif
1360 }
1361 DosPostEventSem(CompactSem);
1362 if (ad && !ad->stopflag) {
1363 PostMsg(hwnd, UM_CONTAINER_FILLED, MPFROMLONG(firstline),
1364 MPFROMLONG(cursored));
1365 ad->relining = FALSE;
1366 }
1367}
1368
1369static VOID LoadFileThread(VOID * args)
1370{
1371 HWND hwnd = (HWND) args;
1372 HAB hab2;
1373 HMQ hmq2;
1374 VIEWDATA *ad;
1375 HFILE handle;
1376 ULONG action;
1377 ULONG len;
1378 APIRET rc;
1379 BOOL error = TRUE;
1380
1381 hab2 = WinInitialize(0);
1382 if (hab2) {
1383 hmq2 = WinCreateMsgQueue(hab2, 0);
1384 if (hmq2) {
1385 WinCancelShutdown(hmq2, TRUE);
1386 IncrThreadUsage();
1387# ifdef FORTIFY
1388 Fortify_EnterScope();
1389# endif
1390 ad = WinQueryWindowPtr(hwnd, QWL_USER);
1391 if (ad) {
1392 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
1393 ad->busy++;
1394 priority_normal();
1395 if (*ad->filename) {
1396 xfree(ad->text, pszSrcFile, __LINE__);
1397 xfree(ad->lines, pszSrcFile, __LINE__);
1398 xfree(ad->markedlines, pszSrcFile, __LINE__);
1399 ad->text = NULL;
1400 ad->lines = NULL;
1401 ad->markedlines = NULL;
1402 ad->ftpin = ad->httpin = ad->mailin = FALSE;
1403 ad->selected = ad->numlines = ad->textsize = ad->numalloc = 0;
1404 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
1405 MPVOID, MPVOID);
1406 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
1407 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
1408 WinSetFocus(HWND_DESKTOP, hwnd);
1409 rc = DosOpen(ad->filename, &handle, &action, 0, 0,
1410 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
1411 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
1412 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
1413 OPEN_ACCESS_READONLY, 0);
1414 if (rc) {
1415 Dos_Error(MB_CANCEL,
1416 rc,
1417 hwnd,
1418 pszSrcFile,
1419 __LINE__,
1420 GetPString(IDS_COMPCANTOPENTEXT), ad->filename);
1421 }
1422 else {
1423 DosChgFilePtr(handle, 0, FILE_END, &len);
1424 DosChgFilePtr(handle, 0, FILE_BEGIN, &action);
1425 if (!len) {
1426 saymsg(MB_CANCEL,
1427 hwnd,
1428 GetPString(IDS_ERRORTEXT),
1429 GetPString(IDS_ZEROLENGTHTEXT), ad->filename);
1430 }
1431 else {
1432 // 06 Oct 07 SHL Protect against 4096 NFTS driver small buffer defect
1433 ad->text = xmalloc(max(len + 2, 4096), // 05 Nov 07 SHL
1434 pszSrcFile,
1435 __LINE__);
1436 if (ad->text) {
1437 *ad->text = 0;
1438 ad->text[len] = 0;
1439 rc = DosRead(handle, ad->text, len, &ad->textsize);
1440 if (rc) {
1441 Dos_Error(MB_CANCEL,
1442 rc,
1443 hwnd,
1444 pszSrcFile,
1445 __LINE__,
1446 GetPString(IDS_ERRORREADINGTEXT), ad->filename);
1447 xfree(ad->text, pszSrcFile, __LINE__);
1448 ad->text = NULL;
1449 ad->textsize = 0;
1450 }
1451 else {
1452 ad->text[ad->textsize] = 0;
1453 if (!ad->hex && !(ad->flags & (8 | 16)) && ad->textsize) {
1454 ULONG x;
1455
1456 x = min(512, ad->textsize);
1457 if (fGuessType && IsBinary(ad->text, x))
1458 ad->hex = TRUE;
1459 }
1460 if (ad->textsize) {
1461 if (_beginthread
1462 (ReLineThread, NULL, 524288, (PVOID) hwnd) == -1)
1463 Runtime_Error(pszSrcFile, __LINE__,
1464 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1465 else
1466 error = FALSE;
1467 }
1468 }
1469 }
1470 }
1471 DosClose(handle);
1472 }
1473 }
1474 ad->busy--;
1475 DosReleaseMutexSem(ad->ScanSem);
1476 }
1477 }
1478 WinDestroyMsgQueue(hmq2);
1479 }
1480 DecrThreadUsage();
1481 WinTerminate(hab2);
1482# ifdef FORTIFY
1483 Fortify_LeaveScope(pszSrcFile, __LINE__);
1484# endif
1485 }
1486 if (error)
1487 PostMsg(hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
1488 DosPostEventSem(CompactSem);
1489}
1490
1491MRESULT EXPENTRY ViewFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
1492 MPARAM mp2)
1493{
1494 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
1495
1496 switch (msg) {
1497 case WM_CHAR:
1498 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
1499 break;
1500
1501 case WM_CONTROL:
1502 switch (SHORT1FROMMP(mp1)) {
1503 case NEWVIEW_LISTBOX:
1504 return WinSendMsg(WinWindowFromID(hwnd, FID_CLIENT), UM_CONTROL,
1505 mp1, mp2);
1506 }
1507 break;
1508
1509 case WM_CALCFRAMERECT:
1510 {
1511 MRESULT mr;
1512 PRECTL prectl;
1513 SHORT sSelect;
1514
1515 mr = oldproc(hwnd, msg, mp1, mp2);
1516
1517 /*
1518 * Calculate the position of the client rectangle.
1519 * Otherwise, we'll see a lot of redraw when we move the
1520 * client during WM_FORMATFRAME.
1521 */
1522
1523 if (mr && mp2) {
1524 prectl = (PRECTL) mp1;
1525 prectl->yBottom += 22;
1526 prectl->yTop -= 22;
1527 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, NEWVIEW_LISTBOX,
1528 LM_QUERYITEMCOUNT,
1529 MPVOID, MPVOID);
1530 if (sSelect > 0)
1531 prectl->yTop -= 48;
1532 }
1533 return mr;
1534 }
1535
1536 case WM_FORMATFRAME:
1537 {
1538 SHORT sCount, soldCount, sSelect;
1539 PSWP pswp, pswpClient, pswpNew1, pswpNew2, pswpNew3, pswpList,
1540 pswpScroll, pswpNew4, pswpUp, pswpDn;
1541
1542 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
1543 soldCount = sCount;
1544
1545 /*
1546 * Reformat the frame to "squeeze" the client
1547 * and make room for status window sibling beneath
1548 */
1549
1550 pswp = (PSWP) mp1;
1551 {
1552 SHORT x;
1553
1554 for (x = 0; x < sCount; x++) {
1555 if (WinQueryWindowUShort(pswp->hwnd, QWS_ID) == FID_CLIENT) {
1556 pswpClient = pswp;
1557 break;
1558 }
1559 pswp++;
1560 }
1561 }
1562 pswpNew1 = (PSWP) mp1 + soldCount;
1563 pswpNew2 = (PSWP) mp1 + (soldCount + 1);
1564 pswpNew3 = (PSWP) mp1 + (soldCount + 2);
1565 pswpNew4 = (PSWP) mp1 + (soldCount + 3);
1566 *pswpNew1 = *pswpClient;
1567 pswpNew1->hwnd = WinWindowFromID(hwnd, NEWVIEW_STATUS1);
1568 pswpNew1->x = pswpClient->x + 2;
1569 pswpNew1->y = pswpClient->y + 2;
1570 pswpNew1->cx = (pswpClient->cx / 3) - 3;
1571 pswpNew1->cy = 20;
1572 pswpClient->y = pswpNew1->y + pswpNew1->cy + 3;
1573 pswpClient->cy = (pswpClient->cy - pswpNew1->cy) - 5;
1574 *pswpNew2 = *pswpNew1;
1575 *pswpNew3 = *pswpNew1;
1576 *pswpNew4 = *pswpNew1;
1577 pswpNew2->hwnd = WinWindowFromID(hwnd, NEWVIEW_STATUS2);
1578 pswpNew3->hwnd = WinWindowFromID(hwnd, NEWVIEW_STATUS3);
1579 pswpNew4->hwnd = WinWindowFromID(hwnd, NEWVIEW_DRAG);
1580 pswpNew2->x = pswpNew1->x + pswpNew1->cx + 3;
1581 pswpNew3->x = pswpNew2->x + pswpNew2->cx + 3;
1582 pswpNew3->cx = ((pswpClient->x + pswpClient->cx) - pswpNew3->x) - 26;
1583 pswpNew4->x = pswpNew3->x + pswpNew3->cx + 3;
1584 pswpNew4->cx = 20;
1585 sCount += 4;
1586 pswpScroll = (PSWP) mp1;
1587 while (pswpScroll < pswpClient) {
1588 if (WinQueryWindowUShort(pswpScroll->hwnd, QWS_ID) == FID_VERTSCROLL)
1589 break;
1590 pswpScroll++;
1591 }
1592 if (pswpScroll == pswpClient)
1593 pswpScroll = NULL;
1594 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, NEWVIEW_LISTBOX,
1595 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
1596 if (sSelect > 0) {
1597 pswpList = (PSWP) mp1 + (soldCount + 4);
1598 *pswpList = *pswpClient;
1599 pswpList->hwnd = WinWindowFromID(hwnd, NEWVIEW_LISTBOX);
1600 pswpList->x = pswpClient->x;
1601 pswpList->cx = pswpClient->cx;
1602 if (pswpScroll) {
1603 pswpList->cx += pswpScroll->cx;
1604 pswpScroll->cy -= 48;
1605 }
1606 pswpList->y = (pswpClient->y + pswpClient->cy) - 48;
1607 pswpList->cy = 48;
1608 pswpClient->cy -= 48;
1609 sCount++;
1610 }
1611 WinShowWindow(WinWindowFromID(hwnd, NEWVIEW_LISTBOX), (sSelect > 0));
1612
1613 if (pswpScroll) {
1614 pswpUp = (PSWP) mp1 + (soldCount + 4 + (sSelect > 0));
1615 *pswpUp = *pswpClient;
1616 pswpUp->hwnd = WinWindowFromID(hwnd, IDM_PREVBLANKLINE);
1617 pswpUp->cx = pswpScroll->cx;
1618 pswpUp->x = pswpScroll->x;
1619 pswpUp->cy = WinQuerySysValue(HWND_DESKTOP, SV_CYVSCROLLARROW);
1620 pswpUp->y = (pswpScroll->y + pswpScroll->cy) - (pswpUp->cy + 1);
1621 pswpScroll->cy -= ((pswpUp->cy * 2) + 1);
1622 pswpDn = (PSWP) mp1 + (soldCount + 5 + (sSelect > 0));
1623 *pswpDn = *pswpUp;
1624 pswpDn->y = pswpScroll->y;
1625 pswpDn->hwnd = WinWindowFromID(hwnd, IDM_NEXTBLANKLINE);
1626 pswpScroll->y += pswpUp->cy;
1627 sCount += 2;
1628 }
1629 else {
1630 WinShowWindow(WinWindowFromID(hwnd, IDM_PREVBLANKLINE), FALSE);
1631 WinShowWindow(WinWindowFromID(hwnd, IDM_NEXTBLANKLINE), FALSE);
1632 }
1633 return MRFROMSHORT(sCount);
1634 }
1635
1636 case WM_QUERYFRAMECTLCOUNT:
1637 {
1638 SHORT sCount, sSelect;
1639
1640 sCount = (SHORT) oldproc(hwnd, msg, mp1, mp2);
1641 sCount += 6;
1642 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, NEWVIEW_LISTBOX,
1643 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
1644 if (sSelect > 0)
1645 sCount++;
1646 return MRFROMSHORT(sCount);
1647 }
1648 }
1649 return oldproc(hwnd, msg, mp1, mp2);
1650}
1651
1652MRESULT EXPENTRY FindStrDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1653{
1654 VIEWDATA *ad;
1655
1656 switch (msg) {
1657 case WM_INITDLG:
1658 if (!mp2)
1659 WinDismissDlg(hwnd, 0);
1660 else {
1661
1662 HWND hwndClient = *(HWND *) mp2;
1663
1664 WinSetWindowULong(hwnd, QWL_USER, (ULONG) hwndClient);
1665 ad = (VIEWDATA *) WinQueryWindowPtr(hwndClient, QWL_USER);
1666 MLEsetwrap(WinWindowFromID(hwnd, NEWFIND_MLE), FALSE);
1667 MLEsetlimit(WinWindowFromID(hwnd, NEWFIND_MLE), SEARCHSTRINGLEN);
1668 MLEsetformat(WinWindowFromID(hwnd, NEWFIND_MLE), MLFIE_NOTRANS);
1669 if (*ad->searchtext) {
1670
1671 IPT here = 0;
1672 ULONG len = strlen(ad->searchtext);
1673
1674 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1675 MLM_SETIMPORTEXPORT,
1676 MPFROMP(ad->searchtext), MPFROMLONG(SEARCHSTRINGLEN));
1677 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1678 MLM_IMPORT, MPFROMP(&here), MPFROMLONG(len));
1679 }
1680 WinCheckButton(hwnd, NEWFIND_ALSOSELECT, ad->alsoselect);
1681 WinCheckButton(hwnd, NEWFIND_SENSITIVE, ad->sensitive);
1682 WinCheckButton(hwnd, NEWFIND_LITERAL, ad->literalsearch);
1683 }
1684 break;
1685
1686 case WM_COMMAND:
1687 switch (SHORT1FROMMP(mp1)) {
1688 case DID_OK:
1689 {
1690 CHAR s[SEARCHSTRINGLEN];
1691 IPT here = 0;
1692 ULONG len;
1693 HWND hwndClient = WinQueryWindowULong(hwnd, QWL_USER);
1694
1695 ad = (VIEWDATA *) WinQueryWindowPtr(hwndClient, QWL_USER);
1696 memset(s, 0, SEARCHSTRINGLEN);
1697 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1698 MLM_SETIMPORTEXPORT,
1699 MPFROMP(s), MPFROMLONG(SEARCHSTRINGLEN));
1700 len = SEARCHSTRINGLEN;
1701 WinSendMsg(WinWindowFromID(hwnd, NEWFIND_MLE),
1702 MLM_EXPORT, MPFROMP(&here), MPFROMLONG(&len));
1703 s[SEARCHSTRINGLEN - 1] = 0;
1704 if (!*s) {
1705 DosBeep(250, 100); // Complain
1706 break;
1707 }
1708 strcpy(ad->searchtext, s);
1709 ad->sensitive = WinQueryButtonCheckstate(hwnd, NEWFIND_SENSITIVE);
1710 if (ad->sensitive != Sensitive) {
1711 Sensitive = ad->sensitive;
1712 PrfWriteProfileData(fmprof,
1713 appname,
1714 "Viewer.Sensitive",
1715 &ad->sensitive, sizeof(BOOL));
1716 }
1717 ad->literalsearch = WinQueryButtonCheckstate(hwnd, NEWFIND_LITERAL);
1718 if (ad->literalsearch != LiteralSearch) {
1719 LiteralSearch = ad->literalsearch;
1720 PrfWriteProfileData(fmprof,
1721 appname,
1722 "Viewer.LiteralSearch",
1723 &ad->literalsearch, sizeof(BOOL));
1724 }
1725 ad->alsoselect = WinQueryButtonCheckstate(hwnd, NEWFIND_ALSOSELECT);
1726 if (ad->alsoselect != AlsoSelect) {
1727 AlsoSelect = ad->alsoselect;
1728 PrfWriteProfileData(fmprof,
1729 appname,
1730 "Viewer.AlsoSelect",
1731 &ad->alsoselect, sizeof(BOOL));
1732 }
1733 }
1734 WinDismissDlg(hwnd, 1);
1735 break;
1736 case DID_CANCEL:
1737 WinDismissDlg(hwnd, 0);
1738 break;
1739 }
1740 return 0;
1741 }
1742 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1743}
1744
1745MRESULT EXPENTRY ViewWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1746{
1747 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
1748
1749 switch (msg) {
1750 case WM_CREATE:
1751 {
1752 HWND temphwnd;
1753 HWND hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
1754
1755 temphwnd = WinCreateWindow(hwndFrame,
1756 WC_BUTTON,
1757 "<",
1758 WS_VISIBLE |
1759 BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
1760 0,
1761 0,
1762 0,
1763 0,
1764 hwndFrame,
1765 HWND_TOP, IDM_PREVBLANKLINE, NULL, NULL);
1766 if (!temphwnd)
1767 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1768 IDS_WINCREATEWINDOW);
1769 else {
1770 WinSetPresParam(temphwnd,
1771 PP_FONTNAMESIZE,
1772 strlen(GetPString(IDS_8HELVTEXT)) + 1,
1773 (PVOID) GetPString(IDS_8HELVTEXT));
1774 }
1775 temphwnd = WinCreateWindow(hwndFrame,
1776 WC_BUTTON,
1777 ">",
1778 WS_VISIBLE |
1779 BS_PUSHBUTTON | BS_NOPOINTERFOCUS,
1780 0,
1781 0,
1782 0,
1783 0,
1784 hwndFrame,
1785 HWND_TOP, IDM_NEXTBLANKLINE, NULL, NULL);
1786 if (!temphwnd)
1787 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1788 IDS_WINCREATEWINDOW);
1789 else {
1790 WinSetPresParam(temphwnd,
1791 PP_FONTNAMESIZE,
1792 strlen(GetPString(IDS_8HELVTEXT)) + 1,
1793 (PVOID) GetPString(IDS_8HELVTEXT));
1794 }
1795 WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER5, 1000L);
1796 }
1797 break;
1798
1799 case WM_TIMER:
1800 if (ad &&
1801 ad->needrefreshing &&
1802 !ad->stopflag &&
1803 !ad->relining &&
1804 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
1805 ad->needrefreshing = FALSE;
1806 DosReleaseMutexSem(ad->ScanSem);
1807 WinInvalidateRect(hwnd, NULL, TRUE);
1808 }
1809 break;
1810
1811 case UM_SETUP:
1812 if (!ad)
1813 Runtime_Error(pszSrcFile, __LINE__, "no data");
1814 else {
1815 CHAR s[CCHMAXPATH + 8];
1816 APIRET rc;
1817
1818 ad->hwndMenu = WinWindowFromID(ad->hwndFrame, FID_MENU);
1819 ad->hvscroll = WinWindowFromID(ad->hwndFrame, FID_VERTSCROLL);
1820 ad->hhscroll = WinWindowFromID(ad->hwndFrame, FID_HORZSCROLL);
1821 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(1, 1), MPVOID);
1822 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(1, 1), MPVOID);
1823 sprintf(s, "%s: %s", FM2Str, ad->filename);
1824 WinSetWindowText(ad->hwndFrame, s);
1825 rc = DosCreateMutexSem(NULL, &ad->ScanSem, 0L, FALSE);
1826 if (rc)
1827 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
1828 "DosCreateMutexSem");
1829 else {
1830 PFNWP oldproc;
1831 HWND hwndFrame = ad->hwndFrame;
1832
1833 WinSendMsg(ad->hvscroll,
1834 SBM_SETSCROLLBAR, MPFROMSHORT(1), MPFROM2SHORT(1, 1));
1835 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR, MPFROMSHORT(1),
1836 MPFROM2SHORT(1, 1));
1837 ad->hwndStatus1 = WinCreateWindow(hwndFrame,
1838 WC_VIEWSTATUS,
1839 GetPString(IDS_LOADINGTEXT),
1840 WS_VISIBLE | SS_TEXT |
1841 DT_LEFT | DT_VCENTER,
1842 0,
1843 0,
1844 0,
1845 0,
1846 hwndFrame,
1847 HWND_TOP,
1848 NEWVIEW_STATUS1, NULL, NULL);
1849 if (!ad->hwndStatus1)
1850 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1851 IDS_WINCREATEWINDOW);
1852
1853 ad->hwndStatus2 = WinCreateWindow(hwndFrame,
1854 WC_VIEWSTATUS,
1855 NULL,
1856 WS_VISIBLE | SS_TEXT |
1857 DT_LEFT | DT_VCENTER,
1858 0,
1859 0,
1860 0,
1861 0,
1862 hwndFrame,
1863 HWND_TOP,
1864 NEWVIEW_STATUS2, NULL, NULL);
1865 if (!ad->hwndStatus2)
1866 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1867 IDS_WINCREATEWINDOW);
1868
1869 ad->hwndStatus3 = WinCreateWindow(hwndFrame,
1870 WC_VIEWSTATUS,
1871 NULL,
1872 WS_VISIBLE | SS_TEXT |
1873 DT_LEFT | DT_VCENTER,
1874 0,
1875 0,
1876 0,
1877 0,
1878 hwndFrame,
1879 HWND_TOP,
1880 NEWVIEW_STATUS3, NULL, NULL);
1881 if (!ad->hwndStatus3)
1882 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1883 IDS_WINCREATEWINDOW);
1884
1885 ad->hwndListbox = WinCreateWindow(hwndFrame,
1886 WC_LISTBOX,
1887 NULL,
1888 LS_NOADJUSTPOS,
1889 0,
1890 0,
1891 0,
1892 0,
1893 hwndFrame,
1894 HWND_TOP,
1895 NEWVIEW_LISTBOX, NULL, NULL);
1896 if (!ad->hwndListbox)
1897 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1898 IDS_WINCREATEWINDOW);
1899
1900 ad->hwndDrag = WinCreateWindow(hwndFrame,
1901 WC_VIEWSTATUS,
1902 "#100",
1903 WS_VISIBLE | SS_BITMAP,
1904 0,
1905 0,
1906 0,
1907 0,
1908 hwndFrame,
1909 HWND_TOP, NEWVIEW_DRAG, NULL, NULL);
1910 if (!ad->hwndDrag)
1911 Win_Error2(hwndFrame, hwnd, pszSrcFile, __LINE__,
1912 IDS_WINCREATEWINDOW);
1913
1914 oldproc = WinSubclassWindow(hwndFrame, ViewFrameWndProc);
1915 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
1916 ad->hps = InitWindow(hwnd);
1917 if (_beginthread(LoadFileThread, NULL, 524288, (PVOID) hwnd) == -1)
1918 Runtime_Error(pszSrcFile, __LINE__,
1919 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1920 else {
1921 WinSendMsg(hwnd, UM_SETUP5, MPVOID, MPVOID);
1922 DosSleep(16); //05 Aug 07 GKY 32
1923 return (MRESULT) 1;
1924 }
1925 }
1926 }
1927 // Oops
1928 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
1929 return 0;
1930
1931 case UM_SETUP5:
1932 if (ad) {
1933 if (ad->hwndFrame ==
1934 WinQueryActiveWindow(WinQueryWindow(ad->hwndFrame,
1935 QW_PARENT)) &&
1936 !ParentIsDesktop(ad->hwndFrame, (HWND) 0)) {
1937 if (hwndStatus2)
1938 WinSetWindowText(hwndStatus2,
1939 (*ad->filename) ?
1940 ad->filename : GetPString(IDS_UNTITLEDTEXT));
1941 if (fMoreButtons) {
1942 WinSetWindowText(hwndName,
1943 (*ad->filename) ?
1944 ad->filename : GetPString(IDS_UNTITLEDTEXT));
1945 WinSetWindowText(hwndDate, NullStr);
1946 WinSetWindowText(hwndAttr, NullStr);
1947 }
1948 if (hwndStatus)
1949 WinSetWindowText(hwndStatus,
1950 GetPString(IDS_INTERNALVIEWERTITLETEXT));
1951 }
1952 }
1953 return 0;
1954
1955 case DM_DISCARDOBJECT:
1956 case DM_PRINTOBJECT:
1957 return MRFROMLONG(DRR_TARGET);
1958
1959 case UM_RESCAN:
1960 if (ad) {
1961 if (!ad->busy && !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
1962 if (ad->numlines) {
1963
1964 CHAR s[80], tb[34], tl[34];
1965
1966 commafmt(tb, sizeof(tb), ad->textsize);
1967 commafmt(tl, sizeof(tl), ad->numlines);
1968 sprintf(s,
1969 " %s %s%s %s %s%s",
1970 tb,
1971 GetPString(IDS_BYTETEXT),
1972 &"s"[ad->textsize == 1],
1973 tl, GetPString(IDS_LINETEXT), &"s"[ad->numlines == 1]);
1974 WinSetWindowText(ad->hwndStatus1, s);
1975 }
1976 else
1977 WinSetWindowText(ad->hwndStatus1, GetPString(IDS_NVNOLINESTEXT));
1978 DosReleaseMutexSem(ad->ScanSem);
1979 }
1980 else
1981 WinSetWindowText(ad->hwndStatus1, GetPString(IDS_WORKINGTEXT));
1982 }
1983 return 0;
1984
1985 case UM_SETUP2:
1986 /**
1987 * calculate width of client in characters, recalc lines if
1988 * oldwidth != newwidth, set ad->oldwidth for later comparison
1989 */
1990 if (ad) {
1991
1992 BOOL invalidate = FALSE;
1993
1994 if (ad->wrapon || ad->hex) { // GKY reverse case where hscroll bar is presnt
1995 if (WinQueryWindow(ad->hhscroll, QW_PARENT) == ad->hwndFrame) {
1996 invalidate = TRUE;
1997 WinSetOwner(ad->hhscroll, HWND_OBJECT);
1998 WinSetParent(ad->hhscroll, HWND_OBJECT, TRUE);
1999 ad->maxx = 0;
2000 ad->horzscroll = 0;
2001 }
2002 }
2003 else {
2004 if (WinQueryWindow(ad->hhscroll, QW_PARENT) != ad->hwndFrame) {
2005 invalidate = TRUE;
2006 WinSetOwner(ad->hhscroll, ad->hwndFrame);
2007 WinSetParent(ad->hhscroll, ad->hwndFrame, TRUE);
2008 }
2009 }
2010 if (invalidate) {
2011 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER),
2012 MPVOID);
2013 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2014 NEWVIEW_DRAG), NULL, FALSE);
2015 WinInvalidateRect(ad->hhscroll, NULL, FALSE);
2016 }
2017 }
2018
2019 if (ad && !ad->busy &&
2020 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2021
2022 RECTL rcl;
2023 ULONG newwidth;
2024
2025 WinQueryWindowRect(hwnd, &rcl);
2026 newwidth = (rcl.xRight - rcl.xLeft) / ad->fattrs.lAveCharWidth;
2027 if ((!ad->hex || ad->oldwidth == -1) &&
2028 newwidth != ad->oldwidth && ad->text && ad->textsize) {
2029 ad->oldwidth = newwidth;
2030 if (!ad->relining) {
2031 if (_beginthread(ReLineThread, NULL, 524288, (PVOID) hwnd) == -1) {
2032 Runtime_Error(pszSrcFile, __LINE__,
2033 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2034 DosReleaseMutexSem(ad->ScanSem);
2035 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
2036 return 0;
2037 }
2038 }
2039 }
2040 ad->oldwidth = newwidth;
2041 DosReleaseMutexSem(ad->ScanSem);
2042 }
2043 return MRFROMLONG(TRUE);
2044
2045 case WM_CHAR:
2046 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
2047 if (ad && !ad->busy && !(SHORT1FROMMP(mp1) & KC_KEYUP) &&
2048 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2049
2050 ULONG numlines, wascursored = ad->cursored;
2051 RECTL rcl;
2052
2053 WinQueryWindowRect(hwnd, &rcl);
2054 numlines = NumLines(&rcl, ad);
2055 if (numlines) {
2056 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
2057 switch (SHORT2FROMMP(mp2)) {
2058 case VK_LEFT:
2059 WinSendMsg(hwnd, WM_HSCROLL, MPFROM2SHORT(FID_HORZSCROLL, 0),
2060 MPFROM2SHORT(0, SB_LINELEFT));
2061 break;
2062 case VK_RIGHT:
2063 WinSendMsg(hwnd, WM_HSCROLL, MPFROM2SHORT(FID_HORZSCROLL, 0),
2064 MPFROM2SHORT(0, SB_LINERIGHT));
2065 break;
2066 case VK_PAGEUP:
2067 PostMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2068 MPFROM2SHORT(0, SB_PAGEUP));
2069 break;
2070 case VK_PAGEDOWN:
2071 PostMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2072 MPFROM2SHORT(0, SB_PAGEDOWN));
2073 break;
2074 case VK_UP:
2075 if (ad->cursored > 1) {
2076 if (shiftstate & KC_SHIFT)
2077 WinSendMsg(hwnd, WM_BUTTON1CLICK,
2078 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2079 ((rcl.yTop - (ad->lMaxHeight *
2080 ((ad->cursored) -
2081 ad->topline))) -
2082 ad->lMaxDescender) - 1),
2083 MPFROM2SHORT(TRUE, 0));
2084 ad->cursored--;
2085 if (ad->cursored < ad->topline) {
2086 PaintLine(hwnd, ad->hps, ad->cursored, ad->topline, &rcl);
2087 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2088 MPFROM2SHORT(0, SB_LINEUP));
2089 }
2090 else {
2091 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2092 PaintLine(hwnd, ad->hps, ad->cursored, ad->topline, &rcl);
2093 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2094 }
2095 }
2096 break;
2097 case VK_DOWN:
2098 if (ad->cursored < ad->numlines &&
2099 ad->cursored < ad->topline + numlines) {
2100 if (shiftstate & KC_SHIFT)
2101 WinSendMsg(hwnd, WM_BUTTON1CLICK,
2102 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2103 ((rcl.yTop - (ad->lMaxHeight *
2104 ((ad->cursored) -
2105 ad->topline))) -
2106 ad->lMaxDescender) - 1),
2107 MPFROM2SHORT(TRUE, 0));
2108 ad->cursored++;
2109 if (ad->cursored >= ad->topline + numlines) {
2110 PaintLine(hwnd, ad->hps, ad->cursored - 2, ad->topline, &rcl);
2111 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2112 MPFROM2SHORT(0, SB_LINEDOWN));
2113 }
2114 else {
2115 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2116 PaintLine(hwnd, ad->hps, ad->cursored - 2, ad->topline, &rcl);
2117 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2118 }
2119 }
2120 break;
2121 case VK_END:
2122 if ((shiftstate & KC_CTRL) ||
2123 ad->cursored == (ad->topline - 1) + numlines) {
2124 ad->cursored = ad->numlines;
2125 ad->topline = (ad->numlines + 1) - numlines;
2126 if (ad->topline > ad->numlines)
2127 ad->topline = 1;
2128 WinInvalidateRect(hwnd, NULL, FALSE);
2129 }
2130 else {
2131 ad->cursored = (ad->topline - 1) + numlines;
2132 if (ad->cursored > ad->numlines)
2133 ad->cursored = ad->numlines;
2134 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2135 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &rcl);
2136 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2137 }
2138 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2139 break;
2140 case VK_HOME:
2141 if ((shiftstate & KC_CTRL) || ad->cursored == ad->topline) {
2142 ad->topline = 1;
2143 ad->cursored = 1;
2144 WinInvalidateRect(hwnd, NULL, FALSE);
2145 }
2146 else {
2147 ad->cursored = ad->topline;
2148 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &rcl);
2149 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &rcl);
2150 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2151 }
2152 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2153 break;
2154 case VK_SPACE:
2155 WinSendMsg(hwnd, WM_BUTTON1CLICK,
2156 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2157 ((rcl.yTop - (ad->lMaxHeight *
2158 ((ad->cursored) -
2159 ad->topline))) -
2160 ad->lMaxDescender) - 1),
2161 MPFROM2SHORT(TRUE, 0));
2162 break;
2163 case VK_NEWLINE:
2164 case VK_ENTER:
2165 WinSendMsg(hwnd, WM_BUTTON1DBLCLK,
2166 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2167 ((rcl.yTop - (ad->lMaxHeight *
2168 ((ad->cursored) -
2169 ad->topline))) -
2170 ad->lMaxDescender) - 1), MPFROM2SHORT(0,
2171 0));
2172 break;
2173 }
2174 }
2175 else if (SHORT1FROMMP(mp1) & KC_CHAR) {
2176 switch (SHORT1FROMMP(mp2)) {
2177 case '\r':
2178 case '\n':
2179 WinSendMsg(hwnd, WM_BUTTON1DBLCLK,
2180 MPFROM2SHORT(ad->fattrs.lAveCharWidth + 2,
2181 (rcl.yTop - (ad->lMaxHeight *
2182 ((ad->cursored) -
2183 ad->topline))) - 1),
2184 MPFROM2SHORT(0, 0));
2185 break;
2186 default:
2187 break;
2188 }
2189 }
2190 if (wascursored != ad->cursored)
2191 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2192 }
2193 DosReleaseMutexSem(ad->ScanSem);
2194 }
2195 break;
2196
2197 case WM_BUTTON1MOTIONSTART:
2198 WinSetFocus(HWND_DESKTOP, hwnd);
2199 if (ad && !ad->stopflag && !ad->busy &&
2200 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2201 ad->mousecaptured = TRUE;
2202 ad->lastselected = ULONG_MAX;
2203 ad->lastdirection = 0;
2204 WinSetCapture(HWND_DESKTOP, hwnd);
2205 WinSendMsg(hwnd, WM_BUTTON1CLICK, mp1, MPFROM2SHORT(TRUE, 0));
2206 }
2207 break;
2208
2209 case WM_MOUSEMOVE:
2210 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
2211 if (ad && ad->mousecaptured) {
2212
2213 ULONG numlines, whichline, x;
2214 LONG inc;
2215 RECTL Rectl;
2216 POINTS pts;
2217 BOOL outofwindow = FALSE;
2218
2219 WinQueryWindowRect(hwnd, &Rectl);
2220 numlines = NumLines(&Rectl, ad);
2221 if (numlines) {
2222 pts.x = SHORT1FROMMP(mp1);
2223 pts.y = SHORT2FROMMP(mp1);
2224 if (pts.y < 0) {
2225 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2226 MPFROM2SHORT(0, SB_LINEDOWN));
2227 pts.y = 1;
2228 outofwindow = TRUE;
2229 }
2230 else if (pts.y > Rectl.yTop - Rectl.yBottom) {
2231 WinSendMsg(hwnd, WM_VSCROLL, MPFROM2SHORT(FID_VERTSCROLL, 0),
2232 MPFROM2SHORT(0, SB_LINEUP));
2233 pts.y = (Rectl.yTop - Rectl.yBottom) - 1;
2234 outofwindow = TRUE;
2235 }
2236 whichline = ((Rectl.yTop - Rectl.yBottom) -
2237 ((LONG) pts.y + ad->lMaxDescender)) / ad->lMaxHeight;
2238 if (whichline > numlines - 1)
2239 whichline = numlines - 1;
2240 whichline += (ad->topline - 1);
2241 if (whichline < ad->numlines && ad->lastselected != whichline) {
2242 if (ad->lastselected != ULONG_MAX) {
2243 inc = (ad->lastselected < whichline) ? 1 : -1;
2244 for (x = ad->lastselected + inc;
2245 x != whichline && x < ad->numlines;
2246 (ad->lastselected < whichline) ? x++ : x--) {
2247 if (ad->markedlines) {
2248 if (ad->markedlines[x] & VF_SELECTED) {
2249 ad->markedlines[x] &= (~VF_SELECTED);
2250 ad->selected--;
2251 }
2252 else {
2253 ad->markedlines[x] |= VF_SELECTED;
2254 ad->selected++;
2255 }
2256 }
2257 PaintLine(hwnd, ad->hps, x, ad->topline, &Rectl);
2258 }
2259 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2260 }
2261 WinSendMsg(hwnd, WM_BUTTON1CLICK, MPFROM2SHORT(pts.x, pts.y),
2262 MPFROM2SHORT(TRUE, 0));
2263 }
2264 }
2265 if (outofwindow) {
2266
2267 POINTL ptl;
2268
2269 WinQueryPointerPos(HWND_DESKTOP, &ptl);
2270 WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1L);
2271 if ((SHORT) ptl.y == (SHORT) SHORT2FROMMP(mp1) &&
2272 (SHORT) ptl.x == (SHORT) SHORT1FROMMP(mp1) &&
2273 ((SHORT) ptl.y < 0 || ptl.y > (Rectl.yTop - Rectl.yBottom))) {
2274 PostMsg(hwnd, UM_MOUSEMOVE, mp1, MPVOID);
2275 DosSleep(1);
2276 }
2277 }
2278 }
2279 break;
2280
2281 case UM_MOUSEMOVE:
2282 if (ad && ad->mousecaptured) {
2283
2284 POINTL ptl;
2285 RECTL Rectl;
2286
2287 WinQueryWindowRect(hwnd, &Rectl);
2288 WinQueryPointerPos(HWND_DESKTOP, &ptl);
2289 WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1);
2290 if ((SHORT) ptl.y == (SHORT) SHORT2FROMMP(mp1) &&
2291 (SHORT) ptl.x == (SHORT) SHORT1FROMMP(mp1) &&
2292 ((SHORT) ptl.y < 0 || ptl.y > (Rectl.yTop - Rectl.yBottom))) {
2293 DosSleep(1);
2294 PostMsg(hwnd, WM_MOUSEMOVE, mp1, MPFROM2SHORT(TRUE, 0));
2295 }
2296 }
2297 return 0;
2298
2299 case WM_BUTTON1UP:
2300 case WM_BUTTON1MOTIONEND:
2301 WinSetFocus(HWND_DESKTOP, hwnd);
2302 if (ad && ad->mousecaptured) {
2303 ad->mousecaptured = FALSE;
2304 ad->lastselected = ULONG_MAX;
2305 ad->lastdirection = 0;
2306 DosReleaseMutexSem(ad->ScanSem);
2307 WinSetCapture(HWND_DESKTOP, NULLHANDLE);
2308 }
2309 break;
2310
2311 case WM_BUTTON1DBLCLK:
2312 case WM_BUTTON1CLICK:
2313 WinSetFocus(HWND_DESKTOP, hwnd);
2314 if (ad && !ad->stopflag && ad->numlines && ad->text && !ad->busy &&
2315 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2316
2317 ULONG numlines, whichline, wascursored, width;
2318 RECTL Rectl;
2319 POINTS pts;
2320
2321 WinQueryWindowRect(hwnd, &Rectl);
2322 numlines = NumLines(&Rectl, ad);
2323 if (!numlines)
2324 break;
2325 pts.x = SHORT1FROMMP(mp1);
2326 pts.y = SHORT2FROMMP(mp1);
2327 whichline = ((Rectl.yTop - Rectl.yBottom) -
2328 ((LONG) pts.y + ad->lMaxDescender)) / ad->lMaxHeight;
2329 if (whichline > numlines - 1)
2330 whichline = numlines - 1;
2331 whichline += (ad->topline - 1);
2332 if (whichline + 1 > ad->numlines)
2333 break;
2334 wascursored = ad->cursored;
2335 ad->cursored = whichline + 1;
2336 if (msg == WM_BUTTON1CLICK) {
2337 if (ad->lastselected != ULONG_MAX) {
2338 if (whichline > ad->lastselected)
2339 ad->lastdirection = 1;
2340 else
2341 ad->lastdirection = 2;
2342 }
2343 else
2344 ad->lastdirection = 0;
2345 ad->lastselected = whichline;
2346 if (whichline < ad->numlines) {
2347 if (ad->markedlines) {
2348 if (ad->markedlines[whichline] & VF_SELECTED) {
2349 ad->selected--;
2350 ad->markedlines[whichline] &= (~VF_SELECTED);
2351 }
2352 else {
2353 ad->selected++;
2354 ad->markedlines[whichline] |= VF_SELECTED;
2355 }
2356 }
2357 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2358 }
2359 PaintLine(hwnd, ad->hps, whichline, ad->topline, &Rectl);
2360 if (ad->cursored != wascursored) {
2361 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
2362 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2363 }
2364 }
2365 else {
2366
2367 SHORT numsels, sSelect = 0, numinserted;
2368 ULONG linenum, size;
2369
2370 if (!ad->hex && ad->lines) {
2371
2372 CHAR *p, *e;
2373
2374 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
2375 e = p = ad->lines[whichline];
2376 while (*e != '\r' && *e != '\n' && e < ad->text + ad->textsize) {
2377 if (ad->wrapon && e - p == width)
2378 break;
2379 e++;
2380 }
2381 if ((*e == '\r' || *e == '\n') && e > p)
2382 e--;
2383 width = e - p;
2384 if (!width)
2385 goto NoAdd;
2386
2387 if ((ad->httpin && (*httprun || fHttpRunWPSDefault) &&
2388 strnstr(ad->lines[whichline], "http://", width)) ||
2389 (ad->ftpin && (*ftprun || fFtpRunWPSDefault) &&
2390 strnstr(ad->lines[whichline], "ftp://", width)) ||
2391 (ad->mailin && *mailrun && mailstr(ad->lines[whichline], "@", width))) {
2392
2393 USHORT ret;
2394 URLDATA *urld;
2395
2396 urld = xmallocz(sizeof(URLDATA), pszSrcFile, __LINE__);
2397 if (urld) {
2398 urld->size = sizeof(URLDATA);
2399 urld->line = ad->lines[whichline];
2400 urld->len = width;
2401 ret = (USHORT) WinDlgBox(HWND_DESKTOP, hwnd, UrlDlgProc,
2402 FM3ModHandle, URL_FRAME, urld);
2403 switch (ret) {
2404 case 0:
2405 xfree(urld, pszSrcFile, __LINE__);
2406# ifdef FORTIFY
2407 Fortify_LeaveScope();
2408# endif
2409 goto NoAdd;
2410 case 1:
2411 if (*urld->url) {
2412 if (fHttpRunWPSDefault) {
2413 CHAR WPSDefaultHttpRun[CCHMAXPATH], WPSDefaultHttpRunDir[CCHMAXPATH];
2414
2415 size = sizeof(WPSDefaultHttpRun);
2416 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2417 "DefaultBrowserExe", WPSDefaultHttpRun, &size);
2418 size = sizeof(WPSDefaultHttpRunDir);
2419 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2420 "DefaultWorkingDir", WPSDefaultHttpRunDir, &size);
2421 runemf2(SEPARATE | WINDOWED,
2422 hwnd, pszSrcFile, __LINE__,
2423 WPSDefaultHttpRunDir,
2424 fLibPathStrictHttpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2425 "%s %s", WPSDefaultHttpRun, urld->url);
2426 }
2427 else
2428 runemf2(SEPARATE | WINDOWED,
2429 hwnd, pszSrcFile, __LINE__,
2430 httprundir,
2431 fLibPathStrictHttpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2432 "%s %s", httprun, urld->url);
2433 }
2434 xfree(urld, pszSrcFile, __LINE__);
2435# ifdef FORTIFY
2436 Fortify_LeaveScope();
2437# endif
2438 goto NoAdd;
2439 case 2:
2440 if (*urld->url){
2441 if (fFtpRunWPSDefault) {
2442 CHAR WPSDefaultFtpRun[CCHMAXPATH], WPSDefaultFtpRunDir[CCHMAXPATH];
2443
2444 size = sizeof(WPSDefaultFtpRun);
2445 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2446 "DefaultBrowserExe", WPSDefaultFtpRun, &size);
2447 size = sizeof(WPSDefaultFtpRunDir);
2448 PrfQueryProfileData(HINI_USERPROFILE, "WPURLDEFAULTSETTINGS",
2449 "DefaultWorkingDir", WPSDefaultFtpRunDir, &size);
2450 runemf2(SEPARATE | WINDOWED,
2451 hwnd, pszSrcFile, __LINE__,
2452 WPSDefaultFtpRunDir,
2453 fLibPathStrictFtpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2454 "%s %s", WPSDefaultFtpRun, urld->url);
2455 }
2456 else
2457 runemf2(SEPARATE | WINDOWED,
2458 hwnd, pszSrcFile, __LINE__,
2459 ftprundir,
2460 fLibPathStrictFtpRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2461 "%s %s", ftprun, urld->url);
2462 }
2463 xfree(urld, pszSrcFile, __LINE__);
2464# ifdef FORTIFY
2465 Fortify_LeaveScope();
2466# endif
2467 goto NoAdd;
2468 case 3:
2469 if (*urld->url){
2470 runemf2(SEPARATE | WINDOWED,
2471 hwnd, pszSrcFile, __LINE__,
2472 mailrundir,
2473 fLibPathStrictMailRun ? "SET LIBPATHSTRICT=TRUE" : NULL,
2474 "%s %s", mailrun, urld->url);
2475 }
2476 xfree(urld, pszSrcFile, __LINE__);
2477# ifdef FORTIFY
2478 Fortify_LeaveScope();
2479# endif
2480 goto NoAdd;
2481 default:
2482 break;
2483 }
2484 xfree(urld, pszSrcFile, __LINE__);
2485# ifdef FORTIFY
2486 Fortify_LeaveScope();
2487# endif
2488 }
2489 }
2490 }
2491 //Move line to selection box at top of viewer
2492 numsels = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2493 LM_QUERYITEMCOUNT, MPVOID,
2494 MPVOID);
2495 if (numsels > 0) {
2496 for (sSelect = 0; sSelect < numsels; sSelect++) {
2497 linenum =
2498 (ULONG) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2499 LM_QUERYITEMHANDLE,
2500 MPFROM2SHORT(sSelect, 0), MPVOID);
2501 if (linenum == whichline)
2502 goto NoAdd;
2503 }
2504 }
2505 {
2506 CHAR *s = NULL, *p;
2507
2508 if (!ad->hex && ad->lines) {
2509 s = xmalloc(width + 2, pszSrcFile, __LINE__);
2510 if (!s)
2511 goto NoAdd;
2512 strncpy(s, ad->lines[whichline], width + 1);
2513 s[width + 1] = 0;
2514 p = s;
2515 while (*p) {
2516 if (*p == '\r' || *p == '\n') {
2517 *p = 0;
2518 break;
2519 }
2520 p++;
2521 }
2522 }
2523 else {
2524
2525 register ULONG x;
2526
2527 width = ad->textsize - (whichline * 16);
2528 width = min(width, 16); //standard hexx line length
2529 //use 80 as width * 5 gives inconsistent format on short lines
2530 s = xmalloc(80, pszSrcFile, __LINE__);
2531 if (!s)
2532 goto NoAdd;
2533 sprintf(s, "%08lx ", whichline * 16);
2534 p = s + 9;
2535 for (x = 0; x < width; x++) {
2536 sprintf(p, " %02x", (UCHAR)ad->text[(whichline * 16) + x]);
2537 p += 3;
2538 }
2539 *p = ' ';
2540 p++;
2541 *p = ' ';
2542 p++;
2543 for (x = 0; x < width; x++) {
2544 *p = ad->text[(whichline * 16) + x];
2545 p++;
2546 }
2547 *p = 0;
2548 }
2549 if (s) {
2550 if (*s) {
2551 ad->dummy = TRUE;
2552 numinserted = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
2553 NEWVIEW_LISTBOX,
2554 LM_INSERTITEM,
2555 MPFROM2SHORT(LIT_END,
2556 0),
2557 MPFROMP(s));
2558 ad->dummy = FALSE;
2559 if (numinserted >= 0)
2560 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2561 LM_SETITEMHANDLE,
2562 MPFROM2SHORT(numinserted, 0),
2563 MPFROMLONG(whichline));
2564 }
2565 xfree(s, pszSrcFile, __LINE__);
2566# ifdef FORTIFY
2567 Fortify_LeaveScope();
2568# endif
2569 }
2570 }
2571 if (!numsels)
2572 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
2573 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
2574 }
2575 NoAdd:
2576 DosReleaseMutexSem(ad->ScanSem);
2577 DosPostEventSem(CompactSem);
2578 }
2579 break;
2580
2581 case WM_MENUEND:
2582 if (ad && ad->hwndPopup == (HWND) mp2) {
2583 WinDestroyWindow(ad->hwndPopup);
2584 ad->hwndPopup = (HWND) 0;
2585 }
2586 break;
2587
2588 case UM_CONTEXTMENU:
2589 case WM_CONTEXTMENU:
2590 if (ad) {
2591 if (!ad->hwndPopup) {
2592 ad->hwndPopup =
2593 WinLoadMenu(HWND_DESKTOP, FM3ModHandle, NEWVIEW_POPUP);
2594 if (ad->hwndPopup)
2595 WinSetPresParam(ad->hwndPopup,
2596 PP_FONTNAMESIZE,
2597 strlen(GetPString(IDS_8HELVTEXT)) + 1,
2598 GetPString(IDS_8HELVTEXT));
2599 }
2600 if (ad->hwndPopup) {
2601
2602 APIRET rc;
2603 SHORT sSelect;
2604
2605 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
2606 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOCLIP, (rc == 0 &&
2607 ad->selected != 0));
2608 WinEnableMenuItem(ad->hwndPopup, IDM_APPENDTOCLIP, (rc == 0 &&
2609 ad->selected !=
2610 0));
2611 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOLIST,
2612 (rc == 0 && ad->selected != 0));
2613 sSelect =
2614 (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
2615 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
2616 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOCLIP2,
2617 (rc == 0 && sSelect > 0));
2618 WinEnableMenuItem(ad->hwndPopup, IDM_APPENDTOCLIP2,
2619 (rc == 0 && sSelect > 0));
2620 WinEnableMenuItem(ad->hwndPopup, IDM_SAVETOLIST2,
2621 (rc == 0 && sSelect > 0));
2622 WinEnableMenuItem(ad->hwndPopup, IDM_SELECTALL,
2623 (rc == 0 && ad->numlines != 0 && ad->markedlines));
2624 WinEnableMenuItem(ad->hwndPopup, IDM_DESELECTALL,
2625 (rc == 0 && ad->numlines != 0 && ad->markedlines
2626 && ad->selected != 0));
2627 WinEnableMenuItem(ad->hwndPopup, IDM_PREVSELECTED,
2628 (rc == 0 && ad->numlines != 0 && ad->markedlines
2629 && ad->selected != 0));
2630 WinEnableMenuItem(ad->hwndPopup, IDM_NEXTSELECTED,
2631 (rc == 0 && ad->numlines != 0 && ad->markedlines
2632 && ad->selected != 0));
2633 WinEnableMenuItem(ad->hwndPopup, IDM_SELECTFOUND,
2634 (rc == 0 && ad->numlines != 0 && ad->markedlines
2635 && ad->found != 0));
2636 WinEnableMenuItem(ad->hwndPopup, IDM_DESELECTFOUND,
2637 (rc == 0 && ad->numlines != 0 && ad->markedlines
2638 && ad->selected != 0 && ad->found != 0));
2639 WinEnableMenuItem(ad->hwndPopup, IDM_INVERT,
2640 (rc == 0 && ad->numlines != 0 && ad->markedlines));
2641 WinEnableMenuItem(ad->hwndPopup, IDM_FINDFIRST,
2642 (rc == 0 && ad->numlines != 0 && ad->markedlines));
2643 WinEnableMenuItem(ad->hwndPopup, IDM_FINDNEXT,
2644 (rc == 0 && ad->numlines != 0 && ad->markedlines
2645 && ad->found));
2646 WinEnableMenuItem(ad->hwndPopup, IDM_FINDPREV,
2647 (rc == 0 && ad->numlines != 0 && ad->markedlines
2648 && ad->found));
2649 WinEnableMenuItem(ad->hwndPopup, IDM_GOTOLINE,
2650 (rc == 0 && ad->numlines != 0));
2651 WinEnableMenuItem(ad->hwndPopup, IDM_GOTOOFFSET,
2652 (rc == 0 && ad->textsize != 0));
2653 if (!rc)
2654 DosReleaseMutexSem(ad->ScanSem);
2655 PopupMenu(hwnd, hwnd, ad->hwndPopup);
2656 }
2657 }
2658 break;
2659
2660 case UM_SETUP3:
2661 if (ad && !ad->busy &&
2662 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2663 ad->multiplier = ad->numlines / 32767;
2664 if (ad->multiplier * 32767 != ad->numlines)
2665 ad->multiplier++;
2666 if (!ad->multiplier)
2667 ad->multiplier++;
2668 {
2669 RECTL Rectl;
2670 ULONG numlines;
2671
2672 WinQueryWindowRect(hwnd, &Rectl);
2673 numlines = NumLines(&Rectl, ad);
2674 if (numlines) {
2675 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
2676 MPFROM2SHORT((SHORT) Rectl.xRight, (SHORT) ad->maxx),
2677 MPVOID);
2678 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
2679 MPFROM2SHORT((SHORT) numlines,
2680 (SHORT) min(ad->numlines, 32767)), MPVOID);
2681 if (ad->multiplier)
2682 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
2683 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
2684 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
2685 ad->multiplier) - numlines));
2686 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
2687 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
2688 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
2689 if (ad->numlines - ad->topline < numlines) {
2690 ad->topline = ((ad->numlines - ad->topline) - numlines);
2691 WinInvalidateRect(hwnd, NULL, FALSE);
2692 }
2693 }
2694 }
2695 DosReleaseMutexSem(ad->ScanSem);
2696 }
2697 return 0;
2698
2699 case UM_SETUP4:
2700 if (ad && !ad->busy &&
2701 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2702
2703 CHAR s[140], t[34];
2704 ULONG numlines;
2705 RECTL Rectl;
2706
2707 WinQueryWindowRect(hwnd, &Rectl);
2708 numlines = NumLines(&Rectl, ad);
2709 commafmt(t, sizeof(t), ad->cursored);
2710 strcpy(s, GetPString(IDS_LINECOLONTEXT));
2711 strcat(s, t);
2712 if (ad->selected) {
2713 if (ad->selected > ad->numlines)
2714 ad->selected = 0;
2715 else {
2716 commafmt(t, sizeof(t), ad->selected);
2717 strcat(s, " (");
2718 strcat(s, t);
2719 strcat(s, GetPString(IDS_SELECTEDPARENTEXT));
2720 }
2721 }
2722 if (ad->found) {
2723 if (ad->found > ad->numlines)
2724 ad->found = 0;
2725 else {
2726 commafmt(t, sizeof(t), ad->found);
2727 strcat(s, " (");
2728 strcat(s, t);
2729 strcat(s, GetPString(IDS_FOUNDPARENTEXT));
2730 }
2731 }
2732 WinSetWindowText(ad->hwndStatus2, s);
2733 if (!ad->hex && ad->lines)
2734 commafmt(t, sizeof(t), ad->lines[ad->cursored - 1] - ad->text);
2735 else
2736 commafmt(t, sizeof(t), (ad->cursored - 1) * 16);
2737 strcpy(s, GetPString(IDS_OFFSETCOLONTEXT));
2738 strcat(s, t);
2739 WinSetWindowText(ad->hwndStatus3, s);
2740 if (ad->multiplier)
2741 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
2742 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
2743 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
2744 ad->multiplier) - numlines));
2745 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
2746 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
2747 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
2748 DosReleaseMutexSem(ad->ScanSem);
2749 }
2750 return 0;
2751
2752 case UM_CONTAINER_FILLED:
2753 if (ad && !ad->busy &&
2754 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2755 ad->stopflag = 0;
2756 ad->topline = 1;
2757 ad->cursored = 1;
2758 ad->multiplier = 1;
2759 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2760 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2761 IDM_NEXTBLANKLINE), !ad->hex);
2762 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2763 IDM_PREVBLANKLINE), !ad->hex);
2764 if (ad->numlines)
2765 {
2766 if (mp1 && (ULONG) mp1 < ad->numlines + 1) {
2767
2768 RECTL Rectl;
2769 ULONG numlines;
2770
2771 WinQueryWindowRect(hwnd, &Rectl);
2772 numlines = NumLines(&Rectl, ad);
2773 if (numlines) {
2774 ad->topline = (ULONG) mp1;
2775 if (ad->numlines - ad->topline < numlines)
2776 ad->topline = ad->numlines - numlines;
2777 ad->cursored = (ULONG) mp1;
2778 if (mp2) {
2779 ad->cursored = (ULONG) mp2;
2780 if (ad->cursored > (ad->topline - 1) + numlines)
2781 ad->cursored = (ad->topline - 1) + numlines;
2782 }
2783 }
2784 }
2785 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
2786 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2787 WinInvalidateRect(hwnd, NULL, FALSE);
2788 }
2789 DosReleaseMutexSem(ad->ScanSem);
2790 }
2791 else if (ad)
2792 ad->needrefreshing = TRUE;
2793 return 0;
2794
2795 case WM_ERASEBACKGROUND:
2796 WinFillRect((HPS) mp1, (PRECTL) mp2,
2797 standardcolors[ad->colors[COLORS_NORMALBACK]]);
2798 return 0;
2799
2800 case WM_PAINT:
2801 if (ad) {
2802
2803 HPS hpsp;
2804 RECTL Rectl;
2805 register ULONG x;
2806 ULONG numlines, wascursored = ad->cursored;
2807
2808 hpsp = WinBeginPaint(hwnd, ad->hps, &Rectl);
2809 WinFillRect(hpsp, &Rectl,
2810 standardcolors[ad->colors[COLORS_NORMALBACK]]);
2811 if (!ad->stopflag && !ad->busy &&
2812 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2813 WinQueryWindowRect(hwnd, &Rectl);
2814 numlines = NumLines(&Rectl, ad);
2815 if (numlines) {
2816 if (ad->numlines && (ad->lines || ad->hex)) {
2817 if (ad->topline > (ad->numlines + 1) - numlines)
2818 ad->topline = (ad->numlines + 1) - numlines;
2819 if (ad->topline > ad->numlines)
2820 ad->topline = 1;
2821 if (!ad->topline)
2822 ad->topline = 1;
2823 if (ad->cursored < ad->topline)
2824 ad->cursored = ad->topline;
2825 else if (ad->cursored > (ad->topline + numlines) - 1)
2826 ad->cursored = (ad->topline + numlines) - 1;
2827 if (ad->cursored > ad->numlines)
2828 ad->cursored = ad->numlines;
2829 if (wascursored != ad->cursored)
2830 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
2831 }
2832 else
2833 ad->topline = ad->cursored = 1;
2834 if (ad->numlines && (ad->lines || ad->hex)) {
2835 for (x = ad->topline - 1; x < ad->numlines; x++) {
2836 if (((LONG) (Rectl.yTop -
2837 (ad->lMaxHeight *
2838 (((x + 1) - ad->topline) + 1))) -
2839 ad->lMaxDescender) <= 0)
2840 break;
2841 PaintLine(hwnd, hpsp, x, ad->topline, &Rectl);
2842 }
2843 }
2844 }
2845 if (ad->multiplier)
2846 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
2847 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
2848 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
2849 ad->multiplier) - numlines));
2850 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
2851 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
2852 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
2853 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
2854 MPFROM2SHORT((SHORT) Rectl.xRight, (SHORT) ad->maxx),
2855 MPVOID);
2856 DosReleaseMutexSem(ad->ScanSem);
2857 ad->needrefreshing = FALSE;
2858 }
2859 else
2860 ad->needrefreshing = TRUE;
2861 WinEndPaint(hpsp);
2862 }
2863 else {
2864
2865 HPS hpsp;
2866
2867 hpsp = WinBeginPaint(hwnd, (HPS) 0, NULL);
2868 WinEndPaint(hpsp);
2869 }
2870 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2871 break;
2872
2873 case WM_HSCROLL:
2874 {
2875 RECTL rectl;
2876 BOOL invalidate = TRUE;
2877
2878 WinQueryWindowRect(hwnd, &rectl);
2879 switch (SHORT2FROMMP(mp2)) {
2880 case SB_PAGERIGHT:
2881 if (abs(ad->horzscroll) <= ad->maxx - rectl.xRight) {
2882 ad->horzscroll -= rectl.xRight;
2883 if (abs(ad->horzscroll) > ad->maxx - rectl.xRight)
2884 ad->horzscroll = -((ad->maxx - rectl.xRight) +
2885 ad->fattrs.lAveCharWidth);
2886 }
2887 else
2888 invalidate = FALSE;
2889 break;
2890
2891 case SB_PAGELEFT:
2892 if (ad->horzscroll < 0) {
2893 ad->horzscroll += rectl.xRight;
2894 if (ad->horzscroll > 0)
2895 ad->horzscroll = 0;
2896 }
2897 else
2898 invalidate = FALSE;
2899 break;
2900
2901 case SB_LINERIGHT:
2902 if (abs(ad->horzscroll) <= ad->maxx - rectl.xRight)
2903 ad->horzscroll -= ad->fattrs.lAveCharWidth;
2904 else
2905 invalidate = FALSE;
2906 break;
2907
2908 case SB_LINELEFT:
2909 if (ad->horzscroll < 0)
2910 ad->horzscroll += ad->fattrs.lAveCharWidth;
2911 else
2912 invalidate = FALSE;
2913 break;
2914
2915 case SB_SLIDERTRACK:
2916 ad->horzscroll = (SHORT1FROMMP(mp2) / ad->fattrs.lAveCharWidth) *
2917 ad->fattrs.lAveCharWidth;
2918 ad->horzscroll = -(ad->horzscroll);
2919 if (ad->horzscroll > 0)
2920 ad->horzscroll = 0;
2921 if (abs(ad->horzscroll) > (ad->maxx - rectl.xRight) +
2922 ad->fattrs.lAveCharWidth)
2923 ad->horzscroll = -(ad->maxx - rectl.xRight);
2924 break;
2925
2926 default:
2927 invalidate = FALSE;
2928 break;
2929 }
2930 if (invalidate)
2931 WinInvalidateRect(hwnd, NULL, FALSE);
2932 }
2933 break;
2934
2935 case WM_VSCROLL:
2936 if (ad && !ad->stopflag && ad->text && ad->numlines && !ad->busy &&
2937 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
2938
2939 ULONG numlines, wascursored;
2940 RECTL rcl;
2941
2942 WinQueryWindowRect(hwnd, &rcl);
2943 numlines = NumLines(&rcl, ad);
2944 if (numlines) {
2945 wascursored = ad->cursored;
2946 switch (SHORT2FROMMP(mp2)) {
2947 case SB_PAGEUP:
2948 if (ad->topline > 1) {
2949 ad->topline -= numlines;
2950 if (ad->topline > ad->numlines ||
2951 ad->topline + numlines > (ad->numlines + 1))
2952 ad->topline = 1;
2953 if (ad->cursored > ad->topline + numlines)
2954 ad->cursored = ad->topline + numlines;
2955 if (ad->cursored > ad->numlines)
2956 ad->cursored = ad->numlines;
2957 WinInvalidateRect(hwnd, NULL, FALSE);
2958 }
2959 break;
2960 case SB_PAGEDOWN:
2961 if (ad->topline + numlines <= ad->numlines) {
2962 ad->topline += numlines;
2963 if (ad->topline + numlines > ad->numlines + 1)
2964 ad->topline = (ad->numlines + 1) - numlines;
2965 if (ad->cursored < ad->topline)
2966 ad->cursored = ad->topline;
2967 if (ad->cursored + 1 > ad->topline + numlines)
2968 ad->cursored = (ad->topline + numlines) - 1;
2969 if (ad->cursored > ad->numlines)
2970 ad->cursored = ad->numlines;
2971 WinInvalidateRect(hwnd, NULL, FALSE);
2972 }
2973 break;
2974 case SB_LINEDOWN:
2975 if (ad->topline + numlines <= ad->numlines) {
2976
2977 RECTL Rectl, iRectl;
2978
2979 ad->topline++;
2980 if (ad->cursored < ad->topline)
2981 ad->cursored = ad->topline;
2982 else if (ad->cursored + 1 > ad->topline + numlines)
2983 ad->cursored = (ad->topline + numlines) - 1;
2984 if (ad->cursored > ad->numlines)
2985 ad->cursored = ad->numlines;
2986 WinQueryWindowRect(hwnd, &Rectl);
2987 WinScrollWindow(hwnd, 0, ad->lMaxHeight,
2988 NULL, NULL, NULLHANDLE, &iRectl, 0);
2989 WinFillRect(ad->hps, &iRectl,
2990 standardcolors[ad->colors[COLORS_NORMALBACK]]);
2991 PaintLine(hwnd, ad->hps, (ad->topline + numlines) - 2,
2992 ad->topline, &Rectl);
2993 if (ad->cursored != ad->topline + numlines)
2994 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &Rectl);
2995 if (wascursored != ad->cursored &&
2996 wascursored < ad->topline + numlines &&
2997 wascursored >= ad->topline)
2998 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
2999 if (numlines >= ad->numlines)
3000 numlines = 0;
3001 if (ad->multiplier)
3002 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3003 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
3004 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
3005 ad->multiplier) -
3006 numlines));
3007 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3008 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
3009 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
3010 }
3011 break;
3012 case SB_LINEUP:
3013 if (ad->topline > 1) {
3014
3015 RECTL Rectl, iRectl;
3016
3017 ad->topline--;
3018 if (ad->cursored < ad->topline)
3019 ad->cursored = ad->topline;
3020 else if (ad->cursored + 1 > ad->topline + numlines)
3021 ad->cursored = (ad->topline + numlines) - 1;
3022 if (ad->cursored > ad->numlines)
3023 ad->cursored = ad->numlines;
3024 WinQueryWindowRect(hwnd, &Rectl);
3025 WinScrollWindow(hwnd, 0, -ad->lMaxHeight,
3026 NULL, NULL, NULLHANDLE, &iRectl, 0);
3027 WinFillRect(ad->hps, &iRectl,
3028 standardcolors[ad->colors[COLORS_NORMALBACK]]);
3029 iRectl = Rectl;
3030 iRectl.yTop -= ((numlines * ad->lMaxHeight) + ad->lMaxDescender);
3031 WinFillRect(ad->hps, &iRectl,
3032 standardcolors[ad->colors[COLORS_NORMALBACK]]);
3033 PaintLine(hwnd, ad->hps, ad->topline - 1, ad->topline, &Rectl);
3034 if (ad->cursored != ad->topline)
3035 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &Rectl);
3036 if (ad->cursored != wascursored &&
3037 wascursored >= ad->topline &&
3038 wascursored < ad->topline + numlines)
3039 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
3040 if (numlines >= ad->numlines)
3041 numlines = 0;
3042 if (ad->multiplier)
3043 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3044 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
3045 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
3046 ad->multiplier) -
3047 numlines));
3048 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3049 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
3050 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
3051 }
3052 break;
3053 case SB_SLIDERTRACK:
3054 if ((SHORT1FROMMP(mp2) >= 1) || (SHORT1FROMMP(mp2)) <= ad->numlines) {
3055 ad->topline = (ULONG) SHORT1FROMMP(mp2) * ad->multiplier;
3056 if (ad->topline + numlines > ad->numlines + 1)
3057 ad->topline = (ad->numlines + 1) - numlines;
3058 if (!ad->topline)
3059 ad->topline = 1;
3060 if (ad->cursored < ad->topline)
3061 ad->cursored = ad->topline;
3062 else if (ad->cursored > ad->topline + numlines)
3063 ad->cursored = ad->topline + numlines;
3064 if (ad->cursored > ad->numlines)
3065 ad->cursored = ad->numlines;
3066 WinInvalidateRect(hwnd, NULL, FALSE);
3067 }
3068 else
3069 WinAlarm(HWND_DESKTOP, WA_NOTE);
3070 break;
3071 }
3072 if (ad->cursored != wascursored)
3073 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3074 }
3075 DosReleaseMutexSem(ad->ScanSem);
3076 }
3077 break;
3078
3079 case WM_INITMENU:
3080 switch (SHORT1FROMMP(mp1)) {
3081 case IDM_FILESMENU:
3082 {
3083 APIRET rc;
3084 SHORT sSelect;
3085
3086 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3087 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP, (rc == 0 &&
3088 ad->selected != 0));
3089 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP, (rc == 0 &&
3090 ad->selected != 0));
3091 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST, (rc == 0 &&
3092 ad->selected != 0));
3093 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3094 LM_QUERYITEMCOUNT, MPVOID,
3095 MPVOID);
3096 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP2,
3097 (rc == 0 && sSelect > 0));
3098 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP2,
3099 (rc == 0 && sSelect > 0));
3100 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST2,
3101 (rc == 0 && sSelect > 0));
3102 if (!rc)
3103 DosReleaseMutexSem(ad->ScanSem);
3104 }
3105 break;
3106
3107 case IDM_VIEWSMENU:
3108 {
3109 APIRET rc;
3110
3111 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3112 WinEnableMenuItem((HWND) mp2, IDM_FONTPALETTE, (rc == 0));
3113 WinEnableMenuItem((HWND) mp2, IDM_HEXMODE, (rc == 0));
3114 WinEnableMenuItem((HWND) mp2, IDM_WRAP, (rc == 0));
3115 WinEnableMenuItem((HWND) mp2, IDM_CODEPAGE, (rc == 0));
3116 if (!rc)
3117 DosReleaseMutexSem(ad->ScanSem);
3118 }
3119 WinCheckMenuItem((HWND) mp2, IDM_HEXMODE, ad->hex);
3120 WinCheckMenuItem((HWND) mp2, IDM_WRAP, ad->wrapon);
3121 WinCheckMenuItem((HWND) mp2, IDM_IGNOREFTP, ad->ignoreftp);
3122 WinCheckMenuItem((HWND) mp2, IDM_IGNOREHTTP, ad->ignorehttp);
3123 WinCheckMenuItem((HWND) mp2, IDM_IGNOREMAIL, ad->ignoremail);
3124 break;
3125
3126 case IDM_SEARCHMENU:
3127 {
3128 APIRET rc;
3129
3130 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3131 WinEnableMenuItem((HWND) mp2, IDM_FINDFIRST, (rc == 0 &&
3132 ad->numlines != 0 &&
3133 ad->markedlines));
3134 WinEnableMenuItem((HWND) mp2, IDM_FINDNEXT, (rc == 0 &&
3135 ad->numlines != 0 &&
3136 ad->markedlines &&
3137 ad->found != 0));
3138 WinEnableMenuItem((HWND) mp2, IDM_FINDPREV, (rc == 0 &&
3139 ad->numlines != 0 &&
3140 ad->markedlines &&
3141 ad->found != 0));
3142 WinEnableMenuItem((HWND) mp2, IDM_NEXTBLANKLINE, (rc == 0 &&
3143 ad->numlines != 0 &&
3144 !ad->hex));
3145 WinEnableMenuItem((HWND) mp2, IDM_PREVBLANKLINE, (rc == 0 &&
3146 ad->numlines != 0 &&
3147 !ad->hex));
3148 WinEnableMenuItem((HWND) mp2, IDM_GOTOLINE, (rc == 0 &&
3149 ad->numlines != 0));
3150 WinEnableMenuItem((HWND) mp2, IDM_GOTOOFFSET, (rc == 0 &&
3151 ad->textsize != 0));
3152 if (!rc)
3153 DosReleaseMutexSem(ad->ScanSem);
3154 }
3155 break;
3156
3157 case IDM_SELECTSUBMENU:
3158 {
3159 APIRET rc;
3160
3161 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3162 WinEnableMenuItem((HWND) mp2, IDM_SELECTALL, (rc == 0 &&
3163 ad->numlines != 0 &&
3164 ad->markedlines &&
3165 (ad->selected !=
3166 ad->numlines ||
3167 !ad->selected)));
3168 WinEnableMenuItem((HWND) mp2, IDM_DESELECTALL, (rc == 0 &&
3169 ad->numlines != 0 &&
3170 ad->markedlines &&
3171 ad->selected != 0));
3172 WinEnableMenuItem((HWND) mp2, IDM_DESELECTFOUND, (rc == 0 &&
3173 ad->numlines != 0 &&
3174 ad->markedlines &&
3175 ad->selected != 0 &&
3176 ad->found != 0));
3177 WinEnableMenuItem((HWND) mp2, IDM_SELECTFOUND, (rc == 0 &&
3178 ad->numlines != 0 &&
3179 ad->markedlines &&
3180 ad->found != 0 &&
3181 (ad->numlines !=
3182 ad->selected ||
3183 !ad->selected)));
3184 WinEnableMenuItem((HWND) mp2, IDM_NEXTSELECTED, (rc == 0 &&
3185 ad->numlines != 0 &&
3186 ad->markedlines &&
3187 ad->selected != 0));
3188 WinEnableMenuItem((HWND) mp2, IDM_PREVSELECTED, (rc == 0 &&
3189 ad->numlines != 0 &&
3190 ad->markedlines &&
3191 ad->selected != 0));
3192 WinEnableMenuItem((HWND) mp2, IDM_INVERT, (rc == 0 &&
3193 ad->numlines != 0 &&
3194 ad->markedlines));
3195 if (!rc)
3196 DosReleaseMutexSem(ad->ScanSem);
3197 }
3198 break;
3199 }
3200 break;
3201
3202 case UM_CONTROL:
3203 switch (SHORT1FROMMP(mp1)) {
3204 case NEWVIEW_LISTBOX:
3205 switch (SHORT2FROMMP(mp1)) {
3206 case LN_SETFOCUS:
3207 if (ad) {
3208 if (!ad->clientfocused) {
3209 PostMsg(hwnd,
3210 WM_COMMAND, MPFROM2SHORT(IDM_NEXTWINDOW, 0), MPVOID);
3211 break;
3212 }
3213 ad->clientfocused = FALSE;
3214 }
3215 PostMsg(hwnd,
3216 UM_CONTROL, MPFROM2SHORT(NEWVIEW_LISTBOX, LN_SELECT), MPVOID);
3217 break;
3218 case LN_KILLFOCUS:
3219 if (ad) {
3220 ad->clientfocused = TRUE;
3221 WinSetFocus(HWND_DESKTOP, hwnd);
3222 }
3223 break;
3224 case LN_SELECT:
3225 if (ad && !ad->dummy) {
3226
3227 ULONG linenum, numlines;
3228 SHORT sSelect;
3229 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
3230 SHORT1FROMMP(mp1));
3231 RECTL Rectl;
3232
3233 sSelect = (SHORT) WinSendMsg(hwndUL,
3234 LM_QUERYSELECTION,
3235 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3236 if (sSelect >= 0) {
3237 linenum = (ULONG) WinSendMsg(hwndUL,
3238 LM_QUERYITEMHANDLE,
3239 MPFROM2SHORT(sSelect, 0), MPVOID);
3240 if (ad->topline != linenum + 1 && linenum < ad->numlines) {
3241 WinQueryWindowRect(hwnd, &Rectl);
3242 numlines = NumLines(&Rectl, ad);
3243 ad->topline = linenum + 1;
3244 if (ad->numlines - ad->topline < numlines)
3245 ad->topline = ad->numlines - numlines;
3246 ad->cursored = linenum + 1;
3247 WinInvalidateRect(hwnd, NULL, FALSE);
3248 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3249 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3250 }
3251 }
3252 else
3253 PostMsg(hwndUL, LM_SELECTITEM, MPFROM2SHORT(0, 0),
3254 MPFROM2SHORT(TRUE, 0));
3255 }
3256 break;
3257
3258 case LN_ENTER:
3259 if (ad) {
3260
3261 SHORT sSelect;
3262 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
3263 SHORT1FROMMP(mp1));
3264
3265 sSelect = (SHORT) WinSendMsg(hwndUL,
3266 LM_QUERYSELECTION,
3267 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3268 if (sSelect >= 0) {
3269 ad->dummy = TRUE;
3270 WinSendMsg(hwndUL, LM_DELETEITEM,
3271 MPFROM2SHORT(sSelect, 0), MPVOID);
3272 ad->dummy = FALSE;
3273 sSelect = (SHORT) WinSendMsg(hwndUL,
3274 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
3275 if (sSelect <= 0) {
3276 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
3277 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3278 WinSetFocus(HWND_DESKTOP, hwnd);
3279 }
3280 }
3281 }
3282 break;
3283
3284 default:
3285 break;
3286 }
3287 break;
3288
3289 default:
3290 break;
3291 }
3292 return 0;
3293
3294 case WM_COMMAND:
3295 switch (SHORT1FROMMP(mp1)) {
3296 case IDM_EDIT:
3297 if (*editor) {
3298
3299 CHAR *dummy[2];
3300
3301 dummy[0] = ad->filename;
3302 dummy[1] = NULL;
3303 ExecOnList(hwnd, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
3304 pszSrcFile, __LINE__);
3305 }
3306 else
3307 StartMLEEditor(ad->hwndParent, 4, ad->filename, ad->hwndFrame);
3308 ad->hwndRestore = (HWND) 0;
3309 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
3310 break;
3311
3312 case IDM_IGNOREFTP:
3313 ad->ignoreftp = (ad->ignoreftp) ? FALSE : TRUE;
3314 ad->ftpin = FALSE;
3315 if (ad->text && (*ftprun || fFtpRunWPSDefault) &&
3316 !ad->ignoreftp && strstr(ad->text, "ftp://"))
3317 ad->ftpin = TRUE;
3318 IgnoreFTP = ad->ignoreftp;
3319 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreFTP",
3320 &ad->ignoreftp, sizeof(BOOL));
3321 WinInvalidateRect(hwnd, NULL, FALSE);
3322 break;
3323
3324 case IDM_IGNOREHTTP:
3325 ad->ignorehttp = (ad->ignorehttp) ? FALSE : TRUE;
3326 ad->httpin = FALSE;
3327 if (ad->text && (*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
3328 strstr(ad->text, "http://"))
3329 ad->httpin = TRUE;
3330 IgnoreHTTP = ad->ignorehttp;
3331 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
3332 &ad->ignorehttp, sizeof(BOOL));
3333 WinInvalidateRect(hwnd, NULL, FALSE);
3334 break;
3335
3336 case IDM_IGNOREMAIL:
3337 ad->ignoremail = (ad->ignoremail) ? FALSE : TRUE;
3338 ad->mailin = FALSE;
3339 if (ad->text && *mailrun && !ad->ignoremail &&
3340 strstr(ad->text, "@"))
3341 ad->mailin = TRUE;
3342 IgnoreMail = ad->ignoremail;
3343 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreMail",
3344 &ad->ignoremail, sizeof(BOOL));
3345 WinInvalidateRect(hwnd, NULL, FALSE);
3346 break;
3347
3348 case IDM_PREVBLANKLINE:
3349 if (!ad->hex && ad->lines) {
3350
3351 ULONG x;
3352
3353 x = ad->cursored - 2;
3354 if (x >= ad->numlines)
3355 x = 0;
3356 while (x < ad->numlines &&
3357 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3358 x--;
3359 if (x >= ad->numlines)
3360 x = 0;
3361 for (; x < ad->numlines; x--) {
3362 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3363 if (x < ad->numlines - 1)
3364 x++;
3365 break;
3366 }
3367 }
3368 if (x < ad->numlines) {
3369 ad->topline = ad->cursored = x;
3370 WinInvalidateRect(hwnd, NULL, FALSE);
3371 }
3372 }
3373 break;
3374
3375 case IDM_NEXTBLANKLINE:
3376 if (!ad->hex && ad->lines) {
3377
3378 ULONG x;
3379
3380 x = ad->cursored;
3381 while (x < ad->numlines &&
3382 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3383 x++;
3384 for (; x < ad->numlines; x++) {
3385 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3386 if (x < ad->numlines - 1)
3387 x++;
3388 break;
3389 }
3390 }
3391 if (x < ad->numlines) {
3392 while (x < ad->numlines &&
3393 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3394 x++;
3395 if (x < ad->numlines) {
3396 ad->topline = ad->cursored = x;
3397 WinInvalidateRect(hwnd, NULL, FALSE);
3398 }
3399 }
3400 }
3401 break;
3402
3403 case IDM_VIEW:
3404 case IDM_OBJECT:
3405 if (!ad->hex && ad->lines) {
3406
3407 CHAR line[CCHMAXPATH], filename[CCHMAXPATH], *p;
3408
3409 strncpy(line, ad->lines[ad->cursored - 1], CCHMAXPATH);
3410 line[CCHMAXPATH - 1] = 0;
3411 chop_at_crnl(line);
3412 if (*line == '\"') {
3413 memmove(line, line + 1, strlen(line));
3414 p = strchr(line, '\"');
3415 lstrip(line);
3416 if (p)
3417 *p = 0;
3418 rstrip(line);
3419 }
3420 else {
3421 lstrip(line);
3422 p = strchr(line, ' ');
3423 if (p)
3424 *p = 0;
3425 rstrip(line);
3426 }
3427 if (!strchr(line, '\\') && !strchr(line, '/') && !strchr(line, ':')) {
3428 strcpy(filename, ad->filename);
3429 p = strrchr(filename, '\\');
3430 if (p)
3431 p++;
3432 else
3433 p = filename;
3434 strcpy(p, line);
3435 }
3436 else
3437 strcpy(filename, line);
3438 MakeFullName(filename);
3439 if (*filename && IsFile(filename) == 1) {
3440 if (SHORT1FROMMP(mp1) == IDM_OBJECT)
3441 OpenObject(filename, Default, ad->hwndFrame);
3442 else
3443 DefaultView(hwnd, ad->hwndFrame, HWND_DESKTOP, NULL, 0, filename);
3444 }
3445 }
3446 break;
3447
3448 case IDM_COLORPALETTE:
3449 {
3450 COLORS co;
3451 LONG temp[COLORS_MAX];
3452
3453 memset(&co, 0, sizeof(co));
3454 co.size = sizeof(co);
3455 co.numcolors = COLORS_MAX;
3456 co.colors = ad->colors;
3457 co.descriptions = IDS_NVCOLORS1TEXT;
3458 co.origs = temp;
3459 co.prompt = IDS_NVCOLORSPROMPTTEXT;
3460 memcpy(temp, ad->colors, sizeof(LONG) * COLORS_MAX);
3461 if (WinDlgBox(HWND_DESKTOP,
3462 hwnd,
3463 ColorDlgProc,
3464 FM3ModHandle, COLOR_FRAME, (PVOID) & co)) {
3465 memcpy(Colors, ad->colors, sizeof(LONG) * COLORS_MAX);
3466 PrfWriteProfileData(fmprof,
3467 appname,
3468 "Viewer.Colors",
3469 &ad->colors, sizeof(LONG) * COLORS_MAX);
3470 WinInvalidateRect(hwnd, NULL, FALSE);
3471 WinInvalidateRect(ad->hwndStatus1, NULL, FALSE);
3472 WinInvalidateRect(ad->hwndStatus2, NULL, FALSE);
3473 WinInvalidateRect(ad->hwndStatus3, NULL, FALSE);
3474 }
3475 }
3476 break;
3477
3478 case IDM_NEXTWINDOW:
3479 case IDM_PREVWINDOW:
3480 {
3481 SHORT sSelect;
3482
3483 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
3484 NEWVIEW_LISTBOX,
3485 LM_QUERYITEMCOUNT,
3486 MPVOID, MPVOID);
3487 if (sSelect) {
3488 if (!ad->clientfocused)
3489 WinSetFocus(HWND_DESKTOP, hwnd);
3490 else
3491 WinSetFocus(HWND_DESKTOP,
3492 WinWindowFromID(ad->hwndFrame, NEWVIEW_LISTBOX));
3493 }
3494 else
3495 WinSetFocus(HWND_DESKTOP, hwnd);
3496 }
3497 break;
3498
3499 case IDM_FINDFIRST:
3500 {
3501 APIRET rc;
3502
3503 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3504 if (!rc) {
3505 if (!ad->busy && ad->text && ad->numlines && ad->markedlines) {
3506
3507 ULONG numlines;
3508 RECTL Rectl;
3509 static char test[SEARCHSTRINGLEN];
3510
3511 WinQueryWindowRect(hwnd, &Rectl);
3512 numlines = NumLines(&Rectl, ad);
3513 if (!numlines)
3514 break;
3515 strcpy(test, ad->searchtext);
3516 if (WinDlgBox(HWND_DESKTOP, hwnd, FindStrDlgProc, FM3ModHandle,
3517 NEWFIND_FRAME, (PVOID) & hwnd)) {
3518 if (*ad->searchtext && strcmp(test, ad->searchtext))
3519 PrfWriteProfileString(fmprof,
3520 appname,
3521 "Viewer.Searchtext",
3522 (PVOID) ad->searchtext);
3523 if (_beginthread(SearchThread, NULL, 524288, (PVOID) hwnd) ==
3524 -1)
3525 Runtime_Error(pszSrcFile, __LINE__,
3526 GetPString(IDS_COULDNTSTARTTHREADTEXT));
3527 }
3528 }
3529 DosReleaseMutexSem(ad->ScanSem);
3530 }
3531 }
3532 break;
3533
3534 case IDM_PREVSELECTED:
3535 case IDM_NEXTSELECTED:
3536 case IDM_FINDPREV:
3537 case IDM_FINDNEXT:
3538 {
3539 APIRET rc;
3540
3541 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3542 if (!rc) {
3543 if (!ad->busy && ad->text && ad->markedlines) {
3544
3545 RECTL Rectl;
3546 register ULONG x;
3547 ULONG numlines;
3548 CHAR markedwith;
3549
3550 markedwith = (SHORT1FROMMP(mp1) == IDM_FINDNEXT ||
3551 SHORT1FROMMP(mp1) == IDM_FINDPREV) ?
3552 VF_FOUND : VF_SELECTED;
3553 WinQueryWindowRect(hwnd, &Rectl);
3554 numlines = NumLines(&Rectl, ad);
3555 if (!numlines)
3556 break;
3557 WinSetPointer(HWND_DESKTOP, hptrBusy);
3558 if (SHORT1FROMMP(mp1) == IDM_PREVSELECTED ||
3559 SHORT1FROMMP(mp1) == IDM_FINDPREV) {
3560 for (x = ad->cursored - 2; x < ULONG_MAX - 1; x--) {
3561 if (ad->markedlines[x] & markedwith) {
3562 ad->topline = x + 1;
3563 if (ad->numlines - ad->topline < numlines)
3564 ad->topline = ad->numlines - numlines;
3565 ad->cursored = x + 1;
3566 WinInvalidateRect(hwnd, NULL, FALSE);
3567 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3568 break;
3569 }
3570 }
3571 }
3572 else {
3573 for (x = ad->cursored; x < ad->numlines; x++) {
3574 if (ad->markedlines[x] & markedwith) {
3575 ad->topline = x + 1;
3576 if (ad->numlines - ad->topline < numlines)
3577 ad->topline = ad->numlines - numlines;
3578 ad->cursored = x + 1;
3579 WinInvalidateRect(hwnd, NULL, FALSE);
3580 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3581 break;
3582 }
3583 }
3584 }
3585 WinSetPointer(HWND_DESKTOP, hptrArrow);
3586 if (x >= ad->numlines)
3587 DosBeep(50, 100);
3588 }
3589 DosReleaseMutexSem(ad->ScanSem);
3590 }
3591 }
3592 break;
3593
3594 case IDM_SELECTFOUND:
3595 case IDM_DESELECTFOUND:
3596 {
3597 APIRET rc;
3598
3599 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3600 if (!rc) {
3601 if (!ad->busy && ad->text && ad->markedlines) {
3602
3603 RECTL Rectl;
3604 register ULONG x;
3605 ULONG numlines;
3606
3607 WinQueryWindowRect(hwnd, &Rectl);
3608 numlines = NumLines(&Rectl, ad);
3609 if (!numlines)
3610 break;
3611 WinSetPointer(HWND_DESKTOP, hptrBusy);
3612 for (x = 0; x < ad->numlines; x++) {
3613 if (SHORT1FROMMP(mp1) == IDM_SELECTFOUND) {
3614 if ((ad->markedlines[x] & VF_FOUND) &&
3615 !(ad->markedlines[x] & VF_SELECTED)) {
3616 ad->markedlines[x] |= VF_SELECTED;
3617 ad->selected++;
3618 }
3619 }
3620 else {
3621 if ((ad->markedlines[x] & VF_FOUND) &&
3622 (ad->markedlines[x] & VF_SELECTED)) {
3623 ad->markedlines[x] &= (~VF_SELECTED);
3624 ad->selected--;
3625 }
3626 }
3627 }
3628 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3629 WinSetPointer(HWND_DESKTOP, hptrArrow);
3630 WinInvalidateRect(hwnd, NULL, FALSE);
3631 }
3632 DosReleaseMutexSem(ad->ScanSem);
3633 }
3634 }
3635 break;
3636
3637 case IDM_GOTOLINE:
3638 case IDM_GOTOOFFSET:
3639 {
3640 APIRET rc;
3641
3642 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3643 if (!rc) {
3644 if (!ad->busy && ad->numlines) {
3645
3646 ULONG numlines, linenum;
3647 CHAR s[34], ss[134];
3648 STRINGINPARMS sip;
3649 RECTL Rectl;
3650 register ULONG x;
3651
3652 WinQueryWindowRect(hwnd, &Rectl);
3653 numlines = NumLines(&Rectl, ad);
3654 if (!numlines)
3655 break;
3656 if (ad->numlines <= numlines) {
3657 DosBeep(500, 100);
3658 break;
3659 }
3660 sip.help = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3661 GetPString(IDS_NVLINEJUMPTEXT) : GetPString(IDS_NVBYTEJUMPTEXT);
3662 sip.ret = s;
3663 *s = 0;
3664 sip.prompt = ss;
3665 sip.inputlen = 34;
3666 sip.title = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3667 GetPString(IDS_NVLINEJUMPTITLETEXT) :
3668 GetPString(IDS_NVBYTEJUMPTITLETEXT);
3669 sprintf(sip.prompt,
3670 GetPString(IDS_NVJUMPTEXT),
3671 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3672 GetPString(IDS_LINETEXT) :
3673 GetPString(IDS_OFFSETTEXT),
3674 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3675 1 :
3676 0,
3677 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3678 ad->numlines : ad->textsize - 1);
3679 WinDlgBox(HWND_DESKTOP,
3680 hwnd, InputDlgProc, FM3ModHandle, STR_FRAME, &sip);
3681 if (*s) {
3682 s[33] = 0;
3683 linenum = atol(s);
3684 switch (SHORT1FROMMP(mp1)) {
3685 case IDM_GOTOLINE:
3686 if (linenum > 0 && linenum <= ad->numlines) {
3687 ad->topline = linenum;
3688 ad->cursored = ad->topline;
3689 if (ad->numlines - ad->topline < numlines)
3690 ad->topline = (ad->numlines - numlines) + 1;
3691 WinInvalidateRect(hwnd, NULL, FALSE);
3692 }
3693 break;
3694 case IDM_GOTOOFFSET:
3695 if (linenum < ad->textsize) {
3696 if (ad->hex)
3697 ad->topline = (linenum / 16) + 1;
3698 else if (ad->lines) {
3699 ad->topline = (ULONG) - 1;
3700 for (x = 0; x < ad->numlines; x++) {
3701 if (ad->lines[x] > ad->text + linenum) {
3702 ad->topline = x + 1;
3703 break;
3704 }
3705 }
3706 if (ad->topline == (ULONG) - 1)
3707 ad->topline = ad->numlines;
3708 }
3709 ad->cursored = ad->topline;
3710 if (ad->numlines - ad->topline < numlines)
3711 ad->topline = (ad->numlines - numlines) + 1;
3712 WinInvalidateRect(hwnd, NULL, FALSE);
3713 }
3714 break;
3715 }
3716 }
3717 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3718 }
3719 DosReleaseMutexSem(ad->ScanSem);
3720 }
3721 }
3722 break;
3723
3724 case IDM_CODEPAGE:
3725 {
3726 INT cp;
3727
3728 cp = PickCodepage(hwnd);
3729 if (cp != -1) {
3730 ad->fattrs.usCodePage = (USHORT) cp;
3731 Codepage = ad->fattrs.usCodePage;
3732 PrfWriteProfileData(fmprof,
3733 appname,
3734 "Viewer.Codepage",
3735 &ad->fattrs.usCodePage, sizeof(USHORT));
3736 GpiDeleteSetId(ad->hps, FIXED_FONT_LCID);
3737 GpiAssociate(ad->hps, 0);
3738 GpiDestroyPS(ad->hps);
3739 ad->hps = InitWindow(hwnd);
3740 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3741 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3742 WinInvalidateRect(hwnd, NULL, FALSE);
3743 }
3744 }
3745 break;
3746
3747 case IDM_SAVETOLIST2:
3748 case IDM_SAVETOCLIP2:
3749 case IDM_APPENDTOCLIP2:
3750 case IDM_SAVETOLIST:
3751 case IDM_SAVETOCLIP:
3752 case IDM_APPENDTOCLIP:
3753 {
3754 APIRET rc;
3755
3756 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3757 if (!rc) {
3758 if (!ad->busy) {
3759 ad->cliptype = SHORT1FROMMP(mp1);
3760 if (_beginthread(ClipboardThread, NULL, 524288, (PVOID) hwnd) ==
3761 -1)
3762 Runtime_Error(pszSrcFile, __LINE__,
3763 GetPString(IDS_COULDNTSTARTTHREADTEXT));
3764 }
3765 DosReleaseMutexSem(ad->ScanSem);
3766 }
3767 }
3768 break;
3769
3770 case IDM_SELECTALL:
3771 case IDM_DESELECTALL:
3772 case IDM_INVERT:
3773 {
3774 APIRET rc;
3775
3776 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3777 if (!rc) {
3778 if (!ad->busy && ad->markedlines) {
3779
3780 register ULONG x;
3781
3782 for (x = 0; x < ad->numlines; x++) {
3783 switch (SHORT1FROMMP(mp1)) {
3784 case IDM_SELECTALL:
3785 if (!(ad->markedlines[x] & VF_SELECTED)) {
3786 ad->markedlines[x] |= VF_SELECTED;
3787 ad->selected++;
3788 }
3789 break;
3790 case IDM_DESELECTALL:
3791 if (ad->markedlines[x] & VF_SELECTED) {
3792 ad->markedlines[x] &= (~VF_SELECTED);
3793 ad->selected--;
3794 }
3795 break;
3796 case IDM_INVERT:
3797 if (ad->markedlines[x] & VF_SELECTED) {
3798 ad->markedlines[x] &= (~VF_SELECTED);
3799 ad->selected--;
3800 }
3801 else {
3802 ad->markedlines[x] |= VF_SELECTED;
3803 ad->selected++;
3804 }
3805 break;
3806 }
3807 }
3808 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3809 WinInvalidateRect(hwnd, NULL, FALSE);
3810 }
3811 DosReleaseMutexSem(ad->ScanSem);
3812 }
3813 }
3814 break;
3815
3816 case IDM_WRAP:
3817 {
3818 APIRET rc;
3819
3820 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3821 if (!rc) {
3822 if (!ad->busy) {
3823 ad->wrapon = ad->wrapon ? FALSE : TRUE;
3824 WrapOn = ad->wrapon;
3825 PrfWriteProfileData(fmprof, appname, "Viewer.WrapOn",
3826 &ad->wrapon, sizeof(BOOL));
3827 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3828 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3829 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3830 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3831 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
3832 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
3833 MPVOID, MPVOID);
3834 ad->oldwidth = -1;
3835 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3836 MPFROM2SHORT(1, 1), MPVOID);
3837 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3838 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3839 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3840 MPFROM2SHORT(1, 1), MPVOID);
3841 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3842 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3843 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
3844 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3845 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3846 NEWVIEW_DRAG), NULL, FALSE);
3847 //WinInvalidateRect(ad->hhscroll, NULL, FALSE);
3848 }
3849 DosReleaseMutexSem(ad->ScanSem);
3850 }
3851 }
3852 break;
3853
3854 case IDM_HEXMODE:
3855 {
3856 APIRET rc;
3857
3858 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3859 if (!rc) {
3860 if (!ad->busy) {
3861 ad->hex = (ad->hex) ? FALSE : TRUE;
3862 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3863 IDM_NEXTBLANKLINE), !ad->hex);
3864 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3865 IDM_PREVBLANKLINE), !ad->hex);
3866 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3867 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3868 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3869 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3870 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
3871 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
3872 MPVOID, MPVOID);
3873 ad->oldwidth = -1;
3874 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3875 MPFROM2SHORT(1, 1), MPVOID);
3876 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3877 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3878 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3879 MPFROM2SHORT(1, 1), MPVOID);
3880 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3881 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3882 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
3883 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3884 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3885 NEWVIEW_DRAG), NULL, FALSE);
3886 //WinInvalidateRect(ad->hhscroll, NULL, FALSE);
3887 }
3888 DosReleaseMutexSem(ad->ScanSem);
3889 }
3890 }
3891 break;
3892
3893 case IDM_FONTPALETTE:
3894 {
3895 APIRET rc;
3896
3897 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3898 if (!rc) {
3899 SetMLEFont(hwnd, &ad->fattrs, 11);
3900 PrfWriteProfileData(fmprof, appname, "Viewer.Fattrs",
3901 &ad->fattrs, sizeof(FATTRS));
3902 Fattrs = ad->fattrs;
3903 GpiDeleteSetId(ad->hps, FIXED_FONT_LCID);
3904 GpiAssociate(ad->hps, 0);
3905 GpiDestroyPS(ad->hps);
3906 ad->hps = InitWindow(hwnd);
3907 DosReleaseMutexSem(ad->ScanSem);
3908 WinSendMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3909 WinInvalidateRect(hwnd, NULL, FALSE);
3910 }
3911 }
3912 break;
3913
3914 case IDM_HELP:
3915 if (hwndHelp)
3916 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
3917 MPFROM2SHORT(HELP_NEWVIEW, 0), MPFROMSHORT(HM_RESOURCEID));
3918 break;
3919 }
3920 return 0;
3921
3922 case WM_SETFOCUS:
3923 if (mp2)
3924 WinSendMsg(hwnd, UM_SETUP5, MPVOID, MPVOID);
3925 if (mp2 && ad && ad->needrefreshing && !ad->stopflag &&
3926 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
3927 ad->needrefreshing = FALSE;
3928 DosReleaseMutexSem(ad->ScanSem);
3929 WinInvalidateRect(hwnd, NULL, TRUE);
3930 }
3931 break;
3932
3933 case WM_SIZE:
3934 if (SHORT1FROMMP(mp2) && SHORT2FROMMP(mp2)) {
3935 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3936 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3937 }
3938 break;
3939
3940 case WM_SAVEAPPLICATION:
3941 if (ad && ParentIsDesktop(hwnd, ad->hwndParent)) {
3942
3943 SWP swp;
3944
3945 WinQueryWindowPos(ad->hwndFrame, &swp);
3946 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
3947 PrfWriteProfileData(fmprof,
3948 appname, "NewViewSizePos", &swp, sizeof(swp));
3949 }
3950 break;
3951
3952 case WM_CLOSE:
3953 if (ad)
3954 ad->stopflag = 1;
3955 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
3956 return 0;
3957
3958 case WM_DESTROY:
3959 {
3960 BOOL dontclose = FALSE;
3961 HWND hwndRestore = (HWND) 0;
3962
3963 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER5);
3964 if (ad) {
3965 ad->stopflag = 1;
3966 if (ad->ScanSem) {
3967 DosRequestMutexSem(ad->ScanSem, 15000);
3968 DosCloseMutexSem(ad->ScanSem);
3969 }
3970 if (ad->busy)
3971 DosSleep(100); //05 Aug 07 GKY 128
3972 if (ad->hps) {
3973 GpiDeleteSetId(ad->hps, FIXED_FONT_LCID);
3974 GpiAssociate(ad->hps, 0);
3975 GpiDestroyPS(ad->hps);
3976 }
3977 hwndRestore = ad->hwndRestore;
3978 dontclose = ((ad->flags & 4) != 0) ? TRUE : FALSE;
3979 FreeViewerMem(hwnd);
3980 WinSetWindowPtr(hwnd, QWL_USER, NULL);
3981 xfree(ad, pszSrcFile, __LINE__);
3982# ifdef FORTIFY
3983 Fortify_LeaveScope(pszSrcFile, __LINE__);
3984# endif
3985 }
3986 if (hwndRestore && hwndRestore != HWND_DESKTOP) {
3987
3988 ULONG fl = SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER;
3989 SWP swp;
3990
3991 if (WinQueryWindowPos(hwndRestore, &swp)) {
3992 if (!(swp.fl & SWP_MAXIMIZE))
3993 fl |= SWP_RESTORE;
3994 WinSetWindowPos(hwndRestore, HWND_TOP, 0, 0, 0, 0, fl);
3995 }
3996 }
3997 if (!dontclose &&
3998 ParentIsDesktop(hwnd, WinQueryWindow(WinQueryWindow(hwnd,
3999 QW_PARENT),
4000 QW_PARENT))) {
4001 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
4002 DosExit(EXIT_PROCESS, 1);
4003 }
4004 }
4005 break;
4006 }
4007
4008 return WinDefWindowProc(hwnd, msg, mp1, mp2);
4009}
4010
4011HWND StartViewer(HWND hwndParent, USHORT flags, CHAR * filename,
4012 HWND hwndRestore)
4013{
4014 HWND hwndFrame = (HWND) 0, hwndClient;
4015 VIEWDATA *ad;
4016 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
4017 FCF_SIZEBORDER | FCF_MINMAX |
4018 FCF_NOBYTEALIGN | FCF_VERTSCROLL |
4019 FCF_MENU | FCF_ICON | FCF_ACCELTABLE | FCF_HORZSCROLL;
4020
4021 if (strcmp(realappname, FM3Str))
4022 hwndParent = HWND_DESKTOP;
4023 if (ParentIsDesktop(hwndParent, hwndParent))
4024 FrameFlags |= FCF_TASKLIST;
4025 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"\"%s\"\r\rparent %s desktop",filename,(ParentIsDesktop(hwndParent,hwndParent)) ? "is" : "isn't");
4026 hwndFrame = WinCreateStdWindow(hwndParent,
4027 0,
4028 &FrameFlags,
4029 WC_NEWVIEW,
4030 GetPString(IDS_FM2VIEWERTITLETEXT),
4031 fwsAnimate,
4032 FM3ModHandle, NEWVIEW_FRAME, &hwndClient);
4033 if (hwndFrame) {
4034
4035 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
4036
4037 if (!fToolbar && hwndMenu) {
4038 WinSendMsg(hwndMenu, MM_DELETEITEM,
4039 MPFROM2SHORT(IDM_FINDFIRST, FALSE), MPVOID);
4040 WinSendMsg(hwndMenu, MM_DELETEITEM,
4041 MPFROM2SHORT(IDM_FINDNEXT, FALSE), MPVOID);
4042 WinSendMsg(hwndMenu, MM_DELETEITEM,
4043 MPFROM2SHORT(IDM_FINDPREV, FALSE), MPVOID);
4044 WinSendMsg(hwndMenu, MM_DELETEITEM,
4045 MPFROM2SHORT(IDM_SAVETOCLIP, FALSE), MPVOID);
4046 }
4047 ad = xmallocz(sizeof(VIEWDATA), pszSrcFile, __LINE__);
4048 if (!ad) {
4049 WinDestroyWindow(hwndFrame);
4050 hwndFrame = (HWND)0;
4051 }
4052 else {
4053 ad->size = sizeof(VIEWDATA);
4054 ad->stopflag = 0;
4055 ad->multiplier = 1;
4056 ad->hwndRestore = hwndRestore;
4057 ad->hwndFrame = hwndFrame;
4058 ad->hwndParent = hwndParent;
4059 ad->clientfocused = TRUE;
4060 ad->oldwidth = -1;
4061 strcpy(ad->filename, filename);
4062 ad->flags = flags;
4063 if (ad->flags & 16)
4064 ad->hex = TRUE;
4065 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
4066 if (Firsttime) {
4067
4068 ULONG size;
4069
4070 size = sizeof(BOOL);
4071 PrfQueryProfileData(fmprof, appname, "Viewer.Sensitive",
4072 (PVOID) & Sensitive, &size);
4073 size = sizeof(USHORT);
4074 PrfQueryProfileData(fmprof, appname, "Viewer.Codepage",
4075 (PVOID) & Codepage, &size);
4076 size = sizeof(BOOL);
4077 PrfQueryProfileData(fmprof, appname, "Viewer.LiteralSearch",
4078 (PVOID) & LiteralSearch, &size);
4079 size = sizeof(BOOL);
4080 PrfQueryProfileData(fmprof, appname, "Viewer.AlsoSelect",
4081 (PVOID) & AlsoSelect, &size);
4082 size = sizeof(BOOL);
4083 PrfQueryProfileData(fmprof, appname, "Viewer.WrapOn",
4084 (PVOID) & WrapOn, &size);
4085 size = sizeof(BOOL);
4086 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreFTP",
4087 (PVOID) & IgnoreFTP, &size);
4088 size = sizeof(BOOL);
4089 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
4090 (PVOID) & IgnoreHTTP, &size);
4091 size = sizeof(BOOL);
4092 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreMail",
4093 (PVOID) & IgnoreMail, &size);
4094 memset(&Fattrs, 0, sizeof(FATTRS));
4095 size = sizeof(FATTRS);
4096 Fattrs.usRecordLength = sizeof(FATTRS);
4097 Fattrs.lMaxBaselineExt = 16;
4098 Fattrs.lAveCharWidth = 8;
4099 Fattrs.usCodePage = Codepage;
4100 strcpy(Fattrs.szFacename, GetPString(IDS_SYSMONOTEXT));
4101 PrfQueryProfileData(fmprof, appname, "Viewer.Fattrs",
4102 (PVOID) & Fattrs, &size);
4103 size = sizeof(LONG) * COLORS_MAX;
4104 PrfQueryProfileData(fmprof, appname, "Viewer.Colors",
4105 (PVOID) Colors, &size);
4106 Firsttime = FALSE;
4107 }
4108 {
4109 ULONG size = sizeof(ad->searchtext);
4110
4111 PrfQueryProfileData(fmprof, appname, "Viewer.Searchtext",
4112 (PVOID) ad->searchtext, &size);
4113 ad->searchtext[sizeof(ad->searchtext) - 1] = 0;
4114 }
4115 ad->sensitive = Sensitive;
4116 ad->literalsearch = LiteralSearch;
4117 ad->fattrs = Fattrs;
4118 ad->alsoselect = AlsoSelect;
4119 ad->fattrs.usCodePage = Codepage;
4120 ad->wrapon = WrapOn;
4121 ad->ignorehttp = IgnoreHTTP;
4122 ad->ignoreftp = IgnoreFTP;
4123 ad->ignoremail = IgnoreMail;
4124 memcpy(ad->colors, Colors, sizeof(LONG) * COLORS_MAX);
4125 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
4126 if (!WinSendMsg(hwndClient, UM_SETUP, MPVOID, MPVOID))
4127 hwndFrame = (HWND) 0;
4128 else {
4129 //DosSleep(32);
4130 if (!(FrameFlags & FCF_TASKLIST) && !(flags & 2)) {
4131 SWP swp;
4132
4133 FillClient(hwndParent, &swp, NULL, FALSE);
4134 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4135 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_RESTORE |
4136 SWP_ZORDER | SWP_ACTIVATE);
4137 }
4138 else if (FrameFlags & FCF_TASKLIST) {
4139
4140 SWP swp, swpD;
4141 ULONG size = sizeof(swp);
4142 LONG cxScreen, cyScreen;
4143
4144 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
4145 if (PrfQueryProfileData(fmprof,
4146 appname, "NewViewSizePos", &swpD, &size)) {
4147 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
4148 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
4149 if (swp.x + swpD.cx > cxScreen)
4150 swp.x = cxScreen - swpD.cx;
4151 if (swp.y + swpD.cy > cyScreen)
4152 swp.y = cyScreen - swpD.cy;
4153 swp.cx = swpD.cx;
4154 swp.cy = swpD.cy;
4155 }
4156 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4157 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
4158 SWP_ACTIVATE);
4159 }
4160 }
4161 }
4162 }
4163 return hwndFrame;
4164}
4165
4166#pragma alloc_text(NEWVIEW,ViewStatusProc,FreeViewerMem,LoadFileThread)
4167#pragma alloc_text(NEWVIEW,InitWindow,PaintLine,ViewWndProc)
4168#pragma alloc_text(NEWVIEW,ViewFrameWndProc,StartViewer,ReLineThread)
4169#pragma alloc_text(NEWVIEW,BuildAList,SearchThread,ClipboardThread,FindStrDlgProc)
4170#pragma alloc_text(NEWVIEW,BuildAList2,UrlDlgProc)
Note: See TracBrowser for help on using the repository browser.