Subversion Repositories Kolibri OS

Rev

Rev 5674 | Rev 6640 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef AUTOBUILD
  2.         #include "lang.h--"
  3. #endif
  4.  
  5. #define MEMSIZE 0x8000
  6. #include "..\lib\strings.h"
  7. #include "..\lib\io.h"
  8. #include "..\lib\gui.h"
  9. #include "..\lib\obj\box_lib.h"
  10.  
  11. unsigned char speaker[23*40*3]= FROM "speaker.raw";
  12.  
  13. #ifdef LANG_RUS
  14.   #define WINDOW_TITLE "‘«®¢ à¨ª 2.0"
  15.   #define DICTIONARY_NOT_FOUND "‘«®¢ àì ­¥ ­ ©¤¥­"
  16.   #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
  17.   #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
  18.   #define ERROR "Žè¨¡ª  #"
  19. #else
  20.   #define WINDOW_TITLE "Dictionary v2.0"
  21.   #define DICTIONARY_NOT_FOUND "Dictionary not found"
  22.   #define DICTIONARY_LOADED "Dictionary loaded"
  23.   #define WORD_NOT_FOUND "Word isn't found in the dictionary"
  24.   #define ERROR "Error #"
  25.   #endif
  26.  
  27. proc_info Form;
  28. char edword[256], search_word[256], translate_result[4096];
  29. #define PRONOUNCED_FILE "/sys/pronounced.txt"
  30. #define SPEECH_PATH "/kolibrios/media/speech/speech"
  31. #define TOPH 44
  32.  
  33. #define TEXT_ENG_RUS "ENG\26RUS"
  34. #define TEXT_RUS_ENG "RUS\26ENG"
  35. #define ENG_RUS 0
  36. #define RUS_ENG 1
  37. int active_dict=2;
  38.  
  39. int mouse_dd, speaker_id;
  40. edit_box edit1= {200,16,16,0xffffff,0x94AECE,0xffffff,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b};
  41.  
  42.  
  43. void main()
  44. {  
  45.         int id;
  46.         load_dll(boxlib, #box_lib_init,0);
  47.         OpenDictionary(ENG_RUS);
  48.         if (param)
  49.         {
  50.                 strcpy(#edword, #param);
  51.                 edit1.size=edit1.pos=strlen(#edword);
  52.                 Translate();
  53.         }
  54.         SetEventMask(0x27);
  55.         loop()
  56.         {
  57.                 switch(WaitEvent())
  58.                 {
  59.                 case evMouse:
  60.                         edit_box_mouse stdcall (#edit1);
  61.                         break;
  62.  
  63.                 case evButton:
  64.             id=GetButtonID();              
  65.             if (id==01) { KillProcess(speaker_id); ExitProcess(); }
  66.                         if (id==10) { OpenDictionary(ENG_RUS); DrawLangButtons(); }
  67.                         if (id==11) { OpenDictionary(RUS_ENG); DrawLangButtons(); }
  68.                         if (id==15)
  69.                         {
  70.                                 if (GetProcessSlot(speaker_id)!=0))
  71.                                 {
  72.                                         KillProcess(speaker_id);
  73.                                         pause(50);
  74.                                 }
  75.                                 else
  76.                                 {
  77.                                         if (WriteFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
  78.                                         pause(50);
  79.                                         speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
  80.                                 }
  81.                                 SpeakerDraw();
  82.                         }
  83.                         break;
  84.  
  85.         case evKey:
  86.                         GetKeys();                     
  87.                         EAX=key_ascii<<8;
  88.                         edit_box_key stdcall(#edit1);  
  89.                         Translate();
  90.                         break;
  91.                        
  92.          case evReDraw:
  93.                         system.color.get();
  94.                         DefineAndDrawWindow(215,120,400,250,0x73,system.color.work,WINDOW_TITLE);
  95.                         GetProcessInfo(#Form, SelfInfo);
  96.                         if (Form.status_window>2) break;
  97.                         if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
  98.                         if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
  99.                         DrawBar(0, 0, Form.width-9, TOPH, system.color.work); //top bg
  100.                         DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph);
  101.                         edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
  102.                         edit_box_draw stdcall(#edit1);
  103.                         DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 19, 2, 0xffffff);
  104.                         DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 20, system.color.work_graph);
  105.                         DrawTranslation();
  106.                         DrawLangButtons();
  107.       }
  108.    }
  109. }
  110.  
  111.  
  112. void DrawLangButtons()
  113. {
  114.         DrawCaptButton(Form.width-130, edit1.top-3, 50,19, 10, system.color.work_button, system.color.work_button_text, TEXT_ENG_RUS);
  115.         DrawCaptButton(Form.width-70, edit1.top-3, 50,19, 11, system.color.work_button, system.color.work_button_text, TEXT_RUS_ENG);
  116.         PutShadow(-active_dict*60 + Form.width-70, edit1.top-3, 50,19, 1, 2);
  117.         SpeakerDraw();
  118. }
  119.  
  120. void SpeakerDraw()
  121. {
  122.         dword x, y;
  123.         x = Form.cwidth-38;
  124.         y = Form.cheight-32;
  125.         if (active_dict)
  126.         {
  127.                 DeleteButton(15);
  128.                 DrawBar(x,y,23,20,0xFFFFFF);
  129.         }
  130.         else
  131.         {
  132.                 DefineButton(x-5, y-5, 23+10, 20+9, 15+BT_HIDE+BT_NOFRAME, 0);
  133.                 if (GetProcessSlot(speaker_id)==0)) _PutImage(x, y, 23,20, #speaker); else _PutImage(x, y, 23,20, 23*20*3+#speaker);           
  134.         }
  135. }
  136.  
  137. void Translate()
  138. {
  139.         dword translation_start, translation_end;
  140.  
  141.         KillProcess(speaker_id);
  142.         sprintf(#search_word, "\10%s\13", #edword);
  143.         strupr(#search_word);
  144.  
  145.         if (!io.FILES_SIZE) || (!edword) goto _TR_END;
  146.  
  147.         translation_start = strstr(io.buffer_data, #search_word);
  148.         if (!translation_start)
  149.         {
  150.                 strcpy(#translate_result, WORD_NOT_FOUND);
  151.         }
  152.         else
  153.         {
  154.                 translation_start = strchr(translation_start, '"') + 1;
  155.                 translation_end = strchr(translation_start, '"');
  156.                 strlcpy(#translate_result, translation_start, translation_end - translation_start);
  157.         }
  158.         _TR_END:
  159.         strcpy(#search_word, #search_word+1);
  160.         DrawTranslation();
  161. }
  162.  
  163.  
  164. void OpenDictionary(dword dict_id)
  165. {
  166.         dword res;
  167.         if (dict_id==active_dict) return;
  168.         KillProcess(speaker_id);
  169.         active_dict = dict_id;
  170.         if (io.buffer_data) free(io.buffer_data);
  171.         if (active_dict==ENG_RUS) res=io.read("dictionaries/eng - rus.dict");
  172.         if (active_dict==RUS_ENG) res=io.read("dictionaries/rus - eng.dict");  
  173.         if (!io.buffer_data)
  174.         {
  175.                 sprintf(#search_word, ERROR, res);
  176.                 strcpy(#translate_result, DICTIONARY_NOT_FOUND);
  177.         }
  178.         else
  179.         {
  180.                 if (active_dict==ENG_RUS) strcpy(#search_word, TEXT_ENG_RUS);
  181.                 if (active_dict==RUS_ENG) strcpy(#search_word, TEXT_RUS_ENG);
  182.                 strcpy(#translate_result, DICTIONARY_LOADED);
  183.         }
  184.         DrawTranslation();     
  185. }
  186.  
  187.  
  188. void DrawTranslation()
  189. {
  190.         int text_break=0;
  191.         char tt[4096]='';
  192.        
  193.         int y_pos=TOPH+1;
  194.         char draw_buf[4096];
  195.         strcpy(#draw_buf, #translate_result);
  196.        
  197.         DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF);
  198.         strttl(#draw_buf);
  199.         WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
  200.         while (draw_buf)
  201.         {
  202.                 text_break= Form.width/6-6;
  203.                 if (text_break>strlen(#draw_buf))
  204.                 {
  205.                         WriteText(10, y_pos+31, 0x80, 0, #draw_buf);
  206.                         break;
  207.                 }
  208.                 while (draw_buf[text_break]<>' ') && (text_break>0) text_break--;
  209.                 strcpy(#tt, #draw_buf+text_break+1);
  210.                 draw_buf[text_break]=0x0;
  211.                 WriteText(10, y_pos+31, 0x80, 0, #draw_buf);
  212.                 strcpy(#draw_buf, #tt);
  213.                 y_pos+=12;
  214.                 if (y_pos+24+8>Form.cheight) break;
  215.         }
  216.         SpeakerDraw();
  217. }
  218.  
  219.  
  220. stop:
  221.