build git 2.17.1
[AROS-Contrib.git] / bgui / examples / CXDemo.c
blob93325f89dc234d683bbcf01416e36d64f45f5da8
1 /*
2 * @(#) $Header$
4 * CXDemo.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.1 2000/08/10 11:50:54 chodorowski
13 * Cleaned up and prettyfied the GUIs a bit.
15 * Revision 42.0 2000/05/09 22:19:29 mlemos
16 * Bumped to revision 42.0 before handing BGUI to AROS team
18 * Revision 41.11 2000/05/09 20:33:19 mlemos
19 * Bumped to revision 41.11
21 * Revision 1.2 2000/05/09 19:58:40 mlemos
22 * Merged with the branch Manuel_Lemos_fixes.
24 * Revision 1.1.2.1 1998/02/28 17:45:09 mlemos
25 * Ian sources
30 /* Execute me to compile with DICE V3.0.
31 dcc CXDemo.c -proto -mi -ms -mRR -lbgui
32 quit
35 #include "DemoCode.h"
38 ** Key ID.
39 **/
40 #define CX_F1_PRESSED 1L
43 ** Gadget ID's.
44 **/
45 #define ID_HIDE 1L
46 #define ID_QUIT 2L
49 ** Information text.
50 **/
51 UBYTE *InfoTxt = ISEQ_C ISEQ_B ISEQ_HIGHLIGHT
52 "\33sCxDemo\n\n" ISEQ_TEXT ISEQ_N
53 "This is a small \"do-nothing\" example of how\n"
54 "to use the BGUI commodity class.\n"
55 "In this example F1 is the Hotkey used to\n"
56 "signal the broker to open the window.";
58 VOID StartDemo( void )
60 Object *CM_Broker, *WN_Window, *GA_Hide, *GA_Quit;
61 ULONG sigrec, type, id, rc;
62 IPTR signal = 0L, winsig = 0L;
63 BOOL running = TRUE;
66 ** Setup a commodity object.
67 **/
68 CM_Broker = CommodityObject,
69 COMM_Name, "CxDemo",
70 COMM_Title, "Simple BGUI broker.",
71 COMM_Description, "Does not do anything useful.",
72 COMM_ShowHide, TRUE,
73 EndObject;
76 ** Object OK?
77 **/
78 if ( CM_Broker )
81 ** Create a small window.
82 **/
83 WN_Window = WindowObject,
84 WINDOW_Title, "CxDemo",
85 WINDOW_RMBTrap, TRUE,
86 WINDOW_SizeGadget, FALSE, /* No use in this window. */
87 WINDOW_AutoAspect, TRUE,
88 WINDOW_AutoKeyLabel, TRUE,
89 WINDOW_MasterGroup,
90 VGroupObject, HOffset(6), VOffset(6), Spacing(6), GROUP_BackFill, SHINE_RASTER,
91 StartMember,
92 InfoObject, ButtonFrame,
93 FRM_Flags, FRF_RECESSED,
94 INFO_TextFormat, InfoTxt,
95 INFO_FixTextWidth, TRUE,
96 INFO_MinLines, 6,
97 EndObject,
98 EndMember,
99 StartMember,
100 HGroupObject,
101 StartMember, GA_Hide = PrefButton( "_Hide", ID_HIDE ), EndMember,
102 VarSpace(DEFAULT_WEIGHT),
103 StartMember, GA_Quit = PrefButton( "_Quit", ID_QUIT ), EndMember,
104 EndObject, FixMinHeight,
105 EndMember,
106 EndObject,
107 EndObject;
110 ** Window OK?
112 if ( WN_Window )
115 ** Add F1 as hotkey.
117 if ( AddHotkey( CM_Broker, "f1", CX_F1_PRESSED, 0L ))
120 ** Obtain broker signal mask.
122 GetAttr( COMM_SigMask, CM_Broker, &signal );
124 ** Activate the broker.
126 EnableBroker( CM_Broker );
128 ** Open up the window.
130 if ( WindowOpen( WN_Window ))
133 ** Obtain window sigmask.
135 GetAttr( WINDOW_SigMask, WN_Window, &winsig );
137 ** Wait for messages.
139 do {
140 sigrec = Wait( signal | winsig | SIGBREAKF_CTRL_C );
142 ** Broker signal?
144 if ( sigrec & signal )
147 ** Obtain the messages from the broker.
149 while ( MsgInfo( CM_Broker, &type, &id, NULL ) != CMMI_NOMORE )
152 ** Evaluate message.
154 switch ( type ) {
156 case CXM_IEVENT:
157 switch ( id ) {
159 case CX_F1_PRESSED:
160 goto openUp;
162 break;
164 case CXM_COMMAND:
165 switch ( id ) {
167 case CXCMD_KILL:
168 Tell( "bye bye\n" );
169 running = FALSE;
170 break;
172 case CXCMD_DISABLE:
173 Tell( "broker disabled\n" );
174 DisableBroker( CM_Broker );
175 break;
177 case CXCMD_ENABLE:
178 Tell( "broker enabled\n" );
179 EnableBroker( CM_Broker );
180 break;
182 case CXCMD_UNIQUE:
183 case CXCMD_APPEAR:
184 openUp:
185 if ( WindowOpen( WN_Window ))
186 GetAttr( WINDOW_SigMask, WN_Window, &winsig );
187 break;
189 case CXCMD_DISAPPEAR:
190 WindowClose( WN_Window );
191 winsig = 0L;
192 break;
194 break;
200 ** Window signal?
202 if ( sigrec & winsig ) {
203 while ( WN_Window && (( rc = HandleEvent( WN_Window )) != WMHI_NOMORE )) {
204 switch ( rc ) {
206 case ID_HIDE:
207 case WMHI_CLOSEWINDOW:
209 ** Hide the window.
211 WindowClose( WN_Window );
212 winsig = 0L;
213 break;
215 case ID_QUIT:
217 ** The end.
219 Tell( "bye bye\n" );
220 running = FALSE;
221 break;
227 ** CTRL+C?
229 if ( sigrec & SIGBREAKF_CTRL_C ) {
230 Tell( "bye bye\n" );
231 running = FALSE;
233 } while ( running );
234 } else
235 Tell( "unable to open the window\n" );
236 } else
237 Tell( "unable to add the hotkey\n" );
238 DisposeObject( WN_Window );
239 } else
240 Tell( "unable to create a window object\n" );
241 DisposeObject( CM_Broker );
242 } else
243 Tell( "unable to create a commodity object\n" );