|
|
1.1 root 1: #define NORASTEROPS
2: #define NOSYSCOMMANDS
3: #include "cardfile.h"
4:
5: /*********************************************************************/
6: /* Windows/PM Cardfile Shared Code */
7: /* */
8: /* (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved */
9: /*********************************************************************/
10:
11: /*********************************************************************/
12: /* The following shared code was developed from the original */
13: /* Cardfile application. This code can be compiled to run under */
14: /* either the Windows or the PM manager environment. All */
15: /* functionality associated with bitmaps or printing has been */
16: /* deleted. Some comments refering to these functions may still be */
17: /* present in the code and should be disregarded. jw. */
18: /*********************************************************************/
19:
20:
21: /*********************************************************************/
22: /* CardfileInput - */
23: /* This routine handles all the menu commands in Cardfile. */
24: /* */
25: /* Slightly different for PM and Windows */
26: /*********************************************************************/
27:
28: void CardfileInput(hWindow, event)
29: HWND hWindow;
30: int event;
31: {
32: PSTR pchBuf;
33: PSTR pchFile;
34: LPCARDHEADER lpCards;
35: unsigned long lTemp;
36: OFSTRUCT ofStruct;
37:
38: /* which menu command was it */
39: switch(event)
40: {
41: case IDM_ABOUT:
42: /* about dialog box */
43: PutUpDB(DTABOUT);
44: break;
45: case IDM_NEW:
46: /* create a new cardfile */
47: if (fReadOnly)
48: break;
49:
50: /* make sure we save any changes the user made */
51: if (!MaybeSaveFile())
52: /* the user cancelled in the save changes dialog */
53: break;
54:
55:
56: CurIFile[0] = 0;
57: CurIFind[0] = 0;
58: SetCaption();
59:
60: /* get rid of the old temp file */
61: Fdelete(TmpFile);
62:
63: /* create a new one */
64: MakeTmpFile();
65:
66: /* there's only one card in a new cardfile shrinking */
67: /* or leaving the same size, so this should always work */
68: GlobalReAlloc(hCards, (long)sizeof(CARDHEADER),GMEM_MOVEABLE);
69: cCards = 1;
70: iFirstCard = 0;
71: iTopCard = 0;
72: SetScrRangeAndPos();
73:
74: /* Set up CurCardHead */
75: MakeBlankCard();
76:
77: /* Save blank card in data structure */
78: lpCards = (LPCARDHEADER) GlobalLock(hCards);
79: *lpCards = CurCardHead;
80: GlobalUnlock(hCards);
81:
82: /* when in phone book mode, not making changes so must */
83: /* save now */
84: if (CardPhone == IDM_PHONEBOOK)
85: SaveCurrentCard(iFirstCard);
86:
87: /* make sure the window gets repainted */
88: InvalidateRect(hWindow, (LPRECT)NULL, TRUE);
89:
90: /* clean file */
91: fFileDirty = FALSE;
92:
93: /* make sure that any selection gets repainted for empty card */
94: if (CardPhone == IDM_CARDFILE)
95: {
96: SetFocus(NULL);
97: SetFocus(hCardWnd);
98: }
99: break;
100:
101: case IDM_OPEN:
102: /* opening an existing file */
103: /* make sure that any changes get saved */
104: if(MaybeSaveFile())
105: {
106: /* put up dialog box, and if user hits ok, open file */
107: if (pchBuf = PutUpDB(DTOPEN))
108: {
109: if (!DoOpen(pchBuf))
110: SetCurCard(iFirstCard);
111: LocalFree((HANDLE)pchBuf);
112: }
113: else
114: /* user cancelled open dialog box */
115: SetCurCard(iFirstCard);
116: }
117: break;
118:
119: case IDM_MERGE:
120: /* merge in another file */
121: DoMerge();
122: break;
123:
124: case IDM_SAVE:
125: case IDM_SAVEAS:
126: /* save the file */
127: pchFile = NULL;
128: /* if doing a SAVE, and file is named, use current name */
129: if (event == IDM_SAVE && CurIFile[0])
130: pchFile = CurIFile;
131: /* else ask the user for a name */
132: else if (GetNewFileName(&ofStruct))
133: pchFile = ofStruct.szPathName;
134: /* if there is a name to save it to */
135: if (pchFile)
136: {
137: /* get the current selection if in cardfile mode */
138: if (CardPhone == IDM_CARDFILE)
139: lTemp = SendMessage(hCardWnd, EM_GETSEL, 0, 0L);
140: /* if in phonebook mode, or if in cardfile mode and */
141: /* able to save the front card */
142: if (CardPhone == IDM_PHONEBOOK ||
143: SaveCurrentCard(iFirstCard))
144: {
145: /* write the file out */
146: if (WriteCardFile(pchFile))
147: {
148: /* reset the caption */
149: SetCaption();
150: /* start a new temp file */
151: Fdelete(TmpFile);
152: MakeTmpFile();
153: }
154: /* if in cardfile mode */
155: if (CardPhone == IDM_CARDFILE)
156: {
157: /* get contents of front card again, and set */
158: /* selection*/
159: SetCurCard(iFirstCard);
160: #ifdef IN_WINDOWS
161: /* Unfortunately, the parameters for the EM_SETSEL */
162: /* message are reversed in PM and Windows - the */
163: /* easiest way to deal with this is to have */
164: /* separate SendMessage calls */
165:
166: SendMessage(hCardWnd, EM_SETSEL, 0, lTemp);
167: #else
168: SendMessage(hCardWnd, EM_SETSEL, lTemp, 0L);
169: #endif
170: }
171: }
172: }
173: break;
174:
175: case IDM_CARDFILE:
176: case IDM_PHONEBOOK:
177: /* change display modes */
178: if (event != CardPhone)
179: {
180: /* if changing to phonebook */
181: if (event == IDM_PHONEBOOK)
182: {
183: /* save data in card */
184: if (!SaveCurrentCard(iFirstCard))
185: /* if it doesn't work, stop */
186: break;
187: }
188: /* else changing to cardfile mode */
189: else
190: {
191: /* set the text in the front card */
192: SetCurCard(iFirstCard);
193: }
194: /* save new mode */
195: CardPhone = event;
196: /* turn off old scroll bar */
197: /* This define calls SetScrollRange and SetScrollPos */
198: SCROLL_RANGE(hWindow, event == IDM_PHONEBOOK ?
199: SB_HORZ : SB_VERT, 0, 0, 0);
200:
201: /* if phonebook, get rid of edit control, otherwise reactivate */
202: ShowWindow(hCardWnd,
203: event == IDM_PHONEBOOK ? HIDE_WINDOW : SHOW_OPENWINDOW);
204:
205: #ifdef IN_WINDOWS
206: /* In PM, the way in which the update is turned off is */
207: /* through a function. There is no easy way to have */
208: /* the SendMessage calls in Windows map into separate */
209: /* functions in PM, so they are in #ifdefs */
210:
211: SendMessage(hCardWnd, WM_SETREDRAW,
212: event == IDM_CARDFILE, 0L);
213: #else
214: WinEnableWindowUpdate( hCardWnd, event == IDM_CARDFILE );
215: #endif
216:
217: /* if phonbook, make sure that topcard is valid */
218: if (event == IDM_PHONEBOOK)
219: SetTopCard();
220: /* set up new scroll bar */
221: SetScrRangeAndPos();
222: /* set focus to right place */
223: SetFocus(event == IDM_PHONEBOOK ? hCardfileWnd : hCardWnd);
224: /* force a repaint */
225: InvalidateRect(hWindow, (LPRECT)NULL, TRUE);
226: }
227: break;
228: case IDM_HEADER:
229: /* if in phone book mode, make sure information is in right place */
230: if (CardPhone == IDM_PHONEBOOK)
231: {
232: SetCurCard(iFirstCard);
233: SaveCurrentCard(iFirstCard);
234: }
235: /* put up dialog box */
236: if(pchBuf = PutUpDB(DTHEADER))
237: {
238: /* save new header */
239: Mylstrcpy((LPSTR)CurCardHead.line, (LPSTR)pchBuf);
240:
241: /* take it out of it's current position */
242: DeleteCard(iFirstCard);
243:
244: /* and put it back in the right place */
245: iFirstCard = AddCurCard();
246:
247: SetScrRangeAndPos(); /* set position */
248: fFileDirty = TRUE;
249: InvalidateRect(hWindow, (LPRECT)NULL, TRUE);
250: LocalFree((HANDLE)pchBuf);
251: }
252: break;
253:
254: case IDM_RESTORE:
255: /* get the old information */
256: SetCurCard(iFirstCard);
257: InvalidateRect(hCardWnd, (LPRECT)NULL, TRUE);
258: break;
259:
260: case IDM_CUT:
261: case IDM_COPY:
262: DoCutCopy(event);
263: break;
264:
265: case IDM_PASTE:
266: DoPaste();
267: break;
268:
269: case IDM_ADD:
270: /* get the new header for the new card */
271: if(pchBuf = PutUpDB(DTADD))
272: {
273: /* allocate space for new card */
274: lTemp = (cCards+1) * sizeof(CARDHEADER);
275: if (!GlobalReAlloc(hCards, lTemp,GMEM_MOVEABLE))
276: CardfileOkError(IDS_EINSMEMORY);
277: else
278: {
279: /* if in phone book mode, or can save current card */
280: if (CardPhone == IDM_PHONEBOOK ||
281: SaveCurrentCard(iFirstCard))
282: {
283: /* make a blank card */
284: MakeBlankCard();
285:
286: /* save the header */
287: Mylstrcpy((LPSTR)CurCardHead.line, (LPSTR)pchBuf);
288:
289: /* the card is dirty */
290: CurCardHead.flags |= (FDIRTY + FNEW);
291:
292: /* add the card */
293: iFirstCard = AddCurCard();
294:
295: /* make sure that top card is correct */
296: if (CardPhone == IDM_PHONEBOOK)
297: SetTopCard();
298:
299: /* set new scroll information */
300: SetScrRangeAndPos();
301:
302: /* if in phone book mode, need to save immediately */
303: if (CardPhone == IDM_PHONEBOOK)
304: SaveCurrentCard(iFirstCard);
305:
306: /* else, force redraw of correct highlighting */
307: else
308: {
309: SetFocus(NULL);
310: SetFocus(hCardWnd);
311: }
312:
313: /* force repaint */
314: InvalidateRect(hWindow, (LPRECT)NULL, TRUE);
315: }
316: }
317: LocalFree((HANDLE)pchBuf);
318: }
319: break;
320:
321: case IDM_DELETE:
322: /* if in phone book mode */
323: if (CardPhone == IDM_PHONEBOOK)
324: {
325: /* get information */
326: SetCurCard(iFirstCard);
327:
328: /* save it in case of cancel */
329: SaveCurrentCard(iFirstCard);
330: }
331:
332: /* ask user for confirmation */
333: if (MyMessageBox(IDS_DELCURCARD,
334: CurCardHead.line,
335: MB_OKCANCEL | MB_ICONQUESTION | MB_DEFBUTTON2) == IDOK)
336: {
337:
338: /* if not last card */
339: if (cCards > 1)
340: {
341: /* get rid of it */
342: DeleteCard(iFirstCard);
343: if (iFirstCard == cCards)
344: if (CardPhone == IDM_CARDFILE)
345: iFirstCard = 0;
346: else
347: iFirstCard = cCards-1;
348:
349: /* change scroll information */
350: SetScrRangeAndPos();
351:
352: /* if in card mode, get card's information */
353: if (CardPhone == IDM_CARDFILE)
354: SetCurCard(iFirstCard);
355:
356: /* shrinking, so don't have to check */
357: lTemp = cCards * sizeof(CARDHEADER);
358: GlobalReAlloc(hCards, lTemp, GMEM_MOVEABLE);
359: }
360: /* else, last card */
361: else
362: {
363: /* make it blank */
364: MakeBlankCard();
365:
366: /* store the info */
367: lpCards = (LPCARDHEADER) GlobalLock(hCards);
368: *lpCards = CurCardHead;
369: GlobalUnlock(hCards);
370:
371: /* save the info in phonebook mode */
372: if (CardPhone == IDM_PHONEBOOK)
373: SaveCurrentCard(iFirstCard);
374: }
375: /* dirty file and window */
376: fFileDirty = TRUE;
377: InvalidateRect(hWindow, (LPRECT)NULL, TRUE);
378: }
379: break;
380:
381: case IDM_DUPLICATE:
382: /* make sure there's room */
383: lTemp = (cCards + 1) * sizeof(CARDHEADER);
384: if (!GlobalReAlloc(hCards, lTemp, GMEM_MOVEABLE))
385: CardfileOkError(IDS_EINSMEMORY);
386: else
387: {
388: /* there is, save current card */
389: if (CardPhone == IDM_PHONEBOOK ||
390: SaveCurrentCard(iFirstCard))
391: {
392: /* get information */
393: SetCurCard(iFirstCard);
394: CurCardHead.flags |= (FDIRTY + FNEW);
395:
396: /* add it */
397: iFirstCard = AddCurCard();
398: if (CardPhone == IDM_PHONEBOOK)
399: {
400: SaveCurrentCard(iFirstCard);
401: SetTopCard();
402: }
403:
404: /* set new scroll information */
405: SetScrRangeAndPos();
406: InvalidateRect(hWindow, (LPRECT)NULL, TRUE);
407: fFileDirty = TRUE;
408: }
409: }
410: break;
411:
412: case IDM_GOTO:
413: /* search headers */
414: if (pchBuf = PutUpDB(DTGOTO))
415: {
416: DoGoto(pchBuf);
417: LocalFree((HANDLE)pchBuf);
418: }
419: break;
420:
421: case IDM_FINDNEXT:
422: /* search body of card */
423: if (CurIFind[0])
424: {
425: FindStrCard();
426: break;
427: }
428:
429: case IDM_FIND:
430: /* search for a pattern */
431: if(pchBuf = PutUpDB(DTFIND))
432: {
433: /* save the pattern */
434: Mylstrcpy((LPSTR)CurIFind, (LPSTR)pchBuf);
435: FindStrCard();
436: LocalFree((HANDLE)pchBuf);
437: }
438: break;
439:
440: default:
441: break;
442: }
443: }
444:
445: /*********************************************************************/
446: /* SetTopCard - */
447: /* This routine is called in phone mode to figure out which */
448: /* header should appear at the top of the window */
449: /* */
450: /* Slightly different for PM and Windows */
451: /*********************************************************************/
452:
453: void SetTopCard()
454: {
455: RECT rect;
456: int i;
457:
458: GetClientRect(hCardfileWnd, (LPRECT)&rect);
459:
460: #ifdef IN_WINDOWS
461: /* In PM, the height of a window after a GetClientRect call is */
462: /* stored in yTop (the origin is based on the bottom */
463:
464: i = rect.bottom / CharFixHeight;
465: #else
466: i = rect.yTop / CharFixHeight;
467: #endif
468:
469: if (!i)
470: i = 1;
471: iTopCard = min(iFirstCard-(i-1)/2, (cCards - i));
472: if (iTopCard < 0)
473: iTopCard = 0;
474: }
475:
476: /*********************************************************************/
477: /* PutUpDB - */
478: /* Calls routine to put up requested dialog box */
479: /* */
480: /* Same for PM and Windows */
481: /*********************************************************************/
482:
483: PSTR PutUpDB(idb)
484: int idb;
485: {
486: FARPROC lpdbProc;
487:
488: DBcmd = idb;
489: switch(idb)
490: {
491: case DTMERGE:
492: case DTOPEN:
493: lpdbProc = lpfnOpen;
494: break;
495: case DTSAVE:
496: lpdbProc = lpfnSave;
497: break;
498: case DTABOUT:
499: lpdbProc = lpfnAbout;
500: break;
501: default:
502: lpdbProc = lpDlgProc;
503: break;
504: }
505: return((PSTR)DialogBox(hCardfileInstance,
506: MAKEINTRESOURCE(idb), hCardfileWnd, lpdbProc));
507: }
508:
509: /*********************************************************************/
510: /* UpdateMenu - */
511: /* This routine initializes the menu every time it is about */
512: /* to be displayed for the user */
513: /* */
514: /* Same for PM and Windows */
515: /*********************************************************************/
516:
517: void UpdateMenu()
518: {
519: HMENU hMenu;
520: long lSelection;
521: int wFmt;
522: int mfPaste;
523:
524: hMenu = GetMenu(hCardfileWnd);
525: CheckMenuItem(hMenu, IDM_CARDFILE,
526: CardPhone == IDM_CARDFILE ? MF_CHECKED : MF_UNCHECKED);
527: CheckMenuItem(hMenu, IDM_PHONEBOOK,
528: CardPhone == IDM_PHONEBOOK ? MF_CHECKED : MF_UNCHECKED);
529:
530: if (CardPhone == IDM_CARDFILE)
531: {
532: mfPaste = MF_GRAYED;
533: if (OpenClipboard(hCardfileWnd))
534: {
535: wFmt = 0;
536:
537: while (wFmt = EnumClipboardFormats(wFmt))
538: {
539: if (wFmt == CF_TEXT)
540: {
541: mfPaste = MF_ENABLED;
542: break;
543: }
544: }
545:
546: CloseClipboard();
547: }
548: EnableMenuItem(hMenu, IDM_PASTE, mfPaste);
549:
550: EnableMenuItem(hMenu, IDM_RESTORE, MF_ENABLED);
551: EnableMenuItem(hMenu, IDM_FIND, MF_ENABLED);
552: EnableMenuItem(hMenu, IDM_FINDNEXT, MF_ENABLED);
553:
554: lSelection = SendMessage(hCardWnd, EM_GETSEL, 0, 0L);
555: if (HIWORD(lSelection) == LOWORD(lSelection))
556: {
557: EnableMenuItem(hMenu, IDM_CUT, MF_GRAYED);
558: EnableMenuItem(hMenu, IDM_COPY, MF_GRAYED);
559: }
560: else
561: {
562: EnableMenuItem(hMenu, IDM_CUT, MF_ENABLED);
563: EnableMenuItem(hMenu, IDM_COPY, MF_ENABLED);
564: }
565: }
566: else
567: {
568: EnableMenuItem(hMenu, IDM_RESTORE, MF_GRAYED);
569: EnableMenuItem(hMenu, IDM_CUT, MF_GRAYED);
570: EnableMenuItem(hMenu, IDM_COPY, MF_GRAYED);
571: EnableMenuItem(hMenu, IDM_PASTE, MF_GRAYED);
572: EnableMenuItem(hMenu, IDM_FIND, MF_GRAYED);
573: EnableMenuItem(hMenu, IDM_FINDNEXT, MF_GRAYED);
574: }
575: }
576:
577:
578: /*********************************************************************/
579: /* SetEditText - */
580: /* This routine sets the contents of the edit control */
581: /* */
582: /* Same for PM and Windows */
583: /*********************************************************************/
584:
585: void FAR SetEditText(lpText)
586: LPSTR lpText;
587: {
588: SetWindowText(hCardWnd, lpText);
589: #ifndef IN_WINDOWS
590: /* In PM, the Edit control doesn't initialize the modify flag to */
591: /* False after a SetWindowText call. Read state of modify flag */
592: /* to reset the flag. */
593:
594: SendMessage(hCardWnd, EM_GETMODIFY, 0, 0L);
595: #endif
596: }
597:
598:
599: /*********************************************************************/
600: /* CardfileMouse - */
601: /* This handles all mouse input to main window. Mouse input in */
602: /* the edit control will get sent to CardWndProc */
603: /* */
604: /* Same for PM and Windows */
605: /*********************************************************************/
606:
607: void CardfileMouse(hWindow, message, pt)
608: HWND hWindow;
609: int message;
610: POINT pt;
611: {
612: RECT rect;
613: int iCard;
614: HDC hDC;
615: int y;
616: MSG msg;
617:
618: if (CardPhone == IDM_CARDFILE)
619: {
620: /* see if click on a card or background */
621: if ((iCard = MapPtToCard(pt)) > -1)
622: {
623: /* if on another card */
624: if (iCard != iFirstCard)
625: {
626: /* bring it to front */
627: CardfileScroll(hCardfileWnd, SB_THUMBTRACK, iCard);
628: CardfileScroll(hCardfileWnd, SB_THUMBPOSITION, iCard);
629: }
630: /* else if double click on first */
631: else if (message == WM_LBUTTONDBLCLK)
632: {
633: /* bring up header box */
634: SetCapture(hCardfileWnd);
635: while(GetKeyState(VK_LBUTTON) < 0)
636: {
637: PeekMessage((LPMSG)&msg, NULL, WM_MOUSEFIRST,
638: WM_MOUSELAST, TRUE);
639: PeekMessage((LPMSG)&msg, NULL, WM_KEYFIRST,
640: WM_KEYLAST, TRUE);
641: }
642: ReleaseCapture();
643: CardfileInput(hWindow, IDM_HEADER);
644: }
645: }
646: }
647: else /* phone book mode */
648: {
649: /* figure out which header the user clicked on */
650: TRANSLATE_COORDS( cyMainWindow );
651:
652: iCard = iTopCard + (TRANSLATE_Y(pt.y) / CharFixHeight);
653: if (message == WM_LBUTTONDOWN || iCard != iFirstCard)
654: {
655: /* single click, change selection */
656: if (iCard < cCards)
657: {
658: y = (iFirstCard - iTopCard) * CharFixHeight;
659: hDC = GetDC(hWindow);
660: SetRect((LPRECT)&rect, 0, y,
661: (LINELENGTH+2)*CharFixWidth, y+CharFixHeight);
662: TRANSLATE_RECT( rect );
663:
664: InvertRect(hDC, (LPRECT)&rect);
665: iFirstCard = iCard;
666: y = (iFirstCard - iTopCard) * CharFixHeight;
667: SetRect((LPRECT)&rect, 0, y,
668: (LINELENGTH+2)*CharFixWidth, y+CharFixHeight);
669: TRANSLATE_RECT( rect );
670:
671: InvertRect(hDC, (LPRECT)&rect);
672: ReleaseDC(hWindow, hDC);
673: }
674: }
675: else /* double click on cur card */
676: {
677: /* bring up header box */
678: if (iCard < cCards)
679: {
680: while(!PeekMessage((LPMSG)&msg, NULL, WM_LBUTTONUP,
681: WM_LBUTTONUP, TRUE))
682: ;
683: CardfileInput(hWindow, IDM_HEADER);
684: }
685: }
686: TRANSLATE_COORDS( 0 );
687: }
688: }
689:
690: /*********************************************************************/
691: /* GetNewCard - */
692: /* This routine is called when a card which is brought forward */
693: /* via a keystroke (i.e. ctrl-letter) */
694: /* */
695: /* Same for PM and Windows */
696: /*********************************************************************/
697:
698: BOOL FAR GetNewCard(iOldCard, iNewCard)
699: int iOldCard;
700: int iNewCard;
701: {
702: HDC hDC;
703: RECT rect;
704: int y;
705:
706: /* if phonebook mode */
707: if (CardPhone == IDM_PHONEBOOK)
708: {
709: /* unselect old card */
710: y = (iOldCard - iTopCard) * CharFixHeight;
711: hDC = GetDC(hCardfileWnd);
712:
713: TRANSLATE_COORDS( cyMainWindow );
714: SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth,
715: y+CharFixHeight);
716: TRANSLATE_RECT( rect );
717: TRANSLATE_COORDS( 0 );
718:
719: InvertRect(hDC, (LPRECT)&rect);
720: ReleaseDC(hCardfileWnd, hDC);
721: /* get new one */
722: BringCardOnScreen(iFirstCard = iNewCard);
723: }
724: else
725: {
726: /* send scroll messages */
727: CardfileScroll(hCardfileWnd, SB_THUMBTRACK, iNewCard);
728: return(CardfileScroll(hCardfileWnd, SB_THUMBPOSITION, iNewCard));
729: }
730: return(TRUE);
731: }
732:
733: /*********************************************************************/
734: /* MapPtToCard - */
735: /* Map mouse coordinates to a particular card. This is called in */
736: /* card mode only */
737: /* */
738: /* Same for PM and Windows */
739: /*********************************************************************/
740:
741: int MapPtToCard(pt)
742: POINT pt;
743: {
744: int idCard;
745: int xCur;
746: int yCur;
747: int i;
748: RECT rect;
749:
750: yCur = yFirstCard - (cScreenCards - 1)*ySpacing;
751: xCur = xFirstCard + (cScreenCards - 1)* (2 * CharFixWidth);
752: idCard = (iFirstCard + cScreenCards-1) % cCards;
753:
754: TRANSLATE_COORDS( cyMainWindow );
755:
756: for (i = 0; i < cScreenCards; ++i)
757: {
758: SetRect((LPRECT)&rect, xCur+1, yCur+1, xCur+CardWidth-1,
759: yCur+CharFixHeight+1);
760: TRANSLATE_RECT( rect );
761:
762: if (PtInRect((LPRECT)&rect, pt))
763: return(idCard);
764:
765: SetRect((LPRECT)&rect, rect.right - 2*CharFixWidth + 2,
766: yCur+1,rect.right,yCur-1+CardHeight);
767: TRANSLATE_RECT( rect );
768:
769: if (PtInRect((LPRECT)&rect, pt))
770: return(idCard);
771: xCur -= (2*CharFixWidth);
772: yCur += ySpacing;
773: idCard--;
774: if (idCard < 0)
775: idCard = cCards - 1;
776: }
777: TRANSLATE_COORDS( 0 );
778:
779: return(-1);
780: }
781:
782: /*********************************************************************/
783: /* CardfileOkError - */
784: /* Puts up a dialog box with only an ok button */
785: /* */
786: /* Same for PM and Windows */
787: /*********************************************************************/
788:
789: void FAR CardfileOkError(strid)
790: int strid;
791: {
792: MyMessageBox(strid, NULL, MB_OK | MB_ICONEXCLAMATION);
793: }
794:
795:
796: /*********************************************************************/
797: /* MyMessageBox - */
798: /* Puts up error message for strid, possibly merging in a string, */
799: /* and asks for the appropriate buttons and icons */
800: /* */
801: /* Same for PM and Windows */
802: /*********************************************************************/
803:
804: WORD FAR MyMessageBox(strid, pchMerge, style)
805: WORD strid;
806: PSTR pchMerge;
807: WORD style;
808: {
809: char buf1[128];
810: char buf2[128];
811:
812: if (strid == IDS_EINSMEMORY)
813: Mylstrcpy((LPSTR)buf1, (LPSTR)NotEnoughMem);
814: else
815: LoadString(hCardfileInstance, strid, (LPSTR)buf1, 128);
816: MergeStrings((LPSTR)buf1, (LPSTR)pchMerge, (LPSTR)buf2);
817: return(MessageBox(hCardfileWnd, (LPSTR)buf2,
818: (LPSTR)rgchCardfile, style));
819: }
820:
821:
822: /*********************************************************************/
823: /* MergeStrings - */
824: /* Scans sz1 for merge spec. If found, insert string sz2 at that */
825: /* point. Then append rest of sz1 NOTE! Merge spec guaranteed to be */
826: /* two chars. Returns TRUE if it does a merge, false otherwise. */
827: /* */
828: /* Same for PM and Windows */
829: /*********************************************************************/
830:
831: BOOL FAR MergeStrings(lpszSrc, lpszMerge, lpszDst)
832: LPSTR lpszSrc;
833: LPSTR lpszMerge;
834: LPSTR lpszDst;
835: {
836: LPSTR lpchSrc;
837: LPSTR lpchDst;
838:
839: lpchSrc = lpszSrc;
840: lpchDst = lpszDst;
841:
842: /* Find merge spec if there is one. */
843: while (*(unsigned far *)lpchSrc != wMerge) {
844: *lpchDst++ = *lpchSrc;
845:
846: /* If we reach end of string before merge spec, just return. */
847: if (!*lpchSrc++)
848: return FALSE;
849:
850: }
851: /* If merge spec found, insert sz2 there. (check for null merge string */
852: if (lpszMerge) {
853: while (*lpszMerge)
854: *lpchDst++ = *lpszMerge++;
855:
856: }
857:
858: /* Jump over merge spec */
859: lpchSrc++,lpchSrc++;
860:
861:
862: /* Now append rest of Src String */
863: while (*lpchDst++ = *lpchSrc++);
864: return TRUE;
865:
866: }
867:
868: /*********************************************************************/
869: /* MakeBlankCard - */
870: /* */
871: /* Same for PM and Windows */
872: /*********************************************************************/
873:
874: void MakeBlankCard()
875: {
876: CurCardHead.line[0] = 0;
877: CurCard.hBitmap = 0;
878: SetEditText((LPSTR)"");
879: CurCardHead.flags = FNEW;
880: }
881:
882:
883: /*********************************************************************/
884: /* SetCaption - */
885: /* Sets cardfile's window caption */
886: /* */
887: /* Same for PM and Windows */
888: /*********************************************************************/
889:
890: void SetCaption()
891: {
892: char buf[40];
893: BuildCaption(buf);
894: SetWindowText( FRAME(hCardfileWnd), (LPSTR)buf );
895: }
896:
897: /*********************************************************************/
898: /* BuildCaption - */
899: /* Creates the string that will appear in the window, or in the */
900: /* spooled file list */
901: /* */
902: /* Same for PM and Windows */
903: /*********************************************************************/
904:
905: void FAR BuildCaption(pchBuf)
906: char *pchBuf;
907: {
908: char *pch;
909: char *pch3;
910:
911: /* always starts off "Cardfile - " */
912: Mylstrcpy((LPSTR)pchBuf, (LPSTR)rgchCardfile);
913: Mylstrcat((LPSTR)pchBuf, (LPSTR)" - ");
914: /* if named, append just filename */
915: if (CurIFile[0])
916: {
917: pch = CurIFile;
918: pch3 = pch;
919: /* scan to end */
920: for ( ; *pch; ++pch)
921: ;
922: /* run backwards looking for beginning of filename */
923: while (pch > pch3 && *pch != '\\')
924: pch = (PSTR)AnsiPrev(pch3, pch);
925: /* if at slash, point to filename */
926: if (*pch == '\\')
927: pch++;
928: Mylstrcat((LPSTR)pchBuf, (LPSTR)pch);
929: }
930: /* if unnamed, append "Untitled" */
931: else
932: Mylstrcat((LPSTR)pchBuf, (LPSTR)rgchUntitled);
933: }
934:
935:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.