|
|
1.1 root 1: #include "cardfile.h"
2:
3:
4: /*********************************************************************/
5: /* Windows/PM Cardfile Shared Code */
6: /* */
7: /* (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved */
8: /*********************************************************************/
9:
10: /*********************************************************************/
11: /* The following shared code was developed from the original */
12: /* Cardfile application. This code can be compiled to run under */
13: /* either the Windows or the PM manager environment. All */
14: /* functionality associated with bitmaps or printing has been */
15: /* deleted. Some comments refering to these functions may still be */
16: /* present in the code and should be disregarded. jw. */
17: /*********************************************************************/
18:
19:
20:
21: /*********************************************************************/
22: /* CardKey - */
23: /* Handles all virtual keys passed to cardfile in Card mode. */
24: /* Included are PageUp, PageDown, Home, and End. Each of these keys */
25: /* brings a new card to the front. */
26: /* */
27: /* Same in Windows and PM. */
28: /*********************************************************************/
29:
30: BOOL CardKey(wParam)
31: WORD wParam;
32: {
33: switch(wParam)
34: {
35: case VK_HOME:
36: CardfileScroll(hCardfileWnd, SB_THUMBTRACK, 0);
37: goto FinishScroll;
38:
39: case VK_END:
40: CardfileScroll(hCardfileWnd, SB_THUMBTRACK, cCards-1);
41: goto FinishScroll;
42:
43: case VK_PRIOR:
44: CardfileScroll(hCardfileWnd, SB_LINEUP, 0);
45: goto FinishScroll;
46:
47: case VK_NEXT:
48: CardfileScroll(hCardfileWnd, SB_LINEDOWN, 0);
49:
50: FinishScroll:
51: CardfileScroll(hCardfileWnd, SB_ENDSCROLL, 0);
52: return(TRUE);
53:
54: default:
55: return(FALSE);
56: }
57: }
58:
59:
60: /*********************************************************************/
61: /* CardChar - */
62: /* Looks at chars coming into cardfile and if ctrl-char, searches */
63: /* for next card beginning with that letter. If found, card is */
64: /* brought to top. If keystroke is processed, returns TRUE, */
65: /* otherwise FALSE. */
66: /* */
67: /* Same in Windows and PM. */
68: /*********************************************************************/
69:
70: BOOL CardChar(ch)
71: int ch;
72: {
73: LPCARDHEADER lpCards;
74: LPCARDHEADER lpTmpCard;
75: int i;
76: int iCardTmp;
77: int y;
78: RECT rect;
79: HDC hDC;
80: MSG msg;
81:
82: /* if character is greater than ' ' */
83: if (ch >= ' ')
84: /* don't want to handle it */
85: return(FALSE);
86:
87: /* find out the letter of the control character */
88: ch += 'A' - 1;
89:
90: /* scan all cards for the character, starting at the front one */
91: lpCards = (LPCARDHEADER) GlobalLock(hCards);
92: iCardTmp = iFirstCard+1;
93: lpTmpCard = lpCards + iCardTmp;
94:
95: for (i = 0; i < cCards; ++i, lpTmpCard++, iCardTmp++)
96: {
97: /* if at end */
98: if (iCardTmp == cCards)
99: {
100: /* go back to beginning */
101: iCardTmp = 0;
102: lpTmpCard = lpCards;
103: }
104:
105: /* case insensitive */
106: if (ANSICHARUP(CHAR_STR(lpTmpCard->line)) == ch)
107: break;
108: }
109: GlobalUnlock(hCards);
110: /* if found one, i will be < cCards */
111: if (i < cCards)
112: {
113: /* if card mode */
114: if (CardPhone != IDM_PHONEBOOK)
115: {
116: /* save current front data */
117: SaveCurrentCard(iFirstCard);
118:
119: /* get new card's data */
120: SetCurCard(iCardTmp);
121: }
122: else
123: {
124: /* if phonebook, just remove selection */
125: y = (iFirstCard - iTopCard) * CharFixHeight;
126: TRANSLATE_COORDS( cyMainWindow );
127:
128: SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth,
129: y + CharFixHeight);
130: TRANSLATE_RECT( rect );
131: TRANSLATE_COORDS( 0 );
132:
133: hDC = GetDC(hCardfileWnd);
134: InvertRect(hDC, (LPRECT)&rect);
135: ReleaseDC(hCardfileWnd, hDC);
136: }
137: iFirstCard = iCardTmp;
138:
139: /* if in card mode, repaint headers and redraw */
140: if (CardPhone == IDM_CARDFILE)
141: {
142: SetScrollPos(hCardfileWnd, SB_HORZ, iFirstCard, TRUE);
143: PaintNewHeaders();
144: InvalidateRect(hCardWnd, (LPRECT)NULL, TRUE);
145: }
146:
147: /* otherwise bring new card on screen */
148: else
149: BringCardOnScreen(iFirstCard); /* will highlight it too */
150: }
151: return(TRUE);
152: }
153:
154:
155: /*********************************************************************/
156: /* BringCardOnScreen - */
157: /* Called in phonebook mode to bring a particular card into the */
158: /* visible window. */
159: /* */
160: /* Same in Windows and PM. */
161: /*********************************************************************/
162:
163: void BringCardOnScreen(iCard)
164: int iCard;
165: {
166: int dLines;
167: int cLines;
168: RECT rect;
169: HDC hDC;
170: int y;
171:
172: /* figure out how many lines there are in the window */
173: cLines = cyMainWindow / CharFixHeight;
174:
175: /* put up new highlight in case it's already partly on the screen */
176: TRANSLATE_COORDS( cyMainWindow );
177: y = (iCard - iTopCard) * CharFixHeight;
178:
179: SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth,
180: y + CharFixHeight);
181: TRANSLATE_RECT( rect );
182:
183: hDC = GetDC(hCardfileWnd);
184: InvertRect(hDC, (LPRECT)&rect);
185: ReleaseDC(hCardfileWnd, hDC);
186: TRANSLATE_COORDS( 0 );
187:
188: /* see if we have to move the list within the window */
189: if (iCard < iTopCard || iCard > iTopCard + cLines - 1)
190: {
191: if (iCard < iTopCard)
192: dLines = (iCard - iTopCard);
193: else
194: dLines = iCard - iTopCard - cLines + 1;
195: iTopCard += dLines;
196:
197: /* reset everything */
198: SetScrollPos(hCardfileWnd, SB_VERT, iTopCard, TRUE);
199: ScrollWindow(hCardfileWnd, 0, -dLines * CharFixHeight,
200: (LPRECT)NULL, (LPRECT)NULL);
201: UpdateWindow(hCardfileWnd);
202: }
203: }
204:
205:
206:
207: /*********************************************************************/
208: /* PhoneKey - */
209: /* Handles virtual keys in phonebook mode. */
210: /* */
211: /* Same in Windows and PM. */
212: /*********************************************************************/
213:
214: BOOL PhoneKey(hwnd, wParam)
215: HWND hwnd;
216: WORD wParam;
217: {
218: HDC hDC;
219: RECT rect;
220: int y;
221: int tmpCurCard;
222: int cLines;
223:
224: cLines = cyMainWindow / CharFixHeight;
225:
226: switch(wParam)
227: {
228: case VK_NEXT:
229: tmpCurCard = iFirstCard + cLines;
230: if (tmpCurCard >= cCards)
231: tmpCurCard = cCards - 1;
232: goto SelectNewObject;
233:
234: case VK_PRIOR:
235: tmpCurCard = iFirstCard - cLines;
236: if (tmpCurCard >= 0)
237: goto SelectNewObject;
238:
239: case VK_HOME:
240: tmpCurCard = 0;
241: goto SelectNewObject;
242:
243: case VK_END:
244: tmpCurCard = cCards - 1;
245: goto SelectNewObject;
246:
247: case VK_UP:
248: tmpCurCard = iFirstCard - 1;
249: goto SelectNewObject;
250:
251: case VK_DOWN:
252: tmpCurCard = iFirstCard + 1;
253:
254: SelectNewObject:
255: if (tmpCurCard >= 0 && tmpCurCard < cCards && tmpCurCard != iFirstCard)
256: {
257: TRANSLATE_COORDS( cyMainWindow );
258: y = (iFirstCard - iTopCard) * CharFixHeight;
259: SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth, y + CharFixHeight);
260: TRANSLATE_RECT( rect);
261:
262: hDC = GetDC(hwnd);
263: InvertRect(hDC, (LPRECT)&rect);
264: ReleaseDC(hwnd, hDC);
265: TRANSLATE_COORDS( 0 );
266:
267: BringCardOnScreen(iFirstCard = tmpCurCard); /* will highlight the right one */
268: }
269: return(TRUE);
270:
271: default:
272: return(FALSE);
273: }
274: }
275:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.