grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / zune / nlist / demo / NList-Demo2.c
blob89e3fc4aa7b7c8671814d1b53664d01ad51b97e6
1 /***************************************************************************
3 NList.mcc - New List MUI Custom Class
4 Registered MUI class, Serial Number: 1d51 0x9d510030 to 0x9d5100A0
5 0x9d5100C0 to 0x9d5100FF
7 Copyright (C) 1996-2001 by Gilles Masson
8 Copyright (C) 2001-2014 NList Open Source Team
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 NList classes Support Site: http://www.sf.net/projects/nlist-classes
22 $Id$
24 ***************************************************************************/
26 #if defined(__AROS__)
27 #include <clib/alib_protos.h>
28 #endif
30 #include <stdlib.h>
31 #include <string.h>
32 #include <stdio.h>
33 #include <dos/dos.h>
34 #include <exec/types.h>
35 #include <exec/memory.h>
36 #include <exec/ports.h>
37 #include <exec/io.h>
38 #include <libraries/dos.h>
39 #include <libraries/dosextens.h>
40 #include <libraries/gadtools.h>
41 #include <libraries/asl.h>
42 #include <libraries/mui.h>
43 #include <workbench/workbench.h>
44 #include <intuition/intuition.h>
45 #include <intuition/classusr.h>
46 #include <graphics/gfxmacros.h>
48 #include <proto/exec.h>
49 #include <proto/dos.h>
50 #include <proto/gadtools.h>
51 #include <proto/asl.h>
53 extern struct Library *MUIMasterBase;
55 #include <mui/NListview_mcc.h>
56 #include <mui/NFloattext_mcc.h>
58 #include "NList-Demo2.h"
60 #include <proto/muimaster.h>
62 #include "SDI_hook.h"
64 /* *********************************************** */
66 struct LITD {
67 LONG num;
68 char str1[4];
69 char *str2;
72 /* *********************************************** */
74 HOOKPROTONHNO(ConstructLI_TextFunc, APTR, struct NList_ConstructMessage *ncm)
76 struct LITD *new_entry = (struct LITD *) AllocVec(sizeof(struct LITD),0);
78 if (new_entry)
80 int i = 0, j = 0;
81 new_entry->num = -1;
82 new_entry->str2 = (char *) ncm->entry;
83 while ((j < 3) && new_entry->str2[i])
85 if ((new_entry->str2[i] > 'A') && (new_entry->str2[i] < 'z'))
86 new_entry->str1[j++] = new_entry->str2[i];
87 if (new_entry->str2[i] == '\033')
88 i++;
89 i++;
91 new_entry->str1[j] = '\0';
93 return (new_entry);
95 return (NULL);
97 MakeHook(ConstructLI_TextHook, ConstructLI_TextFunc);
99 /* *********************************************** */
101 HOOKPROTONHNO(DestructLI_TextFunc, void, struct NList_DestructMessage *ndm)
103 if (ndm->entry)
104 FreeVec((void *) ndm->entry);
106 MakeHook(DestructLI_TextHook, DestructLI_TextFunc);
108 /* *********************************************** */
110 static char buf[20];
112 HOOKPROTONHNO(DisplayLI_TextFunc, void, struct NList_DisplayMessage *ndm)
114 struct LITD *entry = (struct LITD *) ndm->entry;
116 if (entry)
117 { if (entry->num < 0)
118 entry->num = ndm->entry_pos;
120 ndm->preparses[0] = (STRPTR)"\033c";
121 ndm->preparses[1] = (STRPTR)"\033c";
123 if (entry->num % 20 == 3)
124 ndm->strings[0] = (STRPTR)"\033o[0]";
125 else if (entry->num % 20 == 13)
126 ndm->strings[0] = (STRPTR)"\033o[1]";
127 else
129 snprintf(buf, sizeof(buf), "%d", (unsigned int)entry->num);
130 ndm->strings[0] = buf;
133 ndm->strings[1] = (char *) entry->str1;
134 ndm->strings[2] = (char *) entry->str2;
136 else
138 ndm->preparses[0] = (STRPTR)"\033c";
139 ndm->preparses[1] = (STRPTR)"\033c";
140 ndm->preparses[2] = (STRPTR)"\033c";
141 ndm->strings[0] = (STRPTR)"Num";
142 ndm->strings[1] = (STRPTR)"Short";
143 ndm->strings[2] = (STRPTR)"This is the list title !\033n\033b :-)";
146 MakeHook(DisplayLI_TextHook, DisplayLI_TextFunc);
149 /* *********************************************** */
151 HOOKPROTONHNO(CompareLI_TextFunc, LONG, struct NList_CompareMessage *ncm)
153 struct LITD *entry1 = (struct LITD *) ncm->entry1;
154 struct LITD *entry2 = (struct LITD *) ncm->entry2;
155 LONG col1 = ncm->sort_type & MUIV_NList_TitleMark_ColMask;
156 LONG col2 = ncm->sort_type2 & MUIV_NList_TitleMark2_ColMask;
157 LONG result = 0;
160 LONG st = ncm->sort_type & MUIV_NList_TitleMark_TypeMask;
161 kprintf("%lx|Compare() %lx / %lx / %lx\n",obj,ncm->sort_type,st,ncm->sort_type2);
164 if(ncm->sort_type == (LONG)MUIV_NList_SortType_None)
165 return (0);
167 if (col1 == 0)
168 { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
169 result = entry2->num - entry1->num;
170 else
171 result = entry1->num - entry2->num;
173 else if (col1 == 1)
174 { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
175 result = (LONG) stricmp(entry2->str1,entry1->str1);
176 else
177 result = (LONG) stricmp(entry1->str1,entry2->str1);
179 else if (col1 == 2)
180 { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
181 result = (LONG) stricmp(entry2->str2,entry1->str2);
182 else
183 result = (LONG) stricmp(entry1->str2,entry2->str2);
186 if ((result != 0) || (col1 == col2))
187 return (result);
189 if (col2 == 0)
190 { if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
191 result = entry2->num - entry1->num;
192 else
193 result = entry1->num - entry2->num;
195 else if (col2 == 1)
196 { if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
197 result = (LONG) stricmp(entry2->str1,entry1->str1);
198 else
199 result = (LONG) stricmp(entry1->str1,entry2->str1);
201 else if (col2 == 2)
202 { if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
203 result = (LONG) stricmp(entry2->str2,entry1->str2);
204 else
205 result = (LONG) stricmp(entry1->str2,entry2->str2);
208 return (result);
210 MakeHook(CompareLI_TextHook, CompareLI_TextFunc);