📄 icontact.cpp
字号:
case VK_LEFT:
if (nCurrentTab > 0)
SwitchTab(hWnd, nCurrentTab - 1);
break;
case VK_RIGHT:
if (nCurrentTab < 2)
SwitchTab(hWnd, nCurrentTab + 1);
break;
case VK_TACTION:
if (pListData->GetCurrentItemIndex() >= 0)
StartTransition(hWnd, ttSlideLeft,
EXPAND_DETAILS_PERIOD);
break;
}
InvalidateRect(hWnd, &rList, FALSE);
break;
case stDetails:
switch (wParam) {
case VK_BACK:
case VK_LEFT:
pListData->SelectDetail(-1);
StartTransition(hWnd, ttSlideRight);
break;
case VK_UP:
pListData->IncrementDetailIndex(-1);
pListData->IncrementDetailIndex(-1);
// there's no "break" here on purpose, code optimization
case VK_DOWN:
pListData->IncrementDetailIndex(1);
top = DEFAULT_ITEM_HEIGHT
* pListData->GetCurrentDetailIndex();
bot = top + DEFAULT_ITEM_HEIGHT;
if (top - Scrolled < 0)
ScrollTo(hWnd, max(0,
rContent.top - rContent.bottom + bot));
if (bot - Scrolled > rContent.bottom - rContent.top)
ScrollTo(hWnd, max(
ListHeight - rContent.bottom + rContent.top,
top));
break;
case VK_RIGHT:
case VK_TACTION:
HRESULT hr = pListData->PerformCurrentDetailAction(
wParam == VK_RIGHT ? 2 : 1);
if (SUCCEEDED(hr)) {
pListData->PopulateDetails();
if (pSettings->doExitOnAction)
DestroyWindow(hWnd);
}
break;
}
InvalidateRect(hWnd, &rContent, FALSE);
break;
}
UpdateWindow(hWnd);
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
// Uninitialize the COM classes
CoUninitialize();
// Quit
PostQuitMessage (0);
return 0;
}
//-----------------------------------------------------------------------------
// Screen Drawing Functions
//
void DrawScreenOn(HDC hdc, ScreenType st, HDC hdcTmp,
RECT rClip, int yListOffset) {
// MAIN CONTENT
switch (st) {
case stList:
if (rClip.bottom > rList.top || rClip.top < rList.bottom)
DrawListOn(hdc, hdcTmp, rList, yListOffset);
// MENU BAR
if (rClip.bottom > rMenubar.top) {
int rMenubarWidth = rMenubar.right - rMenubar.left;
int numItems = nCurrentTab == 2 ? 5 : 4;
// draw the background of the menu bar
// This will stretch the first column of the menu bar
// fully across the screen
StretchBlt(hdc, rMenubar.left, rMenubar.top,
rMenubarWidth, rMenubar.bottom - rMenubar.top,
hdcSkin, 0, MENU_BAR_Y_OFFSET, 1, MENU_BAR_HEIGHT, SRCCOPY);
// draw buttons
for (int i = 0; i < numItems; i++) {
int xdest = rMenubar.left
+ rMenubarWidth / 10 * (2 * i + 1) - 24;
int ydest = rMenubar.top;
int xsrc = i * 48;
int ysrc = i == nCurrentTab
? MENU_BAR_SELECTED_Y_OFFSET
: MENU_BAR_Y_OFFSET;
StretchBlt(hdc, xdest, ydest, 48, MENU_BAR_HEIGHT,
hdcSkin, xsrc, ysrc, 48, MENU_BAR_HEIGHT,
SRCCOPY);
}
}
break;
case stDetails:
DrawItemDetailsOn(hdc, pListData->GetCurrentItem(), yListOffset);
break;
}
// TITLE BAR
if (rClip.top < rTitlebar.bottom)
DrawTitlebarOn(hdc, rTitlebar, hdcSkin,
pSettings->rgbTitlebarBackground, pSettings->rgbTitlebarText,
pSettings->rgbTitlebarSignal, pSettings->rgbTitlebarBattery,
pSettings->rgbTitlebarBatteryCharge);
// HEADER BAR
DrawHeaderOn(hdc, st, rHeader, hdcSkin);
}
void DrawListOn(HDC hdc, HDC hdcTmp, RECT rList, int yOffset) {
int nFirstItem, nItem;
Data dItemTmp;
TCHAR buffer[16];
int count = NULL == pListData ? 0 : pListData->GetItemCount();
nFirstItem = nItem = yOffset < 0 ? 0 : GetPixelToItem(yOffset);
RECT rItem;
rItem = rList;
rItem.bottom = rList.top + StartPosition[nItem] - yOffset;
// ******* DRAW LIST BACKGROUND
FillRect(hdc, &rList, pSettings->hbrListBackground);
SetBkMode(hdc, TRANSPARENT);
// "About" at bottom of screen
SelectObject(hdc, SecondaryListFont);
SetTextAlign(hdc, TA_LEFT);
SetTextColor(hdc, pSettings->rgbListItemSelectedShadow);
ExtTextOut(hdc, rList.left + 2, rList.bottom - 15,
NULL, NULL, SZ_ABOUT, ABOUT_LENGTH, 0);
if (count == 0) {
//TODO: maybe indicate empty list?
return;
}
// ******* DRAW LIST ITEMS
while (nItem < count && rItem.bottom < rList.bottom) {
dItemTmp = pListData->GetItem(nItem);
rItem.top = rItem.bottom;
rItem.bottom = rItem.top + StartPosition[nItem+1]
- StartPosition[nItem];
if (nItem == pListData->GetCurrentItemIndex()
&& stScreenType == stList) {
DrawItemSelectedOn(hdc, dItemTmp, rItem);
}
else {
DrawItemOn(hdc, dItemTmp, rItem);
}
// ****** Group Header
if (stScreenType == stList
&& pListData->IsItemNewGroup(nItem)
&& dItemTmp.wcGroup && rItem.top >= rList.top) {
DrawGroupHeaderOn(hdc, nItem, rItem);
}
// Next nItem
nItem++;
}
// Special: Draw the group of the list nItem that's at the top of the list
dItemTmp = pListData->GetItem(nFirstItem);
if (dItemTmp.wcGroup && yOffset >= 0) {
RECT rTopGroup = {rList.left, 0, rList.right, DEFAULT_GROUP_HEIGHT};
DrawGroupHeaderOn(hdcTmp, nFirstItem, rTopGroup);
int nHeight = DEFAULT_GROUP_HEIGHT;
int nBottom = nHeight;
if (pListData->IsItemNewGroup(nFirstItem + 1)) {
nBottom = min(nBottom, StartPosition[nFirstItem + 1] - yOffset);
}
// account for the fact that the list
// doesn't start at the top of the screen
nBottom += rList.top;
int nLeft = rList.left;
int nWidth = rList.right - rList.left;
int nTop = nBottom - nHeight;
if (bScrolling && pSettings->doFastGraphics) {
BitBlt(hdc, nLeft, nTop, nWidth, nHeight, hdcTmp, 0, 0, SRCCOPY);
}
else {
BltAlpha(hdc, nLeft, nTop, nWidth, nHeight, hdcTmp, 200);
}
}
// Draw list indicator if scrolling quickly
if (bScrolling) {
SelectObject(hdc, ListIndicatorFont);
SetTextAlign(hdc, TA_CENTER);
SetTextColor(hdc, pSettings->rgbListGroupText);
SetBkMode(hdc, TRANSPARENT);
pListData->GetItemGroup(nFirstItem, buffer);
int length = _tcslen(buffer);
ExtTextOut(hdc, (rList.right - rList.left) / 2 + rList.left,
rList.top + 10, NULL, NULL, buffer, length, 0);
}
}
void DrawGroupHeaderOn(HDC hdc, int index, RECT rItem) {
RECT rHeader = rItem;
rHeader.bottom = rHeader.top + DEFAULT_GROUP_HEIGHT;
TCHAR buffer[10];
pListData->GetItemGroup(index, buffer);
int length = _tcslen(buffer);
// ****** GroupHeader background
FillRect(hdc, &rHeader, pSettings->hbrListGroupBackground);
// separator
RECT rSep = rHeader;
rSep.top = rHeader.bottom - LIST_SEPARATOR_HEIGHT;
FillRect(hdc, &rSep, pSettings->hbrListItemSeparator);
SetTextAlign(hdc, TA_LEFT);
// ******* Draw Group Header Text
SelectObject(hdc, GroupFont);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, pSettings->rgbListGroupText);
ExtTextOut(hdc, rItem.left + LIST_GROUP_ITEM_INDENT,
rHeader.top - 1 + ((DEFAULT_GROUP_HEIGHT - GROUP_ITEM_FONT_SIZE) / 2),
NULL, NULL, buffer, length, 0);
}
void DrawItemSelectedOn(HDC hdc, Data dItem, RECT rItem) {
// ******* DRAW ITEM BACKGROUND
DrawGradientGDI(hdc, rItem,
pSettings->rgbListItemSelectedBackground1,
pSettings->rgbListItemSelectedBackground2);
// ****** Draw Item Text
SelectObject(hdc, PrimaryListFont);
SetTextAlign(hdc, TA_LEFT);
// Item Shadow Text
SetTextColor(hdc, pSettings->rgbListItemSelectedShadow);
ExtTextOut(hdc, rItem.left + LIST_ITEM_INDENT,
rItem.bottom - ((DEFAULT_ITEM_HEIGHT + ITEM_FONT_SIZE) / 2),
ETO_OPAQUE, NULL, dItem.szPrimaryText, dItem.nPrimaryTextLength, 0);
// Item Text
SetTextColor(hdc, pSettings->rgbListItemSelectedText);
ExtTextOut(hdc, rItem.left + LIST_ITEM_INDENT,
rItem.bottom - 2 - ((DEFAULT_ITEM_HEIGHT + ITEM_FONT_SIZE) / 2),
ETO_OPAQUE, NULL, dItem.szPrimaryText, dItem.nPrimaryTextLength, 0);
}
void DrawItemOn(HDC hdc, Data dItem, RECT rItem) {
// Item Background
FillRect(hdc, &rItem, pSettings->hbrListItemBackground);
// separator
RECT rSep = rItem;
rSep.top = rItem.bottom - LIST_SEPARATOR_HEIGHT;
FillRect(hdc, &rSep, pSettings->hbrListItemSeparator);
SetTextAlign(hdc, TA_LEFT);
// Item Primary Text
SelectObject(hdc, PrimaryListFont);
SetTextColor(hdc, dItem.rgbPrimaryText);
ExtTextOut(hdc, rItem.left + LIST_ITEM_INDENT,
rItem.bottom - 2 - ((DEFAULT_ITEM_HEIGHT + ITEM_FONT_SIZE) / 2),
ETO_OPAQUE, NULL, dItem.szPrimaryText, dItem.nPrimaryTextLength, 0);
// Item Secondary Text
if (dItem.nSecondaryTextLength == 0)
return;
SelectObject(hdc, SecondaryListFont);
SetTextAlign(hdc, TA_RIGHT);
SetTextColor(hdc, pSettings->rgbListItemText);
ExtTextOut(hdc, rItem.right - LIST_ITEM_INDENT,
rItem.bottom - 2 - ((DEFAULT_ITEM_HEIGHT + ITEM_SECONDARY_FONT_SIZE) / 2),
ETO_OPAQUE, NULL, dItem.szSecondaryText, dItem.nSecondaryTextLength, 0);
}
void DrawItemDetailsOn(HDC hdc, Data dItem, int yOffset) {
int padding = 10;
int nameHeight = 0;
int nPictureSize = 0;
DataDetail dd = {0};
RECT rRow, rClip;
SelectObject(hdc, PrimaryListFont);
SetTextAlign(hdc, TA_LEFT);
SetBkMode(hdc, TRANSPARENT);
int iItemCount = pListData->GetItemDetailCount();
int iCurrentIndex = pListData->GetCurrentDetailIndex();
int iBitmapHeight = 0;
int iBitmapWidth = 0;
// ******* DRAW ITEM BACKGROUND
DrawGradientGDI(hdc, rContent,
pSettings->rgbListItemSelectedBackground1,
pSettings->rgbListItemSelectedBackground2);
// ******* Draw the current item's picture, if it exists
HBITMAP hBitmap = pListData->GetHBitmap();
if (NULL != hBitmap) {
iBitmapHeight = pListData->GetHBitmapHeight();
iBitmapWidth = pListData->GetHBitmapWidth();
int left = padding;
int top = (DEFAULT_ITEM_HEIGHT * 2 - iBitmapHeight) / 2 + rContent.top - yOffset;
int right = left + iBitmapWidth;
int bottom = top + iBitmapHeight;
// draw black square with a black border of 1
RECT rcBitmap = { left - 1, top - 1, right + 1, bottom + 1};
DrawRect(hdc, &rcBitmap, (COLORREF)0);
// paint the bitmap on the DC
TransparentImage(hdc, left, top, iBitmapWidth, iBitmapHeight,
hBitmap, 0, 0, iBitmapWidth, iBitmapHeight, (COLORREF)0);
}
// ******* Now, draw the item data
for (int c = 0; c < iItemCount; c++) {
dd = pListData->GetItemDetail(c);
if (dd.type == diNothing)
continue;
rRow.top = c * DEFAULT_ITEM_HEIGHT + rContent.top - yOffset;
rRow.bottom = rRow.top + DEFAULT_ITEM_HEIGHT;
if (dd.type == diName)
rRow.bottom += DEFAULT_ITEM_HEIGHT;
rRow.left = rContent.left;
if (rRow.top + yOffset < iBitmapHeight + rContent.top + padding / 2
&& iBitmapWidth > 0)
rRow.left += iBitmapWidth + padding;
rRow.right = rContent.right;
rClip.left = rRow.left + padding;
rClip.right = rRow.right - padding;
rClip.top = rRow.top + padding / 2 + 1;
rClip.bottom = rRow.bottom - padding / 2 - 1;
// If this is the first item of a new group of items, draw a rectangle
// around the group
if ((dd.type == diPhone
|| dd.type == diEmail
|| dd.type == diUrl
|| dd.type == diDetailsButton
|| dd.type == diCallButton
|| dd.type == diSmsButton
|| dd.type == diEditButton
|| dd.type == diSaveContactButton)
&& c > 0
&& pListData->GetItemDetail(c-1).type != dd.type) {
int nRows = 1;
while (c + nRows < iItemCount
&& pListData->GetItemDetail(c + nRows).type == dd.type)
nRows++;
SelectObject(hdc, pSettings->hbrListItemBackground);
SetTextColor(hdc, pSettings->rgbListItemText);
RoundRect(hdc, rRow.left + 6, rRow.top + 3,
rRow.right - 6,
rRow.bottom - 3 + DEFAULT_ITEM_HEIGHT * (nRows - 1),
padding, padding);
}
if (rRow.bottom < 0)
continue;
// Indicate the currently selected item
if (c == iCurrentIndex) {
SelectObject(hdc, pSettings->hbrListItemSelectedBackground);
RoundRect(hdc, rRow.left + 6, rRow.top + 3,
rRow.right - 6, rRow.bottom - 3, padding, padding);
SetTextColor(hdc, pSettings->rgbListItemSelectedText);
}
else {
SelectObject(hdc, GetStockObject(NULL_BRUSH));
SetTextColor(hdc, pSettings->rgbListItemText);
}
if (dd.type == diName) {
SelectObject(hdc, PrimaryListFont);
SetTextAlign(hdc, TA_LEFT | TA_TOP);
// Display the shadow
SetTextColor(hdc, pSettings->rgbListItemSelectedShadow);
ExtTextOut(hdc, rRow.left + padding + 1, rRow.top + padding + 1,
ETO_CLIPPED, &rClip, dd.text, _tcslen(dd.text), NULL);
// Display the name
SetTextColor(hdc, pSettings->rgbListItemSelectedText);
ExtTextOut(hdc, rRow.left + padding, rRow.top + padding,
ETO_CLIPPED, &rClip, dd.text, _tcslen(dd.text), NULL);
}
else if (dd.type == diCompany) {
SelectObject(hdc, SecondaryListFont);
SetTextColor(hdc, pSettings->rgbListItemSelectedText);
ExtTextOut(hdc, rRow.left + padding, rRow.top,
NULL, NULL, dd.text, _tcslen(dd.text), NULL);
}
else if (dd.type == diDetailsButton
|| dd.type == diEditButton
|| dd.type == diCallButton
|| dd.type == diSmsButton
|| dd.type == diSaveContactButton) {
SelectObject(hdc, PrimaryListFont);
SetTextAlign(hdc, TA_CENTER);
ExtTextOut(hdc, (rRow.right - rRow.left) / 2 + rRow.left,
(rRow.bottom - rRow.top - ITEM_FONT_SIZE) / 2 + rRow.top,
ETO_CLIPPED, &rClip, dd.text,
_tcslen(dd.text), 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -