Some "cast to pointer from integer of different size" warnings removed.
[AROS-Contrib.git] / MultiMedia / playcdda / seekbar.c
blobfe6a582539d3f1ae110b724b1e07fe8a63b96598
1 /* Copyright 2010-2011 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include "seekbar.h"
28 #include <proto/utility.h>
29 #include <proto/intuition.h>
30 #include <proto/muimaster.h>
31 #include <proto/alib.h>
33 struct SeekBarData {
34 ULONG level;
35 ULONG min, max;
38 static AROS_UFP3(IPTR, SeekBar_Dispatch,
39 AROS_UFPA(Class *, cl, A0),
40 AROS_UFPA(Object *, o, A2),
41 AROS_UFPA(Msg, msg, A1)
44 struct MUI_CustomClass *SeekBar_CreateClass (void) {
45 return MUI_CreateCustomClass(NULL, MUIC_Prop, NULL, sizeof(struct SeekBarData), SeekBar_Dispatch);
48 void SeekBar_DeleteClass (struct MUI_CustomClass *cl) {
49 MUI_DeleteCustomClass(cl);
52 static IPTR SeekBar_New(Class *cl, Object *o, struct opSet *ops);
53 static IPTR SeekBar_Set(Class *cl, Object *o, struct opSet *ops);
54 static IPTR SeekBar_Get(Class *cl, Object *o, struct opGet *opg);
56 static AROS_UFH3(IPTR, SeekBar_Dispatch,
57 AROS_UFHA(Class *, cl, A0),
58 AROS_UFHA(Object *, o, A2),
59 AROS_UFHA(Msg, msg, A1)
62 AROS_USERFUNC_INIT
63 switch (msg->MethodID) {
64 case OM_NEW: return SeekBar_New(cl, o, (struct opSet *)msg);
65 case OM_SET: return SeekBar_Set(cl, o, (struct opSet *)msg);
66 case OM_GET: return SeekBar_Get(cl, o, (struct opGet *)msg);
68 return DoSuperMethodA(cl, o, msg);
69 AROS_USERFUNC_EXIT
72 static IPTR SeekBar_New(Class *cl, Object *o, struct opSet *ops) {
73 Object *res;
74 struct TagItem tags[5] = {
75 { MUIA_Prop_Slider, TRUE },
76 { MUIA_Prop_Horiz, TRUE },
77 { MUIA_Prop_Entries, 65536 },
78 { MUIA_Prop_Visible, 1 },
79 { TAG_MORE, (IPTR)ops->ops_AttrList },
81 ops->ops_AttrList = tags;
82 res = (Object *)DoSuperMethodA(cl, o, (Msg)ops);
83 ops->ops_AttrList = (struct TagItem *)tags[4].ti_Data;
84 return (IPTR)res;
87 static IPTR SeekBar_Set(Class *cl, Object *o, struct opSet *ops) {
88 struct SeekBarData *data = INST_DATA(cl, o);
89 struct TagItem *tstate, *tag;
90 IPTR tidata;
91 IPTR res = 0;
93 data->level = XGET(o, MUIA_Prop_First) + data->min;
94 tstate = ops->ops_AttrList;
95 while ((tag = NextTagItem(&tstate))) {
96 tidata = tag->ti_Data;
97 switch (tag->ti_Tag) {
98 case MUIA_Slider_Min:
99 if (data->min != tidata) {
100 data->min = tidata;
101 res++;
103 break;
104 case MUIA_Slider_Max:
105 if (data->max != tidata) {
106 data->max = tidata;
107 res++;
109 break;
110 case MUIA_Slider_Level:
111 if (data->level != tidata) {
112 data->level = tidata;
113 res++;
115 break;
118 if (res) {
119 SetSuperAttrs(cl, o,
120 MUIA_Prop_Entries, data->max - data->min + 1,
121 MUIA_Prop_First, data->level - data->min,
122 TAG_END);
124 res += DoSuperMethodA(cl, o, (Msg)ops);
125 return res;
128 static IPTR SeekBar_Get(Class *cl, Object *o, struct opGet *opg) {
129 struct SeekBarData *data = INST_DATA(cl, o);
130 IPTR *storage = opg->opg_Storage;
131 switch (opg->opg_AttrID) {
132 case MUIA_Slider_Min:
133 *storage = data->min;
134 break;
135 case MUIA_Slider_Max:
136 *storage = data->max;
137 break;
138 case MUIA_Slider_Level:
139 data->level = XGET(o, MUIA_Prop_First) + data->min;
140 *storage = data->level;
141 break;
142 default:
143 return DoSuperMethodA(cl, o, (Msg)opg);
145 return 1;