Article View: comp.sys.amiga.tech
Article #13633Re: Some Gadget Questions?
From: ml
Date: Sun, 11 Feb 1990 21:45
Date: Sun, 11 Feb 1990 21:45
113 lines
5405 bytes
5405 bytes
[ This was originally a direct reply, which bounced; I have gone ahead and
posted it because maybe it is of sufficient general interest...]
In a recent article to UseNet you wrote:
]
] I have a couple of questions about gadgets. First I am using power
]windows. The program that I am working on has a custom screen, and two
]borderless windows. Each window has several gadgets. I am using Lattice
]c. The first question That I have has to do with boolean gadgets and the
]necessary flags. I started by creating the first window with several
]string gadgets and one boolean gadget. When the boolean gadget was
]selected I wanted to save the info and close the window. I accomplished
]this by setting the following IDCMP flags, GadgComp, Relverfiy,
]GadgImmediate. ...
] ... Now I created a second window with several string and one boolean
]gadget. The boolean gadget was set up the same way. I open the second
]window first but when I select the boolean gadget nothing goes to the
]message port. What I need to know is how to get a message to the message
]port so I can deal with this event.
Just guessing here, but...
Probably although you have created two windows, you have not set them up
to share a single IDCMP port, or you haven't set up both windows with the
appropriate IDCMP flags (each window has its own set of flags).
Therefore, all events in your second window are either (a) going to a
different message port, or (b) going nowhere at all because window 2
has no message port.
Use something to the effect of:
/* Open first window, with an IDCMP port */
NewWinInfo.IDCMPFLags = GADGETUP | GADGETDOWN .... ;
Window1 = OpenWindow(&NewWinInfo);
/* Open second window. Do NOT create an IDCMP port */
NewWin2Info.IDCMPFlags = 0;
Window2 = OpenWindow(&NewWin2Info);
/* Copy window 1's message port to window 2 */
Window2->UserPort = Window1->UserPort;
/* Now that window 2 has a port, set up its IDCMP flags appropriately. */
ModifyIDCMP(Window2, IDCMP-flags-of-your-choice-anything-except-zero);
The things to note are:
If a windows UserPort is NULL, and you call ModifyIDCMP on it
with nonzero flags (including indirectly in an OpenWindow() call)
then the port will be created.
If a window's UserPort is not NULL, and you call ModifyIDCMP() on
it with flags=0; then the port will be closed.
The port is a standard message port (created with CreatePort())
so you can open or close it yourself using CreatePort() and DeletePort().
Just make sure you don't call CloseWindow() with the window's UserPort
not set to NULL if you close it yourself using DeletePort().
IE, something like this is fine:
Port = CreatePort(...)
NewWinInfo.IDCMPFlags = 0;
Window1 = OpenWindow(...)
Window2 = OpenWindow(...)
Window1->UserPOrt = Window2->UserPort = Port;
ModifyIDCMP(Window1,...)
ModifyIDCMP(Window2,...)
while...
WaitPort(Port) ...
GetMsg(Port)...
Window1->UserPort = Window2->UserPort = NULL;
CloseWindow(Window1);
CloseWindow(Window2);
DeletePort(Port);
In truth, the above example is not wholly correct. There are some subtleties
involved in closing windows with shared message port. I believe CBM has
freely distributed a routine called CloseWindowSafely() that you should
find, or I can email you something equivalent. It would take too long
to go into these subtleties here.
If any one has any interest in it, I have a program I wrote a while back for
our local users' group which is a sort of "GadgetLab" --
a rather extensive (perhaps overly so :-) demo of doing Gadget Programming,
and it does show the use of shared message ports. I sent a copy
a while ago to both Fred Fish & the amiga.source newsgroup, but in both
cases it seems to have fallen into a black hole. If there's sufficient
interest, I suppose I can try again. I figure that with 1.4 looming in
the not too distant future, it (gadget program) will probably be obsolete
before too long anyways, so I haven't made much effort to distribute it.
] The second question is a little more straight foward. When opening a
]window with more then one string gadget how do you get the first gadget to
]be activated so the user just starts entering data, and when he hits return
]to activate the next gadget?
There is an ActivateGadget() function which activates a string gadget.
Syntax:
success = ActivateGadget(gadget,window,requester)
as far as activating a sequence of them is concerned, I suppose the way to
do it is call ActivateGadget() on each next gadget in the chain whenever you
get the GADGETUP event (hitting the RETURN key) for the N'th gadget in
the chain. I haven't tried this though...
Hope this helps!
--
==[ ml@eceris.ncsu.edu (128.109.135.109) ]==
==[ ml@eceris.ncsu.edu (128.109.135.109) ]==
Technical Details
Message-ID:
<1990Feb11.214506.20400@ncsuvx.ncsu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ucsd!rutgers!mephisto!ncsuvx!newsReferences:
<1075@mindlink.UUCP> <1990Feb10.221204.9516@csusac.csus.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ucsd!rutgers!mephisto!ncsuvx!news From: ml@ecerl3.ncsu.edu Newsgroups: comp.sys.amiga.tech Subject: Re: Some Gadget Questions? Message-ID: <1990Feb11.214506.20400@ncsuvx.ncsu.edu> Date: 11 Feb 90 21:45:06 GMT References: <1075@mindlink.UUCP> <1990Feb10.221204.9516@csusac.csus.edu> Reply-To: ml@ecerl3.UUCP () Organization: North Carolina State University Lines: 113