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

📄 dict.c

📁 国家ASIC工程中心使用的嵌入式操作系统
💻 C
字号:
/******************************************************************************
*
* Copyright  2004 National ASIC Center, All right Reserved
*
* FILE NAME:			dict.c
* PROGRAMMER:			yuchao
* Date of Creation:		2004/08/31
* 
* DESCRIPTION: 			dictionary module 					
*						
* NOTE:			 		
*
* FUNCTIONS LIST:
* -----------------------------------------------------------------------------
*
* -----------------------------------------------------------------------------
*
* MODIFICATION HISTORY
* 
*		
******************************************************************************/


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#include <asixwin.h>
#include <asixapp.h>
#include <asixwin\asix_ed.h>
#include <asixwin\asix_mn.h>
#include <asixwin\asix_tb.h>
#include <asixwin\select.h>

#include <sys\sysmsg.h>
#include <resource\bitmap.h>

#include "dict.h"
#include "dictcore.h"


extern void   Dictionary();

//注册表
TASKDESCRIPTION NewDictionaryTskDesp = 
{ "英汉字典", ASIX_APP, 0, yingyong, 2048, 1, LCD_WIDTH, LCD_HEIGHT, Dictionary, APP_PRI};

int fpidx = DICT_CLOSED;
int fpdic = DICT_CLOSED;

