source: trunk/dll/newview.c@ 1162

Last change on this file since 1162 was 1162, checked in by John Small, 17 years ago

Ticket 187: Draft 1: Functions only

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