source: trunk/dll/newview.c@ 1335

Last change on this file since 1335 was 1335, checked in by Steven Levine, 17 years ago

Ticket 26: Add exception handlers to all threads using xbeginthread

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