Mercurial > dwindows
comparison mac/dw.m @ 2439:af5487a11954
Mac: Minor _dw_control_size() cleanup. Make sure check is on the base handle.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 07 Apr 2021 03:04:41 +0000 |
parents | b0e6f8f0a1ff |
children | 0315ae3a8820 |
comparison
equal
deleted
inserted
replaced
2438:f273dbf1312f | 2439:af5487a11954 |
---|---|
4780 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; | 4780 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; |
4781 NSString *nsstr = nil; | 4781 NSString *nsstr = nil; |
4782 id object = _dw_text_handle(handle); | 4782 id object = _dw_text_handle(handle); |
4783 | 4783 |
4784 /* Handle all the different button types */ | 4784 /* Handle all the different button types */ |
4785 if([ object isKindOfClass:[ NSButton class ] ]) | 4785 if([object isKindOfClass:[NSButton class]]) |
4786 { | 4786 { |
4787 switch([object buttonType]) | 4787 switch([object buttonType]) |
4788 { | 4788 { |
4789 case DWButtonTypeSwitch: | 4789 case DWButtonTypeSwitch: |
4790 case DWButtonTypeRadio: | 4790 case DWButtonTypeRadio: |
4827 break; | 4827 break; |
4828 } | 4828 } |
4829 } | 4829 } |
4830 } | 4830 } |
4831 /* If the control is an entryfield set width to 150 */ | 4831 /* If the control is an entryfield set width to 150 */ |
4832 else if([object isKindOfClass:[ NSTextField class ]]) | 4832 else if([object isKindOfClass:[NSTextField class]]) |
4833 { | 4833 { |
4834 NSFont *font = [object font]; | 4834 NSFont *font = [object font]; |
4835 | 4835 |
4836 if([object isEditable]) | 4836 if([object isEditable]) |
4837 { | 4837 { |
4838 /* Spinbuttons don't need to be as wide */ | 4838 /* Spinbuttons don't need to be as wide */ |
4839 if([handle isMemberOfClass:[ DWSpinButton class]]) | 4839 if([handle isMemberOfClass:[DWSpinButton class]]) |
4840 thiswidth = 50; | 4840 thiswidth = 50; |
4841 else | 4841 else |
4842 thiswidth = 150; | 4842 thiswidth = 150; |
4843 /* Comboboxes need some extra height for the border */ | 4843 /* Comboboxes need some extra height for the border */ |
4844 if([object isMemberOfClass:[ DWComboBox class]]) | 4844 if([handle isMemberOfClass:[DWComboBox class]]) |
4845 extraheight = 4; | 4845 extraheight = 4; |
4846 /* Yosemite and higher requires even more border space */ | 4846 /* Yosemite and higher requires even more border space */ |
4847 if(DWOSMinor > 9 || DWOSMajor > 10) | 4847 if(DWOSMinor > 9 || DWOSMajor > 10) |
4848 extraheight += 4; | 4848 extraheight += 4; |
4849 } | 4849 } |
4852 | 4852 |
4853 if(font) | 4853 if(font) |
4854 thisheight = (int)[font boundingRectForFont].size.height; | 4854 thisheight = (int)[font boundingRectForFont].size.height; |
4855 } | 4855 } |
4856 /* Handle the ranged widgets */ | 4856 /* Handle the ranged widgets */ |
4857 else if([ object isMemberOfClass:[DWPercent class] ] || | 4857 else if([object isMemberOfClass:[DWPercent class]] || |
4858 [ object isMemberOfClass:[DWSlider class] ]) | 4858 [object isMemberOfClass:[DWSlider class]]) |
4859 { | 4859 { |
4860 thiswidth = 100; | 4860 thiswidth = 100; |
4861 thisheight = 20; | 4861 thisheight = 20; |
4862 } | 4862 } |
4863 /* Handle the ranged widgets */ | 4863 /* Handle the ranged widgets */ |
4864 else if([ object isMemberOfClass:[DWScrollbar class] ]) | 4864 else if([object isMemberOfClass:[DWScrollbar class]]) |
4865 { | 4865 { |
4866 if([object vertical]) | 4866 if([object vertical]) |
4867 { | 4867 { |
4868 thiswidth = 14; | 4868 thiswidth = 14; |
4869 thisheight = 100; | 4869 thisheight = 100; |
4873 thiswidth = 100; | 4873 thiswidth = 100; |
4874 thisheight = 14; | 4874 thisheight = 14; |
4875 } | 4875 } |
4876 } | 4876 } |
4877 /* Handle bitmap size */ | 4877 /* Handle bitmap size */ |
4878 else if([ object isMemberOfClass:[NSImageView class] ]) | 4878 else if([object isMemberOfClass:[NSImageView class]]) |
4879 { | 4879 { |
4880 NSImage *image = [object image]; | 4880 NSImage *image = [object image]; |
4881 | 4881 |
4882 if(image) | 4882 if(image) |
4883 { | 4883 { |
4885 thiswidth = (int)size.width; | 4885 thiswidth = (int)size.width; |
4886 thisheight = (int)size.height; | 4886 thisheight = (int)size.height; |
4887 } | 4887 } |
4888 } | 4888 } |
4889 /* Handle calendar */ | 4889 /* Handle calendar */ |
4890 else if([ object isMemberOfClass:[DWCalendar class] ]) | 4890 else if([object isMemberOfClass:[DWCalendar class]]) |
4891 { | 4891 { |
4892 NSCell *cell = [object cell]; | 4892 NSCell *cell = [object cell]; |
4893 | 4893 |
4894 if(cell) | 4894 if(cell) |
4895 { | 4895 { |
4898 thiswidth = size.width; | 4898 thiswidth = size.width; |
4899 thisheight = size.height; | 4899 thisheight = size.height; |
4900 } | 4900 } |
4901 } | 4901 } |
4902 /* MLE and Container */ | 4902 /* MLE and Container */ |
4903 else if([ object isMemberOfClass:[DWMLE class] ] || | 4903 else if([object isMemberOfClass:[DWMLE class]] || |
4904 [ object isMemberOfClass:[DWContainer class] ]) | 4904 [object isMemberOfClass:[DWContainer class]]) |
4905 { | 4905 { |
4906 NSSize size; | 4906 NSSize size; |
4907 | 4907 |
4908 if([ object isMemberOfClass:[DWMLE class] ]) | 4908 if([object isMemberOfClass:[DWMLE class]]) |
4909 { | 4909 { |
4910 NSScrollView *sv = [object scrollview]; | 4910 NSScrollView *sv = [object scrollview]; |
4911 NSSize frame = [sv frame].size; | 4911 NSSize frame = [sv frame].size; |
4912 BOOL hscroll = [sv hasHorizontalScroller]; | 4912 BOOL hscroll = [sv hasHorizontalScroller]; |
4913 | 4913 |
4964 thisheight = _DW_SCROLLED_MIN_HEIGHT; | 4964 thisheight = _DW_SCROLLED_MIN_HEIGHT; |
4965 if(thisheight > _DW_SCROLLED_MAX_HEIGHT) | 4965 if(thisheight > _DW_SCROLLED_MAX_HEIGHT) |
4966 thisheight = _DW_SCROLLED_MAX_HEIGHT; | 4966 thisheight = _DW_SCROLLED_MAX_HEIGHT; |
4967 } | 4967 } |
4968 /* Tree */ | 4968 /* Tree */ |
4969 else if([ object isMemberOfClass:[DWTree class] ]) | 4969 else if([object isMemberOfClass:[DWTree class]]) |
4970 { | 4970 { |
4971 thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2); | 4971 thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2); |
4972 thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2); | 4972 thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2); |
4973 } | 4973 } |
4974 /* Any other control type */ | 4974 /* Any other control type */ |
4975 else if([ object isKindOfClass:[ NSControl class ] ]) | 4975 else if([object isKindOfClass:[NSControl class]]) |
4976 nsstr = [object stringValue]; | 4976 nsstr = [object stringValue]; |
4977 | 4977 |
4978 /* If we have a string... | 4978 /* If we have a string... |
4979 * calculate the size with the current font. | 4979 * calculate the size with the current font. |
4980 */ | 4980 */ |
4981 if(nsstr && [nsstr length]) | 4981 if(nsstr && [nsstr length]) |
4982 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); | 4982 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); |
4983 | 4983 |
4984 /* Handle static text fields */ | 4984 /* Handle static text fields */ |
4985 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable]) | 4985 if([object isKindOfClass:[NSTextField class]] && ![object isEditable]) |
4986 { | 4986 { |
4987 id border = handle; | 4987 id border = handle; |
4988 | 4988 |
4989 extrawidth = 10; | 4989 extrawidth = 10; |
4990 | 4990 |
4991 /* Handle status bar field */ | 4991 /* Handle status bar field */ |
4992 if([border isMemberOfClass:[ NSBox class ] ]) | 4992 if([border isMemberOfClass:[NSBox class]]) |
4993 { | 4993 { |
4994 extrawidth += 2; | 4994 extrawidth += 2; |
4995 extraheight = 8; | 4995 extraheight = 8; |
4996 } | 4996 } |
4997 } | 4997 } |