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.
9 #define MUIMASTER_YES_INLINE_STDARG
11 #include <exec/memory.h>
12 #include <utility/tagitem.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() */
27 #include "aboutwindow.h"
28 #include "aboutwindow_private.h"
33 /*** Locale Functions *******************************************************/
34 CONST_STRPTR
MSG(struct Catalog
*catalog
, ULONG id
)
38 return GetCatalogStr(catalog
, id
, CatCompArray
[id
].cca_Str
);
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
)
57 return _(MSG_SECTION_PROGRAMMING
);
60 return _(MSG_SECTION_TRANSLATING
);
69 Object
*list
, struct TagItem
*tags
, struct AboutWindow_DATA
*data
72 struct TagItem
*tstate
= tags
,
75 IPTR section
= SID_NONE
;
76 CONST_STRPTR sectionName
= NULL
;
77 BOOL sectionFirst
= TRUE
;
82 if (tags
== NULL
) return FALSE
;
84 while ((tag
= NextTagItem(&tstate
)) != NULL
&& success
== TRUE
)
89 section
= tag
->ti_Data
;
90 sectionName
= Section2Name(data
->awd_Catalog
, section
);
92 if (sectionName
!= NULL
)
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
);
103 strcat(buffer
, MUIX_B
);
104 strcat(buffer
, sectionName
);
108 list
, MUIM_List_InsertSingle
,
109 (IPTR
) buffer
, MUIV_List_Insert_Bottom
122 name
= (STRPTR
) tag
->ti_Data
;
124 length
= strlen(name
) + 1;
125 if (sectionName
!= NULL
) length
+= 4;
127 buffer
= AllocPooled(data
->awd_Pool
, length
);
131 if (sectionName
!= NULL
) strcat(buffer
, " ");
132 strcat(buffer
, name
);
136 list
, MUIM_List_InsertSingle
,
137 (IPTR
) buffer
, MUIV_List_Insert_Bottom
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
,
163 *sponsorsTags
= NULL
;
164 struct Catalog
*catalog
= NULL
;
166 Object
*rootGroup
= NULL
,
169 *versionObject
= NULL
,
170 *copyrightObject
= NULL
,
171 *descriptionGroup
= NULL
,
172 *descriptionObject
= NULL
,
174 *sponsorsList
= NULL
;
177 versionNumber
= NULL
,
183 CONST_STRPTR pages
[] = { NULL
, NULL
, NULL
};
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
)
201 case MUIA_AboutWindow_Image
:
202 imageObject
= (Object
*) tag
->ti_Data
;
205 case MUIA_AboutWindow_Title
:
206 title
= StrDup((STRPTR
) tag
->ti_Data
);
207 if (title
== NULL
) title
= IGNORE
;
210 case MUIA_AboutWindow_Version_Number
:
211 versionNumber
= StrDup((STRPTR
) tag
->ti_Data
);
212 if (versionNumber
== NULL
) versionNumber
= IGNORE
;
215 case MUIA_AboutWindow_Version_Date
:
216 versionDate
= StrDup((STRPTR
) tag
->ti_Data
);
217 if (versionDate
== NULL
) versionDate
= IGNORE
;
220 case MUIA_AboutWindow_Version_Extra
:
221 versionExtra
= StrDup((STRPTR
) tag
->ti_Data
);
222 if (versionExtra
== NULL
) versionExtra
= IGNORE
;
225 case MUIA_AboutWindow_Copyright
:
226 copyright
= StrDup((STRPTR
) tag
->ti_Data
);
227 if (copyright
== NULL
) copyright
= IGNORE
;
230 case MUIA_AboutWindow_Description
:
231 description
= StrDup((STRPTR
) tag
->ti_Data
);
232 if (description
== NULL
) description
= IGNORE
;
235 case MUIA_AboutWindow_Authors
:
236 authorsTags
= (struct TagItem
*) tag
->ti_Data
;
239 case MUIA_AboutWindow_Sponsors
:
240 sponsorsTags
= (struct TagItem
*) tag
->ti_Data
;
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
,
264 if (imageObject
== NULL
)
266 imageObject
= HVSpace
;
270 /* Setup pages ---------------------------------------------------------*/
271 if (authorsTags
!= NULL
)
273 pages
[nextPage
] = _(MSG_AUTHORS
);
277 if (sponsorsTags
!= NULL
)
279 pages
[nextPage
] = _(MSG_SPONSORS
);
283 self
= (Object
*) DoSuperNewTags
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
,
295 Child
, (IPTR
) (imageGroup
= HGroup
,
298 Child
, (IPTR
) HVSpace
,
299 Child
, (IPTR
) imageObject
,
300 Child
, (IPTR
) HVSpace
,
302 Child
, (IPTR
) (versionObject
= TextObject
,
303 MUIA_Text_PreParse
, (IPTR
) MUIX_C
,
304 MUIA_Text_Contents
, (IPTR
) NULL
,
306 Child
, (IPTR
) (copyrightObject
= TextObject
,
307 MUIA_Text_PreParse
, (IPTR
) MUIX_C
,
308 MUIA_Text_Contents
, (IPTR
) NULL
,
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
,
317 Child
, (IPTR
) VSpace(6),
318 Child
, (IPTR
) RegisterGroup(pages
),
319 Child
, (IPTR
) ListviewObject
,
320 MUIA_Listview_List
, (IPTR
) (authorsList
= ListObject
,
324 Child
, (IPTR
) ListviewObject
,
325 MUIA_Listview_List
, (IPTR
) (sponsorsList
= ListObject
,
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 */
360 self
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
361 (IPTR
) self
, 2, MUIA_Window_Open
, FALSE
367 if (catalog
!= NULL
) CloseCatalog(catalog
);
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
;
388 string
= data
->awd_Title
;
391 GET(self
, MUIA_AboutWindow_Title
, &string
);
393 if (string
!= IGNORE
)
397 GET(_app(self
), MUIA_Application_Title
, &string
);
402 length
= strlen(string
) + strlen(_(MSG_ABOUT
)) + 2; /* space + newline */
403 buffer
= AllocVec(length
, MEMF_ANY
);
408 strlcat(buffer
, _(MSG_ABOUT
), length
);
409 strlcat(buffer
, " ", length
);
410 strlcat(buffer
, string
, length
);
412 set(self
, MUIA_Window_Title
, 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
,
440 /*- Setup default values -------------------------------------------*/
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 -----------------------------------------------*/
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 -------------------------------------------*/
491 /*- Allocate memory --------------------------------------------*/
492 buffer
= AllocVec(length
, MEMF_ANY
);
498 /*- Generate text ------------------------------------------*/
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 */
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
);
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
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
;
587 IPTR AboutWindow__OM_DISPOSE
589 Class
*CLASS
, Object
*self
, Msg message
592 struct AboutWindow_DATA
*data
= INST_DATA(CLASS
, self
);
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
);