DittoWindow.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. #include "stdafx.h"
  2. #include ".\dittowindow.h"
  3. #include "CP_Main.h"
  4. #include "Options.h"
  5. CDittoWindow::CDittoWindow(void)
  6. {
  7. m_captionBorderWidth = theApp.m_metrics.ScaleX(25);
  8. m_lTopBorder = m_captionBorderWidth;
  9. m_lRightBorder = BORDER;
  10. m_lBottomBorder = BORDER;
  11. m_lLeftBorder = BORDER;
  12. m_bMouseOverChevron = false;
  13. m_bMouseDownOnChevron = false;
  14. m_bMouseDownOnClose = false;
  15. m_bMouseOverClose = false;
  16. m_bMouseDownOnMinimize = false;
  17. m_bMouseOverMinimize = false;
  18. m_bMouseDownOnMaximize = false;
  19. m_bMouseOverMaximize = false;
  20. m_bDrawClose = true;
  21. m_bDrawChevron = true;
  22. m_bDrawMaximize = true;
  23. m_bDrawMinimize = true;
  24. m_bMinimized = false;
  25. m_crCloseBT.SetRectEmpty();
  26. m_crChevronBT.SetRectEmpty();
  27. m_crMaximizeBT.SetRectEmpty();
  28. m_crMinimizeBT.SetRectEmpty();
  29. m_CaptionColorLeft = RGB(255, 255, 255);
  30. m_CaptionColorRight = RGB(204, 204, 204);
  31. m_CaptionTextColor = RGB(191, 191, 191);
  32. m_border = RGB(204, 204, 204);
  33. m_sendWMClose = true;
  34. m_customWindowTitle = _T("");
  35. m_useCustomWindowTitle = false;
  36. }
  37. CDittoWindow::~CDittoWindow(void)
  38. {
  39. }
  40. void CDittoWindow::DoCreate(CWnd *pWnd)
  41. {
  42. m_VertFont.CreateFont(theApp.m_metrics.PointsToPixels(18), 0, -900, 0, 400, FALSE, FALSE, 0, DEFAULT_CHARSET,
  43. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  44. DEFAULT_PITCH|FF_SWISS, _T("Segoe UI"));
  45. m_HorFont.CreateFont(theApp.m_metrics.PointsToPixels(18), 0, 0, 0, 500, FALSE, FALSE, 0, DEFAULT_CHARSET,
  46. OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
  47. DEFAULT_PITCH|FF_SWISS, _T("Segoe UI"));
  48. SetTitleTextHeight(pWnd);
  49. m_closeButton.LoadStdImageDPI(Close_Black_16_16, Close_Black_20_20, Close_Black_24_24, Close_Black_28, Close_Black_32_32, _T("PNG"));
  50. m_chevronRightButton.LoadStdImageDPI(ChevronRight_Black_16_16, ChevronRight_Black_20_20, ChevronRight_Black_24_24, ChevronRight_Black_28, ChevronRight_Black_32_32, _T("PNG"));
  51. m_chevronLeftButton.LoadStdImageDPI(ChevronLeft_Black_16_16, ChevronLeft_Black_20_20, ChevronLeft_Black_24_24, ChevronLeft_Black_28, ChevronLeft_Black_32_32, _T("PNG"));
  52. m_maximizeButton.LoadStdImageDPI(IDB_MAXIMIZE_16_16, maximize_20, maximize_24, maximize_28, maximize_32, _T("PNG"));
  53. m_minimizeButton.LoadStdImageDPI(minimize_16, minimize_20, minimize_24, minimize_28, minimize_32, _T("PNG"));
  54. //m_windowIcon.LoadStdImageDPI(NewWindowIcon_24_14, NewWindowIcon_30, NewWindowIcon_36, NewWindowIcon_48, _T("PNG"));
  55. }
  56. void CDittoWindow::DoNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  57. {
  58. //Decrease the client area
  59. lpncsp->rgrc[0].left += m_lLeftBorder;
  60. lpncsp->rgrc[0].top += m_lTopBorder;
  61. lpncsp->rgrc[0].right -= m_lRightBorder;
  62. lpncsp->rgrc[0].bottom -= m_lBottomBorder;
  63. }
  64. UINT CDittoWindow::DoNcHitTest(CWnd *pWnd, CPoint point)
  65. {
  66. CRect crWindow;
  67. pWnd->GetWindowRect(crWindow);
  68. if(crWindow.PtInRect(point) == false)
  69. {
  70. return -1;
  71. }
  72. int x = point.x - crWindow.left;
  73. int y = point.y - crWindow.top;
  74. CPoint myLocal(x, y);
  75. //http://stackoverflow.com/questions/521147/the-curious-problem-of-the-missing-wm-nclbuttonup-message-when-a-window-isnt-ma
  76. //workaround for l button up not coming after a lbutton down
  77. if (m_crCloseBT.PtInRect(myLocal) ||
  78. m_crChevronBT.PtInRect(myLocal) ||
  79. m_crMinimizeBT.PtInRect(myLocal) ||
  80. m_crMaximizeBT.PtInRect(myLocal))
  81. {
  82. return HTBORDER;;
  83. }
  84. if(m_bMinimized == false)
  85. {
  86. if ((point.y < crWindow.top + BORDER * 4) &&
  87. (point.x < crWindow.left + BORDER * 4))
  88. return HTTOPLEFT;
  89. else if ((point.y < crWindow.top + BORDER * 4) &&
  90. (point.x > crWindow.right - BORDER * 4))
  91. return HTTOPRIGHT;
  92. else if ((point.y > crWindow.bottom - BORDER * 4) &&
  93. (point.x > crWindow.right - BORDER * 4))
  94. return HTBOTTOMRIGHT;
  95. else if ((point.y > crWindow.bottom - BORDER * 4) &&
  96. (point.x < crWindow.left + BORDER * 4))
  97. return HTBOTTOMLEFT;
  98. }
  99. if((((m_lTopBorder == m_captionBorderWidth) || (m_lBottomBorder == m_captionBorderWidth)) &&
  100. (m_bMinimized)) == false)
  101. {
  102. if (point.y < crWindow.top + BORDER * 2)
  103. return HTTOP;
  104. if (point.y > crWindow.bottom - BORDER * 2)
  105. return HTBOTTOM;
  106. }
  107. if((((m_lLeftBorder == m_captionBorderWidth) || (m_lRightBorder == m_captionBorderWidth)) &&
  108. (m_bMinimized)) == false)
  109. {
  110. if (point.x > crWindow.right - BORDER * 2)
  111. return HTRIGHT;
  112. if (point.x < crWindow.left + BORDER * 2)
  113. return HTLEFT;
  114. }
  115. if(m_lRightBorder == m_captionBorderWidth)
  116. {
  117. if (point.x > crWindow.right - m_lRightBorder)
  118. return HTCAPTION;
  119. }
  120. else if(m_lBottomBorder == m_captionBorderWidth)
  121. {
  122. if(point.y > crWindow.bottom - m_lBottomBorder)
  123. return HTCAPTION;
  124. }
  125. else if(m_lLeftBorder == m_captionBorderWidth)
  126. {
  127. if (point.x < crWindow.left + m_lLeftBorder)
  128. return HTCAPTION;
  129. }
  130. else if(m_lTopBorder == m_captionBorderWidth)
  131. {
  132. if (point.y < crWindow.top + m_lTopBorder)
  133. return HTCAPTION;
  134. }
  135. return -1;
  136. }
  137. int IndexToPos(int index, bool horizontal)
  138. {
  139. switch (index)
  140. {
  141. case 0:
  142. if (horizontal)
  143. {
  144. return theApp.m_metrics.ScaleX(24);
  145. }
  146. else
  147. {
  148. return theApp.m_metrics.ScaleY(8);
  149. }
  150. break;
  151. case 1:
  152. if (horizontal)
  153. {
  154. return theApp.m_metrics.ScaleX(48);
  155. }
  156. else
  157. {
  158. return theApp.m_metrics.ScaleY(32);
  159. }
  160. break;
  161. case 2:
  162. if (horizontal)
  163. {
  164. return theApp.m_metrics.ScaleX(72);
  165. }
  166. else
  167. {
  168. return theApp.m_metrics.ScaleY(56);
  169. }
  170. break;
  171. case 3:
  172. if (horizontal)
  173. {
  174. return theApp.m_metrics.ScaleX(96);
  175. }
  176. else
  177. {
  178. return theApp.m_metrics.ScaleY(80);
  179. }
  180. break;
  181. case 4:
  182. if (horizontal)
  183. {
  184. return theApp.m_metrics.ScaleX(104);
  185. }
  186. else
  187. {
  188. return theApp.m_metrics.ScaleY(104);
  189. }
  190. break;
  191. }
  192. return 0;
  193. }
  194. void CDittoWindow::DoNcPaint(CWnd *pWnd)
  195. {
  196. CWindowDC dc(pWnd);
  197. CRect rcFrame;
  198. pWnd->GetWindowRect(rcFrame);
  199. pWnd->ScreenToClient(rcFrame);
  200. CRect rc;
  201. pWnd->GetClientRect(rc);
  202. pWnd->ClientToScreen(rc);
  203. long lWidth = rcFrame.Width();
  204. // Draw the window border
  205. CRect rcBorder(0, 0, lWidth, rcFrame.Height());
  206. int border = theApp.m_metrics.ScaleX(2);
  207. int widthHeight = theApp.m_metrics.ScaleX(16);
  208. for (int x = 0; x < border; x++)
  209. {
  210. dc.Draw3dRect(rcBorder, m_border, m_border);
  211. rcBorder.DeflateRect(1, 1, 1, 1);
  212. }
  213. int iconArea = 0;
  214. int index = 0;
  215. int closeIndex = 0;
  216. int chevronIndex = 0;
  217. int minIndex = 0;
  218. int maxIndex = 0;
  219. if (m_bDrawClose)
  220. {
  221. iconArea += theApp.m_metrics.ScaleX(32);
  222. closeIndex = index++;
  223. }
  224. if (m_bDrawChevron)
  225. {
  226. iconArea += theApp.m_metrics.ScaleX(32);
  227. chevronIndex = index++;
  228. }
  229. if (m_bDrawMaximize)
  230. {
  231. iconArea += theApp.m_metrics.ScaleX(32);
  232. maxIndex = index++;
  233. }
  234. if (m_bDrawMinimize)
  235. {
  236. iconArea += theApp.m_metrics.ScaleX(32);
  237. minIndex = index++;
  238. }
  239. CRect leftRect;
  240. CRect rightRect;
  241. CRect textRect;
  242. BOOL bVertical = FALSE;
  243. if(m_lRightBorder == m_captionBorderWidth)
  244. {
  245. rightRect.SetRect(rcBorder.right - (m_captionBorderWidth - border), rcBorder.top, rcBorder.right, rcBorder.top + IndexToPos(index, false));
  246. leftRect.SetRect(rcBorder.right - (m_captionBorderWidth - border), rcBorder.top + IndexToPos(index, false), rcBorder.right, rcBorder.bottom);
  247. textRect.SetRect(rcBorder.right, rightRect.bottom + theApp.m_metrics.ScaleX(10), rcBorder.right - m_captionBorderWidth, rcBorder.bottom - theApp.m_metrics.ScaleX(50));
  248. int left = rightRect.left;
  249. int right = rightRect.right;
  250. int top = IndexToPos(closeIndex, false);
  251. m_crCloseBT.SetRect(left, top, right, top+ widthHeight);
  252. top = IndexToPos(chevronIndex, false);
  253. m_crChevronBT.SetRect(left, top, right, top + widthHeight);
  254. top = IndexToPos(maxIndex, false);
  255. m_crMaximizeBT.SetRect(left, top, right, top + widthHeight);
  256. top = IndexToPos(minIndex, false);
  257. m_crMinimizeBT.SetRect(left, top, right, top + widthHeight);
  258. m_crWindowIconBT.SetRect(rcBorder.right - theApp.m_metrics.ScaleX(24), rcBorder.bottom - theApp.m_metrics.ScaleX(28), rcBorder.right - theApp.m_metrics.ScaleX(2), rcBorder.bottom);
  259. bVertical = TRUE;
  260. }
  261. else if(m_lLeftBorder == m_captionBorderWidth)
  262. {
  263. rightRect.SetRect(rcBorder.left, rcBorder.top, rcBorder.left + m_captionBorderWidth - border, rcBorder.top + IndexToPos(index, false));
  264. leftRect.SetRect(rcBorder.left, rcBorder.top + IndexToPos(index, false), rcBorder.left + m_captionBorderWidth - border, rcBorder.bottom);
  265. textRect.SetRect(rcBorder.left + m_captionBorderWidth - theApp.m_metrics.ScaleX(0), rightRect.bottom + theApp.m_metrics.ScaleX(10), rcBorder.left - theApp.m_metrics.ScaleX(5), rcBorder.bottom - theApp.m_metrics.ScaleX(50));
  266. int left = rightRect.left;
  267. int right = rightRect.right;
  268. int top = IndexToPos(closeIndex, false);
  269. m_crCloseBT.SetRect(left, top, right, top + widthHeight);
  270. top = IndexToPos(chevronIndex, false);
  271. m_crChevronBT.SetRect(left, top, right, top + widthHeight);
  272. top = IndexToPos(maxIndex, false);
  273. m_crMaximizeBT.SetRect(left, top, right, top + widthHeight);
  274. top = IndexToPos(minIndex, false);
  275. m_crMinimizeBT.SetRect(left, top, right, top + widthHeight);
  276. m_crWindowIconBT.SetRect(rcBorder.left + theApp.m_metrics.ScaleX(0), rcBorder.bottom - theApp.m_metrics.ScaleX(28), rcBorder.left + theApp.m_metrics.ScaleX(25), rcBorder.bottom);
  277. bVertical = TRUE;
  278. }
  279. else if(m_lTopBorder == m_captionBorderWidth)
  280. {
  281. leftRect.SetRect(rcBorder.left, rcBorder.top, rcBorder.right - IndexToPos(index-1, true)- theApp.m_metrics.ScaleX(8), m_captionBorderWidth);
  282. rightRect.SetRect(leftRect.right, rcBorder.top, rcBorder.right, m_captionBorderWidth);
  283. textRect.SetRect(leftRect.right, leftRect.top, leftRect.right, leftRect.bottom);
  284. int top = rightRect.top;
  285. int bottom = rightRect.bottom;
  286. int left = rcBorder.right - IndexToPos(closeIndex, true);
  287. m_crCloseBT.SetRect(left, top, left + widthHeight, bottom);
  288. left = rcBorder.right - IndexToPos(chevronIndex, true);
  289. m_crChevronBT.SetRect(left, top, left + widthHeight, bottom);
  290. left = rcBorder.right - IndexToPos(maxIndex, true);
  291. m_crMaximizeBT.SetRect(left, top, left + widthHeight, bottom);
  292. left = rcBorder.right - IndexToPos(minIndex, true);
  293. m_crMinimizeBT.SetRect(left, top, left + widthHeight, bottom);
  294. left = rcBorder.left + theApp.m_metrics.ScaleX(10);
  295. m_crWindowIconBT.SetRect(left, top, left + theApp.m_metrics.ScaleX(24), bottom);
  296. bVertical = FALSE;
  297. }
  298. else if(m_lBottomBorder == m_captionBorderWidth)
  299. {
  300. leftRect.SetRect(rcBorder.left, rcBorder.bottom- m_captionBorderWidth - border, rcBorder.right - IndexToPos(index - 1, true) - theApp.m_metrics.ScaleX(8), rcBorder.bottom);
  301. rightRect.SetRect(leftRect.right, rcBorder.bottom - m_captionBorderWidth - border, rcBorder.right, rcBorder.bottom);
  302. textRect.SetRect(leftRect.right, leftRect.top, leftRect.right, leftRect.bottom);
  303. int top = rightRect.top;
  304. int bottom = rightRect.bottom;
  305. int left = rcBorder.right - IndexToPos(closeIndex, true);
  306. m_crCloseBT.SetRect(left, top, left + widthHeight, bottom);
  307. left = rcBorder.right - IndexToPos(chevronIndex, true);
  308. m_crChevronBT.SetRect(left, top, left+ widthHeight, bottom);
  309. left = rcBorder.right - IndexToPos(maxIndex, true);
  310. m_crMaximizeBT.SetRect(left, top, left + widthHeight, bottom);
  311. left = rcBorder.right - IndexToPos(minIndex, true);
  312. m_crMinimizeBT.SetRect(left, top, left + widthHeight, bottom);
  313. left = rcBorder.left + theApp.m_metrics.ScaleX(10);
  314. m_crWindowIconBT.SetRect(left, top, left + theApp.m_metrics.ScaleX(24), bottom);
  315. bVertical = FALSE;
  316. }
  317. HBRUSH leftColor = CreateSolidBrush(m_CaptionColorLeft);
  318. HBRUSH rightColor = CreateSolidBrush(m_CaptionColorRight);
  319. ::FillRect(dc, &leftRect, leftColor);
  320. ::FillRect(dc, &rightRect, rightColor);
  321. DeleteObject(leftColor);
  322. DeleteObject(rightColor);
  323. int nOldBKMode = dc.SetBkMode(TRANSPARENT);
  324. COLORREF oldColor = dc.SetTextColor(m_CaptionTextColor);
  325. CFont *pOldFont = NULL;
  326. if (bVertical)
  327. pOldFont = dc.SelectObject(&m_VertFont);
  328. else
  329. pOldFont = dc.SelectObject(&m_HorFont);
  330. CString csText = m_customWindowTitle;
  331. if (m_useCustomWindowTitle == false)
  332. {
  333. pWnd->GetWindowText(csText);
  334. }
  335. int flags = DT_SINGLELINE;
  336. if (bVertical == false)
  337. {
  338. CRect size(0, 0, 0, 0);
  339. dc.DrawText(csText, size, DT_CALCRECT);
  340. textRect.left = textRect.right - size.Width() - theApp.m_metrics.ScaleX(10);
  341. flags |= DT_VCENTER;
  342. }
  343. else
  344. {
  345. CRect size(0, 0, 0, 0);
  346. dc.DrawText(csText, size, DT_CALCRECT| DT_SINGLELINE);
  347. int rectWidth = textRect.left - textRect.right;
  348. int offset = rectWidth / 2 - m_titleTextHeight / 2;
  349. //textRect.right += 30;
  350. //I don't understand where the 4 is coming from but it's always 4 pixals from the right so adjust for this
  351. textRect.left -= (offset - theApp.m_metrics.ScaleX(4));
  352. int k = 0;
  353. }
  354. dc.DrawText(csText, textRect, flags);
  355. dc.SelectObject(pOldFont);
  356. dc.SetBkMode(nOldBKMode);
  357. DrawWindowIcon(dc, pWnd);
  358. DrawChevronBtn(dc, pWnd);
  359. DrawCloseBtn(dc, pWnd);
  360. DrawMaximizeBtn(dc, pWnd);
  361. DrawMinimizeBtn(dc, pWnd);
  362. }
  363. void CDittoWindow::DoSetRegion(CWnd *pWnd)
  364. {
  365. return;
  366. //Create the region for drawing the rounded top edge
  367. CRect rect;
  368. CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
  369. pWnd->GetWindowRect(rect);
  370. if(rect.Width() < 0)
  371. return;
  372. CRect r;
  373. pWnd->GetClientRect(&r);
  374. int seven = theApp.m_metrics.ScaleX(7);
  375. int fifteen = theApp.m_metrics.ScaleX(15);
  376. int one = theApp.m_metrics.ScaleX(1);
  377. if((m_lRightBorder == m_captionBorderWidth) ||
  378. (m_lTopBorder == m_captionBorderWidth))
  379. {
  380. rgnRect.CreateRectRgn(0, 0, rect.Width() - seven, rect.Height());
  381. rgnRound.CreateRoundRectRgn(0, 0, rect.Width() + one, rect.Height(), fifteen, fifteen);
  382. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  383. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  384. rgnRect2.CreateRectRgn(0, seven, rect.Width(), rect.Height());
  385. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  386. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  387. //Set the region
  388. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  389. }
  390. else if(m_lLeftBorder == m_captionBorderWidth)
  391. {
  392. rgnRect.CreateRectRgn(0, seven, rect.Width(), rect.Height());
  393. rgnRound.CreateRoundRectRgn(0, 0, rect.Width(), rect.Height(), fifteen, fifteen);
  394. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  395. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  396. rgnRect2.CreateRectRgn(seven, 0, rect.Width(), rect.Height());
  397. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  398. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  399. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  400. }
  401. else if(m_lBottomBorder == m_captionBorderWidth)
  402. {
  403. rgnRect.CreateRectRgn(0, 0, rect.Width(), rect.Height() - seven);
  404. rgnRound.CreateRoundRectRgn(0, 0, rect.Width() + one, rect.Height() + one, fifteen, fifteen);
  405. rgnFinalB.CreateRectRgn(0, 0, 0, 0);
  406. rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
  407. rgnRect2.CreateRectRgn(0, 0, rect.Width() - fifteen, rect.Height());
  408. rgnFinalA.CreateRectRgn(0, 0, 0, 0);
  409. rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
  410. pWnd->SetWindowRgn(rgnFinalA, TRUE);
  411. }
  412. }
  413. void CDittoWindow::DrawChevronBtn(CWindowDC &dc, CWnd *pWnd)
  414. {
  415. if(m_bDrawChevron == false)
  416. {
  417. return;
  418. }
  419. if(this->m_bMinimized)
  420. {
  421. m_chevronLeftButton.Draw(&dc, pWnd, m_crChevronBT, m_bMouseOverChevron, m_bMouseDownOnChevron);
  422. }
  423. else
  424. {
  425. m_chevronRightButton.Draw(&dc, pWnd, m_crChevronBT, m_bMouseOverChevron, m_bMouseDownOnChevron);
  426. }
  427. }
  428. void CDittoWindow::DrawWindowIcon(CWindowDC &dc, CWnd *pWnd)
  429. {
  430. //m_windowIcon.Draw(&dc, pWnd, m_crWindowIconBT.left, m_crWindowIconBT.top, false, false);
  431. }
  432. void CDittoWindow::DrawCloseBtn(CWindowDC &dc, CWnd *pWnd)
  433. {
  434. if(m_bDrawClose == false)
  435. {
  436. return;
  437. }
  438. m_closeButton.Draw(&dc, pWnd, m_crCloseBT, m_bMouseOverClose, m_bMouseDownOnClose);
  439. }
  440. void CDittoWindow::DrawMinimizeBtn(CWindowDC &dc, CWnd *pWnd)
  441. {
  442. if(m_bDrawMinimize == false)
  443. {
  444. return;
  445. }
  446. m_minimizeButton.Draw(&dc, pWnd, m_crMinimizeBT, m_bMouseOverClose, m_bMouseDownOnClose);
  447. }
  448. void CDittoWindow::DrawMaximizeBtn(CWindowDC &dc, CWnd *pWnd)
  449. {
  450. if(m_bDrawMaximize == false)
  451. {
  452. return;
  453. }
  454. m_maximizeButton.Draw(&dc, pWnd, m_crMaximizeBT, m_bMouseOverMaximize, m_bMouseDownOnMaximize);
  455. }
  456. void CDittoWindow::DoNcLButtonDown(CWnd *pWnd, UINT nHitTest, CPoint point)
  457. {
  458. //ReleaseCapture();
  459. CPoint clPoint(point);
  460. pWnd->ScreenToClient(&clPoint);
  461. clPoint.x += m_lLeftBorder;
  462. clPoint.y += m_lTopBorder;
  463. if(m_crCloseBT.PtInRect(clPoint))
  464. {
  465. m_bMouseDownOnClose = true;
  466. //InvalidateRect(pWnd->m_hWnd, m_crCloseBT, TRUE);
  467. //pWnd->InvalidateRect(m_crCloseBT);
  468. //pWnd->UpdateWindow();
  469. //DoNcPaint(pWnd);
  470. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  471. }
  472. else if(m_crChevronBT.PtInRect(clPoint))
  473. {
  474. m_bMouseDownOnChevron = true;
  475. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  476. }
  477. else if(m_crMinimizeBT.PtInRect(clPoint))
  478. {
  479. m_bMouseDownOnMinimize = true;
  480. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  481. }
  482. else if(m_crMaximizeBT.PtInRect(clPoint))
  483. {
  484. m_bMouseDownOnMaximize = true;
  485. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  486. }
  487. else if(m_bMinimized)
  488. {
  489. //MinMaxWindow(FORCE_MAX);
  490. }
  491. }
  492. long CDittoWindow::DoNcLButtonUp(CWnd *pWnd, UINT nHitTest, CPoint point)
  493. {
  494. CRect crWindow;
  495. pWnd->GetWindowRect(crWindow);
  496. CPoint localPoint(point.x - crWindow.left, point.y - crWindow.top);
  497. long lRet = 0;
  498. if(m_bMouseDownOnClose)
  499. {
  500. m_bMouseDownOnClose = false;
  501. m_bMouseOverClose = false;
  502. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  503. if(m_crCloseBT.PtInRect(localPoint))
  504. {
  505. if(m_sendWMClose)
  506. {
  507. pWnd->SendMessage(WM_CLOSE, 0, 0);
  508. }
  509. lRet = BUTTON_CLOSE;
  510. }
  511. }
  512. else if(m_bMouseDownOnChevron)
  513. {
  514. m_bMouseDownOnChevron = false;
  515. m_bMouseOverChevron = false;
  516. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  517. if(m_crChevronBT.PtInRect(localPoint))
  518. {
  519. lRet = BUTTON_CHEVRON;
  520. }
  521. }
  522. else if(m_bMouseDownOnMinimize)
  523. {
  524. m_bMouseDownOnMinimize = false;
  525. m_bMouseOverMinimize = false;
  526. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  527. if(m_crMinimizeBT.PtInRect(localPoint))
  528. {
  529. pWnd->ShowWindow(SW_MINIMIZE);
  530. lRet = BUTTON_MINIMIZE;
  531. }
  532. }
  533. else if(m_bMouseDownOnMaximize)
  534. {
  535. m_bMouseDownOnMaximize = false;
  536. m_bMouseOverMaximize = false;
  537. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  538. if(m_crMaximizeBT.PtInRect(localPoint))
  539. {
  540. if(pWnd->GetStyle() & WS_MAXIMIZE)
  541. pWnd->ShowWindow(SW_RESTORE);
  542. else
  543. pWnd->ShowWindow(SW_SHOWMAXIMIZED);
  544. lRet = BUTTON_MAXIMIZE;
  545. }
  546. }
  547. return lRet;
  548. }
  549. void CDittoWindow::DoNcMouseMove(CWnd *pWnd, UINT nHitTest, CPoint point)
  550. {
  551. return;
  552. CRect crWindow;
  553. pWnd->GetWindowRect(crWindow);
  554. CPoint localPoint(point.x - crWindow.left, point.y - crWindow.top);
  555. if(m_crCloseBT.PtInRect(localPoint))
  556. {
  557. m_bMouseOverClose = true;
  558. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  559. }
  560. else if(m_bMouseOverClose)
  561. {
  562. m_bMouseOverClose = false;
  563. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  564. }
  565. if(m_crChevronBT.PtInRect(localPoint))
  566. {
  567. m_bMouseOverChevron = true;
  568. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  569. }
  570. else if(m_bMouseOverChevron)
  571. {
  572. m_bMouseOverChevron = false;
  573. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  574. }
  575. if(m_crMinimizeBT.PtInRect(localPoint))
  576. {
  577. m_bMouseOverMinimize = true;
  578. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  579. }
  580. else if(m_bMouseOverMinimize)
  581. {
  582. m_bMouseOverMinimize = false;
  583. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  584. }
  585. if(m_crMaximizeBT.PtInRect(localPoint))
  586. {
  587. m_bMouseOverMaximize = true;
  588. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  589. }
  590. else if(m_bMouseOverMaximize)
  591. {
  592. m_bMouseOverMaximize = false;
  593. RedrawWindow(pWnd->m_hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
  594. }
  595. }
  596. bool CDittoWindow::DoPreTranslateMessage(MSG* pMsg)
  597. {
  598. return true;
  599. }
  600. void CDittoWindow::SetCaptionOn(CWnd *pWnd, int nPos, bool bOnstartup, int captionSize, int captionFontSize)
  601. {
  602. m_VertFont.Detach();
  603. m_VertFont.CreateFont(theApp.m_metrics.PointsToPixels(captionFontSize), 0, -900, 0, 400, FALSE, FALSE, 0, DEFAULT_CHARSET,
  604. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  605. DEFAULT_PITCH | FF_SWISS, _T("Segoe UI"));
  606. m_HorFont.Detach();
  607. m_HorFont.CreateFont(theApp.m_metrics.PointsToPixels(captionFontSize), 0, 0, 0, 500, FALSE, FALSE, 0, DEFAULT_CHARSET,
  608. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  609. DEFAULT_PITCH | FF_SWISS, _T("Segoe UI"));
  610. SetTitleTextHeight(pWnd);
  611. m_lTopBorder = BORDER;
  612. m_lRightBorder = BORDER;
  613. m_lBottomBorder = BORDER;
  614. m_lLeftBorder = BORDER;
  615. int oldWidth = m_captionBorderWidth;
  616. m_captionBorderWidth = theApp.m_metrics.ScaleX(captionSize);
  617. if(nPos == CAPTION_RIGHT)
  618. m_lRightBorder = m_captionBorderWidth;
  619. if(nPos == CAPTION_BOTTOM)
  620. m_lBottomBorder = m_captionBorderWidth;
  621. if(nPos == CAPTION_LEFT)
  622. m_lLeftBorder = m_captionBorderWidth;
  623. if(nPos == CAPTION_TOP)
  624. m_lTopBorder = m_captionBorderWidth;
  625. DoSetRegion(pWnd);
  626. if(!bOnstartup)
  627. {
  628. pWnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  629. }
  630. pWnd->Invalidate();
  631. pWnd->RedrawWindow();
  632. if (oldWidth != m_captionBorderWidth)
  633. {
  634. ::SetWindowPos(pWnd->m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  635. }
  636. }
  637. void CDittoWindow::SetTitleTextHeight(CWnd *pWnd)
  638. {
  639. CWindowDC dc(pWnd);
  640. CFont *pOldFont = dc.SelectObject(&m_HorFont);
  641. CRect size(0, 0, 0, 0);
  642. dc.DrawText(_T("W"), size, DT_CALCRECT);
  643. m_titleTextHeight = size.Height();
  644. dc.SelectObject(pOldFont);
  645. }
  646. bool CDittoWindow::SetCaptionColors(COLORREF left, COLORREF right, COLORREF border)
  647. {
  648. m_CaptionColorLeft = left;
  649. m_CaptionColorRight = right;
  650. m_border = border;
  651. return true;
  652. }
  653. void CDittoWindow::SetCaptionTextColor(COLORREF color)
  654. {
  655. m_CaptionTextColor = color;
  656. }