Ejemplo n.º 1
0
static int evtChangeTheme(struct pgEvent *evt) {
  char buf[80];
  int i;
  pghandle currContext;

  i = pgGetPayload(evt->from);

  if (array[i].active) {
      pgDelete(array[i].handle);
      array[i].active = 0;
  }
  else {

      /* fixme buffer overflow... */
      strcpy(buf, pgGetString(array[i].dir));
      strcat(buf, pgGetString(array[i].fname));

      printf("buf: %s", buf);

/*       pgSetContext(*themeContext); */
/*       array[i].handle = pgLoadTheme(pgFromFile(buf)); */
/*       pgSetContext(*pageContext); */

      currContext = pgGetContext();
      pgSetContext(*(pghandle*)(evt->extra));
      array[i].handle = pgLoadTheme(pgFromFile(buf));
      pgSetContext(currContext);


      array[i].active = 1;
  }

  return 0;
}
Ejemplo n.º 2
0
void set_vfd_text(pghandle vfd,const char *text) {
  /* Use the lower level canvas commands to change the VFD's text.
   * The display's previous text is stored as its payload so we can
   * delete it, and we set the new text by changing the text gropnode's
   * parameter
   */

  pghandle h;
  pgDelete(pgGetPayload(vfd));
  h = pgNewString(text);
  pgWriteCmd(vfd,PGCANVAS_SETGROP,1,h);
  pgWriteCmd(vfd,PGCANVAS_REDRAW,0);
  pgSetPayload(vfd,h);
}
Ejemplo n.º 3
0
/* This creates a menu from an array of string handles. 
 * Same return values as pgMenuFromString above.
 *
 * Important note: pgMenuFromArray expects that a new
 *                 context will be entered before the
 *                 string handles are created
 */
int pgMenuFromArray(pghandle *items,int numitems) {
  int i;
  pghandle returnHandle;
  returnHandle = pgNewPopupAt(PG_POPUP_ATEVENT,PG_POPUP_ATEVENT,0,0);

  for (i=0;i<numitems;i++) {
    printf("Menu Item => %d\n", pgNewWidget(PG_WIDGET_MENUITEM,0,0));
    pgSetWidget(PGDEFAULT,
		PG_WP_TEXT,items[i],
		0);
    pgSetPayload(PGDEFAULT,i+1);
  }

  /* Return event */
  return pgGetPayload(pgGetEvent()->from);
}
Ejemplo n.º 4
0
/* There are many ways to create a menu in PicoGUI
 * (at the lowest level, using pgNewPopupAt and the menuitem widget)
 *
 * This creates a static popup menu from a "|"-separated list of
 * menu items, and returns the number (starting with 1) of the chosen
 * item, or 0 for cancel.
 */
int pgMenuFromString(char *items) {
  char *p;
  pghandle str;
  int ret;
  int i;

  if (!items || !*items) return 0;

  /* Create the menu popup in its own context */
  pgEnterContext();
  pgNewPopupAt(PG_POPUP_ATEVENT,PG_POPUP_ATEVENT,0,0);
  
  i=0;
  do {
    /* Do a little fancy stuff to make the string handle.
     * This is like pgNewString but we get to specify the 
     * length instead of having strlen() do it for us.
     */
    if (!(p = strchr(items,'|'))) p = items + strlen(items);
    _pg_add_request(PGREQ_MKSTRING,(void *) items,p-items);
    items = p+1;
    pgFlushRequests();
    str = _pg_return.e.retdata;

    /* Create each menu item */
    pgNewWidget(PG_WIDGET_MENUITEM,0,0);
    pgSetWidget(PGDEFAULT,
		PG_WP_TEXT,str,
		0);
    pgSetPayload(PGDEFAULT,++i);

  } while (*p);

  /* Run the menu */
  ret = pgGetPayload(pgGetEvent()->from);
  pgLeaveContext();
  return ret;
}
Ejemplo n.º 5
0
/* Create a message box, wait until it is
 * answered, then return the answer.
 */
int pgMessageDialog(const char *title,const char *text,u32 flags) {
  u32 ret;
  pghandle wToolbar;

  /* New context for us! */
  pgEnterContext();

  /* Default flags if none are supplied */
  if (!(flags & PG_MSGBTNMASK))
    flags |= PG_MSGBTN_OK;
  if (!(flags & PG_MSGICONMASK)) {
    /* Assume that if the user can say no, it's a question */
    
    if (flags & (PG_MSGBTN_CANCEL | PG_MSGBTN_NO))
      flags |= PG_MSGICON_QUESTION;
    else
      flags |= PG_MSGICON_MESSAGE;
  }

  /* Create the important widgets */
  pgDialogBox(title);
  wToolbar = pgNewWidget(PG_WIDGET_TOOLBAR,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      0);
  pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_ALL,
	      PG_WP_TEXT,pgNewString(text),
	      0);

  /* Buttons */
  if (flags & PG_MSGBTN_CANCEL)
    dlgbtn(wToolbar,PG_MSGBTN_CANCEL,PGRES_STRING_CANCEL,
	   PGTH_P_ICON_CANCEL,PGTH_P_HOTKEY_CANCEL);
  if (flags & PG_MSGBTN_OK)
    dlgbtn(wToolbar,PG_MSGBTN_OK,PGRES_STRING_OK,
	   PGTH_P_ICON_OK,PGTH_P_HOTKEY_OK);
  if (flags & PG_MSGBTN_YES)
    dlgbtn(wToolbar,PG_MSGBTN_YES,PGRES_STRING_YES,
	   PGTH_P_ICON_YES,PGTH_P_HOTKEY_YES);
  if (flags & PG_MSGBTN_NO)
    dlgbtn(wToolbar,PG_MSGBTN_NO,PGRES_STRING_NO,
	   PGTH_P_ICON_NO,PGTH_P_HOTKEY_NO);

  /* Icons */
  if (flags & PG_MSGICON_ERROR)
    dlgicon(wToolbar,PGTH_P_ICON_ERROR);
  if (flags & PG_MSGICON_MESSAGE)
    dlgicon(wToolbar,PGTH_P_ICON_MESSAGE);
  if (flags & PG_MSGICON_QUESTION)
    dlgicon(wToolbar,PGTH_P_ICON_QUESTION);
  if (flags & PG_MSGICON_WARNING)
    dlgicon(wToolbar,PGTH_P_ICON_WARNING);

  /* Run it (ignoring zero-payload events) */
  while (!(ret = pgGetPayload(pgGetEvent()->from)));

  /* Go away now */
  pgLeaveContext();

  return ret;
}