标题duilib ComboEdit

可编辑下拉选择框

可编辑下拉选择框,输入文本后,下拉选择框会自动显示相关的选项;
自己根据EditUI、ComboUI、ListUI自己弄出来的;
缺陷:
当窗口移动的时候(拖住窗口标题移动),combo窗口不会主动关闭,也不会主动跟着窗口移动,需要在窗口的WM_NCLBUTTONDOWN消息设置焦点到窗口或其他控件,使得CEditWnd收到KillFocus消息,从而把自己(CEditWnd)关闭,关闭时也把CComboWnd关闭;
但这样控件需要外部来控制,破坏控件的封装,且移动后焦点就不在ComboEdit上了;

LRESULT CMainFrame::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{switch (uMsg){case WM_TIMER:{OnTimer(uMsg, wParam, lParam, bHandled);}break;case WM_NCLBUTTONDOWN:{ShowMsg(_T("非客户区单击"));SetFocus(GetHWND());}break;default:{}break;}return 0;
}
void CEditCombo_EditWnd::OnFinalMessage(HWND hWnd)
{m_pOwner->Invalidate();// Clear reference and dieif( m_hBkBrush != NULL ) ::DeleteObject(m_hBkBrush);m_pOwner->GetManager()->RemoveNativeWindow(hWnd);m_pOwner->m_pEditWindow = NULL;m_pOwner->EditDestroy();  // 告诉父亲自己destroydelete this;
}LRESULT CEditCombo_EditWnd::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);if ((HWND)wParam != m_pOwner->GetManager()->GetPaintWindow()) {::SendMessage(m_pOwner->GetManager()->GetPaintWindow(), WM_KILLFOCUS, wParam, lParam);}SendMessage(WM_CLOSE);return lRes;
}void CEditComboUI::EditDestroy()
{if (NULL != m_pComboWindow){m_pComboWindow->PostMessage(WM_CLOSE);Invalidate();}
}

CComboEditUI

1. UIComboEdit.h


#pragma once#define  DUI_CTR_EDITCOMBOELEMENT  (_T("EditComboElement"))
#define  DUI_CTR_EDITCOMBO  (_T("EditCombo"))class CEditCombo_EditWnd;
class CEditCombo_ComboWnd;class IEditCombo_ControlUI
{public:virtual int GetWindowStyls() const = 0;virtual CPaintManagerUI* GetManager() const = 0;virtual CControlUI* GetParent() const = 0;virtual LPVOID GetInterface(LPCTSTR pstrName) = 0;virtual void Invalidate() = 0;virtual bool IsEnabled() const = 0;virtual CDuiString GetText() const = 0;virtual void SetPos(RECT rc, bool bNeedInvalidate) = 0;virtual const RECT& GetPos() const = 0;virtual RECT GetRelativePos() const = 0;virtual RECT GetClientPos() const = 0;virtual bool IsVisible() const = 0;virtual void DoEvent(TEventUI &event) = 0;
protected:virtual void _SetText(LPCTSTR pstrText) = 0;  // 仅仅设置m_sText
};class IEditCombo_EditUI : public IEditCombo_ControlUI
{friend class CEditCombo_EditWnd;protected:CEditCombo_EditWnd *m_pEditWindow;  // Edit框public:IEditCombo_EditUI() : m_pEditWindow(NULL){}virtual int GetFont() const = 0;virtual UINT GetTextStyle() const = 0;virtual RECT GetTextPadding() const = 0;virtual bool IsPasswordMode() const = 0;virtual TCHAR GetPasswordChar() const = 0;virtual bool IsReadOnly() const = 0;virtual bool IsAutoSelAll() const = 0;virtual UINT GetMaxChar() const = 0;virtual DWORD GetTextColor() const = 0;virtual DWORD GetNativeEditBkColor() const = 0;virtual DWORD GetNativeEditTextColor() const = 0;virtual void TextChange() = 0;virtual void EditDestroy() = 0;
};
class IEditCombo_ComboUI : public IEditCombo_ControlUI
{friend class CEditCombo_ComboWnd;
protected:CEditCombo_ComboWnd *m_pComboWindow;  // Combo弹窗UINT m_uButtonState;  // 状态public:IEditCombo_ComboUI() : m_pComboWindow(NULL), m_uButtonState(0){}virtual LPCTSTR GetClass() const = 0;virtual bool IsFloat() const = 0;virtual int GetCurSel() const = 0;virtual int GetCount() const = 0;virtual void SetManager(CPaintManagerUI* pManager, CControlUI* pParent, bool bInit = true) = 0;virtual CControlUI* GetItemAt(int id) = 0;virtual void SetFocus() = 0;virtual SIZE GetDropBoxSize() const = 0;virtual CDuiString GetDropBoxAttributeList() = 0;virtual TListInfoUI* GetListInfo() = 0;virtual bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true, bool bMutil = false) = 0;
};class CEditComboElementUI : public CListLabelElementUI
{public:CEditComboElementUI() : CListLabelElementUI(){}LPCTSTR GetClass() const{return DUI_CTR_EDITCOMBOELEMENT;}LPVOID GetInterface(LPCTSTR pstrName){if (0 == _tcscmp(pstrName, DUI_CTR_EDITCOMBOELEMENT)){return static_cast<CEditComboElementUI*>(this);}return CListLabelElementUI::GetInterface(pstrName);}void SetFocus() override{}
};class CEditComboUI : public CContainerUI, public IEditCombo_EditUI, public IEditCombo_ComboUI, public IListOwnerUI
{public:CEditComboUI(void);virtual ~CEditComboUI(void);LPCTSTR GetClass() const;LPVOID GetInterface(LPCTSTR pstrName);UINT GetControlFlags() const;HWND GetNativeWindow() const;HWND GetNativeEditHWND() const;int GetWindowStyls() const;UINT GetTextStyle() const;int GetFont() const;CPaintManagerUI* GetManager() const;CControlUI* GetParent() const;void Invalidate();bool IsEnabled() const;void SetEnabled(bool bEnable);CDuiString GetText() const;void _SetText(LPCTSTR pstrtext);void SetText(LPCTSTR pstrText);RECT GetTextPadding() const;void SetTextPadding(RECT rc);void SetTextPadding(LPCTSTR pstrValue);bool IsVisible() const;void TextChange();void EditDestroy();void SetPasswordMode(bool bPasswordMode);bool IsPasswordMode() const;void SetPasswordChar(TCHAR szChar);TCHAR GetPasswordChar() const;void SetMaxChar(UINT uMax);UINT GetMaxChar() const;void SetReadOnly(bool bReadOnly);bool IsReadOnly() const;void SetNumberOnly(bool bNumberOnly);bool IsNumberOnly() const;void SetAutoSelAll(bool bAuto);bool IsAutoSelAll() const;void SetReplaceSel(LPCTSTR lpszReplace);void SetFont(int index);void SetPos(RECT rc, bool bNeedInvalidate);const RECT& GetPos() const;RECT GetRelativePos() const;RECT GetClientPos() const;void Move(SIZE szOffset, bool bNeedInvalidate);void SetVisible(bool bVisible);void SetInternVisible(bool bVisible);SIZE EstimateSize(SIZE szAvailable);void PaintStatusImage(HDC hDC);void PaintText(HDC hDC);LPCTSTR GetNormalImage();void SetNormalImage(LPCTSTR pStrImage);LPCTSTR GetHotImage();void SetHotImage(LPCTSTR pStrImage);LPCTSTR GetPushedImage() const;void SetPushedIMage(LPCTSTR pStrImage);LPCTSTR GetFocusedImage();void SetFocusedImage(LPCTSTR pStrImage);LPCTSTR GetDisabledImage();void SetDisabledImage(LPCTSTR pStrImage);DWORD GetTextColor() const;void SetNativeEditBkColor(LPCTSTR pStrColor);DWORD GetNativeEditBkColor() const;void SetNativeEditTextColor(LPCTSTR pStrColor);DWORD GetNativeEditTextColor() const;void SetTipValue(LPCTSTR pStrTipValue);void SetTipValueColor(LPCTSTR pStrColor);DWORD GetTipValueColor();CDuiString GetTipValue();LPCTSTR GetSrcTipValue();void SetTextStyle(UINT uStyle);void SetTextColor(DWORD dwTextColor);void SetDisabledTextColor(DWORD dwTextColor);DWORD GetDisabledTextColor() const;DWORD StringToColor(LPCTSTR pstrColor);void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);void DoEvent(TEventUI& event) override;protected:int m_iWindowStyls;  // 类型int m_iFont;  // 字体bool m_bReadOnly;  // 是否只读bool m_bPasswordMode;  // 密码模式TCHAR m_szPasswordChar;  // 密码显示的字符UINT m_uMaxChar;  // 最大个数bool m_bAutoSelAll;  // 自动全选UINT m_uButtonState;  // 按钮状态RECT m_rcTextPadding;  // 文本间隔DWORD m_dwEditBkColor;  // Edit背景颜色DWORD m_dwEditTextColor;  // Edit文本颜色DWORD m_dwTipValueColor;  // 提示颜色CDuiString m_sTipValue;    // 提示的值CDuiString m_sSrcTipValue;  // UINT m_uTextStyle;DWORD m_dwTextColor;DWORD m_dwDisabledTextColor;TDrawInfo m_diNormal;TDrawInfo m_diHot;TDrawInfo m_diPushed;TDrawInfo m_diFocused;TDrawInfo m_diDisabled;public:bool IsFloat() const;int GetCurSel() const;int GetCount() const;void SetManager(CPaintManagerUI* pManager, CControlUI* pParent, bool bInit = true);CControlUI* GetItemAt(int id);void SetFocus();void SetDropBoxSize(SIZE szSize);void SetDropBoxSize(LPCTSTR pstrValue);SIZE GetDropBoxSize() const;void SetDropBoxAttributeList(LPCTSTR pstrList);CDuiString GetDropBoxAttributeList();TListInfoUI* GetListInfo();bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true, bool bMutil = false);bool SelectRange(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true, bool bMutil = false);bool ExpandItem(int iIndex, bool bExpand = true);int GetExpandedItem() const;bool SetItemIndex(CControlUI* pControl, int iNewIndex);bool SetMultiItemIndex(CControlUI* pStartControl, int iCount, int iNewStartIndex);bool Add(CControlUI* pControl);bool AddAt(CControlUI* pControl, int iIndex);bool Remove(CControlUI* pControl, bool bDoNotDestroy =false);bool RemoveAt(int iIndex, bool bDoNotDestroy =false);void RemoveAll();void SetShowText(bool bShow);bool GetShowText() const;void SetSelectCloseFlag(bool flag);bool GetSelectCloseFlag() const;UINT GetItemFixedHeight();void SetItemFixedHeight(UINT nHeight);int GetItemFont(int index);void SetItemFont(int index);void SetItemAlign(LPCTSTR pstrValue);UINT GetItemTextStyle();void SetItemTextStyle(UINT uStyle);RECT GetItemTextPadding() const;void SetItemTextPadding(RECT rc);void SetItemTextPadding(LPCTSTR pstrValue);DWORD GetItemTextColor() const;void SetItemTextColor(DWORD dwTextColor);DWORD GetItemBkColor() const;void SetItemBkColor(DWORD dwBkColor);LPCTSTR GetItemBkImage() const;void SetItemBkImage(LPCTSTR pStrImage);bool IsItemAlternateBk() const;void SetItemAlternateBk(bool bAlternateBk);DWORD GetSelectedItemTextColor() const;void SetSelectedItemTextColor(DWORD dwTextColor);DWORD GetSelectedItemBkColor() const;void SetSelectedItemBkColor(DWORD dwBkColor);LPCTSTR GetSelectedItemImage() const;void SetSelectedItemImage(LPCTSTR pStrImage);DWORD GetHotItemTextColor() const;void SetHotItemTextColor(DWORD dwTextColor);DWORD GetHotItemBkColor() const;void SetHotItemBkColor(DWORD dwBkColor);LPCTSTR GetHotItemImage() const;void SetHotItemImage(LPCTSTR pStrImage);DWORD GetDisabledItemTextColor() const;void SetDisabledItemTextColor(DWORD dwTextColor);DWORD GetDisabledItemBkColor() const;void SetDisabledItemBkColor(DWORD dwBkColor);LPCTSTR GetDisabledItemImage() const;void SetDisabledItemImage(LPCTSTR pStrImage);int GetItemHLineSize() const;void SetItemHLineSize(int iSize);DWORD GetItemHLineColor() const;void SetItemHLineColor(DWORD dwLineColor);int GetItemVLineSize() const;void SetItemVLineSize(int iSize);DWORD GetItemVLineColor() const;void SetItemVLineColor(DWORD dwLineColor);bool IsItemShowHtml();void SetItemShowHtml(bool bShowHtml = true);
private:int m_iCurSel;  // 当前选择的itembool m_bShowText;  // 不显示文本bool m_bSelectCloseFlag;  // (下拉框)关闭SIZE m_szDropBox;  // 下拉框大小CDuiString m_sDropBoxAttributes;  // 下拉框设置// 列表设置TListInfoUI m_ListInfo;
};

