Replaced System by SYS because on "native" the volume name of the system partition...
[AROS-Contrib.git] / bgui / examples / StringHook.c
blob31fe05775bc44882229f725c8254fae50d799b03
1 /*
2 * @(#) $Header$
4 * StringHook.c
6 * (C) Copyright 1998 Manuel Lemos.
7 * (C) Copyright 1995 Jaba Development.
8 * (C) Copyright 1995 Jan van den Baard.
9 * All Rights Reserved.
11 * $Log$
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
28 * Ian sources
33 /* Execute me to compile with DICE V3.0
34 dcc StringHook.c -proto -mi -ms -mRR -lbgui
35 quit
38 #include "DemoCode.h"
40 #include <ctype.h>
43 ** Object ID's.
44 **/
45 #define ID_QUIT 1
48 ** Info text.
49 **/
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.
59 **/
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))
66 ULONG rc = ~0;
68 switch ( *msg ) {
70 case SGH_KEY:
72 ** Only allow for hexadecimal characters and convert
73 ** lowercase to uppercase.
74 **/
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;
79 } else {
80 sgw->WorkBuffer[ sgw->BufferPos - 1 ] = toupper( sgw->Code );
83 break;
85 case SGH_CLICK:
87 ** Convert the character under the
88 ** cursor to 0.
89 **/
90 if ( sgw->BufferPos < sgw->NumChars )
91 sgw->WorkBuffer[ sgw->BufferPos ] = '0';
92 break;
94 default:
95 rc = 0L;
96 break;
98 return( rc );
100 REGFUNC_END
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;
115 ULONG signal, rc;
116 BOOL running = TRUE;
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,
127 WINDOW_MasterGroup,
128 VGroupObject, NormalHOffset, NormalVOffset, NormalSpacing,
129 GROUP_BackFill, FILL_RASTER,
130 StartMember,
131 InfoFixed( NULL, WinInfo, NULL, 5 ),
132 EndMember,
133 StartMember,
134 HGroupObject, HOffset( 4 ), VOffset( 4 ), FRM_Type, FRTYPE_BUTTON, FRM_Recessed, TRUE,
135 StartMember,
136 StringObject,
137 LAB_Label, "Only HEX characters:",
138 LAB_Style, FSF_BOLD,
139 FuzzRidgeFrame,
140 STRINGA_MaxChars, 256,
141 STRINGA_EditHook, &HexHook,
142 EndObject,
143 EndMember,
144 EndObject,
145 EndMember,
146 StartMember,
147 HGroupObject,
148 VarSpace( 50 ),
149 StartMember, GO_Quit = FuzzButton( "_Quit", ID_QUIT ), EndMember,
150 VarSpace( 50 ),
151 EndObject, FixMinHeight,
152 EndMember,
153 EndObject,
154 EndObject;
157 ** Object created OK?
159 if ( WO_Window )
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 );
171 ** Event loop...
173 do {
174 Wait( signal );
176 ** Handle events.
178 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
181 ** Evaluate return code.
183 switch ( rc )
185 case WMHI_CLOSEWINDOW:
186 case ID_QUIT:
187 running = FALSE;
188 break;
191 } while ( running );
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" );