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.

186 lines
5.8 KiB

  1. // options.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "wordpad.h"
  14. #include "strings.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDocOptions
  21. void CDocOptions::SaveDockState(CDockState& ds, LPCTSTR lpszProfileName, LPCTSTR lpszLayout)
  22. {
  23. CMemFile file;
  24. CArchive ar(&file, CArchive::store);
  25. ds.Serialize(ar);
  26. ar.Close();
  27. int nSize = file.GetLength();
  28. ASSERT(nSize < 4096);
  29. BYTE* p = new BYTE[nSize];
  30. file.SeekToBegin();
  31. file.Read(p, nSize);
  32. theApp.WriteProfileBinary(lpszProfileName, lpszLayout, p, nSize);
  33. delete [] p;
  34. }
  35. void CDocOptions::SaveOptions(LPCTSTR lpszProfileName)
  36. {
  37. SaveDockState(m_ds1, lpszProfileName, szLayout1);
  38. SaveDockState(m_ds2, lpszProfileName, szLayout2);
  39. theApp.WriteProfileInt(lpszProfileName, szWrap, m_nWordWrap);
  40. int barstate[2] = {0, 0};
  41. for (int i = 0; i < 2; i++)
  42. {
  43. barstate[i] = barstate[i] | (m_barstate[i].m_bRulerBar ? 0x1 : 0);
  44. barstate[i] = barstate[i] | (m_barstate[i].m_bStatusBar ? 0x2 : 0);
  45. barstate[i] = barstate[i] | (m_barstate[i].m_bToolBar ? 0x4 : 0);
  46. barstate[i] = barstate[i] | (m_barstate[i].m_bFormatBar ? 0x8 : 0);
  47. }
  48. theApp.WriteProfileInt(lpszProfileName, TEXT("BarState0"), barstate[0]);
  49. theApp.WriteProfileInt(lpszProfileName, TEXT("BarState1"), barstate[1]);
  50. }
  51. void CDocOptions::LoadDockState(CDockState& ds, LPCTSTR lpszProfileName, LPCTSTR lpszLayout)
  52. {
  53. BYTE* p;
  54. UINT nLen = 0;
  55. if (theApp.GetProfileBinary(lpszProfileName, lpszLayout, &p, &nLen))
  56. {
  57. ASSERT(nLen < 4096);
  58. //
  59. // APPCOMPAT: If this value is not reasonable, then we have likely run into
  60. // a registry corruption problem with wordpad that seems to appear only once
  61. // every 2-3 months. If the registry is corrupted, then we need to fix
  62. // it or wordpad will get into a weird state.
  63. //
  64. if (nLen >= 4096)
  65. {
  66. delete p ;
  67. HKEY hKeyApp = theApp.GetAppRegistryKey() ;
  68. if ((HKEY) 0 != hKeyApp)
  69. {
  70. RegDeleteKey(hKeyApp, lpszProfileName) ;
  71. RegCloseKey(hKeyApp) ;
  72. }
  73. }
  74. else
  75. {
  76. CMemFile file;
  77. file.Write(p, nLen);
  78. file.SeekToBegin();
  79. CArchive ar(&file, CArchive::load);
  80. ds.Serialize(ar);
  81. ar.Close();
  82. delete p;
  83. }
  84. }
  85. }
  86. void CDocOptions::LoadOptions(LPCTSTR lpszProfileName)
  87. {
  88. LoadDockState(m_ds1, lpszProfileName, szLayout1);
  89. LoadDockState(m_ds2, lpszProfileName, szLayout2);
  90. m_nWordWrap = _VerifyWordWrap(theApp.GetProfileInt(lpszProfileName, szWrap, m_nDefWrap));
  91. for (int bar = 0; bar < 2; bar++)
  92. {
  93. CDockState& ds = (bar == 0) ? m_ds1 : m_ds2;
  94. CBarState& barstate = m_barstate[bar];
  95. int defaultstate = (lpszProfileName == szTextSection) ? 0x6 : 0xf;
  96. int state;
  97. if (0 == bar)
  98. {
  99. state = theApp.GetProfileInt(lpszProfileName, TEXT("BarState0"), defaultstate);
  100. }
  101. else
  102. {
  103. state = theApp.GetProfileInt(lpszProfileName, TEXT("BarState1"), defaultstate);
  104. }
  105. barstate.m_bRulerBar = (state & 0x1) != 0;
  106. barstate.m_bStatusBar = (state & 0x2) != 0;
  107. barstate.m_bToolBar = (state & 0x4) != 0;
  108. barstate.m_bFormatBar = (state & 0x8) != 0;
  109. //
  110. // The following code is used to setup the barstate from the dock state.
  111. // It is really only here to support upgrading from NT 4 or Win95 to
  112. // NT 5 or Memphis. It can problably be removed for NT 6.
  113. //
  114. for (int i = 0;i < ds.m_arrBarInfo.GetSize(); i++)
  115. {
  116. CControlBarInfo* pInfo = (CControlBarInfo*)ds.m_arrBarInfo[i];
  117. ASSERT(pInfo != NULL);
  118. switch (pInfo->m_nBarID)
  119. {
  120. case ID_VIEW_FORMATBAR:
  121. barstate.m_bFormatBar = pInfo->m_bVisible;
  122. break;
  123. case ID_VIEW_RULER:
  124. barstate.m_bRulerBar = pInfo->m_bVisible;
  125. break;
  126. case ID_VIEW_TOOLBAR:
  127. barstate.m_bToolBar = pInfo->m_bVisible;;
  128. break;
  129. case ID_VIEW_STATUS_BAR:
  130. barstate.m_bStatusBar = pInfo->m_bVisible;;
  131. break;
  132. }
  133. }
  134. }
  135. }
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CUnit
  138. const CUnit& CUnit::operator=(const CUnit& unit)
  139. {
  140. m_nTPU = unit.m_nTPU;
  141. m_nSmallDiv = unit.m_nSmallDiv;
  142. m_nMediumDiv = unit.m_nMediumDiv;
  143. m_nLargeDiv = unit.m_nLargeDiv;
  144. m_nMinMove = unit.m_nMinMove;
  145. m_nAbbrevID = unit.m_nAbbrevID;
  146. m_bSpaceAbbrev = unit.m_bSpaceAbbrev;
  147. m_strAbbrev = unit.m_strAbbrev;
  148. return *this;
  149. }
  150. CUnit::CUnit(int nTPU, int nSmallDiv, int nMediumDiv, int nLargeDiv,
  151. int nMinMove, UINT nAbbrevID, BOOL bSpaceAbbrev)
  152. {
  153. m_nTPU = nTPU;
  154. m_nSmallDiv = nSmallDiv;
  155. m_nMediumDiv = nMediumDiv;
  156. m_nLargeDiv = nLargeDiv;
  157. m_nMinMove = nMinMove;
  158. m_nAbbrevID = nAbbrevID;
  159. m_bSpaceAbbrev = bSpaceAbbrev;
  160. }