2. UIComboEdit.cpp


#include "stdafx.h"
#include "UIEditCombo.h"//
class CEditCombo_EditWnd : public CWindowWnd
{public:CEditCombo_EditWnd();void Init(IEditCombo_EditUI* pOwner);RECT CalPos();LPCTSTR GetWindowClassName() const;LPCTSTR GetSuperClassName() const;void OnFinalMessage(HWND hWnd);LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);LRESULT OnEditChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);protected:enum { DEFAULT_TIMERID = 20,};IEditCombo_EditUI* m_pOwner;HBRUSH m_hBkBrush;bool m_bInit;bool m_bDrawCaret;
};CEditCombo_EditWnd::CEditCombo_EditWnd() : m_pOwner(NULL), m_hBkBrush(NULL), m_bInit(false), m_bDrawCaret(false)
{}void CEditCombo_EditWnd::Init(IEditCombo_EditUI* pOwner)
{m_pOwner = pOwner;RECT rcPos = CalPos();UINT uStyle = WS_CHILD | ES_AUTOHSCROLL | pOwner->GetWindowStyls();UINT uTextStyle = m_pOwner->GetTextStyle();if(uTextStyle & DT_LEFT) uStyle |= ES_LEFT;else if(uTextStyle & DT_CENTER) uStyle |= ES_CENTER;else if(uTextStyle & DT_RIGHT) uStyle |= ES_RIGHT;if( m_pOwner->IsPasswordMode() ) uStyle |= ES_PASSWORD;Create(m_pOwner->GetManager()->GetPaintWindow(), NULL, uStyle, 0, rcPos);HFONT hFont=NULL;int iFontIndex=m_pOwner->GetFont();if (iFontIndex!=-1)hFont=m_pOwner->GetManager()->GetFont(iFontIndex);if (hFont==NULL)hFont=m_pOwner->GetManager()->GetDefaultFontInfo()->hFont;SetWindowFont(m_hWnd, hFont, TRUE);Edit_LimitText(m_hWnd, m_pOwner->GetMaxChar());if( m_pOwner->IsPasswordMode() ) Edit_SetPasswordChar(m_hWnd, m_pOwner->GetPasswordChar());Edit_SetText(m_hWnd, m_pOwner->GetText());Edit_SetModify(m_hWnd, FALSE);SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELPARAM(0, 0));Edit_Enable(m_hWnd, m_pOwner->IsEnabled() == true);Edit_SetReadOnly(m_hWnd, m_pOwner->IsReadOnly() == true);//Styls::ShowWindow(m_hWnd, SW_SHOWNOACTIVATE);::SetFocus(m_hWnd);if (m_pOwner->IsAutoSelAll()) {int nSize = GetWindowTextLength(m_hWnd);if( nSize == 0 ) nSize = 1;Edit_SetSel(m_hWnd, 0, nSize);}else {int nSize = GetWindowTextLength(m_hWnd);Edit_SetSel(m_hWnd, nSize, nSize);}m_bInit = true;
}RECT CEditCombo_EditWnd::CalPos()
{CDuiRect rcPos = m_pOwner->GetPos();RECT rcInset = m_pOwner->GetTextPadding();rcPos.left += rcInset.left;rcPos.top += rcInset.top;rcPos.right -= rcInset.right;rcPos.bottom -= rcInset.bottom;LONG lEditHeight = m_pOwner->GetManager()->GetFontInfo(m_pOwner->GetFont())->tm.tmHeight;if( lEditHeight < rcPos.GetHeight() ) {rcPos.top += (rcPos.GetHeight() - lEditHeight) / 2;rcPos.bottom = rcPos.top + lEditHeight;}CControlUI* pParent = static_cast<CControlUI*>(m_pOwner->GetInterface(DUI_CTR_CONTROL));RECT rcParent;while( pParent = pParent->GetParent() ) {if( !pParent->IsVisible() ) {rcPos.left = rcPos.top = rcPos.right = rcPos.bottom = 0;break;}rcParent = pParent->GetClientPos();if( !::IntersectRect(&rcPos, &rcPos, &rcParent) ) {rcPos.left = rcPos.top = rcPos.right = rcPos.bottom = 0;break;}}return rcPos;
}LPCTSTR CEditCombo_EditWnd::GetWindowClassName() const
{return _T("EditCombo_EditWnd");
}LPCTSTR CEditCombo_EditWnd::GetSuperClassName() const
{return WC_EDIT;
}void CEditCombo_EditWnd::OnFinalMessage(HWND hWnd)
{m_pOwner->Invalidate();// Clear reference and dieif( m_hBkBrush != NULL ) ::DeleteObject(m_hBkBrush);m_pOwner->GetManager()->RemoveNativeWindow(hWnd);m_pOwner->m_pEditWindow = NULL;m_pOwner->EditDestroy();delete this;
}LRESULT CEditCombo_EditWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{LRESULT lRes = 0;BOOL bHandled = TRUE;CControlUI *pOwner = static_cast<CControlUI*>(m_pOwner->GetInterface(DUI_CTR_CONTROL));if( uMsg == WM_CREATE ) {m_pOwner->GetManager()->AddNativeWindow(pOwner, m_hWnd);if( m_pOwner->GetManager()->IsLayered() ) {::SetTimer(m_hWnd, DEFAULT_TIMERID, ::GetCaretBlinkTime(), NULL);}bHandled = FALSE;}else if( uMsg == WM_KILLFOCUS ) lRes = OnKillFocus(uMsg, wParam, lParam, bHandled);else if( uMsg == OCM_COMMAND ) {if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE ) lRes = OnEditChanged(uMsg, wParam, lParam, bHandled);else if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_UPDATE ) {RECT rcClient;::GetClientRect(m_hWnd, &rcClient);::InvalidateRect(m_hWnd, &rcClient, FALSE);}}else if( uMsg == WM_KEYDOWN && TCHAR(wParam) == VK_RETURN ) {m_pOwner->GetManager()->SendNotify(pOwner, DUI_MSGTYPE_RETURN);}else if( uMsg == OCM__BASE + WM_CTLCOLOREDIT  || uMsg == OCM__BASE + WM_CTLCOLORSTATIC ) {if (m_pOwner->GetManager()->IsLayered() && !m_pOwner->GetManager()->IsPainting()) {m_pOwner->GetManager()->AddNativeWindow(pOwner, m_hWnd);}DWORD clrColor = m_pOwner->GetNativeEditBkColor();if( clrColor == 0xFFFFFFFF ) return 0;::SetBkMode((HDC)wParam, TRANSPARENT);DWORD dwTextColor = m_pOwner->GetTextColor();::SetTextColor((HDC)wParam, RGB(GetBValue(dwTextColor),GetGValue(dwTextColor),GetRValue(dwTextColor)));if (clrColor < 0xFF000000) {if (m_hBkBrush != NULL) ::DeleteObject(m_hBkBrush);RECT rcWnd = m_pOwner->GetManager()->GetNativeWindowRect(m_hWnd);HBITMAP hBmpEditBk = CRenderEngine::GenerateBitmap(m_pOwner->GetManager(), rcWnd, pOwner, clrColor);m_hBkBrush = ::CreatePatternBrush(hBmpEditBk);::DeleteObject(hBmpEditBk);}else {if (m_hBkBrush == NULL) {m_hBkBrush = ::CreateSolidBrush(RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));}}return (LRESULT)m_hBkBrush;}else if( uMsg == WM_PAINT) {if (m_pOwner->GetManager()->IsLayered()) {m_pOwner->GetManager()->AddNativeWindow(pOwner, m_hWnd);}bHandled = FALSE;}else if( uMsg == WM_PRINT ) {if (m_pOwner->GetManager()->IsLayered()) {lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);if( m_pOwner->IsEnabled() && m_bDrawCaret ) { // todo:判断是否enabledRECT rcClient;::GetClientRect(m_hWnd, &rcClient);POINT ptCaret;::GetCaretPos(&ptCaret);RECT rcCaret = { ptCaret.x, ptCaret.y, ptCaret.x, ptCaret.y+rcClient.bottom-rcClient.top };CRenderEngine::DrawLine((HDC)wParam, rcCaret, 1, 0xFF000000);}return lRes;}bHandled = FALSE;}else if( uMsg == WM_TIMER ) {if (wParam == DEFAULT_TIMERID) {m_bDrawCaret = !m_bDrawCaret;RECT rcClient;::GetClientRect(m_hWnd, &rcClient);::InvalidateRect(m_hWnd, &rcClient, FALSE);return 0;}bHandled = FALSE;}///新增提示功能/else if( uMsg == OCM__BASE + WM_CTLCOLOREDIT  || uMsg == OCM__BASE + WM_CTLCOLORSTATIC ) {  if( m_pOwner->GetNativeEditBkColor() == 0xFFFFFFFF ) return NULL;  ::SetBkMode((HDC)wParam, TRANSPARENT);  DWORD dwTextColor;  if (m_pOwner->GetNativeEditTextColor() != 0x000000)  dwTextColor = m_pOwner->GetNativeEditTextColor();  else  dwTextColor = m_pOwner->GetTextColor();  ::SetTextColor((HDC)wParam, RGB(GetBValue(dwTextColor),GetGValue(dwTextColor),GetRValue(dwTextColor)));  if( m_hBkBrush == NULL ) {  DWORD clrColor = m_pOwner->GetNativeEditBkColor();  m_hBkBrush = ::CreateSolidBrush(RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));  }  return (LRESULT)m_hBkBrush;  }else if (WM_MOUSEWHEEL == uMsg){int zDelta = (int)(short)HIWORD(wParam);TEventUI event = {0};event.Type = UIEVENT_SCROLLWHEEL;event.wParam = MAKELPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, 0);event.lParam = lParam;event.dwTimestamp = ::GetTickCount();m_pOwner->DoEvent(event);} else if (WM_NCHITTEST == uMsg){//::MessageBox(m_hWnd, _T("WM_NCHITTEST"), _T("test"), MB_OK);POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);::ScreenToClient(*this, &pt);RECT rcClient ;::GetClientRect(m_hWnd, &rcClient);if (::PtInRect(&rcClient, pt)){return HTCLIENT;}else{return HTBORDER;}}else if (WM_NCLBUTTONDOWN == uMsg){//      POINT pt;
//      pt.x = GET_X_LPARAM(lParam);
//      pt.y = GET_Y_LPARAM(lParam);
//      ::ScreenToClient(*this, &pt);
//      RECT rcClient ;
//      ::GetClientRect(m_hWnd, &rcClient);
//      if (!::PtInRect(&rcClient, pt)){::MessageBox(m_hWnd, _T("WM_NCLBUTTONDOWN"), _T("test"), MB_OK);}}//else bHandled = FALSE;if( !bHandled ) return CWindowWnd::HandleMessage(uMsg, wParam, lParam);return lRes;
}LRESULT CEditCombo_EditWnd::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);if ((HWND)wParam != m_pOwner->GetManager()->GetPaintWindow()) {::SendMessage(m_pOwner->GetManager()->GetPaintWindow(), WM_KILLFOCUS, wParam, lParam);}SendMessage(WM_CLOSE);return lRes;
}LRESULT CEditCombo_EditWnd::OnEditChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{if( !m_bInit ) return 0;if( m_pOwner == NULL ) return 0;// Copy text backint cchLen = ::GetWindowTextLength(m_hWnd) + 1;LPTSTR pstr = static_cast<LPTSTR>(_alloca(cchLen * sizeof(TCHAR)));ASSERT(pstr);if( pstr == NULL ) return 0;::GetWindowText(m_hWnd, pstr, cchLen);m_pOwner->_SetText(pstr);m_pOwner->GetManager()->SendNotify(static_cast<CControlUI*>(m_pOwner->GetInterface(DUI_CTR_CONTROL)), DUI_MSGTYPE_TEXTCHANGED);if( m_pOwner->GetManager()->IsLayered() ) m_pOwner->Invalidate();m_pOwner->TextChange();return 0;
}
//
class CEditCombo_ComboBodyUI : public CVerticalLayoutUI
{public:CEditCombo_ComboBodyUI(IEditCombo_ComboUI *pOwner);bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI *pStopControl);protected:IEditCombo_ComboUI *m_pOwner;
};CEditCombo_ComboBodyUI::CEditCombo_ComboBodyUI(IEditCombo_ComboUI *pOwner): CVerticalLayoutUI(), m_pOwner(pOwner)
{ASSERT(NULL != m_pOwner);
}
bool CEditCombo_ComboBodyUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI *pStopControl)
{RECT rcTemp = {0};if (!::IntersectRect(&rcTemp, &rcPaint, &m_rcItem)) return true;TListInfoUI *pListInfo = NULL;if (m_pOwner) pListInfo = m_pOwner->GetListInfo();CRenderClip clip;CRenderClip::GenerateClip(hDC, rcTemp, clip);CControlUI::DoPaint(hDC, rcPaint, pStopControl);if (0 < m_items.GetSize()){RECT rc = m_rcItem;rc.left += m_rcInset.left;rc.top += m_rcInset.top;rc.right -= m_rcInset.right;rc.bottom -= m_rcInset.bottom;if (NULL != m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible()){rc.right -= m_pVerticalScrollBar->GetFixedWidth();}if (NULL != m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible()){rc.bottom -= m_pHorizontalScrollBar->GetFixedHeight();}if (!::IntersectRect(&rcTemp, &rcPaint, &rc)){for (int it = 0; it < m_items.GetSize(); ++it){CControlUI *pControl = static_cast<CControlUI*>(m_items[it]);if (pControl == pStopControl) return false;if (!pControl->IsVisible()) continue;if (!::IntersectRect(&rcTemp, &rcPaint, &pControl->GetPos())) continue;if (pControl->IsFloat()){if (!::IntersectRect(&rcTemp, &m_rcItem, &pControl->GetPos())) continue;if (!pControl->Paint(hDC, rcPaint, pStopControl)) return false;}}}else{int iDrawIndex = 0;CRenderClip childClip;CRenderClip::GenerateClip(hDC, rcTemp, childClip);for (int it = 0; it < m_items.GetSize(); ++it){CControlUI *pControl = static_cast<CControlUI*>(m_items[it]);if (pControl == pStopControl) return false;if (!pControl->IsVisible()) continue;if (!pControl->IsFloat()){IListItemUI *pListItem = static_cast<IListItemUI*>(pControl->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->SetDrawIndex(iDrawIndex);iDrawIndex += 1;}if (NULL != pListInfo && 0 < pListInfo->iHLineSize){// 因为没有为最后一个预留分割条长度,如果list铺满,最后一条不会显示RECT rcPadding = pControl->GetPadding();const RECT &rcPos = pControl->GetPos();RECT rcBottomLine = {rcPos.left, rcPos.bottom + rcPadding.bottom, rcPos.right, rcPos.bottom + rcPadding.bottom + pListInfo->iHLineSize};if (::IntersectRect(&rcTemp, &rcPaint, &rcBottomLine)){rcBottomLine.top += pListInfo->iHLineSize / 2;rcBottomLine.bottom = rcBottomLine.top;CRenderEngine::DrawLine(hDC, rcBottomLine, pListInfo->iHLineSize, GetAdjustColor(pListInfo->dwHLineColor));}}}if (!::IntersectRect(&rcTemp, &rcPaint, &pControl->GetPos())) continue;if (pControl->IsFloat()){if (!::IntersectRect(&rcTemp, &m_rcItem, &pControl->GetPos())) continue;CRenderClip::UseOldClipBegin(hDC, childClip);if (!pControl->Paint(hDC, rcPaint, pStopControl)) return false;CRenderClip::UseOldClipEnd(hDC, childClip);}else{if (!::IntersectRect(&rcTemp, &rc, &pControl->GetPos())) continue;if (!pControl->Paint(hDC, rcPaint, pStopControl)) return false;}}}}if (NULL != m_pVerticalScrollBar){if (m_pVerticalScrollBar == pStopControl) return false;if (m_pVerticalScrollBar->IsVisible()){if (::IntersectRect(&rcTemp, &rcPaint, &m_pVerticalScrollBar->GetPos())){if (!m_pVerticalScrollBar->Paint(hDC, rcPaint, pStopControl)) return false;}}}if (NULL != m_pHorizontalScrollBar){if (m_pHorizontalScrollBar == pStopControl) return false;if (m_pHorizontalScrollBar->IsVisible()){if (::IntersectRect(&rcTemp, &rcPaint, &m_pHorizontalScrollBar->GetPos())){if (!m_pHorizontalScrollBar->Paint(hDC, rcPaint, pStopControl)) return false;}}}return true;
}// ------
class CEditCombo_ComboWnd : public CWindowWnd
{public:void Init(IEditCombo_ComboUI *pOwner, bool bNoFocus = false);RECT CalPos();LPCTSTR GetWindowClassName() const;void OnFinalMessage(HWND hWnd);LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);void EnsureVisible(int iIndex);void Scroll(int dx, int dy);#if (_WIN32_WINNT >= 0x0501)virtual UINT GetClassStyle() const;
#endif// 模糊查询显示itemvoid FuzzyQueryShowItem();public:CPaintManagerUI m_pm;IEditCombo_ComboUI *m_pOwner;CVerticalLayoutUI *m_pLayout;int m_iOldSel;bool m_bScrollbarClicked;  // bool m_bNoFocus;  // 不设置焦点
};void CEditCombo_ComboWnd::Init(IEditCombo_ComboUI *pOwner, bool bNoFocus /* = false */)
{m_pOwner = pOwner;m_bNoFocus = bNoFocus;m_pLayout = NULL;m_iOldSel = m_pOwner->GetCurSel();m_bScrollbarClicked = false;// 计算位置大小SIZE szDrop = m_pOwner->GetDropBoxSize();RECT rcOwner = pOwner->GetPos();RECT rc = rcOwner;rc.top = rc.bottom;  // 父窗口的left、bottom为弹出窗口位置rc.bottom = rc.top + szDrop.cy;  // 高度if (0 < szDrop.cx){rc.right = rc.left + szDrop.cx;  // 宽度}// 计算所有item的总高度SIZE szAvailable = {rc.right - rc.left, rc.bottom - rc.top};int cyFixed = 0;for (int it = 0; it < pOwner->GetCount(); ++it){CControlUI *pControl = static_cast<CControlUI*>(pOwner->GetItemAt(it));if (pControl->IsVisible()){SIZE sz = pControl->EstimateSize(szAvailable);cyFixed += sz.cy;}}cyFixed += 4;  // CVerticalLyoutUI默认的Inset高度//cyFixed += 100;  // test// 弹出框的高度rc.bottom = rc.top + min(cyFixed, szDrop.cy);::MapWindowRect(pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc);MONITORINFO oMonitor = {};oMonitor.cbSize = sizeof(oMonitor);::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);CDuiRect rcWork = oMonitor.rcWork;if (rc.bottom > rcWork.bottom){rc.left = rcOwner.left;rc.right = rcOwner.right;if (0 < szDrop.cx){rc.right = rc.left + szDrop.cx;}rc.top = rcOwner.top - min(cyFixed, szDrop.cy);rc.bottom = rcOwner.top;::MapWindowRect(pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc);}Create(pOwner->GetManager()->GetPaintWindow(), NULL, WS_POPUP, WS_EX_TOOLWINDOW, rc);//  HWND hWndParent = m_hWnd;//    while (NULL != ::GetParent(hWndParent))//  {//         hWndParent = ::GetParent(hWndParent);//    }//     //::SendMessage(hWndParent, WM_NCACTIVATE, TRUE, 0L);if (!m_bNoFocus){::ShowWindow(m_hWnd, SW_SHOW);}else{// 显示窗口但不激活(设置焦点)::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);}
}
RECT CEditCombo_ComboWnd::CalPos()
{ASSERT(NULL != m_pOwner);// 计算位置大小SIZE szDrop = m_pOwner->GetDropBoxSize();RECT rcOwner = m_pOwner->GetPos();RECT rc = rcOwner;rc.top = rc.bottom;  // 父窗口的left、bottom为弹出窗口位置rc.bottom = rc.top + szDrop.cy;  // 高度if (0 < szDrop.cx){rc.right = rc.left + szDrop.cx;  // 宽度}// 计算所有item的总高度SIZE szAvailable = {rc.right - rc.left, rc.bottom - rc.top};int cyFixed = 0;for (int it = 0; it < m_pOwner->GetCount(); ++it){CControlUI *pControl = static_cast<CControlUI*>(m_pOwner->GetItemAt(it));if (pControl->IsVisible()){SIZE sz = pControl->EstimateSize(szAvailable);cyFixed += sz.cy;}}cyFixed += 4;  // CVerticalLyoutUI默认的Inset高度//cyFixed += 100;  // test// 弹出框的高度rc.bottom = rc.top + min(cyFixed, szDrop.cy);::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc);MONITORINFO oMonitor = {};oMonitor.cbSize = sizeof(oMonitor);::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);CDuiRect rcWork = oMonitor.rcWork;if (rc.bottom > rcWork.bottom){rc.left = rcOwner.left;rc.right = rcOwner.right;if (0 < szDrop.cx){rc.right = rc.left + szDrop.cx;}rc.top = rcOwner.top - min(cyFixed, szDrop.cy);rc.bottom = rcOwner.top;::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc);}return rc;
}
LPCTSTR CEditCombo_ComboWnd::GetWindowClassName() const
{return _T("EditCombo_ComboWnd");
}
void CEditCombo_ComboWnd::OnFinalMessage(HWND hWnd)
{m_pOwner->m_pComboWindow = NULL;m_pOwner->m_uButtonState &= ~UISTATE_PUSHED;m_pOwner->Invalidate();delete this;
}
LRESULT CEditCombo_ComboWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{if (WM_CREATE == uMsg){m_pm.SetForceUseSharedRes(true);m_pm.Init(m_hWnd);m_pLayout = new CEditCombo_ComboBodyUI(m_pOwner);m_pLayout->SetManager(&m_pm, NULL, true);LPCTSTR pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(_T("VerticalLayout"));if (pDefaultAttributes){m_pLayout->SetAttributeList(pDefaultAttributes);}//m_pLayout->SetInset(CDuiRect(1, 1, 1, 1));m_pLayout->SetBkColor(0xFFFFFFFF);m_pLayout->SetBorderColor(0xFFC6C7D2);m_pLayout->SetBorderSize(1);m_pLayout->SetAutoDestroy(false);m_pLayout->EnableScrollBar();m_pLayout->SetAttributeList(m_pOwner->GetDropBoxAttributeList());for (int i = 0; i < m_pOwner->GetCount(); ++i){m_pLayout->Add(static_cast<CControlUI*>(m_pOwner->GetItemAt(i)));}m_pm.AttachDialog(m_pLayout);FuzzyQueryShowItem();return 0;}else if (WM_CLOSE == uMsg){m_pOwner->SetManager(m_pOwner->GetManager(), m_pOwner->GetParent(), false);if (!m_pOwner->IsFloat()){m_pOwner->SetPos(m_pOwner->GetPos(), false);}else{m_pOwner->SetPos(m_pOwner->GetRelativePos(), false);}//m_pOwner->SetFocus();}else if (WM_LBUTTONDOWN == uMsg || WM_LBUTTONDBLCLK == uMsg){POINT pt = {0};::GetCursorPos(&pt);::ScreenToClient(m_pm.GetPaintWindow(), &pt);CControlUI *pControl = m_pm.FindControl(pt);if (NULL != pControl && 0 == _tcscmp(pControl->GetClass(), DUI_CTR_SCROLLBAR)){m_bScrollbarClicked = true;}}else if (WM_LBUTTONUP == uMsg){if (m_bScrollbarClicked){m_bScrollbarClicked = false;}else{POINT pt = {0};::GetCursorPos(&pt);::ScreenToClient(m_pm.GetPaintWindow(), &pt);CControlUI* pControl = m_pm.FindControl(pt);if (NULL != pControl && 0 != _tcscmp(pControl->GetClass(), DUI_CTR_SCROLLBAR)){PostMessage(WM_KILLFOCUS);}}}else if (WM_KEYDOWN == uMsg){switch (wParam){case VK_ESCAPE:m_pOwner->SelectItem(m_iOldSel, true);EnsureVisible(m_iOldSel);case VK_RETURN:PostMessage(WM_KILLFOCUS);break;default:TEventUI event;event.Type = UIEVENT_KEYDOWN;event.chKey = (TCHAR)wParam;m_pOwner->DoEvent(event);EnsureVisible(m_pOwner->GetCurSel());return 0;}}else if (WM_MOUSEWHEEL == uMsg){int zDelta = (int)(short)HIWORD(wParam);TEventUI event = {0};event.Type = UIEVENT_SCROLLWHEEL;event.wParam = MAKELPARAM(zDelta, 0);event.lParam = lParam;event.dwTimestamp = ::GetTickCount();
//      m_pOwner->DoEvent(event);
//      EnsureVisible(m_pOwner->GetCurSel());if (NULL != m_pLayout){m_pLayout->DoEvent(event);}return 0;}else if (WM_KILLFOCUS == uMsg){if (!m_bNoFocus){if (m_hWnd != (HWND)wParam){HWND hWnd = ::GetFocus();HWND hParentWnd = NULL;bool bIsChildFocus = false;while (hParentWnd = ::GetParent(hWnd)){if (m_hWnd == hParentWnd){bIsChildFocus = true;break;}hWnd = hParentWnd;}if (!bIsChildFocus){PostMessage(WM_CLOSE);return 0;}}}}LRESULT lRes = 0;if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
}
void CEditCombo_ComboWnd::EnsureVisible(int iIndex)
{if (0 <= m_pOwner->GetCurSel()){m_pLayout->FindSelectable(m_pOwner->GetCurSel(), false);RECT rcItem = m_pLayout->GetItemAt(iIndex)->GetPos();RECT rcList = m_pLayout->GetPos();CScrollBarUI *pHorizontalScrollBar = m_pLayout->GetHorizontalScrollBar();if (NULL != pHorizontalScrollBar && pHorizontalScrollBar->IsVisible()){rcList.bottom -= pHorizontalScrollBar->GetFixedHeight();}//int iPos = m_pLayout->GetScrollPos().cy;if (rcItem.top >= rcList.top && rcItem.bottom < rcList.bottom) return;int dy = 0;if (rcItem.top < rcList.top){dy = rcItem.top - rcList.top;}if (rcItem.bottom > rcList.bottom){dy = rcItem.bottom - rcList.bottom;}Scroll(0, dy);}
}
void CEditCombo_ComboWnd::Scroll(int dx, int dy)
{if (0 != dx || 0 != dy){SIZE sz = m_pLayout->GetScrollPos();m_pLayout->SetScrollPos(CDuiSize(sz.cx + dx, sz.cy + dy));}
}
#if (_WIN32_WINNT >= 0x0501)
UINT CEditCombo_ComboWnd::GetClassStyle() const
{return __super::GetClassStyle() | CS_DROPSHADOW;
}
#endif
void CEditCombo_ComboWnd::FuzzyQueryShowItem()
{CDuiString text = m_pOwner->GetText();//if (!text.IsEmpty()){if (NULL != m_pLayout){// 计算位置大小SIZE szDrop = m_pOwner->GetDropBoxSize();RECT rcOwner = m_pOwner->GetPos();RECT rc = rcOwner;rc.top = rc.bottom;  // 父窗口的left、bottom为弹出窗口位置rc.bottom = rc.top + szDrop.cy;  // 高度if (0 < szDrop.cx){rc.right = rc.left + szDrop.cx;  // 宽度}// 计算所有item的总高度SIZE szAvailable = {rc.right - rc.left, rc.bottom - rc.top};int cyFixed = 0;int iCount = 0;for (int i = 0; i < m_pLayout->GetCount(); ++i){CControlUI *pItem = m_pOwner->GetItemAt(i);if (NULL != pItem){const TCHAR *pstr = NULL;pstr = _tcsstr(pItem->GetText().GetData(), text.GetData());if (NULL != pstr || text.IsEmpty()){pItem->SetVisible(true);SIZE sz = pItem->EstimateSize(szAvailable);cyFixed += sz.cy;cyFixed += 4;  // CVerticalLyoutUI默认的Inset高度++iCount;}else{pItem->SetVisible(false);}}}if (0 < iCount){//cyFixed += 4;  // CVerticalLyoutUI默认的Inset高度//cyFixed += 20;  // test//RECT rcInset = m_pLayout->GetInset();//cyFixed += (iCount * (rcInset.bottom + rcInset.top));//cyFixed += (iCount * 4);// 弹出框的高度rc.bottom = rc.top + min(cyFixed, szDrop.cy);::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc);MONITORINFO oMonitor = {};oMonitor.cbSize = sizeof(oMonitor);::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);CDuiRect rcWork = oMonitor.rcWork;if (rc.bottom > rcWork.bottom){rc.left = rcOwner.left;rc.right = rcOwner.right;if (0 < szDrop.cx){rc.right = rc.left + szDrop.cx;}rc.top = rcOwner.top - min(cyFixed, szDrop.cy);rc.bottom = rcOwner.top;::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc);}// 修改大小::SetWindowPos(m_hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);}else{this->PostMessage(WM_CLOSE);}}}
}
////CEditComboUI::CEditComboUI(void): CContainerUI(), IEditCombo_EditUI(), m_iWindowStyls(0), m_iFont(-1), m_bReadOnly(false), m_bPasswordMode(false), m_szPasswordChar(_T('*')), m_uMaxChar(255), m_bAutoSelAll(false), m_rcTextPadding(CDuiRect(4, 3, 4, 3)), m_uButtonState(0), m_dwEditBkColor(0xFFFFFFFF), m_dwEditTextColor(0x00000000), m_dwTipValueColor(0x66666666), m_sTipValue(_T("")), m_sSrcTipValue(_T("")), m_uTextStyle(DT_VCENTER|DT_SINGLELINE), m_dwTextColor(0), m_dwDisabledTextColor(0), m_iCurSel(-1), m_bShowText(true), m_bSelectCloseFlag(true), m_sDropBoxAttributes(_T("")), m_szDropBox(CDuiSize(0, 150))
{SetBkColor(0xFFFFFFFF);m_ListInfo.nColumns = 0;m_ListInfo.uFixedHeight = 0;m_ListInfo.nFont = -1;m_ListInfo.uTextStyle = DT_VCENTER | DT_SINGLELINE;m_ListInfo.dwTextColor = 0xFF000000;m_ListInfo.dwBkColor = 0;m_ListInfo.bAlternateBk = false;m_ListInfo.dwSelectedTextColor = 0xFF000000;m_ListInfo.dwSelectedBkColor = 0xFFC1E3FF;m_ListInfo.dwHotTextColor = 0xFF000000;m_ListInfo.dwHotBkColor = 0xFFE9F5FF;m_ListInfo.dwDisabledTextColor = 0xFFCCCCCC;m_ListInfo.dwDisabledBkColor = 0xFFFFFFFF;m_ListInfo.iHLineSize = 0;m_ListInfo.dwHLineColor = 0xFF3C3C3C;m_ListInfo.iVLineSize = 0;m_ListInfo.dwVLineColor = 0xFF3C3C3C;m_ListInfo.bShowHtml = false;m_ListInfo.bMultiExpandable = false;::ZeroMemory(&m_ListInfo.rcTextPadding, sizeof(m_ListInfo.rcTextPadding));::ZeroMemory(&m_ListInfo.rcColumn, sizeof(m_ListInfo.rcColumn));
}
CEditComboUI::~CEditComboUI(void)
{}LPCTSTR CEditComboUI::GetClass() const
{return DUI_CTR_EDITCOMBO;
}
LPVOID CEditComboUI::GetInterface(LPCTSTR pstrName)
{if (0 == _tcscmp(pstrName, DUI_CTR_ILISTOWNER)){return static_cast<IListOwnerUI*>(this);}if (0 == _tcscmp(pstrName, DUI_CTR_EDITCOMBO)){return static_cast<CEditComboUI*>(this);}else{return CContainerUI::GetInterface(pstrName);}
}
UINT CEditComboUI::GetControlFlags() const
{if (!IsEnabled()){return CControlUI::GetControlFlags();}return UIFLAG_SETCURSOR | UIFLAG_TABSTOP;
}
HWND CEditComboUI::GetNativeWindow() const
{if (NULL != m_pEditWindow){return m_pEditWindow->GetHWND();}return NULL;
}
HWND CEditComboUI::GetNativeEditHWND() const
{return GetNativeWindow();
}int CEditComboUI::GetWindowStyls() const
{return m_iWindowStyls;
}
UINT CEditComboUI::GetTextStyle() const
{//return CContainerUI::GetTextStyle();return 0;
}
int CEditComboUI::GetFont() const
{return m_iFont;
}
CPaintManagerUI* CEditComboUI::GetManager() const
{return CContainerUI::GetManager();
}
CControlUI* CEditComboUI::GetParent() const
{return CControlUI::GetParent();
}
void CEditComboUI::Invalidate()
{return CContainerUI::Invalidate();
}bool CEditComboUI::IsEnabled() const
{return CControlUI::IsEnabled();
}
void CEditComboUI::SetEnabled(bool bEnable)
{CControlUI::SetEnabled(bEnable);if (!IsEnabled()){m_uButtonState = 0;}
}
CDuiString CEditComboUI::GetText() const
{return CControlUI::GetText();
}
void CEditComboUI::_SetText(LPCTSTR pstrText)
{m_sText = pstrText;
}
void CEditComboUI::SetText(LPCTSTR pstrText)
{_SetText(pstrText);if (NULL != m_pEditWindow){Edit_SetText(*m_pEditWindow, m_sText);}Invalidate();
}
RECT CEditComboUI::GetTextPadding() const
{return m_rcTextPadding;
}
void CEditComboUI::SetTextPadding(RECT rc)
{m_rcTextPadding = rc;Invalidate();
}
void CEditComboUI::SetTextPadding(LPCTSTR pstrValue)
{RECT rcTextPadding = {0};LPTSTR pstr = NULL;rcTextPadding.left = _tcstol(pstrValue, &pstr, 10);ASSERT(NULL != pstr);rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10);ASSERT(NULL != pstr);rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10);ASSERT(NULL != pstr);rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10);SetTextPadding(rcTextPadding);
}
bool CEditComboUI::IsVisible() const
{return CControlUI::IsVisible();
}
void CEditComboUI::TextChange()
{if (m_sText.IsEmpty() && FALSE){if (NULL != m_pComboWindow){m_pComboWindow->PostMessage(WM_CLOSE);Invalidate();}}else{if (NULL == m_pComboWindow){m_pComboWindow = new CEditCombo_ComboWnd;ASSERT(NULL != m_pComboWindow);m_pComboWindow->Init(this, true);if (NULL != m_pManager){m_pManager->SendNotify(this, DUI_MSGTYPE_DROPDOWN);}Invalidate();}else{m_pComboWindow->FuzzyQueryShowItem();}}
}
void CEditComboUI::EditDestroy()
{if (NULL != m_pComboWindow){m_pComboWindow->PostMessage(WM_CLOSE);Invalidate();}
}void CEditComboUI::SetPasswordMode(bool bPasswordMode)
{if (m_bPasswordMode != bPasswordMode){m_bPasswordMode = bPasswordMode;Invalidate();}
}
bool CEditComboUI::IsPasswordMode() const
{return m_bPasswordMode;
}
void CEditComboUI::SetPasswordChar(TCHAR szChar)
{if (m_szPasswordChar != szChar){m_szPasswordChar = szChar;if (NULL != m_pEditWindow){Edit_SetPasswordChar(*m_pEditWindow, m_szPasswordChar);}Invalidate();}
}
TCHAR CEditComboUI::GetPasswordChar() const
{return m_szPasswordChar;
}
void CEditComboUI::SetMaxChar(UINT uMax)
{if (m_uMaxChar != uMax){m_uMaxChar = uMax;if (NULL != m_pEditWindow){Edit_LimitText(*m_pEditWindow, m_uMaxChar);}}
}
UINT CEditComboUI::GetMaxChar() const
{return m_uMaxChar;
}
void CEditComboUI::SetReadOnly(bool bReadOnly)
{if (m_bReadOnly != bReadOnly){m_bReadOnly = bReadOnly;if (NULL != m_pEditWindow){Edit_SetReadOnly(*m_pEditWindow, m_bReadOnly);}Invalidate();}
}
bool CEditComboUI::IsReadOnly() const
{return m_bReadOnly;
}
void CEditComboUI::SetNumberOnly(bool bNumberOnly)
{if (bNumberOnly){m_iWindowStyls |= ES_NUMBER;}else{m_iWindowStyls &= ~ES_NUMBER;}
}
bool CEditComboUI::IsNumberOnly() const
{return (0 != (m_iWindowStyls & ES_NUMBER));
}
void CEditComboUI::SetAutoSelAll(bool bAuto)
{if (m_bAutoSelAll != bAuto){m_bAutoSelAll = bAuto;}
}
bool CEditComboUI::IsAutoSelAll() const
{return m_bAutoSelAll;
}void CEditComboUI::SetFont(int index)
{m_iFont = index;
}
void CEditComboUI::SetPos(RECT rc, bool bNeedInvalidate)
{RECT rcNULL = {0};for (int i = 0; i < m_items.GetSize(); ++i){static_cast<CControlUI*>(m_items[i])->SetPos(rcNULL, false);}CControlUI::SetPos(rc, bNeedInvalidate);if (NULL != m_pEditWindow){RECT rcPos = m_pEditWindow->CalPos();if (::IsRectEmpty(&rcPos)){::ShowWindow(m_pEditWindow->GetHWND(), SW_HIDE);}else{::SetWindowPos(m_pEditWindow->GetHWND(), NULL, rcPos.left, rcPos.top, rcPos.right - rcPos.left, rcPos.bottom - rcPos.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);}}if (NULL != m_pComboWindow){RECT rcPos = m_pComboWindow->CalPos();::GetWindowRect(m_pComboWindow->GetHWND(), &rcPos);if (::IsRectEmpty(&rcPos)){::ShowWindow(m_pComboWindow->GetHWND(), SW_HIDE);}else{::SetWindowPos(m_pComboWindow->GetHWND(), NULL, rcPos.left, rcPos.top, rcPos.right - rcPos.left, rcPos.bottom - rcPos.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);}}
}
const RECT& CEditComboUI::GetPos() const
{return CControlUI::GetPos();
}
RECT CEditComboUI::GetRelativePos() const
{return CControlUI::GetRelativePos();
}
RECT CEditComboUI::GetClientPos() const
{return CControlUI::GetClientPos();
}
void CEditComboUI::Move(SIZE szOffset, bool bNeedInvalidate)
{CControlUI::Move(szOffset, bNeedInvalidate);if (NULL != m_pEditWindow){RECT rcPos = m_pEditWindow->CalPos();if (::IsRectEmpty(&rcPos)){::ShowWindow(m_pEditWindow->GetHWND(), SW_HIDE);}else{::SetWindowPos(m_pEditWindow->GetHWND(), NULL, rcPos.left, rcPos.top, rcPos.right - rcPos.left, rcPos.bottom - rcPos.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);}}
}
void CEditComboUI::SetVisible(bool bVisible)
{CControlUI::SetVisible(bVisible);if (!IsVisible() && NULL != m_pEditWindow){m_pManager->SetFocus(NULL);}
}
void CEditComboUI::SetInternVisible(bool bVisible)
{if (!IsVisible() && NULL != m_pEditWindow){m_pManager->SetFocus(NULL);}
}
SIZE CEditComboUI::EstimateSize(SIZE szAvailable)
{if (0 == m_cxyFixed.cy){return CDuiSize(m_cxyFixed.cx, m_pManager->GetFontInfo(GetFont())->tm.tmHeight + 8);}return CControlUI::EstimateSize(szAvailable);
}
void CEditComboUI::PaintText(HDC hDC)
{DWORD dwCurTextColor = m_dwTextColor;if (0 == m_dwTextColor){dwCurTextColor = m_dwTextColor = m_pManager->GetDefaultFontColor();}if (0 == m_dwDisabledTextColor){m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor();}CDuiString sText;if (GetText().IsEmpty()){sText = m_sTipValue;dwCurTextColor = m_dwTipValueColor;}else{if (m_bPasswordMode){sText.Empty();LPCTSTR p = m_sText.GetData();while (*p != _T('\0')){sText += m_szPasswordChar;p = ::CharNext(p);}}else{sText = m_sText;}}RECT rc = m_rcItem;rc.left += m_rcTextPadding.left;rc.right -= m_rcTextPadding.right;rc.top += m_rcTextPadding.top;rc.bottom -= m_rcTextPadding.bottom;CRenderEngine::DrawText(hDC, m_pManager, rc, sText, IsEnabled() ? dwCurTextColor : m_dwDisabledTextColor, m_iFont, DT_SINGLELINE | m_uTextStyle);
}
void CEditComboUI::PaintStatusImage(HDC hDC)
{if (IsFocused()) m_uButtonState |= UISTATE_FOCUSED;else m_uButtonState &= ~UISTATE_FOCUSED;if (!IsEnabled()) m_uButtonState |= UISTATE_DISABLED;else m_uButtonState &= ~UISTATE_DISABLED;if (0 != (m_uButtonState & UISTATE_DISABLED)){if (DrawImage(hDC, m_diDisabled)) return;}else if (0 != (m_uButtonState & UISTATE_PUSHED)){if (DrawImage(hDC, m_diPushed)) return;}else if (0 != (m_uButtonState & UISTATE_HOT)){if (DrawImage(hDC, m_diHot)) return;}else if (0 != (m_uButtonState & UISTATE_FOCUSED)){if (DrawImage(hDC, m_diFocused)) return;}DrawImage(hDC, m_diNormal);
}LPCTSTR CEditComboUI::GetNormalImage()
{return m_diNormal.sDrawString;
}
void CEditComboUI::SetNormalImage(LPCTSTR pStrImage)
{if (m_diNormal.sDrawString != pStrImage|| NULL == m_diNormal.pImageInfo){m_diNormal.Clear();m_diNormal.sDrawString = pStrImage;Invalidate();}
}
LPCTSTR CEditComboUI::GetHotImage()
{return m_diHot.sDrawString;
}
void CEditComboUI::SetHotImage(LPCTSTR pStrImage)
{if (m_diHot.sDrawString != pStrImage|| NULL == m_diHot.pImageInfo){m_diHot.Clear();m_diHot.sDrawString = pStrImage;Invalidate();}
}
LPCTSTR CEditComboUI::GetPushedImage() const
{return m_diPushed.sDrawString;
}
void CEditComboUI::SetPushedIMage(LPCTSTR pStrImage)
{if (m_diPushed.sDrawString != pStrImage|| NULL == m_diPushed.pImageInfo){m_diPushed.Clear();m_diPushed.sDrawString = pStrImage;Invalidate();}
}
LPCTSTR CEditComboUI::GetFocusedImage()
{return m_diFocused.sDrawString;
}
void CEditComboUI::SetFocusedImage(LPCTSTR pStrImage)
{if (m_diFocused.sDrawString != pStrImage|| NULL == m_diFocused.pImageInfo){m_diFocused.Clear();m_diFocused.sDrawString = pStrImage;Invalidate();}
}
LPCTSTR CEditComboUI::GetDisabledImage()
{return m_diDisabled.sDrawString;
}
void CEditComboUI::SetDisabledImage(LPCTSTR pStrImage)
{if (m_diDisabled.sDrawString != pStrImage|| NULL == m_diDisabled.pImageInfo){m_diDisabled.Clear();m_diDisabled.sDrawString = pStrImage;Invalidate();}
}
DWORD CEditComboUI::GetTextColor() const
{return m_dwTextColor;
}
void CEditComboUI::SetNativeEditBkColor(LPCTSTR pStrColor)
{if (*pStrColor == _T('#')){pStrColor = ::CharNext(pStrColor);}LPTSTR pstr = NULL;DWORD clrColor = _tcstoul(pStrColor, &pstr, 16);m_dwEditBkColor = clrColor;
}
DWORD CEditComboUI::GetNativeEditBkColor() const
{return m_dwEditBkColor;
}
void CEditComboUI::SetNativeEditTextColor( LPCTSTR pStrColor )
{if (*pStrColor == _T('#')){pStrColor = ::CharNext(pStrColor);}LPTSTR pstr = NULL;DWORD clrColor = _tcstoul(pStrColor, &pstr, 16);m_dwEditTextColor = clrColor;
}
DWORD CEditComboUI::GetNativeEditTextColor() const
{return m_dwEditTextColor;
}
void CEditComboUI::SetTipValue(LPCTSTR pStrTipValue)
{if (m_sText != _T("")){m_sText = pStrTipValue;}m_sSrcTipValue = pStrTipValue;m_sTipValue = pStrTipValue;
}
void CEditComboUI::SetTipValueColor(LPCTSTR pStrColor)
{if (*pStrColor == _T('#')){pStrColor = ::CharNext(pStrColor);}LPTSTR pstr = NULL;DWORD clrColor = _tcstoul(pStrColor, &pstr, 16);m_dwTipValueColor = clrColor;
}
DWORD CEditComboUI::GetTipValueColor()
{return m_dwTipValueColor;
}
CDuiString CEditComboUI::GetTipValue()
{return m_sTipValue;
}
LPCTSTR CEditComboUI::GetSrcTipValue()
{return m_sSrcTipValue;
}void CEditComboUI::SetTextStyle(UINT uStyle)
{m_uTextStyle = uStyle;
}
void CEditComboUI::SetTextColor(DWORD dwTextColor)
{m_dwTextColor = dwTextColor;
}
void CEditComboUI::SetDisabledTextColor(DWORD dwTextColor)
{m_dwDisabledTextColor = dwTextColor;
}
DWORD CEditComboUI::GetDisabledTextColor() const
{return m_dwDisabledTextColor;
}DWORD CEditComboUI::StringToColor(LPCTSTR pstrColor)
{if (*pstrColor == _T('#')){pstrColor = ::CharNext(pstrColor);}LPTSTR pstr = NULL;return _tcstoul(pstrColor, &pstr, 16);
}
void CEditComboUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{if (0 == _tcscmp(pstrName, _T("readonly"))) SetReadOnly(0 == _tcscmp(pstrValue, _T("true")));else if (0 == _tcscmp(pstrName, _T("numberonly"))) SetNumberOnly(0 == _tcscmp(pstrValue, _T("true")));else if (0 == _tcscmp(pstrName, _T("password"))) SetPasswordMode(0 == _tcscmp(pstrValue, _T("true")));else if (0 == _tcscmp(pstrName, _T("autoselall"))) SetAutoSelAll(0 == _tcscmp(pstrValue, _T("true")));else if (0 == _tcscmp(pstrName, _T("maxchar"))) SetMaxChar(_ttoi(pstrValue));else if (0 == _tcscmp(pstrName, _T("normalimage"))) SetNormalImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("hotimage"))) SetHotImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("focusedimage"))) SetFocusedImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("pushedimage"))) SetPushedIMage(pstrValue);else if (0 == _tcscmp(pstrName, _T("disabledimage"))) SetDisabledImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("nativebkcolor"))) SetNativeEditBkColor(pstrValue);else if (0 == _tcscmp(pstrName, _T("tipvalue"))) SetTipValue(pstrValue);else if (0 == _tcscmp(pstrName, _T("tipvaluecolor"))) SetTipValueColor(pstrValue);else if (0 == _tcscmp(pstrName, _T("nativetextcolor"))) SetNativeEditTextColor(pstrValue);else if (0 == _tcscmp(pstrName, _T("textpadding"))) SetTextPadding(pstrValue);else if (0 == _tcscmp(pstrName, _T("showtext"))) SetShowText(0 == _tcscmp(pstrValue, _T("true")));else if (0 == _tcscmp(pstrName, _T("dropbox"))) SetDropBoxAttributeList(pstrValue);else if (0 == _tcscmp(pstrName, _T("dropboxsize"))) SetDropBoxSize(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemheight"))) m_ListInfo.uFixedHeight = _ttoi(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemfont"))) m_ListInfo.nFont = _ttoi(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemalign"))) SetItemAlign(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemtextpadding"))) SetItemTextPadding(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemtextcolor"))) SetItemTextColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itembkcolor"))) SetItemBkColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itembkimage"))) SetItemBkImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemaltbk"))) SetItemAlternateBk(0 == _tcscmp(pstrValue, _T("true")));else if (0 == _tcscmp(pstrName, _T("itemselectedtextcolor"))) SetSelectedItemTextColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemselectedbkcolor"))) SetItemBkColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemselectedimage"))) SetSelectedItemImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemhottextcolor"))) SetHotItemTextColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemhotbkcolor"))) SetHotItemBkColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemhotimage"))) SetHotItemImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemdisabledtextcolor"))) SetDisabledItemTextColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemdisabledbkcolor"))) SetDisabledItemBkColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemdisabledimage"))) SetDisabledItemImage(pstrValue);else if (0 == _tcscmp(pstrName, _T("itemvlinesize"))) SetItemVLineSize(_ttoi(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemvlinecolor"))) SetItemVLineColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemhlinesize"))) SetItemHLineSize(_ttoi(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemhlinecolor"))) SetItemHLineColor(StringToColor(pstrValue));else if (0 == _tcscmp(pstrName, _T("itemshowhtml"))) SetItemShowHtml(0 == _tcscmp(pstrValue, _T("true")));else CContainerUI::SetAttribute(pstrName, pstrValue);
}void CEditComboUI::DoEvent(TEventUI& event)
{if (!IsMouseEnabled()&& event.Type > UIEVENT__MOUSEBEGIN&& event.Type < UIEVENT__MOUSEEND){if (NULL != m_pParent){return m_pParent->DoEvent(event);}else{return CContainerUI::DoEvent(event);}}if (UIEVENT_SETCURSOR == event.Type && IsEnabled()){::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_IBEAM)));return;}if (UIEVENT_WINDOWSIZE == event.Type){if (NULL != m_pEditWindow){m_pManager->SetFocusNeeded(this);}}if (UIEVENT_SCROLLWHEEL == event.Type){//      if (IsEnabled()) {//          bool bDownward = LOWORD(event.wParam) == SB_LINEDOWN;
//          SetSelectCloseFlag(false);
//          SelectItem(FindSelectable(m_iCurSel + (bDownward ? 1 : -1), bDownward));
//          SetSelectCloseFlag(true);
//          return;
//      }if (NULL != m_pComboWindow){int iDirect = LOWORD(event.wParam);WPARAM wp = MAKEWPARAM(0, LOWORD(event.wParam));m_pComboWindow->PostMessage(WM_MOUSEWHEEL, wp, event.lParam);}}if (UIEVENT_SETFOCUS == event.Type && IsEnabled()){if (NULL != m_pEditWindow){TextChange();return;}else{m_pEditWindow = new CEditCombo_EditWnd;ASSERT(NULL != m_pEditWindow);m_pEditWindow->Init(this);Invalidate();TextChange();}}if (UIEVENT_KILLFOCUS == event.Type && IsEnabled()){if (NULL != m_pEditWindow){//m_pEditWindow->PostMessage(WM_KILLFOCUS);}Invalidate();}if (UIEVENT_BUTTONDOWN == event.Type|| UIEVENT_DBLCLICK == event.Type|| UIEVENT_RBUTTONDOWN == event.Type){if (IsEnabled()){GetManager()->ReleaseCapture();if (IsFocused() && NULL == m_pEditWindow){m_pEditWindow = new CEditCombo_EditWnd();ASSERT(NULL != m_pEditWindow);m_pEditWindow->Init(this);TextChange();}else if (NULL != m_pEditWindow){if (!m_bAutoSelAll){POINT pt = event.ptMouse;pt.x -= m_rcItem.left + m_rcTextPadding.left;pt.y -= m_rcItem.top + m_rcTextPadding.top;Edit_SetSel(*m_pEditWindow, 0, 0);::SendMessage(*m_pEditWindow, WM_LBUTTONDOWN, event.wParam, MAKELPARAM(pt.x, pt.y));}}}return;}if (UIEVENT_MOUSEENTER == event.Type){if (::PtInRect(&m_rcItem, event.ptMouse)){if (IsEnabled()){if (0 != (m_uButtonState & UISTATE_HOT)){m_uButtonState &= ~UISTATE_HOT;Invalidate();}}if (NULL != m_pManager){m_pManager->RemoveMouseLeaveNeeded(this);}}else{if (NULL != m_pManager){m_pManager->AddMouseLeaveNeeded(this);}return;}}CContainerUI::DoEvent(event);
}bool CEditComboUI::IsFloat() const
{return CContainerUI::IsFloat();
}
int CEditComboUI::GetCurSel() const
{return m_iCurSel;
}
int CEditComboUI::GetCount() const
{return CContainerUI::GetCount();
}
void CEditComboUI::SetManager(CPaintManagerUI* pManager, CControlUI* pParent, bool bInit /* = true */)
{// 必须CContainerUI,否则会导致item中的m_pManager为NULL而导致崩溃//return CControlUI::SetManager(pManager, pParent, bInit);return CContainerUI::SetManager(pManager, pParent, bInit);
}
CControlUI* CEditComboUI::GetItemAt(int id)
{return CContainerUI::GetItemAt(id);
}
void CEditComboUI::SetFocus()
{CControlUI::SetFocus();
}void CEditComboUI::SetDropBoxSize(SIZE szSize)
{m_szDropBox = szSize;
}
void CEditComboUI::SetDropBoxSize(LPCTSTR pstrValue)
{SIZE szDropBoxSize = {0};LPTSTR pstr = NULL;szDropBoxSize.cx = _tcstol(pstrValue, &pstr, 10);ASSERT(pstr);szDropBoxSize.cy = _tcstol(pstrValue, &pstr, 10);ASSERT(pstr);SetDropBoxSize(szDropBoxSize);
}
SIZE CEditComboUI::GetDropBoxSize() const
{return m_szDropBox;
}
void CEditComboUI::SetDropBoxAttributeList(LPCTSTR pstrList)
{m_sDropBoxAttributes = pstrList;
}
CDuiString CEditComboUI::GetDropBoxAttributeList()
{return m_sDropBoxAttributes;
}
TListInfoUI* CEditComboUI::GetListInfo()
{return &m_ListInfo;
}bool CEditComboUI::SelectItem(int iIndex, bool bTakeFocus /* = false */, bool bTriggerEvent/* =true */, bool /* bMutil = false */)
{// if (m_bSelectCloseFlag && NULL != m_pComboWindow) m_pComboWindow->Close();if (iIndex == m_iCurSel) return true;int iOldSel = m_iCurSel;if (0 <= m_iCurSel){CControlUI *pControl = static_cast<CControlUI*>(m_items[m_iCurSel]);if (NULL != pControl){IListItemUI *pListItem = static_cast<IListItemUI*>(pControl->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->Select(false, bTriggerEvent);}m_iCurSel = -1;}}if (0 > iIndex) return false;if (0 == m_items.GetSize()) return false;if (iIndex >= m_items.GetSize()) iIndex = m_items.GetSize() - 1;CControlUI *pControl = static_cast<CControlUI*>(m_items[iIndex]);if (NULL == pControl || !pControl->IsEnabled()) return false;IListItemUI *pListItem = static_cast<IListItemUI*>(pControl->GetInterface(DUI_CTR_ILISTITEM));if (NULL == pListItem) return false;m_iCurSel = iIndex;//    if (NULL != m_pComboWindow || bTakeFocus) pControl->SetFocus();pListItem->Select(true, bTriggerEvent);if (NULL != m_pManager && bTriggerEvent){m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, m_iCurSel, iOldSel);}SetText(pControl->GetText());if (NULL != m_pEditWindow){::Edit_SetText(m_pEditWindow->GetHWND(), GetText());}Invalidate();return true;
}
bool CEditComboUI::SelectRange(int iIndex, bool bTakeFocus /* = false */, bool bTriggerEvent/* =true */, bool bMutil /* = false */)
{return false;
}
bool CEditComboUI::ExpandItem(int iIndex, bool bExpand /* = true */)
{return false;
}
int CEditComboUI::GetExpandedItem() const
{return -1;
}bool CEditComboUI::SetItemIndex(CControlUI* pControl, int iNewIndex)
{int iOrginnIndex = GetItemIndex(pControl);if (-1 == iOrginnIndex) return false;if (iOrginnIndex == iNewIndex) return true;IListItemUI *pSelectedListItem = NULL;if (0 <= m_iCurSel){pSelectedListItem = static_cast<IListItemUI*>(GetItemAt(m_iCurSel)->GetInterface(DUI_CTR_ILISTITEM));}if (!CContainerUI::SetItemIndex(pControl, iNewIndex)) return false;int iMinIndex = min(iOrginnIndex, iNewIndex);int iMaxIndex = max(iOrginnIndex, iNewIndex);for (int i = iMinIndex; i < iMaxIndex; ++i){CControlUI *p = GetItemAt(i);IListItemUI *pListItem = static_cast<IListItemUI*>(p->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->SetIndex(i);}}if (NULL != pSelectedListItem){m_iCurSel = pSelectedListItem->GetIndex();}return true;
}
bool CEditComboUI::SetMultiItemIndex(CControlUI* pStartControl, int iCount, int iNewStartIndex)
{if (NULL == pStartControl || 0 > iCount || 0 > iNewStartIndex) return false;int iStartIndex = GetItemIndex(pStartControl);if (iStartIndex == iNewStartIndex) return true;if (iStartIndex + iCount > GetCount()) return false;if (iNewStartIndex + iCount > GetCount()) return false;IListItemUI *pSelectedItem = NULL;if (0 <= m_iCurSel){pSelectedItem = static_cast<IListItemUI*>(GetItemAt(m_iCurSel)->GetInterface(DUI_CTR_ILISTITEM));}if (!CContainerUI::SetMultiItemIndex(pStartControl, iCount, iNewStartIndex)) return false;int iMinIndex = min(iStartIndex, iNewStartIndex);int iMaxIndex = max(iStartIndex, iNewStartIndex);for (int i = iMinIndex; i < iMaxIndex; ++i){CControlUI *p = GetItemAt(i);IListItemUI *pListItem = static_cast<IListItemUI*>(p->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->SetIndex(i);}}if (NULL != pSelectedItem){m_iCurSel = pSelectedItem->GetIndex();}return true;
}
bool CEditComboUI::Add(CControlUI* pControl)
{IListItemUI *pListItem = static_cast<IListItemUI*>(pControl->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->SetOwner(this);pListItem->SetIndex(m_items.GetSize());}return CContainerUI::Add(pControl);
}
bool CEditComboUI::AddAt(CControlUI* pControl, int iIndex)
{if (!CContainerUI::AddAt(pControl, iIndex)) return false;IListItemUI *pListItem = static_cast<IListItemUI*>(pControl->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->SetOwner(this);pListItem->SetIndex(iIndex);}for (int i = iIndex + 1; i < GetCount(); ++i){CControlUI *p = GetItemAt(i);pListItem = static_cast<IListItemUI*>(p->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->SetIndex(i);}}if (m_iCurSel >= iIndex){m_iCurSel += 1;}return true;
}
bool CEditComboUI::Remove(CControlUI* pControl, bool bDoNotDestroy/* =false */)
{int iIndex = GetItemIndex(pControl);if (-1 == iIndex) return false;if (!CContainerUI::RemoveAt(iIndex, bDoNotDestroy)) return false;for (int i = iIndex; i < GetCount(); ++i){CControlUI *p = GetItemAt(i);IListItemUI *pListItem = static_cast<IListItemUI*>(p->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListItem){pListItem->SetIndex(i);}}if (iIndex == m_iCurSel){m_iCurSel = -1;SelectItem(FindSelectable(iIndex, false));}else if (iIndex < m_iCurSel){m_iCurSel -= 1;}return true;
}
bool CEditComboUI::RemoveAt(int iIndex, bool bDoNotDestroy/* =false */)
{if (!CContainerUI::RemoveAt(iIndex, bDoNotDestroy)) return false;for (int i = iIndex; i < GetCount(); ++i){CControlUI *p = GetItemAt(i);IListItemUI *pListeItem = static_cast<IListItemUI*>(p->GetInterface(DUI_CTR_ILISTITEM));if (NULL != pListeItem) pListeItem->SetIndex(i);}if (iIndex == m_iCurSel && 0 <= m_iCurSel){int iSel = m_iCurSel;m_iCurSel = -1;SelectItem(FindSelectable(iSel, false));}else if (iIndex < m_iCurSel){m_iCurSel -= 1;}return true;
}
void CEditComboUI::RemoveAll()
{m_iCurSel = -1;CContainerUI::RemoveAll();
}void CEditComboUI::SetShowText(bool bShow)
{m_bShowText = bShow;
}
bool CEditComboUI::GetShowText() const
{return m_bShowText;
}
void CEditComboUI::SetSelectCloseFlag(bool flag)
{m_bSelectCloseFlag = flag;
}
bool CEditComboUI::GetSelectCloseFlag() const
{return m_bSelectCloseFlag;
}
UINT CEditComboUI::GetItemFixedHeight()
{return m_ListInfo.uFixedHeight;
}
void CEditComboUI::SetItemFixedHeight(UINT nHeight)
{m_ListInfo.uFixedHeight = nHeight;Invalidate();
}
int CEditComboUI::GetItemFont(int index)
{return m_ListInfo.nFont;
}
void CEditComboUI::SetItemFont(int index)
{m_ListInfo.nFont = index;Invalidate();
}
void CEditComboUI::SetItemAlign(LPCTSTR pstrValue)
{if (NULL != _tcsstr(pstrValue, _T("left"))){m_ListInfo.uTextStyle &= ~(DT_CENTER | DT_RIGHT);m_ListInfo.uTextStyle |= DT_LEFT;}else if (NULL != _tcsstr(pstrValue, _T("center"))){m_ListInfo.uTextStyle &= ~(DT_LEFT | DT_RIGHT);m_ListInfo.uTextStyle |= DT_CENTER;}else if (NULL != _tcsstr(pstrValue, _T("right"))){m_ListInfo.uTextStyle &= ~(DT_LEFT | DT_CENTER);m_ListInfo.uTextStyle |= DT_RIGHT;}
}
UINT CEditComboUI::GetItemTextStyle()
{return m_ListInfo.uTextStyle;
}
void CEditComboUI::SetItemTextStyle(UINT uStyle)
{m_ListInfo.uTextStyle = uStyle;Invalidate();
}
RECT CEditComboUI::GetItemTextPadding() const
{return m_ListInfo.rcTextPadding;
}
void CEditComboUI::SetItemTextPadding(RECT rc)
{m_ListInfo.rcTextPadding = rc;Invalidate();
}
void CEditComboUI::SetItemTextPadding(LPCTSTR pstrValue)
{RECT rcTextPadding = {0};LPTSTR pstr = NULL;rcTextPadding.left = _tcstol(pstrValue, &pstr, 10);ASSERT(pstr);rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10);ASSERT(pstr);rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10);ASSERT(pstr);rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10);SetItemTextPadding(rcTextPadding);
}
void CEditComboUI::SetItemTextColor(DWORD dwTextColor)
{m_ListInfo.dwTextColor = dwTextColor;Invalidate();
}
void CEditComboUI::SetItemBkColor(DWORD dwBkColor)
{m_ListInfo.dwBkColor = dwBkColor;
}
void CEditComboUI::SetItemBkImage(LPCTSTR pStrImage)
{if( m_ListInfo.diBk.sDrawString == pStrImage && m_ListInfo.diBk.pImageInfo != NULL ) return;m_ListInfo.diBk.Clear();m_ListInfo.diBk.sDrawString = pStrImage;
}
DWORD CEditComboUI::GetItemTextColor() const
{return m_ListInfo.dwTextColor;
}
DWORD CEditComboUI::GetItemBkColor() const
{return m_ListInfo.dwBkColor;
}
LPCTSTR CEditComboUI::GetItemBkImage() const
{return m_ListInfo.diBk.sDrawString;
}
bool CEditComboUI::IsItemAlternateBk() const
{return m_ListInfo.bAlternateBk;
}
void CEditComboUI::SetItemAlternateBk(bool bAlternateBk)
{m_ListInfo.bAlternateBk = bAlternateBk;
}
void CEditComboUI::SetSelectedItemTextColor(DWORD dwTextColor)
{m_ListInfo.dwSelectedTextColor = dwTextColor;
}
void CEditComboUI::SetSelectedItemBkColor(DWORD dwBkColor)
{m_ListInfo.dwSelectedBkColor = dwBkColor;
}
void CEditComboUI::SetSelectedItemImage(LPCTSTR pStrImage)
{if( m_ListInfo.diSelected.sDrawString == pStrImage && m_ListInfo.diSelected.pImageInfo != NULL ) return;m_ListInfo.diSelected.Clear();m_ListInfo.diSelected.sDrawString = pStrImage;
}
DWORD CEditComboUI::GetSelectedItemTextColor() const
{return m_ListInfo.dwSelectedTextColor;
}
DWORD CEditComboUI::GetSelectedItemBkColor() const
{return m_ListInfo.dwSelectedBkColor;
}
LPCTSTR CEditComboUI::GetSelectedItemImage() const
{return m_ListInfo.diSelected.sDrawString;
}
void CEditComboUI::SetHotItemTextColor(DWORD dwTextColor)
{m_ListInfo.dwHotTextColor = dwTextColor;
}
void CEditComboUI::SetHotItemBkColor(DWORD dwBkColor)
{m_ListInfo.dwHotBkColor = dwBkColor;
}
void CEditComboUI::SetHotItemImage(LPCTSTR pStrImage)
{if( m_ListInfo.diHot.sDrawString == pStrImage && m_ListInfo.diHot.pImageInfo != NULL ) return;m_ListInfo.diHot.Clear();m_ListInfo.diHot.sDrawString = pStrImage;
}
DWORD CEditComboUI::GetHotItemTextColor() const
{return m_ListInfo.dwHotTextColor;
}
DWORD CEditComboUI::GetHotItemBkColor() const
{return m_ListInfo.dwHotBkColor;
}
LPCTSTR CEditComboUI::GetHotItemImage() const
{return m_ListInfo.diHot.sDrawString;
}
void CEditComboUI::SetDisabledItemTextColor(DWORD dwTextColor)
{m_ListInfo.dwDisabledTextColor = dwTextColor;
}
void CEditComboUI::SetDisabledItemBkColor(DWORD dwBkColor)
{m_ListInfo.dwDisabledBkColor = dwBkColor;
}
void CEditComboUI::SetDisabledItemImage(LPCTSTR pStrImage)
{if( m_ListInfo.diDisabled.sDrawString == pStrImage && m_ListInfo.diDisabled.pImageInfo != NULL ) return;m_ListInfo.diDisabled.Clear();m_ListInfo.diDisabled.sDrawString = pStrImage;
}
DWORD CEditComboUI::GetDisabledItemTextColor() const
{return m_ListInfo.dwDisabledTextColor;
}
DWORD CEditComboUI::GetDisabledItemBkColor() const
{return m_ListInfo.dwDisabledBkColor;
}
LPCTSTR CEditComboUI::GetDisabledItemImage() const
{return m_ListInfo.diDisabled.sDrawString;
}
int CEditComboUI::GetItemHLineSize() const
{return m_ListInfo.iHLineSize;
}
void CEditComboUI::SetItemHLineSize(int iSize)
{m_ListInfo.iHLineSize = iSize;
}
DWORD CEditComboUI::GetItemHLineColor() const
{return m_ListInfo.dwHLineColor;
}
void CEditComboUI::SetItemHLineColor(DWORD dwLineColor)
{m_ListInfo.dwHLineColor = dwLineColor;
}
int CEditComboUI::GetItemVLineSize() const
{return m_ListInfo.iVLineSize;
}
void CEditComboUI::SetItemVLineSize(int iSize)
{m_ListInfo.iVLineSize = iSize;
}
DWORD CEditComboUI::GetItemVLineColor() const
{return m_ListInfo.dwVLineColor;
}
void CEditComboUI::SetItemVLineColor(DWORD dwLineColor)
{m_ListInfo.dwVLineColor = dwLineColor;
}
bool CEditComboUI::IsItemShowHtml()
{return m_ListInfo.bShowHtml;
}
void CEditComboUI::SetItemShowHtml(bool bShowHtml)
{if( m_ListInfo.bShowHtml == bShowHtml ) return;m_ListInfo.bShowHtml = bShowHtml;Invalidate();
}

