WndEx.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // WndEx.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "WndEx.h"
  6. #include ".\wndex.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CWndEx
  14. #define CLOSE_WIDTH 12
  15. #define CLOSE_HEIGHT 11
  16. #define CLOSE_BORDER 2
  17. #define TIMER_AUTO_MAX 5
  18. #define TIMER_BUTTON_UP 6
  19. CWndEx::CWndEx()
  20. {
  21. SetCaptionColorActive(false, TRUE);
  22. m_lDelayMaxSeconds = 2;
  23. }
  24. CWndEx::~CWndEx()
  25. {
  26. }
  27. void CWndEx::InvalidateNc()
  28. {
  29. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  30. }
  31. void CWndEx::GetWindowRectEx(LPRECT lpRect)
  32. {
  33. if(m_DittoWindow.m_bMinimized)
  34. {
  35. *lpRect = m_DittoWindow.m_crFullSizeWindow;
  36. return;
  37. }
  38. CWnd::GetWindowRect(lpRect);
  39. }
  40. BEGIN_MESSAGE_MAP(CWndEx, CWnd)
  41. //{{AFX_MSG_MAP(CWndEx)
  42. ON_WM_CREATE()
  43. ON_WM_NCPAINT()
  44. ON_WM_NCCALCSIZE()
  45. ON_WM_NCHITTEST()
  46. ON_WM_NCLBUTTONDOWN()
  47. ON_WM_NCMOUSEMOVE()
  48. ON_WM_NCLBUTTONUP()
  49. ON_WM_ERASEBKGND()
  50. ON_WM_TIMER()
  51. ON_WM_WINDOWPOSCHANGING()
  52. ON_WM_INITMENUPOPUP()
  53. //}}AFX_MSG_MAP
  54. ON_WM_SIZE()
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CWndEx message handlers
  58. BOOL CWndEx::Create(const CRect& crStart, CWnd* pParentWnd)
  59. {
  60. WNDCLASS wc;
  61. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  62. wc.lpfnWndProc = AfxWndProc;
  63. wc.cbClsExtra = 0;
  64. wc.cbWndExtra = 0;
  65. wc.hInstance = AfxGetInstanceHandle();
  66. wc.hIcon = NULL;
  67. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  68. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  69. wc.lpszMenuName = NULL;
  70. wc.lpszClassName = _T("QPasteClass");
  71. // Create the QPaste window class
  72. if (!AfxRegisterClass(&wc))
  73. return FALSE;
  74. return CWndEx::CreateEx(0, _T("QPasteClass"), _T("Quick Paste"), WS_POPUP,
  75. crStart, pParentWnd, 0);
  76. }
  77. int CWndEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
  78. {
  79. if (CWnd::OnCreate(lpCreateStruct) == -1)
  80. return -1;
  81. m_DittoWindow.DoCreate(this);
  82. m_DittoWindow.m_bDrawMinimize = false;
  83. m_DittoWindow.m_bDrawMaximize = false;
  84. SetCaptionColorActive(false, TRUE);
  85. m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true, g_Opt.m_Theme.GetCaptionSize(), g_Opt.m_Theme.GetCaptionFontSize());
  86. SetAutoMaxDelay(CGetSetOptions::GetAutoMaxDelay());
  87. m_toolTip.Create(this);
  88. CRect r;
  89. GetWindowRect(&r);
  90. ScreenToClient(&r);
  91. m_toolTip.AddTool(this, _T("Ditto"), r, 1);
  92. return 0;
  93. }
  94. bool CWndEx::SetCaptionColorActive(BOOL bPersistant, BOOL ConnectedToClipboard)
  95. {
  96. bool bResult;
  97. if(ConnectedToClipboard == false)
  98. {
  99. bResult = m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeftNotConnected(), g_Opt.m_Theme.CaptionRightNotConnected(), g_Opt.m_Theme.BorderNotConnected());
  100. }
  101. else
  102. {
  103. if(bPersistant)
  104. {
  105. bResult = m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeftTopMost(), g_Opt.m_Theme.CaptionRightTopMost(), g_Opt.m_Theme.BorderTopMost());
  106. }
  107. else
  108. {
  109. bResult = m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight(), g_Opt.m_Theme.Border());
  110. }
  111. }
  112. m_DittoWindow.SetCaptionTextColor(g_Opt.m_Theme.CaptionTextColor());
  113. return bResult;
  114. }
  115. void CWndEx::SetCaptionOn(int nPos, bool bOnstartup, int captionSize, int captionFontSize)
  116. {
  117. m_DittoWindow.SetCaptionOn(this, nPos, bOnstartup, captionSize, captionFontSize);
  118. }
  119. void CWndEx::OnNcPaint()
  120. {
  121. m_DittoWindow.DoNcPaint(this);
  122. }
  123. void CWndEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  124. {
  125. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  126. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  127. }
  128. HITTEST_RET CWndEx::OnNcHitTest(CPoint point)
  129. {
  130. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  131. if(Ret == -1)
  132. return CWnd::OnNcHitTest(point);
  133. return Ret;
  134. }
  135. void CWndEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  136. {
  137. int buttonPressed = m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  138. if (buttonPressed != 0)
  139. {
  140. SetTimer(TIMER_BUTTON_UP, 100, NULL);
  141. }
  142. CWnd::OnNcLButtonDown(nHitTest, point);
  143. }
  144. void CWndEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  145. {
  146. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  147. if(lRet > 0)
  148. {
  149. if(lRet == BUTTON_CHEVRON)
  150. {
  151. MinMaxWindow(SWAP_MIN_MAX);
  152. OnNcPaint();
  153. }
  154. return;
  155. }
  156. KillTimer(TIMER_BUTTON_UP);
  157. CWnd::OnNcLButtonUp(nHitTest, point);
  158. }
  159. void CWndEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  160. {
  161. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  162. if((m_bMaxSetTimer == false) && m_DittoWindow.m_bMinimized)
  163. {
  164. COleDateTimeSpan sp = COleDateTime::GetCurrentTime() - m_DittoWindow.m_TimeMinimized;
  165. if(sp.GetTotalSeconds() >= m_lDelayMaxSeconds)
  166. {
  167. SetTimer(TIMER_AUTO_MAX, CGetSetOptions::GetTimeBeforeExpandWindow(), NULL);
  168. m_bMaxSetTimer = true;
  169. }
  170. }
  171. CWnd::OnNcMouseMove(nHitTest, point);
  172. }
  173. BOOL CWndEx::PreTranslateMessage(MSG* pMsg)
  174. {
  175. m_toolTip.RelayEvent(pMsg);
  176. m_DittoWindow.DoPreTranslateMessage(pMsg);
  177. return CWnd::PreTranslateMessage(pMsg);
  178. }
  179. BOOL CWndEx::OnEraseBkgnd(CDC* pDC)
  180. {
  181. return CWnd::OnEraseBkgnd(pDC);
  182. }
  183. void CWndEx::OnTimer(UINT_PTR nIDEvent)
  184. {
  185. if(nIDEvent == TIMER_AUTO_MAX)
  186. {
  187. if(m_DittoWindow.m_bMinimized)
  188. {
  189. CPoint cp;
  190. GetCursorPos(&cp);
  191. UINT nHitTest = (UINT)OnNcHitTest(cp);
  192. ScreenToClient(&cp);
  193. if(nHitTest == HTCAPTION)
  194. {
  195. if(m_DittoWindow.m_crCloseBT.PtInRect(cp) == false)
  196. {
  197. if(m_DittoWindow.m_crMinimizeBT.PtInRect(cp) == false)
  198. {
  199. MinMaxWindow(FORCE_MAX);
  200. }
  201. }
  202. }
  203. }
  204. KillTimer(TIMER_AUTO_MAX);
  205. m_bMaxSetTimer = false;
  206. }
  207. else if (nIDEvent == TIMER_BUTTON_UP)
  208. {
  209. if ((GetKeyState(VK_LBUTTON) & 0x100) == 0)
  210. {
  211. m_DittoWindow.DoNcLButtonUp(this, 0, CPoint(0, 0));
  212. KillTimer(TIMER_BUTTON_UP);
  213. }
  214. }
  215. CWnd::OnTimer(nIDEvent);
  216. }
  217. void CWndEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  218. {
  219. CWnd::OnWindowPosChanging(lpwndpos);
  220. if(m_bMaxSetTimer)
  221. {
  222. KillTimer(TIMER_AUTO_MAX);
  223. m_bMaxSetTimer = false;
  224. }
  225. m_DittoWindow.SnapToEdge(this, lpwndpos);
  226. }
  227. void CWndEx::OnSize(UINT nType, int cx, int cy)
  228. {
  229. CWnd::OnSize(nType, cx, cy);
  230. m_DittoWindow.DoSetRegion(this);
  231. }
  232. void CWndEx::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu)
  233. {
  234. OnInitMenuPopupEx(pPopupMenu, nIndex, bSysMenu, this);
  235. }
  236. void CWndEx::SetToolTipText(CString text)
  237. {
  238. m_toolTip.UpdateTipText(text, this, 1);
  239. }
  240. void CWndEx::SetCustomWindowTitle(CString title)
  241. {
  242. CString old = m_DittoWindow.m_customWindowTitle;
  243. m_DittoWindow.m_customWindowTitle = title;
  244. m_DittoWindow.m_useCustomWindowTitle = true;
  245. if (old != m_DittoWindow.m_customWindowTitle)
  246. {
  247. this->InvalidateNc();
  248. }
  249. }
  250. void CWndEx::MinMaxWindow(long lOption)
  251. {
  252. m_DittoWindow.MinMaxWindow(this, lOption);
  253. }