Mercurial > dwindows
comparison win/dw.c @ 1621:0e8c80209c4b
Rewrite of _get_logfont on Windows to use library functions and
not overrun the buffer in Unicode mode.
Also use _strdup() instead of strdup().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 27 Mar 2012 15:57:36 +0000 |
parents | 32b5fba0b00a |
children | fb3c9d7509dd |
comparison
equal
deleted
inserted
replaced
1620:32b5fba0b00a | 1621:0e8c80209c4b |
---|---|
2818 { | 2818 { |
2819 long val; | 2819 long val; |
2820 | 2820 |
2821 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); | 2821 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); |
2822 | 2822 |
2823 _stprintf(tmpbuf, TEXT("%ld"), val); | 2823 _sntprintf(tmpbuf, 99, TEXT("%ld"), val); |
2824 SetWindowText(hWnd, tmpbuf); | 2824 SetWindowText(hWnd, tmpbuf); |
2825 } | 2825 } |
2826 } | 2826 } |
2827 break; | 2827 break; |
2828 case WM_CTLCOLORSTATIC: | 2828 case WM_CTLCOLORSTATIC: |
4394 _do_resize(mybox, rect.right - rect.left, rect.bottom - rect.top); | 4394 _do_resize(mybox, rect.right - rect.left, rect.bottom - rect.top); |
4395 ShowWindow(istoplevel ? mybox->items[0].hwnd : handle, SW_SHOW); | 4395 ShowWindow(istoplevel ? mybox->items[0].hwnd : handle, SW_SHOW); |
4396 } | 4396 } |
4397 } | 4397 } |
4398 | 4398 |
4399 int instring(char *text, char *buffer) | |
4400 { | |
4401 int z, len = (int)strlen(text), buflen = (int)strlen(buffer); | |
4402 | |
4403 if(buflen > len) | |
4404 { | |
4405 for(z=0;z<=(buflen-len);z++) | |
4406 { | |
4407 if(memcmp(text, &buffer[z], len) == 0) | |
4408 return z; | |
4409 } | |
4410 } | |
4411 return 0; | |
4412 } | |
4413 | |
4414 /* | 4399 /* |
4415 * Changes a window's parent to newparent. | 4400 * Changes a window's parent to newparent. |
4416 * Parameters: | 4401 * Parameters: |
4417 * handle: The window handle to destroy. | 4402 * handle: The window handle to destroy. |
4418 * newparent: The window's new parent window. | 4403 * newparent: The window's new parent window. |
4422 SetParent(handle, newparent); | 4407 SetParent(handle, newparent); |
4423 } | 4408 } |
4424 | 4409 |
4425 LOGFONT _get_logfont(HDC hdc, char *fontname) | 4410 LOGFONT _get_logfont(HDC hdc, char *fontname) |
4426 { | 4411 { |
4427 int z, size = 9, len = (int)strlen(fontname); | 4412 char *Italic, *Bold, *myFontName = strchr(fontname, '.'); |
4428 int Italic, Bold; | 4413 int size = atoi(fontname); |
4429 char *myFontName; | |
4430 LOGFONT lf = {0}; | 4414 LOGFONT lf = {0}; |
4431 | 4415 |
4432 for(z=0;z<len;z++) | 4416 /* If we found a '.' use the location after the . */ |
4433 { | 4417 if(myFontName) |
4434 if(fontname[z]=='.') | 4418 myFontName = _strdup(++myFontName); |
4435 break; | 4419 else /* Otherwise use the whole fontname and default size of 9 */ |
4436 } | 4420 myFontName = _strdup(fontname); |
4437 size = atoi(fontname); | 4421 |
4438 lf.lfHeight = -MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72); | 4422 lf.lfHeight = -MulDiv(size ? size : 9, GetDeviceCaps(hdc, LOGPIXELSY), 72); |
4439 Italic = instring(" Italic", &fontname[z+1]); | 4423 Italic = strstr(myFontName, " Italic"); |
4440 Bold = instring(" Bold", &fontname[z+1]); | 4424 Bold = strstr(myFontName, " Bold"); |
4441 lf.lfWidth = 0; | 4425 lf.lfWidth = 0; |
4442 lf.lfEscapement = 0; | 4426 lf.lfEscapement = 0; |
4443 lf.lfOrientation = 0; | 4427 lf.lfOrientation = 0; |
4444 lf.lfItalic = Italic ? TRUE : FALSE; | 4428 lf.lfItalic = Italic ? TRUE : FALSE; |
4445 lf.lfUnderline = 0; | 4429 lf.lfUnderline = 0; |
4448 lf.lfCharSet = DEFAULT_CHARSET; | 4432 lf.lfCharSet = DEFAULT_CHARSET; |
4449 lf.lfOutPrecision = 0; | 4433 lf.lfOutPrecision = 0; |
4450 lf.lfClipPrecision = 0; | 4434 lf.lfClipPrecision = 0; |
4451 lf.lfQuality = DEFAULT_QUALITY; | 4435 lf.lfQuality = DEFAULT_QUALITY; |
4452 lf.lfPitchAndFamily = DEFAULT_PITCH | FW_DONTCARE; | 4436 lf.lfPitchAndFamily = DEFAULT_PITCH | FW_DONTCARE; |
4453 /* | |
4454 * remove any font modifiers | |
4455 */ | |
4456 myFontName = _strdup(&fontname[z+1]); | |
4457 if(Italic) | 4437 if(Italic) |
4458 myFontName[Italic] = 0; | 4438 *Italic = 0; |
4459 if(Bold) | 4439 if(Bold) |
4460 myFontName[Bold] = 0; | 4440 *Bold = 0; |
4461 _tcsncpy(lf.lfFaceName, UTF8toWide(myFontName), sizeof(lf.lfFaceName)-1); | 4441 _tcsncpy(lf.lfFaceName, UTF8toWide(myFontName), (sizeof(lf.lfFaceName)/sizeof(TCHAR))-1); |
4462 free(myFontName); | 4442 free(myFontName); |
4463 return lf; | 4443 return lf; |
4464 } | 4444 } |
4465 | 4445 |
4466 /* Create a duplicate of an existing font handle | 4446 /* Create a duplicate of an existing font handle |
6799 | 6779 |
6800 /* Figure out the UTF8 length, allocate a return buffer | 6780 /* Figure out the UTF8 length, allocate a return buffer |
6801 * and fill it with the UTF8 text and return it. | 6781 * and fill it with the UTF8 text and return it. |
6802 */ | 6782 */ |
6803 if(tempbuf && (retbuf = WideToUTF8(tempbuf))) | 6783 if(tempbuf && (retbuf = WideToUTF8(tempbuf))) |
6804 retbuf = strdup(retbuf); | 6784 retbuf = _strdup(retbuf); |
6805 return retbuf; | 6785 return retbuf; |
6806 } | 6786 } |
6807 | 6787 |
6808 /* | 6788 /* |
6809 * Disables given window (widget). | 6789 * Disables given window (widget). |
8553 | 8533 |
8554 tvi.mask = TVIF_HANDLE; | 8534 tvi.mask = TVIF_HANDLE; |
8555 tvi.hItem = item; | 8535 tvi.hItem = item; |
8556 | 8536 |
8557 if(TreeView_GetItem(handle, &tvi)) | 8537 if(TreeView_GetItem(handle, &tvi)) |
8558 return strdup(WideToUTF8(tvi.pszText)); | 8538 return _strdup(WideToUTF8(tvi.pszText)); |
8559 return NULL; | 8539 return NULL; |
8560 } | 8540 } |
8561 | 8541 |
8562 /* | 8542 /* |
8563 * Gets the text an item in a tree window (widget). | 8543 * Gets the text an item in a tree window (widget). |