project64/Source/Project64/UserInterface/WTLControls/ModifiedComboBox.h

153 lines
3.9 KiB
C
Raw Normal View History

2016-01-27 09:11:59 +00:00
#pragma once
template <class TParam>
2022-09-26 02:31:54 +00:00
class CModifiedComboBoxT :
public CComboBox
2016-01-27 09:11:59 +00:00
{
2022-09-26 02:31:54 +00:00
typedef std::list<TParam *> TParamList;
2016-01-27 09:11:59 +00:00
public:
2022-09-26 02:31:54 +00:00
// Constructors
CModifiedComboBoxT(TParam defaultValue, HWND hWnd = nullptr, bool AllwaysSelected = true) :
CComboBox(hWnd),
m_Changed(false),
m_Reset(false),
m_defaultValue(defaultValue),
m_BoldFont(nullptr),
m_OriginalFont(nullptr),
m_TextField(nullptr),
m_AllwaysSelected(AllwaysSelected)
{
}
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
~CModifiedComboBoxT()
{
if (m_BoldFont)
{
DeleteObject(m_BoldFont);
}
for (TParamList::iterator iter = m_ParamList.begin(); iter != m_ParamList.end(); iter++)
{
TParam * Item = (TParam *)*iter;
if (Item)
{
delete Item;
}
}
}
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
int AddItem(LPCTSTR strItem, const TParam & lParam)
{
int indx = AddString(strItem);
TParam * Value = new TParam(lParam);
SetItemData(indx, (DWORD_PTR)(Value));
m_ParamList.push_back(Value);
if ((m_AllwaysSelected && GetCount() == 1) || m_defaultValue == lParam)
{
SetCurSel(indx);
}
return indx;
}
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
void SetReset(bool Reset)
{
m_Reset = Reset;
if (m_Reset)
{
SetChanged(false);
}
}
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
void SetChanged(bool Changed)
{
m_Changed = Changed;
if (m_Changed)
{
SetReset(false);
if (m_BoldFont == nullptr)
{
m_OriginalFont = (HFONT)SendMessage(WM_GETFONT);
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
LOGFONT lfSystemVariableFont;
GetObject(m_OriginalFont, sizeof(LOGFONT), &lfSystemVariableFont);
lfSystemVariableFont.lfWeight = FW_BOLD;
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
m_BoldFont = CreateFontIndirect(&lfSystemVariableFont);
}
SendMessage(WM_SETFONT, (WPARAM)m_BoldFont);
InvalidateRect(nullptr);
if (m_TextField)
{
::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_BoldFont, 0);
::InvalidateRect(m_TextField, nullptr, true);
}
}
else
{
if (m_OriginalFont)
{
SendMessage(WM_SETFONT, (WPARAM)m_OriginalFont);
InvalidateRect(nullptr);
if (m_TextField)
{
::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_OriginalFont, 0);
::InvalidateRect(m_TextField, nullptr, true);
}
}
}
}
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
void SetTextField(HWND hWnd)
{
if (m_TextField && m_OriginalFont)
{
::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_OriginalFont, 0);
}
m_TextField = hWnd;
if (m_Changed && m_BoldFont)
{
::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_BoldFont, 0);
}
}
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
inline void SetDefault(const TParam & defaultValue)
{
m_defaultValue = defaultValue;
for (int i = 0, n = GetCount(); i < n; i++)
{
if (*((TParam *)GetItemData(i)) == m_defaultValue)
{
SetCurSel(i);
break;
}
}
}
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
inline bool IsChanged(void) const
{
return m_Changed;
}
inline bool IsReset(void) const
{
return m_Reset;
}
private:
CModifiedComboBoxT(void);
CModifiedComboBoxT(const CModifiedComboBoxT &);
CModifiedComboBoxT & operator=(const CModifiedComboBoxT &);
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
bool m_Changed;
bool m_Reset;
TParam m_defaultValue;
HFONT m_BoldFont;
HFONT m_OriginalFont;
HWND m_TextField;
bool m_AllwaysSelected;
2016-01-27 09:11:59 +00:00
2022-09-26 02:31:54 +00:00
TParamList m_ParamList;
2016-01-27 09:11:59 +00:00
};
2022-09-26 02:31:54 +00:00
typedef CModifiedComboBoxT<WPARAM> CModifiedComboBox;
typedef CModifiedComboBoxT<stdstr> CModifiedComboBoxTxt;