QuickPaste.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. void CQuickPaste::Create(CWnd *pParent)
  29. {
  30. CPoint point;
  31. CSize csSize;
  32. ASSERT(!m_pwndPaste);
  33. m_pwndPaste = new CQPasteWnd;
  34. ASSERT(m_pwndPaste);
  35. // load previous position and size
  36. CGetSetOptions::GetQuickPastePoint(point);
  37. CGetSetOptions::GetQuickPasteSize(csSize);
  38. // Create the window
  39. ASSERT( m_pwndPaste->Create(point, pParent) );
  40. // place it at the previous position and size
  41. m_pwndPaste->MoveWindow(CRect(point, csSize));
  42. }
  43. BOOL CQuickPaste::CloseQPasteWnd()
  44. {
  45. if(m_pwndPaste)
  46. {
  47. if(m_pwndPaste->IsWindowVisible())
  48. return FALSE;
  49. if(m_pwndPaste)
  50. m_pwndPaste->SendMessage(WM_CLOSE, 0, 0);
  51. delete m_pwndPaste;
  52. m_pwndPaste = NULL;
  53. }
  54. return TRUE;
  55. }
  56. void CQuickPaste::ShowQPasteWnd(CWnd *pParent, BOOL bAtPrevPos)
  57. {
  58. {
  59. if((theApp.m_bShowingQuickPaste) || (theApp.m_bShowingOptions))
  60. {
  61. if( g_Opt.m_bShowPersistent )
  62. m_pwndPaste->SetForegroundWindow();
  63. return;
  64. }
  65. }
  66. CPoint ptCaret;
  67. GetFocusWnd(&ptCaret); // get caret position relative to screen
  68. ptCaret.Offset(-12, 12);
  69. int nPosition = CGetSetOptions::GetQuickPastePosition();
  70. CPoint point;
  71. CRect rcPrev;
  72. CSize csSize;
  73. if(!m_pwndPaste)
  74. m_pwndPaste = new CQPasteWnd;
  75. if(!m_pwndPaste)
  76. {
  77. ASSERT(FALSE);
  78. return;
  79. }
  80. //If it is a window get the rect otherwise get the saved point and size
  81. if (IsWindow(m_pwndPaste->m_hWnd))
  82. {
  83. m_pwndPaste->GetWindowRect(rcPrev);
  84. csSize = rcPrev.Size();
  85. }
  86. else
  87. {
  88. CGetSetOptions::GetQuickPastePoint(point);
  89. CGetSetOptions::GetQuickPasteSize(csSize);
  90. }
  91. if(bAtPrevPos)
  92. {
  93. CGetSetOptions::GetQuickPastePoint(point);
  94. CGetSetOptions::GetQuickPasteSize(csSize);
  95. }
  96. else if(nPosition == POS_AT_CARET)
  97. point = ptCaret;
  98. else if(nPosition == POS_AT_CURSOR)
  99. GetCursorPos(&point);
  100. else if(nPosition == POS_AT_PREVIOUS)
  101. CGetSetOptions::GetQuickPastePoint(point);
  102. if( !IsWindow(m_pwndPaste->m_hWnd) )
  103. {
  104. // Create the window
  105. VERIFY( m_pwndPaste->Create(point, pParent) );
  106. }
  107. if((nPosition == POS_AT_CARET) ||
  108. (nPosition == POS_AT_CURSOR) ||
  109. (bAtPrevPos))
  110. {
  111. m_pwndPaste->MoveWindow(CRect(point, csSize));
  112. }
  113. // Show the window
  114. m_pwndPaste->ShowWindow(SW_SHOW);
  115. m_pwndPaste->SetForegroundWindow();
  116. }
  117. void CQuickPaste::HideQPasteWnd()
  118. {
  119. // Hide the window
  120. if(m_pwndPaste)
  121. {
  122. if (IsWindow(m_pwndPaste->m_hWnd))
  123. m_pwndPaste->ShowWindow(SW_SHOW);
  124. }
  125. }