[dasher: 10/217] Removed up/dn controls from ModuleControlLongSpin



commit e00486d5b59309a18cf56f97a48e622ea74d43cf
Author: ipomoena <amajorek google com>
Date:   Tue Jul 14 13:50:18 2015 -0700

    Removed up/dn controls from ModuleControlLongSpin
    
    fix for https://github.com/ipomoena/dasher/issues/4
    Added very rudimentary min max checks.

 Src/Win32/ModuleControlLongSpin.cpp |   58 ++++++++++------------------------
 Src/Win32/ModuleControlLongSpin.h   |    7 +---
 2 files changed, 18 insertions(+), 47 deletions(-)
---
diff --git a/Src/Win32/ModuleControlLongSpin.cpp b/Src/Win32/ModuleControlLongSpin.cpp
index be7ce60..8d44c9c 100644
--- a/Src/Win32/ModuleControlLongSpin.cpp
+++ b/Src/Win32/ModuleControlLongSpin.cpp
@@ -5,54 +5,30 @@ int CModuleControlLongSpin::GetHeightRequest() {
 }
 
 void CModuleControlLongSpin::Initialise(CAppSettings *pAppSets) {
-  int iValue(pAppSets->GetLongParameter(m_iId));
-  SendMessage(m_hSpin, UDM_SETPOS, 0, (LPARAM) MAKELONG ((short)iValue, 0));
-  UpdateEntry(iValue, 0);
+  double dValue = pAppSets->GetLongParameter(m_iId)*1.0 / m_iDivisor;
+  CString sValue;
+  sValue.Format(TEXT("%g"), dValue);
+  m_hEntry.SetWindowText(sValue);
 }
 
 void CModuleControlLongSpin::Apply(CAppSettings *pAppSets) {
-  int iValue(SendMessage(m_hSpin, UDM_GETPOS, 0, 0));
-  pAppSets->SetLongParameter(m_iId, iValue);
+  CString sValue;
+  m_hEntry.GetWindowText(sValue);
+  long lValue = wcstod(sValue, 0)*m_iDivisor;
+  if (lValue < m_iMin)
+    lValue = m_iMin;
+  else if (lValue > m_iMax)
+    lValue = m_iMax;
+
+  pAppSets->SetLongParameter(m_iId, lValue);
 }
 
 void CModuleControlLongSpin::CreateChild(HWND hParent) {
-  m_hEntry = CreateWindowEx(WS_EX_CONTROLPARENT | WS_EX_CLIENTEDGE, TEXT("EDIT"), NULL, 
-    WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 0, 0, hParent, NULL, WinHelper::hInstApp, NULL);
-
-  HGDIOBJ hGuiFont;
-  hGuiFont = GetStockObject(DEFAULT_GUI_FONT);
- 
-  SendMessage(m_hEntry, WM_SETFONT, (WPARAM)hGuiFont, (LPARAM)true);
-
-  m_hSpin = CreateWindowEx(WS_EX_CLIENTEDGE, UPDOWN_CLASS, TEXT(""), 
-    UDS_ALIGNRIGHT | WS_CHILD  | WS_TABSTOP |WS_VISIBLE |  WS_GROUP, 0, 0, 16, 16, 
-    hParent, NULL, WinHelper::hInstApp, NULL);
-
-  SendMessage(m_hSpin, UDM_SETRANGE, 0, (LPARAM) MAKELONG(m_iMax, m_iMin));
+  m_hEntry.Create(TEXT("EDIT"), hParent, 0, 0,
+    WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_NUMBER, WS_EX_CONTROLPARENT | WS_EX_CLIENTEDGE);
+  m_hEntry.SetFont(m_hEntry.GetParent().GetFont());
 }
 
 void CModuleControlLongSpin::LayoutChild(RECT &sRect) {
-   ::MoveWindow(m_hEntry, sRect.left, sRect.top, sRect.right - sRect.left, sRect.bottom - sRect.top, TRUE);
-   SendMessage(m_hSpin, UDM_SETBUDDY, (WPARAM)m_hEntry, 0);
-}
-
-LRESULT CModuleControlLongSpin::OnNotify(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
-  NMHDR *pNotify((LPNMHDR)lParam);
-
-  switch(pNotify->code) {
-    case UDN_DELTAPOS:
-      UpdateEntry(((LPNMUPDOWN) lParam)->iPos, ((LPNMUPDOWN) lParam)->iDelta);
-      break;
-    default:
-      bHandled = false;
-      break;
-  }
-
-  return 0;
-}
-
-void CModuleControlLongSpin::UpdateEntry(int iValue, int iDelta) {
-  WCHAR tcBuffer[256];
-  _sntprintf(tcBuffer, 100, TEXT("%0.4f"), (iValue + iDelta) / static_cast<double>(m_iDivisor));
-  SendMessage(m_hEntry, WM_SETTEXT, 0, (LPARAM) tcBuffer);
+  m_hEntry.MoveWindow(&sRect);
 }
diff --git a/Src/Win32/ModuleControlLongSpin.h b/Src/Win32/ModuleControlLongSpin.h
index 12845fc..b550048 100644
--- a/Src/Win32/ModuleControlLongSpin.h
+++ b/Src/Win32/ModuleControlLongSpin.h
@@ -7,8 +7,6 @@ class CModuleControlLongSpin : public CModuleControl {
 public:
   CModuleControlLongSpin(SModuleSettings *pSetting) : CModuleControl(pSetting) {};
 
-  virtual LRESULT OnNotify(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
-
   virtual int GetHeightRequest();
   virtual void Initialise(CAppSettings *pAppSets);
   virtual void Apply(CAppSettings *pAppSets);
@@ -16,10 +14,7 @@ public:
   virtual void LayoutChild(RECT &sRect);
 
 private:
-  void UpdateEntry(int iValue, int iDelta);
-
-  HWND m_hEntry;
-  HWND m_hSpin;
+  CWindow m_hEntry;
 };
 
 #endif
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]