Mercurial > dwindows
comparison win/dw.c @ 2250:a691de150bef
Win: Fix crash in dw_window_set_font() with a NULL font name on Rich Edit MLEs.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 24 Jan 2021 20:20:06 +0000 |
parents | 703023e1a644 |
children | 48daaf050e82 |
comparison
equal
deleted
inserted
replaced
2249:14a1e07e8f4e | 2250:a691de150bef |
---|---|
40 #endif | 40 #endif |
41 #include <richedit.h> | 41 #include <richedit.h> |
42 | 42 |
43 #ifdef RICHEDIT | 43 #ifdef RICHEDIT |
44 int _DW_MLE_RICH_EDIT = DW_FEATURE_UNSUPPORTED; | 44 int _DW_MLE_RICH_EDIT = DW_FEATURE_UNSUPPORTED; |
45 static CHARFORMAT _dw_default_charformat = {0}; | |
45 #endif | 46 #endif |
46 | 47 |
47 #define STATICCLASSNAME TEXT("STATIC") | 48 #define STATICCLASSNAME TEXT("STATIC") |
48 #define COMBOBOXCLASSNAME TEXT("COMBOBOX") | 49 #define COMBOBOXCLASSNAME TEXT("COMBOBOX") |
49 #define LISTBOXCLASSNAME TEXT("LISTBOX") | 50 #define LISTBOXCLASSNAME TEXT("LISTBOX") |
5686 } | 5687 } |
5687 #ifdef RICHEDIT | 5688 #ifdef RICHEDIT |
5688 if (_tcsnicmp(tmpbuf, RICHEDIT_CLASS, _tcslen(RICHEDIT_CLASS)+1) == 0 || | 5689 if (_tcsnicmp(tmpbuf, RICHEDIT_CLASS, _tcslen(RICHEDIT_CLASS)+1) == 0 || |
5689 _tcsnicmp(tmpbuf, MSFTEDIT_CLASS, _tcslen(MSFTEDIT_CLASS)+1) == 0) | 5690 _tcsnicmp(tmpbuf, MSFTEDIT_CLASS, _tcslen(MSFTEDIT_CLASS)+1) == 0) |
5690 { | 5691 { |
5691 CHARFORMAT cf; | 5692 if(fontname) |
5692 char *Italic, *Bold, *myFontName = strchr(fontname, '.'); | 5693 { |
5693 int size = atoi(fontname); | 5694 CHARFORMAT cf = {0}; |
5694 | 5695 char *Italic, *Bold, *myFontName = strchr(fontname, '.'); |
5695 /* If we found a '.' use the location after the . */ | 5696 int size = atoi(fontname); |
5696 if(myFontName) | 5697 |
5697 myFontName = _strdup(++myFontName); | 5698 /* If we found a '.' use the location after the . */ |
5698 else /* Otherwise use the whole fontname and default size of 9 */ | 5699 if(myFontName) |
5699 myFontName = _strdup(fontname); | 5700 myFontName = _strdup(++myFontName); |
5700 | 5701 else /* Otherwise use the whole fontname and default size of 9 */ |
5701 if((Italic = strstr(myFontName, " Italic"))) | 5702 myFontName = _strdup(fontname); |
5702 *Italic = 0; | 5703 |
5703 if((Bold = strstr(myFontName, " Bold"))) | 5704 if((Italic = strstr(myFontName, " Italic"))) |
5704 *Bold = 0; | 5705 *Italic = 0; |
5705 | 5706 if((Bold = strstr(myFontName, " Bold"))) |
5706 SendMessage(handle, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); | 5707 *Bold = 0; |
5707 cf.cbSize = sizeof(cf); | 5708 |
5708 cf.dwMask = CFM_FACE | CFM_ITALIC | CFM_BOLD; | 5709 cf.cbSize = sizeof(cf); |
5709 cf.dwEffects = (Italic ? CFE_ITALIC : 0) | (Bold ? CFE_BOLD : 0); | 5710 SendMessage(handle, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); |
5710 _tcsncpy(cf.szFaceName, UTF8toWide(myFontName), (sizeof(cf.szFaceName)/sizeof(TCHAR))-1); | 5711 cf.dwMask = CFM_FACE | CFM_ITALIC | CFM_BOLD; |
5711 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); | 5712 cf.dwEffects = (Italic ? CFE_ITALIC : 0) | (Bold ? CFE_BOLD : 0); |
5712 | 5713 _tcsncpy(cf.szFaceName, UTF8toWide(myFontName), (sizeof(cf.szFaceName)/sizeof(TCHAR))-1); |
5713 SendMessage(handle, EM_SETFONTSIZE , (WPARAM)(size ? size : 9), 0); | 5714 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); |
5714 free(myFontName); | 5715 |
5716 SendMessage(handle, EM_SETFONTSIZE , (WPARAM)(size ? size : 9), 0); | |
5717 free(myFontName); | |
5718 } | |
5719 else | |
5720 { | |
5721 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat); | |
5722 SendMessage(handle, EM_SETFONTSIZE , (WPARAM)9, 0); | |
5723 } | |
5715 } | 5724 } |
5716 else | 5725 else |
5717 #endif | 5726 #endif |
5718 { | 5727 { |
5719 /* This needs to be after we get the correct handle */ | 5728 /* This needs to be after we get the correct handle */ |
7031 return NULL; | 7040 return NULL; |
7032 } | 7041 } |
7033 | 7042 |
7034 #ifdef RICHEDIT | 7043 #ifdef RICHEDIT |
7035 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) | 7044 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) |
7045 { | |
7036 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _richeditwndproc); | 7046 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _richeditwndproc); |
7047 /* Save the default RichEdit font for later use */ | |
7048 _dw_default_charformat.cbSize = sizeof(CHARFORMAT); | |
7049 SendMessage(tmp, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat); | |
7050 /* Make sure we set the mask we will use for reseting the MLE later */ | |
7051 _dw_default_charformat.dwMask = CFM_FACE | CFM_ITALIC | CFM_BOLD; | |
7052 } | |
7037 else | 7053 else |
7038 #endif | 7054 #endif |
7039 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _simplewndproc); | 7055 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _simplewndproc); |
7040 cinfo->cinfo.fore = cinfo->cinfo.back = -1; | 7056 cinfo->cinfo.fore = cinfo->cinfo.back = -1; |
7041 cinfo->odd = cinfo->even = DW_RGB_TRANSPARENT; | 7057 cinfo->odd = cinfo->even = DW_RGB_TRANSPARENT; |
9429 * handle: Handle to the MLE. | 9445 * handle: Handle to the MLE. |
9430 * state: TRUE if it wraps, FALSE if it doesn't. | 9446 * state: TRUE if it wraps, FALSE if it doesn't. |
9431 */ | 9447 */ |
9432 void API dw_mle_set_word_wrap(HWND handle, int state) | 9448 void API dw_mle_set_word_wrap(HWND handle, int state) |
9433 { | 9449 { |
9450 #ifdef RICHEDIT | |
9434 /* If it is a rich edit control use the rich edit message */ | 9451 /* If it is a rich edit control use the rich edit message */ |
9435 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) | 9452 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) |
9436 { | 9453 { |
9437 SendMessage(handle, EM_SHOWSCROLLBAR, (WPARAM)SB_HORZ, (LPARAM)(state ? FALSE : TRUE)); | 9454 SendMessage(handle, EM_SHOWSCROLLBAR, (WPARAM)SB_HORZ, (LPARAM)(state ? FALSE : TRUE)); |
9438 SendMessage(handle, EM_SETTARGETDEVICE, 0, state ? 0 : 1); | 9455 SendMessage(handle, EM_SETTARGETDEVICE, 0, state ? 0 : 1); |
9439 } | 9456 } |
9457 #endif | |
9440 } | 9458 } |
9441 | 9459 |
9442 /* | 9460 /* |
9443 * Sets the word auto complete state of an MLE box. | 9461 * Sets the word auto complete state of an MLE box. |
9444 * Parameters: | 9462 * Parameters: |
9456 * point: Point to position cursor. | 9474 * point: Point to position cursor. |
9457 */ | 9475 */ |
9458 void API dw_mle_set_cursor(HWND handle, int point) | 9476 void API dw_mle_set_cursor(HWND handle, int point) |
9459 { | 9477 { |
9460 SendMessage(handle, EM_SETSEL, (WPARAM)point, (LPARAM)point); | 9478 SendMessage(handle, EM_SETSEL, (WPARAM)point, (LPARAM)point); |
9479 #ifdef RICHEDIT | |
9461 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) | 9480 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) |
9462 SendMessage(handle, EM_HIDESELECTION, 0, 0); | 9481 SendMessage(handle, EM_HIDESELECTION, 0, 0); |
9482 #endif | |
9463 SendMessage(handle, EM_SCROLLCARET, 0, 0); | 9483 SendMessage(handle, EM_SCROLLCARET, 0, 0); |
9464 } | 9484 } |
9465 | 9485 |
9466 /* | 9486 /* |
9467 * Finds text in an MLE box. | 9487 * Finds text in an MLE box. |
9500 } | 9520 } |
9501 | 9521 |
9502 if(retval) | 9522 if(retval) |
9503 { | 9523 { |
9504 SendMessage(handle, EM_SETSEL, (WPARAM)retval - textlen, (LPARAM)retval); | 9524 SendMessage(handle, EM_SETSEL, (WPARAM)retval - textlen, (LPARAM)retval); |
9525 #ifdef RICHEDIT | |
9505 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) | 9526 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) |
9506 SendMessage(handle, EM_HIDESELECTION, 0, 0); | 9527 SendMessage(handle, EM_HIDESELECTION, 0, 0); |
9528 #endif | |
9507 SendMessage(handle, EM_SCROLLCARET, 0, 0); | 9529 SendMessage(handle, EM_SCROLLCARET, 0, 0); |
9508 } | 9530 } |
9509 | 9531 |
9510 free(tmpbuf); | 9532 free(tmpbuf); |
9511 | 9533 |