home *** CD-ROM | disk | FTP | other *** search
- program Patient;
- uses
- PatientDoctorRelations, Sound;
-
- const
- FilterOK = 4;
- FilterCancel = 5;
- NetworkEvent = 101;
- DoctorModeEvent = 102;
-
- MessageListID = 128;
- SplashAboutID = 256;
-
- var
- cancel: boolean;
- DoctorMode: boolean;
- theKeys: KeyMap;
- MyTime: longint;
- var
- D: DialogPtr;
- item: integer;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- function UserInterrupt: boolean;
- var
- myEvent: EventRecord;
- begin
- UserInterrupt := false;
- if GetNextEvent(keyDownMask, myEvent) then
- if BitAnd(myEvent.message, charCodeMask) = 46 then
- if (BitAnd(myEvent.modifiers, cmdKey) = cmdKey) then
- UserInterrupt := true;
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure GetDText (D: DialogPtr; item: integer; var Str: Str255);
- var
- itemHandle: Handle;
- itemType: integer;
- itemRect: Rect;
- begin
- GetDItem(D, item, itemType, itemHandle, itemRect);
- GetIText(itemHandle, str);
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure SetDText (D: DialogPtr; item: integer; Str: Str255);
- var
- itemHandle: Handle;
- itemType: integer;
- itemRect: Rect;
- begin
- GetDItem(D, item, itemType, itemHandle, itemRect);
- SetIText(itemHandle, str);
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- function JLDLOGFilter (D: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
- var
- ch, key: integer;
- time: longint;
- OK: boolean;
- itemHandle: handle;
- itemType: integer;
- itemRect: Rect;
- pState: PenState;
- OldPort: GrafPtr;
- NWEvent: EventRecord;
- hh: handle;
- begin
- JLDLOGFilter := false;
- with theEvent do
- case theEvent.what of
- KeyDown:
- begin
- OK := false;
- ch := BitAnd(theEvent.message, charCodeMask);
- key := BitAnd(BitShift(theEvent.message, -8), charCodeMask);
- if ((key = 76) and (BitAnd(modifiers, cmdKey) = cmdKey) and (BitAnd(modifiers, optionKey) = optionKey)) then
- begin
- itemHit := DoctorModeEvent;
- JLDLOGFilter := true;
- end
- else if (ch in [$0D, $03]) and (FilterOK <> -1) and not (BitAnd(modifiers, ShiftKey) = ShiftKey) then
- begin
- itemHit := FilterOK;
- OK := true;
- end
- else if (key = $35) and (FilterCancel <> -1) then
- begin
- itemHit := FilterCancel;
- OK := true;
- end;
- if OK then
- begin
- GetDItem(D, itemHit, itemType, itemHandle, itemRect);
- if (itemType = ctrlItem + btnCtrl) then
- begin
- JLDLOGFilter := true;
- HiliteControl(ControlHandle(itemHandle), 1);
- delay(5, time);
- HiliteControl(ControlHandle(itemHandle), 0);
- end;
- end;
- end;
- otherwise
- begin
- if GetNextEvent(networkMask, NWEvent) then
- begin
- JLDLOGFilter := true;
- itemHit := NetworkEvent;
- end;
- end;
- end;
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure About;
- var
- D: DialogPtr;
- item: integer;
- begin
- D := GetNewDialog(SplashAboutID, nil, Pointer(-1));
- ModalDialog(nil, item);
- DisposDialog(D);
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- function Hospital: boolean;
- const
- DLOGID = 128;
- PatientEdit = 1;
- MsgStatic = 2;
- DrStatic = 3;
- OKButton = 4;
- QuitButton = 5;
- Aboutbutton = 7;
- FirstButton = 8;
- LastButton = 22;
- var
- D: DialogPtr;
- item, itemToSelect: integer;
- DLogDone: boolean;
- S, Response: Str255;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure GoToDoctorMode;
- begin
- if not DoctorMode then
- SizeWindow(D, 504, 192, true)
- else
- SizeWindow(D, 504, 156, true);
- DoctorMode := not DoctorMode;
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure InitializeDialog;
- var
- Hahaha: handle;
- begin
- if DoctorMode then
- begin
- Hahaha := GetResource('snd ', 5009);
- if (SndPlay(nil, Hahaha, false) <> 0) then
- begin
- end;
- disposHandle(Hahaha);
- DoctorMode := false;
- GoToDoctorMode;
- end;
- SetDText(D, PatientEdit, '');
- DLogDone := false;
- StartRead;
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure LetDoctorTalk;
- begin
- hear(response);
- if (Copy(response, 1, 1) = '*') then
- begin
- response := Copy(response, 2, length(response) - 1);
- Sysbeep(0);
- end;
- if DoctorMode then
- begin{I am the doctor}
- SetDText(D, MsgStatic, 'The patient says:');
- SetDText(D, DrStatic, response);
- end{I am the doctor}
- else
- begin{I am the patient}
- SetDText(D, MsgStatic, '');
- SetDText(D, DrStatic, response);
- end;{I am the patient}
- StartRead;
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure PatientIsDoneTalking;
- begin
- GetDText(D, PatientEdit, S);
- if DoctorMode then
- talk(S)
- else
- begin
- talk(Concat('*', S));
- SetDText(D, MsgStatic, 'Hmmm...');
- SetDText(D, DrStatic, '');
- end;
- SetDText(D, PatientEdit, '');
- itemToSelect := PatientEdit;
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure ListenToPatient;
- var
- extra: integer;
- begin
- if DoctorMode then
- begin
- end
- else
- begin
- GetDText(D, PatientEdit, S);
- talk(S);
- end;
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- procedure ExecuteButton (index: integer);
- var
- S: Str255;
- begin
- GetIndString(S, MessageListID, index + 1);
- SetDText(D, PatientEdit, S);
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- begin
- D := GetNewDialog(DlogID, nil, Pointer(-1));
- InitializeDialog;
- itemToSelect := PatientEdit;
- repeat
- if itemToSelect <> 0 then
- SelIText(D, itemToSelect, 0, 32767);
- itemToSelect := 0;
- ModalDialog(@JLDLOGFilter, item);
- case item of
- OKButton:
- PatientIsDoneTalking;
- QuitButton:
- begin
- Hospital := true;
- DLogDone := true;
- if not DoctorMode then
- talk('<<Quitting>>');
- end;
- AboutButton:
- About;
- NetworkEvent:
- LetDoctorTalk;
- DoctorModeEvent:
- GoToDoctorMode;
- PatientEdit:
- ListenToPatient;
- otherwise
- if (item >= FirstButton) and (item <= lastButton) then
- ExecuteButton(item - FirstButton);
- end;
- until DLogDone;
- DisposDialog(D);
- end;
-
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
- {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
-
- begin
- GetKeys(theKeys);
- SetCursor(GetCursor(WatchCursor)^^);
- D := GetNewDialog(SplashAboutID, nil, Pointer(-1));
- DrawDialog(D);
- MyTime := TickCount + 60;
- {Ñ DoctorMode := (theKeys[$7A] and theKeys[$76] and theKeys[$61] and theKeys[$62]);Ñ}
- DoctorMode := (theKeys[$7A]);
-
- OpenSocket;
- Cancel := false;
- while not GetAddress and not Cancel do
- begin
- Cancel := UserInterrupt;
- end;
-
- repeat
- until (tickCount > MyTime);
- DisposDialog(D);
-
- if not Cancel then
- begin
- InitCursor;
- if Hospital then
- begin
- end;
- end;
- CloseSocket;
- end.