?? icontact.cpp
字號:
// iContact.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "iContact.h"
#include "Settings.h"
#include "ListData.h"
#include "ListDataCallLog.h"
#include "ListDataPoom.h"
#include "GraphicFunctions.h"
#include "PhoneUtils.h"
#include "Titlebar.h"
//TODO: fix memory leak when updating contact pictures
//-----------------------------------------------------------------------------
// Global data
//
HINSTANCE hInst; // Program instance handle
Settings * pSettings = NULL;
ListData * pListData = NULL;
ScreenType stScreenType = stList;
int nCurrentTab = 2;
int ListHeight = 0;
int AverageItemHeight = DEFAULT_ITEM_HEIGHT;
int StartPosition[MAX_LIST_ITEMS];
int GroupPosition[ALPHABET_MAX_SIZE];
POINT ptMouseDown = { -1, -1 };
// Graphic
RECT rScreen;
int nScreenHeight;
RECT rTitlebar;
RECT rHeader;
RECT rMenubar;
RECT rList;
RECT rContent;
int rListHeight;
// UI Element Sizes. These can't be static because
// of different DPI devices
int TitlebarHeight = TITLEBAR_HEIGHT;
int DefaultItemHeight = DEFAULT_ITEM_HEIGHT;
int DefaultGroupHeight = DEFAULT_GROUP_HEIGHT;
int HeaderHeight = HEADER_HEIGHT;
int HeaderClickHeight = HEADER_CLICK_HEIGHT;
int MenuBarHeight = MENU_BAR_HEIGHT;
int MenuBarIconWidth = MENU_BAR_ICON_WIDTH;
int TitlebarFontSize = TITLEBAR_FONT_SIZE;
int ItemFontSize = ITEM_FONT_SIZE;
int ItemSecondaryFontSize = ITEM_SECONDARY_FONT_SIZE;
int KeyboardFontSize = KEYBOARD_FONT_SIZE;
int ItemDetailsFontSize = ITEM_DETAILS_FONT_SIZE;
int ItemDetailsPictureSize = ITEM_DETAILS_PICTURE_SIZE;
int ItemDetailsPadding = ITEM_DETAILS_PADDING;
int GroupItemFontSize = GROUP_ITEM_FONT_SIZE;
int ListIndicatorFontSize = LIST_INDICATOR_FONT_SIZE;
int ListItemIndent = LIST_ITEM_INDENT;
int ListGroupItemIndent = LIST_GROUP_ITEM_INDENT;
int ListSeparatorHeight = LIST_SEPARATOR_HEIGHT;
// Fonts
HFONT TitlebarFont;
HFONT PrimaryListFont;
HFONT SecondaryListFont;
HFONT GroupFont;
HFONT ItemDetailsFont;
HFONT ListIndicatorFont;
HFONT KeyboardFont;
// Screen buffers
HDC hdcMem = NULL;
HBITMAP hbmMem = NULL;
HDC hdcTmp = NULL;
HBITMAP hbmTmp = NULL;
HDC hdcSkin = NULL;
HBITMAP hbmSkin = NULL;
HDC hdcPage1 = NULL;
HBITMAP hbmPage1 = NULL;
HDC hdcPage2 = NULL;
HBITMAP hbmPage2 = NULL;
// Scrolling
bool bDragging = false;
bool bScrolling = false;
int Scrolled = 0;
int ListScrolled = 0;
int LastX;
int LastY;
int tStartTime;
int tEndTime;
double Velocity = 0;
int nKeyRepeatCount = 0;
// Scroll To
DWORD Scroll_StartTime = 0;
double Scroll_TimeCounter = 0.0;
int Scroll_StartPosition = 0;
int Scroll_Change = 0;
double Scroll_Duration = 0.0;
// Screen Transition
DWORD dwTransitionStart = 0;
double dTransitionPct = 0.0;
int nTransitionDuration = 0;
bool bTransitioning = false;
TransitionType trTransitionType = ttSlideLeft;
// Popup window
bool bDisplayingPopup = false;
PopupType ptPopupType = ptKeyboard;
// Keyboard Rows/Columns
TCHAR alphabet[ALPHABET_MAX_SIZE];
int nKeyboardLetters = 26;
int nKeyboardRows = 0;
int nKeyboardCols = 0;
int GroupWidth = 0; // Keyboard group width
int GroupHeight = 0; // Keyboard group height
// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
WM_PAINT, DoPaintMain,
WM_DESTROY, DoDestroyMain,
WM_ACTIVATE, DoActivate,
WM_SIZE, DoSize,
WM_LBUTTONDOWN, DoLButtonDown,
WM_MOUSEMOVE, DoMouseMove,
WM_LBUTTONUP, DoLButtonUp,
WM_TIMER, DoTimer,
WM_KEYDOWN, DoKeyDown,
WM_COMMAND, DoCommand,
WM_TITLEBAR, DoTitlebarCallback,
};
//=============================================================================
//
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
MSG msg;
HWND hwndMain;
// Initialize this instance.
hwndMain = InitInstance(hInstance, lpCmdLine, nCmdShow);
if (hwndMain == 0)
return 0x10;
// Application message loop
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
// Instance cleanup
return TermInstance (hInstance, msg.wParam);
}
//-----------------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow){
WNDCLASS wc;
HWND hWnd;
// Save program instance handle in global variable.
hInst = hInstance;
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
// If Windows Mobile, allow only one instance of the application.
hWnd = FindWindow (SZ_APP_NAME, NULL);
if (hWnd) {
SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01));
ParseCommandLine(hWnd, lpCmdLine);
return 0;
}
#endif
// Register application main window class.
wc.style = 0; // Window style
wc.lpfnWndProc = MainWndProc; // Callback function
wc.cbClsExtra = 0; // Extra class data
wc.cbWndExtra = 0; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL; // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = SZ_APP_NAME; // Window class name
if (RegisterClass (&wc) == 0) return 0;
// Create main window.
hWnd = CreateWindowEx(WS_EX_NODRAG, // Ex Style
SZ_APP_NAME, // Window class
SZ_APP_NAME, // Window title
WS_SYSMENU, // Style flags
// don't use WS_VISIBLE.
// Why not? It causes an "error report"
// Why? I don't know.
CW_USEDEFAULT, // x position
CW_USEDEFAULT, // y position
CW_USEDEFAULT, // Initial width
CW_USEDEFAULT, // Initial height
NULL, // Parent
NULL, // Menu, must be null
hInstance, // Application instance
NULL); // Pointer to create
// parameters
// Return fail code if window not created.
if (!IsWindow (hWnd)) return 0;
// Initialize COM libraries (for POOM)
if (FAILED(CoInitializeEx(NULL, 0)))
return 0;
// Additional initialization
// Perform DPI adjustments
HDC hdc = GetDC(hWnd);
int dpi = ::GetDeviceCaps(hdc, LOGPIXELSX);
if (dpi > DEFAULT_DPI) {
TitlebarHeight = MulDiv(TitlebarHeight, dpi, DEFAULT_DPI);
DefaultItemHeight = MulDiv(DefaultItemHeight, dpi, DEFAULT_DPI);
DefaultGroupHeight = MulDiv(DefaultGroupHeight, dpi, DEFAULT_DPI);
HeaderHeight = MulDiv(HeaderHeight, dpi, DEFAULT_DPI);
HeaderClickHeight = MulDiv(HeaderClickHeight, dpi, DEFAULT_DPI);
MenuBarHeight = MulDiv(MenuBarHeight, dpi, DEFAULT_DPI);
MenuBarIconWidth = MulDiv(MenuBarIconWidth, dpi, DEFAULT_DPI);
TitlebarFontSize = MulDiv(TitlebarFontSize, dpi, DEFAULT_DPI);
ItemFontSize = MulDiv(ItemFontSize, dpi, DEFAULT_DPI);
ItemSecondaryFontSize = MulDiv(ItemSecondaryFontSize, dpi, DEFAULT_DPI);
KeyboardFontSize = MulDiv(KeyboardFontSize, dpi, DEFAULT_DPI);
ItemDetailsFontSize = MulDiv(ItemDetailsFontSize, dpi, DEFAULT_DPI);
ItemDetailsPictureSize = MulDiv(ItemDetailsPictureSize, dpi, DEFAULT_DPI);
ItemDetailsPadding = MulDiv(ItemDetailsPadding, dpi, DEFAULT_DPI);
GroupItemFontSize = MulDiv(GroupItemFontSize, dpi, DEFAULT_DPI);
ListIndicatorFontSize = MulDiv(ListIndicatorFontSize, dpi, DEFAULT_DPI);
ListItemIndent = MulDiv(ListItemIndent, dpi, DEFAULT_DPI);
ListGroupItemIndent = MulDiv(ListGroupItemIndent, dpi, DEFAULT_DPI);
ListSeparatorHeight = MulDiv(ListSeparatorHeight, dpi, DEFAULT_DPI);
}
// Initialize titlebar callbacks
InitTitlebar(hWnd);
// Create fonts
TitlebarFont = BuildFont(TitlebarFontSize, FALSE, FALSE);
PrimaryListFont = BuildFont(ItemFontSize, FALSE, FALSE);
SecondaryListFont = BuildFont(ItemSecondaryFontSize, TRUE, FALSE);
ItemDetailsFont = BuildFont(ItemDetailsFontSize, FALSE, FALSE);
GroupFont = BuildFont(GroupItemFontSize, TRUE, FALSE);
ListIndicatorFont = BuildFont(ListIndicatorFontSize, TRUE, FALSE);
KeyboardFont = BuildFont(KeyboardFontSize, TRUE, FALSE);
// Create data lists
pSettings = new Settings();
SwitchTab(hWnd, 2);
InitSurface(hWnd);
// Standard show and update calls
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
ParseCommandLine(hWnd, lpCmdLine);
return hWnd;
}
//-----------------------------------------------------------------------------
// TermInstance - Program cleanup
//
int TermInstance (HINSTANCE hInstance, int nDefRC) {
return nDefRC;
}
//=============================================================================
// Message handling procedures for MainWindow
//
//-----------------------------------------------------------------------------
// MainWndProc - Callback function for application window
//
LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = 0; i < ARRAYSIZE(MainMessages); i++) {
if (wMsg == MainMessages[i].Code)
return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
int rScreenWidth = rScreen.right - rScreen.left;
int rScreenHeight = rScreen.bottom - rScreen.top;
hdc = BeginPaint (hWnd, &ps);
// rect is the region that needs to be painted
rect = ps.rcPaint;
if (bTransitioning) {
RECT rContent = rScreen;
if (trTransitionType == ttSlideRight
|| trTransitionType == ttSlideLeft) {
rContent.top = rTitlebar.bottom;
int rHeight = rContent.bottom - rContent.top;
int width1 = (int)(rScreenWidth * dTransitionPct);
if (trTransitionType == ttSlideLeft)
width1 = rScreenWidth - width1;
int width2 = rScreenWidth - width1;
BitBlt(hdcMem, rContent.left, rContent.top, width1, rHeight,
hdcPage1, width2, rContent.top, SRCCOPY);
BitBlt(hdcMem, width1, rContent.top, width2, rHeight,
hdcPage2, rContent.left, rContent.top, SRCCOPY);
BitBlt(hdcMem, rTitlebar.left, rTitlebar.top,
rScreenWidth, rTitlebar.bottom - rTitlebar.top,
hdcPage1, rTitlebar.left, rTitlebar.top, SRCCOPY);
}
else if (trTransitionType == ttKeyboardExpand
|| trTransitionType == ttKeyboardShrink) {
double cubic = pow(dTransitionPct - 1, 3) + 1;
if (trTransitionType == ttKeyboardShrink)
cubic = 1 - cubic;
int nKbWidth = (int)(rScreenWidth * cubic);
int nKbHeight = (int)(rScreenHeight * cubic);
BitBlt(hdcMem, rScreen.left, rScreen.top,
rScreenWidth, rScreenHeight,
hdcPage1, rScreen.left, rScreen.top, SRCCOPY);
// for faster rendering, don't stretch or alpha-ize the keyboard
if (pSettings->doFastGraphics) {
BitBlt(hdcMem, rScreen.right - nKbWidth,
rScreen.bottom - nKbHeight, nKbWidth, nKbHeight,
hdcPage2, 0, 0, SRCCOPY);
}
else {
BltAlpha(hdcMem, rScreen.right - nKbWidth,
rScreen.bottom - nKbHeight, nKbWidth, nKbHeight,
hdcPage2, 0, 0, rScreenWidth, rScreenHeight, 220);
}
}
}
// not transitioning
else {
DrawScreenOn(hdcMem, stScreenType, hdcTmp, rect, Scrolled);
if (bDisplayingPopup) {
switch (ptPopupType) {
case ptKeyboard:
// draw the keyboard
DrawKeyboardOn(hdcTmp, rScreen);
BltAlpha(hdcMem, rScreen.left, rScreen.top, rScreenWidth, rScreenHeight,
hdcTmp, 0, 0, rScreenWidth, rScreenHeight, 220);
break;
}
}
}
// Transfer everything to the actual screen
BitBlt(hdc, rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, hdcMem, rect.left, rect.top, SRCCOPY);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -