Exemplo n.º 1
0
int main(int argc, char **argv) {
  pghandle wPGLbar,wBattbox;
  pgInit(argc,argv);

  /* Find the applet container */
  wPGLbar = pgFindWidget("PGL-AppletBar");
  if (!wPGLbar) {
    pgMessageDialog(argv[0],"This applet requires PGL",PG_MSGICON_ERROR);
    return 1;
  }
 
  wBattbox = pgNewWidget(PG_WIDGET_BOX,PG_DERIVE_INSIDE,wPGLbar);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      0);

  pgNewWidget(PG_WIDGET_LABEL,PG_DERIVE_INSIDE,wBattbox);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Batt"),
	      PG_WP_SIDE,PG_S_RIGHT,
	      0);

  wBatt = pgNewWidget(PG_WIDGET_INDICATOR,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      0);  

  /* Run it. */
  pgSetIdle(4000,&sysIdle);
  pgEventLoop();
   
  return 0;
}
Exemplo n.º 2
0
int main(int argc,char **argv) {
  pghandle wPGLbar;
  pgInit(argc,argv);

  /* Find the applet container */
  pglToolbar = pgFindWidget("PGL-AppletBar");
  if (!pglToolbar) {
    pgMessageDialog(argv[0],"This applet requires PGL",PG_MSGICON_ERROR);
    return 1;
  }
 
  /* Clock widget. Make it a flatbutton so it normally looks fairly
   * unobtrusive, but it can be clicked. Clicking the clock launches
   * an options dialog box.
   */
  currentClock.wClock = pgNewWidget(PG_WIDGET_FLATBUTTON,
				    PG_DERIVE_INSIDE,pglToolbar);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_NAME,pgNewString("PGL-Clock"),
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnDialog,NULL);
  pgBind(PGDEFAULT, PG_WE_APPMSG, &recieveMessage, NULL);

  /* Let the toolbar know we exist */
  
  pgAppMessage(pglToolbar, pglBuildMessage(PGL_APPLETINSTALLED, "PGL-Clock", "", ""));

  /* Set up default clock */
  currentClock.fClockFont = pgNewFont(NULL,0,PG_FSTYLE_FIXED);
  mungeSettings();

  pgEventLoop();
  return 0;
}
Exemplo n.º 3
0
int PG_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
        /* Connect to the PicoGUI server. No way to process command line args yet,
	 * but since this is based on SHM it's not important to be able to specify
	 * a remote PicoGUI server.
	 *
	 * FIXME: Another nitpick about the current client lib is there's no
	 *        clean way to indicate that command line args are not available.
	 */
        pgInit(0,(char**)"");
	this->hidden->mi = *pgGetVideoMode();

	/* Create a picogui application and canvas. We'll populate the canvas later. */
	this->hidden->wApp = pgRegisterApp(PG_APP_NORMAL,"SDL",0);
	this->hidden->wCanvas = pgNewWidget(PG_WIDGET_CANVAS,0,0);
	pgSetWidget(PGDEFAULT,
		    PG_WP_SIDE, PG_S_ALL,
		    0);

	PG_InitEvents(this);

	/* Determine the screen depth.
	 * We change this during the SDL_SetVideoMode implementation... 
	 * Round up to the nearest Bytes per pixel
	 */
	vformat->BitsPerPixel = this->hidden->mi.bpp;
	vformat->BytesPerPixel = this->hidden->mi.bpp >> 3;
	if (this->hidden->mi.bpp & 7)
	  vformat->BytesPerPixel++;

	/* We're done! */
	return(0);
}
Exemplo n.º 4
0
int main(int argc, char **argv){
  struct keyboard_command cmd_toggle         = {htons (PG_KEYBOARD_TOGGLE)};

  pgInit(argc, argv);
  
  /* Find the applet container */
  pglToolbar = pgFindWidget("PGL-AppletBar");
  if (!pglToolbar) {
    pgMessageDialog(argv[0],"This applet requires PGL",PG_MSGICON_ERROR);
    return 1;
  }

  pglButton = pgNewWidget(PG_WIDGET_FLATBUTTON, PG_DERIVE_INSIDE, pglToolbar);
  pgSetWidget (pglButton,
	       PG_WP_NAME, pgNewString("PGL-Keyboard"),
	       PG_WP_SIDE, PG_S_RIGHT,
	       0);
  pgBind(pglButton, PG_WE_APPMSG, &recieveMessage, NULL);
  pgBind(pglButton, PG_WE_ACTIVATE, &handleButton, &cmd_toggle);

  pgAppMessage(pglToolbar, pglBuildMessage(PGL_APPLETINSTALLED, "PGL-Keyboard", "", ""));

  pgEventLoop();
  return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv) {
  pghandle w[40];
  pghandle app;
  int i;
  float t;
  
  pgInit(argc,argv);
  app = pgRegisterApp(PG_APP_NORMAL,"Scrollbar Fun - C",0);
  
  for (i=0;i<40;i++) {
    w[i] = pgNewWidget(PG_WIDGET_SCROLL,PG_DERIVE_INSIDE,app);
    pgSetWidget(PGDEFAULT,
		PG_WP_SIDE, PG_S_LEFT,
		0);
  }
  
  t = 0;
  while (1) {
    t += 0.04;
    for (i=0;i<40;i++)
      pgSetWidget(w[i],
		  PG_WP_VALUE, (int)(50 + 50 * sin(i*0.2+t)),
		  0);
    pgUpdate();
  }

  return 0;
}
Exemplo n.º 6
0
/* Create the phone keypad so we can easily turn it on and off later */
void init_keypad(void) {
  pghandle column,button;
  int i,j;
  struct pgEvent e;
  pghandle font;

  /* Create the keypad toolbar, invisible for now */
  wKeypad = pgRegisterApp(PG_APP_TOOLBAR,"pgtuxphone/keypad",
			  PG_APPSPEC_SIDE, PG_S_BOTTOM,
			  0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIZE,0,
	      0);

  font = pgNewFont(NULL,20,0);

  /* Make our button grid */
  for (i=0, column=0;i<3;i++) {
    column = pgNewWidget(PG_WIDGET_BOX,column ? PG_DERIVE_AFTER : PG_DERIVE_INSIDE,
			 column);
    pgSetWidget(PGDEFAULT,
		PG_WP_TRANSPARENT,1,
		PG_WP_SIDE,PG_S_LEFT,
		0);
    for (j=0, button=0; j<4;j++) {
      button = pgNewWidget(PG_WIDGET_BUTTON, button ? PG_DERIVE_AFTER :
			   PG_DERIVE_INSIDE, button ? button : column);
      pgSetWidget(PGDEFAULT,
		  //		  PG_WP_SIZE,pgFraction(1,4),
		  //		  PG_WP_SIZEMODE,PG_SZMODE_CNTFRACT,
		  PG_WP_TEXT,pgNewString(keypad[j][i]),
		  PG_WP_FONT,font,
		  PG_WP_SIDE,PG_S_TOP,
		  0);

      /* Extra is a pointer to the digit to dial. Since there's some padding
       * in the button strings, the +1 gives the character itself
       */
      pgBind(PGDEFAULT,PG_WE_ACTIVATE,btnDial,keypad[j][i]+1);
    }
  }
}
Exemplo n.º 7
0
int main(int argc, char **argv) {
   pgInit(argc,argv);
   pgRegisterApp(PG_APP_NORMAL,"Blackout",0);

   /*** Top-level widgets: toolbar and canvas */
   wToolbar = pgNewWidget(PG_WIDGET_TOOLBAR,0,0);
   wCanvas = pgNewWidget(PG_WIDGET_CANVAS,0,0);
   pgBind(PGDEFAULT,PG_WE_BUILD,&evtDrawBoard,NULL);
   pgBind(PGDEFAULT,PG_WE_PNTR_DOWN,&evtMouseDown,NULL);

   /* Toolbar thingies */
   
   pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wToolbar);
   pgSetWidget(PGDEFAULT,
	       PG_WP_TEXT,pgNewString("Menu"),
	       PG_WP_EXTDEVENTS,PG_EXEV_PNTR_DOWN,
	       0);
   pgBind(PGDEFAULT,PG_WE_PNTR_DOWN,&btnMenu,NULL);

   wStatusLabel = pgNewWidget(PG_WIDGET_LABEL,0,0);
   pgSetWidget(PGDEFAULT,
	       PG_WP_SIDE,PG_S_ALL,
	       PG_WP_TRANSPARENT,0,
	       PG_WP_ALIGN,PG_A_CENTER,
//	       PG_WP_FONT,pgNewFont(NULL,10,PG_FSTYLE_BOLD),
	       0);


   /*** Allocate default game board */
   srand(time(NULL));
   boardwidth = 5;
   boardheight = 5;
   boardsize = sizeof(light) * boardwidth * boardheight;
   board = (light *) malloc(boardsize);
   solution = (light *) malloc(boardsize);
   startLevel(1);
   
   /*** Event loop */
   pgEventLoop();
   return 0;
}
Exemplo n.º 8
0
int btnTarget(struct pgEvent *evt) {
  pgcontext gc;
  pghandle wClose,wTB;
  int i,x,w;

  pgEnterContext();
  pgDialogBox("Target");
  wTB = pgNewWidget(PG_WIDGET_TOOLBAR,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      0);

  /* Just draw something fun here */
  pgNewWidget(PG_WIDGET_CANVAS,0,0);
  gc = pgNewCanvasContext(PGDEFAULT,PGFX_PERSISTENT);
  pgSetMapping(gc,0,0,100,100,PG_MAP_SCALE);
  for (i=0;i<=4;i++) {
    x = i*10;
    w = 100-(x<<1);
    pgSetColor(gc,i&1 ? 0xFFFFFF : 0xFF0000);
    pgFEllipse(gc,x,x,w,w);
    pgSetColor(gc,0x000000);
    pgEllipse(gc,x,x,w,w);
  }
  pgContextUpdate(gc);
  pgDeleteContext(gc);

  /* A close button */
  wClose = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wTB);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Close"),
	      PG_WP_HOTKEY,PGKEY_RETURN,
	      PG_WP_SIDE,PG_S_RIGHT,
	      0);

  /* Wait for a click on the canvas, then clean up */
  while (pgGetEvent()->from != wClose);
  pgLeaveContext();
  return 0;
}
Exemplo n.º 9
0
void
addheader (int msg, char *sender, char *subject, char *date)
{
    lastItem = pgNewWidget (PG_WIDGET_LISTITEM,
                            row ? PGDEFAULT : PG_DERIVE_INSIDE,
                            row ? lastItem : wBox);

    pgReplaceTextFmt (lastItem, "[%s] %s - %s",date, subject, sender);
    pgBind (lastItem, PG_WE_ACTIVATE, &setSelected, (void *) (msg));
    pgEventPoll ();

    row++;
}
Exemplo n.º 10
0
void dlgicon(pghandle at,int prop) {
  pghandle bit;

  bit = pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,prop);
  if (bit) {

  pgNewWidget(PG_WIDGET_LABEL,PG_DERIVE_AFTER,at);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_LEFT,
	      PG_WP_IMAGE,bit,
	      PG_WP_BITMASK,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,prop+1),
	      0);
  }
}
Exemplo n.º 11
0
/* Little internal helper function for the message dialog */
void dlgbtn(pghandle tb,u32 payload,int textproperty,
	    int iconproperty,int key) {

  pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,tb);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgGetServerRes(textproperty),
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_HOTKEY,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,key),
	      PG_WP_IMAGE,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 iconproperty),
	      PG_WP_BITMASK,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					  iconproperty+1),
	      0);
  pgSetPayload(PGDEFAULT,payload);
}
Exemplo n.º 12
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);
}
Exemplo n.º 13
0
int main(int argc, char **argv) {
  pghandle wLoadbox,fntLabel;

  pgInit(argc,argv);
  pgRegisterApp(PG_APP_TOOLBAR,"OmniBar-Helio",0);

  /* A font for our labels */
  fntLabel = pgNewFont(NULL,10,PG_FSTYLE_FIXED);

  /* Top-level widgets */

  pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("App"),
	      PG_WP_EXTDEVENTS,PG_EXEV_PNTR_DOWN,
	      0);
  pgBind(PGDEFAULT,PG_WE_PNTR_DOWN,&btnAppMenu,NULL);

  pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Sys"),
	      PG_WP_EXTDEVENTS,PG_EXEV_PNTR_DOWN,
	      0);
  pgBind(PGDEFAULT,PG_WE_PNTR_DOWN,&btnSysMenu,NULL);

  wClock = pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_FONT,fntLabel,
	      PG_WP_TRANSPARENT,0,
	      0);

  pgNewWidget(PG_WIDGET_BOX,0,0);
  pgNewWidget(PG_WIDGET_LABEL,PG_DERIVE_INSIDE,PGDEFAULT);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Batt:"),
	      PG_WP_SIDE,PG_S_LEFT,
	      PG_WP_TRANSPARENT,1,
	      0);
  wBatt = pgNewWidget(PG_WIDGET_INDICATOR,0,0);
  pgSetWidget(PGDEFAULT,PG_WP_SIDE,PG_S_ALL,0);

  /* Run it. */
  pgSetIdle(5000,&sysIdle);
  pgEventLoop();
   
  return 0;
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
0
picosmUI *buildUI(void){
  picosmUI *newUI = (picosmUI *)malloc(sizeof(picosmUI));

  if(!(newUI->wApp = pgFindWidget("PSMApp"))){
    newUI->wApp = pgCreateWidget(PG_WIDGET_DIALOGBOX);
    pgSetWidget(newUI->wApp,
		PG_WP_NAME,pgNewString("PSMApp"),
		PG_WP_TEXT,pgNewString("PicoGUI Login"),
		0);
  }

  if(!(newUI->wButtonBox = pgFindWidget("PSMButtonBox"))){
    newUI->wButtonBox = pgNewWidget(PG_WIDGET_TOOLBAR, PG_DERIVE_INSIDE, 
				    newUI->wApp);
    pgSetWidget(newUI->wButtonBox,
		PG_WP_NAME,pgNewString("PSMButtonBox"),
		PG_WP_SIDE, PG_S_BOTTOM,
		0);
  }

  if(!(newUI->wPasswdBox = pgFindWidget("PSMPasswdBox"))){
    newUI->wPasswdBox = pgNewWidget(PG_WIDGET_BOX, PG_DERIVE_INSIDE, 
				    newUI->wApp);
    pgSetWidget(newUI->wPasswdBox,
		PG_WP_NAME,pgNewString("PSMPasswdBox"),
		PG_WP_TRANSPARENT, 1,
		0);
  }

  if(!(newUI->wLoginBox = pgFindWidget("PSMLoginBox"))){
    newUI->wLoginBox = pgNewWidget(PG_WIDGET_BOX, PG_DERIVE_INSIDE, 
				   newUI->wApp);
    pgSetWidget(newUI->wLoginBox,
		PG_WP_NAME,pgNewString("PSMLoginBox"),
		PG_WP_TRANSPARENT, 1,
		0);
  }

  if(!(newUI->wLoginLabel = pgFindWidget("PSMLoginLabel"))){
    newUI->wLoginLabel = pgNewWidget(PG_WIDGET_LABEL, PG_DERIVE_INSIDE, 
				     newUI->wLoginBox);
    pgSetWidget(newUI->wLoginLabel, 
		PG_WP_NAME,pgNewString("PSMLoginLabel"),
		PG_WP_TEXT, pgNewString("Login: "******"PSMLogin"))){
    newUI->wLogin = pgNewWidget(PG_WIDGET_FIELD, PG_DERIVE_INSIDE, 
				newUI->wLoginBox);
    pgSetWidget(newUI->wLogin, 
		PG_WP_NAME,pgNewString("PSMLogin"),
		PG_WP_SIDE, PG_S_RIGHT,
		PG_WP_SIZEMODE, PG_SZMODE_PERCENT,
		PG_WP_SIZE, 70,
		0);
    pgFocus(newUI->wLogin);
  }
    
  if(!(newUI->wPasswdLabel = pgFindWidget("PSMPasswdLabel"))){
    newUI->wPasswdLabel = pgNewWidget(PG_WIDGET_LABEL, PG_DERIVE_INSIDE, 
				      newUI->wPasswdBox);
    pgSetWidget(newUI->wPasswdLabel, 
		PG_WP_NAME,pgNewString("PSMPasswdLabel"),
		PG_WP_TEXT, pgNewString("Password: "******"PSMPasswd"))){
    newUI->wPasswd = pgNewWidget(PG_WIDGET_FIELD, PG_DERIVE_INSIDE, 
				 newUI->wPasswdBox);
  
    pgSetWidget(newUI->wPasswd, 
		PG_WP_NAME,pgNewString("PSMPasswd"),
		PG_WP_SIDE, PG_S_RIGHT,
		PG_WP_SIZEMODE, PG_SZMODE_PERCENT,
		PG_WP_PASSWORD, '*',
		PG_WP_SIZE, 70,
		0);
  }

  if(!(newUI->wClear = pgFindWidget("PSMClear"))){
    newUI->wClear = pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, 
				newUI->wButtonBox);
    pgSetWidget(newUI->wClear,
		PG_WP_NAME,pgNewString("PSMClear"),
		PG_WP_ALIGN, PG_A_CENTER,
		PG_WP_SIDE, PG_S_RIGHT,
		PG_WP_TEXT, pgNewString("Clear"),
		0);
  }

  if(!(newUI->wLogon = pgFindWidget("PSMLogon"))){
    newUI->wLogon = pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE,
				newUI->wButtonBox);
    pgSetWidget(newUI->wLogon,
		PG_WP_NAME,pgNewString("PSMLogon"),
		PG_WP_ALIGN, PG_A_CENTER,
		PG_WP_SIDE, PG_S_RIGHT,
		PG_WP_TEXT, pgNewString("Log On"),
		0);
  }

  if(!(newUI->wReboot = pgFindWidget("PSMReboot"))){
    newUI->wReboot = pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, 
				 newUI->wButtonBox);
    pgSetWidget(newUI->wReboot,
		PG_WP_NAME,pgNewString("PSMReboot"),
		PG_WP_ALIGN, PG_A_CENTER,
		PG_WP_SIDE, PG_S_LEFT,
		PG_WP_TEXT, pgNewString("Reboot"),
		0);
  }

  if(!(newUI->wPowerOff = pgFindWidget("PSMPowerOff"))){
    newUI->wPowerOff = pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, 
				   newUI->wButtonBox);
    pgSetWidget(newUI->wPowerOff,
		PG_WP_NAME,pgNewString("PSMPowerOff"),
		PG_WP_ALIGN, PG_A_CENTER,
		PG_WP_SIDE, PG_S_LEFT,
		PG_WP_TEXT, pgNewString("Power Off"),
		0);
  }

  return newUI;
}
Exemplo n.º 16
0
int main(int argc, char **argv) {
  pghandle wAllBox, wTXbox, wRXbox;

  /* initialise and register the application */
  pgInit(argc,argv);
  pgRegisterApp(PG_APP_NORMAL,"Network Monitor",0);
  
  /* create a box for putting all the ting inside it */
  wAllBox = pgNewWidget(PG_WIDGET_BOX,0,0);

  /* create a widget which have the name of the interface to monitor */
  wDeviceName = pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, wAllBox);
  pgSetWidget (PGDEFAULT,
	       //PG_WP_DIRECTION,PG_DIR_VERTICAL,
	       PG_WP_SIDE, PG_S_RIGHT,
	       PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN,
	       0);
  pgReplaceTextFmt (wDeviceName, "%s", DEFAULT_NETWORK_INTERFACE);
  pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &selectInterface, NULL);

  /* create the widgets for monitor the RX traffic */
  wRXlabel = pgNewWidget(PG_WIDGET_BUTTON, 0, 0);
  pgSetWidget (PGDEFAULT,
	       PG_WP_SIDE, PG_S_TOP,
	       PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN,
	       0);
  pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &changeDisplay, NULL);
  wRXbox = pgNewWidget(PG_WIDGET_BOX, 0,0);

  /* create the widgets for monitor the TX traffic */
  wTXlabel = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget (PGDEFAULT,
	       PG_WP_SIDE, PG_S_TOP,
	       PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN,
	       0);
  pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &changeDisplay, NULL);
  wTXbox = pgNewWidget(PG_WIDGET_BOX,0,0);

  /* add the RX gauge */
  pgNewWidget(PG_WIDGET_LABEL, PG_DERIVE_INSIDE, wRXbox);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT, pgNewString("RX"),
	      PG_WP_SIDE, PG_S_RIGHT,
	      0);
  wRX = pgNewWidget(PG_WIDGET_INDICATOR, 0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE, PG_S_ALL,
	      0);

  /* add the TX gauge */
  pgNewWidget(PG_WIDGET_LABEL, PG_DERIVE_INSIDE, wTXbox);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT, pgNewString("TX"),
	      PG_WP_SIDE, PG_S_RIGHT,
	      0);
  wTX = pgNewWidget(PG_WIDGET_INDICATOR, 0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE, PG_S_ALL,
	      0);

  /* put the monitoring in the idle time */
  pgSetIdle(IDLE_TIME,&sysIdle);

  /* the main loop */
  pgEventLoop();

  /* bye */
  return 0;

}
Exemplo n.º 17
0
/* Create our toolbar */
void init_call_info(void) {
  pghandle bArrowMask,bArrow;
    
  /* Set up a bitmap/bitmask for the keypad button up arrow.
   * We have the mask stored in PNM format, and we paint
   * the arrow bitmap itself solid black. If we wanted another
   * color for the arrow, we could paint it that other color,
   * then apply the bitmask to it with the PG_LGOP_INVERT_AND
   * logical operation to mask out only the arrow part.
   */
  bArrowMask = pgNewBitmap(pgFromMemory(arrow_bits,arrow_len));
  bArrow = pgCreateBitmap(11,6);
  pgRender(bArrow,PG_GROP_SETCOLOR,0x000000);
  pgRender(bArrow,PG_GROP_RECT,0,0,15,8);

  /* Create a toolbar that starts out hidden */
  wInfoBar = pgRegisterApp(PG_APP_TOOLBAR,"pgtuxphone/call_info",
			   PG_APPSPEC_SIDE, PG_S_BOTTOM,
			   0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIZE,0,
	      0);
  
  /* Create widgets within the toolbar */
  
  wKeypadBtn = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_LEFT,
	      PG_WP_BITMAP, bArrow,
	      PG_WP_BITMASK, bArrowMask,
	      PG_WP_EXTDEVENTS, PG_EXEV_TOGGLE,
	      PG_WP_TEXT,pgNewString("Keypad"),
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnKeypad,NULL);
  
  pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_LEFT,
	      PG_WP_TEXT,pgNewString("Redial"),
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnRedial,NULL);

  /* Make the connect time opaque and fixed-width to minimize the
   * amount of redrawing necessary to update it */
  wConnectTime = pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TRANSPARENT,0,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_FONT,pgNewFont(NULL,0,PG_FSTYLE_FIXED),
	      0);
  wCallStatus = pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      0);

  wName = pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_LEFT,
	      PG_WP_FONT,pgNewFont(NULL,12,0),
	      0);

  wPhoneNumber = pgNewWidget(PG_WIDGET_CANVAS,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_ALL,
	      0);
  new_vfd_label(wPhoneNumber);

}
Exemplo n.º 18
0
int main(int argc,char **argv) {
  pghandle frames[NUMFRAMES];
  char frname[FRAMENAMELEN];
  int i, d;
  pghandle wBitmap, wOk;

  pgInit(argc,argv);

  /* This is so we can clean up afterwards. This isn't necessary for this
   * simple demo, but if this code is used as part of a larger app this
   * is very important.
   */
  pgEnterContext();

  /* Load the frames into memory */
  for (i=0;i<NUMFRAMES;i++) {
    snprintf(frname,FRAMENAMELEN,FRAMENAME,i);
    frames[i] = pgNewBitmap(pgFromFile(frname));
  }

  /* Create a dialog box with an ok button and bitmap widget */
  pgDialogBox(ANIMTITLE);
  wOk = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      PG_WP_TEXT,pgGetServerRes(PGRES_STRING_OK),
	      PG_WP_HOTKEY,pgThemeLookup(PGTH_O_DEFAULT,PGTH_P_HOTKEY_OK),
	      0);
  wBitmap = pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_ALL,
	      PG_WP_TRANSPARENT,0,
	      0);

  /* Animation loop */
  i = 0;
  d = 1;
  for (;;) {
    
    /* change the frame, update the screen */
    pgSetWidget(wBitmap,
		PG_WP_BITMAP,frames[i],
		0);
    pgUpdate();
    
    /* Check whether the ok button was clicked */
    if (pgCheckEvent() && pgGetEvent()->from==wOk)
      break;

    /* Small delay between frames */
    usleep(1);

    /* Next frame, ping-pong style */
    if (i == NUMFRAMES-1)
      d = -1;
    if (!i)
      d = 1;
    i += d;
  }

  /* Clean up */
  pgLeaveContext();

  return 0;
}
Exemplo n.º 19
0
int
main (int argc, char *argv[])
{
    char *home, *conffile;

    pghandle msgscroll, msgbox;
    pghandle wToolbar, wScroll, wItem;

    row = 0;

    pgInit (argc, argv);
    picomailapp = pgRegisterApp (PG_APP_NORMAL, "PicoMail", 0);

    home = getenv ("HOME");
    conffile = malloc (strlen (home) + strlen (CONFIG_FILE) + 1);
    if (home && conffile)
    {
        strcpy (conffile, home);
        strcat (conffile, CONFIG_FILE);

        if (!configfile_parse (conffile))
        {
            pgMessageDialog ("PicoMail",
                             "Configuration file could not be parsed.\n"
                             "Please make sure you have a good '~/.picomail.conf'!",
                             PG_MSGBTN_OK || PG_MSGICON_ERROR);
            exit (1);
        }
        free (conffile);
    }

    wToolbar = pgNewWidget (PG_WIDGET_TOOLBAR, 0, 0);



    wScroll = pgNewWidget (PG_WIDGET_SCROLL, 0, 0);
    wBox = pgNewWidget (PG_WIDGET_BOX, 0, 0);
    pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_ALL, 0);
    pgSetWidget (wScroll, PG_WP_BIND, wBox, 0);




    pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, wToolbar);
    pgSetWidget (PGDEFAULT,
                 PG_WP_TEXT, pgNewString ("Read Message"),
                 PG_WP_SIDE, PG_S_LEFT, PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0);
    pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &readMessage, NULL);


    pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, wToolbar);
    pgSetWidget (PGDEFAULT,
                 PG_WP_TEXT, pgNewString ("Delete Message"),
                 PG_WP_SIDE, PG_S_LEFT, PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0);
    pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &deleteMessage, NULL);


    pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, wToolbar);
    pgSetWidget (PGDEFAULT,
                 PG_WP_TEXT, pgNewString ("Get list of messages!"),
                 PG_WP_SIDE, PG_S_LEFT, PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0);
    pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &getList, NULL);

    pgBind (PGBIND_ANY, PG_WE_CLOSE, &closeboxHandler, NULL);

    /* message viewer */

    mesgviewer = pgRegisterApp (PG_APP_NORMAL, "PicoMail Message", 0);
    pgBind (mesgviewer, PG_WE_CLOSE, &viewerCloseboxHandler, NULL);
    pgSetWidget (mesgviewer, PG_WP_SIZE, 0, 0);
    msgscroll = pgNewWidget (PG_WIDGET_SCROLL, 0, 0);
    msgbox = pgNewWidget (PG_WIDGET_BOX, 0, 0);
    pgSetWidget (msgbox, PG_WP_SIDE, PG_S_ALL, 0);
    pgSetWidget (msgscroll, PG_WP_BIND, msgbox, 0);
    messagebox = pgNewWidget (PG_WIDGET_TEXTBOX, PG_DERIVE_INSIDE, PGDEFAULT);
