Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Martin Wuerthner Newsgroups: comp.sys.acorn.programmer Subject: Re: Toolbox Mouse position Date: Wed, 11 May 2011 22:59:49 +0200 Organization: MW Software Lines: 60 Message-ID: <4d97e2d151.martin@bach.planiverse.com> References: <736bf67d-4bc1-44d8-97d9-104b27e168d4@gu8g2000vbb.googlegroups.com> <2bc8b522-3167-44d2-91a1-db28a548880c@z7g2000prh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: individual.net JqIfNHyZH0L05WApjofvzgn6+4BEYLhWSSDSSN70VwY4AEdDX9 X-Orig-Path: bach.planiverse.com%martin Cancel-Lock: sha1:Fl3QMgGijqunP6FDqH3z4mhKtFw= X-Editor: EmailEdit 6.00 User-Agent: Messenger-Pro/6.00 (MsgServe/6.00) (RISC-OS/5.16) NewsHound/v1.50-32 Xref: x330-a1.tempe.blueboxinc.net comp.sys.acorn.programmer:291 In message <2bc8b522-3167-44d2-91a1-db28a548880c@z7g2000prh.googlegrou ps.com> Mister Ron wrote: > On May 11, 12:36 pm, Alan 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 ---------------------------------------------------------------------