SymbolEdit.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. // AeroEdit.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SymbolEdit.h"
  5. #include "cp_main.h"
  6. #include "QListCtrl.h"
  7. #include "Shared\TextConvert.h"
  8. // CSymbolEdit
  9. #define RANGE_START 3000
  10. #define CLEAR_LIST 3050
  11. #define LIST_MAX_COUNT 50
  12. #define MAX_SAVED_SEARCH_LENGTH 1000
  13. IMPLEMENT_DYNAMIC(CSymbolEdit, CEdit)
  14. CSymbolEdit::CSymbolEdit() :
  15. m_hSymbolIcon(NULL),
  16. m_bInternalIcon(false),
  17. m_colorPromptText(RGB(127, 127, 127)),
  18. m_centerTextDiff(0)
  19. {
  20. m_fontPrompt.CreateFont(
  21. 16, // nHeight
  22. 0, // nWidth
  23. 0, // nEscapement
  24. 0, // nOrientation
  25. FW_NORMAL, // nWeight
  26. TRUE, // bItalic
  27. FALSE, // bUnderline
  28. 0, // cStrikeOut
  29. DEFAULT_CHARSET, // nCharSet
  30. OUT_DEFAULT_PRECIS, // nOutPrecision
  31. CLIP_DEFAULT_PRECIS, // nClipPrecision
  32. DEFAULT_QUALITY, // nQuality
  33. DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
  34. _T("Calibri"));
  35. m_mouseDownOnSearches = false;
  36. m_mouseHoveringOverSearches = false;
  37. m_mouseDownOnClose = false;
  38. m_mouseHoveringOverClose = false;
  39. m_windowDpi = NULL;
  40. //m_searchButton.LoadStdImageDPI(Search_16, Search_20, Search_24, Search_32, _T("PNG"));
  41. }
  42. CSymbolEdit::~CSymbolEdit()
  43. {
  44. DestroyIcon();
  45. }
  46. BEGIN_MESSAGE_MAP(CSymbolEdit, CEdit)
  47. ON_WM_PAINT()
  48. ON_MESSAGE(WM_SETFONT, OnSetFont)
  49. //ON_MESSAGE(WM_EXITMENULOOP, OnMenuExit)
  50. ON_WM_CTLCOLOR_REFLECT()
  51. ON_WM_SETFOCUS()
  52. ON_WM_KILLFOCUS()
  53. ON_WM_SETCURSOR()
  54. ON_WM_LBUTTONUP()
  55. ON_WM_LBUTTONDOWN()
  56. ON_WM_MOUSEMOVE()
  57. ON_COMMAND_RANGE(RANGE_START, (RANGE_START+ LIST_MAX_COUNT), OnSelectSearchString)
  58. ON_WM_EXITSIZEMOVE()
  59. //ON_WM_ERASEBKGND()
  60. ON_WM_NCCALCSIZE()
  61. ON_WM_NCPAINT()
  62. ON_WM_TIMER()
  63. END_MESSAGE_MAP()
  64. BOOL CSymbolEdit::PreTranslateMessage(MSG* pMsg)
  65. {
  66. // TODO: Add your specialized code here and/or call the base class
  67. // Intercept Ctrl + Z (Undo), Ctrl + X (Cut), Ctrl + C (Copy), Ctrl + V (Paste) and Ctrl + A (Select All)
  68. // before CEdit base class gets a hold of them.
  69. if (pMsg->message == WM_KEYDOWN &&
  70. CONTROL_PRESSED)
  71. {
  72. switch (pMsg->wParam)
  73. {
  74. case 'Z':
  75. Undo();
  76. return TRUE;
  77. case 'X':
  78. Cut();
  79. return TRUE;
  80. case 'C':
  81. {
  82. int startChar;
  83. int endChar;
  84. this->GetSel(startChar, endChar);
  85. if (startChar == endChar)
  86. {
  87. CWnd *pWnd = GetParent();
  88. if (pWnd)
  89. {
  90. pWnd->SendMessage(NM_COPY_CLIP, pMsg->wParam, pMsg->lParam);
  91. }
  92. }
  93. else
  94. {
  95. Copy();
  96. }
  97. }
  98. return TRUE;
  99. case 'V':
  100. Paste();
  101. return TRUE;
  102. case 'A':
  103. SetSel(0, -1);
  104. return TRUE;
  105. }
  106. }
  107. switch (pMsg->message)
  108. {
  109. case WM_KEYDOWN:
  110. {
  111. if (pMsg->wParam == VK_RETURN)
  112. {
  113. CWnd *pWnd = GetParent();
  114. if (pWnd)
  115. {
  116. if (g_Opt.m_bFindAsYouType)
  117. {
  118. pWnd->SendMessage(NM_SEARCH_ENTER_PRESSED, 0, 0);
  119. }
  120. else
  121. {
  122. //Send a message to the parent to refill the lb from the search
  123. pWnd->PostMessage(CB_SEARCH, 0, 0);
  124. }
  125. AddToSearchHistory();
  126. }
  127. return TRUE;
  128. }
  129. else if (pMsg->wParam == VK_DOWN &&
  130. ((GetKeyState(VK_CONTROL) & 0x8000) || ((GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_SHIFT) & 0x8000))))
  131. {
  132. if (ShowSearchHistoryMenu())
  133. {
  134. return TRUE;
  135. }
  136. }
  137. else if (pMsg->wParam == VK_DOWN ||
  138. pMsg->wParam == VK_UP ||
  139. pMsg->wParam == VK_PRIOR ||
  140. pMsg->wParam == VK_NEXT)
  141. {
  142. CWnd *pWnd = GetParent();
  143. if (pWnd)
  144. {
  145. pWnd->SendMessage(CB_UPDOWN, pMsg->wParam, pMsg->lParam);
  146. return TRUE;
  147. }
  148. }
  149. else if (pMsg->wParam == VK_DELETE)
  150. {
  151. int startChar;
  152. int endChar;
  153. this->GetSel(startChar, endChar);
  154. CString cs;
  155. this->GetWindowText(cs);
  156. //if selection is at the end then forward this on to the parent to delete the selected clip
  157. if(startChar == cs.GetLength() &&
  158. endChar == cs.GetLength())
  159. {
  160. CWnd *pWnd = GetParent();
  161. if (pWnd)
  162. {
  163. pWnd->SendMessage(NM_DELETE, pMsg->wParam, pMsg->lParam);
  164. return TRUE;
  165. }
  166. }
  167. }
  168. break;
  169. }
  170. }
  171. return CEdit::PreTranslateMessage(pMsg);
  172. }
  173. CString CSymbolEdit::SavePastSearches()
  174. {
  175. TiXmlDocument doc;
  176. TiXmlElement* outer = new TiXmlElement("PastSearches");
  177. doc.LinkEndChild(outer);
  178. int count = (int)m_searches.GetCount();
  179. for (int i = 0; i < count; i++)
  180. {
  181. TiXmlElement* searchElement = new TiXmlElement("Search");
  182. CStringA t;
  183. CTextConvert::ConvertToUTF8(m_searches[i], t);
  184. searchElement->SetAttribute("text", t);
  185. outer->LinkEndChild(searchElement);
  186. }
  187. TiXmlPrinter printer;
  188. printer.SetLineBreak("");
  189. doc.Accept(&printer);
  190. CString cs = printer.CStr();
  191. return cs;
  192. }
  193. void CSymbolEdit::LoadPastSearches(CString values)
  194. {
  195. m_searches.RemoveAll();
  196. TiXmlDocument doc;
  197. CStringA xmlA;
  198. CTextConvert::ConvertToUTF8(values, xmlA);
  199. doc.Parse(xmlA);
  200. TiXmlElement *ItemHeader = doc.FirstChildElement("PastSearches");
  201. if (ItemHeader != NULL)
  202. {
  203. TiXmlElement *ItemElement = ItemHeader->FirstChildElement();
  204. while (ItemElement)
  205. {
  206. CString item = ItemElement->Attribute("text");
  207. CString toAdd = item.Left(MAX_SAVED_SEARCH_LENGTH);
  208. if (toAdd != _T(""))
  209. {
  210. m_searches.Add(toAdd);
  211. }
  212. ItemElement = ItemElement->NextSiblingElement();
  213. }
  214. }
  215. }
  216. void CSymbolEdit::AddToSearchHistory()
  217. {
  218. CString cs;
  219. this->GetWindowText(cs);
  220. if (cs != _T(""))
  221. {
  222. //only save up to 1000, had reports of somehow getting extremely large amounts of junk text
  223. //save and causing memory issues.
  224. cs = cs.Left(MAX_SAVED_SEARCH_LENGTH);
  225. if (m_searches.GetCount() >= LIST_MAX_COUNT)
  226. {
  227. m_searches.RemoveAt(0);
  228. }
  229. bool existing = false;
  230. int count = (int)m_searches.GetCount();
  231. for (int i = 0; i < count; i++)
  232. {
  233. if (m_searches[i] == cs)
  234. {
  235. m_searches.RemoveAt(i);
  236. m_searches.Add(cs);
  237. existing = true;
  238. break;
  239. }
  240. }
  241. if (existing == false)
  242. {
  243. m_searches.Add(cs);
  244. }
  245. }
  246. }
  247. bool CSymbolEdit::ShowSearchHistoryMenu()
  248. {
  249. if (m_searches.GetCount() == 0)
  250. {
  251. return false;
  252. }
  253. CMenu cmPopUp;
  254. cmPopUp.CreatePopupMenu();
  255. int count = min((int)m_searches.GetCount(), LIST_MAX_COUNT);
  256. for (int i = count-1; i >= 0; i--)
  257. {
  258. CString text = m_searches[i];
  259. if (i == count - 1 &&
  260. m_lastSearchShortCut.Key > 0)
  261. {
  262. CString cmdShortcutText = CHotKey::GetHotKeyDisplayStatic(m_lastSearchShortCut.Key);
  263. if (m_lastSearchShortCut.Key2 != 0)
  264. {
  265. CString cmdShortcutText2 = CHotKey::GetHotKeyDisplayStatic(m_lastSearchShortCut.Key2);
  266. if (cmdShortcutText2.GetLength() > 0)
  267. {
  268. cmdShortcutText += _T(" - ");
  269. cmdShortcutText += cmdShortcutText2;
  270. }
  271. }
  272. text += "\t";
  273. text += cmdShortcutText;
  274. }
  275. cmPopUp.AppendMenuW(MF_STRING, (RANGE_START + i), text);
  276. }
  277. cmPopUp.AppendMenu(MF_SEPARATOR);
  278. cmPopUp.AppendMenuW(MF_STRING, CLEAR_LIST, _T("Clear List"));
  279. CRect windowRect;
  280. this->GetWindowRect(&windowRect);
  281. POINT pp;
  282. GetCursorPos(&pp);
  283. POINT x = this->GetCaretPos();
  284. ClientToScreen(&x);
  285. x.y += windowRect.Height();
  286. cmPopUp.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x.x, x.y, this, NULL);
  287. Invalidate();
  288. return true;
  289. }
  290. void CSymbolEdit::DestroyIcon()
  291. {
  292. // if icon was loaded internally, destroy it
  293. if (m_bInternalIcon || m_hSymbolIcon != NULL)
  294. ::DestroyIcon(m_hSymbolIcon);
  295. }
  296. void CSymbolEdit::PreSubclassWindow()
  297. {
  298. RecalcLayout();
  299. }
  300. void CSymbolEdit::SetSymbolIcon(HICON hIcon, BOOL redraw)
  301. {
  302. DestroyIcon();
  303. m_hSymbolIcon = hIcon;
  304. // icon was not loaded internally
  305. m_bInternalIcon = false;
  306. RecalcLayout();
  307. if (redraw)
  308. Invalidate(TRUE);
  309. }
  310. void CSymbolEdit::SetSymbolIcon(UINT id, BOOL redraw)
  311. {
  312. DestroyIcon();
  313. m_hSymbolIcon = (HICON)::LoadImage(
  314. AfxGetResourceHandle(),
  315. MAKEINTRESOURCE(id),
  316. IMAGE_ICON,
  317. 16,
  318. 16,
  319. LR_DEFAULTCOLOR | LR_LOADTRANSPARENT);
  320. ASSERT(m_hSymbolIcon != NULL);
  321. // icon was loaded internally
  322. m_bInternalIcon = true;
  323. RecalcLayout();
  324. if (redraw)
  325. Invalidate(TRUE);
  326. }
  327. void CSymbolEdit::SetPromptText(CString text, BOOL redraw)
  328. {
  329. m_strPromptText = text;
  330. if (redraw)
  331. Invalidate(TRUE);
  332. }
  333. void CSymbolEdit::SetPromptText(LPCTSTR szText, BOOL redraw)
  334. {
  335. m_strPromptText = szText;
  336. if (redraw)
  337. Invalidate(TRUE);
  338. }
  339. void CSymbolEdit::SetPromptTextColor(COLORREF color, BOOL redraw)
  340. {
  341. m_colorPromptText = color;
  342. if (redraw)
  343. Invalidate(TRUE);
  344. }
  345. void CSymbolEdit::SetPromptFont(CFont& font, BOOL redraw)
  346. {
  347. LOGFONT lf;
  348. memset(&lf, 0, sizeof(LOGFONT));
  349. font.GetLogFont(&lf);
  350. SetPromptFont(&lf);
  351. if (redraw)
  352. Invalidate(TRUE);
  353. }
  354. void CSymbolEdit::SetPromptFont(const LOGFONT* lpLogFont, BOOL redraw)
  355. {
  356. m_fontPrompt.DeleteObject();
  357. m_fontPrompt.CreateFontIndirect(lpLogFont);
  358. if (redraw)
  359. Invalidate(TRUE);
  360. }
  361. void CSymbolEdit::RecalcLayout()
  362. {
  363. int width = GetSystemMetrics(SM_CXSMICON);
  364. if (m_hSymbolIcon)
  365. {
  366. DWORD dwMargins = GetMargins();
  367. SetMargins(LOWORD(dwMargins), width + 6);
  368. }
  369. else
  370. {
  371. if (m_windowDpi != NULL)
  372. {
  373. SetMargins(m_windowDpi->Scale(4), m_windowDpi->Scale(34));
  374. }
  375. }
  376. }
  377. void CSymbolEdit::OnPaint()
  378. {
  379. CPaintDC dc(this);
  380. CRect rect;
  381. GetClientRect(&rect);
  382. DWORD margins = GetMargins();
  383. CRect textRect(rect);
  384. textRect.left += LOWORD(margins);
  385. textRect.right -= HIWORD(margins);
  386. // Clearing the background
  387. dc.FillSolidRect(rect, GetSysColor(COLOR_WINDOW));
  388. if (m_hSymbolIcon)
  389. {
  390. // Drawing the icon
  391. int width = GetSystemMetrics(SM_CXSMICON);
  392. int height = GetSystemMetrics(SM_CYSMICON);
  393. ::DrawIconEx(
  394. dc.m_hDC,
  395. rect.right - width - 1,
  396. 1,
  397. m_hSymbolIcon,
  398. width,
  399. height,
  400. 0,
  401. NULL,
  402. DI_NORMAL);
  403. rect.left += LOWORD(margins) + 1;
  404. rect.right -= (width + 7);
  405. }
  406. else
  407. {
  408. //rect.left += (LOWORD(dwMargins) + 1);
  409. //rect.right -= (HIWORD(dwMargins) + 1);
  410. }
  411. CString text;
  412. GetWindowText(text);
  413. CFont* oldFont = NULL;
  414. //rect.top += 1;
  415. if(this == GetFocus() || text.GetLength() > 0)
  416. {
  417. dc.FillSolidRect(rect, g_Opt.m_Theme.SearchTextBoxFocusBG());
  418. //CBrush borderBrush(g_Opt.m_Theme.SearchTextBoxFocusBorder());
  419. //dc.FrameRect(rect, &borderBrush);
  420. //rect.DeflateRect(1, 1, 1, 1);
  421. //textRect.DeflateRect(0, 1, 1, 1);
  422. oldFont = dc.SelectObject(GetFont());
  423. COLORREF oldColor = dc.GetTextColor();
  424. dc.SetTextColor(g_Opt.m_Theme.SearchTextBoxFocusText());
  425. dc.DrawText(text, textRect, DT_SINGLELINE | DT_INTERNAL | DT_EDITCONTROL | DT_NOPREFIX);
  426. dc.SelectObject(oldFont);
  427. dc.SetTextColor(oldColor);
  428. }
  429. else
  430. {
  431. dc.FillSolidRect(rect, g_Opt.m_Theme.MainWindowBG());
  432. }
  433. if (text.GetLength() == 0 && m_strPromptText.GetLength() > 0)
  434. {
  435. //if we aren't showing the close icon, then use the full space
  436. textRect.right += m_windowDpi->Scale(16);
  437. //textRect.right -= LOWORD(margins);
  438. oldFont = dc.SelectObject(&m_fontPrompt);
  439. COLORREF color = dc.GetTextColor();
  440. dc.SetTextColor(m_colorPromptText);
  441. dc.DrawText(m_strPromptText, textRect, DT_LEFT | DT_SINGLELINE | DT_EDITCONTROL | DT_VCENTER | DT_NOPREFIX);
  442. dc.SetTextColor(color);
  443. dc.SelectObject(oldFont);
  444. }
  445. int right = rect.right;
  446. if ((text.GetLength() > 0 || this == GetFocus()))
  447. {
  448. m_searchesButtonRect.SetRect(rect.right - m_windowDpi->Scale(18), 0, rect.right, rect.bottom);
  449. right = rect.right - m_windowDpi->Scale(18);
  450. m_searchesButton.Draw(&dc, *m_windowDpi, this, m_searchesButtonRect.left, 4, m_mouseHoveringOverSearches, m_mouseDownOnSearches);
  451. }
  452. else
  453. {
  454. m_searchesButtonRect.SetRect(0, 0, 0, 0);
  455. //m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
  456. }
  457. if (text.GetLength() > 0)
  458. {
  459. OutputDebugString(_T("showing close button\n"));
  460. m_closeButtonRect.SetRect(right - m_windowDpi->Scale(16), 0, right, rect.bottom);
  461. m_closeButton.Draw(&dc, *m_windowDpi, this, m_closeButtonRect.left, 4, m_mouseHoveringOverClose, m_mouseDownOnClose);
  462. }
  463. else
  464. {
  465. OutputDebugString(_T("not showing close button\n"));
  466. m_closeButtonRect.SetRect(0, 0, 0, 0);
  467. //m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
  468. }
  469. //OutputDebugString(_T("OnPaint"));
  470. if (text != m_lastTextOnPaint &&
  471. text == _T(""))
  472. {
  473. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  474. }
  475. m_lastTextOnPaint = text;
  476. OutputDebugString(_T("OnPaint \r\n"));
  477. }
  478. void CSymbolEdit::OnSize(UINT nType, int cx, int cy)
  479. {
  480. CEdit::OnSize(nType, cx, cy);
  481. RecalcLayout();
  482. }
  483. LRESULT CSymbolEdit::OnSetFont(WPARAM wParam, LPARAM lParam)
  484. {
  485. DefWindowProc(WM_SETFONT, wParam, lParam);
  486. RecalcLayout();
  487. return 0;
  488. }
  489. HBRUSH CSymbolEdit::CtlColor(CDC* pDC, UINT n)
  490. {
  491. OutputDebugString(_T("CtlColor \r\n"));
  492. if (::GetFocus() == m_hWnd)
  493. {
  494. pDC->SetTextColor(g_Opt.m_Theme.SearchTextBoxFocusText());
  495. pDC->SetBkColor(g_Opt.m_Theme.SearchTextBoxFocusBG());
  496. return CreateSolidBrush(g_Opt.m_Theme.SearchTextBoxFocusBG());
  497. }
  498. else
  499. {
  500. pDC->SetBkColor(g_Opt.m_Theme.MainWindowBG());
  501. return CreateSolidBrush(g_Opt.m_Theme.MainWindowBG());
  502. }
  503. }
  504. void CSymbolEdit::OnSetFocus(CWnd* pOldWnd)
  505. {
  506. OutputDebugString(_T("OnSetFocus \r\n"));
  507. //was seeing issues when refreshing non client area inline, do it delayed
  508. SetTimer(1, 500, NULL);
  509. CWnd *pWnd = GetParent();
  510. if (pWnd)
  511. {
  512. if (g_Opt.m_bFindAsYouType)
  513. {
  514. pWnd->SendMessage(NM_FOCUS_ON_SEARCH, 0, 0);
  515. }
  516. }
  517. CEdit::OnSetFocus(pOldWnd);
  518. }
  519. void CSymbolEdit::OnKillFocus(CWnd* pNewWnd)
  520. {
  521. OutputDebugString(_T("OnKillFocus \r\n"));
  522. AddToSearchHistory();
  523. //was seeing issues when refreshing non client area inline, do it delayed
  524. SetTimer(1, 500, NULL);
  525. CEdit::OnKillFocus(pNewWnd);
  526. }
  527. BOOL CSymbolEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  528. {
  529. CPoint pntCursor;
  530. GetCursorPos(&pntCursor);
  531. ScreenToClient(&pntCursor);
  532. if(m_closeButtonRect.PtInRect(pntCursor))
  533. {
  534. HCURSOR h = ::LoadCursor(NULL, IDC_ARROW);
  535. ::SetCursor(h);
  536. return TRUE;
  537. }
  538. if (m_searchesButtonRect.PtInRect(pntCursor))
  539. {
  540. HCURSOR h = ::LoadCursor(NULL, IDC_ARROW);
  541. ::SetCursor(h);
  542. return TRUE;
  543. }
  544. return CEdit::OnSetCursor(pWnd, nHitTest, message);
  545. }
  546. void CSymbolEdit::OnLButtonUp(UINT nFlags, CPoint point)
  547. {
  548. if (m_mouseDownOnClose)
  549. {
  550. ReleaseCapture();
  551. InvalidateRect(m_closeButtonRect);
  552. }
  553. if (m_mouseDownOnSearches)
  554. {
  555. ReleaseCapture();
  556. InvalidateRect(m_searchesButtonRect);
  557. }
  558. m_mouseDownOnClose = false;
  559. m_mouseDownOnSearches = false;
  560. if (m_closeButtonRect.PtInRect(point))
  561. {
  562. if ((GetWindowTextLength() > 0))
  563. {
  564. CWnd *pOwner = GetOwner();
  565. if (pOwner)
  566. {
  567. pOwner->SendMessage(NM_CANCEL_SEARCH, 0, 0);
  568. }
  569. }
  570. }
  571. if (m_searchesButtonRect.PtInRect(point))
  572. {
  573. this->ShowSearchHistoryMenu();
  574. }
  575. CEdit::OnLButtonUp(nFlags, point);
  576. }
  577. void CSymbolEdit::OnLButtonDown(UINT nFlags, CPoint point)
  578. {
  579. if (m_closeButtonRect.PtInRect(point))
  580. {
  581. m_mouseDownOnClose = true;
  582. SetCapture();
  583. InvalidateRect(m_closeButtonRect);
  584. }
  585. else
  586. {
  587. m_mouseDownOnClose = false;
  588. }
  589. if (m_searchesButtonRect.PtInRect(point))
  590. {
  591. m_mouseDownOnSearches = true;
  592. SetCapture();
  593. InvalidateRect(m_searchesButtonRect);
  594. }
  595. else
  596. {
  597. m_mouseDownOnSearches = false;
  598. }
  599. CEdit::OnLButtonDown(nFlags, point);
  600. Invalidate();
  601. }
  602. void CSymbolEdit::OnMouseMove(UINT nFlags, CPoint point)
  603. {
  604. if (m_closeButtonRect.PtInRect(point))
  605. {
  606. if (m_mouseHoveringOverClose == false)
  607. {
  608. m_mouseHoveringOverClose = true;
  609. InvalidateRect(m_closeButtonRect);
  610. }
  611. }
  612. else if(m_mouseHoveringOverClose)
  613. {
  614. m_mouseHoveringOverClose = false;
  615. InvalidateRect(m_closeButtonRect);
  616. }
  617. if (m_searchesButtonRect.PtInRect(point))
  618. {
  619. if (m_mouseHoveringOverSearches == false)
  620. {
  621. m_mouseHoveringOverSearches = true;
  622. InvalidateRect(m_searchesButtonRect);
  623. }
  624. }
  625. else if (m_mouseHoveringOverSearches)
  626. {
  627. m_mouseHoveringOverSearches = false;
  628. InvalidateRect(m_searchesButtonRect);
  629. }
  630. CEdit::OnMouseMove(nFlags, point);
  631. }
  632. void CSymbolEdit::OnSelectSearchString(UINT idIn)
  633. {
  634. int index = idIn - RANGE_START;
  635. if (idIn == CLEAR_LIST)
  636. {
  637. m_searches.RemoveAll();
  638. }
  639. else if (index >= 0 &&
  640. index < m_searches.GetCount())
  641. {
  642. CString cs = m_searches[index];
  643. this->SetWindowTextW(cs);
  644. this->SetFocus();
  645. this->SetSel(-1);
  646. this->Invalidate();
  647. m_searches.RemoveAt(index);
  648. m_searches.Add(cs);
  649. }
  650. }
  651. bool CSymbolEdit::ApplyLastSearch()
  652. {
  653. bool ret = false;
  654. if (m_searches.GetCount() > 0)
  655. {
  656. CString cs = m_searches[m_searches.GetCount()-1];
  657. this->SetWindowTextW(cs);
  658. this->SetFocus();
  659. this->SetSel(-1);
  660. this->Invalidate();
  661. ret = true;
  662. }
  663. return ret;
  664. }
  665. void CSymbolEdit::OnDpiChanged()
  666. {
  667. SetDpiInfo(m_windowDpi);
  668. }
  669. void CSymbolEdit::SetDpiInfo(CDPI *dpi)
  670. {
  671. m_windowDpi = dpi;
  672. m_closeButton.Reset();
  673. m_closeButton.LoadStdImageDPI(m_windowDpi->GetDPI(), search_close_16, search_close_20, search_close_24, search_close_28, search_close_32, _T("PNG"));
  674. m_searchesButton.Reset();
  675. m_searchesButton.LoadStdImageDPI(m_windowDpi->GetDPI(), down_16, down_20, down_24, down_28, down_32, _T("PNG"));
  676. RecalcLayout();
  677. Invalidate();
  678. }
  679. BOOL CSymbolEdit::OnEraseBkgnd(CDC* pDC)
  680. {
  681. // TODO: Add your message handler code here and/or call default
  682. //return CEdit::OnEraseBkgnd(pDC);
  683. return FALSE;
  684. }
  685. void CSymbolEdit::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
  686. {
  687. CString text;
  688. GetWindowText(text);
  689. //if (text.GetLength() > 0 || this == GetFocus())
  690. if (m_windowDpi != NULL)
  691. {
  692. lpncsp->rgrc[0].left += m_windowDpi->Scale(1);
  693. lpncsp->rgrc[0].top += m_windowDpi->Scale(1);
  694. lpncsp->rgrc[0].right -= m_windowDpi->Scale(1);
  695. lpncsp->rgrc[0].bottom -= m_windowDpi->Scale(1);
  696. CRect rectWnd, rectClient;
  697. ////calculate client area height needed for a font
  698. CFont *pFont = GetFont();
  699. CRect rectText;
  700. CDC *pDC = GetDC();
  701. CFont *pOld = pDC->SelectObject(pFont);
  702. pDC->DrawText("Ky", rectText, DT_CALCRECT | DT_LEFT);
  703. UINT uiVClientHeight = rectText.Height();
  704. pDC->SelectObject(pOld);
  705. ReleaseDC(pDC);
  706. ////calculate NC area to center text.
  707. //GetClientRect(rectClient);
  708. GetWindowRect(rectWnd);
  709. rectWnd.DeflateRect(m_windowDpi->Scale(1), m_windowDpi->Scale(1));
  710. m_centerTextDiff = (rectWnd.Height() - uiVClientHeight) / 2;
  711. if (m_centerTextDiff < 0 || m_centerTextDiff > uiVClientHeight)
  712. {
  713. m_centerTextDiff = 0;
  714. }
  715. lpncsp->rgrc[0].top += m_centerTextDiff;
  716. lpncsp->rgrc[0].bottom -= m_centerTextDiff;
  717. }
  718. //ClientToScreen(rectClient);
  719. //UINT uiCenterOffset = (rectWnd.Height() - uiVClientHeight) / 2;
  720. //UINT uiCY = (rectWnd.Heig%ht() - rectClient.Height()) / 2;
  721. //UINT uiCX = (rectWnd.Width() - rectClient.Width()) / 2;
  722. //rectWnd.OffsetRect(-rectWnd.left, -rectWnd.top);
  723. //m_rectNCTop = rectWnd;
  724. //m_rectNCTop.DeflateRect(uiCX, uiCY, uiCX, uiCenterOffset + uiVClientHeight + uiCY);
  725. //m_rectNCBottom = rectWnd;
  726. //m_rectNCBottom.DeflateRect(uiCX, uiCenterOffset + uiVClientHeight + uiCY, uiCX, uiCY);
  727. //lpncsp->rgrc[0].top += uiCenterOffset;
  728. //lpncsp->rgrc[0].bottom -= uiCenterOffset;
  729. //lpncsp->rgrc[0].left += uiCX;
  730. //lpncsp->rgrc[0].right -= uiCY;
  731. //CEdit::OnNcCalcSize(bCalcValidRects, lpncsp);
  732. }
  733. void CSymbolEdit::OnNcPaint()
  734. {
  735. CString text;
  736. GetWindowText(text);
  737. CWindowDC dc(this);
  738. CRect r;
  739. this->GetWindowRect(r);
  740. this->ScreenToClient(r);
  741. CRect t(0, 0, r.Width(), m_centerTextDiff+ m_windowDpi->Scale(1));
  742. CRect b(0, r.Height() - m_centerTextDiff- m_windowDpi->Scale(1), r.Width(), r.Height());
  743. COLORREF c = g_Opt.m_Theme.MainWindowBG();
  744. if (this == GetFocus() || text.GetLength() > 0)
  745. {
  746. dc.FillSolidRect(t, g_Opt.m_Theme.SearchTextBoxFocusBG());
  747. dc.FillSolidRect(b, g_Opt.m_Theme.SearchTextBoxFocusBG());
  748. c = g_Opt.m_Theme.SearchTextBoxFocusBorder();
  749. }
  750. else
  751. {
  752. dc.FillSolidRect(t, g_Opt.m_Theme.MainWindowBG());
  753. dc.FillSolidRect(b, g_Opt.m_Theme.MainWindowBG());
  754. }
  755. //if ((text.GetLength() > 0 || this == GetFocus()) && m_windowDpi)
  756. {
  757. CWindowDC dc(this);
  758. CRect rcFrame;
  759. this->GetWindowRect(rcFrame);
  760. this->ScreenToClient(rcFrame);
  761. CRect rcBorder(0, 0, rcFrame.Width(), rcFrame.Height());
  762. int border = m_windowDpi->Scale(1);
  763. CBrush borderBrush(c);
  764. for (int x = 0; x < border; x++)
  765. {
  766. dc.FrameRect(rcBorder, &borderBrush);
  767. rcBorder.DeflateRect(1, 1, 1, 1);
  768. }
  769. }
  770. OutputDebugString(_T("OnNCPaint \r\n"));
  771. }
  772. void CSymbolEdit::OnTimer(UINT_PTR nIDEvent)
  773. {
  774. switch (nIDEvent)
  775. {
  776. case 1:
  777. KillTimer(1);
  778. //Invalidate();
  779. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  780. break;
  781. }
  782. CEdit::OnTimer(nIDEvent);
  783. }