[dasher: 13/217] Fixed truncated labels in ModuleSettings dialog - win32



commit 6fc13b1e112aadcb51fa0db471432de48fa45d66
Author: ipomoena <amajorek google com>
Date:   Mon Jul 20 23:34:38 2015 -0700

    Fixed truncated labels in ModuleSettings dialog - win32
    
    https://github.com/ipomoena/dasher/issues/2

 Src/Win32/ModuleControl.cpp       |   32 +++++++++++++++++------------
 Src/Win32/ModuleControl.h         |   25 +++++++++++++---------
 Src/Win32/ModuleControlBool.cpp   |   12 +---------
 Src/Win32/ModuleControlBool.h     |    5 +--
 Src/Win32/ModuleControlLong.cpp   |   30 +++++++++------------------
 Src/Win32/ModuleControlLong.h     |    8 ++----
 Src/Win32/ModuleControlString.cpp |   12 +---------
 Src/Win32/ModuleControlString.h   |    7 +++--
 Src/Win32/ModuleSettings.cpp      |   40 +++++++++++++------------------------
 Src/Win32/ModuleSettings.h        |    5 +---
 10 files changed, 72 insertions(+), 104 deletions(-)
---
diff --git a/Src/Win32/ModuleControl.cpp b/Src/Win32/ModuleControl.cpp
index 67be8ae..eab517b 100644
--- a/Src/Win32/ModuleControl.cpp
+++ b/Src/Win32/ModuleControl.cpp
@@ -1,4 +1,5 @@
 #include "ModuleControl.h"
