source: trunk/dll/newview.c@ 1917

Last change on this file since 1917 was 1913, checked in by Gregg Young, 3 weeks ago

Limit the size of files the fast viewer will try to open Ticket #577

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