comparison src/video/win32/SDL_win32keyboard.c @ 4914:cc7ac6aaac5d

Code style updates.
author Daniel Wyatt <Daniel.Wyatt@gmail.com>
date Tue, 23 Nov 2010 20:29:45 -0500
parents 6b89d83b0b5a
children 3617cec7f0ee
comparison
equal deleted inserted replaced
4913:6b89d83b0b5a 4914:cc7ac6aaac5d
628 videodata->ime_hkl = GetKeyboardLayout(0); 628 videodata->ime_hkl = GetKeyboardLayout(0);
629 if (hklprev == videodata->ime_hkl) 629 if (hklprev == videodata->ime_hkl)
630 return; 630 return;
631 631
632 hklprev = videodata->ime_hkl; 632 hklprev = videodata->ime_hkl;
633 switch (PRIMLANG()) 633 switch (PRIMLANG()) {
634 {
635 case LANG_CHINESE: 634 case LANG_CHINESE:
636 videodata->ime_candvertical = SDL_TRUE; 635 videodata->ime_candvertical = SDL_TRUE;
637 if (SUBLANG() == SUBLANG_CHINESE_SIMPLIFIED) 636 if (SUBLANG() == SUBLANG_CHINESE_SIMPLIFIED)
638 videodata->ime_candvertical = SDL_FALSE; 637 videodata->ime_candvertical = SDL_FALSE;
639 638
736 static void 735 static void
737 IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata) 736 IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata)
738 { 737 {
739 LPCANDIDATELIST cand_list = 0; 738 LPCANDIDATELIST cand_list = 0;
740 DWORD size = ImmGetCandidateListW(himc, 0, 0, 0); 739 DWORD size = ImmGetCandidateListW(himc, 0, 0, 0);
741 if (size) 740 if (size) {
742 {
743 cand_list = (LPCANDIDATELIST)SDL_malloc(size); 741 cand_list = (LPCANDIDATELIST)SDL_malloc(size);
744 if (cand_list) 742 if (cand_list) {
745 {
746 size = ImmGetCandidateListW(himc, 0, cand_list, size); 743 size = ImmGetCandidateListW(himc, 0, cand_list, size);
747 if (size) 744 if (size) {
748 {
749 int i = 0; 745 int i = 0;
750 int j = 0; 746 int j = 0;
751 int page_start = 0; 747 int page_start = 0;
752 videodata->ime_candsel = cand_list->dwSelection; 748 videodata->ime_candsel = cand_list->dwSelection;
753 videodata->ime_candcount = cand_list->dwCount; 749 videodata->ime_candcount = cand_list->dwCount;
754 750
755 if (LANG() == LANG_CHS && IME_GetId(videodata, 0)) 751 if (LANG() == LANG_CHS && IME_GetId(videodata, 0)) {
756 {
757 const UINT maxcandchar = 18; 752 const UINT maxcandchar = 18;
758 UINT i = 0; 753 UINT i = 0;
759 UINT cchars = 0; 754 UINT cchars = 0;
760 755
761 for (; i < videodata->ime_candcount; ++i) 756 for (; i < videodata->ime_candcount; ++i) {
762 {
763 UINT len = SDL_wcslen((LPWSTR)((DWORD)cand_list + cand_list->dwOffset[i])) + 1; 757 UINT len = SDL_wcslen((LPWSTR)((DWORD)cand_list + cand_list->dwOffset[i])) + 1;
764 if (len + cchars > maxcandchar) 758 if (len + cchars > maxcandchar) {
765 {
766 if (i > cand_list->dwSelection) 759 if (i > cand_list->dwSelection)
767 break; 760 break;
768 761
769 page_start = i; 762 page_start = i;
770 cchars = len; 763 cchars = len;
771 } 764 }
772 else 765 else {
773 {
774 cchars += len; 766 cchars += len;
775 } 767 }
776 } 768 }
777 videodata->ime_candpgsize = i - page_start; 769 videodata->ime_candpgsize = i - page_start;
778 } 770 }
779 else 771 else {
780 {
781 videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize, MAX_CANDLIST); 772 videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize, MAX_CANDLIST);
782 page_start = (cand_list->dwSelection / videodata->ime_candpgsize) * videodata->ime_candpgsize; 773 page_start = (cand_list->dwSelection / videodata->ime_candpgsize) * videodata->ime_candpgsize;
783 } 774 }
784 SDL_memset(&videodata->ime_candidates, 0, sizeof(videodata->ime_candidates)); 775 SDL_memset(&videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
785 for (i = page_start, j = 0; (DWORD)i < cand_list->dwCount && j < (int)videodata->ime_candpgsize; i++, j++) 776 for (i = page_start, j = 0; (DWORD)i < cand_list->dwCount && j < (int)videodata->ime_candpgsize; i++, j++) {
786 {
787 LPCWSTR candidate = (LPCWSTR)((DWORD)cand_list + cand_list->dwOffset[i]); 777 LPCWSTR candidate = (LPCWSTR)((DWORD)cand_list + cand_list->dwOffset[i]);
788 IME_AddCandidate(videodata, j, candidate); 778 IME_AddCandidate(videodata, j, candidate);
789 } 779 }
790 if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0))) 780 if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0)))
791 videodata->ime_candsel = -1; 781 videodata->ime_candsel = -1;
820 SDL_bool trap = SDL_FALSE; 810 SDL_bool trap = SDL_FALSE;
821 HIMC himc = 0; 811 HIMC himc = 0;
822 if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled) 812 if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled)
823 return SDL_FALSE; 813 return SDL_FALSE;
824 814
825 switch (msg) 815 switch (msg) {
826 {
827 case WM_INPUTLANGCHANGE: 816 case WM_INPUTLANGCHANGE:
828 IME_InputLangChanged(videodata); 817 IME_InputLangChanged(videodata);
829 break; 818 break;
830 case WM_IME_SETCONTEXT: 819 case WM_IME_SETCONTEXT:
831 *lParam = 0; 820 *lParam = 0;
854 videodata->ime_readingstring[0] = 0; 843 videodata->ime_readingstring[0] = 0;
855 videodata->ime_cursor = 0; 844 videodata->ime_cursor = 0;
856 SDL_SendEditingText("", 0, 0); 845 SDL_SendEditingText("", 0, 0);
857 break; 846 break;
858 case WM_IME_NOTIFY: 847 case WM_IME_NOTIFY:
859 switch (wParam) 848 switch (wParam) {
860 {
861 case IMN_SETCONVERSIONMODE: 849 case IMN_SETCONVERSIONMODE:
862 case IMN_SETOPENSTATUS: 850 case IMN_SETOPENSTATUS:
863 IME_UpdateInputLocale(videodata); 851 IME_UpdateInputLocale(videodata);
864 break; 852 break;
865 case IMN_OPENCANDIDATE: 853 case IMN_OPENCANDIDATE:
944 videodata->ime_candsel = selection; 932 videodata->ime_candsel = selection;
945 videodata->ime_candcount = count; 933 videodata->ime_candcount = count;
946 IME_ShowCandidateList(videodata); 934 IME_ShowCandidateList(videodata);
947 935
948 pcandlist->lpVtbl->GetPageIndex(pcandlist, 0, 0, &pgcount); 936 pcandlist->lpVtbl->GetPageIndex(pcandlist, 0, 0, &pgcount);
949 if (pgcount > 0) 937 if (pgcount > 0) {
950 {
951 UINT *idxlist = SDL_malloc(sizeof(UINT) * pgcount); 938 UINT *idxlist = SDL_malloc(sizeof(UINT) * pgcount);
952 if (idxlist) 939 if (idxlist) {
953 {
954 pcandlist->lpVtbl->GetPageIndex(pcandlist, idxlist, pgcount, &pgcount); 940 pcandlist->lpVtbl->GetPageIndex(pcandlist, idxlist, pgcount, &pgcount);
955 pgstart = idxlist[page]; 941 pgstart = idxlist[page];
956 if (page < pgcount - 1) 942 if (page < pgcount - 1)
957 pgsize = SDL_min(count, idxlist[page + 1]) - pgstart; 943 pgsize = SDL_min(count, idxlist[page + 1]) - pgstart;
958 else 944 else
963 } 949 }
964 videodata->ime_candpgsize = SDL_min(pgsize, MAX_CANDLIST); 950 videodata->ime_candpgsize = SDL_min(pgsize, MAX_CANDLIST);
965 videodata->ime_candsel = videodata->ime_candsel - pgstart; 951 videodata->ime_candsel = videodata->ime_candsel - pgstart;
966 952
967 SDL_memset(videodata->ime_candidates, 0, sizeof(videodata->ime_candidates)); 953 SDL_memset(videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
968 for (i = pgstart, j = 0; (DWORD)i < count && j < videodata->ime_candpgsize; i++, j++) 954 for (i = pgstart, j = 0; (DWORD)i < count && j < videodata->ime_candpgsize; i++, j++) {
969 {
970 BSTR bstr; 955 BSTR bstr;
971 if (SUCCEEDED(pcandlist->lpVtbl->GetString(pcandlist, i, &bstr))) 956 if (SUCCEEDED(pcandlist->lpVtbl->GetString(pcandlist, i, &bstr))) {
972 { 957 if (bstr) {
973 if (bstr)
974 {
975 IME_AddCandidate(videodata, j, bstr); 958 IME_AddCandidate(videodata, j, bstr);
976 SysFreeString(bstr); 959 SysFreeString(bstr);
977 } 960 }
978 } 961 }
979 } 962 }
987 } 970 }
988 971
989 STDMETHODIMP_(ULONG)TSFSink_Release(TSFSink *sink) 972 STDMETHODIMP_(ULONG)TSFSink_Release(TSFSink *sink)
990 { 973 {
991 --sink->refcount; 974 --sink->refcount;
992 if (sink->refcount == 0) 975 if (sink->refcount == 0) {
993 {
994 SDL_free(sink); 976 SDL_free(sink);
995 return 0; 977 return 0;
996 } 978 }
997 return sink->refcount; 979 return sink->refcount;
998 } 980 }
1240 StartDrawToBitmap(HDC hdc, HBITMAP *hhbm, int width, int height) 1222 StartDrawToBitmap(HDC hdc, HBITMAP *hhbm, int width, int height)
1241 { 1223 {
1242 BITMAPINFO info = {0}; 1224 BITMAPINFO info = {0};
1243 BITMAPINFOHEADER *infoHeader = &info.bmiHeader; 1225 BITMAPINFOHEADER *infoHeader = &info.bmiHeader;
1244 BYTE *bits = NULL; 1226 BYTE *bits = NULL;
1245 if (hhbm) 1227 if (hhbm) {
1246 {
1247 infoHeader->biSize = sizeof(BITMAPINFOHEADER); 1228 infoHeader->biSize = sizeof(BITMAPINFOHEADER);
1248 infoHeader->biWidth = width; 1229 infoHeader->biWidth = width;
1249 infoHeader->biHeight = -1 * SDL_abs(height); 1230 infoHeader->biHeight = -1 * SDL_abs(height);
1250 infoHeader->biPlanes = 1; 1231 infoHeader->biPlanes = 1;
1251 infoHeader->biBitCount = 32; 1232 infoHeader->biBitCount = 32;
1258 } 1239 }
1259 1240
1260 static void 1241 static void
1261 StopDrawToBitmap(HDC hdc, HBITMAP *hhbm) 1242 StopDrawToBitmap(HDC hdc, HBITMAP *hhbm)
1262 { 1243 {
1263 if (hhbm && *hhbm) 1244 if (hhbm && *hhbm) {
1264 {
1265 DeleteObject(*hhbm); 1245 DeleteObject(*hhbm);
1266 *hhbm = NULL; 1246 *hhbm = NULL;
1267 } 1247 }
1268 } 1248 }
1269 1249
1274 BITMAP bm = {0}; 1254 BITMAP bm = {0};
1275 1255
1276 if (GetObject(hbm, sizeof(bm), &bm) == 0) 1256 if (GetObject(hbm, sizeof(bm), &bm) == 0)
1277 return; 1257 return;
1278 1258
1279 if (bits && texture) 1259 if (bits && texture) {
1280 {
1281 /* 1260 /*
1282 For transparency: 1261 For transparency:
1283 1262
1284 const Uint8 alpha = 130; 1263 const Uint8 alpha = 130;
1285 unsigned long *p = (unsigned long *)bits; 1264 unsigned long *p = (unsigned long *)bits;
1286 unsigned long *end = (unsigned long *)(bits + (bm.bmWidthBytes * bm.bmHeight)); 1265 unsigned long *end = (unsigned long *)(bits + (bm.bmWidthBytes * bm.bmHeight));
1287 while (p < end) 1266 while (p < end) {
1288 {
1289 *p = RGB(GetRValue(*p), GetGValue(*p), GetBValue(*p)) | (alpha << 24); 1267 *p = RGB(GetRValue(*p), GetGValue(*p), GetBValue(*p)) | (alpha << 24);
1290 ++p; 1268 ++p;
1291 } 1269 }
1292 surface = SDL_CreateRGBSurfaceFrom(bits, width, height, bm.bmBitsPixel, bm.bmWidthBytes, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); 1270 surface = SDL_CreateRGBSurfaceFrom(bits, width, height, bm.bmBitsPixel, bm.bmWidthBytes, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
1293 */ 1271 */
1294 surface = SDL_CreateRGBSurfaceFrom(bits, width, height, bm.bmBitsPixel, bm.bmWidthBytes, 0x00ff0000, 0x0000ff00, 0x000000ff, 0); 1272 surface = SDL_CreateRGBSurfaceFrom(bits, width, height, bm.bmBitsPixel, bm.bmWidthBytes, 0x00ff0000, 0x0000ff00, 0x000000ff, 0);
1295 if (surface) 1273 if (surface) {
1296 {
1297 *texture = SDL_CreateTextureFromSurface(0, surface); 1274 *texture = SDL_CreateTextureFromSurface(0, surface);
1298 SDL_FreeSurface(surface); 1275 SDL_FreeSurface(surface);
1299 } 1276 }
1300 } 1277 }
1301 } 1278 }
1314 } 1291 }
1315 1292
1316 static void 1293 static void
1317 DestroyTexture(SDL_Texture **texture) 1294 DestroyTexture(SDL_Texture **texture)
1318 { 1295 {
1319 if (texture && *texture) 1296 if (texture && *texture) {
1320 {
1321 SDL_DestroyTexture(*texture); 1297 SDL_DestroyTexture(*texture);
1322 *texture = NULL; 1298 *texture = NULL;
1323 } 1299 }
1324 } 1300 }
1325 1301
1346 /* Bottom */ 1322 /* Bottom */
1347 left = videodata->ime_rect.x; 1323 left = videodata->ime_rect.x;
1348 top = videodata->ime_rect.y + videodata->ime_rect.h; 1324 top = videodata->ime_rect.y + videodata->ime_rect.h;
1349 right = left + size.cx; 1325 right = left + size.cx;
1350 bottom = top + size.cy; 1326 bottom = top + size.cy;
1351 if (right >= winw) 1327 if (right >= winw) {
1352 {
1353 left -= right - winw; 1328 left -= right - winw;
1354 right = winw; 1329 right = winw;
1355 } 1330 }
1356 if (bottom < winh) 1331 if (bottom < winh)
1357 ok = SDL_TRUE; 1332 ok = SDL_TRUE;
1358 1333
1359 /* Top */ 1334 /* Top */
1360 if (!ok) 1335 if (!ok) {
1361 {
1362 left = videodata->ime_rect.x; 1336 left = videodata->ime_rect.x;
1363 top = videodata->ime_rect.y - size.cy; 1337 top = videodata->ime_rect.y - size.cy;
1364 right = left + size.cx; 1338 right = left + size.cx;
1365 bottom = videodata->ime_rect.y; 1339 bottom = videodata->ime_rect.y;
1366 if (right >= winw) 1340 if (right >= winw) {
1367 {
1368 left -= right - winw; 1341 left -= right - winw;
1369 right = winw; 1342 right = winw;
1370 } 1343 }
1371 if (top >= 0) 1344 if (top >= 0)
1372 ok = SDL_TRUE; 1345 ok = SDL_TRUE;
1373 } 1346 }
1374 1347
1375 /* Right */ 1348 /* Right */
1376 if (!ok) 1349 if (!ok) {
1377 {
1378 left = videodata->ime_rect.x + size.cx; 1350 left = videodata->ime_rect.x + size.cx;
1379 top = 0; 1351 top = 0;
1380 right = left + size.cx; 1352 right = left + size.cx;
1381 bottom = size.cy; 1353 bottom = size.cy;
1382 if (right < winw) 1354 if (right < winw)
1383 ok = SDL_TRUE; 1355 ok = SDL_TRUE;
1384 } 1356 }
1385 1357
1386 /* Left */ 1358 /* Left */
1387 if (!ok) 1359 if (!ok) {
1388 {
1389 left = videodata->ime_rect.x - size.cx; 1360 left = videodata->ime_rect.x - size.cx;
1390 top = 0; 1361 top = 0;
1391 right = videodata->ime_rect.x; 1362 right = videodata->ime_rect.x;
1392 bottom = size.cy; 1363 bottom = size.cy;
1393 if (right >= 0) 1364 if (right >= 0)
1394 ok = SDL_TRUE; 1365 ok = SDL_TRUE;
1395 } 1366 }
1396 1367
1397 /* Window too small, show at (0,0) */ 1368 /* Window too small, show at (0,0) */
1398 if (!ok) 1369 if (!ok) {
1399 {
1400 left = 0; 1370 left = 0;
1401 top = 0; 1371 top = 0;
1402 right = size.cx; 1372 right = size.cx;
1403 bottom = size.cy; 1373 bottom = size.cy;
1404 } 1374 }
1444 HFONT font = CreateFont((int)(1 + videodata->ime_rect.h * 0.75f), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH | FF_SWISS, TEXT("Microsoft Sans Serif")); 1414 HFONT font = CreateFont((int)(1 + videodata->ime_rect.h * 0.75f), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH | FF_SWISS, TEXT("Microsoft Sans Serif"));
1445 1415
1446 SetBkMode(hdc, TRANSPARENT); 1416 SetBkMode(hdc, TRANSPARENT);
1447 SelectObject(hdc, font); 1417 SelectObject(hdc, font);
1448 1418
1449 for (i = 0; i < candcount; ++i) 1419 for (i = 0; i < candcount; ++i) {
1450 {
1451 const WCHAR *s = videodata->ime_candidates[i]; 1420 const WCHAR *s = videodata->ime_candidates[i];
1452 if (!*s) 1421 if (!*s)
1453 break; 1422 break;
1454 1423
1455 GetTextExtentPoint32W(hdc, s, SDL_wcslen(s), &size); 1424 GetTextExtentPoint32W(hdc, s, SDL_wcslen(s), &size);
1488 SelectObject(hdc, candpen); 1457 SelectObject(hdc, candpen);
1489 SelectObject(hdc, candbrush); 1458 SelectObject(hdc, candbrush);
1490 SetTextColor(hdc, candtextcolor); 1459 SetTextColor(hdc, candtextcolor);
1491 SetBkMode(hdc, TRANSPARENT); 1460 SetBkMode(hdc, TRANSPARENT);
1492 1461
1493 for (i = 0; i < candcount; ++i) 1462 for (i = 0; i < candcount; ++i) {
1494 {
1495 const WCHAR *s = videodata->ime_candidates[i]; 1463 const WCHAR *s = videodata->ime_candidates[i];
1496 int left, top, right, bottom; 1464 int left, top, right, bottom;
1497 if (!*s) 1465 if (!*s)
1498 break; 1466 break;
1499 1467
1505 right = size.cx - listborder - listpadding - candmargin; 1473 right = size.cx - listborder - listpadding - candmargin;
1506 if (!vertical) 1474 if (!vertical)
1507 SDL_swap(size.cx, size.cy); 1475 SDL_swap(size.cx, size.cy);
1508 1476
1509 bottom = top + maxcandsize.cy + (candpadding * 2) + (candborder * 2); 1477 bottom = top + maxcandsize.cy + (candpadding * 2) + (candborder * 2);
1510 if (!vertical) 1478 if (!vertical) {
1511 {
1512 SDL_swap(left, top); 1479 SDL_swap(left, top);
1513 SDL_swap(right, bottom); 1480 SDL_swap(right, bottom);
1514 } 1481 }
1515 1482
1516 if (i == videodata->ime_candsel) 1483 if (i == videodata->ime_candsel) {
1517 {
1518 SelectObject(hdc, selpen); 1484 SelectObject(hdc, selpen);
1519 SelectObject(hdc, selbrush); 1485 SelectObject(hdc, selbrush);
1520 SetTextColor(hdc, seltextcolor); 1486 SetTextColor(hdc, seltextcolor);
1521 } 1487 }
1522 else 1488 else {
1523 {
1524 SelectObject(hdc, candpen); 1489 SelectObject(hdc, candpen);
1525 SelectObject(hdc, candbrush); 1490 SelectObject(hdc, candbrush);
1526 SetTextColor(hdc, candtextcolor); 1491 SetTextColor(hdc, candtextcolor);
1527 } 1492 }
1528 1493