source: trunk/dll/newview.c@ 1917

Last change on this file since 1917 was 1913, checked in by Gregg Young, 3 weeks ago

Limit the size of files the fast viewer will try to open Ticket #577

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