Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Menu.wmTimer use Menu.indexOf instead of MenuItem.index #1575

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ LRESULT wmTimer (long wParam, long lParam) {
OS.GetCursorPos (pt);
if (selectedMenuItem != null && selectedMenuItem.parent != null) {
RECT rect = new RECT ();
boolean success = OS.GetMenuItemRect (0, selectedMenuItem.parent.handle, selectedMenuItem.index, rect);
boolean success = OS.GetMenuItemRect (0, selectedMenuItem.parent.handle, indexOf(selectedMenuItem), rect);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fundamental change here is to compute the correct index using the existing method for computing the index.

if (!success) return null;
if (OS.PtInRect (rect, pt)) {
// Mouse cursor is within the bounds of menu item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class MenuItem extends Item {
Menu parent, menu;
long hBitmap;
int id, accelerator, userId, index;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index field was introduce when support for tooltips were added. I've eliminate the use/need for it, hence removed it.

int id, accelerator, userId;
ToolTip itemToolTip;
/* Image margin. */
final static int MARGIN_WIDTH = 1;
Expand Down Expand Up @@ -94,7 +94,7 @@ public class MenuItem extends Item {
public MenuItem (Menu parent, int style) {
super (parent, checkStyle (style));
this.parent = parent;
parent.createItem (this, (index = parent.getItemCount ()));
parent.createItem (this, parent.getItemCount ());
}

/**
Expand Down Expand Up @@ -136,16 +136,7 @@ public MenuItem (Menu parent, int style) {
public MenuItem (Menu parent, int style, int index) {
super (parent, checkStyle (style));
this.parent = parent;
parent.createItem (this, (this.index = index));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks confusingly like a removall, but note there is addition below:

parent.createItem (this, index);

}

MenuItem (Menu parent, Menu menu, int style, int index) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I remove the unused parameter I noticed that the entire constructor is unused so it seems better to remove it.

super (parent, checkStyle (style));
this.parent = parent;
this.menu = menu;
this.index = index;
if (menu != null) menu.cascade = this;
display.addMenuItem (this);
parent.createItem (this, index);
}

/**
Expand Down
Loading