Merged in v 26.12.
[AROS-Contrib.git] / mui / classes / thebar / mcc / TheBar-Test.c
blobd02b11cfa2c0259078132bd979323032f17715d2
1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2013 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
19 $Id$
21 ***************************************************************************/
23 #include "class.h"
24 #include "private.h"
25 #include "debug.h"
26 #include <stdio.h>
28 /******************************************************************************/
30 #ifndef MAKE_ID
31 #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
32 #endif
34 /******************************************************************************/
36 #if defined(__amigaos4__)
37 struct Library *GfxBase = NULL;
38 struct Library *IntuitionBase = NULL;
39 struct Library *MUIMasterBase = NULL;
40 struct Library *CyberGfxBase = NULL;
41 struct Library *DataTypesBase = NULL;
42 struct Library *PictureDTBase = NULL;
44 struct GraphicsIFace *IGraphics = NULL;
45 struct IntuitionIFace *IIntuition = NULL;
46 struct MUIMasterIFace *IMUIMaster = NULL;
47 struct CyberGfxIFace *ICyberGfx = NULL;
48 struct DataTypesIFace *IDataTypes = NULL;
49 #elif defined(__MORPHOS__)
50 struct GfxBase *GfxBase = NULL;
51 struct IntuitionBase *IntuitionBase = NULL;
52 struct Library *MUIMasterBase = NULL;
53 struct Library *UtilityBase = NULL;
54 struct Library *CyberGfxBase = NULL;
55 struct Library *DataTypesBase = NULL;
56 struct Library *PictureDTBase = NULL;
57 #else
58 struct GfxBase *GfxBase = NULL;
59 struct IntuitionBase *IntuitionBase = NULL;
60 struct Library *MUIMasterBase = NULL;
61 #if defined(__AROS__)
62 struct UtilityBase *UtilityBase = NULL;
63 #else
64 struct Library *UtilityBase = NULL;
65 #endif
66 struct Library *CyberGfxBase = NULL;
67 struct Library *DataTypesBase = NULL;
68 struct Library *PictureDTBase = NULL;
69 #endif
71 DISPATCHERPROTO(_Dispatcher);
72 struct MUI_CustomClass *lib_thisClass = NULL;
73 struct MUI_CustomClass *lib_spacerClass = NULL;
74 struct MUI_CustomClass *lib_dragBarClass = NULL;
75 ULONG lib_flags = 0;
77 /******************************************************************************/
79 void closeAll(void)
81 D(DBF_STARTUP,"cleaning up thisClass...");
82 if (lib_thisClass) MUI_DeleteCustomClass(lib_thisClass);
83 D(DBF_STARTUP,"cleaning up dragBarClass...");
84 if (lib_dragBarClass) MUI_DeleteCustomClass(lib_dragBarClass);
85 D(DBF_STARTUP,"cleaning up spacerClass...");
86 if (lib_spacerClass) MUI_DeleteCustomClass(lib_spacerClass);
88 D(DBF_STARTUP,"cleaning up MUIMasterBase...");
89 if (MUIMasterBase)
91 DROPINTERFACE(IMUIMaster);
92 CloseLibrary(MUIMasterBase);
95 D(DBF_STARTUP,"cleaning up VyberGfxBase...");
96 if (CyberGfxBase)
98 DROPINTERFACE(ICyberGfx);
99 CloseLibrary(CyberGfxBase);
102 D(DBF_STARTUP,"cleaning up DataTypesBase...");
103 if (DataTypesBase)
105 DROPINTERFACE(IDataTypes);
106 CloseLibrary(DataTypesBase);
109 D(DBF_STARTUP,"cleaning up UtilityBase...");
110 if (UtilityBase)
112 DROPINTERFACE(IUtility);
113 CloseLibrary((struct Library *)UtilityBase);
116 D(DBF_STARTUP,"cleaning up IntuitionBase...");
117 if (IntuitionBase)
119 DROPINTERFACE(IIntuition);
120 CloseLibrary((struct Library *)IntuitionBase);
123 D(DBF_STARTUP,"cleaning up GfxBase...");
124 if (GfxBase)
126 DROPINTERFACE(IGraphics);
127 CloseLibrary((struct Library *)GfxBase);
131 ULONG initAll(void)
133 if ((GfxBase = (APTR)OpenLibrary("graphics.library", 38)) &&
134 GETINTERFACE(IGraphics, GfxBase) &&
135 (IntuitionBase = (APTR)OpenLibrary("intuition.library", 38)) &&
136 GETINTERFACE(IIntuition, IntuitionBase) &&
137 #ifndef __amigaos4__
138 (UtilityBase = (APTR)OpenLibrary("utility.library", 38)) &&
139 GETINTERFACE(IUtility, UtilityBase) &&
140 #endif
141 (DataTypesBase = OpenLibrary("datatypes.library", 37)) &&
142 GETINTERFACE(IDataTypes, DataTypesBase) &&
143 (MUIMasterBase = OpenLibrary("muimaster.library", 19/*MUIMASTER_VMIN*/)) &&
144 GETINTERFACE(IMUIMaster, MUIMasterBase) &&
145 initSpacerClass() &&
146 initDragBarClass() &&
147 (lib_thisClass = MUI_CreateCustomClass(NULL, (STRPTR)MUIC_Group, NULL, sizeof(struct InstData), ENTRY(_Dispatcher))))
149 CyberGfxBase = OpenLibrary("cybergraphics.library",41);
150 #ifdef __amigaos4__
151 if (!GETINTERFACE(ICyberGfx,CyberGfxBase))
153 CloseLibrary(CyberGfxBase);
154 CyberGfxBase = NULL;
156 #endif
158 PictureDTBase = OpenLibrary("picture.datatype",0);
159 #if !defined(__amigaos4__) && !defined(__AROS__)
160 if (PictureDTBase)
162 if (FindResident("MorphOS"))
164 if ((PictureDTBase->lib_Version<50) ||
165 (PictureDTBase->lib_Version==50 && PictureDTBase->lib_Revision<17))
167 setFlag(lib_flags,BASEFLG_BROKENMOSPDT);
171 #endif
173 if (MUIMasterBase->lib_Version>=20)
175 setFlag(lib_flags, BASEFLG_MUI20);
177 if (MUIMasterBase->lib_Version>20 || MUIMasterBase->lib_Revision>=5341)
178 setFlag(lib_flags, BASEFLG_MUI4);
181 #if defined(DEBUG)
182 SetupDebug();
183 #endif
185 return TRUE;
188 return FALSE;
190 /******************************************************************************/
192 static const char *appearances[] = { "Images and text", "Images", "Text", NULL};
193 static const char *labelPoss[] = { "Bottom", "Top", "Right", "Left", NULL};
195 static struct MUIS_TheBar_Button buttons[] =
197 { 0, 0, "_Pred", "Pread mail.", 0, 0, NULL, NULL },
198 { 1, 1, "_Next", "Next mail.", 0, 0, NULL, NULL },
199 { 2, 2, "_Move", "Move somewhere.",0, 0, NULL, NULL },
200 { MUIV_TheBar_BarSpacer, 3, NULL, NULL, 0, 0, NULL, NULL },
201 { 3, 4, "_Forw", "Forward somewhere.", 0, 0, NULL, NULL },
202 { 4, 5, "F_ind", "Find something.", 0, 0, NULL, NULL },
203 { 5, 6, "_Save", "Save mail.", 0, 0, NULL, NULL },
204 { MUIV_TheBar_End , 0, NULL, NULL, 0, 0, NULL, NULL },
207 // static hooks
208 HOOKPROTONHNO(SaveFunc, ULONG, UNUSED ULONG *qual)
210 D(DBF_STARTUP, "SaveHook triggered: %08lx\n", *qual);
212 return 0;
214 MakeStaticHook(SaveHook, SaveFunc);
216 HOOKPROTONHNO(SleepFunc, ULONG, Object **sb)
218 IPTR sleeping;
220 DoMethod(*sb, MUIM_TheBar_GetAttr, 6, MUIA_TheBar_Attr_Sleep, (IPTR)&sleeping);
222 D(DBF_STARTUP, "SleepHook triggered: %08lx %ld\n", (ULONG)*sb, sleeping);
224 DoMethod(*sb, MUIM_TheBar_SetAttr, 6, MUIA_TheBar_Attr_Sleep, !sleeping);
226 return 0;
228 MakeStaticHook(SleepHook, SleepFunc);
230 int main(void)
232 if (initAll())
234 Object *app, *win, *sb, *appearance, *labelPos, *borderless, *sunny, *raised, *scaled, *update;
236 ENTER();
237 app = ApplicationObject,
238 MUIA_Application_Title, "TheBar Demo1",
239 MUIA_Application_Version, "$VER: TheBarDemo1 1.0 (24.6.2003)",
240 MUIA_Application_Copyright, "Copyright 2003 by Alfonso Ranieri",
241 MUIA_Application_Author, "Alfonso Ranieri <alforan@tin.it>",
242 MUIA_Application_Description, "TheBar example",
243 MUIA_Application_Base, "THEBAREXAMPLE",
245 SubWindow, win = WindowObject,
246 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
247 MUIA_Window_Title, "TheBar Demo1",
249 WindowContents, VGroup,
250 Child, sb = NewObject(lib_thisClass->mcc_Class, NULL,
251 MUIA_Group_Horiz, TRUE,
252 MUIA_TheBar_EnableKeys, TRUE,
253 MUIA_TheBar_Buttons, buttons,
254 MUIA_TheBar_PicsDrawer, "AmiKit:t/thebar/demo/pics",
255 MUIA_TheBar_Strip, "Read.toolbar",
256 MUIA_TheBar_SelStrip, "Read_S.toolbar",
257 MUIA_TheBar_DisStrip, "Read_G.toolbar",
258 MUIA_TheBar_StripCols, 11,
259 End,
260 Child, VGroup,
261 GroupFrameT("Settings"),
262 Child, HGroup,
263 Child, Label2("Appearance"),
264 Child, appearance = MUI_MakeObject(MUIO_Cycle,NULL,(ULONG)appearances),
265 Child, Label2("Label pos"),
266 Child, labelPos = MUI_MakeObject(MUIO_Cycle,NULL,(ULONG)labelPoss),
267 End,
268 Child, HGroup,
269 Child, HSpace(0),
270 Child, Label1("Borderless"),
271 Child, borderless = MUI_MakeObject(MUIO_Checkmark,NULL),
272 Child, HSpace(0),
273 Child, Label1("Sunny"),
274 Child, sunny = MUI_MakeObject(MUIO_Checkmark,NULL),
275 Child, HSpace(0),
276 Child, Label1("Raised"),
277 Child, raised = MUI_MakeObject(MUIO_Checkmark,NULL),
278 Child, HSpace(0),
279 Child, Label1("Scaled"),
280 Child, scaled = MUI_MakeObject(MUIO_Checkmark,NULL),
281 Child, HSpace(0),
282 End,
283 End,
284 Child, update = MUI_MakeObject(MUIO_Button,(ULONG)"_Update"),
285 End,
286 End,
287 End;
288 if (app)
290 ULONG sigs = 0, id;
292 DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
293 DoMethod(update,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)app,2,MUIM_Application_ReturnID,TAG_USER);
295 DoMethod(sb, MUIM_TheBar_Notify, 5, MUIA_Pressed, FALSE, (ULONG)sb, 3, MUIM_CallHook, (ULONG)&SleepHook, (ULONG)sb);
296 DoMethod(sb, MUIM_TheBar_Notify, 6, MUIA_Pressed, FALSE, (ULONG)sb, 3, MUIM_CallHook, (ULONG)&SaveHook, MUIV_TheBar_Qualifier);
298 set(win,MUIA_Window_Open,TRUE);
300 while((LONG)(id = DoMethod(app,MUIM_Application_NewInput,(ULONG)&sigs)) != (LONG)MUIV_Application_ReturnID_Quit)
302 if (id==TAG_USER)
304 ULONG appearanceV, labelPosV, borderlessV, sunnyV, raisedV, scaledV;
306 appearanceV = xget(appearance, MUIA_Cycle_Active);
307 labelPosV = xget(labelPos, MUIA_Cycle_Active);
308 borderlessV = xget(borderless, MUIA_Selected);
309 sunnyV = xget(sunny, MUIA_Selected);
310 raisedV = xget(raised, MUIA_Selected);
311 scaledV = xget(scaled, MUIA_Selected);
313 SetAttrs(sb,MUIA_TheBar_ViewMode, appearanceV,
314 MUIA_TheBar_LabelPos, labelPosV,
315 MUIA_TheBar_Borderless, borderlessV,
316 MUIA_TheBar_Sunny, sunnyV,
317 MUIA_TheBar_Raised, raisedV,
318 MUIA_TheBar_Scaled, scaledV,
319 TAG_DONE);
322 if (sigs)
324 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
325 if (sigs & SIGBREAKF_CTRL_C) break;
329 D(DBF_STARTUP, "cleaning up application object...");
330 MUI_DisposeObject(app);
332 else printf("Failed to create application\n");
334 else printf("Failed to create something\n");
336 RETURN(0);
337 return 0;