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.

3304 lines
89 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* MDI Child Window( For Edit) */
  5. /* */
  6. /* */
  7. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  8. /**************************************************/
  9. #include "stdafx.h"
  10. #include "eudcedit.h"
  11. #include "editwnd.h"
  12. #include "refrwnd.h"
  13. #include "vdata.h"
  14. #include "extfunc.h"
  15. #include "util.h"
  16. #include "rotatdlg.h"
  17. #define STRSAFE_LIB
  18. #include <strsafe.h>
  19. // For mouse
  20. #define NCLICK 0
  21. #define LCLICK 1
  22. #define RCLICK 2
  23. // For selected rectangle
  24. #define LUPPER 0
  25. #define RUPPER 1
  26. #define RLOWER 2
  27. #define LLOWER 3
  28. #define MUPPER 4
  29. #define RMIDLE 5
  30. #define MLOWER 6
  31. #define LMIDLE 7
  32. #define NCHECK 8
  33. // For Rectangular selection and freeform selection
  34. #define BMP 0
  35. #define DSP 1
  36. #define PRV 2
  37. #define VLD 3
  38. #define PIN 4
  39. // max of freeform selection point
  40. #define FREELIAIS 1000
  41. #define MKOUTHDL 2
  42. #ifdef _DEBUG
  43. #undef THIS_FILE
  44. static char BASED_CODE THIS_FILE[] = __FILE__;
  45. #endif
  46. CMenu NEAR CEditWnd::menu;
  47. IMPLEMENT_DYNCREATE( CEditWnd, CMDIChildWnd)
  48. BEGIN_MESSAGE_MAP(CEditWnd, CMDIChildWnd)
  49. //{{AFX_MSG_MAP(CEditWnd)
  50. ON_WM_LBUTTONDOWN()
  51. ON_WM_LBUTTONUP()
  52. ON_WM_MOUSEMOVE()
  53. ON_WM_PAINT()
  54. ON_WM_CREATE()
  55. ON_COMMAND(ID_GAIJI_COPY, OnGaijiCopy)
  56. ON_COMMAND(ID_GAIJI_CUT, OnGaijiCut)
  57. ON_COMMAND(ID_GAIJI_PASTE, OnGaijiPaste)
  58. ON_COMMAND(ID_GAIJI_UNDO, OnGaijiUndo)
  59. ON_WM_RBUTTONDOWN()
  60. ON_WM_RBUTTONUP()
  61. ON_WM_SIZE()
  62. ON_WM_SETCURSOR()
  63. ON_UPDATE_COMMAND_UI(ID_GAIJI_PASTE, OnUpdateGaijiPaste)
  64. ON_WM_MDIACTIVATE()
  65. ON_UPDATE_COMMAND_UI(ID_GAIJI_COPY, OnUpdateGaijiCopy)
  66. ON_UPDATE_COMMAND_UI(ID_GAIJI_CUT, OnUpdateGaijiCut)
  67. ON_COMMAND(ID_DELETE_EDIT, OnDeleteEdit)
  68. ON_UPDATE_COMMAND_UI(ID_DELETE_EDIT, OnUpdateDeleteEdit)
  69. ON_UPDATE_COMMAND_UI(ID_GAIJI_UNDO, OnUpdateGaijiUndo)
  70. ON_WM_KEYDOWN()
  71. ON_WM_CLOSE()
  72. //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74. // Global parameter
  75. LOGFONT EditLogFont;
  76. extern int SelectItems;
  77. extern CBitmap DupBmp;
  78. extern CRect DupRect;
  79. extern CRefrWnd *pRefrChild;
  80. extern BOOL g_bKeepEUDCLink;
  81. /****************************************/
  82. /* */
  83. /* Create MDI child window for edit */
  84. /* */
  85. /****************************************/
  86. BOOL
  87. CEditWnd::Create(
  88. LPCTSTR szTitle,
  89. LONG Style,
  90. RECT EudcWndRect,
  91. CMDIFrameWnd* Parent)
  92. {
  93. // Load menu as same as MainFrame
  94. if( menu.m_hMenu == NULL)
  95. menu.LoadMenu( IDR_MAINFRAME);
  96. m_hMenuShared = menu.m_hMenu;
  97. // Register window class of MDI child for edit
  98. const TCHAR *pszEudcWndClass =
  99. AfxRegisterWndClass( CS_BYTEALIGNCLIENT,
  100. NULL, (HBRUSH)(COLOR_WINDOW+1), NULL);
  101. return CMDIChildWnd::Create( pszEudcWndClass,
  102. szTitle, Style, EudcWndRect, Parent);
  103. }
  104. /****************************************/
  105. /* */
  106. /* Process before window is created */
  107. /* */
  108. /****************************************/
  109. int
  110. CEditWnd::OnCreate( LPCREATESTRUCT lpCreateStruct)
  111. {
  112. if( CMDIChildWnd::OnCreate( lpCreateStruct) == -1)
  113. goto ERR;
  114. // If it is mirrored then turn off mirroing.
  115. ModifyStyleEx( WS_EX_LAYOUTRTL, 0);
  116. if( !CreateNewBitmap())
  117. goto ERR;
  118. if( !ClipPickValueInit())
  119. goto ERR;
  120. if( !InitEditLogfont())
  121. goto ERR;
  122. return 0;
  123. ERR:
  124. return -1;
  125. }
  126. /****************************************/
  127. /* */
  128. /* Create bitmap, and initialized */
  129. /* */
  130. /****************************************/
  131. BOOL
  132. CEditWnd::CreateNewBitmap()
  133. {
  134. WORD BitSize;
  135. HANDLE BitInit;
  136. BYTE *BitmapPtr;
  137. CClientDC ChildDC( this);
  138. if( !ImageDC.CreateCompatibleDC( &ChildDC))
  139. return FALSE;
  140. if( !CRTDrawDC.CreateCompatibleDC( &ChildDC))
  141. return FALSE;
  142. BitSize = (WORD)((( BITMAP_WIDTH +15) /16) *2) *(WORD)BITMAP_HEIGHT;
  143. if (BitSize == 0)
  144. {
  145. return (FALSE);
  146. }
  147. if(( BitInit = LocalAlloc( LMEM_MOVEABLE, BitSize)) == 0)
  148. return FALSE;
  149. if(( BitmapPtr = (BYTE *)LocalLock( BitInit)) == NULL){
  150. LocalFree( BitInit);
  151. return FALSE;
  152. }
  153. // Initialize with white color
  154. memset( BitmapPtr, 0xffff, BitSize);
  155. if( !ImageBmp.CreateBitmap( BITMAP_WIDTH, BITMAP_HEIGHT,
  156. 1, 1, (LPSTR)BitmapPtr)){
  157. LocalUnlock( BitInit);
  158. LocalFree( BitInit);
  159. return FALSE;
  160. }
  161. // Initialize with white color
  162. if( !CRTDrawBmp.CreateBitmap( BITMAP_WIDTH, BITMAP_HEIGHT,
  163. 1, 1, (LPSTR)BitmapPtr)){
  164. LocalUnlock( BitInit);
  165. LocalFree( BitInit);
  166. return FALSE;
  167. }
  168. LocalUnlock( BitInit);
  169. LocalFree( BitInit);
  170. ImageDC.SelectObject( &ImageBmp);
  171. CRTDrawDC.SelectObject( &CRTDrawBmp);
  172. return TRUE;
  173. }
  174. /****************************************/
  175. /* */
  176. /* Registry clipboard format */
  177. /* */
  178. /****************************************/
  179. BOOL
  180. CEditWnd::ClipPickValueInit()
  181. {
  182. // Register "EUDCEDIT" clipboard format
  183. if( !( ClipboardFormat = RegisterClipboardFormat(TEXT("EudcEdit"))))
  184. return FALSE;
  185. return TRUE;
  186. }
  187. /****************************************/
  188. /* */
  189. /* Initialize EditLogFont */
  190. /* */
  191. /****************************************/
  192. BOOL
  193. CEditWnd::InitEditLogfont()
  194. {
  195. CFont cFont;
  196. #ifdef BUILD_ON_WINNT
  197. cFont.CreateStockObject(DEFAULT_GUI_FONT);
  198. #else
  199. cFont.CreateStockObject( SYSTEM_FONT);
  200. #endif
  201. cFont.GetObject( sizeof(LOGFONT), &EditLogFont);
  202. cFont.DeleteObject();
  203. return TRUE;
  204. }
  205. /****************************************/
  206. /* */
  207. /* Default Constructor */
  208. /* */
  209. /****************************************/
  210. CEditWnd::CEditWnd()
  211. {
  212. // Initialize static parameter
  213. BitmapDirty = FALSE;
  214. GridShow = TRUE;
  215. SelectItem = PEN;
  216. RectClipFlag = FALSE;
  217. CheckNum = NCHECK;
  218. ButtonFlag = NCLICK;
  219. IsCapture = FALSE;
  220. UndoBitmapFlag = FALSE;
  221. FlagTmp = FALSE;
  222. UpdateCode = 0x0000;
  223. Ratio = 3;
  224. bFocus = TRUE;
  225. }
  226. /****************************************/
  227. /* */
  228. /* Destructor */
  229. /* */
  230. /****************************************/
  231. CEditWnd::~CEditWnd()
  232. {
  233. // Delete CDC and CBitmap object
  234. if( CRTDrawBmp.Detach() != NULL)
  235. CRTDrawBmp.DeleteObject();
  236. if( ImageBmp.Detach() != NULL)
  237. ImageBmp.DeleteObject();
  238. if( CRTDrawDC.Detach() != NULL)
  239. CRTDrawDC.DeleteDC();
  240. if( ImageDC.Detach() != NULL)
  241. ImageDC.DeleteDC();
  242. if( UndoImage.Detach() != NULL)
  243. UndoImage.DeleteObject();
  244. menu.DestroyMenu();
  245. }
  246. /****************************************/
  247. /* */
  248. /* COMMAND "UNDO" */
  249. /* */
  250. /****************************************/
  251. void
  252. CEditWnd::OnGaijiUndo()
  253. {
  254. int wSize;
  255. LPBYTE pBuf1, pBuf2;
  256. if( !UndoBitmapFlag)
  257. CreateUndoBitmap();
  258. UndoBitmapFlag = TRUE;
  259. if( SelectItem == RECTCLIP || SelectItem == FREEFORM)
  260. WriteSelRectBitmap();
  261. wSize = (int)((( BITMAP_WIDTH +15) /16) *2) *(int)BITMAP_HEIGHT;
  262. pBuf1 = (LPBYTE)malloc( wSize);
  263. pBuf2 = (LPBYTE)malloc( wSize);
  264. ImageBmp.GetBitmapBits( wSize, (LPVOID)pBuf1);
  265. UndoImage.GetBitmapBits( wSize, (LPVOID)pBuf2);
  266. ImageBmp.SetBitmapBits( wSize, (LPVOID)pBuf2);
  267. UndoImage.SetBitmapBits( wSize, (LPVOID)pBuf1);
  268. free(pBuf1);
  269. free(pBuf2);
  270. this->Invalidate(FALSE);
  271. this->UpdateWindow();
  272. }
  273. /****************************************/
  274. /* */
  275. /* COMMAND "UNDO" (Update) */
  276. /* */
  277. /****************************************/
  278. void
  279. CEditWnd::OnUpdateGaijiUndo(
  280. CCmdUI* pCmdUI)
  281. {
  282. if( BitmapDirty)
  283. pCmdUI->Enable(TRUE);
  284. else pCmdUI->Enable(FALSE);
  285. }
  286. /****************************************/
  287. /* */
  288. /* COMMAND "CUT" */
  289. /* */
  290. /****************************************/
  291. void
  292. CEditWnd::OnGaijiCut()
  293. {
  294. UndoImageDraw();
  295. BitmapDirty = TRUE;
  296. ClipImageCopy();
  297. ClipImageCut();
  298. this->Invalidate(FALSE);
  299. if( RectClipFlag){
  300. ToolTerm();
  301. RectClipFlag = FALSE;
  302. }
  303. }
  304. /****************************************/
  305. /* */
  306. /* COMMAND "Cut" (Update) */
  307. /* */
  308. /****************************************/
  309. void
  310. CEditWnd::OnUpdateGaijiCut(
  311. CCmdUI* pCmdUI)
  312. {
  313. if (pCmdUI)
  314. {
  315. pCmdUI->Enable( RectClipFlag);
  316. }
  317. }
  318. /****************************************/
  319. /* */
  320. /* COMMAND "COPY" */
  321. /* */
  322. /****************************************/
  323. void
  324. CEditWnd::OnGaijiCopy()
  325. {
  326. ClipImageCopy();
  327. }
  328. /****************************************/
  329. /* */
  330. /* COMMAND "Copy" (Update) */
  331. /* */
  332. /****************************************/
  333. void
  334. CEditWnd::OnUpdateGaijiCopy( CCmdUI* pCmdUI)
  335. {
  336. if (pCmdUI)
  337. {
  338. pCmdUI->Enable( RectClipFlag);
  339. }
  340. }
  341. /****************************************/
  342. /* */
  343. /* COMMAND "PASTE" */
  344. /* */
  345. /****************************************/
  346. void
  347. CEditWnd::OnGaijiPaste()
  348. {
  349. HBITMAP ClipBmpHandle, hTempBitmap1;
  350. CBitmap ClipBmp1, ClipBmp2;
  351. HDC hStdDC, hTempDC1;
  352. HGDIOBJ hOldSObj, hOldSObj2;
  353. BITMAP Bmp;
  354. CSize StretchSize;
  355. BOOL BitmapFmt, PrivateFmt;
  356. BitmapFmt = FALSE;
  357. PrivateFmt = FALSE;
  358. UndoImageDraw();
  359. BitmapDirty = TRUE;
  360. WriteSelRectBitmap();
  361. this->Invalidate( FALSE);
  362. this->UpdateWindow();
  363. if( !this->OpenClipboard())
  364. return;
  365. if(( ClipBmpHandle = (HBITMAP)GetClipboardData(CF_BITMAP)) == NULL){
  366. CloseClipboard();
  367. return;
  368. }
  369. GetObject(ClipBmpHandle, sizeof(BITMAP), (LPVOID)&Bmp);
  370. hStdDC = CreateCompatibleDC( ImageDC.GetSafeHdc());
  371. hOldSObj = SelectObject(hStdDC, ClipBmpHandle);
  372. hTempBitmap1 = CreateBitmap(Bmp.bmWidth, Bmp.bmHeight, 1, 1, NULL);
  373. hTempDC1 = CreateCompatibleDC( ImageDC.GetSafeHdc());
  374. hOldSObj2 = SelectObject( hTempDC1, hTempBitmap1);
  375. ::BitBlt( hTempDC1, 0, 0, Bmp.bmWidth, Bmp.bmHeight,
  376. hStdDC, 0, 0, SRCCOPY);
  377. if( !CloseClipboard())
  378. {
  379. SelectObject( hStdDC, hOldSObj);
  380. SelectObject( hTempDC1, hOldSObj2);
  381. DeleteObject( hTempBitmap1);
  382. DeleteDC( hStdDC);
  383. DeleteDC( hTempDC1);
  384. return;
  385. }
  386. if( (int)Bmp.bmWidth < BITMAP_WIDTH &&
  387. (int)Bmp.bmHeight < BITMAP_HEIGHT ){
  388. StretchSize.cx = (int)Bmp.bmWidth;
  389. StretchSize.cy = (int)Bmp.bmHeight;
  390. ::StretchBlt( CRTDrawDC.GetSafeHdc(), 0, 0,
  391. StretchSize.cx, StretchSize.cy, hTempDC1, 0, 0,
  392. StretchSize.cx, StretchSize.cy, SRCCOPY);
  393. }else if( Bmp.bmWidth < BITMAP_WIDTH){
  394. StretchSize.cx = (int)Bmp.bmWidth;
  395. StretchSize.cy = BITMAP_HEIGHT;
  396. ::StretchBlt( CRTDrawDC.GetSafeHdc(), 0, 0,
  397. StretchSize.cx, StretchSize.cy, hTempDC1, 0, 0,
  398. StretchSize.cx, Bmp.bmHeight, SRCCOPY);
  399. }else if( Bmp.bmHeight < BITMAP_HEIGHT){
  400. StretchSize.cx = BITMAP_HEIGHT;
  401. StretchSize.cy = (int)Bmp.bmHeight;
  402. ::StretchBlt( CRTDrawDC.GetSafeHdc(), 0, 0,
  403. StretchSize.cx, StretchSize.cy, hTempDC1, 0, 0,
  404. Bmp.bmWidth, StretchSize.cy, SRCCOPY);
  405. }else{
  406. StretchSize.cx = BITMAP_WIDTH;
  407. StretchSize.cy = BITMAP_HEIGHT;
  408. ::StretchBlt( CRTDrawDC.GetSafeHdc(), 0, 0,
  409. StretchSize.cx, StretchSize.cy, hTempDC1, 0, 0,
  410. Bmp.bmWidth, Bmp.bmHeight, SRCCOPY);
  411. }
  412. ptStart.x = 0;
  413. ptStart.y = 0;
  414. ptEnd.x = (StretchSize.cx-1) *ZoomRate;
  415. ptEnd.y = (StretchSize.cy-1) *ZoomRate;
  416. SetMoveRect();
  417. SetValidRect();
  418. SetClickRect();
  419. SetPickRect();
  420. SelectItem = RECTCLIP;
  421. RectClipFlag = TRUE;
  422. this->InvalidateRect( &ClipRect[VLD], FALSE);
  423. this->UpdateWindow();
  424. SelectObject( hStdDC, hOldSObj);
  425. SelectObject( hTempDC1, hOldSObj2);
  426. DeleteObject( hTempBitmap1);
  427. DeleteDC( hStdDC);
  428. DeleteDC( hTempDC1);
  429. return;
  430. }
  431. /****************************************/
  432. /* */
  433. /* COMMAND "PASTE" (Update) */
  434. /* */
  435. /****************************************/
  436. void
  437. CEditWnd::OnUpdateGaijiPaste(
  438. CCmdUI* pCmdUI)
  439. {
  440. UINT ClipFormat;
  441. BOOL BitmapFmt;
  442. BOOL PrivateFmt;
  443. if (!pCmdUI)
  444. {
  445. return;
  446. }
  447. BitmapFmt = FALSE;
  448. PrivateFmt = FALSE;
  449. if( !::OpenClipboard(this->GetSafeHwnd()))
  450. return;
  451. for( ClipFormat = 0;;){
  452. ClipFormat = EnumClipboardFormats( ClipFormat);
  453. if( ClipFormat == CF_BITMAP){
  454. BitmapFmt = TRUE;
  455. if( PrivateFmt) break;
  456. }
  457. if( ClipFormat == ClipboardFormat){
  458. PrivateFmt = TRUE;
  459. if( BitmapFmt) break;
  460. }
  461. if( ClipFormat == 0) break;
  462. }
  463. if( !PrivateFmt){
  464. if( BitmapFmt){
  465. CloseClipboard();
  466. pCmdUI->Enable(TRUE);
  467. return;
  468. }else{
  469. CloseClipboard();
  470. pCmdUI->Enable(FALSE);
  471. return;
  472. }
  473. }else{
  474. if ( !BitmapFmt){
  475. CloseClipboard();
  476. pCmdUI->Enable(FALSE);
  477. return;
  478. }
  479. }
  480. CloseClipboard();
  481. pCmdUI->Enable(FALSE);
  482. }
  483. /****************************************/
  484. /* */
  485. /* COMMAND "Delete" */
  486. /* */
  487. /****************************************/
  488. void
  489. CEditWnd::OnDeleteEdit()
  490. {
  491. UndoImageDraw();
  492. BitmapDirty = TRUE;
  493. if(( SelectItem == RECTCLIP || SelectItem == FREEFORM) &&
  494. RectClipFlag){
  495. RectClipFlag = FALSE;
  496. ToolTerm();
  497. }
  498. this->Invalidate( FALSE);
  499. this->UpdateWindow();
  500. }
  501. /****************************************/
  502. /* */
  503. /* COMMAND "Delete"(Update)*/
  504. /* */
  505. /****************************************/
  506. void
  507. CEditWnd::OnUpdateDeleteEdit(
  508. CCmdUI* pCmdUI)
  509. {
  510. pCmdUI->Enable( RectClipFlag);
  511. }
  512. /****************************************/
  513. /* */
  514. /* Create bitmap for undo */
  515. /* */
  516. /****************************************/
  517. BOOL
  518. CEditWnd::CreateUndoBitmap()
  519. {
  520. HANDLE BitHandle;
  521. BYTE *pBitmap;
  522. WORD wSize;
  523. wSize = (WORD)((( BITMAP_WIDTH + 15) /16) *2) *(WORD)BITMAP_HEIGHT;
  524. if(( BitHandle = LocalAlloc( LMEM_MOVEABLE, wSize)) == 0)
  525. return FALSE;
  526. if(( pBitmap = (BYTE *)LocalLock( BitHandle)) == NULL){
  527. LocalFree( BitHandle);
  528. return FALSE;
  529. }
  530. memset( pBitmap, 0xffff, wSize);
  531. if( !UndoImage.CreateBitmap( BITMAP_WIDTH, BITMAP_HEIGHT,
  532. 1, 1, (LPSTR)pBitmap)){
  533. LocalFree( BitHandle);
  534. return FALSE;
  535. }
  536. LocalUnlock( BitHandle);
  537. LocalFree( BitHandle);
  538. return TRUE;
  539. }
  540. /****************************************/
  541. /* */
  542. /* Cut image to clipboard */
  543. /* */
  544. /****************************************/
  545. BOOL
  546. CEditWnd::ClipImageCut()
  547. {
  548. CPen CutPen;
  549. CBrush CutBrush;
  550. CutPen.CreateStockObject( NULL_PEN);
  551. CPen *OldPen = CRTDrawDC.SelectObject( &CutPen);
  552. CutBrush.CreateSolidBrush( COLOR_WHITE );
  553. CBrush *OldBrush = CRTDrawDC.SelectObject( &CutBrush);
  554. ClipRect[BMP].right += 1;
  555. ClipRect[BMP].bottom += 1;
  556. CRTDrawDC.Rectangle( &ClipRect[BMP]);
  557. CRTDrawDC.SelectObject( OldPen);
  558. CRTDrawDC.SelectObject( OldBrush);
  559. CutPen.DeleteObject();
  560. CutBrush.DeleteObject();
  561. return TRUE;
  562. }
  563. /****************************************/
  564. /* */
  565. /* Copy image to clipboard */
  566. /* */
  567. /****************************************/
  568. BOOL
  569. CEditWnd::ClipImageCopy()
  570. {
  571. CBitmap ClipBmp;
  572. CDC ClipDC;
  573. CRect pRect;
  574. pRect.SetRect( ClipRect[DSP].left /ZoomRate,
  575. ( ClipRect[DSP].top - CAPTION_HEIGHT) /ZoomRate,
  576. ClipRect[DSP].right /ZoomRate,
  577. ( ClipRect[DSP].bottom - CAPTION_HEIGHT) /ZoomRate);
  578. ClipDC.CreateCompatibleDC( &ImageDC);
  579. ClipBmp.CreateCompatibleBitmap( &ImageDC,
  580. pRect.Width(), pRect.Height());
  581. CBitmap *OldClip = ClipDC.SelectObject( &ClipBmp);
  582. ClipDC.PatBlt( 0, 0, pRect.Width(), pRect.Height(), WHITENESS);
  583. ClipDC.StretchBlt( 0, 0, pRect.Width(), pRect.Height(), &CRTDrawDC,
  584. ClipRect[BMP].left, ClipRect[BMP].top,
  585. ClipRect[BMP].Width(), ClipRect[BMP].Height(),SRCCOPY);
  586. if( !this->OpenClipboard()){
  587. ClipDC.SelectObject( OldClip);
  588. ClipBmp.DeleteObject();
  589. ClipDC.DeleteDC();
  590. return FALSE;
  591. }
  592. EmptyClipboard();
  593. if( !SetClipboardData( CF_BITMAP, ClipBmp.Detach())){
  594. ClipDC.SelectObject( OldClip);
  595. ClipBmp.DeleteObject();
  596. ClipDC.DeleteDC();
  597. CloseClipboard();
  598. return FALSE;
  599. }
  600. CloseClipboard();
  601. ClipDC.SelectObject( OldClip);
  602. ClipBmp.DeleteObject();
  603. ClipDC.DeleteDC();
  604. return TRUE;
  605. }
  606. /****************************************/
  607. /* */
  608. /* MESSAGE "WM_PAINT" */
  609. /* */
  610. /****************************************/
  611. void
  612. CEditWnd::OnPaint()
  613. {
  614. CPaintDC dc( this);
  615. DWORD OldTextColor;
  616. this->GetClientRect( &EudcWndRect);
  617. // Set textcolor to gray if fitting curve
  618. if( FlagTmp)
  619. OldTextColor = dc.SetTextColor( COLOR_FITTING);
  620. else OldTextColor = dc.SetTextColor( COLOR_BLACK);
  621. // Put bitmap data on display
  622. ZoomRate = EudcWndRect.right /BITMAP_WIDTH;
  623. dc.StretchBlt( 0, CAPTION_HEIGHT, EudcWndRect.right,
  624. EudcWndRect.bottom - CAPTION_HEIGHT,
  625. &ImageDC, 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT, SRCCOPY);
  626. // Draw selected rectangle if RectClipFlag is build
  627. if( RectClipFlag){
  628. dc.StretchBlt( ClipRect[DSP].left - 1, ClipRect[DSP].top - 1,
  629. ClipRect[DSP].Width(), ClipRect[DSP].Height(),
  630. &CRTDrawDC, ClipRect[BMP].left, ClipRect[BMP].top,
  631. ClipRect[BMP].Width(), ClipRect[BMP].Height(), SRCAND);
  632. DrawMoveRect( &dc);
  633. DrawStretchRect( &dc);
  634. }
  635. dc.SetTextColor( OldTextColor);
  636. CaptionDraw();
  637. if( ZoomRate >= 2 && GridShow)
  638. DrawGridLine( &dc);
  639. if( FlagTmp)
  640. CurveFittingDraw( &dc);
  641. }
  642. /****************************************/
  643. /* */
  644. /* MESSAGE "WM_LBUTTONDOWN" */
  645. /* */
  646. /****************************************/
  647. void
  648. CEditWnd::OnLButtonDown(
  649. UINT ,
  650. CPoint point)
  651. {
  652. CRect CaptionRect;
  653. CPoint ClickPt;
  654. if( ButtonFlag == RCLICK){
  655. this->Invalidate();
  656. ToolTerm();
  657. return;
  658. }
  659. ClickPt = point;
  660. CaptionRect.CopyRect( &EudcWndRect);
  661. CaptionRect.top = CAPTION_HEIGHT;
  662. if( !CaptionRect.PtInRect( point))
  663. return;
  664. ToolInit(LCLICK);
  665. // Modurate coordinate
  666. CorrectMouseDownPoint( point);
  667. // Stretch selected rectangle
  668. if( RectClipFlag){
  669. SetClickRect();
  670. if( ClipRect[PIN].PtInRect( ClickPt) &&
  671. ( EudcWndRect.Width() > ClipRect[DSP].Width() ||
  672. EudcWndRect.Height() - CAPTION_HEIGHT
  673. > ClipRect[DSP].Height())){
  674. BitmapDirty = TRUE;
  675. }else if(( CheckNum = CheckClipRect( ClickPt)) != NCHECK){
  676. BitmapDirty = TRUE;
  677. SetValidRect();
  678. RectClipFlag = FALSE;
  679. this->InvalidateRect( &ClipRect[VLD], FALSE);
  680. this->UpdateWindow();
  681. RectClipFlag = TRUE;
  682. CClientDC dc( this);
  683. DrawMoveRect( &dc);
  684. }else{
  685. RectClipFlag = FALSE;
  686. this->InvalidateRect( &ClipRect[VLD], FALSE);
  687. this->UpdateWindow();
  688. DrawClipBmp();
  689. SetPickRect();
  690. if( SelectItem == RECTCLIP)
  691. DrawRubberBand( TRUE);
  692. else{
  693. CPoint Sp;
  694. Sp.x = ptStart.x;
  695. Sp.y = ptStart.y + CAPTION_HEIGHT;
  696. m_pointArray.RemoveAll();
  697. m_SelectArray.RemoveAll();
  698. m_pointArray.Add( Sp);
  699. Sp.x = ptStart.x /ZoomRate;
  700. Sp.y = ptStart.y /ZoomRate;
  701. m_SelectArray.Add( Sp);
  702. }
  703. }
  704. }else{
  705. if( SelectItem == PEN || SelectItem == BRUSH ){
  706. UndoImageDraw();
  707. BitmapDirty = TRUE;
  708. DrawPoint( ptStart, FALSE);
  709. }else if (SelectItem == ERASER){
  710. UndoImageDraw();
  711. BitmapDirty = TRUE;
  712. DrawPoint( ptStart, TRUE);
  713. }else{
  714. UndoImageDraw();
  715. BitmapDirty = TRUE;
  716. if( SelectItem == FREEFORM){
  717. CPoint Sp;
  718. Sp.x = ptStart.x;
  719. Sp.y = ptStart.y + CAPTION_HEIGHT;
  720. m_pointArray.RemoveAll();
  721. m_SelectArray.RemoveAll();
  722. m_pointArray.Add( Sp);
  723. Sp.x = ptStart.x /ZoomRate;
  724. Sp.y = ptStart.y /ZoomRate;
  725. m_SelectArray.Add( Sp);
  726. }else DrawRubberBand( TRUE);
  727. }
  728. }
  729. }
  730. /****************************************/
  731. /* */
  732. /* MESSAGE "WM_MOUSEMOVE" */
  733. /* */
  734. /****************************************/
  735. void
  736. CEditWnd::OnMouseMove(
  737. UINT ,
  738. CPoint point)
  739. {
  740. if( IsCapture){
  741. // Modurate coordinate
  742. CorrectMouseUpPoint( point);
  743. if( ptPrev.x == ptEnd.x && ptPrev.y == ptEnd.y)
  744. return;
  745. if( RectClipFlag){
  746. if( CheckNum == NCHECK){
  747. CRect URect, MRect, PRRect;
  748. if( !MoveClipRect())
  749. return;
  750. MRect.SetRect( ClipRect[DSP].left - Ratio,
  751. ClipRect[DSP].top - Ratio,
  752. ClipRect[DSP].right + Ratio,
  753. ClipRect[DSP].bottom + Ratio);
  754. PRRect.SetRect( ClipRect[PRV].left - Ratio,
  755. ClipRect[PRV].top - Ratio,
  756. ClipRect[PRV].right + Ratio,
  757. ClipRect[PRV].bottom + Ratio);
  758. URect.UnionRect( &MRect, &PRRect);
  759. this->InvalidateRect( &URect, FALSE);
  760. this->UpdateWindow();
  761. }else StretchMoveRect();
  762. }else{
  763. if( SelectItem == PEN || SelectItem == BRUSH)
  764. DrawToPoint(FALSE);
  765. else if (SelectItem == ERASER)
  766. DrawToPoint(TRUE);
  767. else if( SelectItem == FREEFORM){
  768. DrawFreeForm( FALSE);
  769. SelectFreeForm(FALSE);
  770. }else DrawRubberBand( FALSE);
  771. }
  772. }
  773. }
  774. /****************************************/
  775. /* */
  776. /* MESSAGE "WM_LBUTTONUP" */
  777. /* */
  778. /****************************************/
  779. void
  780. CEditWnd::OnLButtonUp(
  781. UINT ,
  782. CPoint point)
  783. {
  784. if (!bFocus)
  785. {
  786. bFocus = TRUE;
  787. CaptionDraw();
  788. pRefrChild->bFocus = FALSE;
  789. pRefrChild->CaptionDraw();
  790. }
  791. if( IsCapture){
  792. // Modurate coordinate
  793. CorrectMouseUpPoint( point);
  794. if( SelectItem == PEN || SelectItem == BRUSH ||SelectItem == ERASER){
  795. if( FlagTmp)
  796. this->Invalidate(FALSE);
  797. ToolTerm();
  798. return;
  799. }
  800. // draw a figure on bitmap
  801. if( SelectItem == RECTCLIP && !RectClipFlag){
  802. SetMoveRect();
  803. SetPickRect();
  804. SetValidRect();
  805. SetClickRect();
  806. if(( abs( ptEnd.x - ptStart.x) >= ZoomRate*2) &&
  807. ( abs( ptEnd.y - ptStart.y) >= ZoomRate*2) ){
  808. CRTDrawDC.BitBlt( ClipRect[BMP].left,
  809. ClipRect[BMP].top,
  810. ClipRect[BMP].Width(),
  811. ClipRect[BMP].Height(),
  812. &ImageDC, ClipRect[BMP].left,
  813. ClipRect[BMP].top, SRCCOPY);
  814. EraseRectangle();
  815. RectClipFlag = TRUE;
  816. }
  817. this->InvalidateRect( &ClipRect[VLD], FALSE);
  818. this->UpdateWindow();
  819. }else if( SelectItem == FREEFORM && !RectClipFlag){
  820. POINT nArray[FREELIAIS];
  821. POINT pArray[FREELIAIS];
  822. DrawFreeForm( FALSE);
  823. SelectFreeForm( FALSE);
  824. DrawFreeForm( TRUE);
  825. SelectFreeForm( TRUE);
  826. if( m_pointArray.GetSize() >= FREELIAIS ||
  827. m_SelectArray.GetSize() >= FREELIAIS ){
  828. ToolTerm();
  829. this->Invalidate(FALSE);
  830. this->UpdateWindow();
  831. return;
  832. }
  833. for( int i = 0; i < m_pointArray.GetSize(); i++)
  834. nArray[i] = m_pointArray[i];
  835. for( i = 0; i < m_SelectArray.GetSize(); i++)
  836. pArray[i] = m_SelectArray[i];
  837. if( FreeRgn.GetSafeHandle() != NULL)
  838. FreeRgn.DeleteObject();
  839. if( PickRgn.GetSafeHandle() != NULL)
  840. PickRgn.DeleteObject();
  841. FreeRgn.CreatePolygonRgn( nArray,
  842. (int)(m_pointArray.GetSize()), ALTERNATE);
  843. PickRgn.CreatePolygonRgn( pArray,
  844. (int)(m_SelectArray.GetSize()), ALTERNATE);
  845. if( FreeRgn.GetSafeHandle() == NULL ||
  846. PickRgn.GetSafeHandle() == NULL){
  847. m_pointArray.RemoveAll();
  848. m_SelectArray.RemoveAll();
  849. RectClipFlag = FALSE;
  850. }else{
  851. RectClipFlag = TRUE;
  852. if( !SetFreeForm()){
  853. RectClipFlag = FALSE;
  854. FreeRgn.DeleteObject();
  855. PickRgn.DeleteObject();
  856. SetPickRect();
  857. SetValidRect();
  858. SetClickRect();
  859. ClipRect[PRV].CopyRect( &ClipRect[DSP]);
  860. this->InvalidateRect( &ClipRect[VLD], FALSE);
  861. this->UpdateWindow();
  862. }else{
  863. EraseFreeForm();
  864. SetPickRect();
  865. SetValidRect();
  866. SetClickRect();
  867. ClipRect[PRV].CopyRect( &ClipRect[DSP]);
  868. this->InvalidateRect( &ClipRect[VLD], FALSE);
  869. this->UpdateWindow();
  870. }
  871. }
  872. }else if( RectClipFlag){
  873. if( CheckNum != NCHECK){
  874. DrawStretchClipToDisp();
  875. CheckNum = NCHECK;
  876. }else{
  877. if( !MoveClipRect()){
  878. ToolTerm();
  879. return;
  880. }
  881. }
  882. SetValidRect();
  883. SetClickRect();
  884. this->InvalidateRect( &ClipRect[VLD], FALSE);
  885. this->UpdateWindow();
  886. }else{
  887. if( SelectItem != SLOPE)
  888. IllegalRect( &ptStart, &ptEnd);
  889. else{
  890. ptEnd.x = ( ptEnd.x /ZoomRate) *ZoomRate;
  891. ptEnd.y = ( ptEnd.y /ZoomRate) *ZoomRate;
  892. ptStart.x = ( ptStart.x /ZoomRate) *ZoomRate;
  893. ptStart.y = ( ptStart.y /ZoomRate) *ZoomRate;
  894. }
  895. DrawRectBmp();
  896. if( SelectItem == SLOPE)
  897. IllegalRect( &ptStart, &ptEnd);
  898. SetMoveRect();
  899. if( FlagTmp)
  900. this->Invalidate( FALSE);
  901. else if( SelectItem != PEN && SelectItem != BRUSH && SelectItem != ERASER){
  902. this->InvalidateRect( &ClipRect[DSP], FALSE);
  903. }
  904. }
  905. ToolTerm();
  906. }
  907. }
  908. /****************************************/
  909. /* */
  910. /* MESSAGE "WM_RBUTTONDOWN" */
  911. /* */
  912. /****************************************/
  913. void
  914. CEditWnd::OnRButtonDown(
  915. UINT nFlags,
  916. CPoint point)
  917. {
  918. CRect CaptionRect;
  919. if( ButtonFlag == LCLICK){
  920. this->Invalidate();
  921. ToolTerm();
  922. return;
  923. }
  924. if( SelectItem == RECTCLIP || SelectItem == FREEFORM){
  925. ToolTerm();
  926. return;
  927. }
  928. CaptionRect.CopyRect( &EudcWndRect);
  929. CaptionRect.top = CAPTION_HEIGHT;
  930. if( !CaptionRect.PtInRect( point))
  931. return;
  932. ToolInit(RCLICK);
  933. // Modurate coordinate
  934. CorrectMouseDownPoint( point);
  935. UndoImageDraw();
  936. BitmapDirty = TRUE;
  937. if( SelectItem == PEN || SelectItem == BRUSH )
  938. DrawPoint( ptStart, FALSE);
  939. else if (SelectItem == ERASER)
  940. DrawPoint( ptStart, TRUE);
  941. else
  942. DrawRubberBand( TRUE);
  943. }
  944. /****************************************/
  945. /* */
  946. /* MESSAGE "WM_RBUTTONUP" */
  947. /* */
  948. /****************************************/
  949. void
  950. CEditWnd::OnRButtonUp(
  951. UINT nFlags,
  952. CPoint point)
  953. {
  954. if( IsCapture){
  955. if( SelectItem == PEN || SelectItem == BRUSH || SelectItem == ERASER ||
  956. SelectItem == RECTCLIP || SelectItem == FREEFORM){
  957. if( FlagTmp)
  958. this->Invalidate( FALSE);
  959. ToolTerm();
  960. return;
  961. }
  962. // Modurate coordinate
  963. CorrectMouseUpPoint( point);
  964. DrawRubberBand( TRUE);
  965. if( SelectItem != SLOPE)
  966. IllegalRect( &ptStart, &ptEnd);
  967. else{
  968. ptEnd.x = ( ptEnd.x /ZoomRate) *ZoomRate;
  969. ptEnd.y = ( ptEnd.y /ZoomRate) *ZoomRate;
  970. ptStart.x = ( ptStart.x /ZoomRate) *ZoomRate;
  971. ptStart.y = ( ptStart.y /ZoomRate) *ZoomRate;
  972. }
  973. // Draw a figure on bitmap
  974. DrawRectBmp();
  975. if( SelectItem == SLOPE)
  976. IllegalRect( &ptStart, &ptEnd);
  977. SetMoveRect();
  978. if( FlagTmp)
  979. this->Invalidate( FALSE);
  980. else this->InvalidateRect( &ClipRect[DSP], FALSE);
  981. ToolTerm();
  982. }
  983. }
  984. /****************************************/
  985. /* */
  986. /* MESSAGE "WM_SIZE" */
  987. /* */
  988. /****************************************/
  989. void
  990. CEditWnd::OnSize(
  991. UINT nType,
  992. int cx,
  993. int cy)
  994. {
  995. int NewZoomRate;
  996. NewZoomRate = cx / BITMAP_WIDTH;
  997. if( RectClipFlag && NewZoomRate > 1){
  998. ClipRect[PRV].left = ( ClipRect[PRV].left /ZoomRate)
  999. * NewZoomRate;
  1000. ClipRect[PRV].top = ((( ClipRect[PRV].top - CAPTION_HEIGHT)
  1001. /ZoomRate) * NewZoomRate) + CAPTION_HEIGHT;
  1002. ClipRect[PRV].right = ( ClipRect[PRV].right /ZoomRate)
  1003. * NewZoomRate + 1;
  1004. ClipRect[PRV].bottom = ((( ClipRect[PRV].bottom -CAPTION_HEIGHT)
  1005. / ZoomRate) * NewZoomRate) + CAPTION_HEIGHT + 1;
  1006. ClipRect[DSP].left = ( ClipRect[DSP].left /ZoomRate)
  1007. * NewZoomRate;
  1008. ClipRect[DSP].top = ((( ClipRect[DSP].top - CAPTION_HEIGHT)
  1009. / ZoomRate) * NewZoomRate) + CAPTION_HEIGHT;
  1010. ClipRect[DSP].right = ( ClipRect[DSP].right /ZoomRate)
  1011. * NewZoomRate + 1;
  1012. ClipRect[DSP].bottom = ((( ClipRect[DSP].bottom -CAPTION_HEIGHT)
  1013. / ZoomRate) * NewZoomRate) + CAPTION_HEIGHT + 1;
  1014. SetClickRect();
  1015. SetValidRect();
  1016. }else if( RectClipFlag && NewZoomRate <= 1)
  1017. WriteSelRectBitmap();
  1018. CMDIChildWnd::OnSize(nType, cx, cy);
  1019. this->Invalidate(FALSE);
  1020. this->UpdateWindow();
  1021. }
  1022. /****************************************/
  1023. /* */
  1024. /* MESSAGE "WM_SETCURSOR" */
  1025. /* */
  1026. /****************************************/
  1027. BOOL
  1028. CEditWnd::OnSetCursor(
  1029. CWnd* pWnd,
  1030. UINT nHitTest,
  1031. UINT message)
  1032. {
  1033. CPoint point;
  1034. CRect CaptionRect;
  1035. CRect EditRect;
  1036. HCURSOR hArrowCur;
  1037. GetCursorPos( &point);
  1038. this->ScreenToClient( &point);
  1039. this->GetClientRect( &CaptionRect);
  1040. EditRect.CopyRect( &CaptionRect);
  1041. CaptionRect.bottom = CAPTION_HEIGHT;
  1042. EditRect.top = CAPTION_HEIGHT;
  1043. if(CaptionRect.PtInRect( point)){
  1044. hArrowCur = AfxGetApp()->LoadStandardCursor( IDC_ARROW);
  1045. ::SetCursor( hArrowCur);
  1046. }else if( RectClipFlag && !IsCapture && EditRect.PtInRect( point)){
  1047. if( PickRect[LUPPER].PtInRect( point) ||
  1048. PickRect[RLOWER].PtInRect( point)){
  1049. ::SetCursor((HCURSOR)ArrowCursor[LEFTSLOPE]);
  1050. }else if( PickRect[RUPPER].PtInRect( point) ||
  1051. PickRect[LLOWER].PtInRect( point)){
  1052. ::SetCursor((HCURSOR)ArrowCursor[RIGHTSLOPE]);
  1053. }else if( PickRect[MUPPER].PtInRect( point) ||
  1054. PickRect[MLOWER].PtInRect( point)){
  1055. ::SetCursor((HCURSOR)ArrowCursor[HORIZONTAL]);
  1056. }else if( PickRect[RMIDLE].PtInRect( point) ||
  1057. PickRect[LMIDLE].PtInRect( point)){
  1058. ::SetCursor((HCURSOR)ArrowCursor[VERTICAL]);
  1059. }else if( ClipRect[DSP].PtInRect( point)){
  1060. ::SetCursor((HCURSOR)ArrowCursor[ALLDIRECT]);
  1061. }else ::SetCursor((HCURSOR)ToolCursor[SelectItem]);
  1062. }else if( !IsCapture && EditRect.PtInRect( point))
  1063. ::SetCursor((HCURSOR)ToolCursor[SelectItem]);
  1064. else{
  1065. hArrowCur = AfxGetApp()->LoadStandardCursor( IDC_ARROW);
  1066. ::SetCursor( hArrowCur);
  1067. }
  1068. return TRUE;
  1069. }
  1070. /****************************************/
  1071. /* */
  1072. /* MESSAGE "WM_MDIACTIVATE"*/
  1073. /* */
  1074. /****************************************/
  1075. void
  1076. CEditWnd::OnMDIActivate(
  1077. BOOL bActivate,
  1078. CWnd* pActivateWnd,
  1079. CWnd* pDeactivateWnd)
  1080. {
  1081. if( bActivate == FALSE){
  1082. if( SelectItem == RECTCLIP || SelectItem == FREEFORM)
  1083. WriteSelRectBitmap();
  1084. }
  1085. }
  1086. /****************************************/
  1087. /* */
  1088. /* MESSAGE "WM_KEYDOWN" */
  1089. /* */
  1090. /****************************************/
  1091. void
  1092. CEditWnd::OnKeyDown(
  1093. UINT nChar,
  1094. UINT nRepCnt,
  1095. UINT nFlags)
  1096. {
  1097. if( nChar == VK_ESCAPE)
  1098. WriteSelRectBitmap();
  1099. else CMDIChildWnd::OnKeyDown(nChar, nRepCnt, nFlags);
  1100. }
  1101. /****************************************/
  1102. /* */
  1103. /* Draw Caption */
  1104. /* */
  1105. /****************************************/
  1106. void
  1107. CEditWnd::CaptionDraw()
  1108. {
  1109. COLORREF TextColor;
  1110. CString WndCaption;
  1111. CRect CaptionRect;
  1112. CBrush CaptionBrush;
  1113. CFont *OldFont;
  1114. int BkMode;
  1115. CDC dc;
  1116. dc.Attach( ::GetDC( this->GetSafeHwnd()));
  1117. // Get brush with active caption color
  1118. CaptionRect.CopyRect( &EudcWndRect);
  1119. if (bFocus)
  1120. {
  1121. CaptionBrush.CreateSolidBrush(::GetSysColor(COLOR_ACTIVECAPTION));
  1122. }
  1123. else
  1124. {
  1125. CaptionBrush.CreateSolidBrush(::GetSysColor(COLOR_INACTIVECAPTION));
  1126. }
  1127. CaptionRect.bottom = CAPTION_HEIGHT;
  1128. dc.FillRect( &CaptionRect, &CaptionBrush);
  1129. CaptionBrush.DeleteObject();
  1130. // Get font to draw caption
  1131. #ifdef BUILD_ON_WINNT
  1132. OldFont = (CFont *)dc.SelectStockObject(DEFAULT_GUI_FONT);
  1133. #else
  1134. OldFont = (CFont *)dc.SelectStockObject(SYSTEM_FONT);
  1135. #endif
  1136. BkMode = dc.SetBkMode( TRANSPARENT);
  1137. if (bFocus)
  1138. {
  1139. TextColor = dc.SetTextColor( ::GetSysColor(COLOR_CAPTIONTEXT));
  1140. }
  1141. else
  1142. {
  1143. TextColor = dc.SetTextColor( ::GetSysColor(COLOR_INACTIVECAPTIONTEXT));
  1144. }
  1145. WndCaption.LoadString( IDS_EDIT_STR);
  1146. dc.TextOut( EudcWndRect.right /2 - 30, 1, WndCaption);
  1147. dc.SelectObject( OldFont);
  1148. dc.SetTextColor( TextColor);
  1149. dc.SetBkMode( BkMode);
  1150. ::ReleaseDC(NULL, dc.Detach());
  1151. }
  1152. /****************************************/
  1153. /* */
  1154. /* Draw Grid line */
  1155. /* */
  1156. /****************************************/
  1157. void
  1158. CEditWnd::DrawGridLine(
  1159. CDC *dc)
  1160. {
  1161. CPen GlyphPen;
  1162. register int i;
  1163. if (!dc)
  1164. {
  1165. return;
  1166. }
  1167. // Create pen to draw grid
  1168. GlyphPen.CreatePen( PS_SOLID, 1, COLOR_GRID);
  1169. CPen *OldPen = dc->SelectObject( &GlyphPen);
  1170. // Draw grid
  1171. for( i = ZoomRate - 1; i < EudcWndRect.right; i += ZoomRate){
  1172. dc->MoveTo( i, CAPTION_HEIGHT-1);
  1173. dc->LineTo( i, EudcWndRect.bottom);
  1174. }
  1175. for( i =ZoomRate +CAPTION_HEIGHT -1;i<EudcWndRect.bottom;i += ZoomRate){
  1176. dc->MoveTo( 0, i);
  1177. dc->LineTo( EudcWndRect.right, i);
  1178. }
  1179. dc->SelectObject( OldPen);
  1180. GlyphPen.DeleteObject();
  1181. }
  1182. /****************************************/
  1183. /* */
  1184. /* Draw OutLine */
  1185. /* */
  1186. /****************************************/
  1187. BOOL
  1188. CEditWnd::CurveFittingDraw(
  1189. CDC* dc)
  1190. {
  1191. struct VHEAD *vhd;
  1192. struct VDATA *vp;
  1193. CPen CurvePen;
  1194. CPoint DrawPt;
  1195. LPBYTE pBuf;
  1196. int pcnt, TmpHdl, SetHdl;
  1197. if (!dc)
  1198. {
  1199. return FALSE;
  1200. }
  1201. SetHdl = MKOUTHDL;
  1202. DWORD wSize = (WORD)((( BITMAP_WIDTH +15)/16)*2)*(WORD)BITMAP_HEIGHT;
  1203. pBuf = (LPBYTE)malloc(((( BITMAP_WIDTH +15) /16) *2) *BITMAP_HEIGHT);
  1204. if( pBuf == NULL){
  1205. return FALSE;
  1206. }
  1207. ImageBmp.GetBitmapBits( wSize, (LPVOID)pBuf);
  1208. OInit();
  1209. VDNew( SetHdl);
  1210. if(( TmpHdl = OMakeOutline((LPBYTE)pBuf,
  1211. BITMAP_WIDTH,SMOOTHLVL)) < 0){
  1212. free( pBuf);
  1213. OTerm();
  1214. return FALSE;
  1215. }
  1216. if( MkPoly( TmpHdl, SetHdl) < 0){
  1217. free( pBuf);
  1218. OTerm();
  1219. return FALSE;
  1220. }
  1221. VDGetHead( SetHdl, &vhd);
  1222. if( VDGetNCont( SetHdl) > 0){
  1223. CurvePen.CreatePen( PS_SOLID, 1, COLOR_CURVE);
  1224. CPen *OldPen = dc->SelectObject( &CurvePen);
  1225. CBrush *OldBrush = (CBrush *)dc->SelectStockObject( NULL_BRUSH);
  1226. while ( vhd->next != NIL){
  1227. vp = vhd->headp;
  1228. pcnt = vhd->nPoints - 1;
  1229. ZoomPoint( &DrawPt, vp->vd.x, vp->vd.y);
  1230. dc->MoveTo( DrawPt.x, DrawPt.y);
  1231. vp = vp->next;
  1232. while( pcnt-- > 0){
  1233. ZoomPoint( &DrawPt, vp->vd.x, vp->vd.y);
  1234. dc->LineTo( DrawPt.x, DrawPt.y);
  1235. vp = vp->next;
  1236. }
  1237. vhd = vhd->next;
  1238. }
  1239. dc->SelectObject( OldBrush);
  1240. dc->SelectObject( OldPen);
  1241. CurvePen.DeleteObject();
  1242. }
  1243. OTerm();
  1244. free( pBuf);
  1245. return TRUE;
  1246. }
  1247. /****************************************/
  1248. /* */
  1249. /* Zoom coordinate of outline */
  1250. /* */
  1251. /****************************************/
  1252. void
  1253. CEditWnd::ZoomPoint(
  1254. CPoint *DrawPt,
  1255. int x,
  1256. int y)
  1257. {
  1258. DWORD px, py;
  1259. if (!DrawPt)
  1260. {
  1261. return;
  1262. }
  1263. px = (DWORD)(x * EudcWndRect.right);
  1264. py = (DWORD)(y * (EudcWndRect.bottom - CAPTION_HEIGHT));
  1265. DrawPt->x = (int)( px/(BITMAP_WIDTH *4));
  1266. DrawPt->y = (int)( py/(BITMAP_HEIGHT*4)) + CAPTION_HEIGHT;
  1267. }
  1268. /****************************************/
  1269. /* */
  1270. /* Draw MoveRect rectangle */
  1271. /* */
  1272. /****************************************/
  1273. void
  1274. CEditWnd::DrawMoveRect(
  1275. CDC *dc)
  1276. {
  1277. CPen *OldPen;
  1278. CBrush *OldBrush;
  1279. if (!dc)
  1280. {
  1281. return;
  1282. }
  1283. OldPen = (CPen *)dc->SelectStockObject( BLACK_PEN);
  1284. OldBrush = (CBrush *)dc->SelectStockObject( NULL_BRUSH);
  1285. int OldMode = dc->SetROP2( R2_NOTXORPEN);
  1286. dc->Rectangle( &ClipRect[DSP]);
  1287. dc->SelectObject( OldPen);
  1288. dc->SelectObject( OldBrush);
  1289. dc->SetROP2( OldMode);
  1290. }
  1291. /****************************************/
  1292. /* */
  1293. /* Draw clipping rectangle */
  1294. /* */
  1295. /****************************************/
  1296. void
  1297. CEditWnd::DrawStretchRect(
  1298. CDC *dc)
  1299. {
  1300. CPen *OldPen;
  1301. CBrush *OldBrush;
  1302. int Left, Top;
  1303. int Right, Bottom;
  1304. if (!dc)
  1305. {
  1306. return;
  1307. }
  1308. OldPen = (CPen *)dc->SelectStockObject( BLACK_PEN);
  1309. OldBrush = (CBrush *)dc->SelectStockObject( BLACK_BRUSH);
  1310. for( int i = 0; i < 8; i++){
  1311. // Set left and right side of PickRect[]
  1312. if( i == LUPPER || i == LLOWER || i == LMIDLE){
  1313. Left = ClipRect[DSP].left - Ratio;
  1314. Right = ClipRect[DSP].left + Ratio;
  1315. }else if( i == RUPPER || i == RLOWER || i == RMIDLE){
  1316. Left = ClipRect[DSP].right - Ratio;
  1317. Right = ClipRect[DSP].right + Ratio;
  1318. }else{
  1319. Left = ClipRect[DSP].left + ClipRect[DSP].Width()/2
  1320. - Ratio;
  1321. Right = ClipRect[DSP].left + ClipRect[DSP].Width()/2
  1322. + Ratio;
  1323. }
  1324. // Set top and bottom side of PickRect[]
  1325. if( i == LUPPER || i == RUPPER || i == MUPPER){
  1326. Top = ClipRect[DSP].top - Ratio;
  1327. Bottom = ClipRect[DSP].top + Ratio;
  1328. }else if( i == RMIDLE || i == LMIDLE){
  1329. Top = ClipRect[DSP].top + ClipRect[DSP].Height()/2
  1330. - Ratio;
  1331. Bottom = ClipRect[DSP].top + ClipRect[DSP].Height()/2
  1332. + Ratio;
  1333. }else{
  1334. Top = ClipRect[DSP].bottom - Ratio;
  1335. Bottom = ClipRect[DSP].bottom + Ratio;
  1336. }
  1337. PickRect[i].SetRect( Left, Top, Right, Bottom);
  1338. dc->InvertRect( &PickRect[i]);
  1339. }
  1340. dc->SelectObject( OldPen);
  1341. dc->SelectObject( OldBrush);
  1342. }
  1343. /****************************************/
  1344. /* */
  1345. /* Write Selected Rectangle */
  1346. /* */
  1347. /****************************************/
  1348. void
  1349. CEditWnd::WriteSelRectBitmap()
  1350. {
  1351. if( RectClipFlag){
  1352. RectClipFlag = FALSE;
  1353. DrawClipBmp();
  1354. ToolTerm();
  1355. }
  1356. }
  1357. /****************************************/
  1358. /* */
  1359. /* Modurate coordinate */
  1360. /* */
  1361. /****************************************/
  1362. void
  1363. CEditWnd::CorrectMouseDownPoint(
  1364. CPoint point)
  1365. {
  1366. ptStart.x = point.x;
  1367. ptStart.y = point.y - CAPTION_HEIGHT;
  1368. if( ptStart.y < 0)
  1369. ptStart.y = 0;
  1370. if( SelectItem == FREEFORM){
  1371. ptStart.x = (( ptStart.x + ZoomRate/2) /ZoomRate) *ZoomRate;
  1372. ptStart.y = (( ptStart.y + ZoomRate/2) /ZoomRate) *ZoomRate;
  1373. }else if( SelectItem != SLOPE){
  1374. ptStart.x = ( ptStart.x /ZoomRate) *ZoomRate;
  1375. ptStart.y = ( ptStart.y /ZoomRate) *ZoomRate;
  1376. }else{
  1377. ptStart.x = ( ptStart.x /ZoomRate) *ZoomRate +ZoomRate /2;
  1378. ptStart.y = ( ptStart.y /ZoomRate) *ZoomRate +ZoomRate /2;
  1379. }
  1380. if( SelectItem == RECTBAND || SelectItem == RECTFILL ||
  1381. SelectItem == CIRCLE || SelectItem == CIRCLEFILL ){
  1382. if( ptStart.x > EudcWndRect.right - ZoomRate)
  1383. ptStart.x -= ZoomRate;
  1384. if( ptStart.y > EudcWndRect.bottom - CAPTION_HEIGHT - ZoomRate)
  1385. ptStart.y -= ZoomRate;
  1386. ptEnd.x = ptPrev.x = ptStart.x + ZoomRate;
  1387. ptEnd.y = ptPrev.y = ptStart.y + ZoomRate;
  1388. }else ptEnd = ptPrev = ptStart;
  1389. }
  1390. /****************************************/
  1391. /* */
  1392. /* Modurate coordinate */
  1393. /* */
  1394. /****************************************/
  1395. void
  1396. CEditWnd::CorrectMouseUpPoint(
  1397. CPoint point)
  1398. {
  1399. ptPrev = ptEnd;
  1400. ptEnd.x = point.x;
  1401. ptEnd.y = point.y - CAPTION_HEIGHT;
  1402. if( ptEnd.x < 0) ptEnd.x = 0;
  1403. if( ptEnd.y < 0) ptEnd.y = 0;
  1404. if( ptEnd.x > EudcWndRect.right){
  1405. if( SelectItem == BRUSH)
  1406. ptEnd.x = EudcWndRect.right - ZoomRate*2;
  1407. else if( SelectItem == FREEFORM)
  1408. ptEnd.x = EudcWndRect.right;
  1409. else
  1410. ptEnd.x = EudcWndRect.right - ZoomRate;
  1411. }
  1412. if( ptEnd.y > EudcWndRect.bottom - CAPTION_HEIGHT){
  1413. if( SelectItem == BRUSH)
  1414. ptEnd.y = EudcWndRect.bottom - CAPTION_HEIGHT
  1415. - ZoomRate*2;
  1416. else if( SelectItem == FREEFORM)
  1417. ptEnd.y = EudcWndRect.bottom - CAPTION_HEIGHT;
  1418. else
  1419. ptEnd.y = EudcWndRect.bottom - CAPTION_HEIGHT
  1420. - ZoomRate;
  1421. }
  1422. if( SelectItem == FREEFORM){
  1423. ptEnd.x = (( ptEnd.x + ZoomRate/2) /ZoomRate) *ZoomRate ;
  1424. ptEnd.y = (( ptEnd.y + ZoomRate/2) /ZoomRate) *ZoomRate ;
  1425. }else if( SelectItem != SLOPE){
  1426. ptEnd.x = ( ptEnd.x /ZoomRate)*ZoomRate;
  1427. ptEnd.y = ( ptEnd.y /ZoomRate)*ZoomRate;
  1428. }else{
  1429. ptEnd.x = ( ptEnd.x /ZoomRate) *ZoomRate + ZoomRate /2;
  1430. ptEnd.y = ( ptEnd.y /ZoomRate) *ZoomRate + ZoomRate /2;
  1431. }
  1432. if( SelectItem == RECTBAND || SelectItem == RECTFILL ||
  1433. SelectItem == CIRCLE || SelectItem == CIRCLEFILL ){
  1434. if( ptEnd.x - ptStart.x <= ZoomRate &&
  1435. ptEnd.x - ptStart.x >= 0)
  1436. ptEnd.x = ptStart.x + ZoomRate;
  1437. if( ptStart.x - ptEnd.x <= ZoomRate &&
  1438. ptStart.x - ptEnd.x > 0)
  1439. ptEnd.x = ptStart.x - ZoomRate;
  1440. if( ptStart.y - ptEnd.y <= ZoomRate &&
  1441. ptStart.y - ptEnd.y > 0)
  1442. ptEnd.y = ptStart.y - ZoomRate;
  1443. if( ptEnd.y - ptStart.y <= ZoomRate &&
  1444. ptEnd.y -ptStart.y >= 0)
  1445. ptEnd.y = ptStart.y + ZoomRate;
  1446. }
  1447. }
  1448. /****************************************/
  1449. /* */
  1450. /* Move Selected Rectangle */
  1451. /* */
  1452. /****************************************/
  1453. BOOL
  1454. CEditWnd::MoveClipRect()
  1455. {
  1456. int Movex, Movey;
  1457. int Wid, High;
  1458. BOOL sts;
  1459. sts = TRUE;
  1460. ClipRect[PRV].CopyRect( &ClipRect[DSP]);
  1461. // Boundary condition
  1462. Movex = ptEnd.x - ptPrev.x;
  1463. Movey = ptEnd.y - ptPrev.y;
  1464. Wid = ClipRect[DSP].Width();
  1465. High = ClipRect[DSP].Height();
  1466. ClipRect[DSP].OffsetRect( Movex, Movey);
  1467. if( ClipRect[DSP].left < 0){
  1468. ClipRect[DSP].left = 0;
  1469. ClipRect[DSP].right = Wid;
  1470. }
  1471. if( ClipRect[DSP].right > EudcWndRect.right){
  1472. ClipRect[DSP].right = EudcWndRect.right + 1;
  1473. ClipRect[DSP].left = ClipRect[DSP].right - Wid;
  1474. }
  1475. if( ClipRect[DSP].top < CAPTION_HEIGHT){
  1476. ClipRect[DSP].top = CAPTION_HEIGHT;
  1477. ClipRect[DSP].bottom = CAPTION_HEIGHT +High;
  1478. }
  1479. if( ClipRect[DSP].bottom > EudcWndRect.bottom){
  1480. ClipRect[DSP].bottom = EudcWndRect.bottom +1;
  1481. ClipRect[DSP].top = ClipRect[DSP].bottom - High;
  1482. }
  1483. if( ClipRect[PRV].EqualRect( &ClipRect[DSP])){
  1484. sts = FALSE;
  1485. }
  1486. return sts;
  1487. }
  1488. /************************************************/
  1489. /* */
  1490. /* whether point is in rectangle or not */
  1491. /* */
  1492. /************************************************/
  1493. int
  1494. CEditWnd::CheckClipRect(
  1495. POINT ClipPoint)
  1496. {
  1497. for( int i = 0; i < 8; i++){
  1498. if( PickRect[i].PtInRect( ClipPoint))
  1499. return i;
  1500. }
  1501. return NCHECK;
  1502. }
  1503. /****************************************/
  1504. /* */
  1505. /* Process to stretch rectangle */
  1506. /* */
  1507. /****************************************/
  1508. BOOL
  1509. CEditWnd::DrawStretchClipToDisp()
  1510. {
  1511. CDC SwapDC;
  1512. CBitmap SwapBmp;
  1513. CRect SwapRect;
  1514. CClientDC dc( this);
  1515. if( !SwapDC.CreateCompatibleDC( &dc))
  1516. return FALSE;
  1517. if( !SwapBmp.CreateCompatibleBitmap( &SwapDC, EudcWndRect.Width(),
  1518. EudcWndRect.Height()))
  1519. return FALSE;
  1520. CBitmap *OldBitmap = SwapDC.SelectObject( &SwapBmp);
  1521. SwapRect.CopyRect( &ClipRect[DSP]);
  1522. if( EudcWndRect.right < SwapRect.right)
  1523. SwapRect.right -= 1;
  1524. if( EudcWndRect.bottom < SwapRect.bottom)
  1525. SwapRect.bottom -= 1;
  1526. SwapDC.StretchBlt( SwapRect.left, SwapRect.top,
  1527. SwapRect.Width(), SwapRect.Height(),
  1528. &CRTDrawDC, ClipRect[BMP].left, ClipRect[BMP].top,
  1529. ClipRect[BMP].Width(), ClipRect[BMP].Height(),
  1530. SRCCOPY);
  1531. SetPickRect();
  1532. CRTDrawDC.StretchBlt( ClipRect[BMP].left, ClipRect[BMP].top,
  1533. ClipRect[BMP].Width(), ClipRect[BMP].Height(),
  1534. &SwapDC, SwapRect.left, SwapRect.top,
  1535. SwapRect.Width(), SwapRect.Height(), SRCCOPY);
  1536. SwapDC.SelectObject( OldBitmap);
  1537. SwapBmp.DeleteObject();
  1538. SwapDC.DeleteDC();
  1539. return TRUE;
  1540. }
  1541. /****************************************/
  1542. /* */
  1543. /* Draw select rectangle to bitmap */
  1544. /* */
  1545. /****************************************/
  1546. void
  1547. CEditWnd::DrawClipBmp()
  1548. {
  1549. CRect pRect;
  1550. pRect.SetRect(( ClipRect[DSP].left + 1) /ZoomRate,
  1551. ( ClipRect[DSP].top - CAPTION_HEIGHT + 1) /ZoomRate,
  1552. ( ClipRect[DSP].right + 1)/ZoomRate,
  1553. ( ClipRect[DSP].bottom - CAPTION_HEIGHT + 1) /ZoomRate);
  1554. ImageDC.StretchBlt( pRect.left, pRect.top,
  1555. pRect.Width(), pRect.Height(), &CRTDrawDC,
  1556. ClipRect[BMP].left, ClipRect[BMP].top,
  1557. ClipRect[BMP].Width(), ClipRect[BMP].Height(), SRCAND);
  1558. SetValidRect();
  1559. this->InvalidateRect( &ClipRect[VLD], FALSE);
  1560. this->UpdateWindow();
  1561. }
  1562. /****************************************/
  1563. /* */
  1564. /* Set size of clipping rectangle */
  1565. /* */
  1566. /****************************************/
  1567. void
  1568. CEditWnd::SetPickRect()
  1569. {
  1570. ClipRect[BMP].SetRect( ClipRect[DSP].left /ZoomRate,
  1571. ( ClipRect[DSP].top - CAPTION_HEIGHT) /ZoomRate,
  1572. ClipRect[DSP].right /ZoomRate,
  1573. ( ClipRect[DSP].bottom - CAPTION_HEIGHT) /ZoomRate);
  1574. }
  1575. /****************************************/
  1576. /* */
  1577. /* Set size of clipping rectangle */
  1578. /* */
  1579. /****************************************/
  1580. void
  1581. CEditWnd::SetMoveRect()
  1582. {
  1583. IllegalRect( &ptStart, &ptEnd);
  1584. ClipRect[DSP].SetRect( ptStart.x, ptStart.y + CAPTION_HEIGHT,
  1585. ptEnd.x + ZoomRate + 1,
  1586. ptEnd.y + ZoomRate + 1 + CAPTION_HEIGHT);
  1587. ClipRect[PRV].CopyRect( &ClipRect[DSP]);
  1588. }
  1589. /****************************************/
  1590. /* */
  1591. /* Set size of clipping rectangle */
  1592. /* */
  1593. /****************************************/
  1594. void
  1595. CEditWnd::SetValidRect()
  1596. {
  1597. ClipRect[VLD].SetRect( ClipRect[DSP].left - Ratio,
  1598. ClipRect[DSP].top - Ratio,
  1599. ClipRect[DSP].right + Ratio,
  1600. ClipRect[DSP].bottom + Ratio);
  1601. }
  1602. /****************************************/
  1603. /* */
  1604. /* Set size of clipping rectangle */
  1605. /* */
  1606. /****************************************/
  1607. void
  1608. CEditWnd::SetClickRect()
  1609. {
  1610. ClipRect[PIN].SetRect( ClipRect[DSP].left + Ratio,
  1611. ClipRect[DSP].top + Ratio,
  1612. ClipRect[DSP].right - Ratio,
  1613. ClipRect[DSP].bottom - Ratio);
  1614. }
  1615. /****************************************/
  1616. /* */
  1617. /* Draw a figure to bitmap */
  1618. /* */
  1619. /****************************************/
  1620. void
  1621. CEditWnd::DrawRectBmp()
  1622. {
  1623. CPen *OldPen;
  1624. CBrush *OldBrush;
  1625. CRect BRect;
  1626. CPoint ptLT;
  1627. CPoint ptRB;
  1628. ptLT.x = ptStart.x /ZoomRate;
  1629. ptLT.y = ptStart.y /ZoomRate;
  1630. ptRB.x = ptEnd.x /ZoomRate;
  1631. ptRB.y = ptEnd.y /ZoomRate;
  1632. if( ButtonFlag == LCLICK)
  1633. OldPen = (CPen *)ImageDC.SelectStockObject( BLACK_PEN);
  1634. else OldPen = (CPen *)ImageDC.SelectStockObject( WHITE_PEN);
  1635. if( SelectItem == RECTBAND || SelectItem == CIRCLE)
  1636. OldBrush = (CBrush *)ImageDC.SelectStockObject( NULL_BRUSH);
  1637. else if( ButtonFlag == LCLICK)
  1638. OldBrush = (CBrush *)ImageDC.SelectStockObject( BLACK_BRUSH);
  1639. else OldBrush = (CBrush *)ImageDC.SelectStockObject( WHITE_BRUSH);
  1640. BRect.SetRect( ptLT.x, ptLT.y, ptRB.x +1, ptRB.y +1);
  1641. if( SelectItem == CIRCLE || SelectItem == CIRCLEFILL)
  1642. ImageDC.Ellipse( &BRect);
  1643. else if( SelectItem == RECTBAND || SelectItem == RECTFILL)
  1644. ImageDC.Rectangle( &BRect);
  1645. else{
  1646. ImageDC.MoveTo( ptLT);
  1647. ImageDC.LineTo( ptRB);
  1648. if (SelectItem == ERASER)
  1649. DrawPoint( ptEnd, TRUE);
  1650. else
  1651. DrawPoint( ptEnd, FALSE);
  1652. }
  1653. ImageDC.SelectObject( OldPen);
  1654. ImageDC.SelectObject( OldBrush);
  1655. }
  1656. /****************************************/
  1657. /* */
  1658. /* Draw 1Point */
  1659. /* */
  1660. /****************************************/
  1661. void
  1662. CEditWnd::DrawPoint( CPoint Pt, BOOL bErase)
  1663. {
  1664. CBrush PointBrush,*OldBrush1, *OldBrush2;
  1665. CPoint W;
  1666. int Wstep, i, j;
  1667. CClientDC dc( this);
  1668. if( ButtonFlag == LCLICK && !bErase){
  1669. if( FlagTmp)
  1670. PointBrush.CreateSolidBrush( COLOR_FITTING);
  1671. else PointBrush.CreateSolidBrush( COLOR_BLACK);
  1672. }else PointBrush.CreateSolidBrush( COLOR_WHITE);
  1673. OldBrush1 = dc.SelectObject( &PointBrush);
  1674. W = Pt;
  1675. Wstep = ZoomRate;
  1676. if( ZoomRate > 1 && GridShow)
  1677. Wstep -= 1;
  1678. for( i = 0; i < BrushWidth; i++, W.x += ZoomRate){
  1679. W.y = Pt.y;
  1680. for( j = 0; j < BrushWidth; j++ , W.y += ZoomRate)
  1681. dc.PatBlt( W.x, W.y+CAPTION_HEIGHT,Wstep,Wstep,PATCOPY);
  1682. }
  1683. dc.SelectObject( OldBrush1);
  1684. PointBrush.DeleteObject();
  1685. if( ButtonFlag == LCLICK && !bErase)
  1686. OldBrush2 = (CBrush *)ImageDC.SelectStockObject(BLACK_BRUSH);
  1687. else OldBrush2 = (CBrush *)ImageDC.SelectStockObject(WHITE_BRUSH);
  1688. W.x = Pt.x /ZoomRate;
  1689. W.y = Pt.y /ZoomRate;
  1690. if( W.x < BITMAP_WIDTH && W.y < BITMAP_HEIGHT)
  1691. ImageDC.PatBlt( W.x, W.y, BrushWidth, BrushWidth, PATCOPY);
  1692. ImageDC.SelectObject( OldBrush2);
  1693. }
  1694. /****************************************/
  1695. /* */
  1696. /* Degital differencial analyzer */
  1697. /* */
  1698. /****************************************/
  1699. void
  1700. CEditWnd::DrawToPoint(BOOL bErase)
  1701. {
  1702. CPoint Pt, Start, End, Inc;
  1703. int Xf, Yf;
  1704. int Inc1, Inc2;
  1705. int Dx, Dy, D, Tmp;
  1706. BOOL Slope;
  1707. End.x = Xf = ptEnd.x /ZoomRate;
  1708. End.y = Yf = ptEnd.y /ZoomRate;
  1709. Start.x = ptPrev.x /ZoomRate;
  1710. Start.y = ptPrev.y /ZoomRate;
  1711. if( Xf >= Start.x)
  1712. Inc.x = 1;
  1713. else Inc.x = -1;
  1714. if( Yf >= Start.y)
  1715. Inc.y = 1;
  1716. else Inc.y = -1;
  1717. Dx = ( Xf - Start.x)*Inc.x;
  1718. Dy = ( Yf - Start.y)*Inc.y;
  1719. if( !Dx && !Dy) return;
  1720. if( Dx < Dy){
  1721. Tmp = Dy;
  1722. Dy = Dx;
  1723. Dx = Tmp;
  1724. Tmp = Inc.x;
  1725. Inc.x = Inc.y;
  1726. Inc.y = Tmp;
  1727. Slope = TRUE;
  1728. }else Slope = FALSE;
  1729. Inc1 = Dy*2;
  1730. Inc2 = (Dy - Dx)*2;
  1731. D = Inc1 - Dx;
  1732. End.x = Start.x;
  1733. End.y = Start.y;
  1734. while(1){
  1735. Pt.x = End.x *ZoomRate;
  1736. Pt.y = End.y *ZoomRate;
  1737. DrawPoint( Pt, bErase);
  1738. if( End.x == Xf && End.y == Yf)
  1739. break;
  1740. if( Slope){
  1741. Tmp = End.x;
  1742. End.x = End.y;
  1743. End.y = Tmp;
  1744. }
  1745. End.x += Inc.x;
  1746. if( D < 0) D += Inc1;
  1747. else{
  1748. End.y += Inc.y;
  1749. D += Inc2;
  1750. }
  1751. if( Slope){
  1752. Tmp = End.x;
  1753. End.x = End.y;
  1754. End.y = Tmp;
  1755. }
  1756. }
  1757. }
  1758. /****************************************/
  1759. /* */
  1760. /* Initialize tool width and color */
  1761. /* */
  1762. /****************************************/
  1763. void
  1764. CEditWnd::ToolInit(
  1765. int LRButton)
  1766. {
  1767. this->SetCapture();
  1768. ButtonFlag = LRButton;
  1769. IsCapture = TRUE;
  1770. if( SelectItem == PEN || SelectItem == SLOPE)
  1771. BrushWidth = 1;
  1772. else if( SelectItem == BRUSH || SelectItem == ERASER)
  1773. BrushWidth = 2;
  1774. }
  1775. /****************************************/
  1776. /* */
  1777. /* Rubberband stretch mode */
  1778. /* */
  1779. /****************************************/
  1780. void
  1781. CEditWnd::StretchMoveRect()
  1782. {
  1783. CPen *OldPen;
  1784. CBrush *OldBrush;
  1785. int Left, Top, Right, Bottom;
  1786. CClientDC dc( this);
  1787. OldPen = (CPen *)dc.SelectStockObject( BLACK_PEN);
  1788. OldBrush = (CBrush *)dc.SelectStockObject( NULL_BRUSH);
  1789. int OldMode = dc.SetROP2( R2_NOTXORPEN);
  1790. dc.Rectangle( &ClipRect[PRV]);
  1791. Left = ClipRect[DSP].left;
  1792. Top = ClipRect[DSP].top;
  1793. Right = ClipRect[DSP].right;
  1794. Bottom = ClipRect[DSP].bottom;
  1795. switch( CheckNum){
  1796. case RLOWER:
  1797. ClipRect[DSP].SetRect( Left, Top,
  1798. ptEnd.x + ZoomRate + 1,
  1799. ptEnd.y + CAPTION_HEIGHT + ZoomRate + 1);
  1800. if( ClipRect[DSP].Height() < ZoomRate*2)
  1801. ClipRect[DSP].bottom = ClipRect[DSP].top
  1802. + ZoomRate*2+1;
  1803. if( ClipRect[DSP].Width() < ZoomRate*2)
  1804. ClipRect[DSP].right = ClipRect[DSP].left
  1805. + ZoomRate*2+1;
  1806. break;
  1807. case RMIDLE:
  1808. ClipRect[DSP].SetRect( Left, Top,
  1809. ptEnd.x + ZoomRate + 1, Bottom);
  1810. if( ClipRect[DSP].Width() < ZoomRate*2)
  1811. ClipRect[DSP].right = ClipRect[DSP].left
  1812. + ZoomRate*2+1;
  1813. break;
  1814. case MLOWER:
  1815. ClipRect[DSP].SetRect( Left, Top,
  1816. Right, ptEnd.y + CAPTION_HEIGHT + ZoomRate + 1);
  1817. if( ClipRect[DSP].Height() < ZoomRate*2)
  1818. ClipRect[DSP].bottom = ClipRect[DSP].top
  1819. + ZoomRate*2+1;
  1820. break;
  1821. case RUPPER:
  1822. ClipRect[DSP].SetRect( Left, ptEnd.y + CAPTION_HEIGHT,
  1823. ptEnd.x + ZoomRate + 1, Bottom);
  1824. if( ClipRect[DSP].Height() < ZoomRate*2)
  1825. ClipRect[DSP].top = ClipRect[DSP].bottom
  1826. - ZoomRate*2+1;
  1827. if( ClipRect[DSP].Width() < ZoomRate*2)
  1828. ClipRect[DSP].right = ClipRect[DSP].left
  1829. + ZoomRate*2+1;
  1830. break;
  1831. case LLOWER:
  1832. ClipRect[DSP].SetRect( ptEnd.x, Top,
  1833. Right, ptEnd.y + CAPTION_HEIGHT + ZoomRate + 1);
  1834. if( ClipRect[DSP].Width() < ZoomRate*2)
  1835. ClipRect[DSP].left = ClipRect[DSP].right
  1836. - ZoomRate*2+1;
  1837. if( ClipRect[DSP].Height() < ZoomRate*2)
  1838. ClipRect[DSP].bottom = ClipRect[DSP].top
  1839. + ZoomRate*2+1;
  1840. break;
  1841. case LMIDLE:
  1842. ClipRect[DSP].SetRect( ptEnd.x, Top, Right, Bottom);
  1843. if( ClipRect[DSP].Width() < ZoomRate*2)
  1844. ClipRect[DSP].left = ClipRect[DSP].right
  1845. - ZoomRate*2+1;
  1846. break;
  1847. case MUPPER:
  1848. ClipRect[DSP].SetRect( Left, ptEnd.y + CAPTION_HEIGHT,
  1849. Right, Bottom);
  1850. if( ClipRect[DSP].Height() < ZoomRate*2)
  1851. ClipRect[DSP].top = ClipRect[DSP].bottom
  1852. - ZoomRate*2+1;
  1853. break;
  1854. case LUPPER:
  1855. ClipRect[DSP].SetRect( ptEnd.x,
  1856. ptEnd.y + CAPTION_HEIGHT, Right, Bottom);
  1857. if( ClipRect[DSP].Height() < ZoomRate*2)
  1858. ClipRect[DSP].top = ClipRect[DSP].bottom
  1859. - ZoomRate*2+1;
  1860. if( ClipRect[DSP].Width() < ZoomRate*2)
  1861. ClipRect[DSP].left = ClipRect[DSP].right
  1862. - ZoomRate*2+1;
  1863. break;
  1864. default:
  1865. break;
  1866. }
  1867. ClipRect[PRV].CopyRect( &ClipRect[DSP]);
  1868. dc.Rectangle( &ClipRect[DSP]);
  1869. dc.SelectObject( OldPen);
  1870. dc.SelectObject( OldBrush);
  1871. dc.SetROP2( OldMode);
  1872. }
  1873. /****************************************/
  1874. /* */
  1875. /* FreeForm */
  1876. /* */
  1877. /****************************************/
  1878. void
  1879. CEditWnd::SelectFreeForm(
  1880. BOOL MouseSts)
  1881. {
  1882. CPoint Ep, Sp, Cp;
  1883. CPoint Fp, Inc;
  1884. CPoint Dp, Err;
  1885. BOOL Slope;
  1886. int D;
  1887. int Tmp;
  1888. if( !MouseSts){
  1889. Sp.x = ptPrev.x /ZoomRate;
  1890. Sp.y = ptPrev.y /ZoomRate;
  1891. Ep.x = Fp.x = ptEnd.x /ZoomRate;
  1892. Ep.y = Fp.y = ptEnd.y /ZoomRate;
  1893. }else{
  1894. Sp.x = ptEnd.x /ZoomRate;
  1895. Sp.y = ptEnd.y /ZoomRate;
  1896. Ep.x = Fp.x = ptStart.x /ZoomRate;
  1897. Ep.y = Fp.y = ptStart.y /ZoomRate;
  1898. }
  1899. if( Fp.x >= Sp.x)
  1900. Inc.x = 1;
  1901. else Inc.x = -1;
  1902. if( Fp.y >= Sp.y)
  1903. Inc.y = 1;
  1904. else Inc.y = -1;
  1905. Dp.x = ( Fp.x - Sp.x)*Inc.x;
  1906. Dp.y = ( Fp.y - Sp.y)*Inc.y;
  1907. if( !Dp.x && !Dp.y) return;
  1908. if( Dp.x < Dp.y){
  1909. Tmp = Dp.y;
  1910. Dp.y = Dp.x;
  1911. Dp.x = Tmp;
  1912. Tmp = Inc.x;
  1913. Inc.x = Inc.y;
  1914. Inc.y = Tmp;
  1915. Slope = TRUE;
  1916. }else Slope = FALSE;
  1917. Err.x = Dp.y * 2;
  1918. Err.y = ( Dp.y - Dp.x) * 2;
  1919. D = Err.x - Dp.x;
  1920. Ep = Sp;
  1921. while(1){
  1922. m_SelectArray.Add( Ep);
  1923. if( Ep.x == Fp.x && Ep.y == Fp.y)
  1924. break;
  1925. if( Slope){
  1926. Tmp = Ep.x;
  1927. Ep.x = Ep.y;
  1928. Ep.y = Tmp;
  1929. }
  1930. Ep.x += Inc.x;
  1931. if( D < 0) D += Err.x;
  1932. else{
  1933. Ep.y += Inc.y;
  1934. D += Err.y;
  1935. }
  1936. if( Slope){
  1937. Tmp = Ep.x;
  1938. Ep.x = Ep.y;
  1939. Ep.y = Tmp;
  1940. }
  1941. }
  1942. }
  1943. /****************************************/
  1944. /* */
  1945. /* FreeForm */
  1946. /* */
  1947. /****************************************/
  1948. void
  1949. CEditWnd::DrawFreeForm(
  1950. BOOL MouseSts)
  1951. {
  1952. CPoint Ep, Sp, Cp;
  1953. CPoint Fp, Inc;
  1954. CPoint Dp, Err;
  1955. CPoint P1, P2;
  1956. BOOL Slope;
  1957. int D;
  1958. int Tmp;
  1959. CClientDC dc( this);
  1960. CPen *OldPen = (CPen *)dc.SelectStockObject( BLACK_PEN);
  1961. int OldMode = dc.SetROP2( R2_NOTXORPEN);
  1962. if( !MouseSts){
  1963. Sp.x = ptPrev.x;
  1964. Sp.y = ptPrev.y + CAPTION_HEIGHT;
  1965. Ep.x = Fp.x = ptEnd.x;
  1966. Ep.y = Fp.y = ptEnd.y + CAPTION_HEIGHT;
  1967. }else{
  1968. Sp.x = ptEnd.x;
  1969. Sp.y = ptEnd.y + CAPTION_HEIGHT;
  1970. Ep.x = Fp.x = ptStart.x;
  1971. Ep.y = Fp.y = ptStart.y + CAPTION_HEIGHT;
  1972. }
  1973. if( Fp.x >= Sp.x)
  1974. Inc.x = ZoomRate;
  1975. else Inc.x = 0 - ZoomRate;
  1976. if( Fp.y >= Sp.y)
  1977. Inc.y = ZoomRate;
  1978. else Inc.y = 0 - ZoomRate;
  1979. Dp.x = ( Fp.x - Sp.x)*Inc.x;
  1980. Dp.y = ( Fp.y - Sp.y)*Inc.y;
  1981. if( !Dp.x && !Dp.y) return;
  1982. if( Dp.x < Dp.y){
  1983. Tmp = Dp.y;
  1984. Dp.y = Dp.x;
  1985. Dp.x = Tmp;
  1986. Tmp = Inc.x;
  1987. Inc.x = Inc.y;
  1988. Inc.y = Tmp;
  1989. Slope = TRUE;
  1990. }else Slope = FALSE;
  1991. Err.x = Dp.y * 2;
  1992. Err.y = ( Dp.y - Dp.x) * 2;
  1993. D = Err.x - Dp.x;
  1994. Ep = Sp;
  1995. dc.MoveTo( Sp);
  1996. while(1){
  1997. if( Sp.x != Ep.x && Sp.y != Ep.y){
  1998. if( Sp.y < Ep.y && Sp.x > Ep.x){
  1999. Cp.x = Sp.x;
  2000. Cp.y = Ep.y;
  2001. }else if( Sp.y < Ep.y && Sp.x < Ep.x){
  2002. Cp.x = Sp.x;
  2003. Cp.y = Ep.y;
  2004. }else if( Sp.y > Ep.y && Sp.x > Ep.x){
  2005. Cp.y = Sp.y;
  2006. Cp.x = Ep.x;
  2007. }else{
  2008. Cp.y = Sp.y;
  2009. Cp.x = Ep.x;
  2010. }
  2011. dc.LineTo( Cp);
  2012. dc.LineTo( Ep);
  2013. P1 = Cp;
  2014. P2 = Ep;
  2015. m_pointArray.Add( P1);
  2016. m_pointArray.Add( P2);
  2017. }else if( Sp.x != Ep.x || Sp.y != Ep.y){
  2018. dc.LineTo( Ep);
  2019. P1 = Ep;
  2020. m_pointArray.Add( P1);
  2021. }
  2022. Sp.x = Ep.x;
  2023. Sp.y = Ep.y;
  2024. if( Ep.x == Fp.x && Ep.y == Fp.y)
  2025. break;
  2026. if( Slope){
  2027. Tmp = Ep.x;
  2028. Ep.x = Ep.y;
  2029. Ep.y = Tmp;
  2030. }
  2031. Ep.x += Inc.x;
  2032. if( D < 0) D += Err.x;
  2033. else{
  2034. Ep.y += Inc.y;
  2035. D += Err.y;
  2036. }
  2037. if( Slope){
  2038. Tmp = Ep.x;
  2039. Ep.x = Ep.y;
  2040. Ep.y = Tmp;
  2041. }
  2042. }
  2043. dc.SelectObject( OldPen);
  2044. dc.SetROP2( OldMode);
  2045. }
  2046. /****************************************/
  2047. /* */
  2048. /* Rubber Band( rectangle and circle) */
  2049. /* */
  2050. /****************************************/
  2051. void
  2052. CEditWnd::DrawRubberBand(
  2053. BOOL StretchFlag)
  2054. {
  2055. CRect RubberBandRect;
  2056. CPoint ptLT, ptRB;
  2057. int OldMode;
  2058. CClientDC dc( this);
  2059. CPen *OldPen = (CPen *)dc.SelectStockObject( BLACK_PEN);
  2060. CBrush *OldBrush = (CBrush *)dc.SelectStockObject( NULL_BRUSH);
  2061. OldMode = dc.SetROP2( R2_NOTXORPEN);
  2062. if( !StretchFlag){
  2063. ptLT.x = ptStart.x;
  2064. ptLT.y = ptStart.y + CAPTION_HEIGHT;
  2065. ptRB.x = ptPrev.x;
  2066. ptRB.y = ptPrev.y + CAPTION_HEIGHT;
  2067. if( SelectItem != SLOPE)
  2068. IllegalRect( &ptLT, &ptRB);
  2069. RubberBandRect.SetRect( ptLT.x, ptLT.y,
  2070. ptRB.x + ZoomRate + 1, ptRB.y + ZoomRate + 1);
  2071. if( SelectItem == SLOPE){
  2072. dc.MoveTo( ptLT);
  2073. dc.LineTo( ptRB);
  2074. }else if( SelectItem == CIRCLE || SelectItem == CIRCLEFILL)
  2075. dc.Ellipse( &RubberBandRect);
  2076. else dc.Rectangle( &RubberBandRect);
  2077. }
  2078. ptLT.x = ptStart.x;
  2079. ptLT.y = ptStart.y + CAPTION_HEIGHT;
  2080. ptRB.x = ptEnd.x;
  2081. ptRB.y = ptEnd.y + CAPTION_HEIGHT;
  2082. ptPrev = ptRB;
  2083. if( SelectItem != SLOPE)
  2084. IllegalRect( &ptLT, &ptRB);
  2085. RubberBandRect.SetRect( ptLT.x, ptLT.y,
  2086. ptRB.x + ZoomRate + 1, ptRB.y + ZoomRate + 1);
  2087. if( SelectItem == SLOPE){
  2088. dc.MoveTo( ptLT);
  2089. dc.LineTo( ptRB);
  2090. }else if( SelectItem == CIRCLE || SelectItem == CIRCLEFILL)
  2091. dc.Ellipse( &RubberBandRect);
  2092. else dc.Rectangle( &RubberBandRect);
  2093. dc.SelectObject( OldPen);
  2094. dc.SelectObject( OldBrush);
  2095. dc.SetROP2( OldMode);
  2096. }
  2097. /****************************************/
  2098. /* */
  2099. /* Correct coordinate of rectangle */
  2100. /* */
  2101. /****************************************/
  2102. void
  2103. CEditWnd::IllegalRect(
  2104. PPOINT ptTL,
  2105. PPOINT ptBR)
  2106. {
  2107. int Tmp;
  2108. if( ptTL->x > ptBR->x){
  2109. Tmp = ptTL->x;
  2110. ptTL->x = ptBR->x;
  2111. ptBR->x = Tmp;
  2112. }
  2113. if( ptTL->y > ptBR->y){
  2114. Tmp = ptTL->y;
  2115. ptTL->y = ptBR->y;
  2116. ptBR->y = Tmp;
  2117. }
  2118. }
  2119. /****************************************/
  2120. /* */
  2121. /* Process to term tool */
  2122. /* */
  2123. /****************************************/
  2124. void
  2125. CEditWnd::ToolTerm()
  2126. {
  2127. if( IsCapture){
  2128. IsCapture = FALSE;
  2129. ReleaseCapture();
  2130. }
  2131. ButtonFlag = NCLICK;
  2132. }
  2133. /****************************************/
  2134. /* */
  2135. /* Set Freeform selection */
  2136. /* */
  2137. /****************************************/
  2138. BOOL
  2139. CEditWnd::SetFreeForm()
  2140. {
  2141. CBrush EraseBrush;
  2142. CBrush BlackBrush;
  2143. PickRgn.GetRgnBox( &ClipRect[BMP]);
  2144. if( ClipRect[BMP].Width() < 3 ||
  2145. ClipRect[BMP].Height() < 3){
  2146. FreeRgn.GetRgnBox( &ClipRect[DSP]);
  2147. ClipRect[DSP].right += 1;
  2148. ClipRect[DSP].bottom += 1;
  2149. return FALSE;
  2150. }
  2151. EraseBrush.CreateStockObject( WHITE_BRUSH);
  2152. BlackBrush.CreateStockObject( BLACK_BRUSH);
  2153. CRTDrawDC.FillRect( &ClipRect[BMP], &EraseBrush);
  2154. CRTDrawDC.FillRgn( &PickRgn, &BlackBrush);
  2155. EraseBrush.DeleteObject();
  2156. BlackBrush.DeleteObject();
  2157. CRTDrawDC.BitBlt( ClipRect[BMP].left, ClipRect[BMP].top,
  2158. ClipRect[BMP].Width(), ClipRect[BMP].Height(),
  2159. &ImageDC, ClipRect[BMP].left, ClipRect[BMP].top, SRCPAINT);
  2160. FreeRgn.GetRgnBox( &ClipRect[DSP]);
  2161. ClipRect[DSP].right += 1;
  2162. ClipRect[DSP].bottom += 1;
  2163. return TRUE;
  2164. }
  2165. /****************************************/
  2166. /* */
  2167. /* Erase Freeform selection area */
  2168. /* */
  2169. /****************************************/
  2170. void
  2171. CEditWnd::EraseFreeForm()
  2172. {
  2173. CBrush CutBrush;
  2174. CutBrush.CreateSolidBrush( COLOR_WHITE );
  2175. ImageDC.FillRgn( &PickRgn, &CutBrush);
  2176. CutBrush.DeleteObject();
  2177. }
  2178. /****************************************/
  2179. /* */
  2180. /* Erase rectangle selection area */
  2181. /* */
  2182. /****************************************/
  2183. void
  2184. CEditWnd::EraseRectangle()
  2185. {
  2186. CRect pRect;
  2187. CPen *OldPen;
  2188. CBrush CutBrush;
  2189. OldPen = (CPen *)ImageDC.SelectStockObject( NULL_PEN);
  2190. CutBrush.CreateSolidBrush( COLOR_WHITE );
  2191. CBrush *OldBrush = ImageDC.SelectObject( &CutBrush);
  2192. pRect.CopyRect( &ClipRect[BMP]);
  2193. pRect.right += 1;
  2194. pRect.bottom += 1;
  2195. ImageDC.Rectangle( &pRect);
  2196. ImageDC.SelectObject( OldPen);
  2197. ImageDC.SelectObject( OldBrush);
  2198. CutBrush.DeleteObject();
  2199. RectClipFlag = FALSE;
  2200. SetValidRect();
  2201. this->InvalidateRect( &ClipRect[VLD], FALSE);
  2202. this->UpdateWindow();
  2203. RectClipFlag = TRUE;
  2204. }
  2205. /****************************************/
  2206. /* */
  2207. /* Save character with same code */
  2208. /* */
  2209. /****************************************/
  2210. #define ABORT 1
  2211. #define CANCEL 0
  2212. int
  2213. CEditWnd::SaveEUDCCode(UINT msgBoxType)
  2214. {
  2215. CClientDC dc(this);
  2216. CFont cFont, *OldFont;
  2217. LOGFONT LogFont;
  2218. DWORD wSize;
  2219. LPBYTE pBuf=NULL;
  2220. LPBYTE pBuf2=NULL;
  2221. TCHAR BMPPath[MAX_PATH];
  2222. TCHAR TTFPath[MAX_PATH];
  2223. TCHAR *FilePtr;
  2224. int FontType, sts=0;
  2225. //fix for FontIsLinked
  2226. BOOL firstTime = false;
  2227. //
  2228. HRESULT hresult;
  2229. if( SelectItem == RECTCLIP || SelectItem == FREEFORM)
  2230. WriteSelRectBitmap();
  2231. //*STRSAFE* lstrcpy(TTFPath, SelectEUDC.m_File);
  2232. hresult = StringCchCopy(TTFPath , ARRAYLEN(TTFPath), SelectEUDC.m_File);
  2233. if (!SUCCEEDED(hresult))
  2234. {
  2235. goto RET3;
  2236. }
  2237. //*STRSAFE* lstrcpy(BMPPath,TTFPath);
  2238. hresult = StringCchCopy(BMPPath , ARRAYLEN(BMPPath), TTFPath);
  2239. if (!SUCCEEDED(hresult))
  2240. {
  2241. goto RET3;
  2242. }
  2243. if(( FilePtr = Mytcsrchr( BMPPath, '.')) != NULL)
  2244. *FilePtr = '\0';
  2245. //*STRSAFE* lstrcat( BMPPath, TEXT(".EUF"));
  2246. hresult = StringCchCat(BMPPath , ARRAYLEN(BMPPath), TEXT(".EUF"));
  2247. if (!SUCCEEDED(hresult))
  2248. {
  2249. goto RET3;
  2250. }
  2251. DWORD dwStart = GetTickCount();
  2252. // Stop if this has taken too long
  2253. while (1)
  2254. {
  2255. if( GetTickCount() - dwStart >= 1000 )
  2256. break;
  2257. }
  2258. if( !EnableEUDC( FALSE)){
  2259. MessageBox(TEXT("EnableEUDC() Error"), TEXT("EudcEditor"), MB_OK);
  2260. return ABORT;
  2261. }
  2262. //fix for FontIsLinked
  2263. //create logFont first, then use this font to create new character
  2264. OInit();
  2265. if( !OExistTTF( TTFPath)){
  2266. firstTime = TRUE;
  2267. memset( &LogFont, 0, sizeof( LogFont));
  2268. //*STRSAFE* lstrcpy (LogFont.lfFaceName, CountryInfo.szForceFont);
  2269. hresult = StringCchCopy(LogFont.lfFaceName , ARRAYLEN(LogFont.lfFaceName), CountryInfo.szForceFont);
  2270. if (!SUCCEEDED(hresult))
  2271. {
  2272. goto RET;
  2273. }
  2274. LogFont.lfHeight = BITMAP_HEIGHT;
  2275. LogFont.lfWidth = BITMAP_WIDTH;
  2276. LogFont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  2277. LogFont.lfCharSet = (BYTE)CountryInfo.CharacterSet;
  2278. LogFont.lfPitchAndFamily = FF_ROMAN; //| FIXED_PITCH;
  2279. if (CountryInfo.LangID == EUDC_JPN)
  2280. {
  2281. // JPN platform, use fixed pitch font.
  2282. LogFont.lfPitchAndFamily |= FIXED_PITCH;
  2283. }
  2284. if( !cFont.CreateFontIndirect( &LogFont)){
  2285. OutputMessageBox(this->GetSafeHwnd(),
  2286. IDS_ASSOCIATE_DLGTITLE,
  2287. IDS_SELECTFONT_ERROR, TRUE);
  2288. OTerm();
  2289. EnableEUDC(TRUE);
  2290. return ABORT;
  2291. }
  2292. OldFont = dc.SelectObject( &cFont);
  2293. FontType = !SelectEUDC.m_FontTypeFlg? 1:0;
  2294. if( OCreateTTF( dc.GetSafeHdc(), TTFPath, FontType))
  2295. {
  2296. dc.SelectObject(OldFont);
  2297. cFont.DeleteObject();
  2298. OTerm();
  2299. EnableEUDC(TRUE);
  2300. return ABORT;
  2301. }
  2302. dc.SelectObject(OldFont);
  2303. cFont.DeleteObject();
  2304. }
  2305. wSize = (DWORD)((( BITMAP_WIDTH +15) /16) *2) *(WORD)BITMAP_HEIGHT;
  2306. pBuf = (LPBYTE)malloc(((( BITMAP_WIDTH +15) /16) *2) *BITMAP_HEIGHT);
  2307. if( pBuf == NULL){
  2308. OTerm();
  2309. EnableEUDC(TRUE);
  2310. return ABORT;
  2311. }
  2312. pBuf2 = pBuf;
  2313. ImageBmp.GetBitmapBits( wSize, (LPVOID)pBuf2);
  2314. if( OMakeOutline( (LPBYTE)pBuf2, BITMAP_WIDTH, SMOOTHLVL) < 0)
  2315. {
  2316. free(pBuf);
  2317. OTerm();
  2318. EnableEUDC(TRUE);
  2319. return ABORT;
  2320. }
  2321. sts = OOutTTF( dc.GetSafeHdc(),
  2322. TTFPath,
  2323. (unsigned short)UpdateCode,
  2324. CountryInfo.bUnicodeMode);
  2325. if (sts == -3) //tte file is being used by another process
  2326. {
  2327. free(pBuf);
  2328. OTerm();
  2329. EnableEUDC(TRUE);
  2330. HINSTANCE hInst = AfxGetInstanceHandle();
  2331. TCHAR szMessage[256];
  2332. LoadString(hInst, IDS_OVERWRITEFAIL, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  2333. TCHAR szTitle[256];
  2334. LoadString(hInst, IDS_MAINFRAMETITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  2335. if (MessageBox( szMessage, szTitle, msgBoxType) == IDCANCEL)
  2336. return CANCEL;
  2337. else
  2338. return ABORT;
  2339. }
  2340. else if (sts < 0)
  2341. {
  2342. free(pBuf);
  2343. OTerm();
  2344. EnableEUDC(TRUE);
  2345. OutputMessageBox( this->GetSafeHwnd(),
  2346. IDS_MAINFRAMETITLE,
  2347. IDS_NOTENOUGHMEMORY_ERROR, TRUE);
  2348. return ABORT;
  2349. }
  2350. //fix for FontIsLinked
  2351. if (firstTime)
  2352. {
  2353. if (creatW31JEUDC(BMPPath))
  2354. {
  2355. free(pBuf);
  2356. OTerm();
  2357. EnableEUDC(TRUE);
  2358. return ABORT;
  2359. }
  2360. }
  2361. //
  2362. if( OpenW31JEUDC( BMPPath)){
  2363. free(pBuf);
  2364. OTerm();
  2365. EnableEUDC(TRUE);
  2366. return ABORT;
  2367. }
  2368. if( PutW31JEUDCFont((unsigned short)UpdateCode, pBuf2, BITMAP_WIDTH,
  2369. BITMAP_HEIGHT, CountryInfo.bUnicodeMode)){
  2370. CloseW31JEUDC();
  2371. free(pBuf);
  2372. OTerm();
  2373. EnableEUDC(TRUE);
  2374. return ABORT;
  2375. }
  2376. CloseW31JEUDC();
  2377. BitmapDirty = FALSE;
  2378. g_bKeepEUDCLink = TRUE;
  2379. RET:
  2380. if (pBuf)
  2381. {
  2382. free(pBuf);
  2383. }
  2384. OTerm();
  2385. EnableEUDC(TRUE);
  2386. RET3:
  2387. return ABORT;
  2388. }
  2389. /****************************************/
  2390. /* */
  2391. /* draw image for undo */
  2392. /* */
  2393. /****************************************/
  2394. void
  2395. CEditWnd::UndoImageDraw()
  2396. {
  2397. CDC UndoDC;
  2398. if( !UndoBitmapFlag)
  2399. CreateUndoBitmap();
  2400. UndoDC.CreateCompatibleDC( &ImageDC);
  2401. CBitmap *OldBitmap = UndoDC.SelectObject( &UndoImage);
  2402. UndoDC.BitBlt( 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT,
  2403. &ImageDC, 0, 0, SRCCOPY);
  2404. if( RectClipFlag && (SelectItem == RECTCLIP || SelectItem == FREEFORM)){
  2405. CRect pRect;
  2406. pRect.SetRect(( ClipRect[DSP].left + 1) /ZoomRate,
  2407. ( ClipRect[DSP].top - CAPTION_HEIGHT +1) /ZoomRate,
  2408. ( ClipRect[DSP].right + 1)/ZoomRate,
  2409. ( ClipRect[DSP].bottom - CAPTION_HEIGHT +1) /ZoomRate);
  2410. UndoDC.StretchBlt( pRect.left, pRect.top,
  2411. pRect.Width(), pRect.Height(), &CRTDrawDC,
  2412. ClipRect[BMP].left, ClipRect[BMP].top,
  2413. ClipRect[BMP].Width(), ClipRect[BMP].Height(), SRCAND);
  2414. }
  2415. UndoDC.SelectObject( OldBitmap);
  2416. UndoDC.DeleteDC();
  2417. UndoBitmapFlag = TRUE;
  2418. }
  2419. /****************************************/
  2420. /* */
  2421. /* for Update */
  2422. /* */
  2423. /****************************************/
  2424. BOOL
  2425. CEditWnd::SelectCodes()
  2426. {
  2427. int xSize, ySize;
  2428. int wSize;
  2429. LPBYTE pBuf=NULL;
  2430. TCHAR *FilePtr;
  2431. TCHAR BMPPath[MAX_PATH];
  2432. HRESULT hresult;
  2433. //*STRSAFE* lstrcpy( BMPPath, SelectEUDC.m_File);
  2434. hresult = StringCchCopy(BMPPath , ARRAYLEN(BMPPath), SelectEUDC.m_File);
  2435. if (!SUCCEEDED(hresult))
  2436. {
  2437. return FALSE;
  2438. }
  2439. if(( FilePtr = Mytcsrchr( BMPPath, '.')) != NULL)
  2440. *FilePtr = '\0';
  2441. //*STRSAFE* lstrcat( BMPPath, TEXT(".EUF"));
  2442. hresult = StringCchCat(BMPPath , ARRAYLEN(BMPPath), TEXT(".EUF"));
  2443. if (!SUCCEEDED(hresult))
  2444. {
  2445. return FALSE;
  2446. }
  2447. wSize = (int)((( BITMAP_WIDTH + 15) /16) *2) *(int)BITMAP_HEIGHT;
  2448. pBuf = (LPBYTE)malloc( wSize);
  2449. if( OpenW31JEUDC( BMPPath)){
  2450. free( pBuf);
  2451. return FALSE;
  2452. }
  2453. if( GetW31JEUDCFont((unsigned short)UpdateCode, pBuf, wSize,
  2454. &xSize, &ySize, CountryInfo.bUnicodeMode)){
  2455. CloseW31JEUDC();
  2456. free( pBuf);
  2457. return FALSE;
  2458. }else if( xSize != BITMAP_WIDTH || ySize != BITMAP_HEIGHT){
  2459. CloseW31JEUDC();
  2460. free( pBuf);
  2461. return FALSE;
  2462. }
  2463. CloseW31JEUDC();
  2464. ImageBmp.SetBitmapBits( wSize, (LPVOID)pBuf);
  2465. BitmapDirty = FALSE;
  2466. if (pBuf)
  2467. {
  2468. free( pBuf);
  2469. }
  2470. this->Invalidate( FALSE);
  2471. this->UpdateWindow();
  2472. return TRUE;
  2473. }
  2474. /****************************************/
  2475. /* */
  2476. /* Clear bitmap data */
  2477. /* */
  2478. /****************************************/
  2479. BOOL
  2480. CEditWnd::UpdateBitmap()
  2481. {
  2482. WORD wSize;
  2483. HANDLE BitHandle;
  2484. BYTE *pBitmap;
  2485. wSize = (WORD)((( BITMAP_WIDTH +15) /16) *2) *(WORD)BITMAP_HEIGHT;
  2486. if(( BitHandle = LocalAlloc( LMEM_MOVEABLE, wSize)) == 0)
  2487. return FALSE;
  2488. if(( pBitmap = (BYTE *)LocalLock( BitHandle)) == NULL){
  2489. LocalFree( BitHandle);
  2490. return FALSE;
  2491. }
  2492. memset( pBitmap, 0xffff, wSize);
  2493. ImageBmp.SetBitmapBits((DWORD)wSize, (const void far *)pBitmap);
  2494. LocalUnlock( BitHandle);
  2495. LocalFree( BitHandle);
  2496. if(( SelectItem == RECTCLIP || SelectItem == FREEFORM) && RectClipFlag){
  2497. RectClipFlag = FALSE;
  2498. ToolTerm();
  2499. }
  2500. this->Invalidate( FALSE);
  2501. this->UpdateWindow();
  2502. BitmapDirty = FALSE;
  2503. return TRUE;
  2504. }
  2505. /****************************************/
  2506. /* */
  2507. /* Get bitmap dirty flag */
  2508. /* */
  2509. /****************************************/
  2510. BOOL
  2511. CEditWnd::GetBitmapDirty()
  2512. {
  2513. return BitmapDirty;
  2514. }
  2515. /****************************************/
  2516. /* */
  2517. /* Get bitmap dirty flag */
  2518. /* */
  2519. /****************************************/
  2520. BOOL
  2521. CEditWnd::SetBitmapDirty(
  2522. BOOL Flg)
  2523. {
  2524. BitmapDirty = Flg;
  2525. return TRUE;
  2526. }
  2527. /****************************************/
  2528. /* */
  2529. /* Call Charcter */
  2530. /* */
  2531. /****************************************/
  2532. void
  2533. CEditWnd::CallCharTextOut()
  2534. {
  2535. CFont CallFont;
  2536. CSize CharSize;
  2537. BYTE sWork[10];
  2538. int Length;
  2539. int xOffset, yOffset;
  2540. EditLogFont.lfHeight = BITMAP_HEIGHT;
  2541. EditLogFont.lfWeight = 0;
  2542. EditLogFont.lfQuality = PROOF_QUALITY;
  2543. if( !CallFont.CreateFontIndirect( &EditLogFont))
  2544. return;
  2545. CFont *OldFont = ImageDC.SelectObject( &CallFont);
  2546. if( !CallCode)
  2547. Length = 0;
  2548. else
  2549. {
  2550. sWork[0] = LOBYTE(CallCode);
  2551. sWork[1] = HIBYTE(CallCode);
  2552. sWork[2] = sWork[3] = 0;
  2553. Length = 1;
  2554. }
  2555. /*
  2556. else if( !HIBYTE(CallCode)){
  2557. // SBCS
  2558. sWork[0] = LOBYTE(CallCode);
  2559. sWork[1] = (BYTE)'\0';
  2560. Length = 1;
  2561. }else{
  2562. // DBCS
  2563. sWork[0] = HIBYTE(CallCode);
  2564. sWork[1] = LOBYTE(CallCode);
  2565. sWork[2] = (BYTE)'\0';
  2566. Length = 2;
  2567. }
  2568. */
  2569. if( Length){
  2570. CRect TextImage;
  2571. /*
  2572. GetTextExtentPoint32A( ImageDC.GetSafeHdc(), (LPCSTR)sWork,
  2573. Length, &CharSize);
  2574. */
  2575. GetTextExtentPoint32W( ImageDC.GetSafeHdc(), (LPCWSTR)sWork,
  2576. Length, &CharSize);
  2577. TextImage.SetRect( 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT);
  2578. if( CharSize.cx < BITMAP_WIDTH)
  2579. xOffset = ( BITMAP_HEIGHT - CharSize.cx) /2;
  2580. else xOffset = 0;
  2581. if( CharSize.cy < BITMAP_HEIGHT)
  2582. yOffset = ( BITMAP_WIDTH - CharSize.cy) /2;
  2583. else yOffset = 0;
  2584. if( EditLogFont.lfFaceName[0] == '@' &&
  2585. Length == 1)
  2586. xOffset = yOffset = 0;
  2587. /*
  2588. ExtTextOutA(ImageDC.GetSafeHdc(), xOffset, yOffset, ETO_OPAQUE,
  2589. &TextImage, (LPCSTR)sWork, Length, NULL);
  2590. */
  2591. ExtTextOutW(ImageDC.GetSafeHdc(), xOffset, yOffset, ETO_OPAQUE,
  2592. &TextImage, (LPCWSTR)sWork, Length, NULL);
  2593. }
  2594. ImageDC.SelectObject( OldFont);
  2595. CallFont.DeleteObject();
  2596. this->Invalidate( FALSE);
  2597. this->UpdateWindow();
  2598. }
  2599. /****************************************/
  2600. /* */
  2601. /* COMMAND "Flip/Rotate" */
  2602. /* */
  2603. /****************************************/
  2604. void
  2605. CEditWnd::FlipRotate(
  2606. int RadioItem)
  2607. {
  2608. CDC RotateDC;
  2609. CBitmap RotateBMP;
  2610. CBrush wBrush;
  2611. int wSize;
  2612. LPBYTE pBuf1 = NULL;
  2613. LPBYTE pBuf2 = NULL;
  2614. LPBYTE pPtr1, pPtr2;
  2615. UndoImageDraw();
  2616. BitmapDirty = TRUE;
  2617. InitFlipRotate( &RotateDC, &RotateBMP);
  2618. switch( RadioItem){
  2619. case FLIP_HOR:
  2620. if( !RectClipFlag){
  2621. ImageDC.StretchBlt( BITMAP_WIDTH - 1, 0,
  2622. 0 - BITMAP_WIDTH, BITMAP_HEIGHT, &CRTDrawDC,
  2623. 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT, SRCCOPY);
  2624. }else{
  2625. wBrush.CreateStockObject( WHITE_BRUSH);
  2626. CRTDrawDC.FillRect( &ClipRect[BMP], &wBrush);
  2627. wBrush.DeleteObject();
  2628. CRTDrawDC.StretchBlt(
  2629. ClipRect[BMP].right - 1, ClipRect[BMP].top,
  2630. 0 - ClipRect[BMP].Width(),
  2631. ClipRect[BMP].Height(), &RotateDC,
  2632. ClipRect[BMP].left, ClipRect[BMP].top,
  2633. ClipRect[BMP].Width(),
  2634. ClipRect[BMP].Height(), SRCCOPY);
  2635. }
  2636. break;
  2637. case FLIP_VER:
  2638. if( !RectClipFlag){
  2639. ImageDC.StretchBlt( 0, BITMAP_HEIGHT - 1, BITMAP_WIDTH,
  2640. 0 - BITMAP_HEIGHT, &CRTDrawDC, 0, 0,
  2641. BITMAP_WIDTH, BITMAP_HEIGHT, SRCCOPY);
  2642. }else{
  2643. wBrush.CreateStockObject( WHITE_BRUSH);
  2644. CRTDrawDC.FillRect( &ClipRect[BMP], &wBrush);
  2645. wBrush.DeleteObject();
  2646. CRTDrawDC.StretchBlt(
  2647. ClipRect[BMP].left,ClipRect[BMP].bottom - 1,
  2648. ClipRect[BMP].Width(),
  2649. 0 - ClipRect[BMP].Height(), &RotateDC,
  2650. ClipRect[BMP].left, ClipRect[BMP].top,
  2651. ClipRect[BMP].Width(),
  2652. ClipRect[BMP].Height(), SRCCOPY);
  2653. }
  2654. break;
  2655. case ROTATE_9:
  2656. wSize = (int)((( BITMAP_WIDTH +15) /16) *2)*(int)BITMAP_HEIGHT;
  2657. pBuf1 = (LPBYTE)malloc( wSize);
  2658. pBuf2 = (LPBYTE)malloc( wSize);
  2659. if (pBuf1==NULL || pBuf2==NULL)
  2660. {
  2661. goto Exit;
  2662. }
  2663. if( !RectClipFlag){
  2664. ImageBmp.GetBitmapBits( wSize, (LPVOID)pBuf1);
  2665. CRTDrawBmp.GetBitmapBits( wSize, (LPVOID)pBuf2);
  2666. pPtr1 = pBuf1;
  2667. pPtr2 = pBuf2;
  2668. RotateFigure90(pPtr1,pPtr2,BITMAP_WIDTH, BITMAP_HEIGHT);
  2669. ImageBmp.SetBitmapBits( wSize, (LPVOID)pBuf1);
  2670. CRTDrawBmp.SetBitmapBits( wSize, (LPVOID)pBuf2);
  2671. }else{
  2672. CPoint Mid;
  2673. CRTDrawBmp.GetBitmapBits( wSize, (LPVOID)pBuf1);
  2674. RotateBMP.GetBitmapBits( wSize, (LPVOID)pBuf2);
  2675. pPtr1 = pBuf1;
  2676. pPtr2 = pBuf2;
  2677. RotateFigure90(pPtr1,pPtr2,BITMAP_WIDTH, BITMAP_HEIGHT);
  2678. int Lft = ClipRect[BMP].left;
  2679. int Btm = ClipRect[BMP].bottom;
  2680. int Wid = ClipRect[BMP].Width();
  2681. int Hgt = ClipRect[BMP].Height();
  2682. ClipRect[BMP].left = BITMAP_HEIGHT - Btm;
  2683. ClipRect[BMP].top = Lft;
  2684. ClipRect[BMP].right = ClipRect[BMP].left + Hgt;
  2685. ClipRect[BMP].bottom = ClipRect[BMP].top + Wid;
  2686. Lft = ClipRect[DSP].left;
  2687. Btm = ClipRect[DSP].bottom - CAPTION_HEIGHT - 1;
  2688. Wid = ClipRect[DSP].Width();
  2689. Hgt = ClipRect[DSP].Height();
  2690. Mid.x = Lft
  2691. +((ClipRect[DSP].Width()/2)/ZoomRate)*ZoomRate;
  2692. Mid.y = ClipRect[DSP].top - CAPTION_HEIGHT
  2693. +((ClipRect[DSP].Height()/2)/ZoomRate)*ZoomRate;
  2694. Mid.x -= (((ClipRect[DSP].Height()/2)/ZoomRate)*ZoomRate);
  2695. Mid.y -= (((ClipRect[DSP].Width()/2)/ZoomRate)*ZoomRate);
  2696. if( Mid.x < 0) ClipRect[DSP].left = 0;
  2697. else{
  2698. if( ClipRect[DSP].left + Hgt <=
  2699. EudcWndRect.right){
  2700. ClipRect[DSP].left = Mid.x;
  2701. }else{
  2702. ClipRect[DSP].left =
  2703. Mid.x - ((Mid.x + Hgt - EudcWndRect.right)/ZoomRate)*ZoomRate;
  2704. }
  2705. }
  2706. if( Mid.y < 0) ClipRect[DSP].top = CAPTION_HEIGHT;
  2707. else{
  2708. if( ClipRect[DSP].top + Wid <= EudcWndRect.bottom){
  2709. ClipRect[DSP].top =
  2710. CAPTION_HEIGHT + Mid.y;
  2711. }else{
  2712. ClipRect[DSP].top =
  2713. CAPTION_HEIGHT + Mid.y - (( CAPTION_HEIGHT + Mid.y + Wid - EudcWndRect.bottom)/ZoomRate)*ZoomRate;
  2714. }
  2715. }
  2716. ClipRect[DSP].right = ClipRect[DSP].left + Hgt;
  2717. ClipRect[DSP].bottom = ClipRect[DSP].top + Wid;
  2718. CRTDrawBmp.SetBitmapBits( wSize, (LPVOID)pBuf1);
  2719. RotateBMP.SetBitmapBits( wSize, (LPVOID)pBuf2);
  2720. }
  2721. break;
  2722. case ROTATE_18:
  2723. if( !RectClipFlag){
  2724. ImageDC.StretchBlt( BITMAP_WIDTH -1, BITMAP_HEIGHT-1,
  2725. 0-BITMAP_HEIGHT, 0-BITMAP_WIDTH, &CRTDrawDC,
  2726. 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT, SRCCOPY);
  2727. }else{
  2728. wBrush.CreateStockObject( WHITE_BRUSH);
  2729. CRTDrawDC.FillRect( &ClipRect[BMP], &wBrush);
  2730. wBrush.DeleteObject();
  2731. CRTDrawDC.StretchBlt(
  2732. ClipRect[BMP].right-1, ClipRect[BMP].bottom-1,
  2733. 0 - ClipRect[BMP].Width(),
  2734. 0 - ClipRect[BMP].Height(), &RotateDC,
  2735. ClipRect[BMP].left, ClipRect[BMP].top,
  2736. ClipRect[BMP].Width(),
  2737. ClipRect[BMP].Height(), SRCCOPY);
  2738. }
  2739. break;
  2740. case ROTATE_27:
  2741. wSize = (int)((( BITMAP_WIDTH +15) /16) *2) *(int)BITMAP_HEIGHT;
  2742. pBuf1 = (LPBYTE)malloc( wSize);
  2743. pBuf2 = (LPBYTE)malloc( wSize);
  2744. if (pBuf1==NULL || pBuf2==NULL)
  2745. {
  2746. goto Exit;
  2747. }
  2748. if( !RectClipFlag){
  2749. ImageBmp.GetBitmapBits( wSize, (LPVOID)pBuf1);
  2750. CRTDrawBmp.GetBitmapBits( wSize, (LPVOID)pBuf2);
  2751. pPtr1 = pBuf1;
  2752. pPtr2 = pBuf2;
  2753. RotateFigure270( pPtr1, pPtr2, BITMAP_WIDTH,
  2754. BITMAP_HEIGHT);
  2755. ImageBmp.SetBitmapBits( wSize, (LPVOID)pBuf1);
  2756. CRTDrawBmp.SetBitmapBits( wSize, (LPVOID)pBuf2);
  2757. }else{
  2758. CPoint Mid;
  2759. CRTDrawBmp.GetBitmapBits( wSize, (LPVOID)pBuf1);
  2760. RotateBMP.GetBitmapBits( wSize, (LPVOID)pBuf2);
  2761. pPtr1 = pBuf1;
  2762. pPtr2 = pBuf2;
  2763. RotateFigure270( pPtr1, pPtr2,
  2764. BITMAP_WIDTH, BITMAP_HEIGHT);
  2765. int Rgt = ClipRect[BMP].right;
  2766. int Top = ClipRect[BMP].top;
  2767. int Wid = ClipRect[BMP].Width();
  2768. int Hgt = ClipRect[BMP].Height();
  2769. ClipRect[BMP].left = Top;
  2770. ClipRect[BMP].top = BITMAP_WIDTH - Rgt;
  2771. ClipRect[BMP].right = ClipRect[BMP].left + Hgt;
  2772. ClipRect[BMP].bottom = ClipRect[BMP].top + Wid;
  2773. Rgt = ClipRect[DSP].right - 1;
  2774. Top = ClipRect[DSP].top - CAPTION_HEIGHT;
  2775. Wid = ClipRect[DSP].Width();
  2776. Hgt = ClipRect[DSP].Height();
  2777. Mid.x = ClipRect[DSP].left
  2778. + ((ClipRect[DSP].Width()/2)/ZoomRate)*ZoomRate;
  2779. Mid.y = Top
  2780. + ((ClipRect[DSP].Height()/2)/ZoomRate)*ZoomRate;
  2781. Mid.x -= (((ClipRect[DSP].Height()/2)/ZoomRate)*ZoomRate);
  2782. Mid.y -= (((ClipRect[DSP].Width()/2)/ZoomRate)*ZoomRate);
  2783. if( Mid.x < 0) ClipRect[DSP].left = 0;
  2784. else{
  2785. if( ClipRect[DSP].left + Hgt
  2786. <= EudcWndRect.right){
  2787. ClipRect[DSP].left = Mid.x;
  2788. }else{
  2789. ClipRect[DSP].left =
  2790. Mid.x - ((Mid.x + Hgt - EudcWndRect.right)/ZoomRate)*ZoomRate;
  2791. }
  2792. }
  2793. if( Mid.y < 0)
  2794. ClipRect[DSP].top = CAPTION_HEIGHT;
  2795. else{
  2796. if( ClipRect[DSP].top + Wid <= EudcWndRect.bottom){
  2797. ClipRect[DSP].top =
  2798. CAPTION_HEIGHT + Mid.y;
  2799. }else{
  2800. ClipRect[DSP].top =
  2801. CAPTION_HEIGHT + Mid.y - (( CAPTION_HEIGHT + Mid.y + Wid - EudcWndRect.bottom)/ZoomRate)*ZoomRate;
  2802. }
  2803. }
  2804. ClipRect[DSP].right = ClipRect[DSP].left + Hgt;
  2805. ClipRect[DSP].bottom = ClipRect[DSP].top + Wid;
  2806. CRTDrawBmp.SetBitmapBits( wSize, (LPVOID)pBuf1);
  2807. RotateBMP.SetBitmapBits( wSize, (LPVOID)pBuf2);
  2808. }
  2809. break;
  2810. default:
  2811. break;
  2812. }
  2813. if( RectClipFlag){
  2814. if( RotateBMP.Detach() != NULL)
  2815. RotateBMP.DeleteObject();
  2816. if( RotateDC.Detach() != NULL)
  2817. RotateDC.DeleteDC();
  2818. }
  2819. this->Invalidate(FALSE);
  2820. this->UpdateWindow();
  2821. Exit:
  2822. if (pBuf1 != NULL)
  2823. {
  2824. free(pBuf1);
  2825. }
  2826. if (pBuf2 != NULL)
  2827. {
  2828. free(pBuf2);
  2829. }
  2830. }
  2831. /************************************************/
  2832. /* */
  2833. /* Initialize before flip or rotate */
  2834. /* */
  2835. /************************************************/
  2836. void
  2837. CEditWnd::InitFlipRotate(
  2838. CDC* RotateDC,
  2839. CBitmap *RotateBMP)
  2840. {
  2841. WORD BitSize;
  2842. HANDLE BitInit;
  2843. BYTE *BitmapPtr;
  2844. if( RectClipFlag){
  2845. CClientDC dc( this);
  2846. if( !RotateDC->CreateCompatibleDC( &dc))
  2847. return;
  2848. BitSize = (WORD)((( BITMAP_WIDTH +15) /16) *2)
  2849. * (WORD)BITMAP_HEIGHT;
  2850. if (BitSize == 0)
  2851. {
  2852. return;
  2853. }
  2854. if(( BitInit = LocalAlloc( LMEM_MOVEABLE, BitSize))==0)
  2855. return;
  2856. if(( BitmapPtr = (BYTE *)LocalLock( BitInit)) == NULL){
  2857. LocalFree( BitInit);
  2858. return;
  2859. }
  2860. memset( BitmapPtr, 0xffff, BitSize);
  2861. if( !RotateBMP->CreateBitmap(BITMAP_WIDTH,BITMAP_HEIGHT,
  2862. 1, 1, (LPSTR)BitmapPtr)){
  2863. LocalUnlock( BitInit);
  2864. LocalFree( BitInit);
  2865. return;
  2866. }
  2867. LocalUnlock( BitInit);
  2868. LocalFree( BitInit);
  2869. RotateDC->SelectObject( RotateBMP);
  2870. RotateDC->BitBlt( 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT,
  2871. &CRTDrawDC, 0, 0, SRCCOPY);
  2872. }else{
  2873. CRTDrawDC.BitBlt( 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT,
  2874. &ImageDC, 0, 0, SRCCOPY);
  2875. }
  2876. }
  2877. #define set_p(a,i) ((a)[(i)>>3] & (0x80>>((i)&7)))
  2878. /****************************************/
  2879. /* */
  2880. /* Rotate 90 */
  2881. /* */
  2882. /****************************************/
  2883. void
  2884. CEditWnd::RotateFigure90(
  2885. LPBYTE pBuf1,
  2886. LPBYTE pBuf2,
  2887. int bWid,
  2888. int bHgt)
  2889. {
  2890. int i, j, k, l;
  2891. int wSize, aSize;
  2892. BYTE Pt, *test;
  2893. if ( (!pBuf1) ||(!pBuf2))
  2894. {
  2895. return;
  2896. }
  2897. aSize = (int)(((( bWid + 15) /16) *2) *bHgt);
  2898. wSize = (int)((( bWid + 15) /16) *2);
  2899. test = pBuf2;
  2900. for( i = 0; i < wSize; i++){
  2901. pBuf2 = test + aSize - wSize + i;
  2902. for( j = 0; j < 8; j++){
  2903. for( k = wSize-1; k >= 0; k--){
  2904. memset( &Pt, 0x00, sizeof(BYTE));
  2905. for( l = 0; l < 8; l++){
  2906. if( set_p(pBuf2, j))
  2907. Pt |= (1<<(7-l));
  2908. pBuf2 -= wSize;
  2909. }
  2910. *pBuf1++ = Pt;
  2911. }
  2912. pBuf2 = test + aSize - wSize + i;
  2913. }
  2914. }
  2915. return;
  2916. }
  2917. /****************************************/
  2918. /* */
  2919. /* Rotate 270 */
  2920. /* */
  2921. /****************************************/
  2922. void
  2923. CEditWnd::RotateFigure270(
  2924. LPBYTE pBuf1,
  2925. LPBYTE pBuf2,
  2926. int bWid,
  2927. int bHgt)
  2928. {
  2929. int i, j, k, l;
  2930. int wSize, aSize;
  2931. BYTE Pt, *test;
  2932. aSize = (int)(((( bWid + 15) /16) *2) *bHgt);
  2933. wSize = (int)((( bWid + 15) /16) *2);
  2934. test = pBuf2;
  2935. for( i = 0; i < wSize; i++){
  2936. pBuf2 = test + wSize - 1 - i;
  2937. for( j = 7; j >= 0; j--){
  2938. for( k = wSize-1; k >= 0; k--){
  2939. memset( &Pt, 0x00, sizeof(BYTE));
  2940. for( l = 0; l < 8; l++){
  2941. if( set_p(pBuf2, j))
  2942. Pt |= (1<<(7-l));
  2943. pBuf2 += wSize;
  2944. }
  2945. *pBuf1++ = Pt;
  2946. }
  2947. pBuf2 = test + wSize - 1 - i;
  2948. }
  2949. }
  2950. return;
  2951. }
  2952. /****************************************/
  2953. /* */
  2954. /* Set Duplicate rectangle */
  2955. /* */
  2956. /****************************************/
  2957. void
  2958. CEditWnd::SetDuplicateRect(
  2959. RECT *rect,
  2960. POINT *point)
  2961. {
  2962. LPBYTE pDupBmp;
  2963. int wSize;
  2964. UndoImageDraw();
  2965. BitmapDirty = TRUE;
  2966. WriteSelRectBitmap();
  2967. this->Invalidate( FALSE);
  2968. this->UpdateWindow();
  2969. wSize = ((( BITMAP_WIDTH +15) /16) *2) *BITMAP_HEIGHT;
  2970. pDupBmp = (LPBYTE)malloc( wSize);
  2971. DupBmp.GetBitmapBits( wSize, (LPVOID)pDupBmp);
  2972. CRTDrawBmp.SetBitmapBits( wSize, (LPVOID)pDupBmp);
  2973. free( pDupBmp);
  2974. ClipRect[DSP].CopyRect( rect);
  2975. ClipRect[PRV].CopyRect( rect);
  2976. SetValidRect();
  2977. SetClickRect();
  2978. ClipRect[BMP].SetRect( DupRect.left /ZoomRate,
  2979. ( DupRect.top - CAPTION_HEIGHT) /ZoomRate,
  2980. DupRect.right /ZoomRate,
  2981. ( DupRect.bottom - CAPTION_HEIGHT) /ZoomRate);
  2982. RectClipFlag = TRUE;
  2983. this->InvalidateRect( &ClipRect[VLD], FALSE);
  2984. this->UpdateWindow();
  2985. }
  2986. void CEditWnd::OnClose()
  2987. {
  2988. // Don't allow user to use hot key to close this window
  2989. //CMDIChildWnd::OnClose();
  2990. }