Annotation of othersrc/dist/cdk/histogram.c, revision 1.1.1.1

1.1       garbled     1: #include <cdk.h>
                      2: 
                      3: /*
                      4:  * $Author: tom $
                      5:  * $Date: 2000/02/18 23:20:55 $
                      6:  * $Revision: 1.60 $
                      7:  */
                      8: 
                      9: DeclareCDKObjects(my_funcs,Histogram);
                     10: 
                     11: /*
                     12:  * This creates a histogram widget.
                     13:  */
                     14: CDKHISTOGRAM *newCDKHistogram (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, int orient, char *title, boolean Box, boolean shadow)
                     15: {
                     16:    /* Declare local variables. */
                     17:    CDKHISTOGRAM *histogram     = newCDKObject(CDKHISTOGRAM, &my_funcs);
                     18:    int parentWidth             = getmaxx(cdkscreen->window);
                     19:    int parentHeight            = getmaxy(cdkscreen->window);
                     20:    int boxWidth                        = width;
                     21:    int boxHeight               = height;
                     22:    int xpos                    = xplace;
                     23:    int ypos                    = yplace;
                     24:    int oldWidth                        = 0;
                     25:    int oldHeight               = 0;
                     26:    char **temp                 = 0;
                     27:    int x;
                     28: 
                     29:   /*
                     30:    * If the height is a negative value, the height will
                     31:    * be ROWS-height, otherwise, the height will be the
                     32:    * given height.
                     33:    */
                     34:    boxHeight = setWidgetDimension (parentHeight, height, 2);
                     35:    oldHeight = boxHeight;
                     36: 
                     37:   /*
                     38:    * If the width is a negative value, the width will
                     39:    * be COLS-width, otherwise, the width will be the
                     40:    * given width.
                     41:    */
                     42:    boxWidth = setWidgetDimension (parentWidth, width, 0);
                     43:    oldWidth = boxWidth;
                     44: 
                     45:    /* Translate the char * items to chtype * */
                     46:    if (title != 0)
                     47:    {
                     48:       /* We need to split the title on \n. */
                     49:       temp = CDKsplitString (title, '\n');
                     50:       histogram->titleLines = CDKcountStrings (temp);
                     51: 
                     52:       /* For each line in the title, convert from char * to chtype * */
                     53:       for (x=0; x < histogram->titleLines; x++)
                     54:       {
                     55:         histogram->title[x]    = char2Chtype (temp[x], &histogram->titleLen[x], &histogram->titlePos[x]);
                     56:         histogram->titlePos[x] = justifyString (boxWidth, histogram->titleLen[x], histogram->titlePos[x]);
                     57:       }
                     58: 
                     59:       CDKfreeStrings(temp);
                     60:    }
                     61:    else
                     62:    {
                     63:       /* No title? Set the required variables. */
                     64:       histogram->titleLines = 0;
                     65:    }
                     66: 
                     67:    /* Increment the height by the number of lines in the title. */
                     68:    boxHeight += histogram->titleLines;
                     69: 
                     70:   /*
                     71:    * Make sure we didn't extend beyond the dimensions of the window.
                     72:    */
                     73:    boxWidth = MINIMUM (boxWidth, parentWidth);
                     74:    boxHeight = MINIMUM (boxHeight, parentHeight);
                     75: 
                     76:    /* Rejustify the x and y positions if we need to. */
                     77:    alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);
                     78: 
                     79:    /* Create the histogram pointer. */
                     80:    ScreenOf(histogram)         = cdkscreen;
                     81:    histogram->parent           = cdkscreen->window;
                     82:    histogram->win              = newwin (boxHeight + !!shadow, boxWidth + !!shadow, ypos, xpos);
                     83:    histogram->boxWidth         = boxWidth;
                     84:    histogram->boxHeight                = boxHeight;
                     85:    histogram->fieldWidth       = boxWidth-2;
                     86:    histogram->fieldHeight      = boxHeight-histogram->titleLines-2;
                     87:    histogram->orient           = orient;
                     88:    histogram->shadow           = shadow;
                     89:    histogram->ULChar           = ACS_ULCORNER;
                     90:    histogram->URChar           = ACS_URCORNER;
                     91:    histogram->LLChar           = ACS_LLCORNER;
                     92:    histogram->LRChar           = ACS_LRCORNER;
                     93:    histogram->HChar            = ACS_HLINE;
                     94:    histogram->VChar            = ACS_VLINE;
                     95:    histogram->BoxAttrib                = A_NORMAL;
                     96: 
                     97:    /* Is the window null. */
                     98:    if (histogram->win == 0)
                     99:    {
                    100:       /* Clean up any memory used. */
                    101:       free (histogram);
                    102: 
                    103:       /* Return a null pointer. */
                    104:       return (0);
                    105:    }
                    106:    keypad (histogram->win, TRUE);
                    107:    leaveok (histogram->win, TRUE);
                    108: 
                    109:    /* Set up some default values. */
                    110:    histogram->filler   = '#' | A_REVERSE;
                    111:    histogram->statsAttr = A_NORMAL;
                    112:    histogram->statsPos = TOP;
                    113:    histogram->viewType = vREAL;
                    114:    histogram->high     = 0;
                    115:    histogram->low      = 0;
                    116:    histogram->value    = 0;
                    117:    histogram->lowx     = 0;
                    118:    histogram->lowy     = 0;
                    119:    histogram->highx    = 0;
                    120:    histogram->highy    = 0;
                    121:    histogram->curx     = 0;
                    122:    histogram->cury     = 0;
                    123:    histogram->lowString = 0;
                    124:    histogram->highString = 0;
                    125:    histogram->curString = 0;
                    126:    ObjOf(histogram)->box = Box;
                    127: 
                    128:    /* Register this baby. */
                    129:    registerCDKObject (cdkscreen, vHISTOGRAM, histogram);
                    130: 
                    131:    /* Return this thing. */
                    132:    return (histogram);
                    133: }
                    134: 
                    135: /*
                    136:  * This was added for the builder.
                    137:  */
                    138: void activateCDKHistogram (CDKHISTOGRAM *histogram, chtype *actions GCC_UNUSED)
                    139: {
                    140:    drawCDKHistogram (histogram, ObjOf(histogram)->box);
                    141: }
                    142: 
                    143: /*
                    144:  * This sets various histogram attributes.
                    145:  */
                    146: void setCDKHistogram (CDKHISTOGRAM *histogram, EHistogramDisplayType viewType, int statsPos, chtype statsAttr, int low, int high, int value, chtype filler, boolean Box)
                    147: {
                    148:    setCDKHistogramDisplayType (histogram, viewType);
                    149:    setCDKHistogramStatsPos (histogram, statsPos);
                    150:    setCDKHistogramValue (histogram, low, high, value);
                    151:    setCDKHistogramFillerChar (histogram, filler);
                    152:    setCDKHistogramStatsAttr (histogram, statsAttr);
                    153:    setCDKHistogramBox (histogram, Box);
                    154: }
                    155: 
                    156: /*
                    157:  * This sets the values for the histogram.
                    158:  */
                    159: void setCDKHistogramValue (CDKHISTOGRAM *histogram, int low, int high, int value)
                    160: {
                    161:    /* Declare local variables. */
                    162:    char string[100];
                    163:    int len;
                    164: 
                    165:    /* We should error check the information we have. */
                    166:    histogram->low      = (low <= high ? low : 0);
                    167:    histogram->high     = (low <= high ? high : 0);
                    168:    histogram->value    = (low <= value && value <= high ? value : 0);
                    169: 
                    170:    /* Determine the percentage of the given value. */
                    171:    histogram->percent  = (histogram->high == 0 ? 0 : ((float)histogram->value / (float)histogram->high));
                    172: 
                    173:    /* Determine the size of the histogram bar. */
                    174:    if (histogram->orient == VERTICAL)
                    175:    {
                    176:       histogram->barSize = (int)(histogram->percent * (float)histogram->fieldHeight);
                    177:    }
                    178:    else
                    179:    {
                    180:       histogram->barSize = (int)(histogram->percent * (float)histogram->fieldWidth);
                    181:    }
                    182: 
                    183:   /*
                    184:    * We have a number of variables which determine the personality of
                    185:    * the histogram. We have to go through each one methodically, and
                    186:    * set them correctly. This section does this.
                    187:    */
                    188:    if (histogram->viewType != vNONE)
                    189:    {
                    190:       if (histogram->orient == VERTICAL)
                    191:       {
                    192:         if (histogram->statsPos == LEFT || histogram->statsPos == BOTTOM)
                    193:         {
                    194:            /* Free the space used by the character strings. */
                    195:            freeChar (histogram->lowString);
                    196:            freeChar (histogram->highString);
                    197:            freeChar (histogram->curString);
                    198: 
                    199:            /* Set the low label attributes. */
                    200:            sprintf (string, "%d", histogram->low);
                    201:            len                         = (int)strlen (string);
                    202:            histogram->lowString        = copyChar (string);
                    203:            histogram->lowx             = 1;
                    204:            histogram->lowy             = histogram->boxHeight - len - 1;
                    205: 
                    206:            /* Set the high label attributes. */
                    207:            sprintf (string, "%d", histogram->high);
                    208:            histogram->highString       = copyChar (string);
                    209:            histogram->highx            = 1;
                    210:            histogram->highy            = histogram->titleLines + 1;
                    211: 
                    212:            /* Set the current value attributes. */
                    213:            if (histogram->viewType == vPERCENT)
                    214:            {
                    215:               sprintf (string, "%3.1f%%", (float) (histogram->percent * 100));
                    216:            }
                    217:            else if (histogram->viewType == vFRACTION)
                    218:            {
                    219:               sprintf (string, "%d/%d", histogram->value, histogram->high);
                    220:            }
                    221:            else
                    222:            {
                    223:               sprintf (string, "%d", histogram->value);
                    224:            }
                    225:            len                         = (int)strlen (string);
                    226:            histogram->curString        = copyChar (string);
                    227:            histogram->curx             = 1;
                    228:            histogram->cury             = ((histogram->fieldHeight - len) / 2) + histogram->titleLines + 1;
                    229:         }
                    230:         else if (histogram->statsPos == CENTER)
                    231:         {
                    232:            /* Set the character strings correctly. */
                    233:            freeChar (histogram->lowString);
                    234:            freeChar (histogram->highString);
                    235:            freeChar (histogram->curString);
                    236: 
                    237:            /* Set the low label attributes. */
                    238:            sprintf (string, "%d", histogram->low);
                    239:            len                         = (int)strlen (string);
                    240:            histogram->lowString        = copyChar (string);
                    241:            histogram->lowx             = (histogram->fieldWidth/2) + 1;
                    242:            histogram->lowy             = histogram->boxHeight - len - 1;
                    243: 
                    244:            /* Set the high label attributes. */
                    245:            sprintf (string, "%d", histogram->high);
                    246:            histogram->highString       = copyChar (string);
                    247:            histogram->highx            = (histogram->fieldWidth/2) + 1;
                    248:            histogram->highy            = histogram->titleLines + 1;
                    249: 
                    250:            /* Set the stats label attributes. */
                    251:            if (histogram->viewType == vPERCENT)
                    252:            {
                    253:               sprintf (string, "%3.2f%%", (float) (histogram->percent * 100));
                    254:            }
                    255:            else if (histogram->viewType == vFRACTION)
                    256:            {
                    257:               sprintf (string, "%d/%d", histogram->value, histogram->high);
                    258:            }
                    259:            else
                    260:            {
                    261:               sprintf (string, "%d", histogram->value);
                    262:            }
                    263:            len                         = (int)strlen (string);
                    264:            histogram->curString        = copyChar (string);
                    265:            histogram->curx             = (histogram->fieldWidth/2) + 1;
                    266:            histogram->cury             = ((histogram->fieldHeight - len)/2) + histogram->titleLines + 1;
                    267:         }
                    268:         else if (histogram->statsPos == RIGHT || histogram->statsPos == TOP)
                    269:         {
                    270:            /* Set the character strings correctly. */
                    271:            freeChar (histogram->lowString);
                    272:            freeChar (histogram->highString);
                    273:            freeChar (histogram->curString);
                    274: 
                    275:            /* Set the low label attributes. */
                    276:            sprintf (string, "%d", histogram->low);
                    277:            len                         = (int)strlen (string);
                    278:            histogram->lowString        = copyChar (string);
                    279:            histogram->lowx             = histogram->fieldWidth;
                    280:            histogram->lowy             = histogram->boxHeight - len - 1;
                    281: 
                    282:            /* Set the high label attributes. */
                    283:            sprintf (string, "%d", histogram->high);
                    284:            histogram->highString       = copyChar (string);
                    285:            histogram->highx            = histogram->fieldWidth;
                    286:            histogram->highy            = histogram->titleLines + 1;
                    287: 
                    288:            /* Set the stats label attributes. */
                    289:            if (histogram->viewType == vPERCENT)
                    290:            {
                    291:               sprintf (string, "%3.2f%%", (float) (histogram->percent * 100));
                    292:            }
                    293:            else if (histogram->viewType == vFRACTION)
                    294:            {
                    295:               sprintf (string, "%d/%d", histogram->value, histogram->high);
                    296:            }
                    297:            else
                    298:            {
                    299:               sprintf (string, "%d", histogram->value);
                    300:            }
                    301:            len                         = (int)strlen (string);
                    302:            histogram->curString        = copyChar (string);
                    303:            histogram->curx             = histogram->fieldWidth;
                    304:            histogram->cury             = ((histogram->fieldHeight - len)/2) + histogram->titleLines + 1;
                    305:         }
                    306:       }
                    307:       else
                    308:       {
                    309:         /* Alignment is HORIZONTAL. */
                    310:         if (histogram->statsPos == TOP || histogram->statsPos == RIGHT)
                    311:         {
                    312:            /* Set the character strings correctly. */
                    313:            freeChar (histogram->lowString);
                    314:            freeChar (histogram->highString);
                    315:            freeChar (histogram->curString);
                    316: 
                    317:            /* Set the low label attributes. */
                    318:            sprintf (string, "%d", histogram->low);
                    319:            histogram->lowString        = copyChar (string);
                    320:            histogram->lowx             = 1;
                    321:            histogram->lowy             = histogram->titleLines + 1;
                    322: 
                    323:            /* Set the high label attributes. */
                    324:            sprintf (string, "%d", histogram->high);
                    325:            len                         = (int)strlen(string);
                    326:            histogram->highString       = copyChar (string);
                    327:            histogram->highx            = histogram->boxWidth - len - 1;
                    328:            histogram->highy            = histogram->titleLines + 1;
                    329: 
                    330:            /* Set the stats label attributes. */
                    331:            if (histogram->viewType == vPERCENT)
                    332:            {
                    333:               sprintf (string, "%3.1f%%", (float) (histogram->percent * 100));
                    334:            }
                    335:            else if (histogram->viewType == vFRACTION)
                    336:            {
                    337:               sprintf (string, "%d/%d", histogram->value, histogram->high);
                    338:            }
                    339:            else
                    340:            {
                    341:               sprintf (string, "%d", histogram->value);
                    342:            }
                    343:            len                         = (int)strlen(string);
                    344:            histogram->curString        = copyChar (string);
                    345:            histogram->curx             = (histogram->fieldWidth - len)/2 + 1;
                    346:            histogram->cury             = histogram->titleLines + 1;
                    347:         }
                    348:         else if (histogram->statsPos == CENTER)
                    349:         {
                    350:            /* Set the character strings correctly. */
                    351:            freeChar (histogram->lowString);
                    352:            freeChar (histogram->highString);
                    353:            freeChar (histogram->curString);
                    354: 
                    355:            /* Set the low label attributes. */
                    356:            sprintf (string, "%d", histogram->low);
                    357:            histogram->lowString        = copyChar (string);
                    358:            histogram->lowx             = 1;
                    359:            histogram->lowy             = (histogram->fieldHeight/2) + histogram->titleLines + 1;
                    360: 
                    361:            /* Set the high label attributes. */
                    362:            sprintf (string, "%d", histogram->high);
                    363:            len                         = (int)strlen (string);
                    364:            histogram->highString       = copyChar (string);
                    365:            histogram->highx            = histogram->boxWidth - len - 1;
                    366:            histogram->highy            = (histogram->fieldHeight/2) + histogram->titleLines + 1;
                    367: 
                    368:            /* Set the stats label attributes. */
                    369:            if (histogram->viewType == vPERCENT)
                    370:            {
                    371:               sprintf (string, "%3.1f%%", (float) (histogram->percent * 100));
                    372:            }
                    373:            else if (histogram->viewType == vFRACTION)
                    374:            {
                    375:               sprintf (string, "%d/%d", histogram->value, histogram->high);
                    376:            }
                    377:            else
                    378:            {
                    379:               sprintf (string, "%d", histogram->value);
                    380:            }
                    381:            len                         = (int)strlen (string);
                    382:            histogram->curString        = copyChar (string);
                    383:            histogram->curx             = (histogram->fieldWidth - len)/2 + 1;
                    384:            histogram->cury             = (histogram->fieldHeight/2) + histogram->titleLines + 1;
                    385:         }
                    386:         else if (histogram->statsPos == BOTTOM || histogram->statsPos == LEFT)
                    387:         {
                    388:            /* Set the character strings correctly. */
                    389:            freeChar (histogram->lowString);
                    390:            freeChar (histogram->highString);
                    391:            freeChar (histogram->curString);
                    392: 
                    393:            /* Set the low label attributes. */
                    394:            sprintf (string, "%d", histogram->low);
                    395:            histogram->lowString        = copyChar (string);
                    396:            histogram->lowx             = 1;
                    397:            histogram->lowy             = histogram->boxHeight - 2;
                    398: 
                    399:            /* Set the high label attributes. */
                    400:            sprintf (string, "%d", histogram->high);
                    401:            len                         = (int)strlen (string);
                    402:            histogram->highString       = copyChar (string);
                    403:            histogram->highx            = histogram->boxWidth - len - 1;
                    404:            histogram->highy            = histogram->boxHeight - 2;
                    405: 
                    406:            /* Set the stats label attributes. */
                    407:            if (histogram->viewType == vPERCENT)
                    408:            {
                    409:               sprintf (string, "%3.1f%%", (float) (histogram->percent * 100));
                    410:            }
                    411:            else if (histogram->viewType == vFRACTION)
                    412:            {
                    413:               sprintf (string, "%d/%d", histogram->value, histogram->high);
                    414:            }
                    415:            else
                    416:            {
                    417:               sprintf (string, "%d", histogram->value);
                    418:            }
                    419:            histogram->curString        = copyChar (string);
                    420:            histogram->curx             = (histogram->fieldWidth - len)/2 + 1;
                    421:            histogram->cury             = histogram->boxHeight - 2;
                    422:         }
                    423:       }
                    424:    }
                    425: }
                    426: int getCDKHistogramValue (CDKHISTOGRAM *histogram)
                    427: {
                    428:    return histogram->value;
                    429: }
                    430: int getCDKHistogramLowValue (CDKHISTOGRAM *histogram)
                    431: {
                    432:    return histogram->low;
                    433: }
                    434: int getCDKHistogramHighValue (CDKHISTOGRAM *histogram)
                    435: {
                    436:    return histogram->high;
                    437: }
                    438: 
                    439: /*
                    440:  * This sets the histogram display type.
                    441:  */
                    442: void setCDKHistogramDisplayType (CDKHISTOGRAM *histogram, EHistogramDisplayType viewType)
                    443: {
                    444:    histogram->viewType = viewType;
                    445: }
                    446: EHistogramDisplayType getCDKHistogramViewType (CDKHISTOGRAM *histogram)
                    447: {
                    448:    return histogram->viewType;
                    449: }
                    450: 
                    451: /*
                    452:  * This sets the position of the statistics information.
                    453:  */
                    454: void setCDKHistogramStatsPos (CDKHISTOGRAM *histogram, int statsPos)
                    455: {
                    456:    histogram->statsPos = statsPos;
                    457: }
                    458: int getCDKHistogramStatsPos (CDKHISTOGRAM *histogram)
                    459: {
                    460:    return histogram->statsPos;
                    461: }
                    462: 
                    463: /*
                    464:  * This sets the attribute of the statistics.
                    465:  */
                    466: void setCDKHistogramStatsAttr (CDKHISTOGRAM *histogram, chtype statsAttr)
                    467: {
                    468:    histogram->statsAttr = statsAttr;
                    469: }
                    470: chtype getCDKHistogramStatsAttr (CDKHISTOGRAM *histogram)
                    471: {
                    472:    return histogram->statsAttr;
                    473: }
                    474: 
                    475: /*
                    476:  * This sets the character to use when drawing the histogram.
                    477:  */
                    478: void setCDKHistogramFillerChar (CDKHISTOGRAM *histogram, chtype character)
                    479: {
                    480:    histogram->filler = character;
                    481: }
                    482: chtype getCDKHistogramFillerChar (CDKHISTOGRAM *histogram)
                    483: {
                    484:    return histogram->filler;
                    485: }
                    486: 
                    487: /*
                    488:  * This sets the histogram box attribute.
                    489:  */
                    490: void setCDKHistogramBox (CDKHISTOGRAM *histogram, boolean Box)
                    491: {
                    492:    ObjOf(histogram)->box = Box;
                    493: }
                    494: boolean getCDKHistogramBox (CDKHISTOGRAM *histogram)
                    495: {
                    496:    return ObjOf(histogram)->box;
                    497: }
                    498: 
                    499: /*
                    500:  * These functions set the drawing characters of the widget.
                    501:  */
                    502: void setCDKHistogramULChar (CDKHISTOGRAM *histogram, chtype character)
                    503: {
                    504:    histogram->ULChar = character;
                    505: }
                    506: void setCDKHistogramURChar (CDKHISTOGRAM *histogram, chtype character)
                    507: {
                    508:    histogram->URChar = character;
                    509: }
                    510: void setCDKHistogramLLChar (CDKHISTOGRAM *histogram, chtype character)
                    511: {
                    512:    histogram->LLChar = character;
                    513: }
                    514: void setCDKHistogramLRChar (CDKHISTOGRAM *histogram, chtype character)
                    515: {
                    516:    histogram->LRChar = character;
                    517: }
                    518: void setCDKHistogramVerticalChar (CDKHISTOGRAM *histogram, chtype character)
                    519: {
                    520:    histogram->VChar = character;
                    521: }
                    522: void setCDKHistogramHorizontalChar (CDKHISTOGRAM *histogram, chtype character)
                    523: {
                    524:    histogram->HChar = character;
                    525: }
                    526: void setCDKHistogramBoxAttribute (CDKHISTOGRAM *histogram, chtype character)
                    527: {
                    528:    histogram->BoxAttrib = character;
                    529: }
                    530: 
                    531: /*
                    532:  * This sets the background color of the widget.
                    533:  */
                    534: void setCDKHistogramBackgroundColor (CDKHISTOGRAM *histogram, char *color)
                    535: {
                    536:    chtype *holder = 0;
                    537:    int junk1, junk2;
                    538: 
                    539:    /* Make sure the color isn't null. */
                    540:    if (color == 0)
                    541:    {
                    542:       return;
                    543:    }
                    544: 
                    545:    /* Convert the value of the environment variable to a chtype. */
                    546:    holder = char2Chtype (color, &junk1, &junk2);
                    547: 
                    548:    /* Set the widgets background color. */
                    549:    wbkgd (histogram->win, holder[0]);
                    550: 
                    551:    /* Clean up. */
                    552:    freeChtype (holder);
                    553: }
                    554: 
                    555: /*
                    556:  * This moves the histogram field to the given location.
                    557:  */
                    558: static void _moveCDKHistogram (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
                    559: {
                    560:    CDKHISTOGRAM *histogram = (CDKHISTOGRAM *)object;
                    561: 
                    562:    /*
                    563:     * If this is a relative move, then we will adjust where we want
                    564:     * to move to.
                    565:     */
                    566:    if (relative)
                    567:    {
                    568:       xplace += getbegx(histogram->win);
                    569:       yplace += getbegy(histogram->win);
                    570:    }
                    571: 
                    572:    /* Adjust the window if we need to. */
                    573:    alignxy (WindowOf(histogram), &xplace, &yplace, histogram->boxWidth, histogram->boxHeight);
                    574: 
                    575:    /* Move the window to the new location. */
                    576:    moveCursesWindow(histogram->win, xplace, yplace);
                    577: 
                    578:    /* Redraw the window, if they asked for it. */
                    579:    if (refresh_flag)
                    580:    {
                    581:       drawCDKHistogram (histogram, ObjOf(histogram)->box);
                    582:    }
                    583: }
                    584: 
                    585: /*
                    586:  * This function draws the histogram.
                    587:  */
                    588: static void _drawCDKHistogram (CDKOBJS *object, boolean Box)
                    589: {
                    590:    CDKHISTOGRAM *histogram = (CDKHISTOGRAM *)object;
                    591:    chtype battr = 0;
                    592:    chtype bchar = 0;
                    593:    chtype fattr = histogram->filler & A_ATTRIBUTES;
                    594:    chtype fchar = histogram->filler & A_CHARTEXT;
                    595:    int histX   = histogram->titleLines + 1;
                    596:    int histY   = histogram->barSize;
                    597:    int len, x, y;
                    598: 
                    599:    /* Erase the window. */
                    600:    werase (histogram->win);
                    601: 
                    602:    /* Box the widget if asked. */
                    603:    if (Box)
                    604:    {
                    605:       attrbox (histogram->win,
                    606:                histogram->ULChar, histogram->URChar,
                    607:                histogram->LLChar, histogram->LRChar,
                    608:                histogram->HChar,  histogram->VChar,
                    609:                histogram->BoxAttrib,
                    610:                histogram->shadow);
                    611:    }
                    612: 
                    613:    /* Draw in the title if there is one. */
                    614:    for (x=0; x < histogram->titleLines; x++)
                    615:    {
                    616:       writeChtype (histogram->win,
                    617:                        histogram->titlePos[x],
                    618:                        x + 1,
                    619:                        histogram->title[x],
                    620:                        HORIZONTAL, 0,
                    621:                        histogram->titleLen[x]);
                    622:    }
                    623: 
                    624:    /* If the user asked for labels, draw them in. */
                    625:    if (histogram->viewType != vNONE)
                    626:    {
                    627:       /* Draw in the low label. */
                    628:       if (histogram->lowString != 0)
                    629:       {
                    630:         len = (int)strlen (histogram->lowString);
                    631:         writeCharAttrib (histogram->win,
                    632:                                histogram->lowx,
                    633:                                histogram->lowy,
                    634:                                histogram->lowString,
                    635:                                histogram->statsAttr,
                    636:                                histogram->orient,
                    637:                                0, len);
                    638:       }
                    639: 
                    640:       /* Draw in the current value label. */
                    641:       if (histogram->curString != 0)
                    642:       {
                    643:         len = (int)strlen (histogram->curString);
                    644:         writeCharAttrib (histogram->win,
                    645:                                histogram->curx,
                    646:                                histogram->cury,
                    647:                                histogram->curString,
                    648:                                histogram->statsAttr,
                    649:                                histogram->orient,
                    650:                                0, len);
                    651:       }
                    652: 
                    653:       /* Draw in the high label. */
                    654:       if (histogram->highString != 0)
                    655:       {
                    656:         len = (int)strlen (histogram->highString);
                    657:         writeCharAttrib (histogram->win,
                    658:                                histogram->highx,
                    659:                                histogram->highy,
                    660:                                histogram->highString,
                    661:                                histogram->statsAttr,
                    662:                                histogram->orient,
                    663:                                0, len);
                    664:       }
                    665:    }
                    666: 
                    667:   /*
                    668:    * If the orientation is vertical, set
                    669:    * where the bar will start drawing from.
                    670:    */
                    671:    if (histogram->orient == VERTICAL)
                    672:    {
                    673:       histX = histogram->boxHeight - histogram->barSize - 1;
                    674:       histY = histogram->fieldWidth;
                    675:    }
                    676: 
                    677:    /* Draw the histogram bar. */
                    678:    for (x=histX; x < histogram->boxHeight-1; x++)
                    679:    {
                    680:       for (y=1; y <= histY; y++)
                    681:       {
                    682: #ifdef HAVE_WINCHBUG
                    683:         battr  = ' ' | A_REVERSE;
                    684: #else
                    685:         battr  = mvwinch (histogram->win, x, y);
                    686: #endif
                    687:         fchar  = battr & A_ATTRIBUTES;
                    688:         bchar  = battr & A_CHARTEXT;
                    689: 
                    690:         if (bchar == ' ')
                    691:         {
                    692:            mvwaddch (histogram->win, x, y, histogram->filler);
                    693:         }
                    694:         else
                    695:         {
                    696:            mvwaddch (histogram->win, x, y, battr | fattr);
                    697:         }
                    698:       }
                    699:    }
                    700: 
                    701:    /* Refresh the window. */
                    702:    wnoutrefresh (histogram->win);
                    703: }
                    704: 
                    705: /*
                    706:  * This function destroys the histogram.
                    707:  */
                    708: void destroyCDKHistogram (CDKHISTOGRAM *histogram)
                    709: {
                    710:    int x;
                    711: 
                    712:    /* Erase the object. */
                    713:    eraseCDKHistogram (histogram);
                    714: 
                    715:    /* Clean up the char pointers. */
                    716:    freeChar (histogram->curString);
                    717:    freeChar (histogram->lowString);
                    718:    freeChar (histogram->highString);
                    719:    for (x=0; x < histogram->titleLines; x++)
                    720:    {
                    721:       freeChtype (histogram->title[x]);
                    722:    }
                    723: 
                    724:    /* Clean up the windows. */
                    725:    deleteCursesWindow (histogram->win);
                    726: 
                    727:    /* Unregister this object. */
                    728:    unregisterCDKObject (vHISTOGRAM, histogram);
                    729: 
                    730:    /* Finish cleaning up. */
                    731:    free (histogram);
                    732: }
                    733: 
                    734: /*
                    735:  * This function erases the histogram from the screen.
                    736:  */
                    737: static void _eraseCDKHistogram (CDKOBJS *object)
                    738: {
                    739:    CDKHISTOGRAM *histogram = (CDKHISTOGRAM *)object;
                    740: 
                    741:    eraseCursesWindow (histogram->win);
                    742: }

CVSweb <webmaster@jp.NetBSD.org>