source: trunk/dll/newview.c@ 1790

Last change on this file since 1790 was 1790, checked in by Gregg Young, 11 years ago

Added isemailaddress to try to eliminate lines being falsely identified as containing an email. Fixed the mailto code to avoid a buffer over run (trap) and to cut trailing punctuation marks from the address. Tickets [543] & [544]

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