home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1999 February / VPR9902A.BIN / APUPDATE / VC / Tx300d / TX300D.LZH / ADRBOOK.C next >
C/C++ Source or Header  |  1997-03-26  |  10KB  |  394 lines

  1. //## address book
  2. // (C)1997 TY
  3. //2.97A 970228 start
  4.  
  5. #include <windows.h>
  6. #include "dialog.h"
  7. #include "outline.h"
  8.  
  9. #define IDD_ADD                101
  10. #define IDD_EDIT            102
  11. #define IDD_EDITBOX            103
  12. #define IDD_ADDCATEGORY        104
  13. #define IDD_COPY            105
  14. #define IDD_PASTE            106
  15. #define IDD_DEL                107
  16.  
  17. permanent int adrbook_isel = 0;
  18.  
  19. static void addressbookSave(TX* text)
  20. {
  21.     // del EOF
  22.     txJumpFileEnd(text);
  23.     txPrevPara(text);
  24.     txDeletePara(text);
  25.     //
  26.     txSave(text);
  27. }
  28.  
  29. static BOOL _txAbSearchItem(TX* text,mchar* _szfind,txstr szcontent,BOOL fDelete)
  30. {
  31. //2.99C 970326 new
  32.     SEARCHMODE mode = SEARCH_CUR|SEARCH_PARATOP|SEARCH_NOSENSECASE;
  33.     txJumpFileTop(text);
  34.     if (!stricmp(_szfind,"name")) {
  35.         if (txSearchEx(text,"...",mode)) {
  36.             txGetPara(text,szcontent);
  37.             if (fDelete) txDeletePara(text);//2.99C 970326 
  38.             strcpy(szcontent,&szcontent[3]);
  39.             return TRUE;
  40.         }
  41.         return FALSE;
  42.     } else {
  43.         txstr szfind = "<";
  44.         szfind += _szfind;
  45.         szfind += ">";
  46.         if (txSearchEx(text,szfind,mode)) {
  47.             txGetPara(text,szcontent);
  48.             if (fDelete) txDeletePara(text);//2.99C 970326 
  49.             strcpy(szcontent,&szcontent[strlen(szfind)]);
  50.             return TRUE;
  51.         }
  52.         return FALSE;
  53.     }
  54. }
  55.  
  56. static void txAbInsertItem(TX* text,mchar* szItemName,txstr szItem)
  57. {
  58.     txInsertChar(text,'<');
  59.     txInsert(text,szItemName);
  60.     txInsertChar(text,'>');
  61.     txInsert(text,szItem);
  62.     txInsertReturn(text);
  63. }
  64.  
  65. BOOL dlgprocAddressbook(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  66. {
  67.     switch(message) {
  68.         case WM_INITDIALOG: {
  69.             EnableWindow(GetDlgItem(hwnd,IDD_PASTE),FALSE);
  70.             break;
  71.         }
  72.         case WM_COMMAND: {
  73.             int id = WM_COMMAND_GetId(wParam);
  74.             int notify = WM_COMMAND_GetNotify(wParam,lParam);
  75.             TX* text = outlineGetTx(hwnd);
  76.             long cur = outlineGetCursel(hwnd);
  77.             switch(id) {
  78.                 case IDOK: {
  79.                     if (text->fEdit) {
  80.                         addressbookSave(text);
  81.                     }
  82.                     adrbook_isel = cur;
  83.                     break;
  84.                 }
  85.                 case IDCANCEL: {
  86.                     if (text->fEdit) {
  87.                         int q = question("編集内容を保存しますか?");
  88.                         if (q == IDYES) {
  89.                             addressbookSave(text);
  90.                         } else if (q == IDCANCEL) {
  91.                             return TRUE;
  92.                         }
  93.                     }
  94.                     break;
  95.                 }
  96.                 case IDD_COPY: {
  97.                     outlineCopy(hwnd);
  98.                     EnableWindow(GetDlgItem(hwnd,IDD_PASTE),TRUE);
  99.                     break;
  100.                 }
  101.                 case IDD_PASTE: {
  102.                     txPaste(text);
  103.                     outlineFlush(hwnd);
  104.                     outlineSetCursel(hwnd,cur);
  105.                     break;
  106.                 }
  107.                 case IDD_ADD:
  108.                 case IDD_ADDCATEGORY:
  109.                 case IDD_EDIT: {
  110.                     BOOL fEdit = (id == IDD_EDIT);
  111.                     HEADLINE hl;
  112.                     outlineGetCurheadline(hwnd,&hl);
  113.                     BOOL fCategory = (id == IDD_ADDCATEGORY || (fEdit && hl.nest == 1));
  114.                     //
  115.                     HDIALOG hd;
  116.                     if (fEdit) {
  117.                         if (fCategory) {
  118.                             hd = dialog("グループ名の変更");
  119.                         } else {
  120.                             hd = dialog("住所録の編集");
  121.                         }
  122.                     } else {
  123.                         if (fCategory) {
  124.                             hd = dialog("グループの追加");
  125.                         } else {
  126.                             hd = dialog("住所録の追加");
  127.                         }
  128.                     }
  129.                     //
  130.                     txstr szstr = hl.szstr;
  131.                     if (fCategory) {
  132.                         dialogStr(hd,"グループ名(&C):",szstr,12,20);
  133.                         if (dialogOpen(hd) && szstr != "") {
  134.                             if (hl.npara == 0) {
  135.                                 txJumpFileTop(text);
  136.                             } else {
  137.                                 txJumpPara(text,hl.npara);
  138.                             }
  139.                             //
  140.                             if (fCategory && fEdit) {
  141.                                 txDeletePara(text);
  142.                             }
  143.                             txInsertLine(text,"%s%s",text->tsztitle[0+!fCategory],szstr);
  144.                         }
  145.                     } else {
  146.                         dialogStr(hd,"氏名(&N):",szstr,12,30);
  147.                         //
  148.                         TX* work = txAllocText(TXALLOC_UNDO);
  149.                         if (work) {
  150.                             txOpenText(work);
  151.                             if (fEdit) {
  152.                                 outlineCopy(hwnd);
  153.                                 txPaste(work);
  154.                                 txJumpFileTop(work);
  155.                                 txDeletePara(work);
  156.                             } else if (id == IDD_ADD) {
  157.                                 txInsertLine(work,"<address>");
  158.                                 txInsertLine(work,"<tel>");
  159.                                 txInsertLine(work,"<fax>");
  160.                                 txInsertLine(work,"<url>");
  161.                                 txInsertLine(work,"<email>");
  162.                             }
  163.                             txUndoClear(work);
  164. #if 1//2.99C 970326 住所録改善
  165.                             txstr szAddress;
  166.                             txstr szTel;
  167.                             txstr szFax;
  168.                             txstr szUrl;
  169.                             txstr szEmail;
  170.                             int lxg = 12;
  171.                             _txAbSearchItem(work,"address",szAddress,TRUE);
  172.                             _txAbSearchItem(work,"tel",szTel,TRUE);
  173.                             _txAbSearchItem(work,"fax",szFax,TRUE);
  174.                             _txAbSearchItem(work,"url",szUrl,TRUE);
  175.                             _txAbSearchItem(work,"email",szEmail,TRUE);
  176.                             dialogStr(hd,"住所(&A):",szAddress,lxg,40);
  177.                             dialogStr(hd,"電話(&T):",szTel,lxg,20);
  178.                             dialogStr(hd,"FAX(&F):",szFax,lxg,20);
  179.                             dialogStr(hd,"URL(&U):",szUrl,lxg,40);
  180.                             dialogStr(hd,"E-Mail(&M):",szEmail,lxg,40);
  181.                             dialogEditWz(hd,"メモ(&C):",work,lxg+40+1,6,WS_VSCROLL);
  182. #else
  183.                             dialogEditWz(hd,"内容(&C):",work,50,6,WS_VSCROLL);
  184.     #if 0//2.99 970316 
  185.                             #if 1//2.99 970316 
  186.                             dialogCmdLFV(hd);
  187.                             dialogControlID(hd,IDOK);
  188.                             dialogCmd(hd,"OK(&O)",12);
  189.                             dialogControlID(hd,IDCANCEL);
  190.                             dialogCmd(hd,"キャンセル(&C)",12);
  191.                             #endif
  192.     #endif
  193. #endif
  194.                             if (dialogOpen(hd) && szstr != "") {
  195.                                 if (fEdit) {
  196.                                     outlineClear(hwnd);
  197.                                 }
  198.                                 if (id == IDD_ADD) {
  199.                                     HEADLINE hl;
  200.                                     outlineGetHeadline(hwnd,&hl,cur+1);
  201.                                     if (hl.npara == 0) {
  202.                                         txJumpFileTop(text);
  203.                                     } else {
  204.                                         txJumpPara(text,hl.npara);
  205.                                     }
  206.                                     cur++;
  207.                                 } else {
  208.                                     if (hl.npara == 0) {
  209.                                         txJumpFileTop(text);
  210.                                     } else {
  211.                                         txJumpPara(text,hl.npara);
  212.                                     }
  213.                                 }
  214.                                 txInsertLine(text,"%s%s",text->tsztitle[1],szstr);
  215. #if 1//2.99C 970326 
  216.                                 txJumpFileTop(work);
  217.                                 txAbInsertItem(work,"address",szAddress);
  218.                                 txAbInsertItem(work,"tel",szTel);
  219.                                 txAbInsertItem(work,"fax",szFax);
  220.                                 txAbInsertItem(work,"url",szUrl);
  221.                                 txAbInsertItem(work,"email",szEmail);
  222. #endif
  223.                                 txSelectAll(work);
  224.                                 txSelectCopy(work);
  225.                                 txPaste(text);
  226.                                 // 最終行が改行で終っていない場合に対応
  227.                                 txInsertReturn(text);
  228.                                 txUp(text);
  229.                                 txstr szline;
  230.                                 if (txGetLine(text,szline) == 0) {
  231.                                     txDeletePara(text);
  232.                                 } else {
  233.                                     txDown(text);
  234.                                 }
  235.                             }
  236.                             txFreeText(work);
  237.                         }
  238.                     }
  239.                     outlineFlush(hwnd);
  240.                     outlineSetCursel(hwnd,cur);
  241.                     return TRUE;
  242.                 }
  243.                 case IDD_DEL: {
  244.                     long cur = outlineGetCursel(hwnd);
  245.                     outlineClear(hwnd);
  246.                     outlineFlush(hwnd);
  247.                     outlineSetCursel(hwnd,cur);
  248.                     return TRUE;
  249.                 }
  250.             }
  251.             break;
  252.         }
  253.         case CON_SELCHANGED: {
  254.             long cur = outlineGetCursel(hwnd);
  255.             HEADLINE hl;
  256.             BOOL fEof = !outlineGetHeadline(hwnd,&hl,cur+1);
  257.             EnableWindow(GetDlgItem(hwnd,IDD_ADD),!fEof);
  258.             EnableWindow(GetDlgItem(hwnd,IDD_DEL),!fEof);
  259.             EnableWindow(GetDlgItem(hwnd,IDD_EDIT),!fEof);
  260.             EnableWindow(GetDlgItem(hwnd,IDD_COPY),!fEof);
  261.             EnableWindow(GetDlgItem(hwnd,IDOK),!fEof);
  262.             break;
  263.         }
  264.     }
  265.     return FALSE;
  266. }
  267.  
  268. static void addressbookExec(TX* text)
  269. {
  270.     txSetUndisp(text);
  271.     txSetDisp(text);
  272. }
  273.  
  274. addressbookUI
  275. {
  276.     TX _txtemplate;
  277.     TX *text = &_txtemplate;
  278.     mchar szfilename[CCHPATHNAME];
  279.     pathFullConfig(szfilename,"address.dic");
  280.     if (!txInit(text,szfilename)) return FALSE;
  281.     // 設定がなくても正常に動作するように
  282.     strcpy(text->tsztitle[0],"..");
  283.     strcpy(text->tsztitle[1],"...");
  284.     strcpy(text->tsztitle[2],"");
  285.     // add EOF
  286.     txJumpFileEnd(text);
  287.     txInsertLine(text,"%s(end)",text->tsztitle[0]);
  288.     text->fEdit = FALSE;
  289.     //
  290.     HDIALOG hd = dialog("住所録");
  291.     DTRECT r;
  292.     dialogGetPos(hd,&r);
  293.     r.cx = DTCX * 50;
  294.     r.cy = DTCY * 12;
  295.     dialogAddTitle(hd,&r);
  296.     dialogSetPos(hd,&r);
  297.     int x = r.x + r.cx + DTCX * 2;
  298.     r.y += r.cy + DTCY;
  299.     r.cx = DTCX * 50;
  300.     r.cy = DTCY * 6;
  301.     __dialogAddItem(hd,"LISTBOX",NULL,IDD_TITLEVIEW,&r,LBS_NOTIFY|WS_BORDER|WS_VSCROLL|WS_HSCROLL|WS_CHILD|WS_VISIBLE|WS_TABSTOP);
  302.     //
  303.     int cx = 17;
  304.     dialogLFV(hd);
  305.     dialogSetPosX(hd,x);
  306.     dialogOK(hd,cx);
  307.     dialogCancel(hd,cx);
  308.     dialogSpaceV(hd);
  309.     dialogControlID(hd,IDD_ADD);
  310.     dialogButtonCmd(hd,"追加(&A)...",NULL,cx);
  311.     dialogControlID(hd,IDD_ADDCATEGORY);
  312.     dialogButtonCmd(hd,"グループの追加(&B)...",NULL,cx);//2.92 
  313.     dialogControlID(hd,IDD_EDIT);
  314.     dialogButtonCmd(hd,"修正(&E)...",NULL,cx);
  315.     dialogControlID(hd,IDD_DEL);
  316.     dialogButtonCmd(hd,"削除(&D)",NULL,cx);
  317.     //
  318.     dialogSpaceV(hd);
  319.     dialogControlID(hd,IDD_COPY);
  320.     dialogButtonCmd(hd,"コピー(&C)",NULL,cx);
  321.     dialogControlID(hd,IDD_PASTE);
  322.     dialogButtonCmd(hd,"貼り付け(&P)",NULL,cx);
  323.     //
  324.     CHOOSEOUTLINE co;
  325.     memset(&co,0,sizeof(CHOOSEOUTLINE));
  326.     co.text = text;
  327.     co.szhook = "\m.dlgprocAddressbook";
  328.     co.iselFirst = adrbook_isel;
  329.     co.fNoTitleHead = TRUE;
  330.     BOOL ret = FALSE;
  331.     if (dialogSelectTitle(hd,&co)) {
  332.         addressbookExec(textf);
  333.         ret = TRUE;
  334.     }
  335.     txClose(text);
  336.     return ret;//2.99 970315 
  337. }
  338.  
  339. TX* TXAPI txuiAbNew(void)
  340. {
  341. //2.99 970315 new
  342. // textを作成して返す。textが不要になったらtxAbDeleteすること
  343.     if (addressbookUI()) {
  344.         TX* text = malloc(sizeof(TX));
  345.         if (text) {
  346.             if (txInit(text,NULL)) {
  347.                 txClipPaste(text,HCLIP_WIN,FALSE,0);
  348.                 return text;
  349.             } else {
  350.                 free(text);
  351.             }
  352.         }
  353.     }
  354. }
  355.  
  356. void TXAPI txAbDelete(TX* text)
  357. {
  358. //2.99 970315 new
  359.     if (text) {
  360.         txClose(text);
  361.         free(text);
  362.     }
  363. }
  364.  
  365. BOOL TXAPI txAbSearchItem(TX* text,mchar* _szfind,txstr szcontent)
  366. {
  367. //2.99 970315 new
  368. #if 1//2.99C 970326 
  369.     return _txAbSearchItem(text,_szfind,szcontent,FALSE);
  370. #else
  371.     SEARCHMODE mode = SEARCH_CUR|SEARCH_PARATOP|SEARCH_NOSENSECASE;
  372.     txJumpFileTop(text);
  373.     if (!stricmp(_szfind,"name")) {
  374.         if (txSearchEx(text,"...",mode)) {
  375.             txGetPara(text,szcontent);
  376.             strcpy(szcontent,&szcontent[3]);
  377.             return TRUE;
  378.         }
  379.         return FALSE;
  380.     } else {
  381.         txstr szfind = "<";
  382.         szfind += _szfind;
  383.         szfind += ">";
  384.         if (txSearchEx(text,szfind,mode)) {
  385.             txGetPara(text,szcontent);
  386.             strcpy(szcontent,&szcontent[strlen(szfind)]);
  387.             return TRUE;
  388.         }
  389.         return FALSE;
  390.     }
  391. #endif
  392. }
  393.  
  394.