home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / intui110 / tui2.hlp < prev    next >
Encoding:
Text File  |  1992-01-18  |  11.9 KB  |  269 lines

  1. `co(4,7);─────────────────── /// Dialog Transfer and Menu construction ────────────────`co();
  2.  
  3.       InTUItion's Transfer capabilities is one of its most powerful features.
  4.     It gives you the ability to nest or "transfer" control from one dialog to
  5.     another.  Using this feature gives you almost unlimited flexibility in
  6.     dialog construction.  Here's how it works...
  7.  
  8.       The best example of how a transfer works is in the construction program
  9.     itself.  Transfer is used in the Entry dialog.  When this dialog is
  10.     displayed, click on the button marked "Special".  You will see another
  11.     dialog appear containing additional data used by the entry system.  In
  12.     this way, we can prevent cluttering the screen with additional data that
  13.     does not always require modification, yet is only a click or keystroke
  14.     away!
  15.  
  16.       To setup a transfer from one dialog to another, you must first have more
  17.     than one dialog created in your TUI.  All you have to do is click on the
  18.     "Transfer" button in the edit dialog for the item from which you wish to
  19.     transfer.  Though this would normally be a button, you can transfer from
  20.     any object except a static text string.  When you click on "Transfer", a
  21.     pick list will appear containing all dialogs within the current TUI.
  22.     Simply pick the desired dialog to which to transfer.
  23.  
  24.       We have one more decision to make.  When a dialog is transferred from
  25.     another dialog, we need to know what to do when this dialog is exited.  In
  26.     the case of two dialogs the decision is easy; we simply transfer back to
  27.     the calling dialog.  However, suppose we nest four levels deep: do we
  28.     return to the previous dialog or to the first dialog?  InTUItion allows
  29.     you to control this for greater flexibility.  Each item in the dialog that
  30.     can be set as an exit has two buttons marked "One Level" and "All Levels".
  31.     If you select "One Level", then when this object causes an exit from the
  32.     current dialog, control will be returned to the calling dialog (one level
  33.     below it).  If you select "All Levels", the exit will go through all
  34.     dialogs in the chain, finallly exiting from the very first dialog in the
  35.     chain.  The returned value will be set to the item in that very top dialog
  36.     that caused the exit.  It may sound confusing but it's really quite
  37.     simple. Run the included transfer tutorial and try creating your own and
  38.     you'll have transfer mastered in no time.
  39.  
  40.       InTUItion does not support menus as a seperate object or entity.  Menu
  41.     support is part of the UltraWin package.  However, a menu is really just a
  42.     sequence of linked dialogs.  Since we now understand the transfer
  43.     mechanism, we can see how this might work.  The TUICP has a few built in
  44.     features that allow easier construction of dialogs in menu form.
  45.  
  46.       To create a basic menu we simply add a dialog to the TUI.  In this case
  47.     however, we add a menu dialog.  Simply select "Add Menu Dialogs" from the
  48.     "Dialogs" menu.  You will be asked to select the number of dialogs to add.
  49.     This corresponds to how many drop down menus to create on the base horiz-
  50.     ontal menu bar.  Let's select eight and click on OK.  You will notice that
  51.     the TUICP adds nine dialogs to the TUI.  The first dialog is the
  52.     horizontal menu bar and the rest are the drop down menus.  If you click
  53.     the right button on the first one and select "Test" from the "Edit" menu,
  54.     you can see the Transfer in action.  It appears as though we have created
  55.     a common drop down menu system; however, we have done much more.  The
  56.     TUICP created nine dialogs that transfer control back and forth in a
  57.     layout that looks like a typical menu system.  The important thing to
  58.     remember here is that the dialogs have nothing to do with menus since
  59.     menus don't really exist in InTUItion.  This means that you can modify the
  60.     dialogs to contain check boxes, strings, icons, even sliders!  You can
  61.     also move them around the screen, transfer control to yet another menu or
  62.     dialog, etc.  The possibilities are unlimited.  Just remember, a menu is
  63.     really a number of dialogs that contain buttons for each menu entry,
  64.     linked together with the transfer capability.  Run the included menu
  65.     tutorial and try creating your own and you'll soon feel quite confortable
  66.     with this versatile menu system.
  67.  
  68.     NOTE:  While you can create standard drop down menus with the TUICP, and
  69.                  these have there place in many programs, the concept behind the
  70.                  dialogs is to find easier and more intuitive ways to create user
  71.                  interfaces.  You will find that many programs don't need any menus
  72.                  at all, and the ones that do (such as TUICP.EXE) can have a very
  73.                  simple and straightforward menu system that transfers control to
  74.                  other dialogs.
  75.  
  76.  
  77. `co(4,7);────────────────── /// Incorporating Dialogs into your programs ──────────────`co();
  78.  
  79.       Once your have finished your dialog, the easiest way to incorporate it
  80.     into your program is to let the TUICP do the work for you by generating a
  81.     "C" source code shell to interact with the dialog.  Below is an example
  82.     and an explanation as to how it works.
  83.  
  84.         First we have the TEST.DEF file that contains the names of all the
  85.     objects within our dialog.  The generated file looks like this.
  86.  
  87. /**************************************************************************/
  88. /* TEST.DEF                                                               */
  89. /*                                                                        */
  90. /* TUI definitions.  Use these defines as the index parameter for all the */
  91. /* InTUItion functions.                                                   */
  92. /**************************************************************************/
  93.  
  94. #define  TEST_DLG             0
  95. #define  BOX                  1
  96. #define  ENTRY                2
  97. #define  H_SLIDER             3
  98. #define  V_SLIDER             4
  99. #define  ICON                 5
  100. #define  BUTTON               6
  101.  
  102.         Second, we have the TEST.C file that contains the actual source
  103.     generated by the TUICP.  The generated file looks like this.
  104.  
  105. /**************************************************************************/
  106. /* TEST.C                                                                 */
  107. /*                                                                        */
  108. /* Default logic for dialog interaction.                                  */
  109. /**************************************************************************/
  110. #include "t.h"                             /* include the TUI definitions */
  111. #include "TEST.DEF"
  112.  
  113. /*************/
  114. /* ~interact */
  115. /*           **************************************************************/
  116. /* Shell code for typical dialog interaction.  A pointer to the TUI and   */
  117. /* the define for the dialog are passed.                                  */
  118. /*                                                                        */
  119. /* Pass the DO_NORMAL define to do_dialog if you do not want to have every*/
  120. /* event the do_dialog function does not understand returned to you!      */
  121. /**************************************************************************/
  122. interact( TUI *tuip, int dlg_inx )
  123. {
  124.   int ret_inx, end_flag = OFF;
  125.  
  126.   draw_dialog(tuip, dlg_inx);
  127.   while (!end_flag)
  128.   {
  129.     ret_inx = do_dialog(tuip, dlg_inx, DO_RETURN_EVENT);
  130.     switch( ret_inx )
  131.     {
  132.       /*---------------- ESC pressed or clicked off dialog ---------------*/
  133.       case NO_SELECTION:
  134.         end_flag = ON;
  135.         break;
  136.      /*---------------------- an event not processable -------------------*/
  137.       case EVENT_RETURNED:
  138.         if (!Event.is_mouse)
  139.         {
  140.         }
  141.           else switch( Event.key )
  142.         {
  143.         }
  144.         break;
  145.       case BOX:
  146.         break;
  147.       case ENTRY:
  148.         break;
  149.       case H_SLIDER:
  150.         break;
  151.       case V_SLIDER:
  152.         break;
  153.       case ICON:
  154.         break;
  155.       case BUTTON:
  156.         break;
  157.     }
  158.     if ( is_valid_inx(tuip, ret_inx) )
  159.     {
  160.       switch( get_item_type(tuip, ret_inx) )
  161.       {
  162.         case T_BUTTON: case T_ICON:
  163.           deselect(tuip, ret_inx);
  164.           draw_item(tuip, ret_inx);
  165.           break;
  166.       }
  167.     }
  168.   }
  169.   erase_dialog(tuip, dlg_inx);
  170. }
  171. /*** end of interact ***/
  172.  
  173. /*** END OF FILE ***/
  174.  
  175.         Now for your main program, you might have something like this:
  176.  
  177. main()
  178. {
  179.     TUI            Test_tui, *Test_tuip = &Test_tui;
  180.     WINDOW    *desk_wnp;
  181.  
  182.     load_tui(Test_tuip, "TEST.TUI");                /* read the TUI file from disk  */ 
  183.     init_tui(Test_tuip);                                        /* init video, mouse, etc           */
  184.     desk_wnp = Test_tuip->back_wnp;
  185.  
  186.     interact(Test_tuip, TEST_DLG);                    /* go execute generated function*/
  187.  
  188.     end_tui(Test_tuip);                                            /* reset mouse, video, etc            */
  189.     free_tui(Test_tuip);
  190. }
  191.  
  192.       Your main program calls interact with the TUI pointer which has been
  193.     either loaded or linked in, and an index to this dialog.  Remember, a TUI
  194.     file can have many dialogs, this is why we named the dialog when we first
  195.     created it.  You will notice that the interact function draws the dialog
  196.     and calls the core function do_dialog.  This is the main routine that
  197.     interacts with the dialog, returning control to you when an action is
  198.     performed.  Notice the simple switch case processing.  It is almost
  199.     identical to a simply key press switch;  it's really that easy!  All you
  200.     have to do is add the code to handle each event.  We do that next to give
  201.     you a better feel for accessing each object.  Let's start with BOX.
  202.  
  203. BOX - when the user clicks on the box, do_dialog returns the index of BOX.
  204.             We can then perform any needed action.  Let's just beep for now to
  205.             let the user know he selected the box.
  206.  
  207.       case BOX:
  208.         tone(1000,91);                                      /* beep at 1000 Hz for 1 second */
  209.         break;
  210.  
  211. ENTRY - when the user clicks on the entry field or tabs to it and presses
  212.                 enter, or presses the proper hot key, do_dialog returns the index
  213.                 of ENTRY. We can now read the value entered and print it out.
  214.                 
  215.  
  216.           case ENTRY:
  217.        wn_plst(0,0,((TUI_INPUT *)Test_tuip->base[ENTRY].more.ptr)->text.ptr,
  218.                desk_wnp);
  219.        break;
  220.         
  221.        Looks pretty complicated doesn't it?  Here it is in English.  Get
  222.              the main array within this TUI, index into it with the ENTRY object,
  223.              get its more pointer, (which points to an input structure), then get
  224.              its text pointer which points to the string in question.  Then put
  225.              this text in the top left corner of the background desktop window
  226.              created by the init_tui function.  Don't worry, we simplify this
  227.              with macros; here's how it really looks.
  228.  
  229.           case ENTRY:
  230.        wn_plst(0,0, get_inp_text(Test_tuip, ENTRY), desk_wnp);
  231.        break;
  232.         
  233.        A little better; now you can relax again, InTUItion really is doing
  234.              all the hard work for you.
  235.  
  236.  
  237. H_SLIDER - when the user adjusts the slider, do_dialog returns the proper
  238.                      index.  Now we can read the slider value and print it out.  Both
  239.                      horizontal and vertical sliders would have similar code.
  240.            
  241.           case H_SLIDER:
  242.        mv_cs( 0, 0, Test_tuip->back_wnp );
  243.        wn_printf(desk_wnp, "%ld", get_sldr_pos(Test_tuip, H_SLIDER));
  244.        break;
  245.            
  246.  
  247. ICON - when the user clicks on the icon, do_dialog returns the index 
  248.        of ICON. We can then perform any needed action.  Let's just call
  249.        a functionin this case.
  250.  
  251.           case ICON:
  252.        do_icon_action();
  253.        break;
  254.  
  255. BUTTON - when the user clicks on the button, do_dialog returns the index of
  256.                  BUTTON. We can then perform any needed action.  Let's exit the
  257.                  interact function by setting end_flag to ON.
  258.  
  259.           case BUTTON:
  260.        end_flag = ON;                                            /* will cause exit on next pass */
  261.        break;
  262.  
  263.  
  264.       That's all there is to it!  Notice that at the end of the switch
  265.     statement that if the item selected is a button or icon we deselect the
  266.     object and redraw it, since the object would otherwise be left in the
  267.     selected state.  You may elect not to do this depending on what action the
  268.     object is to perform.
  269.