revert mistakenly committed changes.
[AROS.git] / test / Zune / dynlist.c
blobe4266c7612d6ccd874daf6d20316d68bd09e4a56
1 /*
2 Copyright © 2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/types.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
11 #include <dos/dos.h>
12 #include <intuition/gadgetclass.h>
13 #include <intuition/icclass.h>
14 #include <proto/exec.h>
15 #include <proto/intuition.h>
16 #include <proto/muimaster.h>
17 #include <clib/alib_protos.h>
19 #include <utility/hooks.h>
20 #include <libraries/mui.h>
22 Object *app;
23 Object *wnd, *str1, *str2, *str3, *bt1, *bt2, *bt3, *list;
25 static IPTR DynlistDisplayFunc(struct Hook *hook, char **columns, char **entry)
27 if(entry == NULL)
29 columns[0] = "Column 1";
30 columns[1] = "Column 2";
31 columns[2] = "Column 3";
33 else
35 columns[0] = entry[0];
36 columns[1] = entry[1];
37 columns[2] = entry[2];
39 return TRUE;
42 static IPTR AddFunc(struct Hook *hook, Object *caller, void *data)
44 STRPTR s1 = (STRPTR) XGET(str1, MUIA_String_Contents);
45 STRPTR s2 = (STRPTR) XGET(str2, MUIA_String_Contents);
46 STRPTR s3 = (STRPTR) XGET(str3, MUIA_String_Contents);
47 STRPTR *item = (STRPTR*) malloc(sizeof(STRPTR) * 4);
48 item[0] = strdup(s1);
49 item[1] = strdup(s2);
50 item[2] = strdup(s3);
51 item[3] = NULL;
52 DoMethod(list, MUIM_List_InsertSingle, item, MUIV_List_Insert_Top);
54 return TRUE;
57 static IPTR MutateFunc(struct Hook *hook, Object *caller, void *data)
59 LONG active = 0;
60 char **entry;
61 get(list, MUIA_List_Active, &active);
62 if (active == MUIV_List_Active_Off)
63 return FALSE;
65 DoMethod(list, MUIM_List_GetEntry, active, &entry);
66 entry[0] = "A very long entry";
67 entry[1] = "This is even longer";
68 entry[2] = "I'm the longest entry in the application";
69 DoMethod(list, MUIM_List_Redraw, MUIV_List_Redraw_Active);
71 return TRUE;
74 int main(void)
76 struct Hook addHook, displayHook, mutateHook;
77 addHook.h_Entry = HookEntry;
78 addHook.h_SubEntry = (HOOKFUNC) AddFunc;
79 displayHook.h_Entry = HookEntry;
80 displayHook.h_SubEntry = (HOOKFUNC) DynlistDisplayFunc;
81 mutateHook.h_Entry = HookEntry;
82 mutateHook.h_SubEntry = (HOOKFUNC) MutateFunc;
84 app = ApplicationObject,
85 SubWindow, wnd = WindowObject,
86 MUIA_Window_Title, "Dynamic list",
87 MUIA_Window_Activate, TRUE,
89 WindowContents, VGroup,
90 Child, list = ListObject,
91 MUIA_List_DisplayHook, &displayHook,
92 MUIA_List_Format, "BAR,BAR,",
93 MUIA_List_Title, TRUE,
94 End,
95 Child, HGroup,
96 Child, str1 = StringObject, End,
97 Child, str2 = StringObject, End,
98 Child, str3 = StringObject, End,
99 End,
100 Child, HGroup,
101 Child, bt1 = SimpleButton("Add"),
102 Child, bt2 = SimpleButton("Remove"),
103 Child, bt3 = SimpleButton("Grow"),
104 End,
105 End,
106 End,
107 End;
109 if (app)
111 ULONG sigs = 0;
113 DoMethod(wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
114 app, (IPTR) 2,
115 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
117 DoMethod(bt1, MUIM_Notify, MUIA_Pressed, FALSE,
118 (IPTR) bt1, 3,
119 MUIM_CallHook, &addHook, list);
121 DoMethod(bt2, MUIM_Notify, MUIA_Pressed, FALSE,
122 (IPTR) list, 2,
123 MUIM_List_Remove, MUIV_List_Remove_First);
125 DoMethod(bt3, MUIM_Notify, MUIA_Pressed, FALSE,
126 (IPTR) list, 3,
127 MUIM_CallHook, &mutateHook, NULL);
129 set(wnd,MUIA_Window_Open,TRUE);
131 while (DoMethod(app, MUIM_Application_NewInput, (IPTR) &sigs) != MUIV_Application_ReturnID_Quit)
133 if (sigs)
135 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
136 if (sigs & SIGBREAKF_CTRL_C) break;
140 MUI_DisposeObject(app);
143 return 0;