开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 27

MicroOS/MiniGUI

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (9)
标签 (1)
master
rel-3-2
drm
dev-3-4
complex-scripts
tmp-3-2-2
dev-3-2-2
rel-3-0
64b
ver-4-0-0
master
分支 (9)
标签 (1)
master
rel-3-2
drm
dev-3-4
complex-scripts
tmp-3-2-2
dev-3-2-2
rel-3-0
64b
ver-4-0-0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (9)
标签 (1)
master
rel-3-2
drm
dev-3-4
complex-scripts
tmp-3-2-2
dev-3-2-2
rel-3-0
64b
ver-4-0-0
MiniGUI
/
src
/
control
/
button.c
MiniGUI
/
src
/
control
/
button.c
button.c 30.93 KB
一键复制 编辑 原始数据 按行查看 历史
Vincent Wei 提交于 2019年07月15日 14:17 +08:00 . prepend excpetion list statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
///////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/*
* This file is part of MiniGUI, a mature cross-platform windowing
* and Graphics User Interface (GUI) support system for embedded systems
* and smart IoT devices.
*
* Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd.
* Copyright (C) 1998~2002, WEI Yongming
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* Or,
*
* As this program is a library, any link to this program must follow
* GNU General Public License version 3 (GPLv3). If you cannot accept
* GPLv3, you need to be licensed from FMSoft.
*
* If you have got a commercial license of this program, please use it
* under the terms and conditions of the commercial license.
*
* For more information about the commercial license, please refer to
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
/*
** button.c: the Button Control module.
**
** Create date: 1999年8月23日
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "common.h"
#ifdef _MGCTRL_BUTTON
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "ctrl/ctrlhelper.h"
#include "ctrl/button.h"
#include "cliprect.h"
#include "internals.h"
#include "ctrlclass.h"
#include "fixedmath.h"
#include "button_impl.h"
#include "ctrlmisc.h"
# define BTN_WIDTH_BMP 20
# define BTN_HEIGHT_BMP 20
# define BTN_INTER_BMPTEXT 2
#define BUTTON_STATUS(pctrl) (((PBUTTONDATA)((pctrl)->dwAddData2))->status)
#define BUTTON_DATA(pctrl) (((PBUTTONDATA)((pctrl)->dwAddData2))->data)
#define BUTTON_TYPE(pctrl) ((pctrl)->dwStyle & BS_TYPEMASK)
#define BUTTON_IS_AUTO(pctrl) \
(BUTTON_TYPE(pctrl) == BS_AUTO3STATE || \
BUTTON_TYPE(pctrl) == BS_AUTOCHECKBOX || \
BUTTON_TYPE(pctrl) == BS_AUTORADIOBUTTON)
#define BUTTON_IS_PUSHBTN(pctrl) \
(BUTTON_TYPE(pctrl) == BS_PUSHBUTTON || \
BUTTON_TYPE(pctrl) == BS_DEFPUSHBUTTON)
#define BUTTON_IS_RADIOBTN(pctrl) \
(BUTTON_TYPE(pctrl) == BS_AUTORADIOBUTTON || \
BUTTON_TYPE(pctrl) == BS_RADIOBUTTON)
#define BUTTON_IS_CHECKBTN(pctrl) \
(BUTTON_TYPE(pctrl) == BS_AUTOCHECKBOX || \
BUTTON_TYPE(pctrl) == BS_CHECKBOX)
#define BUTTON_IS_3STATEBTN(pctrl) \
(BUTTON_TYPE(pctrl) == BS_AUTOCHECKBOX || \
BUTTON_TYPE(pctrl) == BS_CHECKBOX)
#define BUTTON_SET_POSE(pctrl, status) \
do { \
BUTTON_STATUS(pctrl) &= ~BST_POSE_MASK; \
BUTTON_STATUS(pctrl) |= status; \
}while(0)
#define BUTTON_SET_CHECK(pctrl, check) \
do { \
BUTTON_STATUS(pctrl) &= ~BST_CHECK_MASK;\
BUTTON_STATUS(pctrl) |= check;\
}while(0)
#define BUTTON_GET_POSE(pctrl) \
(BUTTON_STATUS(pctrl) & BST_POSE_MASK)
#define BUTTON_GET_CHECK(pctrl) \
(BUTTON_STATUS(pctrl) & BST_CHECK_MASK)
#define BUTTON_OFFSET 1
static LRESULT ButtonCtrlProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static void btnGetRects (PCONTROL pctrl, RECT* prcClient,
RECT* prcContent,
RECT* prcBitmap);
/*when check a radio button, uncheck others in the same group*/
static void btnUncheckOthers (PCONTROL pctrl)
{
PCONTROL pGroupLeader = pctrl;
PCONTROL pOthers;
DWORD type = BUTTON_TYPE(pctrl);
while (pGroupLeader) {
if (pGroupLeader->dwStyle & WS_GROUP)
break;
pGroupLeader = pGroupLeader->prev;
}
if(!pGroupLeader)
return ;
pOthers = pGroupLeader;
do{
if (BUTTON_TYPE(pOthers)!= type)
break;
if ((pOthers != pctrl) &&
(BUTTON_GET_CHECK(pOthers)!= BST_UNCHECKED)) {
BUTTON_SET_CHECK(pOthers, BST_UNCHECKED);
InvalidateRect ((HWND)pOthers, NULL, TRUE);
}
pOthers = pOthers->next;
} while (pOthers && !(pOthers->dwStyle & WS_GROUP));
}
/*
* change_checked:
* This function change check status.
* return -1: can't change(the button in disable status)
* 0 : new check is old check, didn't change
* 1 : changed
* Author: XuguangWang
* Date: 2007年12月7日
*/
static int change_checked (PCONTROL pctrl, int check_status)
{
int old_status = BUTTON_STATUS(pctrl) & BST_CHECK_MASK;
/*if push button return*/
MG_CHECK_RET (BUTTON_TYPE(pctrl) != BS_PUSHBUTTON, -1);
MG_CHECK_RET (old_status != check_status, 0);
switch (pctrl->dwStyle & BS_TYPEMASK)
{
case BS_RADIOBUTTON:
case BS_AUTORADIOBUTTON:
MG_CHECK_RET (check_status != BST_INDETERMINATE, -1);
BUTTON_SET_CHECK (pctrl, check_status);
btnUncheckOthers (pctrl);
break;
case BS_CHECKBOX:
case BS_AUTOCHECKBOX:
MG_CHECK_RET (check_status != BST_INDETERMINATE, -1);
BUTTON_SET_CHECK (pctrl, check_status);
break;
case BS_3STATE:
case BS_AUTO3STATE:
BUTTON_SET_CHECK (pctrl, check_status);
break;
}
return 1;
}
/**
* switch_check:
* switch check status when the button is clicked
* return: new check status
* Author: XuguangWang
* Date: 2007年12月7日
*/
static int switch_check (PCONTROL pctrl)
{
int old_check = BUTTON_GET_CHECK(pctrl);
/*calc new ckeck status*/
switch (BUTTON_TYPE(pctrl))
{
case BS_RADIOBUTTON:
case BS_AUTORADIOBUTTON:
return BST_CHECKED;
case BS_CHECKBOX:
case BS_AUTOCHECKBOX:
return old_check==BST_CHECKED ? BST_UNCHECKED : BST_CHECKED;
case BS_3STATE:
case BS_AUTO3STATE:
return old_check==BST_UNCHECKED ? BST_CHECKED : (
BUTTON_GET_CHECK(pctrl) == BST_CHECKED ?
BST_INDETERMINATE : BST_UNCHECKED
);
default:
return -1;
}
}
/*change_status_from_pose
* change button status (pose and check status), and invalidate window.
* pose status -- normal, hilite, pressed(pushed), disable.
* check status -- unchecked, checked, indeterminate.
*
* param noti_pose_changing: indicating if the status changing is from key or
* mouse lbutton up and down.
* TRUE -- the button(if it is auto) should notify parent
* FALSE -- the pose changing is from mouse moving, so button need
* not notify parent
*
* param change_valid: if to normal(new_pose) is valid(it can change check status)
* TRUE -- key up or mouse lbutton up on the button
* FALSE -- key lbutton up is not on the button, so it's not a full
* click
* */
static void change_status_from_pose (PCONTROL pctrl, int new_pose,
BOOL noti_pose_changing, BOOL change_valid)
{
static int nt_code[3][3] = {
/*normal->nochange, hilite, pressed*/
{ 0, BN_HILITE, BN_PUSHED},
/*hilite->normal, nochange, pressed*/
{BN_UNHILITE, 0, BN_PUSHED},
/*pressed->normal, hilite, nochange*/
{BN_UNPUSHED, BN_UNPUSHED, 0},
};
DWORD dwStyle = pctrl->dwStyle;
int old_pose = BUTTON_GET_POSE(pctrl);
int new_check;
RECT rcClient;
RECT rcContent;
RECT rcBitmap;
/*make sure it can be changed, and avoid changing more than once*/
MG_CHECK (old_pose!= BST_DISABLE && old_pose != new_pose);
/*set new pose*/
BUTTON_SET_POSE(pctrl, new_pose);
if ((dwStyle & BS_NOTIFY) && noti_pose_changing)
{
if (new_pose != BST_DISABLE)
NotifyParent ((HWND)pctrl, pctrl->id,
nt_code[old_pose][new_pose]);
/*disable the button*/
else
{
/*before to disable, firstly to normal*/
switch (old_pose)
{
case BST_PUSHED:
NotifyParent ((HWND)pctrl, pctrl->id, BN_UNPUSHED);
case BST_HILITE:
NotifyParent ((HWND)pctrl, pctrl->id, BN_UNHILITE);
case BST_NORMAL:
NotifyParent ((HWND)pctrl, pctrl->id, BN_DISABLE);
break;
default:
assert (0);
break;
}
}
}
/*complete a click if the click if valid
* (mouse lbutton up in button )*/
if (old_pose == BST_PUSHED && new_pose != BST_DISABLE
&& change_valid)
{
if (!BUTTON_IS_PUSHBTN(pctrl) && BUTTON_IS_AUTO(pctrl))
{
new_check = switch_check(pctrl);
change_checked(pctrl, new_check);
}
NotifyParent ((HWND)pctrl, pctrl->id, BN_CLICKED);
}
/* DK: When the radio or check button state changes do not erase the background,
* and the prospects for direct rendering */
btnGetRects (pctrl, &rcClient, &rcContent, &rcBitmap);
if (BUTTON_IS_PUSHBTN(pctrl) || (pctrl->dwStyle & BS_PUSHLIKE))
InvalidateRect((HWND)pctrl, NULL, TRUE);
else
InvalidateRect((HWND)pctrl, &rcBitmap, FALSE);
}
/*btnGetRects:
* get the client rect(draw body of button), the content rect
* (draw contern), and bitmap rect(draw a little icon)
*/
static void btnGetRects (PCONTROL pctrl, RECT* prcClient,
RECT* prcContent,
RECT* prcBitmap)
{
GetClientRect ((HWND)pctrl, prcClient);
if (BUTTON_IS_PUSHBTN(pctrl) || (pctrl->dwStyle & BS_PUSHLIKE))
{
SetRect (prcContent, (prcClient->left + BTN_WIDTH_BORDER),
(prcClient->top + BTN_WIDTH_BORDER),
(prcClient->right - BTN_WIDTH_BORDER),
(prcClient->bottom - BTN_WIDTH_BORDER));
if (BUTTON_GET_POSE(pctrl) == BST_PUSHED)
{
prcContent->left ++;
prcContent->top ++;
prcContent->right ++;
prcContent->bottom++;
}
SetRectEmpty (prcBitmap);
return;
}
if (pctrl->dwStyle & BS_LEFTTEXT) {
SetRect (prcContent, 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 (prcContent, 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);
}
}
/**
* calc DrawText format from button style
*/
static int btnGetTextFmt (int dwStyle)
{
UINT dt_fmt;
if (dwStyle & BS_MULTLINE)
dt_fmt = DT_WORDBREAK;
else
dt_fmt = DT_SINGLELINE;
if ((dwStyle & BS_TYPEMASK) == BS_PUSHBUTTON
|| (dwStyle & BS_TYPEMASK) == BS_DEFPUSHBUTTON
|| (dwStyle & BS_PUSHLIKE))
dt_fmt |= DT_CENTER | DT_VCENTER;
else {
if ((dwStyle & BS_ALIGNMASK) == BS_RIGHT)
dt_fmt = DT_WORDBREAK | DT_RIGHT;
else if ((dwStyle & BS_ALIGNMASK) == BS_CENTER)
dt_fmt = DT_WORDBREAK | DT_CENTER;
else dt_fmt = DT_WORDBREAK | DT_LEFT;
if ((dwStyle & BS_ALIGNMASK) == BS_TOP)
dt_fmt |= DT_SINGLELINE | DT_TOP;
else if ((dwStyle & BS_ALIGNMASK) == BS_BOTTOM)
dt_fmt |= DT_SINGLELINE | DT_BOTTOM;
else dt_fmt |= DT_SINGLELINE | DT_VCENTER;
}
return dt_fmt;
}
/**
* draw bitmap content in button with BS_BITMAP style
*/
static void draw_bitmap_button (PCONTROL pctrl, HDC hdc, DWORD dwStyle,
RECT *prcText)
{
if (BUTTON_DATA(pctrl)) {
int x = prcText->left;
int y = prcText->top;
int w = RECTWP (prcText);
int h = RECTHP (prcText);
PBITMAP bmp = (PBITMAP)(BUTTON_DATA(pctrl));
RECT prcClient;
GetClientRect ((HWND)pctrl, &prcClient);
if (dwStyle & BS_REALSIZEIMAGE) {
x += (w - bmp->bmWidth) >> 1;
y += (h - bmp->bmHeight) >> 1;
w = h = 0;
if (bmp->bmWidth > RECTW(prcClient)){
x = prcClient.left + BTN_WIDTH_BORDER;
w = RECTW(prcClient) - 2*BTN_WIDTH_BORDER-1;
}
if (bmp->bmHeight > RECTH(prcClient)){
y = prcClient.top + BTN_WIDTH_BORDER;
h = RECTH(prcClient) - 2*BTN_WIDTH_BORDER-1;
}
}
else {
x = prcClient.top + BTN_WIDTH_BORDER;
y = prcClient.left + BTN_WIDTH_BORDER;
w = RECTW (prcClient) - 2*BTN_WIDTH_BORDER-1;
h = RECTH (prcClient) - 2*BTN_WIDTH_BORDER-1;
}
FillBoxWithBitmap (hdc, x, y, w, h, bmp);
}
}
/**
* draw bitmap content in button with BS_ICON style
*/
static void draw_icon_button(PCONTROL pctrl, HDC hdc, DWORD dwStyle, RECT *prcText)
{
if (BUTTON_DATA(pctrl)) {
int x = prcText->left;
int y = prcText->top;
int w = RECTWP (prcText);
int h = RECTHP (prcText);
HICON icon = (HICON)(BUTTON_DATA(pctrl));
RECT prcClient;
if (dwStyle & BS_REALSIZEIMAGE) {
int iconw, iconh;
GetIconSize (icon, &iconw, &iconh);
x += (w - iconw) >> 1;
y += (h - iconh) >> 1;
w = h = 0;
}
else {
GetClientRect ((HWND)pctrl, &prcClient);
x = prcClient.top;
y = prcClient.left;
w = RECTW (prcClient);
h = RECTH (prcClient);
}
DrawIcon (hdc, x, y, w, h, icon);
}
}
/**
* paint_content_focus:
* draw content in button and focusRect (if it have focus)
* Author: XuguangWang
* Date: 2007年12月7日
*/
static void paint_content_focus(HDC hdc, PCONTROL pctrl, RECT* prc_cont)
{
DWORD dt_fmt = 0;
DWORD fg_color = 0xFFFF;
DWORD text_pixel;
BOOL is_get_fg = FALSE;
BOOL is_get_fmt = FALSE;
gal_pixel old_pixel;
RECT focus_rc;
const WINDOW_ELEMENT_RENDERER* win_rdr;
/* Not used vars.
int status, type;
status = BUTTON_STATUS (pctrl);
type = BUTTON_TYPE (pctrl);
*/
win_rdr = GetWindowInfo((HWND)pctrl)->we_rdr;
/*draw button content*/
switch (pctrl->dwStyle & BS_CONTENTMASK)
{
case BS_BITMAP:
draw_bitmap_button(pctrl, hdc, pctrl->dwStyle, prc_cont);
break;
case BS_ICON:
draw_icon_button(pctrl, hdc, pctrl->dwStyle, prc_cont);
break;
default:
fg_color = GetWindowElementAttr((HWND)pctrl, WE_FGC_THREED_BODY);
is_get_fg = TRUE;
text_pixel = RGBA2Pixel(hdc, GetRValue(fg_color),
GetGValue(fg_color), GetBValue(fg_color),
GetAValue(fg_color));
old_pixel = SetTextColor(hdc, text_pixel);
dt_fmt = btnGetTextFmt(pctrl->dwStyle);
is_get_fmt = TRUE;
SetBkMode (hdc, BM_TRANSPARENT);
DrawText (hdc, pctrl->spCaption, -1, prc_cont, dt_fmt);
SetTextColor(hdc, old_pixel);
/*disable draw text*/
if ((BUTTON_GET_POSE(pctrl) == BST_DISABLE)
| (pctrl->dwStyle & WS_DISABLED))
win_rdr->disabled_text_out ((HWND)pctrl, hdc, pctrl->spCaption,
prc_cont, dt_fmt);
}
/*draw focus frame*/
if (BUTTON_STATUS(pctrl) & BST_FOCUS)
{
focus_rc = *prc_cont;
if (!BUTTON_IS_PUSHBTN(pctrl) &&
!(pctrl->dwStyle & BS_PUSHLIKE) &&
is_get_fmt)
{
dt_fmt |= DT_CALCRECT;
DrawText (hdc, pctrl->spCaption, -1, &focus_rc, dt_fmt);
}
if (!is_get_fg)
fg_color = GetWindowElementAttr((HWND)pctrl, WE_FGC_THREED_BODY);
win_rdr->draw_focus_frame(hdc, &focus_rc, fg_color);
}
}
/**
* paint_push_btn:
* draw push or pushlike button
* Author: XuguangWang
* Date: 2007年12月7日
*/
static void paint_push_btn (HDC hdc, PCONTROL pctrl)
{
const WINDOW_ELEMENT_RENDERER* win_rdr;
DWORD main_color;
RECT rcClient;
RECT rcContent;
RECT rcBitmap;
win_rdr = GetWindowInfo((HWND)pctrl)->we_rdr;
main_color = GetWindowElementAttr((HWND)pctrl, WE_MAINC_THREED_BODY);
btnGetRects (pctrl, &rcClient, &rcContent, &rcBitmap);
win_rdr->draw_push_button((HWND)pctrl, hdc, &rcClient, main_color,
0xFFFFFFFF, BUTTON_STATUS(pctrl));
paint_content_focus(hdc, pctrl, &rcContent);
}
#if 1
/*a matrix from button control status to renderer status*/
static int ctrlst_rdrst[12] = {
/*unckecked*/
LFRDR_BTN_STATUS_NORMAL,
LFRDR_BTN_STATUS_HILITE,
LFRDR_BTN_STATUS_PRESSED,
LFRDR_BTN_STATUS_DISABLED,
/*checked*/
LFRDR_BTN_STATUS_NORMAL|LFRDR_BTN_STATUS_SELECTED,
LFRDR_BTN_STATUS_HILITE|LFRDR_BTN_STATUS_SELECTED,
LFRDR_BTN_STATUS_PRESSED|LFRDR_BTN_STATUS_SELECTED,
LFRDR_BTN_STATUS_DISABLED|LFRDR_BTN_STATUS_SELECTED,
/*indeterminate*/
LFRDR_BTN_STATUS_DISABLED,
LFRDR_BTN_STATUS_DISABLED,
LFRDR_BTN_STATUS_DISABLED,
LFRDR_BTN_STATUS_DISABLED,
};
#else
static int ctrlst_rdrst[12] = {
/*unckecked*/
BST_NORMAL,
BST_HILITE,
BST_PUSHED,
BST_DISABLE,
/*checked*/
BST_NORMAL | BST_CHECKED,
BST_HILITE | BST_CHECKED,
BST_PUSHED | BST_CHECKED,
BST_DISABLE | BST_CHECKED,
/*indeterminate*/
BST_DISABLE,
BST_DISABLE,
BST_DISABLE,
BST_DISABLE,
};
#endif
/**
* paint_check_radio_btn:
* draw check button, radio button and 3state button
* Author: XuguangWang
* Date: 2007年12月7日
*/
static void paint_check_radio_btn (HDC hdc, PCONTROL pctrl)
{
const WINDOW_ELEMENT_RENDERER* win_rdr;
int rdr_st;
RECT rcClient;
RECT rcContent;
RECT rcBitmap;
win_rdr = GetWindowInfo((HWND)pctrl)->we_rdr;
/* Not used vars
gal_pixel text_pixel;
text_pixel = GetWindowElementPixelEx((HWND)pctrl, hdc, WE_FGC_WINDOW);
*/
rdr_st = ctrlst_rdrst [ BUTTON_STATUS (pctrl) &
(BST_POSE_MASK|BST_CHECK_MASK) ];
btnGetRects (pctrl, &rcClient, &rcContent, &rcBitmap);
if (BUTTON_IS_RADIOBTN(pctrl))
win_rdr->draw_radio_button((HWND)pctrl, hdc, &rcBitmap, rdr_st);
else
win_rdr->draw_check_button((HWND)pctrl, hdc, &rcBitmap, rdr_st);
/* DK: just draw text after background has been erased.*/
paint_content_focus(hdc, pctrl, &rcContent);
}
BOOL RegisterButtonControl (void)
{
WNDCLASS WndClass;
WndClass.spClassName = CTRL_BUTTON;
WndClass.dwStyle = WS_NONE;
WndClass.dwExStyle = WS_EX_NONE;
WndClass.hCursor = GetSystemCursor (IDC_ARROW);
WndClass.iBkColor =
GetWindowElementPixel (HWND_NULL, WE_MAINC_THREED_BODY);
WndClass.WinProc = ButtonCtrlProc;
return AddNewControlClass (&WndClass) == ERR_OK;
}
/**
* mouse_in_client:
* calc if mouse is in client
* Author: XuguangWang
* Date: 2007年12月7日
*/
static inline BOOL mouse_in_client(LPARAM lParam, PCONTROL pctrl)
{
int x, y;
x = LOSWORD(lParam);
y = HISWORD(lParam);
ScreenToClient (GetParent ((HWND)pctrl), &x, &y);
return (PtInRect ((PRECT) &(pctrl->cl), x, y));
}
static LRESULT ButtonCtrlProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PCONTROL pctrl;
DWORD dwStyle;
PBUTTONDATA pData;
pctrl = gui_Control(hWnd);
dwStyle = pctrl->dwStyle;
switch(uMsg)
{
case MSG_CREATE:
pData = (BUTTONDATA*) calloc (1, sizeof(BUTTONDATA));
SetWindowBkColor (hWnd, GetWindowElementPixel (hWnd,
WE_MAINC_THREED_BODY));
if (pData == NULL)
return -1;
pData->status = 0;
pData->data = pctrl->dwAddData;
pctrl->dwAddData2 = (DWORD) pData;
if (!BUTTON_IS_PUSHBTN(pctrl) && dwStyle & BS_CHECKED)
BUTTON_SET_CHECK(pctrl, BST_CHECKED);
break;
case MSG_DESTROY:
free ((void*) pctrl->dwAddData2);
break;
case BM_GETCHECK:
if (!BUTTON_IS_PUSHBTN(pctrl))
return BUTTON_GET_CHECK(pctrl);
else
return -1;
case BM_SETCHECK:
{
int set_ret;
UINT old_check;
// MG_CHECK_RET(BUTTON_IS_PUSHBTN(pctrl), -1);
old_check = BUTTON_GET_CHECK(pctrl);
set_ret = change_checked(pctrl,wParam);
if (set_ret == 1)
InvalidateRect (hWnd, NULL, TRUE);
return old_check;
}
case BM_GETSTATE:
return (int)(BUTTON_GET_POSE(pctrl));
case BM_SETSTATE:
{
DWORD old_pose = BUTTON_GET_POSE(pctrl);
if (wParam)
BUTTON_SET_POSE(pctrl, BST_PUSHED);
else
BUTTON_SET_POSE(pctrl, BST_NORMAL);
if (old_pose != BUTTON_GET_POSE(pctrl))
InvalidateRect (hWnd, NULL, TRUE);
return old_pose;
}
case BM_ENABLE:
{
if (wParam == FALSE)
{
/*disable a button*/
MG_CHECK_RET (BUTTON_GET_POSE(pctrl) != BST_DISABLE, 0);
change_status_from_pose (pctrl, BST_DISABLE, TRUE, FALSE);
}
else
{
/*enable a button*/
MG_CHECK_RET (BUTTON_GET_POSE(pctrl) == BST_DISABLE, 0);
BUTTON_SET_POSE (pctrl, BST_NORMAL);
NotifyParent(hWnd, pctrl->id, BN_ENABLE);
}
InvalidateRect (hWnd, NULL, TRUE);
return 0;
}
case BM_GETIMAGE:
{
int* image_type = (int*) wParam;
if (dwStyle & BS_BITMAP) {
if (image_type) {
*image_type = BM_IMAGE_BITMAP;
}
return (int)(BUTTON_DATA (pctrl));
}
else if (dwStyle & BS_ICON) {
if (image_type) {
*image_type = BM_IMAGE_ICON;
}
return (int)(BUTTON_DATA (pctrl));
}
}
return 0;
case BM_SETIMAGE:
{
int oldImage = (int)BUTTON_DATA (pctrl);
if (wParam == BM_IMAGE_BITMAP) {
pctrl->dwStyle &= ~BS_ICON;
pctrl->dwStyle |= BS_BITMAP;
}
else if (wParam == BM_IMAGE_ICON){
pctrl->dwStyle &= ~BS_BITMAP;
pctrl->dwStyle |= BS_ICON;
}
if (lParam) {
BUTTON_DATA (pctrl) = (DWORD)lParam;
InvalidateRect (hWnd, NULL, TRUE);
}
return oldImage;
}
break;
case BM_CLICK:
{
int new_check;
if (BUTTON_IS_AUTO(pctrl))
{
new_check = switch_check(pctrl);
change_checked(pctrl, new_check);
InvalidateRect (hWnd, NULL, TRUE);
}
NotifyParent (hWnd, pctrl->id, BN_CLICKED);
}
break;
case MSG_SETTEXT:
{
int len = strlen((char*)lParam);
FreeFixStr (pctrl->spCaption);
pctrl->spCaption = FixStrAlloc (len);
if (len > 0)
strcpy (pctrl->spCaption, (char*)lParam);
InvalidateRect (hWnd, NULL, TRUE);
break;
}
case BM_SETSTYLE:
pctrl->dwStyle &= 0xFFFF0000;
pctrl->dwStyle |= (DWORD)(wParam & 0x0000FFFF);
if (LOWORD (lParam))
InvalidateRect (hWnd, NULL, TRUE);
break;
case MSG_CHAR:
if (HIBYTE (wParam)==0 && BUTTON_IS_CHECKBTN (pctrl)) {
int old_check = BUTTON_GET_CHECK(pctrl);
if (LOBYTE(wParam) == '+' || LOBYTE(wParam) == '=')
BUTTON_SET_CHECK(pctrl, BST_CHECKED);
else if (LOBYTE(wParam) == '-')
BUTTON_SET_CHECK(pctrl, BST_UNCHECKED);
if (old_check != BUTTON_GET_CHECK(pctrl))
InvalidateRect (hWnd, NULL, TRUE);
}
break;
case MSG_ENABLE:
if (wParam && (dwStyle & WS_DISABLED))
pctrl->dwStyle &= ~WS_DISABLED;
else if (!wParam && !(dwStyle & WS_DISABLED))
pctrl->dwStyle |= WS_DISABLED;
else
return 0;
InvalidateRect (hWnd, NULL, TRUE);
return 0;
case MSG_GETDLGCODE:
switch (dwStyle & BS_TYPEMASK) {
case BS_CHECKBOX:
case BS_AUTOCHECKBOX:
return DLGC_WANTCHARS | DLGC_BUTTON;
case BS_RADIOBUTTON:
case BS_AUTORADIOBUTTON:
return DLGC_RADIOBUTTON | DLGC_BUTTON;
case BS_DEFPUSHBUTTON:
return DLGC_DEFPUSHBUTTON;
case BS_PUSHBUTTON:
return DLGC_PUSHBUTTON;
case BS_3STATE:
case BS_AUTO3STATE:
return DLGC_3STATE;
default:
return 0;
}
break;
case MSG_NCHITTEST:
{
int x, y;
x = (int)wParam;
y = (int)lParam;
if (PtInRect ((PRECT) &(pctrl->cl), x, y))
return HT_CLIENT;
else
return HT_OUT;
}
break;
case MSG_KILLFOCUS:
BUTTON_STATUS(pctrl) &= (~BST_FOCUS);
if (GetCapture() == hWnd) {
ReleaseCapture ();
BUTTON_SET_POSE(pctrl, BST_NORMAL);
}
if (dwStyle & BS_NOTIFY)
NotifyParent (hWnd, pctrl->id, BN_KILLFOCUS);
InvalidateRect (hWnd, NULL, TRUE);
break;
case MSG_SETFOCUS:
BUTTON_STATUS(pctrl) |= BST_FOCUS;
if (dwStyle & BS_NOTIFY)
NotifyParent (hWnd, pctrl->id, BN_SETFOCUS);
InvalidateRect (hWnd, NULL, TRUE);
break;
case MSG_KEYDOWN:
if (wParam != SCANCODE_SPACE
&& wParam != SCANCODE_ENTER
&& wParam != SCANCODE_KEYPADENTER)
break;
if (GetCapture () == hWnd)
break;
SetCapture (hWnd);
//FIXME not needed
//BUTTON_STATUS(pctrl) |= BST_FOCUS;
change_status_from_pose(pctrl, BST_PUSHED, TRUE, TRUE);
break;
case MSG_KEYUP:
{
if (wParam != SCANCODE_SPACE
&& wParam != SCANCODE_ENTER
&& wParam != SCANCODE_KEYPADENTER)
break;
if (GetCapture () == hWnd)
{
ReleaseCapture ();
change_status_from_pose(pctrl, BST_NORMAL, TRUE, TRUE);
}
}
break;
case MSG_LBUTTONDBLCLK:
if (dwStyle & BS_NOTIFY &&
BUTTON_GET_POSE(pctrl) != BST_DISABLE)
NotifyParent (hWnd, pctrl->id, BN_DBLCLK);
break;
case MSG_LBUTTONDOWN:
if (GetCapture () == hWnd)
break;
SetCapture (hWnd);
BUTTON_STATUS(pctrl) |= BST_FOCUS;
change_status_from_pose(pctrl, BST_PUSHED, TRUE, TRUE);
break;
case MSG_LBUTTONUP:
{
if (GetCapture() == hWnd)
{
ReleaseCapture ();
if (mouse_in_client(lParam, pctrl))
change_status_from_pose(pctrl, BST_HILITE, TRUE, TRUE);
else
change_status_from_pose(pctrl, BST_NORMAL, TRUE, FALSE);
}
return 0;
}
case MSG_MOUSEMOVEIN:
{
/*leave a button, nomralize it*/
if (!wParam)
change_status_from_pose(pctrl, BST_NORMAL, TRUE, FALSE);
/*because if lbutton downed on space out of the button,
* and then move to it, it will receive MSG_MOUSEMOVEIN,
* but it should not be hilited by MSG_MOUSEMOVEIN(wParam == TRUE)
* */
break;
}
case MSG_MOUSEMOVE:
{
/*left button is not downed*/
if (!(wParam & KS_LEFTBUTTON))
{
/*mouse not captured by keydowning on other button*/
if (GetCapture()==HWND_NULL)
change_status_from_pose(pctrl, BST_HILITE, TRUE, FALSE);
break;
}
/*the button capture mouse by mouse*/
if (GetCapture() == hWnd)
{
/*normal -- pushed, while lbutton is being downed*/
if (mouse_in_client(lParam, pctrl))
change_status_from_pose(pctrl, BST_PUSHED, FALSE, FALSE);
else
change_status_from_pose(pctrl, BST_NORMAL, FALSE, FALSE);
}
break;
}
case MSG_PAINT:
{
hdc = BeginPaint (hWnd);
SelectFont (hdc, GetWindowFont(hWnd));
if (BUTTON_IS_PUSHBTN(pctrl) || (pctrl->dwStyle & BS_PUSHLIKE))
paint_push_btn(hdc, pctrl);
else
paint_check_radio_btn(hdc, pctrl);
EndPaint (hWnd, hdc);
return 0;
}
default:
break;
}
return DefaultControlProc (hWnd, uMsg, wParam, lParam);
}
#endif /* _MGCTRL_BUTTON */
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

MiniGUI 是一个自由软件项目。其目标是提供一个快速、稳定、跨操作系统的图形用户界面(GUI)支持系统,尤其是基于 Linux/uClinux、eCos 以及其他传统 RTOS(如 VxWorks、ThreadX、uC/OS-II、Nucleus 等)的实时嵌入式操作系统。
暂无标签
GPL-3.0
使用 GPL-3.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/MicroOS/MiniGUI.git
git@gitee.com:MicroOS/MiniGUI.git
MicroOS
MiniGUI
MiniGUI
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /