source: trunk/dll/notify.c@ 1225

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

Ticket 187: Moved typedef's and some #define's from fm3dll.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.7 KB
RevLine 
[356]1/***********************************************************************
2
3 $Id: notify.c 1225 2008-09-13 23:12:12Z jbs $
4
[1002]5 Thread notes window and popup notification status line
[356]6
7 Copyright (c) 1993-98 M. Kimes
[1002]8 Copyright (c) 2006, 2008 Steven H.Levine
[356]9
10 17 Jul 06 SHL Use Win_Error
11 22 Jul 06 SHL Check more run time errors
[593]12 30 Mar 07 GKY Remove GetPString for window class names
[775]13 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
[793]14 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[1002]15 16 Apr 08 SHL Comment and clean up logic
[356]16
17***********************************************************************/
18
[2]19#include <stdlib.h>
20#include <string.h>
21#include <ctype.h>
[1163]22#include <stddef.h> // _threadid
23#include <process.h> // _beginthread
[356]24
[907]25#define INCL_DOS
26#define INCL_WIN
27#define INCL_GPI
[1163]28#define INCL_LONGLONG // dircnrs.h
[907]29
[1211]30#include "fm3dll.h"
[1225]31#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1211]32#include "collect.h" // Data declaration(s)
33#include "grep.h" // Data declaration(s)
34#include "notebook.h" // Data declaration(s)
35#include "init.h" // Data declaration(s)
[2]36#include "fm3dlg.h"
37#include "fm3str.h"
[1163]38#include "errutil.h" // Dos_Error...
39#include "strutil.h" // GetPString
40#include "notify.h"
[1188]41#include "presparm.h" // SetPresParams
[1211]42#include "mainwnd.h" // Data declaration(s)
[1188]43#include "wrappers.h" // xmalloc
44#include "misc.h" // PostMsg
[1038]45#include "fortify.h"
[2]46
47#pragma data_seg(DATA1)
[356]48
[1211]49// Data definitions
[356]50static PSZ pszSrcFile = __FILE__;
[1163]51static volatile HWND hwndNotify; // 16 Apr 08 SHL
[2]52
[1211]53#pragma data_seg(GLOBAL1)
54BOOL fThreadNotes;
55
[1163]56VOID StartNotes(CHAR * s);
57
[1002]58/**
59 * Popup notification message window procedure
60 * Display timed message over status line
61 */
62
[551]63MRESULT EXPENTRY NotifyWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[356]64{
[2]65 static ULONG showing = 0;
66
[551]67 switch (msg) {
68 case WM_CREATE:
69 showing++;
70 {
[1002]71 MRESULT rc = PFNWPStatic(hwnd, msg, mp1, mp2);
[2]72
[551]73 if (!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER2, 5000)) {
[1163]74 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinStartTimer");
75 WinDestroyWindow(hwnd);
[551]76 }
77 else {
[2]78
[1163]79 RGB2 rgb2F, rgb2;
[2]80
[1163]81 memset(&rgb2F, 0, sizeof(RGB2));
82 rgb2F.bRed = (BYTE)65;
83 rgb2.bRed = rgb2.bGreen = rgb2.bBlue = (BYTE)255;
84 rgb2.fcOptions = 0;
85 SetPresParams(hwnd, &rgb2, &rgb2F, &rgb2, GetPString(IDS_8HELVTEXT));
86 if (hwndMain) {
87 if (hwndStatus)
88 WinShowWindow(hwndStatus, FALSE);
89 if (hwndStatus2)
90 WinShowWindow(hwndStatus2, FALSE);
91 }
92 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
[2]93 }
[551]94 return rc;
95 }
[2]96
[551]97 case UM_SETUP:
98 WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_SHOW);
99 WinInvalidateRect(hwnd, NULL, FALSE);
100 return 0;
[2]101
[551]102 case WM_SETFOCUS:
103 if (mp2)
104 PostMsg(hwnd, UM_REPLACEFOCUS, mp1, MPVOID);
105 break;
[2]106
[551]107 case UM_REPLACEFOCUS:
108 if (mp1)
109 WinSetFocus(HWND_DESKTOP, (HWND) mp1);
110 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
111 return 0;
[2]112
[551]113 case WM_PAINT:
114 {
115 SWP swp;
116 POINTL ptl;
[2]117
[1002]118 MRESULT mr = PFNWPStatic(hwnd, msg, mp1, mp2);
119 HPS hps = WinGetPS(hwnd);
[551]120 if (hps) {
[1163]121 if (WinQueryWindowPos(hwnd, &swp)) {
122 ptl.x = 0;
123 ptl.y = 0;
124 GpiMove(hps, &ptl);
125 GpiSetColor(hps, CLR_RED);
126 ptl.x = swp.cx - 1;
127 ptl.y = swp.cy - 1;
128 GpiBox(hps, DRO_OUTLINE, &ptl, 2, 2);
129 }
130 WinReleasePS(hwnd);
[2]131 }
[551]132 return mr;
133 }
[2]134
[551]135 case WM_BUTTON1DOWN:
136 case WM_BUTTON2DOWN:
137 case WM_BUTTON3DOWN:
138 case WM_TIMER:
139 case WM_CLOSE:
140 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER2);
141 WinDestroyWindow(hwnd);
142 return 0;
[2]143
[551]144 case WM_DESTROY:
145 showing--;
146 if (!showing && hwndMain) {
147 if (hwndStatus)
[1163]148 WinShowWindow(hwndStatus, TRUE);
[551]149 if (hwndStatus2)
[1163]150 WinShowWindow(hwndStatus2, TRUE);
[551]151 }
152 break;
[2]153 }
[551]154 return PFNWPStatic(hwnd, msg, mp1, mp2);
[2]155}
156
[1002]157/**
158 * Display timed notification window over status line
159 */
160
[551]161HWND DoNotify(char *str)
[356]162{
[551]163 char *p;
164 HWND hwnd = (HWND) 0, hwndP;
165 LONG x, y, cx, cy;
166 SWP swp, swpS, swpS2;
[2]167 static USHORT id = NOTE_FRAME;
168
[551]169 if (str && *str) {
[1002]170 // figure out what size the window should be and where it should be
171 hwndP = hwndMain ? WinQueryWindow(hwndMain, QW_PARENT) : HWND_DESKTOP;
[551]172 WinQueryWindowPos(hwndP, &swp);
173 if (hwndStatus)
174 WinQueryWindowPos(hwndStatus, &swpS);
175 if (hwndStatus2)
176 WinQueryWindowPos(hwndStatus2, &swpS2);
[1002]177 x = hwndMain ? (hwndStatus ? swpS.x - 1 :
[1163]178 WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER)) : 0;
[1002]179 y = hwndMain ? (hwndStatus ? swpS.y - 1 :
[1163]180 WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER)) : 0;
[551]181 if (hwndMain && hwndStatus) {
182 if (hwndStatus2)
[1163]183 cx = swpS2.cx + swpS.cx + 8;
[2]184 else
[1163]185 cx = swpS.cx + 6;
[2]186 }
187 else
188 cx = (swp.cx - ((x * 2) + 4));
[1002]189 cy = hwndMain ? (hwndStatus ? swpS.cy + 2 : 28) : 28;
[2]190
[1002]191 // pretty-up the note by putting on a leading space
[551]192 if (*str != ' ') {
193 p = xmalloc(strlen(str) + 2, pszSrcFile, __LINE__);
194 if (!p)
[1163]195 p = str;
[2]196 else {
[1163]197 strcpy(p + 1, str);
198 *p = ' ';
[2]199 }
200 }
201 else
202 p = str;
203
204 hwnd = WinCreateWindow(hwndP,
[1163]205 WC_ERRORWND,
206 p,
207 SS_TEXT | DT_LEFT | DT_VCENTER | WS_VISIBLE,
208 x, y, cx, cy, hwndP, HWND_TOP, id++, NULL, NULL);
[377]209 if (!hwndP)
[551]210 Win_Error2(hwndP, hwndP, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
[377]211
[551]212 if (p != str)
[1039]213 free(p);
[551]214 if (id > NOTE_MAX)
[2]215 id = NOTE_FRAME;
216 }
217
218 AddNote(str);
219
220 return hwnd;
221}
222
[1002]223/**
224 * Add message to thread notes window
225 */
226
[551]227HWND Notify(char *str)
[356]228{
[1002]229 return (HWND)WinSendMsg(MainObjectHwnd, UM_NOTIFY, MPFROMP(str), MPVOID);
[2]230}
231
[1002]232/**
233 * Add error message to thread notes window
234 */
235
[551]236VOID NotifyError(CHAR * filename, APIRET status)
[356]237{
[2]238 CHAR errortext[512];
239
[551]240 if (!filename)
[2]241 return;
[551]242 sprintf(errortext, GetPString(IDS_ERRORACCESSTEXT), status, filename);
243 if (toupper(*filename) > 'B') {
244 if (status == 21)
245 strcat(errortext, GetPString(IDS_EMPTYREMOVETEXT));
246 else if (status == 27)
[2]247 strcat(errortext, GetPString(IDS_CDMUSICTEXT));
[551]248 else if (status == 19)
249 strcat(errortext, GetPString(IDS_WRITEPROTECTTEXT));
250 else if (status == 108)
251 strcat(errortext, GetPString(IDS_DRIVELOCKEDTEXT));
[2]252 }
253 else {
[551]254 if (status == 21)
255 strcat(errortext, GetPString(IDS_EMPTYFLOPPYTEXT));
256 else if (status == 27)
257 strcat(errortext, GetPString(IDS_UNFORMATEDTEXT));
258 else if (status == 107)
[2]259 sprintf(&errortext[strlen(errortext)],
[1163]260 GetPString(IDS_PHANTOMTEXT), toupper(*filename));
[551]261 else if (status == 19)
262 strcat(errortext, GetPString(IDS_DISKWRITEPROTEXTTEXT));
263 else if (status == 108)
264 strcat(errortext, GetPString(IDS_DISKLOCKEDTEXT));
[2]265 }
[551]266 DosBeep(250, 10);
267 DosBeep(500, 10);
268 DosBeep(250, 10);
269 DosBeep(500, 10);
[2]270 Notify(errortext);
271}
272
[1002]273/**
274 * Thread notes dialog window dialog procedure
275 */
276
[551]277MRESULT EXPENTRY NoteWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[356]278{
[551]279 static HPOINTER hptrIcon = (HPOINTER) 0;
[2]280
[551]281 switch (msg) {
282 case WM_INITDLG:
[1002]283 if (hwndNotify != (HWND)0) {
284 // Already have notes dialog - pass message on
[551]285 if (mp2) {
[1163]286 WinSendDlgItemMsg(hwndNotify,
287 NOTE_LISTBOX,
288 LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), mp2);
289 PostMsg(hwndNotify, UM_NOTIFY, MPVOID, MPVOID);
290 free((CHAR *)mp2);
[2]291 }
[551]292 WinDismissDlg(hwnd, 0);
293 break;
294 }
295 hwndNotify = hwnd;
296 fThreadNotes = FALSE;
[1002]297 // Remember showing
[551]298 {
299 BOOL dummy = TRUE;
300 PrfWriteProfileData(fmprof,
[1163]301 FM3Str, "ThreadNotes", &dummy, sizeof(BOOL));
[551]302 }
303 if (mp2) {
304 WinSendDlgItemMsg(hwnd,
[1163]305 NOTE_LISTBOX,
306 LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), mp2);
[1039]307 free((CHAR *)mp2);
[551]308 }
[1002]309
[551]310 {
[1002]311 // Return focus
312 HWND hwndActive = WinQueryActiveWindow(HWND_DESKTOP);
[551]313 PostMsg(hwnd, UM_FOCUSME, MPFROMLONG(hwndActive), MPVOID);
314 }
[1002]315
[551]316 hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, NOTE_FRAME);
317 if (hptrIcon)
318 WinDefDlgProc(hwnd, WM_SETICON, MPFROMLONG(hptrIcon), MPFROMLONG(0L));
319 break;
[2]320
[551]321 case UM_FOCUSME:
322 {
323 ULONG size = sizeof(SWP),
[1163]324 fl = SWP_ZORDER | SWP_FOCUSDEACTIVATE | SWP_SHOW;
[551]325 SWP swp;
[2]326
[551]327 if (PrfQueryProfileData(fmprof,
[1163]328 FM3Str, "NoteWndSwp", (PVOID) & swp, &size)) {
329 if (swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
330 fl |= SWP_MINIMIZE;
331 fl &= (~SWP_SHOW);
332 }
333 else
334 fl |= (SWP_MOVE | SWP_SIZE);
[2]335 }
[551]336 WinSetWindowPos(hwnd, HWND_BOTTOM, swp.x, swp.y, swp.cx, swp.cy, fl);
337 if (fl & SWP_MINIMIZE) {
[1163]338 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT) swp.x);
339 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT) swp.cx);
340 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT) swp.y);
341 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT) swp.cy);
[551]342 }
343 }
344 if (mp1)
345 WinSetActiveWindow(HWND_DESKTOP, (HWND) mp1);
346 return 0;
[2]347
[551]348 case UM_STRETCH:
349 {
350 SWP swp;
351 LONG titl, szbx, szby;
[2]352
[551]353 WinQueryWindowPos(hwnd, &swp);
354 if (!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
[1163]355 szbx = SysVal(SV_CXSIZEBORDER);
356 szby = SysVal(SV_CYSIZEBORDER);
357 titl = SysVal(SV_CYTITLEBAR);
358 WinSetWindowPos(WinWindowFromID(hwnd, NOTE_LISTBOX),
359 HWND_TOP,
360 szbx,
361 szby,
362 swp.cx - (szbx * 2L),
363 (swp.cy - titl) - (szby * 2L), SWP_MOVE | SWP_SIZE);
[2]364 }
[551]365 if (!(swp.fl & SWP_MAXIMIZE)) {
[1163]366 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
367 swp.x = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
368 swp.y = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
369 swp.cx = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
370 swp.cy = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
371 }
372 PrfWriteProfileData(fmprof,
373 FM3Str, "NoteWndSwp", (PVOID) & swp, sizeof(SWP));
[551]374 }
375 }
376 return 0;
[2]377
[551]378 case WM_ADJUSTWINDOWPOS:
379 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
380 break;
[2]381
[551]382 case UM_CONTAINER_FILLED:
383 {
[1002]384 SHORT y;
385 SHORT x = (SHORT)WinSendDlgItemMsg(hwnd,
[1163]386 NOTE_LISTBOX,
387 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
[551]388 if (x > 60) {
[1163]389 for (y = 0; y < x - 50; y++) {
390 WinSendDlgItemMsg(hwnd,
391 NOTE_LISTBOX,
392 LM_DELETEITEM, MPFROMSHORT(y), MPVOID);
393 }
[2]394 }
[551]395 }
396 return 0;
[2]397
[551]398 case UM_NOTIFY:
399 {
[1002]400 SHORT x = (SHORT) WinSendDlgItemMsg(hwnd,
[1163]401 NOTE_LISTBOX,
402 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
[551]403 if (x > 0)
[1163]404 WinSendDlgItemMsg(hwnd,
405 NOTE_LISTBOX,
406 LM_SETTOPINDEX, MPFROMSHORT(x), MPVOID);
[551]407 }
408 return 0;
[2]409
[551]410 case UM_SHOWME:
411 WinSetWindowPos(hwnd,
[1163]412 HWND_TOP,
413 0,
414 0,
415 0, 0, SWP_SHOW | SWP_RESTORE | SWP_ZORDER | SWP_ACTIVATE);
[551]416 return 0;
[2]417
[551]418 case WM_COMMAND:
419 return 0;
[2]420
[551]421 case WM_CLOSE:
422 WinDismissDlg(hwnd, 0);
423 return 0;
[2]424
[551]425 case WM_DESTROY:
426 if (hwndNotify == hwnd) {
427 fThreadNotes = FALSE;
428 PrfWriteProfileData(fmprof,
[1163]429 FM3Str, "ThreadNotes", &fThreadNotes, sizeof(BOOL));
[551]430 hwndNotify = (HWND) 0;
431 }
432 if (hptrIcon)
433 WinDestroyPointer(hptrIcon);
434 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
435 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
436 break;
[2]437 }
[551]438 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]439}
440
[1002]441/**
442 * Thread notes dialog window thread
443 */
444
[551]445static VOID NoteThread(VOID * args)
[356]446{
[1002]447 HAB hab = WinInitialize(0);
[1038]448# ifdef FORTIFY
449 Fortify_EnterScope();
[1063]450# endif
[1002]451 if (hab) {
452 HMQ hmq = WinCreateMsgQueue(hab, 0);
453 if (hmq) {
[551]454 if (!hwndNotify)
[1163]455 WinDlgBox(HWND_DESKTOP,
456 HWND_DESKTOP,
457 NoteWndProc, FM3ModHandle, NOTE_FRAME, (CHAR *)args);
[1002]458 WinDestroyMsgQueue(hmq);
[2]459 }
[1002]460 WinTerminate(hab);
[2]461 }
[1038]462# ifdef FORTIFY
[1063]463 Fortify_LeaveScope();
464# endif
[2]465}
466
[1002]467/**
468 * Start thread notes dialog window thread
469 */
470
[551]471VOID StartNotes(CHAR * note)
[356]472{
473 if (!hwndNotify) {
[551]474 if (_beginthread(NoteThread, NULL, 65536, (PVOID) note) == -1)
[1002]475 Runtime_Error2(pszSrcFile, __LINE__, IDS_COULDNTSTARTTHREADTEXT);
476 else {
477 USHORT i;
478 for (i = 0; !hwndNotify && i < 10; i++)
[1163]479 DosSleep(10);
[1002]480 if (!hwndNotify)
[1163]481 Runtime_Error(pszSrcFile, __LINE__, "Can not create Notify window");
[1002]482 }
[2]483 }
484}
485
[1002]486/**
487 * Add note to thread notes window or popup status window
488 */
489
[551]490BOOL AddNote(CHAR * note)
[356]491{
[551]492 CHAR *s, *p;
493 BOOL once = FALSE, ret = FALSE;
[2]494
[551]495 if ((fThreadNotes || hwndNotify) && note && *note) {
[2]496 p = note;
[551]497 while (*p == ' ')
[2]498 p++;
[551]499 if (*p) {
500 if (!hwndNotify) {
[1163]501 fThreadNotes = FALSE;
502 StartNotes(NULL);
[2]503 }
[551]504 if (hwndNotify) {
[1163]505 s = xmalloc(strlen(p) + 14, pszSrcFile, __LINE__);
506 if (s) {
507 sprintf(s, "%08lx %s", _threadid, p);
508 while (!once) {
509 if ((SHORT) WinSendDlgItemMsg(hwndNotify,
510 NOTE_LISTBOX,
511 LM_INSERTITEM,
512 MPFROM2SHORT(LIT_END, 0),
513 MPFROMP(s)) >= 0) {
514 ret = TRUE;
515 PostMsg(hwndNotify, UM_NOTIFY, MPVOID, MPVOID);
516 break;
517 }
518 PostMsg(hwndNotify, UM_CONTAINER_FILLED, MPVOID, MPVOID);
519 once = TRUE;
[1039]520 }
521 free(s);
[1163]522 }
[2]523 }
524 }
525 }
526 return ret;
527}
528
[1002]529/**
530 * Close thread notes window
531 */
532
[551]533VOID EndNote(VOID)
[356]534{
[551]535 if (hwndNotify)
536 if (!PostMsg(hwndNotify, WM_CLOSE, MPVOID, MPVOID))
537 WinSendMsg(hwndNotify, WM_CLOSE, MPVOID, MPVOID);
[2]538}
539
[1002]540/**
541 * Pop up thread notes window
542 */
543
[551]544VOID ShowNote(VOID)
[356]545{
[551]546 if (!hwndNotify)
[2]547 StartNotes(NULL);
[551]548 if (hwndNotify)
549 PostMsg(hwndNotify, UM_SHOWME, MPVOID, MPVOID);
[2]550}
551
[1002]552/**
553 * Hide thread notes window
554 */
555
[551]556VOID HideNote(VOID)
[356]557{
[551]558 if (hwndNotify)
[2]559 WinSetWindowPos(hwndNotify,
[1163]560 HWND_BOTTOM,
561 0,
562 0, 0, 0, SWP_MINIMIZE | SWP_ZORDER | SWP_FOCUSDEACTIVATE);
[2]563}
[793]564
[1038]565#pragma alloc_text(NOTIFY,Notify,NotifyWndProc,StartNotify,NotifyError)
[793]566#pragma alloc_text(NOTIFY2,AddNote,NoteThread,NoteWndProc)
567#pragma alloc_text(NOTIFY3,StartNotes,EndNote,HideNote,ShowNote)
Note: See TracBrowser for help on using the repository browser.