Opened 7 months ago

Last modified 7 months ago

#18648 new bug

BOptionPopUp sets value even if not available — at Version 1

Reported by: jackburton Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: Kits/Interface Kit Version: R1/beta4
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description (last modified by jackburton)

With BOptionPopUp::SetValue() you can set a value which does not exist. As you can see from the implementation, it sets the value of the BControl by calling BControl::SetValue(), but later it could return without setting the correct option, since there might be no option with that value.

Calling Value() will then return the newly set value.

void
BOptionPopUp::SetValue(int32 value)
{
	BControl::SetValue(value);
	BMenu* menu = fMenuField->Menu();
	if (menu == NULL)
		return;

	int32 numItems = menu->CountItems();
	for (int32 i = 0; i < numItems; i++) {
		BMenuItem* item = menu->ItemAt(i);
		if (item && item->Message()) {
			int32 itemValue;
			item->Message()->FindInt32("be:value", &itemValue);
			if (itemValue == value) {
				item->SetMarked(true);
				break;
			}
		}
	}
}

If I remember correctly, this behaviour is inherited from BeOS, but maybe it doesn't make much sense, and could be confusing.

Change History (1)

comment:1 by jackburton, 7 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.