home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / bgui-1.1a.lha / BGUI / demos / popwindow.c < prev    next >
C/C++ Source or Header  |  1994-09-23  |  9KB  |  181 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc popwindow.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: popwindow.c,v $
  7. **      Description: Simple demonstration of jumping to another screen.
  8. **        Copyright: (C) Copyright 1994 Jaba Development.
  9. **                   (C) Copyright 1994 Jan van den Baard.
  10. **                   All Rights Reserved.
  11. **
  12. **          $Author: jaba $
  13. **        $Revision: 1.2 $
  14. **            $Date: 1994/09/23 11:29:18 $
  15. **/
  16.  
  17. #include <libraries/bgui.h>
  18. #include <libraries/bgui_macros.h>
  19. #include <libraries/gadtools.h>
  20.  
  21. #include <clib/alib_protos.h>
  22.  
  23. #include <proto/exec.h>
  24. #include <proto/bgui.h>
  25. #include <proto/intuition.h>
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. /*
  32. **      Library base pointer.
  33. **      NOTE: The intuition.library is opened by DICE
  34. **      it's auto-init code.
  35. **/
  36. struct Library                  *BGUIBase;
  37.  
  38. /*
  39. **      Object ID's.
  40. **/
  41. #define ID_QUIT                 1
  42. #define ID_SCREENNAME           2
  43.  
  44. int main( int argc, char *argv[] )
  45. {
  46.         struct Window           *window;
  47.         Object                  *WO_Window, *GO_Quit, *GO_Name;
  48.         UBYTE                    name[ 64 ];
  49.         ULONG                    signal = 0, rc, tmp;
  50.         BOOL                     running = TRUE;
  51.  
  52.         /*
  53.         **      Open the library.
  54.         **/
  55.         if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  56.                 /*
  57.                 **      Create the window object.
  58.                 **/
  59.                 WO_Window = WindowObject,
  60.                         WINDOW_Title,           "PopWindow Demo",
  61.                         WINDOW_ScaleWidth,      20,
  62.                         WINDOW_SizeGadget,      FALSE,
  63.                         WINDOW_PubScreenName,   "Workbench",
  64.                         WINDOW_MasterGroup,
  65.                                 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  66.                                         StartMember, GO_Name =  String( "Screen Name:", "Workbench", 64, ID_SCREENNAME ), EndMember,
  67.                                         StartMember,
  68.                                                 HGroupObject,
  69.                                                         VarSpace( 50 ),
  70.                                                         StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  71.                                                         VarSpace( 50 ),
  72.                                                 EndObject,
  73.                                         EndMember,
  74.                                 EndObject,
  75.                 EndObject;
  76.  
  77.                 /*
  78.                 **      Object created OK?
  79.                 **/
  80.                 if ( WO_Window ) {
  81.                         /*
  82.                         **      Assign a key to the button.
  83.                         **/
  84.                         tmp = GadgetKey( WO_Window, GO_Quit,  "q" );
  85.                         /*
  86.                         **      OK?
  87.                         **/
  88.                         if ( tmp ) {
  89.                                 /*
  90.                                 **      try to open the window.
  91.                                 **/
  92.                                 if ( window = WindowOpen( WO_Window )) {
  93.                                         /*
  94.                                         **      Obtain it's wait mask.
  95.                                         **/
  96.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  97.                                         /*
  98.                                         **      Event loop...
  99.                                         **/
  100.                                         do {
  101.                                                 Wait( signal );
  102.                                                 /*
  103.                                                 **      Handle events.
  104.                                                 **/
  105.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  106.                                                         /*
  107.                                                         **      Evaluate return code.
  108.                                                         **/
  109.                                                         switch ( rc ) {
  110.  
  111.                                                                 case    WMHI_CLOSEWINDOW:
  112.                                                                 case    ID_QUIT:
  113.                                                                         running = FALSE;
  114.                                                                         break;
  115.  
  116.                                                                 case    ID_SCREENNAME:
  117.                                                                         /*
  118.                                                                         **      Obtain screen name.
  119.                                                                         **/
  120.                                                                         GetAttr( STRINGA_TextVal, GO_Name, &tmp );
  121.                                                                         /*
  122.                                                                         **      Save it.
  123.                                                                         **/
  124.                                                                         strcpy( name, ( UBYTE * )tmp );
  125.                                                                         /*
  126.                                                                         **      Close the window.
  127.                                                                         **/
  128.                                                                         WindowClose( WO_Window );
  129.                                                                         /*
  130.                                                                         **      Setup name.
  131.                                                                         **/
  132.                                                                         SetAttrs( WO_Window, WINDOW_PubScreenName, name, TAG_END );
  133.                                                                         /*
  134.                                                                         **      Re-open window.
  135.                                                                         **/
  136.                                                                         if ( window = WindowOpen( WO_Window )) {
  137.                                                                                 /*
  138.                                                                                 **      Re-set signal mask.
  139.                                                                                 **/
  140.                                                                                 signal = 0L;
  141.                                                                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  142.                                                                                 /*
  143.                                                                                 **      Show it in the gadget.
  144.                                                                                 **/
  145.                                                                                 SetGadgetAttrs(( struct Gadget * )GO_Name, window, NULL, STRINGA_TextVal, name, TAG_END );
  146.                                                                         } else {
  147.                                                                                 puts( "Can't re-open the window!" );
  148.                                                                                 goto bye;
  149.                                                                         }
  150.                                                                         break;
  151.                                                         }
  152.                                                 }
  153.                                         } while ( running );
  154.                                 } else
  155.                                         puts ( "Could not open the window" );
  156.