home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / bgui / examples / source / stringhook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.7 KB  |  182 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/StringHook.c,v 1.1.2.1 1998/02/28 17:45:42 mlemos Exp $
  3.  *
  4.  * StringHook.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: StringHook.c,v $
  12.  * Revision 1.1.2.1  1998/02/28 17:45:42  mlemos
  13.  * Ian sources
  14.  *
  15.  *
  16.  */
  17.  
  18. /* Execute me to compile with DICE V3.0
  19. dcc StringHook.c -proto -mi -ms -mRR -lbgui
  20. quit
  21. */
  22.  
  23. #include "DemoCode.h"
  24.  
  25. #include <ctype.h>
  26.  
  27. /*
  28. **      Object ID's.
  29. **/
  30. #define ID_QUIT                 1
  31.  
  32. /*
  33. **      Info text.
  34. **/
  35. UBYTE  *WinInfo = ISEQ_C "This demo shows you how to include a\n"
  36.                   "string object edit hook. The string object\n"
  37.                   "has a edit hook installed which only allows\n"
  38.                   "you to enter hexadecimal characters. It will\n"
  39.                   "also convert the character you click on to 0.";
  40.  
  41. /*
  42. **      String object edit hook. Copied from the
  43. **      RKM-Manual Libraries. Page 162-166.
  44. **/
  45. SAVEDS ASM ULONG HexHookFunc( REG(a0) struct Hook *hook, REG(a2) struct SGWork *sgw, REG(a1) ULONG *msg )
  46. {
  47.         ULONG           rc = ~0;
  48.  
  49.         switch ( *msg ) {
  50.  
  51.                 case    SGH_KEY:
  52.                         /*
  53.                         **      Only allow for hexadecimal characters and convert
  54.                         **      lowercase to uppercase.
  55.                         **/
  56.                         if ( sgw->EditOp == EO_REPLACECHAR || sgw->EditOp == EO_INSERTCHAR ) {
  57.                                 if ( ! isxdigit( sgw->Code )) {
  58.                                         sgw->Actions |= SGA_BEEP;
  59.                                         sgw->Actions &= ~SGA_USE;
  60.                                 } else {
  61.                                         sgw->WorkBuffer[ sgw->BufferPos - 1 ] = toupper( sgw->Code );
  62.                                 }
  63.                         }
  64.                         break;
  65.  
  66.                 case    SGH_CLICK:
  67.                         /*
  68.                         **      Convert the character under the
  69.                         **      cursor to 0.
  70.                         **/
  71.                         if ( sgw->BufferPos < sgw->NumChars )
  72.                                 sgw->WorkBuffer[ sgw->BufferPos ] = '0';
  73.                         break;
  74.  
  75.                 default:
  76.                         rc = 0L;
  77.                         break;
  78.         }
  79.         return( rc );
  80. }
  81.  
  82. /*
  83. **      Uncomment the below typedef if your compiler
  84. **      complains about it.
  85. **/
  86.  
  87. /* typedef ULONG (*HOOKFUNC)(); */
  88.  
  89. struct Hook HexHook = { NULL, NULL, (HOOKFUNC)HexHookFunc, NULL, NULL };
  90.  
  91. VOID StartDemo( void )
  92. {
  93.     struct Window           *window;
  94.     Object                  *WO_Window, *GO_Quit;
  95.     ULONG                    signal, rc;
  96.     BOOL                     running = TRUE;
  97.  
  98.     /*
  99.     **      Create the window object.
  100.     **/
  101.     WO_Window = WindowObject,
  102.         WINDOW_Title,           "String Edit Hook Demo",
  103.         WINDOW_AutoAspect,      TRUE,
  104.         WINDOW_LockHeight,      TRUE,
  105.         WINDOW_RMBTrap,         TRUE,
  106.         WINDOW_AutoKeyLabel,        TRUE,
  107.         WINDOW_MasterGroup,
  108.             VGroupObject, NormalHOffset, NormalVOffset, NormalSpacing,
  109.                 GROUP_BackFill, FILL_RASTER,
  110.                 StartMember,
  111.                     InfoFixed( NULL, WinInfo, NULL, 5 ),
  112.                 EndMember,
  113.                 StartMember,
  114.                     HGroupObject, HOffset( 4 ), VOffset( 4 ), FRM_Type, FRTYPE_BUTTON, FRM_Recessed, TRUE,
  115.                         StartMember,
  116.                             StringObject,
  117.                                 LAB_Label,              "Only HEX characters:",
  118.                                 LAB_Style,              FSF_BOLD,
  119.                                 FuzzRidgeFrame,
  120.                                 STRINGA_MaxChars,       256,
  121.                                 STRINGA_EditHook,       &HexHook,
  122.                             EndObject,
  123.                         EndMember,
  124.                     EndObject,
  125.                 EndMember,
  126.                 StartMember,
  127.                     HGroupObject,
  128.                         VarSpace( 50 ),
  129.                             StartMember, GO_Quit  = FuzzButton( "_Quit",  ID_QUIT  ), EndMember,
  130.                         VarSpace( 50 ),
  131.                     EndObject, FixMinHeight,
  132.                 EndMember,
  133.             EndObject,
  134.         EndObject;
  135.  
  136.     /*
  137.     **      Object created OK?
  138.     **/
  139.     if ( WO_Window )
  140.     {
  141.         /*
  142.         **      try to open the window.
  143.         **/
  144.         if ( window = WindowOpen( WO_Window ))
  145.         {
  146.             /*
  147.             **      Obtain it's wait mask.
  148.             **/
  149.             GetAttr( WINDOW_SigMask, WO_Window, &signal );
  150.             /*
  151.             **      Event loop...
  152.             **/
  153.             do {
  154.                 Wait( signal );
  155.                 /*
  156.                 **      Handle events.
  157.                 **/
  158.                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
  159.                 {
  160.                     /*
  161.                     **      Evaluate return code.
  162.                     **/
  163.                     switch ( rc )
  164.                     {
  165.                     case WMHI_CLOSEWINDOW:
  166.                     case ID_QUIT:
  167.                         running = FALSE;
  168.                         break;
  169.                     }
  170.                 }
  171.             }    while ( running );
  172.         }    else Tell( "Could not open the window\n" );
  173.         /*
  174.         **      Disposing of the window object will
  175.         **      also close the window if it is
  176.         **      already opened and it will dispose of
  177.         **      all objects attached to it.
  178.         **/
  179.         DisposeObject( WO_Window );
  180.     }    else Tell( "Could not create the window object\n" );
  181. }
  182.