source: trunk/dll/newview.c@ 1498

Last change on this file since 1498 was 1498, checked in by Gregg Young, 16 years ago

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

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