Пример #1
0
/*
 * This creates a marquee widget.
 */
CDKMARQUEE *newCDKMarquee (CDKSCREEN *cdkscreen,
			   int xplace,
			   int yplace,
			   int width,
			   boolean Box,
			   boolean shadow)
{
   CDKMARQUEE *widget	= 0;
   int parentWidth	= getmaxx (cdkscreen->window);
   int xpos		= xplace;
   int ypos		= yplace;
   int boxHeight;
   int boxWidth;

   if ((widget = newCDKObject (CDKMARQUEE, &my_funcs)) == 0)
        return (0);

   setCDKMarqueeBox (widget, Box);

   boxWidth = setWidgetDimension (parentWidth, width, 0);
   boxHeight = (BorderOf (widget) * 2) + 1;

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* Create the widget pointer. */
   ScreenOf (widget)	= cdkscreen;
   widget->parent	= cdkscreen->window;
   widget->win		= newwin (boxHeight, boxWidth, ypos, xpos);
   widget->boxHeight	= boxHeight;
   widget->boxWidth	= boxWidth;
   widget->shadowWin	= 0;
   widget->active	= TRUE;
   widget->width	= width;
   widget->shadow	= shadow;

   /* Is the window null??? */
   if (widget->win == 0)
   {
      destroyCDKObject (widget);
      return (0);
   }

   /* Do we want a shadow? */
   if (shadow)
   {
      widget->shadowWin = subwin (cdkscreen->window,
				  boxHeight, boxWidth,
				  ypos + 1, xpos + 1);
   }

   keypad (widget->win, TRUE);

   registerCDKObject (cdkscreen, vMARQUEE, widget);

   return (widget);
}
Пример #2
0
/*
 * This creates the alphalist widget.
 */
