Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.4 KiB

  1. /****************************************************************************
  2. GDATA.CPP
  3. Owner: cslim
  4. Copyright (c) 1997-1999 Microsoft Corporation
  5. Instance data and Shared memory data management functions
  6. History:
  7. 14-JUL-1999 cslim Copied from IME98 source tree
  8. *****************************************************************************/
  9. #include "private.h"
  10. #include "hanja.h"
  11. #include "immsec.h"
  12. #include "debug.h"
  13. #include "config.h"
  14. #include "gdata.h"
  15. #include "lexheader.h"
  16. // CIMEData static variables
  17. HANDLE CIMEData::m_vhSharedData = 0;
  18. IMEDATA CIMEData::m_ImeDataDef;
  19. static const CHAR IMEKR_IME_SHAREDDATA_MUTEX_NAME[] = "{E12875A0-C3F1-4273-AB6D-9B9948804271}";
  20. static const CHAR IMEKR_IME_SHAREDDATA_NAME[] = "{F6AE3B77-65B1-4181-993C-701461C8F982}";
  21. __inline BOOL DoEnterCriticalSection(HANDLE hMutex)
  22. {
  23. if(WAIT_FAILED==WaitForSingleObject(hMutex, 3000)) // Wait 3 seconds
  24. return(FALSE);
  25. return(TRUE);
  26. }
  27. BOOL CIMEData::InitSharedData()
  28. {
  29. HANDLE hMutex;
  30. BOOL fRet = fFalse;
  31. LPIMEDATA pImedata;
  32. DebugMsg(DM_TRACE, TEXT("InitSharedData"));
  33. hMutex = CreateMutex(GetIMESecurityAttributes(), fFalse, IMEKR_IME_SHAREDDATA_MUTEX_NAME);
  34. if (hMutex != NULL)
  35. {
  36. // *** Begin Critical Section ***
  37. DoEnterCriticalSection(hMutex);
  38. if((m_vhSharedData = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE, fTrue, IMEKR_IME_SHAREDDATA_NAME)))
  39. {
  40. DebugMsg(DM_TRACE, TEXT("InitSharedData - IME shared data already exist"));
  41. fRet = fTrue;
  42. }
  43. else // if shared memory does not exist
  44. {
  45. m_vhSharedData = CreateFileMapping(INVALID_HANDLE_VALUE, GetIMESecurityAttributes(), PAGE_READWRITE,
  46. 0, sizeof(IMEDATA),
  47. IMEKR_IME_SHAREDDATA_NAME);
  48. Assert(m_vhSharedData != 0);
  49. // if shared memory not exist create it
  50. if (m_vhSharedData)
  51. {
  52. DebugMsg(DM_TRACE, TEXT("InitSharedData::InitSharedData() - File mapping Created"));
  53. pImedata = (LPIMEDATA)MapViewOfFile(m_vhSharedData, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
  54. if (!pImedata)
  55. {
  56. Assert(0);
  57. goto ExitCreateSharedData;
  58. }
  59. // initialize the data to zero
  60. ZeroMemory(pImedata, sizeof(IMEDATA));
  61. // Unint value of status and comp window position
  62. pImedata->ptStatusPos.x = pImedata->ptStatusPos.y = -1;
  63. pImedata->ptCompPos.x = pImedata->ptCompPos.y = -1;
  64. // Unmap memory
  65. UnmapViewOfFile(pImedata);
  66. DebugMsg(DM_TRACE, TEXT("IME shared data handle created successfully"));
  67. fRet = fTrue;
  68. }
  69. }
  70. ExitCreateSharedData:
  71. ReleaseMutex(hMutex);
  72. CloseHandle(hMutex);
  73. // *** End Critical Section ***
  74. }
  75. FreeIMESecurityAttributes();
  76. return fRet;
  77. }
  78. // Close shared memory handle. This called when process detach time.
  79. BOOL CIMEData::CloseSharedMemory()
  80. {
  81. HANDLE hMutex;
  82. BOOL fRet = fTrue;
  83. DebugMsg(DM_TRACE, TEXT("CloseSharedMemory"));
  84. hMutex = CreateMutex(GetIMESecurityAttributes(), fFalse, IMEKR_IME_SHAREDDATA_MUTEX_NAME);
  85. // *** Begin Critical Section ***
  86. DoEnterCriticalSection(hMutex);
  87. if (m_vhSharedData)
  88. {
  89. if (fRet = CloseHandle(m_vhSharedData))
  90. m_vhSharedData = 0;
  91. Assert(fRet);
  92. }
  93. ReleaseMutex(hMutex);
  94. CloseHandle(hMutex);
  95. // *** End Critical Section ***
  96. FreeIMESecurityAttributes();
  97. return fTrue;
  98. }
  99. ///////////////////////////////////////////////////////////////////////////////
  100. void CIMEData::InitImeData()
  101. {
  102. if (m_pImedata == NULL)
  103. return;
  104. // Get Work Area
  105. SystemParametersInfo(SPI_GETWORKAREA, 0, &(m_pImedata->rcWorkArea), 0);
  106. // If IMEDATA is not initialized ever, fill it with default value first,
  107. // and then try to read from registry.
  108. // If IMEDATA overwritten by any reason, it will recover to initial data.
  109. if (m_pImedata->ulMagic != IMEDATA_MAGIC_NUMBER)
  110. {
  111. m_pImedata->ulMagic = IMEDATA_MAGIC_NUMBER;
  112. // Default option setting. It can be changed according to registry in ImeSelect
  113. SetCurrentBeolsik(KL_2BEOLSIK);
  114. m_pImedata->fJasoDel = fTrue;
  115. m_pImedata->fKSC5657Hanja = fFalse;
  116. // Default status Buttons
  117. #if !defined(_WIN64)
  118. m_pImedata->uNumOfButtons = 3;
  119. #else
  120. m_pImedata->uNumOfButtons = 2;
  121. #endif
  122. m_pImedata->iCurButtonSize = BTN_MIDDLE;
  123. m_pImedata->StatusButtons[0].m_ButtonType = HAN_ENG_TOGGLE_BUTTON;
  124. m_pImedata->StatusButtons[1].m_ButtonType = HANJA_CONV_BUTTON;
  125. #if !defined(_WIN64)
  126. m_pImedata->StatusButtons[2].m_ButtonType = IME_PAD_BUTTON;
  127. m_pImedata->StatusButtons[3].m_ButtonType = NULL_BUTTON;
  128. #else
  129. m_pImedata->StatusButtons[2].m_ButtonType = NULL_BUTTON;
  130. #endif
  131. // Get all regstry info
  132. GetRegValues(GETSET_REG_ALL);
  133. //
  134. m_pImedata->xCandWi = 320;
  135. m_pImedata->yCandHi = 30;
  136. }
  137. }