里面可能有调试的代码,大家自己去掉;

demo:https://download.csdn.net/download/Cyd520608/12578454

duilib可编辑下拉选择框相关推荐

  1. jquery.chosen.js下拉选择框美化插件项目实例

    由于之前使用的bootstrap-select插件是建立在bootstrap基础上的,实际使用到项目中的时候,与我们使用的ace-admin(基于bootstrap)存在样式冲突,导致下拉框的样式发生 ...

  2. Bootstrap 表单控件一(单行输入框input,下拉选择框select ,文本域textarea)

    单行输入框,常见的文本输入框,也就是input的type属性值为text.在Bootstrap中使用input时也必须添加type类型,如果没有指定type类型,将无法得到正确的样式,因为Bootst ...

  3. python select模块安装_python+selenium select下拉选择框定位处理方法

    一.前言 总结一下python+selenium select下拉选择框定位处理的两种方式,以备后续使用时查询: 二.直接定位(XPath) 使用Firebug找到需要定位到的元素,直接右键复制XPa ...

  4. 自定义组合控件:下拉选择框

    Spinner 自定义组合控件之下拉选择框 项目概述 下拉选择框主要是通过在EditText 下用PopupWindow 动态显示ListView 控件来实现的.下拉选择框可以方便用户的输入效率,以此 ...

  5. js下拉 selenium_selenium的下拉选择框

    今天总结下selenium的下拉选择框.我们通常会遇到两种下拉框,一种使用的是html的标签select,另一种是使用input标签做的假下拉框. 后者我们通常的处理方式与其他的元素类似,点击或使用J ...

  6. html下拉选择框箭头改为年,CSS自定义select下拉选择框的样式(不用其他标签模拟)...

    今天群里有人问到怎么自定义select下拉选择框的样式,于是群里就展开了激烈的讨论,刚开始一直就是考虑怎样使用纯CSS实现,把浏览器默认的样式覆盖掉,但最后均因兼容问题处理不好而失败告终,最后的解决方 ...

  7. UI标签库专题十一:JEECG智能开发平台 DictSelect (数据字典下拉选择框)

     1. DictSelect (数据字典下拉选择框) 1.1. 参数 属性名 类型 描述 是否必须 默认值 typeGroupCode string 字典分组编码 是 null field str ...

  8. UI标签库专题七:JEECG智能开发平台 ComboBox (下拉选择框)

     1.  ComboBox (下拉选择框) 1.1. 参数 属性名 类型 描述 是否必须 默认值 name string 控件名称 是 null url string 远程数据访问 是 null ...

  9. layui实现select下拉选择框组件(含代码、案例、截图)

    layui实现select下拉选择框组件(含代码.案例.截图) 案例 · 效果图: 全部代码如下: <!DOCTYPE html> <html> <head>< ...

