📄 menubutton.c
字号:
// $Id: menubutton.c,v 1.4 2000/11/23 06:26:38 ymwei Exp $//// button.c: the Menu Button Control module.//// Written by Wei Yongming.//// Copyright (C) 2000, BluePoint Software.// Copyright (C) 2000, Wei Yongming.//// Current maintainer: Wei Yongming.//// Create date: 2000/11/16///*** 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.*/////// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------//// TODO:// #include <stdio.h>#include <stdlib.h>#include <string.h>#include <pthread.h>#include <semaphore.h>#ifdef __MINIGUI_LIB__ #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 "ctrlmisc.h"#else #include <minigui/common.h> #include <minigui/minigui.h> #include <minigui/gdi.h> #include <minigui/window.h> #include <minigui/control.h>#endif#define _USE_FIXSTR 1#include "menubutton.h"static int MenuButtonCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam);BOOL RegisterMenuButtonControl (void){ WNDCLASS WndClass; WndClass.spClassName = CTRL_MENUBTN; WndClass.dwStyle = 0; WndClass.hCursor = GetSystemCursor (IDC_ARROW); WndClass.iBkColor = PIXEL_lightgray; WndClass.WinProc = MenuButtonCtrlProc;#ifdef __MINIGUI_LIB__ return AddNewControlClass (&WndClass) == ERR_OK;#else return RegisterWindowClass (&WndClass);#endif}void MenuButtonControlCleanup (void){#ifndef __MINIGUI_LIB__ UnregisterWindowClass (CTRL_MENUBTN);#endif}static BOOL mbInitMenuButtonData (MENUBTNDATA* mb_data, int len){ int i; PMBITEM pmbi; mb_data->cur_sel = MB_INV_ITEM; // init item buffer. if (!(mb_data->buff_head = malloc (len * sizeof (MBITEM)))) return FALSE; mb_data->buff_len = len; mb_data->buff_tail = mb_data->buff_head + len; mb_data->free_list = mb_data->buff_head; pmbi = mb_data->free_list; for (i = 0; i < len - 1; i++) { pmbi->next = pmbi + 1; pmbi ++; } pmbi->next = NULL; return TRUE;}static void mbMenuButtonCleanUp (MENUBTNDATA* mb_data){ PMBITEM pmbi; PMBITEM next; pmbi = mb_data->first_item; while (pmbi) {#if _USE_FIXSTR FreeFixStr (pmbi->text);#else free (pmbi->text);#endif next = pmbi->next; if (pmbi < mb_data->buff_head || pmbi > mb_data->buff_tail) free (pmbi); pmbi = next; } free (mb_data->buff_head);}static void mbResetMenuButtonContent (PMENUBTNDATA mb_data){ int i; PMBITEM pmbi, next; mb_data->item_count = 0; mb_data->cur_sel = MB_INV_ITEM; pmbi = mb_data->first_item; while (pmbi) {#if _USE_FIXSTR FreeFixStr (pmbi->text);#else free (pmbi->text);#endif next = pmbi->next; if (pmbi < mb_data->buff_head || pmbi > mb_data->buff_tail) free (pmbi); pmbi = next; } mb_data->first_item = NULL; mb_data->free_list = mb_data->buff_head; pmbi = mb_data->free_list; for (i = 0; i < mb_data->buff_len - 1; i++) { pmbi->next = pmbi + 1; pmbi ++; } pmbi->next = NULL; return;}static PMBITEM mbAllocItem (PMENUBTNDATA mb_data){ PMBITEM pmbi; if (mb_data->free_list) { pmbi = mb_data->free_list; mb_data->free_list = pmbi->next; } else pmbi = (PMBITEM) malloc (sizeof (MBITEM)); return pmbi;}static void mbFreeItem (PMENUBTNDATA mb_data, PMBITEM pmbi){ if (pmbi < mb_data->buff_head || pmbi > mb_data->buff_tail) free (pmbi); else { pmbi->next = mb_data->free_list; mb_data->free_list = pmbi; }}static int mbAddNewItem (DWORD dwStyle, PMENUBTNDATA mb_data, PMBITEM newItem, int pos){ PMBITEM pmbi; PMBITEM insPosItem = NULL; int insPos = 0; newItem->next = NULL; if (!mb_data->first_item) insPosItem = NULL; else if (dwStyle & MBS_SORT) { pmbi = mb_data->first_item; if (strcmp (newItem->text, pmbi->text) < 0) { insPosItem = NULL; insPos = 0; } else { while (pmbi->next) { if (strcmp (newItem->text, pmbi->next->text) <= 0) break; pmbi = pmbi->next; insPos ++; } insPosItem = pmbi; } } else { pmbi = mb_data->first_item; if (pos < 0) { while (pmbi->next) { pmbi = pmbi->next; insPos ++; } insPosItem = pmbi; } else if (pos > 0) { int index = 0; while (pmbi->next) { if (pos == index) break; pmbi = pmbi->next; index ++; insPos ++; } insPosItem = pmbi; } } if (insPosItem) { pmbi = insPosItem->next; insPosItem->next = newItem; newItem->next = pmbi; insPos ++; } else { pmbi = mb_data->first_item; mb_data->first_item = newItem; newItem->next = pmbi; } mb_data->item_count ++; return insPos;}static PMBITEM mbRemoveItem (PMENUBTNDATA mb_data, int* pos){ int index = 0; PMBITEM pmbi, prev; if (!mb_data->first_item) return NULL; if (*pos < 0) { prev = mb_data->first_item; pmbi = mb_data->first_item; while (pmbi->next) { prev = pmbi; pmbi = pmbi->next; index ++; } if (pmbi == mb_data->first_item) { mb_data->first_item = mb_data->first_item->next; *pos = 0; return pmbi; } else { prev->next = pmbi->next; *pos = index; return pmbi; } } else if (*pos == 0) { pmbi = mb_data->first_item; mb_data->first_item = pmbi->next; return pmbi; } else { index = 0; prev = mb_data->first_item; pmbi = mb_data->first_item; while (pmbi->next) { if (*pos == index) break; prev = pmbi; pmbi = pmbi->next; index ++; } if (pmbi == mb_data->first_item) { mb_data->first_item = mb_data->first_item->next; *pos = 0; return pmbi; } else { prev->next = pmbi->next; *pos = index; return pmbi; } } return NULL;}static PMBITEM mbGetItem (PMENUBTNDATA mb_data, int pos){ int index = 0; PMBITEM pmbi; pmbi = mb_data->first_item; while (pmbi) { if (index == pos) break; index ++; pmbi = pmbi->next; } return pmbi;}#define _WIDTH_BORDER 4#define _WIDTH_MENUBAR 12#define _HEIGHT_MENUBAR 8#define _INTER_BARTEXT 4static void mbGetRects (HWND hWnd, DWORD dwStyle, RECT* prcClient, RECT* prcText, RECT* prcMenuBar){ GetClientRect (hWnd, prcClient); prcClient->right --; prcClient->bottom --; SetRect (prcText, prcClient->left + _WIDTH_BORDER, prcClient->top + _WIDTH_BORDER,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -