Recent

Author Topic: [Solved] How to determine, is user selecting smth in MainMenu or not  (Read 761 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2387
    • UVviewsoft
In TIdleTimer, I check that mouse is located over the main memo, and generate Python events. Now if I make some selection of MainMenu items, Python event is generated too. (e.g. Edit-item is dropped down and I move mouse over Edit children).
How can I avoid mouse movements in MainMenu?

EDIT I need the cross-platform way.
« Last Edit: April 12, 2021, 06:35:18 pm by Alextp »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to determine, is user selecting smth in MainMenu or not
« Reply #1 on: April 11, 2021, 09:32:23 pm »
Respond only to events of the control you're interested in. For example, if you need to grab mouse moves from a memo, add a handler for the OnMouseMove of the memo. In that case, once the focus has moved to the menu and while there, events for the memo shouldn't trigger.

Also you could (in theory) check in your idle timer which control has the focus and act as needed: exit if it's the TMainMenu, etc.
« Last Edit: April 11, 2021, 09:34:59 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: How to determine, is user selecting smth in MainMenu or not
« Reply #2 on: April 11, 2021, 10:12:21 pm »
maybe he is talking about the problem that existed in the Win32 port where when the tree of menus were opening all the OnClicks were firing even when you didn't actually click on them. Only the last and final menu item is suppose to fire that Onclick when you actually click it.

MSDN documents two different events for menus, select and click, I guess Delphi decided to merge both of them into a click

As for his problem I am sure it still does that with other widgets and it can be checked if the menu item that gets a click has children then just don't process the following code.

The only true wisdom is knowing you know nothing

AlexTP

  • Hero Member
  • *****
  • Posts: 2387
    • UVviewsoft
Re: How to determine, is user selecting smth in MainMenu or not
« Reply #3 on: April 11, 2021, 10:40:52 pm »
No, not about win32 problem. OnClick is not mentioned either. @lucamar'a answer is OK for me.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to determine, is user selecting smth in MainMenu or not
« Reply #4 on: April 11, 2021, 10:58:15 pm »
@Jamie:

If I'm reading correctly, his problem (more or less) is that he has an idle-timer and, when it fires, he's (probably) getting the mouse position, comparing with the coordinates of a TMemo (or similar) and triggering some Python scripts.

The problem than would be that when the menu is active the mouse coordinates might well coincide if you're pointing to an item which appears over the memo, so the idle-timer event thinks it's over the memo and triggers the run of the scripts. It has happened to me (in other contexts) and the best solution I found was to track the focus and/or when the mouse enters or leaves some control.

Of course there might be other (best) solution about which I didn't think :-[
Feel free (anyone) to propose it.
The more, the merrier ;D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018