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
*tag
= NULL
, *tstate
= tags
;
74 IPTR section
= SID_NONE
;
75 CONST_STRPTR sectionName
= NULL
;
76 BOOL sectionFirst
= TRUE
;
81 if (tags
== NULL
) return FALSE
;
83 while ((tag
= NextTagItem(&tstate
)) != NULL
&& success
== TRUE
)
88 section
= tag
->ti_Data
;
89 sectionName
= Section2Name(data
->awd_Catalog
, section
);
91 if (sectionName
!= NULL
)
94 ? sectionFirst
= FALSE
95 : DoMethod(list
, MUIM_List_InsertSingle
, (IPTR
) "");
97 length
= strlen(MUIX_B
) + strlen(sectionName
) + 1;
98 buffer
= AllocPooled(data
->awd_Pool
, length
);
102 strcat(buffer
, MUIX_B
);
103 strcat(buffer
, sectionName
);
107 list
, MUIM_List_InsertSingle
,
108 (IPTR
) buffer
, MUIV_List_Insert_Bottom
121 name
= (STRPTR
) tag
->ti_Data
;
123 length
= strlen(name
) + 1;
124 if (sectionName
!= NULL
) length
+= 4;
126 buffer
= AllocPooled(data
->awd_Pool
, length
);
130 if (sectionName
!= NULL
) strcat(buffer
, " ");
131 strcat(buffer
, name
);
135 list
, MUIM_List_InsertSingle
,
136 (IPTR
) buffer
, MUIV_List_Insert_Bottom
152 /*** Methods ****************************************************************/
153 Object
*AboutWindow__OM_NEW
155 Class
*CLASS
, Object
*self
, struct opSet
*message
158 struct AboutWindow_DATA
*data
= NULL
;
159 struct TagItem
*tag
= NULL
,
160 *tstate
= message
->ops_AttrList
,
162 *sponsorsTags
= NULL
;
163 struct Catalog
*catalog
= NULL
;
165 Object
*rootGroup
= NULL
,
168 *versionObject
= NULL
,
169 *copyrightObject
= NULL
,
170 *descriptionGroup
= NULL
,
171 *descriptionObject
= NULL
,
173 *sponsorsList
= NULL
;
176 versionNumber
= NULL
,
182 CONST_STRPTR pages
[] = { NULL
, NULL
, NULL
};
185 /* Allocate memory pool ------------------------------------------------*/
186 pool
= CreatePool(MEMF_ANY
, 4096, 4096);
187 if (pool
== NULL
) return NULL
;
189 /* Initialize locale ---------------------------------------------------*/
190 catalog
= OpenCatalogA
192 NULL
, "System/Classes/Zune/AboutWindow.catalog", NULL
195 /* Parse initial attributes --------------------------------------------*/
196 while ((tag
= NextTagItem(&tstate
)) != NULL
)
200 case MUIA_AboutWindow_Image
:
201 imageObject
= (Object
*) tag
->ti_Data
;
204 case MUIA_AboutWindow_Title
:
205 title
= StrDup((STRPTR
) tag
->ti_Data
);
206 if (title
== NULL
) title
= IGNORE
;
209 case MUIA_AboutWindow_Version_Number
:
210 versionNumber
= StrDup((STRPTR
) tag
->ti_Data
);
211 if (versionNumber
== NULL
) versionNumber
= IGNORE
;
214 case MUIA_AboutWindow_Version_Date
:
215 versionDate
= StrDup((STRPTR
) tag
->ti_Data
);
216 if (versionDate
== NULL
) versionDate
= IGNORE
;
219 case MUIA_AboutWindow_Version_Extra
:
220 versionExtra
= StrDup((STRPTR
) tag
->ti_Data
);
221 if (versionExtra
== NULL
) versionExtra
= IGNORE
;
224 case MUIA_AboutWindow_Copyright
:
225 copyright
= StrDup((STRPTR
) tag
->ti_Data
);
226 if (copyright
== NULL
) copyright
= IGNORE
;
229 case MUIA_AboutWindow_Description
:
230 description
= StrDup((STRPTR
) tag
->ti_Data
);
231 if (description
== NULL
) description
= IGNORE
;
234 case MUIA_AboutWindow_Authors
:
235 authorsTags
= (struct TagItem
*) tag
->ti_Data
;
238 case MUIA_AboutWindow_Sponsors
:
239 sponsorsTags
= (struct TagItem
*) tag
->ti_Data
;
243 continue; /* Don't supress non-processed tags */
246 tag
->ti_Tag
= TAG_IGNORE
;
249 /* Setup image ---------------------------------------------------------*/
250 if (imageObject
== NULL
)
252 TEXT path
[512], program
[1024]; path
[0] = '\0'; program
[0] = '\0';
254 if (GetProgramName(program
, 1024))
256 strlcat(path
, "PROGDIR:", 512);
257 strlcat(path
, FilePart(program
), 512);
258 imageObject
= (Object
*)IconImageObject
,
259 MUIA_IconImage_File
, (IPTR
) path
,
263 if (imageObject
== NULL
)
265 imageObject
= HVSpace
;
269 /* Setup pages ---------------------------------------------------------*/
270 if (authorsTags
!= NULL
)
272 pages
[nextPage
] = _(MSG_AUTHORS
);
276 if (sponsorsTags
!= NULL
)
278 pages
[nextPage
] = _(MSG_SPONSORS
);
282 self
= (Object
*) DoSuperNewTags
286 MUIA_Window_Activate
, TRUE
,
287 MUIA_Window_NoMenus
, TRUE
,
288 MUIA_Window_Height
, MUIV_Window_Height_Visible(25),
289 MUIA_Window_Width
, MUIV_Window_Width_Visible(25),
291 WindowContents
, (IPTR
) VGroup
,
294 Child
, (IPTR
) (imageGroup
= (Object
*)HGroup
,
297 Child
, (IPTR
) HVSpace
,
298 Child
, (IPTR
) imageObject
,
299 Child
, (IPTR
) HVSpace
,
301 Child
, (IPTR
) (versionObject
= (Object
*)TextObject
,
302 MUIA_Text_PreParse
, (IPTR
) MUIX_C
,
303 MUIA_Text_Contents
, (IPTR
) NULL
,
305 Child
, (IPTR
) (copyrightObject
= (Object
*)TextObject
,
306 MUIA_Text_PreParse
, (IPTR
) MUIX_C
,
307 MUIA_Text_Contents
, (IPTR
) NULL
,
309 Child
, (IPTR
) (descriptionGroup
= (Object
*)VGroup
,
310 Child
, (IPTR
) VSpace(6),
311 Child
, (IPTR
) (descriptionObject
= (Object
*)TextObject
,
312 MUIA_Text_PreParse
, (IPTR
) MUIX_I MUIX_C
,
313 MUIA_Text_Contents
, (IPTR
) NULL
,
316 Child
, (IPTR
) VSpace(6),
317 Child
, (IPTR
) RegisterGroup(pages
),
318 Child
, (IPTR
) ListviewObject
,
319 MUIA_Listview_List
, (IPTR
) (authorsList
= (Object
*)ListObject
,
323 Child
, (IPTR
) ListviewObject
,
324 MUIA_Listview_List
, (IPTR
) (sponsorsList
= (Object
*)ListObject
,
331 TAG_MORE
, (IPTR
) message
->ops_AttrList
334 if (self
== NULL
) goto error
;
336 data
= INST_DATA(CLASS
, self
);
337 data
->awd_Catalog
= catalog
;
338 data
->awd_Pool
= pool
;
339 data
->awd_RootGroup
= rootGroup
;
340 data
->awd_ImageGroup
= imageGroup
;
341 data
->awd_ImageObject
= imageObject
;
342 data
->awd_VersionObject
= versionObject
;
343 data
->awd_CopyrightObject
= copyrightObject
;
344 data
->awd_DescriptionGroup
= descriptionGroup
;
345 data
->awd_DescriptionObject
= descriptionObject
;
346 data
->awd_Title
= title
;
347 data
->awd_VersionNumber
= versionNumber
;
348 data
->awd_VersionDate
= versionDate
;
349 data
->awd_VersionExtra
= versionExtra
;
350 data
->awd_Copyright
= copyright
;
351 data
->awd_Description
= description
;
353 if (authorsTags
!= NULL
) NamesToList(authorsList
, authorsTags
, data
);
354 if (sponsorsTags
!= NULL
) NamesToList(sponsorsList
, sponsorsTags
, data
);
356 /* Setup notifications */
359 self
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
360 (IPTR
) self
, 2, MUIA_Window_Open
, FALSE
366 if (catalog
!= NULL
) CloseCatalog(catalog
);
371 IPTR AboutWindow__MUIM_Window_Setup
373 Class
*CLASS
, Object
*self
, Msg message
376 struct AboutWindow_DATA
*data
= INST_DATA(CLASS
, self
);
377 struct Catalog
*catalog
= data
->awd_Catalog
;
378 STRPTR string
= NULL
;
380 if (!DoSuperMethodA(CLASS
, self
, message
)) return FALSE
;
382 /*= Setup window title =================================================*/
384 STRPTR buffer
= NULL
;
387 string
= data
->awd_Title
;
390 GET(self
, MUIA_AboutWindow_Title
, &string
);
392 if (string
!= IGNORE
)
396 GET(_app(self
), MUIA_Application_Title
, &string
);
401 length
= strlen(string
) + strlen(_(MSG_ABOUT
)) + 2; /* space + newline */
402 buffer
= AllocVec(length
, MEMF_ANY
);
407 strlcat(buffer
, _(MSG_ABOUT
), length
);
408 strlcat(buffer
, " ", length
);
409 strlcat(buffer
, string
, length
);
411 set(self
, MUIA_Window_Title
, buffer
);
420 /*= Setup image ========================================================*/
421 if (data
->awd_ImageObject
== NULL
)
423 DoMethod(data
->awd_RootGroup
, OM_REMMEMBER
, (IPTR
) data
->awd_ImageGroup
);
426 /*= Setup version ======================================================*/
428 The version string will have the format:
429 MUIX_B"<title>"MUIX_N" <version> (<date>) [<extra>]"
432 STRPTR title
= data
->awd_Title
,
433 versionNumber
= data
->awd_VersionNumber
,
434 versionDate
= data
->awd_VersionDate
,
435 versionExtra
= data
->awd_VersionExtra
,
439 /*- Setup default values -------------------------------------------*/
442 GET(_app(self
), MUIA_Application_Title
, &title
);
445 if (versionNumber
== NULL
)
447 GET(_app(self
), MUIA_Application_Version_Number
, &versionNumber
);
450 if (versionDate
== NULL
)
452 GET(_app(self
), MUIA_Application_Version_Date
, &versionDate
);
455 if (versionExtra
== NULL
)
457 GET(_app(self
), MUIA_Application_Version_Extra
, &versionExtra
);
460 /* Simplify later checks a little */
461 if (title
== IGNORE
) title
= NULL
;
462 if (versionNumber
== IGNORE
) versionNumber
= NULL
;
463 if (versionDate
== IGNORE
) versionDate
= NULL
;
464 if (versionExtra
== IGNORE
) versionExtra
= NULL
;
466 /*- Calculate length -----------------------------------------------*/
469 length
+= strlen(MUIX_B
) + strlen(title
) + strlen(MUIX_N
) + 1;
472 if (versionNumber
!= NULL
)
474 length
+= 1 /* space */ + strlen(versionNumber
);
477 if (versionDate
!= NULL
)
479 length
+= 1 /* space */ + 1 /* ( */ + strlen(versionDate
) + 1 /* ) */;
482 if (versionExtra
!= NULL
)
484 length
+= 1 /* space */ + 1 /* [ */ + strlen(versionExtra
) + 1 /* ] */;
487 /*- Setup version object -------------------------------------------*/
490 /*- Allocate memory --------------------------------------------*/
491 buffer
= AllocVec(length
, MEMF_ANY
);
497 /*- Generate text ------------------------------------------*/
500 strlcat(buffer
, MUIX_B
, length
);
501 strlcat(buffer
, title
, length
);
502 strlcat(buffer
, MUIX_N
, length
);
505 if (versionNumber
!= NULL
)
507 strlcat(buffer
, " ", length
);
508 strlcat(buffer
, versionNumber
, length
);
511 if (versionDate
!= NULL
)
513 strlcat(buffer
, " (", length
);
514 strlcat(buffer
, versionDate
, length
);
515 strlcat(buffer
, ")", length
);
518 if (versionExtra
!= NULL
)
520 strlcat(buffer
, " [", length
);
521 strlcat(buffer
, versionExtra
, length
);
522 strlcat(buffer
, "]", length
);
525 set(data
->awd_VersionObject
, MUIA_Text_Contents
, buffer
);
526 FreeVec(buffer
); /* don't need it anymore */
532 data
->awd_RootGroup
, OM_REMMEMBER
, (IPTR
) data
->awd_VersionObject
538 /*= Setup copyright ====================================================*/
539 if (data
->awd_Copyright
== NULL
)
541 GET(_app(self
), MUIA_Application_Copyright
, &data
->awd_Copyright
);
544 if (data
->awd_Copyright
!= IGNORE
&& data
->awd_Copyright
!= NULL
)
546 SET(data
->awd_CopyrightObject
, MUIA_Text_Contents
, data
->awd_Copyright
);
550 DoMethod(data
->awd_RootGroup
, OM_REMMEMBER
, (IPTR
) data
->awd_CopyrightObject
);
553 /*= Setup description ==================================================*/
554 if (data
->awd_Description
== NULL
)
556 GET(_app(self
), MUIA_Application_Description
, &data
->awd_Description
);
559 if (data
->awd_Description
!= IGNORE
&& data
->awd_Description
!= NULL
)
563 data
->awd_DescriptionObject
,
564 MUIA_Text_Contents
, data
->awd_Description
571 data
->awd_RootGroup
, OM_REMMEMBER
, (IPTR
) data
->awd_DescriptionGroup
575 /* We no longer need to know whether to IGNORE or not */
576 if (data
->awd_Title
== IGNORE
) data
->awd_Title
= NULL
;
577 if (data
->awd_VersionNumber
== IGNORE
) data
->awd_VersionNumber
= NULL
;
578 if (data
->awd_VersionDate
== IGNORE
) data
->awd_VersionDate
= NULL
;
579 if (data
->awd_VersionExtra
== IGNORE
) data
->awd_VersionExtra
= NULL
;
580 if (data
->awd_Copyright
== IGNORE
) data
->awd_Copyright
= NULL
;
581 if (data
->awd_Description
== IGNORE
) data
->awd_Description
= NULL
;
586 IPTR AboutWindow__OM_DISPOSE
588 Class
*CLASS
, Object
*self
, Msg message
591 struct AboutWindow_DATA
*data
= INST_DATA(CLASS
, self
);
595 data
->awd_Title
, data
->awd_VersionNumber
, data
->awd_VersionDate
,
596 data
->awd_VersionExtra
, data
->awd_Copyright
, data
->awd_VersionExtra
599 for (i
= 0; i
< (sizeof(ptrs
) / sizeof(APTR
)); i
++)
601 if (ptrs
[i
] != NULL
) FreeVec(ptrs
[i
]);
604 if (data
->awd_Pool
!= NULL
) DeletePool(data
->awd_Pool
);
606 if (data
->awd_Catalog
!= NULL
) CloseCatalog(data
->awd_Catalog
);
608 return DoSuperMethodA(CLASS
, self
, message
);