+#include <algorithm>
 
 CModuleControl::CModuleControl(SModuleSettings *pSetting) {
   WinUTF8::UTF8string_to_wstring(pSetting->szDescription, m_strCaption);
@@ -10,19 +11,24 @@ CModuleControl::CModuleControl(SModuleSettings *pSetting) {
   m_iStep = pSetting->iStep;
 };
 
-void CModuleControl::Create(HWND hParent) {
-  m_hCaption.Create(TEXT("STATIC"), hParent, 0, m_strCaption.c_str(), WS_CHILD | WS_VISIBLE);
-  CreateChild(hParent);
-};
+void CModuleControl::Create(HWND hParent, RECT& rect)
+{
+  CWindowImpl<CModuleControl>::Create(hParent, rect);
+
+  RECT captionRect = { 0, 0, CAPTION_WIDTH, GetCaptionHeight() };
+  MapDialogRect(hParent, &captionRect);
+  m_hCaption.Create(TEXT("STATIC"), *this, captionRect, m_strCaption.c_str(), WS_CHILD | WS_VISIBLE);
 
-void CModuleControl::Layout(RECT *pRect) {
-  m_hCaption.MoveWindow(pRect->left, pRect->top, (pRect->right - pRect->left) / 2, pRect->bottom - 
pRect->top);
+  RECT childRect = { CAPTION_WIDTH, 0, CAPTION_WIDTH + CHILD_WIDTH, GetChildHeight() };
+  MapDialogRect(hParent, &childRect);
+  CreateChild(*this, childRect);
+};
 
-  RECT sRect;
-  sRect.left = (pRect->right + pRect->left) / 2;
-  sRect.right = pRect->right;
-  sRect.top = pRect->top;
-  sRect.bottom = pRect->bottom;
+int CModuleControl::GetHeight() {
+  return std::max(GetCaptionHeight(), GetChildHeight());
+}
 
-  LayoutChild(sRect);
-};
\ No newline at end of file
+int CModuleControl::GetCaptionHeight() {
+  int charsPerLine = CAPTION_WIDTH / 4;
+  return 8 * ((m_strCaption.length() + charsPerLine - 1) / charsPerLine);
+}
diff --git a/Src/Win32/ModuleControl.h b/Src/Win32/ModuleControl.h
index 9571f35..48c7e9d 100644
--- a/Src/Win32/ModuleControl.h
+++ b/Src/Win32/ModuleControl.h
@@ -4,27 +4,29 @@
 #include "Common/WinCommon.h"
 #include "AppSettings.h"
 #include "../Common/ModuleSettings.h"
-#include <atlbase.h>
-#include <atlwin.h>
 #include <string>
 
-class CModuleControl {
+class CModuleControl : public CWindowImpl<CModuleControl> {
 public:
+  static const int CAPTION_WIDTH = 125;
+  static const int CHILD_WIDTH = 125;
+
   CModuleControl(SModuleSettings *pSetting);
+  DECLARE_WND_SUPERCLASS(NULL, L"STATIC")
+
+  BEGIN_MSG_MAP(CModuleControl)
+  END_MSG_MAP()
+  void Create(HWND hParent, RECT& rect);
 
- 
-  void Create(HWND hParent);
-  void Layout(RECT *pRect);
+  virtual int GetHeight();
 
   // Abstract members to be implemented by descendents
-  virtual int GetHeightRequest() = 0;
   virtual void Initialise(CAppSettings*) = 0;
   virtual void Apply(CAppSettings*) = 0;
-  virtual void CreateChild(HWND hParent) = 0;
-  virtual void LayoutChild(RECT &sRect) = 0;
 
 protected:
-  std::wstring m_strCaption;
+  virtual void CreateChild(HWND hParent, RECT& rect) = 0;
+  virtual int GetChildHeight() = 0;
 
   int m_iId;
   int m_iMin;
@@ -32,6 +34,9 @@ protected:
   int m_iDivisor;
   int m_iStep;
 
+private:
+  virtual int GetCaptionHeight();
+  std::wstring m_strCaption;
   CWindow m_hCaption;
 };
 
diff --git a/Src/Win32/ModuleControlBool.cpp b/Src/Win32/ModuleControlBool.cpp
index 700e615..bbe012e 100644
--- a/Src/Win32/ModuleControlBool.cpp
+++ b/Src/Win32/ModuleControlBool.cpp
@@ -1,9 +1,5 @@
 #include "ModuleControlBool.h"
 
-int CModuleControlBool::GetHeightRequest() {
-  return 10;
-}
-
 void CModuleControlBool::Initialise(CAppSettings *pAppSets) {
   m_hCheckbox.SendMessage(BM_SETCHECK, pAppSets->GetBoolParameter(m_iId) ? BST_CHECKED : BST_UNCHECKED);
 }
@@ -12,11 +8,7 @@ void CModuleControlBool::Apply(CAppSettings *pAppSets) {
   pAppSets->SetBoolParameter(m_iId, m_hCheckbox.SendMessage(BM_GETCHECK) == BST_CHECKED);
 }
 
-void CModuleControlBool::CreateChild(HWND hParent) {
-  m_hCheckbox.Create(TEXT("BUTTON"), hParent, 0,0,
+void CModuleControlBool::CreateChild(HWND hParent, RECT& rect) {
+  m_hCheckbox.Create(TEXT("BUTTON"), hParent, rect, 0,
     BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP);
 }
-
-void CModuleControlBool::LayoutChild(RECT &sRect) {
-  m_hCheckbox.MoveWindow(&sRect);
-}
diff --git a/Src/Win32/ModuleControlBool.h b/Src/Win32/ModuleControlBool.h
index bd01704..2dc646e 100644
--- a/Src/Win32/ModuleControlBool.h
+++ b/Src/Win32/ModuleControlBool.h
@@ -7,11 +7,10 @@ class CModuleControlBool : public CModuleControl {
 public:
   CModuleControlBool(SModuleSettings *pSetting) : CModuleControl(pSetting) {};
 
-  virtual int GetHeightRequest();
+  virtual int GetChildHeight() { return 10; };
   virtual void Initialise(CAppSettings *pAppSets);
   virtual void Apply(CAppSettings *pAppSets);
-  virtual void CreateChild(HWND hParent);
-  virtual void LayoutChild(RECT &sRect);
+  virtual void CreateChild(HWND hParent, RECT& rect);
 
 private:
   CWindow m_hCheckbox;
diff --git a/Src/Win32/ModuleControlLong.cpp b/Src/Win32/ModuleControlLong.cpp
index f4c617d..96887ae 100644
--- a/Src/Win32/ModuleControlLong.cpp
+++ b/Src/Win32/ModuleControlLong.cpp
@@ -15,10 +15,6 @@ LRESULT CModuleControlLong::OnEditLeft(WORD wNotifyCode, WORD wID, HWND hWndCtl,
   return 0;
 }
 
-int CModuleControlLong::GetHeightRequest() {
-  return 12;
-}
-
 void CModuleControlLong::Initialise(CAppSettings *pAppSets) {
   UpdateValue(pAppSets->GetLongParameter(m_iId));
 }
@@ -27,35 +23,29 @@ void CModuleControlLong::Apply(CAppSettings *pAppSets) {
   pAppSets->SetLongParameter(m_iId, GetValue());
 }
 
-void CModuleControlLong::CreateChild(HWND hParent) {
-  CWindowImpl<CModuleControlLong>::Create(hParent);
+void CModuleControlLong::CreateChild(HWND hParent, RECT& rect) {
+  RECT editRect = rect;
+
   if (m_bShowSlider) {
-    m_hSlider.Create(TRACKBAR_CLASS, *this, 0, 0, TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP);
+    RECT sliderRect = editRect;
+    sliderRect.left = editRect.left + (editRect.right - editRect.left)/4;
+    editRect.right = sliderRect.left;
+
+    m_hSlider.Create(TRACKBAR_CLASS, *this, sliderRect, 0, TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP);
     m_hSlider.SendMessage(TBM_SETPAGESIZE, 0, m_iStep);
     m_hSlider.SendMessage(TBM_SETRANGEMIN, true, m_iMin);
     m_hSlider.SendMessage(TBM_SETRANGEMAX, true, m_iMax);
   }
-
-  m_hEdit.Create(TEXT("EDIT"), *this, 0, 0,
+  m_hEdit.Create(TEXT("EDIT"), *this, editRect, 0,
     WS_CHILD | WS_VISIBLE | WS_TABSTOP, WS_EX_CLIENTEDGE, 1);
-}
 
-void CModuleControlLong::LayoutChild(RECT &sRect) {
-  MoveWindow(&sRect);
-  if (m_bShowSlider) {
-    m_hEdit.MoveWindow(0, 0, 32, sRect.bottom - sRect.top);
-    m_hSlider.MoveWindow(32, 0, sRect.right - sRect.left - 32, sRect.bottom - sRect.top);
-  }
-  else {
-    m_hEdit.MoveWindow(0, 0, sRect.right - sRect.left, sRect.bottom - sRect.top);
-  }
 }
 
 void CModuleControlLong::UpdateValue(long lValue) {
   if (m_hSlider && GetSliderValue() != lValue) {
     m_hSlider.SendMessage(TBM_SETPOS, true, lValue);
   }
-  if (GetEditValue() != lValue)
+  if (!m_hEdit.GetWindowTextLength() || GetEditValue() != lValue)
   {
     double dValue = lValue*1.0 / m_iDivisor;
     CString sValue;
diff --git a/Src/Win32/ModuleControlLong.h b/Src/Win32/ModuleControlLong.h
index cf7b806..1a2e127 100644
--- a/Src/Win32/ModuleControlLong.h
+++ b/Src/Win32/ModuleControlLong.h
@@ -3,10 +3,9 @@
 
 #include "ModuleControl.h"
 
-class CModuleControlLong : public CModuleControl, public CWindowImpl<CModuleControlLong>{
+class CModuleControlLong : public CModuleControl {
 public:
   CModuleControlLong(SModuleSettings *pSetting, bool bShowSlider) : CModuleControl(pSetting), 
m_bShowSlider(bShowSlider) {};
-  DECLARE_WND_SUPERCLASS(NULL, L"STATIC")
 
   BEGIN_MSG_MAP(CModuleControlLong)
     COMMAND_HANDLER(1, EN_CHANGE, OnEditChange)
@@ -17,11 +16,10 @@ public:
   LRESULT OnEditLeft(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
   LRESULT OnSliderScroll(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-  virtual int GetHeightRequest();
+  virtual int GetChildHeight() { return 14; };
   virtual void Initialise(CAppSettings *pAppSets);
   virtual void Apply(CAppSettings *pAppSets);
-  virtual void CreateChild(HWND hParent);
-  virtual void LayoutChild(RECT &sRect);
+  virtual void CreateChild(HWND hParent, RECT& rect);
 
 private:
   void UpdateValue(long lValue);
diff --git a/Src/Win32/ModuleControlString.cpp b/Src/Win32/ModuleControlString.cpp
index 5ee2335..44a8546 100644
--- a/Src/Win32/ModuleControlString.cpp
+++ b/Src/Win32/ModuleControlString.cpp
@@ -1,9 +1,5 @@
 #include "ModuleControlString.h"
 
-int CModuleControlString::GetHeightRequest() {
-  return 14;
-}
-
 void CModuleControlString::Initialise(CAppSettings *pAppSets) {
   std::wstring wideText;
   WinUTF8::UTF8string_to_wstring(pAppSets->GetStringParameter(m_iId), wideText);
@@ -19,11 +15,7 @@ void CModuleControlString::Apply(CAppSettings *pAppSets) {
   pAppSets->SetStringParameter(m_iId, strUTF8Text);
 }
 
-void CModuleControlString::CreateChild(HWND hParent) {
-  m_hEntry.Create(TEXT("EDIT"), hParent, 0, 0,
+void CModuleControlString::CreateChild(HWND hParent, RECT& rect) {
+  m_hEntry.Create(TEXT("EDIT"), hParent, rect, 0,
     WS_CHILD | WS_VISIBLE | WS_TABSTOP, WS_EX_CLIENTEDGE);
 }
-
-void CModuleControlString::LayoutChild(RECT &sRect) {
-  m_hEntry.MoveWindow(&sRect);
-}
diff --git a/Src/Win32/ModuleControlString.h b/Src/Win32/ModuleControlString.h
index a5915c0..5c8ec18 100644
--- a/Src/Win32/ModuleControlString.h
+++ b/Src/Win32/ModuleControlString.h
@@ -7,11 +7,12 @@ class CModuleControlString : public CModuleControl {
 public:
   CModuleControlString(SModuleSettings *pSetting) : CModuleControl(pSetting) {};
 
-  virtual int GetHeightRequest();
   virtual void Initialise(CAppSettings *pAppSets);
   virtual void Apply(CAppSettings *pAppSets);
-  virtual void CreateChild(HWND hParent);
-  virtual void LayoutChild(RECT &sRect);
+
+protected:
+  virtual void CreateChild(HWND hParent, RECT& rect);
+  virtual int GetChildHeight() { return 14; };
 
 private:
   CWindow m_hEntry;
diff --git a/Src/Win32/ModuleSettings.cpp b/Src/Win32/ModuleSettings.cpp
index d434ad7..b7a1444 100644
--- a/Src/Win32/ModuleSettings.cpp
+++ b/Src/Win32/ModuleSettings.cpp
@@ -38,17 +38,25 @@ CModuleSettings::~CModuleSettings() {
 LRESULT CModuleSettings::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
   std::wstring strWName;
   WinUTF8::UTF8string_to_wstring(m_strModuleName, strWName);
+  SetWindowText(strWName.c_str());
 
-  int iHeight(7);
+  int iDlgWidth = 7 + CModuleControl::CAPTION_WIDTH + CModuleControl::CHILD_WIDTH + 7;
+  int iTop = 7;
 
   for (int i(0); i < m_iCount; ++i) {
-    m_pControls[i]->Create(m_hWnd);
+    RECT controlRect = { 7, iTop, iDlgWidth - 7, iTop + m_pControls[i]->GetHeight() };
+    MapDialogRect(&controlRect);
+
+    m_pControls[i]->Create(m_hWnd, controlRect);
     m_pControls[i]->Initialise(m_pAppSets);
-    iHeight += m_pControls[i]->GetHeightRequest() + 2;
+    iTop += m_pControls[i]->GetHeight() + 2;
   }
-  iHeight += (-2 + 7 + 14 + 7); // - last item spacing + buttons 
+  iTop += -2 + 7;
+
+  MoveButton(IDCANCEL, iDlgWidth - 57, iTop);
+  MoveButton(IDOK, iDlgWidth - 2 * (57), iTop);
 
-  RECT size = { 0, 0, m_iDlgWidth, iHeight };
+  RECT size = { 0, 0, iDlgWidth, iTop + 14 + 7 };
   MapDialogRect(&size);
   ResizeClient(size.right, size.bottom);
 
@@ -56,7 +64,7 @@ LRESULT CModuleSettings::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, B
   return 1;
 }
 
-LRESULT  CModuleSettings::OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled){
+LRESULT  CModuleSettings::OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
   if (wID == IDOK) {
     // Apply and close 
     for (int i(0); i < m_iCount; ++i) {
@@ -67,26 +75,6 @@ LRESULT  CModuleSettings::OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, B
   return 0;
 }
 
-LRESULT CModuleSettings::OnSize(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
-  int iCurrentTop(7);
-
-  for (int i(0); i < m_iCount; ++i) {
-    int iHeight(m_pControls[i]->GetHeightRequest());
-
-    RECT sPosition = { 7, iCurrentTop, m_iDlgWidth - 7, iCurrentTop + iHeight };
-    MapDialogRect(&sPosition);
-    m_pControls[i]->Layout(&sPosition);
-
-    iCurrentTop += iHeight + 2;
-  }
-  int btnX = m_iDlgWidth - (50 + 7);
-  int btnY = iCurrentTop -2 + 7;
-  MoveButton(IDCANCEL, btnX, btnY);
-  btnX -= 50 + 7;
-  MoveButton(IDOK, btnX, btnY);
-  return 0;
-}
-
 void CModuleSettings::MoveButton(WORD wID, int x, int y){
 
   RECT r = { x, y, x + 50, y + 14 };
diff --git a/Src/Win32/ModuleSettings.h b/Src/Win32/ModuleSettings.h
index 1f7b98e..64d6156 100644
--- a/Src/Win32/ModuleSettings.h
+++ b/Src/Win32/ModuleSettings.h
@@ -19,20 +19,17 @@ public:
   BEGIN_MSG_MAP(CModuleSettings)
     MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
     COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd)
-    MESSAGE_HANDLER(WM_SIZE, OnSize)
   END_MSG_MAP()
 
   LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
-  LRESULT OnSize(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
 private:
   void MoveButton(WORD wID, int x, int y);
+
   int m_iCount;
   CModuleControl **m_pControls;
   std::string m_strModuleName;
-  const int m_iDlgWidth = 250;
-
   CAppSettings *m_pAppSets;
 };
 


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