void Dictionary( void )
{
	//窗口和控件ID
	U32     mainwin;
	U32     input;
	U32     list[LISTNUM];
	U32     scroll;
	U32     meaning;
	U32     tskbar;
	U32     kb;
	U32     keyboard;
	
	
	
	//函数变量	
	MSG     msg;
	U32     headindex = 0;
	S16     row = 1;
	long    curindex = 0;
	char    buffer[INPUT_LEN + 1];
	ENTRY   *wordlistptr;
	
	char    *wordinfo = NULL;
	ENTRY   *wordlist = NULL;
	
	U8      quit = 0;
	U8      i = 0;
	U8		count = 0;
	U8      kbflag = 1;
	U8		dragflag = 0;
	
	U16     margin = 5;
	
	U16     input_x, input_y = 22;
	U16     input_w, input_h = 20;
	
	U16     list_x, list_y = 44;
	
	U16     scroll_w = 15, scroll_h = 20 * LISTNUM;
	
	U16     list_w, list_h = 20;
	
	U16     scroll_x, scroll_y;
	
	U16     meaning_x, meaning_y;
	U16     meaning_w, meaning_h;
     
	input_x = margin;
	input_w = LCD_WIDTH - 2 * margin;
	list_x = input_x;
	list_w = LCD_WIDTH - 2 * margin - scroll_w;
	scroll_x = list_x + list_w;
	scroll_y = list_y;
	meaning_x = input_x; 
	meaning_y = list_y + LISTNUM * list_h + 1;
	meaning_w = LCD_WIDTH - 2 * margin; 
	meaning_h = LCD_HEIGHT - meaning_y - 20 - 1;
     
     
	//创建按钮
	mainwin = CreateWindow(WNDCLASS_WIN, 
							"英汉字典", 
							WS_OVERLAPPEDWINDOW, 
							0, 
							0, 
							LCD_WIDTH, 
							LCD_HEIGHT, 
							0, 
							0, 
							NULL); 
	input = CreateWindow(WNDCLASS_EDITOR, 
							NULL, 
							WS_CHILD|ES_SINGLE_REGULAR, 
							input_x, 
							input_y, 
							input_w, 
							input_h, 
							mainwin, 
							0, 
							NULL);     
	for(i = 0; i < LISTNUM; i++)
	{
		list[i] = CreateWindow(WNDCLASS_BUTTON, 
							NULL, 
							WS_CHILD|BS_ICON|BS_FLAT|BS_LEFT,    
							list_x, 
							(U16)(list_y + i*20), 
							list_w, 
							list_h, 
							mainwin, 
							0, 
							NULL);   
	}
	tskbar = CreateWindow(WNDCLASS_TSKBAR, 
							NULL, 
							WS_CHILD|TBS_TYPICAL, 
							0, 
							0, 
							0, 
							0, 
							mainwin, 
							0, 
							NULL); 
	kb = AddBtn2TskBar(tskbar, 
							NULL, 
							BS_ICON, 
							20, 
							(char *)zi_jianpan); 
	scroll = CreateWindow(WNDCLASS_SCROLL, 
							NULL, 
							WS_CHILD|SBS_VERT, 
							scroll_x, 
							scroll_y, 
							scroll_w, 
							scroll_h, 
							mainwin, 
							MAKELONG(1, SEARCHNUM - LISTNUM + 1), 
							NULL);
	keyboard = CreateWindow(WNDCLASS_KEYBD, 
							"", 
							WS_CHILD|KBS_LOWCASE|0xff, 
							margin, 
							meaning_y + 14, 
							160, 
							70, 
							mainwin, 
							0, 
							NULL);  
	
	InitDictCore( );
	wordlist = (ENTRY *)calloc(SEARCHNUM, sizeof(ENTRY));
	wordlistptr = wordlist;
	SetFocus(input);
		
	while(!quit)
	{
		ASIXGetMessage(&msg, NULL, 0, 0); 
		switch(msg.message)
		{
			case WM_COMMAND:
				if(msg.lparam == kb)         //点击软键盘按钮, 切换软键盘和解释
				{
					if(kbflag == 1)
					{
						DestroyWindow(keyboard);
						meaning = CreateWindow(WNDCLASS_EDITOR, 
												NULL, 
												WS_CHILD|ES_MULTI_REGULAR, 
												meaning_x, 
												meaning_y, 
												meaning_w, 
												meaning_h, 
												mainwin, 
												DISPLAYSIZE, 
												NULL); 
						kbflag = 0;
					}
					else
					{
						DestroyWindow(meaning);
						keyboard = CreateWindow(WNDCLASS_KEYBD, 
												"", 
												WS_CHILD|KBS_LOWCASE|0xff, 
												margin, 
												meaning_y + 14, 
												160, 
												70, 
												mainwin, 
												0, 
												NULL);
						if(headindex != 0)
						{
							for(i = 0; i < LISTNUM; i++)
							{
								list[i] = CreateWindow(WNDCLASS_BUTTON, 
												NULL, 
												WS_CHILD|BS_ICON|BS_FLAT|BS_LEFT,    
												list_x, 
												(U16)(list_y + i*20), 
												list_w, 
												list_h, 
												mainwin, 
												0, 
												NULL);   
							}
							scroll = CreateWindow(WNDCLASS_SCROLL, 
												NULL, 
												WS_CHILD|SBS_VERT, 
												scroll_x, 
												scroll_y, 
												scroll_w, 
												scroll_h, 
												mainwin, 
												MAKELONG(1, SEARCHNUM - LISTNUM + 1), 
												NULL);
							SetWindowText(input, NULL, NULL);
							count = 0;
							row = 1;
							headindex = 0;
							
							for(i = 0; i< SEARCHNUM; i++) {
								free(wordlist->phrase);
								wordlist->phrase = NULL;
								wordlist++;
							}
							wordlist = wordlistptr; 
							
						}

						SetFocus(input);
						kbflag = 1; 
					}	
				}
				else                       //判断点击列表中的那个单词,显示解释
				{
					if(headindex == 0)
						break;
					else
					{
						for(i = 0; i < LISTNUM; i++)
						{
							if(msg.lparam == list[i])
							{
								if(kbflag == 1)		
								{
									DestroyWindow(keyboard);
									kbflag = 0;
									meaning = CreateWindow(WNDCLASS_EDITOR, 
													NULL, 
													WS_CHILD|ES_MULTI_REGULAR, 
													meaning_x, 
													meaning_y, 
													meaning_w,
													meaning_h, 
													mainwin, 
													DISPLAYSIZE, 
													NULL); 
								}   
	    	                 
								SetWindowText(input, wordlist[i + row - 1].phrase, NULL); 
																
								if((unsigned long)curindex == wordlist[i + row - 1].index && curindex != 0)
									break;
								else
									curindex = wordlist[i + row - 1].index;         
						
								wordinfo = GetEntryInfo(curindex, ENTRY_ALL);
								if(wordinfo != NULL){
									SetWindowText(meaning, wordinfo, NULL);
									free(wordinfo);
									wordinfo = NULL;
								}
								
								break;
							}	
						}
					}
				}                    
				break;
        	

			case WM_CHAR:                       //根据输入区的消息查找,显示列表
				if(msg.lparam == input)
				{
					MSG tempmsg;

					tempmsg.message = WM_CHAR;
					tempmsg.lparam = 0;
					tempmsg.wparam = msg.wparam;
					SysSendMessage( GetCurTaskID(), &tempmsg);			
				}		 
				else
				if(msg.lparam == 0)
				{
					if( isprint(msg.wparam) && (count < INPUT_LEN))                            
					{
						count++;
						GetEditorStr(input, buffer, count+1);
						buffer[count] = '\0';
					}
					else if(msg.wparam == 0xb0)
					{
						if(count == 0)
							break;
					 	else
						{
							count--;
							buffer[count] = '\0';
							SetWindowText(input, buffer, NULL);	
												
						}	
					}
					headindex = SearchEntry(buffer);		             	     
					memset(wordlist, 0, SEARCHNUM*sizeof(ENTRY));
					GetEntryList(wordlist, headindex, SEARCHNUM); 
					for(i = 0; i < LISTNUM; i++)
						SetWindowText(list[i], wordlist[i].phrase, NULL);  	
				}		 
				break;
				
				          
			case WM_VSCROLL:
				if(msg.lparam == scroll)
				{
					if(headindex == 0 || kbflag == 1)
						break;
					else
					{
						switch(msg.wparam)
						{
							case SB_PAGEUP:
								row -= LISTNUM; 
								if(row < 1)		
									row = 1; 
								break; 
							
							case SB_PAGEDOWN:
								row += LISTNUM; 
								if(row > (SEARCHNUM - LISTNUM + 1))	
									row = (SEARCHNUM - LISTNUM + 1); 
								break;
							  
							case SB_LINEUP:
								row -= 1; 
								if(row < 1)		
									row = 1; 
								break; 
							
							case SB_LINEDOWN:
								row += 1; 
								if(row > (SEARCHNUM - LISTNUM + 1))	
									row = (SEARCHNUM - LISTNUM + 1); 
								break;
							  
							case SB_THUMBTRACK:
								dragflag = 1; 
								break; 
							
							case SB_ENDSCROLL:
								row = GetScrollPos(scroll,0,0,0); 
								dragflag = 0; 
								break;
								
							default:
								break;
						}
					 
						if(!dragflag)
						{
							SetScrollPos(scroll,row,0,0);     // 滚动条拖动定位
					
							for(i = 0; i < LISTNUM; i++)	  //列表更新 	
								SetWindowText(list[i], wordlist[i + row - 1].phrase, NULL);
							
							SetWindowText(input, wordlist[row - 1].phrase, NULL);
							
							if((unsigned long)curindex == wordlist[row - 1].index && curindex != 0)
								break;
							else
								curindex = wordlist[row - 1].index;   
						    
							wordinfo = GetEntryInfo(curindex, ENTRY_ALL);
							if(wordinfo != NULL){
								SetWindowText(meaning, wordinfo, NULL);
								free(wordinfo);
								wordinfo = NULL;
							}
							                      
							SetScrollRange(scroll, 1, (U16)(SEARCHNUM - LISTNUM + 1));
							SetScrollPos(scroll, (U16)(row + 1), 0,0);
						}
					}
        	     
				}	   
				break;
	 		
			case WM_QUIT:
				quit = 1;
				break;
				
			default:
				break;
		}
	 
		DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam); 

     	
	}
     
	ExitDictCore(); 
	
	for(i = 0; i< SEARCHNUM; i++) {
			free(wordlist->phrase);
			wordlist->phrase = NULL;
			wordlist++;
	}
	wordlist = wordlistptr;
	free(wordlist);
		
	DestroyWindow( mainwin ); 
	EndofTask(); 
	return;  

}

⌨️ 快捷键说明

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