source: trunk/dll/newview.c@ 1009

Last change on this file since 1009 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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