Jelajahi Sumber

show menu of previouse searches (ctrl-down or ctrl-shift-down or click down icon)

Scott Brogden 8 tahun lalu
induk
melakukan
eb6cd77a40
11 mengubah file dengan 218 tambahan dan 8 penghapusan
  1. 10 0
      CP_Main.rc
  2. 5 0
      CP_Main.vcxproj
  3. 5 0
      CP_Main.vcxproj.filters
  4. 7 1
      Resource.h
  5. 178 7
      SymbolEdit.cpp
  6. 13 0
      SymbolEdit.h
  7. TEMPAT SAMPAH
      res/down_16.png
  8. TEMPAT SAMPAH
      res/down_20.png
  9. TEMPAT SAMPAH
      res/down_24.png
  10. TEMPAT SAMPAH
      res/down_28.png
  11. TEMPAT SAMPAH
      res/down_32.png

+ 10 - 0
CP_Main.rc

@@ -1414,6 +1414,16 @@ cog_28                  PNG                     "res\\cog_28.png"
 
 Search_28               PNG                     "res\\Search_28.png"
 
+down_16                 PNG                     "res\\down_16.png"
+
+down_20                 PNG                     "res\\down_20.png"
+
+down_24                 PNG                     "res\\down_24.png"
+
+down_28                 PNG                     "res\\down_28.png"
+
+down_32                 PNG                     "res\\down_32.png"
+
 
 /////////////////////////////////////////////////////////////////////////////
 //

+ 5 - 0
CP_Main.vcxproj

@@ -2239,6 +2239,11 @@
     </Midl>
   </ItemGroup>
   <ItemGroup>
+    <Image Include="res\down_16.png" />
+    <Image Include="res\down_20.png" />
+    <Image Include="res\down_24.png" />
+    <Image Include="res\down_28.png" />
+    <Image Include="res\down_32.png" />
     <Image Include="res\icon3.ico" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

+ 5 - 0
CP_Main.vcxproj.filters

@@ -1408,5 +1408,10 @@
   </ItemGroup>
   <ItemGroup>
     <Image Include="res\icon3.ico" />
+    <Image Include="res\down_16.png" />
+    <Image Include="res\down_20.png" />
+    <Image Include="res\down_24.png" />
+    <Image Include="res\down_28.png" />
+    <Image Include="res\down_32.png" />
   </ItemGroup>
 </Project>

+ 7 - 1
Resource.h

@@ -182,6 +182,12 @@
 #define IDD_DIALOG_FREIND_PROMPT        324
 #define IDD_DIALOG2                     325
 #define IDD_ADV_OPTIONS                 325
+#define down_16                         328
+#define down_20                         329
+#define down_24                         330
+#define down_28                         331
+#define IDB_PNG20                       332
+#define down_32                         332
 #define IDC_PATH                        1000
 #define IDC_GET_PATH                    1001
 #define IDC_SELECT_SOUND                1002
@@ -690,7 +696,7 @@
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
-#define _APS_NEXT_RESOURCE_VALUE        328
+#define _APS_NEXT_RESOURCE_VALUE        333
 #define _APS_NEXT_COMMAND_VALUE         32942
 #define _APS_NEXT_CONTROL_VALUE         2154
 #define _APS_NEXT_SYMED_VALUE           104

+ 178 - 7
SymbolEdit.cpp

@@ -8,6 +8,10 @@
 
 // CSymbolEdit
 
+#define RANGE_START 3000
+#define CLEAR_LIST 3050
+#define LIST_MAX_COUNT 50
+
 IMPLEMENT_DYNAMIC(CSymbolEdit, CEdit)
 
 CSymbolEdit::CSymbolEdit() :
@@ -31,9 +35,14 @@ CSymbolEdit::CSymbolEdit() :
 		DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
 		_T("Calibri"));
 
+	m_mouseDownOnSearches = false;
+	m_mouseHoveringOverSearches = false;
+	m_mouseDownOnClose = false;
+	m_mouseHoveringOverClose = false;
 
 	//m_searchButton.LoadStdImageDPI(Search_16, Search_20, Search_24, Search_32, _T("PNG"));
 	m_closeButton.LoadStdImageDPI(search_close_16, Search_20, Search_24, Search_28, Search_32, _T("PNG"));
