Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

602 lines
18 KiB

  1. #include "_apipch.h"
  2. extern HINSTANCE ghCommCtrlDLLInst;
  3. // extern LPIMAGELIST_LOADIMAGE gpfnImageList_LoadImage;
  4. extern LPIMAGELIST_LOADIMAGE_A gpfnImageList_LoadImageA;
  5. extern LPIMAGELIST_LOADIMAGE_W gpfnImageList_LoadImageW;
  6. #define TBARCONTAINERCLASS TEXT("WABTBarContainerClass")
  7. #undef FCIDM_TOOLBAR
  8. #define FCIDM_CONTAINER 4876
  9. #define FCIDM_TOOLBAR 4876
  10. #define CBIDX_TOOLS 4877
  11. #define TB_BMP_CX 26
  12. #define TB_BMP_CY 20
  13. #define MAX_TB_WIDTH 80
  14. enum _ImageLists
  15. {
  16. IMLIST_DEFAULT=0,
  17. IMLIST_HOT,
  18. IMLIST_DISABLED,
  19. imlMax
  20. };
  21. HDC m_hdc = NULL;
  22. LRESULT CALLBACK SizableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  23. void AddTools(LPBWI lpbwi, HWND hWndToolParent);
  24. BOOL LoadToolNames(TCHAR *szTools);
  25. #ifdef TOOLBAR_BACK
  26. void OnPaint(HWND hwnd,HBITMAP hbm,HDC hdc);
  27. #endif
  28. void InitToolbar( HWND hwnd,
  29. UINT nBtns, TBBUTTON *ptbb,
  30. TCHAR *pStrings, int cx,
  31. int cy, int cxMax,
  32. int idBmp,
  33. int nNumColors);
  34. /////******************************************************************************/
  35. /////******************************************************************************/
  36. /////******************************************************************************/
  37. #ifdef TOOLBAR_BACK
  38. HRESULT LoadBackBitmap()
  39. {
  40. HRESULT hr = E_FAIL;
  41. HBITMAP hbmSave;
  42. UINT n;
  43. COLORREF clrFace;
  44. UINT i;
  45. RGBQUAD rgbTable[256];
  46. RGBQUAD rgbFace;
  47. HDC m_hdc = NULL;
  48. LPPTGDATA lpPTGData=GetThreadStoragePointer();
  49. if (m_hbmBack)
  50. {
  51. DeleteObject(m_hbmBack);
  52. m_hbmBack = NULL;
  53. }
  54. if (m_hpalBkgnd)
  55. {
  56. DeleteObject(m_hpalBkgnd);
  57. m_hpalBkgnd = NULL;
  58. }
  59. m_hdc = CreateCompatibleDC(NULL);
  60. if (GetDeviceCaps(m_hdc, RASTERCAPS) & RC_PALETTE)
  61. m_hpalBkgnd = CreateHalftonePalette(m_hdc);
  62. m_hbmBack = (HBITMAP) LoadImage(hinstMapiX, MAKEINTRESOURCE(IDB_BITMAP_HBG),
  63. IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_CREATEDIBSECTION);
  64. if (!m_hbmBack)
  65. goto out;
  66. clrFace = GetSysColor(COLOR_BTNFACE);
  67. if (clrFace == RGB(192,192,192))
  68. {
  69. // no mapping needed
  70. hr = S_OK;
  71. goto out;
  72. }
  73. hbmSave = (HBITMAP)SelectObject(m_hdc, m_hbmBack);
  74. n = GetDIBColorTable(m_hdc, 0, 256, rgbTable);
  75. rgbFace.rgbRed = GetRValue(clrFace);
  76. rgbFace.rgbGreen = GetGValue(clrFace);
  77. rgbFace.rgbBlue = GetBValue(clrFace);
  78. for (i = 0; i < n; i++)
  79. {
  80. rgbTable[i].rgbRed = (rgbTable[i].rgbRed * rgbFace.rgbRed ) / 192;
  81. rgbTable[i].rgbGreen = (rgbTable[i].rgbGreen * rgbFace.rgbGreen) / 192;
  82. rgbTable[i].rgbBlue = (rgbTable[i].rgbBlue * rgbFace.rgbBlue ) / 192;
  83. }
  84. SetDIBColorTable(m_hdc, 0, n, rgbTable);
  85. SelectObject(m_hdc, hbmSave);
  86. hr = S_OK;
  87. out:
  88. if(m_hdc)
  89. DeleteDC(m_hdc);
  90. return(hr);
  91. }
  92. #endif
  93. /////******************************************************************************/
  94. /////******************************************************************************/
  95. /////******************************************************************************/
  96. HWND CreateCoolBar(LPBWI lpbwi, HWND hwndParent)
  97. {
  98. DWORD dwcbData = 0;
  99. DWORD dwType = 0;
  100. IF_WIN32(WNDCLASSEX wc;)
  101. IF_WIN16(WNDCLASS wc;)
  102. HWND hWnd = NULL;
  103. LPPTGDATA lpPTGData=GetThreadStoragePointer();
  104. // if no common control, exit
  105. if (NULL == ghCommCtrlDLLInst)
  106. goto out;
  107. #ifndef WIN16
  108. wc.cbSize = sizeof(WNDCLASSEX);
  109. if (!GetClassInfoEx(hinstMapiXWAB, TBARCONTAINERCLASS, &wc))
  110. {
  111. wc.style = 0;
  112. wc.lpfnWndProc = SizableWndProc;
  113. wc.cbClsExtra = 0;
  114. wc.cbWndExtra = 0;
  115. wc.hInstance = hinstMapiXWAB;
  116. wc.hCursor = 0;
  117. wc.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
  118. wc.lpszMenuName = NULL;
  119. wc.lpszClassName = TBARCONTAINERCLASS;
  120. wc.hIcon = NULL;
  121. wc.hIconSm = NULL;
  122. RegisterClassEx(&wc);
  123. }
  124. #else
  125. if (!GetClassInfo(hinstMapiXWAB, TBARCONTAINERCLASS, &wc))
  126. {
  127. wc.style = 0;
  128. wc.lpfnWndProc = SizableWndProc;
  129. wc.cbClsExtra = 0;
  130. wc.cbWndExtra = 0;
  131. wc.hInstance = hinstMapiXWAB;
  132. wc.hCursor = 0;
  133. wc.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
  134. wc.lpszMenuName = NULL;
  135. wc.lpszClassName = TBARCONTAINERCLASS;
  136. wc.hIcon = NULL;
  137. RegisterClass(&wc);
  138. }
  139. #endif
  140. #ifdef TOOLBAR_BACK
  141. LoadBackBitmap();
  142. #endif
  143. hWnd = CreateWindowEx( 0,//WS_EX_STATICEDGE,
  144. TBARCONTAINERCLASS,
  145. NULL,
  146. WS_VISIBLE | WS_CHILD |
  147. WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  148. 0,
  149. 0,
  150. 100,
  151. 36,
  152. hwndParent,
  153. (HMENU) FCIDM_CONTAINER,
  154. hinstMapiXWAB,
  155. (LPVOID)lpbwi);
  156. if (!hWnd)
  157. {
  158. DebugPrintError(( TEXT("CreateCoolBar: Show CreateWindow(TBARCONTAINERCLASS) failed")));
  159. goto out;
  160. }
  161. AddTools(lpbwi, hWnd);
  162. RedrawWindow( hWnd,
  163. NULL,
  164. NULL,
  165. RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
  166. out:
  167. return hWnd;
  168. }
  169. #define MAX_TB_BUTTONS 6
  170. /////******************************************************************************
  171. /////******************************************************************************
  172. ULONG GetToolbarButtonWidth()
  173. {
  174. ULONG ulMax = 0;
  175. TCHAR szBuf[MAX_UI_STR];
  176. LoadString(hinstMapiX, idsToolbarMaxButtonWidth, szBuf, CharSizeOf(szBuf));
  177. ulMax = my_atoi(szBuf);
  178. if( (ulMax<=0) || (ulMax>250) )
  179. ulMax = MAX_TB_WIDTH;
  180. return ulMax;
  181. }
  182. /////******************************************************************************
  183. void AddTools(LPBWI lpbwi, HWND hWndToolParent)
  184. {
  185. TCHAR szToolsText[(MAX_UI_STR + 2) * MAX_TB_BUTTONS];
  186. int nMaxButtons = MAX_TB_BUTTONS;
  187. HWND hWndTools = NULL;
  188. #ifndef WIN16
  189. TBBUTTON tbExplorer[] =
  190. {
  191. { 0, IDC_BB_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 0 },
  192. { 1, IDC_BB_PROPERTIES, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 1 },
  193. { 2, IDC_BB_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 2 },
  194. { 3, IDC_BB_FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 3 },
  195. { 4, IDC_BB_PRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 4 },
  196. { 5, IDC_BB_ACTION, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0,0}, 0, 5 },
  197. };
  198. #else // !WIN16
  199. TBBUTTON tbExplorer[] =
  200. {
  201. { 0, IDC_BB_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
  202. { 1, IDC_BB_PROPERTIES, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 1 },
  203. { 2, IDC_BB_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 2 },
  204. { 3, IDC_BB_FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 3 },
  205. { 4, IDC_BB_PRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 4 },
  206. { 5, IDC_BB_ACTION, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 5 },
  207. };
  208. #endif // !WIN16
  209. if(!bPrintingOn)
  210. nMaxButtons--;
  211. if(!bPrintingOn)
  212. tbExplorer[4] = tbExplorer[5];
  213. // create tools window
  214. hWndTools = CreateWindowEx( WS_EX_TOOLWINDOW,
  215. TOOLBARCLASSNAME,
  216. NULL,
  217. WS_CHILD | WS_VISIBLE | //WS_EX_TRANSPARENT |
  218. TBSTYLE_FLAT | /*TBSTYLE_TOOLTIPS | TBSTYLE_TRANSPARENT |*/
  219. WS_CLIPCHILDREN |
  220. WS_CLIPSIBLINGS |
  221. CCS_NODIVIDER | CCS_NOPARENTALIGN |
  222. CCS_NORESIZE,
  223. 2,
  224. 2,
  225. 100,
  226. 36,
  227. hWndToolParent,
  228. (HMENU) FCIDM_TOOLBAR,
  229. hinstMapiXWAB,
  230. NULL);
  231. if (!hWndTools)
  232. {
  233. DebugPrintError(( TEXT("AddTools: CITB:Show CreateWindow(TOOLBAR) failed")));
  234. goto out;
  235. }
  236. bwi_hWndTools = hWndTools;
  237. LoadToolNames(szToolsText);
  238. {
  239. // Check the current color resolution - if it is more than 256 colors we want
  240. // to use the high-color bitmaps
  241. int nNumColors = 0;
  242. HDC hDC = GetDC(NULL);
  243. nNumColors = GetDeviceCaps(hDC, BITSPIXEL);
  244. InitToolbar( hWndTools,
  245. nMaxButtons,
  246. tbExplorer,
  247. szToolsText,
  248. TB_BMP_CX,
  249. TB_BMP_CY,
  250. GetToolbarButtonWidth(),
  251. (nNumColors > 8) ? IDB_COOLBAR_DEFHI : IDB_COOLBAR_DEFAULT,
  252. nNumColors);
  253. ReleaseDC(NULL, hDC);
  254. }
  255. out:
  256. return;
  257. }
  258. /////******************************************************************************
  259. /////******************************************************************************
  260. /////******************************************************************************
  261. BOOL LoadToolNames(TCHAR *szTools)
  262. {
  263. int i;
  264. for (i = 0; i < MAX_TB_BUTTONS; i++)
  265. {
  266. LoadString(hinstMapiX, idsButton0 + i, szTools, MAX_UI_STR);
  267. szTools += lstrlen(szTools) + 1;
  268. }
  269. *szTools = TEXT('\0');
  270. return(TRUE);
  271. }
  272. /////******************************************************************************
  273. /////******************************************************************************
  274. /////******************************************************************************
  275. void InitToolbar( HWND hwnd,
  276. UINT nBtns,
  277. TBBUTTON *ptbb,
  278. TCHAR *pStrings,
  279. int cx,
  280. int cy,
  281. int cxMax,
  282. int idBmp,
  283. int nNumColors)
  284. {
  285. HIMAGELIST phiml[imlMax];
  286. int nRows = 2;
  287. int i;
  288. for (i = 0; i < imlMax; i++)
  289. {
  290. UINT uFlags = LR_DEFAULTCOLOR;
  291. if (nNumColors > 8 && i != IMLIST_DISABLED)
  292. uFlags |= LR_CREATEDIBSECTION|LR_LOADMAP3DCOLORS;
  293. phiml[i] = gpfnImageList_LoadImage( hinstMapiX,
  294. MAKEINTRESOURCE(idBmp + i),
  295. //(LPCTSTR) ((DWORD) ((WORD) (idBmp + i))),
  296. cx,
  297. 0,
  298. RGB(255,0,255),
  299. IMAGE_BITMAP,
  300. uFlags);
  301. }
  302. // this tells the toolbar what version we are
  303. SendMessage(hwnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
  304. SendMessage(hwnd, TB_SETMAXTEXTROWS, nRows, 0L);
  305. SendMessage(hwnd, TB_SETBITMAPSIZE, 0, MAKELONG(cx, cy));
  306. SendMessage(hwnd, TB_SETIMAGELIST, 0, (LPARAM) phiml[IMLIST_DEFAULT]);
  307. SendMessage(hwnd, TB_SETHOTIMAGELIST, 0, (LPARAM) phiml[IMLIST_HOT]);
  308. SendMessage(hwnd, TB_SETDISABLEDIMAGELIST,0, (LPARAM) phiml[IMLIST_DISABLED]);
  309. ToolBar_AddString(hwnd, (LPARAM) pStrings);
  310. ToolBar_AddButtons(hwnd, nBtns, (LPARAM) ptbb);
  311. SendMessage(hwnd, TB_SETBUTTONWIDTH, 0, MAKELONG(0, cxMax));
  312. //Reset the toolbar container height to match the toolbars height
  313. {
  314. RECT rcTB, rcParent;
  315. HWND hwndParent = GetParent(hwnd);
  316. SendMessage(hwnd,TB_GETITEMRECT,0,(LPARAM) &rcTB);
  317. GetWindowRect(hwndParent,&rcParent);
  318. MoveWindow(hwndParent,rcParent.left, rcParent.top, rcParent.right - rcParent.left, rcTB.bottom-rcTB.top + 4,TRUE);
  319. }
  320. }
  321. /////******************************************************************************
  322. /////******************************************************************************
  323. /////******************************************************************************
  324. LRESULT CALLBACK SizableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  325. {
  326. switch(uMsg)
  327. {
  328. case WM_CREATE:
  329. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LPARAM) ((LPCREATESTRUCT) lParam)->lpCreateParams);
  330. break;
  331. case WM_SETTINGCHANGE:
  332. case WM_SYSCOLORCHANGE:
  333. {
  334. LPBWI lpbwi = (LPBWI)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  335. SendMessage(bwi_hWndTools, uMsg, wParam, lParam);
  336. }
  337. #ifdef TOOLBAR_BACK
  338. LoadBackBitmap();
  339. #endif
  340. RedrawWindow(hwnd, NULL, NULL, RDW_ALLCHILDREN);
  341. break;
  342. case WM_VKEYTOITEM:
  343. case WM_CHARTOITEM:
  344. // We must swallow these messages to avoid infinite SendMessage
  345. break;
  346. case WM_NOTIFY:
  347. // We must swallow these messages to avoid infinite SendMessage
  348. //return(OnNotify((LPNMHDR) lParam));
  349. break;
  350. // case WM_PAINT:
  351. // break;
  352. case WM_ERASEBKGND:
  353. //
  354. // The TBSTYLE_FLAT toolbar cheats a little - to draw the
  355. // background bitmap, we have to draw the bitmap in the
  356. // WM_ERASEBKGND message. Then the toolbar draws a frame
  357. // around the selected button - when the mouse is removed from
  358. // the selected button, the toolbar sends us a
  359. // WM_ERASEBKGND again - but this time the corresponding
  360. // hdc is the hdc of the Toolbar and not of the child window.
  361. // So we **must** use this given hdc to redraw the background
  362. // bitmap, this time onto the toolbar, thus cleaning it up.
  363. #ifdef TOOLBAR_BACK
  364. OnPaint(hwnd, m_hbmBack, (HDC) wParam);
  365. return TRUE;
  366. #else
  367. {
  368. RECT rc;
  369. GetClientRect(hwnd, &rc);
  370. if(!DrawEdge((HDC) wParam, &rc, EDGE_ETCHED, BF_RECT))
  371. DebugPrintError(( TEXT("Drawedge failed: %u\n"),GetLastError()));
  372. }
  373. #endif
  374. break;
  375. case WM_SIZE:
  376. {
  377. LPBWI lpbwi = (LPBWI)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  378. RECT rc,rc1;
  379. GetClientRect(hwnd, &rc);
  380. GetChildClientRect(bwi_hWndTools, &rc1);
  381. if(bwi_hWndTools)
  382. MoveWindow(bwi_hWndTools, rc1.left, rc1.top, rc.right-rc.left-4, rc.bottom-rc.top-4, TRUE);
  383. {
  384. HDC hdc = GetDC(hwnd);
  385. #ifdef TOOLBAR_BACK
  386. OnPaint(hwnd, m_hbmBack, hdc);
  387. #else
  388. {
  389. RECT rc;
  390. GetClientRect(hwnd, &rc);
  391. if(!DrawEdge(hdc, &rc, EDGE_ETCHED, BF_RECT))
  392. DebugPrintError(( TEXT("Drawedge failed: %u\n"),GetLastError()));
  393. }
  394. #endif
  395. ReleaseDC(hwnd,hdc);
  396. }
  397. }
  398. break;
  399. case WM_DESTROY:
  400. #ifdef TOOLBAR_BACK
  401. if (m_hbmBack)
  402. {
  403. DeleteObject(m_hbmBack);
  404. m_hbmBack = NULL;
  405. }
  406. if (m_hpalBkgnd)
  407. {
  408. DeleteObject(m_hpalBkgnd);
  409. m_hpalBkgnd = NULL;
  410. }
  411. #endif
  412. break;
  413. case WM_COMMAND:
  414. //OnCommand(wParam, lParam);
  415. SendMessage(GetParent(hwnd),uMsg,wParam,lParam);
  416. break;
  417. case WM_PRVATETOOLBARENABLE:
  418. {
  419. LPBWI lpbwi = (LPBWI)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  420. SendMessage(bwi_hWndTools, TB_ENABLEBUTTON, wParam, lParam);
  421. }
  422. break;
  423. case WM_PALETTECHANGED:
  424. RedrawWindow( hwnd,
  425. NULL,
  426. NULL,
  427. RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
  428. break;
  429. default:
  430. return(DefWindowProc(hwnd, uMsg, wParam, lParam));
  431. }
  432. return 0L;
  433. }
  434. #ifdef TOOLBAR_BACK
  435. void OnPaint(HWND hwnd,HBITMAP hbm, HDC hdc)
  436. {
  437. // HDC hdc;
  438. PAINTSTRUCT ps;
  439. HDC hdcMem;
  440. HBITMAP hbmMemOld;
  441. HPALETTE hpalOld = NULL;
  442. RECT rc;
  443. BITMAP bm;
  444. int cxIndent = 3;
  445. int cyIndent = 3;
  446. int nTop = 0;
  447. int nLeft = 0;
  448. int nButton = 0;
  449. int i=0;
  450. LPPTGDATA lpPTGData=GetThreadStoragePointer();
  451. // Get the size of the background bitmap
  452. GetObject(hbm, sizeof(BITMAP), (LPVOID) &bm);
  453. GetClientRect(hwnd, &rc);
  454. BeginPaint(hwnd, &ps);
  455. if(hdc)
  456. {
  457. hdcMem = CreateCompatibleDC(hdc);
  458. if (m_hpalBkgnd)
  459. {
  460. hpalOld = SelectPalette(hdc, m_hpalBkgnd, TRUE);
  461. RealizePalette(hdc);
  462. }
  463. hbmMemOld = (HBITMAP) SelectObject(hdcMem, (HGDIOBJ) hbm);
  464. nTop = 0;
  465. nLeft = 0;
  466. while (nLeft < rc.right)
  467. {
  468. BitBlt(hdc, nLeft, nTop, bm.bmWidth, bm.bmHeight, hdcMem, 0,
  469. 0, SRCCOPY);
  470. nLeft += bm.bmWidth;
  471. }
  472. {
  473. if(!DrawEdge(hdc, &rc, EDGE_ETCHED, BF_RECT))
  474. DebugPrintError(("Drawedge failed: %u\n",GetLastError()));
  475. }
  476. if (hpalOld != NULL)
  477. SelectPalette(hdc, hpalOld, TRUE);
  478. SelectObject(hdcMem, hbmMemOld);
  479. DeleteDC(hdcMem);
  480. } // if hdc...
  481. EndPaint(hwnd, &ps);
  482. return;
  483. }
  484. #endif