XTPDockState.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:56k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPDockState.cpp : implementation of the CXTPDockState class.
  2. //
  3. // This file is a part of the XTREME COMMANDBARS MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Resource.h"
  22. #include "Common/XTPResourceManager.h"
  23. #include "Common/XTPImageManager.h"
  24. #include "Common/XTPDrawHelpers.h"
  25. #include "Common/XTPSystemHelpers.h"
  26. #include "Common/XTPPropExchange.h"
  27. #include "Common/XTPVC50Helpers.h"
  28. #include "Common/XTPVC80Helpers.h"
  29. #ifdef _XTP_INCLUDE_GRAPHICLIBRARY
  30. #include "GraphicLibrary/zlib/zlib.h"
  31. #endif
  32. #include "XTPShortcutManager.h"
  33. #include "XTPDockState.h"
  34. #include "XTPCommandBars.h"
  35. #include "XTPDockBar.h"
  36. #include "XTPDockContext.h"
  37. #include "XTPControls.h"
  38. #include "XTPControl.h"
  39. #include "XTPControlPopup.h"
  40. #include "XTPControlButton.h"
  41. #include "XTPControlComboBox.h"
  42. #include "XTPControlEdit.h"
  43. #include "XTPPopupbar.h"
  44. #include "XTPMenuBar.h"
  45. #include "XTPToolBar.h"
  46. #include "XTPDialogBar.h"
  47. #include "XTPPaintManager.h"
  48. #include "XTPStatusBar.h"
  49. #ifdef _DEBUG
  50. #define new DEBUG_NEW
  51. #undef THIS_FILE
  52. static char THIS_FILE[] = __FILE__;
  53. #endif
  54. const TCHAR _xtpVisible[] = _T("Visible");
  55. const TCHAR _xtpBarSection[] = _T("%s-Bar%d");
  56. const TCHAR _xtpDockBarSection[] = _T("%s-DockBar%d");
  57. const TCHAR _xtpSummarySection[] = _T("%s-Summary");
  58. const TCHAR _xtpXPos[] = _T("XPos");
  59. const TCHAR _xtpYPos[] = _T("YPos");
  60. const TCHAR _xtpMRUWidth[] = _T("MRUWidth");
  61. const TCHAR _xtpMRUDockID[] = _T("MRUDockID");
  62. const TCHAR _xtpMRUDockLeftPos[] = _T("MRUDockLeftPos");
  63. const TCHAR _xtpMRUDockRightPos[] = _T("MRUDockRightPos");
  64. const TCHAR _xtpMRUDockTopPos[] = _T("MRUDockTopPos");
  65. const TCHAR _xtpMRUDockBottomPos[] = _T("MRUDockBottomPos");
  66. const TCHAR _xtpMRUFloatXPos[] = _T("MRUFloatXPos");
  67. const TCHAR _xtpMRUFloatYPos[] = _T("MRUFloatYPos");
  68. const TCHAR _xtpBarID[] = _T("BarID");
  69. const TCHAR _xtpFloating[] = _T("Floating");
  70. const TCHAR _xtpBars[] = _T("Bars");
  71. const TCHAR _xtpScreenCX[] = _T("ScreenCX");
  72. const TCHAR _xtpScreenCY[] = _T("ScreenCY");
  73. const TCHAR _xtpBar[] = _T("Bar#%d");
  74. const TCHAR _xtpCommandBarControlsSection[] = _T("%s-Controls");
  75. const TCHAR _xtpCommandBarControls[] = _T("Controls");
  76. const TCHAR _xtpCommandBarLoadFromFile[] = _T("LoadFromFile");
  77. const TCHAR _xtpDialogBar[] = _T("DialogBar");
  78. class CXTPToolBar::CToolBarInfo
  79. {
  80. public:
  81. CToolBarInfo();
  82. ~CToolBarInfo();
  83. BOOL SaveState(LPCTSTR lpszProfileName, int nIndex);
  84. BOOL LoadState(LPCTSTR lpszProfileName, int nIndex, CXTPDockState* pDockState);
  85. void DoPropExchange(CXTPPropExchange* pPX, CXTPDockState* pDockState);
  86. // Attributes
  87. UINT m_nBarID;      // ID of this bar
  88. BOOL m_bVisible;    // visibility of this bar
  89. BOOL m_bFloating;   // whether floating or not
  90. CPoint m_pointPos;  // topleft point of window
  91. UINT m_nMRUWidth;   // MRUWidth for Dynamic Toolbars
  92. XTPBarPosition m_uMRUDockPosition;  // most recent docked dockbar
  93. CRect m_rectMRUDockPos; // most recent docked position
  94. DWORD m_dwMRUFloatStyle; // most recent floating orientation
  95. CPoint m_ptMRUFloatPos; // most recent floating position
  96. CXTPToolBar* m_pBar;    // bar which this refers to (transient)
  97. BOOL m_bDialogBar;
  98. CSize m_szDialogBarDockingClient;
  99. CSize m_szDialogBarFloatingClient;
  100. };
  101. CXTPToolBar::CToolBarInfo::CToolBarInfo()
  102. {
  103. m_nBarID = 0;
  104. m_bVisible = m_bFloating = FALSE;
  105. m_pBar = NULL;
  106. m_pointPos.x = m_pointPos.y = -1;
  107. m_nMRUWidth = 32767;
  108. m_uMRUDockPosition = xtpBarTop;
  109. m_rectMRUDockPos.SetRectEmpty();
  110. m_dwMRUFloatStyle = 0;
  111. m_ptMRUFloatPos = CPoint(0, 0);
  112. m_bDialogBar = FALSE;
  113. m_szDialogBarFloatingClient = m_szDialogBarDockingClient = CSize(200, 200);
  114. }
  115. CXTPToolBar::CToolBarInfo::~CToolBarInfo()
  116. {
  117. }
  118. void CXTPToolBar::CToolBarInfo::DoPropExchange(CXTPPropExchange* pPX, CXTPDockState* pDockState)
  119. {
  120. ASSERT(pDockState != NULL);
  121. if (!pDockState)
  122. return;
  123. PX_Long(pPX, _T("BarId"), (long&)m_nBarID, 0);
  124. PX_Bool(pPX, _T("Visible"), m_bVisible, TRUE);
  125. PX_Bool(pPX, _T("Floating"), m_bFloating, FALSE);
  126. PX_Long(pPX, _T("MRUWidth"), (long&)m_nMRUWidth);
  127. PX_Enum(pPX, _T("MRUDockPosition"), m_uMRUDockPosition, xtpBarTop);
  128. PX_Point(pPX, _T("PointPos"), m_pointPos, CPoint(0, 0));
  129. PX_Rect(pPX, _T("MRUDockPos"), m_rectMRUDockPos, CRect(0, 0, 0, 0));
  130. PX_Point(pPX, _T("MRUFloatPos"), m_ptMRUFloatPos, CPoint(0, 0));
  131. if (pDockState->GetVersion() > _XTP_SCHEMA_87)
  132. {
  133. PX_Bool(pPX, _T("DialogBar"), m_bDialogBar, FALSE);
  134. if (m_bDialogBar)
  135. {
  136. PX_Size(pPX, _T("DialogBarDockingClientSize"), m_szDialogBarDockingClient, CSize(0, 0));
  137. PX_Size(pPX, _T("DialogBarFloatingClientSize"), m_szDialogBarFloatingClient, CSize(0, 0));
  138. }
  139. }
  140. }
  141. BOOL CXTPToolBar::CToolBarInfo::SaveState(LPCTSTR lpszProfileName, int nIndex)
  142. {
  143. TCHAR szSection[256];
  144. wsprintf(szSection, _xtpBarSection, lpszProfileName, nIndex);
  145. // delete the section
  146. CWinApp* pApp = AfxGetApp();
  147. pApp->WriteProfileString(szSection, NULL, NULL);
  148. pApp->WriteProfileInt(szSection, _xtpBarID, m_nBarID);
  149. if (!m_bVisible)
  150. pApp->WriteProfileInt(szSection, _xtpVisible, m_bVisible);
  151. if (m_bFloating)
  152. {
  153. pApp->WriteProfileInt(szSection, _xtpFloating, m_bFloating);
  154. }
  155. if (m_pointPos.x != -1)
  156. pApp->WriteProfileInt(szSection, _xtpXPos, m_pointPos.x);
  157. if (m_pointPos.y != -1)
  158. pApp->WriteProfileInt(szSection, _xtpYPos, m_pointPos.y);
  159. if (m_nMRUWidth != 32767)
  160. pApp->WriteProfileInt(szSection, _xtpMRUWidth, m_nMRUWidth);
  161. pApp->WriteProfileInt(szSection, _xtpMRUDockID, m_uMRUDockPosition);
  162. pApp->WriteProfileInt(szSection, _xtpMRUDockLeftPos, m_rectMRUDockPos.left);
  163. pApp->WriteProfileInt(szSection, _xtpMRUDockTopPos, m_rectMRUDockPos.top);
  164. pApp->WriteProfileInt(szSection, _xtpMRUDockRightPos, m_rectMRUDockPos.right);
  165. pApp->WriteProfileInt(szSection, _xtpMRUDockBottomPos, m_rectMRUDockPos.bottom);
  166. pApp->WriteProfileInt(szSection, _xtpMRUFloatXPos, m_ptMRUFloatPos.x);
  167. pApp->WriteProfileInt(szSection, _xtpMRUFloatYPos, m_ptMRUFloatPos.y);
  168. pApp->WriteProfileInt(szSection, _xtpDialogBar, m_bDialogBar);
  169. if (m_bDialogBar)
  170. {
  171. pApp->WriteProfileInt(szSection, _T("DialogBarDockingClientCx"), m_szDialogBarDockingClient.cx);
  172. pApp->WriteProfileInt(szSection, _T("DialogBarDockingClientCy"), m_szDialogBarDockingClient.cy);
  173. pApp->WriteProfileInt(szSection, _T("DialogBarFloatingClientCx"), m_szDialogBarFloatingClient.cx);
  174. pApp->WriteProfileInt(szSection, _T("DialogBarFloatingClientCy"), m_szDialogBarFloatingClient.cy);
  175. }
  176. //m_pBar->m_pControls->SaveState(szSection);
  177. return TRUE;
  178. }
  179. BOOL CXTPToolBar::CToolBarInfo::LoadState(LPCTSTR lpszProfileName, int nIndex, CXTPDockState* pDockState)
  180. {
  181. ASSERT(pDockState != NULL);
  182. if (!pDockState)
  183. return FALSE;
  184. CWinApp* pApp = AfxGetApp();
  185. TCHAR szSection[256];
  186. wsprintf(szSection, _xtpBarSection, lpszProfileName, nIndex);
  187. m_nBarID = pApp->GetProfileInt(szSection, _xtpBarID, 0);
  188. m_bVisible = (BOOL) pApp->GetProfileInt(szSection, _xtpVisible, TRUE);
  189. m_bFloating = (BOOL) pApp->GetProfileInt(szSection, _xtpFloating, FALSE);
  190. m_pointPos = CPoint(
  191. pApp->GetProfileInt(szSection, _xtpXPos, -1),
  192. pApp->GetProfileInt(szSection, _xtpYPos, -1));
  193. pDockState->ScalePoint(m_pointPos);
  194. m_nMRUWidth = pApp->GetProfileInt(szSection, _xtpMRUWidth, 32767);
  195. m_uMRUDockPosition = (XTPBarPosition)pApp->GetProfileInt(szSection, _xtpMRUDockID, 0);
  196. m_rectMRUDockPos = CRect(
  197. pApp->GetProfileInt(szSection, _xtpMRUDockLeftPos, 0),
  198. pApp->GetProfileInt(szSection, _xtpMRUDockTopPos, 0),
  199. pApp->GetProfileInt(szSection, _xtpMRUDockRightPos, 0),
  200. pApp->GetProfileInt(szSection, _xtpMRUDockBottomPos, 0));
  201. pDockState->ScaleRectPos(m_rectMRUDockPos);
  202. m_ptMRUFloatPos = CPoint(
  203. pApp->GetProfileInt(szSection, _xtpMRUFloatXPos, 0),
  204. pApp->GetProfileInt(szSection, _xtpMRUFloatYPos, 0));
  205. pDockState->ScalePoint(m_ptMRUFloatPos);
  206. m_bDialogBar = pApp->GetProfileInt(szSection, _xtpDialogBar, FALSE);
  207. if (m_bDialogBar)
  208. {
  209. m_szDialogBarDockingClient.cx = pApp->GetProfileInt(szSection, _T("DialogBarDockingClientCx"), m_szDialogBarDockingClient.cx);
  210. m_szDialogBarDockingClient.cy = pApp->GetProfileInt(szSection, _T("DialogBarDockingClientCy"), m_szDialogBarDockingClient.cy);
  211. m_szDialogBarFloatingClient.cx = pApp->GetProfileInt(szSection, _T("DialogBarFloatingClientCx"), m_szDialogBarFloatingClient.cx);
  212. m_szDialogBarFloatingClient.cy = pApp->GetProfileInt(szSection, _T("DialogBarFloatingClientCy"), m_szDialogBarFloatingClient.cy);
  213. }
  214. return TRUE;
  215. }
  216. void CXTPDockState::ScalePoint(CPoint& pt)
  217. {
  218. if (m_bScaling)
  219. {
  220. pt.x = MulDiv(pt.x, m_sizeDevice.cx, m_sizeLogical.cx);
  221. pt.y = MulDiv(pt.y, m_sizeDevice.cy, m_sizeLogical.cy);
  222. }
  223. CRect rectClip = XTPMultiMonitor()->GetWorkArea(pt);
  224. rectClip.right -= GetSystemMetrics(SM_CXICON);
  225. rectClip.bottom -= GetSystemMetrics(SM_CYICON);
  226. if (pt.x > rectClip.right)
  227. pt.x = rectClip.right;
  228. if (pt.y > rectClip.bottom)
  229. pt.y = rectClip.bottom;
  230. }
  231. void CXTPDockState::ScaleRectPos(CRect& rect)
  232. {
  233. CPoint pt;
  234. if (m_bScaling)
  235. {
  236. pt = rect.TopLeft();
  237. pt.x = MulDiv(pt.x, m_sizeDevice.cx, m_sizeLogical.cx) - rect.left;
  238. pt.y = MulDiv(pt.y, m_sizeDevice.cy, m_sizeLogical.cy) - rect.top;
  239. rect.OffsetRect(pt);
  240. }
  241. pt.x = pt.y = 0;
  242. CRect rectClip = XTPMultiMonitor()->GetWorkArea(rect);
  243. if (rect.left > rectClip.right)
  244. pt.x = rectClip.right - rect.left;
  245. if (rect.top > rectClip.bottom)
  246. pt.y = rectClip.bottom - rect.top;
  247. if (!((pt.x == 0) && (pt.y == 0)))
  248. rect.OffsetRect(pt);
  249. }
  250. CXTPDockState::CXTPDockState()
  251. {
  252. m_dwVersion = _XTP_SCHEMA_CURRENT;
  253. m_bScaling = FALSE;
  254. m_sizeDevice = CSize(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
  255. }
  256. CXTPDockState::~CXTPDockState()
  257. {
  258. Clear();
  259. }
  260. void CXTPDockState::Clear()
  261. {
  262. for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
  263. delete m_arrBarInfo[i];
  264. m_arrBarInfo.RemoveAll();
  265. }
  266. void CXTPDockState::SaveState(LPCTSTR lpszProfileName)
  267. {
  268. int nIndex = 0;
  269. for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
  270. {
  271. TOOLBARINFO* pInfo = m_arrBarInfo[i];
  272. ASSERT(pInfo != NULL);
  273. if (!pInfo)
  274. continue;
  275. if (pInfo->SaveState(lpszProfileName, nIndex))
  276. nIndex++;
  277. }
  278. CWinApp* pApp = AfxGetApp();
  279. TCHAR szSection[256];
  280. wsprintf(szSection, _xtpSummarySection, lpszProfileName);
  281. pApp->WriteProfileInt(szSection, _xtpBars, nIndex);
  282. CSize size = GetScreenSize();
  283. pApp->WriteProfileInt(szSection, _xtpScreenCX, size.cx);
  284. pApp->WriteProfileInt(szSection, _xtpScreenCY, size.cy);
  285. }
  286. void CXTPDockState::LoadState(LPCTSTR lpszProfileName)
  287. {
  288. CWinApp* pApp = AfxGetApp();
  289. TCHAR szSection[256];
  290. wsprintf(szSection, _xtpSummarySection, lpszProfileName);
  291. int nBars = pApp->GetProfileInt(szSection, _xtpBars, 0);
  292. CSize size;
  293. size.cx = pApp->GetProfileInt(szSection, _xtpScreenCX, 0);
  294. size.cy = pApp->GetProfileInt(szSection, _xtpScreenCY, 0);
  295. SetScreenSize(size);
  296. for (int i = 0; i < nBars; i++)
  297. {
  298. TOOLBARINFO* pInfo = new TOOLBARINFO;
  299. m_arrBarInfo.Add(pInfo);
  300. pInfo->LoadState(lpszProfileName, i, this);
  301. }
  302. }
  303. void CXTPDockState::DoPropExchange(CXTPPropExchange* pPX)
  304. {
  305. CXTPPropExchangeSection secDockState(pPX->GetSection(_T("DockState")));
  306. // read/write version info
  307. if (pPX->IsStoring())
  308. {
  309. PX_DWord(&secDockState, _T("Version"), m_dwVersion, 0);
  310. CSize sz = GetScreenSize();
  311. PX_Size(&secDockState, _T("ScreenSize"), sz, CSize(0, 0));
  312. WORD nCount = (WORD)m_arrBarInfo.GetSize();
  313. PX_UShort(&secDockState, _T("Count"), nCount, 0);
  314. for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
  315. {
  316. CString strSection;
  317. strSection.Format(_T("BarInfo%i"), i);
  318. CXTPPropExchangeSection secBarInfo(secDockState->GetSection(strSection));
  319. m_arrBarInfo[i]->DoPropExchange(&secBarInfo, this);
  320. }
  321. }
  322. else
  323. {
  324. Clear(); //empty out dockstate
  325. PX_DWord(&secDockState, _T("Version"), m_dwVersion, 0);
  326. CSize size;
  327. PX_Size(&secDockState, _T("ScreenSize"), size, CSize(0, 0));
  328. SetScreenSize(size);
  329. WORD nOldSize = 0;
  330. PX_UShort(&secDockState, _T("Count"), nOldSize, 0);
  331. m_arrBarInfo.SetSize(nOldSize);
  332. for (int i = 0; i < nOldSize; i++)
  333. {
  334. m_arrBarInfo[i] = new TOOLBARINFO;
  335. CString strSection;
  336. strSection.Format(_T("BarInfo%i"), i);
  337. CXTPPropExchangeSection secBarInfo(secDockState->GetSection(strSection));
  338. m_arrBarInfo[i]->DoPropExchange(&secBarInfo, this);
  339. }
  340. m_dwVersion = _XTP_SCHEMA_CURRENT;
  341. }
  342. }
  343. CSize CXTPDockState::GetScreenSize()
  344. {
  345. return m_sizeDevice;
  346. }
  347. void CXTPDockState::SetScreenSize(CSize& size)
  348. {
  349. m_sizeLogical = size;
  350. m_bScaling = (size != m_sizeDevice && size.cx != 0 && size.cy != 0);
  351. }
  352. void CXTPToolBar::GetBarInfo(CToolBarInfo* pInfo)
  353. {
  354. // get state info
  355. pInfo->m_nBarID = m_nBarID;
  356. pInfo->m_pBar = this;
  357. pInfo->m_bVisible = IsVisible(); // handles delayed showing and hiding
  358. pInfo->m_nMRUWidth = m_nMRUWidth;
  359. CXTPWindowRect rect(this);
  360. if (m_pDockBar != NULL) m_pDockBar->ScreenToClient(&rect);
  361. pInfo->m_pointPos = m_hWnd ? rect.TopLeft() : m_pDockContext->m_ptMRUFloatPos;
  362. pInfo->m_bFloating = m_barPosition == xtpBarFloating;
  363. pInfo->m_uMRUDockPosition = m_pDockContext->m_uMRUDockPosition;
  364. pInfo->m_rectMRUDockPos = m_pDockContext->m_rectMRUDockPos;
  365. pInfo->m_ptMRUFloatPos = m_pDockContext->m_ptMRUFloatPos;
  366. pInfo->m_bDialogBar = IsDialogBar();
  367. pInfo->m_szDialogBarDockingClient = CSize(0, 0);
  368. pInfo->m_szDialogBarFloatingClient = CSize(0, 0);
  369. if (pInfo->m_bDialogBar)
  370. {
  371. pInfo->m_szDialogBarDockingClient = ((CXTPDialogBar*)this)->m_szDockingClient;
  372. pInfo->m_szDialogBarFloatingClient = ((CXTPDialogBar*)this)->m_szFloatingClient;
  373. }
  374. }
  375. void CXTPToolBar::SetBarInfo(CToolBarInfo* pInfo)
  376. {
  377. UINT nFlags = (pInfo->m_bFloating ? 0 : SWP_NOSIZE) | SWP_NOACTIVATE | SWP_NOZORDER;
  378. if (!pInfo->m_bFloating && GetDockBar() == NULL)
  379. nFlags |= SWP_NOMOVE;
  380. m_nMRUWidth = pInfo->m_nMRUWidth;
  381. if (pInfo->m_bDialogBar && IsDialogBar())
  382. {
  383. ((CXTPDialogBar*)this)->m_szDockingClient = pInfo->m_szDialogBarDockingClient;
  384. ((CXTPDialogBar*)this)->m_szFloatingClient = pInfo->m_szDialogBarFloatingClient;
  385. }
  386. ASSERT(m_pDockContext != NULL);
  387. if (!m_pDockContext)
  388. return;
  389. // You need to call EnableDocking before calling LoadBarState
  390. m_pDockContext->m_uMRUDockPosition = pInfo->m_uMRUDockPosition;
  391. m_pDockContext->m_rectMRUDockPos = pInfo->m_rectMRUDockPos;
  392. m_pDockContext->m_ptMRUFloatPos = pInfo->m_ptMRUFloatPos;
  393. // move and show/hide the window
  394. SetWindowPos(NULL, pInfo->m_pointPos.x, pInfo->m_pointPos.y, 0, 0,
  395. nFlags | (pInfo->m_bVisible ? SWP_SHOWWINDOW : SWP_HIDEWINDOW));
  396. m_bVisible = pInfo->m_bVisible;
  397. if (pInfo->m_bFloating) OnRecalcLayout();
  398. }
  399. CString CXTPCommandBars::GetIsolatedFileName(const CString& strPrifileName)
  400. {
  401. if (!XTPSystemVersion()->IsWin2KOrGreater())
  402. return _T("");
  403. LPITEMIDLIST pidlAppData = NULL;
  404. IMalloc* pMalloc = NULL;
  405. CString strAppDataFolder;
  406. HRESULT hr = SHGetMalloc(&pMalloc);
  407. if (SUCCEEDED(hr))
  408. {
  409. if (SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlAppData) == NOERROR)
  410. {
  411. TCHAR   szPath[MAX_PATH];
  412. if (SHGetPathFromIDList(pidlAppData, szPath))
  413. {
  414. strAppDataFolder = szPath;
  415. }
  416. }
  417. pMalloc->Free(pidlAppData);
  418. pMalloc->Release();
  419. }
  420. if (strAppDataFolder.IsEmpty())
  421. return _T("");
  422. strAppDataFolder += CString(_T("\")) + AfxGetApp()->m_pszAppName;
  423. CreateDirectory(strAppDataFolder, NULL);
  424. if (!DIRECTORYEXISTS_S(strAppDataFolder))
  425. return _T("");
  426. // Set customization path as "Documents and SettingsuserApplication DataAppNamePrifileName"
  427. return strAppDataFolder + _T("\") + strPrifileName;
  428. }
  429. BOOL CXTPCommandBars::GetControlsFileName(CString& strFileName, LPCTSTR lpszProfileName)
  430. {
  431. if (!m_strControlsFileName.IsEmpty())
  432. {
  433. strFileName = m_strControlsFileName;
  434. return TRUE;
  435. }
  436. CString strProfileName(lpszProfileName);
  437. REPLACE_S(strProfileName, _T("\"), _T("_"));
  438. strFileName = GetIsolatedFileName(strProfileName);
  439. if (!strFileName.IsEmpty())
  440. return TRUE;
  441. TCHAR szBuff[_MAX_PATH];
  442. VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szBuff, _MAX_PATH));
  443. strFileName.Format(_T("%s-%s"), szBuff, (LPCTSTR)strProfileName);
  444. return TRUE;
  445. }
  446. #define ZIP_HEADER ('Z' + ('I' << 8) + ('P' << 16) + ('!' << 24))
  447. class CXTPZipMemFile : public CMemFile
  448. {
  449. struct ZIPBUFFERHEADER
  450. {
  451. DWORD    dwType;
  452. DWORD    dwSize;
  453. };
  454. struct ZIPBUFFERINFO
  455. {
  456. ZIPBUFFERHEADER bh;
  457. BYTE     bBuffer[1];
  458. };
  459. public:
  460. CXTPZipMemFile()
  461. {
  462. }
  463. CXTPZipMemFile(BYTE* lpBuffer, UINT nBufferSize)
  464. {
  465. AttachCompressedBuffer(lpBuffer, nBufferSize);
  466. }
  467. void AttachCompressedBuffer(BYTE* lpBuffer, UINT nBufferSize, BOOL bAutoDelete = FALSE)
  468. {
  469. #ifdef ZLIB_H
  470. ZIPBUFFERINFO* pbi = (ZIPBUFFERINFO*)lpBuffer;
  471. if (nBufferSize < sizeof(ZIPBUFFERINFO) ||
  472. pbi->bh.dwType != ZIP_HEADER)
  473. {
  474. Attach(lpBuffer, nBufferSize);
  475. m_bAutoDelete = bAutoDelete;
  476. return;
  477. }
  478. DWORD dwDestCount = pbi->bh.dwSize;
  479. BYTE* lpBufferDest = (BYTE*)malloc(dwDestCount);
  480. uncompress(lpBufferDest, &dwDestCount, (LPBYTE)&pbi->bBuffer, nBufferSize - sizeof(ZIPBUFFERHEADER));
  481. ASSERT(dwDestCount == pbi->bh.dwSize);
  482. Attach(lpBufferDest, dwDestCount);
  483. m_bAutoDelete = TRUE;
  484. if (bAutoDelete)
  485. {
  486. free(lpBuffer);
  487. }
  488. #else
  489. Attach(lpBuffer, nBufferSize);
  490. m_bAutoDelete = bAutoDelete;
  491. #endif
  492. }
  493. BOOL OpenCompressedFile(LPCTSTR lpszFileName)
  494. {
  495. CFile file;
  496. if (!file.Open(lpszFileName, CFile::modeRead))
  497. return FALSE;
  498. UINT nSize = (UINT)file.GetLength();
  499. LPBYTE lpBuffer = (LPBYTE)malloc(nSize);
  500. file.Read(lpBuffer, nSize);
  501. file.Close();
  502. AttachCompressedBuffer(lpBuffer, nSize, TRUE);
  503. return TRUE;
  504. }
  505. ~CXTPZipMemFile()
  506. {
  507. }
  508. public:
  509. void DetachCompressedBuffer(BYTE*& lpBuffer, DWORD& dwCount)
  510. {
  511. dwCount = (DWORD)GetPosition();
  512. lpBuffer = Detach();
  513. #ifdef ZLIB_H
  514. if (dwCount < 20)
  515. return;
  516. ZIPBUFFERINFO* pbi = (ZIPBUFFERINFO*)malloc(dwCount + sizeof(ZIPBUFFERHEADER));
  517. if (!pbi)
  518. return;
  519. DWORD dwDestCount = dwCount;
  520. if (compress((LPBYTE)&pbi->bBuffer, &dwDestCount, lpBuffer, dwCount) != Z_OK)
  521. {
  522. free(pbi);
  523. return;
  524. }
  525. pbi->bh.dwType = ZIP_HEADER;
  526. pbi->bh.dwSize = dwCount;
  527. free(lpBuffer);
  528. dwCount = dwDestCount + sizeof(ZIPBUFFERHEADER);
  529. lpBuffer = (LPBYTE)pbi;
  530. #endif
  531. }
  532. };
  533. void CXTPCommandBars::SaveBarState(LPCTSTR lpszProfileName, BOOL bOnlyCustomized /*= TRUE*/)
  534. {
  535. OnSetPreviewMode(FALSE); // Lets be sure we not in preview mode.
  536. CXTPDockState state;
  537. GetDockState(state);
  538. state.SaveState(lpszProfileName);
  539. SaveDockBarsState(lpszProfileName);
  540. XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
  541. param.pCommandBars = this;
  542. param.bSaveOnlyCustomized = bOnlyCustomized;
  543. if (m_bCustomizeAvail)
  544. {
  545. CXTPCommandBarList lstCommandBars(this);
  546. GenerateCommandBarList(&lstCommandBars, &param);
  547. CXTPZipMemFile memFile;
  548. CArchive ar (&memFile, CArchive::store);
  549. TCHAR szSection[256];
  550. wsprintf(szSection, _xtpCommandBarControlsSection, lpszProfileName);
  551. CXTPPropExchangeArchive px(ar);
  552. px.m_dwData = (DWORD_PTR)&param;
  553. if (SaveCommandBarList(&px, &lstCommandBars))
  554. {
  555. ar.Flush();
  556. DWORD dwCount = 0;
  557. BYTE* pControls = 0;
  558. memFile.DetachCompressedBuffer(pControls, dwCount);
  559. CString strFileName;
  560. BOOL bSaveToFile = dwCount > 16000;
  561. if (bSaveToFile)
  562. {
  563. bSaveToFile = GetControlsFileName(strFileName, lpszProfileName);
  564. }
  565. if (bSaveToFile)
  566. {
  567. ::DeleteFile((LPCTSTR)strFileName);
  568. }
  569. if (bSaveToFile)
  570. {
  571. try
  572. {
  573. CFile file;
  574. if (file.Open(strFileName, CFile::modeWrite | CFile::modeCreate))
  575. {
  576. file.Write(pControls, dwCount);
  577. AfxGetApp()->WriteProfileString(szSection, _xtpCommandBarControls, strFileName);
  578. AfxGetApp()->WriteProfileInt(szSection, _xtpCommandBarLoadFromFile, TRUE);
  579. file.Close();
  580. SetFileAttributes(strFileName, FILE_ATTRIBUTE_HIDDEN);
  581. }
  582. }
  583. catch (CFileException* pEx)
  584. {
  585. TRACE(_T("CXTPCommandBars::SaveBarState. File exceptionrn"));
  586. pEx->Delete ();
  587. }
  588. }
  589. else
  590. {
  591. AfxGetApp()->WriteProfileBinary(szSection, _xtpCommandBarControls, pControls, dwCount);
  592. AfxGetApp()->WriteProfileInt(szSection, _xtpCommandBarLoadFromFile, FALSE);
  593. }
  594. ar.Abort();
  595. memFile.Close();
  596. free(pControls);
  597. }
  598. else
  599. {
  600. AfxGetApp()->WriteProfileString(szSection, NULL, NULL);
  601. }
  602. }
  603. if (GetMenuBar() && GetMenuBar()->m_bDirtyMenu)
  604. {
  605. GetMenuBar()->SwitchActiveMenu();
  606. }
  607. m_pOptions->bDirtyState = FALSE;
  608. }
  609. void CXTPCommandBars::_LoadControlsPart(CFile& file, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam)
  610. {
  611. CArchive ar (&file, CArchive::load);
  612. CXTPPropExchangeArchive px(ar);
  613. px.m_dwData = (DWORD_PTR)pParam;
  614. CXTPCommandBarList lstCommandBars(this);
  615. if (LoadCommandBarList(&px, &lstCommandBars))
  616. {
  617. RestoreCommandBarList(&lstCommandBars, pParam->bLoadSilent);
  618. }
  619. ar.Close();
  620. }
  621. void CXTPCommandBars::LoadBarState(LPCTSTR lpszProfileName, BOOL bSilent)
  622. {
  623. XTP_COMMANDBARS_PROPEXCHANGE_PARAM paramT;
  624. paramT.pCommandBars = this;
  625. paramT.bLoadSilent = bSilent;
  626. if (m_bCustomizeAvail)
  627. {
  628. TCHAR szSection[256];
  629. wsprintf(szSection, _xtpCommandBarControlsSection, lpszProfileName);
  630. if (AfxGetApp()->GetProfileInt(szSection, _xtpCommandBarLoadFromFile, FALSE))
  631. {
  632. CString strFileName = AfxGetApp()->GetProfileString(szSection, _xtpCommandBarControls);
  633. CXTPZipMemFile file;
  634. if (file.OpenCompressedFile(strFileName))
  635. {
  636. _LoadControlsPart(file, &paramT);
  637. }
  638. }
  639. else
  640. {
  641. BYTE* pControls = NULL;
  642. DWORD dwCount = 0;
  643. CXTPPropExchangeSection sec(TRUE, szSection);
  644. // PX_Blob support 16000 characters for ini file (MFC - 4096)
  645. if (PX_Blob(&sec, _xtpCommandBarControls, pControls, dwCount))
  646. {
  647. CXTPZipMemFile memFile(pControls, dwCount);
  648. _LoadControlsPart(memFile, &paramT);
  649. memFile.Close();
  650. }
  651. if (pControls) free(pControls);
  652. }
  653. }
  654. CXTPDockState state;
  655. state.LoadState(lpszProfileName);
  656. LoadDockBarsState(lpszProfileName);
  657. SetDockState(state);
  658. RecalcFrameLayout(TRUE);
  659. m_pOptions->bDirtyState = FALSE;
  660. }
  661. CXTPStatusBar* CXTPCommandBars::GetStatusBar() const
  662. {
  663. CWnd* pBar = m_pFrame->GetDlgItem(AFX_IDW_STATUS_BAR);
  664. return DYNAMIC_DOWNCAST(CXTPStatusBar, pBar);
  665. }
  666. void CXTPCommandBars::SaveDockBarsState(LPCTSTR lpszProfileName)
  667. {
  668. CWinApp* pApp = AfxGetApp();
  669. TCHAR szSection[256];
  670. for (int nIndex = 0; nIndex < 4; nIndex++)
  671. {
  672. wsprintf(szSection, _xtpDockBarSection, lpszProfileName, nIndex);
  673. pApp->WriteProfileString(szSection, NULL, NULL);
  674. CXTPDockBar* pDock = m_pDocks[nIndex];
  675. int nSize = (int)pDock->m_arrBars.GetSize();
  676. if (nSize > 1)
  677. {
  678. int nCount = 0;
  679. DWORD dwIDPrev = (DWORD)-1;
  680. for (int i = 0; i < nSize; i++)
  681. {
  682. CXTPToolBar* pBar = (CXTPToolBar*)pDock->m_arrBars[i];
  683. DWORD dwID = pBar ? pBar->m_nBarID : 0;
  684. if (dwIDPrev == 0 && dwID == 0)
  685. continue;
  686. dwIDPrev = dwID;
  687. TCHAR buf[16];
  688. wsprintf(buf, _xtpBar, nCount++);
  689. pApp->WriteProfileInt(szSection, buf, (int)dwID);
  690. }
  691. pApp->WriteProfileInt(szSection, _xtpBars, nCount);
  692. }
  693. }
  694. CXTPStatusBar* pBar = GetStatusBar();
  695. if (pBar != NULL)
  696. {
  697. pBar->SaveState(lpszProfileName);
  698. }
  699. else
  700. {
  701. pApp->WriteProfileString(lpszProfileName, _T("StatusBar"), NULL);
  702. }
  703. }
  704. void CXTPCommandBars::LoadDockBarsState(LPCTSTR lpszProfileName)
  705. {
  706. CWinApp* pApp = AfxGetApp();
  707. TCHAR szSection[256];
  708. for (int nIndex = 0; nIndex < 4; nIndex++)
  709. {
  710. wsprintf(szSection, _xtpDockBarSection, lpszProfileName, nIndex);
  711. CXTPDockBar* pDock = m_pDocks[nIndex];
  712. int nBars = pApp->GetProfileInt(szSection, _xtpBars, 0);
  713. if (nBars > 1)
  714. {
  715. for (int i = 0; i < nBars; i++)
  716. {
  717. TCHAR buf[16];
  718. wsprintf(buf, _xtpBar, i);
  719. DWORD dwID = pApp->GetProfileInt(szSection, buf, 0);
  720. CXTPToolBar* pBar = GetToolBar(dwID);
  721. if (pBar)
  722. {
  723. if (pBar->m_hWnd && pBar->GetParent() != pDock)
  724. pBar->SetParent(pDock);
  725. if (pBar->m_pDockBar != NULL)
  726. pBar->m_pDockBar->RemoveCommandBar(pBar);
  727. pBar->m_pDockBar = pDock;
  728. pBar->m_barPosition = pDock->GetPosition();
  729. }
  730. pDock->m_arrBars.InsertAt(i, pBar);
  731. }
  732. }
  733. }
  734. CXTPStatusBar* pBar = GetStatusBar();
  735. if (pBar != NULL) pBar->LoadState(lpszProfileName);
  736. }
  737. void CXTPCommandBars::DoPropExchange(CXTPPropExchange* pPX, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam)
  738. {
  739. if (pPX->IsStoring())
  740. OnSetPreviewMode(FALSE); // Lets be sure we not in preview mode.
  741. XTP_COMMANDBARS_PROPEXCHANGE_PARAM paramT;
  742. if (pParam == NULL)
  743. pParam = &paramT;
  744. pParam->pCommandBars = this;
  745. pPX->m_dwData = (DWORD_PTR)pParam;
  746. CXTPDockState state;
  747. pPX->ExchangeSchemaSafe();
  748. if (pPX->IsStoring())
  749. {
  750. CXTPToolBar* pDesignerBar = 0;
  751. if (pParam->bSerializeActions)
  752. {
  753. CXTPPropExchangeSection secActions(pPX->GetSection(_T("Actions")));
  754. PX_Bool(&secActions, _T("Enabled"), m_bEnableActions, FALSE);
  755. m_pActions->DoPropExchange(&secActions);
  756. }
  757. if (pParam->bSerializeDesignerControls && m_pDesignerControls)
  758. {
  759. pDesignerBar = (CXTPToolBar*)Add(_T("Controls"), xtpBarFloating);
  760. if (pDesignerBar->m_pControls != NULL)
  761. {
  762. pDesignerBar->m_pControls->InternalRelease();
  763. }
  764. pDesignerBar->m_pControls = m_pDesignerControls;
  765. m_pDesignerControls->InternalAddRef();
  766. pDesignerBar->SetBarID(0xFFEEFF);
  767. pDesignerBar->SetVisible(FALSE);
  768. }
  769. if (pParam->bSerializeControls)
  770. {
  771. CXTPCommandBarList lstCommandBars(this);
  772. GenerateCommandBarList(&lstCommandBars, pParam);
  773. VERIFY(SaveCommandBarList(pPX, &lstCommandBars));
  774. }
  775. if (pDesignerBar)
  776. {
  777. Remove(pDesignerBar);
  778. }
  779. if (pParam->bSerializeLayout)
  780. {
  781. GetDockState(state);
  782. CXTPPropExchangeSection secLayout(pPX->GetSection(_T("Layout")));
  783. state.DoPropExchange(&secLayout);
  784. SerializeDockBarsState(&secLayout);
  785. }
  786. if (GetMenuBar() && GetMenuBar()->m_bDirtyMenu)
  787. {
  788. GetMenuBar()->SwitchActiveMenu();
  789. }
  790. }
  791. else
  792. {
  793. if (pParam->bSerializeActions && pPX->GetSchema() > _XTP_SCHEMA_100)
  794. {
  795. CXTPPropExchangeSection secActions(pPX->GetSection(_T("Actions")));
  796. PX_Bool(&secActions, _T("Enabled"), m_bEnableActions, FALSE);
  797. m_pActions->DoPropExchange(&secActions);
  798. }
  799. if (pParam->bSerializeControls)
  800. {
  801. CXTPCommandBarList lstCommandBars(this);
  802. if (LoadCommandBarList(pPX, &lstCommandBars))
  803. {
  804. RestoreCommandBarList(&lstCommandBars, pParam->bLoadSilent);
  805. CXTPMenuBar* pMenuBar = GetMenuBar();
  806. if (pMenuBar)
  807. {
  808. pMenuBar->SetupHook();
  809. pMenuBar->RefreshMenu();
  810. }
  811. }
  812. else
  813. {
  814. return;
  815. }
  816. }
  817. if (pParam->bSerializeLayout)
  818. {
  819. CXTPPropExchangeSection secLayout(pPX->GetSection(_T("Layout")));
  820. state.DoPropExchange(&secLayout);
  821. SerializeDockBarsState(&secLayout);
  822. SetDockState(state);
  823. }
  824. CXTPToolBar* pCommandBar = GetToolBar(0xFFEEFF);
  825. if (pCommandBar)
  826. {
  827. if (pParam->bSerializeDesignerControls)
  828. {
  829. if (m_pDesignerControls)
  830. m_pDesignerControls->InternalRelease();
  831. m_pDesignerControls = pCommandBar->GetControls();
  832. pCommandBar->m_pControls = NULL;
  833. Remove(pCommandBar);
  834. m_pDesignerControls->SetParent(NULL);
  835. m_pDesignerControls->Remove(m_pDesignerControls->FindControl(xtpControlError, XTP_ID_TOOLBAR_EXPAND, TRUE, FALSE));
  836. m_pDesignerControls->Remove(m_pDesignerControls->FindControl(xtpControlError, XTP_ID_TOOLBAR_HIDE, TRUE, FALSE));
  837. m_pDesignerControls->SetCommandBars(this);
  838. }
  839. else
  840. {
  841. Remove(pCommandBar);
  842. }
  843. }
  844. RecalcFrameLayout(TRUE);
  845. }
  846. if (pParam->bSerializeImages)
  847. {
  848. CXTPPropExchangeSection secImages(pPX->GetSection(_T("Images")));
  849. GetImageManager()->DoPropExchange(&secImages);
  850. }
  851. if (pParam->bSerializeOptions)
  852. {
  853. CXTPPropExchangeSection secShortcuts(pPX->GetSection(_T("Shortcuts")));
  854. m_pShortcutManager->DoPropExchange(&secShortcuts);
  855. CXTPPropExchangeSection secOptions(pPX->GetSection(_T("Options")));
  856. XTPPaintTheme theme = GetPaintManager()->BaseTheme();
  857. PX_Enum(&secOptions, _T("Theme"), theme, xtpThemeOffice2000);
  858. if (pPX->IsLoading()) SetPaintManager(CXTPPaintManager::CreateTheme(theme));
  859. m_pOptions->DoPropExchange(&secOptions);
  860. PX_Bool(&secOptions, _T("Customizable"), m_bCustomizeAvail, TRUE);
  861. }
  862. if (pParam->bSerializeDesignerControls && pPX->IsLoading())
  863. {
  864. m_pShortcutManager->CreateOriginalAccelTable();
  865. if (m_bCustomizeAvail)
  866. {
  867. for (int i = 0; i < GetCount(); i++)
  868. {
  869. CXTPToolBar* pToolBar = GetAt(i);
  870. pToolBar->GetControls()->CreateOriginalControls();
  871. }
  872. }
  873. }
  874. m_pOptions->bDirtyState = FALSE;
  875. }
  876. void CXTPCommandBars::SerializeBarState(CArchive& ar, BOOL bSerializeControls, BOOL bOnlyCustomized, BOOL bSilent)
  877. {
  878. CXTPPropExchangeArchive px(ar);
  879. XTP_COMMANDBARS_PROPEXCHANGE_PARAM paramT;
  880. paramT.bSaveOnlyCustomized = bOnlyCustomized;
  881. paramT.bSerializeControls = bSerializeControls;
  882. paramT.bLoadSilent = bSilent;
  883. DoPropExchange(&px, &paramT);
  884. }
  885. void CXTPCommandBars::SerializeDockBarsState(CXTPPropExchange* pPX)
  886. {
  887. CXTPPropExchangeSection secDockBars(pPX->GetSection(_T("DockBars")));
  888. for (int nIndex = 0; nIndex < 4; nIndex++)
  889. {
  890. CXTPDockBar* pDock = m_pDocks[nIndex];
  891. CString strSection;
  892. strSection.Format(_T("DockBar%i"), nIndex);
  893. CXTPPropExchangeSection secDockBar(secDockBars->GetSection(strSection));
  894. if (pPX->IsStoring())
  895. {
  896. int nSize = (int)pDock->m_arrBars.GetSize();
  897. DWORD nCount = 0;
  898. DWORD dwIDPrev = (DWORD)-1;
  899. int i;
  900. for (i = 0; i < nSize; i++)
  901. {
  902. CXTPToolBar* pBar = (CXTPToolBar*)pDock->m_arrBars[i];
  903. DWORD dwID = pBar ? pBar->m_nBarID : 0;
  904. if (dwIDPrev == 0 && dwID == 0) continue;
  905. dwIDPrev = dwID;
  906. nCount++;
  907. }
  908. if (nCount > 1)
  909. {
  910. PX_DWord(&secDockBar, _T("Count"), nCount, 0);
  911. int j = 0;
  912. dwIDPrev = (DWORD)-1;
  913. for (i = 0; i < nSize; i++)
  914. {
  915. CXTPToolBar* pBar = (CXTPToolBar*)pDock->m_arrBars[i];
  916. DWORD dwID = pBar ? pBar->m_nBarID : 0;
  917. if (dwIDPrev == 0 && dwID == 0)
  918. continue;
  919. dwIDPrev = dwID;
  920. CString strDockBarSection;
  921. strDockBarSection.Format(_T("Id%i"), j++);
  922. PX_DWord(&secDockBar, strDockBarSection, dwID, 0);
  923. }
  924. }
  925. else
  926. {
  927. nCount = 0;
  928. PX_DWord(&secDockBar, _T("Count"), nCount, 0);
  929. }
  930. }
  931. else
  932. {
  933. DWORD dwID = 0;
  934. DWORD nBars = 0;
  935. PX_DWord(&secDockBar, _T("Count"), nBars, 0);
  936. if (nBars > 1)
  937. {
  938. for (int i = 0; i < (int)nBars; i++)
  939. {
  940. CString strDockBarSection;
  941. strDockBarSection.Format(_T("Id%i"), i);
  942. PX_DWord(&secDockBar, strDockBarSection, dwID, 0);
  943. CXTPToolBar* pBar = GetToolBar(dwID);
  944. if (pBar)
  945. {
  946. if (pBar->m_hWnd && pBar->GetParent() != pDock)
  947. pBar->SetParent(pDock);
  948. if (pBar->m_pDockBar != NULL)
  949. pBar->m_pDockBar->RemoveCommandBar(pBar);
  950. pBar->m_pDockBar = pDock;
  951. pBar->m_barPosition = pDock->GetPosition();
  952. }
  953. pDock->m_arrBars.InsertAt(i, pBar);
  954. }
  955. }
  956. }
  957. }
  958. }
  959. void CXTPCommandBars::GetDockState(CXTPDockState& state)
  960. {
  961. state.Clear(); //make sure dockstate is empty
  962. // get state info for each bar
  963. for (int i = 0; i < GetCount(); i++)
  964. {
  965. CXTPToolBar* pBar = GetAt(i);
  966. ASSERT(pBar != NULL);
  967. if (!pBar)
  968. continue;
  969. CXTPToolBar::CToolBarInfo* pInfo = new CXTPToolBar::CToolBarInfo;
  970. pBar->GetBarInfo(pInfo);
  971. state.m_arrBarInfo.Add(pInfo);
  972. }
  973. }
  974. void CXTPCommandBars::SetDockState(CXTPDockState& state)
  975. {
  976. for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
  977. {
  978. CXTPToolBar::CToolBarInfo* pInfo = state.m_arrBarInfo[i];
  979. ASSERT(pInfo != NULL);
  980. if (!pInfo)
  981. continue;
  982. pInfo->m_pBar = GetToolBar(pInfo->m_nBarID);
  983. if (pInfo->m_pBar != NULL)
  984. {
  985. if (pInfo->m_bFloating)
  986. {
  987. FloatCommandBar(pInfo->m_pBar);
  988. }
  989. else
  990. {
  991. VERIFY(pInfo->m_pBar->Create(m_pFrame, FALSE));
  992. }
  993. pInfo->m_pBar->SetBarInfo(pInfo);
  994. }
  995. }
  996. }
  997. void CXTPCommandBars::GenerateCommandBarList(CXTPCommandBarList* pCommandBarList, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam)
  998. {
  999. DWORD nID = 0x1000000;
  1000. int i;
  1001. for (i = 0; i < GetCount(); i++)
  1002. {
  1003. CXTPToolBar* pBar = GetAt(i);
  1004. if (pBar->IsTemporary())
  1005. continue;
  1006. if (pParam->bSaveOnlyCustomized && pBar->IsBuiltIn())
  1007. {
  1008. if (!pBar->ShouldSerializeBar())
  1009. continue;
  1010. }
  1011. pBar->GenerateCommandBarList(nID, pCommandBarList, pParam);
  1012. }
  1013. for (i = 0; i < m_pContextMenus->GetCount(); i++)
  1014. {
  1015. CXTPCommandBar* pBar = m_pContextMenus->GetAt(i);
  1016. if (pParam->bSaveOnlyCustomized)
  1017. {
  1018. if (!pBar->GetControls()->IsChanged())
  1019. continue;
  1020. }
  1021. pBar->GenerateCommandBarList(nID, pCommandBarList, pParam);
  1022. }
  1023. }
  1024. void CXTPCommandBar::GenerateCommandBarList(DWORD& nID, CXTPCommandBarList* pCommandBarList, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam)
  1025. {
  1026. if (!pCommandBarList->Lookup(this))
  1027. {
  1028. pCommandBarList->Add(this);
  1029. InternalAddRef();
  1030. if (!IsKindOf(RUNTIME_CLASS(CXTPToolBar)))
  1031. {
  1032. if (m_nBarID == 0 || m_nBarID >= 0x1000000)
  1033. m_nBarID = nID++;
  1034. }
  1035. else ASSERT(m_nBarID != 0);
  1036. m_pControls->GenerateCommandBarList(nID, pCommandBarList, pParam);
  1037. }
  1038. }
  1039. void CXTPMenuBar::GenerateCommandBarList(DWORD& nID, CXTPCommandBarList* pCommandBarList, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam)
  1040. {
  1041. if (!pCommandBarList->Lookup(this))
  1042. {
  1043. CXTPToolBar::GenerateCommandBarList(nID, pCommandBarList, pParam);
  1044. POSITION pos = m_pMDIMenus->GetStartPosition();
  1045. while (pos)
  1046. {
  1047. CXTPMenuBarMDIMenuInfo* pInfo;
  1048. m_pMDIMenus->GetNextMenu(pos, pInfo);
  1049. pInfo->m_pControls->GenerateCommandBarList(nID, pCommandBarList, pParam);
  1050. }
  1051. }
  1052. }
  1053. void CXTPControl::GenerateCommandBarList(DWORD& nID, CXTPCommandBarList* pCommandBarList, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam)
  1054. {
  1055. CXTPCommandBar* pCommandBar = GetCommandBar();
  1056. if (pCommandBar)
  1057. {
  1058. pCommandBar->GenerateCommandBarList(nID, pCommandBarList, pParam);
  1059. }
  1060. }
  1061. void CXTPControls::GenerateCommandBarList(DWORD& nID, CXTPCommandBarList* pCommandBarList, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam)
  1062. {
  1063. for (int i = 0; i < GetCount(); i++)
  1064. {
  1065. CXTPControl* pControl = GetAt(i);
  1066. if (pControl && !pControl->m_bTemporary)
  1067. {
  1068. pControl->GenerateCommandBarList(nID, pCommandBarList, pParam);
  1069. }
  1070. }
  1071. if (m_pOriginalControls && pParam->bSaveOriginalControls)
  1072. m_pOriginalControls->GenerateCommandBarList(nID, pCommandBarList, pParam);
  1073. }
  1074. BOOL CXTPCommandBars::SaveCommandBarList(CXTPPropExchange* pPX, CXTPCommandBarList* pCommandBarList)
  1075. {
  1076. try
  1077. {
  1078. CXTPPropExchangeSection secCommandBars(pPX->GetSection(_T("CommandBars")));
  1079. long nCount = (long)pCommandBarList->GetCount();
  1080. CXTPPropExchangeEnumeratorPtr pEnumerator(secCommandBars->GetEnumerator(_T("CommandBar")));
  1081. POSITION posEnum = pEnumerator->GetPosition(nCount, FALSE);
  1082. for (int i = 0; i < nCount; i++)
  1083. {
  1084. CXTPCommandBar* pCommandBar = pCommandBarList->GetAt(i);
  1085. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  1086. PX_Object(&secItem, pCommandBar, RUNTIME_CLASS(CXTPCommandBar));
  1087. }
  1088. }
  1089. catch (COleException* pEx)
  1090. {
  1091. TRACE(_T("CXTPCommandBars::SaveCommandBarList. OLE exception: %xrn"),
  1092. pEx->m_sc);
  1093. pEx->Delete ();
  1094. return FALSE;
  1095. }
  1096. catch (CArchiveException* pEx)
  1097. {
  1098. TRACE(_T("CXTPCommandBars::SaveCommandBarList. Archive exceptionrn"));
  1099. pEx->Delete ();
  1100. return FALSE;
  1101. }
  1102. return TRUE;
  1103. }
  1104. BOOL CXTPCommandBars::LoadCommandBarList(CXTPPropExchange* pPX, CXTPCommandBarList* pCommandBarList)
  1105. {
  1106. try
  1107. {
  1108. CXTPPropExchangeSection secCommandBars(pPX->GetSection(_T("CommandBars")));
  1109. CXTPPropExchangeEnumeratorPtr pEnumerator(secCommandBars->GetEnumerator(_T("CommandBar")));
  1110. POSITION posEnum = pEnumerator->GetPosition(0, FALSE);
  1111. while (posEnum)
  1112. {
  1113. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  1114. CXTPCommandBar* pCommandBar = NULL;
  1115. PX_Object(&secItem, pCommandBar, RUNTIME_CLASS(CXTPCommandBar));
  1116. if (!pCommandBar)
  1117. {
  1118. return FALSE;
  1119. }
  1120. pCommandBar->GetControls()->RefreshIndexes();
  1121. pCommandBarList->Add(pCommandBar);
  1122. }
  1123. }
  1124. catch (COleException* pEx)
  1125. {
  1126. TRACE(_T("CXTPCommandBars::LoadCommandBarList. OLE exception: %xrn"),
  1127. pEx->m_sc);
  1128. pEx->Delete ();
  1129. return FALSE;
  1130. }
  1131. catch (CArchiveException* pEx)
  1132. {
  1133. TRACE(_T("CXTPCommandBars::LoadCommandBarList. Archive exceptionrn"));
  1134. pEx->Delete ();
  1135. return FALSE;
  1136. }
  1137. return TRUE;
  1138. }
  1139. void CXTPToolBar::MergeToolBar(CXTPCommandBar* pCommandBar, BOOL bSilent)
  1140. {
  1141. CXTPControls* pLastControls = pCommandBar->GetControls()->GetOriginalControls();
  1142. if (pLastControls && GetControls()->GetOriginalControls()
  1143. && GetControls()->GetOriginalControls()->Compare(pLastControls) == FALSE)
  1144. {
  1145. //silent restore if not customized
  1146. if (!bSilent && pLastControls->Compare(pCommandBar->GetControls()) == FALSE)
  1147. {
  1148. CString strMessage, strUpdate;
  1149. VERIFY(XTPResourceManager()->LoadString(&strUpdate, XTP_IDS_CONFIRM_UPDATE));
  1150. strMessage.Format(strUpdate, (LPCTSTR)m_strTitle);
  1151. if (XTPResourceManager()->ShowMessageBox(strMessage, MB_YESNO | MB_ICONQUESTION) == IDNO)
  1152. {
  1153. CXTPOriginalControls* pControls = GetControls()->GetOriginalControls();
  1154. CMDTARGET_ADDREF(pControls);
  1155. Copy(pCommandBar, FALSE);
  1156. m_pControls->SetOriginalControls(pControls);
  1157. }
  1158. }
  1159. }
  1160. else
  1161. {
  1162. CXTPOriginalControls* pOriginalControls = pCommandBar->m_pControls->m_pOriginalControls ? NULL :
  1163. m_pControls->m_pOriginalControls;
  1164. CMDTARGET_ADDREF(pOriginalControls);
  1165. Copy(pCommandBar, FALSE);
  1166. if (pOriginalControls)
  1167. {
  1168. ASSERT(m_pControls->m_pOriginalControls == NULL);
  1169. m_pControls->SetOriginalControls(pOriginalControls);
  1170. }
  1171. }
  1172. }
  1173. void CXTPCommandBars::RestoreCommandBarList(CXTPCommandBarList* pCommandBarList, BOOL bSilent)
  1174. {
  1175. for (int i = 0; i < pCommandBarList->GetCount(); i++)
  1176. {
  1177. CXTPCommandBar* pCommandBar = pCommandBarList->GetAt(i);
  1178. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, pCommandBar);
  1179. if (pToolBar)
  1180. {
  1181. CXTPToolBar* pExistsBar = GetToolBar(pToolBar->GetBarID());
  1182. pCommandBar->RestoreCommandBarList(pCommandBarList);
  1183. if (pExistsBar)
  1184. {
  1185. pExistsBar->MergeToolBar(pCommandBar, bSilent);
  1186. }
  1187. else
  1188. {
  1189. m_arrBars.Add(pToolBar);
  1190. pToolBar->InternalAddRef();
  1191. pToolBar->Create(m_pFrame, FALSE);
  1192. pToolBar->EnableDocking(pToolBar->m_dwFlags);
  1193. OnToolBarAdded(pToolBar);
  1194. }
  1195. }
  1196. else if (pCommandBar->IsPopupBar() && ((CXTPPopupBar*)pCommandBar)->IsContextMenu())
  1197. {
  1198. CXTPCommandBar* pExistsBar = m_pContextMenus->FindCommandBar(pCommandBar->GetBarID());
  1199. pCommandBar->RestoreCommandBarList(pCommandBarList);
  1200. if (pExistsBar)
  1201. {
  1202. CXTPControls* pControls = pCommandBar->GetControls();
  1203. CMDTARGET_ADDREF(pControls)
  1204. CXTPOriginalControls* pOriginalControls = pExistsBar->GetControls()->GetOriginalControls();
  1205. CMDTARGET_ADDREF(pOriginalControls);
  1206. pExistsBar->SetControls(pControls);
  1207. pCommandBar->SetControls(NULL);
  1208. if (pOriginalControls)
  1209. {
  1210. pExistsBar->GetControls()->SetOriginalControls(pOriginalControls);
  1211. }
  1212. }
  1213. else
  1214. {
  1215. m_pContextMenus->Add(pCommandBar);
  1216. pCommandBar->InternalAddRef();
  1217. if (pCommandBar->GetControls()->GetOriginalControls() == NULL)
  1218. pCommandBar->GetControls()->CreateOriginalControls();
  1219. }
  1220. }
  1221. }
  1222. }
  1223. void CXTPCommandBar::RestoreCommandBarList(CXTPCommandBarList* pCommandBarList)
  1224. {
  1225. m_pControls->RestoreCommandBarList(pCommandBarList);
  1226. }
  1227. void CXTPMenuBar::RestoreCommandBarList(CXTPCommandBarList* pCommandBarList)
  1228. {
  1229. CXTPToolBar::RestoreCommandBarList(pCommandBarList);
  1230. POSITION pos = m_pMDIMenus->GetStartPosition();
  1231. while (pos)
  1232. {
  1233. CXTPMenuBarMDIMenuInfo* pInfo;
  1234. m_pMDIMenus->GetNextMenu(pos, pInfo);
  1235. pInfo->m_pControls->RestoreCommandBarList(pCommandBarList);
  1236. }
  1237. }
  1238. void CXTPControl::RestoreCommandBarList(CXTPCommandBarList* /*pCommandBarList*/)
  1239. {
  1240. }
  1241. void CXTPControlPopup::RestoreCommandBarList(CXTPCommandBarList* pCommandBarList)
  1242. {
  1243. if (m_dwCommandBarID != 0)
  1244. {
  1245. CXTPCommandBar* pCommandBar = pCommandBarList->FindCommandBar(m_dwCommandBarID);
  1246. ASSERT(pCommandBar);
  1247. if (pCommandBar)
  1248. {
  1249. SetCommandBar(pCommandBar);
  1250. m_dwCommandBarID = 0;
  1251. pCommandBar->RestoreCommandBarList(pCommandBarList);
  1252. }
  1253. }
  1254. }
  1255. void CXTPControls::RestoreCommandBarList(CXTPCommandBarList* pCommandBarList)
  1256. {
  1257. for (int i = 0; i < GetCount(); i++)
  1258. {
  1259. CXTPControl* pControl = GetAt(i);
  1260. pControl->RestoreCommandBarList(pCommandBarList);
  1261. }
  1262. if (m_pOriginalControls)
  1263. m_pOriginalControls->RestoreCommandBarList(pCommandBarList);
  1264. }
  1265. void CXTPCommandBar::DoPropExchange(CXTPPropExchange* pPX)
  1266. {
  1267. PX_Enum(pPX, _T("Type"), m_barType, xtpBarTypeNormal);
  1268. PX_Enum(pPX, _T("Position"), m_barPosition, xtpBarTop);
  1269. PX_Long(pPX, _T("BarID"), (long&)m_nBarID, 0);
  1270. PX_Long(pPX, _T("Flags"), (long&)m_dwFlags, 0);
  1271. PX_Long(pPX, _T("Style"), (long&)m_dwStyle, 0);
  1272. PX_String(pPX, _T("Title"), m_strTitle, _T(""));
  1273. PX_Bool(pPX, _T("Customizable"), m_bCustomizable, TRUE);
  1274. PX_Int(pPX, _T("MRUWidth"), m_nMRUWidth, 0);
  1275. if (pPX->GetSchema() > _XTP_SCHEMA_80)
  1276. PX_Size(pPX, _T("IconSize"), m_szIcons, CSize(0, 0));
  1277. if (pPX->IsLoading())
  1278. {
  1279. ASSERT(pPX->m_dwData != 0);
  1280. if (pPX->m_dwData) SetCommandBars(((XTP_COMMANDBARS_PROPEXCHANGE_PARAM*)pPX->m_dwData)->pCommandBars);
  1281. }
  1282. if (pPX->GetSchema() > _XTP_SCHEMA_100)
  1283. {
  1284. PX_Size(pPX, _T("ButtonSize"), m_szButtons, CSize(0, 0));
  1285. PX_Bool(pPX, _T("ShowTextBelowIcons"), m_bTextBelow, XTP_BOOL_DEFAULT);
  1286. BOOL bAnimation = IsAnimationEnabled();
  1287. PX_Bool(pPX, _T("EnableAnimation"), bAnimation, FALSE);
  1288. if (pPX->IsLoading())
  1289. {
  1290. EnableAnimation(bAnimation);
  1291. }
  1292. }
  1293. if (pPX->GetSchema() > _XTP_SCHEMA_103)
  1294. {
  1295. PX_Enum(pPX, _T("DefaultButtonStyle"), m_buttonStyle, xtpButtonAutomatic);
  1296. }
  1297. CXTPPropExchangeSection secControls(pPX->GetSection(_T("Controls")));
  1298. m_pControls->DoPropExchange(&secControls);
  1299. }
  1300. void CXTPToolBar::DoPropExchange(CXTPPropExchange* pPX)
  1301. {
  1302. CXTPCommandBar::DoPropExchange(pPX);
  1303. PX_Bool(pPX, _T("BuiltIn"), m_bBuiltIn, TRUE);
  1304. PX_Bool(pPX, _T("TearOff"), m_bTearOff, FALSE);
  1305. if (pPX->GetSchema() > _XTP_SCHEMA_87)
  1306. PX_Bool(pPX, _T("Closeable"), m_bCloseable, TRUE);
  1307. if (pPX->GetSchema() > _XTP_SCHEMA_875)
  1308. PX_Bool(pPX, _T("ContextMenuPresent"), m_bContextMenuPresent, TRUE);
  1309. if (pPX->GetSchema() > _XTP_SCHEMA_98)
  1310. PX_Bool(pPX, _T("CustomizeDialogPresent"), m_bCustomizeDialogPresent, TRUE);
  1311. if (pPX->GetSchema() <= _XTP_SCHEMA_98 && pPX->IsLoading() && m_barType == xtpBarTypeMenuBar)
  1312. {
  1313. m_bCloseable = FALSE;
  1314. }
  1315. }
  1316. void CXTPMenuBar::DoPropExchange(CXTPPropExchange* pPX)
  1317. {
  1318. if (pPX->IsStoring())
  1319. {
  1320. if (m_pMDIMenus->GetCount() > 0)
  1321. {
  1322. SwitchMDIMenu(GetDefaultMenuResource());
  1323. m_bDirtyMenu = TRUE;
  1324. }
  1325. }
  1326. CXTPToolBar::DoPropExchange(pPX);
  1327. PX_Long(pPX, _T("ResourceId"), (long&)m_nIDResource, 0);
  1328. if (pPX->IsStoring())
  1329. {
  1330. //_XTP_SCHEMA_861
  1331. DWORD dwCount = 0;
  1332. POSITION pos = m_pMDIMenus->GetStartPosition();
  1333. while (pos)
  1334. {
  1335. CXTPMenuBarMDIMenuInfo* pInfo;
  1336. m_pMDIMenus->GetNextMenu(pos, pInfo);
  1337. if (pInfo->m_bChanged)
  1338. dwCount++;
  1339. }
  1340. int i = 0;
  1341. pPX->WriteCount(dwCount);
  1342. pos = m_pMDIMenus->GetStartPosition();
  1343. while (pos)
  1344. {
  1345. CXTPMenuBarMDIMenuInfo* pInfo;
  1346. m_pMDIMenus->GetNextMenu(pos, pInfo);
  1347. if (!pInfo->m_bChanged)
  1348. continue;
  1349. long nIDCommand = (long)pInfo->m_nIDResource;
  1350. CString strSection;
  1351. strSection.Format(_T("%s%i"), _T("MDIMenu"), i++);
  1352. CXTPPropExchangeSection sec(pPX->GetSection(strSection));
  1353. PX_Long(&sec, _T("Id"), nIDCommand, 0);
  1354. pInfo->m_pControls->DoPropExchange(&sec);
  1355. }
  1356. }
  1357. else
  1358. {
  1359. if (pPX->GetSchema() > _XTP_SCHEMA_86)
  1360. {
  1361. DWORD nCount = (DWORD)pPX->ReadCount();
  1362. for (DWORD i = 0; i < nCount; i++)
  1363. {
  1364. UINT nIDCommand = 0;
  1365. CString strSection;
  1366. strSection.Format(_T("%s%i"), _T("MDIMenu"), i);
  1367. CXTPPropExchangeSection sec(pPX->GetSection(strSection));
  1368. PX_Long(&sec, _T("Id"), (long&)nIDCommand, 0);
  1369. CXTPMenuBarMDIMenuInfo* pInfo = NULL;
  1370. if (!m_pMDIMenus->Lookup(nIDCommand))
  1371. {
  1372. pInfo = new CXTPMenuBarMDIMenuInfo(GetCommandBars(), nIDCommand);
  1373. m_pMDIMenus->SetAt(nIDCommand, pInfo);
  1374. }
  1375. if (pInfo) pInfo->m_pControls->DoPropExchange(&sec);
  1376. }
  1377. }
  1378. }
  1379. }
  1380. void CXTPPopupBar::DoPropExchange(CXTPPropExchange* pPX)
  1381. {
  1382. CXTPCommandBar::DoPropExchange(pPX);
  1383. PX_Bool(pPX, _T("TearOffPopup"), m_bTearOffPopup, FALSE);
  1384. PX_String(pPX, _T("TearOffCaption"), m_strTearOffCaption, _T(""));
  1385. PX_Long(pPX, _T("TearOffId"), (long&)m_nTearOffID, 0);
  1386. PX_Int(pPX, _T("TearOffWidth"), m_nTearOffWidth, 0);
  1387. if (pPX->GetSchema() > _XTP_SCHEMA_85)
  1388. {
  1389. PX_Rect(pPX, _T("Borders"), m_rcBorders, CRect(2, 4, 2, 4));
  1390. PX_Bool(pPX, _T("ShowShadow"), m_bShowShadow, TRUE);
  1391. }
  1392. if (pPX->GetSchema() > _XTP_SCHEMA_95)
  1393. {
  1394. PX_Bool(pPX, _T("DoubleGripper"), m_bDoubleGripper, FALSE);
  1395. }
  1396. if (pPX->GetSchema() < _XTP_SCHEMA_104)
  1397. {
  1398. SetShowGripper(TRUE);
  1399. }
  1400. if (pPX->GetSchema() > _XTP_SCHEMA_103)
  1401. {
  1402. PX_Bool(pPX, _T("ContextMenu"), m_bContextMenu, FALSE);
  1403. }
  1404. }
  1405. BOOL CXTPControls::ShouldSerializeControl(CXTPControl* pControl)
  1406. {
  1407. return !pControl->m_bTemporary;
  1408. }
  1409. void CXTPControls::DoPropExchange(CXTPPropExchange* pPX)
  1410. {
  1411. ASSERT(pPX->m_dwData != 0);
  1412. XTP_COMMANDBARS_PROPEXCHANGE_PARAM* pParam = (XTP_COMMANDBARS_PROPEXCHANGE_PARAM*)pPX->m_dwData;
  1413. if (pPX->IsStoring())
  1414. {
  1415. long nCount = 0;
  1416. int i;
  1417. for (i = 0; i < m_arrControls.GetSize(); i++)
  1418. {
  1419. CXTPControl* pControl = GetAt(i);
  1420. if (ShouldSerializeControl(pControl)) nCount++;
  1421. }
  1422. CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Control")));
  1423. POSITION posEnum = pEnumerator->GetPosition(nCount, FALSE);
  1424. for (i = 0; i < (int)m_arrControls.GetSize(); i++)
  1425. {
  1426. CXTPControl* pControl = GetAt(i);
  1427. if (ShouldSerializeControl(pControl))
  1428. {
  1429. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  1430. PX_Object(&secItem, pControl, RUNTIME_CLASS(CXTPControl));
  1431. }
  1432. }
  1433. BOOL bOriginalControls = pParam && m_pOriginalControls && pParam->bSaveOriginalControls ? TRUE : FALSE;
  1434. PX_Bool(pPX, _T("OriginalControls"), bOriginalControls, FALSE);
  1435. if (bOriginalControls && m_pOriginalControls)
  1436. {
  1437. CXTPPropExchangeSection secControls(pPX->GetSection(_T("OriginalControls")));
  1438. m_pOriginalControls->DoPropExchange(&secControls);
  1439. }
  1440. BOOL bCustomizedControls = FALSE;
  1441. PX_Bool(pPX, _T("CustomizedControls"), bCustomizedControls, FALSE);
  1442. }
  1443. else
  1444. {
  1445. CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Control")));
  1446. POSITION posEnum = pEnumerator->GetPosition(0, FALSE);
  1447. RemoveAll();
  1448. while (posEnum)
  1449. {
  1450. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  1451. CXTPControl* pControl = NULL;
  1452. PX_Object(&secItem, pControl, RUNTIME_CLASS(CXTPControl));
  1453. if (!pControl)
  1454. AfxThrowArchiveException(CArchiveException::badClass);
  1455. m_arrControls.Add(pControl);
  1456. OnControlAdded(pControl);
  1457. }
  1458. RefreshIndexes();
  1459. if (pPX->GetSchema() > _XTP_SCHEMA_80)
  1460. {
  1461. BOOL bOriginalControls = FALSE;
  1462. PX_Bool(pPX, _T("OriginalControls"), bOriginalControls, FALSE);
  1463. if (bOriginalControls)
  1464. {
  1465. CXTPOriginalControls* pOriginalControls = new CXTPOriginalControls();
  1466. SetOriginalControls(pOriginalControls);
  1467. CXTPPropExchangeSection secControls(pPX->GetSection(_T("OriginalControls")));
  1468. pOriginalControls->DoPropExchange(&secControls);
  1469. }
  1470. BOOL bCustomizedControls = FALSE;
  1471. PX_Bool(pPX, _T("CustomizedControls"), bCustomizedControls, FALSE);
  1472. if (bCustomizedControls)
  1473. {
  1474. // _XTP_SCHEMA_80 compatibility.
  1475. CXTPControls* pCustomizedControls = new CXTPControls;
  1476. CXTPPropExchangeSection secControls(pPX->GetSection(_T("CustomizedControls")));
  1477. pCustomizedControls->DoPropExchange(&secControls);
  1478. pCustomizedControls->InternalRelease();
  1479. }
  1480. }
  1481. }
  1482. }
  1483. void CXTPControlActions::DoPropExchange(CXTPPropExchange* pPX)
  1484. {
  1485. if (pPX->IsStoring())
  1486. {
  1487. long nCount = GetCount();
  1488. CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Action")));
  1489. POSITION posEnum = pEnumerator->GetPosition(nCount, FALSE);
  1490. for (int i = 0; i < nCount; i++)
  1491. {
  1492. CXTPControlAction* pAction = GetAt(i);
  1493. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  1494. int nId = pAction->GetID();
  1495. PX_Int(&secItem, _T("Id"), nId);
  1496. pAction->DoPropExchange(&secItem);
  1497. }
  1498. }
  1499. else
  1500. {
  1501. CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Action")));
  1502. POSITION posEnum = pEnumerator->GetPosition(0, FALSE);
  1503. while (posEnum)
  1504. {
  1505. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  1506. int nId = 0;
  1507. PX_Int(&secItem, _T("Id"), nId);
  1508. CXTPControlAction* pAction = FindAction(nId);
  1509. if (!pAction)
  1510. {
  1511. pAction = new CXTPControlAction(this);
  1512. pAction->m_nId = nId;
  1513. Insert(pAction);
  1514. }
  1515. pAction->DoPropExchange(&secItem);
  1516. }
  1517. }
  1518. }
  1519. void CXTPControlAction::DoPropExchange(CXTPPropExchange* pPX)
  1520. {
  1521. PX_Int(pPX, _T("IconId"), m_nIconId, 0);
  1522. PX_Int(pPX, _T("HelpId"), m_nHelpId, 0);
  1523. PX_String(pPX, _T("Caption"), m_strCaption, _T(""));
  1524. PX_String(pPX, _T("ShortcutText"), m_strShortcutText, _T(""));
  1525. PX_String(pPX, _T("TooltipText"), m_strTooltipText, _T(""));
  1526. PX_String(pPX, _T("DescriptionText"), m_strDescriptionText, _T(""));
  1527. PX_String(pPX, _T("Category"), m_strCategory, _T(""));
  1528. if (pPX->GetSchema() > _XTP_SCHEMA_1122)
  1529. {
  1530. PX_String(pPX, _T("Key"), m_strKey, _T(""));
  1531. }
  1532. }
  1533. void CXTPControl::DoPropExchange(CXTPPropExchange* pPX)
  1534. {
  1535. ASSERT(sizeof(long) == sizeof(DWORD));
  1536. CXTPCommandBars* pCommandBars = ((XTP_COMMANDBARS_PROPEXCHANGE_PARAM*)pPX->m_dwData)->pCommandBars;
  1537. PX_Enum(pPX, _T("Type"), m_controlType, xtpControlButton);
  1538. PX_Int(pPX, _T("Id"), m_nId, -1);
  1539. if (pPX->IsLoading())
  1540. {
  1541. CXTPControlAction* pAction = pCommandBars->GetActions()->FindAction(m_nId);
  1542. if (pAction)
  1543. {
  1544. SetAction(pAction);
  1545. }
  1546. }
  1547. PX_Int(pPX, _T("IconId"), m_nIconId, 0);
  1548. PX_Bool(pPX, _T("BeginGroup"), m_bBeginGroup, FALSE);
  1549. PX_Long(pPX, _T("Tag"), (long&)m_nTag, 0);
  1550. PX_Long(pPX, _T("Flags"), (long&)m_dwFlags, 0);
  1551. PX_Long(pPX, _T("HideFlags"), (long&)m_dwHideFlags, 0);
  1552. PX_String(pPX, _T("Caption"), m_strCaption, _T(""));
  1553. PX_String(pPX, _T("ShortcutText"), m_strShortcutText, _T(""));
  1554. PX_String(pPX, _T("TooltipText"), m_strTooltipText, _T(""));
  1555. PX_String(pPX, _T("DescriptionText"), m_strDescriptionText, _T(""));
  1556. PX_String(pPX, _T("Parameter"), m_strParameter, _T(""));
  1557. PX_Int(pPX, _T("CustomIconId"), m_nCustomIconId, 0);
  1558. PX_String(pPX, _T("CustomCaption"), m_strCustomCaption, _T(""));
  1559. if (pPX->GetSchema() > _XTP_SCHEMA_71)
  1560. PX_String(pPX, _T("Category"), m_strCategory, _T(""));
  1561. if (m_nCustomIconId > 0)
  1562. {
  1563. ASSERT(pCommandBars->IsKindOf(RUNTIME_CLASS(CXTPCommandBars)));
  1564. CXTPPropExchangeSection secCustomIcon(pPX->GetSection(_T("CustomIcon")));
  1565. pCommandBars->GetImageManager()->DoPropExchange(m_nCustomIconId, &secCustomIcon);
  1566. }
  1567. if (pPX->GetSchema() > _XTP_SCHEMA_85)
  1568. {
  1569. if (!(pPX->IsStoring() && pPX->IsAllowDefaultValues() && m_mapDocTemplatesExcluded.IsEmpty()))
  1570. PX_Serialize(pPX, _T("DocTemplatesExcluded"), &m_mapDocTemplatesExcluded);
  1571. if (!(pPX->IsStoring() && pPX->IsAllowDefaultValues() && m_mapDocTemplatesAssigned.IsEmpty()))
  1572. PX_Serialize(pPX, _T("DocTemplatesAssigned"), &m_mapDocTemplatesAssigned);
  1573. PX_Bool(pPX, _T("DefaultItem"), m_bDefaultItem, FALSE);
  1574. }
  1575. if (pPX->GetSchema() > _XTP_SCHEMA_87)
  1576. PX_Bool(pPX, _T("CloseSubMenuOnClick"), m_bCloseSubMenuOnClick, TRUE);
  1577. if (pPX->GetSchema() > _XTP_SCHEMA_875)
  1578. PX_Enum(pPX, _T("CustomStyle"), m_buttonCustomStyle, xtpButtonUndefined);
  1579. if (pPX->GetSchema() < _XTP_SCHEMA_103 && m_buttonCustomStyle == xtpButtonAutomatic)
  1580. m_buttonCustomStyle = xtpButtonUndefined;
  1581. if (pPX->GetSchema() > _XTP_SCHEMA_98)
  1582. PX_Int(pPX, _T("HelpId"), m_nHelpId, 0);
  1583. if (pPX->GetSchema() > _XTP_SCHEMA_100)
  1584. PX_Enum(pPX, _T("Style"), m_buttonStyle, xtpButtonAutomatic);
  1585. if (pPX->GetSchema() > _XTP_SCHEMA_103)
  1586. {
  1587. PX_Int(pPX, _T("Width"), m_nWidth, 0);
  1588. PX_Int(pPX, _T("Height"), m_nHeight, 0);
  1589. PX_Int(pPX, _T("ExecuteOnPressInterval"), m_nExecuteOnPressInterval, 0);
  1590. }
  1591. if (pPX->GetSchema() > _XTP_SCHEMA_1042)
  1592. {
  1593. PX_String(pPX, _T("ShortcutTextAuto"), m_strShortcutTextAuto, _T(""));
  1594. }
  1595. if (pPX->GetSchema() > _XTP_SCHEMA_110)
  1596. PX_String(pPX, _T("KeyboardTip"), m_strKeyboardTip, _T(""));
  1597. if (pPX->GetSchema() > _XTP_SCHEMA_1121)
  1598. PX_Size(pPX, _T("IconSize"), m_szIcon, CSize(0, 0));
  1599. if (pPX->IsLoading())
  1600. {
  1601. OnCaptionChanged();
  1602. }
  1603. }
  1604. void CXTPControlButton::DoPropExchange(CXTPPropExchange* pPX)
  1605. {
  1606. CXTPControl::DoPropExchange(pPX);
  1607. if (pPX->GetSchema() < _XTP_SCHEMA_103)
  1608. PX_Enum(pPX, _T("Style"), m_buttonStyle, xtpButtonAutomatic);
  1609. }
  1610. void CXTPControlPopup::DoPropExchange(CXTPPropExchange* pPX)
  1611. {
  1612. CXTPControl::DoPropExchange(pPX);
  1613. if (pPX->IsStoring())
  1614. {
  1615. long dwCommandBarID = m_pCommandBar ? m_pCommandBar->m_nBarID : 0;
  1616. PX_Long(pPX, _T("CommandBarId"), dwCommandBarID, 0);
  1617. }
  1618. else
  1619. {
  1620. PX_Long(pPX, _T("CommandBarId"), (long&)m_dwCommandBarID, 0);
  1621. }
  1622. if (pPX->GetSchema() > _XTP_SCHEMA_86 && pPX->GetSchema() < _XTP_SCHEMA_103)
  1623. PX_Enum(pPX, _T("Style"), m_buttonStyle, xtpButtonAutomatic);
  1624. }
  1625. void CXTPControlComboBox::DoPropExchange(CXTPPropExchange* pPX)
  1626. {
  1627. CXTPControlPopup::DoPropExchange(pPX);
  1628. PX_Bool(pPX, _T("DropDown"), m_bDropDown, TRUE);
  1629. PX_Int(pPX, _T("Width"), m_nWidth, 0);
  1630. PX_Enum(pPX, _T("ComboStyle"), m_comboStyle, xtpComboNormal);
  1631. if (pPX->GetSchema() > _XTP_SCHEMA_95)
  1632. {
  1633. PX_String(pPX, _T("EditHint"), m_strEditHint, _T(""));
  1634. PX_DWord(pPX, _T("ShellAutoCompleteFlags"), m_dwShellAutoCompleteFlags, 0);
  1635. PX_Bool(pPX, _T("AutoComplete"), m_bAutoComplete, FALSE);
  1636. PX_Int(pPX, _T("EditIconId"), m_nEditIconId, 0);
  1637. PX_Int(pPX, _T("DropDownItemCount"), m_nDropDownItemCount, 12);
  1638. }
  1639. if (pPX->GetSchema() > _XTP_SCHEMA_98)
  1640. {
  1641. PX_DWord(pPX, _T("EditStyle"), m_dwEditStyle, 0);
  1642. }
  1643. if (pPX->IsLoading())
  1644. {
  1645. SetDropDownListStyle(m_bDropDown);
  1646. EnableShellAutoComplete(m_dwShellAutoCompleteFlags);
  1647. }
  1648. }
  1649. void CXTPControlEdit::DoPropExchange(CXTPPropExchange* pPX)
  1650. {
  1651. CXTPControl::DoPropExchange(pPX);
  1652. if (pPX->GetSchema() > _XTP_SCHEMA_861)
  1653. {
  1654. PX_Bool(pPX, _T("HasLabel"), m_bLabel, FALSE);
  1655. PX_Int(pPX, _T("Width"), m_nWidth, 0);
  1656. }
  1657. if (pPX->GetSchema() > _XTP_SCHEMA_875)
  1658. {
  1659. PX_Bool(pPX, _T("ReadOnly"), m_bReadOnly, FALSE);
  1660. }
  1661. if (pPX->GetSchema() > _XTP_SCHEMA_95)
  1662. {
  1663. PX_String(pPX, _T("EditHint"), m_strEditHint, _T(""));
  1664. PX_DWord(pPX, _T("ShellAutoCompleteFlags"), m_dwShellAutoCompleteFlags, 0);
  1665. }
  1666. if (pPX->GetSchema() > _XTP_SCHEMA_98)
  1667. {
  1668. PX_DWord(pPX, _T("EditStyle"), m_dwEditStyle, 0);
  1669. }
  1670. if (pPX->GetSchema() > _XTP_SCHEMA_103)
  1671. {
  1672. PX_Bool(pPX, _T("ShowSpinButtons"), m_bShowSpinButtons, FALSE);
  1673. }
  1674. if (pPX->IsLoading())
  1675. {
  1676. EnableShellAutoComplete(m_dwShellAutoCompleteFlags);
  1677. }
  1678. }