Mercurial > dwindows
comparison win/dw.c @ 2247:703023e1a644
Win: Implement dw_window_set_font() support for Rich Edit based MLEs.
Also add font size and name support for changing MLE in dwtest.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 23 Jan 2021 00:48:12 +0000 |
parents | 7f6939857cca |
children | a691de150bef |
comparison
equal
deleted
inserted
replaced
2246:471cdeaef7ac | 2247:703023e1a644 |
---|---|
5668 * handle: The window (widget) handle. | 5668 * handle: The window (widget) handle. |
5669 * fontname: Name and size of the font in the form "size.fontname" | 5669 * fontname: Name and size of the font in the form "size.fontname" |
5670 */ | 5670 */ |
5671 int API dw_window_set_font(HWND handle, const char *fontname) | 5671 int API dw_window_set_font(HWND handle, const char *fontname) |
5672 { | 5672 { |
5673 HFONT hfont, oldfont; | 5673 HFONT hfont = NULL, oldfont = NULL; |
5674 ColorInfo *cinfo = _dw_window_get_cinfo(handle); | 5674 ColorInfo *cinfo = _dw_window_get_cinfo(handle); |
5675 TCHAR tmpbuf[100] = {0}; | 5675 TCHAR tmpbuf[100] = {0}; |
5676 | 5676 |
5677 GetClassName(handle, tmpbuf, 99); | 5677 GetClassName(handle, tmpbuf, 99); |
5678 if ( _tcsnicmp( tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0 ) | 5678 if ( _tcsnicmp( tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0 ) |
5682 if ( thisbox && thisbox->grouphwnd != (HWND)NULL ) | 5682 if ( thisbox && thisbox->grouphwnd != (HWND)NULL ) |
5683 { | 5683 { |
5684 handle = thisbox->grouphwnd; | 5684 handle = thisbox->grouphwnd; |
5685 } | 5685 } |
5686 } | 5686 } |
5687 | 5687 #ifdef RICHEDIT |
5688 /* This needs to be after we get the correct handle */ | 5688 if (_tcsnicmp(tmpbuf, RICHEDIT_CLASS, _tcslen(RICHEDIT_CLASS)+1) == 0 || |
5689 oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); | 5689 _tcsnicmp(tmpbuf, MSFTEDIT_CLASS, _tcslen(MSFTEDIT_CLASS)+1) == 0) |
5690 hfont = _acquire_font(handle, fontname); | 5690 { |
5691 | 5691 CHARFORMAT cf; |
5692 if(hfont && fontname) | 5692 char *Italic, *Bold, *myFontName = strchr(fontname, '.'); |
5693 int size = atoi(fontname); | |
5694 | |
5695 /* If we found a '.' use the location after the . */ | |
5696 if(myFontName) | |
5697 myFontName = _strdup(++myFontName); | |
5698 else /* Otherwise use the whole fontname and default size of 9 */ | |
5699 myFontName = _strdup(fontname); | |
5700 | |
5701 if((Italic = strstr(myFontName, " Italic"))) | |
5702 *Italic = 0; | |
5703 if((Bold = strstr(myFontName, " Bold"))) | |
5704 *Bold = 0; | |
5705 | |
5706 SendMessage(handle, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); | |
5707 cf.cbSize = sizeof(cf); | |
5708 cf.dwMask = CFM_FACE | CFM_ITALIC | CFM_BOLD; | |
5709 cf.dwEffects = (Italic ? CFE_ITALIC : 0) | (Bold ? CFE_BOLD : 0); | |
5710 _tcsncpy(cf.szFaceName, UTF8toWide(myFontName), (sizeof(cf.szFaceName)/sizeof(TCHAR))-1); | |
5711 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); | |
5712 | |
5713 SendMessage(handle, EM_SETFONTSIZE , (WPARAM)(size ? size : 9), 0); | |
5714 free(myFontName); | |
5715 } | |
5716 else | |
5717 #endif | |
5718 { | |
5719 /* This needs to be after we get the correct handle */ | |
5720 oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); | |
5721 hfont = _acquire_font(handle, fontname); | |
5722 } | |
5723 | |
5724 if(fontname) | |
5693 { | 5725 { |
5694 if(cinfo || (cinfo = _dw_window_new_cinfo(handle, TRUE))) | 5726 if(cinfo || (cinfo = _dw_window_new_cinfo(handle, TRUE))) |
5695 { | 5727 { |
5696 strncpy(cinfo->fontname, fontname, 127); | 5728 strncpy(cinfo->fontname, fontname, 127); |
5697 if(!oldfont) | 5729 if(hfont) |
5698 oldfont = cinfo->hfont; | 5730 { |
5699 cinfo->hfont = hfont; | 5731 if(!oldfont) |
5732 oldfont = cinfo->hfont; | |
5733 cinfo->hfont = hfont; | |
5734 } | |
5700 } | 5735 } |
5701 } | 5736 } |
5702 /* If we changed the font... */ | 5737 /* If we changed the font... */ |
5703 if(hfont) | 5738 if(hfont) |
5704 { | 5739 { |