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

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO 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 "MultiLanguage.h"
  22. #include "MainFrm.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. #define ID_LANGAUGE_FILE 1001
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame
  31. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  32. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  33. //{{AFX_MSG_MAP(CMainFrame)
  34. ON_WM_CREATE()
  35. ON_WM_CLOSE()
  36. //}}AFX_MSG_MAP
  37. ON_COMMAND_EX_RANGE(XTP_IDC_LANG_ARABIC, XTP_IDC_LANG_UKRAINIAN, OnLangaugeFile)
  38. ON_UPDATE_COMMAND_UI_RANGE(XTP_IDC_LANG_ARABIC, XTP_IDC_LANG_UKRAINIAN, OnUpdateLangaugeFile)
  39. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  40. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  41. ON_XTP_INITCOMMANDSPOPUP()
  42. END_MESSAGE_MAP()
  43. static UINT indicators[] =
  44. {
  45. ID_SEPARATOR,           // status line indicator
  46. ID_INDICATOR_CAPS,
  47. ID_INDICATOR_NUM,
  48. ID_INDICATOR_SCRL,
  49. };
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMainFrame construction/destruction
  52. CMainFrame::CMainFrame()
  53. {
  54. OSVERSIONINFO osvi;
  55. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  56. VERIFY(GetVersionEx(&osvi));
  57. m_bIsWin2000OrLater = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion > 4);
  58. }
  59. CMainFrame::~CMainFrame()
  60. {
  61. }
  62. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  63. {
  64. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  65. return -1;
  66. // Create Status bar.
  67. // Important: All control bars including the Status Bar
  68. // must be created before CommandBars....
  69. if (!m_wndStatusBar.Create(this) ||
  70. !m_wndStatusBar.SetIndicators(indicators,
  71. sizeof(indicators)/sizeof(UINT)))
  72. {
  73. TRACE0("Failed to create status barn");
  74. return -1;      // fail to create
  75. }
  76. // Initialize the command bars
  77. if (!InitCommandBars())
  78. return -1;
  79. XTPImageManager()->SetMaskColor(XTPImageManager()->GetBitmapMaskColor(IDR_MAINFRAME));
  80. // Get a pointer to the command bars object.
  81. CXTPCommandBars* pCommandBars = GetCommandBars();
  82. if(pCommandBars == NULL)
  83. {
  84. TRACE0("Failed to create command bars object.n");
  85. return -1;      // fail to create
  86. }
  87. // Add the menu bar
  88. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
  89. _T("Menu Bar"), IDR_MULTILTYPE);
  90. if(pMenuBar == NULL)
  91. {
  92. TRACE0("Failed to create menu bar.n");
  93. return -1;      // fail to create
  94. }
  95. pMenuBar->SetFlags(xtpFlagAddMDISysPopup);
  96. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  97. // Create ToolBar
  98. CXTPToolBar* pToolBar = (CXTPToolBar*)
  99. pCommandBars->Add(_T("Standard"), xtpBarTop);
  100. if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
  101. {
  102. TRACE0("Failed to create toolbarn");
  103. return -1;
  104. }
  105. // Create ToolBar
  106. CXTPToolBar* pLangBar = (CXTPToolBar*)
  107. pCommandBars->Add(_T("Language"), xtpBarTop);
  108. if (!pLangBar || !pLangBar->LoadToolBar(IDR_LANGBAR))
  109. {
  110. TRACE0("Failed to create toolbarn");
  111. return -1;
  112. }
  113. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
  114. // Set Office 2003 Theme
  115. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  116. // Initialize the docking pane manager and set the
  117. // initial them for the docking panes.  Do this only after all
  118. // control bars objects have been created and docked.
  119. m_paneManager.InstallDockingPanes(this);
  120. // Set Office 2003 Theme
  121. m_paneManager.SetTheme(xtpPaneThemeOffice2003);
  122. // Create docking panes.
  123. CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane(
  124. IDR_PANE_OPTIONS, CRect(0, 0,200, 120), xtpPaneDockLeft);
  125. m_paneManager.CreatePane(
  126. IDR_PANE_PROPERTIES, CRect(0, 0,200, 120), xtpPaneDockBottom, pwndPane1);
  127. // Set the icons for the docking pane tabs.
  128. int nIDIcons[] = {IDR_PANE_OPTIONS, IDR_PANE_PROPERTIES};
  129. m_paneManager.SetIcons(IDB_BITMAP_ICONS, nIDIcons,
  130. _countof(nIDIcons), RGB(0, 255, 0));
  131. // Load the previous state for docking panes.
  132. CXTPDockingPaneLayout layoutNormal(&m_paneManager);
  133. if (layoutNormal.Load(_T("NormalLayout")))
  134. {
  135. m_paneManager.SetLayout(&layoutNormal);
  136. }
  137. // Load the previous state for toolbars and menus.
  138. LoadCommandBars(_T("CommandBars"), TRUE);
  139. // Load previously selected language.
  140. OnLangaugeFile(m_langManager.GetCmdID(m_langManager.GetLangID()));
  141. return 0;
  142. }
  143. void CMainFrame::OnClose()
  144. {
  145. // Save the current state for toolbars and menus.
  146. SaveCommandBars(_T("CommandBars"));
  147. // Save the current state for docking panes.
  148. CXTPDockingPaneLayout layoutNormal(&m_paneManager);
  149. m_paneManager.GetLayout(&layoutNormal);
  150. layoutNormal.Save(_T("NormalLayout"));
  151. CMDIFrameWnd::OnClose();
  152. }
  153. void CMainFrame::OnCustomize()
  154. {
  155. // Get a pointer to the command bars object.
  156. CXTPCommandBars* pCommandBars = GetCommandBars();
  157. if(pCommandBars != NULL)
  158. {
  159. // Instantiate the customize dialog object.
  160. CXTPCustomizeSheet dlg(pCommandBars);
  161. // Add the keyboard page to the customize dialog.
  162. CXTPCustomizeKeyboardPage pageKeyboard(&dlg);
  163. dlg.AddPage(&pageKeyboard);
  164. pageKeyboard.AddCategories(IDR_MULTILTYPE);
  165. // Add the options page to the customize dialog.
  166. CXTPCustomizeOptionsPage pageOptions(&dlg);
  167. dlg.AddPage(&pageOptions);
  168. // Add the commands page to the customize dialog.
  169. CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();
  170. pCommands->AddCategories(IDR_MULTILTYPE);
  171. // Use the command bar manager to initialize the
  172. // customize dialog.
  173. pCommands->InsertAllCommandsCategory();
  174. pCommands->InsertBuiltInMenus(IDR_MULTILTYPE);
  175. pCommands->InsertNewMenuCategory();
  176. // Display the dialog.
  177. dlg.DoModal();
  178. }
  179. }
  180. CWnd* CMainFrame::CreatePropertyView()
  181. {
  182. if (m_wndPropertyGrid.GetSafeHwnd() == 0)
  183. {
  184. m_wndPropertyGrid.Create( CRect(0, 0, 0, 0), this, 0 );
  185. m_wndPropertyGrid.SetTheme(xtpGridThemeOffice2003);
  186. //m_wndPropertyGrid.ShowToolBar(TRUE);
  187. m_wndPropertyGrid.SetOwner(this);
  188. CFont font;
  189. font.CreatePointFont(60, _T("Marlett"));
  190. LOGFONT lf;
  191. font.GetLogFont(&lf);
  192. // create document settings category.
  193. CXTPPropertyGridItem* pSettings        = m_wndPropertyGrid.AddCategory(_T("Document Settings"));
  194. // add child items to category.
  195. CXTPPropertyGridItem* pItemSaveOnClose = pSettings->AddChildItem(new CXTPPropertyGridItemBool(_T("SaveOnClose"), TRUE));
  196. pSettings->AddChildItem(new CXTPPropertyGridItemFont(_T("WindowFont"), lf));
  197. pSettings->AddChildItem(new CXTPPropertyGridItemSize(_T("WindowSize"), CSize(100, 100)));
  198. pSettings->Expand();
  199. pItemSaveOnClose->Select();
  200. // create global settings category.
  201. CXTPPropertyGridItem* pGlobals      = m_wndPropertyGrid.AddCategory(_T("Global Settings"));
  202. // add child items to category.
  203. CXTPPropertyGridItem* pItemGreeting = pGlobals->AddChildItem(new CXTPPropertyGridItem(_T("Greeting Text"), _T("Welcome to your application!")));
  204. pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("ItemsInMRUList"), 4));
  205. CXTPPropertyGridItem* pItemRate     = pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("MaxRepeatRate"), 10));
  206. pGlobals->AddChildItem(new CXTPPropertyGridItemColor(_T("ToolbarColor"), RGB(255, 192,128)));
  207. pItemGreeting->SetReadOnly(TRUE);
  208. pItemRate->SetDescription(_T("The rate in milliseconds that the text will repeat."));
  209. // create version category.
  210. CXTPPropertyGridItem* pVersion      = m_wndPropertyGrid.AddCategory(_T("Version"));
  211. // add child items to category.
  212. CXTPPropertyGridItem* pItemVersion  = pVersion->AddChildItem(new CXTPPropertyGridItem(_T("AppVersion"), _T("1.0")));
  213. CXTPPropertyGridItem* pItemLanguage = pVersion->AddChildItem(new CXTPPropertyGridItem(_T("Language"), _T("English (United States)")));
  214. pItemVersion->SetReadOnly(TRUE);
  215. pVersion->Expand();
  216. CXTPPropertyGridItemConstraints* pList = pItemLanguage->GetConstraints();
  217. pList->AddConstraint(_T("Neutral"));
  218. pList->AddConstraint(_T("Arabic"));
  219. pList->AddConstraint(_T("German"));
  220. pList->AddConstraint(_T("Chinese(Taiwan)"));
  221. pList->AddConstraint(_T("English (United Kingdom)"));
  222. pList->AddConstraint(_T("English (United States)"));
  223. pList->AddConstraint(_T("France"));
  224. pList->AddConstraint(_T("Russian"));
  225. pItemLanguage->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  226. // create custom items category.
  227. CXTPPropertyGridItem* pCustom   = m_wndPropertyGrid.AddCategory(_T("Custom Items"));
  228. // add multi level tree node.
  229. CXTPPropertyGridItem* pItemOne   = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("First Level"), _T("")));
  230. CXTPPropertyGridItem* pItemTwo   = pItemOne->AddChildItem(new CXTPPropertyGridItem(_T("Second Level"), _T("")));
  231. CXTPPropertyGridItem* pItemThird = pItemTwo->AddChildItem(new CXTPPropertyGridItem(_T("Third Level"), _T("")));
  232. pItemThird->AddChildItem(new CXTPPropertyGridItem(_T("Fourth Level 1"), _T("")));
  233. pItemThird->AddChildItem(new CXTPPropertyGridItem(_T("Fourth Level 2"), _T("")));
  234. }
  235. return &m_wndPropertyGrid;
  236. }
  237. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  238. {
  239. if (wParam == XTP_DPN_SHOWWINDOW)
  240. {
  241. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  242. if (!pPane->IsValid())
  243. {
  244. switch (pPane->GetID())
  245. {
  246. case IDR_PANE_PROPERTIES:
  247. {
  248. pPane->Attach(CreatePropertyView());
  249. break;
  250. }
  251. case IDR_PANE_OPTIONS:
  252. {
  253. if (m_wndOptions.GetSafeHwnd() == 0)
  254. {
  255. m_wndOptions.Create(_T("nnOptions"),
  256. WS_CHILD|WS_CLIPCHILDREN|
  257. WS_CLIPSIBLINGS|SS_CENTER,
  258. CRect(0, 0, 0, 0), this, 0);
  259. }
  260. pPane->Attach(&m_wndOptions);
  261. break;
  262. }
  263. }
  264. }
  265. return TRUE;
  266. }
  267. return FALSE;
  268. }
  269. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  270. {
  271. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  272. return FALSE;
  273. cs.lpszClass = _T("XTPMainFrame");
  274. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  275. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  276. return TRUE;
  277. }
  278. /////////////////////////////////////////////////////////////////////////////
  279. // CMainFrame diagnostics
  280. #ifdef _DEBUG
  281. void CMainFrame::AssertValid() const
  282. {
  283. CMDIFrameWnd::AssertValid();
  284. }
  285. void CMainFrame::Dump(CDumpContext& dc) const
  286. {
  287. CMDIFrameWnd::Dump(dc);
  288. }
  289. #endif //_DEBUG
  290. /////////////////////////////////////////////////////////////////////////////
  291. // CMainFrame message handlers
  292. void CMainFrame::OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
  293. {
  294. if (pCommandBar->GetControls()->GetCount() > 0 &&
  295. pCommandBar->GetControl(0)->GetID() == ID_LANGAUGE_NOFOUND)
  296. {
  297. while (pCommandBar->GetControls()->GetCount() > 1)
  298. pCommandBar->GetControls()->Remove(1);
  299. for (UINT nCmdUI = XTP_IDC_LANG_ARABIC; nCmdUI <= XTP_IDC_LANG_UKRAINIAN; nCmdUI++)
  300. {
  301. WORD wLangID = m_langManager.GetLangID(nCmdUI);
  302. LANGUAGE_DLL langDll;
  303. if (!m_langManager.GetLangMap().Lookup(wLangID, langDll))
  304. continue;
  305. CXTPControl* pControl = pCommandBar->GetControls()->Add(
  306. xtpControlButton, langDll.uCmdID, _T(""), -1, TRUE);
  307. if (pControl)
  308. {
  309. CString strDescription = m_langManager.GetDescription(wLangID);
  310. if (strDescription.IsEmpty())
  311. {
  312. strDescription.Format(_T("(dll %d corrupt or missing) "), m_langManager.GetLangID());
  313. int iIndex = langDll.strDllPath.ReverseFind(_T('\'))+1;
  314. strDescription += langDll.strDllPath.Right(langDll.strDllPath.GetLength()-iIndex);
  315. }
  316. pControl->SetCaption(strDescription);
  317. pControl->SetParameter(langDll.strDllPath);
  318. pCommandBar->GetControl(0)->SetVisible(FALSE);
  319. }
  320. }
  321. }
  322. }
  323. void CMainFrame::ResetCommandBars()
  324. {
  325. m_bInRecalcLayout = TRUE;
  326. CXTPCommandBars* pCommandBars = GetCommandBars();
  327. for (int i = 0; i < pCommandBars->GetCount(); i++)
  328. {
  329. CXTPToolBar* pToolBar = pCommandBars->GetAt(i);
  330. if (pToolBar->IsBuiltIn())
  331. {
  332. if (pToolBar->GetType() != xtpBarTypeMenuBar)
  333. {
  334. pToolBar->LoadToolBar(pToolBar->GetBarID(), FALSE);
  335. }
  336. else
  337. {
  338. CMenu menu;
  339. menu.LoadMenu(IDR_MULTILTYPE);
  340. pToolBar->LoadMenu(&menu);
  341. pToolBar->GetControls()->CreateOriginalControls();
  342. ((CXTPMenuBar*)pToolBar)->RefreshMenu();
  343. }
  344. }
  345. if (pToolBar->GetBarID() == IDR_LANGBAR)
  346. {
  347. CXTPControls* pCommandList = pToolBar->GetControls();
  348. for (int iIndex = pCommandList->GetCount()-1; iIndex >= 0; --iIndex)
  349. {
  350. CXTPControl* pButton = pCommandList->GetAt(iIndex);
  351. if (pButton)
  352. {
  353. WORD wLangID = m_langManager.GetLangID(pButton->GetID());
  354. pButton->SetCaption(m_langManager.GetDescription(wLangID));
  355. LANGUAGE_DLL langDll;
  356. if (!m_langManager.GetDllInfo(wLangID, langDll))
  357. pCommandList->Remove(iIndex);
  358. }
  359. }
  360. }
  361. }
  362. m_bInRecalcLayout = FALSE;
  363. RecalcLayout();
  364. AfxGetApp()->OnIdle(0);
  365. RedrawWindow(NULL, NULL,
  366. RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
  367. }
  368. BOOL CMainFrame::OnLangaugeFile(UINT nID)
  369. {
  370. LANGUAGE_DLL langDll;
  371. if (m_langManager.GetDllInfo(m_langManager.GetLangID(nID), langDll))
  372. {
  373. if (m_langManager.LoadLanguageDll(langDll.strDllPath))
  374. {
  375. ::SetThreadLocale(MAKELCID(m_langManager.GetLangID(nID), SORT_DEFAULT)); 
  376. BOOL bRTLLayout = ((::GetWindowLong(m_hWnd, GWL_EXSTYLE)
  377. & WS_EX_LAYOUTRTL) == WS_EX_LAYOUTRTL);
  378. if (bRTLLayout != m_langManager.IsRTL())
  379. {
  380. m_langManager.SetRTLLayout(this, m_langManager.IsRTL());
  381. XTPImageManager()->DrawReverted(m_langManager.IsRTL());
  382. }
  383. ResetCommandBars();
  384. return TRUE;
  385. }
  386. }
  387. return FALSE;
  388. }
  389. BOOL CMainFrame::IsUnicodeAndLayoutSupport()
  390. {
  391. #ifdef _UNICODE
  392. return m_bIsWin2000OrLater;
  393. #else
  394. return FALSE;
  395. #endif
  396. }
  397. void CMainFrame::OnUpdateLangaugeFile(CCmdUI* pCmdUI)
  398. {
  399. WORD wLangID = m_langManager.GetLangID(pCmdUI->m_nID);
  400. if (!IsUnicodeAndLayoutSupport())
  401. {
  402. switch (pCmdUI->m_nID)
  403. {
  404. case XTP_IDC_LANG_ARABIC:
  405. case XTP_IDC_LANG_HEBREW:
  406. {
  407. pCmdUI->Enable(FALSE);
  408. return;
  409. }
  410. case XTP_IDC_LANG_CHINESE_PRC:
  411. case XTP_IDC_LANG_CHINESE_TAIWAN:
  412. case XTP_IDC_LANG_GREEK:
  413. case XTP_IDC_LANG_JAPANESE:
  414. case XTP_IDC_LANG_KOREAN:
  415. case XTP_IDC_LANG_THAI:
  416. case XTP_IDC_LANG_RUSSIAN:
  417. case XTP_IDC_LANG_UKRAINIAN:
  418. {
  419. if (wLangID != GetSystemDefaultLangID())
  420. {
  421. pCmdUI->Enable(FALSE);
  422. return;
  423. }
  424. }
  425. }
  426. }
  427. LANGUAGE_DLL langDll;
  428. if (m_langManager.GetDllInfo(wLangID, langDll))
  429. {
  430. pCmdUI->SetCheck(wLangID == m_langManager.GetLangID());
  431. pCmdUI->Enable(TRUE);
  432. }
  433. else
  434. {
  435. pCmdUI->Enable(FALSE);
  436. }
  437. }
  438. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  439. {
  440. // Toggle CommandBars
  441. GetCommandBars()->OnSetPreviewMode(bPreview);
  442. // Toggle Docking Panes.
  443. m_paneManager.OnSetPreviewMode(bPreview);
  444. CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
  445. }