/[winpt]/trunk/Src/wptHotkey.cpp
ViewVC logotype

Diff of /trunk/Src/wptHotkey.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 179 by twoaday, Sat Nov 5 12:28:12 2005 UTC revision 180 by twoaday, Mon Mar 6 14:41:58 2006 UTC
# Line 1  Line 1 
1  /* wptHotkey.cpp - Systemwide hotkeys  /* wptHotkey.cpp - Systemwide hotkeys
2   *      Copyright (C) 2001, 2002, 2003 Timo Schulz   *      Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 31  Line 31 
31  #include "wptNLS.h"  #include "wptNLS.h"
32  #include "wptTypes.h"  #include "wptTypes.h"
33    
34    
35    /* List of all predefined hotkeys. */
36    hotkey_s wpt_hotkeys[]  = {
37        /* ALT+CTRL+ */
38        {"ClipEncrypt", 1, WPT_CLIP_ENCRYPT_ID,           1, 0, 0x45}, /* E */
39        {"ClipDecrypt", 1, WPT_CLIP_DECRYPT_VERIFY_ID,    1, 0, 0x44}, /* D */
40        {"ClipSign", 1, WPT_CLIP_SIGN_ID,                 1, 0, 0x53}, /* S */
41        {"ClipSignEnc", 1, WPT_CLIP_SIGN_ENCRYPT_ID,      1, 0, 0x42}, /* B */
42        /* ALT+SHIFT+ */
43        {"CwsEncrypt", 1, WPT_CURRWND_ENCRYPT_ID,        0, 1, 0x45}, /* E */
44        {"CwsDecrypt", 1, WPT_CURRWND_DECRYPT_VERIFY_ID, 0, 1, 0x44}, /* D */
45        {"CwsSign", 1, WPT_CURRWND_SIGN_ID,              0, 1, 0x53}, /* S */
46        {"CwsSignEnc", 1, WPT_CURRWND_SIGN_ENCRYPT_ID,   0, 1, 0x42}, /* B */
47        /* Agent ALT+CTRL+ */
48        {"AgentForget", 1, WPT_AGENT_FORGET_ID,           1, 0, 0x46}, /* F */
49        {0}
50    };
51    
52    
53    /* Global error variable. */
54  static int err_hotkey = 0;  static int err_hotkey = 0;
55    
56  const char *  const char*
57  hotkeys_strerror (void)  hotkeys_strerror (void)
58  {  {
59      switch (err_hotkey) {      switch (err_hotkey) {
# Line 52  hotkeys_strerror (void) Line 72  hotkeys_strerror (void)
72  }  }
73    
74    
75    /* Register all enabled hotkeys. */
76  int  int
77  hotkeys_register (HWND wnd)  hotkeys_register (HWND wnd)
78  {  {
# Line 69  hotkeys_register (HWND wnd) Line 90  hotkeys_register (HWND wnd)
90      }      }
91    
92      return rc;      return rc;
93  } /* hotkeys_register */  }
94    
95    
96    /* Unregister all hotkeys. */
97  int  int
98  hotkeys_unregister (HWND wnd)  hotkeys_unregister (HWND wnd)
99  {  {
100      int j = 0, rc = 0;        int j = 0;
101    
102      for (j=0; wpt_hotkeys[j].id != 0; j++) {      for (j=0; wpt_hotkeys[j].id != 0; j++)
103          if (wpt_hotkeys[j].enabled) {          hotkey_unregister_single (wnd, &wpt_hotkeys[j]);
             rc = hotkey_unregister_single (wnd, &wpt_hotkeys[j]);  
             if (rc)  
                 break;  
         }  
     }  
104    
105      return rc;      return 0;
106  } /* hotkeys_unregister */  }
107    
108    
109    /* Register a single hotkey @hk. */
110  int  int
111  hotkey_register_single (HWND wnd, hotkey_t hk)  hotkey_register_single (HWND wnd, hotkey_t hk)
112  {  {
     int keymod=0;  
113      int rc;      int rc;
114        int keymod = 0;
115    
116      if (!hk->enabled)      if (!hk->enabled)
117          return 0;          return 0;
           
118      if (hk->alt_ctrl)      if (hk->alt_ctrl)
119          keymod = MOD_CONTROL | MOD_ALT;          keymod = MOD_CONTROL | MOD_ALT;
120      else if (hk->alt_shift)      else if (hk->alt_shift)
# Line 107  hotkey_register_single (HWND wnd, hotkey Line 124  hotkey_register_single (HWND wnd, hotkey
124      if (!rc)      if (!rc)
125          return WPTERR_HOTKEY;          return WPTERR_HOTKEY;
126      return 0;      return 0;
127  } /* hotkey_register_single */  }
128    
129    
130    /* Unregister a single hotkey @hk. */
131  int  int
132  hotkey_unregister_single (HWND wnd, hotkey_t hk)  hotkey_unregister_single (HWND wnd, hotkey_t hk)
133  {  {
134      int rc = UnregisterHotKey (wnd, hk->id);      int rc = 0;
     return rc==0? WPTERR_HOTKEY: 0;  
 } /* hotkey_unregister_single */  
   
   
 void  
 hotkeys_modify (void)  
 {  
     int i;  
135    
136      for (i = 0; wpt_hotkeys[i].id; i++) {      rc = UnregisterHotKey (wnd, hk->id);
137          if( reg_hotkeys[i].enabled ) {      return rc==0? WPTERR_HOTKEY: 0;
138              wpt_hotkeys[i].key = reg_hotkeys[i].key[0];  }
             wpt_hotkeys[i].enabled = 1;  
         }        
     }  
 } /* hotkeys_modify */  
139    
140    
141  void  void
142  hotkey_disable (reg_hotkey_t rhk)  hotkey_disable (hotkey_t hk)
143  {  {
144      strcpy (rhk->key, " ");      hk->enabled = 0;
145      rhk->enabled = 0;  }
 } /* hotkey_disable */  
146    
147    
148  void  void
149  hotkey_enable (reg_hotkey_t rhk, const char * key)  hotkey_enable (hotkey_t hk, const char *key)
150  {  {
151      if (strlen (key) > 2)      if (strlen (key) > 2)
152          BUG (0);          BUG (0);
153      strcpy (rhk->key, key);      hk->key = *key;
154      rhk->enabled = 1;      hk->enabled = 1;
155  } /* hotkey_enable */  }

Legend:
Removed from v.179  
changed lines
  Added in v.180

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26