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.

1296 lines
32 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* MDI Child Window( Reference) */
  5. /* */
  6. /* */
  7. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  8. /**************************************************/
  9. #include "stdafx.h"
  10. #include "eudcedit.h"
  11. #include "refrwnd.h"
  12. #include "editwnd.h"
  13. #include "mainfrm.h"
  14. #define FREELIAIS 1000
  15. LOGFONT ReffLogFont;
  16. CBitmap DupBmp;
  17. CRect DupRect;
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22. extern CEditWnd *pEditChild;
  23. CMenu NEAR CRefrWnd::menu;
  24. IMPLEMENT_DYNCREATE(CRefrWnd, CMDIChildWnd)
  25. BEGIN_MESSAGE_MAP(CRefrWnd, CMDIChildWnd)
  26. //{{AFX_MSG_MAP(CRefrWnd)
  27. ON_BN_CLICKED( IDB_CLOSE_REF, OnClickClose)
  28. ON_WM_PAINT()
  29. ON_WM_CREATE()
  30. ON_WM_SIZE()
  31. ON_WM_LBUTTONDOWN()
  32. ON_WM_LBUTTONUP()
  33. ON_WM_MOUSEMOVE()
  34. ON_COMMAND(ID_GAIJI_COPY, OnGaijiCopy)
  35. ON_UPDATE_COMMAND_UI(ID_GAIJI_COPY, OnUpdateGaijiCopy)
  36. ON_WM_SETCURSOR()
  37. ON_WM_MDIACTIVATE()
  38. ON_WM_KEYDOWN()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /****************************************/
  42. /* */
  43. /* Create reference Window */
  44. /* */
  45. /****************************************/
  46. BOOL
  47. CRefrWnd::Create(
  48. LPCTSTR szTitle,
  49. LONG Style,
  50. RECT ReffWndRect,
  51. CMDIFrameWnd* Parent)
  52. {
  53. // Set Mainframe menu for reference
  54. if( menu.m_hMenu == NULL)
  55. menu.LoadMenu( IDR_MAINFRAME);
  56. m_hMenuShared = menu.m_hMenu;
  57. // Register WindowClass
  58. const TCHAR *pszReffWndClass =
  59. AfxRegisterWndClass( CS_BYTEALIGNCLIENT,
  60. NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL);
  61. return CMDIChildWnd::Create( pszReffWndClass,
  62. szTitle, Style, ReffWndRect, Parent);
  63. }
  64. /****************************************/
  65. /* */
  66. /* Process before window create */
  67. /* */
  68. /****************************************/
  69. int
  70. CRefrWnd::OnCreate(
  71. LPCREATESTRUCT lpCreateStruct)
  72. {
  73. if( CMDIChildWnd::OnCreate( lpCreateStruct) == -1)
  74. return -1;
  75. // Check if m_hWnd is mirrored then we need to set the colse button on the other side.
  76. m_bCloseOnLeft = (BOOL)(GetWindowLongPtr(m_hWnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL);
  77. // Then turn off miroring if any.
  78. if (m_bCloseOnLeft) {
  79. ModifyStyleEx( WS_EX_LAYOUTRTL, 0);
  80. }
  81. if( !CreateNewBitmap())
  82. return -1;
  83. if( !ClipPickValueInit())
  84. return -1;
  85. if( !InitSelectLogfont())
  86. return -1;
  87. if( !LoadCloseBitmap())
  88. return -1;
  89. return 0;
  90. }
  91. /****************************************/
  92. /* */
  93. /* Create New Bitmap */
  94. /* */
  95. /****************************************/
  96. BOOL
  97. CRefrWnd::CreateNewBitmap()
  98. {
  99. WORD wSize;
  100. HANDLE BmpHdl;
  101. BYTE *pBmp;
  102. CClientDC dc( this);
  103. if( !ImageDC.CreateCompatibleDC( &dc))
  104. return FALSE;
  105. wSize = (WORD)((( BITMAP_WIDTH +15) /16) *2) *(WORD)BITMAP_HEIGHT;
  106. if(( BmpHdl = LocalAlloc( LMEM_MOVEABLE, wSize)) == 0)
  107. return FALSE;
  108. if(( pBmp = (BYTE *)LocalLock( BmpHdl)) == NULL){
  109. LocalUnlock( BmpHdl);
  110. LocalFree( BmpHdl);
  111. return FALSE;
  112. }
  113. memset( pBmp, 0xffff, wSize);
  114. if( !ImageBmp.CreateBitmap( BITMAP_WIDTH, BITMAP_HEIGHT,
  115. 1, 1, (LPSTR)pBmp)){
  116. LocalUnlock( BmpHdl);
  117. LocalFree( BmpHdl);
  118. return FALSE;
  119. }
  120. LocalUnlock( BmpHdl);
  121. LocalFree( BmpHdl);
  122. ImageDC.SelectObject( &ImageBmp);
  123. return TRUE;
  124. }
  125. /****************************************/
  126. /* */
  127. /* Initialize clipboard format */
  128. /* */
  129. /****************************************/
  130. BOOL
  131. CRefrWnd::ClipPickValueInit()
  132. {
  133. if( !( ClipboardFormat = RegisterClipboardFormat(TEXT("EudcEdit"))))
  134. return FALSE;
  135. else return TRUE;
  136. }
  137. /****************************************/
  138. /* */
  139. /* Initialize selected logfont */
  140. /* */
  141. /****************************************/
  142. BOOL
  143. CRefrWnd::InitSelectLogfont()
  144. {
  145. CFont cFont;
  146. #ifdef BUILD_ON_WINNT
  147. cFont.CreateStockObject(DEFAULT_GUI_FONT);
  148. #else
  149. cFont.CreateStockObject( SYSTEM_FONT);
  150. #endif
  151. cFont.GetObject( sizeof(LOGFONT), &ReffLogFont);
  152. cFont.DeleteObject();
  153. return TRUE;
  154. }
  155. /****************************************/
  156. /* */
  157. /* Load Close Bitmap (to close) */
  158. /* */
  159. /****************************************/
  160. BOOL
  161. CRefrWnd::LoadCloseBitmap()
  162. {
  163. CRect rect;
  164. this->GetClientRect( &rect);
  165. rect.top = 2;
  166. rect.bottom = CAPTION_HEIGHT - 2;
  167. rect.right -= 2;
  168. rect.left = rect.right - ( rect.bottom - rect.top) - 5;
  169. if( !CloseBtm.Create( NULL, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW |
  170. WS_EX_TOPMOST | BS_PUSHBUTTON, rect, this, IDB_CLOSE_REF) ||
  171. !CloseBtm.LoadBitmaps( IDB_CLOSEBMP, IDB_CLOSEBMPP))
  172. return FALSE;
  173. else{
  174. CloseBtm.SizeToContent();
  175. return TRUE;
  176. }
  177. }
  178. /****************************************/
  179. /* */
  180. /* Default Constructor */
  181. /* */
  182. /****************************************/
  183. CRefrWnd::CRefrWnd()
  184. {
  185. RectVisible = FALSE;
  186. IsCapture = FALSE;
  187. SelectItems = RECTCLIP;
  188. GridShow = TRUE;
  189. bFocus = FALSE;
  190. m_bCloseOnLeft = FALSE;
  191. }
  192. /****************************************/
  193. /* */
  194. /* Destructor */
  195. /* */
  196. /****************************************/
  197. CRefrWnd::~CRefrWnd()
  198. {
  199. if( ImageBmp.Detach() != NULL)
  200. ImageBmp.DeleteObject();
  201. if( ImageDC.Detach() != NULL)
  202. ImageDC.DeleteDC();
  203. menu.DestroyMenu();
  204. }
  205. /****************************************/
  206. /* */
  207. /* MESSAGE "WM_PAINT" */
  208. /* */
  209. /****************************************/
  210. void
  211. CRefrWnd::OnPaint()
  212. {
  213. CString WndCaption;
  214. CFont RefferFont;
  215. BYTE sWork[10];
  216. CSize CharSize;
  217. short xOffset, yOffset;
  218. int Length;
  219. CPaintDC dc( this);
  220. this->GetClientRect( &ReffWndRect);
  221. ZoomRate = ReffWndRect.right /BITMAP_WIDTH;
  222. ReffLogFont.lfHeight = BITMAP_HEIGHT;
  223. ReffLogFont.lfWidth = 0;
  224. ReffLogFont.lfQuality = PROOF_QUALITY;
  225. if( !RefferFont.CreateFontIndirect( &ReffLogFont))
  226. return;
  227. CFont *OldFont = ImageDC.SelectObject( &RefferFont);
  228. if( !ReferCode)
  229. Length = 0;
  230. /*
  231. else if( !(ReferCode & 0xff00)){
  232. // SBCS
  233. sWork[0] = (BYTE)( ReferCode & 0x00ff);
  234. sWork[1] = (BYTE)'\0';
  235. Length = 1;
  236. }else{
  237. // DBCS
  238. sWork[0] = (BYTE)(( ReferCode & 0xff00) >> 8);
  239. sWork[1] = (BYTE)( ReferCode & 0x00ff);
  240. sWork[2] = (BYTE)'\0';
  241. Length = 2;
  242. }
  243. */
  244. else
  245. {
  246. sWork[0] = LOBYTE(ReferCode);
  247. sWork[1] = HIBYTE(ReferCode);
  248. Length = 1;
  249. }
  250. if( Length){
  251. CRect TextImage;
  252. GetTextExtentPoint32W( ImageDC.GetSafeHdc(), (const unsigned short *)sWork,
  253. Length, &CharSize);
  254. /*
  255. GetTextExtentPoint32A( ImageDC.GetSafeHdc(), (LPCSTR)sWork,
  256. Length, &CharSize);*/
  257. TextImage.SetRect( 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT);
  258. if( CharSize.cx < BITMAP_WIDTH)
  259. xOffset = (short)(( BITMAP_HEIGHT - CharSize.cx) /2);
  260. else xOffset = 0;
  261. if( CharSize.cy < BITMAP_HEIGHT)
  262. yOffset = (short)(( BITMAP_WIDTH - CharSize.cy) /2);
  263. else yOffset = 0;
  264. /*
  265. if( ReffLogFont.lfFaceName[0] == '@' && Length == 2)
  266. xOffset = yOffset = 0;
  267. */
  268. if( ReffLogFont.lfFaceName[0] == '@' && Length == 1)
  269. xOffset = yOffset = 0;
  270. /*
  271. ExtTextOutA(ImageDC.GetSafeHdc(), xOffset, yOffset, ETO_OPAQUE,
  272. &TextImage, (LPCSTR)sWork, Length, NULL);
  273. */
  274. ExtTextOutW(ImageDC.GetSafeHdc(), xOffset, yOffset, ETO_OPAQUE,
  275. &TextImage, (const unsigned short *)sWork, Length, NULL);
  276. }
  277. dc.StretchBlt( 0, CAPTION_HEIGHT, ReffWndRect.Width(),
  278. ReffWndRect.Height() - CAPTION_HEIGHT,
  279. &ImageDC, 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT,SRCCOPY);
  280. CRect rect;
  281. rect.CopyRect( &ReffWndRect);
  282. rect.top = 2;
  283. rect.bottom = CAPTION_HEIGHT - 2;
  284. if (m_bCloseOnLeft) {
  285. rect.left += 2;
  286. rect.right = rect.left + ( rect.bottom - rect.top) - 2;
  287. } else {
  288. rect.right -= 2;
  289. rect.left = rect.right - ( rect.bottom - rect.top) - 2;
  290. }
  291. CloseBtm.SetWindowPos( NULL, rect.left, rect.top,
  292. 0, 0, SWP_NOSIZE );
  293. CaptionDraw();
  294. if( RectVisible)
  295. RubberBandPaint( &dc);
  296. if( GridShow && ZoomRate >= 2)
  297. DrawGridLine( &dc);
  298. ImageDC.SelectObject( OldFont);
  299. RefferFont.DeleteObject();
  300. return;
  301. }
  302. /****************************************/
  303. /* */
  304. /* Draw Caption */
  305. /* */
  306. /****************************************/
  307. void
  308. CRefrWnd::CaptionDraw()
  309. {
  310. COLORREF TextColor;
  311. CString WndCaption;
  312. CRect CaptionRect;
  313. CBrush CaptionBrush;
  314. CFont *OldFont;
  315. int BkMode;
  316. CDC dc;
  317. dc.Attach( ::GetDC( this->GetSafeHwnd()));
  318. // Get brush with active caption color
  319. CaptionRect.CopyRect( &ReffWndRect);
  320. if (bFocus)
  321. {
  322. CaptionBrush.CreateSolidBrush(::GetSysColor( COLOR_ACTIVECAPTION));
  323. }
  324. else
  325. {
  326. CaptionBrush.CreateSolidBrush(::GetSysColor(COLOR_INACTIVECAPTION));
  327. }
  328. CaptionRect.bottom = CAPTION_HEIGHT;
  329. dc.FillRect( &CaptionRect, &CaptionBrush);
  330. CaptionBrush.DeleteObject();
  331. // Get font to draw caption
  332. #ifdef BUILD_ON_WINNT
  333. OldFont = (CFont *)dc.SelectStockObject(DEFAULT_GUI_FONT);
  334. #else
  335. OldFont = (CFont *)dc.SelectStockObject(SYSTEM_FONT);
  336. #endif
  337. BkMode = dc.SetBkMode( TRANSPARENT);
  338. if (bFocus)
  339. {
  340. TextColor = dc.SetTextColor( ::GetSysColor(COLOR_CAPTIONTEXT));
  341. }
  342. else
  343. {
  344. TextColor = dc.SetTextColor( ::GetSysColor(COLOR_INACTIVECAPTIONTEXT));
  345. }
  346. WndCaption.LoadString( IDS_REFERENCE_STR);
  347. dc.TextOut( ReffWndRect.right /2 - 30, 1, WndCaption);
  348. dc.SelectObject( OldFont);
  349. dc.SetTextColor( TextColor);
  350. dc.SetBkMode( BkMode);
  351. //
  352. // redraw the close button.
  353. //
  354. CloseBtm.Invalidate(FALSE);
  355. ::ReleaseDC( NULL, dc.Detach());
  356. return;
  357. }
  358. /****************************************/
  359. /* */
  360. /* Draw Grid */
  361. /* */
  362. /****************************************/
  363. void
  364. CRefrWnd::DrawGridLine(
  365. CDC *dc)
  366. {
  367. CPen GlyphPen;
  368. register int i;
  369. // Create pen to draw grid
  370. GlyphPen.CreatePen( PS_SOLID, 1, COLOR_GRID);
  371. CPen *OldPen = dc->SelectObject( &GlyphPen);
  372. // Draw grid
  373. for( i = ZoomRate - 1; i < ReffWndRect.right; i += ZoomRate){
  374. dc->MoveTo( i, CAPTION_HEIGHT-1);
  375. dc->LineTo( i, ReffWndRect.bottom);
  376. }
  377. for( i =ZoomRate +CAPTION_HEIGHT -1;i<ReffWndRect.bottom;i += ZoomRate){
  378. dc->MoveTo( 0, i);
  379. dc->LineTo( ReffWndRect.right, i);
  380. }
  381. dc->SelectObject( OldPen);
  382. GlyphPen.DeleteObject();
  383. }
  384. /****************************************/
  385. /* */
  386. /* Draw RubberBand */
  387. /* */
  388. /****************************************/
  389. void
  390. CRefrWnd::RubberBandPaint(
  391. CDC *dc)
  392. {
  393. CPen *OldPen;
  394. CBrush *OldBrush;
  395. int OldMode;
  396. OldPen = (CPen *)dc->SelectStockObject( BLACK_PEN);
  397. OldBrush = (CBrush *)dc->SelectStockObject( NULL_BRUSH);
  398. OldMode = dc->SetROP2( R2_NOTXORPEN);
  399. dc->Rectangle( &MoveRect);
  400. dc->SelectObject( OldPen);
  401. dc->SelectObject( OldBrush);
  402. dc->SetROP2( OldMode);
  403. }
  404. /****************************************/
  405. /* */
  406. /* MESSAGE "WM_LBUTTONDOWN" */
  407. /* */
  408. /****************************************/
  409. void
  410. CRefrWnd::OnLButtonDown(
  411. UINT ,
  412. CPoint point)
  413. {
  414. CRect CaptionRect;
  415. CaptionRect.CopyRect( &ReffWndRect);
  416. CaptionRect.top = CAPTION_HEIGHT;
  417. if( !CaptionRect.PtInRect( point))
  418. return;
  419. IsCapture = TRUE;
  420. this->SetCapture();
  421. CorrectMouseDownPt( point);
  422. if( RectVisible){
  423. if( MoveRect.PtInRect( point)){
  424. RectVisible = FALSE;
  425. this->InvalidateRect( &MoveRect, FALSE);
  426. this->UpdateWindow();
  427. RectVisible = TRUE;
  428. m_ptMouse.x = point.x - MoveRect.left;
  429. m_ptMouse.y = point.y - MoveRect.top;
  430. this->ClientToScreen( &point);
  431. MoveRectangle( point);
  432. m_ptLast = point;
  433. return;
  434. }else{
  435. RectVisible = FALSE;
  436. this->InvalidateRect( &MoveRect, FALSE);
  437. this->UpdateWindow();
  438. }
  439. }
  440. if( SelectItems == RECTCLIP)
  441. RubberBand( TRUE);
  442. else{
  443. CPoint Sp;
  444. Sp.x = ptStart.x;
  445. Sp.y = ptStart.y + CAPTION_HEIGHT;
  446. m_pointArray.RemoveAll();
  447. m_selectArray.RemoveAll();
  448. m_pointArray.Add( Sp);
  449. Sp.x = ptStart.x /ZoomRate;
  450. Sp.y = ptStart.y /ZoomRate;
  451. m_selectArray.Add( Sp);
  452. }
  453. }
  454. /****************************************/
  455. /* */
  456. /* MESSAGE "WM_MOUSEMOVE" */
  457. /* */
  458. /****************************************/
  459. void
  460. CRefrWnd::OnMouseMove(
  461. UINT ,
  462. CPoint point)
  463. {
  464. if( IsCapture){
  465. CorrectMouseUpPt( point);
  466. if( ptEnd.x == ptPrev.x && ptEnd.y == ptPrev.y)
  467. return;
  468. if( RectVisible){
  469. this->ClientToScreen( &point);
  470. MoveRectangle( m_ptLast);
  471. m_ptLast = point;
  472. MoveRectangle( m_ptLast);
  473. }else{
  474. if( SelectItems == RECTCLIP)
  475. RubberBand( FALSE);
  476. else{
  477. DrawFreeForm( FALSE);
  478. SelectFreeForm( FALSE);
  479. }
  480. }
  481. }
  482. }
  483. /****************************************/
  484. /* */
  485. /* MESSAGE "WM_LBUTTONUP" */
  486. /* */
  487. /****************************************/
  488. void
  489. CRefrWnd::OnLButtonUp(
  490. UINT ,
  491. CPoint point)
  492. {
  493. CRect WorkRect;
  494. int wSize;
  495. char *pDupBmp;
  496. if (!bFocus)
  497. {
  498. bFocus = TRUE;
  499. CaptionDraw();
  500. pEditChild->bFocus = FALSE;
  501. pEditChild->CaptionDraw();
  502. }
  503. if( IsCapture){
  504. CorrectMouseUpPt( point);
  505. if( RectVisible){
  506. MoveRectangle( m_ptLast);
  507. WorkRect.CopyRect( &MoveRect);
  508. WorkRect.left = ptStart.x - MoveRect.left;
  509. WorkRect.top = ptStart.y - MoveRect.top+CAPTION_HEIGHT;
  510. WorkRect.right = MoveRect.Width();
  511. WorkRect.bottom = MoveRect.Height();
  512. this->ClientToScreen( &point);
  513. DupBmp.CreateBitmap( BITMAP_WIDTH, BITMAP_HEIGHT,
  514. 1, 1, NULL);
  515. wSize = ((( BITMAP_WIDTH +15) /16) *2) *BITMAP_HEIGHT;
  516. pDupBmp = (char *)malloc( wSize);
  517. if( SelectItems == FREEFORM){
  518. CBitmap hStdBitmap;
  519. CDC hStdDC;
  520. CBrush BlackBrush;
  521. hStdDC.CreateCompatibleDC( &ImageDC);
  522. hStdBitmap.CreateCompatibleBitmap( &ImageDC,
  523. BITMAP_WIDTH, BITMAP_HEIGHT);
  524. CBitmap *hOldSObj =
  525. hStdDC.SelectObject( &hStdBitmap);
  526. hStdDC.PatBlt( 0, 0, BITMAP_WIDTH,
  527. BITMAP_HEIGHT, WHITENESS);
  528. BlackBrush.CreateStockObject( BLACK_BRUSH);
  529. hStdDC.FillRgn( &PickRgn, &BlackBrush);
  530. BlackBrush.DeleteObject();
  531. hStdDC.BitBlt( 0, 0, BITMAP_WIDTH,
  532. BITMAP_HEIGHT, &ImageDC,0, 0, SRCPAINT);
  533. hStdBitmap.GetBitmapBits( wSize,
  534. (LPVOID)pDupBmp);
  535. hStdDC.SelectObject( &hOldSObj);
  536. hStdBitmap.DeleteObject();
  537. hStdDC.DeleteDC();
  538. }else{
  539. ImageBmp.GetBitmapBits( wSize, (LPVOID)pDupBmp);
  540. }
  541. DupBmp.SetBitmapBits( wSize, (LPVOID)pDupBmp);
  542. free( pDupBmp);
  543. DupRect.CopyRect( &MoveRect);
  544. AfxGetMainWnd()->SendMessage( WM_DUPLICATE,
  545. (WPARAM)&WorkRect,(LPARAM)&point);
  546. DupBmp.DeleteObject();
  547. }else if( SelectItems == RECTCLIP){
  548. IllegalRect( &ptStart, &ptEnd);
  549. MoveRect.SetRect( ptStart.x, ptStart.y + CAPTION_HEIGHT,
  550. ptEnd.x + ZoomRate + 1,
  551. ptEnd.y + ZoomRate + CAPTION_HEIGHT + 1);
  552. if( abs( ptEnd.x - ptStart.x) < ZoomRate*2 ||
  553. abs( ptEnd.y - ptStart.y) < ZoomRate*2){
  554. this->InvalidateRect( &MoveRect, FALSE);
  555. this->UpdateWindow();
  556. }else{
  557. RectVisible = TRUE;
  558. this->InvalidateRect( &MoveRect, FALSE);
  559. this->UpdateWindow();
  560. }
  561. PickRect.SetRect(ptStart.x/ZoomRate, ptStart.y/ZoomRate,
  562. ( ptEnd.x+ZoomRate)/ZoomRate,
  563. ( ptEnd.y+ZoomRate)/ZoomRate);
  564. }else{
  565. CPoint nArray[FREELIAIS];
  566. CPoint pArray[FREELIAIS];
  567. DrawFreeForm( FALSE);
  568. SelectFreeForm( FALSE);
  569. DrawFreeForm( TRUE);
  570. SelectFreeForm( TRUE);
  571. if( m_pointArray.GetSize() >= FREELIAIS ||
  572. m_selectArray.GetSize() >= FREELIAIS ){
  573. IsCapture = FALSE;
  574. ReleaseCapture();
  575. this->Invalidate( FALSE);
  576. this->UpdateWindow();
  577. return;
  578. }
  579. for( int i = 0; i < m_pointArray.GetSize(); i++)
  580. nArray[i] = m_pointArray[i];
  581. for( int k = 0; k < m_selectArray.GetSize(); k++)
  582. pArray[k] = m_selectArray[k];
  583. if( FreeRgn.GetSafeHandle() != NULL)
  584. FreeRgn.DeleteObject();
  585. if( PickRgn.GetSafeHandle() != NULL)
  586. PickRgn.DeleteObject();
  587. FreeRgn.CreatePolygonRgn( nArray,
  588. (int)(m_pointArray.GetSize()), ALTERNATE);
  589. PickRgn.CreatePolygonRgn( pArray,
  590. (int)(m_selectArray.GetSize()), ALTERNATE);
  591. if( FreeRgn.GetSafeHandle() == NULL ||
  592. PickRgn.GetSafeHandle() == NULL ){
  593. m_pointArray.RemoveAll();
  594. m_selectArray.RemoveAll();
  595. }else{
  596. RectVisible = TRUE;
  597. FreeRgn.GetRgnBox( &MoveRect);
  598. PickRgn.GetRgnBox( &PickRect);
  599. if( PickRect.Width() < 3 ||
  600. PickRect.Height() < 3){
  601. RectVisible = FALSE;
  602. FreeRgn.DeleteObject();
  603. PickRgn.DeleteObject();
  604. }
  605. MoveRect.right += 1;
  606. MoveRect.bottom += 1;
  607. this->InvalidateRect( &MoveRect);
  608. this->UpdateWindow();
  609. }
  610. }
  611. IsCapture = FALSE;
  612. }
  613. ReleaseCapture();
  614. }
  615. /****************************************/
  616. /* */
  617. /* Correct Mouse Down Point */
  618. /* */
  619. /****************************************/
  620. void
  621. CRefrWnd::CorrectMouseDownPt(
  622. CPoint point)
  623. {
  624. CRect WorkRect;
  625. WorkRect.CopyRect( &ReffWndRect);
  626. ptStart.x = point.x;
  627. ptStart.y = point.y - CAPTION_HEIGHT;
  628. if( ptStart.y < 0)
  629. ptStart.y = 0;
  630. if( SelectItems == RECTCLIP){
  631. ptStart.x = ( ptStart.x /ZoomRate) *ZoomRate;
  632. ptStart.y = ( ptStart.y /ZoomRate) *ZoomRate;
  633. }else{
  634. ptStart.x = (( ptStart.x + ZoomRate/2) /ZoomRate) *ZoomRate;
  635. ptStart.y = (( ptStart.y + ZoomRate/2) /ZoomRate) *ZoomRate;
  636. }
  637. ptEnd = ptPrev = ptStart;
  638. }
  639. /****************************************/
  640. /* */
  641. /* Correct Mouse Up point */
  642. /* */
  643. /****************************************/
  644. void
  645. CRefrWnd::CorrectMouseUpPt(
  646. CPoint point)
  647. {
  648. ptPrev = ptEnd;
  649. ptEnd.x = point.x;
  650. ptEnd.y = point.y - CAPTION_HEIGHT;
  651. CRect WorkRect;
  652. WorkRect.CopyRect( &ReffWndRect);
  653. if( ptEnd.x < 0) ptEnd.x = 0;
  654. if( ptEnd.y < 0) ptEnd.y = 0;
  655. if( ptEnd.x > WorkRect.right){
  656. if( SelectItems == RECTCLIP)
  657. ptEnd.x = WorkRect.right - ZoomRate;
  658. else ptEnd.x = WorkRect.right;
  659. }
  660. if( ptEnd.y > WorkRect.bottom - CAPTION_HEIGHT){
  661. if( SelectItems == RECTCLIP){
  662. ptEnd.y = WorkRect.bottom - CAPTION_HEIGHT
  663. - ZoomRate;
  664. }else ptEnd.y = WorkRect.bottom - CAPTION_HEIGHT;
  665. }
  666. if( SelectItems == RECTCLIP){
  667. ptEnd.x = ( ptEnd.x /ZoomRate) *ZoomRate;
  668. ptEnd.y = ( ptEnd.y /ZoomRate) *ZoomRate;
  669. }else{
  670. ptEnd.x = (( ptEnd.x + ZoomRate/2) /ZoomRate) *ZoomRate;
  671. ptEnd.y = (( ptEnd.y + ZoomRate/2) /ZoomRate) *ZoomRate;
  672. }
  673. if( SelectItems == RECTCLIP){
  674. if( ptEnd.x - ptStart.x <= ZoomRate &&
  675. ptEnd.x - ptStart.x >= 0)
  676. ptEnd.x = ptStart.x + ZoomRate;
  677. if( ptStart.x - ptEnd.x <= ZoomRate &&
  678. ptStart.x - ptEnd.x > 0)
  679. ptEnd.x = ptStart.x - ZoomRate;
  680. if( ptStart.y - ptEnd.y <= ZoomRate &&
  681. ptStart.y - ptEnd.y > 0)
  682. ptEnd.y = ptStart.y - ZoomRate;
  683. if( ptEnd.y - ptStart.y <= ZoomRate &&
  684. ptEnd.y - ptStart.y >= 0)
  685. ptEnd.y = ptStart.y + ZoomRate;
  686. }
  687. }
  688. /****************************************/
  689. /* */
  690. /* Correct Illegal rectangle */
  691. /* */
  692. /****************************************/
  693. void
  694. CRefrWnd::IllegalRect(
  695. PPOINT ptTL,
  696. PPOINT ptBR)
  697. {
  698. int Tmp;
  699. if( ptTL->x > ptBR->x){
  700. Tmp = ptTL->x;
  701. ptTL->x = ptBR->x;
  702. ptBR->x = Tmp;
  703. }
  704. if( ptTL->y > ptBR->y){
  705. Tmp = ptTL->y;
  706. ptTL->y = ptBR->y;
  707. ptBR->y = Tmp;
  708. }
  709. }
  710. /****************************************/
  711. /* */
  712. /* COMMAND "COPY" */
  713. /* */
  714. /****************************************/
  715. void
  716. CRefrWnd::OnGaijiCopy()
  717. {
  718. ClipImageCopy();
  719. CMainFrame *pMain = new CMainFrame;
  720. pMain->CustomActivate();
  721. delete pMain;
  722. }
  723. /************************************************/
  724. /* */
  725. /* COMMAND "COPY" (Update) */
  726. /* */
  727. /************************************************/
  728. void
  729. CRefrWnd::OnUpdateGaijiCopy(
  730. CCmdUI *pCmdUI)
  731. {
  732. if( RectVisible)
  733. pCmdUI->Enable(TRUE);
  734. else pCmdUI->Enable(FALSE);
  735. }
  736. /****************************************/
  737. /* */
  738. /* Copy Bitmap data */
  739. /* */
  740. /****************************************/
  741. BOOL
  742. CRefrWnd::ClipImageCopy()
  743. {
  744. CBitmap hStdBitmap;
  745. CDC hStdDC;
  746. hStdDC.CreateCompatibleDC( &ImageDC);
  747. hStdBitmap.CreateCompatibleBitmap( &ImageDC,
  748. PickRect.Width(), PickRect.Height());
  749. CBitmap *hOldSObj = hStdDC.SelectObject( &hStdBitmap);
  750. hStdDC.PatBlt( 0, 0, PickRect.Width(), PickRect.Height(), WHITENESS);
  751. if( SelectItems == FREEFORM){
  752. CBrush BlackBrush;
  753. BlackBrush.CreateStockObject( BLACK_BRUSH);
  754. PickRgn.OffsetRgn( 0 - PickRect.left, 0 - PickRect.top);
  755. hStdDC.FillRgn( &PickRgn, &BlackBrush);
  756. BlackBrush.DeleteObject();
  757. hStdDC.BitBlt( 0, 0, PickRect.Width(), PickRect.Height(),
  758. &ImageDC, PickRect.left, PickRect.top, SRCPAINT);
  759. }else{
  760. hStdDC.BitBlt( 0, 0, PickRect.Width(), PickRect.Height(),
  761. &ImageDC, PickRect.left, PickRect.top, SRCCOPY);
  762. }
  763. if (!this->OpenClipboard()) {
  764. hStdDC.SelectObject( hOldSObj);
  765. hStdBitmap.DeleteObject();
  766. hStdDC.DeleteDC();
  767. return FALSE;
  768. }
  769. EmptyClipboard();
  770. if( !SetClipboardData( CF_BITMAP, hStdBitmap.Detach())) {
  771. hStdDC.SelectObject( hOldSObj);
  772. hStdBitmap.DeleteObject();
  773. hStdDC.DeleteDC();
  774. CloseClipboard();
  775. return FALSE;
  776. }
  777. CloseClipboard();
  778. hStdDC.SelectObject( hOldSObj);
  779. hStdBitmap.DeleteObject();
  780. hStdDC.DeleteDC();
  781. RectVisible = FALSE;
  782. this->InvalidateRect( &MoveRect, FALSE);
  783. this->UpdateWindow();
  784. return TRUE;
  785. }
  786. /****************************************/
  787. /* */
  788. /* Draw Rubber Band rectanble */
  789. /* */
  790. /****************************************/
  791. void
  792. CRefrWnd::RubberBand(
  793. BOOL TestFlag)
  794. {
  795. CPen *OldPen;
  796. CBrush *OldBrush;
  797. CPoint ptTL;
  798. CPoint ptBR;
  799. CClientDC dc( this);
  800. OldPen = (CPen *)dc.SelectStockObject( BLACK_PEN);
  801. OldBrush = (CBrush *)dc.SelectStockObject( NULL_BRUSH);
  802. int OldMode = dc.SetROP2( R2_NOTXORPEN);
  803. CRect BRect;
  804. if( !TestFlag){
  805. ptTL.x = ptStart.x;
  806. ptTL.y = ptStart.y + CAPTION_HEIGHT;
  807. ptBR.x = ptPrev.x;
  808. ptBR.y = ptPrev.y + CAPTION_HEIGHT;
  809. IllegalRect( &ptTL, &ptBR);
  810. BRect.SetRect( ptTL.x, ptTL.y,
  811. ptBR.x + ZoomRate +1, ptBR.y + ZoomRate +1);
  812. dc.Rectangle( &BRect);
  813. }
  814. ptTL.x = ptStart.x;
  815. ptTL.y = ptStart.y + CAPTION_HEIGHT;
  816. ptBR.x = ptEnd.x;
  817. ptBR.y = ptEnd.y + CAPTION_HEIGHT;
  818. IllegalRect( &ptTL, &ptBR);
  819. ptPrev = ptBR;
  820. BRect.SetRect( ptTL.x, ptTL.y, ptBR.x + ZoomRate +1,ptBR.y+ZoomRate+1);
  821. dc.Rectangle( &BRect);
  822. dc.SelectObject( OldPen);
  823. dc.SelectObject( OldBrush);
  824. dc.SetROP2( OldMode);
  825. }
  826. /****************************************/
  827. /* */
  828. /* Initialize bitmap data */
  829. /* */
  830. /****************************************/
  831. BOOL
  832. CRefrWnd::UpdateBitmap()
  833. {
  834. WORD wSize;
  835. HANDLE BitHandle;
  836. BYTE *pBitmap;
  837. wSize = (WORD)((( BITMAP_WIDTH + 15) /16) *2) *(WORD)BITMAP_HEIGHT;
  838. if(( BitHandle = LocalAlloc( LMEM_MOVEABLE, wSize)) == 0)
  839. return FALSE;
  840. if(( pBitmap = (BYTE *)LocalLock( BitHandle)) == NULL){
  841. LocalUnlock( BitHandle);
  842. LocalFree( BitHandle);
  843. return FALSE;
  844. }
  845. memset( pBitmap, 0xffff, wSize);
  846. ImageBmp.SetBitmapBits((DWORD)wSize, (const void far *)pBitmap);
  847. LocalUnlock( BitHandle);
  848. LocalFree( BitHandle);
  849. RectVisible = FALSE;
  850. this->Invalidate(FALSE);
  851. this->UpdateWindow();
  852. return TRUE;
  853. }
  854. /****************************************/
  855. /* */
  856. /* MESSAGE "WM_SETCURSOR" */
  857. /* */
  858. /****************************************/
  859. BOOL
  860. CRefrWnd::OnSetCursor(
  861. CWnd* pWnd,
  862. UINT nHitTest,
  863. UINT message)
  864. {
  865. CPoint point;
  866. CRect CaptionRect;
  867. HCURSOR hArrowCur;
  868. GetCursorPos( &point);
  869. this->GetClientRect( &CaptionRect);
  870. this->ScreenToClient( &point);
  871. CaptionRect.top = CAPTION_HEIGHT;
  872. if( CaptionRect.PtInRect( point))
  873. if( MoveRect.PtInRect( point) && RectVisible)
  874. ::SetCursor((HCURSOR)ArrowCursor[ALLDIRECT]);
  875. else ::SetCursor((HCURSOR)ToolCursor[SelectItems]);
  876. else{
  877. hArrowCur = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
  878. ::SetCursor( hArrowCur);
  879. }
  880. return TRUE;
  881. }
  882. /****************************************/
  883. /* */
  884. /* MESSAGE "WM_MDIACTIVATE" */
  885. /* */
  886. /****************************************/
  887. void
  888. CRefrWnd::OnMDIActivate(
  889. BOOL bActivate,
  890. CWnd* pActivateWnd,
  891. CWnd* pDeactivateWnd)
  892. {
  893. if( bActivate == FALSE){
  894. RectVisible = FALSE;
  895. this->InvalidateRect( &MoveRect, FALSE);
  896. this->UpdateWindow();
  897. }
  898. }
  899. /****************************************/
  900. /* */
  901. /* MESSAGE "WM_SIZE" */
  902. /* */
  903. /****************************************/
  904. void
  905. CRefrWnd::OnSize(
  906. UINT nType,
  907. int cx,
  908. int cy)
  909. {
  910. int NewZoomRate;
  911. NewZoomRate = cx / BITMAP_WIDTH;
  912. if( RectVisible && NewZoomRate > 1){
  913. MoveRect.left = ( MoveRect.left /ZoomRate) * NewZoomRate;
  914. MoveRect.top = ((( MoveRect.top - CAPTION_HEIGHT)
  915. / ZoomRate) * NewZoomRate) + CAPTION_HEIGHT;
  916. MoveRect.right = ( MoveRect.right /ZoomRate) * NewZoomRate + 1;
  917. MoveRect.bottom = ((( MoveRect.bottom -CAPTION_HEIGHT)
  918. / ZoomRate) * NewZoomRate) + CAPTION_HEIGHT + 1;
  919. }else if( RectVisible && NewZoomRate <= 1){
  920. RectVisible = FALSE;
  921. }
  922. CMDIChildWnd::OnSize(nType, cx, cy);
  923. this->Invalidate(FALSE);
  924. this->UpdateWindow();
  925. }
  926. /****************************************/
  927. /* */
  928. /* Select FreeForm */
  929. /* */
  930. /****************************************/
  931. void
  932. CRefrWnd::SelectFreeForm(
  933. BOOL MouseSts)
  934. {
  935. CPoint Ep, Sp, Cp;
  936. CPoint Fp, Inc;
  937. CPoint Dp, Err;
  938. BOOL Slope;
  939. int D;
  940. int Tmp;
  941. if( !MouseSts){
  942. Sp.x = ptPrev.x /ZoomRate;
  943. Sp.y = ptPrev.y /ZoomRate;
  944. Ep.x = Fp.x = ptEnd.x /ZoomRate;
  945. Ep.y = Fp.y = ptEnd.y /ZoomRate;
  946. }else{
  947. Sp.x = ptEnd.x /ZoomRate;
  948. Sp.y = ptEnd.y /ZoomRate;
  949. Ep.x = Fp.x = ptStart.x /ZoomRate;
  950. Ep.y = Fp.y = ptStart.y /ZoomRate;
  951. }
  952. if( Fp.x >= Sp.x)
  953. Inc.x = 1;
  954. else Inc.x = -1;
  955. if( Fp.y >= Sp.y)
  956. Inc.y = 1;
  957. else Inc.y = -1;
  958. Dp.x = ( Fp.x - Sp.x)*Inc.x;
  959. Dp.y = ( Fp.y - Sp.y)*Inc.y;
  960. if( !Dp.x && !Dp.y)
  961. return;
  962. if( Dp.x < Dp.y){
  963. Tmp = Dp.y;
  964. Dp.y = Dp.x;
  965. Dp.x = Tmp;
  966. Tmp = Inc.x;
  967. Inc.x = Inc.y;
  968. Inc.y = Tmp;
  969. Slope = TRUE;
  970. }else Slope = FALSE;
  971. Err.x = Dp.y * 2;
  972. Err.y = ( Dp.y - Dp.x) * 2;
  973. D = Err.x - Dp.x;
  974. Ep = Sp;
  975. while(1){
  976. m_selectArray.Add( Ep);
  977. if( Ep.x == Fp.x && Ep.y == Fp.y)
  978. break;
  979. if( Slope){
  980. Tmp = Ep.x;
  981. Ep.x = Ep.y;
  982. Ep.y = Tmp;
  983. }
  984. Ep.x += Inc.x;
  985. if( D < 0)
  986. D += Err.x;
  987. else{
  988. Ep.y += Inc.y;
  989. D += Err.y;
  990. }
  991. if( Slope){
  992. Tmp = Ep.x;
  993. Ep.x = Ep.y;
  994. Ep.y = Tmp;
  995. }
  996. }
  997. }
  998. /****************************************/
  999. /* */
  1000. /* Draw FreeForm */
  1001. /* */
  1002. /****************************************/
  1003. void
  1004. CRefrWnd::DrawFreeForm(
  1005. BOOL MouseSts)
  1006. {
  1007. CPoint Ep, Sp, Cp;
  1008. CPoint Fp, Inc;
  1009. CPoint Dp, Err;
  1010. CPoint P1, P2;
  1011. BOOL Slope;
  1012. int D;
  1013. int Tmp;
  1014. CClientDC dc( this);
  1015. CPen *OldPen = (CPen *)dc.SelectStockObject( BLACK_PEN);
  1016. int OldMode = dc.SetROP2( R2_NOTXORPEN);
  1017. if( !MouseSts){
  1018. Sp.x = ptPrev.x;
  1019. Sp.y = ptPrev.y + CAPTION_HEIGHT;
  1020. Ep.x = Fp.x = ptEnd.x;
  1021. Ep.y = Fp.y = ptEnd.y + CAPTION_HEIGHT;
  1022. }else{
  1023. Sp.x = ptEnd.x;
  1024. Sp.y = ptEnd.y + CAPTION_HEIGHT;
  1025. Ep.x = Fp.x = ptStart.x;
  1026. Ep.y = Fp.y = ptStart.y + CAPTION_HEIGHT;
  1027. }
  1028. if( Fp.x >= Sp.x)
  1029. Inc.x = ZoomRate;
  1030. else Inc.x = 0 - ZoomRate;
  1031. if( Fp.y >= Sp.y)
  1032. Inc.y = ZoomRate;
  1033. else Inc.y = 0 - ZoomRate;
  1034. Dp.x = ( Fp.x - Sp.x)*Inc.x;
  1035. Dp.y = ( Fp.y - Sp.y)*Inc.y;
  1036. if( !Dp.x && !Dp.y)
  1037. return;
  1038. if( Dp.x < Dp.y){
  1039. Tmp = Dp.y;
  1040. Dp.y = Dp.x;
  1041. Dp.x = Tmp;
  1042. Tmp = Inc.x;
  1043. Inc.x = Inc.y;
  1044. Inc.y = Tmp;
  1045. Slope = TRUE;
  1046. }else Slope = FALSE;
  1047. Err.x = Dp.y * 2;
  1048. Err.y = ( Dp.y - Dp.x) * 2;
  1049. D = Err.x - Dp.x;
  1050. Ep = Sp;
  1051. dc.MoveTo( Sp);
  1052. while(1){
  1053. if( Sp.x != Ep.x && Sp.y != Ep.y){
  1054. if( Sp.y < Ep.y && Sp.x > Ep.x){
  1055. Cp.x = Sp.x;
  1056. Cp.y = Ep.y;
  1057. }else if( Sp.y < Ep.y && Sp.x < Ep.x){
  1058. Cp.x = Sp.x;
  1059. Cp.y = Ep.y;
  1060. }else if( Sp.y > Ep.y && Sp.x > Ep.x){
  1061. Cp.y = Sp.y;
  1062. Cp.x = Ep.x;
  1063. }else{
  1064. Cp.y = Sp.y;
  1065. Cp.x = Ep.x;
  1066. }
  1067. dc.LineTo( Cp);
  1068. dc.LineTo( Ep);
  1069. P1 = Cp;
  1070. P2 = Ep;
  1071. m_pointArray.Add( P1);
  1072. m_pointArray.Add( P2);
  1073. }else if( Sp.x != Ep.x || Sp.y != Ep.y){
  1074. dc.LineTo( Ep);
  1075. P1 = Ep;
  1076. m_pointArray.Add( P1);
  1077. }
  1078. Sp.x = Ep.x;
  1079. Sp.y = Ep.y;
  1080. if( Ep.x == Fp.x && Ep.y == Fp.y)
  1081. break;
  1082. if( Slope){
  1083. Tmp = Ep.x;
  1084. Ep.x = Ep.y;
  1085. Ep.y = Tmp;
  1086. }
  1087. Ep.x += Inc.x;
  1088. if( D < 0)
  1089. D += Err.x;
  1090. else{
  1091. Ep.y += Inc.y;
  1092. D += Err.y;
  1093. }
  1094. if( Slope){
  1095. Tmp = Ep.x;
  1096. Ep.x = Ep.y;
  1097. Ep.y = Tmp;
  1098. }
  1099. }
  1100. dc.SelectObject( OldPen);
  1101. dc.SetROP2( OldMode);
  1102. }
  1103. /****************************************/
  1104. /* */
  1105. /* Move Rectangle */
  1106. /* */
  1107. /****************************************/
  1108. void
  1109. CRefrWnd::MoveRectangle(
  1110. CPoint point)
  1111. {
  1112. CDC dc;
  1113. dc.Attach( ::GetDC( NULL));
  1114. dc.PatBlt( point.x - m_ptMouse.x, point.y - m_ptMouse.y,
  1115. MoveRect.Width(), 2, PATINVERT);
  1116. dc.PatBlt( point.x - m_ptMouse.x + MoveRect.Width(),
  1117. point.y - m_ptMouse.y, 2, MoveRect.Height(), PATINVERT);
  1118. dc.PatBlt( point.x - m_ptMouse.x, point.y - m_ptMouse.y
  1119. + MoveRect.Height(), MoveRect.Width() + 2, 2, PATINVERT);
  1120. dc.PatBlt( point.x - m_ptMouse.x, point.y - m_ptMouse.y + 2, 2,
  1121. MoveRect.Height() - 2, PATINVERT);
  1122. ::ReleaseDC( NULL, dc.Detach());
  1123. }
  1124. /****************************************/
  1125. /* */
  1126. /* COMMAND "Close Ref" */
  1127. /* */
  1128. /****************************************/
  1129. void
  1130. CRefrWnd::OnClickClose()
  1131. {
  1132. AfxGetMainWnd()->SendMessage( WM_COMMAND, ID_REFFER_CLOSE, 0);
  1133. }
  1134. /****************************************/
  1135. /* */
  1136. /* MESSAGE "WM_KEYDOWN" */
  1137. /* */
  1138. /****************************************/
  1139. void
  1140. CRefrWnd::OnKeyDown(
  1141. UINT nChar,
  1142. UINT nRepCnt,
  1143. UINT nFlags)
  1144. {
  1145. if( nChar == VK_ESCAPE){
  1146. if( RectVisible){
  1147. RectVisible = FALSE;
  1148. this->Invalidate(FALSE);
  1149. this->UpdateWindow();
  1150. }
  1151. }else CMDIChildWnd::OnKeyDown(nChar, nRepCnt, nFlags);
  1152. }