📄 menu.c
字号:
if (ptmi->flags & TPM_CENTERALIGN) {
ptmi->rc.left -= w >> 1;
ptmi->rc.right -= w >> 1;
}
if (ptmi->flags & TPM_RIGHTALIGN) {
ptmi->rc.left -= w;
ptmi->rc.right -= w;
}
h = ptmi->rc.bottom - ptmi->rc.top + 1;
if (ptmi->flags & TPM_VCENTERALIGN) {
ptmi->rc.top -= h >> 1;
ptmi->rc.bottom -= h >> 1;
}
if (ptmi->flags & TPM_BOTTOMALIGN) {
ptmi->rc.top -= h;
ptmi->rc.bottom -= h;
}
/* adjust the rect according to the screen */
if (ptmi->rc.right > g_rcScr.right) {
if ((prevtmi = ptmi->prev))
offx = prevtmi->rc.right - prevtmi->rc.left + w;
else
offx = ptmi->rc.right - g_rcScr.right;
if (ptmi->rc.left - offx < 0) {
ptmi->rc.left = 0;
ptmi->rc.right = w;
}
else {
ptmi->rc.left -= offx;
ptmi->rc.right -= offx;
}
}
if (ptmi->rc.bottom > g_rcScr.bottom) {
offy = ptmi->rc.bottom - g_rcScr.bottom;
if (ptmi->rc.top - offy < 0) {
ptmi->rc.top = 0;
ptmi->rc.bottom = h;
}
else {
ptmi->rc.top -= offy;
ptmi->rc.bottom -= offy;
}
}
#if defined(_FLAT_WINDOW_STYLE) && !defined(_GRAY_SCREEN)
ptmi->rc.right += 6;
ptmi->rc.bottom +=2;
#endif
}
static const char * menubmp_check =
"++++++++++++++++"
"++++++++++++..++"
"+++++++++++...++"
"++++++++++...+++"
"+++++++++...++++"
"++..++++...+++++"
"++...++...++++++"
"+++......+++++++"
"++++....++++++++"
"+++++..+++++++++"
"++++++++++++++++"
"++++++++++++++++"
;
static const char * menubmp_radio =
"++++++++++++++++"
"++++++++++++++++"
"++++++....++++++"
"+++++......+++++"
"++++........++++"
"++++........++++"
"++++........++++"
"++++........++++"
"+++++......+++++"
"++++++....++++++"
"++++++++++++++++"
"++++++++++++++++"
;
static const char * menubmp_sub =
"++++++++++++++++"
"++++++++++++++++"
"++++++.+++++++++"
"++++++..++++++++"
"++++++...+++++++"
"++++++....++++++"
"++++++....++++++"
"++++++...+++++++"
"++++++..++++++++"
"++++++.+++++++++"
"++++++++++++++++"
"++++++++++++++++"
;
#define MENUBMP_RADIO 1
#define MENUBMP_CHECK 2
#define MENUBMP_SUB 3
static PBITMAP mnuGetMenuItemBitmap (int id, BOOL hilite)
{
int i, j;
const char* menu_bmp;
gal_pixel fg, bg;
if (hilite) {
fg = GetWindowElementColor (FGC_MENUITEM_HILITE);
bg = GetWindowElementColor (BKC_MENUITEM_HILITE);
}
else {
fg = GetWindowElementColor (FGC_MENUITEM_NORMAL);
bg = GetWindowElementColor (BKC_MENUITEM_NORMAL);
}
switch (id) {
case MENUBMP_RADIO:
menu_bmp = menubmp_radio;
break;
case MENUBMP_CHECK:
menu_bmp = menubmp_check;
break;
case MENUBMP_SUB:
menu_bmp = menubmp_sub;
break;
default:
return NULL;
}
for (i = 0; i < 12; i++) {
for (j = 0; j < 16; j++) {
if (*menu_bmp == '+')
SetPixelInBitmap (&bmp_menuitem, j, i, bg);
else
SetPixelInBitmap (&bmp_menuitem, j, i, fg);
menu_bmp ++;
}
}
return &bmp_menuitem;
}
static PBITMAP mnuGetCheckBitmap (PMENUITEM pmi)
{
if (pmi->mnutype & MFT_BMPSTRING) {
if (pmi->mnustate & MFS_CHECKED)
return pmi->hbmpChecked;
else
return pmi->hbmpUnchecked;
}
else if (!(pmi->mnustate & MFS_CHECKED))
return NULL;
// default system check bitmap
if (pmi->mnutype & MFT_RADIOCHECK) {
if (pmi->mnustate & MFS_HILITE)
return mnuGetMenuItemBitmap (MENUBMP_RADIO, TRUE);
return mnuGetMenuItemBitmap (MENUBMP_RADIO, FALSE);
}
else {
if (pmi->mnustate & MFS_HILITE)
return mnuGetMenuItemBitmap (MENUBMP_CHECK, TRUE);
return mnuGetMenuItemBitmap (MENUBMP_CHECK, FALSE);
}
return NULL;
}
static PBITMAP mnuGetSubMenuBitmap (PMENUITEM pmi)
{
if (pmi->mnustate & MFS_HILITE)
return mnuGetMenuItemBitmap (MENUBMP_SUB, TRUE);
return mnuGetMenuItemBitmap (MENUBMP_SUB, FALSE);
}
static int mnuShowPopupMenu (PTRACKMENUINFO ptmi)
{
PMENUITEM pmi = ptmi->pmi;
PMENUITEM psubmi;
int x, y, offy;
int inter;
int mioffx;
int marginlx, marginrx;
int marginy;
PBITMAP bmp;
// save screen under this popup menu.
#ifdef _USE_NEWGAL
memset (&ptmi->savedbox, 0, sizeof (BITMAP));
if (!GetBitmapFromDC (HDC_SCREEN, ptmi->rc.left, ptmi->rc.top,
RECTW (ptmi->rc), RECTH (ptmi->rc), &ptmi->savedbox))
return -1;
#else
ptmi->savedbox = SaveCoveredScreenBox (ptmi->rc.left, ptmi->rc.top,
RECTW (ptmi->rc), RECTH (ptmi->rc));
if (ptmi->savedbox == NULL)
return -1;
#endif
inter = GetMainWinMetrics (MWM_INTERMENUITEMY);
mioffx = GetMainWinMetrics (MWM_MENUITEMOFFX);
marginlx = GetMainWinMetrics (MWM_MENULEFTMARGIN);
marginrx = GetMainWinMetrics (MWM_MENURIGHTMARGIN);
marginy = GetMainWinMetrics (MWM_MENUTOPMARGIN);
// draw background.
x = ptmi->rc.left;
y = ptmi->rc.top;
#ifdef _FLAT_WINDOW_STYLE
SetBrushColor (HDC_SCREEN, GetWindowElementColor(BKC_MENUITEM_NORMAL));
FillBox (HDC_SCREEN, ptmi->rc.left, ptmi->rc.top,
RECTW (ptmi->rc) - 1, RECTH (ptmi->rc) - 1);
SetPenColor (HDC_SCREEN, GetWindowElementColor (WEC_FLAT_BORDER));
Rectangle (HDC_SCREEN, ptmi->rc.left, ptmi->rc.top,
ptmi->rc.right - 2, ptmi->rc.bottom - 2);
#ifndef _GRAY_SCREEN
MoveTo (HDC_SCREEN, ptmi->rc.left + 1, ptmi->rc.bottom - 1);
LineTo (HDC_SCREEN, ptmi->rc.right - 1, ptmi->rc.bottom - 1);
LineTo (HDC_SCREEN, ptmi->rc.right - 1, ptmi->rc.top + 1);
#endif
#else
Draw3DThickFrameEx (HDC_SCREEN, HWND_DESKTOP,
ptmi->rc.left, ptmi->rc.top,
ptmi->rc.right, ptmi->rc.bottom,
DF_3DBOX_NORMAL | DF_3DBOX_FILL,
GetWindowElementColor(BKC_MENUITEM_NORMAL));
#endif
x = ptmi->rc.left + marginlx;
y = ptmi->rc.top + marginy;
if (pmi->mnutype & MFT_BITMAP) {
if (pmi->mnustate & MFS_CHECKED)
bmp = pmi->hbmpChecked;
else
bmp = pmi->hbmpUnchecked;
FillBoxWithBitmap (HDC_SCREEN, x, y,
bmp->bmWidth,
bmp->bmHeight,
bmp);
}
else if (pmi->mnutype & MFT_SEPARATOR) {
SetPenColor (HDC_SCREEN, GetWindowElementColor (WEC_3DFRAME_BOTTOM));
MoveTo (HDC_SCREEN,
x, y + (pmi->h>>1) - inter + 1);
LineTo (HDC_SCREEN,
ptmi->rc.right - marginrx, y + (pmi->h>>1) - inter + 1);
SetPenColor (HDC_SCREEN, GetWindowElementColor (WEC_3DFRAME_TOP));
MoveTo (HDC_SCREEN,
x, y + (pmi->h>>1) - inter + 2);
LineTo (HDC_SCREEN,
ptmi->rc.right - marginrx, y + (pmi->h>>1) - inter + 2);
}
else if (pmi->mnutype & MFT_OWNERDRAW) {
}
else {
SelectFont (HDC_SCREEN, GetSystemFont (SYSLOGFONT_MENU));
SetBkColor (HDC_SCREEN, GetWindowElementColor(BKC_MENUITEM_NORMAL));
if (pmi->type == TYPE_PPPMENU) {
SetTextColor (HDC_SCREEN, GetWindowElementColor(FGC_PPPMENUTITLE));
TextOut (HDC_SCREEN, x + mioffx, y + inter,
(char*)pmi->typedata);
SetPenColor (HDC_SCREEN, GetWindowElementColor (FGC_MENUITEM_NORMAL));
MoveTo (HDC_SCREEN,
x,
y + pmi->h - (inter<<1));
LineTo (HDC_SCREEN,
ptmi->rc.right - marginrx,
y + pmi->h - (inter<<1));
MoveTo (HDC_SCREEN,
x,
y + pmi->h - inter);
LineTo (HDC_SCREEN,
ptmi->rc.right - marginrx,
y + pmi->h - inter);
}
else {
int old_mode, bmp_w = mioffx;
// draw check bitmap
bmp = mnuGetCheckBitmap (pmi);
if (bmp) {
offy = (pmi->h - bmp->bmHeight)>>1;
FillBoxWithBitmap (HDC_SCREEN, x, y + offy,
bmp->bmWidth, pmi->h - (offy<<1), bmp);
bmp_w = MAX (bmp->bmWidth, mioffx);
}
old_mode = SetBkMode (HDC_SCREEN, BM_TRANSPARENT);
if (pmi->mnustate & MFS_DISABLED)
SetTextColor (HDC_SCREEN, GetWindowElementColor(FGC_MENUITEM_DISABLED));
else
SetTextColor (HDC_SCREEN, GetWindowElementColor(FGC_MENUITEM_NORMAL));
TextOut (HDC_SCREEN, x + bmp_w, y + inter,
(char*)pmi->typedata);
SetBkMode (HDC_SCREEN, old_mode);
if (pmi->submenu) {
bmp = mnuGetSubMenuBitmap (pmi);
offy = (pmi->h - bmp->bmHeight)>>1;
FillBoxWithBitmap (HDC_SCREEN,
ptmi->rc.right - mioffx - marginrx,
y + offy,
bmp->bmWidth, pmi->h - (offy<<1), bmp);
}
}
}
y += pmi->h;
if (pmi->type == TYPE_PPPMENU)
psubmi = pmi->submenu;
else
psubmi = pmi->next;
while (psubmi) {
if (psubmi->mnutype & MFT_BITMAP) {
if (psubmi->mnustate & MFS_CHECKED)
bmp = psubmi->hbmpChecked;
else
bmp = psubmi->hbmpUnchecked;
FillBoxWithBitmap (HDC_SCREEN, x, y,
bmp->bmWidth,
bmp->bmHeight,
bmp);
}
else if (psubmi->mnutype & MFT_SEPARATOR) {
SetPenColor (HDC_SCREEN, GetWindowElementColor (WEC_3DFRAME_BOTTOM));
MoveTo (HDC_SCREEN,
x, y + (psubmi->h>>1) - inter + 1);
LineTo (HDC_SCREEN,
ptmi->rc.right - marginrx, y + (psubmi->h>>1) - inter + 1);
SetPenColor (HDC_SCREEN, GetWindowElementColor (WEC_3DFRAME_TOP));
MoveTo (HDC_SCREEN,
x, y + (psubmi->h>>1) - inter + 2);
LineTo (HDC_SCREEN,
ptmi->rc.right - marginrx, y + (psubmi->h>>1) - inter + 2);
}
else if (pmi->mnutype & MFT_OWNERDRAW) {
}
else {
int old_mode, bmp_w = mioffx;
// draw check bitmap
bmp = mnuGetCheckBitmap (psubmi);
if (bmp) {
offy = (psubmi->h - bmp->bmHeight)>>1;
FillBoxWithBitmap (HDC_SCREEN, x, y + offy,
bmp->bmWidth, psubmi->h - (offy<<1), bmp);
bmp_w = MAX (bmp->bmWidth, mioffx);
}
// draw text.
SelectFont (HDC_SCREEN, GetSystemFont (SYSLOGFONT_MENU));
SetBkColor (HDC_SCREEN, GetWindowElementColor(BKC_MENUITEM_NORMAL));
old_mode = SetBkMode (HDC_SCREEN, BM_TRANSPARENT);
if (psubmi->mnustate & MFS_DISABLED)
SetTextColor (HDC_SCREEN, GetWindowElementColor(FGC_MENUITEM_DISABLED));
else
SetTextColor (HDC_SCREEN, GetWindowElementColor(FGC_MENUITEM_NORMAL));
TextOut (HDC_SCREEN, x + bmp_w, y + inter,
(char*)psubmi->typedata);
SetBkMode (HDC_SCREEN, old_mode);
if (psubmi->submenu) {
bmp = mnuGetSubMenuBitmap (psubmi);
offy = (psubmi->h - bmp->bmHeight)>>1;
FillBoxWithBitmap (HDC_SCREEN,
ptmi->rc.right - mioffx - marginrx,
y + offy,
bmp->bmWidth, psubmi->h - (offy<<1), bmp);
}
}
y += psubmi->h;
psubmi = psubmi->next;
}
return 0;
}
static void mnuUnhiliteMenu (PMENUITEM pmi)
{
if (pmi->type == TYPE_PPPMENU)
pmi = pmi->submenu;
else {
if (pmi->mnustate & MFS_HILITE)
pmi->mnustate &= ~MFS_HILITE;
pmi = pmi->next;
}
while (pmi) {
if (pmi->mnustate & MFS_HILITE)
pmi->mnustate &= ~MFS_HILITE;
pmi = pmi->next;
}
}
static void mnuCloseMenu (PTRACKMENUINFO ptmi)
{
PTRACKMENUINFO phead, plast, ptemp;
HMENU hmnu;
UINT flags;
// menu bar info
HWND hwnd;
PMENUBAR pmb;
int barPos;
flags = ptmi->flags;
hmnu = (HMENU)ptmi->pmi;
// get first tracking menu.
phead = ptmi;
while (phead->prev) {
phead = phead->prev;
}
pmb = phead->pmb;
hwnd = phead->hwnd;
barPos = phead->barPos;
// get last tracking menu.
plast = ptmi;
while (plast->next) {
plast = plast->next;
}
while (plast) {
ptemp = plast->prev;
mnuUnhiliteMenu (plast->pmi);
SendMessage (HWND_DESKTOP,
MSG_ENDTRACKMENU, 0, (LPARAM)plast);
plast = ptemp;
}
if (pmb && barPos >= 0)
HiliteMenuBarItem (hwnd, barPos, HMF_DEFAULT);
if (flags & TPM_DESTROY)
DestroyMenu (hmnu);
}
static PTRACKMENUINFO mnuHitTestMenu (PTRACKMENUINFO plast, int x, int y)
{
PTRACKMENUINFO ptemp;
// which popup menu mouse in.
ptemp = plast;
while (ptemp) {
if ( PtInRect(&ptemp->rc, x, y))
return ptemp;
ptemp = ptemp->prev;
}
return NULL;
}
static PMENUITEM mnuHitTestMenuItem (PTRACKMENUINFO ptmi, int x, int y)
{
PMENUITEM pmi = ptmi->pmi;
PMENUITEM psubmi;
RECT rc;
rc.left = ptmi->rc.left;
rc.right = ptmi->rc.right;
rc.top = ptmi->rc.top + GetMainWinMetrics (MWM_MENUTOPMARGIN);
rc.bottom = rc.top + pmi->h;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -