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.

360 lines
8.9 KiB

  1. /* File: D:\WACKER\tdll\sidebar.c (Created: 10-Mar-1995)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 12 $
  7. * $Date: 4/16/02 2:41p $
  8. */
  9. #include <windows.h>
  10. #include "stdtyp.h"
  11. #include "globals.h"
  12. #include "assert.h"
  13. #include "session.h"
  14. #include <term\res.h>
  15. #include <emu\emu.h>
  16. #include "htchar.h"
  17. #define INDENT 3
  18. #define SIDEBAR_CLASS "sidebar class"
  19. #define LOSHORT(x) ((short)LOWORD(x))
  20. #define HISHORT(x) ((short)HIWORD(x))
  21. static void SB_WM_SIZE(const HWND hwnd, const int cx, const int cy);
  22. LRESULT CALLBACK SidebarButtonProc(HWND hwnd, UINT uMsg, WPARAM wPar, LPARAM lPar);
  23. // I know, a static. Bad news but not really. Since this is just for
  24. // the minitel I didn't want to screw around with local atoms. If we
  25. // ever decide that this stuff will be used for more general purposes,
  26. // we can put in the atoms
  27. //
  28. static WNDPROC fpSidebarButtonProc;
  29. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  30. * FUNCTION:
  31. * CreateSidebar
  32. *
  33. * DESCRIPTION:
  34. * Creates a sidebar. What's a sidebar you say? Its a bar with buttons
  35. * on it running down the left side of the session window. It is used
  36. * only for the minitel emulator and displays buttons specific to that
  37. * emulator.
  38. *
  39. * ARGUMENTS:
  40. * hwndSession - session window handle.
  41. *
  42. * RETURNS:
  43. * sidebar window handle.
  44. *
  45. * AUTHOR: Mike Ward, 10-Mar-1995
  46. */
  47. HWND CreateSidebar(const HWND hwndSession, const HSESSION hSession)
  48. {
  49. UINT i;
  50. TCHAR ach[100];
  51. HWND hwnd;
  52. HWND hwndSideBar;
  53. SIZE sz;
  54. LONG cx = 0;
  55. LONG cy = 0;
  56. HDC hdc;
  57. HGDIOBJ hFont;
  58. // Figure out the longest string to size things by
  59. //
  60. hdc = GetDC(hwndSession);
  61. hFont = GetStockObject(DEFAULT_GUI_FONT);
  62. SelectObject(hdc, hFont);
  63. for (i = 0 ; i < 9 ; ++i)
  64. {
  65. LoadString(glblQueryDllHinst(), IDS_SIDEBAR_INDEX+i, ach,
  66. sizeof(ach) / sizeof(TCHAR));
  67. GetTextExtentPoint32(hdc, ach, StrCharGetStrLength(ach), &sz);
  68. cx = max(sz.cx, cx);
  69. cy = max(sz.cy, cy);
  70. }
  71. ReleaseDC(hwndSession, hdc);
  72. // Good button size is 1.5 times text height. Also add padding
  73. // for horizontal diretion.
  74. //
  75. cx += WINDOWSBORDERWIDTH * 10;
  76. cy = (LONG)(cy * 1.5);
  77. // Create sidebar window with proper x dimension
  78. //
  79. hwndSideBar = CreateWindowEx(WS_EX_CLIENTEDGE, SIDEBAR_CLASS, 0,
  80. WS_CHILD, 0, 0, cx+2+(2*INDENT), 100, hwndSession,
  81. (HMENU)IDC_SIDEBAR_WIN, glblQueryDllHinst(), hSession);
  82. // Important: Set fpSidebarButtonProc to zero here. It may have
  83. // been initialized by an earlier instance. We could set it to
  84. // zero in the WM_DESTROY but then I'ld have to keep a list of
  85. // button window handles which I don't want to do here.
  86. //
  87. fpSidebarButtonProc = 0;
  88. // Create buttons for sidebar and postion with text
  89. //
  90. for (i = 0 ; i < 9 ; ++i)
  91. {
  92. LoadString(glblQueryDllHinst(), IDS_SIDEBAR_INDEX+i, ach, sizeof(ach) / sizeof(TCHAR));
  93. hwnd = CreateWindowEx(0, "BUTTON", ach,
  94. WS_CHILD | WS_VISIBLE | BS_LEFT | BS_PUSHBUTTON,
  95. 0, 0, cx, cy, hwndSideBar,
  96. (HMENU)IntToPtr(IDM_MINITEL_INDEX+i), glblQueryDllHinst(), 0);
  97. if ( hwnd == NULL )
  98. {
  99. assert( hwnd );
  100. return 0;
  101. }
  102. SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, 0);
  103. MoveWindow(hwnd, INDENT, ((int)i*(cy+INDENT))+INDENT, cx, cy, FALSE);
  104. // Need to subclass the buttons so that they don't get the focus
  105. // rectangle left on them. This will require an atom to so that
  106. // we can get the original button proc.
  107. //
  108. if (fpSidebarButtonProc == 0)
  109. fpSidebarButtonProc = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_WNDPROC);
  110. if (fpSidebarButtonProc)
  111. SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)SidebarButtonProc);
  112. }
  113. return hwndSideBar;
  114. }
  115. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  116. * FUNCTION:
  117. * SidebarProc
  118. *
  119. * DESCRIPTION:
  120. * Sidebar window proc.
  121. *
  122. * AUTHOR: Mike Ward, 10-Mar-1995
  123. */
  124. LRESULT CALLBACK SidebarProc(HWND hwnd, UINT uMsg, WPARAM wPar, LPARAM lPar)
  125. {
  126. HSESSION hSession;
  127. switch (uMsg)
  128. {
  129. case WM_CREATE:
  130. // Save session handle for later
  131. //
  132. SetWindowLongPtr(hwnd, GWLP_USERDATA,
  133. (LONG_PTR)((LPCREATESTRUCT)lPar)->lpCreateParams);
  134. return 0;
  135. case WM_COMMAND:
  136. switch (LOWORD(wPar))
  137. {
  138. case IDM_MINITEL_INDEX:
  139. case IDM_MINITEL_CANCEL:
  140. case IDM_MINITEL_PREVIOUS:
  141. case IDM_MINITEL_REPEAT:
  142. case IDM_MINITEL_GUIDE:
  143. case IDM_MINITEL_CORRECT:
  144. case IDM_MINITEL_NEXT:
  145. case IDM_MINITEL_SEND:
  146. case IDM_MINITEL_CONFIN:
  147. if (HIWORD(wPar) == BN_CLICKED)
  148. {
  149. hSession = (HSESSION)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  150. emuMinitelSendKey(sessQueryEmuHdl(hSession),
  151. LOWORD(wPar));
  152. SetFocus(sessQueryHwnd(hSession));
  153. }
  154. break;
  155. default:
  156. break;
  157. }
  158. break;
  159. case WM_SIZE:
  160. SB_WM_SIZE(hwnd, LOSHORT(lPar), HISHORT(lPar));
  161. return 0;
  162. default:
  163. break;
  164. }
  165. return DefWindowProc(hwnd, uMsg, wPar, lPar);
  166. }
  167. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  168. * FUNCTION:
  169. * SB_WM_SIZE
  170. *
  171. * DESCRIPTION:
  172. * Sizing logic for sidebar. This routine sizes the sidebar vertically
  173. * to the session window.
  174. *
  175. * ARGUMENTS:
  176. * hwnd - sidebar window handle
  177. * cx - x size of window
  178. * cy - y size of window
  179. *
  180. * RETURNS:
  181. * void
  182. *
  183. * AUTHOR: Mike Ward, 10-Mar-1995
  184. */
  185. static void SB_WM_SIZE(const HWND hwnd, const int cx, const int cy)
  186. {
  187. RECT rc;
  188. RECT rcSB;
  189. RECT rcTmp;
  190. const HSESSION hSession = (HSESSION)GetWindowLongPtr(GetParent(hwnd),
  191. GWLP_USERDATA);
  192. const HWND hwndToolbar = sessQueryHwndToolbar(hSession);
  193. const HWND hwndStatusbar = sessQueryHwndStatusbar(hSession);
  194. if (cx != 0 || cy != 0)
  195. return;
  196. GetWindowRect(hwnd, &rcSB);
  197. GetClientRect(GetParent(hwnd), &rc);
  198. if (IsWindow(hwndToolbar) && IsWindowVisible(hwndToolbar))
  199. {
  200. GetWindowRect(hwndToolbar, &rcTmp);
  201. rc.top += (rcTmp.bottom - rcTmp.top);
  202. }
  203. if (IsWindow(hwndStatusbar) && IsWindowVisible(hwndStatusbar))
  204. {
  205. GetWindowRect(hwndStatusbar, &rcTmp);
  206. rc.bottom -= (rcTmp.bottom - rcTmp.top);
  207. rc.bottom += 2 * WINDOWSBORDERHEIGHT;
  208. }
  209. MoveWindow(hwnd, rc.left, rc.top, rcSB.right-rcSB.left, rc.bottom-rc.top,
  210. TRUE);
  211. return;
  212. }
  213. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  214. * FUNCTION:
  215. * RegisterSidebarClass
  216. *
  217. * DESCRIPTION:
  218. * Registers the sidebar window class used for Minitel.
  219. *
  220. * ARGUMENTS:
  221. * hInstance - instance handle of program.
  222. *
  223. * RETURNS:
  224. * TRUE/FALSE
  225. *
  226. * AUTHOR: Mike Ward, 10-Mar-1995
  227. */
  228. BOOL RegisterSidebarClass(const HINSTANCE hInstance)
  229. {
  230. WNDCLASSEX wc;
  231. memset(&wc, 0, sizeof(WNDCLASSEX));
  232. wc.cbSize = sizeof(WNDCLASSEX);
  233. if (GetClassInfoEx(hInstance, SIDEBAR_CLASS, &wc) == FALSE)
  234. {
  235. wc.style = CS_HREDRAW | CS_VREDRAW;
  236. wc.lpfnWndProc = SidebarProc;
  237. wc.cbClsExtra = 0;
  238. wc.cbWndExtra = sizeof(LONG_PTR);
  239. wc.hInstance = hInstance;
  240. wc.hIcon = NULL;
  241. wc.hCursor = LoadCursor(0, IDC_ARROW);
  242. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  243. wc.lpszMenuName = NULL;
  244. wc.lpszClassName = SIDEBAR_CLASS;
  245. wc.hIconSm = NULL;
  246. if (RegisterClassEx(&wc) == FALSE)
  247. {
  248. assert(FALSE);
  249. return FALSE;
  250. }
  251. }
  252. return TRUE;
  253. }
  254. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  255. * FUNCTION:
  256. * SidebarButtonProc
  257. *
  258. * DESCRIPTION:
  259. * Don't you just love windows. I don't want the focus to ever remain
  260. * on the Sidebar but to do this with standard buttons I have to subclass
  261. * them.
  262. *
  263. * AUTHOR: Mike Ward, 13-Mar-1995
  264. */
  265. LRESULT CALLBACK SidebarButtonProc(HWND hwnd, UINT uMsg, WPARAM wPar, LPARAM lPar)
  266. {
  267. HSESSION hSession;
  268. POINT pt;
  269. RECT rc;
  270. switch (uMsg)
  271. {
  272. case WM_LBUTTONUP:
  273. hSession = (HSESSION)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
  274. // Well, its never simple. If the user clicks on the button, we don't
  275. // reset focus else our sidebar never receives the notification. If
  276. // the user holds the button down however and drags off the button
  277. // and then lets up (button up not on the button) then we need to
  278. // set focus. - mrw.
  279. //
  280. pt.x = LOWORD(lPar);
  281. pt.y = HIWORD(lPar);
  282. GetClientRect(hwnd, &rc);
  283. if (!PtInRect(&rc, pt))
  284. SetFocus(sessQueryHwnd(hSession));
  285. break;
  286. default:
  287. break;
  288. }
  289. return CallWindowProc(fpSidebarButtonProc, hwnd, uMsg, wPar, lPar);
  290. }
  291. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  292. * FUNCTION:
  293. * UnregisterSidebarClass
  294. *
  295. * DESCRIPTION:
  296. * Registers the sidebar window class used for Minitel.
  297. *
  298. * ARGUMENTS:
  299. * hInstance - instance handle of program.
  300. *
  301. * RETURNS:
  302. * TRUE/FALSE
  303. *
  304. * AUTHOR: Mike Ward, 10-Mar-1995
  305. */
  306. BOOL UnregisterSidebarClass(const HINSTANCE hInstance)
  307. {
  308. return UnregisterClass(SIDEBAR_CLASS, hInstance);
  309. }