⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.c

📁 LastWave
💻 C
📖 第 1 页 / 共 4 页
字号:
        if (keys[nKeys] == 0) Errorf("Bad modifier '%s' in key binding",*list);        keyName = *(list+1);      }      else Errorf("Too long key name for key binding");      /* Get the key code */      if (keyName[1] == '\0') keys[nKeys++] += *keyName;      else if (keyName[0] == '0' && keyName[1] == 'x') {        lval = strtol(keyName,&endp,0);	    if (*endp != '\0' || lval < 0 || lval >= 256) Errorf("Bad key code '%s'",keyName);	    keys[nKeys++] += lval;      }      else if (!strcmp(keyName,"esc")) keys[nKeys++] += EscapeKC;      else if (!strcmp(keyName,"newline")) keys[nKeys++] += NewlineKC;      else {        for (i=FirstKC;i<LastKC;i++) {          if (!strcmp(keyName,SpecialKeyNames[i-FirstKC])) {            keys[nKeys++] += i;            break;          }        }        if (i == LastKC) Errorf("Unknown key name '%s'",keyName);      }      keys[nKeys] = 0;    }        if (nKeys == 0) Errorf("Missing key name for key binding");        if (!strcmp(type,"keyUp")) {b.eventType = KeyUp;}    else if (!strcmp(type,"keyDown")) {b.eventType = KeyDown1;}    else if (!strcmp(type,"key")) {b.eventType = KeyDown1 + KeyUp;}    else Errorf("Bad event type '%s'",type);        if ((b.eventType & KeyUp) && nKeys >1) Errorf("Cannot bind KeyUp sequences (You should use the keyword KeyDown1)");        lookForModifiers = NO;  }  /* Draw Events */  else if (!strcmp(type,"draw")) {    lookForModifiers = NO;    b.eventType = Draw;  }  /* Delete events */  else if (!strcmp(type,"delete")) {    lookForModifiers = NO;    b.eventType = Del;  }    /* Error Events */  else if (!strcmp(type,"error")) {    lookForModifiers = NO;    b.eventType = ErrorEvent;  }  /* Delay Events */  else if (!strcmp(type,"delay")) {    if (theBindings != theTerminalBindings) Errorf("Delay bindings must be associated to the terminal");    lookForModifiers = NO;    b.eventType = DelayEvent;    argv = ParseArgv(argv,tFLOAT,&time,-1);    if (time <0) Errorf("The delay should be a positive LWFLOAT");    b.delay = ((int) (time*1000))/1000.;    b.timer = NULL;  }  /* Time Events */  else if (!strcmp(type,"time")) {    if (theBindings != theTerminalBindings) Errorf("Delay bindings must be associated to the terminal");    lookForModifiers = NO;    b.eventType = TimeEvent;    argv = ParseArgv(argv,tFLOAT,&time,-1);    if (time <0) Errorf("The time should be a positive LWFLOAT");    b.time = time;    b.timer = NULL;  }  /* Unknow event type */        else Errorf("Bad event type '%s'",type);      /* Looking for modifiers if necessary (This is done only for button or motion events) */  if (lookForModifiers) {    argv = ParseArgv(argv,tWORD_,NULL,&keyName,-1);    if (keyName != NULL) {      b.button += Str2Modifiers(keyName);      if ((ModMask & b.button) == 0) argv--;    }  }  /* Now get the script */  argv = ParseArgv(argv,tSCRIPT,&(b.script),-1);      /* That's it */    NoMoreArgs(argv); /*  * So let's create the binding !   */    /* Looking for the group name if it exists and creates it if it does not*/  group = NewBindingGroup(groupName,NULL);  /* Allocation of the binding */   cat = GetBindingCategory(b.eventType);  binding = (BINDING) Malloc(sizeof(struct binding));  binding->group = group;  group->nBindings++;  binding->previous = NULL;  binding->next = theBindings[cat];  binding->chainedList = &(theBindings[cat]);  if (binding->next != NULL) binding->next->previous = binding;    theBindings[cat] = binding;    /* Set the fields of the newly created binding */  binding->eventType = b.eventType;  binding->button = b.button;  binding->time = b.time;  binding->delay = b.delay;  binding->script = b.script;  b.script->nRef++;  binding->state = BindingOff;  binding->timer = NULL;  if (nKeys == 0) {binding->keys = NULL; binding->nKeys = 0;}  else {    binding->keys = (unsigned long *) Malloc(sizeof(unsigned long)*(nKeys+1));    binding->nKeys = nKeys;    for (i=0;i<=nKeys;i++) binding->keys[i] = keys[i];  }    if (group->flagActive == YES && (b.eventType == DelayEvent || b.eventType == TimeEvent))    ActivateTimerBinding(binding);}/************************************************************************ * *  Main command for for editing binding groups * ************************************************************************/ void C_Binding(char **argv){  char *command,*groupName;  char flagActivate,flagDeactivate,flagDelete,flagInfo;  BINDINGGROUP g;  BINDING *theBindings;  char *str;  BINDING b,b1;  int w,r;  AHASHELEM e;   GCLASS class;  LISTV lv,lv1;    lv = lv1 = NULL;      /* Read the command and the group name */  argv = ParseArgv(argv,tWORD,&command,tSTR,&groupName,tWORD_,NULL,&str,0);    /* Reading a class name */   if (str != NULL) {    class = (GCLASS) GetElemHashTable(theGClasses,str);    if (class == NULL) Errorf("Bad class name '%s'",str);  }  else class = NULL;      /* Set the command flags */  flagActivate = flagDeactivate = flagDelete = flagInfo = NO;  if (!strcmp(command,"activate")) flagActivate = YES;  else if (!strcmp(command,"deactivate")) flagDeactivate = YES;  else if (!strcmp(command,"delete")) flagDelete = YES;  else if (!strcmp(command,"info")) flagInfo = YES;  else Errorf("Bad action %s",command);      /* Init the binding group flags if necessary */  if (flagInfo) for (g = theBindingGroups;g!= NULL; g = g->next) g->flag = 0;      /*   * First we take care of the case where we need to perform a loop on the bindings (not on the binding groups)   */    if (flagDelete) {    if (class == NULL) {      theBindings = theTerminalBindings;      for (w=0;w<LastEventCategory;w++) {        for (b = theBindings[w]; b != NULL ;) {          if (MatchStr(b->group->name,groupName)) {            b1 = b;            b = b->next;            if (b1->state == BindingOn) b1->state = Binding2BeDeleted;            else DeleteBinding(b1);          }          else b = b->next;        }      }    }    for (r = 0; r<theGClasses->nRows;r++) {      for (e = theGClasses->rows[r]; e != NULL; e = e->next) {         if (class != NULL && class != ((GCLASS) e)) continue;        theBindings = ((GCLASS) e)->theBindings;        for (w=0;w<LastEventCategory;w++) {          for (b = theBindings[w]; b != NULL ;) {            if (MatchStr(b->group->name,groupName)) {              b1 = b;              b = b->next;              if (b1->state == BindingOn) b1->state = Binding2BeDeleted;              else DeleteBinding(b1);            }            else b = b->next;          }        }      }    }    return;  }           /*   * Then we take care of the (simpler) case where we need to perform a loop on the binding groups   */  if (flagInfo) {    lv = TNewListv();     SetResultValue(lv);  }  for (g = theBindingGroups;g!= NULL; g = g->next) {    if (MatchStr(g->name,groupName)) {       if (class) {        theBindings = class->theBindings;        for (w=0;w<LastEventCategory;w++) {          for (b = theBindings[w]; b != NULL ;b = b->next) {            if (b->group == g) break;          }          if (b != NULL) break;        }        if (w == LastEventCategory) continue;      }      if (flagActivate) {        g->flagActive = YES;        for (b = theTerminalBindings[OtherEventCategory];b!= NULL;b=b->next) {          if ((b->eventType == DelayEvent || b->eventType == TimeEvent) && b->group == g) {            ActivateTimerBinding(b);          }        }      }         else if (flagDeactivate) {        g->flagActive = NO;        for (b = theTerminalBindings[OtherEventCategory];b!= NULL;b=b->next) {          if ((b->eventType == DelayEvent || b->eventType == TimeEvent) && b->group == g) {            DeActivateTimerBinding(b);          }        }      }        else if (flagInfo) {        if (g->flag == 0) {          lv1 = TNewListv();          AppendStr2Listv(lv1,g->name);          AppendInt2Listv(lv1,g->flagActive);          if (g->help != NULL)  AppendStr2Listv(lv1,g->help);          AppendValue2Listv(lv,(VALUE) lv1);          g->flag = 1;        }      }   }  }}/************************************************************************ * *  Functions that manage event variable dispatching * ************************************************************************//* * Function to get an event variable (which is a field of a stored event) *    *   name : the name of the event variable *   type : a pointer to the expected type of the variable (strType, signalType...) *          or a pointer to NULL if any type is accepted * *   --> returns the pointer to the content of the variable *       amd the type of this content if *type == NULL. */ void *GetEventVariable(char *name,char **type) /* ?????????????? a jeter */{  static char result[100];  EVENT event = toplevelCur->lastEvent;    /* If no event was stored --> NULL */  if (event == NULL) return(NULL);  if (event->type == NoEvent) return(NULL);    /* A simple test */  if (type == NULL) Errorf("GetEventVariable() : type should not be NULL");    /*   * We test all the  @variables    */        if (*type == strType || *type == NULL) {          /* Key variable */      if (!strcmp("key",name)) {      *type = strType;      if (event->type == KeyDown1 || event->type == KeyUp) return(KeyCode2Str(event->key,NO));      else return(NULL);    }    /* Window variable */      if (!strcmp("window",name)) {      *type = strType;      if (event->object != NULL) return(GetWin(event->object)->name);      else {        strcpy(result,"");        return((void *) result);      }    }    /* Objname variable */      if (!strcmp("objname",name)) {      *type = strType;      if (event->object != NULL) return(GetNameGObject(event->object));      else {        strcpy(result,"");        return((void *) result);      }    }                 /* Type variable */    if (!strcmp("type",name)) {      *type = strType;      if (event->type == KeyDown1) strcpy(result,"keyDown");      else if (event->type == KeyUp) strcpy(result,"keyUp");      else if (event->type == ButtonUp) strcpy(result,"buttonUp");      else if (event->type == ButtonDown) strcpy(result,"buttonDown");      else if (event->type == Enter) strcpy(result,"enter");      else if (event->type == Leave) strcpy(result,"leave");      else if (event->type == MouseMotion) strcpy(result,"mouseMotion");      else if (event->type == Draw) strcpy(result,"draw");      else if (event->type == Del) strcpy(result,"delete");      else if (event->type == ErrorEvent) strcpy(result,"errorEvent");      else Errorf("GetEventVariable() : event type %d unknown",event->type);      return((void *) result);    }    /* Button variable */    if (!strcmp("button",name)) {      *type = strType;      if (event->type == ButtonDown || event->type == ButtonUp || event->type == MouseMotion)         return(ButtonCode2Str(event->button));      else return(NULL);    }      /* i, j, m and n variables (mouse global coordinates) */    if (!strcmp("i",name)){      *type = strType;      sprintf(result,"%d",event->i);      return((void *) result);    }    if (!strcmp("j",name)){      *type = strType;      sprintf(result,"%d",event->j);      return((void *) result);    }    if (!strcmp("m",name)){      *type = strType;      sprintf(result,"%d",event->m);      return((void *) result);    }    if (!strcmp("n",name)){      *type = strType;      sprintf(result,"%d",event->n);      return((void *) result);    }    /* x,y,w and h variables (mouse local coordinates) */    if (!strcmp("x",name)){      *type = strType;      sprintf(result,"%g",event->x);      return((void *) result);    }    if (!strcmp("y",name)){      *type = strType;      sprintf(result,"%g",event->y);      return((void *) result);    }    if (!strcmp("w",name)){      *type = strType;      sprintf(result,"%g",event->w);      return((void *) result);    }    if (!strcmp("h",name)){      *type = strType;      sprintf(result,"%g",event->h);      return((void *) result);    }      }       return(NULL);   } char GetEventVariable2(char *name, char **str, LWFLOAT *f) {  EVENT event;    *str = NULL;    /* Get event */  event = toplevelCur->lastEvent;     /* If no event was stored --> NO */  if (event == NULL) return(NO);  if (event->type == NoEvent) return(NO);    /*   * We just test all the  @variables    */        /* Key variable */    if (!strcmp("key",name)) {    switch(event->type) {      case KeyDown1 : case KeyUp :        *str = KeyCode2Str(event->key,NO);        break;      default : Errorf("GetEventVariable2() : Weird");    }    return(YES);  }  /* Window variable */    if (!strcmp("window",name)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -