📄 button.c
字号:
// $Id: button.c,v 1.12 2000/11/20 09:41:46 ymwei Exp $//// button.c: the Button Control module.//// Copyright (C) 1999, 2000, Wei Yongming.//// Current maintainer: Wei Yongming./*** This library is free software; you can redistribute it and/or** modify it under the terms of the GNU Library General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This library 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** Library General Public License for more details.**** You should have received a copy of the GNU Library General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*//*** Alternatively, the contents of this file may be used under the terms ** of the Mozilla Public License (the "MPL License") in which case the** provisions of the MPL License are applicable instead of those above.*///// Note:// Originally by Zhao Jianghua.//// Create date: 1999/8/23//// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------// WEI Yongming 1999/10/27 Tsinghua Notify Message Fininshed// WEI Yongming 2000/02/24 Tsinghua Add MPL License Finished//// TODO:// #include <stdio.h>#include <stdlib.h>#include <string.h>#include <pthread.h>#include <semaphore.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"#include "button.h"#include "ctrlmisc.h"#ifndef lintstatic char fileid[] = "$Id: button.c,v 1.12 2000/11/20 09:41:46 ymwei Exp $";#endif#define BTN_WIDTH_BORDER 4#define BTN_WIDTH_BMP 14#define BTN_HEIGHT_BMP 13#define BTN_INTER_BMPTEXT 2static BITMAP sg_bmpButton; BOOL RegisterButtonControl (void){ WNDCLASS WndClass; if (!LoadSystemBitmap (&sg_bmpButton, "button")) { fprintf (stderr, "Load Button Bitmap failure!\n"); return FALSE; } WndClass.spClassName = "button"; WndClass.dwStyle = 0; WndClass.hCursor = GetSystemCursor (IDC_ARROW); WndClass.iBkColor = PIXEL_lightgray; WndClass.WinProc = ButtonCtrlProc; return AddNewControlClass (&WndClass) == ERR_OK;}void ButtonControlCleanup (void){ UnloadBitmap (&sg_bmpButton);}static void btnGetRects (HWND hWnd, DWORD dwStyle, RECT* prcClient, RECT* prcText, RECT* prcBitmap){ GetClientRect (hWnd, prcClient); prcClient->right --; prcClient->bottom --; SetRect (prcText, prcClient->left + BTN_WIDTH_BORDER, prcClient->top + BTN_WIDTH_BORDER, prcClient->right - BTN_WIDTH_BORDER, prcClient->bottom - BTN_WIDTH_BORDER); SetRectEmpty (prcBitmap); if ( ((dwStyle & BS_TYPEMASK) < BS_CHECKBOX) || (dwStyle & BS_PUSHLIKE)) return; if (dwStyle & BS_LEFTTEXT) { SetRect (prcText, prcClient->left + 1, prcClient->top + 1, prcClient->right - BTN_WIDTH_BMP - BTN_INTER_BMPTEXT, prcClient->bottom - 1); SetRect (prcBitmap, prcClient->right - BTN_WIDTH_BMP, prcClient->top + 1, prcClient->right - 1, prcClient->bottom - 1); } else { SetRect (prcText, prcClient->left + BTN_WIDTH_BMP + BTN_INTER_BMPTEXT, prcClient->top + 1, prcClient->right - 1, prcClient->bottom - 1); SetRect (prcBitmap, prcClient->left + 1, prcClient->top + 1, prcClient->left + BTN_WIDTH_BMP, prcClient->bottom - 1); }}static void btnGetTextBoundsRect (PCONTROL pCtrl, HDC hdc, DWORD dwStyle, const RECT* prcText, RECT* prcBounds){ UINT uFormat; *prcBounds = *prcText; if (dwStyle & BS_MULTLINE) uFormat = DT_WORDBREAK; else uFormat = DT_SINGLELINE; if ((dwStyle & BS_TYPEMASK) == BS_PUSHBUTTON || (dwStyle & BS_TYPEMASK) == BS_DEFPUSHBUTTON) uFormat |= DT_CENTER | DT_VCENTER; else { uFormat = DT_TOP | DT_LEFT; if ((dwStyle & BS_ALIGNMASK) == BS_LEFT) uFormat = DT_WORDBREAK | DT_LEFT; else if ((dwStyle & BS_ALIGNMASK) == BS_RIGHT) uFormat = DT_WORDBREAK | DT_RIGHT; else if ((dwStyle & BS_ALIGNMASK) == BS_CENTER) uFormat = DT_WORDBREAK | DT_CENTER; if ((dwStyle & BS_ALIGNMASK) == BS_TOP) uFormat = DT_SINGLELINE | DT_TOP; else if ((dwStyle & BS_ALIGNMASK) == BS_BOTTOM) uFormat = DT_SINGLELINE | DT_BOTTOM; else if ((dwStyle & BS_ALIGNMASK) == BS_VCENTER) uFormat = DT_SINGLELINE | DT_VCENTER; } uFormat |= DT_CALCRECT; DrawText (hdc, pCtrl->spCaption, -1, prcBounds, uFormat);}static void btnPaintContent (PCONTROL pCtrl, HDC hdc, DWORD dwStyle, RECT* prcText){ switch (dwStyle & BS_CONTENTMASK) { case BS_TEXT: case BS_LEFTTEXT: { UINT uFormat; if (dwStyle & BS_MULTLINE) uFormat = DT_WORDBREAK; else uFormat = DT_SINGLELINE; if ((dwStyle & BS_TYPEMASK) == BS_PUSHBUTTON || (dwStyle & BS_TYPEMASK) == BS_DEFPUSHBUTTON) uFormat |= DT_CENTER | DT_VCENTER; else { uFormat = DT_TOP | DT_LEFT; if ((dwStyle & BS_ALIGNMASK) == BS_LEFT) uFormat = DT_WORDBREAK | DT_LEFT; else if ((dwStyle & BS_ALIGNMASK) == BS_RIGHT) uFormat = DT_WORDBREAK | DT_RIGHT; else if ((dwStyle & BS_ALIGNMASK) == BS_CENTER) uFormat = DT_WORDBREAK | DT_CENTER; if ((dwStyle & BS_ALIGNMASK) == BS_TOP) uFormat = DT_SINGLELINE | DT_TOP; else if ((dwStyle & BS_ALIGNMASK) == BS_BOTTOM) uFormat = DT_SINGLELINE | DT_BOTTOM; else if ((dwStyle & BS_ALIGNMASK) == BS_VCENTER) uFormat = DT_SINGLELINE | DT_VCENTER; } SetBkColor (hdc, GetWindowBkColor ((HWND)pCtrl)); if (dwStyle & WS_DISABLED) { RECT rc = *prcText; SetBkMode (hdc, BM_TRANSPARENT); SetTextColor (hdc, PIXEL_lightwhite); OffsetRect (prcText, 1, 1); DrawText (hdc, pCtrl->spCaption, -1, prcText, uFormat); SetTextColor (hdc, PIXEL_darkgray); DrawText (hdc, pCtrl->spCaption, -1, &rc, uFormat); } else { SetTextColor (hdc, PIXEL_black); DrawText (hdc, pCtrl->spCaption, -1, prcText, uFormat); } } break; case BS_BITMAP: if (pCtrl->dwAddData) FillBoxWithBitmap (hdc, prcText->left, prcText->top, RECTWP (prcText), RECTHP (prcText), (PBITMAP)(pCtrl->dwAddData)); break; case BS_ICON: if (pCtrl->dwAddData) DrawIcon (hdc, prcText->left, prcText->top, RECTWP (prcText), RECTHP (prcText), (HICON)(pCtrl->dwAddData)); break; }}static void btnPaintNormalButton (PCONTROL pCtrl, HDC hdc, DWORD dwStyle, RECT* prcClient, RECT* prcText, RECT* prcBitmap){ switch (dwStyle & BS_TYPEMASK) { case BS_DEFPUSHBUTTON: SetPenColor (hdc, PIXEL_black); Rectangle (hdc, prcClient->left, prcClient->top, prcClient->right, prcClient->bottom); Draw3DControlFrame (hdc, prcClient->left + 1, prcClient->top + 1, prcClient->right - 1, prcClient->bottom - 1, GetWindowBkColor ((HWND)pCtrl), TRUE); break; case BS_PUSHBUTTON: Draw3DControlFrame (hdc, prcClient->left, prcClient->top, prcClient->right, prcClient->bottom, GetWindowBkColor ((HWND)pCtrl), TRUE); break; case BS_AUTORADIOBUTTON: case BS_RADIOBUTTON: if (dwStyle & BS_PUSHLIKE) { Draw3DControlFrame (hdc, prcClient->left, prcClient->top, prcClient->right, prcClient->bottom, GetWindowBkColor ((HWND)pCtrl), TRUE); break; } if (dwStyle & WS_DISABLED) { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, (BTN_WIDTH_BMP * 5), BTN_HEIGHT_BMP); } else { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, 0, BTN_HEIGHT_BMP); } break; case BS_3STATE: case BS_AUTO3STATE: case BS_AUTOCHECKBOX: case BS_CHECKBOX: if (dwStyle & BS_PUSHLIKE) { Draw3DControlFrame (hdc, prcClient->left, prcClient->top, prcClient->right, prcClient->bottom, GetWindowBkColor ((HWND)pCtrl), TRUE); break; } if (dwStyle & WS_DISABLED) { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, BTN_WIDTH_BMP * 5, 0); } else { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, 0, 0); } break;/* case BS_OWNERDRAW: break;*/ default: break; }}static void btnPaintCheckedButton (PCONTROL pCtrl, HDC hdc, DWORD dwStyle, RECT* prcClient, RECT* prcText, RECT* prcBitmap){ switch (dwStyle & BS_TYPEMASK) { case BS_AUTORADIOBUTTON: case BS_RADIOBUTTON: if (dwStyle & BS_PUSHLIKE) { Draw3DControlFrame (hdc, prcClient->left, prcClient->top, prcClient->right, prcClient->bottom, #if 0 GetWindowBkColor ((HWND)pCtrl),#else PIXEL_darkgray,#endif FALSE); break; } if (dwStyle & WS_DISABLED) { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, (BTN_WIDTH_BMP << 2), BTN_HEIGHT_BMP); } else { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, BTN_WIDTH_BMP, BTN_HEIGHT_BMP); } break; case BS_3STATE: case BS_AUTO3STATE: case BS_AUTOCHECKBOX: case BS_CHECKBOX: if (dwStyle & BS_PUSHLIKE) { Draw3DControlFrame (hdc, prcClient->left, prcClient->top, prcClient->right, prcClient->bottom, #if 0 GetWindowBkColor ((HWND)pCtrl),#else PIXEL_darkgray,#endif FALSE); break; } if (dwStyle & WS_DISABLED) { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, BTN_WIDTH_BMP << 2, 0); } else { FillBoxWithBitmapPart (hdc, prcBitmap->left, prcBitmap->top, BTN_WIDTH_BMP, BTN_HEIGHT_BMP, 0, 0, &sg_bmpButton, BTN_WIDTH_BMP, 0); } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -