WndEx.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. ON_WM_MOVING()
  56. ON_WM_ENTERSIZEMOVE()
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CWndEx message handlers
  60. BOOL CWndEx::Create(const CRect& crStart, CWnd* pParentWnd)
  61. {
  62. WNDCLASS wc;
  63. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  64. wc.lpfnWndProc = AfxWndProc;
  65. wc.cbClsExtra = 0;
  66. wc.cbWndExtra = 0;
  67. wc.hInstance = AfxGetInstanceHandle();
  68. wc.hIcon = NULL;
  69. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  70. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  71. wc.lpszMenuName = NULL;
  72. wc.lpszClassName = _T("QPasteClass");
  73. // Create the QPaste window class
  74. if (!AfxRegisterClass(&wc))
  75. return FALSE;
  76. return CWndEx::CreateEx(0, _T("QPasteClass"), _T("Quick Paste"), WS_POPUP,
  77. crStart, pParentWnd, 0);
  78. }
  79. int CWndEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
  80. {
  81. if (CWnd::OnCreate(lpCreateStruct) == -1)
  82. return -1;
  83. m_DittoWindow.DoCreate(this);
  84. m_DittoWindow.m_bDrawMinimize = false;
  85. m_DittoWindow.m_bDrawMaximize = false;
  86. SetWindowPos(NULL,
  87. lpCreateStruct->x,
  88. lpCreateStruct->y,
  89. m_DittoWindow.m_dpi.Scale(lpCreateStruct->cx),
  90. m_DittoWindow.m_dpi.Scale(lpCreateStruct->cy),
  91. SWP_NOZORDER | SWP_NOACTIVATE);
  92. SetCaptionColorActive(false, TRUE);
  93. m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true, g_Opt.m_Theme.GetCaptionSize(), g_Opt.m_Theme.GetCaptionFontSize());
  94. SetAutoMaxDelay(CGetSetOptions::GetAutoMaxDelay());
  95. m_toolTip.Create(this);
  96. CRect r;
  97. GetWindowRect(&r);
  98. ScreenToClient(&r);
  99. m_toolTip.AddTool(this, _T("Ditto"), r, 1);
  100. return 0;
  101. }
  102. bool CWndEx::SetCaptionColorActive(BOOL bPersistant, BOOL ConnectedToClipboard)
  103. {
  104. bool bResult;
  105. if(ConnectedToClipboard == false)
  106. {
  107. bResult = m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeftNotConnected(), g_Opt.m_Theme.CaptionRightNotConnected(), g_Opt.m_Theme.BorderNotConnected());
  108. }
  109. else
  110. {
  111. if(bPersistant)
  112. {
  113. bResult = m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeftTopMost(), g_Opt.m_Theme.CaptionRightTopMost(), g_Opt.m_Theme.BorderTopMost());
  114. }
  115. else
  116. {
  117. bResult = m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight(), g_Opt.m_Theme.Border());
  118. }
  119. }
  120. m_DittoWindow.SetCaptionTextColor(g_Opt.m_Theme.CaptionTextColor());
  121. return bResult;
  122. }
  123. void CWndEx::SetCaptionOn(int nPos, bool bOnstartup, int captionSize, int captionFontSize)
  124. {
  125. m_DittoWindow.SetCaptionOn(this, nPos, bOnstartup, captionSize, captionFontSize);
  126. }
  127. void CWndEx::OnNcPaint()
  128. {
  129. m_DittoWindow.DoNcPaint(this);
  130. }
  131. void CWndEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  132. {
  133. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  134. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  135. }
  136. HITTEST_RET CWndEx::OnNcHitTest(CPoint point)
  137. {
  138. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  139. if(Ret == -1)
  140. return CWnd::OnNcHitTest(point);
  141. return Ret;
  142. }
  143. void CWndEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  144. {
  145. int buttonPressed = m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  146. if (buttonPressed != 0)
  147. {
  148. SetTimer(TIMER_BUTTON_UP, 100, NULL);
  149. }
  150. CWnd::OnNcLButtonDown(nHitTest, point);
  151. }
  152. void CWndEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  153. {
  154. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  155. if(lRet > 0)
  156. {
  157. if(lRet == BUTTON_CHEVRON)
  158. {
  159. MinMaxWindow(SWAP_MIN_MAX);
  160. OnNcPaint();
  161. }
  162. return;
  163. }
  164. KillTimer(TIMER_BUTTON_UP);
  165. CWnd::OnNcLButtonUp(nHitTest, point);
  166. }
  167. void CWndEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  168. {
  169. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  170. if((m_bMaxSetTimer == false) && m_DittoWindow.m_bMinimized)
  171. {
  172. COleDateTimeSpan sp = COleDateTime::GetCurrentTime() - m_DittoWindow.m_TimeMinimized;
  173. if(sp.GetTotalSeconds() >= m_lDelayMaxSeconds)
  174. {
  175. SetTimer(TIMER_AUTO_MAX, CGetSetOptions::GetTimeBeforeExpandWindow(), NULL);
  176. m_bMaxSetTimer = true;
  177. }
  178. }
  179. CWnd::OnNcMouseMove(nHitTest, point);
  180. }
  181. BOOL CWndEx::PreTranslateMessage(MSG* pMsg)
  182. {
  183. m_toolTip.RelayEvent(pMsg);
  184. m_DittoWindow.DoPreTranslateMessage(pMsg);
  185. return CWnd::PreTranslateMessage(pMsg);
  186. }
  187. BOOL CWndEx::OnEraseBkgnd(CDC* pDC)
  188. {
  189. return CWnd::OnEraseBkgnd(pDC);
  190. }
  191. void CWndEx::OnTimer(UINT_PTR nIDEvent)
  192. {
  193. if(nIDEvent == TIMER_AUTO_MAX)
  194. {
  195. if(m_DittoWindow.m_bMinimized)
  196. {
  197. CPoint cp;
  198. GetCursorPos(&cp);
  199. UINT nHitTest = (UINT)OnNcHitTest(cp);
  200. ScreenToClient(&cp);
  201. if(nHitTest == HTCAPTION)
  202. {
  203. if(m_DittoWindow.m_crCloseBT.PtInRect(cp) == false)
  204. {
  205. if(m_DittoWindow.m_crMinimizeBT.PtInRect(cp) == false)
  206. {
  207. MinMaxWindow(FORCE_MAX);
  208. }
  209. }
  210. }
  211. }
  212. KillTimer(TIMER_AUTO_MAX);
  213. m_bMaxSetTimer = false;
  214. }
  215. else if (nIDEvent == TIMER_BUTTON_UP)
  216. {
  217. if ((GetKeyState(VK_LBUTTON) & 0x100) == 0)
  218. {
  219. m_DittoWindow.DoNcLButtonUp(this, 0, CPoint(0, 0));
  220. KillTimer(TIMER_BUTTON_UP);
  221. }
  222. }
  223. CWnd::OnTimer(nIDEvent);
  224. }
  225. void CWndEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  226. {
  227. CWnd::OnWindowPosChanging(lpwndpos);
  228. if(m_bMaxSetTimer)
  229. {
  230. KillTimer(TIMER_AUTO_MAX);
  231. m_bMaxSetTimer = false;
  232. }
  233. //m_DittoWindow.SnapToEdge(this, lpwndpos);
  234. }
  235. void CWndEx::OnSize(UINT nType, int cx, int cy)
  236. {
  237. CWnd::OnSize(nType, cx, cy);
  238. //m_DittoWindow.DoSetRegion(this);
  239. }
  240. void CWndEx::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu)
  241. {
  242. OnInitMenuPopupEx(pPopupMenu, nIndex, bSysMenu, this);
  243. }
  244. void CWndEx::SetToolTipText(CString text)
  245. {
  246. m_toolTip.UpdateTipText(text, this, 1);
  247. }
  248. void CWndEx::SetCustomWindowTitle(CString title)
  249. {
  250. CString old = m_DittoWindow.m_customWindowTitle;
  251. m_DittoWindow.m_customWindowTitle = title;
  252. m_DittoWindow.m_useCustomWindowTitle = true;
  253. if (old != m_DittoWindow.m_customWindowTitle)
  254. {
  255. this->InvalidateNc();
  256. }
  257. }
  258. void CWndEx::MinMaxWindow(long lOption)
  259. {
  260. m_DittoWindow.MinMaxWindow(this, lOption);
  261. }
  262. void CWndEx::OnMoving(UINT fwSide, LPRECT pRect)
  263. {
  264. CWnd::OnMoving(fwSide, pRect);
  265. m_snap.OnSnapMoving(m_hWnd, pRect);
  266. // TODO: Add your message handler code here
  267. }
  268. void CWndEx::OnEnterSizeMove()
  269. {
  270. m_snap.OnSnapEnterSizeMove(m_hWnd);
  271. CWnd::OnEnterSizeMove();
  272. }