source: trunk/dll/newview.c@ 1780

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

Fixed errors found by cppcheck. Most had the potential to cause difficult to reproduce traps. Also fixed retry code for failure to create an archive work directory and the failure of the mailto code to drop trailing >.

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