GME
13
|
00001 // AutoComboBox.cpp : implementation file 00002 // 00003 00004 #include "stdafx.h" 00005 #include "gmeactivebrowser.h" 00006 #include "AutoComboBox.h" 00007 #include "ActiveBrowsePropertySheet.h" 00008 00009 #ifdef _DEBUG 00010 #define new DEBUG_NEW 00011 #undef THIS_FILE 00012 static char THIS_FILE[] = __FILE__; 00013 #endif 00014 00015 00016 00018 // CAutoComboBox 00019 00020 CAutoComboBox::CAutoComboBox(CTreeCtrlEx* pTreeCtrl) 00021 { 00022 m_pTreeCtrl=pTreeCtrl; 00023 } 00024 00025 CAutoComboBox::~CAutoComboBox() 00026 { 00027 } 00028 00029 00030 BEGIN_MESSAGE_MAP(CAutoComboBox, CComboBox) 00031 //{{AFX_MSG_MAP(CAutoComboBox) 00032 ON_CONTROL_REFLECT(CBN_EDITCHANGE, OnEditChange) 00033 ON_CONTROL_REFLECT(CBN_SELENDOK, OnSelendOk) 00034 //}}AFX_MSG_MAP 00035 END_MESSAGE_MAP() 00036 00038 // CAutoComboBox message handlers 00039 00040 00041 void CAutoComboBox::OnEditKeyDown(int nVKeyCode) 00042 { 00043 00044 switch(nVKeyCode) 00045 { 00046 case VK_RETURN: OnKeyEnter();break; 00047 case VK_DELETE:;break; 00048 case VK_BACK:;break; 00049 case VK_ESCAPE:;break; 00050 case VK_DOWN: 00051 this->ShowDropDown(); 00052 break; 00053 case VK_TAB: 00054 { 00055 if( ::GetKeyState( VK_CONTROL) < 0) { 00056 CActiveBrowserPropertySheet *p = (CActiveBrowserPropertySheet *)m_pTreeCtrl->GetParent()->GetParent(); 00057 if( p) p->nextTab( ::GetKeyState( VK_SHIFT) >= 0); 00058 } else { 00059 m_pTreeCtrl->SetFocus(); 00060 } 00061 }break; 00062 } 00063 00064 } 00065 00066 void CAutoComboBox::Fill(CString& strText, BOOL bReload) 00067 { 00068 // Clear combo 00069 for (int i = GetCount() - 1; i >= 0; i--) 00070 { 00071 DeleteString(i); 00072 } 00073 00074 if(strText=="") 00075 { 00076 m_strPrevTxt=""; 00077 return; 00078 } 00079 if(bReload) 00080 { 00081 00082 m_pTreeCtrl->FindTextInItems(strText,NULL,m_strResults,m_hResults); 00083 } 00084 00085 // Fill combo 00086 for(int i=0;i<=m_strResults.GetUpperBound();i++) 00087 { 00088 AddString(m_strResults.GetAt(i)); 00089 } 00090 00091 00092 if(m_strResults.GetSize()>0) 00093 { 00094 00095 // Setting selection 00096 SetCurSel(0); 00097 00098 // Saving current combo edit text 00099 m_strPrevTxt=strText; 00100 00101 //Getting Current text again after drop down 00102 CString strComboText; 00103 GetWindowText(strComboText); 00104 00105 // Set the selection to be all characters after the current selection. 00106 SetEditSel(m_strPrevTxt.GetLength(), strComboText.GetLength()); 00107 00108 } 00109 00110 } 00111 00112 00113 00114 void CAutoComboBox::OnEditChange() 00115 { 00116 // Get edit text 00117 CString strComboText; 00118 GetWindowText(strComboText); 00119 00120 if(strComboText==m_strPrevTxt) // Deleted selection 00121 { 00122 return; 00123 } 00124 00125 // Filling the combo 00126 Fill(strComboText); 00127 00128 00129 // Dumping CStringListEx for debug purposes 00130 #ifdef _DEBUG 00131 TRACE("\nCStringArray:\n"); 00132 for( int j=0;j<=m_strResults.GetUpperBound();j++) 00133 { 00134 TRACE1("%d :",j); 00135 TRACE(m_strResults.GetAt(j)); 00136 TRACE("\n"); 00137 } 00138 TRACE("___________________________________________________________\n"); 00139 #endif 00140 00141 } 00142 00143 00144 00145 void CAutoComboBox::OnSelendOk() 00146 { 00147 int nCurSel=GetCurSel(); 00148 00149 if(nCurSel!=CB_ERR) 00150 { 00151 m_strPrevTxt=m_strResults.GetAt(nCurSel); 00152 m_pTreeCtrl->SetFocus(); 00153 m_pTreeCtrl->ClearSelection(); 00154 m_pTreeCtrl->SelectItem(m_hResults.GetAt(nCurSel)); 00155 00156 } 00157 } 00158 00159 void CAutoComboBox::SetSelection(HTREEITEM hItem) 00160 { 00161 00162 CString strItemText=m_pTreeCtrl->GetItemText(hItem); 00163 00164 Fill(strItemText); 00165 00166 if(strItemText=="")return; 00167 00168 for(int i=0;i<=m_hResults.GetUpperBound();i++) 00169 { 00170 if(m_hResults.GetAt(i)==hItem) 00171 { 00172 SetCurSel(i); 00173 return; 00174 } 00175 } 00176 ASSERT(FALSE); 00177 00178 } 00179 00180 void CAutoComboBox::OnKeyEnter() 00181 { 00182 int nCurSel=GetCurSel(); 00183 if(nCurSel==CB_ERR) 00184 { 00185 // Get the current text 00186 CString strComboText; 00187 GetWindowText(strComboText); 00188 00189 m_strPrevTxt=strComboText; 00190 00191 for(int i=0;i<=m_strResults.GetUpperBound();i++) 00192 { 00193 if(m_strResults.GetAt(i)==strComboText) 00194 { 00195 SetCurSel(i); 00196 OnSelendOk(); 00197 return; 00198 } 00199 } 00200 } 00201 } 00202 00203 00204 //____________________________________________________ 00205 // NOT CALLED: We do not use this function, but can be useful 00206 BOOL CAutoComboBox::Filter(CString &strFilter) 00207 { 00208 00209 for(int i=0;i<=m_strResults.GetUpperBound();i++) 00210 { 00211 if(m_strResults.GetAt(i).Find(strFilter)!=0) 00212 { 00213 m_strResults.RemoveAt(i); 00214 m_hResults.RemoveAt(i); 00215 i--; 00216 } 00217 } 00218 return m_strResults.GetSize(); 00219 00220 } 00221 //___________________________________________________