include unistd for swab.
[AROS-Contrib.git] / vpdf / arrowstring_class.c
blobccbf5e2759e7caefb48b56aacce29d377bb902f9
1 /****************************************************************************/
2 /* ArrowString class */
3 /* By Michal Rybinski */
4 /****************************************************************************/
6 /*
7 #include "../common/mui_misc.h"
8 #include "../common/mui_help.h"
9 #include "../common/help.h"
10 #include "../macros/vapor.h"
11 #include <emul/emulregs.h>
14 #include <proto/alib.h>
15 #include <proto/muimaster.h>
16 #include <proto/utility.h>
18 #include <string.h>
19 #include <private/vapor/vapor.h>
20 #include "arrowstring_class.h"
21 #include "util.h"
24 struct Data
26 Object *ST_Number;
27 Object *BT_Increase;
28 Object *BT_Decrease;
30 ULONG Step;
31 ULONG Min;
34 ULONG ArrowString_New(struct IClass *cl, Object *obj, struct opSet *msg)
36 struct Data tmp;
38 memset(&tmp, sizeof(tmp), 0);
40 obj = (Object *) DoSuperNew(cl, obj, MUIA_Group_Horiz, TRUE, MUIA_Group_HorizSpacing, 0,
41 Child, tmp.ST_Number = StringObject, StringFrame,
42 MUIA_CycleChain, TRUE,
43 MUIA_String_Accept, "0123456789",
44 MUIA_String_MaxLen, 5,
45 MUIA_FixWidthTxt, "123456",
46 MUIA_String_Format, MUIV_String_Format_Right,
47 MUIA_String_Contents, (IPTR) "1",
48 End,
49 Child, tmp.BT_Increase = ImageObject, ImageButtonFrame,
50 MUIA_InputMode, MUIV_InputMode_RelVerify,
51 MUIA_Image_Spec, MUII_ArrowUp,
52 MUIA_Image_FreeVert, TRUE,
53 MUIA_Background, MUII_ButtonBack,
54 MUIA_ShowSelState, FALSE,
55 End,
56 Child, tmp.BT_Decrease = ImageObject, ImageButtonFrame,
57 MUIA_InputMode, MUIV_InputMode_RelVerify,
58 MUIA_Image_Spec, MUII_ArrowDown,
59 MUIA_Image_FreeVert, TRUE,
60 MUIA_Background, MUII_ButtonBack,
61 MUIA_ShowSelState, FALSE,
62 End,
64 TAG_MORE, msg->ops_AttrList);
66 if (obj)
68 struct Data *data = INST_DATA(cl, obj);
69 struct TagItem *ti;
71 memcpy(data, &tmp, sizeof(tmp));
73 data->Step = 1;
74 data->Min =1;
76 if ((ti = FindTagItem(MA_ArrowString_Step, msg->ops_AttrList)))
78 data->Step = ti->ti_Data;
82 if ((ti = FindTagItem(MA_ArrowString_Min, msg->ops_AttrList)))
84 data->Min = ti->ti_Data;
87 DoMethod(data->BT_Increase, MUIM_Notify, MUIA_Timer, MUIV_EveryTime,
88 obj, 1, MM_ArrowString_Increase);
90 DoMethod(data->BT_Decrease, MUIM_Notify, MUIA_Timer, MUIV_EveryTime,
91 obj, 1, MM_ArrowString_Decrease);
93 DoMethod(data->ST_Number, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
94 obj, 3, MUIM_Set, MA_ArrowString_Changed, TRUE);
96 return (ULONG)obj;
99 return (0);
102 ULONG ArrowString_Get(struct IClass *cl, Object *obj, struct opGet *msg)
104 switch (msg->opg_AttrID)
106 case MA_ArrowString_Changed:
108 return TRUE;
112 return(DoSuperMethodA(cl, obj, (APTR)msg));
115 ULONG ArrowString_Increase(struct IClass *cl, Object *obj)
117 struct Data *data = INST_DATA(cl, obj);
118 ULONG no = xget(data->ST_Number, MUIA_String_Integer);
120 set(data->ST_Number, MUIA_String_Integer, no + data->Step);
121 set(obj, MA_ArrowString_Changed, TRUE);
123 return (0);
126 ULONG ArrowString_Decrease(struct IClass *cl, Object *obj)
128 struct Data *data = INST_DATA(cl, obj);
129 ULONG no = xget(data->ST_Number, MUIA_String_Integer);
131 if (no > data->Min)
133 set(data->ST_Number, MUIA_String_Integer, no - data->Step);
134 set(obj, MA_ArrowString_Changed, TRUE);
137 return (0);
140 ULONG ArrowString_Dispose(struct IClass *cl, Object *obj, Msg msg)
142 return(DoSuperMethodA(cl, obj, (Msg)msg));
145 BEGINMTABLE
146 case OM_NEW : return(ArrowString_New (cl, obj, (APTR)msg));
147 case OM_DISPOSE : return(ArrowString_Dispose (cl, obj, (APTR)msg));
148 case OM_GET : return(ArrowString_Get (cl, obj, (APTR)msg));
149 case MM_ArrowString_Increase : return(ArrowString_Increase (cl, obj));
150 case MM_ArrowString_Decrease : return(ArrowString_Decrease (cl, obj));
151 ENDMTABLE
153 DECSUBCLASS_NC(MUIC_Group, ArrowStringClass)