📄 window.c
字号:
rcArea.right = rcBar.right;
if (PtInRect (&rcArea, x, y))
return SBPOS_RIGHTARROW;
if (x < (rcBar.left + pWin->hscroll.barStart
+ GetMainWinMetrics (MWM_CXHSCROLL)))
return SBPOS_LEFTSPACE;
if (x > (rcBar.left + pWin->hscroll.barStart + pWin->hscroll.barLen
+ GetMainWinMetrics (MWM_CXHSCROLL)))
return SBPOS_RIGHTSPACE;
return SBPOS_THUMB;
}
static int wndGetVScrollBarPos (PMAINWIN pWin, int x, int y)
{
RECT rcBar;
RECT rcArea;
if (pWin->vscroll.status & SBS_DISABLED)
return SBPOS_UNKNOWN;
wndGetVScrollBarRect (pWin, &rcBar);
if (!PtInRect (&rcBar, x, y))
return SBPOS_UNKNOWN;
rcArea.left = rcBar.left;
rcArea.right = rcBar.right;
// Left arrow area
rcArea.top = rcBar.top;
rcArea.bottom = rcArea.top + GetMainWinMetrics (MWM_CYVSCROLL);
if (PtInRect (&rcArea, x, y))
return SBPOS_UPARROW;
// Right arrow area
rcArea.top = rcBar.bottom - GetMainWinMetrics (MWM_CYVSCROLL);
rcArea.bottom = rcBar.bottom;
if (PtInRect (&rcArea, x, y))
return SBPOS_DOWNARROW;
if (y < (rcBar.top + pWin->vscroll.barStart
+ GetMainWinMetrics (MWM_CYVSCROLL)))
return SBPOS_UPSPACE;
if (y > (rcBar.top + pWin->vscroll.barStart + pWin->vscroll.barLen
+ GetMainWinMetrics (MWM_CYVSCROLL)))
return SBPOS_DOWNSPACE;
return SBPOS_THUMB;
}
#ifdef _PC3D_WINDOW_STYLE
static BOOL sbGetSBarArrowPos (PMAINWIN pWin, int location,
int* x, int* y, int* w, int* h)
{
RECT rcBar;
if (location < SBPOS_UPARROW)
wndGetHScrollBarRect (pWin, &rcBar);
else
wndGetVScrollBarRect (pWin, &rcBar);
*w = GetMainWinMetrics (MWM_CXHSCROLL);
*h = GetMainWinMetrics (MWM_CYHSCROLL);
switch (location) {
case SBPOS_LEFTARROW:
*x = rcBar.left;
*y = rcBar.top;
break;
case SBPOS_RIGHTARROW:
*x = rcBar.right - GetMainWinMetrics (MWM_CXHSCROLL) ;
*y = rcBar.top;
break;
case SBPOS_UPARROW:
*x = rcBar.left;
*y = rcBar.top;
break;
case SBPOS_DOWNARROW:
*x = rcBar.left;
*y = rcBar.bottom - GetMainWinMetrics (MWM_CYVSCROLL);
break;
default:
return FALSE;
}
*x -= pWin->left;
*y -= pWin->top;
return TRUE;
}
static BOOL sbGetButtonPos (PMAINWIN pWin, int location,
int* x, int* y, int* w, int* h)
{
RECT rc;
int iBorder;
int iCaption = 0, bCaption;
int iIconX = 0;
int iIconY = 0;
// scroll bar position
if (location & SBPOS_MASK)
return sbGetSBarArrowPos (pWin, location, x, y, w, h);
iBorder = wndGetBorder (pWin);
if (!(pWin->dwStyle & WS_CAPTION))
return FALSE;
if (pWin->hIcon)
{
iIconX = GetMainWinMetrics(MWM_ICONX);
iIconY = GetMainWinMetrics(MWM_ICONY);
}
iCaption = GetMainWinMetrics(MWM_CAPTIONY);
bCaption = iBorder + iCaption - 1;
rc.left = iBorder;
rc.top = iBorder;
rc.right = pWin->right - pWin->left - iBorder;
rc.bottom = iBorder + iCaption;
// close button
*x = rc.right - GetMainWinMetrics (MWM_SB_WIDTH);
*y = GetMainWinMetrics (MWM_SB_HEIGHT);
*w = GetMainWinMetrics (MWM_SB_WIDTH);
if (*y < bCaption) {
*y = iBorder + ((bCaption - *y)>>1);
*h = GetMainWinMetrics (MWM_SB_HEIGHT);
}
else {
*y = iBorder;
*h = iIconY;
}
if (!(pWin->dwExStyle & WS_EX_NOCLOSEBOX)) {
if (location == HT_CLOSEBUTTON)
return TRUE;
*x -= GetMainWinMetrics (MWM_SB_WIDTH);
*x -= GetMainWinMetrics (MWM_SB_INTERX)<<1;
}
if (pWin->dwStyle & WS_MAXIMIZEBOX) {
// restore/maximize button
if (location == HT_MAXBUTTON)
return TRUE;
*x -= GetMainWinMetrics (MWM_SB_WIDTH);
*x -= GetMainWinMetrics (MWM_SB_INTERX);
}
if (pWin->dwStyle & WS_MINIMIZEBOX) {
// minimize button.
if (location == HT_MINBUTTON)
return TRUE;
}
return FALSE;
}
static BOOL sbDownButton (PMAINWIN pWin, int downCode)
{
HDC hdc;
int x, y, w, h;
if (!sbGetButtonPos (pWin, downCode, &x, &y, &w, &h))
return FALSE;
hdc = GetDC ((HWND)pWin);
w += x - 1;
h += y - 1;
#if 0
Draw3DDownFrame (hdc, x, y, w, h, 0);
#else
SetPenColor (hdc, GetWindowElementColorEx ((HWND)pWin, WEC_FLAT_BORDER));
Rectangle (hdc, x, y, w, h);
SetPenColor (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
Rectangle (hdc, x + 1, y + 1, w - 1, h - 1);
#endif
ReleaseDC (hdc);
return TRUE;
}
static BOOL sbUpButton (PMAINWIN pWin, int downCode)
{
HDC hdc;
int x, y, w, h;
PBITMAP bmp = NULL;
int xo = 0, yo = 0, bw = 0, bh = 0;
if (!sbGetButtonPos (pWin, downCode, &x, &y, &w, &h))
return FALSE;
hdc = GetDC ((HWND)pWin);
switch (downCode) {
case HT_MAXBUTTON:
bmp = GetSystemBitmap (SYSBMP_CAPBTNS);
bw = bmp->bmWidth >> 2;
bh = bmp->bmHeight;
xo = yo = 0;
break;
case HT_MINBUTTON:
bmp = GetSystemBitmap (SYSBMP_CAPBTNS);
bw = bmp->bmWidth >> 2;
bh = bmp->bmHeight;
xo = bw; yo = 0;
break;
case HT_CLOSEBUTTON:
bmp = GetSystemBitmap (SYSBMP_CAPBTNS);
bw = bmp->bmWidth >> 2;
bh = bmp->bmHeight;
xo = (bw << 1) + bw; yo = 0;
break;
case SBPOS_UPARROW:
bmp = GetSystemBitmap (SYSBMP_ARROWS);
bw = bmp->bmWidth >> 2;
bh = bmp->bmHeight >> 1;
xo = yo = 0;
break;
case SBPOS_DOWNARROW:
bmp = GetSystemBitmap (SYSBMP_ARROWS);
bw = bmp->bmWidth >> 2;
bh = bmp->bmHeight >> 1;
xo = bw; yo = 0;
break;
case SBPOS_LEFTARROW:
bmp = GetSystemBitmap (SYSBMP_ARROWS);
bw = bmp->bmWidth >> 2;
bh = bmp->bmHeight >> 1;
xo = bw << 1; yo = 0;
break;
case SBPOS_RIGHTARROW:
bmp = GetSystemBitmap (SYSBMP_ARROWS);
bw = bmp->bmWidth >> 2;
bh = bmp->bmHeight >> 1;
xo = (bw << 1) + bw; yo = 0;
break;
}
if (bmp)
FillBoxWithBitmapPart (hdc, x, y, bw, bh, 0, 0, bmp, xo, yo);
ReleaseDC (hdc);
return TRUE;
}
#else
#define sbDownButton(pWin, downCode)
#define sbUpButton(pWin, downCode)
#endif
int MenuBarHitTest (HWND hwnd, int x, int y);
static void wndTrackMenuBarOnMouseMove(PMAINWIN pWin, int message,
int location, int x, int y)
{
PMENUBAR pMenuBar;
int oldBarItem;
int barItem;
pMenuBar = (PMENUBAR)(pWin->hMenu);
if (!pMenuBar) return;
oldBarItem = pMenuBar->hilitedItem;
if (location == HT_OUT) {
if (oldBarItem >= 0)
HiliteMenuBarItem ((HWND)pWin, oldBarItem, HMF_DEFAULT);
return;
}
barItem = MenuBarHitTest ((HWND)pWin, x, y);
if (barItem != oldBarItem) {
if (oldBarItem >= 0)
HiliteMenuBarItem ((HWND)pWin, oldBarItem, HMF_DEFAULT);
if (barItem >= 0) {
HiliteMenuBarItem ((HWND)pWin, barItem, HMF_UPITEM);
pMenuBar->hilitedItem = barItem;
pMenuBar->hiliteFlag = HMF_UPITEM;
}
else
pMenuBar->hilitedItem = -1;
}
}
static BOOL wndHandleHScrollBar (PMAINWIN pWin, int message, int x, int y)
{
static int downPos = SBPOS_UNKNOWN;
static int movePos = SBPOS_UNKNOWN;
static int sbCode;
static int oldBarStart;
static int oldThumbPos;
static int oldx;
int curPos;
RECT rcBar;
wndGetHScrollBarRect (pWin, &rcBar);
rcBar.left += GetMainWinMetrics (MWM_CXHSCROLL);
rcBar.right -= GetMainWinMetrics (MWM_CXHSCROLL);
curPos = wndGetHScrollBarPos (pWin, x, y);
if (curPos == SBPOS_UNKNOWN && downPos == SBPOS_UNKNOWN)
return FALSE;
switch( message )
{
case MSG_NCLBUTTONDOWN:
oldBarStart = pWin->hscroll.barStart;
oldThumbPos = pWin->hscroll.curPos;
oldx = x;
downPos = curPos;
movePos = curPos;
if (curPos == SBPOS_LEFTARROW) {
sbDownButton (pWin, curPos);
if (pWin->hscroll.curPos == pWin->hscroll.minPos)
break;
sbCode = SB_LINELEFT;
}
else if (curPos == SBPOS_RIGHTARROW) {
sbDownButton (pWin, curPos);
if (pWin->hscroll.curPos == pWin->hscroll.maxPos)
break;
sbCode = SB_LINERIGHT;
}
else if (curPos == SBPOS_LEFTSPACE) {
if (pWin->hscroll.curPos == pWin->hscroll.minPos)
break;
sbCode = SB_PAGELEFT;
}
else if (curPos == SBPOS_RIGHTSPACE) {
if (pWin->hscroll.curPos == pWin->hscroll.maxPos)
break;
sbCode = SB_PAGERIGHT;
}
else if (curPos == SBPOS_THUMB) {
sbCode = SB_THUMBTRACK;
break;
}
SendNotifyMessage ((HWND)pWin, MSG_HSCROLL, sbCode, 0);
SetAutoRepeatMessage ((HWND)pWin, MSG_HSCROLL, sbCode, 0);
break;
case MSG_NCLBUTTONUP:
if (sbCode == SB_THUMBTRACK && downPos == SBPOS_THUMB) {
int newBarStart = oldBarStart + x - oldx;
int newThumbPos = newBarStart
* (pWin->hscroll.maxPos - pWin->hscroll.minPos + 1)
/ (rcBar.right - rcBar.left) + pWin->hscroll.minPos;
if (newThumbPos < pWin->hscroll.minPos)
newThumbPos = pWin->hscroll.minPos;
if (newThumbPos > pWin->hscroll.maxPos)
newThumbPos = pWin->hscroll.maxPos;
if (newBarStart != oldBarStart)
SendNotifyMessage ((HWND)pWin,
MSG_HSCROLL, SB_THUMBPOSITION, newThumbPos);
downPos = SBPOS_UNKNOWN;
movePos = SBPOS_UNKNOWN;
break;
}
if (downPos != SBPOS_UNKNOWN) {
sbUpButton (pWin, curPos);
SendNotifyMessage ((HWND)pWin, MSG_HSCROLL, SB_ENDSCROLL, 0);
SetAutoRepeatMessage (HWND_DESKTOP, 0, 0, 0);
}
downPos = SBPOS_UNKNOWN;
movePos = SBPOS_UNKNOWN;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -