From: GreyMerlin Date: Sun, 2 Sep 2018 06:12:25 +0000 (-0700) Subject: Improvements to CSuperComboBox (7) X-Git-Tag: 2.16.4+-jp-10~170^2~66^2~9 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=573c9bf87daefec2665bc33306b8e046fc533b7d;p=winmerge-jp%2Fwinmerge-jp.git Improvements to CSuperComboBox (7) * FINALLY ... the substance of this whole effort! - Keep a parallel copy of the file name text to allow for extended length path names that are longer than the 255 character limit imposed by ComboBoxEx. - modify the way that the CSuperComboBox is initialized, so that more state information is known throughout the life of the control, not just within the `LoadState` and `SaveState` procedures. --- diff --git a/Src/Common/SuperComboBox.cpp b/Src/Common/SuperComboBox.cpp index 88d3d0298..08f9d19ba 100644 --- a/Src/Common/SuperComboBox.cpp +++ b/Src/Common/SuperComboBox.cpp @@ -11,6 +11,7 @@ #endif #define DEF_AUTOADD_STRING _T(" <>") +#define DEF_MAXSIZE 20 ///////////////////////////////////////////////////////////////////////////// @@ -25,8 +26,12 @@ CSuperComboBox::CSuperComboBox(bool bAdd /*= true*/, UINT idstrAddText /*= 0*/) m_bDoComplete = false; m_bAutoComplete = false; m_bHasImageList = false; - m_bRecognizedMyself = false; + m_bComboBoxEx = false; + m_bExtendedFileNames = false; + m_bCanBeEmpty = false; + m_nMaxItems = DEF_MAXSIZE; + m_strCurSel = _T(""); if (bAdd) @@ -82,18 +87,19 @@ void CSuperComboBox::PreSubclassWindow() GetClassName(m_hWnd, szClassName, sizeof(szClassName)/sizeof(szClassName[0])); if (lstrcmpi(_T("ComboBoxEx32"), szClassName) == 0) m_bComboBoxEx = true; - - m_bRecognizedMyself = true; } /** - * @brief Returns whether the window associated with this object is ComboBoxEx. + * @brief Sets additional state for handling Extended Length file names. */ -bool CSuperComboBox::IsComboBoxEx() const +void CSuperComboBox::SetFileControlStates(bool bCanBeEmpty /*= false*/, int nMaxItems /*= -1*/) { - ASSERT(m_bRecognizedMyself); - return m_bComboBoxEx; + ASSERT(m_bComboBoxEx); + m_bExtendedFileNames = true; + m_bCanBeEmpty = bCanBeEmpty; + if (nMaxItems > 0) + m_nMaxItems = nMaxItems; } /** @@ -112,8 +118,14 @@ int CSuperComboBox::AddString(LPCTSTR lpszItem) */ int CSuperComboBox::InsertString(int nIndex, LPCTSTR lpszItem) { - if (IsComboBoxEx()) + if (m_bComboBoxEx) { + if (m_bExtendedFileNames) + { + if (nIndex >= sFullStateText.size()) + sFullStateText.resize(nIndex + 10); + sFullStateText[nIndex] = lpszItem; + } COMBOBOXEXITEM cbitem = {0}; cbitem.mask = CBEIF_TEXT | (m_bHasImageList ? CBEIF_IMAGE|CBEIF_SELECTEDIMAGE : 0); @@ -135,7 +147,7 @@ int CSuperComboBox::InsertString(int nIndex, LPCTSTR lpszItem) */ bool CSuperComboBox::AttachSystemImageList() { - ASSERT(IsComboBoxEx()); + ASSERT(m_bComboBoxEx); if (!m_himlSystem) { SHFILEINFO sfi = {0}; @@ -149,14 +161,13 @@ bool CSuperComboBox::AttachSystemImageList() return true; } -void CSuperComboBox::LoadState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*= false*/, int nMaxItems /*= 20*/) +void CSuperComboBox::LoadState(LPCTSTR szRegSubKey) { - bool bIsEmpty = false; - if( bCanBeEmpty ) - bIsEmpty = (AfxGetApp()->GetProfileInt(szRegSubKey, _T("Empty"), FALSE) == TRUE); + ResetContent(); + int cnt = AfxGetApp()->GetProfileInt(szRegSubKey, _T("Count"), 0); int idx = 0; - for (int i=0; i < cnt && idx < nMaxItems; i++) + for (int i=0; i < cnt && idx < m_nMaxItems; i++) { CString s,s2; s2.Format(_T("Item_%d"), i); @@ -168,33 +179,46 @@ void CSuperComboBox::LoadState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*= false*/ } } if (idx > 0) - if( bIsEmpty ) + { + bool bIsEmpty = (m_bCanBeEmpty ? (AfxGetApp()->GetProfileInt(szRegSubKey, _T("Empty"), FALSE) == TRUE) : false); + if (bIsEmpty) { SetCurSel(-1); } else { SetCurSel(0); + if (m_bExtendedFileNames) + GetEditCtrl()->SetWindowText(sFullStateText[0]); } + } } void CSuperComboBox::GetLBText(int nIndex, CString &rString) const { ASSERT(::IsWindow(m_hWnd)); - if (nIndex==0 && IsComboBoxEx()) + if (m_bExtendedFileNames) + { + rString = sFullStateText[nIndex]; + } + else { - GetEditCtrl()->GetWindowText(rString); - if (!rString.IsEmpty()) - return; + CComboBoxEx::GetLBText(nIndex, rString.GetBufferSetLength(GetLBTextLen(nIndex))); + rString.ReleaseBuffer(); } - CComboBoxEx::GetLBText(nIndex, rString.GetBufferSetLength(GetLBTextLen(nIndex))); - rString.ReleaseBuffer(); } int CSuperComboBox::GetLBTextLen(int nIndex) const { - return CComboBoxEx::GetLBTextLen(nIndex); + if (m_bExtendedFileNames) + { + return sFullStateText[nIndex].GetLength(); + } + else + { + return CComboBoxEx::GetLBTextLen(nIndex); + } } /** @@ -207,10 +231,10 @@ int CSuperComboBox::GetLBTextLen(int nIndex) const * @param [in] bCanBeEmpty * @param [in] nMaxItems Max number of strings to save. */ -void CSuperComboBox::SaveState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*= false*/, int nMaxItems /*= 20*/) +void CSuperComboBox::SaveState(LPCTSTR szRegSubKey) { CString strItem; - if (IsComboBoxEx()) + if (m_bComboBoxEx) GetEditCtrl()->GetWindowText(strItem); else GetWindowText(strItem); @@ -225,7 +249,7 @@ void CSuperComboBox::SaveState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*= false*/ } int cnt = GetCount(); - for (int i=0; i < cnt && idx < nMaxItems; i++) + for (int i=0; i < cnt && idx < m_nMaxItems; i++) { CString s; GetLBText(i, s); @@ -241,7 +265,7 @@ void CSuperComboBox::SaveState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*= false*/ } AfxGetApp()->WriteProfileInt(szRegSubKey, _T("Count"), idx); - if (bCanBeEmpty) + if (m_bCanBeEmpty) AfxGetApp()->WriteProfileInt(szRegSubKey, _T("Empty"), strItem.IsEmpty()); } @@ -302,7 +326,7 @@ BOOL CSuperComboBox::OnSelchange() if (m_strAutoAdd.IsEmpty() || strCurSel != m_strAutoAdd) m_strCurSel = strCurSel; - + if (!m_strAutoAdd.IsEmpty()) { int sel = GetCurSel(); @@ -397,7 +421,7 @@ void CSuperComboBox::SetAutoComplete(INT nSource) m_bAutoComplete = false; // ComboBox's edit control is alway 1001. - CWnd *pWnd = IsComboBoxEx() ? this->GetEditCtrl() : GetDlgItem(1001); + CWnd *pWnd = m_bComboBoxEx ? this->GetEditCtrl() : GetDlgItem(1001); ASSERT(NULL != pWnd); SHAutoComplete(pWnd->m_hWnd, SHACF_FILESYSTEM); break; @@ -415,8 +439,16 @@ void CSuperComboBox::SetAutoComplete(INT nSource) void CSuperComboBox::ResetContent() { + if (m_bExtendedFileNames) + { + sFullStateText.resize(m_nMaxItems); + for (int i = 0; i < m_nMaxItems; i++) + { + sFullStateText[i] = _T(""); + } + } CComboBoxEx::ResetContent(); - if (!m_strAutoAdd.IsEmpty()) + if (!m_bComboBoxEx && !m_strAutoAdd.IsEmpty()) { InsertString(0, m_strAutoAdd); } diff --git a/Src/Common/SuperComboBox.h b/Src/Common/SuperComboBox.h index 952a172eb..92ef4b96e 100644 --- a/Src/Common/SuperComboBox.h +++ b/Src/Common/SuperComboBox.h @@ -24,8 +24,12 @@ protected: bool m_bAutoComplete; bool m_bDoComplete; bool m_bHasImageList; - bool m_bRecognizedMyself; + + int m_nMaxItems; bool m_bComboBoxEx; + bool m_bExtendedFileNames; + bool m_bCanBeEmpty; + bool m_bMustUninitOLE; static HIMAGELIST m_himlSystem; CString m_strCurSel; @@ -33,6 +37,8 @@ protected: DropHandler *m_pDropHandler; + std::vector sFullStateText; + public: enum @@ -56,10 +62,10 @@ public: // Implementation public: - void ResetContent(); void SetAutoAdd(bool bAdd = true, UINT idstrAddText = 0); - void SaveState(LPCTSTR szRegSubKey, bool bCanBeEmpty = false, int nMaxItems = 20); - void LoadState(LPCTSTR szRegSubKey, bool bCanBeEmpty = false, int nMaxItems = 20); + void SetFileControlStates(bool bCanBeEmpty = false, int nMaxItems = -1); + void SaveState(LPCTSTR szRegSubKey); + void LoadState(LPCTSTR szRegSubKey); bool AttachSystemImageList(); int AddString(LPCTSTR lpszItem); int InsertString(int nIndex, LPCTSTR lpszItem); @@ -68,7 +74,7 @@ public: // Generated message map functions protected: - bool IsComboBoxEx() const; + void ResetContent(); virtual BOOL OnAddTemplate(); virtual void PreSubclassWindow(); diff --git a/Src/OpenView.cpp b/Src/OpenView.cpp index 7ac928b4c..d748c2c59 100644 --- a/Src/OpenView.cpp +++ b/Src/OpenView.cpp @@ -231,6 +231,10 @@ void COpenView::OnInitialUpdate() m_dwFlags[1] = pDoc->m_dwFlags[1]; m_dwFlags[2] = pDoc->m_dwFlags[2]; + m_ctlPath[0].SetFileControlStates(); + m_ctlPath[1].SetFileControlStates(); + m_ctlPath[2].SetFileControlStates(true); + for (int file = 0; file < m_files.GetSize(); file++) { m_strPath[file] = m_files[file]; @@ -691,14 +695,9 @@ String COpenView::AskProjectFileName(bool bOpen) */ void COpenView::LoadComboboxStates() { - m_ctlPath[0].CComboBox::ResetContent(); - m_ctlPath[1].CComboBox::ResetContent(); - m_ctlPath[2].CComboBox::ResetContent(); - m_ctlExt.CComboBox::ResetContent(); - m_ctlPath[0].LoadState(_T("Files\\Left")); m_ctlPath[1].LoadState(_T("Files\\Right")); - m_ctlPath[2].LoadState(_T("Files\\Option"), true); + m_ctlPath[2].LoadState(_T("Files\\Option")); m_ctlExt.LoadState(_T("Files\\Ext")); } @@ -709,7 +708,7 @@ void COpenView::SaveComboboxStates() { m_ctlPath[0].SaveState(_T("Files\\Left")); m_ctlPath[1].SaveState(_T("Files\\Right")); - m_ctlPath[2].SaveState(_T("Files\\Option"), true); + m_ctlPath[2].SaveState(_T("Files\\Option")); m_ctlExt.SaveState(_T("Files\\Ext")); }