source: trunk/dll/newview.c@ 1225

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

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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