home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
cmanual-3.0.lha
/
CManual
/
Intuition
/
IDCMP
/
IDCMP.doc
< prev
next >
Wrap
Text File
|
1993-10-12
|
22KB
|
604 lines
8 IDCMP
8.1 INTRODUCTION
We have in the last four chapters talked about IDCMP, but have
never actually explained what it is. But in this chapter we
will at last satisfy your hunger for more information. IDCMP
stands for Intuition's Direct Communications Messages Ports
(nice), and is the most commonly used way of receiving messages
from Intuition, and the only way to communicate to Intuition.
8.2 IDCMP PORTS
When something happens inside the Amiga, a disk is inserted, a
gadget is selected etc, a message is automatically created.
Intuition will then examine the messages and check if your
program is interested to hear about it. (Every window has a
list of none or more IDCMP flags which tells Intuition what
this window is interested of.) If a program is interested of
the message, that program will receive a special message
(IntuiMessage), which contains interesting information about
the message.
--------------------------- Messages created inside the Amiga.
| DISKINSERTED MENUPICK | For example, a disk is inserted,
| CLOSEWINDOW | a menu is activated, a window is
| NEWSIZE GADGETDOWN | closed etc...
---------------------------
| | | | |
V V V V V
------------- Intuition examines every message
| INTUITION | and checks if any program is
------------- interested of it.
/ \
DISKINSERTED GADGETDOWN If program A is interested of
| | DISKINSERTED messages, Intuition
V V will pass that one along to
------------- ------------- program A. If program B is
| PROGRAM A | | PROGRAM B | interested in GADGETDOWN messages
------------- ------------- program B will receive a message
every time a gadget is selected
in program B's window.
All other messages which no
program were interested in will
be thrown away.
Intuition will always start to examine the active window
first, and many IDCMP messages will probably be "swallowed".
If program B is active, and Intuition has found a GADGETDOWN
message, that message would be passed to program B, and all
other programs would never hear about it.
Some messages are important for all programs, such as
DISKINSERTED, and will be passed to ALL "interested" windows.
(If a window has its IDCMPFlags field set to DISKINSERTED, that
window is interested about disk inserted messages.)
8.3 HOW TO RECEIVE IDCMP MESSAGES
If you want to receive messages from Intuition you need to:
1. Open an IDCMP port.
2. Wait for messages.
3. Collect the messages.
4. Examine them.
5. Reply. (Tell Intuition that you have read the message)
8.3.1 OPEN IDCMP PORTS
The IDCMP port can be automatically allocated by Intuition when
you open a window. You only need to specify in the NewWindow
structure's IDCMPFlags field which messages you want to receive
from Intuition, and the rest is done for you. For example, if
you open a window with the IDCMPFlags field set to GADGETDOWN,
a port would be allocated for you, and your program would
receive a message every time a gadget has been selected.
If you already have opened a window you can later change the
IDCMP ports by calling the function ModifyIDCMP().
8.3.2 WAIT FOR MESSAGES
Once an IDCMP port has been opened your program only need to
wait until one or more messages arrives. There are two
different ways of waiting for messages:
1. The Passive Way. Your program is halted and will only wake
up when a message arrives. This will
increase the speed of other applications
since the CPU does not need to bother about
your program as long as it is sleeping. Use
the function Wait().
2. The Active Way. Your program tries to collect a message,
and if it could not find any message it
tries again. This is necessary if you want
your program to continue doing something,
and not stop waiting for a message to
arrive.
8.3.3 COLLECT MESSAGES
When you collect a message you should use the function
GetMsg(). It will return a pointer to an IntuiMessage
structure, which contains all important information about the
message, or NULL if it could not collect any message.
8.3.4 EXAMINE THE MESSAGE
Once you have collected a message successfully you can examine
the IntuiMessage structure. The IntuiMessag structure look like
this:
struct IntuiMessage
{
struct Message ExecMessage;
ULONG Class;
USHORT Code;
USHORT Qualifier;
APTR IAddress;
SHORT MouseX, MouseY;
ULONG Seconds, Micros;
struct Window *IDCMPWindow;
struct IntuiMessage *SpecialLink;
};
ExecMessage: Used by the Exec so do not touch it.
Class: Contains the IDCMP flag.
Code: Contains some special values which is closely
related to the IDCMP flag (Class). For example,
if you receive a MENUVERIFY message you can
examine the Code field to see if it is your
program's Menu (Code == MENUHOT) or some
other program's Menu (Code == MENUWAITING) that
will be displayed. If you on the other hand
receives RAWKEY or VANILLAKEY messages the Code
field will contain the key code and so on.
Qualifier: If your program receives RAWKEY messages
(untranslated keycodes), this field contains
information like if the SHIFT or CTRL key was
pressed or not. (A copy of the ie_Qualifier.)
MouseX: X position of the pointer relative to the top
left corner of your window.
MouseY: Y position of the pointer relative to the top
left corner of your window.
Seconds: Copy of the system clock's seconds.
Micros: Copy of the system clock's microseconds.
IAddress: Pointer to that object that created the message.
For example, if you receive a GADGETDOWN message,
this field contains a pointer to the Gadget that
was selected.
IDCMPWindow: Pointer back to the window that sent this message.
SpecialLink: Used by Exec and Intuition so do not touch it.
The best way to examine this structure is to copy all important
values and then reply as fast as possible. (Intuition will be
slowed down if you do not reply fast.) You can then (after you
have replied) check the copied values. (Remember! Do not use
the IntuiMessage structure any more once you have replied.)
8.3.5 REPLY
Once your program has read everything it is interested of it
should reply back to Intuition by calling the function
ReplyMsg(). This tells Intuition that you have finished with
reading the message.
Important! Once you have replied you may NOT examine/change the
IntuiMessage structure any more. Some other program or Intuition
may use it!
8.3.6 EXAMPLE
Here is an example of how your program should collect and
process IDCMP messages: (This is the Passive Way of collecting
messages.)
/* 1. Wait until a message arrive: */
Wait( 1 << my_window->UserPort->mp_SigBit );
/* (my_window is a pointer to a window.) */
/* (Do not bother to much about the funny formula.) */
/* 2. Try to collect a message: */
my_message = GetMsg( my_window->UserPort );
/* Could we collect a message? (If message == NULL we have */
/* not collected any message. */
if( my_message )
{
/* YES! We have collected a message successfully. */
/* 3. We should now examine the IntuiMessage structure, */
/* and save any important values. (If we save the */
/* information we can reply as soon as possible, and */
/* later examine the values.) */
class = my_message->Class;
code = my_message->Code;
address = my_message->IAddress;
/* 4. We should now reply since we have finished reading */
/* the IntuiMessage structure. (Your progra