Merged in v 26.12.
[AROS-Contrib.git] / mui / classes / thebar / mcp / library.c
blobfa1d93974fb9f878c985b8304571333caeaed2cd
1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2013 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
19 $Id$
21 ***************************************************************************/
23 #include "class.h"
24 #include "private.h"
25 #include "version.h"
26 #include <mcc_common.h>
28 /******************************************************************************/
29 /* include the minimal startup code to be able to start the class from a */
30 /* shell without crashing the system */
31 /******************************************************************************/
32 #include "shellstart.c"
34 #define VERSION LIB_VERSION
35 #define REVISION LIB_REVISION
37 #define CLASS "TheBar.mcp"
38 #define SUPERCLASSP MUIC_Mccprefs
40 #define INSTDATAP InstData
42 #define USERLIBID CLASS " " LIB_REV_STRING " [" SYSTEMSHORT "/" CPU "] (" LIB_DATE ") " LIB_COPYRIGHT
43 #define MASTERVERSION 19
45 #define CLASSINIT
46 #define CLASSEXPUNGE
48 #define USEDCLASSES used_mccs
49 static const char *used_mccs[] = { "TheBar.mcc", "TheBarVirt.mcc", "TheButton.mcc", NULL };
51 #define MIN_STACKSIZE 8192
53 /******************************************************************************/
55 struct Library *DataTypesBase = NULL;
56 struct Library *IFFParseBase = NULL;
57 #if !defined(__amigaos4__)
58 struct Library *CyberGfxBase = NULL;
59 #endif
61 #if !defined(__amigaos4__) && !defined(__MORPHOS__)
62 struct LocaleBase *LocaleBase = NULL;
63 #else
64 struct Library *LocaleBase = NULL;
65 #endif
67 #if defined(__amigaos4__)
68 struct DataTypesIFace *IDataTypes = NULL;
69 //struct CyberGfxIFace *ICyberGfx = NULL;
70 struct IFFParseIFace *IIFFParse = NULL;
71 struct LocaleIFace *ILocale = NULL;
72 #endif
74 // some variables we carry for the whole lifetime of the lib
75 #if !defined(__MORPHOS__) && !defined(__amigaos4__)
76 struct MUI_CustomClass *lib_coloradjust = NULL;
77 struct MUI_CustomClass *lib_penadjust = NULL;
78 struct MUI_CustomClass *lib_backgroundadjust = NULL;
79 struct MUI_CustomClass *lib_poppen = NULL;
80 struct MUI_CustomClass *lib_popbackground = NULL;
81 #endif
82 struct Catalog *lib_cat = NULL;
83 ULONG lib_flags = 0;
85 #if !defined(__MORPHOS__)
86 static BOOL nbitmapCanHandleRawData;
87 #endif
89 /******************************************************************************/
91 static BOOL ClassInit(UNUSED struct Library *base);
92 static BOOL ClassExpunge(UNUSED struct Library *base);
94 /******************************************************************************/
95 #define USE_ICON8_COLORS
96 #define USE_ICON8_BODY
98 #include "icon.h"
100 #if defined(__MORPHOS__)
101 #include <mui/Rawimage_mcc.h>
102 #else
103 #include <mui/NBitmap_mcc.h>
104 #endif
106 static Object *get_prefs_image(void)
108 Object *obj;
110 #if !defined(__MORPHOS__)
111 if(nbitmapCanHandleRawData == TRUE)
113 obj = NBitmapObject,
114 MUIA_FixWidth, ICON32_WIDTH,
115 MUIA_FixHeight, ICON32_HEIGHT,
116 MUIA_NBitmap_Type, MUIV_NBitmap_Type_ARGB32,
117 MUIA_NBitmap_Normal, icon32,
118 MUIA_NBitmap_Width, ICON32_WIDTH,
119 MUIA_NBitmap_Height, ICON32_HEIGHT,
120 End;
122 else
124 obj = NULL;
126 #else
128 no truecolor image data for MorphOS yet
129 obj = RawimageObject,
130 MUIA_Rawimage_Data, icon32,
131 End;
133 obj = NULL;
134 #endif
136 // if the 32bit image data couldn't be loaded
137 // we fall back to the 8bit icon
138 if(obj == NULL)
140 obj = BodychunkObject,\
141 MUIA_FixWidth, ICON8_WIDTH,\
142 MUIA_FixHeight, ICON8_HEIGHT,\
143 MUIA_Bitmap_Width, ICON8_WIDTH ,\
144 MUIA_Bitmap_Height, ICON8_HEIGHT,\
145 MUIA_Bodychunk_Depth, ICON8_DEPTH,\
146 MUIA_Bodychunk_Body, (UBYTE *)icon8_body,\
147 MUIA_Bodychunk_Compression, ICON8_COMPRESSION,\
148 MUIA_Bodychunk_Masking, ICON8_MASKING,\
149 MUIA_Bitmap_SourceColors, (ULONG *)icon8_colors,\
150 MUIA_Bitmap_Transparent, 0,\
151 End;
154 return obj;
157 #define PREFSIMAGEOBJECT get_prefs_image()
159 #include "mccinit.c"
161 /******************************************************************************/
163 static BOOL ClassInit(UNUSED struct Library *base)
165 ENTER();
167 if((DataTypesBase = OpenLibrary("datatypes.library",37)) &&
168 GETINTERFACE(IDataTypes,struct DataTypesIFace *,DataTypesBase) &&
169 (IFFParseBase = OpenLibrary("iffparse.library",37)) &&
170 GETINTERFACE(IIFFParse,struct IFFParseIFace *,IFFParseBase) &&
171 (LocaleBase = (APTR)OpenLibrary("locale.library",36)) &&
172 GETINTERFACE(ILocale,struct LocaleIFace *,LocaleBase))
174 BOOL success = TRUE;
176 // check for MUI 3.9+
177 if(LIB_VERSION_IS_AT_LEAST(MUIMasterBase, 20, 0))
179 lib_flags |= BASEFLG_MUI20;
181 // check for MUI 4.0+
182 if(LIB_VERSION_IS_AT_LEAST(MUIMasterBase, 20, 5500))
183 lib_flags |= BASEFLG_MUI4;
186 // on MUI 3.1 system's we do have to
187 // initialize our subclasses as well
188 #if !defined(__MORPHOS__) && !defined(__amigaos4__) && !defined(__AROS__)
189 if(!(lib_flags & BASEFLG_MUI20))
191 if(!initColoradjust() ||
192 !initPenadjust() ||
193 !initBackgroundadjust() ||
194 !initPoppen() ||
195 !initPopbackground())
197 success = FALSE;
200 #endif
202 if(success == TRUE)
204 initStrings();
206 // we open the cybgraphics.library but without failing if
207 // it doesn't exist
208 #if !defined(__amigaos4__)
209 CyberGfxBase = OpenLibrary("cybergraphics.library", 41);
211 if(!GETINTERFACE(ICyberGfx, struct CyberGfxIFace *, CyberGfxBase))
213 CloseLibrary(CyberGfxBase);
214 CyberGfxBase = NULL;
217 #endif
219 #if !defined(__MORPHOS__)
221 struct Library *nbitmapMcc;
223 nbitmapCanHandleRawData = FALSE;
225 // we need at least NBitmap.mcc V15.8 to be able to let it handle raw image data
226 if((nbitmapMcc = OpenLibrary("mui/NBitmap.mcc", 0)) != NULL)
228 SHOWVALUE(DBF_ALWAYS, nbitmapMcc->lib_Version);
229 SHOWVALUE(DBF_ALWAYS, nbitmapMcc->lib_Revision);
231 if(nbitmapMcc->lib_Version > 15 || (nbitmapMcc->lib_Version == 15 && nbitmapMcc->lib_Revision >= 8))
232 nbitmapCanHandleRawData = TRUE;
234 CloseLibrary(nbitmapMcc);
237 SHOWVALUE(DBF_ALWAYS, nbitmapCanHandleRawData);
239 #endif
241 lib_flags |= BASEFLG_Init;
243 RETURN(TRUE);
244 return TRUE;
248 ClassExpunge(base);
250 RETURN(FALSE);
251 return FALSE;
254 /******************************************************************************/
256 static BOOL
257 ClassExpunge(UNUSED struct Library *base)
259 ENTER();
261 #if !defined(__MORPHOS__) && !defined(__amigaos4__) && !defined(__AROS__)
262 if(!(lib_flags & BASEFLG_MUI20))
264 freePopbackground();
265 freePoppen();
266 freeBackgroundadjust();
267 freePenadjust();
268 freeColoradjust();
270 #endif
272 #if !defined(__amigaos4__)
273 if(CyberGfxBase != NULL)
275 DROPINTERFACE(ICyberGfx);
276 CloseLibrary(CyberGfxBase);
277 CyberGfxBase = NULL;
279 #endif
281 if(LocaleBase != NULL)
283 if(lib_cat != NULL)
285 CloseCatalog(lib_cat);
286 lib_cat = NULL;
288 DROPINTERFACE(ILocale);
289 CloseLibrary((struct Library *)LocaleBase);
290 LocaleBase = NULL;
293 if(IFFParseBase != NULL)
295 DROPINTERFACE(IIFFParse);
296 CloseLibrary(IFFParseBase);
297 IFFParseBase = NULL;
300 if(DataTypesBase != NULL)
302 DROPINTERFACE(IDataTypes);
303 CloseLibrary(DataTypesBase);
304 DataTypesBase = NULL;
307 lib_flags &= ~(BASEFLG_Init|BASEFLG_MUI20|BASEFLG_MUI4);
309 RETURN(TRUE);
310 return TRUE;
313 /******************************************************************************/