source: trunk/dll/newview.c@ 1844

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

Have newview recognize https:
as a url. Remove trailing punctuation from urls. Fix cases where ismailaddress returns TRUE in error. Fixed IP address literal case and limted domains to 3 characters in email addresses.

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