source: trunk/dll/newview.c@ 1400

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

Remainder of changes to rename commafmt.h/c (Ticket 28, 82); Additional strings moved to PCSZs in init.c (Ticket 6); Added WriteDetailsSwitches used it and LoadDetailsSwitches to consolidate inline code (Ticket 343, 344)

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