+	m_searchesButton.LoadStdImageDPI(down_16, down_20, down_24, down_28, down_32, _T("PNG"));
 }
 
 CSymbolEdit::~CSymbolEdit()
@@ -45,6 +54,7 @@ CSymbolEdit::~CSymbolEdit()
 BEGIN_MESSAGE_MAP(CSymbolEdit, CEdit)
 	ON_WM_PAINT()
 	ON_MESSAGE(WM_SETFONT, OnSetFont)
+	//ON_MESSAGE(WM_EXITMENULOOP, OnMenuExit)
 	ON_WM_CTLCOLOR_REFLECT()
 	ON_WM_SETFOCUS()
 	ON_WM_KILLFOCUS()
@@ -52,6 +62,8 @@ BEGIN_MESSAGE_MAP(CSymbolEdit, CEdit)
 	ON_WM_LBUTTONUP()
 	ON_WM_LBUTTONDOWN()
 	ON_WM_MOUSEMOVE()
+	ON_COMMAND_RANGE(RANGE_START, (RANGE_START+ LIST_MAX_COUNT), OnSelectSearchString)
+	ON_WM_EXITSIZEMOVE()
 END_MESSAGE_MAP()
 
 BOOL CSymbolEdit::PreTranslateMessage(MSG* pMsg)
@@ -100,10 +112,20 @@ BOOL CSymbolEdit::PreTranslateMessage(MSG* pMsg)
 					//Send a message to the parent to refill the lb from the search
 					pWnd->PostMessage(CB_SEARCH, 0, 0);
 				}
+
+				AddToSearchHistory();
 			}
 
 			return TRUE;
 		}
+		else if (pMsg->wParam == VK_DOWN &&
+			((GetKeyState(VK_CONTROL) & 0x8000) || ((GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_SHIFT) & 0x8000))))
+		{
+			if (ShowSearchHistoryMenu())
+			{
+				return TRUE;
+			}
+		}
 		else if (pMsg->wParam == VK_DOWN ||
 			pMsg->wParam == VK_UP ||
 			pMsg->wParam == VK_F3 ||
@@ -143,6 +165,71 @@ BOOL CSymbolEdit::PreTranslateMessage(MSG* pMsg)
 	return CEdit::PreTranslateMessage(pMsg);
 }
 
+void CSymbolEdit::AddToSearchHistory()
+{
+	CString cs;
+	this->GetWindowText(cs);
+	if (cs != _T(""))
+	{
+		if (m_searches.GetCount() >= LIST_MAX_COUNT)
+		{
+			m_searches.RemoveAt(0);
+		}
+
+		bool existing = false;
+		int count = m_searches.GetCount();
+		for (int i = 0; i < count; i++)
+		{
+			if (m_searches[i] == cs)
+			{
+				m_searches.RemoveAt(i);
+				m_searches.Add(cs);
+				existing = true;
+				break;
+			}
+		}
+
+		if (existing == false)
+		{
+			m_searches.Add(cs);
+		}
+	}
+}
+
+bool CSymbolEdit::ShowSearchHistoryMenu()
+{
+	if (m_searches.GetCount() == 0)
+	{
+		return false;
+	}
+
+	CMenu cmPopUp;
+	cmPopUp.CreatePopupMenu();
+
+	int count = min(m_searches.GetCount(), LIST_MAX_COUNT);
+	for (int i = count-1; i >= 0; i--)
+	{
+		cmPopUp.AppendMenuW(MF_STRING, (RANGE_START + i), m_searches[i]);
+	}
+
+	cmPopUp.AppendMenu(MF_SEPARATOR);
+	cmPopUp.AppendMenuW(MF_STRING, CLEAR_LIST, _T("Clear List"));
+
+	CRect windowRect;
+	this->GetWindowRect(&windowRect);
+	POINT pp;
+	GetCursorPos(&pp);
+	POINT x = this->GetCaretPos();
+	ClientToScreen(&x);
+	x.y += windowRect.Height();
+
+	cmPopUp.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x.x, x.y, this, NULL);
+	
+	Invalidate();
+	
+	return true;
+}
+
 void CSymbolEdit::DestroyIcon()
 {
 	// if icon was loaded internally, destroy it
@@ -249,7 +336,7 @@ void CSymbolEdit::RecalcLayout()
 	}
 	else
 	{
-		SetMargins(4, 24);
+		SetMargins(4, theApp.m_metrics.ScaleX(34));
 	}
 }
 
