From 15855fa84a09fd1fd486d357c38db0f2bd181e74 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 4 Mar 2014 23:23:45 +0000 Subject: HistoryStats compiles ok now git-svn-id: http://svn.miranda-ng.org/main/trunk@8399 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/HistoryStats/src/optionsctrlimpl_edit.cpp | 190 ++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 plugins/HistoryStats/src/optionsctrlimpl_edit.cpp (limited to 'plugins/HistoryStats/src/optionsctrlimpl_edit.cpp') diff --git a/plugins/HistoryStats/src/optionsctrlimpl_edit.cpp b/plugins/HistoryStats/src/optionsctrlimpl_edit.cpp new file mode 100644 index 0000000000..8af65d71dd --- /dev/null +++ b/plugins/HistoryStats/src/optionsctrlimpl_edit.cpp @@ -0,0 +1,190 @@ +#include "_globals.h" +#include "optionsctrlimpl.h" + +#include "main.h" + +/* + * OptionsCtrlImpl::Edit + */ + +ext::string OptionsCtrlImpl::Edit::getEditText() +{ + int nLen = GetWindowTextLength(m_hEditWnd); + mu_text* szBuf = new mu_text[nLen + 1]; + + GetWindowText(m_hEditWnd, szBuf, nLen + 1); + + ext::string strTemp = szBuf; + + delete[] szBuf; + + return strTemp; +} + +ext::string OptionsCtrlImpl::Edit::getCombinedText() +{ + if (m_strEdit.empty()) + { + return m_strLabel; + } + else + { + ext::string strTemp = m_strLabel; + + strTemp += muT(": "); + strTemp += m_strEdit; + + return strTemp; + } +} + +OptionsCtrlImpl::Edit::Edit(OptionsCtrlImpl* pCtrl, Item* pParent, const mu_text* szLabel, const mu_text* szEdit, DWORD dwFlags, DWORD dwData) + : Item(pCtrl, itEdit, szLabel, dwFlags, dwData), m_hEditWnd(NULL) +{ + m_strEdit = szEdit; + m_bNumber = bool_(dwFlags & OCF_NUMBER); + + m_pCtrl->insertItem(pParent, this, getCombinedText().c_str(), dwFlags, m_bEnabled ? siEdit : siEditG); + + if (pParent) + { + pParent->childAdded(this); + } +} + +void OptionsCtrlImpl::Edit::onSelect() +{ + if (!m_bEnabled || m_hEditWnd) + { + return; + } + + m_pCtrl->setNodeText(m_hItem, m_strLabel.c_str()); + + HFONT hTreeFront = reinterpret_cast(SendMessage(m_pCtrl->m_hTree, WM_GETFONT, 0, 0)); + RECT r; + + if (m_pCtrl->getItemFreeRect(m_hItem, r)) + { + r.top -= 2; + r.bottom += 2; + + if (r.left + 50 > r.right) + { + r.left = r.right - 50; + } + + HWND hTempWnd; + DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_LEFT | ES_AUTOHSCROLL; + + if (m_bNumber) + { + dwStyle |= ES_NUMBER | ES_RIGHT; + } + + if (hTempWnd = CreateWindowEx( + WS_EX_CLIENTEDGE, WC_EDIT, m_strEdit.c_str(), dwStyle, + r.left, r.top, r.right - r.left, r.bottom - r.top, + m_pCtrl->m_hTree, reinterpret_cast(ccEdit), g_hInst, NULL)) + { + SendMessage(hTempWnd, WM_SETFONT, reinterpret_cast(hTreeFront), MAKELPARAM(TRUE, 0)); + + m_hEditWnd = hTempWnd; + } + } +} + +void OptionsCtrlImpl::Edit::onDeselect() +{ + if (m_hEditWnd) + { + RECT rToInvalidate; + bool bValidRect = false; + + if (GetWindowRect(m_hEditWnd, &rToInvalidate)) + { + ScreenToClient(m_pCtrl->m_hTree, reinterpret_cast(&rToInvalidate) + 0); + ScreenToClient(m_pCtrl->m_hTree, reinterpret_cast(&rToInvalidate) + 1); + + bValidRect = true; + } + + m_strEdit = getEditText(); + + m_pCtrl->setNodeText(m_hItem, getCombinedText().c_str()); + + DestroyWindow(m_hEditWnd); + m_hEditWnd = NULL; + + InvalidateRect(m_pCtrl->m_hTree, bValidRect ? &rToInvalidate : NULL, TRUE); + } +} + +void OptionsCtrlImpl::Edit::onActivate() +{ + if (!m_hEditWnd) + { + onSelect(); + } + + if (m_hEditWnd) + { + SetFocus(m_hEditWnd); + SendMessage(m_hEditWnd, EM_SETSEL, 0, -1); + } +} + +void OptionsCtrlImpl::Edit::setEnabled(bool bEnable) +{ + m_bEnabled = bEnable; + + m_pCtrl->setStateImage(m_hItem, bEnable ? siEdit : siEditG); + + if (m_bDisableChilds) + { + enableChilds(m_bEnabled); + } +} + +void OptionsCtrlImpl::Edit::childAdded(Item* pChild) +{ + if (m_bDisableChilds) + { + pChild->setEnabled(m_bEnabled); + } +} + +const mu_text* OptionsCtrlImpl::Edit::getString() +{ + if (m_hEditWnd) + { + m_strEdit = getEditText(); + } + + return m_strEdit.c_str(); +} + +void OptionsCtrlImpl::Edit::setString(const mu_text* szString) +{ + m_strEdit = szString; + + if (m_hEditWnd) + { + SetWindowText(m_hEditWnd, m_strEdit.c_str()); + } + else + { + m_pCtrl->setNodeText(m_hItem, getCombinedText().c_str()); + } +} + +void OptionsCtrlImpl::Edit::setLabel(const mu_text* szLabel) +{ + m_strLabel = szLabel; + + // only if not editing (otherwise update when user finishes editing) + if (!m_hEditWnd) + { + m_pCtrl->setNodeText(m_hItem, getCombinedText().c_str()); + } +} -- cgit v1.2.3