CDKALPHALIST *newCDKAlphalist (CDKSCREEN *cdkscreen,
			       int xplace,
			       int yplace,
			       int height,
			       int width,
			       char *title,
			       char *label,
			       char **list,
			       int listSize,
			       chtype fillerChar,
			       chtype highlight,
			       boolean Box,
			       boolean shadow)
{
   CDKALPHALIST *alphalist	= 0;
   chtype *chtypeLabel		= 0;
   int parentWidth		= getmaxx (cdkscreen->window);
   int parentHeight		= getmaxy (cdkscreen->window);
   int boxWidth			= width;
   int boxHeight		= height;
   int xpos			= xplace;
   int ypos			= yplace;
   int tempWidth		= 0;
   int tempHeight		= 0;
   int labelLen			= 0;
   int x, junk2;

   static const struct { int from; int to; } bindings[] = {
      { CDK_BACKCHAR,	KEY_PPAGE },
      { CDK_FORCHAR,	KEY_NPAGE },
   };

   if ((alphalist = newCDKObject (CDKALPHALIST, &my_funcs)) == 0
       || !createList (alphalist, list, listSize))
   {
      destroyCDKObject (alphalist);
      return (0);
   }

   setCDKAlphalistBox (alphalist, Box);

   /*
    * If the height is a negative value, the height will
    * be ROWS-height, otherwise, the height will be the
    * given height.
    */
   boxHeight = setWidgetDimension (parentHeight, height, 0);

   /*
    * If the width is a negative value, the width will
    * be COLS-width, otherwise, the width will be the
    * given width.
    */
   boxWidth = setWidgetDimension (parentWidth, width, 0);

   /* Translate the label char *pointer to a chtype pointer. */
   if (label != 0)
   {
      chtypeLabel = char2Chtype (label, &labelLen, &junk2);
      freeChtype (chtypeLabel);
   }

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* Make the file selector window. */
   alphalist->win = newwin (boxHeight, boxWidth, ypos, xpos);

   if (alphalist->win == 0)
   {
      destroyCDKObject (alphalist);
      return (0);
   }
   keypad (alphalist->win, TRUE);

   /* Set some variables. */
   ScreenOf (alphalist)		= cdkscreen;
   alphalist->parent		= cdkscreen->window;
   alphalist->highlight		= highlight;
   alphalist->fillerChar	= fillerChar;
   alphalist->boxHeight		= boxHeight;
   alphalist->boxWidth		= boxWidth;
   initExitType (alphalist);
   alphalist->shadow		= shadow;
   alphalist->shadowWin		= 0;

   /* Do we want a shadow? */
   if (shadow)
   {
      alphalist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
   }

   /* Create the entry field. */
   tempWidth = (isFullWidth (width)
		? FULL
		: boxWidth - 2 - labelLen);
   alphalist->entryField = newCDKEntry (cdkscreen,
					getbegx (alphalist->win),
					getbegy (alphalist->win),
					title, label,
					A_NORMAL, fillerChar,
					vMIXED, tempWidth, 0, 512,
					Box, FALSE);
   if (alphalist->entryField == 0)
   {
      destroyCDKObject (alphalist);
      return (0);
   }
   setCDKEntryLLChar (alphalist->entryField, ACS_LTEE);
   setCDKEntryLRChar (alphalist->entryField, ACS_RTEE);

   /* Set the key bindings for the entry field. */
   bindCDKObject (vENTRY, alphalist->entryField, KEY_UP, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_DOWN, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_NPAGE, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_PPAGE, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_TAB, completeWordCB, alphalist);

   /* Set up the post-process function for the entry field. */
   setCDKEntryPreProcess (alphalist->entryField, preProcessEntryField, alphalist);

   /*
    * Create the scrolling list.  It overlaps the entry field by one line if
    * we are using box-borders.
    */
   tempHeight = getmaxy (alphalist->entryField->win) - BorderOf (alphalist);
   tempWidth = (isFullWidth (width)
		? FULL
		: boxWidth - 1);
   alphalist->scrollField = newCDKScroll (cdkscreen,
					  getbegx (alphalist->win),
					  getbegy (alphalist->entryField->win)
					  + tempHeight,
					  RIGHT,
					  boxHeight - tempHeight,
					  tempWidth,
					  0, list, listSize,
					  NONUMBERS, A_REVERSE,
					  Box, FALSE);
   setCDKScrollULChar (alphalist->scrollField, ACS_LTEE);
   setCDKScrollURChar (alphalist->scrollField, ACS_RTEE);

   /* Setup the key bindings. */
   for (x = 0; x < (int) SIZEOF (bindings); ++x)
      bindCDKObject (vALPHALIST, alphalist, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to);

   registerCDKObject (cdkscreen, vALPHALIST, alphalist);

   return (alphalist);
}
Пример #3
0
/*
 * This creates a button widget.
 */
