#pragma once #include #include "IFontAdapterCallback.h" class CFontAdapter : public SAdapterBase { public: private: SArray m_arrFont; IFontAdapterCallback* m_pCB; int m_nFontType; BOOL m_bFontSort; public: CFontAdapter(IFontAdapterCallback* pCB){ m_pCB = pCB; m_nFontType = 0; m_bFontSort = FALSE; } ~CFontAdapter(){} virtual int getCount() { return m_arrFont.GetCount(); } virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate) { if (pItem->GetChildrenCount() == 0) pItem->InitFromXml(xmlTemplate); SWindow* pFont = pItem->FindChildByID(1); SStringT strSelSize = m_arrFont.GetAt(position); pFont->SetWindowText(strSelSize); pItem->SetUserData(position); pItem->GetEventSet()->subscribeEvent(EventItemPanelClick::EventID, Subscriber(&CFontAdapter::OnItemClick, this)); } SStringT getItemDesc(int position) { return m_arrFont.GetAt(position); } bool OnItemClick(EventArgs *pEvt) { EventItemPanelClick* pEvt_ItemPanel = sobj_cast(pEvt); SASSERT(pEvt_ItemPanel); SWindow* pPanel = sobj_cast(pEvt_ItemPanel->sender); SOUI::CPoint pt(GET_X_LPARAM(pEvt_ItemPanel->lParam), GET_Y_LPARAM(pEvt_ItemPanel->lParam)); SWND swnd = pPanel->SwndFromPoint(pt, FALSE); SWindow *pClicked = NULL; if (swnd) { pClicked = SWindowMgr::GetWindow(swnd); } int nIndex = pPanel->GetUserData(); CString strText = GetFontText(nIndex); m_pCB->OnClickFontItem(nIndex,m_nFontType,strText); return true; } SStringT getItem(int position) { SASSERT(position >= 0 && position < (int)m_arrFont.GetCount()); return m_arrFont[position]; } void AddFontText(const SStringT strFont) { if (L"" != strFont) { if(m_bFontSort) { CString strTempFace = strFont; TCHAR fChar1; TCHAR fChar2; CString strText ; int nIndex = -1; fChar1 = strTempFace.GetAt( 0 ); if ( fChar1 >= 0x7e ) //??ĿǰÅжÏ×Ö·ûÊDz»ÊÇË«×Ö½Ú×Ö·ûµÄ { for(int i =0; i < m_arrFont.GetCount(); i++) { strText = m_arrFont.GetAt(i); strText.Trim(); fChar2 = strText.GetAt( 0 ); if ( fChar2 >= 0x7e ) //??ĿǰÅжÏ×Ö·ûÊDz»ÊÇË«×Ö½Ú×Ö·ûµÄ { if(strText.CompareNoCase(strFont) ==0) { nIndex = i; break; } if(strFont.CompareNoCase(strText) < 0) { m_arrFont.InsertAt(i,strFont); nIndex = i; break; } } else { m_arrFont.InsertAt(i,strFont); nIndex = i; break; } } } else { for(int i =0; i < m_arrFont.GetCount(); i++) { strText = m_arrFont.GetAt(i); strText.Trim(); fChar2 = strText.GetAt( 0 ); if ( fChar2 >= 0x7e ) //??ĿǰÅжÏ×Ö·ûÊDz»ÊÇË«×Ö½Ú×Ö·ûµÄ { continue; } else { if(strText.CompareNoCase(strFont) ==0) { nIndex = i; break; } if(strFont.CompareNoCase(strText) < 0) { m_arrFont.InsertAt(i,strFont); nIndex = i; break; } } } } if(nIndex< 0 ) m_arrFont.Add(strFont); this->notifyDataSetChanged(); /*for(int i =0; i < m_arrFont.GetCount(); i++) { strText = m_arrFont.GetAt(i); strText.Trim(); TCHAR *ptr2=strText.GetBuffer(0); if(strText.CompareNoCase(strFont) ==0) { nIndex = i; break; } if(strFont.CompareNoCase(strText) > 0) { m_arrFont.InsertAt(i,strFont); nIndex = i; break; } } if(nIndex< 0 ) m_arrFont.Add(strFont); this->notifyDataSetChanged();*/ } else { if(GetFontIndex((CString)strFont) < 0) { m_arrFont.Add(strFont); this->notifyDataSetChanged(); } } } } void SetFontType(int nFontType) { m_nFontType = nFontType; } void SetSortFont(BOOL bFontSort) { m_bFontSort = bFontSort; } int GetFontIndex(CString strFont) { CString strText ; strFont.Trim(); int nIndex = -1; for(int i =0; i < m_arrFont.GetCount(); i++) { strText = m_arrFont.GetAt(i); strText.Trim(); if(strText == strFont) { nIndex = i; break; } } return nIndex; } SStringT GetFontText(int position) { SASSERT(position >= 0 && position < (int)m_arrFont.GetCount()); return m_arrFont[position]; } };