home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk19 / dir01 / f016390.re_ / f016390.re
Text File  |  1996-04-02  |  76KB  |  2,328 lines

  1. /*----------------------------------------------------------------------+
  2. |                                    |
  3. |  Copyright (1995) Bentley Systems, Inc., All rights reserved.        |
  4. |                                    |
  5. |  "MicroStation" is a registered trademark and "MDL" and "MicroCSL"    |
  6. |  are trademarks of Bentley Systems, Inc.                    |
  7. |                                    |
  8. |  Limited permission is hereby granted to reproduce and modify this    |
  9. |  copyrighted material provided that the resulting code is used only     |
  10. |  in conjunction with Bentley Systems products under the terms of the    |
  11. |  license agreement provided therein, and that this notice is retained    |
  12. |  in its entirety in any such reproduction or modification.        |
  13. |                                    |
  14. +----------------------------------------------------------------------*/
  15. /*----------------------------------------------------------------------+
  16. |                                    |
  17. |   $Workfile:   newitems.mc  $
  18. |   $Revision:   5.37  $
  19. |       $Date:   07 Sep 1995 20:03:32  $
  20. |                                    |
  21. +----------------------------------------------------------------------*/
  22. /*----------------------------------------------------------------------+
  23. |                                    |
  24. |   Function -                                |
  25. |                                    |
  26. |    MDL example to show new items                    |
  27. |                                    |
  28. |    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    |
  29. |                                    |
  30. |   Public Routine Summary -                        |
  31. |                                    |
  32. |    newItems_radioButtonHook - Radio button hook function        |
  33. |    newItems_moveTiedToSpeedScale - Scale motion function        |
  34. |    newItems_speedScaleHook - Scale hook function            |
  35. |    newItems_changeDefaultPushButton - Change a default push button    |
  36. |    newItems_defaultPBOptionBtnHook - Option button hook function    |
  37. |    newItems_adjustSashDialogItems - Move sashes in dialog box    |
  38. |    newItems_sashMotionFunc - Sash motion function            |
  39. |    newItems_sashHook - Sash hook function                |
  40. |    newItems_sashListBoxHook - Sash list box hook function        |
  41. |    newItems_sashDialogHook - Sash dialog box hook function        |
  42. |    newItems_colorsDialogHook - Colors dialog box hook function    |
  43. |    newItems_colorsToggleBtnHook - Colors toggle button hook func    |
  44. |    newItems_setSelectionList - Set up selection list entries    |
  45. |    newItems_trackList - List box motion function            |
  46. |    newItems_multiListInitStrList - Multi-list init function    |
  47. |    newItems_multiListInitDisabled - Multi-list disable function    |
  48. |    newItems_multiListBoxHook - Mulit-list list box hook        |
  49. |    newItems_maintainMultiListModifyMenu,                |
  50. |        newItems_maintainMultiListSelectMenu,            |
  51. |        newItems_maintainMultiListPositionMenu,            |
  52. |        newItems_maintainMultiListLocationMenu - Misc multi-list    |
  53. |            functions                        |
  54. |    newItems_multiListInsertItem - Add item to list            |
  55. |    newItems_doMultiListModify - Handle multi-list modify        |
  56. |    newItems_doMultiListSelect - Handle multi-list select        |
  57. |    newItems_doMultiListPosition - Handle multi-list position    |
  58. |    newItems_doMultiListLocation - Handle multi-list location    |
  59. |    newItems_multiListTestsMenusHook - Multi-list hook function    |
  60. |    newItems_setupPopupMenu - Init popup menus            |
  61. |    newItems_multiListDialogHook - Multi-list dialog box hook    |
  62. |    newItems_draw2DArrows -  2D arrow draw function            |
  63. |    newItems_2DArrowsDialogHook - 2D arrow dialog hook        |
  64. |    newItems_open - Open command function                |
  65. |    newItems_openModal - Open modal dialog                |
  66. |    newItems_exit - Exit application                |
  67. |    newItems_rscSprintf - sprintf from resource file        |
  68. |    newItems_errorPrint - Print error message            |
  69. |    newItems_unloadFunction - Unload function            |
  70. |    newItems_scaleColor - Scale color determination            |
  71. |    newItems_handleRemap - Color table asynch function        |
  72. |    main - Main entry point                        |
  73. |                                    |
  74. +----------------------------------------------------------------------*/
  75. /*----------------------------------------------------------------------+
  76. |                                    |
  77. |   Include Files                               |
  78. |                                    |
  79. +----------------------------------------------------------------------*/
  80. #include    <mdl.h>        /* MDL Library funcs structures & constants */
  81. #include    <dlogitem.h>    /* Dialog Box Manager structures & constants */
  82. #include    <cexpr.h>        /* C Expression structures & constants */
  83. #include    <userfnc.h>
  84. #include    <cmdlist.h>        /* MicroStation command numbers */
  85. #include    <colrname.h>
  86. #include    <stdarg.h>
  87. #include    <dlogids.h>
  88. #include    <stdlib.h>
  89. #include    <string.h>
  90. #include    <stdio.h>
  91.  
  92. #include    "newitems.h"    /* basic dialog box example constants & structs */
  93. #include    "newicmd.h"        /* basic dialog box command numbers */
  94.  
  95. #include    <dlogman.fdf>   /* dialog box manager function prototypes */
  96. #include    <mscolor.fdf>   /* color manager function prototypes */
  97. #include    <msparse.fdf>
  98. #include    <mscexpr.fdf>
  99. #include    <msdialog.fdf>
  100. #include    <msrsrc.fdf>
  101. #include    <mssystem.fdf>
  102. #include    <msoutput.fdf>
  103.  
  104. /*----------------------------------------------------------------------+
  105. |                                    |
  106. |   Local defines                            |
  107. |                                    |
  108. +----------------------------------------------------------------------*/
  109. #define    NMULTILIST_LINES    30
  110.  
  111. /*----------------------------------------------------------------------+
  112. |                                    |
  113. |   Private Global variables                        |
  114. |                                    |
  115. +----------------------------------------------------------------------*/
  116. static NewItemsGlobals    niG = {1, 0};
  117.  
  118. /*----------------------------------------------------------------------+
  119. |                                    |
  120. |   Utility routines                            |
  121. |                                    |
  122. +----------------------------------------------------------------------*/
  123. /*----------------------------------------------------------------------+
  124. |                                                                       |
  125. |   Name    newItems_rscSprintf                    |
  126. |                                                                       |
  127. |   Author    BSI                                         3/93        |
  128. |                                                                       |
  129. +----------------------------------------------------------------------*/
  130. Private void newItems_rscSprintf
  131. (
  132. char   *stringP,        /* <=  Result of sprintf from resource    */
  133. int    messageNumber,        /*  => Index into msg list for format str    */
  134. ...                /*  => Any other optional arguments        */
  135. )
  136.     {
  137.     va_list ap;
  138.     char    tempStr[1024];
  139.  
  140.     va_start (ap, messageNumber);
  141.  
  142.     *stringP = tempStr[0] = '\0';
  143.     mdlResource_loadFromStringList (tempStr, NULL, MESSAGELISTID_NewItems,
  144.                     messageNumber);
  145.     vsprintf (stringP, tempStr, ap);
  146.  
  147.     va_end (ap);
  148.     }
  149.  
  150. /*----------------------------------------------------------------------+
  151. |                                                                       |
  152. | name          newItems_errorPrint -- print an error message into    |
  153. |                  Dialog Box Manager Messages dialog box    |
  154. |                                                                       |
  155. | author        BSI                                     08/92           |
  156. |                                                                       |
  157. +----------------------------------------------------------------------*/
  158. Private void newItems_errorPrint
  159. (
  160. int errorNumber            /* => number of error to print */
  161. )
  162.     {
  163.     char    errorMsg[80];
  164.  
  165.     if (mdlResource_loadFromStringList (errorMsg, NULL,
  166.                     MESSAGELISTID_NewItems, errorNumber))
  167.     return;    /* unable to find message with number "errorNumber" */
  168.  
  169.     mdlDialog_dmsgsPrint (errorMsg);
  170.     }
  171.  
  172. /*----------------------------------------------------------------------+
  173. |                                                                       |
  174. |   Hook Functions                            |
  175. |                                                                       |
  176. +----------------------------------------------------------------------*/ 
  177. /*----------------------------------------------------------------------+
  178. |                                    |
  179. | name        newItems_radioButtonHook                |
  180. |                                    |
  181. | author    BSI                     08/92        |
  182. |                                    |
  183. +----------------------------------------------------------------------*/
  184. Private void newItems_radioButtonHook
  185. (
  186. DialogItemMessage   *dimP    /* => a ptr to a dialog item message */
  187. )
  188.     {
  189.     dimP->msgUnderstood = TRUE;
  190.  
  191.     switch (dimP->messageType)
  192.     {
  193.     case DITEM_MESSAGE_CREATE:
  194.         break;
  195.  
  196.     case DITEM_MESSAGE_STATECHANGED:
  197.         {
  198.         int     chosenRadioButton;
  199.         char    template[25];
  200.         char    buffer[40];
  201.         DialogItem       *diP = dimP->dialogItemP;
  202.  
  203.         mdlResource_loadFromStringList(template, NULL,
  204.                 MESSAGELISTID_NewItems, MSGID_RadioBtnChoice);
  205.  
  206.         switch (diP->id)
  207.             {
  208.         case RBUTTONID_Option1:
  209.             case RBUTTONID_Option2:
  210.             case RBUTTONID_Option3:
  211.             {
  212.             chosenRadioButton = niG.parameter1;
  213.             break;
  214.             }
  215.  
  216.         default:
  217.             {
  218.             chosenRadioButton = niG.parameter4;
  219.             break;
  220.             }
  221.             }
  222.  
  223.         sprintf(buffer, template, chosenRadioButton);
  224.         mdlOutput_status (buffer);
  225.     
  226.         break;
  227.         }
  228.  
  229.     default:
  230.         dimP->msgUnderstood = FALSE;
  231.         break;
  232.         }
  233.     }
  234.  
  235. /*----------------------------------------------------------------------+
  236. |                                                                       |
  237. | name          newItems_moveTiedToSpeedScale                |
  238. |                                                                       |
  239. | author        BSI                    08/92           |
  240. |                                                                       |
  241. +----------------------------------------------------------------------*/
  242. Private void newItems_moveTiedToSpeedScale
  243. (
  244. Scale_MotionFuncArg *mfaP
  245. )
  246.     {
  247.     if (niG.currentSpeedScaleP)
  248.     {
  249.     DialogItem  *tiedToSpeedScaleDiP =
  250.         (DialogItem *) niG.currentSpeedScaleP->userDataP;
  251.  
  252.     if (tiedToSpeedScaleDiP)
  253.         {
  254.         ValueUnion  value;
  255.  
  256.         value.doubleFormat = mfaP->value;
  257.         mdlDialog_itemSetValue (NULL, FMT_DPFP, &value, NULL,
  258.                 tiedToSpeedScaleDiP->rawItemP->ownerDialogP,
  259.                 tiedToSpeedScaleDiP->itemIndex);
  260.         }
  261.     }
  262.     }
  263.  
  264. /*----------------------------------------------------------------------+
  265. |                                    |
  266. | name        newItems_speedScaleHook                    |
  267. |                                    |
  268. | author    BSI                     08/92        |
  269. |                                    |
  270. +----------------------------------------------------------------------*/
  271. Private void newItems_speedScaleHook
  272. (
  273. DialogItemMessage   *dimP    /* => a ptr to a dialog item message */
  274. )
  275.     {
  276.     dimP->msgUnderstood = TRUE;
  277.  
  278.     switch (dimP->messageType)
  279.     {
  280.     case DITEM_MESSAGE_ALLCREATED:
  281.         {
  282.         RawItemHdr    *scaleP = dimP->dialogItemP->rawItemP;
  283.  
  284.         /* store a ptr to the "tiedToSpeed" scale item for later use by
  285.            motionFunc */
  286.         scaleP->userDataP =    mdlDialog_itemGetByTypeAndId (dimP->db,
  287.                             RTYPE_Scale,
  288.                             SCALEID_TiedToSpeed, 0);
  289.         break;
  290.         }
  291.  
  292.     case DITEM_MESSAGE_BUTTON:
  293.         if (dimP->u.button.buttonTrans == BUTTONTRANS_DOWN)
  294.         {
  295.             niG.currentSpeedScaleP = dimP->dialogItemP->rawItemP;
  296.         dimP->u.button.motionFunc = newItems_moveTiedToSpeedScale;
  297.         }
  298.         else if (dimP->u.button.buttonTrans == BUTTONTRANS_UP)
  299.         {
  300.             niG.currentSpeedScaleP = NULL;
  301.         }
  302.  
  303.         break;
  304.  
  305.     case RTYPE_Scale:
  306.         {
  307.         char    msg[20];
  308.  
  309.         if (dimP->auxMessageType == SCALE_AUXMESSAGE_FORMATVALUE)
  310.         {
  311.         Scale_FormatValue   *formatValueP =
  312.             (Scale_FormatValue *) dimP->auxInfoP;
  313.  
  314.         if (formatValueP->value < 15.0)
  315.             mdlResource_loadFromStringList (msg, NULL,
  316.                             MESSAGELISTID_NewItems,
  317.                             MSGID_VerySlow);
  318.         else if (formatValueP->value < 30.0)
  319.             mdlResource_loadFromStringList (msg, NULL,
  320.                             MESSAGELISTID_NewItems,
  321.                             MSGID_Slow);
  322.         else if (formatValueP->value < 70.0)
  323.             mdlResource_loadFromStringList (msg, NULL,
  324.                             MESSAGELISTID_NewItems,
  325.                             MSGID_Normal);
  326.         else if (formatValueP->value < 85.0)
  327.             mdlResource_loadFromStringList (msg, NULL,
  328.                             MESSAGELISTID_NewItems,
  329.                             MSGID_Fast);
  330.         else
  331.             mdlResource_loadFromStringList (msg, NULL,
  332.                             MESSAGELISTID_NewItems,
  333.                             MSGID_VeryFast);
  334.         strcpy (formatValueP->valueStrP, msg);
  335.  
  336.         formatValueP->hookHandled = TRUE;
  337.         }
  338.         break;
  339.         }
  340.  
  341.     default:
  342.         dimP->msgUnderstood = FALSE;
  343.         break;
  344.         }
  345.     }
  346.  
  347. /*----------------------------------------------------------------------+
  348. |                                    |
  349. |   Multi-Line PushButton Dialog Hooks                    |
  350. |                                    |
  351. +----------------------------------------------------------------------*/
  352. /*----------------------------------------------------------------------+
  353. |                                                                       |
  354. | name          newItems_changeDefaultPushButton            |
  355. |                                                                       |
  356. | author        BSI                    01/93           |
  357. |                                                                       |
  358. +----------------------------------------------------------------------*/
  359. Private void newItems_changeDefaultPushButton
  360. (
  361. DialogItemMessage   *dimP    /* => a ptr to a dialog item message */
  362. )
  363.     {
  364.     /* see if there is not supposed to be any default pushButton */
  365.     if (niG.defaultPushButtonId == 0)
  366.     {
  367.     int currentDefaultItem = mdlDialog_itemGetDefault (dimP->db);
  368.  
  369.     if (currentDefaultItem >= 0)
  370.         {
  371.         DialogItem    *oldDefaultDiP;
  372.         RawItemHdr    *oldRihP;
  373.  
  374.         oldDefaultDiP = mdlDialog_itemGetByIndex (dimP->db,
  375.                               currentDefaultItem);
  376.         if (oldDefaultDiP && (oldDefaultDiP->type == RTYPE_PushButton) &&
  377.         (oldRihP = oldDefaultDiP->rawItemP))
  378.         {
  379.         mdlDialog_pushButtonSetDefault (oldRihP, FALSE);
  380.         }
  381.         }
  382.     }
  383.     else
  384.     {
  385.     DialogItem    *diP;
  386.  
  387.     diP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_PushButton,
  388.                         niG.defaultPushButtonId, 0);
  389.     if (diP && diP->rawItemP && diP->type == RTYPE_PushButton)
  390.         mdlDialog_pushButtonSetDefault (diP->rawItemP, TRUE);
  391.     }
  392.     }
  393.  
  394. /*----------------------------------------------------------------------+
  395. |                                                                       |
  396. | name          newItems_defaultPBOptionBtnHook                |
  397. |                                                                       |
  398. | author        BSI                    01/93           |
  399. |                                                                       |
  400. +----------------------------------------------------------------------*/
  401. Private void newItems_defaultPBOptionBtnHook
  402. (
  403. DialogItemMessage   *dimP    /* => a ptr to a dialog item message */
  404. )
  405.     {
  406.     dimP->msgUnderstood = TRUE;
  407.  
  408.     switch (dimP->messageType)
  409.     {
  410.     case DITEM_MESSAGE_STATECHANGED:
  411.         if (dimP->u.stateChanged.reallyChanged)
  412.         {
  413.         newItems_changeDefaultPushButton (dimP);
  414.         }
  415.         break;
  416.  
  417.     default:
  418.         dimP->msgUnderstood = FALSE;
  419.         break;
  420.         }
  421.     }
  422.  
  423. /*----------------------------------------------------------------------+
  424. |                                    |
  425. |   Sash Example Dialog Routines                    |
  426. |                                    |
  427. +----------------------------------------------------------------------*/
  428. /*----------------------------------------------------------------------+
  429. |                                                                       |
  430. | name          newItems_adjustSashDialogItems                |
  431. |                                                                       |
  432. | author        BSI                    09/92           |
  433. |                                                                       |
  434. +----------------------------------------------------------------------*/
  435. Private void newItems_adjustSashDialogItems
  436. (
  437. DialogBox   *db,
  438. int         deltaWidth
  439. )
  440.     {
  441.     DialogItem    *diP;
  442.     RawItemHdr    *sashP;
  443.     RawItemHdr    *topListP;
  444.     RawItemHdr    *bottomListP;
  445.     int         size, nRows, colWidth;
  446.     Point2d     pt;
  447.     BSIRect     contentRect;
  448.     int         fontHeight = mdlDialog_fontGetCurHeight (db);
  449.  
  450.     diP = mdlDialog_itemGetByTypeAndId (db, RTYPE_Sash, SASHID_Example, 0);
  451.     if (!diP)
  452.     return;
  453.     sashP = diP->rawItemP;
  454.  
  455.     diP = mdlDialog_itemGetByTypeAndId (db, RTYPE_ListBox, LISTBOXID_Sash1, 0);
  456.     if (!diP)
  457.     return;
  458.     topListP = diP->rawItemP;
  459.  
  460.     diP = mdlDialog_itemGetByTypeAndId (db, RTYPE_ListBox, LISTBOXID_Sash2, 0);
  461.     if (!diP)
  462.     return;
  463.     bottomListP = diP->rawItemP;
  464.  
  465.     mdlWindow_contentRectGetLocal (&contentRect, db);
  466.  
  467.     /* Can't hide the items since this removes the focus, so just clear the area */
  468. /*  mdlDialog_itemHide (db, topListP->diP->itemIndex, TRUE);
  469.     mdlDialog_itemHide (db, bottomListP->diP->itemIndex, TRUE); */
  470.     mdlWindow_rectClear (db, &topListP->diP->rect, NULL);
  471.     mdlWindow_rectClear (db, &bottomListP->diP->rect, NULL);
  472.  
  473.     /* adjust size of column 0 so listBox is horizontally resized */
  474.     mdlDialog_listBoxGetColInfo (&colWidth, NULL, NULL, NULL, topListP, 0);
  475.     if (deltaWidth != 0)
  476.     {
  477.     int listWidth;        /* size list including scrollBar & bevel */
  478.     int colWidthPixels; /* width of column in pixels */
  479.     int adjustWidth;    /* subtracted from listWidth gives width col in pixels */
  480.  
  481.     listWidth      = mdlDialog_rectWidth (&topListP->diP->rect);
  482.     colWidthPixels = mdlDialog_toPixels (db, colWidth);
  483.     adjustWidth    = listWidth - colWidthPixels;
  484.     colWidthPixels = (sashP->itemRect.corner.x - fontHeight/2) - adjustWidth;
  485.  
  486.     colWidth = mdlDialog_toDCoord (db, colWidthPixels);
  487.     mdlDialog_listBoxSetColInfo (&colWidth, NULL, NULL, NULL, topListP,
  488.                      0, FALSE);
  489.     }
  490.  
  491.     /* adjust horizontal positions of lists so scrollBars line up with sash
  492.        (see Visual Design with OSF/Motif, Kobara, pages 93-94) */
  493.     pt.y = -topListP->itemRect.origin.y;   /* neg num means pixels specified */
  494.     pt.x = -(topListP->itemRect.origin.x +
  495.         (sashP->itemRect.corner.x - topListP->diP->rect.corner.x));
  496.     mdlDialog_itemMove (db, topListP->diP->itemIndex, &pt, FALSE);
  497.  
  498.     /* fix vertical size of top List */
  499.     size  = sashP->itemRect.origin.y - topListP->itemRect.origin.y -
  500.         0.75*fontHeight;
  501.     nRows = size / (fontHeight + fontHeight/6);
  502.     mdlDialog_listBoxSetInfo (NULL, &nRows, NULL, FALSE, topListP);
  503.     mdlDialog_itemDraw (db, topListP->diP->itemIndex);
  504.  
  505.     /* adjust size of column 0 so listBox is horizontally resized */
  506.     if (deltaWidth != 0)
  507.     {
  508.     mdlDialog_listBoxSetColInfo (&colWidth, NULL, NULL, NULL, bottomListP,
  509.                      0, FALSE);
  510.     }
  511.  
  512.     /* Move bottom list; neg num means pixels specified */
  513.     pt.y = -(sashP->itemRect.corner.y + fontHeight/2);
  514.     pt.x = -(bottomListP->itemRect.origin.x +
  515.         (sashP->itemRect.corner.x - bottomListP->diP->rect.corner.x));
  516.     mdlDialog_itemMove (db, bottomListP->diP->itemIndex, &pt, FALSE);
  517.  
  518.     /* fix size of bottom List */
  519.     size  = contentRect.corner.y + pt.y - 0.75*fontHeight;
  520.     nRows = size / (fontHeight + fontHeight/6);
  521.     mdlDialog_listBoxSetInfo (NULL, &nRows, NULL, FALSE, bottomListP);
  522.  
  523.     mdlDialog_itemDraw (db, bottomListP->diP->itemIndex);
  524.     }
  525.  
  526. /*----------------------------------------------------------------------+
  527. |                                                                       |
  528. | name          newItems_sashMotionFunc                    |
  529. |                                                                       |
  530. | author        BSI                    09/92           |
  531. |                                                                       |
  532. +----------------------------------------------------------------------*/
  533. Private void newItems_sashMotionFunc    /* called each time user moves mouse
  534.                        while dragging sash */
  535. (
  536. MotionFuncArg    *mfaP    /* <> mfaP->pt.y = where sash upper left corner will go */
  537.             /* => mfaP->pt.x = where cursor y position is */
  538.             /* => mfaP->dragging = TRUE if cursor is within window */
  539. )
  540.     {
  541.     if (mfaP->pt.y < niG.minSashY)
  542.     mfaP->pt.y = niG.minSashY;
  543.  
  544.     if (mfaP->pt.y > niG.maxSashY)
  545.     mfaP->pt.y = niG.maxSashY;
  546.     }
  547.  
  548. /*----------------------------------------------------------------------+
  549. |                                                                       |
  550. | name          newItems_sashHook                    |
  551. |                                                                       |
  552. | author        BSI                    09/92           |
  553. |                                                                       |
  554. +----------------------------------------------------------------------*/
  555. Private void newItems_sashHook
  556. (
  557. DialogItemMessage   *dimP    /* => a ptr to a dialog item message */
  558. )
  559.     {
  560.     dimP->msgUnderstood = TRUE;
  561.  
  562.     switch (dimP->messageType)
  563.     {
  564.     case DITEM_MESSAGE_BUTTON:
  565.         {
  566.         if (dimP->u.button.buttonTrans == BUTTONTRANS_DOWN)
  567.         {
  568.         BSIRect     contentRect;
  569.         int     fontHeight = mdlDialog_fontGetCurHeight (dimP->db);
  570.  
  571.         dimP->u.button.motionFunc = newItems_sashMotionFunc;
  572.  
  573.         mdlWindow_contentRectGetLocal (&contentRect, dimP->db);
  574.         niG.minSashY = 5*fontHeight;
  575.         niG.maxSashY =
  576.             mdlDialog_rectHeight (&contentRect) -
  577.             5*fontHeight;
  578.         }
  579.         else if (dimP->u.button.buttonTrans == BUTTONTRANS_UP)
  580.         {
  581.         Sash_ButtonUpAuxInfo *buaiP =
  582.             (Sash_ButtonUpAuxInfo *) dimP->auxInfoP;
  583.  
  584.         /* use buaiP->newYPos to determine where upperLeft corner
  585.            of sash beveled rect will go.  This message is sent after
  586.            sash has been erased from old position & moved, but before
  587.            it has been drawn */
  588.         if (buaiP->newYPos != buaiP->oldYPos)
  589.             newItems_adjustSashDialogItems (dimP->db, 0);
  590.         }
  591.  
  592.         break;
  593.         }
  594.  
  595.     default:
  596.         dimP->msgUnderstood = FALSE;
  597.         break;
  598.         }
  599.     }
  600.  
  601. /*----------------------------------------------------------------------+
  602. |                                                                       |
  603. | name          newItems_sashListBoxHook                |
  604. |                                                                       |
  605. | author        BSI                    08/92        |
  606. |                                                                       |
  607. +----------------------------------------------------------------------*/
  608. Private void newItems_sashListBoxHook
  609. (
  610. DialogItemMessage   *dimP
  611. )
  612.     {
  613.     dimP->msgUnderstood = TRUE;
  614.     switch (dimP->messageType)
  615.     {
  616.     case DITEM_MESSAGE_CREATE:
  617.         {
  618.         int         iString;
  619.         DialogItem    *diP = dimP->dialogItemP;
  620.         RawItemHdr    *rihP = diP->rawItemP;
  621.         StringList    *strListP;
  622.         char     formatStr[20];
  623.  
  624.         /* NOTE: nInfoFields is 2 so 2nd infoField can be used
  625.            to store a ptr to a BSIColorDesc */
  626.         rihP->userDataP = strListP = mdlStringList_create (15, 2);
  627.         if (!strListP)
  628.         {
  629.         dimP->u.create.createFailed = TRUE;
  630.         return;
  631.         }
  632.  
  633.         mdlResource_loadFromStringList (formatStr, NULL,
  634.                         MESSAGELISTID_NewItems,
  635.                         MSGID_Line);
  636.         for (iString=0; iString<15; iString++)
  637.         {
  638.         char    buffer[80];
  639.  
  640.         sprintf (buffer, formatStr, iString);
  641.         mdlStringList_setMember (strListP, iString, buffer, NULL);
  642.         }
  643.  
  644.         mdlDialog_listBoxSetStrListP (rihP, strListP, 1);
  645.         break;
  646.         }
  647.  
  648.     case DITEM_MESSAGE_DESTROY:
  649.         {
  650.         DialogItem    *diP = dimP->dialogItemP;
  651.         RawItemHdr    *rihP = diP->rawItemP;
  652.  
  653.         if (rihP->userDataP)
  654.         {
  655.         mdlStringList_destroy (rihP->userDataP);
  656.         }
  657.         break;
  658.         }
  659.  
  660.     default:
  661.         dimP->msgUnderstood = FALSE;
  662.     }
  663.     }
  664.  
  665. /*----------------------------------------------------------------------+
  666. |                                                                       |
  667. | name          newItems_sashDialogHook                    |
  668. |                                                                       |
  669. | author        BSI                    09/92           |
  670. |                                                                       |
  671. +----------------------------------------------------------------------*/
  672. Private void    newItems_sashDialogHook
  673. (
  674. DialogMessage    *dmP        /* => a ptr to a dialog message */
  675. )
  676.     {
  677.     dmP->msgUnderstood = TRUE;
  678.     switch (dmP->messageType)
  679.     {
  680.     case DIALOG_MESSAGE_CREATE:
  681.         {
  682.         dmP->u.create.interests.resizes   = TRUE;
  683.         dmP->u.create.interests.mouses    = TRUE;
  684.         dmP->u.create.interests.nonDataPoints = TRUE;
  685.         break;
  686.         }
  687.  
  688.     case DIALOG_MESSAGE_INIT:
  689.         {
  690.         DialogItem    *diP;
  691.  
  692.         diP = mdlDialog_itemGetByTypeAndId (dmP->db, RTYPE_Sash,
  693.                         SASHID_Example, 0);
  694.         if (!diP)
  695.         break;
  696.  
  697.         newItems_adjustSashDialogItems (dmP->db, 0);
  698.         break;
  699.         }
  700.  
  701.     case DIALOG_MESSAGE_RESIZE:
  702.         {
  703.         int        newWidth, oldWidth;
  704.         BSIRect contentRect;
  705.  
  706.         if (dmP->u.resize.whichCorners == CORNER_ALL)
  707.         break;
  708.         if (1 == mdlDialog_rectHeight (&dmP->u.resize.newContent))
  709.         break;        /* dialog was minimized */
  710.  
  711.         newWidth = mdlDialog_rectWidth (&dmP->u.resize.newContent);
  712.         oldWidth = mdlDialog_rectWidth (&dmP->u.resize.oldContent);
  713.  
  714.         newItems_adjustSashDialogItems (dmP->db, newWidth-oldWidth);
  715.         break;
  716.         }
  717.  
  718.     default:
  719.         dmP->msgUnderstood = FALSE;
  720.         break;
  721.     }
  722.     }
  723.  
  724. /*----------------------------------------------------------------------+
  725. |                                                                       |
  726. | name          newItems_colorsDialogHook                |
  727. |                                                                       |
  728. | author        BSI                    09/92           |
  729. |                                                                       |
  730. +----------------------------------------------------------------------*/
  731. Private void    newItems_colorsDialogHook
  732. (
  733. DialogMessage    *dmP        /* => a ptr to a dialog message */
  734. )
  735.     {
  736.     dmP->msgUnderstood = TRUE;
  737.     switch (dmP->messageType)
  738.     {
  739.     case DIALOG_MESSAGE_CREATE:
  740.         {
  741.         dmP->u.create.interests.mouses    = TRUE;
  742.         dmP->u.create.interests.keystrokes = TRUE;
  743.         break;
  744.         }
  745.  
  746.     case DIALOG_MESSAGE_INIT:
  747.         {
  748.         DialogItem    *diP;
  749.  
  750.         diP = mdlDialog_itemGetByTypeAndId (dmP->db, RTYPE_ToggleButton,
  751.                         TOGGLEBTNID_Colored, 0);
  752.         if (diP)
  753.         {
  754.         mdlDialog_rItemColorSet (diP->rawItemP,
  755.                      DITEM_COLORTYPE_BACKGROUND,
  756.                      niG.localColorsP[LCOLOR_BACKGROUND]);
  757.         mdlDialog_rItemColorSet (diP->rawItemP,
  758.                      DITEM_COLORTYPE_FOREGROUND,
  759.                      niG.localColorsP[LCOLOR_LABELTEXT]);
  760.         mdlDialog_rItemColorSet (diP->rawItemP,
  761.                      DITEM_COLORTYPE_TOPSHADOW,
  762.                      niG.localColorsP[LCOLOR_TOPSHADOW]);
  763.         mdlDialog_rItemColorSet (diP->rawItemP,
  764.                      DITEM_COLORTYPE_BOTTOMSHADOW,
  765.                      niG.localColorsP[LCOLOR_BOTTOMSHADOW]);
  766.         mdlDialog_rItemColorSet (diP->rawItemP,
  767.                      DITEM_COLORTYPE_SELECT,
  768.                      niG.localColorsP[LCOLOR_SELECT]);
  769.         }
  770.  
  771.         diP = mdlDialog_itemGetByTypeAndId (dmP->db, RTYPE_RadioButton,
  772.                         RBUTTONID_Option1, 0);
  773.         if (diP)
  774.         {
  775.         mdlDialog_rItemColorSet (diP->rawItemP,
  776.                      DITEM_COLORTYPE_BACKGROUND,
  777.                      niG.localColorsP[LCOLOR_BACKGROUND]);
  778.         mdlDialog_rItemColorSet (diP->rawItemP,
  779.                      DITEM_COLORTYPE_TOPSHADOW,
  780.                      niG.localColorsP[LCOLOR_TOPSHADOW]);
  781.         mdlDialog_rItemColorSet (diP->rawItemP,
  782.                      DITEM_COLORTYPE_BOTTOMSHADOW,
  783.                      niG.localColorsP[LCOLOR_BOTTOMSHADOW]);
  784.         mdlDialog_rItemColorSet (diP->rawItemP,
  785.                      DITEM_COLORTYPE_SELECT,
  786.                      niG.localColorsP[LCOLOR_SELECT]);
  787.         }
  788.  
  789.         diP = mdlDialog_itemGetByTypeAndId (dmP->db, RTYPE_ListBox,
  790.                         LISTBOXID_Sash1, 0);
  791.         if (diP)
  792.         {
  793.         long       *infoFieldsP;
  794.         StringList *strListP = (StringList *)diP->rawItemP->userDataP;
  795.  
  796.         mdlStringList_getMember (NULL, &infoFieldsP, strListP, 1);
  797.         *(infoFieldsP + 1) = (long) niG.localColorsP[LCOLOR_BOTTOMSHADOW];
  798.         mdlStringList_getMember (NULL, &infoFieldsP, strListP, 2);
  799.         *(infoFieldsP + 1) = (long) niG.localColorsP[LCOLOR_DGN];
  800.         }
  801.         break;
  802.         }
  803.  
  804.     default:
  805.         dmP->msgUnderstood = FALSE;
  806.         break;
  807.     }
  808.     }
  809.  
  810. /*----------------------------------------------------------------------+
  811. |                                    |
  812. | name        newItems_colorsToggleBtnHook                |
  813. |                                    |
  814. | author    BSI                     10/92        |
  815. |                                    |
  816. +----------------------------------------------------------------------*/
  817. Private void newItems_colorsToggleBtnHook
  818. (
  819. DialogItemMessage   *dimP    /* => a ptr to a dialog item message */
  820. )
  821.     {
  822.     dimP->msgUnderstood = TRUE;
  823.  
  824.     switch (dimP->messageType)
  825.     {
  826.     case DITEM_MESSAGE_STATECHANGED:
  827.         {
  828.         DialogItem    *diP;
  829.  
  830.         if (!dimP->u.stateChanged.reallyChanged)
  831.         break;
  832.  
  833.         diP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_ListBox,
  834.             LISTBOXID_Sash1, 0);
  835.         if (diP)
  836.         {
  837.         if (niG.parameter3)
  838.             {
  839.             mdlDialog_rItemColorSet (diP->rawItemP,
  840.                          DITEM_COLORTYPE_BACKGROUND,
  841.                          niG.localColorsP[LCOLOR_BACKGROUND]);
  842.             mdlDialog_itemDraw (dimP->db, diP->itemIndex);
  843.             }
  844.         else
  845.             {
  846.             mdlDialog_rItemColorSet (diP->rawItemP,
  847.                          DITEM_COLORTYPE_BACKGROUND,
  848.                          NULL);
  849.             mdlDialog_itemDraw (dimP->db, diP->itemIndex);
  850.             }
  851.         }
  852.  
  853.         diP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_Text,
  854.             TEXTID_Colored, 0);
  855.         if (diP)
  856.         {
  857.         if (niG.parameter3)
  858.             {
  859.             mdlDialog_rItemColorSet (diP->rawItemP,
  860.                          DITEM_COLORTYPE_BACKGROUND,
  861.                          niG.localColorsP[LCOLOR_BGTEXT]);
  862.             mdlDialog_rItemColorSet (diP->rawItemP,
  863.                          DITEM_COLORTYPE_FOREGROUND,
  864.                          niG.localColorsP[LCOLOR_FGTEXT]);
  865.             mdlDialog_itemDraw (dimP->db, diP->itemIndex);
  866.             }
  867.         else
  868.             {
  869.             mdlDialog_rItemColorSet (diP->rawItemP,
  870.                          DITEM_COLORTYPE_BACKGROUND,
  871.                          NULL);
  872.             mdlDialog_rItemColorSet (diP->rawItemP,
  873.                          DITEM_COLORTYPE_FOREGROUND,
  874.                          NULL);
  875.             mdlDialog_itemDraw (dimP->db, diP->itemIndex);
  876.             }
  877.         }
  878.  
  879.         break;
  880.         }
  881.  
  882.     default:
  883.         dimP->msgUnderstood = FALSE;
  884.         break;
  885.         }
  886.     }
  887.  
  888. /*----------------------------------------------------------------------+
  889. |                                                                       |
  890. | name          newItems_setSelectionList                |
  891. |                                                                       |
  892. | author        BSI                    10/92           |
  893. |                                                                       |
  894. +----------------------------------------------------------------------*/
  895. Private void newItems_setSelectionList
  896. (
  897. void
  898. )
  899.     {
  900.     int         iRow;
  901.     DialogItem    *diP;
  902.     RawItemHdr    *listP, *mListP;
  903.     StringList    *strListP, *mStrListP;
  904.     int         nSelections;
  905.     Spoint2d    *selections;
  906.     Spoint2d    *curSelectionP;
  907.  
  908.     if (!niG.selectionListDiP || !niG.selectionListDiP->rawItemP)
  909.     return;
  910.     listP = niG.selectionListDiP->rawItemP;
  911.     strListP = mdlDialog_listBoxGetStrListP (listP);
  912.     if (!strListP)
  913.     return;
  914.  
  915.     if (!niG.multiListDiP || !niG.multiListDiP->rawItemP)
  916.     return;
  917.  
  918.     mListP = niG.multiListDiP->rawItemP;
  919.     mStrListP = mdlDialog_listBoxGetStrListP (mListP);
  920.     if (!mStrListP)
  921.     return;
  922.  
  923.     mdlDialog_listBoxGetSelections (&nSelections, &selections, mListP);
  924.  
  925.     /* empty the string list */
  926.     mdlStringList_deleteMember (strListP, 0, -1);
  927.     if (nSelections > 0)
  928.     {
  929.     int    iMember;
  930.     char    buffer[40];
  931.     char    *stringP;
  932.  
  933.     mdlStringList_insertMember (NULL, strListP, -1, nSelections*6);
  934.  
  935.     for (iRow=0, curSelectionP=selections;
  936.          iRow<nSelections;
  937.          iRow++, curSelectionP++)
  938.         {
  939.         iMember = iRow*6;
  940.  
  941.         mdlStringList_setMember (strListP, iMember++, "{", NULL);
  942.         sprintf (buffer, "%d,", curSelectionP->y);
  943.         mdlStringList_setMember (strListP, iMember++, buffer, NULL);
  944.         sprintf (buffer, "%d ", curSelectionP->x);
  945.         mdlStringList_setMember (strListP, iMember++, buffer, NULL);
  946.         mdlStringList_setMember (strListP, iMember++, "}", NULL);
  947.  
  948.         mdlStringList_getMember (&stringP, NULL, mStrListP,
  949.                      curSelectionP->y * niG.nColumns);
  950.         mdlStringList_setMember (strListP, iMember++, stringP, NULL);
  951.  
  952.         if (niG.nColumns > 1)
  953.         {
  954.         mdlStringList_getMember (&stringP, NULL, mStrListP,
  955.                      curSelectionP->y * niG.nColumns+1);
  956.         mdlStringList_setMember (strListP, iMember++, stringP, NULL);
  957.         }
  958.         }
  959.     }
  960.  
  961.     mdlDialog_listBoxNRowsChanged (listP);
  962.     mdlDialog_listBoxSetTopRowRedraw (listP, 0, TRUE);
  963.     }
  964.  
  965. /*----------------------------------------------------------------------+
  966. |                                                                       |
  967. | name          newItems_trackList                    |
  968. |                                                                       |
  969. | author        BSI                    10/92           |
  970. |                                                                       |
  971. +----------------------------------------------------------------------*/
  972. Private void newItems_trackList
  973. (
  974. Point2d    *ptP
  975. )
  976.     {
  977.     char    buffer[40];
  978.  
  979.     if (!niG.labelDiP)
  980.     return;
  981.  
  982.     buffer[0] = '\0';
  983.     if (ptP->y != -1)
  984.     sprintf (buffer, "{%3d, %3d}", ptP->y, ptP->x);
  985.  
  986.     mdlWindow_cursorTurnOff();
  987.     mdlDialog_itemSetLabel (niG.multiSelectDbP, niG.labelDiP->itemIndex,
  988.                 buffer);
  989.     }
  990.  
  991. /*----------------------------------------------------------------------+
  992. |                                                                       |
  993. | name          newItems_multiListInitStrList                |
  994. |                                                                       |
  995. | author        BSI                    11/92           |
  996. |                                                                       |
  997. +----------------------------------------------------------------------*/
  998. Private void newItems_multiListInitStrList
  999. (
  1000. StringList  *strListP
  1001. )
  1002.     {
  1003.     int        iString;
  1004.     char    fStr1[20], fStr2[20];
  1005.  
  1006.     mdlResource_loadFromStringList (fStr1, NULL, MESSAGELISTID_NewItems,
  1007.                     MSGID_Right);
  1008.     mdlResource_loadFromStringList (fStr2, NULL, MESSAGELISTID_NewItems,
  1009.                     MSGID_Left);
  1010.     for (iString=0; iString<NMULTILIST_LINES*2; iString++)
  1011.     {
  1012.     char    buffer[80];
  1013.  
  1014.     if (iString & 1)
  1015.         sprintf (buffer, fStr1, iString/2);
  1016.     else
  1017.         sprintf (buffer, fStr2, iString/2+'A', iString/2);
  1018.  
  1019.     mdlStringList_setMember (strListP, iString, buffer, NULL);
  1020.     }
  1021.     }
  1022.  
  1023. /*----------------------------------------------------------------------+
  1024. |                                                                       |
  1025. | name          newItems_multiListInitDisabled                |
  1026. |                                                                       |
  1027. | author        BSI                    11/92           |
  1028. |                                                                       |
  1029. +----------------------------------------------------------------------*/
  1030. Private void newItems_multiListInitDisabled
  1031. (
  1032. RawItemHdr  *listP
  1033. )
  1034.     {
  1035.     mdlDialog_listBoxEnableCells (listP, 5, 6, -1, -1, FALSE, FALSE);
  1036.     mdlDialog_listBoxEnableCells (listP, 12, 12, -1, -1, FALSE, FALSE);
  1037.     }
  1038.  
  1039. /*----------------------------------------------------------------------+
  1040. |                                                                       |
  1041. | name          newItems_multiListBoxHook                |
  1042. |                                                                       |
  1043. | author        BSI                    08/92           |
  1044. |                                                                       |
  1045. +----------------------------------------------------------------------*/
  1046. Private void newItems_multiListBoxHook
  1047. (
  1048. DialogItemMessage   *dimP
  1049. )
  1050.     {
  1051.     RawItemHdr    *listP = dimP->dialogItemP->rawItemP;
  1052.  
  1053.     dimP->msgUnderstood = TRUE;
  1054.     switch (dimP->messageType)
  1055.     {
  1056.     case DITEM_MESSAGE_CREATE:
  1057.         {
  1058.         StringList    *strListP;
  1059.  
  1060.         /* NOTE: nInfoFields is 2 so 2nd infoField can be used
  1061.            to store a ptr to a BSIColorDesc */
  1062.         listP->userDataP =
  1063.         strListP = mdlStringList_create (NMULTILIST_LINES*2, 2);
  1064.         if (!strListP)
  1065.         {
  1066.         dimP->u.create.createFailed = TRUE;
  1067.         return;
  1068.         }
  1069.  
  1070.         mdlDialog_listBoxSetStrListP (listP, strListP, 2);
  1071.         newItems_multiListInitStrList (strListP);
  1072.         newItems_multiListInitDisabled (listP);
  1073.         niG.multiListDiP = dimP->dialogItemP;
  1074.         break;
  1075.         }
  1076.  
  1077.     case DITEM_MESSAGE_ALLCREATED:
  1078.         niG.multiSelectDbP = dimP->db;
  1079.         niG.labelDiP =
  1080.         mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_Label, 0, 0);
  1081.  
  1082.         niG.selectionListDiP =
  1083.         mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_ListBox,
  1084.                           LISTBOXID_SelectionList, 0);
  1085.  
  1086.         break;
  1087.  
  1088.     case DITEM_MESSAGE_DESTROY:
  1089.         if (listP->userDataP)
  1090.         {
  1091.         mdlStringList_destroy (listP->userDataP);
  1092.         }
  1093.         break;
  1094.  
  1095.     case DITEM_MESSAGE_SYNCHRONIZE:
  1096.         {
  1097.         ULong   attributes;
  1098.  
  1099.         mdlDialog_listBoxGetInfo (&attributes, NULL, NULL, listP);
  1100.  
  1101.         attributes &= ~(LISTATTR_SELBROWSE | LISTATTR_SELSINGLE |
  1102.                 LISTATTR_SELMULTI | LISTATTR_SELEXTENDED);
  1103.         switch (niG.selectionMode)
  1104.         {
  1105.         case 0:
  1106.             attributes |= LISTATTR_SELBROWSE;
  1107.             break;
  1108.  
  1109.         case 1:
  1110.             attributes |= LISTATTR_SELSINGLE;
  1111.             break;
  1112.  
  1113.         case 2:
  1114.             attributes |= LISTATTR_SELMULTI;
  1115.             break;
  1116.  
  1117.         case 3:
  1118.             attributes |= LISTATTR_SELEXTENDED;
  1119.             break;
  1120.         }
  1121.  
  1122.         mdlDialog_listBoxSetInfo (&attributes, NULL, NULL, TRUE, listP);
  1123.         break;
  1124.         }
  1125.  
  1126.     case DITEM_MESSAGE_STATECHANGED:
  1127.         if (!dimP->u.stateChanged.reallyChanged)
  1128.         break;
  1129.  
  1130.         newItems_setSelectionList ();
  1131.         break;
  1132.  
  1133.     case DITEM_MESSAGE_BUTTON:
  1134.         if (dimP->u.button.buttonTrans == BUTTONTRANS_DOWN)
  1135.         {
  1136.         dimP->u.button.motionFunc = newItems_trackList;
  1137.         }
  1138.         else if (dimP->u.button.buttonTrans == BUTTONTRANS_UP)
  1139.         {
  1140.         mdlDialog_itemSetLabel (dimP->db, niG.labelDiP->itemIndex, "");
  1141.         }
  1142.         break;
  1143.  
  1144.     default:
  1145.         dimP->msgUnderstood = FALSE;
  1146.     }
  1147.     }
  1148.  
  1149. /*----------------------------------------------------------------------+
  1150. |                                                                       |
  1151. | name          newItems_maintainMultiListModifyMenu            |
  1152. |                                                                       |
  1153. | author        BSI                    10/92           |
  1154. |                                                                       |
  1155. +----------------------------------------------------------------------*/
  1156. Private void newItems_maintainMultiListModifyMenu
  1157. (
  1158. DItem_PulldownMenu  *menuP
  1159. )
  1160.     {
  1161.     int                nSelections;
  1162.     RawItemHdr           *listP;
  1163.     DItem_PulldownMenuItem  menuItem;
  1164.     boolean            onlyOneElement =
  1165.                 (niG.selectionMode == SELECTIONMODE_BROWSE ||
  1166.                  niG.selectionMode == SELECTIONMODE_SINGLE);
  1167.  
  1168.     if (!niG.multiListDiP || !niG.multiListDiP->rawItemP)
  1169.     return;
  1170.  
  1171.     listP = niG.multiListDiP->rawItemP;
  1172.     mdlDialog_listBoxGetSelections (&nSelections, NULL, listP);
  1173.  
  1174.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  1175.                     0, MSID_AddSelection))
  1176.         mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  1177.  
  1178.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  1179.                     0, MSID_DeleteSelection))
  1180.         mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  1181.  
  1182.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  1183.                     0, MSID_ToggleAddMode))
  1184.         mdlDialog_textPDMItemSetEnabled (&menuItem,
  1185.                 niG.selectionMode == SELECTIONMODE_EXTENDED);
  1186.     }
  1187.  
  1188. /*----------------------------------------------------------------------+
  1189. |                                                                       |
  1190. | name          newItems_maintainMultiListSelectMenu            |
  1191. |                                                                       |
  1192. | author        BSI                    10/92           |
  1193. |                                                                       |
  1194. +----------------------------------------------------------------------*/
  1195. Private void newItems_maintainMultiListSelectMenu
  1196. (
  1197. DItem_PulldownMenu  *menuP
  1198. )
  1199.     {
  1200.     DItem_PulldownMenuItem  menuItem;
  1201.     boolean            onlyOneElement =
  1202.                 (niG.selectionMode == SELECTIONMODE_BROWSE ||
  1203.                  niG.selectionMode == SELECTIONMODE_SINGLE);
  1204.  
  1205.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  1206.                     0, MSID_SelectEveryOther))
  1207.     mdlDialog_textPDMItemSetEnabled (&menuItem, !onlyOneElement);
  1208.  
  1209.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  1210.                     0, MSID_SelectAll))
  1211.     mdlDialog_textPDMItemSetEnabled (&menuItem, !onlyOneElement);
  1212.  
  1213.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  1214.                     0, MSID_DeselectAll))
  1215.     mdlDialog_textPDMItemSetEnabled (&menuItem,
  1216.                 niG.selectionMode != SELECTIONMODE_BROWSE);
  1217.     }
  1218.  
  1219. /*----------------------------------------------------------------------+
  1220. |                                                                       |
  1221. | name          newItems_maintainMultiListPositionMenu            |
  1222. |                                                                       |
  1223. | author        BSI                    10/92           |
  1224. |                                                                       |
  1225. +----------------------------------------------------------------------*/
  1226. Private void newItems_maintainMultiListPositionMenu
  1227. (
  1228. DItem_PulldownMenu  *menuP
  1229. )
  1230.     {
  1231.     int                nSelections;
  1232.     RawItemHdr           *listP;
  1233.     DItem_PulldownMenuItem  menuItem;
  1234.     boolean            onlyOneElement =
  1235.     (niG.selectionMode == SELECTIONMODE_BROWSE ||
  1236.      niG.selectionMode == SELECTIONMODE_SINGLE);
  1237.  
  1238.     if (!niG.multiListDiP ||
  1239.     !niG.multiListDiP->rawItemP)
  1240.     return;
  1241.  
  1242.     listP = niG.multiListDiP->rawItemP;
  1243.     mdlDialog_listBoxGetSelections (&nSelections, NULL, listP);
  1244.  
  1245.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  1246.                 0, MSID_TopSelection))
  1247.         mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  1248.     }
  1249.  
  1250. /*----------------------------------------------------------------------+
  1251. |                                                                       |
  1252. | name        newItems_maintainMultiListLocationMenu            |
  1253. |                                                                       |
  1254. | author        BSI                    10/92           |
  1255. |                                                                       |
  1256. +----------------------------------------------------------------------*/
  1257. Private void newItems_maintainMultiListLocationMenu
  1258. (
  1259. DItem_PulldownMenu  *menuP
  1260. )
  1261.     {
  1262.     int                nSelections;
  1263.     RawItemHdr           *listP;
  1264.     DItem_PulldownMenuItem  menuItem;
  1265.     boolean            onlyOneElement =
  1266.                 (niG.selectionMode == SELECTIONMODE_BROWSE ||
  1267.                  niG.selectionMode == SELECTIONMODE_SINGLE);
  1268.  
  1269.     if (!niG.multiListDiP || !niG.multiListDiP->rawItemP)
  1270.     return;
  1271.  
  1272.     listP = niG.multiListDiP->rawItemP;
  1273.     mdlDialog_listBoxGetSelections (&nSelections, NULL, listP);
  1274.  
  1275.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL, 0,
  1276.                     MSID_LocationSelection))
  1277.     mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  1278.     }
  1279.  
  1280. /*----------------------------------------------------------------------+
  1281. |                                                                       |
  1282. | name          newItems_multiListInsertItem                |
  1283. |                                                                       |
  1284. | author        BSI                    11/92           |
  1285. |                                                                       |
  1286. +----------------------------------------------------------------------*/
  1287. Private void newItems_multiListInsertItem
  1288. (
  1289. RawItemHdr  *listP,
  1290. StringList  *strListP,
  1291. int         iRow,        /* => row to insert before */
  1292. int         nDisplayedRows,
  1293. int         oldTopRow,
  1294. boolean         appending
  1295. )
  1296.     {
  1297.     int        iString;
  1298.     int        newTopRow;
  1299.     char    buffer[80];
  1300.  
  1301.     iString = iRow * niG.nColumns;
  1302.     mdlStringList_insertMember (&iString, strListP, iString, niG.nColumns);
  1303.  
  1304.     if (appending)
  1305.     newItems_rscSprintf (buffer, MSGID_LeftAfter, iRow-1+'A', iRow-1);
  1306.     else
  1307.     newItems_rscSprintf (buffer, MSGID_LeftBefore, iRow+'A', iRow);
  1308.     mdlStringList_setMember (strListP, iString, buffer, NULL);
  1309.  
  1310.     if (niG.nColumns > 1)
  1311.     {
  1312.     if (appending)
  1313.         newItems_rscSprintf (buffer, MSGID_Right, iRow-1);
  1314.     else
  1315.         newItems_rscSprintf (buffer, MSGID_Right, iRow);
  1316.  
  1317.     mdlStringList_setMember (strListP, iString+1, buffer, NULL);
  1318.     }
  1319.  
  1320.     mdlDialog_listBoxNRowsChanged (listP);
  1321.  
  1322.     newTopRow = iRow - nDisplayedRows/2;
  1323.     if (newTopRow < 0)  newTopRow = 0;
  1324.     mdlDialog_listBoxSetTopRowRedraw (listP, newTopRow, TRUE);
  1325.     }
  1326.  
  1327. /*----------------------------------------------------------------------+
  1328. |                                                                       |
  1329. | name          newItems_doMultiListModify                |
  1330. |                                                                       |
  1331. | author        BSI                    10/92           |
  1332. |                                                                       |
  1333. +----------------------------------------------------------------------*/
  1334. Private void newItems_doMultiListModify
  1335. (
  1336. RawItemHdr  *listP,
  1337. int         searchId
  1338. )
  1339.     {
  1340.     int        minRow, maxRow, nDisplayedRows;
  1341.     StringList *strListP;
  1342.     int        nRows = 0;
  1343.  
  1344.     strListP = mdlDialog_listBoxGetStrListP (listP);
  1345.     if (strListP)
  1346.     {
  1347.     int nMembers;
  1348.  
  1349.     nMembers = mdlStringList_size (strListP);
  1350.     nRows = nMembers / niG.nColumns;
  1351.     }
  1352.  
  1353.     mdlDialog_listBoxGetDisplayRange (&minRow, &maxRow, NULL, NULL, listP);
  1354.     nDisplayedRows = maxRow - minRow + 1;
  1355.  
  1356.     switch (searchId)
  1357.     {
  1358.     case MSID_ResetList:
  1359.         mdlDialog_listBoxSelectCells (listP, 0, -1, 0, -1, FALSE, FALSE);
  1360.         mdlStringList_deleteMember (strListP, 0, -1);
  1361.         mdlStringList_insertMember (NULL, strListP, -1,
  1362.                     NMULTILIST_LINES * 2);
  1363.         newItems_multiListInitStrList (strListP);
  1364.  
  1365.         mdlDialog_listBoxNRowsChanged (listP);
  1366.         newItems_multiListInitDisabled (listP);
  1367.  
  1368.         mdlDialog_listBoxSetTopRowRedraw (listP, 0, TRUE);
  1369.         break;
  1370.  
  1371.     case MSID_RecreateList:
  1372.         mdlStringList_destroy (strListP);
  1373.         listP->userDataP = strListP =
  1374.                 mdlStringList_create (NMULTILIST_LINES*2, 2);
  1375.         newItems_multiListInitStrList (strListP);
  1376.         mdlDialog_listBoxSetStrListP (listP, strListP, 2);
  1377.         newItems_multiListInitDisabled (listP);
  1378.         mdlDialog_listBoxSetTopRowRedraw (listP, 0, TRUE);
  1379.  
  1380.         /* a stateChanged message won't be generated, fixup list
  1381.         manually */
  1382.         newItems_setSelectionList ();
  1383.         break;
  1384.  
  1385.     case MSID_AddTop:
  1386.         newItems_multiListInsertItem (listP, strListP, 0, nDisplayedRows,
  1387.                       minRow, FALSE);
  1388.         break;
  1389.  
  1390.     case MSID_AddBottom:
  1391.         newItems_multiListInsertItem (listP, strListP, nRows,
  1392.                       nDisplayedRows, minRow, TRUE);
  1393.         break;
  1394.  
  1395.     case MSID_AddSelection:
  1396.         {
  1397.         int        nSelections;
  1398.         Spoint2d    *selections;
  1399.  
  1400.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  1401.         if (nSelections > 0 && selections)
  1402.         newItems_multiListInsertItem (listP, strListP, selections->y,
  1403.                           nDisplayedRows, minRow, FALSE);
  1404.         break;
  1405.         }
  1406.  
  1407.     case MSID_DeleteSelection:
  1408.         {
  1409.         int        nSelections;
  1410.         Spoint2d    *selections;
  1411.  
  1412.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  1413.         if (nSelections > 0 && selections)
  1414.         {
  1415.         int         newTopRow;
  1416.         Spoint2d    *curSelectionP;
  1417.  
  1418.         for (curSelectionP = selections+nSelections-1;
  1419.              curSelectionP >= selections; curSelectionP--)
  1420.             {
  1421.             mdlStringList_deleteMember (strListP,
  1422.                         curSelectionP->y * niG.nColumns,
  1423.                         niG.nColumns);
  1424.             }
  1425.  
  1426.         /* browse should always have something selected */
  1427.         if (niG.selectionMode == SELECTIONMODE_BROWSE)
  1428.             mdlDialog_listBoxSelectCells (listP, selections->y,
  1429.                           selections->y, 0, -1, TRUE,
  1430.                           FALSE);
  1431.  
  1432.         mdlDialog_listBoxNRowsChanged (listP);
  1433.         newTopRow = selections->y - nDisplayedRows/2;
  1434.         if (newTopRow < 0)
  1435.             newTopRow = 0;
  1436.  
  1437.         mdlDialog_listBoxSetTopRowRedraw (listP, newTopRow, TRUE);
  1438.         }
  1439.         break;
  1440.         }
  1441.     }
  1442.     }
  1443.  
  1444. /*----------------------------------------------------------------------+
  1445. |                                                                       |
  1446. | name          newItems_doMultiListSelect                |
  1447. |                                                                       |
  1448. | author        BSI                    10/92           |
  1449. |                                                                       |
  1450. +----------------------------------------------------------------------*/
  1451. Private void newItems_doMultiListSelect
  1452. (
  1453. RawItemHdr  *listP,
  1454. int         searchId
  1455. )
  1456.     {
  1457.     StringList    *strListP;
  1458.     int        nRows = 0;
  1459.  
  1460.     strListP = mdlDialog_listBoxGetStrListP (listP);
  1461.     if (strListP)
  1462.     {
  1463.     int nMembers;
  1464.  
  1465.     nMembers = mdlStringList_size (strListP);
  1466.     nRows = nMembers / niG.nColumns;
  1467.     }
  1468.  
  1469.     switch (searchId)
  1470.     {
  1471.     case MSID_SelectTop:
  1472.         {
  1473.         Spoint2d    selectionPt;
  1474.  
  1475.         selectionPt.x = selectionPt.y = 0;
  1476.         mdlDialog_listBoxSetSelections (listP, 1, &selectionPt, TRUE,
  1477.                         TRUE);
  1478.         break;
  1479.         }
  1480.  
  1481.     case MSID_SelectBottom:
  1482.         {
  1483.         Spoint2d    selectionPt;
  1484.  
  1485.         selectionPt.y = nRows - 1;
  1486.         selectionPt.x = 0;
  1487.         mdlDialog_listBoxSetSelections (listP, 1, &selectionPt, TRUE,
  1488.                         TRUE);
  1489.         break;
  1490.         }
  1491.  
  1492.     case MSID_SelectEveryOther:
  1493.         if ((niG.selectionMode == SELECTIONMODE_MULTI) ||
  1494.         (niG.selectionMode == SELECTIONMODE_EXTENDED))
  1495.         {
  1496.         int         iRow;
  1497.         int         nSelectedRows = 0;
  1498.         Spoint2d    *curSelectionP, *selectionsP = NULL;
  1499.  
  1500.         selectionsP = malloc ((nRows/2+1)*sizeof(Spoint2d));
  1501.         if (!selectionsP)
  1502.             break;
  1503.  
  1504.         for (iRow=0, curSelectionP=selectionsP; iRow<nRows;
  1505.             iRow+=2, curSelectionP++, nSelectedRows++)
  1506.              {
  1507.              curSelectionP->y = iRow;
  1508.              curSelectionP->x = 0;
  1509.              }
  1510.  
  1511.         mdlDialog_listBoxSetSelections (listP, nSelectedRows,
  1512.                         selectionsP, TRUE, TRUE);
  1513.         free (selectionsP);
  1514.         }
  1515.         break;
  1516.  
  1517.     case MSID_SelectAll:
  1518.         if ((niG.selectionMode == SELECTIONMODE_MULTI) ||
  1519.         (niG.selectionMode == SELECTIONMODE_EXTENDED))
  1520.         {
  1521.         mdlDialog_listBoxSelectCells (listP, 0, -1, 0, -1, TRUE,
  1522.                           TRUE);
  1523.         }
  1524.         break;
  1525.  
  1526.     case MSID_DeselectTop:
  1527.         mdlDialog_listBoxSelectCells (listP, 0, 0, 0, -1, FALSE, TRUE);
  1528.         break;
  1529.  
  1530.     case MSID_DeselectBottom:
  1531.         mdlDialog_listBoxSelectCells (listP, nRows-1, nRows-1, 0, -1,
  1532.                       FALSE, TRUE);
  1533.         break;
  1534.  
  1535.     case MSID_DeselectAll:
  1536.         mdlDialog_listBoxSelectCells (listP, 0, -1, 0, -1, FALSE, TRUE);
  1537.         break;
  1538.     }
  1539.     }
  1540.  
  1541. /*----------------------------------------------------------------------+
  1542. |                                                                       |
  1543. | name          newItems_doMultiListPosition                |
  1544. |                                                                       |
  1545. | author        BSI                    10/92           |
  1546. |                                                                       |
  1547. +----------------------------------------------------------------------*/
  1548. Private void newItems_doMultiListPosition
  1549. (
  1550. RawItemHdr  *listP,
  1551. int         searchId
  1552. )
  1553.     {
  1554.     int        minRow, maxRow, nDisplayedRows;
  1555.     StringList    *strListP;
  1556.     int        nRows = 0;
  1557.  
  1558.     strListP = mdlDialog_listBoxGetStrListP (listP);
  1559.     if (strListP)
  1560.     {
  1561.     int nMembers;
  1562.  
  1563.     nMembers = mdlStringList_size (strListP);
  1564.     nRows = nMembers / niG.nColumns;
  1565.     }
  1566.  
  1567.     mdlDialog_listBoxGetDisplayRange (&minRow, &maxRow, NULL, NULL, listP);
  1568.     nDisplayedRows = maxRow - minRow + 1;
  1569.  
  1570.     switch (searchId)
  1571.     {
  1572.     case MSID_Top1st:
  1573.         mdlDialog_listBoxSetTopRow (listP, 0);
  1574.         break;
  1575.  
  1576.     case MSID_BottomLast:
  1577.         {
  1578.         int    newTopRow;
  1579.  
  1580.         newTopRow = nRows - nDisplayedRows;
  1581.         if (newTopRow < 0)
  1582.         newTopRow = 0;
  1583.  
  1584.         mdlDialog_listBoxSetTopRow (listP, newTopRow);
  1585.         break;
  1586.         }
  1587.  
  1588.     case MSID_TopSelection:
  1589.         {
  1590.         int        nSelections;
  1591.         Spoint2d    *selections;
  1592.  
  1593.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  1594.         if (nSelections > 0 && selections)
  1595.         mdlDialog_listBoxSetTopRow (listP, selections->y);
  1596.         break;
  1597.         }
  1598.     }
  1599.     }
  1600.  
  1601. /*----------------------------------------------------------------------+
  1602. |                                                                       |
  1603. | name          newItems_doMultiListLocation                |
  1604. |                                                                       |
  1605. | author        BSI                    10/92           |
  1606. |                                                                       |
  1607. +----------------------------------------------------------------------*/
  1608. Private void newItems_doMultiListLocation
  1609. (
  1610. RawItemHdr  *listP,
  1611. int         searchId
  1612. )
  1613.     {
  1614.     StringList    *strListP;
  1615.     int        nRows = 0;
  1616.  
  1617.     strListP = mdlDialog_listBoxGetStrListP (listP);
  1618.     if (strListP)
  1619.     {
  1620.     int nMembers;
  1621.  
  1622.     nMembers = mdlStringList_size (strListP);
  1623.     nRows = nMembers / niG.nColumns;
  1624.     }
  1625.  
  1626.     switch (searchId)
  1627.     {
  1628.     case MSID_LocationTop:
  1629.         {
  1630.         int newTopRow;
  1631.  
  1632.         mdlDialog_listBoxSetLocationCursor (listP, 0, 0);
  1633.  
  1634.         /* need to get location cursor since first rows may be disabled */
  1635.         mdlDialog_listBoxGetLocationCursor (&newTopRow, NULL, listP);
  1636.         mdlDialog_listBoxSetTopRow (listP, newTopRow);
  1637.         break;
  1638.         }
  1639.  
  1640.     case MSID_LocationBottom:
  1641.         {
  1642.         int newTopRow;
  1643.         int    minRow, maxRow, nDisplayedRows;
  1644.  
  1645.         mdlDialog_listBoxSetLocationCursor (listP, nRows-1, 0);
  1646.  
  1647.         /* need to get location cursor since last rows may be disabled */
  1648.         mdlDialog_listBoxGetLocationCursor (&newTopRow, NULL, listP);
  1649.  
  1650.         mdlDialog_listBoxGetDisplayRange (&minRow, &maxRow, NULL, NULL,
  1651.                           listP);
  1652.         nDisplayedRows = maxRow - minRow + 1;
  1653.         newTopRow = newTopRow - nDisplayedRows + 1;
  1654.         if (newTopRow < 0)
  1655.         newTopRow = 0;
  1656.  
  1657.         mdlDialog_listBoxSetTopRow (listP, newTopRow);
  1658.         break;
  1659.         }
  1660.  
  1661.     case MSID_LocationSelection:
  1662.         {
  1663.         int        nSelections;
  1664.         Spoint2d    *selections;
  1665.  
  1666.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  1667.         if (nSelections > 0 && selections)
  1668.         {
  1669.         mdlDialog_listBoxSetLocationCursor (listP, selections->y, 0);
  1670.         newItems_doMultiListPosition (listP, MSID_TopSelection);
  1671.         }
  1672.         break;
  1673.         }
  1674.     }
  1675.     }
  1676.  
  1677. /*----------------------------------------------------------------------+
  1678. |                                                                       |
  1679. | name          newItems_multiListTestsMenusHook            |
  1680. |                                                                       |
  1681. | author        BSI                    10/92           |
  1682. |                                                                       |
  1683. +----------------------------------------------------------------------*/
  1684. Private void newItems_multiListTestsMenusHook
  1685. (
  1686. DialogItemMessage   *dimP
  1687. )
  1688.     {
  1689.     dimP->msgUnderstood = TRUE;
  1690.  
  1691.     switch (dimP->messageType)
  1692.     {
  1693.     case DITEM_MESSAGE_DRAW:
  1694.         {
  1695.         DItem_PulldownMenuItem  menuItem;
  1696.         RawItemHdr           *menuBarP = dimP->dialogItemP->rawItemP;
  1697.         PulldownMenuMessage       *pdmmP =
  1698.                     (PulldownMenuMessage *)dimP->auxInfoP;
  1699.         DItem_PulldownMenu       *menuP = pdmmP->menuP;
  1700.  
  1701.         if (menuP->type != RTYPE_PulldownMenu)
  1702.         break;
  1703.         /* need to switch on menuP->id because multiple menus were attached
  1704.            to this hook function */
  1705.         switch (menuP->id)
  1706.         {
  1707.         case PDMID_MultiListModify:
  1708.             newItems_maintainMultiListModifyMenu (menuP);
  1709.             break;
  1710.  
  1711.         case PDMID_MultiListSelect:
  1712.             newItems_maintainMultiListSelectMenu (menuP);
  1713.             break;
  1714.  
  1715.         case PDMID_MultiListPosition:
  1716.             newItems_maintainMultiListPositionMenu (menuP);
  1717.             break;
  1718.  
  1719.         case PDMID_MultiListLocation:
  1720.             newItems_maintainMultiListLocationMenu (menuP);
  1721.             break;
  1722.         }
  1723.  
  1724.         break;
  1725.         }
  1726.  
  1727.     case DITEM_MESSAGE_BUTTON:
  1728.         {
  1729.         DItem_PulldownMenuItem  menuItem;
  1730.         RawItemHdr           *menuBarP = dimP->dialogItemP->rawItemP;
  1731.         PulldownMenuMessage       *pdmmP =
  1732.                     (PulldownMenuMessage *)dimP->auxInfoP;
  1733.         DItem_PulldownMenu       *menuP;
  1734.         RawItemHdr           *listP;
  1735.         int                searchId;
  1736.  
  1737.         if (dimP->u.button.buttonTrans != BUTTONTRANS_UP)
  1738.         break;
  1739.         menuP = pdmmP->menuP;
  1740.  
  1741.         if (!niG.multiListDiP || !niG.multiListDiP->rawItemP)
  1742.         break;
  1743.         listP = niG.multiListDiP->rawItemP;
  1744.         searchId = pdmmP->u.activateItem.searchId;
  1745.  
  1746.         /* need to switch on menuP->id because multiple menus were
  1747.         attached to this hook function */
  1748.         switch (menuP->id)
  1749.         {
  1750.         case PDMID_MultiListModify:
  1751.             newItems_doMultiListModify (listP, searchId);
  1752.             break;
  1753.  
  1754.         case PDMID_MultiListSelect:
  1755.             newItems_doMultiListSelect (listP, searchId);
  1756.             break;
  1757.  
  1758.         case PDMID_MultiListPosition:
  1759.             newItems_doMultiListPosition (listP, searchId);
  1760.             break;
  1761.  
  1762.         case PDMID_MultiListLocation:
  1763.             newItems_doMultiListLocation (listP, searchId);
  1764.             break;
  1765.         }
  1766.  
  1767.         break;
  1768.         }
  1769.  
  1770.     default:
  1771.         dimP->msgUnderstood = FALSE;
  1772.         break;
  1773.     }
  1774.     }
  1775.  
  1776. /*----------------------------------------------------------------------+
  1777. |                                                                       |
  1778. | name          newItems_setupPopupMenu                    |
  1779. |                                                                       |
  1780. | author        BSI                    03/93           |
  1781. |                                                                       |
  1782. +----------------------------------------------------------------------*/
  1783. Private void newItems_setupPopupMenu
  1784. (
  1785. DialogMessage   *dmP
  1786. )
  1787.     {
  1788.     int             iItem;
  1789.     int             menuId;
  1790.     RawItemHdr        *popupP;
  1791.     DialogItem        *popupDiP;
  1792.     DialogItem        *downDiP;
  1793.     DItem_PulldownMenu    *popupMenuP;
  1794.     DialogBox        *dbP = dmP->db;
  1795.  
  1796.     /* find the index of the item the reset button went down in */
  1797.     iItem = mdlDialog_findItemIndex (dbP, &dmP->u.button.pt, FALSE);
  1798.     if (iItem < 0)
  1799.     return;
  1800.  
  1801.     popupDiP = mdlDialog_itemGetByTypeAndId (dbP, RTYPE_PopupMenu,
  1802.                          POPUPMENUID_MultiList, 0);
  1803.     if (!popupDiP)
  1804.     return;
  1805.     popupP  = popupDiP->rawItemP;
  1806.  
  1807.     downDiP = mdlDialog_itemGetByIndex (dbP, iItem);
  1808.     switch (downDiP->type)
  1809.     {
  1810.     case RTYPE_ListBox:
  1811.         if (downDiP->id == LISTBOXID_Multi)
  1812.         menuId = PDMID_MultiListPosition;
  1813.         else
  1814.         menuId = PDMID_MultiListSelect;
  1815.         break;
  1816.  
  1817.     case RTYPE_OptionButton:
  1818.         menuId = PDMID_MultiListTests;
  1819.         break;
  1820.  
  1821.     default:
  1822.         return;
  1823.     }
  1824.  
  1825.     /* Popup Menus are a restricted form of MenuBar (they only have 1 top
  1826.        level menu). mdlDialog_menuBarxxx functions can be called with ptrs
  1827.        to popup menus. */
  1828.     popupMenuP = mdlDialog_menuBarGetMenu (popupP, 0);
  1829.     if (!popupMenuP)
  1830.     return;
  1831.     if (popupMenuP->id != menuId)
  1832.     {
  1833.     mdlDialog_menuBarDeleteMenu (popupMenuP, popupP, NULL, 0);
  1834.     mdlDialog_menuBarInsMenu (popupP, RTYPE_PulldownMenu, menuId, NULL);
  1835.     }
  1836.  
  1837.     /* force the button event to go to the popupMenu item */
  1838.     dmP->u.button.buttonRiP = popupP;
  1839.     }
  1840.  
  1841. /*----------------------------------------------------------------------+
  1842. |                                                                       |
  1843. | name          newItems_multiListDialogHook                |
  1844. |                                                                       |
  1845. | author        BSI                    09/92           |
  1846. |                                                                       |
  1847. +----------------------------------------------------------------------*/
  1848. Private void    newItems_multiListDialogHook
  1849. (
  1850. DialogMessage    *dmP        /* => a ptr to a dialog message */
  1851. )
  1852.     {
  1853.     dmP->msgUnderstood = TRUE;
  1854.     switch (dmP->messageType)
  1855.     {
  1856.     case DIALOG_MESSAGE_CREATE:
  1857.         dmP->u.create.interests.preButtons = TRUE;
  1858.         dmP->u.create.interests.nonDataPoints = TRUE;
  1859.         break;
  1860.  
  1861.     case DIALOG_MESSAGE_PREBUTTON:
  1862.         if ((dmP->u.button.buttonTrans == BUTTONTRANS_DOWN) &&
  1863.         (dmP->u.button.buttonNumber == RESET))
  1864.         {
  1865.         newItems_setupPopupMenu (dmP);
  1866.         }
  1867.         break;
  1868.  
  1869.     default:
  1870.         dmP->msgUnderstood = FALSE;
  1871.         break;
  1872.     }
  1873.     }
  1874.  
  1875. /*----------------------------------------------------------------------+
  1876. |                                    |
  1877. |   2D Arrows                                |
  1878. |                                    |
  1879. +----------------------------------------------------------------------*/
  1880. /*----------------------------------------------------------------------+
  1881. |                                                                       |
  1882. | name          newItems_draw2DArrows                    |
  1883. |                                                                       |
  1884. | author        BSI                    12/92           |
  1885. |                                                                       |
  1886. +----------------------------------------------------------------------*/
  1887. Private void newItems_draw2DArrows
  1888. (
  1889. DialogBox   *dbP,
  1890. Point2d        *ptP,
  1891. boolean         enabled,
  1892. boolean         drawShaft,
  1893. boolean         fill
  1894. )
  1895.     {
  1896.     Point2d        pt;
  1897.     BSIRect        rect;
  1898.     BSIColorDescr  *whiteP;
  1899.     int            fontHeight = mdlDialog_fontGetCurHeight (dbP);
  1900.  
  1901.     if (!(fontHeight & 1))
  1902.     fontHeight++;                /* make odd */
  1903.     whiteP = (BSIColorDescr *)mdlWindow_fixedColorIndexGet (dbP, WHITE_INDEX);
  1904.  
  1905.     pt.x = ptP->x + fontHeight;
  1906.     pt.y = ptP->y;
  1907.     mdlDialog_rectSet (&rect, pt.x, pt.y, pt.x+fontHeight-1,
  1908.                pt.y+fontHeight-1);
  1909.     mdlDialog_rectFill (dbP, &rect, LGREY_INDEX);
  1910.     mdlDialog_rectDraw (dbP, &rect, BLACK_INDEX);
  1911.     pt.x += 3;
  1912.     pt.y += 3;
  1913.     mdlDialog_2DArrowDrawCD (dbP, &pt, fontHeight-6, enabled, drawShaft,
  1914.     SCROLL_ARROW_UP, NULL, NULL, NULL, whiteP, NULL);
  1915.  
  1916.     pt.x = ptP->x + fontHeight;
  1917.     pt.y = ptP->y + fontHeight*2;
  1918.     mdlDialog_rectSet (&rect, pt.x, pt.y, pt.x+fontHeight-1,
  1919.                pt.y+fontHeight-1);
  1920.     mdlDialog_rectFill (dbP, &rect, LGREY_INDEX);
  1921.     mdlDialog_rectDraw (dbP, &rect, BLACK_INDEX);
  1922.     pt.x += 3;
  1923.     pt.y += 3;
  1924.     mdlDialog_2DArrowDrawCD (dbP, &pt, fontHeight-6, enabled, drawShaft,
  1925.     SCROLL_ARROW_DOWN, NULL, NULL, NULL, whiteP, NULL);
  1926.  
  1927.     pt.x = ptP->x;
  1928.     pt.y = ptP->y + fontHeight;
  1929.     mdlDialog_rectSet (&rect, pt.x, pt.y, pt.x+fontHeight-1,
  1930.                pt.y+fontHeight-1);
  1931.     mdlDialog_rectFill (dbP, &rect, LGREY_INDEX);
  1932.     mdlDialog_rectDraw (dbP, &rect, BLACK_INDEX);
  1933.     pt.x += 3;
  1934.     pt.y += 3;
  1935.     mdlDialog_2DArrowDrawCD (dbP, &pt, fontHeight-6, enabled, drawShaft,
  1936.     SCROLL_ARROW_LEFT, NULL, NULL, NULL, whiteP, NULL);
  1937.  
  1938.     pt.x = ptP->x + fontHeight*2;
  1939.     pt.y = ptP->y + fontHeight;
  1940.     mdlDialog_rectSet (&rect, pt.x, pt.y, pt.x+fontHeight-1,
  1941.                pt.y+fontHeight-1);
  1942.     mdlDialog_rectFill (dbP, &rect, LGREY_INDEX);
  1943.     mdlDialog_rectDraw (dbP, &rect, BLACK_INDEX);
  1944.     pt.x += 3;
  1945.     pt.y += 3;
  1946.     mdlDialog_2DArrowDrawCD (dbP, &pt, fontHeight-6, enabled, drawShaft,
  1947.                  SCROLL_ARROW_RIGHT, NULL, NULL, NULL, whiteP,
  1948.                  NULL);
  1949.     }
  1950.  
  1951. /*----------------------------------------------------------------------+
  1952. |                                                                       |
  1953. | name        newItems_2DArrowsDialogHook                |
  1954. |                                                                       |
  1955. | author        BSI                    12/92           |
  1956. |                                                                       |
  1957. +----------------------------------------------------------------------*/
  1958. Private void    newItems_2DArrowsDialogHook
  1959. (
  1960. DialogMessage    *dmP        /* => a ptr to a dialog message */
  1961. )
  1962.     {
  1963.     dmP->msgUnderstood = TRUE;
  1964.     switch (dmP->messageType)
  1965.     {
  1966.     case DIALOG_MESSAGE_CREATE:
  1967.         dmP->u.create.interests.updates   = TRUE;
  1968.         break;
  1969.  
  1970.     case DIALOG_MESSAGE_UPDATE:
  1971.         {
  1972.         Point2d pt;
  1973.         int    fontHeight   = mdlDialog_fontGetCurHeight (dmP->db);
  1974.  
  1975.         pt.x = fontHeight;
  1976.         pt.y = fontHeight;
  1977.         newItems_draw2DArrows (dmP->db, &pt, FALSE, FALSE, TRUE);
  1978.  
  1979.         pt.x += fontHeight*4;
  1980.         newItems_draw2DArrows (dmP->db, &pt, TRUE,     FALSE, TRUE);
  1981.  
  1982.         pt.y += fontHeight*4;
  1983.         newItems_draw2DArrows (dmP->db, &pt, TRUE,  TRUE, TRUE);
  1984.  
  1985.         pt.x -= fontHeight*4;
  1986.         newItems_draw2DArrows (dmP->db, &pt, FALSE, TRUE, TRUE);
  1987.  
  1988.         pt.x = fontHeight;
  1989.         pt.y = fontHeight + fontHeight*5;
  1990.         newItems_draw2DArrows (dmP->db, &pt, FALSE, FALSE, FALSE);
  1991.  
  1992.         pt.x += fontHeight*4;
  1993.         newItems_draw2DArrows (dmP->db, &pt, TRUE,     FALSE, FALSE);
  1994.  
  1995.         pt.y += fontHeight*4;
  1996.         newItems_draw2DArrows (dmP->db, &pt, TRUE,  TRUE, FALSE);
  1997.  
  1998.         pt.x -= fontHeight*4;
  1999.         newItems_draw2DArrows (dmP->db, &pt, FALSE, TRUE, FALSE);
  2000.         break;
  2001.         }
  2002.  
  2003.     default:
  2004.         dmP->msgUnderstood = FALSE;
  2005.         break;
  2006.     }
  2007.     }
  2008.  
  2009. /*----------------------------------------------------------------------+
  2010. |                                                                       |
  2011. |       Command Handling routines                                       |
  2012. |                                                                       |
  2013. +----------------------------------------------------------------------*/
  2014. /*----------------------------------------------------------------------+
  2015. |                                                                       |
  2016. | name          newitems_open                        |
  2017. |                                                                       |
  2018. | author        BSI                                     12/90           |
  2019. |                                                                       |
  2020. +----------------------------------------------------------------------*/
  2021. Private void newItems_open
  2022. (
  2023. char    *unparsedP    /* => unparsed part of command */
  2024. )
  2025. cmdNumber   CMD_NEWITEMS_OPEN_RADIOBUTTONS,
  2026.         CMD_NEWITEMS_OPEN_HSCALES, CMD_NEWITEMS_OPEN_VSCALES,
  2027.         CMD_NEWITEMS_OPEN_MLPBUTS, CMD_NEWITEMS_OPEN_SASH,
  2028.         CMD_NEWITEMS_OPEN_BGROUP, CMD_NEWITEMS_OPEN_COLORS,
  2029.         CMD_NEWITEMS_OPEN_MULTILIST, CMD_NEWITEMS_OPEN_2DARROWS,
  2030.         CMD_NEWITEMS_OPEN_ALERTS
  2031.     {
  2032.     int        lastAction;
  2033.     DialogBox  *dbP;    /* a ptr to a dialog box */
  2034.     long    dialogId;
  2035.  
  2036.     dialogId = (mdlCommandNumber & 0xFF00) >> 8;
  2037.     if (dialogId == 0)
  2038.     return;
  2039.  
  2040.     if (dialogId == DIALOGID_MultiList)
  2041.     {
  2042.     /* Did this way because didn't feel like adding a dialog hook */
  2043.     niG.selectionMode = SELECTIONMODE_BROWSE;
  2044.     niG.nColumns = 2;
  2045.     }
  2046.  
  2047.     /* open the newItems dialog box */
  2048.     if ((dbP = mdlDialog_open (NULL, dialogId)) == NULL)
  2049.     newItems_errorPrint (MSGID_DialogBox);
  2050.     }
  2051.  
  2052. /*----------------------------------------------------------------------+
  2053. |                                                                       |
  2054. | name          newitems_openModal                                      |
  2055. |                                                                       |
  2056. | author        BSI                                     12/90           |
  2057. |                                                                       |
  2058. +----------------------------------------------------------------------*/
  2059. Private void newItems_openModal
  2060. (
  2061. char    *unparsedP    /* => unparsed part of command */
  2062. )
  2063. cmdNumber   CMD_NEWITEMS_MODALOPEN_RADIOBUTTONS, CMD_NEWITEMS_MODALOPEN_SCALES
  2064.     {
  2065.     int        lastAction;
  2066.     long    dialogId = 0;
  2067.  
  2068.     /* open child modal dialog box */
  2069.     switch (mdlCommandNumber)
  2070.     {
  2071.     case CMD_NEWITEMS_MODALOPEN_RADIOBUTTONS:
  2072.         dialogId = DIALOGID_ModalRadioButtons;
  2073.         break;
  2074.  
  2075.     case CMD_NEWITEMS_MODALOPEN_SCALES:
  2076.         dialogId = DIALOGID_ModalScales;
  2077.         break;
  2078.     }
  2079.  
  2080.     if (dialogId == 0)
  2081.     return;
  2082.  
  2083.     if (mdlDialog_openModal (&lastAction, NULL, dialogId))
  2084.     newItems_errorPrint (MSGID_DialogBox);
  2085.     }
  2086.  
  2087. /*----------------------------------------------------------------------+
  2088. |                                                                       |
  2089. | name          newItems_alertCommands                    |
  2090. |                                                                       |
  2091. | author        BSI                    12/93           |
  2092. |                                    |
  2093. |   Example uses of mdlDialog_openxxxxxAlert.                    |
  2094. |                                        |
  2095. +----------------------------------------------------------------------*/
  2096. Private void newItems_alertCommands
  2097. (
  2098. char    *unparsedP    /* => unparsed part of command */
  2099. )
  2100. cmdNumber   CMD_NEWITEMS_ALERT_CRITICAL,CMD_NEWITEMS_ALERT_INFORMATION,
  2101.         CMD_NEWITEMS_ALERT_QUESTION,CMD_NEWITEMS_ALERT_WARNING
  2102.  
  2103.     {
  2104.     char    msgBuf[300];
  2105.  
  2106.     switch (mdlCommandNumber)
  2107.     {
  2108.     case CMD_NEWITEMS_ALERT_CRITICAL:
  2109.         mdlResource_loadFromStringList (msgBuf, 0L, MESSAGELISTID_NewItems,
  2110.                         MSGID_Critical);
  2111.         mdlDialog_openMessageBox (DIALOGID_MsgBoxYesNoCancel, msgBuf,
  2112.                       MSGBOX_ICON_CRITICAL);
  2113.         break;
  2114.  
  2115.      case CMD_NEWITEMS_ALERT_INFORMATION:
  2116.         mdlResource_loadFromStringList (msgBuf, 0L, MESSAGELISTID_NewItems,
  2117.                         MSGID_Information);
  2118.         mdlDialog_openMessageBox (DIALOGID_MsgBoxOK, msgBuf,
  2119.                       MSGBOX_ICON_INFORMATION);
  2120.         break;
  2121.  
  2122.     case CMD_NEWITEMS_ALERT_QUESTION:
  2123.         mdlResource_loadFromStringList (msgBuf, 0L, MESSAGELISTID_NewItems,
  2124.                         MSGID_Question);
  2125.         mdlDialog_openMessageBox (DIALOGID_MsgBoxOKCancel, msgBuf,
  2126.                       MSGBOX_ICON_QUESTION);
  2127.         break;
  2128.  
  2129.     case CMD_NEWITEMS_ALERT_WARNING:
  2130.         mdlResource_loadFromStringList (msgBuf, 0L, MESSAGELISTID_NewItems,
  2131.                         MSGID_Warning);
  2132.         mdlDialog_openMessageBox (DIALOGID_MsgBoxYesNo, msgBuf,
  2133.                       MSGBOX_ICON_WARNING);
  2134.         break;
  2135.         }
  2136.     }
  2137.  
  2138. /*----------------------------------------------------------------------+
  2139. |                                                                       |
  2140. | name          newItems_exit                        |
  2141. |                                                                       |
  2142. | author        BSI                    08/92           |
  2143. |                                                                       |
  2144. +----------------------------------------------------------------------*/
  2145. Private void newItems_exit
  2146. (
  2147. char    *unparsedP    /* => unparsed part of command */
  2148. )
  2149. cmdNumber   CMD_NEWITEMS_EXIT
  2150.     {
  2151.     mdlDialog_cmdNumberQueue (FALSE, CMD_MDL_SILENTUNLOAD,
  2152.                                           mdlSystem_getCurrTaskID(), TRUE);
  2153.     }
  2154.  
  2155. /*----------------------------------------------------------------------+
  2156. |                                                                       |
  2157. | name          newItems_unloadFunction                    |
  2158. |                                                                       |
  2159. | author        BSI                                     09/91           |
  2160. |                                                                       |
  2161. +----------------------------------------------------------------------*/
  2162. Private int newItems_unloadFunction
  2163. (
  2164. int reasonCode
  2165. )
  2166.     {
  2167.     mdlDialog_menuBarUnloadApp    (NULL, NULL, 0);
  2168.     if (niG.localPalP != NULL)
  2169.         mdlColorPal_destroy (&niG.localPalP);
  2170.  
  2171.     return (FALSE);
  2172.     }
  2173.  
  2174. /*----------------------------------------------------------------------+
  2175. |                                                                       |
  2176. | name          newItems_scaleColor                    |
  2177. |                                                                       |
  2178. | author        BSI                    10/92           |
  2179. |                                                                       |
  2180. +----------------------------------------------------------------------*/
  2181. Private int newItems_scaleColor
  2182. (
  2183. int    color,
  2184. double    scaleFactor
  2185. )
  2186.     {
  2187.     color *= scaleFactor;
  2188.     if (color > 255)
  2189.     color = 255;
  2190.  
  2191.     return (color);
  2192.     }
  2193.  
  2194. /*----------------------------------------------------------------------+
  2195. |                                    |
  2196. | name        newItems_initializeColorDescriptors            |
  2197. |                                    |
  2198. | author    BSI                    11/94        |
  2199. |                                    |
  2200. +----------------------------------------------------------------------*/
  2201. Private int    newItems_initializeColorDescriptors
  2202. (
  2203. BSIColorPalette **palPP,
  2204. BSIColorDescr   **colorsPP,        /* <= color descr array to initialize */
  2205. int            numColorDescrs      /* => number of colors in the array */
  2206. )
  2207.     {
  2208.     int         status;
  2209.     long    iColor, lColorIndex;
  2210.     BSIColorDescr **cdPP;
  2211.     RGBColorDef    backgroundRgb;
  2212.     RGBColorDef    rgb;
  2213.  
  2214.     /*-------------------------------------------------------------------
  2215.     Create a palette of color descriptors to use for our color
  2216.     customized items.
  2217.     -------------------------------------------------------------------*/
  2218.     if ((status = mdlColorPal_create (palPP, numColorDescrs))
  2219.     != SUCCESS)
  2220.     return status;
  2221.  
  2222.     /* setup local color array for easy access to color descriptors */
  2223.     for (iColor=0, cdPP=colorsPP; iColor < numColorDescrs; iColor++, cdPP++)
  2224.     *cdPP = mdlColorPal_getColorDescr (*palPP, iColor);
  2225.  
  2226.     /* Use the X color id for Light Blue to set a color descriptor to be used
  2227.        as a lt blue background color */
  2228.     mdlColorDescr_setByColorId (colorsPP[LCOLOR_BACKGROUND], LIGHT_BLUE, FALSE);
  2229.     mdlColorDescr_getRgb (&backgroundRgb, colorsPP[LCOLOR_BACKGROUND]);
  2230.  
  2231.     /* Make the select color a little darker than background */
  2232.     rgb = backgroundRgb;
  2233.     rgb.red   *= 0.85;
  2234.     rgb.green *= 0.85;
  2235.     rgb.blue  *= 0.85;
  2236.     mdlColorDescr_setByRgb (colorsPP[LCOLOR_SELECT], &rgb, FALSE);
  2237.  
  2238.     /* Make the top shadow color a little lighter than the background */
  2239.     rgb = backgroundRgb;
  2240.     rgb.red   = newItems_scaleColor (rgb.red, 1.5);
  2241.     rgb.green = newItems_scaleColor (rgb.green, 1.5);
  2242.     rgb.blue  = newItems_scaleColor (rgb.blue, 1.5);
  2243.     mdlColorDescr_setByRgb (colorsPP[LCOLOR_TOPSHADOW], &rgb, FALSE);
  2244.  
  2245.     /* Make the bottom shadow color alot darker */
  2246.     rgb = backgroundRgb;
  2247.     rgb.red   *= 0.50;
  2248.     rgb.green *= 0.50;
  2249.     rgb.blue  *= 0.50;
  2250.     mdlColorDescr_setByRgb (colorsPP[LCOLOR_BOTTOMSHADOW], &rgb, FALSE);
  2251.  
  2252.     /* Use some of the standard "menu colors" (Window Manager colors). */
  2253.     mdlColorDescr_setByMenuColor (colorsPP[LCOLOR_BGTEXT],      MGREY_INDEX);
  2254.     mdlColorDescr_setByMenuColor (colorsPP[LCOLOR_FGTEXT],      WHITE_INDEX);
  2255.     mdlColorDescr_setByMenuColor (colorsPP[LCOLOR_LABELTEXT],     RED_INDEX);
  2256.  
  2257.     /* Use an element color for one of our descriptors */
  2258.     mdlColorDescr_setByElemColorNumber (colorsPP[LCOLOR_DGN], 4);
  2259.  
  2260.     return SUCCESS;
  2261.     }
  2262.  
  2263. /*----------------------------------------------------------------------+
  2264. |                                    |
  2265. | name        main                            |
  2266. |                                    |
  2267. | author    BSI                     08/92        |
  2268. |                                    |
  2269. +----------------------------------------------------------------------*/
  2270. static DialogHookInfo uHooks[] =
  2271.     {
  2272.     {HOOKID_RadioButtons,        newItems_radioButtonHook},
  2273.     {HOOKID_ScaleSpeed,            newItems_speedScaleHook},
  2274.     {HOOKID_Sash,            newItems_sashHook},
  2275.     {HOOKID_ListBoxSash,        newItems_sashListBoxHook},
  2276.     {HOOKID_Dialog_Sash,        newItems_sashDialogHook},
  2277.     {HOOKID_Dialog_Colors,        newItems_colorsDialogHook},
  2278.     {HOOKID_ToggleBtnColor,        newItems_colorsToggleBtnHook},
  2279.     {HOOKID_ListBoxMulti,        newItems_multiListBoxHook},
  2280.     {HOOKID_PDMMultiListTests,        newItems_multiListTestsMenusHook},
  2281.     {HOOKID_Dialog_2DArrows,        newItems_2DArrowsDialogHook},
  2282.     {HOOKID_OptionBtnDefaultPB,        newItems_defaultPBOptionBtnHook},
  2283.     {HOOKID_Dialog_MultiList,        newItems_multiListDialogHook},
  2284.     };
  2285.  
  2286. Public void main
  2287. (
  2288. int   argc,        /* => number of args in next array */
  2289. char *argv[]        /* => array of cmd line arguments */
  2290. )
  2291.     {
  2292.     char           *setP;    /* ptr to "C expression symbol set" */
  2293.     RscFileHandle        rscFileH;    /* a resource file handle */
  2294.     char            buffer[80];
  2295.     DItem_PulldownMenuItem  menuItem;
  2296.  
  2297.     /* open the resource file that we came out of */
  2298.     mdlResource_openFile (&rscFileH, NULL, 0);
  2299.  
  2300.     /* load the command table */
  2301.     if (mdlParse_loadCommandTable (NULL) == NULL)
  2302.     newItems_errorPrint (MSGID_CommandTable);
  2303.  
  2304.     /* set up variables that will be evaluated within C expression strings */
  2305.     setP = mdlCExpression_initializeSet (VISIBILITY_DIALOG_BOX, 0, FALSE);
  2306.     mdlDialog_publishComplexVariable (setP, "newitemsglobals", "niG", &niG);
  2307.  
  2308.     mdlSystem_setFunction (SYSTEM_UNLOAD_PROGRAM, newItems_unloadFunction);
  2309.  
  2310.     /* publish our hook functions */
  2311.     mdlDialog_hookPublish (sizeof(uHooks)/sizeof(DialogHookInfo), uHooks);
  2312.  
  2313.     niG.range1 = 0.0;
  2314.     niG.range2 = 50.0;
  2315.     niG.range3 = 100.0;
  2316.     niG.parameter4 = 1;
  2317.  
  2318.     mdlResource_loadFromStringList (buffer, NULL, MESSAGELISTID_NewItems,
  2319.                     MSGID_NewItems);
  2320.     mdlDialog_menuBarRegister (&menuItem, MENUBARID_NewItems, buffer, FALSE,
  2321.                    TRUE);
  2322.  
  2323.     mdlDialog_menuBarActivate (&menuItem, NULL, 0, FALSE, FALSE, FALSE);
  2324.  
  2325.     newItems_initializeColorDescriptors (&niG.localPalP, niG.localColorsP, NLOCAL_COLORS);
  2326.     }
  2327.  
  2328.