//        pgSetWidget(msgscroll, PG_WP_BIND,messagebox, 0);
    pgSetWidget (messagebox,
                 PG_WP_TEXT, pgNewString ("Hier is uw bericht!"), 0);



    pgEventLoop ();

    configfile_free ();
    return 0;
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
int main(int argc, char **argv) {
  struct pgEvent *evt;
  pghandle wApply,wClose,sTmp,wToolbar;
  pghandle wXres,wYres,wBpp,wRotate,wPopup;
  struct pgmodeinfo mi;
  char buf[20];
   
  pgInit(argc,argv);
  wPopup = pgDialogBox("Set Video Mode");

  /******** Take care of such niceties... */
   
  wToolbar = pgNewWidget(PG_WIDGET_TOOLBAR,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      0);
		  
  wApply = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wToolbar);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Apply"),
	      0);

  wClose = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Close"),
	      0);

  /******** Mode options */
   
  /* For now just make boxes, we'll fill them in later */
  wXres = pgNewWidget(PG_WIDGET_BOX,PG_DERIVE_AFTER,wToolbar);
  pgSetWidget(PGDEFAULT,PG_WP_TRANSPARENT,1,0);
  wYres = pgNewWidget(PG_WIDGET_BOX,0,0);
  pgSetWidget(PGDEFAULT,PG_WP_TRANSPARENT,1,0);
  wBpp = pgNewWidget(PG_WIDGET_BOX,0,0);
  pgSetWidget(PGDEFAULT,PG_WP_TRANSPARENT,1,0);
   
  wRotate = pgNewWidget(PG_WIDGET_CHECKBOX,0,0);
  pgSetWidget(PGDEFAULT,PG_WP_TEXT,pgNewString("Rotation"),0);
   
  /* Fill in the boxes */
   
  wXres = pgNewWidget(PG_WIDGET_FIELD,PG_DERIVE_INSIDE,wXres);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_SIZE,50,
	      PG_WP_SIZEMODE,PG_SZMODE_PERCENT,
	      0);
  pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_TEXT,pgNewString("Width:"),
	      0);
   
  wYres = pgNewWidget(PG_WIDGET_FIELD,PG_DERIVE_INSIDE,wYres);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_SIZE,50,
	      PG_WP_SIZEMODE,PG_SZMODE_PERCENT,
	      0);
  pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_TEXT,pgNewString("Height:"),
	      0);
   
  wBpp = pgNewWidget(PG_WIDGET_FIELD,PG_DERIVE_INSIDE,wBpp);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_SIZE,50,
	      PG_WP_SIZEMODE,PG_SZMODE_PERCENT,
	      0);
  pgNewWidget(PG_WIDGET_LABEL,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_TEXT,pgNewString("BPP:"),
	      0);
   
  /******** Run a tiny event loop */
   
  /* Big loop setting modes... */
  for (;;) {
      
    /* Get actual mode info, put it in the widgets.
     * Not the best way, but for now pgReplaceTextFmt doesn't work on
     * field widgets because their handle handling is different :)
     * The field copies our string to an internal buffer so we don't need
     * to keep the handle around. Note that a server bug (listed in my
     * todo file) will cause a server segfault if pgReplaceText is used!
     */
    mi = *pgGetVideoMode();
      
    sprintf(buf,"%d",mi.xres);
    sTmp = pgNewString(buf);
    pgSetWidget(wXres,PG_WP_TEXT,sTmp,0);
    pgDelete(sTmp);

    sprintf(buf,"%d",mi.yres);
    sTmp = pgNewString(buf);
    pgSetWidget(wYres,PG_WP_TEXT,sTmp,0);
    pgDelete(sTmp);

    sprintf(buf,"%d",mi.bpp);
    sTmp = pgNewString(buf);
    pgSetWidget(wBpp,PG_WP_TEXT,sTmp,0);
    pgDelete(sTmp);

    pgSetWidget(wRotate,PG_WP_ON,mi.flags & PG_VID_ROTATE90,0);
      
    /* Small event loop waiting for an apply */
    for (;;) {
      evt = pgGetEvent();
	 
      /* Done yet? */
      if (evt->from == wClose)
	return 0;
	 
      /* Any PG_WE_ACTIVATE causes apply, this covers clicking the apply
       * button or pressing enter in a field. Specifically exclude
       * clicking the rotate checkbox */
      if (evt->type == PG_WE_ACTIVATE && evt->from != wRotate) 
	break;
    }
      
    /* Set mode based on widget values */
    pgSetVideoMode(atoi(pgGetString(pgGetWidget(wXres,PG_WP_TEXT))),
		   atoi(pgGetString(pgGetWidget(wYres,PG_WP_TEXT))),
		   atoi(pgGetString(pgGetWidget(wBpp,PG_WP_TEXT))),
		   pgGetWidget(wRotate,PG_WP_ON) ? PG_FM_ON : PG_FM_OFF,
		   PG_VID_ROTATE90);
  }
   
  return 0;
}
Exemplo n.º 22
0
/* Options Dialog */
int btnDialog(struct pgEvent *btnevt) {
  struct pgEvent evt;
  pghandle wSampleTB,wOk,wCancel,wSetFont,wOptionBox,wTB;
  pghandle w24hour,wSeconds,wColon,wWeekDay,wDay,wMonth,wYear;
  struct clockData oldData;

  /* Save data in case of cancel */
  oldData = currentClock;

  /* Top-level widgets */

  pgEnterContext();
  pgDialogBox("Clock Preferences");

  wTB = pgNewWidget(PG_WIDGET_TOOLBAR,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      0);

  wSampleTB = pgNewWidget(PG_WIDGET_TOOLBAR,0,0);

  wOptionBox = pgNewWidget(PG_WIDGET_BOX,0,0);

  pgNewWidget(PG_WIDGET_SCROLL,PG_DERIVE_BEFORE,wOptionBox);
  pgSetWidget(PGDEFAULT,
	      PG_WP_BIND,wOptionBox,
	      0);

  /* Options */

  w24hour = pgNewWidget(PG_WIDGET_CHECKBOX,PG_DERIVE_INSIDE,wOptionBox);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("24-hour clock"),
	      PG_WP_ON,currentClock.enable24hour,
	      0);
  wSeconds = pgNewWidget(PG_WIDGET_CHECKBOX,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Show seconds"),
	      PG_WP_ON,currentClock.enableSeconds,
	      0);
  wColon = pgNewWidget(PG_WIDGET_CHECKBOX,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Flash colon"),
	      PG_WP_ON,currentClock.flashColon,
	      0);
  wSetFont = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Set Font"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  wWeekDay = pgNewWidget(PG_WIDGET_CHECKBOX,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Show weekday"),
	      PG_WP_ON,currentClock.enableWeekDay,
	      0);
  wDay = pgNewWidget(PG_WIDGET_CHECKBOX,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Show day"),
	      PG_WP_ON,currentClock.enableDay,
	      0);
  wMonth = pgNewWidget(PG_WIDGET_CHECKBOX,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Show month"),
	      PG_WP_ON,currentClock.enableMonth,
	      0);
  wYear = pgNewWidget(PG_WIDGET_CHECKBOX,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Show year"),
	      PG_WP_ON,currentClock.enableYear,
	      /* Give the last one PG_S_ALL to avoid extra margin at the
	       * bottom of wCheckBoxBox
	       */
	      PG_WP_SIDE,PG_S_ALL,
	      0);

  /* Buttons */

  wCancel = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wTB);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgGetServerRes(PGRES_STRING_CANCEL),
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_HOTKEY,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_HOTKEY_CANCEL),
	      PG_WP_BITMAP,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_ICON_CANCEL),
	      PG_WP_BITMASK,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					  PGTH_P_ICON_CANCEL_MASK),
	      0);
  wOk = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wTB);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgGetServerRes(PGRES_STRING_OK),
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_HOTKEY,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_HOTKEY_OK),
	      PG_WP_BITMAP,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_ICON_OK),
	      PG_WP_BITMASK,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					  PGTH_P_ICON_OK_MASK),
	      0);

  /* Sample clock */

  currentClock.wClock = pgNewWidget(PG_WIDGET_FLATBUTTON,PG_DERIVE_INSIDE,
				    wSampleTB);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_ALL,
	      0);

  /* Run the dialog */
  for (;;) {
    mungeSettings();                /* New settings take effect */
    evt = *pgGetEvent();            /* Wait for an event */

    /* Set Font */
    if (evt.from == wSetFont) {
      pghandle fNew, fOld;
      fNew = pgFontPicker("Set Clock Font");
      if (fNew) {
	fOld = currentClock.fClockFont;
	/* Send new font handle to the main context */
	pgChangeContext(fNew,-1);
	/* Select new one, delete old one
	 * (unless this was the original font we entered with.
	 * Then, keep it around because we might cancel this dialog) */
	currentClock.fClockFont = fNew;
	if (fOld != oldData.fClockFont)
	  pgDelete(fOld);
      }
    }

    /* Cancel - revert everything */
    else if (evt.from == wCancel) {
      currentClock = oldData;
      break;
    }

    /* Done. Revert widget, delete old font */
    else if (evt.from == wOk) {
      if (oldData.fClockFont != currentClock.fClockFont)
	pgDelete(oldData.fClockFont);
      currentClock.wClock = oldData.wClock;
      break;
    }

    /* Set various flags */
    else if (evt.from == wColon)
      currentClock.flashColon ^= 1;
    else if (evt.from == w24hour)
      currentClock.enable24hour ^= 1;
    else if (evt.from == wSeconds)
      currentClock.enableSeconds ^= 1;
    else if (evt.from == wWeekDay)
      currentClock.enableWeekDay ^= 1;
    else if (evt.from == wDay)
      currentClock.enableDay ^= 1;
    else if (evt.from == wMonth)
      currentClock.enableMonth ^= 1;
    else if (evt.from == wYear)
      currentClock.enableYear ^= 1;
  }
  storeSettings();
  pgLeaveContext();
  mungeSettings();
  return 0;
}
Exemplo n.º 23
0
int main(int argc, char **argv) {
  pghandle wBox, wItem, sFoo;
  int i;

  /* Application
   */
  pgInit(argc,argv);
  pgRegisterApp(PG_APP_NORMAL,"List Test App",0);

  /* Scrolling box
   */
  wBox = pgNewWidget(PG_WIDGET_BOX,0,0);
  pgNewWidget(PG_WIDGET_SCROLL, PG_DERIVE_BEFORE, wBox);
  pgSetWidget(PGDEFAULT,
	      PG_WP_BIND, wBox,
	      0);

  /* Add some normal listitems (just text)
   * The listitem widget is hilighted when the cursor is over them,
   * and turned on when clicked. They are mutually exclusive.
   */
  for (i=0;i<5;i++) {
    wItem = pgNewWidget(PG_WIDGET_LISTITEM,
			i ? PGDEFAULT : PG_DERIVE_INSIDE,
			i ? PGDEFAULT : wBox);
    pgReplaceTextFmt(PGDEFAULT,"Normal listitem #%d",i);
  }

  /* Normally you'd want to use listitems, but just to show the
   * difference we'll throw in some menuitems...
   */
  for (i=0;i<5;i++) {
    wItem = pgNewWidget(PG_WIDGET_MENUITEM,0,0);
    pgReplaceTextFmt(PGDEFAULT,"Normal menuitem #%d",i);
  }

  /* Instead of using the PG_WP_TEXT property, create some
   * other widgets inside the listitem. They will be hilighted
   * with their PG_WP_HILIGHTED property when the mouse is over them.
   */
  sFoo = pgNewString("Foo");
  for (i=0;i<5;i++) {
    wItem = pgNewWidget(PG_WIDGET_LISTITEM,PG_DERIVE_AFTER,wItem);

    pgNewWidget(PG_WIDGET_CHECKBOX, PG_DERIVE_INSIDE, wItem);
    pgSetWidget(PGDEFAULT,
		PG_WP_TEXT, sFoo,
		PG_WP_SIDE, PG_S_LEFT,
		PG_WP_SIZEMODE, PG_SZMODE_PERCENT,
		PG_WP_SIZE, 20,
		0);

    pgNewWidget(PG_WIDGET_LABEL, 0,0);
    pgSetWidget(PGDEFAULT,
		PG_WP_SIDE, PG_S_LEFT,
		0);
    pgReplaceTextFmt(PGDEFAULT,"Container listitem #%d",i);
  }

  /* For contrast, repeat the same example with menuitems
   */
  for (i=0;i<5;i++) {
    wItem = pgNewWidget(PG_WIDGET_MENUITEM,PG_DERIVE_AFTER,wItem);

    pgNewWidget(PG_WIDGET_CHECKBOX, PG_DERIVE_INSIDE, wItem);
    pgSetWidget(PGDEFAULT,
		PG_WP_TEXT, sFoo,
		PG_WP_SIDE, PG_S_LEFT,
		PG_WP_SIZEMODE, PG_SZMODE_PERCENT,
		PG_WP_SIZE, 20,
		0);

    pgNewWidget(PG_WIDGET_LABEL, 0,0);
    pgSetWidget(PGDEFAULT,
		PG_WP_SIDE, PG_S_LEFT,
		0);
    pgReplaceTextFmt(PGDEFAULT,"Container menuitem #%d",i);
  }
  
  /* Just for testing the pgTraverseWidget method of finding
   * an item by its index:
   * (Normally if you wanted to print out all the items in a container
   * you should iterate with PG_TRAVERSE_FORWARD)
   */
  for (i=0;;i++) {
    pghandle w,t;
    char *text = "(no text)";

    w = pgTraverseWidget(wBox, PG_TRAVERSE_CHILDREN, i);
    if (!w)
      break;

    /* Get the widget's text if it has any */
    t = pgGetWidget(w, PG_WP_TEXT);
    if (t)
      text = pgGetString(t);

    printf("Child #%d : %s\n",i, text);
  }
  
  /* Add an event handler to catch all hilighting events
   */
  pgBind(PGBIND_ANY, PGBIND_ANY, evtHilight, NULL);  
  pgEventLoop();
  return 0;
}
Exemplo n.º 24
0
/* Like a messge dialog, with an input field */
pghandle pgInputDialog(const char *title, const char *message,
		       pghandle deftxt) {
  pghandle wToolbar,wField,wOk,wCancel,from;
  pghandle str = 0;

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

  /* Create the important widgets */
  pgDialogBox(title);
  wToolbar = pgNewWidget(PG_WIDGET_TOOLBAR,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      0);
  wField = 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(message),
	      0);
  wField = pgNewWidget(PG_WIDGET_FIELD,PG_DERIVE_INSIDE,wField);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE,PG_S_BOTTOM,
	      PG_WP_SIDE,PG_S_ALL,
	      /* Only set the property if nonzero */
	      deftxt ? PG_WP_TEXT : 0,deftxt,
	      0);

  /* buttons */
  wCancel = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wToolbar);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgGetServerRes(PGRES_STRING_CANCEL),
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_HOTKEY,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_HOTKEY_CANCEL),
	      PG_WP_IMAGE,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_ICON_CANCEL),
	      PG_WP_BITMASK,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					  PGTH_P_ICON_CANCEL_MASK),
	      0);
  wOk = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wToolbar);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgGetServerRes(PGRES_STRING_OK),
	      PG_WP_SIDE,PG_S_RIGHT,
	      PG_WP_HOTKEY,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_HOTKEY_OK),
	      PG_WP_IMAGE,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					 PGTH_P_ICON_OK),
	      PG_WP_BITMASK,pgThemeLookup(PGTH_O_POPUP_MESSAGEDLG,
					  PGTH_P_ICON_OK_MASK),
	      0);

  /* Run */
  pgFocus(wField);
  for (;;) {
    from = pgGetEvent()->from;
    if (from == wOk) {
      /* Make a copy, because the one used in PG_WP_TEXT is deleted
       * automatically by the field widget on deletion. 
       */
      str = pgDup(pgGetWidget(wField,PG_WP_TEXT));
      /* Send it back up to the caller's context */
      pgChangeContext(str,-1);
      break;
    }
    else if (from == wCancel)
      break;
  }
  pgLeaveContext();
  return str;
}
Exemplo n.º 25
0
int
main(int argc, char** argv)
{
  pgcolor color;
  struct pgmodeinfo mi;
  int i;
  pghandle ttl_box;

  /* init PicoGUI client */
  pgInit(argc,argv);
  pgRegisterApp(PG_APP_NORMAL, argv[0], 0);

  /* create the title */
  ttl_box = pgNewWidget(PG_WIDGET_BOX,0,0);

  ttl_text = pgNewWidget(PG_WIDGET_LABEL, PG_DERIVE_INSIDE, ttl_box);
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString("wclock"),
	       0);

  pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, ttl_box);
  pgSetWidget (PGDEFAULT,
               PG_WP_SIDE, PG_S_RIGHT,
 	       PG_WP_TEXT, pgNewString("?"),
               PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN,
               0);
  pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &btn_handler, (void*)btnid_set);

  pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, ttl_box);
  pgSetWidget (PGDEFAULT,
               PG_WP_SIDE, PG_S_LEFT,
 	       PG_WP_TEXT, pgNewString(">"),
               PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN,
               0);
  pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &btn_handler, (void*)btnid_right);

  pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, ttl_box);
  pgSetWidget (PGDEFAULT,
               PG_WP_SIDE, PG_S_LEFT,
 	       PG_WP_TEXT, pgNewString("<"),
               PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN,
               0);
  pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &btn_handler, (void*)btnid_left);

  /* create the main context */
  main_window = pgNewWidget(PG_WIDGET_CANVAS, PG_DERIVE_AFTER, ttl_box);
  pgBind(PGDEFAULT, PGBIND_ANY, &canvas_handler, NULL);

  /* init time zones */
  init_zones();

  /* activate mouse move, keyboard and focus events */
  pgSetWidget(main_window,
	      PG_WP_TRIGGERMASK, pgGetWidget(main_window, PG_WP_TRIGGERMASK) |
	      PG_TRIGGER_MOVE |
	      PG_TRIGGER_CHAR |
	      PG_TRIGGER_KEYDOWN |
	      PG_TRIGGER_KEYUP /* |
	      PG_TRIGGER_ACTIVATE |
	      PG_TRIGGER_DEACTIVATE */,
	      0);

  mi = *pgGetVideoMode();
  width = mi.lxres;
  height = mi.lyres;

  /* Make a backbuffer bitmap */
  world_bitmap = create_world_bitmap();
  width = get_world_width();
  height = get_world_height();

  /* Set the clipping rectangle */
  pgWriteCmd(main_window,
	     PGCANVAS_GROP, 5,
	     PG_GROP_SETCLIP, 0, 0, width, height + TIMEBAR_HEIGHT);
  
  /* Set to be always rendered */
  pgWriteCmd(main_window,
	     PGCANVAS_GROPFLAGS, 1,
	     PG_GROPF_UNIVERSAL);
  
  /* Create contexts for the canvas itself and the back-buffer */
  gfx_context = pgNewCanvasContext(main_window, PGFX_IMMEDIATE );

  /* run all */
  DPRINTF(">>> entering loop\n");
  pgEventLoop();

  return 0;
}
Exemplo n.º 26
0
/* int main(int argc,char **argv) { */
int dialogdemo(pghandle widget)
{
  
/*   pgInit(argc,argv); */
/*   pgRegisterApp(PG_APP_NORMAL,"Standard Dialogs",0); */

  /* Scrollable box */
/*   wBox = pgNewWidget(PG_WIDGET_SCROLLBOX, PG_DERIVE_INSIDE, widget); */

  /* Message Dialog */
/*   pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wBox); */
  pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE, widget);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Quote"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnQuote,NULL);
  pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Confirm dialog"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnConfirm,NULL);

  /* Custom dialog box */
  pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Display something"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnTarget,NULL);

  /* Date picker */
  wDate = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Select a date"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnDate,NULL);

  /* Text input */
  wInputBtn = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Input a string"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnInput,NULL);

  /* Font picker */
  wFontBtn = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Font selection"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnFont,NULL);

  /* File open */
  wFileOpenBtn = pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Open a file"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnFileOpen,NULL);

  /* File save */
