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.

97 lines
2.7 KiB

  1. //
  2. // globals.cpp
  3. //
  4. // Global variables.
  5. //
  6. #include "globals.h"
  7. HINSTANCE g_hInst;
  8. LONG g_cRefDll = -1; // -1 /w no refs, for win95 InterlockedIncrement/Decrement compat
  9. CRITICAL_SECTION g_cs;
  10. /* 6565d455-5030-4c0f-8871-83f6afde514f */
  11. const CLSID c_clsidCaseTextService = { 0x6565d455, 0x5030, 0x4c0f, {0x88, 0x71, 0x83, 0xf6, 0xaf, 0xde, 0x51, 0x4f} };
  12. /* 4d5459db-7543-42c0-9204-9195b91f6fb8 */
  13. const GUID c_guidCaseProfile = { 0x4d5459db, 0x7543, 0x42c0, {0x92, 0x04, 0x91, 0x95, 0xb9, 0x1f, 0x6f, 0xb8} };
  14. /* 01679c88-5141-4ee5-a47f-c8d586ff37e1 */
  15. const GUID c_guidLangBarItemButton = { 0x01679c88, 0x5141, 0x4ee5, {0xa4, 0x7f, 0xc8, 0xd5, 0x86, 0xff, 0x37, 0xe1} };
  16. //+---------------------------------------------------------------------------
  17. //
  18. // ToggleChar
  19. //
  20. // Toggle the case of a single char.
  21. //----------------------------------------------------------------------------
  22. WCHAR ToggleChar(WCHAR ch)
  23. {
  24. // toggle english ascii
  25. if ((ch >= 'a' && ch <= 'z') ||
  26. (ch >= 'A' && ch <= 'Z'))
  27. {
  28. return ch ^ 32;
  29. }
  30. // give up for non-ascii
  31. return ch;
  32. }
  33. //+---------------------------------------------------------------------------
  34. //
  35. // ToggleCase
  36. //
  37. // Toggle the case of all text covered by the range. The input range is
  38. // collapsed to its end point on exit.
  39. //
  40. // If fIgnoreRangeEnd == TRUE, all text following the start of range will be
  41. // toggled, and the range will be collapsed at the end-of-doc on exit.
  42. //----------------------------------------------------------------------------
  43. void ToggleCase(TfEditCookie ec, ITfRange *pRange, BOOL fIgnoreRangeEnd)
  44. {
  45. ITfRange *pRangeToggle;
  46. ULONG cch;
  47. ULONG i;
  48. DWORD dwFlags;
  49. WCHAR achText[64];
  50. // backup the current range
  51. if (pRange->Clone(&pRangeToggle) != S_OK)
  52. return;
  53. dwFlags = TF_TF_MOVESTART | (fIgnoreRangeEnd ? TF_TF_IGNOREEND : 0);
  54. while (TRUE)
  55. {
  56. // grab the next block of chars
  57. if (pRange->GetText(ec, dwFlags, achText, ARRAYSIZE(achText), &cch) != S_OK)
  58. break;
  59. // out of text?
  60. if (cch == 0)
  61. break;
  62. // toggle the case
  63. for (i=0; i<cch; i++)
  64. {
  65. achText[i] = ToggleChar(achText[i]);
  66. }
  67. // shift pRangeToggle so it covers just the text we read
  68. if (pRangeToggle->ShiftEndToRange(ec, pRange, TF_ANCHOR_START) != S_OK)
  69. break;
  70. // replace the text
  71. pRangeToggle->SetText(ec, 0, achText, cch);
  72. // prepare for next iteration
  73. pRangeToggle->Collapse(ec, TF_ANCHOR_END);
  74. }
  75. pRangeToggle->Release();
  76. }