source: trunk/dll/newview.c@ 1890

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

Remove dead code and comments from remaining c files. #if 0 and #if NEVER were not addressed

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