revert between 56095 -> 55830 in arch
[AROS.git] / workbench / prefs / palette / paleditor.c
blob7facea2e0a1fdfa781114370316a75ceebf5889d
1 /*
2 Copyright 2010-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/asl.h>
11 #include <libraries/mui.h>
12 #include <prefs/palette.h>
13 #include <prefs/prefhdr.h>
14 /* #define DEBUG 1 */
15 #include <zune/customclasses.h>
16 #include <zune/prefseditor.h>
18 #include <proto/alib.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
21 #include <proto/utility.h>
22 #include <proto/muimaster.h>
23 #include <proto/dos.h>
24 #include <proto/iffparse.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdlib.h>
30 #include <aros/debug.h>
32 #include "locale.h"
33 #include "paleditor.h"
34 #include "prefs.h"
36 STATIC CONST_STRPTR pennames[9];
39 without this initial palette we can't later set MUIA_Palette_Entries.
40 This is probably a bug in Zune.
42 STATIC const struct MUI_Palette_Entry initialpens[9] =
44 {0, 0, 0, 0, 0},
45 {1, 0, 0, 0, 0},
46 {2, 0, 0, 0, 0},
47 {3, 0, 0, 0, 0},
48 {4, 0, 0, 0, 0},
49 {5, 0, 0, 0, 0},
50 {6, 0, 0, 0, 0},
51 {7, 0, 0, 0, 0},
52 {MUIV_Palette_Entry_End, 0, 0, 0, 0}
55 /*** Instance Data **********************************************************/
56 struct PalEditor_DATA
58 Object *palpe_palette;
61 STATIC VOID PalPrefs2Gadgets(struct PalEditor_DATA *data);
62 STATIC VOID Gadgets2PalPrefs(struct PalEditor_DATA *data);
64 /*** Macros *****************************************************************/
65 #define SETUP_INST_DATA struct PalEditor_DATA *data = INST_DATA(CLASS, self)
67 /*** Methods ****************************************************************/
68 Object *PalEditor__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
70 Object *palpe_palette;
72 pennames[0] = _(MSG_PEN0);
73 pennames[1] = _(MSG_PEN1);
74 pennames[2] = _(MSG_PEN2);
75 pennames[3] = _(MSG_PEN3);
76 pennames[4] = _(MSG_PEN4);
77 pennames[5] = _(MSG_PEN5);
78 pennames[6] = _(MSG_PEN6);
79 pennames[7] = _(MSG_PEN7);
80 pennames[8] = NULL;
82 self = (Object *) DoSuperNewTags
84 CLASS, self, NULL,
85 MUIA_PrefsEditor_Name, __(MSG_WINTITLE),
86 MUIA_PrefsEditor_Path, (IPTR) "SYS/palette.prefs",
87 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/Palette",
88 Child, HGroup,
89 Child, (IPTR)(palpe_palette = (Object *)PaletteObject,
90 MUIA_Palette_Entries, (IPTR)initialpens,
91 MUIA_Palette_Names, (IPTR)pennames,
92 End),
93 End,
94 TAG_DONE
97 if (self)
99 SETUP_INST_DATA;
101 data->palpe_palette = palpe_palette;
103 DoMethod
105 data->palpe_palette, MUIM_Notify, MUIA_Palette_Entries, MUIV_EveryTime,
106 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
110 return self;
113 STATIC VOID Gadgets2PalPrefs (struct PalEditor_DATA *data)
115 LONG i;
116 struct MUI_Palette_Entry *currentpens =
117 (struct MUI_Palette_Entry *)XGET(data->palpe_palette, MUIA_Palette_Entries);
119 for (i = 0; i < 8; i++)
121 paletteprefs.pap_Colors[i].ColorIndex = currentpens[i].mpe_ID;
122 paletteprefs.pap_Colors[i].Red = currentpens[i].mpe_Red >> 16;
123 paletteprefs.pap_Colors[i].Green = currentpens[i].mpe_Green >> 16;
124 paletteprefs.pap_Colors[i].Blue = currentpens[i].mpe_Blue >> 16;
128 STATIC VOID PalPrefs2Gadgets(struct PalEditor_DATA *data)
130 LONG i;
131 struct MUI_Palette_Entry currentpens[9];
133 for (i = 0; i < 8; i++)
135 currentpens[i].mpe_ID = paletteprefs.pap_Colors[i].ColorIndex;
136 currentpens[i].mpe_Red = paletteprefs.pap_Colors[i].Red << 16;
137 currentpens[i].mpe_Green = paletteprefs.pap_Colors[i].Green << 16;
138 currentpens[i].mpe_Blue = paletteprefs.pap_Colors[i].Blue << 16;
140 currentpens[8].mpe_ID = MUIV_Palette_Entry_End;
141 NNSET(data->palpe_palette, MUIA_Palette_Entries, currentpens);
144 IPTR PalEditor__MUIM_PrefsEditor_ImportFH
146 Class *CLASS, Object *self,
147 struct MUIP_PrefsEditor_ImportFH *message
150 SETUP_INST_DATA;
151 BOOL success = TRUE;
153 success = Prefs_ImportFH(message->fh);
154 if (success) PalPrefs2Gadgets(data);
156 return success;
159 IPTR PalEditor__MUIM_PrefsEditor_ExportFH
161 Class *CLASS, Object *self,
162 struct MUIP_PrefsEditor_ExportFH *message
165 SETUP_INST_DATA;
166 BOOL success = TRUE;
168 Gadgets2PalPrefs(data);
169 success = Prefs_ExportFH(message->fh);
171 return success;
174 IPTR PalEditor__MUIM_PrefsEditor_SetDefaults
176 Class *CLASS, Object *self, Msg message
179 SETUP_INST_DATA;
180 BOOL success = TRUE;
182 success = Prefs_Default();
183 if (success) PalPrefs2Gadgets(data);
185 return success;
188 /*** Setup ******************************************************************/
189 ZUNE_CUSTOMCLASS_4
191 PalEditor, NULL, MUIC_PrefsEditor, NULL,
192 OM_NEW, struct opSet *,
193 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
194 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
195 MUIM_PrefsEditor_SetDefaults, Msg