QuickPaste.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // QuickPaste.cpp: implementation of the CQuickPaste class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CP_Main.h"
  6. #include "QuickPaste.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. #define ID_QPASTE_WND 0x1001
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CQuickPaste::CQuickPaste()
  17. {
  18. m_pwndPaste = NULL;
  19. }
  20. CQuickPaste::~CQuickPaste()
  21. {
  22. if(m_pwndPaste)
  23. {
  24. delete m_pwndPaste;
  25. m_pwndPaste = NULL;
  26. }
  27. }
  28. BOOL CQuickPaste::CloseQPasteWnd()
  29. {
  30. if(m_pwndPaste)
  31. {
  32. if(m_pwndPaste->IsWindowVisible())
  33. return FALSE;
  34. if(m_pwndPaste)
  35. m_pwndPaste->SendMessage(WM_CLOSE, 0, 0);
  36. delete m_pwndPaste;
  37. m_pwndPaste = NULL;
  38. }
  39. return TRUE;
  40. }
  41. void CQuickPaste::ShowQPasteWnd(CWnd *pParent, BOOL bAtPrevPos)
  42. {
  43. {
  44. if((theApp.m_bShowingQuickPaste) || (theApp.m_bShowingOptions))
  45. return;
  46. }
  47. int nPosition = CGetSetOptions::GetQuickPastePosition();
  48. CPoint ptCaret;
  49. HWND hWndActive = GetActiveWnd(&ptCaret);
  50. ptCaret.Offset(-12, 12);
  51. CPoint point;
  52. CRect rcPrev;
  53. CSize csSize;
  54. if(!m_pwndPaste)
  55. m_pwndPaste = new CQPasteWnd;
  56. if(!m_pwndPaste)
  57. {
  58. ASSERT(FALSE);
  59. return;
  60. }
  61. //If its a window get the rect otherwise get the saved point and size
  62. if (IsWindow(m_pwndPaste->m_hWnd))
  63. {
  64. m_pwndPaste->GetWindowRect(rcPrev);
  65. csSize = rcPrev.Size();
  66. }
  67. else
  68. {
  69. CGetSetOptions::GetQuickPastePoint(point);
  70. CGetSetOptions::GetQuickPasteSize(csSize);
  71. }
  72. if(bAtPrevPos)
  73. {
  74. CGetSetOptions::GetQuickPastePoint(point);
  75. CGetSetOptions::GetQuickPasteSize(csSize);
  76. }
  77. else if(nPosition == POS_AT_CARET)
  78. point = ptCaret;
  79. else if(nPosition == POS_AT_CURSOR)
  80. GetCursorPos(&point);
  81. else if(nPosition == POS_AT_PREVIOUS)
  82. CGetSetOptions::GetQuickPastePoint(point);
  83. if (!IsWindow(m_pwndPaste->m_hWnd))
  84. {
  85. // Create the window
  86. if (!m_pwndPaste->Create(point, pParent))
  87. return;
  88. }
  89. if((nPosition == POS_AT_CARET) ||
  90. (nPosition == POS_AT_CURSOR) ||
  91. (bAtPrevPos))
  92. {
  93. m_pwndPaste->MoveWindow(CRect(point, csSize));
  94. }
  95. //set the window that recieves the paste message
  96. m_pwndPaste->SetFocusWindow(hWndActive);
  97. // Show the window
  98. m_pwndPaste->ShowWindow(SW_SHOW);
  99. ::SetForegroundWindow(m_pwndPaste->m_hWnd);
  100. ::SetFocus(m_pwndPaste->m_hWnd);
  101. }
  102. void CQuickPaste::HideQPasteWnd()
  103. {
  104. // Hide the window
  105. if(m_pwndPaste)
  106. {
  107. if (IsWindow(m_pwndPaste->m_hWnd))
  108. m_pwndPaste->ShowWindow(SW_SHOW);
  109. }
  110. }