Example #1
0
/* Another menu callback. */
int menu_callback(void)
{
   char str[256];

   ustrzcpy(str, sizeof str, active_menu->text);
   alert("Selected menu item:", "", ustrtok(str, "\t"), "Ok", NULL, 0, 0);
   return D_O_K;
}
Example #2
0
static int convert_align_value_to_flags(const char *value)
{
  char *tok, *ptr = base_strdup(value);
  int flags = 0;

  for (tok=ustrtok(ptr, " ");
       tok != NULL;
       tok=ustrtok(NULL, " ")) {
    if (ustrcmp(tok, "horizontal") == 0) {
      flags |= JI_HORIZONTAL;
    }
    else if (ustrcmp(tok, "vertical") == 0) {
      flags |= JI_VERTICAL;
    }
    else if (ustrcmp(tok, "left") == 0) {
      flags |= JI_LEFT;
    }
    else if (ustrcmp(tok, "center") == 0) {
      flags |= JI_CENTER;
    }
    else if (ustrcmp(tok, "right") == 0) {
      flags |= JI_RIGHT;
    }
    else if (ustrcmp(tok, "top") == 0) {
      flags |= JI_TOP;
    }
    else if (ustrcmp(tok, "middle") == 0) {
      flags |= JI_MIDDLE;
    }
    else if (ustrcmp(tok, "bottom") == 0) {
      flags |= JI_BOTTOM;
    }
    else if (ustrcmp(tok, "homogeneous") == 0) {
      flags |= JI_HOMOGENEOUS;
    }
  }

  base_free(ptr);
  return flags;
}
Example #3
0
static void process_one_word(Accelerator* accel, char* word)
{
  KeyModifiers modifiers = kKeyNoneModifier;
  KeyScancode scancode = kKeyNil;
  int ascii = 0;
  char* tok;

  // Special case: plus sign
  if (word[0] == '+' && word[1] == 0) {
    accel->addKey(kKeyNoneModifier, kKeyNil, '+');
    return;
  }

  for (tok=ustrtok(word, "+"); tok;
       tok=ustrtok(NULL, "+")) {
    // Modifiers

    if (ustricmp(tok, "Shift") == 0) {
      modifiers = (KeyModifiers)((int)modifiers | (int)kKeyShiftModifier);
    }
    else if (ustricmp (tok, "Alt") == 0) {
      modifiers = (KeyModifiers)((int)modifiers | (int)kKeyAltModifier);
    }
    else if (ustricmp (tok, "Ctrl") == 0) {
      modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
    }

    // Scancode

    // word with one character
    else if (tok[1] == 0) {
      if (((*tok >= 'a') && (*tok <= 'z')) ||
          ((*tok >= 'A') && (*tok <= 'Z'))) {
        ascii = tolower(*tok);
      }
      else {
        ascii = *tok;
      }

      if (((*tok >= 'a') && (*tok <= 'z')) ||
          ((*tok >= 'A') && (*tok <= 'Z')))
        scancode = (KeyScancode)((int)kKeyA + tolower(*tok) - 'a');
      else if ((*tok >= '0') && (*tok <= '9'))
        scancode = (KeyScancode)((int)kKey0 + *tok - '0');
      else {
        switch (*tok) {
          case '~': scancode = kKeyTilde; break;
          case '-': scancode = kKeyMinus; break;
          case '=': scancode = kKeyEquals; break;
          case '[': scancode = kKeyOpenbrace; break;
          case ']': scancode = kKeyClosebrace; break;
          case ';': scancode = kKeyColon; break;
          case '\'': scancode = kKeyQuote; break;
          case '\\': scancode = kKeyBackslash; break;
          case ',': scancode = kKeyComma; break;
          case '.': scancode = kKeyStop; break;
          case '/': scancode = kKeySlash; break;
          case '*': scancode = kKeyAsterisk; break;
        }
      }
    }
    /* other ones */
    else {
      /* F1, F2, ..., F11, F12 */
      if ((toupper (*tok) == 'F') && (ustrlen(tok) <= 3)) {
        int num = ustrtol(tok+1, NULL, 10);
        if ((num >= 1) && (num <= 12))
          scancode = (KeyScancode)((int)kKeyF1 + num - 1);
      }
      else if ((ustricmp(tok, "Escape") == 0) ||
               (ustricmp(tok, "Esc") == 0))
        scancode = kKeyEsc;
      else if (ustricmp(tok, "Backspace") == 0)
        scancode = kKeyBackspace;
      else if (ustricmp(tok, "Tab") == 0)
        scancode = kKeyTab;
      else if (ustricmp(tok, "Enter") == 0)
        scancode = kKeyEnter;
      else if (ustricmp(tok, "Space") == 0)
        scancode = kKeySpace;
      else if ((ustricmp(tok, "Insert") == 0) ||
               (ustricmp(tok, "Ins") == 0))
        scancode = kKeyInsert;
      else if ((ustricmp(tok, "Delete") == 0) ||
               (ustricmp(tok, "Del") == 0))
        scancode = kKeyDel;
      else if (ustricmp(tok, "Home") == 0)
        scancode = kKeyHome;
      else if (ustricmp(tok, "End") == 0)
        scancode = kKeyEnd;
      else if ((ustricmp(tok, "Page Up") == 0) ||
               (ustricmp(tok, "PgUp") == 0))
        scancode = kKeyPageUp;
      else if ((ustricmp(tok, "Page Down") == 0) ||
               (ustricmp(tok, "PgDn") == 0))
        scancode = kKeyPageDown;
      else if (ustricmp(tok, "Left") == 0)
        scancode = kKeyLeft;
      else if (ustricmp(tok, "Right") == 0)
        scancode = kKeyRight;
      else if (ustricmp(tok, "Up") == 0)
        scancode = kKeyUp;
      else if (ustricmp(tok, "Down") == 0)
        scancode = kKeyDown;
      else if (ustricmp(tok, "0 Pad") == 0)
        scancode = kKey0Pad;
      else if (ustricmp(tok, "1 Pad") == 0)
        scancode = kKey1Pad;
      else if (ustricmp(tok, "2 Pad") == 0)
        scancode = kKey2Pad;
      else if (ustricmp(tok, "3 Pad") == 0)
        scancode = kKey3Pad;
      else if (ustricmp(tok, "4 Pad") == 0)
        scancode = kKey4Pad;
      else if (ustricmp(tok, "5 Pad") == 0)
        scancode = kKey5Pad;
      else if (ustricmp(tok, "6 Pad") == 0)
        scancode = kKey6Pad;
      else if (ustricmp(tok, "7 Pad") == 0)
        scancode = kKey7Pad;
      else if (ustricmp(tok, "8 Pad") == 0)
        scancode = kKey8Pad;
      else if (ustricmp(tok, "9 Pad") == 0)
        scancode = kKey9Pad;
      else if (ustricmp(tok, "Slash Pad") == 0)
        scancode = kKeySlashPad;
      else if (ustricmp(tok, "Asterisk") == 0)
        scancode = kKeyAsterisk;
      else if (ustricmp(tok, "Minus Pad") == 0)
        scancode = kKeyMinusPad;
      else if (ustricmp(tok, "Plus Pad") == 0)
        scancode = kKeyPlusPad;
      else if (ustricmp(tok, "Del Pad") == 0)
        scancode = kKeyDelPad;
      else if (ustricmp(tok, "Enter Pad") == 0)
        scancode = kKeyEnterPad;
    }
  }

  accel->addKey(modifiers, scancode, ascii);
}
Example #4
0
/* fs_flist_putter:
 *  Callback routine for for_each_file() to fill the file selector listbox.
 */
