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

📄 newtoolbar.c

📁 在ADS环境下MiniGUI的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    ptb.x = rc.right; ptb.y = pta.y;
    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
    pta.y += 1; ptb.y = pta.y;
    line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);

    /* draw two separator lines */
    pta.x = 2; pta.y = MARGIN_VERT;
    ptb.x = pta.x; ptb.y = rc.bottom - MARGIN_VERT - 1;
    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
    pta.x += 1; ptb.x = pta.x;
    line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);

    pta.x = 5; pta.y = MARGIN_VERT;
    ptb.x = pta.x; ptb.y = rc.bottom - MARGIN_VERT - 1;
    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
    pta.x += 1; ptb.x = pta.x;
    line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);

    /* draw separator line between bitmap and text */
/*    if ((ntb_data->style & NTBS_WITHTEXT) && !(ntb_data->style & NTBS_TEXTRIGHT)) {
        pta.x = MARGIN_HORZ; pta.y = rc.bottom - GetFontHeight (hdc) - GAP_BMP_TEXT_VERT;
        ptb.x = rc.right; ptb.y = pta.y;
        line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
        pta.y += 1; ptb.y = pta.y;
        line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);
    } */
#endif /* _FLAT_WINDOW_STYLE */
    
    
    item = ntb_data->head;
    while (item) {
        if ( (item->flags & NTBIF_TYPEMASK) == NTBIF_NEWLINE )
            item = item->next;
        l = item->rc_item.left;
        t = item->rc_item.top;
        r = item->rc_item.right;
        b = item->rc_item.bottom;
        w = ntb_data->w_cell;
        h = ntb_data->h_cell;

        if ((item->flags & NTBIF_TYPEMASK) == NTBIF_SEPARATOR) {
            if (ntb_data->style & NTBS_DRAWSEPARATOR) {
#ifdef _FLAT_WINDOW_STYLE
                pta.x = l + 2;
                pta.y = t;
                ptb.x = pta.x;
                ptb.y = rc.bottom - MARGIN_VERT;
                line_a2b (hdc, &pta, &ptb, COLOR_black);
#else
                pta.x = l + 1;
                pta.y = t;
                ptb.x = pta.x;
                ptb.y = rc.bottom - MARGIN_VERT;
                line_a2b (hdc, &pta, &ptb, COLOR_darkgray);

                pta.x += 1;
                pta.y = t;
                ptb.x = pta.x;
                ptb.y = rc.bottom - MARGIN_VERT;
                line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);
#endif
            }

            item = item->next;
            continue;
        }

        if (item->flags & NTBIF_DISABLED) {
                if (ntb_data->nr_cols == 4)
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image, 
                                w * 3, h * item->bmp_cell);
                else
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image, 
                                0, h * item->bmp_cell);
        }
        else if ( item->flags & NTBIF_CHECKED) {
                if (ntb_data->nr_cols >= 3)
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image,
                                    w * 2, h * item->bmp_cell);
                else if ( ntb_data->nr_cols >=2 )
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image, 
                                w, h * item->bmp_cell);
                else
                {
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image, 
                                0, h * item->bmp_cell);
                    r = l + w ;
                    b = t + h ;
                    pta.x = l; pta.y = t;
                    ptb.x = l; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_black);
                    pta.x = l; pta.y = t;
                    ptb.x = r; ptb.y = t;
                    line_a2b (hdc, &pta, &ptb, COLOR_black);

                    pta.x = r; pta.y = t;
                    ptb.x = r; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_black);
                    pta.x = l; pta.y = b;
                    ptb.x = r; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_black);
                }
            
        }
        else {
            if (item == ntb_data->sel_item) {
                if (ntb_data->btn_down && ntb_data->nr_cols >= 3)
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image,
                                    w * 2, h * item->bmp_cell);
                else if (!ntb_data->btn_down && ntb_data->nr_cols >= 2)
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image,
                                    w, h * item->bmp_cell);
                else
                    FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image,
                                0, h * item->bmp_cell);
            }
            else
                FillBoxWithBitmapPart (hdc, l, t, w, h, 0, 0, ntb_data->image,
                                    0, h * item->bmp_cell);
        }
        
        if (ntb_data->style & NTBS_DRAWSTATES) {

            if ((ntb_data->style & NTBS_WITHTEXT) 
                            && !(ntb_data->style & NTBS_TEXTRIGHT)) {
                r = l + w;
                b = t + h;
            }
            else {
                r--; b--;
            }

            if (!(item->flags & NTBIF_DISABLED) && item == ntb_data->sel_item) {
                if (ntb_data->btn_down) {
                    pta.x = l; pta.y = t;
                    ptb.x = l; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
                    pta.x = l; pta.y = t;
                    ptb.x = r; ptb.y = t;
                    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);

                    pta.x = r; pta.y = t;
                    ptb.x = r; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);
                    pta.x = l; pta.y = b;
                    ptb.x = r; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);
                }
                else {
                    pta.x = l; pta.y = t;
                    ptb.x = l; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);
                    pta.x = l; pta.y = t;
                    ptb.x = r; ptb.y = t;
                    line_a2b (hdc, &pta, &ptb, COLOR_lightwhite);

                    pta.x = r; pta.y = t;
                    ptb.x = r; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
                    pta.x = l; pta.y = b;
                    ptb.x = r; ptb.y = b;
                    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
                }
            }
        }

        if (ntb_data->style & NTBS_WITHTEXT) {
            DWORD format = DT_SINGLELINE | DT_VCENTER;

            if (ntb_data->style & NTBS_TEXTRIGHT)
                format |= DT_LEFT;
            else
                format |= DT_CENTER;

            SetBkMode (hdc, BM_TRANSPARENT);
            DrawText (hdc, item->text, -1, &item->rc_text, format);
        }

        item = item->next;
    }
}