/*   wFileSaveBtn = pgNewWidget(PG_WIDGET_BUTTON,0,0); */
/*   pgSetWidget(PGDEFAULT, */
/* 	      PG_WP_TEXT,pgNewString("pgFilePicker: Save a file"), */
/* 	      PG_WP_SIDE,PG_S_TOP, */
/* 	      0); */
/*   pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnFileSave,NULL); */

  /* Color Picker */
  pgNewWidget(PG_WIDGET_BUTTON,0,0);
  pgSetWidget(PGDEFAULT,
	      PG_WP_TEXT,pgNewString("Select a Color"),
	      PG_WP_SIDE,PG_S_TOP,
	      0);
  pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnColor,NULL);

  /* Bomb */
/*   pgNewWidget(PG_WIDGET_BUTTON,0,0); */
/*   pgSetWidget(PGDEFAULT, */
/* 	      PG_WP_TEXT,pgNewString("Bomb: Cause error dialog"), */
/* 	      PG_WP_SIDE,PG_S_TOP, */
/* 	      0); */
/*   pgBind(PGDEFAULT,PG_WE_ACTIVATE,&btnBomb,NULL); */

/*   pgEventLoop(); */
  return 0;
}
Exemplo n.º 27
0
int main(int argc, char **argv) {
    pghandle vbox, vbox2, wToolbar;

    pgInit(argc,argv);
    pgRegisterApp(PG_APP_NORMAL,"Textedit Demo",0);
    
    /* A toolbar for the buttons */
    wToolbar = pgNewWidget (PG_WIDGET_TOOLBAR, 0, 0);

    /* share the screen for two textedit widgets */
    vbox = pgNewWidget (PG_WIDGET_BOX, 0, 0);
    pgSetWidget (PGDEFAULT,
		 PG_WP_SIDE, PG_S_LEFT,
		 PG_WP_SIZE, pgFraction (1, 2),
		 PG_WP_SIZEMODE, PG_SZMODE_CNTFRACT,
		 0);

    vbox2 = pgNewWidget (PG_WIDGET_BOX, 0, 0);
    pgSetWidget (PGDEFAULT,
		 PG_WP_SIDE, PG_S_ALL,
		 0);

    /* first edit box */
    edit = pgNewWidget (PG_WIDGET_TEXTEDIT, PG_DERIVE_INSIDE, vbox); 
    pgSetWidget (edit,
		 PG_WP_FONT, pgNewFont (NULL, 12, PG_FSTYLE_BOLD),
		 PG_WP_TEXT, pgNewString ("Howdy!"),
		 PG_WP_SELECTION, pgNewString ("Hey!"),
		 0);

    /* second edit box */
    edit = pgNewWidget(PG_WIDGET_TEXTEDIT, PG_DERIVE_INSIDE, vbox2); 
    pgSetWidget (edit,
		 PG_WP_FONT, pgNewFont (NULL, 24, PG_FSTYLE_BOLD),
		 PG_WP_TEXT, pgNewString ("Howdy!"),
		 PG_WP_SELECTION, pgNewString ("Hey!"),
		 0);

    /* buttons in the toolbar */    
    wPaste = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wToolbar);
    pgSetWidget(PGDEFAULT,
                PG_WP_SIZE,pgFraction(1,3),
                PG_WP_SIZEMODE,PG_SZMODE_CNTFRACT,
                PG_WP_TEXT,pgNewString("Paste"),
                0);
    pgBind(PGDEFAULT,PG_WE_ACTIVATE,&evtBtn,NULL);

    wCopy = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wToolbar);
    pgSetWidget(PGDEFAULT,
                PG_WP_SIZE,pgFraction(1,3),
                PG_WP_SIZEMODE,PG_SZMODE_CNTFRACT,
                PG_WP_TEXT,pgNewString("Copy"),
                0);
    pgBind(PGDEFAULT,PG_WE_ACTIVATE,&evtBtn,NULL);

    wCut = pgNewWidget(PG_WIDGET_BUTTON,PG_DERIVE_INSIDE,wToolbar);
    pgSetWidget(PGDEFAULT,
                PG_WP_SIZE,pgFraction(1,3),
                PG_WP_SIZEMODE,PG_SZMODE_CNTFRACT,
                PG_WP_TEXT,pgNewString("Cut"),
                0);
    pgBind(PGDEFAULT,PG_WE_ACTIVATE,&evtBtn,NULL);
    
    pgSetWidget(edit,
		PG_WP_SELECTION, pgNewString("Two!"),
		0);

    pgEventLoop();

    return 0;
}
Exemplo n.º 28
0
/* widget: the parent widget to derive inside
 * directory: the directory into which search for themes */
