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.

193 lines
6.5 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 "precomp.h"
  10. #include "hanja.h"
  11. #include "immsec.h"
  12. #include "debug.h"
  13. #include "config.h"
  14. #include "gdata.h"
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // Per process variables
  17. // Make sure all per process data shoulde be initialized
  18. BOOL vfUnicode = fTrue;
  19. INSTDATA vInstData = {0};
  20. LPINSTDATA vpInstData = NULL;
  21. // CIMEData static variables
  22. HANDLE CIMEData::m_vhSharedData = 0;
  23. IMEDATA CIMEData::m_ImeDataDef;
  24. static const CHAR IMEKR_IME_SHAREDDATA_MUTEX_NAME[] = "{E12875A0-C3F1-4273-AB6D-9B9948804271}";
  25. static const CHAR IMEKR_IME_SHAREDDATA_NAME[] = "{F6AE3B77-65B1-4181-993C-701461C8F982}";
  26. BOOL CIMEData::InitSharedData()
  27. {
  28. HANDLE hMutex;
  29. BOOL fRet = fFalse;
  30. LPIMEDATA pImedata;
  31. Dbg(DBGID_Mem, TEXT("InitSharedData"));
  32. hMutex = CreateMutex(GetIMESecurityAttributes(), fFalse, IMEKR_IME_SHAREDDATA_MUTEX_NAME);
  33. if (hMutex != NULL)
  34. {
  35. // *** Begin Critical Section ***
  36. DoEnterCriticalSection(hMutex);
  37. if((m_vhSharedData = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE, fTrue, IMEKR_IME_SHAREDDATA_NAME)))
  38. {
  39. Dbg(DBGID_Mem, TEXT("InitSharedData - IME shared data already exist"));
  40. fRet = fTrue;
  41. }
  42. else // if shared memory does not exist
  43. {
  44. m_vhSharedData = CreateFileMapping(INVALID_HANDLE_VALUE, GetIMESecurityAttributes(), PAGE_READWRITE,
  45. 0, sizeof(IMEDATA),
  46. IMEKR_IME_SHAREDDATA_NAME);
  47. DbgAssert(m_vhSharedData != 0);
  48. // if shared memory not exist create it
  49. if (m_vhSharedData)
  50. {
  51. Dbg(DBGID_Mem, TEXT("InitSharedData::InitSharedData() - File mapping Created"));
  52. pImedata = (LPIMEDATA)MapViewOfFile(m_vhSharedData, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
  53. if (!pImedata)
  54. {
  55. DbgAssert(0);
  56. goto ExitCreateSharedData;
  57. }
  58. // initialize the data to zero
  59. ZeroMemory(pImedata, sizeof(IMEDATA));
  60. // Unint value of status and comp window position
  61. pImedata->ptStatusPos.x = pImedata->ptStatusPos.y = -1;
  62. pImedata->ptCompPos.x = pImedata->ptCompPos.y = -1;
  63. // Unmap memory
  64. UnmapViewOfFile(pImedata);
  65. Dbg(DBGID_Mem, TEXT("IME shared data handle created successfully"));
  66. fRet = fTrue;
  67. }
  68. }
  69. ExitCreateSharedData:
  70. ReleaseMutex(hMutex);
  71. CloseHandle(hMutex);
  72. // *** End Critical Section ***
  73. }
  74. FreeIMESecurityAttributes();
  75. return fRet;
  76. }
  77. // Close shared memory handle. This called when process detach time.
  78. BOOL CIMEData::CloseSharedMemory()
  79. {
  80. HANDLE hMutex;
  81. BOOL fRet = fTrue;
  82. Dbg(DBGID_Mem, TEXT("CloseSharedMemory"));
  83. hMutex = CreateMutex(GetIMESecurityAttributes(), fFalse, IMEKR_IME_SHAREDDATA_MUTEX_NAME);
  84. if (hMutex != NULL)
  85. {
  86. // *** Begin Critical Section ***
  87. DoEnterCriticalSection(hMutex);
  88. if (m_vhSharedData)
  89. {
  90. if (fRet = CloseHandle(m_vhSharedData))
  91. m_vhSharedData = 0;
  92. DbgAssert(fRet);
  93. }
  94. ReleaseMutex(hMutex);
  95. CloseHandle(hMutex);
  96. // *** End Critical Section ***
  97. }
  98. FreeIMESecurityAttributes();
  99. return fTrue;
  100. }
  101. ///////////////////////////////////////////////////////////////////////////////
  102. void CIMEData::InitImeData()
  103. {
  104. POINT ptStatusWinPosReg;
  105. // Get Work Area
  106. SystemParametersInfo(SPI_GETWORKAREA, 0, &(m_pImedata->rcWorkArea), 0);
  107. // if current status window position different from registy, reset reg value
  108. if (GetStatusWinPosReg(&ptStatusWinPosReg))
  109. {
  110. if (ptStatusWinPosReg.x != m_pImedata->ptStatusPos.x ||
  111. ptStatusWinPosReg.y != m_pImedata->ptStatusPos.y)
  112. SetRegValues(GETSET_REG_STATUSPOS);
  113. }
  114. // Reset magic number for Winlogon process.
  115. if ((vpInstData->dwSystemInfoFlags & IME_SYSINFO_WINLOGON) != 0)
  116. m_pImedata->ulMagic = 0;
  117. // If IMEDATA is not initialized ever, fill it with default value first,
  118. // and then try to read from registry.
  119. // If IMEDATA overwritten by any reason, it will recover to initial data.
  120. if (m_pImedata->ulMagic != IMEDATA_MAGIC_NUMBER)
  121. {
  122. // Set magic number only if not a Winlogon process
  123. // If current process is WinLogon, we should reload user setting after login
  124. if ((vpInstData->dwSystemInfoFlags & IME_SYSINFO_WINLOGON) == 0)
  125. m_pImedata->ulMagic = IMEDATA_MAGIC_NUMBER;
  126. // Default option setting. It can be changed according to registry in ImeSelect
  127. SetCurrentBeolsik(KL_2BEOLSIK);
  128. m_pImedata->fJasoDel = fTrue;
  129. m_pImedata->fKSC5657Hanja = fFalse;
  130. // Default status Buttons
  131. #if !defined(_WIN64)
  132. m_pImedata->uNumOfButtons = 3;
  133. #else
  134. m_pImedata->uNumOfButtons = 2;
  135. #endif
  136. m_pImedata->iCurButtonSize = BTN_MIDDLE;
  137. m_pImedata->StatusButtons[0].m_ButtonType = HAN_ENG_TOGGLE_BUTTON;
  138. m_pImedata->StatusButtons[1].m_ButtonType = HANJA_CONV_BUTTON;
  139. #if !defined(_WIN64)
  140. m_pImedata->StatusButtons[2].m_ButtonType = IME_PAD_BUTTON;
  141. m_pImedata->StatusButtons[3].m_ButtonType = NULL_BUTTON;
  142. #else
  143. m_pImedata->StatusButtons[2].m_ButtonType = NULL_BUTTON;
  144. #endif
  145. // init with default button status
  146. UpdateStatusButtons(*this);
  147. m_pImedata->cxStatLeftMargin = 3; // 9; if left two vertical exist
  148. m_pImedata->cxStatRightMargin = 3;
  149. m_pImedata->cyStatMargin = 3;
  150. m_pImedata->cyStatButton = m_pImedata->cyStatMargin;
  151. // Get all regstry info
  152. GetRegValues(GETSET_REG_ALL);
  153. UpdateStatusWinDimension();
  154. //
  155. m_pImedata->xCandWi = 320;
  156. m_pImedata->yCandHi = 30;
  157. }
  158. }