added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / classes / zune / betterstring / mcc / GetSetAttrs.c
blob74997659aae929a275977f22ac430ec3a105dfba
1 /***************************************************************************
3 BetterString.mcc - A better String gadget MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005 by BetterString.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 BetterString class Support Site: http://www.sf.net/projects/bstring-mcc/
19 $Id$
21 ***************************************************************************/
23 #include <stdio.h>
24 #include <string.h>
26 #include <clib/alib_protos.h>
27 #include <proto/dos.h>
28 #include <proto/exec.h>
29 #include <proto/intuition.h>
30 #include <proto/utility.h>
31 #include <proto/muimaster.h>
32 #include <libraries/mui.h>
34 #include "BetterString_mcc.h"
36 #include "private.h"
37 #include "rev.h"
39 ULONG Get(struct IClass *cl, Object *obj, struct opGet *msg)
41 struct InstData *data = (struct InstData *)INST_DATA(cl, obj);
43 ULONG ti_Data;
44 switch(msg->opg_AttrID)
46 case MUIA_Font:
47 ti_Data = (ULONG)(data->Font ? data->Font : muiAreaData(obj)->mad_Font);
48 break;
50 case MUIA_ControlChar:
51 ti_Data = (ULONG)data->CtrlChar;
52 break;
54 case MUIA_String_AttachedList:
55 ti_Data = (ULONG)data->ForwardObject;
56 break;
58 case MUIA_String_BufferPos:
59 ti_Data = (ULONG)data->BufferPos;
60 break;
62 case MUIA_String_Acknowledge:
63 case MUIA_String_Contents:
64 ti_Data = (ULONG)data->Contents;
65 break;
67 case MUIA_String_DisplayPos:
68 ti_Data = (ULONG)data->DisplayPos;
69 break;
71 case MUIA_String_Format:
72 ti_Data = (ULONG)data->Alignment;
73 break;
75 case MUIA_String_Integer:
76 StrToLong(data->Contents, (LONG *)&ti_Data);
77 break;
79 case MUIA_String_MaxLen:
80 ti_Data = (ULONG)data->MaxLength;
81 break;
83 case MUIA_String_Reject:
84 ti_Data = (ULONG)data->Reject;
85 break;
87 case MUIA_String_Secret:
88 ti_Data = (data->Flags & FLG_Secret) ? TRUE : FALSE;
89 break;
91 case MUIA_BetterString_KeyUpFocus:
92 ti_Data = (ULONG)data->KeyUpFocus;
93 break;
95 case MUIA_BetterString_KeyDownFocus:
96 ti_Data = (ULONG)data->KeyDownFocus;
97 break;
99 case MUIA_BetterString_SelectSize:
100 ti_Data = (data->Flags & FLG_BlockEnabled) ? data->BlockStop-data->BlockStart : 0;
101 break;
103 case MUIA_BetterString_StayActive:
104 ti_Data = (data->Flags & FLG_StayActive) ? TRUE : FALSE;
105 break;
107 case MUIA_BetterString_NoInput:
108 ti_Data = (data->Flags & FLG_NoInput) ? TRUE : FALSE;
109 break;
111 case MUIA_Version:
112 ti_Data = LIB_VERSION;
113 break;
115 case MUIA_Revision:
116 ti_Data = LIB_REVISION;
117 break;
119 default:
120 return DoSuperMethodA(cl, obj, (Msg)msg);
121 break;
123 *msg->opg_Storage = ti_Data;
124 return TRUE;
127 ULONG Set(struct IClass *cl, Object *obj, struct opSet *msg)
129 struct InstData *data = (struct InstData *)INST_DATA(cl, obj);
130 struct TagItem *tags, *tag;
131 UBYTE IntegerString[12];
132 ULONG ti_Data;
134 struct TagItem boolMap[] =
136 { MUIA_Disabled, FLG_Ghosted },
137 { MUIA_String_AdvanceOnCR, FLG_AdvanceOnCr },
138 { MUIA_String_Secret, FLG_Secret },
139 { MUIA_BetterString_StayActive, FLG_StayActive },
140 { MUIA_BetterString_NoInput, FLG_NoInput },
141 { TAG_DONE, NULL }
144 tags = msg->ops_AttrList;
145 data->Flags = PackBoolTags(data->Flags, tags, boolMap);
147 while((tag = NextTagItem(&tags)))
149 ti_Data = tag->ti_Data;
150 switch(tag->ti_Tag)
152 case MUIA_Disabled:
153 MUI_Redraw(obj, MADF_DRAWOBJECT);
154 break;
156 case MUIA_String_AttachedList:
157 data->ForwardObject = (Object *)ti_Data;
158 break;
160 case MUIA_String_Accept:
161 data->Accept = (STRPTR)ti_Data;
162 break;
164 case MUIA_String_BufferPos:
165 data->BufferPos = (UWORD)ti_Data;
166 data->Flags &= ~FLG_BlockEnabled;
167 break;
169 case MUIA_BetterString_Columns:
170 data->Width = (UWORD)ti_Data;
171 break;
173 case MUIA_String_Integer:
174 tag->ti_Tag = TAG_IGNORE;
175 snprintf(IntegerString, 11, "%d", ti_Data);
176 ti_Data = (ULONG)IntegerString;
177 /* The missing break is intended! */
179 case MUIA_String_Contents:
181 STRPTR new_str = (STRPTR)ti_Data;
182 BOOL circular = FALSE;
183 if(new_str)
185 circular = !strcmp(data->Contents, new_str);
186 if(!circular && data->MaxLength && strlen(new_str) > data->MaxLength)
187 circular = !strncmp(data->Contents, new_str, data->MaxLength);
190 if(!circular)
192 if(new_str)
194 WORD extra = strlen(new_str)-strlen(data->Contents);
196 if(extra > 0)
197 data->Contents = (STRPTR)ExpandPool(data->Pool, data->Contents, extra);
199 strcpy(data->Contents, new_str);
200 data->Flags &= ~FLG_BlockEnabled;
201 data->BufferPos = strlen(data->Contents);
202 data->DisplayPos = 0;
203 if(data->MaxLength && data->BufferPos >= data->MaxLength)
205 data->Contents[data->MaxLength-1] = '\0';
206 data->BufferPos = data->MaxLength-1;
209 else
211 *data->Contents = '\0';
212 data->Flags &= ~FLG_BlockEnabled;
213 // data->BlockStart = data->BlockStop = 0;
216 else
218 // if(data->Contents != (STRPTR)ti_Data)
219 tag->ti_Tag = TAG_IGNORE;
222 break;
224 case MUIA_ControlChar:
225 data->CtrlChar = (UBYTE)ti_Data;
226 break;
228 case MUIA_String_DisplayPos:
229 data->DisplayPos = (UWORD)ti_Data;
230 break;
232 case MUIA_String_Format:
233 data->Alignment = (WORD)ti_Data;
234 break;
236 case MUIA_String_MaxLen:
237 data->MaxLength = (UWORD)ti_Data;
238 // kprintf("MaxLen: %ld\n", ti_Data);
239 break;
241 case MUIA_String_Reject:
242 data->Reject = (STRPTR)ti_Data;
243 break;
245 case MUIA_BetterString_KeyUpFocus:
246 data->KeyUpFocus = (Object *)ti_Data;
247 break;
249 case MUIA_BetterString_KeyDownFocus:
250 data->KeyDownFocus = (Object *)ti_Data;
251 break;
253 case MUIA_BetterString_SelectSize:
254 data->BlockStart = data->BufferPos;
255 data->Flags |= FLG_BlockEnabled;
257 data->BlockStop = data->BufferPos+ti_Data;
258 if(data->BlockStop < 0)
259 data->BlockStop = 0;
260 if(data->BlockStop > strlen(data->Contents))
261 data->BlockStop = strlen(data->Contents);
262 break;
264 case 0x80420d71: /* MUIA_String_Popup */
265 data->Popup = (Object *)ti_Data;
266 break;
268 /* default:
269 printf("Object: 0x%lx, tag: 0x%lx, Unknown attr: 0x%lx\n", obj, tag->ti_Tag, ti_Data);
270 break;
271 */ }
273 if(data->BufferPos > strlen(data->Contents))
274 data->BufferPos = strlen(data->Contents);
276 MUI_Redraw(obj, MADF_DRAWUPDATE);
277 return(0);