I posted this message on the AmigaC mailing list.. I've reposted here as there have been no responses yet:
I've created a custom string gadget editing hook, but it wont display text in my string gadget while I type.. but when I hit enter, the text is printed in my windows listbrowser alright. So the text is being stored somewhere, but not displayed.. I'm using a Reaction
string gadget. Heres the relevant parts to my program.. I hope it makes sense. Btw this hook is just a test hook, I will be make it do other stuff later..
#define SG_STRLEN 600
struct Vars
{
struct StringInfo sgg_StrInfo;
struct StringExtend sgg_Extend;
struct Hook sgg_Hook;
UBYTE sgg_Buff[SG_STRLEN];
UBYTE sgg_WBuff[SG_STRLEN];
UBYTE sgg_UBuff[SG_STRLEN];
} *vars;
ULONG str_hookRoutine(struct Hook *hook, struct SGWork *sgw, ULONG
*msg)
{
UBYTE *work_ptr;
ULONG return_code;
/* Hook must return non-zero if command is supported.
** This will be changed to zero if the command is unsupported.
*/
return_code = ~0L;
if (*msg == SGH_KEY)
{
if ((sgw->EditOp == EO_REPLACECHAR) ||
(sgw->EditOp == EO_INSERTCHAR))
{
if((int)sgw->Code == 66) sgw->WorkBuffer[sgw->BufferPos -
1] = 'Z'; else
sgw->WorkBuffer[sgw->BufferPos - 1] = (int)sgw->Code;
}
}
else if (*msg == SGH_CLICK)
{
/* mouse click
** zero the digit clicked on
*/
if (sgw->BufferPos < sgw->NumChars)
{
work_ptr = sgw->WorkBuffer + sgw->BufferPos;
*work_ptr = '0';
}
}
else
{
/* UNKNOWN COMMAND
** hook should return zero if the command is not supported.
*/
return_code = 0;
}
return(return_code);
}
#define ASM __asm
#define REG(x) register __ ## x
ULONG ASM
hookEntry(REG(a0) struct Hook *h, REG(a2) VOID *o, REG(a1) VOID *msg)
{
return ((*(ULONG (*)(struct Hook *,VOID *,VOID *))(h->h_SubEntry))
(h, o, msg));
}
/* This simple function is used to initialize a Hook */
VOID InitHook (struct Hook *h, ULONG (*func)(struct Hook *hook,
struct SGWork *sgw, ULONG *msg), VOID *data)
{
/* Make sure a pointer was passed */
if (h)
{
/* Fill in the Hook fields */
h->h_Entry = (ULONG (*)()) hookEntry;
h->h_SubEntry = (HOOKFUNC)func;
h->h_Data = data;
}
}
struct Gadget *string_gadget;
int main()
{
(snipped large LAYOUT gadget stuff)
LAYOUT_AddChild, string_gadget =(Gadget*) StringObject,
STRINGA_MaxChars, 600,
GA_RelVerify, TRUE,
GA_UserInput, TRUE,
LAYOUT_DeferLayout, TRUE,
GA_ID, 1,
StringEnd, LayoutEnd;
(/snipped large LAYOUT gadget stuff)
vars = (struct Vars *)AllocMem(sizeof(struct Vars),MEMF_CLEAR);
if (vars != NULL)
{
vars->sgg_Extend.EditHook = &(vars->sgg_Hook);
vars->sgg_Extend.WorkBuffer = vars->sgg_WBuff;
vars->sgg_StrInfo.Buffer = vars->sgg_Buff;
vars->sgg_StrInfo.UndoBuffer = vars->sgg_UBuff;
vars->sgg_StrInfo.MaxChars = 600;
vars->sgg_StrInfo.Extension = &(vars->sgg_Extend);
string_gadget->Flags = GFLG_GADGHCOMP | GFLG_STRINGEXTEND;
string_gadget->SpecialInfo = &(vars->sgg_StrInfo);
InitHook (&(vars->sgg_Hook), str_hookRoutine, NULL);
//RA_SetUpHook(vars->sgg_Hook,string_gadget,NULL);
}
etc etc
}