CDKBUTTON *newCDKButton (CDKSCREEN *cdkscreen,
			 int xplace,
			 int yplace,
			 const char *text,
			 tButtonCallback callback,
			 boolean Box,
			 boolean shadow)
{
   /* *INDENT-EQLS* */
   CDKBUTTON *button    = 0;
   int parentWidth      = getmaxx (cdkscreen->window);
   int parentHeight     = getmaxy (cdkscreen->window);
   int boxWidth         = 0;
   int boxHeight;
   int xpos             = xplace;
   int ypos             = yplace;

   if ((button = newCDKObject (CDKBUTTON, &my_funcs)) == 0)
        return (0);

   setCDKButtonBox (button, Box);
   boxHeight = 1 + 2 * BorderOf (button);

   /* Translate the char * to a chtype. */
   button->info = char2Chtype (text, &button->infoLen, &button->infoPos);
   boxWidth = MAXIMUM (boxWidth, button->infoLen) + 2 * BorderOf (button);

   /* Create the string alignments. */
   button->infoPos = justifyString (boxWidth - 2 * BorderOf (button),
				    button->infoLen, button->infoPos);

   /*
    * Make sure we didn't extend beyond the dimensions of the window.
    */
   boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth);
   boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight);

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* *INDENT-EQLS* Create the button. */
   ScreenOf (button)            = cdkscreen;
   ObjOf (button)->fn           = &my_funcs;
   button->parent               = cdkscreen->window;
   button->win                  = newwin (boxHeight, boxWidth, ypos, xpos);
   button->shadowWin            = (WINDOW *)NULL;
   button->xpos                 = xpos;
   button->ypos                 = ypos;
   button->boxWidth             = boxWidth;
   button->boxHeight            = boxHeight;
   button->callback             = callback;
   ObjOf (button)->inputWindow  = button->win;
   ObjOf (button)->acceptsFocus = TRUE;
   initExitType (button);
   button->shadow               = shadow;

   /* Is the window NULL? */
   if (button->win == (WINDOW *)NULL)
   {
      destroyCDKObject (button);
      return (0);
   }

   keypad (button->win, TRUE);

   /* If a shadow was requested, then create the shadow window. */
   if (shadow)
      button->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);

   /* Register this baby. */
   registerCDKObject (cdkscreen, vBUTTON, button);

   /* Return the button pointer. */
   return (button);
}
Пример #4
0
/*
 * Create a graph widget.
 */
CDKGRAPH *newCDKGraph (CDKSCREEN *cdkscreen,
		       int xplace,
		       int yplace,
		       int height,
		       int width,
		       const char *title,
		       const char *xtitle,
		       const char *ytitle)
{
   /* *INDENT-EQLS* */
   CDKGRAPH *widget     = 0;
   int parentWidth      = getmaxx (cdkscreen->window);
   int parentHeight     = getmaxy (cdkscreen->window);
   int boxWidth         = width;
   int boxHeight        = height;
   int xpos             = xplace;
   int ypos             = yplace;

   if ((widget = newCDKObject (CDKGRAPH, &my_funcs)) == 0)
        return (0);

   setCDKGraphBox (widget, FALSE);

   /* *INDENT-EQLS* */
   boxHeight = setWidgetDimension (parentHeight, height, 3);
   boxWidth  = setWidgetDimension (parentWidth, width, 0);
   boxWidth  = setCdkTitle (ObjOf (widget), title, boxWidth);
   boxHeight += TitleLinesOf (widget);
   boxWidth  = MINIMUM (boxWidth, parentWidth);
   boxHeight = MINIMUM (boxHeight, parentHeight);

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* *INDENT-EQLS* Create the widget pointer. */
   ScreenOf (widget)    = cdkscreen;
   widget->parent       = cdkscreen->window;
   widget->win          = newwin (boxHeight, boxWidth, ypos, xpos);
   widget->boxHeight    = boxHeight;
   widget->boxWidth     = boxWidth;
   widget->minx         = 0;
   widget->maxx         = 0;
   widget->xscale       = 0;
   widget->yscale       = 0;
   widget->count        = 0;
   widget->displayType  = vLINE;

   if (widget->win == 0)
   {
      destroyCDKObject (widget);
      return (0);
   }
   keypad (widget->win, TRUE);

   /* Translate the X Axis title char * to a chtype * */
   if (xtitle != 0)
   {
      widget->xtitle = char2Chtype (xtitle, &widget->xtitleLen, &widget->xtitlePos);
      widget->xtitlePos = justifyString (widget->boxHeight,
					 widget->xtitleLen,
					 widget->xtitlePos);
   }
   else
   {
      widget->xtitle = char2Chtype ("<C></5>X Axis", &widget->xtitleLen, &widget->xtitlePos);
      widget->xtitlePos = justifyString (widget->boxHeight,
					 widget->xtitleLen,
					 widget->xtitlePos);
   }

   /* Translate the Y Axis title char * to a chtype * */
   if (ytitle != 0)
   {
      widget->ytitle = char2Chtype (ytitle, &widget->ytitleLen, &widget->ytitlePos);
      widget->ytitlePos = justifyString (widget->boxWidth,
					 widget->ytitleLen,
					 widget->ytitlePos);
   }
   else
   {
      widget->ytitle = char2Chtype ("<C></5>Y Axis", &widget->ytitleLen, &widget->ytitlePos);
      widget->ytitlePos = justifyString (widget->boxWidth,
					 widget->ytitleLen,
					 widget->ytitlePos);
   }

   widget->graphChar = 0;

   registerCDKObject (cdkscreen, vGRAPH, widget);

   return (widget);
}
Пример #5
0
/*
 * This function creates a new scrolling list widget.
 */
