source: trunk/dll/newview.c@ 1084

Last change on this file since 1084 was 1084, checked in by Gregg Young, 17 years ago

Added ability to save/append either the full path name (already present) or just the filename to the clipboard. Changed the menu text to make these easier to find. Removed the final return/newline from the list. Ticket 137

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