source: trunk/dll/newview.c@ 1570

Last change on this file since 1570 was 1544, checked in by Gregg Young, 15 years ago

Changes to fopen and _fsopen to allow FM2 to be loaded in high memory

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