QuickPaste.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. Log(_T("Creating QPasteWnd"));
  43. }
  44. BOOL CQuickPaste::CloseQPasteWnd()
  45. {
  46. if(m_pwndPaste)
  47. {
  48. if(m_pwndPaste->IsWindowVisible())
  49. {
  50. Log(_T("CloseQPasteWnd called but the window is visible"));
  51. return FALSE;
  52. }
  53. if(m_pwndPaste)
  54. m_pwndPaste->DestroyWindow();
  55. Log(_T("CloseQPasteWnd called closing qpastewnd"));
  56. delete m_pwndPaste;
  57. m_pwndPaste = NULL;
  58. }
  59. return TRUE;
  60. }
  61. void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboard, BOOL bReFillList)
  62. {
  63. if(bFromKeyboard == false && GetKeyState(VK_SHIFT) & 0x8000 && GetKeyState(VK_CONTROL) & 0x8000)
  64. {
  65. if(m_pwndPaste)
  66. m_pwndPaste->DestroyWindow();
  67. Log(_T("CloseQPasteWnd called closing qpastewnd from keyboard"));
  68. delete m_pwndPaste;
  69. m_pwndPaste = NULL;
  70. theApp.m_db.close();
  71. OpenDatabase(CGetSetOptions::GetDBPath());
  72. return;
  73. }
  74. if(g_Opt.m_bShowPersistent && m_pwndPaste != NULL)
  75. {
  76. m_pwndPaste->ShowWindow(SW_SHOW);
  77. m_pwndPaste->MinMaxWindow(FORCE_MAX);
  78. m_pwndPaste->SetForegroundWindow();
  79. return;
  80. }
  81. int nPosition = CGetSetOptions::GetQuickPastePosition();
  82. CPoint point;
  83. CRect rcPrev;
  84. CSize csSize;
  85. if(!m_pwndPaste)
  86. m_pwndPaste = new CQPasteWnd;
  87. if(!m_pwndPaste)
  88. {
  89. ASSERT(FALSE);
  90. return;
  91. }
  92. m_pwndPaste->MinMaxWindow(FORCE_MAX);
  93. //If it is a window get the rect otherwise get the saved point and size
  94. if (IsWindow(m_pwndPaste->m_hWnd))
  95. {
  96. m_pwndPaste->GetWindowRect(rcPrev);
  97. csSize = rcPrev.Size();
  98. }
  99. else
  100. {
  101. CGetSetOptions::GetQuickPastePoint(point);
  102. CGetSetOptions::GetQuickPasteSize(csSize);
  103. }
  104. CPoint ptCaret = GetFocusedCaretPos();
  105. if(ptCaret.x <= 0 || ptCaret.y <= 0)
  106. {
  107. CRect cr;
  108. ::GetWindowRect(theApp.m_hTargetWnd, cr);
  109. if(cr.PtInRect(ptCaret) == FALSE)
  110. {
  111. ptCaret = cr.CenterPoint();
  112. ptCaret.x -= csSize.cx/2;
  113. ptCaret.y -= csSize.cy/2;
  114. }
  115. }
  116. if(bAtPrevPos)
  117. {
  118. CGetSetOptions::GetQuickPastePoint(point);
  119. CGetSetOptions::GetQuickPasteSize(csSize);
  120. }
  121. else if(nPosition == POS_AT_CARET)
  122. point = ptCaret;
  123. else if(nPosition == POS_AT_CURSOR)
  124. GetCursorPos(&point);
  125. else if(nPosition == POS_AT_PREVIOUS)
  126. CGetSetOptions::GetQuickPastePoint(point);
  127. if( !IsWindow(m_pwndPaste->m_hWnd) )
  128. {
  129. // Create the window
  130. VERIFY( m_pwndPaste->Create(point, pParent) );
  131. }
  132. CRect crRect = CRect(point, csSize);
  133. if(g_Opt.m_bEnsureEntireWindowCanBeSeen)
  134. EnsureWindowVisible(&crRect);
  135. if((nPosition == POS_AT_CARET) ||
  136. (nPosition == POS_AT_CURSOR) ||
  137. (bAtPrevPos))
  138. {
  139. m_pwndPaste->MoveWindow(crRect);
  140. }
  141. // Show the window
  142. m_pwndPaste->ShowWindow(SW_SHOW);
  143. m_pwndPaste->ShowQPasteWindow(bReFillList);
  144. m_pwndPaste->SetForegroundWindow();
  145. }
  146. void CQuickPaste::HideQPasteWnd()
  147. {
  148. // Hide the window
  149. if(m_pwndPaste)
  150. {
  151. if (IsWindow(m_pwndPaste->m_hWnd))
  152. m_pwndPaste->HideQPasteWindow();
  153. }
  154. }
  155. BOOL CQuickPaste::IsWindowVisibleEx()
  156. {
  157. if(m_pwndPaste)
  158. return IsWindowVisible(m_pwndPaste->m_hWnd);
  159. return FALSE;
  160. }