Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.acorn.programmer > #285 > unrolled thread
| Started by | Mister Ron <mrronman@googlemail.com> |
|---|---|
| First post | 2011-05-10 13:50 -0700 |
| Last post | 2011-05-14 07:44 +0100 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.sys.acorn.programmer
Toolbox Mouse position Mister Ron <mrronman@googlemail.com> - 2011-05-10 13:50 -0700
Re: Toolbox Mouse position Alan <alan_baa@hotmail.com> - 2011-05-11 04:36 -0700
Re: Toolbox Mouse position Mister Ron <mrronman@googlemail.com> - 2011-05-11 13:15 -0700
Re: Toolbox Mouse position Martin Wuerthner <spamtrap@mw-software.com> - 2011-05-11 22:59 +0200
Re: Toolbox Mouse position Rik Griffin <nospam@denbridgemarine.com> - 2011-05-12 10:14 +0100
Re: Toolbox Mouse position Mister Ron <mrronman@googlemail.com> - 2011-05-13 13:28 -0700
Re: Toolbox Mouse position Rik Griffin <rik.griffin@btinternet.com> - 2011-05-14 00:58 +0100
Re: Toolbox Mouse position Tank <webmaster@tankstage.co.uk> - 2011-05-14 07:44 +0100
| From | Mister Ron <mrronman@googlemail.com> |
|---|---|
| Date | 2011-05-10 13:50 -0700 |
| Subject | Toolbox Mouse position |
| Message-ID | <a9bd1414-f078-4e4c-af3b-2d7a3ee84705@e13g2000vbo.googlegroups.com> |
Hello again I've got a toolbox application window in which i dynamically create display_fields. When i select an entry from a menu belonging to the window, How can I determine the position of where the menu was created so I can decide which displayfield I was over to operate on. Thanks MrRon
[toc] | [next] | [standalone]
| From | Alan <alan_baa@hotmail.com> |
|---|---|
| Date | 2011-05-11 04:36 -0700 |
| Message-ID | <736bf67d-4bc1-44d8-97d9-104b27e168d4@gu8g2000vbb.googlegroups.com> |
| In reply to | #285 |
On May 10, 9:50 pm, Mister Ron <mrron...@googlemail.com> wrote: > Hello again > > I've got a toolbox application window in which i dynamically create > display_fields. > > When i select an entry from a menu belonging to the window, How can I > determine the position of where the menu was created so I can decide > which displayfield I was over to operate on. > > Thanks > MrRon I haven't tried if for a while, but I believe I have in the past used the mouse click event on the window to store the position if it is a menu click. Alternatively it may work using Window_GetPointerInfo in the menu about to be shown event. Regards, Alan
[toc] | [prev] | [next] | [standalone]
| From | Mister Ron <mrronman@googlemail.com> |
|---|---|
| Date | 2011-05-11 13:15 -0700 |
| Message-ID | <2bc8b522-3167-44d2-91a1-db28a548880c@z7g2000prh.googlegroups.com> |
| In reply to | #289 |
On May 11, 12:36 pm, Alan <alan_...@hotmail.com> wrote: > I haven't tried if for a while, but I believe I have in the past used > the > mouse click event on the window to store the position if it is a menu > click. > Alternatively it may work using Window_GetPointerInfo in the menu > about to be shown event. > > Regards, > Alan I've got the menu_about_to_show_event but am having difficulty with accessing the union structure. I'm trying with Acorn c++ compiler : int ypos = (WindowAboutToBeShownEvent) event->info.top_left.y; error: member info undefined any pointers please. Ta. MrRon
[toc] | [prev] | [next] | [standalone]
| From | Martin Wuerthner <spamtrap@mw-software.com> |
|---|---|
| Date | 2011-05-11 22:59 +0200 |
| Message-ID | <4d97e2d151.martin@bach.planiverse.com> |
| In reply to | #290 |
In message <2bc8b522-3167-44d2-91a1-db28a548880c@z7g2000prh.googlegrou
ps.com>
Mister Ron <mrronman@googlemail.com> wrote:
> On May 11, 12:36 pm, Alan <alan_...@hotmail.com> wrote:
>> I haven't tried if for a while, but I believe I have in the past used
>> the
>> mouse click event on the window to store the position if it is a menu
>> click.
>> Alternatively it may work using Window_GetPointerInfo in the menu
>> about to be shown event.
>>
>> Regards,
>> Alan
> I've got the menu_about_to_show_event but am having difficulty with
> accessing the union structure.
> I'm trying with Acorn c++ compiler :
> int ypos = (WindowAboutToBeShownEvent) event->info.top_left.y;
> error: member info undefined
There are four things wrong with that line of code:
1) In your ToolBox event handler the "event" parameter is a pointer to
the event, which is also highlighted by the fact that you used "->" to
access its members. Therefore, you need to cast to a pointer type, but
(WindowAboutToBeShownEvent) is a structure type.
2) In your menu_about_to_show_event you would not expect to see a
WindowAboutToBeShownEvent, but, not surprisingly, a
MenuAboutToBeShownEvent, which does not have an info.top_left member,
but an immediate "pos" member of type TopLeft.
3) The "->" operator binds more tightly than the (type) cast operator,
so you need to use parentheses to force the cast to take precedence,
otherwise you are just casting the type of the read member value.
So, the corrected code after 1) to 3) is:
int ypos = ((MenuAboutToBeShownEvent*)event)->pos.y;
4) The above only tells you where the menu is, but you have no
official way of deducing the pointer position from that (the ToolBox
does open the menu at a fixed offset from the pointer position, but
you cannot rely on that).
The proper way to do this is to remember to position of the most
recent Menu click over the window. In most cases you could get away
with reading the current pointer position in menu_about_to_be_shown,
but you have no guarantee that the pointer is still where it was when
the click occurred, in particular if the system is busy.
--
Martin
---------------------------------------------------------------------
Martin Wuerthner MW Software http://www.mw-software.com/
RISC OS Software for Design, Printing and Publishing
---------------------------------------------------------------------
[toc] | [prev] | [next] | [standalone]
| From | Rik Griffin <nospam@denbridgemarine.com> |
|---|---|
| Date | 2011-05-12 10:14 +0100 |
| Message-ID | <24d725d251.rik-news@iyonix.elements> |
| In reply to | #285 |
In message <a9bd1414-f078-4e4c-af3b-2d7a3ee84705@e13g2000vbo.googlegroups.com>
Mister Ron <mrronman@googlemail.com> wrote:
> Hello again
>
> I've got a toolbox application window in which i dynamically create
> display_fields.
>
> When i select an entry from a menu belonging to the window, How can I
> determine the position of where the menu was created so I can decide
> which displayfield I was over to operate on.
When you click on your window, you'll get a Wimp_EMouseClick event,
assuming you've set the window background button type to ButtonType_Click
(3).
In the wimp event block delivered to your application, there's a window
handle and an icon handle. Use Window_WimpToToolbox to find which toolbox
gadget the icon handle belongs to, this is the component ID of your display
field.
Note - for other gadget types this is slightly more complicated.
ScrollList and TextArea gadgets won't return a Wimp_EMouseClick event, but
your window's menu will still open.
Tabs gadgets will return Wimp_EMouseClick if you click over the tab, but
what you get when you click over a window nested in the gadget depends on
the flags for that window.
TreeView gadgets will return an event if you click Menu over them, but not
for Select or Adjust, unless the TreeView_AllEvents flag is set. TreeView
gadgets can have their own menu, so your window's menu won't be shown,
although you can listen for the Wimp_EMouseClick with the component ID of
the TreeView, and open the menu yourself.
Tabs and TreeViews will also return the correct component ID in the IDBlock
returned for click events.
These differences are because these "complex" gadgets are implemented using
nested windows, rather than Wimp icons.
Sorry, I kind of went off on one there, but anyway, I hope I answered your
original question! :)
--
Rik Griffin
Standard disclaimer, not speaking for anyone but myself, blah blah
(Reply-To may be broken: use rik dot griffin at denbridge marine dot com)
[toc] | [prev] | [next] | [standalone]
| From | Mister Ron <mrronman@googlemail.com> |
|---|---|
| Date | 2011-05-13 13:28 -0700 |
| Message-ID | <88a93ecb-a883-48c6-abd2-76ab95f20cc7@cu4g2000vbb.googlegroups.com> |
| In reply to | #285 |
Thanks guys for the info. I tried Martin's method then Rik's. I'm now saving the position of the click in the click event. Then in the menu_click event find the ComponentId. However some of my displayfields are greyed out and window_wimp_to_toolbox seem to return -1 for these icons. I'm now trying to calculate the window position again so I can work out which icon i'm over with the following: /* Find window Y coords */ WimpGetWindowInfoBlock block; block.window_handle = mouse_click_position.window_handle; e=wimp_get_window_info( &block ); if(e) raise_error(e); This doesn't seem to error but crashes later with an ** unrecoverable error in run time system : free failed Does this look right or is there a better method to use. Ta MrRon
[toc] | [prev] | [next] | [standalone]
| From | Rik Griffin <rik.griffin@btinternet.com> |
|---|---|
| Date | 2011-05-14 00:58 +0100 |
| Message-ID | <79a2fad251.rik@iyonix.hell> |
| In reply to | #298 |
In message <88a93ecb-a883-48c6-abd2-76ab95f20cc7@cu4g2000vbb.googlegroups.com>
Mister Ron <mrronman@googlemail.com> wrote:
>
> Thanks guys for the info.
> I tried Martin's method then Rik's.
> I'm now saving the position of the click in the click event. Then in
> the menu_click event find the ComponentId.
>
> However some of my displayfields are greyed out and
> window_wimp_to_toolbox seem to return -1 for these icons.
Hmm, yes, I just tested it in ResTest and greyed out gadgets return an icon
number of -1 in the mouse click event. I never knew that, or probably I did
and I've forgotten it :)
By the way, I was wrong originally, you don't need to set your window's
background to button type 3 to see Menu clicks, it seems they are always
returned.
> I'm now trying to calculate the window position again so I can work
> out which icon i'm over with the following:
>
> /* Find window Y coords */
> WimpGetWindowInfoBlock block;
> block.window_handle = mouse_click_position.window_handle;
> e=wimp_get_window_info( &block ); if(e) raise_error(e);
>
> This doesn't seem to error but crashes later with an ** unrecoverable
> error in run time system : free failed
>
> Does this look right or is there a better method to use.
Wimp_GetWindowInfo returns a block for the window AND all the icons in it.
So it'll overrun the end of the WimpGetWindowInfoBlock. You can stop the
icon information being written to your block by setting bit 1 of r0.
But if all you want is the window position, it'd be simpler to use
wimp_get_window_state which uses a WimpGetWindowStateBlock, which just
basically gives you the position of the window and its flags.
--
Rik Griffin
[toc] | [prev] | [next] | [standalone]
| From | Tank <webmaster@tankstage.co.uk> |
|---|---|
| Date | 2011-05-14 07:44 +0100 |
| Message-ID | <19c91fd351.tank@tankstage.co.uk> |
| In reply to | #298 |
In message <88a93ecb-a883-48c6-abd2-76ab95f20cc7@cu4g2000vbb.googlegro
ups.com>
Mister Ron <mrronman@googlemail.com> wrote:
> Thanks guys for the info.
> I tried Martin's method then Rik's.
> I'm now saving the position of the click in the click event. Then in
> the menu_click event find the ComponentId.
> However some of my displayfields are greyed out and
> window_wimp_to_toolbox seem to return -1 for these icons.
> I'm now trying to calculate the window position again so I can work
> out which icon i'm over with the following:
> /* Find window Y coords */
> WimpGetWindowInfoBlock block;
> block.window_handle = mouse_click_position.window_handle;
> e=wimp_get_window_info( &block ); if(e) raise_error(e);
> This doesn't seem to error but crashes later with an ** unrecoverable
> error in run time system : free failed
> Does this look right or is there a better method to use.
> Ta
> MrRon
A longer winded (so slower to return), but portable method is,
1. Get the number of gadgets in the window with
"Window_EnumerateGadgets"
2. Loop getting the gadget flags with "Toolbox_MiscOp" (r2=64)
3. If the gadget is faded change it to unfaded with "Toolbox_MiscOp"
(r2=65)
4. Get the pointer info with "Window_GetPointerInfo" r4=gadget number
5. If you changed the faded flag, change it back
I have done this in Basic.
Tank
--
webmaster@tankstage.co.uk Iyonix PC
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.acorn.programmer
csiph-web