source: trunk/dll/newview.c@ 1129

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

Added ability to save/append either the full path name (already present) or just the filename to the clipboard. Changed the menu text to make these easier to find. Removed the final return/newline from the list. Ticket 137

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