Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2276 lines
67 KiB

  1. /******************************************************************************/
  2. /* Tfont.CPP: IMPLEMENTATION OF THE CTfont CLASS which encapsulates the */
  3. /* CTfondDlg and CTfontTbar classes */
  4. /* */
  5. /******************************************************************************/
  6. /* */
  7. /* Methods in this file */
  8. /* */
  9. /* TextFont Object */
  10. /* CTfont::CTfont */
  11. /* CTfont::CTfont */
  12. /* CTfont::~CTfont */
  13. /* CTfont::EmptyMap */
  14. /* CTfont::FreeMemoryFromCBox */
  15. /* */
  16. /* Miscellaneous Methods */
  17. /* CTfont::Create */
  18. /* CTfont::Undo */
  19. /* CTfont::RefreshToolBar */
  20. /* CTfont::ResizeWindow */
  21. /* CTfont::DrawItem */
  22. /* CTfont::SetColorsInDC */
  23. /* CTfont::SaveToIniFile */
  24. /* CTfont::RestoreFontAttrsFromIniFile */
  25. /* CTfont::ReadFromIniFile */
  26. /* */
  27. /* Font/Size enumeration methods */
  28. /* CTfont::RefreshFontList */
  29. /* CTfont::EnumFontFace */
  30. /* CTfont::EnumFontFaceProc */
  31. /* CTfont::EnumFontSizes */
  32. /* CTfont::EnumFontOneFaceProc */
  33. /* */
  34. /* Combo Box Notification and processing methods */
  35. /* CTfont::ProcessNewTypeface */
  36. /* CTfont::UpdateEditControlFont */
  37. /* CTfont::OnTypeFaceComboBoxUpdate */
  38. /* CTfont::OnPointSizeComboBoxUpdate */
  39. /* CTfont::OnTypefaceChange */
  40. /* CTfont::OnPointSizeChange */
  41. /* CTfont::OnRButtonDown */
  42. /* */
  43. /* */
  44. /* Control Notification/Window Messages */
  45. /* CTfont::OnMove */
  46. /* CTfont::OnClose */
  47. /* CTfont::OnSetFocus */
  48. /* CTfont::OnDestroy */
  49. /* CTfont::OnBold */
  50. /* CTfont::OnItalic */
  51. /* CTfont::OnUnderline */
  52. /* CTfont::OnShadow */
  53. /* CTfont::OnPen */
  54. /* CTfont::OnEditText */
  55. /* CTfont::OnKeyboard */
  56. /* CTfont::OnInsSpace */
  57. /* CTfont::OnBackSpace */
  58. /* CTfont::OnNewLine */
  59. /* CTfont::OnDrawItem */
  60. /* CTfont::OnMeasureItem */
  61. /* */
  62. /******************************************************************************/
  63. /* */
  64. /* Tool Bar Object */
  65. /* CTfontTbar::CTfontTbar */
  66. /* CTfontTbar::Create */
  67. /* CTfontTbar::~CTfontTbar */
  68. /* */
  69. /******************************************************************************/
  70. /* */
  71. /* Dialog Bar Object */
  72. /* TfontDlg::CTfontDlg(void) */
  73. /* TfontDlg::Create(CWnd* pcParentWnd) */
  74. /* TfontDlg::~CTfontDlg(void) */
  75. /* TfontDlg::OnRButtonDown */
  76. /* */
  77. /* */
  78. /******************************************************************************/
  79. #include "stdafx.h"
  80. #include <memory.h>
  81. #include <tchar.h>
  82. #include "global.h"
  83. #include "pbrush.h"
  84. #include "pbrusfrm.h"
  85. #include "pbrusvw.h"
  86. #include "pictures.h"
  87. #include "resource.h"
  88. #include "minifwnd.h"
  89. #include "Tfont.h"
  90. #include "Tedit.h"
  91. #ifndef NT
  92. #include <penwin.h> // soe we can bring up the lens from the toolbar
  93. #endif
  94. #ifdef _DEBUG
  95. #undef THIS_FILE
  96. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  97. #endif
  98. IMPLEMENT_DYNCREATE( CTfont, CMiniFrmWnd )
  99. IMPLEMENT_DYNCREATE( CTfontTbar, CToolBar )
  100. IMPLEMENT_DYNCREATE( CTfontDlg, CDialogBar )
  101. #include "memtrace.h"
  102. UINT CTBitmaps[] = {FONT_TT_BMP, FONT_PRN_BMP, TT_OPENTYPE_BMP, PS_OPENTYPE_BMP, TYPE1_BMP};
  103. /******************************************************************************/
  104. class CCharSetDesc
  105. {
  106. public:
  107. CCharSetDesc(LPCTSTR lpszScript, BYTE nCharSet);
  108. CString m_strScript;
  109. BYTE m_nCharSet;
  110. CCharSetDesc *m_pNext;
  111. };
  112. CCharSetDesc::CCharSetDesc(LPCTSTR lpszScript, BYTE nCharSet)
  113. {
  114. m_strScript = lpszScript;
  115. m_nCharSet = nCharSet;
  116. m_pNext = NULL;
  117. }
  118. /******************************************************************************/
  119. class CFontDesc
  120. {
  121. public:
  122. CFontDesc(LPCTSTR lpszName, LPCTSTR lpszScript, BYTE nCharSet, int iFontType);
  123. ~CFontDesc();
  124. CString m_strName;
  125. CCharSetDesc m_CharSetDesc;
  126. int m_iFontType;
  127. };
  128. CFontDesc::CFontDesc(LPCTSTR lpszName, LPCTSTR lpszScript, BYTE nCharSet, int iFontType)
  129. : m_CharSetDesc(lpszScript, nCharSet)
  130. {
  131. m_strName = lpszName;
  132. m_iFontType = iFontType;
  133. }
  134. CFontDesc::~CFontDesc()
  135. {
  136. // delete the charset list entries
  137. CCharSetDesc *pCharSetDesc = m_CharSetDesc.m_pNext;
  138. while (pCharSetDesc)
  139. {
  140. CCharSetDesc *pTemp = pCharSetDesc;
  141. pCharSetDesc = pCharSetDesc->m_pNext;
  142. delete pTemp;
  143. }
  144. }
  145. /******************************************************************************/
  146. class CFontComboBox : public CComboBox
  147. {
  148. public:
  149. int AddFontName(LPCTSTR lpszName, LPCTSTR lpszScript, BYTE nCharSet,
  150. int iFontType);
  151. CFontDesc* GetFontDesc(int nIndex) {return (CFontDesc*)GetItemData(nIndex);};
  152. BOOL IsSameName(CFontDesc* pDesc, int index);
  153. // I'm not really doing the message map stuff
  154. void ClearList();
  155. } ;
  156. /******************************************************************************/
  157. class CCharSetComboBox : public CComboBox
  158. {
  159. public:
  160. int AddCharSet(LPCTSTR lpszScript, BYTE nCharSet);
  161. int SelectCharSet(int nStartAfter, BYTE nCharSet);
  162. int GetCurSelCharSet();
  163. } ;
  164. /******************************************************************************/
  165. //
  166. // HACKHACK: All this history stuff is to help make choosing a script for
  167. // a font easier. There doesn't seem to be anyway to get a "good" script
  168. // for a given font/locale so what we do is save the last serveral scripts
  169. // and hope that the font the user just switched to supports one of them.
  170. //
  171. class CHistoryList
  172. {
  173. public:
  174. CHistoryList();
  175. void AddHead(int nNewItem);
  176. int GetAt (unsigned int uIndex);
  177. enum { m_uHistorySize = 4 };
  178. private:
  179. unsigned int m_uHistoryIndex;
  180. int m_HistoryList[m_uHistorySize];
  181. };
  182. CHistoryList::CHistoryList()
  183. {
  184. m_uHistoryIndex = 0;
  185. for (int i = 0; i < m_uHistorySize; ++i)
  186. {
  187. m_HistoryList[i] = -1;
  188. }
  189. }
  190. void CHistoryList::AddHead(int nNewItem)
  191. {
  192. m_HistoryList[(++m_uHistoryIndex) % m_uHistorySize] = nNewItem;
  193. }
  194. int CHistoryList::GetAt(unsigned int uIndex)
  195. {
  196. ASSERT((int)uIndex >= 0 && uIndex < m_uHistorySize);
  197. return m_HistoryList[(m_uHistoryIndex-uIndex) % m_uHistorySize];
  198. }
  199. static CHistoryList g_CharSetHistoryList;
  200. /******************************************************************************/
  201. // CTfont
  202. BEGIN_MESSAGE_MAP( CTfont, CMiniFrmWnd )
  203. //{{AFX_MSG_MAP(CTfont)
  204. ON_CBN_SELCHANGE(IDC_TYPEFACE, OnTypefaceChange)
  205. ON_CBN_SELCHANGE(IDC_POINTSIZE, OnPointSizeChange)
  206. ON_CBN_KILLFOCUS(IDC_POINTSIZE, OnPointSizeChange)
  207. ON_COMMAND(IDOK, OnPointSizeChange)
  208. ON_CBN_SELCHANGE(IDC_CHARSET, OnTypefaceChange)
  209. ON_WM_ERASEBKGND()
  210. ON_WM_SETFOCUS()
  211. ON_WM_DESTROY()
  212. ON_WM_MOVE()
  213. ON_WM_CLOSE()
  214. ON_WM_RBUTTONDOWN()
  215. ON_WM_LBUTTONDOWN()
  216. ON_WM_LBUTTONUP()
  217. ON_COMMAND(IDC_BOLD, OnBold)
  218. ON_COMMAND(IDC_ITALIC, OnItalic)
  219. ON_COMMAND(IDC_UNDERLINE, OnUnderline)
  220. ON_COMMAND(IDC_VERTEDIT, OnVertEdit)
  221. ON_UPDATE_COMMAND_UI(IDC_VERTEDIT, OnVertEditUpdate)
  222. ON_COMMAND(IDC_SHADOW, OnShadow)
  223. ON_COMMAND(IDC_PENEXT, OnPen)
  224. ON_COMMAND(IDC_EDITTEXT, OnEditText)
  225. ON_COMMAND(IDC_KEYBOARD, OnKeyboard)
  226. ON_COMMAND(IDC_INS_SPACE, OnInsSpace)
  227. ON_COMMAND(IDC_BACKSPACE, OnBackSpace)
  228. ON_COMMAND(IDC_NEWLINE, OnNewLine)
  229. //}}AFX_MSG_MAP
  230. ON_MESSAGE(UM_DELAYED_TOOLBAR, OnDelayedPen)
  231. END_MESSAGE_MAP()
  232. /******************************************************************************/
  233. // CTfont construction/destruction
  234. CTfont::CTfont( CTedit *pcTedit )
  235. {
  236. ASSERT( pcTedit != NULL );
  237. m_pcTedit = pcTedit;
  238. m_cStrTypeFaceName.Empty();
  239. m_cStrTypeFaceNamePrev.Empty();
  240. m_nCharSet = DEFAULT_CHARSET;
  241. m_nCharSetPrev = DEFAULT_CHARSET;
  242. m_iWeight = FW_NORMAL;
  243. m_bBoldOn = FALSE;
  244. m_bItalicOn = FALSE;
  245. m_bUnderlineOn = FALSE;
  246. m_bVertEditOn = FALSE;
  247. m_bShadowOn = FALSE;
  248. m_bPenOn = FALSE;
  249. m_bInUpdate = FALSE;
  250. m_iControlIDLastChange = 0;
  251. m_iPointSize = 0;
  252. m_iPointSizePrev = 0;
  253. m_iFontType = 0;
  254. m_cRectWindow.SetRectEmpty();
  255. m_pcTfontTbar = new CTfontTbar();
  256. }
  257. /******************************************************************************/
  258. CTfont::CTfont()
  259. {
  260. m_cStrTypeFaceName.Empty();
  261. m_cStrTypeFaceNamePrev.Empty();
  262. m_nCharSet = DEFAULT_CHARSET;
  263. m_nCharSetPrev = DEFAULT_CHARSET;
  264. m_iWeight = FW_NORMAL;
  265. m_bBoldOn = FALSE;
  266. m_bItalicOn = FALSE;
  267. m_bUnderlineOn = FALSE;
  268. m_bVertEditOn = FALSE;
  269. m_bShadowOn = FALSE;
  270. m_bPenOn = FALSE;
  271. m_bInUpdate = FALSE;
  272. m_iControlIDLastChange = 0;
  273. m_iPointSize = 0;
  274. m_iPointSizePrev = 0;
  275. m_iFontType = 0;
  276. m_cRectWindow.SetRectEmpty();
  277. m_pcTfontTbar = new CTfontTbar();
  278. }
  279. /******************************************************************************/
  280. // CTfont construction/destruction
  281. CTfont::~CTfont(void)
  282. {
  283. SaveToIniFile();
  284. // *DK* this deletion of the current font assumes this object, the font picker,
  285. // is going away at the same time the edit control is going away, since this
  286. // current font is selected into the edit control.
  287. m_cCurrentFont.DeleteObject();
  288. if (m_pcTedit)
  289. {
  290. m_pcTedit->m_pcTfont = NULL;
  291. m_pcTedit = NULL;
  292. }
  293. delete m_pcTfontTbar;
  294. }
  295. /******************************************************************************/
  296. BOOL CTfont::Create( CRect rectEditArea )
  297. {
  298. BOOL bRC = TRUE;
  299. CRect cRectWindow( 0, 0, 0, 0 );
  300. CString pWindowName;
  301. pWindowName.LoadString( IDS_FONT_TOOL);
  302. bRC = CMiniFrmWnd::Create( pWindowName, 0, cRectWindow, AfxGetMainWnd() );
  303. if (bRC != FALSE)
  304. {
  305. TRY
  306. {
  307. bRC = m_cTfontDlg.Create ( this ); // can throw excpetion
  308. bRC = m_pcTfontTbar->Create( this ); // can throw excpetion
  309. ResizeWindow();
  310. }
  311. CATCH(CResourceException, e)
  312. {
  313. /*DK* ##ERROR CResourceException caught, could not create either toolbar or dialog bar object */
  314. }
  315. END_CATCH
  316. }
  317. else
  318. {
  319. /*DK* ##ERROR Could not create window for font tool box*/
  320. }
  321. ASSERT( bRC != FALSE );
  322. if (bRC != FALSE)
  323. {
  324. RefreshFontList();
  325. //Select the first item in the combobox.
  326. CComboBox* pCBox = (CComboBox*)m_cTfontDlg.GetDlgItem( IDC_TYPEFACE );
  327. ASSERT( pCBox != NULL );
  328. if (pCBox != NULL)
  329. {
  330. // we need to default to font with correct charset or font association.
  331. CHARSETINFO csi;
  332. if (!TranslateCharsetInfo((DWORD*)UIntToPtr(GetACP()), &csi, TCI_SRCCODEPAGE))
  333. csi.ciCharset=ANSI_CHARSET;
  334. for (int bFound = FALSE, index=0; !bFound && index < pCBox->GetCount();index++)
  335. {
  336. CFontDesc* pDesc = (CFontDesc*) pCBox->GetItemData(index);
  337. for (CCharSetDesc *pCharSetDesc = &pDesc->m_CharSetDesc; !bFound && pCharSetDesc != NULL; pCharSetDesc = pCharSetDesc->m_pNext)
  338. {
  339. if ( pCharSetDesc->m_nCharSet == csi.ciCharset)
  340. {
  341. bFound = TRUE;
  342. pCBox->SetCurSel(index);
  343. g_CharSetHistoryList.AddHead(pCharSetDesc->m_nCharSet);
  344. }
  345. }
  346. }
  347. // simulate a selection
  348. OnTypefaceChange();
  349. }
  350. ReadFromIniFile(); // will show the window the same state as saved
  351. // make sure the font tools does not show up on top of the edit box
  352. CRect rectFont;
  353. CRect rect;
  354. GetWindowRect( &rectFont );
  355. if (rect.IntersectRect( &rectEditArea, &rectFont ))
  356. SetWindowPos( &wndTop, rectFont.left,
  357. rectEditArea.top - (rectFont.Height() + theApp.m_cyFrame),
  358. 0, 0, SWP_NOSIZE );
  359. if (theApp.m_bShowTextToolbar)
  360. ShowWindow( SW_SHOWNOACTIVATE );
  361. }
  362. return bRC;
  363. }
  364. /***************************************************************************/
  365. BOOL CTfont::PreCreateWindow(CREATESTRUCT& cs)
  366. {
  367. BOOL bRet = CMiniFrmWnd::PreCreateWindow(cs);
  368. if (bRet)
  369. {
  370. // We don't want CLIENTEDGE on this window
  371. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  372. }
  373. return(bRet);
  374. }
  375. /******************************************************************************/
  376. void CTfont::GetFontInfo(int iFontSelection, BYTE nCharSetSelection)
  377. {
  378. CFontComboBox* pFontCBox = (CFontComboBox*)m_cTfontDlg.GetDlgItem(IDC_TYPEFACE);
  379. CCharSetComboBox* pCharSetCBox = (CCharSetComboBox*)m_cTfontDlg.GetDlgItem(IDC_CHARSET);
  380. CFontDesc* pDesc = pFontCBox->GetFontDesc(iFontSelection);
  381. m_strFontName = pDesc->m_strName;
  382. m_iFontType = pDesc->m_iFontType;
  383. // set the charset
  384. m_nCharSetPrev = m_nCharSet;
  385. m_nCharSet = nCharSetSelection;
  386. // fill in the charset combo box with the current set of charsets
  387. pCharSetCBox->ResetContent();
  388. for (CCharSetDesc *pCharSetDesc = &pDesc->m_CharSetDesc; pCharSetDesc != NULL; pCharSetDesc = pCharSetDesc->m_pNext)
  389. {
  390. pCharSetCBox->AddCharSet(pCharSetDesc->m_strScript, pCharSetDesc->m_nCharSet);
  391. }
  392. // and select the current charset
  393. pCharSetCBox->SelectCharSet(-1, nCharSetSelection);
  394. }
  395. void CTfont::Undo(void)
  396. {
  397. switch( m_iControlIDLastChange )
  398. {
  399. case IDC_TYPEFACE:
  400. if (m_cStrTypeFaceName.Compare(m_cStrTypeFaceNamePrev) != 0)
  401. {
  402. TRY
  403. {
  404. CString cStrTemp = m_cStrTypeFaceName;
  405. m_cStrTypeFaceName = m_cStrTypeFaceNamePrev;
  406. m_cStrTypeFaceNamePrev = cStrTemp;
  407. CFontComboBox* pCBox = (CFontComboBox*)m_cTfontDlg.GetDlgItem(IDC_TYPEFACE);
  408. int iSelection = pCBox->SelectString( -1, m_cStrTypeFaceName );
  409. ASSERT( iSelection != CB_ERR );
  410. if (iSelection != CB_ERR)
  411. {
  412. GetFontInfo(iSelection, m_nCharSetPrev);
  413. ProcessNewTypeface();
  414. }
  415. }
  416. CATCH(CMemoryException,e)
  417. {
  418. /*DK* ##ERROR CString Thrown CMemoryException*/
  419. }
  420. END_CATCH
  421. }
  422. // the processing of process new font may cause a re-selection in the
  423. // combo box (same code as user selection) changing this value. We
  424. // must re-set for undo of undo.
  425. m_iControlIDLastChange = IDC_TYPEFACE;
  426. break;
  427. case IDC_POINTSIZE:
  428. if (m_iPointSize != m_iPointSizePrev)
  429. {
  430. int iPointSizeTemp = m_iPointSize;
  431. m_iPointSize = m_iPointSizePrev;
  432. m_iPointSizePrev = iPointSizeTemp;
  433. m_cTfontDlg.SetDlgItemInt( IDC_POINTSIZE, m_iPointSize );
  434. UpdateEditControlFont();
  435. }
  436. break;
  437. case IDC_BOLD:
  438. OnBold();
  439. RefreshToolBar();
  440. break;
  441. case IDC_ITALIC:
  442. OnItalic();
  443. RefreshToolBar();
  444. break;
  445. case IDC_UNDERLINE:
  446. OnUnderline();
  447. RefreshToolBar();
  448. break;
  449. case IDC_VERTEDIT:
  450. OnVertEdit();
  451. RefreshToolBar();
  452. break;
  453. case IDC_SHADOW:
  454. OnShadow();
  455. RefreshToolBar();
  456. break;
  457. default:
  458. break;
  459. }
  460. }
  461. /******************************************************************************/
  462. void CTfont::RefreshToolBar(void)
  463. {
  464. // Set the bold button state
  465. if (m_bBoldOn)
  466. {
  467. m_pcTfontTbar->SetButtonInfo( BOLD_TBAR_POS, IDC_BOLD, TBBS_CHECKBOX | TBBS_CHECKED, BOLD_BMP_POS);
  468. }
  469. else
  470. {
  471. m_pcTfontTbar->SetButtonInfo( BOLD_TBAR_POS, IDC_BOLD, TBBS_CHECKBOX, BOLD_BMP_POS);
  472. }
  473. // Set the italic button state
  474. if (m_bItalicOn)
  475. {
  476. m_pcTfontTbar->SetButtonInfo( ITALIC_TBAR_POS, IDC_ITALIC, TBBS_CHECKBOX | TBBS_CHECKED, ITALIC_BMP_POS);
  477. }
  478. else
  479. {
  480. m_pcTfontTbar->SetButtonInfo( ITALIC_TBAR_POS, IDC_ITALIC, TBBS_CHECKBOX, ITALIC_BMP_POS);
  481. }
  482. // Set the underline button state
  483. if (m_bUnderlineOn)
  484. {
  485. m_pcTfontTbar->SetButtonInfo(UNDERLINE_TBAR_POS, IDC_UNDERLINE, TBBS_CHECKBOX | TBBS_CHECKED, UNDERLINE_BMP_POS);
  486. }
  487. else
  488. {
  489. m_pcTfontTbar->SetButtonInfo(UNDERLINE_TBAR_POS, IDC_UNDERLINE, TBBS_CHECKBOX, UNDERLINE_BMP_POS);
  490. }
  491. // Set the VertEdit button state
  492. if (m_bVertEditOn)
  493. {
  494. m_pcTfontTbar->SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX | TBBS_CHECKED, VERTEDIT_BMP_POS);
  495. }
  496. else
  497. {
  498. m_pcTfontTbar->SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX, VERTEDIT_BMP_POS);
  499. }
  500. // Set the underline button state
  501. if (theApp.m_bPenSystem)
  502. if (m_bPenOn)
  503. {
  504. m_pcTfontTbar->SetButtonInfo(PEN_TBAR_PEN_POS, IDC_PENEXT, TBBS_CHECKBOX | TBBS_CHECKED, PEN_BMP_POS);
  505. }
  506. else
  507. {
  508. m_pcTfontTbar->SetButtonInfo(PEN_TBAR_TEXT_POS, IDC_PENEXT, TBBS_CHECKBOX, PEN_BMP_POS);
  509. }
  510. // Set the shadow button state
  511. // currently this is not present on the toolbar. When it is available, fix the
  512. // SHADOW_TBAR_POS and SHADOW_BMP_POS #define in tfont.h
  513. // if (m_bShadowOn)
  514. // {
  515. // m_pcTfontTbar->SetButtonInfo(SHADOW_TBAR_POS, IDC_SHADOW, TBBS_CHECKBOX | TBBS_CHECKED, SHADOW_BMP_POS);
  516. // }
  517. // else
  518. // {
  519. // m_pcTfontTbar->SetButtonInfo(SHADOW_TBAR_POS, IDC_SHADOW, TBBS_CHECKBOX, SHADOW_BMP_POS);
  520. // }
  521. }
  522. /******************************************************************************/
  523. void CTfont::ResizeWindow( void )
  524. {
  525. CRect cClientRect;
  526. CRect cRectDlgBar;
  527. CRect cRectTbar;
  528. int ixPosDlgBar = 0;
  529. int iyPosDlgBar = 0;
  530. int ixPosTbar = 0;
  531. int iyPosTbar = 0;
  532. int iWindowHeight = 0;
  533. int iWindowWidth = 0;
  534. int iBorder = 0;
  535. int ixNCBorder = 0;
  536. int iyNCBorder = 0;
  537. ixNCBorder += theApp.m_cxBorder * 2;
  538. iyNCBorder += theApp.m_cyBorder * 2;
  539. iyNCBorder += theApp.m_cyCaption;
  540. m_cTfontDlg.GetWindowRect( &cRectDlgBar );
  541. cRectTbar.SetRectEmpty();
  542. m_pcTfontTbar->GetWindowRect( &cRectTbar );
  543. // /4 since border is for top/bottom or left/right
  544. // the boder is 1/4 the height of the tool/dialog bar
  545. iBorder += cRectDlgBar.Height() / 4;
  546. // Compute the Width
  547. // Width is combination of both
  548. iWindowWidth += ixNCBorder;
  549. iWindowWidth += cRectDlgBar.Width();
  550. iWindowWidth += cRectTbar.Width();
  551. iWindowWidth += 3 * iBorder; // border on left and right and between dlgbar and tbar
  552. // Compute the Height
  553. // Height is combination of both
  554. iWindowHeight += iyNCBorder;
  555. iWindowHeight += cRectDlgBar.Height();
  556. iWindowHeight += 2 * iBorder; // border on top and bottom
  557. // position the main window
  558. if (GetSafeHwnd() != NULL)
  559. {
  560. // size this window to fit children
  561. SetWindowPos(&wndTop, 0, 0, iWindowWidth, iWindowHeight, SWP_NOMOVE);
  562. }
  563. GetClientRect(&cClientRect);
  564. // calculate the x positions of the 2 control bars (next to eachother)
  565. ixPosDlgBar = iBorder;
  566. ixPosTbar = iBorder * 2 + cRectDlgBar.Width();
  567. // center the 2 control bars in the vertical position
  568. iyPosDlgBar = (cClientRect.Height() - cRectDlgBar.Height()) / 2;
  569. iyPosTbar = (cClientRect.Height() - cRectTbar.Height()) / 2;
  570. // Position the Dialog Bar
  571. if (m_cTfontDlg.GetSafeHwnd() != NULL)
  572. {
  573. m_cTfontDlg.SetWindowPos(&wndTop, ixPosDlgBar, iyPosDlgBar, 0, 0, SWP_NOSIZE);
  574. m_cTfontDlg.ShowWindow(SW_SHOWNOACTIVATE);
  575. }
  576. // Position the Toolbar
  577. if (m_pcTfontTbar->GetSafeHwnd() != NULL)
  578. {
  579. m_pcTfontTbar->SetWindowPos(&wndTop, ixPosTbar, iyPosTbar, 0, 0, SWP_NOSIZE);
  580. m_pcTfontTbar->ShowWindow(SW_SHOWNOACTIVATE);
  581. }
  582. }
  583. /******************************************************************************/
  584. /******************************************************************************/
  585. /* */
  586. /* Ini File section format PBrush.INI in Windows Dir */
  587. /* [Text] */
  588. /* TypeFaceName= string */
  589. /* PointSize= # */
  590. /* FontPalette= x y nCmdShow (x,y) is location screen. nCmdShow is param to */
  591. /* Bold= ON F ShowWindow of SW_SHOW or SW_HIDE */
  592. /* Italic= ON */
  593. /* Underline= ON */
  594. /* */
  595. /******************************************************************************/
  596. void CTfont::SaveToIniFile(void)
  597. {
  598. theApp.m_iPointSize = m_iPointSize;
  599. theApp.m_strTypeFaceName = m_cStrTypeFaceName;
  600. theApp.m_iCharSet = m_nCharSet;
  601. theApp.m_iPosTextX = m_cRectWindow.left;
  602. theApp.m_iPosTextY = m_cRectWindow.top;
  603. theApp.m_iBoldText = m_bBoldOn;
  604. theApp.m_iItalicText = m_bItalicOn;
  605. theApp.m_iUnderlineText = m_bUnderlineOn;
  606. theApp.m_iVertEditText = m_bVertEditOn;
  607. theApp.m_iPenText = m_bPenOn;
  608. }
  609. /******************************************************************************/
  610. /* See Save to ini for format of ini file */
  611. void CTfont::ReadFromIniFile(void)
  612. {
  613. CRect rect;
  614. GetWindowRect( &rect );
  615. CSize size = rect.Size();
  616. CPoint ptPos = theApp.CheckWindowPosition( CPoint( theApp.m_iPosTextX,
  617. theApp.m_iPosTextY ),
  618. size );
  619. if (! ptPos.x
  620. && ! ptPos.y)
  621. {
  622. AfxGetMainWnd()->GetWindowRect( &rect );
  623. rect.OffsetRect( 15, 15 );
  624. ptPos.x = rect.left;
  625. ptPos.y = rect.top;
  626. }
  627. if (GetSafeHwnd() != NULL)
  628. {
  629. SetWindowPos(&wndTop, ptPos.x, ptPos.y, 0, 0, SWP_NOSIZE);
  630. }
  631. if (theApp.m_strTypeFaceName.IsEmpty() == 0)
  632. {
  633. m_cStrTypeFaceName = theApp.m_strTypeFaceName;
  634. m_iPointSize = theApp.m_iPointSize;
  635. // m_iPointSize = 0; // 0 is initial value => 1st in list will be selected
  636. CFontComboBox* pCBox = (CFontComboBox*)m_cTfontDlg.GetDlgItem(IDC_TYPEFACE);
  637. int iSelection = pCBox->SelectString(-1, m_cStrTypeFaceName);
  638. if (iSelection != CB_ERR)
  639. {
  640. CFontDesc* pDesc = pCBox->GetFontDesc(iSelection);
  641. BYTE nNewCharSet = PickCharSet(&pDesc->m_CharSetDesc, theApp.m_iCharSet);
  642. GetFontInfo(iSelection, nNewCharSet);
  643. ProcessNewTypeface(); // this will also set the pointsize to what we have in our variable
  644. }
  645. }
  646. if (theApp.m_iBoldText)
  647. {
  648. m_bBoldOn = FALSE;
  649. OnBold(); // toggles from false to TRUE
  650. m_pcTfontTbar->SetButtonInfo(BOLD_TBAR_POS, IDC_BOLD, TBBS_CHECKBOX | TBBS_CHECKED, BOLD_BMP_POS);
  651. }
  652. if (theApp.m_iItalicText)
  653. {
  654. m_bItalicOn = FALSE;
  655. OnItalic(); // toggles from false to TRUE
  656. m_pcTfontTbar->SetButtonInfo(ITALIC_TBAR_POS, IDC_ITALIC, TBBS_CHECKBOX | TBBS_CHECKED, ITALIC_BMP_POS);
  657. }
  658. if (theApp.m_iUnderlineText)
  659. {
  660. m_bUnderlineOn = FALSE;
  661. OnUnderline(); // toggles from false to TRUE
  662. m_pcTfontTbar->SetButtonInfo(UNDERLINE_TBAR_POS, IDC_UNDERLINE, TBBS_CHECKBOX | TBBS_CHECKED, UNDERLINE_BMP_POS);
  663. }
  664. if (theApp.m_iVertEditText == -1) //no setting in profile
  665. {
  666. theApp.m_iVertEditText = (IS_DBCS_CHARSET(m_nCharSet)) ? FALSE : 2;
  667. }
  668. if (theApp.m_iVertEditText == 2)
  669. {
  670. m_bVertEditOn = 2;
  671. m_pcTfontTbar->SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX | TBBS_DISABLED, VERTEDIT_BMP_POS);
  672. }
  673. else if (theApp.m_iVertEditText)
  674. {
  675. m_bVertEditOn = FALSE;
  676. OnVertEdit(); // toggles from false to TRUE
  677. m_pcTfontTbar->SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX | TBBS_CHECKED, VERTEDIT_BMP_POS);
  678. }
  679. else
  680. {
  681. m_bVertEditOn = FALSE;
  682. m_pcTfontTbar->SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX, VERTEDIT_BMP_POS);
  683. }
  684. if (theApp.m_bPenSystem)
  685. if (theApp.m_iPenText)
  686. {
  687. m_bPenOn = FALSE;
  688. OnPen(); // toggles from false to TRUE
  689. }
  690. }
  691. /******************************************************************************/
  692. void CTfont::RefreshFontList(void)
  693. {
  694. CFontComboBox* pBox = (CFontComboBox *)m_cTfontDlg.GetDlgItem(IDC_TYPEFACE);
  695. pBox->ClearList();
  696. CClientDC cdcWindow(this);
  697. HDC hDC = cdcWindow.GetSafeHdc();
  698. ASSERT(hDC != NULL);
  699. if (hDC != NULL)
  700. {
  701. FONTENUMPROC lpEnumFamCallBack;
  702. lpEnumFamCallBack = (FONTENUMPROC) CTfont::EnumFontFaceProc;
  703. LOGFONT lf;
  704. memset(&lf, 0, sizeof(lf));
  705. lf.lfCharSet = DEFAULT_CHARSET;
  706. ::EnumFontFamiliesEx(hDC, &lf, lpEnumFamCallBack, (LPARAM) this, NULL);
  707. }
  708. }
  709. /******************************************************************************/
  710. int CFontComboBox::AddFontName(LPCTSTR lpszName, LPCTSTR lpszScript, BYTE nCharSet,
  711. int iFontType)
  712. {
  713. int nIndex = FindStringExact(-1, lpszName);
  714. if (nIndex != CB_ERR)
  715. {
  716. // add this new charset to the end of the charset list
  717. CFontDesc* pDesc = (CFontDesc*) GetItemData(nIndex);
  718. CCharSetDesc *pCharSetDesc = &pDesc->m_CharSetDesc;
  719. while (pCharSetDesc->m_pNext != NULL)
  720. {
  721. pCharSetDesc = pCharSetDesc->m_pNext;
  722. }
  723. pCharSetDesc->m_pNext = new CCharSetDesc(lpszScript, nCharSet);
  724. return(nIndex);
  725. }
  726. CFontDesc* pDesc = new CFontDesc(lpszName, lpszScript, nCharSet, iFontType);
  727. if (!pDesc)
  728. {
  729. return(-1);
  730. }
  731. nIndex = AddString(lpszName);
  732. ASSERT(nIndex >=0);
  733. if (nIndex >=0) //no error
  734. {
  735. SetItemData(nIndex, (DWORD_PTR)pDesc);
  736. }
  737. else
  738. {
  739. delete pDesc;
  740. }
  741. return nIndex;
  742. }
  743. void CFontComboBox::ClearList()
  744. {
  745. // destroy all the CFontDesc's
  746. int nCount = GetCount();
  747. for (int i=0;i<nCount;i++)
  748. delete GetFontDesc(i);
  749. ResetContent();
  750. }
  751. BOOL CFontComboBox::IsSameName(CFontDesc* pDesc, int index)
  752. {
  753. CFontDesc* pDescOther = GetFontDesc(index);
  754. if (pDescOther == (CFontDesc*)CB_ERR)
  755. {
  756. return(FALSE);
  757. }
  758. return(lstrcmp(pDesc->m_strName, pDescOther->m_strName) == 0);
  759. }
  760. int CCharSetComboBox::AddCharSet(LPCTSTR lpszScript, BYTE nCharSet)
  761. {
  762. int nIndex = AddString(lpszScript);
  763. if (nIndex != CB_ERR && nIndex != CB_ERRSPACE)
  764. {
  765. SetItemData(nIndex, nCharSet);
  766. }
  767. return nIndex;
  768. }
  769. int CCharSetComboBox::SelectCharSet(int nStartAfter, BYTE nCharSet)
  770. {
  771. for (int i = nStartAfter+1; i < GetCount(); ++i)
  772. {
  773. if ((BYTE) GetItemData(i) == nCharSet)
  774. {
  775. return SetCurSel(i);
  776. }
  777. }
  778. return CB_ERR;
  779. }
  780. int CCharSetComboBox::GetCurSelCharSet()
  781. {
  782. int iSelection = GetCurSel();
  783. if (iSelection != CB_ERR)
  784. {
  785. iSelection = (int) GetItemData(iSelection);
  786. }
  787. return iSelection;
  788. }
  789. int CTfont::EnumFontFace( ENUMLOGFONTEX* lpEnumLogFont,
  790. NEWTEXTMETRICEX* lpNewTextMetric,
  791. int iFontType )
  792. {
  793. // only enumerate TrueType faces
  794. // in DBCS builds also exclude vertical faces
  795. if ((lpEnumLogFont->elfLogFont.lfCharSet != OEM_CHARSET)
  796. && (lpEnumLogFont->elfLogFont.lfCharSet != MAC_CHARSET)
  797. && (lpEnumLogFont->elfLogFont.lfFaceName[0] != TEXT('@'))
  798. )
  799. {
  800. INT ntmFlags = lpNewTextMetric->ntmTm.ntmFlags;
  801. CFontComboBox* pBox = (CFontComboBox *)m_cTfontDlg.GetDlgItem(IDC_TYPEFACE);
  802. if (ntmFlags & NTM_PS_OPENTYPE)
  803. iFontType = PS_OPENTYPE_FONT;
  804. else if (ntmFlags & NTM_TYPE1)
  805. iFontType = TYPE1_FONT;
  806. else
  807. {
  808. if (iFontType & TRUETYPE_FONTTYPE)
  809. {
  810. if (ntmFlags & NTM_TT_OPENTYPE)
  811. iFontType = TT_OPENTYPE_FONT;
  812. else
  813. iFontType = TT_FONT;
  814. }
  815. else if (iFontType & DEVICE_FONTTYPE)
  816. iFontType = DEVICE_FONT;
  817. else if (iFontType & RASTER_FONTTYPE)
  818. iFontType = RASTER_FONT;
  819. }
  820. pBox->AddFontName(lpEnumLogFont->elfLogFont.lfFaceName,
  821. (LPCTSTR)lpEnumLogFont->elfScript, lpEnumLogFont->elfLogFont.lfCharSet, iFontType);
  822. }
  823. return 1;
  824. }
  825. /******************************************************************************/
  826. int CALLBACK CTfont::EnumFontFaceProc( ENUMLOGFONTEX* lpEnumLogFont,
  827. NEWTEXTMETRICEX* lpNewTextMetric,
  828. int iFontType, LPARAM lParam )
  829. {
  830. class CTfont* pCTfont;
  831. ASSERT(lParam != NULL);
  832. if (lParam != NULL)
  833. {
  834. pCTfont = (CTfont*)lParam;
  835. return pCTfont->EnumFontFace(lpEnumLogFont, lpNewTextMetric, iFontType);
  836. }
  837. return 0;
  838. }
  839. /******************************************************************************/
  840. int CTfont::EnumFontSizes( LPENUMLOGFONT lpEnumLogFont,
  841. LPNEWTEXTMETRIC lpNewTextMetric,
  842. int iFontType )
  843. {
  844. int iPtSize;
  845. /* testint */
  846. CAttrEdit* pcEdit = m_pcTedit->GetEditWindow();
  847. ASSERT(pcEdit != NULL);
  848. if (pcEdit != NULL)
  849. {
  850. CClientDC cdcClient( pcEdit );
  851. // ptsize = char height * 72 / pixels per inch
  852. // char height = cell height - internal leading
  853. iPtSize = MulDiv( lpNewTextMetric->tmHeight -
  854. lpNewTextMetric->tmInternalLeading,
  855. 72, cdcClient.GetDeviceCaps( LOGPIXELSY ) );
  856. }
  857. TCHAR buffTmp[10];
  858. // Leading zero prefixed for Combobox sorting order.
  859. wsprintf( buffTmp, TEXT("%2d"), iPtSize );
  860. CComboBox* pCBox = (CComboBox*)m_cTfontDlg.GetDlgItem(IDC_POINTSIZE);
  861. ASSERT (pCBox != NULL);
  862. if (pCBox != NULL)
  863. {
  864. // only add the string if it does not exist
  865. int iRC = pCBox->FindStringExact(-1, buffTmp);
  866. if (iRC == CB_ERR)
  867. {
  868. pCBox->AddString(buffTmp);
  869. }
  870. }
  871. return 1;
  872. }
  873. /******************************************************************************/
  874. int CALLBACK CTfont::EnumFontOneFaceProc( LPENUMLOGFONT lpEnumLogFont,
  875. LPNEWTEXTMETRIC lpNewTextMetric,
  876. int iFontType, LPARAM lParam )
  877. {
  878. class CTfont* pCTfont;
  879. ASSERT(lParam != NULL);
  880. if (lParam != NULL)
  881. {
  882. pCTfont = (CTfont*)lParam;
  883. return pCTfont->EnumFontSizes(lpEnumLogFont, lpNewTextMetric, iFontType);
  884. }
  885. return 0;
  886. }
  887. /******************************************************************************/
  888. // User selected a new typeface in the combo box
  889. /******************************************************************************/
  890. void CTfont::ProcessNewTypeface(void)
  891. {
  892. CString cStringText;
  893. CClientDC cdcDlgBox( this );
  894. HDC hDC = cdcDlgBox.GetSafeHdc();
  895. ASSERT(hDC != NULL);
  896. if (hDC != NULL)
  897. {
  898. FONTENUMPROC lpEnumFamCallBack;
  899. lpEnumFamCallBack = (FONTENUMPROC)CTfont::EnumFontOneFaceProc;
  900. CComboBox* pCBox = (CComboBox*)m_cTfontDlg.GetDlgItem(IDC_POINTSIZE);
  901. ASSERT (pCBox != NULL);
  902. if (pCBox != NULL)
  903. {
  904. pCBox->ResetContent();
  905. // only do this if non-true-type font if true type, filll in with default sizes
  906. if (
  907. (m_iFontType & (TT_FONT | TT_OPENTYPE_FONT)) ||
  908. !( (m_iFontType & (TT_FONT | TT_OPENTYPE_FONT)) || (m_iFontType & RASTER_FONT) )
  909. ) // if truetype or vector font
  910. {
  911. // True Type and Vector Fonts are continuously scallable.
  912. // There are the reccomended values
  913. pCBox->AddString(TEXT(" 8"));
  914. pCBox->AddString(TEXT(" 9"));
  915. pCBox->AddString(TEXT("10"));
  916. pCBox->AddString(TEXT("11"));
  917. pCBox->AddString(TEXT("12"));
  918. pCBox->AddString(TEXT("14"));
  919. pCBox->AddString(TEXT("16"));
  920. pCBox->AddString(TEXT("18"));
  921. pCBox->AddString(TEXT("20"));
  922. pCBox->AddString(TEXT("22"));
  923. pCBox->AddString(TEXT("24"));
  924. pCBox->AddString(TEXT("26"));
  925. pCBox->AddString(TEXT("28"));
  926. pCBox->AddString(TEXT("36"));
  927. pCBox->AddString(TEXT("48"));
  928. pCBox->AddString(TEXT("72"));
  929. }
  930. else
  931. {
  932. ::EnumFontFamilies(hDC, m_strFontName, lpEnumFamCallBack, (LPARAM) this);
  933. }
  934. // 0 is uninitialized value
  935. if (m_iPointSize != 0)
  936. {
  937. m_cTfontDlg.SetDlgItemInt(IDC_POINTSIZE, m_iPointSize);
  938. }
  939. else
  940. {
  941. pCBox->SetCurSel(0);
  942. }
  943. // simulate a selection
  944. OnPointSizeComboBoxUpdate();
  945. }
  946. }
  947. }
  948. /******************************************************************************/
  949. // change the font in the edit control based on the font selection
  950. /******************************************************************************/
  951. void CTfont::UpdateEditControlFont(void)
  952. {
  953. LOGFONT lf;
  954. CFont* pcOldFont;
  955. BOOL bRC;
  956. HFONT hFont;
  957. int iCellHeight = 0;
  958. BeginWaitCursor();
  959. CAttrEdit* pcEdit = m_pcTedit->GetEditWindow();
  960. ASSERT(pcEdit != NULL);
  961. if (pcEdit != NULL)
  962. {
  963. CClientDC cdcClient( pcEdit );
  964. //previous font's tm.tmInternalLeading could be different from current.
  965. iCellHeight = - MulDiv(m_iPointSize, cdcClient.GetDeviceCaps(LOGPIXELSY)
  966. ,72);
  967. }
  968. lf.lfWidth = 0;
  969. lf.lfHeight = iCellHeight;
  970. lf.lfEscapement = (m_bVertEditOn == TRUE) ? 2700 : 0;
  971. lf.lfOrientation = (m_bVertEditOn == TRUE) ? 2700 : 0;
  972. lf.lfWeight = m_iWeight;
  973. lf.lfItalic = (BYTE)m_bItalicOn;
  974. lf.lfUnderline = (BYTE)m_bUnderlineOn;
  975. lf.lfStrikeOut = 0;
  976. lf.lfCharSet = m_nCharSet;
  977. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  978. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  979. lf.lfQuality = DEFAULT_QUALITY;
  980. lf.lfPitchAndFamily = FF_DONTCARE | DEFAULT_PITCH;
  981. if ( (m_bVertEditOn == TRUE) && IS_DBCS_CHARSET( lf.lfCharSet ) )
  982. {
  983. lstrcpy(lf.lfFaceName, TEXT("@"));
  984. lstrcpyn(lf.lfFaceName + 1, m_strFontName, ARRAYSIZE(lf.lfFaceName) - 1);
  985. }
  986. else
  987. lstrcpyn(lf.lfFaceName, m_strFontName, ARRAYSIZE(lf.lfFaceName));
  988. hFont = (HFONT)m_cCurrentFont.Detach();
  989. bRC = m_cCurrentFont.CreateFontIndirect(&lf);
  990. ASSERT(bRC != 0);
  991. if (bRC != 0)
  992. {
  993. if (m_pcTedit != NULL)
  994. {
  995. CAttrEdit* pcEdit = m_pcTedit->GetEditWindow();
  996. ASSERT( pcEdit != NULL );
  997. pcOldFont = pcEdit->GetFont();
  998. pcEdit->SetFont( &m_cCurrentFont );
  999. m_pcTedit->OnAttrEditFontChange();
  1000. m_pcTedit->RefreshWindow();
  1001. }
  1002. //hFont is last font allocated here
  1003. if (hFont != NULL)
  1004. {
  1005. ::DeleteObject( hFont );
  1006. }
  1007. }
  1008. else
  1009. {
  1010. /*DK* ##ERROR Could not create font indirect */
  1011. }
  1012. EndWaitCursor();
  1013. }
  1014. /******************************************************************************/
  1015. /******************************************************************************/
  1016. BYTE CTfont::PickCharSet(CCharSetDesc *pCharSetDescList, int iCharSetSelection)
  1017. {
  1018. ASSERT(pCharSetDescList);
  1019. // place the selected charset on top of the charset history list
  1020. if (iCharSetSelection != g_CharSetHistoryList.GetAt(0) && iCharSetSelection != -1)
  1021. {
  1022. g_CharSetHistoryList.AddHead(iCharSetSelection);
  1023. }
  1024. // try to select a charset from the history list
  1025. for (unsigned int i = 0; i < g_CharSetHistoryList.m_uHistorySize; ++i)
  1026. {
  1027. int nSearchCharSet = g_CharSetHistoryList.GetAt(i);
  1028. if (nSearchCharSet != -1)
  1029. {
  1030. for (CCharSetDesc *pCharSetDesc = pCharSetDescList; pCharSetDesc != NULL; pCharSetDesc = pCharSetDesc->m_pNext)
  1031. {
  1032. if (pCharSetDesc->m_nCharSet == (BYTE) nSearchCharSet)
  1033. {
  1034. return (BYTE) nSearchCharSet;
  1035. }
  1036. }
  1037. }
  1038. }
  1039. // if we fail to find a match, select the first charset
  1040. return pCharSetDescList->m_nCharSet;
  1041. }
  1042. /******************************************************************************/
  1043. // Combo box for type face changed, determine what processing to do
  1044. /******************************************************************************/
  1045. void CTfont::OnTypeFaceComboBoxUpdate(void)
  1046. {
  1047. int iSelection;
  1048. CString cStringText;
  1049. // LPFONTINFORMATION lpFontInformation;
  1050. CFontComboBox* pFontCBox = (CFontComboBox*)m_cTfontDlg.GetDlgItem(IDC_TYPEFACE);
  1051. CCharSetComboBox* pCharSetCBox = (CCharSetComboBox*)m_cTfontDlg.GetDlgItem(IDC_CHARSET);
  1052. ASSERT(pFontCBox != NULL && pCharSetCBox != NULL);
  1053. if (pFontCBox != NULL && pCharSetCBox != NULL)
  1054. {
  1055. TRY
  1056. {
  1057. iSelection = pFontCBox->GetCurSel();
  1058. ASSERT(iSelection != CB_ERR);
  1059. if (iSelection != CB_ERR)
  1060. {
  1061. pFontCBox->GetLBText(iSelection, cStringText);
  1062. }
  1063. }
  1064. CATCH(CMemoryException,e)
  1065. {
  1066. cStringText.Empty();
  1067. /*DK* ##ERROR CString Thrown CMemoryException*/
  1068. }
  1069. END_CATCH
  1070. int iCharSetSelection = pCharSetCBox->GetCurSelCharSet();
  1071. if (m_cStrTypeFaceName.Compare(cStringText) != 0 || (BYTE) iCharSetSelection != m_nCharSet)
  1072. {
  1073. CFontDesc* pDesc = pFontCBox->GetFontDesc(iSelection);
  1074. BYTE nNewCharSet = PickCharSet(&pDesc->m_CharSetDesc, iCharSetSelection);
  1075. if ( IS_DBCS_CHARSET( nNewCharSet ) )
  1076. {
  1077. if ( m_bVertEditOn == 2 )
  1078. {
  1079. m_bVertEditOn = FALSE;
  1080. m_pcTfontTbar->SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT,
  1081. TBBS_CHECKBOX, VERTEDIT_BMP_POS);
  1082. }
  1083. }
  1084. else
  1085. {
  1086. if ( m_bVertEditOn == TRUE )
  1087. {
  1088. AfxMessageBox(IDS_ERROR_DBCSFONTONLY);
  1089. pFontCBox->SelectString( -1, m_cStrTypeFaceName );
  1090. pCharSetCBox->SelectCharSet( -1, m_nCharSet );
  1091. return;
  1092. }
  1093. else
  1094. {
  1095. m_bVertEditOn = 2;
  1096. m_pcTfontTbar->SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX | TBBS_DISABLED, VERTEDIT_BMP_POS);
  1097. }
  1098. }
  1099. // could have been set in OnCloseUpTypeFace method, so don't do double
  1100. // processing
  1101. TRY
  1102. {
  1103. m_cStrTypeFaceNamePrev = m_cStrTypeFaceName;
  1104. m_cStrTypeFaceName = cStringText;
  1105. }
  1106. CATCH(CMemoryException,e)
  1107. {
  1108. m_cStrTypeFaceName.Empty();
  1109. /*DK* ##ERROR CString Thrown CMemoryException*/
  1110. }
  1111. END_CATCH
  1112. GetFontInfo(iSelection, nNewCharSet);
  1113. ProcessNewTypeface();
  1114. m_iControlIDLastChange = IDC_TYPEFACE;
  1115. }
  1116. }
  1117. }
  1118. /******************************************************************************/
  1119. void CTfont::OnPointSizeComboBoxUpdate(void)
  1120. {
  1121. int iSelection;
  1122. int iHeight;
  1123. CString cStringText;
  1124. CComboBox* pCBox = (CComboBox*)m_cTfontDlg.GetDlgItem(IDC_POINTSIZE);
  1125. ASSERT(pCBox != NULL);
  1126. if (pCBox != NULL)
  1127. {
  1128. TRY
  1129. {
  1130. iSelection = pCBox->GetCurSel();
  1131. if (iSelection != CB_ERR)
  1132. {
  1133. pCBox->GetLBText(iSelection, cStringText);
  1134. iHeight = Atoi(cStringText);
  1135. }
  1136. else
  1137. {
  1138. // if no selection, get displayed value in combo edit part
  1139. iHeight = m_cTfontDlg.GetDlgItemInt(IDC_POINTSIZE);
  1140. }
  1141. }
  1142. CATCH(CMemoryException,e)
  1143. {
  1144. cStringText.Empty();
  1145. /*DK* ##ERROR CString Thrown CMemoryException*/
  1146. }
  1147. END_CATCH
  1148. if (iHeight !=0 )
  1149. {
  1150. if (iHeight != m_iPointSize )
  1151. {
  1152. // could have been set in OnCloseUpTypeFace method, so don't do double
  1153. // processing
  1154. m_iPointSizePrev = m_iPointSize;
  1155. m_iPointSize = iHeight;
  1156. }
  1157. }
  1158. else
  1159. {
  1160. AfxMessageBox(IDS_ERROR_FONTSIZENUMERIC);
  1161. m_cTfontDlg.SetDlgItemInt(IDC_POINTSIZE,m_iPointSize);
  1162. }
  1163. // need to call update font because could be same size with diff
  1164. // typeface, and we got called indirectly by filling the combo box
  1165. UpdateEditControlFont();
  1166. m_iControlIDLastChange = IDC_POINTSIZE;
  1167. }
  1168. }
  1169. /******************************************************************************/
  1170. void CTfont::OnTypefaceChange()
  1171. {
  1172. if (! m_bInUpdate)
  1173. {
  1174. m_bInUpdate = TRUE;
  1175. OnTypeFaceComboBoxUpdate();
  1176. m_bInUpdate = FALSE;
  1177. }
  1178. }
  1179. /******************************************************************************/
  1180. void CTfont::OnPointSizeChange()
  1181. {
  1182. if (! m_bInUpdate)
  1183. {
  1184. m_bInUpdate = TRUE;
  1185. OnPointSizeComboBoxUpdate();
  1186. m_bInUpdate = FALSE;
  1187. }
  1188. }
  1189. /******************************************************************************/
  1190. void CTfont::OnRButtonDown(UINT nFlags, CPoint point)
  1191. {
  1192. #if 0
  1193. CMenu cMenuPopup;
  1194. CMenu *pcContextMenu;
  1195. BOOL bRC;
  1196. bRC = cMenuPopup.LoadMenu(IDR_TEXT_POPUP);
  1197. ASSERT(bRC != 0);
  1198. if (bRC != 0)
  1199. {
  1200. pcContextMenu = cMenuPopup.GetSubMenu(ID_TOOL_POPUPMENU_POS);
  1201. ASSERT(pcContextMenu != NULL);
  1202. if (pcContextMenu != NULL)
  1203. {
  1204. ClientToScreen(&point);
  1205. pcContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this, NULL);
  1206. }
  1207. }
  1208. else
  1209. {
  1210. /*DK* ##ERROR Could not loadmenu */
  1211. }
  1212. #endif
  1213. }
  1214. /******************************************************************************/
  1215. void CTfont::OnMove(int x, int y)
  1216. {
  1217. CMiniFrmWnd::OnMove(x, y);
  1218. // TODO: Add your message handler code here
  1219. GetWindowRect(&m_cRectWindow);
  1220. }
  1221. /******************************************************************************/
  1222. void CTfont::OnClose()
  1223. {
  1224. theApp.m_bShowTextToolbar = FALSE;
  1225. ShowWindow( SW_HIDE );
  1226. }
  1227. /******************************************************************************/
  1228. BOOL CTfont::OnEraseBkgnd( CDC* pDC )
  1229. {
  1230. CRect rect;
  1231. GetClientRect( rect );
  1232. pDC->FillRect( rect, GetSysBrush( COLOR_BTNFACE ) );
  1233. return CMiniFrmWnd::OnEraseBkgnd( pDC );
  1234. }
  1235. /******************************************************************************/
  1236. void CTfont::OnSetFocus(CWnd* pOldWnd)
  1237. {
  1238. CMiniFrmWnd::OnSetFocus(pOldWnd);
  1239. CComboBox* pCBox = (CComboBox*)m_cTfontDlg.GetDlgItem( IDC_TYPEFACE );
  1240. ASSERT(pCBox != NULL);
  1241. if (pCBox != NULL)
  1242. {
  1243. pCBox->SetFocus();
  1244. }
  1245. }
  1246. /******************************************************************************/
  1247. void CTfont::OnDestroy()
  1248. {
  1249. CFontComboBox* pBox = (CFontComboBox *)m_cTfontDlg.GetDlgItem(IDC_TYPEFACE);
  1250. pBox->ClearList();
  1251. CMiniFrmWnd::OnDestroy();
  1252. }
  1253. /******************************************************************************/
  1254. void CTfont::OnBold(void)
  1255. {
  1256. m_iControlIDLastChange = IDC_BOLD;
  1257. m_bBoldOn = !m_bBoldOn;
  1258. if (m_bBoldOn)
  1259. {
  1260. m_iWeight = FW_BOLD;
  1261. }
  1262. else
  1263. {
  1264. m_iWeight = FW_NORMAL;
  1265. }
  1266. UpdateEditControlFont();
  1267. }
  1268. /******************************************************************************/
  1269. void CTfont::OnItalic(void)
  1270. {
  1271. m_bItalicOn = !m_bItalicOn;
  1272. UpdateEditControlFont();
  1273. m_iControlIDLastChange = IDC_ITALIC;
  1274. }
  1275. /******************************************************************************/
  1276. void CTfont::OnUnderline(void)
  1277. {
  1278. m_bUnderlineOn = !m_bUnderlineOn;
  1279. UpdateEditControlFont();
  1280. m_iControlIDLastChange = IDC_UNDERLINE;
  1281. }
  1282. /******************************************************************************/
  1283. void CTfont::OnVertEdit(void)
  1284. {
  1285. if (m_bVertEditOn == 2)
  1286. {
  1287. return;
  1288. }
  1289. m_bVertEditOn = !m_bVertEditOn;
  1290. m_pcTedit->m_bVertEdit = m_bVertEditOn;
  1291. UpdateEditControlFont();
  1292. m_iControlIDLastChange = IDC_VERTEDIT;
  1293. }
  1294. /******************************************************************************/
  1295. void CTfont::OnVertEditUpdate(CCmdUI* pCmdUI)
  1296. {
  1297. pCmdUI->Enable( !(m_bVertEditOn == 2) );
  1298. }
  1299. /******************************************************************************/
  1300. void CTfont::OnShadow(void)
  1301. {
  1302. m_bShadowOn = !m_bShadowOn;
  1303. UpdateEditControlFont();
  1304. m_iControlIDLastChange = IDC_SHADOW;
  1305. }
  1306. /******************************************************************************/
  1307. void CTfont::OnPen(void)
  1308. {
  1309. PostMessage( UM_DELAYED_TOOLBAR );
  1310. }
  1311. /******************************************************************************/
  1312. long CTfont::OnDelayedPen( WPARAM, LPARAM )
  1313. {
  1314. if (! theApp.m_bPenSystem)
  1315. m_bPenOn = FALSE;
  1316. m_bPenOn = !m_bPenOn;
  1317. m_iControlIDLastChange = IDC_PENEXT;
  1318. delete m_pcTfontTbar;
  1319. m_pcTfontTbar = new CTfontTbar();
  1320. BOOL bRC = m_pcTfontTbar->Create( this, m_bPenOn );
  1321. if (bRC)
  1322. {
  1323. ResizeWindow();
  1324. RefreshToolBar();
  1325. }
  1326. return 0;
  1327. }
  1328. /******************************************************************************/
  1329. void CTfont::OnEditText(void)
  1330. {
  1331. m_iControlIDLastChange = IDC_EDITTEXT;
  1332. CEdit *ctl = m_pcTedit? m_pcTedit->GetEditWindow() : NULL;
  1333. if (ctl)
  1334. {
  1335. ctl->SetFocus();
  1336. #ifndef NT
  1337. // NT doesn't support pen computing
  1338. ctl->SendMessage(WM_PENMISC, PMSC_EDITTEXT, 0);
  1339. #endif
  1340. }
  1341. }
  1342. /******************************************************************************/
  1343. void CTfont::OnKeyboard(void)
  1344. {
  1345. m_iControlIDLastChange = IDC_KEYBOARD;
  1346. CEdit *ctl = m_pcTedit? m_pcTedit->GetEditWindow() : NULL;
  1347. if (ctl)
  1348. {
  1349. }
  1350. }
  1351. /******************************************************************************/
  1352. void CTfont::OnInsSpace(void)
  1353. {
  1354. m_iControlIDLastChange = IDC_INS_SPACE;
  1355. CEdit *ctl = m_pcTedit? m_pcTedit->GetEditWindow() : NULL;
  1356. if (ctl)
  1357. {
  1358. ctl->SendMessage(WM_CHAR, (WPARAM)VK_SPACE, 0);
  1359. ctl->SetFocus();
  1360. }
  1361. }
  1362. /******************************************************************************/
  1363. void CTfont::OnBackSpace(void)
  1364. {
  1365. m_iControlIDLastChange = IDC_BACKSPACE;
  1366. CEdit *ctl = m_pcTedit? m_pcTedit->GetEditWindow() : NULL;
  1367. if (ctl)
  1368. {
  1369. ctl->SendMessage(WM_CHAR, (WPARAM)VK_BACK, 0);
  1370. ctl->SetFocus();
  1371. }
  1372. }
  1373. /******************************************************************************/
  1374. void CTfont::OnNewLine(void)
  1375. {
  1376. m_iControlIDLastChange = IDC_NEWLINE;
  1377. CEdit *ctl = m_pcTedit? m_pcTedit->GetEditWindow() : NULL;
  1378. if (ctl)
  1379. {
  1380. ctl->SendMessage(WM_CHAR, (WPARAM)VK_RETURN, 0);
  1381. ctl->SetFocus();
  1382. }
  1383. }
  1384. /******************************************************************************/
  1385. void CTfontDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
  1386. {
  1387. CString cStringText;
  1388. CComboBox cCBox;
  1389. BOOL bRC;
  1390. TRY
  1391. {
  1392. ASSERT( lpDrawItemStruct->CtlType == ODT_COMBOBOX );
  1393. ASSERT( lpDrawItemStruct->CtlID == IDC_TYPEFACE );
  1394. if (lpDrawItemStruct->CtlType != ODT_COMBOBOX
  1395. || lpDrawItemStruct->CtlID != IDC_TYPEFACE)
  1396. {
  1397. AfxThrowNotSupportedException();
  1398. }
  1399. // empty combo boxes have -1 id
  1400. if (lpDrawItemStruct->itemID != 0xFFFFFFFF)
  1401. {
  1402. bRC = cCBox.Attach(lpDrawItemStruct->hwndItem);
  1403. ASSERT(bRC != 0);
  1404. if (bRC == 0)
  1405. {
  1406. AfxThrowNotSupportedException();
  1407. }
  1408. TRY
  1409. {
  1410. cCBox.GetLBText(lpDrawItemStruct->itemID, cStringText);
  1411. cCBox.Detach();
  1412. DrawItem(lpDrawItemStruct, &cStringText);
  1413. }
  1414. CATCH(CMemoryException,e)
  1415. {
  1416. cStringText.Empty();
  1417. cCBox.Detach();
  1418. /*DK* ##ERROR CString Thrown CMemoryException*/
  1419. }
  1420. END_CATCH
  1421. }
  1422. }
  1423. CATCH(CNotSupportedException,e)
  1424. {
  1425. CWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
  1426. }
  1427. END_CATCH
  1428. }
  1429. /******************************************************************************/
  1430. void CTfont::OnLButtonDown(UINT nFlags, CPoint point)
  1431. {
  1432. CMiniFrmWnd::OnLButtonDown(nFlags, point);
  1433. }
  1434. /******************************************************************************/
  1435. void CTfont::OnLButtonUp(UINT nFlags, CPoint point)
  1436. {
  1437. CMiniFrmWnd::OnLButtonUp( nFlags, point );
  1438. }
  1439. /******************************************************************************/
  1440. void CTfont::RecalcLayout(BOOL bNotify /*= TRUE*/)
  1441. {
  1442. if (m_pcTfontTbar && m_pcTfontTbar->m_hWnd && m_cTfontDlg.m_hWnd)
  1443. {
  1444. ResizeWindow();
  1445. }
  1446. }
  1447. /******************************************************************************/
  1448. /******************************************************************************/
  1449. /******************************************************************************/
  1450. // CTfontTbar
  1451. BEGIN_MESSAGE_MAP( CTfontTbar, CToolBar )
  1452. //{{AFX_MSG_MAP(CTfontTbar)
  1453. // NOTE - the ClassWizard will add and remove mapping macros here.
  1454. // DO NOT EDIT what you see in these blocks of generated code !
  1455. // ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
  1456. //}}AFX_MSG_MAP
  1457. END_MESSAGE_MAP()
  1458. /******************************************************************************/
  1459. // CTfontTbar construction/destruction
  1460. CTfontTbar::CTfontTbar(void)
  1461. {
  1462. }
  1463. /******************************************************************************/
  1464. BOOL CTfontTbar::Create(CWnd* pcParentWnd, BOOL bShowPen)
  1465. {
  1466. BOOL bRC = TRUE;
  1467. int iNumButtons;
  1468. int iNumSeparators;
  1469. UINT ButtonIDS[MAX_TBAR_ITEMS];
  1470. if (bShowPen)
  1471. {
  1472. ButtonIDS[0] = IDC_BOLD;
  1473. ButtonIDS[1] = IDC_ITALIC;
  1474. ButtonIDS[2] = IDC_UNDERLINE;
  1475. ButtonIDS[3] = IDC_VERTEDIT;
  1476. ButtonIDS[4] = ID_SEPARATOR;
  1477. ButtonIDS[5] = IDC_INS_SPACE;
  1478. ButtonIDS[6] = IDC_BACKSPACE;
  1479. ButtonIDS[7] = IDC_NEWLINE;
  1480. ButtonIDS[8] = ID_SEPARATOR;
  1481. ButtonIDS[9] = IDC_EDITTEXT;
  1482. ButtonIDS[10] = ID_SEPARATOR;
  1483. ButtonIDS[11] = IDC_PENEXT;
  1484. iNumButtons = 12;
  1485. iNumSeparators = 3;
  1486. }
  1487. else
  1488. {
  1489. ButtonIDS[0] = IDC_BOLD;
  1490. ButtonIDS[1] = IDC_ITALIC;
  1491. ButtonIDS[2] = IDC_UNDERLINE;
  1492. ButtonIDS[3] = IDC_VERTEDIT;
  1493. if (theApp.m_bPenSystem)
  1494. {
  1495. ButtonIDS[4] = ID_SEPARATOR;
  1496. ButtonIDS[5] = IDC_PENEXT;
  1497. iNumButtons = 6;
  1498. iNumSeparators = 1;
  1499. }
  1500. else
  1501. {
  1502. iNumButtons = 4;
  1503. iNumSeparators = 0;
  1504. }
  1505. }
  1506. bRC = CToolBar::Create( pcParentWnd, CBRS_ALIGN_TOP );
  1507. if (bRC == 0)
  1508. {
  1509. AfxThrowResourceException();
  1510. /*DK* ##ERROR Could not create toolbar object*/
  1511. }
  1512. bRC = LoadBitmap(IDB_TEXT_TBAR);
  1513. if (bRC == 0)
  1514. {
  1515. AfxThrowResourceException();
  1516. /*DK* ##ERROR Could not load bitmap for toolbar*/
  1517. }
  1518. bRC = SetButtons(ButtonIDS, iNumButtons);
  1519. if (bShowPen)
  1520. {
  1521. // Set the style to be checkbox style.
  1522. SetButtonInfo(BOLD_TBAR_POS, IDC_BOLD, TBBS_CHECKBOX, BOLD_BMP_POS);
  1523. SetButtonInfo(ITALIC_TBAR_POS, IDC_ITALIC, TBBS_CHECKBOX, ITALIC_BMP_POS);
  1524. SetButtonInfo(UNDERLINE_TBAR_POS, IDC_UNDERLINE, TBBS_CHECKBOX, UNDERLINE_BMP_POS);
  1525. SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX, VERTEDIT_BMP_POS);
  1526. SetButtonInfo(INS_SPACE_TBAR_POS, IDC_INS_SPACE, TBBS_BUTTON, INS_SPACE_BMP_POS);
  1527. SetButtonInfo(BACKSPACE_TBAR_POS, IDC_BACKSPACE, TBBS_BUTTON, BACKSPACE_BMP_POS);
  1528. SetButtonInfo(NEWLINE_TBAR_POS, IDC_NEWLINE, TBBS_BUTTON, NEWLINE_BMP_POS);
  1529. SetButtonInfo(EDITTEXT_TBAR_POS, IDC_EDITTEXT, TBBS_BUTTON, EDITTEXT_BMP_POS);
  1530. SetButtonInfo(PEN_TBAR_PEN_POS, IDC_PENEXT, TBBS_CHECKBOX, PEN_BMP_POS);
  1531. // presently unused
  1532. // SetButtonInfo(KEYBOARD_TBAR_POS, IDC_KEYBOARD, TBBS_BUTTON, KEYBOARD_BMP_POS);
  1533. }
  1534. else
  1535. {
  1536. // Set the style to be checkbox style.
  1537. SetButtonInfo(BOLD_TBAR_POS, IDC_BOLD, TBBS_CHECKBOX, BOLD_BMP_POS);
  1538. SetButtonInfo(ITALIC_TBAR_POS, IDC_ITALIC, TBBS_CHECKBOX, ITALIC_BMP_POS);
  1539. SetButtonInfo(UNDERLINE_TBAR_POS, IDC_UNDERLINE, TBBS_CHECKBOX, UNDERLINE_BMP_POS);
  1540. SetButtonInfo(VERTEDIT_TBAR_POS, IDC_VERTEDIT, TBBS_CHECKBOX, VERTEDIT_BMP_POS);
  1541. if (theApp.m_bPenSystem)
  1542. SetButtonInfo(PEN_TBAR_TEXT_POS, IDC_PENEXT, TBBS_CHECKBOX, PEN_BMP_POS);
  1543. }
  1544. CSize size = CToolBar::CalcFixedLayout( FALSE, TRUE );
  1545. if (GetSafeHwnd() != NULL)
  1546. {
  1547. SetWindowPos( &wndTop, 0, 0, size.cx, size.cy, SWP_NOMOVE );
  1548. }
  1549. return bRC;
  1550. }
  1551. /******************************************************************************/
  1552. CTfontTbar::~CTfontTbar(void)
  1553. {
  1554. }
  1555. /******************************************************************************/
  1556. /******************************************************************************/
  1557. // CTfontDlg
  1558. BEGIN_MESSAGE_MAP(CTfontDlg, CDialogBar)
  1559. //{{AFX_MSG_MAP(CTfontDlg)
  1560. ON_WM_RBUTTONDOWN()
  1561. ON_WM_MEASUREITEM()
  1562. ON_WM_DRAWITEM()
  1563. // ON_DM_GETDEFID()
  1564. //}}AFX_MSG_MAP
  1565. END_MESSAGE_MAP()
  1566. /******************************************************************************/
  1567. // CTfontDlg construction/destruction
  1568. CTfontDlg::CTfontDlg(void)
  1569. {
  1570. BOOL bRC;
  1571. CSize cSizeBmp(0, 0);
  1572. INT i;
  1573. m_Max_cx_FontType_BMP = 0;
  1574. // Set up the Size Structures for offsets in drawing the font typeface.
  1575. for (i = 0; i < NumCPic; i++)
  1576. {
  1577. bRC = m_cPictures[i].PictureSet(CTBitmaps[i]);
  1578. ASSERT( bRC != 0 );
  1579. if (bRC)
  1580. {
  1581. cSizeBmp = m_cPictures[i].PictureSize();
  1582. if (cSizeBmp.cx > m_Max_cx_FontType_BMP)
  1583. {
  1584. m_Max_cx_FontType_BMP = cSizeBmp.cx;
  1585. }
  1586. }
  1587. else
  1588. {
  1589. /*DK* ##ERROR could not create bitmap for tt font in owner draw lbox*/
  1590. }
  1591. }
  1592. }
  1593. /******************************************************************************/
  1594. BOOL CTfontDlg::Create(CWnd* pcParentWnd)
  1595. {
  1596. BOOL bRC = CDialogBar::Create(pcParentWnd, IDD_TEXT_FONT_DLG,
  1597. CBRS_NOALIGN, NULL);
  1598. if (bRC)
  1599. SetWindowPos(&wndTop, 0,0, m_sizeDefault.cx, m_sizeDefault.cy, SWP_NOMOVE);
  1600. return bRC;
  1601. }
  1602. /******************************************************************************/
  1603. CTfontDlg::~CTfontDlg(void)
  1604. {
  1605. }
  1606. /******************************************************************************/
  1607. void CTfontDlg::OnRButtonDown(UINT nFlags, CPoint point)
  1608. {
  1609. CWnd *pcParent = GetParent();
  1610. const MSG *pCurrentMessage = GetCurrentMessage();
  1611. pcParent->SendMessage(pCurrentMessage->message, pCurrentMessage->wParam,
  1612. pCurrentMessage->lParam);
  1613. }
  1614. /******************************************************************************/
  1615. void CTfontDlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  1616. {
  1617. TEXTMETRIC tm;
  1618. BOOL bRC;
  1619. // get default to fill in measureitem struct first
  1620. CWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
  1621. TRY
  1622. {
  1623. ASSERT( lpMeasureItemStruct->CtlType == ODT_COMBOBOX );
  1624. ASSERT( lpMeasureItemStruct->CtlID == IDC_TYPEFACE );
  1625. if (lpMeasureItemStruct->CtlType != ODT_COMBOBOX
  1626. || lpMeasureItemStruct->CtlID != IDC_TYPEFACE)
  1627. {
  1628. AfxThrowNotSupportedException();
  1629. }
  1630. CClientDC cdcClient(this);
  1631. bRC = cdcClient.GetTextMetrics(&tm);
  1632. ASSERT(bRC !=0);
  1633. if (bRC != 0)
  1634. {
  1635. lpMeasureItemStruct->itemHeight = tm.tmAscent + 2;
  1636. }
  1637. }
  1638. CATCH(CNotSupportedException,e)
  1639. {
  1640. }
  1641. END_CATCH
  1642. }
  1643. /******************************************************************************/
  1644. void CTfontDlg::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct, CString *pcStringText)
  1645. {
  1646. CBrush* cpBrush;
  1647. BOOL bSelected;
  1648. BOOL bRC;
  1649. CDC cdcCombo;
  1650. BOOL bDrawPicture = FALSE;
  1651. CRect cRectText;
  1652. int iPictureHeight = 0;
  1653. CSize cSizeBmp(0,0);
  1654. int ix = 0;
  1655. int iy = 0;
  1656. CFontDesc* pDesc = (CFontDesc*)lpDrawItemStruct->itemData;
  1657. CFontComboBox *pwndCombo = (CFontComboBox *)CFontComboBox::FromHandle(lpDrawItemStruct->hwndItem);
  1658. if (pwndCombo)
  1659. {
  1660. // Only need to check the item before and after
  1661. if (!pwndCombo->IsSameName(pDesc, lpDrawItemStruct->itemID - 1)
  1662. && !pwndCombo->IsSameName(pDesc, lpDrawItemStruct->itemID + 1))
  1663. {
  1664. pcStringText = &pDesc->m_strName;
  1665. }
  1666. }
  1667. // Set the picture object up to draw a picture if one is needed (if this
  1668. // font is a printer/true type font).
  1669. bDrawPicture = TRUE;
  1670. switch (pDesc->m_iFontType)
  1671. {
  1672. case DEVICE_FONT:
  1673. cSizeBmp = m_cPictures[1].PictureSize();
  1674. break;
  1675. case TT_FONT:
  1676. cSizeBmp = m_cPictures[0].PictureSize();
  1677. break;
  1678. case TT_OPENTYPE_FONT:
  1679. cSizeBmp = m_cPictures[2].PictureSize();
  1680. break;
  1681. case PS_OPENTYPE_FONT:
  1682. cSizeBmp = m_cPictures[3].PictureSize();
  1683. break;
  1684. case TYPE1_FONT:
  1685. cSizeBmp = m_cPictures[4].PictureSize();
  1686. break;
  1687. default:
  1688. bDrawPicture = FALSE;
  1689. break;
  1690. }
  1691. if (bDrawPicture)
  1692. {
  1693. iPictureHeight = cSizeBmp.cy;
  1694. }
  1695. TRY
  1696. {
  1697. if ( (lpDrawItemStruct->itemState & ODS_SELECTED) == ODS_SELECTED)
  1698. {
  1699. bSelected = TRUE;
  1700. cpBrush = GetSysBrush( COLOR_HIGHLIGHT );
  1701. }
  1702. else
  1703. {
  1704. bSelected = FALSE;
  1705. cpBrush = GetSysBrush( COLOR_WINDOW );
  1706. }
  1707. if (! cpBrush)
  1708. {
  1709. /*DK* ##ERROR Could not create solid brush */
  1710. AfxThrowNotSupportedException();
  1711. }
  1712. bRC = cdcCombo.Attach(lpDrawItemStruct->hDC);
  1713. ASSERT(bRC != 0);
  1714. if (bRC == 0)
  1715. {
  1716. AfxThrowNotSupportedException();
  1717. }
  1718. SetColorsInDC(lpDrawItemStruct->hDC, bSelected);
  1719. cdcCombo.FillRect(&(lpDrawItemStruct->rcItem), cpBrush);
  1720. // If this is a Printer or True Type font, draw the image/picture.
  1721. if (bDrawPicture)
  1722. {
  1723. ix = lpDrawItemStruct->rcItem.left + 1; // 0 is focus rect
  1724. //center vertically
  1725. iy = lpDrawItemStruct->rcItem.top +
  1726. abs(((lpDrawItemStruct->rcItem.bottom -
  1727. lpDrawItemStruct->rcItem.top) - iPictureHeight))/2;
  1728. switch (pDesc->m_iFontType)
  1729. {
  1730. case DEVICE_FONT:
  1731. m_cPictures[1].Picture(&cdcCombo, ix, iy);
  1732. break;
  1733. case TT_FONT:
  1734. m_cPictures[0].Picture(&cdcCombo, ix, iy);
  1735. break;
  1736. case TT_OPENTYPE_FONT:
  1737. m_cPictures[2].Picture(&cdcCombo, ix, iy);
  1738. break;
  1739. case PS_OPENTYPE_FONT:
  1740. m_cPictures[3].Picture(&cdcCombo, ix, iy);
  1741. break;
  1742. case TYPE1_FONT:
  1743. m_cPictures[4].Picture(&cdcCombo, ix, iy);
  1744. break;
  1745. default:
  1746. break;
  1747. }
  1748. }
  1749. // set the rectangle for the text, and draw the text
  1750. cRectText = lpDrawItemStruct->rcItem;
  1751. cRectText.left += m_Max_cx_FontType_BMP + FONT_BMP_TXT_BORDER;
  1752. cdcCombo.DrawText(*pcStringText, -1, &(cRectText), DT_LEFT | DT_SINGLELINE | DT_VCENTER);
  1753. if ( (lpDrawItemStruct->itemState & ODS_FOCUS) == ODS_FOCUS)
  1754. {
  1755. cdcCombo.DrawFocusRect(&(lpDrawItemStruct->rcItem));
  1756. }
  1757. }
  1758. CATCH(CNotSupportedException,e)
  1759. {
  1760. /*DK* ##ERROR Internal Thown Unsupported Exception */
  1761. }
  1762. END_CATCH
  1763. cdcCombo.Detach();
  1764. }
  1765. /******************************************************************************/
  1766. // bInverted is the same as text selected.
  1767. void CTfontDlg::SetColorsInDC(HDC hdc, BOOL bInverted)
  1768. {
  1769. DWORD dwFGColor;
  1770. DWORD dwBKColor;
  1771. if (bInverted)
  1772. {
  1773. dwFGColor = ::GetSysColor( COLOR_HIGHLIGHTTEXT );
  1774. dwBKColor = ::GetSysColor( COLOR_HIGHLIGHT );
  1775. }
  1776. else
  1777. {
  1778. dwFGColor = ::GetSysColor( COLOR_WINDOWTEXT );
  1779. dwBKColor = ::GetSysColor( COLOR_WINDOW );
  1780. }
  1781. ::SetTextColor( hdc, dwFGColor );
  1782. ::SetBkMode ( hdc, OPAQUE );
  1783. ::SetBkColor( hdc, dwBKColor );
  1784. }