source: trunk/dll/newview.c@ 1673

Last change on this file since 1673 was 1673, checked in by Gregg Young, 13 years ago

Update to Doxygen comment style Ticket 55. Also some minor code cleanup.

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