Leaked source code of windows server 2003
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.

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