home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / msq31004.zip / DIALOGS.C < prev    next >
C/C++ Source or Header  |  1995-07-14  |  11KB  |  414 lines

  1. /* dialogs.c
  2. **
  3. ** Released into the PUBLIC DOMAIN 10 jul 1994 by John Dennis
  4. **
  5. ** Contains all the static dialogs for Msgedsq and functions that
  6. ** control/activate these dialogs.  Most of the functions are
  7. ** genereric in the input they take.
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. #include "msged.h"
  13. #include "main.h"
  14. #include "keys.h"
  15.  
  16. /*
  17. **
  18. ** Initial colour value #defines.
  19. **
  20. */
  21.  
  22. #define f          BLACK|_LGREY
  23. #define s          BLACK|_LGREY
  24. #define bf         BLACK|_CYAN
  25. #define bs         WHITE|_CYAN
  26. #define bb         BLACK|_LGREY
  27.  
  28.  
  29. char editbuf[255];
  30.  
  31. button dlg_ok     = {ID_OK,      14, 12, 0, 0, bf, bs, bb, "Ok"};
  32. button dlg_cancel = {ID_CANCEL,  24, 12, 0, 0, bf, bs, bb, "Cancel"};
  33. ckbutton ck1      = {3,  19, 1, 2,  0, 0, f, s, "Show Address"};
  34. ckbutton ck2      = {4,  19, 2, 2,  0, 0, f, s, "Hard Quoting"};
  35. ckbutton ck3      = {5,  19, 3, 2,  0, 0, f, s, "Write ^aMSGIDs"};
  36. ckbutton ck4      = {6,  19, 4, 2,  0, 0, f, s, "Opus Dates"};
  37. ckbutton ck5      = {7,  19, 5, 2,  0, 0, f, s, "Show SEEN-BYs"};
  38. ckbutton ck6      = {8,  19, 6, 2,  0, 0, f, s, "Confirm Actions"};
  39. ckbutton ck7      = {9,  19, 7, 2,  0, 0, f, s, "Use Lastread"};
  40. ckbutton ck8      = {10, 19, 8, 2,  0, 0, f, s, "Use ^aPID"};
  41. ckbutton ck9      = {11, 19, 9, 2,  0, 0, f, s, "Show CRs"};
  42. ckbutton ck10     = {12, 19,10, 2,  0, 0, f, s, "Save CC Msgs"};
  43.  
  44. ckbutton ck11     = {13, 40, 1, 25, 0, 0, f, s, "Raw CC Msgs"};
  45. ckbutton ck12     = {14, 40, 2, 25, 0, 0, f, s, "Show Date Arvd?"};
  46. ckbutton ck13     = {15, 40, 3, 25, 0, 0, f, s, "Write Tearline?"};
  47. ckbutton ck14     = {16, 40, 4, 25, 0, 0, f, s, "Show Real Msg#?"};
  48. ckbutton ck15     = {17, 40, 5, 25, 0, 0, f, s, "Show ^a lines"};
  49. ckbutton ck16     = {18, 40, 6, 25, 0, 0, f, s, "Chop quotes"};
  50. ckbutton ck17     = {19, 40, 7, 25, 0, 0, f, s, "Quote quotes"};
  51. ckbutton ck18     = {20, 40, 8, 25, 0, 0, f, s, "Show EOLs"};
  52. ckbutton ck19     = {21, 40, 9, 25, 0, 0, f, s, "Use SOT/EOT"};
  53. ckbutton ck20     = {22, 40,10, 25, 0, 0, f, s, "Show Sys Name"};
  54.  
  55. dlgbox settings =
  56. {
  57.     10, 3, 68, 24,
  58.     BLACK|_LGREY,
  59.     BLACK|_LGREY,
  60.     LCYAN|_LGREY,
  61.     INSBDR|SHADOW,
  62.     " System Switches ",
  63.     22,
  64. //    20,
  65.     {   {D_CHK, 0, &ck1},
  66.         {D_CHK, 0, &ck2},
  67.         {D_CHK, 0, &ck3},
  68.         {D_CHK, 0, &ck4},
  69.         {D_CHK, 0, &ck5},
  70.         {D_CHK, 0, &ck6},
  71.         {D_CHK, 0, &ck7},
  72.         {D_CHK, 0, &ck8},
  73.         {D_CHK, 0, &ck9},
  74.         {D_CHK, 0, &ck10},
  75.         {D_CHK, 0, &ck11},
  76.         {D_CHK, 0, &ck12},
  77.         {D_CHK, 0, &ck13},
  78.         {D_CHK, 0, &ck14},
  79.         {D_CHK, 0, &ck15},
  80.         {D_CHK, 0, &ck16},
  81.         {D_CHK, 0, &ck17},
  82.         {D_CHK, 0, &ck18},
  83.         {D_CHK, 0, &ck19},
  84.         {D_CHK, 0, &ck20},
  85.         {D_BUT, 0, &dlg_ok},
  86.         {D_BUT, 0, &dlg_cancel}}
  87. };
  88.  
  89.  
  90. /*
  91. **
  92. ** Used by the GetString function
  93. **
  94. */
  95.  
  96. button strok      = {ID_OK,      5, 3, 0, 0, bf, bs, bb, "Ok"};
  97. button strcancel  = {ID_CANCEL, 15, 3, 0, 0, bf, bs, bb, "Cancel"};
  98. editf  editfld    = {ID_EDIT,    1, 1, 0, 0, f,  f,  editbuf, 20, 0};
  99.  
  100. dlgbox get_string =
  101. {
  102.     10, 5, 60, 20,
  103.     BLACK|_LGREY,
  104.     BLACK|_LGREY,
  105.     LCYAN|_LGREY,
  106.     INSBDR|SHADOW,
  107.     NULL,
  108.     3,
  109.     {   {D_EDT, 0, &editfld},
  110.         {D_BUT, 0, &strok},
  111.         {D_BUT, 0, &strcancel}
  112.     }
  113. };
  114.  
  115.  
  116. /*
  117. ** These are used by the ChoiceBox function.
  118. **
  119. */
  120.  
  121. static button b_one   = {ID_ONE,   0, 0, 0, 0, 0, 0, 0, NULL};
  122. static button b_two   = {ID_TWO,   0, 0, 0, 0, 0, 0, 0, NULL};
  123. static button b_three = {ID_THREE, 0, 0, 0, 0, 0, 0, 0, NULL};
  124.  
  125. static dlgbox cb =
  126. {
  127.     0, 0, 0, 0,
  128.     0, 0, 0,
  129.     INSBDR|SHADOW,
  130.     NULL,
  131.     1,
  132.     {
  133.         {D_BUT, 0, (void *) &b_one},
  134.         {D_BUT, 0, (void *) &b_two},
  135.         {D_BUT, 0, (void *) &b_three}
  136.     }
  137. };
  138.  
  139.  
  140. /*
  141. **
  142. ** Menu at the top of the screen.
  143. **
  144. */
  145.  
  146. MC MouseMnu =
  147. {
  148.     0, 0, 0, 0,
  149.     CMD_HOR|CMD_PRT,
  150.     NBDR,
  151.     0,
  152.     1,
  153.     7,
  154.     0,
  155.     5,
  156.     { { ID_SCAN,  0,        area_scan,  NULL, "Scan",  'c', 0, 0 }, 
  157.       { ID_AREA,  0,        newarea,    NULL, "Area",  'a', 0, 7 },
  158.       { ID_LIST,  0,        dolist,     NULL, "List",  'l', 0, 14 }, 
  159.       { ID_SETUP, 0,        set_switch, NULL, "Setup", 's', 0, 28 },
  160.       { ID_QUIT,  CMD_EXIT, NULL,       NULL, "Quit",  'q', 0, 35 }
  161.     }
  162. };
  163.  
  164.  
  165. /*=======================================================================
  166. **
  167. **
  168. ** The module functions.
  169. **
  170. **
  171. */
  172.  
  173.  
  174. void WriteSettings(void)
  175. {
  176.     SW->showaddr      = ck1.down;
  177.     SW->hardquote     = ck2.down;
  178.     SW->msgids        = ck3.down;
  179.     SW->opusdate      = ck4.down;
  180.     SW->seenbys       = ck5.down;
  181.     SW->confirmations = ck6.down;
  182.     SW->use_lastr     = ck7.down;
  183.     SW->usepid        = ck8.down;
  184.     SW->showcr        = ck9.down;
  185.     SW->savecc        = ck10.down;
  186.     SW->rawcc         = ck11.down;
  187.     SW->datearrived   = ck12.down;
  188.     SW->tearline      = ck13.down;
  189.     SW->showrealmsgn  = ck14.down;
  190.     SW->shownotes     = ck15.down;
  191.     SW->chopquote     = ck16.down;
  192.     SW->qquote        = ck17.down;
  193.     SW->showeol       = ck18.down;
  194.     SW->soteot        = ck19.down;
  195.     SW->showsystem    = ck20.down;
  196. }
  197.  
  198. void ReadSettings(void)
  199. {
  200.     ck1.down  = (unsigned char)SW->showaddr;
  201.     ck2.down  = (unsigned char)SW->hardquote;
  202.     ck3.down  = (unsigned char)SW->msgids;
  203.     ck4.down  = (unsigned char)SW->opusdate;
  204.     ck5.down  = (unsigned char)SW->seenbys;
  205.     ck6.down  = (unsigned char)SW->confirmations;
  206.     ck7.down  = (unsigned char)SW->use_lastr;
  207.     ck8.down  = (unsigned char)SW->usepid;
  208.     ck9.down  = (unsigned char)SW->showcr;
  209.     ck10.down = (unsigned char)SW->savecc;
  210.     ck11.down = (unsigned char)SW->rawcc;
  211.     ck12.down = (unsigned char)SW->datearrived;
  212.     ck13.down = (unsigned char)SW->tearline;
  213.     ck14.down = (unsigned char)SW->showrealmsgn;
  214.     ck15.down = (unsigned char)SW->shownotes;
  215.     ck16.down = (unsigned char)SW->chopquote;
  216.     ck17.down = (unsigned char)SW->qquote;
  217.     ck18.down = (unsigned char)SW->showeol;
  218.     ck19.down = (unsigned char)SW->soteot;
  219.     ck20.down = (unsigned char)SW->showsystem;
  220. }
  221.  
  222. int GetString(char *title, char *msg, char *buf, int len)
  223. {
  224.     WND *hCurr, *hWnd;
  225.     int ret;
  226.  
  227.     if (len + 10 > maxx)
  228.         len = maxx - 10;
  229.  
  230.     hCurr = Wtop();
  231.     hWnd  = WPopUp(len + 8, 8, INSBDR|SHADOW, cm[IP_BTXT], cm[IP_NTXT]);
  232.  
  233.     WWriteStr(1, 0, cm[IP_NTXT], msg);
  234.  
  235.     strcpy(editbuf, buf);
  236.  
  237.     editfld.len      = len;
  238.     editfld.curpos   = strlen(buf);
  239.     editfld.fattr    = cm[IP_ETXT];
  240.     editfld.sattr    = cm[IP_ETXT];
  241.     get_string.title = title;
  242.     strok.x          = len/2 - 9;
  243.     strcancel.x      = len/2 + 3;
  244.     ret              = DoDialog(&get_string, 1);
  245.  
  246.     switch (ret)
  247.     {
  248.         case ID_OK:
  249.         case Key_Ent:
  250.             strcpy(buf, editbuf);
  251.             ret = 1;
  252.             break;
  253.         default:
  254.             ret = 0;
  255.             break;
  256.     }
  257.     WClose(hWnd);
  258.     WCurr(hCurr);
  259.     return ret;
  260. }
  261.  
  262.  
  263. /*
  264. **
  265. **  Puts up a choice window, returning the ID of the button chosen.
  266. **  There can be only one line of text.  It works out the positioning
  267. **  of the buttons and text automagically.
  268. **
  269. **  params:
  270. **      title - title for the msgbox
  271. **      txt   - single line of text
  272. **      b1    - text for button 1
  273. **      b2    - ""              2
  274. **      b3    - ""              3
  275. **
  276. ** Returns ID of button pressed; this will be ID_ONE, ID_TWO or ID_THREE,
  277. ** or Key_Esc for an escape.
  278. **
  279. */
  280.  
  281. void SetupButton(button *b, char *txt, int x, int y, unsigned char sel, unsigned char norm, unsigned char back)
  282. {
  283.     b->x      = x;
  284.     b->y      = y;
  285.     b->select = 0;
  286.     b->down   = 0;
  287.     b->btext  = txt;
  288.     b->sattr  = sel;
  289.     b->fattr  = norm;
  290.     b->battr  = back;
  291. }
  292.  
  293. int ChoiceBox(char *title, char *txt, char *b1, char *b2, char *b3)
  294. {
  295.     WND *hCurr, *hWnd;
  296.     int TextLen  = 0;
  297.     int ChoiceLen = 0;
  298.     int wid, dep, pos, height, num = 0;
  299.  
  300.     if (txt != NULL)
  301.         TextLen = strlen(txt);
  302.  
  303.     if (b1 != NULL)
  304.     {
  305.         ChoiceLen += strlen(b1) + 6;
  306.         num++;
  307.     }
  308.     if (b2 != NULL)
  309.     {
  310.         ChoiceLen += strlen(b2) + 6;
  311.         num++;
  312.     }
  313.     if (b3 != NULL)
  314.     {
  315.         ChoiceLen += strlen(b3) + 6;
  316.         num++;
  317.     }
  318.  
  319.     wid = (ChoiceLen > TextLen) ? ChoiceLen + 8 : TextLen + 8;
  320.     dep = (txt == NULL) ? 6 : 7;
  321.  
  322.     hCurr = Wtop();
  323.     hWnd  = WPopUp(wid, dep, INSBDR|SHADOW, cm[DL_BTXT], cm[DL_WTXT]);
  324.  
  325.     if (!hWnd)
  326.     {
  327.         return -1;
  328.     }
  329.  
  330.     if (title != NULL)
  331.         WTitle(title, cm[DL_BTXT]);
  332.  
  333.     pos    = (wid / 2) - (ChoiceLen / 2) - 1;
  334.     height = (txt == NULL) ? 1 : 2;
  335.  
  336.     if (b1 != NULL)
  337.     {
  338.         SetupButton(&b_one,   b1, pos, height, 
  339.                     (unsigned char)cm[DL_BSEL], (unsigned char)cm[DL_BNRM], (unsigned char)cm[DL_BSHD]);
  340.         pos += strlen(b1) + 6;
  341.     }
  342.  
  343.     if (b2 != NULL)
  344.     {
  345.         SetupButton(&b_two,   b2, pos, height, 
  346.                     (unsigned char)cm[DL_BSEL], (unsigned char)cm[DL_BNRM], (unsigned char)cm[DL_BSHD]);
  347.         pos += strlen(b2) + 6;
  348.     }
  349.  
  350.     if (b3 != NULL)
  351.         SetupButton(&b_three, b3, pos, height, 
  352.                     (unsigned char)cm[DL_BSEL], (unsigned char)cm[DL_BNRM], (unsigned char)cm[DL_BSHD]);
  353.  
  354.     cb.num = num;
  355.  
  356.     if (txt != NULL)
  357.         WPutsCen(0, cm[DL_BTXT], txt);
  358.  
  359.     num = DoDialog(&cb, 1);
  360.  
  361.     WClose(hWnd);
  362.     WCurr(hCurr);
  363.  
  364.     return num;
  365. }
  366.  
  367.  
  368. /*
  369. **
  370. ** Sets the dialogs to the colours in the cm gobal array.
  371. **
  372. */
  373.  
  374. void SetDlgColor(dlgbox *Dlg)
  375. {
  376.     int i;
  377.  
  378.     Dlg->fattr = cm[DL_WTXT];
  379.     Dlg->sattr = cm[DL_WTXT];
  380.     Dlg->battr = cm[DL_BTXT];
  381.  
  382.     for (i = 0; i < Dlg->num; i++)
  383.     {
  384.         switch (Dlg->ctrls[i].type)
  385.         {
  386.             case D_BUT:
  387.                 ((button *) Dlg->ctrls[i].ctl)->fattr = cm[DL_BNRM];
  388.                 ((button *) Dlg->ctrls[i].ctl)->sattr = cm[DL_BSEL];
  389.                 ((button *) Dlg->ctrls[i].ctl)->battr = cm[DL_BSHD];
  390.                 break;
  391.  
  392.             case D_CHK:
  393.                 ((ckbutton *) Dlg->ctrls[i].ctl)->fattr = cm[DL_CNRM];
  394.                 ((ckbutton *) Dlg->ctrls[i].ctl)->sattr = cm[DL_CSEL];
  395.                 break;
  396.  
  397.             case D_EDT:
  398.                 ((editf *) Dlg->ctrls[i].ctl)->fattr = cm[DL_ENRM];
  399.                 ((editf *) Dlg->ctrls[i].ctl)->sattr = cm[DL_ESEL];
  400.                 break;
  401.         }
  402.     }
  403. }
  404.  
  405. void SetDialogColors(void)
  406. {
  407.     SetDlgColor(&settings);
  408.     SetDlgColor(&get_string);
  409.     cb.num = 3;
  410.     SetDlgColor(&cb);
  411. }
  412.  
  413. /* end */
  414.