|
From: | Fu Steve X |
Subject: | Scroll in CDK |
Date: | Tue, 8 Mar 2005 14:30:29 -0500 |
Tom,
A couple of things about the Scroll widget are illustrated in the test program at the end of this message. The test program is based on the sample scroll_ex.c.
1. I invoke the function deleteCDKScrollItem( ) to delete an item then re-draw the Scroll. The numbers do not get re-set when re-drawing the Scroll if the Boolean numbers is turned on, They are now 1,2,4... since 3 is deleted.
2. The following line is needed to avoid a core dump when deleting all items and reset the scroll with new items.
scrollList->item = 0;
I think it is because the function call CDKfreeChtypes at line #846 in createCDKScrollItemList. Not sure why it is needed to be freed. If it is really needed, probably the scrollp->item should be set to NULL in deleteCDKScrollItem when the listSize==0.
Thanks.
Steve
--------------------------------- cut here ------------------------------------------------------------------
/* $Id: scroll_ex.c,v 1.16 2004/08/28 01:02:30 tom Exp $ */
#include <cdk.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName="scroll_ex";
#endif
/*
* This program demonstrates the Cdk scrolling list widget.
*/
int main(int argc, char **argv)
{
/* Declare variables. */
CDKSCREEN *cdkscreen = 0;
CDKSCROLL *scrollList = 0;
WINDOW *cursesWin = 0;
char *title = "<C></5>Pick a file";
char **item = 0;
char *mesg[5], temp[256];
int selection, count, i;
CDK_PARAMS params;
CDKparseParams(argc, argv, ¶ms, CDK_CLI_PARAMS);
/* Set up CDK. */
cursesWin = initscr();
cdkscreen = initCDKScreen (cursesWin);
/* Set up CDK Colors. */
initCDKColor();
/* Use the current diretory list to fill the radio list. */
count = CDKgetDirectoryContents (".", &item);
/* Create the scrolling list. */
scrollList = newCDKScroll (cdkscreen,
CDKparamValue(¶ms, 'X', CENTER),
CDKparamValue(¶ms, 'Y', CENTER),
RIGHT,
CDKparamValue(¶ms, 'H', 10),
CDKparamValue(¶ms, 'W', 50),
title, item, count,
TRUE,
A_REVERSE,
CDKparamValue(¶ms, 'N', TRUE),
CDKparamValue(¶ms, 'S', FALSE));
/* Is the scrolling list null? */
if (scrollList == 0)
{
/* Exit CDK. */
destroyCDKScreen (cdkscreen);
endCDK();
/* Print out a message and exit. */
printf ("Oops. Could not make scrolling list. Is the window too small?\n");
exit (EXIT_FAILURE);
}
drawCDKScroll (scrollList, 1);
sleep (2);
/*
* delete one item
*/
deleteCDKScrollItem(scrollList, 2);
drawCDKScroll (scrollList, 1);
sleep (2);
/*
* delete all items
*/
count = scrollList->listSize;
for (i = 0; i<count; i++ )
{
if ( item[i] ) {
free ( item[i] );
}
deleteCDKScrollItem(scrollList, count-i-1);
}
/*
* needed to avoid being free again.
*/
scrollList->item = 0;
/* Use the parent of current diretory list to fill the radio list. */
count = CDKgetDirectoryContents ("..", &item);
setCDKScrollItems(scrollList, item, count, TRUE);
drawCDKScroll (scrollList, 1);
setCDKScrollPosition (scrollList, 0);
/* Activate the scrolling list. */
selection = activateCDKScroll (scrollList, 0);
/* Determine how the widget was exited. */
if (scrollList->exitType == vESCAPE_HIT)
{
mesg[0] = "<C>You hit escape. No file selected.";
mesg[1] = "",
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, mesg, 3);
}
else if (scrollList->exitType == vNORMAL)
{
mesg[0] = "<C>You selected the following file";
sprintf (temp, "<C>%.*s", (int)(sizeof(temp) - 20), item[selection]);
mesg[1] = copyChar (temp);
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, mesg, 3);
freeChar (mesg[1]);
}
/* Clean up. */
CDKfreeStrings (item);
destroyCDKScroll (scrollList);
destroyCDKScreen (cdkscreen);
endCDK();
exit (EXIT_SUCCESS);
}
[Prev in Thread] | Current Thread | [Next in Thread] |