English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 16 July 2020, 12:34   #1
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
Raise event from STRING_KIND gadget without loosing focus?

I have added a hook on a STRING_KIND gadget. The hook code is as follows:
Code:
    if(strcmp(obj->WorkBuffer, "Hello") == 0)
    {
        obj->Code = 'F';
        obj->Actions |= SGA_END;
        return (~0);
    }
    else
    {
        return 0;
    }
This works fine, when I insert the text Hello in the STRING_KIND gadget an IDCMP event is raised and I handle this through the main loop;
Code:
while(run)
{
    ...

    case GAD_ANSWER_TXT:
        if(msg->Code == 'F')
        {
            printf("Correct Answer Given!\n");
        }
        ...
However when I raise an event from the STRING_KIND Gadget I loose focus from it, i.e. a user cannot continue to type, unless I do not re-focus after the logic in the while loop using the following;
Code:
ActivateGadget(my_answer_field, my_window, NULL);
However this means that if I have some heavy code in while loop, focus might take some extra time to get back to the STRING_KIND gadget.


Therefore I was wondering, is there a way how I can raise an IDCMP event / message from a STRING_KIND gadget without loosing focus from same STRING_KIND gadget?
Sim085 is offline  
Old 16 July 2020, 14:51   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Quote:
Originally Posted by Sim085 View Post
I have added a hook on a STRING_KIND gadget. The hook code is as follows:
Code:
    if(strcmp(obj->WorkBuffer, "Hello") == 0)
    {
        obj->Code = 'F';
        obj->Actions |= SGA_END;
        return (~0);
    }
    else
    {
        return 0;
    }
Therefore I was wondering, is there a way how I can raise an IDCMP event / message from a STRING_KIND gadget without loosing focus from same STRING_KIND gadget?
SGA_END menas exactly that: The user is done typing data into the gadget, and focus shall be lost, after sending the IDCMP_GADGETUP. This is what happens if you press RETURN in the gadget.


If you want some other form of feedback for your application, SGA_END is not what you are looking for. Instead, you could allocate a signal in your main task, and run into a Signal() in the string gadget hook, indicating for your main task that somethig is to be done about the string gadget.
Thomas Richter is offline  
Old 16 July 2020, 18:51   #3
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by Sim085 View Post
I have added a hook on a STRING_KIND gadget.

...



Therefore I was wondering, is there a way how I can raise an IDCMP event / message from a STRING_KIND gadget without loosing focus from same STRING_KIND gadget?

1. track which gadget is the current gadget
2. enable IDCMP_RAWKEY events
3. handle the IDCMP_RAWKEY and update/check the gadget as you like
bebbo is offline  
Old 16 July 2020, 20:25   #4
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
Hi Thomas,

I followed this example on signals and looks to be working:
https://wiki.amigaos.net/wiki/Exec_S...ating_a_Signal

Quote:
Originally Posted by Thomas Richter View Post
SGA_END menas exactly that: The user is done typing data into the gadget, and focus shall be lost, after sending the IDCMP_GADGETUP. This is what happens if you press RETURN in the gadget.


If you want some other form of feedback for your application, SGA_END is not what you are looking for. Instead, you could allocate a signal in your main task, and run into a Signal() in the string gadget hook, indicating for your main task that somethig is to be done about the string gadget.
Sim085 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Use two or more colours in STRING_KIND gadget at the same time. Sim085 Coders. C/C++ 1 02 July 2020 06:21
Event hacking and window focus hth313 Coders. System 0 19 June 2019 18:34
Intuition Requester: programmatically set focus on string gadget? Warty Coders. C/C++ 3 08 September 2018 07:35
Gadget/Layout.gadget V44 ruliovega support.Apps 6 02 January 2006 11:50
Loosing fullscreen focus when moving mouse. spiff support.WinUAE 1 15 October 2004 13:52

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:25.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09586 seconds with 13 queries