/* * This removes a marker from the calendar. */ static int removeCalendarMarkCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { CDKCALENDAR *calendar = (CDKCALENDAR *)object; struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData; int x; /* Look for the marker in the list. */ for (x = 0; x < appointmentInfo->appointmentCount; x++) { if ((appointmentInfo->appointment[x].day == calendar->day) && (appointmentInfo->appointment[x].month == calendar->month) && (appointmentInfo->appointment[x].year == calendar->year)) { freeChar (appointmentInfo->appointment[x].description); appointmentInfo->appointment[x].description = 0; break; } } /* Remove the marker from the calendar. */ removeCDKCalendarMarker (calendar, calendar->day, calendar->month, calendar->year); /* Redraw the calendar. */ drawCDKCalendar (calendar, ObjOf (calendar)->box); return (FALSE); }
static int show_date (CmdConfig *cmd_config, CameraWidget *date) { CDKCALENDAR *calendar = NULL; int day, month, year, selection; time_t time; struct tm *date_info; const char *label; char title[1024]; gp_widget_get_value (date, &time); date_info = localtime (&time); /* Month in CDK starts with 1 */ day = date_info->tm_mday; month = date_info->tm_mon + 1; year = date_info->tm_year + 1900; gp_widget_get_label (date, &label); snprintf (title, sizeof (title), "<C></5>%s", label); /* Create the calendar */ calendar = newCDKCalendar (cmd_config->screen, CENTER, 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, TRUE, FALSE); if (!calendar) return (GP_ERROR); drawCDKCalendar (calendar, TRUE); selection = activateCDKCalendar (calendar, 0); if (calendar->exitType == vNORMAL) { date_info = localtime (&time); /* Month in CDK starts with 1 */ date_info->tm_mday = calendar->day; date_info->tm_mon = calendar->month - 1; date_info->tm_year = calendar->year - 1900; time = mktime (date_info); gp_widget_set_value (date, &time); set_config (cmd_config); } destroyCDKCalendar (calendar); return (GP_OK); }
/* * This program demonstrates the Cdk calendar widget. */ int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKCALENDAR *calendar = 0; WINDOW *cursesWin = 0; const char *title = "<C></U>CDK Appointment Book\n<C><#HL(30)>\n"; char *filename = 0; struct tm *dateInfo = 0; time_t clck = 0; struct AppointmentInfo appointmentInfo; int day, month, year, ret, x; char temp[1000]; /* * Get the current dates and set the default values for * the day/month/year values for the calendar. */ /* *INDENT-EQLS* */ time (&clck); dateInfo = gmtime (&clck); day = dateInfo->tm_mday; month = dateInfo->tm_mon + 1; year = dateInfo->tm_year + 1900; /* Check the command line for options. */ while (1) { /* Are there any more command line options to parse. */ if ((ret = getopt (argc, argv, "d:m:y:t:f:")) == -1) { break; } switch (ret) { case 'd': day = atoi (optarg); break; case 'm': month = atoi (optarg); break; case 'y': year = atoi (optarg); break; case 't': title = copyChar (optarg); break; case 'f': filename = copyChar (optarg); break; } } /* Create the appointment book filename. */ if (filename == 0) { char *home = getenv ("HOME"); if (home != 0) { sprintf (temp, "%.*s/.appointment", (int)sizeof (temp) - 20, home); } else { strcat (temp, ".appointment"); } filename = copyChar (temp); } /* Read the appointment book information. */ readAppointmentFile (filename, &appointmentInfo); /* Set up CDK. */ cursesWin = initscr (); cdkscreen = initCDKScreen (cursesWin); /* Start CDK Colors. */ initCDKColor (); /* Create the calendar widget. */ calendar = newCDKCalendar (cdkscreen, CENTER, CENTER, title, day, month, year, A_NORMAL, A_NORMAL, A_NORMAL, A_REVERSE, TRUE, FALSE); /* Is the widget null? */ if (calendar == 0) { /* Clean up the memory. */ destroyCDKScreen (cdkscreen); /* End curses... */ endCDK (); /* Spit out a message. */ 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, &appointmentInfo); bindCDKObject (vCALENDAR, calendar, 'M', createCalendarMarkCB, &appointmentInfo); bindCDKObject (vCALENDAR, calendar, 'r', removeCalendarMarkCB, &appointmentInfo); bindCDKObject (vCALENDAR, calendar, 'R', removeCalendarMarkCB, &appointmentInfo); bindCDKObject (vCALENDAR, calendar, '?', displayCalendarMarkCB, &appointmentInfo); bindCDKObject (vCALENDAR, calendar, 'j', accelerateToDateCB, &appointmentInfo); bindCDKObject (vCALENDAR, calendar, 'J', accelerateToDateCB, &appointmentInfo); /* Set all the appointments read from the file. */ for (x = 0; x < appointmentInfo.appointmentCount; x++) { chtype marker = GPAppointmentAttributes[appointmentInfo.appointment[x].type]; setCDKCalendarMarker (calendar, appointmentInfo.appointment[x].day, appointmentInfo.appointment[x].month, appointmentInfo.appointment[x].year, marker); } /* Draw the calendar widget. */ drawCDKCalendar (calendar, ObjOf (calendar)->box); /* Let the user play with the widget. */ activateCDKCalendar (calendar, 0); /* Save the appointment information. */ saveAppointmentFile (filename, &appointmentInfo); free (filename); /* Clean up and exit. */ destroyCDKCalendar (calendar); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }
/* * This displays the marker(s) on the given day. */ static int displayCalendarMarkCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { /* *INDENT-EQLS* */ CDKCALENDAR *calendar = (CDKCALENDAR *)object; CDKLABEL *label = 0; struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData; int found = 0; int day = 0; int month = 0; int year = 0; int mesgLines = 0; const char *type = 0; char *mesg[10], temp[256]; int x; /* Look for the marker in the list. */ for (x = 0; x < appointmentInfo->appointmentCount; x++) { /* Get the day month year. */ /* *INDENT-EQLS* */ day = appointmentInfo->appointment[x].day; month = appointmentInfo->appointment[x].month; year = appointmentInfo->appointment[x].year; /* Determine the appointment type. */ if (appointmentInfo->appointment[x].type == vBirthday) { type = "Birthday"; } else if (appointmentInfo->appointment[x].type == vAnniversary) { type = "Anniversary"; } else if (appointmentInfo->appointment[x].type == vAppointment) { type = "Appointment"; } else { type = "Other"; } /* Find the marker by the day/month/year. */ if ((day == calendar->day) && (month == calendar->month) && (year == calendar->year) && (appointmentInfo->appointment[x].description != 0)) { /* Create the message for the label widget. */ sprintf (temp, "<C>Appointment Date: %02d/%02d/%d", day, month, year); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar (" "); mesg[mesgLines++] = copyChar ("<C><#HL(35)>"); sprintf (temp, " Appointment Type: %s", type); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar (" Description :"); sprintf (temp, " %s", appointmentInfo->appointment[x].description); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar ("<C><#HL(35)>"); mesg[mesgLines++] = copyChar (" "); mesg[mesgLines++] = copyChar ("<C>Press space to continue."); found = 1; break; } } /* If we didn't find the marker, create a different message. */ if (found == 0) { sprintf (temp, "<C>There is no appointment for %02d/%02d/%d", calendar->day, calendar->month, calendar->year); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar ("<C><#HL(30)>"); mesg[mesgLines++] = copyChar ("<C>Press space to continue."); } /* Create the label widget. */ label = newCDKLabel (ScreenOf (calendar), CENTER, CENTER, (CDK_CSTRING2)mesg, mesgLines, TRUE, FALSE); drawCDKLabel (label, ObjOf (label)->box); waitCDKLabel (label, ' '); destroyCDKLabel (label); /* Clean up the memory used. */ for (x = 0; x < mesgLines; x++) { freeChar (mesg[x]); } /* Redraw the calendar widget. */ drawCDKCalendar (calendar, ObjOf (calendar)->box); return (FALSE); }
/* * 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); }
/* * 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, ¶ms, "d:m:y:t:w:" CDK_MIN_PARAMS); day = CDKparamNumber2 (¶ms, 'd', dateInfo->tm_mday); month = CDKparamNumber2 (¶ms, 'm', dateInfo->tm_mon + 1); year = CDKparamNumber2 (¶ms, 'y', dateInfo->tm_year + 1900); title = CDKparamString2 (¶ms, 't', "<C></U>CDK Calendar Widget\n<C>Demo"); cdkscreen = initCDKScreen (NULL); /* Start CDK Colors. */ initCDKColor (); /* Create the calendar widget. */ calendar = newCDKCalendar (cdkscreen, CDKparamValue (¶ms, 'X', CENTER), CDKparamValue (¶ms, '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 (¶ms, 'N', TRUE), CDKparamValue (¶ms, '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 (¶ms, '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); }