source: trunk/dll/newview.c@ 1880

Last change on this file since 1880 was 1880, checked in by Gregg Young, 10 years ago

Remove dead code and comments from remaining c files. #if 0 and #if NEVER were not addressed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 119.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: newview.c 1880 2015-10-12 18:26:16Z 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) -
3103 numlines));
3104 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3105 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
3106 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
3107 }
3108 break;
3109 case SB_LINEUP:
3110 if (ad->topline > 1) {
3111
3112 RECTL Rectl, iRectl;
3113
3114 ad->topline--;
3115 if (ad->cursored < ad->topline)
3116 ad->cursored = ad->topline;
3117 else if (ad->cursored + 1 > ad->topline + numlines)
3118 ad->cursored = (ad->topline + numlines) - 1;
3119 if (ad->cursored > ad->numlines)
3120 ad->cursored = ad->numlines;
3121 WinQueryWindowRect(hwnd, &Rectl);
3122 WinScrollWindow(hwnd, 0, -ad->lMaxHeight,
3123 NULL, NULL, NULLHANDLE, &iRectl, 0);
3124 WinFillRect(ad->hps, &iRectl,
3125 standardcolors[ad->colors[COLORS_NORMALBACK]]);
3126 iRectl = Rectl;
3127 iRectl.yTop -= ((numlines * ad->lMaxHeight) + ad->lMaxDescender);
3128 WinFillRect(ad->hps, &iRectl,
3129 standardcolors[ad->colors[COLORS_NORMALBACK]]);
3130 PaintLine(hwnd, ad->hps, ad->topline - 1, ad->topline, &Rectl);
3131 if (ad->cursored != ad->topline)
3132 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &Rectl);
3133 if (ad->cursored != wascursored &&
3134 wascursored >= ad->topline &&
3135 wascursored < ad->topline + numlines)
3136 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
3137 if (numlines >= ad->numlines)
3138 numlines = 0;
3139 if (ad->multiplier)
3140 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3141 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
3142 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
3143 ad->multiplier) -
3144 numlines));
3145 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3146 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
3147 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
3148 }
3149 break;
3150 case SB_SLIDERTRACK:
3151 if ((SHORT1FROMMP(mp2) >= 1) || (SHORT1FROMMP(mp2)) <= ad->numlines) {
3152 ad->topline = (ULONG) SHORT1FROMMP(mp2) * ad->multiplier;
3153 if (ad->topline + numlines > ad->numlines + 1)
3154 ad->topline = (ad->numlines + 1) - numlines;
3155 if (!ad->topline)
3156 ad->topline = 1;
3157 if (ad->cursored < ad->topline)
3158 ad->cursored = ad->topline;
3159 else if (ad->cursored > ad->topline + numlines)
3160 ad->cursored = ad->topline + numlines;
3161 if (ad->cursored > ad->numlines)
3162 ad->cursored = ad->numlines;
3163 WinInvalidateRect(hwnd, NULL, FALSE);
3164 }
3165 else
3166 WinAlarm(HWND_DESKTOP, WA_NOTE);
3167 break;
3168 }
3169 if (ad->cursored != wascursored)
3170 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3171 }
3172 DosReleaseMutexSem(ad->ScanSem);
3173 }
3174 break;
3175
3176 case WM_INITMENU:
3177 switch (SHORT1FROMMP(mp1)) {
3178 case IDM_FILESMENU:
3179 {
3180 APIRET rc;
3181 SHORT sSelect;
3182
3183 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3184 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP, (rc == 0 &&
3185 ad->selected != 0));
3186 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP, (rc == 0 &&
3187 ad->selected != 0));
3188 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST, (rc == 0 &&
3189 ad->selected != 0));
3190 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3191 LM_QUERYITEMCOUNT, MPVOID,
3192 MPVOID);
3193 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP2,
3194 (rc == 0 && sSelect > 0));
3195 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP2,
3196 (rc == 0 && sSelect > 0));
3197 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST2,
3198 (rc == 0 && sSelect > 0));
3199 if (!rc)
3200 DosReleaseMutexSem(ad->ScanSem);
3201 }
3202 break;
3203
3204 case IDM_VIEWSMENU:
3205 {
3206 APIRET rc;
3207
3208 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3209 WinEnableMenuItem((HWND) mp2, IDM_FONTPALETTE, (rc == 0));
3210 WinEnableMenuItem((HWND) mp2, IDM_HEXMODE, (rc == 0));
3211 WinEnableMenuItem((HWND) mp2, IDM_WRAP, (rc == 0));
3212 WinEnableMenuItem((HWND) mp2, IDM_CODEPAGE, (rc == 0));
3213 if (!rc)
3214 DosReleaseMutexSem(ad->ScanSem);
3215 }
3216 WinCheckMenuItem((HWND) mp2, IDM_HEXMODE, ad->hex);
3217 WinCheckMenuItem((HWND) mp2, IDM_WRAP, ad->wrapon);
3218 WinCheckMenuItem((HWND) mp2, IDM_IGNOREFTP, ad->ignoreftp);
3219 WinCheckMenuItem((HWND) mp2, IDM_IGNOREHTTP, ad->ignorehttp);
3220 WinCheckMenuItem((HWND) mp2, IDM_IGNOREMAIL, ad->ignoremail);
3221 break;
3222
3223 case IDM_SEARCHMENU:
3224 {
3225 APIRET rc;
3226
3227 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3228 WinEnableMenuItem((HWND) mp2, IDM_FINDFIRST, (rc == 0 &&
3229 ad->numlines != 0 &&
3230 ad->markedlines));
3231 WinEnableMenuItem((HWND) mp2, IDM_FINDNEXT, (rc == 0 &&
3232 ad->numlines != 0 &&
3233 ad->markedlines &&
3234 ad->found != 0));
3235 WinEnableMenuItem((HWND) mp2, IDM_FINDPREV, (rc == 0 &&
3236 ad->numlines != 0 &&
3237 ad->markedlines &&
3238 ad->found != 0));
3239 WinEnableMenuItem((HWND) mp2, IDM_NEXTBLANKLINE, (rc == 0 &&
3240 ad->numlines != 0 &&
3241 !ad->hex));
3242 WinEnableMenuItem((HWND) mp2, IDM_PREVBLANKLINE, (rc == 0 &&
3243 ad->numlines != 0 &&
3244 !ad->hex));
3245 WinEnableMenuItem((HWND) mp2, IDM_GOTOLINE, (rc == 0 &&
3246 ad->numlines != 0));
3247 WinEnableMenuItem((HWND) mp2, IDM_GOTOOFFSET, (rc == 0 &&
3248 ad->textsize != 0));
3249 if (!rc)
3250 DosReleaseMutexSem(ad->ScanSem);
3251 }
3252 break;
3253
3254 case IDM_SELECTSUBMENU:
3255 {
3256 APIRET rc;
3257
3258 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3259 WinEnableMenuItem((HWND) mp2, IDM_SELECTALL, (rc == 0 &&
3260 ad->numlines != 0 &&
3261 ad->markedlines &&
3262 (ad->selected !=
3263 ad->numlines ||
3264 !ad->selected)));
3265 WinEnableMenuItem((HWND) mp2, IDM_DESELECTALL, (rc == 0 &&
3266 ad->numlines != 0 &&
3267 ad->markedlines &&
3268 ad->selected != 0));
3269 WinEnableMenuItem((HWND) mp2, IDM_DESELECTFOUND, (rc == 0 &&
3270 ad->numlines != 0 &&
3271 ad->markedlines &&
3272 ad->selected != 0 &&
3273 ad->found != 0));
3274 WinEnableMenuItem((HWND) mp2, IDM_SELECTFOUND, (rc == 0 &&
3275 ad->numlines != 0 &&
3276 ad->markedlines &&
3277 ad->found != 0 &&
3278 (ad->numlines !=
3279 ad->selected ||
3280 !ad->selected)));
3281 WinEnableMenuItem((HWND) mp2, IDM_NEXTSELECTED, (rc == 0 &&
3282 ad->numlines != 0 &&
3283 ad->markedlines &&
3284 ad->selected != 0));
3285 WinEnableMenuItem((HWND) mp2, IDM_PREVSELECTED, (rc == 0 &&
3286 ad->numlines != 0 &&
3287 ad->markedlines &&
3288 ad->selected != 0));
3289 WinEnableMenuItem((HWND) mp2, IDM_INVERT, (rc == 0 &&
3290 ad->numlines != 0 &&
3291 ad->markedlines));
3292 if (!rc)
3293 DosReleaseMutexSem(ad->ScanSem);
3294 }
3295 break;
3296 }
3297 break;
3298
3299 case UM_CONTROL:
3300 switch (SHORT1FROMMP(mp1)) {
3301 case NEWVIEW_LISTBOX:
3302 switch (SHORT2FROMMP(mp1)) {
3303 case LN_SETFOCUS:
3304 if (ad) {
3305 if (!ad->clientfocused) {
3306 PostMsg(hwnd,
3307 WM_COMMAND, MPFROM2SHORT(IDM_NEXTWINDOW, 0), MPVOID);
3308 break;
3309 }
3310 ad->clientfocused = FALSE;
3311 }
3312 PostMsg(hwnd,
3313 UM_CONTROL, MPFROM2SHORT(NEWVIEW_LISTBOX, LN_SELECT), MPVOID);
3314 break;
3315 case LN_KILLFOCUS:
3316 if (ad) {
3317 ad->clientfocused = TRUE;
3318 WinSetFocus(HWND_DESKTOP, hwnd);
3319 }
3320 break;
3321 case LN_SELECT:
3322 if (ad && !ad->dummy) {
3323
3324 ULONG linenum, numlines;
3325 SHORT sSelect;
3326 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
3327 SHORT1FROMMP(mp1));
3328 RECTL Rectl;
3329
3330 sSelect = (SHORT) WinSendMsg(hwndUL,
3331 LM_QUERYSELECTION,
3332 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3333 if (sSelect >= 0) {
3334 linenum = (ULONG) WinSendMsg(hwndUL,
3335 LM_QUERYITEMHANDLE,
3336 MPFROM2SHORT(sSelect, 0), MPVOID);
3337 if (ad->topline != linenum + 1 && linenum < ad->numlines) {
3338 WinQueryWindowRect(hwnd, &Rectl);
3339 numlines = NumLines(&Rectl, ad);
3340 ad->topline = linenum + 1;
3341 if (ad->numlines - ad->topline < numlines)
3342 ad->topline = ad->numlines - numlines;
3343 ad->cursored = linenum + 1;
3344 WinInvalidateRect(hwnd, NULL, FALSE);
3345 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3346 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3347 }
3348 }
3349 else
3350 PostMsg(hwndUL, LM_SELECTITEM, MPFROM2SHORT(0, 0),
3351 MPFROM2SHORT(TRUE, 0));
3352 }
3353 break;
3354
3355 case LN_ENTER:
3356 if (ad) {
3357
3358 SHORT sSelect;
3359 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
3360 SHORT1FROMMP(mp1));
3361
3362 sSelect = (SHORT) WinSendMsg(hwndUL,
3363 LM_QUERYSELECTION,
3364 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3365 if (sSelect >= 0) {
3366 ad->dummy = TRUE;
3367 WinSendMsg(hwndUL, LM_DELETEITEM,
3368 MPFROM2SHORT(sSelect, 0), MPVOID);
3369 ad->dummy = FALSE;
3370 sSelect = (SHORT) WinSendMsg(hwndUL,
3371 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
3372 if (sSelect <= 0) {
3373 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
3374 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3375 WinSetFocus(HWND_DESKTOP, hwnd);
3376 }
3377 }
3378 }
3379 break;
3380
3381 default:
3382 break;
3383 }
3384 break;
3385
3386 default:
3387 break;
3388 }
3389 return 0;
3390
3391 case WM_COMMAND:
3392 switch (SHORT1FROMMP(mp1)) {
3393 case IDM_EDIT:
3394 if (*editor) {
3395
3396 CHAR *dummy[2];
3397
3398 dummy[0] = ad->filename;
3399 dummy[1] = NULL;
3400 ExecOnList(hwnd, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
3401 pszSrcFile, __LINE__);
3402 }
3403 else
3404 StartMLEEditor(ad->hwndParent, 4, ad->filename, ad->hwndFrame);
3405 ad->hwndRestore = (HWND) 0;
3406 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
3407 break;
3408
3409 case IDM_IGNOREFTP:
3410 ad->ignoreftp = (ad->ignoreftp) ? FALSE : TRUE;
3411 ad->ftpin = FALSE;
3412 if (ad->text && (*ftprun || fFtpRunWPSDefault) &&
3413 !ad->ignoreftp && strstr(ad->text, "ftp://"))
3414 ad->ftpin = TRUE;
3415 IgnoreFTP = ad->ignoreftp;
3416 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreFTP",
3417 &ad->ignoreftp, sizeof(BOOL));
3418 WinInvalidateRect(hwnd, NULL, FALSE);
3419 break;
3420
3421 case IDM_IGNOREHTTP:
3422 ad->ignorehttp = (ad->ignorehttp) ? FALSE : TRUE;
3423 ad->httpin = FALSE;
3424 if (ad->text && (*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
3425 (strstr(ad->text, "http://") || strstr(ad->text, "https://")))
3426 ad->httpin = TRUE;
3427 IgnoreHTTP = ad->ignorehttp;
3428 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
3429 &ad->ignorehttp, sizeof(BOOL));
3430 WinInvalidateRect(hwnd, NULL, FALSE);
3431 break;
3432
3433 case IDM_IGNOREMAIL:
3434 ad->ignoremail = (ad->ignoremail) ? FALSE : TRUE;
3435 ad->mailin = FALSE;
3436 if (ad->text && *mailrun && !ad->ignoremail &&
3437 isemailaddress(ad->text))
3438 ad->mailin = TRUE;
3439 IgnoreMail = ad->ignoremail;
3440 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreMail",
3441 &ad->ignoremail, sizeof(BOOL));
3442 WinInvalidateRect(hwnd, NULL, FALSE);
3443 break;
3444
3445 case IDM_PREVBLANKLINE:
3446 if (!ad->hex && ad->lines) {
3447
3448 ULONG x;
3449
3450 x = ad->cursored - 2;
3451 if (x >= ad->numlines)
3452 x = 0;
3453 while (x < ad->numlines &&
3454 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3455 x--;
3456 if (x >= ad->numlines)
3457 x = 0;
3458 for (; x < ad->numlines; x--) {
3459 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3460 if (x < ad->numlines - 1)
3461 x++;
3462 break;
3463 }
3464 }
3465 if (x < ad->numlines) {
3466 ad->topline = ad->cursored = x;
3467 WinInvalidateRect(hwnd, NULL, FALSE);
3468 }
3469 }
3470 break;
3471
3472 case IDM_NEXTBLANKLINE:
3473 if (!ad->hex && ad->lines) {
3474
3475 ULONG x;
3476
3477 x = ad->cursored;
3478 while (x < ad->numlines &&
3479 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3480 x++;
3481 for (; x < ad->numlines; x++) {
3482 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3483 if (x < ad->numlines - 1)
3484 x++;
3485 break;
3486 }
3487 }
3488 if (x < ad->numlines) {
3489 while (x < ad->numlines &&
3490 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
3491 x++;
3492 if (x < ad->numlines) {
3493 ad->topline = ad->cursored = x;
3494 WinInvalidateRect(hwnd, NULL, FALSE);
3495 }
3496 }
3497 }
3498 break;
3499
3500 case IDM_VIEW:
3501 case IDM_OBJECT:
3502 if (!ad->hex && ad->lines) {
3503
3504 CHAR line[CCHMAXPATH], filename[CCHMAXPATH], *p;
3505
3506 strncpy(line, ad->lines[ad->cursored - 1], CCHMAXPATH);
3507 line[CCHMAXPATH - 1] = 0;
3508 chop_at_crnl(line);
3509 if (*line == '\"') {
3510 memmove(line, line + 1, strlen(line));
3511 p = strchr(line, '\"');
3512 lstrip(line);
3513 if (p)
3514 *p = 0;
3515 rstrip(line);
3516 }
3517 else {
3518 lstrip(line);
3519 p = strchr(line, ' ');
3520 if (p)
3521 *p = 0;
3522 rstrip(line);
3523 }
3524 if (!strchr(line, '\\') && !strchr(line, '/') && !strchr(line, ':')) {
3525 strcpy(filename, ad->filename);
3526 p = strrchr(filename, '\\');
3527 if (p)
3528 p++;
3529 else
3530 p = filename;
3531 strcpy(p, line);
3532 }
3533 else
3534 strcpy(filename, line);
3535 MakeFullName(filename);
3536 if (*filename && IsFile(filename) == 1) {
3537 if (SHORT1FROMMP(mp1) == IDM_OBJECT)
3538 OpenObject(filename, Default, ad->hwndFrame);
3539 else
3540 DefaultView(hwnd, ad->hwndFrame, HWND_DESKTOP, NULL, 0, filename);
3541 }
3542 }
3543 break;
3544
3545 case IDM_COLORPALETTE:
3546 {
3547 COLORS co;
3548 LONG temp[COLORS_MAX];
3549
3550 memset(&co, 0, sizeof(co));
3551 co.size = sizeof(co);
3552 co.numcolors = COLORS_MAX;
3553 co.colors = ad->colors;
3554 co.descriptions = IDS_NVCOLORS1TEXT;
3555 co.origs = temp;
3556 co.prompt = IDS_NVCOLORSPROMPTTEXT;
3557 memcpy(temp, ad->colors, sizeof(LONG) * COLORS_MAX);
3558 if (WinDlgBox(HWND_DESKTOP,
3559 hwnd,
3560 ColorDlgProc,
3561 FM3ModHandle, COLOR_FRAME, (PVOID) & co)) {
3562 memcpy(Colors, ad->colors, sizeof(LONG) * COLORS_MAX);
3563 PrfWriteProfileData(fmprof,
3564 appname,
3565 "Viewer.Colors",
3566 &ad->colors, sizeof(LONG) * COLORS_MAX);
3567 WinInvalidateRect(hwnd, NULL, FALSE);
3568 WinInvalidateRect(ad->hwndStatus1, NULL, FALSE);
3569 WinInvalidateRect(ad->hwndStatus2, NULL, FALSE);
3570 WinInvalidateRect(ad->hwndStatus3, NULL, FALSE);
3571 }
3572 }
3573 break;
3574
3575 case IDM_NEXTWINDOW:
3576 case IDM_PREVWINDOW:
3577 {
3578 SHORT sSelect;
3579
3580 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
3581 NEWVIEW_LISTBOX,
3582 LM_QUERYITEMCOUNT,
3583 MPVOID, MPVOID);
3584 if (sSelect) {
3585 if (!ad->clientfocused)
3586 WinSetFocus(HWND_DESKTOP, hwnd);
3587 else
3588 WinSetFocus(HWND_DESKTOP,
3589 WinWindowFromID(ad->hwndFrame, NEWVIEW_LISTBOX));
3590 }
3591 else
3592 WinSetFocus(HWND_DESKTOP, hwnd);
3593 }
3594 break;
3595
3596 case IDM_FINDFIRST:
3597 {
3598 APIRET rc;
3599
3600 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3601 if (!rc) {
3602 if (!ad->busy && ad->text && ad->numlines && ad->markedlines) {
3603
3604 ULONG numlines;
3605 RECTL Rectl;
3606 static char test[SEARCHSTRINGLEN];
3607
3608 WinQueryWindowRect(hwnd, &Rectl);
3609 numlines = NumLines(&Rectl, ad);
3610 if (!numlines)
3611 break;
3612 strcpy(test, ad->searchtext);
3613 if (WinDlgBox(HWND_DESKTOP, hwnd, FindStrDlgProc, FM3ModHandle,
3614 NEWFIND_FRAME, (PVOID) & hwnd)) {
3615 if (*ad->searchtext && strcmp(test, ad->searchtext))
3616 PrfWriteProfileString(fmprof,
3617 appname,
3618 "Viewer.Searchtext",
3619 (PVOID) ad->searchtext);
3620 xbeginthread(SearchThread,
3621 524288,
3622 (PVOID)hwnd,
3623 pszSrcFile,
3624 __LINE__);
3625 }
3626 }
3627 DosReleaseMutexSem(ad->ScanSem);
3628 }
3629 }
3630 break;
3631
3632 case IDM_PREVSELECTED:
3633 case IDM_NEXTSELECTED:
3634 case IDM_FINDPREV:
3635 case IDM_FINDNEXT:
3636 {
3637 APIRET rc;
3638
3639 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3640 if (!rc) {
3641 if (!ad->busy && ad->text && ad->markedlines) {
3642
3643 RECTL Rectl;
3644 register ULONG x;
3645 ULONG numlines;
3646 CHAR markedwith;
3647
3648 markedwith = (SHORT1FROMMP(mp1) == IDM_FINDNEXT ||
3649 SHORT1FROMMP(mp1) == IDM_FINDPREV) ?
3650 VF_FOUND : VF_SELECTED;
3651 WinQueryWindowRect(hwnd, &Rectl);
3652 numlines = NumLines(&Rectl, ad);
3653 if (!numlines)
3654 break;
3655 WinSetPointer(HWND_DESKTOP, hptrBusy);
3656 if (SHORT1FROMMP(mp1) == IDM_PREVSELECTED ||
3657 SHORT1FROMMP(mp1) == IDM_FINDPREV) {
3658 for (x = ad->cursored - 2; x < ULONG_MAX - 1; x--) {
3659 if (ad->markedlines[x] & markedwith) {
3660 ad->topline = x + 1;
3661 if (ad->numlines - ad->topline < numlines)
3662 ad->topline = ad->numlines - numlines;
3663 ad->cursored = x + 1;
3664 WinInvalidateRect(hwnd, NULL, FALSE);
3665 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3666 break;
3667 }
3668 }
3669 }
3670 else {
3671 for (x = ad->cursored; x < ad->numlines; x++) {
3672 if (ad->markedlines[x] & markedwith) {
3673 ad->topline = x + 1;
3674 if (ad->numlines - ad->topline < numlines)
3675 ad->topline = ad->numlines - numlines;
3676 ad->cursored = x + 1;
3677 WinInvalidateRect(hwnd, NULL, FALSE);
3678 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3679 break;
3680 }
3681 }
3682 }
3683 WinSetPointer(HWND_DESKTOP, hptrArrow);
3684 if (x >= ad->numlines && !fAlertBeepOff)
3685 DosBeep(50, 100);
3686 }
3687 DosReleaseMutexSem(ad->ScanSem);
3688 }
3689 }
3690 break;
3691
3692 case IDM_SELECTFOUND:
3693 case IDM_DESELECTFOUND:
3694 {
3695 APIRET rc;
3696
3697 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3698 if (!rc) {
3699 if (!ad->busy && ad->text && ad->markedlines) {
3700
3701 RECTL Rectl;
3702 register ULONG x;
3703 ULONG numlines;
3704
3705 WinQueryWindowRect(hwnd, &Rectl);
3706 numlines = NumLines(&Rectl, ad);
3707 if (!numlines)
3708 break;
3709 WinSetPointer(HWND_DESKTOP, hptrBusy);
3710 for (x = 0; x < ad->numlines; x++) {
3711 if (SHORT1FROMMP(mp1) == IDM_SELECTFOUND) {
3712 if ((ad->markedlines[x] & VF_FOUND) &&
3713 !(ad->markedlines[x] & VF_SELECTED)) {
3714 ad->markedlines[x] |= VF_SELECTED;
3715 ad->selected++;
3716 }
3717 }
3718 else {
3719 if ((ad->markedlines[x] & VF_FOUND) &&
3720 (ad->markedlines[x] & VF_SELECTED)) {
3721 ad->markedlines[x] &= (~VF_SELECTED);
3722 ad->selected--;
3723 }
3724 }
3725 }
3726 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3727 WinSetPointer(HWND_DESKTOP, hptrArrow);
3728 WinInvalidateRect(hwnd, NULL, FALSE);
3729 }
3730 DosReleaseMutexSem(ad->ScanSem);
3731 }
3732 }
3733 break;
3734
3735 case IDM_GOTOLINE:
3736 case IDM_GOTOOFFSET:
3737 {
3738 APIRET rc;
3739
3740 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3741 if (!rc) {
3742 if (!ad->busy && ad->numlines) {
3743
3744 ULONG numlines, linenum;
3745 CHAR s[34], ss[134];
3746 STRINGINPARMS sip;
3747 RECTL Rectl;
3748 register ULONG x;
3749
3750 WinQueryWindowRect(hwnd, &Rectl);
3751 numlines = NumLines(&Rectl, ad);
3752 if (!numlines)
3753 break;
3754 if (ad->numlines <= numlines) {
3755 if (!fAlertBeepOff)
3756 DosBeep(500, 100);
3757 break;
3758 }
3759 sip.help = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3760 GetPString(IDS_NVLINEJUMPTEXT) : GetPString(IDS_NVBYTEJUMPTEXT);
3761 sip.ret = s;
3762 *s = 0;
3763 sip.inputlen = 34;
3764 sip.title = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3765 GetPString(IDS_NVLINEJUMPTITLETEXT) :
3766 GetPString(IDS_NVBYTEJUMPTITLETEXT);
3767 sprintf(ss,
3768 GetPString(IDS_NVJUMPTEXT),
3769 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3770 GetPString(IDS_LINETEXT) :
3771 GetPString(IDS_OFFSETTEXT),
3772 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3773 1 :
3774 0,
3775 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3776 ad->numlines : ad->textsize - 1);
3777 sip.prompt = ss;
3778 WinDlgBox(HWND_DESKTOP,
3779 hwnd, InputDlgProc, FM3ModHandle, STR_FRAME, &sip);
3780 if (*s) {
3781 s[33] = 0;
3782 linenum = atol(s);
3783 switch (SHORT1FROMMP(mp1)) {
3784 case IDM_GOTOLINE:
3785 if (linenum > 0 && linenum <= ad->numlines) {
3786 ad->topline = linenum;
3787 ad->cursored = ad->topline;
3788 if (ad->numlines - ad->topline < numlines)
3789 ad->topline = (ad->numlines - numlines) + 1;
3790 WinInvalidateRect(hwnd, NULL, FALSE);
3791 }
3792 break;
3793 case IDM_GOTOOFFSET:
3794 if (linenum < ad->textsize) {
3795 if (ad->hex)
3796 ad->topline = (linenum / 16) + 1;
3797 else if (ad->lines) {
3798 ad->topline = (ULONG) - 1;
3799 for (x = 0; x < ad->numlines; x++) {
3800 if (ad->lines[x] > ad->text + linenum) {
3801 ad->topline = x + 1;
3802 break;
3803 }
3804 }
3805 if (ad->topline == (ULONG) - 1)
3806 ad->topline = ad->numlines;
3807 }
3808 ad->cursored = ad->topline;
3809 if (ad->numlines - ad->topline < numlines)
3810 ad->topline = (ad->numlines - numlines) + 1;
3811 WinInvalidateRect(hwnd, NULL, FALSE);
3812 }
3813 break;
3814 }
3815 }
3816 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3817 }
3818 DosReleaseMutexSem(ad->ScanSem);
3819 }
3820 }
3821 break;
3822
3823 case IDM_CODEPAGE:
3824 {
3825 INT cp;
3826
3827 cp = PickCodepage(hwnd);
3828 if (cp != -1) {
3829 ad->fattrs.usCodePage = (USHORT) cp;
3830 Codepage = ad->fattrs.usCodePage;
3831 PrfWriteProfileData(fmprof,
3832 appname,
3833 "Viewer.Codepage",
3834 &ad->fattrs.usCodePage, sizeof(USHORT));
3835 GpiDeleteSetId(ad->hps, NEWVIEWMLE_FONT_LCID);
3836 GpiAssociate(ad->hps, 0);
3837 GpiDestroyPS(ad->hps);
3838 ad->hps = InitWindow(hwnd);
3839 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3840 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3841 WinInvalidateRect(hwnd, NULL, FALSE);
3842 }
3843 }
3844 break;
3845
3846 case IDM_SAVETOLIST2:
3847 case IDM_SAVETOCLIP2:
3848 case IDM_APPENDTOCLIP2:
3849 case IDM_SAVETOLIST:
3850 case IDM_SAVETOCLIP:
3851 case IDM_APPENDTOCLIP:
3852 {
3853 APIRET rc;
3854
3855 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3856 if (!rc) {
3857 if (!ad->busy) {
3858 ad->cliptype = SHORT1FROMMP(mp1);
3859 xbeginthread(ClipboardThread,
3860 524288,
3861 (PVOID)hwnd,
3862 pszSrcFile,
3863 __LINE__);
3864 }
3865 DosReleaseMutexSem(ad->ScanSem);
3866 }
3867 }
3868 break;
3869
3870 case IDM_SELECTALL:
3871 case IDM_DESELECTALL:
3872 case IDM_INVERT:
3873 {
3874 APIRET rc;
3875
3876 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3877 if (!rc) {
3878 if (!ad->busy && ad->markedlines) {
3879
3880 register ULONG x;
3881
3882 for (x = 0; x < ad->numlines; x++) {
3883 switch (SHORT1FROMMP(mp1)) {
3884 case IDM_SELECTALL:
3885 if (!(ad->markedlines[x] & VF_SELECTED)) {
3886 ad->markedlines[x] |= VF_SELECTED;
3887 ad->selected++;
3888 }
3889 break;
3890 case IDM_DESELECTALL:
3891 if (ad->markedlines[x] & VF_SELECTED) {
3892 ad->markedlines[x] &= (~VF_SELECTED);
3893 ad->selected--;
3894 }
3895 break;
3896 case IDM_INVERT:
3897 if (ad->markedlines[x] & VF_SELECTED) {
3898 ad->markedlines[x] &= (~VF_SELECTED);
3899 ad->selected--;
3900 }
3901 else {
3902 ad->markedlines[x] |= VF_SELECTED;
3903 ad->selected++;
3904 }
3905 break;
3906 }
3907 }
3908 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3909 WinInvalidateRect(hwnd, NULL, FALSE);
3910 }
3911 DosReleaseMutexSem(ad->ScanSem);
3912 }
3913 }
3914 break;
3915
3916 case IDM_WRAP:
3917 {
3918 APIRET rc;
3919
3920 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3921 if (!rc) {
3922 if (!ad->busy) {
3923 ad->wrapon = ad->wrapon ? FALSE : TRUE;
3924 WrapOn = ad->wrapon;
3925 PrfWriteProfileData(fmprof, appname, "Viewer.WrapOn",
3926 &ad->wrapon, sizeof(BOOL));
3927 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3928 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3929 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3930 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3931 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
3932 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
3933 MPVOID, MPVOID);
3934 ad->oldwidth = -1;
3935 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3936 MPFROM2SHORT(1, 1), MPVOID);
3937 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3938 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3939 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3940 MPFROM2SHORT(1, 1), MPVOID);
3941 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3942 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3943 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
3944 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3945 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3946 NEWVIEW_DRAG), NULL, FALSE);
3947 }
3948 DosReleaseMutexSem(ad->ScanSem);
3949 }
3950 }
3951 break;
3952
3953 case IDM_HEXMODE:
3954 {
3955 APIRET rc;
3956
3957 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3958 if (!rc) {
3959 if (!ad->busy) {
3960 ad->hex = (ad->hex) ? FALSE : TRUE;
3961 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3962 IDM_NEXTBLANKLINE), !ad->hex);
3963 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3964 IDM_PREVBLANKLINE), !ad->hex);
3965 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3966 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3967 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3968 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3969 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
3970 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
3971 MPVOID, MPVOID);
3972 ad->oldwidth = -1;
3973 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3974 MPFROM2SHORT(1, 1), MPVOID);
3975 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3976 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3977 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3978 MPFROM2SHORT(1, 1), MPVOID);
3979 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3980 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
3981 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
3982 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3983 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3984 NEWVIEW_DRAG), NULL, FALSE);
3985 }
3986 DosReleaseMutexSem(ad->ScanSem);
3987 }
3988 }
3989 break;
3990
3991 case IDM_FONTPALETTE:
3992 {
3993 APIRET rc;
3994
3995 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3996 if (!rc) {
3997 SetMLEFont(hwnd, &ad->fattrs, 11);
3998 PrfWriteProfileData(fmprof, appname, "Viewer.Fattrs",
3999 &ad->fattrs, sizeof(FATTRS));
4000 Fattrs = ad->fattrs;
4001 GpiDeleteSetId(ad->hps, NEWVIEWMLE_FONT_LCID);
4002 GpiAssociate(ad->hps, 0);
4003 GpiDestroyPS(ad->hps);
4004 ad->hps = InitWindow(hwnd);
4005 DosReleaseMutexSem(ad->ScanSem);
4006 WinSendMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
4007 WinInvalidateRect(hwnd, NULL, FALSE);
4008 }
4009 }
4010 break;
4011
4012 case IDM_HELP:
4013 if (hwndHelp)
4014 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
4015 MPFROM2SHORT(HELP_NEWVIEW, 0), MPFROMSHORT(HM_RESOURCEID));
4016 break;
4017 }
4018 return 0;
4019
4020 case WM_SETFOCUS:
4021 if (mp2)
4022 WinSendMsg(hwnd, UM_SETUP5, MPVOID, MPVOID);
4023 if (mp2 && ad && ad->needrefreshing && !ad->stopflag &&
4024 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
4025 ad->needrefreshing = FALSE;
4026 DosReleaseMutexSem(ad->ScanSem);
4027 WinInvalidateRect(hwnd, NULL, TRUE);
4028 }
4029 break;
4030
4031 case WM_SIZE:
4032 if (SHORT1FROMMP(mp2) && SHORT2FROMMP(mp2)) {
4033 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
4034 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
4035 }
4036 break;
4037
4038 case WM_SAVEAPPLICATION:
4039 if (ad && ParentIsDesktop(hwnd, ad->hwndParent)) {
4040
4041 SWP swp;
4042
4043 WinQueryWindowPos(ad->hwndFrame, &swp);
4044 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
4045 PrfWriteProfileData(fmprof,
4046 appname, "NewViewSizePos", &swp, sizeof(swp));
4047 }
4048 break;
4049
4050 case WM_CLOSE:
4051 if (ad)
4052 ad->stopflag = 1;
4053 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
4054 return 0;
4055
4056 case WM_DESTROY:
4057 {
4058 BOOL dontclose = FALSE;
4059 HWND hwndRestore = (HWND) 0;
4060
4061 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NEWVIEW_TIMER);
4062 if (ad) {
4063 ad->stopflag = 1;
4064 if (ad->ScanSem) {
4065 DosRequestMutexSem(ad->ScanSem, 15000);
4066 DosCloseMutexSem(ad->ScanSem);
4067 }
4068 if (ad->busy)
4069 DosSleep(100);
4070 if (ad->hps) {
4071 GpiDeleteSetId(ad->hps, NEWVIEWMLE_FONT_LCID);
4072 GpiAssociate(ad->hps, 0);
4073 GpiDestroyPS(ad->hps);
4074 }
4075 hwndRestore = ad->hwndRestore;
4076 dontclose = ((ad->flags & 4) != 0) ? TRUE : FALSE;
4077 FreeViewerMem(hwnd);
4078 WinSetWindowPtr(hwnd, QWL_USER, NULL);
4079 free(ad);
4080 }
4081 if (hwndRestore && hwndRestore != HWND_DESKTOP) {
4082
4083 ULONG fl = SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER;
4084 SWP swp;
4085
4086 if (WinQueryWindowPos(hwndRestore, &swp)) {
4087 if (!(swp.fl & SWP_MAXIMIZE))
4088 fl |= SWP_RESTORE;
4089 WinSetWindowPos(hwndRestore, HWND_TOP, 0, 0, 0, 0, fl);
4090 }
4091 }
4092 if (!dontclose &&
4093 ParentIsDesktop(hwnd, WinQueryWindow(WinQueryWindow(hwnd,
4094 QW_PARENT),
4095 QW_PARENT))) {
4096 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
4097 DosExit(EXIT_PROCESS, 1);
4098 }
4099 }
4100 break;
4101 }
4102
4103 return WinDefWindowProc(hwnd, msg, mp1, mp2);
4104}
4105
4106HWND StartViewer(HWND hwndParent, USHORT flags, CHAR * filename,
4107 HWND hwndRestore)
4108{
4109 HWND hwndFrame = (HWND) 0, hwndClient;
4110 VIEWDATA *ad;
4111 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
4112 FCF_SIZEBORDER | FCF_MINMAX |
4113 FCF_NOBYTEALIGN | FCF_VERTSCROLL |
4114 FCF_MENU | FCF_ICON | FCF_ACCELTABLE | FCF_HORZSCROLL;
4115
4116 if (strcmp(realappname, FM3Str))
4117 hwndParent = HWND_DESKTOP;
4118 if (ParentIsDesktop(hwndParent, hwndParent))
4119 FrameFlags |= FCF_TASKLIST;
4120 hwndFrame = WinCreateStdWindow(hwndParent,
4121 0,
4122 &FrameFlags,
4123 (CHAR *) WC_NEWVIEW,
4124 (CHAR *) GetPString(IDS_FM2VIEWERTITLETEXT),
4125 fwsAnimate,
4126 FM3ModHandle, NEWVIEW_FRAME, &hwndClient);
4127 if (hwndFrame) {
4128
4129 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
4130
4131 if (!fToolbar && hwndMenu) {
4132 WinSendMsg(hwndMenu, MM_DELETEITEM,
4133 MPFROM2SHORT(IDM_FINDFIRST, FALSE), MPVOID);
4134 WinSendMsg(hwndMenu, MM_DELETEITEM,
4135 MPFROM2SHORT(IDM_FINDNEXT, FALSE), MPVOID);
4136 WinSendMsg(hwndMenu, MM_DELETEITEM,
4137 MPFROM2SHORT(IDM_FINDPREV, FALSE), MPVOID);
4138 WinSendMsg(hwndMenu, MM_DELETEITEM,
4139 MPFROM2SHORT(IDM_SAVETOCLIP, FALSE), MPVOID);
4140 }
4141 ad = xmallocz(sizeof(VIEWDATA), pszSrcFile, __LINE__);
4142 if (!ad) {
4143 WinDestroyWindow(hwndFrame);
4144 hwndFrame = (HWND)0;
4145 }
4146 else {
4147 ad->size = sizeof(VIEWDATA);
4148 ad->stopflag = 0;
4149 ad->multiplier = 1;
4150 ad->hwndRestore = hwndRestore;
4151 ad->hwndFrame = hwndFrame;
4152 ad->hwndParent = hwndParent;
4153 ad->clientfocused = TRUE;
4154 ad->oldwidth = -1;
4155 strcpy(ad->filename, filename);
4156 ad->flags = flags;
4157 if (ad->flags & 16)
4158 ad->hex = TRUE;
4159 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
4160 if (Firsttime) {
4161
4162 ULONG size;
4163
4164 size = sizeof(BOOL);
4165 PrfQueryProfileData(fmprof, appname, "Viewer.Sensitive",
4166 (PVOID) & Sensitive, &size);
4167 size = sizeof(USHORT);
4168 PrfQueryProfileData(fmprof, appname, "Viewer.Codepage",
4169 (PVOID) & Codepage, &size);
4170 size = sizeof(BOOL);
4171 PrfQueryProfileData(fmprof, appname, "Viewer.LiteralSearch",
4172 (PVOID) & LiteralSearch, &size);
4173 size = sizeof(BOOL);
4174 PrfQueryProfileData(fmprof, appname, "Viewer.AlsoSelect",
4175 (PVOID) & AlsoSelect, &size);
4176 size = sizeof(BOOL);
4177 PrfQueryProfileData(fmprof, appname, "Viewer.WrapOn",
4178 (PVOID) & WrapOn, &size);
4179 size = sizeof(BOOL);
4180 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreFTP",
4181 (PVOID) & IgnoreFTP, &size);
4182 size = sizeof(BOOL);
4183 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
4184 (PVOID) & IgnoreHTTP, &size);
4185 size = sizeof(BOOL);
4186 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreMail",
4187 (PVOID) & IgnoreMail, &size);
4188 memset(&Fattrs, 0, sizeof(FATTRS));
4189 size = sizeof(FATTRS);
4190 Fattrs.usRecordLength = sizeof(FATTRS);
4191 Fattrs.lMaxBaselineExt = 16;
4192 Fattrs.lAveCharWidth = 8;
4193 Fattrs.usCodePage = Codepage;
4194 strcpy(Fattrs.szFacename, GetPString(IDS_SYSMONOTEXT));
4195 PrfQueryProfileData(fmprof, appname, "Viewer.Fattrs",
4196 (PVOID) & Fattrs, &size);
4197 size = sizeof(LONG) * COLORS_MAX;
4198 PrfQueryProfileData(fmprof, appname, "Viewer.Colors",
4199 (PVOID) Colors, &size);
4200 Firsttime = FALSE;
4201 }
4202 {
4203 ULONG size = sizeof(ad->searchtext);
4204
4205 PrfQueryProfileData(fmprof, appname, "Viewer.Searchtext",
4206 (PVOID) ad->searchtext, &size);
4207 ad->searchtext[sizeof(ad->searchtext) - 1] = 0;
4208 }
4209 ad->sensitive = Sensitive;
4210 ad->literalsearch = LiteralSearch;
4211 ad->fattrs = Fattrs;
4212 ad->alsoselect = AlsoSelect;
4213 ad->fattrs.usCodePage = Codepage;
4214 ad->wrapon = WrapOn;
4215 ad->ignorehttp = IgnoreHTTP;
4216 ad->ignoreftp = IgnoreFTP;
4217 ad->ignoremail = IgnoreMail;
4218 memcpy(ad->colors, Colors, sizeof(LONG) * COLORS_MAX);
4219 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
4220 if (!WinSendMsg(hwndClient, UM_SETUP, MPVOID, MPVOID))
4221 hwndFrame = (HWND) 0;
4222 else {
4223 if (!(FrameFlags & FCF_TASKLIST) && !(flags & 2)) {
4224 SWP swp;
4225
4226 FillClient(hwndParent, &swp, NULL, FALSE);
4227 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4228 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_RESTORE |
4229 SWP_ZORDER | SWP_ACTIVATE);
4230 }
4231 else if (FrameFlags & FCF_TASKLIST) {
4232
4233 SWP swp, swpD;
4234 ULONG size = sizeof(swp);
4235 LONG cxScreen, cyScreen;
4236
4237 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
4238 if (PrfQueryProfileData(fmprof,
4239 appname, "NewViewSizePos", &swpD, &size)) {
4240 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
4241 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
4242 if (swp.x + swpD.cx > cxScreen)
4243 swp.x = cxScreen - swpD.cx;
4244 if (swp.y + swpD.cy > cyScreen)
4245 swp.y = cyScreen - swpD.cy;
4246 swp.cx = swpD.cx;
4247 swp.cy = swpD.cy;
4248 }
4249 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4250 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
4251 SWP_ACTIVATE);
4252 }
4253 }
4254 }
4255 }
4256 return hwndFrame;
4257}
4258
4259#pragma alloc_text(NEWVIEW,ViewStatusProc,FreeViewerMem,LoadFileThread)
4260#pragma alloc_text(NEWVIEW,InitWindow,PaintLine,ViewWndProc)
4261#pragma alloc_text(NEWVIEW,ViewFrameWndProc,StartViewer,ReLineThread)
4262#pragma alloc_text(NEWVIEW,BuildAList,SearchThread,ClipboardThread,FindStrDlgProc)
4263#pragma alloc_text(NEWVIEW,BuildAList2,UrlDlgProc)
Note: See TracBrowser for help on using the repository browser.