RISC OS Open
A fast and easily customised operating system for ARM devices
ROOL
Home | News | Downloads | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account
Forums → Community Support →

Two more wimp programming questions

Subscribe to Two more wimp programming questions 14 posts, 6 voices

 
Jan 12, 2021 10:39pm
Avatar Andreas Skyman (8677) 138 posts

When waltzing around in my c code like a gerbil on too much sugar, I’ve come across two more things that I can’t quite wrap my head around:

1. In research for the program I’m working on, I came across Message_WindowInfo 0, which is sent when the program wants to iconize, to ask for the menu. My program won’t iconize during normal operations, but I thought it might be nice if it had a custom sprite if it did. The sprite is already loaded on for the icon bar, but I can’t figure out how to respond to the message, even if I capture it in my wimp_poll loop. There doesn’t seem to be a type for it in OSLib, or..?

2. My icon bar menu feels a bit crowded, and many applications solve this by adding a divider. Is this some sort of sprite icon that you add as a menu entry (in the terminology of Steve Fryatt’s tutorial 1, not sure if they’re officially called entries) or how is it supposed to be done?


0: https://www.riscosopen.org/wiki/documentation/show/Message_WindowInfo
1: http://www.stevefryatt.org.uk/risc-os/wimp-prog/the-missing-menus

 
Jan 12, 2021 10:53pm
Avatar Andrew Conroy (370) 624 posts

2. My icon bar menu feels a bit crowded, and many applications solve this by adding a divider. Is this some sort of sprite icon that you add as a menu entry (in the terminology of Steve Fryatt’s tutorial 1, not sure if they’re officially called entries) or how is it supposed to be done?

I’ve no idea how to do it in C, but generally, to put a line under a menu item, you set bit 1 of the item flags for that menu entry.

 
Jan 12, 2021 11:27pm
Avatar Bryan (8467) 215 posts

2. My icon bar menu feels a bit crowded, and many applications solve this by adding a divider. Is this some sort of sprite icon that you add as a menu entry (in the terminology of Steve Fryatt’s tutorial 1, not sure if they’re officially called entries) or how is it supposed to be done?

When investigating this many (many) yearrs ago, I came across this and have been using it ever since (in BASIC).

