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

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