source: trunk/dll/newview.c@ 1391

Last change on this file since 1391 was 1391, checked in by Gregg Young, 17 years ago

Move nontranslated strings to init.c and codepage.c; use those strings in place of GetPString calls. Move other strings to a StringTable; minor cleanup and code changes to codepage.c to use a string array instead of GetPString calls. Ticket 340

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