@@ -269,9 +356,7 @@ void CSymbolEdit::OnPaint()
 	textRect.right -= HIWORD(margins);
 
 	// Clearing the background
-	dc.FillSolidRect(rect, GetSysColor(COLOR_WINDOW));
-
-	
+	dc.FillSolidRect(rect, GetSysColor(COLOR_WINDOW));	
 
 	if (m_hSymbolIcon)
 	{
@@ -329,8 +414,8 @@ void CSymbolEdit::OnPaint()
 	if (text.GetLength() == 0 && m_strPromptText.GetLength() > 0)
 	{
 		//if we aren't showing the close icon, then use the full space
-		textRect.right += HIWORD(margins);
-		textRect.right -= LOWORD(margins);
+		textRect.right += theApp.m_metrics.ScaleX(16);
+		//textRect.right -= LOWORD(margins);
 
 		oldFont = dc.SelectObject(&m_fontPrompt);
 		COLORREF color = dc.GetTextColor();
@@ -341,13 +426,29 @@ void CSymbolEdit::OnPaint()
 		dc.SelectObject(oldFont);
 	}
 
+	int right = rect.right;
+	if ((text.GetLength() > 0 || this == GetFocus()))
+	{
+		m_searchesButtonRect.SetRect(rect.right - theApp.m_metrics.ScaleX(18), 0, rect.right, rect.bottom);
+		right = rect.right - theApp.m_metrics.ScaleX(18);
+		m_searchesButton.Draw(&dc, this, m_searchesButtonRect.left, 4, m_mouseHoveringOverSearches, m_mouseDownOnSearches);
+	}
+	else
+	{
+		m_searchesButtonRect.SetRect(0, 0, 0, 0);
+		//m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
+	}
+
 	if (text.GetLength() > 0)
 	{
-		m_closeButtonRect.SetRect(rect.right - 22, 0, rect.right, rect.bottom);
+		OutputDebugString(_T("showing close button\n"));
+
+		m_closeButtonRect.SetRect(right - theApp.m_metrics.ScaleX(16), 0, right, rect.bottom);
 		m_closeButton.Draw(&dc, this, m_closeButtonRect.left, 4, m_mouseHoveringOverClose, m_mouseDownOnClose);
 	}
 	else
 	{
+		OutputDebugString(_T("not showing close button\n"));
 		m_closeButtonRect.SetRect(0, 0, 0, 0);
 		//m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
 	}
@@ -403,6 +504,8 @@ void CSymbolEdit::OnSetFocus(CWnd* pOldWnd)
 
 void CSymbolEdit::OnKillFocus(CWnd* pNewWnd)
 {
+	AddToSearchHistory();
+
 	Invalidate(FALSE);
 	CEdit::OnKillFocus(pNewWnd);
 }
@@ -420,6 +523,13 @@ BOOL CSymbolEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
 		return TRUE;
 	}
 
+	if (m_searchesButtonRect.PtInRect(pntCursor))
+	{
+		HCURSOR h = ::LoadCursor(NULL, IDC_ARROW);
+		::SetCursor(h);
+		return TRUE;
+	}
+
 	return CEdit::OnSetCursor(pWnd, nHitTest, message);
 }
 
@@ -431,7 +541,14 @@ void CSymbolEdit::OnLButtonUp(UINT nFlags, CPoint point)
 		InvalidateRect(m_closeButtonRect);
 	}
 
+	if (m_mouseDownOnSearches)
+	{
+		ReleaseCapture();
+		InvalidateRect(m_searchesButtonRect);
+	}
+
 	m_mouseDownOnClose = false;
