Program IDCMP;

{
    This program demonstrates the sort of information you can
expect from Intuition.  All it does is open a window with a bunch
of IDCMP flags set, then describes them as they come in.
}

{$I "Include:Exec/Ports.i"}
{$I "Include:Intuition/Intuition.i"}

var
    W : WindowPtr;
    IM : IntuiMessagePtr;
    Quit : Boolean;

Function OpenNewWindow : Boolean;
var
   nw : NewWindow;
begin
    with nw do begin
	LeftEdge := 50;
	TopEdge  := 50;
	Width    := 200;
	Height   := 100;
	DetailPen:= -1;
	BlockPen := -1;
	IDCMPFlags := NEWSIZE_f + MOUSEBUTTONS_f + MENUPICK_f +
			CLOSEWINDOW_f + DISKINSERTED_f +
			DISKREMOVED_f + ACTIVEWINDOW_f + INACTIVEWINDOW_f +
			VANILLAKEY_f;
	Flags    := WINDOWSIZING + WINDOWDRAG + WINDOWDEPTH +
			WINDOWCLOSE;
	FirstGadget := Nil;
	CheckMark := Nil;
	Title     := "IDCMP Test Window";
	Screen    := Nil;
	BitMap	  := Nil;
	MinWidth  := 40;
	MinHeight := 20;
        MaxWidth  := -1;
	MaxHeight := -1;
	WType	  := WBENCHSCREEN_f;
    end;
    W := OpenWindow(Adr(nw));
    OpenNewWindow := W <> Nil;
end;

begin
    if OpenNewWindow then begin
	repeat
	    IM := IntuiMessagePtr(WaitPort(W^.UserPort));
	    IM := IntuiMessagePtr(GetMsg(W^.UserPort));
	    Writeln;
	    with IM^ do begin
		case Class of
		  SIZEVERIFY_f	: Writeln('Size Verify');
		  NEWSIZE_f	: Writeln('New Window Size');
		  REFRESHWINDOW_f: Writeln('Refresh Window');
		  MOUSEBUTTONS_f: Writeln('Mouse Button');
		  MOUSEMOVE_f	: Writeln('Mouse Move');
		  GADGETDOWN_f	: Writeln('Gadget Down');
		  GADGETUP_f	: Writeln('Gadget Up');
		  REQSET_f	: Writeln('Request Set');
		  MENUPICK_f	: Writeln('Menu Pick');
		  CLOSEWINDOW_f	: Writeln('Close Window');
		  RAWKEY_f	: Writeln('Raw Key');
		  REQVERIFY_f	: Writeln('Request Verify');
		  REQCLEAR_f	: Writeln('Requests Cleared');
		  MENUVERIFY_f	: Writeln('Menu Verify');
		  NEWPREFS_f	: Writeln('New Preferences');
		  DISKINSERTED_f: Writeln('Disk Inserted');
		  DISKREMOVED_f	: Writeln('Disk Removed');
		  WBENCHMESSAGE_f: Writeln('WorkBench Message');
		  ACTIVEWINDOW_f: Writeln('Window Activated');
		  INACTIVEWINDOW_f: Writeln('Window Deactivated');
		  DELTAMOVE_f	: Writeln('Delta Move');
		  VANILLAKEY_f	: Writeln('Vanilla Key');
		  INTUITICKS_f	: Writeln('IntuiTicks');
		end;
		case Class of
		  MOUSEBUTTONS_f: if Code = SELECTUP then
				      Writeln('Left Button Released')
				  else
				      Writeln('Left Button Pressed');
		  MENUPICK_f    : Writeln('Menu Choice: ', Code);
		  RAWKEY_f	: Writeln('Raw Key Code: ', Code);
		  VANILLAKEY_f	: begin
				      Write('Key Pressed: ');
				      if (Code > 32) and (Code < 127) then
					  Write(Chr(Code),',');
				      Writeln('Chr(', Code, ')');
				  end;
		else
		    Writeln('Code: ', Code);
		end;
		Writeln('Qualifier: ', Qualifier);
		Writeln('Mouse Position: (', MouseX, ',', MouseY, ')');
		Writeln('Seconds: ', Seconds);
		Writeln('Micros:  ', Micros);
		Quit := Class = CLOSEWINDOW_f;
	    end;
	    ReplyMsg(MessagePtr(IM));
	until Quit;
	CloseWindow(W);
    end else
	Writeln('Could not open the window');
end.
