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

📄 newtoolbar.c

📁 在ADS环境下MiniGUI的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
** $Id: newtoolbar.c,v 1.18 2004/08/02 03:03:57 weiym Exp $
**
** newtoolbar.c: the new-toolbar control module.
**
** This control is a substitute of old ToolBar control.
** New application should use the NewToolBar control
** instead of ToolBar control.
**
** Copyright (C) 2003 Feynman Software.
** 
** Authors:
**      Wei Yongming (ymwei@minigui.org)
**      Peng Yuan
**
** Create date: 2003/04/24
*/

/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/*
** TODO:
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "control.h"
#include "cliprect.h"
#include "internals.h"
#include "ctrlclass.h"

#ifdef _CTRL_NEWTOOLBAR

#include "ctrlmisc.h"
#include "newtoolbar.h"

static int NewToolbarCtrlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam);

BOOL RegisterNewToolbarControl (void)
{
    WNDCLASS WndClass;

    WndClass.spClassName = CTRL_NEWTOOLBAR;
    WndClass.dwStyle     = WS_NONE;
    WndClass.dwExStyle   = WS_EX_NONE;
    WndClass.hCursor     = GetSystemCursor (IDC_ARROW);
    WndClass.iBkColor    = GetWindowElementColor (BKC_CONTROL_DEF);
    WndClass.WinProc     = NewToolbarCtrlProc;

    return AddNewControlClass (&WndClass) == ERR_OK;
}


static void line_a2b (HDC hdc, POINT* a, POINT* b, int color)
{
    SetPenColor (hdc, color);
    MoveTo (hdc, a->x, a->y);
    LineTo (hdc, b->x, b->y);
}

static void draw_tool_bar_vert (HWND hwnd, HDC hdc, PNTBCTRLDATA ntb_data)
{
    int         l, t, r, b, w, h;
    RECT        rc;
    POINT       pta, ptb;
    NTBITEM*    item = NULL;

    GetClientRect (hwnd, &rc);

    /* draw right and left line */
#ifdef _FLAT_WINDOW_STYLE
    pta.x = 0; pta.y = 0;
    ptb.x = 0; ptb.y = rc.bottom;
    line_a2b (hdc, &pta, &ptb, COLOR_black);

    pta.x = rc.right - 1 ; pta.y = 0;
    ptb.x = rc.right - 1; ptb.y = rc.bottom;
    line_a2b (hdc, &pta, &ptb, COLOR_black);

    /* draw two separator lines */
    pta.y = 2; pta.x = MARGIN_V_HORZ;
    ptb.y = pta.y; ptb.x = rc.right - MARGIN_V_HORZ - 1;
    line_a2b (hdc, &pta, &ptb, COLOR_black);

    pta.y = 5; pta.x = MARGIN_V_HORZ;
    ptb.y = pta.y; ptb.x = rc.right - MARGIN_V_HORZ - 1;
    line_a2b (hdc, &pta, &ptb, COLOR_black);

    /* 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_black);
    }*/
#else
    rc.bottom -= 1;
    rc.right -= 1;

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

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

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

    pta.y = 5; pta.x = MARGIN_V_HORZ;
    ptb.y = pta.y; ptb.x = rc.right - MARGIN_V_HORZ - 1;
    line_a2b (hdc, &pta, &ptb, COLOR_darkgray);
    pta.y += 1; ptb.y = pta.y;
    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.y = l ;
                pta.x = t + 2;
                ptb.y = pta.y;
                ptb.x = rc.right - MARGIN_V_HORZ;
                line_a2b (hdc, &pta, &ptb, COLOR_black);
#else
                pta.y = l ;
                pta.x = t + 1;
                ptb.y = pta.y;
                ptb.x = rc.left - MARGIN_V_HORZ;
                line_a2b (hdc, &pta, &ptb, COLOR_darkgray);

                pta.y += 1;
                pta.x = t + 1;
                ptb.y = pta.y;
                ptb.x = rc.left - MARGIN_V_HORZ;
                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 void draw_tool_bar_horz (HWND hwnd, HDC hdc, PNTBCTRLDATA ntb_data)
{
    int         l, t, r, b, w, h;
    RECT        rc;
    POINT       pta, ptb;
    NTBITEM*    item = NULL;

    GetClientRect (hwnd, &rc);

    /* draw top and bottom line */
#ifdef _FLAT_WINDOW_STYLE
    pta.x = 0; pta.y = 0;
    ptb.x = rc.right; ptb.y = pta.y;
    line_a2b (hdc, &pta, &ptb, COLOR_black);

    pta.x = 0; pta.y = rc.bottom - 1;
    ptb.x = rc.right; ptb.y = pta.y;
    line_a2b (hdc, &pta, &ptb, COLOR_black);

    /* 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_black);

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

    /* 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_black);
    }*/
#else
    rc.bottom -= 1;
    rc.right -= 1;

    pta.x = 0; pta.y = 0;
    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);

    pta.x = 0; pta.y = rc.bottom - 1;

⌨️ 快捷键说明

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