[BACK]Return to cdkscreen.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / othersrc / dist / cdk

Annotation of othersrc/dist/cdk/cdkscreen.c, Revision 1.2

1.1       garbled     1: #include <cdk.h>
                      2:
                      3: /*
1.2     ! christos    4:  * $Author: garbled $
        !             5:  * $Date: 2001/01/04 19:58:24 $
        !             6:  * $Revision: 1.1.1.1 $
1.1       garbled     7:  */
                      8:
                      9: static boolean validObjType(EObjectType type)
                     10: {
                     11:    switch (type) {
                     12:    case vALPHALIST:
                     13:    case vBUTTONBOX:
                     14:    case vCALENDAR:
                     15:    case vDIALOG:
                     16:    case vENTRY:
                     17:    case vFSELECT:
                     18:    case vGRAPH:
                     19:    case vHISTOGRAM:
                     20:    case vITEMLIST:
                     21:    case vLABEL:
                     22:    case vMARQUEE:
                     23:    case vMATRIX:
                     24:    case vMENTRY:
                     25:    case vMENU:
                     26:    case vRADIO:
                     27:    case vSCALE:
                     28:    case vSCROLL:
                     29:    case vSELECTION:
                     30:    case vSLIDER:
                     31:    case vSWINDOW:
                     32:    case vTEMPLATE:
                     33:    case vVIEWER:
                     34:       return TRUE;
                     35:    default:
                     36:       return FALSE;
                     37:    }
                     38: }
                     39:
                     40: void *_newCDKObject(unsigned size, CDKFUNCS *funcs)
                     41: {
                     42:    void *result = malloc(size);
                     43:    memset(result, 0, sizeof(CDKOBJS));
                     44:    ((CDKOBJS *)result)->fn = funcs;
                     45:    return result;
                     46: }
                     47:
                     48: /*
                     49:  * This creates a new CDK screen.
                     50:  */
                     51: CDKSCREEN *initCDKScreen(WINDOW *window)
                     52: {
                     53:    CDKSCREEN *screen = (CDKSCREEN *)malloc (sizeof(CDKSCREEN));
                     54:    int x;
                     55:
                     56:    /* Set up basic curses settings. */
                     57:    noecho();
                     58:    cbreak();
                     59:
                     60:    /* Initialize the CDKSCREEN pointer. */
                     61:    screen->objectCount = 0;
                     62:    screen->window      = window;
                     63:    for (x=0; x < MAX_OBJECTS; x++)
                     64:    {
                     65:       screen->object[x] = 0;
                     66:       screen->cdktype[x] = vNULL;
                     67:    }
                     68:
                     69:    /* OK, we are done. */
                     70:    return (screen);
                     71: }
                     72:
                     73: /*
                     74:  * This registers a CDK object with a screen.
                     75:  */
                     76: void registerCDKObject (CDKSCREEN *screen, EObjectType cdktype, void *object)
                     77: {
                     78:    /* Set some basic vars. */
                     79:    int objectNumber                    = screen->objectCount;
                     80:    CDKOBJS *obj                                = (CDKOBJS *)object;
                     81:
                     82:    screen->object[objectNumber]                = obj;
                     83:
                     84:    if (validObjType(cdktype)) {
                     85:       (obj)->screenIndex               = objectNumber;
                     86:       (obj)->screen                    = screen;
                     87:       screen->cdktype[objectNumber]    = cdktype;
                     88:       screen->objectCount++;
                     89:    }
                     90: }
                     91:
                     92: /*
                     93:  * This removes an object from the CDK screen.
                     94:  */
                     95: void unregisterCDKObject (EObjectType cdktype, void *object)
                     96: {
                     97:    /* Declare some vars. */
                     98:    CDKSCREEN *screen;
                     99:    int Index, x;
                    100:
                    101:    if (validObjType(cdktype)) {
                    102:       CDKOBJS *obj = (CDKOBJS *)object;
                    103:
                    104:       screen   = (obj)->screen;
                    105:       Index    = (obj)->screenIndex;
                    106:
                    107:       /*
                    108:        * If this is the last object -1 then this is the last. If not
                    109:        * we have to shuffle all the other objects to the left.
                    110:        */
                    111:       for (x=Index; x < screen->objectCount-1; x++)
                    112:       {
                    113:         cdktype                = screen->cdktype[x+1];
                    114:         screen->cdktype[x]     = cdktype;
                    115:         screen->object[x]      = screen->object[x+1];
                    116:         (screen->object[x])->screenIndex = x;
                    117:       }
                    118:
                    119:       /* Clear out the last widget on the screen list. */
                    120:       x = screen->objectCount--;
                    121:       screen->object[x]                = 0;
                    122:       screen->cdktype[x]       = vNULL;
                    123:    }
                    124: }
                    125:
                    126: /*
                    127:  * This 'brings' a CDK object to the top of the stack.
                    128:  */
                    129: void raiseCDKObject (EObjectType cdktype, void *object)
                    130: {
                    131:    CDKOBJS *swapobject;
                    132:    int toppos          = -1;
                    133:    int swapindex       = -1;
                    134:    EObjectType swaptype;
                    135:
                    136:    if (validObjType(cdktype)) {
                    137:       CDKOBJS *obj = (CDKOBJS *)object;
                    138:
                    139:       toppos           = (obj)->screen->objectCount;
                    140:       swapobject       = (obj)->screen->object[toppos];
                    141:       swaptype         = (obj)->screen->cdktype[toppos];
                    142:       swapindex                = (obj)->screenIndex;
                    143:
                    144:       (obj)->screenIndex               = toppos;
                    145:       (obj)->screen->object[toppos]    = obj;
                    146:       (obj)->screen->cdktype[toppos]   = cdktype;
                    147:
                    148:       (obj)->screenIndex               = swapindex;
                    149:       (obj)->screen->object[swapindex] = swapobject;
                    150:       (obj)->screen->cdktype[swapindex] = swaptype;
                    151:    }
                    152: }
                    153:
                    154: /*
                    155:  * This 'lowers' an object.
                    156: */
                    157: void lowerCDKObject (EObjectType cdktype, void *object)
                    158: {
                    159:    CDKOBJS *swapobject;
                    160:    int toppos          = 0;
                    161:    int swapindex       = -1;
                    162:    EObjectType swaptype;
                    163:
                    164:    if (validObjType(cdktype)) {
                    165:       CDKOBJS *obj = (CDKOBJS *)object;
                    166:
                    167:       swapobject       = (obj)->screen->object[toppos];
                    168:       swaptype         = (obj)->screen->cdktype[toppos];
                    169:       swapindex                = (obj)->screenIndex;
                    170:
                    171:       (obj)->screenIndex               = toppos;
                    172:       (obj)->screen->object[toppos]    = obj;
                    173:       (obj)->screen->cdktype[toppos]   = cdktype;
                    174:
                    175:       (obj)->screenIndex               = swapindex;
                    176:       (obj)->screen->object[swapindex] = swapobject;
                    177:       (obj)->screen->cdktype[swapindex] = swaptype;
                    178:    }
                    179: }
                    180:
                    181: /*
                    182:  * This calls refreshCDKScreen. (made consistent with widgets)
                    183:  */
                    184: void drawCDKScreen (CDKSCREEN *cdkscreen)
                    185: {
                    186:     refreshCDKScreen (cdkscreen);
                    187: }
                    188:
                    189: /*
                    190:  * This refreshes all the objects in the screen.
                    191:  */
                    192: void refreshCDKScreen (CDKSCREEN *cdkscreen)
                    193: {
                    194:    int objectCount = cdkscreen->objectCount;
                    195:    int x;
                    196:
                    197:    /* Refresh the screen. */
                    198:    wnoutrefresh (cdkscreen->window);
                    199:
                    200:    /* We just call the drawObject function. */
                    201:    for (x=0; x < objectCount; x++)
                    202:    {
                    203:       CDKOBJS *obj = cdkscreen->object[x];
                    204:
                    205:       if (validObjType (cdkscreen->cdktype[x]))
                    206:         obj->fn->drawObj(obj, obj->box);
                    207:    }
                    208: }
                    209:
                    210: /*
                    211:  * This clears all the objects in the screen.
                    212:  */
                    213: void eraseCDKScreen (CDKSCREEN *cdkscreen)
                    214: {
                    215:    int objectCount = cdkscreen->objectCount;
                    216:    int x;
                    217:
                    218:    /* Refresh the screen. */
                    219:    wnoutrefresh (cdkscreen->window);
                    220:
                    221:    /* We just call the drawObject function. */
                    222:    for (x=0; x < objectCount; x++)
                    223:    {
                    224:       CDKOBJS *obj = cdkscreen->object[x];
                    225:
                    226:       if (validObjType (cdkscreen->cdktype[x]))
                    227:         obj->fn->eraseObj(obj);
                    228:    }
                    229: }
                    230:
                    231: /*
                    232:  * This destroys a CDK screen.
                    233:  */
                    234: void destroyCDKScreen (CDKSCREEN *screen)
                    235: {
                    236:    free (screen);
                    237: }
                    238:
                    239: /*
                    240:  * This is added to remain consistent.
                    241:  */
                    242: void endCDK(void)
                    243: {
                    244:    /* Turn echoing back on. */
                    245:    echo();
                    246:
                    247:    /* Turn off cbreak. */
                    248:    nocbreak();
                    249:
                    250:    /* End the curses windows. */
                    251:    endwin();
                    252:
                    253: #ifdef HAVE_XCURSES
                    254:    XCursesExit();
                    255: #endif
                    256: }

CVSweb <webmaster@jp.NetBSD.org>