QuickPaste.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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(theApp.m_bShowingQuickPaste)
  75. {
  76. if(g_Opt.m_bShowPersistent)
  77. {
  78. m_pwndPaste->MinMaxWindow(FORCE_MAX);
  79. m_pwndPaste->SetForegroundWindow();
  80. }
  81. return;
  82. }
  83. int nPosition = CGetSetOptions::GetQuickPastePosition();
  84. CPoint point;
  85. CRect rcPrev;
  86. CSize csSize;
  87. if(!m_pwndPaste)
  88. m_pwndPaste = new CQPasteWnd;
  89. if(!m_pwndPaste)
  90. {
  91. ASSERT(FALSE);
  92. return;
  93. }
  94. m_pwndPaste->MinMaxWindow(FORCE_MAX);
  95. //If it is a window get the rect otherwise get the saved point and size
  96. if (IsWindow(m_pwndPaste->m_hWnd))
  97. {
  98. m_pwndPaste->GetWindowRect(rcPrev);
  99. csSize = rcPrev.Size();
  100. }
  101. else
  102. {
  103. CGetSetOptions::GetQuickPastePoint(point);
  104. CGetSetOptions::GetQuickPasteSize(csSize);
  105. }
  106. CPoint ptCaret = GetFocusedCaretPos();
  107. if(ptCaret.x <= 0 || ptCaret.y <= 0)
  108. {
  109. CRect cr;
  110. ::GetWindowRect(theApp.m_hTargetWnd, cr);
  111. ptCaret = cr.CenterPoint();
  112. ptCaret.x -= csSize.cx/2;
  113. ptCaret.y -= csSize.cy/2;
  114. }
  115. if(bAtPrevPos)
  116. {
  117. CGetSetOptions::GetQuickPastePoint(point);
  118. CGetSetOptions::GetQuickPasteSize(csSize);
  119. }
  120. else if(nPosition == POS_AT_CARET)
  121. point = ptCaret;
  122. else if(nPosition == POS_AT_CURSOR)
  123. GetCursorPos(&point);
  124. else if(nPosition == POS_AT_PREVIOUS)
  125. CGetSetOptions::GetQuickPastePoint(point);
  126. if( !IsWindow(m_pwndPaste->m_hWnd) )
  127. {
  128. // Create the window
  129. VERIFY( m_pwndPaste->Create(point, pParent) );
  130. }
  131. CRect crRect = CRect(point, csSize);
  132. if(g_Opt.m_bEnsureEntireWindowCanBeSeen)
  133. EnsureWindowVisible(&crRect);
  134. if((nPosition == POS_AT_CARET) ||
  135. (nPosition == POS_AT_CURSOR) ||
  136. (bAtPrevPos))
  137. {
  138. m_pwndPaste->MoveWindow(crRect);
  139. }
  140. // Show the window
  141. m_pwndPaste->ShowQPasteWindow(bReFillList);
  142. m_pwndPaste->SetForegroundWindow();
  143. }
  144. void CQuickPaste::HideQPasteWnd()
  145. {
  146. // Hide the window
  147. if(m_pwndPaste)
  148. {
  149. if (IsWindow(m_pwndPaste->m_hWnd))
  150. m_pwndPaste->HideQPasteWindow();
  151. }
  152. }
  153. BOOL CQuickPaste::IsWindowVisibleEx()
  154. {
  155. if(m_pwndPaste)
  156. return IsWindowVisible(m_pwndPaste->m_hWnd);
  157. return FALSE;
  158. }