bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

addCDKScrollItem function in CDK


From: Fu Steve X
Subject: addCDKScrollItem function in CDK
Date: Wed, 23 Mar 2005 13:37:25 -0500

Hi,

The simple test code is based on scroll_ex.c. I just bind a callback to 'a' to invoke the addCDKScrollItem function. The items in the SCROLL starts to get garbled from top down if I keep pressing 'a' for 4 or 5 times. Scrolling the items up and down doesn't refresh the list correctly either. But it looks OK if I dump out chtype2Char(scrollp->item[0]).

Is that a bug?

Thanks!

Steve


/* $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

static int addItemCB(EObjectType cdktype GCC_UNUSED, void *object, void *clientData
, chtype input GCC_UNUSED)
{

   CDKSCROLL *s = (CDKSCROLL*) object;

   addCDKScrollItem(s, "junk");

        refreshCDKScreen(ScreenOf(s));

        return (TRUE);
}

/*
 * This program demonstrates the Cdk scrolling list widget.
 */
int main(int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen         = 0;
   CDKSCROLL *scrollList        = 0;
   CDKSCROLL *scrollList2       = 0;
   WINDOW *cursesWin            = 0;
   char *title                  = "<C></5>Pick a file";
   char **item                  = 0;
   char *mesg[5], temp[256];
   int selection, count;

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, 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(&params, 'X', CENTER),
                              CDKparamValue(&params, 'Y', 0),
                              RIGHT,
                              CDKparamValue(&params, 'H', 10),
                              CDKparamValue(&params, 'W', 50),
                              title, item, count,
                              FALSE,
                              A_REVERSE,
                              CDKparamValue(&params, 'N', TRUE),
                              CDKparamValue(&params, 'S', FALSE));

        bindCDKObject (vSCROLL, scrollList, 'a', addItemCB, NULL);

   /* 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);
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]