PROCmake_menu("My Menu",window_update%!0-150,518,"Option1/Option2/______/OptionA/OptionB",")

The row of _ characters gives an adequate divider. And just needs the corresponding mouse click procedure to ignore the menu option. Could use – characters or even just spaces I think

 
Jan 12, 2021 11:41pm
Avatar Steve Fryatt (216) 1479 posts

I’ve no idea how to do it in C, but generally, to put a line under a menu item, you set bit 1 of the item flags for that menu entry.

I’d not (yet) covered this in the OSLib tutorial, as the menu chapters were already getting a little heavy going. It’s already pencilled in for a later chapter, when time permits.

The short answer is that you set one of the wimp_menu_flags – wimp_MENU_SEPARATE in OSLib terms – in the wimp_menu_entry structure for the entry that you wish to have the dotted line under. That is

entry->menu_flags |= wimp_MENU_SEPARATE;

See this chapter for details of the menu structure. If you open your iconbar menu using a routine like the menus_create_iconbar_menu() 1 described here, then the additional height of the separators is taken into account for you.

Which is, as Andrew says, setting bit 1 of the menu item flags – just with a little bit of sugar coating to make it clear what’s going on.

The row of _ characters gives an adequate divider. And just needs the corresponding mouse click procedure to ignore the menu option. Could use – characters or even just spaces I think

Please, no. Just follow the Style Guide – it’s not hard to do.

1 Or, indeed, using the comparable functions in libraries like SFLib, DeskLib and so on. If you’re calculating your iconbar menu height by hand in 2021, you’re doing it wrong.

 
Jan 13, 2021 12:01am
Avatar Steve Fryatt (216) 1479 posts

I came across Message_WindowInfo, which is sent when the program wants to iconize, to ask for the menu. My program won’t iconize during normal operations, but I thought it might be nice if it had a custom sprite if it did. The sprite is already loaded on for the icon bar, but I can’t figure out how to respond to the message, even if I capture it in my wimp_poll loop. There doesn’t seem to be a type for it in OSLib, or..?

The types are wimp_full_message_window_info (or just wimp_message_window_info if you don’t want the standard message header fields, which isn’t normally the case).

To receive it, you listen out for Events 17 and 18 (that’s wimp_USER_MESSAGE and wimp_USER_MESSAGE_RECORDED), and check for when the action is message_WINDOW_INFO. How you do this, exactly, will depend on how you’re handling wimp_poll() – using SFLib, you’d register a handler for them with event_add_message_handler(). How do you detect message_QUIT, as it’s the same process?

Once you’ve got the message, you can update the wimp_full_message_window_info block (remember that coming from wimp_poll(), it’s in your poll block so you can do what you like with it) and then call wimp_send_message() to reply with the details. Something like

wimp_send_message(wimp_USER_MESSAGE, message, message->sender);

where message is a pointer (wimp_full_message_window_info *message) to the full message block from wimp_poll(), suitably cast and updated by you copying in the strings for the icon name and title.

It’s late, and that’s all off the top of my head, so take it with a pinch of salt.

 
Jan 13, 2021 12:14am
Avatar Julie Stamp (8365) 261 posts

but I thought it might be nice if it had a custom sprite if it did

If you’ve got one icon for any iconized window, then no messages are needed. Put a sprite called “ic_tailwimplite” in the sprites file that you *IconSprites, and the Pinboard will use that automatically.

If you do want different icons for different windows, or want to try out the messages anyway,

There doesn’t seem to be a type for it in OSLib, or..?

I think you might be noticing here that the union in wimp_message doesn’t have a member of type wimp_message_window_info. Not all messages do. For these I cast the wimp message,

wimp_full_message_window_info *wininfo = 
  (wimp_full_message_window_info *)&block.message;

or

wimp_message_window_info *wininfo = 
  (wimp_message_window_info *)&block.message.data;

and then cast it back for the replying wimp_send_message().

 
Jan 13, 2021 11:00am
Avatar Andreas Skyman (8677) 138 posts

I am amazed at how quick and how detailed help you get in this forum. Thanks everyone!

I went with @Julie’s default-icon suggestion for the first issue, and adding separators worked fine as per @Steve’s suggestion.

 
Jan 21, 2021 9:26pm
Avatar Andreas Skyman (8677) 138 posts

All right, another Wimp/OSLib question. Currently I’m capturing the wimp_KEY_PRESSED event in my main poll loop, parsing the result, and sending it on with process_key if I don’t need it. This works as a proof of concept, but the keys this gives me access too are a bit too restricted. What I would like to catch is something like Alt/Logo(+Shift)+Arrow Keys. In OSLib there are two functions that look like they might help with that: keyinput_scan and keyinput_scan_multiple (alternatively the check varieties, but I think scan is what I want). My thinking is that I should either listen for NULL events in and ordinary poll loop, or use wimp_poll_idle and issue call to the keyinput functions regularly. I suspect the logic of this will be very much more involved than the rather handy wimp_KEY API, but I guess that’s unavoidable and I’ll cross that bridge when I get there.

Now for the problem – I don’t understand the keyinput API, and an internet search gave me nothing useful…
keyinput_scan has five inputs:
On entry:
- keyinputscan_flags flags – the only defined flag I can find is RETURN_TIME, but no real documentation of what time this is
- int initial_code – I’m guessing this is a keycode, that I have to supply, but… which one? What does it do?
- int *next_code – I’m guessing my “answer to the query” will end up here?
- int *state – State of key in next_code? Some sort of bit field?
- int *time – The time returned if the appropriate flag is given presumably ends up here, but what time is this?

keyinput_scan_multiple has much the same input, but additionally takes
On entry:
- int *buf – I assume buf needs to point to an int array of length:
- int num_entries_to_fill and that it will hold states as in the scalar call?
On exit:
- int *next_code – I’m thinking this is still a scalar.
- int *num_entries_filled – I assume is the number of filled entries in buf

The keyinput_check functions have almost the same signature, but with an int usage instead of initial_code, and no int *next_code.

Does anyone have experience with this part of the API? Perhaps this isn’t the right SWI for what I want to accomplish?

 
Jan 21, 2021 9:58pm
Avatar Julie Stamp (8365) 261 posts

The KeyInput API is part of RISC OS Select and is not in RISC OS 5 (yet). It is intended to supersede some of the OS_Byte calls, as detailed in the Select PRMs (Input.KeyVExtendedInput). If you use OS_Byte 121 it’s effectively INKEY from BASIC.

I haven’t used DeepKeys before, but it does look like what you want. You’ll get your key press messages as before, but they’ll be longer containing detailed information on modifiers.

 
Jan 22, 2021 7:54am
Avatar Andreas Skyman (8677) 138 posts

The KeyInput API is part of RISC OS Select and is not in RISC OS 5 (yet). It is intended to supersede some of the OS_Byte calls, as detailed in the Select PRMs (Input.KeyVExtendedInput). If you use OS_Byte 121 it’s effectively INKEY from BASIC.

Thanks! I’m glad I asked before getting too deep into attempting to use keyinput. The plethora of osbyte calls with just numbers rather than names was a bit scary at firs (well, it still is), but now that I’ve read up on it a bit more, it actually looks like osbyte 121 might not be too complicated. I have an idea of what to try next, at least.

I haven’t used DeepKeys before, but it does look like what you want. You’ll get your key press messages as before, but they’ll be longer containing detailed information on modifiers.

Yes, wow. It looks like a more or less perfect match. I’d really prefer not to rely on non-free third party libraries though, so I think I’ll try to go the osbyte route. Good to know there is a fallback though!

 
Jan 22, 2021 8:26am
Avatar Steve Pampling (1551) 6517 posts

I’d really prefer not to rely on non-free third party libraries though,

DeepKeys is a free utility.

 
Jan 22, 2021 9:43am
Avatar Andreas Skyman (8677) 138 posts

DeepKeys is a free utility.

I didn’t find a license indicating this, and haven’t seen the source anywhere, so I assumed it was non-free (that is to say “proprietary”). I would be happy to be proven wrong, of course.

 
Jan 22, 2021 6:51pm
Avatar Steve Pampling (1551) 6517 posts

If you do Twitter (not my thing) then Nemo is on there (check his web site for the specifics)

 
Jan 22, 2021 8:50pm
Avatar Andreas Skyman (8677) 138 posts

If you do Twitter (not my thing) then Nemo is on there (check his web site for the specifics)

I used to, but these days I only listen to the tweeting of actual birds. Much better!

Anyway, it seems it is some sort of shareware or freeware: one is free to distribute the binary as long as the copyright notice is distributed with it, but not – as far as I can tell – to study the code or modify it`. That is nice to know, and might make it a viable plan B, but I’d prefer to get by on only free software if I can.

Reply

To post replies, please first log in.

Forums → Community Support →

Search forums

Social

Follow us on and

ROOL Store

Buy RISC OS Open merchandise here, including SD cards for Raspberry Pi and more.

Donate! Why?

Help ROOL make things happen – please consider donating!

RISC OS IPR

RISC OS is an Open Source operating system owned by RISC OS Developments Ltd and licensed primarily under the Apache 2.0 license.

Description

Community-provided support for all users of RISC OS.

Voices

  • Andreas Skyman (8677)
  • Andrew Conroy (370)
  • Bryan (8467)
  • Steve Fryatt (216)
  • Julie Stamp (8365)
  • Steve Pampling (1551)

Options

  • Forums
  • Login
Site design © RISC OS Open Limited 2018 except where indicated
The RISC OS Open Beast theme is based on Beast's default layout

Valid XHTML 1.0  |  Valid CSS

Powered by Beast © 2006 Josh Goebel and Rick Olson
This site runs on Rails

Hosted by Arachsys