source: trunk/dll/newview.c@ 1063

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

Fortify ifdef reformat

  • 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 1063 2008-07-11 03:33:36Z 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
34***********************************************************************/
35
36#include <stdlib.h>
37#include <string.h>
38#include <process.h>
39#include <limits.h>
40#include <share.h>
41
42#define INCL_DOS
43#define INCL_WIN
44#define INCL_GPI
45#define INCL_LONGLONG
46
47#include "fm3dlg.h"
48#include "fm3str.h"
49#include "mle.h"
50#include "makelist.h" // AddToList
51#include "errutil.h" // Dos_Error...
52#include "strutil.h" // GetPString
53#include "notebook.h" // httprun etc
54#include "fm3dll.h"
55#include "fortify.h"
56
57#pragma data_seg(DATA2)
58
59static PSZ pszSrcFile = __FILE__;
60
61#define VF_SELECTED 0x01
62#define VF_FOUND 0x02
63#define VF_HTTP 0x04
64#define VF_FTP 0x08
65
66#define FIXED_FONT_LCID 5
67
68#define COLORS_MAX 14
69
70#define COLORS_CURSOREDNORMALBACK 0
71#define COLORS_CURSOREDSELECTEDBACK 1
72#define COLORS_NORMALBACK 2
73#define COLORS_SELECTEDBACK 3
74#define COLORS_NORMALFORE 4
75#define COLORS_FOUNDFORE 5
76#define COLORS_SELECTEDFORE 6
77#define COLORS_SELECTEDFOUNDFORE 7
78#define COLORS_HTTPBACK 8
79#define COLORS_HTTPFORE 9
80#define COLORS_FTPBACK 10
81#define COLORS_FTPFORE 11
82#define COLORS_MAILBACK 12
83#define COLORS_MAILFORE 13
84
85static LONG Colors[COLORS_MAX] = {
86 COLR_WHITE, COLR_DARKGRAY,
87 COLR_PALEGRAY, COLR_BLACK,
88 COLR_BLACK, COLR_RED,
89 COLR_WHITE, COLR_YELLOW,
90 COLR_PALEGRAY, COLR_DARKBLUE,
91 COLR_PALEGRAY, COLR_DARKGREEN,
92 COLR_PALEGRAY, COLR_DARKRED
93};
94
95#define SEARCHSTRINGLEN 1024
96
97typedef struct
98{
99 FATTRS fattrs;
100 LONG colors[COLORS_MAX];
101 CHAR *text;
102 CHAR **lines, *markedlines;
103 CHAR searchtext[SEARCHSTRINGLEN], *lastpos, szFacename[FACESIZE];
104 ULONG textsize, numlines, topline, cursored, selected, numalloc, multiplier,
105 lastselected, found;
106 LONG oldwidth, lastdirection, lMaxAscender, lMaxDescender, lMaxHeight,
107 maxx, horzscroll;
108 HMTX ScanSem;
109 HWND hvscroll, hwndMenu, hwndStatus1, hwndStatus2, hwndStatus3, hwndRestore,
110 hwndPopup, hwndListbox, hwndFrame, hwndDrag, hwndParent, hhscroll;
111 HPS hps;
112 USHORT size;
113 USHORT flags;
114 USHORT cliptype;
115 CHAR filename[CCHMAXPATH];
116 CHAR stopflag, busy;
117 BOOL hex, mousecaptured, sensitive, dummy, literalsearch, clientfocused,
118 alsoselect, wrapon, relining, httpin, ftpin, mailin, ignorehttp, ignoreftp,
119 ignoremail, needrefreshing;
120}
121VIEWDATA;
122
123typedef struct
124{
125 ULONG len;
126 CHAR *line;
127 USHORT size;
128 USHORT dummy;
129 CHAR url[SEARCHSTRINGLEN];
130}
131URLDATA;
132
133static BOOL Sensitive = FALSE;
134static USHORT Codepage = 0;
135static BOOL Firsttime = TRUE;
136static BOOL LiteralSearch = FALSE;
137static BOOL AlsoSelect = FALSE;
138static BOOL WrapOn = FALSE;
139static BOOL IgnoreFTP = FALSE;
140static BOOL IgnoreHTTP = FALSE;
141static BOOL IgnoreMail = FALSE;
142static FATTRS Fattrs;
143
144// mailstr checks for a designated character in a string then cuts the string
145//to the first word that contains the character then prepends <mailto: and appends >
146
147CHAR *mailstr(CHAR *pszSrc, CHAR *pszFindChar, LONG StrLens)
148{
149 CHAR *pszCharCounter;
150 CHAR *pszTestStr = pszSrc;
151 CHAR szMailTo[1024] = "mailto:";
152 //CHAR szMailEnd[] = ">";
153
154 if (!strnstr(pszTestStr, pszFindChar, StrLens))
155 return NULL;
156 bstripcr(pszSrc);
157 remove_first_occurence_of_character("\r", pszSrc);
158 remove_first_occurence_of_character("\n", pszSrc);
159 if (!strstr(pszSrc, " ")){
160 if (!stristr(pszSrc, "<mailto:") && !fNoMailtoMailRun) {
161 strip_lead_char("<", pszSrc);
162 strip_trail_char(">", pszSrc);
163 strcat(szMailTo, pszSrc);
164 // strcat(szMailTo, szMailEnd);
165 pszSrc = szMailTo;
166 return pszSrc;
167 }
168 else {
169 strip_lead_char("<", pszSrc);
170 strip_trail_char(">", pszSrc);
171 return pszSrc;
172 }
173 }
174 while (strchr(pszSrc, ' ') < strchr(pszSrc, *pszFindChar)){
175 pszCharCounter = pszSrc;
176 while (*pszCharCounter && *pszCharCounter != ' '){
177 *pszCharCounter = ' ';
178 pszCharCounter++;
179 }
180 lstrip(pszSrc);
181 }
182 pszCharCounter = pszSrc;
183 while (*pszCharCounter && *pszCharCounter != ' ' && *pszCharCounter != '\r' &&
184 *pszCharCounter != '\n' && *pszCharCounter != '\"')
185 pszCharCounter++;
186 *pszCharCounter = 0;
187 if (!stristr(pszSrc, "<mailto:") && !fNoMailtoMailRun) {
188 strip_lead_char("<", pszSrc);
189 strip_trail_char(">", pszSrc);
190 strcat(szMailTo, pszSrc);
191 //strcat(szMailTo, szMailEnd);
192 pszSrc = szMailTo;
193 return pszSrc;
194 }
195 else {
196 strip_lead_char("<", pszSrc);
197 strip_trail_char(">", pszSrc);
198 return pszSrc;
199 }
200}
201
202MRESULT EXPENTRY UrlDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
203{
204 URLDATA *urld;
205
206 switch (msg) {
207 case WM_INITDLG:
208 if (mp2) {
209 CHAR *p, *e, *pp;
210 SHORT count;
211
212 WinSetWindowPtr(hwnd, QWL_USER, mp2);
213 urld = mp2;
214 e = urld->line + urld->len + 1;
215 p = urld->line;
216 do {
217 p = strnstr(p, "http://", e - p);
218 if (p) {
219 strncpy(urld->url, p, min(e - p, SEARCHSTRINGLEN - 1));
220 urld->url[min(e - p, SEARCHSTRINGLEN - 1)] = 0;
221 pp = urld->url;
222 while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' &&
223 *pp != '\"')
224 pp++;
225 *pp = 0;
226 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
227 MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
228 p++;
229 }
230 }
231 while (p && *p && p < e);
232 p = urld->line;
233 do {
234 p = strnstr(p, "ftp://", e - p);
235 if (p) {
236 strncpy(urld->url, p, min(e - p, SEARCHSTRINGLEN - 1));
237 urld->url[min(e - p, SEARCHSTRINGLEN - 1)] = 0;
238 pp = urld->url;
239 while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' &&
240 *pp != '\"')
241 pp++;
242 *pp = 0;
243 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
244 MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
245 p++;
246 }
247 }
248 while (p && *p && p < e);
249 p = urld->line;
250 if (mailstr(p, "@", e - p)) {
251 pp = mailstr(p, "@", e - p);
252 strcpy(urld->url, pp);
253 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
254 MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
255 }
256 *urld->url = 0;
257 count = (SHORT) WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_QUERYITEMCOUNT,
258 MPVOID, MPVOID);
259 if (count) {
260 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_SELECTITEM,
261 MPFROMSHORT(0), MPFROMSHORT(TRUE));
262 if (count == 1)
263 WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
264 else
265 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
266 break;
267 }
268 }
269 WinDismissDlg(hwnd, 0);
270 break;
271
272 case UM_SETUP:
273 WinShowWindow(hwnd, TRUE);
274 return 0;
275
276 case WM_CONTROL:
277 switch (SHORT1FROMMP(mp1)) {
278 case URL_LISTBOX:
279 switch (SHORT2FROMMP(mp1)) {
280 case LN_ENTER:
281 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
282 break;
283 }
284 break;
285 }
286 return 0;
287
288 case WM_COMMAND:
289 switch (SHORT1FROMMP(mp1)) {
290 case URL_BOOKMARK:
291 WinDismissDlg(hwnd, 3);
292 break;
293
294 case DID_OK:
295 {
296 SHORT select;
297
298 urld = WinQueryWindowPtr(hwnd, QWL_USER);
299 if (urld) {
300 select = (SHORT) WinSendDlgItemMsg(hwnd, URL_LISTBOX,
301 LM_QUERYSELECTION,
302 MPFROMSHORT(LIT_FIRST), MPVOID);
303 if (select >= 0) {
304 *urld->url = 0;
305 WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_QUERYITEMTEXT,
306 MPFROM2SHORT(select, sizeof(urld->url)),
307 MPFROMP(urld->url));
308 if (*urld->url) {
309 if (!strncmp(urld->url, "http://", 7)) {
310 WinDismissDlg(hwnd, 1);
311 break;
312 }
313 else if (!strncmp(urld->url, "ftp://", 6)) {
314 memmove(urld->url, urld->url + 6, strlen(urld->url) + 1);
315 if (*urld->url) {
316 WinDismissDlg(hwnd, 2);
317 break;
318 }
319 }
320 else if (strchr(urld->url, '@')) {
321 WinDismissDlg(hwnd, 3);
322 break;
323 }
324 }
325 }
326 }
327 }
328 Runtime_Error(pszSrcFile, __LINE__, "no data");
329 break;
330
331 case DID_CANCEL:
332 WinDismissDlg(hwnd, 0);
333 break;
334
335 case IDM_HELP:
336 break;
337 }
338 return 0;
339 }
340 return WinDefDlgProc(hwnd, msg, mp1, mp2);
341}
342
343static ULONG NumLines(RECTL * rcl, VIEWDATA * ad)
344{
345 ULONG numlines;
346
347 numlines = (rcl->yTop - rcl->yBottom) / ad->lMaxHeight;
348 if (ad->lMaxDescender && numlines &&
349 ((rcl->yTop - rcl->yBottom) -
350 (numlines * ad->lMaxHeight) <= ad->lMaxDescender))
351 numlines--;
352 return numlines;
353}
354
355static CHAR **BuildAList(HWND hwnd)
356{
357 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
358 register ULONG x, y, z = 0;
359 ULONG width;
360 RECTL Rectl;
361 CHAR **list = NULL, s[SEARCHSTRINGLEN], a;
362 register CHAR *p, *e;
363 UINT numlines = 0, numalloc = 0;
364
365 if (ad && ad->selected) {
366 WinQueryWindowRect(hwnd, &Rectl);
367 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
368 if (!width && !ad->hex)
369 return list;
370 for (x = 0; x < ad->numlines; x++) {
371 if (ad->stopflag)
372 break;
373 if (ad->markedlines[x] & VF_SELECTED) {
374 if (ad->hex) {
375 width = ad->textsize - (x * 16);
376 width = min(width, 16);
377 sprintf(s, "%08lx ", x * 16);
378 p = s + 9;
379 for (y = 0; y < width; y++) {
380 sprintf(p, " %02x", (UCHAR)ad->text[(x * 16) + y]);
381 p += 3;
382 }
383 *p = ' ';
384 p++;
385 *p = ' ';
386 p++;
387 for (y = 0; y < width; y++) {
388 a = ad->text[(x * 16) + y];
389 if (a && a != '\n' && a != '\r' && a != '\t' && a != '\x1a')
390 *p = ad->text[(x * 16) + y];
391 else
392 *p = '.';
393 p++;
394 }
395 *p = 0;
396 }
397 else {
398 if (!ad->wrapon) {
399 e = p = ad->lines[x];
400 while (*e != '\r' && *e != '\n' && e < ad->text + ad->textsize)
401 e++;
402 /* fixme to be gone?
403 if((*e == '\r' || *e == '\n') && e > p)
404 e--;
405 */
406 width = e - p;
407 }
408 else {
409 p = ad->lines[x];
410 e = p + (width - 1);
411 if (e - ad->text > ad->textsize)
412 e = ad->text + ad->textsize;
413 while (p < e) {
414 if (*p == '\r' || *p == '\n') {
415 e = p;
416 break;
417 }
418 p++;
419 }
420 }
421 strncpy(s, ad->lines[x], e - ad->lines[x]);
422 s[e - ad->lines[x]] = 0;
423 }
424 if (AddToList(s, &list, &numlines, &numalloc))
425 break;
426 z++;
427 if (z >= ad->selected)
428 break;
429 }
430 }
431 }
432 return list;
433}
434
435static CHAR **BuildAList2(HWND hwnd)
436{
437 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
438 CHAR **list = NULL, s[SEARCHSTRINGLEN];
439 SHORT x, z;
440 UINT numlines = 0, numalloc = 0;
441
442 if (ad) {
443 z = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
444 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
445 z = max(z, 0);
446 for (x = 0; x < z; x++) {
447 if (ad->stopflag)
448 break;
449 *s = 0;
450 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_QUERYITEMTEXT,
451 MPFROM2SHORT(x, SEARCHSTRINGLEN), MPFROMP(s));
452 if (*s)
453 if (AddToList(s, &list, &numlines, &numalloc))
454 break;
455 }
456 }
457 return list;
458}
459
460MRESULT EXPENTRY ViewStatusProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
461{
462 switch (msg) {
463 case WM_CREATE:
464 return CommonTextProc(hwnd, msg, mp1, mp2);
465
466 case WM_MOUSEMOVE:
467 {
468 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
469
470 if (fOtherHelp) {
471 if ((!hwndBubble || WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd)
472 && !WinQueryCapture(HWND_DESKTOP)) {
473
474 char *s = NULL;
475
476 switch (id) {
477 case NEWVIEW_STATUS2:
478 s = GetPString(IDS_NVSTATUS2HELPTEXT);
479 break;
480 case NEWVIEW_STATUS3:
481 s = GetPString(IDS_NVSTATUS3HELPTEXT);
482 break;
483 case NEWVIEW_DRAG:
484 s = GetPString(IDS_NVDRAGHELPTEXT);
485 break;
486 }
487 if (s && *s)
488 MakeBubble(hwnd, TRUE, s);
489 else if (hwndBubble)
490 WinDestroyWindow(hwndBubble);
491 }
492 }
493 switch (id) {
494 case NEWVIEW_STATUS1:
495 break;
496 default:
497 return CommonTextButton(hwnd, msg, mp1, mp2);
498 }
499 }
500 break;
501
502 case WM_BUTTON3UP:
503 case WM_BUTTON1UP:
504 case WM_BUTTON1DOWN:
505 case WM_BUTTON3DOWN:
506 {
507 USHORT id;
508
509 id = WinQueryWindowUShort(hwnd, QWS_ID);
510 switch (id) {
511 case NEWVIEW_STATUS1:
512 break;
513 default:
514 return CommonTextButton(hwnd, msg, mp1, mp2);
515 }
516 }
517 break;
518
519 case UM_CLICKED:
520 case UM_CLICKED3:
521 {
522 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID), cmd = 0;
523
524 switch (id) {
525 case NEWVIEW_DRAG:
526 if (msg == UM_CLICKED)
527 cmd = (msg == UM_CLICKED) ? IDM_HEXMODE : IDM_DESELECTALL;
528 break;
529 case NEWVIEW_STATUS2:
530 cmd = (msg == UM_CLICKED) ? IDM_GOTOLINE : IDM_FINDFIRST;
531 break;
532 case NEWVIEW_STATUS3:
533 cmd = (msg == UM_CLICKED) ? IDM_GOTOOFFSET : IDM_FINDNEXT;
534 break;
535 default:
536 break;
537 }
538 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
539 FID_CLIENT),
540 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
541 }
542 return 0;
543
544 case WM_BEGINDRAG:
545 {
546 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
547
548 switch (id) {
549 case NEWVIEW_STATUS1:
550 case NEWVIEW_DRAG:
551 {
552 VIEWDATA *ad =
553 WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
554 QW_PARENT),
555 FID_CLIENT), QWL_USER);
556
557 if (ad)
558 DragOne(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
559 FID_CLIENT), (HWND) 0, ad->filename,
560 FALSE);
561 }
562 break;
563 default:
564 break;
565 }
566 }
567 break;
568
569 case WM_CONTEXTMENU:
570 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
571 FID_CLIENT), UM_CONTEXTMENU, MPVOID, MPVOID);
572 break;
573
574 case WM_SETFOCUS:
575 if (mp2)
576 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
577 break;
578
579 case WM_PAINT:
580 {
581 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
582 ULONG color;
583 VIEWDATA *ad = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
584 QW_PARENT),
585 FID_CLIENT), QWL_USER);
586 SWP swp;
587 POINTL ptl;
588 HPS hps;
589
590 switch (id) {
591 case NEWVIEW_STATUS1:
592 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, FALSE);
593 break;
594 default:
595 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
596 break;
597 }
598 hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
599 if (hps) {
600 WinQueryWindowPos(hwnd, &swp);
601 ptl.x = swp.x - 1;
602 ptl.y = swp.y + swp.cy + 2;
603 GpiMove(hps, &ptl);
604 switch (id) {
605 case NEWVIEW_STATUS1:
606 if (ad)
607 color =
608 (standardcolors[ad->colors[COLORS_NORMALBACK]] ==
609 CLR_WHITE) ? CLR_PALEGRAY : CLR_WHITE;
610 else
611 color = CLR_WHITE;
612 break;
613 default:
614 if (ad)
615 color =
616 (standardcolors[ad->colors[COLORS_NORMALBACK]] ==
617 CLR_PALEGRAY) ? CLR_DARKGRAY : CLR_PALEGRAY;
618 else
619 color = CLR_PALEGRAY;
620 break;
621 }
622 GpiSetColor(hps, color);
623 ptl.x = swp.x + swp.cx;
624 GpiLine(hps, &ptl);
625 WinReleasePS(hps);
626 }
627 }
628 break;
629
630 case UM_FOCUSME:
631 WinSetFocus(HWND_DESKTOP,
632 WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_CLIENT));
633 return 0;
634 }
635 return PFNWPStatic(hwnd, msg, mp1, mp2);
636}
637
638static VOID FreeViewerMem(HWND hwnd)
639{
640 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
641
642 if (ad) {
643 ad->selected = ad->textsize = ad->numlines = ad->numalloc = 0;
644 xfree(ad->text, pszSrcFile, __LINE__);
645 xfree(ad->lines, pszSrcFile, __LINE__);
646 xfree(ad->markedlines, pszSrcFile, __LINE__);
647 ad->text = NULL;
648 ad->lines = NULL;
649 ad->markedlines = NULL;
650 DosPostEventSem(CompactSem);
651 }
652}
653
654static HPS InitWindow(HWND hwnd)
655{
656 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
657 HPS hps = (HPS) 0;
658 SIZEL sizel;
659 FONTMETRICS FontMetrics;
660
661 if (ad) {
662 sizel.cx = sizel.cy = 0;
663 hps = GpiCreatePS(WinQueryAnchorBlock(hwnd), WinOpenWindowDC(hwnd),
664 (PSIZEL) & sizel, PU_PELS | GPIF_DEFAULT | GPIT_MICRO |
665 GPIA_ASSOC);
666 if (hps) {
667 GpiSetCp(hps, (ULONG) ad->fattrs.usCodePage);
668 GpiCreateLogFont(hps, NULL, FIXED_FONT_LCID, &ad->fattrs);
669 GpiSetCharSet(hps, FIXED_FONT_LCID);
670 GpiQueryFontMetrics(hps, (long)sizeof(FONTMETRICS), &FontMetrics);
671 ad->fattrs.lAveCharWidth = FontMetrics.lAveCharWidth;
672 ad->fattrs.lMaxBaselineExt = FontMetrics.lMaxBaselineExt;
673 ad->lMaxAscender = max(FontMetrics.lMaxAscender, 0);
674 ad->lMaxDescender = max(FontMetrics.lMaxDescender, 0);
675 ad->lMaxHeight = ad->lMaxAscender + ad->lMaxDescender;
676 if (ad->fattrs.usCodePage != FontMetrics.usCodePage) {
677 ad->fattrs.usCodePage = FontMetrics.usCodePage;
678 Codepage = ad->fattrs.usCodePage;
679 PrfWriteProfileData(fmprof,
680 appname,
681 "Viewer.Codepage",
682 &ad->fattrs.usCodePage, sizeof(USHORT));
683 }
684 else if (ad->fattrs.usCodePage) {
685
686 HMQ hmq;
687 ULONG cps[50], len, x;
688
689 if (!DosQueryCp(sizeof(cps), cps, &len)) {
690 for (x = 0; x < len / sizeof(ULONG); x++) {
691 if (cps[x] == (ULONG) ad->fattrs.usCodePage) {
692 hmq = WinQueryWindowULong(hwnd, QWL_HMQ);
693 WinSetCp(hmq, ad->fattrs.usCodePage);
694 break;
695 }
696 }
697 }
698 DosSetProcessCp((ULONG) ad->fattrs.usCodePage);
699 }
700 GpiSetBackMix(hps, BM_OVERPAINT);
701 SetPresParamFromFattrs(WinWindowFromID(ad->hwndFrame, NEWVIEW_LISTBOX),
702 &ad->fattrs, FontMetrics.sNominalPointSize,
703 MAKEFIXED(FontMetrics.sNominalPointSize / 10,
704 0));
705 }
706 }
707 return (hps);
708}
709
710static VOID PaintLine(HWND hwnd, HPS hps, ULONG whichline, ULONG topline,
711 RECTL * Rectl)
712{
713 VIEWDATA *ad = WinQueryWindowPtr(hwnd, QWL_USER);
714 POINTL ptl;
715 ULONG width;
716 register CHAR *p, *e;
717 CHAR marker[] = " >";
718 RECTL rcl2;
719
720 if (ad && (ad->hex || ad->lines)) {
721 ptl.y = (Rectl->yTop - (ad->lMaxHeight *
722 (((whichline + 1) - topline) + 1)));
723 ptl.x = 0;
724 GpiMove(hps, &ptl);
725 GpiSetBackMix(hps, BM_OVERPAINT);
726 if (ad->markedlines) {
727 if (ad->markedlines[whichline] & VF_SELECTED) {
728 GpiSetColor(hps, ((ad->markedlines[whichline] & VF_FOUND) != 0) ?
729 standardcolors[ad->colors[COLORS_SELECTEDFOUNDFORE]] :
730 standardcolors[ad->colors[COLORS_SELECTEDFORE]]);
731 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
732 standardcolors[ad->
733 colors[COLORS_CURSOREDSELECTEDBACK]] :
734 standardcolors[ad->colors[COLORS_SELECTEDBACK]]);
735 }
736 else if (ad->markedlines[whichline] & VF_FOUND) {
737 GpiSetColor(hps, standardcolors[ad->colors[COLORS_FOUNDFORE]]);
738 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
739 standardcolors[ad->
740 colors[COLORS_CURSOREDNORMALBACK]] :
741 standardcolors[ad->colors[COLORS_NORMALBACK]]);
742 }
743 else {
744 GpiSetColor(hps, standardcolors[ad->colors[COLORS_NORMALFORE]]);
745 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
746 standardcolors[ad->
747 colors[COLORS_CURSOREDNORMALBACK]] :
748 standardcolors[ad->colors[COLORS_NORMALBACK]]);
749 }
750 }
751 else {
752 GpiSetColor(hps, standardcolors[ad->colors[COLORS_NORMALFORE]]);
753 GpiSetBackColor(hps, (whichline == ad->cursored - 1) ?
754 standardcolors[ad->colors[COLORS_CURSOREDNORMALBACK]] :
755 standardcolors[ad->colors[COLORS_NORMALBACK]]);
756 }
757 if (!ad->hex) {
758 if (ad->wrapon) {
759 width = (Rectl->xRight - Rectl->xLeft) / ad->fattrs.lAveCharWidth;
760 if (width) {
761 GpiCharString(hps, 1, marker + (whichline == ad->cursored - 1));
762 p = ad->lines[whichline];
763 e = p + (width - 1);
764 if (e - ad->text > ad->textsize)
765 e = ad->text + ad->textsize;
766 while (p < e) {
767 if (*p == '\r' || *p == '\n') {
768 e = p;
769 break;
770 }
771 p++;
772 }
773 if (ad->ftpin && whichline != ad->cursored - 1
774 && (!ad->markedlines
775 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
776 && strnstr(ad->lines[whichline], "ftp://",
777 e - ad->lines[whichline])) {
778 GpiSetColor(hps, standardcolors[ad->colors[COLORS_FTPFORE]]);
779 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_FTPBACK]]);
780 }
781 if (ad->httpin && whichline != ad->cursored - 1
782 && (!ad->markedlines
783 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
784 && strnstr(ad->lines[whichline], "http://",
785 e - ad->lines[whichline])) {
786 GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
787 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
788 }
789
790 if (ad->mailin && whichline != ad->cursored - 1
791 && (!ad->markedlines
792 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
793 && strnstr(ad->lines[whichline], "@",e - ad->lines[whichline])) {
794 GpiSetColor(hps, standardcolors[ad->colors[COLORS_MAILFORE]]);
795 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_MAILBACK]]);
796 }
797 rcl2 = *Rectl;
798 rcl2.yTop = ptl.y + ad->lMaxAscender;
799 rcl2.yBottom = ptl.y - ad->lMaxDescender;
800 GpiCharString(hps, e - ad->lines[whichline], ad->lines[whichline]);
801 GpiQueryCurrentPosition(hps, &ptl);
802 rcl2.xLeft = ptl.x;
803 WinFillRect(hps, &rcl2,
804 standardcolors[ad->colors[COLORS_NORMALBACK]]);
805 }
806 }
807 else {
808 width = (Rectl->xRight - Rectl->xLeft) / ad->fattrs.lAveCharWidth;
809 if (width) {
810 GpiCharString(hps, 1, marker + (whichline == ad->cursored - 1));
811 p = ad->lines[whichline];
812 e = p + (abs(ad->horzscroll) / ad->fattrs.lAveCharWidth);
813 if (e - ad->text > ad->textsize)
814 e = ad->text + ad->textsize;
815 while (p < e) {
816 if (*p == '\r' || *p == '\n')
817 break;
818 p++;
819 }
820 if (*p != '\r' && *p != '\n') {
821
822 CHAR *pp;
823
824 e = p + (width - 1);
825 if (e - ad->text > ad->textsize)
826 e = ad->text + ad->textsize;
827 pp = p;
828 while (pp < e) {
829 if (*pp == '\r' || *pp == '\n') {
830 e = pp;
831 break;
832 }
833 pp++;
834 }
835 }
836 else
837 e = p;
838 if (ad->ftpin && whichline != ad->cursored - 1
839 && (!ad->markedlines
840 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
841 && strnstr(ad->lines[whichline], "ftp://",
842 e - ad->lines[whichline])) {
843 GpiSetColor(hps, standardcolors[ad->colors[COLORS_FTPFORE]]);
844 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_FTPBACK]]);
845 }
846 if (ad->httpin && whichline != ad->cursored - 1
847 && (!ad->markedlines
848 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
849 && strnstr(ad->lines[whichline], "http://",e - ad->lines[whichline])) {
850 GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
851 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
852 }
853
854 if (ad->mailin && whichline != ad->cursored - 1
855 && (!ad->markedlines
856 || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
857 && strnstr(ad->lines[whichline], "@",e - ad->lines[whichline])) {
858 GpiSetColor(hps, standardcolors[ad->colors[COLORS_MAILFORE]]);
859 GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_MAILBACK]]);
860 }
861 rcl2 = *Rectl;
862 rcl2.yTop = ptl.y + ad->lMaxAscender;
863 rcl2.yBottom = ptl.y - ad->lMaxDescender;
864 GpiCharString(hps, e - p, p);
865 GpiQueryCurrentPosition(hps, &ptl);
866 rcl2.xLeft = ptl.x;
867 WinFillRect(hps, &rcl2,
868 standardcolors[ad->colors[COLORS_NORMALBACK]]);
869 }
870 }
871 }
872 else {
873
874 CHAR s[80];
875 register ULONG x;
876
877 rcl2 = *Rectl;
878 rcl2.yTop = ptl.y + ad->lMaxAscender;
879 rcl2.yBottom = ptl.y - ad->lMaxDescender;
880 GpiCharString(hps, 1, marker + (whichline == ad->cursored - 1));
881 width = ad->textsize - (whichline * 16);
882 width = min(width, 16);
883 sprintf(s, "%08lx ", whichline * 16);
884 p = s + 9;
885 for (x = 0; x < width; x++) {
886 sprintf(p, " %02x", (UCHAR)ad->text[(whichline * 16) + x]);
887 p += 3;
888 }
889 for (; x < 16; x++) {
890 *p = ' ';
891 p++;
892 *p = ' ';
893 p++;
894 *p = ' ';
895 p++;
896 }
897 *p = ' ';
898 p++;
899 *p = ' ';
900 p++;
901 for (x = 0; x < width; x++) {
902 *p = ad->text[(whichline * 16) + x];
903 p++;
904 }
905 *p = 0;
906 GpiCharString(hps, (p - s) - (abs(ad->horzscroll) /
907 ad->fattrs.lAveCharWidth),
908 s + (abs(ad->horzscroll) / ad->fattrs.lAveCharWidth));
909 GpiQueryCurrentPosition(hps, &ptl);
910 if (ptl.x + abs(ad->horzscroll) + ad->fattrs.lAveCharWidth + 1 >
911 ad->maxx) {
912 ad->maxx = ptl.x + abs(ad->horzscroll) + ad->fattrs.lAveCharWidth + 1;
913 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
914 MPFROM2SHORT((SHORT) Rectl->xRight, (SHORT) ad->maxx),
915 MPVOID);
916 }
917 rcl2.xLeft = ptl.x;
918 WinFillRect(hps, &rcl2, standardcolors[ad->colors[COLORS_NORMALBACK]]);
919 }
920 }
921}
922
923static VOID SearchThread(VOID * args)
924{
925 HWND hwnd = (HWND) args;
926 HAB hab2;
927 HMQ hmq2;
928 VIEWDATA *ad;
929 register CHAR *p;
930 RECTL Rectl;
931 ULONG width, numlines, lastline, whichline, firstline = ULONG_MAX;
932 register ULONG x;
933 CHAR s[SEARCHSTRINGLEN], s2[SEARCHSTRINGLEN], *t, *n, markwith;
934
935 priority_normal();
936# ifdef FORTIFY
937 Fortify_EnterScope();
938# endif
939 hab2 = WinInitialize(0);
940 if (hab2) {
941 hmq2 = WinCreateMsgQueue(hab2, 0);
942 if (hmq2) {
943 WinCancelShutdown(hmq2, TRUE);
944 IncrThreadUsage();
945 ad = WinQueryWindowPtr(hwnd, QWL_USER);
946 if (ad) {
947 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
948 markwith = VF_FOUND | ((ad->alsoselect) ? VF_SELECTED : 0);
949 strcpy(s, ad->searchtext);
950 if (*s) {
951 WinQueryWindowRect(hwnd, &Rectl);
952 width = (Rectl.xRight - Rectl.xLeft) / ad->fattrs.lAveCharWidth;
953 numlines = NumLines(&Rectl, ad);
954 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
955 NEWVIEW_STATUS1),
956 GetPString(IDS_SEARCHINGTEXT));
957 if (numlines && width && ad->markedlines && ad->numlines &&
958 ad->text && ad->textsize) {
959 for (x = 0; x < ad->numlines && !ad->stopflag; x++)
960 ad->markedlines[x] &= (~VF_FOUND);
961 ad->found = 0;
962 t = s;
963 while (t && !ad->stopflag) {
964 lastline = 1;
965 n = convert_nl_to_nul(t);
966 if (*t) {
967 strcpy(s2, t);
968 if (ad->literalsearch)
969 literal(s2);
970 p = ad->text;
971 while (p && !ad->stopflag) {
972 p = findstring(s2, strlen(s2), p,
973 ad->textsize - (p - ad->text),
974 ad->sensitive);
975 if (p) {
976 if (ad->hex) {
977 whichline = (p - ad->text) / 16;
978 if (whichline < firstline)
979 firstline = whichline;
980 if (!(ad->markedlines[whichline] & VF_FOUND))
981 ad->found++;
982 if (markwith & VF_SELECTED) {
983 if (!(ad->markedlines[whichline] & VF_SELECTED))
984 ad->selected++;
985 }
986 ad->markedlines[whichline] |= markwith;
987 if ((p - ad->text) + strlen(s2) >
988 (whichline + 1) * 16) {
989 whichline++;
990 if (!(ad->markedlines[whichline] & VF_FOUND))
991 ad->found++;
992 if (markwith & VF_SELECTED) {
993 if (!(ad->markedlines[whichline] & VF_SELECTED))
994 ad->selected++;
995 }
996 ad->markedlines[whichline] |= markwith;
997 }
998 p = ad->text + ((whichline + 1) * 16);
999 if (p >= ad->text + ad->textsize)
1000 break;
1001 }
1002 else {
1003 for (x = lastline; x < ad->numlines; x++) {
1004 if (ad->lines[x] > p) {
1005 if (x - 1 < firstline)
1006 firstline = x - 1;
1007 if (!(ad->markedlines[x - 1] & VF_FOUND))
1008 ad->found++;
1009 if (markwith & VF_SELECTED) {
1010 if (!(ad->markedlines[x - 1] & VF_SELECTED))
1011 ad->selected++;
1012 }
1013 ad->markedlines[x - 1] |= markwith;
1014 if (x + 1 < ad->numlines &&
1015 p + strlen(s2) > ad->lines[x]) {
1016 x++;
1017 if (!(ad->markedlines[x - 1] & VF_FOUND))
1018 ad->found++;
1019 if (markwith & VF_SELECTED) {
1020 if (!(ad->markedlines[x - 1] & VF_SELECTED))
1021 ad->selected++;
1022 }
1023 ad->markedlines[x - 1] |= markwith;
1024 }
1025 lastline = x;
1026 p = ad->lines[x];
1027 break;
1028 }
1029 }
1030 if (x >= ad->numlines) {
1031 if (markwith & VF_SELECTED) {
1032 if (!
1033 (ad->markedlines[numlines - 1] & VF_SELECTED))
1034 ad->selected++;
1035 if (!(ad->markedlines[numlines - 1] & VF_FOUND))
1036 ad->found++;
1037 }
1038 ad->markedlines[ad->numlines - 1] |= markwith;
1039 break;
1040 }
1041 }
1042 }
1043 }
1044 }
1045 t = n;
1046 }
1047 }
1048 DosReleaseMutexSem(ad->ScanSem);
1049 if (!ad->stopflag && firstline == ULONG_MAX) {
1050 DosBeep(50, 50);
1051 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1052 NEWVIEW_STATUS1),
1053 GetPString(IDS_NOMATCHINGTEXT));
1054 DosSleep(150);//05 Aug 07 GKY 1500
1055 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1056 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1057 }
1058 else if (!ad->stopflag) {
1059 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1060 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
1061 PostMsg(hwnd, UM_CONTAINER_FILLED,
1062 MPFROMLONG(firstline + 1), MPFROMLONG(firstline + 1));
1063 }
1064 }
1065 else
1066 DosReleaseMutexSem(ad->ScanSem);
1067 }
1068 }
1069 WinDestroyMsgQueue(hmq2);
1070 }
1071 DecrThreadUsage();
1072 WinTerminate(hab2);
1073 }
1074
1075# ifdef FORTIFY
1076 Fortify_LeaveScope();
1077# endif
1078 DosPostEventSem(CompactSem);
1079}
1080
1081static VOID ClipboardThread(VOID * args)
1082{
1083 HWND hwnd = (HWND) args;
1084 HAB hab2;
1085 HMQ hmq2;
1086 VIEWDATA *ad;
1087 CHAR **list;
1088 USHORT cmd;
1089 register ULONG x;
1090 BOOL released = FALSE;
1091
1092 priority_normal();
1093# ifdef FORTIFY
1094 Fortify_EnterScope();
1095# endif
1096 hab2 = WinInitialize(0);
1097 if (hab2) {
1098 hmq2 = WinCreateMsgQueue(hab2, 0);
1099 if (hmq2) {
1100 WinCancelShutdown(hmq2, TRUE);
1101 IncrThreadUsage();
1102 ad = WinQueryWindowPtr(hwnd, QWL_USER);
1103 if (ad) {
1104 if (!DosRequestMutexSem(ad->ScanSem, SEM_INDEFINITE_WAIT)) {
1105 cmd = ad->cliptype;
1106 if (ad->numlines && ad->text && ad->textsize && ad->markedlines &&
1107 !ad->stopflag) {
1108 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1109 NEWVIEW_STATUS1),
1110 GetPString(IDS_BUILDINGLINELISTTEXT));
1111 if (cmd == IDM_SAVETOCLIP || cmd == IDM_APPENDTOCLIP ||
1112 cmd == IDM_SAVETOLIST)
1113 list = BuildAList(hwnd);
1114 else
1115 list = BuildAList2(hwnd);
1116 if (list) {
1117 if (!ad->stopflag) {
1118 WinSetWindowText(WinWindowFromID(ad->hwndFrame,
1119 NEWVIEW_STATUS1),
1120 (cmd == IDM_SAVETOCLIP ||
1121 cmd == IDM_SAVETOCLIP2) ?
1122 GetPString(IDS_SAVETOCLIPTEXT) :
1123 (cmd == IDM_APPENDTOCLIP ||
1124 cmd == IDM_APPENDTOCLIP2) ?
1125 GetPString(IDS_APPENDTOCLIPTEXT) :
1126 GetPString(IDS_WRITETOFILETEXT));
1127 DosReleaseMutexSem(ad->ScanSem);
1128 released = TRUE;
1129 if (cmd == IDM_SAVETOCLIP || cmd == IDM_APPENDTOCLIP ||
1130 cmd == IDM_SAVETOCLIP2 || cmd == IDM_APPENDTOCLIP2)
1131 ListToClipboardHab(hab2, list, (cmd == IDM_APPENDTOCLIP ||
1132 cmd == IDM_APPENDTOCLIP2));
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.