6 * (C) Copyright 1998 Manuel Lemos.
7 * (C) Copyright 1995 Jaba Development.
8 * (C) Copyright 1995 Jan van den Baard.
12 * Revision 42.2 2004/06/17 07:38:47 chodorowski
13 * Added missing REGFUNC_END.
15 * Revision 42.1 2000/05/15 19:29:50 stegerg
16 * replacements for REG macro.
18 * Revision 42.0 2000/05/09 22:20:05 mlemos
19 * Bumped to revision 42.0 before handing BGUI to AROS team
21 * Revision 41.11 2000/05/09 20:33:55 mlemos
22 * Bumped to revision 41.11
24 * Revision 1.2 2000/05/09 19:59:10 mlemos
25 * Merged with the branch Manuel_Lemos_fixes.
27 * Revision 1.1.2.1 1998/02/28 17:45:42 mlemos
33 /* Execute me to compile with DICE V3.0
34 dcc StringHook.c -proto -mi -ms -mRR -lbgui
50 UBYTE
*WinInfo
= ISEQ_C
"This demo shows you how to include a\n"
51 "string object edit hook. The string object\n"
52 "has a edit hook installed which only allows\n"
53 "you to enter hexadecimal characters. It will\n"
54 "also convert the character you click on to 0.";
57 ** String object edit hook. Copied from the
58 ** RKM-Manual Libraries. Page 162-166.
60 //SAVEDS ASM ULONG HexHookFunc( REG(a0) struct Hook *hook, REG(a2) struct SGWork *sgw, REG(a1) ULONG *msg )
61 SAVEDS ASM
REGFUNC3(ULONG
, HexHookFunc
,
62 REGPARAM(A0
, struct Hook
*, hook
),
63 REGPARAM(A2
, struct SGWork
*, sgw
),
64 REGPARAM(A1
, ULONG
*, msg
))
72 ** Only allow for hexadecimal characters and convert
73 ** lowercase to uppercase.
75 if ( sgw
->EditOp
== EO_REPLACECHAR
|| sgw
->EditOp
== EO_INSERTCHAR
) {
76 if ( ! isxdigit( sgw
->Code
)) {
77 sgw
->Actions
|= SGA_BEEP
;
78 sgw
->Actions
&= ~SGA_USE
;
80 sgw
->WorkBuffer
[ sgw
->BufferPos
- 1 ] = toupper( sgw
->Code
);
87 ** Convert the character under the
90 if ( sgw
->BufferPos
< sgw
->NumChars
)
91 sgw
->WorkBuffer
[ sgw
->BufferPos
] = '0';
103 ** Uncomment the below typedef if your compiler
104 ** complains about it.
107 /* typedef ULONG (*HOOKFUNC)(); */
109 struct Hook HexHook
= { NULL
, NULL
, (HOOKFUNC
)HexHookFunc
, NULL
, NULL
};
111 VOID
StartDemo( void )
113 struct Window
*window
;
114 Object
*WO_Window
, *GO_Quit
;
119 ** Create the window object.
121 WO_Window
= WindowObject
,
122 WINDOW_Title
, "String Edit Hook Demo",
123 WINDOW_AutoAspect
, TRUE
,
124 WINDOW_LockHeight
, TRUE
,
125 WINDOW_RMBTrap
, TRUE
,
126 WINDOW_AutoKeyLabel
, TRUE
,
128 VGroupObject
, NormalHOffset
, NormalVOffset
, NormalSpacing
,
129 GROUP_BackFill
, FILL_RASTER
,
131 InfoFixed( NULL
, WinInfo
, NULL
, 5 ),
134 HGroupObject
, HOffset( 4 ), VOffset( 4 ), FRM_Type
, FRTYPE_BUTTON
, FRM_Recessed
, TRUE
,
137 LAB_Label
, "Only HEX characters:",
140 STRINGA_MaxChars
, 256,
141 STRINGA_EditHook
, &HexHook
,
149 StartMember
, GO_Quit
= FuzzButton( "_Quit", ID_QUIT
), EndMember
,
151 EndObject
, FixMinHeight
,
157 ** Object created OK?
162 ** try to open the window.
164 if ( window
= WindowOpen( WO_Window
))
167 ** Obtain it's wait mask.
169 GetAttr( WINDOW_SigMask
, WO_Window
, &signal
);
178 while (( rc
= HandleEvent( WO_Window
)) != WMHI_NOMORE
)
181 ** Evaluate return code.
185 case WMHI_CLOSEWINDOW
:
192 } else Tell( "Could not open the window\n" );
194 ** Disposing of the window object will
195 ** also close the window if it is
196 ** already opened and it will dispose of
197 ** all objects attached to it.
199 DisposeObject( WO_Window
);
200 } else Tell( "Could not create the window object\n" );