⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phonehis.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************
*
* Copyright  2002 National ASIC Center, All rights Reserved
*
* FILE NAME:			phonehis.c
* PROGRAMMER:			longn_qi
* Date of Creation:		2002/09/12
* 
* DESCRIPTION: 			
*
* NOTE:			 		 
*						 
*
* FUNCTIONS LIST:
* -------------------------------------------------------------------------
* BrowserPhoneHistory			Browser phone history.
* ReadPhoneHistory				Read Phone history content.
* ReadPhdbData					Convert history data from binary format to structure.
* WritePhdbData					Convert history data from structure to binary format.
* Data2ListCaption				Convert history data from structure to brief display format.
* Data2History					Convert history data from structure to full display format.
* RefreshPhoneHistoryLst		Update history display list content.
* SavePhoneHistory				Save history data to the database.
* 
* GLOBAL VARS LIST:
* 
*
**************************************************************************
*
* MODIFICATION HISTORY
*
*
* 2002/09/12	by longn_qi		Create the file
*								
*************************************************************************/
#include <stdio.h>
#include <string.h> 

#include "asixwin.h"
#include "asixapp.h"

#include "lmalloc.h"
#include "at.h"

#include "asix_ed.h"
#include "asix_lb.h"

#include "bitmap.h"

#include "phonehdb.h"

#include "phbook.h"
#include "sms.h"
#include "phonehis.h"
#include "call.h"

extern FIELDINDEXLIST	PhoneHDBFList[];

char	*PhHisTypeLst[PH_HIS_TYPE_NUM][2] =
{
	{ "0", "已拨" },
	{ "1", "已接" },
	{ "2", "未接" },
	{ "3", "拒接" },
};

