/*
 * This demonstrates the Cdk preprocess feature.
 */
int main (void)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKENTRY *widget     = 0;
   const char *title    = "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!";
   char *info;
   const char *mesg[10];
   char temp[256];

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK colors. */
   initCDKColor ();

   /* Create the entry field widget. */
   widget = newCDKEntry (cdkscreen, CENTER, CENTER,
			 title, 0, A_NORMAL, '.', vMIXED,
			 40, 0, 256, TRUE, FALSE);

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create the entry box. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   setCDKEntryPreProcess (widget, entryPreProcessCB, 0);

   /* Activate the entry field. */
   info = activateCDKEntry (widget, 0);

   /* Tell them what they typed. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information passed back.";
      mesg[1] = "",
	 mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      mesg[0] = "<C>You typed in the following";
      sprintf (temp, "<C>(%.*s)", (int)(sizeof (temp) - 20), info);
      mesg[1] = temp;
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 4);
   }

   /* Clean up and exit. */
   destroyCDKEntry (widget);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #2
0
int run_modules(CDKSCREEN *screen, mainwin_t *mainwin)
{
	int i;
	char *mesg[2];
	char temp[32];

	for (i = 0; i < mainwin->nmodules; i++) {
		module_t *module = mainwin->modules[i];

		if (strcmp(module->id, "hardware") == 0) {
			snprintf(temp, 32, "<C>Running %s Test ...", module->name);
			mesg[0] = temp;
			mesg[1] = "<C>Hit any key to continue.";
			popupLabel(screen, mesg, 2);

			send_msg(module->name, "AUTORUN");
			module->handler(screen->window, mainwin);
		}
	}

	mesg[0] = "<C>Auto Test Completed.";
	mesg[1] = "<C>Hit any key to continue.";
	popupLabel(screen, mesg, 2);

	return 0;
}
Exemple #3
0
void display_msg(char *txt)
{
    char **msg = CDKsplitString(txt, '\n');
    
    popupLabel (cdkscreen, msg, CDKcountStrings(msg)); 
    CDKfreeStrings(msg);
}
Exemple #4
0
void mostrar_scroll(CDKSCREEN *cdkScreen)
{
    char *lista[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
//    char** items[2];
 //   items[0]="asdf";
  //  items[1]="edfsdaf";
    char *titulo="dios";
    char salir;
    int elegido;
/*
  	CDKSCREEN *	 cdkscreen ,
		int		 xpos ,
		int		 ypos ,
		int		 spos ,
		int		 height ,
		int		 width ,
		char *		 title ,
		char **		 itemList ,
		int		 items ,
		boolean		 numbers ,
		chtype		 highlight ,
		boolean		 Box ,
		boolean		 shadow );
*/
    CDKSCROLL *menucito;
do
    {
    menucito=newCDKScroll(cdkScreen,
                        CENTER,
                         CENTER,
                        RIGHT,
                        10,
                        15,
                        titulo,
                        lista,
                        7,
                        FALSE,
                        A_REVERSE,
                        TRUE,
                        FALSE);
    elegido=activateCDKScroll(menucito,0);
 // destroyCDKScroll (menucito);





    popupLabel(cdkScreen,&lista[elegido],1);

  //  hacer(elegido);
   // break;


} while((salir=(getch())!='q'));
     destroyCDKScroll (menucito);
 //    mostrar_info(cdkScreen);
   // hacer(elegido);
     endCDK();
}
Exemple #5
0
void
hexDump(unsigned char* buf, int dlen)
{
	char	c[17];
	int	i, ct;
	
	char** string;
	char bufz[BUFSIZ] = { 0 };
	char* buf2;

	for (i = 0; i < dlen; ++i)
	{
		if(i != 0 && (i % 2) == 0)
			bufz[strlen(bufz)] = ' ';

		if (i != 0 && (i % 16) == 0)
		{
			c[16] = '\0';

			strcat(bufz, "  " );
			strcat(bufz, c );
			bufz[strlen(bufz)] = '\n';
		}

		ct = buf[i] & 0xff;

		c[i % 16] = (ct >= ' ' && ct <= '~') ? ct : '.';

		sprintf( bufz, "%s%02x", bufz, ct );
	}

	c[i % 16] = '\0';

	for (; i % 16; ++i)
		strcat(bufz, "   " ); 

	bufz[strlen(bufz)] = '\t';
	strcat(bufz, c );
	bufz[strlen(bufz)] = '\n';

	for(i = 0, ct = 0;i < strlen(bufz);i++)
		if(bufz[i] == '\n')
			ct++;

	string = malloc( sizeof(char*) * ct );

	buf2 = strtok( bufz, "\n" );

	i = 0;

	string[i++] = strdup( buf2 );

	while((buf2 = strtok(NULL, "\n" )))
		string[i++] = strdup( buf2 );
	
	popupLabel( cdkscreen, string, ct );

	free( string );
}
Exemple #6
0
int autorun_handler(WINDOW *win, void *ptr)
{
	char *mesg[2];
	CDKSCREEN *screen;

	screen = initCDKScreen(win);

	mesg[0] = "<C>Auto Running Hardware Test ...";
	mesg[1] = "<C>Hit any key to continue.";
	popupLabel(screen, mesg, 2);

	run_modules(screen, ptr);

	destroyCDKScreen(screen);

	return 0;
}
Exemple #7
0
static int do_help (CB_PARAMS)
{
   static const char *message[] =
   {
      "File Selection tests:",
      "",
      "F1 = help (this message)",
      "F2 = delete current item",
      "F3 = delete previous item",
      "F4 = reload all items",
      "F5 = undo deletion",
      0
   };
   popupLabel (cdkscreen,
	       (CDK_CSTRING2)message,
	       (int)CDKcountStrings ((CDK_CSTRING2)message));
   return TRUE;
}
Exemple #8
0
/*
 * This program demonstrates the Cdk matrix widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKMATRIX *courseList = 0;
   WINDOW *cursesWin    = 0;
   const char *title    = 0;
   int rows             = 8;
   int cols             = 5;
   int vrows            = 3;
   int vcols            = 5;

   bool use_coltitles;
   bool use_rowtitles;

   const char *coltitle[MY_COLS];
   const char *rowtitle[MY_COLS];
   const char *mesg[MY_COLS];

   int colwidth[MY_COLS];
   int colvalue[MY_COLS];

   CDK_PARAMS params;

   CDKparseParams (argc, argv, &params, "trcT:" CDK_MIN_PARAMS);

   /* invert, so giving -S causes the shadow to turn off */
   params.Shadow = !params.Shadow;

   /* cancel the default title, or supply a new one */
   if (CDKparamValue (&params, 't', FALSE))
   {
      title = 0;
   }
   else if ((title = CDKparamString (&params, 'T')) == 0)
   {
      title = "<C>This is the CDK\n<C>matrix widget.\n<C><#LT><#HL(30)><#RT>";
   }

   /* allow cancelling of column and/or row titles with -c and/or -r */
   use_coltitles = !CDKparamValue (&params, 'c', FALSE);
   use_rowtitles = !CDKparamValue (&params, 'r', FALSE);

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor ();

   /* Create the horizontal and vertical matrix labels. */
#define set_col(n, width, string) \
   coltitle[n] = use_coltitles ? string : 0 ;\
   colwidth[n] = width ;\
   colvalue[n] = vUMIXED

   set_col (1, 7, "</B/5>Course");
   set_col (2, 7, "</B/33>Lec 1");
   set_col (3, 7, "</B/33>Lec 2");
   set_col (4, 7, "</B/33>Lec 3");
   set_col (5, 1, "</B/7>Flag");

#define set_row(n, string) \
   rowtitle[n] = use_rowtitles ? "<C></B/6>" string : 0

   set_row (1, "Course 1");
   set_row (2, "Course 2");
   set_row (3, "Course 3");
   set_row (4, "Course 4");
   set_row (5, "Course 5");
   set_row (6, "Course 6");
   set_row (7, "Course 7");
   set_row (8, "Course 8");

   /* Create the matrix object. */
   courseList = newCDKMatrix (cdkscreen,
			      CDKparamValue (&params, 'X', CENTER),
			      CDKparamValue (&params, 'Y', CENTER),
			      rows, cols, vrows, vcols,
			      title,
			      (CDK_CSTRING2) rowtitle,
			      (CDK_CSTRING2) coltitle,
			      colwidth, colvalue,
			      -1, -1, '.',
			      COL, params.Box,
			      params.Box,
			      params.Shadow);

   /* Check to see if the matrix is null. */
   if (courseList == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create the matrix widget.\n");
      printf ("Is the window too small ?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the matrix. */
   activateCDKMatrix (courseList, 0);

   /* Check if the user hit escape or not. */
   if (courseList->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information passed back.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (courseList->exitType == vNORMAL)
   {
      char temp[80];

      sprintf (temp, "Current cell (%d,%d)", courseList->crow, courseList->ccol);
      mesg[0] = "<L>You exited the matrix normally.";
      mesg[1] = temp;
      mesg[2] = "<L>To get the contents of the matrix cell, you can";
      mesg[3] = "<L>use getCDKMatrixCell():";
      mesg[4] = getCDKMatrixCell (courseList, courseList->crow, courseList->ccol);
      mesg[5] = "";
      mesg[6] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 7);
   }

   /* Clean up. */
   destroyCDKMatrix (courseList);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #9
0
/*
 * This program demonstrates the Cdk scale widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKSCALE *widget	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C>Select a value";
   char *label		= "</5>Current value";
   char temp[256], *mesg[5];
   int selection;

   CDK_PARAMS params;
   int high;
   int inc;
   int low;

   CDKparseParams(argc, argv, &params, "h:i:l:w:" CDK_MIN_PARAMS);
   high   = CDKparamNumber2(&params, 'h', 100);
   inc    = CDKparamNumber2(&params, 'i', 1);
   low    = CDKparamNumber2(&params, 'l', 0);

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor();

   /* Create the widget. */
   widget = newCDKScale (cdkscreen,
			CDKparamValue(&params, 'X', CENTER),
			CDKparamValue(&params, 'Y', CENTER),
			title, label,
			A_NORMAL,
			CDKparamNumber2(&params, 'w', 5),
			low, low, high,
			inc, (inc*2),
			CDKparamValue(&params, 'N', TRUE),
			CDKparamValue(&params, 'S', FALSE));

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message. */
      printf ("Oops. Can't make the widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the widget. */
   selection = activateCDKScale (widget, 0);

   /* Check the exit value of the widget. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No value selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected %d", selection);
      mesg[0] = copyChar (temp);
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
      freeChar (mesg[0]);
   }

   /* Clean up. */
   destroyCDKScale (widget);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #10
0
/*
 * Demonstrate a scrolling-window.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKSWINDOW *swindow	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C></5>Error Log";
   char *mesg[5];

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, CDK_CLI_PARAMS);

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK colors. */
   initCDKColor();

   /* Create the scrolling window. */
   swindow = newCDKSwindow (cdkscreen,
			   CDKparamValue(&params, 'X', CENTER),
			   CDKparamValue(&params, 'Y', CENTER),
			   CDKparamValue(&params, 'H', 6),
			   CDKparamValue(&params, 'W', 65),
			   title, 100,
			   CDKparamValue(&params, 'N', TRUE),
			   CDKparamValue(&params, 'S', FALSE));

   /* Is the window null. */
   if (swindow == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message and exit. */
      printf ("Oops. Can not seem to create the scrolling window. Is the window too small??\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Draw the scrolling window. */
   drawCDKSwindow (swindow, ObjOf(swindow)->box);

   /* Load up the scrolling window. */
   addCDKSwindow (swindow, "<C></11>TOP: This is the first line.", BOTTOM);
   addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM);
   sleep (1);

   addCDKSwindow (swindow, "<L></11>1: This is another line.", BOTTOM);
   addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM);
   sleep (1);

   addCDKSwindow (swindow, "<C></11>2: This is another line.", BOTTOM);
   addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM);
   sleep (1);

   addCDKSwindow (swindow, "<R></11>3: This is another line.", BOTTOM);
   addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM);
   sleep (1);

   addCDKSwindow (swindow, "<C></11>4: This is another line.", BOTTOM);
   addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM);
   sleep (1);

   addCDKSwindow (swindow, "<L></11>5: This is another line.", BOTTOM);
   addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM);
   sleep (1);

   addCDKSwindow (swindow, "<C></11>6: This is another line.", BOTTOM);
   addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM);
   sleep (1);

   addCDKSwindow (swindow, "<C>Done. You can now play.", BOTTOM);

   addCDKSwindow (swindow, "<C>This is being added to the top.", TOP);

   /* Activate the scrolling window. */
   activateCDKSwindow (swindow, 0);

   /* Check how the user exited this widget. */
   if (swindow->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape to leave this widget.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (swindow->exitType == vNORMAL)
   {
      mesg[0] = "<C>You hit return to exit this widget.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }

   /* Clean up. */
   destroyCDKSwindow (swindow);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #11
0
/*
 * This program demonstrates the file selector and the viewer widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen  = 0;
   CDKVIEWER *example    = 0;
   CDKFSELECT *fSelect   = 0;
   WINDOW *cursesWin     = 0;
   const char *title     = "<C>Pick a file.";
   const char *label     = "File: ";
   const char *directory = ".";
   char *filename        = 0;
   char **info           = 0;
   const char *button[5];
   const char *mesg[4];
   char vtitle[256];
   char temp[256];
   int selected, lines, ret;

   /* Parse up the command line. */
   while (1)
   {
      ret = getopt (argc, argv, "d:f:");
      if (ret == -1)
      {
	 break;
      }
      switch (ret)
      {
      case 'd':
	 directory = strdup (optarg);
	 break;

      case 'f':
	 filename = strdup (optarg);
	 break;
      }
   }

   /* Create the viewer buttons. */
   button[0] = "</5><OK><!5>";
   button[1] = "</5><Cancel><!5>";

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start color. */
   initCDKColor ();

   /* Get the filename. */
   if (filename == 0)
   {
      fSelect = newCDKFselect (cdkscreen, CENTER, CENTER, 20, 65,
			       title, label, A_NORMAL, '_', A_REVERSE,
			       "</5>", "</48>", "</N>", "</N>", TRUE, FALSE);

      /*
       * Set the starting directory. This is not neccessary because when
       * the file selector starts it uses the present directory as a default.
       */
      setCDKFselect (fSelect, directory, A_NORMAL, '.', A_REVERSE,
		     "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box);

      /* Activate the file selector. */
      filename = copyChar (activateCDKFselect (fSelect, 0));

      /* Check how the person exited from the widget. */
      if (fSelect->exitType == vESCAPE_HIT)
      {
	 /* Pop up a message for the user. */
	 mesg[0] = "<C>Escape hit. No file selected.";
	 mesg[1] = "";
	 mesg[2] = "<C>Press any key to continue.";
	 popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);

	 /* Destroy the file selector. */
	 destroyCDKFselect (fSelect);

	 /* Exit CDK. */
	 destroyCDKScreen (cdkscreen);
	 endCDK ();

	 ExitProgram (EXIT_SUCCESS);
      }
   }

   /* Destroy the file selector. */
   destroyCDKFselect (fSelect);

   /* Create the file viewer to view the file selected. */
   example = newCDKViewer (cdkscreen, CENTER, CENTER, 20, -2,
			   (CDK_CSTRING2) button, 2,
			   A_REVERSE, TRUE, FALSE);

   /* Could we create the viewer widget? */
   if (example == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      /* Print out a message and exit. */
      printf ("Cannot create viewer. Is the window too small?\n");
      ExitProgram (EXIT_SUCCESS);
   }

   /* Open the file and read the contents. */
   lines = CDKreadFile (filename, &info);
   if (lines == -1)
   {
      printf ("Could not open %s\n", filename);
      ExitProgram (EXIT_FAILURE);
   }

   /* Set up the viewer title, and the contents to the widget. */
   sprintf (vtitle, "<C></B/22>%20s<!22!B>", filename);
   setCDKViewer (example, vtitle,
		 (CDK_CSTRING2) info, lines,
		 A_REVERSE, TRUE, TRUE, TRUE);

   /* Activate the viewer widget. */
   selected = activateCDKViewer (example, 0);

   /* Check how the person exited from the widget. */
   if (example->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>Escape hit. No Button selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (example->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected button %d", selected);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }

   /* Clean up. */
   destroyCDKViewer (example);
   destroyCDKScreen (cdkscreen);
   CDKfreeStrings (info);
   freeChar (filename);

   endCDK ();

   ExitProgram (EXIT_SUCCESS);
}
/*
 * This program demonstrates the Cdk scale widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKFSCALE *scale     = 0;
   const char *title    = "<C>Select a value";
   const char *label    = "</5>Current value";
   char temp[256];
   const char *mesg[5];
   float selection;

   CDK_PARAMS params;
   float high;
   float inc;
   float low;

   /* *INDENT-EQLS* */
   CDKparseParams (argc, argv, &params, "h:i:l:w:" CDK_MIN_PARAMS);
   high   = myFloatParam (&params, 'h', 2.4);
   inc    = myFloatParam (&params, 'i', 0.2);
   low    = myFloatParam (&params, 'l', -1.2);

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK Colors. */
   initCDKColor ();

   /* Create the scale. */
   scale = newCDKFScale (cdkscreen,
			 CDKparamValue (&params, 'X', CENTER),
			 CDKparamValue (&params, 'Y', CENTER),
			 title, label, A_NORMAL,
			 CDKparamNumber2 (&params, 'w', 10),
			 low, low, high,
			 inc, (inc * (float)2.), 1,
			 CDKparamValue (&params, 'N', TRUE),
			 CDKparamValue (&params, 'S', FALSE));

   /* Is the scale null? */
   if (scale == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Can't make the scale widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the scale. */
   selection = activateCDKFScale (scale, 0);

   /* Check the exit value of the scale widget. */
   if (scale->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No value selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (scale->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected %f", selection);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }

   /* Clean up. */
   destroyCDKFScale (scale);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #13
0
/*
 * This demonstrates the Cdk preprocess feature.
 */
int main (void)
{
   /* Declare local variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKENTRY *widget	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!";
   char *info, *mesg[10], temp[256];

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK colors. */
   initCDKColor();

   /* Create the entry field widget. */
   widget = newCDKEntry (cdkscreen, CENTER, CENTER,
			 title, 0, A_NORMAL, '.', vMIXED,
			 40, 0, 256, TRUE, FALSE);

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a little message. */
      printf ("Oops. Can't seem to create the entry box. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   setCDKEntryPreProcess (widget, entryPreProcessCB, 0);

   /* Activate the entry field. */
   info = activateCDKEntry (widget, 0);

   /* Tell them what they typed. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information passed back.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      mesg[0] = "<C>You typed in the following";
      sprintf (temp, "<C>(%.*s)", (int)(sizeof(temp) - 20), info);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);
      freeChar (mesg[1]);
   }

   /* Clean up and exit. */
   destroyCDKEntry (widget);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #14
0
/*
 * This program demonstrates the Cdk radio widget.
 *
 * Options (in addition to normal CLI parameters):
 *	-c	create the data after the widget
 *	-s SPOS	location for the scrollbar
 *	-t TEXT	title for the widget
 *
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKRADIO *radio      = 0;
   WINDOW *cursesWin    = 0;
   const char *title    = "<C></5>Select a filename";
   char **item          = 0;
   const char *mesg[5];
   char temp[256];
   int selection, count;

   CDK_PARAMS params;

   CDKparseParams (argc, argv, &params, "cs:t:" CDK_CLI_PARAMS);

   /* Use the current diretory list to fill the radio list. */
   count = CDKgetDirectoryContents (".", &item);
   if (count <= 0)
   {
      fprintf (stderr, "Cannot get directory list\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Set up CDK Colors. */
   initCDKColor ();

   /* Create the radio list. */
   radio = newCDKRadio (cdkscreen,
			CDKparamValue (&params, 'X', CENTER),
			CDKparamValue (&params, 'Y', CENTER),
			CDKparsePosition (CDKparamString2 (&params,
							   's',
							   "RIGHT")),
			CDKparamValue (&params, 'H', 10),
			CDKparamValue (&params, 'W', 40),
			CDKparamString2 (&params, 't', title),
			CDKparamNumber (&params, 'c') ? 0 : (CDK_CSTRING2) item,
			CDKparamNumber (&params, 'c') ? 0 : count,
			'#' | A_REVERSE, 1,
			A_REVERSE,
			CDKparamValue (&params, 'N', TRUE),
			CDKparamValue (&params, 'S', FALSE));

   /* Check if the radio list is null. */
   if (radio == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create the radio widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   if (CDKparamNumber (&params, 'c'))
   {
      setCDKRadioItems (radio, (CDK_CSTRING2) item, count);
   }

   /* loop until user selects a file, or cancels */
   for (;;)
   {
      /* Activate the radio list. */
      selection = activateCDKRadio (radio, 0);

      /* Check the exit status of the widget. */
      if (radio->exitType == vESCAPE_HIT)
      {
	 mesg[0] = "<C>You hit escape. No item selected.";
	 mesg[1] = "";
	 mesg[2] = "<C>Press any key to continue.";
	 popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
	 break;
      }
      else if (radio->exitType == vNORMAL)
      {
	 struct stat sb;

	 if (stat (item[selection], &sb) == 0
	     && (sb.st_mode & S_IFMT) == S_IFDIR)
	 {
	    char **nitem = 0;

	    mesg[0] = "<C>You selected a directory";
	    sprintf (temp, "<C>%.*s", (int)(sizeof (temp) - 20), item[selection]);
	    mesg[1] = temp;
	    mesg[2] = "";
	    mesg[3] = "<C>Press any key to continue.";
	    popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 4);
	    count = CDKgetDirectoryContents (item[selection], &nitem);
	    if (count > 0)
	    {
	       CDKfreeStrings (item);
	       item = nitem;
	       if (chdir (item[selection]) == 0)
		  setCDKRadioItems (radio, (CDK_CSTRING2) item, count);
	    }
	 }
	 else
	 {
	    mesg[0] = "<C>You selected the filename";
	    sprintf (temp, "<C>%.*s", (int)(sizeof (temp) - 20), item[selection]);
	    mesg[1] = temp;
	    mesg[2] = "";
	    mesg[3] = "<C>Press any key to continue.";
	    popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 4);
	    break;
	 }
      }
   }

   /* Clean up. */
   CDKfreeStrings (item);
   destroyCDKRadio (radio);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #15
0
/*
 * This program demonstrates the Cdk itemlist widget.
 *
 * Options (in addition to minimal CLI parameters):
 *	-c	create the data after the widget
 */
int main(int argc, char **argv)
{
   /* Declare local variables. */
   CDKSCREEN *cdkscreen		= 0;
   CDKITEMLIST *monthlist	= 0;
   WINDOW *cursesWin		= 0;
   char *title			= "<C>Pick A Month";
   char *label			= "</U/5>Month:";
   char *info[MONTHS], temp[256], *mesg[10];
   int choice, startMonth;
   struct tm *dateInfo;
   time_t clck;

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, "c" CDK_MIN_PARAMS);

   /*
    * Get the current date and set the default month to the
    * current month.
    */
   time (&clck);
   dateInfo	= localtime (&clck);
   startMonth	= dateInfo->tm_mon;

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK colors. */
   initCDKColor();

   /* Create the choice list. */
   info[0]	= "<C></5>January";
   info[1]	= "<C></5>February";
   info[2]	= "<C></B/19>March";
   info[3]	= "<C></5>April";
   info[4]	= "<C></5>May";
   info[5]	= "<C></K/5>June";
   info[6]	= "<C></12>July";
   info[7]	= "<C></5>August";
   info[8]	= "<C></5>September";
   info[9]	= "<C></32>October";
   info[10]	= "<C></5>November";
   info[11]	= "<C></11>December";

   /* Create the itemlist widget. */
   monthlist	= newCDKItemlist (cdkscreen,
				  CDKparamValue(&params, 'X', CENTER),
				  CDKparamValue(&params, 'Y', CENTER),
				  title,
				  label,
				  CDKparamNumber(&params, 'c') ? 0 : info,
				  CDKparamNumber(&params, 'c') ? 0 : MONTHS,
				  startMonth,
				  CDKparamValue(&params, 'N', TRUE),
				  CDKparamValue(&params, 'S', FALSE));

   /* Is the widget null? */
   if (monthlist == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a little message. */
      printf ("Oops. Can't seem to create the itemlist box. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   if (CDKparamNumber(&params, 'c'))
   {
      setCDKItemlistValues (monthlist, info, MONTHS, 0);
   }

   /* Activate the widget. */
   choice = activateCDKItemlist (monthlist, 0);

   /* Check how they exited from the widget. */
   if (monthlist->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No item selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(monthlist), mesg, 3);
   }
   else if (monthlist->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected the %dth item which is", choice);
      mesg[0] = copyChar (temp);
      mesg[1] = info[choice];
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(monthlist), mesg, 4);
      freeChar (mesg[0]);
   }

   /* Clean up. */
   destroyCDKItemlist (monthlist);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
/*
 * This program demonstrates the file selector and the viewer widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKVIEWER *example   = 0;
   CDKFSELECT *fSelect  = 0;
   char **info          = 0;
   const char *button[5];
   char vTitle[256];
   const char *mesg[4];
   char temp[256];
   int selected, lines;

   CDK_PARAMS params;
   char *filename;		/* specify filename, bypassing fselect */
   char *directory;		/* specify starting directory for fselect */
   int interp_it;		/* interpret embedded markup */
   int link_it;			/* load file via embedded link */

   CDKparseParams (argc, argv, &params, "f:d:il" CDK_CLI_PARAMS);
   /* *INDENT-EQLS* */
   filename     = CDKparamString (&params, 'f');
   directory    = CDKparamString2 (&params, 'd', ".");
   interp_it    = CDKparamNumber2 (&params, 'i', FALSE);
   link_it      = CDKparamNumber2 (&params, 'l', FALSE);

   /* Create the viewer buttons. */
   button[0] = "</5><OK><!5>";
   button[1] = "</5><Cancel><!5>";

   cdkscreen = initCDKScreen (NULL);

   /* Start color. */
   initCDKColor ();

   /* Get the filename. */
   if (filename == 0)
   {
      const char *title = "<C>Pick\n<C>A\n<C>File";
      const char *label = "File:  ";

      fSelect = newCDKFselect (cdkscreen,
			       CDKparamValue (&params, 'X', CENTER),
			       CDKparamValue (&params, 'Y', CENTER),
			       CDKparamValue (&params, 'H', 20),
			       CDKparamValue (&params, 'W', 65),
			       title, label, A_NORMAL, '_', A_REVERSE,
			       "</5>", "</48>", "</N>", "</N>",
			       CDKparamValue (&params, 'N', TRUE),
			       CDKparamValue (&params, 'S', FALSE));
      if (fSelect == 0)
      {
	 destroyCDKScreen (cdkscreen);
	 endCDK ();

	 fprintf (stderr, "Cannot create fselect-widget\n");
	 ExitProgram (EXIT_FAILURE);
      }

      /*
       * Set the starting directory. This is not necessary because when
       * the file selector starts it uses the present directory as a default.
       */
      setCDKFselect (fSelect, directory, A_NORMAL, '.', A_REVERSE,
		     "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box);

      /* Activate the file selector. */
      filename = activateCDKFselect (fSelect, 0);

      /* Check how the person exited from the widget. */
      if (fSelect->exitType == vESCAPE_HIT)
      {
	 /* Pop up a message for the user. */
	 mesg[0] = "<C>Escape hit. No file selected.";
	 mesg[1] = "";
	 mesg[2] = "<C>Press any key to continue.";
	 popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);

	 /* Exit CDK. */
	 destroyCDKFselect (fSelect);
	 destroyCDKScreen (cdkscreen);
	 endCDK ();
	 ExitProgram (EXIT_SUCCESS);
      }
   }

   /* Create the file viewer to view the file selected. */
   example = newCDKViewer (cdkscreen,
			   CDKparamValue (&params, 'X', CENTER),
			   CDKparamValue (&params, 'Y', CENTER),
			   CDKparamValue (&params, 'H', 20),
			   CDKparamValue (&params, 'W', -2),
			   (CDK_CSTRING2)button, 2, A_REVERSE,
			   CDKparamValue (&params, 'N', TRUE),
			   CDKparamValue (&params, 'S', FALSE));

   /* Could we create the viewer widget? */
   if (example == 0)
   {
      /* Exit CDK. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create viewer. Is the window too small?\n");
      ExitProgram (EXIT_SUCCESS);
   }

   if (link_it)
   {
      info = (char **)calloc (2, sizeof (char *));
      info[0] = (char *)malloc (5 + strlen (filename));
      sprintf (info[0], "<F=%s>", filename);
      lines = -1;
      interp_it = TRUE;
   }
   else
   {
      setCDKViewer (example, "reading...", 0, 0, A_REVERSE, TRUE, TRUE, TRUE);
      /* Open the file and read the contents. */
      lines = CDKreadFile (filename, &info);
      if (lines == -1)
      {
	 endCDK ();
	 printf ("Could not open \"%s\"\n", filename);
	 ExitProgram (EXIT_FAILURE);
      }
   }

   /* Set up the viewer title, and the contents to the widget. */
   sprintf (vTitle, "<C></B/21>Filename:<!21></22>%20s<!22!B>", filename);
   setCDKViewer (example, vTitle,
		 (CDK_CSTRING2)info, lines,
		 A_REVERSE, interp_it, TRUE, TRUE);

   CDKfreeStrings (info);

   /* Destroy the file selector widget. */
   destroyCDKFselect (fSelect);

   /* Activate the viewer widget. */
   selected = activateCDKViewer (example, 0);

   /* Check how the person exited from the widget. */
   if (example->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>Escape hit. No Button selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }
   else if (example->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected button %d", selected);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }

   /* Clean up. */
   destroyCDKViewer (example);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
/*
 * This program demonstrates the Cdk dialog widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKDIALOG *question  = 0;
   const char *buttons[] =
   {"</B/24>Ok", "</B16>Cancel"};
   const char *message[10];
   const char *mesg[3];
   char temp[100];
   int selection;

   CDK_PARAMS params;

   CDKparseParams (argc, argv, &params, CDK_MIN_PARAMS);

   cdkscreen = initCDKScreen (NULL);

   /* Start color. */
   initCDKColor ();

   /* Create the message within the dialog box. */
   message[0] = "<C></U>Dialog Widget Demo";
   message[1] = " ";
   message[2] = "<C>The dialog widget allows the programmer to create";
   message[3] = "<C>a popup dialog box with buttons. The dialog box";
   message[4] = "<C>can contain </B/32>colours<!B!32>, </R>character attributes<!R>";
   message[5] = "<R>and even be right justified.";
   message[6] = "<L>and left.";

   /* Create the dialog box. */
   question = newCDKDialog (cdkscreen,
			    CDKparamValue (&params, 'X', CENTER),
			    CDKparamValue (&params, 'Y', CENTER),
			    (CDK_CSTRING2) message, 7,
			    (CDK_CSTRING2) buttons, 2,
			    COLOR_PAIR (2) | A_REVERSE,
			    TRUE,
			    CDKparamValue (&params, 'N', TRUE),
			    CDKparamValue (&params, 'S', FALSE));

   /* Check if we got a null value back. */
   if (question == 0)
   {
      /* Shut down Cdk. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create the dialog box. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the dialog box. */
   selection = activateCDKDialog (question, 0);

   /* Tell them what was selected. */
   if (question->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No button selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (question->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected button #%d", selection);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }

   /* Clean up. */
   destroyCDKDialog (question);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #18
0
/*
 * This program demonstrates the Cdk unsigned-slider widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKUSLIDER *widget   = 0;
   WINDOW *cursesWin    = 0;
   char title[256];
   const char *label    = "</B>Current Value:";
   const char *mesg[5];
   char temp[256];
   unsigned selection;

   CDK_PARAMS params;
   unsigned high;
   unsigned inc;
   unsigned low;

   /* *INDENT-EQLS* */
   CDKparseParams (argc, argv, &params, "h:i:l:w:" CDK_MIN_PARAMS);
   high   = (unsigned)CDKparamNumber2 (&params, 'h', 100);
   inc    = (unsigned)CDKparamNumber2 (&params, 'i', 1);
   low    = (unsigned)CDKparamNumber2 (&params, 'l', 1);

   sprintf (title, "<C></U>Enter a value:\nLow  %#x\nHigh %#x", low, high);

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor ();

   /* Create the widget. */
   widget = newCDKUSlider (cdkscreen,
			   CDKparamValue (&params, 'X', CENTER),
			   CDKparamValue (&params, 'Y', CENTER),
			   title, label,
			   A_REVERSE | COLOR_PAIR (29) | ' ',
			   CDKparamNumber2 (&params, 'w', 50),
			   low, low, high,
			   inc, (inc * 2),
			   CDKparamValue (&params, 'N', TRUE),
			   CDKparamValue (&params, 'S', FALSE));

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot make the widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the widget. */
   selection = activateCDKUSlider (widget, 0);

   /* Check the exit value of the widget. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No value selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected %u", selection);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }

   /* Clean up. */
   destroyCDKUSlider (widget);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #19
0
/*
 * This program demonstrates the Cdk radio widget.
 */
int main(int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = (CDKSCREEN *) NULL;
   CDKRADIO *radio = (CDKRADIO *) NULL;
   WINDOW *cursesWin = (WINDOW *) NULL;
   char *item[5] =
   {"Choice A", "Choice B", "Choice C"};
   char *mesg[5], temp[100];
   int selection;

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, "s:t:" CDK_CLI_PARAMS);

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Set up CDK Colors. */
   initCDKColor ();

   /* Create the radio list. */
   radio = newCDKRadio (cdkscreen,
			CDKparamValue(&params, 'X', CENTER),
			CDKparamValue(&params, 'Y', CENTER),
			CDKparsePosition(CDKparamString2(&params, 's', "NONE")),
			CDKparamValue(&params, 'H', 5),
			CDKparamValue(&params, 'W', 20),
		        CDKparamString(&params, 't'),
			item, 3,
			'#' | A_REVERSE, 1,
			A_REVERSE,
			CDKparamValue(&params, 'N', TRUE),
			CDKparamValue(&params, 'S', FALSE));

   /* Check if the radio list is NULL. */
   if (radio == (CDKRADIO *) NULL)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      /* Print out a message and exit. */
      printf ("Oops. Can't seem to create the radio widget. ");
      printf ("Is the window too small??\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the radio list. */
   selection = activateCDKRadio (radio, (chtype *) NULL);

   /* Check the exit status of the widget. */
   if (radio->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No item selected.";
      mesg[1] = "",
	 mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (radio->exitType == vNORMAL)
   {
      mesg[0] = "<C>You selected the filename";
      sprintf (temp, "<C>%.*s", (int)(sizeof(temp) - 20), item[selection]);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);
      freeChar (mesg[1]);
   }

   destroyCDKRadio (radio);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #20
0
/*
 * This function sets the information inside the file selector.
 */
void setCDKFselect (CDKFSELECT *fselect, char *directory, chtype fieldAttrib, chtype filler, chtype highlight, char *dirAttribute, char *fileAttribute, char *linkAttribute, char *sockAttribute, boolean Box GCC_UNUSED)
{
   /* Declare local variables. */
   CDKSCROLL *fscroll	= fselect->scrollField;
   CDKENTRY *fentry	= fselect->entryField;
   char *tempDir	= 0;
   char *mesg[10], newDirectory[2000], temp[100];
   int ret;

   /* Keep the info sent to us. */
   fselect->fieldAttribute	= fieldAttrib;
   fselect->fillerCharacter	= filler;
   fselect->highlight		= highlight;
   strcpy (newDirectory, directory);

   /* Set the attributes of the entry field/scrolling list. */
   setCDKEntryFillerChar (fentry, filler);
   setCDKScrollHighlight (fscroll, highlight);

   /* Only do the directory stuff if the directory is not null. */
   if (directory != 0)
   {
      /* Try to expand the directory if it starts with a ~ */
      if (directory[0] == '~')
      {
	 tempDir = expandFilename (directory);
	 if (tempDir != 0)
	 {
	    strcpy (newDirectory, tempDir);
	    freeChar (tempDir);
	 }
      }

      /* Change directories. */
      ret = chdir (newDirectory);
      if (ret != 0)
      {
	 /* Beep at them. */
	 Beep();

	 /* Couldn't get into the directory, pop up a little message. */
	 sprintf (temp, "<C>Could not change into %s", newDirectory);
	 mesg[0] = copyChar (temp);

#ifdef HAVE_STRERROR
	 sprintf (temp, "<C></U>%s", strerror(errno));
	 mesg[1] = copyChar (temp);
#else
	 sprintf (temp, "<C></U>Unknown reason.");
	 mesg[1] = copyChar (temp);
#endif

	 mesg[2] = " ";
	 mesg[3] = "<C>Press Any Key To Continue.";

	 /* Pop Up a message. */
	 popupLabel (ScreenOf(fselect), mesg, 4);

	 /* Clean up some memory. */
	 freeCharList (mesg, 4);

	 /* Get out of here. */
	 eraseCDKFselect (fselect);
	 drawCDKFselect (fselect, ObjOf(fselect)->box);
	 return;
      }
   }

   /*
    * If the information coming in is the same as the information
    * that is already there, there is no need to destroy it.
    */
   if (fselect->pwd != directory)
   {
      setPWD(fselect);
   }
   if (fselect->fileAttribute != fileAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->fileAttribute);
      fselect->fileAttribute = copyChar (fileAttribute);
   }
   if (fselect->dirAttribute != dirAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->dirAttribute);
      fselect->dirAttribute = copyChar (dirAttribute);
   }
   if (fselect->linkAttribute != linkAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->linkAttribute);
      fselect->linkAttribute = copyChar (linkAttribute);
   }
   if (fselect->sockAttribute != sockAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->sockAttribute);
      fselect->sockAttribute = copyChar (sockAttribute);
   }

   /* Set the contents of the entry field. */
   setCDKEntryValue (fentry, fselect->pwd);
   drawCDKEntry (fentry, ObjOf(fentry)->box);

   /* Get the directory contents. */
   if (setCDKFselectDirContents (fselect) == 0)
   {
      Beep();
      return;
   }

   /* Set the values in the scrolling list. */
   setCDKScrollItems (fscroll,
			fselect->dirContents,
			fselect->fileCounter,
			FALSE);
}
Exemple #21
0
/*
 * This program demonstrates the Cdk template widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen		= 0;
   CDKTEMPLATE *phoneNumber	= 0;
   WINDOW *cursesWin		= 0;
   char *title			= "<C>Title";
   char *label			= "</5>Phone Number:<!5>";
   char *Overlay		= "</B/6>(___)<!6> </5>___-____";
   char *plate			= "(###) ###-####";
   char *info, *mixed, temp[256], *mesg[5];

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, CDK_MIN_PARAMS);

   /* Set up CDK*/
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor();

   /* Declare the template. */
   phoneNumber = newCDKTemplate (cdkscreen,
				 CDKparamValue(&params, 'X', CENTER),
				 CDKparamValue(&params, 'Y', CENTER),
				 title, label,
				 plate, Overlay,
				 CDKparamValue(&params, 'N', TRUE),
				 CDKparamValue(&params, 'S', FALSE));

   /* Is the template pointer null? */
   if (phoneNumber == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message and exit. */
      printf ("Oops. Can;'t seem to create template. Is the window too small?");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the template. */
   info = activateCDKTemplate (phoneNumber, 0);

   /* Tell them what they typed. */
   if (phoneNumber->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information typed in.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (phoneNumber->exitType == vNORMAL)
   {
      /* Mix the plate and the number. */
      mixed = mixCDKTemplate (phoneNumber);

      /* Create the message to display.				*/
      sprintf (temp, "Phone Number with out plate mixing  : %.*s", (int)(sizeof(temp) - 50), info);
      mesg[0] = copyChar (temp);
      sprintf (temp, "Phone Number with the plate mixed in: %.*s", (int)(sizeof(temp) - 50), mixed);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);

      freeChar (mesg[0]);
      freeChar (mesg[1]);
      freeChar (mixed);
   }

   /* Clean up. */
   destroyCDKTemplate (phoneNumber);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #22
0
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKVIEWER *example   = 0;
   CDKFSELECT *fSelect  = 0;
   WINDOW *cursesWin    = 0;
   const char *title    = "<C>Pick\n<C>A\n<C>File";
   const char *label    = "File: ";
   char **info          = 0;
   const char *button[5];
   const char *mesg[4];
   char *filename;
   char vTitle[256];
   char temp[256];
   int selected, lines;

   CDK_PARAMS params;
   char *directory;

   CDKparseParams (argc, argv, &params, "d:" CDK_CLI_PARAMS);
   directory = CDKparamString2 (&params, 'd', ".");

   /* Create the viewer buttons. */
   button[0] = "</5><OK><!5>";
   button[1] = "</5><Cancel><!5>";

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start color. */
   initCDKColor ();

   /* Get the filename. */
   fSelect = newCDKFselect (cdkscreen,
			    CDKparamValue (&params, 'X', CENTER),
			    CDKparamValue (&params, 'Y', CENTER),
			    CDKparamValue (&params, 'H', 20),
			    CDKparamValue (&params, 'W', 65),
			    title, label, A_NORMAL, '_', A_REVERSE,
			    "</5>", "</48>", "</N>", "</N>",
			    CDKparamValue (&params, 'N', TRUE),
			    CDKparamValue (&params, 'S', FALSE));

   if (fSelect == 0)
   {
      destroyCDKScreen (cdkscreen);
      endCDK ();

      fprintf (stderr, "Cannot create widget\n");
      ExitProgram (EXIT_FAILURE);
   }

   bindCDKObject (vFSELECT, fSelect, '?', do_help, NULL);
   bindCDKObject (vFSELECT, fSelect, KEY_F1, do_help, NULL);
   bindCDKObject (vFSELECT, fSelect, KEY_F2, do_delete, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F3, do_delete1, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F4, do_reload, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F5, do_undo, fSelect);

   /*
    * Set the starting directory. This is not necessary because when
    * the file selector starts it uses the present directory as a default.
    */
   setCDKFselect (fSelect, directory, A_NORMAL, ' ', A_REVERSE,
		  "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box);
   myUserList = copyCharList ((const char **)getCDKFselectContents (fSelect, &userSize));
   myUndoList = (UNDO *) malloc ((size_t) userSize * sizeof (UNDO));
   undoSize = 0;

   /* Activate the file selector. */
   filename = activateCDKFselect (fSelect, 0);

   /* Check how the person exited from the widget. */
   if (fSelect->exitType == vESCAPE_HIT)
   {
      /* Pop up a message for the user. */
      mesg[0] = "<C>Escape hit. No file selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);

      /* Exit CDK. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      ExitProgram (EXIT_SUCCESS);
   }

   /* Create the file viewer to view the file selected. */
   example = newCDKViewer (cdkscreen, CENTER, CENTER, 20, -2,
			   (CDK_CSTRING2)button, 2, A_REVERSE, TRUE, FALSE);

   /* Could we create the viewer widget? */
   if (example == 0)
   {
      /* Exit CDK. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Can't seem to create viewer. Is the window too small?\n");
      ExitProgram (EXIT_SUCCESS);
   }

   /* Open the file and read the contents. */
   lines = CDKreadFile (filename, &info);
   if (lines == -1)
   {
      filename = copyChar (filename);

      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Could not open \"%s\"\n", filename);

      ExitProgram (EXIT_FAILURE);
   }

   /* Set up the viewer title, and the contents to the widget. */
   sprintf (vTitle, "<C></B/21>Filename:<!21></22>%20s<!22!B>", filename);
   setCDKViewer (example, vTitle,
		 (CDK_CSTRING2)info, lines,
		 A_REVERSE, TRUE, TRUE, TRUE);

   CDKfreeStrings (info);

   /* Destroy the file selector widget. */
   destroyCDKFselect (fSelect);

   /* Activate the viewer widget. */
   selected = activateCDKViewer (example, 0);

   /* Check how the person exited from the widget. */
   if (example->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>Escape hit. No Button selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }
   else if (example->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected button %d", selected);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }

   /* Clean up. */
   destroyCDKViewer (example);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #23
0
/*
 * This program demonstrates the Cdk selection widget.
 *
 * Options (in addition to normal CLI parameters):
 *	-c	create the data after the widget
 *	-s SPOS	location for the scrollbar
 *	-t TEXT	title for the widget
 *
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen		= 0;
   CDKSELECTION *selection	= 0;
   WINDOW *cursesWin		= 0;
   char *title			= "<C></5>Pick one or more accounts.";
   char *choices[]		= {"   ", "-->"};
   char **item = 0;
   char temp[256], *mesg[200];
   struct passwd *ent;
   unsigned x, y;
   unsigned used = 0;
   unsigned count = 0;

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, "cs:t:" CDK_CLI_PARAMS);

   /* Use the account names to create a list. */
   count = 0;
   while ((ent = getpwent ()) != 0)
   {
      used = CDKallocStrings(&item, ent->pw_name, count++, used);
   }
   endpwent();
   count--;

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Set up CDK Colors. */
   initCDKColor();

   /* Create the selection list. */
   selection = newCDKSelection (cdkscreen,
				CDKparamValue(&params, 'X', CENTER),
				CDKparamValue(&params, 'Y', CENTER),
				CDKparsePosition(CDKparamString2(&params, 's', "RIGHT")),
				CDKparamValue(&params, 'H', 10),
				CDKparamValue(&params, 'W', 50),
				CDKparamString2(&params, 't', title),
				CDKparamNumber(&params, 'c') ? 0 : item,
				CDKparamNumber(&params, 'c') ? 0 : count,
				choices, 2,
				A_REVERSE,
				CDKparamValue(&params, 'N', TRUE),
				CDKparamValue(&params, 'S', FALSE));

   /* Is the selection list null? */
   if (selection == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message and exit. */
      printf ("Oops. Can;t seem to create the selection list. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   if (CDKparamNumber(&params, 'c'))
   {
      setCDKSelectionItems (selection, item, count);
   }

   /* Activate the selection list. */
   activateCDKSelection (selection, 0);

   /* Check the exit status of the widget. */
   if (selection->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No items selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (selection->exitType == vNORMAL)
   {
      mesg[0] = "<C>Here are the accounts you selected.";
      y = 1;
      for (x=0; x < count; x++)
      {
	 if (selection->selections[x] == 1)
	 {
	    sprintf (temp, "<C></5>%.*s", (int)(sizeof(temp) - 20), item[x]);
	    mesg[y++] = copyChar (temp);
	 }
      }
      popupLabel (cdkscreen, mesg, y);

      /* Clean up. */
      for (x=1; x < y; x++)
      {
	  freeChar (mesg[x]);
      }
   }

   /* Clean up. */
   CDKfreeStrings (item);
   destroyCDKSelection (selection);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Exemple #24
0
/*
 * This function allows the user to dump the
 * information from the viewer into a file.
 */
static void saveInformation (CDKVIEWER *widget)
{
   /* Declare local variables. */
   CDKENTRY *entry	= 0;
   char *filename	= 0;
   char temp[256], *mesg[10];
   int linesSaved;

   /* Create the entry field to get the filename. */
   entry = newCDKEntry (ScreenOf(widget), CENTER, CENTER,
				"<C></B/5>Enter the filename of the save file.",
				"Filename: ",
				A_NORMAL, '_', vMIXED,
				20, 1, 256,
				TRUE, FALSE);

   /* Get the filename. */
   filename = activateCDKEntry (entry, 0);

   /* Did they hit escape? */
   if (entry->exitType == vESCAPE_HIT)
   {
      /* Popup a message. */
      mesg[0] = "<C></B/5>Save Canceled.";
      mesg[1] = "<C>Escape hit. Scrolling window information not saved.";
      mesg[2] = " ";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(widget), mesg, 4);

      destroyCDKEntry (entry);
      return;
   }

   /* Write the contents of the viewer to the file. */
   linesSaved = dumpViewer (widget, filename);

   /* Was the save successful? */
   if (linesSaved == -1)
   {
      /* Nope, tell 'em. */
      mesg[0] = "<C></B/16>Error";
      mesg[1] = "<C>Could not save to the file.";
      sprintf (temp, "<C>(%s)", filename);
      mesg[2] = copyChar (temp);
      mesg[3] = " ";
      mesg[4] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(widget), mesg, 5);
      freeChar (mesg[2]);
   }
   else
   {
      mesg[0] = "<C></B/5>Save Successful";
      sprintf (temp, "<C>There were %d lines saved to the file", linesSaved);
      mesg[1] = copyChar (temp);
      sprintf (temp, "<C>(%s)", filename);
      mesg[2] = copyChar (temp);
      mesg[3] = " ";
      mesg[4] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(widget), mesg, 5);
      freeChar (mesg[1]); freeChar (mesg[2]);
   }

   destroyCDKEntry (entry);
   eraseCDKScreen (ScreenOf(widget));
   drawCDKScreen (ScreenOf(widget));
}
/*
 * This program demonstrates the Cdk calendar widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen		= 0;
   CDKCALENDAR *calendar	= 0;
   const char *mesg[5];
   char temp[256];
   struct tm *dateInfo;
   time_t clck, retVal;

   CDK_PARAMS params;
   char *title;
   int day;
   int month;
   int year;

   /*
    * Get the current dates and set the default values for
    * the day/month/year values for the calendar.
    */
   time (&clck);
   dateInfo	= gmtime (&clck);

   /* *INDENT-EQLS* */
   CDKparseParams (argc, argv, &params, "d:m:y:t:w:" CDK_MIN_PARAMS);
   day   = CDKparamNumber2 (&params, 'd', dateInfo->tm_mday);
   month = CDKparamNumber2 (&params, 'm', dateInfo->tm_mon + 1);
   year  = CDKparamNumber2 (&params, 'y', dateInfo->tm_year + 1900);
   title = CDKparamString2 (&params, 't', "<C></U>CDK Calendar Widget\n<C>Demo");

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK Colors. */
   initCDKColor ();

   /* Create the calendar widget. */
   calendar = newCDKCalendar (cdkscreen,
			      CDKparamValue (&params, 'X', CENTER),
			      CDKparamValue (&params, 'Y', CENTER),
			      title, day, month, year,
			      COLOR_PAIR (16) | A_BOLD,
			      COLOR_PAIR (24) | A_BOLD,
			      COLOR_PAIR (32) | A_BOLD,
			      COLOR_PAIR (40) | A_REVERSE,
			      CDKparamValue (&params, 'N', TRUE),
			      CDKparamValue (&params, 'S', FALSE));

   /* Is the widget null? */
   if (calendar == 0)
   {
      /* Clean up the memory. */
      destroyCDKScreen (cdkscreen);

      /* End curses... */
      endCDK ();

      printf ("Cannot create the calendar. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Create a key binding to mark days on the calendar. */
   bindCDKObject (vCALENDAR, calendar, 'm', createCalendarMarkCB, calendar);
   bindCDKObject (vCALENDAR, calendar, 'M', createCalendarMarkCB, calendar);
   bindCDKObject (vCALENDAR, calendar, 'r', removeCalendarMarkCB, calendar);
   bindCDKObject (vCALENDAR, calendar, 'R', removeCalendarMarkCB, calendar);

   calendar->weekBase = CDKparamNumber (&params, 'w');

   /* Draw the calendar widget. */
   drawCDKCalendar (calendar, ObjOf (calendar)->box);

   /* Let the user play with the widget. */
   retVal = activateCDKCalendar (calendar, 0);

   /* Check which day they selected. */
   if (calendar->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No date selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (calendar->exitType == vNORMAL)
   {
      mesg[0] = "You selected the following date";
      sprintf (temp, "<C></B/16>%02d/%02d/%d (dd/mm/yyyy)",
	       calendar->day,
	       calendar->month,
	       calendar->year);
      mesg[1] = temp;
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }

   /* Clean up and exit. */
   destroyCDKCalendar (calendar);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   fflush (stdout);
   printf ("Selected Time: %s\n", ctime (&retVal));
   ExitProgram (EXIT_SUCCESS);
}
Exemple #26
0
/*
 * This program demonstrates the Cdk matrix widget.
 */
int main (int argc, char **argv)
{
   /* Declare local variables. */
   CDKSCREEN *cdkscreen     = 0;
   CDKMATRIX *form_prov    = 0;
   WINDOW *cursesWin        = 0;
   char *title          = 0;
   int rows         = 5;
   int cols         = 1;
   int vrows            = 5;
   int vcols            = 1;
   char *coltitle[10], *rowtitle[10], *mesg[10];
   int colwidth[10], colvalue[10];

 //  CDK_PARAMS params;

 //  CDKparseParams (argc, argv, &params, CDK_MIN_PARAMS);

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor();

   /* Create the horizontal and vertical matrix labels. */
#define set_col(n, width, string) \
   coltitle[n] = string;   colwidth[n] = width ; colvalue[n] = vUMIXED

   set_col(1, 7, "</B/5>Proveedor");
   set_col(2, 7, "</B/33>Lec 1");
   set_col(3, 7, "</B/33>Lec 2");
   set_col(4, 7, "</B/33>Lec 3");
   set_col(5, 1, "</B/7>Flag");

#define set_row(n, string) \
   rowtitle[n] = "</B/8>" string

   set_row(1, "ID");
   set_row(2, "Nombre");
   set_row(3, "Apellido");
   set_row(4, "Correo");
   set_row(5, "Direccion");
   set_row(6, "Course 6");
   set_row(7, "Course 7");
   set_row(8, "Course 8");

   /* Create the title. */
   /* Create the matrix object. */
   form_prov = newCDKMatrix (cdkscreen,
                   CENTER,
                   CENTER,
                  rows, cols, vrows, vcols,
                  title, rowtitle, coltitle,
                  colwidth, colvalue,
                  -1, -1, '.',
                  COL, TRUE,
                  TRUE,
                   FALSE);

   /* Check to see if the matrix is null. */
   if (form_prov == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a little message. */
      printf ("Oops. Can't seem to create the matrix widget. Is the window too small ?\n");
      exit (EXIT_FAILURE);
   }

   /* Activate the matrix. */
   activateCDKMatrix (form_prov, 0);

   /* Check if the user hit escape or not. */
   if (form_prov->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information passed back.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (form_prov->exitType == vNORMAL)
   {
      char temp[80];

      sprintf(temp, "Current cell (%d,%d)", form_prov->crow, form_prov->ccol);
      mesg[0] = "<L>You exited the matrix normally.";
      mesg[1] = temp;
      mesg[2] = "<L>To get the contents of the matrix cell, you can";
      mesg[3] = "<L>use getCDKMatrixCell():";
      mesg[4] = getCDKMatrixCell(form_prov, form_prov->crow, form_prov->ccol);
      mesg[5] = "";
      mesg[6] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 7);
   }

   /* Clean up. */
   destroyCDKMatrix (form_prov);
   destroyCDKScreen (cdkscreen);
   endCDK();
   exit (EXIT_SUCCESS);
}
Exemple #27
0
/*
 * This program demonstrates the Cdk slider widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKFSLIDER *widget	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C></U>Enter a value:";
   char *label		= "</B>Current Value:";
   char temp[256], *mesg[5];
   float selection;

   CDK_PARAMS params;
   float high;
   float inc;
   float low;

   float scale;
   int n, digits;

   CDKparseParams(argc, argv, &params, "h:i:l:w:p:" CDK_MIN_PARAMS);
   digits = CDKparamNumber2(&params, 'p', 0);

   scale = 1.0;
   for (n = 0; n < digits; ++n) {
      scale = scale * 10.0;
   }

   high   = CDKparamNumber2(&params, 'h', 100) / scale;
   inc    = CDKparamNumber2(&params, 'i', 1) / scale;
   low    = CDKparamNumber2(&params, 'l', 1) / scale;

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor();

   /* Create the widget. */
   widget = newCDKFSlider (cdkscreen,
			  CDKparamValue(&params, 'X', CENTER),
			  CDKparamValue(&params, 'Y', CENTER),
			  title, label,
			  A_REVERSE | COLOR_PAIR (29) | ' ',
			  CDKparamNumber2(&params, 'w', 50),
			  low, low, high,
			  inc, (inc*2),
			  digits,
			  CDKparamValue(&params, 'N', TRUE),
			  CDKparamValue(&params, 'S', FALSE));

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message. */
      printf ("Oops. Can't make the widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the widget. */
   selection = activateCDKFSlider (widget, 0);

   /* Check the exit value of the widget. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No value selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected %.*f", digits, selection);
      mesg[0] = copyChar (temp);
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
      freeChar (mesg[0]);
   }

   /* Clean up.*/
   destroyCDKFSlider (widget);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}