comparison mac/dw.m @ 744:9882b0dfa304

Added an internal Mac function for setting the default Dynamic Windows font. Currently it affects labels and buttons... may become a public function on all platforms.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 16 Mar 2011 03:24:12 +0000
parents 4462bc7de1e3
children d29fb0d5b291
comparison
equal deleted inserted replaced
743:4462bc7de1e3 744:9882b0dfa304
2549 DW_MUTEX_UNLOCK; 2549 DW_MUTEX_UNLOCK;
2550 } 2550 }
2551 2551
2552 HWND _button_new(char *text, ULONG cid) 2552 HWND _button_new(char *text, ULONG cid)
2553 { 2553 {
2554 DWButton *button = [[DWButton alloc] init]; 2554 DWButton *button = [[DWButton alloc] init];
2555 if(text && *text) 2555 if(text && *text)
2556 { 2556 {
2557 [button setTitle:[ NSString stringWithUTF8String:text ]]; 2557 [button setTitle:[ NSString stringWithUTF8String:text ]];
2558 } 2558 }
2559 [button setTarget:button]; 2559 [button setTarget:button];
2560 [button setAction:@selector(buttonClicked:)]; 2560 [button setAction:@selector(buttonClicked:)];
2561 [button setTag:cid]; 2561 [button setTag:cid];
2562 [button setButtonType:NSMomentaryPushInButton]; 2562 [button setButtonType:NSMomentaryPushInButton];
2563 [button setBezelStyle:NSThickerSquareBezelStyle]; 2563 [button setBezelStyle:NSThickerSquareBezelStyle];
2564 if(DWDefaultFont)
2565 {
2566 [[button cell] setFont:DWDefaultFont];
2567 }
2564 return button; 2568 return button;
2565 } 2569 }
2566 2570
2567 /* 2571 /*
2568 * Create a new button window (widget) to be packed. 2572 * Create a new button window (widget) to be packed.
3628 * text: The text to be display by the static text widget. 3632 * text: The text to be display by the static text widget.
3629 * id: An ID to be used with dw_window_from_id() or 0L. 3633 * id: An ID to be used with dw_window_from_id() or 0L.
3630 */ 3634 */
3631 HWND API dw_text_new(char *text, ULONG cid) 3635 HWND API dw_text_new(char *text, ULONG cid)
3632 { 3636 {
3633 NSTextField *textfield = [[NSTextField alloc] init]; 3637 NSTextField *textfield = [[NSTextField alloc] init];
3634 [textfield setEditable:NO]; 3638 [textfield setEditable:NO];
3635 [textfield setSelectable:NO]; 3639 [textfield setSelectable:NO];
3636 [textfield setBordered:NO]; 3640 [textfield setBordered:NO];
3637 [textfield setDrawsBackground:NO]; 3641 [textfield setDrawsBackground:NO];
3638 [textfield setStringValue:[ NSString stringWithUTF8String:text ]]; 3642 [textfield setStringValue:[ NSString stringWithUTF8String:text ]];
3639 [textfield setTag:cid]; 3643 [textfield setTag:cid];
3640 /*[[textfield cell] setFont:DWDefaultFont];*/ 3644 if(DWDefaultFont)
3641 return textfield; 3645 {
3646 [[textfield cell] setFont:DWDefaultFont];
3647 }
3648 return textfield;
3642 } 3649 }
3643 3650
3644 /* 3651 /*
3645 * Creates a rendering context widget (window) to be packed. 3652 * Creates a rendering context widget (window) to be packed.
3646 * Parameters: 3653 * Parameters:
5963 [window setLevel:NSNormalWindowLevel]; 5970 [window setLevel:NSNormalWindowLevel];
5964 [window setHidesOnDeactivate:NO]; 5971 [window setHidesOnDeactivate:NO];
5965 } 5972 }
5966 } 5973 }
5967 5974
5968 /* 5975 NSFont *_dw_font_by_name(char *fontname)
5969 * Sets the font used by a specified window (widget) handle.
5970 * Parameters:
5971 * handle: The window (widget) handle.
5972 * fontname: Name and size of the font in the form "size.fontname"
5973 */
5974 int API dw_window_set_font(HWND handle, char *fontname)
5975 { 5976 {
5976 char *fontcopy = strdup(fontname); 5977 char *fontcopy = strdup(fontname);
5977 char *name = strchr(fontcopy, '.'); 5978 char *name = strchr(fontcopy, '.');
5979 NSFont *font = nil;
5980
5978 if(name) 5981 if(name)
5979 { 5982 {
5980 int size = atoi(fontcopy); 5983 int size = atoi(fontcopy);
5981 *name = 0; 5984 *name = 0;
5982 name++; 5985 name++;
5983 NSFont *font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; 5986 font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size];
5984 if(font) 5987 }
5988 free(fontcopy);
5989 return font;
5990 }
5991
5992 /*
5993 * Sets the font used by a specified window (widget) handle.
5994 * Parameters:
5995 * handle: The window (widget) handle.
5996 * fontname: Name and size of the font in the form "size.fontname"
5997 */
5998 int API dw_window_set_font(HWND handle, char *fontname)
5999 {
6000 NSFont *font = _dw_font_by_name(fontname);
6001
6002 if(font)
6003 {
6004 id object = handle;
6005 if([object window])
5985 { 6006 {
5986 id object = handle; 6007 [object lockFocus];
5987 if([object window]) 6008 [font set];
5988 { 6009 [object unlockFocus];
5989 [object lockFocus];
5990 [font set];
5991 [object unlockFocus];
5992 }
5993 if([object isKindOfClass:[NSControl class]])
5994 {
5995 [object setFont:font];
5996 [[object cell] setFont:font];
5997 }
5998 } 6010 }
5999 } 6011 if([object isKindOfClass:[NSControl class]])
6000 free(fontcopy); 6012 {
6013 [object setFont:font];
6014 [[object cell] setFont:font];
6015 }
6016 }
6001 return 0; 6017 return 0;
6002 } 6018 }
6003 6019
6004 /* 6020 /*
6005 * Returns the current font for the specified window 6021 * Returns the current font for the specified window
7474 [pool release]; 7490 [pool release];
7475 #endif 7491 #endif
7476 free(tmp); 7492 free(tmp);
7477 } 7493 }
7478 7494
7495 void _dw_default_font(char *fontname)
7496 {
7497 if(DWDefaultFont)
7498 {
7499 [DWDefaultFont release];
7500 }
7501 DWDefaultFont = _dw_font_by_name(fontname);
7502 [DWDefaultFont retain];
7503 }
7504
7479 /* 7505 /*
7480 * Initializes the Dynamic Windows engine. 7506 * Initializes the Dynamic Windows engine.
7481 * Parameters: 7507 * Parameters:
7482 * newthread: True if this is the only thread. 7508 * newthread: True if this is the only thread.
7483 * False if there is already a message loop running. 7509 * False if there is already a message loop running.
7497 /* Create a default main menu, with just the application menu */ 7523 /* Create a default main menu, with just the application menu */
7498 DWMainMenu = _generate_main_menu(); 7524 DWMainMenu = _generate_main_menu();
7499 [DWMainMenu retain]; 7525 [DWMainMenu retain];
7500 [DWApp setMainMenu:DWMainMenu]; 7526 [DWApp setMainMenu:DWMainMenu];
7501 DWObj = [[DWObject alloc] init]; 7527 DWObj = [[DWObject alloc] init];
7502 DWDefaultFont = [[NSFont fontWithName:@"Geneva" size:10.0] retain]; 7528 DWDefaultFont = nil;
7503 /* Create mutexes for thread safety */ 7529 /* Create mutexes for thread safety */
7504 DWRunMutex = dw_mutex_new(); 7530 DWRunMutex = dw_mutex_new();
7505 DWThreadMutex = dw_mutex_new(); 7531 DWThreadMutex = dw_mutex_new();
7506 DWThreadMutex2 = dw_mutex_new(); 7532 DWThreadMutex2 = dw_mutex_new();
7507 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ 7533 /* Use NSThread to start a dummy thread to initialize the threading subsystem */