📄 newtoolbar.c
字号:
/*** $Id: newtoolbar.c,v 1.14 2003/09/04 02:40:36 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 (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; 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) { 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 == 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; new_item->rc_item.top = MARGIN_VERT; if (ntb_data->tail == NULL) new_item->rc_item.left = MARGIN_HORZ; else new_item->rc_item.left = ntb_data->tail->rc_item.right + GAP_ITEM_ITEM_HORZ; hdc = GetClientDC (hwnd); switch (new_item->flags & NTBIF_TYPEMASK) { case NTBIF_PUSHBUTTON: 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.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; } ReleaseDC (hdc); new_item->next = NULL; if (ntb_data->tail == NULL) { ntb_data->head = ntb_data->tail = new_item; } else { ntb_data->tail->next = new_item; ntb_data->tail = new_item; } ntb_data->nr_items++;}static void recalc_items (HWND hwnd, NTBCTRLDATA* ntb_data){ HDC hdc; PNTBITEM item, prev = NULL; hdc = GetClientDC (hwnd); item = ntb_data->head; while (item) { item->rc_item.top = MARGIN_VERT; if (prev) item->rc_item.left = prev->rc_item.right + GAP_ITEM_ITEM_HORZ; else item->rc_item.left = MARGIN_HORZ; switch (item->flags & NTBIF_TYPEMASK) { case NTBIF_PUSHBUTTON: case NTBIF_HOTSPOTBUTTON: if (ntb_data->style & NTBS_WITHTEXT) { if (ntb_data->style & NTBS_TEXTRIGHT) { SIZE sz_text; GetTextExtent (hdc, item->text, -1, &sz_text); item->rc_item.bottom = item->rc_item.top + ntb_data->h_cell + 1; item->rc_text.left = item->rc_item.left + ntb_data->w_cell + GAP_BMP_TEXT_HORZ + 1; item->rc_text.right = item->rc_text.left + sz_text.cx; item->rc_text.top = item->rc_item.top; item->rc_text.bottom = item->rc_item.bottom; item->rc_item.right = item->rc_text.right + GAP_BMP_TEXT_HORZ + 1; } else { item->rc_item.right = item->rc_item.left + ntb_data->w_cell + 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -