Subversion Repositories Kolibri OS

Rev

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

  1. // Mouse Configuration Utility ver 1.62
  2.  
  3. #ifndef AUTOBUILD
  4. #include "lang.h--"
  5. #endif
  6.  
  7. #define MEMSIZE 4096*11
  8.  
  9. #include "..\lib\strings.h"
  10. #include "..\lib\mem.h"
  11. #include "..\lib\fs.h"
  12. #include "..\lib\gui.h"
  13. #include "..\lib\obj\libio.h"
  14. #include "..\lib\obj\box_lib.h"
  15. #include "..\lib\obj\libini.h"
  16. #include "..\lib\patterns\restart_process.h"
  17.  
  18. // Translatiions
  19. #ifdef LANG_RUS
  20.         ?define WINDOW_TITLE "à®¢¥àª  ¨ ­ áâனª  ¯ à ¬¥â஢ ¬ëè¨"
  21.         ?define CHECK_MOUSE_1 " ¦¬¨â¥ ­  í⮩ ®¡« áâ¨"
  22.         ?define CHECK_MOUSE_2 "¤«ï ¯à®¢¥àª¨ ª­®¯®ª ¬ëè¨"
  23.         ?define POINTER_SPEED "„¥«¨â¥«ì ᪮à®á⨠㪠§ â¥«ï ¬ëè¨"
  24.         ?define ACCELERATION_TEXT "—ã¢á⢨⥫쭮áâì 㪠§ â¥«ï ¬ëè¨"
  25.         ?define DOUBLE_CLICK_TEXT "‡ ¤¥à¦ª  ¤¢®©­®£® ª«¨ª  ¬ëèìî"
  26.         ?define MOUSE_EMULATION "“¯à ¢«¥­¨¥ 㪠§ â¥«¥¬ ¬ëè¨ ç¥à¥§ ª« ¢¨ âãàã"
  27.         ?define MADMOUSE "‘ª¢®§­ë¥ ¤«ï ªãàá®à  áâ®à®­ë íªà ­ "
  28.         ?define COMMOUSE "‡ £à㧨âì ¤à ©¢¥à ¬ëè¨ ¤«ï COM-¯®àâ  (F10)"
  29.         ?define COMMOUSE_LOADED "'„à ©¢¥à ¤«ï COM ¬ëè¨ ¡ë« § £à㦥­' -O"
  30.         ?define COMMOUSE_CAN_NOT_UNLOAD "'Žáâ ­®¢ª  ¤à ©¢¥à  ­¥¢®§¬®¦­ ' -W"
  31. #else
  32.         ?define WINDOW_TITLE "Mouse testing and configuration"
  33.         ?define CHECK_MOUSE_1 "Click on this area to"
  34.         ?define CHECK_MOUSE_2 "check your mouse buttons"
  35.         ?define POINTER_SPEED "Mouse pointer speed divider"
  36.         ?define ACCELERATION_TEXT "Mouse pointer sensitivity"
  37.         ?define DOUBLE_CLICK_TEXT "Mouse double click delay"
  38.         ?define MOUSE_EMULATION "Enable mouse emulation using keyboard NumPad"
  39.         ?define MADMOUSE "Through screen sides for pointer"
  40.         ?define COMMOUSE "Load mouse driver for COM-port (F10)"
  41.         ?define COMMOUSE_LOADED "'Driver for COM mouse loaded' -O"
  42.         ?define COMMOUSE_CAN_NOT_UNLOAD "'Driver stop is impossible' -W"
  43. #endif
  44.  
  45. #define FRAME_X 18
  46. #define FRAME_Y 18
  47. :block mouse_frame = { FRAME_X, FRAME_Y, NULL, 130 };
  48. :more_less_box pointer_speed      = { NULL, 0, 64, POINTER_SPEED };
  49. :more_less_box acceleration       = { NULL, 0, 64, ACCELERATION_TEXT };
  50. :more_less_box double_click_delay = { NULL, 0, 999, DOUBLE_CLICK_TEXT, 8 };
  51. :checkbox emulation = { MOUSE_EMULATION, NULL };
  52. :checkbox madmouse = { MADMOUSE, NULL };
  53. :checkbox com_mouse = { COMMOUSE, NULL };
  54.  
  55. _ini ini = { "/sys/settings/system.ini", "loaded drivers" };
  56.  
  57. void main() {
  58.         proc_info Form;
  59.         int id;
  60.        
  61.         load_dll(libini, #lib_init,1);
  62.         load_dll(boxlib, #box_lib_init,0);
  63.        
  64.         LoadCfg();
  65.  
  66.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  67.  
  68.         loop() switch(WaitEvent())
  69.         {
  70.                 case evMouse:
  71.                                 mouse.get();
  72.                                 IF (mouse_frame.hovered()) DrawMouseImage(mouse.lkm,mouse.pkm,mouse.mkm,mouse.vert);
  73.                                 IF (mouse.click) || (mouse.up) DrawMouseImage(0,0,0,0);
  74.                                 break;
  75.  
  76.                 CASE evButton:
  77.                                 id = GetButtonID();
  78.                                 IF (1 == id) ExitApp();
  79.                                 else IF (pointer_speed.click(id)) ApplyCfg();
  80.                                 else IF (acceleration.click(id)) ApplyCfg();
  81.                                 else IF (double_click_delay.click(id)) ApplyCfg();
  82.                                 else IF (emulation.click(id)) {
  83.                                         IF (emulation.checked == true) RunProgram("/sys/mousemul", 0);
  84.                                         ELSE KillProcessByName("mousemul", SINGLE);
  85.                                         break;
  86.                                 }
  87.                                 else IF (madmouse.click(id)) {                                         
  88.                                         IF (madmouse.checked == true) RunProgram("/sys/madmouse", 0);
  89.                                         ELSE KillProcessByName("madmouse", SINGLE);
  90.                                         break;
  91.                                 }
  92.                                 else IF (id == com_mouse.id) {
  93.                                         EventClickComMouse();
  94.                                 }
  95.                                 break;
  96.  
  97.                 case evKey:
  98.                                 GetKeys();
  99.                                 IF (key_scancode == SCAN_CODE_ESC) ExitApp();
  100.                                 IF (key_scancode == SCAN_CODE_F10) EventClickComMouse();
  101.                                 break;
  102.                        
  103.                 case evReDraw:
  104.                                 system.color.get();
  105.                                 DefineAndDrawWindow(430, 150, 424, 343+skin_height,0x34,system.color.work,WINDOW_TITLE,0);
  106.                                 GetProcessInfo(#Form, SelfInfo);
  107.                                 if (Form.status_window>2) break;
  108.                                 mouse_frame.w = - FRAME_X * 2 + Form.cwidth;
  109.                                 DefineButton(FRAME_X, FRAME_Y, mouse_frame.w,
  110.                                         mouse_frame.h, 99+BT_NOFRAME, 0xF0F2F3); //needed to handle mouse_up and refresh mouse image
  111.                                 WriteText(FRAME_X + 110, FRAME_Y + 25, 0x90, 0x2C343C, CHECK_MOUSE_1);
  112.                                 WriteText(FRAME_X + 110, FRAME_Y + 45, 0x90, 0x2C343C, CHECK_MOUSE_2);
  113.                                 DrawMouseImage(0,0,0,0);
  114.                                 DrawControls();
  115.         }
  116. }
  117.  
  118. :byte panels_img_data[] = FROM "mouse_image.raw";
  119.  
  120. #define red    0xff0000
  121. #define yellow 0xfff600
  122. #define white  0xffffff
  123. #define dgrey  0x2d353d
  124.  
  125. :struct IMG_PAL{ dword back, shad1, contour, left,  right, middle, mwhite; }
  126.          pal = { 0xF0F2F3,0xABB0B2, dgrey,   white, white, dgrey,  white  };
  127.  
  128. void DrawMouseImage(dword l,r,m,v) {
  129.         #define IMG_W 59
  130.         #define IMG_H 101
  131.  
  132.         IF (l) pal.left = red;
  133.         IF (m) pal.middle = red;
  134.         IF (r) pal.right = red;
  135.         IF (v) pal.middle = yellow;
  136.  
  137.         PutPaletteImage(#panels_img_data,IMG_W,IMG_H,18+30,18+15,8,#pal);
  138.         pal.left = pal.right = white;
  139.         pal.middle = dgrey;
  140.         IF (v) {
  141.                 pause(10);
  142.                 DrawMouseImage(l,r,m,0);
  143.         }
  144. }
  145.  
  146. void DrawControls() {
  147.         incn y;
  148.         y.n = FRAME_Y+115;
  149.         pointer_speed.draw(FRAME_X, y.inc(30));
  150.         acceleration.draw(FRAME_X, y.inc(30));
  151.         double_click_delay.draw(FRAME_X, y.inc(30));
  152.         emulation.draw(FRAME_X, y.inc(33));
  153.         madmouse.draw(FRAME_X, y.inc(27));
  154.         com_mouse.draw(FRAME_X, y.inc(27));
  155. }
  156.  
  157. void LoadCfg() {
  158.         acceleration.value = GetMouseAcceleration();
  159.         pointer_speed.value = GetMouseSpeed();
  160.         double_click_delay.value = GetMouseDoubleClickDelay();
  161.         com_mouse.checked = ini.GetInt("com_mouse", 0);
  162.         madmouse.checked = CheckProcessExists("MADMOUSE");
  163.         emulation.checked = CheckProcessExists("MOUSEMUL");
  164. }
  165.  
  166. void ExitApp() {
  167.         ini.SetInt("com_mouse", com_mouse.checked);
  168.         ExitProcess();
  169. }
  170.  
  171. void ApplyCfg() {
  172.         SetMouseSpeed(pointer_speed.value);
  173.         SetMouseAcceleration(acceleration.value);
  174.         SetMouseDoubleClickDelay(double_click_delay.value);
  175. }
  176.  
  177. void EventClickComMouse()
  178. {
  179.         if (!com_mouse.checked)
  180.         {
  181.                 if (RunProgram("/sys/loaddrv", "COMMOUSE")>=0) {
  182.                         notify(COMMOUSE_LOADED);
  183.                         com_mouse.click(com_mouse.id);
  184.                 }
  185.                 else {
  186.                         notify("'Error running LOADDRV' -E");
  187.                 }
  188.         }
  189.         else
  190.         {
  191.                 notify(COMMOUSE_CAN_NOT_UNLOAD);
  192.         }
  193. }
  194.  
  195. stop:
  196.