icon.library: Implement LayoutIconA()
[AROS.git] / workbench / demos / modelclassdemo.c
blob47f552edd163fe3f78961448de604b7c455edbf7
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>
20 #include <proto/alib.h>
21 #include <proto/exec.h>
22 #include <proto/intuition.h>
24 #include <stdio.h>
25 #include <string.h>
27 /**********************************************************************************************/
29 struct IntuitionBase *IntuitionBase;
30 static struct Window *win;
31 static struct Gadget *gad1, *gad2, *gad3, *gad4;
32 static Object *model, *ic1;
33 static BOOL gadgets_added_to_model = FALSE;
35 /**********************************************************************************************/
37 static struct TagItem prop_to_idcmp[] =
39 {PGA_Top , ICSPECIAL_CODE },
40 {TAG_DONE }
43 static struct TagItem prop_to_string[] =
45 {PGA_Top , STRINGA_LongVal },
46 {TAG_DONE }
50 /**********************************************************************************************/
52 static void cleanup(char *msg)
54 if (msg) printf("modelclass: %s\n",msg);
56 if (win) RemoveGList(win, gad1, -1);
57 if (gad1) DisposeObject((Object *)gad1);
58 if (gad3) DisposeObject((Object *)gad3);
60 if (!gadgets_added_to_model)
62 if (gad2) DisposeObject((Object *)gad2);
63 if (gad4) DisposeObject((Object *)gad4);
64 if (ic1) DisposeObject((Object *)ic1);
67 if (model) DisposeObject(model);
69 CloseWindow(win);
71 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
75 /**********************************************************************************************/
77 static void openlibs(void)
79 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39);
80 if (!IntuitionBase) cleanup("can't open intuition.library V39!");
83 /**********************************************************************************************/
85 static void makegadgets(void)
87 model = NewObject(0, MODELCLASS, ICA_TARGET, ICTARGET_IDCMP,
88 ICA_MAP, (IPTR)prop_to_idcmp,
89 TAG_DONE);
91 if (!model) cleanup("can't create modelclass object!");
93 ic1 = NewObject(0, ICCLASS, TAG_DONE);
95 if (!ic1) cleanup("can't create icclass object!");
97 gad1 = (struct Gadget *)NewObject(0, PROPGCLASS, GA_Left, 10,
98 GA_Top, 40,
99 GA_Width, 20,
100 GA_Height, 100,
101 PGA_Freedom, FREEVERT,
102 PGA_Top, 0,
103 PGA_Total, 1000,
104 PGA_Visible, 100,
105 ICA_TARGET, (IPTR)model,
106 TAG_DONE);
107 if (!gad1) cleanup("can't create gadget 1!");
109 gad2 = (struct Gadget *)NewObject(0, PROPGCLASS, GA_Left, 40,
110 GA_Top, 40,
111 GA_Width, 20,
112 GA_Height, 200,
113 PGA_Freedom, FREEVERT,
114 PGA_Top, 0,
115 PGA_Total, 1000,
116 PGA_Visible, 100,
117 GA_Previous, (IPTR)gad1,
118 TAG_DONE);
119 if (!gad2) cleanup("can't create gadget 2!");
121 gad3 = (struct Gadget *)NewObject(0, STRGCLASS, GA_Left, 80,
122 GA_Top, 40,
123 GA_Width, 100,
124 GA_Height, 20,
125 STRINGA_LongVal, 0,
126 GA_Previous, (IPTR)gad2,
127 TAG_DONE);
129 if (!gad3) cleanup("can't create gadget 3!");
131 gad4 = (struct Gadget *)NewObject(0, PROPGCLASS, GA_Left, 80,
132 GA_Top, 80,
133 GA_Width, 150,
134 GA_Height, 20,
135 PGA_Freedom, FREEHORIZ,
136 PGA_Top, 0,
137 PGA_Total, 1000,
138 PGA_Visible, 100,
139 GA_Previous, (IPTR)gad3,
140 TAG_DONE);
141 if (!gad4) cleanup("can't create gadget 4!");
143 SetAttrs(ic1, ICA_TARGET, (IPTR) gad3,
144 ICA_MAP, (IPTR) prop_to_string,
145 TAG_DONE);
147 DoMethod(model, OM_ADDMEMBER, (IPTR) gad2);
148 DoMethod(model, OM_ADDMEMBER, (IPTR) ic1);
149 DoMethod(model, OM_ADDMEMBER, (IPTR) gad4);
151 gadgets_added_to_model = TRUE;
155 /**********************************************************************************************/
157 static void makewin(void)
159 win = OpenWindowTags(0, WA_Title , (IPTR) "Modelclass demo: Use first prop gadget!",
160 WA_Left , 20000,
161 WA_Top , 20,
162 WA_Width , 400,
163 WA_Height , 300,
164 WA_AutoAdjust , TRUE,
165 WA_CloseGadget , TRUE,
166 WA_DepthGadget , TRUE,
167 WA_DragBar , TRUE,
168 WA_IDCMP , IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE,
169 WA_Activate , TRUE,
170 WA_Gadgets , (IPTR) gad1,
171 TAG_DONE
174 if (!win) cleanup("can't open window!");
178 /**********************************************************************************************/
180 static void handleall(void)
182 struct IntuiMessage *msg;
183 BOOL quitme = FALSE;
185 while(!quitme)
187 WaitPort(win->UserPort);
188 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
190 switch(msg->Class)
192 case IDCMP_CLOSEWINDOW:
193 quitme = TRUE;
194 break;
196 case IDCMP_IDCMPUPDATE:
197 printf("IDCMP_IDCMPUPDATE: code = %d\n", msg->Code);
198 break;
200 } /* switch msg->Class */
202 ReplyMsg((struct Message *)msg);
204 } /* while msg = getmsg */
206 } /* while (!quitme) */
209 /**********************************************************************************************/
211 int main(void)
213 openlibs();
214 makegadgets();
215 makewin();
216 handleall();
217 cleanup(0);
218 return 0;
222 /**********************************************************************************************/