source: trunk/dll/newview.c@ 1186

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

Ticket 187: Draft 2: Move remaining function declarations

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