comparison mac/dw.m @ 1772:5e16351b01d2

Experimental change to use NSBox to draw border of status text widgets on Mac. Probably will take some more tweaking but it should work on 10.5 and 10.8 in addition to 10.6 and 10.7 that the old method supported.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 14 Jul 2012 04:13:59 +0000
parents bed4320cb0ce
children da7786b8573f
comparison
equal deleted inserted replaced
1771:bed4320cb0ce 1772:5e16351b01d2
3550 range = [view bounds].size.width; 3550 range = [view bounds].size.width;
3551 } 3551 }
3552 return range; 3552 return range;
3553 } 3553 }
3554 3554
3555 /* Return the handle to the text object */
3556 id _text_handle(id object)
3557 {
3558 if([object isMemberOfClass:[ DWSpinButton class]])
3559 {
3560 DWSpinButton *spinbutton = object;
3561 object = [spinbutton textfield];
3562 }
3563 if([object isMemberOfClass:[ NSBox class]])
3564 {
3565 NSBox *box = object;
3566 id content = [box contentView];
3567
3568 if([content isMemberOfClass:[ DWText class]])
3569 {
3570 object = content;
3571 }
3572 }
3573 return object;
3574 }
3575
3555 /* Internal function to calculate the widget's required size.. 3576 /* Internal function to calculate the widget's required size..
3556 * These are the general rules for widget sizes: 3577 * These are the general rules for widget sizes:
3557 * 3578 *
3558 * Render/Unspecified: 1x1 3579 * Render/Unspecified: 1x1
3559 * Scrolled(Container,Tree,MLE): Guessed size clamped to min and max in dw.h 3580 * Scrolled(Container,Tree,MLE): Guessed size clamped to min and max in dw.h
3565 */ 3586 */
3566 void _control_size(id handle, int *width, int *height) 3587 void _control_size(id handle, int *width, int *height)
3567 { 3588 {
3568 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; 3589 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
3569 NSString *nsstr = nil; 3590 NSString *nsstr = nil;
3570 id object = handle; 3591 id object = _text_handle(handle);
3571 3592
3572 if([object isMemberOfClass:[ DWSpinButton class]])
3573 object = [object textfield];
3574 /* Handle all the different button types */ 3593 /* Handle all the different button types */
3575 if([ object isKindOfClass:[ NSButton class ] ]) 3594 if([ object isKindOfClass:[ NSButton class ] ])
3576 { 3595 {
3577 switch([object buttonType]) 3596 switch([object buttonType])
3578 { 3597 {
3748 /* Tree */ 3767 /* Tree */
3749 else if([ object isMemberOfClass:[DWTree class] ]) 3768 else if([ object isMemberOfClass:[DWTree class] ])
3750 { 3769 {
3751 thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2); 3770 thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2);
3752 thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2); 3771 thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2);
3753 } 3772 }
3754 /* Any other control type */ 3773 /* Any other control type */
3755 else if([ object isKindOfClass:[ NSControl class ] ]) 3774 else if([ object isKindOfClass:[ NSControl class ] ])
3756 nsstr = [object stringValue]; 3775 nsstr = [object stringValue];
3757 3776
3758 /* If we have a string... 3777 /* If we have a string...
3762 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); 3781 dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight);
3763 3782
3764 /* Handle static text fields */ 3783 /* Handle static text fields */
3765 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable]) 3784 if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable])
3766 { 3785 {
3786 id border = handle;
3787
3767 /* Handle status bar field */ 3788 /* Handle status bar field */
3768 if([object isBordered] || (DWOSMinor > 5 && [object isBezeled])) 3789 if([border isMemberOfClass:[ NSBox class ] ])
3769 { 3790 {
3770 extrawidth = 12; 3791 extrawidth = 12;
3771 extraheight = 4; 3792 extraheight = 4;
3772 } 3793 }
3773 else 3794 else
3774 extrawidth = 10; 3795 extrawidth = 10;
3796 //dw_debug("this width %d height %d extra width %d height %d \"%s\"\n", thiswidth, thisheight, extrawidth, extraheight, (char *)[nsstr UTF8String]);
3775 } 3797 }
3776 3798
3777 /* Set the requested sizes */ 3799 /* Set the requested sizes */
3778 if(width) 3800 if(width)
3779 *width = thiswidth + extrawidth; 3801 *width = thiswidth + extrawidth;
3780 if(height) 3802 if(height)
3781 *height = thisheight + extraheight; 3803 *height = thisheight + extraheight;
3782 } 3804 }
5314 * text: The text to be display by the static text widget. 5336 * text: The text to be display by the static text widget.
5315 * id: An ID to be used with dw_window_from_id() or 0L. 5337 * id: An ID to be used with dw_window_from_id() or 0L.
5316 */ 5338 */
5317 HWND API dw_status_text_new(char *text, ULONG cid) 5339 HWND API dw_status_text_new(char *text, ULONG cid)
5318 { 5340 {
5341 NSBox *border = [[NSBox alloc] init];
5319 NSTextField *textfield = dw_text_new(text, cid); 5342 NSTextField *textfield = dw_text_new(text, cid);
5320 [textfield setBordered:YES]; 5343
5321 if(DWOSMinor > 5 && DWOSMinor < 8) 5344 [border setBorderType:NSGrooveBorder];
5322 { 5345 //[border setBorderType:NSLineBorder];
5323 [textfield setBezeled:YES]; 5346 [border setTitlePosition:NSNoTitle];
5324 [textfield setBezelStyle:NSTextFieldSquareBezel]; 5347 [border setContentView:textfield];
5325 } 5348 [border setContentViewMargins:NSMakeSize(1,1)];
5349 [textfield autorelease];
5326 [textfield setBackgroundColor:[NSColor clearColor]]; 5350 [textfield setBackgroundColor:[NSColor clearColor]];
5327 [[textfield cell] setVCenter:YES]; 5351 [[textfield cell] setVCenter:YES];
5328 return textfield; 5352 return border;
5329 } 5353 }
5330 5354
5331 /* 5355 /*
5332 * Create a new static text window (widget) to be packed. 5356 * Create a new static text window (widget) to be packed.
5333 * Parameters: 5357 * Parameters:
8591 { 8615 {
8592 NSFont *font = _dw_font_by_name(fontname); 8616 NSFont *font = _dw_font_by_name(fontname);
8593 8617
8594 if(font) 8618 if(font)
8595 { 8619 {
8596 id object = handle; 8620 id object = _text_handle(handle);
8597 if([object window]) 8621 if([object window])
8598 { 8622 {
8599 [object lockFocus]; 8623 [object lockFocus];
8600 [font set]; 8624 [font set];
8601 [object unlockFocus]; 8625 [object unlockFocus];
8637 * Parameters: 8661 * Parameters:
8638 * handle: The window handle from which to obtain the font. 8662 * handle: The window handle from which to obtain the font.
8639 */ 8663 */
8640 char * API dw_window_get_font(HWND handle) 8664 char * API dw_window_get_font(HWND handle)
8641 { 8665 {
8642 id object = handle; 8666 id object = _text_handle(handle);
8643 NSFont *font = nil; 8667 NSFont *font = nil;
8644 8668
8645 if([object isMemberOfClass:[DWGroupBox class]]) 8669 if([object isMemberOfClass:[DWGroupBox class]])
8646 { 8670 {
8647 font = [object titleFont]; 8671 font = [object titleFont];
8763 * Returns: 8787 * Returns:
8764 * text: The text associsated with a given window. 8788 * text: The text associsated with a given window.
8765 */ 8789 */
8766 char * API dw_window_get_text(HWND handle) 8790 char * API dw_window_get_text(HWND handle)
8767 { 8791 {
8768 NSObject *object = handle; 8792 id object = _text_handle(handle);
8769 8793
8770 if([object isMemberOfClass:[ DWSpinButton class]])
8771 {
8772 DWSpinButton *spinbutton = handle;
8773 handle = object = [spinbutton textfield];
8774 }
8775 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ]) 8794 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
8776 { 8795 {
8777 id window = handle; 8796 id window = object;
8778 NSString *nsstr = [ window title]; 8797 NSString *nsstr = [ window title];
8779 8798
8780 return strdup([ nsstr UTF8String ]); 8799 return strdup([ nsstr UTF8String ]);
8781 } 8800 }
8782 else if([ object isKindOfClass:[ NSControl class ] ]) 8801 else if([ object isKindOfClass:[ NSControl class ] ])
8783 { 8802 {
8784 NSControl *control = handle; 8803 NSControl *control = object;
8785 NSString *nsstr = [ control stringValue]; 8804 NSString *nsstr = [ control stringValue];
8786 8805
8787 return strdup([ nsstr UTF8String ]); 8806 return strdup([ nsstr UTF8String ]);
8788 } 8807 }
8789 return NULL; 8808 return NULL;
8795 * handle: Handle to the window. 8814 * handle: Handle to the window.
8796 * text: The text associsated with a given window. 8815 * text: The text associsated with a given window.
8797 */ 8816 */
8798 void API dw_window_set_text(HWND handle, char *text) 8817 void API dw_window_set_text(HWND handle, char *text)
8799 { 8818 {
8800 id object = handle; 8819 id object = _text_handle(handle);
8801 8820
8802 if([object isMemberOfClass:[ DWSpinButton class]])
8803 {
8804 DWSpinButton *spinbutton = handle;
8805 object = [spinbutton textfield];
8806 }
8807 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ]) 8821 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
8808 [object setTitle:[ NSString stringWithUTF8String:text ]]; 8822 [object setTitle:[ NSString stringWithUTF8String:text ]];
8809 else if([ object isKindOfClass:[ NSControl class ] ]) 8823 else if([ object isKindOfClass:[ NSControl class ] ])
8810 { 8824 {
8811 NSControl *control = handle; 8825 NSControl *control = object;
8812 [control setStringValue:[ NSString stringWithUTF8String:text ]]; 8826 [control setStringValue:[ NSString stringWithUTF8String:text ]];
8813 } 8827 }
8814 else if([object isMemberOfClass:[DWGroupBox class]]) 8828 else if([object isMemberOfClass:[DWGroupBox class]])
8815 { 8829 {
8816 DWGroupBox *groupbox = handle; 8830 DWGroupBox *groupbox = object;
8817 [groupbox setTitle:[NSString stringWithUTF8String:text]]; 8831 [groupbox setTitle:[NSString stringWithUTF8String:text]];
8818 } 8832 }
8819 else 8833 else
8820 return; 8834 return;
8821 /* If we changed the text... */ 8835 /* If we changed the text... */