+	m_mouseDownOnSearches = false;
 
 	if (m_closeButtonRect.PtInRect(point))
 	{
@@ -445,6 +562,11 @@ void CSymbolEdit::OnLButtonUp(UINT nFlags, CPoint point)
 		}		
 	}	
 
+	if (m_searchesButtonRect.PtInRect(point))
+	{
+		this->ShowSearchHistoryMenu();
+	}
+
 	CEdit::OnLButtonUp(nFlags, point);
 }
 
@@ -461,6 +583,17 @@ void CSymbolEdit::OnLButtonDown(UINT nFlags, CPoint point)
 		m_mouseDownOnClose = false;
 	}
 
+	if (m_searchesButtonRect.PtInRect(point))
+	{
+		m_mouseDownOnSearches = true;
+		SetCapture();
+		InvalidateRect(m_searchesButtonRect);
+	}
+	else
+	{
+		m_mouseDownOnSearches = false;
+	}
+
 	CEdit::OnLButtonDown(nFlags, point);
 }
 
@@ -480,5 +613,43 @@ void CSymbolEdit::OnMouseMove(UINT nFlags, CPoint point)
 		InvalidateRect(m_closeButtonRect);
 	}
 
+	if (m_searchesButtonRect.PtInRect(point))
+	{
+		if (m_mouseHoveringOverSearches == false)
+		{
+			m_mouseHoveringOverSearches = true;
+			InvalidateRect(m_searchesButtonRect);
+		}
+	}
+	else if (m_mouseHoveringOverSearches)
+	{
+		m_mouseHoveringOverSearches = false;
+		InvalidateRect(m_searchesButtonRect);
+	}
+
 	CEdit::OnMouseMove(nFlags, point);
 }
+
+void CSymbolEdit::OnSelectSearchString(UINT idIn)
+{
+	int index = idIn - RANGE_START;
+
+	if (idIn == CLEAR_LIST)
+	{
+		m_searches.RemoveAll();
+	}
+	else if (index >= 0 &&
+		index < m_searches.GetCount())
+	{
+		CString cs = m_searches[index];
+		this->SetWindowTextW(cs);
+
+		this->SetFocus();
+		this->SetSel(-1);
+
+		this->Invalidate();
+
+		m_searches.RemoveAt(index);
+		m_searches.Add(cs);
+	}
+}

+ 13 - 0
SymbolEdit.h

@@ -48,6 +48,10 @@ public:
 
 	virtual BOOL PreTranslateMessage(MSG* pMsg);
 
+	void AddToSearchHistory();
+
+	bool ShowSearchHistoryMenu();
+
 	void SetSymbolIcon(HICON hIcon, BOOL redraw = TRUE);
 	void SetSymbolIcon(UINT id, BOOL redraw = TRUE);
 
@@ -67,11 +71,19 @@ protected:
 	bool m_mouseDownOnClose;
 	bool m_mouseHoveringOverClose;
 
+	CGdiImageDrawer m_searchesButton;
+	CRect m_searchesButtonRect;
+	bool m_mouseDownOnSearches;
+	bool m_mouseHoveringOverSearches;
+
+	CStringArray m_searches;
+
 	void RecalcLayout();
 	virtual void PreSubclassWindow();
 
 	afx_msg void OnSize(UINT nType, int cx, int cy);
 	afx_msg LRESULT OnSetFont(WPARAM wParam, LPARAM lParam);
+	//afx_msg LRESULT OnMenuExit(WPARAM wParam, LPARAM lParam);
 	afx_msg HBRUSH CtlColor(CDC* pDC, UINT n);
 	afx_msg void OnSetFocus(CWnd* pOldWnd);
 	afx_msg void OnKillFocus(CWnd* pNewWnd);
@@ -79,6 +91,7 @@ protected:
 	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
 	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
 	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
+	afx_msg void OnSelectSearchString(UINT idIn);
 
 	DECLARE_MESSAGE_MAP()
 

TEMPAT SAMPAH
res/down_16.png


TEMPAT SAMPAH
res/down_20.png


TEMPAT SAMPAH
res/down_24.png


TEMPAT SAMPAH
res/down_28.png


TEMPAT SAMPAH
res/down_32.png