QuickPaste.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. theApp.TargetActiveWindow();
  67. CPoint ptCaret;
  68. GetFocusWnd(&ptCaret); // get caret position relative to screen
  69. ptCaret.Offset(-12, 12);
  70. int nPosition = CGetSetOptions::GetQuickPastePosition();
  71. CPoint point;
  72. CRect rcPrev;
  73. CSize csSize;
  74. if(!m_pwndPaste)
  75. m_pwndPaste = new CQPasteWnd;
  76. if(!m_pwndPaste)
  77. {
  78. ASSERT(FALSE);
  79. return;
  80. }
  81. //If it is a window get the rect otherwise get the saved point and size
  82. if (IsWindow(m_pwndPaste->m_hWnd))
  83. {
  84. m_pwndPaste->GetWindowRect(rcPrev);
  85. csSize = rcPrev.Size();
  86. }
  87. else
  88. {
  89. CGetSetOptions::GetQuickPastePoint(point);
  90. CGetSetOptions::GetQuickPasteSize(csSize);
  91. }
  92. if(bAtPrevPos)
  93. {
  94. CGetSetOptions::GetQuickPastePoint(point);
  95. CGetSetOptions::GetQuickPasteSize(csSize);
  96. }
  97. else if(nPosition == POS_AT_CARET)
  98. point = ptCaret;
  99. else if(nPosition == POS_AT_CURSOR)
  100. GetCursorPos(&point);
  101. else if(nPosition == POS_AT_PREVIOUS)
  102. CGetSetOptions::GetQuickPastePoint(point);
  103. if( !IsWindow(m_pwndPaste->m_hWnd) )
  104. {
  105. // Create the window
  106. VERIFY( m_pwndPaste->Create(point, pParent) );
  107. }
  108. if((nPosition == POS_AT_CARET) ||
  109. (nPosition == POS_AT_CURSOR) ||
  110. (bAtPrevPos))
  111. {
  112. m_pwndPaste->MoveWindow(CRect(point, csSize));
  113. }
  114. // Show the window
  115. m_pwndPaste->ShowWindow(SW_SHOW);
  116. m_pwndPaste->SetForegroundWindow();
  117. }
  118. void CQuickPaste::HideQPasteWnd()
  119. {
  120. // Hide the window
  121. if(m_pwndPaste)
  122. {
  123. if (IsWindow(m_pwndPaste->m_hWnd))
  124. m_pwndPaste->ShowWindow(SW_SHOW);
  125. }
  126. }