🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #544

Getting a PopUpList's window

#544
From: Gregory H. Anderson
Date: Wed, 12 Aug 1992 00:23
83 lines
3624 bytes
Someone sent me this by email to our free support line, but there was no  
sender anywhere to be found on the mail. It was even blank in my mailbox.  
(Probably a PR2 beta tester with a munged sendmail...  8^)) Anyway, I hope  
you recognize yourself and find the answer here. Let me know who you are,  
so I can record it in our files.

The question was:
-------------------------------------------------------------------------
I have several (5) Windows, each with a fairly large number of data entry  
items - Switches, TextFieldCells, and PopUpLists - and a generic  
home-grown object - ChangeController. ChangeController is the target  
object of the Switches, TextFieldCells and PopUpLists with an action of  
controlDidChange:sender.

All controlDidChange: wants to do is "dirty" the appropriate Window with  
setDocEdited:YES. For the Switches and TextFieldCells, I simply
	[[sender window] setDocEdited:YES];

But I cannot determine the Window in which the PopUpLists are. I have sent  
messages to the Matrix (sender) and the selectedCell. They seem to think  
they are in a PopUpList window, but how can I determine which window the  
PopUpList is in?
-------------------------------------------------------------------------

The answer is:

You are doing an inherently problematic thing, because PopUpLists are NOT  
controls, like TextFields and Buttons. They inherit through the Window  
hierarchy and are actually subclasses of Menus. By definition, you cannot  
ask a Window what Window it lives on. The Matrix lives on the PopUpList,  
not the Window it appears to be on, so it's no help either. Even the cover  
button is no help, because it's not directly attached to the PopUp.

The only way to figure out which effective Window sent the message is to  
subclass PopUpList, create an instance variable to store the effective  
window, and override the popUp: method. Try this:

@interface MyPopUpList:PopUpList 
	{
	id effectiveWindow;
	}

- effectiveWindow;

@end

@implementation MyPopUpList

- popUp:sender
	{
	effectiveWindow = [sender window];
	return [super popUp:sender];
	}

- effectiveWindow { return effectiveWindow; }

@end

In your case, it should be safe to assume that the sender is the button  
covering the PopUpList, so [sender window] should be what you're looking  
for. Now, in your controller code, say:

- receivePopUpMessage:sender
	{
	[[[sender window] effectiveWindow] setEdited:YES];
	}

There is no way to notify the target in advance (like at the top of the  
popUp: override), because the actions of individual cells in a PopUpList  
can all point to different targets. You wouldn't know who to send the  
message to until a specific cell is chosen. By then you're inside super.

Unfortunately, the implication of this suggestion is that you can't use  
the native PopUps in IB. I don't think you can put them on a 2.x palette  
because IB treats them special. Does that kill the whole deal for you?

PopUpLists: can't live with 'em, can't shoot 'em in the head.

--
Gregory H. Anderson          | "We're very tolerant around here,
Benevolent Dictator-for-Life |  being only amateurs ourselves."
Anderson Financial Systems   | - Tortoise (Godel, Escher, Bach)
greg@afs.com  (Nextmail OK)  | 
Technical Details
Message-ID: <1992Aug12.002320.2320@afs.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!afs!greg

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!afs!greg
From: greg@afs.com (Gregory H. Anderson)
Subject: Getting a PopUpList's window
Message-ID: <1992Aug12.002320.2320@afs.com>
Sender: greg@afs.com
Reply-To: greg@afs.com
Date: Wed, 12 Aug 1992 00:23:20 GMT
Lines: 83