home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 December (Special) / DOSV2002_12.iso / utility / tcl230ja95.lzh / source.lzh / exe / mouse.c < prev    next >
C/C++ Source or Header  |  2001-02-08  |  9KB  |  338 lines

  1. /*-------------------------------------------
  2.   mouse.c
  3.   mouse operation
  4.   KAZUBON 1997-2001
  5. ---------------------------------------------*/
  6.  
  7. #include "tclock.h"
  8.  
  9. // XButton Messages
  10. #ifndef WM_XBUTTONDOWN
  11. #define WM_XBUTTONDOWN 0x020B
  12. #define WM_XBUTTONUP   0x020C
  13. #define XBUTTON1       0x0001
  14. #define XBUTTON2       0x0002
  15. #endif
  16.  
  17. static char reg_section[] = "Mouse";
  18. static UINT last_mousedown  = 0;
  19. static WORD last_xmousedown = 0;
  20. static DWORD last_tickcount;
  21. static int num_click = 0;
  22. static int exec_button = -1;
  23. static BOOL timer = FALSE;
  24.  
  25. static int GetMouseFuncNum(int button, int nclick);
  26.  
  27. /*------------------------------------------------
  28.     initialize registry data
  29. --------------------------------------------------*/
  30. void InitMouseFunction(void)
  31. {
  32.     int i;
  33.     LONG n;
  34.     char *old_entry[] = { "LClick", "LDblClick" };
  35.     char entry[20];
  36.     char s[256];
  37.     
  38.     last_tickcount = GetTickCount();
  39.     
  40.     if(GetMyRegLong(reg_section, "ver230", 0) == 0)
  41.     {
  42.         SetMyRegLong(reg_section, "ver230", 1);
  43.         if(GetMyRegLong(reg_section, "02", -1) < 0)
  44.             SetMyRegLong(reg_section, "02", 0);
  45.     }
  46.     
  47.     // save old data with new format
  48.     for(i = 0; i < 2; i++)
  49.     {
  50.         n = GetMyRegLong(reg_section, old_entry[i], -1);
  51.         if(n < 0) continue;
  52.         
  53.         DelMyReg(reg_section, old_entry[i]);
  54.         wsprintf(entry, "0%d", i + 1);
  55.         SetMyRegLong(reg_section, entry, n);
  56.         if(n == 6)
  57.         {
  58.             GetMyRegStr(reg_section, "ClipFormat", s, 256, "");
  59.             if(s[0])
  60.             {
  61.                 DelMyReg(reg_section, "ClipFormat");
  62.                 wsprintf(entry, "0%dClip", i + 1);
  63.                 SetMyRegStr(reg_section, entry, s);
  64.             }
  65.         }
  66.         else if(n == 100)
  67.         {
  68.             strcpy(entry, old_entry[i]); strcat(entry, "File");
  69.             GetMyRegStr(reg_section, entry, s, 256, "");
  70.             if(s[0])
  71.             {
  72.                 DelMyReg(reg_section, entry);
  73.                 wsprintf(entry, "0%dFile", i + 1);
  74.                 SetMyRegStr(reg_section, entry, s);
  75.             }
  76.         }
  77.     }
  78. }
  79.  
  80. /*------------------------------------------------
  81.    when files dropped to the clock
  82. --------------------------------------------------*/
  83. void OnDropFiles(HWND hwnd, HDROP hdrop)
  84. {
  85.     char fname[MAX_PATH], sname[MAX_PATH];
  86.     char app[1024];
  87.     SHFILEOPSTRUCT shfos;
  88.     char *buf, *p;
  89.     int i, num;
  90.     int nType;
  91.     
  92.     nType = GetMyRegLong(reg_section, "DropFiles", 0);
  93.     
  94.     num = DragQueryFile(hdrop, (UINT)-1, NULL, 0);
  95.     if(num <= 0) return;
  96.     buf = malloc(num*MAX_PATH);
  97.     if(buf == NULL) return;
  98.     p = buf;
  99.     for(i = 0; i < num; i++)
  100.     {
  101.         DragQueryFile(hdrop, i, fname, MAX_PATH);
  102.         if(nType == 1 || nType == 3 || nType == 4)  // ごみ箱、コピー、移動
  103.         {                             // '\0'で区切られたファイル名
  104.             strcpy(p, fname); p += strlen(p) + 1;
  105.         }
  106.         else if(nType == 2) //プログラムで開く:
  107.         {                   //スペースで区切られた短いファイル名
  108.             if(num > 1) GetShortPathName(fname, sname, MAX_PATH);
  109.             else strcpy(sname, fname);
  110.             strcpy(p, sname);
  111.             p += strlen(p);
  112.             if(num > 1 && i < num - 1) { *p = ' '; p++; }
  113.         }
  114.     }
  115.     *p = 0;
  116.     DragFinish(hdrop);
  117.     
  118.     GetMyRegStr(reg_section, "DropFilesApp", app, 1024, "");
  119.     
  120.     if(nType == 1 || nType == 3 || nType == 4)  // ごみ箱、コピー、移動
  121.     {
  122.         memset(&shfos, 0, sizeof(SHFILEOPSTRUCT));
  123.         shfos.hwnd = NULL;
  124.         if(nType == 1) shfos.wFunc = FO_DELETE;
  125.         else if(nType == 3) shfos.wFunc = FO_COPY;
  126.         else if(nType == 4) shfos.wFunc = FO_MOVE;
  127.         shfos.pFrom = buf;
  128.         if(nType == 3 || nType == 4) shfos.pTo = app;
  129.         shfos.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
  130.         SHFileOperation(&shfos);
  131.     }
  132.     else if(nType == 2) //ファイルで開く
  133.     {
  134.         char command[MAX_PATH*2];
  135.         
  136.         strcpy(command, app);
  137.         strcat(command, " ");
  138.         strcat(command, buf);
  139.         ExecFile(hwnd, command);
  140.     }
  141.     free(buf);
  142. }
  143.  
  144. /*------------------------------------------------------------
  145.    when the clock clicked
  146.    
  147.    registry format 
  148.    name    value
  149.    03      3           left button triple click -> Minimize All
  150.    32      100         x-1 button  double click -> Run Notepad
  151.    32File  C:\Windows\notepad.exe
  152. --------------------------------------------------------------*/
  153. void OnMouseMsg(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  154. {
  155.     LONG n_func;
  156.     int button;
  157.     UINT doubleclick_time;
  158.     char s[10];
  159.     int i;
  160.     BOOL bDown = FALSE;
  161.     
  162.     if(timer) KillTimer(hwnd, IDTIMER_MOUSE);
  163.     timer = FALSE;
  164.     
  165.     if(message == WM_LBUTTONDOWN || message == WM_LBUTTONUP)
  166.     {
  167.         BOOL b;
  168.         b = GetMyRegLong("", "StartButtonHide", FALSE);
  169.         if(b) b = GetMyRegLong("", "StartMenuClock", FALSE);
  170.         if(b) return;
  171.     }
  172.     
  173.     switch(message)
  174.     {
  175.         case WM_LBUTTONDOWN: 
  176.         case WM_LBUTTONUP:   button = 0; break;
  177.         case WM_RBUTTONDOWN:
  178.         case WM_RBUTTONUP:   button = 1; break;
  179.         case WM_MBUTTONDOWN:
  180.         case WM_MBUTTONUP:   button = 2; break;
  181.         case WM_XBUTTONDOWN:
  182.         case WM_XBUTTONUP:
  183.             if(HIWORD(wParam) == XBUTTON1) button = 3;
  184.             else if(HIWORD(wParam) == XBUTTON2) button = 4;
  185.             else return;
  186.             break;
  187.         default: return;
  188.     }
  189.     
  190.     switch(message)
  191.     {
  192.         case WM_LBUTTONDOWN:
  193.         case WM_RBUTTONDOWN:
  194.         case WM_MBUTTONDOWN:
  195.         case WM_XBUTTONDOWN:
  196.             if(last_mousedown != message) num_click = 0;
  197.             last_mousedown = message;
  198.             if(last_mousedown == WM_XBUTTONDOWN)
  199.                 last_xmousedown = HIWORD(wParam);
  200.             bDown = TRUE;
  201.             break;
  202.         case WM_LBUTTONUP:
  203.             if(last_mousedown != WM_LBUTTONDOWN) last_mousedown = 0;
  204.             break;
  205.         case WM_RBUTTONUP:
  206.             if(last_mousedown != WM_RBUTTONDOWN) last_mousedown = 0;
  207.             break;
  208.         case WM_MBUTTONUP:
  209.             if(last_mousedown != WM_MBUTTONDOWN) last_mousedown = 0;
  210.             break;
  211.         case WM_XBUTTONUP:
  212.             if(last_mousedown != WM_XBUTTONDOWN || 
  213.                 last_xmousedown != HIWORD(wParam))
  214.             {
  215.                 last_mousedown = 0; last_xmousedown = 0;
  216.             }
  217.             break;
  218.     }
  219.     
  220.     if(last_mousedown == 0) { num_click = 0; return; }
  221.     
  222.     // Mouse double click speed
  223.     GetMyRegStr(reg_section, "DoubleClickSpeed", s, 10, "");
  224.     if(s[0]) doubleclick_time = atoi(s);
  225.     else     doubleclick_time = GetDoubleClickTime();
  226.     
  227.     if(GetTickCount() - last_tickcount > doubleclick_time)
  228.         num_click = 0;
  229.     last_tickcount = GetTickCount();
  230.     
  231.     if(bDown)
  232.     {
  233.         n_func = GetMouseFuncNum(button, num_click + 1);
  234.         if(n_func >= 0 && n_func != MOUSEFUNC_SCREENSAVER)
  235.         {
  236.             for(i = num_click + 2; i <= 4; i++)
  237.             {
  238.                 n_func = GetMouseFuncNum(button, i);
  239.                 if(n_func >= 0) return;
  240.             }
  241.             num_click++;
  242.             exec_button = button;
  243.             OnTimerMouse(hwnd);
  244.         }
  245.         return;
  246.     }
  247.     
  248.     num_click++;
  249.     
  250.     n_func = GetMouseFuncNum(button, num_click);
  251.     if(n_func < 0) return;
  252.     
  253.     for(i = num_click + 1; i <= 4; i++)
  254.     {
  255.         n_func = GetMouseFuncNum(button, i);
  256.         if(n_func >= 0)
  257.         {
  258.             exec_button = button;
  259.             timer = TRUE;
  260.             SetTimer(hwnd, IDTIMER_MOUSE, doubleclick_time, 0);
  261.             return;
  262.         }
  263.     }
  264.     
  265.     exec_button = button;
  266.     OnTimerMouse(hwnd);
  267. }
  268.  
  269. /*------------------------------------------------
  270.    execute mouse function
  271. --------------------------------------------------*/
  272. void OnTimerMouse(HWND hwnd)
  273. {
  274.     int button;
  275.     LONG n_func;
  276.     char entry[20];
  277.     
  278.     button = exec_button;
  279.     if(timer) KillTimer(hwnd, IDTIMER_MOUSE); timer = FALSE;
  280.     
  281.     n_func = GetMouseFuncNum(button, num_click);
  282.     
  283.     if(n_func < 0) return;
  284.     
  285.     switch (n_func)
  286.     {
  287.         case MOUSEFUNC_DATETIME:
  288.         case MOUSEFUNC_EXITWIN:
  289.         case MOUSEFUNC_RUNAPP:
  290.         case MOUSEFUNC_MINALL:
  291.         {
  292.             WPARAM wParam;
  293.             HWND hwndTray;
  294.             if(n_func == MOUSEFUNC_DATETIME)
  295.                 wParam = IDC_DATETIME;
  296.             else if(n_func == MOUSEFUNC_EXITWIN)
  297.                 wParam = IDC_EXITWIN;
  298.             else if(n_func == MOUSEFUNC_RUNAPP)
  299.                 wParam = IDC_RUNAPP;
  300.             else if(n_func == MOUSEFUNC_MINALL)
  301.                 wParam = IDC_MINALL;
  302.             hwndTray = FindWindow("Shell_TrayWnd", NULL);
  303.             if(hwndTray) PostMessage(hwndTray, WM_COMMAND, wParam, 0);
  304.             break;
  305.         }
  306.         case MOUSEFUNC_SYNCTIME:
  307.             StartSyncTime(hwnd, NULL, 0); break;
  308.         case MOUSEFUNC_TIMER:
  309.             DialogTimer(hwnd); break;
  310.         case MOUSEFUNC_CLIPBOARD:
  311.         {
  312.             LPARAM lParam;
  313.             lParam = MAKELONG((WORD)button, (WORD)num_click);
  314.             PostMessage(g_hwndClock, CLOCKM_COPY, 0, lParam);
  315.             break;
  316.         }
  317.         case MOUSEFUNC_SCREENSAVER:
  318.         {
  319.             SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
  320.             break;
  321.         }
  322.         case MOUSEFUNC_OPENFILE:
  323.         {
  324.             char fname[1024];
  325.             wsprintf(entry, "%d%dFile", button, num_click);
  326.             GetMyRegStr(reg_section, entry, fname, 1024, "");
  327.             if(fname[0]) ExecFile(hwnd, fname);
  328.         }
  329.     }
  330. }
  331.  
  332. int GetMouseFuncNum(int button, int nclick)
  333. {
  334.     char entry[20];
  335.     wsprintf(entry, "%d%d", button, nclick);
  336.     return GetMyRegLong(reg_section, entry, -1);
  337. }
  338.