2 Copyright 1999, David Le Corfec.
3 Copyright 2002-2006, The AROS Development Team.
12 #include <exec/types.h>
14 #include <clib/alib_protos.h>
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <proto/graphics.h>
18 #include <proto/utility.h>
19 #include <proto/dos.h>
20 #include <proto/muimaster.h>
23 #include "muimaster_intern.h"
25 #include "textengine.h"
27 extern struct Library
*MUIMasterBase
;
37 CONST_STRPTR preparse
;
40 LONG xpixel
; /* needed for cursor up/down movements, can be -1 */
41 struct MUI_EventHandlerNode ehn
;
43 LONG update
; /* type of update: 1 - everything,
44 * 2 - insert char, no scroll */
47 #define MTDF_SETMIN (1<<0)
48 #define MTDF_SETMAX (1<<1)
49 #define MTDF_SETVMAX (1<<2)
50 #define MTDF_HICHAR (1<<3)
51 #define MTDF_HICHARIDX (1<<4)
54 static const int __version
= 1;
55 static const int __revision
= 1;
57 static void setup_text(struct MUI_TextData
*data
, Object
*obj
);
59 /**************************************************************************
61 **************************************************************************/
62 IPTR
Text__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
64 struct MUI_TextData
*data
;
65 struct TagItem
*tags
, *tag
;
67 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
71 data
= INST_DATA(cl
, obj
);
72 data
->mtd_Flags
= MTDF_SETMIN
| MTDF_SETVMAX
;
74 /* parse initial taglist */
76 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
80 case MUIA_Text_Contents
:
82 data
->contents
= StrDup((STRPTR
) tag
->ti_Data
);
85 case MUIA_Text_HiChar
:
86 data
->hichar
= tag
->ti_Data
;
87 _handle_bool_tag(data
->mtd_Flags
, tag
->ti_Data
, MTDF_HICHAR
);
90 case MUIA_Text_HiCharIdx
:
91 data
->hichar
= tag
->ti_Data
;
92 _handle_bool_tag(data
->mtd_Flags
, tag
->ti_Data
, MTDF_HICHARIDX
);
95 case MUIA_Text_PreParse
:
96 data
->preparse
= StrDup((STRPTR
) tag
->ti_Data
);
99 case MUIA_Text_SetMin
:
100 _handle_bool_tag(data
->mtd_Flags
, tag
->ti_Data
, MTDF_SETMIN
);
103 case MUIA_Text_SetMax
:
104 _handle_bool_tag(data
->mtd_Flags
, tag
->ti_Data
, MTDF_SETMAX
);
107 case MUIA_Text_SetVMax
:
108 _handle_bool_tag(data
->mtd_Flags
, tag
->ti_Data
, MTDF_SETVMAX
);
115 data
->preparse
= StrDup("");
117 data
->contents
= StrDup("");
119 if (!data
->contents
|| !data
->preparse
)
121 CoerceMethod(cl
, obj
, OM_DISPOSE
);
125 /* D(bug("Text_New(0x%lx)\n", obj)); */
127 data
->ehn
.ehn_Events
= IDCMP_MOUSEBUTTONS
;
128 data
->ehn
.ehn_Priority
= 0;
129 data
->ehn
.ehn_Flags
= 0;
130 data
->ehn
.ehn_Object
= obj
;
131 data
->ehn
.ehn_Class
= cl
;
138 /**************************************************************************
140 **************************************************************************/
141 IPTR
Text__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
143 struct MUI_TextData
*data
= INST_DATA(cl
, obj
);
145 FreeVec(data
->contents
);
146 FreeVec((APTR
) data
->preparse
);
148 return DoSuperMethodA(cl
, obj
, msg
);
151 /**************************************************************************
153 **************************************************************************/
154 IPTR
Text__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
156 struct MUI_TextData
*data
= INST_DATA(cl
, obj
);
157 struct TagItem
*tags
= msg
->ops_AttrList
;
160 while ((tag
= NextTagItem(&tags
)) != NULL
)
164 case MUIA_Text_Contents
:
167 StrDup(((char *)tag
->ti_Data
) ? (char *)tag
->
173 zune_text_destroy(data
->ztext
);
176 FreeVec(data
->contents
);
177 data
->contents
= new_contents
;
178 if (_flags(obj
) & MADF_SETUP
)
179 setup_text(data
, obj
);
180 MUI_Redraw(obj
, MADF_DRAWOBJECT
); /* should be optimized */
185 case MUIA_Text_PreParse
:
188 StrDup(((char *)tag
->ti_Data
) ? (char *)tag
->
194 zune_text_destroy(data
->ztext
);
197 FreeVec((APTR
) data
->preparse
);
198 data
->preparse
= new_preparse
;
199 if (_flags(obj
) & MADF_SETUP
)
200 setup_text(data
, obj
);
201 MUI_Redraw(obj
, MADF_DRAWOBJECT
); /* should be optimized */
207 D(bug("Text_Set(%p) : MUIA_Selected val=%ld sss=%d\n", obj
,
208 tag
->ti_Data
, ! !(_flags(obj
) & MADF_SHOWSELSTATE
)));
213 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
217 /**************************************************************************
219 **************************************************************************/
220 IPTR
Text__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
222 struct MUI_TextData
*data
= INST_DATA(cl
, obj
);
224 #define STORE *(msg->opg_Storage)
225 switch (msg
->opg_AttrID
)
227 case MUIA_Text_Contents
:
228 STORE
= (IPTR
) data
->contents
;
231 case MUIA_Text_PreParse
:
232 STORE
= (IPTR
) data
->preparse
;
243 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
247 /**************************************************************************
249 **************************************************************************/
250 static void setup_text(struct MUI_TextData
*data
, Object
*obj
)
252 if (data
->mtd_Flags
& MTDF_HICHAR
)
254 data
->ztext
= zune_text_new(data
->preparse
, data
->contents
,
255 ZTEXT_ARG_HICHAR
, data
->hichar
);
257 else if (data
->mtd_Flags
& MTDF_HICHARIDX
)
259 data
->ztext
= zune_text_new(data
->preparse
, data
->contents
,
260 ZTEXT_ARG_HICHARIDX
, data
->hichar
);
264 data
->ztext
= zune_text_new(data
->preparse
, data
->contents
,
267 zune_text_get_bounds(data
->ztext
, obj
);
269 /* D(bug("muimaster.library/text.c: ZText of 0x%lx at 0x%lx\n", */
270 /* obj, data->ztext)); */
273 /**************************************************************************
275 **************************************************************************/
276 IPTR
Text__MUIM_Setup(struct IClass
*cl
, Object
*obj
,
277 struct MUIP_Setup
*msg
)
279 struct MUI_TextData
*data
= INST_DATA(cl
, obj
);
281 if (!(DoSuperMethodA(cl
, obj
, (Msg
) msg
)))
284 setup_text(data
, obj
);
286 DoMethod(_win(obj
), MUIM_Window_AddEventHandler
, (IPTR
) & data
->ehn
);
290 /**************************************************************************
292 **************************************************************************/
293 IPTR
Text__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
,
294 struct MUIP_Cleanup
*msg
)
296 struct MUI_TextData
*data
= INST_DATA(cl
, obj
);
298 DoMethod(_win(obj
), MUIM_Window_RemEventHandler
, (IPTR
) & data
->ehn
);
302 zune_text_destroy(data
->ztext
);
306 return (DoSuperMethodA(cl
, obj
, (Msg
) msg
));
309 /**************************************************************************
311 **************************************************************************/
312 IPTR
Text__MUIM_Show(struct IClass
*cl
, Object
*obj
,
313 struct MUIP_Show
*msg
)
315 //struct MUI_TextData *data = INST_DATA(cl, obj);
317 if (!(DoSuperMethodA(cl
, obj
, (Msg
) msg
)))
323 /**************************************************************************
325 **************************************************************************/
326 IPTR
Text__MUIM_Hide(struct IClass
*cl
, Object
*obj
,
327 struct MUIP_Hide
*msg
)
329 //struct MUI_TextData *data = INST_DATA(cl, obj);
330 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
333 /**************************************************************************
335 **************************************************************************/
336 IPTR
Text__MUIM_AskMinMax(struct IClass
*cl
, Object
*obj
,
337 struct MUIP_AskMinMax
*msg
)
340 struct MUI_TextData
*data
= INST_DATA(cl
, obj
);
342 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
344 height
= data
->ztext
->height
;
345 if (_font(obj
)->tf_YSize
> height
)
346 height
= _font(obj
)->tf_YSize
;
347 /* D(bug("YSize=%ld\n", _font(obj)->tf_YSize)); */
350 msg
->MinMaxInfo
->MinWidth
+= data
->ztext
->width
;
351 msg
->MinMaxInfo
->DefWidth
+= data
->ztext
->width
;
352 msg
->MinMaxInfo
->MaxWidth
+= data
->ztext
->width
;
354 msg
->MinMaxInfo
->MinHeight
+= height
;
355 msg
->MinMaxInfo
->DefHeight
+= height
;
357 if (!(data
->mtd_Flags
& MTDF_SETVMAX
))
358 msg
->MinMaxInfo
->MaxHeight
+= MUI_MAXMAX
;
360 msg
->MinMaxInfo
->MaxHeight
+= height
;
362 if (!(data
->mtd_Flags
& MTDF_SETMAX
))
363 msg
->MinMaxInfo
->MaxWidth
= MUI_MAXMAX
;
365 if (!(data
->mtd_Flags
& MTDF_SETMIN
))
366 msg
->MinMaxInfo
->MinWidth
= 0;
369 ("Text_AskMinMax 0x%lx (%s): Min=%ldx%ld Max=%ldx%ld Def=%ldx%ld\n",
370 obj
, data
->contents
, msg
->MinMaxInfo
->MinWidth
,
371 msg
->MinMaxInfo
->MinHeight
, msg
->MinMaxInfo
->MaxWidth
,
372 msg
->MinMaxInfo
->MaxHeight
, msg
->MinMaxInfo
->DefWidth
,
373 msg
->MinMaxInfo
->DefHeight
));
378 /**************************************************************************
380 **************************************************************************/
381 IPTR
Text__MUIM_Draw(struct IClass
*cl
, Object
*obj
,
382 struct MUIP_Draw
*msg
)
384 struct MUI_TextData
*data
= INST_DATA(cl
, obj
);
388 /* D(bug("muimaster.library/text.c: Draw Text Object at " */
389 /* "0x%lx %ldx%ldx%ldx%ld\n", obj, _left(obj), _top(obj), */
390 /* _right(obj), _bottom(obj))); */
392 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
394 if ((msg
->flags
& MADF_DRAWUPDATE
) && !data
->update
)
397 if (!(msg
->flags
& MADF_DRAWUPDATE
))
400 if (msg
->flags
& MADF_DRAWUPDATE
&& data
->update
== 1)
402 DoMethod(obj
, MUIM_DrawBackground
, _mleft(obj
), _mtop(obj
),
403 _mwidth(obj
), _mheight(obj
), _mleft(obj
), _mtop(obj
), 0);
406 clip
= MUI_AddClipping(muiRenderInfo(obj
), _mleft(obj
), _mtop(obj
),
407 _mwidth(obj
), _mheight(obj
));
409 SetAPen(_rp(obj
), _pens(obj
)[MPEN_TEXT
]);
412 get(_win(obj
), MUIA_Window_ActiveObject
, &act
);
414 int y
= (_mheight(obj
) - data
->ztext
->height
) / 2;
415 zune_text_draw(data
->ztext
, obj
,
416 _mleft(obj
), _mright(obj
), _mtop(obj
) + y
);
420 MUI_RemoveClipping(muiRenderInfo(obj
), clip
);
425 /**************************************************************************
426 MUIM_Export : to export an object's "contents" to a dataspace object.
427 **************************************************************************/
428 IPTR
Text__MUIM_Export(struct IClass
*cl
, Object
*obj
,
429 struct MUIP_Export
*msg
)
431 //struct MUI_TextData *data = INST_DATA(cl, obj);
435 if ((id
= muiNotifyData(obj
)->mnd_ObjectID
))
437 DoMethod(msg
->dataspace
, MUIM_Dataspace_AddString
,
438 _U(id
), _U("contents"), _U(data
->contents
));
445 /**************************************************************************
446 MUIM_Import : to import an object's "contents" from a dataspace object.
447 **************************************************************************/
448 IPTR
Text__MUIM_Import(struct IClass
*cl
, Object
*obj
,
449 struct MUIP_Import
*msg
)
455 if ((id
= muiNotifyData(obj
)->mnd_ObjectID
))
457 if ((s
= (STRPTR
) DoMethod(msg
->dataspace
,
458 MUIM_Dataspace_FindString
, _U(id
), _U("contents"))))
460 set(obj
, MUIA_Text_Contents
, _U(s
));
468 BOOPSI_DISPATCHER(IPTR
, Text_Dispatcher
, cl
, obj
, msg
)
470 switch (msg
->MethodID
)
473 return Text__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
475 return Text__OM_DISPOSE(cl
, obj
, msg
);
477 return Text__OM_SET(cl
, obj
, (struct opSet
*)msg
);
479 return Text__OM_GET(cl
, obj
, (struct opGet
*)msg
);
482 return Text__MUIM_AskMinMax(cl
, obj
, (APTR
) msg
);
484 return Text__MUIM_Draw(cl
, obj
, (APTR
) msg
);
486 return Text__MUIM_Setup(cl
, obj
, (APTR
) msg
);
488 return Text__MUIM_Cleanup(cl
, obj
, (APTR
) msg
);
490 return Text__MUIM_Show(cl
, obj
, (APTR
) msg
);
492 return Text__MUIM_Hide(cl
, obj
, (APTR
) msg
);
494 return Text__MUIM_Export(cl
, obj
, (APTR
) msg
);
496 return Text__MUIM_Import(cl
, obj
, (APTR
) msg
);
499 return DoSuperMethodA(cl
, obj
, msg
);
501 BOOPSI_DISPATCHER_END
506 const struct __MUIBuiltinClass _MUI_Text_desc
=
510 sizeof(struct MUI_TextData
),
511 (void *) Text_Dispatcher