home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / quot210s.zip / src / adlg.c < prev    next >
C/C++ Source or Header  |  1998-12-10  |  19KB  |  590 lines

  1. /*
  2.  * adlg.c
  3.  *
  4.  * Routines for author menu options and dialogue boxes.
  5.  *
  6.  *      Created: 16th July, 1997 (split from quoter.c)
  7.  * Version 2.00: 21st December, 1997
  8.  * Version 2.10: 10th December, 1998
  9.  *
  10.  * (C) 1997-1998 Nicholas Paul Sheppard
  11.  *
  12.  * This file is distributed under the GNU General Public License. See the
  13.  * file copying.txt for details.
  14.  */
  15.  
  16. #define INCL_DOSPROCESS
  17. #define INCL_WIN
  18. #include <os2.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include "quoter.h"
  23. #include "authors.h"
  24. #include "threads.h"
  25. #include "general.h"
  26. #include "pmutil.h"
  27.  
  28. MRESULT EXPENTRY EditAuthorBox(HWND hwnd, ULONG message, MPARAM mp1, MPARAM mp2)
  29. /*
  30.  * Window procedure for the edit quote box. If mp2 is Q_ADD when the dialogue is
  31.  * initialised, add the author to the database. If mp2 is Q_EDIT, edit an author
  32.  * already existing in the database.
  33.  */
  34. {
  35.     static char    szTempFileName[L_tmpnam];
  36.     static char    szOrigCode[20];
  37.     static int    iMode;
  38.     static HAPP    happEditor = NULLHANDLE;
  39.     char         szString[100], szMessage[200], szTitle[20];
  40.     FILE        *f;
  41.     BOOL        bNewCode;
  42.  
  43.     switch (message) {
  44.         case WM_INITDLG:
  45.             happEditor = NULLHANDLE;
  46.             tmpnam(szTempFileName);
  47.             WinSendDlgItemMsg(hwnd, IDC_EDITA_CODE, EM_SETTEXTLIMIT, MPFROMSHORT(AUTHOR_MAX_CODE), 0);
  48.             WinSendDlgItemMsg(hwnd, IDC_EDITA_SURNAME, EM_SETTEXTLIMIT, MPFROMSHORT(AUTHOR_MAX_SURNAME), 0);
  49.             WinSendDlgItemMsg(hwnd, IDC_EDITA_GNAME, EM_SETTEXTLIMIT, MPFROMSHORT(AUTHOR_MAX_GNAME), 0);
  50.             WinSendDlgItemMsg(hwnd, IDC_EDITA_BORN, EM_SETTEXTLIMIT, MPFROMSHORT(AUTHOR_MAX_BIRTH), 0);
  51.             WinSendDlgItemMsg(hwnd, IDC_EDITA_DIED, EM_SETTEXTLIMIT, MPFROMSHORT(AUTHOR_MAX_DEATH), 0);
  52.             iMode = (int)LONGFROMMP(mp2);
  53.             if (iMode == Q_EDIT) {
  54.                 WinLoadString(hab, 0, IDS_TITLE_EDITA, sizeof(szTitle), szTitle);
  55.                 strcpy(szOrigCode, ps.szAuthorCode);
  56.                 WinSetDlgItemText(hwnd, IDC_EDITA_CODE, ps.szAuthorCode);
  57.                 WinSetDlgItemText(hwnd, IDC_EDITA_SURNAME, ps.pai->szSurname);
  58.                 WinSetDlgItemText(hwnd, IDC_EDITA_GNAME, ps.pai->szGivenName);
  59.                 WinSetDlgItemText(hwnd, IDC_EDITA_BORN, ps.pai->szBirthYear);
  60.                 WinSetDlgItemText(hwnd, IDC_EDITA_DIED, ps.pai->szDeathYear);
  61.                 if ((f = fopen(szTempFileName, "w")) == NULL) {
  62.                     WinLoadString(hab, 0, IDS_OPENFAILED, sizeof(szString), szString);
  63.                     sprintf(szMessage, szString, szTempFileName);
  64.                     WinLoadString(hab, 0, IDS_ERROR, sizeof(szTitle), szTitle);
  65.                     WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_ERROR);
  66.                     WinDismissDlg(hwnd, TRUE);
  67.                 } else {
  68.                     if (ps.pszDesc != NULL)
  69.                         fputs(ps.pszDesc, f);
  70.                     fclose(f);
  71.                 }
  72.             } else {
  73.                 WinLoadString(hab, 0, IDS_TITLE_ADDA, sizeof(szTitle), szTitle);
  74.                 if ((ps.pai = (AUTHORINFO *)malloc(sizeof(AUTHORINFO))) == NULL) {
  75.                     WinLoadString(hab, 0, IDS_NOMEM, sizeof(szMessage), szMessage);
  76.                     WinLoadString(hab, 0, IDS_ERROR, sizeof(szTitle), szTitle);
  77.                     WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_ERROR);
  78.                     WinDismissDlg(hwnd, TRUE);
  79.                 }
  80.             }
  81.             WinSetWindowText(hwnd, szTitle);
  82.             return (FALSE);
  83.  
  84.         case WM_APPTERMINATENOTIFY:
  85.             happEditor = NULLHANDLE;
  86.             WinEnableControl(hwnd, IDC_EDITA_DESC, TRUE);
  87.             return (FALSE);
  88.  
  89.         case WM_COMMAND:
  90.             switch (SHORT1FROMMP(mp1)) {
  91.                 case IDC_EDITA_DESC:
  92.                     strreplace(prf.szEditorParams, "%", szTempFileName, szMessage);
  93.                     if ((happEditor = SpawnPM(hwnd, prf.szEditor, szMessage)) != NULLHANDLE)
  94.                         WinEnableControl(hwnd, IDC_EDITA_DESC, FALSE);
  95.                     return (FALSE);
  96.  
  97.                 case IDC_EDITA_OKAY:
  98.                     WinQueryDlgItemText(hwnd, IDC_EDITA_CODE, sizeof(ps.szAuthorCode), ps.szAuthorCode);
  99.  
  100.                     /* make sure the author code is non-trivial */
  101.                     if (ps.szAuthorCode[0] == '\0') {
  102.                         WinLoadString(hab, 0, IDS_NOCODE, sizeof(szMessage), szMessage);
  103.                         WinLoadString(hab, 0, IDS_RETRY, sizeof(szTitle), szTitle);
  104.                         WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_ERROR);
  105.                         return (FALSE);
  106.                     }
  107.  
  108.                     /* see if code already exists in the database */
  109.                     bNewCode = iMode == Q_ADD;
  110.                     bNewCode = bNewCode || ((iMode == Q_EDIT) && (strcmp(ps.szAuthorCode, szOrigCode) != 0));
  111.                     if (bNewCode) {
  112.                         if (AuthorExists(&(ps.adb), ps.szAuthorCode)) {
  113.                             WinLoadString(hab, 0, IDS_REPLACECODE, sizeof(szString), szString);
  114.                             sprintf(szMessage, szString, ps.szAuthorCode);
  115.                             WinLoadString(hab, 0, IDS_CONFIRM, sizeof(szTitle), szTitle);
  116.                             if (WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_YESNO | MB_QUERY) != MBID_YES)
  117.                                        return (FALSE);
  118.                         }
  119.                     }
  120.  
  121.                     /* delete old code if we have changed it */
  122.                     if (bNewCode && (iMode == Q_EDIT))
  123.                         AuthorDeleteAuthor(&(ps.adb), szOrigCode);
  124.  
  125.                     /* read information from the dialogue */
  126.                     WinQueryDlgItemText(hwnd, IDC_EDITA_SURNAME, sizeof(ps.pai->szSurname), ps.pai->szSurname);
  127.                     WinQueryDlgItemText(hwnd, IDC_EDITA_GNAME, sizeof(ps.pai->szGivenName), ps.pai->szGivenName);
  128.                     WinQueryDlgItemText(hwnd, IDC_EDITA_BORN, sizeof(ps.pai->szBirthYear), ps.pai->szBirthYear);
  129.                     WinQueryDlgItemText(hwnd, IDC_EDITA_DIED, sizeof(ps.pai->szDeathYear), ps.pai->szDeathYear);
  130.                     if ((f = fopen(szTempFileName, "r")) != NULL) {
  131.                         ps.pszDesc = strfromf(f);
  132.                         fclose(f);
  133.                         DosDelete(szTempFileName);
  134.                     } else
  135.                         ps.pszDesc = "";
  136.                     if (happEditor != NULLHANDLE)
  137.                         WinTerminateApp(happEditor);
  138.                     AuthorAddAuthor(&(ps.adb), ps.szAuthorCode, ps.pai, ps.pszDesc);
  139.                     WinDismissDlg(hwnd, TRUE);
  140.                     return (FALSE);
  141.  
  142.                 case IDC_EDITA_CANCEL:
  143.                     if (iMode == Q_ADD)
  144.                         AuthorFreeAuthor(&(ps.pai), &(ps.pszDesc));
  145.                     if (happEditor != NULLHANDLE)
  146.                         WinTerminateApp(happEditor);
  147.                     DosDelete(szTempFileName);
  148.                     WinDismissDlg(hwnd, TRUE);
  149.                     return (FALSE);
  150.             }
  151.  
  152.         default:
  153.             return (WinDefDlgProc(hwnd, message, mp1, mp2));
  154.     }
  155.  
  156.     return (FALSE);
  157. }
  158.  
  159.  
  160. MRESULT EXPENTRY ChooseAuthorBox(HWND hwnd, ULONG message, MPARAM mp1, MPARAM mp2)
  161. /*
  162.  * Window procedure for the choose author box. This allows the user to select an
  163.  * author from a list of codes.
  164.  */
  165. {
  166.     static THREADINFO    ti;
  167.     static HWND        hwndList, hwndCounter;
  168.     static int        iCount;
  169.     static char        szSearch[AUTHOR_MAX_SEARCH];
  170.     static TID        tidSearch;
  171.     char            szMessage[200], szTitle[20];
  172.     int            iIndex;
  173.     SEARCHINFO        *psi;
  174.     AUTHORINFO        *pai;
  175.  
  176.     switch (message) {
  177.         case WM_INITDLG:
  178.             WinLoadString(hab, 0, IDS_TITLE_ACODE, sizeof(szMessage), szMessage);
  179.             WinSetWindowText(hwnd, szMessage);
  180.             hwndList = WinWindowFromID(hwnd, IDC_CODE_CODE);
  181.             hwndCounter = WinWindowFromID(hwnd, IDC_CODE_COUNT);
  182.             WinSendMsg(hwndList, LM_DELETEALL, 0, 0);
  183.             WinEnableControl(hwnd, IDC_CODE_OKAY, FALSE);
  184.             WinEnableControl(hwnd, IDC_CODE_CANCEL, TRUE);
  185.             psi = (SEARCHINFO *)PVOIDFROMMP(mp2);
  186.             ti.hwndCaller = hwnd;
  187.             if (psi->pszString != NULL)
  188.                 ti.pData = (void *)strcpy(szSearch, psi->pszString);
  189.             else
  190.                 ti.pData = NULL;
  191.             ti.pps = &ps;
  192.             tidSearch = -1;
  193.             switch (psi->iType) {
  194.                 case Q_FULL:
  195.                     tidSearch = _beginthread((THREADPROC)ThreadFindAllAuthors, NULL, THREADSTACK, (void *)&ti);
  196.                     break;
  197.  
  198.                 case Q_TEXT:
  199.                     tidSearch = _beginthread((THREADPROC)ThreadFindDescription, NULL, THREADSTACK, (void *)&ti);
  200.                     break;
  201.  
  202.                 case Q_NAME:
  203.                     tidSearch = _beginthread((THREADPROC)ThreadFindAuthorName, NULL, THREADSTACK, (void *)&ti);
  204.                     break;
  205.             }
  206.             if (tidSearch == -1) {
  207.                 WinLoadString(hab, 0, IDS_THREADFAILED, sizeof(szMessage), szMessage);
  208.                 WinLoadString(hab, 0, IDS_ERROR, sizeof(szTitle), szTitle);
  209.                 WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_ERROR);
  210.                 WinDismissDlg(hwnd, TRUE);
  211.             }
  212.             iCount = 0;
  213.             return (FALSE);
  214.  
  215.         case QM_FOUND:
  216.             AuthorGetAuthor(&(ps.adb), (char *)PVOIDFROMMP(mp1), &pai, NULL);
  217.             strcpy(szMessage, pai->szSurname);
  218.             if ((pai->szGivenName[0] != '\0') && (pai->szSurname[0] != '\0')) {
  219.                 strcat(szMessage, ", ");
  220.             }
  221.             strcat(szMessage, pai->szGivenName);
  222.             strcat(szMessage, " (");
  223.             strcat(szMessage, (char *)PVOIDFROMMP(mp1));
  224.             strcat(szMessage, ")");
  225.             WinInsertLboxItem(hwndList, LIT_SORTASCENDING, szMessage);
  226.             AuthorFreeAuthor(&pai, NULL);
  227.             sprintf(szMessage, "%d", ++iCount);
  228.             WinSetWindowText(hwndCounter, szMessage);
  229.             return (FALSE);
  230.  
  231.         case QM_DONE:
  232.             if (WinQueryLboxCount(hwndList) == 0) {
  233.                 WinLoadString(hab, 0, IDS_NOAUTHORS, sizeof(szMessage), szMessage);
  234.                 WinLoadString(hab, 0, IDS_RETRY, sizeof(szTitle), szTitle);
  235.                 WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_INFORMATION);
  236.                 WinDismissDlg(hwnd, TRUE);
  237.                 return (FALSE);
  238.             }
  239.             tidSearch = -1;
  240.             WinEnableControl(hwnd, IDC_CODE_OKAY, TRUE);
  241.             WinEnableControl(hwnd, IDC_CODE_CANCEL, TRUE);
  242.             return (FALSE);
  243.  
  244.         case QM_ERROR:
  245.             WinLoadString(hab, 0, IDS_BADRX, sizeof(szMessage), szMessage);
  246.             WinLoadString(hab, 0, IDS_RETRY, sizeof(szTitle), szTitle);
  247.             WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_ERROR);
  248.             WinDismissDlg(hwnd, TRUE);
  249.             return (FALSE);
  250.  
  251.         case WM_COMMAND:
  252.             switch (SHORT1FROMMP(mp1)) {
  253.                 case IDC_CODE_OKAY:
  254.                     iIndex = (int)WinQueryLboxSelectedItem(hwndList);
  255.                     if (iIndex != LIT_NONE) {
  256.                         WinQueryLboxItemText(hwndList, iIndex, szMessage, sizeof(szMessage));
  257.                         strencl(szMessage, ps.szAuthorCode, '(', ')');
  258.                     } else {
  259.                         ps.szAuthorCode[0] = '\0';
  260.                         ps.pszDesc = NULL;
  261.                     }
  262.                     WinDismissDlg(hwnd, TRUE);
  263.                     return (FALSE);
  264.  
  265.                 case IDC_CODE_CANCEL:
  266.                     if (tidSearch != -1) {
  267.                         /* cancel searching */
  268.                         DosKillThread(tidSearch);
  269.                         WinPostMsg(hwnd, QM_DONE, NULL, NULL);
  270.                     } else {
  271.                         /* cancel selection */
  272.                         ps.szAuthorCode[0] = '\0';
  273.                         ps.pszDesc = NULL;
  274.                         WinDismissDlg(hwnd, TRUE);
  275.                     }
  276.                     return (FALSE);
  277.             }
  278.  
  279.         case WM_CONTROL:
  280.             switch (SHORT1FROMMP(mp1)) {
  281.                 case IDC_CODE_CODE:
  282.                     switch (SHORT2FROMMP(mp1)) {
  283.                         case LN_ENTER:
  284.                             WinPostMsg(hwnd, WM_COMMAND, MPFROMSHORT(IDC_CODE_OKAY), 0);
  285.                             return (FALSE);
  286.                     }
  287.             }
  288.  
  289.  
  290.         default:
  291.             return (WinDefDlgProc(hwnd, message, mp1, mp2));
  292.     }
  293.  
  294.     return (FALSE);
  295. }
  296.  
  297.  
  298. MRESULT EXPENTRY ImportAuthorsBox(HWND hwnd, ULONG message, MPARAM mp1, MPARAM mp2)
  299. /*
  300.  * Window procedure for the import author database box.
  301.  */
  302. {
  303.     static THREADINFO    ti;
  304.     static IMPORTINFO    ii;
  305.     static AUTHORDB        adb;
  306.     FILEDLG            fd;
  307.     char            szString[CCHMAXPATH], szMessage[CCHMAXPATH], szTitle[20];
  308.  
  309.     switch (message) {
  310.         case WM_INITDLG:
  311.             WinCheckButton(hwnd, IDC_IMPORT_REPLACE_ASK, TRUE);
  312.             WinSendDlgItemMsg(hwnd, IDC_IMPORT_SOURCE, EM_SETTEXTLIMIT, MPFROMSHORT(CCHMAXPATH), 0);
  313.             return (FALSE);
  314.  
  315.         case QM_DONE:
  316.             WinDismissDlg(hwnd, TRUE);
  317.             return (FALSE);
  318.  
  319.         case WM_COMMAND:
  320.             switch (SHORT1FROMMP(mp1)) {
  321.                 case IDC_IMPORT_BROWSE:
  322.                     memset(&fd, 0, sizeof(FILEDLG));
  323.                     fd.cbSize = sizeof(FILEDLG);
  324.                     fd.fl = FDS_OPEN_DIALOG | FDS_CENTER;
  325.                     dircat(strcpy(fd.szFullFile, prf.szDataPath), szAuthorExt);
  326.                     WinLoadString(hab, 0, IDS_TITLE_BROWSE, sizeof(szTitle), szTitle);
  327.                     fd.pszTitle = szTitle;
  328.                     WinFileDlg(HWND_DESKTOP, hwnd, &fd);
  329.                     if (fd.lReturn == DID_OK)
  330.                         WinSetDlgItemText(hwnd, IDC_IMPORT_SOURCE, dirnoext(fd.szFullFile));
  331.                     return (FALSE);
  332.  
  333.                 case IDC_IMPORT_OKAY:
  334.                     WinQueryDlgItemText(hwnd, IDC_IMPORT_SOURCE, sizeof(fd.szFullFile), fd.szFullFile);
  335.                     if (AuthorOpenDB(fd.szFullFile, &adb, S_IREAD)) {
  336.                         ti.hwndCaller = hwnd;
  337.                         ii.pdb = &adb;
  338.                         ii.bAsk = WinQueryButtonCheckstate(hwnd, IDC_IMPORT_REPLACE_ASK);
  339.                         ii.bReplace = WinQueryButtonCheckstate(hwnd, IDC_IMPORT_REPLACE_ALL);
  340.                         ti.pData = ⅈ
  341.                         ti.pps = &ps;
  342.                         if (_beginthread((THREADPROC)ThreadImportAuthors, NULL, THREADSTACK, (void *)&ti) == -1) {
  343.                             WinLoadString(hab, 0, IDS_THREADFAILED, sizeof(szString), szString);
  344.                             WinLoadString(hab, 0, IDS_ERROR, sizeof(szTitle), szTitle);
  345.                             WinMessageBox(HWND_DESKTOP, hwnd, szString, szTitle, 0, MB_ERROR);
  346.                             WinDismissDlg(hwnd, TRUE);
  347.                         }
  348.                     } else {
  349.                         WinLoadString(hab, 0, IDS_OPENFAILED, sizeof(szString), szString);
  350.                         sprintf(szMessage, szString, fd.szFullFile);
  351.                         WinLoadString(hab, 0, IDS_ERROR, sizeof(szTitle), szTitle);
  352.                         WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_ERROR);
  353.                     }
  354.                     return (FALSE);
  355.  
  356.                 case IDC_IMPORT_CANCEL:
  357.                     WinDismissDlg(hwnd, TRUE);
  358.                     return (FALSE);
  359.             }
  360.  
  361.         default:
  362.             return (WinDefDlgProc(hwnd, message, mp1, mp2));
  363.     }
  364.  
  365.     return (FALSE);
  366. }
  367.  
  368.  
  369. BOOL MenuOpenAuthors(HWND hwnd, char *pszDBName)
  370. /*
  371.  * Open an author database.
  372.  *
  373.  * HWND hwnd        - the window handle we're running in
  374.  * char *pszDBName    - database name to open; NULL to ask the user.
  375.  *
  376.  * Returns:        - TRUE if sucessful
  377.  *              FALSE otherwise.
  378.  */
  379. {
  380.     FILEDLG        fd;
  381.     BOOL        bCont, bRet;
  382.     char        szString[200], szMessage[200], szTitle[20];
  383.     ADBINFO        adbinfo;
  384.  
  385.     bRet = FALSE;
  386.     if (pszDBName == NULL) {
  387.         memset(&fd, 0, sizeof(FILEDLG));
  388.         fd.cbSize = sizeof(FILEDLG);
  389.         fd.fl = FDS_OPEN_DIALOG | FDS_CENTER;
  390.         dircat(strcpy(fd.szFullFile, prf.szDataPath), szAuthorExt);
  391.         WinLoadString(hab, 0, IDS_TITLE_OPEN, sizeof(szTitle), szTitle);
  392.         fd.pszTitle = szTitle;
  393.         WinFileDlg(HWND_DESKTOP, hwnd, &fd);
  394.     } else
  395.         strcpy(fd.szFullFile, pszDBName);
  396.     if ((pszDBName != NULL) || (fd.lReturn == DID_OK)) {
  397.         bCont = TRUE;
  398.         dirnoext(fd.szFullFile);
  399.         if (!AuthorDBStat(fd.szFullFile, &adbinfo)) {
  400.             WinLoadString(hab, 0, IDS_MAKENEWDB, sizeof(szString), szString);
  401.             sprintf(szMessage, szString, fd.szFullFile);
  402.             WinLoadString(hab, 0, IDS_CONFIRM, sizeof(szTitle), szTitle);
  403.             bCont = WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_QUERY | MB_YESNO) == MBID_YES;
  404.             adbinfo.flMode = S_IWRITE | S_IREAD;
  405.         }
  406.         if (bCont) {
  407.             if (AuthorOpenDB(fd.szFullFile, &(ps.adb), ps.iAdbMode = adbinfo.flMode)) {
  408.                 strcpy(prf.szAuthorDB1, fd.szFullFile);
  409.                 dirfname(strcpy(ps.szAuthorDB, fd.szFullFile));
  410.                 bRet = TRUE;
  411.             } else {
  412.                 WinLoadString(hab, 0, IDS_OPENFAILED, sizeof(szString), szString);
  413.                 sprintf(szMessage, szString, fd.szFullFile);
  414.                 WinLoadString(hab, 0, IDS_ERROR, sizeof(szTitle), szTitle);
  415.                 WinMessageBox(HWND_DESKTOP, hwnd, szMessage, szTitle, 0, MB_ERROR);
  416.             }
  417.         }
  418.     }
  419.  
  420.     return (bRet);
  421. }
  422.  
  423.  
  424. BOOL MenuAddAuthor(HWND hwnd)
  425. /*
  426.  * Allow the user to add an author. Returns TRUE if the author was successfully added.
  427.  */
  428. {
  429.     BOOL        bRet;
  430.  
  431.     bRet = FALSE;
  432.     ps.szQuoteCode[0] = '\0';
  433.     ps.szAuthorCode[0] = '\0';
  434.     QuoteFreeQuote(&(ps.pqi), &(ps.pszText));
  435.     AuthorFreeAuthor(&(ps.pai), &(ps.pszDesc));
  436.     WinDlgBox(HWND_DESKTOP, hwnd, EditAuthorBox, NULLHANDLE, IDD_EDITAUTHOR, MPFROMLONG(Q_ADD));
  437.     if (ps.pai != NULL)
  438.         bRet = TRUE;
  439.  
  440.     return (bRet);
  441. }
  442.  
  443.  
  444. BOOL MenuEditAuthor(HWND hwnd, int bCurrent)
  445. /*
  446.  * Allow the user to edit an author. Returns TRUE if the author as edited.
  447.  *
  448.  * int bCurrent    - edit the current author (or provide a list)?
  449.  */
  450. {
  451.     BOOL        bRet;
  452.     SEARCHINFO    si;
  453.  
  454.     bRet = FALSE;
  455.     ps.szQuoteCode[0] = '\0';
  456.     if (!bCurrent) {
  457.         ps.szAuthorCode[0] = '\0';
  458.         si.iType = Q_FULL;
  459.         si.pszString = NULL;
  460.         WinDlgBox(HWND_DESKTOP, hwnd, ChooseAuthorBox, NULLHANDLE, IDD_CHOOSECODE, MPFROMP(&si));
  461.     }
  462.     if (ps.szAuthorCode[0] != '\0') {
  463.         AuthorFreeAuthor(&(ps.pai), &(ps.pszDesc));
  464.         AuthorGetAuthor(&(ps.adb), ps.szAuthorCode, &(ps.pai), &(ps.pszDesc));
  465.         WinDlgBox(HWND_DESKTOP, hwnd, EditAuthorBox, NULLHANDLE, IDD_EDITAUTHOR, MPFROMLONG(Q_EDIT));
  466.         bRet = TRUE;
  467.     }
  468.  
  469.     return (bRet);
  470. }
  471.  
  472.  
  473. void MenuDelAuthor(HWND hwnd, int bCurrent)
  474. /*
  475.  * Allow the user to delete an author.
  476.  *
  477.  * int bCurrent    - delete the current quote (or provide a list)?
  478.  */
  479. {
  480.     SEARCHINFO    si;
  481.  
  482.     ps.szQuoteCode[0] = '\0';
  483.     if (!bCurrent) {
  484.         ps.szAuthorCode[0] = '\0';
  485.         si.iType = Q_FULL;
  486.         si.pszString = NULL;
  487.         WinDlgBox(HWND_DESKTOP, hwnd, ChooseAuthorBox, NULLHANDLE, IDD_CHOOSECODE, MPFROMP(&si));
  488.     }
  489.     if (ps.szAuthorCode[0] != '\0') {
  490.         AuthorDeleteAuthor(&(ps.adb), ps.szAuthorCode);
  491.         ps.szAuthorCode[0] = '\0';
  492.         AuthorFreeAuthor(&(ps.pai), &(ps.pszDesc));
  493.     }
  494. }
  495.  
  496.  
  497. BOOL MenuGetAuthorAll(HWND hwnd)
  498. /*
  499.  * Allow the user to select an author from all authors in the database.
  500.  * Returns TRUE if a selection was made.
  501.  */
  502. {
  503.     BOOL        bRet;
  504.     SEARCHINFO    si;
  505.  
  506.     bRet = FALSE;
  507.     ps.szQuoteCode[0] = '\0';
  508.     ps.szAuthorCode[0] = '\0';
  509.     si.iType = Q_FULL;
  510.     si.pszString = NULL;
  511.     WinDlgBox(HWND_DESKTOP, hwnd, ChooseAuthorBox, NULLHANDLE, IDD_CHOOSECODE, MPFROMP(&si));
  512.     if (ps.szAuthorCode[0] != '\0') {
  513.         AuthorFreeAuthor(&(ps.pai), &(ps.pszDesc));
  514.         AuthorGetAuthor(&(ps.adb), ps.szAuthorCode, &(ps.pai), &(ps.pszDesc));
  515.         bRet = TRUE;
  516.     }
  517.  
  518.     return (bRet);
  519. }
  520.  
  521.  
  522. BOOL MenuGetAuthorDesc(HWND hwnd)
  523. /*
  524.  * Allow the user to select from all authors containing a given string
  525.  * in their description. Returns TRUE if a selection was made.
  526.  */
  527. {
  528.     BOOL        bRet;
  529.     SEARCHINFO    si;
  530.     GETTEXT        gt;
  531.     char        szString[AUTHOR_MAX_SEARCH + 1], szTitle[100];
  532.  
  533.     bRet = FALSE;
  534.     ps.szQuoteCode[0] = '\0';
  535.     ps.szAuthorCode[0] = '\0';
  536.     szString[0] = '\0';
  537.     gt.iMaxLength = AUTHOR_MAX_SEARCH;
  538.     gt.pszString = szString;
  539.     WinLoadString(hab, 0, IDS_TITLE_AS_DESC, sizeof(szTitle), szTitle);
  540.     gt.pszTitle = szTitle;
  541.     WinDlgBox(HWND_DESKTOP, hwnd, GetTextBox, NULLHANDLE, IDD_GETTEXT, MPFROMP(>));
  542.     if (szString[0] != '\0') {
  543.         si.iType = Q_TEXT;
  544.         si.pszString = szString;
  545.         WinDlgBox(HWND_DESKTOP, hwnd, ChooseAuthorBox, NULLHANDLE, IDD_CHOOSECODE, MPFROMP(&si));
  546.         if (ps.szAuthorCode[0] != '\0') {
  547.             AuthorFreeAuthor(&(ps.pai), &(ps.pszDesc));
  548.             AuthorGetAuthor(&(ps.adb), ps.szAuthorCode, &(ps.pai), &(ps.pszDesc));
  549.             bRet = TRUE;
  550.         }
  551.     }
  552.  
  553.     return (bRet);
  554. }
  555.  
  556.  
  557. BOOL MenuGetAuthorName(HWND hwnd)
  558. /*
  559.  * Allow the user to select from all authors with a given name. Returns
  560.  * TRUE if a selection was made.
  561.  */
  562. {
  563.     BOOL        bRet;
  564.     SEARCHINFO    si;
  565.     GETTEXT        gt;
  566.     char        szString[AUTHOR_MAX_SEARCH + 1], szTitle[100];
  567.  
  568.     bRet = FALSE;
  569.     ps.szQuoteCode[0] = '\0';
  570.     ps.szAuthorCode[0] = '\0';
  571.     szString[0] = '\0';
  572.     gt.iMaxLength = AUTHOR_MAX_SEARCH;
  573.     gt.pszString = szString;
  574.     WinLoadString(hab, 0, IDS_TITLE_AS_NAME, sizeof(szTitle), szTitle);
  575.     gt.pszTitle = szTitle;
  576.     WinDlgBox(HWND_DESKTOP, hwnd, GetTextBox, NULLHANDLE, IDD_GETTEXT, MPFROMP(>));
  577.     if (szString[0] != '\0') {
  578.         si.iType = Q_NAME;
  579.         si.pszString = szString;
  580.         WinDlgBox(HWND_DESKTOP, hwnd, ChooseAuthorBox, NULLHANDLE, IDD_CHOOSECODE, MPFROMP(&si));
  581.         if (ps.szAuthorCode[0] != '\0') {
  582.             AuthorFreeAuthor(&(ps.pai), &(ps.pszDesc));
  583.             AuthorGetAuthor(&(ps.adb), ps.szAuthorCode, &(ps.pai), &(ps.pszDesc));
  584.             bRet = TRUE;
  585.         }
  586.     }
  587.  
  588.     return (bRet);
  589. }
  590.