source: trunk/dll/newview.c@ 1395

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

Allow user to turn off alert and/or error beeps in settings notebook. Ticket 341 Move repeated strings to PCSZs. Ticket 6 Add *DateFormat functions to format dates based on locale Ticket 28 Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error Ticket 6

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