home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / HOTKEY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.5 KB  |  114 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. //----------------------------------------------------------------------------
  8. #include <owl/pch.h>
  9. #if !defined(OWL_HOTKEY_H)
  10. # include <owl/hotkey.h>
  11. #endif
  12. #if !defined(WINSYS_SYSTEM_H)
  13. # include <winsys/system.h>
  14. #endif
  15.  
  16. OWL_DIAGINFO;
  17.  
  18. //
  19. // Constructors for THotKey
  20. //
  21. // Initialize data fields using parameters passed and default values
  22. //
  23. // By default, a Hotkey control associated with the TColumnHeader will:
  24. //   - be visible upon creation
  25. //   - have a border
  26. //
  27. THotKey::THotKey(TWindow*   parent,
  28.                  int        id,
  29.                  int x, int y, int w, int h,
  30.                  TModule*   module)
  31. :
  32.   TControl(parent, id, 0, x, y, w, h, module)
  33. {
  34.   if (!TCommCtrl::IsAvailable())
  35.     throw TXCommCtrl();
  36. #if defined(BI_PLAT_WIN32)
  37.   if (TSystem::IsNT())
  38.     Attr.Style |= WS_BORDER;
  39. #endif
  40. }
  41.  
  42. //
  43. // Construct a hot key control from resource
  44. //
  45. THotKey::THotKey(TWindow*   parent,
  46.                  int        resourceId,
  47.                  TModule*   module)
  48. :
  49.   TControl(parent, resourceId, module)
  50. {
  51.   if (!TCommCtrl::IsAvailable())
  52.     throw TXCommCtrl();
  53. }
  54.  
  55. //
  56. // Return the class name for a hot key control
  57. //
  58. char far*
  59. THotKey::GetClassName()
  60. {
  61.   return HOTKEY_CLASS;
  62. }
  63.  
  64. //
  65. // Transfer a uint16 (the virtual key code) for the control.
  66. //
  67. uint
  68. THotKey::Transfer(void* buffer, TTransferDirection direction)
  69. {
  70.   if (direction == tdGetData)
  71.     *((uint16*)buffer) = GetHotKey();
  72.   else if (direction == tdSetData)
  73.     SetHotKey(*((uint16*)buffer));
  74.  
  75.   return sizeof(uint16);
  76. }
  77.  
  78. //
  79. // Returns the 16-bit virtual key code for the control.
  80. //
  81. uint16
  82. THotKey::GetHotKey()
  83. {
  84.   return LoUint16(SendMessage(HKM_GETHOTKEY));
  85. }
  86.  
  87. //
  88. // Sets the virtual key code and modifier flags for the hot key.
  89. // See the Windows API for more details on VK_xxxx and modifier flags.
  90. //
  91. void
  92. THotKey::SetHotKey(uint16 hotKey)
  93. {
  94.   SendMessage(HKM_SETHOTKEY, TParam1(hotKey));
  95. }
  96.  
  97. //
  98. // Sets the virtual key code and modifier flags for the hot key.
  99. //
  100. void
  101. THotKey::SetHotKey(uint8 vk, uint8 mods)
  102. {
  103.   SetHotKey(MkUint16(vk, mods));
  104. }
  105.  
  106. //
  107. // Sets the invalid key combinations for the hotkey control.
  108. //
  109. void
  110. THotKey::SetRules(uint16 invalid, uint16 defFlag)
  111. {
  112.   SendMessage(HKM_SETRULES, TParam1(invalid), MkParam2(defFlag, 0));
  113. }
  114.