void themebar(pghandle widget, char* directory, int* themecontext)
{
  struct dirent *dent;
  int i,l;
  DIR *d;
  char buf[80];
  pghandle box;

  THEME_DIRECTORY=directory;
  if (! (d = opendir(THEME_DIRECTORY))) {
      eerror("directory not found");
      exit(1);
  }

  /* simple & dirty */
/*   pageContext = pagecontext; */
/*   themeContext = themecontext; */

  box = pgNewWidget(PG_WIDGET_SCROLLBOX, PG_DERIVE_AFTER, widget);
  pgSetWidget(PGDEFAULT,
	      PG_WP_SIDE, PG_S_ALL,
/*  	      PG_WP_TRANSPARENT, 1, */
	      0);

  /* Make handles */
  rewinddir(d);
  i = 0;
  while ((dent = readdir(d))) {
    l = strlen(dent->d_name);
    if (l<4) continue;
    if (strcmp(dent->d_name+l-3,".th")) continue;

    buf[0] = 0;
/*     dent->d_name[l-3] = 0; */

    if (idx == LENGHT) {
	eerror("max array lenght reached in themebar.c: too many themes.");
	break;
    }

    array[idx].dir = pgNewString(directory);
    array[idx].fname = pgNewString(dent->d_name);
    array[idx].active = 0;

    /* Add item */
    pgNewWidget(PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, box);
    pgSetWidget(PGDEFAULT,
/* 		PG_WP_EXTDEVENTS, pgGetWidget(PGDEFAULT, PG_WP_EXTDEVENTS) & ~PG_EXEV_EXCLUSIVE, */
/* 		PG_WP_EXTDEVENTS, PG_EXEV_TOGGLE, */
		PG_WP_TEXT, array[idx].fname,
		PG_WP_SIDE, PG_S_BOTTOM,
		0);

    pgSetPayload(PGDEFAULT, idx);
    idx++;

    pgBind(PGDEFAULT,PG_WE_ACTIVATE,evtChangeTheme, themecontext);
  }
  closedir(d);

  pgSubUpdate(widget);
  return;
}
Exemplo n.º 29
0
/*
 * main
 */
