{ Dieses kleine Prog. demonstriert die Erstellung von  }
{ HotKeys mit der commodities.library. Die Funktion    }
{ HotKey vereinfacht das Erstellen von HotKeys. Sie ist}
{ aber noch ausbaufähig (Fehlermeldungen etc.) !!      }
{                                                      }
{ ©1994 by Björn "BOMBER" Schotte (BOMBERSOFT)         }
{                                                      }
{ Written in MaxonPASCAL 3 (© by MAXON)                }
{                                          BS/26/07/94 }

{ Anmerkung: Das Programm basiert zum einen auf dem    }
{            Pascal-Prog. Usershell aus der Kickstart  }
{            09/92 und dem C-Prog. ActivateII aus der  }
{            Kickstart 04/92                           }
{            (basiert nur nach dem Erstellen von Hot-  }
{            Keys !!)                                  }

PROGRAM CommoditiesTest;

{$opt q}

USES Exec;

{$incl"commodities.lib",
      "libraries/commodities_functions.h",
      "dos.lib"}

CONST
  EVT_HOT = 1; { Erstes HotKey ID}
  HOTKEY1  = "lalt f1"; { Definition des HotKeys (Tastenkombination etc.) }
  EVT_POPKEY = 2; { Zweites HotKey ID }
  POPKEY1  = "ralt f1"; { Definition des HotKeys }

VAR
  mp : p_MsgPort;
  co,broker,co1,filter1,filter2,send1,send2,co2 : p_CxObj;
  b  : NewBroker;
  done : BOOLEAN;
  mask,x,x1 : LONG;
  msg : p_CxMsg;
  id,typ,err : LONG;
  s,s1 : STR;

{ Erstellt einen HotKey }
FUNCTION  HotKey(beschr : STR; VAR co:p_CxObj; id:LONG) : p_CxObj;
VAR
  s : p_CxObj;
BEGIN
  HotKey := NIL;
  co := CxFilter(PTR(beschr));
  IF co = NIL THEN EXIT;
  s := CxSender(mp,id);
  IF s = NIL THEN
  BEGIN
    DeleteCxObj(co);
    EXIT;
  END;
  AttachCxObj(co,s);
  AttachCxObj(co,CxTranslate(NIL));
  AttachCxObj(broker,co);
  HotKey := co;
END;

BEGIN
  OpenLib(CxBase,"commodities.library",37);
  mp := CreateMsgPort;
  IF mp = NIL THEN Error("MessagePort could not be set up !!");
  mp^.mp_Node.ln_Name := "TestPort";
  AddPort(mp); { Port öffentlich machen }
  { Broker-Struktur ausfüllen }
  b := NewBroker(NB_VERSION,"TestBroker","TestBroker","Hallo",NBU_UNIQUE,
                 0,0,mp,0);
  { Broker erstellen: }
  broker := CxBroker(^b,NIL);
  IF broker<>NIL THEN
  BEGIN
    { HotKeys erstellen }
    co := NIL;
    co1 := NIL;
    x := SIGBREAKF_CTRL_C;
    x1 := 1 SHL mp^.mp_SigBit;
    s := HOTKEY1;
    co := HotKey(s,co,EVT_HOT);
    s := POPKEY1;
    co1 := HotKey(s,co1,EVT_POPKEY);
    err := ActivateCxObj(broker,1); { Broker aktivieren !! }
    done := FALSE;
    REPEAT
      { Auf CTRL-C oder Signal von Commodity warten !! }
      mask := _Wait(x OR x1);
      IF (mask AND x) = x THEN done := TRUE
      ELSE IF (mask AND x1) = x1 THEN
      BEGIN
        msg := p_CxMsg(GetMsg(mp));
        WHILE msg<>NIL DO
        BEGIN
          id := CxMsgID(msg);
          typ := CxMsgType(msg);
          CASE typ OF
            CXM_IEVENT:
              CASE id OF
                EVT_HOT: Writeln("HotKey"); { HotKey gedrückt }
                EVT_POPKEY: Writeln("PopKey"); { PopKey gedrückt }
              ELSE END;
            CXM_COMMAND:
              { Kommt vom Proggy "Exchange" }
              CASE id OF
                CXCMD_KILL : done := TRUE; { Commodity beenden }
              ELSE END;
          ELSE END;
          msg := p_CxMsg(GetMsg(mp));
        END;
      END;
    UNTIL done;
    err := ActivateCxObj(broker,0); { Broker deaktivieren }
    DeleteCxObjAll(broker); { Alle Objekte, die am Broker hängen, löschen }
    { Noch anstehende Messages replyen }
    msg := p_CxMsg(GetMsg(mp));
    WHILE msg<>NIL DO
    BEGIN
      ReplyMsg(p_Message(msg));
      msg := p_CxMsg(GetMsg(mp));
    END;
  END;
  RemPort(mp); { Port vorm System entfernen }
  DeleteMsgPort(mp); { Löschen des Ports }
END.


