Hello,
trying to understand how Amiga programming works.
I have this source to open a window containing a string gadget:
Object *open_text_window_new(struct Screen *scr, struct Menu *menu)
{
Object *winobj;
if ((winobj = WindowObject,
WA_PubScreen, scr,
WA_Title, "My Window",
WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_SIZEBBOTTOM | WFLG_SIZEGADGET | WFLG_ACTIVATE,
WA_IDCMP, IDCMP_VANILLAKEY | IDCMP_INTUITICKS,
WA_Width, scr->Width * 6 / 10,
WA_Height, scr->Height * 4 / 10,
WINDOW_MenuStrip,menu,
WINDOW_BackFillName, "Sys:Prefs/Presets/Patterns/Chalk/ChalkBlue.brush",
WINDOW_Position, WPOS_TOPLEFT,
WINDOW_ParentGroup, VGroupObject,
LAYOUT_AddChild, VLayoutObject,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_BevelStyle, BVS_GROUP,
LAYOUT_Label, " Welcome",
LAYOUT_AddChild, StringObject,
GA_ID, GID_STRING1,
GA_RelVerify, TRUE,
GA_TabCycle, TRUE,
STRINGA_MinVisible, 20,
STRINGA_MaxChars, SMAX,
EndObject,
CHILD_Label, LabelObject, LABEL_Text, "This is a label:",
End,
End,
LAYOUT_AddChild, HLayoutObject,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_BevelStyle, BVS_GROUP,
EndHGroup,
EndVGroup,
EndWindow))
return (winobj);
}
Now, how can i access the string getting the text after press enter or other events?
What to do in my program loop?
Thank you very much.
@AmigaBlitter
You have to listen for OM_NOTIFY messages from the string object. As per the string class docs, you will receive a message with GA_ID = GID_STRING1 (the ID that you gave the string gadget), and a STRINGA_TextVal attribute containing the string.
If you want to get the string at any time, then you should store a pointer to the string object. That way you can call GetAttr()/GetAttrs(). To do this, you should follow the method recommended in Trixie's Recommended Practice article, section 4.3. His example in that section shows an array of object pointers being set for each GUI object that set/get attrs needs to be called on. For example:
sets objects[OID_BUTTON] to point to the button object. You really should be doing this anyway, so that you can use SetGadgetAttrs() to change the string when needed.
BTW, I see that you're using the old Reaction MACROs. Section 2.2 of the same article (link above) discourages using them. Use the coding style in Section 4.3.
Hans
P.S., Have a look at this page and this page, on the AmigaOS wiki. They should come in handy.
Join the Kea Campus - upgrade your skills; support my work; enjoy the Amiga corner.
https://keasigmadelta.com/ - see more of my work
Thank you, Hans
Studying...
About the reaction macros, i'm avoiding now... thanks to your suggestions and thanks to trixie's articles.
My problem is that i can't find tutorial that are made without reaction macros. Event in the sdk there are only fews examples done without reaction macros.
A generally more convenient way would be to listen for WMHI_GADGETUP events and use GetAttr() to obtain the new string value. By default string.gadget only sends a GADGETUP when the gadget is exited by pressing return or enter but this can be changed by setting STRINGA_RelVerifySpecial to TRUE.
@salass00
Ugh! I just realised that OM_NOTIFY is a BOOPSI method, not a message. So, listening for WMHI_GADGETUP events is the correct way to do this.
Hans
Join the Kea Campus - upgrade your skills; support my work; enjoy the Amiga corner.
https://keasigmadelta.com/ - see more of my work
If you set ICA_TARGET to ICTARGET_IDCMP you will get them as IDCMP_IDCMPUPDATE messages but you will need to use an IDCMP hook to intercept them as there is no WMHI_ equivalent for this type of event.
@salass00
have you got my e-mail, perhaps?