int main (int argc, char * argv [])
{
  /* Constants to facilitate passing commands through pgBind() */
  struct keyboard_command cmd_show           = {htons (PG_KEYBOARD_SHOW)};
  struct keyboard_command cmd_hide           = {htons (PG_KEYBOARD_HIDE)};
  struct keyboard_command cmd_toggle         = {htons (PG_KEYBOARD_TOGGLE)};
  struct keyboard_command cmd_enable         = {htons (PG_KEYBOARD_ENABLE)};
  struct keyboard_command cmd_disable        = {htons (PG_KEYBOARD_DISABLE)};
  struct keyboard_command cmd_toggle_display = {htons (PG_KEYBOARD_TOGGLE_DISPLAY)};
  struct keyboard_command cmd_select_pattern = {htons (PG_KEYBOARD_SELECT_PATTERN), htons (PG_KBPATTERN_NUMERIC)};
  struct keyboard_command cmd_push_context   = {htons (PG_KEYBOARD_PUSH_CONTEXT)};
  struct keyboard_command cmd_pop_context    = {htons (PG_KEYBOARD_POP_CONTEXT)};
  struct keyboard_command cmd_block          = {htons (PG_KEYBOARD_BLOCK)};
  struct keyboard_command cmd_release        = {htons (PG_KEYBOARD_RELEASE)};

  /* Handle for GUI placement */
  pghandle lastBox;

  /* Handle for font object */
  pghandle font;

  /* Init and register the app */
  pgInit (argc, argv);
  pgRegisterApp (PG_APP_NORMAL, "Virtual Keyboard Commands", 0);

  font = pgNewFont ("Helvetica", 8, 0);

  /* Create all the widgets */
  lastBox = pgNewWidget (PG_WIDGET_BOX, 0, 0);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("SHOW"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_show);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_AFTER, PGDEFAULT);
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("HIDE"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_hide);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_AFTER, PGDEFAULT);
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("TOGGLE"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_toggle);

  lastBox = pgNewWidget (PG_WIDGET_BOX, PG_DERIVE_AFTER, lastBox);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("ENABLE"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_enable);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_AFTER, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("DISABLE"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_disable);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_AFTER, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("TOGGLE_ENABLE"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_toggle_display);

  lastBox = pgNewWidget (PG_WIDGET_BOX, PG_DERIVE_AFTER, lastBox);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("SELECT_PATTERN NUMERIC"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_select_pattern);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_AFTER, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("PUSH_CONTEXT"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_push_context);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_AFTER, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("POP_CONTEXT"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_pop_context);

  lastBox = pgNewWidget (PG_WIDGET_BOX, PG_DERIVE_AFTER, lastBox);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("BLOCK"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_block);

  pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_AFTER, PGDEFAULT);	
  pgSetWidget (PGDEFAULT,
	       PG_WP_TEXT, pgNewString ("RELEASE"),
	       PG_WP_SIDE, PG_S_LEFT,
	       PG_WP_FONT, font,
	       0);
  pgBind (PGDEFAULT, PG_WE_ACTIVATE, &handleButton, &cmd_release);

  font = pgNewFont ("Helvetica", 12, 0);

  pgNewWidget (PG_WIDGET_FIELD, PG_DERIVE_AFTER, lastBox);
  pgSetWidget (PGDEFAULT,
	       PG_WP_SIZE, 16,
	       PG_WP_FONT, font,
	       0);

  /* Wait for events */
  pgEventLoop ();

  return 0;
}
Exemplo n.º 30
0
int main(int argc,char **argv) {
  /* File data */
  unsigned char * file_data;

#ifdef POCKETBEE

  /* Register the handler for SIGTERM */
  signal (SIGTERM, sig_handler);
  /* Register exit function */
  atexit (proper_exit);

#endif /* POCKETBEE */

  /* Make a 'toolbar' app */
  pgInit(argc,argv);
  wApp = pgRegisterApp(PG_APP_TOOLBAR,"Keyboard",0);

  wCanvas = pgNewWidget(PG_WIDGET_CANVAS, PG_DERIVE_INSIDE, wApp);
  pgSetWidget (PGDEFAULT,
	       PG_WP_SIDE, PG_S_ALL,
	       0);
  wDisabled = pgNewWidget (PG_WIDGET_CANVAS, PG_DERIVE_AFTER, wCanvas);
  pgSetWidget (PGDEFAULT,
	       PG_WP_SIDE, PG_S_ALL,
	       0);
  drawDisabledKeyboard ();

  if (!argv[1] || argv[2]) {
    printf("usage:\n  %s <keyboard file>\n",argv[0]);
    return 1;
  }

  /* Load patterns */
  fpat = fopen(argv[1],"r");
  if (!fpat) {
    pgMessageDialog(*argv,"Error loading keyboard file",0);
    return 1;
  }
  file_data = kb_validate (fpat, &mpat);
  fclose (fpat);
  if (file_data == NULL) {
    pgMessageDialog(*argv,"Invalid keyboard file [kb_validate()]",0);
    return 1;
  }
  if (kb_loadpatterns(file_data)) {
    free (file_data);
    pgMessageDialog(*argv,"Invalid keyboard file [kb_loadpatterns()]",0);
    return 1;
  }
  free (file_data);

  /* Resize app widget */
  pgSetWidget(wApp,
              PG_WP_NAME,pgNewString(PG_KEYBOARD_APPNAME),
	      PG_WP_SIDE,mpat->app_side,
#ifdef POCKETBEE
	      /* Start the keyboard hidden */
	      PG_WP_SIZE,0,
#else /* POCKETBEE */
	      PG_WP_SIZE,mpat->app_size,
#endif /* POCKETBEE */
	      PG_WP_SIZEMODE,mpat->app_sizemode,
	      PG_WP_TRANSPARENT,1,
	      0);

#ifdef POCKETBEE

#  ifdef USE_PM

  DPRINTF ("about to tell PM we are ready\n");
  
  /* Signal the PM of a proper start */
  if (pm_ready () == -1) {
    DPRINTF ("cannot signal PM (error during pm_ready)\n");
  }

#  endif /* USE_PM */

  /* Find the public box in the finder */
  {
    pghandle box;
    int i = 0;

    while ( !(box = pgFindWidget ("FinderKbdBox")) && i < 5 )
      {
	DPRINTF ("Finder public box not found, waiting ...\n");
	sleep (1);
	i++;
      }

    if (box)
      {
	/* Create a button in this box */
	pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, box);
	pgSetWidget (PGDEFAULT,
		     PG_WP_TEXT, pgNewString ("Kbd"),
		     0);

	/* Attach a handler to it */
	pgBind (PGDEFAULT, PG_WE_ACTIVATE, &kbd_btn_handler, NULL);
      }
  }

#endif /* POCKETBEE */

  initKbdCanvas ();

  /* Set up an event handler for the received messages */
  pgBind (wApp, PG_WE_APPMSG, &evtMessage, NULL);

  pgEventLoop();
  return 0;
}