Subversion Repositories Kolibri OS

Rev

Rev 6638 | Rev 6678 | 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. #ifdef LANG_RUS
  12.   #define WINDOW_TITLE "‘«®¢ à¨ª 2.2"
  13.   #define DICTIONARY_NOT_FOUND "‘«®¢ àì ­¥ ­ ©¤¥­"
  14.   #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
  15.   #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
  16.   #define ERROR "Žè¨¡ª  #%d"
  17. #else
  18.   #define WINDOW_TITLE "Dictionary v2.2"
  19.   #define DICTIONARY_NOT_FOUND "Dictionary not found"
  20.   #define DICTIONARY_LOADED "Dictionary loaded"
  21.   #define WORD_NOT_FOUND "Word isn't found in the dictionary"
  22.   #define ERROR "Error #%d"
  23.   #endif
  24.  
  25. proc_info Form;
  26. char edword[256], search_word[256], translate_result[4096];
  27. #define TOPH 44
  28.  
  29. #define TEXT_ENG_RUS "ENG\26RUS"
  30. #define TEXT_RUS_ENG "RUS\26ENG"
  31. #define TEXT_VOCABULARIES "ENG     RUS"
  32. #define ENG_RUS 0
  33. #define RUS_ENG 1
  34. #define BUTTON_CHANGE_LANGUAGE 10
  35. int active_dict=2;
  36.  
  37. int mouse_dd;
  38. edit_box edit1= {200,16,16,0xffffff,0x94AECE,0xffffff,0x94AECE,0,248,#edword,#mouse_dd,100000000000010b};
  39.  
  40.  
  41. void main()
  42. {  
  43.         int id;
  44.         load_dll(boxlib, #box_lib_init,0);
  45.         OpenDictionary(ENG_RUS);
  46.         if (param)
  47.         {
  48.                 strcpy(#edword, #param);
  49.                 edit1.size=edit1.pos=strlen(#edword);
  50.                 Translate();
  51.         }
  52.         SetEventMask(0x27);
  53.         loop()
  54.         {
  55.                 switch(WaitEvent())
  56.                 {
  57.                 case evMouse:
  58.                         edit_box_mouse stdcall (#edit1);
  59.                         break;
  60.  
  61.                 case evButton:
  62.             id=GetButtonID();              
  63.             if (id==01) ExitProcess();
  64.                         if (id==BUTTON_CHANGE_LANGUAGE) {
  65.                                 if (active_dict == ENG_RUS) OpenDictionary(RUS_ENG); else OpenDictionary(ENG_RUS);
  66.                                 DrawLangButtons();
  67.                         }
  68.                         break;
  69.  
  70.         case evKey:
  71.                         GetKeys();
  72.                         edit_box_key stdcall(#edit1);  
  73.                         Translate();
  74.                         break;
  75.                        
  76.          case evReDraw:
  77.                         system.color.get();
  78.                         DefineAndDrawWindow(215,120,500,350,0x73,system.color.work,WINDOW_TITLE);
  79.                         GetProcessInfo(#Form, SelfInfo);
  80.                         if (Form.status_window>2) break;
  81.                         if (Form.height<140) { MoveSize(OLD,OLD,OLD,140); break; }
  82.                         if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
  83.                         DrawBar(0, 0, Form.width-9, TOPH, system.color.work); //top bg
  84.                         DrawBar(0, TOPH, Form.width-9, 1, system.color.work_graph);
  85.                         edit1.width=Form.width-edit1.left-edit1.left-9 - 116;
  86.                         edit_box_draw stdcall(#edit1);
  87.                         DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 19, 2, 0xffffff);
  88.                         DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 20, system.color.work_graph);
  89.                         WriteText(Form.width-120, edit1.top, 0x90, system.color.work_text, TEXT_VOCABULARIES);
  90.                         DrawTranslation();
  91.                         DrawLangButtons();
  92.       }
  93.    }
  94. }
  95.  
  96.  
  97. void DrawLangButtons()
  98. {
  99.         dword direction;
  100.         DefineButton(Form.width-88, edit1.top-4, 20, 20, BUTTON_CHANGE_LANGUAGE, system.color.work_button);
  101.         if (active_dict == ENG_RUS) direction = "\26"; else direction = "\27";
  102.         WriteText(Form.width-82, edit1.top-1, 10000001b, system.color.work_button_text, direction);
  103. }
  104.  
  105. void Translate()
  106. {
  107.         dword translation_start, translation_end;
  108.  
  109.         sprintf(#search_word, "\10%s\13", #edword);
  110.         strupr(#search_word);
  111.  
  112.         if (!io.FILES_SIZE) || (!edword) goto _TR_END;
  113.  
  114.         translation_start = strstr(io.buffer_data, #search_word);
  115.         if (!translation_start)
  116.         {
  117.                 strcpy(#translate_result, WORD_NOT_FOUND);
  118.         }
  119.         else
  120.         {
  121.                 translation_start = strchr(translation_start, '"') + 1;
  122.                 translation_end = strchr(translation_start, '"');
  123.                 strlcpy(#translate_result, translation_start, translation_end - translation_start);
  124.         }
  125.         _TR_END:
  126.         strcpy(#search_word, #search_word+1);
  127.         DrawTranslation();
  128. }
  129.  
  130.  
  131. void OpenDictionary(dword dict_id)
  132. {
  133.         dword res;
  134.         if (dict_id==active_dict) return;
  135.         active_dict = dict_id;
  136.         if (io.buffer_data) free(io.buffer_data);
  137.         if (active_dict==ENG_RUS) res=io.read("dictionaries/eng - rus.dict");
  138.         if (active_dict==RUS_ENG) res=io.read("dictionaries/rus - eng.dict");  
  139.         if (!io.buffer_data)
  140.         {
  141.                 sprintf(#search_word, ERROR, res);
  142.                 strcpy(#translate_result, DICTIONARY_NOT_FOUND);
  143.         }
  144.         else
  145.         {
  146.                 if (active_dict==ENG_RUS) strcpy(#search_word, TEXT_ENG_RUS);
  147.                 if (active_dict==RUS_ENG) strcpy(#search_word, TEXT_RUS_ENG);
  148.                 strcpy(#translate_result, DICTIONARY_LOADED);
  149.         }
  150.         DrawTranslation();     
  151. }
  152.  
  153.  
  154. void DrawTranslation()
  155. {
  156.         int y_pos=TOPH+1;
  157.         char draw_buf[4096];
  158.         strlcpy(#draw_buf, #translate_result, sizeof(draw_buf));
  159.        
  160.         DrawBar(0, y_pos, Form.width-9, Form.cheight - y_pos, 0xFFFFFF);
  161.         strttl(#draw_buf);
  162.         WriteTextB(10+1, y_pos+8, 10000001b, 0x800080, #search_word);
  163.  
  164.         DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, 15,
  165.                 #draw_buf, -1, 0x000000);
  166. }
  167.  
  168.  
  169. stop:
  170.