static NTBITEM* get_item_by_pos (PNTBCTRLDATA ntb_data, int posx, int posy)
{
    NTBITEM* item;

    item = ntb_data->head;
    while (item) {
        if (!(item->flags & NTBIF_DISABLED) && PtInRect (&item->rc_item, posx, posy)) {
            return item;
        }

        item = item->next;
    }

    return NULL;
}

static void append_new_item (HWND hwnd, NTBCTRLDATA* ntb_data, NTBITEM* new_item)
{
    HDC hdc;

    hdc = GetClientDC (hwnd);
    if (! (ntb_data->style & NTBS_VERTICAL) )
    {
       //horizontal
        
        if (ntb_data->tail == NULL )
        {
            new_item->rc_item.top = MARGIN_VERT;
            new_item->rc_item.left = MARGIN_HORZ;
        }
        else if ( (new_item->flags & NTBIF_TYPEMASK ) == NTBIF_NEWLINE )
        {
            new_item->rc_item.top = ntb_data->tail->rc_item.bottom + GAP_ITEM_ITEM_VERT;
            new_item->rc_item.left = MARGIN_HORZ;
            new_item->rc_item.bottom = new_item->rc_item.top;
            new_item->rc_item.right = new_item->rc_item.left;
            goto  end;
        }
        else
        {
            new_item->rc_item.top = ntb_data->tail->rc_item.top;
            if ( (ntb_data->tail->flags & NTBIF_TYPEMASK) == NTBIF_NEWLINE )
                new_item->rc_item.left = MARGIN_HORZ;
            else
                new_item->rc_item.left = ntb_data->tail->rc_item.right + GAP_ITEM_ITEM_HORZ;
        }


        switch (new_item->flags & NTBIF_TYPEMASK) {
        case NTBIF_PUSHBUTTON:
        case NTBIF_CHECKBUTTON:
        case NTBIF_HOTSPOTBUTTON:
            if (ntb_data->style & NTBS_WITHTEXT) {
                if (ntb_data->style & NTBS_TEXTRIGHT) {

                    SIZE sz_text;
                    GetTextExtent (hdc, new_item->text, -1, &sz_text);

                    new_item->rc_item.bottom 
                            = new_item->rc_item.top + ntb_data->h_cell + 1;

                    new_item->rc_text.left = new_item->rc_item.left + ntb_data->w_cell + GAP_BMP_TEXT_HORZ;
                    new_item->rc_text.right = new_item->rc_text.left + sz_text.cx;
                    new_item->rc_text.top = new_item->rc_item.top;
                    new_item->rc_text.bottom = new_item->rc_item.bottom;

                    new_item->rc_item.right = new_item->rc_text.right + GAP_BMP_TEXT_HORZ + 1;
                }
                else {
                    new_item->rc_item.right = new_item->rc_item.left + ntb_data->w_cell + 1;

                    new_item->rc_text.left = new_item->rc_item.left;
                    new_item->rc_text.right = new_item->rc_item.right;
                    new_item->rc_text.top 
                            = new_item->rc_item.top + ntb_data->h_cell + GAP_BMP_TEXT_VERT;
                    new_item->rc_text.bottom = new_item->rc_text.top + GetFontHeight (hdc);

                    new_item->rc_item.bottom = new_item->rc_text.bottom + 1;
                }
            }
            else {
                new_item->rc_item.right = new_item->rc_item.left + ntb_data->w_cell + 1;
                new_item->rc_item.bottom = new_item->rc_item.top + ntb_data->h_cell + 1;
            }
            break;
            
        case NTBIF_NEWLINE:
        case NTBIF_SEPARATOR:
        default:
            if (ntb_data->style & NTBS_DRAWSEPARATOR)
                new_item->rc_item.right = new_item->rc_item.left + WIDTH_SEPARATOR;
            else
                new_item->rc_item.right = new_item->rc_item.left + WIDTH_SEPARATOR * 2;
            new_item->rc_item.bottom = new_item->rc_item.top + ntb_data->h_cell;
            break;
        }
    }
    else
    {
    // vertical 
        if (ntb_data->tail == NULL )
        {
            new_item->rc_item.top = MARGIN_V_VERT;
            new_item->rc_item.left = MARGIN_V_HORZ;
        }
        else if ( (new_item->flags & NTBIF_TYPEMASK ) == NTBIF_NEWLINE )
        {
            new_item->rc_item.left = ntb_data->tail->rc_item.right + GAP_ITEM_ITEM_HORZ;
            new_item->rc_item.top = MARGIN_V_VERT;
            new_item->rc_item.bottom = new_item->rc_item.top;
            new_item->rc_item.right = new_item->rc_item.left;
            goto  end;
        }
        else
        {
            if ( (ntb_data->tail->flags & NTBIF_TYPEMASK) == NTBIF_NEWLINE )
                new_item->rc_item.top = MARGIN_V_VERT; 
            else
                new_item->rc_item.top = ntb_data->tail->rc_item.bottom + GAP_ITEM_ITEM_VERT;
            new_item->rc_item.left = ntb_data->tail->rc_item.left;
        }
        
        switch (new_item->flags & NTBIF_TYPEMASK) {
        case NTBIF_PUSHBUTTON:
        case NTBIF_CHECKBUTTON:
        case NTBIF_HOTSPOTBUTTON:
            if (ntb_data->style & NTBS_WITHTEXT) {
                if (ntb_data->style & NTBS_TEXTRIGHT) {

                    SIZE sz_text;
                    GetTextExtent (hdc, new_item->text, -1, &sz_text);

                    new_item->rc_item.bottom 
                            = new_item->rc_item.top + ntb_data->h_cell + 1;

                    new_item->rc_text.left = new_item->rc_item.left + ntb_data->w_cell + GAP_BMP_TEXT_HORZ;
                    new_item->rc_text.right = new_item->rc_text.left + sz_text.cx;
                    new_item->rc_text.top = new_item->rc_item.top;
                    new_item->rc_text.bottom = new_item->rc_item.bottom;

                    new_item->rc_item.right = new_item->rc_text.right + GAP_BMP_TEXT_HORZ + 1;
                }
                else {
                    new_item->rc_item.right = new_item->rc_item.left + ntb_data->w_cell + 1;

                    new_item->rc_text.left = new_item->rc_item.left;
                    new_item->rc_text.right = new_item->rc_item.right;
                    new_item->rc_text.top 
                            = new_item->rc_item.top + ntb_data->h_cell + GAP_BMP_TEXT_VERT;
                    new_item->rc_text.bottom = new_item->rc_text.top + GetFontHeight (hdc);

                    new_item->rc_item.bottom = new_item->rc_text.bottom + 1;
                }
            }
            else {
                new_item->rc_item.right = new_item->rc_item.left + ntb_data->w_cell + 1;
                new_item->rc_item.bottom = new_item->rc_item.top + ntb_data->h_cell + 1;
            }
            break;
                        
        case NTBIF_SEPARATOR:
        default:
            if (ntb_data->style & NTBS_DRAWSEPARATOR)
                new_item->rc_item.bottom = new_item->rc_item.top + WIDTH_SEPARATOR;
            else
                new_item->rc_item.bottom = new_item->rc_item.top + WIDTH_SEPARATOR * 2;
            new_item->rc_item.right = new_item->rc_item.left + ntb_data->w_cell;
            break;
        }
    }

⌨️ 快捷键说明

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