|
|
Microsoft OS/2 SDK PM 08-08-1988
#include "cardfile.h"
/*********************************************************************/
/* Windows/PM Cardfile Shared Code */
/* */
/* (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved */
/*********************************************************************/
/*********************************************************************/
/* The following shared code was developed from the original */
/* Cardfile application. This code can be compiled to run under */
/* either the Windows or the PM manager environment. All */
/* functionality associated with bitmaps or printing has been */
/* deleted. Some comments refering to these functions may still be */
/* present in the code and should be disregarded. jw. */
/*********************************************************************/
/*********************************************************************/
/* CardWndProc - */
/* in card mode, cardfile uses an edit control for the body */
/* of the frontmost card. When the user presses Ctrl-letter, the */
/* application needs to intercept this message and search for a */
/* a matching card. */
/* */
/* Different in PM and Windows */
/*********************************************************************/
long far PASCAL CardWndProc(hwnd, message, wParam, lParam)
HWND hwnd;
unsigned message;
WINWORD wParam;
DWORD lParam;
{
switch (message)
{
case WM_CHAR:
/* In Windows, Ctrl-chars are sent in the WM_CHAR message */
/* and virtual keys are sent in the WM_SYSKEYDOWN message. */
/* In PM, all keystrokes are sent in the WM_CHAR message. */
/* The simplest way to handle this difference is to */
/* have different code for both cases. */
#ifdef IN_WINDOWS
/* could be a ctrl-letter combination, which means */
/* move to the next card starting with that letter. */
/* check, and if not pass it on */
if (!GetKeyState(VK_CTRL) || !CardChar(wParam))
goto PassMessageOn;
#else
/* PM Only! */
/* If key up or dead key, pass to system */
if (wParam & (KC_KEYUP | KC_DEADKEY | KC_ALT))
goto PassMessageOn;
/* If virtual key is valid, see if can process */
if (wParam & KC_VIRTUALKEY)
if (CardKey(HIUSHORT(lParam)))
return( TRUE );
/* Otherwise, if valid char, try to process */
if ((wParam & KC_CHAR) && (wParam & KC_CTRL))
if (CardChar(LOUSHORT(lParam)))
return( TRUE );
goto PassMessageOn;
#endif
break;
#ifdef IN_WINDOWS
/* Try to process virtual keystroke */
case WM_KEYDOWN:
/* could be page up-down, home, end */
if (!CardKey(wParam))
goto PassMessageOn;
break;
#endif
default:
PassMessageOn:
return(CallWindowProc(lpEditWndProc, hCardWnd, message, wParam,
lParam));
break;
}
return(0L);
}
/*********************************************************************/
/* DeleteCard - */
/* get rid of a card, and remove it from the data structure */
/* */
/* Same for PM and Windows */
/*********************************************************************/
void DeleteCard(iCard)
int iCard;
{
LPCARDHEADER lpCards;
cCards--;
lpCards = (LPCARDHEADER) GlobalLock(hCards);
RepMov( (LPSTR) (lpCards+iCard), (LPSTR) (lpCards+iCard+1),
(cCards-iCard) * sizeof(CARDHEADER) );
GlobalUnlock(hCards);
}
/*********************************************************************/
/* AddCurCard - */
/* adding a new card, insert it in the linked list in alphabetical*/
/* order based on the header */
/* */
/* Same for PM and Windows */
/*********************************************************************/
int FAR AddCurCard()
{
LPCARDHEADER lpCards;
LPCARDHEADER lpTCards;
char *pch1;
unsigned char c1, c2;
LPSTR lpch2;
int i, fKj1, fKj2;
lpCards = (LPCARDHEADER) GlobalLock(hCards);
lpTCards = lpCards;
/* scan for right place to insert the card */
for (i = 0; i < cCards; i++) {
fKj1 = fKj2 = 0;
/* compare new header and current one */
for(pch1 = CurCardHead.line, lpch2 = lpTCards->line;
*pch1; ++pch1, ++lpch2)
{
/* do not call ansi upper if it is the second byte */
/* of the kanji stream */
/* The original Windows call AnsiUpper was replace by */
/* ANSICHARUP in those cases that it was called with a */
/* single char */
c1 = KanjiXlat((fKj1 ? *pch1 : ANSICHARUP(CHAR_STR(pch1))),
(short *)&fKj1);
c2 = KanjiXlat((fKj2 ? *lpch2 : ANSICHARUP(CHAR_STR(lpch2))),
(short *)&fKj2);
if (c1 != c2)
break;
}
/* if less than or equal, found the spot */
if (c1 <= c2)
break;
lpTCards++;
}
if (i != cCards)
RepMovUp( (LPSTR) (lpTCards + 1), (LPSTR) lpTCards,
(cCards - i) * sizeof(CARDHEADER) );
*lpTCards = CurCardHead;
GlobalUnlock(hCards);
cCards++;
return(i);
}
/*********************************************************************/
/* KanjiXlat -
/* Same for PM and Windows */
/*********************************************************************/
KanjiXlat(c, fKj)
unsigned char c;
short *fKj;
{
/* if (fKj) ==> this is the second byte of a kanji char,
no translation */
if (*fKj)
{
*fKj = 0;
return c;
}
if (c < 0x80)
return c;
if (c <= 0x9f)
{
*fKj = 1;
return c + 0x40;
}
if (c <= 0xdf)
return c - 0x20;
*fKj = 1;
return c;
}
/*********************************************************************/
/* SaveCurrentCard - */
/* Saves the data on the current card */
/* */
/* Slightly different in PM and Windows */
/*********************************************************************/
BOOL SaveCurrentCard(iCard)
int iCard;
{
LPCARDHEADER lpCards;
HANDLE hText;
LPSTR lpText;
/* save the card if it's dirty */
/* dirty if edittext has changed */
if (CurCardHead.flags & (FDIRTY+FNEW) ||
SendMessage(hCardWnd, EM_GETMODIFY, 0, 0L))
{
/* get a buffer for text on card */
hText = GlobalAlloc(GHND, (long)CARDTEXTSIZE);
if (!hText)
{
CardfileOkError(IDS_EINSMEMSAVE);
return(FALSE);
}
lpText = GlobalLock(hText);
/* get the text in the edit control */
GetWindowText(hCardWnd, lpText, CARDTEXTSIZE);
/* save the card */
if (WriteCurCard(&CurCardHead, &CurCard, lpText))
{
if (CurCardHead.flags & FDIRTY ||
SendMessage(hCardWnd, EM_GETMODIFY, 0, 0L))
fFileDirty = TRUE;
#ifdef IN_WINDOWS
/* In Windows, the edit modify flag must be manually reset. */
/* In PM, it's reset when the EM_GETMODIFY occurs */
SendMessage(hCardWnd, EM_SETMODIFY, FALSE, 0L);
#endif
CurCardHead.flags &= (!FNEW);
CurCardHead.flags &= (!FDIRTY);
CurCardHead.flags |= FTMPFILE;
/* save the card in the linked list. information about */
/* location of card's data has changed, which is why the */
/* header needs to be saved */
lpCards = (LPCARDHEADER) GlobalLock(hCards);
lpCards += iCard;
*lpCards = CurCardHead;
GlobalUnlock(hCards);
}
else
return(FALSE);
GlobalUnlock(hText);
GlobalFree(hText);
}
return(TRUE);
}
/*********************************************************************/
/* SetCurCard - */
/* get the data for the current front card */
/* */
/* Same for PM and Windows */
/*********************************************************************/
void SetCurCard(iCard)
int iCard;
{
LPCARDHEADER lpCards;
LPSTR lpText;
HANDLE hText;
/* allocate a buffer to read the text into */
hText = GlobalAlloc(GHND, (long)CARDTEXTSIZE);
if (!hText)
{
CardfileOkError(IDS_EINSMEMREAD);
return;
}
lpCards = (LPCARDHEADER) GlobalLock(hCards);
lpCards += iCard;
/* get the current header */
CurCardHead = *lpCards;
GlobalUnlock(hCards);
lpText = GlobalLock(hText);
/* read the data */
if (!ReadCurCardData(&CurCardHead, &CurCard, lpText))
CardfileOkError(IDS_ECANTREADPICT);
/* set the contents of the edit control */
SetEditText(lpText);
GlobalUnlock(hText);
GlobalFree(hText);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.