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.

1065 lines
38 KiB

  1. //--------------------------------------------------------------------------
  2. //
  3. // controls.cpp
  4. //
  5. //--------------------------------------------------------------------------
  6. #include <w95wraps.h>
  7. #include <windows.h>
  8. #include <commctrl.h>
  9. #include <shlwapi.h>
  10. #include <stdlib.h>
  11. #include "parse.h"
  12. #include "controls.h"
  13. #include "resource.h"
  14. extern HINSTANCE g_hInst;
  15. #define CHECKBOX_HEIGHT 25
  16. #define EDITTEXT_HEIGHT 23
  17. #define DROPDOWNLIST_HEIGHT 23
  18. #define NUMERIC_HEIGHT 23
  19. #define TEXT_HEIGHT 23
  20. #define COMBOBOX_HEIGHT 23
  21. #define EDITTEXT_WIDTH 300
  22. #define DROPDOWNLIST_WIDTH 300
  23. #define DROPDOWNLIST_WIDTH_LF 400
  24. #define NUMERIC_WIDTH 75
  25. #define COMBOBOX_WIDTH 300
  26. #define BUTTON_HEIGHT 25
  27. #define BUTTON_WIDTH 75
  28. #define CHECKBOX_ONLY_WIDTH 21
  29. extern HINSTANCE g_hInst;
  30. extern BOOL g_fAdmDirty;
  31. void InitFont(HWND hWnd);
  32. INT_PTR CALLBACK ValueDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  33. LRESULT APIENTRY ControlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  34. {
  35. RECT rectWnd;
  36. RECT rectControl;
  37. WNDPROC lpOrgControlProc;
  38. HWND hCategoryWnd;
  39. SCROLLINFO si;
  40. LPCONTROLINFO lpControlInfo = NULL;
  41. LPMSG lpmsg;
  42. LRESULT lRet;
  43. lpControlInfo = (LPCONTROLINFO) GetWindowLongPtr(hWnd, GWLP_USERDATA);
  44. if (lpControlInfo != NULL)
  45. lpOrgControlProc = (WNDPROC) lpControlInfo->lpOrgControlProc;
  46. else
  47. return FALSE;
  48. switch(message)
  49. {
  50. case WM_GETDLGCODE: // to handle the return/enter key for push button control
  51. if(((LPPART)lpControlInfo->lpPart)->nType == PART_LISTBOX)
  52. {
  53. lRet = CallWindowProc(lpOrgControlProc, hWnd, message, wParam, lParam);
  54. if (lParam)
  55. {
  56. lpmsg = (LPMSG) lParam;
  57. if (lpmsg->message == WM_KEYDOWN)
  58. {
  59. if (lpmsg->wParam == VK_RETURN)
  60. lRet |= DLGC_WANTMESSAGE;
  61. }
  62. }
  63. return (lRet);
  64. }
  65. break;
  66. case WM_SETFOCUS:
  67. hCategoryWnd = GetParent(GetParent(hWnd));
  68. GetWindowRect(hCategoryWnd, &rectWnd);
  69. GetWindowRect(hWnd, &rectControl);
  70. if(rectControl.bottom + 5 > rectWnd.bottom)
  71. {
  72. if((rectControl.top > rectWnd.bottom) && GetParent((HWND) wParam) != GetParent(hWnd))
  73. {
  74. ZeroMemory(&si, sizeof(SCROLLINFO));
  75. si.cbSize = sizeof(SCROLLINFO);
  76. si.fMask = SIF_RANGE;
  77. GetScrollInfo(hCategoryWnd, SB_VERT, &si);
  78. SendMessage(hCategoryWnd, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, si.nMax), 0L);
  79. }
  80. else
  81. {
  82. int nScrollDown = (rectControl.bottom + 5) - rectWnd.bottom;
  83. do {
  84. SendMessage(hCategoryWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0L);
  85. }while((nScrollDown -= SCROLL_LINE) > 0);
  86. }
  87. }
  88. else if(rectControl.top - 5 < rectWnd.top)
  89. {
  90. if(GetParent((HWND) wParam) != GetParent(hWnd))
  91. SendMessage(hCategoryWnd, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, 0), 0L);
  92. else
  93. {
  94. int nScrollUp = rectWnd.top - (rectControl.top - 5);
  95. do{
  96. SendMessage(hCategoryWnd, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0L);
  97. }while((nScrollUp -= SCROLL_LINE) > 0);
  98. }
  99. }
  100. break;
  101. case WM_KEYDOWN:
  102. if (wParam == VK_RETURN) // handle the return/enter key for push button control
  103. {
  104. if(((LPPART)lpControlInfo->lpPart)->nType == PART_LISTBOX)
  105. DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_VALUEDLG), hWnd, ValueDialogProc, (LPARAM)hWnd);
  106. }
  107. break;
  108. case WM_KILLFOCUS:
  109. if(((LPPART)lpControlInfo->lpPart)->nType == PART_NUMERIC)
  110. {
  111. TCHAR szValue[MAX_PATH];
  112. int nValue;
  113. GetWindowText(hWnd, szValue, ARRAYSIZE(szValue));
  114. nValue = StrToInt(szValue);
  115. if (nValue < ((LPPART)lpControlInfo->lpPart)->nMin)
  116. nValue = ((LPPART)lpControlInfo->lpPart)->nMin;
  117. else if (((LPPART)lpControlInfo->lpPart)->nMax > 0 && nValue > ((LPPART)lpControlInfo->lpPart)->nMax)
  118. nValue = ((LPPART)lpControlInfo->lpPart)->nMax;
  119. wnsprintf(szValue, ARRAYSIZE(szValue), TEXT("%d"), nValue);
  120. SetWindowText(hWnd, szValue);
  121. }
  122. break;
  123. default:
  124. break;
  125. }
  126. return CallWindowProc(lpOrgControlProc, hWnd, message, wParam, lParam);
  127. }
  128. INT_PTR CALLBACK ValueDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  129. {
  130. HWND hList = GetDlgItem(hDlg, IDC_VALUELIST);
  131. TCHAR szValueName[10];
  132. TCHAR szValue[MAX_PATH];
  133. int nItem = 0;
  134. LPCONTROLINFO lpControlInfo;
  135. LPPART pPart;
  136. LPPARTDATA pPartData;
  137. TCHAR szMsg[100];
  138. TCHAR szTitle[20];
  139. switch(message)
  140. {
  141. case WM_INITDIALOG:
  142. InitFont(GetDlgItem(hDlg, IDC_VALUE_ED));
  143. InitFont(GetDlgItem(hDlg, IDC_VALUELIST));
  144. SendMessage(GetDlgItem(hDlg, IDC_VALUE_ED), EM_SETLIMITTEXT, MAX_PATH, 0L);
  145. EnableWindow(GetDlgItem(hDlg, IDC_DELETE), FALSE);
  146. LoadString(g_hInst, IDS_TITLE, szTitle, ARRAYSIZE(szTitle));
  147. SetWindowText(hDlg, szTitle);
  148. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)lParam); // save the show button control pointer
  149. lpControlInfo = (LPCONTROLINFO) GetWindowLongPtr((HWND)lParam, GWLP_USERDATA);
  150. pPartData = lpControlInfo->lpPartData;
  151. if(pPartData != NULL && pPartData->nActions != 0)
  152. {
  153. LoadString(g_hInst, IDS_LISTINSERTFAIL, szMsg, ARRAYSIZE(szMsg));
  154. for(int nIndex = 0; nIndex < pPartData->actionlist[0].nValues; nIndex++)
  155. {
  156. if(SendMessage(hList, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) pPartData->actionlist[0].value[nIndex].szValue) == LB_ERR)
  157. {
  158. MessageBox(hDlg, szMsg, szTitle, MB_OK);
  159. break;
  160. }
  161. }
  162. }
  163. SetWindowLongPtr(hList, GWLP_USERDATA, 0);
  164. SendMessage(hDlg, DM_SETDEFID, IDC_ADD, 0L);
  165. break;
  166. case WM_COMMAND:
  167. switch(HIWORD(wParam))
  168. {
  169. case BN_CLICKED:
  170. switch(LOWORD(wParam))
  171. {
  172. case IDC_ADD:
  173. LoadString(g_hInst, IDS_TITLE, szTitle, ARRAYSIZE(szTitle));
  174. memset(szValue, 0, sizeof(szValue));
  175. GetDlgItemText(hDlg, IDC_VALUE_ED, szValue, ARRAYSIZE(szValue));
  176. if(*szValue == 0)
  177. {
  178. LoadString(g_hInst, IDS_VALUETEXTNULL, szMsg, ARRAYSIZE(szMsg));
  179. MessageBox(hDlg, szMsg, szTitle, MB_OK);
  180. }
  181. else
  182. {
  183. if(SendMessage(hList, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) szValue) == LB_ERR)
  184. {
  185. LoadString(g_hInst, IDS_LISTINSERTFAIL, szMsg, ARRAYSIZE(szMsg));
  186. MessageBox(hDlg, szMsg, szTitle, MB_OK);
  187. break;
  188. }
  189. SetWindowLongPtr(hList, GWLP_USERDATA, 1);
  190. SetDlgItemText(hDlg, IDC_VALUE_ED, TEXT('\0'));
  191. }
  192. break;
  193. case IDC_DELETE:
  194. if((nItem = (int) SendMessage(hList, LB_GETCURSEL, 0, 0L)) == LB_ERR)
  195. break;
  196. SendMessage(hList, LB_DELETESTRING, (WPARAM) nItem, 0L);
  197. SetWindowLongPtr(hList, GWLP_USERDATA, 1);
  198. break;
  199. case IDOK:
  200. if (GetWindowLongPtr(hList, GWLP_USERDATA))
  201. {
  202. lpControlInfo = (LPCONTROLINFO) GetWindowLongPtr((HWND)GetWindowLongPtr(hDlg, GWLP_USERDATA), GWLP_USERDATA);
  203. pPart = lpControlInfo->lpPart;
  204. pPartData = lpControlInfo->lpPartData;
  205. // Free original memory
  206. if(pPartData != NULL && pPartData->nActions != 0)
  207. {
  208. for(int nValueIndex = 0; nValueIndex < pPartData->actionlist[0].nValues; nValueIndex++)
  209. {
  210. if(pPartData->actionlist[0].value[nValueIndex].szKeyname)
  211. LocalFree(pPartData->actionlist[0].value[nValueIndex].szKeyname);
  212. if(pPartData->actionlist[0].value[nValueIndex].szValueName)
  213. LocalFree(pPartData->actionlist[0].value[nValueIndex].szValueName);
  214. if(pPartData->actionlist[0].value[nValueIndex].szValue)
  215. LocalFree(pPartData->actionlist[0].value[nValueIndex].szValue);
  216. }
  217. HeapFree(GetProcessHeap(), 0, pPartData->actionlist[0].value);
  218. }
  219. // Reallocate memory
  220. if(pPartData->nActions == 0)
  221. pPartData->actionlist = (LPACTIONLIST) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACTIONLIST) * 1);
  222. if(pPartData->actionlist != NULL)
  223. {
  224. int nItems = (int) SendMessage(hList, LB_GETCOUNT, 0, 0L);
  225. pPartData->nActions = 1;
  226. pPartData->actionlist[0].value = (LPVALUE) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VALUE) * nItems);
  227. if(pPartData->actionlist[0].value != NULL)
  228. {
  229. pPartData->actionlist[0].nValues = nItems;
  230. for(int nIndex = 0; nIndex < nItems; nIndex++)
  231. {
  232. memset(szValue, 0, sizeof(szValue));
  233. memset(szValueName, 0, sizeof(szValueName));
  234. if(SendMessage(hList, LB_GETTEXT, (WPARAM) nIndex, (LPARAM) (LPCTSTR) szValue) != LB_ERR)
  235. {
  236. pPartData->actionlist[0].value[nIndex].szKeyname = StrDup(pPart->value.szKeyname);
  237. wnsprintf(szValueName, ARRAYSIZE(szValueName), TEXT("%d"), (nIndex + 1));
  238. if(ISNONNULL(szValueName))
  239. pPartData->actionlist[0].value[nIndex].szValueName = StrDup(szValueName);
  240. if(ISNONNULL(szValue))
  241. pPartData->actionlist[0].value[nIndex].szValue = StrDup(szValue);
  242. }
  243. }
  244. if(nItems != 0)
  245. {
  246. pPartData->value.fNumeric = TRUE;
  247. pPartData->value.dwValue = 1;
  248. }
  249. }
  250. }
  251. g_fAdmDirty = TRUE;
  252. pPartData->fSave = TRUE;
  253. }
  254. EndDialog(hDlg, 1);
  255. break;
  256. case IDCANCEL:
  257. EndDialog(hDlg, 1);
  258. break;
  259. default:
  260. break;
  261. }
  262. break;
  263. case LBN_SELCHANGE:
  264. if(SendMessage(hList, LB_GETCURSEL, 0, 0L) == LB_ERR)
  265. EnableWindow(GetDlgItem(hDlg, IDC_DELETE), FALSE);
  266. else
  267. EnableWindow(GetDlgItem(hDlg, IDC_DELETE), TRUE);
  268. }
  269. break;
  270. case WM_DESTROY:
  271. SendMessage(hList, LB_RESETCONTENT, 0, 0L);
  272. break;
  273. default:
  274. return 0;
  275. }
  276. return 1;
  277. }
  278. LRESULT APIENTRY FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  279. {
  280. WNDPROC lpOrgFrameProc;
  281. HWND hwndCtl = NULL;
  282. LPCONTROLINFO lpControlInfo;
  283. LPNMUPDOWN lpNumUpDown;
  284. switch(message)
  285. {
  286. case WM_COMMAND:
  287. if(HIWORD(wParam) == BN_CLICKED)
  288. {
  289. hwndCtl = (HWND) lParam;
  290. lpControlInfo = (LPCONTROLINFO) GetWindowLongPtr(hwndCtl, GWLP_USERDATA);
  291. if(lpControlInfo != NULL && ((LPPART)lpControlInfo->lpPart)->nType == PART_LISTBOX)
  292. DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_VALUEDLG), hwndCtl, ValueDialogProc, (LPARAM)hwndCtl);
  293. }
  294. break;
  295. case WM_NOTIFY:
  296. lpNumUpDown = (LPNMUPDOWN) lParam;
  297. if (lpNumUpDown->hdr.code == UDN_DELTAPOS)
  298. {
  299. hwndCtl = (HWND) SendMessage(lpNumUpDown->hdr.hwndFrom, UDM_GETBUDDY, 0, 0L);
  300. if (hwndCtl != NULL)
  301. {
  302. lpControlInfo = (LPCONTROLINFO) GetWindowLongPtr(hwndCtl, GWLP_USERDATA);
  303. if (lpControlInfo != NULL && ((LPPART)lpControlInfo->lpPart)->nType == PART_NUMERIC)
  304. {
  305. int nSpin = ((LPPART)lpControlInfo->lpPart)->nSpin;
  306. if (nSpin != 0)
  307. lpNumUpDown->iDelta *= nSpin; // iDelta is by default 1 for increments & -1 for decrements.
  308. }
  309. }
  310. }
  311. break;
  312. default:
  313. break;
  314. }
  315. lpOrgFrameProc = (WNDPROC) GetWindowLongPtr(hWnd, GWLP_USERDATA);
  316. return CallWindowProc(lpOrgFrameProc, hWnd, message, wParam, lParam);
  317. }
  318. //--------------------------------------------------------------------------
  319. // CAdmControl member functions
  320. //--------------------------------------------------------------------------
  321. CAdmControl::CAdmControl( )
  322. {
  323. hControl = NULL;
  324. hUpDown = NULL;
  325. nControlX = nControlY = nControlWidth = nControlHeight = 0;
  326. fCreated = FALSE;
  327. nPart = -1;
  328. }
  329. CAdmControl::~CAdmControl( )
  330. {
  331. label.Destroy( );
  332. }
  333. //--------------------------------------------------------------------------
  334. // CAdmControl C R E A T E
  335. //
  336. //--------------------------------------------------------------------------
  337. int CAdmControl::Create( HWND hwndParent, int x, int y, int nWidth, int nHeight, int nMaxTextWidth,
  338. LPPART part, LPPARTDATA pPartData, BOOL fRSoPMode)
  339. {
  340. int i;
  341. TCHAR szValue[10];
  342. WNDPROC lpOrgControlProc;
  343. int nTextWidth = nWidth;
  344. BOOL bContinue = TRUE;
  345. DWORD dwType = CSW_LABEL;
  346. CONTROLINFO* lpControlInfo = NULL;
  347. TCHAR szMsg[MAX_PATH];
  348. HDC hDC;
  349. SIZE size;
  350. if(part->nType == PART_ERROR)
  351. return y;
  352. if (part->nType == PART_POLICY && !part->fRequired && StrCmp(part->szCategory, part->szName) == 0)
  353. return y;
  354. if( part->nType != PART_CHECKBOX )
  355. {
  356. if(part->nType == PART_POLICY)
  357. {
  358. if(!part->fRequired)
  359. {
  360. dwType = CSW_BOLDLABEL;
  361. y += 2;
  362. }
  363. else
  364. bContinue = FALSE;
  365. }
  366. if(bContinue)
  367. {
  368. if(!nTextWidth)
  369. nTextWidth = nMaxTextWidth;
  370. label.Create( hwndParent, x, y, nTextWidth, TEXT_HEIGHT, dwType );
  371. y += label.SetText( part->szName );
  372. if (part->nType != PART_POLICY)
  373. y += 2;
  374. }
  375. }
  376. DWORD dwDynamicStyles = 0L;
  377. if (fRSoPMode)
  378. dwDynamicStyles = WS_DISABLED;
  379. switch( part->nType )
  380. {
  381. case PART_EDITTEXT:
  382. if(!nHeight)
  383. nHeight = EDITTEXT_HEIGHT;
  384. if(!nWidth)
  385. nWidth = (nMaxTextWidth >= EDITTEXT_WIDTH) ? EDITTEXT_WIDTH : nMaxTextWidth;
  386. hControl = CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("EDIT"), pPartData->value.szValue,
  387. WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL | dwDynamicStyles,
  388. x, y, nWidth, nHeight, hwndParent, NULL, g_hInst, NULL );
  389. if (hControl && part->nMax)
  390. SendMessage(hControl, EM_SETLIMITTEXT, part->nMax, 0L);
  391. y += 6;
  392. break;
  393. case PART_DROPDOWNLIST:
  394. if (!nHeight)
  395. nHeight = DROPDOWNLIST_HEIGHT;
  396. if(!nWidth)
  397. {
  398. //we need to set the width to something proportionate to the font size
  399. int nTempWidth;
  400. HDC hDC;
  401. hDC = GetDC(hwndParent);
  402. int ipx = GetDeviceCaps(hDC,LOGPIXELSX);
  403. if (ipx <= 96)
  404. nTempWidth = DROPDOWNLIST_WIDTH; //small fonts or smaller
  405. else
  406. nTempWidth = DROPDOWNLIST_WIDTH_LF; //large fonts--increase size
  407. nWidth = (nMaxTextWidth >= nTempWidth) ? (nTempWidth) : (nMaxTextWidth);
  408. }
  409. hControl = CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("COMBOBOX"), pPartData->value.szValue,
  410. WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_AUTOHSCROLL |
  411. WS_VSCROLL | dwDynamicStyles,
  412. x, y, nWidth, nHeight * 4, hwndParent, NULL, g_hInst, NULL );
  413. for( i = 0; i < part->nActions; i++ )
  414. {
  415. int nIndex = (int) SendMessage( hControl, CB_ADDSTRING, 0, (LPARAM) part->actionlist[i].szName );
  416. if( StrCmp( pPartData->value.szValue, part->actionlist[i].szName ) == 0 )
  417. {
  418. SendMessage( hControl, CB_SETCURSEL, (WPARAM) nIndex, 0 );
  419. }
  420. }
  421. y += 6;
  422. break;
  423. case PART_NUMERIC:
  424. if(!nHeight)
  425. nHeight = NUMERIC_HEIGHT;
  426. if(!nWidth)
  427. nWidth = (nMaxTextWidth >= NUMERIC_WIDTH) ? NUMERIC_WIDTH : nMaxTextWidth;
  428. hControl = CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""),
  429. WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL | ES_NUMBER | dwDynamicStyles,
  430. x, y, nWidth, nHeight, hwndParent, NULL, g_hInst, NULL );
  431. hUpDown = CreateUpDownControl( WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_ARROWKEYS | UDS_NOTHOUSANDS,
  432. x + nWidth, y, 20, nHeight, hwndParent, 5, // BUG BUG - need real id
  433. g_hInst, hControl, part->nMax, part->nMin, part->nDefault );
  434. wnsprintf(szValue, ARRAYSIZE(szValue), TEXT("%d"), pPartData->value.dwValue );
  435. SendMessage( hControl, WM_SETTEXT, 0, (LPARAM) szValue);
  436. y += 6;
  437. break;
  438. case PART_POLICY:
  439. if(!part->fRequired)
  440. {
  441. nHeight = 0;
  442. y += 6;
  443. break;
  444. }
  445. // if policy is a part continue with the next case statement
  446. case PART_CHECKBOX:
  447. if(!nHeight)
  448. nHeight = CHECKBOX_HEIGHT;
  449. if(!nWidth)
  450. nWidth = nMaxTextWidth;
  451. // get the height required for the checkbox
  452. {
  453. CStaticWindow label;
  454. label.Create( hwndParent, x, y, nWidth - CHECKBOX_ONLY_WIDTH, nHeight, CSW_LABEL );
  455. nHeight = label.SetText( part->szName );
  456. }
  457. hControl = CreateWindowEx( 0, TEXT("BUTTON"), part->szName,
  458. WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_AUTOCHECKBOX | BS_MULTILINE | dwDynamicStyles,
  459. x, y, nWidth, nHeight, hwndParent, NULL, g_hInst, NULL );
  460. if( pPartData->value.dwValue )
  461. SendMessage( hControl, BM_SETCHECK, TRUE, 0 );
  462. else
  463. SendMessage( hControl, BM_SETCHECK, FALSE, 0 );
  464. y += 6;
  465. break;
  466. case PART_LISTBOX:
  467. if(!nHeight)
  468. nHeight = BUTTON_HEIGHT;
  469. if(!nWidth)
  470. nWidth = (nMaxTextWidth >= BUTTON_WIDTH) ? BUTTON_WIDTH : nMaxTextWidth;
  471. LoadString(g_hInst, IDS_SHOWBUTTON, szMsg, ARRAYSIZE(szMsg));
  472. hControl = CreateWindowEx( 0, TEXT("BUTTON"), szMsg,
  473. WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_PUSHBUTTON | BS_NOTIFY | dwDynamicStyles,
  474. x, y, nWidth, nHeight, hwndParent, NULL, g_hInst, NULL );
  475. if(hControl)
  476. {
  477. hDC = GetDC(hControl);
  478. if(hDC)
  479. {
  480. GetTextExtentPoint32(hDC, szMsg, lstrlen(szMsg), &size);
  481. MoveWindow(hControl, x, y, size.cx + 20, (size.cy > nHeight) ? size.cy + 7 : nHeight, TRUE);
  482. }
  483. y += 6;
  484. }
  485. break;
  486. case PART_TEXT:
  487. nHeight = 0;
  488. y += 6;
  489. break;
  490. case PART_COMBOBOX:
  491. if(!nHeight)
  492. nHeight = COMBOBOX_HEIGHT;
  493. if(!nWidth)
  494. nWidth = (nMaxTextWidth >= COMBOBOX_WIDTH) ? COMBOBOX_WIDTH : nMaxTextWidth;
  495. hControl = CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("COMBOBOX"), pPartData->value.szValue,
  496. WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | CBS_DROPDOWN | CBS_AUTOHSCROLL | dwDynamicStyles,
  497. x, y, nWidth, nHeight * 4, hwndParent, NULL, g_hInst, NULL );
  498. for( i = 0; i < part->nSuggestions; i++ )
  499. {
  500. SendMessage( hControl, CB_ADDSTRING, 0, (LPARAM) part->suggestions[i].szText );
  501. }
  502. SendMessage( hControl, WM_SETTEXT, 0, (LPARAM) pPartData->value.szValue );
  503. y += 6;
  504. break;
  505. }
  506. if(hControl != NULL)
  507. {
  508. InitFont(hControl);
  509. lpOrgControlProc = (WNDPROC) GetWindowLongPtr(hControl, GWLP_WNDPROC);
  510. SetWindowLongPtr(hControl, GWLP_WNDPROC, (LONG_PTR) &ControlWndProc);
  511. lpControlInfo = (LPCONTROLINFO) LocalAlloc((LPTR), sizeof(CONTROLINFO));
  512. lpControlInfo->lpOrgControlProc = lpOrgControlProc;
  513. lpControlInfo->lpPart = part;
  514. lpControlInfo->lpPartData = pPartData;
  515. SetWindowLongPtr(hControl, GWLP_USERDATA, (LONG_PTR) lpControlInfo);
  516. fCreated = TRUE;
  517. }
  518. return y + nHeight;
  519. }
  520. //--------------------------------------------------------------------------
  521. // CAdmControl D E S T R O Y
  522. //--------------------------------------------------------------------------
  523. void CAdmControl::Destroy( )
  524. {
  525. if( hControl != NULL )
  526. {
  527. LPCONTROLINFO lpControlInfo = (LPCONTROLINFO) GetWindowLongPtr(hControl, GWLP_USERDATA);
  528. if (lpControlInfo != NULL)
  529. {
  530. SetWindowLongPtr(hControl, GWLP_WNDPROC, (LONG_PTR) lpControlInfo->lpOrgControlProc);
  531. LocalFree(lpControlInfo);
  532. SetWindowLongPtr(hControl, GWLP_USERDATA, 0L);
  533. }
  534. DestroyWindow( hControl );
  535. hControl = NULL;
  536. }
  537. if( hUpDown != NULL)
  538. {
  539. DestroyWindow( hUpDown );
  540. hUpDown = NULL;
  541. }
  542. }
  543. //--------------------------------------------------------------------------
  544. // CAdmControl S A V E
  545. //--------------------------------------------------------------------------
  546. void CAdmControl::Save( LPPART part, LPPARTDATA pPartData )
  547. {
  548. int nCheck;
  549. TCHAR szText[1024];
  550. DWORD dwTemp;
  551. ZeroMemory(szText, sizeof(szText));
  552. switch( part->nType )
  553. {
  554. case PART_EDITTEXT:
  555. case PART_COMBOBOX:
  556. GetWindowText( hControl, szText, ARRAYSIZE(szText));
  557. if (!pPartData->fSave ||
  558. (pPartData->value.szValue == NULL && *szText != TEXT('\0')) ||
  559. (pPartData->value.szValue != NULL && StrCmp(pPartData->value.szValue, szText) != 0))
  560. {
  561. g_fAdmDirty = TRUE;
  562. pPartData->fSave = TRUE;
  563. }
  564. if(pPartData->value.szValue != NULL)
  565. LocalFree(pPartData->value.szValue);
  566. pPartData->value.szValue = NULL;
  567. if(ISNONNULL(szText))
  568. pPartData->value.szValue = StrDup(szText);
  569. break;
  570. case PART_DROPDOWNLIST:
  571. GetWindowText( hControl, szText, ARRAYSIZE(szText));
  572. if (!pPartData->fSave ||
  573. (pPartData->value.szValue == NULL && *szText != 0) ||
  574. (pPartData->value.szValue != NULL && StrCmp(pPartData->value.szValue, szText) != 0))
  575. {
  576. g_fAdmDirty = TRUE;
  577. pPartData->fSave = TRUE;
  578. }
  579. if(pPartData->value.szValue != NULL)
  580. LocalFree(pPartData->value.szValue);
  581. pPartData->value.szValue = NULL;
  582. if(ISNONNULL(szText))
  583. pPartData->value.szValue = StrDup(szText);
  584. pPartData->nSelectedAction = (int) SendMessage( hControl, CB_GETCURSEL, 0, 0 );
  585. if( pPartData->nSelectedAction == CB_ERR )
  586. pPartData->nSelectedAction = NO_ACTION;
  587. break;
  588. case PART_NUMERIC:
  589. GetWindowText( hControl, szText, ARRAYSIZE(szText));
  590. {
  591. int nValue;
  592. nValue = StrToInt(szText);
  593. if (nValue < part->nMin)
  594. nValue = part->nMin;
  595. else if (part->nMax > 0 && nValue > part->nMax)
  596. nValue = part->nMax;
  597. wnsprintf(szText, ARRAYSIZE(szText), TEXT("%d"), nValue);
  598. }
  599. if(pPartData->value.szValue != NULL)
  600. LocalFree(pPartData->value.szValue);
  601. pPartData->value.szValue = NULL;
  602. dwTemp = pPartData->value.dwValue;
  603. pPartData->value.dwValue = 0;
  604. if(ISNONNULL(szText))
  605. {
  606. pPartData->value.szValue = StrDup(szText);
  607. if (pPartData->value.szValue)
  608. pPartData->value.dwValue = StrToInt( pPartData->value.szValue );
  609. }
  610. pPartData->value.fNumeric = TRUE;
  611. if (!pPartData->fSave || dwTemp != pPartData->value.dwValue)
  612. {
  613. g_fAdmDirty = TRUE;
  614. pPartData->fSave = TRUE;
  615. }
  616. break;
  617. case PART_POLICY:
  618. if(!part->fRequired)
  619. break;
  620. case PART_CHECKBOX:
  621. nCheck = (int) SendMessage( hControl, BM_GETCHECK, 0, 0 );
  622. pPartData->value.fNumeric = TRUE;
  623. switch( nCheck )
  624. {
  625. case BST_CHECKED:
  626. if (!pPartData->fSave || pPartData->value.dwValue != 1)
  627. {
  628. g_fAdmDirty = TRUE;
  629. pPartData->fSave = TRUE;
  630. }
  631. pPartData->value.dwValue = 1;
  632. break;
  633. case BST_UNCHECKED:
  634. if (!pPartData->fSave || pPartData->value.dwValue != 0)
  635. {
  636. g_fAdmDirty = TRUE;
  637. pPartData->fSave = TRUE;
  638. }
  639. pPartData->value.dwValue = 0;
  640. break;
  641. }
  642. break;
  643. case PART_LISTBOX:
  644. pPartData->value.fNumeric = TRUE;
  645. break;
  646. }
  647. }
  648. //--------------------------------------------------------------------------
  649. // CAdmControl M O V E U P
  650. //--------------------------------------------------------------------------
  651. void CAdmControl::MoveUp( int nValue )
  652. {
  653. label.MoveUp( nValue );
  654. nControlY -= nValue;
  655. if( hUpDown != NULL )
  656. {
  657. RECT r;
  658. GetWindowRect( hUpDown, &r );
  659. ::MoveWindow( hControl, nControlX, nControlY, nControlWidth-(r.right-r.left), nControlHeight, TRUE );
  660. ::MoveWindow( hUpDown, nControlX+nControlWidth-(r.right-r.left), nControlY, (r.right-r.left), nControlHeight, TRUE );
  661. }
  662. else
  663. ::MoveWindow( hControl, nControlX, nControlY, nControlWidth, nControlHeight, TRUE );
  664. }
  665. //--------------------------------------------------------------------------
  666. // CAdmControl M O V E L E F T
  667. //--------------------------------------------------------------------------
  668. void CAdmControl::MoveLeft( int nValue )
  669. {
  670. label.MoveLeft( nValue );
  671. nControlX -= nValue;
  672. if( hUpDown != NULL )
  673. {
  674. RECT r;
  675. GetWindowRect( hUpDown, &r );
  676. ::MoveWindow( hControl, nControlX, nControlY, nControlWidth-(r.right-r.left), nControlHeight, TRUE );
  677. ::MoveWindow( hUpDown, nControlX+nControlWidth-(r.right-r.left), nControlY, (r.right-r.left), nControlHeight, TRUE );
  678. }
  679. else
  680. ::MoveWindow( hControl, nControlX, nControlY, nControlWidth, nControlHeight, TRUE );
  681. }
  682. //--------------------------------------------------------------------------
  683. // CAdmControl R E S E T
  684. //--------------------------------------------------------------------------
  685. void CAdmControl::Reset(LPPART part, LPPARTDATA pPartData)
  686. {
  687. int nIndex = 0;
  688. TCHAR szValue[10];
  689. HWND hwndParent;
  690. RECT rectWnd;
  691. RECT rectControl;
  692. switch( part->nType )
  693. {
  694. case PART_EDITTEXT:
  695. if(pPartData->value.szValue)
  696. SendMessage( hControl, WM_SETTEXT, 0, (LPARAM) pPartData->value.szValue );
  697. else
  698. SendMessage( hControl, WM_SETTEXT, 0, (LPARAM) "" );
  699. break;
  700. case PART_DROPDOWNLIST:
  701. if(pPartData->value.szValue != NULL)
  702. {
  703. for( nIndex = 0; nIndex < part->nActions; nIndex++ )
  704. {
  705. if( part->actionlist[nIndex].szName != NULL && StrCmp( pPartData->value.szValue, part->actionlist[nIndex].szName ) == 0 )
  706. {
  707. SendMessage( hControl, CB_SETCURSEL, (WPARAM) nIndex, 0 );
  708. }
  709. }
  710. }
  711. else if(part->nActions != 0)
  712. SendMessage( hControl, CB_SETCURSEL, (WPARAM) -1, 0 );
  713. break;
  714. case PART_NUMERIC:
  715. if(hUpDown != NULL)
  716. {
  717. hwndParent = GetParent(hUpDown);
  718. GetWindowRect(hwndParent, &rectWnd);
  719. GetWindowRect(hUpDown, &rectControl);
  720. DestroyWindow(hUpDown);
  721. hUpDown = CreateUpDownControl( WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_ARROWKEYS,
  722. rectControl.left - rectWnd.left, rectControl.top - rectWnd.top, rectControl.right - rectControl.left,
  723. rectControl.bottom - rectControl.top, hwndParent, 5, // BUG BUG - need real id
  724. g_hInst, hControl, part->nMax, part->nMin, part->nDefault );
  725. }
  726. wnsprintf(szValue, ARRAYSIZE(szValue), TEXT("%d"), pPartData->value.dwValue );
  727. SendMessage( hControl, WM_SETTEXT, 0, (LPARAM) szValue);
  728. break;
  729. case PART_POLICY:
  730. if(!part->fRequired)
  731. break;
  732. case PART_CHECKBOX:
  733. if( pPartData->value.dwValue )
  734. SendMessage( hControl, BM_SETCHECK, TRUE, 0 );
  735. else
  736. SendMessage( hControl, BM_SETCHECK, FALSE, 0 );
  737. break;
  738. // case PART_LISTBOX:
  739. // break;
  740. case PART_COMBOBOX:
  741. if(pPartData->value.szValue != NULL)
  742. SendMessage( hControl, WM_SETTEXT, 0, (LPARAM) part->value.szValue );
  743. else
  744. SendMessage( hControl, WM_SETTEXT, 0, (LPARAM) "" );
  745. break;
  746. default:
  747. break;
  748. }
  749. }
  750. //--------------------------------------------------------------------------
  751. // CAdmControl G E T P A R T
  752. //--------------------------------------------------------------------------
  753. int CAdmControl::GetPart()
  754. {
  755. return nPart;
  756. }
  757. //--------------------------------------------------------------------------
  758. // CAdmControl S E T P A R T
  759. //--------------------------------------------------------------------------
  760. void CAdmControl::SetPart(int nPartNo)
  761. {
  762. nPart = nPartNo;
  763. }
  764. //--------------------------------------------------------------------------
  765. // CStaticWindow member functions
  766. CStaticWindow::CStaticWindow( )
  767. {
  768. fCreated = FALSE;
  769. nControlX = nControlY = nControlWidth = nControlHeight = 0;
  770. hWnd = NULL;
  771. dwType = 0;
  772. }
  773. CStaticWindow::~CStaticWindow( )
  774. {
  775. Destroy();
  776. }
  777. //--------------------------------------------------------------------------
  778. // CStaticWindow C R E A T E
  779. //--------------------------------------------------------------------------
  780. void CStaticWindow::Create( HWND hwndParent, int x, int y, int nWidth, int nHeight, DWORD dwFlags )
  781. {
  782. WNDPROC lpOrgFrameProc;
  783. nControlX = x;
  784. nControlY = y;
  785. nControlWidth = nWidth;
  786. nControlHeight = nHeight;
  787. if( HasFlag(dwFlags, CSW_BORDER) )
  788. {
  789. hWnd = CreateWindowEx( WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT, TEXT("STATIC"), TEXT(""),
  790. WS_VISIBLE | WS_CHILD | WS_BORDER, x, y, nWidth, nHeight, hwndParent,
  791. NULL, g_hInst, NULL );
  792. }
  793. if( HasFlag(dwFlags, CSW_LABEL) )
  794. {
  795. hWnd = CreateWindowEx( 0, TEXT("STATIC"), TEXT(""),
  796. WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX, x, y, nWidth, nHeight, hwndParent,
  797. NULL, g_hInst, NULL );
  798. }
  799. if( HasFlag(dwFlags, CSW_FRAME) )
  800. {
  801. hWnd = CreateWindowEx( WS_EX_CONTROLPARENT, TEXT("STATIC"), TEXT(""),
  802. WS_VISIBLE | WS_CHILD, x, y, nWidth, nHeight, hwndParent,
  803. NULL, g_hInst, NULL );
  804. lpOrgFrameProc = (WNDPROC) GetWindowLongPtr(hWnd, GWLP_WNDPROC);
  805. SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR) FrameWndProc);
  806. SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lpOrgFrameProc);
  807. }
  808. dwType = dwFlags;
  809. if(hWnd != NULL)
  810. {
  811. HFONT hFont = NULL;
  812. fCreated = TRUE;
  813. hFont = GetFont();
  814. if (hFont != NULL)
  815. SendMessage( hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
  816. }
  817. }
  818. //--------------------------------------------------------------------------
  819. // CStaticWindow M O V E W I N D O W
  820. //--------------------------------------------------------------------------
  821. void CStaticWindow::MoveWindow( int x, int y, int nWidth, int nHeight )
  822. {
  823. if( fCreated )
  824. ::MoveWindow( hWnd, x, y, nWidth, nHeight, TRUE );
  825. }
  826. //--------------------------------------------------------------------------
  827. // CStaticWindow D E S T R O Y
  828. //--------------------------------------------------------------------------
  829. void CStaticWindow::Destroy( )
  830. {
  831. if( fCreated )
  832. {
  833. DestroyWindow( hWnd );
  834. hWnd = NULL;
  835. fCreated = FALSE;
  836. }
  837. }
  838. //--------------------------------------------------------------------------
  839. // CStaticWindow S E T T E X T
  840. //--------------------------------------------------------------------------
  841. int CStaticWindow::SetText( LPTSTR szText )
  842. {
  843. int nHeight = 0;
  844. if( fCreated )
  845. {
  846. HDC hDC;
  847. RECT rect;
  848. int nWidth;
  849. HFONT hOldFont = NULL;
  850. HFONT hFont = NULL;
  851. GetClientRect(hWnd, &rect);
  852. nWidth = rect.right;
  853. hFont = GetFont();
  854. hDC = GetDC(hWnd);
  855. if (hFont != NULL)
  856. hOldFont = (HFONT) SelectObject(hDC, hFont);
  857. nHeight = DrawText(hDC, szText, -1, &rect, DT_LEFT | DT_WORDBREAK | DT_CALCRECT);
  858. if (hOldFont != NULL)
  859. {
  860. hFont = (HFONT)SelectObject(hDC, hOldFont);
  861. if (hFont)
  862. DeleteObject(hFont);
  863. }
  864. ReleaseDC(hWnd, hDC);
  865. SetWindowPos(hWnd, NULL, 0, 0, nWidth, nHeight, SWP_NOMOVE | SWP_NOZORDER);
  866. SetWindowText( hWnd, szText );
  867. }
  868. return nHeight;
  869. }
  870. //--------------------------------------------------------------------------
  871. // CStaticWindow M O V E U P
  872. //--------------------------------------------------------------------------
  873. void CStaticWindow::MoveUp( int nValue )
  874. {
  875. nControlY -= nValue;
  876. ::MoveWindow( hWnd, nControlX, nControlY, nControlWidth, nControlHeight, TRUE );
  877. }
  878. //--------------------------------------------------------------------------
  879. // CStaticWindow M O V E L E F T
  880. //--------------------------------------------------------------------------
  881. void CStaticWindow::MoveLeft( int nValue )
  882. {
  883. nControlX -= nValue;
  884. ::MoveWindow( hWnd, nControlX, nControlY, nControlWidth, nControlHeight, TRUE );
  885. }
  886. //--------------------------------------------------------------------------
  887. // CStaticWindow H W N D
  888. //--------------------------------------------------------------------------
  889. HWND CStaticWindow::Hwnd( )
  890. {
  891. return hWnd;
  892. }
  893. void InitFont(HWND hWnd)
  894. {
  895. HFONT hFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  896. SendMessage( hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
  897. }
  898. HFONT CStaticWindow::GetFont()
  899. {
  900. HFONT hFont = NULL;
  901. static TCHAR szFontName[LF_FACESIZE];
  902. static int nFontSize = 0;
  903. if (HasOnlyFlag(dwType, CSW_BOLDLABEL) || HasOnlyFlag(dwType, CSW_ITALICLABEL))
  904. {
  905. HDC hDC = GetDC(hWnd);
  906. LOGFONT lf;
  907. TEXTMETRIC tm;
  908. ZeroMemory(&lf, sizeof(lf));
  909. if (nFontSize == 0)
  910. {
  911. TCHAR szFontSize[5];
  912. if (!LoadString(g_hInst, IDS_ADMBOLDFONT, szFontName, LF_FACESIZE))
  913. StrCpy(szFontName, TEXT("MS Sans Serif"));
  914. LoadString(g_hInst, IDS_ADMBOLDFONTSIZE, szFontSize, ARRAYSIZE(szFontSize));
  915. nFontSize = StrToInt(szFontSize);
  916. if (nFontSize < 8)
  917. nFontSize = 8;
  918. }
  919. StrCpy(lf.lfFaceName, szFontName);
  920. lf.lfHeight = -((nFontSize * GetDeviceCaps(hDC, LOGPIXELSY)) / 72);
  921. GetTextMetrics(hDC, &tm);
  922. lf.lfCharSet = tm.tmCharSet;
  923. ReleaseDC(hWnd, hDC);
  924. lf.lfWeight = FW_REGULAR;
  925. if (HasOnlyFlag(dwType, CSW_BOLDLABEL))
  926. lf.lfWeight = FW_BOLD;
  927. if (HasOnlyFlag(dwType, CSW_ITALICLABEL))
  928. lf.lfItalic = 1;
  929. hFont = CreateFontIndirect(&lf);
  930. }
  931. else
  932. hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  933. return hFont;
  934. }