Merged in v 26.12.
[AROS-Contrib.git] / mui / classes / thebar / demo / demo3.c
blob0652d716db6c0af46f4e2d6575fe4635086e5e16
2 #include <proto/exec.h>
3 #include <proto/dos.h>
4 #include <proto/muimaster.h>
5 #include <proto/intuition.h>
6 #include <clib/alib_protos.h>
7 #include <mui/TheBar_mcc.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "SDI_compiler.h"
13 /***********************************************************************/
15 long __stack = 8192;
16 #if defined(__amigaos4__)
17 struct Library *IntuitionBase;
18 struct Library *MUIMasterBase;
19 struct IntuitionIFace *IIntuition;
20 struct MUIMasterIFace *IMUIMaster;
21 #else
22 struct IntuitionBase *IntuitionBase;
23 struct Library *MUIMasterBase;
24 #endif
26 /***********************************************************************/
28 #ifndef MAKE_ID
29 #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
30 #endif
32 /***********************************************************************/
34 #if defined(__amigaos4__)
35 #define CLOSELIB(lib, iface) { if((iface) && (lib)) { DropInterface((APTR)(iface)); iface = NULL; CloseLibrary((struct Library *)lib); lib = NULL; } }
36 #define GETINTERFACE(iname, iface, base) ((iface) = (APTR)GetInterface((struct Library *)(base), (iname), 1L, NULL))
37 #define DROPINTERFACE(iface) { DropInterface((APTR)(iface)); iface = NULL; }
38 #else
39 #define CLOSELIB(lib, iface) { if((lib)) { CloseLibrary((struct Library *)lib); lib = NULL; } }
40 #define GETINTERFACE(iname, iface, base) TRUE
41 #define DROPINTERFACE(iface) ((void)0)
42 #endif
44 /***********************************************************************/
46 const char * pics[] =
48 "Add",
49 "Clone",
50 "Edit",
51 "Remove",
52 "Search",
53 "Prefs",
54 "Login",
55 NULL
58 const char * spics[] =
60 "Add_S",
61 "Clone_S",
62 "Edit_S",
63 "Remove_S",
64 "Search_S",
65 "Prefs_S",
66 "Login_S",
67 NULL
70 const char * dpics[] =
72 "Add_G",
73 "Clone_G",
74 "Edit_G",
75 "Remove_G",
76 "Search_G",
77 "Prefs_G",
78 "Login_G",
79 NULL
82 struct MUIS_TheBar_Button buttons[] =
84 {0, 0, "_Get", "Get the disc.", 0, 0, NULL, NULL},
85 {1, 1, "Sa_ve", "Save the disc.", 0, 0, NULL, NULL},
86 {2, 2, "_Stop", "Stop the connection.", 0, 0, NULL, NULL},
87 {MUIV_TheBar_BarSpacer,-1, NULL, NULL, 0, 0, NULL, NULL},
88 {3, 3, "_Disc", "Disc page.", 0, 0, NULL, NULL},
89 {MUIV_TheBar_ButtonSpacer,-1, NULL, NULL, 0, 0, NULL, NULL},
90 {0, 4, "_Stop2", "Stop2 the connection.", 0, 0, NULL, NULL},
91 {4, 5, "_Matches", "Matches page.", MUIV_TheBar_ButtonFlag_Immediate|MUIV_TheBar_ButtonFlag_Selected, 1<<6, NULL, NULL},
92 {MUIV_TheBar_ImageSpacer,-1, NULL, NULL, 0, 0, NULL, NULL},
93 {5, 6, "_Edit", "Edit page.", MUIV_TheBar_ButtonFlag_Immediate, 1<<5, NULL, NULL},
94 {MUIV_TheBar_End, 0, NULL, NULL, 0, 0, NULL, NULL},
97 const char *rowss[] = {"0","1","2","3","6",NULL};
98 const char *colss[] = {"0","1","2","3","4","5","6",NULL};
99 const char *viewModes[] = {"Images and text","Images","Text",NULL};
100 const char *buttonsPoss[] = {"Left","Center","Right",NULL};
101 const char *labelPoss[] = {"Bottom","Top","Right","Left",NULL};
103 const char *usedClasses[] = {"TheBar.mcc",NULL};
106 main(UNUSED int argc,char **argv)
108 int res;
110 if ((IntuitionBase = (APTR)OpenLibrary("intuition.library",39)) != NULL &&
111 GETINTERFACE("main", IIntuition, IntuitionBase))
113 if ((MUIMasterBase = OpenLibrary("muimaster.library",19)) != NULL &&
114 GETINTERFACE("main", IMUIMaster, MUIMasterBase))
116 Object *app, *win, *mg, *sb, *viewMode, *buttonsPos, *labelPos, *borderless, *sunny,
117 *raised, *scaled, *keys, *bspacer, *fixed, *free, *update, *rows, *cols, *s4, *h0,
118 *rb, *rs, *ri;
120 if ((app = ApplicationObject,
121 MUIA_Application_Title, "TheBar Demo3",
122 MUIA_Application_Version, "$VER: TheBarDemo3 1.0 (24.6.2003)",
123 MUIA_Application_Copyright, "Copyright 2003 by Alfonso Ranieri",
124 MUIA_Application_Author, "Alfonso Ranieri <alforan@tin.it>",
125 MUIA_Application_Description, "TheBar example",
126 MUIA_Application_Base, "THEBAREXAMPLE",
127 MUIA_Application_UsedClasses, usedClasses,
129 SubWindow, win = WindowObject,
130 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
131 MUIA_Window_Title, "TheBar Demo3",
133 WindowContents, mg = VGroup,
135 Child, sb = TheBarObject,
136 MUIA_Group_Horiz, TRUE,
137 MUIA_TheBar_IgnoreAppearance, TRUE,
138 MUIA_TheBar_ViewMode, MUIV_TheBar_ViewMode_Gfx,
139 MUIA_TheBar_Buttons, buttons,
140 MUIA_TheBar_PicsDrawer, "PROGDIR:Pics",
141 MUIA_TheBar_Pics, pics,
142 MUIA_TheBar_SelPics, spics,
143 MUIA_TheBar_DisPics, dpics,
144 End,
146 Child, VGroup,
147 GroupFrameT("Appearance"),
148 Child, ColGroup(2),
149 Child, Label2("Rows"),
150 Child, HGroup,
151 Child, rows = MUI_MakeObject(MUIO_Radio,NULL,rowss),
152 Child, HSpace(0),
153 End,
154 Child, Label2("Columns"),
155 Child, HGroup,
156 Child, cols = MUI_MakeObject(MUIO_Radio,NULL,colss),
157 Child, HSpace(0),
158 End,
159 Child, Label2("ViewMode"),
160 Child, viewMode = MUI_MakeObject(MUIO_Cycle,NULL,viewModes),
161 Child, Label2("Buttons position"),
162 Child, buttonsPos = MUI_MakeObject(MUIO_Cycle,NULL,buttonsPoss),
163 Child, Label2("Label position"),
164 Child, labelPos = MUI_MakeObject(MUIO_Cycle,NULL,labelPoss),
165 End,
166 Child, ScrollgroupObject,
167 MUIA_Scrollgroup_FreeHoriz, FALSE,
168 MUIA_Scrollgroup_Contents, VirtgroupObject,
169 MUIA_Frame, MUIV_Frame_Virtual,
170 Child, HGroup,
171 Child, ColGroup(2),
172 Child, borderless = MUI_MakeObject(MUIO_Checkmark,NULL),
173 Child, LLabel1("Borderless"),
174 Child, sunny = MUI_MakeObject(MUIO_Checkmark,NULL),
175 Child, LLabel1("Sunny"),
176 Child, raised = MUI_MakeObject(MUIO_Checkmark,NULL),
177 Child, LLabel1("Raised"),
178 Child, scaled = MUI_MakeObject(MUIO_Checkmark,NULL),
179 Child, LLabel1("Scaled"),
180 Child, keys = MUI_MakeObject(MUIO_Checkmark,NULL),
181 Child, LLabel1("Enable keys"),
182 Child, bspacer = MUI_MakeObject(MUIO_Checkmark,NULL),
183 Child, LLabel1("Bar spacer"),
184 Child, fixed = MUI_MakeObject(MUIO_Checkmark,NULL),
185 Child, LLabel("Fixed"),
186 Child, free = MUI_MakeObject(MUIO_Checkmark,NULL),
187 Child, LLabel("Disable 0"),
188 Child, h0 = MUI_MakeObject(MUIO_Checkmark,NULL),
189 Child, LLabel("Hide 0"),
190 Child, s4 = MUI_MakeObject(MUIO_Checkmark,NULL),
191 Child, LLabel("Sleep 4"),
192 Child, RectangleObject, MUIA_FixHeightTxt,"a",End,
193 Child, RectangleObject, MUIA_FixHeightTxt,"a",End,
194 Child, rb = MUI_MakeObject(MUIO_Checkmark,NULL),
195 Child, LLabel("Remove Bars"),
196 Child, rs = MUI_MakeObject(MUIO_Checkmark,NULL),
197 Child, LLabel("Remove Spaces"),
198 Child, ri = MUI_MakeObject(MUIO_Checkmark,NULL),
199 Child, LLabel("Remove Images"),
200 End,
201 Child, HSpace(0),
202 End,
203 Child, VSpace(0),
204 End,
205 End,
206 Child, update = MUI_MakeObject(MUIO_Button,"_Update"),
207 End,
208 End,
209 End,
210 End) != NULL)
212 ULONG sigs = 0;
213 LONG id;
215 set(rows,MUIA_Group_Horiz,TRUE);
216 set(cols,MUIA_Group_Horiz,TRUE);
217 set(viewMode,MUIA_Cycle_Active,1);
218 set(s4,MUIA_Selected,TRUE);
219 DoMethod(sb,MUIM_TheBar_SetAttr,4,MUIA_TheBar_Attr_Sleep,TRUE);
221 DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
222 DoMethod(update,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,TAG_USER);
224 set(win,MUIA_Window_Open,TRUE);
226 while ((id = DoMethod(app,MUIM_Application_NewInput,&sigs))!=MUIV_Application_ReturnID_Quit)
228 if (id==(LONG)TAG_USER)
230 IPTR c = 0,
231 r = 0,
232 vm = 0,
233 bp = 0,
234 lp = 0,
235 br = 0,
236 su = 0,
237 ra = 0,
238 sc = 0,
239 k = 0,
240 bs = 0,
241 fi = 0,
242 fr = 0,
243 hl0 = 0,
244 sl4 = 0,
245 rbl = 0,
246 rsl = 0,
247 ril = 0,
248 rem = 0;
250 get(rows,MUIA_Radio_Active,&r);
251 if (r==4) r = 6;
252 get(cols,MUIA_Radio_Active,&c);
254 get(viewMode,MUIA_Cycle_Active,&vm);
255 get(buttonsPos,MUIA_Cycle_Active,&bp);
256 get(labelPos,MUIA_Cycle_Active,&lp);
258 get(borderless,MUIA_Selected,&br);
259 get(sunny,MUIA_Selected,&su);
260 get(raised,MUIA_Selected,&ra);
261 get(scaled,MUIA_Selected,&sc);
262 get(keys,MUIA_Selected,&k);
263 get(bspacer,MUIA_Selected,&bs);
264 get(fixed,MUIA_Selected,&fi);
265 get(free,MUIA_Selected,&fr);
267 get(h0,MUIA_Selected,&hl0);
268 get(s4,MUIA_Selected,&sl4);
270 get(rb,MUIA_Selected,&rbl);
271 get(rs,MUIA_Selected,&rsl);
272 get(ri,MUIA_Selected,&ril);
273 rem = 0;
274 if (rbl) rem |= MUIV_TheBar_RemoveSpacers_Bar;
275 if (rsl) rem |= MUIV_TheBar_RemoveSpacers_Button;
276 if (ril) rem |= MUIV_TheBar_RemoveSpacers_Image;
278 DoMethod(mg,MUIM_Group_InitChange);
279 DoMethod(sb,MUIM_Group_InitChange);
281 SetAttrs(sb,MUIA_TheBar_Columns, c,
282 MUIA_TheBar_Rows, r,
283 MUIA_TheBar_ViewMode, vm,
284 MUIA_TheBar_Borderless, br,
285 MUIA_TheBar_Sunny, su,
286 MUIA_TheBar_Raised, ra,
287 MUIA_TheBar_Scaled, sc,
288 MUIA_TheBar_EnableKeys, k,
289 MUIA_TheBar_BarSpacer, bs,
290 MUIA_TheBar_RemoveSpacers,rem,
291 MUIA_TheBar_LabelPos, lp,
292 TAG_DONE);
294 DoMethod(sb,MUIM_TheBar_SetAttr,0,MUIA_TheBar_Attr_Hide,hl0);
295 DoMethod(sb,MUIM_TheBar_SetAttr,4,MUIA_TheBar_Attr_Sleep,sl4);
297 DoMethod(sb,MUIM_TheBar_SetAttr,6,MUIA_TheBar_Attr_Disabled,fr);
299 DoMethod(sb,MUIM_Group_ExitChange);
300 DoMethod(mg,MUIM_Group_ExitChange);
303 if (sigs)
305 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
306 if (sigs & SIGBREAKF_CTRL_C) break;
310 MUI_DisposeObject(app);
312 res = RETURN_OK;
314 else
316 printf("%s: can't create application\n",argv[0]);
317 res = RETURN_FAIL;
320 CLOSELIB(MUIMasterBase, IMUIMaster);
322 else
324 printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
325 res = RETURN_ERROR;
328 CLOSELIB(IntuitionBase, IIntuition);
330 else
332 printf("%s: Can't open intuition.library ver 39 or higher\n",argv[0]);
333 res = RETURN_ERROR;
336 return res;
339 /***********************************************************************/