source: trunk/dll/newview.c@ 1162

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

Ticket 187: Draft 1: Functions only

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