home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / languages / progs / shell / Sources / c / Menu < prev    next >
Encoding:
Text File  |  1994-05-17  |  2.9 KB  |  151 lines

  1. #include <string.h>
  2.  
  3. #include "DeskLib:Menus.h"
  4. #include "DeskLib:WimpSWIs.h"
  5. #include "DeskLib:Kbd.h"
  6. #include "DeskLib:Window.h"
  7. #include "DeskLib:Event.h"
  8. #include "DeskLib:Save.h"
  9.  
  10. #include "Shell.ShellMenu.h"
  11. #include "Shell.Extra.h"
  12.  
  13.  
  14.  
  15. #define Shell_StringsDiffer( s1, s2)    (strcmp( (s1), (s2)))
  16. #define Shell_StringsEqual( s1, s2)    (!strcmp( (s1), (s2)))
  17.     /* I can never remember which way round strcmp works...    */
  18.  
  19. BOOL            Shell_pause    = FALSE;
  20.  
  21. static char            Shell_selections[255];
  22. static menu            men, defaultmenu;
  23. static menu_block        *menublock;
  24. static Shell_menuhandler    menuhandler;
  25.  
  26. static window_handle save_window;
  27.  
  28.  
  29.  
  30.  
  31. void    Shell_MenuPoll( void)
  32. {
  33. do    {
  34.     if ( Shell_pause)    Shell_Poll();
  35.     else    {
  36.         Shell_PollSlow();
  37.         if ( !Shell_selections[0]) return;
  38.         }
  39.  
  40.     if ( Shell_selections[0])    {
  41.         if ( Shell_StringsEqual( Shell_selections, "Pause"))    {
  42.             Shell_pause=TRUE;
  43.             }
  44.         else if ( Shell_StringsEqual( Shell_selections, "Continue"))    {
  45.             Shell_pause=FALSE;
  46.             }
  47.         else    menuhandler( Shell_selections);
  48.         Shell_selections[0] = 0;
  49.         }
  50.     }
  51.     while ( Shell_pause);
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. static void    Shell_MenuHandler( void *ref, int *hit)
  61. {
  62.  
  63. UNUSED( ref);
  64.  
  65. Wimp_DecodeMenu( menublock, hit, Shell_selections);
  66. *strchr( Shell_selections, '\r') = 0;
  67. /* can't do 'menuhandler( Shell_selections)' */
  68.  
  69. if ( Shell_StringsEqual( Shell_selections, "Pause"))    {
  70.     Menus_SetFlags( men, 1, TRUE, TRUE);
  71.     Menus_SetFlags( men, 2, FALSE, FALSE);
  72.     }
  73.  
  74. else    if ( Shell_StringsEqual( Shell_selections, "Continue"))    {
  75.     Menus_SetFlags( men, 1, FALSE, FALSE);
  76.     Menus_SetFlags( men, 2, TRUE, TRUE);
  77.     }
  78.  
  79. /*    copy hit to global storage, so that menu flags can be changed (NIY)
  80.     {    int *hit2 = global_hit;
  81.     do    {
  82.         *hit2++ = *hit++;
  83.         }
  84.         while ( *hit != -1);
  85.     }
  86. */
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. static menu Shell_MenuMaker( void *ref)
  97. {
  98. /*if ( Kbd_KeyDown( inkey_SHIFT))    return (menu) -1;*/
  99. UNUSED( ref);
  100. return    men;
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. void    Shell_InitMenuHandler( char *menutitle, char *menustring, Shell_menuhandler menhand)
  109. {
  110. men = Menus_New( menutitle, menustring);
  111.  
  112. defaultmenu = Menus_New( "Default", "Save");
  113.  
  114. save_window = Window_Create( "SaveAs", 0);
  115.  
  116. Menus_AddDialogBox( defaultmenu, 1, save_window);
  117.  
  118. Menus_SetFlags( men, 1, FALSE, FALSE);
  119. Menus_SetFlags( men, 2, TRUE, TRUE);
  120.  
  121. menublock = Menus_SysHandle( men);
  122. Menus_AttachMenuMaker( Shell_MenuMaker, event_ANY, event_ANY, Shell_MenuHandler, (void *) men );
  123. menuhandler = menhand;
  124. }
  125.  
  126.  
  127.  
  128. void    Shell_ChangeMenu( char *menutitle, char *menustring)
  129. {
  130. /*Menus_Dispose( men, |*recursive*| TRUE);*/
  131. men = Menus_New( menutitle, menustring);
  132. defaultmenu = Menus_New( "default", "Save");
  133. menublock = Menus_SysHandle( men);
  134. Menus_AttachMenu( men, event_ANY, event_ANY, Shell_MenuHandler, NULL );
  135. }
  136.  
  137.  
  138. void    Shell_SuspendMenu( void)
  139. {
  140. if (!men) Shell_ErrorReportFatal( 1, "Can't suspend menu - none is defined");
  141. Menus_DetachMenu( event_ANY, event_ANY);
  142. }
  143.  
  144.  
  145. void    Shell_UnSuspendMenu( void)
  146. {
  147. Menus_AttachMenu( men, event_ANY, event_ANY, Shell_MenuHandler, NULL );
  148. }
  149.  
  150.  
  151.