⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reglist.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    list_rect.bottom = list_rect.top + string_rect.bottom;
    GetWindowRect( string, &string_rect);

    if( string_rect.left < list_rect.left ) {
        dx = list_rect.left - string_rect.left;
    } else {
        if( string_rect.right > list_rect.right ) {
            dx = list_rect.right - string_rect.right;
        } else {
            dx = 0;
        }
    }

    if( string_rect.top < list_rect.top ) {
        dy = list_rect.top - string_rect.top;
    } else {
        if( string_rect.bottom > list_rect.bottom ) {
            dy = list_rect.bottom - string_rect.bottom;
        } else {
            dy = 0;
        }
    }

    if( dx || dy ) {
        ScrollWindow( list, dx, dy, NULL, NULL );
        if( dx ) {
            pos = GetScrollPos( list, SB_HORZ );
            SetScrollPos( list, SB_HORZ, pos - dx, TRUE );
        }
        if( dy ) {
            pos = GetScrollPos( list, SB_VERT );
            SetScrollPos( list, SB_VERT, pos - dy, TRUE );
        }
    }
    SendMessage( string, REG_STRING_SELECTED, 0, 0 );
}

static void UpdateRegList(HWND list, RegListData *list_data)
{
    int                 i;
    int                 j;
    int                 num_columns;
    int                 height;
    int                 x;
    int                 y;
    int                 left;
    int                 id;
    int                 num_regs;
    RegStringCreateData *reg_create;
    int                 space;
    int                 old_maxx;
    int                 new_maxx;
    int                 new_maxy;
    int                 min;
    int                 extra;
    HWND                string;
    HWND                d_string;
    mad_reg_set_data    *reg_set;

    reg_set = list_data->reg_set;

    string = GetWindow( list, GW_CHILD );
    while(string != NULL ) {
        SetRegStringDestroyFlag( string );
        string = GetWindow( string, GW_HWNDNEXT );
    }


    left =  GetScrollPos( list, SB_HORZ );
    y =  GetScrollPos( list, SB_VERT );
    GetScrollRange( list, SB_HORZ, &min, &old_maxx );
    SetupRegList( list, reg_set, &reg_create, &num_regs, &num_columns, &space, &height, &extra );
    GetScrollRange( list, SB_HORZ, &min, &new_maxx );
    GetScrollRange( list, SB_VERT, &min, &new_maxy );
    left -= old_maxx - new_maxx;
    y = min( new_maxy, y );
    SetScrollPos( list, SB_HORZ, left, TRUE );
    SetScrollPos( list, SB_VERT, y, TRUE );
    left *= -1;
    y   *= -1;
    left += space;
    x = left;
    j = id = 0;
    for( i = 0; i < num_regs; i++ ) {
        if( extra < j ){
            x++;
        }
        if( IsEmptyString( reg_create[i].buffer ) == FALSE ) {
            string = GetDlgItem( list, id );
            if( string == NULL ) {
                CreateRegString( list, x, y, reg_create[j].length, height, reg_create[i].buffer, id );
            } else {
                UpdateRegString( string, list, x, y, reg_create[j].length, height, reg_create[i].buffer );
            }

        }
        x += reg_create[j].length + space;
        id++;
        j++;
        if( j == num_columns ) {
             y += height;
             x = left;
             j = 0;
        }
    }

    string = GetWindow( list, GW_CHILD );
    while( string ) {
        if( GetRegStringDestroyFlag( string ) == TRUE ) {
            if( list_data->curr_reg == string ) {
                list_data->curr_reg = NULL;
            }
            d_string = string;
            string = GetWindow( string, GW_HWNDNEXT );
            DestroyWindow( d_string );
        } else {
            string = GetWindow( string, GW_HWNDNEXT );
        }
    }

    if( list_data->curr_reg == NULL ) {
        list_data->curr_reg = GetWindow( list, GW_CHILD );
        if( list == GetFocus() ) {
            MakeStringCurrent( list, list_data->curr_reg, list_data );
        }
    }

    FreeRegStringCreate( reg_create, num_regs );
}

static void ShowRegListMenu(HWND list, int x, int y, RegListData *data )
{
    TrackPopupMenu( data->menu,
        TPM_LEFTBUTTON,// | TPM_RIGHTBUTTON ,
        x,
        y,
        0,
        list,
        NULL );
}