static void fs_flist_putter(AL_CONST char *str, int attrib, int param)
{
   char ext_tokens[32];
   char *s, *ext, *tok, *name;
   char tmp[512], tmp2[32];
   int c, c2, i, k, sign;

   /* attribute flags (rhsda order)
    * 0 = not required, 1 = must be set, -1 = must be unset
    */
   int attr_flag[5+5] = {
      0, -1, -1, 0, 0,
      FA_RDONLY, FA_HIDDEN, FA_SYSTEM, FA_DIREC, FA_ARCH
   };

   c = usetc(ext_tokens, ' ');
   c += usetc(ext_tokens+c, ',');
   c += usetc(ext_tokens+c, ';');
   usetc(ext_tokens+c, 0);

   s = get_filename(str);
   fix_filename_case(s);

   if (fext) {
      ustrcpy(tmp, fext);
      ustrtok(tmp, ext_tokens);
      c = (ustrtok(NULL, ext_tokens) ? 1 : 0);
      if (!c) {
	 if (!ustrchr(fext, '/'))
	    c = 1;
      }

      if (c && (!(attrib & FA_DIREC))) {
	 ustrcpy(tmp, fext);
	 ext = get_extension(s);
	 tok = ustrtok(tmp, ext_tokens);

	 while (tok) {
	    if (ustricmp(ext, tok) == 0)
	       break;

	    tok = ustrtok(NULL, ext_tokens);
	 }

	 if (!tok)
	    return;
      }

      c = usetc(ext_tokens, ' ');
      c += usetc(ext_tokens+c, ',');
      c += usetc(ext_tokens+c, ';');
      c += usetc(ext_tokens+c, '/');
      usetc(ext_tokens+c, 0);

      ustrcpy(tmp, fext);
      tok = ustrchr(tmp, '/');

      if (tok)
	 tok = ustrtok(tok, ext_tokens);

      if (tok) {
	 sign = 1;
	 c = usetc(tmp2, 'r');
	 c += usetc(tmp2+c, 'h');
	 c += usetc(tmp2+c, 's');
	 c += usetc(tmp2+c, 'd');
	 c += usetc(tmp2+c, 'a');
	 c += usetc(tmp2+c, '+');
	 c += usetc(tmp2+c, '-');
	 usetc(tmp2+c, 0);

	 /* scan the string */
	 i = 0;
	 while ((c = utolower(ugetat(tok, i)))) {
	    k = 0;
	    while ((c2 = ugetat(tmp2, k))!=0) {
	       if (c == c2) {
		  if (k<5) {
		     attr_flag[k] = sign;
		     break;
		  }
		  else
		     sign = (k==5) ? 1 : -1;
	       }
	       k++;
	    }
	    i++;
	 }
      }
   }

   /* check if file attributes match */
   if (!(attr_flag[3+5] & attrib)) {
      /* if not a directory, we check all attributes except FA_DIREC */
      for (c=0; c<5; c++) {
	 if (c == 3)
	    continue;
	 if ((attr_flag[c] == 1) && (!(attrib & attr_flag[c+5])))
	    return;
	 if ((attr_flag[c] == -1) && (attrib & attr_flag[c+5]))
	    return;
      }
   }
   else {
      /* if a directory, we check only FA_DIREC */
      if (attr_flag[3] == -1)
	 return;
   }

   if ((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) {
      name = malloc(ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0));
      if (!name)
	 return;

      for (c=0; c<flist->size; c++) {
	 if (ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) {
	    if (attrib & FA_DIREC)
	       if (ustrfilecmp(s, flist->name[c]) < 0)
		  break;
	 }
	 else {
	    if (attrib & FA_DIREC)
	       break;
	    if (ustrfilecmp(s, flist->name[c]) < 0)
	       break;
	 }
      }

      for (c2=flist->size; c2>c; c2--)
	 flist->name[c2] = flist->name[c2-1];

      flist->name[c] = name;
      ustrcpy(flist->name[c], s);

      if (attrib & FA_DIREC)
	 put_backslash(flist->name[c]);

      flist->size++;
   }
}
Example #5
0
static Widget* convert_xmlelement_to_widget(TiXmlElement* elem, Widget* root)
{
  const char *elem_name = elem->Value();
  JWidget widget = NULL;
  JWidget child;

  /* TODO error handling: add a message if the widget is bad specified */

  // Boxes
  if (ustrcmp(elem_name, "box") == 0) {
    bool horizontal  = bool_attr_is_true(elem, "horizontal");
    bool vertical    = bool_attr_is_true(elem, "vertical");
    bool homogeneous = bool_attr_is_true(elem, "homogeneous");

    widget = new Box((horizontal ? JI_HORIZONTAL:
                      vertical ? JI_VERTICAL: 0) |
                     (homogeneous ? JI_HOMOGENEOUS: 0));
  }
  else if (ustrcmp(elem_name, "vbox") == 0) {
    bool homogeneous = bool_attr_is_true(elem, "homogeneous");

    widget = new VBox();
    if (homogeneous)
      widget->setAlign(widget->getAlign() | JI_HOMOGENEOUS);
  }
  else if (ustrcmp(elem_name, "hbox") == 0) {
    bool homogeneous = bool_attr_is_true(elem, "homogeneous");

    widget = new HBox();
    if (homogeneous)
      widget->setAlign(widget->getAlign() | JI_HOMOGENEOUS);
  }
  else if (ustrcmp(elem_name, "boxfiller") == 0) {
    widget = new BoxFiller();
  }
  // Button
  else if (ustrcmp(elem_name, "button") == 0) {
    const char *text = elem->Attribute("text");

    widget = new Button(text ? TRANSLATE_ATTR(text): NULL);
    if (widget) {
      bool left   = bool_attr_is_true(elem, "left");
      bool right  = bool_attr_is_true(elem, "right");
      bool top    = bool_attr_is_true(elem, "top");
      bool bottom = bool_attr_is_true(elem, "bottom");
      bool closewindow = bool_attr_is_true(elem, "closewindow");
      const char *_bevel = elem->Attribute("bevel");

      widget->setAlign((left ? JI_LEFT: (right ? JI_RIGHT: JI_CENTER)) |
                       (top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE)));

      if (_bevel != NULL) {
        char* bevel = base_strdup(_bevel);
        int c, b[4];
        char *tok;

        for (c=0; c<4; ++c)
          b[c] = 0;

        for (tok=ustrtok(bevel, " "), c=0;
             tok;
             tok=ustrtok(NULL, " "), ++c) {
          if (c < 4)
            b[c] = ustrtol(tok, NULL, 10);
        }
        base_free(bevel);

        setup_bevels(widget, b[0], b[1], b[2], b[3]);
      }

      if (closewindow) {
        static_cast<Button*>(widget)
          ->Click.connect(Bind<void>(&Widget::closeWindow, widget));
      }
    }
  }
  // Check
  else if (ustrcmp(elem_name, "check") == 0) {
    const char *text = elem->Attribute("text");
    const char *looklike = elem->Attribute("looklike");

    text = (text ? TRANSLATE_ATTR(text): NULL);

    if (looklike != NULL && strcmp(looklike, "button") == 0) {
      widget = new CheckBox(text, JI_BUTTON);
    }
    else {
      widget = new CheckBox(text);
    }

    if (widget) {
      bool center = bool_attr_is_true(elem, "center");
      bool right  = bool_attr_is_true(elem, "right");
      bool top    = bool_attr_is_true(elem, "top");
      bool bottom = bool_attr_is_true(elem, "bottom");

      widget->setAlign((center ? JI_CENTER:
                        (right ? JI_RIGHT: JI_LEFT)) |
                       (top    ? JI_TOP:
                        (bottom ? JI_BOTTOM: JI_MIDDLE)));
    }
  }
  /* combobox */
  else if (ustrcmp(elem_name, "combobox") == 0) {
    widget = new ComboBox();
  }
  /* entry */
  else if (ustrcmp(elem_name, "entry") == 0) {
    const char *maxsize = elem->Attribute("maxsize");
    const char *text = elem->Attribute("text");

    if (maxsize != NULL) {
      bool readonly = bool_attr_is_true(elem, "readonly");

      widget = new Entry(ustrtol(maxsize, NULL, 10),
                         text ? TRANSLATE_ATTR(text): NULL);

      if (readonly)
        ((Entry*)widget)->setReadOnly(true);
    }
  }
  /* grid */
  else if (ustrcmp(elem_name, "grid") == 0) {
    const char *columns = elem->Attribute("columns");
    bool same_width_columns = bool_attr_is_true(elem, "same_width_columns");

    if (columns != NULL) {
      widget = new Grid(ustrtol(columns, NULL, 10),
                        same_width_columns);
    }
  }
  /* label */
  else if (ustrcmp(elem_name, "label") == 0) {
    const char *text = elem->Attribute("text");

    widget = new Label(text ? TRANSLATE_ATTR(text): NULL);
    if (widget) {
      bool center = bool_attr_is_true(elem, "center");
      bool right  = bool_attr_is_true(elem, "right");
      bool top    = bool_attr_is_true(elem, "top");
      bool bottom = bool_attr_is_true(elem, "bottom");

      widget->setAlign((center ? JI_CENTER:
                        (right ? JI_RIGHT: JI_LEFT)) |
                       (top    ? JI_TOP:
                        (bottom ? JI_BOTTOM: JI_MIDDLE)));
    }
  }
  /* listbox */
  else if (ustrcmp(elem_name, "listbox") == 0) {
    widget = new ListBox();
  }
  /* listitem */
  else if (ustrcmp(elem_name, "listitem") == 0) {
    const char *text = elem->Attribute("text");

    widget = new ListBox::Item(text ? TRANSLATE_ATTR(text): NULL);
  }
  /* splitter */
  else if (ustrcmp(elem_name, "splitter") == 0) {
    bool horizontal = bool_attr_is_true(elem, "horizontal");
    bool vertical = bool_attr_is_true(elem, "vertical");

    widget = new Splitter(horizontal ? JI_HORIZONTAL:
                          vertical ? JI_VERTICAL: 0);
  }
  /* radio */
  else if (ustrcmp(elem_name, "radio") == 0) {
    const char* text = elem->Attribute("text");
    const char* group = elem->Attribute("group");
    const char *looklike = elem->Attribute("looklike");

    text = (text ? TRANSLATE_ATTR(text): NULL);
    int radio_group = (group ? ustrtol(group, NULL, 10): 1);

    if (looklike != NULL && strcmp(looklike, "button") == 0) {
      widget = new RadioButton(text, radio_group, JI_BUTTON);
    }
    else {
      widget = new RadioButton(text, radio_group);
    }

    if (widget) {
      bool center = bool_attr_is_true(elem, "center");
      bool right  = bool_attr_is_true(elem, "right");
      bool top    = bool_attr_is_true(elem, "top");
      bool bottom = bool_attr_is_true(elem, "bottom");

      widget->setAlign((center ? JI_CENTER:
                        (right ? JI_RIGHT: JI_LEFT)) |
                       (top    ? JI_TOP:
                        (bottom ? JI_BOTTOM: JI_MIDDLE)));
    }
  }
  /* separator */
  else if (ustrcmp(elem_name, "separator") == 0) {
    const char *text = elem->Attribute("text");
    bool center      = bool_attr_is_true(elem, "center");
    bool right       = bool_attr_is_true(elem, "right");
    bool middle      = bool_attr_is_true(elem, "middle");
    bool bottom      = bool_attr_is_true(elem, "bottom");
    bool horizontal  = bool_attr_is_true(elem, "horizontal");
    bool vertical    = bool_attr_is_true(elem, "vertical");

    widget = new Separator(text ? TRANSLATE_ATTR(text): NULL,
                           (horizontal ? JI_HORIZONTAL: 0) |
                           (vertical ? JI_VERTICAL: 0) |
                           (center ? JI_CENTER:
                            (right ? JI_RIGHT: JI_LEFT)) |
                           (middle ? JI_MIDDLE:
                            (bottom ? JI_BOTTOM: JI_TOP)));
  }
  /* slider */
  else if (ustrcmp(elem_name, "slider") == 0) {
    const char *min = elem->Attribute("min");
    const char *max = elem->Attribute("max");
    int min_value = min != NULL ? ustrtol(min, NULL, 10): 0;
    int max_value = max != NULL ? ustrtol(max, NULL, 10): 0;

    widget = new Slider(min_value, max_value, min_value);
  }
  /* textbox */
  else if (ustrcmp(elem_name, "textbox") == 0) {
    //bool wordwrap = bool_attr_is_true(elem, "wordwrap");

    /* TODO add translatable support */
    /* TODO here we need jxmlelem_get_text(elem) */
    /* widget = jtextbox_new(tag->text, wordwrap ? JI_WORDWRAP: 0); */
    ASSERT(false);
  }
  /* view */
  else if (ustrcmp(elem_name, "view") == 0) {
    widget = new View();
  }
  /* window */
  else if (ustrcmp(elem_name, "window") == 0) {
    const char *text = elem->Attribute("text");

    if (text) {
      bool desktop = bool_attr_is_true(elem, "desktop");

      if (desktop)
        widget = new Frame(true, NULL);
      else
        widget = new Frame(false, TRANSLATE_ATTR(text));
    }
  }
  /* colorpicker */
  else if (ustrcmp(elem_name, "colorpicker") == 0) {
    widget = new ColorButton(Color::fromMask(), app_get_current_pixel_format());
  }

  // Was the widget created?
  if (widget) {
    const char *name      = elem->Attribute("name");
    const char *tooltip   = elem->Attribute("tooltip");
    bool selected         = bool_attr_is_true(elem, "selected");
    bool disabled         = bool_attr_is_true(elem, "disabled");
    bool expansive        = bool_attr_is_true(elem, "expansive");
    bool magnetic         = bool_attr_is_true(elem, "magnetic");
    bool noborders        = bool_attr_is_true(elem, "noborders");
    const char *width     = elem->Attribute("width");
    const char *height    = elem->Attribute("height");
    const char *minwidth  = elem->Attribute("minwidth");
    const char *minheight = elem->Attribute("minheight");
    const char *maxwidth  = elem->Attribute("maxwidth");
    const char *maxheight = elem->Attribute("maxheight");
    const char *childspacing = elem->Attribute("childspacing");

    if (name != NULL)
      widget->setName(name);

    if (tooltip != NULL)
      jwidget_add_tooltip_text(widget, tooltip, JI_LEFT);

    if (selected)
      widget->setSelected(selected);

    if (disabled)
      widget->setEnabled(false);

    if (expansive)
      widget->setExpansive(true);

    if (magnetic)
      widget->setFocusMagnet(true);

    if (noborders)
      jwidget_noborders(widget);

    if (childspacing)
      widget->child_spacing = ustrtol(childspacing, NULL, 10);

    if (width || minwidth ||
        height || minheight) {
      int w = (width || minwidth) ? ustrtol(width ? width: minwidth, NULL, 10): 0;
      int h = (height || minheight) ? ustrtol(height ? height: minheight, NULL, 10): 0;
      jwidget_set_min_size(widget, w*jguiscale(), h*jguiscale());
    }

    if (width || maxwidth ||
        height || maxheight) {
      int w = (width || maxwidth) ? strtol(width ? width: maxwidth, NULL, 10): INT_MAX;
      int h = (height || maxheight) ? strtol(height ? height: maxheight, NULL, 10): INT_MAX;
      jwidget_set_max_size(widget, w*jguiscale(), h*jguiscale());
    }

    if (!root)
      root = widget;

    // Children
    TiXmlElement* child_elem = elem->FirstChildElement();
    while (child_elem) {
      child = convert_xmlelement_to_widget(child_elem, root);
      if (child) {
        // Attach the child in the view
        if (widget->type == JI_VIEW) {
          static_cast<View*>(widget)->attachToView(child);
          break;
        }
        // Add the child in the grid
        else if (widget->type == JI_GRID) {
          const char* cell_hspan = child_elem->Attribute("cell_hspan");
          const char* cell_vspan = child_elem->Attribute("cell_vspan");
          const char* cell_align = child_elem->Attribute("cell_align");
          int hspan = cell_hspan ? ustrtol(cell_hspan, NULL, 10): 1;
          int vspan = cell_vspan ? ustrtol(cell_vspan, NULL, 10): 1;
          int align = cell_align ? convert_align_value_to_flags(cell_align): 0;
          Grid* grid = dynamic_cast<Grid*>(widget);
          ASSERT(grid != NULL);

          grid->addChildInCell(child, hspan, vspan, align);
        }
        // Just add the child in any other kind of widget
        else
          widget->addChild(child);
      }
      child_elem = child_elem->NextSiblingElement();
    }

    if (widget->type == JI_VIEW) {
      bool maxsize = bool_attr_is_true(elem, "maxsize");
      if (maxsize)
        static_cast<View*>(widget)->makeVisibleAllScrollableArea();
    }
  }

  return widget;
}