source: trunk/dll/newview.c@ 1844

Last change on this file since 1844 was 1802, checked in by Gregg Young, 10 years ago

Have newview recognize https:
as a url. Remove trailing punctuation from urls. Fix cases where ismailaddress returns TRUE in error. Fixed IP address literal case and limted domains to 3 characters in email addresses.

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