Mercurial > dwindows
comparison mac/dw.m @ 1564:d84a690448c3
Attempted fix at border calculation on Mac for status text fields.
Subclass the text fields so user data can be set on those widgets.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 17 Jan 2012 21:04:56 +0000 |
parents | bc3a11fe9a46 |
children | 035bc006afbe |
comparison
equal
deleted
inserted
replaced
1563:90fdfc8aa16d | 1564:d84a690448c3 |
---|---|
1157 } | 1157 } |
1158 return [super performKeyEquivalent:theEvent]; | 1158 return [super performKeyEquivalent:theEvent]; |
1159 } | 1159 } |
1160 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } | 1160 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } |
1161 @end | 1161 @end |
1162 | |
1163 /* Subclass for a text and status text type */ | |
1164 @interface DWText : NSTextField | |
1165 { | |
1166 void *userdata; | |
1167 id clickDefault; | |
1168 } | |
1169 -(void *)userdata; | |
1170 -(void)setUserdata:(void *)input; | |
1171 @end | |
1172 | |
1173 @implementation DWText | |
1174 -(void *)userdata { return userdata; } | |
1175 -(void)setUserdata:(void *)input { userdata = input; } | |
1176 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | |
1177 @end | |
1178 | |
1162 | 1179 |
1163 /* Subclass for a entryfield password type */ | 1180 /* Subclass for a entryfield password type */ |
1164 @interface DWEntryFieldPassword : NSSecureTextField | 1181 @interface DWEntryFieldPassword : NSSecureTextField |
1165 { | 1182 { |
1166 void *userdata; | 1183 void *userdata; |
3623 } | 3640 } |
3624 /* Any other control type */ | 3641 /* Any other control type */ |
3625 else if([ object isKindOfClass:[ NSControl class ] ]) | 3642 else if([ object isKindOfClass:[ NSControl class ] ]) |
3626 nsstr = [object stringValue]; | 3643 nsstr = [object stringValue]; |
3627 | 3644 |
3628 /* Handle static text fields */ | |
3629 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable]) | |
3630 { | |
3631 /* Handle status bar field */ | |
3632 if([object isBordered] || (DWOSMinor > 5 && [object isBezeled])) | |
3633 extrawidth = 12; | |
3634 else | |
3635 extrawidth = 10; | |
3636 } | |
3637 | |
3638 /* If we have a string... | 3645 /* If we have a string... |
3639 * calculate the size with the current font. | 3646 * calculate the size with the current font. |
3640 */ | 3647 */ |
3641 if(nsstr && [nsstr length]) | 3648 if(nsstr && [nsstr length]) |
3642 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); | 3649 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); |
3643 | 3650 |
3651 /* Handle static text fields */ | |
3652 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable]) | |
3653 { | |
3654 /* Handle status bar field */ | |
3655 if([object isBordered] || (DWOSMinor > 5 && [object isBezeled])) | |
3656 { | |
3657 extrawidth = 12; | |
3658 extraheight = 4; | |
3659 } | |
3660 else | |
3661 extrawidth = 10; | |
3662 } | |
3663 | |
3644 /* Set the requested sizes */ | 3664 /* Set the requested sizes */ |
3645 if(width) | 3665 if(width) |
3646 *width = thiswidth + extrawidth; | 3666 *width = thiswidth + extrawidth; |
3647 if(height) | 3667 if(height) |
3648 *height = thisheight + extraheight; | 3668 *height = thisheight + extraheight; |
5044 * text: The text to be display by the static text widget. | 5064 * text: The text to be display by the static text widget. |
5045 * id: An ID to be used with dw_window_from_id() or 0L. | 5065 * id: An ID to be used with dw_window_from_id() or 0L. |
5046 */ | 5066 */ |
5047 HWND API dw_text_new(char *text, ULONG cid) | 5067 HWND API dw_text_new(char *text, ULONG cid) |
5048 { | 5068 { |
5049 NSTextField *textfield = [[NSTextField alloc] init]; | 5069 DWText *textfield = [[DWText alloc] init]; |
5050 [textfield setEditable:NO]; | 5070 [textfield setEditable:NO]; |
5051 [textfield setSelectable:NO]; | 5071 [textfield setSelectable:NO]; |
5052 [textfield setBordered:NO]; | 5072 [textfield setBordered:NO]; |
5053 [textfield setDrawsBackground:NO]; | 5073 [textfield setDrawsBackground:NO]; |
5054 [textfield setStringValue:[ NSString stringWithUTF8String:text ]]; | 5074 [textfield setStringValue:[ NSString stringWithUTF8String:text ]]; |