use for all targets
[AROS.git] / workbench / prefs / appearance / themepreview.c
blobc0fcf730161fda493e01a0b9ef271d94d093b789
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
9 #define MUIMASTER_YES_INLINE_STDARG
11 #include <zune/customclasses.h>
12 #include <zune/prefseditor.h>
14 #include <proto/graphics.h>
15 #include <proto/intuition.h>
16 #include <proto/muimaster.h>
17 #include <proto/utility.h>
19 #include <proto/alib.h>
21 #ifndef GRAPHICS_RASTPORT_H
22 # include <graphics/rastport.h>
23 #endif
25 #include <stdlib.h>
27 #include "locale.h"
28 #include "themepreview.h"
30 #if (0)
31 static CONST_STRPTR PREVIEWFILE_BASE = "THEME:preview";
32 static CONST_STRPTR PREVIEWFILE_WIN = "THEME:preview.win";
33 static CONST_STRPTR PREVIEWFILE_ZUNE = "THEME:preview.zune";
34 static CONST_STRPTR PREVIEWFILE_WAND = "THEME:preview.wand";
35 #endif
37 #define PREVIEW_WIDTH 256
38 #define PREVIEW_HEIGHT 150
40 /*** Instance Data **********************************************************/
42 struct ThemePreview_DATA
44 char *tp_Theme;
45 struct RastPort *tp_Buffer;
48 /*** Macros *****************************************************************/
49 #define SETUP_INST_DATA struct ThemePreview_DATA *data = INST_DATA(CLASS, self)
51 /*** Methods ****************************************************************/
52 Object *ThemePreview__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
54 D(bug("[ThemePreview] %s()\n", __PRETTY_FUNCTION__));
56 self = (Object *) DoSuperNewTags
58 CLASS, self, NULL,
60 MUIA_Frame, MUIV_Frame_ReadList,
61 MUIA_FrameTitle, _(MSG_PREVIEW),
63 TAG_DONE
66 #if (0)
67 if (self)
69 SETUP_INST_DATA;
71 #endif
73 return self;
76 IPTR ThemePreview__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
78 #if (0)
79 SETUP_INST_DATA;
80 #endif
82 D(bug("[ThemePreview] %s()\n", __PRETTY_FUNCTION__));
84 return DoSuperMethodA(CLASS, self, message);
87 IPTR ThemePreview__OM_SET(Class *CLASS, Object *self, struct opSet *message)
89 #if (0)
90 SETUP_INST_DATA;
91 #endif
92 struct TagItem *tags, *tag;
94 for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
96 switch (tag->ti_Tag)
98 case MUIA_ThemePreview_Theme:
100 D(bug("[ThemePreview] %s: Theme '%s'\n", __PRETTY_FUNCTION__, tag->ti_Data));
101 // TODO: Composite preview if available..
102 break;
107 return DoSuperMethodA(CLASS, self, message);
110 IPTR ThemePreview__OM_GET(Class *CLASS, Object *self, struct opGet *message)
112 SETUP_INST_DATA;
114 switch (message->opg_AttrID)
116 case MUIA_ThemePreview_Theme:
117 *message->opg_Storage = (IPTR)data->tp_Theme;
118 break;
119 default:
120 return DoSuperMethodA(CLASS, self, (Msg)message);
123 return TRUE;
126 IPTR ThemePreview__MUIM_AskMinMax(struct IClass *CLASS, Object *self, struct MUIP_AskMinMax *message)
128 ULONG rc = DoSuperMethodA(CLASS, self, (Msg) message);
130 D(bug("[ThemePreview] %s()\n", __PRETTY_FUNCTION__));
132 message->MinMaxInfo->MinWidth += PREVIEW_WIDTH;
133 message->MinMaxInfo->MinHeight += PREVIEW_HEIGHT;
135 message->MinMaxInfo->DefWidth += PREVIEW_WIDTH;
136 message->MinMaxInfo->DefHeight += PREVIEW_HEIGHT;
138 message->MinMaxInfo->MaxWidth = MUI_MAXMAX;
139 message->MinMaxInfo->MaxHeight = MUI_MAXMAX;
141 return rc;
144 IPTR ThemePreview__MUIM_Draw(struct IClass *CLASS, Object *self, struct MUIP_Draw *message)
146 SETUP_INST_DATA;
148 APTR clip;
150 D(bug("[ThemePreview] %s()\n", __PRETTY_FUNCTION__));
152 DoSuperMethodA(CLASS, self, (Msg)message);
154 if (data->tp_Buffer)
156 // Render Preview..
157 clip = MUI_AddClipping(muiRenderInfo(self), _mleft(self), _mtop(self), _mright(self) - _mleft(self) + 1, _mbottom(self) - _mtop(self) + 1);
158 BltBitMapRastPort(data->tp_Buffer->BitMap,
159 _mleft(self), _mtop(self),
160 _rp(self),
161 0, 0,
162 PREVIEW_WIDTH, PREVIEW_HEIGHT,
163 0xC0);
164 MUI_RemoveClipping(muiRenderInfo(self), clip);
166 else
168 char *unavailableStr = (char *)_(MSG_NOPREVIEW);
169 int len = strlen(unavailableStr);
170 struct TextExtent te;
172 len = TextFit(_rp(self), unavailableStr, len, &te, NULL, 1, _mright(self) - _mleft(self) + 1, _mbottom(self) - _mtop(self) + 1);
174 SetDrMd(_rp(self), JAM1);
175 Move(_rp(self), _mleft(self) + ((_mright(self) - _mleft(self) + 1) >> 1) - (te.te_Width >> 1), _mtop(self) + ((_mbottom(self) - _mtop(self) + 1) >> 1) - (te.te_Height >> 1));
176 Text(_rp(self), unavailableStr, len);
178 return 0;
181 /*** Setup ******************************************************************/
182 ZUNE_CUSTOMCLASS_6
184 ThemePreview, NULL, MUIC_Area, NULL,
185 MUIM_Draw, struct MUIP_Draw *,
186 MUIM_AskMinMax, struct MUIP_AskMinMax *,
187 OM_GET, struct opGet *,
188 OM_SET, struct opSet *,
189 OM_NEW, struct opSet *,
190 OM_DISPOSE, Msg