added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / demos / modelclassdemo.c
blob6422dddbcc996f1c4a2e8475f5c5a5e26de86741
1 /**********************************************************************************************/
3 /* modelclassdemo:
5 connect one prop gadget with two other prop gadgets,
6 one string gadget, and the IDCMP.
8 This interconnection is done with modelclass and icclass objects
12 /**********************************************************************************************/
14 #include <intuition/intuition.h>
15 #include <intuition/classes.h>
16 #include <intuition/classusr.h>
17 #include <intuition/gadgetclass.h>
18 #include <intuition/icclass.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
22 #include <stdio.h>
23 #include <string.h>
25 /**********************************************************************************************/
27 struct IntuitionBase *IntuitionBase;
28 static struct Window *win;
29 static struct Gadget *gad1, *gad2, *gad3, *gad4;
30 static Object *model, *ic1;
31 static BOOL gadgets_added_to_model = FALSE;
33 /**********************************************************************************************/
35 static struct TagItem prop_to_idcmp[] =
37 {PGA_Top , ICSPECIAL_CODE },
38 {TAG_DONE }
41 static struct TagItem prop_to_string[] =
43 {PGA_Top , STRINGA_LongVal },
44 {TAG_DONE }
48 /**********************************************************************************************/
50 static void cleanup(char *msg)
52 if (msg) printf("modelclass: %s\n",msg);
54 if (win) RemoveGList(win, gad1, -1);
55 if (gad1) DisposeObject((Object *)gad1);
56 if (gad3) DisposeObject((Object *)gad3);
58 if (!gadgets_added_to_model)
60 if (gad2) DisposeObject((Object *)gad2);
61 if (gad4) DisposeObject((Object *)gad4);
62 if (ic1) DisposeObject((Object *)ic1);
65 if (model) DisposeObject(model);
67 CloseWindow(win);
69 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
73 /**********************************************************************************************/
75 static void openlibs(void)
77 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39);
78 if (!IntuitionBase) cleanup("can't open intuition.library V39!");
81 /**********************************************************************************************/
83 static void makegadgets(void)
85 model = NewObject(0, MODELCLASS, ICA_TARGET, ICTARGET_IDCMP,
86 ICA_MAP, (IPTR)prop_to_idcmp,
87 TAG_DONE);
89 if (!model) cleanup("can't create modelclass object!");
91 ic1 = NewObject(0, ICCLASS, TAG_DONE);
93 if (!ic1) cleanup("can't create icclass object!");
95 gad1 = (struct Gadget *)NewObject(0, PROPGCLASS, GA_Left, 10,
96 GA_Top, 40,
97 GA_Width, 20,
98 GA_Height, 100,
99 PGA_Freedom, FREEVERT,
100 PGA_Top, 0,
101 PGA_Total, 1000,
102 PGA_Visible, 100,
103 ICA_TARGET, (IPTR)model,
104 TAG_DONE);
105 if (!gad1) cleanup("can't create gadget 1!");
107 gad2 = (struct Gadget *)NewObject(0, PROPGCLASS, GA_Left, 40,
108 GA_Top, 40,
109 GA_Width, 20,
110 GA_Height, 200,
111 PGA_Freedom, FREEVERT,
112 PGA_Top, 0,
113 PGA_Total, 1000,
114 PGA_Visible, 100,
115 GA_Previous, (IPTR)gad1,
116 TAG_DONE);
117 if (!gad2) cleanup("can't create gadget 2!");
119 gad3 = (struct Gadget *)NewObject(0, STRGCLASS, GA_Left, 80,
120 GA_Top, 40,
121 GA_Width, 100,
122 GA_Height, 20,
123 STRINGA_LongVal, 0,
124 GA_Previous, (IPTR)gad2,
125 TAG_DONE);
127 if (!gad3) cleanup("can't create gadget 3!");
129 gad4 = (struct Gadget *)NewObject(0, PROPGCLASS, GA_Left, 80,
130 GA_Top, 80,
131 GA_Width, 150,
132 GA_Height, 20,
133 PGA_Freedom, FREEHORIZ,
134 PGA_Top, 0,
135 PGA_Total, 1000,
136 PGA_Visible, 100,
137 GA_Previous, (IPTR)gad3,
138 TAG_DONE);
139 if (!gad4) cleanup("can't create gadget 4!");
141 SetAttrs(ic1, ICA_TARGET, (IPTR) gad3,
142 ICA_MAP, (IPTR) prop_to_string,
143 TAG_DONE);
145 DoMethod(model, OM_ADDMEMBER, (IPTR) gad2);
146 DoMethod(model, OM_ADDMEMBER, (IPTR) ic1);
147 DoMethod(model, OM_ADDMEMBER, (IPTR) gad4);
149 gadgets_added_to_model = TRUE;
153 /**********************************************************************************************/
155 static void makewin(void)
157 win = OpenWindowTags(0, WA_Title , (IPTR) "Modelclass demo: Use first prop gadget!",
158 WA_Left , 20000,
159 WA_Top , 20,
160 WA_Width , 400,
161 WA_Height , 300,
162 WA_AutoAdjust , TRUE,
163 WA_CloseGadget , TRUE,
164 WA_DepthGadget , TRUE,
165 WA_DragBar , TRUE,
166 WA_IDCMP , IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE,
167 WA_Activate , TRUE,
168 WA_Gadgets , (IPTR) gad1,
169 TAG_DONE
172 if (!win) cleanup("can't open window!");
176 /**********************************************************************************************/
178 static void handleall(void)
180 struct IntuiMessage *msg;
181 BOOL quitme = FALSE;
183 while(!quitme)
185 WaitPort(win->UserPort);
186 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
188 switch(msg->Class)
190 case IDCMP_CLOSEWINDOW:
191 quitme = TRUE;
192 break;
194 case IDCMP_IDCMPUPDATE:
195 printf("IDCMP_IDCMPUPDATE: code = %d\n", msg->Code);
196 break;
198 } /* switch msg->Class */
200 ReplyMsg((struct Message *)msg);
202 } /* while msg = getmsg */
204 } /* while (!quitme) */
207 /**********************************************************************************************/
209 int main(void)
211 openlibs();
212 makegadgets();
213 makewin();
214 handleall();
215 cleanup(0);
216 return 0;
220 /**********************************************************************************************/