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/
21 ***************************************************************************/
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"
39 ULONG
Get(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
41 struct InstData
*data
= (struct InstData
*)INST_DATA(cl
, obj
);
44 switch(msg
->opg_AttrID
)
47 ti_Data
= (ULONG
)(data
->Font
? data
->Font
: muiAreaData(obj
)->mad_Font
);
50 case MUIA_ControlChar
:
51 ti_Data
= (ULONG
)data
->CtrlChar
;
54 case MUIA_String_AttachedList
:
55 ti_Data
= (ULONG
)data
->ForwardObject
;
58 case MUIA_String_BufferPos
:
59 ti_Data
= (ULONG
)data
->BufferPos
;
62 case MUIA_String_Acknowledge
:
63 case MUIA_String_Contents
:
64 ti_Data
= (ULONG
)data
->Contents
;
67 case MUIA_String_DisplayPos
:
68 ti_Data
= (ULONG
)data
->DisplayPos
;
71 case MUIA_String_Format
:
72 ti_Data
= (ULONG
)data
->Alignment
;
75 case MUIA_String_Integer
:
76 StrToLong(data
->Contents
, (LONG
*)&ti_Data
);
79 case MUIA_String_MaxLen
:
80 ti_Data
= (ULONG
)data
->MaxLength
;
83 case MUIA_String_Reject
:
84 ti_Data
= (ULONG
)data
->Reject
;
87 case MUIA_String_Secret
:
88 ti_Data
= (data
->Flags
& FLG_Secret
) ? TRUE
: FALSE
;
91 case MUIA_BetterString_KeyUpFocus
:
92 ti_Data
= (ULONG
)data
->KeyUpFocus
;
95 case MUIA_BetterString_KeyDownFocus
:
96 ti_Data
= (ULONG
)data
->KeyDownFocus
;
99 case MUIA_BetterString_SelectSize
:
100 ti_Data
= (data
->Flags
& FLG_BlockEnabled
) ? data
->BlockStop
-data
->BlockStart
: 0;
103 case MUIA_BetterString_StayActive
:
104 ti_Data
= (data
->Flags
& FLG_StayActive
) ? TRUE
: FALSE
;
107 case MUIA_BetterString_NoInput
:
108 ti_Data
= (data
->Flags
& FLG_NoInput
) ? TRUE
: FALSE
;
112 ti_Data
= LIB_VERSION
;
116 ti_Data
= LIB_REVISION
;
120 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
123 *msg
->opg_Storage
= ti_Data
;
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];
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
},
144 tags
= msg
->ops_AttrList
;
145 data
->Flags
= PackBoolTags(data
->Flags
, tags
, boolMap
);
147 while((tag
= NextTagItem(&tags
)))
149 ti_Data
= tag
->ti_Data
;
153 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
156 case MUIA_String_AttachedList
:
157 data
->ForwardObject
= (Object
*)ti_Data
;
160 case MUIA_String_Accept
:
161 data
->Accept
= (STRPTR
)ti_Data
;
164 case MUIA_String_BufferPos
:
165 data
->BufferPos
= (UWORD
)ti_Data
;
166 data
->Flags
&= ~FLG_BlockEnabled
;
169 case MUIA_BetterString_Columns
:
170 data
->Width
= (UWORD
)ti_Data
;
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
;
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
);
194 WORD extra
= strlen(new_str
)-strlen(data
->Contents
);
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;
211 *data
->Contents
= '\0';
212 data
->Flags
&= ~FLG_BlockEnabled
;
213 // data->BlockStart = data->BlockStop = 0;
218 // if(data->Contents != (STRPTR)ti_Data)
219 tag
->ti_Tag
= TAG_IGNORE
;
224 case MUIA_ControlChar
:
225 data
->CtrlChar
= (UBYTE
)ti_Data
;
228 case MUIA_String_DisplayPos
:
229 data
->DisplayPos
= (UWORD
)ti_Data
;
232 case MUIA_String_Format
:
233 data
->Alignment
= (WORD
)ti_Data
;
236 case MUIA_String_MaxLen
:
237 data
->MaxLength
= (UWORD
)ti_Data
;
238 // kprintf("MaxLen: %ld\n", ti_Data);
241 case MUIA_String_Reject
:
242 data
->Reject
= (STRPTR
)ti_Data
;
245 case MUIA_BetterString_KeyUpFocus
:
246 data
->KeyUpFocus
= (Object
*)ti_Data
;
249 case MUIA_BetterString_KeyDownFocus
:
250 data
->KeyDownFocus
= (Object
*)ti_Data
;
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)
260 if(data
->BlockStop
> strlen(data
->Contents
))
261 data
->BlockStop
= strlen(data
->Contents
);
264 case 0x80420d71: /* MUIA_String_Popup */
265 data
->Popup
= (Object
*)ti_Data
;
269 printf("Object: 0x%lx, tag: 0x%lx, Unknown attr: 0x%lx\n", obj, tag->ti_Tag, ti_Data);
273 if(data
->BufferPos
> strlen(data
->Contents
))
274 data
->BufferPos
= strlen(data
->Contents
);
276 MUI_Redraw(obj
, MADF_DRAWUPDATE
);