Support unrar64.dll
[xy_vsfilter.git] / src / thirdparty / mfc / afxctrlcontainer.cpp
blobe1a75b39f4e9eec1ba5e19c2383abb2a8a6832a3
1 // This is a part of the Microsoft Foundation Classes C++ library.
2 // Copyright (C) Microsoft Corporation
3 // All rights reserved.
4 //
5 // This source code is only intended as a supplement to the
6 // Microsoft Foundation Classes Reference and related
7 // electronic documentation provided with the library.
8 // See these sources for detailed information regarding the
9 // Microsoft Foundation Classes product.
11 // CWnd support for MFC Control containment (Feature Pack controls)
14 #include "stdafx.h"
15 #undef SubclassWindow
16 #include "afxctrlcontainer.h"
17 #if 0
18 #include "afxtagmanager.h"
19 #include "afxbutton.h"
20 #include "afxcolorbutton.h"
21 #include "afxeditbrowsectrl.h"
22 #include "afxfontcombobox.h"
23 #include "afxlinkctrl.h"
24 #include "afxmaskededit.h"
25 #include "afxmenubutton.h"
26 #include "afxpropertygridctrl.h"
27 #include "afxshelllistctrl.h"
28 #include "afxshelltreectrl.h"
29 #include "afxvslistbox.h"
30 #endif
32 ////////////////////////////////////////////////////////////////////////////
34 #if (_MSC_VER == 1700)
35 void AfxDoRegisterMFCControlClass(LPCTSTR lpszClassName, LPCTSTR lpszBaseClassName)
36 #else
37 static void DoRegisterWindowClass(LPCTSTR lpszClassName, LPCTSTR lpszBaseClassName)
38 #endif
40 ASSERT(lpszClassName != NULL);
41 ASSERT(lpszBaseClassName != NULL);
43 WNDCLASS wnd = {0};
45 HINSTANCE hInst = AfxGetInstanceHandle();
46 #if (_MSC_VER == 1700)
47 if (!GetClassInfo(hInst, lpszBaseClassName, &wnd))
48 #else
49 if (!AfxCtxGetClassInfo(hInst, lpszBaseClassName, &wnd))
50 #endif
52 wnd.style = CS_DBLCLKS;
53 wnd.hInstance = hInst;
54 wnd.lpfnWndProc = ::DefWindowProc;
57 wnd.lpszClassName = lpszClassName;
58 AfxRegisterClass(&wnd);
61 #if (_MSC_VER == 1600)
62 void AfxRegisterMFCCtrlClasses()
64 DoRegisterWindowClass(_T("MFCButton"), WC_BUTTON);
65 DoRegisterWindowClass(_T("MFCColorButton"), WC_BUTTON);
66 DoRegisterWindowClass(_T("MFCEditBrowse"), WC_EDIT);
67 DoRegisterWindowClass(_T("MFCFontComboBox"), WC_COMBOBOX);
68 DoRegisterWindowClass(_T("MFCLink"), WC_BUTTON);
69 DoRegisterWindowClass(_T("MFCMaskedEdit"), WC_EDIT);
70 DoRegisterWindowClass(_T("MFCMenuButton"), WC_BUTTON);
71 DoRegisterWindowClass(_T("MFCPropertyGrid"), WC_STATIC);
72 DoRegisterWindowClass(_T("MFCShellList"), WC_LISTVIEW);
73 DoRegisterWindowClass(_T("MFCShellTree"), WC_TREEVIEW);
74 DoRegisterWindowClass(_T("MFCVSListBox"), WC_STATIC);
76 #endif
78 ////////////////////////////////////////////////////////////////////////////
79 // CMFCControlContainer
81 CMFCControlContainer::CMFCControlContainer(CWnd* pWnd) : m_pWnd(pWnd)
85 CMFCControlContainer::~CMFCControlContainer()
87 FreeSubclassedControls();
88 ClearControlData();
91 #if (_MSC_VER == 1600)
92 BOOL CMFCControlContainer::SubclassDlgControls()
94 if (m_pWnd->GetSafeHwnd() != NULL)
96 // Subclass Feature Pack controls:
97 CWnd* pWndChild = m_pWnd->GetWindow(GW_CHILD);
98 while (pWndChild != NULL)
100 ASSERT_VALID(pWndChild);
102 TCHAR lpszClassName [MAX_CLASS_NAME + 1];
104 ::GetClassName(pWndChild->GetSafeHwnd(), lpszClassName, MAX_CLASS_NAME);
105 CWnd* pWndSubclassedCtrl = CreateDlgControl(lpszClassName);
107 if (pWndSubclassedCtrl != NULL)
109 m_arSubclassedCtrls.Add((CObject*)pWndSubclassedCtrl);
110 pWndSubclassedCtrl->SubclassWindow(pWndChild->GetSafeHwnd());
113 pWndChild = pWndChild->GetNextWindow();
116 return TRUE;
119 return FALSE;
121 #endif
123 void CMFCControlContainer::FreeSubclassedControls()
125 // Free subclassed controls:
126 for (int i = 0; i < m_arSubclassedCtrls.GetCount(); i++)
128 if (m_arSubclassedCtrls [i] != NULL)
130 delete m_arSubclassedCtrls [i];
133 m_arSubclassedCtrls.RemoveAll();
136 CWnd* CMFCControlContainer::CreateDlgControl(LPCTSTR lpszClassName)
138 ASSERT(m_pWnd->GetSafeHwnd() != NULL);
140 if (lpszClassName != NULL)
142 CString strClass = lpszClassName;
143 CWnd* pWndSubclassedCtrl = NULL;
144 #if 0
145 if (strClass == _T("MFCButton"))
147 pWndSubclassedCtrl = new CMFCButton;
149 else if (strClass == _T("MFCColorButton"))
151 pWndSubclassedCtrl = new CMFCColorButton;
153 else if (strClass == _T("MFCEditBrowse"))
155 pWndSubclassedCtrl = new CMFCEditBrowseCtrl;
157 else if (strClass == _T("MFCFontComboBox"))
159 pWndSubclassedCtrl = new CMFCFontComboBox;
161 else if (strClass == _T("MFCLink"))
163 pWndSubclassedCtrl = new CMFCLinkCtrl;
165 else if (strClass == _T("MFCMaskedEdit"))
167 pWndSubclassedCtrl = new CMFCMaskedEdit;
169 else if (strClass == _T("MFCMenuButton"))
171 pWndSubclassedCtrl = new CMFCMenuButton;
173 else if (strClass == _T("MFCPropertyGrid"))
175 pWndSubclassedCtrl = new CMFCPropertyGridCtrl;
177 else if (strClass == _T("MFCShellList"))
179 pWndSubclassedCtrl = new CMFCShellListCtrl;
181 else if (strClass == _T("MFCShellTree"))
183 pWndSubclassedCtrl = new CMFCShellTreeCtrl;
185 else if (strClass == _T("MFCVSListBox"))
187 pWndSubclassedCtrl = new CVSListBox;
189 #endif
190 return pWndSubclassedCtrl;
193 return NULL;
196 BOOL CMFCControlContainer::IsSubclassedFeaturePackControl(HWND hWndCtrl)
198 if (hWndCtrl == NULL)
200 return FALSE;
203 for (int i = 0; i < m_arSubclassedCtrls.GetCount(); i++)
205 CWnd* pWnd = (CWnd*)m_arSubclassedCtrls[i];
206 if (pWnd->GetSafeHwnd() == hWndCtrl)
208 return TRUE;
212 return FALSE;
215 #if (_MSC_VER == 1600)
216 void CMFCControlContainer::PreUnsubclassControl(CWnd* pControl)
218 UNREFERENCED_PARAMETER(pControl);
220 // CMFCShellListCtrl* pListCtrl = DYNAMIC_DOWNCAST(CMFCShellListCtrl, pControl);
221 // if (pListCtrl != NULL && pListCtrl->GetHeaderCtrl().GetSafeHwnd() != NULL)
222 // {
223 // pListCtrl->GetHeaderCtrl().UnsubclassWindow();
224 // }
226 #endif
228 BOOL CMFCControlContainer::ReSubclassControl(HWND hWndCtrl, WORD nIDC, CWnd& control)
230 if (hWndCtrl == NULL)
232 return FALSE;
235 int nIndex = -1;
236 for (int i = 0; i < m_arSubclassedCtrls.GetCount(); i++)
238 CWnd* pWnd = (CWnd*)m_arSubclassedCtrls [i];
239 if (pWnd->GetSafeHwnd() == hWndCtrl)
241 nIndex = i;
242 break;
246 if (nIndex != -1)
248 CWnd* pWnd = DYNAMIC_DOWNCAST(CWnd, m_arSubclassedCtrls [nIndex]);
250 if (pWnd->GetSafeHwnd() != NULL)
252 ASSERT_VALID(pWnd);
254 // get init state
255 DWORD dwSize = 0;
256 BYTE* pbInitData = NULL;
257 GetControlData(nIDC, dwSize, pbInitData);
259 // Free old subclassed control:
260 m_arSubclassedCtrls [nIndex] = NULL;
262 // unsubclass
263 PreUnsubclassControl(pWnd);
264 VERIFY(pWnd->UnsubclassWindow() == hWndCtrl);
265 // destroy
266 delete pWnd;
268 // subclass
269 if (!control.SubclassWindow(hWndCtrl))
271 ASSERT(FALSE); // possibly trying to subclass twice?
272 AfxThrowNotSupportedException();
275 // set init state
276 if (dwSize > 0)
278 control.SendMessage(WM_MFC_INITCTRL, (WPARAM)dwSize, (LPARAM)pbInitData);
281 return TRUE;
285 return FALSE;
288 void CMFCControlContainer::SetControlData(WORD nIDC, DWORD dwSize, BYTE* pbData)
290 CByteArray* pArray = new CByteArray;
291 pArray->SetSize(dwSize);
293 BYTE* pbBuffer = pArray->GetData();
294 if (memcpy_s(pbBuffer, dwSize, pbData, dwSize) != 0)
296 delete pArray;
297 ASSERT(FALSE);
298 return;
301 m_mapControlData.SetAt(nIDC, pArray);
304 BOOL CMFCControlContainer::GetControlData(WORD nIDC, DWORD& dwSize, BYTE*& pbData)
306 CObject* pData = NULL;
307 if (m_mapControlData.Lookup(nIDC, pData) && pData != NULL)
309 CByteArray* pArray = (CByteArray*)pData;
310 dwSize = (DWORD)pArray->GetSize();
311 pbData = pArray->GetData();
312 return TRUE;
315 return FALSE;
318 void CMFCControlContainer::ClearControlData()
320 WORD nIDC;
321 CObject* pData = NULL;
322 POSITION pos = m_mapControlData.GetStartPosition();
323 while (pos != NULL)
325 m_mapControlData.GetNextAssoc(pos, nIDC, pData);
326 CByteArray* pArray = (CByteArray*)pData;
327 delete pArray;
330 m_mapControlData.RemoveAll();
333 #if (_MSC_VER == 1600)
335 ////////////////////////////////////////////////////////////////////////////
336 // Accessing dialog DLGINIT helpers
338 int __stdcall CMFCControlContainer::UTF8ToString(LPCSTR lpSrc, CString& strDst, int nLength)
340 LPTSTR lpDst = NULL;
341 int count = ::MultiByteToWideChar(CP_UTF8, 0, lpSrc, nLength, NULL, 0);
342 if (count <= 0)
344 return 0;
347 LPWSTR lpWide = new WCHAR[count + 1];
348 memset(lpWide, 0, (count + 1) * sizeof(WCHAR));
350 ::MultiByteToWideChar(CP_UTF8, 0, lpSrc, nLength, lpWide, count);
352 #ifdef _UNICODE
353 lpDst = lpWide;
354 #else
355 count = ::WideCharToMultiByte(::GetACP(), 0, lpWide, -1, NULL, 0, NULL, 0);
357 if (count > 0)
359 lpDst = new char[count + 1];
360 memset(lpDst, 0, count + 1);
362 ::WideCharToMultiByte(::GetACP(), 0, lpWide, -1, lpDst, count, NULL, 0);
365 delete [] lpWide;
366 #endif
368 strDst = lpDst;
369 delete[] lpDst;
370 return count;
373 BOOL __stdcall CMFCControlContainer::ReadBoolProp(CTagManager& /*tagManager*/, LPCTSTR lpszTag, BOOL& bMember)
375 if (lpszTag == NULL)
377 return FALSE;
380 CString str;
381 // tagManager.ExcludeTag(lpszTag, str);
383 if (str.IsEmpty())
385 return FALSE;
388 bMember = (str.CompareNoCase(PS_True) == 0);
389 return TRUE;
391 #endif