home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1999 March
/
VPR9903A.BIN
/
APUPDATE
/
VC
/
Tx300d
/
TX300D.LZH
/
ADRBOOK.C
next >
Wrap
C/C++ Source or Header
|
1997-03-26
|
10KB
|
394 lines
//## address book
// (C)1997 TY
//2.97A 970228 start
#include <windows.h>
#include "dialog.h"
#include "outline.h"
#define IDD_ADD 101
#define IDD_EDIT 102
#define IDD_EDITBOX 103
#define IDD_ADDCATEGORY 104
#define IDD_COPY 105
#define IDD_PASTE 106
#define IDD_DEL 107
permanent int adrbook_isel = 0;
static void addressbookSave(TX* text)
{
// del EOF
txJumpFileEnd(text);
txPrevPara(text);
txDeletePara(text);
//
txSave(text);
}
static BOOL _txAbSearchItem(TX* text,mchar* _szfind,txstr szcontent,BOOL fDelete)
{
//2.99C 970326 new
SEARCHMODE mode = SEARCH_CUR|SEARCH_PARATOP|SEARCH_NOSENSECASE;
txJumpFileTop(text);
if (!stricmp(_szfind,"name")) {
if (txSearchEx(text,"...",mode)) {
txGetPara(text,szcontent);
if (fDelete) txDeletePara(text);//2.99C 970326
strcpy(szcontent,&szcontent[3]);
return TRUE;
}
return FALSE;
} else {
txstr szfind = "<";
szfind += _szfind;
szfind += ">";
if (txSearchEx(text,szfind,mode)) {
txGetPara(text,szcontent);
if (fDelete) txDeletePara(text);//2.99C 970326
strcpy(szcontent,&szcontent[strlen(szfind)]);
return TRUE;
}
return FALSE;
}
}
static void txAbInsertItem(TX* text,mchar* szItemName,txstr szItem)
{
txInsertChar(text,'<');
txInsert(text,szItemName);
txInsertChar(text,'>');
txInsert(text,szItem);
txInsertReturn(text);
}
BOOL dlgprocAddressbook(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG: {
EnableWindow(GetDlgItem(hwnd,IDD_PASTE),FALSE);
break;
}
case WM_COMMAND: {
int id = WM_COMMAND_GetId(wParam);
int notify = WM_COMMAND_GetNotify(wParam,lParam);
TX* text = outlineGetTx(hwnd);
long cur = outlineGetCursel(hwnd);
switch(id) {
case IDOK: {
if (text->fEdit) {
addressbookSave(text);
}
adrbook_isel = cur;
break;
}
case IDCANCEL: {
if (text->fEdit) {
int q = question("編集内容を保存しますか?");
if (q == IDYES) {
addressbookSave(text);
} else if (q == IDCANCEL) {
return TRUE;
}
}
break;
}
case IDD_COPY: {
outlineCopy(hwnd);
EnableWindow(GetDlgItem(hwnd,IDD_PASTE),TRUE);
break;
}
case IDD_PASTE: {
txPaste(text);
outlineFlush(hwnd);
outlineSetCursel(hwnd,cur);
break;
}
case IDD_ADD:
case IDD_ADDCATEGORY:
case IDD_EDIT: {
BOOL fEdit = (id == IDD_EDIT);
HEADLINE hl;
outlineGetCurheadline(hwnd,&hl);
BOOL fCategory = (id == IDD_ADDCATEGORY || (fEdit && hl.nest == 1));
//
HDIALOG hd;
if (fEdit) {
if (fCategory) {
hd = dialog("グループ名の変更");
} else {
hd = dialog("住所録の編集");
}
} else {
if (fCategory) {
hd = dialog("グループの追加");
} else {
hd = dialog("住所録の追加");
}
}
//
txstr szstr = hl.szstr;
if (fCategory) {
dialogStr(hd,"グループ名(&C):",szstr,12,20);
if (dialogOpen(hd) && szstr != "") {
if (hl.npara == 0) {
txJumpFileTop(text);
} else {
txJumpPara(text,hl.npara);
}
//
if (fCategory && fEdit) {
txDeletePara(text);
}
txInsertLine(text,"%s%s",text->tsztitle[0+!fCategory],szstr);
}
} else {
dialogStr(hd,"氏名(&N):",szstr,12,30);
//
TX* work = txAllocText(TXALLOC_UNDO);
if (work) {
txOpenText(work);
if (fEdit) {
outlineCopy(hwnd);
txPaste(work);
txJumpFileTop(work);
txDeletePara(work);
} else if (id == IDD_ADD) {
txInsertLine(work,"<address>");
txInsertLine(work,"<tel>");
txInsertLine(work,"<fax>");
txInsertLine(work,"<url>");
txInsertLine(work,"<email>");
}
txUndoClear(work);
#if 1//2.99C 970326 住所録改善
txstr szAddress;
txstr szTel;
txstr szFax;
txstr szUrl;
txstr szEmail;
int lxg = 12;
_txAbSearchItem(work,"address",szAddress,TRUE);
_txAbSearchItem(work,"tel",szTel,TRUE);
_txAbSearchItem(work,"fax",szFax,TRUE);
_txAbSearchItem(work,"url",szUrl,TRUE);
_txAbSearchItem(work,"email",szEmail,TRUE);
dialogStr(hd,"住所(&A):",szAddress,lxg,40);
dialogStr(hd,"電話(&T):",szTel,lxg,20);
dialogStr(hd,"FAX(&F):",szFax,lxg,20);
dialogStr(hd,"URL(&U):",szUrl,lxg,40);
dialogStr(hd,"E-Mail(&M):",szEmail,lxg,40);
dialogEditWz(hd,"メモ(&C):",work,lxg+40+1,6,WS_VSCROLL);
#else
dialogEditWz(hd,"内容(&C):",work,50,6,WS_VSCROLL);
#if 0//2.99 970316
#if 1//2.99 970316
dialogCmdLFV(hd);
dialogControlID(hd,IDOK);
dialogCmd(hd,"OK(&O)",12);
dialogControlID(hd,IDCANCEL);
dialogCmd(hd,"キャンセル(&C)",12);
#endif
#endif
#endif
if (dialogOpen(hd) && szstr != "") {
if (fEdit) {
outlineClear(hwnd);
}
if (id == IDD_ADD) {
HEADLINE hl;
outlineGetHeadline(hwnd,&hl,cur+1);
if (hl.npara == 0) {
txJumpFileTop(text);
} else {
txJumpPara(text,hl.npara);
}
cur++;
} else {
if (hl.npara == 0) {
txJumpFileTop(text);
} else {
txJumpPara(text,hl.npara);
}
}
txInsertLine(text,"%s%s",text->tsztitle[1],szstr);
#if 1//2.99C 970326
txJumpFileTop(work);
txAbInsertItem(work,"address",szAddress);
txAbInsertItem(work,"tel",szTel);
txAbInsertItem(work,"fax",szFax);
txAbInsertItem(work,"url",szUrl);
txAbInsertItem(work,"email",szEmail);
#endif
txSelectAll(work);
txSelectCopy(work);
txPaste(text);
// 最終行が改行で終っていない場合に対応
txInsertReturn(text);
txUp(text);
txstr szline;
if (txGetLine(text,szline) == 0) {
txDeletePara(text);
} else {
txDown(text);
}
}
txFreeText(work);
}
}
outlineFlush(hwnd);
outlineSetCursel(hwnd,cur);
return TRUE;
}
case IDD_DEL: {
long cur = outlineGetCursel(hwnd);
outlineClear(hwnd);
outlineFlush(hwnd);
outlineSetCursel(hwnd,cur);
return TRUE;
}
}
break;
}
case CON_SELCHANGED: {
long cur = outlineGetCursel(hwnd);
HEADLINE hl;
BOOL fEof = !outlineGetHeadline(hwnd,&hl,cur+1);
EnableWindow(GetDlgItem(hwnd,IDD_ADD),!fEof);
EnableWindow(GetDlgItem(hwnd,IDD_DEL),!fEof);
EnableWindow(GetDlgItem(hwnd,IDD_EDIT),!fEof);
EnableWindow(GetDlgItem(hwnd,IDD_COPY),!fEof);
EnableWindow(GetDlgItem(hwnd,IDOK),!fEof);
break;
}
}
return FALSE;
}
static void addressbookExec(TX* text)
{
txSetUndisp(text);
txSetDisp(text);
}
addressbookUI
{
TX _txtemplate;
TX *text = &_txtemplate;
mchar szfilename[CCHPATHNAME];
pathFullConfig(szfilename,"address.dic");
if (!txInit(text,szfilename)) return FALSE;
// 設定がなくても正常に動作するように
strcpy(text->tsztitle[0],"..");
strcpy(text->tsztitle[1],"...");
strcpy(text->tsztitle[2],"");
// add EOF
txJumpFileEnd(text);
txInsertLine(text,"%s(end)",text->tsztitle[0]);
text->fEdit = FALSE;
//
HDIALOG hd = dialog("住所録");
DTRECT r;
dialogGetPos(hd,&r);
r.cx = DTCX * 50;
r.cy = DTCY * 12;
dialogAddTitle(hd,&r);
dialogSetPos(hd,&r);
int x = r.x + r.cx + DTCX * 2;
r.y += r.cy + DTCY;
r.cx = DTCX * 50;
r.cy = DTCY * 6;
__dialogAddItem(hd,"LISTBOX",NULL,IDD_TITLEVIEW,&r,LBS_NOTIFY|WS_BORDER|WS_VSCROLL|WS_HSCROLL|WS_CHILD|WS_VISIBLE|WS_TABSTOP);
//
int cx = 17;
dialogLFV(hd);
dialogSetPosX(hd,x);
dialogOK(hd,cx);
dialogCancel(hd,cx);
dialogSpaceV(hd);
dialogControlID(hd,IDD_ADD);
dialogButtonCmd(hd,"追加(&A)...",NULL,cx);
dialogControlID(hd,IDD_ADDCATEGORY);
dialogButtonCmd(hd,"グループの追加(&B)...",NULL,cx);//2.92
dialogControlID(hd,IDD_EDIT);
dialogButtonCmd(hd,"修正(&E)...",NULL,cx);
dialogControlID(hd,IDD_DEL);
dialogButtonCmd(hd,"削除(&D)",NULL,cx);
//
dialogSpaceV(hd);
dialogControlID(hd,IDD_COPY);
dialogButtonCmd(hd,"コピー(&C)",NULL,cx);
dialogControlID(hd,IDD_PASTE);
dialogButtonCmd(hd,"貼り付け(&P)",NULL,cx);
//
CHOOSEOUTLINE co;
memset(&co,0,sizeof(CHOOSEOUTLINE));
co.text = text;
co.szhook = "\m.dlgprocAddressbook";
co.iselFirst = adrbook_isel;
co.fNoTitleHead = TRUE;
BOOL ret = FALSE;
if (dialogSelectTitle(hd,&co)) {
addressbookExec(textf);
ret = TRUE;
}
txClose(text);
return ret;//2.99 970315
}
TX* TXAPI txuiAbNew(void)
{
//2.99 970315 new
// textを作成して返す。textが不要になったらtxAbDeleteすること
if (addressbookUI()) {
TX* text = malloc(sizeof(TX));
if (text) {
if (txInit(text,NULL)) {
txClipPaste(text,HCLIP_WIN,FALSE,0);
return text;
} else {
free(text);
}
}
}
}
void TXAPI txAbDelete(TX* text)
{
//2.99 970315 new
if (text) {
txClose(text);
free(text);
}
}
BOOL TXAPI txAbSearchItem(TX* text,mchar* _szfind,txstr szcontent)
{
//2.99 970315 new
#if 1//2.99C 970326
return _txAbSearchItem(text,_szfind,szcontent,FALSE);
#else
SEARCHMODE mode = SEARCH_CUR|SEARCH_PARATOP|SEARCH_NOSENSECASE;
txJumpFileTop(text);
if (!stricmp(_szfind,"name")) {
if (txSearchEx(text,"...",mode)) {
txGetPara(text,szcontent);
strcpy(szcontent,&szcontent[3]);
return TRUE;
}
return FALSE;
} else {
txstr szfind = "<";
szfind += _szfind;
szfind += ">";
if (txSearchEx(text,szfind,mode)) {
txGetPara(text,szcontent);
strcpy(szcontent,&szcontent[strlen(szfind)]);
return TRUE;
}
return FALSE;
}
#endif
}