Mercurial > dwindows
comparison os2/dw.c @ 1411:22ba64e357de
Initial versions of code to figure out control sizes for Windows and OS/2...
and some fixes for the Mac version.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 02 Dec 2011 08:22:11 +0000 |
parents | 93eb987c05cf |
children | 246aadf8fbd4 |
comparison
equal
deleted
inserted
replaced
1410:c607fd86e5c2 | 1411:22ba64e357de |
---|---|
4639 | 4639 |
4640 DefaultFont = strdup(fontname); | 4640 DefaultFont = strdup(fontname); |
4641 free(oldfont); | 4641 free(oldfont); |
4642 } | 4642 } |
4643 | 4643 |
4644 /* Internal function to return a pointer to an item struct | |
4645 * with information about the packing information regarding object. | |
4646 */ | |
4647 Item *_box_item(HWND handle) | |
4648 { | |
4649 HWND parent = WinQueryWindow(handle, QW_PARENT); | |
4650 Box *thisbox = (Box *)WinQueryWindowPtr(parent, QWP_USER); | |
4651 | |
4652 /* If it is a desktop window let WM_DESTROY handle it */ | |
4653 if(parent != HWND_DESKTOP) | |
4654 { | |
4655 if(thisbox && thisbox->count) | |
4656 { | |
4657 int z; | |
4658 Item *thisitem = thisbox->items; | |
4659 | |
4660 for(z=0;z<thisbox->count;z++) | |
4661 { | |
4662 if(thisitem[z].hwnd == handle) | |
4663 return &thisitem[z]; | |
4664 } | |
4665 } | |
4666 } | |
4667 return NULL; | |
4668 } | |
4669 | |
4670 /* Internal function to calculate the widget's required size.. | |
4671 * These are the general rules for widget sizes: | |
4672 * | |
4673 * Scrolled(Container,Tree,MLE)/Render/Unspecified: 1x1 | |
4674 * Entryfield/Combobox/Spinbutton: 150x(maxfontheight) | |
4675 * Spinbutton: 50x(maxfontheight) | |
4676 * Text/Status: (textwidth)x(textheight) | |
4677 */ | |
4678 void _control_size(HWND handle, int *width, int *height) | |
4679 { | |
4680 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; | |
4681 char tmpbuf[100], *buf = dw_window_get_text(handle); | |
4682 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
4683 | |
4684 WinQueryClassName(handle, 99, (PCH)tmpbuf); | |
4685 | |
4686 /* If we have a string... | |
4687 * calculate the size with the current font. | |
4688 */ | |
4689 if(buf) | |
4690 { | |
4691 if(*buf) | |
4692 dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight); | |
4693 dw_free(buf); | |
4694 } | |
4695 | |
4696 /* Combobox */ | |
4697 if(strnicmp(tmpbuf, WC_COMBOBOX, strlen(WC_COMBOBOX)+1) == 0) | |
4698 { | |
4699 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight); | |
4700 thiswidth = 150; | |
4701 extraheight = 4; | |
4702 if(thisheight < 18) | |
4703 thisheight = 18; | |
4704 } | |
4705 else if(strnicmp(tmpbuf, WC_SPINBUTTON, strlen(WC_SPINBUTTON)+1) == 0) | |
4706 { | |
4707 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight); | |
4708 thiswidth = 50; | |
4709 } | |
4710 else if(strnicmp(tmpbuf, WC_ENTRYFIELD, strlen(WC_ENTRYFIELD)+1) == 0) | |
4711 { | |
4712 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight); | |
4713 thiswidth = 150; | |
4714 extraheight = 6; | |
4715 } | |
4716 else if(strnicmp(tmpbuf, WC_BUTTON, strlen(WC_BUTTON)+1) == 0) | |
4717 { | |
4718 ULONG style = WinQueryWindowULong(handle, QWL_STYLE); | |
4719 | |
4720 if(style & BS_AUTOCHECKBOX || style & BS_AUTORADIOBUTTON) | |
4721 { | |
4722 extrawidth = 24; | |
4723 extraheight = 4; | |
4724 } | |
4725 else | |
4726 { | |
4727 extrawidth = 8; | |
4728 extraheight = 4; | |
4729 } | |
4730 } | |
4731 | |
4732 /* Set the requested sizes */ | |
4733 if(width) | |
4734 *width = thiswidth + extrawidth; | |
4735 if(height) | |
4736 *height = thisheight + extraheight; | |
4737 } | |
4738 | |
4644 /* | 4739 /* |
4645 * Sets the font used by a specified window (widget) handle. | 4740 * Sets the font used by a specified window (widget) handle. |
4646 * Parameters: | 4741 * Parameters: |
4647 * handle: The window (widget) handle. | 4742 * handle: The window (widget) handle. |
4648 * fontname: Name and size of the font in the form "size.fontname" | 4743 * fontname: Name and size of the font in the form "size.fontname" |
4649 */ | 4744 */ |
4650 int API dw_window_set_font(HWND handle, char *fontname) | 4745 int API dw_window_set_font(HWND handle, char *fontname) |
4651 { | 4746 { |
4652 HWND group = (HWND)dw_window_get_data(handle, "_dw_buddy"); | 4747 HWND group = (HWND)dw_window_get_data(handle, "_dw_buddy"); |
4653 return WinSetPresParam(group ? group : handle, PP_FONTNAMESIZE, strlen(fontname)+1, fontname); | 4748 /* If we changed the font... */ |
4749 if(!WinSetPresParam(group ? group : handle, PP_FONTNAMESIZE, strlen(fontname)+1, fontname)) | |
4750 { | |
4751 Item *item = _box_item(handle); | |
4752 | |
4753 /* Check to see if any of the sizes need to be recalculated */ | |
4754 if(item && (item->origwidth == -1 || item->origheight == -1)) | |
4755 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | |
4756 return DW_ERROR_NONE; | |
4757 } | |
4758 return DW_ERROR_UNKNOWN; | |
4654 } | 4759 } |
4655 | 4760 |
4656 /* | 4761 /* |
4657 * Gets the font used by a specified window (widget) handle. | 4762 * Gets the font used by a specified window (widget) handle. |
4658 * Parameters: | 4763 * Parameters: |
6400 */ | 6505 */ |
6401 void API dw_window_set_text(HWND handle, char *text) | 6506 void API dw_window_set_text(HWND handle, char *text) |
6402 { | 6507 { |
6403 HWND entryfield = (HWND)dw_window_get_data(handle, "_dw_buddy"); | 6508 HWND entryfield = (HWND)dw_window_get_data(handle, "_dw_buddy"); |
6404 WinSetWindowText(entryfield ? entryfield : handle, (PSZ)text); | 6509 WinSetWindowText(entryfield ? entryfield : handle, (PSZ)text); |
6510 /* If we changed the text... */ | |
6511 { | |
6512 Item *item = _box_item(handle); | |
6513 | |
6514 /* Check to see if any of the sizes need to be recalculated */ | |
6515 if(item && (item->origwidth == -1 || item->origheight == -1)) | |
6516 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | |
6517 } | |
6405 } | 6518 } |
6406 | 6519 |
6407 /* | 6520 /* |
6408 * Sets the text used for a given window's floating bubble help. | 6521 * Sets the text used for a given window's floating bubble help. |
6409 * Parameters: | 6522 * Parameters: |
6651 | 6764 |
6652 tmpitem[index].hwnd = item; | 6765 tmpitem[index].hwnd = item; |
6653 tmpitem[index].origwidth = tmpitem[index].width = width; | 6766 tmpitem[index].origwidth = tmpitem[index].width = width; |
6654 tmpitem[index].origheight = tmpitem[index].height = height; | 6767 tmpitem[index].origheight = tmpitem[index].height = height; |
6655 tmpitem[index].pad = pad; | 6768 tmpitem[index].pad = pad; |
6656 if(hsize) | 6769 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC; |
6657 tmpitem[index].hsize = SIZEEXPAND; | 6770 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC; |
6658 else | 6771 |
6659 tmpitem[index].hsize = SIZESTATIC; | 6772 /* If either of the parameters are -1 ... calculate the size */ |
6660 | 6773 if(width == -1 || height == -1) |
6661 if(vsize) | 6774 _control_size(item, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); |
6662 tmpitem[index].vsize = SIZEEXPAND; | |
6663 else | |
6664 tmpitem[index].vsize = SIZESTATIC; | |
6665 | 6775 |
6666 thisbox->items = tmpitem; | 6776 thisbox->items = tmpitem; |
6667 | 6777 |
6668 if(thisbox->count) | 6778 if(thisbox->count) |
6669 free(thisitem); | 6779 free(thisitem); |