Source code of Windows XP (NT5)
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.

266 lines
8.4 KiB

  1. #include "stdafx.h"
  2. #include "pbrush.h"
  3. #include "settings.h"
  4. #include <atlbase.h>
  5. #ifdef _DEBUG
  6. #undef THIS_FILE
  7. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  8. #endif
  9. #include "memtrace.h"
  10. extern BOOL NEAR g_bDriverCanStretch;
  11. extern BOOL NEAR g_bShowAllFiles;
  12. /***************************************************************************/
  13. static TCHAR NEAR mszView[] = TEXT("View");
  14. static TCHAR NEAR mszNoStretching[] = TEXT("NoStretching");
  15. static TCHAR NEAR mszShowAllFiles[] = TEXT("ShowAllFiles");
  16. static TCHAR NEAR mszShowThumbnail[] = TEXT("ShowThumbnail");
  17. static TCHAR NEAR mszShowText[] = TEXT("ShowTextTool");
  18. static TCHAR NEAR mszSnapToGrid[] = TEXT("SnapToGrid");
  19. static TCHAR NEAR mszGridExtent[] = TEXT("GridExtent");
  20. static TCHAR NEAR mszBMPWidth[] = TEXT("BMPWidth");
  21. static TCHAR NEAR mszBMPHeight[] = TEXT("BMPHeight");
  22. static TCHAR NEAR mszThumbXPos[] = TEXT("ThumbXPos");
  23. static TCHAR NEAR mszThumbYPos[] = TEXT("ThumbYPos");
  24. static TCHAR NEAR mszThumbWidth[] = TEXT("ThumbWidth");
  25. static TCHAR NEAR mszThumbHeight[] = TEXT("ThumbHeight");
  26. static TCHAR NEAR mszCurrentUnits[] = TEXT("UnitSetting");
  27. static TCHAR NEAR mszText[] = TEXT("Text");
  28. static TCHAR NEAR mszFaceName[] = TEXT("TypeFaceName");
  29. static TCHAR NEAR mszPointSize[] = TEXT("PointSize");
  30. static TCHAR NEAR mszCharSet[] = TEXT("CharSet");
  31. static TCHAR NEAR mszBold[] = TEXT("Bold");
  32. static TCHAR NEAR mszUnderline[] = TEXT("Underline");
  33. static TCHAR NEAR mszItalic[] = TEXT("Italic");
  34. static TCHAR NEAR mszVertEdit[] = TEXT("VerticalEdit");
  35. static TCHAR NEAR mszPositionX[] = TEXT("PositionX");
  36. static TCHAR NEAR mszPositionY[] = TEXT("PositionY");
  37. static TCHAR NEAR mszTextPen[] = TEXT("TextPen");
  38. static TCHAR NEAR mszColors[] = TEXT("Colors");
  39. static TCHAR NEAR mszNumberOfColors[] = TEXT("NumberOfColors");
  40. static TCHAR NEAR mszSoftware[] = TEXT("Software");
  41. static TCHAR NEAR mszWindowPlacement[] = TEXT("WindowPlacement");
  42. /***************************************************************************/
  43. void OpenAppKey(LPCTSTR pszKeyName, HKEY *phk)
  44. {
  45. *phk = NULL;
  46. CRegKey rkSoftware;
  47. if (rkSoftware.Create(HKEY_CURRENT_USER, mszSoftware) != ERROR_SUCCESS)
  48. {
  49. return;
  50. }
  51. CString cszSubKey;
  52. if (!cszSubKey.LoadString(IDS_REGISTRY_PATH))
  53. {
  54. return;
  55. }
  56. CRegKey rkSubKey;
  57. if (rkSubKey.Create(rkSoftware, cszSubKey) != ERROR_SUCCESS)
  58. {
  59. return;
  60. }
  61. //
  62. // use the app's profile name instead of the
  63. // localizable app name
  64. //
  65. CRegKey rkAppKey;
  66. if (rkAppKey.Create(rkSubKey, theApp.m_pszProfileName) != ERROR_SUCCESS)
  67. {
  68. return;
  69. }
  70. if (RegOpenKey(rkAppKey, pszKeyName, phk) != ERROR_SUCCESS)
  71. {
  72. return;
  73. }
  74. }
  75. void CPBApp::LoadProfileSettings()
  76. {
  77. CWinApp::LoadStdProfileSettings( );
  78. BOOL bNoStretch = (BOOL)GetProfileInt( mszView, mszNoStretching, FALSE );
  79. g_bDriverCanStretch = ! bNoStretch;
  80. m_bShowThumbnail = (BOOL)GetProfileInt( mszView, mszShowThumbnail , FALSE );
  81. g_bShowAllFiles = (BOOL)GetProfileInt( mszView, mszShowAllFiles, FALSE );
  82. int iX = GetProfileInt( mszView, mszBMPWidth , 0 );
  83. int iY = GetProfileInt( mszView, mszBMPHeight, 0 );
  84. if (! iX || ! iY)
  85. {
  86. iX = 0;
  87. iY = 0;
  88. }
  89. m_sizeBitmap = CSize( iX, iY );
  90. HKEY hkView;
  91. OpenAppKey(mszView, &hkView);
  92. if (hkView)
  93. {
  94. DWORD dwType = REG_BINARY;
  95. DWORD dwSize = sizeof(m_wpPlacement);;
  96. if (RegQueryValueEx(hkView, mszWindowPlacement, 0, &dwType, (LPBYTE)&m_wpPlacement,
  97. &dwSize)!= ERROR_SUCCESS || dwType!=REG_BINARY || dwSize!=sizeof(m_wpPlacement))
  98. {
  99. memset((LPVOID)&m_wpPlacement, 0, sizeof(m_wpPlacement));
  100. }
  101. RegCloseKey(hkView);
  102. }
  103. int iW;
  104. int iH;
  105. CPoint ptPos;
  106. CSize size;
  107. iX = GetProfileInt( mszView, mszThumbXPos , 0 );
  108. iY = GetProfileInt( mszView, mszThumbYPos , 0 );
  109. iW = GetProfileInt( mszView, mszThumbWidth , 0 );
  110. iH = GetProfileInt( mszView, mszThumbHeight, 0 );
  111. if (iX && iY && iW && iH)
  112. {
  113. size = CSize( iW, iH );
  114. ptPos = CheckWindowPosition( CPoint( iX, iY ), size );
  115. m_rectFloatThumbnail = CRect( ptPos, size );
  116. }
  117. m_iCurrentUnits = GetProfileInt( mszView, mszCurrentUnits, 0 );
  118. m_bShowTextToolbar = (BOOL)GetProfileInt ( mszText, mszShowText , TRUE );
  119. m_iPointSize = GetProfileInt ( mszText, mszPointSize, 0 );
  120. m_iBoldText = GetProfileInt ( mszText, mszBold , 0 );
  121. m_iUnderlineText = GetProfileInt ( mszText, mszUnderline, 0 );
  122. m_iItalicText = GetProfileInt ( mszText, mszItalic , 0 );
  123. m_iVertEditText = GetProfileInt ( mszText, mszVertEdit, -1 );
  124. m_iPosTextX = GetProfileInt ( mszText, mszPositionX, 0 );
  125. m_iPosTextY = GetProfileInt ( mszText, mszPositionY, 0 );
  126. m_strTypeFaceName = GetProfileString( mszText, mszFaceName , NULL);
  127. m_iCharSet = GetProfileInt ( mszText, mszCharSet , -1 );
  128. if (m_iCharSet == -1)
  129. {
  130. CHARSETINFO csi;
  131. if (!TranslateCharsetInfo((DWORD*)UIntToPtr(GetACP()), &csi, TCI_SRCCODEPAGE))
  132. csi.ciCharset=ANSI_CHARSET;
  133. m_iCharSet = csi.ciCharset;
  134. }
  135. m_iPenText = GetProfileInt ( mszText, mszTextPen , 0 );
  136. m_iSnapToGrid = GetProfileInt( mszView, mszSnapToGrid, 0 );
  137. m_iGridExtent = GetProfileInt( mszView, mszGridExtent, 1 );
  138. m_pColors = new COLORREF[16];
  139. if (m_pColors != NULL)
  140. {
  141. TCHAR szNumber[8];
  142. int iColors = GetProfileInt( mszColors, mszNumberOfColors, 0 );
  143. for (int i = 0; i < iColors; i++)
  144. {
  145. _Itoa( i, szNumber, 10 );
  146. m_pColors[i] = (COLORREF)GetProfileInt( mszColors, szNumber, 0 );
  147. }
  148. m_iColors = i;
  149. }
  150. }
  151. /***************************************************************************/
  152. void CPBApp::SaveProfileSettings()
  153. {
  154. HKEY hkView;
  155. OpenAppKey(mszView, &hkView);
  156. if (hkView)
  157. {
  158. RegSetValueEx(hkView, mszWindowPlacement, 0, REG_BINARY, (LPBYTE)&m_wpPlacement,
  159. sizeof(m_wpPlacement));
  160. RegCloseKey(hkView);
  161. }
  162. WriteProfileInt( mszView, mszShowThumbnail , m_bShowThumbnail );
  163. WriteProfileInt( mszView, mszBMPWidth , m_sizeBitmap.cx );
  164. WriteProfileInt( mszView, mszBMPHeight , m_sizeBitmap.cy );
  165. WriteProfileInt( mszView, mszThumbXPos , m_rectFloatThumbnail.left );
  166. WriteProfileInt( mszView, mszThumbYPos , m_rectFloatThumbnail.top );
  167. WriteProfileInt( mszView, mszThumbWidth , m_rectFloatThumbnail.Width() );
  168. WriteProfileInt( mszView, mszThumbHeight , m_rectFloatThumbnail.Height() );
  169. WriteProfileInt( mszView, mszCurrentUnits , m_iCurrentUnits );
  170. WriteProfileInt( mszView, mszNoStretching , ! g_bDriverCanStretch );
  171. WriteProfileInt( mszText, mszShowText , m_bShowTextToolbar );
  172. WriteProfileInt( mszText, mszPointSize , m_iPointSize );
  173. WriteProfileInt( mszText, mszPositionX , m_iPosTextX );
  174. WriteProfileInt( mszText, mszPositionY , m_iPosTextY );
  175. WriteProfileInt( mszText, mszBold , m_iBoldText );
  176. WriteProfileInt( mszText, mszUnderline , m_iUnderlineText );
  177. WriteProfileInt( mszText, mszItalic , m_iItalicText );
  178. WriteProfileInt( mszText, mszVertEdit , m_iVertEditText );
  179. WriteProfileInt( mszText, mszTextPen , m_iPenText );
  180. WriteProfileString( mszText, mszFaceName, m_strTypeFaceName );
  181. WriteProfileInt( mszText, mszCharSet , m_iCharSet );
  182. WriteProfileInt( mszView, mszSnapToGrid, m_iSnapToGrid);
  183. WriteProfileInt( mszView, mszGridExtent, m_iGridExtent);
  184. if (m_pColors != NULL)
  185. {
  186. TCHAR szNumber[8];
  187. int iColor;
  188. WriteProfileInt( mszColors, mszNumberOfColors, m_iColors );
  189. for (int i = 0; i < m_iColors; i++)
  190. {
  191. iColor = (int)(m_pColors[i] & (COLORREF)0x00FFFFFF);
  192. _Itoa( i, szNumber, 10 );
  193. WriteProfileInt( mszColors, szNumber, iColor );
  194. }
  195. delete [] m_pColors;
  196. }
  197. }
  198. /***************************************************************************/