source: trunk/dll/newview.c@ 1038

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

More fortify cleanup

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