Ejemplo n.º 1
0
/*
 * This sets the information within the button.
 */
void setCDKButtonMessage (CDKBUTTON *button, const char *info)
{
   /* Clean out the old message. */
   freeChtype (button->info);
   button->infoPos = 0;
   button->infoLen = 0;

   /* Copy in the new message. */

   button->info = char2Chtype (info, &button->infoLen, &button->infoPos);
   button->infoPos = justifyString (button->boxWidth - 2 * BorderOf (button),
				    button->infoLen, button->infoPos);

   /* Redraw the button widget. */
   eraseCDKButton (button);
   drawCDKButton (button, ObjOf (button)->box);
}
Ejemplo n.º 2
0
vector<string> Solution::fullJustify(vector<string> &A, int B) {
    vector<string> result;
    
    //cout<<"size of input "<<A.size()<<endl;
    // Edge case
    if(A.size() == 0 || (A.size() == 1 && A[0] == "")) { return result; }
    
    int startPos = 0;
    int length = 0;
    
    for(int i = 0; i < A.size(); i++) {
        //cout<<"startPos = "<<startPos<<" i = "<<i<<" length = "<<length<<endl;
        length += A[i].length();
        // Check if length + min padding has exceeded
        if(length + (i-startPos) > B) {
            // Construct a subvector here
            vector<string>::const_iterator first = A.begin() + startPos;
            vector<string>::const_iterator last = A.begin() + i;
            vector<string> subsetStrings(first, last);
            
            // find length of just the strings we are trying to merge
            int stringLength = length - A[i].length();
            result.push_back(justifyString(subsetStrings, stringLength, B));
            
            length = A[i].length();
            startPos = i;
        }
    }
    
    // Last line justification
    if (startPos < A.size()) {
        string lastString = A[startPos++];
        while (startPos < A.size()) {
            //cout<<"startPos = "<<startPos<<" lastString = "<<lastString<<endl;
            lastString += " " + A[startPos++];
        }
        //cout<<"while loop ended with string "<<lastString;
        int paddingLength = B-lastString.length();
        //cout<<"padding length = "<<paddingLength;
        string padding(paddingLength, ' ');
        lastString += padding;
    
        result.push_back(lastString);
    }
    return result;
}
Ejemplo n.º 3
0
static boolean allocListItem (CDKSCROLL *scrollp,
			      int which,
			      char **work,
			      size_t * used,
			      int number,
			      const char *value)
{
   if (number > 0)
   {
      size_t need = NUMBER_LEN (value);
      if (need > *used)
      {
	 *used = ((need + 2) * 2);
	 if (*work == 0)
	 {
	    if ((*work = (char *)malloc (*used)) == 0)
	       return FALSE;
	 }
	 else
	 {
	    if ((*work = (char *)realloc (*work, *used)) == 0)
	       return FALSE;
	 }
      }
      sprintf (*work, NUMBER_FMT, number, value);
      value = *work;
   }

   if ((scrollp->item[which] = char2Chtype (value,
					    &(scrollp->itemLen[which]),
					    &(scrollp->itemPos[which]))) == 0)
      return FALSE;

   scrollp->itemPos[which] = justifyString (scrollp->boxWidth,
					    scrollp->itemLen[which],
					    scrollp->itemPos[which]);

   return TRUE;
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
Archivo: fscale.c Proyecto: dyne/MuSE
/*
 * This function creates a scale widget.
 */
CDKFSCALE *newCDKFScale (CDKSCREEN *cdkscreen, int xplace, int yplace, char *title, char *label, chtype fieldAttr, int fieldWidth, float start, float low, float high, float inc, float fastinc, int digits, boolean Box, boolean shadow)
{
   /* Declare local variables. */
   CDKFSCALE *scale	= newCDKObject(CDKFSCALE, &my_funcs);
   chtype *holder	= 0;
   int parentWidth	= getmaxx(cdkscreen->window) - 1;
   int parentHeight	= getmaxy(cdkscreen->window) - 1;
   int boxHeight	= 3;
   int boxWidth		= fieldWidth + 2;
   int maxWidth		= INT_MIN;
   int horizontalAdjust = 0;
   int xpos		= xplace;
   int ypos		= yplace;
   char **temp		= 0;
   int x, len, junk, junk2;

   /* Set some basic values of the scale field. */
   scale->label		= 0;
   scale->labelLen	= 0;
   scale->labelWin	= 0;
   scale->titleLines	= 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;

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

   /* Translate the char * items to chtype * */
   if (title != 0)
   {
      temp = CDKsplitString (title, '\n');
      scale->titleLines = CDKcountStrings (temp);

      /* We need to determine the widest title line. */
      for (x=0; x < scale->titleLines; x++)
      {
	 holder = char2Chtype (temp[x], &len, &junk2);
	 maxWidth = MAXIMUM (maxWidth, len);
	 freeChtype (holder);
      }

      /*
       * If one of the title lines is wider than the field and the label,
       * the box width will expand to accomodate.
       */
       if (maxWidth > boxWidth)
       {
	  horizontalAdjust = (int)((maxWidth - boxWidth) / 2) + 1;
	  boxWidth = maxWidth + 2;
       }

      /* For each line in the title, convert from char * to chtype * */
      for (x=0; x < scale->titleLines; x++)
      {
	 scale->title[x]	= char2Chtype (temp[x], &scale->titleLen[x], &scale->titlePos[x]);
	 scale->titlePos[x]	= justifyString (boxWidth, scale->titleLen[x], scale->titlePos[x]);
      }
      CDKfreeStrings(temp);
   }
   else
   {
      /* No title? Set the required variables. */
      scale->titleLines = 0;
   }
   boxHeight += scale->titleLines;

  /*
   * 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 - scale->labelLen - 2) ? (boxWidth - scale->labelLen - 2) : fieldWidth);

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

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

   /* Is the main window null??? */
   if (scale->win == 0)
   {
      freeChtype (scale->label);
      free (scale);

      /* Return a null pointer. */
      return (0);
   }

   /* Create the scale label window. */
   if (scale->label != 0)
   {
      scale->labelWin = subwin (scale->win, 1,
				scale->labelLen + 2,
				ypos + scale->titleLines + 1,
				xpos + horizontalAdjust + 1);
   }

   /* Create the scale field window. */
   scale->fieldWin = subwin (scale->win, 1, fieldWidth,
				ypos + scale->titleLines + 1,
				xpos + scale->labelLen + horizontalAdjust + 1);
   keypad (scale->fieldWin, TRUE);
   keypad (scale->win, TRUE);

   /* Create the scale field. */
   ScreenOf(scale)		= cdkscreen;
   ObjOf(scale)->box		= Box;
   scale->parent		= cdkscreen->window;
   scale->shadowWin		= 0;
   scale->boxWidth		= boxWidth;
   scale->boxHeight		= boxHeight;
   scale->fieldWidth		= fieldWidth;
   scale->fieldAttr		= (chtype)fieldAttr;
   scale->current		= low;
   scale->low			= low;
   scale->high			= high;
   scale->current		= start;
   scale->inc			= inc;
   scale->fastinc		= fastinc;
   scale->digits		= digits;
   scale->exitType		= vNEVER_ACTIVATED;
   scale->shadow		= shadow;
   scale->preProcessFunction	= 0;
   scale->preProcessData	= 0;
   scale->postProcessFunction	= 0;
   scale->postProcessData	= 0;
   scale->ULChar		= ACS_ULCORNER;
   scale->URChar		= ACS_URCORNER;
   scale->LLChar		= ACS_LLCORNER;
   scale->LRChar		= ACS_LRCORNER;
   scale->HChar			= ACS_HLINE;
   scale->VChar			= ACS_VLINE;
   scale->BoxAttrib		= A_NORMAL;

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

   /* Clean the key bindings. */
   cleanCDKObjectBindings (vFSCALE, scale);

   /* Register this baby. */
   registerCDKObject (cdkscreen, vFSCALE, scale);

   /* Return the pointer. */
   return (scale);
}
Ejemplo n.º 7
0
Archivo: dialog.c Proyecto: dyne/MuSE
/*
 * This function creates a dialog widget.
 */
CDKDIALOG *newCDKDialog (CDKSCREEN *cdkscreen, int xplace, int yplace, char **mesg, int rows, char **buttonLabel, int buttonCount, chtype highlight, boolean separator, boolean Box, boolean shadow)
{
   /* Declare local variables. */
   CDKDIALOG *dialog	= newCDKObject(CDKDIALOG, &my_funcs);
   int boxWidth		= MIN_DIALOG_WIDTH;
   int boxHeight	= rows + 3 + separator;
   int maxmessagewidth	= -1;
   int buttonwidth	= 0;
   int xpos		= xplace;
   int ypos		= yplace;
   int temp		= 0;
   int buttonadj	= 0;
   int x		= 0;

   /* Translate the char * message to a chtype * */
   for (x=0; x < rows; x++)
   {
      dialog->info[x]	= char2Chtype (mesg[x], &dialog->infoLen[x], &dialog->infoPos[x]);
      maxmessagewidth	= MAXIMUM(maxmessagewidth, dialog->infoLen[x]);
   }

   /* Translate the button label char * to a chtype * */
   for (x = 0; x < buttonCount; x++)
   {
      dialog->buttonLabel[x]	= char2Chtype (buttonLabel[x], &dialog->buttonLen[x], &temp);
      buttonwidth		+= dialog->buttonLen[x] + 1;
   }
   buttonwidth--;

   /* Determine the final dimensions of the box. */
   boxWidth	= MAXIMUM(boxWidth, maxmessagewidth);
   boxWidth	= MAXIMUM(boxWidth, buttonwidth);
   boxWidth	= boxWidth + 4;

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

   /* Set up the dialog box attributes. */
   ScreenOf(dialog)		= cdkscreen;
   dialog->parent		= cdkscreen->window;
   dialog->win			= newwin (boxHeight, boxWidth, ypos, xpos);
   dialog->shadowWin		= 0;
   dialog->buttonCount		= buttonCount;
   dialog->currentButton	= 0;
   dialog->messageRows		= rows;
   dialog->boxHeight		= boxHeight;
   dialog->boxWidth		= boxWidth;
   dialog->highlight		= highlight;
   dialog->separator		= separator;
   dialog->exitType		= vNEVER_ACTIVATED;
   ObjOf(dialog)->box		= Box;
   dialog->shadow		= shadow;
   dialog->ULChar		= ACS_ULCORNER;
   dialog->URChar		= ACS_URCORNER;
   dialog->LLChar		= ACS_LLCORNER;
   dialog->LRChar		= ACS_LRCORNER;
   dialog->HChar		= ACS_HLINE;
   dialog->VChar		= ACS_VLINE;
   dialog->BoxAttrib		= A_NORMAL;
   dialog->preProcessFunction	= 0;
   dialog->preProcessData	= 0;
   dialog->postProcessFunction	= 0;
   dialog->postProcessData	= 0;

   /* If we couldn't create the window, we should return a null value. */
   if (dialog->win == 0)
   {
      /* Couldn't create the window. Clean up used memory. */
      for (x=0; x < dialog->messageRows ; x++)
      {
	 freeChtype (dialog->info[x]);
      }
      for (x=0; x < dialog->buttonCount; x++)
      {
	 freeChtype (dialog->buttonLabel[x]);
      }

      /* Remove the memory used by the dialog pointer. */
      free (dialog);

      /* Return a null dialog box. */
      return (0);
   }
   keypad (dialog->win, TRUE);

   /* Find the button positions. */
   buttonadj = ((int)((boxWidth-buttonwidth)/2));
   for (x = 0; x < buttonCount; x++)
   {
      dialog->buttonPos[x]	= buttonadj;
      buttonadj			= buttonadj + dialog->buttonLen[x] + 1;
   }

   /* Create the string alignments. */
   for (x=0; x < rows; x++)
   {
      dialog->infoPos[x] = justifyString (boxWidth, dialog->infoLen[x], dialog->infoPos[x]);
   }

   /* Was there a shadow? */
   if (shadow)
   {
      dialog->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
   }

   /* Empty the key bindings. */
   cleanCDKObjectBindings (vDIALOG, dialog);

   /* Register this baby. */
   registerCDKObject (cdkscreen, vDIALOG, dialog);

   /* Return the dialog box pointer. */
   return (dialog);
}