📄 checklist.c
字号:
infoPtr->TextColor[Enabled]);
hOldFont = SelectObject(hDC,
infoPtr->hFont);
for (Item = FirstItem, CurrentIndex = VisibleFirstIndex;
Item != NULL && CurrentIndex <= LastTouchedIndex;
Item = Item->Next, CurrentIndex++)
{
TextRect.bottom = TextRect.top + infoPtr->ItemHeight - (2 * CI_TEXT_MARGIN_HEIGHT);
ItemRect.bottom = ItemRect.top + infoPtr->ItemHeight;
SetBrushOrgEx(hDC,
ItemRect.left,
ItemRect.top,
NULL);
if (Enabled && PrevEnabled != ((Item->State & CIS_DISABLED) != CIS_DISABLED))
{
PrevEnabled = ((Item->State & CIS_DISABLED) != CIS_DISABLED);
SetTextColor(hDC,
infoPtr->TextColor[PrevEnabled]);
}
#if SUPPORT_UXTHEME
ItemHovered = (Enabled && infoPtr->HoveredCheckItem == Item);
#endif
if (infoPtr->QuickSearchHitItem == Item)
{
COLORREF OldBkColor, OldFgColor;
SIZE TextSize;
SIZE_T TextLen, HighlightLen = wcslen(infoPtr->QuickSearchText);
/* highlight the quicksearch text */
if (GetTextExtentPoint32(hDC,
Item->Name,
HighlightLen,
&TextSize))
{
COLORREF HighlightTextColor, HighlightBackground;
RECT rcHighlight = TextRect;
HighlightTextColor = GetSysColor(COLOR_HIGHLIGHTTEXT);
HighlightBackground = GetSysColor(COLOR_HIGHLIGHT);
rcHighlight.right = rcHighlight.left + TextSize.cx;
InflateRect(&rcHighlight,
0,
CI_TEXT_SELECTIONMARGIN);
OldBkColor = SetBkColor(hDC,
HighlightBackground);
OldFgColor = SetTextColor(hDC,
HighlightTextColor);
/* draw the highlighted text */
DrawText(hDC,
Item->Name,
HighlightLen,
&rcHighlight,
DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
SetBkColor(hDC,
OldBkColor);
SetTextColor(hDC,
OldFgColor);
/* draw the remaining part of the text */
TextLen = wcslen(Item->Name);
if (HighlightLen < TextLen)
{
rcHighlight.left = rcHighlight.right;
rcHighlight.right = TextRect.right;
DrawText(hDC,
Item->Name + HighlightLen,
-1,
&rcHighlight,
DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
}
}
}
else
{
/* draw the text */
DrawText(hDC,
Item->Name,
-1,
&TextRect,
DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
}
CheckBox.top = TextRect.top;
CheckBox.bottom = TextRect.bottom;
/* draw the Allow checkbox */
IsPushed = (Enabled && Item == infoPtr->FocusedCheckItem && infoPtr->HasFocus &&
!(Item->State & CIS_ALLOWDISABLED) && infoPtr->FocusedCheckItemBox != CLB_DENY &&
infoPtr->FocusedPushed);
CheckBox.left = infoPtr->CheckBoxLeft[CLB_ALLOW] - ((TextRect.bottom - TextRect.top) / 2);
CheckBox.right = CheckBox.left + (TextRect.bottom - TextRect.top);
#if SUPPORT_UXTHEME
if (infoPtr->ThemeHandle != NULL)
{
INT BtnState = CalculateCheckBoxStyle(Item->State & CIS_ALLOW,
Enabled && !(Item->State & CIS_ALLOWDISABLED),
(ItemHovered && infoPtr->HoveredCheckItemBox != CLB_DENY),
IsPushed);
hDrawResult = DrawThemeBackground(infoPtr->ThemeHandle,
hDC,
BP_CHECKBOX,
BtnState,
&CheckBox,
NULL);
}
else
{
hDrawResult = E_FAIL;
}
/* draw the standard checkbox if no themes are enabled or drawing the
themeed control failed */
if (FAILED(hDrawResult))
#endif
{
DrawFrameControl(hDC,
&CheckBox,
DFC_BUTTON,
DFCS_BUTTONCHECK | DFCS_FLAT |
((Item->State & CIS_ALLOWDISABLED) || !Enabled ? DFCS_INACTIVE : 0) |
((Item->State & CIS_ALLOW) ? DFCS_CHECKED : 0) |
(IsPushed ? DFCS_PUSHED : 0));
}
if (Item == infoPtr->FocusedCheckItem && !(infoPtr->UIState & UISF_HIDEFOCUS) &&
infoPtr->HasFocus &&
infoPtr->FocusedCheckItemBox != CLB_DENY)
{
RECT rcFocus = CheckBox;
InflateRect (&rcFocus,
CI_TEXT_MARGIN_HEIGHT,
CI_TEXT_MARGIN_HEIGHT);
DrawFocusRect(hDC,
&rcFocus);
}
/* draw the Deny checkbox */
IsPushed = (Enabled && Item == infoPtr->FocusedCheckItem && infoPtr->HasFocus &&
!(Item->State & CIS_DENYDISABLED) && infoPtr->FocusedCheckItemBox == CLB_DENY &&
infoPtr->FocusedPushed);
CheckBox.left = infoPtr->CheckBoxLeft[CLB_DENY] - ((TextRect.bottom - TextRect.top) / 2);
CheckBox.right = CheckBox.left + (TextRect.bottom - TextRect.top);
#if SUPPORT_UXTHEME
if (infoPtr->ThemeHandle != NULL)
{
INT BtnState = CalculateCheckBoxStyle(Item->State & CIS_DENY,
Enabled && !(Item->State & CIS_DENYDISABLED),
(ItemHovered && infoPtr->HoveredCheckItemBox == CLB_DENY),
IsPushed);
hDrawResult = DrawThemeBackground(infoPtr->ThemeHandle,
hDC,
BP_CHECKBOX,
BtnState,
&CheckBox,
NULL);
}
else
{
hDrawResult = E_FAIL;
}
/* draw the standard checkbox if no themes are enabled or drawing the
themeed control failed */
if (FAILED(hDrawResult))
#endif
{
DrawFrameControl(hDC,
&CheckBox,
DFC_BUTTON,
DFCS_BUTTONCHECK | DFCS_FLAT |
((Item->State & CIS_DENYDISABLED) || !Enabled ? DFCS_INACTIVE : 0) |
((Item->State & CIS_DENY) ? DFCS_CHECKED : 0) |
(IsPushed ? DFCS_PUSHED : 0));
}
if (infoPtr->HasFocus && !(infoPtr->UIState & UISF_HIDEFOCUS) &&
Item == infoPtr->FocusedCheckItem &&
infoPtr->FocusedCheckItemBox == CLB_DENY)
{
RECT rcFocus = CheckBox;
InflateRect (&rcFocus,
CI_TEXT_MARGIN_HEIGHT,
CI_TEXT_MARGIN_HEIGHT);
DrawFocusRect(hDC,
&rcFocus);
}
TextRect.top += infoPtr->ItemHeight;
ItemRect.top += infoPtr->ItemHeight;
}
SelectObject(hDC,
hOldFont);
SetTextColor(hDC,
OldTextColor);
SetBrushOrgEx(hDC,
hOldBrushOrg.x,
hOldBrushOrg.y,
NULL);
}
}
static VOID
ChangeCheckItemFocus(IN PCHECKLISTWND infoPtr,
IN PCHECKITEM NewFocus,
IN UINT NewFocusBox)
{
if (NewFocus != infoPtr->FocusedCheckItem)
{
PCHECKITEM OldFocus = infoPtr->FocusedCheckItem;
infoPtr->FocusedCheckItem = NewFocus;
infoPtr->FocusedCheckItemBox = NewFocusBox;
if (OldFocus != NULL)
{
UpdateCheckItem(infoPtr,
OldFocus);
}
}
else
{
infoPtr->FocusedCheckItemBox = NewFocusBox;
}
if (NewFocus != NULL)
{
MakeCheckItemVisible(infoPtr,
NewFocus);
UpdateCheckItem(infoPtr,
NewFocus);
}
}
static VOID
UpdateCheckItemBox(IN PCHECKLISTWND infoPtr,
IN PCHECKITEM Item,
IN UINT ItemBox)
{
RECT rcClient;
INT VisibleFirst, VisibleItems;
INT Index = CheckItemToIndex(infoPtr,
Item);
if (Index != -1)
{
VisibleFirst = GetScrollPos(infoPtr->hSelf,
SB_VERT);
if (Index >= VisibleFirst)
{
GetClientRect(infoPtr->hSelf,
&rcClient);
VisibleItems = ((rcClient.bottom - rcClient.top) + infoPtr->ItemHeight - 1) / infoPtr->ItemHeight;
if (Index <= VisibleFirst + VisibleItems)
{
RECT rcUpdate;
rcUpdate.left = rcClient.left + infoPtr->CheckBoxLeft[ItemBox] - (infoPtr->ItemHeight / 2);
rcUpdate.right = rcUpdate.left + infoPtr->ItemHeight;
rcUpdate.top = ((Index - VisibleFirst) * infoPtr->ItemHeight);
rcUpdate.bottom = rcUpdate.top + infoPtr->ItemHeight;
RedrawWindow(infoPtr->hSelf,
&rcUpdate,
NULL,
RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN);
}
}
}
}
#if SUPPORT_UXTHEME
static VOID
ChangeCheckItemHotTrack(IN PCHECKLISTWND infoPtr,
IN PCHECKITEM NewHotTrack,
IN UINT NewHotTrackBox)
{
if (NewHotTrack != infoPtr->HoveredCheckItem)
{
PCHECKITEM OldHotTrack = infoPtr->HoveredCheckItem;
UINT OldHotTrackBox = infoPtr->HoveredCheckItemBox;
infoPtr->HoveredCheckItem = NewHotTrack;
infoPtr->HoveredCheckItemBox = NewHotTrackBox;
if (OldHotTrack != NULL)
{
UpdateCheckItemBox(infoPtr,
OldHotTrack,
OldHotTrackBox);
}
}
else
{
infoPtr->HoveredCheckItemBox = NewHotTrackBox;
}
if (NewHotTrack != NULL)
{
UpdateCheckItemBox(infoPtr,
NewHotTrack,
NewHotTrackBox);
}
}
#endif
static BOOL
ChangeCheckBox(IN PCHECKLISTWND infoPtr,
IN PCHECKITEM CheckItem,
IN UINT CheckItemBox)
{
NMCHANGEITEMCHECKBOX CheckData;
DWORD OldState = CheckItem->State;
DWORD CheckedBit = ((infoPtr->FocusedCheckItemBox == CLB_DENY) ? CIS_DENY : CIS_ALLOW);
BOOL Checked = (CheckItem->State & CheckedBit) != 0;
CheckData.OldState = OldState;
CheckData.NewState = (Checked ? OldState & ~CheckedBit : OldState | CheckedBit);
CheckData.CheckBox = infoPtr->FocusedCheckItemBox;
CheckData.Checked = !Checked;
if (NotifyControlParent(infoPtr,
CLN_CHANGINGITEMCHECKBOX,
&CheckData) != (LRESULT)-1)
{
CheckItem->State = CheckData.NewState;
}
return (CheckItem->State != OldState);
}
static VOID
DisplayCaret(IN PCHECKLISTWND infoPtr)
{
if (IsWindowEnabled(infoPtr->hSelf) && !infoPtr->ShowingCaret)
{
infoPtr->ShowingCaret = TRUE;
CreateCaret(infoPtr->hSelf,
NULL,
infoPtr->CaretWidth,
infoPtr->ItemHeight - (2 * CI_TEXT_MARGIN_HEIGHT));
ShowCaret(infoPtr->hSelf);
}
}
static VOID
RemoveCaret(IN PCHECKLISTWND infoPtr)
{
if (IsWindowEnabled(infoPtr->hSelf) && infoPtr->ShowingCaret)
{
infoPtr->ShowingCaret = FALSE;
HideCaret(infoPtr->hSelf);
DestroyCaret();
}
}
static VOID
KillQuickSearchTimers(IN PCHECKLISTWND infoPtr)
{
KillTimer(infoPtr->hSelf,
TIMER_ID_SETHITFOCUS);
KillTimer(infoPtr->hSelf,
TIMER_ID_RESETQUICKSEARCH);
}
static VOID
MapItemToRect(IN PCHECKLISTWND infoPtr,
IN PCHECKITEM CheckItem,
OUT RECT *prcItem)
{
INT Index = CheckItemToIndex(infoPtr,
CheckItem);
if (Index != -1)
{
RECT rcClient;
INT VisibleFirst;
GetClientRect(infoPtr->hSelf,
&rcClient);
VisibleFirst = GetScrollPos(infoPtr->hSelf,
SB_VERT);
prcItem->left = rcClient.left;
prcItem->right = rcClient.right;
prcItem->top = (Index - VisibleFirst) * infoPtr->ItemHeight;
prcItem->bottom = prcItem->top + infoPtr->ItemHeight;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -