String gadget events?

7 posts / 0 new
Last post
AmigaBlitter
AmigaBlitter's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2012-02-18 19:55
String gadget events?
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.
Hans
Hans's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2010-12-09 22:04
@AmigaBlitter You have to
@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:
  1. LAYOUT_AddChild, objects[OID_BUTTON] = IIntuition->NewObject(ButtonClass, NULL,
  2. GA_ID, OID_BUTTON,
  3. GA_RelVerify, TRUE,
  4. GA_Text, "Press me!",
  5. TAG_END),
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.
http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more. Home of the RadeonHD driver for Amiga OS 4.x project. http://keasigmadelta.co.nz/ - more of my software.
AmigaBlitter
AmigaBlitter's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2012-02-18 19:55
Thank you,
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.
salass00
salass00's picture
Offline
Last seen: 4 days 12 hours ago
Joined: 2011-02-03 11:27
You have to listen for
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.
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.
Hans
Hans's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2010-12-09 22:04
@salass00 Ugh! I just
@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
http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more. Home of the RadeonHD driver for Amiga OS 4.x project. http://keasigmadelta.co.nz/ - more of my software.
salass00
salass00's picture
Offline
Last seen: 4 days 12 hours ago
Joined: 2011-02-03 11:27
Ugh! I just realised that
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.
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.
AmigaBlitter
AmigaBlitter's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2012-02-18 19:55
@salass00 have you got my
@salass00 have you got my e-mail, perhaps?
Log in or register to post comments