Topic says it all: I want to be able to have both right mouse button evens from a menu AND use menus in the same window. How is this possible? Surely it is possible, because it is used in applications like DeluxePaint and PPaint.
When I use WFLG_RMBTRAP the menu is blocked, and when not I can't right mouse events.
Help!
IMHO the only way to get both is to change the WFLG_RMBTRAP flag dynamically depending on the mouse position. If the mouse pointer is over an area where you need the right mouse button clicks, set the flag and if the pointer is outside this area, clear the flag.
Wouldn't it be easier just to use the middle mouse button. Personally, I don't like it when I click the right mouse button expecting a program menu or context menu and end up selecting something I didn't expect to be selected. RMB bringing up a menu is pretty much a standard for Amiga programs so why confuse things. There's already enough confusion with ported GUI systems that don't act like Amiga programs. Would a MMB press or Shift-LMB press accomplish what you want? This is all just my personal opinion so don't let it bother you.
By the way here is a quote from Heinz Wrobel on the v2.1 Developer CD (Intuition/Hints):
It is strongly discouraged to use so called "atomic
modifications" of structure fields like updating the
ReportMouse() setting WFLG_REPORTMOUSE or changing WFLG_RMBTRAP
on the fly. On future PowerPC machines, a single instruction
might no longer be atomic. So if there is a function to modify a
shared value, use it.
Here is a quote from an article on the same CD:
WFLG_RMBTRAP is an exception to most fields in Intuition structures
because it is legal for an application to directly modify this flag.
Note that this change must take place as an atomic operation so that
Exec cannot perform a task switch in the middle of the change. If you
are unsure your compiler will do this, use a Forbid()/Permit() pair to
prevent a task switch.
Since the above quotes apply to earlier versions of AmigaOS and the use
of "Forbit()/Permit() is discouraged with OS4, it might be wise to ask
how to legally achieve an "atomic operation" with OS4. Someone smarter
than me will need to answer that question for you.
X1000 - OS 4.1FE
@thomas
Got it, thanks! Everything works now.
@xenic
Interesting stuff. At the moment I'll stick to the current solution (no Forbid/Permit) since it seems to work ok.
Are you actually changing the flags in the Window structure (setting/clearing the WFLG_RMBTRAP flag) or using SetWindowAttr() to change the WA_RMBTrap attribute? The latter would seem safer to me but I'm no Intuition expert.
X1000 - OS 4.1FE
I'm using SetWindowAttr(). No crashes yet, so I think it is safe.
It IS safer. No direct manipulation of GUI flags in Intuition, please :-)
But for ReAction windows created using window.class, SetWindowAttr() is considered obsolete. Same for SetWindowPointer(). The programmer should use SetAttrs() on the window object instead. I know Alfkil is not using ReAction windows in his port but I thought I'd mention it here.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@trixie
How did you find out that SetWindowAttr() is obsolete? I don't see any mention of it in the SDK Intuition autodocs. It sort of irritates me when I find out that the documentation isn't uptodate and I'm using the wrong functions.
X1000 - OS 4.1FE
@xenix
SetWindowAttr() and SetWindowPointer() are obsolete FOR REACTION WINDOWS created using window.class. It is because such a window is created as a BOOPSI object, and all BOOPSI objects are to be manipulated using SetAttrs() and GetAttrs(). Dedicated functions like SetWindowAttr() and SetWindowPointer() manipulate the GUI elements directly, bypassing the BOOPSI subsystem (and possibly not setting some important stuff in the object). They work but may not in the future.
If your window is created the traditional way, that is, through OpenWindowTags(), then there's of course no problem with using SetWindowAttr() and SetWindowPointer().
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@trixie
O.K. That makes sense. An old timer like me gets confused between traditional Intuition functions and those that apply to classes. Thanks for the info.
X1000 - OS 4.1FE