static LRESULT ProcessKeyEvent(HWND hwnd,UINT msg, WPARAM wparam,LPARAM lparam)
{
    HWND        string;
    RECT        rectold;
    RECT        rectnew;
    UINT        direction;
    RegListData *data;
    HWND        parent;
    WORD        repeat;

    repeat = LOWORD( lparam );
    data = (RegListData *)GetWindowLong( hwnd, 0 );
    direction = GW_HWNDNEXT;
    string = data->curr_reg;

    switch (wparam){
    case VK_TAB:
        parent = GetParent( hwnd );
        SetFocus( GetNextDlgTabItem( parent, hwnd, ( GetKeyState( VK_SHIFT) < 0 ) ? TRUE : FALSE ) );
        return( 0L );

    case VK_RETURN:
        SendMessage( string, WM_LBUTTONDBLCLK, 0, 0 );
        return ( 0L );
    case VK_LEFT:
        direction = GW_HWNDPREV;
        /* fall through */
    case VK_RIGHT:
        while( repeat > 0 ){
            string = GetWindow( string, direction );
            repeat--;
        }
        break;
    case VK_UP:
        direction = GW_HWNDPREV;
        /* fall through */
    case VK_DOWN:
        GetWindowRect( string, &rectold );
        while( repeat > 0 ) {
            while( string ) {
                string = GetWindow( string, direction );
                if( string == NULL ) {
                    return( 0L );
                }
                GetWindowRect( string, &rectnew );
                if ( rectold.left == rectnew.left ){
                    break;
                }
            }
        repeat--;
        }
        break;
    default:
        return( DefWindowProc( hwnd, msg, wparam, lparam) );
    }
    if ( string ){
        MakeStringCurrent( hwnd, string, data );
    }
    return ( 0L );
}

LRESULT CALLBACK RegListProc(HWND hwnd, UINT msg,WPARAM wparam, LPARAM lparam)
{
    RegListData *data;
    RECT        rect;
    WORD        item;

    data = (RegListData *)GetWindowLong( hwnd, 0 );
    switch( msg ){
    case CHILD_R_CLICK:
        SetFocus( hwnd );
        MakeStringCurrent( hwnd, (HWND)wparam, data );
        EnableMenuItem( data->menu, 1, MF_BYCOMMAND | MF_ENABLED );
        GetWindowRect( data->curr_reg, &rect );
        ShowRegListMenu( hwnd, rect.left + LOWORD( lparam ), rect.top + HIWORD( lparam ), data );
        break;
    case WM_RBUTTONDOWN:
        EnableMenuItem( data->menu, 1, MF_BYCOMMAND | MF_GRAYED );
        GetWindowRect( hwnd, &rect );
        ShowRegListMenu( hwnd, rect.left + LOWORD( lparam ), rect.top + HIWORD( lparam ), data );
        break;
    case WM_SETFOCUS:
        SendMessage( data->curr_reg, REG_STRING_SELECTED, 0, 0 );
        break;
    case WM_KILLFOCUS:
        SendMessage( data->curr_reg, REG_STRING_DESELECTED, 0, 0 );
        break;
    case WM_KEYDOWN:
        ProcessKeyEvent( hwnd, msg, wparam, lparam );
        break;
    case WM_GETDLGCODE:
        return( DLGC_WANTALLKEYS );
    case CHILD_L_CLICK:
        SetFocus( hwnd );
        MakeStringCurrent( hwnd, (HWND)wparam, data );
        break;
    case HIDE_REG_LIST:
        ShowWindow( hwnd, SW_HIDE );
        break;
    case UNHIDE_REG_LIST:
        ShowWindow( hwnd, SW_SHOW );
        break;
    case UPDATE_REG_LIST:
        UpdateRegList( hwnd, data );
        break;
    case WM_HSCROLL:
    case WM_VSCROLL:
        ScrollRegList( hwnd, msg, wparam );
        break;
    case WM_DESTROY:
        DestroyMenu( data->menu );
        MemFree( data );
        break;
    case WM_COMMAND:
        if ( HIWORD( wparam ) == 0 ){
            item = LOWORD( wparam );
            switch( item  ){
            case 1:
                SendMessage( data->curr_reg, WM_LBUTTONDBLCLK, 0, 0 );
                break;
            default:
                if( CheckMenuItem( data->menu, item, MF_BYCOMMAND ) == MF_CHECKED ){
                    CheckMenuItem( data->menu, item, MF_UNCHECKED | MF_BYCOMMAND );
                } else {
                    CheckMenuItem( data->menu, item, MF_CHECKED | MF_BYCOMMAND );
                }
                item -= MAD_MENU_FIRST_ITEM;
                item = 1 << item;
                MADRegSetDisplayToggle( data->reg_set, item, item );
                UpdateRegList( hwnd, data );
            }
            break;
        }
        /* fall through */
        default:
            return DefWindowProc( hwnd, msg, wparam, lparam );
    }
    return ( 0L );
}


void InitRegList(void)
{
    WNDCLASS            wc;
    wc.style = CS_BYTEALIGNWINDOW | CS_BYTEALIGNCLIENT;
    wc.lpfnWndProc = RegListProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 4;
    wc.hInstance = Instance;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor( NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "REG_LIST";
    RegisterClass( &wc );
    InitRegString();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -