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.

742 lines
14 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. widget.c
  5. Abstract:
  6. Widget creation/management/deletion support for TAPI Browser util.
  7. Author:
  8. Dan Knudson (DanKn) 23-Aug-1994
  9. Revision History:
  10. --*/
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include <string.h>
  14. #include <ctype.h>
  15. #include <malloc.h>
  16. #include "tb.h"
  17. #include "vars.h"
  18. void
  19. UpdateWidgetList(
  20. void
  21. )
  22. {
  23. int i;
  24. LRESULT lSel = SendMessage (ghwndList1, LB_GETCURSEL, 0, 0);
  25. PMYWIDGET pWidget = aWidgets, pSelWidget = (PMYWIDGET) NULL;
  26. if (lSel != LB_ERR)
  27. {
  28. pSelWidget = (PMYWIDGET) SendMessage(
  29. ghwndList1,
  30. LB_GETITEMDATA,
  31. (WPARAM) lSel,
  32. 0
  33. );
  34. }
  35. SendMessage (ghwndList1, LB_RESETCONTENT, 0, 0);
  36. for (i = 0; pWidget; i++)
  37. {
  38. char buf[64];
  39. switch (pWidget->dwType)
  40. {
  41. case WT_LINEAPP:
  42. sprintf (buf, "LineApp=x%lx", ((PMYLINEAPP) pWidget)->hLineApp);
  43. break;
  44. case WT_LINE:
  45. {
  46. PMYLINE pLine = (PMYLINE) pWidget;
  47. sprintf(
  48. buf,
  49. " Line=x%lx id=%ld ",
  50. pLine->hLine,
  51. pLine->dwDevID
  52. );
  53. if (pLine->dwPrivileges & LINECALLPRIVILEGE_NONE)
  54. {
  55. strcat (buf, "DialOut");
  56. }
  57. else
  58. {
  59. if (pLine->dwPrivileges & LINECALLPRIVILEGE_OWNER)
  60. {
  61. strcat (buf, "DialInOut");
  62. }
  63. if (pLine->dwPrivileges & LINECALLPRIVILEGE_MONITOR)
  64. {
  65. strcat (buf, " Monitor");
  66. }
  67. }
  68. if (pLine->dwPrivileges & LINEOPENOPTION_PROXY)
  69. {
  70. strcat (buf, " Proxy");
  71. }
  72. break;
  73. }
  74. case WT_CALL:
  75. {
  76. PMYCALL pCall = (PMYCALL) pWidget;
  77. if (pCall->hCall)
  78. {
  79. int i;
  80. for (i = 0; aCallStates[i].dwVal != 0xffffffff; i++)
  81. {
  82. if (pCall->dwCallState == aCallStates[i].dwVal)
  83. {
  84. break;
  85. }
  86. }
  87. sprintf(
  88. buf,
  89. " Call=x%lx %s %s",
  90. pCall->hCall,
  91. aCallStates[i].lpszVal,
  92. (pCall->bMonitor ? "Monitor" : "Owner")
  93. );
  94. }
  95. else
  96. {
  97. strcpy (buf, " <MakeCall reply pending>");
  98. }
  99. break;
  100. }
  101. case WT_PHONEAPP:
  102. sprintf (buf, "PhoneApp=x%lx", ((PMYPHONEAPP) pWidget)->hPhoneApp);
  103. break;
  104. case WT_PHONE:
  105. sprintf(
  106. buf,
  107. " Phone=x%lx id=%ld",
  108. ((PMYPHONE) pWidget)->hPhone,
  109. ((PMYPHONE) pWidget)->dwDevID
  110. );
  111. break;
  112. }
  113. SendMessage (ghwndList1, LB_INSERTSTRING, (WPARAM) -1, (LPARAM) buf);
  114. SendMessage (ghwndList1, LB_SETITEMDATA, (WPARAM) i, (LPARAM) pWidget);
  115. pWidget = pWidget->pNext;
  116. }
  117. //
  118. // Restore selection if appropriate
  119. //
  120. if ((lSel != LB_ERR) && ((lSel = (LONG) GetWidgetIndex (pSelWidget)) >= 0))
  121. {
  122. SendMessage (ghwndList1, LB_SETCURSEL, (WPARAM) lSel, 0);
  123. }
  124. }
  125. void
  126. InsertWidgetInList(
  127. PMYWIDGET pNewWidget,
  128. PMYWIDGET pWidgetInsertBefore
  129. )
  130. {
  131. pNewWidget->pNext = pWidgetInsertBefore;
  132. if ((aWidgets == NULL) || (pWidgetInsertBefore == aWidgets))
  133. {
  134. aWidgets = pNewWidget;
  135. }
  136. else
  137. {
  138. PMYWIDGET pPrevWidget = aWidgets;
  139. while (pPrevWidget->pNext &&
  140. (pPrevWidget->pNext != pWidgetInsertBefore))
  141. {
  142. pPrevWidget = pPrevWidget->pNext;
  143. }
  144. pPrevWidget->pNext = pNewWidget;
  145. }
  146. UpdateWidgetList();
  147. }
  148. BOOL
  149. RemoveWidgetFromList(
  150. PMYWIDGET pWidgetToRemove
  151. )
  152. {
  153. if (aWidgets == NULL)
  154. {
  155. goto RemoveWidgetFromList_error;
  156. }
  157. if (pWidgetToRemove == aWidgets)
  158. {
  159. aWidgets = pWidgetToRemove->pNext;
  160. }
  161. else
  162. {
  163. PMYWIDGET pPrevWidget = aWidgets;
  164. while (pPrevWidget->pNext && (pPrevWidget->pNext != pWidgetToRemove))
  165. {
  166. pPrevWidget = pPrevWidget->pNext;
  167. }
  168. if (pPrevWidget->pNext == NULL)
  169. {
  170. goto RemoveWidgetFromList_error;
  171. }
  172. pPrevWidget->pNext = pWidgetToRemove->pNext;
  173. }
  174. free (pWidgetToRemove);
  175. UpdateWidgetList();
  176. return TRUE;
  177. RemoveWidgetFromList_error:
  178. ShowStr ("Error: pWidget x%lx not found in list", pWidgetToRemove);
  179. return FALSE;
  180. }
  181. PMYLINEAPP
  182. AllocLineApp(
  183. void
  184. )
  185. {
  186. PMYLINEAPP pNewLineApp = (PMYLINEAPP) malloc (sizeof(MYLINEAPP));
  187. if (pNewLineApp)
  188. {
  189. PMYWIDGET pWidget = aWidgets;
  190. memset (pNewLineApp, 0, sizeof(MYLINEAPP));
  191. pNewLineApp->Widget.dwType = WT_LINEAPP;
  192. //
  193. // Insert new line app after all existing line apps, lines, & calls,
  194. // and before any existing phone apps
  195. //
  196. while (pWidget && (pWidget->dwType != WT_PHONEAPP))
  197. {
  198. // assert (pWidget->dwType != WT_PHONE)
  199. pWidget = pWidget->pNext;
  200. }
  201. InsertWidgetInList ((PMYWIDGET) pNewLineApp, pWidget);
  202. }
  203. return pNewLineApp;
  204. }
  205. PMYLINEAPP
  206. GetLineApp(
  207. HLINEAPP hLineApp
  208. )
  209. {
  210. PMYWIDGET pWidget = aWidgets;
  211. while (pWidget)
  212. {
  213. if (pWidget->dwType == WT_LINEAPP)
  214. {
  215. PMYLINEAPP pLineApp = (PMYLINEAPP) pWidget;
  216. if (pLineApp->hLineApp == hLineApp)
  217. {
  218. break;
  219. }
  220. }
  221. pWidget = pWidget->pNext;
  222. }
  223. return ((PMYLINEAPP) pWidget);
  224. }
  225. VOID
  226. FreeLineApp(
  227. PMYLINEAPP pLineApp
  228. )
  229. {
  230. PMYWIDGET pWidget = pLineApp->Widget.pNext;
  231. // BUGBUG chk validity of pLineApp
  232. if (RemoveWidgetFromList ((PMYWIDGET) pLineApp))
  233. {
  234. while (pWidget &&
  235. (pWidget->dwType != WT_LINEAPP) &&
  236. (pWidget->dwType != WT_PHONEAPP))
  237. {
  238. PMYWIDGET pWidget2 = pWidget->pNext;
  239. // assert (pWidget->dwType != WT_PHONE)
  240. RemoveWidgetFromList (pWidget);
  241. pWidget = pWidget2;
  242. }
  243. }
  244. }
  245. PMYLINE
  246. AllocLine(
  247. PMYLINEAPP pLineApp
  248. )
  249. {
  250. PMYLINE pNewLine = (PMYLINE) malloc (sizeof(MYLINE));
  251. if (pNewLine)
  252. {
  253. PMYWIDGET pWidget = (PMYWIDGET) pLineApp->Widget.pNext;
  254. memset (pNewLine, 0, sizeof(MYLINE));
  255. pNewLine->Widget.dwType = WT_LINE;
  256. pNewLine->pLineApp = pLineApp;
  257. //
  258. // Insert new line after all existing lines & calls on specfied
  259. // line app, but before the next line app or phone app
  260. //
  261. while (pWidget &&
  262. (pWidget->dwType != WT_LINEAPP) &&
  263. (pWidget->dwType != WT_PHONEAPP))
  264. {
  265. pWidget = pWidget->pNext;
  266. }
  267. InsertWidgetInList ((PMYWIDGET) pNewLine, pWidget);
  268. }
  269. return pNewLine;
  270. }
  271. PMYLINE
  272. GetLine(
  273. HLINE hLine
  274. )
  275. {
  276. PMYWIDGET pWidget = aWidgets;
  277. while (pWidget)
  278. {
  279. if (pWidget->dwType == WT_LINE)
  280. {
  281. PMYLINE pLine = (PMYLINE) pWidget;
  282. if (pLine->hLine == hLine)
  283. {
  284. break;
  285. }
  286. }
  287. pWidget = pWidget->pNext;
  288. }
  289. return ((PMYLINE) pWidget);
  290. }
  291. VOID
  292. FreeLine(
  293. PMYLINE pLine
  294. )
  295. {
  296. PMYWIDGET pWidget = pLine->Widget.pNext;
  297. if (RemoveWidgetFromList ((PMYWIDGET) pLine))
  298. {
  299. while (pWidget &&
  300. (pWidget->dwType == WT_CALL))
  301. {
  302. PMYWIDGET pWidget2 = pWidget->pNext;
  303. RemoveWidgetFromList (pWidget);
  304. pWidget = pWidget2;
  305. }
  306. }
  307. }
  308. PMYCALL
  309. AllocCall(
  310. PMYLINE pLine
  311. )
  312. {
  313. PMYCALL pNewCall = (PMYCALL) malloc (sizeof(MYCALL));
  314. if (pNewCall)
  315. {
  316. PMYWIDGET pWidget = (PMYWIDGET) pLine->Widget.pNext;
  317. memset (pNewCall, 0, sizeof(MYCALL));
  318. pNewCall->Widget.dwType = WT_CALL;
  319. pNewCall->pLine = pLine;
  320. //
  321. // Insert new call after all existing calls on specified line,
  322. // and before the next line, line app, or phone app
  323. //
  324. while (pWidget && (pWidget->dwType == WT_CALL))
  325. {
  326. pWidget = pWidget->pNext;
  327. }
  328. InsertWidgetInList ((PMYWIDGET) pNewCall, pWidget);
  329. }
  330. return pNewCall;
  331. }
  332. PMYCALL
  333. GetCall(
  334. HCALL hCall
  335. )
  336. {
  337. PMYWIDGET pWidget = aWidgets;
  338. while (pWidget)
  339. {
  340. if (pWidget->dwType == WT_CALL)
  341. {
  342. PMYCALL pCall = (PMYCALL) pWidget;
  343. if (pCall->hCall == hCall)
  344. {
  345. break;
  346. }
  347. }
  348. pWidget = pWidget->pNext;
  349. }
  350. return ((PMYCALL) pWidget);
  351. }
  352. VOID
  353. FreeCall(
  354. PMYCALL pCall
  355. )
  356. {
  357. // BUGBUG chk validity of pCall
  358. RemoveWidgetFromList ((PMYWIDGET) pCall);
  359. }
  360. VOID
  361. MoveCallToLine(
  362. PMYCALL pCall,
  363. HLINE hLine
  364. )
  365. {
  366. //
  367. // This func gets called when a user has invoked an op that requires
  368. // creating a call, and we did an AllocCall() based on the currently
  369. // selected line/calls, but in the call params dlg the user overrode
  370. // the default hLine/hCall, and so we need to move the call widget
  371. // in the global list from under the orig specified line widget to
  372. // the line widget corresponding to the specified "hLine". (Note that
  373. // this is not a simple matter of free-ing & realloc-ing another call,
  374. // since TAPI saved the &pCall->hCall.)
  375. //
  376. PMYWIDGET pWidget = aWidgets;
  377. //
  378. // Remove call widget from the global list
  379. //
  380. while (pWidget->pNext != (PMYWIDGET) pCall)
  381. {
  382. pWidget = pWidget->pNext;
  383. }
  384. pWidget->pNext = pCall->Widget.pNext;
  385. //
  386. // Find the right place to insert it in list, then insert it
  387. //
  388. pWidget = (PMYWIDGET) GetLine (hLine);
  389. pCall->pLine = (PMYLINE) pWidget;
  390. while (pWidget->pNext && (pWidget->pNext->dwType == WT_CALL))
  391. {
  392. pWidget = pWidget->pNext;
  393. }
  394. pCall->Widget.pNext = pWidget->pNext;
  395. pWidget->pNext = (PMYWIDGET) pCall;
  396. UpdateWidgetList();
  397. }
  398. PMYPHONEAPP
  399. AllocPhoneApp(
  400. void
  401. )
  402. {
  403. PMYPHONEAPP pNewPhoneApp = (PMYPHONEAPP) malloc (sizeof(MYPHONEAPP));
  404. if (pNewPhoneApp)
  405. {
  406. PMYWIDGET pWidget = aWidgets;
  407. memset (pNewPhoneApp, 0, sizeof(MYPHONEAPP));
  408. pNewPhoneApp->Widget.dwType = WT_PHONEAPP;
  409. //
  410. // Insert new phone app at end of list
  411. //
  412. InsertWidgetInList ((PMYWIDGET) pNewPhoneApp, (PMYWIDGET) NULL);
  413. }
  414. return pNewPhoneApp;
  415. }
  416. PMYPHONEAPP
  417. GetPhoneApp(
  418. HPHONEAPP hPhoneApp
  419. )
  420. {
  421. PMYWIDGET pWidget = aWidgets;
  422. while (pWidget)
  423. {
  424. if (pWidget->dwType == WT_PHONEAPP)
  425. {
  426. PMYPHONEAPP pPhoneApp = (PMYPHONEAPP) pWidget;
  427. if (pPhoneApp->hPhoneApp == hPhoneApp)
  428. {
  429. break;
  430. }
  431. }
  432. pWidget = pWidget->pNext;
  433. }
  434. return ((PMYPHONEAPP) pWidget);
  435. }
  436. VOID
  437. FreePhoneApp(
  438. PMYPHONEAPP pPhoneApp
  439. )
  440. {
  441. PMYWIDGET pWidget = pPhoneApp->Widget.pNext;
  442. if (RemoveWidgetFromList ((PMYWIDGET) pPhoneApp))
  443. {
  444. while (pWidget && (pWidget->dwType == WT_PHONE))
  445. {
  446. PMYWIDGET pWidget2 = pWidget->pNext;
  447. RemoveWidgetFromList (pWidget);
  448. pWidget = pWidget2;
  449. }
  450. }
  451. }
  452. PMYPHONE
  453. AllocPhone(
  454. PMYPHONEAPP pPhoneApp
  455. )
  456. {
  457. PMYPHONE pNewPhone = (PMYPHONE) malloc (sizeof(MYPHONE));
  458. if (pNewPhone)
  459. {
  460. PMYWIDGET pWidget = (PMYWIDGET) pPhoneApp->Widget.pNext;
  461. memset (pNewPhone, 0, sizeof(MYPHONE));
  462. pNewPhone->Widget.dwType = WT_PHONE;
  463. pNewPhone->pPhoneApp = pPhoneApp;
  464. //
  465. // Insert new phone after all phones on the specified phone app,
  466. // and before the next phone app
  467. //
  468. while (pWidget && (pWidget->dwType == WT_PHONE))
  469. {
  470. pWidget = pWidget->pNext;
  471. }
  472. InsertWidgetInList ((PMYWIDGET) pNewPhone, pWidget);
  473. }
  474. return pNewPhone;
  475. }
  476. PMYPHONE
  477. GetPhone(
  478. HPHONE hPhone
  479. )
  480. {
  481. PMYWIDGET pWidget = aWidgets;
  482. while (pWidget)
  483. {
  484. if (pWidget->dwType == WT_PHONE)
  485. {
  486. PMYPHONE pPhone = (PMYPHONE) pWidget;
  487. if (pPhone->hPhone == hPhone)
  488. {
  489. break;
  490. }
  491. }
  492. pWidget = pWidget->pNext;
  493. }
  494. return ((PMYPHONE) pWidget);
  495. }
  496. VOID
  497. FreePhone(
  498. PMYPHONE pPhone
  499. )
  500. {
  501. RemoveWidgetFromList ((PMYWIDGET) pPhone);
  502. }
  503. int
  504. GetWidgetIndex(
  505. PMYWIDGET pWidget
  506. )
  507. {
  508. int i;
  509. PMYWIDGET pWidget2 = aWidgets;
  510. for (i = 0; (pWidget2 && (pWidget != pWidget2)); i++)
  511. {
  512. pWidget2 = pWidget2->pNext;
  513. }
  514. if (!pWidget2)
  515. {
  516. i = -1;
  517. }
  518. return i;
  519. }
  520. void
  521. SelectWidget(
  522. PMYWIDGET pWidget
  523. )
  524. {
  525. int i;
  526. PMYWIDGET pWidget2 = aWidgets;
  527. for (i = 0; pWidget2; i++)
  528. {
  529. if (pWidget == pWidget2)
  530. {
  531. SendMessage (ghwndList1, LB_SETCURSEL, (WPARAM) i, 0);
  532. break;
  533. }
  534. pWidget2 = pWidget2->pNext;
  535. }
  536. }