QuickPaste.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. Log(StrF(_T("Start of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d"), bAtPrevPos, bFromKeyboard, bReFillList));
  64. if(bFromKeyboard == false && GetKeyState(VK_SHIFT) & 0x8000 && GetKeyState(VK_CONTROL) & 0x8000)
  65. {
  66. if(m_pwndPaste)
  67. m_pwndPaste->DestroyWindow();
  68. Log(_T("CloseQPasteWnd called closing qpastewnd from keyboard"));
  69. delete m_pwndPaste;
  70. m_pwndPaste = NULL;
  71. theApp.m_db.close();
  72. OpenDatabase(CGetSetOptions::GetDBPath());
  73. return;
  74. }
  75. if(g_Opt.m_bShowPersistent && m_pwndPaste != NULL)
  76. {
  77. m_pwndPaste->ShowWindow(SW_SHOW);
  78. m_pwndPaste->MinMaxWindow(FORCE_MAX);
  79. m_pwndPaste->SetForegroundWindow();
  80. return;
  81. }
  82. int nPosition = CGetSetOptions::GetQuickPastePosition();
  83. CPoint point;
  84. CRect rcPrev;
  85. CSize csSize;
  86. if(!m_pwndPaste)
  87. m_pwndPaste = new CQPasteWnd;
  88. if(!m_pwndPaste)
  89. {
  90. ASSERT(FALSE);
  91. return;
  92. }
  93. m_pwndPaste->MinMaxWindow(FORCE_MAX);
  94. //If it is a window get the rect otherwise get the saved point and size
  95. if (IsWindow(m_pwndPaste->m_hWnd))
  96. {
  97. m_pwndPaste->GetWindowRect(rcPrev);
  98. csSize = rcPrev.Size();
  99. }
  100. else
  101. {
  102. CGetSetOptions::GetQuickPastePoint(point);
  103. CGetSetOptions::GetQuickPasteSize(csSize);
  104. }
  105. CPoint ptCaret = theApp.m_activeWnd.FocusCaret();
  106. if(ptCaret.x <= 0 || ptCaret.y <= 0)
  107. {
  108. CRect cr;
  109. ::GetWindowRect(theApp.m_activeWnd.ActiveWnd(), cr);
  110. ptCaret = cr.CenterPoint();
  111. ptCaret.x -= csSize.cx/2;
  112. ptCaret.y -= csSize.cy/2;
  113. }
  114. if(bAtPrevPos)
  115. {
  116. CGetSetOptions::GetQuickPastePoint(point);
  117. CGetSetOptions::GetQuickPasteSize(csSize);
  118. }
  119. else if(nPosition == POS_AT_CARET)
  120. point = ptCaret;
  121. else if(nPosition == POS_AT_CURSOR)
  122. GetCursorPos(&point);
  123. else if(nPosition == POS_AT_PREVIOUS)
  124. CGetSetOptions::GetQuickPastePoint(point);
  125. if( !IsWindow(m_pwndPaste->m_hWnd) )
  126. {
  127. // Create the window
  128. VERIFY( m_pwndPaste->Create(point, pParent) );
  129. }
  130. CRect crRect = CRect(point, csSize);
  131. if(g_Opt.m_bEnsureEntireWindowCanBeSeen)
  132. EnsureWindowVisible(&crRect);
  133. if((nPosition == POS_AT_CARET) ||
  134. (nPosition == POS_AT_CURSOR) ||
  135. (bAtPrevPos))
  136. {
  137. m_pwndPaste->MoveWindow(crRect);
  138. }
  139. // Show the window
  140. m_pwndPaste->ShowWindow(SW_SHOW);
  141. if(bReFillList)
  142. {
  143. m_pwndPaste->ShowQPasteWindow(bReFillList);
  144. }
  145. m_pwndPaste->SetForegroundWindow();
  146. Log(StrF(_T("END of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d"), bAtPrevPos, bFromKeyboard, bReFillList));
  147. }
  148. void CQuickPaste::MoveSelection(bool down)
  149. {
  150. if(m_pwndPaste)
  151. {
  152. if (IsWindow(m_pwndPaste->m_hWnd))
  153. {
  154. m_pwndPaste->MoveSelection(down);
  155. }
  156. }
  157. }
  158. void CQuickPaste::OnKeyStateUp()
  159. {
  160. if(m_pwndPaste)
  161. {
  162. if (IsWindow(m_pwndPaste->m_hWnd))
  163. {
  164. m_pwndPaste->OnKeyStateUp();
  165. }
  166. }
  167. }
  168. void CQuickPaste::SetKeyModiferState(bool bActive)
  169. {
  170. if(m_pwndPaste)
  171. {
  172. if (IsWindow(m_pwndPaste->m_hWnd))
  173. {
  174. m_pwndPaste->SetKeyModiferState(bActive);
  175. }
  176. }
  177. }
  178. void CQuickPaste::HideQPasteWnd()
  179. {
  180. // Hide the window
  181. if(m_pwndPaste)
  182. {
  183. if (IsWindow(m_pwndPaste->m_hWnd))
  184. m_pwndPaste->HideQPasteWindow();
  185. }
  186. }
  187. BOOL CQuickPaste::IsWindowVisibleEx()
  188. {
  189. if(m_pwndPaste)
  190. return IsWindowVisible(m_pwndPaste->m_hWnd);
  191. return FALSE;
  192. }