Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #291

Re: Toolbox Mouse position

From Martin Wuerthner <spamtrap@mw-software.com>
Newsgroups comp.sys.acorn.programmer
Subject Re: Toolbox Mouse position
Date 2011-05-11 22:59 +0200
Organization MW Software
Message-ID <4d97e2d151.martin@bach.planiverse.com> (permalink)
References <a9bd1414-f078-4e4c-af3b-2d7a3ee84705@e13g2000vbo.googlegroups.com> <736bf67d-4bc1-44d8-97d9-104b27e168d4@gu8g2000vbb.googlegroups.com> <2bc8b522-3167-44d2-91a1-db28a548880c@z7g2000prh.googlegroups.com>

Show all headers | View raw


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
---------------------------------------------------------------------

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web