source: trunk/dll/newview.c@ 1335

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

Ticket 26: Add exception handlers to all threads using xbeginthread

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