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.

282 lines
6.1 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* Gage when import bitmap */
  5. /* (Dialog) */
  6. /* */
  7. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  8. /**************************************************/
  9. #include "stdafx.h"
  10. #include "eudcedit.h"
  11. #include "gagedlg.h"
  12. #include "extfunc.h"
  13. #include "util.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #endif
  18. extern TCHAR UserFont[MAX_PATH];
  19. extern TCHAR EUDCTTF[MAX_PATH];
  20. extern TCHAR EUDCBMP[MAX_PATH];
  21. static HWND hDlg;
  22. static UINT nEUDC;
  23. static UINT cEUDC;
  24. static BOOL ExecuteFlag;
  25. static BOOL testtest;
  26. extern BOOL g_bKeepEUDCLink;
  27. BOOL SendImportMessage( unsigned int cEudc, unsigned int nEudc);
  28. /****************************************/
  29. /* */
  30. /* Constructor */
  31. /* */
  32. /****************************************/
  33. CGageDlg::CGageDlg( CWnd* pParent, LPTSTR szUserFont, LPTSTR szBmpFile, LPTSTR szTtfFile, BOOL bIsWin95EUDC)
  34. : CDialog(CGageDlg::IDD, pParent)
  35. {
  36. lstrcpy (m_szTtfFile, szTtfFile? szTtfFile : EUDCTTF);
  37. lstrcpy (m_szBmpFile, szBmpFile? szBmpFile : EUDCBMP);
  38. lstrcpy (m_szUserFont, szUserFont? szUserFont : UserFont);
  39. m_bIsWin95EUDC = bIsWin95EUDC;
  40. //{{AFX_DATA_INIT(CGageDlg)
  41. //}}AFX_DATA_INIT
  42. }
  43. /****************************************/
  44. /* */
  45. /* MESSAGE "WM_INITDIALOG" */
  46. /* */
  47. /****************************************/
  48. BOOL
  49. CGageDlg::OnInitDialog()
  50. {
  51. CString DlgTitle;
  52. CDialog::OnInitDialog();
  53. // Implement "?" in this dialog.
  54. DlgTitle.LoadString( IDS_IMPORT_DLGTITLE);
  55. this->SetWindowText( DlgTitle);
  56. // Set Dialog Title name.
  57. m_EditGage.SubclassDlgItem( IDC_GAGE, this);
  58. hDlg = this->GetSafeHwnd();
  59. testtest = FALSE;
  60. OutputMessageBox( this->GetSafeHwnd(),
  61. IDS_MAINFRAMETITLE,
  62. IDS_IMPORTFONT_MSG, TRUE);
  63. return TRUE;
  64. }
  65. /****************************************/
  66. /* */
  67. /* COMMAND "OK" */
  68. /* */
  69. /****************************************/
  70. void
  71. CGageDlg::OnOK()
  72. {
  73. ExecuteFlag = FALSE;
  74. CDialog::OnOK();
  75. }
  76. /****************************************/
  77. /* */
  78. /* Window procedure */
  79. /* */
  80. /****************************************/
  81. LRESULT
  82. CGageDlg::WindowProc(
  83. UINT message,
  84. WPARAM wParam,
  85. LPARAM lParam)
  86. {
  87. int sts;
  88. if( message == WM_IMPORTGAGE){
  89. if( lParam){
  90. cEUDC = (UINT)wParam;
  91. nEUDC = (UINT)lParam;
  92. m_EditGage.Invalidate( FALSE);
  93. m_EditGage.UpdateWindow();
  94. }
  95. return (0L);
  96. }
  97. if( message == WM_IMPORTSTOP){
  98. ExecuteFlag = TRUE;
  99. // The code is to fix the related bug #421829 & #438677
  100. // It delays 1 second to call EnabelEUDC(FALSE).
  101. DWORD dwStart = GetTickCount();
  102. // Stop if this has taken too long
  103. while (1)
  104. {
  105. if( GetTickCount() - dwStart >= 1000 )
  106. break;
  107. }
  108. EnableEUDC( FALSE);
  109. sts = Import(m_szUserFont, m_szBmpFile, m_szTtfFile,
  110. BITMAP_WIDTH, BITMAP_HEIGHT, SMOOTHLVL, m_bIsWin95EUDC);
  111. //
  112. // we import some glyphs and will not delete the link.
  113. //
  114. g_bKeepEUDCLink = TRUE;
  115. EnableEUDC( TRUE);
  116. if( sts) return (0L); // for debug
  117. return (0L);
  118. }
  119. return CDialog::WindowProc( message, wParam, lParam);
  120. }
  121. /****************************************/
  122. /* */
  123. /* Default Constructor */
  124. /* */
  125. /****************************************/
  126. CEditGage::CEditGage()
  127. {
  128. }
  129. /****************************************/
  130. /* */
  131. /* Destructor */
  132. /* */
  133. /****************************************/
  134. CEditGage::~CEditGage()
  135. {
  136. }
  137. /****************************************/
  138. /* */
  139. /* MESSAGE "WM_PAINT" */
  140. /* */
  141. /****************************************/
  142. void
  143. CEditGage::OnPaint()
  144. {
  145. TCHAR cEUDCBuf[10];
  146. TCHAR nEUDCBuf[10];
  147. TCHAR ViewBuf[30];
  148. CRect EditGageRect;
  149. CRect BrueGageRect, WhiteGageRect;
  150. CBrush wBrush, bBrush;
  151. CPaintDC dc( this);
  152. this->GetClientRect( &EditGageRect);
  153. if( !testtest){
  154. testtest = TRUE;
  155. ::SendMessage( hDlg, WM_IMPORTSTOP, (WPARAM)0, (LPARAM)0);
  156. }else{
  157. if( nEUDC){
  158. wsprintf( cEUDCBuf, TEXT("%d"), cEUDC);
  159. wsprintf( nEUDCBuf, TEXT("%d"), nEUDC);
  160. lstrcpy(ViewBuf, cEUDCBuf);
  161. lstrcat(ViewBuf, TEXT(" /"));
  162. lstrcat(ViewBuf, nEUDCBuf);
  163. GetParent()->SetDlgItemText( IDC_IMPORT_STATIC, (LPCTSTR)ViewBuf);
  164. BrueGageRect.CopyRect( &EditGageRect);
  165. WhiteGageRect.CopyRect( &EditGageRect);
  166. BrueGageRect.right = (cEUDC*EditGageRect.Width()) / nEUDC;
  167. WhiteGageRect.left = BrueGageRect.right;
  168. bBrush.CreateSolidBrush(COLOR_BLUE);
  169. dc.FillRect( &BrueGageRect, &bBrush);
  170. bBrush.DeleteObject();
  171. wBrush.CreateStockObject( WHITE_BRUSH);
  172. dc.FillRect( &WhiteGageRect, &wBrush);
  173. wBrush.DeleteObject();
  174. }
  175. }
  176. if( cEUDC >= nEUDC){
  177. ::SendMessage( hDlg, WM_COMMAND, (WPARAM)IDOK, (LPARAM)0);
  178. }
  179. }
  180. /****************************************/
  181. /* */
  182. /* MESSAGE "WM_ONLBUTTONDOWN" */
  183. /* */
  184. /****************************************/
  185. void
  186. CEditGage::OnLButtonDown(
  187. UINT nFlags,
  188. CPoint point)
  189. {
  190. }
  191. /****************************************/
  192. /* */
  193. /* MESSAGE "WM_SETCURSOR" */
  194. /* */
  195. /****************************************/
  196. BOOL
  197. CEditGage::OnSetCursor(
  198. CWnd* pWnd,
  199. UINT nHitTest,
  200. UINT message)
  201. {
  202. ::SetCursor( AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  203. return TRUE;
  204. }
  205. BEGIN_MESSAGE_MAP( CEditGage, CEdit)
  206. //{{AFX_MSG_MAP( CEditGage)
  207. ON_WM_PAINT()
  208. ON_WM_LBUTTONDOWN()
  209. ON_WM_SETCURSOR()
  210. ON_WM_RBUTTONUP()
  211. //}}AFX_MSG_MAP
  212. END_MESSAGE_MAP()
  213. /****************************************/
  214. /* */
  215. /* Send Import Message */
  216. /* */
  217. /****************************************/
  218. BOOL
  219. SendImportMessage(
  220. unsigned int cEudc,
  221. unsigned int nEudc)
  222. {
  223. MSG msg;
  224. while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)){
  225. if( msg.message == WM_QUIT)
  226. break;
  227. TranslateMessage( &msg);
  228. DispatchMessage( &msg);
  229. }
  230. if( !ExecuteFlag){
  231. cEudc = 0;
  232. nEudc = 0;
  233. return FALSE;
  234. }
  235. SendMessage( hDlg, WM_IMPORTGAGE, (WPARAM)cEudc, (LPARAM)nEudc);
  236. return TRUE;
  237. }
  238. BEGIN_MESSAGE_MAP(CGageDlg, CDialog)
  239. //{{AFX_MSG_MAP(CGageDlg)
  240. //}}AFX_MSG_MAP
  241. END_MESSAGE_MAP()
  242. void CEditGage::OnRButtonUp(UINT nFlags, CPoint point)
  243. {
  244. }