source: trunk/dll/newview.c@ 1210

Last change on this file since 1210 was 1210, checked in by John Small, 17 years ago

Ticket 187: Move data declarations/definitions out of fm3dll.h

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