* Sync to trunk r63845.
[reactos.git] / dll / win32 / browseui / precomp.h
1 #ifndef _BROWSEUI_PCH_
2 #define _BROWSEUI_PCH_
3
4 #include <stdarg.h>
5
6 #define WIN32_NO_STATUS
7 #define _INC_WINDOWS
8 #define COM_NO_WINDOWS_H
9
10 #include <windef.h>
11 #include <winbase.h>
12 #include <wincon.h>
13 #include <shlobj.h>
14 #include <tlogstg.h>
15 #include <shlobj_undoc.h>
16 #include <shlguid_undoc.h>
17 #include <shdeprecated.h>
18 #include <tchar.h>
19 #include <atlbase.h>
20 #include <atlcom.h>
21 #include <atlwin.h>
22 #include <perhist.h>
23 #include <exdispid.h>
24 #include <shlwapi.h>
25 #include <shlwapi_undoc.h>
26 #include <wine/debug.h>
27
28 #include "resource.h"
29
30 #include "aclmulti.h"
31 #include "addressband.h"
32 #include "addresseditbox.h"
33 #include "bandproxy.h"
34 #include "bandsite.h"
35 #include "bandsitemenu.h"
36 #include "brandband.h"
37 #include "internettoolbar.h"
38 #include "commonbrowser.h"
39 #include "globalfoldersettings.h"
40 #include "regtreeoptions.h"
41 #include <stdio.h>
42
43 static __inline ULONG
44 Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
45 {
46 char szMsg[512];
47 char *szMsgStart;
48 const char *fname;
49 va_list vl;
50 ULONG uRet;
51
52 fname = strrchr(filename, '\\');
53 if (fname == NULL)
54 {
55 fname = strrchr(filename, '/');
56 if (fname != NULL)
57 fname++;
58 }
59 else
60 fname++;
61
62 if (fname == NULL)
63 fname = filename;
64
65 szMsgStart = szMsg + sprintf(szMsg, "%s:%d: ", fname, line);
66
67 va_start(vl, lpFormat);
68 uRet = (ULONG) vsprintf(szMsgStart, lpFormat, vl);
69 va_end(vl);
70
71 OutputDebugStringA(szMsg);
72
73 return uRet;
74 }
75
76 #define DbgPrint(fmt, ...) \
77 Win32DbgPrint(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
78
79 static void DbgDumpMenuInternal(HMENU hmenu, char* padding, int padlevel)
80 {
81 WCHAR label[128];
82
83 padding[padlevel] = '.';
84 padding[padlevel + 1] = '.';
85 padding[padlevel + 2] = 0;
86
87 int count = GetMenuItemCount(hmenu);
88 for (int i = 0; i < count; i++)
89 {
90 MENUITEMINFOW mii = { 0 };
91
92 mii.cbSize = sizeof(mii);
93 mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU | MIIM_STATE | MIIM_ID;
94 mii.dwTypeData = label;
95 mii.cch = _countof(label);
96
97 GetMenuItemInfo(hmenu, i, TRUE, &mii);
98
99 if (mii.fType & MFT_BITMAP)
100 DbgPrint("%s%2d - %08x: BITMAP %08p (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.hbmpItem, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
101 else if (mii.fType & MFT_SEPARATOR)
102 DbgPrint("%s%2d - %08x ---SEPARATOR---\n", padding, i, mii.wID);
103 else
104 DbgPrint("%s%2d - %08x: %S (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.dwTypeData, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
105
106 if (mii.hSubMenu)
107 DbgDumpMenuInternal(mii.hSubMenu, padding, padlevel + 2);
108
109 }
110
111 padding[padlevel] = 0;
112 }
113
114 static __inline void DbgDumpMenu(HMENU hmenu)
115 {
116 char padding[128];
117 DbgDumpMenuInternal(hmenu, padding, 0);
118 }
119
120 #if 1
121 #define FAILED_UNEXPECTEDLY(hr) (FAILED(hr) && (DbgPrint("Unexpected failure %08x.\n", hr), TRUE))
122 #else
123 #define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
124 #endif
125
126
127 template <class Base>
128 class CComDebugObject : public Base
129 {
130 public:
131 CComDebugObject(void * = NULL)
132 {
133 _pAtlModule->Lock();
134 }
135
136 virtual ~CComDebugObject()
137 {
138 this->FinalRelease();
139 _pAtlModule->Unlock();
140 }
141
142 STDMETHOD_(ULONG, AddRef)()
143 {
144 int rc = this->InternalAddRef();
145 DbgPrint("RefCount is now %d(++)!\n", rc);
146 return rc;
147 }
148
149 STDMETHOD_(ULONG, Release)()
150 {
151 ULONG newRefCount;
152
153 newRefCount = this->InternalRelease();
154 DbgPrint("RefCount is now %d(--)!\n", newRefCount);
155 if (newRefCount == 0)
156 delete this;
157 return newRefCount;
158 }
159
160 STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
161 {
162 return this->_InternalQueryInterface(iid, ppvObject);
163 }
164
165 static HRESULT WINAPI CreateInstance(CComDebugObject<Base> **pp)
166 {
167 CComDebugObject<Base> *newInstance;
168 HRESULT hResult;
169
170 ATLASSERT(pp != NULL);
171 if (pp == NULL)
172 return E_POINTER;
173
174 hResult = E_OUTOFMEMORY;
175 newInstance = NULL;
176 ATLTRY(newInstance = new CComDebugObject<Base>())
177 if (newInstance != NULL)
178 {
179 newInstance->SetVoid(NULL);
180 newInstance->InternalFinalConstructAddRef();
181 hResult = newInstance->_AtlInitialConstruct();
182 if (SUCCEEDED(hResult))
183 hResult = newInstance->FinalConstruct();
184 if (SUCCEEDED(hResult))
185 hResult = newInstance->_AtlFinalConstruct();
186 newInstance->InternalFinalConstructRelease();
187 if (hResult != S_OK)
188 {
189 delete newInstance;
190 newInstance = NULL;
191 }
192 }
193 *pp = newInstance;
194 return hResult;
195 }
196 };
197
198 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
199
200 #endif /* _BROWSEUI_PCH_ */