CDKSCROLL *newCDKScroll (CDKSCREEN *cdkscreen,
			 int xplace,
			 int yplace,
			 int splace,
			 int height,
			 int width,
			 const char *title,
			 CDK_CSTRING2 list,
			 int listSize,
			 boolean numbers,
			 chtype highlight,
			 boolean Box,
			 boolean shadow)
{
   /* *INDENT-EQLS* */
   CDKSCROLL *scrollp           = 0;
   int parentWidth              = getmaxx (cdkscreen->window);
   int parentHeight             = getmaxy (cdkscreen->window);
   int boxWidth                 = width;
   int boxHeight                = height;
   int xpos                     = xplace;
   int ypos                     = yplace;
   int scrollAdjust             = 0;
   int x;
   /* *INDENT-OFF* */
   static const struct { int from; int to; } bindings[] = {
		{ CDK_BACKCHAR,	KEY_PPAGE },
		{ CDK_FORCHAR,	KEY_NPAGE },
		{ 'g',		KEY_HOME },
		{ '1',		KEY_HOME },
		{ 'G',		KEY_END },
		{ '<',		KEY_HOME },
		{ '>',		KEY_END },
   };
   /* *INDENT-ON* */

   if ((scrollp = newCDKObject (CDKSCROLL, &my_funcs)) == 0)
   {
      destroyCDKObject (scrollp);
      return (0);
   }

   setCDKScrollBox (scrollp, Box);

   /*
    * If the height is a negative value, the height will
    * be ROWS-height, otherwise, the height will be the
    * given height.
    */
   boxHeight = setWidgetDimension (parentHeight, height, 0);

   /*
    * If the width is a negative value, the width will
    * be COLS-width, otherwise, the width will be the
    * given width.
    */
   boxWidth = setWidgetDimension (parentWidth, width, 0);

   boxWidth = setCdkTitle (ObjOf (scrollp), title, boxWidth);

   /* Set the box height. */
   if (TitleLinesOf (scrollp) > boxHeight)
   {
      boxHeight = (TitleLinesOf (scrollp)
		   + MINIMUM (listSize, 8)
		   + 2 * BorderOf (scrollp));
   }

   /* Adjust the box width if there is a scrollp bar. */
   if ((splace == LEFT) || (splace == RIGHT))
   {
      scrollp->scrollbar = TRUE;
      boxWidth += 1;
   }
   else
   {
      scrollp->scrollbar = FALSE;
   }

   /*
    * Make sure we didn't extend beyond the dimensions of the window.
    */
   scrollp->boxWidth = (boxWidth > parentWidth
			? (parentWidth - scrollAdjust)
			: boxWidth);
   scrollp->boxHeight = (boxHeight > parentHeight
			 ? parentHeight
			 : boxHeight);

   setViewSize (scrollp, listSize);

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, scrollp->boxWidth, scrollp->boxHeight);

   /* Make the scrolling window */
   scrollp->win = newwin (scrollp->boxHeight, scrollp->boxWidth, ypos, xpos);

   /* Is the scrolling window null?? */
   if (scrollp->win == 0)
   {
      destroyCDKObject (scrollp);
      return (0);
   }

   /* Turn the keypad on for the window. */
   keypad (scrollp->win, TRUE);

   /* Create the scrollbar window. */
   if (splace == RIGHT)
   {
      scrollp->scrollbarWin = subwin (scrollp->win,
				      maxViewSize (scrollp), 1,
				      SCREEN_YPOS (scrollp, ypos),
				      xpos + scrollp->boxWidth
				      - BorderOf (scrollp) - 1);
   }
   else if (splace == LEFT)
   {
      scrollp->scrollbarWin = subwin (scrollp->win,
				      maxViewSize (scrollp), 1,
				      SCREEN_YPOS (scrollp, ypos),
				      SCREEN_XPOS (scrollp, xpos));
   }
   else
   {
      scrollp->scrollbarWin = 0;
   }

   /* create the list window */

   scrollp->listWin = subwin (scrollp->win,
			      maxViewSize (scrollp),
			      scrollp->boxWidth
			      - 2 * BorderOf (scrollp) - scrollAdjust,
			      SCREEN_YPOS (scrollp, ypos),
			      SCREEN_XPOS (scrollp, xpos)
			      + (splace == LEFT ? 1 : 0));

   /* *INDENT-EQLS* Set the rest of the variables */
   ScreenOf (scrollp)           = cdkscreen;
   scrollp->parent              = cdkscreen->window;
   scrollp->shadowWin           = 0;
   scrollp->scrollbarPlacement  = splace;
   scrollp->maxLeftChar         = 0;
   scrollp->leftChar            = 0;
   scrollp->highlight           = highlight;
   initExitType (scrollp);
   ObjOf (scrollp)->acceptsFocus = TRUE;
   ObjOf (scrollp)->inputWindow = scrollp->win;
   scrollp->shadow              = shadow;

   setCDKScrollPosition (scrollp, 0);

   /* Create the scrolling list item list and needed variables. */
   if (createCDKScrollItemList (scrollp, numbers, list, listSize) <= 0)
   {
      destroyCDKObject (scrollp);
      return (0);
   }

   /* Do we need to create a shadow? */
   if (shadow)
   {
      scrollp->shadowWin = newwin (scrollp->boxHeight,
				   boxWidth,
				   ypos + 1,
				   xpos + 1);
   }

   /* Setup the key bindings. */
   for (x = 0; x < (int)SIZEOF (bindings); ++x)
      bindCDKObject (vSCROLL,
		     scrollp,
		     (chtype)bindings[x].from,
		     getcCDKBind,
		     (void *)(long)bindings[x].to);

   registerCDKObject (cdkscreen, vSCROLL, scrollp);

   /* Return the scrolling list */
   return scrollp;
}
Пример #6
0
/*
 * This function creates a widget.
 */
