|
|
1.1 root 1: #include "cardfile.h"
2:
3: /*********************************************************************/
4: /* Windows/PM Cardfile Shared Code */
5: /* */
6: /* (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved */
7: /*********************************************************************/
8:
9: /*********************************************************************/
10: /* The following shared code was developed from the original */
11: /* Cardfile application. This code can be compiled to run under */
12: /* either the Windows or the PM manager environment. All */
13: /* functionality associated with bitmaps or printing has been */
14: /* deleted. Some comments refering to these functions may still be */
15: /* present in the code and should be disregarded. jw. */
16: /*********************************************************************/
17:
18: /*********************************************************************/
19: /* CardWndProc - */
20: /* in card mode, cardfile uses an edit control for the body */
21: /* of the frontmost card. When the user presses Ctrl-letter, the */
22: /* application needs to intercept this message and search for a */
23: /* a matching card. */
24: /* */
25: /* Different in PM and Windows */
26: /*********************************************************************/
27:
28:
29: long far PASCAL CardWndProc(hwnd, message, wParam, lParam)
30: HWND hwnd;
31: unsigned message;
32: WINWORD wParam;
33: DWORD lParam;
34: {
35: switch (message)
36: {
37: case WM_CHAR:
38: /* In Windows, Ctrl-chars are sent in the WM_CHAR message */
39: /* and virtual keys are sent in the WM_SYSKEYDOWN message. */
40: /* In PM, all keystrokes are sent in the WM_CHAR message. */
41: /* The simplest way to handle this difference is to */
42: /* have different code for both cases. */
43:
44: #ifdef IN_WINDOWS
45: /* could be a ctrl-letter combination, which means */
46: /* move to the next card starting with that letter. */
47: /* check, and if not pass it on */
48: if (!GetKeyState(VK_CTRL) || !CardChar(wParam))
49: goto PassMessageOn;
50: #else
51: /* PM Only! */
52: /* If key up or dead key, pass to system */
53: if (wParam & (KC_KEYUP | KC_DEADKEY | KC_ALT))
54: goto PassMessageOn;
55:
56: /* If virtual key is valid, see if can process */
57: if (wParam & KC_VIRTUALKEY)
58: if (CardKey(HIUSHORT(lParam)))
59: return( TRUE );
60:
61: /* Otherwise, if valid char, try to process */
62: if ((wParam & KC_CHAR) && (wParam & KC_CTRL))
63: if (CardChar(LOUSHORT(lParam)))
64: return( TRUE );
65:
66: goto PassMessageOn;
67: #endif
68: break;
69:
70: #ifdef IN_WINDOWS
71: /* Try to process virtual keystroke */
72:
73: case WM_KEYDOWN:
74: /* could be page up-down, home, end */
75: if (!CardKey(wParam))
76: goto PassMessageOn;
77: break;
78: #endif
79:
80: default:
81: PassMessageOn:
82: return(CallWindowProc(lpEditWndProc, hCardWnd, message, wParam,
83: lParam));
84: break;
85: }
86: return(0L);
87: }
88:
89: /*********************************************************************/
90: /* DeleteCard - */
91: /* get rid of a card, and remove it from the data structure */
92: /* */
93: /* Same for PM and Windows */
94: /*********************************************************************/
95:
96: void DeleteCard(iCard)
97: int iCard;
98: {
99: LPCARDHEADER lpCards;
100:
101: cCards--;
102: lpCards = (LPCARDHEADER) GlobalLock(hCards);
103: RepMov( (LPSTR) (lpCards+iCard), (LPSTR) (lpCards+iCard+1),
104: (cCards-iCard) * sizeof(CARDHEADER) );
105: GlobalUnlock(hCards);
106: }
107:
108: /*********************************************************************/
109: /* AddCurCard - */
110: /* adding a new card, insert it in the linked list in alphabetical*/
111: /* order based on the header */
112: /* */
113: /* Same for PM and Windows */
114: /*********************************************************************/
115:
116: int FAR AddCurCard()
117: {
118: LPCARDHEADER lpCards;
119: LPCARDHEADER lpTCards;
120: char *pch1;
121: unsigned char c1, c2;
122: LPSTR lpch2;
123: int i, fKj1, fKj2;
124:
125: lpCards = (LPCARDHEADER) GlobalLock(hCards);
126: lpTCards = lpCards;
127: /* scan for right place to insert the card */
128: for (i = 0; i < cCards; i++) {
129: fKj1 = fKj2 = 0;
130: /* compare new header and current one */
131: for(pch1 = CurCardHead.line, lpch2 = lpTCards->line;
132: *pch1; ++pch1, ++lpch2)
133: {
134: /* do not call ansi upper if it is the second byte */
135: /* of the kanji stream */
136:
137: /* The original Windows call AnsiUpper was replace by */
138: /* ANSICHARUP in those cases that it was called with a */
139: /* single char */
140: c1 = KanjiXlat((fKj1 ? *pch1 : ANSICHARUP(CHAR_STR(pch1))),
141: (short *)&fKj1);
142: c2 = KanjiXlat((fKj2 ? *lpch2 : ANSICHARUP(CHAR_STR(lpch2))),
143: (short *)&fKj2);
144: if (c1 != c2)
145: break;
146: }
147: /* if less than or equal, found the spot */
148: if (c1 <= c2)
149: break;
150: lpTCards++;
151: }
152: if (i != cCards)
153: RepMovUp( (LPSTR) (lpTCards + 1), (LPSTR) lpTCards,
154: (cCards - i) * sizeof(CARDHEADER) );
155:
156: *lpTCards = CurCardHead;
157: GlobalUnlock(hCards);
158: cCards++;
159: return(i);
160: }
161:
162: /*********************************************************************/
163: /* KanjiXlat -
164: /* Same for PM and Windows */
165: /*********************************************************************/
166:
167: KanjiXlat(c, fKj)
168: unsigned char c;
169: short *fKj;
170: {
171: /* if (fKj) ==> this is the second byte of a kanji char,
172: no translation */
173: if (*fKj)
174: {
175: *fKj = 0;
176: return c;
177: }
178:
179: if (c < 0x80)
180: return c;
181: if (c <= 0x9f)
182: {
183: *fKj = 1;
184: return c + 0x40;
185: }
186: if (c <= 0xdf)
187: return c - 0x20;
188: *fKj = 1;
189: return c;
190: }
191:
192: /*********************************************************************/
193: /* SaveCurrentCard - */
194: /* Saves the data on the current card */
195: /* */
196: /* Slightly different in PM and Windows */
197: /*********************************************************************/
198:
199: BOOL SaveCurrentCard(iCard)
200: int iCard;
201: {
202: LPCARDHEADER lpCards;
203: HANDLE hText;
204: LPSTR lpText;
205:
206: /* save the card if it's dirty */
207: /* dirty if edittext has changed */
208: if (CurCardHead.flags & (FDIRTY+FNEW) ||
209: SendMessage(hCardWnd, EM_GETMODIFY, 0, 0L))
210: {
211: /* get a buffer for text on card */
212: hText = GlobalAlloc(GHND, (long)CARDTEXTSIZE);
213: if (!hText)
214: {
215: CardfileOkError(IDS_EINSMEMSAVE);
216: return(FALSE);
217: }
218: lpText = GlobalLock(hText);
219:
220: /* get the text in the edit control */
221: GetWindowText(hCardWnd, lpText, CARDTEXTSIZE);
222:
223: /* save the card */
224: if (WriteCurCard(&CurCardHead, &CurCard, lpText))
225: {
226: if (CurCardHead.flags & FDIRTY ||
227: SendMessage(hCardWnd, EM_GETMODIFY, 0, 0L))
228: fFileDirty = TRUE;
229:
230: #ifdef IN_WINDOWS
231: /* In Windows, the edit modify flag must be manually reset. */
232: /* In PM, it's reset when the EM_GETMODIFY occurs */
233: SendMessage(hCardWnd, EM_SETMODIFY, FALSE, 0L);
234: #endif
235: CurCardHead.flags &= (!FNEW);
236: CurCardHead.flags &= (!FDIRTY);
237: CurCardHead.flags |= FTMPFILE;
238: /* save the card in the linked list. information about */
239: /* location of card's data has changed, which is why the */
240: /* header needs to be saved */
241: lpCards = (LPCARDHEADER) GlobalLock(hCards);
242: lpCards += iCard;
243: *lpCards = CurCardHead;
244: GlobalUnlock(hCards);
245: }
246: else
247: return(FALSE);
248: GlobalUnlock(hText);
249: GlobalFree(hText);
250: }
251: return(TRUE);
252: }
253:
254: /*********************************************************************/
255: /* SetCurCard - */
256: /* get the data for the current front card */
257: /* */
258: /* Same for PM and Windows */
259: /*********************************************************************/
260:
261: void SetCurCard(iCard)
262: int iCard;
263: {
264: LPCARDHEADER lpCards;
265: LPSTR lpText;
266: HANDLE hText;
267:
268: /* allocate a buffer to read the text into */
269: hText = GlobalAlloc(GHND, (long)CARDTEXTSIZE);
270: if (!hText)
271: {
272: CardfileOkError(IDS_EINSMEMREAD);
273: return;
274: }
275:
276: lpCards = (LPCARDHEADER) GlobalLock(hCards);
277: lpCards += iCard;
278:
279: /* get the current header */
280: CurCardHead = *lpCards;
281: GlobalUnlock(hCards);
282: lpText = GlobalLock(hText);
283:
284: /* read the data */
285: if (!ReadCurCardData(&CurCardHead, &CurCard, lpText))
286: CardfileOkError(IDS_ECANTREADPICT);
287:
288: /* set the contents of the edit control */
289: SetEditText(lpText);
290: GlobalUnlock(hText);
291: GlobalFree(hText);
292: }
293:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.