Clone
ixen
committed
on 15 Nov 20
Fixed incomplete data filling when using rule edit dialogs. Limit responses available in the rule edit dialogs to those appropriate for spec… Show more
Fixed incomplete data filling when using rule edit dialogs. Limit responses available in the rule edit dialogs to those appropriate for specific feedback type.

Show less

src/ch/ComboDataWrapper.h (+62)
  1 // ============================================================================
  2 //  Copyright (C) 2001-2020 by Jozef Starosczyk
  3 //  ixen {at} copyhandler [dot] com
  4 //
  5 //  This program is free software; you can redistribute it and/or modify
  6 //  it under the terms of the GNU Library General Public License
  7 //  (version 2) as published by the Free Software Foundation;
  8 //
  9 //  This program is distributed in the hope that it will be useful,
  10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12 //  GNU General Public License for more details.
  13 //
  14 //  You should have received a copy of the GNU Library General Public
  15 //  License along with this program; if not, write to the
  16 //  Free Software Foundation, Inc.,
  17 //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18 // ============================================================================
  19 #pragma once
  20
  21 template<class T>
  22 class ComboDataWrapper
  23 {
  24 public:
  25         ComboDataWrapper(CComboBox& rCombo, T defaultValue, T lastValue) :
  26                 m_rCombo(rCombo),
  27                 m_defaultValue(defaultValue),
  28                 m_lastValue(lastValue)
  29         {
  30         }
  31
  32         T GetSelectedValue() const
  33         {
  34                 int iSel = m_rCombo.GetCurSel();
  35                 if(iSel < 0)
  36                         return m_defaultValue;
  37
  38                 DWORD_PTR dwData = m_rCombo.GetItemData(iSel);
  39                 if(dwData < m_lastValue)
  40                         return (T)dwData;
  41
  42                 return m_defaultValue;
  43         }
  44
  45         void SelectComboResult(T value)
  46         {
  47                 for(int iIndex = 0; iIndex < m_rCombo.GetCount(); ++iIndex)
  48                 {
  49                         DWORD_PTR dwData = m_rCombo.GetItemData(iIndex);
  50                         if(dwData == value)
  51                         {
  52                                 m_rCombo.SetCurSel(iIndex);
  53                                 return;
  54                         }
  55                 }
  56         }
  57
  58 private:
  59         CComboBox& m_rCombo;
  60         T m_defaultValue;
  61         T m_lastValue;
  62 };