CDKUSCALE *newCDKUScale (CDKSCREEN *cdkscreen,
                         int xplace,
                         int yplace,
                         char *title,
                         char *label,
                         chtype fieldAttr,
                         int fieldWidth,
                         unsigned start,
                         unsigned low,
                         unsigned high,
                         unsigned inc,
                         unsigned fastInc,
                         boolean Box,
                         boolean shadow)
{
    CDKUSCALE *widget	= 0;
    int parentWidth	= getmaxx(cdkscreen->window);
    int parentHeight	= getmaxy(cdkscreen->window);
    int boxHeight;
    int boxWidth;
    int horizontalAdjust, oldWidth;
    int xpos		= xplace;
    int ypos		= yplace;
    int x, junk;

    static const struct {
        int from;
        int to;
    } bindings[] = {
        { 'u',		KEY_UP },
        { 'U',		KEY_PPAGE },
        { CDK_BACKCHAR,	KEY_PPAGE },
        { CDK_FORCHAR,	KEY_NPAGE },
        { 'g',		KEY_HOME },
        { '^',		KEY_HOME },
        { 'G',		KEY_END },
        { '$',		KEY_END },
    };

    if ((widget = newCDKObject(CDKUSCALE, &my_funcs)) == 0)
        return (0);

    setCDKUScaleBox (widget, Box);

    boxHeight		= (BorderOf(widget) * 2) + 1;
    boxWidth		= fieldWidth + 2*BorderOf(widget);

    /* Set some basic values of the widget's data field. */
    widget->label	= 0;
    widget->labelLen	= 0;
    widget->labelWin	= 0;

    /*
     * If the fieldWidth is a negative value, the fieldWidth will
     * be COLS-fieldWidth, otherwise, the fieldWidth will be the
     * given width.
     */
    fieldWidth = setWidgetDimension (parentWidth, fieldWidth, 0);
    boxWidth = fieldWidth + 2*BorderOf(widget);

    /* Translate the label char *pointer to a chtype pointer. */
    if (label != 0)
    {
        widget->label	= char2Chtype (label, &widget->labelLen, &junk);
        boxWidth		= widget->labelLen + fieldWidth + 2;
    }

    oldWidth = boxWidth;
    boxWidth = setCdkTitle(ObjOf(widget), title, boxWidth);
    horizontalAdjust = (boxWidth - oldWidth) / 2;

    boxHeight += TitleLinesOf(widget);

    /*
     * Make sure we didn't extend beyond the dimensions of the window.
     */
    boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth);
    boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight);
    fieldWidth = (fieldWidth > (boxWidth - widget->labelLen - 2*BorderOf(widget))
                  ? (boxWidth - widget->labelLen - 2*BorderOf(widget))
                  : fieldWidth);

    /* Rejustify the x and y positions if we need to. */
    alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

    /* Make the widget's window. */
    widget->win = newwin (boxHeight, boxWidth, ypos, xpos);

    /* Is the main window null??? */
    if (widget->win == 0)
    {
        destroyCDKObject(widget);
        return (0);
    }

    /* Create the widget's label window. */
    if (widget->label != 0)
    {
        widget->labelWin = subwin (widget->win,
                                   1, widget->labelLen,
                                   ypos + TitleLinesOf(widget) + BorderOf(widget),
                                   xpos + horizontalAdjust + BorderOf(widget));
        if (widget->labelWin == 0)
        {
            destroyCDKObject(widget);
            return (0);
        }
    }

    /* Create the widget's data field window. */
    widget->fieldWin = subwin (widget->win,
                               1, fieldWidth,
                               ypos + TitleLinesOf(widget) + BorderOf(widget),
                               xpos + widget->labelLen + horizontalAdjust + BorderOf(widget));
    if (widget->fieldWin == 0)
    {
        destroyCDKObject(widget);
        return (0);
    }
    keypad (widget->fieldWin, TRUE);
    keypad (widget->win, TRUE);

    /* Create the widget's data field. */
    ScreenOf(widget)		= cdkscreen;
    widget->parent		= cdkscreen->window;
    widget->shadowWin		= 0;
    widget->boxWidth		= boxWidth;
    widget->boxHeight		= boxHeight;
    widget->fieldWidth		= fieldWidth;
    widget->fieldAttr		= (chtype)fieldAttr;
    widget->current		= low;
    widget->low			= low;
    widget->high			= high;
    widget->current		= start;
    widget->inc			= inc;
    widget->fastinc		= fastInc;
    initExitType(widget);
    ObjOf(widget)->acceptsFocus	= TRUE;
    ObjOf(widget)->inputWindow	= widget->win;
    widget->shadow		= shadow;

    /* Do we want a shadow??? */
    if (shadow)
    {
        widget->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
        if (widget->shadowWin == 0)
        {
            destroyCDKObject(widget);
            return (0);
        }
    }

    /* Setup the key bindings. */
    for (x = 0; x < (int) SIZEOF(bindings); ++x)
        bindCDKObject (vUSCALE, widget, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to);

    registerCDKObject (cdkscreen, vUSCALE, widget);

    return (widget);
}