📄 icontact.cpp
字号:
// "back" button in header bar
//TODO: back to categories from stScreenType == stList
if (ptMouseDown.y < rHeader.top + HEADER_CLICK_HEIGHT
&& ptMouseDown.x <= HEADER_CLICK_HEIGHT
&& stScreenType == stDetails) {
return 0;
}
// "+" button in header bar, or * in detail view
if (ptMouseDown.y < rHeader.top + HEADER_CLICK_HEIGHT
&& ptMouseDown.x >= rList.right - HEADER_CLICK_HEIGHT
&& (
stScreenType == stList && pListData->CanAdd()
|| stScreenType == stDetails && pListData->CanFavorite()
) ) {
return 0;
}
if (bScrolling) {
ScrollBar(y);
InvalidateRect(hWnd, &rList, false);
UpdateWindow(hWnd);
return 0;
}
if (abs(y - ptMouseDown.y) > SCROLL_THRESHOLD) {
if (stScreenType == stList)
pListData->UnselectItem();
else if (stScreenType == stDetails)
pListData->SelectDetail(-1);
bDragging = true;
}
// SCROLL
Scrolled = Scrolled - y + LastY;
LastY = y;
LastX = x;
Velocity = (double)(LastY - ptMouseDown.y) / (t - tStartTime);
tEndTime = t;
InvalidateRect(hWnd,
(stScreenType == stDetails ? &rContent : &rList), false);
UpdateWindow(hWnd);
return 0;
}
//-----------------------------------------------------------------------------
// DoLButtonUp - Process WM_LBUTTONUP message for window
//
LRESULT DoLButtonUp (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
POINT pt;
if (bTransitioning) {
return 0;
}
if (bScrolling) {
bScrolling = false;
InvalidateRect(hWnd, &rList, FALSE);
UpdateWindow(hWnd);
return 0;
}
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
int minScroll = 0;
int maxScroll = ListHeight > rListHeight ? ListHeight - rListHeight : 0;
// They clicked on the popup, no matter what screen
if (bDisplayingPopup) {
StartTransition(hWnd, ttKeyboardShrink, SHRINK_KEYBOARD_PERIOD);
int keyboardIndex = (pt.y / GroupHeight)
* (rScreen.right - rScreen.left) / GroupWidth
+ (pt.x - rScreen.left) / GroupWidth;
if (keyboardIndex < nKeyboardLetters) {
pListData->UnselectItem();
ScrollTo(hWnd, GroupPosition[keyboardIndex]);
}
}
// They clicked in the titlebar
// no matter what the screen type is
else if (PtInRect(&rTitlebar, ptMouseDown) && PtInRect(&rTitlebar, pt)) {
if (pSettings->doExitOnMinimize) {
DestroyWindow(hWnd);
}
else {
ShowWindow(hWnd, SW_MINIMIZE);
}
}
// They clicked in the bottom menus (in list screen)
else if (stScreenType == stList
&& PtInRect(&rMenubar, ptMouseDown) && PtInRect(&rMenubar, pt)) {
int tabWidth = (rMenubar.right - rMenubar.left) / 5;
if (pt.x < tabWidth * 3) {
SwitchTab(hWnd, pt.x / tabWidth);
}
else if (pt.x < tabWidth * 4) { // Dialer
RunDialer();
if (pSettings->doExitOnAction)
DestroyWindow(hWnd);
}
//else { // Voicemail
// CallVmail();
//}
else { // Keyboard
if (nCurrentTab == 2) {
StartTransition(hWnd, ttKeyboardExpand, EXPAND_KEYBOARD_PERIOD);
}
}
InvalidateRect(hWnd, &rMenubar, FALSE);
}
// They scrolled the screen up too far
else if (bDragging && Scrolled < minScroll) {
bDragging = false;
ScrollTo(hWnd, minScroll);
}
// They scrolled the screen down too far
else if (bDragging && Scrolled > maxScroll) {
bDragging = false;
ScrollTo(hWnd, maxScroll);
}
// now we're scrolling
else if (bDragging) {
SetTimer(hWnd, IDT_TIMER_SCROLL,
REFRESH_RATE, (TIMERPROC) NULL);
bScrolling = true;
bDragging = false;
return 0;
}
else {
int pos = 0;
// This is the normal *click* event
switch (stScreenType) {
case stList:
// "back" button in header bar
if (pt.y >= rHeader.top
&& pt.y < rHeader.top + HEADER_CLICK_HEIGHT
&& pt.x <= HEADER_CLICK_HEIGHT) {
//TODO: back to categories
}
// "+" button in header bar
else if (pt.y >= rHeader.top
&& pt.y < rHeader.top + HEADER_CLICK_HEIGHT
&& pt.x >= rList.right - HEADER_CLICK_HEIGHT
&& pListData->CanAdd()) {
pListData->AddItem();
// This will refresh the data in the current tab
SwitchTab(hWnd, nCurrentTab);
}
// Clicked a list item
else if (pt.y >= rList.top) {
pos = pt.y + Scrolled - rList.top;
pListData->SelectItem(GetPixelToItem(pos));
StartTransition(hWnd, ttSlideLeft, EXPAND_DETAILS_PERIOD);
}
break;
case stDetails:
// "back" button in header bar
if (pt.y >= rHeader.top
&& pt.y < rHeader.top + HEADER_CLICK_HEIGHT
&& pt.x <= HEADER_CLICK_HEIGHT) {
// Back to list
StartTransition(hWnd, ttSlideRight, EXPAND_DETAILS_PERIOD);
}
// "*" button in header bar
else if (pt.y >= rHeader.top
&& pt.y < rHeader.top + HEADER_CLICK_HEIGHT
&& pt.x >= rList.right - HEADER_CLICK_HEIGHT
&& pListData->CanFavorite()) {
pListData->ToggleFavorite();
pListData->PopulateDetails();
pListData->GetItem(pListData->GetCurrentItemIndex());
InvalidateRect(hWnd, &rHeader, false);
}
// Clicked a list item
else if (pt.y >= rList.top) {
// HANDLE SUBLIST EVENTS
pos = pt.y + Scrolled - rContent.top;
int subListIndex = pos / DEFAULT_ITEM_HEIGHT;
if (!pListData->SelectDetail(subListIndex))
break;
InvalidateRect(hWnd, &rContent, false);
UpdateWindow(hWnd);
// TODO: is this the best way to send SMS?
int column = pt.x > rList.right - 40 ? 2 : 1;
HRESULT hr = pListData->PerformCurrentDetailAction(column);
if (SUCCEEDED(hr)) {
if (pSettings->doExitOnAction)
DestroyWindow(hWnd);
else
pListData->PopulateDetails();
}
else {
SwitchTab(hWnd, nCurrentTab);
}
InvalidateRect(hWnd, &rScreen, FALSE);
}
pListData->SelectDetail(-1);
break;
}
}
UpdateWindow(hWnd);
return 0;
}
//-----------------------------------------------------------------------------
// DoTimer - Process WM_TIMER message for window
//
LRESULT DoTimer (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
DWORD t = ::GetTickCount();
DWORD dt = 0;
double s = 0.0;
int minScrolled = 0;
int maxScrolled = ListHeight <= rListHeight ? 0 : ListHeight - rListHeight;
switch (wParam) {
///// TIMER for scrolling
case IDT_TIMER_SCROLL:
// Time
dt = t - tEndTime;
// Velocity
if (Scrolled < minScrolled)
Velocity = (double)(Scrolled - minScrolled) / 2 / dt;
else if (Scrolled > maxScrolled)
Velocity = (double)(Scrolled - maxScrolled) / 2 / dt;
else {
double dv = Velocity * FRICTION_COEFF * dt;
if (fabs(dv) > fabs(Velocity))
Velocity = 0;
else
Velocity = Velocity - dv;
}
// Displacement
s = Velocity * dt;
if (s < 0 && s > -1 && Scrolled < minScrolled)
s = -1;
else if (s > 0 && s < 1 && Scrolled > maxScrolled)
s = 1;
// We're done scrolling
if ((int)s == 0) {
KillTimer(hWnd, IDT_TIMER_SCROLL);
bScrolling = false;
Velocity = 0;
}
Scrolled = Scrolled - (int)s;
tEndTime = t;
if (stScreenType == stList)
InvalidateRect(hWnd, &rList, false);
else
InvalidateRect(hWnd, &rContent, false);
break;
///// TIMER for scroll to
case IDT_TIMER_SCROLL_TO:
KillTimer(hWnd, IDT_TIMER_SCROLL);
Scroll_TimeCounter = (double)(t - Scroll_StartTime);
if (Scroll_TimeCounter < Scroll_Duration) {
bScrolling = true;
// Cubic
double amount = Scroll_Change
* (pow(Scroll_TimeCounter/Scroll_Duration - 1, 3) + 1);
Velocity = (amount - Scroll_StartPosition) / Scroll_TimeCounter;
Scrolled = Scroll_StartPosition + (int)amount;
}
else {
bScrolling = false;
Velocity = 0;
KillTimer(hWnd, IDT_TIMER_SCROLL_TO);
Scrolled = Scroll_Change + Scroll_StartPosition;
}
if (stScreenType == stList)
InvalidateRect(hWnd, &rList, false);
else
InvalidateRect(hWnd, &rContent, false);
break;
case IDT_TIMER_TRANSITION:
dTransitionPct = (double)(t - dwTransitionStart)
/ nTransitionDuration;
if (dTransitionPct >= 1.0) {
dTransitionPct = 1.0;
bTransitioning = false;
if (trTransitionType == ttSlideRight) {
stScreenType = stList;
Scrolled = ListScrolled;
pListData->UnselectItem();
CalculateHeights();
}
else if (trTransitionType == ttSlideLeft) {
stScreenType = stDetails;
CalculateHeights();
}
else if (trTransitionType == ttKeyboardExpand) {
bDisplayingPopup = true;
}
else if (trTransitionType == ttKeyboardShrink) {
bDisplayingPopup = false;
}
KillTimer(hWnd, IDT_TIMER_TRANSITION);
}
InvalidateRect(hWnd, &rScreen, false);
break;
case IDT_TIMER_LOADLIST:
pListData =
// Favorites
nCurrentTab == 0 ? (ListData *)new ListDataPoom(pSettings, true)
// Call Log
: nCurrentTab == 1 ? (ListData *)new ListDataCallLog(pSettings)
// Contacts
: (ListData *)new ListDataPoom(pSettings);
CalculateHeights();
InvalidateRect(hWnd, &rHeader, false);
KillTimer(hWnd, IDT_TIMER_LOADLIST);
Scrolled = -rListHeight;
ScrollTo(hWnd, 0);
break;
}
UpdateWindow(hWnd);
return 0;
}
//-----------------------------------------------------------------------------
// DoKeyDown - Process WM_KEYDOWN message for window
//
LRESULT DoKeyDown (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int top = 0;
int bot = 0;
bool bRepeating = (lParam & (1 << 30)) != 0;
int index;
if (bTransitioning) {
return 0;
}
switch (stScreenType) {
case stList:
if (bScrolling) {
KillTimer(hWnd, IDT_TIMER_SCROLL);
bScrolling = false;
Velocity = 0;
}
if (bRepeating) {
nKeyRepeatCount++;
if (nKeyRepeatCount < 10)
bRepeating = false;
else if (nKeyRepeatCount % 5 != 0)
return 0;
}
else {
nKeyRepeatCount = 0;
}
switch (wParam) {
case VK_UP:
pListData->SelectPreviousItem(
GetPixelToItem(Scrolled + rListHeight), bRepeating);
// make sure the selected item is visible
index = pListData->GetCurrentItemIndex();
top = StartPosition[index];
bot = StartPosition[index + 1];
if (bScrolling) {
Scrolled = max(0, min(StartPosition[index],
ListHeight - rListHeight));
}
else if (!bScrolling && (top < Scrolled
|| bot > Scrolled + rListHeight)) {
Scrolled = max(0, bot - rListHeight);
}
break;
case VK_DOWN:
pListData->SelectNextItem(
GetPixelToItem(Scrolled), bRepeating);
// make sure the selected item is visible
index = pListData->GetCurrentItemIndex();
top = StartPosition[index];
bot = StartPosition[index + 1];
if (bScrolling) {
Scrolled = max(0, min(StartPosition[index],
ListHeight - rListHeight));
}
else if (!bScrolling && (top < Scrolled
|| bot > Scrolled + rListHeight)) {
Scrolled = min(top, ListHeight - rListHeight);
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -