New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / classes / zune / aboutwindow / aboutwindow.c
blobf5ac5a6b345b92dbd263ac8869b9795d58173c68
1 /*
2 Copyright © 2003-2004, The AROS Development Team. All rights reserved.
3 This file is part of the AboutWindow class, which is distributed under
4 the terms of version 2.1 of the GNU Lesser General Public License.
6 $Id$
7 */
9 #define MUIMASTER_YES_INLINE_STDARG
11 #include <exec/memory.h>
12 #include <utility/tagitem.h>
13 #include <dos/dos.h>
14 #include <libraries/mui.h>
15 #include <zune/iconimage.h>
17 #include <proto/exec.h>
18 #include <proto/muimaster.h>
19 #include <proto/intuition.h>
20 #include <proto/utility.h>
21 #include <proto/locale.h>
22 #include <proto/dos.h>
23 #include <clib/alib_protos.h> /* StrDup() */
25 #include <string.h>
27 #include "aboutwindow.h"
28 #include "aboutwindow_private.h"
30 #define CATCOMP_ARRAY
31 #include "strings.h"
33 /*** Locale Functions *******************************************************/
34 CONST_STRPTR MSG(struct Catalog *catalog, ULONG id)
36 if (catalog != NULL)
38 return GetCatalogStr(catalog, id, CatCompArray[id].cca_Str);
40 else
42 return CatCompArray[id].cca_Str;
46 #define _(id) MSG(catalog,id)
48 /*** Macros and Defines *****************************************************/
49 #define IGNORE ((APTR)(1UL))
51 /*** Utility ****************************************************************/
52 CONST_STRPTR Section2Name(struct Catalog *catalog, ULONG section)
54 switch (section)
56 case SID_PROGRAMMING:
57 return _(MSG_SECTION_PROGRAMMING);
59 case SID_TRANSLATING:
60 return _(MSG_SECTION_TRANSLATING);
62 default:
63 return NULL;
67 BOOL NamesToList
69 Object *list, struct TagItem *tags, struct AboutWindow_DATA *data
72 struct TagItem *tstate = tags,
73 *tag = NULL;
74 BOOL success = TRUE;
75 IPTR section = SID_NONE;
76 CONST_STRPTR sectionName = NULL;
77 BOOL sectionFirst = TRUE;
78 STRPTR name;
79 STRPTR buffer;
80 ULONG length = 0;
82 if (tags == NULL) return FALSE;
84 while ((tag = NextTagItem(&tstate)) != NULL && success == TRUE)
86 switch (tag->ti_Tag)
88 case SECTION_ID:
89 section = tag->ti_Data;
90 sectionName = Section2Name(data->awd_Catalog, section);
92 if (sectionName != NULL)
94 sectionFirst
95 ? sectionFirst = FALSE
96 : DoMethod(list, MUIM_List_InsertSingle, (IPTR) "");
98 length = strlen(MUIX_B) + strlen(sectionName) + 1;
99 buffer = AllocPooled(data->awd_Pool, length);
100 if (buffer != NULL)
102 buffer[0] = '\0';
103 strcat(buffer, MUIX_B);
104 strcat(buffer, sectionName);
106 DoMethod
108 list, MUIM_List_InsertSingle,
109 (IPTR) buffer, MUIV_List_Insert_Bottom
112 else
114 success = FALSE;
115 break;
119 break;
121 case NAME_STRING:
122 name = (STRPTR) tag->ti_Data;
124 length = strlen(name) + 1;
125 if (sectionName != NULL) length += 4;
127 buffer = AllocPooled(data->awd_Pool, length);
128 if (buffer != NULL)
130 buffer[0] = '\0';
131 if (sectionName != NULL) strcat(buffer, " ");
132 strcat(buffer, name);
134 DoMethod
136 list, MUIM_List_InsertSingle,
137 (IPTR) buffer, MUIV_List_Insert_Bottom
140 else
142 success = FALSE;
143 break;
146 break;
150 return success;
153 /*** Methods ****************************************************************/
154 Object *AboutWindow__OM_NEW
156 Class *CLASS, Object *self, struct opSet *message
159 struct AboutWindow_DATA *data = NULL;
160 struct TagItem *tag = NULL,
161 *tstate = message->ops_AttrList,
162 *authorsTags = NULL,
163 *sponsorsTags = NULL;
164 struct Catalog *catalog = NULL;
165 APTR pool;
166 Object *rootGroup = NULL,
167 *imageGroup = NULL,
168 *imageObject = NULL,
169 *versionObject = NULL,
170 *copyrightObject = NULL,
171 *descriptionGroup = NULL,
172 *descriptionObject = NULL,
173 *authorsList = NULL,
174 *sponsorsList = NULL;
176 STRPTR title = NULL,
177 versionNumber = NULL,
178 versionDate = NULL,
179 versionExtra = NULL,
180 description = NULL,
181 copyright = NULL;
183 CONST_STRPTR pages[] = { NULL, NULL, NULL };
184 UBYTE nextPage = 0;
186 /* Allocate memory pool ------------------------------------------------*/
187 pool = CreatePool(MEMF_ANY, 4096, 4096);
188 if (pool == NULL) return NULL;
190 /* Initialize locale ---------------------------------------------------*/
191 catalog = OpenCatalogA
193 NULL, "System/Classes/Zune/AboutWindow.catalog", NULL
196 /* Parse initial attributes --------------------------------------------*/
197 while ((tag = NextTagItem(&tstate)) != NULL)
199 switch (tag->ti_Tag)
201 case MUIA_AboutWindow_Image:
202 imageObject = (Object *) tag->ti_Data;
203 break;
205 case MUIA_AboutWindow_Title:
206 title = StrDup((STRPTR) tag->ti_Data);
207 if (title == NULL) title = IGNORE;
208 break;
210 case MUIA_AboutWindow_Version_Number:
211 versionNumber = StrDup((STRPTR) tag->ti_Data);
212 if (versionNumber == NULL) versionNumber = IGNORE;
213 break;
215 case MUIA_AboutWindow_Version_Date:
216 versionDate = StrDup((STRPTR) tag->ti_Data);
217 if (versionDate == NULL) versionDate = IGNORE;
218 break;
220 case MUIA_AboutWindow_Version_Extra:
221 versionExtra = StrDup((STRPTR) tag->ti_Data);
222 if (versionExtra == NULL) versionExtra = IGNORE;
223 break;
225 case MUIA_AboutWindow_Copyright:
226 copyright = StrDup((STRPTR) tag->ti_Data);
227 if (copyright == NULL) copyright = IGNORE;
228 break;
230 case MUIA_AboutWindow_Description:
231 description = StrDup((STRPTR) tag->ti_Data);
232 if (description == NULL) description = IGNORE;
233 break;
235 case MUIA_AboutWindow_Authors:
236 authorsTags = (struct TagItem *) tag->ti_Data;
237 break;
239 case MUIA_AboutWindow_Sponsors:
240 sponsorsTags = (struct TagItem *) tag->ti_Data;
241 break;
243 default:
244 continue; /* Don't supress non-processed tags */
247 tag->ti_Tag = TAG_IGNORE;
250 /* Setup image ---------------------------------------------------------*/
251 if (imageObject == NULL)
253 TEXT path[512], program[1024]; path[0] = '\0'; program[0] = '\0';
255 if (GetProgramName(program, 1024))
257 strlcat(path, "PROGDIR:", 512);
258 strlcat(path, FilePart(program), 512);
259 imageObject = IconImageObject,
260 MUIA_IconImage_File, (IPTR) path,
261 End;
264 if (imageObject == NULL)
266 imageObject = HVSpace;
270 /* Setup pages ---------------------------------------------------------*/
271 if (authorsTags != NULL)
273 pages[nextPage] = _(MSG_AUTHORS);
274 nextPage++;
277 if (sponsorsTags != NULL)
279 pages[nextPage] = _(MSG_SPONSORS);
280 nextPage++;
283 self = (Object *) DoSuperNewTags
285 CLASS, self, NULL,
287 MUIA_Window_Activate, TRUE,
288 MUIA_Window_NoMenus, TRUE,
289 MUIA_Window_Height, MUIV_Window_Height_Visible(25),
290 MUIA_Window_Width, MUIV_Window_Width_Visible(25),
292 WindowContents, (IPTR) VGroup,
293 GroupSpacing(6),
295 Child, (IPTR) (imageGroup = HGroup,
296 MUIA_Weight, 0,
298 Child, (IPTR) HVSpace,
299 Child, (IPTR) imageObject,
300 Child, (IPTR) HVSpace,
301 End),
302 Child, (IPTR) (versionObject = TextObject,
303 MUIA_Text_PreParse, (IPTR) MUIX_C,
304 MUIA_Text_Contents, (IPTR) NULL,
305 End),
306 Child, (IPTR) (copyrightObject = TextObject,
307 MUIA_Text_PreParse, (IPTR) MUIX_C,
308 MUIA_Text_Contents, (IPTR) NULL,
309 End),
310 Child, (IPTR) (descriptionGroup = VGroup,
311 Child, (IPTR) VSpace(6),
312 Child, (IPTR) (descriptionObject = TextObject,
313 MUIA_Text_PreParse, (IPTR) MUIX_I MUIX_C,
314 MUIA_Text_Contents, (IPTR) NULL,
315 End),
316 End),
317 Child, (IPTR) VSpace(6),
318 Child, (IPTR) RegisterGroup(pages),
319 Child, (IPTR) ListviewObject,
320 MUIA_Listview_List, (IPTR) (authorsList = ListObject,
321 ReadListFrame,
322 End),
323 End,
324 Child, (IPTR) ListviewObject,
325 MUIA_Listview_List, (IPTR) (sponsorsList = ListObject,
326 ReadListFrame,
327 End),
328 End,
329 End,
330 End,
332 TAG_MORE, (IPTR) message->ops_AttrList
335 if (self == NULL) goto error;
337 data = INST_DATA(CLASS, self);
338 data->awd_Catalog = catalog;
339 data->awd_Pool = pool;
340 data->awd_RootGroup = rootGroup;
341 data->awd_ImageGroup = imageGroup;
342 data->awd_ImageObject = imageObject;
343 data->awd_VersionObject = versionObject;
344 data->awd_CopyrightObject = copyrightObject;
345 data->awd_DescriptionGroup = descriptionGroup;
346 data->awd_DescriptionObject = descriptionObject;
347 data->awd_Title = title;
348 data->awd_VersionNumber = versionNumber;
349 data->awd_VersionDate = versionDate;
350 data->awd_VersionExtra = versionExtra;
351 data->awd_Copyright = copyright;
352 data->awd_Description = description;
354 if (authorsTags != NULL) NamesToList(authorsList, authorsTags, data);
355 if (sponsorsTags != NULL) NamesToList(sponsorsList, sponsorsTags, data);
357 /* Setup notifications */
358 DoMethod
360 self, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
361 (IPTR) self, 2, MUIA_Window_Open, FALSE
364 return self;
366 error:
367 if (catalog != NULL) CloseCatalog(catalog);
369 return NULL;
372 IPTR AboutWindow__MUIM_Window_Setup
374 Class *CLASS, Object *self, Msg message
377 struct AboutWindow_DATA *data = INST_DATA(CLASS, self);
378 struct Catalog *catalog = data->awd_Catalog;
379 STRPTR string = NULL;
381 if (!DoSuperMethodA(CLASS, self, message)) return FALSE;
383 /*= Setup window title =================================================*/
385 STRPTR buffer = NULL;
386 ULONG length = 0;
388 string = data->awd_Title;
389 if (string == NULL)
391 GET(self, MUIA_AboutWindow_Title, &string);
393 if (string != IGNORE)
395 if (string == NULL)
397 GET(_app(self), MUIA_Application_Title, &string);
400 if (string != NULL)
402 length = strlen(string) + strlen(_(MSG_ABOUT)) + 2; /* space + newline */
403 buffer = AllocVec(length, MEMF_ANY);
405 if (buffer != NULL)
407 buffer[0] = '\0';
408 strlcat(buffer, _(MSG_ABOUT), length);
409 strlcat(buffer, " ", length);
410 strlcat(buffer, string, length);
412 set(self, MUIA_Window_Title, buffer);
414 FreeVec(buffer);
421 /*= Setup image ========================================================*/
422 if (data->awd_ImageObject == NULL)
424 DoMethod(data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_ImageGroup);
427 /*= Setup version ======================================================*/
429 The version string will have the format:
430 MUIX_B"<title>"MUIX_N" <version> (<date>) [<extra>]"
433 STRPTR title = data->awd_Title,
434 versionNumber = data->awd_VersionNumber,
435 versionDate = data->awd_VersionDate,
436 versionExtra = data->awd_VersionExtra,
437 buffer = NULL;
438 ULONG length = 0;
440 /*- Setup default values -------------------------------------------*/
441 if (title == NULL)
443 GET(_app(self), MUIA_Application_Title, &title);
446 if (versionNumber == NULL)
448 GET(_app(self), MUIA_Application_Version_Number, &versionNumber);
451 if (versionDate == NULL)
453 GET(_app(self), MUIA_Application_Version_Date, &versionDate);
456 if (versionExtra == NULL)
458 GET(_app(self), MUIA_Application_Version_Extra, &versionExtra);
461 /* Simplify later checks a little */
462 if (title == IGNORE) title = NULL;
463 if (versionNumber == IGNORE) versionNumber = NULL;
464 if (versionDate == IGNORE) versionDate = NULL;
465 if (versionExtra == IGNORE) versionExtra = NULL;
467 /*- Calculate length -----------------------------------------------*/
468 if (title != NULL)
470 length += strlen(MUIX_B) + strlen(title) + strlen(MUIX_N) + 1;
473 if (versionNumber != NULL)
475 length += 1 /* space */ + strlen(versionNumber);
478 if (versionDate != NULL)
480 length += 1 /* space */ + 1 /* ( */ + strlen(versionDate) + 1 /* ) */;
483 if (versionExtra != NULL)
485 length += 1 /* space */ + 1 /* [ */ + strlen(versionExtra) + 1 /* ] */;
488 /*- Setup version object -------------------------------------------*/
489 if (length > 0)
491 /*- Allocate memory --------------------------------------------*/
492 buffer = AllocVec(length, MEMF_ANY);
494 if (buffer != NULL)
496 buffer[0] = '\0';
498 /*- Generate text ------------------------------------------*/
499 if (title != NULL)
501 strlcat(buffer, MUIX_B, length);
502 strlcat(buffer, title, length);
503 strlcat(buffer, MUIX_N, length);
506 if (versionNumber != NULL)
508 strlcat(buffer, " ", length);
509 strlcat(buffer, versionNumber, length);
512 if (versionDate != NULL)
514 strlcat(buffer, " (", length);
515 strlcat(buffer, versionDate, length);
516 strlcat(buffer, ")", length);
519 if (versionExtra != NULL)
521 strlcat(buffer, " [", length);
522 strlcat(buffer, versionExtra, length);
523 strlcat(buffer, "]", length);
526 set(data->awd_VersionObject, MUIA_Text_Contents, buffer);
527 FreeVec(buffer); /* don't need it anymore */
529 else
531 DoMethod
533 data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_VersionObject
539 /*= Setup copyright ====================================================*/
540 if (data->awd_Copyright == NULL)
542 GET(_app(self), MUIA_Application_Copyright, &data->awd_Copyright);
545 if (data->awd_Copyright != IGNORE && data->awd_Copyright != NULL)
547 SET(data->awd_CopyrightObject, MUIA_Text_Contents, data->awd_Copyright);
549 else
551 DoMethod(data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_CopyrightObject);
554 /*= Setup description ==================================================*/
555 if (data->awd_Description == NULL)
557 GET(_app(self), MUIA_Application_Description, &data->awd_Description);
560 if (data->awd_Description != IGNORE && data->awd_Description != NULL)
564 data->awd_DescriptionObject,
565 MUIA_Text_Contents, data->awd_Description
568 else
570 DoMethod
572 data->awd_RootGroup, OM_REMMEMBER, (IPTR) data->awd_DescriptionGroup
576 /* We no longer need to know whether to IGNORE or not */
577 if (data->awd_Title == IGNORE) data->awd_Title = NULL;
578 if (data->awd_VersionNumber == IGNORE) data->awd_VersionNumber = NULL;
579 if (data->awd_VersionDate == IGNORE) data->awd_VersionDate = NULL;
580 if (data->awd_VersionExtra == IGNORE) data->awd_VersionExtra = NULL;
581 if (data->awd_Copyright == IGNORE) data->awd_Copyright = NULL;
582 if (data->awd_Description == IGNORE) data->awd_Description = NULL;
584 return TRUE;
587 IPTR AboutWindow__OM_DISPOSE
589 Class *CLASS, Object *self, Msg message
592 struct AboutWindow_DATA *data = INST_DATA(CLASS, self);
593 UBYTE i;
594 APTR ptrs[] =
596 data->awd_Title, data->awd_VersionNumber, data->awd_VersionDate,
597 data->awd_VersionExtra, data->awd_Copyright, data->awd_VersionExtra
600 for (i = 0; i < (sizeof(ptrs) / sizeof(APTR)); i++)
602 if (ptrs[i] != NULL) FreeVec(ptrs[i]);
605 if (data->awd_Pool != NULL) DeletePool(data->awd_Pool);
607 if (data->awd_Catalog != NULL) CloseCatalog(data->awd_Catalog);
609 return DoSuperMethodA(CLASS, self, message);