StyleBar.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // StyleBar.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "EastDraw.h"
  5. #include "EastDrawDoc.h"
  6. #include "EastDrawView.h"
  7. #include "StyleBar.h"
  8. #include"CUnit.h"
  9. #include "MainFrm.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CStyleBar
  17. BEGIN_MESSAGE_MAP(CStyleBar, CToolBar)
  18. //{{AFX_MSG_MAP(CStyleBar)
  19. ON_WM_CREATE()
  20. ON_WM_ACTIVATE()
  21. //}}AFX_MSG_MAP
  22. ON_CBN_SELENDOK (IDC_FONTNAMES, OnSelectFont)
  23. ON_CBN_SELENDOK (IDC_FONTSIZES, OnSelectSize)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CStyleBar message handlers
  27. int CStyleBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  28. {
  29. static int nFontSizes[] = {1,2,3,4,5,6,7,
  30. 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 48, 72
  31. };
  32. if (CToolBar::OnCreate(lpCreateStruct) == -1)
  33. return -1;
  34. if (!LoadToolBar (IDR_STYLE_BAR))
  35. return -1;
  36. CClientDC dc (this);
  37. m_font.CreatePointFont (80, _T ("MS Sans Serif"));
  38. CFont* pOldFont = dc.SelectObject (&m_font);
  39. TEXTMETRIC tm;
  40. dc.GetTextMetrics (&tm);
  41. int cxChar = tm.tmAveCharWidth;
  42. int cyChar = tm.tmHeight + tm.tmExternalLeading;
  43. dc.SelectObject (pOldFont);
  44. SetButtonInfo (4, IDC_FONTNAMES, TBBS_SEPARATOR, cxChar * 32);
  45. CRect rect;
  46. GetItemRect (4, &rect);
  47. rect.bottom = rect.top + (cyChar * 16);
  48. if (!m_wndFontNames.Create (WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  49. CBS_DROPDOWNLIST | CBS_SORT, rect, this, IDC_FONTNAMES))
  50. return -1;
  51. m_wndFontNames.SetFont (&m_font);
  52. InitTypefaceList (&dc);
  53. SetButtonInfo (6, IDC_FONTSIZES, TBBS_SEPARATOR, cxChar * 12);
  54. GetItemRect (6, &rect);
  55. rect.bottom = rect.top + (cyChar * 14);
  56. if (!m_wndFontSizes.Create (WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  57. CBS_DROPDOWNLIST, rect, this, IDC_FONTSIZES))
  58. return -1;
  59. m_wndFontSizes.SetFont (&m_font);
  60. CString string;
  61. int nCount = sizeof (nFontSizes) / sizeof (int);
  62. for (int k=0; k<nCount; k++) {
  63. string.Format (_T ("%d"), nFontSizes[k]);
  64. m_wndFontSizes.AddString (string);
  65. }
  66. m_wndFontSizes.SetCurSel(2);
  67. m_wndFontNames.SetCurSel(m_wndFontNames.FindString(0,"Arial"));
  68. isBoldUp=true;
  69. isUnderlineUp=true;
  70. isItalicUp=true;
  71. return 0;
  72. }
  73. void CStyleBar::OnSelectFont ()
  74. {
  75. TCHAR szFaceName[LF_FACESIZE];
  76. int nIndex = m_wndFontNames.GetCurSel ();
  77. m_wndFontNames.GetLBText (nIndex, szFaceName);
  78. CMDIChildWnd*pChild=((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
  79. CEastDrawView*pView=(CEastDrawView*)pChild->GetActiveView();
  80. ENUMLOGFONT lpelf;
  81. m_FontMap.Lookup(nIndex,lpelf);
  82. TCHAR szSize[8];
  83. int nIndex1 = m_wndFontSizes.GetCurSel ();
  84. m_wndFontSizes.GetLBText (nIndex1, szSize);
  85. int nSize = atoi (szSize) *5;
  86. float fmultiple=float(nSize)/float(lpelf.elfLogFont.lfHeight);
  87. lpelf.elfLogFont.lfHeight=nSize;
  88. lpelf.elfLogFont.lfWidth=nSize*fmultiple;
  89. lpelf.elfLogFont.lfWeight=this->isBoldUp?FW_NORMAL:FW_BOLD;
  90. lpelf.elfLogFont.lfItalic=this->isItalicUp?0:1;
  91. lpelf.elfLogFont.lfUnderline=this->isUnderlineUp?0:1;
  92. if(pView->m_LBDownTimes==1)
  93. pView->m_pCurrentUnit->ChangeFont(&lpelf);
  94. }
  95. void CStyleBar::OnSelectSize ()
  96. {
  97. TCHAR szSize[8];
  98. int nIndex = m_wndFontSizes.GetCurSel ();
  99. m_wndFontSizes.GetLBText (nIndex, szSize);
  100. int nSize = atoi (szSize) *5; // Need twips
  101. CMDIChildWnd*pChild=((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
  102. CEastDrawView*pView=(CEastDrawView*)pChild->GetActiveView();
  103. ENUMLOGFONT lpelf;
  104. nIndex = m_wndFontNames.GetCurSel ();
  105. this->m_FontMap.Lookup(nIndex,lpelf);
  106. float fmultiple=float(nSize)/float(lpelf.elfLogFont.lfHeight);
  107. lpelf.elfLogFont.lfHeight=nSize;
  108. lpelf.elfLogFont.lfWidth=nSize*fmultiple;
  109. lpelf.elfLogFont.lfWeight=this->isBoldUp?FW_NORMAL:FW_BOLD;
  110. lpelf.elfLogFont.lfItalic=this->isItalicUp?0:1;
  111. lpelf.elfLogFont.lfUnderline=this->isUnderlineUp?0:1;
  112. pView->m_pCurrentUnit->ChangeFontSize(&lpelf);
  113. }
  114. void CStyleBar::InitTypefaceList (CDC* pDC)
  115. {
  116. ::EnumFontFamilies (pDC->m_hDC, NULL,
  117. (FONTENUMPROC) EnumFontNameProc, (LPARAM) this);
  118. }
  119. int CALLBACK CStyleBar::EnumFontNameProc (ENUMLOGFONT* lpelf,
  120. NEWTEXTMETRIC* lpntm, int nFontType, LPARAM lParam)
  121. {
  122. CStyleBar* pWnd = (CStyleBar*) lParam;
  123. int i=pWnd->m_wndFontNames.GetCount();
  124. if (nFontType & TRUETYPE_FONTTYPE)
  125. {
  126. pWnd->m_wndFontNames.InsertString(i,lpelf->elfLogFont.lfFaceName);
  127. pWnd->m_FontMap[i]=*lpelf;
  128. }
  129. return 1;
  130. }
  131. void CStyleBar::OnCharBold()
  132. {
  133. // TODO: Add your command handler code here
  134. TCHAR szSize[8];
  135. int nIndex = m_wndFontSizes.GetCurSel ();
  136. m_wndFontSizes.GetLBText (nIndex, szSize);
  137. int nSize = atoi (szSize) *5;
  138. CMDIChildWnd*pChild=((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
  139. CEastDrawView*pView=(CEastDrawView*)pChild->GetActiveView();
  140. ENUMLOGFONT lpelf;
  141. nIndex = m_wndFontNames.GetCurSel ();
  142. this->m_FontMap.Lookup(nIndex,lpelf);
  143. float fmultiple=float(nSize)/float(lpelf.elfLogFont.lfHeight);
  144. lpelf.elfLogFont.lfHeight=nSize;
  145. lpelf.elfLogFont.lfWidth=nSize*fmultiple;
  146. lpelf.elfLogFont.lfWeight=this->isBoldUp?FW_BOLD:FW_NORMAL;
  147. lpelf.elfLogFont.lfItalic=this->isItalicUp?0:1;
  148. lpelf.elfLogFont.lfUnderline=this->isUnderlineUp?0:1;
  149. isBoldUp=!isBoldUp;
  150. if(pView->m_LBDownTimes==1)
  151. pView->m_pCurrentUnit->ChangeFontSize(&lpelf);
  152. }
  153. void CStyleBar::OnCharItalic()
  154. {
  155. TCHAR szSize[8];
  156. int nIndex = m_wndFontSizes.GetCurSel ();
  157. m_wndFontSizes.GetLBText (nIndex, szSize);
  158. int nSize = atoi (szSize) *5;
  159. CMDIChildWnd*pChild=((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
  160. CEastDrawView*pView=(CEastDrawView*)pChild->GetActiveView();
  161. ENUMLOGFONT lpelf;
  162. nIndex = m_wndFontNames.GetCurSel ();
  163. this->m_FontMap.Lookup(nIndex,lpelf);
  164. float fmultiple=float(nSize)/float(lpelf.elfLogFont.lfHeight);
  165. lpelf.elfLogFont.lfHeight=nSize;
  166. lpelf.elfLogFont.lfWidth=nSize*fmultiple;
  167. lpelf.elfLogFont.lfWeight=this->isBoldUp?FW_NORMAL:FW_BOLD;
  168. lpelf.elfLogFont.lfItalic=this->isItalicUp?1:0;
  169. lpelf.elfLogFont.lfUnderline=this->isUnderlineUp?0:1;
  170. isItalicUp=!isItalicUp;
  171. if(pView->m_LBDownTimes==1)
  172. pView->m_pCurrentUnit->ChangeFontSize(&lpelf);
  173. }
  174. void CStyleBar::OnCharUnderline()
  175. {
  176. static BOOL isUp=true;
  177. TCHAR szSize[8];
  178. int nIndex = m_wndFontSizes.GetCurSel ();
  179. m_wndFontSizes.GetLBText (nIndex, szSize);
  180. int nSize = atoi (szSize) *5;
  181. CMDIChildWnd*pChild=((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
  182. CEastDrawView*pView=(CEastDrawView*)pChild->GetActiveView();
  183. ENUMLOGFONT lpelf;
  184. nIndex = m_wndFontNames.GetCurSel ();
  185. this->m_FontMap.Lookup(nIndex,lpelf);
  186. float fmultiple=float(nSize)/float(lpelf.elfLogFont.lfHeight);
  187. lpelf.elfLogFont.lfHeight=nSize;
  188. lpelf.elfLogFont.lfWidth=nSize*fmultiple;
  189. lpelf.elfLogFont.lfWeight=this->isBoldUp?FW_NORMAL:FW_BOLD;
  190. lpelf.elfLogFont.lfItalic=this->isItalicUp?0:1;
  191. lpelf.elfLogFont.lfUnderline=this->isUnderlineUp?1:0;
  192. isUnderlineUp=!isUnderlineUp;
  193. if(pView->m_LBDownTimes==1)
  194. pView->m_pCurrentUnit->ChangeFontSize(&lpelf);
  195. }
  196. void CStyleBar::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
  197. {
  198. CToolBar::OnActivate(nState, pWndOther, bMinimized);
  199. // TODO: Add your message handler code here
  200. }
  201. void CStyleBar::IniFont()
  202. {
  203. this->OnSelectFont();
  204. }