/* $Id: radio_ex.c,v 1.16 2005/12/28 01:43:29 tom Exp $ */ #include <cdk_test.h> #ifdef HAVE_XCURSES char *XCursesProgramName = "radio_ex"; #endif /* * 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) { /* Declare variables. */ CDKSCREEN *cdkscreen = 0; CDKRADIO *radio = 0; WINDOW *cursesWin = 0; char *title = "<C></5>Select a filename"; char **item = 0; char *mesg[5], temp[256]; int selection, count; CDK_PARAMS params; CDKparseParams(argc, argv, ¶ms, "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(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), CDKparsePosition(CDKparamString2(¶ms, 's', "RIGHT")), CDKparamValue(¶ms, 'H', 10), CDKparamValue(¶ms, 'W', 40), CDKparamString2(¶ms, 't', title), CDKparamNumber(¶ms, 'c') ? 0 : item, CDKparamNumber(¶ms, 'c') ? 0 : count, '#'|A_REVERSE, 1, A_REVERSE, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, 'S', FALSE)); /* Check if the radio list is null. */ if (radio == 0) { /* Exit CDK. */ destroyCDKScreen (cdkscreen); endCDK(); /* Print out a message and exit. */ printf ("Oops. Can't seem to create the radio widget. Is the window too small??\n"); ExitProgram (EXIT_FAILURE); } if (CDKparamNumber(¶ms, 'c')) { setCDKRadioItems (radio, 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, 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, mesg, 4); if ((count = CDKgetDirectoryContents (item[selection], &nitem)) > 0) { CDKfreeStrings(item); item = nitem; chdir(item[selection]); setCDKRadioItems (radio, 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, mesg, 4); break; } } } /* Clean up. */ CDKfreeStrings (item); destroyCDKRadio (radio); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }