#endif
#define DEF_AUTOADD_STRING _T(" <<new template>>")
+#define DEF_MAXSIZE 20
/////////////////////////////////////////////////////////////////////////////
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)
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;
}
/**
*/
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);
*/
bool CSuperComboBox::AttachSystemImageList()
{
- ASSERT(IsComboBoxEx());
+ ASSERT(m_bComboBoxEx);
if (!m_himlSystem)
{
SHFILEINFO sfi = {0};
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);
}
}
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);
+ }
}
/**
* @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);
}
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);
}
AfxGetApp()->WriteProfileInt(szRegSubKey, _T("Count"), idx);
- if (bCanBeEmpty)
+ if (m_bCanBeEmpty)
AfxGetApp()->WriteProfileInt(szRegSubKey, _T("Empty"), strItem.IsEmpty());
}
if (m_strAutoAdd.IsEmpty()
|| strCurSel != m_strAutoAdd)
m_strCurSel = strCurSel;
-
+
if (!m_strAutoAdd.IsEmpty())
{
int sel = GetCurSel();
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;
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);
}
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;
DropHandler *m_pDropHandler;
+ std::vector<CString> sFullStateText;
+
public:
enum
// 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);
// Generated message map functions
protected:
- bool IsComboBoxEx() const;
+ void ResetContent();
virtual BOOL OnAddTemplate();
virtual void PreSubclassWindow();
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];
*/
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"));
}
{
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"));
}