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

对话框与窗口

开发平台:

Visual C++

  1. // XTPSyntaxEditPropertiesPage.cpp : implementation file
  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 SYNTAX EDIT 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. // common includes
  23. #include "Common/XTPNotifyConnection.h"
  24. #include "Common/XTPSmartPtrInternalT.h"
  25. #include "Common/XTPVC80Helpers.h"
  26. #include "Common/XTPVC50Helpers.h"
  27. #include "Common/XTPResourceManager.h"
  28. #include "Common/XTPDrawHelpers.h"
  29. // syntax editor includes
  30. #include "XTPSyntaxEditDefines.h"
  31. #include "XTPSyntaxEditStruct.h"
  32. #include "XTPSyntaxEditLexPtrs.h"
  33. #include "XTPSyntaxEditLexClassSubObjT.h"
  34. #include "XTPSyntaxEditTextIterator.h"
  35. #include "XTPSyntaxEditSectionManager.h"
  36. #include "XTPSyntaxEditLexCfgFileReader.h"
  37. #include "XTPSyntaxEditLexClassSubObjDef.h"
  38. #include "XTPSyntaxEditLexClass.h"
  39. #include "XTPSyntaxEditLexColorFileReader.h"
  40. #include "XTPSyntaxEditBufferManager.h"
  41. #include "XTPSyntaxEditCtrl.h"
  42. #include "XTPSyntaxEditDoc.h"
  43. #include "XTPSyntaxEditView.h"
  44. #include "XTPSyntaxEditPaintManager.h"
  45. #include "XTPSyntaxEditColorSampleText.h"
  46. #include "XTPSyntaxEditColorComboBox.h"
  47. #include "XTPSyntaxEditPropertiesPage.h"
  48. #include "XTPSyntaxEditPropertiesDlg.h"
  49. #ifdef _DEBUG
  50. #undef THIS_FILE
  51. static char BASED_CODE THIS_FILE[] = __FILE__;
  52. #endif
  53. //===========================================================================
  54. // EnumFontFamExProc
  55. //===========================================================================
  56. AFX_STATIC int CALLBACK EnumFontFamExProc(
  57. ENUMLOGFONTEX *lpelfe,    // logical-font data
  58. NEWTEXTMETRICEX *lpntme,  // physical-font data
  59. DWORD FontType,           // type of font
  60. LPARAM lParam)            // application-defined data
  61. {
  62. CComboBox* pWndCombo = DYNAMIC_DOWNCAST(CComboBox, (CComboBox*)lParam);
  63. if (::IsWindow(pWndCombo->GetSafeHwnd()))
  64. {
  65. switch (pWndCombo->GetDlgCtrlID())
  66. {
  67. case XTP_IDC_EDIT_COMB_NAMES:
  68. {
  69. //if (lpelfe->elfLogFont.lfPitchAndFamily & FIXED_PITCH)
  70. {
  71. // Make sure the fonts are only added once.
  72. if (pWndCombo->FindStringExact(0, (LPCTSTR)lpelfe->elfFullName) == CB_ERR)
  73. {
  74. // Add to list
  75. pWndCombo->AddString((LPCTSTR)lpelfe->elfLogFont.lfFaceName);
  76. }
  77. }
  78. }
  79. break;
  80. case XTP_IDC_EDIT_COMB_SIZES:
  81. {
  82. if (FontType != TRUETYPE_FONTTYPE)
  83. {
  84. CWindowDC dc(NULL);
  85. CString csSize;
  86. csSize.Format(_T("%i"),::MulDiv(lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading,
  87. 72, ::GetDeviceCaps(dc.m_hDC, LOGPIXELSY)));
  88. // Make sure the fonts are only added once.
  89. if (pWndCombo->FindStringExact(0, (LPCTSTR)csSize) == CB_ERR)
  90. {
  91. // Add to list
  92. pWndCombo->AddString((LPCTSTR)csSize);
  93. }
  94. }
  95. }
  96. break;
  97. case XTP_IDC_EDIT_COMB_SCRIPT:
  98. {
  99. if (lpelfe->elfScript[0] != _T(''))
  100. {
  101. // Make sure the fonts are only added once.
  102. if (pWndCombo->FindStringExact(0, (LPCTSTR)lpelfe->elfScript) == CB_ERR)
  103. {
  104. // Add to list
  105. int iIndex = pWndCombo->AddString((LPCTSTR)lpelfe->elfScript);
  106. if (iIndex != CB_ERR)
  107. {
  108. pWndCombo->SetItemData(iIndex,
  109. (DWORD)lpelfe->elfLogFont.lfCharSet);
  110. }
  111. }
  112. }
  113. }
  114. break;
  115. }
  116. }
  117. return TRUE;
  118. }
  119. namespace XTPSyntaxEditLexAnalyser
  120. {
  121. extern CString MakeStr(const CStringArray& rArProps, LPCTSTR strSplitter);
  122. extern BOOL PropPathSplit(LPCTSTR pcszPropPath, CStringArray& rArProps);
  123. }
  124. using namespace XTPSyntaxEditLexAnalyser;
  125. //===========================================================================
  126. // CXTPSyntaxEditPropertiesPageEdit property page
  127. //===========================================================================
  128. CXTPSyntaxEditPropertiesPageEdit::CXTPSyntaxEditPropertiesPageEdit(CXTPSyntaxEditView* pEditView/*=NULL*/)
  129. : //CPropertyPage(CXTPSyntaxEditPropertiesPageEdit::IDD),
  130. m_bModified(FALSE)
  131. , m_pEditView(pEditView)
  132. {
  133. ASSERT_VALID(m_pEditView); // must be valid.
  134. m_psp.dwFlags |= PSP_DLGINDIRECT;
  135. m_psp.pResource = XTPResourceManager()->LoadDialogTemplate(IDD);
  136. //{{AFX_DATA_INIT(CXTPSyntaxEditPropertiesPageEdit)
  137. m_bAutoReload = TRUE;
  138. m_bHorzScrollBar = TRUE;
  139. m_bVertScrollBar = TRUE;
  140. m_bSyntaxColor = TRUE;
  141. m_bAutoIndent = TRUE;
  142. m_bSelMargin = TRUE;
  143. m_bLineNumbers = TRUE;
  144. m_bVirtualSpace = TRUE;
  145. m_bCollapsibleNodes = TRUE;
  146. m_nCaretStyle = 0;
  147. m_nTabSize = 4;
  148. m_nTabType = 1;
  149. //}}AFX_DATA_INIT
  150. ReadRegistryValues();
  151. }
  152. CXTPSyntaxEditPropertiesPageEdit::~CXTPSyntaxEditPropertiesPageEdit()
  153. {
  154. }
  155. void CXTPSyntaxEditPropertiesPageEdit::DoDataExchange(CDataExchange* pDX)
  156. {
  157. CPropertyPage::DoDataExchange(pDX);
  158. //{{AFX_DATA_MAP(CXTPSyntaxEditPropertiesPageEdit)
  159. DDX_Check(pDX, XTP_IDC_EDIT_CHK_AUTO_RELOAD, m_bAutoReload);
  160. DDX_Check(pDX, XTP_IDC_EDIT_CHK_HORZ_SCROLLBAR, m_bHorzScrollBar);
  161. DDX_Check(pDX, XTP_IDC_EDIT_CHK_VERT_SCROLLBAR, m_bVertScrollBar);
  162. DDX_Check(pDX, XTP_IDC_EDIT_CHK_SYNTAX_COLOR, m_bSyntaxColor);
  163. DDX_Check(pDX, XTP_IDC_EDIT_CHK_AUTO_INDENT, m_bAutoIndent);
  164. DDX_Check(pDX, XTP_IDC_EDIT_CHK_SELMARGIN, m_bSelMargin);
  165. DDX_Check(pDX, XTP_IDC_EDIT_CHK_LINE_NUMBERS, m_bLineNumbers);
  166. DDX_Check(pDX, XTP_IDC_EDIT_CHK_VIRTUAL_SPACE, m_bVirtualSpace);
  167. DDX_Check(pDX, XTP_IDC_EDIT_CHK_COLLAPSIBLE_NODES, m_bCollapsibleNodes);
  168. DDX_Control(pDX, XTP_IDC_EDIT_RAD_TABS_SPACES, m_btnRadioSpaces);
  169. DDX_Control(pDX, XTP_IDC_EDIT_RAD_TABS_TAB, m_btnRadioTab);
  170. DDX_Control(pDX, XTP_IDC_EDIT_RAD_CARET_THIN, m_btnRadioCaretThin);
  171. DDX_Control(pDX, XTP_IDC_EDIT_RAD_CARET_THICK, m_btnRadioCaretThick);
  172. DDX_Text(pDX, XTP_IDC_EDIT_TABS_SIZE, m_nTabSize);
  173. DDV_MinMaxInt(pDX, m_nTabSize, 1, 64);
  174. //}}AFX_DATA_MAP
  175. }
  176. IMPLEMENT_DYNCREATE(CXTPSyntaxEditPropertiesPageEdit, CPropertyPage)
  177. BEGIN_MESSAGE_MAP(CXTPSyntaxEditPropertiesPageEdit, CPropertyPage)
  178. //{{AFX_MSG_MAP(CXTPSyntaxEditPropertiesPageEdit)
  179. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_AUTO_RELOAD, OnChkAutoReload)
  180. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_HORZ_SCROLLBAR, OnChkHorzScrollBar)
  181. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_VERT_SCROLLBAR, OnChkVertScrollBar)
  182. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_SYNTAX_COLOR, OnChkSyntaxColor)
  183. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_AUTO_INDENT, OnChkAutoIndent)
  184. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_SELMARGIN, OnChkSelMargin)
  185. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_LINE_NUMBERS, OnChkLineNumbers)
  186. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_COLLAPSIBLE_NODES, OnChkLineNumbers)
  187. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_VIRTUAL_SPACE, OnChkVirtualSpace)
  188. ON_BN_CLICKED(XTP_IDC_EDIT_RAD_TABS_SPACES, OnTabsSpaces)
  189. ON_BN_CLICKED(XTP_IDC_EDIT_RAD_TABS_TAB, OnTabsTab)
  190. ON_BN_CLICKED(XTP_IDC_EDIT_RAD_CARET_THIN, OnCaretThin)
  191. ON_BN_CLICKED(XTP_IDC_EDIT_RAD_CARET_THICK, OnCaretThick)
  192. ON_EN_CHANGE(XTP_IDC_EDIT_TABS_SIZE, OnChangeTabsSize)
  193. //}}AFX_MSG_MAP
  194. END_MESSAGE_MAP()
  195. BOOL CXTPSyntaxEditPropertiesPageEdit::ReadRegistryValues()
  196. {
  197. if (!::IsWindow(m_pEditView->GetSafeHwnd()))
  198. return FALSE;
  199. CXTPSyntaxEditDoc* pEditDoc = m_pEditView->GetDocument();
  200. if (pEditDoc)
  201. {
  202. m_bAutoReload = pEditDoc->GetAutoReload();
  203. }
  204. CXTPSyntaxEditCtrl& wndEditCtrl = m_pEditView->GetEditCtrl();
  205. if (::IsWindow(wndEditCtrl.m_hWnd))
  206. {
  207. m_bVertScrollBar = wndEditCtrl.GetVertScrollBar();
  208. m_bHorzScrollBar = wndEditCtrl.GetHorzScrollBar();
  209. m_bSyntaxColor  = wndEditCtrl.GetSyntaxColor();
  210. m_bAutoIndent   = wndEditCtrl.GetAutoIndent();
  211. m_bSelMargin    = wndEditCtrl.GetSelMargin();
  212. m_bLineNumbers  = wndEditCtrl.GetLineNumbers();
  213. m_bVirtualSpace = wndEditCtrl.IsEnabledVirtualSpace();
  214. m_bCollapsibleNodes = wndEditCtrl.GetCollapsibleNodes();
  215. m_nCaretStyle   = wndEditCtrl.GetWideCaret();
  216. m_nTabSize      = wndEditCtrl.GetTabSize();
  217. m_nTabType      = wndEditCtrl.GetTabWithSpace() ? 0: 1;
  218. }
  219. return TRUE;
  220. }
  221. BOOL CXTPSyntaxEditPropertiesPageEdit::WriteRegistryValues()
  222. {
  223. if (!::IsWindow(m_pEditView->GetSafeHwnd()))
  224. return FALSE;
  225. CXTPSyntaxEditDoc* pEditDoc = m_pEditView->GetDocument();
  226. if (pEditDoc)
  227. {
  228. pEditDoc->SetAutoReload(m_bAutoReload, TRUE);
  229. }
  230. CXTPSyntaxEditCtrl& wndEditCtrl = m_pEditView->GetEditCtrl();
  231. if (::IsWindow(wndEditCtrl.m_hWnd))
  232. {
  233. wndEditCtrl.SetScrollBars(m_bHorzScrollBar, m_bVertScrollBar, TRUE);
  234. wndEditCtrl.SetSyntaxColor(m_bSyntaxColor, TRUE);
  235. wndEditCtrl.SetAutoIndent(m_bAutoIndent, TRUE);
  236. wndEditCtrl.SetSelMargin(m_bSelMargin, TRUE);
  237. wndEditCtrl.SetLineNumbers(m_bLineNumbers, TRUE);
  238. wndEditCtrl.EnableVirtualSpace(m_bVirtualSpace, TRUE);
  239. wndEditCtrl.SetCollapsibleNodes(m_bCollapsibleNodes, TRUE);
  240. wndEditCtrl.SetWideCaret(m_nCaretStyle, TRUE);
  241. wndEditCtrl.SetTabSize(m_nTabSize, TRUE);
  242. wndEditCtrl.SetTabWithSpace(m_nTabType? FALSE: TRUE, TRUE);
  243. }
  244. wndEditCtrl.RestoreCursor();
  245. return TRUE;
  246. }
  247. void CXTPSyntaxEditPropertiesPageEdit::OnChkAutoReload()
  248. {
  249. UpdateData();
  250. SetModified(TRUE);
  251. }
  252. void CXTPSyntaxEditPropertiesPageEdit::OnChkHorzScrollBar()
  253. {
  254. UpdateData();
  255. SetModified(TRUE);
  256. }
  257. void CXTPSyntaxEditPropertiesPageEdit::OnChkVertScrollBar()
  258. {
  259. UpdateData();
  260. SetModified(TRUE);
  261. }
  262. void CXTPSyntaxEditPropertiesPageEdit::OnChkSyntaxColor()
  263. {
  264. UpdateData();
  265. SetModified(TRUE);
  266. }
  267. void CXTPSyntaxEditPropertiesPageEdit::OnChkAutoIndent()
  268. {
  269. UpdateData();
  270. SetModified(TRUE);
  271. }
  272. void CXTPSyntaxEditPropertiesPageEdit::OnChkSelMargin()
  273. {
  274. UpdateData();
  275. SetModified(TRUE);
  276. }
  277. void CXTPSyntaxEditPropertiesPageEdit::OnChkLineNumbers()
  278. {
  279. UpdateData();
  280. SetModified(TRUE);
  281. }
  282. void CXTPSyntaxEditPropertiesPageEdit::OnChkVirtualSpace()
  283. {
  284. UpdateData();
  285. SetModified(TRUE);
  286. }
  287. void CXTPSyntaxEditPropertiesPageEdit::OnChangeTabsSize()
  288. {
  289. UpdateData();
  290. SetModified(TRUE);
  291. }
  292. void CXTPSyntaxEditPropertiesPageEdit::OnTabsSpaces()
  293. {
  294. m_nTabType = 0;
  295. SetModified(TRUE);
  296. }
  297. void CXTPSyntaxEditPropertiesPageEdit::OnTabsTab()
  298. {
  299. m_nTabType = 1;
  300. SetModified(TRUE);
  301. }
  302. void CXTPSyntaxEditPropertiesPageEdit::OnCaretThin()
  303. {
  304. m_nCaretStyle = 0;
  305. SetModified(TRUE);
  306. }
  307. void CXTPSyntaxEditPropertiesPageEdit::OnCaretThick()
  308. {
  309. m_nCaretStyle = 1;
  310. SetModified(TRUE);
  311. }
  312. BOOL CXTPSyntaxEditPropertiesPageEdit::OnInitDialog()
  313. {
  314. CPropertyPage::OnInitDialog();
  315. m_btnRadioSpaces.SetCheck(m_nTabType == 0);
  316. m_btnRadioTab.SetCheck(m_nTabType == 1);
  317. m_btnRadioCaretThin.SetCheck(m_nCaretStyle == 0);
  318. m_btnRadioCaretThick.SetCheck(m_nCaretStyle == 1);
  319. return TRUE;  // return TRUE unless you set the focus to a control
  320.               // EXCEPTION: OCX Property Pages should return FALSE
  321. }
  322. BOOL CXTPSyntaxEditPropertiesPageEdit::OnApply()
  323. {
  324. if (!CPropertyPage::OnApply())
  325. return FALSE;
  326. // no changes made or they have already been applied.
  327. if (!m_bModified)
  328. return TRUE;
  329. // update registry settings.
  330. if (!WriteRegistryValues())
  331. return FALSE;
  332. m_bModified = FALSE;
  333. if (m_pEditView && m_pEditView->GetDocument() )
  334. m_pEditView->GetDocument()->UpdateAllViews(NULL, xtpEditHintInitView);
  335. return TRUE;
  336. }
  337. void CXTPSyntaxEditPropertiesPageEdit::SetModified(BOOL bChanged/*=TRUE*/)
  338. {
  339. CPropertyPage::SetModified();
  340. m_bModified = bChanged;
  341. }
  342. //===========================================================================
  343. // CXTPSyntaxEditPropertiesPageFont property page
  344. //===========================================================================
  345. CXTPSyntaxEditPropertiesPageFont::CXTPSyntaxEditPropertiesPageFont(CXTPSyntaxEditView* pEditView/*=NULL*/)
  346. : //CPropertyPage(CXTPSyntaxEditPropertiesPageFont::IDD),
  347. m_bModified(FALSE)
  348. , m_pEditView(pEditView)
  349. , m_uFaceSize(LF_FACESIZE)
  350. {
  351. m_psp.dwFlags |= PSP_DLGINDIRECT;
  352. m_psp.pResource = XTPResourceManager()->LoadDialogTemplate(IDD);
  353. //{{AFX_DATA_INIT(CXTPSyntaxEditPropertiesPageFont)
  354. m_bStrikeOut = FALSE;
  355. m_bUnderline = FALSE;
  356. m_csName = _T("Courier");
  357. m_csStyle = _T("Regular");
  358. m_csSize = _T("10");
  359. //}}AFX_DATA_INIT
  360. m_iCharSet = DEFAULT_CHARSET;
  361. m_crHiliteText = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
  362. m_crHiliteBack = ::GetSysColor(COLOR_HIGHLIGHT);
  363. m_crText = ::GetSysColor(COLOR_WINDOWTEXT);
  364. m_crBack = ::GetSysColor(COLOR_WINDOW);
  365. ReadRegistryValues();
  366. }
  367. CXTPSyntaxEditPropertiesPageFont::~CXTPSyntaxEditPropertiesPageFont()
  368. {
  369. }
  370. void CXTPSyntaxEditPropertiesPageFont::DoDataExchange(CDataExchange* pDX)
  371. {
  372. CPropertyPage::DoDataExchange(pDX);
  373. //{{AFX_DATA_MAP(CXTPSyntaxEditPropertiesPageFont)
  374. DDX_Control(pDX, XTP_IDC_EDIT_COMB_SCRIPT, m_wndComboScript);
  375. DDX_Control(pDX, XTP_IDC_EDIT_COMB_STYLES, m_wndComboStyle);
  376. DDX_Control(pDX, XTP_IDC_EDIT_COMB_SIZES, m_wndComboSize);
  377. DDX_Control(pDX, XTP_IDC_EDIT_COMB_NAMES, m_wndComboName);
  378. /*  DDX_Check(pDX, XTP_IDC_EDIT_CHK_STRIKEOUT, m_bStrikeOut);*/
  379. /*  DDX_Check(pDX, XTP_IDC_EDIT_CHK_UNDERLINE, m_bUnderline);*/
  380. DDX_Control(pDX, XTP_IDC_EDIT_COMB_TEXT, m_wndComboText);
  381. DDX_Control(pDX, XTP_IDC_EDIT_COMB_BACK, m_wndComboBack);
  382. DDX_Control(pDX, XTP_IDC_EDIT_COMB_TEXTSEL, m_wndComboHiliteText);
  383. DDX_Control(pDX, XTP_IDC_EDIT_COMB_BACKSEL, m_wndComboHiliteBack);
  384. DDX_Control(pDX, XTP_IDC_EDIT_TXT_SAMPLE, m_txtSample);
  385. DDX_Control(pDX, XTP_IDC_EDIT_TXT_SAMPLESEL, m_txtSampleSel);
  386. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_TEXT, m_crText);
  387. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_BACK, m_crBack);
  388. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_TEXTSEL, m_crHiliteText);
  389. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_BACKSEL, m_crHiliteBack);
  390. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_TEXT, m_btnCustomText);
  391. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_BACK, m_btnCustomBack);
  392. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_TEXTSEL, m_btnCustomHiliteText);
  393. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_BACKSEL, m_btnCustomHiliteBack);
  394. DDX_CBString(pDX, XTP_IDC_EDIT_COMB_STYLES, m_csStyle);
  395. DDX_CBString(pDX, XTP_IDC_EDIT_COMB_NAMES, m_csName);
  396. DDX_CBString(pDX, XTP_IDC_EDIT_COMB_SIZES, m_csSize);
  397. DDV_MaxChars(pDX, m_csSize, m_uFaceSize);
  398. //}}AFX_DATA_MAP
  399. }
  400. IMPLEMENT_DYNCREATE(CXTPSyntaxEditPropertiesPageFont, CPropertyPage)
  401. BEGIN_MESSAGE_MAP(CXTPSyntaxEditPropertiesPageFont, CPropertyPage)
  402. //{{AFX_MSG_MAP(CXTPSyntaxEditPropertiesPageFont)
  403. ON_CBN_SELCHANGE(XTP_IDC_EDIT_COMB_NAMES, OnSelChangeComboNames)
  404. ON_CBN_SELCHANGE(XTP_IDC_EDIT_COMB_STYLES, OnSelChangeComboStyles)
  405. ON_CBN_SELCHANGE(XTP_IDC_EDIT_COMB_SIZES, OnSelChangeComboSizes)
  406. /*  ON_BN_CLICKED(XTP_IDC_EDIT_CHK_STRIKEOUT, OnChkStrikeOut)*/
  407. /*  ON_BN_CLICKED(XTP_IDC_EDIT_CHK_UNDERLINE, OnChkUnderline)*/
  408. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_TEXT, OnBtnCustomText)
  409. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_BACK, OnBtnCustomBack)
  410. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_TEXTSEL, OnBtnCustomHiliteText)
  411. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_BACKSEL, OnBtnCustomtHiliteBack)
  412. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_TEXTSEL, OnSelEndOkHiliteText)
  413. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_BACKSEL, OnSelEndOkHiliteBack)
  414. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_TEXT, OnSelEndOkText)
  415. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_BACK, OnSelEndOkBack)
  416. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_SCRIPT, OnSelEndOkScript)
  417. //}}AFX_MSG_MAP
  418. END_MESSAGE_MAP()
  419. BOOL CXTPSyntaxEditPropertiesPageFont::CreateSafeFontIndirect(CFont& editFont, const LOGFONT& lf)
  420. {
  421. if (editFont.GetSafeHandle())
  422. editFont.DeleteObject();
  423. if (!editFont.CreateFontIndirect(&lf))
  424. return FALSE;
  425. return TRUE;
  426. }
  427. BOOL CXTPSyntaxEditPropertiesPageFont::GetSafeLogFont(LOGFONT& lf)
  428. {
  429. if (m_editFont.GetSafeHandle())
  430. {
  431. m_editFont.GetLogFont(&lf);
  432. return TRUE;
  433. }
  434. CFont* pFont = GetPaintManager() ? GetPaintManager()->GetFont() : NULL;
  435. if (pFont && pFont->GetSafeHandle())
  436. {
  437. pFont->GetLogFont(&lf);
  438. return TRUE;
  439. }
  440. return FALSE;
  441. }
  442. BOOL CXTPSyntaxEditPropertiesPageFont::ReadRegistryValues()
  443. {
  444. LOGFONT lf = {0};
  445. if (!GetSafeLogFont(lf))
  446. return FALSE;
  447. if (!CreateSafeFontIndirect(m_editFont, lf))
  448. return FALSE;
  449. if (!GetPaintManager())
  450. return FALSE;
  451. m_crText        = GetPaintManager()->GetTextColor();
  452. m_crBack        = GetPaintManager()->GetBackColor();
  453. m_crHiliteText  = GetPaintManager()->GetHiliteTextColor();
  454. m_crHiliteBack  = GetPaintManager()->GetHiliteBackColor();
  455. m_bStrikeOut    = (BOOL)lf.lfStrikeOut;
  456. m_bUnderline    = (BOOL)lf.lfUnderline;
  457. return TRUE;
  458. }
  459. BOOL CXTPSyntaxEditPropertiesPageFont::WriteRegistryValues()
  460. {
  461. // update paint manager font(paint manager font is set with CXTPSyntaxEditCtrl::CreateFontIndirect).
  462. LOGFONT lf = {0};
  463. if (!GetSafeLogFont(lf))
  464. return FALSE;
  465. if (!m_pEditView || !GetPaintManager())
  466. return FALSE;
  467. m_pEditView->SetFontIndirect(&lf, TRUE);
  468. // commit values to registry.
  469. GetPaintManager()->SetTextColor(m_crText, TRUE);
  470. GetPaintManager()->SetBackColor(m_crBack, TRUE);
  471. GetPaintManager()->SetHiliteTextColor(m_crHiliteText, TRUE);
  472. GetPaintManager()->SetHiliteBackColor(m_crHiliteBack, TRUE);
  473. return TRUE;
  474. }
  475. CXTPSyntaxEditPaintManager* CXTPSyntaxEditPropertiesPageFont::GetPaintManager()
  476. {
  477. if (m_pEditView)
  478. return m_pEditView->GetEditCtrl().GetPaintManager();
  479. return NULL;
  480. }
  481. BOOL CXTPSyntaxEditPropertiesPageFont::OnInitDialog()
  482. {
  483. CPropertyPage::OnInitDialog();
  484. // Initialize combo boxes.
  485. InitFontCombo();
  486. InitStyleCombo();
  487. InitSizeCombo();
  488. InitScriptCombo();
  489. InitColorComboxes();
  490. UpdateSampleFont();
  491. return TRUE;  // return TRUE unless you set the focus to a control
  492.               // EXCEPTION: OCX Property Pages should return FALSE
  493. }
  494. void CXTPSyntaxEditPropertiesPageFont::InitFontCombo()
  495. {
  496. m_wndComboName.ResetContent();
  497. LOGFONT lfEnum = {0};
  498. lfEnum.lfCharSet = DEFAULT_CHARSET;
  499. lfEnum.lfPitchAndFamily = /*FIXED_PITCH | */ FF_DONTCARE;
  500. lfEnum.lfFaceName[0] = 0;
  501. CWindowDC dc(NULL);
  502. ::EnumFontFamiliesEx(dc.m_hDC, &lfEnum,
  503. (FONTENUMPROC)EnumFontFamExProc, (LPARAM)&m_wndComboName, 0 );
  504. if (!m_editFont.GetSafeHandle())
  505. return;
  506. LOGFONT lf = {0};
  507. if (!GetSafeLogFont(lf))
  508. return;
  509. m_csName = lf.lfFaceName;
  510. if (m_wndComboName.SelectString(-1, m_csName) == CB_ERR)
  511. m_wndComboName.SetWindowText(m_csName);
  512. }
  513. void CXTPSyntaxEditPropertiesPageFont::InitStyleCombo()
  514. {
  515. m_wndComboStyle.ResetContent();
  516. CString csBuffer;
  517. XTPResourceManager()->LoadString(&csBuffer, XTP_IDS_EDIT_REGULAR);
  518. m_wndComboStyle.AddString(csBuffer);
  519. XTPResourceManager()->LoadString(&csBuffer, XTP_IDS_EDIT_BOLD);
  520. m_wndComboStyle.AddString(csBuffer);
  521. XTPResourceManager()->LoadString(&csBuffer, XTP_IDS_EDIT_ITALIC);
  522. m_wndComboStyle.AddString(csBuffer);
  523. XTPResourceManager()->LoadString(&csBuffer, XTP_IDS_EDIT_BOLDITALIC);
  524. m_wndComboStyle.AddString(csBuffer);
  525. if (!m_editFont.GetSafeHandle())
  526. return;
  527. LOGFONT lf = {0};
  528. if (!GetSafeLogFont(lf))
  529. return;
  530. if (lf.lfWeight >= FW_BOLD && lf.lfItalic)
  531. {
  532. XTPResourceManager()->LoadString(&m_csStyle, XTP_IDS_EDIT_BOLDITALIC);
  533. }
  534. else if (lf.lfItalic)
  535. {
  536. XTPResourceManager()->LoadString(&m_csStyle, XTP_IDS_EDIT_ITALIC);
  537. }
  538. else if (lf.lfWeight >= FW_BOLD)
  539. {
  540. XTPResourceManager()->LoadString(&m_csStyle, XTP_IDS_EDIT_BOLD);
  541. }
  542. else
  543. {
  544. XTPResourceManager()->LoadString(&m_csStyle, XTP_IDS_EDIT_REGULAR);
  545. }
  546. if (m_wndComboStyle.SelectString(-1, m_csStyle) == CB_ERR)
  547. m_wndComboStyle.SetWindowText(m_csStyle);
  548. }
  549. void CXTPSyntaxEditPropertiesPageFont::InitSizeCombo()
  550. {
  551. m_wndComboSize.ResetContent();
  552. if (!m_editFont.GetSafeHandle())
  553. return;
  554. LOGFONT lf = {0};
  555. if (!GetSafeLogFont(lf))
  556. return;
  557. CWindowDC dc(NULL);
  558. ::EnumFontFamiliesEx(dc.m_hDC, &lf,
  559. (FONTENUMPROC)EnumFontFamExProc, (LPARAM)&m_wndComboSize, 0);
  560. if (m_wndComboSize.GetCount() == 0)
  561. {
  562. TCHAR* szSize[] = {
  563. _T("8"),  _T("9"),  _T("10"), _T("11"),
  564. _T("12"), _T("14"), _T("16"), _T("18"),
  565. _T("20"), _T("22"), _T("24"), _T("26"),
  566. _T("28"), _T("36"), _T("48"), _T("72") };
  567. for (int i = 0; i < (sizeof(szSize)/sizeof(szSize[0])); i++)
  568. {
  569. m_wndComboSize.AddString(szSize[i]);
  570. }
  571. }
  572. m_csSize.Format(_T("%i"),-::MulDiv(lf.lfHeight,
  573. 72, ::GetDeviceCaps(dc.m_hDC, LOGPIXELSY)));
  574. if (m_wndComboSize.SelectString(-1, m_csSize) == CB_ERR)
  575. m_wndComboSize.SetWindowText(m_csSize);
  576. }
  577. void CXTPSyntaxEditPropertiesPageFont::InitScriptCombo()
  578. {
  579. m_wndComboScript.ResetContent();
  580. if (!m_editFont.GetSafeHandle())
  581. return;
  582. LOGFONT lf = {0};
  583. if (!GetSafeLogFont(lf))
  584. return;
  585. m_iCharSet = lf.lfCharSet;
  586. lf.lfCharSet = DEFAULT_CHARSET;
  587. lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
  588. CWindowDC dc(NULL);
  589. ::EnumFontFamiliesEx(dc.m_hDC, &lf,
  590. (FONTENUMPROC)EnumFontFamExProc, (LPARAM)&m_wndComboScript, 0);
  591. int iCount = m_wndComboScript.GetCount();
  592. int i;
  593. for (i = 0; i < iCount; ++i)
  594. {
  595. BYTE lfCharSet = (BYTE)m_wndComboScript.GetItemData(i);
  596. if (lfCharSet == (BYTE)m_iCharSet)
  597. {
  598. m_wndComboScript.SetCurSel(i);
  599. break;
  600. }
  601. }
  602. if (i == iCount)
  603. m_wndComboScript.SetCurSel(0);
  604. }
  605. void CXTPSyntaxEditPropertiesPageFont::InitColorComboxes()
  606. {
  607. ASSERT(GetPaintManager());
  608. if (!GetPaintManager())
  609. return;
  610. m_wndComboText.SetAutoColor(::GetSysColor(COLOR_WINDOWTEXT));
  611. m_crText = GetPaintManager()->GetTextColor();
  612. if (m_wndComboText.SetSelColor(m_crText) == CB_ERR)
  613. {
  614. m_wndComboText.SetUserColor(m_crText);
  615. m_wndComboText.SetSelColor(m_crText);
  616. }
  617. m_wndComboBack.SetAutoColor(::GetSysColor(COLOR_WINDOW));
  618. m_crBack = GetPaintManager()->GetBackColor();
  619. if (m_wndComboBack.SetSelColor(m_crBack) == CB_ERR)
  620. {
  621. m_wndComboBack.SetUserColor(m_crBack);
  622. m_wndComboBack.SetSelColor(m_crBack);
  623. }
  624. m_wndComboHiliteText.SetAutoColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
  625. m_crHiliteText = GetPaintManager()->GetHiliteTextColor();
  626. if (m_wndComboHiliteText.SetSelColor(m_crHiliteText) == CB_ERR)
  627. {
  628. m_wndComboHiliteText.SetUserColor(m_crHiliteText);
  629. m_wndComboHiliteText.SetSelColor(m_crHiliteText);
  630. }
  631. m_wndComboHiliteBack.SetAutoColor(::GetSysColor(COLOR_HIGHLIGHT));
  632. m_crHiliteBack = GetPaintManager()->GetHiliteBackColor();
  633. if (m_wndComboHiliteBack.SetSelColor(m_crHiliteBack) == CB_ERR)
  634. {
  635. m_wndComboHiliteBack.SetUserColor(m_crHiliteBack);
  636. m_wndComboHiliteBack.SetSelColor(m_crHiliteBack);
  637. }
  638. UpdateSampleColors();
  639. }
  640. void CXTPSyntaxEditPropertiesPageFont::UpdateSampleColors()
  641. {
  642. m_txtSample.SetBackColor(m_crBack);
  643. m_txtSample.SetTextColor(m_crText);
  644. m_txtSampleSel.SetBackColor(m_crHiliteBack);
  645. m_txtSampleSel.SetTextColor(m_crHiliteText);
  646. }
  647. void CXTPSyntaxEditPropertiesPageFont::UpdateSampleFont()
  648. {
  649. if (m_editFont.GetSafeHandle())
  650. {
  651. m_txtSample.SetFont(&m_editFont);
  652. m_txtSampleSel.SetFont(&m_editFont);
  653. }
  654. }
  655. int CXTPSyntaxEditPropertiesPageFont::GetLBText(CComboBox& comboBox, CString& csItemText)
  656. {
  657. UpdateData();
  658. if (!::IsWindow(comboBox.m_hWnd))
  659. return CB_ERR;
  660. int iCurSel = comboBox.GetCurSel();
  661. if (iCurSel == CB_ERR)
  662. return CB_ERR;
  663. comboBox.GetLBText(iCurSel, csItemText);
  664. if (!csItemText.IsEmpty())
  665. {
  666. if (comboBox.SelectString(-1, csItemText) == CB_ERR)
  667. comboBox.SetWindowText(csItemText);
  668. return iCurSel;
  669. }
  670. return CB_ERR;
  671. }
  672. void CXTPSyntaxEditPropertiesPageFont::OnSelChangeComboNames()
  673. {
  674. if (!m_wndComboName.GetListBox().SelChanged())
  675. return;
  676. if (GetLBText(m_wndComboName, m_csName) == CB_ERR)
  677. return;
  678. LOGFONT lf = {0};
  679. if (!GetSafeLogFont(lf))
  680. return;
  681. STRCPY_S(lf.lfFaceName, m_csName.GetLength() + 1, m_csName);
  682. if (CreateSafeFontIndirect(m_editFont, lf))
  683. {
  684. UpdateSampleFont();
  685. InitSizeCombo();
  686. InitScriptCombo();
  687. SetModified(TRUE);
  688. }
  689. }
  690. void CXTPSyntaxEditPropertiesPageFont::OnSelChangeComboStyles()
  691. {
  692. if (!m_wndComboStyle.GetListBox().SelChanged())
  693. return;
  694. if (GetLBText(m_wndComboStyle, m_csStyle) == CB_ERR)
  695. return;
  696. LOGFONT lf = {0};
  697. if (!GetSafeLogFont(lf))
  698. return;
  699. CString csBuffer;
  700. XTPResourceManager()->LoadString(&csBuffer, XTP_IDS_EDIT_ITALIC);
  701. lf.lfItalic = (m_csStyle.Find(csBuffer) == -1)? (BYTE)FALSE: (BYTE)TRUE;
  702. XTPResourceManager()->LoadString(&csBuffer, XTP_IDS_EDIT_BOLD);
  703. lf.lfWeight = (m_csStyle.Find(csBuffer) == -1)? FW_NORMAL: FW_BOLD;
  704. if (CreateSafeFontIndirect(m_editFont, lf))
  705. {
  706. UpdateSampleFont();
  707. SetModified(TRUE);
  708. }
  709. }
  710. void CXTPSyntaxEditPropertiesPageFont::OnSelChangeComboSizes()
  711. {
  712. if (!m_wndComboSize.GetListBox().SelChanged())
  713. return;
  714. if (GetLBText(m_wndComboSize, m_csSize) == CB_ERR)
  715. return;
  716. LOGFONT lf = {0};
  717. if (!GetSafeLogFont(lf))
  718. return;
  719. CWindowDC dc(NULL);
  720. lf.lfHeight = -MulDiv(_ttoi(m_csSize),
  721. ::GetDeviceCaps(dc.m_hDC, LOGPIXELSY), 72);
  722. if (CreateSafeFontIndirect(m_editFont, lf))
  723. {
  724. UpdateSampleFont();
  725. SetModified(TRUE);
  726. }
  727. }
  728. void CXTPSyntaxEditPropertiesPageFont::OnChkStrikeOut()
  729. {
  730. UpdateData();
  731. LOGFONT lf = {0};
  732. if (!GetSafeLogFont(lf))
  733. return;
  734. lf.lfStrikeOut = (BYTE)m_bStrikeOut;
  735. if (CreateSafeFontIndirect(m_editFont, lf))
  736. {
  737. UpdateSampleFont();
  738. SetModified(TRUE);
  739. }
  740. }
  741. void CXTPSyntaxEditPropertiesPageFont::OnChkUnderline()
  742. {
  743. UpdateData();
  744. LOGFONT lf = {0};
  745. if (!GetSafeLogFont(lf))
  746. return;
  747. lf.lfUnderline = (BYTE)m_bUnderline;
  748. if (CreateSafeFontIndirect(m_editFont, lf))
  749. {
  750. UpdateSampleFont();
  751. SetModified(TRUE);
  752. }
  753. }
  754. void CXTPSyntaxEditPropertiesPageFont::OnSelEndOkScript()
  755. {
  756. if (!m_wndComboScript.GetListBox().SelChanged())
  757. return;
  758. UpdateData();
  759. int iCurSel = m_wndComboScript.GetCurSel();
  760. if (iCurSel == CB_ERR)
  761. return;
  762. LOGFONT lf = {0};
  763. if (!GetSafeLogFont(lf))
  764. return;
  765. lf.lfCharSet = (BYTE)m_wndComboScript.GetItemData(iCurSel);
  766. m_iCharSet = lf.lfCharSet;
  767. if (CreateSafeFontIndirect(m_editFont, lf))
  768. {
  769. UpdateSampleFont();
  770. SetModified(TRUE);
  771. UpdateData(FALSE);
  772. }
  773. }
  774. void CXTPSyntaxEditPropertiesPageFont::OnSelEndOkHiliteText()
  775. {
  776. UpdateData();
  777. UpdateSampleColors();
  778. SetModified(TRUE);
  779. }
  780. void CXTPSyntaxEditPropertiesPageFont::OnSelEndOkHiliteBack()
  781. {
  782. UpdateData();
  783. UpdateSampleColors();
  784. SetModified(TRUE);
  785. }
  786. void CXTPSyntaxEditPropertiesPageFont::OnSelEndOkText()
  787. {
  788. UpdateData();
  789. UpdateSampleColors();
  790. SetModified(TRUE);
  791. }
  792. void CXTPSyntaxEditPropertiesPageFont::OnSelEndOkBack()
  793. {
  794. UpdateData();
  795. UpdateSampleColors();
  796. SetModified(TRUE);
  797. }
  798. void CXTPSyntaxEditPropertiesPageFont::OnBtnCustomText()
  799. {
  800. if (m_wndComboText.SelectUserColor() != CB_ERR)
  801. {
  802. m_crText = m_wndComboText.GetSelColor();
  803. OnSelEndOkText();
  804. SetModified(TRUE);
  805. }
  806. }
  807. void CXTPSyntaxEditPropertiesPageFont::OnBtnCustomBack()
  808. {
  809. if (m_wndComboBack.SelectUserColor() != CB_ERR)
  810. {
  811. m_crBack = m_wndComboBack.GetSelColor();
  812. OnSelEndOkBack();
  813. SetModified(TRUE);
  814. }
  815. }
  816. void CXTPSyntaxEditPropertiesPageFont::OnBtnCustomHiliteText()
  817. {
  818. if (m_wndComboHiliteText.SelectUserColor() != CB_ERR)
  819. {
  820. m_crHiliteText = m_wndComboHiliteText.GetSelColor();
  821. OnSelEndOkHiliteText();
  822. SetModified(TRUE);
  823. }
  824. }
  825. void CXTPSyntaxEditPropertiesPageFont::OnBtnCustomtHiliteBack()
  826. {
  827. if (m_wndComboHiliteBack.SelectUserColor() != CB_ERR)
  828. {
  829. m_crHiliteBack = m_wndComboHiliteBack.GetSelColor();
  830. OnSelEndOkHiliteBack();
  831. SetModified(TRUE);
  832. }
  833. }
  834. BOOL CXTPSyntaxEditPropertiesPageFont::OnApply()
  835. {
  836. if (!CPropertyPage::OnApply())
  837. return FALSE;
  838. // no changes made or they have already been applied.
  839. if (!m_bModified)
  840. return TRUE;
  841. // update registry settings.
  842. if (!WriteRegistryValues())
  843. return FALSE;
  844. m_bModified = FALSE;
  845. return TRUE;
  846. }
  847. void CXTPSyntaxEditPropertiesPageFont::SetModified(BOOL bChanged/*=TRUE*/)
  848. {
  849. CPropertyPage::SetModified();
  850. m_bModified = bChanged;
  851. }
  852. //===========================================================================
  853. // CXTPSyntaxEditPropertiesPageColor property page
  854. //===========================================================================
  855. CXTPSyntaxEditPropertiesPageColor::CXTPSyntaxEditPropertiesPageColor(CXTPSyntaxEditView* pEditView/*=NULL*/)
  856. : //CPropertyPage(CXTPSyntaxEditPropertiesPageColor::IDD),
  857.   m_bModified(FALSE)
  858. , m_pEditView(pEditView)
  859. , m_parLexClassInfo(NULL)
  860. {
  861. m_psp.dwFlags |= PSP_DLGINDIRECT;
  862. m_psp.pResource = XTPResourceManager()->LoadDialogTemplate(IDD);
  863. //{{AFX_DATA_INIT(CXTPSyntaxEditPropertiesPageColor)
  864. m_bBold = FALSE;
  865. m_bItalic = FALSE;
  866. m_bUnderline = FALSE;
  867. //}}AFX_DATA_INIT
  868. SetDefaults();
  869. if (m_pEditView)
  870. {
  871. CXTPSyntaxEditConfigurationManager* ptrConfigMgr =
  872. m_pEditView->GetEditCtrl().GetLexConfigurationManager();
  873. if (ptrConfigMgr)
  874. {
  875. m_ptrConfigMgr.SetPtr(ptrConfigMgr, TRUE);
  876. m_pTextSchemesMgr = &m_ptrConfigMgr->GetTextSchemesManager();
  877. }
  878. }
  879. }
  880. CXTPSyntaxEditPropertiesPageColor::~CXTPSyntaxEditPropertiesPageColor()
  881. {
  882. XTPSyntaxEditLexConfig()->CleanInfoMap(m_mapLexClassInfo);
  883. }
  884. void CXTPSyntaxEditPropertiesPageColor::SetDefaults()
  885. {
  886. // reset color values.
  887. m_crText        = ::GetSysColor(COLOR_WINDOWTEXT);
  888. m_crBack        = ::GetSysColor(COLOR_WINDOW);
  889. m_crHiliteText  = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
  890. m_crHiliteBack  = ::GetSysColor(COLOR_HIGHLIGHT);
  891. // reset font attribute flags.
  892. m_bBold         = FALSE;
  893. m_bItalic       = FALSE;
  894. m_bUnderline    = FALSE;
  895. if (::IsWindow(m_hWnd))
  896. {
  897. UpdateData(FALSE);
  898. }
  899. }
  900. void CXTPSyntaxEditPropertiesPageColor::DoDataExchange(CDataExchange* pDX)
  901. {
  902. CPropertyPage::DoDataExchange(pDX);
  903. //{{AFX_DATA_MAP(CXTPSyntaxEditPropertiesPageColor)
  904. DDX_Check(pDX, XTP_IDC_EDIT_CHK_BOLD, m_bBold);
  905. DDX_Check(pDX, XTP_IDC_EDIT_CHK_ITALIC, m_bItalic);
  906. DDX_Check(pDX, XTP_IDC_EDIT_CHK_UNDERLINE, m_bUnderline);
  907. DDX_Control(pDX, XTP_IDC_EDIT_COMB_TEXT, m_wndComboText);
  908. DDX_Control(pDX, XTP_IDC_EDIT_COMB_BACK, m_wndComboBack);
  909. DDX_Control(pDX, XTP_IDC_EDIT_COMB_TEXTSEL, m_wndComboHiliteText);
  910. DDX_Control(pDX, XTP_IDC_EDIT_COMB_BACKSEL, m_wndComboHiliteBack);
  911. DDX_Control(pDX, XTP_IDC_EDIT_TXT_SAMPLE, m_txtSample);
  912. DDX_Control(pDX, XTP_IDC_EDIT_TXT_SAMPLESEL, m_txtSampleSel);
  913. DDX_Control(pDX, XTP_IDC_EDIT_LBOX_SCHEMANAMES, m_lboxName);
  914. DDX_Control(pDX, XTP_IDC_EDIT_LBOX_SCHEMAPROP, m_lboxProp);
  915. DDX_Control(pDX, XTP_IDC_EDIT_CHK_BOLD, m_btnBold);
  916. DDX_Control(pDX, XTP_IDC_EDIT_CHK_ITALIC, m_btnItalic);
  917. DDX_Control(pDX, XTP_IDC_EDIT_CHK_UNDERLINE, m_btnUnderline);
  918. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_TEXT, m_btnCustomText);
  919. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_BACK, m_btnCustomBack);
  920. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_TEXTSEL, m_btnCustomHiliteText);
  921. DDX_Control(pDX, XTP_IDC_EDIT_BTN_CUSTOM_BACKSEL, m_btnCustomHiliteBack);
  922. DDX_Control(pDX, XTP_IDC_EDIT_GRP_SAMPLE, m_gboxSampleText);
  923. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_TEXT, m_crText);
  924. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_BACK, m_crBack);
  925. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_TEXTSEL, m_crHiliteText);
  926. DDX_CBSyntaxColor(pDX, XTP_IDC_EDIT_COMB_BACKSEL, m_crHiliteBack);
  927. //}}AFX_DATA_MAP
  928. }
  929. IMPLEMENT_DYNCREATE(CXTPSyntaxEditPropertiesPageColor, CPropertyPage)
  930. BEGIN_MESSAGE_MAP(CXTPSyntaxEditPropertiesPageColor, CPropertyPage)
  931. //{{AFX_MSG_MAP(CXTPSyntaxEditPropertiesPageColor)
  932. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_BOLD, OnChkBold)
  933. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_ITALIC, OnChkItalic)
  934. ON_BN_CLICKED(XTP_IDC_EDIT_CHK_UNDERLINE, OnChkUnderline)
  935. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_TEXT, OnBtnCustomText)
  936. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_BACK, OnBtnCustomBack)
  937. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_TEXTSEL, OnBtnCustomHiliteText)
  938. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_CUSTOM_BACKSEL, OnBtnCustomtHiliteBack)
  939. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_TEXTSEL, OnSelEndOkHiliteText)
  940. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_BACKSEL, OnSelEndOkHiliteBack)
  941. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_TEXT, OnSelEndOkText)
  942. ON_CBN_SELENDOK(XTP_IDC_EDIT_COMB_BACK, OnSelEndOkBack)
  943. ON_LBN_SELCHANGE(XTP_IDC_EDIT_LBOX_SCHEMANAMES, OnSelChangeSchemaNames)
  944. ON_LBN_SELCHANGE(XTP_IDC_EDIT_LBOX_SCHEMAPROP, OnSelChangeSchemaProp)
  945. ON_LBN_DBLCLK(XTP_IDC_EDIT_LBOX_SCHEMANAMES, OnDblClickSchema)
  946. ON_WM_CONTEXTMENU()
  947. //}}AFX_MSG_MAP
  948. END_MESSAGE_MAP()
  949. void CXTPSyntaxEditPropertiesPageColor::UpdateSampleColors()
  950. {
  951. m_txtSampleSel.SetBackColor(m_crHiliteBack);
  952. m_txtSampleSel.SetTextColor(m_crHiliteText);
  953. m_txtSample.SetBackColor(m_crBack);
  954. m_txtSample.SetTextColor(m_crText);
  955. }
  956. BOOL CXTPSyntaxEditPropertiesPageColor::OnInitDialog()
  957. {
  958. CPropertyPage::OnInitDialog();
  959. // TODO:  Add extra initialization here
  960. m_wndComboHiliteBack.SetAutoColor(::GetSysColor(COLOR_HIGHLIGHT));
  961. m_wndComboHiliteText.SetAutoColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
  962. m_wndComboBack.SetAutoColor(::GetSysColor(COLOR_WINDOW));
  963. m_wndComboText.SetAutoColor(::GetSysColor(COLOR_WINDOWTEXT));
  964. if (m_wndComboBack.SetSelColor(m_crBack) == CB_ERR)
  965. {
  966. m_wndComboBack.SetUserColor(m_crBack);
  967. m_wndComboBack.SetSelColor(m_crBack);
  968. }
  969. if (m_wndComboText.SetSelColor(m_crText) == CB_ERR)
  970. {
  971. m_wndComboText.SetUserColor(m_crText);
  972. m_wndComboText.SetSelColor(m_crText);
  973. }
  974. if (m_wndComboHiliteBack.SetSelColor(m_crHiliteBack) == CB_ERR)
  975. {
  976. m_wndComboHiliteBack.SetUserColor(m_crHiliteBack);
  977. m_wndComboHiliteBack.SetSelColor(m_crHiliteBack);
  978. }
  979. if (m_wndComboHiliteText.SetSelColor(m_crHiliteText) == CB_ERR)
  980. {
  981. m_wndComboHiliteText.SetUserColor(m_crHiliteText);
  982. m_wndComboHiliteText.SetSelColor(m_crHiliteText);
  983. }
  984. XTPSyntaxEditLexConfig()->CopyInfoMap(m_mapLexClassInfo);
  985. // Get all schemes names
  986. CXTPSyntaxEditSchemaFileInfoList& infoList = m_pTextSchemesMgr->GetSchemaList();
  987. for (POSITION pos = infoList.GetHeadPosition(); pos;)
  988. {
  989. XTP_EDIT_SCHEMAFILEINFO& info = infoList.GetNext(pos);
  990. int iIndex = m_lboxName.AddString((info.csDesc.GetLength() > 0)? info.csDesc: info.csName);
  991. if (iIndex != LB_ERR)
  992. {
  993. m_lboxName.SetItemData(iIndex, (DWORD_PTR)&info);
  994. }
  995. }
  996. if (m_lboxName.GetCount() > 0)
  997. {
  998. m_lboxName.SetCurSel(0);
  999. OnSelChangeSchemaNames();
  1000. }
  1001. return TRUE;  // return TRUE unless you set the focus to a control
  1002. // EXCEPTION: OCX Property Pages should return FALSE
  1003. }
  1004. BOOL CXTPSyntaxEditPropertiesPageColor::WriteRegistryValues()
  1005. {
  1006. if (!::IsWindow(m_pEditView->GetSafeHwnd()))
  1007. return FALSE;
  1008. for (POSITION pos = m_mapLexClassInfo.GetStartPosition(); pos;)
  1009. {
  1010. CString csKey; CXTPSyntaxEditLexClassInfoArray* pLexClassArray = NULL;
  1011. m_mapLexClassInfo.GetNextAssoc(pos, csKey, (void*&)pLexClassArray);
  1012. XTPSyntaxEditLexConfig()->WriteCfgFile(csKey, *pLexClassArray);
  1013. }
  1014. return TRUE;
  1015. }
  1016. void CXTPSyntaxEditPropertiesPageColor::OnSelEndOkHiliteText()
  1017. {
  1018. UpdateData();
  1019. UpdateSampleColors();
  1020. SetModified(TRUE);
  1021. UpdateColorValue(m_wndComboHiliteText, m_crHiliteText, XTPLEX_ATTR_TXT_COLORSELFG);
  1022. }
  1023. void CXTPSyntaxEditPropertiesPageColor::OnSelEndOkHiliteBack()
  1024. {
  1025. UpdateData();
  1026. UpdateSampleColors();
  1027. SetModified(TRUE);
  1028. UpdateColorValue(m_wndComboHiliteBack, m_crHiliteBack, XTPLEX_ATTR_TXT_COLORSELBK);
  1029. }
  1030. void CXTPSyntaxEditPropertiesPageColor::OnSelEndOkText()
  1031. {
  1032. UpdateData();
  1033. UpdateSampleColors();
  1034. SetModified(TRUE);
  1035. UpdateColorValue(m_wndComboText, m_crText, XTPLEX_ATTR_TXT_COLORFG);
  1036. }
  1037. void CXTPSyntaxEditPropertiesPageColor::OnSelEndOkBack()
  1038. {
  1039. UpdateData();
  1040. UpdateSampleColors();
  1041. SetModified(TRUE);
  1042. UpdateColorValue(m_wndComboBack, m_crBack, XTPLEX_ATTR_TXT_COLORBK);
  1043. }
  1044. void CXTPSyntaxEditPropertiesPageColor::OnChkBold()
  1045. {
  1046. UpdateData();
  1047. UpdateFont();
  1048. SetModified(TRUE);
  1049. UpdateFontValue(m_bBold, XTPLEX_ATTR_TXT_BOLD);
  1050. }
  1051. void CXTPSyntaxEditPropertiesPageColor::OnChkItalic()
  1052. {
  1053. UpdateData();
  1054. UpdateFont();
  1055. SetModified(TRUE);
  1056. UpdateFontValue(m_bItalic, XTPLEX_ATTR_TXT_ITALIC);
  1057. }
  1058. void CXTPSyntaxEditPropertiesPageColor::OnChkUnderline()
  1059. {
  1060. UpdateData();
  1061. UpdateFont();
  1062. SetModified(TRUE);
  1063. UpdateFontValue(m_bUnderline, XTPLEX_ATTR_TXT_UNDERLINE);
  1064. }
  1065. void CXTPSyntaxEditPropertiesPageColor::OnBtnCustomText()
  1066. {
  1067. if (m_wndComboText.SelectUserColor() != CB_ERR)
  1068. {
  1069. m_crText = m_wndComboText.GetSelColor();
  1070. OnSelEndOkText();
  1071. }
  1072. }
  1073. void CXTPSyntaxEditPropertiesPageColor::OnBtnCustomBack()
  1074. {
  1075. if (m_wndComboBack.SelectUserColor() != CB_ERR)
  1076. {
  1077. m_crBack = m_wndComboBack.GetSelColor();
  1078. OnSelEndOkBack();
  1079. }
  1080. }
  1081. void CXTPSyntaxEditPropertiesPageColor::OnBtnCustomHiliteText()
  1082. {
  1083. if (m_wndComboHiliteText.SelectUserColor() != CB_ERR)
  1084. {
  1085. m_crHiliteText = m_wndComboHiliteText.GetSelColor();
  1086. OnSelEndOkHiliteText();
  1087. }
  1088. }
  1089. void CXTPSyntaxEditPropertiesPageColor::OnBtnCustomtHiliteBack()
  1090. {
  1091. if (m_wndComboHiliteBack.SelectUserColor() != CB_ERR)
  1092. {
  1093. m_crHiliteBack = m_wndComboHiliteBack.GetSelColor();
  1094. OnSelEndOkHiliteBack();
  1095. }
  1096. }
  1097. BOOL CXTPSyntaxEditPropertiesPageColor::OnSetActive()
  1098. {
  1099. UpdateFont();
  1100. return CPropertyPage::OnSetActive();
  1101. }
  1102. void CXTPSyntaxEditPropertiesPageColor::UpdateFont()
  1103. {
  1104. CXTPSyntaxEditPropertiesDlg* pParentDlg = DYNAMIC_DOWNCAST(
  1105. CXTPSyntaxEditPropertiesDlg, GetParent());
  1106. if (!pParentDlg)
  1107. return;
  1108. CXTPSyntaxEditPropertiesPageFont* pPage2 = DYNAMIC_DOWNCAST(
  1109. CXTPSyntaxEditPropertiesPageFont, pParentDlg->GetPage(1));
  1110. if (!pPage2)
  1111. return;
  1112. LOGFONT lf = {0};
  1113. if (!pPage2->GetSafeLogFont(lf))
  1114. return;
  1115. lf.lfStrikeOut = 0;
  1116. lf.lfItalic    = (BYTE)m_bItalic;
  1117. lf.lfUnderline = (BYTE)m_bUnderline;
  1118. lf.lfWeight    = m_bBold? FW_BOLD: FW_NORMAL;
  1119. if (pPage2->CreateSafeFontIndirect(m_editFont, lf))
  1120. {
  1121. m_txtSample.SetFont(&m_editFont);
  1122. m_txtSampleSel.SetFont(&m_editFont);
  1123. }
  1124. }
  1125. BOOL CXTPSyntaxEditPropertiesPageColor::OnApply()
  1126. {
  1127. if (!CPropertyPage::OnApply())
  1128. return FALSE;
  1129. // no changes made or they have already been applied.
  1130. if (!m_bModified)
  1131. return TRUE;
  1132. // update registry settings.
  1133. if (!WriteRegistryValues())
  1134. return FALSE;
  1135. m_bModified = FALSE;
  1136. return TRUE;
  1137. }
  1138. void CXTPSyntaxEditPropertiesPageColor::EnableControls()
  1139. {
  1140. BOOL bEnable = (m_lboxName.GetCurSel() != LB_ERR);
  1141. m_lboxProp.EnableWindow(bEnable);
  1142. bEnable = (bEnable && m_lboxProp.GetCurSel() != LB_ERR);
  1143. m_txtSampleSel.EnableWindow(bEnable);
  1144. m_txtSample.EnableWindow(bEnable);
  1145. m_gboxSampleText.EnableWindow(bEnable);
  1146. m_wndComboHiliteText.EnableWindow(bEnable);
  1147. m_wndComboHiliteBack.EnableWindow(bEnable);
  1148. m_wndComboText.EnableWindow(bEnable);
  1149. m_wndComboBack.EnableWindow(bEnable);
  1150. m_btnBold.EnableWindow(bEnable);
  1151. m_btnItalic.EnableWindow(bEnable);
  1152. m_btnUnderline.EnableWindow(bEnable);
  1153. m_btnCustomText.EnableWindow(bEnable);
  1154. m_btnCustomBack.EnableWindow(bEnable);
  1155. m_btnCustomHiliteText.EnableWindow(bEnable);
  1156. m_btnCustomHiliteBack.EnableWindow(bEnable);
  1157. }
  1158. void CXTPSyntaxEditPropertiesPageColor::OnSelChangeSchemaNames()
  1159. {
  1160. if (!m_lboxName.SelChanged())
  1161. return;
  1162. SetDefaults();
  1163. int iIndex = m_lboxName.GetCurSel();
  1164. if (iIndex != LB_ERR)
  1165. {
  1166. XTP_EDIT_SCHEMAFILEINFO* pSchemaInfo = (XTP_EDIT_SCHEMAFILEINFO*)m_lboxName.GetItemData(iIndex);
  1167. if (pSchemaInfo)
  1168. {
  1169. InitSchemaClasses(pSchemaInfo);
  1170. }
  1171. }
  1172. }
  1173. void CXTPSyntaxEditPropertiesPageColor::OnSelChangeSchemaProp()
  1174. {
  1175. if (!m_lboxProp.SelChanged())
  1176. return;
  1177. SetDefaults();
  1178. int iIndex = m_lboxProp.GetCurSel();
  1179. if (iIndex == LB_ERR)
  1180. return;
  1181. XTP_EDIT_LEXCLASSINFO* pInfoClass = (XTP_EDIT_LEXCLASSINFO*)m_lboxProp.GetItemData(iIndex);
  1182. if (!pInfoClass)
  1183. return;
  1184. InitClassData(*pInfoClass);
  1185. UpdateData(FALSE);
  1186. }
  1187. BOOL CXTPSyntaxEditPropertiesPageColor::IsTopLevelClass(const XTP_EDIT_LEXCLASSINFO& infoClass)
  1188. {
  1189. int nPropertiesCount = (int)infoClass.arPropertyDesc.GetSize();
  1190. for (int iIndex = 0; iIndex < nPropertiesCount; iIndex++)
  1191. {
  1192. // Process property name
  1193. const XTP_EDIT_LEXPROPINFO& infoProp =
  1194. infoClass.arPropertyDesc.GetAt(iIndex);
  1195. if (infoProp.arPropName.GetSize() != 2)
  1196. continue;
  1197. CString csParent = infoProp.arPropName.GetAt(0);
  1198. if (csParent.CompareNoCase(_T("parent")) != 0)
  1199. continue;
  1200. CString csFile = infoProp.arPropName.GetAt(1);
  1201. if (csFile.CompareNoCase(_T("file")) != 0)
  1202. continue;
  1203. return TRUE;
  1204. }
  1205. return FALSE;
  1206. }
  1207. CString CXTPSyntaxEditPropertiesPageColor::GetDisplayName(const XTP_EDIT_LEXCLASSINFO& info) const
  1208. {
  1209. for (int i = 0; i < info.arPropertyDesc.GetSize(); ++i)
  1210. {
  1211. if (MakeStr(info.arPropertyDesc[i].arPropName, _T(":")) == XTPLEX_ATTR_DISPLAYNAME)
  1212. {
  1213. CString csDisplayName = GetPropValue(info.arPropertyDesc[i]);
  1214. REMOVE_S(csDisplayName, 39);
  1215. return csDisplayName;
  1216. }
  1217. }
  1218. return info.csClassName;
  1219. }
  1220. BOOL CXTPSyntaxEditPropertiesPageColor::InitSchemaClasses(XTP_EDIT_SCHEMAFILEINFO* pSchemaInfo)
  1221. {
  1222. CString csKey = pSchemaInfo->csValue;
  1223. csKey.MakeLower();
  1224. m_parLexClassInfo = NULL;
  1225. if (!m_mapLexClassInfo.Lookup(csKey, (void*&)m_parLexClassInfo) || !m_parLexClassInfo)
  1226. return FALSE;
  1227. m_lboxProp.SetRedraw(FALSE);
  1228. m_lboxProp.ResetContent();
  1229. // For all classes in the current scheme
  1230. int iSize = (int)m_parLexClassInfo->GetSize();
  1231. for (int i = 0; i < iSize; i++)
  1232. {
  1233. int iIndex = m_lboxProp.AddString(GetDisplayName((*m_parLexClassInfo)[i]));
  1234. if (iIndex != LB_ERR)
  1235. m_lboxProp.SetItemData(iIndex, (DWORD_PTR)&(*m_parLexClassInfo)[i]);
  1236. }
  1237. m_lboxProp.SetCurSel(0);
  1238. OnSelChangeSchemaProp();
  1239. m_lboxProp.SetRedraw(TRUE);
  1240. m_lboxProp.RedrawWindow();
  1241. return TRUE;
  1242. }
  1243. CString CXTPSyntaxEditPropertiesPageColor::GetPropValue(const XTP_EDIT_LEXPROPINFO& infoProp) const
  1244. {
  1245. CString csValue;
  1246. for (int iItem = 0; iItem < infoProp.arPropValue.GetSize(); iItem++)
  1247. {
  1248. if (iItem > 0)
  1249. {
  1250. csValue += _T(", ");
  1251. }
  1252. CString strProp1 = infoProp.arPropValue.GetAt(iItem);
  1253. csValue += XTPSyntaxEditLexConfig()->ESToStr(strProp1, TRUE);
  1254. }
  1255. return csValue;
  1256. }
  1257. AFX_STATIC int AFX_CDECL AfxStrToInt(LPCTSTR pcszValue)
  1258. {
  1259. TCHAR* pCh = NULL;
  1260. return _tcstol(pcszValue, &pCh, 0);
  1261. }
  1262. AFX_STATIC DWORD AFX_CDECL AfxStrToRGB(LPCTSTR pcszValue)
  1263. {
  1264. return XTP_EDIT_RGB_INT2CLR(AfxStrToInt(pcszValue));
  1265. }
  1266. void CXTPSyntaxEditPropertiesPageColor::InitClassData(const XTP_EDIT_LEXCLASSINFO& infoClass)
  1267. {
  1268. int iCount = (int)infoClass.arPropertyDesc.GetSize();
  1269. for (int iIndex = 0; iIndex < iCount; ++iIndex)
  1270. {
  1271. const XTP_EDIT_LEXPROPINFO& infoProp = infoClass.arPropertyDesc.GetAt(iIndex);
  1272. CString csPropName = MakeStr(infoProp.arPropName, _T(":"));
  1273. if (csPropName == XTPLEX_ATTR_TXT_COLORFG)
  1274. {
  1275. m_crText = AfxStrToRGB(GetPropValue(infoProp));
  1276. }
  1277. else if (csPropName == XTPLEX_ATTR_TXT_COLORBK)
  1278. {
  1279. m_crBack = AfxStrToRGB(GetPropValue(infoProp));
  1280. }
  1281. else if (csPropName == XTPLEX_ATTR_TXT_COLORSELFG)
  1282. {
  1283. m_crHiliteText = AfxStrToRGB(GetPropValue(infoProp));
  1284. }
  1285. else if (csPropName == XTPLEX_ATTR_TXT_COLORSELBK)
  1286. {
  1287. m_crHiliteBack = AfxStrToRGB(GetPropValue(infoProp));
  1288. }
  1289. else if (csPropName == XTPLEX_ATTR_TXT_BOLD)
  1290. {
  1291. m_bBold = (BOOL)_ttoi(GetPropValue(infoProp));
  1292. }
  1293. else if (csPropName == XTPLEX_ATTR_TXT_ITALIC)
  1294. {
  1295. m_bItalic = (BOOL)_ttoi(GetPropValue(infoProp));
  1296. }
  1297. else if (csPropName == XTPLEX_ATTR_TXT_UNDERLINE)
  1298. {
  1299. m_bUnderline = (BOOL)_ttoi(GetPropValue(infoProp));
  1300. }
  1301. }
  1302. UpdateFont();
  1303. UpdateSampleColors();
  1304. EnableControls();
  1305. }
  1306. void CXTPSyntaxEditPropertiesPageColor::SetModified(BOOL bChanged/*=TRUE*/)
  1307. {
  1308. CPropertyPage::SetModified(bChanged);
  1309. m_bModified = bChanged;
  1310. if (m_parLexClassInfo)
  1311. m_parLexClassInfo->m_bModified = bChanged;
  1312. }
  1313. int CXTPSyntaxEditPropertiesPageColor::PropExists(CXTPSyntaxEditLexPropInfoArray& arrProp, LPCTSTR lpszPropName)
  1314. {
  1315. int iCount = (int)arrProp.GetSize();
  1316. for (int iIndex = 0; iIndex < iCount; ++iIndex)
  1317. {
  1318. const XTP_EDIT_LEXPROPINFO& infoProp = arrProp.GetAt(iIndex);
  1319. CString csPropName = MakeStr(infoProp.arPropName, _T(":"));
  1320. if (csPropName.CompareNoCase(lpszPropName) == 0)
  1321. {
  1322. return iIndex;
  1323. }
  1324. }
  1325. return -1;
  1326. }
  1327. BOOL CXTPSyntaxEditPropertiesPageColor::UpdateColorValue(CXTPSyntaxEditColorComboBox& combo, COLORREF& color, LPCTSTR lpszPropName)
  1328. {
  1329. int iSel = m_lboxProp.GetCurSel();
  1330. XTP_EDIT_LEXCLASSINFO* pInfoClass = (XTP_EDIT_LEXCLASSINFO*)m_lboxProp.GetItemData(iSel);
  1331. if (!pInfoClass)
  1332. return FALSE;
  1333. int iIndex = PropExists(pInfoClass->arPropertyDesc, lpszPropName);
  1334. // automatic color selected, remove from array.
  1335. if (combo.GetAutoColor() == color)
  1336. {
  1337. if (iIndex != -1)
  1338. {
  1339. pInfoClass->arPropertyDesc.RemoveAt(iIndex);
  1340. return TRUE;
  1341. }
  1342. }
  1343. else
  1344. {
  1345. CString csColor;
  1346. csColor.Format(_T("0x%06X"), XTP_EDIT_RGB_INT2CLR(color));
  1347. if (iIndex == -1)
  1348. {
  1349. XTP_EDIT_LEXPROPINFO infoProp;
  1350. infoProp.arPropValue.Add(csColor);
  1351. PropPathSplit(lpszPropName, infoProp.arPropName);
  1352. pInfoClass->arPropertyDesc.Add(infoProp);
  1353. }
  1354. else
  1355. {
  1356. XTP_EDIT_LEXPROPINFO& infoProp = pInfoClass->arPropertyDesc[iIndex];
  1357. infoProp.arPropValue.RemoveAll();
  1358. infoProp.arPropValue.Add(csColor);
  1359. }
  1360. return TRUE;
  1361. }
  1362. return FALSE;
  1363. }
  1364. BOOL CXTPSyntaxEditPropertiesPageColor::UpdateFontValue(BOOL& bValue, LPCTSTR lpszPropName)
  1365. {
  1366. CString csValue(_T("1"));
  1367. int iSel = m_lboxProp.GetCurSel();
  1368. XTP_EDIT_LEXCLASSINFO* pInfoClass = (XTP_EDIT_LEXCLASSINFO*)m_lboxProp.GetItemData(iSel);
  1369. if (!pInfoClass)
  1370. return FALSE;
  1371. int iIndex = PropExists(pInfoClass->arPropertyDesc, lpszPropName);
  1372. if (iIndex != -1)
  1373. {
  1374. pInfoClass->arPropertyDesc.RemoveAt(iIndex);
  1375. }
  1376. if (bValue == TRUE)
  1377. {
  1378. XTP_EDIT_LEXPROPINFO infoProp;
  1379. PropPathSplit(lpszPropName, infoProp.arPropName);
  1380. infoProp.arPropValue.Add(csValue);
  1381. pInfoClass->arPropertyDesc.Add(infoProp);
  1382. return TRUE;
  1383. }
  1384. return FALSE;
  1385. }
  1386. void CXTPSyntaxEditPropertiesPageColor::OnDblClickSchema()
  1387. {
  1388. int iIndex = m_lboxName.GetCurSel();
  1389. if (iIndex == LB_ERR)
  1390. return;
  1391. XTP_EDIT_SCHEMAFILEINFO* pSchemaInfo = (XTP_EDIT_SCHEMAFILEINFO*)m_lboxName.GetItemData(iIndex);
  1392. if (pSchemaInfo == NULL)
  1393. return;
  1394. if (!FILEEXISTS_S(pSchemaInfo->csValue))
  1395. return;
  1396. TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szFileName[_MAX_FNAME], szEx[_MAX_EXT];
  1397. SPLITPATH_S(pSchemaInfo->csValue, szDrive, szDir, szFileName, szEx);
  1398. CString csBuffer;
  1399. XTPResourceManager()->LoadString(
  1400. &csBuffer, XTP_IDS_EDIT_OPENSCHEMAMSG);
  1401. CString csMessage;
  1402. csMessage.Format(csBuffer, szFileName, szEx);
  1403. if (AfxMessageBox(csMessage, MB_ICONQUESTION | MB_YESNO) == IDYES)
  1404. {
  1405. // close the options dialog.
  1406. CPropertySheet* pWndParent = DYNAMIC_DOWNCAST(CPropertySheet, GetParent());
  1407. if (pWndParent)
  1408. pWndParent->EndDialog(IDCANCEL);
  1409. // open the document.
  1410. CWinApp* pWinApp = AfxGetApp();
  1411. if (pWinApp)
  1412. pWinApp->OpenDocumentFile(pSchemaInfo->csValue);
  1413. }
  1414. }
  1415. void CXTPSyntaxEditPropertiesPageColor::OnContextMenu(CWnd* pWnd, CPoint point)
  1416. {
  1417. UNREFERENCED_PARAMETER(pWnd);
  1418. int iItem = m_lboxName.HitTest(point);
  1419. if (iItem != LB_ERR)
  1420. {
  1421. m_lboxName.SetCurSel(iItem);
  1422. OnSelChangeSchemaNames();
  1423. CString csBuffer;
  1424. XTPResourceManager()->LoadString(
  1425. &csBuffer, XTP_IDS_EDIT_OPENSCHEMACMD);
  1426. CMenu menu;
  1427. menu.CreatePopupMenu();
  1428. menu.AppendMenu(MF_STRING, ID_FILE_OPEN, csBuffer);
  1429. UINT nFlags = TPM_LEFTALIGN|TPM_RIGHTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD;
  1430. if (menu.TrackPopupMenu(nFlags, point.x, point.y, this) == ID_FILE_OPEN)
  1431. {
  1432. OnDblClickSchema();
  1433. }
  1434. }
  1435. }
  1436. //===========================================================================
  1437. // CXTPSyntaxEditTipWnd
  1438. //===========================================================================
  1439. CXTPSyntaxEditTipWnd::CXTPSyntaxEditTipWnd()
  1440. : m_pListBox(NULL)
  1441. , m_iIndex(LB_ERR)
  1442. , m_uIDEvent1(1001)
  1443. , m_uIDEvent2(1002)
  1444. {
  1445. RegisterWindowClass();
  1446. }
  1447. CXTPSyntaxEditTipWnd::~CXTPSyntaxEditTipWnd()
  1448. {
  1449. DestroyWindow();
  1450. }
  1451. BEGIN_MESSAGE_MAP(CXTPSyntaxEditTipWnd, CWnd)
  1452. //{{AFX_MSG_MAP(CXTPSyntaxEditTipWnd)
  1453. ON_WM_PAINT()
  1454. ON_WM_TIMER()
  1455. ON_WM_NCHITTEST_EX()
  1456. ON_WM_NCPAINT()
  1457. //}}AFX_MSG_MAP
  1458. END_MESSAGE_MAP()
  1459. //---------------------------------------------------------------------------
  1460. // CXTPSyntaxEditTipWnd diagnostics
  1461. //---------------------------------------------------------------------------
  1462. #ifdef _DEBUG
  1463. void CXTPSyntaxEditTipWnd::AssertValid() const
  1464. {
  1465. CWnd::AssertValid();
  1466. ASSERT(::IsWindow(m_hWnd));
  1467. ASSERT_VALID(m_pListBox);
  1468. }
  1469. void CXTPSyntaxEditTipWnd::Dump(CDumpContext& dc) const
  1470. {
  1471. CWnd::Dump(dc);
  1472. }
  1473. #endif //_DEBUG
  1474. //---------------------------------------------------------------------------
  1475. // CXTPSyntaxEditTipWnd registration
  1476. //---------------------------------------------------------------------------
  1477. BOOL CXTPSyntaxEditTipWnd::RegisterWindowClass(HINSTANCE hInstance /*= NULL*/)
  1478. {
  1479. WNDCLASS wndcls;
  1480. if (hInstance == NULL) hInstance = AfxGetInstanceHandle();
  1481. if (!(::GetClassInfo(hInstance, XTP_EDIT_CLASSNAME_LBOXTIP, &wndcls)))
  1482. {
  1483. // otherwise we need to register a new class
  1484. wndcls.style = CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW;
  1485. wndcls.lpfnWndProc = ::DefWindowProc;
  1486. wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
  1487. wndcls.hInstance = hInstance;
  1488. wndcls.hIcon = NULL;
  1489. wndcls.hCursor = ::LoadCursor(0, IDC_ARROW);
  1490. wndcls.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1);
  1491. wndcls.lpszMenuName = NULL;
  1492. wndcls.lpszClassName = XTP_EDIT_CLASSNAME_LBOXTIP;
  1493. if (!AfxRegisterClass(&wndcls))
  1494. {
  1495. AfxThrowResourceException();
  1496. return FALSE;
  1497. }
  1498. }
  1499. return TRUE;
  1500. }
  1501. //---------------------------------------------------------------------------
  1502. // CXTPSyntaxEditTipWnd paint routines
  1503. //---------------------------------------------------------------------------
  1504. BOOL CXTPSyntaxEditTipWnd::OwnerDrawTip(CDC* pDC, CRect rClient)
  1505. {
  1506. ASSERT_VALID(this);
  1507. HWND hWndLBox = m_pListBox->GetSafeHwnd();
  1508. if (!::IsWindow(hWndLBox))
  1509. return FALSE;
  1510. DRAWITEMSTRUCT dis;
  1511. ::ZeroMemory(&dis, sizeof(DRAWITEMSTRUCT));
  1512. dis.CtlType     = ODT_LISTBOX;
  1513. dis.CtlID       = (UINT)m_pListBox->GetDlgCtrlID();
  1514. dis.itemID      = (UINT)m_iIndex;
  1515. dis.itemAction  = ODA_DRAWENTIRE;
  1516. dis.hwndItem    = hWndLBox;
  1517. dis.hDC         = pDC->GetSafeHdc();
  1518. dis.rcItem      = rClient;
  1519. dis.itemData    = m_pListBox->GetItemData(m_iIndex);
  1520. if (m_pListBox->GetSel(m_iIndex) > 0)
  1521. dis.itemState |= ODS_SELECTED;
  1522. if (m_pListBox->GetCaretIndex() == m_iIndex)
  1523. dis.itemState |= ODS_FOCUS;
  1524. m_pListBox->DrawItem(&dis);
  1525. return TRUE;
  1526. }
  1527. BOOL CXTPSyntaxEditTipWnd::DrawTip(CDC* pDC, CRect rClient)
  1528. {
  1529. ASSERT_VALID(this);
  1530. CString csItemText;
  1531. m_pListBox->GetText(m_iIndex, csItemText);
  1532. CXTPFontDC fontDC(pDC, m_pListBox->GetFont(), GetTextColor());
  1533. pDC->SetBkColor(GetBackColor());
  1534. pDC->FillSolidRect(rClient, pDC->GetBkColor());
  1535. pDC->SetBkMode(TRANSPARENT);
  1536. pDC->DrawText(csItemText, rClient,
  1537. DT_VCENTER | DT_CENTER |DT_SINGLELINE | DT_NOPREFIX | DT_EXPANDTABS);
  1538. return TRUE;
  1539. }
  1540. COLORREF CXTPSyntaxEditTipWnd::GetTextColor() const
  1541. {
  1542. ASSERT_VALID(this);
  1543. return ::GetSysColor((m_pListBox->GetSel(m_iIndex) > 0)?
  1544. COLOR_HIGHLIGHTTEXT: COLOR_INFOTEXT);
  1545. }
  1546. COLORREF CXTPSyntaxEditTipWnd::GetBackColor() const
  1547. {
  1548. ASSERT_VALID(this);
  1549. return ::GetSysColor((m_pListBox->GetSel(m_iIndex) > 0)?
  1550. COLOR_HIGHLIGHT: COLOR_INFOBK);
  1551. }
  1552. void CXTPSyntaxEditTipWnd::OnPaint()
  1553. {
  1554. CPaintDC dc(this); // device context for painting
  1555. CXTPClientRect rClient(this);
  1556. if (IsOwnerDrawn())
  1557. OwnerDrawTip(&dc, rClient);
  1558. else
  1559. DrawTip(&dc, rClient);
  1560. }
  1561. void CXTPSyntaxEditTipWnd::OnNcPaint()
  1562. {
  1563. CXTPWindowRect rc(this);
  1564. rc.OffsetRect(-rc.TopLeft());
  1565. CWindowDC dc(this);
  1566. dc.SetBkColor(GetBackColor());
  1567. dc.SetTextColor(GetTextColor());
  1568. dc.FillSolidRect(&rc, dc.GetBkColor());
  1569. dc.DrawFocusRect(&rc);
  1570. }
  1571. //---------------------------------------------------------------------------
  1572. // CXTPSyntaxEditTipWnd message handlers
  1573. //---------------------------------------------------------------------------
  1574. void CXTPSyntaxEditTipWnd::OnTimer(UINT_PTR nIDEvent)
  1575. {
  1576. ASSERT_VALID(this);
  1577. if (nIDEvent == m_uIDEvent1)
  1578. {
  1579. HideTip();
  1580. }
  1581. if (nIDEvent == m_uIDEvent2)
  1582. {
  1583. CPoint point;
  1584. ::GetCursorPos(&point);
  1585. ScreenToClient(&point);
  1586. BOOL bOutside = FALSE;
  1587. m_pListBox->ItemFromPoint(point, bOutside);
  1588. if (bOutside)
  1589. {
  1590. HideTip();
  1591. }
  1592. }
  1593. CWnd::OnTimer(nIDEvent);
  1594. }
  1595. LRESULT CXTPSyntaxEditTipWnd::OnNcHitTest(CPoint point)
  1596. {
  1597. UNREFERENCED_PARAMETER(point);
  1598. return (LRESULT)HTTRANSPARENT;
  1599. }
  1600. BOOL CXTPSyntaxEditTipWnd::Create(CListBox* pListBox)
  1601. {
  1602. ASSERT_VALID(pListBox);
  1603. m_pListBox = pListBox;
  1604. if (!::IsWindow(m_pListBox->GetSafeHwnd()))
  1605. return FALSE;
  1606. // Already created?
  1607. if (::IsWindow(m_hWnd))
  1608. return TRUE;
  1609. if (!CWnd::CreateEx(WS_EX_TOOLWINDOW, XTP_EDIT_CLASSNAME_LBOXTIP, NULL,
  1610. WS_POPUP | WS_BORDER | WS_CLIPSIBLINGS, CXTPEmptyRect(), NULL, 0))
  1611. {
  1612. TRACE0("Failed to create tooltip window.n");
  1613. return FALSE;
  1614. }
  1615. return TRUE;
  1616. }
  1617. BOOL CXTPSyntaxEditTipWnd::IsOwnerDrawn()
  1618. {
  1619. ASSERT_VALID(this);
  1620. HWND hWndLBox = m_pListBox->GetSafeHwnd();
  1621. if (::IsWindow(hWndLBox))
  1622. {
  1623. return ((::GetWindowLong(hWndLBox, GWL_STYLE) &
  1624. (LBS_OWNERDRAWFIXED|LBS_OWNERDRAWVARIABLE)) != 0);
  1625. }
  1626. return FALSE;
  1627. }
  1628. BOOL CXTPSyntaxEditTipWnd::ShowTip(int iIndex)
  1629. {
  1630. ASSERT_VALID(this);
  1631. if ((iIndex < 0) || (iIndex >= m_pListBox->GetCount()))
  1632. return HideTip();
  1633. CPoint ptCursor;
  1634. ::GetCursorPos(&ptCursor);
  1635. if (m_iIndex == iIndex)
  1636. {
  1637. if (ptCursor == m_ptCursor)
  1638. {
  1639. RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
  1640. return TRUE;
  1641. }
  1642. }
  1643. m_ptCursor = ptCursor;
  1644. // stop existing timer.
  1645. KillTipTimer();
  1646. CRect rItem;
  1647. if (CalcItemRect(iIndex, rItem))
  1648. {
  1649. if ((m_rWindow == rItem) || m_rWindow.IsRectEmpty())
  1650. return HideTip();
  1651. m_rWindow.InflateRect(0,2);
  1652. if (m_iIndex != iIndex)
  1653. {
  1654. m_iIndex = iIndex;
  1655. RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
  1656. }
  1657. ShowWindow(SW_SHOWNA);
  1658. MoveWindow(&m_rWindow);
  1659. // set timer.
  1660. SetTipTimer();
  1661. return TRUE;
  1662. }
  1663. return FALSE;
  1664. }
  1665. BOOL CXTPSyntaxEditTipWnd::HideTip()
  1666. {
  1667. if (::IsWindowVisible(m_hWnd))
  1668. {
  1669. // stop existing timer.
  1670. KillTipTimer();
  1671. ShowWindow(SW_HIDE);
  1672. return TRUE;
  1673. }
  1674. return FALSE;
  1675. }
  1676. BOOL CXTPSyntaxEditTipWnd::CalcItemRect(int iItem, CRect& rItem)
  1677. {
  1678. ASSERT_VALID(this);
  1679. if (m_pListBox->GetItemRect(iItem, &rItem) == LB_ERR)
  1680. return FALSE;
  1681. if (IsOwnerDrawn())
  1682. return FALSE;
  1683. CString csItem;
  1684. m_pListBox->GetText(iItem, csItem);
  1685. m_pListBox->ClientToScreen(rItem);
  1686. if (csItem.IsEmpty())
  1687. return FALSE;
  1688. CWindowDC dc(NULL);
  1689. CXTPFontDC fontDC(&dc, m_pListBox->GetFont());
  1690. int iAdjust = dc.GetTextExtent(csItem).cx + (::GetSystemMetrics(SM_CXEDGE)*2);
  1691. m_rWindow.CopyRect(rItem);
  1692. m_rWindow.right = max(rItem.right, rItem.left + iAdjust);
  1693. return TRUE;
  1694. }
  1695. void CXTPSyntaxEditTipWnd::SetTipTimer()
  1696. {
  1697. SetTimer(m_uIDEvent1, 5000, NULL); // 5 seconds.
  1698. SetTimer(m_uIDEvent2, 100,  NULL); // 10th of a second.
  1699. }
  1700. void CXTPSyntaxEditTipWnd::KillTipTimer()
  1701. {
  1702. // stop existing timers.
  1703. KillTimer(m_uIDEvent1);
  1704. KillTimer(m_uIDEvent2);
  1705. }
  1706. //===========================================================================
  1707. // CXTPSyntaxEditTipListBox
  1708. //===========================================================================
  1709. CXTPSyntaxEditTipListBox::CXTPSyntaxEditTipListBox()
  1710. {
  1711. m_dwIdx = (DWORD)MAKELONG(-1,-2);
  1712. }
  1713. int CXTPSyntaxEditTipListBox::HitTest(LPPOINT pPoint /*= NULL*/) const
  1714. {
  1715. CPoint point;
  1716. if (pPoint == NULL)
  1717. {
  1718. ::GetCursorPos(&point);
  1719. ScreenToClient(&point);
  1720. pPoint = &point;
  1721. }
  1722. BOOL bOutside;
  1723. int iIndex = (int)ItemFromPoint(*pPoint, bOutside);
  1724. if (bOutside)
  1725. return LB_ERR;
  1726. return iIndex;
  1727. }
  1728. int CXTPSyntaxEditTipListBox::HitTest(CPoint point, BOOL bIsClient /*= FALSE*/) const
  1729. {
  1730. if (!bIsClient)
  1731. ScreenToClient(&point);
  1732. return HitTest(&point);
  1733. }
  1734. int CXTPSyntaxEditTipListBox::ShowTip(CPoint point, BOOL bIsClient /*= FALSE*/)
  1735. {
  1736. if (!bIsClient)
  1737. ScreenToClient(&point);
  1738. if (!::IsWindow(m_wndInfoTip.m_hWnd))
  1739. m_wndInfoTip.Create(this);
  1740. int iIndex = HitTest(&point);
  1741. if (iIndex != LB_ERR)
  1742. {
  1743. m_wndInfoTip.ShowTip(iIndex);
  1744. }
  1745. return iIndex;
  1746. }
  1747. BOOL CXTPSyntaxEditTipListBox::SelChanged() const
  1748. {
  1749. return (LOWORD(m_dwIdx) != HIWORD(m_dwIdx));
  1750. }
  1751. BOOL CXTPSyntaxEditTipListBox::PreTranslateMessage(MSG* pMsg)
  1752. {
  1753. UINT uMessage = pMsg->message;
  1754. switch (uMessage)
  1755. {
  1756. case WM_MOUSEMOVE:
  1757. ShowTip(pMsg->pt);
  1758. break;
  1759. case WM_LBUTTONDOWN:
  1760. m_dwIdx = (DWORD)MAKELONG(GetCurSel(), HIWORD(m_dwIdx));
  1761. ShowTip(pMsg->pt);
  1762. break;
  1763. case WM_LBUTTONUP:
  1764. m_dwIdx = (DWORD)MAKELONG(LOWORD(m_dwIdx), GetCurSel());
  1765. break;
  1766. case WM_KEYDOWN:
  1767. case WM_MOUSEWHEEL:
  1768. m_wndInfoTip.HideTip();
  1769. break;
  1770. }
  1771. return CListBox::PreTranslateMessage(pMsg);
  1772. }
  1773. //===========================================================================
  1774. // CXTPSyntaxEditTipComboBox
  1775. //===========================================================================
  1776. BEGIN_MESSAGE_MAP(CXTPSyntaxEditTipComboBox, CComboBox)
  1777. //{{AFX_MSG_MAP(CXTPSyntaxEditTipComboBox)
  1778. ON_WM_CTLCOLOR()
  1779. ON_WM_DESTROY()
  1780. //}}AFX_MSG_MAP
  1781. END_MESSAGE_MAP()
  1782. HBRUSH CXTPSyntaxEditTipComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  1783. {
  1784. if (nCtlColor == CTLCOLOR_LISTBOX)
  1785. {
  1786. if (m_wndListBox.GetSafeHwnd() == NULL)
  1787. m_wndListBox.SubclassWindow(pWnd->GetSafeHwnd());
  1788. }
  1789. HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
  1790. return hbr;
  1791. }
  1792. void CXTPSyntaxEditTipComboBox::OnDestroy()
  1793. {
  1794. if (m_wndListBox.GetSafeHwnd() != NULL)
  1795. m_wndListBox.UnsubclassWindow();
  1796. CComboBox::OnDestroy();
  1797. }