Beispiel #1
0
static int
show_toggle (CmdConfig *cmd_config, CameraWidget *toggle)
{
	CDKITEMLIST *list = NULL;
	int value, selection;
	const char *label;
	char title[1024], *info[] = {N_("Yes"), N_("No")};

	CHECK (gp_widget_get_value (toggle, &value));
	CHECK (gp_widget_get_label (toggle, &label));
	snprintf (title, sizeof (title), "<C></5>%s", label);

	list = newCDKItemlist (cmd_config->screen, CENTER, CENTER, title, "",
			       info, 2, 1 - value, TRUE, FALSE);
	if (!list)
		return (GP_ERROR);

	selection = activateCDKItemlist (list, 0);
	if (list->exitType == vNORMAL) {
		selection = 1 - selection;
		gp_widget_set_value (toggle, &selection);
		set_config (cmd_config);
	}

	destroyCDKItemlist (list);

	return (GP_OK);
}
Beispiel #2
0
static int
show_radio (CmdConfig *cmd_config, CameraWidget *radio)
{
	CDKITEMLIST *list = NULL;
	const char *label, *value, *current_value;
	char title[1024], *items[100];
	int x, count, current = 0, selection, found;

	gp_widget_get_label (radio, &label);
	snprintf (title, sizeof (title), "<C></5>%s", label);
	gp_widget_get_value (radio, &current_value);
	count = gp_widget_count_choices (radio);

	/* Check if the current value is in the list */
	current = found = 0;
	for (x = 0; x < count; x++) {
		gp_widget_get_choice (radio, x, &value);
		if (!strcmp (value, current_value)) {
			current = x;
			found = 1;
			break;
		}
	}
	if (!found)
		items[0] = copyChar ((char *) current_value);

	/* Add all items */
	for (x = 0; x < count; x++) {
		gp_widget_get_choice (radio, x, &value);
		items[x + 1 - found] = copyChar ((char *) value);
	}

	list = newCDKItemlist (cmd_config->screen, CENTER, CENTER,
			       title, _("Value: "), items, count,
			       current, TRUE, FALSE);
	if (!list)
		return (GP_ERROR);

	selection = activateCDKItemlist (list, 0);
	if (list->exitType == vNORMAL) {
		gp_widget_get_choice (radio, selection, &value);
		gp_widget_set_value (radio, (void *) value);
		set_config (cmd_config);
	}

	destroyCDKItemlist (list);
	return (GP_OK);
}
Beispiel #3
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);
}
Beispiel #4
0
/*
 * This adds a marker to the calendar.
 */
static int createCalendarMarkCB (EObjectType objectType GCC_UNUSED, void *object,
				 void *clientData,
				 chtype key GCC_UNUSED)
{
   /* *INDENT-EQLS* */
   CDKCALENDAR *calendar                        = (CDKCALENDAR *)object;
   CDKENTRY *entry                              = 0;
   CDKITEMLIST *itemlist                        = 0;
   const char *items[]                          =
   {
      "Birthday",
      "Anniversary",
      "Appointment",
      "Other"
   };
   char *description                            = 0;
   struct AppointmentInfo *appointmentInfo      = (struct AppointmentInfo *)clientData;
   int current                                  = appointmentInfo->appointmentCount;
   chtype marker;
   int selection;

   /* Create the itemlist widget. */
   itemlist = newCDKItemlist (ScreenOf (calendar),
			      CENTER, CENTER, 0,
			      "Select Appointment Type: ",
			      (CDK_CSTRING2)items, 4, 0,
			      TRUE, FALSE);

   /* Get the appointment tye from the user. */
   selection = activateCDKItemlist (itemlist, 0);

   /* They hit escape, kill the itemlist widget and leave. */
   if (selection == -1)
   {
      destroyCDKItemlist (itemlist);
      drawCDKCalendar (calendar, ObjOf (calendar)->box);
      return (FALSE);
   }

   /* Destroy the itemlist and set the marker. */
   destroyCDKItemlist (itemlist);
   drawCDKCalendar (calendar, ObjOf (calendar)->box);
   marker = GPAppointmentAttributes[selection];

   /* Create the entry field for the description. */
   entry = newCDKEntry (ScreenOf (calendar),
			CENTER, CENTER,
			"<C>Enter a description of the appointment.",
			"Description: ",
			A_NORMAL, (chtype)'.',
			vMIXED, 40, 1, 512,
			TRUE, FALSE);

   /* Get the description. */
   description = activateCDKEntry (entry, 0);
   if (description == 0)
   {
      destroyCDKEntry (entry);
      drawCDKCalendar (calendar, ObjOf (calendar)->box);
      return (FALSE);
   }

   /* Destroy the entry and set the marker. */
   description = copyChar (entry->info);
   destroyCDKEntry (entry);
   drawCDKCalendar (calendar, ObjOf (calendar)->box);

   /* Set the marker. */
   setCDKCalendarMarker (calendar,
			 calendar->day,
			 calendar->month,
			 calendar->year,
			 marker);

   /* Keep the marker. */
   appointmentInfo->appointment[current].day = calendar->day;
   appointmentInfo->appointment[current].month = calendar->month;
   appointmentInfo->appointment[current].year = calendar->year;
   appointmentInfo->appointment[current].type = (EAppointmentType) selection;
   appointmentInfo->appointment[current].description = description;
   appointmentInfo->appointmentCount++;

   /* Redraw the calendar. */
   drawCDKCalendar (calendar, ObjOf (calendar)->box);
   return (FALSE);
}