最新文章

  1. 整数展示分数和整形数的四则运算
  2. android sdk版本控制,1. 统一SDK版本管理配置
  3. 虹影图片下载器(Preview)
  4. python笔记 xpinyin
  5. 安全设置IIS的15个方法
  6. 实施SAP:资源和进度
  7. Exceptions(小节)
  8. 涨疯了,历史总是如此相似
  9. Activity启动模式和FLAG、TASKAFFINITY
  10. 形容女人的词语大全(坏与好)
  11. python在线学习直播-一对多直播系统开发,百万用户在线,直播弹幕系统是如何实现的?...
  12. 纯php代码打印数据表
  13. pywinauto实现微信消息自动发送
  14. 移动应用数据统计平台(之一)
  15. 瑞星微RK3288开发板 (ARM Cortex-A17架构)
  16. 笔记本计算机声音小,笔记本麦克风声音小的简单解决办法【图文教程】
  17. MATLAB绘制“问题儿童表情包”动图2
  18. word停止工作 怎么解决
  19. WebEx网络视频会议
  20. 怎么利用群控解决问题

热门文章

  1. python计算工资_编写Python代码计算工资总额,包括Overtim
  2. 【除夕夜特辑】手把手教你微信公众号开发
  3. 字符指针和整形指针简单分析,*,的作用。
  4. 3D三维向量的单位化、正规化、标准化推导及代码实现
  5. 使用VC和MATCOM结合开发应用程序心得笔记
  6. Kubernetes VPA
  7. P7259 [COCI2009-2010#3] SORT 题解
  8. ps -aux ps -ef 命令
  9. 英特尔称CPU超过10核没什么用,暗讽AMD胶水多核
  10. idea 创建MavenWeb项目报错 Cannot resolve plugin org.apache.maven.plugins:maven-clean-plugin:2.5