Source code of Windows XP (NT5)
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.

544 lines
12 KiB

  1. /*++
  2. * File name:
  3. * dialog.c
  4. * Contents:
  5. * Implements dialog boxes for add to/browse bitmap database
  6. --*/
  7. #include <windows.h>
  8. #include "..\lib\bmpdb.h"
  9. #include "resource.h"
  10. PBMPENTRY g_pBitmap;
  11. PGROUPENTRY g_pGrpList;
  12. PBMPENTRY g_pBmpList;
  13. char g_szAddTextId[256];
  14. char szBuffer[1024] = "null";
  15. /*++
  16. * Function:
  17. * _StripLine
  18. * Description:
  19. * Strips trailing and leading white space cahracters
  20. * in a string
  21. * Arguments:
  22. * line - the string
  23. * Called by:
  24. * _AddGlyphDlgProc
  25. --*/
  26. void _StripLine(char *line)
  27. {
  28. int last = strlen(line);
  29. char *first = line;
  30. if (last) last--;
  31. while(last && isspace(line[last]))
  32. {
  33. line[last] = 0;
  34. last--;
  35. }
  36. while(isspace(*first))
  37. first++;
  38. if (line != first)
  39. memmove(line, first, strlen(first) + 1 );
  40. }
  41. /*++
  42. * Function:
  43. * DrawGlyph
  44. * Description:
  45. * Draws the glyph (monochrome bitmap) g_pBitmap
  46. * in the client window area
  47. * Arguments:
  48. * hWnd - the handle to the window
  49. * Called by:
  50. * PaintGlyph
  51. --*/
  52. void
  53. DrawGlyph (HWND hWnd)
  54. {
  55. HDC hDC = NULL;
  56. HDC glyphDC = NULL;
  57. HBITMAP hOldBmp;
  58. RECT rect;
  59. INT xCenter, yCenter;
  60. INT xSize, ySize;
  61. if (!g_pBitmap)
  62. goto exitpt1;
  63. GetClientRect (hWnd, &rect);
  64. hDC = GetDC (hWnd);
  65. if ( !hDC )
  66. goto exitpt;
  67. glyphDC = CreateCompatibleDC(hDC);
  68. if (!glyphDC)
  69. goto exitpt;
  70. hOldBmp = SelectObject(glyphDC, g_pBitmap->hBitmap);
  71. xSize = (g_pBitmap->xSize > (UINT)rect.right )?rect.right :g_pBitmap->xSize;
  72. ySize = (g_pBitmap->ySize > (UINT)rect.bottom)?rect.bottom:g_pBitmap->ySize;
  73. xCenter = (rect.right - xSize) / 2;
  74. yCenter = (rect.bottom- ySize) / 2;
  75. BitBlt(hDC, // Dest DC
  76. xCenter, // Dest x
  77. yCenter, // Dest y
  78. xSize, // Width
  79. ySize, // Height
  80. glyphDC, // Source
  81. 0, // Src x
  82. 0, // Src y
  83. SRCCOPY); // Rop
  84. SelectObject(glyphDC, hOldBmp);
  85. DeleteDC( glyphDC );
  86. exitpt:
  87. if ( hDC )
  88. ReleaseDC (hWnd, hDC);
  89. exitpt1:
  90. ;
  91. }
  92. /*++
  93. * Function:
  94. * PaintGlyph
  95. * Description:
  96. * Repaints the glyph. Usualy called on WM_PAINT message
  97. * Arguments:
  98. * hWnd - the window
  99. * Called by:
  100. * _CommentListClicked, _AddGlyphDlgProc, _BrowseDlgProc
  101. --*/
  102. void
  103. PaintGlyph (HWND hWnd)
  104. {
  105. InvalidateRect (hWnd, NULL, TRUE);
  106. UpdateWindow (hWnd);
  107. DrawGlyph (hWnd);
  108. }
  109. /*++
  110. * Function:
  111. * _AddWideToLB
  112. * Description:
  113. * Adds wide string to list box
  114. * Arguments:
  115. * hwndLB - list box handle
  116. * wszString - string to add
  117. * Called by:
  118. * _DeleteItem, _BrowseDlgItem
  119. --*/
  120. VOID
  121. _AddWideToLB(HWND hwndLB, LPCWSTR wszString)
  122. {
  123. char lpszString[256];
  124. WideCharToMultiByte(
  125. CP_ACP,
  126. 0,
  127. wszString,
  128. -1,
  129. lpszString,
  130. sizeof(lpszString),
  131. NULL, NULL);
  132. SendMessage(hwndLB, LB_ADDSTRING, 0, (LPARAM)lpszString);
  133. }
  134. /*++
  135. * Function:
  136. * _DeleteItem
  137. * Description:
  138. * Deletes an entry from the list box and database
  139. * Arguments:
  140. * hDlg - dialog handle
  141. * hWndIDList - list box with IDs
  142. * hWndCommentList - list box with comment strings
  143. * Called by:
  144. * _BrowseDlgItem
  145. --*/
  146. VOID
  147. _DeleteItem(HWND hDlg, HWND hWndIDList, HWND hWndCommentList)
  148. {
  149. PGROUPENTRY pGroup;
  150. PBMPENTRY pBitmap;
  151. FOFFSET lBmpOffs;
  152. LRESULT iIDIndex, iCmntIndex, iIdx;
  153. iIDIndex = SendMessage (hWndIDList, LB_GETCURSEL, 0, 0);
  154. iIdx = iCmntIndex = SendMessage (hWndCommentList, LB_GETCURSEL, 0, 0);
  155. if (iIDIndex == LB_ERR || iCmntIndex == LB_ERR)
  156. goto exitpt;
  157. pGroup = g_pGrpList;
  158. while(pGroup && iIDIndex)
  159. {
  160. pGroup = pGroup->pNext;
  161. iIDIndex--;
  162. }
  163. pBitmap = g_pBmpList;
  164. while (pBitmap && iCmntIndex)
  165. {
  166. pBitmap = pBitmap->pNext;
  167. iCmntIndex --;
  168. }
  169. if (!pBitmap || !pGroup)
  170. goto exitpt;
  171. DeleteBitmapByPointer(pBitmap->FOffsMe);
  172. // Is this is the last bitmap in the group ?
  173. if (iIdx == 0 && pBitmap->pNext == NULL)
  174. DeleteGroupByPointer(pGroup->FOffsMe);
  175. // Refresh the boxes
  176. FreeGroupList(g_pGrpList);
  177. SendMessage(hWndIDList, LB_RESETCONTENT, 0, 0);
  178. g_pGrpList = GetGroupList();
  179. pGroup = g_pGrpList;
  180. while (pGroup)
  181. {
  182. _AddWideToLB(hWndIDList, pGroup->WText);
  183. pGroup = pGroup->pNext;
  184. }
  185. exitpt:
  186. ;
  187. }
  188. /*++
  189. * Function:
  190. * _IDListClicked
  191. * Description:
  192. * Processes selecting an item from the list box with IDs
  193. * Fills the comment list box
  194. * Arguments:
  195. * hDlg - handle to the dialog
  196. * hWndCommentList - list box with comments
  197. * hWndIDList - list box with IDs
  198. * Called by:
  199. * _BrowseDlgProc
  200. --*/
  201. VOID
  202. _IDListClicked(HWND hDlg, HWND hWndCommentList, HWND hWndIDList)
  203. {
  204. LRESULT iIDIndex;
  205. PBMPENTRY pBitmap;
  206. PGROUPENTRY pGroup;
  207. iIDIndex = SendMessage (hWndIDList, LB_GETCURSEL, 0, 0);
  208. // Clear the comment list box
  209. SendMessage(hWndCommentList, LB_RESETCONTENT, 0, 0);
  210. FreeBitmapList(g_pBmpList);
  211. if (iIDIndex != LB_ERR)
  212. {
  213. LRESULT iIdx = iIDIndex;
  214. // Find the choosen group
  215. pGroup = g_pGrpList;
  216. while(pGroup && iIdx)
  217. {
  218. iIdx--;
  219. pGroup = pGroup->pNext;
  220. }
  221. // Read the bitmap group
  222. if (pGroup)
  223. {
  224. HDC hDC = GetDC(hDlg);
  225. if ( hDC )
  226. {
  227. pBitmap = g_pBmpList = GetBitmapList(hDC, pGroup->FOffsBmp);
  228. ReleaseDC(hDlg, hDC);
  229. while(pBitmap)
  230. {
  231. SendMessage (hWndCommentList, LB_ADDSTRING, 0, (LPARAM)pBitmap->szComment);
  232. pBitmap = pBitmap->pNext;
  233. }
  234. }
  235. }
  236. EnableWindow (GetDlgItem (hDlg, IDC_DELETE), FALSE);
  237. }
  238. }
  239. /*++
  240. * Function:
  241. * _CommentListClicked
  242. * Description:
  243. * Processes selecting an item from comment list box
  244. * Shows the bitmap under this comment and ID
  245. * Arguments:
  246. * hDlg - dialog handle
  247. * hWndGlyph - glyph window
  248. * hWndCommentList - list box with comments
  249. * Called by:
  250. * _BrowseDlgProc
  251. --*/
  252. VOID
  253. _CommentListClicked(HWND hDlg, HWND hWndGlyph, HWND hWndCommentList)
  254. {
  255. LRESULT iCommIndex;
  256. PBMPENTRY pBitmap;
  257. iCommIndex = SendMessage (hWndCommentList, LB_GETCURSEL, 0, 0);
  258. g_pBitmap = NULL;
  259. if (iCommIndex != LB_ERR)
  260. {
  261. LRESULT iIdx = iCommIndex;
  262. pBitmap = g_pBmpList;
  263. while (pBitmap && iIdx)
  264. {
  265. pBitmap = pBitmap->pNext;
  266. iIdx --;
  267. }
  268. g_pBitmap = pBitmap;
  269. EnableWindow (GetDlgItem (hDlg, IDC_DELETE), TRUE);
  270. }
  271. PaintGlyph (hWndGlyph);
  272. }
  273. /*++
  274. * Function:
  275. * _AddGlyphDlgProc
  276. * Description:
  277. * Processes the messages for Add Glyph dialog box
  278. * Arguments:
  279. * hDlg - dialog handle
  280. * uiMsg - message ID
  281. * wParam - word parameter
  282. * lParam - long parameter
  283. * Return value:
  284. * TRUE if the message is processed
  285. --*/
  286. INT_PTR
  287. CALLBACK
  288. _AddGlyphDlgProc (HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  289. {
  290. static HWND hWndGlyph = NULL;
  291. switch (uiMsg)
  292. {
  293. case WM_INITDIALOG:
  294. hWndGlyph = GetDlgItem (hDlg, IDC_GLYPH);
  295. SendDlgItemMessage (hDlg, IDC_IDEDIT, EM_LIMITTEXT, (WPARAM)MAX_STRING_LENGTH, 0);
  296. SendDlgItemMessage (hDlg, IDC_COMMENT, EM_LIMITTEXT, (WPARAM)MAX_STRING_LENGTH, 0);
  297. return TRUE;
  298. case WM_PAINT:
  299. PaintGlyph (hWndGlyph);
  300. break;
  301. case WM_COMMAND:
  302. switch (LOWORD (wParam))
  303. {
  304. case IDOK:
  305. GetDlgItemText (
  306. hDlg,
  307. IDC_IDEDIT,
  308. g_szAddTextId,
  309. sizeof (g_szAddTextId) - 1
  310. );
  311. _StripLine(g_szAddTextId);
  312. GetDlgItemText (
  313. hDlg,
  314. IDC_COMMENT,
  315. g_pBitmap->szComment,
  316. sizeof (g_pBitmap->szComment) - 1
  317. );
  318. _StripLine(g_pBitmap->szComment);
  319. if (!g_szAddTextId[0])
  320. {
  321. MessageBox(hDlg, "Please enter ID !", "Warning", MB_OK);
  322. } else if (!g_pBitmap->szComment[0])
  323. {
  324. MessageBox(hDlg, "Please enter comment !", "Warning", MB_OK);
  325. } else {
  326. EndDialog (hDlg, TRUE);
  327. }
  328. return TRUE;
  329. case IDCANCEL:
  330. EndDialog (hDlg, FALSE);
  331. return TRUE;
  332. }
  333. }
  334. return FALSE;
  335. }
  336. /*++
  337. * Function:
  338. * AddBitmapDialog
  339. * Description:
  340. * Pops an "Add Glyph(bitmap)" dialog
  341. * Arguments:
  342. * hInst - our instance
  343. * hWnd - main window handle
  344. * pBitmap - selected bitmap
  345. * Called by:
  346. * glyphspy.c!_ClickOnGlyph
  347. --*/
  348. VOID
  349. AddBitmapDialog(HINSTANCE hInst, HWND hWnd, PBMPENTRY pBitmap)
  350. {
  351. g_pBitmap = pBitmap;
  352. if (!g_pBitmap)
  353. goto exitpt;
  354. if (DialogBox (
  355. hInst,
  356. MAKEINTRESOURCE (IDD_ADDGLYPH),
  357. hWnd,
  358. _AddGlyphDlgProc
  359. ))
  360. {
  361. // Add the entry to the DB
  362. if (!AddBitMapA(g_pBitmap, g_szAddTextId))
  363. {
  364. MessageBox(hWnd, "Can't add the glyph to the database !", "Warning", MB_OK);
  365. }
  366. }
  367. exitpt:
  368. ;
  369. }
  370. /*++
  371. * Function:
  372. * _BrowseDlgProc
  373. * Description:
  374. * Processes the messages for "Browse Glyphs(bitmaps)" dialog
  375. * Arguments:
  376. * hDlg - dialog handle
  377. * uiMsg - message ID
  378. * wParam - word parameter
  379. * lParam - long parameter
  380. * Return value:
  381. * TRUE if the message is processed
  382. --*/
  383. INT_PTR
  384. CALLBACK
  385. _BrowseDlgProc (HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  386. {
  387. static HWND hWndGlyph = NULL;
  388. static HWND hWndIDList = NULL;
  389. static HWND hWndCommentList = NULL;
  390. int i;
  391. int iIndex;
  392. PGROUPENTRY pGroup;
  393. BOOL rv = FALSE;
  394. switch (uiMsg)
  395. {
  396. case WM_INITDIALOG:
  397. hWndGlyph = GetDlgItem (hDlg, IDC_GLYPH);
  398. hWndIDList = GetDlgItem (hDlg, IDC_IDLIST);
  399. hWndCommentList = GetDlgItem(hDlg, IDC_COMMENTLIST);
  400. EnableWindow (GetDlgItem (hDlg, IDC_DELETE), FALSE);
  401. g_pGrpList = GetGroupList();
  402. pGroup = g_pGrpList;
  403. while (pGroup)
  404. {
  405. _AddWideToLB(hWndIDList, pGroup->WText);
  406. pGroup = pGroup->pNext;
  407. }
  408. rv = TRUE;
  409. break;
  410. case WM_PAINT:
  411. PaintGlyph (hWndGlyph);
  412. break;
  413. case WM_COMMAND:
  414. switch (LOWORD (wParam))
  415. {
  416. case IDOK:
  417. EndDialog (hDlg, TRUE);
  418. rv = TRUE;
  419. break;
  420. case IDC_DELETE:
  421. _DeleteItem(hDlg, hWndIDList, hWndCommentList);
  422. _IDListClicked(hDlg, hWndCommentList, hWndIDList);
  423. _CommentListClicked(hDlg, hWndGlyph, hWndCommentList);
  424. rv = TRUE;
  425. break;
  426. case IDC_IDLIST:
  427. if (HIWORD (wParam) == LBN_SELCHANGE)
  428. {
  429. _IDListClicked(hDlg, hWndCommentList, hWndIDList);
  430. _CommentListClicked(hDlg, hWndGlyph, hWndCommentList);
  431. }
  432. rv = TRUE;
  433. break;
  434. case IDC_COMMENTLIST:
  435. if (HIWORD(wParam) == LBN_SELCHANGE)
  436. {
  437. _CommentListClicked(hDlg, hWndGlyph, hWndCommentList);
  438. }
  439. rv = TRUE;
  440. break;
  441. }
  442. }
  443. return rv;
  444. }
  445. /*++
  446. * Function:
  447. * BrowseBitmapsDialog
  448. * Description:
  449. * Pops "Browse Glyphs(bitmaps) database"
  450. * Arguments:
  451. * hInst - our instance
  452. * hWnd - main window handle
  453. * Called by:
  454. * glyphspy.c!_GlyphSpyWndProc on ID_YEAH_BROWSE
  455. --*/
  456. VOID
  457. BrowseBitmapsDialog(HINSTANCE hInst, HWND hWnd)
  458. {
  459. g_pGrpList = NULL;
  460. g_pBitmap = NULL;
  461. g_pBmpList = NULL;
  462. DialogBox (
  463. hInst,
  464. MAKEINTRESOURCE (IDD_BROWSE),
  465. hWnd,
  466. _BrowseDlgProc
  467. );
  468. FreeBitmapList(g_pBmpList);
  469. FreeGroupList(g_pGrpList);
  470. }