[solved] How to make an Object the active one at window opening ?

9 posts / 0 new
Last post
zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
[solved] How to make an Object the active one at window opening ?

Hi,
Does it exist, in Reaction, a way to make an Object active without user input ?

For example, in a window with a simple "OK" button, is there a way to make this button active ? A simple "Return" key press will press it ?

In MUI, there is a "set(window,MUIA_Window_ActiveObject,MyButton);". any Reaction equivalent ?

I tried,
IIntuition->ActivateGadget(GAD(OBJ_ABT_OK), window_About,NULL) ;
without success...

Thank you

thomas
thomas's picture
Offline
Last seen: 11 hours 4 min ago
Joined: 2011-05-16 14:23
ILayout->ActivateLayoutGadget

ILayout->ActivateLayoutGadget

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
If your layout is in a

If your layout is in a reaction window.class window then you should use:

WM_ACTIVATEGADGET -- Activate layout gadget.

If the layout is attached to a plain intuition window / requester

Use ILayout->ActivatelayoutGadget()

But neither of those will achieve the button being pressed from keyboard....

Instead you can set the keyboard shortcut via the gadget text by placing an under score just before the letter you want as the shortcut.

eg

GA_Text,"_OK",

Will display as button with an OK with the O underlined, pressing O wil then 'press' the button.

You can also specify the shortcut key with:

GA_ActivateKey (CONST_STRPTR)

I'm not sure if that will enable keys like Return or Esc though, for those keys you will have to listen to WMHI_RAWKEY and detect a keyup event for the corresponding key, then trigger the same bit of code that pressing the key would have.

zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
Thank you Thomas and Andy I

Thank you Thomas and Andy

I still used "_OK" and ActivateKey. it doesn't make the object active.

I tried too ActivateLayoutGadget without more success.

If I have to use RAWKEY only for that it seems a lit bit too much complicated.
Thx again

  1. WINDOW_Layout, OBJ(OBJ_ABT_ROOT) = VLayoutObject,
  2.  
  3. LAYOUT_AddChild, HLayoutObject,
  4.  
  5. LAYOUT_AddChild, ButtonObject,
  6. GA_ID, OBJ_ABT_OK,
  7. GA_Width,50,
  8. GA_RelVerify,TRUE,
  9. BUTTON_Justification, BCJ_CENTER,
  10. GA_Text,"_OK",
  11. ButtonEnd,
  12.  
  13. LayoutEnd,
  14.  
  15. WindowEnd;
  16.  
  17. if (win_About)
  18. {
  19.  
  20. if ( (window_About = RA_OpenWindow(win_About)) )
  21. {
  22. ActivateLayoutGadget(GAD(OBJ_ABT_ROOT), window_About,NULL, OBJ_ABT_OK) ;
  23.  
  24. } // fin RA_OpenWindow()
  25.  
  26. } // end if (winAbout)
broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Typing "O" doesn't depress

Typing "O" doesn't depress the OK button? Does it display with a underlined 'O' ?

Similar code does work here in my own about window. I will email you it.

zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
Yes, pressing "O" activate

Yes, pressing "O" activate and press the button. No problem for that, sorry if my initial post was not enough clear.

My initial question was about Enter key press. In MUI, an activated button with MUIA_Window_ActiveObject reacts to Enter key.

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Buttons wont listen to the

Buttons wont listen to the enter key in that way as Enter is not meaningful to a button, if you want enter or esc to close your about window then you need to add WMHI_RawKey and check for the keypress.

zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
Thank you for the

Thank you for the explanation,

zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
Solved by using RAWKEY

Solved by using RAWKEY

case WMHI_RAWKEY:
{
struct InputEvent *ie;

GetAttr(WINDOW_InputEvent,win_About,(ULONG *)&ie);

// 67 = NumPad Return
// 68 = Return key
if ( (ie->ie_Code == 67) || (ie->ie_Code == 68) )
{
doneAbout = TRUE;
}
}

Log in or register to post comments