home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk22 / dir02 / f013370.re_ / f013370.re
Text File  |  1996-04-02  |  10KB  |  256 lines

  1. /*----------------------------------------------------------------------+
  2. |                                    |
  3. |  Copyright (1993-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. |    $Logfile:   J:/mdl/examples/basic/basic.mcv  $
  18. |   $Workfile:   basic.mc  $
  19. |   $Revision:   5.5  $
  20. |       $Date:   12 Jul 1995 10:39:30  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   Function -                                |
  26. |                                    |
  27. |    MDL example to show creation & use of basic dialog box        |
  28. |                                    |
  29. |    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    |
  30. |                                    |
  31. |   Public Routine Summary -                        |
  32. |                                    |
  33. |    main - Main entry point and initialization logic        |
  34. |    basic_dialogHook - Dialog box hook function            |
  35. |    basic_toggleButtonHook - Toggle button item hook function    |
  36. |    basic_openModal - Application command function to open modal    |
  37. |        dialog box                            |
  38. |    basic_errorPrint - Function to display an error message in     |
  39. |        messages dialog box                        |
  40. |                                    |
  41. +----------------------------------------------------------------------*/
  42. /*----------------------------------------------------------------------+
  43. |                                    |
  44. |   Include Files                               |
  45. |                                    |
  46. +----------------------------------------------------------------------*/
  47. #include    <mdl.h>        /* MDL Library funcs structures & constants */
  48. #include    <dlogitem.h>    /* Dialog Box Manager structures & constants */
  49. #include    <cexpr.h>        /* C Expression structures & constants */
  50. #include    <cmdlist.h>        /* MicroStation command numbers */
  51.  
  52. #include    <dlogman.fdf>   /* dialog box manager function prototypes */
  53. #include    <msrsrc.fdf>
  54. #include    <mssystem.fdf>
  55. #include    <mscexpr.fdf>
  56. #include    <msparse.fdf>
  57.  
  58. #include    "basic.h"        /* basic dialog box example constants & structs */
  59. #include    "basiccmd.h"    /* basic dialog box command numbers */
  60.  
  61. /*----------------------------------------------------------------------+
  62. |                                    |
  63. |   Utility routines                            |
  64. |                                    |
  65. +----------------------------------------------------------------------*/
  66. /*----------------------------------------------------------------------+
  67. |                                                                       |
  68. | name          basic_errorPrint -- print an error message into Dialog    |
  69. |                  Box Manager Messages dialog box        |
  70. |                                                                       |
  71. | author        BSI                                     12/90           |
  72. |                                                                       |
  73. +----------------------------------------------------------------------*/
  74. Private void basic_errorPrint
  75. (
  76. int errorNumber            /* => number of error to print */
  77. )
  78.     {
  79.     char    errorMsg[80];
  80.  
  81.     if (mdlResource_loadFromStringList (errorMsg, NULL,
  82.         MESSAGELISTID_BasicErrors, errorNumber))
  83.     return;    /* unable to find message with number "errorNumber" */
  84.  
  85.     mdlDialog_dmsgsPrint (errorMsg);
  86.     }
  87.  
  88.  
  89. /*----------------------------------------------------------------------+
  90. |                                    |
  91. |   Private Global variables                        |
  92. |                                    |
  93. +----------------------------------------------------------------------*/
  94. /* The following variable is referenced in C expression strings used by
  95.    the text, option button, and toggle button items defined in basic.r.
  96.    The initial external state of the text item and the option button
  97.    (they are both looking at the same application variable) is 1.  The
  98.    initial external state of the toggle button in the modal dialog box is
  99.    0 (the toggle is "out" or OFF) */
  100. Private BasicGlobals    basicGlobals = {1, 0};
  101.  
  102. /*----------------------------------------------------------------------+
  103. |                                                                       |
  104. |   Hook Functions                            |
  105. |                                                                       |
  106. +----------------------------------------------------------------------*/
  107. /*----------------------------------------------------------------------+
  108. |                                    |
  109. | name        basic_dialogHook                    |
  110. |                                    |
  111. | author    BSI                     12/90        |
  112. |                                    |
  113. +----------------------------------------------------------------------*/
  114. Private void    basic_dialogHook
  115. (
  116. DialogMessage    *dmP        /* => a ptr to a dialog message */
  117. )
  118.     {
  119.     /* ignore any messages being sent to modal dialog hook */
  120.     if (dmP->dialogId != DIALOGID_Basic)
  121.     return;
  122.  
  123.     dmP->msgUnderstood = TRUE;
  124.     switch (dmP->messageType)
  125.     {
  126.     case DIALOG_MESSAGE_DESTROY:
  127.         {
  128.         /* unload this mdl task when the Basic Dialog is closed */
  129.         mdlDialog_cmdNumberQueue (FALSE, CMD_MDL_UNLOAD,
  130.                       mdlSystem_getCurrTaskID(), TRUE);
  131.         /*  mdlSystem_getCurrTaskID was erroneously omitted from the
  132.         MDL documentation. It returns a character pointer that
  133.         points to the current task's task ID.    */
  134.         break;
  135.         };
  136.  
  137.     default:
  138.         dmP->msgUnderstood = FALSE;
  139.         break;
  140.     }
  141.     }
  142.  
  143. /*----------------------------------------------------------------------+
  144. |                                    |
  145. | name        basic_toggleButtonHook                    |
  146. |                                    |
  147. | author    BSI                     12/90        |
  148. |                                    |
  149. +----------------------------------------------------------------------*/
  150. Private void basic_toggleButtonHook
  151. (
  152. DialogItemMessage   *dimP    /* => a ptr to a dialog item message */
  153. )
  154.     {
  155.     dimP->msgUnderstood = TRUE;
  156.  
  157.     switch (dimP->messageType)
  158.     {
  159.     case DITEM_MESSAGE_CREATE:
  160.         {
  161.         basicGlobals.parameter2 = 0;
  162.         break;
  163.         }
  164.  
  165.     default:
  166.         dimP->msgUnderstood = FALSE;
  167.         break;
  168.         }
  169.     }
  170.  
  171. /*----------------------------------------------------------------------+
  172. |                                                                       |
  173. |       Command Handling routines                                       |
  174. |                                                                       |
  175. +----------------------------------------------------------------------*/
  176. /*----------------------------------------------------------------------+
  177. |                                                                       |
  178. | name          basic_openModal                                         |
  179. |                                                                       |
  180. | author        BSI                                     12/90           |
  181. |                                                                       |
  182. +----------------------------------------------------------------------*/
  183. Public cmdName void basic_openModal
  184. (
  185. char    *unparsedP    /* => unparsed part of command */
  186. )
  187. cmdNumber   CMD_OPENMODAL
  188.     {
  189.     int    lastAction;
  190.  
  191.     /* open child modal dialog box */
  192.     if (mdlDialog_openModal (&lastAction, NULL, DIALOGID_BasicModal))
  193.     {
  194.     basic_errorPrint (ERRID_ModalDialog);
  195.     return;
  196.     }
  197.  
  198.     /* if the user clicked in OK push button, and the toggle button is
  199.        currently "in", then increment parameter1 and update the appearance
  200.        of both the text item and the option button item in the Basic dialog
  201.        box */
  202.     if (lastAction == ACTIONBUTTON_OK && basicGlobals.parameter2)
  203.     {
  204.     basicGlobals.parameter1++;
  205.     if (basicGlobals.parameter1 > 3)
  206.         basicGlobals.parameter1 = 1;
  207.     mdlDialog_synonymsSynch (NULL, SYNONYMID_Basic, NULL);
  208.     }
  209.     }
  210.  
  211. /*----------------------------------------------------------------------+
  212. |                                    |
  213. | name        main                            |
  214. |                                    |
  215. | author    BSI                     12/90        |
  216. |                                    |
  217. +----------------------------------------------------------------------*/
  218. Private DialogHookInfo uHooks[] =
  219.     {
  220.     {HOOKITEMID_ToggleButton_Basic,    basic_toggleButtonHook},
  221.     {HOOKDIALOGID_Basic,        basic_dialogHook},
  222.     };
  223.  
  224. Public int main
  225. (
  226. int   argc,        /* => number of args in next array */
  227. char *argv[]        /* => array of cmd line arguments */
  228. )
  229.     {
  230.     char        *setP;    /* a ptr to a "C expression symbol set" */
  231.     RscFileHandle    rscFileH;    /* a resource file handle */
  232.     DialogBox        *dbP;    /* a ptr to a dialog box */
  233.  
  234.     /* open the resource file that we came out of */
  235.     mdlResource_openFile (&rscFileH, NULL, 0);
  236.  
  237.     /* load the command table */
  238.     if (mdlParse_loadCommandTable (NULL) == NULL)
  239.     basic_errorPrint (ERRID_CommandTable);
  240.  
  241.     /* set up variables that will be evaluated within C expression strings */
  242.     setP = mdlCExpression_initializeSet (VISIBILITY_DIALOG_BOX, 0, FALSE);
  243.     mdlDialog_publishComplexVariable (setP, "basicglobals",
  244.                         "basicGlobals", &basicGlobals);
  245.  
  246.     /* publish our hook functions */
  247.     mdlDialog_hookPublish (sizeof(uHooks)/sizeof(DialogHookInfo), uHooks);
  248.  
  249.     /* open the "Basic" dialog box */
  250.     if ( (dbP = mdlDialog_open (NULL, DIALOGID_Basic)) == NULL)
  251.     basic_errorPrint (ERRID_BasicDialog);
  252.  
  253.     return SUCCESS;
  254.     }
  255.  
  256.