source: trunk/dll/newview.c@ 1323

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

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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