source: trunk/dll/newview.c@ 1186

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

Ticket 187: Draft 2: Move remaining function declarations

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