www.pudn.com > cwin.rar > GETXYA.C


    /*----------------------------------------------------------- 
        函数 getxya : 基本数据编辑 
    -----------------------------------------------------------*/ 
    #include  
    #include  
    #include  
 
    unsigned _Cdecl getxya(col,line,width,s,picture) 
    int col;             /* 编辑窗口左上角列坐标(以字节为单位) */ 
    int line;            /* 编辑窗口左上角行坐标(以象素为单位) */ 
    int width;           /* 编辑窗口宽度                       */ 
    char *s;             /* 被编辑的字符串                     */ 
    char *picture;       /* 编辑格式                           */ 
    { 
        unsigned char buff[81];              /* 编辑缓冲区     */ 
        unsigned char pict[81];              /* 格式缓冲区     */ 
        unsigned char *bptr  = buff;         /* 编辑指针       */ 
        unsigned char *brear = buff+width-1; /* 编辑区尾部指针 */ 
        int _EndEdit         = NO;           /* 结束编辑标记   */ 
        int modified         = NO;           /* 是否修改过     */ 
        int old_c            = _TextColor;   /* 原正文颜色     */ 
        int old_b            = _Background;  /* 原背景颜色     */ 
        int len              = strlen(s);    /* 长度临时变量   */ 
        int have_cursor      = iscursorlight(); /* 光标已打开  */ 
        int mouselight       = ismouselight();  /* 鼠标已打开  */ 
        unsigned h;                             /* 键盘输入键  */ 
 
        /*-- 将待编辑字符串拷贝到编辑缓冲区中 -----------------*/ 
        len = len>width?width:len; 
        memset(buff,' ',width); 
        memcpy(buff,s,len); 
        buff[width] = 0; 
 
        /*-- 将编辑格式串拷贝到格式缓冲区中 -------------------*/ 
        if(picture) 
        { 
            len = strlen(picture); 
            len = len>width?width:len; 
            memset(pict,' ',width); 
            memcpy(pict,picture,len); 
            pict[width] = 0; 
        } 
 
        /*-- 设置工作环境参数,显示待编辑的字符串 --------------*/ 
        set_text_color(_EditColor); 
        set_background(_EditBk); 
        _TextCol  = col; 
        _TextLine = line; 
        if(mouselight) 
            delight_mouse(); 
        putnstr(buff,width); 
        if(mouselight) 
            light_mouse(); 
        if(!have_cursor) 
            lightcursor(); 
 
        /*-- 按下任意键后清编辑缓冲区 -------------------------*/ 
        if((h=geth())==LEFT_BUTTON || h==RIGHT_BUTTON) 
            h -= 400; 
        else if(isprint(h)) 
            memset(buff,' ',width); 
        ungeth(h); 
 
        /*-- 根据键盘输入键编辑缓冲区内容 ---------------------*/ 
        do 
        { 
            /*-- 接收一个键盘码 -------------------------------*/ 
            if((h=geth())<=3) 
               h += 400; 
 
            /*-- 根据键盘码编辑 -------------------------------*/ 
            if(mouselight) 
                delight_mouse(); 
            switch(h) 
            { 
                case KEY_Left:                     /* 左箭头   */ 
                    if(bptr==buff) 
                        _EndEdit = YES; 
                    else 
                    { 
                        bptr--; 
                        _TextCol -= _Xtimes; 
                    } 
                    break; 
                case KEY_Right:                    /* 右箭头   */ 
                    if(bptr >= brear) 
                        _EndEdit = YES; 
                    else 
                    { 
                        bptr++; 
                        _TextCol += _Xtimes; 
                    } 
                    break; 
                case KEY_Home:                     /* Home 键  */ 
                    if(bptr>buff) 
                    { 
                        bptr     = buff; 
                        _TextCol = col; 
                    } 
                    else 
                        _EndEdit = YES; 
                    break; 
                case KEY_End:                      /* End 键   */ 
                    if(bptrbuff) 
                    { 
                        bptr--; 
                        _TextCol -= _Xtimes; 
                        memmove(bptr,bptr+1,width-(bptr-buff)); 
                        *(buff+width-1) = ' '; 
                        putnstr(bptr,width-(bptr-buff)); 
                    } 
                    modified = YES; 
                    break; 
                default:                           /* 其他键   */ 
                    /*-- 如果是功能键,退出编辑 ----------------*/ 
                    if(isedit(h) || h==KEY_ENTER || h==KEY_ESC || h==LEFT_BUTTON || h==RIGHT_BUTTON) 
                    { 
                        _EndEdit = YES; 
                        break; 
                    } 
 
                    /*-- 如果有格式串,按其进行编辑 ------------*/ 
                    if(picture) 
                    { 
                        switch(*(pict+(bptr-buff))) 
                        { 
                            case 'A': 
                            case 'a': 
                                if(!isalpha(h) && h!=' ') 
                                    goto _EndLoop; 
                                break; 
                            case '9': 
                                if(!isdigit(h) && h!='-' && h!='+' && h!='.') 
                                    goto _EndLoop; 
                                break; 
                            case '.': 
                                h    =    '.'; 
                                break; 
                            case ',': 
                                h    =    ','; 
                                break; 
                        } 
                    } 
 
                    /*-- 如果是可编辑字符,进入编辑缓冲区 ------*/ 
                    if(isprint(h) && bptr-buff<=width) 
                    { 
                        if(bptr<=brear) 
                        { 
                            if(isins()) 
                                movmem(bptr,bptr+1,brear-bptr); 
                            *bptr++   = h; 
                            putnstr(bptr-1,brear-bptr+2); 
                            _TextCol += _Xtimes; 
                        } 
                        if(bptr-buff==width) 
                        { 
                            _EndEdit = YES; 
                            h        = KEY_Right; 
                        } 
                        modified      = YES; 
                    } 
                    _EndLoop:; 
            }                               /* switch 语句结束 */ 
            if(mouselight) 
                light_mouse(); 
        }while(!_EndEdit); 
 
        /*-- 如果是ESC键,放弃被编辑的内容 ---------------------*/ 
        if(h!=KEY_ESC && h!=RIGHT_BUTTON && modified) 
        { 
            strcpy(s,buff); 
            h += 1024; 
        } 
 
        /*-- 以原正文和背景颜色显示被编辑的字符串 -------------*/ 
        delightcursor(); 
        if(mouselight) 
            delight_mouse(); 
        _TextCol = col; 
        set_text_color(old_c); 
        set_background(old_b); 
        putnstr(buff,width); 
        if(mouselight) 
            light_mouse(); 
        if(have_cursor) 
            lightcursor(); 
 
        /*-- 返回退出编辑状态的键盘码 -------------------------*/ 
        return h; 
    }