source: trunk/dll/newview.c@ 1210

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

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

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