source: trunk/dll/newview.c@ 1781

Last change on this file since 1781 was 1781, checked in by Gregg Young, 11 years ago

Fix conditional trap caused by changes in CS [1780]

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