source: trunk/dll/newview.c@ 1034

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

More fortify changes

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