home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk21 / dir01 / f015570.re_ / f015570.re
Text File  |  1996-04-02  |  33KB  |  1,021 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:   listmult.mc  $
  18. |   $Revision:   1.2  $
  19. |       $Date:   26 Jul 1995 07:05:02  $
  20. |                                    |
  21. +----------------------------------------------------------------------*/
  22. /*----------------------------------------------------------------------+
  23. |                                    |
  24. |   Function -                                |
  25. |                                    |
  26. |    MDL example to show new items                    |
  27. |                                    |
  28. |    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    |
  29. |                                    |
  30. |   Public Routine Summary -                        |
  31. |                                    |
  32. |    main - Main entry point                        |
  33. |                                    |
  34. +----------------------------------------------------------------------*/
  35. /*----------------------------------------------------------------------+
  36. |                                    |
  37. |   Include Files                               |
  38. |                                    |
  39. +----------------------------------------------------------------------*/
  40. #include    <mdl.h>        /* MDL Library funcs structures & constants */
  41. #include    <dlogitem.h>    /* Dialog Box Manager structures & constants */
  42. #include    <stdarg.h>
  43. #include    <stdio.h>
  44. #include    <stdlib.h>
  45.  
  46. #include    <dlogman.fdf>   /* dialog box manager function prototypes */
  47. #include    <msrsrc.fdf>
  48.  
  49. #include    "listbox.h"     /* basic dialog box example constants & structs */
  50.  
  51. /*----------------------------------------------------------------------+
  52. |                                    |
  53. |   Local defines                            |
  54. |                                    |
  55. +----------------------------------------------------------------------*/
  56. #define    NMULTILIST_LINES    30
  57.  
  58. /*----------------------------------------------------------------------+
  59. |                                    |
  60. |   Public Global variables                        |
  61. |                                    |
  62. +----------------------------------------------------------------------*/
  63. extern ListBoxGlobals listboxGlobs;
  64.  
  65. /*----------------------------------------------------------------------+
  66. |                                    |
  67. |   Utility routines                            |
  68. |                                    |
  69. +----------------------------------------------------------------------*/
  70. /*----------------------------------------------------------------------+
  71. |                                                                       |
  72. |   Name    listmult_rscSprintf                    |
  73. |                                                                       |
  74. |   Author    BSI                                         3/93        |
  75. |                                                                       |
  76. +----------------------------------------------------------------------*/
  77. Private void listmult_rscSprintf
  78. (
  79. char   *stringP,        /* <=  Result of sprintf from resource    */
  80. int    messageNumber,        /*  => Index into msg list for format str    */
  81. ...                /*  => Any other optional arguments        */
  82. )
  83.     {
  84.     va_list ap;
  85.     char    tempStr[1024];
  86.  
  87.     va_start (ap, messageNumber);
  88.  
  89.     *stringP = tempStr[0] = '\0';
  90.     mdlResource_loadFromStringList (tempStr, NULL, MESSAGELISTID_ListBox,
  91.                     messageNumber);
  92.     vsprintf (stringP, tempStr, ap);
  93.  
  94.     va_end (ap);
  95.     }
  96.  
  97. /*----------------------------------------------------------------------+
  98. |                                                                       |
  99. |   Hook Functions                            |
  100. |                                                                       |
  101. +----------------------------------------------------------------------*/ 
  102. /*----------------------------------------------------------------------+
  103. |                                                                       |
  104. | name          listmult_setSelectionList                |
  105. |                                                                       |
  106. | author        BSI                    10/92           |
  107. |                                                                       |
  108. +----------------------------------------------------------------------*/
  109. Private void listmult_setSelectionList
  110. (
  111. void
  112. )
  113.     {
  114.     int         iRow;
  115.     DialogItem    *diP;
  116.     RawItemHdr    *listP, *mListP;
  117.     StringList    *strListP, *mStrListP;
  118.     int         nSelections;
  119.     Spoint2d    *selections;
  120.     Spoint2d    *curSelectionP;
  121.  
  122.     if (!listboxGlobs.selectionListDiP || !listboxGlobs.selectionListDiP->rawItemP)
  123.     return;
  124.     listP = listboxGlobs.selectionListDiP->rawItemP;
  125.     strListP = mdlDialog_listBoxGetStrListP (listP);
  126.     if (!strListP)
  127.     return;
  128.  
  129.     if (!listboxGlobs.multiListDiP || !listboxGlobs.multiListDiP->rawItemP)
  130.     return;
  131.  
  132.     mListP = listboxGlobs.multiListDiP->rawItemP;
  133.     mStrListP = mdlDialog_listBoxGetStrListP (mListP);
  134.     if (!mStrListP)
  135.     return;
  136.  
  137.     mdlDialog_listBoxGetSelections (&nSelections, &selections, mListP);
  138.  
  139.     /* empty the string list */
  140.     mdlStringList_deleteMember (strListP, 0, -1);
  141.     if (nSelections > 0)
  142.     {
  143.     int    iMember;
  144.     char    buffer[40];
  145.     char    *stringP;
  146.  
  147.     mdlStringList_insertMember (NULL, strListP, -1, nSelections*6);
  148.  
  149.     for (iRow=0, curSelectionP=selections;
  150.          iRow<nSelections;
  151.          iRow++, curSelectionP++)
  152.         {
  153.         iMember = iRow*6;
  154.  
  155.         mdlStringList_setMember (strListP, iMember++, "{", NULL);
  156.         sprintf (buffer, "%d,", curSelectionP->y);
  157.         mdlStringList_setMember (strListP, iMember++, buffer, NULL);
  158.         sprintf (buffer, "%d ", curSelectionP->x);
  159.         mdlStringList_setMember (strListP, iMember++, buffer, NULL);
  160.         mdlStringList_setMember (strListP, iMember++, "}", NULL);
  161.  
  162.         mdlStringList_getMember (&stringP, NULL, mStrListP,
  163.                      curSelectionP->y * listboxGlobs.nColumns);
  164.         mdlStringList_setMember (strListP, iMember++, stringP, NULL);
  165.  
  166.         if (listboxGlobs.nColumns > 1)
  167.         {
  168.         mdlStringList_getMember (&stringP, NULL, mStrListP,
  169.                      curSelectionP->y * listboxGlobs.nColumns+1);
  170.         mdlStringList_setMember (strListP, iMember++, stringP, NULL);
  171.         }
  172.         }
  173.     }
  174.  
  175.     mdlDialog_listBoxNRowsChanged (listP);
  176.     mdlDialog_listBoxSetTopRowRedraw (listP, 0, TRUE);
  177.     }
  178.  
  179. /*----------------------------------------------------------------------+
  180. |                                                                       |
  181. | name          listmult_trackList                    |
  182. |                                                                       |
  183. | author        BSI                    10/92           |
  184. |                                                                       |
  185. +----------------------------------------------------------------------*/
  186. Private void listmult_trackList
  187. (
  188. Point2d    *ptP
  189. )
  190.     {
  191.     char    buffer[40];
  192.  
  193.     if (!listboxGlobs.labelDiP)
  194.     return;
  195.  
  196.     buffer[0] = '\0';
  197.     if (ptP->y != -1)
  198.     sprintf (buffer, "{%3d, %3d}", ptP->y, ptP->x);
  199.  
  200.     mdlWindow_cursorTurnOff();
  201.     mdlDialog_itemSetLabel (listboxGlobs.multiSelectDbP, listboxGlobs.labelDiP->itemIndex,
  202.                 buffer);
  203.     }
  204.  
  205. /*----------------------------------------------------------------------+
  206. |                                                                       |
  207. | name          listmult_multiListInitStrList                |
  208. |                                                                       |
  209. | author        BSI                    11/92           |
  210. |                                                                       |
  211. +----------------------------------------------------------------------*/
  212. Private void listmult_multiListInitStrList
  213. (
  214. StringList  *strListP
  215. )
  216.     {
  217.     int        iString;
  218.     char    fStr1[20], fStr2[20];
  219.  
  220.     mdlResource_loadFromStringList (fStr1, NULL, MESSAGELISTID_ListBox,
  221.                     MSGID_Right);
  222.     mdlResource_loadFromStringList (fStr2, NULL, MESSAGELISTID_ListBox,
  223.                     MSGID_Left);
  224.     for (iString=0; iString<NMULTILIST_LINES*2; iString++)
  225.     {
  226.     char    buffer[80];
  227.  
  228.     if (iString & 1)
  229.         sprintf (buffer, fStr1, iString/2);
  230.     else
  231.         sprintf (buffer, fStr2, iString/2+'A', iString/2);
  232.  
  233.     mdlStringList_setMember (strListP, iString, buffer, NULL);
  234.     }
  235.     }
  236.  
  237. /*----------------------------------------------------------------------+
  238. |                                                                       |
  239. | name          listmult_multiListInitDisabled                |
  240. |                                                                       |
  241. | author        BSI                    11/92           |
  242. |                                                                       |
  243. +----------------------------------------------------------------------*/
  244. Private void listmult_multiListInitDisabled
  245. (
  246. RawItemHdr  *listP
  247. )
  248.     {
  249.     mdlDialog_listBoxEnableCells (listP, 5, 6, -1, -1, FALSE, FALSE);
  250.     mdlDialog_listBoxEnableCells (listP, 12, 12, -1, -1, FALSE, FALSE);
  251.     }
  252.  
  253. /*----------------------------------------------------------------------+
  254. |                                                                       |
  255. | name          listmult_multiListBoxHook                |
  256. |                                                                       |
  257. | author        BSI                    08/92           |
  258. |                                                                       |
  259. +----------------------------------------------------------------------*/
  260. Public void listmult_multiListBoxHook
  261. (
  262. DialogItemMessage   *dimP
  263. )
  264.     {
  265.     RawItemHdr    *listP = dimP->dialogItemP->rawItemP;
  266.  
  267.     dimP->msgUnderstood = TRUE;
  268.     switch (dimP->messageType)
  269.     {
  270.     case DITEM_MESSAGE_CREATE:
  271.         {
  272.         StringList    *strListP;
  273.  
  274.         /* NOTE: nInfoFields is 2 so 2nd infoField can be used
  275.            to store a ptr to a BSIColorDesc */
  276.         listP->userDataP =
  277.         strListP = mdlStringList_create (NMULTILIST_LINES*2, 2);
  278.         if (!strListP)
  279.         {
  280.         dimP->u.create.createFailed = TRUE;
  281.         return;
  282.         }
  283.  
  284.         mdlDialog_listBoxSetStrListP (listP, strListP, 2);
  285.         listmult_multiListInitStrList (strListP);
  286.         listmult_multiListInitDisabled (listP);
  287.         listboxGlobs.multiListDiP = dimP->dialogItemP;
  288.         break;
  289.         }
  290.  
  291.     case DITEM_MESSAGE_ALLCREATED:
  292.         listboxGlobs.multiSelectDbP = dimP->db;
  293.         listboxGlobs.labelDiP =
  294.         mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_Label, 0, 0);
  295.  
  296.         listboxGlobs.selectionListDiP =
  297.         mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_ListBox,
  298.                           LISTBOXID_SelectionList, 0);
  299.  
  300.         break;
  301.  
  302.     case DITEM_MESSAGE_DESTROY:
  303.         if (listP->userDataP)
  304.         {
  305.         mdlStringList_destroy (listP->userDataP);
  306.         }
  307.         break;
  308.  
  309.     case DITEM_MESSAGE_SYNCHRONIZE:
  310.         {
  311.         ULong   attributes;
  312.  
  313.         mdlDialog_listBoxGetInfo (&attributes, NULL, NULL, listP);
  314.  
  315.         attributes &= ~(LISTATTR_SELBROWSE | LISTATTR_SELSINGLE |
  316.                 LISTATTR_SELMULTI | LISTATTR_SELEXTENDED);
  317.         switch (listboxGlobs.selectionMode)
  318.         {
  319.         case 0:
  320.             attributes |= LISTATTR_SELBROWSE;
  321.             break;
  322.  
  323.         case 1:
  324.             attributes |= LISTATTR_SELSINGLE;
  325.             break;
  326.  
  327.         case 2:
  328.             attributes |= LISTATTR_SELMULTI;
  329.             break;
  330.  
  331.         case 3:
  332.             attributes |= LISTATTR_SELEXTENDED;
  333.             break;
  334.         }
  335.  
  336.         mdlDialog_listBoxSetInfo (&attributes, NULL, NULL, TRUE, listP);
  337.         break;
  338.         }
  339.  
  340.     case DITEM_MESSAGE_STATECHANGED:
  341.         if (!dimP->u.stateChanged.reallyChanged)
  342.         break;
  343.  
  344.         listmult_setSelectionList ();
  345.         break;
  346.  
  347.     case DITEM_MESSAGE_BUTTON:
  348.         if (dimP->u.button.buttonTrans == BUTTONTRANS_DOWN)
  349.         {
  350.         dimP->u.button.motionFunc = listmult_trackList;
  351.         }
  352.         else if (dimP->u.button.buttonTrans == BUTTONTRANS_UP)
  353.         {
  354.         mdlDialog_itemSetLabel (dimP->db, listboxGlobs.labelDiP->itemIndex, "");
  355.         }
  356.         break;
  357.  
  358.     default:
  359.         dimP->msgUnderstood = FALSE;
  360.     }
  361.     }
  362.  
  363. /*----------------------------------------------------------------------+
  364. |                                                                       |
  365. | name          listmult_maintainMultiListModifyMenu            |
  366. |                                                                       |
  367. | author        BSI                    10/92           |
  368. |                                                                       |
  369. +----------------------------------------------------------------------*/
  370. Private void listmult_maintainMultiListModifyMenu
  371. (
  372. DItem_PulldownMenu  *menuP
  373. )
  374.     {
  375.     int                nSelections;
  376.     RawItemHdr           *listP;
  377.     DItem_PulldownMenuItem  menuItem;
  378.     boolean            onlyOneElement =
  379.                 (listboxGlobs.selectionMode == SELECTIONMODE_BROWSE ||
  380.                  listboxGlobs.selectionMode == SELECTIONMODE_SINGLE);
  381.  
  382.     if (!listboxGlobs.multiListDiP || !listboxGlobs.multiListDiP->rawItemP)
  383.     return;
  384.  
  385.     listP = listboxGlobs.multiListDiP->rawItemP;
  386.     mdlDialog_listBoxGetSelections (&nSelections, NULL, listP);
  387.  
  388.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  389.                     0, MENUSEARCHID_AddSelection))
  390.         mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  391.  
  392.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  393.                     0, MENUSEARCHID_DeleteSelection))
  394.         mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  395.  
  396.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  397.                     0, MENUSEARCHID_ToggleAddMode))
  398.         mdlDialog_textPDMItemSetEnabled (&menuItem,
  399.                 listboxGlobs.selectionMode == SELECTIONMODE_EXTENDED);
  400.     }
  401.  
  402. /*----------------------------------------------------------------------+
  403. |                                                                       |
  404. | name          listmult_maintainMultiListSelectMenu            |
  405. |                                                                       |
  406. | author        BSI                    10/92           |
  407. |                                                                       |
  408. +----------------------------------------------------------------------*/
  409. Private void listmult_maintainMultiListSelectMenu
  410. (
  411. DItem_PulldownMenu  *menuP
  412. )
  413.     {
  414.     DItem_PulldownMenuItem  menuItem;
  415.     boolean            onlyOneElement =
  416.                 (listboxGlobs.selectionMode == SELECTIONMODE_BROWSE ||
  417.                  listboxGlobs.selectionMode == SELECTIONMODE_SINGLE);
  418.  
  419.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  420.                     0, MENUSEARCHID_SelectEveryOther))
  421.     mdlDialog_textPDMItemSetEnabled (&menuItem, !onlyOneElement);
  422.  
  423.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  424.                     0, MENUSEARCHID_SelectAll))
  425.     mdlDialog_textPDMItemSetEnabled (&menuItem, !onlyOneElement);
  426.  
  427.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  428.                     0, MENUSEARCHID_DeselectAll))
  429.     mdlDialog_textPDMItemSetEnabled (&menuItem,
  430.                 listboxGlobs.selectionMode != SELECTIONMODE_BROWSE);
  431.     }
  432.  
  433. /*----------------------------------------------------------------------+
  434. |                                                                       |
  435. | name          listmult_maintainMultiListPositionMenu            |
  436. |                                                                       |
  437. | author        BSI                    10/92           |
  438. |                                                                       |
  439. +----------------------------------------------------------------------*/
  440. Private void listmult_maintainMultiListPositionMenu
  441. (
  442. DItem_PulldownMenu  *menuP
  443. )
  444.     {
  445.     int                nSelections;
  446.     RawItemHdr           *listP;
  447.     DItem_PulldownMenuItem  menuItem;
  448.     boolean            onlyOneElement =
  449.     (listboxGlobs.selectionMode == SELECTIONMODE_BROWSE ||
  450.      listboxGlobs.selectionMode == SELECTIONMODE_SINGLE);
  451.  
  452.     if (!listboxGlobs.multiListDiP ||
  453.     !listboxGlobs.multiListDiP->rawItemP)
  454.     return;
  455.  
  456.     listP = listboxGlobs.multiListDiP->rawItemP;
  457.     mdlDialog_listBoxGetSelections (&nSelections, NULL, listP);
  458.  
  459.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL,
  460.                 0, MENUSEARCHID_TopSelection))
  461.         mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  462.     }
  463.  
  464. /*----------------------------------------------------------------------+
  465. |                                                                       |
  466. | name        listmult_maintainMultiListLocationMenu            |
  467. |                                                                       |
  468. | author        BSI                    10/92           |
  469. |                                                                       |
  470. +----------------------------------------------------------------------*/
  471. Private void listmult_maintainMultiListLocationMenu
  472. (
  473. DItem_PulldownMenu  *menuP
  474. )
  475.     {
  476.     int                nSelections;
  477.     RawItemHdr           *listP;
  478.     DItem_PulldownMenuItem  menuItem;
  479.     boolean            onlyOneElement =
  480.                 (listboxGlobs.selectionMode == SELECTIONMODE_BROWSE ||
  481.                  listboxGlobs.selectionMode == SELECTIONMODE_SINGLE);
  482.  
  483.     if (!listboxGlobs.multiListDiP || !listboxGlobs.multiListDiP->rawItemP)
  484.     return;
  485.  
  486.     listP = listboxGlobs.multiListDiP->rawItemP;
  487.     mdlDialog_listBoxGetSelections (&nSelections, NULL, listP);
  488.  
  489.     if (!mdlDialog_menuBarFindItem (&menuItem, &menuP, NULL, NULL, 0,
  490.                     MENUSEARCHID_LocationSelection))
  491.     mdlDialog_textPDMItemSetEnabled (&menuItem, nSelections > 0);
  492.     }
  493.  
  494. /*----------------------------------------------------------------------+
  495. |                                                                       |
  496. | name          listmult_multiListInsertItem                |
  497. |                                                                       |
  498. | author        BSI                    11/92           |
  499. |                                                                       |
  500. +----------------------------------------------------------------------*/
  501. Private void listmult_multiListInsertItem
  502. (
  503. RawItemHdr  *listP,
  504. StringList  *strListP,
  505. int         iRow,        /* => row to insert before */
  506. int         nDisplayedRows,
  507. int         oldTopRow,
  508. boolean         appending
  509. )
  510.     {
  511.     int        iString;
  512.     int        newTopRow;
  513.     char    buffer[80];
  514.  
  515.     iString = iRow * listboxGlobs.nColumns;
  516.     mdlStringList_insertMember (&iString, strListP, iString, listboxGlobs.nColumns);
  517.  
  518.     if (appending)
  519.     listmult_rscSprintf (buffer, MSGID_LeftAfter, iRow-1+'A', iRow-1);
  520.     else
  521.     listmult_rscSprintf (buffer, MSGID_LeftBefore, iRow+'A', iRow);
  522.     mdlStringList_setMember (strListP, iString, buffer, NULL);
  523.  
  524.     if (listboxGlobs.nColumns > 1)
  525.     {
  526.     if (appending)
  527.         listmult_rscSprintf (buffer, MSGID_Right, iRow-1);
  528.     else
  529.         listmult_rscSprintf (buffer, MSGID_Right, iRow);
  530.  
  531.     mdlStringList_setMember (strListP, iString+1, buffer, NULL);
  532.     }
  533.  
  534.     mdlDialog_listBoxNRowsChanged (listP);
  535.  
  536.     newTopRow = iRow - nDisplayedRows/2;
  537.     if (newTopRow < 0)  newTopRow = 0;
  538.     mdlDialog_listBoxSetTopRowRedraw (listP, newTopRow, TRUE);
  539.     }
  540.  
  541. /*----------------------------------------------------------------------+
  542. |                                                                       |
  543. | name          listmult_doMultiListModify                |
  544. |                                                                       |
  545. | author        BSI                    10/92           |
  546. |                                                                       |
  547. +----------------------------------------------------------------------*/
  548. Private void listmult_doMultiListModify
  549. (
  550. RawItemHdr  *listP,
  551. int         searchId
  552. )
  553.     {
  554.     int        minRow, maxRow, nDisplayedRows;
  555.     StringList *strListP;
  556.     int        nRows = 0;
  557.  
  558.     strListP = mdlDialog_listBoxGetStrListP (listP);
  559.     if (strListP)
  560.     {
  561.     int nMembers;
  562.  
  563.     nMembers = mdlStringList_size (strListP);
  564.     nRows = nMembers / listboxGlobs.nColumns;
  565.     }
  566.  
  567.     mdlDialog_listBoxGetDisplayRange (&minRow, &maxRow, NULL, NULL, listP);
  568.     nDisplayedRows = maxRow - minRow + 1;
  569.  
  570.     switch (searchId)
  571.     {
  572.     case MENUSEARCHID_ResetList:
  573.         mdlDialog_listBoxSelectCells (listP, 0, -1, 0, -1, FALSE, FALSE);
  574.         mdlStringList_deleteMember (strListP, 0, -1);
  575.         mdlStringList_insertMember (NULL, strListP, -1,
  576.                     NMULTILIST_LINES * 2);
  577.         listmult_multiListInitStrList (strListP);
  578.  
  579.         mdlDialog_listBoxNRowsChanged (listP);
  580.         listmult_multiListInitDisabled (listP);
  581.  
  582.         mdlDialog_listBoxSetTopRowRedraw (listP, 0, TRUE);
  583.         break;
  584.  
  585.     case MENUSEARCHID_RecreateList:
  586.         mdlStringList_destroy (strListP);
  587.         listP->userDataP = strListP =
  588.                 mdlStringList_create (NMULTILIST_LINES*2, 2);
  589.         listmult_multiListInitStrList (strListP);
  590.         mdlDialog_listBoxSetStrListP (listP, strListP, 2);
  591.         listmult_multiListInitDisabled (listP);
  592.         mdlDialog_listBoxSetTopRowRedraw (listP, 0, TRUE);
  593.  
  594.         /* a stateChanged message won't be generated, fixup list
  595.         manually */
  596.         listmult_setSelectionList ();
  597.         break;
  598.  
  599.     case MENUSEARCHID_AddTop:
  600.         listmult_multiListInsertItem (listP, strListP, 0, nDisplayedRows,
  601.                       minRow, FALSE);
  602.         break;
  603.  
  604.     case MENUSEARCHID_AddBottom:
  605.         listmult_multiListInsertItem (listP, strListP, nRows,
  606.                       nDisplayedRows, minRow, TRUE);
  607.         break;
  608.  
  609.     case MENUSEARCHID_AddSelection:
  610.         {
  611.         int        nSelections;
  612.         Spoint2d    *selections;
  613.  
  614.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  615.         if (nSelections > 0 && selections)
  616.         listmult_multiListInsertItem (listP, strListP, selections->y,
  617.                           nDisplayedRows, minRow, FALSE);
  618.         break;
  619.         }
  620.  
  621.     case MENUSEARCHID_DeleteSelection:
  622.         {
  623.         int        nSelections;
  624.         Spoint2d    *selections;
  625.  
  626.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  627.         if (nSelections > 0 && selections)
  628.         {
  629.         int         newTopRow;
  630.         Spoint2d    *curSelectionP;
  631.  
  632.         for (curSelectionP = selections+nSelections-1;
  633.              curSelectionP >= selections; curSelectionP--)
  634.             {
  635.             mdlStringList_deleteMember (strListP,
  636.                         curSelectionP->y * listboxGlobs.nColumns,
  637.                         listboxGlobs.nColumns);
  638.             }
  639.  
  640.         /* browse should always have something selected */
  641.         if (listboxGlobs.selectionMode == SELECTIONMODE_BROWSE)
  642.             mdlDialog_listBoxSelectCells (listP, selections->y,
  643.                           selections->y, 0, -1, TRUE,
  644.                           FALSE);
  645.  
  646.         mdlDialog_listBoxNRowsChanged (listP);
  647.         newTopRow = selections->y - nDisplayedRows/2;
  648.         if (newTopRow < 0)
  649.             newTopRow = 0;
  650.  
  651.         mdlDialog_listBoxSetTopRowRedraw (listP, newTopRow, TRUE);
  652.         }
  653.         break;
  654.         }
  655.     }
  656.     }
  657.  
  658. /*----------------------------------------------------------------------+
  659. |                                                                       |
  660. | name          listmult_doMultiListSelect                |
  661. |                                                                       |
  662. | author        BSI                    10/92           |
  663. |                                                                       |
  664. +----------------------------------------------------------------------*/
  665. Private void listmult_doMultiListSelect
  666. (
  667. RawItemHdr  *listP,
  668. int         searchId
  669. )
  670.     {
  671.     StringList    *strListP;
  672.     int        nRows = 0;
  673.  
  674.     strListP = mdlDialog_listBoxGetStrListP (listP);
  675.     if (strListP)
  676.     {
  677.     int nMembers;
  678.  
  679.     nMembers = mdlStringList_size (strListP);
  680.     nRows = nMembers / listboxGlobs.nColumns;
  681.     }
  682.  
  683.     switch (searchId)
  684.     {
  685.     case MENUSEARCHID_SelectTop:
  686.         {
  687.         Spoint2d    selectionPt;
  688.  
  689.         selectionPt.x = selectionPt.y = 0;
  690.         mdlDialog_listBoxSetSelections (listP, 1, &selectionPt, TRUE,
  691.                         TRUE);
  692.         break;
  693.         }
  694.  
  695.     case MENUSEARCHID_SelectBottom:
  696.         {
  697.         Spoint2d    selectionPt;
  698.  
  699.         selectionPt.y = nRows - 1;
  700.         selectionPt.x = 0;
  701.         mdlDialog_listBoxSetSelections (listP, 1, &selectionPt, TRUE,
  702.                         TRUE);
  703.         break;
  704.         }
  705.  
  706.     case MENUSEARCHID_SelectEveryOther:
  707.         if ((listboxGlobs.selectionMode == SELECTIONMODE_MULTI) ||
  708.         (listboxGlobs.selectionMode == SELECTIONMODE_EXTENDED))
  709.         {
  710.         int         iRow;
  711.         int         nSelectedRows = 0;
  712.         Spoint2d    *curSelectionP, *selectionsP = NULL;
  713.  
  714.         selectionsP = malloc ((nRows/2+1)*sizeof(Spoint2d));
  715.         if (!selectionsP)
  716.             break;
  717.  
  718.         for (iRow=0, curSelectionP=selectionsP; iRow<nRows;
  719.             iRow+=2, curSelectionP++, nSelectedRows++)
  720.              {
  721.              curSelectionP->y = iRow;
  722.              curSelectionP->x = 0;
  723.              }
  724.  
  725.         mdlDialog_listBoxSetSelections (listP, nSelectedRows,
  726.                         selectionsP, TRUE, TRUE);
  727.         free (selectionsP);
  728.         }
  729.         break;
  730.  
  731.     case MENUSEARCHID_SelectAll:
  732.         if ((listboxGlobs.selectionMode == SELECTIONMODE_MULTI) ||
  733.         (listboxGlobs.selectionMode == SELECTIONMODE_EXTENDED))
  734.         {
  735.         mdlDialog_listBoxSelectCells (listP, 0, -1, 0, -1, TRUE,
  736.                           TRUE);
  737.         }
  738.         break;
  739.  
  740.     case MENUSEARCHID_DeselectTop:
  741.         mdlDialog_listBoxSelectCells (listP, 0, 0, 0, -1, FALSE, TRUE);
  742.         break;
  743.  
  744.     case MENUSEARCHID_DeselectBottom:
  745.         mdlDialog_listBoxSelectCells (listP, nRows-1, nRows-1, 0, -1,
  746.                       FALSE, TRUE);
  747.         break;
  748.  
  749.     case MENUSEARCHID_DeselectAll:
  750.         mdlDialog_listBoxSelectCells (listP, 0, -1, 0, -1, FALSE, TRUE);
  751.         break;
  752.     }
  753.     }
  754.  
  755. /*----------------------------------------------------------------------+
  756. |                                                                       |
  757. | name          listmult_doMultiListPosition                |
  758. |                                                                       |
  759. | author        BSI                    10/92           |
  760. |                                                                       |
  761. +----------------------------------------------------------------------*/
  762. Private void listmult_doMultiListPosition
  763. (
  764. RawItemHdr  *listP,
  765. int         searchId
  766. )
  767.     {
  768.     int        minRow, maxRow, nDisplayedRows;
  769.     StringList    *strListP;
  770.     int        nRows = 0;
  771.  
  772.     strListP = mdlDialog_listBoxGetStrListP (listP);
  773.     if (strListP)
  774.     {
  775.     int nMembers;
  776.  
  777.     nMembers = mdlStringList_size (strListP);
  778.     nRows = nMembers / listboxGlobs.nColumns;
  779.     }
  780.  
  781.     mdlDialog_listBoxGetDisplayRange (&minRow, &maxRow, NULL, NULL, listP);
  782.     nDisplayedRows = maxRow - minRow + 1;
  783.  
  784.     switch (searchId)
  785.     {
  786.     case MENUSEARCHID_Top1st:
  787.         mdlDialog_listBoxSetTopRow (listP, 0);
  788.         break;
  789.  
  790.     case MENUSEARCHID_BottomLast:
  791.         {
  792.         int    newTopRow;
  793.  
  794.         newTopRow = nRows - nDisplayedRows;
  795.         if (newTopRow < 0)
  796.         newTopRow = 0;
  797.  
  798.         mdlDialog_listBoxSetTopRow (listP, newTopRow);
  799.         break;
  800.         }
  801.  
  802.     case MENUSEARCHID_TopSelection:
  803.         {
  804.         int        nSelections;
  805.         Spoint2d    *selections;
  806.  
  807.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  808.         if (nSelections > 0 && selections)
  809.         mdlDialog_listBoxSetTopRow (listP, selections->y);
  810.         break;
  811.         }
  812.     }
  813.     }
  814.  
  815. /*----------------------------------------------------------------------+
  816. |                                                                       |
  817. | name          listmult_doMultiListLocation                |
  818. |                                                                       |
  819. | author        BSI                    10/92           |
  820. |                                                                       |
  821. +----------------------------------------------------------------------*/
  822. Private void listmult_doMultiListLocation
  823. (
  824. RawItemHdr  *listP,
  825. int         searchId
  826. )
  827.     {
  828.     StringList    *strListP;
  829.     int        nRows = 0;
  830.  
  831.     strListP = mdlDialog_listBoxGetStrListP (listP);
  832.     if (strListP)
  833.     {
  834.     int nMembers;
  835.  
  836.     nMembers = mdlStringList_size (strListP);
  837.     nRows = nMembers / listboxGlobs.nColumns;
  838.     }
  839.  
  840.     switch (searchId)
  841.     {
  842.     case MENUSEARCHID_LocationTop:
  843.         {
  844.         int newTopRow;
  845.  
  846.         mdlDialog_listBoxSetLocationCursor (listP, 0, 0);
  847.  
  848.         /* need to get location cursor since first rows may be disabled */
  849.         mdlDialog_listBoxGetLocationCursor (&newTopRow, NULL, listP);
  850.         mdlDialog_listBoxSetTopRow (listP, newTopRow);
  851.         break;
  852.         }
  853.  
  854.     case MENUSEARCHID_LocationBottom:
  855.         {
  856.         int newTopRow;
  857.         int    minRow, maxRow, nDisplayedRows;
  858.  
  859.         mdlDialog_listBoxSetLocationCursor (listP, nRows-1, 0);
  860.  
  861.         /* need to get location cursor since last rows may be disabled */
  862.         mdlDialog_listBoxGetLocationCursor (&newTopRow, NULL, listP);
  863.  
  864.         mdlDialog_listBoxGetDisplayRange (&minRow, &maxRow, NULL, NULL,
  865.                           listP);
  866.         nDisplayedRows = maxRow - minRow + 1;
  867.         newTopRow = newTopRow - nDisplayedRows + 1;
  868.         if (newTopRow < 0)
  869.         newTopRow = 0;
  870.  
  871.         mdlDialog_listBoxSetTopRow (listP, newTopRow);
  872.         break;
  873.         }
  874.  
  875.     case MENUSEARCHID_LocationSelection:
  876.         {
  877.         int        nSelections;
  878.         Spoint2d    *selections;
  879.  
  880.         mdlDialog_listBoxGetSelections (&nSelections, &selections, listP);
  881.         if (nSelections > 0 && selections)
  882.         {
  883.         mdlDialog_listBoxSetLocationCursor (listP, selections->y, 0);
  884.         listmult_doMultiListPosition (listP, MENUSEARCHID_TopSelection);
  885.         }
  886.         break;
  887.         }
  888.     }
  889.     }
  890.  
  891. /*----------------------------------------------------------------------+
  892. |                                                                       |
  893. | name          listmult_multiListTestsMenusHook            |
  894. |                                                                       |
  895. | author        BSI                    10/92           |
  896. |                                                                       |
  897. +----------------------------------------------------------------------*/
  898. Public void listmult_multiListTestsMenusHook
  899. (
  900. DialogItemMessage   *dimP
  901. )
  902.     {
  903.     dimP->msgUnderstood = TRUE;
  904.  
  905.     switch (dimP->messageType)
  906.     {
  907.     case DITEM_MESSAGE_DRAW:
  908.         {
  909.         DItem_PulldownMenuItem  menuItem;
  910.         RawItemHdr           *menuBarP = dimP->dialogItemP->rawItemP;
  911.         PulldownMenuMessage       *pdmmP =
  912.                     (PulldownMenuMessage *)dimP->auxInfoP;
  913.         DItem_PulldownMenu       *menuP = pdmmP->menuP;
  914.  
  915.         if (menuP->type != RTYPE_PulldownMenu)
  916.         break;
  917.         /* need to switch on menuP->id because multiple menus were attached
  918.            to this hook function */
  919.         switch (menuP->id)
  920.         {
  921.         case PULLDOWNMENUID_MultiListModify:
  922.             listmult_maintainMultiListModifyMenu (menuP);
  923.             break;
  924.  
  925.         case PULLDOWNMENUID_MultiListSelect:
  926.             listmult_maintainMultiListSelectMenu (menuP);
  927.             break;
  928.  
  929.         case PULLDOWNMENUID_MultiListPosition:
  930.             listmult_maintainMultiListPositionMenu (menuP);
  931.             break;
  932.  
  933.         case PULLDOWNMENUID_MultiListLocation:
  934.             listmult_maintainMultiListLocationMenu (menuP);
  935.             break;
  936.         }
  937.  
  938.         break;
  939.         }
  940.  
  941.     case DITEM_MESSAGE_BUTTON:
  942.         {
  943.         DItem_PulldownMenuItem  menuItem;
  944.         RawItemHdr           *menuBarP = dimP->dialogItemP->rawItemP;
  945.         PulldownMenuMessage       *pdmmP =
  946.                     (PulldownMenuMessage *)dimP->auxInfoP;
  947.         DItem_PulldownMenu       *menuP;
  948.         RawItemHdr           *listP;
  949.         int                searchId;
  950.  
  951.         if (dimP->u.button.buttonTrans != BUTTONTRANS_UP)
  952.         break;
  953.         menuP = pdmmP->menuP;
  954.  
  955.         if (!listboxGlobs.multiListDiP || !listboxGlobs.multiListDiP->rawItemP)
  956.         break;
  957.         listP = listboxGlobs.multiListDiP->rawItemP;
  958.         searchId = pdmmP->u.activateItem.searchId;
  959.  
  960.         /* need to switch on menuP->id because multiple menus were
  961.         attached to this hook function */
  962.         switch (menuP->id)
  963.         {
  964.         case PULLDOWNMENUID_MultiListModify:
  965.             listmult_doMultiListModify (listP, searchId);
  966.             break;
  967.  
  968.         case PULLDOWNMENUID_MultiListSelect:
  969.             listmult_doMultiListSelect (listP, searchId);
  970.             break;
  971.  
  972.         case PULLDOWNMENUID_MultiListPosition:
  973.             listmult_doMultiListPosition (listP, searchId);
  974.             break;
  975.  
  976.         case PULLDOWNMENUID_MultiListLocation:
  977.             listmult_doMultiListLocation (listP, searchId);
  978.             break;
  979.         }
  980.  
  981.         break;
  982.         }
  983.  
  984.     default:
  985.         dimP->msgUnderstood = FALSE;
  986.         break;
  987.     }
  988.     }
  989.  
  990. /*----------------------------------------------------------------------+
  991. |                                                                       |
  992. | name          listmult_multiListDialogHook                |
  993. |                                                                       |
  994. | author        BSI                    09/92           |
  995. |                                                                       |
  996. +----------------------------------------------------------------------*/
  997. Public void    listmult_multiListDialogHook
  998. (
  999. DialogMessage    *dmP        /* => a ptr to a dialog message */
  1000. )
  1001.     {
  1002.     dmP->msgUnderstood = TRUE;
  1003.     switch (dmP->messageType)
  1004.     {
  1005.     case DIALOG_MESSAGE_CREATE:
  1006.         {
  1007.         listboxGlobs.selectionMode = SELECTIONMODE_BROWSE;
  1008.         listboxGlobs.nColumns = 2;
  1009.  
  1010.         dmP->u.create.interests.nonDataPoints = TRUE;
  1011.         
  1012.         break;
  1013.         }
  1014.  
  1015.     default:
  1016.         dmP->msgUnderstood = FALSE;
  1017.         break;
  1018.     }
  1019.     }
  1020.  
  1021.