void BrowserPhoneHistory( void )
{
	MSG 	msg;
	U32		hGC;
	U8		quit = 0;

#define	ITEM_NUM		8		// 可显示的记录项的个数

	// 窗口和控件
	U32		mainwin;			// 主窗口
	U32		bt_list[ITEM_NUM];	// 通话记录选择列表
	U32		lb_type;			// 通话记录类型下拉列表
	U32		bt_del, bt_search;	// 记录的操作按钮(删除记录、查找记录)
	U32		scroll;				// 滚动条
	U32		tskbar;				// 任务栏

	U16		sel_type = 0;		// 选择的记录类别(其值与列表项type_item对应)
	U16		sel_list = 0xFFFF;	// 选中的记录(显示区的相对位置,0xFFFF表示未选中任何记录)
	S8		bt_list_cap[ITEM_NUM][30];	// 记录内容的显示列表(循环列表,表头由变量list_head决定)
	U8		list_head = 0;		// 可显示记录列表首记录的位置(循环列表)
	U8		en_scroll = 0;		// 滚动显示使能标志,用于减少滚动时的闪烁
	U16		first_list = 0;		// 可显示的第一行

	// 数据库相关
	DBLACB	*lacb;				// 数据库局部访问控制块
	LOCALSEARCHLIST	*search_result;		// 数据库查找结果
	BYTE	*data;				// 数据块首地址

	FIELDVALUELIST	*list[ITEM_NUM], *list_data;	// 结构化的数据
	
 	// 临时变量
	U16		temp;
	U8		i, j;
	FIELDVALUELIST	*plist;
		
	struct LBOX_ITEM	type_item[] =	// 通话记录类型
	{
		ICON_ENABLE,	UNDERLINE,	"全部",
		ICON_ENABLE,	UNDERLINE,	"已拨",
		ICON_ENABLE,	UNDERLINE,	"已接",
		ICON_ENABLE,	UNDERLINE,	"未接",
		ICON_ENABLE,	UNDERLINE,	"拒接",
		ICON_END,		UNDERLINE,	NULL
	};

	// WINDOW ARRANGEMENT
	const	U16		form_w = PHY_LCD_W, form_h = PHY_LCD_H, form_x = 0, form_y = 0;
	const	U16		lb_w = 80, lb_h = 20, lb_x = form_x + 5, lb_y = form_y + 25;
	const	U16		bt_w = 20, bt_h = 20, bt_y = lb_y;
	const	U16		bt_list_w = 130, bt_list_h = 20, bt_list_x = lb_x, bt_list_y = lb_y + lb_h + 5;
	const	U16		scroll_w = 20, scroll_h = ITEM_NUM * bt_list_h, scroll_x = form_x + PHY_LCD_W - scroll_w - 5, scroll_y = bt_list_y;

	dbgprintf( "### Enter 通话记录 ###" );

	hGC = GetGC();
	
	mainwin = CreateWindow(	WNDCLASS_WIN,			
					"通话记录",			
					WS_OVERLAPPEDWINDOW,
					form_x,form_y,				
					form_w,form_h,
					0,				
					0,				
					NULL);			

	lb_type = CreateWindow(	WNDCLASS_LIST,
					NULL,
					WS_CHILD | LBS_POPUP,
					lb_x,lb_y,
					lb_w,lb_h,
					mainwin,
					0,
					type_item );

	
	temp = lb_x + lb_w + 5;
	bt_del = CreateWindow(	WNDCLASS_BUTTON,
					"\\删除",
					WS_CHILD | BS_ICON | BS_FLAT,
					temp,bt_y,
					bt_w,bt_h,
					mainwin,
					0,
					(void *)zi_delete );

	temp += bt_w + 5;
	bt_search = CreateWindow(	WNDCLASS_BUTTON,
					"\\查找",
					WS_CHILD | BS_ICON | BS_FLAT,
					temp,bt_y,
					bt_w,bt_h,
					mainwin,
					0,
					(void *)zi_find );

//	for( i = 0; i < ITEM_NUM; i++ )
//		bt_list_cap[i] = NULL;
	
	// 连接通话记录数据库
	lacb = LinkDataBase( PH_DATA_BASE );
	if( lacb == NULL )	// 连接数据库失败
	{
	}

	// 读取通话记录列表
	search_result = LocalFindRecord( lacb, PH_TIME_FIELD, NULL, GLOBAL_SEARCH );
	if( search_result == NULL )
	{
	}

	// 读取记录数据块,并结构化
	list_data = (FIELDVALUELIST *)Lmalloc( sizeof( FIELDVALUELIST ) * PH_INDEX_FIELD_NUM * ITEM_NUM );
	if( list_data == NULL )
	{
	}

	plist = list_data;
	for( i = 0; i < ITEM_NUM && i < search_result->num; i++ )
	{
		list[i] = plist;
		plist += PH_INDEX_FIELD_NUM;
//		if( search_result->head[i].data == NULL )
//		{
//			data = LocalReadRecord( lacb, search_result->head[i].index );
//			search_result->head[i].data = data;
//		}
//		else
//			data = search_result->head[i].data;

		data = search_result->head[i].data;
		ReadPhdbData( list[i], data );
	}
	for( ; i < ITEM_NUM; i++ )	// 数据项的个数较少
	{
		list[i] = plist;
		plist += PH_INDEX_FIELD_NUM;
		for( j = 0; j < PH_INDEX_FIELD_NUM; j++ )
			list[i][j].fieldvalue = NULL;
	}

	// 将结构化后的数据字符串化
	for( i = 0; i < ITEM_NUM; i++ )
	{
//		bt_list_cap[i][0] = '\0';
//		for( j = 0; j < PH_INDEX_FIELD_NUM; j++ )
//			strcat( bt_list_cap[i], list[i][j].fieldvalue );
		Data2ListCaption( bt_list_cap[i], list[i] );
	}
	
	// 显示最新的通话记录
	temp = bt_list_y;
	for( i = 0; i < ITEM_NUM; i++ )
	{
		bt_list[i] = CreateWindow( WNDCLASS_BUTTON, 
								bt_list_cap[i], 
								WS_CHILD | BS_TOOLBAR | BS_LEFT,
								bt_list_x,temp,
								bt_list_w,bt_list_h,
								mainwin,
								0,
								NULL);
		temp += bt_list_h;
	}

	scroll = CreateWindow(	WNDCLASS_SCROLL,
					NULL,
					WS_CHILD | SBS_VERT,
					scroll_x,scroll_y,
					scroll_w,scroll_h,
					mainwin,
					MAKELONG( 0, 0 ),
					NULL );
	
	if( search_result->num > ITEM_NUM )
		SetScrollRange( scroll, 0, (U16)( search_result->num - ITEM_NUM ) );
	else
	{
		for( i = (U8)search_result->num; i < ITEM_NUM; i++ )
			EnableWindow( bt_list[i], FALSE );
	}

	tskbar = CreateWindow( WNDCLASS_TSKBAR, 
					NULL, 
					WS_CHILD|TBS_TYPICAL, 
					0, 0, 
					0, 0,
					mainwin, 
					0, 
					NULL);
	
	while( !quit )
	{
		ASIXGetMessage( &msg, NULL, 0, 0 );
		switch( msg.message )
		{			
			case WM_COMMAND:	// 按钮消息
				for( i = 0; i < ITEM_NUM; i++ )
				{
					if( msg.lparam == bt_list[i] )	// 选择记录
					{
						if( i == sel_list )
						{
							ReadPhoneHistoryDetails( search_result, sel_type, (U16)( first_list + sel_list ) );
							
							// 列表可能有变动,须重新组织记录列表
							search_result = RefreshPhoneHistoryLst( lacb, list, sel_type, &first_list );

							list_head = 0;
							first_list = 0;
							sel_list = 0xFFFF;

							GroupOn( hGC );
							// 更新记录列表的显示
							for( i = 0, j = list_head; i < ITEM_NUM; i++, j++ )
							{
								if( j >= ITEM_NUM )
									j -= ITEM_NUM;
								Data2ListCaption( bt_list_cap[j], list[j] );
								SetWindowText( bt_list[i], bt_list_cap[j], NULL );						
							}

							if( search_result->num > ITEM_NUM )
							{
								SetScrollRange( scroll, 0, (U16)( search_result->num - ITEM_NUM ) );
								for( i = 0; i < ITEM_NUM; i++ )
									EnableWindow( bt_list[i], TRUE );
							}
							else
							{
								SetScrollRange( scroll, 0, 0 );
								for( i = 0; i < search_result->num; i++ )
									EnableWindow( bt_list[i], TRUE );
								for( i = (U8)search_result->num; i < ITEM_NUM; i++ )
									EnableWindow( bt_list[i], FALSE );
							}
							SetScrollPos( scroll, 0, 0, 0 );
							GroupOff( hGC, bt_list_x, bt_list_y, bt_list_x + bt_list_w + scroll_w -1, bt_list_y + bt_list_h * ITEM_NUM -1 );
						}
						else
						{
							if( sel_list != 0xFFFF )
								RepaintWindow( bt_list[sel_list], BS_INVERT );
							sel_list = i;
						}
						break;
					}
				}
				if( msg.lparam == bt_del )	// 删除记录
				{
					if( sel_list == 0xFFFF )
					{
						MessageBox( mainwin, "请先选择要删除的记录!", "提醒", MB_OK | MB_ICONINFORMATION );
					}
					else 
					{
						// 确认删除
						if( MessageBox( mainwin, "真的要删除该记录?", "提醒", MB_OKCANCEL | MB_ICONQUESTION ) == IDOK )
						{
							if( LocalDelRecord( lacb, search_result->head[first_list+sel_list].index ) != DB_ERROR )
							{
								DelOldSearchList( search_result );
								// 重新组织记录列表
								search_result = RefreshPhoneHistoryLst( lacb, list, sel_type, &first_list );
								list_head = 0;
								sel_list = 0xFFFF;

								GroupOn( hGC );
								// 更新记录列表的显示
								for( i = 0, j = list_head; i < ITEM_NUM; i++, j++ )
								{
									if( j >= ITEM_NUM )
										j -= ITEM_NUM;
									Data2ListCaption( bt_list_cap[j], list[j] );
									SetWindowText( bt_list[i], bt_list_cap[j], NULL );						
								}

								if( search_result->num > ITEM_NUM )
								{
									SetScrollRange( scroll, 0, (U16)( search_result->num - ITEM_NUM ) );
									for( i = 0; i < ITEM_NUM; i++ )
										EnableWindow( bt_list[i], TRUE );
								}
								else
								{
									SetScrollRange( scroll, 0, 0 );
									for( i = 0; i < search_result->num; i++ )
										EnableWindow( bt_list[i], TRUE );
									for( i = (U8)search_result->num; i < ITEM_NUM; i++ )
										EnableWindow( bt_list[i], FALSE );
								}
								SetScrollPos( scroll, 0, 0, 0 );
								GroupOff( hGC, bt_list_x, bt_list_y, bt_list_x + bt_list_w + scroll_w -1, bt_list_y + bt_list_h * ITEM_NUM -1 );
							}
						}
					}
				}
				else if( msg.lparam == bt_search )	// 查找记录
				{
					MessageBox( mainwin, "该功能尚未开通!", "谢谢使用", MB_OK | MB_ICONINFORMATION );
				}
				break;
			case WM_LISTBOX:	// 下拉列表框消息
				if( msg.lparam == lb_type )
				{
					if( sel_type == msg.wparam )	// 类型选择未改变
						break;

					// 删除旧记录列表
					DelOldSearchList( search_result );
					
					// 组织新记录列表
					sel_type = msg.wparam;
					search_result = RefreshPhoneHistoryLst( lacb, list, sel_type, &first_list );
					list_head = 0;
					sel_list = 0xFFFF;

					GroupOn( hGC );
					// 更新记录列表的显示
					for( i = 0, j = list_head; i < ITEM_NUM; i++, j++ )
					{
						if( j >= ITEM_NUM )
							j -= ITEM_NUM;
						Data2ListCaption( bt_list_cap[j], list[j] );
						SetWindowText( bt_list[i], bt_list_cap[j], NULL );						
					}

					SetScrollPos( scroll, 0, 0, 0 );
					if( search_result->num > ITEM_NUM )
					{
						SetScrollRange( scroll, 0, (U16)( search_result->num - ITEM_NUM ) );
						for( i = 0; i < ITEM_NUM; i++ )
							EnableWindow( bt_list[i], TRUE );
					}
					else
					{
						SetScrollRange( scroll, 0, 0 );
						for( i = 0; i < search_result->num; i++ )
							EnableWindow( bt_list[i], TRUE );
						for( i = (U8)search_result->num; i < ITEM_NUM; i++ )
							EnableWindow( bt_list[i], FALSE );
					}
					GroupOff( hGC, bt_list_x, bt_list_y, bt_list_x + bt_list_w + scroll_w -1, bt_list_y + bt_list_h * ITEM_NUM -1 );
				}
				break;
			case WM_VSCROLL:	// 滚动条消息
				if( msg.lparam == scroll )
				{				
					U8	en_set_sb_pos = 1;

					sel_list = 0xFFFF;
					switch(msg.wparam)
					{
						case   SB_LINEDOWN:	// 下翻一行
							if( first_list + ITEM_NUM < search_result->num )
							{
								// 读取下一个记录项
								data = search_result->head[first_list+ITEM_NUM].data;
								ReadPhdbData( list[list_head], data );
								// 滚动
								first_list++;
								list_head++;
								if( list_head == ITEM_NUM )
									list_head = 0;
								en_scroll = 1;
							}
							break;
						case    SB_LINEUP:	// 上翻一行
							if( first_list != 0 )
							{
								// 滚动
								first_list--;
								if( list_head == 0 )
									list_head = ITEM_NUM;
								list_head--;
								// 读取前一个记录项
								data = search_result->head[first_list].data;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -