source: trunk/dll/newview.c

Last change on this file was 1893, checked in by Gregg Young, 5 years ago

Fix some layout and font issues in the viewers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 119.2 KB
RevLine 
[83]1
2/***********************************************************************
3
4 $Id: newview.c 1893 2020-05-26 20:04:17Z gyoung $
5
6 New internal viewer
7
8 Copyright (c) 1993-98 M. Kimes
[1498]9 Copyright (c) 2001, 2010 Steven H. Levine
[83]10
[130]11 01 Dec 03 SHL Comments
12 02 Dec 03 SHL Correct WM_VSCROLL math
13 23 May 05 SHL Use QWL_USER
[191]14 06 Jun 05 SHL Indent -i2
[218]15 06 Jun 05 SHL Correct reversed wrap logic
[350]16 17 Jul 06 SHL Use Runtime_Error
[368]17 26 Jul 06 SHL Use chop_at_crnl and convert_nl_to_nul
[533]18 03 Nov 06 SHL Renames
19 03 Nov 06 SHL Count thread usage
[574]20 22 Mar 07 GKY Use QWL_USER
[593]21 30 Mar 07 GKY Remove GetPString for window class names
[775]22 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
[793]23 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[812]24 26 Aug 07 GKY Fixed fast viewer text load failure
[819]25 28 Aug 07 GKY Reversed horizontal scrollbar behavior to be present for unwrapped text and absent for wrapped text & hex.
[850]26 14 Sep 07 SHL Another attempt to correct the fast viewer text load failure
[855]27 10 Oct 07 SHL Correct ReLineThread typo
[888]28 17 Dec 07 GKY Make WPURLDEFAULTSETTINGS the fall back for ftp/httprun
[890]29 28 Dec 07 GKY Add mailrun to allow mailto by clicking on an email address in the viewer
[895]30 29 Dec 07 GKY Formated email address using "<mailto:"
[985]31 29 Feb 08 GKY Use xfree where appropriate
32 29 Feb 08 GKY Refactor global command line variables to notebook.h
[1084]33 20 Jul 08 GKY Change ListToClipboardHab call to match changes made to function
[1335]34 10 Dec 08 SHL Integrate exception handler support
[1391]35 11 Jan 09 GKY Replace font names in the string file with global set at compile in init.c
[1395]36 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
37 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
[1400]38 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
39 08 Mar 09 GKY Additional strings move to PCSZs in init.c
[1444]40 13 Jul 09 SHL Sync with renames
[1498]41 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
[1781]42 28 Jun 14 GKY Fix errors identified with CPPCheck Fix "mailto" failure to drop trailing >
[1790]43 30 Aug 14 GKY Added isemailaddress to try to eliminate lines being falsely identified as
44 containing an email. Fixed the mailto code to avoid a buffer over run (trap)
45 and to cut trailing punctuation marks from the address
[1802]46 04 Apr 15 GKY Have https:// recognized as a url. Strip trailing punctuation from urls.
[83]47
48***********************************************************************/
49
[2]50#include <stdlib.h>
51#include <string.h>
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) /
[1893]3102 ad->multiplier) - numlines));
[551]3103 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3104 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
3105 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
[191]3106 }
3107 break;
3108 case SB_LINEUP:
[551]3109 if (ad->topline > 1) {
[2]3110
[191]3111 RECTL Rectl, iRectl;
[2]3112
[551]3113 ad->topline--;
3114 if (ad->cursored < ad->topline)
3115 ad->cursored = ad->topline;
3116 else if (ad->cursored + 1 > ad->topline + numlines)
3117 ad->cursored = (ad->topline + numlines) - 1;
3118 if (ad->cursored > ad->numlines)
3119 ad->cursored = ad->numlines;
[191]3120 WinQueryWindowRect(hwnd, &Rectl);
[551]3121 WinScrollWindow(hwnd, 0, -ad->lMaxHeight,
[191]3122 NULL, NULL, NULLHANDLE, &iRectl, 0);
[551]3123 WinFillRect(ad->hps, &iRectl,
3124 standardcolors[ad->colors[COLORS_NORMALBACK]]);
[191]3125 iRectl = Rectl;
[551]3126 iRectl.yTop -= ((numlines * ad->lMaxHeight) + ad->lMaxDescender);
3127 WinFillRect(ad->hps, &iRectl,
3128 standardcolors[ad->colors[COLORS_NORMALBACK]]);
3129 PaintLine(hwnd, ad->hps, ad->topline - 1, ad->topline, &Rectl);
3130 if (ad->cursored != ad->topline)
3131 PaintLine(hwnd, ad->hps, ad->cursored - 1, ad->topline, &Rectl);
3132 if (ad->cursored != wascursored &&
3133 wascursored >= ad->topline &&
3134 wascursored < ad->topline + numlines)
3135 PaintLine(hwnd, ad->hps, wascursored - 1, ad->topline, &Rectl);
3136 if (numlines >= ad->numlines)
[191]3137 numlines = 0;
[551]3138 if (ad->multiplier)
3139 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
3140 MPFROMSHORT((SHORT) (ad->topline / ad->multiplier)),
3141 MPFROM2SHORT(1, (SHORT) ((ad->numlines + 1) /
[1893]3142 ad->multiplier) - numlines));
[551]3143 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
3144 MPFROMSHORT((SHORT) abs(ad->horzscroll)),
3145 MPFROM2SHORT(0, (SHORT) (ad->maxx - Rectl.xRight)));
[191]3146 }
3147 break;
3148 case SB_SLIDERTRACK:
[551]3149 if ((SHORT1FROMMP(mp2) >= 1) || (SHORT1FROMMP(mp2)) <= ad->numlines) {
[1893]3150 ad->topline = (ULONG) ((SHORT1FROMMP(mp2) * ad->multiplier) +
3151 (ad->multiplier > 1 ? (numlines * 2) : 0));
[551]3152 if (ad->topline + numlines > ad->numlines + 1)
3153 ad->topline = (ad->numlines + 1) - numlines;
3154 if (!ad->topline)
3155 ad->topline = 1;
3156 if (ad->cursored < ad->topline)
3157 ad->cursored = ad->topline;
3158 else if (ad->cursored > ad->topline + numlines)
3159 ad->cursored = ad->topline + numlines;
3160 if (ad->cursored > ad->numlines)
3161 ad->cursored = ad->numlines;
[191]3162 WinInvalidateRect(hwnd, NULL, FALSE);
3163 }
3164 else
3165 WinAlarm(HWND_DESKTOP, WA_NOTE);
3166 break;
3167 }
[551]3168 if (ad->cursored != wascursored)
[191]3169 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
[2]3170 }
[551]3171 DosReleaseMutexSem(ad->ScanSem);
[191]3172 }
3173 break;
[2]3174
[191]3175 case WM_INITMENU:
[551]3176 switch (SHORT1FROMMP(mp1)) {
[191]3177 case IDM_FILESMENU:
3178 {
3179 APIRET rc;
3180 SHORT sSelect;
[2]3181
[551]3182 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3183 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP, (rc == 0 &&
3184 ad->selected != 0));
3185 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP, (rc == 0 &&
3186 ad->selected != 0));
3187 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST, (rc == 0 &&
3188 ad->selected != 0));
3189 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
3190 LM_QUERYITEMCOUNT, MPVOID,
3191 MPVOID);
3192 WinEnableMenuItem((HWND) mp2, IDM_SAVETOCLIP2,
3193 (rc == 0 && sSelect > 0));
3194 WinEnableMenuItem((HWND) mp2, IDM_APPENDTOCLIP2,
3195 (rc == 0 && sSelect > 0));
3196 WinEnableMenuItem((HWND) mp2, IDM_SAVETOLIST2,
3197 (rc == 0 && sSelect > 0));
[191]3198 if (!rc)
[551]3199 DosReleaseMutexSem(ad->ScanSem);
[191]3200 }
3201 break;
[2]3202
[191]3203 case IDM_VIEWSMENU:
3204 {
3205 APIRET rc;
[2]3206
[551]3207 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3208 WinEnableMenuItem((HWND) mp2, IDM_FONTPALETTE, (rc == 0));
3209 WinEnableMenuItem((HWND) mp2, IDM_HEXMODE, (rc == 0));
3210 WinEnableMenuItem((HWND) mp2, IDM_WRAP, (rc == 0));
3211 WinEnableMenuItem((HWND) mp2, IDM_CODEPAGE, (rc == 0));
[191]3212 if (!rc)
[551]3213 DosReleaseMutexSem(ad->ScanSem);
[191]3214 }
[551]3215 WinCheckMenuItem((HWND) mp2, IDM_HEXMODE, ad->hex);
3216 WinCheckMenuItem((HWND) mp2, IDM_WRAP, ad->wrapon);
3217 WinCheckMenuItem((HWND) mp2, IDM_IGNOREFTP, ad->ignoreftp);
3218 WinCheckMenuItem((HWND) mp2, IDM_IGNOREHTTP, ad->ignorehttp);
[890]3219 WinCheckMenuItem((HWND) mp2, IDM_IGNOREMAIL, ad->ignoremail);
[191]3220 break;
[2]3221
[191]3222 case IDM_SEARCHMENU:
3223 {
3224 APIRET rc;
[2]3225
[551]3226 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3227 WinEnableMenuItem((HWND) mp2, IDM_FINDFIRST, (rc == 0 &&
3228 ad->numlines != 0 &&
3229 ad->markedlines));
3230 WinEnableMenuItem((HWND) mp2, IDM_FINDNEXT, (rc == 0 &&
3231 ad->numlines != 0 &&
3232 ad->markedlines &&
3233 ad->found != 0));
3234 WinEnableMenuItem((HWND) mp2, IDM_FINDPREV, (rc == 0 &&
3235 ad->numlines != 0 &&
3236 ad->markedlines &&
3237 ad->found != 0));
3238 WinEnableMenuItem((HWND) mp2, IDM_NEXTBLANKLINE, (rc == 0 &&
3239 ad->numlines != 0 &&
3240 !ad->hex));
3241 WinEnableMenuItem((HWND) mp2, IDM_PREVBLANKLINE, (rc == 0 &&
3242 ad->numlines != 0 &&
3243 !ad->hex));
3244 WinEnableMenuItem((HWND) mp2, IDM_GOTOLINE, (rc == 0 &&
3245 ad->numlines != 0));
3246 WinEnableMenuItem((HWND) mp2, IDM_GOTOOFFSET, (rc == 0 &&
3247 ad->textsize != 0));
[191]3248 if (!rc)
[551]3249 DosReleaseMutexSem(ad->ScanSem);
[191]3250 }
3251 break;
[2]3252
[191]3253 case IDM_SELECTSUBMENU:
3254 {
3255 APIRET rc;
[2]3256
[551]3257 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3258 WinEnableMenuItem((HWND) mp2, IDM_SELECTALL, (rc == 0 &&
3259 ad->numlines != 0 &&
3260 ad->markedlines &&
3261 (ad->selected !=
3262 ad->numlines ||
3263 !ad->selected)));
3264 WinEnableMenuItem((HWND) mp2, IDM_DESELECTALL, (rc == 0 &&
3265 ad->numlines != 0 &&
3266 ad->markedlines &&
3267 ad->selected != 0));
3268 WinEnableMenuItem((HWND) mp2, IDM_DESELECTFOUND, (rc == 0 &&
3269 ad->numlines != 0 &&
3270 ad->markedlines &&
3271 ad->selected != 0 &&
3272 ad->found != 0));
3273 WinEnableMenuItem((HWND) mp2, IDM_SELECTFOUND, (rc == 0 &&
3274 ad->numlines != 0 &&
3275 ad->markedlines &&
3276 ad->found != 0 &&
3277 (ad->numlines !=
3278 ad->selected ||
3279 !ad->selected)));
3280 WinEnableMenuItem((HWND) mp2, IDM_NEXTSELECTED, (rc == 0 &&
3281 ad->numlines != 0 &&
3282 ad->markedlines &&
3283 ad->selected != 0));
3284 WinEnableMenuItem((HWND) mp2, IDM_PREVSELECTED, (rc == 0 &&
3285 ad->numlines != 0 &&
3286 ad->markedlines &&
3287 ad->selected != 0));
3288 WinEnableMenuItem((HWND) mp2, IDM_INVERT, (rc == 0 &&
3289 ad->numlines != 0 &&
3290 ad->markedlines));
[191]3291 if (!rc)
[551]3292 DosReleaseMutexSem(ad->ScanSem);
[2]3293 }
3294 break;
[191]3295 }
3296 break;
[2]3297
[191]3298 case UM_CONTROL:
[551]3299 switch (SHORT1FROMMP(mp1)) {
[191]3300 case NEWVIEW_LISTBOX:
[551]3301 switch (SHORT2FROMMP(mp1)) {
[191]3302 case LN_SETFOCUS:
[551]3303 if (ad) {
3304 if (!ad->clientfocused) {
[191]3305 PostMsg(hwnd,
[551]3306 WM_COMMAND, MPFROM2SHORT(IDM_NEXTWINDOW, 0), MPVOID);
[191]3307 break;
3308 }
[551]3309 ad->clientfocused = FALSE;
[191]3310 }
3311 PostMsg(hwnd,
[551]3312 UM_CONTROL, MPFROM2SHORT(NEWVIEW_LISTBOX, LN_SELECT), MPVOID);
[191]3313 break;
3314 case LN_KILLFOCUS:
[551]3315 if (ad) {
3316 ad->clientfocused = TRUE;
[191]3317 WinSetFocus(HWND_DESKTOP, hwnd);
3318 }
3319 break;
3320 case LN_SELECT:
[551]3321 if (ad && !ad->dummy) {
[2]3322
[191]3323 ULONG linenum, numlines;
3324 SHORT sSelect;
[551]3325 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
[191]3326 SHORT1FROMMP(mp1));
3327 RECTL Rectl;
[2]3328
[191]3329 sSelect = (SHORT) WinSendMsg(hwndUL,
3330 LM_QUERYSELECTION,
[551]3331 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3332 if (sSelect >= 0) {
[191]3333 linenum = (ULONG) WinSendMsg(hwndUL,
3334 LM_QUERYITEMHANDLE,
[551]3335 MPFROM2SHORT(sSelect, 0), MPVOID);
3336 if (ad->topline != linenum + 1 && linenum < ad->numlines) {
[191]3337 WinQueryWindowRect(hwnd, &Rectl);
3338 numlines = NumLines(&Rectl, ad);
[551]3339 ad->topline = linenum + 1;
3340 if (ad->numlines - ad->topline < numlines)
3341 ad->topline = ad->numlines - numlines;
3342 ad->cursored = linenum + 1;
[191]3343 WinInvalidateRect(hwnd, NULL, FALSE);
3344 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3345 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3346 }
3347 }
3348 else
3349 PostMsg(hwndUL, LM_SELECTITEM, MPFROM2SHORT(0, 0),
3350 MPFROM2SHORT(TRUE, 0));
3351 }
3352 break;
[2]3353
[191]3354 case LN_ENTER:
[551]3355 if (ad) {
[2]3356
[191]3357 SHORT sSelect;
[551]3358 HWND hwndUL = WinWindowFromID(ad->hwndFrame,
[191]3359 SHORT1FROMMP(mp1));
[2]3360
[191]3361 sSelect = (SHORT) WinSendMsg(hwndUL,
3362 LM_QUERYSELECTION,
[551]3363 MPFROM2SHORT(LIT_FIRST, 0), MPVOID);
3364 if (sSelect >= 0) {
3365 ad->dummy = TRUE;
[191]3366 WinSendMsg(hwndUL, LM_DELETEITEM,
3367 MPFROM2SHORT(sSelect, 0), MPVOID);
[551]3368 ad->dummy = FALSE;
[191]3369 sSelect = (SHORT) WinSendMsg(hwndUL,
[551]3370 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
3371 if (sSelect <= 0) {
3372 PostMsg(ad->hwndFrame, WM_UPDATEFRAME,
[191]3373 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3374 WinSetFocus(HWND_DESKTOP, hwnd);
3375 }
3376 }
3377 }
3378 break;
[2]3379
[191]3380 default:
3381 break;
[2]3382 }
[191]3383 break;
[2]3384
[191]3385 default:
3386 break;
3387 }
3388 return 0;
[2]3389
[191]3390 case WM_COMMAND:
[551]3391 switch (SHORT1FROMMP(mp1)) {
[191]3392 case IDM_EDIT:
[551]3393 if (*editor) {
[2]3394
[191]3395 CHAR *dummy[2];
[2]3396
[551]3397 dummy[0] = ad->filename;
[191]3398 dummy[1] = NULL;
[1497]3399 ExecOnList(hwnd, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
[1335]3400 pszSrcFile, __LINE__);
[191]3401 }
3402 else
[551]3403 StartMLEEditor(ad->hwndParent, 4, ad->filename, ad->hwndFrame);
3404 ad->hwndRestore = (HWND) 0;
[191]3405 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
3406 break;
[2]3407
[191]3408 case IDM_IGNOREFTP:
[551]3409 ad->ignoreftp = (ad->ignoreftp) ? FALSE : TRUE;
3410 ad->ftpin = FALSE;
[890]3411 if (ad->text && (*ftprun || fFtpRunWPSDefault) &&
[1335]3412 !ad->ignoreftp && strstr(ad->text, "ftp://"))
[551]3413 ad->ftpin = TRUE;
3414 IgnoreFTP = ad->ignoreftp;
[191]3415 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreFTP",
[551]3416 &ad->ignoreftp, sizeof(BOOL));
[191]3417 WinInvalidateRect(hwnd, NULL, FALSE);
3418 break;
[2]3419
[191]3420 case IDM_IGNOREHTTP:
[551]3421 ad->ignorehttp = (ad->ignorehttp) ? FALSE : TRUE;
3422 ad->httpin = FALSE;
[890]3423 if (ad->text && (*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
[1802]3424 (strstr(ad->text, "http://") || strstr(ad->text, "https://")))
[551]3425 ad->httpin = TRUE;
3426 IgnoreHTTP = ad->ignorehttp;
[191]3427 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
[551]3428 &ad->ignorehttp, sizeof(BOOL));
[191]3429 WinInvalidateRect(hwnd, NULL, FALSE);
3430 break;
[2]3431
[890]3432 case IDM_IGNOREMAIL:
3433 ad->ignoremail = (ad->ignoremail) ? FALSE : TRUE;
3434 ad->mailin = FALSE;
3435 if (ad->text && *mailrun && !ad->ignoremail &&
[1790]3436 isemailaddress(ad->text))
[890]3437 ad->mailin = TRUE;
3438 IgnoreMail = ad->ignoremail;
3439 PrfWriteProfileData(fmprof, appname, "Viewer.IgnoreMail",
3440 &ad->ignoremail, sizeof(BOOL));
3441 WinInvalidateRect(hwnd, NULL, FALSE);
3442 break;
3443
[191]3444 case IDM_PREVBLANKLINE:
[551]3445 if (!ad->hex && ad->lines) {
[2]3446
[191]3447 ULONG x;
[2]3448
[551]3449 x = ad->cursored - 2;
3450 if (x >= ad->numlines)
[191]3451 x = 0;
[551]3452 while (x < ad->numlines &&
3453 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
[191]3454 x--;
[551]3455 if (x >= ad->numlines)
[191]3456 x = 0;
[551]3457 for (; x < ad->numlines; x--) {
3458 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3459 if (x < ad->numlines - 1)
[191]3460 x++;
3461 break;
3462 }
3463 }
[551]3464 if (x < ad->numlines) {
3465 ad->topline = ad->cursored = x;
[191]3466 WinInvalidateRect(hwnd, NULL, FALSE);
3467 }
3468 }
3469 break;
[2]3470
[191]3471 case IDM_NEXTBLANKLINE:
[551]3472 if (!ad->hex && ad->lines) {
[2]3473
[191]3474 ULONG x;
[2]3475
[551]3476 x = ad->cursored;
3477 while (x < ad->numlines &&
3478 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
[191]3479 x++;
[551]3480 for (; x < ad->numlines; x++) {
3481 if (*ad->lines[x] == '\r' || *ad->lines[x] == '\n') {
3482 if (x < ad->numlines - 1)
[191]3483 x++;
3484 break;
3485 }
3486 }
[551]3487 if (x < ad->numlines) {
3488 while (x < ad->numlines &&
3489 (*ad->lines[x] == '\r' || *ad->lines[x] == '\n'))
[191]3490 x++;
[551]3491 if (x < ad->numlines) {
3492 ad->topline = ad->cursored = x;
[191]3493 WinInvalidateRect(hwnd, NULL, FALSE);
3494 }
3495 }
3496 }
3497 break;
[2]3498
[191]3499 case IDM_VIEW:
3500 case IDM_OBJECT:
[551]3501 if (!ad->hex && ad->lines) {
[2]3502
[191]3503 CHAR line[CCHMAXPATH], filename[CCHMAXPATH], *p;
[2]3504
[551]3505 strncpy(line, ad->lines[ad->cursored - 1], CCHMAXPATH);
[191]3506 line[CCHMAXPATH - 1] = 0;
[368]3507 chop_at_crnl(line);
[551]3508 if (*line == '\"') {
[191]3509 memmove(line, line + 1, strlen(line));
3510 p = strchr(line, '\"');
3511 lstrip(line);
3512 if (p)
3513 *p = 0;
3514 rstrip(line);
3515 }
[551]3516 else {
[191]3517 lstrip(line);
3518 p = strchr(line, ' ');
3519 if (p)
3520 *p = 0;
3521 rstrip(line);
3522 }
[551]3523 if (!strchr(line, '\\') && !strchr(line, '/') && !strchr(line, ':')) {
3524 strcpy(filename, ad->filename);
[191]3525 p = strrchr(filename, '\\');
3526 if (p)
3527 p++;
3528 else
3529 p = filename;
3530 strcpy(p, line);
3531 }
3532 else
3533 strcpy(filename, line);
3534 MakeFullName(filename);
[551]3535 if (*filename && IsFile(filename) == 1) {
[191]3536 if (SHORT1FROMMP(mp1) == IDM_OBJECT)
[551]3537 OpenObject(filename, Default, ad->hwndFrame);
[191]3538 else
[551]3539 DefaultView(hwnd, ad->hwndFrame, HWND_DESKTOP, NULL, 0, filename);
[191]3540 }
3541 }
3542 break;
[2]3543
[191]3544 case IDM_COLORPALETTE:
3545 {
3546 COLORS co;
3547 LONG temp[COLORS_MAX];
[2]3548
[191]3549 memset(&co, 0, sizeof(co));
3550 co.size = sizeof(co);
3551 co.numcolors = COLORS_MAX;
[551]3552 co.colors = ad->colors;
[191]3553 co.descriptions = IDS_NVCOLORS1TEXT;
3554 co.origs = temp;
3555 co.prompt = IDS_NVCOLORSPROMPTTEXT;
[551]3556 memcpy(temp, ad->colors, sizeof(LONG) * COLORS_MAX);
[191]3557 if (WinDlgBox(HWND_DESKTOP,
3558 hwnd,
3559 ColorDlgProc,
[551]3560 FM3ModHandle, COLOR_FRAME, (PVOID) & co)) {
3561 memcpy(Colors, ad->colors, sizeof(LONG) * COLORS_MAX);
[191]3562 PrfWriteProfileData(fmprof,
3563 appname,
3564 "Viewer.Colors",
[551]3565 &ad->colors, sizeof(LONG) * COLORS_MAX);
3566 WinInvalidateRect(hwnd, NULL, FALSE);
3567 WinInvalidateRect(ad->hwndStatus1, NULL, FALSE);
3568 WinInvalidateRect(ad->hwndStatus2, NULL, FALSE);
3569 WinInvalidateRect(ad->hwndStatus3, NULL, FALSE);
[191]3570 }
3571 }
3572 break;
[2]3573
[191]3574 case IDM_NEXTWINDOW:
3575 case IDM_PREVWINDOW:
3576 {
3577 SHORT sSelect;
[2]3578
[551]3579 sSelect = (SHORT) WinSendDlgItemMsg(ad->hwndFrame,
[191]3580 NEWVIEW_LISTBOX,
3581 LM_QUERYITEMCOUNT,
[551]3582 MPVOID, MPVOID);
3583 if (sSelect) {
3584 if (!ad->clientfocused)
[191]3585 WinSetFocus(HWND_DESKTOP, hwnd);
3586 else
3587 WinSetFocus(HWND_DESKTOP,
[551]3588 WinWindowFromID(ad->hwndFrame, NEWVIEW_LISTBOX));
[191]3589 }
3590 else
3591 WinSetFocus(HWND_DESKTOP, hwnd);
3592 }
3593 break;
[2]3594
[191]3595 case IDM_FINDFIRST:
3596 {
3597 APIRET rc;
[2]3598
[551]3599 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3600 if (!rc) {
3601 if (!ad->busy && ad->text && ad->numlines && ad->markedlines) {
[2]3602
[191]3603 ULONG numlines;
3604 RECTL Rectl;
3605 static char test[SEARCHSTRINGLEN];
[2]3606
[191]3607 WinQueryWindowRect(hwnd, &Rectl);
3608 numlines = NumLines(&Rectl, ad);
3609 if (!numlines)
3610 break;
[551]3611 strcpy(test, ad->searchtext);
[191]3612 if (WinDlgBox(HWND_DESKTOP, hwnd, FindStrDlgProc, FM3ModHandle,
[551]3613 NEWFIND_FRAME, (PVOID) & hwnd)) {
3614 if (*ad->searchtext && strcmp(test, ad->searchtext))
[191]3615 PrfWriteProfileString(fmprof,
3616 appname,
3617 "Viewer.Searchtext",
[551]3618 (PVOID) ad->searchtext);
[1335]3619 xbeginthread(SearchThread,
3620 524288,
3621 (PVOID)hwnd,
3622 pszSrcFile,
3623 __LINE__);
[191]3624 }
3625 }
[551]3626 DosReleaseMutexSem(ad->ScanSem);
[191]3627 }
3628 }
3629 break;
[2]3630
[191]3631 case IDM_PREVSELECTED:
3632 case IDM_NEXTSELECTED:
3633 case IDM_FINDPREV:
3634 case IDM_FINDNEXT:
3635 {
3636 APIRET rc;
[2]3637
[551]3638 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3639 if (!rc) {
3640 if (!ad->busy && ad->text && ad->markedlines) {
[2]3641
[191]3642 RECTL Rectl;
3643 register ULONG x;
3644 ULONG numlines;
3645 CHAR markedwith;
[2]3646
[191]3647 markedwith = (SHORT1FROMMP(mp1) == IDM_FINDNEXT ||
3648 SHORT1FROMMP(mp1) == IDM_FINDPREV) ?
3649 VF_FOUND : VF_SELECTED;
3650 WinQueryWindowRect(hwnd, &Rectl);
3651 numlines = NumLines(&Rectl, ad);
3652 if (!numlines)
3653 break;
3654 WinSetPointer(HWND_DESKTOP, hptrBusy);
3655 if (SHORT1FROMMP(mp1) == IDM_PREVSELECTED ||
[551]3656 SHORT1FROMMP(mp1) == IDM_FINDPREV) {
3657 for (x = ad->cursored - 2; x < ULONG_MAX - 1; x--) {
3658 if (ad->markedlines[x] & markedwith) {
3659 ad->topline = x + 1;
3660 if (ad->numlines - ad->topline < numlines)
3661 ad->topline = ad->numlines - numlines;
3662 ad->cursored = x + 1;
[191]3663 WinInvalidateRect(hwnd, NULL, FALSE);
3664 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3665 break;
3666 }
3667 }
3668 }
[551]3669 else {
3670 for (x = ad->cursored; x < ad->numlines; x++) {
3671 if (ad->markedlines[x] & markedwith) {
3672 ad->topline = x + 1;
3673 if (ad->numlines - ad->topline < numlines)
3674 ad->topline = ad->numlines - numlines;
3675 ad->cursored = x + 1;
[191]3676 WinInvalidateRect(hwnd, NULL, FALSE);
3677 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3678 break;
3679 }
3680 }
3681 }
3682 WinSetPointer(HWND_DESKTOP, hptrArrow);
[1395]3683 if (x >= ad->numlines && !fAlertBeepOff)
[191]3684 DosBeep(50, 100);
3685 }
[551]3686 DosReleaseMutexSem(ad->ScanSem);
[191]3687 }
3688 }
3689 break;
[2]3690
[191]3691 case IDM_SELECTFOUND:
3692 case IDM_DESELECTFOUND:
3693 {
3694 APIRET rc;
[2]3695
[551]3696 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3697 if (!rc) {
3698 if (!ad->busy && ad->text && ad->markedlines) {
[2]3699
[191]3700 RECTL Rectl;
3701 register ULONG x;
3702 ULONG numlines;
[2]3703
[191]3704 WinQueryWindowRect(hwnd, &Rectl);
3705 numlines = NumLines(&Rectl, ad);
3706 if (!numlines)
3707 break;
3708 WinSetPointer(HWND_DESKTOP, hptrBusy);
[551]3709 for (x = 0; x < ad->numlines; x++) {
3710 if (SHORT1FROMMP(mp1) == IDM_SELECTFOUND) {
3711 if ((ad->markedlines[x] & VF_FOUND) &&
3712 !(ad->markedlines[x] & VF_SELECTED)) {
3713 ad->markedlines[x] |= VF_SELECTED;
3714 ad->selected++;
[191]3715 }
3716 }
[551]3717 else {
3718 if ((ad->markedlines[x] & VF_FOUND) &&
3719 (ad->markedlines[x] & VF_SELECTED)) {
3720 ad->markedlines[x] &= (~VF_SELECTED);
3721 ad->selected--;
[191]3722 }
3723 }
3724 }
3725 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3726 WinSetPointer(HWND_DESKTOP, hptrArrow);
3727 WinInvalidateRect(hwnd, NULL, FALSE);
3728 }
[551]3729 DosReleaseMutexSem(ad->ScanSem);
[191]3730 }
3731 }
3732 break;
[2]3733
[191]3734 case IDM_GOTOLINE:
3735 case IDM_GOTOOFFSET:
3736 {
3737 APIRET rc;
[2]3738
[551]3739 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3740 if (!rc) {
3741 if (!ad->busy && ad->numlines) {
[2]3742
[191]3743 ULONG numlines, linenum;
3744 CHAR s[34], ss[134];
3745 STRINGINPARMS sip;
3746 RECTL Rectl;
3747 register ULONG x;
[2]3748
[191]3749 WinQueryWindowRect(hwnd, &Rectl);
3750 numlines = NumLines(&Rectl, ad);
3751 if (!numlines)
3752 break;
[551]3753 if (ad->numlines <= numlines) {
[1395]3754 if (!fAlertBeepOff)
3755 DosBeep(500, 100);
[191]3756 break;
3757 }
3758 sip.help = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
[551]3759 GetPString(IDS_NVLINEJUMPTEXT) : GetPString(IDS_NVBYTEJUMPTEXT);
[191]3760 sip.ret = s;
3761 *s = 0;
3762 sip.inputlen = 34;
3763 sip.title = (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3764 GetPString(IDS_NVLINEJUMPTITLETEXT) :
3765 GetPString(IDS_NVBYTEJUMPTITLETEXT);
[1394]3766 sprintf(ss,
[191]3767 GetPString(IDS_NVJUMPTEXT),
3768 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3769 GetPString(IDS_LINETEXT) :
3770 GetPString(IDS_OFFSETTEXT),
3771 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
3772 1 :
3773 0,
3774 (SHORT1FROMMP(mp1) == IDM_GOTOLINE) ?
[551]3775 ad->numlines : ad->textsize - 1);
[1394]3776 sip.prompt = ss;
[191]3777 WinDlgBox(HWND_DESKTOP,
[551]3778 hwnd, InputDlgProc, FM3ModHandle, STR_FRAME, &sip);
3779 if (*s) {
[191]3780 s[33] = 0;
3781 linenum = atol(s);
[551]3782 switch (SHORT1FROMMP(mp1)) {
[191]3783 case IDM_GOTOLINE:
[551]3784 if (linenum > 0 && linenum <= ad->numlines) {
3785 ad->topline = linenum;
3786 ad->cursored = ad->topline;
3787 if (ad->numlines - ad->topline < numlines)
3788 ad->topline = (ad->numlines - numlines) + 1;
3789 WinInvalidateRect(hwnd, NULL, FALSE);
[191]3790 }
3791 break;
3792 case IDM_GOTOOFFSET:
[551]3793 if (linenum < ad->textsize) {
3794 if (ad->hex)
3795 ad->topline = (linenum / 16) + 1;
3796 else if (ad->lines) {
3797 ad->topline = (ULONG) - 1;
3798 for (x = 0; x < ad->numlines; x++) {
3799 if (ad->lines[x] > ad->text + linenum) {
3800 ad->topline = x + 1;
[191]3801 break;
3802 }
3803 }
[551]3804 if (ad->topline == (ULONG) - 1)
3805 ad->topline = ad->numlines;
[191]3806 }
[551]3807 ad->cursored = ad->topline;
3808 if (ad->numlines - ad->topline < numlines)
3809 ad->topline = (ad->numlines - numlines) + 1;
3810 WinInvalidateRect(hwnd, NULL, FALSE);
[191]3811 }
3812 break;
3813 }
3814 }
[551]3815 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
[191]3816 }
[551]3817 DosReleaseMutexSem(ad->ScanSem);
[191]3818 }
3819 }
3820 break;
[2]3821
[191]3822 case IDM_CODEPAGE:
3823 {
3824 INT cp;
[2]3825
[191]3826 cp = PickCodepage(hwnd);
[551]3827 if (cp != -1) {
3828 ad->fattrs.usCodePage = (USHORT) cp;
3829 Codepage = ad->fattrs.usCodePage;
[191]3830 PrfWriteProfileData(fmprof,
3831 appname,
3832 "Viewer.Codepage",
[551]3833 &ad->fattrs.usCodePage, sizeof(USHORT));
[1433]3834 GpiDeleteSetId(ad->hps, NEWVIEWMLE_FONT_LCID);
[551]3835 GpiAssociate(ad->hps, 0);
3836 GpiDestroyPS(ad->hps);
3837 ad->hps = InitWindow(hwnd);
3838 WinSendMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3839 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3840 WinInvalidateRect(hwnd, NULL, FALSE);
[191]3841 }
3842 }
3843 break;
[2]3844
[191]3845 case IDM_SAVETOLIST2:
3846 case IDM_SAVETOCLIP2:
3847 case IDM_APPENDTOCLIP2:
3848 case IDM_SAVETOLIST:
3849 case IDM_SAVETOCLIP:
3850 case IDM_APPENDTOCLIP:
3851 {
3852 APIRET rc;
[2]3853
[551]3854 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3855 if (!rc) {
3856 if (!ad->busy) {
3857 ad->cliptype = SHORT1FROMMP(mp1);
[1335]3858 xbeginthread(ClipboardThread,
3859 524288,
3860 (PVOID)hwnd,
3861 pszSrcFile,
3862 __LINE__);
[191]3863 }
[551]3864 DosReleaseMutexSem(ad->ScanSem);
[191]3865 }
3866 }
3867 break;
[2]3868
[191]3869 case IDM_SELECTALL:
3870 case IDM_DESELECTALL:
3871 case IDM_INVERT:
3872 {
3873 APIRET rc;
[2]3874
[551]3875 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3876 if (!rc) {
3877 if (!ad->busy && ad->markedlines) {
[2]3878
[191]3879 register ULONG x;
[2]3880
[551]3881 for (x = 0; x < ad->numlines; x++) {
3882 switch (SHORT1FROMMP(mp1)) {
[191]3883 case IDM_SELECTALL:
[551]3884 if (!(ad->markedlines[x] & VF_SELECTED)) {
3885 ad->markedlines[x] |= VF_SELECTED;
3886 ad->selected++;
[191]3887 }
3888 break;
3889 case IDM_DESELECTALL:
[551]3890 if (ad->markedlines[x] & VF_SELECTED) {
3891 ad->markedlines[x] &= (~VF_SELECTED);
3892 ad->selected--;
[191]3893 }
3894 break;
3895 case IDM_INVERT:
[551]3896 if (ad->markedlines[x] & VF_SELECTED) {
3897 ad->markedlines[x] &= (~VF_SELECTED);
3898 ad->selected--;
[191]3899 }
[551]3900 else {
3901 ad->markedlines[x] |= VF_SELECTED;
3902 ad->selected++;
[191]3903 }
3904 break;
3905 }
3906 }
3907 WinSendMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
3908 WinInvalidateRect(hwnd, NULL, FALSE);
3909 }
[551]3910 DosReleaseMutexSem(ad->ScanSem);
[191]3911 }
3912 }
3913 break;
[2]3914
[191]3915 case IDM_WRAP:
3916 {
3917 APIRET rc;
[2]3918
[551]3919 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3920 if (!rc) {
3921 if (!ad->busy) {
3922 ad->wrapon = ad->wrapon ? FALSE : TRUE;
3923 WrapOn = ad->wrapon;
[191]3924 PrfWriteProfileData(fmprof, appname, "Viewer.WrapOn",
[551]3925 &ad->wrapon, sizeof(BOOL));
[191]3926 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3927 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3928 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
[551]3929 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
[191]3930 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
[551]3931 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
[191]3932 MPVOID, MPVOID);
[551]3933 ad->oldwidth = -1;
3934 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3935 MPFROM2SHORT(1, 1), MPVOID);
3936 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
[191]3937 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
[551]3938 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3939 MPFROM2SHORT(1, 1), MPVOID);
3940 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
[191]3941 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
[551]3942 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
[191]3943 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3944 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3945 NEWVIEW_DRAG), NULL, FALSE);
3946 }
[551]3947 DosReleaseMutexSem(ad->ScanSem);
[191]3948 }
3949 }
3950 break;
[2]3951
[191]3952 case IDM_HEXMODE:
3953 {
3954 APIRET rc;
[2]3955
[551]3956 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3957 if (!rc) {
3958 if (!ad->busy) {
3959 ad->hex = (ad->hex) ? FALSE : TRUE;
[191]3960 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
[551]3961 IDM_NEXTBLANKLINE), !ad->hex);
[191]3962 WinEnableWindow(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
[551]3963 IDM_PREVBLANKLINE), !ad->hex);
[191]3964 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
3965 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
3966 PostMsg(hwnd, UM_SETUP4, MPVOID, MPVOID);
[551]3967 if (WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX,
[191]3968 LM_QUERYITEMCOUNT, MPVOID, MPVOID))
[551]3969 WinSendDlgItemMsg(ad->hwndFrame, NEWVIEW_LISTBOX, LM_DELETEALL,
[191]3970 MPVOID, MPVOID);
[551]3971 ad->oldwidth = -1;
3972 WinSendMsg(ad->hvscroll, SBM_SETTHUMBSIZE,
3973 MPFROM2SHORT(1, 1), MPVOID);
3974 WinSendMsg(ad->hvscroll, SBM_SETSCROLLBAR,
[191]3975 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
[551]3976 WinSendMsg(ad->hhscroll, SBM_SETTHUMBSIZE,
3977 MPFROM2SHORT(1, 1), MPVOID);
3978 WinSendMsg(ad->hhscroll, SBM_SETSCROLLBAR,
[191]3979 MPFROMSHORT(1), MPFROM2SHORT(1, 1));
[551]3980 WinSendMsg(ad->hwndFrame, WM_UPDATEFRAME,
[191]3981 MPFROMLONG(FCF_SIZEBORDER), MPVOID);
3982 WinInvalidateRect(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3983 NEWVIEW_DRAG), NULL, FALSE);
3984 }
[551]3985 DosReleaseMutexSem(ad->ScanSem);
[191]3986 }
3987 }
3988 break;
[2]3989
[191]3990 case IDM_FONTPALETTE:
3991 {
3992 APIRET rc;
[2]3993
[551]3994 rc = DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN);
3995 if (!rc) {
[1893]3996 SetMLEFont(hwnd, &ad->fattrs, 3);
[191]3997 PrfWriteProfileData(fmprof, appname, "Viewer.Fattrs",
[551]3998 &ad->fattrs, sizeof(FATTRS));
3999 Fattrs = ad->fattrs;
[1433]4000 GpiDeleteSetId(ad->hps, NEWVIEWMLE_FONT_LCID);
[551]4001 GpiAssociate(ad->hps, 0);
4002 GpiDestroyPS(ad->hps);
4003 ad->hps = InitWindow(hwnd);
4004 DosReleaseMutexSem(ad->ScanSem);
[191]4005 WinSendMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
4006 WinInvalidateRect(hwnd, NULL, FALSE);
4007 }
[2]4008 }
4009 break;
4010
[191]4011 case IDM_HELP:
4012 if (hwndHelp)
4013 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
[551]4014 MPFROM2SHORT(HELP_NEWVIEW, 0), MPFROMSHORT(HM_RESOURCEID));
[2]4015 break;
[191]4016 }
4017 return 0;
[2]4018
[191]4019 case WM_SETFOCUS:
4020 if (mp2)
4021 WinSendMsg(hwnd, UM_SETUP5, MPVOID, MPVOID);
[551]4022 if (mp2 && ad && ad->needrefreshing && !ad->stopflag &&
4023 !DosRequestMutexSem(ad->ScanSem, SEM_IMMEDIATE_RETURN)) {
4024 ad->needrefreshing = FALSE;
4025 DosReleaseMutexSem(ad->ScanSem);
[191]4026 WinInvalidateRect(hwnd, NULL, TRUE);
4027 }
4028 break;
[2]4029
[191]4030 case WM_SIZE:
[551]4031 if (SHORT1FROMMP(mp2) && SHORT2FROMMP(mp2)) {
[191]4032 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
4033 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
4034 }
4035 break;
[2]4036
[191]4037 case WM_SAVEAPPLICATION:
[551]4038 if (ad && ParentIsDesktop(hwnd, ad->hwndParent)) {
[2]4039
[191]4040 SWP swp;
[2]4041
[551]4042 WinQueryWindowPos(ad->hwndFrame, &swp);
[191]4043 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
4044 PrfWriteProfileData(fmprof,
[551]4045 appname, "NewViewSizePos", &swp, sizeof(swp));
[191]4046 }
4047 break;
[2]4048
[191]4049 case WM_CLOSE:
4050 if (ad)
[551]4051 ad->stopflag = 1;
[191]4052 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
4053 return 0;
[2]4054
[191]4055 case WM_DESTROY:
4056 {
4057 BOOL dontclose = FALSE;
[551]4058 HWND hwndRestore = (HWND) 0;
[2]4059
[1444]4060 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_NEWVIEW_TIMER);
[551]4061 if (ad) {
4062 ad->stopflag = 1;
4063 if (ad->ScanSem) {
[771]4064 DosRequestMutexSem(ad->ScanSem, 15000);
[551]4065 DosCloseMutexSem(ad->ScanSem);
[191]4066 }
[551]4067 if (ad->busy)
[1880]4068 DosSleep(100);
[551]4069 if (ad->hps) {
[1433]4070 GpiDeleteSetId(ad->hps, NEWVIEWMLE_FONT_LCID);
[551]4071 GpiAssociate(ad->hps, 0);
4072 GpiDestroyPS(ad->hps);
[191]4073 }
[551]4074 hwndRestore = ad->hwndRestore;
4075 dontclose = ((ad->flags & 4) != 0) ? TRUE : FALSE;
[191]4076 FreeViewerMem(hwnd);
4077 WinSetWindowPtr(hwnd, QWL_USER, NULL);
[1039]4078 free(ad);
[2]4079 }
[551]4080 if (hwndRestore && hwndRestore != HWND_DESKTOP) {
[191]4081
4082 ULONG fl = SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER;
4083 SWP swp;
4084
[551]4085 if (WinQueryWindowPos(hwndRestore, &swp)) {
[191]4086 if (!(swp.fl & SWP_MAXIMIZE))
4087 fl |= SWP_RESTORE;
4088 WinSetWindowPos(hwndRestore, HWND_TOP, 0, 0, 0, 0, fl);
4089 }
4090 }
4091 if (!dontclose &&
4092 ParentIsDesktop(hwnd, WinQueryWindow(WinQueryWindow(hwnd,
[551]4093 QW_PARENT),
4094 QW_PARENT))) {
4095 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
[191]4096 DosExit(EXIT_PROCESS, 1);
4097 }
4098 }
4099 break;
[2]4100 }
4101
[191]4102 return WinDefWindowProc(hwnd, msg, mp1, mp2);
[2]4103}
4104
[191]4105HWND StartViewer(HWND hwndParent, USHORT flags, CHAR * filename,
4106 HWND hwndRestore)
[83]4107{
[551]4108 HWND hwndFrame = (HWND) 0, hwndClient;
[191]4109 VIEWDATA *ad;
4110 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
[551]4111 FCF_SIZEBORDER | FCF_MINMAX |
4112 FCF_NOBYTEALIGN | FCF_VERTSCROLL |
4113 FCF_MENU | FCF_ICON | FCF_ACCELTABLE | FCF_HORZSCROLL;
[2]4114
[191]4115 if (strcmp(realappname, FM3Str))
[2]4116 hwndParent = HWND_DESKTOP;
[191]4117 if (ParentIsDesktop(hwndParent, hwndParent))
[2]4118 FrameFlags |= FCF_TASKLIST;
4119 hwndFrame = WinCreateStdWindow(hwndParent,
[191]4120 0,
4121 &FrameFlags,
[1498]4122 (CHAR *) WC_NEWVIEW,
4123 (CHAR *) GetPString(IDS_FM2VIEWERTITLETEXT),
[191]4124 fwsAnimate,
[551]4125 FM3ModHandle, NEWVIEW_FRAME, &hwndClient);
4126 if (hwndFrame) {
[2]4127
[191]4128 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
[2]4129
[551]4130 if (!fToolbar && hwndMenu) {
[191]4131 WinSendMsg(hwndMenu, MM_DELETEITEM,
4132 MPFROM2SHORT(IDM_FINDFIRST, FALSE), MPVOID);
4133 WinSendMsg(hwndMenu, MM_DELETEITEM,
4134 MPFROM2SHORT(IDM_FINDNEXT, FALSE), MPVOID);
4135 WinSendMsg(hwndMenu, MM_DELETEITEM,
4136 MPFROM2SHORT(IDM_FINDPREV, FALSE), MPVOID);
4137 WinSendMsg(hwndMenu, MM_DELETEITEM,
4138 MPFROM2SHORT(IDM_SAVETOCLIP, FALSE), MPVOID);
[2]4139 }
[551]4140 ad = xmallocz(sizeof(VIEWDATA), pszSrcFile, __LINE__);
[350]4141 if (!ad) {
4142 WinDestroyWindow(hwndFrame);
[858]4143 hwndFrame = (HWND)0;
[350]4144 }
4145 else {
[551]4146 ad->size = sizeof(VIEWDATA);
4147 ad->stopflag = 0;
4148 ad->multiplier = 1;
4149 ad->hwndRestore = hwndRestore;
4150 ad->hwndFrame = hwndFrame;
4151 ad->hwndParent = hwndParent;
4152 ad->clientfocused = TRUE;
4153 ad->oldwidth = -1;
4154 strcpy(ad->filename, filename);
4155 ad->flags = flags;
4156 if (ad->flags & 16)
4157 ad->hex = TRUE;
[191]4158 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
[551]4159 if (Firsttime) {
[2]4160
[191]4161 ULONG size;
[2]4162
[191]4163 size = sizeof(BOOL);
4164 PrfQueryProfileData(fmprof, appname, "Viewer.Sensitive",
4165 (PVOID) & Sensitive, &size);
4166 size = sizeof(USHORT);
4167 PrfQueryProfileData(fmprof, appname, "Viewer.Codepage",
4168 (PVOID) & Codepage, &size);
4169 size = sizeof(BOOL);
4170 PrfQueryProfileData(fmprof, appname, "Viewer.LiteralSearch",
4171 (PVOID) & LiteralSearch, &size);
4172 size = sizeof(BOOL);
4173 PrfQueryProfileData(fmprof, appname, "Viewer.AlsoSelect",
4174 (PVOID) & AlsoSelect, &size);
4175 size = sizeof(BOOL);
4176 PrfQueryProfileData(fmprof, appname, "Viewer.WrapOn",
4177 (PVOID) & WrapOn, &size);
4178 size = sizeof(BOOL);
4179 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreFTP",
4180 (PVOID) & IgnoreFTP, &size);
4181 size = sizeof(BOOL);
4182 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreHTTP",
[1335]4183 (PVOID) & IgnoreHTTP, &size);
4184 size = sizeof(BOOL);
[890]4185 PrfQueryProfileData(fmprof, appname, "Viewer.IgnoreMail",
4186 (PVOID) & IgnoreMail, &size);
[191]4187 memset(&Fattrs, 0, sizeof(FATTRS));
4188 size = sizeof(FATTRS);
4189 Fattrs.usRecordLength = sizeof(FATTRS);
4190 Fattrs.lMaxBaselineExt = 16;
4191 Fattrs.lAveCharWidth = 8;
4192 Fattrs.usCodePage = Codepage;
4193 strcpy(Fattrs.szFacename, GetPString(IDS_SYSMONOTEXT));
4194 PrfQueryProfileData(fmprof, appname, "Viewer.Fattrs",
4195 (PVOID) & Fattrs, &size);
4196 size = sizeof(LONG) * COLORS_MAX;
4197 PrfQueryProfileData(fmprof, appname, "Viewer.Colors",
4198 (PVOID) Colors, &size);
4199 Firsttime = FALSE;
[2]4200 }
4201 {
[551]4202 ULONG size = sizeof(ad->searchtext);
[191]4203
4204 PrfQueryProfileData(fmprof, appname, "Viewer.Searchtext",
[551]4205 (PVOID) ad->searchtext, &size);
4206 ad->searchtext[sizeof(ad->searchtext) - 1] = 0;
[2]4207 }
[551]4208 ad->sensitive = Sensitive;
4209 ad->literalsearch = LiteralSearch;
4210 ad->fattrs = Fattrs;
4211 ad->alsoselect = AlsoSelect;
4212 ad->fattrs.usCodePage = Codepage;
4213 ad->wrapon = WrapOn;
4214 ad->ignorehttp = IgnoreHTTP;
4215 ad->ignoreftp = IgnoreFTP;
[890]4216 ad->ignoremail = IgnoreMail;
[551]4217 memcpy(ad->colors, Colors, sizeof(LONG) * COLORS_MAX);
[191]4218 WinSetWindowPtr(hwndClient, QWL_USER, (PVOID) ad);
[350]4219 if (!WinSendMsg(hwndClient, UM_SETUP, MPVOID, MPVOID))
[551]4220 hwndFrame = (HWND) 0;
[350]4221 else {
[551]4222 if (!(FrameFlags & FCF_TASKLIST) && !(flags & 2)) {
[191]4223 SWP swp;
[551]4224
[191]4225 FillClient(hwndParent, &swp, NULL, FALSE);
4226 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4227 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_RESTORE |
4228 SWP_ZORDER | SWP_ACTIVATE);
4229 }
[551]4230 else if (FrameFlags & FCF_TASKLIST) {
[2]4231
[191]4232 SWP swp, swpD;
4233 ULONG size = sizeof(swp);
4234 LONG cxScreen, cyScreen;
[2]4235
[191]4236 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
4237 if (PrfQueryProfileData(fmprof,
[551]4238 appname, "NewViewSizePos", &swpD, &size)) {
[191]4239 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
4240 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
4241 if (swp.x + swpD.cx > cxScreen)
4242 swp.x = cxScreen - swpD.cx;
4243 if (swp.y + swpD.cy > cyScreen)
4244 swp.y = cyScreen - swpD.cy;
4245 swp.cx = swpD.cx;
4246 swp.cy = swpD.cy;
4247 }
4248 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
4249 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
4250 SWP_ACTIVATE);
4251 }
[2]4252 }
4253 }
4254 }
4255 return hwndFrame;
4256}
[793]4257
4258#pragma alloc_text(NEWVIEW,ViewStatusProc,FreeViewerMem,LoadFileThread)
4259#pragma alloc_text(NEWVIEW,InitWindow,PaintLine,ViewWndProc)
4260#pragma alloc_text(NEWVIEW,ViewFrameWndProc,StartViewer,ReLineThread)
4261#pragma alloc_text(NEWVIEW,BuildAList,SearchThread,ClipboardThread,FindStrDlgProc)
4262#pragma alloc_text(NEWVIEW,BuildAList2,UrlDlgProc)
Note: See TracBrowser for help on using the repository browser.