QuickPaste.cpp 3.1 KB

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