source: trunk/dll/newview.c

Last change on this file was 1893, checked in by Gregg Young, 5 years ago

Fix some layout and font issues in the viewers

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