source: trunk/dll/newview.c@ 1038

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

More fortify cleanup

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